@trim21/personal-pi-extensions 0.1.20261019144232 → 0.1.20261028151816

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 CHANGED
@@ -104,6 +104,8 @@
104
104
  "enabledTools": [{ "tools": ["web_search"], "models": ["glm-*"] }],
105
105
  // 只进 codemode、不交给模型的工具(须声明结构化输出才会生效)
106
106
  "codemodeOnlyTools": [{ "tools": ["aft_*"], "models": ["deepseek-*"] }],
107
+ // bash 命令的额外环境变量:沙箱内外都生效,同名变量覆盖基础值
108
+ "shell": { "env": { "GIT_EDITOR": "true", "GIT_SEQUENCE_EDITOR": "true" } },
107
109
  },
108
110
  }
109
111
  ```
@@ -121,6 +123,11 @@
121
123
  有些工具由代码固定为 codemode-only(例如 gh-readonly 那一组,见
122
124
  [GitHub 只读工具](#github-只读工具)),不需要这条配置;`disabledTools` 对它们同样生效。
123
125
 
126
+ `shell.env` 是 bash 工具的额外环境变量表,沙箱内执行与不经沙箱的本地执行都注入,同名
127
+ 变量以它为准(可以覆盖沙箱默认的 `HOME` / `PATH` / `LANG` 等;`bash -lc` 之后 profile
128
+ 仍可能再改动)。典型用法是让命令不要拉起编辑器。它只影响 bash 工具,LSP、`gh`、codemode
129
+ 脚本等其它子进程的环境不变。
130
+
124
131
  **判定时机是每个会话启动**:pi 在启动 / `/new` / `resume` / `/fork` / `/reload` 时重建
125
132
  扩展,注册就发生在 `session_start` 里(模型在扩展加载期读不到),因此新会话按自己的
126
133
  模型重新判定;**同一会话内 `/model` 切换不会改变工具集合**,换模型请开新会话。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.20261019144232",
3
+ "version": "0.1.20261028151816",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
package/src/bwrap/exec.ts CHANGED
@@ -44,11 +44,14 @@ export interface BwrapInvocation {
44
44
  /**
45
45
  * 组装一次 bwrap 调用。实际执行(`execInvocation`)与调试打印共用这里,
46
46
  * 保证 `--print-args` 输出的命令行与真正跑的那条完全一致。
47
+ *
48
+ * `extraEnv` 是配置注入的额外环境变量:合并进这份干净环境,同名时覆盖基础值。
47
49
  */
48
50
  export async function buildBwrapInvocation(
49
51
  resolved: ResolvedBwrap,
50
52
  workspace: string,
51
53
  command: string,
54
+ extraEnv?: Readonly<Record<string, string>>,
52
55
  ): Promise<BwrapInvocation> {
53
56
  // 干净环境:不继承父进程 env/PATH,由 bash -lc 从 /etc/profile 与用户 profile 重建
54
57
  const home = process.env.HOME;
@@ -77,6 +80,7 @@ export async function buildBwrapInvocation(
77
80
  LANG: "C.UTF-8",
78
81
  // 基础 PATH:profile 加载阶段(设置 PATH 前)需要系统命令(如 id),由 profile 随后覆盖;不含 sbin
79
82
  PATH: "/usr/local/bin:/usr/bin:/bin",
83
+ ...extraEnv,
80
84
  },
81
85
  needsNetworkStack: resolved.network === "limited",
82
86
  };
@@ -219,11 +223,13 @@ export function execInvocation(
219
223
  /**
220
224
  * @param workspace session 工作区:writablePaths 的 "." 与 PROTECTED_DIRS 都基于它解析,
221
225
  * 与当次命令的 cwd(仅作为进程执行目录)解耦,避免 workdir 参数漂移可写边界。
226
+ * @param extraEnv 配置注入的额外环境变量,覆盖沙箱环境里的同名基础值。
222
227
  */
223
228
  export function createBwrapBashOperations(
224
229
  resolved: ResolvedBwrap,
225
230
  workspace: string,
226
231
  networkStack?: NetworkStack,
232
+ extraEnv?: Readonly<Record<string, string>>,
227
233
  ): BashOperations {
228
234
  return {
229
235
  async exec(command, cwd, { onData, signal, timeout }) {
@@ -233,7 +239,7 @@ export function createBwrapBashOperations(
233
239
  // 已中断(signal.reason 是 name=AbortError 的 DOMException):直接抛,不再执行
234
240
  signal?.throwIfAborted();
235
241
 
236
- const invocation = await buildBwrapInvocation(resolved, workspace, command);
242
+ const invocation = await buildBwrapInvocation(resolved, workspace, command, extraEnv);
237
243
  return execInvocation(invocation, {
238
244
  cwd,
239
245
  holderPid: networkStack?.holderPid,
@@ -431,10 +431,17 @@ export class BwrapRuntime {
431
431
  * sandbox.json 加载(主会话入口的现状行为)。
432
432
  */
433
433
  private readonly config: BwrapConfig | undefined;
434
+ /** 注入给每条 bash 命令的额外环境变量(`personalExtensions.shell.env`),沙箱内外都生效。 */
435
+ private readonly env: Readonly<Record<string, string>>;
434
436
 
435
- constructor(policy: RequestPolicy, config?: BwrapConfig) {
437
+ constructor(
438
+ policy: RequestPolicy,
439
+ config?: BwrapConfig,
440
+ env: Readonly<Record<string, string>> = {},
441
+ ) {
436
442
  this.policy = policy;
437
443
  this.config = config;
444
+ this.env = env;
438
445
  }
439
446
 
440
447
  setup(pi: ExtensionAPI): void {
@@ -635,6 +642,7 @@ export class BwrapRuntime {
635
642
  commandCwd: execCwd,
636
643
  command: request.command,
637
644
  unsandboxed: local,
645
+ env: this.env,
638
646
  onData: (data) => {
639
647
  output.append(data);
640
648
  emitUpdate();
@@ -1108,10 +1116,13 @@ export class BwrapRuntime {
1108
1116
  * config 为完整配置(completeBwrapConfig 的产物):加载配置与创建解耦,传入后不再
1109
1117
  * 读盘,且沙箱固定(不注册 /bwrap-* 命令、非沙盒请求直接拒绝)。缺省从全局/项目
1110
1118
  * sandbox.json 加载。
1119
+ * env 为注入给每条命令的额外环境变量(`personalExtensions.shell.env`):由入口显式
1120
+ * 传入,缺省不注入——测试里创建 runtime 因此读不到开发机的 settings.json。
1111
1121
  */
1112
1122
  export function createBwrapRuntime(
1113
1123
  policy: RequestPolicy = createRequestPolicy(),
1114
1124
  config?: BwrapConfig,
1125
+ env?: Readonly<Record<string, string>>,
1115
1126
  ): BwrapRuntime {
1116
- return new BwrapRuntime(policy, config);
1127
+ return new BwrapRuntime(policy, config, env);
1117
1128
  }
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { existsSync } from "node:fs";
14
14
 
15
- import { createLocalBashOperations } from "@earendil-works/pi-coding-agent";
15
+ import { type BashOperations, createLocalBashOperations } from "@earendil-works/pi-coding-agent";
16
16
 
17
17
  import { expandHome } from "../lib/path.js";
18
18
  import {
@@ -56,6 +56,11 @@ export interface SandboxRunOptions {
56
56
  timeout?: number;
57
57
  /** 调用方已决定不经沙箱(审批通过的全权限、Windows)。fs 与 network 均 allow-all 时无需显式设置。 */
58
58
  unsandboxed?: boolean;
59
+ /**
60
+ * 额外环境变量(`personalExtensions.shell.env`):沙箱路径合并进沙箱环境并覆盖同名基础值,
61
+ * 本地路径以父进程环境为基底合并——两条执行方式都要注入。
62
+ */
63
+ env?: Readonly<Record<string, string>>;
59
64
  /** 网络栈子进程输出转发,仅诊断用(默认丢弃)。 */
60
65
  log?: NetworkStackLog;
61
66
  /** 网络栈就绪回调:取 holder pid 与 mihomo 配置路径手动排查。 */
@@ -106,6 +111,20 @@ export function loadSandboxConfig(input: SandboxConfigInput): ResolvedBwrap {
106
111
  return resolveSandboxPaths(resolveBwrap(configured), workspace);
107
112
  }
108
113
 
114
+ /** 本地执行路径注入 env:没配置时保持 pi 的默认环境(含它补的 bin 目录)。 */
115
+ function withExtraEnv(
116
+ operations: BashOperations,
117
+ env: Readonly<Record<string, string>> | undefined,
118
+ ): BashOperations {
119
+ if (env === undefined || Object.keys(env).length === 0) {
120
+ return operations;
121
+ }
122
+ return {
123
+ exec: (command, cwd, options) =>
124
+ operations.exec(command, cwd, { ...options, env: { ...process.env, ...env } }),
125
+ };
126
+ }
127
+
109
128
  /**
110
129
  * 在 resolved 描述的沙箱里执行一条命令;network limited 模式下现建现停网络栈。
111
130
  * 超时与取消的错误语义由底层 operations.exec 抛出(TimeoutError / AbortError)。
@@ -126,8 +145,8 @@ export async function runInSandbox(
126
145
  options.onNetworkStack?.(stack);
127
146
  }
128
147
  const operations = local
129
- ? createLocalBashOperations()
130
- : createBwrapBashOperations(resolved, workspace, stack);
148
+ ? withExtraEnv(createLocalBashOperations(), options.env)
149
+ : createBwrapBashOperations(resolved, workspace, stack, options.env);
131
150
  const { exitCode } = await operations.exec(options.command, commandCwd, {
132
151
  onData: options.onData,
133
152
  signal: options.signal,
@@ -192,12 +211,15 @@ export interface SandboxPreview {
192
211
  */
193
212
  export async function previewSandboxCommand(
194
213
  resolved: ResolvedBwrap,
195
- options: Pick<SandboxRunOptions, "workspace" | "command" | "commandCwd" | "unsandboxed"> & {
214
+ options: Pick<
215
+ SandboxRunOptions,
216
+ "workspace" | "command" | "commandCwd" | "unsandboxed" | "env"
217
+ > & {
196
218
  holderPid?: number;
197
219
  },
198
220
  ): Promise<SandboxPreview> {
199
221
  const workspace = expandHome(options.workspace);
200
- const invocation = await buildBwrapInvocation(resolved, workspace, options.command);
222
+ const invocation = await buildBwrapInvocation(resolved, workspace, options.command, options.env);
201
223
  if (!invocation.needsNetworkStack || options.unsandboxed === true) {
202
224
  return { argv: invocationArgv(invocation), env: invocation.env, needsNetworkStack: false };
203
225
  }
@@ -5,6 +5,7 @@ import type { LspManager } from "../lib/lsp/lsp.js";
5
5
  import { createRequestPolicy, type RequestPolicy } from "../lib/request-policy.js";
6
6
  import type { ToolBus } from "../lib/tool-bus.js";
7
7
  import { registerToolsOnSessionStart } from "../lib/tool-registration.js";
8
+ import { readToolsConfig } from "../lib/tools-config.js";
8
9
  import { createClaudeCodeFileTools } from "./files.js";
9
10
  import { registerSearchTools } from "./search.js";
10
11
  import { registerSessionTools } from "./session-tools.js";
@@ -29,7 +30,8 @@ export interface ClaudeCodeToolsetOptions {
29
30
  /** claude-code 风格工具集的共享部件:入口与独立默认导出都从这里取。 */
30
31
  export function createClaudeCodeTools(pi: ExtensionAPI, options?: ClaudeCodeToolsetOptions) {
31
32
  const policy = options?.policy ?? createRequestPolicy(pi.events);
32
- const runtime = options?.runtime ?? createBwrapRuntime(policy);
33
+ const runtime =
34
+ options?.runtime ?? createBwrapRuntime(policy, undefined, readToolsConfig().shellEnv);
33
35
  // 独立入口(不经 src/index.ts 的共享服务)要自己接上 bwrap 的会话钩子与 /bwrap* 命令。
34
36
  if (options?.runtime === undefined) {
35
37
  runtime.setup(pi);
@@ -21,6 +21,7 @@ import {
21
21
  BASH_MAX_TIMEOUT_MS,
22
22
  bashStructuredSchema,
23
23
  spilledOutput,
24
+ systemReminder,
24
25
  } from "../lib/bash-tool.js";
25
26
  import { resolveWorkdir } from "../lib/path.js";
26
27
  import { defineStructuredTool, type ToolBus } from "../lib/tool-bus.js";
@@ -163,7 +164,9 @@ export function registerShellTools(bus: ToolBus, pi: ExtensionAPI, runtime: Bwra
163
164
  if (error.kind === "aborted") {
164
165
  // 用户取消:直接返回已捕获的输出,不抛错;时长只算命令真正运行的时间,
165
166
  // 不含审批弹窗等 UI 交互
166
- const status = `Command aborted by user after ${formatElapsedSeconds(error.elapsedMs)}`;
167
+ const status = systemReminder(
168
+ `Command aborted by user after ${formatElapsedSeconds(error.elapsedMs)}`,
169
+ );
167
170
  return {
168
171
  content: [
169
172
  { type: "text" as const, text: text ? `${text}\n\n${status}` : status },
@@ -183,9 +186,8 @@ export function registerShellTools(bus: ToolBus, pi: ExtensionAPI, runtime: Bwra
183
186
  },
184
187
  };
185
188
  }
186
- const full = text
187
- ? `${text}\n\nCommand timed out after ${timeout} milliseconds`
188
- : `Command timed out after ${timeout} milliseconds`;
189
+ const status = systemReminder(`Command timed out after ${timeout} milliseconds`);
190
+ const full = text ? `${text}\n\n${status}` : status;
189
191
  return {
190
192
  content: [
191
193
  { type: "text" as const, text: full },
package/src/index.ts CHANGED
@@ -36,7 +36,7 @@ export default function personalExtensions(pi: ExtensionAPI): void {
36
36
  const registration = createToolRegistration(pi);
37
37
  // 共享服务要在 registration 之后创建:LSP manager 的 session_start handler 得
38
38
  // 排在「记录本会话模型」的 handler 之后。
39
- const services = createToolServices(pi);
39
+ const services = createToolServices(pi, { shellEnv: registration.config.shellEnv });
40
40
 
41
41
  // 与文件工具集无关的模块(各自在 create 里注册自己的会话钩子与提示)。
42
42
  const modules: { name: string; module: ToolModule }[] = [];
@@ -14,6 +14,11 @@ import { Type } from "typebox";
14
14
  export const BASH_DEFAULT_TIMEOUT_MS = 120_000;
15
15
  export const BASH_MAX_TIMEOUT_MS = 7_200_000;
16
16
 
17
+ /** 工具追加的状态行(超时、用户取消)统一包成系统提醒,避免被当成命令输出。 */
18
+ export function systemReminder(text: string): string {
19
+ return `<system-reminder>\n${text}\n</system-reminder>`;
20
+ }
21
+
17
22
  /**
18
23
  * `Bash` 的结构化结果:只有退出码与完整输出——命令非零退出不是失败,所以载荷里没有成败
19
24
  * 标志,脚本直接读 `exitCode` 分支;超时/中止时 `exitCode` 为 `null`(原因在模型侧文本里)。
@@ -34,11 +34,13 @@ export interface ToolServices {
34
34
  export interface ToolServicesOptions extends LspServiceOptions {
35
35
  /** 固定沙箱配置(子代理用);不传则跟随用户配置与 /bwrap-* 命令。 */
36
36
  sandbox?: BwrapConfig;
37
+ /** 注入给 bash 命令的额外环境变量(`personalExtensions.shell.env`)。 */
38
+ shellEnv?: Readonly<Record<string, string>>;
37
39
  }
38
40
 
39
41
  export function createToolServices(pi: ExtensionAPI, options?: ToolServicesOptions): ToolServices {
40
42
  const policy = createRequestPolicy(pi.events);
41
- const runtime = createBwrapRuntime(policy, options?.sandbox);
43
+ const runtime = createBwrapRuntime(policy, options?.sandbox, options?.shellEnv);
42
44
  // 注册 /bwrap* 命令、沙箱系统提示与 session 生命周期钩子;固定沙箱
43
45
  // (子代理)不注册命令,见 BwrapRuntime.setup。
44
46
  runtime.setup(pi);
@@ -8,7 +8,8 @@
8
8
  * "fileIoByModel": [{ "models": ["glm-*"], "fileIo": "opencode" }],
9
9
  * "disabledTools": ["talk-*", { "tools": ["web_*"], "models": ["gpt-*"] }],
10
10
  * "enabledTools": [{ "tools": ["web_search"], "models": ["glm-*"] }],
11
- * "codemodeOnlyTools": [{ "tools": ["read-github-*"], "models": ["glm-*"] }]
11
+ * "codemodeOnlyTools": [{ "tools": ["read-github-*"], "models": ["glm-*"] }],
12
+ * "shell": { "env": { "GIT_EDITOR": "true", "GIT_SEQUENCE_EDITOR": "true" } }
12
13
  * }
13
14
  * }
14
15
  * ```
