@xiaobuyu/nodesign 0.0.1

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 (372) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +140 -0
  3. package/bin/nodesign.js +176 -0
  4. package/package.json +104 -0
  5. package/server/api/README.md +45 -0
  6. package/server/api/_guard.js +75 -0
  7. package/server/api/admin.js +187 -0
  8. package/server/api/assets/docx-page.js +103 -0
  9. package/server/api/assets/helpers.js +22 -0
  10. package/server/api/assets/notes.js +144 -0
  11. package/server/api/assets.js +896 -0
  12. package/server/api/board.js +57 -0
  13. package/server/api/browse.js +138 -0
  14. package/server/api/canvas.js +444 -0
  15. package/server/api/chatai.js +324 -0
  16. package/server/api/exports/build-standalone.js +980 -0
  17. package/server/api/exports/cards.js +118 -0
  18. package/server/api/exports/docx-pdf.js +46 -0
  19. package/server/api/exports/export-page.js +142 -0
  20. package/server/api/exports/handoff.js +147 -0
  21. package/server/api/exports.js +690 -0
  22. package/server/api/instruction.js +75 -0
  23. package/server/api/local.js +115 -0
  24. package/server/api/me.js +116 -0
  25. package/server/api/memory.js +185 -0
  26. package/server/api/pending-changes.js +366 -0
  27. package/server/api/plugins.js +164 -0
  28. package/server/api/projects.js +220 -0
  29. package/server/api/publish.js +64 -0
  30. package/server/api/recent.js +73 -0
  31. package/server/api/sessions.js +589 -0
  32. package/server/api/skills.js +77 -0
  33. package/server/api/standalone-fit.js +168 -0
  34. package/server/api/turn-compose.js +180 -0
  35. package/server/api/turn-inflight.js +44 -0
  36. package/server/api/turn.js +669 -0
  37. package/server/auth/README.md +17 -0
  38. package/server/auth/middleware.js +138 -0
  39. package/server/auth/origin-guard.js +71 -0
  40. package/server/auth/session.js +108 -0
  41. package/server/auth/tier.js +113 -0
  42. package/server/auth/users-store.js +348 -0
  43. package/server/edit/README.md +29 -0
  44. package/server/engine/README.md +113 -0
  45. package/server/engine/agent/agent-shared.js +550 -0
  46. package/server/engine/agent/auto-mode-default-hard-deny.txt +4 -0
  47. package/server/engine/agent/auto-mode-rules.js +78 -0
  48. package/server/engine/agent/context.js +418 -0
  49. package/server/engine/agent/events.js +464 -0
  50. package/server/engine/agent/hooks/canvas-validate.js +199 -0
  51. package/server/engine/agent/hooks/failure.js +120 -0
  52. package/server/engine/agent/hooks/file-events.js +75 -0
  53. package/server/engine/agent/hooks/lifecycle.js +233 -0
  54. package/server/engine/agent/hooks/post-canvas-focus.js +80 -0
  55. package/server/engine/agent/hooks/post-guidance.js +206 -0
  56. package/server/engine/agent/hooks/post-subagent-report.js +104 -0
  57. package/server/engine/agent/hooks/post-trim.js +58 -0
  58. package/server/engine/agent/hooks/pre-board-neighborhood.js +34 -0
  59. package/server/engine/agent/hooks/pre-defaults.js +84 -0
  60. package/server/engine/agent/hooks/pre-injectors.js +277 -0
  61. package/server/engine/agent/hooks/pre-performance-log-guard.js +78 -0
  62. package/server/engine/agent/hooks/pre-starter-files.js +61 -0
  63. package/server/engine/agent/hooks/pre-workspace-scope-guard.js +78 -0
  64. package/server/engine/agent/hooks/site-validate.js +94 -0
  65. package/server/engine/agent/hooks/tool-prompts.js +31 -0
  66. package/server/engine/agent/hooks/turn-state-memory.js +56 -0
  67. package/server/engine/agent/hooks/user-prompt-submit.js +215 -0
  68. package/server/engine/agent/hooks.js +354 -0
  69. package/server/engine/agent/init-contract.js +69 -0
  70. package/server/engine/agent/isolation.js +159 -0
  71. package/server/engine/agent/model-context.js +359 -0
  72. package/server/engine/agent/model-table.js +292 -0
  73. package/server/engine/agent/plugin-loader.js +266 -0
  74. package/server/engine/agent/prompts/nodesign-prelude.md +336 -0
  75. package/server/engine/agent/prompts/tools/ask-user-question-protocol.md +71 -0
  76. package/server/engine/agent/prompts/tools/direct-edit-protocol.md +98 -0
  77. package/server/engine/agent/prompts/tools/generate-image-cookbook.gemini-gateway.md +583 -0
  78. package/server/engine/agent/prompts/tools/generate-image-cookbook.md +483 -0
  79. package/server/engine/agent/prompts/tools/hybrid-reference.md +100 -0
  80. package/server/engine/agent/prompts/tools/paint-still-cookbook.md +270 -0
  81. package/server/engine/agent/prompts/tools/roll-film-cookbook.md +70 -0
  82. package/server/engine/agent/prompts/tools/site-reference.md +106 -0
  83. package/server/engine/agent/prompts/tools/tweaks-syntax.md +125 -0
  84. package/server/engine/agent/prompts/tools/vision-checker-dispatch.md +48 -0
  85. package/server/engine/agent/session-loop.js +1024 -0
  86. package/server/engine/agent/session-model.js +164 -0
  87. package/server/engine/agent/skill.js +204 -0
  88. package/server/engine/agent/system-prompts.js +86 -0
  89. package/server/engine/agent/task-events.js +78 -0
  90. package/server/engine/agents/ds-extractor.md +132 -0
  91. package/server/engine/agents/explorer.md +190 -0
  92. package/server/engine/agents/index.js +230 -0
  93. package/server/engine/agents/schemas/design-system.json +156 -0
  94. package/server/engine/agents/schemas/tweak-schema.json +113 -0
  95. package/server/engine/agents/tweak-proposer.md +127 -0
  96. package/server/engine/agents/vision-checker.md +254 -0
  97. package/server/engine/browse/capture.js +422 -0
  98. package/server/engine/browse/card.js +137 -0
  99. package/server/engine/browse/handover.js +59 -0
  100. package/server/engine/browse/page-digest.js +119 -0
  101. package/server/engine/browse/refs.js +196 -0
  102. package/server/engine/browse/registry.js +307 -0
  103. package/server/engine/browse/screencast.js +170 -0
  104. package/server/engine/browse/state.js +121 -0
  105. package/server/engine/chatai/chat-log.js +79 -0
  106. package/server/engine/chatai/index.js +193 -0
  107. package/server/engine/chatai/openai-compat.js +152 -0
  108. package/server/engine/chatai/orchestrate.js +309 -0
  109. package/server/engine/chatai/perform.js +40 -0
  110. package/server/engine/chatai/summarize.js +79 -0
  111. package/server/engine/mcp/capability-gate.js +52 -0
  112. package/server/engine/mcp/index.js +339 -0
  113. package/server/engine/mcp/param-sanitizer.js +142 -0
  114. package/server/engine/mcp/tools/arrange-on-board.js +124 -0
  115. package/server/engine/mcp/tools/artifact-session.js +278 -0
  116. package/server/engine/mcp/tools/browse-computer.js +421 -0
  117. package/server/engine/mcp/tools/browse-find-batch.js +183 -0
  118. package/server/engine/mcp/tools/browse-screenshot.js +157 -0
  119. package/server/engine/mcp/tools/browse.js +480 -0
  120. package/server/engine/mcp/tools/build-docx.js +101 -0
  121. package/server/engine/mcp/tools/clear-pending-changes.js +99 -0
  122. package/server/engine/mcp/tools/create-on-board.js +155 -0
  123. package/server/engine/mcp/tools/crystallize-skill.js +168 -0
  124. package/server/engine/mcp/tools/deliver-files.js +0 -0
  125. package/server/engine/mcp/tools/explain-style.js +237 -0
  126. package/server/engine/mcp/tools/export-handoff.js +133 -0
  127. package/server/engine/mcp/tools/expose-tweaks.js +149 -0
  128. package/server/engine/mcp/tools/generate-image.js +842 -0
  129. package/server/engine/mcp/tools/get-computed-styles.js +164 -0
  130. package/server/engine/mcp/tools/get-pending-changes.js +205 -0
  131. package/server/engine/mcp/tools/h3box-ssh.js +84 -0
  132. package/server/engine/mcp/tools/helpers/acquire-page.js +82 -0
  133. package/server/engine/mcp/tools/helpers/motion-lab.js +554 -0
  134. package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -0
  135. package/server/engine/mcp/tools/helpers/perception-page.js +215 -0
  136. package/server/engine/mcp/tools/helpers/reference-download.js +103 -0
  137. package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -0
  138. package/server/engine/mcp/tools/helpers/rembg.js +273 -0
  139. package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -0
  140. package/server/engine/mcp/tools/highlight.js +68 -0
  141. package/server/engine/mcp/tools/list-pages.js +222 -0
  142. package/server/engine/mcp/tools/lookup-tags.js +59 -0
  143. package/server/engine/mcp/tools/navigate-to-page.js +60 -0
  144. package/server/engine/mcp/tools/organize-board.js +64 -0
  145. package/server/engine/mcp/tools/paint-still.js +434 -0
  146. package/server/engine/mcp/tools/pin-to-board.js +130 -0
  147. package/server/engine/mcp/tools/preview-deck.js +130 -0
  148. package/server/engine/mcp/tools/profile-scroll.js +305 -0
  149. package/server/engine/mcp/tools/publish-site.js +102 -0
  150. package/server/engine/mcp/tools/query-elements.js +195 -0
  151. package/server/engine/mcp/tools/read-board.js +103 -0
  152. package/server/engine/mcp/tools/read-document.js +93 -0
  153. package/server/engine/mcp/tools/read-page.js +264 -0
  154. package/server/engine/mcp/tools/read-tavern-json.js +143 -0
  155. package/server/engine/mcp/tools/record-decision.js +140 -0
  156. package/server/engine/mcp/tools/relate-on-board.js +110 -0
  157. package/server/engine/mcp/tools/remove-background.js +391 -0
  158. package/server/engine/mcp/tools/report-issue.js +115 -0
  159. package/server/engine/mcp/tools/roll-film.js +266 -0
  160. package/server/engine/mcp/tools/screenshot-docx.js +138 -0
  161. package/server/engine/mcp/tools/screenshot-url.js +195 -0
  162. package/server/engine/mcp/tools/screenshot.js +583 -0
  163. package/server/engine/mcp/tools/tier-gate.js +96 -0
  164. package/server/engine/mcp/tools/trace-motion.js +215 -0
  165. package/server/engine/mcp/tools/web-search.js +548 -0
  166. package/server/engine/motion/inventory.js +349 -0
  167. package/server/engine/perception/session.js +235 -0
  168. package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -0
  169. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +192 -0
  170. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -0
  171. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -0
  172. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -0
  173. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -0
  174. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -0
  175. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -0
  176. package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -0
  177. package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +162 -0
  178. package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -0
  179. package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -0
  180. package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +228 -0
  181. 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 -0
  182. package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -0
  183. package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +323 -0
  184. package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -0
  185. package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -0
  186. package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -0
  187. package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -0
  188. package/server/engine/runs/active-runs.js +698 -0
  189. package/server/engine/runs/live-turn.js +252 -0
  190. package/server/engine/runs/store.js +364 -0
  191. package/server/engine/runs/turn-relay.js +217 -0
  192. package/server/engine/runtime/workspace.js +164 -0
  193. package/server/index.js +235 -0
  194. package/server/lib/artifact-file-path.js +80 -0
  195. package/server/lib/artifact-target.js +284 -0
  196. package/server/lib/asset-refs.js +239 -0
  197. package/server/lib/async-queue.js +104 -0
  198. package/server/lib/auto-relations.js +130 -0
  199. package/server/lib/binding-types.js +60 -0
  200. package/server/lib/board-kind-sizes.js +62 -0
  201. package/server/lib/board-relations.js +133 -0
  202. package/server/lib/browse-proxy.js +180 -0
  203. package/server/lib/canvas-id.js +36 -0
  204. package/server/lib/cover.js +227 -0
  205. package/server/lib/danbooru-tags.js +291 -0
  206. package/server/lib/doc-extract.js +156 -0
  207. package/server/lib/docx/build-from-source.js +260 -0
  208. package/server/lib/docx/build.js +490 -0
  209. package/server/lib/docx/dump-styles.js +287 -0
  210. package/server/lib/docx/fonts/nodesign-cjk.conf +164 -0
  211. package/server/lib/docx/merge-runs.js +129 -0
  212. package/server/lib/docx/numbering.js +218 -0
  213. package/server/lib/docx/order.js +152 -0
  214. package/server/lib/docx/rawzip.js +172 -0
  215. package/server/lib/docx/render.js +92 -0
  216. package/server/lib/docx/text-lint.js +225 -0
  217. package/server/lib/docx/tokens.js +335 -0
  218. package/server/lib/docx/units.js +29 -0
  219. package/server/lib/docx/xml.js +291 -0
  220. package/server/lib/docx-pages.js +187 -0
  221. package/server/lib/export-collect.js +289 -0
  222. package/server/lib/export-package.js +210 -0
  223. package/server/lib/html-srcset.js +145 -0
  224. package/server/lib/image-variant.js +460 -0
  225. package/server/lib/ingress/forward-openai-chat.js +305 -0
  226. package/server/lib/ingress/openai-chat.js +491 -0
  227. package/server/lib/ingress/session-notice.js +66 -0
  228. package/server/lib/ingress/session-routes.js +68 -0
  229. package/server/lib/ingress/slot-probe.js +130 -0
  230. package/server/lib/ingress/upstream-billing.js +52 -0
  231. package/server/lib/ingress/upstream-fail-streak.js +72 -0
  232. package/server/lib/ingress/upstream-truncation.js +48 -0
  233. package/server/lib/issues-store.js +182 -0
  234. package/server/lib/kinds/deck.js +72 -0
  235. package/server/lib/kinds/docx.js +283 -0
  236. package/server/lib/kinds/file-kinds.js +113 -0
  237. package/server/lib/kinds/index.js +202 -0
  238. package/server/lib/kinds/site.js +161 -0
  239. package/server/lib/model-ingress.js +543 -0
  240. package/server/lib/moderation.js +255 -0
  241. package/server/lib/notice-store.js +103 -0
  242. package/server/lib/plugin-install.js +104 -0
  243. package/server/lib/plugin-validator.js +721 -0
  244. package/server/lib/publish-store.js +115 -0
  245. package/server/lib/quick-summary.js +52 -0
  246. package/server/lib/quota.js +270 -0
  247. package/server/lib/rate-window.js +29 -0
  248. package/server/lib/reference-assets.js +92 -0
  249. package/server/lib/region-shot.js +135 -0
  250. package/server/lib/safe-path.js +73 -0
  251. package/server/lib/sdk-session.js +33 -0
  252. package/server/lib/showcase-store.js +92 -0
  253. package/server/lib/site-publish.js +465 -0
  254. package/server/lib/ssrf-guard.js +432 -0
  255. package/server/lib/task-scan.js +158 -0
  256. package/server/lib/tavern-json.js +154 -0
  257. package/server/lib/video-variant.js +237 -0
  258. package/server/lib/workspace-path.js +33 -0
  259. package/server/ops/fix-sdk-musl.mjs +40 -0
  260. package/server/ops/install-macos-fonts.sh +114 -0
  261. package/server/ops/macos-fonts.conf +336 -0
  262. package/server/ops/sandbox-shim/bwrap +57 -0
  263. package/server/projects/assets-summary.js +119 -0
  264. package/server/projects/auto-name.js +53 -0
  265. package/server/projects/board-store.js +640 -0
  266. package/server/projects/move-entry.js +103 -0
  267. package/server/projects/store.js +270 -0
  268. package/server/projects/ui-config.js +54 -0
  269. package/server/projects/workspace-templates.js +53 -0
  270. package/server/projects/workspace.js +1025 -0
  271. package/server/runtime/capabilities.js +153 -0
  272. package/server/runtime/local-config.js +177 -0
  273. package/server/runtime/local-env.js +88 -0
  274. package/server/runtime/platform.js +342 -0
  275. package/server/runtime/profile.js +72 -0
  276. package/server/services/rembg-launcher.js +313 -0
  277. package/server/services/rembg-service.py +334 -0
  278. package/server/shared/README.md +25 -0
  279. package/server/shared/deck.js +54 -0
  280. package/server/shared/time.js +49 -0
  281. package/server/style-pipeline/README.md +53 -0
  282. package/server/ws/broker.js +36 -0
  283. package/server/ws/browse-channel.js +177 -0
  284. package/server/ws/index.js +386 -0
  285. package/web/README.md +89 -0
  286. package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +11 -0
  287. package/web/dist/assets/DeckWindow-4G0xX7P3.js +16 -0
  288. package/web/dist/assets/DocxWindow-BXQsoPkh.js +16 -0
  289. package/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  290. package/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  291. package/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  292. package/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  293. package/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  294. package/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  295. package/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  296. package/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  297. package/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  298. package/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  299. package/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  300. package/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  301. package/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  302. package/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  303. package/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  304. package/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  305. package/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  306. package/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  307. package/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  308. package/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  309. package/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  310. package/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  311. package/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  312. package/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  313. package/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  314. package/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  315. package/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  316. package/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  317. package/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  318. package/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  319. package/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  320. package/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  321. package/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  322. package/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  323. package/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  324. package/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  325. package/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  326. package/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  327. package/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  328. package/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  329. package/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  330. package/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  331. package/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  332. package/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  333. package/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  334. package/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  335. package/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  336. package/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  337. package/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  338. package/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  339. package/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  340. package/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  341. package/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  342. package/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  343. package/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  344. package/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  345. package/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  346. package/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  347. package/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  348. package/web/dist/assets/SiteWindow-D6eS-2gM.js +18 -0
  349. package/web/dist/assets/again-D8tfgKKO.webp +0 -0
  350. package/web/dist/assets/caveat-nd-CP6HlsNg.woff2 +0 -0
  351. package/web/dist/assets/clock-xJhvfYpS.webp +0 -0
  352. package/web/dist/assets/film-cut-BBKMwH7q.webp +0 -0
  353. package/web/dist/assets/film-still-BZ_DL9Tt.webp +0 -0
  354. package/web/dist/assets/index-C0KUf6Wd.css +1 -0
  355. package/web/dist/assets/index-Cbl3ATvp.js +2125 -0
  356. package/web/dist/assets/ink-desk-BRbxeDsR.webp +0 -0
  357. package/web/dist/assets/ink-night-Bz4BT3XH.webp +0 -0
  358. package/web/dist/assets/ink-portrait-C0DM4V8Q.webp +0 -0
  359. package/web/dist/assets/longcang-regular-C0uvTuKa.woff2 +0 -0
  360. package/web/dist/assets/lxgw-nd-bold-DbRfiTgo.woff2 +0 -0
  361. package/web/dist/assets/lxgw-nd-regular-CpMw9Ehg.woff2 +0 -0
  362. package/web/dist/assets/pending-edit-apply-DTjo2geW.js +31 -0
  363. package/web/dist/assets/question-8H4HSqxh.webp +0 -0
  364. package/web/dist/assets/reject-BaPJqElj.webp +0 -0
  365. package/web/dist/assets/rotate-cw-LMT3x1Zj.js +11 -0
  366. package/web/dist/assets/rp-portrait-CbrGpew2.webp +0 -0
  367. package/web/dist/assets/rp-street-C4jVKjxx.webp +0 -0
  368. package/web/dist/assets/square-dashed-mouse-pointer-CBoAkfhi.js +11 -0
  369. package/web/dist/assets/tangle-DIxHVNuT.webp +0 -0
  370. package/web/dist/assets/thisone-BylZKglV.webp +0 -0
  371. package/web/dist/assets/thumb-DO1wfK1I.webp +0 -0
  372. package/web/dist/index.html +18 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * mcp/tools/build-docx.js — build_docx MCP tool(2026-08-17)
