@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,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可写根的 ACL 授权与回收:给目标目录打「能力 SID 三件套」,并把同目录的读-并-写串行化。
|
|
3
|
+
*
|
|
4
|
+
* 三件套(照 dsh `sandbox-windows-acl/src/acl.ts` 的实证取舍):
|
|
5
|
+
* 1. Allow ACE:能力 SID,掩码 GRANT_MASK,OI|CI 继承——这是 WRITE_RESTRICTED
|
|
6
|
+
* 的 pass-2 交集检查里唯一放行写的凭据;
|
|
7
|
+
* 2. Deny ACE:Everyone 的 FILE_DELETE_CHILD,**只挂 CONTAINER_INHERIT**。
|
|
8
|
+
* 原因:0x40 ∈ FILE_ALL_ACCESS,若 OI|CI 落到每个文件上会拒掉所有 FullControl
|
|
9
|
+
* 打开;只挂目录则既拦「借父目录句柄删子项」的逃逸,又不伤文件打开;
|
|
10
|
+
* 3. 强制标签:S-1-16-4096(Low)+ NO_WRITE_UP,OI|CI——低完整性令牌不许改写
|
|
11
|
+
* 中完整性创建的文件,把「继承授权」这条暗道也封上。
|
|
12
|
+
*
|
|
13
|
+
* 前提(不满足就响亮失败,绝不静默):目录归调用者所有。写强制标签要 WRITE_OWNER,
|
|
14
|
+
* 而对象所有者天然持有 READ_CONTROL|WRITE_DAC,所以自己建的目录一定打得上去;
|
|
15
|
+
* 只有 Modify 权限的目录会失败,这是设计不是 bug。
|
|
16
|
+
*
|
|
17
|
+
* 幂等:三件套全部精确命中(逐字节比 SID)就跳过整树重传播——
|
|
18
|
+
* SetNamedSecurityInfoW 的授权是急切传播,大树首次要几十秒,幂等跳过是唯一缓解。
|
|
19
|
+
*
|
|
20
|
+
* 并发:同一目录的读-并-写用阻塞的 LockFileEx 独占锁串行化(锁文件放 dsc 家目录;
|
|
21
|
+
* 阻塞而非 fail-immediately:我们要的是「等前一位做完」,同进程重入被后端的授权缓存挡住,
|
|
22
|
+
* 不会自锁)。
|
|
23
|
+
*
|
|
24
|
+
* 句柄口径:句柄与系统指针一律 number(见 ffi.ts 文件头)。系统 ACL 里的 SID 是
|
|
25
|
+
* **内联在 ACE 里的字节**而不是指针,比对只能按 walkAces 逐字节走。
|
|
26
|
+
*
|
|
27
|
+
* @module dsc/core/sandbox/win/acl
|
|
28
|
+
*/
|
|
29
|
+
import { createHash } from 'node:crypto';
|
|
30
|
+
import { join } from 'node:path';
|
|
31
|
+
import { ACCESS_ALLOWED_ACE_TYPE, ACCESS_DENIED_ACE_TYPE, ACL_ACE_COUNT_OFFSET, ACL_FIRST_ACE_OFFSET, ACL_REVISION, ACE_MASK_OFFSET, ACE_SID_OFFSET, CONTAINER_INHERIT_ACE, DACL_SECURITY_INFORMATION, DENY_ACCESS, EXPLICIT_ACCESS_SIZE, FILE_ATTRIBUTE_NORMAL, FILE_DELETE_CHILD, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE, GRANT_ACCESS, GRANT_MASK, LABEL_SECURITY_INFORMATION, LOCKFILE_EXCLUSIVE_LOCK, OBJECT_INHERIT_ACE, OPEN_ALWAYS, OVERLAPPED_SIZE, REVOKE_ACCESS, SE_FILE_OBJECT, SID_MAX_BYTES, SYSTEM_MANDATORY_LABEL_ACE_TYPE, SYSTEM_MANDATORY_LABEL_NO_WRITE_UP, WinLowLabelSid, WinWorldSid, } from './abi.js';
|
|
32
|
+
import { addressOf, readMemory, slotUintPtr, throwLastError, throwWin32 } from './ffi.js';
|
|
33
|
+
import { packExplicitAccessSid, sidStringToBuffer, wellKnownSidBuffer } from './token.js';
|
|
34
|
+
/** 任意字符串 → NUL 结尾的 UTF-16 缓冲(Win32 的 str16 入参口径)。 */
|
|
35
|
+
function utf16Buffer(text) {
|
|
36
|
+
const buffer = Buffer.alloc(text.length * 2 + 2);
|
|
37
|
+
buffer.write(text, 0, 'utf16le');
|
|
38
|
+
return buffer;
|
|
39
|
+
}
|
|
40
|
+
/** `(HANDLE)-1`:CreateFileW 的失败哨兵值。 */
|
|
41
|
+
const INVALID_HANDLE_VALUE = 0xffffffffffffffffn;
|
|
42
|
+
/** 锁文件名:小写路径的 sha256 前 16 位 hex(避开路径里不合法的文件名字符)。 */
|
|
43
|
+
function lockFilePath(lockDir, path) {
|
|
44
|
+
return join(lockDir, createHash('sha256').update(path.toLowerCase()).digest('hex').slice(0, 16) + '.lock');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 拿住路径锁再干活(阻塞式独占;见文件头并发说明)。
|
|
48
|
+
*
|
|
49
|
+
* 两处刻意的写法:
|
|
50
|
+
* - 不加 LOCKFILE_FAIL_IMMEDIATELY:同目录的第二次授权要**等**第一次写完 ACL 再读,
|
|
51
|
+
* 失败即返会让幂等判定看到中间态;
|
|
52
|
+
* - OVERLAPPED 给一块零化内存:koffi 3.1.1 给 LockFileEx/UnlockFileEx 传 NULL 会崩(已实测)。
|
|
53
|
+
*/
|
|
54
|
+
function withPathLock(bound, lockDir, path, work) {
|
|
55
|
+
const raw = bound.createFileW(utf16Buffer(lockFilePath(lockDir, path)), (GENERIC_READ | GENERIC_WRITE) >>> 0, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, null);
|
|
56
|
+
// 失败形态有两种:NULL(0) 与 INVALID_HANDLE_VALUE(-1)。koffi 对超出安全整数范围的
|
|
57
|
+
// uintptr_t 回 BigInt(实测 CreateFileW 失败给 18446744073709551615n),只判 === 0
|
|
58
|
+
// 会漏掉后者,下一步就会拿着假句柄去加锁
|
|
59
|
+
const handle = typeof raw === 'bigint' ? raw : BigInt(Number(raw));
|
|
60
|
+
if (handle === 0n || handle === INVALID_HANDLE_VALUE)
|
|
61
|
+
throwLastError(bound, 'CreateFileW(锁文件)');
|
|
62
|
+
const lockHandle = Number(handle);
|
|
63
|
+
const overlapped = Buffer.alloc(OVERLAPPED_SIZE);
|
|
64
|
+
try {
|
|
65
|
+
if (Number(bound.lockFileEx(lockHandle, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, overlapped)) === 0) {
|
|
66
|
+
throwLastError(bound, 'LockFileEx');
|
|
67
|
+
}
|
|
68
|
+
return work();
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
// 解锁与关句柄失败都吞:锁会随句柄关闭由内核释放,这里的失败不改变上面的真实结果
|
|
72
|
+
try {
|
|
73
|
+
bound.unlockFileEx(lockHandle, 0, 1, 0, overlapped);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* 同上 */
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
bound.closeHandle(lockHandle);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* 同上 */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 把一段 ACL 字节解开成 ACE 列表。
|
|
88
|
+
*
|
|
89
|
+
* SID **内联在 ACE+8** 处(不是指针),长度 = 8 + count*4,count 字节在 sid+1;
|
|
90
|
+
* 按 AceSize 步进。size 出现非法值(小于最小 ACE、越过 ACL 尾、装不下声明的 SID)
|
|
91
|
+
* 就停下——后面的字节已经不可信,继续步进只会走到别人的数据上。
|
|
92
|
+
*/
|
|
93
|
+
export function walkAces(aclBytes) {
|
|
94
|
+
if (aclBytes.length < ACL_FIRST_ACE_OFFSET)
|
|
95
|
+
return [];
|
|
96
|
+
const view = new DataView(aclBytes.buffer, aclBytes.byteOffset, aclBytes.byteLength);
|
|
97
|
+
const count = view.getUint16(ACL_ACE_COUNT_OFFSET, true);
|
|
98
|
+
const out = [];
|
|
99
|
+
let offset = ACL_FIRST_ACE_OFFSET;
|
|
100
|
+
for (let index = 0; index < count; index += 1) {
|
|
101
|
+
if (offset + ACE_SID_OFFSET > aclBytes.length)
|
|
102
|
+
break;
|
|
103
|
+
const size = view.getUint16(offset + 2, true);
|
|
104
|
+
// 最小合法 ACE = 头 8 字节 + 最短 SID 8 字节
|
|
105
|
+
if (size < ACE_SID_OFFSET + 8 || offset + size > aclBytes.length)
|
|
106
|
+
break;
|
|
107
|
+
const subAuthorityCount = aclBytes[offset + ACE_SID_OFFSET + 1];
|
|
108
|
+
const sidLength = 8 + subAuthorityCount * 4;
|
|
109
|
+
if (ACE_SID_OFFSET + sidLength > size)
|
|
110
|
+
break;
|
|
111
|
+
out.push({
|
|
112
|
+
type: aclBytes[offset],
|
|
113
|
+
flags: aclBytes[offset + 1],
|
|
114
|
+
mask: view.getUint32(offset + ACE_MASK_OFFSET, true),
|
|
115
|
+
sid: aclBytes.subarray(offset + ACE_SID_OFFSET, offset + ACE_SID_OFFSET + sidLength),
|
|
116
|
+
});
|
|
117
|
+
offset += size;
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/** SID 逐字节相等(长度不同直接不等)。 */
|
|
122
|
+
function sameSid(a, b) {
|
|
123
|
+
if (a.length !== b.length)
|
|
124
|
+
return false;
|
|
125
|
+
for (let index = 0; index < a.length; index += 1) {
|
|
126
|
+
if (a[index] !== b[index])
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 三件套是否都已**精确**命中(命中则整树重传播可以整段跳过)。
|
|
133
|
+
*
|
|
134
|
+
* 三条都要,且 flags 也要精确:
|
|
135
|
+
* - Allow:type 0,flags 恰好 OI|CI,mask 恰好 GRANT_MASK,SID == 能力 SID;
|
|
136
|
+
* - Deny:type 1,flags 恰好 CI(**不许**带 OI),mask 恰好 FILE_DELETE_CHILD,SID == Everyone;
|
|
137
|
+
* - 标签:type 0x11,flags 恰好 OI|CI,mask 恰好 NO_WRITE_UP,SID == Low 标签。
|
|
138
|
+
* 带上别的 flags 说明这条 ACE 不是我们打的(可能来自继承或别人),不能当命中。
|
|
139
|
+
*/
|
|
140
|
+
function hasExactTrio(dacl, sacl, capability, everyone, low) {
|
|
141
|
+
if (dacl === null || sacl === null)
|
|
142
|
+
return false;
|
|
143
|
+
const daclAces = walkAces(dacl);
|
|
144
|
+
const allow = daclAces.some((ace) => ace.type === ACCESS_ALLOWED_ACE_TYPE &&
|
|
145
|
+
ace.flags === (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) &&
|
|
146
|
+
ace.mask === (GRANT_MASK >>> 0) &&
|
|
147
|
+
sameSid(ace.sid, capability));
|
|
148
|
+
const deny = daclAces.some((ace) => ace.type === ACCESS_DENIED_ACE_TYPE &&
|
|
149
|
+
ace.flags === CONTAINER_INHERIT_ACE &&
|
|
150
|
+
ace.mask === FILE_DELETE_CHILD &&
|
|
151
|
+
sameSid(ace.sid, everyone));
|
|
152
|
+
const label = walkAces(sacl).some((ace) => ace.type === SYSTEM_MANDATORY_LABEL_ACE_TYPE &&
|
|
153
|
+
ace.flags === (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) &&
|
|
154
|
+
ace.mask === SYSTEM_MANDATORY_LABEL_NO_WRITE_UP &&
|
|
155
|
+
sameSid(ace.sid, low));
|
|
156
|
+
return allow && deny && label;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 读系统指针指向的 ACL 字节:0 = 该 ACL 不存在(NULL DACL),返回 null。
|
|
160
|
+
* 先读 8 字节头拿 AclSize(u16@2),再整块读——头里的 AclSize 不合法就抛,
|
|
161
|
+
* 因为后面按它取字节,错一点就是读别人的内存。
|
|
162
|
+
*/
|
|
163
|
+
function readAclBytes(bound, aclPointer) {
|
|
164
|
+
if (aclPointer === 0)
|
|
165
|
+
return null;
|
|
166
|
+
const header = readMemory(bound, aclPointer, 8);
|
|
167
|
+
const size = header[2] | (header[3] << 8);
|
|
168
|
+
if (size < 8)
|
|
169
|
+
throw new Error(`ACL 头的 AclSize 不合法(${String(size)}):安全描述符已经不可信`);
|
|
170
|
+
return readMemory(bound, aclPointer, size);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 给目录授权(幂等):三件套一次 SetNamedSecurityInfoW 打齐。
|
|
174
|
+
*
|
|
175
|
+
* @param path - 目标目录(调用方保证是 realpath 规范化后的绝对路径)。
|
|
176
|
+
* @param sid - 能力 SID 串(S-1-4-x-y,来自 workspace-sid.ts)。
|
|
177
|
+
* @param lockDir - 锁文件目录(调用方保证已存在)。
|
|
178
|
+
*/
|
|
179
|
+
export function grantWrite(bound, path, sid, lockDir) {
|
|
180
|
+
const capability = sidStringToBuffer(bound, sid);
|
|
181
|
+
const everyone = wellKnownSidBuffer(bound, WinWorldSid);
|
|
182
|
+
const low = wellKnownSidBuffer(bound, WinLowLabelSid);
|
|
183
|
+
const name = utf16Buffer(path);
|
|
184
|
+
return withPathLock(bound, lockDir, path, () => {
|
|
185
|
+
const owner = slotUintPtr(bound);
|
|
186
|
+
const group = slotUintPtr(bound);
|
|
187
|
+
const dacl = slotUintPtr(bound);
|
|
188
|
+
const sacl = slotUintPtr(bound);
|
|
189
|
+
const sd = slotUintPtr(bound);
|
|
190
|
+
const readCode = Number(bound.getNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION, owner.slot, group.slot, dacl.slot, sacl.slot, sd.slot));
|
|
191
|
+
if (readCode !== 0)
|
|
192
|
+
throwWin32(bound, 'GetNamedSecurityInfoW(三件套)', readCode);
|
|
193
|
+
try {
|
|
194
|
+
if (hasExactTrio(readAclBytes(bound, dacl.get()), readAclBytes(bound, sacl.get()), capability, everyone, low)) {
|
|
195
|
+
return { applied: false, detail: '三件套已在(幂等跳过,不重传播)' };
|
|
196
|
+
}
|
|
197
|
+
// 两条 EA 打进一块 96 字节:Allow(能力 SID,OI|CI)+ Deny(Everyone 只删子项,仅 CI)
|
|
198
|
+
const entries = Buffer.alloc(EXPLICIT_ACCESS_SIZE * 2);
|
|
199
|
+
entries.set(packExplicitAccessSid(bound, {
|
|
200
|
+
mask: GRANT_MASK,
|
|
201
|
+
mode: GRANT_ACCESS,
|
|
202
|
+
inheritance: OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE,
|
|
203
|
+
sid: capability,
|
|
204
|
+
}), 0);
|
|
205
|
+
entries.set(packExplicitAccessSid(bound, {
|
|
206
|
+
mask: FILE_DELETE_CHILD,
|
|
207
|
+
mode: DENY_ACCESS,
|
|
208
|
+
inheritance: CONTAINER_INHERIT_ACE,
|
|
209
|
+
sid: everyone,
|
|
210
|
+
}), EXPLICIT_ACCESS_SIZE);
|
|
211
|
+
const newDacl = slotUintPtr(bound);
|
|
212
|
+
const mergeCode = Number(bound.setEntriesInAclW(2, entries, dacl.get(), newDacl.slot));
|
|
213
|
+
if (mergeCode !== 0)
|
|
214
|
+
throwWin32(bound, 'SetEntriesInAclW(三件套)', mergeCode);
|
|
215
|
+
// 标签 ACL:InitializeAcl 建空 ACL + AddMandatoryAce 加 Low 标签 + NO_WRITE_UP(OI|CI)
|
|
216
|
+
const labelAcl = Buffer.alloc(8 + 8 + SID_MAX_BYTES);
|
|
217
|
+
if (Number(bound.initializeAcl(labelAcl, labelAcl.length, ACL_REVISION)) === 0) {
|
|
218
|
+
throwLastError(bound, 'InitializeAcl');
|
|
219
|
+
}
|
|
220
|
+
if (Number(bound.addMandatoryAce(labelAcl, ACL_REVISION, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, SYSTEM_MANDATORY_LABEL_NO_WRITE_UP, low)) === 0) {
|
|
221
|
+
throwLastError(bound, 'AddMandatoryAce');
|
|
222
|
+
}
|
|
223
|
+
// labelAcl 只活在这次调用里:地址被嵌进 Win32 参数后必须由局部变量持有到返回(防 GC)
|
|
224
|
+
const writeCode = Number(bound.setNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | LABEL_SECURITY_INFORMATION, 0, 0, newDacl.get(), addressOf(bound, labelAcl)));
|
|
225
|
+
if (writeCode !== 0)
|
|
226
|
+
throwWin32(bound, 'SetNamedSecurityInfoW(三件套)', writeCode);
|
|
227
|
+
return { applied: true, detail: '已打三件套(Allow 能力 SID + Deny Everyone 删子项 + Low 标签)' };
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
// GetNamedSecurityInfoW 的契约:只 LocalFree 描述符本身,绝不 free 里面的 ACL 指针
|
|
231
|
+
const descriptor = sd.get();
|
|
232
|
+
if (descriptor !== 0) {
|
|
233
|
+
try {
|
|
234
|
+
bound.localFree(descriptor);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
/* 描述符释放失败不该遮住真实结果:进程退出时内核兜底 */
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 给目录补「账号 SID 的读写执行 Allow ACE」(网络第二级账号分支专用)。
|
|
245
|
+
*
|
|
246
|
+
* 为什么要它:专用离线账号没有当前用户的权限,工作区里它连**读**都不行——
|
|
247
|
+
* pass-1(普通 SID 检查)就过不去,命令在仓库里什么都干不了。假能力 SID 的
|
|
248
|
+
* 三件套只解决 pass-2(写受限交集),pass-1 得靠这条 ACE 补上。
|
|
249
|
+
*
|
|
250
|
+
* 掩码 = 读 + 执行 + GRANT_MASK(写/删),仍刻意不含 WRITE_DAC/WRITE_OWNER;
|
|
251
|
+
* 幂等口径与三件套一致(精确命中即跳过整树重传播)。
|
|
252
|
+
*/
|
|
253
|
+
export function grantAccountAccess(bound, path, accountSid, lockDir) {
|
|
254
|
+
const capability = sidStringToBuffer(bound, accountSid);
|
|
255
|
+
const name = utf16Buffer(path);
|
|
256
|
+
const accountMask = (FILE_GENERIC_READ | FILE_GENERIC_EXECUTE | GRANT_MASK) >>> 0;
|
|
257
|
+
return withPathLock(bound, lockDir, path, () => {
|
|
258
|
+
const ownerSlot = slotUintPtr(bound);
|
|
259
|
+
const groupSlot = slotUintPtr(bound);
|
|
260
|
+
const daclSlot = slotUintPtr(bound);
|
|
261
|
+
const saclSlot = slotUintPtr(bound);
|
|
262
|
+
const sdSlot = slotUintPtr(bound);
|
|
263
|
+
const readCode = Number(bound.getNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, ownerSlot.slot, groupSlot.slot, daclSlot.slot, saclSlot.slot, sdSlot.slot));
|
|
264
|
+
if (readCode !== 0)
|
|
265
|
+
throwWin32(bound, 'GetNamedSecurityInfoW(账号授权)', readCode);
|
|
266
|
+
try {
|
|
267
|
+
const daclPointer = daclSlot.get();
|
|
268
|
+
const already = walkAces(readAclBytes(bound, daclPointer) ?? new Uint8Array()).some((ace) => ace.type === ACCESS_ALLOWED_ACE_TYPE &&
|
|
269
|
+
ace.flags === (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) &&
|
|
270
|
+
ace.mask === accountMask && sameSid(ace.sid, capability));
|
|
271
|
+
if (already)
|
|
272
|
+
return { applied: false, detail: '账号 ACE 已在(幂等跳过)' };
|
|
273
|
+
const entry = packExplicitAccessSid(bound, {
|
|
274
|
+
mask: accountMask, mode: GRANT_ACCESS, inheritance: OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, sid: capability,
|
|
275
|
+
});
|
|
276
|
+
const newDaclSlot = slotUintPtr(bound);
|
|
277
|
+
const code = Number(bound.setEntriesInAclW(1, entry, daclPointer, newDaclSlot.slot));
|
|
278
|
+
if (code !== 0)
|
|
279
|
+
throwWin32(bound, 'SetEntriesInAclW(账号授权)', code);
|
|
280
|
+
const writeCode = Number(bound.setNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, newDaclSlot.get(), 0));
|
|
281
|
+
if (writeCode !== 0)
|
|
282
|
+
throwWin32(bound, 'SetNamedSecurityInfoW(账号授权)', writeCode);
|
|
283
|
+
return { applied: true, detail: '已补账号读写执行 ACE' };
|
|
284
|
+
}
|
|
285
|
+
finally {
|
|
286
|
+
try {
|
|
287
|
+
bound.localFree(sdSlot.get());
|
|
288
|
+
}
|
|
289
|
+
catch { /* 描述符为空时忽略 */ }
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 回收目录上的能力 SID 授权(REVOKE_ACCESS 只摘我们自己的那条 ACE)。
|
|
295
|
+
*
|
|
296
|
+
* 刻意**不动** Low 标签:NO_WRITE_UP 只拦「比标签更低」的写,用户自己的中完整性
|
|
297
|
+
* 进程不受影响,留着它等于给这个目录留一道永久加固;摘标签反而要在「还有没有别的
|
|
298
|
+
* 能力授权」上做一堆判断,收益为负。
|
|
299
|
+
*/
|
|
300
|
+
export function revokeWrite(bound, path, sid, lockDir) {
|
|
301
|
+
const capability = sidStringToBuffer(bound, sid);
|
|
302
|
+
const name = utf16Buffer(path);
|
|
303
|
+
return withPathLock(bound, lockDir, path, () => {
|
|
304
|
+
const owner = slotUintPtr(bound);
|
|
305
|
+
const group = slotUintPtr(bound);
|
|
306
|
+
const dacl = slotUintPtr(bound);
|
|
307
|
+
const sacl = slotUintPtr(bound);
|
|
308
|
+
const sd = slotUintPtr(bound);
|
|
309
|
+
const readCode = Number(bound.getNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, owner.slot, group.slot, dacl.slot, sacl.slot, sd.slot));
|
|
310
|
+
if (readCode !== 0)
|
|
311
|
+
throwWin32(bound, 'GetNamedSecurityInfoW(回收)', readCode);
|
|
312
|
+
try {
|
|
313
|
+
const stillThere = walkAces(readAclBytes(bound, dacl.get()) ?? new Uint8Array())
|
|
314
|
+
.some((ace) => ace.type === ACCESS_ALLOWED_ACE_TYPE && sameSid(ace.sid, capability));
|
|
315
|
+
if (!stillThere)
|
|
316
|
+
return { applied: false, detail: '授权本就不在(幂等跳过)' };
|
|
317
|
+
const entry = packExplicitAccessSid(bound, { mask: 0, mode: REVOKE_ACCESS, inheritance: 0, sid: capability });
|
|
318
|
+
const newDacl = slotUintPtr(bound);
|
|
319
|
+
const mergeCode = Number(bound.setEntriesInAclW(1, entry, dacl.get(), newDacl.slot));
|
|
320
|
+
if (mergeCode !== 0)
|
|
321
|
+
throwWin32(bound, 'SetEntriesInAclW(回收)', mergeCode);
|
|
322
|
+
const writeCode = Number(bound.setNamedSecurityInfoW(name, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, newDacl.get(), 0));
|
|
323
|
+
if (writeCode !== 0)
|
|
324
|
+
throwWin32(bound, 'SetNamedSecurityInfoW(回收)', writeCode);
|
|
325
|
+
return { applied: true, detail: '已摘除能力 ACE(Low 标签保留)' };
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
const descriptor = sd.get();
|
|
329
|
+
if (descriptor !== 0) {
|
|
330
|
+
try {
|
|
331
|
+
bound.localFree(descriptor);
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
/* 同上 */
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { CommandRunner } from '../../tools/command-runner.js';
|
|
2
|
+
/** 执行器 id(宿主诊断与 `enforcement` 上报用这个键)。 */
|
|
3
|
+
export declare const WINDOWS_TOKEN_RUNNER_ID = "sandbox-windows-token";
|
|
4
|
+
/** runner 自身失败的 stderr 签名:宿主与 win-token 冒烟探针靠它把「runner 挂了」与「命令失败了」分开。 */
|
|
5
|
+
export declare const RUNNER_FAILURE_SIGNATURE = "dsc-sandbox-run: ";
|
|
6
|
+
/**
|
|
7
|
+
* 探一次受限令牌后端可用性:Windows + koffi 装得上 + runner 构建产物在。
|
|
8
|
+
* 不实际建令牌(探测要快且无副作用),真正的失败在 runner 里响亮报出来。
|
|
9
|
+
*/
|
|
10
|
+
export declare function probeWindowsToken(): {
|
|
11
|
+
available: boolean;
|
|
12
|
+
detail: string;
|
|
13
|
+
};
|
|
14
|
+
/** 执行器构造入参(路径都要求是 realpath 规范化后的绝对路径)。 */
|
|
15
|
+
export interface WindowsTokenRunnerOptions {
|
|
16
|
+
mode: 'read-only' | 'workspace-write';
|
|
17
|
+
/** 会话工作目录(常驻可写根)。 */
|
|
18
|
+
cwd: string;
|
|
19
|
+
/** 沙箱私有临时目录(会话结束回收授权)。 */
|
|
20
|
+
tmpDir: string;
|
|
21
|
+
/** 附加可写根。 */
|
|
22
|
+
extraRoots?: readonly string[];
|
|
23
|
+
/** 网络开关(每次都现取,改设置立即生效)。 */
|
|
24
|
+
networkAccess: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 网络第二级账号分支(可选,来自 setup 状态文件):给了它,runner 以专用离线
|
|
27
|
+
* 账号跑命令(LogonUserW + 受限化账号令牌),可写根补账号读写执行 ACE;
|
|
28
|
+
* 网络开关开时起本地白名单代理并把子进程指向它(WFP 已按账号 SID 堵死其余出口)。
|
|
29
|
+
*/
|
|
30
|
+
account?: {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly sid: string;
|
|
33
|
+
readonly dscHome: string;
|
|
34
|
+
/** 代理监听端口(与 setup 防火墙放行的端口一致,默认 3128)。 */
|
|
35
|
+
readonly proxyPort: number;
|
|
36
|
+
};
|
|
37
|
+
/** 出网白名单现取值(代理用;账号分支且开网时生效)。 */
|
|
38
|
+
networkAllowlist?: () => readonly string[];
|
|
39
|
+
/** 降级与回收失败的一句话,交给插件报给用户。 */
|
|
40
|
+
onDetail?: (message: string) => void;
|
|
41
|
+
}
|
|
42
|
+
/** 执行器句柄:runner 本体 + 收尾 + 一句话说明。 */
|
|
43
|
+
export interface WindowsTokenRunnerHandle {
|
|
44
|
+
runner: CommandRunner;
|
|
45
|
+
/** 进程收尾:尽力回收临时目录的能力 ACE(工作区/附加根是常驻授权,不回收)。 */
|
|
46
|
+
dispose(): void;
|
|
47
|
+
/** 给用户看的一句话:强制了什么、哪些不管。 */
|
|
48
|
+
describe(): string;
|
|
49
|
+
/**
|
|
50
|
+
* 网络第二级是否已随本执行器生效(账号分支在位):插件据此把 enforcement
|
|
51
|
+
* 报成 full(FS 由账号 ACL + 交集双重锁死,网络由 WFP + 白名单代理锁死)。
|
|
52
|
+
*/
|
|
53
|
+
readonly networkEnforced: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 建一个受限令牌执行器。
|
|
57
|
+
*
|
|
58
|
+
* 授权是**惰性**的:第一次 `plan()` 才给目录打 ACL(大树首次传播要几十秒,
|
|
59
|
+
* 挂载时不做)。按路径缓存结果,同一目录只授权一次;任一目录失败就整体降级。
|
|
60
|
+
*/
|
|
61
|
+
export declare function createWindowsTokenRunner(options: WindowsTokenRunnerOptions): WindowsTokenRunnerHandle;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows 受限令牌后端的探测与执行器:把 bash 工具的执行体换成
|
|
3
|
+
* `node runner-entry.js … -- <原命令>`,由 runner 用受限令牌真正 spawn 子进程。
|
|
4
|
+
*
|
|
5
|
+
* 为什么换执行体而不是在守卫链上拦:守卫链只拦得住 dsc 自己发起的工具调用,
|
|
6
|
+
* 拦不住命令内部的任意写(`node build.js` 里那行 fs.writeFile)。文件系统的
|
|
7
|
+
* 强制这一层只有换执行体才拿得到:ACL 上的能力 SID 授权 + 受限令牌的
|
|
8
|
+
* WRITE_RESTRICTED pass-2 交集检查,写根之外一律写不进去。
|
|
9
|
+
*
|
|
10
|
+
* 这一层**只管文件系统的写**,三处已知缺口如实写进 `describe()`,绝不假装管住了:
|
|
11
|
+
* 1. 硬链接别名:在写根内建一个指向根外文件的硬链接,写它等于写根外(NTFS 硬链接
|
|
12
|
+
* 不受路径判定约束);
|
|
13
|
+
* 2. 读不受限:WRITE_RESTRICTED 的 pass-2 只对写生效,读、网络、进程可见性
|
|
14
|
+
* 与普通用户一样;
|
|
15
|
+
* 3. 网络:真管控要「专用账号 + WFP + 白名单代理」那套提权 setup,本层只在
|
|
16
|
+
* 网络开关关时叠一层代理环境变量软墙(codex env.rs 同款),拦不住铁了心的进程。
|
|
17
|
+
*
|
|
18
|
+
* 降级语义(刻意的,不是妥协):ACL 授权任何一步失败 → 后端当场作废自己
|
|
19
|
+
* (`plan()` 此后返回 null),命令回到策略围栏那条路,并把错误全文报给用户。
|
|
20
|
+
* 半吊子的强制比明说「没强制」危险。
|
|
21
|
+
*
|
|
22
|
+
* @module dsc/core/sandbox/win/backend
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
import { DSC_HOME } from '../../path-policy.js';
|
|
28
|
+
import { grantAccountAccess, grantWrite, revokeWrite } from './acl.js';
|
|
29
|
+
import { bindAll, tryLoadFfi } from './ffi.js';
|
|
30
|
+
import { rootWriteSid, tempWriteSid } from './workspace-sid.js';
|
|
31
|
+
import { createNetProxy, proxyEnvVars } from '../net-proxy.js';
|
|
32
|
+
/** 执行器 id(宿主诊断与 `enforcement` 上报用这个键)。 */
|
|
33
|
+
export const WINDOWS_TOKEN_RUNNER_ID = 'sandbox-windows-token';
|
|
34
|
+
/** runner 自身失败的 stderr 签名:宿主与 win-token 冒烟探针靠它把「runner 挂了」与「命令失败了」分开。 */
|
|
35
|
+
export const RUNNER_FAILURE_SIGNATURE = 'dsc-sandbox-run: ';
|
|
36
|
+
/** 询问顺序:与容器后端同档(策略围栏先问,它之后才轮到换执行体)。 */
|
|
37
|
+
const RUNNER_ORDER = 20;
|
|
38
|
+
/** 授权锁文件目录:同目录并发授权要串行化,锁文件落在 dsc 家目录下。 */
|
|
39
|
+
const LOCK_DIR = join(DSC_HOME, 'sandbox', 'locks');
|
|
40
|
+
/** 网络开关关闭时叠的代理软墙(照 codex `env.rs` 的取值)。 */
|
|
41
|
+
const OFFLINE_ENV = {
|
|
42
|
+
HTTP_PROXY: 'http://127.0.0.1:9',
|
|
43
|
+
HTTPS_PROXY: 'http://127.0.0.1:9',
|
|
44
|
+
ALL_PROXY: 'http://127.0.0.1:9',
|
|
45
|
+
http_proxy: 'http://127.0.0.1:9',
|
|
46
|
+
https_proxy: 'http://127.0.0.1:9',
|
|
47
|
+
all_proxy: 'http://127.0.0.1:9',
|
|
48
|
+
NO_PROXY: 'localhost,127.0.0.1,::1',
|
|
49
|
+
no_proxy: 'localhost,127.0.0.1,::1',
|
|
50
|
+
PIP_NO_INDEX: '1',
|
|
51
|
+
PIP_DISABLE_PIP_VERSION_CHECK: '1',
|
|
52
|
+
NPM_CONFIG_OFFLINE: 'true',
|
|
53
|
+
CARGO_NET_OFFLINE: 'true',
|
|
54
|
+
GIT_SSH_COMMAND: 'cmd /c exit 1',
|
|
55
|
+
};
|
|
56
|
+
/** runner 入口脚本的构建产物(backend 编译后在 lib/ 里与 runner-entry.js 同目录)。 */
|
|
57
|
+
function runnerEntryPath() {
|
|
58
|
+
return fileURLToPath(new URL('./runner-entry.js', import.meta.url));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 探一次受限令牌后端可用性:Windows + koffi 装得上 + runner 构建产物在。
|
|
62
|
+
* 不实际建令牌(探测要快且无副作用),真正的失败在 runner 里响亮报出来。
|
|
63
|
+
*/
|
|
64
|
+
export function probeWindowsToken() {
|
|
65
|
+
if (process.platform !== 'win32')
|
|
66
|
+
return { available: false, detail: '非 Windows 平台' };
|
|
67
|
+
const loaded = tryLoadFfi();
|
|
68
|
+
if (!loaded.ok)
|
|
69
|
+
return { available: false, detail: `Win32 FFI 底座不可用:${loaded.why}` };
|
|
70
|
+
const entry = runnerEntryPath();
|
|
71
|
+
if (!existsSync(entry)) {
|
|
72
|
+
return { available: false, detail: `runner 入口没有构建产物:找不到 ${entry}(先跑 pnpm run build)` };
|
|
73
|
+
}
|
|
74
|
+
return { available: true, detail: '受限令牌后端可用(koffi FFI + runner 子进程)' };
|
|
75
|
+
}
|
|
76
|
+
/** 把错误转成一行可读文本(授权失败的「错误全文」要原样报给用户)。 */
|
|
77
|
+
function describeError(error) {
|
|
78
|
+
return error instanceof Error ? error.message : String(error);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 建一个受限令牌执行器。
|
|
82
|
+
*
|
|
83
|
+
* 授权是**惰性**的:第一次 `plan()` 才给目录打 ACL(大树首次传播要几十秒,
|
|
84
|
+
* 挂载时不做)。按路径缓存结果,同一目录只授权一次;任一目录失败就整体降级。
|
|
85
|
+
*/
|
|
86
|
+
export function createWindowsTokenRunner(options) {
|
|
87
|
+
// 目录清单:工作目录、私有临时目录、附加可写根(工作区与附加根用 rootWriteSid,
|
|
88
|
+
// temp 用 tempWriteSid,两种派生前缀不同,永不撞号)
|
|
89
|
+
const roots = [];
|
|
90
|
+
const push = (path, sid) => {
|
|
91
|
+
const key = path.replace(/[\\/]+$/, '').toLowerCase();
|
|
92
|
+
if (roots.some((root) => root.path.replace(/[\\/]+$/, '').toLowerCase() === key))
|
|
93
|
+
return;
|
|
94
|
+
roots.push({ path, sid });
|
|
95
|
+
};
|
|
96
|
+
if (options.mode === 'workspace-write') {
|
|
97
|
+
push(options.cwd, rootWriteSid(options.cwd));
|
|
98
|
+
push(options.tmpDir, tempWriteSid(options.tmpDir));
|
|
99
|
+
for (const extra of options.extraRoots ?? []) {
|
|
100
|
+
if (extra.trim() !== '')
|
|
101
|
+
push(extra, rootWriteSid(extra));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// read-only 刻意不做任何 ACL 授权:该档令牌不含能力 SID,写本来就全拒;
|
|
105
|
+
// 授权只会「永久改用户工作区的 ACL + 强制标签」,是纯副作用零收益,违背最小惊扰
|
|
106
|
+
const entry = runnerEntryPath();
|
|
107
|
+
const grants = new Map();
|
|
108
|
+
let bound = null;
|
|
109
|
+
let authorized = false;
|
|
110
|
+
let degraded = false;
|
|
111
|
+
/** 本地白名单代理(账号分支且开网时惰性起,dispose 时收)。 */
|
|
112
|
+
let proxy = null;
|
|
113
|
+
/** 惰性物化授权:true = 可以换执行体,false = 已降级(此后 plan 一律返回 null)。 */
|
|
114
|
+
const ensureAuthorized = () => {
|
|
115
|
+
if (degraded)
|
|
116
|
+
return false;
|
|
117
|
+
if (authorized)
|
|
118
|
+
return true;
|
|
119
|
+
if (roots.length === 0) {
|
|
120
|
+
// read-only:没有可授权目录,连 FFI 都不必加载(dispose 靠 bound===null 短路)
|
|
121
|
+
authorized = true;
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const loaded = tryLoadFfi();
|
|
126
|
+
if (!loaded.ok)
|
|
127
|
+
throw new Error(`Win32 FFI 底座不可用:${loaded.why}`);
|
|
128
|
+
const boundNow = bindAll(loaded.ffi);
|
|
129
|
+
bound = boundNow;
|
|
130
|
+
mkdirSync(LOCK_DIR, { recursive: true });
|
|
131
|
+
for (const root of roots) {
|
|
132
|
+
if (grants.has(root.path))
|
|
133
|
+
continue;
|
|
134
|
+
try {
|
|
135
|
+
grants.set(root.path, grantWrite(boundNow, root.path, root.sid, LOCK_DIR));
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new Error(`给可写根「${root.path}」(能力 SID ${root.sid})打 ACL 失败:${describeError(error)}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// 账号分支:每个可写根再补一条「账号 SID 读写执行」ACE——专用账号没有当前
|
|
142
|
+
// 用户的权限,pass-1(普通 SID 检查)靠它才过得去;pass-2 仍走上面的能力 SID
|
|
143
|
+
if (options.account !== undefined) {
|
|
144
|
+
for (const root of roots) {
|
|
145
|
+
grants.set(`${root.path}#account`, grantAccountAccess(boundNow, root.path, options.account.sid, LOCK_DIR));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
authorized = true;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
degraded = true;
|
|
153
|
+
options.onDetail?.(`受限令牌后端已降级为策略围栏(不再换执行体):${describeError(error)}`);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* 账号分支的网络出口:起本地白名单代理并返回要注入的环境变量。
|
|
159
|
+
* 代理起不来时返回 null(调用方回落软墙)——此时 WFP 把账号的一切出口堵死,
|
|
160
|
+
* 子进程等于离线,这是 fail-closed 的正确姿态,绝不静默放开。
|
|
161
|
+
*/
|
|
162
|
+
const ensureProxy = async () => {
|
|
163
|
+
if (proxy !== null)
|
|
164
|
+
return proxyEnvVars(proxy.url);
|
|
165
|
+
if (options.account === undefined)
|
|
166
|
+
return null;
|
|
167
|
+
try {
|
|
168
|
+
proxy = await createNetProxy({
|
|
169
|
+
port: options.account.proxyPort,
|
|
170
|
+
online: () => options.networkAccess(),
|
|
171
|
+
allowlist: () => options.networkAllowlist?.() ?? [],
|
|
172
|
+
});
|
|
173
|
+
options.onDetail?.(`出网白名单代理已起:${proxy.url}(账号的其余出口已被 WFP 堵死)`);
|
|
174
|
+
return proxyEnvVars(proxy.url);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
options.onDetail?.(`白名单代理起不来(账号出网将被 WFP 全拦,子进程等于离线):${describeError(error)}`);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const runner = {
|
|
182
|
+
id: WINDOWS_TOKEN_RUNNER_ID,
|
|
183
|
+
order: RUNNER_ORDER,
|
|
184
|
+
async plan(run, current) {
|
|
185
|
+
if (!ensureAuthorized())
|
|
186
|
+
return null;
|
|
187
|
+
// 已经是本后端换过的计划(别人套第二次):不套两层
|
|
188
|
+
if (current.file === process.execPath && current.args[0] === entry)
|
|
189
|
+
return null;
|
|
190
|
+
// 网络:账号分支开网走白名单代理(WFP 只给账号留了回环代理口),关网或
|
|
191
|
+
// 没有账号分支时叠一级软墙;不改调用方给的 env 对象,改复制品
|
|
192
|
+
let env = current.env;
|
|
193
|
+
const netOn = options.networkAccess();
|
|
194
|
+
if (options.account !== undefined) {
|
|
195
|
+
env = { ...env, ...(netOn ? (await ensureProxy()) ?? OFFLINE_ENV : OFFLINE_ENV) };
|
|
196
|
+
}
|
|
197
|
+
else if (!netOn) {
|
|
198
|
+
env = { ...env, ...OFFLINE_ENV };
|
|
199
|
+
}
|
|
200
|
+
const args = [
|
|
201
|
+
entry,
|
|
202
|
+
'--mode', options.mode,
|
|
203
|
+
'--temp', options.tmpDir,
|
|
204
|
+
...roots.flatMap((root) => ['--root', `${root.sid}=${root.path}`]),
|
|
205
|
+
...(options.account === undefined ? [] : ['--account', options.account.name, '--dsc-home', options.account.dscHome]),
|
|
206
|
+
'--',
|
|
207
|
+
current.file,
|
|
208
|
+
...current.args,
|
|
209
|
+
];
|
|
210
|
+
// 普通 node 子进程:不需要自定义 spawn,file/args/env/cwd 表达得下
|
|
211
|
+
return { ...current, file: process.execPath, args, env, cwd: run.cwd };
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
runner,
|
|
216
|
+
dispose() {
|
|
217
|
+
// 代理先收(在途连接断掉,端口让出来)
|
|
218
|
+
proxy?.close();
|
|
219
|
+
proxy = null;
|
|
220
|
+
// 临时目录是会话级授权:回收能力 ACE。工作区与附加根是常驻授权,不回收。
|
|
221
|
+
// 这里是尽力而为——回收失败只记一句,绝不影响会话结果(残留的假 SID ACE 惰性无害,
|
|
222
|
+
// 没有任何真实账号持有它)
|
|
223
|
+
if (bound === null)
|
|
224
|
+
return;
|
|
225
|
+
try {
|
|
226
|
+
revokeWrite(bound, options.tmpDir, tempWriteSid(options.tmpDir), LOCK_DIR);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
options.onDetail?.(`回收临时目录授权失败(不影响本次结果):${describeError(error)}`);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
describe() {
|
|
233
|
+
const net = options.account !== undefined
|
|
234
|
+
? '网络:账号分支在位——出网只过白名单代理,其余出口被 WFP 按账号 SID 堵死'
|
|
235
|
+
: '网络真管控要第二级提权 setup(本层只在断网时叠代理环境变量软墙)';
|
|
236
|
+
if (roots.length === 0) {
|
|
237
|
+
return '文件系统写:read-only 档,令牌不含能力 SID,任何目录都写不了;未对工作区做任何 ACL 改动;读与进程可见性不受限';
|
|
238
|
+
}
|
|
239
|
+
const list = roots.map((root) => root.path).join('、');
|
|
240
|
+
const readGap = options.account !== undefined
|
|
241
|
+
? '读与进程可见性被账号权限限死(账号只有可写根内的读执行)'
|
|
242
|
+
: '读与进程可见性一概不受限';
|
|
243
|
+
return `文件系统写:只允许写 ${list}(ACL 能力 SID + WRITE_RESTRICTED 交集检查,` +
|
|
244
|
+
`命令在受限令牌的 runner 子进程里跑);已知缺口:硬链接别名可指到写根外仍能写、` +
|
|
245
|
+
`${readGap};${net}`;
|
|
246
|
+
},
|
|
247
|
+
networkEnforced: options.account !== undefined,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 二级网络管控的**状态汇总**(免提权的 doctor):把「布防还在不在」拆成 6 项逐条查。
|
|
3
|
+
*
|
|
4
|
+
* 六项:① koffi/Win32 FFI 底座 → ② setup-state.json → ③ 账号存在且已启用 →
|
|
5
|
+
* ④ account.bin 能用 DPAPI 解开 → ⑤ 5 条防火墙规则在且按账号 SID 限定作用域 →
|
|
6
|
+
* ⑥ WFP 持久子层还在。
|
|
7
|
+
* 全绿 → `full`;任何一项缺 → `partial`。每项**独立容错**:一项炸了只让它自己变红,
|
|
8
|
+
* 不影响其余项,也不抛异常——doctor 的产物永远是「一句话明细列表」。
|
|
9
|
+
*
|
|
10
|
+
* 一个诚实的边界(本机实测):非提权会话看不到 WFP 对象,所以 ⑥ 在没提权的会话里可能报
|
|
11
|
+
* 「未查到」,wfp.ts 会把「结论不可信」写进 detail。这种情况 tier 依然是 partial(宁严勿松),
|
|
12
|
+
* 但明细会明确告诉你这是探测能力问题、还是真没布防。
|
|
13
|
+
*
|
|
14
|
+
* @module dsc/core/sandbox/win/doctor
|
|
15
|
+
*/
|
|
16
|
+
/** doctor 结论:`full` = 六项全绿;`partial` = 有任何一项没对上。 */
|
|
17
|
+
export interface WindowsNetworkDoctorResult {
|
|
18
|
+
readonly tier: 'full' | 'partial';
|
|
19
|
+
readonly details: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 逐项检查并给中文明细。**不抛**:所有异常都变成一条 `×` 明细。
|
|
23
|
+
*/
|
|
24
|
+
export declare function doctorWindowsNetwork(dscHome: string): Promise<WindowsNetworkDoctorResult>;
|