dsh-better-edit 1.2.2 → 1.2.4

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.
@@ -29,7 +29,7 @@ import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
29
29
  import type { FsSandboxController } from "./sandbox.js";
30
30
  import type { LineEnding } from "./edit-diff.js";
31
31
  import { scanDrift } from "./session-view.js";
32
- import { runFileEdits, resolveMissingPath } from "./mutation/engine.js";
32
+ import { runFileEdits } from "./mutation/engine.js";
33
33
  import type { FileEditResult, PreparedItem } from "./mutation/engine.js";
34
34
  import { restoreEndings } from "./edit-diff.js";
35
35
  import { buildMetrics, buildNoop, buildChanged, buildBatchResult } from "./edit-response.js";
@@ -41,7 +41,7 @@ import { trackNoopPayload, clearNoopLoop, noopPayloadKey } from "./noop-guard.js
41
41
  export declare function resolveDisplayPath(path: string, cwd: string): string;
42
42
  /** Snapshot bookkeeping for noop/success results (best-effort). */
43
43
  export declare function snapshotIdFor(io: FileIO, absolutePath: string, signal?: AbortSignal): Promise<string | undefined>;
44
- export { runFileEdits, resolveMissingPath };
44
+ export { runFileEdits };
45
45
  export { persistUndoAndWrite };
46
46
  export type { FileEditResult, PreparedItem };
47
47
  export { buildMetrics, buildNoop, buildChanged, buildBatchResult };
