@logictan/dsh-stitch-designer 2.1.2 → 2.1.4
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 +2 -1
- package/lib/guidance.js +2 -1
- package/lib/index.js +49 -11
- package/lib/tools.js +58 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,7 +90,8 @@ Commissioning:
|
|
|
90
90
|
| 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. |
|
|
91
91
|
| 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
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
|
-
|
|
|
93
|
+
| 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
|
+
| 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. |
|
|
94
95
|
|
|
95
96
|
Implementation:
|
|
96
97
|
|
package/lib/guidance.js
CHANGED
|
@@ -52,5 +52,6 @@ export const STITCH_GUIDANCE = [
|
|
|
52
52
|
'5. 唯一例外:当实现必须与某个既有设计语言保持一致时(例如要求按 `@logictan/dsh-macos-theme` 出稿),才需要交代样式——但只报名字没用,Stitch 不认识你的包名和主题名。要把那套语言实际长什么样告诉它:颜色取值、圆角、描边、字重与字号层级、间距密度、明暗关系。项目里已有设计系统说明(如主题包的设计系统文档或 Stitch 的 design system)就直接给原文,不要只给一个标识符。没有这种一致性要求时,不要指定任何设计语言。',
|
|
53
53
|
'6. 设计稿最终要被像素级还原,所以稿子里不得出现无法实现的功能和元素。写提示词时就假定它会被逐像素实现:不要许愿一个做不到的交互、一个实现不了的效果,或一份拿不到的数据。',
|
|
54
54
|
'7. 尽可能复用已有组件。出稿前先看项目里已经有什么(宿主组件、共享组件层),让稿子由这些组件拼出来,而不是重画一套长得像的。',
|
|
55
|
-
'8.
|
|
55
|
+
'8. 先出明色(亮色)版。暗色只另外出一页,用来确定暗色下的配色 token(背景、表面、描边、文字、强调色各自的取值与层级);不要为每一页都出暗色稿——那一页就够,其余页面靠它定的 token 在实现时一并给出。此后新增、修改、删除设计稿一律只针对明色版,不要再给暗色出稿。暗色不是把明色反相,而是同一套设计语言在暗色下的取值:颜色、描边、层级都要按暗色重新给,实现时两边共用同一套 token。',
|
|
56
|
+
'9. 改设计稿尽量用 `edit_screens` 在原稿上改,不要重新 `generate_screen_from_text` 出一张新稿来替代它。同一份设计稿在项目里只保留一份:`edit_screens` 会生成新的 screen id 而不是原地覆盖,所以改完要把被取代的旧 id 用 `mcp__stitch__remove_screens_from_canvas` 从画布移除(传一个 id 就是删一张)。画布上只该有当前有效的那一稿,废弃的旧稿、试出来的变体稿都按这条清掉。移除不可撤销,删之前先确认哪些 id 已被取代。',
|
|
56
57
|
].join('\n');
|
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, withoutWithdrawn } from './tools.js';
|
|
44
|
+
import { createOutput, createToolDefinition, publicToolName, retryWithBackoff, 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';
|
|
@@ -61,6 +61,26 @@ export const SERVER_NAME = 'stitch';
|
|
|
61
61
|
/** The prefix every tool this plugin registers carries, announcement filter included. */
|
|
62
62
|
const PUBLIC_PREFIX = `mcp__${SERVER_NAME}__`;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* How the boot-time `tools/list` is retried before the tools are given up on.
|
|
66
|
+
*
|
|
67
|
+
* The definitions are not shipped statically — they ARE the upstream catalogs —
|
|
68
|
+
* so registration happens only after a successful `tools/list`, and that fetch
|
|
69
|
+
* is the one thing that can fail transiently at boot: the credential store may
|
|
70
|
+
* not be live yet on a cold start, or the network hiccups. The credential-update
|
|
71
|
+
* event covers the "key set later" case, but a key already present at boot never
|
|
72
|
+
* fires it, so without a self-retry a single failed fetch left the tools
|
|
73
|
+
* unregistered for the whole process lifetime while the system prompt still
|
|
74
|
+
* claimed they existed — the model then called `mcp__stitch__*` and got
|
|
75
|
+
* "unknown tool" (observed live 2026-11-13: 18 tools reachable via the API, yet
|
|
76
|
+
* none registered because the one boot fetch failed).
|
|
77
|
+
*
|
|
78
|
+
* Bounded exponential backoff, then give up with a warning: an unrecoverable
|
|
79
|
+
* failure (wrong key, Stitch down) must not spin forever. The credential-update
|
|
80
|
+
* event remains the recovery path after that point.
|
|
81
|
+
*/
|
|
82
|
+
const SYNC_RETRY_DELAYS_MS = [500, 1000, 2000, 4000, 8000];
|
|
83
|
+
|
|
64
84
|
/**
|
|
65
85
|
* Register the Stitch tools and announce the design conventions.
|
|
66
86
|
*
|
|
@@ -109,8 +129,9 @@ export function apply(ctx) {
|
|
|
109
129
|
toolsCtx.effect(() => {
|
|
110
130
|
let disposed = false;
|
|
111
131
|
let disposers = [];
|
|
132
|
+
let cancelRetry;
|
|
112
133
|
|
|
113
|
-
const
|
|
134
|
+
const registerListed = async () => {
|
|
114
135
|
const listed = await stitch.listTools();
|
|
115
136
|
if (disposed) return;
|
|
116
137
|
const next = listed.map((tool) =>
|
|
@@ -127,17 +148,32 @@ export function apply(ctx) {
|
|
|
127
148
|
toolsCtx.logger.info(`stitch-designer: registered ${disposers.length} mcp__${SERVER_NAME}__* tools`);
|
|
128
149
|
};
|
|
129
150
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
151
|
+
// One attempt plus bounded backoff, so the boot fetch that failed
|
|
152
|
+
// transiently (credential store not live yet, network hiccup) heals
|
|
153
|
+
// itself instead of leaving the tools missing for the process lifetime.
|
|
154
|
+
// A failure that persists through every retry is logged once and left to
|
|
155
|
+
// the credential-update event; an unrecoverable one (wrong key) stops
|
|
156
|
+
// here rather than spinning. Each new run cancels any pending backoff so
|
|
157
|
+
// a mid-flight credential update cannot race an in-progress retry.
|
|
158
|
+
const syncWithRetry = () => {
|
|
159
|
+
cancelRetry?.();
|
|
160
|
+
cancelRetry = retryWithBackoff(registerListed, SYNC_RETRY_DELAYS_MS, {
|
|
161
|
+
shouldStop: () => disposed,
|
|
162
|
+
onRetry: (error, delay) =>
|
|
163
|
+
toolsCtx.logger.warn(
|
|
164
|
+
`stitch-designer: the mcp__${SERVER_NAME}__* tools are not registered yet (${error?.message ?? error}); retrying in ${delay}ms`,
|
|
165
|
+
),
|
|
166
|
+
onGiveUp: (error, attempts) =>
|
|
167
|
+
toolsCtx.logger.warn(
|
|
168
|
+
`stitch-designer: the mcp__${SERVER_NAME}__* tools are not registered after ${attempts} attempts (${error?.message ?? error}); set or fix the API key to retry.`,
|
|
169
|
+
),
|
|
170
|
+
});
|
|
135
171
|
};
|
|
136
172
|
|
|
137
|
-
|
|
173
|
+
syncWithRetry();
|
|
138
174
|
const offCredential = toolsCtx.on('credentials/reference-updated', (ref) => {
|
|
139
175
|
if (ref !== API_KEY_REF || disposers.length > 0) return;
|
|
140
|
-
|
|
176
|
+
syncWithRetry();
|
|
141
177
|
});
|
|
142
178
|
|
|
143
179
|
// `remove_screens_from_canvas` is local, not upstream: Stitch has no
|
|
@@ -189,6 +225,7 @@ export function apply(ctx) {
|
|
|
189
225
|
|
|
190
226
|
return () => {
|
|
191
227
|
disposed = true;
|
|
228
|
+
cancelRetry?.();
|
|
192
229
|
offCredential();
|
|
193
230
|
removeScreenDispose();
|
|
194
231
|
for (const dispose of disposers) dispose();
|
|
@@ -201,8 +238,9 @@ export function apply(ctx) {
|
|
|
201
238
|
// The withdrawn half of the toolset (see `ANNOUNCED_TOOLS`): registered and
|
|
202
239
|
// executable, absent from every request's tool list. Filtering by the public
|
|
203
240
|
// name prefix rather than by a captured registration set keeps this correct
|
|
204
|
-
// when `tools/list` fails at boot and the tools appear later
|
|
205
|
-
//
|
|
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.
|
|
206
244
|
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
|
|
207
245
|
const assembly = await next();
|
|
208
246
|
const tools = withoutWithdrawn(assembly.tools, PUBLIC_PREFIX);
|
package/lib/tools.js
CHANGED
|
@@ -267,3 +267,61 @@ export function createToolDefinition(options) {
|
|
|
267
267
|
},
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Run one async attempt, and on failure schedule bounded retries.
|
|
273
|
+
*
|
|
274
|
+
* The tool list this plugin registers comes from Stitch's own `tools/list`, so
|
|
275
|
+
* registration is only possible after that fetch succeeds — and that fetch is
|
|
276
|
+
* the one thing that can fail transiently at boot (credential store not live
|
|
277
|
+
* yet, network hiccup). A single failed fetch used to leave the tools missing
|
|
278
|
+
* for the whole process lifetime, even though the system prompt still announced
|
|
279
|
+
* them, so the model called `mcp__stitch__*` and got "unknown tool". This is the
|
|
280
|
+
* bounded self-heal: attempt now, and on rejection wait `delays[0]`, retry, wait
|
|
281
|
+
* `delays[1]`, and so on, giving up after the delays run out.
|
|
282
|
+
*
|
|
283
|
+
* Exported and dependency-injected (`schedule`) so the behavior is testable
|
|
284
|
+
* without a live endpoint or real timers.
|
|
285
|
+
*
|
|
286
|
+
* @param attempt - the work; its rejection is what triggers a retry.
|
|
287
|
+
* @param delays - backoff in milliseconds before each retry, in order.
|
|
288
|
+
* @param options - `shouldStop` checked before every retry; `onRetry`/`onGiveUp`
|
|
289
|
+
* notifications; `schedule` timer function that MUST return a canceller.
|
|
290
|
+
* @returns a canceller that stops any pending retry.
|
|
291
|
+
*/
|
|
292
|
+
export function retryWithBackoff(attempt, delays, options = {}) {
|
|
293
|
+
const {
|
|
294
|
+
shouldStop = () => false,
|
|
295
|
+
onRetry,
|
|
296
|
+
onGiveUp,
|
|
297
|
+
// Normalized to return a canceller. Bare `setTimeout` returns a Timeout
|
|
298
|
+
// object, and the teardown path calls the return value — returning the raw
|
|
299
|
+
// timeout would throw "cancelScheduled is not a function" when the effect is
|
|
300
|
+
// unloaded during a backoff window.
|
|
301
|
+
schedule = (fn, delay) => {
|
|
302
|
+
const timeout = setTimeout(fn, delay);
|
|
303
|
+
return () => clearTimeout(timeout);
|
|
304
|
+
},
|
|
305
|
+
} = options;
|
|
306
|
+
let cancelled = false;
|
|
307
|
+
let cancelScheduled;
|
|
308
|
+
|
|
309
|
+
const run = (index) => {
|
|
310
|
+
attempt().catch((error) => {
|
|
311
|
+
if (cancelled || shouldStop()) return;
|
|
312
|
+
if (index >= delays.length) {
|
|
313
|
+
onGiveUp?.(error, index + 1);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const delay = delays[index];
|
|
317
|
+
onRetry?.(error, delay);
|
|
318
|
+
cancelScheduled = schedule(() => run(index + 1), delay);
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
run(0);
|
|
323
|
+
return () => {
|
|
324
|
+
cancelled = true;
|
|
325
|
+
cancelScheduled?.();
|
|
326
|
+
};
|
|
327
|
+
}
|
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.4",
|
|
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",
|