@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,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse 首调注入族 —— 各工具的 reference 文档 / 起手提醒,agent 首次调
|
|
3
|
+
* 对应工具时才进 context(不放系统 prompt 恒驻,每 turn 拖累)。
|
|
4
|
+
* (2026-08-14 可维护性行动:从 hooks.js 原样迁出,语义零改动)
|
|
5
|
+
*
|
|
6
|
+
* 共同模式:closure 里一个 alreadyInjected 布尔(或 per-kind Set),每 session
|
|
7
|
+
* 只注一次;permissionDecision='allow' 不阻塞工具。
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { toWorkspaceRel } from '../../../lib/workspace-path.js';
|
|
11
|
+
import { kindOfPath, kindDef, KIND_DECK } from '../../../lib/artifact-target.js';
|
|
12
|
+
import { loadToolPrompt } from './tool-prompts.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* PreToolUse(get_pending_changes) — 第一次调用时注入 DirectEdit 逐 kind
|
|
16
|
+
* 处理协议全文(字段结构 / pending-move 语义 / 邻居保护 / preDragLayout /
|
|
17
|
+
* constraint anchor 表)。prelude 常驻部分只留流程骨架 + 语义底线三条,
|
|
18
|
+
* ~90 行细则在 agent 真的要处理 pending changes 时才进 context。
|
|
19
|
+
*/
|
|
20
|
+
export function makePreToolUseGetPendingChangesProtocolInjector() {
|
|
21
|
+
let alreadyInjected = false;
|
|
22
|
+
return async (_input, _toolUseId, _options) => {
|
|
23
|
+
if (alreadyInjected) return {};
|
|
24
|
+
alreadyInjected = true;
|
|
25
|
+
const protocol = loadToolPrompt('direct-edit-protocol');
|
|
26
|
+
return {
|
|
27
|
+
hookSpecificOutput: {
|
|
28
|
+
hookEventName: 'PreToolUse',
|
|
29
|
+
permissionDecision: 'allow',
|
|
30
|
+
additionalContext:
|
|
31
|
+
'<system-reminder>\n[DirectEdit 逐 kind 处理协议 — 首次注入]\n\n'
|
|
32
|
+
+ protocol
|
|
33
|
+
+ '\n\n本协议每 session 只注入一次,后续处理 pending changes 直接按它做。\n'
|
|
34
|
+
+ '</system-reminder>',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* PreToolUse(AskUserQuestion) — 第一次问用户时注入 NoDesign 的问法协议
|
|
42
|
+
* (何时用卡片 vs chat、schema、写选项的诀窍、preview 字段的两种形态与限制)。
|
|
43
|
+
* 常驻在 prelude 里是 1.2k tokens,但一次会话里可能一次都用不上。
|
|
44
|
+
*/
|
|
45
|
+
export function makePreToolUseAskUserQuestionProtocolInjector() {
|
|
46
|
+
let alreadyInjected = false;
|
|
47
|
+
return async (_input, _toolUseId, _options) => {
|
|
48
|
+
if (alreadyInjected) return {};
|
|
49
|
+
alreadyInjected = true;
|
|
50
|
+
const protocol = loadToolPrompt('ask-user-question-protocol');
|
|
51
|
+
return {
|
|
52
|
+
hookSpecificOutput: {
|
|
53
|
+
hookEventName: 'PreToolUse',
|
|
54
|
+
permissionDecision: 'allow',
|
|
55
|
+
additionalContext:
|
|
56
|
+
'<system-reminder>\n[AskUserQuestion 协议 — 首次注入]\n\n'
|
|
57
|
+
+ protocol
|
|
58
|
+
+ '\n\n本协议每 session 只注入一次,后续问用户直接按它写。\n'
|
|
59
|
+
+ '</system-reminder>',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* PreToolUse(Write) — 第一次写 .html 时注入该形态的技术参考。
|
|
67
|
+
*
|
|
68
|
+
* 2026-07-28 加站点后按 kind 分流:以前是"任何 .html 都注入 hybrid deck 参考",
|
|
69
|
+
* 于是 agent 写站点首页时会被塞一份讲 `data-page` / `__nd-deck-wrap` / babel 的
|
|
70
|
+
* 文档 —— 文不对题,还会诱导它往站点里塞 deck 专属结构。
|
|
71
|
+
*
|
|
72
|
+
* 两种形态各注一次(一个会话理论上只做一种,但试作阶段可能先摸另一种)。
|
|
73
|
+
*/
|
|
74
|
+
export function makePreToolUseHybridReferenceInjector({ workspaceRoot } = {}) {
|
|
75
|
+
const injected = new Set();
|
|
76
|
+
return async (input, _toolUseId, _options) => {
|
|
77
|
+
const fp = input?.tool_input?.file_path;
|
|
78
|
+
if (typeof fp !== 'string') return {};
|
|
79
|
+
const rel = workspaceRoot ? toWorkspaceRel(fp, workspaceRoot) : fp;
|
|
80
|
+
const kind = workspaceRoot ? await kindOfPath(workspaceRoot, rel) : KIND_DECK;
|
|
81
|
+
// 触发条件从「写 .html」改成「写的文件跟这个形态的入口同类型」(2026-08-01)。
|
|
82
|
+
// 写死 .html 的年代只有 deck 和 site,两者入口都是 html 所以恰好没错;非 html 入口的形态
|
|
83
|
+
// 的入口不是 .html,于是它的技术参考**永远不会被注入**,agent 一辈子不知道
|
|
84
|
+
// 目录结构该长什么样。扩展名从注册表的 entryFile 推,加形态不用再回来改。
|
|
85
|
+
const wantExt = path.extname(kindDef(kind)?.entryFile || '.html').toLowerCase();
|
|
86
|
+
if (path.extname(fp).toLowerCase() !== wantExt) return {};
|
|
87
|
+
if (injected.has(kind)) return {};
|
|
88
|
+
injected.add(kind);
|
|
89
|
+
// 技术参考按注册表分发(kinds/<kind>.referenceDoc)—— 新形态自带自己那份
|
|
90
|
+
const meta = kindDef(kind)?.referenceDoc || kindDef(KIND_DECK).referenceDoc;
|
|
91
|
+
return {
|
|
92
|
+
hookSpecificOutput: {
|
|
93
|
+
hookEventName: 'PreToolUse',
|
|
94
|
+
permissionDecision: 'allow',
|
|
95
|
+
additionalContext:
|
|
96
|
+
`<system-reminder>\n[${meta.title} — 首次注入]\n\n`
|
|
97
|
+
+ loadToolPrompt(meta.file)
|
|
98
|
+
+ '\n\n本参考每 session 每形态只注入一次。\n'
|
|
99
|
+
+ '</system-reminder>',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// paint_still 首调注入本地生图手册:四模型选型 + noobai 标签流 + FLUX.2 官方
|
|
106
|
+
// 提示词实践(BFL prompting guide 摘要)+ 装卸税排序纪律。
|
|
107
|
+
export function makePreToolUsePaintStillCookbookInjector() {
|
|
108
|
+
let alreadyInjected = false;
|
|
109
|
+
return async (_input, _toolUseId, _options) => {
|
|
110
|
+
if (alreadyInjected) return {};
|
|
111
|
+
alreadyInjected = true;
|
|
112
|
+
const cookbook = loadToolPrompt('paint-still-cookbook');
|
|
113
|
+
return {
|
|
114
|
+
hookSpecificOutput: {
|
|
115
|
+
hookEventName: 'PreToolUse',
|
|
116
|
+
permissionDecision: 'allow',
|
|
117
|
+
additionalContext:
|
|
118
|
+
'<system-reminder>\n[paint_still 本地生图手册 — 首次注入]\n\n'
|
|
119
|
+
+ cookbook
|
|
120
|
+
+ '\n\n本手册每 session 只注入一次,后续调用直接照用。\n'
|
|
121
|
+
+ '</system-reminder>',
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// roll_film 首调注入 H3 提示词手册:三字段格式 + 多镜纪律(逐字角色块/同种子)
|
|
128
|
+
// + 禁视觉检查。模式与 generate_image cookbook 完全同款。
|
|
129
|
+
export function makePreToolUseRollFilmCookbookInjector() {
|
|
130
|
+
let alreadyInjected = false;
|
|
131
|
+
return async (_input, _toolUseId, _options) => {
|
|
132
|
+
if (alreadyInjected) return {};
|
|
133
|
+
alreadyInjected = true;
|
|
134
|
+
const cookbook = loadToolPrompt('roll-film-cookbook');
|
|
135
|
+
return {
|
|
136
|
+
hookSpecificOutput: {
|
|
137
|
+
hookEventName: 'PreToolUse',
|
|
138
|
+
permissionDecision: 'allow',
|
|
139
|
+
additionalContext:
|
|
140
|
+
'<system-reminder>\n[roll_film H3 提示词手册 — 首次注入]\n\n'
|
|
141
|
+
+ cookbook
|
|
142
|
+
+ '\n\n本手册每 session 只注入一次,后续调用直接照用。\n'
|
|
143
|
+
+ '</system-reminder>',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* PreToolUse(generate_image) — 第一次调用时注 完整 cookbook(A-J 段)。
|
|
151
|
+
*
|
|
152
|
+
* 配套 SKILL.md 里的精简版 cookbook(5 元素公式 + 渲文字铁律 + 反例正例)保第一张
|
|
153
|
+
* 图质量底线;本 hook 注入完整深度内容,让第二张起 agent 拿出更稳的 prompt。
|
|
154
|
+
*
|
|
155
|
+
* 触发:本 session 第 1 次调 generate_image;后续不再注入(避免 spam)。
|
|
156
|
+
* 文件源:prompts/tools/generate-image-cookbook.md(模块加载时缓存)。
|
|
157
|
+
*/
|
|
158
|
+
export function makePreToolUseGenerateImageCookbookInjector() {
|
|
159
|
+
let alreadyInjected = false;
|
|
160
|
+
return async (_input, _toolUseId, _options) => {
|
|
161
|
+
if (alreadyInjected) return {};
|
|
162
|
+
alreadyInjected = true;
|
|
163
|
+
const cookbook = loadToolPrompt('generate-image-cookbook');
|
|
164
|
+
return {
|
|
165
|
+
hookSpecificOutput: {
|
|
166
|
+
hookEventName: 'PreToolUse',
|
|
167
|
+
permissionDecision: 'allow',
|
|
168
|
+
additionalContext:
|
|
169
|
+
'<system-reminder>\n[generate_image 完整 cookbook — 首次注入]\n\n'
|
|
170
|
+
+ cookbook
|
|
171
|
+
+ '\n\n本 cookbook 每 session 只注入一次,已读完后续生图调用直接用即可。\n'
|
|
172
|
+
+ '</system-reminder>',
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* PreToolUse(generate_image) — 第一次调用时提醒 agent 先 Read 目标页面。
|
|
180
|
+
*
|
|
181
|
+
* 设计原则 metadata-not-content:不预解析 canvas.html 注入页面 HTML,
|
|
182
|
+
* 而是提醒 agent 自己 Read。避免"被注入摘要后反而不主动读"的反模式。
|
|
183
|
+
*
|
|
184
|
+
* 触发:本 session(hook 工厂调用一次 → closure 一份 alreadyReminded)内
|
|
185
|
+
* 第 1 次调用 generate_image;后续不再注入。
|
|
186
|
+
*
|
|
187
|
+
* 不阻塞工具调用,permissionDecision='allow' 直接放行。
|
|
188
|
+
*/
|
|
189
|
+
export function makePreToolUseGenerateImageReadPageReminder() {
|
|
190
|
+
let alreadyReminded = false;
|
|
191
|
+
return async (_input, _toolUseId, _options) => {
|
|
192
|
+
if (alreadyReminded) return {};
|
|
193
|
+
alreadyReminded = true;
|
|
194
|
+
return {
|
|
195
|
+
hookSpecificOutput: {
|
|
196
|
+
hookEventName: 'PreToolUse',
|
|
197
|
+
permissionDecision: 'allow',
|
|
198
|
+
additionalContext:
|
|
199
|
+
'<system-reminder>\n[generate_image 目标页提醒]\n\n'
|
|
200
|
+
+ '即将生成图片。如果还没看过目标页(deck 里对应的 <section data-page="N"> / 站点的那一页),建议先 Read 一下:\n'
|
|
201
|
+
+ ' - 页面尺寸(多少行 / 多大留给图)\n'
|
|
202
|
+
+ ' - 主色(design-tokens 里的 --bg / --accent / --hero)\n'
|
|
203
|
+
+ ' - 已有视觉风格(hybrid 范式有无 React 组件 / 已有图片调性)\n\n'
|
|
204
|
+
+ '多数情况下第一张图会被当 referenceImages 种子用于全 deck,看一眼能避免后续违和(暖色页塞冷调插图这类)。本提醒每 session 只触发一次。\n'
|
|
205
|
+
+ '</system-reminder>',
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* PreToolUse(expose_tweaks) — 第一次调用时注 完整控件 schema 语法。
|
|
213
|
+
*
|
|
214
|
+
* SKILL.md 已有"何时暴露 / 暴露什么"哲学(5-8 个核心维度即可);本 hook 注入完整
|
|
215
|
+
* 控件类型 / target_var vs target_class_on / target_scope / Tailwind 桥接 / 常坑
|
|
216
|
+
* 等参考语法,让 agent 写 controls JSON 时一次到位。
|
|
217
|
+
*
|
|
218
|
+
* 触发:本 session 第 1 次调 expose_tweaks;后续不再注入。
|
|
219
|
+
* 文件源:prompts/tools/tweaks-syntax.md(模块加载时缓存)。
|
|
220
|
+
*/
|
|
221
|
+
export function makePreToolUseExposeTweaksSyntaxInjector() {
|
|
222
|
+
let alreadyInjected = false;
|
|
223
|
+
return async (_input, _toolUseId, _options) => {
|
|
224
|
+
if (alreadyInjected) return {};
|
|
225
|
+
alreadyInjected = true;
|
|
226
|
+
const syntax = loadToolPrompt('tweaks-syntax');
|
|
227
|
+
return {
|
|
228
|
+
hookSpecificOutput: {
|
|
229
|
+
hookEventName: 'PreToolUse',
|
|
230
|
+
permissionDecision: 'allow',
|
|
231
|
+
additionalContext:
|
|
232
|
+
'<system-reminder>\n[expose_tweaks 完整语法 — 首次注入]\n\n'
|
|
233
|
+
+ syntax
|
|
234
|
+
+ '\n\n本语法每 session 只注入一次。\n'
|
|
235
|
+
+ '</system-reminder>',
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* PreToolUse(Agent) — subagent_type='vision-checker' 时首次注 派遣 prompt 模板。
|
|
243
|
+
*
|
|
244
|
+
* 注:跟 makePreToolUseAgentForceForegroundHandler 共存于同一 'Task|Agent' matcher
|
|
245
|
+
* 下,SDK 按数组顺序串行执行多个 hook。本 hook 仅在 subagent_type==='vision-checker'
|
|
246
|
+
* 命中时注 dispatch 模板(含全 deck 自检 / 有 plan 时按计划 critique / 单页评审 3 模板)。
|
|
247
|
+
*
|
|
248
|
+
* ⚠️ 2026-08-03 修:原来读的是 `input.subagent_type`,而 PreToolUse 的 hook input
|
|
249
|
+
* 形状是 `{ tool_name, tool_input, tool_use_id, ... }`(sdk.d.ts PreToolUseHookInput),
|
|
250
|
+
* 工具入参在 **tool_input** 里 —— 顶层那个字段永远是 undefined,条件永远不成立。
|
|
251
|
+
* 结果:历史上 6 次 vision-checker 派遣,模板一次都没注进去(jsonl 全量 grep 0 命中)。
|
|
252
|
+
* 同文件的 force-foreground handler 一直读的是 `input?.tool_input`,是对的,
|
|
253
|
+
* 这里当初抄漏了一层。
|
|
254
|
+
*
|
|
255
|
+
* 触发:本 session 第 1 次派 vision-checker;后续不再注入。
|
|
256
|
+
* 文件源:prompts/tools/vision-checker-dispatch.md(模块加载时缓存)。
|
|
257
|
+
*/
|
|
258
|
+
export function makePreToolUseTaskVisionCheckerDispatchInjector() {
|
|
259
|
+
let alreadyInjected = false;
|
|
260
|
+
return async (input, _toolUseId, _options) => {
|
|
261
|
+
if (alreadyInjected) return {};
|
|
262
|
+
if (input?.tool_input?.subagent_type !== 'vision-checker') return {};
|
|
263
|
+
alreadyInjected = true;
|
|
264
|
+
const dispatch = loadToolPrompt('vision-checker-dispatch');
|
|
265
|
+
return {
|
|
266
|
+
hookSpecificOutput: {
|
|
267
|
+
hookEventName: 'PreToolUse',
|
|
268
|
+
permissionDecision: 'allow',
|
|
269
|
+
additionalContext:
|
|
270
|
+
'<system-reminder>\n[vision-checker 派遣 prompt 模板 — 首次注入]\n\n'
|
|
271
|
+
+ dispatch
|
|
272
|
+
+ '\n\n本模板每 session 只注入一次。后续派遣按这套结构写 prompt 即可。\n'
|
|
273
|
+
+ '</system-reminder>',
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pre-performance-log-guard —— 演出记录的隐私闸(2026-08-15,用户拍板)。
|
|
3
|
+
*
|
|
4
|
+
* RP 台词只走 chatai 通路(中转站),**不进设计会话**:agent 线的上下文进
|
|
5
|
+
* Anthropic,用户的演出原文不该去。此闸拦 agent 对演出文件夹里对话记录/摘要的
|
|
6
|
+
* Read / Grep —— 判定证据是同目录有 `编排.yaml`。写不拦:建场要种开场白
|
|
7
|
+
* (Write 对话.jsonl 是 skill 教的正路)。
|
|
8
|
+
*
|
|
9
|
+
* ⭐ **边界写死在这儿,别再自己脑补它有多严**:只拦「路径点名那个文件」这一种
|
|
10
|
+
* 读法。`Grep path=<演出文件夹>`、Bash `cat 戏/对话.jsonl` 都过得去。
|
|
11
|
+
* 2026-08-15 补过那两条(Grep 注排除 glob + Bash 命令闸),**用户看过连带面之后
|
|
12
|
+
* 决定撤回**:改 Grep 输入会影响所有 RP 项目的每一次搜索,Bash 串匹配会误伤
|
|
13
|
+
* `git add` / `cp` 这类正当命令,而拦住的只是"顺手"——本来就不防蓄意。
|
|
14
|
+
* 撤回时留下的真教训记在 [[nodesign-rp-mode]]:判据用正则抓 `编排.yaml` 里第一个
|
|
15
|
+
* `文件:` 会把系统层条目的设定文件(`文件: 设定/叙述者.md`)当成记录名 ——
|
|
16
|
+
* 所以下面这份解析是 YAML 解析、只认 `历史.文件`。
|
|
17
|
+
*
|
|
18
|
+
* 剩下两层不在这个文件里:
|
|
19
|
+
* - 项目 `.gitignore` 里有 对话.jsonl / 摘要.json(workspace.js 的
|
|
20
|
+
* DEFAULT_GITIGNORE),而 Grep 走 ripgrep 默认跳过被 gitignore 的文件;
|
|
21
|
+
* - rp-craft skill 的隐私纪律章(让它压根不想去读)。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import path from 'node:path';
|
|
25
|
+
import fs from 'node:fs/promises';
|
|
26
|
+
import YAML from 'yaml';
|
|
27
|
+
|
|
28
|
+
const FIXED = ['对话.jsonl', '摘要.json'];
|
|
29
|
+
const CONFIG_FILE = '编排.yaml';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 一个演出文件夹认哪几个记录文件名(固定两个 + `历史.文件` 自定义的记录名)。
|
|
33
|
+
*
|
|
34
|
+
* ⚠️ 必须**解析 YAML** 而不是正则抓第一个 `文件:` —— 系统层条目的
|
|
35
|
+
* `文件: 设定/叙述者.md` 排在 `历史.文件` 前面,正则版会把用户的设定文件
|
|
36
|
+
* 当成记录名(2026-08-15 在真配置上量出来的)。
|
|
37
|
+
* 半写完的 YAML 解析失败 → 只认固定两个名,不拦别的。
|
|
38
|
+
*/
|
|
39
|
+
async function namesOfPerformanceDir(dir) {
|
|
40
|
+
let raw;
|
|
41
|
+
try { raw = await fs.readFile(path.join(dir, CONFIG_FILE), 'utf8'); } catch { return null; }
|
|
42
|
+
const names = new Set(FIXED);
|
|
43
|
+
try {
|
|
44
|
+
const doc = YAML.parse(raw);
|
|
45
|
+
const rec = doc?.历史?.文件;
|
|
46
|
+
if (typeof rec === 'string' && rec.trim()) names.add(path.basename(rec.trim()));
|
|
47
|
+
} catch { /* 写了一半的 YAML:固定两个名照旧生效 */ }
|
|
48
|
+
return names;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @returns {Promise<null | string>} null=放行;string=拒绝理由 */
|
|
52
|
+
export async function checkPerformanceLogRead(toolInput, workspaceRoot) {
|
|
53
|
+
const fp = toolInput?.file_path || toolInput?.path || '';
|
|
54
|
+
if (typeof fp !== 'string' || !fp) return null;
|
|
55
|
+
const abs = path.isAbsolute(fp) ? fp : path.resolve(workspaceRoot || '', fp);
|
|
56
|
+
const names = await namesOfPerformanceDir(path.dirname(abs));
|
|
57
|
+
if (!names) return null; // 同目录没有 编排.yaml → 不是演出文件夹
|
|
58
|
+
const base = path.basename(abs);
|
|
59
|
+
if (!names.has(base)) return null;
|
|
60
|
+
return `「${base}」是这场演出的对话记录——用户的演出原文是隐私,只走 chatai 通路,不进设计会话。`
|
|
61
|
+
+ '要推进剧情改 状态/ 里的文件(尾部条目每轮现读);用户想给你看某段戏会自己粘贴过来。';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function makePreToolUsePerformanceLogGuard({ workspaceRoot }) {
|
|
65
|
+
return async (input) => {
|
|
66
|
+
try {
|
|
67
|
+
const reason = await checkPerformanceLogRead(input?.tool_input, workspaceRoot);
|
|
68
|
+
if (!reason) return {};
|
|
69
|
+
return {
|
|
70
|
+
hookSpecificOutput: {
|
|
71
|
+
hookEventName: 'PreToolUse',
|
|
72
|
+
permissionDecision: 'deny',
|
|
73
|
+
permissionDecisionReason: reason,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
} catch { return {}; } // 闸自己出错不拦工具(fail-open)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill 起手文件拷贝族(2026-08-14 可维护性行动:从 hooks.js 原样迁出)。
|
|
3
|
+
* 2026-07-27 工作台升级起,starter 拷贝从 session-loop init 挪到 hook:
|
|
4
|
+
* session 不再默认等于 deck 任务,非 deck 会话的 cwd 不再预置 deck 模板。
|
|
5
|
+
*/
|
|
6
|
+
import { ensureSkillStarterFiles, listSkillIds, listSkillStarterFiles } from '../skill.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* PreToolUse(Skill) — agent 加载 deskskill-engine-mini 时把 skill 起手文件
|
|
10
|
+
* (canvas.template.html 等)拷进 session cwd。
|
|
11
|
+
*
|
|
12
|
+
* ensureSkillStarterFiles 幂等 + fail-soft。
|
|
13
|
+
*/
|
|
14
|
+
export function makePreToolUseSkillStarterFilesCopier({ workspaceRoot }) {
|
|
15
|
+
const done = new Set();
|
|
16
|
+
return async (input, _toolUseId, _options) => {
|
|
17
|
+
if (!workspaceRoot) return {};
|
|
18
|
+
try {
|
|
19
|
+
// 认哪个 skill 从入参里读,不再硬编码 'deskskill-engine-mini' ——
|
|
20
|
+
// 硬编码的后果是新 skill(站点)的模板永远拷不出来,而且静默。
|
|
21
|
+
const raw = JSON.stringify(input?.tool_input || {});
|
|
22
|
+
for (const id of await listSkillIds()) {
|
|
23
|
+
if (done.has(id) || !raw.includes(id)) continue;
|
|
24
|
+
done.add(id);
|
|
25
|
+
const r = await ensureSkillStarterFiles(workspaceRoot, id);
|
|
26
|
+
if (r.copied.length > 0) {
|
|
27
|
+
console.log(`[hooks] starter files copied on Skill load (${id}): ${r.copied.join(', ')}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.warn('[hooks] starter files copy on Skill load failed:', err.message);
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* PreToolUse(Bash) 兜底 —— agent 没走 Skill 加载、直接按 prelude 的
|
|
39
|
+
* "起手 cp canvas.template.html" 动手时,命令里出现模板名就现场补拷,
|
|
40
|
+
* 避免 cp 报 No such file。
|
|
41
|
+
*/
|
|
42
|
+
export function makePreToolUseBashStarterFilesFallback({ workspaceRoot }) {
|
|
43
|
+
const done = new Set();
|
|
44
|
+
return async (input, _toolUseId, _options) => {
|
|
45
|
+
if (!workspaceRoot) return {};
|
|
46
|
+
const command = String(input?.tool_input?.command || '');
|
|
47
|
+
if (!command.includes('.template.')) return {}; // 快速排除绝大多数命令
|
|
48
|
+
try {
|
|
49
|
+
for (const id of await listSkillIds()) {
|
|
50
|
+
if (done.has(id)) continue;
|
|
51
|
+
const names = await listSkillStarterFiles(id);
|
|
52
|
+
if (!names.some(n => command.includes(n))) continue;
|
|
53
|
+
done.add(id);
|
|
54
|
+
await ensureSkillStarterFiles(workspaceRoot, id);
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn('[hooks] starter files fallback copy failed:', err.message);
|
|
58
|
+
}
|
|
59
|
+
return {};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pre-workspace-scope-guard —— 结构化工具的项目边界闸(2026-08-15)
|
|
3
|
+
*
|
|
4
|
+
* 沙盒(bwrap)只管 Bash。Read / Grep / Glob / Write / Edit 是 SDK 进程内工具,
|
|
5
|
+
* 不进 bwrap —— 2026-08-15 探针实测:沙盒开着,Read 照样能读别的项目的工作区,
|
|
6
|
+
* Write 照样能往 cwd 外落文件。凭据那部分由 permissions.deny 盖住了
|
|
7
|
+
* (runtime/platform.js),**但"别人的项目"盖不住**:deny 规则没有"除了自己这个"
|
|
8
|
+
* 的写法(deny 压过 allow),而项目是动态新建的。
|
|
9
|
+
*
|
|
10
|
+
* 两条判据,读写不一样严:
|
|
11
|
+
* - **写**(Write/Edit/NotebookEdit):只准落在自己的工作区或临时目录。
|
|
12
|
+
* 写东西到别处没有任何正当理由 —— 产物都在工作区里。
|
|
13
|
+
* - **读**(Read/Grep/Glob):只拦数据根内部的越界。仓库、plugin/skill 目录、
|
|
14
|
+
* /tmp 照读不误 —— 那是干活要用的(skill 附件就在仓库里)。
|
|
15
|
+
*
|
|
16
|
+
* 边界(故意窄,别自己脑补更严):
|
|
17
|
+
* - 凭据不归它管(那是 platform.protectedPathRules 的活,两边别互相假设)。
|
|
18
|
+
* - 自己出错就放行(fail-open)—— 闸崩了不该把整个会话堵死。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
|
|
24
|
+
const TARGET_FIELDS = ['file_path', 'path', 'notebook_path'];
|
|
25
|
+
const WRITE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit', 'NotebookEdit']);
|
|
26
|
+
|
|
27
|
+
function insideDir(abs, dir) {
|
|
28
|
+
return abs === dir || abs.startsWith(dir.endsWith(path.sep) ? dir : dir + path.sep);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 临时目录(沙盒会把 TMPDIR 指到自己那份,两个都认) */
|
|
32
|
+
function tempDirs() {
|
|
33
|
+
return [process.env.TMPDIR, os.tmpdir(), '/tmp'].filter(Boolean).map(d => path.resolve(d));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @returns {null | string} null=放行;string=拒绝理由
|
|
38
|
+
*/
|
|
39
|
+
export function checkWorkspaceScope(toolInput, { workspaceRoot, dataRoot, toolName } = {}) {
|
|
40
|
+
if (!workspaceRoot) return null;
|
|
41
|
+
const ws = path.resolve(workspaceRoot);
|
|
42
|
+
const isWrite = WRITE_TOOLS.has(toolName);
|
|
43
|
+
if (!isWrite && !dataRoot) return null;
|
|
44
|
+
const root = dataRoot ? path.resolve(dataRoot) : null;
|
|
45
|
+
for (const field of TARGET_FIELDS) {
|
|
46
|
+
const v = toolInput?.[field];
|
|
47
|
+
if (typeof v !== 'string' || !v) continue;
|
|
48
|
+
const abs = path.resolve(ws, v); // 相对路径按工作区解析
|
|
49
|
+
if (insideDir(abs, ws)) continue; // 自己的工作区,放行
|
|
50
|
+
if (isWrite) {
|
|
51
|
+
if (tempDirs().some(d => insideDir(abs, d))) continue; // 临时文件随便写
|
|
52
|
+
return `${toolName} 只能落在你自己的工作区里(${ws}),或者临时目录。`
|
|
53
|
+
+ '产物、草稿、附件全都归工作区管;往外写一律拒绝。';
|
|
54
|
+
}
|
|
55
|
+
if (!root || !insideDir(abs, root)) continue; // 数据根之外的读不归这道闸管
|
|
56
|
+
return '这个路径在别的项目的工作区里,不是你这个项目的东西。'
|
|
57
|
+
+ `你的工作区是 ${ws} —— 用相对路径就好,越过它去读写别人的项目一律拒绝。`;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function makePreToolUseWorkspaceScopeGuard({ workspaceRoot, dataRoot }) {
|
|
63
|
+
return async (input) => {
|
|
64
|
+
try {
|
|
65
|
+
const reason = checkWorkspaceScope(input?.tool_input, {
|
|
66
|
+
workspaceRoot, dataRoot, toolName: input?.tool_name,
|
|
67
|
+
});
|
|
68
|
+
if (!reason) return {};
|
|
69
|
+
return {
|
|
70
|
+
hookSpecificOutput: {
|
|
71
|
+
hookEventName: 'PreToolUse',
|
|
72
|
+
permissionDecision: 'deny',
|
|
73
|
+
permissionDecisionReason: reason,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
} catch { return {}; } // 闸自己出错不拦工具(fail-open)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/site-validate.js — 站点页面的两条硬规则 lint(2026-08-21)
|
|
3
|
+
*
|
|
4
|
+
* 起手模板(site.template.html / style.template.css)08-21 删了:它把"别把预览弄坏"
|
|
5
|
+
* 的硬规则和"站长什么样"的默认审美捆在一个文件里,后者同化了一半的成品(11/28 个
|
|
6
|
+
* 站保留着模板骨架)。硬规则不能靠"注释写在模板顶上、agent 记得 Read"传播 ——
|
|
7
|
+
* 契约要配 lint。这里就是那两条:
|
|
8
|
+
*
|
|
9
|
+
* 1. `<meta name="viewport">` 缺失 → 手机端按 980px 虚拟视口渲染,媒体查询
|
|
10
|
+
* 看着"没生效"
|
|
11
|
+
* 2. 根路径 `href="/x"` / `src="/x"` → 预览走 `/api/projects/<id>/artifact-file/…`
|
|
12
|
+
* 前缀,根路径跳出前缀直接 404(发布到独立域名后反而正常,所以本地更容易漏)
|
|
13
|
+
*
|
|
14
|
+
* 实测(08-21,27 个站)两条违反都是 0 —— 模型本来就守。lint 的意义是把"本来就守"
|
|
15
|
+
* 变成"守不守都查得到",弱模型/长会话漂移时兜底。只报不改,跟 canvas-validate 同款。
|
|
16
|
+
*
|
|
17
|
+
* 只看**子目录里的 .html**(站点住自己的文件夹);工作区根上的 .html 是 deck,
|
|
18
|
+
* 不归这里(deck 有自己的 canvas-validate)。
|
|
19
|
+
*/
|
|
20
|
+
import fs from 'node:fs/promises';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
const MAX_BYTES = 2 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
const strip = (html) => String(html)
|
|
26
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
27
|
+
.replace(/<script[\s\S]*?<\/script>/gi, '')
|
|
28
|
+
.replace(/<style[\s\S]*?<\/style>/gi, '');
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 纯函数:html 文本 → 问题列表(空数组 = 干净)。
|
|
32
|
+
* @returns {Array<{title:string, detail:string}>}
|
|
33
|
+
*/
|
|
34
|
+
export function lintSiteHtml(html) {
|
|
35
|
+
const src = strip(html);
|
|
36
|
+
const issues = [];
|
|
37
|
+
if (!/<meta\s[^>]*name\s*=\s*["']viewport["']/i.test(src)) {
|
|
38
|
+
issues.push({
|
|
39
|
+
title: '缺 <meta name="viewport">',
|
|
40
|
+
detail: '没有它手机端按 980px 虚拟视口渲染,媒体查询看着"没生效"。加 <meta name="viewport" content="width=device-width, initial-scale=1">。',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// 根路径:href="/x" 或 src="/x",排除协议相对 "//cdn…";"/" 单独一个也算(回首页应写 index.html)
|
|
44
|
+
const roots = [...src.matchAll(/\b(?:href|src|action)\s*=\s*["'](\/(?!\/)[^"']*)["']/gi)].map(m => m[1]);
|
|
45
|
+
if (roots.length) {
|
|
46
|
+
const uniq = [...new Set(roots)].slice(0, 5);
|
|
47
|
+
issues.push({
|
|
48
|
+
title: `根路径链接 ${roots.length} 处(${uniq.join(' ')}${roots.length > uniq.length ? ' …' : ''})`,
|
|
49
|
+
detail: '预览和导出都走 artifact-file/<路径> 前缀,根路径会跳出前缀直接 404。站内一律相对路径:about.html / assets/x.png / ../assets/generated/x.png。',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return issues;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 相对工作区的 .html,且在子目录里(站点页)—— deck 在根上,不归这里 */
|
|
56
|
+
export function isSitePagePath(workspaceRoot, fp) {
|
|
57
|
+
if (!fp || !/\.html?$/i.test(fp)) return false;
|
|
58
|
+
const rel = path.relative(workspaceRoot, path.resolve(workspaceRoot, fp)).split(path.sep).join('/');
|
|
59
|
+
if (!rel || rel.startsWith('..') || !rel.includes('/')) return false;
|
|
60
|
+
if (/^(exports|node_modules|_drafts|\.)/.test(rel)) return false; // _drafts/ 是独立单页,不是站点页
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function makePostToolUseSiteValidationHandler({ workspaceRoot }) {
|
|
65
|
+
return async (input) => {
|
|
66
|
+
try {
|
|
67
|
+
const fp = input?.tool_input?.file_path;
|
|
68
|
+
if (!workspaceRoot || !isSitePagePath(workspaceRoot, fp)) return {};
|
|
69
|
+
const abs = path.resolve(workspaceRoot, fp);
|
|
70
|
+
let html;
|
|
71
|
+
try {
|
|
72
|
+
const st = await fs.stat(abs);
|
|
73
|
+
if (st.size > MAX_BYTES) return {};
|
|
74
|
+
html = await fs.readFile(abs, 'utf8');
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err.code === 'ENOENT') return {};
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
if (html.includes('__nd-deck-wrap')) return {}; // 收进文件夹的 deck,不是站点页
|
|
80
|
+
const issues = lintSiteHtml(html);
|
|
81
|
+
if (!issues.length) return {};
|
|
82
|
+
const body = issues.map((i, idx) => `${idx + 1}. ${i.title}\n ${i.detail}`).join('\n\n');
|
|
83
|
+
return {
|
|
84
|
+
systemMessage:
|
|
85
|
+
`<system-reminder>\n[site-validate] 你刚改完 ${fp},系统检测到 ${issues.length} 项会让预览出错的硬规则违反:\n\n`
|
|
86
|
+
+ body
|
|
87
|
+
+ '\n\n有意为之就忽略;否则下一轮先修这几处再继续。\n</system-reminder>',
|
|
88
|
+
};
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.warn('[hooks/site-validate] threw:', err.message);
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具 prompt lazy 注入文件加载(首调即缓存)。仿 agents/index.js loadPrompt 模式。
|
|
3
|
+
*
|
|
4
|
+
* 用途:cookbook / tweaks-syntax / vision-checker-dispatch 这些 reference 文档
|
|
5
|
+
* 不放系统 prompt 恒驻(每 turn 拖累),改由 PreToolUse hook 在 agent 首次调对应工具时
|
|
6
|
+
* 通过 additionalContext 注入。文件存 prompts/tools/*.md,模块加载时一次性读完缓存到 map。
|
|
7
|
+
*
|
|
8
|
+
* fail-soft:缺失 / 读失败返回 stub 字符串,hook 注入也不至于崩;console.warn 让部署
|
|
9
|
+
* 日志能立刻发现。
|
|
10
|
+
*/
|
|
11
|
+
import fsSync from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
// prompts/ 住在 agent/ 层(本模块在 agent/hooks/ 下一层,要往上跳一级)
|
|
16
|
+
const PROMPTS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'prompts', 'tools');
|
|
17
|
+
|
|
18
|
+
const TOOL_PROMPT_CACHE = {};
|
|
19
|
+
export function loadToolPrompt(name) {
|
|
20
|
+
if (TOOL_PROMPT_CACHE[name] !== undefined) return TOOL_PROMPT_CACHE[name];
|
|
21
|
+
const file = path.join(PROMPTS_DIR, `${name}.md`);
|
|
22
|
+
try {
|
|
23
|
+
TOOL_PROMPT_CACHE[name] = fsSync.readFileSync(file, 'utf8');
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.warn(`[hooks] failed to load tool prompt ${name}.md (${err.message}); using stub`);
|
|
26
|
+
TOOL_PROMPT_CACHE[name] =
|
|
27
|
+
`(tool prompt ${name}.md not found at ${file}. PreToolUse hook will skip lazy injection — `
|
|
28
|
+
+ `agent fallbacks to whatever guidance lives in SKILL.md core.)`;
|
|
29
|
+
}
|
|
30
|
+
return TOOL_PROMPT_CACHE[name];
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hooks/turn-state-memory.js — 每轮状态注入的"上一轮记忆"(2026-08-21)
|
|
3
|
+
*
|
|
4
|
+
* UserPromptSubmit 每轮把工作区状态(素材 / 产物 / 便利贴 / 关系线 / 决策 / tweaks)
|
|
5
|
+
* 注给模型。以前每轮全量,30 轮下来上下文里是十几份几乎一样的块(实测 540~1300
|
|
6
|
+
* token/轮)。现在**首轮全量、之后只报变化**:每节算一个指纹存在这里,下一轮对照。
|
|
7
|
+
*
|
|
8
|
+
* 键按 sessionId(一次对话一份记忆)。两种情况要清掉让下一轮重新全量:
|
|
9
|
+
* - 上下文压缩之后(PostCompact):旧的那份已经被摘要吞了,"同上轮"没有所指
|
|
10
|
+
* - 进程重启:Map 本来就空
|
|
11
|
+
* 上限 300 个会话,LRU 淘汰 —— 会话结束不另外清(多数会话没几轮,留着也就几百字节)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const MAX_SESSIONS = 300;
|
|
15
|
+
/** sessionId → { sections: Map<key, {hash:string, items:string[]|null}>, turns: number } */
|
|
16
|
+
const memory = new Map();
|
|
17
|
+
|
|
18
|
+
/** djb2:够用的短指纹,不引 crypto */
|
|
19
|
+
export function fingerprint(text) {
|
|
20
|
+
let h = 5381;
|
|
21
|
+
const s = String(text);
|
|
22
|
+
for (let i = 0; i < s.length; i += 1) h = ((h << 5) + h + s.charCodeAt(i)) | 0;
|
|
23
|
+
return (h >>> 0).toString(36);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getTurnMemory(sessionId) {
|
|
27
|
+
if (!sessionId) return null;
|
|
28
|
+
const m = memory.get(sessionId);
|
|
29
|
+
if (m) { memory.delete(sessionId); memory.set(sessionId, m); } // LRU 触碰
|
|
30
|
+
return m || null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function setTurnMemory(sessionId, sections) {
|
|
34
|
+
if (!sessionId) return;
|
|
35
|
+
const prev = memory.get(sessionId);
|
|
36
|
+
memory.delete(sessionId);
|
|
37
|
+
memory.set(sessionId, { sections, turns: (prev?.turns || 0) + 1 });
|
|
38
|
+
while (memory.size > MAX_SESSIONS) memory.delete(memory.keys().next().value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 压缩后 / 想强制下一轮全量时调 */
|
|
42
|
+
export function resetTurnMemory(sessionId) {
|
|
43
|
+
if (sessionId) memory.delete(sessionId);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 两个清单的差 → { added, removed }(给素材 / 便利贴这种按项报变化的节用) */
|
|
47
|
+
export function diffItems(prevItems, nextItems) {
|
|
48
|
+
const prev = new Set(prevItems || []);
|
|
49
|
+
const next = new Set(nextItems || []);
|
|
50
|
+
return {
|
|
51
|
+
added: [...next].filter(x => !prev.has(x)),
|
|
52
|
+
removed: [...prev].filter(x => !next.has(x)),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const _memory = memory; // 测试用
|