@@ -45,6 +46,9 @@ const toolRuleSchema = Type.Object({
45
46
  models: Type.Optional(Type.Array(Type.String())),
46
47
  });
47
48
 
49
+ /** `shell.env`:环境变量名 → 值,注入给 bash 工具执行的命令。 */
50
+ const shellEnvSchema = Type.Record(Type.String(), Type.String());
51
+
48
52
  // ── 类型 ─────────────────────────────────────────────────────────────────────
49
53
 
50
54
  export type FileIoToolset = "claude-code" | "opencode";
@@ -71,6 +75,8 @@ export interface ToolsConfig {
71
75
  enabledTools: readonly ToolPatternRule[];
72
76
  /** 命中且声明了 `structuredSchema` 的工具只进 codemode、不交给 pi。 */
73
77
  codemodeOnlyTools: readonly ToolPatternRule[];
78
+ /** `shell.env`:注入给 bash 命令的额外环境变量(沙箱内外都生效)。 */
79
+ shellEnv: Readonly<Record<string, string>>;
74
80
  /** 解析阶段发现的问题,由调用方在能提示用户时上报。 */
75
81
  warnings: readonly string[];
76
82
  }
@@ -163,6 +169,47 @@ function parseToolRules(value: unknown, fieldPath: string, warnings: string[]):
163
169
  return rules;
