Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .agents/skills/stitch-sdk-domain-design/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This skill teaches you how to perform **Stage 2** of the generation pipeline: re
A valid `domain-map.json` with two sections: `classes` and `bindings`, validated by `ir-schema.ts`.

> [!IMPORTANT]
> Your output is validated **twice** by the codegen: structurally (Zod IR schema) and semantically (projection steps verified against `outputSchema` from the tools-manifest).
> Your output is validated **twice** by the codegen: structurally (Zod IR schema) and semantically (sent args verified against `inputSchema`, projection steps verified against `outputSchema` from the tools-manifest).

---

Expand Down Expand Up @@ -84,6 +84,18 @@ Optional params use `"optional": true`. Renamed params use `"rename": "newName"`
A `"default": "VALUE"` (requires `optional: true`) is sent when the caller
omits the value: `deviceType: options?.deviceType ?? "DESKTOP"`.

A `computed` template reads `{field}` from the arg of that name, or from
`this.field` when there is none — so a self field needs no arg to be used in a
template. A param marked `"templateOnly": true` stays in the method signature
and feeds the template, but is never sent: `getScreen(screenId)` sends only
``{ name: `projects/${this.projectId}/screens/${screenId}` }``.

> [!IMPORTANT]
> **Every arg that is sent must be declared by the tool's `inputSchema`.** The
> server rejects undeclared fields ("Request contains an invalid argument"), so
> codegen fails on them. When a re-captured manifest drops an input field,
> remove the arg, or mark the param `templateOnly` if it builds a `name`.

> [!IMPORTANT]
> **Method signature shape (D12):** required params are positional, in IR
> order; ALL optional params are emitted into a single trailing
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ import { StitchToolClient, GetScreenResponse } from "@google/stitch-sdk";

