@xiaobuyu/nodesign 0.0.1 → 0.0.3

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 (358) 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 +42 -22
  9. package/server/api/assets/notes.js +194 -144
  10. package/server/api/assets.js +891 -896
  11. package/server/api/board.js +134 -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 +465 -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 +258 -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 +388 -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 +1035 -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 +351 -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 +152 -155
  118. package/server/engine/mcp/tools/crystallize-skill.js +168 -168
  119. package/server/engine/mcp/tools/edit-sketch.js +167 -0
  120. package/server/engine/mcp/tools/explain-style.js +237 -237
  121. package/server/engine/mcp/tools/export-handoff.js +133 -133
  122. package/server/engine/mcp/tools/expose-tweaks.js +149 -149
  123. package/server/engine/mcp/tools/generate-image.js +842 -842
  124. package/server/engine/mcp/tools/get-computed-styles.js +164 -164
  125. package/server/engine/mcp/tools/get-pending-changes.js +205 -205
  126. package/server/engine/mcp/tools/h3box-ssh.js +84 -84
  127. package/server/engine/mcp/tools/helpers/acquire-page.js +82 -82
  128. package/server/engine/mcp/tools/helpers/motion-lab.js +554 -554
  129. package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -112
  130. package/server/engine/mcp/tools/helpers/perception-page.js +215 -215
  131. package/server/engine/mcp/tools/helpers/reference-download.js +103 -103
  132. package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -80
  133. package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -280
  134. package/server/engine/mcp/tools/highlight.js +68 -68
  135. package/server/engine/mcp/tools/list-pages.js +222 -222
  136. package/server/engine/mcp/tools/look-at-board.js +124 -0
  137. package/server/engine/mcp/tools/lookup-tags.js +59 -59
  138. package/server/engine/mcp/tools/navigate-to-page.js +60 -60
  139. package/server/engine/mcp/tools/organize-board.js +64 -64
  140. package/server/engine/mcp/tools/paint-still.js +434 -434
  141. package/server/engine/mcp/tools/pin-to-board.js +130 -130
  142. package/server/engine/mcp/tools/preview-deck.js +130 -130
  143. package/server/engine/mcp/tools/profile-scroll.js +305 -305
  144. package/server/engine/mcp/tools/publish-site.js +102 -102
  145. package/server/engine/mcp/tools/query-elements.js +195 -195
  146. package/server/engine/mcp/tools/read-board.js +190 -103
  147. package/server/engine/mcp/tools/read-document.js +93 -93
  148. package/server/engine/mcp/tools/read-page.js +264 -264
  149. package/server/engine/mcp/tools/read-tavern-json.js +143 -143
  150. package/server/engine/mcp/tools/read-user-view.js +59 -0
  151. package/server/engine/mcp/tools/record-decision.js +140 -140
  152. package/server/engine/mcp/tools/relate-on-board.js +112 -110
  153. package/server/engine/mcp/tools/report-issue.js +115 -115
  154. package/server/engine/mcp/tools/roll-film.js +266 -266
  155. package/server/engine/mcp/tools/screenshot-docx.js +138 -138
  156. package/server/engine/mcp/tools/screenshot-url.js +195 -195
  157. package/server/engine/mcp/tools/screenshot.js +583 -583
  158. package/server/engine/mcp/tools/sketch-on-board.js +337 -0
  159. package/server/engine/mcp/tools/tier-gate.js +96 -96
  160. package/server/engine/mcp/tools/trace-motion.js +215 -215
  161. package/server/engine/mcp/tools/web-search.js +548 -548
  162. package/server/engine/mcp/tools/write-on-board.js +130 -0
  163. package/server/engine/motion/inventory.js +349 -349
  164. package/server/engine/perception/session.js +235 -235
  165. package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -5
  166. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +199 -192
  167. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -667
  168. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -22
  169. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -25
  170. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -23
  171. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -21
  172. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -23
  173. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -21
  174. package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +169 -162
  175. package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -407
  176. package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -80
  177. package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +235 -228
  178. 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
  179. package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -268
  180. package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +330 -323
  181. package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -134
  182. package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -61
  183. package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -163
  184. package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -86
  185. package/server/engine/runs/active-runs.js +698 -698
  186. package/server/engine/runs/board-tasklist.js +130 -0
  187. package/server/engine/runs/live-turn.js +252 -252
  188. package/server/engine/runs/store.js +364 -364
  189. package/server/engine/runs/turn-relay.js +217 -217
  190. package/server/engine/runtime/workspace.js +164 -164
  191. package/server/index.js +3 -0
  192. package/server/lib/artifact-file-path.js +80 -80
  193. package/server/lib/artifact-target.js +284 -284
  194. package/server/lib/asset-refs.js +239 -239
  195. package/server/lib/async-queue.js +104 -104
  196. package/server/lib/auto-relations.js +130 -130
  197. package/server/lib/binding-types.js +72 -60
  198. package/server/lib/board-graph-export.js +191 -0
  199. package/server/lib/board-groups.js +167 -0
  200. package/server/lib/board-hero.js +76 -0
  201. package/server/lib/board-kind-sizes.js +85 -62
  202. package/server/lib/board-relations.js +133 -133
  203. package/server/lib/browse-proxy.js +180 -180
  204. package/server/lib/canvas-id.js +36 -36
  205. package/server/lib/chalk.js +121 -0
  206. package/server/lib/cover.js +227 -227
  207. package/server/lib/danbooru-tags.js +291 -291
  208. package/server/lib/doc-extract.js +156 -156
  209. package/server/lib/docx/build-from-source.js +260 -260
  210. package/server/lib/docx/build.js +490 -490
  211. package/server/lib/docx/dump-styles.js +287 -287
  212. package/server/lib/docx/fonts/nodesign-cjk.conf +164 -164
  213. package/server/lib/docx/merge-runs.js +129 -129
  214. package/server/lib/docx/numbering.js +218 -218
  215. package/server/lib/docx/order.js +152 -152
  216. package/server/lib/docx/rawzip.js +172 -172
  217. package/server/lib/docx/render.js +92 -92
  218. package/server/lib/docx/text-lint.js +225 -225
  219. package/server/lib/docx/tokens.js +335 -335
  220. package/server/lib/docx/units.js +29 -29
  221. package/server/lib/docx/xml.js +291 -291
  222. package/server/lib/docx-pages.js +187 -187
  223. package/server/lib/export-collect.js +289 -289
  224. package/server/lib/export-package.js +210 -210
  225. package/server/lib/html-srcset.js +145 -145
  226. package/server/lib/image-variant.js +460 -460
  227. package/server/lib/ingress/forward-openai-chat.js +305 -305
  228. package/server/lib/ingress/openai-chat.js +491 -491
  229. package/server/lib/ingress/session-notice.js +66 -66
  230. package/server/lib/ingress/session-routes.js +68 -68
  231. package/server/lib/ingress/slot-probe.js +130 -130
  232. package/server/lib/ingress/upstream-billing.js +52 -52
  233. package/server/lib/ingress/upstream-fail-streak.js +72 -72
  234. package/server/lib/ingress/upstream-truncation.js +48 -48
  235. package/server/lib/issues-store.js +182 -182
  236. package/server/lib/kinds/deck.js +72 -72
  237. package/server/lib/kinds/docx.js +283 -283
  238. package/server/lib/kinds/file-kinds.js +113 -113
  239. package/server/lib/kinds/index.js +202 -202
  240. package/server/lib/kinds/site.js +161 -161
  241. package/server/lib/model-ingress.js +543 -543
  242. package/server/lib/moderation.js +255 -255
  243. package/server/lib/notice-store.js +103 -103
  244. package/server/lib/plugin-install.js +104 -104
  245. package/server/lib/plugin-validator.js +721 -721
  246. package/server/lib/publish-store.js +115 -115
  247. package/server/lib/quick-summary.js +52 -52
  248. package/server/lib/quota.js +270 -270
  249. package/server/lib/rate-window.js +29 -29
  250. package/server/lib/reference-assets.js +92 -92
  251. package/server/lib/region-shot.js +135 -135
  252. package/server/lib/safe-path.js +73 -73
  253. package/server/lib/sdk-session.js +33 -33
  254. package/server/lib/showcase-store.js +92 -92
  255. package/server/lib/site-publish.js +465 -465
  256. package/server/lib/sketch-layout.js +277 -0
  257. package/server/lib/ssrf-guard.js +432 -432
  258. package/server/lib/task-scan.js +158 -158
  259. package/server/lib/tavern-json.js +154 -154
  260. package/server/lib/video-variant.js +237 -237
  261. package/server/lib/workspace-path.js +33 -33
  262. package/server/ops/fix-sdk-musl.mjs +40 -40
  263. package/server/ops/install-macos-fonts.sh +114 -114
  264. package/server/ops/macos-fonts.conf +336 -336
  265. package/server/ops/sandbox-shim/bwrap +57 -57
  266. package/server/projects/assets-summary.js +119 -119
  267. package/server/projects/auto-name.js +53 -53
  268. package/server/projects/board-limits.js +12 -0
  269. package/server/projects/board-sanitize.js +252 -0
  270. package/server/projects/board-store.js +507 -640
  271. package/server/projects/move-entry.js +103 -103
  272. package/server/projects/store.js +270 -270
  273. package/server/projects/ui-config.js +60 -54
  274. package/server/projects/viewpoint-store.js +78 -0
  275. package/server/projects/workspace-templates.js +53 -53
  276. package/server/projects/workspace.js +1025 -1025
  277. package/server/runtime/local-config.js +177 -177
  278. package/server/runtime/profile.js +72 -72
  279. package/server/services/rembg-service.py +334 -334
  280. package/server/shared/README.md +25 -25
  281. package/server/shared/deck.js +54 -54
  282. package/server/shared/time.js +49 -49
  283. package/server/style-pipeline/README.md +53 -53
  284. package/server/ws/broker.js +39 -36
  285. package/server/ws/browse-channel.js +177 -177
  286. package/server/ws/index.js +386 -386
  287. package/web/README.md +89 -89
  288. package/web/dist/assets/BrowserWindow-P_vIdh-G.js +11 -0
  289. package/web/dist/assets/{DeckWindow-4G0xX7P3.js → DeckWindow-BpLv5082.js} +3 -3
  290. package/web/dist/assets/{DocxWindow-BXQsoPkh.js → DocxWindow-DSAU1-tD.js} +4 -4
  291. package/web/dist/assets/MermaidBlock-DR1GikCv.js +313 -0
  292. package/web/dist/assets/SiteWindow-92uBuRRR.js +18 -0
  293. package/web/dist/assets/abnfDiagram-VCTEODGH-uA8Esix4.js +1 -0
  294. package/web/dist/assets/arc-D_khH_xN.js +1 -0
  295. package/web/dist/assets/architectureDiagram-5GKGNRK7-DydJHqOt.js +36 -0
  296. package/web/dist/assets/blockDiagram-NRAW4CY4-B7wBbKiW.js +129 -0
  297. package/web/dist/assets/c4Diagram-UCG6FXSJ-6mrH0x7Y.js +38 -0
  298. package/web/dist/assets/channel-DGkccMO1.js +1 -0
  299. package/web/dist/assets/chunk-2Q5K7J3B-Cuikho5Q.js +1 -0
  300. package/web/dist/assets/chunk-5VM5RSS4-3-KZ5AUz.js +15 -0
  301. package/web/dist/assets/chunk-F27PBJKO-Bkwq2gGU.js +1 -0
  302. package/web/dist/assets/chunk-G27WJ6UU-BLyQzdGE.js +231 -0
  303. package/web/dist/assets/chunk-JWPE2WC7-B7HxxQds.js +1 -0
  304. package/web/dist/assets/chunk-LCL6LL3I-CtXrnUwF.js +206 -0
  305. package/web/dist/assets/chunk-POPQ4Y6H-dxddZlXt.js +1 -0
  306. package/web/dist/assets/chunk-SVP7TREG-DpkmrgHn.js +88 -0
  307. package/web/dist/assets/chunk-XXDRQBXY-BwZ7RbpQ.js +1 -0
  308. package/web/dist/assets/classDiagram-DTDB5LWJ-BGscw3OD.js +1 -0
  309. package/web/dist/assets/classDiagram-v2-JRS7N3AN-BGscw3OD.js +1 -0
  310. package/web/dist/assets/cose-bilkent-JH36ORCC-DGFOsMUt.js +1 -0
  311. package/web/dist/assets/cynefin-OW5HDTMX-DUwn3ehS.js +178 -0
  312. package/web/dist/assets/cynefinDiagram-5FMLGOSQ-DlLAOZ9x.js +62 -0
  313. package/web/dist/assets/cytoscape.esm-BjAbmLdb.js +331 -0
  314. package/web/dist/assets/dagre-3AP2YEHR-CyourLfz.js +4 -0
  315. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  316. package/web/dist/assets/diagram-S7CK7UJ4-BTMbx2np.js +30 -0
  317. package/web/dist/assets/diagram-UQ7AKVKN-UK94_1-P.js +41 -0
  318. package/web/dist/assets/diagram-VSXAHHWV-C7zS-v9v.js +3 -0
  319. package/web/dist/assets/diagram-VX7I27RA-DKJRa6CK.js +24 -0
  320. package/web/dist/assets/diagram-Z3DM3KII-kUbAfGAp.js +24 -0
  321. package/web/dist/assets/ebnfDiagram-PWID7BFC-CVW16_vb.js +1 -0
  322. package/web/dist/assets/erDiagram-SSCWMZ5O-BRQMFQ5y.js +99 -0
  323. package/web/dist/assets/flowDiagram-A5DVABFB-S34LpLtK.js +168 -0
  324. package/web/dist/assets/ganttDiagram-EL5Y4UJY-BFiqk1-G.js +292 -0
  325. package/web/dist/assets/gitGraphDiagram-WWUBYQGX-LZsrdyyv.js +106 -0
  326. package/web/dist/assets/index-GAamh1p4.js +2152 -0
  327. package/web/dist/assets/infoDiagram-RXCK75RN-0DvN6KIp.js +2 -0
  328. package/web/dist/assets/init-Gi6I4Gst.js +1 -0
  329. package/web/dist/assets/ishikawaDiagram-5VMMS53U-CaY3A-Bx.js +70 -0
  330. package/web/dist/assets/journeyDiagram-EYS64GPL-BBeiaCrj.js +139 -0
  331. package/web/dist/assets/kanban-definition-3QL26DDD-ux42DRXQ.js +89 -0
  332. package/web/dist/assets/layout-CnXiF_NB.js +1 -0
  333. package/web/dist/assets/linear-BMW0u6G6.js +1 -0
  334. package/web/dist/assets/mindmap-definition-FBJOCRG2-hUxSpdKn.js +96 -0
  335. package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
  336. package/web/dist/assets/pegDiagram-XKGWAZYB-aCaQPH0w.js +1 -0
  337. package/web/dist/assets/{pending-edit-apply-DTjo2geW.js → pending-edit-apply-AcdOQ9Ij.js} +6 -6
  338. package/web/dist/assets/pieDiagram-E7YTZNPT-CmOEZ8zg.js +39 -0
  339. package/web/dist/assets/quadrantDiagram-AXDQQJYC-VW6fAhsV.js +7 -0
  340. package/web/dist/assets/railroadDiagram-O6MQD6OU-CKJ7Ba5K.js +1 -0
  341. package/web/dist/assets/requirementDiagram-EFPCY7ZU-pNGkq9Vw.js +84 -0
  342. package/web/dist/assets/{rotate-cw-LMT3x1Zj.js → rotate-cw-KAfChbGV.js} +1 -1
  343. package/web/dist/assets/sankeyDiagram-P5KCCOFB-BIMmDTfZ.js +40 -0
  344. package/web/dist/assets/sequenceDiagram-WJ2MYXX4-BBW7wzKY.js +162 -0
  345. package/web/dist/assets/sizeCapture-X5ZJPWSS-DdkXmLYR.js +1 -0
  346. package/web/dist/assets/{square-dashed-mouse-pointer-CBoAkfhi.js → square-dashed-mouse-pointer-CDUlhUP7.js} +1 -1
  347. package/web/dist/assets/stateDiagram-HBIQ2CUA-W313Uz16.js +1 -0
  348. package/web/dist/assets/stateDiagram-v2-4QOOHH4V-DDhJBZzf.js +1 -0
  349. package/web/dist/assets/swimlanes-XN3QIQJK-C29TL26K.js +1 -0
  350. package/web/dist/assets/swimlanesDiagram-VK2B7HYN-BfN-Xdmu.js +8 -0
  351. package/web/dist/assets/timeline-definition-24CTP7MA-CF0JMObX.js +120 -0
  352. package/web/dist/assets/vennDiagram-4TSXK5OY-DrDFsaH3.js +34 -0
  353. package/web/dist/assets/wardleyDiagram-VM6X3IG4-CVrnRIS_.js +78 -0
  354. package/web/dist/assets/xychartDiagram-S5SC5T6Z-BvkN1zsT.js +7 -0
  355. package/web/dist/index.html +17 -17
  356. package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +0 -11
  357. package/web/dist/assets/SiteWindow-D6eS-2gM.js +0 -18
  358. package/web/dist/assets/index-Cbl3ATvp.js +0 -2125