164
170
  }
165
171
 
172
+ /** 解析 `shell.env`:非法条目逐键告警并跳过,其余键照常生效。 */
173
+ function parseShellEnv(value: unknown, field: string, warnings: string[]): Record<string, string> {
174
+ if (value === undefined) {
175
+ return {};
176
+ }
177
+ if (Value.Check(shellEnvSchema, value)) {
178
+ return { ...value };
179
+ }
180
+ if (!isRecord(value)) {
181
+ warnings.push(`${field}: expected an object mapping names to string values, ignored`);
182
+ return {};
183
+ }
184
+
185
+ const env: Record<string, string> = {};
186
+ for (const [key, entry] of Object.entries(value)) {
187
+ if (typeof entry === "string") {
188
+ env[key] = entry;
189
+ continue;
190
+ }
191
+ warnings.push(
192
+ `${field}.${key}: invalid value ${JSON.stringify(entry)} ignored (expected a string)`,
193
+ );
194
+ }
195
+ return env;
196
+ }
197
+
198
+ function parseShellSection(
199
+ value: unknown,
200
+ field: string,
201
+ warnings: string[],
202
+ ): Record<string, string> {
203
+ if (value === undefined) {
204
+ return {};
205
+ }
206
+ if (!isRecord(value)) {
207
+ warnings.push(`${field}: expected an object, ignored`);
208
+ return {};
209
+ }
210
+ return parseShellEnv(value.env, `${field}.env`, warnings);
211
+ }
212
+
166
213
  /** 解析 `personalExtensions` section(纯函数,便于测试)。 */
