@logictan/dsh-stitch-designer 2.0.0 → 2.0.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/README.md CHANGED
@@ -45,7 +45,20 @@ Setting the key registers the tools immediately; no restart is needed.
45
45
 
46
46
  ## Design conventions
47
47
 
48
- Three rules apply when a Stitch design is implemented as code in a repository.
48
+ Two groups of rules apply: how a screen is commissioned, and how it is then
49
+ implemented.
50
+
51
+ Commissioning:
52
+
53
+ | Rule | Why |
54
+ | --- | --- |
55
+ | Say what to show and what to leave out, and nothing about style | The brief names the content and the existing components, plus what must not appear. Layout, spacing, colour, type and motion are left to Stitch; a brief that fixes them turns design into transcription, no better than writing it by hand. |
56
+ | 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. |
57
+ | 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. |
58
+ | Compose it from components the project already has | Host components and the shared component layer exist; a redrawn lookalike is work spent twice. |
59
+ | Ask for a dark variant every time | Dark is the same design language's dark values, not an inversion. Both are implemented from one set of tokens. |
60
+
61
+ Implementation:
49
62
 
50
63
  | Rule | How it reaches the model |
51
64
  | --- | --- |
@@ -53,11 +66,11 @@ Three rules apply when a Stitch design is implemented as code in a repository.
53
66
  | Implement with TailwindCSS, the way Stitch builds its screens | Announced in the system prompt. Unless the repository already has an architecture that cannot accommodate TailwindCSS, in which case the model is told to explain that first. |
54
67
  | Implement from Stitch's exported HTML for pixel-level fidelity | Announced in the system prompt. 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. |
55
68
 
56
- The first rule is enforced in code and the other two are announced, because only
57
- the first has a computable predicate. "Did you use TailwindCSS?" and "is this
58
- pixel-perfect?" cannot be checked, so a validator for them would be a lie — they
59
- are delivered the way this repository delivers every other non-computable rule,
60
- as a system-prompt section the plugin registers itself (`src/guidance.js`).
69
+ Only the one-project rule is enforced in code, because it is the only one with a
70
+ computable predicate. "Did you use TailwindCSS?" and "is this pixel-perfect?"
71
+ cannot be checked, so a validator for them would be a lie — they are delivered
72
+ the way this repository delivers every other non-computable rule, as a
73
+ system-prompt section the plugin registers itself (`src/guidance.js`).
61
74
 
62
75
  `.stitch.json` is the project's own file — commit it. It is small and
63
76
  hand-editable on purpose: it is the escape hatch when a Stitch project was
