Official agent skill

Typed Service Contracts

by google-labs-code in google-labs-code/stitch-sdk

Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern.

OfficialApache-2.0Auto-check passedDevelopment

Install Typed Service Contracts

skills CLI
$ npx skills add google-labs-code/stitch-sdk --skill typed-service-contracts -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install google-labs-code/stitch-sdk typed-service-contracts --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/google-labs-code/stitch-sdk.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/typed-service-contract .claude/skills/typed-service-contracts && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
typed-service-contracts
GitHub stars
1.8k
Token cost
~1.4k tokens
SKILL.md length
336 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
Apache-2.0

At a glance

Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern.

  • Works in 5 steps: The Spec (spec.ts) → The Handler (handler.ts) → Define the Contract (spec.ts) → …
  • Complex business logic
  • SKILL.md covers When to use this skill, Architecture Components and How to use it
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Typed Service Contracts is an agent skill from google-labs-code/stitch-sdk, published by the product's own GitHub organization. Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern. Use when building CLIs, libraries, or complex business logic.

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Type safety. It works with TypeScript and Zod. The repository describes itself as: Generate UI screens from text prompts and extract their HTML and screenshots programmatically. The licence is Apache-2.0.

When your agent uses it

  • Complex business logic
  • Tasks that involve Type safety

Example prompts

  • “Spec and Handler”
  • “/typed-service-contracts”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. The Spec (spec.ts)
  2. The Handler (handler.ts)
  3. Define the Contract (spec.ts)
  4. Implement the Handler (handler.ts)
  5. Testing Strategy

What it can do on your machine

Read from SKILL.md and the folder at commit e3f8ece. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Typed Service Contracts loads about 1.4k tokens when it runs. Until then it costs about 49 tokens; SKILL.md has 336 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~49
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from google-labs-code/stitch-sdk at commit e3f8ece, republished under its Apache-2.0 licence (© google-labs-code). 336 words, ~1,420 tokens.

