@logictan/dsh-stitch-designer 2.1.4 → 2.1.6
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/README.md +24 -10
- package/lib/guidance.js +40 -23
- package/lib/index.js +142 -89
- package/lib/tools.js +0 -57
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -79,17 +79,18 @@ Setting the key registers the tools immediately; no restart is needed.
|
|
|
79
79
|
|
|
80
80
|
## Design conventions
|
|
81
81
|
|
|
82
|
-
Two groups of rules apply: how a screen is commissioned, and how it
|
|
83
|
-
implemented.
|
|
82
|
+
Two groups of rules apply: how a screen is commissioned and reviewed, and how it
|
|
83
|
+
is then implemented.
|
|
84
84
|
|
|
85
|
-
Commissioning:
|
|
85
|
+
Commissioning and review:
|
|
86
86
|
|
|
87
87
|
| Rule | Why |
|
|
88
88
|
| --- | --- |
|
|
89
|
-
| Say what to show
|
|
89
|
+
| Say what to show, what to leave out, and which functional styles to keep | The brief names the content, the existing components, what must not appear, and the styles that carry meaning — status colours, required-field markers, a component's own emphasis level. Everything else (layout, spacing, decorative colour, type, motion) is left to Stitch; a brief that fixes it turns design into transcription. The carve-out is narrow on purpose: name what the style conveys and where, never a whole visual spec. |
|
|
90
|
+
| Read the project's own conventions first | A project's design docs, status-colour table and reusable component layer outrank anything decided in the brief. Compose the screen from those components rather than redrawing a lookalike. |
|
|
90
91
|
| Ask for nothing that cannot be built | The screen is going to be reproduced pixel for pixel, so a wish for an impossible interaction or unavailable data is a defect in the brief. |
|
|
92
|
+
| Review the screen for pixel fidelity before writing code | **Except for dynamic data** (runtime values: real names, API lists, timestamps, chart numbers), the screen must be reproducible pixel for pixel — structure, hierarchy, spacing, colour, type, radii, borders, icons, copy, states. Dynamic data may appear as placeholder content. A screen that fails this is revised with `edit_screens` and its superseded id cleared; it never reaches the implementation. |
|
|
91
93
|
| Describe a design language only when the implementation must match one — and describe it, don't name it | The one exception to "no style limits": when a screen has to fit an existing visual system (here, `@logictan/dsh-macos-theme`), the brief must say what that system actually looks like — colour values, radii, borders, type weights and sizes, spacing density, light/dark relationships. Stitch does not know our package or theme names; pass the theme's own design-system text verbatim when the project has one. With no such constraint, specify no design language at all. |
|
|
92
|
-
| Compose it from components the project already has | Host components and the shared component layer exist; a redrawn lookalike is work spent twice. |
|
|
93
94
|
| Revise with `edit_screens`, and keep exactly one copy of each screen | An edit produces a new screen id instead of overwriting the old one, so the design is changed in place and the id it superseded is removed with `remove_screens_from_canvas`. A canvas holding abandoned drafts and tried variants hides which screen is current — and the removal is irreversible, so which ids were superseded is settled before it is called. |
|
|
94
95
|
| Commission the light screen first, and one dedicated dark screen for the tokens | Dark is the same design language's dark values, not an inversion, so the tokens have to be decided somewhere the model can see them: one extra screen settles background, surface, border, foreground and accent values. Every other screen then exists only in light, and is implemented in both modes from those tokens. Later adds, edits and deletes touch the light screens only. |
|
|
95
96
|
|
|
@@ -98,14 +99,27 @@ Implementation:
|
|
|
98
99
|
| Rule | How it reaches the model |
|
|
99
100
|
| --- | --- |
|
|
100
101
|
| One code project owns exactly one Stitch project | **Enforced.** The id is recorded in the code project's `.stitch.json`; a second `create_project` from an already-bound directory is refused with the existing id. |
|
|
101
|
-
| Implement with TailwindCSS, the way Stitch builds its screens |
|
|
102
|
-
| Implement from Stitch's exported HTML for pixel-level fidelity |
|
|
102
|
+
| Implement with TailwindCSS, the way Stitch builds its screens | Carried by the `stitch_design` toolset's `guidance` and the `stitch-design` skill. Unless the repository already has an architecture that cannot accommodate TailwindCSS, in which case the model is told to explain that first. |
|
|
103
|
+
| Implement from Stitch's exported HTML for pixel-level fidelity | Same two paths. The export goes to `<project>/docs/design/<screenId>.html`; anywhere the implementation would differ from the design, the model is told to ask first and give the reason. |
|
|
103
104
|
|
|
104
105
|
Only the one-project rule is enforced in code, because it is the only one with a
|
|
105
106
|
computable predicate. "Did you use TailwindCSS?" and "is this pixel-perfect?"
|
|
106
|
-
cannot be checked, so a validator for them would be a lie
|
|
107
|
-
|
|
108
|
-
system
|
|
107
|
+
cannot be checked, so a validator for them would be a lie.
|
|
108
|
+
|
|
109
|
+
The prose travels on two paths, and neither is the system prompt — it used to be
|
|
110
|
+
a `systemPrompt.section()`, which made every session in every repository pay
|
|
111
|
+
~1,100 characters for rules it would never act on:
|
|
112
|
+
|
|
113
|
+
1. **The `stitch_design` toolset's `guidance`**, returned by `get_tools` the
|
|
114
|
+
moment an agent loads the Stitch tools. Commissioning a screen is exactly
|
|
115
|
+
when these rules bind, and an agent that never designs anything pays nothing.
|
|
116
|
+
A redundant load returns them again, so a session that compacted its context
|
|
117
|
+
gets the rules back with the tools.
|
|
118
|
+
2. **An embedded skill, `stitch-design`**, for the work that calls no Stitch
|
|
119
|
+
tool at all: implementing an already-exported
|
|
120
|
+
`docs/design/<screenId>.html`. It is registered with `ctx.skills.register()`
|
|
121
|
+
from a nested `ctx.inject`, so a host without a skill registry loses the
|
|
122
|
+
skill and keeps the tools.
|
|
109
123
|
|
|
110
124
|
`.stitch.json` is the project's own file — commit it. It is small and
|
|
111
125
|
hand-editable on purpose: it is the escape hatch when a Stitch project was
|
package/lib/guidance.js
CHANGED
|
@@ -5,30 +5,47 @@
|
|
|
5
5
|
* this pixel-perfect?" have no computable predicate, so a validator for them
|
|
6
6
|
* would be a lie — it would either pass everything or block correct work. They
|
|
7
7
|
* are delivered the way this repository delivers every other non-computable
|
|
8
|
-
* rule: as
|
|
9
|
-
*
|
|
10
|
-
* having to remember to ask.
|
|
8
|
+
* rule: as text the plugin owns, so the model reads it in every session without
|
|
9
|
+
* anyone having to remember to ask.
|
|
11
10
|
*
|
|
12
11
|
* The one convention with a computable predicate — one code project owns one
|
|
13
12
|
* Stitch project — is **not** here. It is enforced in `src/conventions.js`,
|
|
14
13
|
* because a rule the model can silently break is not a rule. This file is only
|
|
15
14
|
* the text.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
* ## Where this text is delivered, and why it moved
|
|
17
|
+
*
|
|
18
|
+
* It used to be a `ctx.systemPrompt.section()`, which made every session in
|
|
19
|
+
* every repository pay ~1,100 characters for rules it would never act on. It
|
|
20
|
+
* now travels on two paths that each match when the rules actually matter:
|
|
21
|
+
*
|
|
22
|
+
* - **The `stitch_design` toolset's `guidance`**, returned by `get_tools` at
|
|
23
|
+
* the moment an agent loads the Stitch tools. Commissioning a screen is
|
|
24
|
+
* exactly when these rules bind, and an agent that never designs anything
|
|
25
|
+
* pays nothing.
|
|
26
|
+
* - **An embedded skill (`stitch-design`)**, so the same rules are reachable
|
|
27
|
+
* when the work is implementing an already-exported
|
|
28
|
+
* `<project>/docs/design/<screenId>.html` and no Stitch tool is called at
|
|
29
|
+
* all. That path is why the skill exists rather than the toolset alone.
|
|
30
|
+
*
|
|
31
|
+
* The rules fall in two groups, and the split is the point: commissioning
|
|
32
|
+
* governs what to ask Stitch for, implementation governs what the code does
|
|
33
|
+
* with the result. A brief that over-specifies produces a screen no better than
|
|
34
|
+
* hand-written code, and a screen containing what cannot be built is a defect
|
|
35
|
+
* discovered only at implementation time — both are cheaper to prevent when the
|
|
36
|
+
* model is told before it writes the prompt.
|
|
23
37
|
*
|
|
24
38
|
* @module @logictan/dsh-stitch-designer/guidance
|
|
25
39
|
*/
|
|
26
40
|
|
|
27
|
-
/**
|
|
28
|
-
export const
|
|
41
|
+
/** Name of the embedded skill carrying these rules. Kebab-case, model-facing. */
|
|
42
|
+
export const SKILL_NAME = 'stitch-design';
|
|
29
43
|
|
|
30
|
-
/**
|
|
31
|
-
export const
|
|
44
|
+
/** One-line routing description; this is what the skill catalog shows. */
|
|
45
|
+
export const SKILL_DESCRIPTION =
|
|
46
|
+
'Commission UI screens from Google Stitch and implement them pixel for pixel. '
|
|
47
|
+
+ 'Use when a screen is to be designed or generated with Stitch, or when implementing an '
|
|
48
|
+
+ 'already-exported Stitch design (<project>/docs/design/<screenId>.html) as code.';
|
|
32
49
|
|
|
33
50
|
/**
|
|
34
51
|
* What the model is told about Stitch, and about implementing its designs.
|
|
@@ -38,20 +55,20 @@ export const SECTION_ORDER = 150;
|
|
|
38
55
|
* acted on.
|
|
39
56
|
*/
|
|
40
57
|
export const STITCH_GUIDANCE = [
|
|
41
|
-
'本机已安装 dsh-stitch-designer 插件(Google Stitch AI 界面设计):提供 Stitch 原生工具(数量随上游变化,含建/删/列项目、列/取界面、生成界面、改界面、生成变体、设计系统、设计稿上传与文件下载),以及 1 个本插件自建的 `mcp__stitch__remove_screens_from_canvas`(把一张或多张 screen 从项目画布上移除;传一个 id 就是删一张——Stitch 没有删除单张 screen 的接口)。',
|
|
42
|
-
'',
|
|
43
|
-
'Stitch 全部工具的参数表都不在提示词里(由 dsh-tool-surface 撤下),参数按 dsh-tool-surface 的 stitch 组说明填,直接按名调用即可。其中 `create_design_system`、`update_design_system` 结构复杂(`$defs` 三层嵌套、字体枚举 68 个),先读插件 README 或用 `mcp__stitch__get_project` 读项目里已存的设计系统资产,不要凭空猜字段。',
|
|
44
|
-
'',
|
|
45
58
|
'用 Stitch 设计稿实现界面时,遵守以下规范:',
|
|
46
59
|
'1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
|
|
47
60
|
'2. 实现时使用 TailwindCSS,与 Stitch 生成设计稿的方式保持一致;除非该项目已有架构无法兼容 TailwindCSS,此时先说明是哪一处不兼容、为什么不兼容,再动手。',
|
|
48
61
|
'3. 先导出 Stitch 的设计稿 HTML,照着它实现,尽可能做到像素级还原。设计稿 HTML 落在 `<项目>/docs/design/<screenId>.html`,应提交到版本库。凡实现需要与设计稿不一致的地方,先问用户并给出理由,不要自行偏离。',
|
|
49
62
|
'',
|
|
50
63
|
'下单给 Stitch 时,遵守以下规范:',
|
|
51
|
-
'4.
|
|
52
|
-
'5.
|
|
53
|
-
'6.
|
|
54
|
-
'7.
|
|
55
|
-
'
|
|
56
|
-
'
|
|
64
|
+
'4. 提示词只说明三样东西:需要显示什么内容、用哪些已有组件,以及不需要显示什么(不要出现的模块、数据、交互)。布局、间距、装饰性配色、字体、动效等样式一律不写,让它自由发挥。把样式写死成一份详细规格,等于让它照着抄,产出的稿子不会比你自己写的更好。',
|
|
65
|
+
'5. 有一类样式必须写进提示词:带功能语义、实现时不能改的样式。典型的是状态指示色(成功/警告/错误、在线/离线、必填标记),以及已有组件自带的尺寸或强调层级——它们表达信息,不是装饰,改掉就等于改需求。只点名这类样式要表达什么、在哪些元素上,不要借此扩写成整套视觉规格。',
|
|
66
|
+
'6. 唯一需要交代整套样式的情况:实现必须与某个既有设计语言保持一致时(例如要求按 `@logictan/dsh-macos-theme` 出稿)。但只报名字没用,Stitch 不认识你的包名和主题名。要把那套语言实际长什么样告诉它:颜色取值、圆角、描边、字重与字号层级、间距密度、明暗关系。项目里已有设计系统说明(如主题包的设计系统文档或 Stitch 的 design system)就直接给原文,不要只给一个标识符。没有这种一致性要求时,不要指定任何设计语言。',
|
|
67
|
+
'7. 下单前先看目标项目自己已经定了什么:设计文档与设计系统、状态色表、可复用的宿主组件与共享组件层。稿子要由这些组件拼出来,而不是重画一套长得像的;项目已有的视觉约定优先于你的临场发挥。要沿用项目里已存的设计系统时,先用 `mcp__stitch__get_project` 读出它的资产再改,不要凭空猜 `create_design_system` / `update_design_system` 的字段(schema 三层嵌套、字体枚举 68 个)。',
|
|
68
|
+
'',
|
|
69
|
+
'审核设计稿时,遵守以下规范:',
|
|
70
|
+
'8. 设计稿最终要被逐像素还原,所以稿子里不得出现无法实现的功能和元素。写提示词时就假定它会被逐像素实现:不要许愿一个做不到的交互、一个实现不了的效果,或一份拿不到的数据。',
|
|
71
|
+
'9. 出稿后先按这条审核,再动代码:**除动态数据外,设计稿必须能被逐像素还原**。动态数据指运行时才有的值(真实用户名、接口返回的列表、时间戳、图表数值),它们在稿里可以是示意内容。除此之外——结构、层级、间距、颜色、字体、圆角、描边、图标、文案、状态——都必须能在实现里照抄到位。发现做不到的结构或效果、编造的字段、拿不到的数据,不要带着问题进实现:先用 `edit_screens` 在原稿上改掉,改完把被取代的旧 id 清掉。',
|
|
72
|
+
'10. 改设计稿尽量用 `edit_screens` 在原稿上改,不要重新 `generate_screen_from_text` 出一张新稿来替代它。同一份设计稿在项目里只保留一份:`edit_screens` 会生成新的 screen id 而不是原地覆盖,所以改完要把被取代的旧 id 用 `mcp__stitch__remove_screens_from_canvas` 从画布移除(传一个 id 就是删一张)。画布上只该有当前有效的那一稿,废弃的旧稿、试出来的变体稿都按这条清掉。移除不可撤销,删之前先确认哪些 id 已被取代。',
|
|
73
|
+
'11. 先出明色(亮色)版。暗色只另外出一页,用来确定暗色下的配色 token(背景、表面、描边、文字、强调色各自的取值与层级);不要为每一页都出暗色稿——那一页就够,其余页面靠它定的 token 在实现时一并给出。此后新增、修改、删除设计稿一律只针对明色版,不要再给暗色出稿。暗色不是把明色反相,而是同一套设计语言在暗色下的取值:颜色、描边、层级都要按暗色重新给,实现时两边共用同一套 token。',
|
|
57
74
|
].join('\n');
|
package/lib/index.js
CHANGED
|
@@ -40,12 +40,93 @@
|
|
|
40
40
|
import { createCanvasClient } from './canvas.js';
|
|
41
41
|
import { createStitchClient } from './stitch.js';
|
|
42
42
|
import { createInvoker } from './conventions.js';
|
|
43
|
-
import {
|
|
44
|
-
import { createOutput, createToolDefinition, publicToolName, retryWithBackoff
|
|
43
|
+
import { SKILL_DESCRIPTION, SKILL_NAME, STITCH_GUIDANCE } from './guidance.js';
|
|
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,25 @@ 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
|
+
// The rules travel with the load, not with the system prompt: an
|
|
237
|
+
// agent that never designs anything pays nothing for them, and the
|
|
238
|
+
// one that loads the Stitch tools reads them in the same result.
|
|
239
|
+
guidance: STITCH_GUIDANCE,
|
|
240
|
+
tools: next,
|
|
241
|
+
})];
|
|
242
|
+
toolsCtx.logger.info(`stitch-designer: toolset ${TOOLSET_NAME} carries ${next.length} mcp__${SERVER_NAME}__* tools`);
|
|
149
243
|
};
|
|
150
244
|
|
|
151
245
|
// One attempt plus bounded backoff, so the boot fetch that failed
|
|
@@ -176,95 +270,54 @@ export function apply(ctx) {
|
|
|
176
270
|
syncWithRetry();
|
|
177
271
|
});
|
|
178
272
|
|
|
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
273
|
return () => {
|
|
227
274
|
disposed = true;
|
|
228
275
|
cancelRetry?.();
|
|
229
276
|
offCredential();
|
|
230
|
-
removeScreenDispose();
|
|
231
277
|
for (const dispose of disposers) dispose();
|
|
232
278
|
disposers = [];
|
|
233
279
|
};
|
|
234
280
|
}, 'stitch-designer: Stitch tools');
|
|
235
281
|
});
|
|
236
282
|
|
|
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
283
|
// ------------------------------------------------------------- guidance
|
|
251
284
|
// The design conventions that cannot be enforced are announced instead, the
|
|
252
|
-
// way this repository delivers every other non-computable rule.
|
|
253
|
-
//
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
285
|
+
// way this repository delivers every other non-computable rule. They are NOT
|
|
286
|
+
// a system-prompt section any more: that made every session in every
|
|
287
|
+
// repository pay ~1,100 characters for rules it would never act on.
|
|
288
|
+
//
|
|
289
|
+
// Two delivery paths, each covering a case the other misses:
|
|
290
|
+
//
|
|
291
|
+
// - the toolset's `guidance` (above), read the moment an agent loads the
|
|
292
|
+
// Stitch tools — the moment a screen gets commissioned;
|
|
293
|
+
// - an embedded skill, for the work that never calls a Stitch tool:
|
|
294
|
+
// implementing an already-exported `docs/design/<screenId>.html`.
|
|
295
|
+
//
|
|
296
|
+
// Read through a nested `ctx.inject` rather than the plugin-level `inject`,
|
|
297
|
+
// and rather than a one-shot `ctx.get`. `get` is strict about the provider's
|
|
298
|
+
// fiber being ACTIVE, and providers come up asynchronously — a service read
|
|
299
|
+
// once in `apply` can legitimately be `undefined` (the same race that left the
|
|
300
|
+
// Stitch tools unregistered on a cold start, see the note above). A nested
|
|
301
|
+
// `inject` waits for the provider and costs only the skill if it never comes:
|
|
302
|
+
// the plugin-level `inject` would instead skip the whole plugin, which is the
|
|
303
|
+
// "no skill registry means no Stitch tools at all" failure this file avoids
|
|
304
|
+
// everywhere else.
|
|
305
|
+
ctx.inject(['skills'], (skillsCtx) => {
|
|
306
|
+
const skills = skillsCtx.get('skills');
|
|
307
|
+
skillsCtx.effect(
|
|
308
|
+
() =>
|
|
309
|
+
skills.register({
|
|
310
|
+
name: SKILL_NAME,
|
|
311
|
+
description: SKILL_DESCRIPTION,
|
|
312
|
+
content: STITCH_GUIDANCE,
|
|
313
|
+
// Required, and not defaulted by the registry: `register()` fills in
|
|
314
|
+
// `invocation` and `provider` only, while `get()` validates `source`
|
|
315
|
+
// as a string. Omitting it registers a skill whose catalog entry
|
|
316
|
+
// exists and whose body cannot be loaded — measured 2026-12-04:
|
|
317
|
+
// `TypeError: loaded skill "stitch-design" source must be a string`.
|
|
318
|
+
source: 'runtime',
|
|
319
|
+
}),
|
|
320
|
+
'stitch-designer: stitch-design skill',
|
|
321
|
+
);
|
|
322
|
+
});
|
|
270
323
|
}
|
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.6",
|
|
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,10 @@
|
|
|
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-skill": "^0.2.1-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
|
|
80
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
|
|
81
|
+
"@logictan/dsh-tool-toolsets": "^0.1.0"
|
|
78
82
|
}
|
|
79
83
|
}
|