@deepseek-ai/dsh-tool-bash 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 CHANGED
@@ -111,8 +111,8 @@
111
111
  en: 2d4f2c8605eccab3
112
112
  zh: 67f1f0218f73c6bf
113
113
  /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/what-the-model-sees:
114
- en: d6d7068e23fc1b93
115
- zh: 515e8aa586415179
114
+ en: 1772eedea1c1ee6a
115
+ zh: a0d77bdd515cb517
116
116
  /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect:
117
117
  en: a3a78ef476ec5e56
118
118
  zh: dd2c8ad0f69e8ff1
package/README.md CHANGED
@@ -196,7 +196,7 @@ Append-only; newly visible content follows the reusable request prefix and does
196
196
 
197
197
  #### What the model sees
198
198
 
199
- Validation and policy failures are normalized as `Error: <message>`. This package's stable messages are `invalid command: expected a non-empty string`, `invalid description: expected a non-empty string`, `invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`.
199
+ Validation and policy failures are normalized as `Error: <message>`. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled.
200
200
 
201
201
  #### Token effect
202
202
 
package/README.zh.md CHANGED
@@ -196,7 +196,7 @@ renderer 输出依数据而定的 stdout 尾部,再输出可选的 `[stderr]`
196
196
 
197
197
  #### 模型看到什么
198
198
 
199
- 验证与策略失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid command: expected a non-empty string`、`invalid description: expected a non-empty string`、`invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。
199
+ 验证与策略失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。
200
200
 
201
201
  #### Token 影响
202
202
 
package/lib/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { isAbsolute, sep } from "node:path";
3
- import { TOOL_ABORTED, defineTool } from "@deepseek-ai/dsh-tools";
3
+ import { TOOL_ABORTED, ToolArgsError, ToolContextUnavailableError, defineTool } from "@deepseek-ai/dsh-tools";
4
4
  import { HarnessError } from "@deepseek-ai/dsh-llm";
5
- import { ESCALATION_TARGETS, approveEscalation, escalationHintMarker, sandboxDenialMarker, sandboxPermissionsDescription, validateEscalationArgs } from "@deepseek-ai/dsh-sandbox";
5
+ import { JobError } from "@deepseek-ai/dsh-jobs";
6
+ import { ESCALATION_TARGETS, SandboxEscalationError, approveEscalation, escalationHintMarker, sandboxDenialMarker, sandboxPermissionsDescription, validateEscalationArgs } from "@deepseek-ai/dsh-sandbox";
7
+ import { subprocessSpawnFailure } from "@deepseek-ai/dsh-subprocess";
6
8
  import { DSH_ENV_PREFIX, parseExitStatus } from "@deepseek-ai/dsh-shell";
7
9
  //#region lib/types/background.js
8
10
  /**
@@ -95,11 +97,13 @@ function ringDelta(chunks) {
95
97
  * Adapt asynchronous shell preparation after job admission without exposing a partial process.
96
98
  * @param start - starts the process with job-owned cancellation.
97
99
  * @param outcome - projects the settled process into the job outcome.
98
- * @returns synchronous job hooks whose completion includes preparation and process settlement.
100
+ * @returns synchronous job hooks whose completion includes preparation and process settlement,
101
+ * and the original error of a failed preparation for a caller that reports it.
99
102
  */
100
103
  function processJob(start, outcome) {
101
104
  const controller = new AbortController();
102
105
  let process;
106
+ let failure;
103
107
  return {
104
108
  cancel: (reason) => {
105
109
  if (controller.signal.aborted) return;
@@ -116,12 +120,15 @@ function processJob(start, outcome) {
116
120
  }
117
121
  return outcome(process);
118
122
  } catch (error) {
123
+ const killed = controller.signal.aborted && process === void 0;
124
+ if (!killed) failure = { error };
119
125
  return {
120
- status: controller.signal.aborted && process === void 0 ? "killed" : "failed",
126
+ status: killed ? "killed" : "failed",
121
127
  detail: error instanceof Error ? error.message : String(error)
122
128
  };
123
129
  }
124
- })()
130
+ })(),
131
+ failure: () => failure
125
132
  };
126
133
  }
127
134
  //#endregion
@@ -233,9 +240,9 @@ const Config = z.object({
233
240
  promoteOnTimeout: z.boolean().default(true)
234
241
  });
