@xiaobuyu/nodesign 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +140 -0
- package/bin/nodesign.js +176 -0
- package/package.json +104 -0
- package/server/api/README.md +45 -0
- package/server/api/_guard.js +75 -0
- package/server/api/admin.js +187 -0
- package/server/api/assets/docx-page.js +103 -0
- package/server/api/assets/helpers.js +22 -0
- package/server/api/assets/notes.js +144 -0
- package/server/api/assets.js +896 -0
- package/server/api/board.js +57 -0
- package/server/api/browse.js +138 -0
- package/server/api/canvas.js +444 -0
- package/server/api/chatai.js +324 -0
- package/server/api/exports/build-standalone.js +980 -0
- package/server/api/exports/cards.js +118 -0
- package/server/api/exports/docx-pdf.js +46 -0
- package/server/api/exports/export-page.js +142 -0
- package/server/api/exports/handoff.js +147 -0
- package/server/api/exports.js +690 -0
- package/server/api/instruction.js +75 -0
- package/server/api/local.js +115 -0
- package/server/api/me.js +116 -0
- package/server/api/memory.js +185 -0
- package/server/api/pending-changes.js +366 -0
- package/server/api/plugins.js +164 -0
- package/server/api/projects.js +220 -0
- package/server/api/publish.js +64 -0
- package/server/api/recent.js +73 -0
- package/server/api/sessions.js +589 -0
- package/server/api/skills.js +77 -0
- package/server/api/standalone-fit.js +168 -0
- package/server/api/turn-compose.js +180 -0
- package/server/api/turn-inflight.js +44 -0
- package/server/api/turn.js +669 -0
- package/server/auth/README.md +17 -0
- package/server/auth/middleware.js +138 -0
- package/server/auth/origin-guard.js +71 -0
- package/server/auth/session.js +108 -0
- package/server/auth/tier.js +113 -0
- package/server/auth/users-store.js +348 -0
- package/server/edit/README.md +29 -0
- package/server/engine/README.md +113 -0
- package/server/engine/agent/agent-shared.js +550 -0
- package/server/engine/agent/auto-mode-default-hard-deny.txt +4 -0
- package/server/engine/agent/auto-mode-rules.js +78 -0
- package/server/engine/agent/context.js +418 -0
- package/server/engine/agent/events.js +464 -0
- package/server/engine/agent/hooks/canvas-validate.js +199 -0
- package/server/engine/agent/hooks/failure.js +120 -0
- package/server/engine/agent/hooks/file-events.js +75 -0
- package/server/engine/agent/hooks/lifecycle.js +233 -0
- package/server/engine/agent/hooks/post-canvas-focus.js +80 -0
- package/server/engine/agent/hooks/post-guidance.js +206 -0
- package/server/engine/agent/hooks/post-subagent-report.js +104 -0
- package/server/engine/agent/hooks/post-trim.js +58 -0
- package/server/engine/agent/hooks/pre-board-neighborhood.js +34 -0
- package/server/engine/agent/hooks/pre-defaults.js +84 -0
- package/server/engine/agent/hooks/pre-injectors.js +277 -0
- package/server/engine/agent/hooks/pre-performance-log-guard.js +78 -0
- package/server/engine/agent/hooks/pre-starter-files.js +61 -0
- package/server/engine/agent/hooks/pre-workspace-scope-guard.js +78 -0
- package/server/engine/agent/hooks/site-validate.js +94 -0
- package/server/engine/agent/hooks/tool-prompts.js +31 -0
- package/server/engine/agent/hooks/turn-state-memory.js +56 -0
- package/server/engine/agent/hooks/user-prompt-submit.js +215 -0
- package/server/engine/agent/hooks.js +354 -0
- package/server/engine/agent/init-contract.js +69 -0
- package/server/engine/agent/isolation.js +159 -0
- package/server/engine/agent/model-context.js +359 -0
- package/server/engine/agent/model-table.js +292 -0
- package/server/engine/agent/plugin-loader.js +266 -0
- package/server/engine/agent/prompts/nodesign-prelude.md +336 -0
- package/server/engine/agent/prompts/tools/ask-user-question-protocol.md +71 -0
- package/server/engine/agent/prompts/tools/direct-edit-protocol.md +98 -0
- package/server/engine/agent/prompts/tools/generate-image-cookbook.gemini-gateway.md +583 -0
- package/server/engine/agent/prompts/tools/generate-image-cookbook.md +483 -0
- package/server/engine/agent/prompts/tools/hybrid-reference.md +100 -0
- package/server/engine/agent/prompts/tools/paint-still-cookbook.md +270 -0
- package/server/engine/agent/prompts/tools/roll-film-cookbook.md +70 -0
- package/server/engine/agent/prompts/tools/site-reference.md +106 -0
- package/server/engine/agent/prompts/tools/tweaks-syntax.md +125 -0
- package/server/engine/agent/prompts/tools/vision-checker-dispatch.md +48 -0
- package/server/engine/agent/session-loop.js +1024 -0
- package/server/engine/agent/session-model.js +164 -0
- package/server/engine/agent/skill.js +204 -0
- package/server/engine/agent/system-prompts.js +86 -0
- package/server/engine/agent/task-events.js +78 -0
- package/server/engine/agents/ds-extractor.md +132 -0
- package/server/engine/agents/explorer.md +190 -0
- package/server/engine/agents/index.js +230 -0
- package/server/engine/agents/schemas/design-system.json +156 -0
- package/server/engine/agents/schemas/tweak-schema.json +113 -0
- package/server/engine/agents/tweak-proposer.md +127 -0
- package/server/engine/agents/vision-checker.md +254 -0
- package/server/engine/browse/capture.js +422 -0
- package/server/engine/browse/card.js +137 -0
- package/server/engine/browse/handover.js +59 -0
- package/server/engine/browse/page-digest.js +119 -0
- package/server/engine/browse/refs.js +196 -0
- package/server/engine/browse/registry.js +307 -0
- package/server/engine/browse/screencast.js +170 -0
- package/server/engine/browse/state.js +121 -0
- package/server/engine/chatai/chat-log.js +79 -0
- package/server/engine/chatai/index.js +193 -0
- package/server/engine/chatai/openai-compat.js +152 -0
- package/server/engine/chatai/orchestrate.js +309 -0
- package/server/engine/chatai/perform.js +40 -0
- package/server/engine/chatai/summarize.js +79 -0
- package/server/engine/mcp/capability-gate.js +52 -0
- package/server/engine/mcp/index.js +339 -0
- package/server/engine/mcp/param-sanitizer.js +142 -0
- package/server/engine/mcp/tools/arrange-on-board.js +124 -0
- package/server/engine/mcp/tools/artifact-session.js +278 -0
- package/server/engine/mcp/tools/browse-computer.js +421 -0
- package/server/engine/mcp/tools/browse-find-batch.js +183 -0
- package/server/engine/mcp/tools/browse-screenshot.js +157 -0
- package/server/engine/mcp/tools/browse.js +480 -0
- package/server/engine/mcp/tools/build-docx.js +101 -0
- package/server/engine/mcp/tools/clear-pending-changes.js +99 -0
- package/server/engine/mcp/tools/create-on-board.js +155 -0
- package/server/engine/mcp/tools/crystallize-skill.js +168 -0
- package/server/engine/mcp/tools/deliver-files.js +0 -0
- package/server/engine/mcp/tools/explain-style.js +237 -0
- package/server/engine/mcp/tools/export-handoff.js +133 -0
- package/server/engine/mcp/tools/expose-tweaks.js +149 -0
- package/server/engine/mcp/tools/generate-image.js +842 -0
- package/server/engine/mcp/tools/get-computed-styles.js +164 -0
- package/server/engine/mcp/tools/get-pending-changes.js +205 -0
- package/server/engine/mcp/tools/h3box-ssh.js +84 -0
- package/server/engine/mcp/tools/helpers/acquire-page.js +82 -0
- package/server/engine/mcp/tools/helpers/motion-lab.js +554 -0
- package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -0
- package/server/engine/mcp/tools/helpers/perception-page.js +215 -0
- package/server/engine/mcp/tools/helpers/reference-download.js +103 -0
- package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -0
- package/server/engine/mcp/tools/helpers/rembg.js +273 -0
- package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -0
- package/server/engine/mcp/tools/highlight.js +68 -0
- package/server/engine/mcp/tools/list-pages.js +222 -0
- package/server/engine/mcp/tools/lookup-tags.js +59 -0
- package/server/engine/mcp/tools/navigate-to-page.js +60 -0
- package/server/engine/mcp/tools/organize-board.js +64 -0
- package/server/engine/mcp/tools/paint-still.js +434 -0
- package/server/engine/mcp/tools/pin-to-board.js +130 -0
- package/server/engine/mcp/tools/preview-deck.js +130 -0
- package/server/engine/mcp/tools/profile-scroll.js +305 -0
- package/server/engine/mcp/tools/publish-site.js +102 -0
- package/server/engine/mcp/tools/query-elements.js +195 -0
- package/server/engine/mcp/tools/read-board.js +103 -0
- package/server/engine/mcp/tools/read-document.js +93 -0
- package/server/engine/mcp/tools/read-page.js +264 -0
- package/server/engine/mcp/tools/read-tavern-json.js +143 -0
- package/server/engine/mcp/tools/record-decision.js +140 -0
- package/server/engine/mcp/tools/relate-on-board.js +110 -0
- package/server/engine/mcp/tools/remove-background.js +391 -0
- package/server/engine/mcp/tools/report-issue.js +115 -0
- package/server/engine/mcp/tools/roll-film.js +266 -0
- package/server/engine/mcp/tools/screenshot-docx.js +138 -0
- package/server/engine/mcp/tools/screenshot-url.js +195 -0
- package/server/engine/mcp/tools/screenshot.js +583 -0
- package/server/engine/mcp/tools/tier-gate.js +96 -0
- package/server/engine/mcp/tools/trace-motion.js +215 -0
- package/server/engine/mcp/tools/web-search.js +548 -0
- package/server/engine/motion/inventory.js +349 -0
- package/server/engine/perception/session.js +235 -0
- package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +192 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -0
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -0
- package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +162 -0
- package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -0
- package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -0
- package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +228 -0
- package/server/engine/plugins/nodesign/skills/rp-craft/patterns//346/274/224/345/207/272/351/241/265-/346/234/200/345/260/217/345/256/236/347/216/260.html +78 -0
- package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -0
- package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +323 -0
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -0
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -0
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -0
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -0
- package/server/engine/runs/active-runs.js +698 -0
- package/server/engine/runs/live-turn.js +252 -0
- package/server/engine/runs/store.js +364 -0
- package/server/engine/runs/turn-relay.js +217 -0
- package/server/engine/runtime/workspace.js +164 -0
- package/server/index.js +235 -0
- package/server/lib/artifact-file-path.js +80 -0
- package/server/lib/artifact-target.js +284 -0
- package/server/lib/asset-refs.js +239 -0
- package/server/lib/async-queue.js +104 -0
- package/server/lib/auto-relations.js +130 -0
- package/server/lib/binding-types.js +60 -0
- package/server/lib/board-kind-sizes.js +62 -0
- package/server/lib/board-relations.js +133 -0
- package/server/lib/browse-proxy.js +180 -0
- package/server/lib/canvas-id.js +36 -0
- package/server/lib/cover.js +227 -0
- package/server/lib/danbooru-tags.js +291 -0
- package/server/lib/doc-extract.js +156 -0
- package/server/lib/docx/build-from-source.js +260 -0
- package/server/lib/docx/build.js +490 -0
- package/server/lib/docx/dump-styles.js +287 -0
- package/server/lib/docx/fonts/nodesign-cjk.conf +164 -0
- package/server/lib/docx/merge-runs.js +129 -0
- package/server/lib/docx/numbering.js +218 -0
- package/server/lib/docx/order.js +152 -0
- package/server/lib/docx/rawzip.js +172 -0
- package/server/lib/docx/render.js +92 -0
- package/server/lib/docx/text-lint.js +225 -0
- package/server/lib/docx/tokens.js +335 -0
- package/server/lib/docx/units.js +29 -0
- package/server/lib/docx/xml.js +291 -0
- package/server/lib/docx-pages.js +187 -0
- package/server/lib/export-collect.js +289 -0
- package/server/lib/export-package.js +210 -0
- package/server/lib/html-srcset.js +145 -0
- package/server/lib/image-variant.js +460 -0
- package/server/lib/ingress/forward-openai-chat.js +305 -0
- package/server/lib/ingress/openai-chat.js +491 -0
- package/server/lib/ingress/session-notice.js +66 -0
- package/server/lib/ingress/session-routes.js +68 -0
- package/server/lib/ingress/slot-probe.js +130 -0
- package/server/lib/ingress/upstream-billing.js +52 -0
- package/server/lib/ingress/upstream-fail-streak.js +72 -0
- package/server/lib/ingress/upstream-truncation.js +48 -0
- package/server/lib/issues-store.js +182 -0
- package/server/lib/kinds/deck.js +72 -0
- package/server/lib/kinds/docx.js +283 -0
- package/server/lib/kinds/file-kinds.js +113 -0
- package/server/lib/kinds/index.js +202 -0
- package/server/lib/kinds/site.js +161 -0
- package/server/lib/model-ingress.js +543 -0
- package/server/lib/moderation.js +255 -0
- package/server/lib/notice-store.js +103 -0
- package/server/lib/plugin-install.js +104 -0
- package/server/lib/plugin-validator.js +721 -0
- package/server/lib/publish-store.js +115 -0
- package/server/lib/quick-summary.js +52 -0
- package/server/lib/quota.js +270 -0
- package/server/lib/rate-window.js +29 -0
- package/server/lib/reference-assets.js +92 -0
- package/server/lib/region-shot.js +135 -0
- package/server/lib/safe-path.js +73 -0
- package/server/lib/sdk-session.js +33 -0
- package/server/lib/showcase-store.js +92 -0
- package/server/lib/site-publish.js +465 -0
- package/server/lib/ssrf-guard.js +432 -0
- package/server/lib/task-scan.js +158 -0
- package/server/lib/tavern-json.js +154 -0
- package/server/lib/video-variant.js +237 -0
- package/server/lib/workspace-path.js +33 -0
- package/server/ops/fix-sdk-musl.mjs +40 -0
- package/server/ops/install-macos-fonts.sh +114 -0
- package/server/ops/macos-fonts.conf +336 -0
- package/server/ops/sandbox-shim/bwrap +57 -0
- package/server/projects/assets-summary.js +119 -0
- package/server/projects/auto-name.js +53 -0
- package/server/projects/board-store.js +640 -0
- package/server/projects/move-entry.js +103 -0
- package/server/projects/store.js +270 -0
- package/server/projects/ui-config.js +54 -0
- package/server/projects/workspace-templates.js +53 -0
- package/server/projects/workspace.js +1025 -0
- package/server/runtime/capabilities.js +153 -0
- package/server/runtime/local-config.js +177 -0
- package/server/runtime/local-env.js +88 -0
- package/server/runtime/platform.js +342 -0
- package/server/runtime/profile.js +72 -0
- package/server/services/rembg-launcher.js +313 -0
- package/server/services/rembg-service.py +334 -0
- package/server/shared/README.md +25 -0
- package/server/shared/deck.js +54 -0
- package/server/shared/time.js +49 -0
- package/server/style-pipeline/README.md +53 -0
- package/server/ws/broker.js +36 -0
- package/server/ws/browse-channel.js +177 -0
- package/server/ws/index.js +386 -0
- package/web/README.md +89 -0
- package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +11 -0
- package/web/dist/assets/DeckWindow-4G0xX7P3.js +16 -0
- package/web/dist/assets/DocxWindow-BXQsoPkh.js +16 -0
- package/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/web/dist/assets/SiteWindow-D6eS-2gM.js +18 -0
- package/web/dist/assets/again-D8tfgKKO.webp +0 -0
- package/web/dist/assets/caveat-nd-CP6HlsNg.woff2 +0 -0
- package/web/dist/assets/clock-xJhvfYpS.webp +0 -0
- package/web/dist/assets/film-cut-BBKMwH7q.webp +0 -0
- package/web/dist/assets/film-still-BZ_DL9Tt.webp +0 -0
- package/web/dist/assets/index-C0KUf6Wd.css +1 -0
- package/web/dist/assets/index-Cbl3ATvp.js +2125 -0
- package/web/dist/assets/ink-desk-BRbxeDsR.webp +0 -0
- package/web/dist/assets/ink-night-Bz4BT3XH.webp +0 -0
- package/web/dist/assets/ink-portrait-C0DM4V8Q.webp +0 -0
- package/web/dist/assets/longcang-regular-C0uvTuKa.woff2 +0 -0
- package/web/dist/assets/lxgw-nd-bold-DbRfiTgo.woff2 +0 -0
- package/web/dist/assets/lxgw-nd-regular-CpMw9Ehg.woff2 +0 -0
- package/web/dist/assets/pending-edit-apply-DTjo2geW.js +31 -0
- package/web/dist/assets/question-8H4HSqxh.webp +0 -0
- package/web/dist/assets/reject-BaPJqElj.webp +0 -0
- package/web/dist/assets/rotate-cw-LMT3x1Zj.js +11 -0
- package/web/dist/assets/rp-portrait-CbrGpew2.webp +0 -0
- package/web/dist/assets/rp-street-C4jVKjxx.webp +0 -0
- package/web/dist/assets/square-dashed-mouse-pointer-CBoAkfhi.js +11 -0
- package/web/dist/assets/tangle-DIxHVNuT.webp +0 -0
- package/web/dist/assets/thisone-BylZKglV.webp +0 -0
- package/web/dist/assets/thumb-DO1wfK1I.webp +0 -0
- package/web/dist/index.html +18 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/get-computed-styles.js — get_computed_styles MCP tool
|
|
3
|
+
*
|
|
4
|
+
* 拿一组元素在 canvas.html 真实渲染后的 computed style(不是 inline 也不是
|
|
5
|
+
* CSS 文件里的 raw 值)—— agent 不用猜"用户看到的字号实际是多少 px",直接调。
|
|
6
|
+
*
|
|
7
|
+
* 典型场景:
|
|
8
|
+
* - "把 H1 字号缩小一点" → 先拿当前 H1 是多少 px 再决定改多少
|
|
9
|
+
* - "对比度够不够" → 拿 color 和 background-color 算对比度
|
|
10
|
+
*
|
|
11
|
+
* 默认拿一组常用样式属性(color/fontSize/fontFamily/...);agent 可以传
|
|
12
|
+
* props 数组只拿需要的(省 token)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import fs from 'node:fs/promises';
|
|
17
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { degradedNote } from './helpers/perception-page.js';
|
|
20
|
+
import { acquireArtifactPage, LIVE_PARAM_DESC } from './helpers/acquire-page.js';
|
|
21
|
+
import { resolveDeckSize, extractDeckAspect } from '../../../shared/deck.js';
|
|
22
|
+
import { resolveCanvasTarget, CANVAS_PATH_DESC, KIND_SITE, requireBrowsable,
|
|
23
|
+
} from '../../../lib/artifact-target.js';
|
|
24
|
+
|
|
25
|
+
const DEFAULT_PROPS = [
|
|
26
|
+
'color', 'backgroundColor',
|
|
27
|
+
'fontSize', 'fontFamily', 'fontWeight', 'lineHeight', 'letterSpacing',
|
|
28
|
+
'textAlign', 'textTransform',
|
|
29
|
+
'padding', 'margin',
|
|
30
|
+
'borderRadius', 'borderWidth', 'borderColor',
|
|
31
|
+
'display', 'width', 'height',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const MAX_RESULTS = 30;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} deps
|
|
38
|
+
* @param {string} deps.workspaceRoot
|
|
39
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
40
|
+
*/
|
|
41
|
+
export function makeGetComputedStylesTool({ workspaceRoot, projectId, sessionId, ctx: _ctx }) {
|
|
42
|
+
return tool(
|
|
43
|
+
'get_computed_styles',
|
|
44
|
+
`Get the actual rendered computed styles for elements matching a CSS
|
|
45
|
+
selector in your artifact page (site page / deck). Returns the post-CSS-cascade values (px / rgb()
|
|
46
|
+
form), not raw stylesheet declarations.
|
|
47
|
+
|
|
48
|
+
Use when:
|
|
49
|
+
- Before changing a style property, check the current value (don't guess)
|
|
50
|
+
- Verifying contrast ratios (need both color and backgroundColor)
|
|
51
|
+
- Debugging why a layout looks wrong
|
|
52
|
+
|
|
53
|
+
By default returns a generic style set; pass \`props\` to restrict to just
|
|
54
|
+
the properties you care about (saves tokens).
|
|
55
|
+
|
|
56
|
+
Returns up to 30 elements.`,
|
|
57
|
+
{
|
|
58
|
+
selector: z.string().min(1).describe('CSS selector to inspect. Plain CSS only — no playwright syntax (:has-text, >>, nth=), ASCII quotes not HTML entities (" breaks the parse)'),
|
|
59
|
+
props: z
|
|
60
|
+
.array(z.string())
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('Optional: subset of CSS properties to read (camelCase, e.g. ["color","fontSize"]). Default: a generic set.'),
|
|
63
|
+
page: z
|
|
64
|
+
.number()
|
|
65
|
+
.int()
|
|
66
|
+
.min(1)
|
|
67
|
+
.optional()
|
|
68
|
+
.describe('Optional: scope to a specific page (prepends section[data-page="N"])'),
|
|
69
|
+
path: z.string().optional().describe(CANVAS_PATH_DESC),
|
|
70
|
+
live: z.boolean().optional().describe(LIVE_PARAM_DESC),
|
|
71
|
+
},
|
|
72
|
+
async ({ selector, props, page: pageIndex, path: relPath, live }) => {
|
|
73
|
+
if (!workspaceRoot) {
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: 'text', text: 'No workspace bound; cannot read computed styles.' }],
|
|
76
|
+
isError: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const target = await resolveCanvasTarget(workspaceRoot, relPath, sessionId);
|
|
80
|
+
if (!target.ok) return { content: [{ type: 'text', text: target.message }], isError: true };
|
|
81
|
+
const notBrowsable = requireBrowsable(target);
|
|
82
|
+
if (notBrowsable) return { content: [{ type: 'text', text: notBrowsable }], isError: true };
|
|
83
|
+
const canvasPath = target.absPath;
|
|
84
|
+
let html;
|
|
85
|
+
try {
|
|
86
|
+
html = await fs.readFile(canvasPath, 'utf8');
|
|
87
|
+
} catch {
|
|
88
|
+
return { content: [{ type: 'text', text: `${target.relPath} not found in workspace.` }], isError: true };
|
|
89
|
+
}
|
|
90
|
+
// 站点没有 deck 比例:extractDeckAspect 找不到 __nd-deck-wrap 会静默回落到
|
|
91
|
+
// 16:9,于是按 1920x1080 量出来的盒子被当成真实布局报给 agent。站点按桌面档
|
|
92
|
+
// 1440 量,跟 screenshot_canvas 的 desktop 档一致。
|
|
93
|
+
const dims = target.kind === KIND_SITE
|
|
94
|
+
? { width: 1440, height: 900 }
|
|
95
|
+
: resolveDeckSize(extractDeckAspect(html));
|
|
96
|
+
|
|
97
|
+
const finalSelector = pageIndex
|
|
98
|
+
? `section[data-page="${pageIndex}"] ${selector}`
|
|
99
|
+
: selector;
|
|
100
|
+
const finalProps = (Array.isArray(props) && props.length > 0) ? props : DEFAULT_PROPS;
|
|
101
|
+
|
|
102
|
+
let acq;
|
|
103
|
+
try {
|
|
104
|
+
// 页面从统一口拿(helpers/acquire-page.js):live:true = 会话里现在这一页;否则新开走 http
|
|
105
|
+
acq = await acquireArtifactPage({ projectId, workspaceRoot, target, live, viewport: { width: dims.width, height: dims.height } });
|
|
106
|
+
const page = acq.page;
|
|
107
|
+
const opened = acq;
|
|
108
|
+
|
|
109
|
+
const result = await page.evaluate(({ sel, p, max }) => {
|
|
110
|
+
const els = Array.from(document.querySelectorAll(sel));
|
|
111
|
+
const total = els.length;
|
|
112
|
+
const slice = els.slice(0, max);
|
|
113
|
+
const items = slice.map((el) => {
|
|
114
|
+
const cs = getComputedStyle(el);
|
|
115
|
+
const styles = {};
|
|
116
|
+
for (const prop of p) {
|
|
117
|
+
try {
|
|
118
|
+
styles[prop] = cs[prop];
|
|
119
|
+
} catch {
|
|
120
|
+
styles[prop] = null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
tag: el.tagName.toLowerCase(),
|
|
125
|
+
dataAnchor: el.getAttribute('data-anchor') || null,
|
|
126
|
+
text: (el.textContent || '').trim().slice(0, 80),
|
|
127
|
+
computed: styles,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
return { items, total };
|
|
131
|
+
}, { sel: finalSelector, p: finalProps, max: MAX_RESULTS });
|
|
132
|
+
|
|
133
|
+
if (result.total === 0) {
|
|
134
|
+
return {
|
|
135
|
+
content: [{
|
|
136
|
+
type: 'text',
|
|
137
|
+
text: `No elements match selector: ${finalSelector}`,
|
|
138
|
+
}],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const truncatedNote = result.total > MAX_RESULTS
|
|
143
|
+
? ` (showing first ${MAX_RESULTS} of ${result.total})`
|
|
144
|
+
: '';
|
|
145
|
+
|
|
146
|
+
const degraded = degradedNote(opened); // 契约:note 非空必须写进返回文本
|
|
147
|
+
return {
|
|
148
|
+
content: [{
|
|
149
|
+
type: 'text',
|
|
150
|
+
text: `${degraded ? `${degraded}\n\n` : ''}${acq.liveNote ? `${acq.liveNote}\n\n` : ''}Computed styles for ${result.total} element(s)${truncatedNote}:`
|
|
151
|
+
+ `\n\n${JSON.stringify(result.items, null, 2)}`,
|
|
152
|
+
}],
|
|
153
|
+
};
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return {
|
|
156
|
+
content: [{ type: 'text', text: `get_computed_styles failed: ${err?.message || String(err)}` }],
|
|
157
|
+
isError: true,
|
|
158
|
+
};
|
|
159
|
+
} finally {
|
|
160
|
+
await acq?.release?.(); // 一次性:关浏览器;live:松会话锁
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* helpers/acquire-page.js — 感知工具拿到"那一页"的唯一出口(2026-08-21)
|
|
3
|
+
*
|
|
4
|
+
* 两条路一个形状:
|
|
5
|
+
* - `live: true` → 产物会话里**现在这一页**(engine/perception/session.js),
|
|
6
|
+
* 状态保留,用完不关,只松锁
|
|
7
|
+
* - 否则 → 新开一只保真 chromium,openArtifactPage,goto,用完关 —— 可复现
|
|
8
|
+
*
|
|
9
|
+
* 老工具以前各自抄 launch→open→goto→close(七份),"没走成 http 要把 note 写进返回"
|
|
10
|
+
* 那条契约也是各自记各自漏。现在 goto 的超时容忍、退化 note、viaHttp 都在这一处出。
|
|
11
|
+
*
|
|
12
|
+
* 返回:{ page, live, viewport, note, viaHttp, gotoNote, liveNote, release() }
|
|
13
|
+
* - note 非空 = 没走成 http(退回 file://),调用方照旧用 degradedNote(acq) 拼进返回文本
|
|
14
|
+
* - gotoNote 非空 = load/networkidle 没等到(照样继续,caption 要说)
|
|
15
|
+
* - liveNote live 模式下告诉 agent:视口/设备参数被忽略、会话视口是多少
|
|
16
|
+
* - release **必须在 finally 里调**:一次性模式关浏览器,live 模式松会话锁
|
|
17
|
+
*/
|
|
18
|
+
import { openArtifactPage, launchPerceptionBrowser } from './perception-page.js';
|
|
19
|
+
import { lockSession } from '../../../perception/session.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} o
|
|
23
|
+
* @param {string} o.projectId
|
|
24
|
+
* @param {string} o.workspaceRoot
|
|
25
|
+
* @param {{absPath:string, relPath:string}} o.target resolveCanvasTarget 的结果
|
|
26
|
+
* @param {{width:number,height:number}} [o.viewport] 一次性模式用;live 模式忽略
|
|
27
|
+
* @param {number} [o.deviceScaleFactor] 一次性模式用
|
|
28
|
+
* @param {boolean} [o.live]
|
|
29
|
+
* @param {string} [o.waitUntil] 默认 networkidle(老工具的口径)
|
|
30
|
+
* @param {number} [o.timeout]
|
|
31
|
+
*/
|
|
32
|
+
export async function acquireArtifactPage({
|
|
33
|
+
projectId, workspaceRoot, target, viewport, deviceScaleFactor = 1, live = false,
|
|
34
|
+
waitUntil = 'networkidle', timeout = 15000,
|
|
35
|
+
}) {
|
|
36
|
+
if (live) {
|
|
37
|
+
const { entry, release } = await lockSession(projectId);
|
|
38
|
+
if (target?.absPath && entry.target.absPath !== target.absPath) {
|
|
39
|
+
release();
|
|
40
|
+
throw new Error(`The live session is on ${entry.target.relPath}, not ${target.relPath}. `
|
|
41
|
+
+ 'Either omit path (to inspect the live page), artifact_open that file first, or drop live:true.');
|
|
42
|
+
}
|
|
43
|
+
const vp = entry.viewport;
|
|
44
|
+
// 会话里可能已经站内导航过(index → about),报现在的页,不报当初开的那个
|
|
45
|
+
let now = entry.target.relPath;
|
|
46
|
+
try {
|
|
47
|
+
const u = new URL(entry.page.url());
|
|
48
|
+
if (/\/artifact-file\//.test(u.pathname)) now = decodeURIComponent(u.pathname.replace(/^.*\/artifact-file\//, ''));
|
|
49
|
+
} catch { /* */ }
|
|
50
|
+
const liveNote = `live session page (now at ${now}, viewport ${vp.width}x${vp.height} — current interaction state, `
|
|
51
|
+
+ 'not a fresh load; viewport/device params are ignored here)';
|
|
52
|
+
return {
|
|
53
|
+
page: entry.page, live: true, viewport: vp, note: entry.note, viaHttp: entry.viaHttp,
|
|
54
|
+
gotoNote: null, liveNote, release: async () => release(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const browser = await launchPerceptionBrowser();
|
|
59
|
+
try {
|
|
60
|
+
const opened = await openArtifactPage(browser, {
|
|
61
|
+
projectId, workspaceRoot, absPath: target.absPath, viewport, deviceScaleFactor, waitUntil, timeout,
|
|
62
|
+
});
|
|
63
|
+
let gotoNote = null;
|
|
64
|
+
try { await opened.goto(); } catch (err) {
|
|
65
|
+
if (!/Timeout/i.test(String(err?.message))) throw err;
|
|
66
|
+
gotoNote = `${waitUntil} not reached in ${Math.round(timeout / 1000)}s (slow/looping network activity) — captured anyway`;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
page: opened.page, live: false, viewport, note: opened.note, viaHttp: opened.viaHttp,
|
|
70
|
+
gotoNote, liveNote: null,
|
|
71
|
+
release: async () => { try { await browser.close(); } catch { /* */ } },
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
try { await browser.close(); } catch { /* */ }
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** live 参数的统一说明文字(五个工具共用一句,别各说各的) */
|
|
80
|
+
export const LIVE_PARAM_DESC = 'Inspect the page currently open in the artifact session (artifact_open) — its present '
|
|
81
|
+
+ 'interaction state (opened menus, typed input, game state) instead of a fresh load. Viewport/device params '
|
|
82
|
+
+ 'are ignored in live mode (the session has its own). Default false = fresh reproducible load.';
|