dsh-cliworker-now 0.0.0-stage → 0.7.7
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.en.md +364 -0
- package/README.md +368 -2
- package/cordis.patch.yml +3 -0
- package/lib/account-models.mjs +262 -0
- package/lib/client.js +22139 -0
- package/lib/client.js.map +1 -0
- package/lib/grok-catalog.mjs +145 -0
- package/lib/hermes-native-entry.py +96 -0
- package/lib/hermes-nous-refresh.py +331 -0
- package/lib/index.js +14544 -0
- package/lib/index.js.map +1 -0
- package/lib/native-launch.mjs +234 -0
- package/lib/native-spawn.mjs +32 -0
- package/lib/own-account-lease.mjs +105 -0
- package/lib/pi-installation.mjs +87 -0
- package/lib/pi-login.mjs +80 -0
- package/lib/pi-native-catalog.mjs +417 -0
- package/lib/pi-omp-bridge.mjs +602 -0
- package/lib/pi-omp-environment.mjs +15 -0
- package/lib/pi-omp-refresh.mjs +324 -0
- package/lib/private-launch.mjs +23 -0
- package/lib/terminal-bridge.mjs +18 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +1430 -0
- package/lib/typert.remote-client.d.ts +72 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +1256 -0
- package/lib/types/client/account-query-queue.d.ts +16 -0
- package/lib/types/client/account-query-queue.js +61 -0
- package/lib/types/client/account-query-queue.js.map +1 -0
- package/lib/types/client/account-terminal-css.d.ts +1 -0
- package/lib/types/client/account-terminal-css.js +3 -0
- package/lib/types/client/account-terminal-css.js.map +1 -0
- package/lib/types/client/account-terminal.d.ts +17 -0
- package/lib/types/client/account-terminal.js +525 -0
- package/lib/types/client/account-terminal.js.map +1 -0
- package/lib/types/client/assets/antigravity.png +0 -0
- package/lib/types/client/assets/claude-code.png +0 -0
- package/lib/types/client/assets/cliworker-now-logo.png +0 -0
- package/lib/types/client/assets/codex.png +0 -0
- package/lib/types/client/assets/grok.png +0 -0
- package/lib/types/client/assets/hermes.png +0 -0
- package/lib/types/client/assets/kimi-dark.png +0 -0
- package/lib/types/client/assets/kimi-light.png +0 -0
- package/lib/types/client/assets/mimo-code.png +0 -0
- package/lib/types/client/assets/omp.png +0 -0
- package/lib/types/client/assets/opencode.png +0 -0
- package/lib/types/client/assets/pi.png +0 -0
- package/lib/types/client/assets/zcode.png +0 -0
- package/lib/types/client/composer-keymap.d.ts +18 -0
- package/lib/types/client/composer-keymap.js +49 -0
- package/lib/types/client/composer-keymap.js.map +1 -0
- package/lib/types/client/conversation-timeline.d.ts +6 -0
- package/lib/types/client/conversation-timeline.js +65 -0
- package/lib/types/client/conversation-timeline.js.map +1 -0
- package/lib/types/client/copy-text.d.ts +5 -0
- package/lib/types/client/copy-text.js +45 -0
- package/lib/types/client/copy-text.js.map +1 -0
- package/lib/types/client/icons.d.ts +21 -0
- package/lib/types/client/icons.js +68 -0
- package/lib/types/client/icons.js.map +1 -0
- package/lib/types/client/index.d.ts +3 -0
- package/lib/types/client/index.js +124 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/management-styles.d.ts +1 -0
- package/lib/types/client/management-styles.js +17 -0
- package/lib/types/client/management-styles.js.map +1 -0
- package/lib/types/client/name-copy.d.ts +5 -0
- package/lib/types/client/name-copy.js +107 -0
- package/lib/types/client/name-copy.js.map +1 -0
- package/lib/types/client/native-job-overlay.d.ts +11 -0
- package/lib/types/client/native-job-overlay.js +129 -0
- package/lib/types/client/native-job-overlay.js.map +1 -0
- package/lib/types/client/operation-error.d.ts +2 -0
- package/lib/types/client/operation-error.js +12 -0
- package/lib/types/client/operation-error.js.map +1 -0
- package/lib/types/client/panel.d.ts +8 -0
- package/lib/types/client/panel.js +310 -0
- package/lib/types/client/panel.js.map +1 -0
- package/lib/types/client/rename-copy-styles.d.ts +1 -0
- package/lib/types/client/rename-copy-styles.js +21 -0
- package/lib/types/client/rename-copy-styles.js.map +1 -0
- package/lib/types/client/rename-worker.d.ts +9 -0
- package/lib/types/client/rename-worker.js +53 -0
- package/lib/types/client/rename-worker.js.map +1 -0
- package/lib/types/client/role-presets.d.ts +6 -0
- package/lib/types/client/role-presets.js +111 -0
- package/lib/types/client/role-presets.js.map +1 -0
- package/lib/types/client/settings-dialog.d.ts +13 -0
- package/lib/types/client/settings-dialog.js +442 -0
- package/lib/types/client/settings-dialog.js.map +1 -0
- package/lib/types/client/stat-popover.d.ts +10 -0
- package/lib/types/client/stat-popover.js +32 -0
- package/lib/types/client/stat-popover.js.map +1 -0
- package/lib/types/client/styles.d.ts +9 -0
- package/lib/types/client/styles.js +221 -0
- package/lib/types/client/styles.js.map +1 -0
- package/lib/types/client/telemetry.d.ts +11 -0
- package/lib/types/client/telemetry.js +24 -0
- package/lib/types/client/telemetry.js.map +1 -0
- package/lib/types/client/worker-card.d.ts +10 -0
- package/lib/types/client/worker-card.js +75 -0
- package/lib/types/client/worker-card.js.map +1 -0
- package/lib/types/client/worker-model-menu.d.ts +9 -0
- package/lib/types/client/worker-model-menu.js +136 -0
- package/lib/types/client/worker-model-menu.js.map +1 -0
- package/lib/types/client/workers.d.ts +21 -0
- package/lib/types/client/workers.js +59 -0
- package/lib/types/client/workers.js.map +1 -0
- package/lib/types/client/zcode-login-link-provider.d.ts +9 -0
- package/lib/types/client/zcode-login-link-provider.js +105 -0
- package/lib/types/client/zcode-login-link-provider.js.map +1 -0
- package/lib/types/client/zcode-login-link.d.ts +16 -0
- package/lib/types/client/zcode-login-link.js +194 -0
- package/lib/types/client/zcode-login-link.js.map +1 -0
- package/lib/types/host/account-identity.d.ts +16 -0
- package/lib/types/host/account-identity.js +126 -0
- package/lib/types/host/account-identity.js.map +1 -0
- package/lib/types/host/account-login.d.ts +10 -0
- package/lib/types/host/account-login.js +126 -0
- package/lib/types/host/account-login.js.map +1 -0
- package/lib/types/host/account-models.d.mts +21 -0
- package/lib/types/host/account-models.mjs +262 -0
- package/lib/types/host/accounts.d.ts +42 -0
- package/lib/types/host/accounts.js +945 -0
- package/lib/types/host/accounts.js.map +1 -0
- package/lib/types/host/adapters.d.ts +24 -0
- package/lib/types/host/adapters.js +380 -0
- package/lib/types/host/adapters.js.map +1 -0
- package/lib/types/host/agy-context.d.ts +8 -0
- package/lib/types/host/agy-context.js +122 -0
- package/lib/types/host/agy-context.js.map +1 -0
- package/lib/types/host/agy-models.d.ts +5 -0
- package/lib/types/host/agy-models.js +37 -0
- package/lib/types/host/agy-models.js.map +1 -0
- package/lib/types/host/agy-windows-account.d.ts +14 -0
- package/lib/types/host/agy-windows-account.js +104 -0
- package/lib/types/host/agy-windows-account.js.map +1 -0
- package/lib/types/host/authorized-catalog.d.ts +14 -0
- package/lib/types/host/authorized-catalog.js +35 -0
- package/lib/types/host/authorized-catalog.js.map +1 -0
- package/lib/types/host/bridge-protocol.d.ts +15 -0
- package/lib/types/host/bridge-protocol.js +80 -0
- package/lib/types/host/bridge-protocol.js.map +1 -0
- package/lib/types/host/claude-native-oauth.d.ts +17 -0
- package/lib/types/host/claude-native-oauth.js +272 -0
- package/lib/types/host/claude-native-oauth.js.map +1 -0
- package/lib/types/host/claude-own-route.d.ts +33 -0
- package/lib/types/host/claude-own-route.js +250 -0
- package/lib/types/host/claude-own-route.js.map +1 -0
- package/lib/types/host/cli-account-binding.d.ts +33 -0
- package/lib/types/host/cli-account-binding.js +540 -0
- package/lib/types/host/cli-account-binding.js.map +1 -0
- package/lib/types/host/cli-protocol.d.ts +27 -0
- package/lib/types/host/cli-protocol.js +212 -0
- package/lib/types/host/cli-protocol.js.map +1 -0
- package/lib/types/host/codex-account.d.ts +8 -0
- package/lib/types/host/codex-account.js +143 -0
- package/lib/types/host/codex-account.js.map +1 -0
- package/lib/types/host/codex-models.d.ts +6 -0
- package/lib/types/host/codex-models.js +169 -0
- package/lib/types/host/codex-models.js.map +1 -0
- package/lib/types/host/extended-adapters.d.ts +44 -0
- package/lib/types/host/extended-adapters.js +207 -0
- package/lib/types/host/extended-adapters.js.map +1 -0
- package/lib/types/host/first-party-account-context.d.ts +26 -0
- package/lib/types/host/first-party-account-context.js +55 -0
- package/lib/types/host/first-party-account-context.js.map +1 -0
- package/lib/types/host/first-party-models.d.ts +29 -0
- package/lib/types/host/first-party-models.js +459 -0
- package/lib/types/host/first-party-models.js.map +1 -0
- package/lib/types/host/grok-adapter.d.ts +44 -0
- package/lib/types/host/grok-adapter.js +293 -0
- package/lib/types/host/grok-adapter.js.map +1 -0
- package/lib/types/host/grok-models.d.ts +47 -0
- package/lib/types/host/grok-models.js +320 -0
- package/lib/types/host/grok-models.js.map +1 -0
- package/lib/types/host/harness-opencode-accounts.d.ts +17 -0
- package/lib/types/host/harness-opencode-accounts.js +80 -0
- package/lib/types/host/harness-opencode-accounts.js.map +1 -0
- package/lib/types/host/hermes-account-context.d.ts +8 -0
- package/lib/types/host/hermes-account-context.js +99 -0
- package/lib/types/host/hermes-account-context.js.map +1 -0
- package/lib/types/host/hermes-accounts.d.ts +19 -0
- package/lib/types/host/hermes-accounts.js +356 -0
- package/lib/types/host/hermes-accounts.js.map +1 -0
- package/lib/types/host/hermes-adapter.d.ts +93 -0
- package/lib/types/host/hermes-adapter.js +455 -0
- package/lib/types/host/hermes-adapter.js.map +1 -0
- package/lib/types/host/hermes-env.d.ts +4 -0
- package/lib/types/host/hermes-env.js +22 -0
- package/lib/types/host/hermes-env.js.map +1 -0
- package/lib/types/host/hermes-installation.d.ts +10 -0
- package/lib/types/host/hermes-installation.js +181 -0
- package/lib/types/host/hermes-installation.js.map +1 -0
- package/lib/types/host/hermes-models.d.ts +26 -0
- package/lib/types/host/hermes-models.js +328 -0
- package/lib/types/host/hermes-models.js.map +1 -0
- package/lib/types/host/hermes-native-entry.py +96 -0
- package/lib/types/host/hermes-nous-refresh.py +331 -0
- package/lib/types/host/hermes-nous.d.ts +53 -0
- package/lib/types/host/hermes-nous.js +343 -0
- package/lib/types/host/hermes-nous.js.map +1 -0
- package/lib/types/host/hermes-renewal.d.ts +27 -0
- package/lib/types/host/hermes-renewal.js +292 -0
- package/lib/types/host/hermes-renewal.js.map +1 -0
- package/lib/types/host/hermes-suppression.d.ts +7 -0
- package/lib/types/host/hermes-suppression.js +69 -0
- package/lib/types/host/hermes-suppression.js.map +1 -0
- package/lib/types/host/hermes-windows-installation.d.ts +5 -0
- package/lib/types/host/hermes-windows-installation.js +91 -0
- package/lib/types/host/hermes-windows-installation.js.map +1 -0
- package/lib/types/host/index.d.ts +140 -0
- package/lib/types/host/index.js +947 -0
- package/lib/types/host/index.js.map +1 -0
- package/lib/types/host/kimi-accounts.d.ts +17 -0
- package/lib/types/host/kimi-accounts.js +220 -0
- package/lib/types/host/kimi-accounts.js.map +1 -0
- package/lib/types/host/kimi-oauth-models.d.ts +14 -0
- package/lib/types/host/kimi-oauth-models.js +246 -0
- package/lib/types/host/kimi-oauth-models.js.map +1 -0
- package/lib/types/host/managed-agent.d.ts +4 -0
- package/lib/types/host/managed-agent.js +127 -0
- package/lib/types/host/managed-agent.js.map +1 -0
- package/lib/types/host/mimo-configuration.d.ts +22 -0
- package/lib/types/host/mimo-configuration.js +258 -0
- package/lib/types/host/mimo-configuration.js.map +1 -0
- package/lib/types/host/mimo-metadata-cache.d.ts +22 -0
- package/lib/types/host/mimo-metadata-cache.js +121 -0
- package/lib/types/host/mimo-metadata-cache.js.map +1 -0
- package/lib/types/host/native-capability-cache.d.ts +11 -0
- package/lib/types/host/native-capability-cache.js +94 -0
- package/lib/types/host/native-capability-cache.js.map +1 -0
- package/lib/types/host/native-launch.d.mts +2 -0
- package/lib/types/host/native-launch.mjs +234 -0
- package/lib/types/host/native-process.d.ts +5 -0
- package/lib/types/host/native-process.js +41 -0
- package/lib/types/host/native-process.js.map +1 -0
- package/lib/types/host/native-spawn.mjs +32 -0
- package/lib/types/host/opencode-adapter.d.ts +94 -0
- package/lib/types/host/opencode-adapter.js +507 -0
- package/lib/types/host/opencode-adapter.js.map +1 -0
- package/lib/types/host/opencode-native.d.ts +27 -0
- package/lib/types/host/opencode-native.js +403 -0
- package/lib/types/host/opencode-native.js.map +1 -0
- package/lib/types/host/own-account-lease.d.mts +5 -0
- package/lib/types/host/own-account-lease.mjs +105 -0
- package/lib/types/host/pi-installation.d.mts +7 -0
- package/lib/types/host/pi-installation.mjs +87 -0
- package/lib/types/host/pi-omp-accounts.d.ts +28 -0
- package/lib/types/host/pi-omp-accounts.js +175 -0
- package/lib/types/host/pi-omp-accounts.js.map +1 -0
- package/lib/types/host/pi-omp-adapter.d.ts +32 -0
- package/lib/types/host/pi-omp-adapter.js +190 -0
- package/lib/types/host/pi-omp-adapter.js.map +1 -0
- package/lib/types/host/pi-omp-environment.d.mts +1 -0
- package/lib/types/host/pi-omp-environment.mjs +15 -0
- package/lib/types/host/pi-omp-identity.d.ts +2 -0
- package/lib/types/host/pi-omp-identity.js +142 -0
- package/lib/types/host/pi-omp-identity.js.map +1 -0
- package/lib/types/host/pi-omp-logout.d.ts +3 -0
- package/lib/types/host/pi-omp-logout.js +152 -0
- package/lib/types/host/pi-omp-logout.js.map +1 -0
- package/lib/types/host/pi-omp-native.d.ts +71 -0
- package/lib/types/host/pi-omp-native.js +753 -0
- package/lib/types/host/pi-omp-native.js.map +1 -0
- package/lib/types/host/pi-omp-refresh.d.mts +7 -0
- package/lib/types/host/pi-omp-refresh.mjs +324 -0
- package/lib/types/host/private-launch.mjs +23 -0
- package/lib/types/host/process.d.ts +43 -0
- package/lib/types/host/process.js +134 -0
- package/lib/types/host/process.js.map +1 -0
- package/lib/types/host/protocol.d.ts +23 -0
- package/lib/types/host/protocol.js +112 -0
- package/lib/types/host/protocol.js.map +1 -0
- package/lib/types/host/roles.d.ts +34 -0
- package/lib/types/host/roles.js +80 -0
- package/lib/types/host/roles.js.map +1 -0
- package/lib/types/host/routing.d.ts +31 -0
- package/lib/types/host/routing.js +248 -0
- package/lib/types/host/routing.js.map +1 -0
- package/lib/types/host/runtime.d.ts +60 -0
- package/lib/types/host/runtime.js +598 -0
- package/lib/types/host/runtime.js.map +1 -0
- package/lib/types/host/storage.d.ts +48 -0
- package/lib/types/host/storage.js +449 -0
- package/lib/types/host/storage.js.map +1 -0
- package/lib/types/host/telemetry.d.ts +17 -0
- package/lib/types/host/telemetry.js +158 -0
- package/lib/types/host/telemetry.js.map +1 -0
- package/lib/types/host/windows-account-bootstrap.ps1 +44 -0
- package/lib/types/host/windows-account-launch.mjs +47 -0
- package/lib/types/host/windows-account-owner.ps1 +137 -0
- package/lib/types/host/windows-account-stdio.mjs +19 -0
- package/lib/types/host/windows-account-terminal.d.ts +17 -0
- package/lib/types/host/windows-account-terminal.js +208 -0
- package/lib/types/host/windows-account-terminal.js.map +1 -0
- package/lib/types/host/windows-agy-account.ps1 +81 -0
- package/lib/types/host/windows-cli-installation.d.ts +31 -0
- package/lib/types/host/windows-cli-installation.js +157 -0
- package/lib/types/host/windows-cli-installation.js.map +1 -0
- package/lib/types/host/windows-hidden-launch.mjs +49 -0
- package/lib/types/host/windows-hidden-process.d.ts +12 -0
- package/lib/types/host/windows-hidden-process.js +116 -0
- package/lib/types/host/windows-hidden-process.js.map +1 -0
- package/lib/types/host/zcode-account-models.d.ts +16 -0
- package/lib/types/host/zcode-account-models.js +114 -0
- package/lib/types/host/zcode-account-models.js.map +1 -0
- package/lib/types/host/zcode-adapter.d.ts +93 -0
- package/lib/types/host/zcode-adapter.js +808 -0
- package/lib/types/host/zcode-adapter.js.map +1 -0
- package/lib/types/host/zcode-grok-accounts.d.ts +30 -0
- package/lib/types/host/zcode-grok-accounts.js +408 -0
- package/lib/types/host/zcode-grok-accounts.js.map +1 -0
- package/lib/types/shared/accounts.d.ts +47 -0
- package/lib/types/shared/accounts.js +2 -0
- package/lib/types/shared/accounts.js.map +1 -0
- package/lib/types/shared/builtin-presets.d.ts +2 -0
- package/lib/types/shared/builtin-presets.js +231 -0
- package/lib/types/shared/builtin-presets.js.map +1 -0
- package/lib/types/shared/cli-settings.d.ts +5 -0
- package/lib/types/shared/cli-settings.js +2 -0
- package/lib/types/shared/cli-settings.js.map +1 -0
- package/lib/types/shared/model-presentation.d.ts +10 -0
- package/lib/types/shared/model-presentation.js +95 -0
- package/lib/types/shared/model-presentation.js.map +1 -0
- package/lib/types/shared/models.d.ts +7 -0
- package/lib/types/shared/models.js +35 -0
- package/lib/types/shared/models.js.map +1 -0
- package/lib/types/shared/telemetry.d.ts +18 -0
- package/lib/types/shared/telemetry.js +16 -0
- package/lib/types/shared/telemetry.js.map +1 -0
- package/lib/types/shared/types.d.ts +127 -0
- package/lib/types/shared/types.js +147 -0
- package/lib/types/shared/types.js.map +1 -0
- package/lib/windows-account-bootstrap.ps1 +44 -0
- package/lib/windows-account-launch.mjs +47 -0
- package/lib/windows-account-owner.ps1 +137 -0
- package/lib/windows-account-stdio.mjs +19 -0
- package/lib/windows-agy-account.ps1 +81 -0
- package/lib/windows-hidden-launch.mjs +49 -0
- package/lib/zcode-resume.mjs +423 -0
- package/package.json +109 -4
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { lstat, open } from 'node:fs/promises';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import { safePiOmpAncestors } from "./pi-omp-native.js";
|
|
6
|
+
/** Hash current bounded own files without retaining file content or following links. */
|
|
7
|
+
export async function metadataFileFingerprint(path, signal) {
|
|
8
|
+
let file;
|
|
9
|
+
let bytes;
|
|
10
|
+
try {
|
|
11
|
+
signal.throwIfAborted();
|
|
12
|
+
await safePiOmpAncestors(dirname(path));
|
|
13
|
+
const before = await lstat(path);
|
|
14
|
+
if (before.isSymbolicLink() || !before.isFile() || before.nlink !== 1 || before.size > 1_048_576)
|
|
15
|
+
return;
|
|
16
|
+
file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
17
|
+
const opened = await file.stat();
|
|
18
|
+
if (!opened.isFile() ||
|
|
19
|
+
opened.dev !== before.dev ||
|
|
20
|
+
opened.ino !== before.ino ||
|
|
21
|
+
opened.nlink !== 1 ||
|
|
22
|
+
opened.size !== before.size ||
|
|
23
|
+
opened.size > 1_048_576 ||
|
|
24
|
+
opened.mtimeMs !== before.mtimeMs)
|
|
25
|
+
return;
|
|
26
|
+
bytes = Buffer.alloc(opened.size + 1);
|
|
27
|
+
let offset = 0;
|
|
28
|
+
while (offset < bytes.length) {
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
const read = await file.read(bytes, offset, bytes.length - offset, offset);
|
|
31
|
+
if (!read.bytesRead)
|
|
32
|
+
break;
|
|
33
|
+
offset += read.bytesRead;
|
|
34
|
+
}
|
|
35
|
+
const after = await file.stat(), current = await lstat(path);
|
|
36
|
+
signal.throwIfAborted();
|
|
37
|
+
if (current.isSymbolicLink() ||
|
|
38
|
+
current.dev !== opened.dev ||
|
|
39
|
+
current.ino !== opened.ino ||
|
|
40
|
+
current.nlink !== 1 ||
|
|
41
|
+
offset !== opened.size ||
|
|
42
|
+
after.size !== opened.size ||
|
|
43
|
+
current.size !== opened.size ||
|
|
44
|
+
after.mtimeMs !== opened.mtimeMs ||
|
|
45
|
+
current.mtimeMs !== opened.mtimeMs ||
|
|
46
|
+
after.ctimeMs !== opened.ctimeMs ||
|
|
47
|
+
current.ctimeMs !== opened.ctimeMs)
|
|
48
|
+
return;
|
|
49
|
+
return createHash('sha256').update(bytes.subarray(0, offset)).digest('hex');
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
return error.code === 'ENOENT' ? 'missing' : undefined;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
bytes?.fill(0);
|
|
57
|
+
await file?.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Callers admit only validated public capabilities, never account status or raw CLI output. */
|
|
61
|
+
export class NativeCapabilityCache {
|
|
62
|
+
ttlMs;
|
|
63
|
+
limit;
|
|
64
|
+
entries = new Map();
|
|
65
|
+
constructor(ttlMs = 30_000, limit = 16) {
|
|
66
|
+
this.ttlMs = ttlMs;
|
|
67
|
+
this.limit = limit;
|
|
68
|
+
}
|
|
69
|
+
get(key) {
|
|
70
|
+
if (!key)
|
|
71
|
+
return;
|
|
72
|
+
const entry = this.entries.get(key), now = Date.now();
|
|
73
|
+
if (!entry)
|
|
74
|
+
return;
|
|
75
|
+
if (now < entry.created || now - entry.created >= this.ttlMs) {
|
|
76
|
+
this.entries.delete(key);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return structuredClone(entry.value);
|
|
80
|
+
}
|
|
81
|
+
set(key, value) {
|
|
82
|
+
if (!key)
|
|
83
|
+
return;
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
for (const [id, entry] of this.entries)
|
|
86
|
+
if (now < entry.created || now - entry.created >= this.ttlMs)
|
|
87
|
+
this.entries.delete(id);
|
|
88
|
+
this.entries.delete(key);
|
|
89
|
+
this.entries.set(key, { created: now, value: structuredClone(value) });
|
|
90
|
+
while (this.entries.size > this.limit)
|
|
91
|
+
this.entries.delete(this.entries.keys().next().value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=native-capability-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-capability-cache.js","sourceRoot":"","sources":["../../../src/host/native-capability-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,IAAY,EACZ,MAAmB;IAEnB,IAAI,IAAkD,CAAA;IACtD,IAAI,KAAyB,CAAA;IAC7B,IAAI,CAAC;QACH,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;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAM,CAAC,CAAA;IAC/F,CAAC;CACF"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// Inspect fixed launcher data; never ask a shell to interpret CLI arguments.
|
|
2
|
+
import { openSync, readSync, fstatSync, closeSync, realpathSync, statSync, existsSync } from 'node:fs'
|
|
3
|
+
import { basename, dirname, extname, isAbsolute, relative, resolve, sep, delimiter, join } from 'node:path'
|
|
4
|
+
import { homedir, userInfo } from 'node:os'
|
|
5
|
+
|
|
6
|
+
const invalid = () => Object.assign(
|
|
7
|
+
new Error('CLI 启动入口无法确认,请配置原生程序或固定 Node/Bun 入口'),
|
|
8
|
+
{ code: 'CLI_LAUNCHER_UNSUPPORTED' },
|
|
9
|
+
)
|
|
10
|
+
const batch = (value) => /\.(?:cmd|bat)$/i.test(value)
|
|
11
|
+
function text(path, limit = 128 * 1024) {
|
|
12
|
+
const descriptor = openSync(path, 'r')
|
|
13
|
+
try {
|
|
14
|
+
const info = fstatSync(descriptor)
|
|
15
|
+
if (!info.isFile() || info.size > limit) throw invalid()
|
|
16
|
+
const bytes = Buffer.alloc(info.size + 1)
|
|
17
|
+
const read = readSync(descriptor, bytes, 0, bytes.length, 0)
|
|
18
|
+
const after = fstatSync(descriptor)
|
|
19
|
+
if (read !== info.size || info.size !== after.size || info.mtimeMs !== after.mtimeMs) throw invalid()
|
|
20
|
+
return bytes
|
|
21
|
+
.subarray(0, read)
|
|
22
|
+
.toString('utf8')
|
|
23
|
+
.replace(/^\uFEFF/, '')
|
|
24
|
+
} finally {
|
|
25
|
+
closeSync(descriptor)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function file(path) {
|
|
29
|
+
const canonical = realpathSync(path)
|
|
30
|
+
if (!statSync(canonical).isFile()) throw invalid()
|
|
31
|
+
return canonical
|
|
32
|
+
}
|
|
33
|
+
function scriptRuntime(path) {
|
|
34
|
+
const descriptor = openSync(path, 'r')
|
|
35
|
+
try {
|
|
36
|
+
const bytes = Buffer.alloc(256)
|
|
37
|
+
const length = readSync(descriptor, bytes, 0, bytes.length, 0)
|
|
38
|
+
const header = bytes.subarray(0, length).toString('utf8').split('\n')[0].trim()
|
|
39
|
+
if (header.startsWith('#!')) {
|
|
40
|
+
const match = /^#!\s*(?:\/usr\/bin\/env\s+(?:-S\s+)?)?(?:[^\s]*\/)?(node|bun)\s*$/.exec(header)
|
|
41
|
+
if (!match) throw invalid()
|
|
42
|
+
return match[1]
|
|
43
|
+
}
|
|
44
|
+
// A fixed npm bin entry can declare its runtime in the package manifest.
|
|
45
|
+
for (let directory = dirname(path), depth = 0; depth < 5; depth++, directory = dirname(directory)) {
|
|
46
|
+
const manifestPath = join(directory, 'package.json')
|
|
47
|
+
if (!existsSync(manifestPath)) continue
|
|
48
|
+
const manifest = JSON.parse(text(manifestPath))
|
|
49
|
+
const bins = typeof manifest.bin === 'string' ? [manifest.bin] : Object.values(manifest.bin ?? {})
|
|
50
|
+
if (bins.some((entry) => typeof entry === 'string' && resolve(directory, entry) === path)) {
|
|
51
|
+
if (manifest.engines?.bun && !manifest.engines?.node) return 'bun'
|
|
52
|
+
return 'node'
|
|
53
|
+
}
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
return /\.[cm]?js$/i.test(path) ? 'node' : undefined
|
|
57
|
+
} finally {
|
|
58
|
+
closeSync(descriptor)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function runtimeProgram(runtime, platform, launcherDirectory) {
|
|
62
|
+
if (runtime === 'node') return process.execPath
|
|
63
|
+
if (runtime !== 'bun') throw invalid()
|
|
64
|
+
const name = platform === 'win32' ? 'bun.exe' : 'bun'
|
|
65
|
+
const candidates = [
|
|
66
|
+
...(launcherDirectory ? [join(launcherDirectory, name)] : []),
|
|
67
|
+
...(process.env.PATH ?? '')
|
|
68
|
+
.split(delimiter)
|
|
69
|
+
.map((directory) => directory.replace(/^"|"$/g, ''))
|
|
70
|
+
.filter(isAbsolute)
|
|
71
|
+
.map((directory) => join(directory, name)),
|
|
72
|
+
...(process.env.BUN_INSTALL ? [join(process.env.BUN_INSTALL, 'bin', name)] : []),
|
|
73
|
+
...[homedir(), userInfo().homedir].map((home) => join(home, '.bun', 'bin', name)),
|
|
74
|
+
]
|
|
75
|
+
const candidate = candidates.find((path) => existsSync(path) && statSync(path).isFile())
|
|
76
|
+
if (!candidate) throw new Error('未找到 Bun,请安装该 CLI 所需的 Bun 运行时')
|
|
77
|
+
return file(candidate)
|
|
78
|
+
}
|
|
79
|
+
/** npm's native bin shim is data, not a batch program to execute. */
|
|
80
|
+
function nativePackageBin(shim, suffix) {
|
|
81
|
+
const parts = suffix.replace(/\\/g, '/').split('/')
|
|
82
|
+
if (parts[0] !== 'node_modules' || parts.some((part) => !part || part === '.' || part === '..'))
|
|
83
|
+
throw invalid()
|
|
84
|
+
const scoped = parts[1]?.startsWith('@')
|
|
85
|
+
const name = parts.slice(1, scoped ? 3 : 2).join('/')
|
|
86
|
+
if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(name)) throw invalid()
|
|
87
|
+
const root = fileDirectory(resolve(dirname(shim), ...parts.slice(0, scoped ? 3 : 2)))
|
|
88
|
+
const entry = file(resolve(dirname(shim), ...parts))
|
|
89
|
+
const inside = relative(root, entry)
|
|
90
|
+
if (!inside || inside === '..' || inside.startsWith('..' + sep) || isAbsolute(inside)) throw invalid()
|
|
91
|
+
const manifest = JSON.parse(text(join(root, 'package.json')))
|
|
92
|
+
const command = basename(shim, extname(shim))
|
|
93
|
+
const declared = typeof manifest.bin === 'string'
|
|
94
|
+
? name.split('/').at(-1) === command ? manifest.bin : undefined
|
|
95
|
+
: manifest.bin?.[command]
|
|
96
|
+
if (manifest.name !== name || typeof declared !== 'string' || isAbsolute(declared) ||
|
|
97
|
+
declared.replace(/\\/g, '/').split('/').includes('..') || file(resolve(root, declared)) !== entry)
|
|
98
|
+
throw invalid()
|
|
99
|
+
const descriptor = openSync(entry, 'r')
|
|
100
|
+
try {
|
|
101
|
+
const header = Buffer.alloc(64), signature = Buffer.alloc(4)
|
|
102
|
+
const size = fstatSync(descriptor).size
|
|
103
|
+
if (readSync(descriptor, header, 0, 64, 0) !== 64 || header.toString('ascii', 0, 2) !== 'MZ')
|
|
104
|
+
throw invalid()
|
|
105
|
+
const offset = header.readUInt32LE(0x3c)
|
|
106
|
+
if (offset < 64 || offset + 4 > size || readSync(descriptor, signature, 0, 4, offset) !== 4 ||
|
|
107
|
+
signature.toString('hex') !== '50450000') throw invalid()
|
|
108
|
+
} finally {
|
|
109
|
+
closeSync(descriptor)
|
|
110
|
+
}
|
|
111
|
+
return entry
|
|
112
|
+
}
|
|
113
|
+
function fileDirectory(path) {
|
|
114
|
+
const canonical = realpathSync(path)
|
|
115
|
+
if (!statSync(canonical).isDirectory()) throw invalid()
|
|
116
|
+
return canonical
|
|
117
|
+
}
|
|
118
|
+
function inspectBatch(executable, platform) {
|
|
119
|
+
const source = text(file(executable)).trim().replace(/\r\n/g, '\n')
|
|
120
|
+
// Nous' official fallback contains just a fixed interpreter and its encoded
|
|
121
|
+
// launcher. Preserve its own bootstrap; do not guess a virtualenv interpreter.
|
|
122
|
+
const hermes =
|
|
123
|
+
/^@echo off\n"([^"\n%]+)" -I -c "(import base64; exec\(base64\.b64decode\('([A-Za-z0-9+/]+={0,2})'\)\))" %\*$/i.exec(
|
|
124
|
+
source,
|
|
125
|
+
)
|
|
126
|
+
if (hermes) {
|
|
127
|
+
const decoded = Buffer.from(hermes[3], 'base64')
|
|
128
|
+
if (
|
|
129
|
+
!isAbsolute(hermes[1]) ||
|
|
130
|
+
decoded.toString('base64') !== hermes[3] ||
|
|
131
|
+
!decoded.toString('utf8').startsWith('import os, re, sys\n') ||
|
|
132
|
+
!decoded.toString('utf8').includes('import hermes_bootstrap') ||
|
|
133
|
+
!decoded.toString('utf8').includes('from hermes_cli.main import main')
|
|
134
|
+
)
|
|
135
|
+
throw invalid()
|
|
136
|
+
return { kind: 'python', argv: [file(hermes[1]), '-I', '-c', hermes[2]] }
|
|
137
|
+
}
|
|
138
|
+
const entries = new Set()
|
|
139
|
+
const runtimes = new Set()
|
|
140
|
+
for (const original of source.split('\n')) {
|
|
141
|
+
let line = original.trim()
|
|
142
|
+
if (!line || /^@?(?:echo off|rem\b.*)$/i.test(line)) continue
|
|
143
|
+
// npm cmd-shim's standard final control prefix is launcher boilerplate;
|
|
144
|
+
// it is discarded, and nothing from it is executed by this module.
|
|
145
|
+
line = line.replace(/^endLocal & goto #_undefined_# 2>NUL \|\| title [^&\n]+ & /i, '')
|
|
146
|
+
const native = /^@?"%(?:~dp0[\\/]?|dp0%[\\/])([^"\n%]+\.exe)"\s+%\*$/i.exec(line)
|
|
147
|
+
if (native) {
|
|
148
|
+
entries.add(nativePackageBin(executable, native[1]))
|
|
149
|
+
runtimes.add('native')
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
const command =
|
|
153
|
+
/^@?(?:(node|bun)|"%_prog%"|"%(?:~dp0[\\/]?|dp0%[\\/])(node|bun)\.exe")\s+"%(?:~dp0[\\/]?|dp0%[\\/])([^"\n%]+)"\s+%\*$/i.exec(
|
|
154
|
+
line,
|
|
155
|
+
)
|
|
156
|
+
if (command) {
|
|
157
|
+
const path = file(resolve(dirname(executable), command[3].replace(/[\\/]/g, sep)))
|
|
158
|
+
if (!scriptRuntime(path)) throw invalid()
|
|
159
|
+
entries.add(path)
|
|
160
|
+
if (command[1] || command[2]) runtimes.add((command[1] || command[2]).toLowerCase())
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
const program = /^@?set "?_prog=(?:%(?:~dp0[\\/]?|dp0%[\\/]))?(node|bun)(?:\.exe)?"?$/i.exec(line)
|
|
164
|
+
if (program) {
|
|
165
|
+
runtimes.add(program[1].toLowerCase())
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
if (
|
|
169
|
+
/^@?(?:goto start|:find_dp0|:start|set dp0=%~dp0|exit \/b|setlocal|endlocal|call :find_dp0)$/i.test(
|
|
170
|
+
line,
|
|
171
|
+
) ||
|
|
172
|
+
/^@?if (?:not )?exist "%(?:~dp0[\\/]?|dp0%[\\/])(?:node|bun)\.exe" \($/i.test(line) ||
|
|
173
|
+
/^\)(?: else \()?$/i.test(line) ||
|
|
174
|
+
/^@?set pathext=%pathext:;\.js;=;%$/i.test(line) ||
|
|
175
|
+
/^@?if (?:not )?defined node_path \($/i.test(line) ||
|
|
176
|
+
/^@?set "node_path=[^"\n&|<>]+"$/i.test(line)
|
|
177
|
+
)
|
|
178
|
+
continue
|
|
179
|
+
throw invalid()
|
|
180
|
+
}
|
|
181
|
+
if (entries.size !== 1 || runtimes.size !== 1) throw invalid()
|
|
182
|
+
const entry = [...entries][0],
|
|
183
|
+
runtime = [...runtimes][0]
|
|
184
|
+
if (runtime === 'native') return { kind: 'native', argv: [entry] }
|
|
185
|
+
if (scriptRuntime(entry) !== runtime) throw invalid()
|
|
186
|
+
return { kind: runtime, argv: [runtimeProgram(runtime, platform, dirname(executable)), entry] }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Canonical npm entry for installation identity checks; Python launchers keep their identity. */
|
|
190
|
+
export function resolveNativeEntry(executable, platform = process.platform) {
|
|
191
|
+
if (platform !== 'win32') return executable
|
|
192
|
+
if (isAbsolute(executable) && !extname(executable) && !existsSync(executable)) {
|
|
193
|
+
const extensions = (process.env.PATHEXT || '.EXE;.COM;.CMD;.BAT')
|
|
194
|
+
.split(';')
|
|
195
|
+
.map((extension) => extension.toLowerCase())
|
|
196
|
+
.filter((extension) => /^\.(?:exe|com|cmd|bat)$/.test(extension))
|
|
197
|
+
const candidate = [...new Set(extensions)]
|
|
198
|
+
.map((extension) => executable + extension)
|
|
199
|
+
.find((path) => existsSync(path) && statSync(path).isFile())
|
|
200
|
+
if (candidate) executable = candidate
|
|
201
|
+
}
|
|
202
|
+
if (!batch(executable)) return executable
|
|
203
|
+
let inspected
|
|
204
|
+
try {
|
|
205
|
+
inspected = inspectBatch(executable, platform)
|
|
206
|
+
} catch {
|
|
207
|
+
// A present but invalid shim is not an absent CLI. Never forward raw paths or script text.
|
|
208
|
+
throw invalid()
|
|
209
|
+
}
|
|
210
|
+
// Keep Bun's fixed shim identity: it may pin a bundled bun.exe beside the
|
|
211
|
+
// shim which cannot be recovered from only the package's JS path.
|
|
212
|
+
return inspected.kind === 'node' ? inspected.argv[1] : inspected.kind === 'native' ? inspected.argv[0] : executable
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Windows CreateProcess accepts real programs, not npm command files. */
|
|
216
|
+
export function nativeLaunchArgv(argv, platform = process.platform) {
|
|
217
|
+
if (
|
|
218
|
+
!Array.isArray(argv) ||
|
|
219
|
+
!argv.length ||
|
|
220
|
+
argv.some((value) => typeof value !== 'string' || value.includes('\0'))
|
|
221
|
+
)
|
|
222
|
+
throw invalid()
|
|
223
|
+
if (platform !== 'win32') {
|
|
224
|
+
if (!/\.[cm]?js$/i.test(argv[0])) return [...argv]
|
|
225
|
+
const entry = file(argv[0])
|
|
226
|
+
return [runtimeProgram(scriptRuntime(entry), platform), entry, ...argv.slice(1)]
|
|
227
|
+
}
|
|
228
|
+
const executable = resolveNativeEntry(argv[0], platform),
|
|
229
|
+
arguments_ = argv.slice(1)
|
|
230
|
+
if (batch(executable)) return [...inspectBatch(executable, platform).argv, ...arguments_]
|
|
231
|
+
if (/\.[cm]?js$/i.test(executable) || (extname(executable) === '' && scriptRuntime(executable)))
|
|
232
|
+
return [runtimeProgram(scriptRuntime(executable), platform), file(executable), ...arguments_]
|
|
233
|
+
return [executable, ...arguments_]
|
|
234
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProcessBackend } from './process.ts';
|
|
2
|
+
/** One normalization boundary for tasks, metadata and interactive account menus. */
|
|
3
|
+
export declare function nativeProcessBackend(backend: ProcessBackend, platform?: NodeJS.Platform, options?: {
|
|
4
|
+
electron?: boolean;
|
|
5
|
+
}): ProcessBackend;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { nativeLaunchArgv, resolveNativeEntry } from './native-launch.mjs';
|
|
2
|
+
import { win32 } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { isCurrentWindowsRuntime, needsWindowsHiddenLaunch, spawnWindowsHidden } from "./windows-hidden-process.js";
|
|
5
|
+
const privateLauncher = fileURLToPath(new URL('./private-launch.mjs', import.meta.url));
|
|
6
|
+
/** One normalization boundary for tasks, metadata and interactive account menus. */
|
|
7
|
+
export function nativeProcessBackend(backend, platform = process.platform, options = {}) {
|
|
8
|
+
const normalize = (spec) => {
|
|
9
|
+
const argv = nativeLaunchArgv(spec.argv, platform);
|
|
10
|
+
return {
|
|
11
|
+
...spec,
|
|
12
|
+
argv,
|
|
13
|
+
...(argv[0] === process.execPath || (platform === 'win32' && isCurrentWindowsRuntime(argv[0]))
|
|
14
|
+
? { env: { ...spec.env, ELECTRON_RUN_AS_NODE: '1' } } : {}),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
async resolveExecutable(name) {
|
|
19
|
+
return resolveNativeEntry(await backend.resolveExecutable(resolveNativeEntry(name, platform)), platform);
|
|
20
|
+
},
|
|
21
|
+
spawn(spec) {
|
|
22
|
+
const normalized = normalize(spec);
|
|
23
|
+
const electron = options.electron ?? !!process.versions.electron;
|
|
24
|
+
// Fold only our exact private-umask helper into the background relay.
|
|
25
|
+
// Leaving another pipe relay beneath it would delay the native exit
|
|
26
|
+
// receipt until all descendants released their inherited output pipes.
|
|
27
|
+
if (platform === 'win32' && electron && isCurrentWindowsRuntime(normalized.argv[0]) &&
|
|
28
|
+
normalized.argv.length > 2 && win32.normalize(normalized.argv[1]).toLowerCase() === win32.normalize(privateLauncher).toLowerCase())
|
|
29
|
+
return spawnWindowsHidden(backend, { ...normalized, argv: nativeLaunchArgv(normalized.argv.slice(2), platform) }, { privateUmask: true });
|
|
30
|
+
return needsWindowsHiddenLaunch(normalized.argv, platform, electron)
|
|
31
|
+
? spawnWindowsHidden(backend, normalized)
|
|
32
|
+
: backend.spawn(normalized);
|
|
33
|
+
},
|
|
34
|
+
...(backend.spawnTerminal
|
|
35
|
+
? {
|
|
36
|
+
spawnTerminal: (spec) => backend.spawnTerminal(normalize(spec)),
|
|
37
|
+
}
|
|
38
|
+
: {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=native-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-process.js","sourceRoot":"","sources":["../../../src/host/native-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACnH,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,sBAAsB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEvF,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CAClC,OAAuB,EACvB,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAC3B,UAAkC,EAAE;IAEpC,MAAM,SAAS,GAAG,CAAiE,IAAO,EAAE,EAAE;QAC5F,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAClD,OAAO;YACL,GAAG,IAAI;YACP,IAAI;YACJ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,uBAAuB,CAAC,IAAI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kB,CAAC,OAAO,EAAE,UAAU,CAAC;gBACzC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAC/B,CAAC;QACD,GAAG,CAAC,OAAO,CAAC,aAAa;YACvB,CAAC,CAAC;gBACE,aAAa,EAAE,CAAC,IAAiE,EAAE,EAAE,CACnF,OAAO,CAAC,aAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC1C;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
/** Native CLI descendants keep their pipes/ConPTY and the enclosing Host Job.
|
|
4
|
+
* Window presentation is per child: hiding a wrapper does not hide its children.
|
|
5
|
+
* Node ignores windowsHide on POSIX, so both platforms use this one boundary.
|
|
6
|
+
*/
|
|
7
|
+
export function spawnNativeProcess(executable, argv, options) {
|
|
8
|
+
return spawn(executable, argv, { ...options, windowsHide: true })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Relay ordinary background pipes as bytes with Node's stream backpressure.
|
|
12
|
+
* Numeric/inherited descriptors make libuv omit CREATE_NO_WINDOW on Windows.
|
|
13
|
+
* This must never be used for a ConPTY: its console handles stay inherited. */
|
|
14
|
+
export function forwardNativeStdio(child) {
|
|
15
|
+
const stopInput = () => {
|
|
16
|
+
process.stdin.unpipe(child.stdin)
|
|
17
|
+
process.stdin.destroy()
|
|
18
|
+
}
|
|
19
|
+
const fail = () => { child.kill('SIGTERM'); process.exitCode = 1 }
|
|
20
|
+
child.stdin.on('error', error => { stopInput(); if (error.code !== 'EPIPE') fail() })
|
|
21
|
+
child.stdin.once('close', stopInput)
|
|
22
|
+
child.once('exit', stopInput)
|
|
23
|
+
child.once('error', stopInput)
|
|
24
|
+
process.stdin.on('error', fail)
|
|
25
|
+
process.stdout.on('error', fail)
|
|
26
|
+
process.stderr.on('error', fail)
|
|
27
|
+
child.stdout.on('error', fail)
|
|
28
|
+
child.stderr.on('error', fail)
|
|
29
|
+
process.stdin.pipe(child.stdin)
|
|
30
|
+
child.stdout.pipe(process.stdout, { end: false })
|
|
31
|
+
child.stderr.pipe(process.stderr, { end: false })
|
|
32
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type ModelChoice, type TaskMode } from '../shared/types.ts';
|
|
2
|
+
import type { EventInput, ProtocolResult } from './protocol.ts';
|
|
3
|
+
import { type OpenCodeNativeOptions } from './opencode-native.ts';
|
|
4
|
+
import { probeAccountModels } from './account-models.mjs';
|
|
5
|
+
export interface OpenCodeInput {
|
|
6
|
+
executable: string;
|
|
7
|
+
project: string;
|
|
8
|
+
preference: {
|
|
9
|
+
model: string;
|
|
10
|
+
effort: string;
|
|
11
|
+
};
|
|
12
|
+
mode: TaskMode;
|
|
13
|
+
prompt: string;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
stateDirectory: string;
|
|
16
|
+
/** Stable private XDG data root shared with account login, not worker databases. */
|
|
17
|
+
authDirectory?: string;
|
|
18
|
+
/** Deprecated compatibility option; ignored. */
|
|
19
|
+
managedCredentials?: boolean;
|
|
20
|
+
nativeHome?: string;
|
|
21
|
+
modelsPath?: string;
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
type Capture = (argv: string[], env?: Record<string, string>) => Promise<string>;
|
|
25
|
+
export interface OpenCodeCredentialConfig {
|
|
26
|
+
zaiCredentialRef?: string;
|
|
27
|
+
resolveCredential?: (ref: string) => Promise<string | undefined>;
|
|
28
|
+
}
|
|
29
|
+
/** Compatibility only: Host credentials are never resolved for OpenCode. */
|
|
30
|
+
export declare function openCodeCredentialEnvironment(_config: OpenCodeCredentialConfig): Promise<Record<string, string>>;
|
|
31
|
+
export declare function openCodeAuthDirectory(stateDirectory?: string): string;
|
|
32
|
+
/** Only the auth data root is shared; each process keeps its own DB/config/cache. */
|
|
33
|
+
export declare function openCodeEnvironment(stateDirectory: string, config: Record<string, unknown>, authDirectory?: string, _managedCredentials?: boolean, modelsPath?: string): Promise<{
|
|
34
|
+
OPENCODE_MODELS_PATH?: string | undefined;
|
|
35
|
+
XDG_CONFIG_HOME: string;
|
|
36
|
+
XDG_DATA_HOME: string;
|
|
37
|
+
XDG_CACHE_HOME: string;
|
|
38
|
+
XDG_STATE_HOME: string;
|
|
39
|
+
TMPDIR: string;
|
|
40
|
+
OPENCODE_DB: string;
|
|
41
|
+
OPENCODE_CONFIG: string;
|
|
42
|
+
OPENCODE_CONFIG_DIR: string;
|
|
43
|
+
OPENCODE_CONFIG_CONTENT: string;
|
|
44
|
+
OPENCODE_PERMISSION: string;
|
|
45
|
+
OPENCODE_AUTO_SHARE: string;
|
|
46
|
+
OPENCODE_DISABLE_AUTOUPDATE: string;
|
|
47
|
+
OPENCODE_DISABLE_PRUNE: string;
|
|
48
|
+
OPENCODE_DISABLE_SHARE: string;
|
|
49
|
+
OPENCODE_DISABLE_DEFAULT_PLUGINS: string;
|
|
50
|
+
OPENCODE_AUTH_CONTENT: string;
|
|
51
|
+
OPENCODE_DISABLE_PROJECT_CONFIG: string;
|
|
52
|
+
OPENCODE_DISABLE_CLAUDE_CODE: string;
|
|
53
|
+
OPENCODE_DISABLE_EXTERNAL_SKILLS: string;
|
|
54
|
+
OPENCODE_DISABLE_LSP_DOWNLOAD: string;
|
|
55
|
+
OPENCODE_DISABLE_MODELS_FETCH: string;
|
|
56
|
+
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: string;
|
|
57
|
+
OPENCODE_PURE: string;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function prepareOpenCode(input: OpenCodeInput): Promise<{
|
|
60
|
+
argv: string[];
|
|
61
|
+
env: Record<string, string>;
|
|
62
|
+
}>;
|
|
63
|
+
/** CLI default zero prices are not affirmative price evidence. */
|
|
64
|
+
export declare function parseOpenCodeModels(output: string): ModelChoice[];
|
|
65
|
+
export interface OpenCodeDiscoveryOptions extends OpenCodeNativeOptions {
|
|
66
|
+
credentialEnv?: Record<string, string>;
|
|
67
|
+
probeOptions?: Parameters<typeof probeAccountModels>[1];
|
|
68
|
+
}
|
|
69
|
+
export declare function discoverOpenCode(executable: string, capture: Capture, stateDirectory: string, authDirectory?: string, _managedCredentials?: boolean, options?: OpenCodeDiscoveryOptions): Promise<ModelChoice[]>;
|
|
70
|
+
/** Native OpenCode JSONL; success needs clean EOF after stop, identity and no failed tool. */
|
|
71
|
+
export declare class OpenCodeProtocol {
|
|
72
|
+
private emit;
|
|
73
|
+
private identify;
|
|
74
|
+
private maxLineBytes;
|
|
75
|
+
private decoder;
|
|
76
|
+
private pending;
|
|
77
|
+
private ended;
|
|
78
|
+
private stopped;
|
|
79
|
+
private sawStep;
|
|
80
|
+
private failure?;
|
|
81
|
+
private response;
|
|
82
|
+
private steps;
|
|
83
|
+
private textParts;
|
|
84
|
+
private openTools;
|
|
85
|
+
conversationId?: string;
|
|
86
|
+
result?: ProtocolResult;
|
|
87
|
+
constructor(emit: (event: EventInput) => void, identify: (id: string) => void, maxLineBytes: number);
|
|
88
|
+
feed(chunk: Buffer | string): void;
|
|
89
|
+
end(): void;
|
|
90
|
+
private step;
|
|
91
|
+
private id;
|
|
92
|
+
private line;
|
|
93
|
+
}
|
|
94
|
+
export {};
|