@waq666/pneuma 0.0.0-stage → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +206 -3
- 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 +15 -0
- package/lib/app/App.js +1650 -0
- package/lib/app/App.js.nv-backup +1650 -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 +63 -0
- package/lib/app/ChatView.js +310 -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 +201 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/TimelineRail.d.ts +22 -0
- package/lib/app/TimelineRail.js +160 -0
- package/lib/app/TimelineRail.js.negbak +98 -0
- package/lib/app/TimelineRail.js.nv-backup +160 -0
- package/lib/app/ToolCard.d.ts +11 -0
- package/lib/app/ToolCard.js +64 -0
- package/lib/app/ToolCard.js.nv-backup +64 -0
- package/lib/app/TranscriptOverlay.d.ts +27 -0
- package/lib/app/TranscriptOverlay.js +36 -0
- package/lib/app/TranscriptViewport.d.ts +78 -0
- package/lib/app/TranscriptViewport.js +218 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +71 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +40 -0
- package/lib/app/click.js +103 -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/keymap.d.ts +56 -0
- package/lib/app/keymap.js +56 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/mouse.d.ts +33 -0
- package/lib/app/mouse.js +35 -0
- package/lib/app/pointer.d.ts +16 -0
- package/lib/app/pointer.js +60 -0
- package/lib/app/scroll-model.d.ts +240 -0
- package/lib/app/scroll-model.js +347 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/snapshot-subscribe.d.ts +34 -0
- package/lib/app/snapshot-subscribe.js +110 -0
- package/lib/app/theme.d.ts +194 -0
- package/lib/app/theme.js +186 -0
- package/lib/app/ticker.d.ts +7 -0
- package/lib/app/ticker.js +53 -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 +283 -0
- package/lib/core/llm.js +565 -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 +896 -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 +434 -0
- package/lib/plugins/tool-search.js.nv-backup +434 -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,679 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 审批灾难地板:排在守卫链最前面(order 5)的一道硬闸,自己判、自己拒,不等任何人放行。
|
|
3
|
+
*
|
|
4
|
+
* 为什么必须在 order 5:守卫链是「第一位给出 deny 或 pass 的赢」(`core/tool-guards.ts:99-113`)。
|
|
5
|
+
* 协作模式闸门挂在 order 10,计划档与免打扰档在若干情形直接返回 pass(`core/modes.ts:104`、`:135`),
|
|
6
|
+
* 它一返回 pass,后面 order 20 的安全钩子与 order 30 的审批就再也拿不到发言权;
|
|
7
|
+
* 权限模式的「完全访问」还会在审批层直接放行(`plugins/approval.ts:334-337`)。
|
|
8
|
+
* 所以「灾难命令连满权限也不许跑」这件事只能由排在它们前面的一位自己完成。
|
|
9
|
+
*
|
|
10
|
+
* 求值顺序(每层都不依赖后面的层,fail-closed 的理由写在各分支上):
|
|
11
|
+
* 1. 结构不可验证 → deny
|
|
12
|
+
* 2. 灾难地板 → deny
|
|
13
|
+
* 3. 用户 deny 黑名单 → deny(先于完全访问生效)
|
|
14
|
+
* 4. 危险模式 → 无人值守才 deny,否则 defer 交审批
|
|
15
|
+
* 5. 命令白名单 → defer,并由 whitelist() 交给审批层免卡放行(不自己 pass)
|
|
16
|
+
* 6. 无人值守兜底 → 白名单之外、需要确认的命令与工作区外的写 deny
|
|
17
|
+
* 7. 其余 → defer
|
|
18
|
+
*
|
|
19
|
+
* 地板只判「拒」或「不拒」,「不拒」一律走 defer。自己 return pass 会把后面的安全钩子
|
|
20
|
+
* 一起跳掉,那等于白名单连带免掉了用户自己的闸门。
|
|
21
|
+
*
|
|
22
|
+
* @module dsc/core/approval-floor
|
|
23
|
+
*/
|
|
24
|
+
import { audit } from './audit.js';
|
|
25
|
+
import { builtinDangerHit, classifyCommand, splitSegments } from './command-policy.js';
|
|
26
|
+
import { isInsideCwd } from './path-policy.js';
|
|
27
|
+
import { argsSummary } from './tools.js';
|
|
28
|
+
/** 配置键:插件条目树里的 file,同时是设置分区 id。 */
|
|
29
|
+
export const FLOOR_CONFIG_KEY = 'approval-floor';
|
|
30
|
+
/** 可调值的合法区间(配置校验与设置页共用一份,两处不会写岔)。 */
|
|
31
|
+
export const FLOOR_LIMITS = {
|
|
32
|
+
maxCommandLength: { min: 100, max: 100_000 },
|
|
33
|
+
circuitBreakerThreshold: { min: 1, max: 100 },
|
|
34
|
+
circuitBreakerCooldownMs: { min: 0, max: 3_600_000 },
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 默认白名单:这些前缀本来会被判成「要问」,但它们是常见工程命令,跑起来只读源码或只产出构建物。
|
|
38
|
+
* 逗号与换行都可以用,设置页那个文本框按这两种分隔符切。
|
|
39
|
+
*/
|
|
40
|
+
const DEFAULT_ALLOW_PREFIXES = [
|
|
41
|
+
'pnpm run build',
|
|
42
|
+
'pnpm run test',
|
|
43
|
+
'pnpm run typecheck',
|
|
44
|
+
'pnpm run lint',
|
|
45
|
+
'npm run build',
|
|
46
|
+
'npm run test',
|
|
47
|
+
'npm test',
|
|
48
|
+
'yarn build',
|
|
49
|
+
'yarn test',
|
|
50
|
+
'cargo build',
|
|
51
|
+
'cargo test',
|
|
52
|
+
'cargo check',
|
|
53
|
+
'go build',
|
|
54
|
+
'go test',
|
|
55
|
+
'python -m pytest',
|
|
56
|
+
'pytest',
|
|
57
|
+
];
|
|
58
|
+
/**
|
|
59
|
+
* 默认 deny 黑名单:这些字符串出现在命令原文、命令词元或写目标路径里就拒。
|
|
60
|
+
* glob 里的 `*` 配任意字符(含路径分隔符),`?` 配一个字符,其余按字面量。
|
|
61
|
+
* 黑名单宁可多拦:写宽了要用户自己认,写窄了漏一次就收不回来。
|
|
62
|
+
*/
|
|
63
|
+
const DEFAULT_DENY_GLOBS = [
|
|
64
|
+
'*etc/passwd*',
|
|
65
|
+
'*etc/shadow*',
|
|
66
|
+
'*etc/sudoers*',
|
|
67
|
+
'*.ssh/*',
|
|
68
|
+
'*.aws/*',
|
|
69
|
+
'*.gnupg/*',
|
|
70
|
+
'*.env',
|
|
71
|
+
'*.env.*',
|
|
72
|
+
'*.pem',
|
|
73
|
+
'*.key',
|
|
74
|
+
'*.pfx',
|
|
75
|
+
'*.p12',
|
|
76
|
+
'*credentials.yaml',
|
|
77
|
+
'*credentials.yml',
|
|
78
|
+
'*id_rsa*',
|
|
79
|
+
'*id_ed25519*',
|
|
80
|
+
];
|
|
81
|
+
/** 用户没写过的字段用这里的值。 */
|
|
82
|
+
export const DEFAULT_FLOOR_CONFIG = {
|
|
83
|
+
allowPrefixes: DEFAULT_ALLOW_PREFIXES.map((entry) => entry.split(/\s+/)),
|
|
84
|
+
denyGlobs: [...DEFAULT_DENY_GLOBS],
|
|
85
|
+
maxCommandLength: 4000,
|
|
86
|
+
circuitBreakerThreshold: 5,
|
|
87
|
+
circuitBreakerCooldownMs: 60_000,
|
|
88
|
+
circuitBreakerEnabled: true,
|
|
89
|
+
unattended: false,
|
|
90
|
+
};
|
|
91
|
+
/** 词元里出现这些字符的前缀不许写进白名单:它们是 shell 的语法,不是命令的词。 */
|
|
92
|
+
const PREFIX_FORBIDDEN = /[*?`$;&|<>()\\\n\r!'{}^%"']/;
|
|
93
|
+
/**
|
|
94
|
+
* 把设置页里的一行字解析成白名单前缀。
|
|
95
|
+
*
|
|
96
|
+
* @param text - 一行前缀,例如 `pnpm run build` 或 `git diff *`。
|
|
97
|
+
* @returns 解析好的词元数组,或一句说明哪里不能用。
|
|
98
|
+
*/
|
|
99
|
+
export function parsePrefixEntry(text) {
|
|
100
|
+
const tokens = text.trim().split(/\s+/).filter((token) => token !== '');
|
|
101
|
+
if (tokens.length === 0)
|
|
102
|
+
return { ok: false, error: '空的一行' };
|
|
103
|
+
const starAt = tokens.indexOf('*');
|
|
104
|
+
if (starAt >= 0 && starAt !== tokens.length - 1)
|
|
105
|
+
return { ok: false, error: '`*` 只能放在末尾' };
|
|
106
|
+
for (const token of tokens) {
|
|
107
|
+
if (token === '*')
|
|
108
|
+
continue;
|
|
109
|
+
if (PREFIX_FORBIDDEN.test(token))
|
|
110
|
+
return { ok: false, error: `词元「${token}」里有 shell 特殊字符` };
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, pattern: tokens };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 检查一条 deny glob 能不能用。
|
|
116
|
+
*
|
|
117
|
+
* @param text - 一行 glob,例如 `*etc/passwd*`。
|
|
118
|
+
* @returns 去掉首尾空白后的 glob,或一句说明哪里不能用。
|
|
119
|
+
*/
|
|
120
|
+
export function parseGlobEntry(text) {
|
|
121
|
+
const glob = text.trim();
|
|
122
|
+
if (glob === '')
|
|
123
|
+
return { ok: false, error: '空的一行' };
|
|
124
|
+
if (compiledGlob(glob) === null)
|
|
125
|
+
return { ok: false, error: '这条 glob 编译不成正则' };
|
|
126
|
+
return { ok: true, glob };
|
|
127
|
+
}
|
|
128
|
+
/** 把设置页那个文本框切成一条条规则:换行或逗号分隔,空行丢掉。 */
|
|
129
|
+
export function splitListText(text) {
|
|
130
|
+
return text
|
|
131
|
+
.split(/[\n,]/)
|
|
132
|
+
.map((item) => item.trim())
|
|
133
|
+
.filter((item) => item !== '');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 解析设置页里的一整份前缀清单。
|
|
137
|
+
* @param text - 多行文本(换行或逗号分隔)。
|
|
138
|
+
* @returns 规范化后的前缀清单,或第一处错误。
|
|
139
|
+
*/
|
|
140
|
+
export function parsePrefixListText(text) {
|
|
141
|
+
const values = [];
|
|
142
|
+
for (const entry of splitListText(text)) {
|
|
143
|
+
const parsed = parsePrefixEntry(entry);
|
|
144
|
+
if (!parsed.ok)
|
|
145
|
+
return { ok: false, error: `前缀「${entry}」用不了:${parsed.error}` };
|
|
146
|
+
values.push(parsed.pattern.join(' '));
|
|
147
|
+
}
|
|
148
|
+
if (values.length === 0)
|
|
149
|
+
return { ok: false, error: '白名单不能是空的:要恢复默认值,请在插件配置里删掉 allowPrefixes 这一项' };
|
|
150
|
+
return { ok: true, values };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 解析设置页里的一整份 deny 黑名单。
|
|
154
|
+
* @param text - 多行文本(换行或逗号分隔)。
|
|
155
|
+
* @returns 规范化后的 glob 清单,或第一处错误。
|
|
156
|
+
*/
|
|
157
|
+
export function parseGlobListText(text) {
|
|
158
|
+
const values = [];
|
|
159
|
+
for (const entry of splitListText(text)) {
|
|
160
|
+
const parsed = parseGlobEntry(entry);
|
|
161
|
+
if (!parsed.ok)
|
|
162
|
+
return { ok: false, error: `黑名单「${entry}」用不了:${parsed.error}` };
|
|
163
|
+
values.push(parsed.glob);
|
|
164
|
+
}
|
|
165
|
+
if (values.length === 0)
|
|
166
|
+
return { ok: false, error: '黑名单不能是空的:要恢复默认值,请在插件配置里删掉 denyGlobs 这一项' };
|
|
167
|
+
return { ok: true, values };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 把一份原始配置(`resolvePluginConfig` 的返回值)解析成生效配置。
|
|
171
|
+
*
|
|
172
|
+
* 坏值一律回落到默认值并把原因写进 `problems`;调用方据此一律拒,
|
|
173
|
+
* 绝不静默采用半份配置——地板的配置读错了就是 fail-open。
|
|
174
|
+
*
|
|
175
|
+
* @param raw - 原始配置对象,可以是任何东西(磁盘上的东西不受类型系统保证)。
|
|
176
|
+
* @returns 生效配置与配置问题清单。
|
|
177
|
+
*/
|
|
178
|
+
export function resolveFloorConfig(raw) {
|
|
179
|
+
if (raw !== undefined && raw !== null && (typeof raw !== 'object' || Array.isArray(raw))) {
|
|
180
|
+
return { config: DEFAULT_FLOOR_CONFIG, problems: ['配置不是一个对象'] };
|
|
181
|
+
}
|
|
182
|
+
const doc = raw === null || raw === undefined ? {} : raw;
|
|
183
|
+
const problems = [];
|
|
184
|
+
const allowPrefixes = readPrefixes(doc.allowPrefixes, problems);
|
|
185
|
+
const denyGlobs = readGlobs(doc.denyGlobs, problems);
|
|
186
|
+
const maxCommandLength = readInt(doc.maxCommandLength, FLOOR_LIMITS.maxCommandLength, DEFAULT_FLOOR_CONFIG.maxCommandLength, 'maxCommandLength', problems);
|
|
187
|
+
const circuitBreakerThreshold = readInt(doc.circuitBreakerThreshold, FLOOR_LIMITS.circuitBreakerThreshold, DEFAULT_FLOOR_CONFIG.circuitBreakerThreshold, 'circuitBreakerThreshold', problems);
|
|
188
|
+
const circuitBreakerCooldownMs = readInt(doc.circuitBreakerCooldownMs, FLOOR_LIMITS.circuitBreakerCooldownMs, DEFAULT_FLOOR_CONFIG.circuitBreakerCooldownMs, 'circuitBreakerCooldownMs', problems);
|
|
189
|
+
const circuitBreakerEnabled = readBool(doc.circuitBreakerEnabled, DEFAULT_FLOOR_CONFIG.circuitBreakerEnabled, 'circuitBreakerEnabled', problems);
|
|
190
|
+
const unattended = readBool(doc.unattended, DEFAULT_FLOOR_CONFIG.unattended, 'unattended', problems);
|
|
191
|
+
return {
|
|
192
|
+
config: { allowPrefixes, denyGlobs, maxCommandLength, circuitBreakerThreshold, circuitBreakerCooldownMs, circuitBreakerEnabled, unattended },
|
|
193
|
+
problems,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function readPrefixes(value, problems) {
|
|
197
|
+
if (value === undefined)
|
|
198
|
+
return DEFAULT_FLOOR_CONFIG.allowPrefixes;
|
|
199
|
+
if (!Array.isArray(value)) {
|
|
200
|
+
problems.push('allowPrefixes 要是一串字符串(每条形如 `pnpm run build`)');
|
|
201
|
+
return DEFAULT_FLOOR_CONFIG.allowPrefixes;
|
|
202
|
+
}
|
|
203
|
+
const out = [];
|
|
204
|
+
for (const item of value) {
|
|
205
|
+
if (typeof item !== 'string') {
|
|
206
|
+
problems.push(`allowPrefixes 里混进了非字符串:${JSON.stringify(item)}`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const parsed = parsePrefixEntry(item);
|
|
210
|
+
if (!parsed.ok) {
|
|
211
|
+
problems.push(`allowPrefixes 里的「${item}」用不了:${parsed.error}`);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
out.push(parsed.pattern);
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
function readGlobs(value, problems) {
|
|
219
|
+
if (value === undefined)
|
|
220
|
+
return DEFAULT_FLOOR_CONFIG.denyGlobs;
|
|
221
|
+
if (!Array.isArray(value)) {
|
|
222
|
+
problems.push('denyGlobs 要是一串字符串(每条形如 `*etc/passwd*`)');
|
|
223
|
+
return DEFAULT_FLOOR_CONFIG.denyGlobs;
|
|
224
|
+
}
|
|
225
|
+
const out = [];
|
|
226
|
+
for (const item of value) {
|
|
227
|
+
if (typeof item !== 'string') {
|
|
228
|
+
problems.push(`denyGlobs 里混进了非字符串:${JSON.stringify(item)}`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const parsed = parseGlobEntry(item);
|
|
232
|
+
if (!parsed.ok) {
|
|
233
|
+
problems.push(`denyGlobs 里的「${item}」用不了:${parsed.error}`);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
out.push(parsed.glob);
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
function readInt(value, limits, fallback, name, problems) {
|
|
241
|
+
if (value === undefined)
|
|
242
|
+
return fallback;
|
|
243
|
+
if (typeof value !== 'number' || !Number.isInteger(value)) {
|
|
244
|
+
problems.push(`${name} 要是一个整数`);
|
|
245
|
+
return fallback;
|
|
246
|
+
}
|
|
247
|
+
if (value < limits.min || value > limits.max) {
|
|
248
|
+
problems.push(`${name} 要在 ${limits.min}~${limits.max} 之间,收到 ${value}`);
|
|
249
|
+
return fallback;
|
|
250
|
+
}
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
function readBool(value, fallback, name, problems) {
|
|
254
|
+
if (value === undefined)
|
|
255
|
+
return fallback;
|
|
256
|
+
if (typeof value !== 'boolean') {
|
|
257
|
+
problems.push(`${name} 要是 true 或 false`);
|
|
258
|
+
return fallback;
|
|
259
|
+
}
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
/** 命令替换最多往下看几层;再深就按「看不清」拒。 */
|
|
263
|
+
const MAX_SUBSTITUTION_DEPTH = 6;
|
|
264
|
+
/**
|
|
265
|
+
* 扫一遍命令的结构:引号与括号闭合没有、命令替换里是什么。
|
|
266
|
+
*
|
|
267
|
+
* 这些构造只做「括号配对 + 摘出内层片段」,不做完整 shell 语法解析:
|
|
268
|
+
* 判不出来的地方一律让调用方按拒处理。
|
|
269
|
+
*/
|
|
270
|
+
function inspectStructure(command) {
|
|
271
|
+
const substitutions = [];
|
|
272
|
+
const stack = [];
|
|
273
|
+
let quote = null;
|
|
274
|
+
let tickStart = -1;
|
|
275
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
276
|
+
const ch = command[i];
|
|
277
|
+
if (quote !== null) {
|
|
278
|
+
// 单引号里的一切都是字面量;双引号与反引号里 `\` 可以转义(与 splitSegments 同一套规则)。
|
|
279
|
+
if (quote !== "'" && ch === '\\' && i + 1 < command.length) {
|
|
280
|
+
i += 1;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (ch === quote) {
|
|
284
|
+
if (quote === '`' && tickStart >= 0) {
|
|
285
|
+
substitutions.push(command.slice(tickStart + 1, i));
|
|
286
|
+
tickStart = -1;
|
|
287
|
+
}
|
|
288
|
+
quote = null;
|
|
289
|
+
}
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
293
|
+
quote = ch;
|
|
294
|
+
if (ch === '`')
|
|
295
|
+
tickStart = i;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (ch === '$' && command[i + 1] === '(') {
|
|
299
|
+
stack.push({ kind: 'sub', start: i + 2 });
|
|
300
|
+
i += 1;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (ch === '(') {
|
|
304
|
+
stack.push({ kind: 'paren', start: i });
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (ch === ')') {
|
|
308
|
+
const top = stack.pop();
|
|
309
|
+
if (top === undefined)
|
|
310
|
+
return { fatal: '命令里有一个多余的右括号,配不成对', substitutions };
|
|
311
|
+
if (top.kind === 'sub')
|
|
312
|
+
substitutions.push(command.slice(top.start, i));
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (quote !== null) {
|
|
317
|
+
return { fatal: `命令里的 ${quote === '`' ? '反引号' : `${quote} 引号`}没闭合,没法判定它到底要跑什么`, substitutions };
|
|
318
|
+
}
|
|
319
|
+
if (stack.length > 0)
|
|
320
|
+
return { fatal: '命令里的括号没闭合,没法判定它到底要跑什么', substitutions };
|
|
321
|
+
return { fatal: null, substitutions };
|
|
322
|
+
}
|
|
323
|
+
/** 关掉整台机器的命令:只在「命令位置」上认,`grep shutdown` 因此不会被误伤。 */
|
|
324
|
+
const POWER_HEADS = {
|
|
325
|
+
shutdown: () => '关机命令会让这台机器停掉',
|
|
326
|
+
reboot: () => '重启命令会让这台机器停掉',
|
|
327
|
+
halt: () => '停机命令会让这台机器停掉',
|
|
328
|
+
poweroff: () => '关机命令会让这台机器停掉',
|
|
329
|
+
init: (args) => (args[0] === '0' || args[0] === '6' ? 'init 切到停机或重启档' : null),
|
|
330
|
+
systemctl: (args) => (['poweroff', 'reboot', 'halt'].includes(args[0] ?? '') ? `systemctl ${args[0]} 会停掉这台机器` : null),
|
|
331
|
+
kill: (args) => (args.includes('-1') ? 'kill -1 会把信号发给一大批进程' : null),
|
|
332
|
+
};
|
|
333
|
+
/** 命令位置上的这些词只是包装,真正的命令在它们后面(`sudo shutdown now` 也是关机)。 */
|
|
334
|
+
const WRAPPERS = new Set(['sudo', 'doas', 'command', 'exec', 'nohup', 'time']);
|
|
335
|
+
/**
|
|
336
|
+
* 这些 head 加 `-c` / `/c` / `-Command` 就是把脚本塞在参数里,静态判不出它要干什么。
|
|
337
|
+
* `cmd` 必须在内:Windows 上 `cmd /c 任意命令` 是最常见的包装,漏了它地板就把
|
|
338
|
+
* `cmd /c format C:` 当明文命令审,`/c` 明明已经在 {@link INLINE_FLAGS} 里。
|
|
339
|
+
*/
|
|
340
|
+
const SHELL_HEADS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'pwsh', 'powershell', 'cmd']);
|
|
341
|
+
/** 上面那类 shell 的「脚本在参数里」开关。 */
|
|
342
|
+
const INLINE_FLAGS = new Set(['-c', '/c', '-command', '--command', '-encodedcommand', '-enc']);
|
|
343
|
+
/** 命中这些内置危险模式时,命令内容根本不是明文命令(编码过、或者下载下来直接喂给 shell)。 */
|
|
344
|
+
const OPAQUE_DANGER_NAMES = new Set(['encoded-command', 'download-pipe-shell', 'powerShell-iex']);
|
|
345
|
+
/** fork 炸弹:`:(){ :|:& };:` 这类自复制函数会把进程表撑爆。 */
|
|
346
|
+
const FORK_BOMB = /:\s*\(\s*\)\s*\{[^}]*:\s*\|\s*:[^}]*\}/;
|
|
347
|
+
/** 取词元的命令名:去掉目录部分与 `.exe`,再转小写。 */
|
|
348
|
+
function baseName(token) {
|
|
349
|
+
return token.toLowerCase().replace(/^.*[\\/]/, '').replace(/\.exe$/, '');
|
|
350
|
+
}
|
|
351
|
+
/** 跳过 `sudo` 这类包装器之后的命令名与它的参数。 */
|
|
352
|
+
function effectiveHead(tokens) {
|
|
353
|
+
let index = 0;
|
|
354
|
+
while (index < tokens.length && WRAPPERS.has(baseName(tokens[index])))
|
|
355
|
+
index += 1;
|
|
356
|
+
const head = tokens[index];
|
|
357
|
+
if (head === undefined)
|
|
358
|
+
return null;
|
|
359
|
+
return { name: baseName(head), args: tokens.slice(index + 1) };
|
|
360
|
+
}
|
|
361
|
+
/** 命令段里的所有文本(原文 + 词元),黑名单 glob 拿去逐条比。 */
|
|
362
|
+
function segmentTexts(command) {
|
|
363
|
+
const out = [];
|
|
364
|
+
for (const segment of splitSegments(command))
|
|
365
|
+
out.push(segment.raw, ...segment.tokens);
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
/** 内置危险模式的全部命中(整条命令与每一段都看一遍;管道类模式要整条才认得出)。 */
|
|
369
|
+
function dangerHits(command) {
|
|
370
|
+
const hits = new Map();
|
|
371
|
+
const whole = builtinDangerHit(command);
|
|
372
|
+
if (whole !== null)
|
|
373
|
+
hits.set(whole.name, whole);
|
|
374
|
+
for (const segment of splitSegments(command)) {
|
|
375
|
+
const hit = builtinDangerHit(segment.raw);
|
|
376
|
+
if (hit !== null)
|
|
377
|
+
hits.set(hit.name, hit);
|
|
378
|
+
}
|
|
379
|
+
return [...hits.values()];
|
|
380
|
+
}
|
|
381
|
+
/** 命令内容不是明文的那种构造:编码执行、下载下来直接喂 shell、`sh -c`、`eval`。 */
|
|
382
|
+
function opaqueShellReason(command) {
|
|
383
|
+
for (const hit of dangerHits(command)) {
|
|
384
|
+
if (OPAQUE_DANGER_NAMES.has(hit.name))
|
|
385
|
+
return `命令里有「${hit.reason}」这类构造,内容不是明文命令`;
|
|
386
|
+
}
|
|
387
|
+
for (const segment of splitSegments(command)) {
|
|
388
|
+
const head = effectiveHead(segment.tokens);
|
|
389
|
+
if (head === null)
|
|
390
|
+
continue;
|
|
391
|
+
if (head.name === 'eval')
|
|
392
|
+
return 'eval 会把字符串当命令跑,静态判不出它要干什么';
|
|
393
|
+
if (!SHELL_HEADS.has(head.name))
|
|
394
|
+
continue;
|
|
395
|
+
// `sh -c'rm -rf /'` 这种写法在词元化之后 `-c` 会和脚本粘成一个词元,所以还要按前缀认一次。
|
|
396
|
+
for (const token of head.args) {
|
|
397
|
+
const lowered = token.toLowerCase();
|
|
398
|
+
if (INLINE_FLAGS.has(lowered))
|
|
399
|
+
return `${head.name} ${lowered} 把脚本塞在参数里,静态判不出它要干什么`;
|
|
400
|
+
if (lowered.startsWith('-c') && lowered.length > 2 && !/^-[a-z]+$/.test(lowered)) {
|
|
401
|
+
return `${head.name} -c 把脚本塞在参数里,静态判不出它要干什么`;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
/** 灾难地板自己补的那部分:fork 炸弹与关机/重启类命令;`rm -rf /`、`dd of=/dev/sd*` 由硬地板规则负责。 */
|
|
408
|
+
function doomReason(command) {
|
|
409
|
+
if (FORK_BOMB.test(command))
|
|
410
|
+
return 'fork 炸弹会把机器的进程表撑爆,机器直接卡死';
|
|
411
|
+
for (const segment of splitSegments(command)) {
|
|
412
|
+
const head = effectiveHead(segment.tokens);
|
|
413
|
+
if (head === null)
|
|
414
|
+
continue;
|
|
415
|
+
const reason = POWER_HEADS[head.name]?.(head.args) ?? null;
|
|
416
|
+
if (reason !== null)
|
|
417
|
+
return reason;
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
// ---------------------------------------------------------------- 黑名单 glob
|
|
422
|
+
/** 编译过的 glob(同一份配置每次判定都要用,没必要每回重编)。 */
|
|
423
|
+
const GLOB_CACHE = new Map();
|
|
424
|
+
/** 正则里要按字面量处理的字符。 */
|
|
425
|
+
const REGEXP_SPECIAL = /[\\^$.[\]{}()|+*?/]/;
|
|
426
|
+
/** glob → 正则:`*` 配任意字符(含路径分隔符),`?` 配一个字符,其余按字面量。 */
|
|
427
|
+
function compiledGlob(glob) {
|
|
428
|
+
const cached = GLOB_CACHE.get(glob);
|
|
429
|
+
if (cached !== undefined)
|
|
430
|
+
return cached;
|
|
431
|
+
let out = '';
|
|
432
|
+
for (const ch of glob) {
|
|
433
|
+
if (ch === '*')
|
|
434
|
+
out += '.*';
|
|
435
|
+
else if (ch === '?')
|
|
436
|
+
out += '.';
|
|
437
|
+
else
|
|
438
|
+
out += REGEXP_SPECIAL.test(ch) ? `\\${ch}` : ch;
|
|
439
|
+
}
|
|
440
|
+
let re;
|
|
441
|
+
try {
|
|
442
|
+
re = new RegExp(`^${out}$`, 'i');
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
// 吞掉的是正则编译错误本身:转义已覆盖全部特殊字符,正常到不了这里;真到了就返回 null,
|
|
446
|
+
// 由 parseGlobEntry 当成配置问题报出来——判不了的黑名单不许静默失效。
|
|
447
|
+
void error;
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
GLOB_CACHE.set(glob, re);
|
|
451
|
+
return re;
|
|
452
|
+
}
|
|
453
|
+
/** 这些文本里有没有命中黑名单;命中返回那条 glob(说给模型听)。 */
|
|
454
|
+
function globHit(texts, globs) {
|
|
455
|
+
for (const glob of globs) {
|
|
456
|
+
const re = compiledGlob(glob);
|
|
457
|
+
if (re === null)
|
|
458
|
+
continue;
|
|
459
|
+
if (texts.some((text) => re.test(text)))
|
|
460
|
+
return glob;
|
|
461
|
+
}
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
/** 首次出现这些字符的 prepend 命令不再走白名单:管道、分号、子 shell、变量、重定向都在里面。 */
|
|
465
|
+
const WHITELIST_FORBIDDEN = ['`', '$', ';', '&', '|', '<', '>', '(', ')', '\\', '\n', '\r', '!', '{', '}', '^', '%', '"', "'"];
|
|
466
|
+
/** 白名单前缀匹配(照 codex `execpolicy/src/rule.rs` 的前缀匹配:按序匹配词元)。 */
|
|
467
|
+
function whitelistHit(command, config) {
|
|
468
|
+
const segments = splitSegments(command);
|
|
469
|
+
// 多段命令不给白名单:段与段之间怎么组合不在前缀的射程里。
|
|
470
|
+
if (segments.length !== 1)
|
|
471
|
+
return null;
|
|
472
|
+
const segment = segments[0];
|
|
473
|
+
// 带重定向 / 通配符 / 变量赋值的段不许走规则(codex 的同一条告诫,这里复用判定引擎自己的标记)。
|
|
474
|
+
if (segment.ruleUnfriendly)
|
|
475
|
+
return null;
|
|
476
|
+
for (const ch of WHITELIST_FORBIDDEN) {
|
|
477
|
+
if (command.includes(ch))
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
for (const pattern of config.allowPrefixes) {
|
|
481
|
+
const probe = { pattern: [...pattern], decision: 'allow', justification: 'approval-floor 白名单' };
|
|
482
|
+
const verdict = classifyCommand(command, { rules: [probe] });
|
|
483
|
+
// 按对象身份比对:决定必须是我们这条临时规则给出的,
|
|
484
|
+
// 不能因为「这条命令恰好是只读的」就冒充白名单放行。
|
|
485
|
+
if (verdict.decision === 'allow' && verdict.matchedRule === probe)
|
|
486
|
+
return [...pattern];
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
/** 逐层判定一次调用。每一层的理由写在分支旁边。 */
|
|
491
|
+
function evaluate(input, config, rules) {
|
|
492
|
+
const command = input.command?.trim() ?? '';
|
|
493
|
+
const target = input.target;
|
|
494
|
+
// 只读工具不归地板管:读文件越界由路径护栏负责,地板只关心「跑什么」与「写哪里」。
|
|
495
|
+
if (input.risk === 'read')
|
|
496
|
+
return { action: 'defer', layer: 'none', reason: '只读工具不归地板管' };
|
|
497
|
+
if (command === '') {
|
|
498
|
+
if (target === undefined)
|
|
499
|
+
return { action: 'defer', layer: 'none', reason: '既没有命令也没有写目标,交给后面的守卫' };
|
|
500
|
+
const hit = globHit([target], config.denyGlobs);
|
|
501
|
+
if (hit !== null)
|
|
502
|
+
return { action: 'deny', layer: 'deny-list', reason: `写目标命中用户 deny 黑名单(${hit})` };
|
|
503
|
+
if (config.unattended && !isInsideCwd(input.cwd, target)) {
|
|
504
|
+
return { action: 'deny', layer: 'unattended', reason: `无人值守场景只放行工作区内的写入,这次是 ${target}` };
|
|
505
|
+
}
|
|
506
|
+
return { action: 'defer', layer: 'none', reason: '写目标没命中黑名单,交给审批' };
|
|
507
|
+
}
|
|
508
|
+
// 第 1 层:结构不可验证。判不出它到底要跑什么,就没人能保证它安全,因此直接拒。
|
|
509
|
+
if (command.length > config.maxCommandLength) {
|
|
510
|
+
return { action: 'deny', layer: 'opaque', reason: `命令有 ${command.length} 个字符,超过上限 ${config.maxCommandLength},看不清要跑什么` };
|
|
511
|
+
}
|
|
512
|
+
const structure = inspectStructure(command);
|
|
513
|
+
if (structure.fatal !== null)
|
|
514
|
+
return { action: 'deny', layer: 'opaque', reason: structure.fatal };
|
|
515
|
+
const opaque = opaqueShellReason(command);
|
|
516
|
+
if (opaque !== null)
|
|
517
|
+
return { action: 'deny', layer: 'opaque', reason: opaque };
|
|
518
|
+
const verdict = classifyCommand(command, { rules });
|
|
519
|
+
// 第 2 层:灾难地板。硬地板规则(`rm -rf /`、`dd of=/dev/sd*` 这类)由策略引擎给,
|
|
520
|
+
// fork 炸弹与关机重启命令由这里补——它们在命令位置上认,不会误伤 `grep shutdown`。
|
|
521
|
+
if (verdict.hardline)
|
|
522
|
+
return { action: 'deny', layer: 'disaster', reason: `${verdict.reason}(灾难性动作,任何权限模式都不放行)` };
|
|
523
|
+
const doom = doomReason(command);
|
|
524
|
+
if (doom !== null)
|
|
525
|
+
return { action: 'deny', layer: 'disaster', reason: `${doom}(任何权限模式都不放行)` };
|
|
526
|
+
// 命令替换与反引号里的片段递归再判一次:`echo $(rm -rf /)` 外层看不出灾难,内层看得出。
|
|
527
|
+
for (const fragment of structure.substitutions) {
|
|
528
|
+
const inner = innerDenyReason(fragment, config, rules, 1);
|
|
529
|
+
if (inner !== null)
|
|
530
|
+
return { action: 'deny', layer: 'disaster', reason: `命令替换里的片段被判为灾难性动作:${inner}` };
|
|
531
|
+
}
|
|
532
|
+
// 内层干净也不放行:外层的实际效果是两段拼出来的,静态判不出,只能拒(fail-closed)。
|
|
533
|
+
if (structure.substitutions.length > 0) {
|
|
534
|
+
return { action: 'deny', layer: 'opaque', reason: '命令里有 $(...) 或反引号,里外两层拼起来的实际效果判不出来' };
|
|
535
|
+
}
|
|
536
|
+
// 第 3 层:用户 deny 黑名单与 deny 前缀规则。排在权限模式与审批之前,
|
|
537
|
+
// 「完全访问」因此在审批层放行不了它(`plugins/approval.ts:334-337` 那条路径直接被抄掉)。
|
|
538
|
+
const hit = globHit([command, ...segmentTexts(command)], config.denyGlobs);
|
|
539
|
+
if (hit !== null)
|
|
540
|
+
return { action: 'deny', layer: 'deny-list', reason: `命令命中用户 deny 黑名单(${hit})` };
|
|
541
|
+
if (verdict.matchedRule !== null && verdict.matchedRule.decision === 'deny') {
|
|
542
|
+
return {
|
|
543
|
+
action: 'deny',
|
|
544
|
+
layer: 'deny-list',
|
|
545
|
+
reason: `用户规则禁止:${verdict.matchedRule.justification ?? verdict.matchedRule.pattern.join(' ')}`,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
// 第 4 层:内置危险模式。有人看着就交给审批卡(defer),无人值守时没有卡可弹,只能拒。
|
|
549
|
+
const dangers = dangerHits(command);
|
|
550
|
+
if (dangers.length > 0) {
|
|
551
|
+
const reason = dangers.map((danger) => danger.reason).join(';');
|
|
552
|
+
if (config.unattended)
|
|
553
|
+
return { action: 'deny', layer: 'unattended', reason: `无人值守场景不放行危险命令:${reason}` };
|
|
554
|
+
return { action: 'defer', layer: 'dangerous', reason: `危险命令(${reason}),交给审批卡问人` };
|
|
555
|
+
}
|
|
556
|
+
// 第 5 层:命令白名单。命中不等于「链条到此为止」——地板只把结论交出去,
|
|
557
|
+
// 由审批层按 {@link ApprovalFloor} 的 whitelist() 免卡放行。地板自己 return pass 会连同
|
|
558
|
+
// 后面的安全钩子(order 20)与生命周期钩子(order 25)一起跳掉,那不是白名单的本意。
|
|
559
|
+
if (whitelistHit(command, config) !== null) {
|
|
560
|
+
return { action: 'defer', layer: 'allowlist', reason: '命中白名单前缀,交给审批层免卡放行' };
|
|
561
|
+
}
|
|
562
|
+
// 无人值守没有卡可弹:白名单之外、需要确认的命令一律拒(ask 等于拒,与免打扰档同一条道理)。
|
|
563
|
+
if (config.unattended && verdict.decision !== 'allow') {
|
|
564
|
+
return { action: 'deny', layer: 'unattended', reason: `无人值守场景不弹审批卡,需要确认的命令一律拒:${verdict.reason}` };
|
|
565
|
+
}
|
|
566
|
+
return { action: 'defer', layer: 'none', reason: '地板没意见,交给后面的守卫' };
|
|
567
|
+
}
|
|
568
|
+
/** 命令替换片段里的灾难性判定:只看「判不了」与「灾难」两类,理由里不带前缀。 */
|
|
569
|
+
function innerDenyReason(command, config, rules, depth) {
|
|
570
|
+
const text = command.trim();
|
|
571
|
+
if (text === '')
|
|
572
|
+
return null;
|
|
573
|
+
if (depth > MAX_SUBSTITUTION_DEPTH)
|
|
574
|
+
return `命令替换嵌套超过 ${MAX_SUBSTITUTION_DEPTH} 层`;
|
|
575
|
+
if (text.length > config.maxCommandLength)
|
|
576
|
+
return `命令替换里的片段太长(${text.length} 个字符)`;
|
|
577
|
+
const structure = inspectStructure(text);
|
|
578
|
+
if (structure.fatal !== null)
|
|
579
|
+
return structure.fatal;
|
|
580
|
+
const opaque = opaqueShellReason(text);
|
|
581
|
+
if (opaque !== null)
|
|
582
|
+
return opaque;
|
|
583
|
+
const verdict = classifyCommand(text, { rules });
|
|
584
|
+
if (verdict.hardline)
|
|
585
|
+
return verdict.reason;
|
|
586
|
+
const doom = doomReason(text);
|
|
587
|
+
if (doom !== null)
|
|
588
|
+
return doom;
|
|
589
|
+
for (const fragment of structure.substitutions) {
|
|
590
|
+
const inner = innerDenyReason(fragment, config, rules, depth + 1);
|
|
591
|
+
if (inner !== null)
|
|
592
|
+
return inner;
|
|
593
|
+
}
|
|
594
|
+
if (structure.substitutions.length > 0)
|
|
595
|
+
return '片段里还套着命令替换,拼不出实际效果';
|
|
596
|
+
const hit = globHit([text, ...segmentTexts(text)], config.denyGlobs);
|
|
597
|
+
if (hit !== null)
|
|
598
|
+
return `命中用户 deny 黑名单(${hit})`;
|
|
599
|
+
if (verdict.matchedRule !== null && verdict.matchedRule.decision === 'deny') {
|
|
600
|
+
return `用户规则禁止:${verdict.matchedRule.justification ?? verdict.matchedRule.pattern.join(' ')}`;
|
|
601
|
+
}
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* 组装灾难地板。
|
|
606
|
+
*
|
|
607
|
+
* 配置读不通时守卫照样挂载、却一律拒:挂载失败等于链上根本没有地板,
|
|
608
|
+
* 那是 fail-open——比「全部拒掉、让用户看见问题去改」危险得多。
|
|
609
|
+
*
|
|
610
|
+
* 熔断只统计地板自己的 deny:地板排在审批前面,看不到审批最终怎么裁,
|
|
611
|
+
* 所以「连续被拒」不是「用户连续拒绝」,只是「同一条路反复撞在同一个坑里」。
|
|
612
|
+
*
|
|
613
|
+
* @param options - 见 {@link ApprovalFloorOptions}。
|
|
614
|
+
* @returns 守卫与它的状态读写。
|
|
615
|
+
*/
|
|
616
|
+
export function createApprovalFloor(options) {
|
|
617
|
+
const now = options.now ?? (() => Date.now());
|
|
618
|
+
let consecutiveDenies = 0;
|
|
619
|
+
let openUntil = 0;
|
|
620
|
+
/** 结论落定之后更新熔断计数并落审计,最后转成守卫裁决。 */
|
|
621
|
+
const settle = (outcome, input, config, countIt) => {
|
|
622
|
+
if (countIt) {
|
|
623
|
+
if (outcome.action === 'deny') {
|
|
624
|
+
consecutiveDenies += 1;
|
|
625
|
+
if (config.circuitBreakerEnabled && consecutiveDenies >= config.circuitBreakerThreshold) {
|
|
626
|
+
openUntil = now() + config.circuitBreakerCooldownMs;
|
|
627
|
+
consecutiveDenies = 0;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
consecutiveDenies = 0;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (outcome.action === 'defer')
|
|
635
|
+
return { action: 'defer' };
|
|
636
|
+
audit({
|
|
637
|
+
ts: Date.now(),
|
|
638
|
+
kind: 'auto-deny',
|
|
639
|
+
tool: input.toolName,
|
|
640
|
+
summary: argsSummary(input.args ?? {}).slice(0, 200),
|
|
641
|
+
reason: outcome.reason,
|
|
642
|
+
decision: 'blocked',
|
|
643
|
+
cwd: input.cwd,
|
|
644
|
+
});
|
|
645
|
+
return { action: 'deny', reason: `灾难地板拒绝:${outcome.reason}` };
|
|
646
|
+
};
|
|
647
|
+
const guard = {
|
|
648
|
+
id: 'approval-floor',
|
|
649
|
+
order: 5,
|
|
650
|
+
decide(input) {
|
|
651
|
+
const { config, problems } = options.readConfig();
|
|
652
|
+
// 配置坏掉:一律拒,且不计入熔断(否则理由会被熔断盖住,用户看不到真正的问题)。
|
|
653
|
+
if (problems.length > 0) {
|
|
654
|
+
return settle({ action: 'deny', layer: 'config', reason: `配置读不通,按最严处理一律拒:${problems.join(';')}` }, input, config, false);
|
|
655
|
+
}
|
|
656
|
+
const at = now();
|
|
657
|
+
if (openUntil !== 0 && at >= openUntil) {
|
|
658
|
+
openUntil = 0;
|
|
659
|
+
consecutiveDenies = 0;
|
|
660
|
+
}
|
|
661
|
+
if (openUntil !== 0) {
|
|
662
|
+
const seconds = Math.max(1, Math.ceil((openUntil - at) / 1000));
|
|
663
|
+
return settle({ action: 'deny', layer: 'circuit', reason: `连续被拒 ${config.circuitBreakerThreshold} 次,熔断冷却中(还有约 ${seconds} 秒),这段时间一律拒` }, input, config,
|
|
664
|
+
// 熔断期间的拒不再计数:否则模型每重试一次就续一次冷却,永远恢复不了。
|
|
665
|
+
false);
|
|
666
|
+
}
|
|
667
|
+
return settle(evaluate(input, config, options.rules()), input, config, true);
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
return {
|
|
671
|
+
guard,
|
|
672
|
+
whitelist: (command) => whitelistHit(command, options.readConfig().config),
|
|
673
|
+
breaker: () => ({ consecutiveDenies, openUntil, tripped: openUntil !== 0 && now() < openUntil }),
|
|
674
|
+
reset: () => {
|
|
675
|
+
consecutiveDenies = 0;
|
|
676
|
+
openUntil = 0;
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
}
|