@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,205 +1,205 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/get-pending-changes.js — get_pending_changes MCP tool
|
|
3
|
-
*
|
|
4
|
-
* 用户在 canvas 上的"直接编辑(双击文本改字)"和"评论"会被前端 push 到
|
|
5
|
-
* workspace/pending-changes.json。下次用户发 chat 消息时,turn.js 在
|
|
6
|
-
* composeUserMessage 里 prepend 一个 system 提示告诉 agent "有 N 处变更,
|
|
7
|
-
* 可调本工具查看详情"。agent 决定要不要拉详情。
|
|
8
|
-
*
|
|
9
|
-
* pending-changes.json schema:
|
|
10
|
-
* {
|
|
11
|
-
* items: [{
|
|
12
|
-
* id: string,
|
|
13
|
-
* kind: 'edit' | 'comment'
|
|
14
|
-
* | 'pending-move' | 'pending-style' | 'pending-duplicate' | 'pending-delete'
|
|
15
|
-
* | 'applied-move' | 'applied-style' | 'applied-duplicate',
|
|
16
|
-
* anchor: { dataId, path, textHint, bbox },
|
|
17
|
-
* aiContext: { tag, role?, pageInfo?, outerHtml?, computed?, siblings?,
|
|
18
|
-
* targetContainerTag?, alignmentHints? },
|
|
19
|
-
* diff?: { oldText, newText }, // edit 时有
|
|
20
|
-
* text?: string, // comment 时有
|
|
21
|
-
* move?: { container: anchor, before: anchor|null }, // pending-move / -duplicate 时有
|
|
22
|
-
* styleDelta?: { left?, top?, marginLeft?, ... }, // pending-style 时有
|
|
23
|
-
* reactMount?: boolean, // 涉及 React mount 区→改 JSX 源码
|
|
24
|
-
* ts: ISO,
|
|
25
|
-
* }]
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* 2026-05-12 新增 4 个 pending-* kind(画布拖移工具产物):
|
|
29
|
-
* - pending-move 用户拖动元素跨/内容器;按 move.container + move.before 改 DOM 树位置
|
|
30
|
-
* - pending-duplicate 用户 alt-drag 复制;先 clone source 再插入 target
|
|
31
|
-
* - pending-style 用户 nudge / 调对齐;按 styleDelta 改 inline style 或 class
|
|
32
|
-
* - pending-delete 用户按 Del 删元素;按 anchor 删 source 节点
|
|
33
|
-
*
|
|
34
|
-
* reactMount=true 的 item 走 `<script id="__nd-app">` 里的 JSX 改动(不是改 HTML 段)。
|
|
35
|
-
*
|
|
36
|
-
* 2026-07-29 新增 applied-* kind(站点窗拖拽直接落盘):用户在站点页拖完,
|
|
37
|
-
* 前端已把整页序列化写回文件 —— 这些是 FYI 记录(applied:true),**不要再应用一遍**,
|
|
38
|
-
* 只用来理解用户动了什么;有 path 字段指明改的是哪份文件。
|
|
39
|
-
*
|
|
40
|
-
* 拉完后建议调 mcp__nodesign__clear_pending_changes 清 buffer,避免重复处理。
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
import path from 'node:path';
|
|
44
|
-
import fs from 'node:fs/promises';
|
|
45
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
46
|
-
import { z } from 'zod';
|
|
47
|
-
|
|
48
|
-
/** 一次调用最多附几张圈选截图(更早的留路径让 agent 按需自己读) */
|
|
49
|
-
const MAX_REGION_SHOTS = 3;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {object} deps
|
|
53
|
-
* @param {string} deps.workspaceRoot
|
|
54
|
-
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
55
|
-
*/
|
|
56
|
-
export function makeGetPendingChangesTool({ workspaceRoot, ctx: _ctx }) {
|
|
57
|
-
return tool(
|
|
58
|
-
'get_pending_changes',
|
|
59
|
-
`Read the user's pending changes buffer — a list of direct edits, inline
|
|
60
|
-
comments, and drag-tool moves the user made on the canvas in between chat
|
|
61
|
-
turns.
|
|
62
|
-
|
|
63
|
-
When to use:
|
|
64
|
-
- You see a <system>用户在过去时段做了 N 处变更...</system> hint at the top
|
|
65
|
-
of the user's message → call this tool to read the actual changes.
|
|
66
|
-
- The user references "the change I just made" / "the edit I did" / "the move
|
|
67
|
-
I just did" → check the buffer first.
|
|
68
|
-
|
|
69
|
-
Each item has:
|
|
70
|
-
- kind: one of
|
|
71
|
-
'edit' (user changed text by double-clicking in the canvas —
|
|
72
|
-
ALREADY saved to the file; informational)
|
|
73
|
-
'comment' (user wrote a comment for an element)
|
|
74
|
-
'pending-move' (user dragged an element to a new container/position)
|
|
75
|
-
'pending-duplicate'(user alt-dragged to copy an element to a new spot)
|
|
76
|
-
'pending-style' (user nudged / adjusted alignment → inline style delta)
|
|
77
|
-
'pending-delete' (user deleted an element)
|
|
78
|
-
'applied-move' / 'applied-style' / 'applied-duplicate'
|
|
79
|
-
(user dragged inside a site page window — the frontend
|
|
80
|
-
ALREADY serialized the page and wrote it to the file.
|
|
81
|
-
Do NOT re-apply these; they are FYI so you know what
|
|
82
|
-
the user changed. You may tidy the source afterwards
|
|
83
|
-
— e.g. lift baked inline left/top into the stylesheet —
|
|
84
|
-
but only if asked or clearly beneficial.)
|
|
85
|
-
- path (optional): which file the change belongs to (workspace-relative, e.g. about.html or 稿件/about.html).
|
|
86
|
-
Absent = the current session's canvas.html.
|
|
87
|
-
- anchor: stable element reference (dataId / path / textHint / bbox)
|
|
88
|
-
- aiContext: element role, page info, outerHTML, computed styles, siblings,
|
|
89
|
-
plus targetContainerTag / alignmentHints for moves
|
|
90
|
-
- diff (edit): { oldText, newText }
|
|
91
|
-
- becameEmpty (edit): true means the user CLEARED that text. The element is still
|
|
92
|
-
in the source and still takes up vertical space — usually you should delete the
|
|
93
|
-
whole element, not just leave it empty. Ask if you are unsure.
|
|
94
|
-
- text (comment): the comment body
|
|
95
|
-
- linkedToEditId (comment, optional): when present, this comment is a follow-up
|
|
96
|
-
instruction tied to another pending edit (e.g. "for that drag I just did, keep
|
|
97
|
-
the neighbor element fixed"). Always read the linked edit and treat them as
|
|
98
|
-
one combined operation; both get cleared together.
|
|
99
|
-
- move (pending-move / pending-duplicate): { container: anchor, before: anchor|null }
|
|
100
|
-
- styleDelta (pending-style): { left?, top?, marginLeft?, ... }
|
|
101
|
-
- reactMount: when true, the change touches a React mount subtree → modify
|
|
102
|
-
the JSX inside <script id="__nd-app"> rather than the static HTML
|
|
103
|
-
|
|
104
|
-
'region-comment' items are different in shape — the user lassoed an AREA of
|
|
105
|
-
the preview rather than clicking one element:
|
|
106
|
-
- region: { x, y, w, h } in page CSS px, and viewport: the size they saw it at
|
|
107
|
-
- elements: what sits inside that box, innermost-first, each with anchor / tag /
|
|
108
|
-
a text excerpt / its own rect / coverage (how much of it the box covers).
|
|
109
|
-
Containers much larger than the box are deliberately excluded — the user was
|
|
110
|
-
pointing at what's inside, not at the wrapper.
|
|
111
|
-
- container: the innermost element that fully encloses the box — i.e. WHERE on
|
|
112
|
-
the page this is. The elements list alone can't tell you header from footer.
|
|
113
|
-
- text: what they said about it (may be empty — the box itself is the message)
|
|
114
|
-
- shot: a screenshot of that area (plus a little margin), attached to this
|
|
115
|
-
tool result as an image right after the JSON. Look at it: it is the ground
|
|
116
|
-
truth of what the user was looking at, and the elements list is only an
|
|
117
|
-
index into it.
|
|
118
|
-
- docxPage (present when path is a .docx): the user lassoed on a rendered page
|
|
119
|
-
image of a word document — docxPage is the 1-based page number, region is in
|
|
120
|
-
page-image pixels, and there are NO elements/container (a page image has no
|
|
121
|
-
DOM). The shot is cropped from the same LibreOffice page render the user was
|
|
122
|
-
looking at. To act on it, edit the token JSON source and rebuild with
|
|
123
|
-
build_docx — never edit the .docx itself.
|
|
124
|
-
|
|
125
|
-
After processing, call mcp__nodesign__clear_pending_changes to clear the
|
|
126
|
-
buffer so subsequent turns don't see the same changes again.`,
|
|
127
|
-
{
|
|
128
|
-
// No params; reading is unconditional.
|
|
129
|
-
_placeholder: z.string().optional().describe('Unused; reserved for future filters'),
|
|
130
|
-
},
|
|
131
|
-
async () => {
|
|
132
|
-
try {
|
|
133
|
-
if (!workspaceRoot) {
|
|
134
|
-
return {
|
|
135
|
-
content: [{ type: 'text', text: 'No workspace bound; cannot read pending changes.' }],
|
|
136
|
-
isError: true,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const bufPath = path.join(workspaceRoot, 'pending-changes.json');
|
|
141
|
-
let buf = { items: [] };
|
|
142
|
-
try {
|
|
143
|
-
const raw = await fs.readFile(bufPath, 'utf8');
|
|
144
|
-
const parsed = JSON.parse(raw);
|
|
145
|
-
if (parsed && Array.isArray(parsed.items)) buf = parsed;
|
|
146
|
-
} catch (err) {
|
|
147
|
-
if (err.code !== 'ENOENT') throw err;
|
|
148
|
-
// file doesn't exist = empty buffer
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const items = buf.items;
|
|
152
|
-
if (items.length === 0) {
|
|
153
|
-
return {
|
|
154
|
-
content: [{
|
|
155
|
-
type: 'text',
|
|
156
|
-
text: 'No pending changes. The user has not made any direct edits or comments since the last clear.',
|
|
157
|
-
}],
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const content = [{
|
|
162
|
-
type: 'text',
|
|
163
|
-
text: `Pending changes (${items.length} item${items.length === 1 ? '' : 's'}):\n\n`
|
|
164
|
-
+ JSON.stringify(items, null, 2),
|
|
165
|
-
}];
|
|
166
|
-
|
|
167
|
-
// 圈选的截图直接挂在结果里 —— 那张图就是用户当时看着的画面,让 agent
|
|
168
|
-
// 再去 Read 一次纯属多一跳,而且它多半不会主动去读。
|
|
169
|
-
// 只带最近 MAX_REGION_SHOTS 张:一次拉出十张图,token 全烧在这上面。
|
|
170
|
-
const shots = items.filter(it => it.kind === 'region-comment' && it.shot);
|
|
171
|
-
const attach = shots.slice(-MAX_REGION_SHOTS);
|
|
172
|
-
for (const it of attach) {
|
|
173
|
-
try {
|
|
174
|
-
const buf = await fs.readFile(path.join(workspaceRoot, it.shot));
|
|
175
|
-
content.push({ type: 'text', text: `↓ 圈选 ${it.id}(${it.path})用户框住的那一块:`
|
|
176
|
-
+ (it.shotNote ? `\n${it.shotNote}(所以这张图不等于用户当时看到的画面)` : '') });
|
|
177
|
-
content.push({ type: 'image', data: buf.toString('base64'), mimeType: 'image/webp' });
|
|
178
|
-
} catch (err) {
|
|
179
|
-
content.push({
|
|
180
|
-
type: 'text',
|
|
181
|
-
text: `圈选 ${it.id} 的截图读不到(${err?.code || err?.message})—— 按 elements 清单和 region 坐标处理。`,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (shots.length > attach.length) {
|
|
186
|
-
content.push({
|
|
187
|
-
type: 'text',
|
|
188
|
-
text: `另有 ${shots.length - attach.length} 张更早的圈选截图没有附上(一次最多 ${MAX_REGION_SHOTS} 张)。`
|
|
189
|
-
+ `需要的话按 item 里的 shot 路径自己 Read。`,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return { content };
|
|
194
|
-
} catch (err) {
|
|
195
|
-
return {
|
|
196
|
-
content: [{
|
|
197
|
-
type: 'text',
|
|
198
|
-
text: `get_pending_changes failed: ${err?.message || String(err)}`,
|
|
199
|
-
}],
|
|
200
|
-
isError: true,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
);
|
|
205
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/get-pending-changes.js — get_pending_changes MCP tool
|
|
3
|
+
*
|
|
4
|
+
* 用户在 canvas 上的"直接编辑(双击文本改字)"和"评论"会被前端 push 到
|
|
5
|
+
* workspace/pending-changes.json。下次用户发 chat 消息时,turn.js 在
|
|
6
|
+
* composeUserMessage 里 prepend 一个 system 提示告诉 agent "有 N 处变更,
|
|
7
|
+
* 可调本工具查看详情"。agent 决定要不要拉详情。
|
|
8
|
+
*
|
|
9
|
+
* pending-changes.json schema:
|
|
10
|
+
* {
|
|
11
|
+
* items: [{
|
|
12
|
+
* id: string,
|
|
13
|
+
* kind: 'edit' | 'comment'
|
|
14
|
+
* | 'pending-move' | 'pending-style' | 'pending-duplicate' | 'pending-delete'
|
|
15
|
+
* | 'applied-move' | 'applied-style' | 'applied-duplicate',
|
|
16
|
+
* anchor: { dataId, path, textHint, bbox },
|
|
17
|
+
* aiContext: { tag, role?, pageInfo?, outerHtml?, computed?, siblings?,
|
|
18
|
+
* targetContainerTag?, alignmentHints? },
|
|
19
|
+
* diff?: { oldText, newText }, // edit 时有
|
|
20
|
+
* text?: string, // comment 时有
|
|
21
|
+
* move?: { container: anchor, before: anchor|null }, // pending-move / -duplicate 时有
|
|
22
|
+
* styleDelta?: { left?, top?, marginLeft?, ... }, // pending-style 时有
|
|
23
|
+
* reactMount?: boolean, // 涉及 React mount 区→改 JSX 源码
|
|
24
|
+
* ts: ISO,
|
|
25
|
+
* }]
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* 2026-05-12 新增 4 个 pending-* kind(画布拖移工具产物):
|
|
29
|
+
* - pending-move 用户拖动元素跨/内容器;按 move.container + move.before 改 DOM 树位置
|
|
30
|
+
* - pending-duplicate 用户 alt-drag 复制;先 clone source 再插入 target
|
|
31
|
+
* - pending-style 用户 nudge / 调对齐;按 styleDelta 改 inline style 或 class
|
|
32
|
+
* - pending-delete 用户按 Del 删元素;按 anchor 删 source 节点
|
|
33
|
+
*
|
|
34
|
+
* reactMount=true 的 item 走 `<script id="__nd-app">` 里的 JSX 改动(不是改 HTML 段)。
|
|
35
|
+
*
|
|
36
|
+
* 2026-07-29 新增 applied-* kind(站点窗拖拽直接落盘):用户在站点页拖完,
|
|
37
|
+
* 前端已把整页序列化写回文件 —— 这些是 FYI 记录(applied:true),**不要再应用一遍**,
|
|
38
|
+
* 只用来理解用户动了什么;有 path 字段指明改的是哪份文件。
|
|
39
|
+
*
|
|
40
|
+
* 拉完后建议调 mcp__nodesign__clear_pending_changes 清 buffer,避免重复处理。
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import path from 'node:path';
|
|
44
|
+
import fs from 'node:fs/promises';
|
|
45
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
46
|
+
import { z } from 'zod';
|
|
47
|
+
|
|
48
|
+
/** 一次调用最多附几张圈选截图(更早的留路径让 agent 按需自己读) */
|
|
49
|
+
const MAX_REGION_SHOTS = 3;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {object} deps
|
|
53
|
+
* @param {string} deps.workspaceRoot
|
|
54
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
55
|
+
*/
|
|
56
|
+
export function makeGetPendingChangesTool({ workspaceRoot, ctx: _ctx }) {
|
|
57
|
+
return tool(
|
|
58
|
+
'get_pending_changes',
|
|
59
|
+
`Read the user's pending changes buffer — a list of direct edits, inline
|
|
60
|
+
comments, and drag-tool moves the user made on the canvas in between chat
|
|
61
|
+
turns.
|
|
62
|
+
|
|
63
|
+
When to use:
|
|
64
|
+
- You see a <system>用户在过去时段做了 N 处变更...</system> hint at the top
|
|
65
|
+
of the user's message → call this tool to read the actual changes.
|
|
66
|
+
- The user references "the change I just made" / "the edit I did" / "the move
|
|
67
|
+
I just did" → check the buffer first.
|
|
68
|
+
|
|
69
|
+
Each item has:
|
|
70
|
+
- kind: one of
|
|
71
|
+
'edit' (user changed text by double-clicking in the canvas —
|
|
72
|
+
ALREADY saved to the file; informational)
|
|
73
|
+
'comment' (user wrote a comment for an element)
|
|
74
|
+
'pending-move' (user dragged an element to a new container/position)
|
|
75
|
+
'pending-duplicate'(user alt-dragged to copy an element to a new spot)
|
|
76
|
+
'pending-style' (user nudged / adjusted alignment → inline style delta)
|
|
77
|
+
'pending-delete' (user deleted an element)
|
|
78
|
+
'applied-move' / 'applied-style' / 'applied-duplicate'
|
|
79
|
+
(user dragged inside a site page window — the frontend
|
|
80
|
+
ALREADY serialized the page and wrote it to the file.
|
|
81
|
+
Do NOT re-apply these; they are FYI so you know what
|
|
82
|
+
the user changed. You may tidy the source afterwards
|
|
83
|
+
— e.g. lift baked inline left/top into the stylesheet —
|
|
84
|
+
but only if asked or clearly beneficial.)
|
|
85
|
+
- path (optional): which file the change belongs to (workspace-relative, e.g. about.html or 稿件/about.html).
|
|
86
|
+
Absent = the current session's canvas.html.
|
|
87
|
+
- anchor: stable element reference (dataId / path / textHint / bbox)
|
|
88
|
+
- aiContext: element role, page info, outerHTML, computed styles, siblings,
|
|
89
|
+
plus targetContainerTag / alignmentHints for moves
|
|
90
|
+
- diff (edit): { oldText, newText }
|
|
91
|
+
- becameEmpty (edit): true means the user CLEARED that text. The element is still
|
|
92
|
+
in the source and still takes up vertical space — usually you should delete the
|
|
93
|
+
whole element, not just leave it empty. Ask if you are unsure.
|
|
94
|
+
- text (comment): the comment body
|
|
95
|
+
- linkedToEditId (comment, optional): when present, this comment is a follow-up
|
|
96
|
+
instruction tied to another pending edit (e.g. "for that drag I just did, keep
|
|
97
|
+
the neighbor element fixed"). Always read the linked edit and treat them as
|
|
98
|
+
one combined operation; both get cleared together.
|
|
99
|
+
- move (pending-move / pending-duplicate): { container: anchor, before: anchor|null }
|
|
100
|
+
- styleDelta (pending-style): { left?, top?, marginLeft?, ... }
|
|
101
|
+
- reactMount: when true, the change touches a React mount subtree → modify
|
|
102
|
+
the JSX inside <script id="__nd-app"> rather than the static HTML
|
|
103
|
+
|
|
104
|
+
'region-comment' items are different in shape — the user lassoed an AREA of
|
|
105
|
+
the preview rather than clicking one element:
|
|
106
|
+
- region: { x, y, w, h } in page CSS px, and viewport: the size they saw it at
|
|
107
|
+
- elements: what sits inside that box, innermost-first, each with anchor / tag /
|
|
108
|
+
a text excerpt / its own rect / coverage (how much of it the box covers).
|
|
109
|
+
Containers much larger than the box are deliberately excluded — the user was
|
|
110
|
+
pointing at what's inside, not at the wrapper.
|
|
111
|
+
- container: the innermost element that fully encloses the box — i.e. WHERE on
|
|
112
|
+
the page this is. The elements list alone can't tell you header from footer.
|
|
113
|
+
- text: what they said about it (may be empty — the box itself is the message)
|
|
114
|
+
- shot: a screenshot of that area (plus a little margin), attached to this
|
|
115
|
+
tool result as an image right after the JSON. Look at it: it is the ground
|
|
116
|
+
truth of what the user was looking at, and the elements list is only an
|
|
117
|
+
index into it.
|
|
118
|
+
- docxPage (present when path is a .docx): the user lassoed on a rendered page
|
|
119
|
+
image of a word document — docxPage is the 1-based page number, region is in
|
|
120
|
+
page-image pixels, and there are NO elements/container (a page image has no
|
|
121
|
+
DOM). The shot is cropped from the same LibreOffice page render the user was
|
|
122
|
+
looking at. To act on it, edit the token JSON source and rebuild with
|
|
123
|
+
build_docx — never edit the .docx itself.
|
|
124
|
+
|
|
125
|
+
After processing, call mcp__nodesign__clear_pending_changes to clear the
|
|
126
|
+
buffer so subsequent turns don't see the same changes again.`,
|
|
127
|
+
{
|
|
128
|
+
// No params; reading is unconditional.
|
|
129
|
+
_placeholder: z.string().optional().describe('Unused; reserved for future filters'),
|
|
130
|
+
},
|
|
131
|
+
async () => {
|
|
132
|
+
try {
|
|
133
|
+
if (!workspaceRoot) {
|
|
134
|
+
return {
|
|
135
|
+
content: [{ type: 'text', text: 'No workspace bound; cannot read pending changes.' }],
|
|
136
|
+
isError: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const bufPath = path.join(workspaceRoot, 'pending-changes.json');
|
|
141
|
+
let buf = { items: [] };
|
|
142
|
+
try {
|
|
143
|
+
const raw = await fs.readFile(bufPath, 'utf8');
|
|
144
|
+
const parsed = JSON.parse(raw);
|
|
145
|
+
if (parsed && Array.isArray(parsed.items)) buf = parsed;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
if (err.code !== 'ENOENT') throw err;
|
|
148
|
+
// file doesn't exist = empty buffer
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const items = buf.items;
|
|
152
|
+
if (items.length === 0) {
|
|
153
|
+
return {
|
|
154
|
+
content: [{
|
|
155
|
+
type: 'text',
|
|
156
|
+
text: 'No pending changes. The user has not made any direct edits or comments since the last clear.',
|
|
157
|
+
}],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const content = [{
|
|
162
|
+
type: 'text',
|
|
163
|
+
text: `Pending changes (${items.length} item${items.length === 1 ? '' : 's'}):\n\n`
|
|
164
|
+
+ JSON.stringify(items, null, 2),
|
|
165
|
+
}];
|
|
166
|
+
|
|
167
|
+
// 圈选的截图直接挂在结果里 —— 那张图就是用户当时看着的画面,让 agent
|
|
168
|
+
// 再去 Read 一次纯属多一跳,而且它多半不会主动去读。
|
|
169
|
+
// 只带最近 MAX_REGION_SHOTS 张:一次拉出十张图,token 全烧在这上面。
|
|
170
|
+
const shots = items.filter(it => it.kind === 'region-comment' && it.shot);
|
|
171
|
+
const attach = shots.slice(-MAX_REGION_SHOTS);
|
|
172
|
+
for (const it of attach) {
|
|
173
|
+
try {
|
|
174
|
+
const buf = await fs.readFile(path.join(workspaceRoot, it.shot));
|
|
175
|
+
content.push({ type: 'text', text: `↓ 圈选 ${it.id}(${it.path})用户框住的那一块:`
|
|
176
|
+
+ (it.shotNote ? `\n${it.shotNote}(所以这张图不等于用户当时看到的画面)` : '') });
|
|
177
|
+
content.push({ type: 'image', data: buf.toString('base64'), mimeType: 'image/webp' });
|
|
178
|
+
} catch (err) {
|
|
179
|
+
content.push({
|
|
180
|
+
type: 'text',
|
|
181
|
+
text: `圈选 ${it.id} 的截图读不到(${err?.code || err?.message})—— 按 elements 清单和 region 坐标处理。`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (shots.length > attach.length) {
|
|
186
|
+
content.push({
|
|
187
|
+
type: 'text',
|
|
188
|
+
text: `另有 ${shots.length - attach.length} 张更早的圈选截图没有附上(一次最多 ${MAX_REGION_SHOTS} 张)。`
|
|
189
|
+
+ `需要的话按 item 里的 shot 路径自己 Read。`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return { content };
|
|
194
|
+
} catch (err) {
|
|
195
|
+
return {
|
|
196
|
+
content: [{
|
|
197
|
+
type: 'text',
|
|
198
|
+
text: `get_pending_changes failed: ${err?.message || String(err)}`,
|
|
199
|
+
}],
|
|
200
|
+
isError: true,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/h3box-ssh.js — GPU 盒子 SSH 公用件(roll_film / paint_still 共用)
|
|
3
|
-
*
|
|
4
|
-
* 盒子 = featurize 按时租的 5090(.env NODESIGN_H3BOX_SSH/PORT/PASS,每次租机
|
|
5
|
-
* 都换)。密码走 sshpass -e(SSHPASS 环境变量),没配密码就当 key 认证。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { spawn } from 'node:child_process';
|
|
9
|
-
import os from 'node:os';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 盒子总开关(2026-08-17)。
|
|
13
|
-
*
|
|
14
|
-
* 盒子是站主手动开关的物理机,但 SSH 地址常年配在 .env 里 —— 所以「机器关着」
|
|
15
|
-
* 跟「没配过」在代码里长得完全不一样:后者 boxConfig() 返回 null 能立刻兜底,
|
|
16
|
-
* 前者会一路 SSH 到超时才失败(paint_still 单张 240s、krea2 400s,整批还要乘
|
|
17
|
-
* 系数;roll_film 每镜 900s),agent 和用户一起干等几分钟,还看不出为什么。
|
|
18
|
-
*
|
|
19
|
-
* 这个开关让工具在**调用的第一行**就诚实说不可用。开机后把 .env 里那行改回 on
|
|
20
|
-
* (或整行删掉,默认就是 on)。它管的是整台机器:paint_still 的五个模型和
|
|
21
|
-
* roll_film 的 box 后端都住在上面。
|
|
22
|
-
*/
|
|
23
|
-
export const localBoxEnabled = () => (process.env.NODESIGN_LOCAL_BOX || 'on').toLowerCase() !== 'off';
|
|
24
|
-
|
|
25
|
-
/** 关机时给 agent 的统一说辞:说清原因、给替代路径、明确别重试 */
|
|
26
|
-
export const BOX_OFF_MSG = '本地 GPU 盒子当前关着(站主手动开关机)。这台机器上的东西'
|
|
27
|
-
+ '现在都用不了:paint_still 的 noobai / noobai-eps / pony / anima / krea2 五个模型,'
|
|
28
|
-
+ '以及 roll_film 的本地后端。转告用户,生图改走 generate_image;要用本地产线得先开机。'
|
|
29
|
-
+ '别重试,重试也是同样的结果。';
|
|
30
|
-
|
|
31
|
-
export function boxConfig() {
|
|
32
|
-
const target = process.env.NODESIGN_H3BOX_SSH || '';
|
|
33
|
-
if (!target) return null;
|
|
34
|
-
return {
|
|
35
|
-
target,
|
|
36
|
-
port: process.env.NODESIGN_H3BOX_PORT || '22',
|
|
37
|
-
pass: process.env.NODESIGN_H3BOX_PASS || '',
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** POSIX 单引号转义(远端 zsh/bash 规则相同) */
|
|
42
|
-
export const shq = (s) => `'${String(s).replace(/'/g, "'\\''")}'`;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 跑一条 ssh/scp。永不 throw,resolve {code, out, err};code=-1 表示本地 spawn 失败。
|
|
46
|
-
* @param {{target:string,port:string,pass:string}} box
|
|
47
|
-
* @param {'ssh'|'scp'} bin
|
|
48
|
-
*/
|
|
49
|
-
export function runBox(box, bin, args, { timeoutMs = 240_000, signal } = {}) {
|
|
50
|
-
return new Promise((resolve) => {
|
|
51
|
-
const env = { ...process.env };
|
|
52
|
-
let cmd = bin; let argv = args;
|
|
53
|
-
if (box.pass) {
|
|
54
|
-
env.SSHPASS = box.pass;
|
|
55
|
-
cmd = 'sshpass'; argv = ['-e', bin, ...args];
|
|
56
|
-
}
|
|
57
|
-
const child = spawn(cmd, argv, { stdio: ['ignore', 'pipe', 'pipe'], env });
|
|
58
|
-
let out = ''; let err = '';
|
|
59
|
-
child.stdout.on('data', (d) => { out = (out + d).slice(-8000); });
|
|
60
|
-
child.stderr.on('data', (d) => { err = (err + d).slice(-2000); });
|
|
61
|
-
const timer = setTimeout(() => { try { child.kill('SIGKILL'); } catch { /* */ } }, timeoutMs);
|
|
62
|
-
const onAbort = () => { try { child.kill('SIGKILL'); } catch { /* */ } };
|
|
63
|
-
signal?.addEventListener?.('abort', onAbort, { once: true });
|
|
64
|
-
child.on('close', (code) => {
|
|
65
|
-
clearTimeout(timer);
|
|
66
|
-
signal?.removeEventListener?.('abort', onAbort);
|
|
67
|
-
resolve({ code, out, err });
|
|
68
|
-
});
|
|
69
|
-
child.on('error', (e) => { clearTimeout(timer); resolve({ code: -1, out, err: String(e.message) }); });
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 连接复用:首连付一次完整握手(跨境实测 ~4s),之后 10 分钟内的 ssh/scp 走同一条
|
|
74
|
-
// 隧道,每次 ~0.1s。socket 名带主机+端口,换租新盒(端口必变)不会撞旧 socket;
|
|
75
|
-
// master 空闲 10 分钟自灭,盒子重启后 auto 会自动弃掉死 socket 重连。
|
|
76
|
-
const CTRL = [
|
|
77
|
-
'-o', 'ControlMaster=auto',
|
|
78
|
-
'-o', `ControlPath=${os.tmpdir()}/h3box-cm-%r@%h-%p`,
|
|
79
|
-
'-o', 'ControlPersist=600',
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
/** ssh 公共参数(-p 端口);scp 用 scpArgs(-P 端口) */
|
|
83
|
-
export const sshArgs = (box) => [...CTRL, '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=10', '-p', box.port, box.target];
|
|
84
|
-
export const scpArgs = (box) => [...CTRL, '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=10', '-P', box.port];
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/h3box-ssh.js — GPU 盒子 SSH 公用件(roll_film / paint_still 共用)
|
|
3
|
+
*
|
|
4
|
+
* 盒子 = featurize 按时租的 5090(.env NODESIGN_H3BOX_SSH/PORT/PASS,每次租机
|
|
5
|
+
* 都换)。密码走 sshpass -e(SSHPASS 环境变量),没配密码就当 key 认证。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 盒子总开关(2026-08-17)。
|
|
13
|
+
*
|
|
14
|
+
* 盒子是站主手动开关的物理机,但 SSH 地址常年配在 .env 里 —— 所以「机器关着」
|
|
15
|
+
* 跟「没配过」在代码里长得完全不一样:后者 boxConfig() 返回 null 能立刻兜底,
|
|
16
|
+
* 前者会一路 SSH 到超时才失败(paint_still 单张 240s、krea2 400s,整批还要乘
|
|
17
|
+
* 系数;roll_film 每镜 900s),agent 和用户一起干等几分钟,还看不出为什么。
|
|
18
|
+
*
|
|
19
|
+
* 这个开关让工具在**调用的第一行**就诚实说不可用。开机后把 .env 里那行改回 on
|
|
20
|
+
* (或整行删掉,默认就是 on)。它管的是整台机器:paint_still 的五个模型和
|
|
21
|
+
* roll_film 的 box 后端都住在上面。
|
|
22
|
+
*/
|
|
23
|
+
export const localBoxEnabled = () => (process.env.NODESIGN_LOCAL_BOX || 'on').toLowerCase() !== 'off';
|
|
24
|
+
|
|
25
|
+
/** 关机时给 agent 的统一说辞:说清原因、给替代路径、明确别重试 */
|
|
26
|
+
export const BOX_OFF_MSG = '本地 GPU 盒子当前关着(站主手动开关机)。这台机器上的东西'
|
|
27
|
+
+ '现在都用不了:paint_still 的 noobai / noobai-eps / pony / anima / krea2 五个模型,'
|
|
28
|
+
+ '以及 roll_film 的本地后端。转告用户,生图改走 generate_image;要用本地产线得先开机。'
|
|
29
|
+
+ '别重试,重试也是同样的结果。';
|
|
30
|
+
|
|
31
|
+
export function boxConfig() {
|
|
32
|
+
const target = process.env.NODESIGN_H3BOX_SSH || '';
|
|
33
|
+
if (!target) return null;
|
|
34
|
+
return {
|
|
35
|
+
target,
|
|
36
|
+
port: process.env.NODESIGN_H3BOX_PORT || '22',
|
|
37
|
+
pass: process.env.NODESIGN_H3BOX_PASS || '',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** POSIX 单引号转义(远端 zsh/bash 规则相同) */
|
|
42
|
+
export const shq = (s) => `'${String(s).replace(/'/g, "'\\''")}'`;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 跑一条 ssh/scp。永不 throw,resolve {code, out, err};code=-1 表示本地 spawn 失败。
|
|
46
|
+
* @param {{target:string,port:string,pass:string}} box
|
|
47
|
+
* @param {'ssh'|'scp'} bin
|
|
48
|
+
*/
|
|
49
|
+
export function runBox(box, bin, args, { timeoutMs = 240_000, signal } = {}) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const env = { ...process.env };
|
|
52
|
+
let cmd = bin; let argv = args;
|
|
53
|
+
if (box.pass) {
|
|
54
|
+
env.SSHPASS = box.pass;
|
|
55
|
+
cmd = 'sshpass'; argv = ['-e', bin, ...args];
|
|
56
|
+
}
|
|
57
|
+
const child = spawn(cmd, argv, { stdio: ['ignore', 'pipe', 'pipe'], env });
|
|
58
|
+
let out = ''; let err = '';
|
|
59
|
+
child.stdout.on('data', (d) => { out = (out + d).slice(-8000); });
|
|
60
|
+
child.stderr.on('data', (d) => { err = (err + d).slice(-2000); });
|
|
61
|
+
const timer = setTimeout(() => { try { child.kill('SIGKILL'); } catch { /* */ } }, timeoutMs);
|
|
62
|
+
const onAbort = () => { try { child.kill('SIGKILL'); } catch { /* */ } };
|
|
63
|
+
signal?.addEventListener?.('abort', onAbort, { once: true });
|
|
64
|
+
child.on('close', (code) => {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
signal?.removeEventListener?.('abort', onAbort);
|
|
67
|
+
resolve({ code, out, err });
|
|
68
|
+
});
|
|
69
|
+
child.on('error', (e) => { clearTimeout(timer); resolve({ code: -1, out, err: String(e.message) }); });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 连接复用:首连付一次完整握手(跨境实测 ~4s),之后 10 分钟内的 ssh/scp 走同一条
|
|
74
|
+
// 隧道,每次 ~0.1s。socket 名带主机+端口,换租新盒(端口必变)不会撞旧 socket;
|
|
75
|
+
// master 空闲 10 分钟自灭,盒子重启后 auto 会自动弃掉死 socket 重连。
|
|
76
|
+
const CTRL = [
|
|
77
|
+
'-o', 'ControlMaster=auto',
|
|
78
|
+
'-o', `ControlPath=${os.tmpdir()}/h3box-cm-%r@%h-%p`,
|
|
79
|
+
'-o', 'ControlPersist=600',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
/** ssh 公共参数(-p 端口);scp 用 scpArgs(-P 端口) */
|
|
83
|
+
export const sshArgs = (box) => [...CTRL, '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=10', '-p', box.port, box.target];
|
|
84
|
+
export const scpArgs = (box) => [...CTRL, '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=10', '-P', box.port];
|