@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,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/ingress/slot-probe.js — 模型插槽体检(08-22,探针脚本转正)。
|
|
3
|
+
*
|
|
4
|
+
* 配置页「体检」按钮打的就是它:对一行 API 模型,**穿过进程内入口**(model-ingress → 转换层 → 上游)
|
|
5
|
+
* 发五发最小请求,回一张红绿表。为什么必须穿入口而不是直打上游:quirk 表按上游写(gproxy 的
|
|
6
|
+
* network_error、refusal 映射、空体 5xx),用户自带的新端点踩的坑和内置行不一样,直打上游测不出转换层
|
|
7
|
+
* 那一段;而真会话里 CLI 发的就是经过入口的请求(body.model 是剥了 [1m] 的 sdkAlias)。
|
|
8
|
+
*
|
|
9
|
+
* 五项:text(非流式)/ stream(SSE)/ tool_use(工具调用 + 入参能解析)/ vision(64×64 纯红图问颜色)/
|
|
10
|
+
* count_tokens。vision 与 count_tokens 标 info:上游不支持不算这行不能当主力,但用户该知道。
|
|
11
|
+
*
|
|
12
|
+
* 订阅行不经入口(CLI 自己的登录态),这里不探,回一条说明。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import sharp from 'sharp';
|
|
16
|
+
import { getOrStartIngress } from '../model-ingress.js';
|
|
17
|
+
import { registerIngressSession, unregisterIngressSession } from './session-routes.js';
|
|
18
|
+
import { resolveModelRoute } from '../../engine/agent/model-context.js';
|
|
19
|
+
|
|
20
|
+
const PEEK_TOOL = {
|
|
21
|
+
name: 'peek',
|
|
22
|
+
description: 'Return the secret number. Call it with a one-sentence reason.',
|
|
23
|
+
input_schema: { type: 'object', properties: { reason: { type: 'string' } }, required: ['reason'] },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async function redPng() {
|
|
27
|
+
return (await sharp({ create: { width: 64, height: 64, channels: 3, background: { r: 220, g: 20, b: 20 } } }).png().toBuffer()).toString('base64');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function parseSse(text) {
|
|
31
|
+
const events = [];
|
|
32
|
+
for (const chunk of text.split(/\n\n+/)) {
|
|
33
|
+
const line = chunk.split('\n').find((l) => l.startsWith('data:'));
|
|
34
|
+
if (!line) continue;
|
|
35
|
+
try { events.push(JSON.parse(line.slice(5).trim())); } catch { /* 非 JSON 行(ping 等)跳过 */ }
|
|
36
|
+
}
|
|
37
|
+
return events;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const textOf = (json) => (json?.content || []).filter((b) => b.type === 'text').map((b) => b.text).join('').trim();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} appModel
|
|
44
|
+
* @param {{ timeoutMs?: number, vision?: boolean }} [opts]
|
|
45
|
+
* @returns {Promise<{ appModel: string, mode: 'api'|'subscription', checks: Array<{ id, label, ok: boolean|null, level: 'core'|'info', ms: number, note: string }> }>}
|
|
46
|
+
*/
|
|
47
|
+
export async function probeModel(appModel, { timeoutMs = 45_000, vision = true } = {}) {
|
|
48
|
+
const route = resolveModelRoute(appModel);
|
|
49
|
+
if (route.mode !== 'api') {
|
|
50
|
+
return { appModel, mode: 'subscription', checks: [{ id: 'subscription', label: '订阅/直连行', ok: null, level: 'info', ms: 0,
|
|
51
|
+
note: '这一行由 Claude Code 自己的登录态或 ANTHROPIC_API_KEY 驱动,不经入口,这里不探;开个项目发一句话就能验' }] };
|
|
52
|
+
}
|
|
53
|
+
const ingress = await getOrStartIngress();
|
|
54
|
+
const tag = `probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
55
|
+
registerIngressSession(tag, appModel);
|
|
56
|
+
const model = route.sdkAlias.replace(/\[1m\]$/i, ''); // CLI 序列化时剥 [1m],体检照它发
|
|
57
|
+
const base = `${ingress.baseUrl}/__nd/${encodeURIComponent(tag)}`;
|
|
58
|
+
const checks = [];
|
|
59
|
+
|
|
60
|
+
async function post(path, body) {
|
|
61
|
+
const ac = new AbortController();
|
|
62
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
63
|
+
const t0 = Date.now();
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(base + path, {
|
|
66
|
+
method: 'POST', signal: ac.signal,
|
|
67
|
+
headers: { 'content-type': 'application/json', 'x-api-key': 'nd-ingress-managed', 'anthropic-version': '2023-06-01' },
|
|
68
|
+
body: JSON.stringify({ model, ...body }),
|
|
69
|
+
});
|
|
70
|
+
const text = await res.text();
|
|
71
|
+
let json = null; try { json = JSON.parse(text); } catch { /* SSE 或非 JSON */ }
|
|
72
|
+
return { status: res.status, text, json, ms: Date.now() - t0 };
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return { status: 0, text: '', json: null, ms: Date.now() - t0, error: err.name === 'AbortError' ? `超时 ${timeoutMs / 1000}s` : err.message };
|
|
75
|
+
} finally { clearTimeout(timer); }
|
|
76
|
+
}
|
|
77
|
+
const errNote = (r) => r.error || `HTTP ${r.status}${r.text ? `:${r.text.slice(0, 160)}` : ''}`;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
// 1 text
|
|
81
|
+
{
|
|
82
|
+
const r = await post('/v1/messages', { max_tokens: 32, messages: [{ role: 'user', content: 'Reply with exactly the word pong and nothing else.' }] });
|
|
83
|
+
const ok = r.status === 200 && !!textOf(r.json);
|
|
84
|
+
checks.push({ id: 'text', label: '非流式文本', ok, level: 'core', ms: r.ms,
|
|
85
|
+
note: ok ? `答「${textOf(r.json).slice(0, 40)}」 stop=${r.json.stop_reason} in/out=${r.json.usage?.input_tokens ?? '?'}/${r.json.usage?.output_tokens ?? '?'}` : errNote(r) });
|
|
86
|
+
}
|
|
87
|
+
// 2 stream
|
|
88
|
+
{
|
|
89
|
+
const r = await post('/v1/messages', { max_tokens: 32, stream: true, messages: [{ role: 'user', content: 'Reply with exactly the word pong and nothing else.' }] });
|
|
90
|
+
const ev = r.status === 200 ? parseSse(r.text) : [];
|
|
91
|
+
const types = new Set(ev.map((e) => e.type));
|
|
92
|
+
const delta = ev.filter((e) => e.type === 'content_block_delta' && e.delta?.type === 'text_delta').map((e) => e.delta.text).join('');
|
|
93
|
+
const ok = r.status === 200 && types.has('message_start') && types.has('message_stop') && !!delta.trim();
|
|
94
|
+
const errEv = ev.find((e) => e.type === 'error');
|
|
95
|
+
checks.push({ id: 'stream', label: '流式(SSE)', ok, level: 'core', ms: r.ms,
|
|
96
|
+
note: ok ? `${ev.length} 个事件,文本「${delta.trim().slice(0, 40)}」` : (r.status === 200 ? `事件类型 ${[...types].join(',') || '(空)'}${errEv ? ` error=${JSON.stringify(errEv.error || errEv).slice(0, 120)}` : ''}` : errNote(r)) });
|
|
97
|
+
}
|
|
98
|
+
// 3 tool_use
|
|
99
|
+
{
|
|
100
|
+
const r = await post('/v1/messages', { max_tokens: 200, tools: [PEEK_TOOL], tool_choice: { type: 'any' },
|
|
101
|
+
messages: [{ role: 'user', content: 'Call the peek tool now with a short reason. Do not answer in text.' }] });
|
|
102
|
+
const tu = (r.json?.content || []).find((b) => b.type === 'tool_use');
|
|
103
|
+
const ok = r.status === 200 && !!tu && tu.name === 'peek' && tu.input && typeof tu.input === 'object';
|
|
104
|
+
checks.push({ id: 'tool_use', label: '工具调用', ok, level: 'core', ms: r.ms,
|
|
105
|
+
note: ok ? `stop=${r.json.stop_reason} input=${JSON.stringify(tu.input).slice(0, 80)}` : (r.status === 200 ? `没发起 tool_use(stop=${r.json?.stop_reason},内容=${textOf(r.json).slice(0, 80) || JSON.stringify(r.json?.content || []).slice(0, 80)})` : errNote(r)) });
|
|
106
|
+
}
|
|
107
|
+
// 4 vision
|
|
108
|
+
if (vision) {
|
|
109
|
+
const png = await redPng();
|
|
110
|
+
const r = await post('/v1/messages', { max_tokens: 32, messages: [{ role: 'user', content: [
|
|
111
|
+
{ type: 'image', source: { type: 'base64', media_type: 'image/png', data: png } },
|
|
112
|
+
{ type: 'text', text: 'What color is this image? Answer with one English word.' },
|
|
113
|
+
] }] });
|
|
114
|
+
const ans = textOf(r.json);
|
|
115
|
+
const ok = r.status === 200 && /red/i.test(ans);
|
|
116
|
+
checks.push({ id: 'vision', label: '看图', ok, level: 'info', ms: r.ms,
|
|
117
|
+
note: r.status === 200 ? `纯红图答「${ans.slice(0, 40)}」${ok ? '' : '(没认出 red:这行看不了图,截图自检会瞎)'}` : errNote(r) });
|
|
118
|
+
}
|
|
119
|
+
// 5 count_tokens
|
|
120
|
+
{
|
|
121
|
+
const r = await post('/v1/messages/count_tokens', { messages: [{ role: 'user', content: 'hello there' }] });
|
|
122
|
+
const ok = r.status === 200 && Number.isFinite(r.json?.input_tokens);
|
|
123
|
+
checks.push({ id: 'count_tokens', label: 'count_tokens', ok, level: 'info', ms: r.ms,
|
|
124
|
+
note: ok ? `input_tokens=${r.json.input_tokens}(上游没有该端点时入口本地估算,数会偏)` : errNote(r) });
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
unregisterIngressSession(tag);
|
|
128
|
+
}
|
|
129
|
+
return { appModel, mode: 'api', upstream: route.upstreamId, wireModel: route.upstream && undefined, checks };
|
|
130
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/ingress/upstream-billing.js —— 上游**自报**的费用/用量,按会话 × appModel 累加,供回合结账取走。
|
|
3
|
+
*
|
|
4
|
+
* 背景(08-21 晚):Zen 的 /zen/go 入口每个响应带 `cost`(美元字符串;流式在 [DONE] 之后补一条
|
|
5
|
+
* {"choices":[],"cost":"…"})和 usage.prompt_tokens_details.cached_tokens。我们原来的仪表是
|
|
6
|
+
* "SDK 按 alias 的 Claude 价目算 → reprice 按表价重算",CLI 失败时还按字符估算 —— 假表。
|
|
7
|
+
* 上游报了真数就用真数:ingress 每次往返 note 一笔,session-loop 在 absorbResult 之后 take 走本轮累计,
|
|
8
|
+
* 覆盖 counters.modelUsage[appModel].costUsd(context.applyUpstreamBilling)。
|
|
9
|
+
*
|
|
10
|
+
* 只覆盖 cost,token 数仍以 SDK 的 modelUsage 差分为准(两边口径不同:OpenAI 的 prompt_tokens 含缓存命中);
|
|
11
|
+
* SDK 没给该模型条目时(CLI 失败 / helper),用上游 token 数补一条,别让这笔钱无家可归。
|
|
12
|
+
* 上游没报 cost(cost 为 null)就不动任何东西 —— 假数据比没有更坏。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export class UpstreamBilling {
|
|
16
|
+
constructor() { this.map = new Map(); } // sid → Map<appModel, acc>
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} sid
|
|
19
|
+
* @param {string} appModel
|
|
20
|
+
* @param {{ costUsd?: number|null, usage?: object|null }} info
|
|
21
|
+
*/
|
|
22
|
+
note(sid, appModel, { costUsd = null, usage = null } = {}) {
|
|
23
|
+
if (!sid || !appModel) return;
|
|
24
|
+
const c = costUsd == null || !Number.isFinite(Number(costUsd)) ? null : Number(costUsd);
|
|
25
|
+
if (c == null && !usage) return;
|
|
26
|
+
let per = this.map.get(sid);
|
|
27
|
+
if (!per) { per = new Map(); this.map.set(sid, per); }
|
|
28
|
+
const acc = per.get(appModel) || { costUsd: null, responses: 0, promptTokens: 0, completionTokens: 0, cachedTokens: 0, reasoningTokens: 0 };
|
|
29
|
+
acc.responses += 1;
|
|
30
|
+
if (c != null) acc.costUsd = (acc.costUsd || 0) + c;
|
|
31
|
+
if (usage) {
|
|
32
|
+
acc.promptTokens += Number(usage.prompt_tokens) || 0;
|
|
33
|
+
acc.completionTokens += Number(usage.completion_tokens) || 0;
|
|
34
|
+
acc.cachedTokens += Number(usage.prompt_tokens_details?.cached_tokens) || 0;
|
|
35
|
+
acc.reasoningTokens += Number(usage.completion_tokens_details?.reasoning_tokens) || 0;
|
|
36
|
+
}
|
|
37
|
+
per.set(appModel, acc);
|
|
38
|
+
}
|
|
39
|
+
/** 取走并清零该会话的累计:{ appModel → acc };没有 → null */
|
|
40
|
+
take(sid) {
|
|
41
|
+
const per = sid ? this.map.get(sid) : null;
|
|
42
|
+
if (!per) return null;
|
|
43
|
+
this.map.delete(sid);
|
|
44
|
+
return Object.fromEntries(per);
|
|
45
|
+
}
|
|
46
|
+
peek(sid) { const per = this.map.get(sid); return per ? Object.fromEntries(per) : null; }
|
|
47
|
+
clear(sid) { if (sid) this.map.delete(sid); else this.map.clear(); }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const upstreamBilling = new UpstreamBilling();
|
|
51
|
+
export const noteUpstreamBilling = (sid, appModel, info) => upstreamBilling.note(sid, appModel, info);
|
|
52
|
+
export const takeUpstreamBilling = (sid) => upstreamBilling.take(sid);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/ingress/upstream-fail-streak.js —— 每会话的上游连续失败计数(08-21 晚,僵尸 run 案)。
|
|
3
|
+
*
|
|
4
|
+
* 病:Zen 持续回 503 / network_error 时,我们按规矩发 5xx 或流内 error 事件,CLI 对 5xx 做**无上限**
|
|
5
|
+
* 指数退避重试(假上游实测:75s 内 16 次还在涨),每次又挂 Zen 50~185s —— 一个回合跑了一小时,
|
|
6
|
+
* 用户早断线,run 一直 running。流内 error 事件本身 CLI 只试 4 次就放弃,真正喂活循环的是
|
|
7
|
+
* 非流式兜底那一跳拿到的 502/503。
|
|
8
|
+
*
|
|
9
|
+
* 治法:同一会话连续 N 次上游失败后,ingress 对下一个请求直接回 **HTTP 400**(invalid_request_error)。
|
|
10
|
+
* 假上游 + 真 SDK 循环实测:400 不重试、回合以 is_error 的 result 收场、错误文本原样到用户、
|
|
11
|
+
* streamInput 会话不死(下一条消息照常处理)。消费掉上限后计数归零,用户再发就有新的 N 次机会。
|
|
12
|
+
*
|
|
13
|
+
* 什么算失败:上游 5xx / 转发层网络错 / 200 但零 choices / 私货 finish_reason 且零可见输出(流式与
|
|
14
|
+
* 非流式都算)。什么算成功:一次回应带可见内容(或透传路 2xx)。成功一次就清零。
|
|
15
|
+
* 超过 DECAY_MS 没有新失败也清零(别让昨天的坏账拦今天的人)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_MAX = 4;
|
|
19
|
+
export const DECAY_MS = 30 * 60 * 1000;
|
|
20
|
+
|
|
21
|
+
export function failStreakMax(env = process.env) {
|
|
22
|
+
const v = Number(env.NODESIGN_UPSTREAM_FAIL_STREAK);
|
|
23
|
+
return Number.isInteger(v) && v > 0 ? v : DEFAULT_MAX;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class FailStreaks {
|
|
27
|
+
constructor({ max = null, decayMs = DECAY_MS, now = () => Date.now() } = {}) {
|
|
28
|
+
this.map = new Map(); // sid → { n, last, reason }
|
|
29
|
+
this.maxOverride = max;
|
|
30
|
+
this.decayMs = decayMs;
|
|
31
|
+
this.now = now;
|
|
32
|
+
}
|
|
33
|
+
get max() { return this.maxOverride ?? failStreakMax(); }
|
|
34
|
+
/** 记一次结果。ok=true 清零;ok=false 累加并记原因。返回当前计数。 */
|
|
35
|
+
note(sid, ok, reason = '') {
|
|
36
|
+
if (!sid) return 0;
|
|
37
|
+
if (ok) { this.map.delete(sid); return 0; }
|
|
38
|
+
const now = this.now();
|
|
39
|
+
const cur = this.map.get(sid);
|
|
40
|
+
const n = cur && now - cur.last < this.decayMs ? cur.n + 1 : 1;
|
|
41
|
+
this.map.set(sid, { n, last: now, reason: String(reason || '').slice(0, 160) });
|
|
42
|
+
return n;
|
|
43
|
+
}
|
|
44
|
+
/** 到上限了吗(含衰减判断) */
|
|
45
|
+
exhausted(sid) {
|
|
46
|
+
const cur = sid ? this.map.get(sid) : null;
|
|
47
|
+
if (!cur) return false;
|
|
48
|
+
if (this.now() - cur.last >= this.decayMs) { this.map.delete(sid); return false; }
|
|
49
|
+
return cur.n >= this.max;
|
|
50
|
+
}
|
|
51
|
+
/** 取走并清零:返回 { n, reason },用于组拒绝话术;之后用户再发有新的 max 次机会 */
|
|
52
|
+
consume(sid) {
|
|
53
|
+
const cur = this.map.get(sid) || { n: 0, reason: '' };
|
|
54
|
+
this.map.delete(sid);
|
|
55
|
+
return cur;
|
|
56
|
+
}
|
|
57
|
+
clear(sid) { if (sid) this.map.delete(sid); else this.map.clear(); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** ingress 进程内单例 */
|
|
61
|
+
export const failStreaks = new FailStreaks();
|
|
62
|
+
|
|
63
|
+
/** 拒绝体(Anthropic error 形状;400 = CLI 不重试,实测) */
|
|
64
|
+
export function exhaustedErrorBody({ label, n, reason }) {
|
|
65
|
+
return {
|
|
66
|
+
type: 'error',
|
|
67
|
+
error: {
|
|
68
|
+
type: 'invalid_request_error',
|
|
69
|
+
message: `${label} 连续 ${n} 次没有返回可用内容(最近一次:${reason || '未知'}),这轮先停了。稍后再发一次,或换个模型。`,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/ingress/upstream-truncation.js —— 「上一次响应是不是半截」的会话级标记(08-21 晚)。
|
|
3
|
+
*
|
|
4
|
+
* 病:Zen 会在模型说到一半时把流掐了(无 finish_reason,或私货 finish 如 network_error),
|
|
5
|
+
* 而正文已经吐出来一部分。转换层照旧按 end_turn 收尾(这是对的,假上游实测:有可见输出后
|
|
6
|
+
* 再发 error 事件 CLI 不重试、只会把半截 + "Server error mid-response" 一起判 is_error 给用户),
|
|
7
|
+
* 于是**半截答案就成了最终答案** —— agent 说了半句话就收工,用户以为它答完了。
|
|
8
|
+
* 08-21 当天生产日志 4 次。
|
|
9
|
+
*
|
|
10
|
+
* 治法(对齐 OpenCode 1.18.21 对 unknown finish 的处理):ingress 每次往返把「半截」标记记到
|
|
11
|
+
* 会话上,session-loop 收到 result 时取走;有标记就自动补一条续接消息再跑一轮,
|
|
12
|
+
* 半截那段原样留在对话历史里(跟 OpenCode 一样,不删不改,让模型自己接着说)。
|
|
13
|
+
*
|
|
14
|
+
* 只记**最近一次**,不累加:一个回合里有多次 API 往返(工具调用),我们关心的是收尾那次
|
|
15
|
+
* 是不是半截。任何一次完整收尾都把标记清掉。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export class UpstreamTruncation {
|
|
19
|
+
constructor({ now = () => Date.now() } = {}) {
|
|
20
|
+
this.map = new Map(); // sid → { reason, appModel, at }
|
|
21
|
+
this.now = now;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 记一次往返的收尾形态。truncated 为 null/'' = 这次收得完整 → 清掉旧标记。
|
|
25
|
+
* @param {string} sid
|
|
26
|
+
* @param {string|null} truncated 半截原因串(openai-chat.js 的 truncationReason 产出)
|
|
27
|
+
* @param {{ appModel?: string }} [meta]
|
|
28
|
+
*/
|
|
29
|
+
note(sid, truncated, { appModel = '' } = {}) {
|
|
30
|
+
if (!sid) return;
|
|
31
|
+
if (!truncated) { this.map.delete(sid); return; }
|
|
32
|
+
this.map.set(sid, { reason: String(truncated).slice(0, 120), appModel, at: this.now() });
|
|
33
|
+
}
|
|
34
|
+
/** 取走并清零:{ reason, appModel, at } 或 null */
|
|
35
|
+
take(sid) {
|
|
36
|
+
if (!sid) return null;
|
|
37
|
+
const cur = this.map.get(sid) || null;
|
|
38
|
+
this.map.delete(sid);
|
|
39
|
+
return cur;
|
|
40
|
+
}
|
|
41
|
+
clear(sid) { if (sid) this.map.delete(sid); else this.map.clear(); }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** ingress 进程内单例 */
|
|
45
|
+
export const upstreamTruncation = new UpstreamTruncation();
|
|
46
|
+
|
|
47
|
+
export function noteUpstreamTruncation(sid, truncated, meta) { upstreamTruncation.note(sid, truncated, meta); }
|
|
48
|
+
export function takeUpstreamTruncation(sid) { return upstreamTruncation.take(sid); }
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* server/lib/issues-store.js — harness 问题库(2026-07-30)
|
|
3
|
+
*
|
|
4
|
+
* 两层写同一张表:
|
|
5
|
+
*
|
|
6
|
+
* auto —— PostToolUseFailure 钩子自动记的每次工具失败。**不依赖 agent 的自觉**,
|
|
7
|
+
* 抓得到"某个工具这周失败 40 次但从来没人提过"这种。agent 太会兜底了,
|
|
8
|
+
* 工具坏了它换个姿势就过去了,表面上活儿还是干完的。
|
|
9
|
+
* agent —— report_friction 工具主动报的摩擦:为什么绕路、期望的接口长什么样。
|
|
10
|
+
* 这是 auto 层拿不到的那半句 —— "screenshot 超时 12 次"指不出修法,
|
|
11
|
+
* "我只想要首屏但只能 fullPage 再自己裁"才指得出。
|
|
12
|
+
*
|
|
13
|
+
* 为什么是 SQLite 不是 issue 目录:要看的是"哪个问题最频繁",那是聚合查询;
|
|
14
|
+
* 散文件每次都得自己数。同一类问题按 (source, tool_name, signature) 累加 count,
|
|
15
|
+
* 不是堆一万条重复记录。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import crypto from 'node:crypto';
|
|
19
|
+
import db from '../engine/runs/store.js';
|
|
20
|
+
|
|
21
|
+
db.exec(`
|
|
22
|
+
CREATE TABLE IF NOT EXISTS issues (
|
|
23
|
+
id TEXT PRIMARY KEY,
|
|
24
|
+
source TEXT NOT NULL, -- 'auto' | 'agent'
|
|
25
|
+
tool_name TEXT,
|
|
26
|
+
signature TEXT NOT NULL, -- 归一化指纹,聚合键
|
|
27
|
+
summary TEXT NOT NULL,
|
|
28
|
+
detail TEXT,
|
|
29
|
+
expectation TEXT, -- agent 期望的解决方案(自述层才有)
|
|
30
|
+
project_id TEXT,
|
|
31
|
+
session_id TEXT,
|
|
32
|
+
run_id TEXT,
|
|
33
|
+
user_id TEXT,
|
|
34
|
+
count INTEGER NOT NULL DEFAULT 1,
|
|
35
|
+
status TEXT NOT NULL DEFAULT 'open', -- 'open' | 'ack' | 'ignored' | 'closed'
|
|
36
|
+
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
|
|
37
|
+
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_issues_key ON issues(source, tool_name, signature);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_issues_count ON issues(status, count DESC);
|
|
42
|
+
`);
|
|
43
|
+
|
|
44
|
+
// kind 轴(2026-08-02,上报工具扩容):bug=行为错了 / friction=能用但绕路 /
|
|
45
|
+
// idea=改进想法(没坏也值得说)。老行回填:auto 全是工具失败事件 → bug;
|
|
46
|
+
// agent 存量按原语义 → friction。回填只在加列那一次跑,之后 kind 归写入方管。
|
|
47
|
+
{
|
|
48
|
+
const cols = new Set(db.prepare('PRAGMA table_info(issues)').all().map(c => c.name));
|
|
49
|
+
if (!cols.has('kind')) {
|
|
50
|
+
db.exec("ALTER TABLE issues ADD COLUMN kind TEXT NOT NULL DEFAULT 'friction'");
|
|
51
|
+
db.exec("UPDATE issues SET kind = 'bug' WHERE source = 'auto'");
|
|
52
|
+
console.log('[issues] kind column added (auto 存量回填为 bug)');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 错误指纹:把可变部分抹掉,留下问题的"类"。
|
|
58
|
+
* 不归一化的话同一个毛病会因为路径/行号/时间戳不同散成几十条,聚合就没意义了。
|
|
59
|
+
*/
|
|
60
|
+
export function signatureOf(text) {
|
|
61
|
+
const norm = String(text || '')
|
|
62
|
+
.replace(/[/~][\w.\-/@ 一-鿿]+/g, '<path>') // 路径
|
|
63
|
+
.replace(/\b[0-9a-f]{8,}\b/gi, '<hash>') // id / hash
|
|
64
|
+
.replace(/\d+/g, 'N') // 行号、字节数、耗时
|
|
65
|
+
.replace(/\s+/g, ' ')
|
|
66
|
+
.trim()
|
|
67
|
+
.slice(0, 300);
|
|
68
|
+
return crypto.createHash('sha1').update(norm).digest('hex').slice(0, 16);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function newId() {
|
|
72
|
+
return `iss_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 记一条(同类累加)。任何调用点都必须 fail-soft —— 记录问题这件事本身不能变成
|
|
77
|
+
* 新的故障源,所以这里吞掉一切异常。
|
|
78
|
+
* @returns {{ id: string, count: number } | null}
|
|
79
|
+
*/
|
|
80
|
+
const KINDS = new Set(['bug', 'friction', 'idea']);
|
|
81
|
+
|
|
82
|
+
export function recordIssue({
|
|
83
|
+
source, toolName, summary, detail, expectation,
|
|
84
|
+
projectId, sessionId, runId, userId, signature, kind,
|
|
85
|
+
}) {
|
|
86
|
+
try {
|
|
87
|
+
if (!summary) return null;
|
|
88
|
+
const k = KINDS.has(kind) ? kind : (source === 'auto' ? 'bug' : 'friction');
|
|
89
|
+
const sig = signature || signatureOf(`${toolName || ''}|${detail || summary}`);
|
|
90
|
+
const key = { source, toolName: toolName || null, sig };
|
|
91
|
+
const existing = db.prepare(
|
|
92
|
+
'SELECT id, count FROM issues WHERE source = ? AND tool_name IS ? AND signature = ?',
|
|
93
|
+
).get(key.source, key.toolName, key.sig);
|
|
94
|
+
|
|
95
|
+
if (existing) {
|
|
96
|
+
db.prepare(`UPDATE issues
|
|
97
|
+
SET count = count + 1, last_seen = datetime('now'),
|
|
98
|
+
project_id = COALESCE(?, project_id),
|
|
99
|
+
session_id = COALESCE(?, session_id),
|
|
100
|
+
run_id = COALESCE(?, run_id),
|
|
101
|
+
status = CASE WHEN status = 'closed' THEN 'open' ELSE status END
|
|
102
|
+
WHERE id = ?`)
|
|
103
|
+
.run(projectId ?? null, sessionId ?? null, runId ?? null, existing.id);
|
|
104
|
+
return { id: existing.id, count: existing.count + 1 };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const id = newId();
|
|
108
|
+
db.prepare(`INSERT INTO issues
|
|
109
|
+
(id, source, kind, tool_name, signature, summary, detail, expectation,
|
|
110
|
+
project_id, session_id, run_id, user_id)
|
|
111
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
112
|
+
.run(id, source, k, key.toolName, key.sig,
|
|
113
|
+
String(summary).slice(0, 300),
|
|
114
|
+
detail ? String(detail).slice(0, 4000) : null,
|
|
115
|
+
expectation ? String(expectation).slice(0, 2000) : null,
|
|
116
|
+
projectId ?? null, sessionId ?? null, runId ?? null, userId ?? null);
|
|
117
|
+
return { id, count: 1 };
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.warn('[issues] record failed:', err.message);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function rowToIssue(r) {
|
|
125
|
+
if (!r) return null;
|
|
126
|
+
return {
|
|
127
|
+
id: r.id,
|
|
128
|
+
source: r.source,
|
|
129
|
+
kind: r.kind || 'friction',
|
|
130
|
+
toolName: r.tool_name,
|
|
131
|
+
signature: r.signature,
|
|
132
|
+
summary: r.summary,
|
|
133
|
+
detail: r.detail,
|
|
134
|
+
expectation: r.expectation,
|
|
135
|
+
projectId: r.project_id,
|
|
136
|
+
sessionId: r.session_id,
|
|
137
|
+
runId: r.run_id,
|
|
138
|
+
userId: r.user_id,
|
|
139
|
+
count: r.count,
|
|
140
|
+
status: r.status,
|
|
141
|
+
firstSeen: r.first_seen,
|
|
142
|
+
lastSeen: r.last_seen,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 默认按次数降序 —— 一眼看到最该修的那个。
|
|
148
|
+
* status/source 传 'all' 或空 = 不过滤:这两个字段直接当 SQL 值用过一次,
|
|
149
|
+
* `status:'all'` 匹配不到任何行却返空数组,读起来像"库里是干净的"(体检脚本
|
|
150
|
+
* 就这么漏过一条残留)。宁可在这里认掉这个词,不让空结果继续说谎。
|
|
151
|
+
*/
|
|
152
|
+
export function listIssues({ status, source, kind, limit = 200 } = {}) {
|
|
153
|
+
const where = [];
|
|
154
|
+
const args = [];
|
|
155
|
+
if (status && status !== 'all') { where.push('status = ?'); args.push(status); }
|
|
156
|
+
if (source && source !== 'all') { where.push('source = ?'); args.push(source); }
|
|
157
|
+
if (kind && kind !== 'all') { where.push('kind = ?'); args.push(kind); }
|
|
158
|
+
const sql = `SELECT * FROM issues${where.length ? ` WHERE ${where.join(' AND ')}` : ''}
|
|
159
|
+
ORDER BY count DESC, last_seen DESC LIMIT ?`;
|
|
160
|
+
return db.prepare(sql).all(...args, limit).map(rowToIssue);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const STATUSES = new Set(['open', 'ack', 'ignored', 'closed']);
|
|
164
|
+
|
|
165
|
+
export function setIssueStatus(id, status) {
|
|
166
|
+
if (!STATUSES.has(status)) throw new Error(`invalid status: ${status}`);
|
|
167
|
+
const info = db.prepare('UPDATE issues SET status = ? WHERE id = ?').run(status, id);
|
|
168
|
+
return info.changes > 0 ? rowToIssue(db.prepare('SELECT * FROM issues WHERE id = ?').get(id)) : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function removeIssue(id) {
|
|
172
|
+
return db.prepare('DELETE FROM issues WHERE id = ?').run(id).changes > 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 顶栏/概览用:open 状态下按工具聚合的次数 */
|
|
176
|
+
export function issueStats() {
|
|
177
|
+
const rows = db.prepare(
|
|
178
|
+
`SELECT tool_name, source, SUM(count) AS total, COUNT(*) AS kinds
|
|
179
|
+
FROM issues WHERE status = 'open' GROUP BY tool_name, source ORDER BY total DESC`,
|
|
180
|
+
).all();
|
|
181
|
+
return rows.map(r => ({ toolName: r.tool_name, source: r.source, total: r.total, kinds: r.kinds }));
|
|
182
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kinds/deck.js — deck 形态(演示 / 长图 / 单页报告)
|
|
3
|
+
*
|
|
4
|
+
* 形态契约见 kinds/index.js。deck 是「源即产物」的退化形态:
|
|
5
|
+
* canvas.html 既是工作对象也是被导出的东西,产物根永远是任务根。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import fs from 'node:fs/promises';
|
|
10
|
+
import { isReservedFile } from '../task-scan.js';
|
|
11
|
+
|
|
12
|
+
const ENTRY = 'canvas.html';
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
id: 'deck',
|
|
16
|
+
entryFile: ENTRY,
|
|
17
|
+
view: 'deck',
|
|
18
|
+
injectFit: true, // 导出 / 独立打开时注入整屏翻页 fit script
|
|
19
|
+
capabilities: ['browsable'], // 入口是 html,能塞进 iframe / playwright
|
|
20
|
+
exportFormats: ['html', 'pdf', 'pptx', 'handoff'],
|
|
21
|
+
referenceDoc: { file: 'hybrid-reference', title: 'Hybrid deck 技术参考' },
|
|
22
|
+
|
|
23
|
+
// deck 没有构建这回事,产物根 = 任务根
|
|
24
|
+
artifactRoot: async () => '',
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* deck 实例发现(2026-07-29 多产物平权):任务根顶层每个 .html 各是一份
|
|
28
|
+
* **平等的** deck,没有主次。canvas.html 只是常用名(判定证据 + 无提示时
|
|
29
|
+
* 的排序偏好),不再有"主 deck / 试作"等级。
|
|
30
|
+
*
|
|
31
|
+
* @param {boolean} [opts.rootSiteExists] 任务根是一个站点时,顶层散装
|
|
32
|
+
* .html 是站点页面不是 deck —— 只有 canvas.html(范式保留名)除外
|
|
33
|
+
*/
|
|
34
|
+
async discoverInstances(taskDir, _marker, opts = {}) {
|
|
35
|
+
let entries = [];
|
|
36
|
+
try { entries = await fs.readdir(taskDir, { withFileTypes: true }); } catch { /* */ }
|
|
37
|
+
return entries
|
|
38
|
+
.filter(e => e.isFile() && /\.html?$/i.test(e.name) && !e.name.startsWith('.'))
|
|
39
|
+
.filter(e => !isReservedFile(e.name))
|
|
40
|
+
.map(e => e.name)
|
|
41
|
+
.filter(f => !opts.rootSiteExists || f === ENTRY)
|
|
42
|
+
.sort((a, b) => (b === ENTRY) - (a === ENTRY) || a.localeCompare(b))
|
|
43
|
+
.map(f => ({ file: f }));
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async instanceManifest(taskDir, _marker, inst) {
|
|
47
|
+
return {
|
|
48
|
+
kind: 'deck',
|
|
49
|
+
root: '',
|
|
50
|
+
srcRoot: '',
|
|
51
|
+
entry: inst.file,
|
|
52
|
+
entryRel: inst.file,
|
|
53
|
+
file: inst.file,
|
|
54
|
+
pages: null,
|
|
55
|
+
single: false,
|
|
56
|
+
title: inst.file === ENTRY ? null : inst.file.replace(/\.html?$/i, ''),
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/** 每轮注入的产物清单里,这份 deck 的一行说明 */
|
|
61
|
+
async describe(taskDir, artifact) {
|
|
62
|
+
const entryAbs = path.join(taskDir, artifact.entryRel);
|
|
63
|
+
const label = `deck ${artifact.entryRel}`;
|
|
64
|
+
try {
|
|
65
|
+
const stat = await fs.stat(entryAbs);
|
|
66
|
+
if (stat.size > 512 * 1024) return `${label} · ${(stat.size / 1024).toFixed(0)}KB,Read 时配 limit 分段读`;
|
|
67
|
+
const raw = await fs.readFile(entryAbs, 'utf8');
|
|
68
|
+
const n = (raw.match(/<section\b[^>]*\bdata-page=/g) || []).length;
|
|
69
|
+
return n > 0 ? `${label} · ${n} 页` : `${label} · 还没有 <section data-page=> 分页结构`;
|
|
70
|
+
} catch { return `${label} · 入口读不到`; }
|
|
71
|
+
},
|
|
72
|
+
};
|