package/lib/client.js CHANGED
@@ -15,6 +15,7 @@ window.__ModuleLoader__.load({
15
15
  id: "@logictan/dsh-stitch-designer",
16
16
  factory: function (require) {
17
17
  var React = require("react");
18
+ var UI = require("@logictan/dsh-plugins-shared-client");
18
19
 
19
20
  /** Loader entry id this card's row is keyed by; equals the host half's `export const name`. */
20
21
  var ROW_ID = "stitch-designer";
@@ -40,27 +41,6 @@ window.__ModuleLoader__.load({
40
41
  */
41
42
  var API_KEY_REF = "STITCH_API_KEY";
42
43
 
43
- var CSS_ID = "stitch-designer/key-card.css";
44
- var css = [
45
- ".std-card{display:flex;flex-direction:column;gap:10px;padding:4px 0;font-size:13px}",
46
- ".std-card-row{display:flex;align-items:center;gap:8px}",
47
- ".std-btn{padding:2px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3));background:transparent;color:var(--dsw-alias-label-tertiary, inherit);font-size:12px;cursor:pointer}",
48
- ".std-btn:hover{color:var(--dsw-alias-label-primary, inherit)}",
49
- ".std-btn:disabled{opacity:.5;cursor:default}",
50
- ".std-input{flex:1;min-width:0;padding:5px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35));background:var(--dsw-alias-fill-l1, transparent);color:var(--dsw-alias-label-primary, inherit);font-size:12px;line-height:18px}",
51
- ".std-note{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-tertiary, inherit)}",
52
- ".std-ok{color:var(--dsw-alias-success-fg, #22c55e)}",
53
- ".std-bad{color:var(--dsw-alias-danger-fg, #ef4444)}"
54
- ].join("");
55
-
56
- if (typeof document !== "undefined" && document.querySelector('style[data-plugin-css="' + CSS_ID + '"]') === null) {
57
- var tag = document.createElement("style");
58
- tag.dataset.plugin = "stitch-designer";
59
- tag.dataset.pluginCss = CSS_ID;
60
- tag.textContent = css;
61
- document.head.appendChild(tag);
62
- }
63
-
64
44
  /**
65
45
  * The Stitch API-key card on the plugin's Plugins-page row.
66
46
  *
@@ -156,45 +136,55 @@ window.__ModuleLoader__.load({
156
136
 
157
137
  var configured = status && status.configured === true;
158
138
  var statusLine = configured
159
- ? React.createElement("div", { className: "std-note std-ok" }, "已配置(值不回读)。来源: " + (status.source || "file"))
160
- : React.createElement("div", { className: "std-note std-bad" }, "未配置。设置后 15 个 mcp__stitch__* 工具即可用。");
139
+ ? React.createElement(UI.Banner, { kind: "ok" }, "已配置(值不回读)。来源: " + (status.source || "file"))
140
+ : React.createElement(UI.Banner, { kind: "error" }, "未配置。设置后 15 个 mcp__stitch__* 工具即可用。");
161
141
 
162
142
  return React.createElement(
163
- "div",
164
- { className: "std-card" },
165
- React.createElement("div", { className: "std-note" }, "Stitch API Key"),
143
+ UI.SettingsCard,
144
+ {
145
+ title: "Stitch API Key",
146
+ },
166
147
  statusLine,
167
148
  React.createElement(
168
149
  "div",
169
- { className: "std-card-row" },
170
- React.createElement("input", {
171
- className: "std-input",
172
- type: "password",
173
- value: value,
174
- placeholder: configured ? "已设置(留空则不改)" : "粘贴 AQ. 开头的 key",
175
- autoComplete: "off",
176
- disabled: pending,
177
- onChange: function (e) {
178
- setValue(e.target.value);
179
- },
180
- }),
150
+ { style: { display: "flex", alignItems: "center", gap: "8px" } },
181
151
  React.createElement(
182
- "button",
183
- { className: "std-btn", disabled: pending || value === "", onClick: save },
152
+ "div",
153
+ { style: { flex: 1, minWidth: 0 } },
154
+ React.createElement(UI.TextField, {
155
+ type: "password",
156
+ value: value,
157
+ placeholder: configured ? "已设置(留空则不改)" : "粘贴 AQ. 开头的 key",
158
+ autoComplete: "off",
159
+ disabled: pending,
160
+ onValueChange: function (next) {
161
+ setValue(next);
162
+ },
163
+ }),
164
+ ),
165
+ React.createElement(
166
+ UI.Button,
167
+ { variant: "primary", disabled: pending || value === "", onClick: save },
184
168
  pending ? "保存中…" : "保存",
185
169
  ),
186
170
  React.createElement(
187
- "button",
188
- { className: "std-btn", disabled: pending || !configured, onClick: clear },
171
+ UI.Button,
172
+ { variant: "secondary", disabled: pending || !configured, onClick: clear },
189
173
  "清除",
190
174
  ),
191
175
  ),
192
176
  React.createElement(
193
- "div",
194
- { className: "std-note" },
177
+ UI.Banner,
178
+ { kind: "info" },
195
179
  "key 来自 https://stitch.withgoogle.com(头像 → Stitch Settings → API key)。存于 $DSH_HOME/.credentials.yaml 的 STITCH_API_KEY,不写入插件配置行,因此不会以明文出现在 cordis.patch.yml。",
196
180
  ),
197
- message ? React.createElement("div", { className: "std-note" }, message) : null,
181
+ message
182
+ ? React.createElement(
183
+ UI.Banner,
184
+ { kind: message.indexOf("失败") >= 0 ? "error" : "info" },
185
+ message,
186
+ )
187
+ : null,
198
188
  );
199
189
  }
200
190
 
package/lib/guidance.js CHANGED
@@ -14,6 +14,13 @@
14
14
  * because a rule the model can silently break is not a rule. This file is only
15
15
  * the text.
16
16
  *
17
+ * The rules fall in two groups, and the split is the point: rules 4-8 govern
18
+ * how a screen is commissioned (what to ask Stitch for), rules 1-3 govern how
19
+ * the result is implemented. A brief that over-specifies produces a screen that
20
+ * is no better than hand-written code, and a screen containing what cannot be
21
+ * built is a defect discovered only at implementation time — both are cheaper
22
+ * to prevent when the model is told before it writes the prompt.
23
+ *
17
24
  * @module @logictan/dsh-stitch-designer/guidance
18
25
  */
19
26
 
@@ -37,4 +44,11 @@ export const STITCH_GUIDANCE = [
37
44
  '1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
38
45
  '2. 实现时使用 TailwindCSS,与 Stitch 生成设计稿的方式保持一致;除非该项目已有架构无法兼容 TailwindCSS,此时先说明是哪一处不兼容、为什么不兼容,再动手。',
39
46
  '3. 先导出 Stitch 的设计稿 HTML,照着它实现,尽可能做到像素级还原。设计稿 HTML 落在 `<项目>/docs/design/<screenId>.html`,应提交到版本库。凡实现需要与设计稿不一致的地方,先问用户并给出理由,不要自行偏离。',
47
+ '',
48
+ '下单给 Stitch 时,遵守以下规范:',
49
+ '4. 提示词只说明需要显示什么内容、用哪些已有组件,以及不需要显示什么(不要出现的模块、数据、交互)。布局、间距、配色、字体、动效等样式一律不写,让它自由发挥。把样式写死成一份详细规格,等于让它照着抄,产出的稿子不会比你自己写的更好。',
50
+ '5. 唯一例外:当实现必须与某个既有设计语言保持一致时(例如要求按 `@logictan/dsh-macos-theme` 出稿),才需要交代样式——但只报名字没用,Stitch 不认识你的包名和主题名。要把那套语言实际长什么样告诉它:颜色取值、圆角、描边、字重与字号层级、间距密度、明暗关系。项目里已有设计系统说明(如主题包的设计系统文档或 Stitch 的 design system)就直接给原文,不要只给一个标识符。没有这种一致性要求时,不要指定任何设计语言。',
51
+ '6. 设计稿最终要被像素级还原,所以稿子里不得出现无法实现的功能和元素。写提示词时就假定它会被逐像素实现:不要许愿一个做不到的交互、一个实现不了的效果,或一份拿不到的数据。',
52
+ '7. 尽可能复用已有组件。出稿前先看项目里已经有什么(宿主组件、共享组件层),让稿子由这些组件拼出来,而不是重画一套长得像的。',
53
+ '8. 每份设计稿都要同时给出暗色版本。暗色不是把亮色反相,而是同一套设计语言在暗色下的取值:颜色、描边、层级都要按暗色重新给。实现时两边共用同一套 token,暗色不另写一份。',
40
54
  ].join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logictan/dsh-stitch-designer",
3
- "version": "2.0.0",
3
+ "version": "2.0.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",
@@ -14,6 +14,9 @@
14
14
  "patch": "./cordis.patch.yml"
15
15
  },
16
16
  "client": {
17
+ "external": [
18
+ "@logictan/dsh-plugins-shared-client"
19
+ ],
17
20
  "inject": [
18
21
  "slots",
19
22
  "remote",
@@ -55,7 +58,8 @@
55
58
  },
56
59
  "peerDependencies": {
57
60
  "@deepseek-ai/cordis": "^4.0.2",
58
- "@deepseek-ai/dsh-tools": "^0.1.5-alpha.1 || ^0.1.6-alpha.1 || ^0.1.7-alpha.1 || ^0.1.7-rc.1 || ^0.2.0-rc.1 || ^0.2.0-rc.2"
61
+ "@deepseek-ai/dsh-tools": "^0.1.5-alpha.1 || ^0.1.6-alpha.1 || ^0.1.7-alpha.1 || ^0.1.7-rc.1 || ^0.2.0-rc.1 || ^0.2.0-rc.2",
62
+ "@logictan/dsh-plugins-shared-client": "^0.1.0"
59
63
  },
60
64
  "peerDependenciesMeta": {
61
65
  "@deepseek-ai/cordis": {
@@ -63,6 +67,9 @@
63
67
  },
64
68
  "@deepseek-ai/dsh-tools": {
65
69
  "optional": true
70
+ },
71
+ "@logictan/dsh-plugins-shared-client": {
72
+ "optional": true
66
73
  }
67
74
  },
68
75
  "devDependencies": {