@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,264 +1,264 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/read-page.js — read_page MCP tool
|
|
3
|
-
*
|
|
4
|
-
* 让 agent 精确读 canvas.html 的某一页(`<section data-page="N">` 一段),
|
|
5
|
-
* 不必每次 Read 整个 canvas.html 然后自己切片。
|
|
6
|
-
*
|
|
7
|
-
* 行为:
|
|
8
|
-
* - input: { page: number }(1-based,跟 data-page="N" 一致)
|
|
9
|
-
* - 找 canvas.html 里 `<section[^>]*data-page="N"[^>]*>...</section>` 一段
|
|
10
|
-
* - 返该段 outerHTML(含 attributes + 完整子树)
|
|
11
|
-
* - **Hybrid 范式扩展(2026-05-06)**:检测 `<script type="text/babel">` 存在
|
|
12
|
-
* 时,section 里若有 `data-react-mount="xxx"` 或 React mount 用的 `id="xxx"`,
|
|
13
|
-
* 额外 grep babel script 里 `getElementById('xxx')` 上下文 (±20 行) 一并返
|
|
14
|
-
* 回——agent 想改 React 部分时不必再 Read 整个 babel script
|
|
15
|
-
* - 找不到该页 → isError + 列出当前 canvas.html 实际有哪些 page
|
|
16
|
-
* - canvas.html 不存在 → isError + 提示 agent 需要先 Write 创建
|
|
17
|
-
*
|
|
18
|
-
* 用 regex 而非 DOM parser:纯字符串匹配,避免 jsdom 等大依赖;
|
|
19
|
-
* canvas.html 是 agent 自己写的,section 嵌套不会出现(约定每页是 sibling section)。
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import fs from 'node:fs/promises';
|
|
24
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
25
|
-
import { z } from 'zod';
|
|
26
|
-
import { resolveCanvasTarget, CANVAS_PATH_DESC, KIND_SITE, requireBrowsable,
|
|
27
|
-
} from '../../../lib/artifact-target.js';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Thumbnail hint:检测 sectionHtml 是否含 `assets/generated/` 图 + thumbnails 目录存在
|
|
31
|
-
* 返 prepend hint 字符串(无需 hint 时返空)。
|
|
32
|
-
*
|
|
33
|
-
* 让 agent 知道:preview iframe 加载的 <img src> 是 thumbnail 快照(GET /canvas
|
|
34
|
-
* 路径透明改写),文件系统 / 这里返的 outerHTML 中 src 是真实 src,重生图后
|
|
35
|
-
* thumbnail 自动更新。
|
|
36
|
-
*/
|
|
37
|
-
async function detectThumbnailHint(workspaceRoot, sectionHtml) {
|
|
38
|
-
if (!workspaceRoot || !sectionHtml) return '';
|
|
39
|
-
if (!/assets\/generated\//.test(sectionHtml)) return '';
|
|
40
|
-
// thumbnail 与真实 src 的差别 08-21 起只在 generate-image cookbook 里说一次(每次 read_page 都带是 N 倍重复)
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Hybrid 范式:从 section html 抽 mount id(data-react-mount + id 双源),
|
|
46
|
-
* 然后到 raw canvas.html 的 babel script 段里 grep `getElementById('<id>')` 上下文。
|
|
47
|
-
*
|
|
48
|
-
* 为什么取 ±20 行:覆盖 createRoot 调用 + 上方 component 函数定义大概率在这窗口内。
|
|
49
|
-
* agent 拿到这段后能直接看到 "<MyComponent .../>" 的调用 + 定义,不需要再 Read。
|
|
50
|
-
*
|
|
51
|
-
* @param {string} raw 整个 canvas.html
|
|
52
|
-
* @param {string} sectionHtml 当前 section outerHTML
|
|
53
|
-
* @returns {Array<{ mountId: string, snippet: string, startLine: number }>}
|
|
54
|
-
*/
|
|
55
|
-
function extractReactMountSources(raw, sectionHtml) {
|
|
56
|
-
// 1. 检测 hybrid(必有 babel script)
|
|
57
|
-
if (!/<script[^>]*type=["']text\/babel["']/i.test(raw)) return [];
|
|
58
|
-
|
|
59
|
-
// 2. 抽 section 里的 mount id —— data-react-mount 优先,id 兜底
|
|
60
|
-
const mountIds = new Set();
|
|
61
|
-
for (const m of sectionHtml.matchAll(/\bdata-react-mount\s*=\s*["']([^"']+)["']/gi)) mountIds.add(m[1]);
|
|
62
|
-
for (const m of sectionHtml.matchAll(/\bid\s*=\s*["']([^"']+)["']/gi)) mountIds.add(m[1]);
|
|
63
|
-
if (mountIds.size === 0) return [];
|
|
64
|
-
|
|
65
|
-
// 3. 抽出所有 <script type="text/babel">...</script> 段
|
|
66
|
-
const babelBlocks = [...raw.matchAll(/<script[^>]*type=["']text\/babel["'][^>]*>([\s\S]*?)<\/script>/gi)];
|
|
67
|
-
if (babelBlocks.length === 0) return [];
|
|
68
|
-
|
|
69
|
-
// 用整个 raw 行号做参考,方便 agent 知道 babel 段大概在文件哪里
|
|
70
|
-
const rawLines = raw.split('\n');
|
|
71
|
-
const segments = [];
|
|
72
|
-
|
|
73
|
-
for (const id of mountIds) {
|
|
74
|
-
// 在每个 babel 段里找 getElementById('<id>') 调用
|
|
75
|
-
const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
|
-
const re = new RegExp(`getElementById\\s*\\(\\s*['"]${escaped}['"]\\s*\\)`, 'g');
|
|
77
|
-
|
|
78
|
-
for (const block of babelBlocks) {
|
|
79
|
-
const blockText = block[1];
|
|
80
|
-
if (!re.test(blockText)) { re.lastIndex = 0; continue; }
|
|
81
|
-
re.lastIndex = 0;
|
|
82
|
-
|
|
83
|
-
// 找 block 在 raw 中的起始行
|
|
84
|
-
const blockStartIdx = raw.indexOf(block[0]);
|
|
85
|
-
const blockStartLine = blockStartIdx >= 0 ? raw.slice(0, blockStartIdx).split('\n').length : 1;
|
|
86
|
-
|
|
87
|
-
// grep 行号(相对 block)
|
|
88
|
-
const blockLines = blockText.split('\n');
|
|
89
|
-
blockLines.forEach((line, i) => {
|
|
90
|
-
if (line.includes(`getElementById('${id}')`) || line.includes(`getElementById("${id}")`)) {
|
|
91
|
-
const start = Math.max(0, i - 20);
|
|
92
|
-
const end = Math.min(blockLines.length, i + 21);
|
|
93
|
-
const snippet = blockLines.slice(start, end).join('\n');
|
|
94
|
-
segments.push({
|
|
95
|
-
mountId: id,
|
|
96
|
-
snippet,
|
|
97
|
-
startLine: blockStartLine + start + 1, // raw 文件行号
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
break; // 一个 mount id 在第一个匹配的 block 找到就停(避免重复)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return segments;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {object} deps
|
|
110
|
-
* @param {string} deps.workspaceRoot
|
|
111
|
-
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
112
|
-
*/
|
|
113
|
-
export function makeReadPageTool({ workspaceRoot, sessionId, ctx: _ctx }) {
|
|
114
|
-
return tool(
|
|
115
|
-
'read_page',
|
|
116
|
-
`DECK ONLY. Read a specific page (a single \`<section data-page="N">\`) from the deck .html.
|
|
117
|
-
|
|
118
|
-
Use this instead of Read+Grep+offset/limit when you want to inspect or
|
|
119
|
-
reason about one specific page in detail. Returns the outerHTML of that
|
|
120
|
-
section (including attributes and full subtree).
|
|
121
|
-
|
|
122
|
-
**Hybrid mode**: when the deck has \`<script type="text/babel">\` blocks
|
|
123
|
-
(the Hybrid format from the deck starter canvas.template.html), this tool also
|
|
124
|
-
returns the corresponding React mount source code for any
|
|
125
|
-
\`data-react-mount\` / \`id\` attribute it finds in the section — so you
|
|
126
|
-
don't need to Read the whole babel script just to find the component
|
|
127
|
-
that renders to a mount point on this page.
|
|
128
|
-
|
|
129
|
-
When to use:
|
|
130
|
-
- "Show me what page 3 looks like in code" — read_page(3)
|
|
131
|
-
- Before editing page N — read_page(N) to see exact current markup
|
|
132
|
-
- Debugging why a specific page renders wrong
|
|
133
|
-
|
|
134
|
-
When NOT to use:
|
|
135
|
-
- Reading the whole deck structure → use Read on the deck .html with limit:50
|
|
136
|
-
to see all section openings
|
|
137
|
-
- Finding a specific element across pages → use Grep
|
|
138
|
-
- the deck file doesn't exist yet (creating from scratch) → use Write directly
|
|
139
|
-
- sites: pages are separate files — Read them, or list_pages for the site map`,
|
|
140
|
-
{
|
|
141
|
-
page: z
|
|
142
|
-
.number()
|
|
143
|
-
.int()
|
|
144
|
-
.min(1)
|
|
145
|
-
.describe('Page number (1-based, matches data-page="N" attribute)'),
|
|
146
|
-
path: z.string().optional().describe(CANVAS_PATH_DESC),
|
|
147
|
-
},
|
|
148
|
-
async ({ page, path: relPath }) => {
|
|
149
|
-
try {
|
|
150
|
-
if (!workspaceRoot) {
|
|
151
|
-
return {
|
|
152
|
-
content: [{ type: 'text', text: 'No workspace bound; cannot read page.' }],
|
|
153
|
-
isError: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const target = await resolveCanvasTarget(workspaceRoot, relPath, sessionId);
|
|
158
|
-
if (!target.ok) return { content: [{ type: 'text', text: target.message }], isError: true };
|
|
159
|
-
const notBrowsable = requireBrowsable(target);
|
|
160
|
-
if (notBrowsable) return { content: [{ type: 'text', text: notBrowsable }], isError: true };
|
|
161
|
-
const canvasPath = target.absPath;
|
|
162
|
-
let raw;
|
|
163
|
-
try {
|
|
164
|
-
raw = await fs.readFile(canvasPath, 'utf8');
|
|
165
|
-
} catch (err) {
|
|
166
|
-
if (err.code === 'ENOENT') {
|
|
167
|
-
return {
|
|
168
|
-
content: [{
|
|
169
|
-
type: 'text',
|
|
170
|
-
text: 'That deck file does not exist yet. Use Write to create it first '
|
|
171
|
-
+ '(see SKILL.md for the section data-page="N" structure).',
|
|
172
|
-
}],
|
|
173
|
-
isError: true,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
throw err;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// 匹配 `<section ... data-page="<page>" ...>...</section>`
|
|
180
|
-
// 双引号 / 单引号 / 不引号都接受。section 内不嵌套 section(约定)。
|
|
181
|
-
const pageStr = String(page);
|
|
182
|
-
const escaped = pageStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
183
|
-
// 三种 attribute quoting 尝试
|
|
184
|
-
const patterns = [
|
|
185
|
-
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*"${escaped}"[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
186
|
-
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*'${escaped}'[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
187
|
-
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*${escaped}\\b[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
188
|
-
];
|
|
189
|
-
|
|
190
|
-
let match = null;
|
|
191
|
-
for (const re of patterns) {
|
|
192
|
-
const m = raw.match(re);
|
|
193
|
-
if (m) { match = m; break; }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (!match) {
|
|
197
|
-
// 列出 canvas.html 里实际有哪些 page,给 agent 反馈
|
|
198
|
-
const allPages = [...raw.matchAll(/<section\b[^>]*\bdata-page\s*=\s*['"]?(\d+)/gi)]
|
|
199
|
-
.map(m => m[1])
|
|
200
|
-
.filter((v, i, arr) => arr.indexOf(v) === i);
|
|
201
|
-
// 站点:分页读根本不适用,直说该怎么做,别丢一句"没有分页结构"让 agent
|
|
202
|
-
// 自己猜(它多半会改用 Read 全文件,把整份站点灌进上下文)
|
|
203
|
-
if (target.kind === KIND_SITE) {
|
|
204
|
-
return {
|
|
205
|
-
content: [{
|
|
206
|
-
type: 'text',
|
|
207
|
-
text: `${target.relPath} 是站点页面,没有 <section data-page="N"> 分页,read_page 的页码语义不适用。\n`
|
|
208
|
-
+ '站点这样读:先 list_pages 看站点结构(每页的标题 / 小标题 / 站内链接 / 断链),'
|
|
209
|
-
+ '要看某一页的实际内容用 query_elements 按 selector 取,或者直接 Read 那个文件(站点页面通常不大)。',
|
|
210
|
-
}],
|
|
211
|
-
isError: true,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
const pagesList = allPages.length > 0
|
|
215
|
-
? `Available pages: ${allPages.join(', ')}`
|
|
216
|
-
: `${target.relPath} has no <section data-page="N"> structure.`;
|
|
217
|
-
return {
|
|
218
|
-
content: [{
|
|
219
|
-
type: 'text',
|
|
220
|
-
text: `Page ${page} not found in ${target.relPath}. ${pagesList}`,
|
|
221
|
-
}],
|
|
222
|
-
isError: true,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const sectionHtml = match[0];
|
|
227
|
-
|
|
228
|
-
// Hybrid 范式扩展:检测 babel script + section 里的 mount id
|
|
229
|
-
// 找到 mount id 后从 babel script 抓 ±20 行上下文返给 agent
|
|
230
|
-
const hybridSegments = extractReactMountSources(raw, sectionHtml);
|
|
231
|
-
|
|
232
|
-
// Thumbnail hint:section 含 assets/generated/ 图 + thumbnails 目录存在 → prepend hint
|
|
233
|
-
const thumbnailHint = await detectThumbnailHint(workspaceRoot, sectionHtml);
|
|
234
|
-
|
|
235
|
-
const parts = [];
|
|
236
|
-
if (thumbnailHint) parts.push(thumbnailHint + '\n\n');
|
|
237
|
-
parts.push(`Page ${page} (${sectionHtml.length} chars):\n\n${sectionHtml}`);
|
|
238
|
-
if (hybridSegments.length > 0) {
|
|
239
|
-
parts.push(
|
|
240
|
-
`\n\n--- React mount sources for this page (${hybridSegments.length} mount${hybridSegments.length > 1 ? 's' : ''}) ---\n`
|
|
241
|
-
+ hybridSegments.map(({ mountId, snippet, startLine }) =>
|
|
242
|
-
`\n## mount: ${mountId} (babel script line ~${startLine})\n\n\`\`\`tsx\n${snippet}\n\`\`\``
|
|
243
|
-
).join('\n')
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
content: [{
|
|
249
|
-
type: 'text',
|
|
250
|
-
text: parts.join(''),
|
|
251
|
-
}],
|
|
252
|
-
};
|
|
253
|
-
} catch (err) {
|
|
254
|
-
return {
|
|
255
|
-
content: [{
|
|
256
|
-
type: 'text',
|
|
257
|
-
text: `read_page failed: ${err?.message || String(err)}`,
|
|
258
|
-
}],
|
|
259
|
-
isError: true,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
);
|
|
264
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/read-page.js — read_page MCP tool
|
|
3
|
+
*
|
|
4
|
+
* 让 agent 精确读 canvas.html 的某一页(`<section data-page="N">` 一段),
|
|
5
|
+
* 不必每次 Read 整个 canvas.html 然后自己切片。
|
|
6
|
+
*
|
|
7
|
+
* 行为:
|
|
8
|
+
* - input: { page: number }(1-based,跟 data-page="N" 一致)
|
|
9
|
+
* - 找 canvas.html 里 `<section[^>]*data-page="N"[^>]*>...</section>` 一段
|
|
10
|
+
* - 返该段 outerHTML(含 attributes + 完整子树)
|
|
11
|
+
* - **Hybrid 范式扩展(2026-05-06)**:检测 `<script type="text/babel">` 存在
|
|
12
|
+
* 时,section 里若有 `data-react-mount="xxx"` 或 React mount 用的 `id="xxx"`,
|
|
13
|
+
* 额外 grep babel script 里 `getElementById('xxx')` 上下文 (±20 行) 一并返
|
|
14
|
+
* 回——agent 想改 React 部分时不必再 Read 整个 babel script
|
|
15
|
+
* - 找不到该页 → isError + 列出当前 canvas.html 实际有哪些 page
|
|
16
|
+
* - canvas.html 不存在 → isError + 提示 agent 需要先 Write 创建
|
|
17
|
+
*
|
|
18
|
+
* 用 regex 而非 DOM parser:纯字符串匹配,避免 jsdom 等大依赖;
|
|
19
|
+
* canvas.html 是 agent 自己写的,section 嵌套不会出现(约定每页是 sibling section)。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import fs from 'node:fs/promises';
|
|
24
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
import { resolveCanvasTarget, CANVAS_PATH_DESC, KIND_SITE, requireBrowsable,
|
|
27
|
+
} from '../../../lib/artifact-target.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Thumbnail hint:检测 sectionHtml 是否含 `assets/generated/` 图 + thumbnails 目录存在
|
|
31
|
+
* 返 prepend hint 字符串(无需 hint 时返空)。
|
|
32
|
+
*
|
|
33
|
+
* 让 agent 知道:preview iframe 加载的 <img src> 是 thumbnail 快照(GET /canvas
|
|
34
|
+
* 路径透明改写),文件系统 / 这里返的 outerHTML 中 src 是真实 src,重生图后
|
|
35
|
+
* thumbnail 自动更新。
|
|
36
|
+
*/
|
|
37
|
+
async function detectThumbnailHint(workspaceRoot, sectionHtml) {
|
|
38
|
+
if (!workspaceRoot || !sectionHtml) return '';
|
|
39
|
+
if (!/assets\/generated\//.test(sectionHtml)) return '';
|
|
40
|
+
// thumbnail 与真实 src 的差别 08-21 起只在 generate-image cookbook 里说一次(每次 read_page 都带是 N 倍重复)
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hybrid 范式:从 section html 抽 mount id(data-react-mount + id 双源),
|
|
46
|
+
* 然后到 raw canvas.html 的 babel script 段里 grep `getElementById('<id>')` 上下文。
|
|
47
|
+
*
|
|
48
|
+
* 为什么取 ±20 行:覆盖 createRoot 调用 + 上方 component 函数定义大概率在这窗口内。
|
|
49
|
+
* agent 拿到这段后能直接看到 "<MyComponent .../>" 的调用 + 定义,不需要再 Read。
|
|
50
|
+
*
|
|
51
|
+
* @param {string} raw 整个 canvas.html
|
|
52
|
+
* @param {string} sectionHtml 当前 section outerHTML
|
|
53
|
+
* @returns {Array<{ mountId: string, snippet: string, startLine: number }>}
|
|
54
|
+
*/
|
|
55
|
+
function extractReactMountSources(raw, sectionHtml) {
|
|
56
|
+
// 1. 检测 hybrid(必有 babel script)
|
|
57
|
+
if (!/<script[^>]*type=["']text\/babel["']/i.test(raw)) return [];
|
|
58
|
+
|
|
59
|
+
// 2. 抽 section 里的 mount id —— data-react-mount 优先,id 兜底
|
|
60
|
+
const mountIds = new Set();
|
|
61
|
+
for (const m of sectionHtml.matchAll(/\bdata-react-mount\s*=\s*["']([^"']+)["']/gi)) mountIds.add(m[1]);
|
|
62
|
+
for (const m of sectionHtml.matchAll(/\bid\s*=\s*["']([^"']+)["']/gi)) mountIds.add(m[1]);
|
|
63
|
+
if (mountIds.size === 0) return [];
|
|
64
|
+
|
|
65
|
+
// 3. 抽出所有 <script type="text/babel">...</script> 段
|
|
66
|
+
const babelBlocks = [...raw.matchAll(/<script[^>]*type=["']text\/babel["'][^>]*>([\s\S]*?)<\/script>/gi)];
|
|
67
|
+
if (babelBlocks.length === 0) return [];
|
|
68
|
+
|
|
69
|
+
// 用整个 raw 行号做参考,方便 agent 知道 babel 段大概在文件哪里
|
|
70
|
+
const rawLines = raw.split('\n');
|
|
71
|
+
const segments = [];
|
|
72
|
+
|
|
73
|
+
for (const id of mountIds) {
|
|
74
|
+
// 在每个 babel 段里找 getElementById('<id>') 调用
|
|
75
|
+
const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
|
+
const re = new RegExp(`getElementById\\s*\\(\\s*['"]${escaped}['"]\\s*\\)`, 'g');
|
|
77
|
+
|
|
78
|
+
for (const block of babelBlocks) {
|
|
79
|
+
const blockText = block[1];
|
|
80
|
+
if (!re.test(blockText)) { re.lastIndex = 0; continue; }
|
|
81
|
+
re.lastIndex = 0;
|
|
82
|
+
|
|
83
|
+
// 找 block 在 raw 中的起始行
|
|
84
|
+
const blockStartIdx = raw.indexOf(block[0]);
|
|
85
|
+
const blockStartLine = blockStartIdx >= 0 ? raw.slice(0, blockStartIdx).split('\n').length : 1;
|
|
86
|
+
|
|
87
|
+
// grep 行号(相对 block)
|
|
88
|
+
const blockLines = blockText.split('\n');
|
|
89
|
+
blockLines.forEach((line, i) => {
|
|
90
|
+
if (line.includes(`getElementById('${id}')`) || line.includes(`getElementById("${id}")`)) {
|
|
91
|
+
const start = Math.max(0, i - 20);
|
|
92
|
+
const end = Math.min(blockLines.length, i + 21);
|
|
93
|
+
const snippet = blockLines.slice(start, end).join('\n');
|
|
94
|
+
segments.push({
|
|
95
|
+
mountId: id,
|
|
96
|
+
snippet,
|
|
97
|
+
startLine: blockStartLine + start + 1, // raw 文件行号
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
break; // 一个 mount id 在第一个匹配的 block 找到就停(避免重复)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return segments;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {object} deps
|
|
110
|
+
* @param {string} deps.workspaceRoot
|
|
111
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
112
|
+
*/
|
|
113
|
+
export function makeReadPageTool({ workspaceRoot, sessionId, ctx: _ctx }) {
|
|
114
|
+
return tool(
|
|
115
|
+
'read_page',
|
|
116
|
+
`DECK ONLY. Read a specific page (a single \`<section data-page="N">\`) from the deck .html.
|
|
117
|
+
|
|
118
|
+
Use this instead of Read+Grep+offset/limit when you want to inspect or
|
|
119
|
+
reason about one specific page in detail. Returns the outerHTML of that
|
|
120
|
+
section (including attributes and full subtree).
|
|
121
|
+
|
|
122
|
+
**Hybrid mode**: when the deck has \`<script type="text/babel">\` blocks
|
|
123
|
+
(the Hybrid format from the deck starter canvas.template.html), this tool also
|
|
124
|
+
returns the corresponding React mount source code for any
|
|
125
|
+
\`data-react-mount\` / \`id\` attribute it finds in the section — so you
|
|
126
|
+
don't need to Read the whole babel script just to find the component
|
|
127
|
+
that renders to a mount point on this page.
|
|
128
|
+
|
|
129
|
+
When to use:
|
|
130
|
+
- "Show me what page 3 looks like in code" — read_page(3)
|
|
131
|
+
- Before editing page N — read_page(N) to see exact current markup
|
|
132
|
+
- Debugging why a specific page renders wrong
|
|
133
|
+
|
|
134
|
+
When NOT to use:
|
|
135
|
+
- Reading the whole deck structure → use Read on the deck .html with limit:50
|
|
136
|
+
to see all section openings
|
|
137
|
+
- Finding a specific element across pages → use Grep
|
|
138
|
+
- the deck file doesn't exist yet (creating from scratch) → use Write directly
|
|
139
|
+
- sites: pages are separate files — Read them, or list_pages for the site map`,
|
|
140
|
+
{
|
|
141
|
+
page: z
|
|
142
|
+
.number()
|
|
143
|
+
.int()
|
|
144
|
+
.min(1)
|
|
145
|
+
.describe('Page number (1-based, matches data-page="N" attribute)'),
|
|
146
|
+
path: z.string().optional().describe(CANVAS_PATH_DESC),
|
|
147
|
+
},
|
|
148
|
+
async ({ page, path: relPath }) => {
|
|
149
|
+
try {
|
|
150
|
+
if (!workspaceRoot) {
|
|
151
|
+
return {
|
|
152
|
+
content: [{ type: 'text', text: 'No workspace bound; cannot read page.' }],
|
|
153
|
+
isError: true,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const target = await resolveCanvasTarget(workspaceRoot, relPath, sessionId);
|
|
158
|
+
if (!target.ok) return { content: [{ type: 'text', text: target.message }], isError: true };
|
|
159
|
+
const notBrowsable = requireBrowsable(target);
|
|
160
|
+
if (notBrowsable) return { content: [{ type: 'text', text: notBrowsable }], isError: true };
|
|
161
|
+
const canvasPath = target.absPath;
|
|
162
|
+
let raw;
|
|
163
|
+
try {
|
|
164
|
+
raw = await fs.readFile(canvasPath, 'utf8');
|
|
165
|
+
} catch (err) {
|
|
166
|
+
if (err.code === 'ENOENT') {
|
|
167
|
+
return {
|
|
168
|
+
content: [{
|
|
169
|
+
type: 'text',
|
|
170
|
+
text: 'That deck file does not exist yet. Use Write to create it first '
|
|
171
|
+
+ '(see SKILL.md for the section data-page="N" structure).',
|
|
172
|
+
}],
|
|
173
|
+
isError: true,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 匹配 `<section ... data-page="<page>" ...>...</section>`
|
|
180
|
+
// 双引号 / 单引号 / 不引号都接受。section 内不嵌套 section(约定)。
|
|
181
|
+
const pageStr = String(page);
|
|
182
|
+
const escaped = pageStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
183
|
+
// 三种 attribute quoting 尝试
|
|
184
|
+
const patterns = [
|
|
185
|
+
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*"${escaped}"[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
186
|
+
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*'${escaped}'[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
187
|
+
new RegExp(`<section\\b[^>]*\\bdata-page\\s*=\\s*${escaped}\\b[^>]*>[\\s\\S]*?</section>`, 'i'),
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
let match = null;
|
|
191
|
+
for (const re of patterns) {
|
|
192
|
+
const m = raw.match(re);
|
|
193
|
+
if (m) { match = m; break; }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!match) {
|
|
197
|
+
// 列出 canvas.html 里实际有哪些 page,给 agent 反馈
|
|
198
|
+
const allPages = [...raw.matchAll(/<section\b[^>]*\bdata-page\s*=\s*['"]?(\d+)/gi)]
|
|
199
|
+
.map(m => m[1])
|
|
200
|
+
.filter((v, i, arr) => arr.indexOf(v) === i);
|
|
201
|
+
// 站点:分页读根本不适用,直说该怎么做,别丢一句"没有分页结构"让 agent
|
|
202
|
+
// 自己猜(它多半会改用 Read 全文件,把整份站点灌进上下文)
|
|
203
|
+
if (target.kind === KIND_SITE) {
|
|
204
|
+
return {
|
|
205
|
+
content: [{
|
|
206
|
+
type: 'text',
|
|
207
|
+
text: `${target.relPath} 是站点页面,没有 <section data-page="N"> 分页,read_page 的页码语义不适用。\n`
|
|
208
|
+
+ '站点这样读:先 list_pages 看站点结构(每页的标题 / 小标题 / 站内链接 / 断链),'
|
|
209
|
+
+ '要看某一页的实际内容用 query_elements 按 selector 取,或者直接 Read 那个文件(站点页面通常不大)。',
|
|
210
|
+
}],
|
|
211
|
+
isError: true,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const pagesList = allPages.length > 0
|
|
215
|
+
? `Available pages: ${allPages.join(', ')}`
|
|
216
|
+
: `${target.relPath} has no <section data-page="N"> structure.`;
|
|
217
|
+
return {
|
|
218
|
+
content: [{
|
|
219
|
+
type: 'text',
|
|
220
|
+
text: `Page ${page} not found in ${target.relPath}. ${pagesList}`,
|
|
221
|
+
}],
|
|
222
|
+
isError: true,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const sectionHtml = match[0];
|
|
227
|
+
|
|
228
|
+
// Hybrid 范式扩展:检测 babel script + section 里的 mount id
|
|
229
|
+
// 找到 mount id 后从 babel script 抓 ±20 行上下文返给 agent
|
|
230
|
+
const hybridSegments = extractReactMountSources(raw, sectionHtml);
|
|
231
|
+
|
|
232
|
+
// Thumbnail hint:section 含 assets/generated/ 图 + thumbnails 目录存在 → prepend hint
|
|
233
|
+
const thumbnailHint = await detectThumbnailHint(workspaceRoot, sectionHtml);
|
|
234
|
+
|
|
235
|
+
const parts = [];
|
|
236
|
+
if (thumbnailHint) parts.push(thumbnailHint + '\n\n');
|
|
237
|
+
parts.push(`Page ${page} (${sectionHtml.length} chars):\n\n${sectionHtml}`);
|
|
238
|
+
if (hybridSegments.length > 0) {
|
|
239
|
+
parts.push(
|
|
240
|
+
`\n\n--- React mount sources for this page (${hybridSegments.length} mount${hybridSegments.length > 1 ? 's' : ''}) ---\n`
|
|
241
|
+
+ hybridSegments.map(({ mountId, snippet, startLine }) =>
|
|
242
|
+
`\n## mount: ${mountId} (babel script line ~${startLine})\n\n\`\`\`tsx\n${snippet}\n\`\`\``
|
|
243
|
+
).join('\n')
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
content: [{
|
|
249
|
+
type: 'text',
|
|
250
|
+
text: parts.join(''),
|
|
251
|
+
}],
|
|
252
|
+
};
|
|
253
|
+
} catch (err) {
|
|
254
|
+
return {
|
|
255
|
+
content: [{
|
|
256
|
+
type: 'text',
|
|
257
|
+
text: `read_page failed: ${err?.message || String(err)}`,
|
|
258
|
+
}],
|
|
259
|
+
isError: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
}
|