const client = new StitchToolClient({ apiKey: "..." });
const result = await client.callTool<GetScreenResponse>("get_screen", {
projectId: "...",
screenId: "...",
name: "projects/.../screens/...",
});
await client.close();
```
Expand Down
18 changes: 2 additions & 16 deletions packages/sdk/generated/domain-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,9 @@
"class": "Project",
"method": "getScreen",
"args": {
"projectId": {
"from": "self"
},
"screenId": {
"from": "param"
"from": "param",
"templateOnly": true
},
"name": {
"from": "computed",
Expand All @@ -291,12 +289,6 @@
"class": "Screen",
"method": "getHtmlUrl",
"args": {
"projectId": {
"from": "self"
},
"screenId": {
"from": "self"
},
"name": {
"from": "computed",
"template": "projects/{projectId}/screens/{screenId}"
Expand Down Expand Up @@ -332,12 +324,6 @@
"class": "Screen",
"method": "getImageUrl",
"args": {
"projectId": {
"from": "self"
},
"screenId": {
"from": "self"
},
"name": {
"from": "computed",
"template": "projects/{projectId}/screens/{screenId}"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/designsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
import { type StitchToolClientSpec } from "../../src/spec/client.js";
import { StitchError } from "../../src/spec/errors.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
export { Stitch } from "./stitch.js";
export { Project } from "./project.js";
Expand Down
4 changes: 1 addition & 3 deletions packages/sdk/generated/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
import { type StitchToolClientSpec } from "../../src/spec/client.js";
import { StitchError } from "../../src/spec/errors.js";
Expand Down Expand Up @@ -209,8 +209,6 @@ export class Project {
async getScreen(screenId: string): Promise<Screen> {
try {
const raw = await this.client.callTool<GetScreenResponse>("get_screen", {
projectId: this.projectId,
screenId,
name: `projects/${this.projectId}/screens/${screenId}`,
});
return this.client.entities.resolve(Screen, ["projectId", "screenId"], {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/responses.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/

/** Response message for create_project. */
Expand Down
6 changes: 1 addition & 5 deletions packages/sdk/generated/src/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
import { type StitchToolClientSpec } from "../../src/spec/client.js";
import { StitchError } from "../../src/spec/errors.js";
Expand Down Expand Up @@ -261,8 +261,6 @@ export class Screen {

try {
const raw = await this.client.callTool<GetScreenResponse>("get_screen", {
projectId: this.projectId,
screenId: this.screenId,
name: `projects/${this.projectId}/screens/${this.screenId}`,
});
// writeBack: merge the response into this.data so the next call hits the cache
Expand Down Expand Up @@ -293,8 +291,6 @@ export class Screen {

try {
const raw = await this.client.callTool<GetScreenResponse>("get_screen", {
projectId: this.projectId,
screenId: this.screenId,
name: `projects/${this.projectId}/screens/${this.screenId}`,
});
// writeBack: merge the response into this.data so the next call hits the cache
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/stitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
import { type StitchToolClientSpec } from "../../src/spec/client.js";
import { StitchError } from "../../src/spec/errors.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/tool-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/
/** JSON Schema property descriptor for a tool parameter. */
export interface ToolPropertySchema {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/generated/src/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT — changes will be overwritten.

Source: tools-manifest.json (sha256:88ec3dfa066c...)
domain-map.json (sha256:a6177cc7e2f4...)
domain-map.json (sha256:55a31393745c...)
*/

/** A component style token in a design system. */
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/generated/stitch-sdk.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"schemaVersion": 1,
"generated": {
"generatedAt": "2026-09-30T23:36:31.707Z",
"sourceHash": "sha256:e4065faf73314496863dc38dae0ba79f4375834c975a4d3e03bfe46bc7d6183c",
"generatedAt": "2026-10-22T02:32:47.218Z",
"sourceHash": "sha256:9afa649b93e650c8fcd905b42c1f98dee761700e769a2ee7d4744e9c1f73d4f8",
"manifestHash": "sha256:88ec3dfa066ce5060be236b0a5c0b5fb51671a7dd60d05556c028e6c4c8f0e1c",
"domainMapHash": "sha256:a6177cc7e2f44d2d536928d4e0ae7bd51ed2dd3393235787216b976498c3b1b2",
"domainMapHash": "sha256:55a31393745c750400c7e172cf8c3dd65560d587ded20da79591dfc5e4de191c",
"fileCount": 8,
"repairedTools": [
"generate_screen_from_text",
Expand All @@ -13,8 +13,8 @@
]
},
"domainMap": {
"generatedAt": "2026-09-23T18:36:09.460Z",
"sourceHash": "sha256:a6177cc7e2f44d2d536928d4e0ae7bd51ed2dd3393235787216b976498c3b1b2",
"generatedAt": "2026-10-22T02:32:47.218Z",
"sourceHash": "sha256:55a31393745c750400c7e172cf8c3dd65560d587ded20da79591dfc5e4de191c",
"manifestHash": "sha256:88ec3dfa066ce5060be236b0a5c0b5fb51671a7dd60d05556c028e6c4c8f0e1c",
"classCount": 4,
"bindingCount": 15
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/src/download-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ export class DownloadAssetsHandler implements DownloadAssetsSpec {
let htmlUrl = screen.htmlCode?.downloadUrl;
if (!htmlUrl) {
try {
// get_screen accepts only `name`; extra fields are rejected
const raw = await this.client.callTool("get_screen", {
projectId,
screenId: screenId,
name: `projects/${projectId}/screens/${screenId}`,
});
htmlUrl = (raw as any)?.htmlCode?.downloadUrl;
Expand Down
38 changes: 38 additions & 0 deletions packages/sdk/test/unit/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,44 @@ describe("DownloadAssetsHandler", () => {
},
]);
});

it("falls back to get_screen with only the resource name when a screen has no htmlCode", async () => {
const mockClient = { callTool: vi.fn() } as any;
mockClient.callTool.mockImplementation((tool: string) => {
if (tool === "list_screens") {
return Promise.resolve({
screens: [{ id: "s1", name: "projects/p1/screens/s1" }],
});
}
if (tool === "get_screen") {
return Promise.resolve({
htmlCode: { downloadUrl: "https://fake/s1.html" },
});
}
return Promise.resolve({});
});
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
text: () => Promise.resolve("<html></html>"),
}),
);

const handler = new DownloadAssetsHandler(mockClient);
const result = await handler.execute({
projectId: "p1",
outputDir: "/tmp/out",
});

// get_screen accepts only `name`; any extra field is rejected (#381)
expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", {
name: "projects/p1/screens/s1",
});
expect(result.success).toBe(true);
if (!result.success) return;
expect(result.downloadedScreens.map((s) => s.screenId)).toEqual(["s1"]);
});
});

describe("sanitizeFilename", () => {
Expand Down
29 changes: 23 additions & 6 deletions packages/sdk/test/unit/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ describe("SDK Unit Tests", () => {

const result = await screen.getHtmlUrl();

// get_screen accepts only `name`; any extra field is rejected (#381)
expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", {
projectId: projectId,
screenId: "screen-123",
name: "projects/proj-123/screens/screen-123",
});
expect(result).toBe("https://api.example.com/html");
Expand Down Expand Up @@ -105,8 +104,6 @@ describe("SDK Unit Tests", () => {
const result = await screen.getImageUrl();

expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", {
projectId: projectId,
screenId: "screen-123",
name: "projects/proj-123/screens/screen-123",
});
expect(result).toBe("https://api.example.com/image.png");
Expand All @@ -127,8 +124,6 @@ describe("SDK Unit Tests", () => {
const err = await screen.getHtmlUrl().catch((e: unknown) => e);

expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", {
projectId: projectId,
screenId: "screen-123",
name: "projects/proj-123/screens/screen-123",
});
// Missing artifact is NOT_FOUND, never a silent empty string
Expand Down Expand Up @@ -564,6 +559,28 @@ describe("SDK Unit Tests", () => {
expect(result).toEqual([]);
});

it("getScreen should call get_screen with only the resource name", async () => {
const project = mockClient.entities.resolve(
Project,
["projectId"],
projectId,
);

(mockClient.callTool as Mock).mockResolvedValue({
name: `projects/${projectId}/screens/s-42`,
title: "Checkout",
});

const screen = await project.getScreen("s-42");

expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", {
name: `projects/${projectId}/screens/s-42`,
});
expect(screen).toBeInstanceOf(Screen);
expect(screen.projectId).toBe(projectId);
expect(screen.screenId).toBe("s-42");
});

it("generate should throw StitchError on failure", async () => {
const project = mockClient.entities.resolve(
Project,
Expand Down
5 changes: 5 additions & 0 deletions scripts/check-skill-consistency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const REQUIRED_TOKENS = [
"rename",
"default",
"template",
"templateOnly",
// Class config
"constructorParams",
"reference",
Expand Down Expand Up @@ -114,6 +115,10 @@ check(
ArgSpec.safeParse({ from: "param", optional: true, default: "D" }).success,
"param default is live",
);
check(
ArgSpec.safeParse({ from: "param", templateOnly: true }).success,
"param templateOnly is live",
);
check(
!DomainClassConfig.safeParse({
description: "d",
Expand Down
Loading
Loading