@songtonyli/dsh-cli 0.1.80 → 0.1.82
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/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +94 -1589
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +1 -7
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +1 -3
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +1 -3
- package/node_modules/@aws-sdk/core/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-login/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-process/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +4 -4
- package/node_modules/@aws-sdk/eventstream-handler-node/package.json +2 -2
- package/node_modules/@aws-sdk/middleware-eventstream/package.json +2 -2
- package/node_modules/@aws-sdk/middleware-websocket/package.json +3 -3
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
- package/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +37 -19
- package/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +37 -19
- package/node_modules/@aws-sdk/token-providers/package.json +4 -4
- package/node_modules/@deepseek-ai/dsh-client-modules/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-subprocess-local/README.i18n.yaml +14 -14
- package/node_modules/@deepseek-ai/dsh-subprocess-local/README.md +7 -5
- package/node_modules/@deepseek-ai/dsh-subprocess-local/README.zh.md +7 -5
- package/node_modules/@deepseek-ai/dsh-subprocess-local/lib/index.js +15 -3
- package/node_modules/@deepseek-ai/dsh-subprocess-local/lib/runner-launch-f9xQyTek.js +1669 -0
- package/node_modules/@deepseek-ai/dsh-subprocess-local/lib/runner.js +1 -1
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +19 -16
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +30 -13
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +30 -13
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +615 -245
- package/node_modules/execa/lib/convert/duplex.js +8 -4
- package/node_modules/execa/lib/convert/readable.js +3 -8
- package/node_modules/execa/lib/convert/writable.js +6 -5
- package/node_modules/execa/lib/io/input-sync.js +2 -1
- package/node_modules/execa/lib/io/max-buffer.js +2 -1
- package/node_modules/execa/lib/io/output-sync.js +2 -1
- package/node_modules/execa/lib/methods/create.js +7 -0
- package/node_modules/execa/lib/methods/node.js +1 -1
- package/node_modules/execa/lib/methods/script.js +3 -3
- package/node_modules/execa/lib/resolve/all-async.js +2 -1
- package/node_modules/execa/lib/resolve/wait-subprocess.js +6 -0
- package/node_modules/execa/lib/stdio/handle-async.js +3 -2
- package/node_modules/execa/lib/stdio/handle.js +8 -3
- package/node_modules/execa/lib/transform/generator.js +7 -0
- package/node_modules/execa/lib/transform/run-sync.js +17 -5
- package/node_modules/execa/package.json +1 -1
- package/package.json +16 -16
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonSettings.js +0 -1
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v1/JsonCodec.js +0 -20
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v1/JsonSettings.js +0 -1
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v1/JsonShapeDeserializer.js +0 -160
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v1/JsonShapeSerializer.js +0 -193
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.js +0 -103
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v2/JsonCodec2.js +0 -20
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.js +0 -200
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js +0 -519
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/detectBufferParsing.js +0 -18
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReplacer.js +0 -46
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReviver.js +0 -121
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/needsReviver.js +0 -41
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/parseJsonBody.js +0 -89
|
@@ -33,26 +33,26 @@
|
|
|
33
33
|
en: cc8e9b90f1d2e3de
|
|
34
34
|
zh: f85fdcd1c783bbfc
|
|
35
35
|
/deepseek-ai-dsh-subprocess-local/use-this-package/shutdown-behavior:
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
36
|
+
en: 3c0ebaf847b18a81
|
|
37
|
+
zh: 28d7fbc122580191
|
|
38
38
|
/deepseek-ai-dsh-subprocess-local/use-this-package/what-can-go-wrong:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: 12509f3a9fa0b392
|
|
40
|
+
zh: 4b0e4ba6a17e2ce9
|
|
41
41
|
/deepseek-ai-dsh-subprocess-local/understand-the-implementation:
|
|
42
42
|
en: 531a48766c666ea0
|
|
43
43
|
zh: b40df533a2fd7244
|
|
44
44
|
/deepseek-ai-dsh-subprocess-local/understand-the-implementation/design-concept:
|
|
45
|
-
en:
|
|
46
|
-
zh:
|
|
45
|
+
en: b64b0ceeed541759
|
|
46
|
+
zh: 0a34d4263094ee9d
|
|
47
47
|
/deepseek-ai-dsh-subprocess-local/understand-the-implementation/source-map:
|
|
48
|
-
en:
|
|
49
|
-
zh:
|
|
48
|
+
en: f30506b10206c83f
|
|
49
|
+
zh: 756151215f01fda7
|
|
50
50
|
/deepseek-ai-dsh-subprocess-local/understand-the-implementation/main-flow:
|
|
51
|
-
en:
|
|
52
|
-
zh:
|
|
51
|
+
en: bfb725fe6feb3672
|
|
52
|
+
zh: 8c7ea4d9c8513156
|
|
53
53
|
/deepseek-ai-dsh-subprocess-local/understand-the-implementation/safety-invariants:
|
|
54
|
-
en:
|
|
55
|
-
zh:
|
|
54
|
+
en: 1bb4d64659f7b517
|
|
55
|
+
zh: c71617efd201cc25
|
|
56
56
|
/deepseek-ai-dsh-subprocess-local/further-exploration:
|
|
57
57
|
en: b15c86ee670899d9
|
|
58
58
|
zh: a18f23e9f3e36727
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
en: e290ccc9b3c92c08
|
|
64
64
|
zh: d75d48f485447a74
|
|
65
65
|
/deepseek-ai-dsh-subprocess-local/known-limitations-and-deferred-work:
|
|
66
|
-
en:
|
|
67
|
-
zh:
|
|
66
|
+
en: 5241a474d5da8ef1
|
|
67
|
+
zh: da7188c3dc24dcf6
|
|
68
68
|
/deepseek-ai-dsh-subprocess-local/known-limitations-and-deferred-work/dev-note:
|
|
69
69
|
en: e67f633dc6fe7773
|
|
70
70
|
zh: 3bb0c20c93f16f98
|
|
@@ -63,13 +63,13 @@ Opted-in root exit does not terminate surviving descendants. A confirmed empty L
|
|
|
63
63
|
|
|
64
64
|
### Shutdown behavior
|
|
65
65
|
|
|
66
|
-
Normal disposal terminates every running managed range and terminal session and awaits quiescence. During a JavaScript-observable host exit — direct `process.exit()`, default uncaught exceptions, default unhandled rejections — synchronous finalization asks a Linux scope to kill its members, kills each Windows runner so its sole Job handle closes, and
|
|
66
|
+
Normal disposal terminates every running managed range and terminal session and awaits quiescence. During a JavaScript-observable host exit — direct `process.exit()`, default uncaught exceptions, default unhandled rejections — synchronous finalization asks a Linux scope to kill its members, kills each Windows runner so its sole Job handle closes, and for fallbacks kills the process group and the descendants one synchronous process-table read finds, runs `taskkill`, or signals captured identities. It creates no promises or timers and does not claim quiescence. The same exit removes the private per-process spill directory when it holds no completed spill file; completed spill files remain as full-output recovery artifacts until an external cleanup. Unhandled `SIGTERM`/`SIGINT`/`SIGHUP`, `SIGKILL`, fatal OOM, native crashes, and power loss need an external supervisor.
|
|
67
67
|
|
|
68
68
|
Linux ordinary and terminal cancellation preserves the observed termination signal even before the bootstrap consumes its launch request. An unconsumed request still reports startup failure when no matching termination was requested; a recorded pre-exec error always takes precedence. `waitForExit()` independently proves the scope empty, including a scope the manager leaves active with no processes after a payload dies before it enters that scope's cgroup. State queries interrupted by a termination signal are repeated before deciding whether cleanup succeeded. After termination, a consumed launch request and zero scope processes prove quiescence even before the direct-process exit notification. If the final scope signal fails, an accepted direct `SIGKILL` or verified direct-process absence permits one wait for the pending direct-process settlement before rechecking an active range not yet proven empty. This wait is independent of output draining and whole-range settlement. The fresh scope observation must prove the range empty; surviving processes or an unknown process count retain the signal failure.
|
|
69
69
|
|
|
70
70
|
### What can go wrong
|
|
71
71
|
|
|
72
|
-
An executable that cannot be resolved fails loud with a stable error. `done` rejects when spawn or provider failure prevents a direct outcome, and that rejection does not prove whether target execution began. `waitForExit()` rejects if the selected owner can no longer prove its range empty, and cleanup still attempts termination. A read past the retained tail is `lossy` and points at the spill file when one exists. A fallback process
|
|
72
|
+
An executable that cannot be resolved fails loud with a stable error. `done` rejects when spawn or provider failure prevents a direct outcome, and that rejection does not prove whether target execution began. `waitForExit()` rejects if the selected owner can no longer prove its range empty, and cleanup still attempts termination. A read past the retained tail is `lossy` and points at the spill file when one exists. A fallback ordinary command can miss a descendant reparented away from its process tree before termination reads the process table, and an observed terminal session can miss a descendant that escapes before observation — see the limitations below.
|
|
73
73
|
|
|
74
74
|
-----
|
|
75
75
|
|
|
@@ -83,7 +83,7 @@ This section explains the design decisions behind the provider and points at the
|
|
|
83
83
|
|
|
84
84
|
### Design concept
|
|
85
85
|
|
|
86
|
-
Each spawn selects one owner for both signalling and quiescence. Supported Linux ordinary and terminal launches use transient user-systemd scopes, while supported Windows ordinary launches use a helper-owned kill-on-close Job. macOS, unavailable user-systemd, and unavailable Windows native support use the
|
|
86
|
+
Each spawn selects one owner for both signalling and quiescence. Supported Linux ordinary and terminal launches use transient user-systemd scopes, while supported Windows ordinary launches use a helper-owned kill-on-close Job. macOS, unavailable user-systemd, and unavailable Windows native support use the detached process group plus the leader's descendants recorded when termination starts, `taskkill`, or terminal-session observations, with one warning. The provider never replays a command through fallback after a native path may have started it.
|
|
87
87
|
|
|
88
88
|
### Source map
|
|
89
89
|
|
|
@@ -91,6 +91,7 @@ Each spawn selects one owner for both signalling and quiescence. Supported Linux
|
|
|
91
91
|
|---|---|
|
|
92
92
|
| [`src/index.ts`](src/index.ts) | Service wiring: live-handle sets, disposal, host-exit finalization, executable lookup |
|
|
93
93
|
| [`src/spawn.ts`](src/spawn.ts) | Shared process plumbing: direct outcomes, tail-keep collection, spill files, and fallback spawning |
|
|
94
|
+
| [`src/descendant-sweep.ts`](src/descendant-sweep.ts) | POSIX fallback descendant tracking: process-table reads at termination and identity-fenced signals |
|
|
94
95
|
| [`src/managed-owner.ts`](src/managed-owner.ts) | Private signal-and-wait owner used by each ordinary handle |
|
|
95
96
|
| [`src/linux-scope.ts`](src/linux-scope.ts) | Linux user-systemd capability checks, scope launch, signalling, and quiescence |
|
|
96
97
|
| [`src/linux-execve.ts`](src/linux-execve.ts) | Linux libc image replacement and inherited-standard-descriptor preservation |
|
|
@@ -104,11 +105,11 @@ Each spawn selects one owner for both signalling and quiescence. Supported Linux
|
|
|
104
105
|
|
|
105
106
|
### Main flow
|
|
106
107
|
|
|
107
|
-
A spawn synchronously validates the final argv, cwd, and environment, selects containment before the user command can run, and returns a handle while target identity remains private. Linux ordinary and terminal launches use a private one-shot request whose scoped bootstrap restores the target cwd and environment, resolves the executable, clears close-on-exec on fd 0 through fd 2 and optional control fd 7, and enters libc `execve()` with the original argv. Windows ordinary launches isolate runner fd 0 through fd 2, reserve fd 3 for IPC, and carry target stdio on fd 4 through fd 6 plus fd 7 when control is requested; the runner resolves those CRT descriptors to OS handles, creates the target suspended, assigns it to the Job, resumes it, and closes its standard-stream carriers and optional fd-7 carrier. `done` settles the direct command after its stdio barrier, while `waitForExit()` separately waits for the selected scope, Job, process group, or observed session to become empty.
|
|
108
|
+
A spawn synchronously validates the final argv, cwd, and environment, selects containment before the user command can run, and returns a handle while target identity remains private. Linux ordinary and terminal launches use a private one-shot request whose scoped bootstrap restores the target cwd and environment, resolves the executable, clears close-on-exec on fd 0 through fd 2 and optional control fd 7, and enters libc `execve()` with the original argv. Windows ordinary launches isolate runner fd 0 through fd 2, reserve fd 3 for IPC, and carry target stdio on fd 4 through fd 6 plus fd 7 when control is requested; the runner resolves those CRT descriptors to OS handles, creates the target suspended, assigns it to the Job, resumes it, and closes its standard-stream carriers and optional fd-7 carrier. `done` settles the direct command after its stdio barrier, while `waitForExit()` separately waits for the selected scope, Job, process group with its recorded descendants, or observed session to become empty.
|
|
108
109
|
|
|
109
110
|
### Safety invariants
|
|
110
111
|
|
|
111
|
-
Spill files are opened `0600` with `O_EXCL` and random names under a `0700` per-process directory, defeating symlink planting in shared temp dirs; a failed open, append, or final close withholds the spill path and never interrupts collection, because collection runs inside the stream's `'data'` listener where a thrown error would kill the host process. Fallback process identities carry start times, so cleanup
|
|
112
|
+
Spill files are opened `0600` with `O_EXCL` and random names under a `0700` per-process directory, defeating symlink planting in shared temp dirs; a failed open, append, or final close withholds the spill path and never interrupts collection, because collection runs inside the stream's `'data'` listener where a thrown error would kill the host process. Fallback process identities carry start times, and every signal to one follows a process-table read in the same synchronous pass, so cleanup does not follow PID reuse; the ordinary-command sweep adopts the leader's tree only while Node has not reaped the leader, so a recycled leader pid never contributes another process's children. A selected native failure is reported instead of replaying argv through fallback, and a range is removed from the live set only after cleanup completes or the failure remains observable. Host-exit finalization creates no promises or timers, preserves the host exit code and diagnostic, contains each target's failure, and does not claim quiescence.
|
|
112
113
|
|
|
113
114
|
</details>
|
|
114
115
|
|
|
@@ -152,6 +153,7 @@ These limits define when the provider is a poor fit or needs special operational
|
|
|
152
153
|
- **Windows terminal signalling is console-wide** — SIGINT is delivered as a `\x03` Ctrl-C input write that the console host turns into a console-wide CTRL_C event (on Windows that host is node-pty's bundled OpenConsole); SIGTSTP and SIGHUP are rejected as unavailable; a `taskkill` without `/F` does not terminate console processes, so the teardown TERM tier is a grace wait before the `/F` escalation. Windows readiness has no exact stdin-wait tier: the prompt-marker fast path compares the shell pid as the pseudo foreground group, and silence/timing tiers cover the rest.
|
|
153
154
|
- **Windows terminal allocation requires node-pty's bundled console host assets** — every Windows terminal is spawned with `useConptyDll: true`, so allocation resolves `conpty/conpty.dll` and `OpenConsole.exe` relative to node-pty's own addon; an asset that is missing or unpacked wrong makes `spawnTerminal` throw instead of falling back to the operating system console host. node-pty marks the option experimental, so a node-pty upgrade can change this behaviour. See the [bundled console host note](../../../.agents/notes/implemented/bug-fix/2026-09-28-pty-bundled-console-host.md).
|
|
154
155
|
- **Fallback terminal ownership remains observational** — on macOS or Linux without usable user-systemd, a child that reparents before any foreground-inspection snapshot or leaves the owned terminal session can escape the process-table scan. The local provider does not add a continuous process-table monitor; supported Linux native mode instead retains these descendants through scope membership.
|
|
156
|
+
- **Fallback ordinary ownership reads the process table only to terminate** — on macOS or Linux without usable user-systemd, termination reads the process table when it starts and again at the `SIGKILL` escalation, signals the process group and every running descendant of the leader that the read finds, and `waitForExit()` waits for both; a descendant still in the group receives each signal twice. A descendant reparented before the read, such as a double-forked daemon whose parent is now pid 1, is not found. On macOS each read forks `/bin/ps`, and host-exit finalization reads once per live command; while only recorded descendants remain, `waitForExit()` reads at most once every 50 milliseconds. A command that exits without being terminated is never inspected, so daemons it left outside its process group keep running. When the table cannot be read, the provider warns once and signals the process group only.
|
|
155
157
|
- **In-process cleanup requires a JavaScript-observable exit** — direct `process.exit()`, default uncaught exceptions, and default unhandled rejections emit Node's synchronous `exit` event. The default OS disposition for an unhandled `SIGTERM`, `SIGINT`, or `SIGHUP` bypasses that event; an application covers those signals only by installing a handler that performs normal disposal or calls `process.exit()`. `SIGKILL`, fatal OOM, `process.abort()`, native crashes, power loss, and any failure that cannot run JavaScript require an external supervisor, container init, or equivalent OS owner.
|
|
156
158
|
- **The credential scrub is a name heuristic** — `*KEY*`/`*PASSWORD*`/`*SECRET*`/`*TOKEN*` only; differently named secrets (for example `*PASSPHRASE*`) pass through, and a whitelist for over-scrubbed variables is noted future work.
|
|
157
159
|
- **Completed spill files are not deleted** — bounded full-output recovery files accumulate under the OS tmpdir until something external cleans them; the private per-process spill directory is removed at a JavaScript-observable exit only when it holds no completed spill file.
|
|
@@ -63,13 +63,13 @@ Windows 普通子进程通过 `windowsHide` 启动私有 Job runner,并为原
|
|
|
63
63
|
|
|
64
64
|
### 关闭行为
|
|
65
65
|
|
|
66
|
-
正常 dispose 会终止每个仍在运行的受管范围与终端会话并等待其完全停稳。在 JavaScript 可观察的宿主退出期间——直接 `process.exit()`、默认未捕获异常、默认未处理 rejection——同步最终清理会请求 Linux scope 终止其成员,同步终止每个 Windows runner 以关闭其唯一 Job handle
|
|
66
|
+
正常 dispose 会终止每个仍在运行的受管范围与终端会话并等待其完全停稳。在 JavaScript 可观察的宿主退出期间——直接 `process.exit()`、默认未捕获异常、默认未处理 rejection——同步最终清理会请求 Linux scope 终止其成员,同步终止每个 Windows runner 以关闭其唯一 Job handle;对 fallback,则终止进程组及一次同步进程表读取找到的后代、运行 `taskkill`,或向已捕获身份发送信号。它不创建 Promise 或定时器,也不声称已经完全停稳。同一退出阶段会删除未持有任何已完成 spill 文件的每进程私有 spill 目录;已完成的 spill 文件作为完整输出恢复产物保留,直到外部机制清理。未处理的 `SIGTERM`/`SIGINT`/`SIGHUP`、`SIGKILL`、fatal OOM、native crash 与断电需要外部 supervisor。
|
|
67
67
|
|
|
68
68
|
Linux 普通进程和终端进程即使在 bootstrap 消费启动请求前被取消,也会保留实际观察到的终止信号。如果没有请求对应的终止信号,未消费的请求仍会报启动失败;已记录的 pre-exec 错误始终优先。`waitForExit()` 独立证明 scope 已为空,其中也包括 payload 在进入该 scope 的 cgroup 前就被杀死、manager 因此让它保持 active 却没有任何进程的 scope。状态查询期间若发出终止信号,会重新查询后再判定清理是否成功。请求终止后,启动请求已消费且 scope 进程数为零即可证明完全停稳,无需等待直接进程的退出通知。如果最终 scope 信号发送失败,直接进程接受 `SIGKILL` 或被独立确认已不存在,owner 才可以等待一次尚未送达的直接进程停稳通知,再重新查询尚未证明为空的 active 范围。此等待独立于输出排空和整个范围的停稳。新取得的 scope 状态必须证明范围已为空;仍有进程存活或进程数未知时,仍报告信号失败。
|
|
69
69
|
|
|
70
70
|
### 可能出错的地方
|
|
71
71
|
|
|
72
|
-
无法解析的可执行文件会明确报出稳定错误。当 spawn 或提供方故障使 direct outcome 无法产生时,`done` 会 reject;该 rejection 不能证明 target 是否已经开始执行。若所选 owner 无法再证明其范围为空,`waitForExit()` 会 reject,清理仍会尝试终止。越过保留尾部的读取是 `lossy` 的,并在 spill 文件存在时指向它。fallback
|
|
72
|
+
无法解析的可执行文件会明确报出稳定错误。当 spawn 或提供方故障使 direct outcome 无法产生时,`done` 会 reject;该 rejection 不能证明 target 是否已经开始执行。若所选 owner 无法再证明其范围为空,`waitForExit()` 会 reject,清理仍会尝试终止。越过保留尾部的读取是 `lossy` 的,并在 spill 文件存在时指向它。fallback 普通命令可能遗漏在终止读取进程表之前就已重新设定父进程、离开其进程树的后代;已观察终端 session 可能遗漏在观察前逃逸的后代——见下文限制。
|
|
73
73
|
|
|
74
74
|
-----
|
|
75
75
|
|
|
@@ -83,7 +83,7 @@ Linux 普通进程和终端进程即使在 bootstrap 消费启动请求前被取
|
|
|
83
83
|
|
|
84
84
|
### 设计理念
|
|
85
85
|
|
|
86
|
-
每次 spawn 都为信号发送与完全停稳选择同一个 owner。受支持的 Linux 普通命令与终端启动使用临时 user-systemd scope,受支持的 Windows 普通命令使用由 helper 持有、关闭时终止成员的 Job。macOS、不可用的 user-systemd,以及不可用的 Windows
|
|
86
|
+
每次 spawn 都为信号发送与完全停稳选择同一个 owner。受支持的 Linux 普通命令与终端启动使用临时 user-systemd scope,受支持的 Windows 普通命令使用由 helper 持有、关闭时终止成员的 Job。macOS、不可用的 user-systemd,以及不可用的 Windows 原生支持使用 detached 进程组加上终止开始时记录的 leader 后代、`taskkill` 或终端会话观察,并只告警一次。native 路径可能已经启动命令后,本提供方绝不会通过 fallback 重放该命令。
|
|
87
87
|
|
|
88
88
|
### 源码地图
|
|
89
89
|
|
|
@@ -91,6 +91,7 @@ Linux 普通进程和终端进程即使在 bootstrap 消费启动请求前被取
|
|
|
91
91
|
|---|---|
|
|
92
92
|
| [`src/index.ts`](src/index.ts) | 服务接线:存活句柄集合、dispose、宿主退出最终清理、可执行文件查找 |
|
|
93
93
|
| [`src/spawn.ts`](src/spawn.ts) | 共享进程管道:直接结果、保尾收集、spill 文件与 fallback spawn |
|
|
94
|
+
| [`src/descendant-sweep.ts`](src/descendant-sweep.ts) | POSIX fallback 后代跟踪:终止时读取进程表,并按身份校验发送信号 |
|
|
94
95
|
| [`src/managed-owner.ts`](src/managed-owner.ts) | 每个普通句柄使用的私有信号与等待 owner |
|
|
95
96
|
| [`src/linux-scope.ts`](src/linux-scope.ts) | Linux user-systemd 能力检查、scope 启动、信号发送与完全停稳 |
|
|
96
97
|
| [`src/linux-execve.ts`](src/linux-execve.ts) | Linux libc 进程映像替换与继承标准文件描述符保留 |
|
|
@@ -104,11 +105,11 @@ Linux 普通进程和终端进程即使在 bootstrap 消费启动请求前被取
|
|
|
104
105
|
|
|
105
106
|
### 主流程
|
|
106
107
|
|
|
107
|
-
一次 spawn 会同步校验最终 argv、cwd 与环境,在用户命令可能运行前选择 containment,并在目标身份保持私有的情况下返回句柄。Linux 普通命令与终端启动使用私有的一次性请求;scope 内的 bootstrap 会恢复目标 cwd 与环境、解析可执行文件、清除 fd 0 至 fd 2 及可选控制 fd 7 的 close-on-exec 标记,再以原始 argv 进入 libc `execve()`。Windows 普通命令会隔离 runner 的 fd 0 至 fd 2、把 fd 3 留给 IPC,并用 fd 4 至 fd 6 承载 target stdio,在请求控制时还使用 fd 7;runner 把这些 CRT 描述符解析成 OS handle,以 suspended 状态创建 target,将其加入 Job、恢复运行,再关闭自身的标准流载体及可选 fd-7 载体。`done` 会在 direct command 及其 stdio 屏障结算后完成,`waitForExit()` 则分别等待所选 scope、Job
|
|
108
|
+
一次 spawn 会同步校验最终 argv、cwd 与环境,在用户命令可能运行前选择 containment,并在目标身份保持私有的情况下返回句柄。Linux 普通命令与终端启动使用私有的一次性请求;scope 内的 bootstrap 会恢复目标 cwd 与环境、解析可执行文件、清除 fd 0 至 fd 2 及可选控制 fd 7 的 close-on-exec 标记,再以原始 argv 进入 libc `execve()`。Windows 普通命令会隔离 runner 的 fd 0 至 fd 2、把 fd 3 留给 IPC,并用 fd 4 至 fd 6 承载 target stdio,在请求控制时还使用 fd 7;runner 把这些 CRT 描述符解析成 OS handle,以 suspended 状态创建 target,将其加入 Job、恢复运行,再关闭自身的标准流载体及可选 fd-7 载体。`done` 会在 direct command 及其 stdio 屏障结算后完成,`waitForExit()` 则分别等待所选 scope、Job、进程组及其已记录后代,或已观察会话变空。
|
|
108
109
|
|
|
109
110
|
### 安全不变式
|
|
110
111
|
|
|
111
|
-
spill 文件以 `0600` 权限、`O_EXCL` 与随机名称在 `0700` 每进程目录下创建,可抵御共享临时目录中的符号链接植入;打开、追加或最终关闭失败时不公布 spill 路径,且绝不中断收集,因为收集运行在流的 `'data'` 监听器内,抛出的错误会杀死宿主进程。fallback
|
|
112
|
+
spill 文件以 `0600` 权限、`O_EXCL` 与随机名称在 `0700` 每进程目录下创建,可抵御共享临时目录中的符号链接植入;打开、追加或最终关闭失败时不公布 spill 路径,且绝不中断收集,因为收集运行在流的 `'data'` 监听器内,抛出的错误会杀死宿主进程。fallback 进程身份携带启动时间,而且每次向某个身份发送信号之前,都会在同一个同步过程中读取进程表,因此清理不会跟随 PID 复用;普通命令的后代清扫只在 Node 尚未回收 leader 时采纳 leader 的进程树,因此被复用的 leader pid 绝不会把其他进程的子进程带进来。选定的 native 路径失败时会报告错误,而不会通过 fallback 重放 argv;受管范围只有在清理完成后才从存活集合移除,否则失败仍保持可观察。宿主退出最终清理不创建 Promise 或定时器,保留宿主退出码与诊断,分别包含每个目标的失败,也不会声称已经完全停稳。
|
|
112
113
|
|
|
113
114
|
</details>
|
|
114
115
|
|
|
@@ -152,6 +153,7 @@ spill 文件以 `0600` 权限、`O_EXCL` 与随机名称在 `0700` 每进程目
|
|
|
152
153
|
- **Windows 终端信号是控制台级的**——SIGINT 以 `\x03` Ctrl-C 输入写入投递,由控制台宿主(Windows 上为 node-pty 自带的 OpenConsole)转为控制台级 CTRL_C 事件;SIGTSTP 与 SIGHUP 被拒绝(不可用);不带 `/F` 的 `taskkill` 无法终止控制台进程,因此拆卸的 TERM 档是 `/F` 升级前的宽限等待。Windows 就绪没有精确的 stdin-wait 档:prompt-marker 快路径把 shell pid 作为伪前台进程组比较,其余由静默与计时档覆盖。
|
|
153
154
|
- **Windows 终端分配依赖 node-pty 自带的控制台宿主资产**——每个 Windows 终端都以 `useConptyDll: true` 启动,分配时按 node-pty 自身 addon 的相对位置解析 `conpty/conpty.dll` 与 `OpenConsole.exe`;资产缺失或解包错误会让 `spawnTerminal` 抛错,而不是回退到操作系统控制台宿主。node-pty 把该选项标为实验性,升级 node-pty 可能改变这一行为。见[自带控制台宿主说明](../../../.agents/notes/implemented/bug-fix/2026-09-28-pty-bundled-console-host.zh.md)。
|
|
154
155
|
- **fallback 终端 ownership 仍依赖观察**——在 macOS 或缺少可用 user-systemd 的 Linux 上,子进程如果在任何前台检查快照之前重新设定父进程,或离开自有终端会话,就可能逃出进程表扫描。本地提供方不会新增持续进程表监视器;受支持的 Linux native 模式改由 scope membership 持有这些后代。
|
|
156
|
+
- **fallback 普通命令 ownership 只为终止读取进程表**——在 macOS 或缺少可用 user-systemd 的 Linux 上,终止会在开始时读取进程表,并在 `SIGKILL` 升级时再读取一次,向进程组以及该次读取找到的每个仍在运行的 leader 后代发送信号,`waitForExit()` 会等待两者;仍在进程组中的后代会收到每个信号两次。在读取之前已重新设定父进程的后代(例如父进程已变为 pid 1 的双重 fork 守护进程)不会被找到。在 macOS 上每次读取都会 fork `/bin/ps`,宿主退出最终清理会为每个存活命令读取一次;只剩已记录后代时,`waitForExit()` 最多每 50 毫秒读取一次。未被终止而自行退出的命令从不被检查,因此它留在进程组之外的守护进程会继续运行。进程表无法读取时,提供方只告警一次,并只向进程组发送信号。
|
|
155
157
|
- **进程内清理要求退出阶段仍能执行 JavaScript**——直接 `process.exit()`、默认未捕获异常和默认未处理 rejection 会发出 Node 同步 `exit` 事件。未安装 handler 时,`SIGTERM`、`SIGINT` 或 `SIGHUP` 的默认 OS 处置不会发出该事件;应用只有安装执行正常 dispose 或调用 `process.exit()` 的 handler 才能覆盖这些信号。`SIGKILL`、fatal OOM、`process.abort()`、native crash、断电,以及任何无法运行 JavaScript 的故障,都需要外部 supervisor、容器 init 或等价的 OS owner 负责。
|
|
156
158
|
- **凭据清除依赖名称启发式规则**——只匹配 `*KEY*`/`*PASSWORD*`/`*SECRET*`/`*TOKEN*`;名称不同的 secret(例如 `*PASSPHRASE*`)会继续传递,对误删变量引入白名单属于已记录的后续工作。
|
|
157
159
|
- **不会删除已完成的 spill 文件**——有界的完整输出恢复文件会在 OS tmpdir 下累积,直到外部机制进行清理;每进程私有 spill 目录仅在未持有任何已完成 spill 文件时于 JavaScript 可观察的退出阶段删除。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as bindManagedProcess, D as
|
|
1
|
+
import { C as bindManagedProcess, D as SWEEP_FAILURE_IMPACT, E as validateSubprocessSpec, O as createProcessInspector, S as loadLinuxExecve, T as spawnSubprocess, _ as parseWindowsRunnerResult, c as runnerStdio, d as cleanupLinuxLaunchFiles, k as controlPipe, l as spawnRunnerInvocation, m as deserializeRunnerError, n as WINDOWS_RUNNER_SELECTION, o as runnerEnvironment, p as createLinuxLaunchFiles, s as runnerInvocationAvailable, u as targetEnvironment, w as childEnv, y as readLinuxStartupError } from "./runner-launch-f9xQyTek.js";
|
|
2
2
|
import { logSpillFailure, prepareManagedProcessBinding } from "./output.js";
|
|
3
3
|
import { closeSync, constants, existsSync, mkdtempSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { access, stat } from "node:fs/promises";
|
|
@@ -1458,6 +1458,8 @@ var LocalSubprocessRuntime = class extends SubprocessRuntime {
|
|
|
1458
1458
|
internals = {};
|
|
1459
1459
|
/** Provider-lifetime latch suppressing repeated weaker-containment warnings. */
|
|
1460
1460
|
fallbackWarningIssued = false;
|
|
1461
|
+
/** Provider-lifetime latch suppressing repeated descendant-sweep failure warnings. */
|
|
1462
|
+
sweepFailureReported = false;
|
|
1461
1463
|
/**
|
|
1462
1464
|
* Linux native containment decisions. Each probe is a spawnSync that blocks the event loop and forks the
|
|
1463
1465
|
* host, so the selector reruns it only after an event invalidates the previous verdict.
|
|
@@ -1487,6 +1489,15 @@ var LocalSubprocessRuntime = class extends SubprocessRuntime {
|
|
|
1487
1489
|
}
|
|
1488
1490
|
/** Spill failures reach the plugin logger; the log line is the only trace of why a result has no spill path. */
|
|
1489
1491
|
reportSpillFailure = logSpillFailure(this.ctx.logger, "subprocess-local");
|
|
1492
|
+
/**
|
|
1493
|
+
* Descendant-sweep failures reach the plugin logger once per provider; every
|
|
1494
|
+
* affected fallback handle keeps terminating its process group only.
|
|
1495
|
+
*/
|
|
1496
|
+
reportSweepFailure = (error) => {
|
|
1497
|
+
if (this.sweepFailureReported) return;
|
|
1498
|
+
this.sweepFailureReported = true;
|
|
1499
|
+
this.ctx.logger.warn(`subprocess-local ${SWEEP_FAILURE_IMPACT}`, error);
|
|
1500
|
+
};
|
|
1490
1501
|
terminateForHostExit() {
|
|
1491
1502
|
for (const handle of this.live) try {
|
|
1492
1503
|
handle.terminateForHostExit();
|
|
@@ -1551,7 +1562,8 @@ var LocalSubprocessRuntime = class extends SubprocessRuntime {
|
|
|
1551
1562
|
let handle;
|
|
1552
1563
|
const internals = {
|
|
1553
1564
|
...this.internals,
|
|
1554
|
-
onSpillFailure: this.reportSpillFailure
|
|
1565
|
+
onSpillFailure: this.reportSpillFailure,
|
|
1566
|
+
onSweepFailure: this.reportSweepFailure
|
|
1555
1567
|
};
|
|
1556
1568
|
if (containmentMode === "fallback") handle = spawnSubprocess(spec, internals);
|
|
1557
1569
|
else {
|
|
@@ -1603,7 +1615,7 @@ var LocalSubprocessRuntime = class extends SubprocessRuntime {
|
|
|
1603
1615
|
if (this.fallbackWarningIssued) return;
|
|
1604
1616
|
this.fallbackWarningIssued = true;
|
|
1605
1617
|
const reason = selectedReason ?? (platform === "darwin" ? "macOS has no supported persistent process-range owner" : platform === "win32" ? kind === "terminal" ? "Windows ConPTY remains outside Job containment" : "the Win32 Job runner is unavailable" : `platform ${platform} has no native managed range`);
|
|
1606
|
-
this.ctx.logger.warn(`subprocess-local is using weaker process-tree containment because ${reason}; descendants
|
|
1618
|
+
this.ctx.logger.warn(`subprocess-local is using weaker process-tree containment because ${reason}; termination reaches the process group and the descendants observed in the process tree, but a descendant that leaves both before it is observed, such as a double-forked daemon, is not guaranteed to terminate or delay waitForExit()`);
|
|
1607
1619
|
}
|
|
1608
1620
|
/** @inheritdoc */
|
|
1609
1621
|
async terminalEnvironment(signal) {
|