@logictan/dsh-stitch-designer 2.1.0 → 2.1.2
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 +2 -0
- package/lib/index.js +16 -1
- package/lib/tools.js +111 -7
- package/package.json +1 -1
package/lib/guidance.js
CHANGED
|
@@ -40,6 +40,8 @@ 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 全部工具的参数表都不在提示词里(由 dsh-tool-surface 撤下),参数按 dsh-tool-surface 的 stitch 组说明填,直接按名调用即可。其中 `create_design_system`、`update_design_system` 结构复杂(`$defs` 三层嵌套、字体枚举 68 个),先读插件 README 或用 `mcp__stitch__get_project` 读项目里已存的设计系统资产,不要凭空猜字段。',
|
|
44
|
+
'',
|
|
43
45
|
'用 Stitch 设计稿实现界面时,遵守以下规范:',
|
|
44
46
|
'1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
|
|
45
47
|
'2. 实现时使用 TailwindCSS,与 Stitch 生成设计稿的方式保持一致;除非该项目已有架构无法兼容 TailwindCSS,此时先说明是哪一处不兼容、为什么不兼容,再动手。',
|
package/lib/index.js
CHANGED
|
@@ -41,7 +41,7 @@ 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 } from './tools.js';
|
|
44
|
+
import { createOutput, createToolDefinition, publicToolName, withoutWithdrawn } from './tools.js';
|
|
45
45
|
|
|
46
46
|
/** Plugin row id; must equal the row id in `cordis.patch.yml`. */
|
|
47
47
|
export const name = 'stitch-designer';
|
|
@@ -58,6 +58,9 @@ export const API_KEY_REF = 'STITCH_API_KEY';
|
|
|
58
58
|
/** Server namespace embedded in every public tool name (`mcp__stitch__*`). */
|
|
59
59
|
export const SERVER_NAME = 'stitch';
|
|
60
60
|
|
|
61
|
+
/** The prefix every tool this plugin registers carries, announcement filter included. */
|
|
62
|
+
const PUBLIC_PREFIX = `mcp__${SERVER_NAME}__`;
|
|
63
|
+
|
|
61
64
|
/**
|
|
62
65
|
* Register the Stitch tools and announce the design conventions.
|
|
63
66
|
*
|
|
@@ -194,6 +197,18 @@ export function apply(ctx) {
|
|
|
194
197
|
}, 'stitch-designer: Stitch tools');
|
|
195
198
|
});
|
|
196
199
|
|
|
200
|
+
// ------------------------------------------------------------ annotation
|
|
201
|
+
// The withdrawn half of the toolset (see `ANNOUNCED_TOOLS`): registered and
|
|
202
|
+
// executable, absent from every request's tool list. Filtering by the public
|
|
203
|
+
// name prefix rather than by a captured registration set keeps this correct
|
|
204
|
+
// when `tools/list` fails at boot and the tools appear later on a credential
|
|
205
|
+
// update — the names are the contract, the set of them is not.
|
|
206
|
+
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
|
|
207
|
+
const assembly = await next();
|
|
208
|
+
const tools = withoutWithdrawn(assembly.tools, PUBLIC_PREFIX);
|
|
209
|
+
return tools === assembly.tools ? assembly : { ...assembly, tools };
|
|
210
|
+
});
|
|
211
|
+
|
|
197
212
|
// ------------------------------------------------------------- guidance
|
|
198
213
|
// The design conventions that cannot be enforced are announced instead, the
|
|
199
214
|
// way this repository delivers every other non-computable rule. Read through
|
package/lib/tools.js
CHANGED
|
@@ -10,13 +10,15 @@
|
|
|
10
10
|
* Two measured facts drive every choice here (probed against the live
|
|
11
11
|
* `tools/list` of 2026-10-08, all 15 tools):
|
|
12
12
|
*
|
|
13
|
-
* - `parameters` is passed through VERBATIM
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* - `parameters` is passed through VERBATIM, minus the two `x-google-*` fields
|
|
14
|
+
* {@link PROMPT_ONLY_EXTENSIONS} names. `ToolRuntime.register` validates only
|
|
15
|
+
* `output.schema`; it never inspects `definition.parameters`. Stitch's input
|
|
16
|
+
* schemas carry `$defs` / `$ref` / `x-google-*` (11 of 15 fail
|
|
16
17
|
* `assertSupportedJsonSchema`), so routing them through `defineTool` — which
|
|
17
18
|
* validates its `parameters` at construction — would throw for 11 tools.
|
|
18
|
-
* Registering the
|
|
19
|
-
* shape that keeps the upstream contract intact for the model
|
|
19
|
+
* Registering the upstream schema is therefore not a shortcut, it is the only
|
|
20
|
+
* shape that keeps the upstream contract intact for the model; the two fields
|
|
21
|
+
* removed on top of it are prompt weight the model cannot act on.
|
|
20
22
|
* - `output.schema` IS validated, both at registration and again on every
|
|
21
23
|
* result (`createSuccessResult`). 13 of Stitch's 15 advertised
|
|
22
24
|
* `outputSchema`s are outside the accepted subset, so they must be dropped
|
|
@@ -59,6 +61,107 @@ export function publicToolName(serverName, rawName) {
|
|
|
59
61
|
return `${normalized.slice(0, MAX_PUBLIC_NAME_LENGTH - HASH_LENGTH - 1)}_${hash}`;
|
|
60
62
|
}
|
|
61
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
|
+
|
|
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
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `x-google-*` fields the prompt pays for and the model cannot use.
|
|
125
|
+
*
|
|
126
|
+
* Measured on the live `tools/list` (2026-11-11): `create_design_system` and
|
|
127
|
+
* `update_design_system` carry 4,744 characters of `x-google-enum-descriptions`
|
|
128
|
+
* each — one English gloss per font enum value, restating the value it sits on —
|
|
129
|
+
* plus 1,460 characters of `x-google-enum-deprecated`, every entry `false`.
|
|
130
|
+
* Together 44% of each 14,000-character schema, and across 651 local sessions
|
|
131
|
+
* the pair was called twice. The enum values themselves are untouched, so the
|
|
132
|
+
* model still sees every legal font; only the glosses and the all-false flags go.
|
|
133
|
+
*/
|
|
134
|
+
const PROMPT_ONLY_EXTENSIONS = new Set(['x-google-enum-descriptions', 'x-google-enum-deprecated']);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Copy an upstream input schema with its prompt-only extension fields removed.
|
|
138
|
+
*
|
|
139
|
+
* `parameters` is otherwise passed through verbatim (see the module note), so
|
|
140
|
+
* this is a subtraction, never a rewrite: object keys, ordering, `$defs`,
|
|
141
|
+
* `$ref`, `oneOf` and every standard keyword survive as they arrive. The schema
|
|
142
|
+
* is not validated here — the runtime does not inspect `parameters`, and
|
|
143
|
+
* Stitch's own schemas would fail `assertSupportedJsonSchema`.
|
|
144
|
+
*
|
|
145
|
+
* @param schema - the upstream `inputSchema`.
|
|
146
|
+
* @returns the same schema, or a copy without {@link PROMPT_ONLY_EXTENSIONS}.
|
|
147
|
+
*/
|
|
148
|
+
export function promptSafeInputSchema(schema) {
|
|
149
|
+
if (schema === null || typeof schema !== 'object') return schema;
|
|
150
|
+
if (Array.isArray(schema)) return schema.map(promptSafeInputSchema);
|
|
151
|
+
let changed = false;
|
|
152
|
+
const copy = {};
|
|
153
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
154
|
+
if (PROMPT_ONLY_EXTENSIONS.has(key)) {
|
|
155
|
+
changed = true;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const next = promptSafeInputSchema(value);
|
|
159
|
+
if (next !== value) changed = true;
|
|
160
|
+
copy[key] = next;
|
|
161
|
+
}
|
|
162
|
+
return changed ? copy : schema;
|
|
163
|
+
}
|
|
164
|
+
|
|
62
165
|
/**
|
|
63
166
|
* Keep an advertised output schema only if the runtime accepts it.
|
|
64
167
|
*
|
|
@@ -137,7 +240,8 @@ export function createOutput(structuredSchema) {
|
|
|
137
240
|
/**
|
|
138
241
|
* Adapt one upstream Stitch tool descriptor to a ToolRuntime definition.
|
|
139
242
|
*
|
|
140
|
-
* `parameters` is the raw upstream `inputSchema`
|
|
243
|
+
* `parameters` is the raw upstream `inputSchema` minus {@link PROMPT_ONLY_EXTENSIONS}
|
|
244
|
+
* (see the module note); every other field arrives as Stitch sent it. The
|
|
141
245
|
* result is unregistered; the caller owns registration lifetime.
|
|
142
246
|
*
|
|
143
247
|
* @param options - upstream descriptor fields plus the raw-result callback.
|
|
@@ -148,7 +252,7 @@ export function createToolDefinition(options) {
|
|
|
148
252
|
return {
|
|
149
253
|
name,
|
|
150
254
|
description,
|
|
151
|
-
parameters: inputSchema,
|
|
255
|
+
parameters: promptSafeInputSchema(inputSchema),
|
|
152
256
|
output: createOutput(supportedOutputSchema(outputSchema)),
|
|
153
257
|
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
154
258
|
async execute(args, exec) {
|
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.2",
|
|
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",
|