dsh-win-multi-bash 0.1.0

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.
@@ -0,0 +1,526 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import { TOOL_ABORTED, defineTool } from "@deepseek-ai/dsh-tools";
4
+ import { HarnessError } from "@deepseek-ai/dsh-llm";
5
+ import { ESCALATION_TARGETS, approveEscalation, canonicalPath, escalationHintMarker, sandboxDenialMarker, validateEscalationArgs } from "@deepseek-ai/dsh-sandbox";
6
+ import { DSH_ENV_PREFIX, parseExitStatus } from "@deepseek-ai/dsh-shell";
7
+ //#region lib/types/background.js
8
+ /**
9
+ * Generic-task adaptation for background bash process handles.
10
+ *
11
+ * @module @deepseek-ai/dsh-tool-bash/background
12
+ */
13
+ /**
14
+ * Map a settled background process onto the generic task-outcome vocabulary:
15
+ * `killed` stays `killed` (detail: the signal when one is known), everything
16
+ * else is `completed` with the exit code as detail. A nonzero command exit is
17
+ * reported, not failed, exactly like the foreground rendering.
18
+ * @param proc - the settled process handle.
19
+ * @returns the outcome for the `ctx.jobs` registration.
20
+ */
21
+ function processOutcome(proc) {
22
+ if (proc.status === "killed") return {
23
+ status: "killed",
24
+ detail: proc.signal !== null ? `signal: ${proc.signal}` : "killed before exit"
25
+ };
26
+ return {
27
+ status: "completed",
28
+ detail: `exit code: ${proc.exitCode ?? 0}`
29
+ };
30
+ }
31
+ //#endregion
32
+ //#region lib/types/render.js
33
+ /**
34
+ * Model-facing result rendering for the bash tool.
35
+ *
36
+ * @module @deepseek-ai/dsh-tool-bash/render
37
+ */
38
+ /** Append the truncation notice (with the full-output spill path) to a stream's text. */
39
+ function streamText(output) {
40
+ if (!output.truncated) return output.text;
41
+ return `${output.text}\n[output truncated; full output: ${output.spillPath ?? "(unavailable)"}]`;
42
+ }
43
+ /**
44
+ * Shape one finished run into the text the model sees: stdout, then a marked
45
+ * stderr section, then exit-status markers. Non-zero exits are reported, not
46
+ * errored — the model decides how to react; only infrastructure failures
47
+ * (spawn errors, aborts) surface as isError results.
48
+ * @param result - the completed foreground run from the executor.
49
+ * @param escalationModes - the escalation targets this composition advertises;
50
+ * non-empty adds the same-turn escalation hint after a denial marker
51
+ * (default `[]`: no hint).
52
+ * @returns the model-facing text: output body (or `(no output)`), then any timeout/signal/exit markers, each on its own line.
53
+ */
54
+ function renderResult(result, escalationModes = []) {
55
+ const out = streamText(result.stdout);
56
+ const err = streamText(result.stderr);
57
+ let body = out;
58
+ if (err.length > 0) {
59
+ if (body.length > 0 && !body.endsWith("\n")) body += "\n";
60
+ body += `[stderr]\n${err}`;
61
+ }
62
+ if (body.length === 0) body = "(no output)";
63
+ const markers = [];
64
+ if (result.sandbox?.denied) {
65
+ markers.push(sandboxDenialMarker(result.sandbox.mode));
66
+ if (escalationModes.length > 0) markers.push(escalationHintMarker("command"));
67
+ }
68
+ if (result.timedOut) markers.push(`[timed out after ${result.timeoutMs}ms]`);
69
+ if (result.signal !== null) markers.push(`[killed by signal: ${result.signal}]`);
70
+ else if (result.exitCode !== 0) markers.push(`[exit code: ${result.exitCode}]`);
71
+ if (markers.length === 0) return body;
72
+ if (!body.endsWith("\n")) body += "\n";
73
+ return body + markers.join("\n");
74
+ }
75
+ /**
76
+ * Shape one background-process read into the `job_output` delta the model
77
+ * sees: the incremental delta, plus the lossy-read notice (with full-stream
78
+ * spill paths) when in-memory truncation dropped unread bytes. Empty-delta
79
+ * rendering (`(no new output)`) is the generic job controller's job.
80
+ * @param read - one incremental read from the process handle.
81
+ * @param sandbox - settled sandbox facts, when this was a confined process.
82
+ * @param escalationModes - escalation targets advertised by this composition.
83
+ * @returns the delta text with any loss or sandbox notice appended.
84
+ */
85
+ function renderProcessRead(read, sandbox, escalationModes = []) {
86
+ const notices = [];
87
+ if (read.lossy) {
88
+ const paths = [read.stdoutSpillPath, read.stderrSpillPath].filter((path) => path !== void 0);
89
+ notices.push(`[some output was dropped from memory; full output: ${paths.length > 0 ? paths.join(", ") : "(unavailable)"}]`);
90
+ }
91
+ if (sandbox?.runnerFailed) 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]`);
92
+ else if (sandbox?.denied) {
93
+ notices.push(sandboxDenialMarker(sandbox.mode));
94
+ if (escalationModes.length > 0) notices.push(escalationHintMarker("command"));
95
+ }
96
+ if (notices.length === 0) return read.delta;
97
+ return `${read.delta}${read.delta.length > 0 && !read.delta.endsWith("\n") ? "\n" : ""}${notices.join("\n")}`;
98
+ }
99
+ //#endregion
100
+ //#region lib/types/factory.js
101
+ /**
102
+ * Model-facing Consumer of the `ctx.shell` capability seam. Background calls
103
+ * register process handles with `ctx.jobs`; their work uses job cancellation
104
+ * rather than the tool-call signal after an id is returned.
105
+ *
106
+ * TODO(permissions): deployment policy belongs in `tools/pre-execute` and
107
+ * sandboxing executors; see docs/architecture.md § Where new behavior goes.
108
+ * @module @deepseek-ai/dsh-tool-bash/factory
109
+ */
110
+ const DIALECT_FACTS = {
111
+ posix: {
112
+ shell: "bash",
113
+ invoke: "bash -c",
114
+ paths: "POSIX paths",
115
+ env: "$VAR",
116
+ toolchain: "the full Unix toolchain"
117
+ },
118
+ msys: {
119
+ shell: "Git Bash (MSYS2)",
120
+ invoke: "bash -c",
121
+ paths: "MSYS paths such as /d/WorkSpace or native C:\\...",
122
+ env: "$VAR",
123
+ toolchain: "the Git for Windows toolchain (git, Windows .exe tools, POSIX utilities)",
124
+ conversion: "MSYS auto-converts leading-slash arguments to Windows paths whenever a native Windows executable is called, so POSIX paths get mangled (e.g. `wsl.exe -e ls /root` fails on `D:/Program Files/Git/root`); prefix such calls with `MSYS_NO_PATHCONV=1` to pass arguments verbatim"
125
+ },
126
+ wsl: {
127
+ shell: "WSL Linux",
128
+ invoke: "bash -c",
129
+ paths: "Linux paths such as /mnt/c/... (Windows paths auto-converted by wsl.exe)",
130
+ env: "$VAR",
131
+ toolchain: "the Linux userland (apt, gcc, python, ...)",
132
+ conversion: "the command rides as a base64 payload, so quoting and Linux paths reach the distro verbatim (no MSYS-style mangling)"
133
+ }
134
+ };
135
+ /** Runtime configuration schema for a shell tool instance. */
136
+ const Config$1 = z.object({ enableRunInBackground: z.boolean().default(true) });
137
+ /**
138
+ * The model-facing description of one shell tool instance. The POSIX variant
139
+ * keeps the legacy wording byte-for-byte (the ACP/headless tool-schema
140
+ * fixtures pin it); msys/wsl instances describe their dialect facts.
141
+ * @param dialect - the shell dialect the instance runs.
142
+ * @param backgroundEnabled - whether `run_in_background` is advertised.
143
+ * @param escalationModes - the escalation targets this composition advertises;
144
+ * empty adds no same-turn escalation guidance.
145
+ * @returns the tool description passed to `defineTool`.
146
+ */
147
+ function shellDescription(dialect, backgroundEnabled, escalationModes) {
148
+ const background = backgroundEnabled ? "Set `run_in_background: true` for long-running commands: the call returns a job id immediately; read its output with `job_output` and stop it with `job_kill`." : "Background execution is not available; long-running commands must finish within the timeout.";
149
+ if (dialect === "posix") return `Execute a bash command (\`bash -c\`) and return its stdout/stderr. Each call runs in a fresh shell: no state (cwd, variables, functions) persists between calls — pass \`workdir\` instead of using \`cd\`. Non-zero exits are reported as \`[exit code: N]\`. Current harness environment facts are exposed through managed \`\$${DSH_ENV_PREFIX}*\` variables; inspect them when needed. Commands may run under a file sandbox; a blocked file operation is reported as \`[sandbox: file access denied under <mode> mode]\` — a policy denial, not a bug in the command; do not retry another way. Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. ` + background + escalationTail(escalationModes);
150
+ const facts = DIALECT_FACTS[dialect];
151
+ return `Execute a ${facts.shell} command (${facts.invoke}) and return its stdout/stderr. Each call runs in a fresh shell: no state (cwd, variables, functions) persists between calls — pass \`workdir\` instead of using \`cd\`. Paths use ${facts.paths}; read environment variables with ${facts.env}; ${facts.toolchain} is available. Note: ${facts.conversion}. Non-zero exits are reported as \`[exit code: N]\`. Current harness environment facts are exposed through managed \`\$${DSH_ENV_PREFIX}*\` variables; inspect them when needed. Commands may run under a file sandbox; a blocked file operation is reported as \`[sandbox: file access denied under <mode> mode]\` — a policy denial, not a bug in the command; do not retry another way. Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. ` + background + escalationTail(escalationModes);
152
+ }
153
+ /**
154
+ * The same-turn escalation guidance appended after a denial marker. Kept in
155
+ * one place because every dialect shares the exact approval contract.
156
+ * @param escalationModes - the escalation targets this composition advertises.
157
+ * @returns the guidance sentence, or '' when no escalation is advertised.
158
+ */
159
+ function escalationTail(escalationModes) {
160
+ if (escalationModes.length === 0) return "";
161
+ return " Attempting a command the sandbox may deny is safe and expected: run it and read the marker rather than assuming the denial. When a command is denied and a wider mode would let it succeed, escalate immediately in the same turn — the one sanctioned exception to a denial: retry the exact same command once with `sandbox_permissions` (the narrowest wider mode that suffices) plus a one-sentence `justification`. Do not detour through chat to ask permission first — the approval prompt raised by that retry is how the user consents. If the session states approval prompts are disabled, there is no exception: a denial is final — do not set `sandbox_permissions`. Never escalate speculatively: ground the request in a real denial — normally the one this command just hit; escalating up front is fine only when this session already denied the same access. A rejected escalation is final for that command — stop and explain, never work around it — but it does not forbid attempting or escalating other commands later.";
162
+ }
163
+ function validateShellArgs(args) {
164
+ if (args.command.trim().length === 0) throw new Error("invalid command: expected a non-empty string");
165
+ if (args.description.trim().length === 0) throw new Error("invalid description: expected a non-empty string");
166
+ 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)}`);
167
+ validateEscalationArgs(args.sandbox_permissions, args.justification);
168
+ }
169
+ function presentShellCall(args) {
170
+ if (args.run_in_background === true) return {
171
+ card: "generic",
172
+ title: args.command,
173
+ kind: "execute",
174
+ rawInput: args.command,
175
+ content: [{
176
+ type: "text",
177
+ text: args.description
178
+ }]
179
+ };
180
+ return {
181
+ card: "terminal",
182
+ title: args.command,
183
+ description: args.description,
184
+ ...args.workdir !== void 0 ? { cwd: args.workdir } : {}
185
+ };
186
+ }
187
+ /**
188
+ * Present completed foreground output as a terminal; background acknowledgements
189
+ * and execution errors use generic fenced output without an exit-status pill.
190
+ */
191
+ function presentShellResult(args, result) {
192
+ const block = result.content.length === 1 ? result.content[0] : void 0;
193
+ if (block === void 0 || block.type !== "text") return void 0;
194
+ const raw = block.text;
195
+ if (typeof args === "object" && args !== null && args.run_in_background === true || result.isError) return {
196
+ card: "generic",
197
+ content: [{
198
+ type: "text",
199
+ text: `\`\`\`console\n${raw.replace(/\n+$/, "")}\n\`\`\``
200
+ }]
201
+ };
202
+ const { body, ...exit } = parseExitStatus(raw);
203
+ return {
204
+ card: "terminal",
205
+ output: body,
206
+ ...exit
207
+ };
208
+ }
209
+ /**
210
+ * Resolve an explicit workdir first, making a relative one session-workspace-relative;
211
+ * otherwise use the filesystem identity of the session cwd and leave executor
212
+ * defaulting as the fallback. A resolved sandbox-policy root wins so workdir
213
+ * and confinement use the exact same per-call identity.
214
+ */
215
+ function resolveWorkdir(modelWorkdir, exec, policyWorkspaceRoot) {
216
+ const headerCwd = exec.agent?.session.header.cwd;
217
+ const sessionCwd = policyWorkspaceRoot ?? (headerCwd === void 0 ? void 0 : canonicalPath(headerCwd));
218
+ if (modelWorkdir === void 0) return sessionCwd;
219
+ if (sessionCwd !== void 0 && !isAbsolute(modelWorkdir)) return resolve(sessionCwd, modelWorkdir);
220
+ return modelWorkdir;
221
+ }
222
+ /** Detach the executor DTO from readonly Service Definition types into plain JSON data. */
223
+ function canonicalShellResult(result) {
224
+ const output = (stream) => ({
225
+ text: stream.text,
226
+ truncated: stream.truncated,
227
+ ...stream.spillPath !== void 0 ? { spillPath: stream.spillPath } : {}
228
+ });
229
+ return {
230
+ exitCode: result.exitCode,
231
+ signal: result.signal,
232
+ timedOut: result.timedOut,
233
+ aborted: result.aborted,
234
+ timeoutMs: result.timeoutMs,
235
+ stdout: output(result.stdout),
236
+ stderr: output(result.stderr),
237
+ ...result.sandbox !== void 0 ? { sandbox: {
238
+ mode: result.sandbox.mode,
239
+ denied: result.sandbox.denied,
240
+ ...result.sandbox.enforcement !== void 0 ? { enforcement: result.sandbox.enforcement } : {},
241
+ ...result.sandbox.runnerFailed !== void 0 ? { runnerFailed: result.sandbox.runnerFailed } : {}
242
+ } } : {}
243
+ };
244
+ }
245
+ /** Canonical background-handle properties shared by the shell output union. */
246
+ const BACKGROUND_OUTPUT_PROPERTIES = {
247
+ kind: {
248
+ type: "string",
249
+ required: true,
250
+ const: "background"
251
+ },
252
+ jobId: {
253
+ type: "string",
254
+ required: true
255
+ }
256
+ };
257
+ /**
258
+ * Build a model-facing shell tool plugin. The instance name doubles as the
259
+ * tool name, the approval subject, the prompt section name (`tool:<toolName>`),
260
+ * and the `ctx.jobs` kind; the instance module declares its kind in
261
+ * {@link JobKindMap} via declaration merging.
262
+ * @param def - the instance definition: `toolName` (also the job kind),
263
+ * `shell` (routed to the selector executor when defined), and `dialect`.
264
+ * @returns the complete plugin object (name/inject/Config/apply).
265
+ */
266
+ function defineShellTool(def) {
267
+ return {
268
+ name: `tool-${def.toolName}`,
269
+ inject: [
270
+ "tools",
271
+ "shell",
272
+ "systemPrompt",
273
+ "shellEnv"
274
+ ],
275
+ Config: Config$1,
276
+ apply(ctx, config = {}) {
277
+ const backgroundEnabled = config.enableRunInBackground ?? true;
278
+ const defaultMode = ctx.shell.sandboxMode;
279
+ const escalationModes = defaultMode === void 0 ? [] : ESCALATION_TARGETS;
280
+ const sandboxPolicy = defaultMode === void 0 ? void 0 : ctx.get("sandboxPolicy");
281
+ if (defaultMode !== void 0 && sandboxPolicy === void 0) throw new Error(`tool-${def.toolName}: the mounted bash executor confines but ctx.sandboxPolicy is missing`);
282
+ /** Resolve the complete standing policy for this call when a confining executor is mounted. */
283
+ const resolveSandboxPolicy = (exec) => sandboxPolicy?.resolve(exec.agent === void 0 ? {} : { session: exec.agent.session });
284
+ /**
285
+ * Resolve a sandbox-escalation request through `ctx.approval` BEFORE
286
+ * anything executes, delegating the shared fail-closed sequence (strict
287
+ * widening, channel resolution, outcome mapping) to
288
+ * {@link approveEscalation}. This tool contributes only the composition
289
+ * guard (the fields are unadvertised without a sandboxing executor, yet
290
+ * schema validation checks advertised keys only, so an unadvertised
291
+ * `sandbox_permissions` still reaches execute) and the approval
292
+ * ingredients. The shared policy resolver is required whenever the executor
293
+ * advertises confinement, so a split composition fails at tool-plugin load.
294
+ */
295
+ const approveShellEscalation = (mode, justification, exec, standingPolicy) => {
296
+ if (escalationModes.length === 0) throw new Error("sandbox_permissions is not available in this composition (no sandboxing executor to escalate)");
297
+ const effectiveMode = standingPolicy.mode;
298
+ return approveEscalation({
299
+ requestedMode: mode,
300
+ justification,
301
+ effectiveMode,
302
+ subject: "command"
303
+ }, {
304
+ approver: ctx.get("approval"),
305
+ agent: exec.agent,
306
+ callId: exec.callId,
307
+ toolName: def.toolName,
308
+ signal: exec.signal
309
+ });
310
+ };
311
+ ctx.systemPrompt.section({
312
+ name: `tool:${def.toolName}`,
313
+ order: 105,
314
+ text: "Check the [exit code: N] marker on every bash result; investigate failures before moving on."
315
+ });
316
+ ctx.tools.register(defineTool({
317
+ name: def.toolName,
318
+ description: shellDescription(def.dialect, backgroundEnabled, escalationModes),
319
+ parameters: {
320
+ command: {
321
+ type: "string",
322
+ required: true,
323
+ description: "The bash command to execute."
324
+ },
325
+ description: {
326
+ type: "string",
327
+ required: true,
328
+ description: "Clear, concise description of what this command does in active voice, 5-10 words (shown in the UI). Examples: \"ls\" → \"List files in current directory\"; \"git status\" → \"Show working tree status\"; \"npm install\" → \"Install package dependencies\"."
329
+ },
330
+ timeoutMs: {
331
+ type: "number",
332
+ description: "Timeout in milliseconds. The executor applies its configured default and cap, and kills the command on expiry."
333
+ },
334
+ workdir: {
335
+ type: "string",
336
+ description: "Working directory for this command. Defaults to the session workspace; a relative path is resolved against it."
337
+ },
338
+ ...backgroundEnabled ? { run_in_background: {
339
+ type: "boolean",
340
+ description: "Run in the background and return a job id immediately (collect with job_output, stop with job_kill). No timeout applies."
341
+ } } : {},
342
+ ...escalationModes.length > 0 ? {
343
+ sandbox_permissions: {
344
+ type: "string",
345
+ enum: [...escalationModes],
346
+ description: "The wider sandbox mode this command needs. Only valid as a one-shot retry of a command the sandbox just denied; requires justification and user approval."
347
+ },
348
+ justification: {
349
+ type: "string",
350
+ description: "Required with sandbox_permissions: one sentence for the user explaining why this exact command needs the wider access."
351
+ }
352
+ } : {}
353
+ },
354
+ output: {
355
+ schema: { oneOf: [{
356
+ type: "object",
357
+ additionalProperties: false,
358
+ properties: BACKGROUND_OUTPUT_PROPERTIES
359
+ }, {
360
+ type: "object",
361
+ additionalProperties: false,
362
+ properties: {
363
+ kind: {
364
+ type: "string",
365
+ required: true,
366
+ const: "foreground"
367
+ },
368
+ exitCode: {
369
+ required: true,
370
+ oneOf: [{ type: "integer" }, { type: "null" }]
371
+ },
372
+ signal: {
373
+ required: true,
374
+ oneOf: [{ type: "string" }, { type: "null" }]
375
+ },
376
+ timedOut: {
377
+ type: "boolean",
378
+ required: true
379
+ },
380
+ aborted: {
381
+ type: "boolean",
382
+ required: true
383
+ },
384
+ timeoutMs: {
385
+ type: "number",
386
+ required: true
387
+ },
388
+ stdout: {
389
+ type: "object",
390
+ additionalProperties: false,
391
+ required: true,
392
+ properties: {
393
+ text: {
394
+ type: "string",
395
+ required: true
396
+ },
397
+ truncated: {
398
+ type: "boolean",
399
+ required: true
400
+ },
401
+ spillPath: { type: "string" }
402
+ }
403
+ },
404
+ stderr: {
405
+ type: "object",
406
+ additionalProperties: false,
407
+ required: true,
408
+ properties: {
409
+ text: {
410
+ type: "string",
411
+ required: true
412
+ },
413
+ truncated: {
414
+ type: "boolean",
415
+ required: true
416
+ },
417
+ spillPath: { type: "string" }
418
+ }
419
+ },
420
+ sandbox: {
421
+ type: "object",
422
+ additionalProperties: false,
423
+ properties: {
424
+ mode: {
425
+ type: "string",
426
+ required: true
427
+ },
428
+ denied: {
429
+ type: "boolean",
430
+ required: true
431
+ },
432
+ enforcement: { type: "string" },
433
+ runnerFailed: { type: "boolean" }
434
+ }
435
+ }
436
+ }
437
+ }] },
438
+ render: (_args, value) => [{
439
+ type: "text",
440
+ text: value.kind === "background" ? `started background job ${value.jobId}` : renderResult(value, escalationModes)
441
+ }]
442
+ },
443
+ async execute(args, exec) {
444
+ validateShellArgs(args);
445
+ const standingPolicy = resolveSandboxPolicy(exec);
446
+ const approvedMode = args.sandbox_permissions !== void 0 && args.justification !== void 0 ? await approveShellEscalation(args.sandbox_permissions, args.justification, exec, standingPolicy) : void 0;
447
+ const policy = approvedMode === void 0 ? standingPolicy : {
448
+ ...standingPolicy,
449
+ mode: approvedMode
450
+ };
451
+ const workdir = resolveWorkdir(args.workdir, exec, standingPolicy?.workspaceRoot);
452
+ const dshEnv = ctx.shellEnv.collect(exec);
453
+ const request = {
454
+ command: args.command,
455
+ ...workdir !== void 0 ? { workdir } : {},
456
+ ...args.timeoutMs !== void 0 ? { timeoutMs: args.timeoutMs } : {},
457
+ ...def.shell !== void 0 ? { shell: def.shell } : {},
458
+ dshEnv,
459
+ ...policy !== void 0 ? { sandboxPolicy: policy } : {}
460
+ };
461
+ if (args.run_in_background === true) {
462
+ if (!backgroundEnabled) throw new Error("run_in_background is disabled for this deployment (enableRunInBackground: false)");
463
+ const jobs = ctx.get("jobs");
464
+ if (jobs === void 0) throw new Error("background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs");
465
+ if (exec.signal.aborted) {
466
+ const error = new HarnessError("tool call aborted", TOOL_ABORTED);
467
+ error.name = "AbortError";
468
+ throw error;
469
+ }
470
+ return {
471
+ kind: "background",
472
+ jobId: jobs.start({
473
+ kind: def.toolName,
474
+ label: args.command,
475
+ ...exec.agent ? { owner: exec.agent } : {},
476
+ run: () => {
477
+ const proc = ctx.shell.start(ctx.shell.resolve(request));
478
+ return {
479
+ cancel: () => void proc.kill(),
480
+ done: proc.done.then(() => processOutcome(proc)),
481
+ readOutput: () => renderProcessRead(proc.readOutput(), proc.sandbox, escalationModes)
482
+ };
483
+ }
484
+ })
485
+ };
486
+ }
487
+ const result = await ctx.shell.run(ctx.shell.resolve({
488
+ ...request,
489
+ signal: exec.signal
490
+ }));
491
+ if (result.aborted) {
492
+ const error = new HarnessError("tool call aborted", TOOL_ABORTED);
493
+ error.name = "AbortError";
494
+ throw error;
495
+ }
496
+ return {
497
+ kind: "foreground",
498
+ ...canonicalShellResult(result)
499
+ };
500
+ },
501
+ presentCall: presentShellCall,
502
+ presentResult: presentShellResult
503
+ }));
504
+ }
505
+ };
506
+ }
507
+ //#endregion
508
+ //#region lib/types/index.js
509
+ /**
510
+ * The POSIX bash tool instance built by the shared shell-tool factory. Its
511
+ * tool contract is unchanged: no `shell` field, so a selector executor
512
+ * routes it to its configured default; single-backend compositions never
513
+ * notice the field.
514
+ * @module @deepseek-ai/dsh-tool-bash
515
+ */
516
+ /** The POSIX bash tool (unchanged contract). */
517
+ const bashTool = defineShellTool({
518
+ toolName: "bash",
519
+ dialect: "posix"
520
+ });
521
+ const name = bashTool.name;
522
+ const inject = bashTool.inject;
523
+ const Config = bashTool.Config;
524
+ const apply = bashTool.apply;
525
+ //#endregion
526
+ export { Config, apply, defineShellTool, inject, name };
@@ -0,0 +1,23 @@
1
+ //#region lib/types/invariant.js
2
+ /**
3
+ * Package-owned invariant companion for `@deepseek-ai/dsh-tool-bash`.
4
+ * @module @deepseek-ai/dsh-tool-bash/invariant
5
+ */
6
+ const PACKAGE_NAME = "@deepseek-ai/dsh-tool-bash";
7
+ /** Cordis companion plugin name. */
8
+ const name = "tool-bash-invariant";
9
+ /** Service required before the companion can reserve package ownership. */
10
+ const inject = ["invariants"];
11
+ /**
12
+ * No runtime invariant: the environment registry validates ownership and collected values at each
13
+ * mutation/read; it publishes no independent snapshot that a companion could cross-check.
14
+ */
15
+ const install = () => {};
16
+ /**
17
+ * Register this package's invariant companion.
18
+ * @param ctx - Cordis context carrying the invariant service.
19
+ * @returns the installed registration's disposer after setup succeeds.
20
+ */
21
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
22
+ //#endregion
23
+ export { apply, inject, name };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generic-task adaptation for background bash process handles.
3
+ *
4
+ * @module @deepseek-ai/dsh-tool-bash/background
5
+ */
6
+ /**
7
+ * Map a settled background process onto the generic task-outcome vocabulary:
8
+ * `killed` stays `killed` (detail: the signal when one is known), everything
9
+ * else is `completed` with the exit code as detail. A nonzero command exit is
10
+ * reported, not failed, exactly like the foreground rendering.
11
+ * @param proc - the settled process handle.
12
+ * @returns the outcome for the `ctx.jobs` registration.
13
+ */
14
+ export function processOutcome(proc) {
15
+ // TODO(background-infrastructure-outcome): widen ShellProcess with an explicit
16
+ // infrastructure-failure outcome, then map it to task `failed`. Restricted
17
+ // runner failures expose sandbox.runnerFailed, but unconfined spawn failures
18
+ // still alias a signal-less kill; real nonzero command exits must remain
19
+ // `completed`.
20
+ if (proc.status === 'killed') {
21
+ return { status: 'killed', detail: proc.signal !== null ? `signal: ${proc.signal}` : 'killed before exit' };
22
+ }
23
+ return { status: 'completed', detail: `exit code: ${proc.exitCode ?? 0}` };
24
+ }
25
+ //# sourceMappingURL=background.js.map