3
+ *
4
+ * 把 token 源文件构建成 .docx。
5
+ *
6
+ * ⭐**agent 拿到的是一条命令,不是一个构建系统。** 它写 JSON、调这个工具、
7
+ * 然后 screenshot 看结果 —— 不需要知道 OOXML、不需要跑 node、不需要碰沙盒
8
+ * 外的东西。(跟 h3box / publish_site 一个路子。)
9
+ *
10
+ * ⚠️ 构建完**不自动截图**:那会让每次构建都多花几秒和一张图的上下文。看不看
11
+ * 由 agent 自己决定 —— 但返回文案里会催它去看,因为「做完看一眼」这条纪律在
12
+ * docx 上比在网页上更要紧(没有 DOM 可查,眼睛是唯一的验收手段)。
13
+ */
14
+
15
+ import path from 'node:path';
16
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
17
+ import { z } from 'zod';
18
+ import { buildFromSource, DocxSourceError } from '../../../lib/docx/build-from-source.js';
19
+ import { formatLint } from '../../../lib/docx/text-lint.js';
20
+ import { setActiveArtifact } from '../../../lib/artifact-target.js';
21
+ import { safeResolveRead, safeResolveWrite } from '../../../lib/safe-path.js';
22
+ import { Events } from '../../agent/events.js';
23
+
24
+ const err = (text) => ({ content: [{ type: 'text', text }], isError: true });
25
+
26
+ export function makeBuildDocxTool({ workspaceRoot, sessionId, ctx }) {
27
+ return tool(
28
+ 'build_docx',
29
+ `Build a .docx from its token source file.
30
+
31
+ The token JSON is the source of truth; the .docx is a build output. Always edit
32
+ the JSON and rebuild — never hand-edit the .docx, or the next build silently
33
+ throws your edit away.
34
+
35
+ Source file shape:
36
+ {
37
+ "preset": "公文", // dictionary entry to start from (optional)
38
+ "tokens": { ... }, // overrides on top of the preset
39
+ "content": [ {"t":"p","style":"Normal","text":"..."} ],
40
+ "header": "...", "footer": "..." // optional
41
+ }
42
+
43
+ Built-in dictionary entries: 办公标准 (plain Office look) / 公文 (GB/T 9704-2012
44
+ Chinese official document) / 学术论文 (Chinese academic). These are starting
45
+ points, not a menu — override tokens freely, or skip preset and supply the full
46
+ token table.
47
+
48
+ Block types: {"t":"p"} paragraph, {"t":"table"}, {"t":"pageBreak"}.
49
+
50
+ After building, LOOK AT IT with screenshot. A .docx has no DOM — rendering is
51
+ the only way to verify layout, and "it built without errors" says nothing about
52
+ whether it looks right.`,
53
+ {
54
+ source: z
55
+ .string()
56
+ .optional()
57
+ .describe("Token source file, workspace-relative. Defaults to '文档.json'."),
58
+ output: z
59
+ .string()
60
+ .optional()
61
+ .describe("Output .docx path, workspace-relative. Defaults to the source name with a .docx extension."),
62
+ },
63
+ async ({ source, output }) => {
64
+ const srcRel = (source || '文档.json').replace(/\\/g, '/');
65
+ const outRel = (output || srcRel.replace(/\.json$/i, '.docx')).replace(/\\/g, '/');
66
+ if (!/\.docx$/i.test(outRel)) return err(`输出得是 .docx,收到的是 ${outRel}`);
67
+
68
+ // ⚠️ 词法检查挡不住软链:工作区里一个指向外面的 `out.docx` 软链,会让这个
69
+ // 工具变成一个**绕过沙盒的任意写原语**(MCP 工具跑在 server 进程里,不在
70
+ // bwrap 内)。读写判据不同,见 lib/safe-path.js。
71
+ const srcAbs = await safeResolveRead(workspaceRoot, srcRel);
72
+ if (!srcAbs) return err('源路径跑出工作区了');
73
+ const outAbs = await safeResolveWrite(workspaceRoot, outRel);
74
+ if (!outAbs) return err('产物路径跑出工作区了(目标是软链也会被拒 —— 顺着它写会覆盖工作区外的文件)');
75
+
76
+ try {
77
+ const r = await buildFromSource(srcAbs, outAbs);
78
+ // 记成当前产物,这样后面 screenshot / 导出不传 path 也能找到它
79
+ setActiveArtifact(sessionId, outRel, 'docx');
80
+ // emit file_changed —— 让画布上的 docx 卡**当场**换新页图。MCP 工具写盘
81
+ // 不走 PostToolUse(Write|Edit) 那条直发(matcher 匹配不到 mcp__nodesign__*),
82
+ // 不发的话卡片停在旧页图,最多等 60 秒缓存自然过期(generate-image 同款补发)
83
+ try { ctx?.emit?.(Events.fileChanged(outRel, 'change')); } catch { /* fail-safe */ }
84
+ return {
85
+ content: [{
86
+ type: 'text',
87
+ text: `${outRel} 已构建 · ${(r.bytes / 1024).toFixed(1)}KB · ${r.blocks} 个块 · ${r.styles} 个样式`
88
+ + `${r.preset ? ` · 起点「${r.preset}」` : ''}\n`
89
+ // 字符/版式体检:符号惯例与全文一致性,schema 和渲染都照不到的那层
90
+ + (r.lint ? formatLint(r.lint) : ''),
91
+ }],
92
+ };
93
+ } catch (e) {
94
+ if (e instanceof DocxSourceError) {
95
+ return err(`${srcRel} 构建失败:${e.message}${e.detail ? `\n${e.detail}` : ''}`);
96
+ }
97
+ return err(`构建出错:${String(e.message || e).slice(0, 500)}`);
98
+ }
99
+ },
100
+ );
101
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * mcp/tools/clear-pending-changes.js — clear_pending_changes MCP tool
3
+ *
4
+ * 配 get_pending_changes 用:agent 处理完 pending 变更后清 buffer,
5
+ * 避免下次 turn 又看到同样的变更被反复处理。
6
+ *
7
+ * 不传 ids → 全清;传 ids → 只删指定。
8
+ */
9
+
10
+ import path from 'node:path';
11
+ import fs from 'node:fs/promises';
12
+ import { tool } from '@anthropic-ai/claude-agent-sdk';
13
+ import { z } from 'zod';
14
+
15
+ /**
16
+ * @param {object} deps
17
+ * @param {string} deps.workspaceRoot
18
+ * @param {import('../../agent/context.js').AgentContext} [deps.ctx]
19
+ */
20
+ export function makeClearPendingChangesTool({ workspaceRoot, ctx }) {
21
+ return tool(
22
+ 'clear_pending_changes',
23
+ `Clear processed items from the user's pending changes buffer.
24
+
25
+ Call this after you've read pending changes via get_pending_changes and
26
+ acted on them, so the same changes don't re-appear in the next turn.
27
+
28
+ - Omit ids → clear all
29
+ - Pass ids → clear only those specific items`,
30
+ {
31
+ ids: z
32
+ .array(z.string())
33
+ .optional()
34
+ .describe('Specific item ids to clear; omit to clear everything'),
35
+ },
36
+ async ({ ids }) => {
37
+ try {
38
+ if (!workspaceRoot) {
39
+ return {
40
+ content: [{ type: 'text', text: 'No workspace bound; cannot clear pending changes.' }],
41
+ isError: true,
42
+ };
43
+ }
44
+
45
+ const bufPath = path.join(workspaceRoot, 'pending-changes.json');
46
+ let buf = { items: [] };
47
+ try {
48
+ const raw = await fs.readFile(bufPath, 'utf8');
49
+ const parsed = JSON.parse(raw);
50
+ if (parsed && Array.isArray(parsed.items)) buf = parsed;
51
+ } catch (err) {
52
+ if (err.code !== 'ENOENT') throw err;
53
+ }
54
+
55
+ const beforeItems = buf.items;
56
+ let clearedItems;
57
+ if (Array.isArray(ids) && ids.length > 0) {
58
+ const set = new Set(ids);
59
+ clearedItems = beforeItems.filter(it => set.has(it.id));
60
+ buf.items = beforeItems.filter(it => !set.has(it.id));
61
+ } else {
62
+ clearedItems = beforeItems;
63
+ buf.items = [];
64
+ }
65
+ const removed = clearedItems.length;
66
+ // 带上被清的 id 列表,让前端可以同步移除 comments state 里对应的橙色 overlay。
67
+ // 前端 comments[].id 跟 pending-changes item.id 已统一(见 ProjectWorkspace
68
+ // handleAddComment + pending-changes.js POST accept body.id)。
69
+ const clearedIds = clearedItems.map(it => it.id);
70
+
71
+ await fs.writeFile(bufPath, JSON.stringify(buf, null, 2), 'utf8');
72
+
73
+ try {
74
+ ctx?.emit?.({
75
+ type: 'run.pending_changes_cleared',
76
+ clearedIds,
77
+ removed,
78
+ remaining: buf.items.length,
79
+ });
80
+ } catch { /* emit fail-safe */ }
81
+
82
+ return {
83
+ content: [{
84
+ type: 'text',
85
+ text: `Cleared ${removed} pending change(s); ${buf.items.length} remaining.`,
86
+ }],
87
+ };
88
+ } catch (err) {
89
+ return {
90
+ content: [{
91
+ type: 'text',
92
+ text: `clear_pending_changes failed: ${err?.message || String(err)}`,
93
+ }],
94
+ isError: true,
95
+ };
96
+ }
97
+ },
98
+ );
99
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * mcp/tools/create-on-board.js —— create_on_board(2026-08-14,agent 建元素批)
3
+ *
4
+ * 让 agent 落**用户级的画布原生物件**。v1 只开手写字(text):便签是留档不是
5
+ * 聊天,agent 值得写下来的是"这一版为什么这么改"这类一句话,不是回复的搬运。
6
+ * 涂鸦不开 —— agent 画矢量笔迹没有意义,它要画图走生图。
7
+ *
8
+ * 设计对齐用户侧:
9
+ * - near 锚定 = 用户"标注"的同构(落在锚右侧空白,关系线可选一步带上)——
10
+ * 一次调用 = 一段字 + 一条线,跟 keepAnnotation 落的东西一模一样
11
+ * - 字体/字号走 board-store 同一份白名单(TEXT_FONTS)
12
+ * - 尺寸估算抄前端 handleCreateText 同款公式(约 26 全角字/行)
13
+ * - by:'agent' 出处,用户一眼分得出谁写的
14
+ *
15
+ * 护栏:每回合上限 4 条 —— 画布是版面不是弹幕区。
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 { estimateSize } from '../../../lib/board-kind-sizes.js';
22
+ import { normalizeCanvasId, layerOf } from '../../../lib/canvas-id.js';
23
+
24
+ const MAX_PER_TURN = 4;
25
+ const SIZE_PX = { sm: 13, md: 16, lg: 22, xl: 30 };
26
+
27
+ let seq = 0;
28
+ const nextTextId = () => `text:a${Date.now().toString(36)}${(seq++ % 1000).toString(36)}`;
29
+ const nextBindingId = () => `b:a${Date.now().toString(36)}n${(seq++ % 1000).toString(36)}`;
30
+
31
+ /** 前端 handleCreateText 同款身位估算(约 26 全角字/行,行高 1.6) */
32
+ function textBox(t, sizeKey) {
33
+ const px = SIZE_PX[sizeKey] || 16;
34
+ const cols = Math.min(26, Math.max(6, t.length));
35
+ const lines = Math.ceil(t.length / cols) + (t.match(/\n/g)?.length || 0);
36
+ return { w: Math.round(cols * px * 1.05) + 12, h: Math.round(lines * px * 1.6) + 10 };
37
+ }
38
+
39
+ export function makeCreateOnBoardTool({ projectId, ctx }) {
40
+ const turnStamp = { turn: -1, count: 0 };
41
+ return tool(
42
+ 'create_on_board',
43
+ `Write a handwritten note directly on the canvas — the same kind the user writes.
44
+
45
+ Use it for remarks worth KEEPING on the board: why a version went this way, what
46
+ to compare, a caption for a group. Not for conversation (that goes in your reply)
47
+ and not for documents (write a .md instead). Hard cap: ${MAX_PER_TURN} notes per turn.
48
+
49
+ - near: anchor it beside a thing (and usually pass relation to draw the line —
50
+ that is exactly the user's "annotation" gesture: a note + an annotates edge)
51
+ - omit near: the note lands under the desktop's current content`,
52
+ {
53
+ text: z.string().min(1).max(200).describe('The note text (≤200 chars, one thought)'),
54
+ near: z.string().max(300).optional()
55
+ .describe('Canvas id to place the note next to (right side, auto-avoids overlap)'),
56
+ relation: z.object({
57
+ type: z.enum(['annotates', 'link']).describe('annotates = the note is ABOUT it; link = loosely related'),
58
+ to: z.string().min(1).max(300).describe('Canvas id the line connects to (usually = near)'),
59
+ label: z.string().max(60).optional().describe('Optional words on the line (link only usually)'),
60
+ }).optional().describe('Draw a relation line from the note in the same call'),
61
+ font: z.enum(['pen', 'kai', 'sans', 'serif', 'mono']).optional()
62
+ .describe('Handwriting style (default pen — same as the user\'s default)'),
63
+ size: z.enum(['sm', 'md', 'lg', 'xl']).optional().describe('Text size (default md)'),
64
+ },
65
+ async ({ text, near: rawNear, relation, font, size }) => {
66
+ if (!projectId) {
67
+ return { content: [{ type: 'text', text: 'No project bound.' }], isError: true };
68
+ }
69
+ const err = (t) => ({ content: [{ type: 'text', text: t }], isError: true });
70
+
71
+ const turn = ctx?.counters?.turns ?? -1;
72
+ if (turnStamp.turn !== turn) { turnStamp.turn = turn; turnStamp.count = 0; }
73
+ if (turnStamp.count >= MAX_PER_TURN) {
74
+ return err(`本回合便签额度用完(${MAX_PER_TURN} 条)—— 画布是版面不是弹幕区,要说的话说给用户听。`);
75
+ }
76
+
77
+ const t = String(text).trim();
78
+ if (!t) return err('空字不落板。');
79
+ const sizeKey = SIZE_PX[size] ? size : 'md';
80
+ const box = textBox(t, sizeKey);
81
+
82
+ const board = await readBoard(projectId);
83
+ const known = new Set(Object.keys(board.zones || {}));
84
+ let pos; let zone = '';
85
+ if (rawNear) {
86
+ const near = normalizeCanvasId(rawNear);
87
+ const anchorEntry = near ? board.objects?.[near] : null;
88
+ if (!anchorEntry || !Number.isFinite(anchorEntry.x)) {
89
+ return err(`锚点 ${rawNear} 还没有座位(read_board 里看不到就锚不上)。`);
90
+ }
91
+ zone = layerOf(near, anchorEntry, known);
92
+ const aSize = estimateSize(near, anchorEntry);
93
+ pos = { x: Math.round(anchorEntry.x + aSize.w + 24), y: Math.round(anchorEntry.y) };
94
+ // 撞卡往下让(同 arrange 的避让)
95
+ const obstacles = Object.entries(board.objects || {})
96
+ .filter(([id, e]) => Number.isFinite(e?.x) && layerOf(id, e, known) === zone)
97
+ .map(([id, e]) => ({ ...estimateSize(id, e), x: e.x, y: e.y }));
98
+ for (let g = 0; g < 40; g += 1) {
99
+ const blocker = obstacles.find(o =>
100
+ !(pos.x + box.w <= o.x || o.x + o.w <= pos.x || pos.y + box.h <= o.y || o.y + o.h <= pos.y));
101
+ if (!blocker) break;
102
+ pos.y = blocker.y + blocker.h + 16;
103
+ }
104
+ } else {
105
+ // 桌面根层内容最低边下面(跟新物件入座同一条起排线精神)
106
+ let bottom = 0;
107
+ for (const [id, e] of Object.entries(board.objects || {})) {
108
+ if (!Number.isFinite(e?.y) || layerOf(id, e, known) !== '') continue;
109
+ bottom = Math.max(bottom, e.y + estimateSize(id, e).h);
110
+ }
111
+ for (const zz of Object.values(board.zones || {})) {
112
+ if (Number.isFinite(zz?.y)) bottom = Math.max(bottom, zz.y + 150);
113
+ }
114
+ pos = { x: 10, y: Math.round(bottom) + 16 };
115
+ }
116
+
117
+ const textId = nextTextId();
118
+ const patch = {
119
+ objects: {
120
+ [textId]: {
121
+ x: pos.x, y: pos.y, z: 1, w: box.w, h: box.h,
122
+ kind: 'text',
123
+ data: { t, font: TEXT_FONTS.includes(font) ? font : 'pen', size: sizeKey, color: 'ink' },
124
+ zone, by: 'agent',
125
+ },
126
+ },
127
+ };
128
+ if (relation) {
129
+ const to = normalizeCanvasId(relation.to);
130
+ if (to && to !== textId) {
131
+ patch.bindings = {
132
+ [nextBindingId()]: {
133
+ type: relation.type, from: textId, to, by: 'agent',
134
+ ...(relation.label ? { label: relation.label } : {}),
135
+ },
136
+ };
137
+ }
138
+ }
139
+
140
+ const saved = await patchBoard(projectId, patch);
141
+ if (!saved.objects?.[textId]) return err('便签被 board 拒了(内容或字段不合法)。');
142
+ turnStamp.count += 1;
143
+ try {
144
+ ctx?.emit?.({ type: 'board.updated', sessionId: null, summary: '写了一条画布便签' });
145
+ } catch { /* fail-soft */ }
146
+ return {
147
+ content: [{
148
+ type: 'text',
149
+ text: `Note on board at (${pos.x},${pos.y})${relation ? ' with a line' : ''} (id: ${textId}).`
150
+ + ` ${MAX_PER_TURN - turnStamp.count} left this turn.`,
151
+ }],
152
+ };
153
+ },
154
+ );
155
+ }
@@ -0,0 +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
+ }