@namzu/sdk 68.0.0 → 69.0.0
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/CHANGELOG.md +45 -0
- package/dist/bridge/acp/server.d.ts +12 -0
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +20 -0
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/compaction/context-window.d.ts +8 -0
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +14 -0
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/compaction/loaded-skills.d.ts +10 -0
- package/dist/compaction/loaded-skills.d.ts.map +1 -1
- package/dist/compaction/loaded-skills.js +45 -1
- package/dist/compaction/loaded-skills.js.map +1 -1
- package/dist/compaction/manager.d.ts +8 -0
- package/dist/compaction/manager.d.ts.map +1 -1
- package/dist/compaction/manager.js +31 -0
- package/dist/compaction/manager.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +7 -1
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.js +2 -2
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/restore.d.ts +8 -0
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +65 -0
- package/dist/compaction/restore.js.map +1 -1
- package/dist/compaction/salience/working-set.d.ts.map +1 -1
- package/dist/compaction/salience/working-set.js +2 -2
- package/dist/compaction/salience/working-set.js.map +1 -1
- package/dist/compaction/tool-result-editing.d.ts +6 -0
- package/dist/compaction/tool-result-editing.d.ts.map +1 -1
- package/dist/compaction/tool-result-editing.js +7 -1
- package/dist/compaction/tool-result-editing.js.map +1 -1
- package/dist/compaction/types.d.ts +2 -0
- package/dist/compaction/types.d.ts.map +1 -1
- package/dist/compaction/wire.d.ts.map +1 -1
- package/dist/compaction/wire.js +4 -0
- package/dist/compaction/wire.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +23 -1
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/network/join.d.ts +10 -0
- package/dist/network/join.d.ts.map +1 -1
- package/dist/network/join.js +15 -0
- package/dist/network/join.js.map +1 -1
- package/dist/network/service.d.ts.map +1 -1
- package/dist/network/service.js +166 -12
- package/dist/network/service.js.map +1 -1
- package/dist/network/store.d.ts +23 -1
- package/dist/network/store.d.ts.map +1 -1
- package/dist/network/store.js +23 -1
- package/dist/network/store.js.map +1 -1
- package/dist/network/transport.d.ts +1 -1
- package/dist/network/transport.js +1 -1
- package/dist/network/wire.d.ts +12 -0
- package/dist/network/wire.d.ts.map +1 -1
- package/dist/network/wire.js +12 -1
- package/dist/network/wire.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +7 -2
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +5 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +5 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/instrumentation.d.ts.map +1 -1
- package/dist/provider/instrumentation.js +10 -0
- package/dist/provider/instrumentation.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +1 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +5 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +1 -1
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +2 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +4 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +1 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/tool/presentation.d.ts +8 -1
- package/dist/registry/tool/presentation.d.ts.map +1 -1
- package/dist/registry/tool/presentation.js +14 -5
- package/dist/registry/tool/presentation.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +2 -1
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +19 -3
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/failure.d.ts +12 -0
- package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/failure.js +46 -0
- package/dist/runtime/query/auto-review/failure.js.map +1 -0
- package/dist/runtime/query/auto-review/index.d.ts +1 -0
- package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/index.js +1 -0
- package/dist/runtime/query/auto-review/index.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +6 -6
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +8 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +2 -0
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +21 -3
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
- package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.js +4 -0
- package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts +5 -1
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +13 -3
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +13 -2
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +13 -2
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +36 -1
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +3 -1
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +20 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +5 -2
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.js +2 -2
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +4 -0
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +106 -5
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +2 -1
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit-apply.d.ts +1 -0
- package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
- package/dist/tools/builtins/edit-apply.js +108 -21
- package/dist/tools/builtins/edit-apply.js.map +1 -1
- package/dist/tools/builtins/edit-match.d.ts +37 -0
- package/dist/tools/builtins/edit-match.d.ts.map +1 -1
- package/dist/tools/builtins/edit-match.js +193 -0
- package/dist/tools/builtins/edit-match.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +14 -7
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/exit-semantics.d.ts +8 -0
- package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
- package/dist/tools/builtins/exit-semantics.js +19 -0
- package/dist/tools/builtins/exit-semantics.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +2 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/present-file.d.ts +24 -0
- package/dist/tools/builtins/present-file.d.ts.map +1 -0
- package/dist/tools/builtins/present-file.js +116 -0
- package/dist/tools/builtins/present-file.js.map +1 -0
- package/dist/tools/builtins/read-file.js +1 -1
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts +12 -1
- package/dist/tools/builtins/read-render.d.ts.map +1 -1
- package/dist/tools/builtins/read-render.js +16 -3
- package/dist/tools/builtins/read-render.js.map +1 -1
- package/dist/tools/builtins/search-tools.d.ts +10 -0
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +36 -2
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +5 -0
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +13 -2
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/task/create.js +2 -2
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/task/update.js +1 -1
- package/dist/tools/task/update.js.map +1 -1
- package/dist/types/provider/chat.d.ts +8 -0
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +10 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/model.d.ts +6 -0
- package/dist/types/provider/model.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +2 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/tool/presentation.d.ts +11 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/node-on-path.d.ts +27 -0
- package/dist/utils/node-on-path.d.ts.map +1 -0
- package/dist/utils/node-on-path.js +70 -0
- package/dist/utils/node-on-path.js.map +1 -0
- package/package.json +1 -1
- package/src/bridge/acp/server.ts +25 -0
- package/src/compaction/context-window.ts +18 -0
- package/src/compaction/loaded-skills.ts +42 -1
- package/src/compaction/manager.ts +28 -0
- package/src/compaction/manual.ts +9 -1
- package/src/compaction/model-summary.ts +2 -2
- package/src/compaction/restore.ts +69 -0
- package/src/compaction/salience/working-set.ts +6 -2
- package/src/compaction/tool-result-editing.ts +8 -1
- package/src/compaction/types.ts +2 -0
- package/src/compaction/wire.ts +4 -0
- package/src/manager/session/turn-recorder.ts +24 -1
- package/src/network/join.ts +17 -0
- package/src/network/service.ts +185 -12
- package/src/network/store.ts +28 -1
- package/src/network/transport.ts +1 -1
- package/src/network/wire.ts +13 -1
- package/src/prompt/coding-agent-doctrine.ts +7 -2
- package/src/provider/fallback.ts +6 -0
- package/src/provider/idle-timeout.ts +6 -0
- package/src/provider/instrumentation.ts +12 -0
- package/src/provider/model-window-suffix.ts +1 -0
- package/src/provider/retry.ts +6 -0
- package/src/public-runtime.ts +1 -0
- package/src/public-tools.ts +9 -0
- package/src/public-types.ts +1 -0
- package/src/registry/tool/presentation.ts +14 -4
- package/src/runtime/jobs/registry.ts +2 -1
- package/src/runtime/query/auto-review/classifier.ts +19 -3
- package/src/runtime/query/auto-review/failure.ts +50 -0
- package/src/runtime/query/auto-review/index.ts +1 -0
- package/src/runtime/query/file-evidence-replay.ts +6 -5
- package/src/runtime/query/index.ts +19 -0
- package/src/runtime/query/iteration/index.ts +2 -0
- package/src/runtime/query/iteration/phases/compaction.ts +25 -2
- package/src/runtime/query/iteration/phases/context.ts +4 -0
- package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
- package/src/runtime/query/iteration/step-shaping.ts +4 -0
- package/src/runtime/query/prepare-turn.ts +20 -2
- package/src/runtime/query/review-policy.ts +24 -4
- package/src/runtime/query/turn/outcome-ledger.ts +45 -1
- package/src/sandbox/provider/local.ts +3 -1
- package/src/tools/admit-facts.ts +18 -0
- package/src/tools/builtins/bash.ts +5 -2
- package/src/tools/builtins/browser.ts +2 -2
- package/src/tools/builtins/computer-use.ts +123 -4
- package/src/tools/builtins/content-fingerprint.ts +2 -1
- package/src/tools/builtins/edit-apply.ts +124 -24
- package/src/tools/builtins/edit-match.ts +200 -0
- package/src/tools/builtins/edit.ts +16 -7
- package/src/tools/builtins/exit-semantics.ts +23 -0
- package/src/tools/builtins/index.ts +2 -0
- package/src/tools/builtins/present-file.ts +127 -0
- package/src/tools/builtins/read-file.ts +1 -1
- package/src/tools/builtins/read-render.ts +18 -3
- package/src/tools/builtins/search-tools.ts +36 -2
- package/src/tools/builtins/wait-for-job.ts +5 -0
- package/src/tools/builtins/web.ts +15 -2
- package/src/tools/task/create.ts +2 -2
- package/src/tools/task/update.ts +1 -1
- package/src/types/provider/chat.ts +9 -0
- package/src/types/provider/interface.ts +11 -0
- package/src/types/provider/model.ts +6 -0
- package/src/types/provider/stream.ts +2 -0
- package/src/types/tool/presentation.ts +12 -0
- package/src/utils/node-on-path.ts +81 -0
|
@@ -74,6 +74,15 @@ export interface ChatCompletionParams {
|
|
|
74
74
|
|
|
75
75
|
cacheControl?: CacheControl
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* A stable name for the conversation this request belongs to. A driver
|
|
79
|
+
* whose wire has a cache-routing field (a prompt cache key, a session
|
|
80
|
+
* header) sends it so every request of one conversation lands on the same
|
|
81
|
+
* cache; a driver without one ignores it. Never a secret and never
|
|
82
|
+
* derived from the content of the request.
|
|
83
|
+
*/
|
|
84
|
+
cacheKey?: string
|
|
85
|
+
|
|
77
86
|
topP?: number
|
|
78
87
|
topK?: number
|
|
79
88
|
frequencyPenalty?: number
|
|
@@ -280,6 +280,17 @@ export interface LLMProvider {
|
|
|
280
280
|
*/
|
|
281
281
|
resolveContextWindow?(model: string, signal?: AbortSignal): Promise<number | undefined>
|
|
282
282
|
|
|
283
|
+
/**
|
|
284
|
+
* The token count at which the provider's own service says a conversation on `model`
|
|
285
|
+
* should be compacted, when it states one (the same listing that states the window).
|
|
286
|
+
*
|
|
287
|
+
* The compaction trigger uses it as `min(limit, 90% of the window)` when the host set no
|
|
288
|
+
* threshold of its own; without it Namzu's derived trigger applies. Same contract as
|
|
289
|
+
* `resolveContextWindow`: asked once per turn, bounded, and a rejection or `undefined`
|
|
290
|
+
* means "no answer", never a failed turn.
|
|
291
|
+
*/
|
|
292
|
+
resolveAutoCompactLimit?(model: string, signal?: AbortSignal): Promise<number | undefined>
|
|
293
|
+
|
|
283
294
|
/**
|
|
284
295
|
* The model to re-run a refused request on, when this provider has one.
|
|
285
296
|
*
|
|
@@ -37,6 +37,12 @@ export interface ModelInfo {
|
|
|
37
37
|
* back to its own table instead of trusting a zero.
|
|
38
38
|
*/
|
|
39
39
|
contextWindow?: number
|
|
40
|
+
/**
|
|
41
|
+
* Tokens at which the provider's service says a conversation should be compacted, already
|
|
42
|
+
* held to 90% of `contextWindow` when both are known. Absent means the service stated none
|
|
43
|
+
* and Namzu's own trigger rule applies.
|
|
44
|
+
*/
|
|
45
|
+
autoCompactTokenLimit?: number
|
|
40
46
|
/** Same, and absent for the same reason. */
|
|
41
47
|
maxOutputTokens?: number
|
|
42
48
|
/**
|
|
@@ -26,6 +26,8 @@ export interface StreamChunk {
|
|
|
26
26
|
url?: string
|
|
27
27
|
/** How many sources the provider reported for this call. Absent means unknown, not zero. */
|
|
28
28
|
results?: number
|
|
29
|
+
/** How many queries one hosted call ran, when it ran several. Absent means one or unknown. */
|
|
30
|
+
searches?: number
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
content?: string
|
|
@@ -219,6 +219,18 @@ export type ToolFacts =
|
|
|
219
219
|
readonly hunks?: readonly ToolDiffHunk[]
|
|
220
220
|
readonly hunksTruncated?: true
|
|
221
221
|
}
|
|
222
|
+
| {
|
|
223
|
+
readonly kind: 'shared'
|
|
224
|
+
/** Files handed to the person, as absolute paths. */
|
|
225
|
+
readonly files: readonly {
|
|
226
|
+
readonly path: string
|
|
227
|
+
/** Where the path led when the call checked it, links followed; a host compares it again at use. */
|
|
228
|
+
readonly real?: string
|
|
229
|
+
readonly bytes?: number
|
|
230
|
+
}[]
|
|
231
|
+
/** One line saying what they are. */
|
|
232
|
+
readonly caption?: string
|
|
233
|
+
}
|
|
222
234
|
| {
|
|
223
235
|
readonly kind: 'failure'
|
|
224
236
|
readonly reason: ToolFailureReason
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { constants, accessSync, realpathSync, statSync } from 'node:fs'
|
|
2
|
+
import { posix, win32 } from 'node:path'
|
|
3
|
+
import { readEnvironmentEntry, setEnvironmentEntry } from './process-environment.js'
|
|
4
|
+
|
|
5
|
+
export interface NodeOnPathOptions {
|
|
6
|
+
/** The running binary. Defaults to `process.execPath`. */
|
|
7
|
+
readonly execPath?: string
|
|
8
|
+
readonly platform?: NodeJS.Platform
|
|
9
|
+
/** Whether a file is an executable `node`. Defaults to a filesystem check. */
|
|
10
|
+
readonly isExecutable?: (file: string) => boolean
|
|
11
|
+
/** Resolve links. Defaults to `fs.realpathSync`. */
|
|
12
|
+
readonly realpath?: (file: string) => string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function defaultIsExecutable(file: string, platform: NodeJS.Platform): boolean {
|
|
16
|
+
try {
|
|
17
|
+
if (!statSync(file).isFile()) return false
|
|
18
|
+
if (platform !== 'win32') accessSync(file, constants.X_OK)
|
|
19
|
+
return true
|
|
20
|
+
} catch {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The directory that would be appended to PATH so `node` resolves, or
|
|
27
|
+
* undefined when `node` already resolves (or cannot be offered).
|
|
28
|
+
*/
|
|
29
|
+
export function nodeDirectoryToAppend(
|
|
30
|
+
pathValue: string,
|
|
31
|
+
options: NodeOnPathOptions = {},
|
|
32
|
+
): string | undefined {
|
|
33
|
+
const platform = options.platform ?? process.platform
|
|
34
|
+
const path = platform === 'win32' ? win32 : posix
|
|
35
|
+
const execPath = options.execPath ?? process.execPath
|
|
36
|
+
const binary = path.basename(execPath).toLowerCase()
|
|
37
|
+
const wanted = platform === 'win32' ? ['node.exe', 'node.cmd'] : ['node']
|
|
38
|
+
if (!wanted.includes(binary)) return undefined
|
|
39
|
+
|
|
40
|
+
const entries = pathValue.split(path.delimiter)
|
|
41
|
+
const isExecutable =
|
|
42
|
+
options.isExecutable ?? ((file: string) => defaultIsExecutable(file, platform))
|
|
43
|
+
for (const dir of entries) {
|
|
44
|
+
if (dir === '') continue
|
|
45
|
+
for (const file of wanted) if (isExecutable(path.join(dir, file))) return undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let target: string
|
|
49
|
+
try {
|
|
50
|
+
target = path.dirname((options.realpath ?? realpathSync)(execPath))
|
|
51
|
+
} catch {
|
|
52
|
+
target = path.dirname(execPath)
|
|
53
|
+
}
|
|
54
|
+
return entries.includes(target) ? undefined : target
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Make `node` resolvable in a shell command's environment.
|
|
59
|
+
*
|
|
60
|
+
* The runtime is often started by an absolute path whose directory is not on
|
|
61
|
+
* the user's PATH, so a command like `node --test` then fails with exit 127
|
|
62
|
+
* while the runtime itself is running on that very binary. When no `node`
|
|
63
|
+
* resolves on PATH, the directory of the running binary is appended to the END
|
|
64
|
+
* of PATH: a `node` the user has installed always wins. The environment is
|
|
65
|
+
* returned unchanged when `node` already resolves, when PATH is absent, or when
|
|
66
|
+
* the running binary is not a plain node binary (an embedded runtime).
|
|
67
|
+
*/
|
|
68
|
+
export function withNodeOnPath(
|
|
69
|
+
env: Record<string, string>,
|
|
70
|
+
options: NodeOnPathOptions = {},
|
|
71
|
+
): Record<string, string> {
|
|
72
|
+
const platform = options.platform ?? process.platform
|
|
73
|
+
const entry = readEnvironmentEntry(env, 'PATH', platform)
|
|
74
|
+
if (!entry) return env
|
|
75
|
+
const [name, value] = entry
|
|
76
|
+
const target = nodeDirectoryToAppend(value, options)
|
|
77
|
+
if (target === undefined) return env
|
|
78
|
+
const separator = platform === 'win32' ? ';' : ':'
|
|
79
|
+
setEnvironmentEntry(env, name, value === '' ? target : `${value}${separator}${target}`, platform)
|
|
80
|
+
return env
|
|
81
|
+
}
|