@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,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 沙箱命令策略(形制照 codex 的 execpolicy):一条 shell 命令 → allow / prompt / forbidden。
|
|
3
|
+
*
|
|
4
|
+
* 与 `core/command-policy.ts` 的分工(两份东西长得像但判的不是一件事):
|
|
5
|
+
* - `command-policy` 回答「这条命令危不危险、要不要问人」,它是**审批面**,
|
|
6
|
+
* 结论是 allow/ask/deny,且 deny 是任何权限模式都翻不了的硬地板;
|
|
7
|
+
* - 本模块回答「这条命令会不会写到可写根之外 / 要不要联网」,它是**围栏面**,
|
|
8
|
+
* 结论是 allow/prompt/forbidden,forbidden 只代表「沙箱不同意」。
|
|
9
|
+
* 两边共用同一套切段结果(`splitSegments`),所以「一段一段判」这件事只有一份实现。
|
|
10
|
+
*
|
|
11
|
+
* 规则表是内置的:沙箱的策略值不值得让用户手写 DSL,先看有没有人真的想改;
|
|
12
|
+
* 现在给的是 codex 那批机器级改动(计划任务、注册表、网络、ACL、引导)+
|
|
13
|
+
* 一批明确只读的 allow 前缀。`allow` 不等于免审批卡——那是审批层的事(见插件注释)。
|
|
14
|
+
*
|
|
15
|
+
* 边界(老老实实写在这里):这一层认得出**写在命令里的**写目标与网络命令,
|
|
16
|
+
* 认不出「`node build.js` 里那行 fs.writeFile 写了哪」「子进程 curl 拉了哪个地址」。
|
|
17
|
+
* 这就是 `enforcement: partial` 的准确含义。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/sandbox/execpolicy
|
|
20
|
+
*/
|
|
21
|
+
import { splitSegments } from '../command-policy.js';
|
|
22
|
+
/** 命中即 forbidden:机器级改动面(关掉它们等于关掉「改机器」这件事)。 */
|
|
23
|
+
const FORBIDDEN_RULES = [
|
|
24
|
+
{
|
|
25
|
+
name: 'schtasks',
|
|
26
|
+
decision: 'forbidden',
|
|
27
|
+
pattern: ['schtasks'],
|
|
28
|
+
justification: '计划任务能让任意命令常驻执行(后门面),沙箱里不做这件事',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'reg-write',
|
|
32
|
+
decision: 'forbidden',
|
|
33
|
+
pattern: ['reg', 'add'],
|
|
34
|
+
justification: '写注册表是机器级改动,且常被用来做持久化',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'reg-delete',
|
|
38
|
+
decision: 'forbidden',
|
|
39
|
+
pattern: ['reg', 'delete'],
|
|
40
|
+
justification: '删注册表键会破坏已装软件与系统设置',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'reg-import',
|
|
44
|
+
decision: 'forbidden',
|
|
45
|
+
pattern: ['reg', 'import'],
|
|
46
|
+
justification: '导入注册表文件等于一次性写一批机器级配置,内容看不清',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'netsh',
|
|
50
|
+
decision: 'forbidden',
|
|
51
|
+
pattern: ['netsh'],
|
|
52
|
+
justification: '改网络/防火墙配置属于机器级改动',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'bcdedit',
|
|
56
|
+
decision: 'forbidden',
|
|
57
|
+
pattern: ['bcdedit'],
|
|
58
|
+
justification: '改引导配置,写错就开不了机',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'takeown',
|
|
62
|
+
decision: 'forbidden',
|
|
63
|
+
pattern: ['takeown'],
|
|
64
|
+
justification: '抢占文件所有权是提权的前置动作',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'icacls-grant',
|
|
68
|
+
decision: 'forbidden',
|
|
69
|
+
pattern: ['icacls'],
|
|
70
|
+
requires: (segment) => segment.tokens.some((token) => /^\/(grant|setowner|reset|inheritance)/i.test(token)),
|
|
71
|
+
justification: '改文件 ACL / 把权限开给别的账号,等于把数据交出去(只读的 icacls 另说)',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'diskpart',
|
|
75
|
+
decision: 'forbidden',
|
|
76
|
+
pattern: ['diskpart'],
|
|
77
|
+
justification: '分区级操作,数据不可恢复',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'vssadmin',
|
|
81
|
+
decision: 'forbidden',
|
|
82
|
+
pattern: ['vssadmin'],
|
|
83
|
+
justification: '卷影副本是最后的回滚手段,删它等于把退路拆掉',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'wbadmin',
|
|
87
|
+
decision: 'forbidden',
|
|
88
|
+
pattern: ['wbadmin'],
|
|
89
|
+
justification: '改备份与系统状态,写错就失去恢复能力',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'bootrec',
|
|
93
|
+
decision: 'forbidden',
|
|
94
|
+
pattern: ['bootrec'],
|
|
95
|
+
justification: '改引导记录,写错就开不了机',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
/** 明确只读/构建类:允许在沙箱内直接跑(真正免不免审批卡由审批层决定)。 */
|
|
99
|
+
const ALLOW_RULES = [
|
|
100
|
+
{ name: 'git-status', decision: 'allow', pattern: ['git', 'status'], justification: '看仓库状态,只读' },
|
|
101
|
+
{ name: 'git-diff', decision: 'allow', pattern: ['git', 'diff'], justification: '看改动内容,只读' },
|
|
102
|
+
{ name: 'git-log', decision: 'allow', pattern: ['git', 'log'], justification: '看提交历史,只读' },
|
|
103
|
+
{ name: 'list-posix', decision: 'allow', pattern: ['ls'], justification: '列目录,只读' },
|
|
104
|
+
{ name: 'list-win', decision: 'allow', pattern: ['dir'], justification: '列目录,只读' },
|
|
105
|
+
{ name: 'pnpm-build', decision: 'allow', pattern: ['pnpm', 'run', 'build'], justification: '构建工作区,产物落在工作区内' },
|
|
106
|
+
{ name: 'pnpm-test', decision: 'allow', pattern: ['pnpm', 'test'], justification: '跑测试' },
|
|
107
|
+
];
|
|
108
|
+
/** 内置规则表(forbidden 在前,匹配时先看它们)。 */
|
|
109
|
+
export const BUILTIN_EXEC_RULES = [...FORBIDDEN_RULES, ...ALLOW_RULES];
|
|
110
|
+
// ---------------------------------------------------------------- 词元工具
|
|
111
|
+
/** `sudo rm -rf /` 真正跑的是 rm;这些包装词要剥掉。 */
|
|
112
|
+
const WRAPPERS = new Set(['sudo', 'doas', 'command', 'env', 'nohup']);
|
|
113
|
+
/** 取这一段真正要跑的程序名(小写、去 `.exe`、去目录前缀、剥包装词)。 */
|
|
114
|
+
function headOf(tokens) {
|
|
115
|
+
const index = headIndex(tokens);
|
|
116
|
+
return index < 0 ? '' : tokenName(tokens[index]);
|
|
117
|
+
}
|
|
118
|
+
/** 程序名在词元里的下标(-1 = 认不出):操作数循环要跳过它,不然命令名自己会被当成路径。 */
|
|
119
|
+
function headIndex(tokens) {
|
|
120
|
+
let index = 0;
|
|
121
|
+
while (index < tokens.length && WRAPPERS.has(tokenName(tokens[index])))
|
|
122
|
+
index += 1;
|
|
123
|
+
// `env FOO=bar cmd`:跳过环境变量赋值
|
|
124
|
+
while (index < tokens.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[index]))
|
|
125
|
+
index += 1;
|
|
126
|
+
return index < tokens.length ? index : -1;
|
|
127
|
+
}
|
|
128
|
+
/** 词元 → 程序名(去路径、去 `.exe`、小写)。 */
|
|
129
|
+
function tokenName(token) {
|
|
130
|
+
const base = token.split(/[\\/]/).pop() ?? token;
|
|
131
|
+
return base.toLowerCase().replace(/\.exe$/, '');
|
|
132
|
+
}
|
|
133
|
+
/** 前缀匹配:`pattern` 是段词元的前缀,末尾 `*` 表示后面随便。 */
|
|
134
|
+
function matchExecRule(rule, segment) {
|
|
135
|
+
if (segment.tokens.length === 0)
|
|
136
|
+
return false;
|
|
137
|
+
for (let i = 0; i < rule.pattern.length; i += 1) {
|
|
138
|
+
const want = rule.pattern[i];
|
|
139
|
+
if (want === '*')
|
|
140
|
+
break;
|
|
141
|
+
const got = segment.tokens[i];
|
|
142
|
+
if (got === undefined)
|
|
143
|
+
return false;
|
|
144
|
+
if (tokenName(got) !== want.toLowerCase())
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return rule.requires === undefined ? true : rule.requires(segment);
|
|
148
|
+
}
|
|
149
|
+
// ---------------------------------------------------------------- 写目标
|
|
150
|
+
/** 所有非开关词元都是「被改动的路径」(删/建/截断/写内容:源自己就动手了)。 */
|
|
151
|
+
const FULL_WRITE_HEADS = new Set([
|
|
152
|
+
'rm', 'del', 'erase', 'rd', 'rmdir', 'remove-item', 'ri',
|
|
153
|
+
'mkdir', 'md', 'new-item', 'ni', 'touch', 'truncate', 'tee', 'clear-content',
|
|
154
|
+
]);
|
|
155
|
+
/** 只有**最后一个**非开关词元是写目标(源可能在可写根之外,只是读它)。 */
|
|
156
|
+
const COPY_HEADS = new Set(['cp', 'copy', 'copy-item', 'cpi', 'xcopy', 'robocopy']);
|
|
157
|
+
/** 源同样被改动(移走就是删掉),所以所有词元都算目标。 */
|
|
158
|
+
const MOVE_HEADS = new Set(['mv', 'move', 'move-item', 'mi', 'ren', 'rename', 'rename-item', 'rn']);
|
|
159
|
+
/** 写目标是 `-Path` 一类的值,没有就给第一个非开关词元。 */
|
|
160
|
+
const CONTENT_HEADS = new Set(['set-content', 'add-content', 'out-file', 'export-csv', 'export-clixml']);
|
|
161
|
+
/** `-Path` 这一族(写目标用的)。 */
|
|
162
|
+
const PATH_FLAGS = new Set(['-path', '-filepath', '-literalpath', '-file']);
|
|
163
|
+
/** `-Destination` 这一族。 */
|
|
164
|
+
const DEST_FLAGS = new Set(['-destination', '-dest']);
|
|
165
|
+
/**
|
|
166
|
+
* 一个词元是不是开关。
|
|
167
|
+
*
|
|
168
|
+
* Windows 上 `/f`、`/grant`、`/r` 是开关,但 `/tmp/x` 是路径——只把「一个斜杠 +
|
|
169
|
+
* 1~3 个字母且后面没有别的斜杠」当开关。POSIX 上 `/` 开头的都不是开关。
|
|
170
|
+
*/
|
|
171
|
+
function isFlag(token, win32) {
|
|
172
|
+
if (token === '-')
|
|
173
|
+
return true;
|
|
174
|
+
if (token.startsWith('-'))
|
|
175
|
+
return true;
|
|
176
|
+
if (win32 && /^\/[A-Za-z]{1,3}$/.test(token))
|
|
177
|
+
return true;
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
/** 重定向词元 → 写目标(`''` = 目标在下一个词元;null = 不是文件重定向)。 */
|
|
181
|
+
function redirectTarget(token) {
|
|
182
|
+
const match = /^(\d?>>?)(.*)$/.exec(token);
|
|
183
|
+
if (match === null)
|
|
184
|
+
return null;
|
|
185
|
+
const rest = match[2] ?? '';
|
|
186
|
+
// `2>&1`、`>&2` 只是接文件描述符,不落盘
|
|
187
|
+
if (rest.startsWith('&'))
|
|
188
|
+
return null;
|
|
189
|
+
return rest;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 从一段命令里认出所有「会被写到的路径」。
|
|
193
|
+
*
|
|
194
|
+
* 认的是形状,不是语义:`rm`/`mv`/`Set-Content`/`>`/`dd of=` 这些齐了,
|
|
195
|
+
* 但 `bash -c "rm x"`、`node -e "fs.unlinkSync(...)"` 这类藏在参数里的写认不出来——
|
|
196
|
+
* 这正是策略围栏「拦得住工具调用、拦不住命令内部」的那一半。
|
|
197
|
+
*
|
|
198
|
+
* `cp`/`copy` 只算**最后一个**词元(源在可写根之外只是读它,算成写会误拒);
|
|
199
|
+
* `mv`/`rm` 算全部(源被移走或被删,同样是动手)。
|
|
200
|
+
*/
|
|
201
|
+
export function writeTargetsOf(segment, win32) {
|
|
202
|
+
const tokens = segment.tokens;
|
|
203
|
+
const out = [];
|
|
204
|
+
const push = (value) => {
|
|
205
|
+
if (value === undefined)
|
|
206
|
+
return;
|
|
207
|
+
const trimmed = value.trim();
|
|
208
|
+
if (trimmed === '')
|
|
209
|
+
return;
|
|
210
|
+
out.push(trimmed);
|
|
211
|
+
};
|
|
212
|
+
// 1) 重定向:`> x`、`>>x`、`1> x`;`2>&1` 不算
|
|
213
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
214
|
+
const target = redirectTarget(tokens[i]);
|
|
215
|
+
if (target === null)
|
|
216
|
+
continue;
|
|
217
|
+
push(target === '' ? tokens[i + 1] : target);
|
|
218
|
+
}
|
|
219
|
+
// 2) `dd` 的 `of=`(`if=` 是读)
|
|
220
|
+
for (const token of tokens) {
|
|
221
|
+
const match = /^of=(.+)$/i.exec(token);
|
|
222
|
+
if (match !== null)
|
|
223
|
+
push(match[1]);
|
|
224
|
+
}
|
|
225
|
+
const head = headOf(tokens);
|
|
226
|
+
if (head === '')
|
|
227
|
+
return [...new Set(out)];
|
|
228
|
+
// 3) 命令自身的词元(跳过程序名自己)
|
|
229
|
+
const command = headIndex(tokens);
|
|
230
|
+
const operands = [];
|
|
231
|
+
/** 已经用 `-Path`/`-Destination` 指名道姓说过目标了:位置参数不再当路径。 */
|
|
232
|
+
let explicit = false;
|
|
233
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
234
|
+
if (i === command)
|
|
235
|
+
continue;
|
|
236
|
+
const token = tokens[i];
|
|
237
|
+
const redirect = redirectTarget(token);
|
|
238
|
+
if (redirect !== null) {
|
|
239
|
+
// 目标已在第 1 步收过:下一个词元别再当操作数
|
|
240
|
+
if (redirect === '')
|
|
241
|
+
i += 1;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (/^of=/i.test(token))
|
|
245
|
+
continue;
|
|
246
|
+
if (isFlag(token, win32)) {
|
|
247
|
+
const lowered = token.toLowerCase();
|
|
248
|
+
const value = tokens[i + 1];
|
|
249
|
+
if (value !== undefined && !isFlag(value, win32)) {
|
|
250
|
+
if (DEST_FLAGS.has(lowered)) {
|
|
251
|
+
push(value);
|
|
252
|
+
explicit = true;
|
|
253
|
+
i += 1;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (PATH_FLAGS.has(lowered)) {
|
|
257
|
+
// `cp -Path a -Destination b`:a 是源,不算写
|
|
258
|
+
if (!COPY_HEADS.has(head)) {
|
|
259
|
+
push(value);
|
|
260
|
+
explicit = true;
|
|
261
|
+
}
|
|
262
|
+
i += 1;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
operands.push(token);
|
|
269
|
+
}
|
|
270
|
+
// 开关已经指明了目标时,剩下的位置参数多半是别的东西的值(`-Value hello`、`-ItemType Directory`),
|
|
271
|
+
// 一律不再当路径——宁可漏算一个写目标(还有审批卡兜底),也别凭空造出一个越界判断。
|
|
272
|
+
if (explicit)
|
|
273
|
+
return [...new Set(out)];
|
|
274
|
+
if (COPY_HEADS.has(head)) {
|
|
275
|
+
push(operands[operands.length - 1]);
|
|
276
|
+
}
|
|
277
|
+
else if (MOVE_HEADS.has(head) || FULL_WRITE_HEADS.has(head)) {
|
|
278
|
+
for (const operand of operands)
|
|
279
|
+
push(operand);
|
|
280
|
+
}
|
|
281
|
+
else if (CONTENT_HEADS.has(head)) {
|
|
282
|
+
// 只认位置参数里的第一个(`Set-Content x.txt -Value hello` 的 hello 不是路径)
|
|
283
|
+
push(operands[0]);
|
|
284
|
+
}
|
|
285
|
+
return [...new Set(out)];
|
|
286
|
+
}
|
|
287
|
+
// ---------------------------------------------------------------- 网络命令
|
|
288
|
+
/** 一级词元就是网络工具的。 */
|
|
289
|
+
const NETWORK_HEADS = new Set([
|
|
290
|
+
'curl', 'wget', 'iwr', 'invoke-webrequest', 'irm', 'invoke-restmethod',
|
|
291
|
+
'nc', 'ncat', 'netcat', 'telnet', 'ftp', 'ssh', 'scp', 'sftp', 'rsync',
|
|
292
|
+
'test-netconnection', 'resolve-dnsname', 'gh',
|
|
293
|
+
]);
|
|
294
|
+
/** 「程序 + 子命令」形态的网络动作。 */
|
|
295
|
+
const NETWORK_SUBCOMMANDS = {
|
|
296
|
+
npm: new Set(['install', 'i', 'ci', 'add', 'create', 'update', 'publish', 'dlx', 'exec', 'x']),
|
|
297
|
+
npx: new Set(['*']),
|
|
298
|
+
pnpm: new Set(['install', 'i', 'add', 'update', 'publish', 'dlx', 'create', 'exec']),
|
|
299
|
+
yarn: new Set(['install', 'add', 'upgrade', 'publish', 'dlx', 'create']),
|
|
300
|
+
git: new Set(['clone', 'fetch', 'pull', 'push', 'ls-remote', 'submodule', 'archive']),
|
|
301
|
+
pip: new Set(['install', 'download']),
|
|
302
|
+
pip3: new Set(['install', 'download']),
|
|
303
|
+
cargo: new Set(['install', 'add', 'update', 'publish', 'login']),
|
|
304
|
+
go: new Set(['get', 'install']),
|
|
305
|
+
docker: new Set(['pull', 'push', 'login', 'run', 'build']),
|
|
306
|
+
dotnet: new Set(['restore', 'add', 'nuget', 'tool']),
|
|
307
|
+
apt: new Set(['install', 'update', 'upgrade']),
|
|
308
|
+
'apt-get': new Set(['install', 'update', 'upgrade']),
|
|
309
|
+
yum: new Set(['install', 'update']),
|
|
310
|
+
dnf: new Set(['install', 'update']),
|
|
311
|
+
apk: new Set(['add', 'update']),
|
|
312
|
+
brew: new Set(['install', 'update', 'upgrade']),
|
|
313
|
+
choco: new Set(['install', 'upgrade']),
|
|
314
|
+
winget: new Set(['install', 'upgrade', 'search']),
|
|
315
|
+
scoop: new Set(['install', 'update']),
|
|
316
|
+
nuget: new Set(['install', 'restore']),
|
|
317
|
+
};
|
|
318
|
+
/** 这一段要不要联网。 */
|
|
319
|
+
export function isNetworkSegment(segment, win32 = process.platform === 'win32') {
|
|
320
|
+
const head = headOf(segment.tokens);
|
|
321
|
+
if (head === '')
|
|
322
|
+
return false;
|
|
323
|
+
if (NETWORK_HEADS.has(head))
|
|
324
|
+
return true;
|
|
325
|
+
const subs = NETWORK_SUBCOMMANDS[head];
|
|
326
|
+
if (subs === undefined)
|
|
327
|
+
return false;
|
|
328
|
+
if (subs.has('*'))
|
|
329
|
+
return true;
|
|
330
|
+
// 子命令可能被开关夹在中间(`npm --silent install`):取第一个非开关词元
|
|
331
|
+
const sub = segment.tokens.slice(1).find((token) => !isFlag(token, win32));
|
|
332
|
+
if (sub === undefined)
|
|
333
|
+
return false;
|
|
334
|
+
return subs.has(tokenName(sub));
|
|
335
|
+
}
|
|
336
|
+
// ---------------------------------------------------------------- 判定入口
|
|
337
|
+
/** 认得出的「把命令写在参数里」的 shell:它们后面那段要再拆一次判。 */
|
|
338
|
+
const INLINE_SHELL_HEADS = new Set(['powershell', 'pwsh', 'cmd', 'sh', 'bash', 'zsh', 'dash', 'ksh']);
|
|
339
|
+
/** 内层命令的开关名(按平台各自习惯,两边都认,宽进严出)。 */
|
|
340
|
+
const INLINE_SHELL_FLAGS = new Set(['-command', '-c', '/c', '/k']);
|
|
341
|
+
/**
|
|
342
|
+
* 这一段是不是「跑一段写在参数里的脚本」:是的话把那段脚本原文交出来。
|
|
343
|
+
*
|
|
344
|
+
* 为什么必须拆:`powershell -Command "Set-Content -Path C:\outside\x -Value y"` 的写目标
|
|
345
|
+
* 藏在引号里,只看外层这一个词元(`powershell`)什么都看不出来——这是最常见的绕过写法。
|
|
346
|
+
* 只认开关后面的那段(`sh -c rm x` 这种没加引号的按空格拼回去),认不出就不猜。
|
|
347
|
+
*
|
|
348
|
+
* @returns 内层命令原文;不是这种形态返回 null。
|
|
349
|
+
*/
|
|
350
|
+
export function innerShellCommand(segment, win32) {
|
|
351
|
+
const head = headOf(segment.tokens);
|
|
352
|
+
if (!INLINE_SHELL_HEADS.has(head))
|
|
353
|
+
return null;
|
|
354
|
+
const start = headIndex(segment.tokens);
|
|
355
|
+
for (let i = start + 1; i < segment.tokens.length; i += 1) {
|
|
356
|
+
if (!INLINE_SHELL_FLAGS.has(segment.tokens[i].toLowerCase()))
|
|
357
|
+
continue;
|
|
358
|
+
const rest = segment.tokens.slice(i + 1);
|
|
359
|
+
return rest.length === 0 ? null : rest.join(' ');
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 把命令摊平成待判定的段:外层照旧保留(它的重定向还得看),
|
|
365
|
+
* 认得出的内层脚本再拆一次(最多两层,够覆盖 `powershell -Command "sh -c ..."` 这种叠法)。
|
|
366
|
+
*/
|
|
367
|
+
function expandSegments(command, win32, depth = 0) {
|
|
368
|
+
const out = [];
|
|
369
|
+
for (const segment of splitSegments(command)) {
|
|
370
|
+
if (depth < 2) {
|
|
371
|
+
const inner = innerShellCommand(segment, win32);
|
|
372
|
+
if (inner !== null && inner.trim() !== '')
|
|
373
|
+
out.push(...expandSegments(inner, win32, depth + 1));
|
|
374
|
+
}
|
|
375
|
+
out.push(segment);
|
|
376
|
+
}
|
|
377
|
+
return out;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* 判一条命令。
|
|
381
|
+
*
|
|
382
|
+
* 逐段判(`|`、`;`、`&&` 切开),任何一段 forbidden 就是整条 forbidden;
|
|
383
|
+
* 全部只读放行才是 allow;其余是 prompt(交审批卡)。
|
|
384
|
+
* 顺序:内置 forbidden 规则 → 网络开关 → 写目标归属 → allow 规则。
|
|
385
|
+
* 带重定向/变量/子 shell 的段不给走 allow 规则(照 codex 那条「结构不可验证就不放行」)。
|
|
386
|
+
* 内层脚本(`powershell -Command "..."`、`sh -c ...`)会再拆一层一起判——
|
|
387
|
+
* 不拆的话写目标藏在引号里,等于没有围栏。
|
|
388
|
+
*/
|
|
389
|
+
export function evaluateCommand(command, options) {
|
|
390
|
+
const rules = options.rules ?? BUILTIN_EXEC_RULES;
|
|
391
|
+
const win32 = options.win32 ?? process.platform === 'win32';
|
|
392
|
+
const segments = expandSegments(command, win32);
|
|
393
|
+
const writeTargets = [];
|
|
394
|
+
let network = false;
|
|
395
|
+
let decision = 'allow';
|
|
396
|
+
const loose = [];
|
|
397
|
+
for (const segment of segments) {
|
|
398
|
+
if (segment.tokens.length === 0)
|
|
399
|
+
continue;
|
|
400
|
+
const forbidden = rules.find((rule) => rule.decision === 'forbidden' && matchExecRule(rule, segment));
|
|
401
|
+
if (forbidden !== undefined) {
|
|
402
|
+
return {
|
|
403
|
+
decision: 'forbidden',
|
|
404
|
+
rule: forbidden.name,
|
|
405
|
+
reason: `命令规则「${forbidden.name}」禁止这一段:${forbidden.justification}`,
|
|
406
|
+
writeTargets,
|
|
407
|
+
network,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (isNetworkSegment(segment, win32)) {
|
|
411
|
+
network = true;
|
|
412
|
+
if (!options.networkAccess) {
|
|
413
|
+
return {
|
|
414
|
+
decision: 'forbidden',
|
|
415
|
+
rule: 'network-off',
|
|
416
|
+
reason: `这一段要联网(${segment.raw.trim()}),而沙箱的网络开关是关的`,
|
|
417
|
+
writeTargets,
|
|
418
|
+
network,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
for (const target of writeTargetsOf(segment, win32)) {
|
|
423
|
+
writeTargets.push(target);
|
|
424
|
+
const check = options.checkWrite(target);
|
|
425
|
+
if (!check.allowed) {
|
|
426
|
+
return {
|
|
427
|
+
decision: 'forbidden',
|
|
428
|
+
rule: `write-target:${check.rule}`,
|
|
429
|
+
reason: `命令里的写目标落不住:${check.reason}`,
|
|
430
|
+
writeTargets,
|
|
431
|
+
network,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const allowed = !segment.ruleUnfriendly && rules.some((rule) => rule.decision === 'allow' && matchExecRule(rule, segment));
|
|
436
|
+
if (!allowed) {
|
|
437
|
+
decision = 'prompt';
|
|
438
|
+
loose.push(segment.raw.trim());
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (decision === 'allow') {
|
|
442
|
+
return { decision: 'allow', rule: 'allow-rule', reason: '各段都命中放行规则(只读/构建)', writeTargets, network };
|
|
443
|
+
}
|
|
444
|
+
const shown = loose.slice(0, 3).join(';');
|
|
445
|
+
return {
|
|
446
|
+
decision: 'prompt',
|
|
447
|
+
rule: 'default',
|
|
448
|
+
reason: `没命中沙箱的放行规则,按默认交给审批卡:${shown}`,
|
|
449
|
+
writeTargets,
|
|
450
|
+
network,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 代理运行状态与最近若干条放行/阻断记录(`/sandbox` 诊断用)。 */
|
|
2
|
+
export interface ProxyLogEntry {
|
|
3
|
+
at: number;
|
|
4
|
+
host: string;
|
|
5
|
+
port: string;
|
|
6
|
+
allowed: boolean;
|
|
7
|
+
why: string;
|
|
8
|
+
}
|
|
9
|
+
export interface NetProxy {
|
|
10
|
+
/** 实际监听端口(探测可用端口后确定)。 */
|
|
11
|
+
readonly port: number;
|
|
12
|
+
/** 给子进程环境用的代理地址:`http://127.0.0.1:<port>`。 */
|
|
13
|
+
readonly url: string;
|
|
14
|
+
/** 最近一次请求起的日志(新的在后,环形,最多 keep 条)。 */
|
|
15
|
+
log(): readonly ProxyLogEntry[];
|
|
16
|
+
/** 停掉监听并断开全部在途连接。 */
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface NetProxyOptions {
|
|
20
|
+
/** 现取的网络总开关(关 = 全部阻断)。 */
|
|
21
|
+
online: () => boolean;
|
|
22
|
+
/** 现取的域名白名单(每次请求现读,改设置立刻生效)。 */
|
|
23
|
+
allowlist: () => readonly string[];
|
|
24
|
+
/** 指定端口(默认 0 = 由系统挑一个空闲口)。 */
|
|
25
|
+
port?: number;
|
|
26
|
+
/** 日志条数上限(默认 50)。 */
|
|
27
|
+
keep?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function createNetProxy(options: NetProxyOptions): Promise<NetProxy>;
|
|
30
|
+
/** 给子进程环境注入的代理变量(大小写都给:不同工具认不同的键)。 */
|
|
31
|
+
export declare function proxyEnvVars(url: string): Record<string, string>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 出网白名单代理:windows-token 后端的网络出口。
|
|
3
|
+
*
|
|
4
|
+
* 为什么是「代理 + 域名白名单」而不是直接放网络:
|
|
5
|
+
* 沙箱子进程的网络被 WFP/防火墙挡到只剩回环(见 setup 脚本),它唯一能碰到的
|
|
6
|
+
* 外部服务就是本进程里这个代理。代理按域名清单放行 CONNECT 与绝对形式 HTTP,
|
|
7
|
+
* 其余一律 403——于是**任何**出网流量都必须经过这份清单,不管子进程认不认
|
|
8
|
+
* HTTP_PROXY 环境变量(不认的直连会被 WFP 拦死,两道锁是互补的,不是重复的)。
|
|
9
|
+
*
|
|
10
|
+
* 刻意不做 TLS 解密(codex 的 network-proxy 做了 MITM):解密需要给沙箱账号装根证书、
|
|
11
|
+
* 且会撞证书固定。对「管控」这个目的,CONNECT 头里的域名就是子进程想去的地方——
|
|
12
|
+
* 代理只把流量中继给它声明的主机,中间人解密带来的只是「看得见」,不是「管得住」。
|
|
13
|
+
* 管控强度不因省掉 MITM 而下降:没进清单的域名一个字节都出不去。
|
|
14
|
+
*
|
|
15
|
+
* 纯 node:http/net/dns,无新依赖;DNS 由代理代查(子进程的 53 端口出不去)。
|
|
16
|
+
*
|
|
17
|
+
* @module dsc/core/sandbox/net-proxy
|
|
18
|
+
*/
|
|
19
|
+
import { createServer, request as httpRequest } from 'node:http';
|
|
20
|
+
import { connect as tcpConnect } from 'node:net';
|
|
21
|
+
import { allowlistMatches } from './policy.js';
|
|
22
|
+
/** 回环地址族:代理只听这些,不给外面开面。 */
|
|
23
|
+
const LOOPBACK_HOST = '127.0.0.1';
|
|
24
|
+
/** CONNECT / 绝对形式 HTTP 请求里的 `host:port`。 */
|
|
25
|
+
function parseAuthority(authority) {
|
|
26
|
+
const index = authority.lastIndexOf(':');
|
|
27
|
+
if (index <= 0)
|
|
28
|
+
return null;
|
|
29
|
+
const host = authority.slice(0, index).trim().toLowerCase().replace(/^\[|\]$/g, '');
|
|
30
|
+
const port = authority.slice(index + 1).trim();
|
|
31
|
+
if (host === '' || !/^\d{1,5}$/.test(port))
|
|
32
|
+
return null;
|
|
33
|
+
const numeric = Number(port);
|
|
34
|
+
if (numeric < 1 || numeric > 65535)
|
|
35
|
+
return null;
|
|
36
|
+
return { host, port };
|
|
37
|
+
}
|
|
38
|
+
/** 绝对形式 HTTP 请求行里的 URL → `host:port`;不是绝对形式给 null。 */
|
|
39
|
+
function parseAbsoluteUrl(raw) {
|
|
40
|
+
const match = /^https?:\/\/([^/?#]+)/i.exec(raw);
|
|
41
|
+
if (match === null)
|
|
42
|
+
return parseAuthority(''); // 非 URL:不是代理形态
|
|
43
|
+
return parseAuthority(match[1]);
|
|
44
|
+
}
|
|
45
|
+
export function createNetProxy(options) {
|
|
46
|
+
const keep = options.keep ?? 50;
|
|
47
|
+
const logBuffer = [];
|
|
48
|
+
const sockets = new Set();
|
|
49
|
+
const record = (entry) => {
|
|
50
|
+
logBuffer.push(entry);
|
|
51
|
+
if (logBuffer.length > keep)
|
|
52
|
+
logBuffer.shift();
|
|
53
|
+
};
|
|
54
|
+
/** 这一次请求放不放行:总开关 + 白名单,一条不满足就给拒因。 */
|
|
55
|
+
const verdict = (host) => {
|
|
56
|
+
if (!options.online())
|
|
57
|
+
return { allowed: false, why: '网络开关是关的(沙箱档位)' };
|
|
58
|
+
const list = options.allowlist();
|
|
59
|
+
if (allowlistMatches(host, list))
|
|
60
|
+
return { allowed: true };
|
|
61
|
+
return {
|
|
62
|
+
allowed: false,
|
|
63
|
+
why: list.length === 0 ? '白名单是空的(开了网也没放任何域名)' : `不在出网白名单里(清单 ${String(list.length)} 项)`,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const server = createServer((req, res) => {
|
|
67
|
+
// 绝对形式(代理语义)按 URL 判;相对形式按 Host 头判(host*port 缺口视为 80)。
|
|
68
|
+
const parsed = req.url !== undefined && /^https?:\/\//i.test(req.url)
|
|
69
|
+
? parseAbsoluteUrl(req.url)
|
|
70
|
+
: parseAuthority(req.headers.host ?? '');
|
|
71
|
+
if (parsed === null) {
|
|
72
|
+
res.writeHead(400).end('dsc 沙箱代理:认不出目标主机');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const one = verdict(parsed.host);
|
|
76
|
+
record({ at: Date.now(), host: parsed.host, port: parsed.port, allowed: one.allowed, why: one.allowed ? '在白名单里' : one.why });
|
|
77
|
+
if (!one.allowed) {
|
|
78
|
+
res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
|
|
79
|
+
res.end(`dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「设置 → 沙箱」把它加进出网白名单。`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// 放行:按原样转发(去代理语义的 URL 前缀),流式直通不缓存
|
|
83
|
+
const upstream = httpRequest({
|
|
84
|
+
host: parsed.host,
|
|
85
|
+
port: Number(parsed.port),
|
|
86
|
+
path: req.url ?? '/',
|
|
87
|
+
method: req.method,
|
|
88
|
+
headers: { ...req.headers, host: `${parsed.host}:${parsed.port}`, proxy_connection: undefined, 'proxy-authorization': undefined },
|
|
89
|
+
});
|
|
90
|
+
upstream.on('error', () => {
|
|
91
|
+
if (!res.headersSent)
|
|
92
|
+
res.writeHead(502).end(`dsc 沙箱代理:连不上 ${parsed.host}:${parsed.port}`);
|
|
93
|
+
else
|
|
94
|
+
res.destroy();
|
|
95
|
+
});
|
|
96
|
+
req.pipe(upstream);
|
|
97
|
+
upstream.pipe(res);
|
|
98
|
+
});
|
|
99
|
+
// CONNECT:只认目标主机并做双向裸中继(TLS 原样透传,不落盘不看内容)
|
|
100
|
+
server.on('connect', (req, socket, head) => {
|
|
101
|
+
const parsed = parseAuthority(req.url ?? '');
|
|
102
|
+
if (parsed === null) {
|
|
103
|
+
socket.write('HTTP/1.1 400 Bad Request\r\n\r\n');
|
|
104
|
+
socket.destroy();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const one = verdict(parsed.host);
|
|
108
|
+
record({ at: Date.now(), host: parsed.host, port: parsed.port, allowed: one.allowed, why: one.allowed ? '在白名单里' : one.why });
|
|
109
|
+
if (!one.allowed) {
|
|
110
|
+
const body = `dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「设置 → 沙箱」把它加进出网白名单。`;
|
|
111
|
+
socket.write(`HTTP/1.1 403 Forbidden\r\ncontent-type: text/plain; charset=utf-8\r\ncontent-length: ${Buffer.byteLength(body)}\r\n\r\n${body}`);
|
|
112
|
+
socket.destroy();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const upstream = tcpConnect(Number(parsed.port), parsed.host, () => {
|
|
116
|
+
socket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
|
117
|
+
if (head.length > 0)
|
|
118
|
+
upstream.write(head);
|
|
119
|
+
upstream.pipe(socket);
|
|
120
|
+
socket.pipe(upstream);
|
|
121
|
+
});
|
|
122
|
+
upstream.on('error', () => {
|
|
123
|
+
socket.write('HTTP/1.1 502 Bad Gateway\r\n\r\n');
|
|
124
|
+
socket.destroy();
|
|
125
|
+
});
|
|
126
|
+
sockets.add(upstream);
|
|
127
|
+
sockets.add(socket);
|
|
128
|
+
upstream.on('close', () => sockets.delete(upstream));
|
|
129
|
+
socket.on('close', () => sockets.delete(socket));
|
|
130
|
+
});
|
|
131
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
132
|
+
server.once('error', rejectPromise);
|
|
133
|
+
server.listen(options.port ?? 0, LOOPBACK_HOST, () => {
|
|
134
|
+
const address = server.address();
|
|
135
|
+
const port = typeof address === 'object' && address !== null ? address.port : 0;
|
|
136
|
+
resolvePromise({
|
|
137
|
+
port,
|
|
138
|
+
url: `http://${LOOPBACK_HOST}:${String(port)}`,
|
|
139
|
+
log: () => [...logBuffer],
|
|
140
|
+
close: () => {
|
|
141
|
+
for (const socket of sockets)
|
|
142
|
+
socket.destroy();
|
|
143
|
+
sockets.clear();
|
|
144
|
+
server.close();
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/** 给子进程环境注入的代理变量(大小写都给:不同工具认不同的键)。 */
|
|
151
|
+
export function proxyEnvVars(url) {
|
|
152
|
+
return {
|
|
153
|
+
HTTP_PROXY: url,
|
|
154
|
+
HTTPS_PROXY: url,
|
|
155
|
+
http_proxy: url,
|
|
156
|
+
https_proxy: url,
|
|
157
|
+
ALL_PROXY: url,
|
|
158
|
+
all_proxy: url,
|
|
159
|
+
NO_PROXY: '',
|
|
160
|
+
no_proxy: '',
|
|
161
|
+
};
|
|
162
|
+
}
|