@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.
- package/README.md +156 -106
- package/bin/nodesign.js +0 -0
- package/package.json +1 -1
- package/server/api/README.md +45 -45
- package/server/api/_guard.js +75 -75
- package/server/api/admin.js +187 -187
- package/server/api/assets/docx-page.js +103 -103
- package/server/api/assets/helpers.js +42 -22
- package/server/api/assets/notes.js +194 -144
- package/server/api/assets.js +891 -896
- package/server/api/board.js +134 -57
- package/server/api/browse.js +138 -138
- package/server/api/canvas.js +444 -444
- package/server/api/chatai.js +324 -324
- package/server/api/exports/build-standalone.js +980 -980
- package/server/api/exports/cards.js +118 -118
- package/server/api/exports/docx-pdf.js +46 -46
- package/server/api/exports/export-page.js +142 -142
- package/server/api/exports/handoff.js +147 -147
- package/server/api/exports.js +690 -690
- package/server/api/instruction.js +75 -75
- package/server/api/me.js +116 -116
- package/server/api/memory.js +185 -185
- package/server/api/pending-changes.js +366 -366
- package/server/api/plugins.js +164 -164
- package/server/api/projects.js +220 -220
- package/server/api/publish.js +64 -64
- package/server/api/recent.js +73 -73
- package/server/api/sessions.js +589 -589
- package/server/api/skills.js +77 -77
- package/server/api/standalone-fit.js +168 -168
- package/server/api/turn-compose.js +180 -180
- package/server/api/turn-inflight.js +44 -44
- package/server/auth/README.md +17 -17
- package/server/auth/middleware.js +138 -138
- package/server/auth/origin-guard.js +71 -71
- package/server/auth/session.js +108 -108
- package/server/auth/tier.js +113 -113
- package/server/auth/users-store.js +348 -348
- package/server/edit/README.md +29 -29
- package/server/engine/README.md +113 -113
- package/server/engine/agent/agent-shared.js +550 -550
- package/server/engine/agent/auto-mode-default-hard-deny.txt +4 -4
- package/server/engine/agent/auto-mode-rules.js +78 -78
- package/server/engine/agent/context.js +418 -418
- package/server/engine/agent/events.js +465 -464
- package/server/engine/agent/hooks/canvas-validate.js +199 -199
- package/server/engine/agent/hooks/failure.js +120 -120
- package/server/engine/agent/hooks/file-events.js +75 -75
- package/server/engine/agent/hooks/lifecycle.js +233 -233
- package/server/engine/agent/hooks/post-canvas-focus.js +80 -80
- package/server/engine/agent/hooks/post-guidance.js +206 -206
- package/server/engine/agent/hooks/post-subagent-report.js +104 -104
- package/server/engine/agent/hooks/post-trim.js +58 -58
- package/server/engine/agent/hooks/pre-board-neighborhood.js +34 -34
- package/server/engine/agent/hooks/pre-defaults.js +84 -84
- package/server/engine/agent/hooks/pre-injectors.js +277 -277
- package/server/engine/agent/hooks/pre-performance-log-guard.js +78 -78
- package/server/engine/agent/hooks/pre-starter-files.js +61 -61
- package/server/engine/agent/hooks/pre-workspace-scope-guard.js +78 -78
- package/server/engine/agent/hooks/site-validate.js +94 -94
- package/server/engine/agent/hooks/tool-prompts.js +31 -31
- package/server/engine/agent/hooks/turn-state-memory.js +56 -56
- package/server/engine/agent/hooks/user-prompt-submit.js +258 -215
- package/server/engine/agent/hooks.js +354 -354
- package/server/engine/agent/init-contract.js +69 -69
- package/server/engine/agent/isolation.js +159 -159
- package/server/engine/agent/model-table.js +292 -292
- package/server/engine/agent/plugin-loader.js +266 -266
- package/server/engine/agent/prompts/nodesign-prelude.md +388 -336
- package/server/engine/agent/prompts/tools/ask-user-question-protocol.md +71 -71
- package/server/engine/agent/prompts/tools/direct-edit-protocol.md +98 -98
- package/server/engine/agent/prompts/tools/generate-image-cookbook.gemini-gateway.md +583 -583
- package/server/engine/agent/prompts/tools/generate-image-cookbook.md +483 -483
- package/server/engine/agent/prompts/tools/hybrid-reference.md +100 -100
- package/server/engine/agent/prompts/tools/paint-still-cookbook.md +270 -270
- package/server/engine/agent/prompts/tools/roll-film-cookbook.md +70 -70
- package/server/engine/agent/prompts/tools/site-reference.md +106 -106
- package/server/engine/agent/prompts/tools/tweaks-syntax.md +125 -125
- package/server/engine/agent/prompts/tools/vision-checker-dispatch.md +48 -48
- package/server/engine/agent/session-loop.js +1035 -1024
- package/server/engine/agent/session-model.js +164 -164
- package/server/engine/agent/skill.js +204 -204
- package/server/engine/agent/task-events.js +78 -78
- package/server/engine/agents/ds-extractor.md +132 -132
- package/server/engine/agents/explorer.md +190 -190
- package/server/engine/agents/index.js +230 -230
- package/server/engine/agents/schemas/design-system.json +156 -156
- package/server/engine/agents/schemas/tweak-schema.json +113 -113
- package/server/engine/agents/tweak-proposer.md +127 -127
- package/server/engine/agents/vision-checker.md +254 -254
- package/server/engine/browse/capture.js +422 -422
- package/server/engine/browse/card.js +137 -137
- package/server/engine/browse/handover.js +59 -59
- package/server/engine/browse/page-digest.js +119 -119
- package/server/engine/browse/refs.js +196 -196
- package/server/engine/browse/registry.js +307 -307
- package/server/engine/browse/screencast.js +170 -170
- package/server/engine/browse/state.js +121 -121
- package/server/engine/chatai/chat-log.js +79 -79
- package/server/engine/chatai/index.js +193 -193
- package/server/engine/chatai/openai-compat.js +152 -152
- package/server/engine/chatai/orchestrate.js +309 -309
- package/server/engine/chatai/perform.js +40 -40
- package/server/engine/chatai/summarize.js +79 -79
- package/server/engine/mcp/capability-gate.js +52 -52
- package/server/engine/mcp/index.js +351 -339
- package/server/engine/mcp/param-sanitizer.js +142 -142
- package/server/engine/mcp/tools/arrange-on-board.js +124 -124
- package/server/engine/mcp/tools/artifact-session.js +278 -278
- package/server/engine/mcp/tools/browse-computer.js +421 -421
- package/server/engine/mcp/tools/browse-find-batch.js +183 -183
- package/server/engine/mcp/tools/browse-screenshot.js +157 -157
- package/server/engine/mcp/tools/browse.js +480 -480
- package/server/engine/mcp/tools/build-docx.js +101 -101
- package/server/engine/mcp/tools/clear-pending-changes.js +99 -99
- package/server/engine/mcp/tools/create-on-board.js +152 -155
- package/server/engine/mcp/tools/crystallize-skill.js +168 -168
- package/server/engine/mcp/tools/edit-sketch.js +167 -0
- package/server/engine/mcp/tools/explain-style.js +237 -237
- package/server/engine/mcp/tools/export-handoff.js +133 -133
- package/server/engine/mcp/tools/expose-tweaks.js +149 -149
- package/server/engine/mcp/tools/generate-image.js +842 -842
- package/server/engine/mcp/tools/get-computed-styles.js +164 -164
- package/server/engine/mcp/tools/get-pending-changes.js +205 -205
- package/server/engine/mcp/tools/h3box-ssh.js +84 -84
- package/server/engine/mcp/tools/helpers/acquire-page.js +82 -82
- package/server/engine/mcp/tools/helpers/motion-lab.js +554 -554
- package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -112
- package/server/engine/mcp/tools/helpers/perception-page.js +215 -215
- package/server/engine/mcp/tools/helpers/reference-download.js +103 -103
- package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -80
- package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -280
- package/server/engine/mcp/tools/highlight.js +68 -68
- package/server/engine/mcp/tools/list-pages.js +222 -222
- package/server/engine/mcp/tools/look-at-board.js +124 -0
- package/server/engine/mcp/tools/lookup-tags.js +59 -59
- package/server/engine/mcp/tools/navigate-to-page.js +60 -60
- package/server/engine/mcp/tools/organize-board.js +64 -64
- package/server/engine/mcp/tools/paint-still.js +434 -434
- package/server/engine/mcp/tools/pin-to-board.js +130 -130
- package/server/engine/mcp/tools/preview-deck.js +130 -130
- package/server/engine/mcp/tools/profile-scroll.js +305 -305
- package/server/engine/mcp/tools/publish-site.js +102 -102
- package/server/engine/mcp/tools/query-elements.js +195 -195
- package/server/engine/mcp/tools/read-board.js +190 -103
- package/server/engine/mcp/tools/read-document.js +93 -93
- package/server/engine/mcp/tools/read-page.js +264 -264
- package/server/engine/mcp/tools/read-tavern-json.js +143 -143
- package/server/engine/mcp/tools/read-user-view.js +59 -0
- package/server/engine/mcp/tools/record-decision.js +140 -140
- package/server/engine/mcp/tools/relate-on-board.js +112 -110
- package/server/engine/mcp/tools/report-issue.js +115 -115
- package/server/engine/mcp/tools/roll-film.js +266 -266
- package/server/engine/mcp/tools/screenshot-docx.js +138 -138
- package/server/engine/mcp/tools/screenshot-url.js +195 -195
- package/server/engine/mcp/tools/screenshot.js +583 -583
- package/server/engine/mcp/tools/sketch-on-board.js +337 -0
- package/server/engine/mcp/tools/tier-gate.js +96 -96
- package/server/engine/mcp/tools/trace-motion.js +215 -215
- package/server/engine/mcp/tools/web-search.js +548 -548
- package/server/engine/mcp/tools/write-on-board.js +130 -0
- package/server/engine/motion/inventory.js +349 -349
- package/server/engine/perception/session.js +235 -235
- package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -5
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +199 -192
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -667
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -22
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -25
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -23
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -21
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -23
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -21
- package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +169 -162
- package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -407
- package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -80
- package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +235 -228
- 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
- package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -268
- package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +330 -323
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -134
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -61
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -163
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -86
- package/server/engine/runs/active-runs.js +698 -698
- package/server/engine/runs/board-tasklist.js +130 -0
- package/server/engine/runs/live-turn.js +252 -252
- package/server/engine/runs/store.js +364 -364
- package/server/engine/runs/turn-relay.js +217 -217
- package/server/engine/runtime/workspace.js +164 -164
- package/server/index.js +3 -0
- package/server/lib/artifact-file-path.js +80 -80
- package/server/lib/artifact-target.js +284 -284
- package/server/lib/asset-refs.js +239 -239
- package/server/lib/async-queue.js +104 -104
- package/server/lib/auto-relations.js +130 -130
- package/server/lib/binding-types.js +72 -60
- package/server/lib/board-graph-export.js +191 -0
- package/server/lib/board-groups.js +167 -0
- package/server/lib/board-hero.js +76 -0
- package/server/lib/board-kind-sizes.js +85 -62
- package/server/lib/board-relations.js +133 -133
- package/server/lib/browse-proxy.js +180 -180
- package/server/lib/canvas-id.js +36 -36
- package/server/lib/chalk.js +121 -0
- package/server/lib/cover.js +227 -227
- package/server/lib/danbooru-tags.js +291 -291
- package/server/lib/doc-extract.js +156 -156
- package/server/lib/docx/build-from-source.js +260 -260
- package/server/lib/docx/build.js +490 -490
- package/server/lib/docx/dump-styles.js +287 -287
- package/server/lib/docx/fonts/nodesign-cjk.conf +164 -164
- package/server/lib/docx/merge-runs.js +129 -129
- package/server/lib/docx/numbering.js +218 -218
- package/server/lib/docx/order.js +152 -152
- package/server/lib/docx/rawzip.js +172 -172
- package/server/lib/docx/render.js +92 -92
- package/server/lib/docx/text-lint.js +225 -225
- package/server/lib/docx/tokens.js +335 -335
- package/server/lib/docx/units.js +29 -29
- package/server/lib/docx/xml.js +291 -291
- package/server/lib/docx-pages.js +187 -187
- package/server/lib/export-collect.js +289 -289
- package/server/lib/export-package.js +210 -210
- package/server/lib/html-srcset.js +145 -145
- package/server/lib/image-variant.js +460 -460
- package/server/lib/ingress/forward-openai-chat.js +305 -305
- package/server/lib/ingress/openai-chat.js +491 -491
- package/server/lib/ingress/session-notice.js +66 -66
- package/server/lib/ingress/session-routes.js +68 -68
- package/server/lib/ingress/slot-probe.js +130 -130
- package/server/lib/ingress/upstream-billing.js +52 -52
- package/server/lib/ingress/upstream-fail-streak.js +72 -72
- package/server/lib/ingress/upstream-truncation.js +48 -48
- package/server/lib/issues-store.js +182 -182
- package/server/lib/kinds/deck.js +72 -72
- package/server/lib/kinds/docx.js +283 -283
- package/server/lib/kinds/file-kinds.js +113 -113
- package/server/lib/kinds/index.js +202 -202
- package/server/lib/kinds/site.js +161 -161
- package/server/lib/model-ingress.js +543 -543
- package/server/lib/moderation.js +255 -255
- package/server/lib/notice-store.js +103 -103
- package/server/lib/plugin-install.js +104 -104
- package/server/lib/plugin-validator.js +721 -721
- package/server/lib/publish-store.js +115 -115
- package/server/lib/quick-summary.js +52 -52
- package/server/lib/quota.js +270 -270
- package/server/lib/rate-window.js +29 -29
- package/server/lib/reference-assets.js +92 -92
- package/server/lib/region-shot.js +135 -135
- package/server/lib/safe-path.js +73 -73
- package/server/lib/sdk-session.js +33 -33
- package/server/lib/showcase-store.js +92 -92
- package/server/lib/site-publish.js +465 -465
- package/server/lib/sketch-layout.js +277 -0
- package/server/lib/ssrf-guard.js +432 -432
- package/server/lib/task-scan.js +158 -158
- package/server/lib/tavern-json.js +154 -154
- package/server/lib/video-variant.js +237 -237
- package/server/lib/workspace-path.js +33 -33
- package/server/ops/fix-sdk-musl.mjs +40 -40
- package/server/ops/install-macos-fonts.sh +114 -114
- package/server/ops/macos-fonts.conf +336 -336
- package/server/ops/sandbox-shim/bwrap +57 -57
- package/server/projects/assets-summary.js +119 -119
- package/server/projects/auto-name.js +53 -53
- package/server/projects/board-limits.js +12 -0
- package/server/projects/board-sanitize.js +252 -0
- package/server/projects/board-store.js +507 -640
- package/server/projects/move-entry.js +103 -103
- package/server/projects/store.js +270 -270
- package/server/projects/ui-config.js +60 -54
- package/server/projects/viewpoint-store.js +78 -0
- package/server/projects/workspace-templates.js +53 -53
- package/server/projects/workspace.js +1025 -1025
- package/server/runtime/local-config.js +177 -177
- package/server/runtime/profile.js +72 -72
- package/server/services/rembg-service.py +334 -334
- package/server/shared/README.md +25 -25
- package/server/shared/deck.js +54 -54
- package/server/shared/time.js +49 -49
- package/server/style-pipeline/README.md +53 -53
- package/server/ws/broker.js +39 -36
- package/server/ws/browse-channel.js +177 -177
- package/server/ws/index.js +386 -386
- package/web/README.md +89 -89
- package/web/dist/assets/BrowserWindow-P_vIdh-G.js +11 -0
- package/web/dist/assets/{DeckWindow-4G0xX7P3.js → DeckWindow-BpLv5082.js} +3 -3
- package/web/dist/assets/{DocxWindow-BXQsoPkh.js → DocxWindow-DSAU1-tD.js} +4 -4
- package/web/dist/assets/MermaidBlock-DR1GikCv.js +313 -0
- package/web/dist/assets/SiteWindow-92uBuRRR.js +18 -0
- package/web/dist/assets/abnfDiagram-VCTEODGH-uA8Esix4.js +1 -0
- package/web/dist/assets/arc-D_khH_xN.js +1 -0
- package/web/dist/assets/architectureDiagram-5GKGNRK7-DydJHqOt.js +36 -0
- package/web/dist/assets/blockDiagram-NRAW4CY4-B7wBbKiW.js +129 -0
- package/web/dist/assets/c4Diagram-UCG6FXSJ-6mrH0x7Y.js +38 -0
- package/web/dist/assets/channel-DGkccMO1.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-Cuikho5Q.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-3-KZ5AUz.js +15 -0
- package/web/dist/assets/chunk-F27PBJKO-Bkwq2gGU.js +1 -0
- package/web/dist/assets/chunk-G27WJ6UU-BLyQzdGE.js +231 -0
- package/web/dist/assets/chunk-JWPE2WC7-B7HxxQds.js +1 -0
- package/web/dist/assets/chunk-LCL6LL3I-CtXrnUwF.js +206 -0
- package/web/dist/assets/chunk-POPQ4Y6H-dxddZlXt.js +1 -0
- package/web/dist/assets/chunk-SVP7TREG-DpkmrgHn.js +88 -0
- package/web/dist/assets/chunk-XXDRQBXY-BwZ7RbpQ.js +1 -0
- package/web/dist/assets/classDiagram-DTDB5LWJ-BGscw3OD.js +1 -0
- package/web/dist/assets/classDiagram-v2-JRS7N3AN-BGscw3OD.js +1 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-DGFOsMUt.js +1 -0
- package/web/dist/assets/cynefin-OW5HDTMX-DUwn3ehS.js +178 -0
- package/web/dist/assets/cynefinDiagram-5FMLGOSQ-DlLAOZ9x.js +62 -0
- package/web/dist/assets/cytoscape.esm-BjAbmLdb.js +331 -0
- package/web/dist/assets/dagre-3AP2YEHR-CyourLfz.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-S7CK7UJ4-BTMbx2np.js +30 -0
- package/web/dist/assets/diagram-UQ7AKVKN-UK94_1-P.js +41 -0
- package/web/dist/assets/diagram-VSXAHHWV-C7zS-v9v.js +3 -0
- package/web/dist/assets/diagram-VX7I27RA-DKJRa6CK.js +24 -0
- package/web/dist/assets/diagram-Z3DM3KII-kUbAfGAp.js +24 -0
- package/web/dist/assets/ebnfDiagram-PWID7BFC-CVW16_vb.js +1 -0
- package/web/dist/assets/erDiagram-SSCWMZ5O-BRQMFQ5y.js +99 -0
- package/web/dist/assets/flowDiagram-A5DVABFB-S34LpLtK.js +168 -0
- package/web/dist/assets/ganttDiagram-EL5Y4UJY-BFiqk1-G.js +292 -0
- package/web/dist/assets/gitGraphDiagram-WWUBYQGX-LZsrdyyv.js +106 -0
- package/web/dist/assets/index-GAamh1p4.js +2152 -0
- package/web/dist/assets/infoDiagram-RXCK75RN-0DvN6KIp.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/ishikawaDiagram-5VMMS53U-CaY3A-Bx.js +70 -0
- package/web/dist/assets/journeyDiagram-EYS64GPL-BBeiaCrj.js +139 -0
- package/web/dist/assets/kanban-definition-3QL26DDD-ux42DRXQ.js +89 -0
- package/web/dist/assets/layout-CnXiF_NB.js +1 -0
- package/web/dist/assets/linear-BMW0u6G6.js +1 -0
- package/web/dist/assets/mindmap-definition-FBJOCRG2-hUxSpdKn.js +96 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/pegDiagram-XKGWAZYB-aCaQPH0w.js +1 -0
- package/web/dist/assets/{pending-edit-apply-DTjo2geW.js → pending-edit-apply-AcdOQ9Ij.js} +6 -6
- package/web/dist/assets/pieDiagram-E7YTZNPT-CmOEZ8zg.js +39 -0
- package/web/dist/assets/quadrantDiagram-AXDQQJYC-VW6fAhsV.js +7 -0
- package/web/dist/assets/railroadDiagram-O6MQD6OU-CKJ7Ba5K.js +1 -0
- package/web/dist/assets/requirementDiagram-EFPCY7ZU-pNGkq9Vw.js +84 -0
- package/web/dist/assets/{rotate-cw-LMT3x1Zj.js → rotate-cw-KAfChbGV.js} +1 -1
- package/web/dist/assets/sankeyDiagram-P5KCCOFB-BIMmDTfZ.js +40 -0
- package/web/dist/assets/sequenceDiagram-WJ2MYXX4-BBW7wzKY.js +162 -0
- package/web/dist/assets/sizeCapture-X5ZJPWSS-DdkXmLYR.js +1 -0
- package/web/dist/assets/{square-dashed-mouse-pointer-CBoAkfhi.js → square-dashed-mouse-pointer-CDUlhUP7.js} +1 -1
- package/web/dist/assets/stateDiagram-HBIQ2CUA-W313Uz16.js +1 -0
- package/web/dist/assets/stateDiagram-v2-4QOOHH4V-DDhJBZzf.js +1 -0
- package/web/dist/assets/swimlanes-XN3QIQJK-C29TL26K.js +1 -0
- package/web/dist/assets/swimlanesDiagram-VK2B7HYN-BfN-Xdmu.js +8 -0
- package/web/dist/assets/timeline-definition-24CTP7MA-CF0JMObX.js +120 -0
- package/web/dist/assets/vennDiagram-4TSXK5OY-DrDFsaH3.js +34 -0
- package/web/dist/assets/wardleyDiagram-VM6X3IG4-CVrnRIS_.js +78 -0
- package/web/dist/assets/xychartDiagram-S5SC5T6Z-BvkN1zsT.js +7 -0
- package/web/dist/index.html +17 -17
- package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +0 -11
- package/web/dist/assets/SiteWindow-D6eS-2gM.js +0 -18
- package/web/dist/assets/index-Cbl3ATvp.js +0 -2125
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/read-tavern-json.js — read_tavern_json MCP tool(2026-08-15)
|
|
3
|
-
*
|
|
4
|
-
* 搬酒馆的东西进来时的读取口。**不要用 Read 去读这类文件**:真样本
|
|
5
|
-
* (Izumi 0814.json)464KB、210 条提示词,启用的只有 56 条 —— Read 一次就是
|
|
6
|
-
* 十几万 token 进上下文,换来的绝大部分是停用的备选条目。
|
|
7
|
-
*
|
|
8
|
-
* 两步走:先 `摘要` 看结构(每条只给名字/角色/字数/一句引子),挑好了再
|
|
9
|
-
* `取` 正文。转成 编排.yaml 和设定文件是 agent 自己的活,这个工具只读不写。
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import path from 'node:path';
|
|
13
|
-
import fs from 'node:fs/promises';
|
|
14
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
15
|
-
import { z } from 'zod';
|
|
16
|
-
import { detectKind, digest, fetchEntries } from '../../../lib/tavern-json.js';
|
|
17
|
-
|
|
18
|
-
const MAX_FETCH_CHARS = 24_000;
|
|
19
|
-
|
|
20
|
-
function 渲染摘要(d, 文件名) {
|
|
21
|
-
const L = [];
|
|
22
|
-
if (d.形态 === 'preset') {
|
|
23
|
-
L.push(`酒馆 Chat Completion 预设:${文件名}`);
|
|
24
|
-
L.push(`启用 ${d.启用.length} 条(其中有正文的 ${d.启用.filter(e => e.字数 > 0).length} 条,合计 ${d.合计字数} 字)· 停用 ${d.停用.length} 条`);
|
|
25
|
-
const p = d.参数;
|
|
26
|
-
L.push(`参数:temperature ${p.temperature} · top_p ${p.top_p} · 最大输出 ${p.最大输出} · reasoning_effort ${p.reasoning_effort ?? '未设'}`);
|
|
27
|
-
L.push('');
|
|
28
|
-
L.push('启用条目(顺序 = 进模型顺序):');
|
|
29
|
-
for (const [i, e] of d.启用.entries()) {
|
|
30
|
-
const 标 = e.占位 ? '〔占位·酒馆运行时填,搬过来丢掉〕'
|
|
31
|
-
: e.分隔 ? '〔分节标题·无正文〕' : `${e.字数}字`;
|
|
32
|
-
L.push(`${String(i + 1).padStart(2)}. ${e.名字} [${e.角色}] ${标}${e.深度 != null ? ` 深度${e.深度}` : ''}`);
|
|
33
|
-
if (e.引子) L.push(` ${e.引子}…`);
|
|
34
|
-
}
|
|
35
|
-
if (d.停用.length) {
|
|
36
|
-
L.push('');
|
|
37
|
-
L.push(`停用的 ${d.停用.length} 条(同一功能的备选,酒馆里只开一个;名字列表):`);
|
|
38
|
-
L.push(d.停用.map(e => e.名字).join(' / '));
|
|
39
|
-
}
|
|
40
|
-
L.push('');
|
|
41
|
-
L.push('占位条目(marker,酒馆运行时填角色卡/历史,搬过来一律丢):' + (d.占位条目.join(' / ') || '无'));
|
|
42
|
-
L.push('分节标题(0 字,只是把开关分组,也不用搬):' + (d.分隔条目.join(' / ') || '无'));
|
|
43
|
-
} else if (d.形态 === 'card') {
|
|
44
|
-
L.push(`酒馆角色卡:${d.名字}(${文件名})`);
|
|
45
|
-
for (const f of d.字段) L.push(`- ${f.字段} ${f.字数}字 ${f.引子}…`);
|
|
46
|
-
if (d.开场白备选) L.push(`- alternate_greetings ${d.开场白备选} 条备选开场白`);
|
|
47
|
-
if (d.世界书.length) {
|
|
48
|
-
L.push('');
|
|
49
|
-
L.push(`内嵌世界书 ${d.世界书.length} 条:`);
|
|
50
|
-
for (const e of d.世界书) {
|
|
51
|
-
L.push(`- ${e.名字} ${e.常驻 ? '常驻' : `触发[${e.触发.join(' ')}]`} ${e.字数}字${e.停用 ? ' (停用)' : ''}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
L.push(`酒馆世界书:${文件名},${d.条目.length} 条`);
|
|
56
|
-
for (const e of d.条目) {
|
|
57
|
-
L.push(`- ${e.名字} ${e.常驻 ? '常驻' : `触发[${e.触发.join(' ')}]`} ${e.字数}字${e.停用 ? ' (停用)' : ''}`);
|
|
58
|
-
if (e.引子) L.push(` ${e.引子}…`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
L.push('');
|
|
62
|
-
L.push('要正文就再调一次本工具:mode="fetch",entries=["名字或名字的一部分", …]。');
|
|
63
|
-
return L.join('\n');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function makeReadTavernJsonTool({ workspaceRoot, sharedRoot }) {
|
|
67
|
-
return tool(
|
|
68
|
-
'read_tavern_json',
|
|
69
|
-
`Read a SillyTavern (酒馆) export JSON — a chat-completion **preset**, a
|
|
70
|
-
**character card** (V2/V3), or a **lorebook** — without pouring the whole file
|
|
71
|
-
into your context.
|
|
72
|
-
|
|
73
|
-
Use this instead of Read for any 酒馆 JSON. A real preset in the wild is 460KB
|
|
74
|
-
with 210 prompt entries of which only 56 are enabled; Read would burn six digits
|
|
75
|
-
of tokens on disabled alternates.
|
|
76
|
-
|
|
77
|
-
Two steps:
|
|
78
|
-
1. mode "digest" (default) — structure only: every entry's name, role, size and a
|
|
79
|
-
60-char peek, plus which are enabled/disabled, plus sampler params.
|
|
80
|
-
2. mode "fetch" with entries[] — full text of just the ones you picked (name,
|
|
81
|
-
partial name, or id). Capped at ${MAX_FETCH_CHARS} chars per call.
|
|
82
|
-
|
|
83
|
-
This tool only reads. Turning a preset into 编排.yaml + 设定 files is your job —
|
|
84
|
-
you decide the grouping, and you drop what does not belong (markers are filled by
|
|
85
|
-
酒馆 at runtime and have no place here; platform-specific jailbreak sections are
|
|
86
|
-
pointless on this platform).`,
|
|
87
|
-
{
|
|
88
|
-
path: z.string().describe(
|
|
89
|
-
'Path to the .json. Relative paths resolve against the session workspace, '
|
|
90
|
-
+ 'then the shared project dir (e.g. "assets/Izumi 0814.json").',
|
|
91
|
-
),
|
|
92
|
-
// ⚠️ 参数名和枚举值一律 ASCII —— 工具 schema 是模型要照着填的东西,
|
|
93
|
-
// 中文键名在这条路上不可靠(全仓其他工具也都是 ASCII,别开这个头)
|
|
94
|
-
mode: z.enum(['digest', 'fetch']).optional()
|
|
95
|
-
.describe('digest = structure only (default); fetch = full text of the picked entries'),
|
|
96
|
-
entries: z.array(z.string()).optional()
|
|
97
|
-
.describe('For mode="fetch": entry names (partial match ok) or ids'),
|
|
98
|
-
},
|
|
99
|
-
async ({ path: rel, mode = 'digest', entries = [] }) => {
|
|
100
|
-
const fail = (text) => ({ content: [{ type: 'text', text }], isError: true });
|
|
101
|
-
try {
|
|
102
|
-
const raw = String(rel || '').trim();
|
|
103
|
-
if (!raw) return fail('read_tavern_json needs a path.');
|
|
104
|
-
const candidates = path.isAbsolute(raw)
|
|
105
|
-
? [raw]
|
|
106
|
-
: [workspaceRoot && path.resolve(workspaceRoot, raw),
|
|
107
|
-
sharedRoot && path.resolve(sharedRoot, raw)].filter(Boolean);
|
|
108
|
-
let abs = null;
|
|
109
|
-
for (const c of candidates) {
|
|
110
|
-
try { await fs.access(c); abs = c; break; } catch { /* 下一个 */ }
|
|
111
|
-
}
|
|
112
|
-
if (!abs) return fail(`File not found: ${raw}\nLooked in:\n${candidates.map(c => ` ${c}`).join('\n')}`);
|
|
113
|
-
|
|
114
|
-
let doc;
|
|
115
|
-
try { doc = JSON.parse(await fs.readFile(abs, 'utf8')); } catch (e) {
|
|
116
|
-
return fail(`这个文件不是合法 JSON:${e.message}`);
|
|
117
|
-
}
|
|
118
|
-
const kind = detectKind(doc);
|
|
119
|
-
if (!kind) {
|
|
120
|
-
return fail('认不出这是酒馆的哪种导出(预设要有 prompts + prompt_order;角色卡要有 first_mes;世界书要有 entries)。普通 JSON 用 Read 就行。');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (mode === 'fetch') {
|
|
124
|
-
const 出 = fetchEntries(doc, entries);
|
|
125
|
-
if (!出.length) return fail(`没找到这些条目:${entries.join(' / ')}。先用 mode="digest" 看名字。`);
|
|
126
|
-
let 总 = 0;
|
|
127
|
-
const 块 = [];
|
|
128
|
-
for (const e of 出) {
|
|
129
|
-
if (总 >= MAX_FETCH_CHARS) { 块.push(`〔余下 ${出.length - 块.length} 条超出单次上限,分批取〕`); break; }
|
|
130
|
-
const 文 = e.正文.slice(0, MAX_FETCH_CHARS - 总);
|
|
131
|
-
总 += 文.length;
|
|
132
|
-
块.push(`### ${e.名字}${e.角色 ? ` [${e.角色}]` : ''}\n${文}`);
|
|
133
|
-
}
|
|
134
|
-
return { content: [{ type: 'text', text: 块.join('\n\n') }] };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return { content: [{ type: 'text', text: 渲染摘要(digest(doc), path.basename(abs)) }] };
|
|
138
|
-
} catch (err) {
|
|
139
|
-
return fail(`read_tavern_json failed: ${err?.message || String(err)}`);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/read-tavern-json.js — read_tavern_json MCP tool(2026-08-15)
|
|
3
|
+
*
|
|
4
|
+
* 搬酒馆的东西进来时的读取口。**不要用 Read 去读这类文件**:真样本
|
|
5
|
+
* (Izumi 0814.json)464KB、210 条提示词,启用的只有 56 条 —— Read 一次就是
|
|
6
|
+
* 十几万 token 进上下文,换来的绝大部分是停用的备选条目。
|
|
7
|
+
*
|
|
8
|
+
* 两步走:先 `摘要` 看结构(每条只给名字/角色/字数/一句引子),挑好了再
|
|
9
|
+
* `取` 正文。转成 编排.yaml 和设定文件是 agent 自己的活,这个工具只读不写。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { detectKind, digest, fetchEntries } from '../../../lib/tavern-json.js';
|
|
17
|
+
|
|
18
|
+
const MAX_FETCH_CHARS = 24_000;
|
|
19
|
+
|
|
20
|
+
function 渲染摘要(d, 文件名) {
|
|
21
|
+
const L = [];
|
|
22
|
+
if (d.形态 === 'preset') {
|
|
23
|
+
L.push(`酒馆 Chat Completion 预设:${文件名}`);
|
|
24
|
+
L.push(`启用 ${d.启用.length} 条(其中有正文的 ${d.启用.filter(e => e.字数 > 0).length} 条,合计 ${d.合计字数} 字)· 停用 ${d.停用.length} 条`);
|
|
25
|
+
const p = d.参数;
|
|
26
|
+
L.push(`参数:temperature ${p.temperature} · top_p ${p.top_p} · 最大输出 ${p.最大输出} · reasoning_effort ${p.reasoning_effort ?? '未设'}`);
|
|
27
|
+
L.push('');
|
|
28
|
+
L.push('启用条目(顺序 = 进模型顺序):');
|
|
29
|
+
for (const [i, e] of d.启用.entries()) {
|
|
30
|
+
const 标 = e.占位 ? '〔占位·酒馆运行时填,搬过来丢掉〕'
|
|
31
|
+
: e.分隔 ? '〔分节标题·无正文〕' : `${e.字数}字`;
|
|
32
|
+
L.push(`${String(i + 1).padStart(2)}. ${e.名字} [${e.角色}] ${标}${e.深度 != null ? ` 深度${e.深度}` : ''}`);
|
|
33
|
+
if (e.引子) L.push(` ${e.引子}…`);
|
|
34
|
+
}
|
|
35
|
+
if (d.停用.length) {
|
|
36
|
+
L.push('');
|
|
37
|
+
L.push(`停用的 ${d.停用.length} 条(同一功能的备选,酒馆里只开一个;名字列表):`);
|
|
38
|
+
L.push(d.停用.map(e => e.名字).join(' / '));
|
|
39
|
+
}
|
|
40
|
+
L.push('');
|
|
41
|
+
L.push('占位条目(marker,酒馆运行时填角色卡/历史,搬过来一律丢):' + (d.占位条目.join(' / ') || '无'));
|
|
42
|
+
L.push('分节标题(0 字,只是把开关分组,也不用搬):' + (d.分隔条目.join(' / ') || '无'));
|
|
43
|
+
} else if (d.形态 === 'card') {
|
|
44
|
+
L.push(`酒馆角色卡:${d.名字}(${文件名})`);
|
|
45
|
+
for (const f of d.字段) L.push(`- ${f.字段} ${f.字数}字 ${f.引子}…`);
|
|
46
|
+
if (d.开场白备选) L.push(`- alternate_greetings ${d.开场白备选} 条备选开场白`);
|
|
47
|
+
if (d.世界书.length) {
|
|
48
|
+
L.push('');
|
|
49
|
+
L.push(`内嵌世界书 ${d.世界书.length} 条:`);
|
|
50
|
+
for (const e of d.世界书) {
|
|
51
|
+
L.push(`- ${e.名字} ${e.常驻 ? '常驻' : `触发[${e.触发.join(' ')}]`} ${e.字数}字${e.停用 ? ' (停用)' : ''}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
L.push(`酒馆世界书:${文件名},${d.条目.length} 条`);
|
|
56
|
+
for (const e of d.条目) {
|
|
57
|
+
L.push(`- ${e.名字} ${e.常驻 ? '常驻' : `触发[${e.触发.join(' ')}]`} ${e.字数}字${e.停用 ? ' (停用)' : ''}`);
|
|
58
|
+
if (e.引子) L.push(` ${e.引子}…`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
L.push('');
|
|
62
|
+
L.push('要正文就再调一次本工具:mode="fetch",entries=["名字或名字的一部分", …]。');
|
|
63
|
+
return L.join('\n');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function makeReadTavernJsonTool({ workspaceRoot, sharedRoot }) {
|
|
67
|
+
return tool(
|
|
68
|
+
'read_tavern_json',
|
|
69
|
+
`Read a SillyTavern (酒馆) export JSON — a chat-completion **preset**, a
|
|
70
|
+
**character card** (V2/V3), or a **lorebook** — without pouring the whole file
|
|
71
|
+
into your context.
|
|
72
|
+
|
|
73
|
+
Use this instead of Read for any 酒馆 JSON. A real preset in the wild is 460KB
|
|
74
|
+
with 210 prompt entries of which only 56 are enabled; Read would burn six digits
|
|
75
|
+
of tokens on disabled alternates.
|
|
76
|
+
|
|
77
|
+
Two steps:
|
|
78
|
+
1. mode "digest" (default) — structure only: every entry's name, role, size and a
|
|
79
|
+
60-char peek, plus which are enabled/disabled, plus sampler params.
|
|
80
|
+
2. mode "fetch" with entries[] — full text of just the ones you picked (name,
|
|
81
|
+
partial name, or id). Capped at ${MAX_FETCH_CHARS} chars per call.
|
|
82
|
+
|
|
83
|
+
This tool only reads. Turning a preset into 编排.yaml + 设定 files is your job —
|
|
84
|
+
you decide the grouping, and you drop what does not belong (markers are filled by
|
|
85
|
+
酒馆 at runtime and have no place here; platform-specific jailbreak sections are
|
|
86
|
+
pointless on this platform).`,
|
|
87
|
+
{
|
|
88
|
+
path: z.string().describe(
|
|
89
|
+
'Path to the .json. Relative paths resolve against the session workspace, '
|
|
90
|
+
+ 'then the shared project dir (e.g. "assets/Izumi 0814.json").',
|
|
91
|
+
),
|
|
92
|
+
// ⚠️ 参数名和枚举值一律 ASCII —— 工具 schema 是模型要照着填的东西,
|
|
93
|
+
// 中文键名在这条路上不可靠(全仓其他工具也都是 ASCII,别开这个头)
|
|
94
|
+
mode: z.enum(['digest', 'fetch']).optional()
|
|
95
|
+
.describe('digest = structure only (default); fetch = full text of the picked entries'),
|
|
96
|
+
entries: z.array(z.string()).optional()
|
|
97
|
+
.describe('For mode="fetch": entry names (partial match ok) or ids'),
|
|
98
|
+
},
|
|
99
|
+
async ({ path: rel, mode = 'digest', entries = [] }) => {
|
|
100
|
+
const fail = (text) => ({ content: [{ type: 'text', text }], isError: true });
|
|
101
|
+
try {
|
|
102
|
+
const raw = String(rel || '').trim();
|
|
103
|
+
if (!raw) return fail('read_tavern_json needs a path.');
|
|
104
|
+
const candidates = path.isAbsolute(raw)
|
|
105
|
+
? [raw]
|
|
106
|
+
: [workspaceRoot && path.resolve(workspaceRoot, raw),
|
|
107
|
+
sharedRoot && path.resolve(sharedRoot, raw)].filter(Boolean);
|
|
108
|
+
let abs = null;
|
|
109
|
+
for (const c of candidates) {
|
|
110
|
+
try { await fs.access(c); abs = c; break; } catch { /* 下一个 */ }
|
|
111
|
+
}
|
|
112
|
+
if (!abs) return fail(`File not found: ${raw}\nLooked in:\n${candidates.map(c => ` ${c}`).join('\n')}`);
|
|
113
|
+
|
|
114
|
+
let doc;
|
|
115
|
+
try { doc = JSON.parse(await fs.readFile(abs, 'utf8')); } catch (e) {
|
|
116
|
+
return fail(`这个文件不是合法 JSON:${e.message}`);
|
|
117
|
+
}
|
|
118
|
+
const kind = detectKind(doc);
|
|
119
|
+
if (!kind) {
|
|
120
|
+
return fail('认不出这是酒馆的哪种导出(预设要有 prompts + prompt_order;角色卡要有 first_mes;世界书要有 entries)。普通 JSON 用 Read 就行。');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (mode === 'fetch') {
|
|
124
|
+
const 出 = fetchEntries(doc, entries);
|
|
125
|
+
if (!出.length) return fail(`没找到这些条目:${entries.join(' / ')}。先用 mode="digest" 看名字。`);
|
|
126
|
+
let 总 = 0;
|
|
127
|
+
const 块 = [];
|
|
128
|
+
for (const e of 出) {
|
|
129
|
+
if (总 >= MAX_FETCH_CHARS) { 块.push(`〔余下 ${出.length - 块.length} 条超出单次上限,分批取〕`); break; }
|
|
130
|
+
const 文 = e.正文.slice(0, MAX_FETCH_CHARS - 总);
|
|
131
|
+
总 += 文.length;
|
|
132
|
+
块.push(`### ${e.名字}${e.角色 ? ` [${e.角色}]` : ''}\n${文}`);
|
|
133
|
+
}
|
|
134
|
+
return { content: [{ type: 'text', text: 块.join('\n\n') }] };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { content: [{ type: 'text', text: 渲染摘要(digest(doc), path.basename(abs)) }] };
|
|
138
|
+
} catch (err) {
|
|
139
|
+
return fail(`read_tavern_json failed: ${err?.message || String(err)}`);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/read-user-view.js —— read_user_view(2026-08-23 黑板)
|
|
3
|
+
*
|
|
4
|
+
* 「用户此刻在看哪」:视口世界矩形 + 缩放 + 当前层 + 开着的窗 + 选中集 +
|
|
5
|
+
* 视口里有哪些东西。前端节流上报、服务端只留最近一份(viewpoint-store)。
|
|
6
|
+
* UserPromptSubmit 注入一行摘要(只报变化);细节走这个工具。
|
|
7
|
+
* 指代消解的顺序:选中的 > 开着的窗 > 视口中心附近的东西。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { readBoard } from '../../../projects/board-store.js';
|
|
13
|
+
import { estimateSizeOn } from '../../../lib/board-kind-sizes.js';
|
|
14
|
+
import { layerOf } from '../../../lib/canvas-id.js';
|
|
15
|
+
import { getViewpoint, describeViewpoint } from '../../../projects/viewpoint-store.js';
|
|
16
|
+
import { describeEndpoint } from '../../../lib/board-relations.js';
|
|
17
|
+
|
|
18
|
+
export function makeReadUserViewTool({ projectId }) {
|
|
19
|
+
return tool(
|
|
20
|
+
'read_user_view',
|
|
21
|
+
`What the user is looking at RIGHT NOW: viewport (world rect + zoom), which folder
|
|
22
|
+
layer, which artifact window is open, what is selected, and which items are inside the
|
|
23
|
+
viewport (sorted by distance to its centre). Use it to resolve "this / here / that one"
|
|
24
|
+
and to decide where a sketch or note should land so the user actually sees it. Resolve
|
|
25
|
+
pointers in this order: selected > open window > items near the viewport centre.`,
|
|
26
|
+
{ _: z.string().max(1).optional().describe('(no arguments)') },
|
|
27
|
+
async () => {
|
|
28
|
+
if (!projectId) return { content: [{ type: 'text', text: 'No project bound.' }], isError: true };
|
|
29
|
+
const vp = getViewpoint(projectId);
|
|
30
|
+
if (!vp) return { content: [{ type: 'text', text: '还没有用户视点上报(用户没开着画布页,或上报过期 >10 分钟)。' }] };
|
|
31
|
+
const board = await readBoard(projectId);
|
|
32
|
+
const known = new Set(Object.keys(board.zones || {}));
|
|
33
|
+
const layer = vp.layer || '';
|
|
34
|
+
const rects = Object.entries(board.objects || {})
|
|
35
|
+
.filter(([id, e]) => Number.isFinite(e?.x) && layerOf(id, e, known) === layer)
|
|
36
|
+
.map(([id, e]) => ({ id, x: e.x, y: e.y, ...estimateSizeOn(board, id, e) }));
|
|
37
|
+
const lines = [`用户此刻(${Math.round((Date.now() - vp.at) / 1000)}s 前上报):${describeViewpoint(vp, rects) || '未知'}`];
|
|
38
|
+
if (vp.camera) {
|
|
39
|
+
const c = vp.camera; const cx = c.x + c.w / 2; const cy = c.y + c.h / 2;
|
|
40
|
+
const inside = rects
|
|
41
|
+
.filter(r => !(r.x + r.w < c.x || r.x > c.x + c.w || r.y + r.h < c.y || r.y > c.y + c.h))
|
|
42
|
+
.map(r => ({ ...r, d: Math.hypot(r.x + r.w / 2 - cx, r.y + r.h / 2 - cy) }))
|
|
43
|
+
.sort((a, b) => a.d - b.d);
|
|
44
|
+
if (inside.length) {
|
|
45
|
+
lines.push('视口里(离中心由近到远):');
|
|
46
|
+
for (const r of inside.slice(0, 20)) {
|
|
47
|
+
const e = board.objects[r.id];
|
|
48
|
+
const flags = `${e.staging ? ' 〔草稿〕' : ''}${e.tag ? ` #${e.tag}` : ''}`;
|
|
49
|
+
lines.push(`- ${describeEndpoint(r.id, board)} @(${Math.round(r.x)},${Math.round(r.y)}) ${Math.round(r.w)}x${Math.round(r.h)} (id: ${r.id})${flags}`);
|
|
50
|
+
}
|
|
51
|
+
if (inside.length > 20) lines.push(`…还有 ${inside.length - 20} 件`);
|
|
52
|
+
}
|
|
53
|
+
lines.push(`视口中心 = (${Math.round(cx)},${Math.round(cy)});想让用户不用动镜头就看到,就把东西摆进这个矩形。`);
|
|
54
|
+
}
|
|
55
|
+
if (vp.selected?.length) lines.push(`选中:${vp.selected.map(id => describeEndpoint(id, board)).join('、')}`);
|
|
56
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/record-decision.js — record_decision MCP tool
|
|
3
|
-
*
|
|
4
|
-
* agent 在做关键设计决策时调,把"做了什么 + 为什么"写成共享便利贴
|
|
5
|
-
* `notes/决策.md` 的一面(`---` 分面)。2026-07-30 起决策
|
|
6
|
-
* 不再进 spec.json.decisions[]:便利贴是 agent 和用户的**共享层**——
|
|
7
|
-
* 用户在画布上直接看到、能翻、能改;spec.json 只是 agent 自己的暗档案,
|
|
8
|
-
* 用户看不见,头脑风暴根本进不来。旧会话已有的 spec.json decisions[]
|
|
9
|
-
* 仍被 hooks 注入(只读遗产),新决策一律走这里。
|
|
10
|
-
*
|
|
11
|
-
* 便利贴格式约定(前端 NoteSticker 按此渲染):
|
|
12
|
-
* - 一个 .md = 一张贴;`\n---\n` 分面,翻页看
|
|
13
|
-
* - 每面第一行 `# 标题`
|
|
14
|
-
*
|
|
15
|
-
* 落点:工作区 `notes/`(扁平模型,2026-08-08 起)—— 没有"任务归属"了,
|
|
16
|
-
* 便利贴直接住项目桌面。
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
20
|
-
import { z } from 'zod';
|
|
21
|
-
import { promises as fs } from 'node:fs';
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import { Events } from '../../agent/events.js';
|
|
24
|
-
|
|
25
|
-
const NOTE_FILE = '决策.md';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {object} deps
|
|
29
|
-
* @param {string} deps.workspaceRoot
|
|
30
|
-
* @param {string} [deps.sessionId]
|
|
31
|
-
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
32
|
-
*/
|
|
33
|
-
export function makeRecordDecisionTool({ workspaceRoot, sessionId, ctx }) {
|
|
34
|
-
return tool(
|
|
35
|
-
'record_decision',
|
|
36
|
-
`Record a key design decision as a face of the project's decision sticky note
|
|
37
|
-
(notes/决策.md). The note is SHARED with the user — it renders as
|
|
38
|
-
a flippable sticky on their canvas, they can read and edit it. Use this to
|
|
39
|
-
capture WHY you made a particular choice — color, type scale, layout metaphor,
|
|
40
|
-
copy strategy — so the intent survives across sessions and the user can push
|
|
41
|
-
back on it.
|
|
42
|
-
|
|
43
|
-
Use this tool when:
|
|
44
|
-
- You make a non-trivial choice that has multiple defensible alternatives
|
|
45
|
-
(e.g., picking a primary color, deciding deck length, choosing a layout)
|
|
46
|
-
- The user gives feedback that changes a previous decision (record both)
|
|
47
|
-
- You want to document a constraint discovered mid-work
|
|
48
|
-
|
|
49
|
-
Do NOT use this tool for:
|
|
50
|
-
- Trivial implementation details (CSS class names, file structure)
|
|
51
|
-
- Things obvious from the canvas itself (the visible design speaks for itself)
|
|
52
|
-
- Every change — over-recording bloats the note and dilutes signal
|
|
53
|
-
|
|
54
|
-
For free-form shared notes (brainstorm material, reference digests, handoff
|
|
55
|
-
context), just Write notes/<slug>.md directly — same sticky-note
|
|
56
|
-
rendering, no tool needed.`,
|
|
57
|
-
{
|
|
58
|
-
title: z
|
|
59
|
-
.string()
|
|
60
|
-
.min(2)
|
|
61
|
-
.max(200)
|
|
62
|
-
.describe('Short decision title (e.g., "Primary color = #3366FF")'),
|
|
63
|
-
rationale: z
|
|
64
|
-
.string()
|
|
65
|
-
.min(2)
|
|
66
|
-
.max(2000)
|
|
67
|
-
.describe('Why this choice — connect to brief / user feedback / design principle'),
|
|
68
|
-
scope: z
|
|
69
|
-
.string()
|
|
70
|
-
.optional()
|
|
71
|
-
.describe('Where it applies (e.g., "Global", "Cover page", "All H1 headings")'),
|
|
72
|
-
alternatives: z
|
|
73
|
-
.array(z.string())
|
|
74
|
-
.optional()
|
|
75
|
-
.describe('Alternatives considered, briefly noting why rejected'),
|
|
76
|
-
},
|
|
77
|
-
async ({ title, rationale, scope, alternatives }) => {
|
|
78
|
-
try {
|
|
79
|
-
if (!workspaceRoot) {
|
|
80
|
-
return {
|
|
81
|
-
content: [{ type: 'text', text: 'No workspace bound; cannot record decision.' }],
|
|
82
|
-
isError: true,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const alts = Array.isArray(alternatives)
|
|
86
|
-
? alternatives.map(s => String(s).trim()).filter(Boolean) : [];
|
|
87
|
-
const face = [
|
|
88
|
-
`# ${title.trim()}`,
|
|
89
|
-
'',
|
|
90
|
-
rationale.trim(),
|
|
91
|
-
...(scope ? ['', `- 范围:${scope.trim()}`] : []),
|
|
92
|
-
...(alts.length ? [`- 备选:${alts.join(' / ')}`] : []),
|
|
93
|
-
`- ${new Date().toISOString().slice(0, 10)}`,
|
|
94
|
-
].join('\n');
|
|
95
|
-
|
|
96
|
-
const notesDir = path.join(workspaceRoot, 'notes');
|
|
97
|
-
await fs.mkdir(notesDir, { recursive: true });
|
|
98
|
-
const noteFile = path.join(notesDir, NOTE_FILE);
|
|
99
|
-
let prev = '';
|
|
100
|
-
try { prev = await fs.readFile(noteFile, 'utf8'); } catch { /* 首条 */ }
|
|
101
|
-
const next = prev.trim() ? `${prev.replace(/\s+$/, '')}\n\n---\n\n${face}\n` : `${face}\n`;
|
|
102
|
-
await fs.writeFile(noteFile, next, 'utf8');
|
|
103
|
-
|
|
104
|
-
const faceCount = next.split(/\n---\n/).length;
|
|
105
|
-
try {
|
|
106
|
-
// MCP 工具写盘不走 PostToolUse(Write/Edit) 那条 file_changed 直发,
|
|
107
|
-
// 自己补一发,前端便利贴才会当场刷新
|
|
108
|
-
// 工作区相对路径(fileChanged 正字法;曾发绝对路径=前端只吃到清单重拉,
|
|
109
|
-
// 寻址和版本 key 全失配。2026-08-14 普查改)
|
|
110
|
-
ctx?.emit?.(Events.fileChanged(`notes/${NOTE_FILE}`, 'change'));
|
|
111
|
-
ctx?.emit?.({
|
|
112
|
-
type: 'run.decision_recorded',
|
|
113
|
-
title: title.trim(),
|
|
114
|
-
scope: scope?.trim() || null,
|
|
115
|
-
decisionsCount: faceCount,
|
|
116
|
-
});
|
|
117
|
-
} catch { /* emit fail-safe */ }
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
content: [{
|
|
121
|
-
type: 'text',
|
|
122
|
-
// ⚠️ 这里曾写 `tasks/${task}/...` —— 扁平化删掉 task 变量时漏了这行,
|
|
123
|
-
// `task` 成悬空引用:决策照写、事件照发,**返回时 ReferenceError 被
|
|
124
|
-
// 外层 catch 接住**,agent 每次调用都收到报错以为失败(还可能重试出
|
|
125
|
-
// 重复面)。悬空引用潜伏族第二案(第一案 reloadToken,2026-08-08)。
|
|
126
|
-
text: `Decision recorded as face ${faceCount} of notes/${NOTE_FILE}: "${title.trim()}"`,
|
|
127
|
-
}],
|
|
128
|
-
};
|
|
129
|
-
} catch (err) {
|
|
130
|
-
return {
|
|
131
|
-
content: [{
|
|
132
|
-
type: 'text',
|
|
133
|
-
text: `Record decision failed: ${err?.message || String(err)}`,
|
|
134
|
-
}],
|
|
135
|
-
isError: true,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/record-decision.js — record_decision MCP tool
|
|
3
|
+
*
|
|
4
|
+
* agent 在做关键设计决策时调,把"做了什么 + 为什么"写成共享便利贴
|
|
5
|
+
* `notes/决策.md` 的一面(`---` 分面)。2026-07-30 起决策
|
|
6
|
+
* 不再进 spec.json.decisions[]:便利贴是 agent 和用户的**共享层**——
|
|
7
|
+
* 用户在画布上直接看到、能翻、能改;spec.json 只是 agent 自己的暗档案,
|
|
8
|
+
* 用户看不见,头脑风暴根本进不来。旧会话已有的 spec.json decisions[]
|
|
9
|
+
* 仍被 hooks 注入(只读遗产),新决策一律走这里。
|
|
10
|
+
*
|
|
11
|
+
* 便利贴格式约定(前端 NoteSticker 按此渲染):
|
|
12
|
+
* - 一个 .md = 一张贴;`\n---\n` 分面,翻页看
|
|
13
|
+
* - 每面第一行 `# 标题`
|
|
14
|
+
*
|
|
15
|
+
* 落点:工作区 `notes/`(扁平模型,2026-08-08 起)—— 没有"任务归属"了,
|
|
16
|
+
* 便利贴直接住项目桌面。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
import { promises as fs } from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { Events } from '../../agent/events.js';
|
|
24
|
+
|
|
25
|
+
const NOTE_FILE = '决策.md';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {object} deps
|
|
29
|
+
* @param {string} deps.workspaceRoot
|
|
30
|
+
* @param {string} [deps.sessionId]
|
|
31
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
32
|
+
*/
|
|
33
|
+
export function makeRecordDecisionTool({ workspaceRoot, sessionId, ctx }) {
|
|
34
|
+
return tool(
|
|
35
|
+
'record_decision',
|
|
36
|
+
`Record a key design decision as a face of the project's decision sticky note
|
|
37
|
+
(notes/决策.md). The note is SHARED with the user — it renders as
|
|
38
|
+
a flippable sticky on their canvas, they can read and edit it. Use this to
|
|
39
|
+
capture WHY you made a particular choice — color, type scale, layout metaphor,
|
|
40
|
+
copy strategy — so the intent survives across sessions and the user can push
|
|
41
|
+
back on it.
|
|
42
|
+
|
|
43
|
+
Use this tool when:
|
|
44
|
+
- You make a non-trivial choice that has multiple defensible alternatives
|
|
45
|
+
(e.g., picking a primary color, deciding deck length, choosing a layout)
|
|
46
|
+
- The user gives feedback that changes a previous decision (record both)
|
|
47
|
+
- You want to document a constraint discovered mid-work
|
|
48
|
+
|
|
49
|
+
Do NOT use this tool for:
|
|
50
|
+
- Trivial implementation details (CSS class names, file structure)
|
|
51
|
+
- Things obvious from the canvas itself (the visible design speaks for itself)
|
|
52
|
+
- Every change — over-recording bloats the note and dilutes signal
|
|
53
|
+
|
|
54
|
+
For free-form shared notes (brainstorm material, reference digests, handoff
|
|
55
|
+
context), just Write notes/<slug>.md directly — same sticky-note
|
|
56
|
+
rendering, no tool needed.`,
|
|
57
|
+
{
|
|
58
|
+
title: z
|
|
59
|
+
.string()
|
|
60
|
+
.min(2)
|
|
61
|
+
.max(200)
|
|
62
|
+
.describe('Short decision title (e.g., "Primary color = #3366FF")'),
|
|
63
|
+
rationale: z
|
|
64
|
+
.string()
|
|
65
|
+
.min(2)
|
|
66
|
+
.max(2000)
|
|
67
|
+
.describe('Why this choice — connect to brief / user feedback / design principle'),
|
|
68
|
+
scope: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('Where it applies (e.g., "Global", "Cover page", "All H1 headings")'),
|
|
72
|
+
alternatives: z
|
|
73
|
+
.array(z.string())
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('Alternatives considered, briefly noting why rejected'),
|
|
76
|
+
},
|
|
77
|
+
async ({ title, rationale, scope, alternatives }) => {
|
|
78
|
+
try {
|
|
79
|
+
if (!workspaceRoot) {
|
|
80
|
+
return {
|
|
81
|
+
content: [{ type: 'text', text: 'No workspace bound; cannot record decision.' }],
|
|
82
|
+
isError: true,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const alts = Array.isArray(alternatives)
|
|
86
|
+
? alternatives.map(s => String(s).trim()).filter(Boolean) : [];
|
|
87
|
+
const face = [
|
|
88
|
+
`# ${title.trim()}`,
|
|
89
|
+
'',
|
|
90
|
+
rationale.trim(),
|
|
91
|
+
...(scope ? ['', `- 范围:${scope.trim()}`] : []),
|
|
92
|
+
...(alts.length ? [`- 备选:${alts.join(' / ')}`] : []),
|
|
93
|
+
`- ${new Date().toISOString().slice(0, 10)}`,
|
|
94
|
+
].join('\n');
|
|
95
|
+
|
|
96
|
+
const notesDir = path.join(workspaceRoot, 'notes');
|
|
97
|
+
await fs.mkdir(notesDir, { recursive: true });
|
|
98
|
+
const noteFile = path.join(notesDir, NOTE_FILE);
|
|
99
|
+
let prev = '';
|
|
100
|
+
try { prev = await fs.readFile(noteFile, 'utf8'); } catch { /* 首条 */ }
|
|
101
|
+
const next = prev.trim() ? `${prev.replace(/\s+$/, '')}\n\n---\n\n${face}\n` : `${face}\n`;
|
|
102
|
+
await fs.writeFile(noteFile, next, 'utf8');
|
|
103
|
+
|
|
104
|
+
const faceCount = next.split(/\n---\n/).length;
|
|
105
|
+
try {
|
|
106
|
+
// MCP 工具写盘不走 PostToolUse(Write/Edit) 那条 file_changed 直发,
|
|
107
|
+
// 自己补一发,前端便利贴才会当场刷新
|
|
108
|
+
// 工作区相对路径(fileChanged 正字法;曾发绝对路径=前端只吃到清单重拉,
|
|
109
|
+
// 寻址和版本 key 全失配。2026-08-14 普查改)
|
|
110
|
+
ctx?.emit?.(Events.fileChanged(`notes/${NOTE_FILE}`, 'change'));
|
|
111
|
+
ctx?.emit?.({
|
|
112
|
+
type: 'run.decision_recorded',
|
|
113
|
+
title: title.trim(),
|
|
114
|
+
scope: scope?.trim() || null,
|
|
115
|
+
decisionsCount: faceCount,
|
|
116
|
+
});
|
|
117
|
+
} catch { /* emit fail-safe */ }
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
content: [{
|
|
121
|
+
type: 'text',
|
|
122
|
+
// ⚠️ 这里曾写 `tasks/${task}/...` —— 扁平化删掉 task 变量时漏了这行,
|
|
123
|
+
// `task` 成悬空引用:决策照写、事件照发,**返回时 ReferenceError 被
|
|
124
|
+
// 外层 catch 接住**,agent 每次调用都收到报错以为失败(还可能重试出
|
|
125
|
+
// 重复面)。悬空引用潜伏族第二案(第一案 reloadToken,2026-08-08)。
|
|
126
|
+
text: `Decision recorded as face ${faceCount} of notes/${NOTE_FILE}: "${title.trim()}"`,
|
|
127
|
+
}],
|
|
128
|
+
};
|
|
129
|
+
} catch (err) {
|
|
130
|
+
return {
|
|
131
|
+
content: [{
|
|
132
|
+
type: 'text',
|
|
133
|
+
text: `Record decision failed: ${err?.message || String(err)}`,
|
|
134
|
+
}],
|
|
135
|
+
isError: true,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
}
|