toc-ocra 0.2.34 → 0.2.36
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 -21
- package/README.md +129 -121
- package/assets/icon.svg +1 -1
- package/dist/cli/cli.mjs +747 -395
- package/dist/plugin/renderer.css.map +1 -1
- package/dist/plugin/renderer.js.map +1 -1
- package/dist/service/agent.mjs +734 -383
- package/dist/src/exec/script-runner.js +9 -5
- package/dist/src/exec/script-runner.js.map +1 -1
- package/dist/src/health/server.js +8 -8
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/platform/common.d.ts +20 -0
- package/dist/src/platform/common.js +40 -0
- package/dist/src/platform/common.js.map +1 -0
- package/dist/src/platform/index.d.ts +10 -0
- package/dist/src/platform/index.js +20 -0
- package/dist/src/platform/index.js.map +1 -0
- package/dist/src/platform/posix.d.ts +2 -0
- package/dist/src/platform/posix.js +210 -0
- package/dist/src/platform/posix.js.map +1 -0
- package/dist/src/platform/types.d.ts +61 -0
- package/dist/src/platform/types.js +2 -0
- package/dist/src/platform/types.js.map +1 -0
- package/dist/src/platform/win32.d.ts +4 -0
- package/dist/src/platform/win32.js +162 -0
- package/dist/src/platform/win32.js.map +1 -0
- package/dist/src/providers/cli/claude.js +3 -2
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/codex.js +3 -2
- package/dist/src/providers/cli/codex.js.map +1 -1
- package/dist/src/providers/cli/gemini.js +2 -2
- package/dist/src/providers/cli/gemini.js.map +1 -1
- package/dist/src/providers/cli/grok.js +2 -2
- package/dist/src/providers/cli/grok.js.map +1 -1
- package/dist/src/providers/cli/kiro-session-log.d.ts +53 -0
- package/dist/src/providers/cli/kiro-session-log.js +155 -0
- package/dist/src/providers/cli/kiro-session-log.js.map +1 -0
- package/dist/src/providers/cli/kiro.d.ts +8 -2
- package/dist/src/providers/cli/kiro.js +100 -13
- package/dist/src/providers/cli/kiro.js.map +1 -1
- package/dist/src/providers/cli/opencode.js +2 -2
- package/dist/src/providers/cli/opencode.js.map +1 -1
- package/dist/src/providers/codex-quota.js +3 -2
- package/dist/src/providers/codex-quota.js.map +1 -1
- package/dist/src/providers/detection.js +3 -1
- package/dist/src/providers/detection.js.map +1 -1
- package/dist/src/providers/kiro-models.js +3 -2
- package/dist/src/providers/kiro-models.js.map +1 -1
- package/dist/src/providers/model-catalog.js +3 -1
- package/dist/src/providers/model-catalog.js.map +1 -1
- package/dist/src/providers/provider.d.ts +55 -4
- package/dist/src/providers/provider.js +51 -15
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/runs/orphan-registry.js +2 -8
- package/dist/src/runs/orphan-registry.js.map +1 -1
- package/dist/src/runs/process-tree.d.ts +5 -14
- package/dist/src/runs/process-tree.js +7 -83
- package/dist/src/runs/process-tree.js.map +1 -1
- package/dist/src/runs/run-supervisor.d.ts +2 -0
- package/dist/src/runs/run-supervisor.js +56 -10
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/dist/src/runtime/cli/hydrate-shell-path.d.ts +9 -22
- package/dist/src/runtime/cli/hydrate-shell-path.js +17 -148
- package/dist/src/runtime/cli/hydrate-shell-path.js.map +1 -1
- package/dist/src/shared/node-cli-command-resolution.d.ts +5 -0
- package/dist/src/shared/node-cli-command-resolution.js +28 -81
- package/dist/src/shared/node-cli-command-resolution.js.map +1 -1
- package/locales/en.json +202 -202
- package/locales/zh-CN.json +202 -202
- package/package.json +100 -100
- package/scripts/installation.cjs +239 -239
- package/scripts/postinstall.cjs +22 -22
- package/scripts/service.mjs +253 -253
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
export type HydrationResult
|
|
3
|
-
ok: true;
|
|
4
|
-
segments: string[];
|
|
5
|
-
failureReason: 'none';
|
|
6
|
-
proxyEnv?: Record<string, string>;
|
|
7
|
-
} | {
|
|
8
|
-
ok: false;
|
|
9
|
-
segments: [];
|
|
10
|
-
failureReason: Exclude<ShellHydrationFailureReason, 'none'>;
|
|
11
|
-
};
|
|
1
|
+
import { type HydrationResult } from '../../platform/index.js';
|
|
2
|
+
export type { HydrationResult, ShellHydrationFailureReason } from '../../platform/index.js';
|
|
12
3
|
/** @internal - tests need a clean hydration cache between cases. */
|
|
13
4
|
export declare function _resetHydrateShellPathCache(): void;
|
|
14
5
|
/** Use configured terminal proxies when launchd/Electron did not inherit them. Never log these values. */
|
|
15
6
|
export declare function mergeShellProxyEnvironment(hydration: HydrationResult, baseline?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
16
7
|
type HydrateOptions = {
|
|
17
8
|
force?: boolean;
|
|
18
|
-
/** Override for tests — defaults to
|
|
19
|
-
|
|
20
|
-
/** Override for tests — defaults to `pickShell()`. */
|
|
21
|
-
shellOverride?: string | null;
|
|
9
|
+
/** Override for tests — defaults to the platform's terminal environment reader. */
|
|
10
|
+
reader?: () => Promise<HydrationResult>;
|
|
22
11
|
};
|
|
23
12
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* when the user asks to re-probe (e.g. after installing a new CLI).
|
|
13
|
+
* Read the PATH a new terminal would have and cache the promise for the
|
|
14
|
+
* lifetime of the process. Pass `force: true` when the user asks to re-probe
|
|
15
|
+
* (e.g. after installing a new CLI).
|
|
28
16
|
*/
|
|
29
17
|
export declare function hydrateShellPath(options?: HydrateOptions): Promise<HydrationResult>;
|
|
30
18
|
/**
|
|
31
|
-
* Promote
|
|
32
|
-
* preserving
|
|
19
|
+
* Promote terminal PATH segments to the front of process.env.PATH,
|
|
20
|
+
* preserving their order and avoiding duplicates. Returns the segments that
|
|
33
21
|
* were newly added so callers can log/telemetry on nontrivial hydrations.
|
|
34
22
|
*/
|
|
35
23
|
export declare function mergePathSegments(segments: string[]): string[];
|
|
36
|
-
export {};
|
|
@@ -1,69 +1,17 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
1
|
import { delimiter } from 'node:path';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// it would export. This matches the behavior of every popular Electron app that
|
|
12
|
-
// handles this problem (Hyper, VS Code, Cursor, etc. via shell-env/fix-path) —
|
|
13
|
-
// we implement it inline to avoid adding a dependency.
|
|
14
|
-
const DELIMITER = '__ORCA_SHELL_PATH__';
|
|
15
|
-
const PROXY_DELIMITER = '__ECHO_SHELL_PROXY__';
|
|
16
|
-
const PROXY_KEYS = ['http_proxy', 'https_proxy', 'all_proxy', 'no_proxy', 'HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY'];
|
|
17
|
-
const SPAWN_TIMEOUT_MS = 5000;
|
|
18
|
-
// ANSI escape sequences can leak into the captured output when the user's rc
|
|
19
|
-
// files print banners or set colored prompts. Strip them before parsing.
|
|
20
|
-
const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]/g; // eslint-disable-line no-control-regex
|
|
2
|
+
import { currentPlatform, PROXY_KEYS } from '../../platform/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* PATH and proxies of the user's terminal, read once per process. A service
|
|
5
|
+
* or GUI-launched agent often inherits a smaller environment than the
|
|
6
|
+
* terminal where the user installed their CLIs. How the terminal
|
|
7
|
+
* environment is read is OS-specific (login shell on macOS / Linux, the
|
|
8
|
+
* registry on Windows; see src/platform); caching and merging are shared.
|
|
9
|
+
*/
|
|
21
10
|
let cached = null;
|
|
22
11
|
/** @internal - tests need a clean hydration cache between cases. */
|
|
23
12
|
export function _resetHydrateShellPathCache() {
|
|
24
13
|
cached = null;
|
|
25
14
|
}
|
|
26
|
-
function pickShell() {
|
|
27
|
-
if (process.platform === 'win32') {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const shell = process.env.SHELL;
|
|
31
|
-
if (shell && shell.length > 0) {
|
|
32
|
-
return shell;
|
|
33
|
-
}
|
|
34
|
-
return process.platform === 'darwin' ? '/bin/zsh' : '/bin/bash';
|
|
35
|
-
}
|
|
36
|
-
function parseCapturedPath(stdout) {
|
|
37
|
-
const cleaned = stdout.replace(ANSI_RE, '');
|
|
38
|
-
const first = cleaned.indexOf(DELIMITER);
|
|
39
|
-
if (first < 0) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
const second = cleaned.indexOf(DELIMITER, first + DELIMITER.length);
|
|
43
|
-
if (second < 0) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const value = cleaned.slice(first + DELIMITER.length, second).trim();
|
|
47
|
-
if (!value) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
// Why: Set preserves insertion order, and PATH resolution is first-match-wins,
|
|
51
|
-
// so de-duping this way keeps the user's rc-file ordering intact.
|
|
52
|
-
return [
|
|
53
|
-
...new Set(value
|
|
54
|
-
.split(delimiter)
|
|
55
|
-
.map((s) => s.trim())
|
|
56
|
-
.filter(Boolean))
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
function parseCapturedProxy(stdout) {
|
|
60
|
-
const start = stdout.indexOf(PROXY_DELIMITER);
|
|
61
|
-
const end = stdout.indexOf(PROXY_DELIMITER, start + PROXY_DELIMITER.length);
|
|
62
|
-
if (start < 0 || end < 0)
|
|
63
|
-
return {};
|
|
64
|
-
const values = stdout.slice(start + PROXY_DELIMITER.length, end).split('\0');
|
|
65
|
-
return Object.fromEntries(PROXY_KEYS.flatMap((key, index) => values[index] ? [[key, values[index]]] : []));
|
|
66
|
-
}
|
|
67
15
|
/** Use configured terminal proxies when launchd/Electron did not inherit them. Never log these values. */
|
|
68
16
|
export function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
69
17
|
const environment = { ...baseline };
|
|
@@ -79,103 +27,25 @@ export function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
|
79
27
|
}
|
|
80
28
|
return environment;
|
|
81
29
|
}
|
|
82
|
-
function spawnShellAndReadPath(shell) {
|
|
83
|
-
return new Promise((resolve) => {
|
|
84
|
-
// Why: printing $PATH between delimiters is resilient to rc-file banners,
|
|
85
|
-
// MOTDs, and `echo` invocations that shells like fish print unprompted.
|
|
86
|
-
// `-ilc` runs the shell as a login+interactive so both .profile/.zprofile
|
|
87
|
-
// and .bashrc/.zshrc are sourced — matches what `which` in Terminal sees.
|
|
88
|
-
const proxyValues = PROXY_KEYS.map(key => `"\${${key}-}"`).join(' ');
|
|
89
|
-
const command = `printf '%s' '${DELIMITER}'; printf '%s' "$PATH"; printf '%s' '${DELIMITER}'; printf '%s' '${PROXY_DELIMITER}'; printf '%s\\0' ${proxyValues}; printf '%s' '${PROXY_DELIMITER}'`;
|
|
90
|
-
let finished = false;
|
|
91
|
-
let stdout = '';
|
|
92
|
-
let timer = null;
|
|
93
|
-
const child = spawn(shell, ['-ilc', command], {
|
|
94
|
-
// Why: inherit current env so the shell sees the same baseline, then let
|
|
95
|
-
// it layer its own rc files on top. Do NOT forward stdio — some shells
|
|
96
|
-
// (oh-my-zsh setups, powerlevel10k) print a lot to stderr on startup,
|
|
97
|
-
// and we don't want that in Orca's console.
|
|
98
|
-
env: process.env,
|
|
99
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
100
|
-
detached: false
|
|
101
|
-
});
|
|
102
|
-
const cleanup = () => {
|
|
103
|
-
if (timer) {
|
|
104
|
-
clearTimeout(timer);
|
|
105
|
-
timer = null;
|
|
106
|
-
}
|
|
107
|
-
child.stdout.off('data', onStdoutData);
|
|
108
|
-
child.off('error', onError);
|
|
109
|
-
child.off('close', onClose);
|
|
110
|
-
};
|
|
111
|
-
const finish = (result) => {
|
|
112
|
-
if (finished) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
finished = true;
|
|
116
|
-
cleanup();
|
|
117
|
-
resolve(result);
|
|
118
|
-
};
|
|
119
|
-
timer = setTimeout(() => {
|
|
120
|
-
// Why: slow rc files (corporate env setup, nvm eager init) can exceed
|
|
121
|
-
// our budget. Kill the shell and fall back to process.env rather than
|
|
122
|
-
// blocking the Agents pane indefinitely.
|
|
123
|
-
try {
|
|
124
|
-
child.kill('SIGKILL');
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
// ignore
|
|
128
|
-
}
|
|
129
|
-
finish({ segments: [], ok: false, failureReason: 'timeout' });
|
|
130
|
-
}, SPAWN_TIMEOUT_MS);
|
|
131
|
-
const onStdoutData = (chunk) => {
|
|
132
|
-
stdout += chunk.toString('utf8');
|
|
133
|
-
};
|
|
134
|
-
const onError = () => {
|
|
135
|
-
finish({ segments: [], ok: false, failureReason: 'spawn_error' });
|
|
136
|
-
};
|
|
137
|
-
const onClose = () => {
|
|
138
|
-
const segments = parseCapturedPath(stdout);
|
|
139
|
-
if (segments.length === 0) {
|
|
140
|
-
finish({ segments: [], ok: false, failureReason: 'empty_path' });
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
finish({ segments, proxyEnv: parseCapturedProxy(stdout), ok: true, failureReason: 'none' });
|
|
144
|
-
};
|
|
145
|
-
child.stdout.on('data', onStdoutData);
|
|
146
|
-
child.on('error', onError);
|
|
147
|
-
child.on('close', onClose);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
30
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* when the user asks to re-probe (e.g. after installing a new CLI).
|
|
31
|
+
* Read the PATH a new terminal would have and cache the promise for the
|
|
32
|
+
* lifetime of the process. Pass `force: true` when the user asks to re-probe
|
|
33
|
+
* (e.g. after installing a new CLI).
|
|
155
34
|
*/
|
|
156
35
|
export function hydrateShellPath(options = {}) {
|
|
157
|
-
if (cached && !options.force)
|
|
36
|
+
if (cached && !options.force)
|
|
158
37
|
return cached;
|
|
159
|
-
|
|
160
|
-
const shell = options.shellOverride !== undefined ? options.shellOverride : pickShell();
|
|
161
|
-
if (!shell) {
|
|
162
|
-
// Windows uses cmd/PowerShell rather than a POSIX login shell — the
|
|
163
|
-
// `patchPackagedProcessPath` static list is sufficient there.
|
|
164
|
-
cached = Promise.resolve({ segments: [], ok: false, failureReason: 'no_shell' });
|
|
165
|
-
return cached;
|
|
166
|
-
}
|
|
167
|
-
cached = (options.spawner ?? spawnShellAndReadPath)(shell);
|
|
38
|
+
cached = (options.reader ?? (() => currentPlatform.readLoginEnvironment()))();
|
|
168
39
|
return cached;
|
|
169
40
|
}
|
|
170
41
|
/**
|
|
171
|
-
* Promote
|
|
172
|
-
* preserving
|
|
42
|
+
* Promote terminal PATH segments to the front of process.env.PATH,
|
|
43
|
+
* preserving their order and avoiding duplicates. Returns the segments that
|
|
173
44
|
* were newly added so callers can log/telemetry on nontrivial hydrations.
|
|
174
45
|
*/
|
|
175
46
|
export function mergePathSegments(segments) {
|
|
176
|
-
if (segments.length === 0)
|
|
47
|
+
if (segments.length === 0)
|
|
177
48
|
return [];
|
|
178
|
-
}
|
|
179
49
|
const current = process.env.PATH ?? '';
|
|
180
50
|
const currentSegments = current.split(delimiter).filter(Boolean);
|
|
181
51
|
const shellSegments = [...new Set(segments)];
|
|
@@ -187,9 +57,8 @@ export function mergePathSegments(segments) {
|
|
|
187
57
|
...currentSegments.filter((segment) => !shellSegmentSet.has(segment))
|
|
188
58
|
];
|
|
189
59
|
const next = merged.join(delimiter);
|
|
190
|
-
if (next === current)
|
|
60
|
+
if (next === current)
|
|
191
61
|
return [];
|
|
192
|
-
}
|
|
193
62
|
// Why: shell-provided entries must win over hardcoded packaged-app fallbacks.
|
|
194
63
|
// A seeded fallback can point at a stale CLI while the user's shell resolves
|
|
195
64
|
// a healthy one from the same directory list in a different order.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate-shell-path.js","sourceRoot":"","sources":["../../../../src/runtime/cli/hydrate-shell-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hydrate-shell-path.js","sourceRoot":"","sources":["../../../../src/runtime/cli/hydrate-shell-path.ts"],"names":[],"mapp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CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACpC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAA;IACtC,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAChE,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC5C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAA;IAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IACvE,MAAM,MAAM,GAAG;QACb,GAAG,aAAa;QAChB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KACtE,CAAA;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnC,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,CAAA;IAC/B,8EAA8E;IAC9E,6EAA6E;IAC7E,mEAAmE;IACnE,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;IACvB,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds a CLI the way a terminal would: PATH first, then the install folders
|
|
3
|
+
* of version managers and package managers. What differs per OS (file
|
|
4
|
+
* names, executability, folder layout) comes from the platform adapter.
|
|
5
|
+
*/
|
|
1
6
|
type ResolveCommandOptions = {
|
|
2
7
|
pathEnv?: string | null;
|
|
3
8
|
platform?: NodeJS.Platform;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!pathEnv) {
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { platformFor } from '../platform/index.js';
|
|
5
|
+
import { sharedUserBinDirectoriesHead, sharedUserBinDirectoriesTail } from '../platform/common.js';
|
|
6
|
+
function adapterOf(options) {
|
|
7
|
+
return platformFor(options.platform ?? process.platform);
|
|
8
|
+
}
|
|
9
|
+
function splitPath(platform, pathEnv) {
|
|
10
|
+
if (!pathEnv)
|
|
12
11
|
return [];
|
|
13
|
-
}
|
|
14
12
|
return pathEnv
|
|
15
|
-
.split(
|
|
13
|
+
.split(platform.id === 'win32' ? ';' : ':')
|
|
16
14
|
.map((entry) => entry.trim())
|
|
17
15
|
.filter(Boolean);
|
|
18
16
|
}
|
|
@@ -29,9 +27,8 @@ function compareVersionDesc(left, right) {
|
|
|
29
27
|
const length = Math.max(leftParts.length, rightParts.length);
|
|
30
28
|
for (let index = 0; index < length; index += 1) {
|
|
31
29
|
const delta = (rightParts[index] ?? 0) - (leftParts[index] ?? 0);
|
|
32
|
-
if (delta !== 0)
|
|
30
|
+
if (delta !== 0)
|
|
33
31
|
return delta;
|
|
34
|
-
}
|
|
35
32
|
}
|
|
36
33
|
return right.localeCompare(left);
|
|
37
34
|
}
|
|
@@ -39,68 +36,23 @@ function findFirstExecutable(platform, directories, executableNames) {
|
|
|
39
36
|
for (const directory of directories) {
|
|
40
37
|
for (const executableName of executableNames) {
|
|
41
38
|
const candidate = join(directory, executableName);
|
|
42
|
-
if (
|
|
39
|
+
if (platform.isRunnableFile(candidate))
|
|
43
40
|
return candidate;
|
|
44
|
-
}
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
return null;
|
|
48
44
|
}
|
|
49
|
-
function isRunnableCommand(platform, candidate) {
|
|
50
|
-
try {
|
|
51
|
-
const stats = statSync(candidate);
|
|
52
|
-
if (!stats.isFile()) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
if (platform === 'win32') {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
// Why: GUI fallback probing should skip placeholders/directories so spawn
|
|
59
|
-
// can continue to a runnable CLI instead of failing later with EACCES/EISDIR.
|
|
60
|
-
accessSync(candidate, constants.X_OK);
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
45
|
function getBaseVersionManagerDirectories(platform, homePath) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Why: mise (formerly rtx) exposes managed tool binaries via a shims
|
|
73
|
-
// directory, similar to asdf.
|
|
74
|
-
join(homePath, '.local', 'share', 'mise', 'shims')
|
|
46
|
+
return [
|
|
47
|
+
...sharedUserBinDirectoriesHead(homePath),
|
|
48
|
+
...platform.userBinDirectories(homePath),
|
|
49
|
+
...sharedUserBinDirectoriesTail(homePath)
|
|
75
50
|
];
|
|
76
|
-
if (platform === 'win32') {
|
|
77
|
-
// Why: Anthropic's native Windows installer places claude.exe here, and
|
|
78
|
-
// GUI-launched Orca may not inherit the user's PATH entry for it.
|
|
79
|
-
directories.push(join(homePath, '.local', 'bin'));
|
|
80
|
-
directories.push(join(homePath, 'AppData', 'Roaming', 'npm'));
|
|
81
|
-
directories.push(join(homePath, 'AppData', 'Local', 'pnpm'));
|
|
82
|
-
directories.push(join(homePath, 'AppData', 'Local', 'Yarn', 'bin'));
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
directories.push(join(homePath, '.local', 'bin'));
|
|
86
|
-
// Why: pnpm uses platform-specific global bin directories that differ from
|
|
87
|
-
// npm's ~/.local/bin.
|
|
88
|
-
if (platform === 'darwin') {
|
|
89
|
-
directories.push(join(homePath, 'Library', 'pnpm'));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
directories.push(join(homePath, '.local', 'share', 'pnpm'));
|
|
93
|
-
}
|
|
94
|
-
directories.push(join(homePath, '.yarn', 'bin'));
|
|
95
|
-
}
|
|
96
|
-
directories.push(join(homePath, '.bun', 'bin'));
|
|
97
|
-
return directories;
|
|
98
51
|
}
|
|
99
52
|
function getNvmVersionDirectories(homePath) {
|
|
100
53
|
const nvmVersionsDir = join(homePath, '.nvm', 'versions', 'node');
|
|
101
|
-
if (!existsSync(nvmVersionsDir))
|
|
54
|
+
if (!existsSync(nvmVersionsDir))
|
|
102
55
|
return [];
|
|
103
|
-
}
|
|
104
56
|
return readdirSync(nvmVersionsDir, { withFileTypes: true })
|
|
105
57
|
.filter((entry) => entry.isDirectory())
|
|
106
58
|
.map((entry) => entry.name)
|
|
@@ -110,27 +62,23 @@ function getNvmVersionDirectories(homePath) {
|
|
|
110
62
|
function getVersionManagerDirectories(platform, homePath, executableNames) {
|
|
111
63
|
const directories = getBaseVersionManagerDirectories(platform, homePath);
|
|
112
64
|
const firstNvmMatch = findFirstExecutable(platform, getNvmVersionDirectories(homePath), executableNames);
|
|
113
|
-
if (firstNvmMatch)
|
|
65
|
+
if (firstNvmMatch)
|
|
114
66
|
directories.unshift(dirname(firstNvmMatch));
|
|
115
|
-
}
|
|
116
67
|
return directories;
|
|
117
68
|
}
|
|
118
69
|
export function resolveCliCommand(commandName, options = {}) {
|
|
119
70
|
return findCliCommand(commandName, options) ?? commandName;
|
|
120
71
|
}
|
|
121
72
|
export function findCliCommand(commandName, options = {}) {
|
|
122
|
-
const platform = options
|
|
123
|
-
const executableNames =
|
|
73
|
+
const platform = adapterOf(options);
|
|
74
|
+
const executableNames = platform.executableNames(commandName);
|
|
124
75
|
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
125
|
-
const pathCandidate = findFirstExecutable(platform, splitPath(pathEnv), executableNames);
|
|
126
|
-
if (pathCandidate)
|
|
76
|
+
const pathCandidate = findFirstExecutable(platform, splitPath(platform, pathEnv), executableNames);
|
|
77
|
+
if (pathCandidate)
|
|
127
78
|
return pathCandidate;
|
|
128
|
-
}
|
|
129
79
|
const homePath = options.homePath ?? homedir();
|
|
130
80
|
const nvmCandidate = findFirstExecutable(platform, getNvmVersionDirectories(homePath), executableNames);
|
|
131
|
-
|
|
132
|
-
findFirstExecutable(platform, getBaseVersionManagerDirectories(platform, homePath), executableNames);
|
|
133
|
-
return versionManagerCandidate;
|
|
81
|
+
return nvmCandidate ?? findFirstExecutable(platform, getBaseVersionManagerDirectories(platform, homePath), executableNames);
|
|
134
82
|
}
|
|
135
83
|
/** Resolve without conflating a launch fallback with an installed executable. */
|
|
136
84
|
export function resolveCliCommandDetailed(commandName, options = {}) {
|
|
@@ -140,9 +88,9 @@ export function resolveCliCommandDetailed(commandName, options = {}) {
|
|
|
140
88
|
: { command: commandName, found: false };
|
|
141
89
|
}
|
|
142
90
|
export function resolveCliCommands(commandNames, options = {}) {
|
|
143
|
-
const platform = options
|
|
91
|
+
const platform = adapterOf(options);
|
|
144
92
|
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
145
|
-
const pathDirectories = splitPath(pathEnv);
|
|
93
|
+
const pathDirectories = splitPath(platform, pathEnv);
|
|
146
94
|
const homePath = options.homePath ?? homedir();
|
|
147
95
|
const installDirectories = [
|
|
148
96
|
...getNvmVersionDirectories(homePath),
|
|
@@ -150,7 +98,7 @@ export function resolveCliCommands(commandNames, options = {}) {
|
|
|
150
98
|
];
|
|
151
99
|
const resolved = new Map();
|
|
152
100
|
for (const commandName of new Set(commandNames)) {
|
|
153
|
-
const executableNames =
|
|
101
|
+
const executableNames = platform.executableNames(commandName);
|
|
154
102
|
const pathCandidate = findFirstExecutable(platform, pathDirectories, executableNames);
|
|
155
103
|
const installCandidate = pathCandidate ?? findFirstExecutable(platform, installDirectories, executableNames);
|
|
156
104
|
resolved.set(commandName, installCandidate ?? commandName);
|
|
@@ -165,9 +113,8 @@ export function resolveClaudeCommand(options = {}) {
|
|
|
165
113
|
}
|
|
166
114
|
// Why: Node-script CLIs need their version-manager sibling `node` on PATH.
|
|
167
115
|
export function getVersionManagerBinPaths(options = {}) {
|
|
168
|
-
const platform = options
|
|
116
|
+
const platform = adapterOf(options);
|
|
169
117
|
const homePath = options.homePath ?? homedir();
|
|
170
|
-
|
|
171
|
-
return getVersionManagerDirectories(platform, homePath, nodeNames);
|
|
118
|
+
return getVersionManagerDirectories(platform, homePath, platform.executableNames('node'));
|
|
172
119
|
}
|
|
173
120
|
//# sourceMappingURL=node-cli-command-resolution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-cli-command-resolution.js","sourceRoot":"","sources":["../../../src/shared/node-cli-command-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"node-cli-command-resolution.js","sourceRoot":"","sources":["../../../src/shared/node-cli-command-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAwB,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAA;AAoBlG,SAAS,SAAS,CAAC,OAA8B;IAC/C,OAAO,WAAW,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC1D,CAAC;AAED,SAAS,SAA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