@@ -1,168 +1,168 @@
1
- /**
2
- * mcp/tools/crystallize-skill.js — crystallize_skill MCP tool
3
- *
4
- * 把一次真实探索的**结论**固化成用户自己的 skill,并把作品收进个人橱窗。
5
- *
6
- * 为什么不是"存模板":模板是把成品存下来,换个主题就崩——真正能复用的是判断依据
7
- * (为什么这个字号阶梯、为什么这个场合压住动效、哪些默认做法在这个气质里必须反掉)。
8
- * 所以这个工具收的是方法论,不是 HTML。产物写进用户级 plugin 根
9
- * (~/.nodesign/plugins/<userId>/<name>/),下次开新会话在**这个用户的所有项目**里
10
- * 都能用(plugin 发现是 startup-time,当前会话不生效)。
11
- *
12
- * 跟 record_decision 的分工:决策贴是**这一件作品**的过程档案,随任务走;
13
- * 这里是跨项目复用的方法论,随用户走。一个是日志,一个是沉淀。
14
- *
15
- * 归属:写到**项目 owner** 的目录,不是"当前请求者"——同一个项目谁跑都该产出同一
16
- * 套资产。owner 查不到就报错,不往共享根写(那是刚修掉的跨用户污染路径)。
17
- */
18
-
19
- import { tool } from '@anthropic-ai/claude-agent-sdk';
20
- import { z } from 'zod';
21
- import { getProject } from '../../../projects/store.js';
22
- import { getUserPluginsRoot } from '../../agent/plugin-loader.js';
23
- import { installPluginToRoot } from '../../../lib/plugin-install.js';
24
- import { upsertEntry } from '../../../lib/showcase-store.js';
25
- import { getActiveArtifact } from '../../../lib/artifact-target.js';
26
- import { Events } from '../../agent/events.js';
27
-
28
- const NAME_RE = /^[a-z0-9][a-z0-9-]{2,39}$/;
29
-
30
- function composeSkillMd({ name, title, description, body }) {
31
- return [
32
- '---',
33
- `name: ${name}`,
34
- `description: ${description.replace(/\n+/g, ' ').trim()}`,
35
- 'version: 0.1.0',
36
- '---',
37
- '',
38
- `# ${title.trim()}`,
39
- '',
40
- body.trim(),
41
- '',
42
- ].join('\n');
43
- }
44
-
45
- /**
46
- * @param {object} deps
47
- * @param {string} [deps.projectId]
48
- * @param {string} [deps.sessionId]
49
- * @param {import('../../agent/context.js').AgentContext} [deps.ctx]
50
- */
51
- export function makeCrystallizeSkillTool({ projectId, sessionId, ctx }) {
52
- return tool(
53
- 'crystallize_skill',
54
- `Distill a style/approach the user and you worked out together into a REUSABLE
55
- SKILL owned by this user, and put the finished work in their personal showcase.
56
-
57
- Call this ONLY when the user asks to keep a style, or explicitly confirms they
58
- want this approach reusable. Never call it unprompted — a skill the user did not
59
- ask for is clutter in every future session.
60
-
61
- What belongs in \`body\` is the METHODOLOGY, not the artifact:
62
- - The reasoning behind the choices (why this type scale, why this palette works
63
- for this kind of room, why motion was held back here)
64
- - What the user rejected along the way and why — the negative space is the most
65
- reusable part
66
- - The anti-default list for this style: what the obvious move would have been,
67
- and why it was wrong here
68
- - Where this style BREAKS DOWN — occasions it does not suit. A skill that cannot
69
- state its own boundary is a template wearing a methodology costume, and it will
70
- produce bad work the first time it is applied off-target.
71
-
72
- Do NOT paste HTML/CSS of the finished piece. Concrete values (a specific hex, a
73
- specific scale) belong in only as illustrations of the reasoning.
74
-
75
- The skill lands in the user's personal plugin dir and becomes available in NEW
76
- sessions across all their projects (plugin discovery happens at session start,
77
- so it does not apply to the current session).`,
78
- {
79
- name: z.string()
80
- .describe('Skill id, kebab-case, 3-40 chars (e.g. "quiet-editorial-deck"). Becomes the plugin/skill name.'),
81
- title: z.string().min(2).max(80)
82
- .describe('Human-readable name of the style (e.g. "安静的编辑气质 · 长文型 deck")'),
83
- description: z.string().min(20).max(600)
84
- .describe('Frontmatter description — the routing signal. MUST say when to use it AND when not to.'),
85
- body: z.string().min(200)
86
- .describe('The methodology in markdown: reasoning, rejected alternatives, anti-default list, and where the style breaks down.'),
87
- showcaseTitle: z.string().max(80).optional()
88
- .describe('Title for the showcase card. Defaults to the style title.'),
89
- showcaseNote: z.string().max(400).optional()
90
- .describe('One line for the showcase card: what occasion this piece was for.'),
91
- artifactPath: z.string().optional()
92
- .describe('Work to show on the card, relative to workspace (e.g. "canvas.html" or "稿件/主稿.html"). Defaults to the active artifact.'),
93
- overwrite: z.boolean().optional()
94
- .describe('Replace an existing skill of the same name. Ask the user before setting this.'),
95
- },
96
- async ({ name, title, description, body, showcaseTitle, showcaseNote, artifactPath, overwrite }) => {
97
- const fail = (text) => ({ content: [{ type: 'text', text }], isError: true });
98
- try {
99
- if (!NAME_RE.test(String(name || ''))) {
100
- return fail(`Invalid skill name "${name}" — use kebab-case, 3-40 chars, e.g. "quiet-editorial-deck".`);
101
- }
102
- if (!projectId) return fail('No project bound; cannot resolve who owns this skill.');
103
- const ownerId = getProject(projectId)?.ownerId || null;
104
- const root = getUserPluginsRoot(ownerId);
105
- if (!root) {
106
- return fail('This project has no owner on record, so there is no personal skill library to write to.');
107
- }
108
-
109
- const md = composeSkillMd({ name, title, description, body });
110
- const result = await installPluginToRoot(Buffer.from(md, 'utf8'), root, { force: !!overwrite });
111
- if (result.status === 409) {
112
- return fail(`A skill named "${name}" already exists in this user's library `
113
- + `(${result.body.existing?.description || 'no description'}). `
114
- + 'Ask the user whether to replace it, then call again with overwrite: true.');
115
- }
116
- if (result.status >= 400) {
117
- const errs = (result.body.errors || []).join('; ') || result.body.error;
118
- return fail(`Skill rejected by validator: ${errs}`);
119
- }
120
-
121
- // 橱窗条目:作品 + 它沉淀出来的 skill
122
- // 橱窗条目指向的是**产物的相对路径**。扁平化前还要顺带记一个 taskId
123
- // (产物住在哪个任务文件夹里),任务层没了之后这个字段永远是 null ——
124
- // 留着列是因为 showcase 表里有存量数据,读的时候还认它。
125
- const rel = String(artifactPath || getActiveArtifact(sessionId)?.path || '').replace(/\\/g, '/');
126
- const artifactRel = rel || null;
127
- let entry = null;
128
- try {
129
- entry = upsertEntry({
130
- userId: ownerId,
131
- projectId,
132
- taskId: null,
133
- artifactRel,
134
- skillName: name,
135
- title: (showcaseTitle || title).trim(),
136
- note: showcaseNote?.trim() || null,
137
- });
138
- } catch (err) {
139
- console.warn('[crystallize_skill] showcase entry failed:', err.message);
140
- }
141
-
142
- try {
143
- ctx?.emit?.({
144
- type: 'run.skill_crystallized',
145
- skillName: name,
146
- title: title.trim(),
147
- showcaseId: entry?.id || null,
148
- });
149
- } catch { /* emit fail-safe */ }
150
-
151
- const warn = (result.body.warnings || []).length
152
- ? ` Warnings: ${result.body.warnings.join('; ')}.` : '';
153
- return {
154
- content: [{
155
- type: 'text',
156
- text: `Skill "${name}" saved to the user's personal library`
157
- + `${artifactRel ? ` and the work added to their showcase` : ''}.`
158
- + ` It becomes available in NEW sessions (not this one).${warn}`
159
- + ` Tell the user plainly what you captured and what boundary you wrote,`
160
- + ` so they can correct it while it is fresh.`,
161
- }],
162
- };
163
- } catch (err) {
164
- return fail(`crystallize_skill failed: ${err?.message || String(err)}`);
165
- }
166
- },
167
- );
168
- }
1
+ /**
2
+ * mcp/tools/crystallize-skill.js — crystallize_skill MCP tool
3
+ *
4
+ * 把一次真实探索的**结论**固化成用户自己的 skill,并把作品收进个人橱窗。
5
+ *
6
+ * 为什么不是"存模板":模板是把成品存下来,换个主题就崩——真正能复用的是判断依据
7
+ * (为什么这个字号阶梯、为什么这个场合压住动效、哪些默认做法在这个气质里必须反掉)。
8
+ * 所以这个工具收的是方法论,不是 HTML。产物写进用户级 plugin 根
9
+ * (~/.nodesign/plugins/<userId>/<name>/),下次开新会话在**这个用户的所有项目**里
10
+ * 都能用(plugin 发现是 startup-time,当前会话不生效)。
11
+ *
12
+ * 跟 record_decision 的分工:决策贴是**这一件作品**的过程档案,随任务走;
13
+ * 这里是跨项目复用的方法论,随用户走。一个是日志,一个是沉淀。
14
+ *
15
+ * 归属:写到**项目 owner** 的目录,不是"当前请求者"——同一个项目谁跑都该产出同一
16
+ * 套资产。owner 查不到就报错,不往共享根写(那是刚修掉的跨用户污染路径)。
17
+ */
18
+
19
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
20
+ import { z } from 'zod';
21
+ import { getProject } from '../../../projects/store.js';
22
+ import { getUserPluginsRoot } from '../../agent/plugin-loader.js';
23
+ import { installPluginToRoot } from '../../../lib/plugin-install.js';
24
+ import { upsertEntry } from '../../../lib/showcase-store.js';
25
+ import { getActiveArtifact } from '../../../lib/artifact-target.js';
26
+ import { Events } from '../../agent/events.js';
27
+
28
+ const NAME_RE = /^[a-z0-9][a-z0-9-]{2,39}$/;
29
+
30
+ function composeSkillMd({ name, title, description, body }) {
31
+ return [
32
+ '---',
33
+ `name: ${name}`,
34
+ `description: ${description.replace(/\n+/g, ' ').trim()}`,
35
+ 'version: 0.1.0',
36
+ '---',
37
+ '',
38
+ `# ${title.trim()}`,
39
+ '',
40
+ body.trim(),
41
+ '',
42
+ ].join('\n');
43
+ }
44
+
45
+ /**
46
+ * @param {object} deps
47
+ * @param {string} [deps.projectId]
48
+ * @param {string} [deps.sessionId]
49
+ * @param {import('../../agent/context.js').AgentContext} [deps.ctx]
50
+ */
51
+ export function makeCrystallizeSkillTool({ projectId, sessionId, ctx }) {
52
+ return tool(
53
+ 'crystallize_skill',
54
+ `Distill a style/approach the user and you worked out together into a REUSABLE
55
+ SKILL owned by this user, and put the finished work in their personal showcase.
56
+
57
+ Call this ONLY when the user asks to keep a style, or explicitly confirms they
58
+ want this approach reusable. Never call it unprompted — a skill the user did not
59
+ ask for is clutter in every future session.
60
+
61
+ What belongs in \`body\` is the METHODOLOGY, not the artifact:
62
+ - The reasoning behind the choices (why this type scale, why this palette works
63
+ for this kind of room, why motion was held back here)
64
+ - What the user rejected along the way and why — the negative space is the most
65
+ reusable part
66
+ - The anti-default list for this style: what the obvious move would have been,
67
+ and why it was wrong here
68
+ - Where this style BREAKS DOWN — occasions it does not suit. A skill that cannot
69
+ state its own boundary is a template wearing a methodology costume, and it will
70
+ produce bad work the first time it is applied off-target.
71
+
72
+ Do NOT paste HTML/CSS of the finished piece. Concrete values (a specific hex, a
73
+ specific scale) belong in only as illustrations of the reasoning.
74
+
75
+ The skill lands in the user's personal plugin dir and becomes available in NEW
76
+ sessions across all their projects (plugin discovery happens at session start,
77
+ so it does not apply to the current session).`,
78
+ {
79
+ name: z.string()
80
+ .describe('Skill id, kebab-case, 3-40 chars (e.g. "quiet-editorial-deck"). Becomes the plugin/skill name.'),
81
+ title: z.string().min(2).max(80)
82
+ .describe('Human-readable name of the style (e.g. "安静的编辑气质 · 长文型 deck")'),
83
+ description: z.string().min(20).max(600)
84
+ .describe('Frontmatter description — the routing signal. MUST say when to use it AND when not to.'),
85
+ body: z.string().min(200)
86
+ .describe('The methodology in markdown: reasoning, rejected alternatives, anti-default list, and where the style breaks down.'),
87
+ showcaseTitle: z.string().max(80).optional()
88
+ .describe('Title for the showcase card. Defaults to the style title.'),
89
+ showcaseNote: z.string().max(400).optional()
90
+ .describe('One line for the showcase card: what occasion this piece was for.'),
91
+ artifactPath: z.string().optional()
92
+ .describe('Work to show on the card, relative to workspace (e.g. "canvas.html" or "稿件/主稿.html"). Defaults to the active artifact.'),
93
+ overwrite: z.boolean().optional()
94
+ .describe('Replace an existing skill of the same name. Ask the user before setting this.'),
95
+ },
96
+ async ({ name, title, description, body, showcaseTitle, showcaseNote, artifactPath, overwrite }) => {
97
+ const fail = (text) => ({ content: [{ type: 'text', text }], isError: true });
98
+ try {
99
+ if (!NAME_RE.test(String(name || ''))) {
100
+ return fail(`Invalid skill name "${name}" — use kebab-case, 3-40 chars, e.g. "quiet-editorial-deck".`);
101
+ }
102
+ if (!projectId) return fail('No project bound; cannot resolve who owns this skill.');
103
+ const ownerId = getProject(projectId)?.ownerId || null;
104
+ const root = getUserPluginsRoot(ownerId);
105
+ if (!root) {
106
+ return fail('This project has no owner on record, so there is no personal skill library to write to.');
107
+ }
108
+
109
+ const md = composeSkillMd({ name, title, description, body });
110
+ const result = await installPluginToRoot(Buffer.from(md, 'utf8'), root, { force: !!overwrite });
111
+ if (result.status === 409) {
112
+ return fail(`A skill named "${name}" already exists in this user's library `
113
+ + `(${result.body.existing?.description || 'no description'}). `
114
+ + 'Ask the user whether to replace it, then call again with overwrite: true.');
115
+ }
116
+ if (result.status >= 400) {
117
+ const errs = (result.body.errors || []).join('; ') || result.body.error;
118
+ return fail(`Skill rejected by validator: ${errs}`);
119
+ }
120
+
121
+ // 橱窗条目:作品 + 它沉淀出来的 skill
122
+ // 橱窗条目指向的是**产物的相对路径**。扁平化前还要顺带记一个 taskId
123
+ // (产物住在哪个任务文件夹里),任务层没了之后这个字段永远是 null ——
124
+ // 留着列是因为 showcase 表里有存量数据,读的时候还认它。
125
+ const rel = String(artifactPath || getActiveArtifact(sessionId)?.path || '').replace(/\\/g, '/');
126
+ const artifactRel = rel || null;
127
+ let entry = null;
128
+ try {
129
+ entry = upsertEntry({
130
+ userId: ownerId,
131
+ projectId,
132
+ taskId: null,
133
+ artifactRel,
134
+ skillName: name,
135
+ title: (showcaseTitle || title).trim(),
136
+ note: showcaseNote?.trim() || null,
137
+ });
138
+ } catch (err) {
139
+ console.warn('[crystallize_skill] showcase entry failed:', err.message);
140
+ }
141
+
142
+ try {
143
+ ctx?.emit?.({
144
+ type: 'run.skill_crystallized',
145
+ skillName: name,
146
+ title: title.trim(),
147
+ showcaseId: entry?.id || null,
148
+ });
149
+ } catch { /* emit fail-safe */ }
150
+
151
+ const warn = (result.body.warnings || []).length
152
+ ? ` Warnings: ${result.body.warnings.join('; ')}.` : '';
153
+ return {
154
+ content: [{
155
+ type: 'text',
156
+ text: `Skill "${name}" saved to the user's personal library`
157
+ + `${artifactRel ? ` and the work added to their showcase` : ''}.`
158
+ + ` It becomes available in NEW sessions (not this one).${warn}`
159
+ + ` Tell the user plainly what you captured and what boundary you wrote,`
160
+ + ` so they can correct it while it is fresh.`,
161
+ }],
162
+ };
163
+ } catch (err) {
164
+ return fail(`crystallize_skill failed: ${err?.message || String(err)}`);
165
+ }
166
+ },
167
+ );
168
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * mcp/tools/edit-sketch.js —— edit_sketch(2026-08-23 黑板二期)
3
+ *
4
+ * 改已有的图,不重画。原则抄用户自己的 AI-Annotation-demo 里那条「引用,不吐坐标」:
5
+ * agent 只引用画布 id,位置用**相对关系**表达(在某件东西的右边/下面/上面/左边、
6
+ * 或网格位移),像素由服务端解析 —— 让模型吐绝对坐标必幻觉。
7
+ *
8
+ * 一次调用一批操作(按序执行,一条坏了其余照做并在返回里报):
9
+ * set_text 改字(文字节点:内容/格式/字号/颜色)
10
+ * move 挪一件:to {ref, side, gap?} 或 {dx, dy}(网格单位)
11
+ * move_group 挪一组(同 tag 的全部,保持相对位置):to 同上
12
+ * remove 删一件画布原生物件(text/scribble);产物卡不删(只能摘标签)
13
+ * add_node 加一个文字节点,位置 at {ref, side, gap?},归进 tag
14
+ * add_edge / set_edge / remove_edge 线的增改删(线 id 见 read_board)
15
+ * 改完前端按 board.updated 整份重拉;默认不进 staging(改的是已落定的图)。
16
+ */
17
+
18
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
19
+ import { z } from 'zod';
20
+ import { readBoard, patchBoard, TEXT_FONTS } from '../../../projects/board-store.js';
21
+ import { estimateSizeOn } from '../../../lib/board-kind-sizes.js';
22
+ import { layerOf, normalizeCanvasId } from '../../../lib/canvas-id.js';
23
+ import { BINDING_TYPE_IDS, BINDING_MATERIALS } from '../../../lib/binding-types.js';
24
+ import { UNIT, textBox } from '../../../lib/sketch-layout.js';
25
+
26
+ const MAX_OPS = 40;
27
+ let seq = 0;
28
+ const stamp = () => `${Date.now().toString(36)}${(seq++ % 1000).toString(36)}`;
29
+
30
+ const REL = z.object({
31
+ ref: z.string().min(1).max(300).describe('canvas id to place relative to'),
32
+ side: z.enum(['right', 'left', 'above', 'below']),
33
+ gap: z.number().min(0).max(40).optional().describe('grid units (default 1)'),
34
+ });
35
+ const DELTA = z.object({ dx: z.number().min(-200).max(200), dy: z.number().min(-200).max(200) }).describe('grid units');
36
+ const TO = z.union([REL, DELTA]);
37
+
38
+ const OP = z.discriminatedUnion('op', [
39
+ z.object({ op: z.literal('set_text'), id: z.string().min(1).max(300), text: z.string().min(1).max(4000).optional(), format: z.enum(['plain', 'md']).optional(), size: z.enum(['sm', 'md', 'lg', 'xl']).optional(), color: z.enum(['ink', 'red', 'pencil', 'brass']).optional(), font: z.enum(['pen', 'kai', 'sans', 'serif', 'mono']).optional() }),
40
+ z.object({ op: z.literal('move'), id: z.string().min(1).max(300), to: TO }),
41
+ z.object({ op: z.literal('move_group'), tag: z.string().min(1).max(40), to: TO }),
42
+ z.object({ op: z.literal('remove'), id: z.string().min(1).max(300) }),
43
+ z.object({ op: z.literal('add_node'), id: z.string().regex(/^[A-Za-z0-9_-]{1,24}$/).optional().describe('local handle to reference in later ops of this call'), text: z.string().min(1).max(4000), format: z.enum(['plain', 'md']).optional(), size: z.enum(['sm', 'md', 'lg', 'xl']).optional(), font: z.enum(['pen', 'kai', 'sans', 'serif', 'mono']).optional(), color: z.enum(['ink', 'red', 'pencil', 'brass']).optional(), at: REL, tag: z.string().max(40).optional() }),
44
+ z.object({ op: z.literal('add_edge'), from: z.string().min(1).max(300), to: z.string().min(1).max(300), type: z.enum(BINDING_TYPE_IDS).optional(), material: z.enum(BINDING_MATERIALS).optional(), label: z.string().max(60).optional(), tag: z.string().max(40).optional() }),
45
+ z.object({ op: z.literal('set_edge'), id: z.string().min(1).max(300), label: z.string().max(60).optional(), type: z.enum(BINDING_TYPE_IDS).optional(), material: z.enum(BINDING_MATERIALS).optional() }),
46
+ z.object({ op: z.literal('remove_edge'), id: z.string().min(1).max(300) }),
47
+ ]);
48
+
49
+ export function makeEditSketchTool({ projectId, ctx }) {
50
+ return tool(
51
+ 'edit_sketch',
52
+ `Edit what is already on the board — by id, without redrawing. Positions are RELATIVE
53
+ (to {ref, side, gap} = beside/above/below another canvas id) or grid deltas ({dx,dy},
54
+ 1 cell = ${UNIT}px); you never give absolute coordinates. ids come from read_board
55
+ (nodes: text:…/scribble:…, cards: deck:…/site:…/paths; lines: b:…).
56
+ ops (run in order; a failing op is reported, the rest still apply):
57
+ set_text{id,text?,format?,size?,color?,font?} · move{id,to} · move_group{tag,to} ·
58
+ remove{id} · add_node{id?,text,at:{ref,side,gap?},…} · add_edge{from,to,type?,material?,label?} ·
59
+ set_edge{id,label?,type?,material?} · remove_edge{id}
60
+ Use this for "move A under B", "rephrase that note", "add a branch", "delete the
61
+ wrong line". For a brand-new diagram use sketch_on_board.`,
62
+ {
63
+ tag: z.string().max(40).optional().describe('Default tag for add_node/add_edge (the sketch you are editing)'),
64
+ ops: z.array(OP).min(1).max(MAX_OPS),
65
+ },
66
+ async ({ tag: defaultTag, ops }) => {
67
+ const err = (t) => ({ content: [{ type: 'text', text: t }], isError: true });
68
+ if (!projectId) return err('No project bound.');
69
+ const board = await readBoard(projectId);
70
+ const known = new Set(Object.keys(board.zones || {}));
71
+ const objects = {}; const bindings = {}; // 增量 patch
72
+ const live = { ...board.objects }; // 本次调用内的"当前态"(让后一条 op 看见前一条的结果)
73
+ const local = new Map(); // add_node 的本地句柄 → canvas id
74
+ const rid = (raw) => { if (local.has(raw)) return local.get(raw); const c = normalizeCanvasId(raw); return c && live[c] ? c : null; };
75
+ const rectOf = (id) => { const e = live[id]; return e ? { x: e.x, y: e.y, ...estimateSizeOn(board, id, e) } : null; };
76
+ const placeRel = (box, rel) => {
77
+ const r = rectOf(rid(rel.ref));
78
+ if (!r) return null;
79
+ const g = (rel.gap ?? 1) * UNIT;
80
+ if (rel.side === 'right') return { x: r.x + r.w + g, y: r.y };
81
+ if (rel.side === 'left') return { x: r.x - g - box.w, y: r.y };
82
+ if (rel.side === 'below') return { x: r.x, y: r.y + r.h + g };
83
+ return { x: r.x, y: r.y - g - box.h };
84
+ };
85
+ const report = []; let ok = 0;
86
+ const setObj = (id, e) => { live[id] = e; objects[id] = e; };
87
+
88
+ for (let i = 0; i < ops.length; i += 1) {
89
+ const o = ops[i];
90
+ const fail = (why) => report.push(`✗ #${i + 1} ${o.op}: ${why}`);
91
+ try {
92
+ if (o.op === 'set_text') {
93
+ const id = rid(o.id); const e = id && live[id];
94
+ if (!e || e.kind !== 'text') { fail(`${o.id} 不是文字节点`); continue; }
95
+ const data = { ...e.data };
96
+ if (o.text) data.t = o.text;
97
+ if (o.format) { if (o.format === 'md') data.format = 'md'; else delete data.format; }
98
+ if (o.size) data.size = o.size; if (o.color) data.color = o.color; if (o.font && TEXT_FONTS.includes(o.font)) data.font = o.font;
99
+ const box = textBox(data.t, data.size || 'md', { md: data.format === 'md' });
100
+ setObj(id, { ...e, data, w: box.w, h: box.h }); ok += 1;
101
+ } else if (o.op === 'move') {
102
+ const id = rid(o.id); const e = id && live[id];
103
+ if (!e) { fail(`${o.id} 不在板上`); continue; }
104
+ const box = rectOf(id);
105
+ const p = 'ref' in o.to ? placeRel(box, o.to) : { x: e.x + o.to.dx * UNIT, y: e.y + o.to.dy * UNIT };
106
+ if (!p) { fail(`参照 ${o.to.ref} 不在板上`); continue; }
107
+ setObj(id, { ...e, x: Math.round(p.x), y: Math.round(p.y) }); ok += 1;
108
+ } else if (o.op === 'move_group') {
109
+ const members = Object.entries(live).filter(([, e]) => e.tag === o.tag && Number.isFinite(e?.x));
110
+ if (!members.length) { fail(`没有 #${o.tag} 的东西`); continue; }
111
+ const bb = { x: Math.min(...members.map(([, e]) => e.x)), y: Math.min(...members.map(([, e]) => e.y)) };
112
+ const rects = members.map(([id]) => rectOf(id));
113
+ const w = Math.max(...rects.map(r => r.x + r.w)) - bb.x; const h = Math.max(...rects.map(r => r.y + r.h)) - bb.y;
114
+ const p = 'ref' in o.to ? placeRel({ w, h }, o.to) : { x: bb.x + o.to.dx * UNIT, y: bb.y + o.to.dy * UNIT };
115
+ if (!p) { fail(`参照 ${o.to.ref} 不在板上`); continue; }
116
+ const dx = Math.round(p.x - bb.x); const dy = Math.round(p.y - bb.y);
117
+ for (const [id, e] of members) setObj(id, { ...e, x: e.x + dx, y: e.y + dy });
118
+ ok += 1;
119
+ } else if (o.op === 'remove') {
120
+ const id = rid(o.id); const e = id && live[id];
121
+ if (!e) { fail(`${o.id} 不在板上`); continue; }
122
+ if (!e.kind) { fail(`${id} 是产物卡,不能从黑板删;要摘标签用 finish_sketch erase`); continue; }
123
+ delete live[id]; objects[id] = null; ok += 1;
124
+ } else if (o.op === 'add_node') {
125
+ const size = (o.size === 'sm' && o.text.length > 40) ? 'md' : (o.size || 'md');
126
+ const box = textBox(o.text, size, { md: o.format === 'md' });
127
+ const p = placeRel(box, o.at);
128
+ if (!p) { fail(`参照 ${o.at.ref} 不在板上`); continue; }
129
+ const refId = rid(o.at.ref);
130
+ const zone = layerOf(refId, live[refId], known);
131
+ const id = `text:a${stamp()}`;
132
+ const tag = o.tag || defaultTag || live[refId]?.tag || null;
133
+ setObj(id, {
134
+ x: Math.round(p.x), y: Math.round(p.y), z: 1, w: box.w, h: box.h, kind: 'text',
135
+ data: { t: o.text, ...(o.format === 'md' ? { format: 'md' } : {}), font: TEXT_FONTS.includes(o.font) ? o.font : 'pen', size, color: o.color || 'ink' },
136
+ zone, by: 'agent', ...(tag ? { tag } : {}),
137
+ });
138
+ if (o.id) local.set(o.id, id);
139
+ report.push(`+ node ${o.id ? `${o.id}=` : ''}${id}`); ok += 1;
140
+ } else if (o.op === 'add_edge') {
141
+ const from = rid(o.from); const to = rid(o.to);
142
+ if (!from || !to || from === to) { fail(`端点不在板上:${o.from} → ${o.to}`); continue; }
143
+ const id = `b:a${stamp()}`;
144
+ const tag = o.tag || defaultTag || live[from]?.tag || live[to]?.tag || null;
145
+ bindings[id] = { type: o.type || 'link', from, to, by: 'agent', ...(o.material && o.material !== 'ink' ? { material: o.material } : {}), ...(o.label ? { label: o.label } : {}), ...(tag ? { tag } : {}) };
146
+ report.push(`+ edge ${id}`); ok += 1;
147
+ } else if (o.op === 'set_edge') {
148
+ const b = board.bindings?.[o.id];
149
+ if (!b) { fail(`线 ${o.id} 不存在`); continue; }
150
+ const nb = { ...b };
151
+ if (o.label !== undefined) { if (o.label) nb.label = o.label; else delete nb.label; }
152
+ if (o.type) nb.type = o.type;
153
+ if (o.material) { if (o.material === 'ink') delete nb.material; else nb.material = o.material; }
154
+ bindings[o.id] = nb; ok += 1;
155
+ } else if (o.op === 'remove_edge') {
156
+ if (!board.bindings?.[o.id]) { fail(`线 ${o.id} 不存在`); continue; }
157
+ bindings[o.id] = null; ok += 1;
158
+ }
159
+ } catch (e) { fail(String(e?.message || e).slice(0, 120)); }
160
+ }
161
+ if (!ok) return err(`没有一条操作成功:\n${report.join('\n')}`);
162
+ await patchBoard(projectId, { objects, bindings });
163
+ try { ctx?.emit?.({ type: 'board.updated', sessionId: null, summary: `改了黑板(${ok} 处)` }); } catch { /* */ }
164
+ return { content: [{ type: 'text', text: `Applied ${ok}/${ops.length} op(s).${report.length ? `\n${report.join('\n')}` : ''}` }] };
165
+ },
166
+ );
167
+ }