167
214
  export function parseToolsConfig(section: unknown, source = "personalExtensions"): ToolsConfig {
168
215
  const warnings: string[] = [];
@@ -174,6 +221,7 @@ export function parseToolsConfig(section: unknown, source = "personalExtensions"
174
221
  disabledTools: [],
175
222
  enabledTools: [],
176
223
  codemodeOnlyTools: [],
224
+ shellEnv: {},
177
225
  warnings,
178
226
  };
179
227
  }
@@ -185,6 +233,7 @@ export function parseToolsConfig(section: unknown, source = "personalExtensions"
185
233
  disabledTools: [],
186
234
  enabledTools: [],
187
235
  codemodeOnlyTools: [],
236
+ shellEnv: {},
188
237
  warnings,
189
238
  };
190
239
  }
@@ -199,6 +248,7 @@ export function parseToolsConfig(section: unknown, source = "personalExtensions"
199
248
  `${source}.codemodeOnlyTools`,
200
249
  warnings,
201
250
  ),
251
+ shellEnv: parseShellSection(section.shell, `${source}.shell`, warnings),
202
252
  warnings,
203
253
  };
204
254
  }
@@ -16,11 +16,13 @@ import {
16
16
  BASH_MAX_TIMEOUT_MS,
17
17
  bashStructuredSchema,
18
18
  spilledOutput,
19
+ systemReminder,
19
20
  } from "../lib/bash-tool.js";