@@ -77,7 +77,7 @@ declare function commitBatch(opts: Omit<PersistWriteOptions, "restoreUnwrittenUn
77
77
  * Owns: applySequence → branch (single/multi × noop/applied) → commit →
78
78
  * buildBatchResult → recordServedTruncated → return text.
79
79
  *
80
- * The tool layer (adapter) only validates and resolves the nullable path; all
80
+ * The tool layer (adapter) only validates and delegates; all
81
81
  * lifecycle branching concentrates here (locality). One interface serves N
82
82
  * call sites (leverage). Deleting this module would scatter the lifecycle
83
83
  * across every tool — it concentrates (deep).
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Preset tool-policy gate: which hashline-owned tools one agent install may
3
+ * register. The registry cannot enforce a preset's policy for this plugin —
4
+ * scope restrictions filter only *inherited* tools, never a scope's own
5
+ * registrations (Rianico/dsh-better-edit#110) — so the install consults the
6
+ * composed preset's own layer instead.
7
+ *
8
+ * `read` is unconditional: it is the plugin's core capability and the source of
9
+ * every anchor. Every mutating tool is installed only when the preset's layer
10
+ * resolves the matching tool, which keeps `edit` paired with `read` and never
11
+ * shadows a tool the preset did not compose.
12
+ *
13
+ * The probe is an optional-service seam: no `agentPresets` service, no composed
14
+ * preset (preset-free composition), or no scope-read API (`acquireScope` on
15
+ * 0.2.x, `standingKeyFor` on older registries) keeps today's unconditional
16
+ * install, so a host that predates 0.2.1 keeps its pre-gate behavior.
17
+ * @module dsh-better-edit/preset-toolset
18
+ */
19
+ import type { Context } from "@deepseek-ai/cordis";
20
+ /** The hashline-owned tools one install may register. `read` is always installed. */
21
+ export interface HashlineToolset {
22
+ /** The hashline `edit` (also gates `undo`). */
23
+ edit: boolean;
24
+ /** The governed `str_replace_editor` shadow (ADR-0015). */
25
+ strReplaceEditor: boolean;
26
+ /** `undo_last_edit` — follows {@link HashlineToolset.edit}, see {@link toolsetFor}. */
27
+ undo: boolean;
28
+ /** A preset that neither resolves `write` nor composed one needs no guard. */
29
+ writeHook: boolean;
30
+ }
31
+ /** Today's install — the fallback for every composition the gate cannot read. */
32
+ export declare const UNCONDITIONAL_TOOLSET: HashlineToolset;
33
+ /**
34
+ * Derive the toolset from one predicate over preset tool names. `undo` follows
35
+ * `edit` because `undo_last_edit` reverts only hashline edits: installing it
36
+ * beside no `edit` would advertise a history that can never exist.
37
+ */
38
+ export declare function toolsetFor(resolves: (name: string) => boolean): HashlineToolset;
39
+ /**
40
+ * Keep only the guidance sections whose tool was installed. `tool:read` always
41
+ * stays; the edit and undo sections follow their tools so the prompt never
42
+ * advertises a catalog entry the agent does not have.
43
+ */
44
+ export declare function sectionsForToolset<T extends {
45
+ name: string;
46
+ }>(sections: readonly T[], toolset: HashlineToolset): T[];
47
+ /** The host surface the probe touches; `logger` is optional so a bare host works. */
48
+ export interface PresetProbeHost {
49
+ get(service: string): object | undefined;
50
+ logger?: {
51
+ warn(message: string): void;
52
+ };
53
+ }
54
+ /**
55
+ * Resolve the toolset for one agent from its composed preset. Every failure —
56
+ * a missing service, an unreadable preset, a rejected scope read, or a throwing
57
+ * registry — falls back to {@link UNCONDITIONAL_TOOLSET} (and warns), never to a
58
+ * smaller set: the gate may only ever remove a tool it has positively seen the
59
+ * preset decline.
60
+ */
61
+ export declare function resolveToolset(host: PresetProbeHost, agentCtx: Context): Promise<HashlineToolset>;
@@ -43,7 +43,7 @@ export interface ReadAndServeResult {
43
43
  * carries the UTF-8 rewrite note when the file had decode errors.
44
44
  *
45
45
  * Emits nothing on the fs-observation gate — callers that need the
46
- * observation recorded (the `read` tool) do that themselves with their exec
47
- * context.
46
+ * observation recorded (the `read` tool and the write auto-read hook) do that
47
+ * themselves with their exec context.
48
48
  */
49
49
  export declare function readAndServe(io: FileIO, rawPath: string, cwd: string, options: ReadAndServeOptions): Promise<ReadAndServeResult>;
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Self-healing watcher for hash-anchored tools.
3
- * Restores `read`/`edit` on the agent's own scope layer if an external
4
- * preset deletes them (e.g. router-standard stage advance).
3
+ * Restores the hashline tools the install actually registered when an external
4
+ * preset deletes them (e.g. router-standard stage advance). The heal set is the
5
+ * installed set: a tool the preset gate declined has no definition to restore,
6
+ * so a `tools/change` can never resurrect it (Rianico/dsh-better-edit#110).
5
7
  * See Rianico/dsh-better-edit#43.
6
8
  * @module dsh-better-edit/self-heal
7
9
  */
@@ -23,7 +25,11 @@ export interface SelfHealOptions {
23
25
  };
24
26
  toolsSvc: unknown;
25
27
  hashReadDef: unknown;
26
- hashEditDef: unknown;
28
+ /**
29
+ * Omitted when the preset gate declined the hashline `edit`: an absent
30
+ * definition is the watcher's "never heal this" signal, not a takeover.
31
+ */
32
+ hashEditDef?: unknown;
27
33
  /** ADR-0015 shadow def; when present the watcher also heals `str_replace_editor`. */
28
34
  hashStrReplaceDef?: unknown;
29
35
  healMinIntervalMs?: number;
@@ -60,6 +60,16 @@ export declare function loadRetiredAnchors(sessionKey: string, path: string): Pr
60
60
  export declare function retireAnchorsInStore(store: ServedPersistence, sessionKey: string, path: string, hashes: Iterable<string>): void;
61
61
  /** Keep freed anchors dead for this session until it has seen the whole file again. */
62
62
  export declare function retireAnchors(sessionKey: string, path: string, hashes: Iterable<string>): Promise<void>;
63
+ /**
64
+ * Caller-owned transaction: revive retired anchors inside the caller's unit.
65
+ *
66
+ * The undo restore is the one path that brings a retired assignment back: when the
67
+ * pre-edit line returns byte-identically, its pre-edit anchor is live again, so the
68
+ * retirement that the edit recorded must move with the restore (ADR-0017 reversal).
69
+ * Anchors not in the store's retired set are left untouched; the entry's `deathPos`
70
+ * does not matter — the anchor's line is back, so the whole entry goes.
71
+ */
72
+ export declare function unretireAnchorsInStore(store: ServedPersistence, sessionKey: string, path: string, hashes: Iterable<string>): void;
63
73
  /** Full-file context for a complete read — when present and matching `rows`, the call is a full read. */
64
74
  export interface FullReadContext {
65
75
  hashes: readonly string[];
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * The dsh `edit` tool: hash-anchored literal range edits that shadow the
3
3
  * built-in `edit` on the agent's own scope layer. Now the sole mutation tool
4
- * (batch_edit removed, ADR-0007): payload is { file: string|null, edits: [{anchor_from,anchor_to,replace_with},...] }
5
- * single-file atomic batch, legacy null file inference via anchors.
4
+ * (batch_edit removed, ADR-0007): payload is { file: string, edits: [{anchor_from,anchor_to,replace_with},...] }
5
+ * single-file atomic batch; the file is named explicitly, never inferred (#117).
6
6
  * @module dsh-better-edit/tool-edit
7
7
  */
8
8
  import type { Context } from "@deepseek-ai/cordis";
package/lib/write-hook.js CHANGED
@@ -103,7 +103,16 @@ export function registerWriteHook(rootCtx, agentCtx, io) {
103
103
  const cwd = execCwd(exec);
104
104
  const sessionKey = execSessionKey(exec);
105
105
  const signal = exec.signal;
106
- const { text } = await readAndServe(io, rawPath, cwd, { sessionKey, signal });
106
+ const { text, absolutePath } = await readAndServe(io, rawPath, cwd, {
107
+ sessionKey,
108
+ signal,
109
+ });
110
+ // Record the present observation with the fs policy gate so later
111
+ // built-in write/edit calls see this file as observed at the version
112
+ // these rows describe — this block advertises every row above as an
113
+ // anchor, and the gate only knows a version it was told about
114
+ // (a no-op when no policy listens).
115
+ await io.emitObserved(absolutePath, exec, signal);
107
116
  return {
108
117
  kind: "accept",
109
118
  content: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
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",