@logictan/dsh-stitch-designer 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/guidance.js +1 -1
- package/lib/index.js +99 -70
- package/lib/tools.js +0 -57
- package/package.json +6 -3
package/lib/guidance.js
CHANGED
|
@@ -40,7 +40,7 @@ export const SECTION_ORDER = 150;
|
|
|
40
40
|
export const STITCH_GUIDANCE = [
|
|
41
41
|
'本机已安装 dsh-stitch-designer 插件(Google Stitch AI 界面设计):提供 Stitch 原生工具(数量随上游变化,含建/删/列项目、列/取界面、生成界面、改界面、生成变体、设计系统、设计稿上传与文件下载),以及 1 个本插件自建的 `mcp__stitch__remove_screens_from_canvas`(把一张或多张 screen 从项目画布上移除;传一个 id 就是删一张——Stitch 没有删除单张 screen 的接口)。',
|
|
42
42
|
'',
|
|
43
|
-
'Stitch
|
|
43
|
+
'Stitch 全部工具是一个按需加载的 toolset `stitch_design`:参数表不在提示词里,要调用前先调 `get_tools({toolset:"stitch_design"})` 加载,工具从下一轮起进入工具列表,之后整个会话一直可用。其中 `create_design_system`、`update_design_system` 结构复杂(`$defs` 三层嵌套、字体枚举 68 个),先读插件 README 或用 `mcp__stitch__get_project` 读项目里已存的设计系统资产,不要凭空猜字段。',
|
|
44
44
|
'',
|
|
45
45
|
'用 Stitch 设计稿实现界面时,遵守以下规范:',
|
|
46
46
|
'1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
|
package/lib/index.js
CHANGED
|
@@ -41,11 +41,92 @@ import { createCanvasClient } from './canvas.js';
|
|
|
41
41
|
import { createStitchClient } from './stitch.js';
|
|
42
42
|
import { createInvoker } from './conventions.js';
|
|
43
43
|
import { SECTION_NAME, SECTION_ORDER, STITCH_GUIDANCE } from './guidance.js';
|
|
44
|
-
import { createOutput, createToolDefinition, publicToolName, retryWithBackoff
|
|
44
|
+
import { createOutput, createToolDefinition, publicToolName, retryWithBackoff } from './tools.js';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Name of this plugin's toolset in the `get_tools` catalog.
|
|
48
|
+
*
|
|
49
|
+
* Model-facing: the model passes this name to `get_tools`.
|
|
50
|
+
*/
|
|
51
|
+
const TOOLSET_NAME = 'stitch_design';
|
|
52
|
+
|
|
53
|
+
/** Model-facing when-to-use line for the toolset, printed beside its catalog entry. */
|
|
54
|
+
const TOOLSET_DESCRIPTION =
|
|
55
|
+
'Google Stitch UI design: projects, screens (list, get, generate, edit, variants), '
|
|
56
|
+
+ 'design systems, file download, canvas removal. Load when the task is to design a UI with Stitch.';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The one tool Stitch does not offer, built here rather than from `tools/list`.
|
|
60
|
+
*
|
|
61
|
+
* Stitch has no screen-delete route (`stitch delete screen` answers
|
|
62
|
+
* `UNSUPPORTED_RESOURCE`, `DELETE .../screens/<id>` answers 404), so the bridge
|
|
63
|
+
* performs the removal itself through one project-level PATCH. The tool takes a
|
|
64
|
+
* list because the canvas is one field: N removals are one write, and a single
|
|
65
|
+
* removal is just the one-element list.
|
|
66
|
+
*
|
|
67
|
+
* It travels with the toolset like every other tool: nothing here needs the
|
|
68
|
+
* upstream catalog, but every path to the canvas needs the API key, so it can
|
|
69
|
+
* only ever be usable exactly when the toolset is. Its `parameters` stay
|
|
70
|
+
* verbatim, which is why it does not go through `defineTool`.
|
|
71
|
+
*
|
|
72
|
+
* @param canvas - the Canvas REST client.
|
|
73
|
+
* @returns a registry-ready tool definition.
|
|
74
|
+
*/
|
|
75
|
+
function removeScreensTool(canvas) {
|
|
76
|
+
return {
|
|
77
|
+
name: publicToolName(SERVER_NAME, 'remove_screens_from_canvas'),
|
|
78
|
+
description:
|
|
79
|
+
'Remove one or more screens from a Stitch project canvas. Stitch has no screen-delete API, so '
|
|
80
|
+
+ 'this rewrites the project\'s canvas without those screens — always in a single write, '
|
|
81
|
+
+ 'however many ids you pass. The screen objects themselves are not destroyed; they disappear '
|
|
82
|
+
+ 'from the project, which is what clears abandoned screens out. Use '
|
|
83
|
+
+ 'mcp__stitch__list_screens to find screen ids first. Ids that are not on the canvas are '
|
|
84
|
+
+ 'reported back rather than failing the whole call.',
|
|
85
|
+
parameters: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
projectId: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'Stitch project id (bare id, not "projects/<id>").',
|
|
91
|
+
},
|
|
92
|
+
screenIds: {
|
|
93
|
+
type: 'array',
|
|
94
|
+
items: { type: 'string' },
|
|
95
|
+
description: 'Ids of the screens to remove from the canvas. One id is the normal single-removal case.',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
required: ['projectId', 'screenIds'],
|
|
99
|
+
},
|
|
100
|
+
output: createOutput(undefined),
|
|
101
|
+
async execute(args, exec) {
|
|
102
|
+
const result = await canvas.removeScreens(args.projectId, args.screenIds, exec);
|
|
103
|
+
const remaining = Array.isArray(result?.screenInstances) ? result.screenInstances.length : 0;
|
|
104
|
+
const lines = [
|
|
105
|
+
`Removed ${result.removed.length} screen(s) from project ${args.projectId}: ${result.removed.join(', ')}.`,
|
|
106
|
+
`The canvas now holds ${remaining} screen(s).`,
|
|
107
|
+
];
|
|
108
|
+
if (result.missing.length > 0) {
|
|
109
|
+
lines.push(`Not on the canvas (left alone): ${result.missing.join(', ')}.`);
|
|
110
|
+
}
|
|
111
|
+
return { content: [{ type: 'text', text: lines.join(' ') }] };
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
45
115
|
|
|
46
116
|
/** Plugin row id; must equal the row id in `cordis.patch.yml`. */
|
|
47
117
|
export const name = 'stitch-designer';
|
|
48
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The `ctx.toolsets` service carries this plugin's entire tool surface.
|
|
121
|
+
*
|
|
122
|
+
* Declared at module level (not only inside `apply`) because cordis reads
|
|
123
|
+
* `inject` off the plugin value it is handed, and a host without the mechanism
|
|
124
|
+
* cannot serve a single Stitch tool — so the honest outcome is "the plugin is
|
|
125
|
+
* not mounted", not a guidance section announcing seventeen tools no catalog
|
|
126
|
+
* lists.
|
|
127
|
+
*/
|
|
128
|
+
export const inject = ['toolsets'];
|
|
129
|
+
|
|
49
130
|
/**
|
|
50
131
|
* Credential reference holding the Stitch API key.
|
|
51
132
|
*
|
|
@@ -58,9 +139,6 @@ export const API_KEY_REF = 'STITCH_API_KEY';
|
|
|
58
139
|
/** Server namespace embedded in every public tool name (`mcp__stitch__*`). */
|
|
59
140
|
export const SERVER_NAME = 'stitch';
|
|
60
141
|
|
|
61
|
-
/** The prefix every tool this plugin registers carries, announcement filter included. */
|
|
62
|
-
const PUBLIC_PREFIX = `mcp__${SERVER_NAME}__`;
|
|
63
|
-
|
|
64
142
|
/**
|
|
65
143
|
* How the boot-time `tools/list` is retried before the tools are given up on.
|
|
66
144
|
*
|
|
@@ -123,8 +201,8 @@ export function apply(ctx) {
|
|
|
123
201
|
// that gap: setting the key in the Plugins page registers the tools in the
|
|
124
202
|
// running process, with no restart. Without it the tools would appear only
|
|
125
203
|
// after the user happened to restart, which reads as "the plugin is broken".
|
|
126
|
-
ctx.inject(['
|
|
127
|
-
const
|
|
204
|
+
ctx.inject(['toolsets', 'credentials'], (toolsCtx) => {
|
|
205
|
+
const toolsets = toolsCtx.get('toolsets');
|
|
128
206
|
|
|
129
207
|
toolsCtx.effect(() => {
|
|
130
208
|
let disposed = false;
|
|
@@ -143,9 +221,21 @@ export function apply(ctx) {
|
|
|
143
221
|
call: (args, exec) => invoke(tool.name, args, exec),
|
|
144
222
|
}),
|
|
145
223
|
);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
224
|
+
next.push(removeScreensTool(canvas));
|
|
225
|
+
// `toolsets.register` is NOT idempotent — a second registration of one
|
|
226
|
+
// name throws `toolset name "..." is already registered`. Exactly one
|
|
227
|
+
// registration can exist here because the only two ways into this
|
|
228
|
+
// function are the boot attempt and the credential listener below, and
|
|
229
|
+
// that listener is guarded on `disposers.length > 0` — once a sync has
|
|
230
|
+
// succeeded there is no path back into it for the life of the fiber.
|
|
231
|
+
// (A failed attempt leaves `disposers` empty, so a retry or a later key
|
|
232
|
+
// fix registers for the first time, not a second time.)
|
|
233
|
+
disposers = [toolsets.register({
|
|
234
|
+
name: TOOLSET_NAME,
|
|
235
|
+
description: TOOLSET_DESCRIPTION,
|
|
236
|
+
tools: next,
|
|
237
|
+
})];
|
|
238
|
+
toolsCtx.logger.info(`stitch-designer: toolset ${TOOLSET_NAME} carries ${next.length} mcp__${SERVER_NAME}__* tools`);
|
|
149
239
|
};
|
|
150
240
|
|
|
151
241
|
// One attempt plus bounded backoff, so the boot fetch that failed
|
|
@@ -176,77 +266,16 @@ export function apply(ctx) {
|
|
|
176
266
|
syncWithRetry();
|
|
177
267
|
});
|
|
178
268
|
|
|
179
|
-
// `remove_screens_from_canvas` is local, not upstream: Stitch has no
|
|
180
|
-
// screen-delete route (`stitch delete screen` answers
|
|
181
|
-
// `UNSUPPORTED_RESOURCE`, `DELETE .../screens/<id>` answers 404), so the
|
|
182
|
-
// bridge performs the removal itself through one project-level PATCH. The
|
|
183
|
-
// tool takes a list because the canvas is one field: N removals are one
|
|
184
|
-
// write, and a single removal is just the one-element list. It is
|
|
185
|
-
// registered here unconditionally because it needs no `tools/list` to
|
|
186
|
-
// describe it — its contract is this file's.
|
|
187
|
-
const removeScreenDispose = tools.register({
|
|
188
|
-
name: publicToolName(SERVER_NAME, 'remove_screens_from_canvas'),
|
|
189
|
-
description:
|
|
190
|
-
'Remove one or more screens from a Stitch project canvas. Stitch has no screen-delete API, so '
|
|
191
|
-
+ 'this rewrites the project\'s canvas without those screens — always in a single write, '
|
|
192
|
-
+ 'however many ids you pass. The screen objects themselves are not destroyed; they disappear '
|
|
193
|
-
+ 'from the project, which is what clears abandoned screens out. Use '
|
|
194
|
-
+ 'mcp__stitch__list_screens to find screen ids first. Ids that are not on the canvas are '
|
|
195
|
-
+ 'reported back rather than failing the whole call.',
|
|
196
|
-
parameters: {
|
|
197
|
-
type: 'object',
|
|
198
|
-
properties: {
|
|
199
|
-
projectId: {
|
|
200
|
-
type: 'string',
|
|
201
|
-
description: 'Stitch project id (bare id, not "projects/<id>").',
|
|
202
|
-
},
|
|
203
|
-
screenIds: {
|
|
204
|
-
type: 'array',
|
|
205
|
-
items: { type: 'string' },
|
|
206
|
-
description: 'Ids of the screens to remove from the canvas. One id is the normal single-removal case.',
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
required: ['projectId', 'screenIds'],
|
|
210
|
-
},
|
|
211
|
-
output: createOutput(undefined),
|
|
212
|
-
async execute(args, exec) {
|
|
213
|
-
const result = await canvas.removeScreens(args.projectId, args.screenIds, exec);
|
|
214
|
-
const remaining = Array.isArray(result?.screenInstances) ? result.screenInstances.length : 0;
|
|
215
|
-
const lines = [
|
|
216
|
-
`Removed ${result.removed.length} screen(s) from project ${args.projectId}: ${result.removed.join(', ')}.`,
|
|
217
|
-
`The canvas now holds ${remaining} screen(s).`,
|
|
218
|
-
];
|
|
219
|
-
if (result.missing.length > 0) {
|
|
220
|
-
lines.push(`Not on the canvas (left alone): ${result.missing.join(', ')}.`);
|
|
221
|
-
}
|
|
222
|
-
return { content: [{ type: 'text', text: lines.join(' ') }] };
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
|
|
226
269
|
return () => {
|
|
227
270
|
disposed = true;
|
|
228
271
|
cancelRetry?.();
|
|
229
272
|
offCredential();
|
|
230
|
-
removeScreenDispose();
|
|
231
273
|
for (const dispose of disposers) dispose();
|
|
232
274
|
disposers = [];
|
|
233
275
|
};
|
|
234
276
|
}, 'stitch-designer: Stitch tools');
|
|
235
277
|
});
|
|
236
278
|
|
|
237
|
-
// ------------------------------------------------------------ annotation
|
|
238
|
-
// The withdrawn half of the toolset (see `ANNOUNCED_TOOLS`): registered and
|
|
239
|
-
// executable, absent from every request's tool list. Filtering by the public
|
|
240
|
-
// name prefix rather than by a captured registration set keeps this correct
|
|
241
|
-
// when `tools/list` fails at boot and the tools appear later — either
|
|
242
|
-
// through the boot retry or a credential update — the names are the
|
|
243
|
-
// contract, the set of them is not.
|
|
244
|
-
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
|
|
245
|
-
const assembly = await next();
|
|
246
|
-
const tools = withoutWithdrawn(assembly.tools, PUBLIC_PREFIX);
|
|
247
|
-
return tools === assembly.tools ? assembly : { ...assembly, tools };
|
|
248
|
-
});
|
|
249
|
-
|
|
250
279
|
// ------------------------------------------------------------- guidance
|
|
251
280
|
// The design conventions that cannot be enforced are announced instead, the
|
|
252
281
|
// way this repository delivers every other non-computable rule. Read through
|
package/lib/tools.js
CHANGED
|
@@ -61,64 +61,7 @@ export function publicToolName(serverName, rawName) {
|
|
|
61
61
|
return `${normalized.slice(0, MAX_PUBLIC_NAME_LENGTH - HASH_LENGTH - 1)}_${hash}`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/**
|
|
65
|
-
* Stitch tools whose definitions stay in the prompt; every other one is withdrawn.
|
|
66
|
-
*
|
|
67
|
-
* Measured on the live `tools/list` (2026-11-11): the 17 definitions cost 45,680
|
|
68
|
-
* characters of a 180,629-character first request, and across 651 local sessions
|
|
69
|
-
* the two heaviest were called twice. Withdrawing a definition from the prompt
|
|
70
|
-
* does not unregister the tool — execution resolves through the registry's layer
|
|
71
|
-
* visibility, not through the assembly — so a model that names one still gets it
|
|
72
|
-
* run; what it loses is the schema, which for simple string-id tools is not the
|
|
73
|
-
* thing that decides whether the call is right.
|
|
74
|
-
*
|
|
75
|
-
* The split follows that test, not usage: a tool stays announced when its
|
|
76
|
-
* arguments are structures the model cannot guess (a `DesignSystem`,
|
|
77
|
-
* a `VariantOptions`, a `screenInstances` entry), and is withdrawn when they are
|
|
78
|
-
* a project id, a screen id, a title or a prompt — all of which the guidance
|
|
79
|
-
* section spells out. The two design-system writers alone are 15,815 characters,
|
|
80
|
-
* so keeping them announced is what makes the split worth anything.
|
|
81
|
-
*/
|
|
82
|
-
export const ANNOUNCED_TOOLS = new Set([
|
|
83
|
-
'create_design_system',
|
|
84
|
-
'create_design_system_from_design_md',
|
|
85
|
-
'apply_design_system',
|
|
86
|
-
'upload_design_md',
|
|
87
|
-
'generate_screen_from_text',
|
|
88
|
-
'edit_screens',
|
|
89
|
-
'generate_variants',
|
|
90
|
-
]);
|
|
91
64
|
|
|
92
|
-
/**
|
|
93
|
-
* Whether one upstream Stitch tool keeps its definition in the prompt.
|
|
94
|
-
*
|
|
95
|
-
* @param rawName - Stitch's own tool name.
|
|
96
|
-
* @returns `true` when the definition is announced.
|
|
97
|
-
*/
|
|
98
|
-
export function isAnnounced(rawName) {
|
|
99
|
-
return ANNOUNCED_TOOLS.has(rawName);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Drop the withdrawn Stitch definitions from an assembled tool list.
|
|
104
|
-
*
|
|
105
|
-
* Names outside the `mcp__<server>__` namespace pass through untouched: the
|
|
106
|
-
* assembly holds every provider's tools, and only this plugin's are its to
|
|
107
|
-
* remove. The prefix test is against the public name, not a captured
|
|
108
|
-
* registration set, so a `tools/list` that failed at boot and succeeded later on
|
|
109
|
-
* a credential update still gets filtered.
|
|
110
|
-
*
|
|
111
|
-
* @param tools - the assembly's tool definitions.
|
|
112
|
-
* @param prefix - the public-name prefix this plugin registers under.
|
|
113
|
-
* @returns the same array when nothing was withdrawn, otherwise a filtered copy.
|
|
114
|
-
*/
|
|
115
|
-
export function withoutWithdrawn(tools, prefix) {
|
|
116
|
-
if (!Array.isArray(tools)) return tools;
|
|
117
|
-
const kept = tools.filter(
|
|
118
|
-
(tool) => typeof tool?.name !== 'string' || !tool.name.startsWith(prefix) || isAnnounced(tool.name.slice(prefix.length)),
|
|
119
|
-
);
|
|
120
|
-
return kept.length === tools.length ? tools : kept;
|
|
121
|
-
}
|
|
122
65
|
|
|
123
66
|
/**
|
|
124
67
|
* `x-google-*` fields the prompt pays for and the model cannot use.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logictan/dsh-stitch-designer",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "DSH Stitch designer: Google Stitch AI UI generation as native mcp__stitch__* tools, plus the design conventions that keep one code project bound to one Stitch project. DSH Stitch 界面设计子插件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
77
|
-
"@deepseek-ai/dsh-
|
|
77
|
+
"@deepseek-ai/dsh-scope": "^0.2.1-rc.2",
|
|
78
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
|
|
80
|
+
"@logictan/dsh-tool-toolsets": "^0.1.0"
|
|
78
81
|
}
|
|
79
|
-
}
|
|
82
|
+
}
|