@deepseek-ai/dsh-shell-env 0.2.2-rc.1 → 0.2.2-rc.3
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.i18n.yaml +12 -12
- package/README.md +6 -5
- package/README.zh.md +6 -5
- package/lib/index.js +29 -4
- package/lib/types/error.d.ts +20 -0
- package/lib/types/error.d.ts.map +1 -0
- package/lib/types/error.js.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +17 -12
- package/src/error.ts +28 -0
- package/src/index.ts +227 -0
package/README.i18n.yaml
CHANGED
|
@@ -18,26 +18,26 @@
|
|
|
18
18
|
en: 34d2f05183df200f
|
|
19
19
|
zh: 7753b97c91743901
|
|
20
20
|
/deepseek-ai-dsh-shell-env/use-this-package/what-every-shell-call-receives:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
21
|
+
en: bab0b75fb967d41a
|
|
22
|
+
zh: 8f636d9965d01ad1
|
|
23
23
|
/deepseek-ai-dsh-shell-env/use-this-package/adding-your-own-environment-facts:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: 14da34f853d089be
|
|
25
|
+
zh: 5ad3942aa5321893
|
|
26
26
|
/deepseek-ai-dsh-shell-env/use-this-package/choosing-the-harness-home:
|
|
27
27
|
en: 0041438f2b7f7e4f
|
|
28
28
|
zh: 93fa165b07adcdf4
|
|
29
29
|
/deepseek-ai-dsh-shell-env/use-this-package/what-can-go-wrong:
|
|
30
|
-
en:
|
|
31
|
-
zh:
|
|
30
|
+
en: 737e5607cb1229cc
|
|
31
|
+
zh: 835b3f225d91f6ea
|
|
32
32
|
/deepseek-ai-dsh-shell-env/understand-the-implementation:
|
|
33
33
|
en: f782557ca8da3138
|
|
34
34
|
zh: e8f0082b9692cacc
|
|
35
35
|
/deepseek-ai-dsh-shell-env/understand-the-implementation/design-philosophy:
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
36
|
+
en: 5438a951817526d9
|
|
37
|
+
zh: 66459cdea830a8c8
|
|
38
38
|
/deepseek-ai-dsh-shell-env/understand-the-implementation/source-map:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: da18240c8c1dc687
|
|
40
|
+
zh: a854ddaca8953832
|
|
41
41
|
/deepseek-ai-dsh-shell-env/understand-the-implementation/collection:
|
|
42
42
|
en: 0c2d7d5b2131630f
|
|
43
43
|
zh: b44d4f0ddf89421b
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
en: e95e649f0410fa75
|
|
52
52
|
zh: b3d64877420b4c0d
|
|
53
53
|
/deepseek-ai-dsh-shell-env/known-limitations-and-deferred-work:
|
|
54
|
-
en:
|
|
55
|
-
zh:
|
|
54
|
+
en: e61f29904019b35b
|
|
55
|
+
zh: bfe2e8363d6c7e58
|
|
56
56
|
/deepseek-ai-dsh-shell-env/known-limitations-and-deferred-work/dev-note:
|
|
57
57
|
en: e67f633dc6fe7773
|
|
58
58
|
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Load this plugin in any composition that mounts a model shell tool (`dsh-tool-ba
|
|
|
29
29
|
|
|
30
30
|
### What every shell call receives
|
|
31
31
|
|
|
32
|
-
Every call receives `DSH_HOME` (the absolute Harness home), `DSH_SHELL=1`, and, for agent calls, `DSH_SESSION_ID` (the calling session's id). When the launcher provided a profile context, every call also receives `DSH_PROFILE` (the profile name)
|
|
32
|
+
Every call receives `DSH_HOME` (the absolute Harness home), `DSH_SHELL=1`, and, for agent calls, `DSH_SESSION_ID` (the calling session's id). Outside a single-executable application, every call also receives `DSH_NODE_EXECUTABLE`, the absolute path of the executable running the Harness. Under Desktop that is the Electron executable: it runs a script as Node only with `ELECTRON_RUN_AS_NODE=1`, and its Node file APIs read entries inside the `app.asar` archive that ordinary tools cannot open. When the launcher provided a profile context, every call also receives `DSH_PROFILE` (the profile name), `DSH_PROFILE_DIR` (its absolute directory; its `node_modules` holds only profile-installed packages, while the harness's own bundles resolve from the dsh installation), and `DSH_INSTALL_DIR` (the absolute directory of the `@deepseek-ai/dsh` package that anchors the installation, which carries the published `docs/` and `src/`); compositions booted without a profile omit all three.
|
|
33
33
|
|
|
34
34
|
### Adding your own environment facts
|
|
35
35
|
|
|
@@ -50,7 +50,7 @@ export function apply(ctx: Context): void {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Contributors must declare every key they return; returning an undeclared or non-string value fails the call. Registration is disposed with the registering plugin, so hot-reloading a plugin removes its facts.
|
|
53
|
+
Contributors must declare every key they return; returning an undeclared or non-string value fails the call with `ShellEnvError` (`SHELL_ENV_CONTRIBUTION_INVALID`). Registration is disposed with the registering plugin, so hot-reloading a plugin removes its facts.
|
|
54
54
|
|
|
55
55
|
### Choosing the Harness home
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-a
|
|
|
64
64
|
|
|
65
65
|
### What can go wrong
|
|
66
66
|
|
|
67
|
-
Two contributors declaring the same key, or a contributor claiming a reserved built-in (`DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, `DSH_PROFILE_DIR`), fails plugin load loudly. A `DSH_*` key must be all-caps with underscores (for example `DSH_REGION`), and a missing description fails registration.
|
|
67
|
+
Two contributors declaring the same key, or a contributor claiming a reserved built-in (`DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, `DSH_PROFILE_DIR`, `DSH_INSTALL_DIR`, `DSH_NODE_EXECUTABLE`), fails plugin load loudly. A `DSH_*` key must be all-caps with underscores (for example `DSH_REGION`), and a missing description fails registration.
|
|
68
68
|
|
|
69
69
|
-----
|
|
70
70
|
|
|
@@ -80,13 +80,14 @@ This section explains the design decisions behind the registry and points at the
|
|
|
80
80
|
|
|
81
81
|
- **Trusted namespace, rebuilt per call.** The environment is a Harness-owned `DSH_*` namespace: the shell executor discards inherited `DSH_*` values and merges the registry's current snapshot for each execution, so nested harnesses and concurrent parent/child agents cannot leak stale identities, and `process.env` is never modified.
|
|
82
82
|
- **Declared ownership, loud conflicts.** Contributors declare their keys up front so duplicate ownership is detected before the first command; resolvers may only return declared keys.
|
|
83
|
-
- **Built-ins stay here.** `DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, and `
|
|
83
|
+
- **Built-ins stay here.** `DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, `DSH_PROFILE_DIR`, `DSH_INSTALL_DIR`, and `DSH_NODE_EXECUTABLE` are reserved for the registry; contributors cannot claim them.
|
|
84
84
|
|
|
85
85
|
### Source map
|
|
86
86
|
|
|
87
87
|
| File | Role |
|
|
88
88
|
|---|---|
|
|
89
89
|
| [`src/index.ts`](src/index.ts) | Plugin entry, `ShellEnvRegistry` service, and the built-in facts |
|
|
90
|
+
| [`src/error.ts`](src/error.ts) | `ShellEnvError` and its codes |
|
|
90
91
|
|
|
91
92
|
### Collection
|
|
92
93
|
|
|
@@ -126,7 +127,7 @@ The managed environment never enters the request prefix, so it does not invalida
|
|
|
126
127
|
|
|
127
128
|
These limits define when the registry is a poor fit or needs care. They are current package constraints, not a task backlog.
|
|
128
129
|
|
|
129
|
-
- **`list()` enumerates plugin-contributed variables only** — registry-owned built-ins (`DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, `DSH_PROFILE_DIR`) are not included, so diagnostics, prompt, or UI code must not treat `list()` as an exhaustive environment catalog.
|
|
130
|
+
- **`list()` enumerates plugin-contributed variables only** — registry-owned built-ins (`DSH_HOME`, `DSH_SHELL`, `DSH_SESSION_ID`, `DSH_PROFILE`, `DSH_PROFILE_DIR`, `DSH_INSTALL_DIR`, `DSH_NODE_EXECUTABLE`) are not included, so diagnostics, prompt, or UI code must not treat `list()` as an exhaustive environment catalog.
|
|
130
131
|
|
|
131
132
|
<a id="dev-note"></a>
|
|
132
133
|
### Dev Note
|
package/README.zh.md
CHANGED
|
@@ -29,7 +29,7 @@ kind: "package-reference"
|
|
|
29
29
|
|
|
30
30
|
### 每次 shell 调用都会收到什么
|
|
31
31
|
|
|
32
|
-
每次调用都会收到 `DSH_HOME`(Harness 主目录的绝对路径)、`DSH_SHELL=1`,agent 调用还会收到 `DSH_SESSION_ID`(调用方会话的 id
|
|
32
|
+
每次调用都会收到 `DSH_HOME`(Harness 主目录的绝对路径)、`DSH_SHELL=1`,agent 调用还会收到 `DSH_SESSION_ID`(调用方会话的 id)。不在单可执行文件应用中运行时,每次调用还会收到 `DSH_NODE_EXECUTABLE`,即运行 Harness 的可执行文件的绝对路径。Desktop 下它是 Electron 可执行文件:只有设置 `ELECTRON_RUN_AS_NODE=1` 时它才以 Node 方式运行脚本,其 Node 文件 API 能读取普通工具打不开的 `app.asar` 归档内条目。启动器提供了 profile 上下文时,每次调用还会收到 `DSH_PROFILE`(profile 名)、`DSH_PROFILE_DIR`(其绝对目录;其 `node_modules` 只存放 profile 自行安装的包,harness 自带的组合包从 dsh 安装目录解析)与 `DSH_INSTALL_DIR`(作为安装锚点的 `@deepseek-ai/dsh` 包的绝对目录,随包发布的 `docs/` 与 `src/` 位于其中);不带 profile 启动的组合则三者都没有。
|
|
33
33
|
|
|
34
34
|
### 添加你自己的环境事实
|
|
35
35
|
|
|
@@ -50,7 +50,7 @@ export function apply(ctx: Context): void {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
contributor
|
|
53
|
+
contributor 必须声明它返回的每个键;返回未声明或非字符串的值会让该次调用以 `ShellEnvError`(`SHELL_ENV_CONTRIBUTION_INVALID`)失败。注册随注册插件的释放而释放,因此热重载插件会移除它的事实。
|
|
54
54
|
|
|
55
55
|
### 选择 Harness 主目录
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ contributor 必须声明它返回的每个键;返回未声明或非字符串
|
|
|
64
64
|
|
|
65
65
|
### 可能出什么问题
|
|
66
66
|
|
|
67
|
-
两个 contributor 声明同一个键,或 contributor 声称拥有保留内置键(`DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE`、`DSH_PROFILE_DIR`),都会导致插件加载时明确报错。`DSH_*` 键必须全大写并带下划线(例如 `DSH_REGION`),缺少描述也会让注册失败。
|
|
67
|
+
两个 contributor 声明同一个键,或 contributor 声称拥有保留内置键(`DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE`、`DSH_PROFILE_DIR`、`DSH_INSTALL_DIR`、`DSH_NODE_EXECUTABLE`),都会导致插件加载时明确报错。`DSH_*` 键必须全大写并带下划线(例如 `DSH_REGION`),缺少描述也会让注册失败。
|
|
68
68
|
|
|
69
69
|
-----
|
|
70
70
|
|
|
@@ -80,13 +80,14 @@ contributor 必须声明它返回的每个键;返回未声明或非字符串
|
|
|
80
80
|
|
|
81
81
|
- **受信命名空间,每次调用重建。** 环境是归 Harness 所有的 `DSH_*` 命名空间:shell 执行器丢弃继承的 `DSH_*` 值,并为每次执行合并注册表的当前快照,因此嵌套 harness 与并发的父子 agent 无法泄漏陈旧身份,`process.env` 也永不被修改。
|
|
82
82
|
- **声明所有权,冲突明确报错。** contributor 预先声明键,使重复所有权在第一条命令之前就被发现;resolver 只能返回已声明的键。
|
|
83
|
-
- **内置键留在这里。** `DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE` 与 `
|
|
83
|
+
- **内置键留在这里。** `DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE`、`DSH_PROFILE_DIR`、`DSH_INSTALL_DIR` 与 `DSH_NODE_EXECUTABLE` 为注册表保留;contributor 不能声称拥有它们。
|
|
84
84
|
|
|
85
85
|
### 源码地图
|
|
86
86
|
|
|
87
87
|
| 文件 | 职责 |
|
|
88
88
|
|---|---|
|
|
89
89
|
| [`src/index.ts`](src/index.ts) | 插件入口、`ShellEnvRegistry` 服务与内置事实 |
|
|
90
|
+
| [`src/error.ts`](src/error.ts) | `ShellEnvError` 及其 code |
|
|
90
91
|
|
|
91
92
|
### 收集
|
|
92
93
|
|
|
@@ -126,7 +127,7 @@ contributor 必须声明它返回的每个键;返回未声明或非字符串
|
|
|
126
127
|
|
|
127
128
|
这些限制说明注册表何时不合适或需要小心使用。它们是当前包约束,不是任务积压。
|
|
128
129
|
|
|
129
|
-
- **`list()` 只枚举插件贡献的变量**——注册表自有的内置键(`DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE`、`DSH_PROFILE_DIR`)不包含在内,因此诊断、提示词或 UI 代码不得把 `list()` 当作完整的环境目录。
|
|
130
|
+
- **`list()` 只枚举插件贡献的变量**——注册表自有的内置键(`DSH_HOME`、`DSH_SHELL`、`DSH_SESSION_ID`、`DSH_PROFILE`、`DSH_PROFILE_DIR`、`DSH_INSTALL_DIR`、`DSH_NODE_EXECUTABLE`)不包含在内,因此诊断、提示词或 UI 代码不得把 `list()` 当作完整的环境目录。
|
|
130
131
|
|
|
131
132
|
<a id="dev-note"></a>
|
|
132
133
|
### 开发备注
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
1
2
|
import { Service } from "@deepseek-ai/cordis";
|
|
2
3
|
import z from "@deepseek-ai/schemastery";
|
|
3
4
|
import { DSH_ENV_PREFIX } from "@deepseek-ai/dsh-shell";
|
|
4
5
|
import { DSH_HOME_ENV, resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
6
|
+
import { HarnessError } from "@deepseek-ai/dsh-error";
|
|
7
|
+
//#region lib/types/error.js
|
|
8
|
+
/** Machine-routable shell environment failures. @module */
|
|
9
|
+
/** Shell environment failure carrying a stable {@link ShellEnvErrorCode}. */
|
|
10
|
+
var ShellEnvError = class extends HarnessError {
|
|
11
|
+
code;
|
|
12
|
+
/**
|
|
13
|
+
* @param message - names the contributor and the offending key.
|
|
14
|
+
* @param code - the failure class consumers route on.
|
|
15
|
+
*/
|
|
16
|
+
constructor(message, code) {
|
|
17
|
+
super(message, code);
|
|
18
|
+
this.name = "ShellEnvError";
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
5
23
|
//#region lib/types/index.js
|
|
6
24
|
/**
|
|
7
25
|
* Tool-independent shell environment plugin: owns the `ctx.shellEnv` registry of
|
|
@@ -20,12 +38,16 @@ const DSH_SHELL_KEY = `${DSH_ENV_PREFIX}SHELL`;
|
|
|
20
38
|
const DSH_SESSION_ID_KEY = `${DSH_ENV_PREFIX}SESSION_ID`;
|
|
21
39
|
const DSH_PROFILE_KEY = `${DSH_ENV_PREFIX}PROFILE`;
|
|
22
40
|
const DSH_PROFILE_DIR_KEY = `${DSH_ENV_PREFIX}PROFILE_DIR`;
|
|
41
|
+
const DSH_INSTALL_DIR_KEY = `${DSH_ENV_PREFIX}INSTALL_DIR`;
|
|
42
|
+
const DSH_NODE_EXECUTABLE_KEY = `${DSH_ENV_PREFIX}NODE_EXECUTABLE`;
|
|
23
43
|
const RESERVED_BASH_ENV_KEYS = new Set([
|
|
24
44
|
DSH_HOME_ENV,
|
|
25
45
|
DSH_SHELL_KEY,
|
|
26
46
|
DSH_SESSION_ID_KEY,
|
|
27
47
|
DSH_PROFILE_KEY,
|
|
28
|
-
DSH_PROFILE_DIR_KEY
|
|
48
|
+
DSH_PROFILE_DIR_KEY,
|
|
49
|
+
DSH_INSTALL_DIR_KEY,
|
|
50
|
+
DSH_NODE_EXECUTABLE_KEY
|
|
29
51
|
]);
|
|
30
52
|
const BASH_ENV_KEY_SUFFIX = /^[A-Z][A-Z0-9_]*$/;
|
|
31
53
|
/**
|
|
@@ -86,18 +108,21 @@ var ShellEnvRegistry = class extends Service {
|
|
|
86
108
|
[DSH_HOME_ENV]: this.dshHome,
|
|
87
109
|
[DSH_SHELL_KEY]: "1"
|
|
88
110
|
};
|
|
111
|
+
const sea = process.getBuiltinModule("node:sea");
|
|
112
|
+
if (sea === void 0 || !sea.isSea()) values[DSH_NODE_EXECUTABLE_KEY] = process.execPath;
|
|
89
113
|
if (execution.agent !== void 0) values[DSH_SESSION_ID_KEY] = execution.agent.session.header.id;
|
|
90
114
|
const profile = this.ctx.get("profileContext");
|
|
91
115
|
if (profile !== void 0) {
|
|
92
116
|
values[DSH_PROFILE_KEY] = profile.name;
|
|
93
117
|
values[DSH_PROFILE_DIR_KEY] = profile.dir;
|
|
118
|
+
values[DSH_INSTALL_DIR_KEY] = dirname(profile.installAnchor);
|
|
94
119
|
}
|
|
95
120
|
for (const contributor of [...this.contributors.values()].sort((left, right) => left.name.localeCompare(right.name))) {
|
|
96
121
|
const resolved = contributor.resolve(execution);
|
|
97
122
|
for (const [rawKey, value] of Object.entries(resolved)) {
|
|
98
123
|
const key = rawKey;
|
|
99
|
-
if (!Object.hasOwn(contributor.variables, key)) throw new
|
|
100
|
-
if (typeof value !== "string") throw new
|
|
124
|
+
if (!Object.hasOwn(contributor.variables, key)) throw new ShellEnvError(`bash env contributor "${contributor.name}" returned undeclared key "${key}"`, "SHELL_ENV_CONTRIBUTION_INVALID");
|
|
125
|
+
if (typeof value !== "string") throw new ShellEnvError(`bash env contributor "${contributor.name}" returned a non-string value for "${key}"`, "SHELL_ENV_CONTRIBUTION_INVALID");
|
|
101
126
|
values[key] = value;
|
|
102
127
|
}
|
|
103
128
|
}
|
|
@@ -124,4 +149,4 @@ function apply(ctx, config = {}) {
|
|
|
124
149
|
new ShellEnvRegistry(ctx, config);
|
|
125
150
|
}
|
|
126
151
|
//#endregion
|
|
127
|
-
export { Config, ShellEnvRegistry, apply, inject, name };
|
|
152
|
+
export { Config, ShellEnvError, ShellEnvRegistry, apply, inject, name };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Machine-routable shell environment failures. @module */
|
|
2
|
+
import { HarnessError } from '@deepseek-ai/dsh-error';
|
|
3
|
+
/**
|
|
4
|
+
* Every {@link ShellEnvError} code:
|
|
5
|
+
* - `SHELL_ENV_CONTRIBUTION_INVALID` — a registered contributor returned an undeclared key or a non-string value; the
|
|
6
|
+
* shell command does not run, and the contributing plugin must be fixed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SHELL_ENV_ERROR_CODES: readonly ["SHELL_ENV_CONTRIBUTION_INVALID"];
|
|
9
|
+
/** One code from {@link SHELL_ENV_ERROR_CODES}. */
|
|
10
|
+
export type ShellEnvErrorCode = typeof SHELL_ENV_ERROR_CODES[number];
|
|
11
|
+
/** Shell environment failure carrying a stable {@link ShellEnvErrorCode}. */
|
|
12
|
+
export declare class ShellEnvError extends HarnessError {
|
|
13
|
+
readonly code: ShellEnvErrorCode;
|
|
14
|
+
/**
|
|
15
|
+
* @param message - names the contributor and the offending key.
|
|
16
|
+
* @param code - the failure class consumers route on.
|
|
17
|
+
*/
|
|
18
|
+
constructor(message: string, code: ShellEnvErrorCode);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,6CAA8C,CAAA;AAEhF,mDAAmD;AACnD,MAAM,MAAM,iBAAiB,GAAG,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAA;AAEpE,6EAA6E;AAC7E,qBAAa,aAAc,SAAQ,YAAY;IAC7C,SAAkB,IAAI,EAAE,iBAAiB,CAAA;IAEzC;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;CAKrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,gCAAgC,CAAU,CAAA;AAKhF,6EAA6E;AAC7E,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC3B,IAAI,CAAmB;IAEzC;;;OAGG;IACH,YAAY,OAAe,EAAE,IAAuB;QAClD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Service, type Context } from '@deepseek-ai/cordis';
|
|
|
11
11
|
import z from '@deepseek-ai/schemastery';
|
|
12
12
|
import type { DshEnvironment, DshEnvironmentKey } from '@deepseek-ai/dsh-shell';
|
|
13
13
|
import type { ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
14
|
+
export { ShellEnvError, type ShellEnvErrorCode } from './error.ts';
|
|
14
15
|
declare module '@deepseek-ai/cordis' {
|
|
15
16
|
interface Context {
|
|
16
17
|
shellEnv: ShellEnvRegistry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAI3D,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAElE,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,QAA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AAE,QAAQ,CAAC,WAAW;YACjC,GAAG,EAAE,GAAwB;SAC9B,CAAC,CAAC,CAAC;aACH,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7D,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,SAAiB,EAAE;IACrD,IAAI,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-shell-env",
|
|
3
3
|
"description": "Tool-independent managed DSH_* shell environment registry",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -25,26 +25,31 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
|
-
"lib/types/**/*.d.ts"
|
|
28
|
+
"lib/types/**/*.d.ts",
|
|
29
|
+
"lib/types/**/*.d.ts.map",
|
|
30
|
+
"lib/**/*.js.map",
|
|
31
|
+
"src"
|
|
29
32
|
],
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
33
|
-
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.
|
|
34
|
-
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.
|
|
35
|
-
"@deepseek-ai/dsh-shell": "0.2.2-rc.
|
|
36
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
36
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.3",
|
|
37
|
+
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.3",
|
|
38
|
+
"@deepseek-ai/dsh-shell": "0.2.2-rc.3",
|
|
39
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.3",
|
|
40
|
+
"@deepseek-ai/dsh-error": "0.2.2-rc.3"
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"@deepseek-ai/schemastery": "~3.19.0"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
46
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
43
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
44
|
-
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.
|
|
45
|
-
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.
|
|
46
|
-
"@deepseek-ai/dsh-
|
|
47
|
-
"@deepseek-ai/dsh-
|
|
48
|
-
"@deepseek-ai/dsh-
|
|
47
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.3",
|
|
48
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.3",
|
|
49
|
+
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.3",
|
|
50
|
+
"@deepseek-ai/dsh-error": "0.2.2-rc.3",
|
|
51
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
52
|
+
"@deepseek-ai/dsh-shell": "0.2.2-rc.3",
|
|
53
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.3"
|
|
49
54
|
}
|
|
50
55
|
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Machine-routable shell environment failures. @module */
|
|
2
|
+
|
|
3
|
+
import { HarnessError } from '@deepseek-ai/dsh-error'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every {@link ShellEnvError} code:
|
|
7
|
+
* - `SHELL_ENV_CONTRIBUTION_INVALID` — a registered contributor returned an undeclared key or a non-string value; the
|
|
8
|
+
* shell command does not run, and the contributing plugin must be fixed.
|
|
9
|
+
*/
|
|
10
|
+
export const SHELL_ENV_ERROR_CODES = ['SHELL_ENV_CONTRIBUTION_INVALID'] as const
|
|
11
|
+
|
|
12
|
+
/** One code from {@link SHELL_ENV_ERROR_CODES}. */
|
|
13
|
+
export type ShellEnvErrorCode = typeof SHELL_ENV_ERROR_CODES[number]
|
|
14
|
+
|
|
15
|
+
/** Shell environment failure carrying a stable {@link ShellEnvErrorCode}. */
|
|
16
|
+
export class ShellEnvError extends HarnessError {
|
|
17
|
+
override readonly code: ShellEnvErrorCode
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param message - names the contributor and the offending key.
|
|
21
|
+
* @param code - the failure class consumers route on.
|
|
22
|
+
*/
|
|
23
|
+
constructor(message: string, code: ShellEnvErrorCode) {
|
|
24
|
+
super(message, code)
|
|
25
|
+
this.name = 'ShellEnvError'
|
|
26
|
+
this.code = code
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-independent shell environment plugin: owns the `ctx.shellEnv` registry of
|
|
3
|
+
* trusted, per-execution `DSH_*` variables consumed by the model-facing shell
|
|
4
|
+
* tools (`dsh-tool-bash`, `dsh-tool-pwsh`). Built-in shell facts are owned by
|
|
5
|
+
* the registry itself while plugins can register additional, enumerable facts
|
|
6
|
+
* with effect-scoped disposal.
|
|
7
|
+
*
|
|
8
|
+
* @module @deepseek-ai/dsh-shell-env
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { dirname } from 'node:path'
|
|
12
|
+
import { Service, type Context } from '@deepseek-ai/cordis'
|
|
13
|
+
import z from '@deepseek-ai/schemastery'
|
|
14
|
+
import { DSH_ENV_PREFIX } from '@deepseek-ai/dsh-shell'
|
|
15
|
+
import type { DshEnvironment, DshEnvironmentKey } from '@deepseek-ai/dsh-shell'
|
|
16
|
+
import { DSH_HOME_ENV, resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
17
|
+
import { ShellEnvError } from './error.ts'
|
|
18
|
+
import type { ToolExecution } from '@deepseek-ai/dsh-tools'
|
|
19
|
+
// Declares `Context.profileContext`, the launcher-provided profile the built-ins read.
|
|
20
|
+
import type {} from '@deepseek-ai/dsh-app-boot'
|
|
21
|
+
|
|
22
|
+
export { ShellEnvError, type ShellEnvErrorCode } from './error.ts'
|
|
23
|
+
|
|
24
|
+
declare module '@deepseek-ai/cordis' {
|
|
25
|
+
interface Context {
|
|
26
|
+
shellEnv: ShellEnvRegistry
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const name = 'shell-env'
|
|
31
|
+
export const inject: string[] = []
|
|
32
|
+
|
|
33
|
+
/** Plugin config (all optional — the built-in facts resolve without defaults). */
|
|
34
|
+
export interface Config {
|
|
35
|
+
/** DeepSeek Harness home directory exposed as `DSH_HOME`; defaults to `$DSH_HOME` or `~/.dsh`. */
|
|
36
|
+
dshHome?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Runtime configuration schema for the shell-env plugin. */
|
|
40
|
+
export const Config: z<Config> = z.object({
|
|
41
|
+
dshHome: z.string(),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
/** Model-visible metadata for one managed `DSH_*` environment variable. */
|
|
45
|
+
export interface BashEnvVariable {
|
|
46
|
+
/** Concise description of the environment fact represented by the variable. */
|
|
47
|
+
description: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A plugin contribution to the managed environment of each model shell call.
|
|
52
|
+
* Declared keys make ownership conflicts detectable before the first command;
|
|
53
|
+
* `resolve` computes only the values available for the current execution.
|
|
54
|
+
*/
|
|
55
|
+
export interface BashEnvContributor {
|
|
56
|
+
/** Stable contributor name used in diagnostics and duplicate detection. */
|
|
57
|
+
name: string
|
|
58
|
+
/** Complete set of `DSH_*` keys this contributor may return. */
|
|
59
|
+
variables: Readonly<Record<DshEnvironmentKey, BashEnvVariable>>
|
|
60
|
+
/**
|
|
61
|
+
* Resolve this contributor's available values for one tool execution.
|
|
62
|
+
* @param execution - the shell tool execution and its optional calling agent.
|
|
63
|
+
* @returns a partial map containing only keys declared in {@link variables}.
|
|
64
|
+
*/
|
|
65
|
+
resolve(execution: ToolExecution): Readonly<Partial<Record<DshEnvironmentKey, string>>>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** An enumerable declaration returned by {@link ShellEnvRegistry.list}. */
|
|
69
|
+
export interface BashEnvVariableInfo extends BashEnvVariable {
|
|
70
|
+
/** Contributor that owns the variable. */
|
|
71
|
+
contributor: string
|
|
72
|
+
/** Declared `DSH_*` environment variable name. */
|
|
73
|
+
key: DshEnvironmentKey
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const DSH_SHELL_KEY = `${DSH_ENV_PREFIX}SHELL` as const
|
|
77
|
+
const DSH_SESSION_ID_KEY = `${DSH_ENV_PREFIX}SESSION_ID` as const
|
|
78
|
+
const DSH_PROFILE_KEY = `${DSH_ENV_PREFIX}PROFILE` as const
|
|
79
|
+
const DSH_PROFILE_DIR_KEY = `${DSH_ENV_PREFIX}PROFILE_DIR` as const
|
|
80
|
+
const DSH_INSTALL_DIR_KEY = `${DSH_ENV_PREFIX}INSTALL_DIR` as const
|
|
81
|
+
const DSH_NODE_EXECUTABLE_KEY = `${DSH_ENV_PREFIX}NODE_EXECUTABLE` as const
|
|
82
|
+
const RESERVED_BASH_ENV_KEYS = new Set<DshEnvironmentKey>([
|
|
83
|
+
DSH_HOME_ENV,
|
|
84
|
+
DSH_SHELL_KEY,
|
|
85
|
+
DSH_SESSION_ID_KEY,
|
|
86
|
+
DSH_PROFILE_KEY,
|
|
87
|
+
DSH_PROFILE_DIR_KEY,
|
|
88
|
+
DSH_INSTALL_DIR_KEY,
|
|
89
|
+
DSH_NODE_EXECUTABLE_KEY,
|
|
90
|
+
])
|
|
91
|
+
const BASH_ENV_KEY_SUFFIX = /^[A-Z][A-Z0-9_]*$/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Registry (`ctx.shellEnv`) for trusted, per-execution `DSH_*` variables.
|
|
95
|
+
* The namespace is rebuilt for every model shell call: ambient `DSH_*` values
|
|
96
|
+
* are discarded by the executor, then the registry's current snapshot is
|
|
97
|
+
* injected. Built-in shell facts remain owned by the registry itself while
|
|
98
|
+
* plugins can register additional, enumerable facts with effect-scoped
|
|
99
|
+
* disposal.
|
|
100
|
+
*/
|
|
101
|
+
export class ShellEnvRegistry extends Service {
|
|
102
|
+
private readonly contributors = new Map<string, BashEnvContributor>()
|
|
103
|
+
private readonly keyOwners = new Map<DshEnvironmentKey, string>()
|
|
104
|
+
private readonly dshHome: string
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Create and install the `ctx.shellEnv` service.
|
|
108
|
+
* @param ctx - Cordis context that owns the service and registrations.
|
|
109
|
+
* @param config - home-directory configuration for the built-in variables.
|
|
110
|
+
*/
|
|
111
|
+
constructor(ctx: Context, config: Config = {}) {
|
|
112
|
+
super(ctx, 'shellEnv')
|
|
113
|
+
this.dshHome = resolveDshHome(config.dshHome)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Register one environment contributor. Names and keys are unique; built-in
|
|
118
|
+
* keys are reserved. Registration is disposed with the calling plugin fiber.
|
|
119
|
+
* @param contributor - declared key ownership and per-execution resolver.
|
|
120
|
+
* @returns the disposer that unregisters the contribution.
|
|
121
|
+
*/
|
|
122
|
+
register(contributor: BashEnvContributor): () => void {
|
|
123
|
+
const dispose = this.ctx.effect(function* (this: ShellEnvRegistry) {
|
|
124
|
+
if (contributor.name.trim().length === 0) {
|
|
125
|
+
throw new Error('bash env contributor name must be non-empty')
|
|
126
|
+
}
|
|
127
|
+
if (this.contributors.has(contributor.name)) {
|
|
128
|
+
throw new Error(`bash env contributor "${contributor.name}" is already registered`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const variables = Object.entries(contributor.variables) as [DshEnvironmentKey, BashEnvVariable][]
|
|
132
|
+
for (const [key, variable] of variables) {
|
|
133
|
+
if (!key.startsWith(DSH_ENV_PREFIX)
|
|
134
|
+
|| !BASH_ENV_KEY_SUFFIX.test(key.slice(DSH_ENV_PREFIX.length))) {
|
|
135
|
+
throw new Error(`bash env contributor "${contributor.name}" declared invalid key "${key}"`)
|
|
136
|
+
}
|
|
137
|
+
if (RESERVED_BASH_ENV_KEYS.has(key)) {
|
|
138
|
+
throw new Error(`bash env contributor "${contributor.name}" cannot own reserved key "${key}"`)
|
|
139
|
+
}
|
|
140
|
+
if (variable.description.trim().length === 0) {
|
|
141
|
+
throw new Error(`bash env contributor "${contributor.name}" must describe "${key}"`)
|
|
142
|
+
}
|
|
143
|
+
const owner = this.keyOwners.get(key)
|
|
144
|
+
if (owner !== undefined) {
|
|
145
|
+
throw new Error(`bash env key "${key}" is already owned by contributor "${owner}"; contributor "${contributor.name}" cannot also own it`)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.contributors.set(contributor.name, contributor)
|
|
150
|
+
for (const [key] of variables) this.keyOwners.set(key, contributor.name)
|
|
151
|
+
yield () => {
|
|
152
|
+
this.contributors.delete(contributor.name)
|
|
153
|
+
for (const [key] of variables) this.keyOwners.delete(key)
|
|
154
|
+
}
|
|
155
|
+
}.bind(this), 'bashEnv.register()')
|
|
156
|
+
return () => void dispose()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Build the trusted `DSH_*` snapshot for one shell tool execution.
|
|
161
|
+
* @param execution - the current tool execution.
|
|
162
|
+
* @returns an immutable environment overlay containing built-ins and current contributions.
|
|
163
|
+
*/
|
|
164
|
+
collect(execution: ToolExecution): DshEnvironment {
|
|
165
|
+
const values: Record<DshEnvironmentKey, string> = {
|
|
166
|
+
[DSH_HOME_ENV]: this.dshHome,
|
|
167
|
+
[DSH_SHELL_KEY]: '1',
|
|
168
|
+
}
|
|
169
|
+
// A single-executable application runs its embedded entry instead of a script argument. The
|
|
170
|
+
// browser worker image answers no `node:sea`, so the module is looked up at run time.
|
|
171
|
+
const sea = process.getBuiltinModule('node:sea') as typeof import('node:sea') | undefined
|
|
172
|
+
if (sea === undefined || !sea.isSea()) values[DSH_NODE_EXECUTABLE_KEY] = process.execPath
|
|
173
|
+
if (execution.agent !== undefined) {
|
|
174
|
+
values[DSH_SESSION_ID_KEY] = execution.agent.session.header.id
|
|
175
|
+
}
|
|
176
|
+
const profile = this.ctx.get('profileContext')
|
|
177
|
+
if (profile !== undefined) {
|
|
178
|
+
values[DSH_PROFILE_KEY] = profile.name
|
|
179
|
+
values[DSH_PROFILE_DIR_KEY] = profile.dir
|
|
180
|
+
values[DSH_INSTALL_DIR_KEY] = dirname(profile.installAnchor)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
for (const contributor of [...this.contributors.values()].sort((left, right) => left.name.localeCompare(right.name))) {
|
|
184
|
+
const resolved = contributor.resolve(execution)
|
|
185
|
+
for (const [rawKey, value] of Object.entries(resolved)) {
|
|
186
|
+
const key = rawKey as DshEnvironmentKey
|
|
187
|
+
if (!Object.hasOwn(contributor.variables, key)) {
|
|
188
|
+
throw new ShellEnvError(`bash env contributor "${contributor.name}" returned undeclared key "${key}"`, 'SHELL_ENV_CONTRIBUTION_INVALID')
|
|
189
|
+
}
|
|
190
|
+
if (typeof value !== 'string') {
|
|
191
|
+
throw new ShellEnvError(
|
|
192
|
+
`bash env contributor "${contributor.name}" returned a non-string value for "${key}"`,
|
|
193
|
+
'SHELL_ENV_CONTRIBUTION_INVALID',
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
values[key] = value
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return Object.freeze(Object.fromEntries(Object.entries(values).sort(([left], [right]) => left.localeCompare(right))))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// TODO(bash-env-list-builtins): Include registry-owned built-ins before diagnostics,
|
|
204
|
+
// prompt, or UI code treats list() as an exhaustive environment catalog.
|
|
205
|
+
/**
|
|
206
|
+
* Enumerate plugin-contributed variables without executing their resolvers.
|
|
207
|
+
* @returns declarations sorted by environment variable name.
|
|
208
|
+
*/
|
|
209
|
+
list(): BashEnvVariableInfo[] {
|
|
210
|
+
return [...this.contributors.values()]
|
|
211
|
+
.flatMap(contributor => Object.entries(contributor.variables).map(([key, variable]) => ({
|
|
212
|
+
contributor: contributor.name,
|
|
213
|
+
description: variable.description,
|
|
214
|
+
key: key as DshEnvironmentKey,
|
|
215
|
+
})))
|
|
216
|
+
.sort((left, right) => left.key.localeCompare(right.key))
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Load the shell-env plugin: register the `ctx.shellEnv` registry service.
|
|
222
|
+
* @param ctx - Cordis context that owns the service and registrations.
|
|
223
|
+
* @param config - home-directory configuration for the built-in variables.
|
|
224
|
+
*/
|
|
225
|
+
export function apply(ctx: Context, config: Config = {}): void {
|
|
226
|
+
new ShellEnvRegistry(ctx, config)
|
|
227
|
+
}
|