dsh-better-edit 0.1.2 → 0.1.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.
@@ -14,7 +14,7 @@ import { loadServed, sessionKeyFor } from './served-store.js';
14
14
  import { findSnapshotPathsByHashes } from './snapshot-store.js';
15
15
  import { scanDrift } from './drift.js';
16
16
  import { abortIf, isRec, rejectUnknownFields, splitLines } from './utils.js';
17
- const ROOT_KS = new Set(['path', 'remove_from', 'remove_to', 'replacement_text']);
17
+ const ROOT_KS = new Set(['path', 'remove_from', 'remove_to', 'replacement_text', 'sandbox_permissions', 'justification']);
18
18
  export function assertReq(request) {
19
19
  if (!isRec(request)) {
20
20
  throw new Error('[E_BAD_SHAPE] Edit request must be an object.');
package/lib/fs-bridge.js CHANGED
@@ -71,7 +71,7 @@ export function ctxFsIO(fs, ctx) {
71
71
  return mapFsError(error, absolutePath);
72
72
  }
73
73
  },
74
- async writeText(absolutePath, content, signal, exec) {
74
+ async writeText(absolutePath, content, signal, exec, sandboxPolicy) {
75
75
  try {
76
76
  const target = await fs.resolve(absolutePath, {
77
77
  ...(signal !== undefined ? { signal } : {}),
@@ -80,12 +80,19 @@ export function ctxFsIO(fs, ctx) {
80
80
  // createIfAbsent / replaceIfVersion; the bare default is
81
81
  // undefined (unconditional) when no policy is mounted.
82
82
  const intent = await ctx.waterfall("fs/write-intent", target, exec, () => undefined);
83
- const outcome = await fs.writeText(target, content, intent, signal);
83
+ // The sandbox policy (session workspace root + mode) is what a
84
+ // confined backend checks: without it the backend falls back to
85
+ // the deployment default root and denies writes inside the
86
+ // session workspace under workspace-write.
87
+ const outcome = await fs.writeText(target, content, intent, signal, sandboxPolicy);
84
88
  // Record the present observation (a no-op when no policy
85
89
  // plugin listens), so later built-in tools see the new version.
86
90
  ctx.emit("fs/observed", target, { kind: "present", version: outcome.version }, exec);
87
91
  }
88
92
  catch (error) {
93
+ // FS_SANDBOX_DENIED passes through raw; the tool layer maps it
94
+ // to the shared [sandbox: …] marker + escalation hint via its
95
+ // sandbox controller.
89
96
  return mapFsError(error, absolutePath);
90
97
  }
91
98
  },
@@ -128,7 +135,7 @@ export function localIO() {
128
135
  signal?.throwIfAborted();
129
136
  return readFile(absolutePath, "utf-8");
130
137
  },
131
- async writeText(absolutePath, content, signal) {
138
+ async writeText(absolutePath, content, signal, _exec, _sandboxPolicy) {
132
139
  signal?.throwIfAborted();
133
140
  await writeAtomic(absolutePath, content);
134
141
  },
package/lib/index.js CHANGED
@@ -12,6 +12,7 @@
12
12
  * @module dsh-better-edit
13
13
  */
14
14
  import { ctxFsIO } from "./fs-bridge.js";
15
+ import { FsSandboxController } from "./sandbox.js";
15
16
  import { registerReadTool } from "./tool-read.js";
16
17
  import { registerEditTool } from "./tool-edit.js";
17
18
  import { registerBatchEditTool } from "./tool-batch-edit.js";
@@ -38,9 +39,10 @@ function installAgentTools(rootCtx, agent) {
38
39
  const io = ctxFsIO(rootCtx.fs, rootCtx);
39
40
  const disposers = [];
40
41
  disposers.push(registerReadTool(rootCtx, agent.ctx, io));
41
- disposers.push(registerEditTool(rootCtx, agent.ctx, io));
42
- disposers.push(registerBatchEditTool(rootCtx, agent.ctx, io));
43
- disposers.push(registerUndoTool(rootCtx, agent.ctx, io));
42
+ const sandbox = new FsSandboxController(rootCtx);
43
+ disposers.push(registerEditTool(rootCtx, agent.ctx, io, sandbox));
44
+ disposers.push(registerBatchEditTool(rootCtx, agent.ctx, io, sandbox));
45
+ disposers.push(registerUndoTool(rootCtx, agent.ctx, io, sandbox));
44
46
  disposers.push(registerWriteHook(rootCtx, agent.ctx, io));
45
47
  // Shadow the preset's built-in tool guidance with the hashline contract.
46
48
  // Same section names on the agent's own layer win over the preset's.
package/lib/sandbox.js ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The sandbox-escalation API for the hashline mutating tools, mirroring
3
+ * `@deepseek-ai/dsh-tool-fs`'s `FsSandboxController` (same vocabulary, same
4
+ * fail-closed approval sequence, shared `@deepseek-ai/dsh-sandbox` pieces) so
5
+ * `edit`/`batch_edit`/`undo_last_edit` escalate exactly like the built-in
6
+ * `write`/`edit` — and, critically, stamp the per-call policy with the SESSION
7
+ * workspace root. Without the policy the sandbox backend falls back to the
8
+ * deployment default root, so an edit inside the session workspace is denied
9
+ * under `workspace-write` even though the built-in `write` succeeds there.
10
+ * @module dsh-better-edit/sandbox
11
+ */
12
+ import { FsError } from '@deepseek-ai/dsh-fs';
13
+ import { ESCALATION_TARGETS, approveEscalation, escalationHintMarker, sandboxDenialMarker, validateEscalationArgs, } from '@deepseek-ai/dsh-sandbox';
14
+ /**
15
+ * The filesystem escalation API: advertisement gating, per-call policy
16
+ * resolution, the one-approved wider retry, and denial-marker mapping. A pure
17
+ * product of `ctx` at plugin apply time.
18
+ */
19
+ export class FsSandboxController {
20
+ ctx;
21
+ /** The escalation targets this composition advertises (`[]` when no confining backend is mounted). */
22
+ escalationModes;
23
+ /** Shared per-session policy resolver, required by a confining backend. */
24
+ policy;
25
+ constructor(ctx) {
26
+ this.ctx = ctx;
27
+ const defaultMode = ctx.fs.sandboxMode;
28
+ this.escalationModes = defaultMode === undefined ? [] : ESCALATION_TARGETS;
29
+ this.policy = defaultMode === undefined ? undefined : ctx.get('sandboxPolicy');
30
+ if (defaultMode !== undefined && this.policy === undefined) {
31
+ throw new Error('dsh-better-edit: the mounted filesystem confines but ctx.sandboxPolicy is missing');
32
+ }
33
+ }
34
+ /**
35
+ * The escalation schema fields for a mutating tool's `parameters`. Call it
36
+ * only under a confining backend (guard on {@link escalationModes}); the
37
+ * enum pins the closed target vocabulary, the strict-wider check happens
38
+ * per call at execution.
39
+ */
40
+ schemaFields() {
41
+ return {
42
+ sandbox_permissions: {
43
+ type: 'string',
44
+ enum: [...this.escalationModes],
45
+ description: 'The wider sandbox mode this file operation needs. Only valid as a one-shot retry '
46
+ + 'of an operation the sandbox just denied; requires justification and user approval.',
47
+ },
48
+ justification: {
49
+ type: 'string',
50
+ description: 'Required with sandbox_permissions: one sentence for the user explaining '
51
+ + 'why this exact file operation needs the wider access.',
52
+ },
53
+ };
54
+ }
55
+ /**
56
+ * The policy to stamp onto this mutation: an approved escalation grant (a
57
+ * strictly wider retry resolved through `ctx.approval` before anything
58
+ * executes), else the session's standing mode. The calling session's cwd is
59
+ * always carried as the workspace root, so `workspace-write` allows writes
60
+ * inside the session workspace.
61
+ * @param toolName - the mutating tool's name, for the approval audit trail.
62
+ * @param args - the call's escalation arguments.
63
+ * @param exec - the tool-execution context (agent, callId, signal).
64
+ * @returns the policy to pass to the mutation, or undefined for an
65
+ * unsandboxed backend.
66
+ */
67
+ async resolvePolicy(toolName, args, exec) {
68
+ validateEscalationArgs(args.sandbox_permissions, args.justification);
69
+ const standingPolicy = this.policy?.resolve({ ...exec.agent ? { session: exec.agent.session } : {} });
70
+ if (args.sandbox_permissions === undefined || args.justification === undefined) {
71
+ return standingPolicy;
72
+ }
73
+ if (this.escalationModes.length === 0) {
74
+ throw new Error('sandbox_permissions is not available in this composition (no sandboxing filesystem to escalate)');
75
+ }
76
+ const policy = standingPolicy;
77
+ const approvedMode = await approveEscalation({ requestedMode: args.sandbox_permissions, justification: args.justification, effectiveMode: policy.mode, subject: 'operation' }, {
78
+ approver: this.ctx.get('approval'),
79
+ agent: exec.agent,
80
+ callId: exec.callId,
81
+ toolName,
82
+ signal: exec.signal,
83
+ });
84
+ return { ...policy, mode: approvedMode };
85
+ }
86
+ /**
87
+ * Map a thrown provider error for the model: a `FS_SANDBOX_DENIED` becomes
88
+ * the shared `[sandbox: …]` denial marker plus the same-turn escalation
89
+ * hint, keeping the structured code. Any other error passes through.
90
+ */
91
+ mapError(error, policy) {
92
+ if (!(error instanceof FsError) || error.code !== 'FS_SANDBOX_DENIED')
93
+ return error;
94
+ const mode = policy.mode;
95
+ return new FsError(`${sandboxDenialMarker(mode)}\n${escalationHintMarker('operation')}`, 'FS_SANDBOX_DENIED', { cause: error });
96
+ }
97
+ }
@@ -33,7 +33,7 @@ function assertBatchReq(request) {
33
33
  if (!isRec(request)) {
34
34
  throw new Error('[E_BAD_SHAPE] batch_edit request must be an object with an "edits" array.');
35
35
  }
36
- rejectUnknownFields(request, new Set(["edits"]), "batch_edit request");
36
+ rejectUnknownFields(request, new Set(["edits", "sandbox_permissions", "justification"]), "batch_edit request");
37
37
  if (!Array.isArray(request.edits) || request.edits.length === 0) {
38
38
  throw new Error('[E_BAD_SHAPE] batch_edit request requires a non-empty "edits" array.');
39
39
  }
@@ -313,7 +313,7 @@ function toSection(file) {
313
313
  * @param io - the filesystem bridge.
314
314
  * @returns the exact disposer that unregisters the tool.
315
315
  */
316
- export function buildBatchEditTool(io) {
316
+ export function buildBatchEditTool(io, sandbox) {
317
317
  return defineTool({
318
318
  name: "batch_edit",
319
319
  description: BATCH_EDIT_DESCRIPTION,
@@ -357,6 +357,7 @@ export function buildBatchEditTool(io) {
357
357
  });
358
358
  }
359
359
  assertBatchReq(canonical);
360
+ const sandboxPolicy = await sandbox.resolvePolicy("batch_edit", canonical, exec);
360
361
  const items = await prepareItems(io, canonical, cwd, signal);
361
362
  const groups = groupByPath(items);
362
363
  const processed = [];
@@ -395,7 +396,7 @@ export function buildBatchEditTool(io) {
395
396
  try {
396
397
  for (const u of undos) {
397
398
  abortIf(signal);
398
- await io.writeText(u.file.absolutePath, u.file.bom + restoreEndings(u.file.result, u.file.originalEnding), signal, exec);
399
+ await io.writeText(u.file.absolutePath, u.file.bom + restoreEndings(u.file.result, u.file.originalEnding), signal, exec, sandboxPolicy);
399
400
  written.push(u);
400
401
  }
401
402
  }
@@ -403,7 +404,7 @@ export function buildBatchEditTool(io) {
403
404
  for (const w of written) {
404
405
  try {
405
406
  await io.writeText(w.file.absolutePath, w.file.bom +
406
- restoreEndings(w.file.originalNormalized, w.file.originalEnding), undefined, exec);
407
+ restoreEndings(w.file.originalNormalized, w.file.originalEnding), undefined, exec, sandboxPolicy);
407
408
  }
408
409
  catch (restoreError) {
409
410
  console.error("Failed to restore file after batch write failure:", restoreError);
@@ -415,7 +416,7 @@ export function buildBatchEditTool(io) {
415
416
  console.error("Failed to restore undo entry after batch write failure:", restoreError);
416
417
  }
417
418
  }
418
- throw error;
419
+ throw sandbox.mapError(error, sandboxPolicy);
419
420
  }
420
421
  const result = buildBatchResult(processed.map(toSection));
421
422
  if (result.details.servedRows && result.details.servedRows.length > 0) {
@@ -437,6 +438,6 @@ export function buildBatchEditTool(io) {
437
438
  /**
438
439
  * Register the hashline tool on the calling agent’s scope (own layer).
439
440
  */
440
- export function registerBatchEditTool(_rootCtx, agentCtx, io) {
441
- return agentCtx.tools.register(buildBatchEditTool(io));
441
+ export function registerBatchEditTool(_rootCtx, agentCtx, io, sandbox) {
442
+ return agentCtx.tools.register(buildBatchEditTool(io, sandbox));
442
443
  }
package/lib/tool-edit.js CHANGED
@@ -28,7 +28,7 @@ import { withWorkspace } from "./workspace.js";
28
28
  * @param io - the filesystem bridge (ctx.fs backed in deployment).
29
29
  * @returns the exact disposer that unregisters the tool.
30
30
  */
31
- export function buildEditTool(io) {
31
+ export function buildEditTool(io, sandbox) {
32
32
  return defineTool({
33
33
  name: "edit",
34
34
  description: EDIT_DESCRIPTION,
@@ -37,6 +37,7 @@ export function buildEditTool(io) {
37
37
  remove_from: removeFromSchema,
38
38
  remove_to: removeToSchema,
39
39
  replacement_text: replacementTextSchema,
40
+ ...(sandbox.escalationModes.length > 0 ? sandbox.schemaFields() : {}),
40
41
  },
41
42
  output: {
42
43
  schema: { type: "string" },
@@ -55,6 +56,7 @@ export function buildEditTool(io) {
55
56
  canonical.path = resolution.path;
56
57
  }
57
58
  assertReq(canonical);
59
+ const sandboxPolicy = await sandbox.resolvePolicy("edit", canonical, exec);
58
60
  const normalizedParams = canonical;
59
61
  const path = normalizedParams.path;
60
62
  abortIf(signal);
@@ -112,11 +114,11 @@ export function buildEditTool(io) {
112
114
  }
113
115
  try {
114
116
  abortIf(signal);
115
- await io.writeText(absolutePath, bom + restoreEndings(result, originalEnding), signal, exec);
117
+ await io.writeText(absolutePath, bom + restoreEndings(result, originalEnding), signal, exec, sandboxPolicy);
116
118
  }
117
119
  catch (error) {
118
120
  await undo.restore();
119
- throw error;
121
+ throw sandbox.mapError(error, sandboxPolicy);
120
122
  }
121
123
  const updatedSnapshotId = await snapshotIdFor(io, absolutePath, signal);
122
124
  const editMeta = {
@@ -150,6 +152,6 @@ export function buildEditTool(io) {
150
152
  /**
151
153
  * Register the hashline tool on the calling agent’s scope (own layer).
152
154
  */
153
- export function registerEditTool(_rootCtx, agentCtx, io) {
154
- return agentCtx.tools.register(buildEditTool(io));
155
+ export function registerEditTool(_rootCtx, agentCtx, io, sandbox) {
156
+ return agentCtx.tools.register(buildEditTool(io, sandbox));
155
157
  }
package/lib/tool-undo.js CHANGED
@@ -15,6 +15,7 @@ import { getUndo, clearUndo } from "./undo-edit.js";
15
15
  import { recordServedTruncated } from "./served-store.js";
16
16
  import { UNDO_DESCRIPTION } from "./prompts.js";
17
17
  import { execCwd, execSessionKey } from "./dsh-context.js";
18
+ import { FsSandboxController } from "./sandbox.js";
18
19
  import { withWorkspace } from "./workspace.js";
19
20
  function assertUndoReq(request) {
20
21
  if (!isRec(request)) {
@@ -32,7 +33,7 @@ function assertUndoReq(request) {
32
33
  * @param io - the filesystem bridge.
33
34
  * @returns the exact disposer that unregisters the tool.
34
35
  */
35
- export function buildUndoTool(io) {
36
+ export function buildUndoTool(io, sandbox) {
36
37
  return defineTool({
37
38
  name: "undo_last_edit",
38
39
  description: UNDO_DESCRIPTION,
@@ -42,6 +43,7 @@ export function buildUndoTool(io) {
42
43
  required: true,
43
44
  description: "Path to the file to undo",
44
45
  },
46
+ ...(sandbox.escalationModes.length > 0 ? sandbox.schemaFields() : {}),
45
47
  },
46
48
  output: {
47
49
  schema: { type: "string" },
@@ -56,6 +58,7 @@ export function buildUndoTool(io) {
56
58
  assertUndoReq(canonical);
57
59
  const path = canonical.path;
58
60
  const absolutePath = await io.resolve(path, cwd, signal);
61
+ const sandboxPolicy = await sandbox.resolvePolicy("undo_last_edit", canonical, exec);
59
62
  const undo = await getUndo(absolutePath);
60
63
  if (!undo) {
61
64
  return `No undo history for ${path}. There is no previous edit to revert.`;
@@ -86,7 +89,12 @@ export function buildUndoTool(io) {
86
89
  const undoDiffResult = genDiff(currentNormalized, undo.content, 1, undo.hashes, currentHashes);
87
90
  const undoDiff = undoDiffResult.diff;
88
91
  const restoredRange = changedRange(currentNormalized, undo.content);
89
- await io.writeText(absolutePath, undo.bom + restoreEndings(undo.content, undo.originalEnding), signal, exec);
92
+ try {
93
+ await io.writeText(absolutePath, undo.bom + restoreEndings(undo.content, undo.originalEnding), signal, exec, sandboxPolicy);
94
+ }
95
+ catch (error) {
96
+ throw sandbox.mapError(error, sandboxPolicy);
97
+ }
90
98
  try {
91
99
  await upsertSnapshotFor(absolutePath, contentChecksum(undo.content), splitLines(undo.content).length, undo.hashes);
92
100
  }
@@ -110,6 +118,6 @@ export function buildUndoTool(io) {
110
118
  /**
111
119
  * Register the hashline tool on the calling agent’s scope (own layer).
112
120
  */
113
- export function registerUndoTool(_rootCtx, agentCtx, io) {
114
- return agentCtx.tools.register(buildUndoTool(io));
121
+ export function registerUndoTool(_rootCtx, agentCtx, io, sandbox) {
122
+ return agentCtx.tools.register(buildUndoTool(io, sandbox));
115
123
  }
@@ -17,6 +17,7 @@
17
17
  import type { Context } from "@deepseek-ai/cordis";
18
18
  import type { FileSystem } from "@deepseek-ai/dsh-fs";
19
19
  import type { ToolExecution } from "@deepseek-ai/dsh-tools";
20
+ import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
20
21
  /** Text-IO operations the hashline tools need, keyed by canonical absolute path. */
21
22
  export interface FileIO {
22
23
  /** Resolve a (possibly relative) request path against the session cwd to a canonical absolute path. */
@@ -25,12 +26,16 @@ export interface FileIO {
25
26
  readText(absolutePath: string, signal?: AbortSignal): Promise<string>;
26
27
  /**
27
28
  * Atomically write whole text, preserving mode when the file exists. On the
28
- * dsh backend this dispatches `fs/write-intent` (policy guard) and emits
29
+ * dsh backend this dispatches `fs/write-intent` (policy guard), stamps the
30
+ * sandbox policy (session workspace root + mode) onto the write, and emits
29
31
  * `fs/observed` with the new version on success, so later built-in tools
30
32
  * see a fresh observation.
31
33
  * @param exec - the calling execution; carries the session the policy keys by.
34
+ * @param sandboxPolicy - the per-call sandbox mode + workspace root the
35
+ * confined backend checks (resolved from the session by the tool layer);
36
+ * omitted on an unsandboxed backend.
32
37
  */
33
- writeText(absolutePath: string, content: string, signal?: AbortSignal, exec?: ToolExecution): Promise<void>;
38
+ writeText(absolutePath: string, content: string, signal?: AbortSignal, exec?: ToolExecution, sandboxPolicy?: SandboxExecutionPolicy): Promise<void>;
34
39
  /**
35
40
  * Emit `fs/observed` (present at the current version) for a successful
36
41
  * read, so the policy records that this session has seen the file.
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The sandbox-escalation API for the hashline mutating tools, mirroring
3
+ * `@deepseek-ai/dsh-tool-fs`'s `FsSandboxController` (same vocabulary, same
4
+ * fail-closed approval sequence, shared `@deepseek-ai/dsh-sandbox` pieces) so
5
+ * `edit`/`batch_edit`/`undo_last_edit` escalate exactly like the built-in
6
+ * `write`/`edit` — and, critically, stamp the per-call policy with the SESSION
7
+ * workspace root. Without the policy the sandbox backend falls back to the
8
+ * deployment default root, so an edit inside the session workspace is denied
9
+ * under `workspace-write` even though the built-in `write` succeeds there.
10
+ * @module dsh-better-edit/sandbox
11
+ */
12
+ import type { Context } from '@deepseek-ai/cordis';
13
+ import type { ToolExecution } from '@deepseek-ai/dsh-tools';
14
+ import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox';
15
+ /** The two escalation arguments a mutating tool may carry (advertised only under a confining backend). */
16
+ export interface FsEscalationArgs {
17
+ sandbox_permissions?: string;
18
+ justification?: string;
19
+ }
20
+ /** The schema fields for the escalation arguments, spread into a tool's `parameters` when a confining backend is mounted. */
21
+ export interface EscalationSchemaFields {
22
+ sandbox_permissions: {
23
+ type: 'string';
24
+ enum: string[];
25
+ description: string;
26
+ };
27
+ justification: {
28
+ type: 'string';
29
+ description: string;
30
+ };
31
+ }
32
+ /**
33
+ * The filesystem escalation API: advertisement gating, per-call policy
34
+ * resolution, the one-approved wider retry, and denial-marker mapping. A pure
35
+ * product of `ctx` at plugin apply time.
36
+ */
37
+ export declare class FsSandboxController {
38
+ private readonly ctx;
39
+ /** The escalation targets this composition advertises (`[]` when no confining backend is mounted). */
40
+ readonly escalationModes: readonly SandboxMode[];
41
+ /** Shared per-session policy resolver, required by a confining backend. */
42
+ private readonly policy;
43
+ constructor(ctx: Context);
44
+ /**
45
+ * The escalation schema fields for a mutating tool's `parameters`. Call it
46
+ * only under a confining backend (guard on {@link escalationModes}); the
47
+ * enum pins the closed target vocabulary, the strict-wider check happens
48
+ * per call at execution.
49
+ */
50
+ schemaFields(): EscalationSchemaFields;
51
+ /**
52
+ * The policy to stamp onto this mutation: an approved escalation grant (a
53
+ * strictly wider retry resolved through `ctx.approval` before anything
54
+ * executes), else the session's standing mode. The calling session's cwd is
55
+ * always carried as the workspace root, so `workspace-write` allows writes
56
+ * inside the session workspace.
57
+ * @param toolName - the mutating tool's name, for the approval audit trail.
58
+ * @param args - the call's escalation arguments.
59
+ * @param exec - the tool-execution context (agent, callId, signal).
60
+ * @returns the policy to pass to the mutation, or undefined for an
61
+ * unsandboxed backend.
62
+ */
63
+ resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined>;
64
+ /**
65
+ * Map a thrown provider error for the model: a `FS_SANDBOX_DENIED` becomes
66
+ * the shared `[sandbox: …]` denial marker plus the same-turn escalation
67
+ * hint, keeping the structured code. Any other error passes through.
68
+ */
69
+ mapError(error: unknown, policy: SandboxExecutionPolicy | undefined): unknown;
70
+ }
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { Context } from "@deepseek-ai/cordis";
9
9
  import type { FileIO } from "./fs-bridge.js";
10
+ import type { FsSandboxController } from "./sandbox.js";
10
11
  /**
11
12
  * Register the `batch_edit` tool on the calling agent's scope.
12
13
  * @param _rootCtx - host context.
@@ -14,8 +15,8 @@ import type { FileIO } from "./fs-bridge.js";
14
15
  * @param io - the filesystem bridge.
15
16
  * @returns the exact disposer that unregisters the tool.
16
17
  */
17
- export declare function buildBatchEditTool(io: FileIO): import("@deepseek-ai/dsh-tools").ToolDefinition;
18
+ export declare function buildBatchEditTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
18
19
  /**
19
20
  * Register the hashline tool on the calling agent’s scope (own layer).
20
21
  */
21
- export declare function registerBatchEditTool(_rootCtx: Context, agentCtx: Context, io: FileIO): () => void;
22
+ export declare function registerBatchEditTool(_rootCtx: Context, agentCtx: Context, io: FileIO, sandbox: FsSandboxController): () => void;
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { Context } from "@deepseek-ai/cordis";
9
9
  import type { FileIO } from "./fs-bridge.js";
10
+ import type { FsSandboxController } from "./sandbox.js";
10
11
  /**
11
12
  * Register the hash-anchored `edit` tool on the calling agent's scope.
12
13
  * @param _rootCtx - host context (logger, lifecycle).
@@ -15,8 +16,8 @@ import type { FileIO } from "./fs-bridge.js";
15
16
  * @param io - the filesystem bridge (ctx.fs backed in deployment).
16
17
  * @returns the exact disposer that unregisters the tool.
17
18
  */
18
- export declare function buildEditTool(io: FileIO): import("@deepseek-ai/dsh-tools").ToolDefinition;
19
+ export declare function buildEditTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
19
20
  /**
20
21
  * Register the hashline tool on the calling agent’s scope (own layer).
21
22
  */
22
- export declare function registerEditTool(_rootCtx: Context, agentCtx: Context, io: FileIO): () => void;
23
+ export declare function registerEditTool(_rootCtx: Context, agentCtx: Context, io: FileIO, sandbox: FsSandboxController): () => void;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { Context } from "@deepseek-ai/cordis";
8
8
  import type { FileIO } from "./fs-bridge.js";
9
+ import { FsSandboxController } from "./sandbox.js";
9
10
  /**
10
11
  * Register the `undo_last_edit` tool on the calling agent's scope.
11
12
  * @param _rootCtx - host context.
@@ -13,8 +14,8 @@ import type { FileIO } from "./fs-bridge.js";
13
14
  * @param io - the filesystem bridge.
14
15
  * @returns the exact disposer that unregisters the tool.
15
16
  */
16
- export declare function buildUndoTool(io: FileIO): import("@deepseek-ai/dsh-tools").ToolDefinition;
17
+ export declare function buildUndoTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
17
18
  /**
18
19
  * Register the hashline tool on the calling agent’s scope (own layer).
19
20
  */
20
- export declare function registerUndoTool(_rootCtx: Context, agentCtx: Context, io: FileIO): () => void;
21
+ export declare function registerUndoTool(_rootCtx: Context, agentCtx: Context, io: FileIO, sandbox: FsSandboxController): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/edit/batch_edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
6
6
  "main": "lib/index.js",
@@ -52,7 +52,8 @@
52
52
  "dependencies": {
53
53
  "diff": "^8.0.2",
54
54
  "file-type": "^21.3.0",
55
- "xxhash-wasm": "^1.1.0"
55
+ "xxhash-wasm": "^1.1.0",
56
+ "@deepseek-ai/dsh-sandbox": "^0.1.0-rc.6"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "@deepseek-ai/cordis": "^4.0.0",