20
21
  import { resolveWorkdir } from "../lib/path.js";
21
22
  import { createRequestPolicy } from "../lib/request-policy.js";
22
23
  import { defineStructuredTool, type ToolBus } from "../lib/tool-bus.js";
23
24
  import { registerToolsOnSessionStart } from "../lib/tool-registration.js";
25
+ import { readToolsConfig } from "../lib/tools-config.js";
24
26
 
25
27
  /** 对齐上游 opencode 的截断提示文案(tools/BashTool/bash.ts)。 */
26
28
  const CAPTURE_TRUNCATED_NOTICE = "[output capture truncated at the in-memory safety limit]";
@@ -51,7 +53,11 @@ function appendTruncationNotice(
51
53
  */
52
54
  export default function opencodeBash(
53
55
  pi: ExtensionAPI,
54
- runtime: BwrapRuntime = createBwrapRuntime(createRequestPolicy(pi.events)),
56
+ runtime: BwrapRuntime = createBwrapRuntime(
57
+ createRequestPolicy(pi.events),
58
+ undefined,
59
+ readToolsConfig().shellEnv,
60
+ ),
55
61
  ): void {
56
62
  registerToolsOnSessionStart(pi, (bus) => registerBashTool(bus, pi, runtime));
57
63
  }
@@ -127,10 +133,11 @@ export function registerBashTool(bus: ToolBus, pi: ExtensionAPI, runtime: BwrapR
127
133
  error.partial.truncation,
128
134
  error.partial.fullOutputPath,
129
135
  );
130
- const status =
136
+ const status = systemReminder(
131
137
  error.kind === "timeout"
132
138
  ? `Command exceeded timeout of ${timeout} ms. Retry with a larger timeout if the command is expected to take longer.`
133
- : `Command aborted by user after ${formatElapsedSeconds(error.elapsedMs)}`;
139
+ : `Command aborted by user after ${formatElapsedSeconds(error.elapsedMs)}`,
140
+ );
134
141
  const full = text ? `${text}\n\n${status}` : status;
135
142
  // 对齐上游 opencode:超时与中断都不抛错,输出与状态文本一起返回;
136
143
  // 超时可能是沙箱的网络限制导致的,附加沙箱状态(用户中断与沙箱无关)
@@ -18,6 +18,7 @@ import type { LspManager } from "../lib/lsp/lsp.js";
18
18
  import { createRequestPolicy, type RequestPolicy } from "../lib/request-policy.js";
19
19
  import type { ToolBus } from "../lib/tool-bus.js";
20
20
  import { registerToolsOnSessionStart } from "../lib/tool-registration.js";
21
+ import { readToolsConfig } from "../lib/tools-config.js";
21
22
  import { registerBashTool } from "./bash.js";
22
23
  import { createOpencodeFileTools } from "./files.js";
23
24
  import { registerGlobTool } from "./glob.js";
@@ -36,7 +37,8 @@ export interface OpencodeToolsetOptions {
36
37
  export function createOpencodeTools(pi: ExtensionAPI, options?: OpencodeToolsetOptions) {
37
38
  // 非沙盒请求策略由本工具集创建,注入文件工具与 bash runtime 共享同一份。
38
39
  const policy = options?.policy ?? createRequestPolicy(pi.events);
39
- const runtime = options?.runtime ?? createBwrapRuntime(policy);
40
+ const runtime =
41
+ options?.runtime ?? createBwrapRuntime(policy, undefined, readToolsConfig().shellEnv);
40
42
  // 独立入口(不经 src/index.ts 的共享服务)要自己接上 bwrap 的会话钩子与 /bwrap* 命令。
41
43
  if (options?.runtime === undefined) {
42
44
  runtime.setup(pi);
@@ -229,7 +229,10 @@ export function subagentToolsExtension(
229
229
  ): ExtensionFactory {
230
230
  return (pi) => {
231
231
  const registration = createToolRegistration(pi);
232
- const services = createToolServices(pi, { sandbox: agent.sandbox ?? SUBAGENT_DEFAULT_SANDBOX });
232
+ const services = createToolServices(pi, {
233
+ sandbox: agent.sandbox ?? SUBAGENT_DEFAULT_SANDBOX,
234
+ shellEnv: registration.config.shellEnv,
235
+ });
233
236
  const kind = toolsetsForToolNames(tools);
234
237
  if (!kind) {
235
238
  return;