@songtonyli/dsh-cli 0.1.66 → 0.1.68
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/@babel/runtime/helpers/esm/interopRequireWildcard.js +16 -19
- package/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +5 -5
- package/node_modules/@babel/runtime/helpers/interopRequireWildcard.js +16 -19
- package/node_modules/@babel/runtime/helpers/toPrimitive.js +5 -5
- package/node_modules/@babel/runtime/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +12 -11
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +6 -6
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +3 -3
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +3 -3
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +26 -34
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +118 -57
- package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +3 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +3 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +955 -567
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ workspace and no build step. Native packages that ship one build per platform
|
|
|
26
26
|
ripgrep, the PTY backend's addons, sharp, koffi, and the Landlock launcher — are
|
|
27
27
|
ordinary optional dependencies, so npm resolves the right one for your machine.
|
|
28
28
|
|
|
29
|
-
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.
|
|
29
|
+
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.68; `dsh --version`
|
|
30
30
|
also reports the harness build the package was assembled from.
|
|
31
31
|
|
|
32
32
|
## License
|
package/bin/dsh.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const argv = process.argv.slice(2)
|
|
|
18
18
|
// version this package publishes. Reporting only one of the two would make an
|
|
19
19
|
// ordinary `npm install @songtonyli/dsh-cli@x` look like it installed something else.
|
|
20
20
|
if (argv.length === 1 && (argv[0] === '--version' || argv[0] === '-V')) {
|
|
21
|
-
console.log('@songtonyli/dsh-cli 0.1.
|
|
21
|
+
console.log('@songtonyli/dsh-cli 0.1.68 (deepseek-harness 0.2.1-alpha.1)')
|
|
22
22
|
process.exit(0)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
var cache;
|
|
2
2
|
function _interopRequireWildcard(e, t) {
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]);
|
|
19
|
-
return f;
|
|
20
|
-
})(e, t);
|
|
3
|
+
if (!t && e && e.__esModule) return e;
|
|
4
|
+
var r,
|
|
5
|
+
c,
|
|
6
|
+
a = Object.defineProperty,
|
|
7
|
+
n = {
|
|
8
|
+
__proto__: null,
|
|
9
|
+
"default": e
|
|
10
|
+
};
|
|
11
|
+
if (Object(e) !== e) return n;
|
|
12
|
+
if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) {
|
|
13
|
+
if (cache.has(e)) return cache.get(e);
|
|
14
|
+
cache.set(e, n);
|
|
15
|
+
}
|
|
16
|
+
for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]);
|
|
17
|
+
return n;
|
|
21
18
|
}
|
|
22
19
|
export { _interopRequireWildcard as default };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _typeof from "./typeof.js";
|
|
2
|
-
function toPrimitive(t,
|
|
2
|
+
function toPrimitive(t, e) {
|
|
3
3
|
if ("object" != _typeof(t) || !t) return t;
|
|
4
|
-
var
|
|
5
|
-
if (void 0 !==
|
|
6
|
-
var i =
|
|
4
|
+
var r;
|
|
5
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
6
|
+
var i = r.call(t, e || "default");
|
|
7
7
|
if ("object" != _typeof(i)) return i;
|
|
8
8
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
9
9
|
}
|
|
10
|
-
return ("string" ===
|
|
10
|
+
return ("string" === e ? String : Number)(t);
|
|
11
11
|
}
|
|
12
12
|
export { toPrimitive as default };
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
var
|
|
1
|
+
var cache;
|
|
2
2
|
function _interopRequireWildcard(e, t) {
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]);
|
|
19
|
-
return f;
|
|
20
|
-
}, module.exports.__esModule = true, module.exports["default"] = module.exports)(e, t);
|
|
3
|
+
if (!t && e && e.__esModule) return e;
|
|
4
|
+
var r,
|
|
5
|
+
c,
|
|
6
|
+
a = Object.defineProperty,
|
|
7
|
+
n = {
|
|
8
|
+
__proto__: null,
|
|
9
|
+
"default": e
|
|
10
|
+
};
|
|
11
|
+
if (Object(e) !== e) return n;
|
|
12
|
+
if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) {
|
|
13
|
+
if (cache.has(e)) return cache.get(e);
|
|
14
|
+
cache.set(e, n);
|
|
15
|
+
}
|
|
16
|
+
for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]);
|
|
17
|
+
return n;
|
|
21
18
|
}
|
|
22
19
|
module.exports = _interopRequireWildcard, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var _typeof = require("./typeof.js")["default"];
|
|
2
|
-
function toPrimitive(t,
|
|
2
|
+
function toPrimitive(t, e) {
|
|
3
3
|
if ("object" != _typeof(t) || !t) return t;
|
|
4
|
-
var
|
|
5
|
-
if (void 0 !==
|
|
6
|
-
var i =
|
|
4
|
+
var r;
|
|
5
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
6
|
+
var i = r.call(t, e || "default");
|
|
7
7
|
if ("object" != _typeof(i)) return i;
|
|
8
8
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
9
9
|
}
|
|
10
|
-
return ("string" ===
|
|
10
|
+
return ("string" === e ? String : Number)(t);
|
|
11
11
|
}
|
|
12
12
|
module.exports = toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"micromark-util-sanitize-uri": "^2.0.1",
|
|
49
49
|
"simple-icons": "16.31.0",
|
|
50
50
|
"@deepseek-ai/dsh-client-store": "0.2.1-alpha.1",
|
|
51
|
+
"@deepseek-ai/dsh-util-code-language": "0.2.1-alpha.1",
|
|
51
52
|
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-alpha.1",
|
|
52
|
-
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
53
|
-
"@deepseek-ai/dsh-util-code-language": "0.2.1-alpha.1"
|
|
53
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
54
54
|
},
|
|
55
55
|
"files": [
|
|
56
56
|
"lib/index.js",
|
|
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
|
|
|
167
167
|
const SCROLLBAR_LINGER_MS = 2e3;
|
|
168
168
|
/** Format complete-build metadata for the local brand badge. */
|
|
169
169
|
function localBuildVersion() {
|
|
170
|
-
return `0.2.1-alpha.1-
|
|
170
|
+
return `0.2.1-alpha.1-7d99acf` + ({}.DSH_CLIENT_GIT_DIRTY === "true" ? "-dirty" : "");
|
|
171
171
|
}
|
|
172
172
|
/** Each panel row subscribes only to its own selection state. */
|
|
173
173
|
function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/react": "~18.3.1",
|
|
27
|
-
"@deepseek-ai/
|
|
28
|
-
"@deepseek-ai/
|
|
27
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1",
|
|
28
|
+
"@deepseek-ai/dsh-client-store": "0.2.1-alpha.1"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"lib/index.js",
|
|
@@ -187,15 +187,17 @@ function canonicalTarget(path) {
|
|
|
187
187
|
return parent === absolute ? absolute : join(canonicalTarget(parent), basename(absolute));
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* @param
|
|
194
|
-
* @returns
|
|
190
|
+
* Compile file-name globs, where `*` matches any run of characters and
|
|
191
|
+
* matching ignores case, into one predicate. Compile once and reuse the
|
|
192
|
+
* predicate when testing many names.
|
|
193
|
+
* @param globs - patterns such as `.env.*` or `id_rsa*`.
|
|
194
|
+
* @returns whether a single path component matches any whole pattern; always false for no globs.
|
|
195
195
|
*/
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
function nameGlobMatcher(globs) {
|
|
197
|
+
if (globs.length === 0) return () => false;
|
|
198
|
+
const patterns = globs.map((glob) => glob.split("*").map((part) => part.replaceAll(/[.+?^${}()|[\]\\]/gu, String.raw`\$&`)).join(".*"));
|
|
199
|
+
const regex = new RegExp(`^(?:${patterns.join("|")})$`, "iu");
|
|
200
|
+
return (name) => regex.test(name);
|
|
199
201
|
}
|
|
200
202
|
/**
|
|
201
203
|
* Whether the canonical file name of `path` matches a hidden-name glob of
|
|
@@ -205,8 +207,7 @@ function matchesNameGlob(name, glob) {
|
|
|
205
207
|
* @returns true when the path is hidden regardless of its root.
|
|
206
208
|
*/
|
|
207
209
|
function isHiddenIn(path, scope) {
|
|
208
|
-
|
|
209
|
-
return scope.hiddenNames.some((glob) => matchesNameGlob(name, glob));
|
|
210
|
+
return nameGlobMatcher(scope.hiddenNames)(basename(canonicalTarget(path)));
|
|
210
211
|
}
|
|
211
212
|
/**
|
|
212
213
|
* Whether `path` is readable within `scope`: it lies inside a root after both
|
|
@@ -361,4 +362,4 @@ var SandboxProvider = class extends Service {
|
|
|
361
362
|
escalationNote(_policy, _target) {}
|
|
362
363
|
};
|
|
363
364
|
//#endregion
|
|
364
|
-
export { ESCALATION_TARGETS, SANDBOX_UNAVAILABLE, SandboxProvider, SandboxProvider as default, SandboxUnavailableError, WIDER_MODES, approveEscalation, canonicalPath, classifyRunnerFailure, escalationHintMarker, isHiddenIn, isReadableIn, isRunnerSpawnFailure,
|
|
365
|
+
export { ESCALATION_TARGETS, SANDBOX_UNAVAILABLE, SandboxProvider, SandboxProvider as default, SandboxUnavailableError, WIDER_MODES, approveEscalation, canonicalPath, classifyRunnerFailure, escalationHintMarker, isHiddenIn, isReadableIn, isRunnerSpawnFailure, matchesSignature, nameGlobMatcher, sandboxDenialMarker, sandboxPermissionsDescription, validateEscalationArgs, writableRoots };
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
en: fe0f7d5ac6160763
|
|
28
28
|
zh: 4e1455a8559d46ca
|
|
29
29
|
/deepseek-ai-dsh-sandbox-apple-container/use-this-package/what-confinement-covers:
|
|
30
|
-
en:
|
|
31
|
-
zh:
|
|
30
|
+
en: 36ce4366173e0544
|
|
31
|
+
zh: 4f7537ee5c9c78c0
|
|
32
32
|
/deepseek-ai-dsh-sandbox-apple-container/use-this-package/failures-and-recovery:
|
|
33
33
|
en: 79782500f91b1f06
|
|
34
34
|
zh: a132d680acb85edc
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
en: 42b15ac6321706aa
|
|
37
37
|
zh: c8011788e17a2cd6
|
|
38
38
|
/deepseek-ai-dsh-sandbox-apple-container/understand-the-implementation/containers:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: 9d22cd4f279e3c98
|
|
40
|
+
zh: b401fea7af29a453
|
|
41
41
|
/deepseek-ai-dsh-sandbox-apple-container/understand-the-implementation/execution-shim:
|
|
42
|
-
en:
|
|
43
|
-
zh:
|
|
42
|
+
en: 98ef17c4b9975fa3
|
|
43
|
+
zh: 223994718947d592
|
|
44
44
|
/deepseek-ai-dsh-sandbox-apple-container/understand-the-implementation/source-map:
|
|
45
45
|
en: 866bf8dec1ab38ba
|
|
46
46
|
zh: af875a19b5ceb7b9
|
|
@@ -71,7 +71,7 @@ The fields of `@deepseek-ai/dsh-sandbox-local` also apply to the `local` backend
|
|
|
71
71
|
| A command or tool reads a secret file in the workspace | Masked to `/dev/null` in the guest; refused by file tools; excluded from `grep` |
|
|
72
72
|
| A credential reaches the guest environment | Denied names and URLs carrying `user:password@` are never forwarded |
|
|
73
73
|
| A command plants a Git hook or config the host later runs | `.git` is read-only under `workspace-write`; writes fail with `Read-only file system` and use the normal escalation |
|
|
74
|
-
| A command writes outside the workspace | The write lands in the container's own disk and never reaches the host |
|
|
74
|
+
| A command writes outside the workspace | The write lands in the container's own disk and never reaches the host, except under `/run/dsh`, the container's private run directory for start sentinels, which is deleted with the container |
|
|
75
75
|
|
|
76
76
|
`danger-full-access` bypasses `confine`, so it runs on the host under either backend. The approval prompt for an escalation to `danger-full-access` from a container session adds that the command runs directly on the Mac, outside the container. The Auto permission does not write it while a session runs on this backend: it writes `workspace-write`, and the reviewer, not a prompt, approves a one-shot escalation that leaves the container ([Auto review](../../experimental/auto-review/README.md)). On the `local` backend Auto still writes `danger-full-access`.
|
|
77
77
|
|
|
@@ -89,11 +89,11 @@ Missing CLI, a stopped API server that cannot start, or a failed `container run`
|
|
|
89
89
|
|
|
90
90
|
### Containers
|
|
91
91
|
|
|
92
|
-
The provider owns one container per canonical workspace root and confined mode, shared by every session and subagent in that workspace and mode. It starts with `container run --detach --init --rm`, labelled with the owning process id, bind-mounted with `--mount type=bind,…` (the `-v src:dst:ro` form is not used because `container` 1.5.0 misparses it), and idles on `sleep infinity`. A cached container is re-inspected at most once per `recheckMs` and restarted when gone; disposal deletes every owned container, and load deletes containers whose
|
|
92
|
+
The provider owns one container per canonical workspace root and confined mode, shared by every session and subagent in that workspace and mode. It starts with `container run --detach --init --rm`, labelled with the owning process id, bind-mounted with `--mount type=bind,…` (the `-v src:dst:ro` form is not used because `container` 1.5.0 misparses it), and idles on `sleep infinity`. Each container also mounts a private host run directory, `<os tmpdir>/dsh-container-run/<container name>`, writable at `/run/dsh` under every confined mode. A cached container is re-inspected with one `container inspect` at most once per `recheckMs` and restarted when it is gone or its run directory was deleted; disposal deletes every owned container and its run directory, and load deletes containers and run directories whose process has exited. When the default backend is `container` and the deployment default mode is confined, the default-mode container starts in the background at load.
|
|
93
93
|
|
|
94
94
|
### Execution shim
|
|
95
95
|
|
|
96
|
-
`confine` returns `[node, exec-shim.js, <executable>, <container>, <denylist>, '--', ...argv]`. The shim runs on the host with the caller's working directory and environment, writes the filtered environment to a private `--env-file`, and runs `container exec -i [-t] -w <cwd>` with the argv under `setsid -w` in the guest. Because `container exec` does not forward signals, the shim
|
|
96
|
+
`confine` returns `[node, exec-shim.js, <executable>, <container>, <run dir>, <denylist>, '--', ...argv]`. The shim runs on the host with the caller's working directory and environment, writes the filtered environment to a private `--env-file`, and runs `container exec -i [-t] -w <cwd>` with the argv under `setsid -w` in the guest. Before the argv starts, the guest wrapper writes its process-group id to `/run/dsh/<token>.pid`; when that write fails, the argv does not run. Because `container exec` does not forward signals, the shim signals that process group itself; a forwarded signal exits `128 + n`. The pid file doubles as the start sentinel: after `container exec` exits, the shim removes it from the host run directory, and a missing file marks a runtime failure, reported as `dsh-container-exec: …` with exit 125 and classified by the runner-failure rule, rather than a command that ran and failed. Each command therefore costs one `container exec`. The built `lib/exec-shim.js` depends only on Node built-ins and runs under plain Node in the npm-installed CLI; a source checkout launches `src/exec-shim.ts` through tsx.
|
|
97
97
|
|
|
98
98
|
### Source map
|
|
99
99
|
|
|
@@ -71,7 +71,7 @@ kind: "package-reference"
|
|
|
71
71
|
| 命令或工具读取工作区中的密钥文件 | 在客户机中被遮蔽为 `/dev/null`;被文件工具拒绝;从 `grep` 中排除 |
|
|
72
72
|
| 凭据进入客户机环境 | 被拒绝的名称以及带有 `user:password@` 的 URL 永不转发 |
|
|
73
73
|
| 命令植入宿主机之后会执行的 Git hook 或配置 | 在 `workspace-write` 下 `.git` 为只读;写入以 `Read-only file system` 失败,并走常规提权流程 |
|
|
74
|
-
| 命令写入工作区之外 |
|
|
74
|
+
| 命令写入工作区之外 | 写入落在容器自己的磁盘上,不会到达宿主机;唯一例外是 `/run/dsh`,即容器存放启动哨兵的私有运行目录,它随容器一起删除 |
|
|
75
75
|
|
|
76
76
|
`danger-full-access` 绕过 `confine`,因此在任一后端下都在宿主机上运行。从容器会话升权到 `danger-full-access` 时,审批提示会补充说明该命令将直接在 Mac 上运行,而不是在容器内。会话运行在此后端时,Auto 权限不会写入它:而是写入 `workspace-write`,并由 reviewer 而不是提示批准离开容器的一次性提权([Auto review](../../experimental/auto-review/README.zh.md))。在 `local` 后端上,Auto 仍写入 `danger-full-access`。
|
|
77
77
|
|
|
@@ -89,11 +89,11 @@ CLI 缺失、已停止且无法启动的 API 服务器,或 `container run` 失
|
|
|
89
89
|
|
|
90
90
|
### 容器
|
|
91
91
|
|
|
92
|
-
提供方为每个规范化的工作区根目录与受限模式各持有一个容器,由该工作区与模式下的所有会话和子智能体共享。容器以 `container run --detach --init --rm` 启动,带有所属进程 id 的标签,使用 `--mount type=bind,…` 绑定挂载(不使用 `-v src:dst:ro` 形式,因为 `container` 1.5.0 会错误解析它),并以 `sleep infinity`
|
|
92
|
+
提供方为每个规范化的工作区根目录与受限模式各持有一个容器,由该工作区与模式下的所有会话和子智能体共享。容器以 `container run --detach --init --rm` 启动,带有所属进程 id 的标签,使用 `--mount type=bind,…` 绑定挂载(不使用 `-v src:dst:ro` 形式,因为 `container` 1.5.0 会错误解析它),并以 `sleep infinity` 空转。每个容器还挂载一个私有的宿主机运行目录 `<os tmpdir>/dsh-container-run/<container name>`,在所有受限模式下都以可写方式挂载到 `/run/dsh`。缓存的容器每 `recheckMs` 至多以一次 `container inspect` 重新检查,在容器消失或其运行目录被删除时重新启动;销毁时删除所有自有容器及其运行目录,加载时删除所属进程已退出的容器与运行目录。当默认后端为 `container` 且部署默认模式为受限模式时,默认模式的容器会在加载时于后台启动。
|
|
93
93
|
|
|
94
94
|
### 执行 shim
|
|
95
95
|
|
|
96
|
-
`confine` 返回 `[node, exec-shim.js, <executable>, <container>, <denylist>, '--', ...argv]`。shim 以调用方的工作目录与环境在宿主机上运行,将过滤后的环境写入私有的 `--env-file`,并在客户机中通过 `setsid -w` 以 `container exec -i [-t] -w <cwd>` 运行 argv
|
|
96
|
+
`confine` 返回 `[node, exec-shim.js, <executable>, <container>, <run dir>, <denylist>, '--', ...argv]`。shim 以调用方的工作目录与环境在宿主机上运行,将过滤后的环境写入私有的 `--env-file`,并在客户机中通过 `setsid -w` 以 `container exec -i [-t] -w <cwd>` 运行 argv。argv 启动前,客户机包装脚本将其进程组 id 写入 `/run/dsh/<token>.pid`;写入失败时 argv 不会运行。由于 `container exec` 不转发信号,shim 自行向该进程组发送信号;被转发的信号以 `128 + n` 退出。该 pid 文件同时充当启动哨兵:`container exec` 退出后,shim 从宿主机运行目录中删除它,文件缺失即表示运行时失败(以 `dsh-container-exec: …` 报告、退出码 125,并由运行器失败规则分类),而非已运行但失败的命令。因此每条命令只需一次 `container exec`。构建后的 `lib/exec-shim.js` 只依赖 Node 内置模块,可在 npm 安装的 CLI 中以纯 Node 运行;源码检出则通过 tsx 启动 `src/exec-shim.ts`。
|
|
97
97
|
|
|
98
98
|
### 源码地图
|
|
99
99
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { mkdtempSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { constants, tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
/** Prefix of the single stderr line the shim writes for {@link SHIM_FAILURE_EXIT}. */
|
|
7
7
|
const SHIM_FAILURE_PREFIX = "dsh-container-exec: ";
|
|
8
|
+
/** Guest path of each container's run directory, a writable bind mount of a host directory. */
|
|
9
|
+
const GUEST_RUN_DIR = "/run/dsh";
|
|
8
10
|
/**
|
|
9
11
|
* Decode the argument list produced by {@link encodeShimArgs}.
|
|
10
12
|
* @param args - the shim process arguments after the entry path.
|
|
@@ -12,11 +14,12 @@ const SHIM_FAILURE_PREFIX = "dsh-container-exec: ";
|
|
|
12
14
|
* @throws {Error} when the list is malformed or the argv is empty.
|
|
13
15
|
*/
|
|
14
16
|
function parseShimArgs(args) {
|
|
15
|
-
const [executable, container, denylist, separator, ...argv] = args;
|
|
16
|
-
if (executable === void 0 || container === void 0 || denylist === void 0 || separator !== "--" || argv.length === 0) throw new Error("usage: exec-shim <executable> <container> <denylist> -- <argv...>");
|
|
17
|
+
const [executable, container, runDir, denylist, separator, ...argv] = args;
|
|
18
|
+
if (executable === void 0 || container === void 0 || runDir === void 0 || denylist === void 0 || separator !== "--" || argv.length === 0) throw new Error("usage: exec-shim <executable> <container> <run-dir> <denylist> -- <argv...>");
|
|
17
19
|
return {
|
|
18
20
|
executable,
|
|
19
21
|
container,
|
|
22
|
+
runDir,
|
|
20
23
|
denylist: denylist === "" ? [] : denylist.split(","),
|
|
21
24
|
argv
|
|
22
25
|
};
|
|
@@ -50,22 +53,20 @@ function envFileText(env, denylist) {
|
|
|
50
53
|
}
|
|
51
54
|
return text;
|
|
52
55
|
}
|
|
53
|
-
/**
|
|
54
|
-
function
|
|
55
|
-
return {
|
|
56
|
-
pid: `/run/dsh-${token}.pid`,
|
|
57
|
-
started: `/run/dsh-${token}.started`
|
|
58
|
-
};
|
|
56
|
+
/** File name of one run's process-group-id file in the run directory. */
|
|
57
|
+
function pidFileName(token) {
|
|
58
|
+
return `${token}.pid`;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* The guest `sh -c` wrapper: records its process-group id
|
|
62
|
-
* sentinel, runs the argv
|
|
61
|
+
* The guest `sh -c` wrapper: records its process-group id, which doubles as
|
|
62
|
+
* the start sentinel, then runs the argv and exits with its status. When the
|
|
63
|
+
* file cannot be written, the argv never runs and the wrapper exits
|
|
64
|
+
* {@link SHIM_FAILURE_EXIT}.
|
|
63
65
|
* @param token - the run's unique token.
|
|
64
66
|
* @returns the script text.
|
|
65
67
|
*/
|
|
66
68
|
function wrapperScript(token) {
|
|
67
|
-
|
|
68
|
-
return `echo $$ > ${pid}; : > ${started}; "$@"; s=$?; if [ $s -eq 0 ]; then rm -f ${pid} ${started}; fi; exit $s`;
|
|
69
|
+
return `echo $$ > ${GUEST_RUN_DIR}/${pidFileName(token)} || exit 125; "$@"`;
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* The `container exec` arguments that run the caller's argv in its own guest session.
|
|
@@ -105,24 +106,7 @@ function killArgs(container, token, signal) {
|
|
|
105
106
|
container,
|
|
106
107
|
"sh",
|
|
107
108
|
"-c",
|
|
108
|
-
`kill -${signal.slice(3)} -$(cat ${
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* The `container exec` arguments that remove the run's token files and exit
|
|
113
|
-
* zero only when the start sentinel existed.
|
|
114
|
-
* @param container - the container name.
|
|
115
|
-
* @param token - the run's token.
|
|
116
|
-
* @returns the arguments after the `container` executable.
|
|
117
|
-
*/
|
|
118
|
-
function settleArgs(container, token) {
|
|
119
|
-
const { pid, started } = tokenPaths(token);
|
|
120
|
-
return [
|
|
121
|
-
"exec",
|
|
122
|
-
container,
|
|
123
|
-
"sh",
|
|
124
|
-
"-c",
|
|
125
|
-
`test -e ${started}; s=$?; rm -f ${pid} ${started}; exit $s`
|
|
109
|
+
`kill -${signal.slice(3)} -$(cat ${GUEST_RUN_DIR}/${pidFileName(token)}) 2>/dev/null; true`
|
|
126
110
|
];
|
|
127
111
|
}
|
|
128
112
|
/** The exit status a shell reports for a process killed by `signal`. */
|
|
@@ -157,10 +141,9 @@ async function runShim(args, deps) {
|
|
|
157
141
|
resolve(code ?? signalExit(signal));
|
|
158
142
|
});
|
|
159
143
|
});
|
|
160
|
-
|
|
161
|
-
const started = await deps.run(args.executable, settleArgs(args.container, deps.token));
|
|
144
|
+
const started = deps.consumeFile(join(args.runDir, pidFileName(deps.token)));
|
|
162
145
|
if (forwarded !== void 0) return signalExit(forwarded);
|
|
163
|
-
if (
|
|
146
|
+
if (exit === 0 || started) return exit;
|
|
164
147
|
deps.stderr(`${SHIM_FAILURE_PREFIX}the container runtime failed before the command started (container exec exited ${exit})\n`);
|
|
165
148
|
return 125;
|
|
166
149
|
} catch (error) {
|
|
@@ -198,6 +181,15 @@ try {
|
|
|
198
181
|
resolve(error === null ? 0 : typeof error.code === "number" ? error.code : 125);
|
|
199
182
|
});
|
|
200
183
|
}),
|
|
184
|
+
consumeFile: (path) => {
|
|
185
|
+
try {
|
|
186
|
+
unlinkSync(path);
|
|
187
|
+
return true;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error.code === "ENOENT") return false;
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
201
193
|
writeEnvFile: (text) => {
|
|
202
194
|
const path = join(mkdtempSync(join(tmpdir(), "dsh-container-env-")), "env");
|
|
203
195
|
writeFileSync(path, text, { mode: 384 });
|