235
242
  function validateBashArgs(args, effectiveMode) {
236
- if (args.command.trim().length === 0) throw new Error("invalid command: expected a non-empty string");
237
- if (args.description.trim().length === 0) throw new Error("invalid description: expected a non-empty string");
238
- if (args.timeoutMs !== void 0 && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) throw new Error(`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`);
243
+ if (args.command.trim().length === 0) throw new ToolArgsError(["invalid command: expected a non-empty string"]);
244
+ if (args.description.trim().length === 0) throw new ToolArgsError(["invalid description: expected a non-empty string"]);
245
+ if (args.timeoutMs !== void 0 && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`]);
239
246
  if (args.sandbox_permissions !== void 0 && args.sandbox_permissions === effectiveMode) return;
240
247
  const justification = args.sandbox_permissions === void 0 && args.justification?.trim() === "" ? void 0 : args.justification;
241
248
  validateEscalationArgs(args.sandbox_permissions, justification);
@@ -321,6 +328,16 @@ function toolAborted() {
321
328
  error.name = "AbortError";
322
329
  return error;
323
330
  }
331
+ /**
332
+ * Report a launch or preparation rejection as this tool's failure. This
333
+ * call's cancellation reason stays as thrown so the registry records it as
334
+ * aborted; a platform spawn error is classified as a subprocess spawn failure
335
+ * with the original as `cause`; any other value, including a coded error,
336
+ * keeps its own identity.
337
+ */
338
+ function launchFailure(error, signal) {
339
+ return signal.aborted && error === signal.reason ? error : subprocessSpawnFailure(error, "bash");
340
+ }
324
341
  /** Canonical background-handle properties shared by the bash output union. */
325
342
  const BACKGROUND_OUTPUT_PROPERTIES = {
326
343
  kind: {
@@ -358,7 +375,7 @@ function apply(ctx, config = {}) {
358
375
  * advertises confinement, so a split composition fails at tool-plugin load.
359
376
  */
360
377
  const approveBashEscalation = (mode, justification, exec, standingPolicy) => {
361
- if (escalationModes.length === 0) throw new Error("sandbox_permissions is not available in this composition (no sandboxing executor to escalate)");
378
+ if (escalationModes.length === 0) throw new SandboxEscalationError("sandbox_permissions is not available in this composition (no sandboxing executor to escalate)", "SANDBOX_ESCALATION_UNAVAILABLE");
362
379
  const effectiveMode = standingPolicy.mode;
363
380
  return approveEscalation({
364
381
  requestedMode: mode,
@@ -390,6 +407,7 @@ function apply(ctx, config = {}) {
390
407
  const startJob = (registry, args, exec, spec) => {
391
408
  let proc;
392
409
  let stopped;
410
+ let hooks;
393
411
  return {
394
412
  id: registry.start({
395
413
  kind: "bash",
@@ -401,24 +419,26 @@ function apply(ctx, config = {}) {
401
419
  ...exec.agent ? { owner: exec.agent.id } : {},
402
420
  output: processSources(() => proc),
403
421
  run: () => {
404
- const hooks = processJob(async (signal) => {
422
+ const job = processJob(async (signal) => {
405
423
  proc = await ctx.shell.execute({
406
424
  ...spec,
407
425
  signal
408
426
  });
409
427
  return proc;
410
428
  }, (started) => processOutcome(started, escalationModes));
429
+ hooks = job;
411
430
  return {
412
- done: hooks.done,
431
+ done: job.done,
413
432
  cancel: (reason) => {
414
433
  stopped = reason;
415
- hooks.cancel(reason);
434
+ job.cancel(reason);
416
435
  }
417
436
  };
418
437
  }
419
438
  }),
420
439
  process: () => proc,
421
- stopped: () => stopped
440
+ stopped: () => stopped,
441
+ failure: () => hooks?.failure()
422
442
  };
423
443
  };
424
444
  /** Wait on a registered foreground command until it settles or the timeout passes. */
@@ -480,8 +500,13 @@ function apply(ctx, config = {}) {
480
500
  }
481
501
  registry.remove(attached.id, owner);
482
502
  const process = attached.process();
483
- if (process === void 0) throw new Error(view.detail);
484
- const result = await process.result();
503
+ if (process === void 0) {
504
+ const failure = attached.failure();
505
+ throw failure === void 0 ? new Error(view.detail) : launchFailure(failure.error, exec.signal);
506
+ }
507
+ const result = await process.result().catch((error) => {
508
+ throw launchFailure(error, exec.signal);
509
+ });
485
510
  const stopped = attached.stopped();
486
511
  return {
487
512
  kind: "foreground",
@@ -671,8 +696,8 @@ function apply(ctx, config = {}) {
671
696
  ...policy !== void 0 ? { sandboxPolicy: policy } : {}
672
697
  };
673
698
  if (args.run_in_background === true) {
674
- if (!backgroundEnabled) throw new Error("run_in_background is disabled for this deployment (enableRunInBackground: false)");
675
- if (jobs === void 0) throw new Error("background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs");
699
+ if (!backgroundEnabled) throw new JobError("run_in_background is disabled for this deployment (enableRunInBackground: false)", "JOB_BACKGROUND_DISABLED");
700
+ if (jobs === void 0) throw new ToolContextUnavailableError("background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs");
676
701
  if (exec.signal.aborted) throw toolAborted();
677
702
  const spec = ctx.shell.resolve({
678
703
  ...request,
@@ -701,7 +726,12 @@ function apply(ctx, config = {}) {
701
726
  ...request,
702
727
  signal: exec.signal
703
728
  });
704
- const result = await (await ctx.shell.execute(spec)).result();
729
+ let result;
730
+ try {
731
+ result = await (await ctx.shell.execute(spec)).result();
732
+ } catch (error) {
733
+ throw launchFailure(error, exec.signal);
734
+ }
705
735
  if (result.aborted) throw toolAborted();
706
736
  return {
707
737
  kind: "foreground",
@@ -8,6 +8,17 @@
8
8
  import type { SandboxMode } from '@deepseek-ai/dsh-sandbox';
9
9
  import type { ShellProcess } from '@deepseek-ai/dsh-shell';
10
10
  import type { JobChunk, JobHooks, JobOutcome, JobOutputSource } from '@deepseek-ai/dsh-jobs';
11
+ /** Job hooks plus the original error of a job that failed before its process produced an outcome. */
12
+ export interface ProcessJobHooks extends JobHooks {
13
+ /**
14
+ * The error that ended a `failed` job, kept with its own class and code;
15
+ * undefined while the job runs and for a completed or killed job.
16
+ * @returns the original failure, boxed so any thrown value is preserved.
17
+ */
18
+ failure(): {
19
+ error: unknown;
20
+ } | undefined;
21
+ }
11
22
  /**
12
23
  * Map a settled background process onto the generic job-outcome vocabulary:
13
24
  * `killed` stays `killed` (detail: the signal when one is known), everything
@@ -44,7 +55,8 @@ export declare function ringDelta(chunks: readonly JobChunk[]): string;
44
55
  * Adapt asynchronous shell preparation after job admission without exposing a partial process.
45
56
  * @param start - starts the process with job-owned cancellation.
46
57
  * @param outcome - projects the settled process into the job outcome.
47
- * @returns synchronous job hooks whose completion includes preparation and process settlement.
58
+ * @returns synchronous job hooks whose completion includes preparation and process settlement,
59
+ * and the original error of a failed preparation for a caller that reports it.
48
60
  */
49
- export declare function processJob(start: (signal: AbortSignal) => Promise<ShellProcess>, outcome: (process: ShellProcess) => JobOutcome): JobHooks;
61
+ export declare function processJob(start: (signal: AbortSignal) => Promise<ShellProcess>, outcome: (process: ShellProcess) => JobOutcome): ProcessJobHooks;
50
62
  //# sourceMappingURL=background.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/background.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D,OAAO,KAAK,EAAE,YA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CAAA;QAC/C,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACtC,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAChG,CAAC;AAED;;;;;GAKG;AACH,OAAO,EAAE,eAAe,EAAyB,MAAM,wBAAwB,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-tool-bash",
3
3
  "description": "Model-facing bash tool with optional generic background-job and sandbox-escalation support",
4
- "version": "0.2.2-rc.1",
4
+ "version": "0.2.2-rc.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -25,51 +25,56 @@
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
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
33
- "@deepseek-ai/dsh-shell": "0.2.2-rc.1",
34
- "@deepseek-ai/dsh-shell-env": "0.2.2-rc.1",
35
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
36
- "@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
37
- "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
38
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
39
- "@deepseek-ai/dsh-jobs": "0.2.2-rc.1",
40
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
41
- "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
35
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
36
+ "@deepseek-ai/dsh-shell": "0.2.2-rc.3",
37
+ "@deepseek-ai/dsh-shell-env": "0.2.2-rc.3",
38
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
39
+ "@deepseek-ai/dsh-sandbox": "0.2.2-rc.3",
40
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.3",
41
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
42
+ "@deepseek-ai/dsh-jobs": "0.2.2-rc.3",
43
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
44
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.3",
42
45
  "@deepseek-ai/cordis": "~4.1.0",
43
- "@deepseek-ai/dsh-working-directory": "0.2.2-rc.1"
46
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.3",
47
+ "@deepseek-ai/dsh-subprocess": "0.2.2-rc.3"
44
48
  },
45
49
  "dependencies": {
46
50
  "@deepseek-ai/schemastery": "~3.19.0"
47
51
  },
48
52
  "devDependencies": {
49
- "@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.1",
50
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
51
- "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.1",
52
- "@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.1",
53
- "@deepseek-ai/dsh-shell": "0.2.2-rc.1",
54
- "@deepseek-ai/dsh-shell-env": "0.2.2-rc.1",
55
- "@deepseek-ai/dsh-bash-local": "0.2.2-rc.1",
56
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
57
- "@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.1",
58
- "@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
59
- "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
60
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
61
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.1",
62
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
63
- "@deepseek-ai/dsh-jobs": "0.2.2-rc.1",
64
- "@deepseek-ai/dsh-jobs-local": "0.2.2-rc.1",
65
- "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
66
- "@deepseek-ai/dsh-tool-executor-ptc": "0.2.2-rc.1",
67
- "@deepseek-ai/dsh-tool-jobs": "0.2.2-rc.1",
68
- "@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.1",
69
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
70
- "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
53
+ "@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.3",
54
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
55
+ "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.3",
56
+ "@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.3",
57
+ "@deepseek-ai/dsh-shell": "0.2.2-rc.3",
58
+ "@deepseek-ai/dsh-shell-env": "0.2.2-rc.3",
59
+ "@deepseek-ai/dsh-bash-local": "0.2.2-rc.3",
60
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
61
+ "@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.3",
62
+ "@deepseek-ai/dsh-sandbox": "0.2.2-rc.3",
63
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.3",
64
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
65
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.3",
66
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
67
+ "@deepseek-ai/dsh-jobs": "0.2.2-rc.3",
68
+ "@deepseek-ai/dsh-jobs-local": "0.2.2-rc.3",
69
+ "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.3",
70
+ "@deepseek-ai/dsh-tool-executor-ptc": "0.2.2-rc.3",
71
+ "@deepseek-ai/dsh-tool-jobs": "0.2.2-rc.3",
72
+ "@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.3",
73
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
74
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.3",
71
75
  "@deepseek-ai/cordis": "~4.1.0",
72
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
73
- "@deepseek-ai/dsh-working-directory": "0.2.2-rc.1"
76
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.3",
77
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.3",
78
+ "@deepseek-ai/dsh-subprocess": "0.2.2-rc.3"
74
79
  }
75
80
  }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Generic-job adaptation for bash process handles: the terminal outcome the
3
+ * registry records, the pull sources it pumps, and the ring read a foreground
4
+ * call renders when it stops waiting.
5
+ *
6
+ * @module @deepseek-ai/dsh-tool-bash/background
7
+ */
8
+
9
+ import type { SandboxMode } from '@deepseek-ai/dsh-sandbox'
10
+ import { escalationHintMarker, sandboxDenialMarker } from '@deepseek-ai/dsh-sandbox'
11
+ import type { ShellProcess, ShellSandboxInfo } from '@deepseek-ai/dsh-shell'
12
+ import type { JobChunk, JobHooks, JobOutcome, JobOutputSource } from '@deepseek-ai/dsh-jobs'
13
+
14
+ /** Job hooks plus the original error of a job that failed before its process produced an outcome. */
15
+ export interface ProcessJobHooks extends JobHooks {
16
+ /**
17
+ * The error that ended a `failed` job, kept with its own class and code;
18
+ * undefined while the job runs and for a completed or killed job.
19
+ * @returns the original failure, boxed so any thrown value is preserved.
20
+ */
21
+ failure(): { error: unknown } | undefined
22
+ }
23
+
24
+ /**
25
+ * Sandbox facts worth the terminal detail: a runner that never ran the
26
+ * command, or a denial (with the escalation hint this composition offers).
27
+ * @param sandbox - settled sandbox facts, when this was a confined process.
28
+ * @param escalationModes - escalation targets advertised by this composition.
29
+ * @returns the markers to append, oldest first.
30
+ */
31
+ function sandboxNotes(sandbox: ShellSandboxInfo | undefined, escalationModes: readonly SandboxMode[]): string[] {
32
+ if (sandbox?.runnerFailed) {
33
+ return [`[sandbox: the sandbox runner itself failed under ${sandbox.mode} mode — the command did not run; this is a sandbox problem, not a command failure]`]
34
+ }
35
+ if (sandbox?.denied) {
36
+ const notes = [sandboxDenialMarker(sandbox.mode)]
37
+ if (escalationModes.length > 0) notes.push(escalationHintMarker('command'))
38
+ return notes
39
+ }
40
+ return []
41
+ }
42
+
43
+ /**
44
+ * Map a settled background process onto the generic job-outcome vocabulary:
45
+ * `killed` stays `killed` (detail: the signal when one is known), everything
46
+ * else is `completed` with the exit code as detail. A nonzero command exit is
47
+ * reported, not failed, exactly like the foreground rendering. Sandbox facts
48
+ * join the detail, since a job's terminal reason is the one line every
49
+ * reader — the model's status line, the roster row — shows.
50
+ * @param proc - the settled process handle.
51
+ * @param escalationModes - escalation targets advertised by this composition.
52
+ * @returns the outcome for the `ctx.jobs` registration.
53
+ */
54
+ export function processOutcome(proc: ShellProcess, escalationModes: readonly SandboxMode[] = []): JobOutcome {
55
+ // TODO(background-infrastructure-outcome): widen ShellProcess with an explicit
56
+ // infrastructure-failure outcome, then map it to job `failed`. Restricted
57
+ // runner failures expose sandbox.runnerFailed, but unconfined spawn failures
58
+ // still alias a signal-less kill; real nonzero command exits must remain
59
+ // `completed`.
60
+ const base: JobOutcome = proc.status === 'killed'
61
+ ? { status: 'killed', detail: proc.signal !== null ? `signal: ${proc.signal}` : 'killed before exit' }
62
+ : { status: 'completed', detail: `exit code: ${proc.exitCode ?? 0}` }
63
+ const notes = sandboxNotes(proc.sandbox, escalationModes)
64
+ return notes.length === 0 ? base : { ...base, detail: `${base.detail}; ${notes.join(' ')}` }
65
+ }
66
+
67
+ /**
68
+ * The process's non-consuming stream readers as registry pull sources. They
69
+ * bind lazily because the process is spawned inside the starter, after the
70
+ * registry admitted the job; a read before the spawn yields nothing, and the
71
+ * pump keeps the model's consuming cursor untouched. A rejected spawn's
72
+ * stderr reader carries the provider's `subprocess failed before reporting an
73
+ * outcome: …` note.
74
+ * @param proc - the started process's observed streams, once the starter has spawned it.
75
+ * @returns one source per stream, stdout first.
76
+ */
77
+ export function processSources(proc: () => Pick<ShellProcess, 'observed'> | undefined): JobOutputSource[] {
78
+ const source = (channel: 'stdout' | 'stderr'): JobOutputSource => ({
79
+ channel,
80
+ read: (fromByte) => {
81
+ const live = proc()
82
+ return live === undefined ? { text: '', nextOffset: fromByte, lossy: false } : live.observed[channel].readFrom(fromByte)
83
+ },
84
+ })
85
+ return [source('stdout'), source('stderr')]
86
+ }
87
+
88
+ /**
89
+ * The ring chunks of one consuming registry read as the shell tools render a
90
+ * process read: stdout chunks in order, then every stderr chunk in one
91
+ * `[stderr]` section, so the output a foreground call hands over when it
92
+ * stops waiting reads exactly like the `job_output` reads that follow it.
93
+ * @param chunks - the chunks since the model cursor, in offset order.
94
+ * @returns the delta text, possibly empty.
95
+ */
96
+ export function ringDelta(chunks: readonly JobChunk[]): string {
97
+ const out = chunks.filter(chunk => chunk.channel !== 'stderr').map(chunk => chunk.text).join('')
98
+ const err = chunks.filter(chunk => chunk.channel === 'stderr').map(chunk => chunk.text).join('')
99
+ const separator = out.length > 0 && !out.endsWith('\n') ? '\n' : ''
100
+ return out + (err.length > 0 ? `${separator}[stderr]\n${err}` : '')
101
+ }
102
+
103
+ /**
104
+ * Adapt asynchronous shell preparation after job admission without exposing a partial process.
105
+ * @param start - starts the process with job-owned cancellation.
106
+ * @param outcome - projects the settled process into the job outcome.
107
+ * @returns synchronous job hooks whose completion includes preparation and process settlement,
108
+ * and the original error of a failed preparation for a caller that reports it.
109
+ */
110
+ export function processJob(
111
+ start: (signal: AbortSignal) => Promise<ShellProcess>,
112
+ outcome: (process: ShellProcess) => JobOutcome,
113
+ ): ProcessJobHooks {
114
+ const controller = new AbortController()
115
+ let process: ShellProcess | undefined
116
+ let failure: { error: unknown } | undefined
117
+ const done: Promise<JobOutcome> = (async () => {
118
+ try {
119
+ process = await start(controller.signal)
120
+ try {
121
+ if (controller.signal.aborted) process.kill()
122
+ } finally {
123
+ await process.done
124
+ }
125
+ return outcome(process)
126
+ } catch (error: unknown) {
127
+ const killed = controller.signal.aborted && process === undefined
128
+ if (!killed) failure = { error }
129
+ return {
130
+ status: killed ? 'killed' : 'failed',
131
+ detail: error instanceof Error ? error.message : String(error),
132
+ }
133
+ }
134
+ })()
135
+ return {
136
+ cancel: (reason) => {
137
+ if (controller.signal.aborted) return
138
+ controller.abort(reason)
139
+ process?.kill()
140
+ },
141
+ done,
142
+ failure: () => failure,
143
+ }
144
+ }
package/src/index.ts ADDED
@@ -0,0 +1,584 @@
1
+ /**
2
+ * Model-facing Consumer of the `ctx.shell` capability seam. While a job
3
+ * registry is composed, every call registers its process with `ctx.jobs` as
4
+ * it starts: `run_in_background` returns the id at once, and a foreground call
5
+ * waits on its job until the command finishes or the wait times out, at which
6
+ * point it returns the same id. Without a registry the tool is foreground-only
7
+ * and the executor's deadline kills the command.
8
+ *
9
+ * TODO(permissions): deployment policy belongs in `tools/pre-execute` and
10
+ * sandboxing executors; see docs/architecture.md § Where new behavior goes.
11
+ * @module @deepseek-ai/dsh-tool-bash
12
+ */
13
+
14
+ import type {} from '@deepseek-ai/dsh-working-directory'
15
+ import { FiberState } from '@deepseek-ai/cordis'
16
+ import type { Context } from '@deepseek-ai/cordis'
17
+ import z from '@deepseek-ai/schemastery'
18
+ import { isAbsolute, sep } from 'node:path'
19
+ import { defineTool, TOOL_ABORTED, ToolArgsError, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools'
20
+ import type { GenericCallView, TerminalCallView, ToolDefinition, ToolExecution, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools'
21
+ import { HarnessError } from '@deepseek-ai/dsh-llm'
22
+ import { JobError } from '@deepseek-ai/dsh-jobs'
23
+ import type { JobId, JobRegistry, JobView } from '@deepseek-ai/dsh-jobs'
24
+ import type {} from '@deepseek-ai/dsh-user-approval'
25
+ import type {} from '@deepseek-ai/dsh-shell-env'
26
+ import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox'
27
+ import { ESCALATION_TARGETS, SandboxEscalationError, approveEscalation, sandboxPermissionsDescription, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox'
28
+ import { subprocessSpawnFailure } from '@deepseek-ai/dsh-subprocess'
29
+ import type { SandboxPolicyService } from '@deepseek-ai/dsh-sandbox-policy'
30
+ import { DSH_ENV_PREFIX } from '@deepseek-ai/dsh-shell'
31
+ import type { ShellExecRequest, ShellExecSpec, ShellExecution, ShellRunResult } from '@deepseek-ai/dsh-shell'
32
+ import { processJob, processOutcome, processSources, ringDelta } from './background.ts'
33
+ import type { ProcessJobHooks } from './background.ts'
34
+ import { parseExitStatus, renderJobRead, renderPromoted, renderResult } from './render.ts'
35
+
36
+ export const name = 'tool-bash'
37
+ export const inject = ['tools', 'shell', 'systemPrompt', 'shellEnv', 'workingDirectory']
38
+
39
+ /** Configuration for the bash tool. */
40
+ export interface Config {
41
+ /**
42
+ * Expose `run_in_background` while a job registry is composed (default
43
+ * true); disabled calls are also rejected. Without a registry the tool is
44
+ * foreground-only regardless.
45
+ */
46
+ enableRunInBackground?: boolean
47
+ /**
48
+ * Keep a foreground command that reaches its timeout running as a
49
+ * background job instead of killing it (default true). Applies only while
50
+ * background execution is available: with `enableRunInBackground` false or
51
+ * no job registry, the executor's deadline kills the command. A foreground
52
+ * command the registry refuses at its start (admission or a missing
53
+ * controller) also runs under the deadline kill.
54
+ */
55
+ promoteOnTimeout?: boolean
56
+ }
57
+
58
+ /** Runtime configuration schema for the bash tool plugin. */
59
+ export const Config: z<Config> = z.object({
60
+ enableRunInBackground: z.boolean().default(true),
61
+ promoteOnTimeout: z.boolean().default(true),
62
+ })
63
+
64
+ /** Parsed tool args; execute validates value constraints absent from ParameterSchemaSpec. */
65
+ interface BashToolArgs {
66
+ command: string
67
+ description: string
68
+ timeoutMs?: number
69
+ workdir?: string
70
+ run_in_background?: boolean
71
+ sandbox_permissions?: string
72
+ /** Optional for an omitted or repeated effective mode; widening requires a non-empty reason. */
73
+ justification?: string
74
+ }
75
+
76
+ function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undefined): void {
77
+ if (args.command.trim().length === 0) {
78
+ throw new ToolArgsError(['invalid command: expected a non-empty string'])
79
+ }
80
+ if (args.description.trim().length === 0) {
81
+ throw new ToolArgsError(['invalid description: expected a non-empty string'])
82
+ }
83
+ if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) {
84
+ throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`])
85
+ }
86
+ if (args.sandbox_permissions !== undefined && args.sandbox_permissions === effectiveMode) return
87
+ const justification = args.sandbox_permissions === undefined && args.justification?.trim() === ''
88
+ ? undefined
89
+ : args.justification
90
+ validateEscalationArgs(args.sandbox_permissions, justification)
91
+ }
92
+
93
+ function bashDescription(): string {
94
+ return 'Execute a bash command (`bash -c`) and return its stdout/stderr. '
95
+ + 'Each call runs in a fresh shell; pass `workdir` instead of using `cd`. '
96
+ + `Managed \`$${DSH_ENV_PREFIX}*\` variables expose current harness environment facts. `
97
+ + 'Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. '
98
+ + 'Provide `description` before `command` in the arguments. '
99
+ + 'Before any delete or move, verify that the resolved absolute target path is the intended one; never run it against a computed path you have not checked. '
100
+ + 'An unset variable expands to an empty string, so guard variables in such paths with `${VAR:?}`. '
101
+ + 'Commands may run under a file sandbox; a blocked file operation is reported as `[sandbox: file access denied under <mode> mode]`, a policy denial: do not retry another way.'
102
+ }
103
+
104
+ /**
105
+ * Present foreground calls as terminals and background starts as generic cards.
106
+ * The command remains the title on both paths; foreground cwd is passed through
107
+ * for the bridge to resolve, while background descriptions remain card content.
108
+ */
109
+ type BashCallArgs = { command: string; description: string; workdir?: string; run_in_background?: boolean }
110
+
111
+ function presentBashCall(args: BashCallArgs): GenericCallView | TerminalCallView {
112
+ if (args.run_in_background === true) {
113
+ return {
114
+ card: 'generic',
115
+ title: args.command,
116
+ kind: 'execute',
117
+ rawInput: args.command,
118
+ content: [{ type: 'text', text: args.description }],
119
+ }
120
+ }
121
+ return {
122
+ card: 'terminal',
123
+ title: args.command,
124
+ description: args.description,
125
+ ...args.workdir !== undefined ? { cwd: args.workdir } : {},
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Present completed foreground output as a terminal; background acknowledgements
131
+ * and execution errors use generic fenced output without an exit-status pill.
132
+ */
133
+ function presentBashResult(args: unknown, result: ToolResult): ToolResultView | undefined {
134
+ const block = result.content.length === 1 ? result.content[0] : undefined
135
+ if (block === undefined || block.type !== 'text') return undefined
136
+ const raw = block.text
137
+ const isBackground = typeof args === 'object' && args !== null && (args as { run_in_background?: unknown }).run_in_background === true
138
+ const isPromoted = (result as { value?: { kind?: unknown } }).value?.kind === 'promoted'
139
+ // Background acknowledgements, promotions, and errors have no terminal exit status.
140
+ if (isBackground || isPromoted || result.isError) {
141
+ return { card: 'generic', content: [{ type: 'text', text: `\`\`\`console\n${raw.replace(/\n+$/, '')}\n\`\`\`` }] }
142
+ }
143
+ // The exit marker becomes the card's exit pill, so it leaves the output body.
144
+ const { body, ...exit } = parseExitStatus(raw)
145
+ return { card: 'terminal', output: body, ...exit }
146
+ }
147
+
148
+ /** Resolve a relative per-call override against the Session's current directory. */
149
+ function resolveWorkdir(modelWorkdir: string | undefined, sessionCwd: string | undefined): string | undefined {
150
+ if (modelWorkdir === undefined) return sessionCwd
151
+ if (sessionCwd !== undefined && !isAbsolute(modelWorkdir)) {
152
+ return `${sessionCwd}${sep}${modelWorkdir}`
153
+ }
154
+ return modelWorkdir
155
+ }
156
+
157
+ /** Detach the executor DTO from readonly Service Definition types into plain JSON data. */
158
+ function canonicalBashResult(result: ShellRunResult, cwd: string) {
159
+ const output = (stream: ShellRunResult['stdout']) => ({
160
+ text: stream.text,
161
+ truncated: stream.truncated,
162
+ ...stream.spillPath !== undefined ? { spillPath: stream.spillPath } : {},
163
+ })
164
+ return {
165
+ cwd,
166
+ exitCode: result.exitCode,
167
+ signal: result.signal,
168
+ timedOut: result.timedOut,
169
+ aborted: result.aborted,
170
+ timeoutMs: result.timeoutMs,
171
+ stdout: output(result.stdout),
172
+ stderr: output(result.stderr),
173
+ ...result.sandbox !== undefined ? {
174
+ sandbox: {
175
+ mode: result.sandbox.mode,
176
+ denied: result.sandbox.denied,
177
+ ...result.sandbox.enforcement !== undefined ? { enforcement: result.sandbox.enforcement } : {},
178
+ ...result.sandbox.runnerFailed !== undefined ? { runnerFailed: result.sandbox.runnerFailed } : {},
179
+ },
180
+ } : {},
181
+ }
182
+ }
183
+
184
+ /** The structured abort the foreground paths throw when the caller cancels the call. */
185
+ function toolAborted(): HarnessError {
186
+ const error = new HarnessError('tool call aborted', TOOL_ABORTED)
187
+ error.name = 'AbortError'
188
+ return error
189
+ }
190
+
191
+ /**
192
+ * Report a launch or preparation rejection as this tool's failure. This
193
+ * call's cancellation reason stays as thrown so the registry records it as
194
+ * aborted; a platform spawn error is classified as a subprocess spawn failure
195
+ * with the original as `cause`; any other value, including a coded error,
196
+ * keeps its own identity.
197
+ */
198
+ function launchFailure(error: unknown, signal: AbortSignal): unknown {
199
+ return signal.aborted && error === signal.reason ? error : subprocessSpawnFailure(error, 'bash')
200
+ }
201
+
202
+ /** A registered command: its id, the process once the starter spawned it, and the reason an outside kill gave. */
203
+ interface StartedJob {
204
+ readonly id: JobId
205
+ readonly process: () => ShellExecution | undefined
206
+ readonly stopped: () => string | undefined
207
+ /** The original error of a registration whose preparation failed before the process published. */
208
+ readonly failure: () => { error: unknown } | undefined
209
+ }
210
+
211
+ /** Canonical background-handle properties shared by the bash output union. */
212
+ const BACKGROUND_OUTPUT_PROPERTIES = {
213
+ kind: { type: 'string', required: true, const: 'background' },
214
+ jobId: { type: 'string', required: true },
215
+ cwd: { type: 'string', required: true },
216
+ } as const
217
+
218
+ export function apply(ctx: Context, config: Config = {}): void {
219
+ const backgroundEnabled = config.enableRunInBackground ?? true
220
+ // Keeping a timed-out command needs the whole background surface: the job
221
+ // tools to collect and stop it, and the registry itself at execution time.
222
+ const promoteOnTimeout = (config.promoteOnTimeout ?? true) && backgroundEnabled
223
+ const defaultMode = ctx.shell.sandboxMode
224
+ const escalationModes: readonly SandboxMode[] = defaultMode === undefined ? [] : ESCALATION_TARGETS
225
+ const sandboxPolicy: SandboxPolicyService | undefined = defaultMode === undefined ? undefined : ctx.get('sandboxPolicy')
226
+ if (defaultMode !== undefined && sandboxPolicy === undefined) {
227
+ throw new Error('tool-bash: the mounted bash executor confines but ctx.sandboxPolicy is missing')
228
+ }
229
+ /** Resolve the complete standing policy for this call when a confining executor is mounted. */
230
+ const resolveSandboxPolicy = (exec: ToolExecution): SandboxExecutionPolicy | undefined =>
231
+ sandboxPolicy?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session })
232
+
233
+ /**
234
+ * Resolve a sandbox-escalation request through `ctx.approval` BEFORE
235
+ * anything executes, delegating the shared fail-closed sequence (strict
236
+ * widening, channel resolution, outcome mapping) to
237
+ * {@link approveEscalation}. This tool contributes only the composition
238
+ * guard (the fields are unadvertised without a sandboxing executor, yet
239
+ * schema validation checks advertised keys only, so an unadvertised
240
+ * `sandbox_permissions` still reaches execute) and the approval
241
+ * ingredients. The shared policy resolver is required whenever the executor
242
+ * advertises confinement, so a split composition fails at tool-plugin load.
243
+ */
244
+ const approveBashEscalation = (
245
+ mode: string,
246
+ justification: string,
247
+ exec: ToolExecution,
248
+ standingPolicy: SandboxExecutionPolicy | undefined,
249
+ ): Promise<SandboxMode> => {
250
+ if (escalationModes.length === 0) {
251
+ throw new SandboxEscalationError(
252
+ 'sandbox_permissions is not available in this composition (no sandboxing executor to escalate)',
253
+ 'SANDBOX_ESCALATION_UNAVAILABLE',
254
+ )
255
+ }
256
+ const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
257
+ return approveEscalation(
258
+ { requestedMode: mode, justification, effectiveMode, subject: 'command' },
259
+ {
260
+ approver: ctx.get('approval'),
261
+ agent: exec.agent,
262
+ callId: exec.callId,
263
+ toolName: 'bash',
264
+ signal: exec.signal,
265
+ },
266
+ )
267
+ }
268
+
269
+ // Cross-call guidance belongs in the prompt rather than one-call schema prose.
270
+ ctx.systemPrompt.section({
271
+ name: 'tool:bash',
272
+ order: ctx.systemPrompt.getSectionOrder('TOOL_BASH'),
273
+ text: 'Check the [exit code: N] marker on every bash result; investigate failures before moving on.',
274
+ })
275
+
276
+ /**
277
+ * One registration of the `bash` tool. With a registry, every call
278
+ * registers its process as a job at its start; without one the tool is
279
+ * foreground-only and the executor's deadline kills the command.
280
+ */
281
+ const bashTool = (jobs: JobRegistry | undefined): ToolDefinition => {
282
+ const background = jobs !== undefined
283
+ const promote = background && promoteOnTimeout
284
+ /** Register the command as a job; the process spawns inside the starter, after admission. */
285
+ const startJob = (registry: JobRegistry, args: BashToolArgs, exec: ToolExecution, spec: ShellExecSpec): StartedJob => {
286
+ let proc: ShellExecution | undefined
287
+ let stopped: string | undefined
288
+ let hooks: ProcessJobHooks | undefined
289
+ const id = registry.start({
290
+ kind: 'bash',
291
+ label: args.command,
292
+ toolCall: { callId: exec.callId, rootCallId: exec.rootCallId },
293
+ ...exec.agent ? { owner: exec.agent.id } : {},
294
+ output: processSources(() => proc),
295
+ run: () => {
296
+ const job = processJob(
297
+ async (signal) => {
298
+ proc = await ctx.shell.execute({ ...spec, signal })
299
+ return proc
300
+ },
301
+ started => processOutcome(started, escalationModes),
302
+ )
303
+ hooks = job
304
+ return {
305
+ done: job.done,
306
+ // A kill from outside this call (the human's, a parallel job_kill)
307
+ // reaches the process here; its reason is what the model reads.
308
+ cancel: (reason) => {
309
+ stopped = reason
310
+ job.cancel(reason)
311
+ },
312
+ }
313
+ },
314
+ })
315
+ return { id, process: () => proc, stopped: () => stopped, failure: () => hooks?.failure() }
316
+ }
317
+ /** Wait on a registered foreground command until it settles or the timeout passes. */
318
+ const waitOnJob = async (registry: JobRegistry, attached: StartedJob, exec: ToolExecution, spec: ShellExecSpec) => {
319
+ const owner = exec.agent?.id
320
+ const timeoutMs = spec.timeoutMs
321
+ /**
322
+ * Stop the job on this call's own account and stay on it until it
323
+ * settles, so the settlement is `awaited` and no completion notice
324
+ * follows a result this call already carries; the record then leaves
325
+ * with the call, as the model never saw the id.
326
+ */
327
+ const stop = async (reason: string): Promise<JobView> => {
328
+ registry.kill(attached.id, owner, reason)
329
+ const settled = await registry.wait(attached.id, timeoutMs, owner)
330
+ if (settled.status !== 'running' && settled.status !== 'stopping') registry.remove(attached.id, owner)
331
+ return settled
332
+ }
333
+ let view: JobView
334
+ try {
335
+ view = await registry.wait(attached.id, timeoutMs, owner, exec.signal)
336
+ } catch {
337
+ // A wait on the caller's own live job rejects only for the caller's
338
+ // abort: the model's call is over, so the command goes with it, as
339
+ // under the deadline kill.
340
+ await stop('tool call aborted')
341
+ throw toolAborted()
342
+ }
343
+ if ((view.status === 'running' || view.status === 'stopping') && attached.process() === undefined) {
344
+ // The wait expired while preparation still ran: nothing is running
345
+ // to keep, so this is the deadline's preparation timeout, with the
346
+ // settled empty result the executor's own deadline would have given.
347
+ await stop('timed out during preparation')
348
+ return {
349
+ kind: 'foreground' as const,
350
+ cwd: spec.workdir,
351
+ exitCode: null,
352
+ signal: null,
353
+ timedOut: true,
354
+ aborted: false,
355
+ timeoutMs,
356
+ stdout: { text: '', truncated: false },
357
+ stderr: { text: '', truncated: false },
358
+ ...spec.sandboxPolicy !== undefined ? { sandbox: { mode: spec.sandboxPolicy.mode, denied: false } } : {},
359
+ }
360
+ }
361
+ if (view.status === 'running' || view.status === 'stopping') {
362
+ // The wait timed out: the job keeps running. One consuming read seeds
363
+ // the result with the output so far, so `job_output` continues exactly
364
+ // where this result stops.
365
+ const read = registry.read(attached.id, owner)
366
+ return {
367
+ kind: 'promoted' as const,
368
+ cwd: spec.workdir,
369
+ jobId: attached.id,
370
+ timeoutMs,
371
+ output: renderJobRead(
372
+ ringDelta(read.chunks), read.lossy, read.job.output.spillPaths ?? [], attached.process()?.sandbox, escalationModes,
373
+ ),
374
+ }
375
+ }
376
+ // Settled while the call waited: the model never saw the id, so the
377
+ // record leaves the registry with this result. The process handle keeps
378
+ // the split streams and classification the foreground result needs.
379
+ registry.remove(attached.id, owner)
380
+ const process = attached.process()
381
+ // No process was published: the starter failed before the spawn. The
382
+ // original error keeps its class and code, exactly as the foreground
383
+ // projection would have rejected; a kill before the spawn has only its detail.
384
+ if (process === undefined) {
385
+ const failure = attached.failure()
386
+ throw failure === undefined ? new Error(view.detail) : launchFailure(failure.error, exec.signal)
387
+ }
388
+ const result = await process.result().catch((error: unknown) => { throw launchFailure(error, exec.signal) })
389
+ const stopped = attached.stopped()
390
+ return { kind: 'foreground' as const, ...canonicalBashResult(result, spec.workdir), ...stopped !== undefined ? { stopped } : {} }
391
+ }
392
+ return defineTool({
393
+ name: 'bash',
394
+ description: bashDescription(),
395
+ parameters: {
396
+ description: {
397
+ type: 'string',
398
+ required: true,
399
+ description: 'Clear, concise description of what this command does in active voice, '
400
+ + '5-10 words (shown in the UI). Examples: "ls" → "List files in current directory"; '
401
+ + '"git status" → "Show working tree status"; "npm install" → "Install package dependencies".',
402
+ },
403
+ command: { type: 'string', required: true, description: 'The bash command to execute.' },
404
+ timeoutMs: {
405
+ type: 'number',
406
+ description: promote
407
+ ? 'Timeout in milliseconds. The executor applies its configured default and cap; on expiry the command moves to the background as a job instead of being killed.'
408
+ : 'Timeout in milliseconds. The executor applies its configured default and cap, and kills the command on expiry.',
409
+ },
410
+ workdir: { type: 'string', description: 'Working directory for this command. Defaults to the session workspace; a relative path is resolved against it.' },
411
+ ...background ? {
412
+ run_in_background: { type: 'boolean' as const, description: 'Run in the background and return a job id immediately (collect with job_output, stop with job_kill). No timeout applies.' },
413
+ } : {},
414
+ ...escalationModes.length > 0 ? {
415
+ sandbox_permissions: {
416
+ type: 'string' as const,
417
+ enum: [...escalationModes],
418
+ description: sandboxPermissionsDescription('command'),
419
+ },
420
+ justification: {
421
+ type: 'string' as const,
422
+ description: 'Required with sandbox_permissions: one sentence for the user explaining why this exact command needs the wider access. '
423
+ + 'Use the language of the user’s current request.',
424
+ },
425
+ } : {},
426
+ },
427
+ output: {
428
+ schema: {
429
+ oneOf: [
430
+ {
431
+ type: 'object',
432
+ additionalProperties: false,
433
+ properties: BACKGROUND_OUTPUT_PROPERTIES,
434
+ },
435
+ {
436
+ type: 'object',
437
+ additionalProperties: false,
438
+ properties: {
439
+ kind: { type: 'string', required: true, const: 'promoted' },
440
+ cwd: { type: 'string', required: true },
441
+ jobId: { type: 'string', required: true },
442
+ timeoutMs: { type: 'number', required: true },
443
+ output: { type: 'string', required: true },
444
+ },
445
+ },
446
+ {
447
+ type: 'object',
448
+ additionalProperties: false,
449
+ properties: {
450
+ kind: { type: 'string', required: true, const: 'foreground' },
451
+ cwd: { type: 'string', required: true },
452
+ exitCode: { required: true, oneOf: [{ type: 'integer' }, { type: 'null' }] },
453
+ signal: { required: true, oneOf: [{ type: 'string' }, { type: 'null' }] },
454
+ timedOut: { type: 'boolean', required: true },
455
+ aborted: { type: 'boolean', required: true },
456
+ stopped: { type: 'string' },
457
+ timeoutMs: { type: 'number', required: true },
458
+ stdout: {
459
+ type: 'object',
460
+ additionalProperties: false,
461
+ required: true,
462
+ properties: {
463
+ text: { type: 'string', required: true },
464
+ truncated: { type: 'boolean', required: true },
465
+ spillPath: { type: 'string' },
466
+ },
467
+ },
468
+ stderr: {
469
+ type: 'object',
470
+ additionalProperties: false,
471
+ required: true,
472
+ properties: {
473
+ text: { type: 'string', required: true },
474
+ truncated: { type: 'boolean', required: true },
475
+ spillPath: { type: 'string' },
476
+ },
477
+ },
478
+ sandbox: {
479
+ type: 'object',
480
+ additionalProperties: false,
481
+ properties: {
482
+ mode: { type: 'string', required: true },
483
+ denied: { type: 'boolean', required: true },
484
+ enforcement: { type: 'string' },
485
+ runnerFailed: { type: 'boolean' },
486
+ },
487
+ },
488
+ },
489
+ },
490
+ ],
491
+ },
492
+ render: (_args, value) => [{
493
+ type: 'text',
494
+ text: value.kind === 'background'
495
+ ? `started background job ${value.jobId}`
496
+ : value.kind === 'promoted'
497
+ ? renderPromoted(value)
498
+ : renderResult(value as { kind: 'foreground' } & ShellRunResult, escalationModes),
499
+ }],
500
+ presentationMeta: (_args, value) => ({ cwd: value.cwd }),
501
+ },
502
+ async execute(args: BashToolArgs, exec) {
503
+ // Description is display metadata; workdir defaults to the caller's session.
504
+ const standingPolicy = resolveSandboxPolicy(exec)
505
+ validateBashArgs(args, standingPolicy?.mode)
506
+ const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined
507
+ ? await approveBashEscalation(args.sandbox_permissions, args.justification, exec, standingPolicy)
508
+ : undefined
509
+ const policy = approvedMode === undefined
510
+ ? standingPolicy
511
+ : { ...(standingPolicy as SandboxExecutionPolicy), mode: approvedMode }
512
+ const cwd = exec.agent === undefined ? undefined : await ctx.workingDirectory.ensure(exec.agent, exec.signal)
513
+ const workdir = resolveWorkdir(args.workdir, cwd)
514
+ const dshEnv = ctx.shellEnv.collect(exec)
515
+ const request: ShellExecRequest = {
516
+ command: args.command,
517
+ ...workdir !== undefined ? { workdir } : {},
518
+ ...args.timeoutMs !== undefined ? { timeoutMs: args.timeoutMs } : {},
519
+ dshEnv,
520
+ ...policy !== undefined ? { sandboxPolicy: policy } : {},
521
+ }
522
+ if (args.run_in_background === true) {
523
+ // Undeclared keys are allowed, so schema omission also needs enforcement.
524
+ if (!backgroundEnabled) {
525
+ throw new JobError('run_in_background is disabled for this deployment (enableRunInBackground: false)', 'JOB_BACKGROUND_DISABLED')
526
+ }
527
+ if (jobs === undefined) {
528
+ throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs')
529
+ }
530
+ // The caller owns cancellation until ctx.jobs commits detached ownership.
531
+ if (exec.signal.aborted) throw toolAborted()
532
+ const spec = ctx.shell.resolve({ ...request, onExpiry: 'none' })
533
+ return { kind: 'background' as const, jobId: startJob(jobs, args, exec, spec).id, cwd: spec.workdir }
534
+ }
535
+ // A foreground call is a job the tool waits on, so the command is
536
+ // visible and killable from the moment it starts and outlives the wait
537
+ // when the timeout passes. Admission refused at the start (the owner's
538
+ // job limit, no controller) runs the command under the deadline kill
539
+ // instead, exactly as a composition without a registry does.
540
+ if (jobs !== undefined && promote) {
541
+ const spec = ctx.shell.resolve({ ...request, onExpiry: 'none' })
542
+ let attached: StartedJob | undefined
543
+ try {
544
+ attached = startJob(jobs, args, exec, spec)
545
+ } catch (error) {
546
+ ctx.logger.warn(`bash: job registration refused, running in the foreground with the timeout kill instead: ${String(error)}`)
547
+ }
548
+ if (attached !== undefined) return waitOnJob(jobs, attached, exec, spec)
549
+ }
550
+ const spec = ctx.shell.resolve({ ...request, signal: exec.signal })
551
+ let result: ShellRunResult
552
+ try {
553
+ result = await (await ctx.shell.execute(spec)).result()
554
+ } catch (error) {
555
+ throw launchFailure(error, exec.signal)
556
+ }
557
+ if (result.aborted) throw toolAborted()
558
+ return { kind: 'foreground' as const, ...canonicalBashResult(result, spec.workdir) }
559
+ },
560
+ presentCall: presentBashCall,
561
+ presentResult: presentBashResult,
562
+ })
563
+ }
564
+
565
+ // The background surface follows the registry. The foreground-only variant
566
+ // registers now unless a registry is already composed, the job-backed
567
+ // variant replaces it for as long as `ctx.jobs` is present, and the
568
+ // foreground-only one returns when the registry unloads while this plugin
569
+ // stays. Both registrations belong to this plugin's own fiber.
570
+ if (!backgroundEnabled) {
571
+ ctx.tools.register(bashTool(undefined))
572
+ return
573
+ }
574
+ let foregroundOnly = ctx.get('jobs') === undefined ? ctx.tools.register(bashTool(undefined)) : undefined
575
+ ctx.inject(['jobs'], (jobCtx) => {
576
+ foregroundOnly?.()
577
+ foregroundOnly = undefined
578
+ const unregister = ctx.tools.register(bashTool(jobCtx.jobs))
579
+ jobCtx.effect(() => () => {
580
+ unregister()
581
+ if (ctx.fiber.state === FiberState.ACTIVE) foregroundOnly = ctx.tools.register(bashTool(undefined))
582
+ })
583
+ })
584
+ }
package/src/render.ts ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Model-facing result rendering for the bash tool.
3
+ *
4
+ * @module @deepseek-ai/dsh-tool-bash/render
5
+ */
6
+
7
+ import type { ShellRunResult, ShellSandboxInfo, CollectedOutput } from '@deepseek-ai/dsh-shell'
8
+ import type { SandboxMode } from '@deepseek-ai/dsh-sandbox'
9
+ import { escalationHintMarker, sandboxDenialMarker } from '@deepseek-ai/dsh-sandbox'
10
+
11
+ /** Append the truncation notice (with the full-output spill path) to a stream's text. */
12
+ function streamText(output: CollectedOutput): string {
13
+ if (!output.truncated) return output.text
14
+ return `${output.text}\n[output truncated; full output: ${output.spillPath ?? '(unavailable)'}]`
15
+ }
16
+
17
+ /**
18
+ * Shape one finished run into the text the model sees: stdout, then a marked
19
+ * stderr section, then exit-status markers. Non-zero exits are reported, not
20
+ * errored — the model decides how to react; only infrastructure failures
21
+ * (spawn errors, aborts) surface as isError results.
22
+ * @param result - the completed foreground run from the executor.
23
+ * @param escalationModes - the escalation targets this composition advertises;
24
+ * non-empty adds the same-turn escalation hint after a denial marker
25
+ * (default `[]`: no hint).
26
+ * @returns the model-facing text: output body (or `(no output)`), then any timeout/stopped/signal/exit markers, each on its own line.
27
+ */
28
+ export function renderResult(
29
+ result: ShellRunResult & { stopped?: string },
30
+ escalationModes: readonly SandboxMode[] = [],
31
+ ): string {
32
+ const out = streamText(result.stdout)
33
+ const err = streamText(result.stderr)
34
+
35
+ let body = out
36
+ if (err.length > 0) {
37
+ // Single newline between sections (stdout usually ends with one already).
38
+ if (body.length > 0 && !body.endsWith('\n')) body += '\n'
39
+ body += `[stderr]\n${err}`
40
+ }
41
+ if (body.length === 0) body = '(no output)'
42
+
43
+ const markers: string[] = []
44
+ // Keep the exit marker last because parseExitStatus anchors there.
45
+ if (result.sandbox?.denied) {
46
+ markers.push(sandboxDenialMarker(result.sandbox.mode))
47
+ // Hint only when the composition exposes escalation, before the final exit marker.
48
+ if (escalationModes.length > 0) {
49
+ markers.push(escalationHintMarker('command'))
50
+ }
51
+ }
52
+ // A command may trap SIGTERM and exit 0 after timeout; still report interruption.
53
+ if (result.timedOut) markers.push(`[timed out after ${result.timeoutMs}ms]`)
54
+ // A kill from outside the call (the human stopping its job) is not a
55
+ // command failure: the reason tells the model not to retry.
56
+ if (result.stopped !== undefined) markers.push(`[stopped: ${result.stopped}]`)
57
+ if (result.signal !== null) {
58
+ markers.push(`[killed by signal: ${result.signal}]`)
59
+ } else if (result.exitCode !== 0) {
60
+ markers.push(`[exit code: ${result.exitCode}]`)
61
+ }
62
+ if (markers.length === 0) return body
63
+
64
+ if (!body.endsWith('\n')) body += '\n'
65
+ return body + markers.join('\n')
66
+ }
67
+
68
+ /**
69
+ * Shape a foreground call that stopped waiting into the text the model sees:
70
+ * the output captured so far (one consuming registry read taken at that
71
+ * point, so `job_output` continues exactly after it), then the still-running
72
+ * marker. The `tool:jobs` system-prompt section explains how to follow up.
73
+ * @param promoted - the promoted result value: the job id, the wait that
74
+ * expired, and the output so far.
75
+ * @returns the model-facing text for a promoted call.
76
+ */
77
+ export function renderPromoted(promoted: { jobId: string; timeoutMs: number; output: string }): string {
78
+ const body = promoted.output.length > 0
79
+ ? promoted.output.endsWith('\n') ? promoted.output : `${promoted.output}\n`
80
+ : ''
81
+ return `${body}[still running after ${promoted.timeoutMs}ms; moved to background job ${promoted.jobId}]`
82
+ }
83
+
84
+ /**
85
+ * Shape the one consuming registry read a foreground call embeds in its
86
+ * result when it stops waiting: the output produced so far, plus the
87
+ * dropped-output notice (naming the job's spill files) when the model cursor
88
+ * fell behind the ring, and the sandbox notices. Later `job_output` reads
89
+ * render the same ring through the job tools.
90
+ * @param delta - the read's chunks as rendered text.
91
+ * @param lossy - whether bytes before the delta were evicted unread.
92
+ * @param spillPaths - the complete-stream files the job currently advertises.
93
+ * @param sandbox - settled sandbox facts, when this was a confined process.
94
+ * @param escalationModes - escalation targets advertised by this composition.
95
+ * @returns the delta text with any loss or sandbox notice appended.
96
+ */
97
+ export function renderJobRead(
98
+ delta: string,
99
+ lossy: boolean,
100
+ spillPaths: readonly string[],
101
+ sandbox?: ShellSandboxInfo,
102
+ escalationModes: readonly SandboxMode[] = [],
103
+ ): string {
104
+ const notices: string[] = []
105
+ if (lossy) {
106
+ notices.push(`[some output was dropped from memory; full output: ${spillPaths.length > 0 ? spillPaths.join(', ') : '(unavailable)'}]`)
107
+ }
108
+ if (sandbox?.runnerFailed) {
109
+ notices.push(`[sandbox: the sandbox runner itself failed under ${sandbox.mode} mode — the command did not run; this is a sandbox problem, not a command failure]`)
110
+ } else if (sandbox?.denied) {
111
+ notices.push(sandboxDenialMarker(sandbox.mode))
112
+ if (escalationModes.length > 0) {
113
+ notices.push(escalationHintMarker('command'))
114
+ }
115
+ }
116
+ if (notices.length === 0) return delta
117
+ return `${delta}${delta.length > 0 && !delta.endsWith('\n') ? '\n' : ''}${notices.join('\n')}`
118
+ }
119
+
120
+ /**
121
+ * The exit-status parse is the shared marker-contract half of the shell-tool
122
+ * rendering story, owned by `@deepseek-ai/dsh-shell` so `dsh-tool-pwsh` reuses
123
+ * it (its renderer emits the same markers). Re-exported here to keep
124
+ * `../src/render.ts` a single import root for bash-tool consumers.
125
+ */
126
+ export { parseExitStatus, type ParsedExitStatus } from '@deepseek-ai/dsh-shell'