dsh-better-edit 0.8.1 → 0.8.2

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/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
+ ## [0.8.2](https://github.com/Rianico/dsh-better-edit/compare/v0.8.1...v0.8.2) (2026-09-14)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **str-replace:** stamp the sandbox policy on shadow writes ([#72](https://github.com/Rianico/dsh-better-edit/issues/72)) ([1afaa53](https://github.com/Rianico/dsh-better-edit/commit/1afaa53bfd65dbcbebdcffb673a6c3923abc3045))
6
+
1
7
  ## [0.8.1](https://github.com/Rianico/dsh-better-edit/compare/v0.8.0...v0.8.1) (2026-09-11)
2
8
 
3
9
  ### Bug Fixes
4
10
 
5
- * **str-replace:** record real fs version so view/read authorizes str_replace/insert ([#70](https://github.com/Rianico/dsh-better-edit/issues/70)) ([06b76ff](https://github.com/Rianico/dsh-better-edit/commit/06b76ffec4c0393f790d2195c06910328b611059))
11
+ - **str-replace:** record real fs version so view/read authorizes str_replace/insert ([#70](https://github.com/Rianico/dsh-better-edit/issues/70)) ([06b76ff](https://github.com/Rianico/dsh-better-edit/commit/06b76ffec4c0393f790d2195c06910328b611059))
6
12
 
7
13
  ### Documentation
8
14
 
9
- * add PR template and document PR requirements via git scaffolding ([#68](https://github.com/Rianico/dsh-better-edit/issues/68)) ([b341fbc](https://github.com/Rianico/dsh-better-edit/commit/b341fbc778868496bdee2e49801c5cf3745d1c99))
15
+ - add PR template and document PR requirements via git scaffolding ([#68](https://github.com/Rianico/dsh-better-edit/issues/68)) ([b341fbc](https://github.com/Rianico/dsh-better-edit/commit/b341fbc778868496bdee2e49801c5cf3745d1c99))
10
16
 
11
17
  ## [0.8.0](https://github.com/Rianico/dsh-better-edit/compare/v0.7.1...v0.8.0) (2026-09-09)
12
18
 
package/lib/index.js CHANGED
@@ -73,7 +73,7 @@ function installAgentTools(rootCtx, agent) {
73
73
  disposers.push(agent.ctx.tools.register(hashEditDef));
74
74
  // Governed shadow of the preset's built-in str_replace_editor
75
75
  // (ADR-0015): identical contract, encoding-governed mutations.
76
- const hashStrReplaceDef = buildStrReplaceEditorTool(io);
76
+ const hashStrReplaceDef = buildStrReplaceEditorTool(io, sandbox);
77
77
  disposers.push(agent.ctx.tools.register(hashStrReplaceDef));
78
78
  disposers.push(registerUndoTool(rootCtx, agent.ctx, io, sandbox));
79
79
  disposers.push(registerWriteHook(rootCtx, agent.ctx, io));
@@ -13,6 +13,11 @@
13
13
  * - `create` defaults to UTF-8 without BOM.
14
14
  * - `undo_edit` is out of scope → `E_UNSUPPORTED` (use `undo_last_edit`).
15
15
  *
16
+ * - `create` / `str_replace` / `insert` stamp the per-call sandbox policy from
17
+ * `FsSandboxController` (the calling session's workspace root plus any
18
+ * approved one-shot escalation), matching the built-in and the hashline
19
+ * `edit` / `undo_last_edit` paths; unconfined deployments stamp `undefined`.
20
+ *
16
21
  * See ADR-0015.
17
22
  * @module dsh-better-edit/tool-str-replace-editor
18
23
  */
@@ -74,6 +79,27 @@ async function requireObserved(io, absolutePath, displayPath, signal) {
74
79
  throw argError("E_BLIND_REPLACE", `str_replace_editor: ${displayPath} has not been viewed in this session (no file encoding state at the current version). Call view first, then retry. Nothing was written.`);
75
80
  }
76
81
  }
82
+ /**
83
+ * Governed save: resolve the per-call sandbox policy — the session's standing
84
+ * mode stamped with the calling session's workspace root, or an approved
85
+ * one-shot escalation grant — and hand it to the provider write; a sandbox
86
+ * denial is remapped to the shared `[sandbox: …]` marker plus the escalation
87
+ * hint so the caller can retry once.
88
+ *
89
+ * Without it the confined backend falls back to the deployment default root,
90
+ * so a write inside the session workspace is denied under `workspace-write`
91
+ * even though the built-in `str_replace_editor` (which carries the policy)
92
+ * succeeds there. Mirrors the hashline `edit` / `undo_last_edit` path.
93
+ */
94
+ async function writeGoverned(io, sandbox, absolutePath, content, args, exec) {
95
+ const policy = await sandbox.resolvePolicy("str_replace_editor", args, exec);
96
+ try {
97
+ await io.writeText(absolutePath, content, exec.signal, exec, policy);
98
+ }
99
+ catch (error) {
100
+ throw sandbox.mapError(error, policy);
101
+ }
102
+ }
77
103
  function countOccurrences(haystack, needle) {
78
104
  if (needle.length === 0)
79
105
  return 0;
@@ -99,7 +125,7 @@ function autoGuessWarning(absolutePath, rawPath) {
99
125
  getAutoGuessFooter(absolutePath.replace(/\\/g, "/")) ??
100
126
  undefined);
101
127
  }
102
- export function buildStrReplaceEditorTool(io) {
128
+ export function buildStrReplaceEditorTool(io, sandbox) {
103
129
  return defineTool({
104
130
  name: "str_replace_editor",
105
131
  description: STR_REPLACE_EDITOR_DESCRIPTION,
@@ -134,6 +160,7 @@ export function buildStrReplaceEditorTool(io) {
134
160
  type: "string",
135
161
  description: "Full content for create",
136
162
  },
163
+ ...(sandbox.escalationModes.length > 0 ? sandbox.schemaFields() : {}),
137
164
  },
138
165
  output: {
139
166
  schema: {
@@ -201,7 +228,7 @@ export function buildStrReplaceEditorTool(io) {
201
228
  throw argError("E_FILE_EXISTS", `str_replace_editor: cannot create ${rawPath} — file already exists.`);
202
229
  }
203
230
  // Governed default: UTF-8 without BOM (no memo → no BOM).
204
- await io.writeText(absolutePath, fileText, signal, exec);
231
+ await writeGoverned(io, sandbox, absolutePath, fileText, rec, exec);
205
232
  try {
206
233
  const version = await io.statVersion(absolutePath, signal);
207
234
  recordOpenState(absolutePath, fileText, "utf8", false, version);
@@ -236,7 +263,7 @@ export function buildStrReplaceEditorTool(io) {
236
263
  throw argError("E_AMBIGUOUS_MATCH", `str_replace_editor: old_str has multiple matches (${matches}) in ${rawPath} — must match exactly once. Narrow old_str with more context. Nothing was written.`);
237
264
  }
238
265
  const next = restoreForSave(current.replace(oldStr, newStr), absolutePath);
239
- await io.writeText(absolutePath, next, signal, exec);
266
+ await writeGoverned(io, sandbox, absolutePath, next, rec, exec);
240
267
  return { text: `Replaced 1 occurrence in ${rawPath}.` };
241
268
  }
242
269
  // insert
@@ -262,13 +289,13 @@ export function buildStrReplaceEditorTool(io) {
262
289
  if (endsWithNL && out2.length > 0)
263
290
  out2 += "\n";
264
291
  const next = restoreForSave(out2, absolutePath);
265
- await io.writeText(absolutePath, next, signal, exec);
292
+ await writeGoverned(io, sandbox, absolutePath, next, rec, exec);
266
293
  return { text: `Inserted ${added.length} line(s) at line ${insertAt} in ${rawPath}.` };
267
294
  });
268
295
  },
269
296
  });
270
297
  }
271
298
  /** Register the shadow `str_replace_editor` on the calling agent's scope (own layer). */
272
- export function registerStrReplaceEditorTool(agentCtx, io) {
273
- return agentCtx.tools.register(buildStrReplaceEditorTool(io));
299
+ export function registerStrReplaceEditorTool(agentCtx, io, sandbox) {
300
+ return agentCtx.tools.register(buildStrReplaceEditorTool(io, sandbox));
274
301
  }
@@ -13,15 +13,21 @@
13
13
  * - `create` defaults to UTF-8 without BOM.
14
14
  * - `undo_edit` is out of scope → `E_UNSUPPORTED` (use `undo_last_edit`).
15
15
  *
16
+ * - `create` / `str_replace` / `insert` stamp the per-call sandbox policy from
17
+ * `FsSandboxController` (the calling session's workspace root plus any
18
+ * approved one-shot escalation), matching the built-in and the hashline
19
+ * `edit` / `undo_last_edit` paths; unconfined deployments stamp `undefined`.
20
+ *
16
21
  * See ADR-0015.
17
22
  * @module dsh-better-edit/tool-str-replace-editor
18
23
  */
24
+ import type { FsSandboxController } from "./sandbox.js";
19
25
  import type { FileIO } from "./fs-bridge.js";
20
26
  export declare const STR_REPLACE_EDITOR_DESCRIPTION: string;
21
- export declare function buildStrReplaceEditorTool(io: FileIO): import("@deepseek-ai/dsh-tools").ToolDefinition;
27
+ export declare function buildStrReplaceEditorTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
22
28
  /** Register the shadow `str_replace_editor` on the calling agent's scope (own layer). */
23
29
  export declare function registerStrReplaceEditorTool(agentCtx: {
24
30
  tools: {
25
31
  register(def: unknown): () => void;
26
32
  };
27
- }, io: FileIO): () => void;
33
+ }, io: FileIO, sandbox: FsSandboxController): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Hash-anchored read/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.",
5
5
  "keywords": [
6
6
  "anchors",