@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,272 @@
|
|
|
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
|
+
import { spawn } from 'node:child_process';
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { bindAll, tryLoadFfi } from './ffi.js';
|
|
20
|
+
import { accountBlobPath, readSetupState, unprotectSecret } from './account.js';
|
|
21
|
+
import { firewallRuleNames, DSC_WFP_SUBLAYER_GUID } from './net-abi.js';
|
|
22
|
+
import { DSC_SANDBOX_ACCOUNT, DSC_SANDBOX_DEFAULT_PROXY_PORT } from './setup.js';
|
|
23
|
+
import { probeWfpSublayer } from './wfp.js';
|
|
24
|
+
/** 每项的超时(查防火墙/本地账号的 cmdlet 偶尔会慢,给足 20 秒)。 */
|
|
25
|
+
const ITEM_TIMEOUT_MS = 20_000;
|
|
26
|
+
/**
|
|
27
|
+
* 逐项检查并给中文明细。**不抛**:所有异常都变成一条 `×` 明细。
|
|
28
|
+
*/
|
|
29
|
+
export async function doctorWindowsNetwork(dscHome) {
|
|
30
|
+
const details = [];
|
|
31
|
+
let bad = 0;
|
|
32
|
+
const mark = (ok, text) => {
|
|
33
|
+
if (!ok)
|
|
34
|
+
bad += 1;
|
|
35
|
+
details.push(`${ok ? '√' : '×'} ${text}`);
|
|
36
|
+
};
|
|
37
|
+
// ① FFI 底座:后面几项(DPAPI、WFP 探测)都要用
|
|
38
|
+
let ffiOk = false;
|
|
39
|
+
try {
|
|
40
|
+
const ffi = tryLoadFfi();
|
|
41
|
+
ffiOk = ffi.ok;
|
|
42
|
+
mark(ffi.ok, ffi.ok ? 'koffi/Win32 FFI 底座可用(kernel32 + advapi32 已绑)' : `koffi/Win32 FFI 底座不可用:${ffi.why}`);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
mark(false, `探测 FFI 底座时异常:${errorText(error)}`);
|
|
46
|
+
}
|
|
47
|
+
// ② 账本
|
|
48
|
+
let state = null;
|
|
49
|
+
try {
|
|
50
|
+
const read = readSetupState(dscHome);
|
|
51
|
+
if (read === null) {
|
|
52
|
+
mark(false, '没有 setup-state.json:二级网络管控还没成功 setup 过一次');
|
|
53
|
+
}
|
|
54
|
+
else if (!read.ok) {
|
|
55
|
+
mark(false, read.error);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
state = read.state;
|
|
59
|
+
mark(true, `setup-state.json 在:账号 ${read.state.account}(${read.state.sid}),代理端口 ${String(read.state.proxyPort)},布防时间 ${read.state.at}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
mark(false, `读 setup-state.json 时异常:${errorText(error)}`);
|
|
64
|
+
}
|
|
65
|
+
const account = state?.account ?? DSC_SANDBOX_ACCOUNT;
|
|
66
|
+
const proxyPort = state?.proxyPort ?? DSC_SANDBOX_DEFAULT_PROXY_PORT;
|
|
67
|
+
const expectedSid = state?.sid ?? null;
|
|
68
|
+
// ③ 账号存在且已启用
|
|
69
|
+
try {
|
|
70
|
+
const probe = await queryAccount(account);
|
|
71
|
+
if (!probe.ok) {
|
|
72
|
+
mark(false, `查本地账号 ${account} 失败:${probe.detail}`);
|
|
73
|
+
}
|
|
74
|
+
else if (!probe.exists) {
|
|
75
|
+
mark(false, `本地账号 ${account} 不存在(二级网络管控没布防,或已被清理)`);
|
|
76
|
+
}
|
|
77
|
+
else if (!probe.enabled) {
|
|
78
|
+
mark(false, `本地账号 ${account} 存在但处于禁用态(setup 走到一半被打断?重跑 setup 即可)`);
|
|
79
|
+
}
|
|
80
|
+
else if (expectedSid !== null && probe.sid !== null && probe.sid.toLowerCase() !== expectedSid.toLowerCase()) {
|
|
81
|
+
mark(false, `本地账号 ${account} 的 SID(${probe.sid})与账本里的(${expectedSid})不一致:账本是旧的,请重跑 setup`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
mark(true, `本地账号 ${account} 存在且已启用(SID ${probe.sid ?? '未知'})`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
mark(false, `查本地账号 ${account} 时异常:${errorText(error)}`);
|
|
89
|
+
}
|
|
90
|
+
// ④ account.bin 能解开(只报长度,绝不打印密码)
|
|
91
|
+
try {
|
|
92
|
+
if (!ffiOk) {
|
|
93
|
+
mark(false, '跳过 account.bin 检查:FFI 底座不可用,DPAPI 解不开');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const blobPath = accountBlobPath(dscHome);
|
|
97
|
+
if (!existsSync(blobPath)) {
|
|
98
|
+
mark(false, `没有 account.bin(${blobPath}):沙箱账号密码没落盘,起不了沙箱进程`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const ffi = tryLoadFfi();
|
|
102
|
+
if (!ffi.ok)
|
|
103
|
+
throw new Error(`Win32 FFI 底座不可用:${ffi.why}`);
|
|
104
|
+
const bound = bindAll(ffi.ffi);
|
|
105
|
+
const secret = unprotectSecret(bound, readFileSync(blobPath));
|
|
106
|
+
mark(true, `account.bin 可用 DPAPI 解开(明文 ${String(secret.length)} 个字符,按设计不打印内容)`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
mark(false, `account.bin 检查失败:${errorText(error)}`);
|
|
112
|
+
}
|
|
113
|
+
// ⑤ 5 条防火墙规则在,且按账号 SID 限定作用域
|
|
114
|
+
try {
|
|
115
|
+
const names = firewallRuleNames(proxyPort);
|
|
116
|
+
const probe = await queryFirewallRules(names);
|
|
117
|
+
if (!probe.ok) {
|
|
118
|
+
mark(false, `查防火墙规则失败:${probe.detail}`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const missing = names.filter((name) => !probe.found.includes(name.toLowerCase()));
|
|
122
|
+
if (missing.length > 0) {
|
|
123
|
+
mark(false, `防火墙规则缺 ${String(missing.length)} 条:${missing.join('、')}`);
|
|
124
|
+
}
|
|
125
|
+
else if (probe.scopes.size === 0) {
|
|
126
|
+
mark(true, `5 条防火墙规则都在(作用域没读出来,没有核对 LocalUserAuthorizedList)`);
|
|
127
|
+
}
|
|
128
|
+
else if (expectedSid === null) {
|
|
129
|
+
mark(true, `5 条防火墙规则都在(账本里没有 SID,跳过了作用域核对)`);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// 认两种写法:SDDL 里可能是 SID,也可能被规范化成账号名(都不算错,只要不是别的账号)
|
|
133
|
+
const wrong = [...probe.scopes.entries()].filter(([, scope]) => {
|
|
134
|
+
const text = scope.toLowerCase();
|
|
135
|
+
return !text.includes(expectedSid.toLowerCase()) && !text.includes(account.toLowerCase());
|
|
136
|
+
});
|
|
137
|
+
if (wrong.length > 0) {
|
|
138
|
+
mark(false, `防火墙规则作用域不对(没按账号 ${account} / SID ${expectedSid} 限定):${wrong.map(([name]) => name).join('、')}`);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
mark(true, `5 条防火墙规则都在,且作用域都限定在账号 ${account}(SID ${expectedSid})上`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
mark(false, `查防火墙规则时异常:${errorText(error)}`);
|
|
148
|
+
}
|
|
149
|
+
// ⑥ WFP 持久子层——**提示项,不计入 tier**:非提权会话看不到 WFP 对象是 Windows
|
|
150
|
+
// 权限行为(engine 打得开、对象查询必被拒),而 setup 脚本「首错即停」且账本写在
|
|
151
|
+
// WFP 安装成功之后,②-⑤ 全绿已蕴含布防在位。探测结果只作展示,避免非提权环境
|
|
152
|
+
// 永远 partial 的假阴性。
|
|
153
|
+
try {
|
|
154
|
+
const probe = probeWfpSublayer(state?.wfpSublayerGuid ?? DSC_WFP_SUBLAYER_GUID);
|
|
155
|
+
if (probe.present) {
|
|
156
|
+
details.push(`√ WFP 子层探测:${probe.detail}`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
details.push(`· WFP 子层探测(提示项,不计入结论):${probe.detail}——账本(②)在即代表布防已写入`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
details.push(`· WFP 子层探测异常(提示项,不计入结论):${errorText(error)}`);
|
|
164
|
+
}
|
|
165
|
+
return { tier: bad === 0 ? 'full' : 'partial', details };
|
|
166
|
+
}
|
|
167
|
+
/** 用 PowerShell 查本地账号(Get-LocalUser 只在 PS 5.1+ 的 LocalAccounts 模块里有)。 */
|
|
168
|
+
async function queryAccount(account) {
|
|
169
|
+
const command = [
|
|
170
|
+
`$u = Get-LocalUser -Name ${quotePowerShell(account)} -ErrorAction SilentlyContinue`,
|
|
171
|
+
`if ($null -eq $u) { '{"exists":false}' } else {`,
|
|
172
|
+
` ConvertTo-Json -Compress -InputObject ([ordered]@{ exists = $true; enabled = [bool]$u.Enabled; sid = [string]$u.SID.Value })`,
|
|
173
|
+
`}`,
|
|
174
|
+
].join('\n');
|
|
175
|
+
const outcome = await runPowerShell(command, ITEM_TIMEOUT_MS);
|
|
176
|
+
if (outcome.code !== 0 && outcome.stdout.trim() === '') {
|
|
177
|
+
return { ok: false, detail: `powershell 退出码 ${String(outcome.code)}:${outcome.stderr.trim() || '没有输出'}`, exists: false, enabled: false, sid: null };
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const parsed = JSON.parse(outcome.stdout.trim());
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
detail: '',
|
|
184
|
+
exists: parsed.exists === true,
|
|
185
|
+
enabled: parsed.enabled === true,
|
|
186
|
+
sid: typeof parsed.sid === 'string' ? parsed.sid : null,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return { ok: false, detail: `解析 Get-LocalUser 输出失败:${errorText(error)};原始输出 ${outcome.stdout.trim().slice(0, 200)}`, exists: false, enabled: false, sid: null };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 查规则在不在,并顺带把每条规则的 LocalUserAuthorizedList 读出来(核对作用域)。
|
|
195
|
+
* 作用域读不出来的那些(老系统/权限问题)不进 scopes,Doctor 会按「没核对」处理而不是判错。
|
|
196
|
+
*/
|
|
197
|
+
async function queryFirewallRules(names) {
|
|
198
|
+
const nameList = names.map(quotePowerShell).join(', ');
|
|
199
|
+
const command = [
|
|
200
|
+
`$out = @()`,
|
|
201
|
+
`foreach ($r in @(Get-NetFirewallRule -Name @(${nameList}) -ErrorAction SilentlyContinue)) {`,
|
|
202
|
+
` $scope = ''`,
|
|
203
|
+
` try { $scope = [string](($r | Get-NetFirewallSecurityFilter).LocalUser) } catch { $scope = '' }`,
|
|
204
|
+
` $out += ($r.Name + '||' + $scope)`,
|
|
205
|
+
`}`,
|
|
206
|
+
`$out`,
|
|
207
|
+
].join('\n');
|
|
208
|
+
const outcome = await runPowerShell(command, ITEM_TIMEOUT_MS);
|
|
209
|
+
if (outcome.code !== 0 && outcome.stdout.trim() === '') {
|
|
210
|
+
return { ok: false, detail: `powershell 退出码 ${String(outcome.code)}:${outcome.stderr.trim() || '没有输出'}`, found: [], scopes: new Map() };
|
|
211
|
+
}
|
|
212
|
+
const found = [];
|
|
213
|
+
const scopes = new Map();
|
|
214
|
+
for (const line of outcome.stdout.split(/\r?\n/)) {
|
|
215
|
+
const text = line.trim();
|
|
216
|
+
if (text === '')
|
|
217
|
+
continue;
|
|
218
|
+
const [name, scope] = text.split('||');
|
|
219
|
+
if (name === undefined || name === '')
|
|
220
|
+
continue;
|
|
221
|
+
found.push(name.toLowerCase());
|
|
222
|
+
if (typeof scope === 'string' && scope.trim() !== '')
|
|
223
|
+
scopes.set(name, scope.trim());
|
|
224
|
+
}
|
|
225
|
+
return { ok: true, detail: '', found, scopes };
|
|
226
|
+
}
|
|
227
|
+
/** 跑一次 Windows PowerShell 5.1 的 -Command,收退出码与输出。 */
|
|
228
|
+
function runPowerShell(command, timeoutMs) {
|
|
229
|
+
return new Promise((resolve) => {
|
|
230
|
+
let stdout = '';
|
|
231
|
+
let stderr = '';
|
|
232
|
+
let settled = false;
|
|
233
|
+
// 让 PS 用 UTF-8 写 stdout:中文的诊断信息(规则名、错误文本)按 GBK 出来在 node 侧就是乱码
|
|
234
|
+
const wrapped = `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}`;
|
|
235
|
+
const child = spawn(join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'), ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', wrapped], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
236
|
+
const timer = setTimeout(() => {
|
|
237
|
+
if (settled)
|
|
238
|
+
return;
|
|
239
|
+
settled = true;
|
|
240
|
+
child.kill();
|
|
241
|
+
resolve({ code: -1, stdout, stderr: `${stderr}\n(超时 ${String(timeoutMs)} ms 已终止)` });
|
|
242
|
+
}, timeoutMs);
|
|
243
|
+
child.stdout?.on('data', (chunk) => {
|
|
244
|
+
stdout += chunk.toString('utf8');
|
|
245
|
+
});
|
|
246
|
+
child.stderr?.on('data', (chunk) => {
|
|
247
|
+
stderr += chunk.toString('utf8');
|
|
248
|
+
});
|
|
249
|
+
child.on('error', (error) => {
|
|
250
|
+
if (settled)
|
|
251
|
+
return;
|
|
252
|
+
settled = true;
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
resolve({ code: -1, stdout, stderr: `${stderr}\n${errorText(error)}` });
|
|
255
|
+
});
|
|
256
|
+
child.on('close', (code) => {
|
|
257
|
+
if (settled)
|
|
258
|
+
return;
|
|
259
|
+
settled = true;
|
|
260
|
+
clearTimeout(timer);
|
|
261
|
+
resolve({ code: code ?? -1, stdout, stderr });
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** PowerShell 单引号字面量:内部单引号翻倍。 */
|
|
266
|
+
function quotePowerShell(value) {
|
|
267
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
268
|
+
}
|
|
269
|
+
/** 异常转一句话。 */
|
|
270
|
+
function errorText(error) {
|
|
271
|
+
return error instanceof Error ? error.message : String(error);
|
|
272
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** 带 API 名与 Win32 错误码的错误:上层给用户看的每句话都来自它。 */
|
|
2
|
+
export declare class Win32Error extends Error {
|
|
3
|
+
readonly api: string;
|
|
4
|
+
readonly win32Code: number;
|
|
5
|
+
constructor(api: string, win32Code: number, detail: string);
|
|
6
|
+
}
|
|
7
|
+
/** koffi 模块的最小形状(只声明用到的那几个入口,避免整包类型依赖)。 */
|
|
8
|
+
interface KoffiLike {
|
|
9
|
+
load(name: string): KoffiLibrary;
|
|
10
|
+
alloc(type: string, count: number): unknown;
|
|
11
|
+
decode(value: unknown, type: string, count?: number): unknown;
|
|
12
|
+
address(value: unknown): bigint;
|
|
13
|
+
errno(): number;
|
|
14
|
+
}
|
|
15
|
+
interface KoffiLibrary {
|
|
16
|
+
func(convention: string, name: string, result: string, args: string[]): (...args: unknown[]) => unknown;
|
|
17
|
+
}
|
|
18
|
+
/** 绑定后的库对:进程侧(kernel32)与安全侧(advapi32)。 */
|
|
19
|
+
export interface WinFfi {
|
|
20
|
+
readonly koffi: KoffiLike;
|
|
21
|
+
readonly k32: KoffiLibrary;
|
|
22
|
+
readonly adv: KoffiLibrary;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 尝试加载 FFI 底座。koffi 缺失/加载失败/非 Windows 都返回 `{ok:false}`,
|
|
26
|
+
* 由调用方决定降级路径(插件照常挂载,强制后端不启用)。
|
|
27
|
+
*/
|
|
28
|
+
export declare function tryLoadFfi(): {
|
|
29
|
+
ok: true;
|
|
30
|
+
ffi: WinFfi;
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
why: string;
|
|
34
|
+
};
|
|
35
|
+
/** 加载失败时直接抛(runner 子进程等「后端已确认可用」的路径用)。 */
|
|
36
|
+
export declare function loadFfi(): WinFfi;
|
|
37
|
+
/** 绑定表形状(由 bindAll 推断;不写返回注解是为了避免 ReturnType 自引用)。 */
|
|
38
|
+
export type BoundWin32 = ReturnType<typeof bindAll>;
|
|
39
|
+
/** 一份现成的绑定表。只在这里写签名,别处不碰 koffi 原生对象。 */
|
|
40
|
+
export declare function bindAll(ffi: WinFfi): {
|
|
41
|
+
koffi: KoffiLike;
|
|
42
|
+
closeHandle: (...args: unknown[]) => unknown;
|
|
43
|
+
getLastLastError: (...args: unknown[]) => unknown;
|
|
44
|
+
formatMessageW: (...args: unknown[]) => unknown;
|
|
45
|
+
createPipe: (...args: unknown[]) => unknown;
|
|
46
|
+
setHandleInformation: (...args: unknown[]) => unknown;
|
|
47
|
+
readFile: (...args: unknown[]) => unknown;
|
|
48
|
+
peekNamedPipe: (...args: unknown[]) => unknown;
|
|
49
|
+
waitForSingleObject: (...args: unknown[]) => unknown;
|
|
50
|
+
getExitCodeProcess: (...args: unknown[]) => unknown;
|
|
51
|
+
createJobObjectW: (...args: unknown[]) => unknown;
|
|
52
|
+
setInformationJobObject: (...args: unknown[]) => unknown;
|
|
53
|
+
assignProcessToJobObject: (...args: unknown[]) => unknown;
|
|
54
|
+
resumeThread: (...args: unknown[]) => unknown;
|
|
55
|
+
terminateProcess: (...args: unknown[]) => unknown;
|
|
56
|
+
terminateJobObject: (...args: unknown[]) => unknown;
|
|
57
|
+
setConsoleCtrlHandler: (...args: unknown[]) => unknown;
|
|
58
|
+
setEnvironmentVariableW: (...args: unknown[]) => unknown;
|
|
59
|
+
createFileW: (...args: unknown[]) => unknown;
|
|
60
|
+
lockFileEx: (...args: unknown[]) => unknown;
|
|
61
|
+
unlockFileEx: (...args: unknown[]) => unknown;
|
|
62
|
+
openProcess: (...args: unknown[]) => unknown;
|
|
63
|
+
localAlloc: (...args: unknown[]) => unknown;
|
|
64
|
+
localFree: (...args: unknown[]) => unknown;
|
|
65
|
+
createProcessAsUserW: (...args: unknown[]) => unknown;
|
|
66
|
+
openProcessToken: (...args: unknown[]) => unknown;
|
|
67
|
+
convertStringSidToSidW: (...args: unknown[]) => unknown;
|
|
68
|
+
createWellKnownSid: (...args: unknown[]) => unknown;
|
|
69
|
+
isValidSid: (...args: unknown[]) => unknown;
|
|
70
|
+
getLengthSid: (...args: unknown[]) => unknown;
|
|
71
|
+
copySid: (...args: unknown[]) => unknown;
|
|
72
|
+
getTokenInformation: (...args: unknown[]) => unknown;
|
|
73
|
+
setTokenInformation: (...args: unknown[]) => unknown;
|
|
74
|
+
createRestrictedToken: (...args: unknown[]) => unknown;
|
|
75
|
+
setEntriesInAclW: (...args: unknown[]) => unknown;
|
|
76
|
+
logonUserW: (...args: unknown[]) => unknown;
|
|
77
|
+
initializeAcl: (...args: unknown[]) => unknown;
|
|
78
|
+
addMandatoryAce: (...args: unknown[]) => unknown;
|
|
79
|
+
setNamedSecurityInfoW: (...args: unknown[]) => unknown;
|
|
80
|
+
getNamedSecurityInfoW: (...args: unknown[]) => unknown;
|
|
81
|
+
};
|
|
82
|
+
/** 把最近一次 Win32 错误转成 `Win32Error` 抛出。 */
|
|
83
|
+
export declare function throwLastError(bound: BoundWin32, api: string): never;
|
|
84
|
+
/** 「返回值即错误码」的调用(SetEntriesInAclW / Set·GetNamedSecurityInfoW)用这个抛。 */
|
|
85
|
+
export declare function throwWin32(bound: BoundWin32, api: string, code: number): never;
|
|
86
|
+
/** 这个管道错误意味着对端已关闭:读循环的正常终点,不算失败。 */
|
|
87
|
+
export declare function isBrokenPipe(code: number): boolean;
|
|
88
|
+
/** 开一个 `uintptr_t` 出参槽(句柄/系统指针回填),`get()` 直接给 number。 */
|
|
89
|
+
export declare function slotUintPtr(bound: BoundWin32): {
|
|
90
|
+
slot: unknown;
|
|
91
|
+
get: () => number;
|
|
92
|
+
};
|
|
93
|
+
/** 开一个 `uint32` 出参槽。 */
|
|
94
|
+
export declare function slotUint32(bound: BoundWin32): {
|
|
95
|
+
slot: unknown;
|
|
96
|
+
get: () => number;
|
|
97
|
+
};
|
|
98
|
+
/** 开一块 n 字节的读写内存(GetTokenInformation 的载荷、ReadFile 的落点)。 */
|
|
99
|
+
export declare function byteArea(bound: BoundWin32, n: number): {
|
|
100
|
+
ptr: unknown;
|
|
101
|
+
bytes: () => Uint8Array;
|
|
102
|
+
};
|
|
103
|
+
/** Buffer 的数值地址(手工打包结构体时往里塞指针用;Buffer 必须活着别被 GC)。 */
|
|
104
|
+
export declare function addressOf(bound: BoundWin32, buffer: Buffer | Uint8Array): number;
|
|
105
|
+
/** 读系统指针指向的内存(PSID/PACL/SD 都是数值地址,decode 直读)。 */
|
|
106
|
+
export declare function readMemory(bound: BoundWin32, address: number, n: number): Uint8Array;
|
|
107
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* koffi FFI 绑定层:kernel32(进程/管道/作业)+ advapi32(令牌/ACL/安全描述符)。
|
|
3
|
+
*
|
|
4
|
+
* 口径(全文件统一,勿混):
|
|
5
|
+
* - **句柄与系统返回的指针(PSID/PACL/SD)一律 `uintptr_t`**,在 JS 侧就是 number;
|
|
6
|
+
* `koffi.decode(数值地址, 'uint8', n)` 可以直接读那块内存(已实测);
|
|
7
|
+
* - **我们自己 Buffer 的入参指针用 `'void *'` 直接传 Buffer**(koffi 取其地址,
|
|
8
|
+
* 且 API 的回写能从同一 Buffer 读回——已实测);需要嵌进手工结构体的地址
|
|
9
|
+
* 用 `koffi.address()` 取数值;
|
|
10
|
+
* - 结构体全部手工打包(见 abi.ts 偏移表),koffi struct 一概不用;
|
|
11
|
+
* - 每个 `int` 返回型调用失败都读 GetLastError 抛 `Win32Error{api, win32Code}`;
|
|
12
|
+
* 「返回值即错误码」的调用走 `throwWin32`;
|
|
13
|
+
* - 加载失败要能被上层探测到而不是崩宿主:`tryLoadFfi()` 给 `{ok:false, why}`。
|
|
14
|
+
*
|
|
15
|
+
* @module dsc/core/sandbox/win/ffi
|
|
16
|
+
*/
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
import { ERROR_BROKEN_PIPE, ERROR_NO_DATA } from './abi.js';
|
|
19
|
+
/** 带 API 名与 Win32 错误码的错误:上层给用户看的每句话都来自它。 */
|
|
20
|
+
export class Win32Error extends Error {
|
|
21
|
+
api;
|
|
22
|
+
win32Code;
|
|
23
|
+
constructor(api, win32Code, detail) {
|
|
24
|
+
super(`${api} 失败(Win32 错误码 ${String(win32Code)}):${detail}`);
|
|
25
|
+
this.name = 'Win32Error';
|
|
26
|
+
this.api = api;
|
|
27
|
+
this.win32Code = win32Code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let cached = null;
|
|
31
|
+
/**
|
|
32
|
+
* 尝试加载 FFI 底座。koffi 缺失/加载失败/非 Windows 都返回 `{ok:false}`,
|
|
33
|
+
* 由调用方决定降级路径(插件照常挂载,强制后端不启用)。
|
|
34
|
+
*/
|
|
35
|
+
export function tryLoadFfi() {
|
|
36
|
+
if (cached !== null)
|
|
37
|
+
return { ok: true, ffi: cached };
|
|
38
|
+
if (process.platform !== 'win32')
|
|
39
|
+
return { ok: false, why: '非 Windows 平台' };
|
|
40
|
+
try {
|
|
41
|
+
const require = createRequire(import.meta.url);
|
|
42
|
+
const koffi = require('koffi');
|
|
43
|
+
if (typeof koffi?.load !== 'function' || typeof koffi?.alloc !== 'function') {
|
|
44
|
+
return { ok: false, why: 'koffi 模块形状不对(版本不匹配?)' };
|
|
45
|
+
}
|
|
46
|
+
cached = { koffi, k32: koffi.load('kernel32.dll'), adv: koffi.load('advapi32.dll') };
|
|
47
|
+
return { ok: true, ffi: cached };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return { ok: false, why: error instanceof Error ? error.message : String(error) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** 加载失败时直接抛(runner 子进程等「后端已确认可用」的路径用)。 */
|
|
54
|
+
export function loadFfi() {
|
|
55
|
+
const result = tryLoadFfi();
|
|
56
|
+
if (!result.ok)
|
|
57
|
+
throw new Error(`Win32 FFI 底座不可用:${result.why}`);
|
|
58
|
+
return result.ffi;
|
|
59
|
+
}
|
|
60
|
+
/** 绑定一个 `__stdcall` 函数。 */
|
|
61
|
+
function bind(lib, name, result, args) {
|
|
62
|
+
return lib.func('__stdcall', name, result, args);
|
|
63
|
+
}
|
|
64
|
+
/** 一份现成的绑定表。只在这里写签名,别处不碰 koffi 原生对象。 */
|
|
65
|
+
export function bindAll(ffi) {
|
|
66
|
+
const { koffi, k32, adv } = ffi;
|
|
67
|
+
return {
|
|
68
|
+
koffi,
|
|
69
|
+
// ── kernel32:句柄/管道/作业/等待/锁(句柄一律 uintptr_t)──
|
|
70
|
+
closeHandle: bind(k32, 'CloseHandle', 'int', ['uintptr_t']),
|
|
71
|
+
getLastLastError: bind(k32, 'GetLastError', 'uint32', []),
|
|
72
|
+
formatMessageW: bind(k32, 'FormatMessageW', 'uint32', ['uint32', 'void *', 'uint32', 'uint32', 'void *', 'uint32', 'void *']),
|
|
73
|
+
createPipe: bind(k32, 'CreatePipe', 'int', ['void *', 'void *', 'void *', 'uint32']),
|
|
74
|
+
setHandleInformation: bind(k32, 'SetHandleInformation', 'int', ['uintptr_t', 'uint32', 'uint32']),
|
|
75
|
+
readFile: bind(k32, 'ReadFile', 'int', ['uintptr_t', 'void *', 'uint32', 'void *', 'void *']),
|
|
76
|
+
peekNamedPipe: bind(k32, 'PeekNamedPipe', 'int', ['uintptr_t', 'void *', 'uint32', 'void *', 'void *', 'void *']),
|
|
77
|
+
waitForSingleObject: bind(k32, 'WaitForSingleObject', 'uint32', ['uintptr_t', 'uint32']),
|
|
78
|
+
getExitCodeProcess: bind(k32, 'GetExitCodeProcess', 'int', ['uintptr_t', 'void *']),
|
|
79
|
+
createJobObjectW: bind(k32, 'CreateJobObjectW', 'uintptr_t', ['void *', 'void *']),
|
|
80
|
+
setInformationJobObject: bind(k32, 'SetInformationJobObject', 'int', ['uintptr_t', 'uint32', 'void *', 'uint32']),
|
|
81
|
+
assignProcessToJobObject: bind(k32, 'AssignProcessToJobObject', 'int', ['uintptr_t', 'uintptr_t']),
|
|
82
|
+
resumeThread: bind(k32, 'ResumeThread', 'uint32', ['uintptr_t']),
|
|
83
|
+
terminateProcess: bind(k32, 'TerminateProcess', 'int', ['uintptr_t', 'uint32']),
|
|
84
|
+
terminateJobObject: bind(k32, 'TerminateJobObject', 'int', ['uintptr_t', 'uint32']),
|
|
85
|
+
setConsoleCtrlHandler: bind(k32, 'SetConsoleCtrlHandler', 'int', ['void *', 'int']),
|
|
86
|
+
setEnvironmentVariableW: bind(k32, 'SetEnvironmentVariableW', 'int', ['void *', 'void *']),
|
|
87
|
+
createFileW: bind(k32, 'CreateFileW', 'uintptr_t', ['void *', 'uint32', 'uint32', 'void *', 'uint32', 'uint32', 'void *']),
|
|
88
|
+
lockFileEx: bind(k32, 'LockFileEx', 'int', ['uintptr_t', 'uint32', 'uint32', 'uint32', 'uint32', 'void *']),
|
|
89
|
+
unlockFileEx: bind(k32, 'UnlockFileEx', 'int', ['uintptr_t', 'uint32', 'uint32', 'uint32', 'void *']),
|
|
90
|
+
openProcess: bind(k32, 'OpenProcess', 'uintptr_t', ['uint32', 'int', 'uint32']),
|
|
91
|
+
localAlloc: bind(k32, 'LocalAlloc', 'uintptr_t', ['uint32', 'uintptr_t']),
|
|
92
|
+
localFree: bind(k32, 'LocalFree', 'uintptr_t', ['uintptr_t']),
|
|
93
|
+
// ── advapi32:CreateProcessAsUserW 活在这家(令牌那一家),不在 kernel32 ──
|
|
94
|
+
createProcessAsUserW: bind(adv, 'CreateProcessAsUserW', 'int', ['uintptr_t', 'void *', 'void *', 'void *', 'void *', 'int', 'uint32', 'void *', 'void *', 'void *', 'void *']),
|
|
95
|
+
openProcessToken: bind(adv, 'OpenProcessToken', 'int', ['uintptr_t', 'uint32', 'void *']),
|
|
96
|
+
convertStringSidToSidW: bind(adv, 'ConvertStringSidToSidW', 'int', ['void *', 'void *']),
|
|
97
|
+
createWellKnownSid: bind(adv, 'CreateWellKnownSid', 'int', ['uint32', 'uintptr_t', 'void *', 'void *']),
|
|
98
|
+
isValidSid: bind(adv, 'IsValidSid', 'int', ['uintptr_t']),
|
|
99
|
+
getLengthSid: bind(adv, 'GetLengthSid', 'uint32', ['uintptr_t']),
|
|
100
|
+
copySid: bind(adv, 'CopySid', 'int', ['uint32', 'void *', 'uintptr_t']),
|
|
101
|
+
getTokenInformation: bind(adv, 'GetTokenInformation', 'int', ['uintptr_t', 'uint32', 'void *', 'uint32', 'void *']),
|
|
102
|
+
setTokenInformation: bind(adv, 'SetTokenInformation', 'int', ['uintptr_t', 'uint32', 'void *', 'uint32']),
|
|
103
|
+
createRestrictedToken: bind(adv, 'CreateRestrictedToken', 'int', ['uintptr_t', 'uint32', 'uint32', 'uintptr_t', 'uint32', 'uintptr_t', 'uint32', 'void *', 'void *']),
|
|
104
|
+
setEntriesInAclW: bind(adv, 'SetEntriesInAclW', 'uint32', ['uint32', 'void *', 'uintptr_t', 'void *']),
|
|
105
|
+
logonUserW: bind(adv, 'LogonUserW', 'int', ['void *', 'void *', 'void *', 'uint32', 'uint32', 'void *']),
|
|
106
|
+
initializeAcl: bind(adv, 'InitializeAcl', 'int', ['void *', 'uint32', 'uint32']),
|
|
107
|
+
addMandatoryAce: bind(adv, 'AddMandatoryAce', 'int', ['void *', 'uint32', 'uint32', 'uint32', 'void *']),
|
|
108
|
+
setNamedSecurityInfoW: bind(adv, 'SetNamedSecurityInfoW', 'uint32', ['void *', 'uint32', 'uint32', 'uintptr_t', 'uintptr_t', 'uintptr_t', 'uintptr_t']),
|
|
109
|
+
getNamedSecurityInfoW: bind(adv, 'GetNamedSecurityInfoW', 'uint32', ['void *', 'uint32', 'uint32', 'void *', 'void *', 'void *', 'void *', 'void *']),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** 系统错误文本(本地化),拿不到就空串。 */
|
|
113
|
+
function systemErrorText(bound, code) {
|
|
114
|
+
try {
|
|
115
|
+
const buffer = bound.koffi.alloc('uint16', 512);
|
|
116
|
+
const written = Number(bound.formatMessageW(0x00001000, null, code, 0, buffer, 512, null));
|
|
117
|
+
if (written <= 0)
|
|
118
|
+
return '';
|
|
119
|
+
const bytes = new Uint8Array(bound.koffi.decode(buffer, 'uint8', written * 2));
|
|
120
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, written * 2).toString('utf16le').trim();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** 把最近一次 Win32 错误转成 `Win32Error` 抛出。 */
|
|
127
|
+
export function throwLastError(bound, api) {
|
|
128
|
+
const code = Number(bound.getLastLastError()) >>> 0;
|
|
129
|
+
const detail = systemErrorText(bound, code);
|
|
130
|
+
throw new Win32Error(api, code, detail !== '' ? detail : '(无系统描述)');
|
|
131
|
+
}
|
|
132
|
+
/** 「返回值即错误码」的调用(SetEntriesInAclW / Set·GetNamedSecurityInfoW)用这个抛。 */
|
|
133
|
+
export function throwWin32(bound, api, code) {
|
|
134
|
+
const normalized = Number(code) >>> 0;
|
|
135
|
+
const detail = systemErrorText(bound, normalized);
|
|
136
|
+
throw new Win32Error(api, normalized, detail !== '' ? detail : '(无系统描述)');
|
|
137
|
+
}
|
|
138
|
+
/** 这个管道错误意味着对端已关闭:读循环的正常终点,不算失败。 */
|
|
139
|
+
export function isBrokenPipe(code) {
|
|
140
|
+
const normalized = Number(code) >>> 0;
|
|
141
|
+
return normalized === ERROR_BROKEN_PIPE || normalized === ERROR_NO_DATA;
|
|
142
|
+
}
|
|
143
|
+
// ── 槽位与内存小工具 ─────────────────────────────────────────────────────────
|
|
144
|
+
/** 开一个 `uintptr_t` 出参槽(句柄/系统指针回填),`get()` 直接给 number。 */
|
|
145
|
+
export function slotUintPtr(bound) {
|
|
146
|
+
const slot = bound.koffi.alloc('uintptr_t', 1);
|
|
147
|
+
return { slot, get: () => Number(bound.koffi.decode(slot, 'uintptr_t')) };
|
|
148
|
+
}
|
|
149
|
+
/** 开一个 `uint32` 出参槽。 */
|
|
150
|
+
export function slotUint32(bound) {
|
|
151
|
+
const slot = bound.koffi.alloc('uint32', 1);
|
|
152
|
+
return { slot, get: () => Number(bound.koffi.decode(slot, 'uint32')) };
|
|
153
|
+
}
|
|
154
|
+
/** 开一块 n 字节的读写内存(GetTokenInformation 的载荷、ReadFile 的落点)。 */
|
|
155
|
+
export function byteArea(bound, n) {
|
|
156
|
+
const ptr = bound.koffi.alloc('uint8', n);
|
|
157
|
+
return { ptr, bytes: () => new Uint8Array(bound.koffi.decode(ptr, 'uint8', n)) };
|
|
158
|
+
}
|
|
159
|
+
/** Buffer 的数值地址(手工打包结构体时往里塞指针用;Buffer 必须活着别被 GC)。 */
|
|
160
|
+
export function addressOf(bound, buffer) {
|
|
161
|
+
return Number(bound.koffi.address(buffer));
|
|
162
|
+
}
|
|
163
|
+
/** 读系统指针指向的内存(PSID/PACL/SD 都是数值地址,decode 直读)。 */
|
|
164
|
+
export function readMemory(bound, address, n) {
|
|
165
|
+
return new Uint8Array(bound.koffi.decode(address, 'uint8', n));
|
|
166
|
+
}
|