@waq666/pneuma 0.0.0-stage → 0.7.0
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 +21 -0
- package/README.md +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次性 WS 票据:浏览器先拿设备 token 换一张票(HTTP),再用票升级 WebSocket。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要多这一跳:浏览器的 WebSocket 构造函数发不了自定义头,token 只能塞在 URL 上,
|
|
5
|
+
* 而 URL 会进各级日志。塞一次性的、30 秒就死的票据,泄了也换不到第二次连接。
|
|
6
|
+
*
|
|
7
|
+
* @module dsc/core/remote/tickets
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes } from 'node:crypto';
|
|
10
|
+
/** 票据有效期:够浏览器从 HTTP 响应走到 WebSocket 握手,不够被人捡去用。 */
|
|
11
|
+
export const TICKET_TTL_MS = 30_000;
|
|
12
|
+
export class TicketStore {
|
|
13
|
+
/** 票据 → 过期时刻与设备身份。 */
|
|
14
|
+
tickets = new Map();
|
|
15
|
+
ttlMs;
|
|
16
|
+
now;
|
|
17
|
+
constructor(ttlMs = TICKET_TTL_MS, now = () => Date.now()) {
|
|
18
|
+
this.ttlMs = ttlMs;
|
|
19
|
+
this.now = now;
|
|
20
|
+
}
|
|
21
|
+
/** 发一张新票,挂上取票的那台设备。 */
|
|
22
|
+
issue(deviceId = '') {
|
|
23
|
+
this.prune();
|
|
24
|
+
const ticket = randomBytes(24).toString('base64url');
|
|
25
|
+
this.tickets.set(ticket, { expiresAt: this.now() + this.ttlMs, deviceId });
|
|
26
|
+
return ticket;
|
|
27
|
+
}
|
|
28
|
+
/** 用票:**取走即焚**,同一张票第二次来必然 null;过期也 null。 */
|
|
29
|
+
redeem(ticket) {
|
|
30
|
+
this.prune();
|
|
31
|
+
const record = this.tickets.get(ticket);
|
|
32
|
+
if (record === undefined)
|
|
33
|
+
return null;
|
|
34
|
+
this.tickets.delete(ticket);
|
|
35
|
+
return record.expiresAt > this.now() ? { deviceId: record.deviceId } : null;
|
|
36
|
+
}
|
|
37
|
+
/** 现在还剩几张没用的票(自检用)。 */
|
|
38
|
+
get size() {
|
|
39
|
+
this.prune();
|
|
40
|
+
return this.tickets.size;
|
|
41
|
+
}
|
|
42
|
+
prune() {
|
|
43
|
+
const now = this.now();
|
|
44
|
+
for (const [ticket, record] of this.tickets) {
|
|
45
|
+
if (record.expiresAt <= now)
|
|
46
|
+
this.tickets.delete(ticket);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** 单文件上限 20MB(这条路由不受 64KB 请求体上限约束,见 plugins/remote.ts)。 */
|
|
2
|
+
export declare const UPLOAD_MAX_BYTES: number;
|
|
3
|
+
/** 上传目录总配额 100MB。 */
|
|
4
|
+
export declare const UPLOAD_QUOTA_BYTES: number;
|
|
5
|
+
/** 上传根目录的缺省值:`~/.dsc/remote/uploads`。 */
|
|
6
|
+
export declare const UPLOAD_DIR: string;
|
|
7
|
+
export interface UploadSaved {
|
|
8
|
+
ok: true;
|
|
9
|
+
/** 落盘绝对路径。 */
|
|
10
|
+
path: string;
|
|
11
|
+
size: number;
|
|
12
|
+
/** 安全化之后的原始文件名(不含随机前缀,给界面显示用)。 */
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface UploadFailed {
|
|
16
|
+
ok: false;
|
|
17
|
+
error: string;
|
|
18
|
+
}
|
|
19
|
+
export type UploadOutcome = UploadSaved | UploadFailed;
|
|
20
|
+
/**
|
|
21
|
+
* 把用户给的文件名洗成能安全落盘的一段。
|
|
22
|
+
*
|
|
23
|
+
* 只取最后一段(`../../evil.txt` → `evil.txt`),去掉控制字符与 `< > : " | ? *`,
|
|
24
|
+
* 去掉开头与结尾的点(`..`、`...`、`x.` 这些在 Windows 上会被截断或指到别处),
|
|
25
|
+
* 保留扩展名(只留字母数字,最多 12 位)。洗完是空的就退回 `upload`。
|
|
26
|
+
*/
|
|
27
|
+
export declare function safeUploadName(raw: string): string;
|
|
28
|
+
export interface UploadStoreOptions {
|
|
29
|
+
/** 上传根目录(默认 `~/.dsc/remote/uploads`;自检脚本换成临时目录)。 */
|
|
30
|
+
dir?: string;
|
|
31
|
+
/** 取时刻(自检注入假钟,测按天分目录)。 */
|
|
32
|
+
now?: () => number;
|
|
33
|
+
/** 目录总配额;自检脚本调小它才能几百字节就把淘汰那条路走通。 */
|
|
34
|
+
quotaBytes?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare class RemoteUploads {
|
|
37
|
+
private readonly dir;
|
|
38
|
+
private readonly now;
|
|
39
|
+
private readonly quotaBytes;
|
|
40
|
+
constructor(options?: UploadStoreOptions);
|
|
41
|
+
/** 上传根目录。 */
|
|
42
|
+
get root(): string;
|
|
43
|
+
/**
|
|
44
|
+
* 落盘一个文件。
|
|
45
|
+
*
|
|
46
|
+
* @param filename - 客户端给的原始文件名(可能带路径、控制字符,全是不可信输入)
|
|
47
|
+
* @param data - 原始字节
|
|
48
|
+
*/
|
|
49
|
+
save(filename: string, data: Buffer): UploadOutcome;
|
|
50
|
+
/** 目录里现在一共多少字节。 */
|
|
51
|
+
totalBytes(): number;
|
|
52
|
+
/** 目录里现有的文件(自检用;按路径排序)。 */
|
|
53
|
+
files(): Array<{
|
|
54
|
+
path: string;
|
|
55
|
+
size: number;
|
|
56
|
+
mtimeMs: number;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* 把总量压到 limit 以内:按修改时间从旧到新删,`protect` 指的是刚写完、不许被这次淘汰
|
|
60
|
+
* 带走的那个文件。
|
|
61
|
+
*/
|
|
62
|
+
private enforceQuota;
|
|
63
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 远程上传:手机把照片、日志、短音频丢进 `~/.dsc/remote/uploads/`,宿主再把磁盘路径
|
|
3
|
+
* 交给会话(模型用 read 之类的工具自己去看)。
|
|
4
|
+
*
|
|
5
|
+
* 三条安全规矩:
|
|
6
|
+
*
|
|
7
|
+
* 1. **文件名从不可信输入里造**。路径分隔符(`/` 与 `\`)、控制字符、Windows 非法字符
|
|
8
|
+
* 与设备名(CON/NUL/COM1…)全部剥掉,只留最后一段做「安全化文件名」,扩展名保留。
|
|
9
|
+
* 落盘名再前置 8 位随机十六进制——同名文件不会互相覆盖,也看不出是谁传的。
|
|
10
|
+
* 2. **单文件 20MB**,目录总量 **100MB**,超了按最旧删除(手机随手传的大文件不至于把
|
|
11
|
+
* 用户的家目录撑爆)。上限判定在写入前后各做一次:前面那次是为了别先写爆再删。
|
|
12
|
+
* 3. **按天分目录**(`uploads/yyyymmdd/`)。人工去翻的时候一眼能看出是哪天传的,
|
|
13
|
+
* 配额淘汰也是先淘汰最早那几天的。
|
|
14
|
+
*
|
|
15
|
+
* @module dsc/core/remote/uploads
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { randomBytes } from 'node:crypto';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { REMOTE_DIR } from './store.js';
|
|
21
|
+
/** 单文件上限 20MB(这条路由不受 64KB 请求体上限约束,见 plugins/remote.ts)。 */
|
|
22
|
+
export const UPLOAD_MAX_BYTES = 20 * 1024 * 1024;
|
|
23
|
+
/** 上传目录总配额 100MB。 */
|
|
24
|
+
export const UPLOAD_QUOTA_BYTES = 100 * 1024 * 1024;
|
|
25
|
+
/** 上传根目录的缺省值:`~/.dsc/remote/uploads`。 */
|
|
26
|
+
export const UPLOAD_DIR = join(REMOTE_DIR, 'uploads');
|
|
27
|
+
/** 安全化文件名的长度上限(留出随机前缀与扩展名的位置)。 */
|
|
28
|
+
const STEM_LIMIT = 80;
|
|
29
|
+
/** Windows 上不能直接当文件名用的设备名。 */
|
|
30
|
+
const RESERVED_NAMES = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i;
|
|
31
|
+
/**
|
|
32
|
+
* 把用户给的文件名洗成能安全落盘的一段。
|
|
33
|
+
*
|
|
34
|
+
* 只取最后一段(`../../evil.txt` → `evil.txt`),去掉控制字符与 `< > : " | ? *`,
|
|
35
|
+
* 去掉开头与结尾的点(`..`、`...`、`x.` 这些在 Windows 上会被截断或指到别处),
|
|
36
|
+
* 保留扩展名(只留字母数字,最多 12 位)。洗完是空的就退回 `upload`。
|
|
37
|
+
*/
|
|
38
|
+
export function safeUploadName(raw) {
|
|
39
|
+
const last = raw.split(/[/\\]/).pop() ?? '';
|
|
40
|
+
const cleaned = last
|
|
41
|
+
.replace(/[\u0000-\u001f\u007f]/g, '')
|
|
42
|
+
.replace(/[<>:"|?*]/g, '')
|
|
43
|
+
.replace(/^\.+/, '')
|
|
44
|
+
.replace(/[. ]+$/, '')
|
|
45
|
+
.trim();
|
|
46
|
+
if (cleaned === '')
|
|
47
|
+
return 'upload';
|
|
48
|
+
const dot = cleaned.lastIndexOf('.');
|
|
49
|
+
const rawStem = dot > 0 ? cleaned.slice(0, dot) : cleaned;
|
|
50
|
+
const stem = (rawStem === '' ? 'upload' : rawStem).slice(0, STEM_LIMIT);
|
|
51
|
+
const ext = (dot > 0 ? cleaned.slice(dot + 1) : '').replace(/[^0-9A-Za-z]/g, '').slice(0, 12);
|
|
52
|
+
const name = ext === '' ? stem : `${stem}.${ext}`;
|
|
53
|
+
// 设备名看的是主名:Windows 上 `com1.txt` 照样指到串口,扩展名救不了它
|
|
54
|
+
return RESERVED_NAMES.test(stem) ? `_${name}` : name;
|
|
55
|
+
}
|
|
56
|
+
/** 落盘目录名:本地时间的 yyyymmdd。 */
|
|
57
|
+
function dayDir(now) {
|
|
58
|
+
const date = new Date(now);
|
|
59
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
60
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
61
|
+
return `${String(date.getFullYear())}${month}${day}`;
|
|
62
|
+
}
|
|
63
|
+
export class RemoteUploads {
|
|
64
|
+
dir;
|
|
65
|
+
now;
|
|
66
|
+
quotaBytes;
|
|
67
|
+
constructor(options = {}) {
|
|
68
|
+
this.dir = options.dir ?? UPLOAD_DIR;
|
|
69
|
+
this.now = options.now ?? (() => Date.now());
|
|
70
|
+
this.quotaBytes = options.quotaBytes ?? UPLOAD_QUOTA_BYTES;
|
|
71
|
+
}
|
|
72
|
+
/** 上传根目录。 */
|
|
73
|
+
get root() {
|
|
74
|
+
return this.dir;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 落盘一个文件。
|
|
78
|
+
*
|
|
79
|
+
* @param filename - 客户端给的原始文件名(可能带路径、控制字符,全是不可信输入)
|
|
80
|
+
* @param data - 原始字节
|
|
81
|
+
*/
|
|
82
|
+
save(filename, data) {
|
|
83
|
+
if (data.length > UPLOAD_MAX_BYTES) {
|
|
84
|
+
return { ok: false, error: `文件超过 ${String(Math.round(UPLOAD_MAX_BYTES / 1024 / 1024))}MB 上限` };
|
|
85
|
+
}
|
|
86
|
+
const safe = safeUploadName(filename);
|
|
87
|
+
const diskName = `${randomBytes(4).toString('hex')}-${safe}`;
|
|
88
|
+
const dayDirectory = join(this.dir, dayDir(this.now()));
|
|
89
|
+
mkdirSync(dayDirectory, { recursive: true });
|
|
90
|
+
// 先腾地方:这一次写下去也不能顶破配额
|
|
91
|
+
this.enforceQuota(this.quotaBytes - data.length);
|
|
92
|
+
const path = join(dayDirectory, diskName);
|
|
93
|
+
writeFileSync(path, data);
|
|
94
|
+
this.enforceQuota(this.quotaBytes, path);
|
|
95
|
+
return { ok: true, path, size: data.length, name: safe };
|
|
96
|
+
}
|
|
97
|
+
/** 目录里现在一共多少字节。 */
|
|
98
|
+
totalBytes() {
|
|
99
|
+
let total = 0;
|
|
100
|
+
for (const file of this.files())
|
|
101
|
+
total += file.size;
|
|
102
|
+
return total;
|
|
103
|
+
}
|
|
104
|
+
/** 目录里现有的文件(自检用;按路径排序)。 */
|
|
105
|
+
files() {
|
|
106
|
+
const out = [];
|
|
107
|
+
const walk = (directory) => {
|
|
108
|
+
let entries;
|
|
109
|
+
try {
|
|
110
|
+
entries = readdirSync(directory, { withFileTypes: true });
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
for (const entry of entries) {
|
|
116
|
+
const full = join(directory, entry.name);
|
|
117
|
+
if (entry.isDirectory()) {
|
|
118
|
+
walk(full);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const info = statSync(full);
|
|
123
|
+
if (info.isFile())
|
|
124
|
+
out.push({ path: full, size: info.size, mtimeMs: info.mtimeMs });
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// 正好被删了 / 读不动:跳过
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
walk(this.dir);
|
|
132
|
+
out.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 把总量压到 limit 以内:按修改时间从旧到新删,`protect` 指的是刚写完、不许被这次淘汰
|
|
137
|
+
* 带走的那个文件。
|
|
138
|
+
*/
|
|
139
|
+
enforceQuota(limit, protect) {
|
|
140
|
+
const files = this.files();
|
|
141
|
+
let total = 0;
|
|
142
|
+
for (const file of files)
|
|
143
|
+
total += file.size;
|
|
144
|
+
if (total <= limit)
|
|
145
|
+
return;
|
|
146
|
+
const byAge = [...files].sort((left, right) => left.mtimeMs - right.mtimeMs);
|
|
147
|
+
for (const file of byAge) {
|
|
148
|
+
if (total <= limit)
|
|
149
|
+
break;
|
|
150
|
+
if (protect !== undefined && file.path === protect)
|
|
151
|
+
continue;
|
|
152
|
+
try {
|
|
153
|
+
unlinkSync(file.path);
|
|
154
|
+
total -= file.size;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// 删不掉(被占用之类):留着,继续试下一个
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自标识的 user agent。文档要求「用自己的名字」,通用的 `node`(undici 缺省)不算。
|
|
3
|
+
* 形状跟常见客户端一致:`<产品名>/<版本>`(HTTP 头里不能有空格)。
|
|
4
|
+
*/
|
|
5
|
+
export declare const APP_USER_AGENT: string;
|
|
6
|
+
/** 会话归因头的名字。 */
|
|
7
|
+
export declare const OPENCODE_SESSION_HEADER = "x-opencode-session";
|
|
8
|
+
/**
|
|
9
|
+
* 这个 baseUrl 是不是 opencode Go 入口。大小写不敏感、允许尾斜杠;
|
|
10
|
+
* 认不出的 URL(用户填错、空串)一律 false——宁可漏发,不可乱发。
|
|
11
|
+
*
|
|
12
|
+
* @param baseUrl - 端点配置里的 baseUrl(core/config 已剥掉尾部斜杠,这里再兜一次)。
|
|
13
|
+
*/
|
|
14
|
+
export declare function isOpenCodeGoBaseUrl(baseUrl: string | undefined): boolean;
|
|
15
|
+
/** 会话 id 的线上值;空、超长、带非法字符时返回 undefined(省略这个头,不弄坏请求)。 */
|
|
16
|
+
export declare function sessionIdHeaderValue(sessionId: string | undefined): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* 按端点补的归因头。不带条件、不命中就返回空表(调用方直接展开进 headers)。
|
|
19
|
+
*
|
|
20
|
+
* 同一个会话的价值就在「稳定」:网关按它做路由与 prompt 缓存,所以值只取会话
|
|
21
|
+
* 自己的 id,不做任何随机化;换会话才换值。
|
|
22
|
+
*
|
|
23
|
+
* @param baseUrl - 这次请求打向的端点。
|
|
24
|
+
* @param sessionId - 这条请求属于的会话(宿主用会话 meta.id)。
|
|
25
|
+
*/
|
|
26
|
+
export declare function sessionAttributionHeaders(baseUrl: string | undefined, sessionId: string | undefined): Record<string, string>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型请求的归因头:自标识 + 端点点名要的会话头。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单开一节:这里全是纯字符串判断(只 import 版本号),探针能直读;
|
|
5
|
+
* 「哪种端点要哪几个头」是事实,散在 fetch 旁边迟早漂。
|
|
6
|
+
*
|
|
7
|
+
* 当前只有一家点名要:opencode 的 Go 网关按**会话**做路由与 prompt 缓存,
|
|
8
|
+
* 缺 `x-opencode-session` 直接 400 `MissingSessionID`(2026-10-14 用户报障,
|
|
9
|
+
* 分析见 docs/opencode-go-session-header.md)。它同时要求客户端用**自己的**
|
|
10
|
+
* 名字标识自己(通用的 node/undici 不算),所以命中它的入口连 user-agent 一起给。
|
|
11
|
+
*
|
|
12
|
+
* 门控形状(对齐同类客户端的实现):**host 与 path 一起判**,不认 provider id
|
|
13
|
+
* ——id 是用户随手起的,会变。host 是 `opencode.ai` 或其子域、path 规范化后正好
|
|
14
|
+
* 是 `/zen/go/v1` 才算 Go 入口;普通 Zen(`/zen/v1`)与别的 OpenCode API 都不带。
|
|
15
|
+
*
|
|
16
|
+
* **别家端点一个字节都看不到这些头**:会话头是端点私有的,无条件多带会被挑剔的
|
|
17
|
+
* 网关判 400(与 core/llm 里 `ChatMessage.ts` 那条教训同一件事——请求体如此,
|
|
18
|
+
* 请求头同理)。
|
|
19
|
+
*
|
|
20
|
+
* @module dsc/core/request-attribution
|
|
21
|
+
*/
|
|
22
|
+
import { DSC_VERSION } from './version.js';
|
|
23
|
+
/**
|
|
24
|
+
* 自标识的 user agent。文档要求「用自己的名字」,通用的 `node`(undici 缺省)不算。
|
|
25
|
+
* 形状跟常见客户端一致:`<产品名>/<版本>`(HTTP 头里不能有空格)。
|
|
26
|
+
*/
|
|
27
|
+
export const APP_USER_AGENT = `pneuma/${DSC_VERSION}`;
|
|
28
|
+
/** Go 网关的根域;子域也算(`www.opencode.ai` 之类)。 */
|
|
29
|
+
const OPENCODE_HOST = 'opencode.ai';
|
|
30
|
+
/** Go 入口的 path;只认这一个,普通 Zen 的 `/zen/v1` 不在其列。 */
|
|
31
|
+
const OPENCODE_GO_PATH = '/zen/go/v1';
|
|
32
|
+
/** 会话归因头的名字。 */
|
|
33
|
+
export const OPENCODE_SESSION_HEADER = 'x-opencode-session';
|
|
34
|
+
/**
|
|
35
|
+
* 会话 id 能不能直接当头的值:HTTP 头不许出现换行等控制字符(带上会让 fetch
|
|
36
|
+
* 直接抛异常,把整次请求弄坏)。合法值只放行 ASCII 字母数字与 `._:-`,长度封顶 128。
|
|
37
|
+
*/
|
|
38
|
+
const HEADER_VALUE_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
39
|
+
/**
|
|
40
|
+
* 这个 baseUrl 是不是 opencode Go 入口。大小写不敏感、允许尾斜杠;
|
|
41
|
+
* 认不出的 URL(用户填错、空串)一律 false——宁可漏发,不可乱发。
|
|
42
|
+
*
|
|
43
|
+
* @param baseUrl - 端点配置里的 baseUrl(core/config 已剥掉尾部斜杠,这里再兜一次)。
|
|
44
|
+
*/
|
|
45
|
+
export function isOpenCodeGoBaseUrl(baseUrl) {
|
|
46
|
+
const trimmed = baseUrl?.trim();
|
|
47
|
+
if (trimmed === undefined || trimmed === '')
|
|
48
|
+
return false;
|
|
49
|
+
let url;
|
|
50
|
+
try {
|
|
51
|
+
url = new URL(trimmed);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const host = url.hostname.toLowerCase();
|
|
57
|
+
const path = url.pathname.replace(/\/+$/, '').toLowerCase();
|
|
58
|
+
return (host === OPENCODE_HOST || host.endsWith(`.${OPENCODE_HOST}`)) && path === OPENCODE_GO_PATH;
|
|
59
|
+
}
|
|
60
|
+
/** 会话 id 的线上值;空、超长、带非法字符时返回 undefined(省略这个头,不弄坏请求)。 */
|
|
61
|
+
export function sessionIdHeaderValue(sessionId) {
|
|
62
|
+
const trimmed = sessionId?.trim();
|
|
63
|
+
if (trimmed === undefined || trimmed === '')
|
|
64
|
+
return undefined;
|
|
65
|
+
return HEADER_VALUE_PATTERN.test(trimmed) ? trimmed : undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 按端点补的归因头。不带条件、不命中就返回空表(调用方直接展开进 headers)。
|
|
69
|
+
*
|
|
70
|
+
* 同一个会话的价值就在「稳定」:网关按它做路由与 prompt 缓存,所以值只取会话
|
|
71
|
+
* 自己的 id,不做任何随机化;换会话才换值。
|
|
72
|
+
*
|
|
73
|
+
* @param baseUrl - 这次请求打向的端点。
|
|
74
|
+
* @param sessionId - 这条请求属于的会话(宿主用会话 meta.id)。
|
|
75
|
+
*/
|
|
76
|
+
export function sessionAttributionHeaders(baseUrl, sessionId) {
|
|
77
|
+
if (!isOpenCodeGoBaseUrl(baseUrl))
|
|
78
|
+
return {};
|
|
79
|
+
const value = sessionIdHeaderValue(sessionId);
|
|
80
|
+
return {
|
|
81
|
+
'user-agent': APP_USER_AGENT,
|
|
82
|
+
// 没有可用的会话 id 就只留自标识:网关照样会报它的 MissingSessionID,
|
|
83
|
+
// 报错原文比一个编出来的 id 好排查。
|
|
84
|
+
...(value === undefined ? {} : { [OPENCODE_SESSION_HEADER]: value }),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时请求 invariant:校验「这次真的发给模型的消息」能不能从会话日志 + 投影链重建。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有它:投影链(plugins/prompt.ts 的 rewrite)约定是纯函数,但约定没人守时它
|
|
5
|
+
* 不会自己响。一旦某个投影带随机数/时间戳、或者就地改了输入,模型看到的就和日志能重建的
|
|
6
|
+
* 对不上——这种 bug 平时悄无声息,等用户发现「模型怎么记错了」时早已无从追溯。这里在
|
|
7
|
+
* 调用点逐条比对,把「模型可见 ⟺ 日志可重建」钉成一条可执行的检查(对应 dsh 的
|
|
8
|
+
* agent-loop invariant:请求 messages 与 `session.deriveMessages()` 逐字节相等)。
|
|
9
|
+
*
|
|
10
|
+
* 与 dsh 的取舍不同:dsh 在 `llm/stream` waterfall 里不符即 `fail`(杀请求)。dsc 选择
|
|
11
|
+
* **只报不杀**——报出来人还能救(看 notice、去查是哪条投影),杀掉会话只会让用户白白丢
|
|
12
|
+
* 一轮对话。所以本模块**绝不抛异常、绝不阻断请求、绝不 mutate 输入**;调用点拿到报告后
|
|
13
|
+
* 自行决定怎么报。
|
|
14
|
+
*
|
|
15
|
+
* @module dsc/core/request-invariant
|
|
16
|
+
*/
|
|
17
|
+
import { type ChatMessage } from './llm.js';
|
|
18
|
+
/** 一次比对的结果。`ok:false` 时其余字段给出可行动的定位。 */
|
|
19
|
+
export interface InvariantReport {
|
|
20
|
+
/** true = 发送侧与重建侧一致(或差异只落在尾部运行时注入段,见下)。 */
|
|
21
|
+
ok: boolean;
|
|
22
|
+
/** 第一条对不上的下标(0 基,含头部 system)。 */
|
|
23
|
+
firstDiffIndex?: number;
|
|
24
|
+
/** 人话原因:第几条起、两侧 role、总条数差。 */
|
|
25
|
+
reason?: string;
|
|
26
|
+
/** 失配形状指纹:同一会话同一形状只报一次的去重键(不含正文,所以随机值也稳定)。 */
|
|
27
|
+
digest?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 深到「足够抓就地改」的一份快照:消息对象、content 数组、tool_calls 数组与其中每项
|
|
31
|
+
* 都复制一层(大字符串按引用共享——不可变,安全)。用来在投影链跑之前拍一份输入,
|
|
32
|
+
* 之后与跑完的输入比,就能发现「投影就地改了它拿到的输入」。
|
|
33
|
+
*
|
|
34
|
+
* 为什么值得单独做:就地改比「结果不一致」更隐蔽——结果看着对,可被改的消息对象与
|
|
35
|
+
* 会话日志是同一批引用,日志已经被写花了(下一次请求就带着花掉的历史)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function snapshotMessages(messages: readonly ChatMessage[]): ChatMessage[];
|
|
38
|
+
/**
|
|
39
|
+
* 输入被就地改动的第一条下标;没被改返回 null。`before` 应是 {@link snapshotMessages}
|
|
40
|
+
* 拍的快照,`after` 是投影链跑完的同一份输入。长度先比(塞/删一条最直观),再逐条比字段。
|
|
41
|
+
*/
|
|
42
|
+
export declare function firstMutatedIndex(before: readonly ChatMessage[], after: readonly ChatMessage[]): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* 校验「发出去的那份」(sent) 能不能从「按同一路径重新派生的那份」(derived) 重建。
|
|
45
|
+
*
|
|
46
|
+
* 两条判定,按顺序:
|
|
47
|
+
* 1. **就地改输入**(`input` 给了才查):投影改了它拿到的输入 → 直接判不一致。
|
|
48
|
+
* 这条独立于「结果是否一致」——结果可能碰巧对,日志却已被污染。
|
|
49
|
+
* 2. **逐条比对**:先按 {@link RUNTIME_INJECTION_MARKERS} 从两侧摘掉运行时注入段
|
|
50
|
+
* (易变段放宽),剩下的正文逐条比,第一条对不上即报出。
|
|
51
|
+
*
|
|
52
|
+
* 绝不抛异常、绝不 mutate 任何入参。
|
|
53
|
+
*
|
|
54
|
+
* @param sent - 真正要发出去的消息(组装 + 投影链的结果)。
|
|
55
|
+
* @param derived - 按同一路径重新派生的结果。
|
|
56
|
+
* @param input - 可选:投影链跑之前的输入快照与跑完的输入,用来查就地改动。
|
|
57
|
+
*/
|
|
58
|
+
export declare function checkReconstructable(sent: readonly ChatMessage[], derived: readonly ChatMessage[], input?: {
|
|
59
|
+
before: readonly ChatMessage[];
|
|
60
|
+
after: readonly ChatMessage[];
|
|
61
|
+
}): InvariantReport;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时请求 invariant:校验「这次真的发给模型的消息」能不能从会话日志 + 投影链重建。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有它:投影链(plugins/prompt.ts 的 rewrite)约定是纯函数,但约定没人守时它
|
|
5
|
+
* 不会自己响。一旦某个投影带随机数/时间戳、或者就地改了输入,模型看到的就和日志能重建的
|
|
6
|
+
* 对不上——这种 bug 平时悄无声息,等用户发现「模型怎么记错了」时早已无从追溯。这里在
|
|
7
|
+
* 调用点逐条比对,把「模型可见 ⟺ 日志可重建」钉成一条可执行的检查(对应 dsh 的
|
|
8
|
+
* agent-loop invariant:请求 messages 与 `session.deriveMessages()` 逐字节相等)。
|
|
9
|
+
*
|
|
10
|
+
* 与 dsh 的取舍不同:dsh 在 `llm/stream` waterfall 里不符即 `fail`(杀请求)。dsc 选择
|
|
11
|
+
* **只报不杀**——报出来人还能救(看 notice、去查是哪条投影),杀掉会话只会让用户白白丢
|
|
12
|
+
* 一轮对话。所以本模块**绝不抛异常、绝不阻断请求、绝不 mutate 输入**;调用点拿到报告后
|
|
13
|
+
* 自行决定怎么报。
|
|
14
|
+
*
|
|
15
|
+
* @module dsc/core/request-invariant
|
|
16
|
+
*/
|
|
17
|
+
import { contentText } from './llm.js';
|
|
18
|
+
/** content 相等:字符串/null 按值,数组按「逐段」比(不 stringify——图像 data URL 很大)。 */
|
|
19
|
+
function sameContent(a, b) {
|
|
20
|
+
if (typeof a === 'string' || a === null || a === undefined) {
|
|
21
|
+
return typeof b === 'string' || b === null || b === undefined ? a === b : false;
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(a) || !Array.isArray(b))
|
|
24
|
+
return false;
|
|
25
|
+
if (a.length !== b.length)
|
|
26
|
+
return false;
|
|
27
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
28
|
+
const x = a[i];
|
|
29
|
+
const y = b[i];
|
|
30
|
+
if (x.type !== y.type)
|
|
31
|
+
return false;
|
|
32
|
+
if (x.type === 'text') {
|
|
33
|
+
if (y.type !== 'text' || x.text !== y.text)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
else if (y.type !== 'image_url' || x.image_url.url !== y.image_url.url) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/** 工具调用相等:id / type / 函数名 / 参数字符串逐个比。 */
|
|
43
|
+
function sameToolCalls(a, b) {
|
|
44
|
+
if (a === b)
|
|
45
|
+
return true;
|
|
46
|
+
if (a === undefined || b === undefined)
|
|
47
|
+
return false;
|
|
48
|
+
if (a.length !== b.length)
|
|
49
|
+
return false;
|
|
50
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
51
|
+
const x = a[i];
|
|
52
|
+
const y = b[i];
|
|
53
|
+
if (x.id !== y.id || x.type !== y.type || x.function.name !== y.function.name || x.function.arguments !== y.function.arguments) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 单条消息是否等价。只比协议上有意义的字段——`ts` 这类记账字段不算内容差异
|
|
61
|
+
* (它是落库时刻,两次派生之间本来就不同,比它会制造误报)。
|
|
62
|
+
*/
|
|
63
|
+
function sameMessage(a, b) {
|
|
64
|
+
return (a.role === b.role &&
|
|
65
|
+
a.tool_call_id === b.tool_call_id &&
|
|
66
|
+
a.reasoning_content === b.reasoning_content &&
|
|
67
|
+
sameContent(a.content, b.content) &&
|
|
68
|
+
sameToolCalls(a.tool_calls, b.tool_calls));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 深到「足够抓就地改」的一份快照:消息对象、content 数组、tool_calls 数组与其中每项
|
|
72
|
+
* 都复制一层(大字符串按引用共享——不可变,安全)。用来在投影链跑之前拍一份输入,
|
|
73
|
+
* 之后与跑完的输入比,就能发现「投影就地改了它拿到的输入」。
|
|
74
|
+
*
|
|
75
|
+
* 为什么值得单独做:就地改比「结果不一致」更隐蔽——结果看着对,可被改的消息对象与
|
|
76
|
+
* 会话日志是同一批引用,日志已经被写花了(下一次请求就带着花掉的历史)。
|
|
77
|
+
*/
|
|
78
|
+
export function snapshotMessages(messages) {
|
|
79
|
+
return messages.map((message) => {
|
|
80
|
+
const out = {
|
|
81
|
+
role: message.role,
|
|
82
|
+
content: typeof message.content === 'string' || message.content === null || message.content === undefined
|
|
83
|
+
? (message.content ?? null)
|
|
84
|
+
: message.content.map((part) => part.type === 'text'
|
|
85
|
+
? { type: 'text', text: part.text }
|
|
86
|
+
: { type: 'image_url', image_url: { url: part.image_url.url } }),
|
|
87
|
+
};
|
|
88
|
+
if (message.reasoning_content !== undefined)
|
|
89
|
+
out.reasoning_content = message.reasoning_content;
|
|
90
|
+
if (message.tool_call_id !== undefined)
|
|
91
|
+
out.tool_call_id = message.tool_call_id;
|
|
92
|
+
if (message.tool_calls !== undefined) {
|
|
93
|
+
out.tool_calls = message.tool_calls.map((call) => ({
|
|
94
|
+
id: call.id,
|
|
95
|
+
type: call.type,
|
|
96
|
+
function: { name: call.function.name, arguments: call.function.arguments },
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
if (message.ts !== undefined)
|
|
100
|
+
out.ts = message.ts;
|
|
101
|
+
return out;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 输入被就地改动的第一条下标;没被改返回 null。`before` 应是 {@link snapshotMessages}
|
|
106
|
+
* 拍的快照,`after` 是投影链跑完的同一份输入。长度先比(塞/删一条最直观),再逐条比字段。
|
|
107
|
+
*/
|
|
108
|
+
export function firstMutatedIndex(before, after) {
|
|
109
|
+
if (before.length !== after.length)
|
|
110
|
+
return Math.min(before.length, after.length);
|
|
111
|
+
for (let i = 0; i < before.length; i += 1) {
|
|
112
|
+
if (!sameMessage(before[i], after[i]))
|
|
113
|
+
return i;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 运行时注入段的识别标记。这些段的正文由投影在请求尾部追加、内容依赖外部状态
|
|
119
|
+
* (当天日期 / 钩子结果 / 编辑器诊断),天生不满足「重放可复现」;其中
|
|
120
|
+
* `user-prompt-submit`、`lsp-write-diagnostics` 还会在第一次跑时消费掉待发队列,
|
|
121
|
+
* 第二次派生必然少掉那一段。比对前把这些段从两侧都摘掉、剩下的正文再逐字节比——
|
|
122
|
+
* 这是本模块唯一的放宽点,也是「零误报」的关键(对易变段放宽成结构比对)。
|
|
123
|
+
*
|
|
124
|
+
* 标记与来源一一对应(新增一类尾部注入时要往这里补一行):
|
|
125
|
+
* - env-facts:`plugins/prompt.ts` 的 environmentSnapshot
|
|
126
|
+
* - lsp-write-diagnostics:`plugins/lsp.ts`
|
|
127
|
+
* - user-prompt-submit:`plugins/lifecycle-hooks.ts`
|
|
128
|
+
*/
|
|
129
|
+
const RUNTIME_INJECTION_MARKERS = [
|
|
130
|
+
'本条是程序在每次请求时自动附上的当前环境快照',
|
|
131
|
+
'【LSP 诊断】',
|
|
132
|
+
'<external_content source="hook:',
|
|
133
|
+
];
|
|
134
|
+
/** 这条是不是「运行时注入段」(尾部追加、不要求重放可复现的 user 消息)。 */
|
|
135
|
+
function isRuntimeInjection(message) {
|
|
136
|
+
if (message.role !== 'user')
|
|
137
|
+
return false;
|
|
138
|
+
const text = contentText(message.content);
|
|
139
|
+
return RUNTIME_INJECTION_MARKERS.some((marker) => text.includes(marker));
|
|
140
|
+
}
|
|
141
|
+
/** 摘掉运行时注入段,同时记住每条在原数组里的下标(报错要指回原位置)。 */
|
|
142
|
+
function stripRuntimeInjections(messages) {
|
|
143
|
+
const out = [];
|
|
144
|
+
messages.forEach((message, index) => {
|
|
145
|
+
if (!isRuntimeInjection(message))
|
|
146
|
+
out.push({ message, index });
|
|
147
|
+
});
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 校验「发出去的那份」(sent) 能不能从「按同一路径重新派生的那份」(derived) 重建。
|
|
152
|
+
*
|
|
153
|
+
* 两条判定,按顺序:
|
|
154
|
+
* 1. **就地改输入**(`input` 给了才查):投影改了它拿到的输入 → 直接判不一致。
|
|
155
|
+
* 这条独立于「结果是否一致」——结果可能碰巧对,日志却已被污染。
|
|
156
|
+
* 2. **逐条比对**:先按 {@link RUNTIME_INJECTION_MARKERS} 从两侧摘掉运行时注入段
|
|
157
|
+
* (易变段放宽),剩下的正文逐条比,第一条对不上即报出。
|
|
158
|
+
*
|
|
159
|
+
* 绝不抛异常、绝不 mutate 任何入参。
|
|
160
|
+
*
|
|
161
|
+
* @param sent - 真正要发出去的消息(组装 + 投影链的结果)。
|
|
162
|
+
* @param derived - 按同一路径重新派生的结果。
|
|
163
|
+
* @param input - 可选:投影链跑之前的输入快照与跑完的输入,用来查就地改动。
|
|
164
|
+
*/
|
|
165
|
+
export function checkReconstructable(sent, derived, input) {
|
|
166
|
+
if (input !== undefined) {
|
|
167
|
+
const mutated = firstMutatedIndex(input.before, input.after);
|
|
168
|
+
if (mutated !== null) {
|
|
169
|
+
const role = input.after[mutated]?.role ?? '(无)';
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
firstDiffIndex: mutated,
|
|
173
|
+
reason: `投影就地改了输入:第 ${mutated + 1} 条(${role})被就地改写,会话日志可能已被污染`,
|
|
174
|
+
digest: `mut:${mutated}:${role}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const sentCore = stripRuntimeInjections(sent);
|
|
179
|
+
const derivedCore = stripRuntimeInjections(derived);
|
|
180
|
+
const max = Math.min(sentCore.length, derivedCore.length);
|
|
181
|
+
let k = 0;
|
|
182
|
+
while (k < max && sameMessage(sentCore[k].message, derivedCore[k].message))
|
|
183
|
+
k += 1;
|
|
184
|
+
if (k === sentCore.length && k === derivedCore.length)
|
|
185
|
+
return { ok: true };
|
|
186
|
+
const roleA = sentCore[k]?.message.role ?? '(无)';
|
|
187
|
+
const roleB = derivedCore[k]?.message.role ?? '(无)';
|
|
188
|
+
// 定位回原数组下标:优先发送侧那条,发送侧没有(重建侧多出来)就用重建侧那条。
|
|
189
|
+
const firstDiffIndex = sentCore[k]?.index ?? derivedCore[k]?.index ?? Math.max(sent.length, derived.length);
|
|
190
|
+
const delta = sentCore.length - derivedCore.length;
|
|
191
|
+
return {
|
|
192
|
+
ok: false,
|
|
193
|
+
firstDiffIndex,
|
|
194
|
+
reason: `第 ${firstDiffIndex + 1} 条起不一致(发送侧 ${roleA},重建侧 ${roleB};可比条数 ${sentCore.length} vs ${derivedCore.length},差 ${delta >= 0 ? '+' : ''}${delta})`,
|
|
195
|
+
// digest 只取「可比位置 + 两侧 role」,不含长度:一个回合内多条请求的条数天然不同,
|
|
196
|
+
// 带上长度会把同一处 bug 拆成多种形状、每轮重复报(去重就失效了)。
|
|
197
|
+
digest: `${k}:${roleA}:${roleB}`,
|
|
198
|
+
};
|
|
199
|
+
}
|