Download SKILL.mdSave it as .claude/skills/typed-service-contracts/SKILL.md (or your agent's skills folder).
name
typed-service-contracts
description
Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern. Use when building CLIs, libraries, or complex business logic.

Typed Service Contracts (Spec & Handler Pattern)

This skill defines a Vertical Slice Architecture backed by Design by Contract (DbC) principles. It treats application logic as rigorously defined Units of Work where inputs are parsed (not just validated) and errors are treated as values (Result Pattern) rather than exceptions.

When to use this skill

  • Building CLIs or Libraries: When you need strict boundaries between user input and system logic.
  • Complex Validation: When inputs require transformation (parsing) before being useful (e.g., ensuring a string is a valid file path).
  • High-Reliability Requirements: When you cannot afford unhandled runtime exceptions and need exhaustive error handling.
  • Testing Focus: When you want to separate data validation tests from business logic tests.

Architecture Components

1. The Spec (spec.ts)

The "Contract" or "Port". It defines the What. It must contain:

  • Input Schema: A Zod schema that parses raw input into a valid DTO.
  • Output Schema: A Zod schema defining the successful data structure.
  • Error Schema: A discriminated union of specific failure modes (not generic errors).
  • Result Type: A DiscriminatedUnion of Success | Failure.
  • Interface: The capability definition (e.g., interface ConfigureSpec).
2. The Handler (handler.ts)

The "Implementation" or "Adapter". It defines the How. It must:

  • Implement the Interface defined in the Spec.
  • Be an "Impure" class that handles side effects (File System, API calls).
  • NEVER throw exceptions. It must catch internal errors and map them to the Result type.

How to use it

Step 1: Define the Contract (spec.ts)

Follow this template to define the boundaries.

typescript
import { z } from "zod";

// 1. VALIDATION HELPERS (Reusable Refinements)
export const SafePathSchema = z
  .string()
  .min(1)
  .refine((p) => !p.includes(".."), "No traversal allowed");

// 2. INPUT (The Command) - "Parse, don't validate"
export const MyTaskInputSchema = z.object({
  path: SafePathSchema,
  force: z.boolean().default(false),
});
export type MyTaskInput = z.infer<typeof MyTaskInputSchema>;

// 3. ERROR CODES (Exhaustive)
export const MyTaskErrorCode = z.enum([
  "FILE_NOT_FOUND",
  "PERMISSION_DENIED",
  "UNKNOWN_ERROR",
]);

// 4. RESULT (The Monad)
export const MyTaskSuccess = z.object({
  success: z.literal(true),
  data: z.string(), // The output payload
});

export const MyTaskFailure = z.object({
  success: z.literal(false),
  error: z.object({
    code: MyTaskErrorCode,
    message: z.string(),
    suggestion: z.string().optional(),
    recoverable: z.boolean(),
  }),
});

export type MyTaskResult =
  | z.infer<typeof MyTaskSuccess>
  | z.infer<typeof MyTaskFailure>;

// 5. INTERFACE (The Capability)
export interface MyTaskSpec {
  execute(input: MyTaskInput): Promise<MyTaskResult>;
}
Step 2: Implement the Handler (handler.ts)

Follow this template to implement the logic.

typescript
import { MyTaskSpec, MyTaskInput, MyTaskResult } from "./spec.js";
import * as fs from "fs";

export class MyTaskHandler implements MyTaskSpec {
  async execute(input: MyTaskInput): Promise<MyTaskResult> {
    try {
      // 1. Business Logic
      if (!fs.existsSync(input.path)) {
        // 2. Explicit Error Return (No Throwing)
        return {
          success: false,
          error: {
            code: "FILE_NOT_FOUND",
            message: `Path does not exist: ${input.path}`,
            recoverable: true,
          },
        };
      }

      // 3. Success Return
      return {
        success: true,
        data: "Operation complete",
      };
    } catch (error) {
      // 4. Safety Net: Catch unknown runtime errors
      return {
        success: false,
        error: {
          code: "UNKNOWN_ERROR",
          message: error instanceof Error ? error.message : String(error),
          recoverable: false,
        },
      };
    }
  }
}
Step 3: Testing Strategy

Do not write monolithic tests. Split them into Contract Tests and Logic Tests.

A. Contract Tests (Schema)

Test the Bouncer. Ensure invalid data is rejected before it reaches the handler.

  • Focus: Edge cases, validation rules, Zod refinements.
  • Style: Data-driven (Table tests).
typescript
// spec.test.ts
import { MyTaskInputSchema } from "./spec";

const invalidCases = [
  { val: "../etc/passwd", err: "No traversal allowed" },
  { val: "", err: "min(1)" },
];

test.each(invalidCases)("validates paths", ({ val, err }) => {
  const result = MyTaskInputSchema.safeParse({ path: val });
  expect(result.success).toBe(false);
});
B. Logic Tests (Handler)

Test the Chef. Mock external dependencies (fs, network) and assert the Result Object.

  • Focus: Business logic flow, error mapping, success states.
  • Style: Mocked unit tests or Scenario Runners.
typescript
// handler.test.ts
import { MyTaskHandler } from "./handler";
import { vi } from "vitest"; // or jest

test("returns FILE_NOT_FOUND if path missing", async () => {
  // MOCK
  vi.mocked(fs.existsSync).mockReturnValue(false);

  // EXECUTE
  const handler = new MyTaskHandler();
  const result = await handler.execute({ path: "/fake" });

  // ASSERT (Check the Result Object)
  expect(result.success).toBe(false);
  if (!result.success) {
    expect(result.error.code).toBe("FILE_NOT_FOUND");
  }
});

© google-labs-code, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/typed-service-contract of google-labs-code/stitch-sdk.

Open the folder on GitHubat commit e3f8ece

Compare with similar skills

Typed Service Contracts next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Typed Service Contracts compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Typed Service Contracts this skillgoogle-labs-code/stitch-sdk1.8k—~1.4kAutomated safety check: PassApache-2.0
Ban Type AssertionsFactory-AI/factory-plugins110—~1.7kAutomated safety check: PassNone
Hono Idiomsirahardianto/awesome-agv157—~3kAutomated safety check: PassMIT
Type Safetyidavidov13/agentic-playwright223—~3.5kAutomated safety check: PassMIT
Common Tasksidavidov13/agentic-playwright223—~2.5kAutomated safety check: PassMIT
Data Strategyidavidov13/agentic-playwright223—~3.4kAutomated safety check: PassMIT

Similar skills

  • Ban Type Assertions

    Factory-AI/factory-plugins

    Ban as type assertions in a package via the @typescript-eslint/consistent-type-assertions lint rule, replacing them with compiler-verified type-safe alternatives.

    110 GitHub stars~1.7k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Hono Idioms

    irahardianto/awesome-agv

    Hono lightweight web framework patterns: type-safe route handlers, middleware composition, Zod validation, and RPC clients for Cloudflare Workers, Node, or Bun.

    157 GitHub stars~3k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • Type Safety

    idavidov13/agentic-playwright

    TypeScript type safety conventions for the Playwright scaffold — the "no any" rule, Zod 4 schema patterns (z.strictObject, top-level validators like z.uuid / z.email / z.url / z.int / z.enum)…

    223 GitHub stars~3.5k tokensUpdated 7 days ago
    Testing & QAAuto-check passed
  • Common Tasks

    idavidov13/agentic-playwright

    Copy-paste AI prompt templates for common Playwright scaffold development tasks — adding page objects, functional/E2E/API tests, Zod schemas, factories, fixtures, and components.

    223 GitHub stars~2.5k tokensUpdated 7 days ago
    Testing & QAAuto-check passed
  • Data Strategy

    idavidov13/agentic-playwright

    Test data strategy for the Playwright scaffold — Faker + Zod factories for dynamic happy-path data, static TS files (.ts with as const exports — never .json) for domain-specific curated invalid…

    223 GitHub stars~3.4k tokensUpdated 7 days ago
    Testing & QAAuto-check passed
  • Schema Source Of Truth

    TheDecipherist/claude-code-mastery-project-starter-kit

    One canonical Zod schema per entity, reused across the stack instead of redeclared at each layer.

    338 GitHub stars~988 tokensUpdated 3 mo ago
    Frontend & DesignAuto-check passed

More from google-labs-code/stitch-sdk

All 9 skills in this repo
  • Stitch SDK Development

    google-labs-code/stitch-sdk

    Official

    Develop the Stitch SDK. An agent skill from google-labs-code/stitch-sdk.

    1.8k GitHub stars~3.4k tokensUpdated 7 days ago
    Auto-check passed
  • Stitch SDK Domain Design

    google-labs-code/stitch-sdk

    Official

    Design the domain model for the Stitch SDK. An agent skill from google-labs-code/stitch-sdk.

    1.8k GitHub stars~2.4k tokensUpdated 7 days ago
    Auto-check passed
  • Stitch SDK Pipeline

    google-labs-code/stitch-sdk

    Official

    Run the full Stitch SDK generation pipeline. An agent skill from google-labs-code/stitch-sdk.

    1.8k GitHub stars~2k tokensUpdated 7 days ago
    Auto-check passed
  • Stitch SDK Readme

    google-labs-code/stitch-sdk

    Official

    Generate or update the README for the Stitch SDK. An agent skill from google-labs-code/stitch-sdk.

    1.8k GitHub stars~1.8k tokensUpdated 7 days ago
    Auto-check passed
  • Stitch SDK Usage

    google-labs-code/stitch-sdk

    Official

    Use the Stitch SDK to generate, edit, and iterate on UI screens from text prompts, manage projects, and retrieve screen HTML/images.

    1.8k GitHub stars~2.8k tokensUpdated 7 days ago
    Auto-check passed
  • TDD Red Green Refactor

    google-labs-code/stitch-sdk

    Official

    Enforces a disciplined Red-Green-Refactor (TDD) workflow in TypeScript/Node.js.

    1.8k GitHub stars~755 tokensUpdated 7 days ago
    Auto-check passed

Works with

Questions about Typed Service Contracts

What does Typed Service Contracts do?

Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern. Typed Service Contracts is an agent skill from google-labs-code/stitch-sdk, published by the product's own GitHub organization. Architecture standard for building robust, type-safe TypeScript services using the "Spec and Handler" pattern.

When should I use Typed Service Contracts?

Typed Service Contracts fits situations like: complex business logic; tasks that involve Type safety.

How do I install Typed Service Contracts in Claude Code?

Run `npx skills add google-labs-code/stitch-sdk --skill typed-service-contracts -a claude-code`. Or copy the skill folder (.agents/skills/typed-service-contract in google-labs-code/stitch-sdk) into .claude/skills/typed-service-contracts in your project. Claude Code loads it when a task matches its description.

How do I install Typed Service Contracts in Codex?

Run `npx skills add google-labs-code/stitch-sdk --skill typed-service-contracts -a codex`. Or copy the skill folder (.agents/skills/typed-service-contract in google-labs-code/stitch-sdk) into .agents/skills/typed-service-contracts in your project. Codex loads it when a task matches its description.

Can I use Typed Service Contracts in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add google-labs-code/stitch-sdk --skill typed-service-contracts -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/typed-service-contracts, .gemini/skills/typed-service-contracts, .github/skills/typed-service-contracts and .opencode/skills/typed-service-contracts in your project.

What does Typed Service Contracts need to run?

SKILL.md names no scripts, command-line tools or credentials: Typed Service Contracts is instructions for the agent only.

Does Typed Service Contracts access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Typed Service Contracts safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Typed Service Contracts use?

Typed Service Contracts is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Typed Service Contracts use?

About 1.4k tokens (SKILL.md is roughly 5.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Typed Service Contracts?

Skills that share tags, products or a category with Typed Service Contracts: Ban Type Assertions (Factory-AI/factory-plugins, 110 stars), Hono Idioms (irahardianto/awesome-agv, 157 stars), Type Safety (idavidov13/agentic-playwright, 223 stars) and Common Tasks (idavidov13/agentic-playwright, 223 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Typed Service Contracts?

google-labs-code (a GitHub organization, an official publisher) maintains it in google-labs-code/stitch-sdk, which has 1,826 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 1, 2026.

Source: google-labs-code/stitch-sdk on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.