@xiaobuyu/nodesign 0.0.1 → 0.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.
Files changed (282) hide show
  1. package/README.md +156 -106
  2. package/bin/nodesign.js +0 -0
  3. package/package.json +1 -1
  4. package/server/api/README.md +45 -45
  5. package/server/api/_guard.js +75 -75
  6. package/server/api/admin.js +187 -187
  7. package/server/api/assets/docx-page.js +103 -103
  8. package/server/api/assets/helpers.js +22 -22
  9. package/server/api/assets/notes.js +144 -144
  10. package/server/api/assets.js +896 -896
  11. package/server/api/board.js +57 -57
  12. package/server/api/browse.js +138 -138
  13. package/server/api/canvas.js +444 -444
  14. package/server/api/chatai.js +324 -324
  15. package/server/api/exports/build-standalone.js +980 -980
  16. package/server/api/exports/cards.js +118 -118
  17. package/server/api/exports/docx-pdf.js +46 -46
  18. package/server/api/exports/export-page.js +142 -142
  19. package/server/api/exports/handoff.js +147 -147
  20. package/server/api/exports.js +690 -690
  21. package/server/api/instruction.js +75 -75
  22. package/server/api/me.js +116 -116
  23. package/server/api/memory.js +185 -185
  24. package/server/api/pending-changes.js +366 -366
  25. package/server/api/plugins.js +164 -164
  26. package/server/api/projects.js +220 -220
  27. package/server/api/publish.js +64 -64
  28. package/server/api/recent.js +73 -73
  29. package/server/api/sessions.js +589 -589
  30. package/server/api/skills.js +77 -77
  31. package/server/api/standalone-fit.js +168 -168
  32. package/server/api/turn-compose.js +180 -180
  33. package/server/api/turn-inflight.js +44 -44
  34. package/server/auth/README.md +17 -17
  35. package/server/auth/middleware.js +138 -138
  36. package/server/auth/origin-guard.js +71 -71
  37. package/server/auth/session.js +108 -108
  38. package/server/auth/tier.js +113 -113
  39. package/server/auth/users-store.js +348 -348
  40. package/server/edit/README.md +29 -29
  41. package/server/engine/README.md +113 -113
  42. package/server/engine/agent/agent-shared.js +550 -550
  43. package/server/engine/agent/auto-mode-default-hard-deny.txt +4 -4
  44. package/server/engine/agent/auto-mode-rules.js +78 -78
  45. package/server/engine/agent/context.js +418 -418
  46. package/server/engine/agent/events.js +464 -464
  47. package/server/engine/agent/hooks/canvas-validate.js +199 -199
  48. package/server/engine/agent/hooks/failure.js +120 -120
  49. package/server/engine/agent/hooks/file-events.js +75 -75
  50. package/server/engine/agent/hooks/lifecycle.js +233 -233
  51. package/server/engine/agent/hooks/post-canvas-focus.js +80 -80
  52. package/server/engine/agent/hooks/post-guidance.js +206 -206
  53. package/server/engine/agent/hooks/post-subagent-report.js +104 -104
  54. package/server/engine/agent/hooks/post-trim.js +58 -58
  55. package/server/engine/agent/hooks/pre-board-neighborhood.js +34 -34
  56. package/server/engine/agent/hooks/pre-defaults.js +84 -84
  57. package/server/engine/agent/hooks/pre-injectors.js +277 -277
  58. package/server/engine/agent/hooks/pre-performance-log-guard.js +78 -78
  59. package/server/engine/agent/hooks/pre-starter-files.js +61 -61
  60. package/server/engine/agent/hooks/pre-workspace-scope-guard.js +78 -78
  61. package/server/engine/agent/hooks/site-validate.js +94 -94
  62. package/server/engine/agent/hooks/tool-prompts.js +31 -31
  63. package/server/engine/agent/hooks/turn-state-memory.js +56 -56
  64. package/server/engine/agent/hooks/user-prompt-submit.js +215 -215
  65. package/server/engine/agent/hooks.js +354 -354
  66. package/server/engine/agent/init-contract.js +69 -69
  67. package/server/engine/agent/isolation.js +159 -159
  68. package/server/engine/agent/model-table.js +292 -292
  69. package/server/engine/agent/plugin-loader.js +266 -266
  70. package/server/engine/agent/prompts/nodesign-prelude.md +336 -336
  71. package/server/engine/agent/prompts/tools/ask-user-question-protocol.md +71 -71
  72. package/server/engine/agent/prompts/tools/direct-edit-protocol.md +98 -98
  73. package/server/engine/agent/prompts/tools/generate-image-cookbook.gemini-gateway.md +583 -583
  74. package/server/engine/agent/prompts/tools/generate-image-cookbook.md +483 -483
  75. package/server/engine/agent/prompts/tools/hybrid-reference.md +100 -100
  76. package/server/engine/agent/prompts/tools/paint-still-cookbook.md +270 -270
  77. package/server/engine/agent/prompts/tools/roll-film-cookbook.md +70 -70
  78. package/server/engine/agent/prompts/tools/site-reference.md +106 -106
  79. package/server/engine/agent/prompts/tools/tweaks-syntax.md +125 -125
  80. package/server/engine/agent/prompts/tools/vision-checker-dispatch.md +48 -48
  81. package/server/engine/agent/session-loop.js +1024 -1024
  82. package/server/engine/agent/session-model.js +164 -164
  83. package/server/engine/agent/skill.js +204 -204
  84. package/server/engine/agent/task-events.js +78 -78
  85. package/server/engine/agents/ds-extractor.md +132 -132
  86. package/server/engine/agents/explorer.md +190 -190
  87. package/server/engine/agents/index.js +230 -230
  88. package/server/engine/agents/schemas/design-system.json +156 -156
  89. package/server/engine/agents/schemas/tweak-schema.json +113 -113
  90. package/server/engine/agents/tweak-proposer.md +127 -127
  91. package/server/engine/agents/vision-checker.md +254 -254
  92. package/server/engine/browse/capture.js +422 -422
  93. package/server/engine/browse/card.js +137 -137
  94. package/server/engine/browse/handover.js +59 -59
  95. package/server/engine/browse/page-digest.js +119 -119
  96. package/server/engine/browse/refs.js +196 -196
  97. package/server/engine/browse/registry.js +307 -307
  98. package/server/engine/browse/screencast.js +170 -170
  99. package/server/engine/browse/state.js +121 -121
  100. package/server/engine/chatai/chat-log.js +79 -79
  101. package/server/engine/chatai/index.js +193 -193
  102. package/server/engine/chatai/openai-compat.js +152 -152
  103. package/server/engine/chatai/orchestrate.js +309 -309
  104. package/server/engine/chatai/perform.js +40 -40
  105. package/server/engine/chatai/summarize.js +79 -79
  106. package/server/engine/mcp/capability-gate.js +52 -52
  107. package/server/engine/mcp/index.js +339 -339
  108. package/server/engine/mcp/param-sanitizer.js +142 -142
  109. package/server/engine/mcp/tools/arrange-on-board.js +124 -124
  110. package/server/engine/mcp/tools/artifact-session.js +278 -278
  111. package/server/engine/mcp/tools/browse-computer.js +421 -421
  112. package/server/engine/mcp/tools/browse-find-batch.js +183 -183
  113. package/server/engine/mcp/tools/browse-screenshot.js +157 -157
  114. package/server/engine/mcp/tools/browse.js +480 -480
  115. package/server/engine/mcp/tools/build-docx.js +101 -101
  116. package/server/engine/mcp/tools/clear-pending-changes.js +99 -99
  117. package/server/engine/mcp/tools/create-on-board.js +155 -155
  118. package/server/engine/mcp/tools/crystallize-skill.js +168 -168
  119. package/server/engine/mcp/tools/explain-style.js +237 -237
  120. package/server/engine/mcp/tools/export-handoff.js +133 -133
  121. package/server/engine/mcp/tools/expose-tweaks.js +149 -149
  122. package/server/engine/mcp/tools/generate-image.js +842 -842
  123. package/server/engine/mcp/tools/get-computed-styles.js +164 -164
  124. package/server/engine/mcp/tools/get-pending-changes.js +205 -205
  125. package/server/engine/mcp/tools/h3box-ssh.js +84 -84
  126. package/server/engine/mcp/tools/helpers/acquire-page.js +82 -82
  127. package/server/engine/mcp/tools/helpers/motion-lab.js +554 -554
  128. package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -112
  129. package/server/engine/mcp/tools/helpers/perception-page.js +215 -215
  130. package/server/engine/mcp/tools/helpers/reference-download.js +103 -103
  131. package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -80
  132. package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -280
  133. package/server/engine/mcp/tools/highlight.js +68 -68
  134. package/server/engine/mcp/tools/list-pages.js +222 -222
  135. package/server/engine/mcp/tools/lookup-tags.js +59 -59
  136. package/server/engine/mcp/tools/navigate-to-page.js +60 -60
  137. package/server/engine/mcp/tools/organize-board.js +64 -64
  138. package/server/engine/mcp/tools/paint-still.js +434 -434
  139. package/server/engine/mcp/tools/pin-to-board.js +130 -130
  140. package/server/engine/mcp/tools/preview-deck.js +130 -130
  141. package/server/engine/mcp/tools/profile-scroll.js +305 -305
  142. package/server/engine/mcp/tools/publish-site.js +102 -102
  143. package/server/engine/mcp/tools/query-elements.js +195 -195
  144. package/server/engine/mcp/tools/read-board.js +103 -103
  145. package/server/engine/mcp/tools/read-document.js +93 -93
  146. package/server/engine/mcp/tools/read-page.js +264 -264
  147. package/server/engine/mcp/tools/read-tavern-json.js +143 -143
  148. package/server/engine/mcp/tools/record-decision.js +140 -140
  149. package/server/engine/mcp/tools/relate-on-board.js +110 -110
  150. package/server/engine/mcp/tools/report-issue.js +115 -115
  151. package/server/engine/mcp/tools/roll-film.js +266 -266
  152. package/server/engine/mcp/tools/screenshot-docx.js +138 -138
  153. package/server/engine/mcp/tools/screenshot-url.js +195 -195
  154. package/server/engine/mcp/tools/screenshot.js +583 -583
  155. package/server/engine/mcp/tools/tier-gate.js +96 -96
  156. package/server/engine/mcp/tools/trace-motion.js +215 -215
  157. package/server/engine/mcp/tools/web-search.js +548 -548
  158. package/server/engine/motion/inventory.js +349 -349
  159. package/server/engine/perception/session.js +235 -235
  160. package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -5
  161. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +192 -192
  162. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -667
  163. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -22
  164. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -25
  165. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -23
  166. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -21
  167. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -23
  168. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -21
  169. package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +162 -162
  170. package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -407
  171. package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -80
  172. package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +228 -228
  173. package/server/engine/plugins/nodesign/skills/rp-craft/patterns//346/274/224/345/207/272/351/241/265-/346/234/200/345/260/217/345/256/236/347/216/260.html +78 -78
  174. package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -268
  175. package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +323 -323
  176. package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -134
  177. package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -61
  178. package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -163
  179. package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -86
  180. package/server/engine/runs/active-runs.js +698 -698
  181. package/server/engine/runs/live-turn.js +252 -252
  182. package/server/engine/runs/store.js +364 -364
  183. package/server/engine/runs/turn-relay.js +217 -217
  184. package/server/engine/runtime/workspace.js +164 -164
  185. package/server/lib/artifact-file-path.js +80 -80
  186. package/server/lib/artifact-target.js +284 -284
  187. package/server/lib/asset-refs.js +239 -239
  188. package/server/lib/async-queue.js +104 -104
  189. package/server/lib/auto-relations.js +130 -130
  190. package/server/lib/binding-types.js +60 -60
  191. package/server/lib/board-kind-sizes.js +62 -62
  192. package/server/lib/board-relations.js +133 -133
  193. package/server/lib/browse-proxy.js +180 -180
  194. package/server/lib/canvas-id.js +36 -36
  195. package/server/lib/cover.js +227 -227
  196. package/server/lib/danbooru-tags.js +291 -291
  197. package/server/lib/doc-extract.js +156 -156
  198. package/server/lib/docx/build-from-source.js +260 -260
  199. package/server/lib/docx/build.js +490 -490
  200. package/server/lib/docx/dump-styles.js +287 -287
  201. package/server/lib/docx/fonts/nodesign-cjk.conf +164 -164
  202. package/server/lib/docx/merge-runs.js +129 -129
  203. package/server/lib/docx/numbering.js +218 -218
  204. package/server/lib/docx/order.js +152 -152
  205. package/server/lib/docx/rawzip.js +172 -172
  206. package/server/lib/docx/render.js +92 -92
  207. package/server/lib/docx/text-lint.js +225 -225
  208. package/server/lib/docx/tokens.js +335 -335
  209. package/server/lib/docx/units.js +29 -29
  210. package/server/lib/docx/xml.js +291 -291
  211. package/server/lib/docx-pages.js +187 -187
  212. package/server/lib/export-collect.js +289 -289
  213. package/server/lib/export-package.js +210 -210
  214. package/server/lib/html-srcset.js +145 -145
  215. package/server/lib/image-variant.js +460 -460
  216. package/server/lib/ingress/forward-openai-chat.js +305 -305
  217. package/server/lib/ingress/openai-chat.js +491 -491
  218. package/server/lib/ingress/session-notice.js +66 -66
  219. package/server/lib/ingress/session-routes.js +68 -68
  220. package/server/lib/ingress/slot-probe.js +130 -130
  221. package/server/lib/ingress/upstream-billing.js +52 -52
  222. package/server/lib/ingress/upstream-fail-streak.js +72 -72
  223. package/server/lib/ingress/upstream-truncation.js +48 -48
  224. package/server/lib/issues-store.js +182 -182
  225. package/server/lib/kinds/deck.js +72 -72
  226. package/server/lib/kinds/docx.js +283 -283
  227. package/server/lib/kinds/file-kinds.js +113 -113
  228. package/server/lib/kinds/index.js +202 -202
  229. package/server/lib/kinds/site.js +161 -161
  230. package/server/lib/model-ingress.js +543 -543
  231. package/server/lib/moderation.js +255 -255
  232. package/server/lib/notice-store.js +103 -103
  233. package/server/lib/plugin-install.js +104 -104
  234. package/server/lib/plugin-validator.js +721 -721
  235. package/server/lib/publish-store.js +115 -115
  236. package/server/lib/quick-summary.js +52 -52
  237. package/server/lib/quota.js +270 -270
  238. package/server/lib/rate-window.js +29 -29
  239. package/server/lib/reference-assets.js +92 -92
  240. package/server/lib/region-shot.js +135 -135
  241. package/server/lib/safe-path.js +73 -73
  242. package/server/lib/sdk-session.js +33 -33
  243. package/server/lib/showcase-store.js +92 -92
  244. package/server/lib/site-publish.js +465 -465
  245. package/server/lib/ssrf-guard.js +432 -432
  246. package/server/lib/task-scan.js +158 -158
  247. package/server/lib/tavern-json.js +154 -154
  248. package/server/lib/video-variant.js +237 -237
  249. package/server/lib/workspace-path.js +33 -33
  250. package/server/ops/fix-sdk-musl.mjs +40 -40
  251. package/server/ops/install-macos-fonts.sh +114 -114
  252. package/server/ops/macos-fonts.conf +336 -336
  253. package/server/ops/sandbox-shim/bwrap +57 -57
  254. package/server/projects/assets-summary.js +119 -119
  255. package/server/projects/auto-name.js +53 -53
  256. package/server/projects/board-store.js +640 -640
  257. package/server/projects/move-entry.js +103 -103
  258. package/server/projects/store.js +270 -270
  259. package/server/projects/ui-config.js +54 -54
  260. package/server/projects/workspace-templates.js +53 -53
  261. package/server/projects/workspace.js +1025 -1025
  262. package/server/runtime/local-config.js +177 -177
  263. package/server/runtime/profile.js +72 -72
  264. package/server/services/rembg-service.py +334 -334
  265. package/server/shared/README.md +25 -25
  266. package/server/shared/deck.js +54 -54
  267. package/server/shared/time.js +49 -49
  268. package/server/style-pipeline/README.md +53 -53
  269. package/server/ws/broker.js +36 -36
  270. package/server/ws/browse-channel.js +177 -177
  271. package/server/ws/index.js +386 -386
  272. package/web/README.md +89 -89
  273. package/web/dist/assets/BrowserWindow-BYCgizHw.js +11 -0
  274. package/web/dist/assets/{DeckWindow-4G0xX7P3.js → DeckWindow-pNydEM4L.js} +1 -1
  275. package/web/dist/assets/{DocxWindow-BXQsoPkh.js → DocxWindow-PPgzh3Gq.js} +1 -1
  276. package/web/dist/assets/{SiteWindow-D6eS-2gM.js → SiteWindow-DM0LQPCO.js} +1 -1
  277. package/web/dist/assets/{index-Cbl3ATvp.js → index-BHTBJlpY.js} +32 -32
  278. package/web/dist/assets/{pending-edit-apply-DTjo2geW.js → pending-edit-apply-C0I13CbD.js} +1 -1
  279. package/web/dist/assets/{rotate-cw-LMT3x1Zj.js → rotate-cw-B1UQ8Hld.js} +1 -1
  280. package/web/dist/assets/{square-dashed-mouse-pointer-CBoAkfhi.js → square-dashed-mouse-pointer-8lrgqmfv.js} +1 -1
  281. package/web/dist/index.html +17 -17
  282. package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +0 -11
@@ -1,110 +1,110 @@
1
- /**
2
- * mcp/tools/relate-on-board.js — relate_on_board MCP tool(2026-08-07)
3
- *
4
- * 让 agent 在画布上**画出产物之间的关系**。
5
- *
6
- * ## 为什么这个工具重要
7
- *
8
- * 北极星是「任务文件夹能排出登录墙那种版面」。手摆之所以好看,是因为每张纸的
9
- * 位置在回答「它和旁边那张什么关系」—— 而系统此前只知道每个产物的尺寸和
10
- * mtime。**关系数据不到位,再好的布局算法也只能排出「错落有致的网格」。**
11
- *
12
- * 关键洞察是:**关系不需要推断,agent 手里本来就有**。它知道 proto-暖调 和
13
- * proto-冷调 是同一拍的两个试作、知道哪张图是哪次批注的结果、知道这版改自那版。
14
- * 这些信息现在全在会话里,一落到画布就只剩文件名。这个工具就是那条落差。
15
- *
16
- * 线不存坐标:端点是物件 id 或工作区 id,端点一移动线自己跟着走。
17
- */
18
-
19
- import { tool } from '@anthropic-ai/claude-agent-sdk';
20
- import { z } from 'zod';
21
- import { patchBoard } from '../../../projects/board-store.js';
22
- import { BINDING_TYPES, BINDING_TYPE_IDS } from '../../../lib/binding-types.js';
23
-
24
- /** 词汇表渲染成工具描述里的一段表,免得两处各写各的 */
25
- const VOCAB = BINDING_TYPE_IDS
26
- .map(id => `- ${id} (${BINDING_TYPES[id].label})${BINDING_TYPES[id].directed ? '' : ' — undirected'}`)
27
- .join('\n');
28
-
29
- let seq = 0;
30
- const nextId = () => `b:a${Date.now().toString(36)}${(seq++ % 1000).toString(36)}`;
31
-
32
- export function makeRelateOnBoardTool({ projectId, ctx }) {
33
- return tool(
34
- 'relate_on_board',
35
- `Draw a relationship line between two things on the workbench canvas.
36
-
37
- The canvas knows *what* each artifact is, but not *how they relate*. You are
38
- the only one who knows that — you made them. Recording it lets the user see
39
- lineage at a glance, and lets layout put related things near each other.
40
-
41
- Relationship types:
42
- ${VOCAB}
43
-
44
- Endpoints are canvas ids — a kind prefix plus the workspace-relative path,
45
- exactly as the file sits on disk:
46
- - a file: 'assets/generated/x.webp', 'notes/灵感.md'
47
- - a deck: 'deck:海报/proto-暖调.html'
48
- - a site: 'site:伊蕾娜手账研究站'
49
- - a folder: just its path, '海报' or '海报/初稿'
50
-
51
- Use it right after you produce something that relates to earlier work:
52
- - made v2 of a poster → derives-from, from the new one to the old one
53
- - produced two variants to compare → contrast between them
54
- - storyboard panels in order → flow, each to the next
55
- - used a reference image in a deck → ref, from the deck to the image
56
-
57
- Do NOT use it for "these are all in the same folder" — that is what the
58
- folder already says. Only record relationships that are not obvious from
59
- where the files live.`,
60
- {
61
- type: z.enum(BINDING_TYPE_IDS).describe('Relationship kind (see list above)'),
62
- from: z.string().min(1).max(300).describe('Source canvas id — see forms above'),
63
- to: z.string().min(1).max(300).describe('Target canvas id — see forms above'),
64
- label: z.string().max(60).optional()
65
- .describe('Optional short words on the line. Omit to use the default for the type.'),
66
- },
67
- async ({ type, from, to, label }) => {
68
- if (!projectId) {
69
- return { content: [{ type: 'text', text: 'No project bound; cannot draw relationships.' }], isError: true };
70
- }
71
- if (from === to) {
72
- return {
73
- content: [{ type: 'text', text: 'from and to are the same thing — a relationship needs two ends.' }],
74
- isError: true,
75
- };
76
- }
77
- const id = nextId();
78
- // by:'agent' 不只是记录出处 —— 用户画的线 agent 不该擅自删,反过来也一样
79
- const binding = { type, from, to, by: 'agent', ...(label ? { label } : {}) };
80
- const board = await patchBoard(projectId, { bindings: { [id]: binding } });
81
-
82
- // 服务端会丢掉非法的线(未知 type / 自环)。**丢了要说**,否则 agent 以为
83
- // 画上了,用户看不到,两边都不知道发生了什么。
84
- if (!board.bindings?.[id]) {
85
- return {
86
- content: [{ type: 'text', text: `Relationship rejected by the board (bad type or endpoints): ${type} ${from} -> ${to}` }],
87
- isError: true,
88
- };
89
- }
90
-
91
- // 广播:前端整份重拉。**sessionId 必须显式给 null** —— ctx 会把自己的
92
- // sessionId 补进事件,那样只有当前会话的连接收得到,别的 tab 看不见。
93
- try {
94
- ctx?.emit?.({
95
- type: 'board.updated',
96
- sessionId: null,
97
- summary: `已画一条「${BINDING_TYPES[type].label}」关系`,
98
- });
99
- } catch { /* emit fail-safe:广播失败不该让工具报错,线已经落盘了 */ }
100
-
101
- const arrow = BINDING_TYPES[type].directed ? '->' : '<->';
102
- return {
103
- content: [{
104
- type: 'text',
105
- text: `Drew ${type} (${BINDING_TYPES[type].label}): ${from} ${arrow} ${to}`,
106
- }],
107
- };
108
- },
109
- );
110
- }
1
+ /**
2
+ * mcp/tools/relate-on-board.js — relate_on_board MCP tool(2026-08-07)
3
+ *
4
+ * 让 agent 在画布上**画出产物之间的关系**。
5
+ *
6
+ * ## 为什么这个工具重要
7
+ *
8
+ * 北极星是「任务文件夹能排出登录墙那种版面」。手摆之所以好看,是因为每张纸的
9
+ * 位置在回答「它和旁边那张什么关系」—— 而系统此前只知道每个产物的尺寸和
10
+ * mtime。**关系数据不到位,再好的布局算法也只能排出「错落有致的网格」。**
11
+ *
12
+ * 关键洞察是:**关系不需要推断,agent 手里本来就有**。它知道 proto-暖调 和
13
+ * proto-冷调 是同一拍的两个试作、知道哪张图是哪次批注的结果、知道这版改自那版。
14
+ * 这些信息现在全在会话里,一落到画布就只剩文件名。这个工具就是那条落差。
15
+ *
16
+ * 线不存坐标:端点是物件 id 或工作区 id,端点一移动线自己跟着走。
17
+ */
18
+
19
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
20
+ import { z } from 'zod';
21
+ import { patchBoard } from '../../../projects/board-store.js';
22
+ import { BINDING_TYPES, BINDING_TYPE_IDS } from '../../../lib/binding-types.js';
23
+
24
+ /** 词汇表渲染成工具描述里的一段表,免得两处各写各的 */
25
+ const VOCAB = BINDING_TYPE_IDS
26
+ .map(id => `- ${id} (${BINDING_TYPES[id].label})${BINDING_TYPES[id].directed ? '' : ' — undirected'}`)
27
+ .join('\n');
28
+
29
+ let seq = 0;
30
+ const nextId = () => `b:a${Date.now().toString(36)}${(seq++ % 1000).toString(36)}`;
31
+
32
+ export function makeRelateOnBoardTool({ projectId, ctx }) {
33
+ return tool(
34
+ 'relate_on_board',
35
+ `Draw a relationship line between two things on the workbench canvas.
36
+
37
+ The canvas knows *what* each artifact is, but not *how they relate*. You are
38
+ the only one who knows that — you made them. Recording it lets the user see
39
+ lineage at a glance, and lets layout put related things near each other.
40
+
41
+ Relationship types:
42
+ ${VOCAB}
43
+
44
+ Endpoints are canvas ids — a kind prefix plus the workspace-relative path,
45
+ exactly as the file sits on disk:
46
+ - a file: 'assets/generated/x.webp', 'notes/灵感.md'
47
+ - a deck: 'deck:海报/proto-暖调.html'
48
+ - a site: 'site:伊蕾娜手账研究站'
49
+ - a folder: just its path, '海报' or '海报/初稿'
50
+
51
+ Use it right after you produce something that relates to earlier work:
52
+ - made v2 of a poster → derives-from, from the new one to the old one
53
+ - produced two variants to compare → contrast between them
54
+ - storyboard panels in order → flow, each to the next
55
+ - used a reference image in a deck → ref, from the deck to the image
56
+
57
+ Do NOT use it for "these are all in the same folder" — that is what the
58
+ folder already says. Only record relationships that are not obvious from
59
+ where the files live.`,
60
+ {
61
+ type: z.enum(BINDING_TYPE_IDS).describe('Relationship kind (see list above)'),
62
+ from: z.string().min(1).max(300).describe('Source canvas id — see forms above'),
63
+ to: z.string().min(1).max(300).describe('Target canvas id — see forms above'),
64
+ label: z.string().max(60).optional()
65
+ .describe('Optional short words on the line. Omit to use the default for the type.'),
66
+ },
67
+ async ({ type, from, to, label }) => {
68
+ if (!projectId) {
69
+ return { content: [{ type: 'text', text: 'No project bound; cannot draw relationships.' }], isError: true };
70
+ }
71
+ if (from === to) {
72
+ return {
73
+ content: [{ type: 'text', text: 'from and to are the same thing — a relationship needs two ends.' }],
74
+ isError: true,
75
+ };
76
+ }
77
+ const id = nextId();
78
+ // by:'agent' 不只是记录出处 —— 用户画的线 agent 不该擅自删,反过来也一样
79
+ const binding = { type, from, to, by: 'agent', ...(label ? { label } : {}) };
80
+ const board = await patchBoard(projectId, { bindings: { [id]: binding } });
81
+
82
+ // 服务端会丢掉非法的线(未知 type / 自环)。**丢了要说**,否则 agent 以为
83
+ // 画上了,用户看不到,两边都不知道发生了什么。
84
+ if (!board.bindings?.[id]) {
85
+ return {
86
+ content: [{ type: 'text', text: `Relationship rejected by the board (bad type or endpoints): ${type} ${from} -> ${to}` }],
87
+ isError: true,
88
+ };
89
+ }
90
+
91
+ // 广播:前端整份重拉。**sessionId 必须显式给 null** —— ctx 会把自己的
92
+ // sessionId 补进事件,那样只有当前会话的连接收得到,别的 tab 看不见。
93
+ try {
94
+ ctx?.emit?.({
95
+ type: 'board.updated',
96
+ sessionId: null,
97
+ summary: `已画一条「${BINDING_TYPES[type].label}」关系`,
98
+ });
99
+ } catch { /* emit fail-safe:广播失败不该让工具报错,线已经落盘了 */ }
100
+
101
+ const arrow = BINDING_TYPES[type].directed ? '->' : '<->';
102
+ return {
103
+ content: [{
104
+ type: 'text',
105
+ text: `Drew ${type} (${BINDING_TYPES[type].label}): ${from} ${arrow} ${to}`,
106
+ }],
107
+ };
108
+ },
109
+ );
110
+ }
@@ -1,115 +1,115 @@
1
- /**
2
- * mcp/tools/report-issue.js — report_issue MCP tool
3
- * (2026-08-02 由 report_friction 扩容改名:加 kind 轴,bug / friction / idea)
4
- *
5
- * agent 主动给维护者写信:harness 的故障(bug)、能用但绕路的摩擦(friction)、
6
- * 干活时冒出来的改进想法(idea)。三类走同一张 issues 表同一套指纹聚合。
7
- *
8
- * 跟自动层(PostToolUseFailure → issues 表 source='auto')的分工:
9
- * 自动层记"发生了什么"——某工具失败 N 次,不依赖 agent 自觉,但指不出修法。
10
- * 这一层补"为什么难受、期望怎样"——一条 "screenshot 超时 12 次" 没有信息量,
11
- * 一条 "截长站点页时我只想要首屏,但只能 fullPage 然后自己裁" 才指向修法。
12
- *
13
- * 措辞戒律(继承自 report_friction,扩 idea 后同样适用):
14
- * - 压住"遇到困难就上报"的倾向:上报**不是**绕路的替代品,照常把活儿干完。
15
- * - idea 通道要具体到可实施——"工具链很棒" 这种话没有收件人,不收。
16
- * - 同类按指纹聚合累加,不是刷一万条重复。
17
- */
18
-
19
- import { tool } from '@anthropic-ai/claude-agent-sdk';
20
- import { z } from 'zod';
21
- import { recordIssue, signatureOf } from '../../../lib/issues-store.js';
22
- import { getProject } from '../../../projects/store.js';
23
-
24
- /**
25
- * @param {object} deps
26
- * @param {string} [deps.projectId]
27
- * @param {string} [deps.sessionId]
28
- * @param {import('../../agent/context.js').AgentContext} [deps.ctx]
29
- */
30
- export function makeReportIssueTool({ projectId, sessionId, ctx }) {
31
- return tool(
32
- 'report_issue',
33
- `Write to the maintainer of this HARNESS — the tools and environment you work
34
- in. This goes to their issue list, not to the user. Three kinds:
35
-
36
- - "bug": something in the harness behaved WRONGLY — a tool crashed on valid
37
- input, returned corrupt output, or contradicted its own description.
38
- - "friction": it worked, but the path was painful — a missing parameter, a
39
- return shape you had to fight, a workaround you have now done more than once
40
- (the workaround IS the report).
41
- - "idea": nothing is broken, but while working you saw something the harness
42
- could do better or do at all — a tool that should exist, a flag that would
43
- collapse three steps into one, a default that fights real usage. The
44
- maintainer reads every one of these and good ones get built — if a concrete
45
- improvement occurred to you, report it rather than let it evaporate.
46
-
47
- This is NOT a substitute for doing the work. Finish the task the way you would
48
- have anyway — route around the problem, deliver the result — and log this on
49
- the side. Never report and then hand back less than you could have.
50
-
51
- Do NOT report:
52
- - Your own mistakes (wrong path, malformed edit) — not harness issues
53
- - One-off flakes that a retry fixed
54
- - Anything about the design work itself (that belongs in the conversation)
55
- - Praise or vague sentiment ("the tools are great", "X could be better
56
- somehow") — a report with no actionable content is noise
57
-
58
- Be concrete. "screenshot is slow" is useless. "screenshot_canvas on a 6000px
59
- site page takes ~14s and returns an image too large to read, so I crop by hand
60
- every time; a viewportOnly flag would remove the whole detour" is actionable.`,
61
- {
62
- kind: z.enum(['bug', 'friction', 'idea'])
63
- .describe('bug = behaved wrongly · friction = worked but painful · idea = improvement worth building'),
64
- summary: z.string().min(8).max(200)
65
- .describe('One line. bug/friction: what is wrong, concrete. idea: the improvement itself, not "improve X".'),
66
- detail: z.string().min(20).max(3000)
67
- .describe('What you were doing and what happened (bug/friction: include the workaround you used; idea: the real situation that made you want this).'),
68
- // 选填(2026-08-18):以前是必填,agent 不传就被 zod 打回 —— **信箱把上报挡在
69
- // 门外**,库里有 4 次这样的失败。能提当然好,提不出来也别丢掉这条上报。
70
- expectation: z.string().min(10).max(1500).optional()
71
- .describe('If you can name it: bug → the correct behaviour; friction → what would remove the detour; idea → what it looks like once built and what it unlocks. Leave it out rather than padding it.'),
72
- toolName: z.string().max(80).optional()
73
- .describe('The tool involved, if it is about one (e.g. "mcp__nodesign__screenshot_canvas").'),
74
- },
75
- async ({ kind, summary, detail, expectation, toolName }) => {
76
- try {
77
- const rec = recordIssue({
78
- source: 'agent',
79
- kind,
80
- toolName: toolName || null,
81
- summary,
82
- detail,
83
- expectation,
84
- projectId,
85
- sessionId,
86
- userId: projectId ? getProject(projectId)?.ownerId : null,
87
- // 按"摘要 + 工具"归一化:同一个抱怨反复出现是累加计数,不是刷屏
88
- signature: signatureOf(`${toolName || ''}|${summary}`),
89
- });
90
- if (!rec) {
91
- return {
92
- content: [{ type: 'text', text: 'Could not write the report (logged server-side). Carry on with the task.' }],
93
- isError: true,
94
- };
95
- }
96
- try {
97
- ctx?.emit?.({ type: 'run.friction_reported', kind, summary, toolName: toolName || null, count: rec.count });
98
- } catch { /* emit fail-safe */ }
99
- return {
100
- content: [{
101
- type: 'text',
102
- text: rec.count > 1
103
- ? `Logged (this is the ${rec.count}th time this one has come up). Now carry on and finish the task.`
104
- : 'Logged. Now carry on and finish the task.',
105
- }],
106
- };
107
- } catch (err) {
108
- return {
109
- content: [{ type: 'text', text: `report_issue failed: ${err?.message || String(err)}` }],
110
- isError: true,
111
- };
112
- }
113
- },
114
- );
115
- }
1
+ /**
2
+ * mcp/tools/report-issue.js — report_issue MCP tool
3
+ * (2026-08-02 由 report_friction 扩容改名:加 kind 轴,bug / friction / idea)
4
+ *
5
+ * agent 主动给维护者写信:harness 的故障(bug)、能用但绕路的摩擦(friction)、
6
+ * 干活时冒出来的改进想法(idea)。三类走同一张 issues 表同一套指纹聚合。
7
+ *
8
+ * 跟自动层(PostToolUseFailure → issues 表 source='auto')的分工:
9
+ * 自动层记"发生了什么"——某工具失败 N 次,不依赖 agent 自觉,但指不出修法。
10
+ * 这一层补"为什么难受、期望怎样"——一条 "screenshot 超时 12 次" 没有信息量,
11
+ * 一条 "截长站点页时我只想要首屏,但只能 fullPage 然后自己裁" 才指向修法。
12
+ *
13
+ * 措辞戒律(继承自 report_friction,扩 idea 后同样适用):
14
+ * - 压住"遇到困难就上报"的倾向:上报**不是**绕路的替代品,照常把活儿干完。
15
+ * - idea 通道要具体到可实施——"工具链很棒" 这种话没有收件人,不收。
16
+ * - 同类按指纹聚合累加,不是刷一万条重复。
17
+ */
18
+
19
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
20
+ import { z } from 'zod';
21
+ import { recordIssue, signatureOf } from '../../../lib/issues-store.js';
22
+ import { getProject } from '../../../projects/store.js';
23
+
24
+ /**
25
+ * @param {object} deps
26
+ * @param {string} [deps.projectId]
27
+ * @param {string} [deps.sessionId]
28
+ * @param {import('../../agent/context.js').AgentContext} [deps.ctx]
29
+ */
30
+ export function makeReportIssueTool({ projectId, sessionId, ctx }) {
31
+ return tool(
32
+ 'report_issue',
33
+ `Write to the maintainer of this HARNESS — the tools and environment you work
34
+ in. This goes to their issue list, not to the user. Three kinds:
35
+
36
+ - "bug": something in the harness behaved WRONGLY — a tool crashed on valid
37
+ input, returned corrupt output, or contradicted its own description.
38
+ - "friction": it worked, but the path was painful — a missing parameter, a
39
+ return shape you had to fight, a workaround you have now done more than once
40
+ (the workaround IS the report).
41
+ - "idea": nothing is broken, but while working you saw something the harness
42
+ could do better or do at all — a tool that should exist, a flag that would
43
+ collapse three steps into one, a default that fights real usage. The
44
+ maintainer reads every one of these and good ones get built — if a concrete
45
+ improvement occurred to you, report it rather than let it evaporate.
46
+
47
+ This is NOT a substitute for doing the work. Finish the task the way you would
48
+ have anyway — route around the problem, deliver the result — and log this on
49
+ the side. Never report and then hand back less than you could have.
50
+
51
+ Do NOT report:
52
+ - Your own mistakes (wrong path, malformed edit) — not harness issues
53
+ - One-off flakes that a retry fixed
54
+ - Anything about the design work itself (that belongs in the conversation)
55
+ - Praise or vague sentiment ("the tools are great", "X could be better
56
+ somehow") — a report with no actionable content is noise
57
+
58
+ Be concrete. "screenshot is slow" is useless. "screenshot_canvas on a 6000px
59
+ site page takes ~14s and returns an image too large to read, so I crop by hand
60
+ every time; a viewportOnly flag would remove the whole detour" is actionable.`,
61
+ {
62
+ kind: z.enum(['bug', 'friction', 'idea'])
63
+ .describe('bug = behaved wrongly · friction = worked but painful · idea = improvement worth building'),
64
+ summary: z.string().min(8).max(200)
65
+ .describe('One line. bug/friction: what is wrong, concrete. idea: the improvement itself, not "improve X".'),
66
+ detail: z.string().min(20).max(3000)
67
+ .describe('What you were doing and what happened (bug/friction: include the workaround you used; idea: the real situation that made you want this).'),
68
+ // 选填(2026-08-18):以前是必填,agent 不传就被 zod 打回 —— **信箱把上报挡在
69
+ // 门外**,库里有 4 次这样的失败。能提当然好,提不出来也别丢掉这条上报。
70
+ expectation: z.string().min(10).max(1500).optional()
71
+ .describe('If you can name it: bug → the correct behaviour; friction → what would remove the detour; idea → what it looks like once built and what it unlocks. Leave it out rather than padding it.'),
72
+ toolName: z.string().max(80).optional()
73
+ .describe('The tool involved, if it is about one (e.g. "mcp__nodesign__screenshot_canvas").'),
74
+ },
75
+ async ({ kind, summary, detail, expectation, toolName }) => {
76
+ try {
77
+ const rec = recordIssue({
78
+ source: 'agent',
79
+ kind,
80
+ toolName: toolName || null,
81
+ summary,
82
+ detail,
83
+ expectation,
84
+ projectId,
85
+ sessionId,
86
+ userId: projectId ? getProject(projectId)?.ownerId : null,
87
+ // 按"摘要 + 工具"归一化:同一个抱怨反复出现是累加计数,不是刷屏
88
+ signature: signatureOf(`${toolName || ''}|${summary}`),
89
+ });
90
+ if (!rec) {
91
+ return {
92
+ content: [{ type: 'text', text: 'Could not write the report (logged server-side). Carry on with the task.' }],
93
+ isError: true,
94
+ };
95
+ }
96
+ try {
97
+ ctx?.emit?.({ type: 'run.friction_reported', kind, summary, toolName: toolName || null, count: rec.count });
98
+ } catch { /* emit fail-safe */ }
99
+ return {
100
+ content: [{
101
+ type: 'text',
102
+ text: rec.count > 1
103
+ ? `Logged (this is the ${rec.count}th time this one has come up). Now carry on and finish the task.`
104
+ : 'Logged. Now carry on and finish the task.',
105
+ }],
106
+ };
107
+ } catch (err) {
108
+ return {
109
+ content: [{ type: 'text', text: `report_issue failed: ${err?.message || String(err)}` }],
110
+ isError: true,
111
+ };
112
+ }
113
+ },
114
+ );
115
+ }