dsh-hashline-edit 0.3.11 → 0.4.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.
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Hashline guidance sections for the dsh host layer.
3
3
  *
4
- * Four prompt sections are owned here — `tool:read`, `tool:write`,
5
- * `tool:apply_patch` and `tool:undo_last_edit` — because the hashline tools
6
- * shadow the preset's built-ins and must bring their own brief.
7
- * built-ins and must bring their own brief. The compiled default text IS the
4
+ * Prompt sections are owned here — `tool:read`, `tool:write`, `tool:apply_patch`
5
+ * and `tool:edit` — because the hashline tools shadow the preset's built-ins and
6
+ * must bring their own brief. The compiled default text IS the
8
7
  * pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
9
8
  * and pi hosts cannot drift about the tool contract.
10
9
  *
@@ -36,7 +35,7 @@ export declare function renderSectionDefault(name: string): string;
36
35
  export interface GuidanceToggles {
37
36
  readonly read: boolean;
38
37
  readonly applyPatch: boolean;
39
- readonly undo: boolean;
38
+ readonly edit: boolean;
40
39
  }
41
40
  /**
42
41
  * Register the enabled guidance sections with STATIC bundled text.
@@ -1,48 +1,15 @@
1
- /**
2
- * Hide the native editor tools so precise and batch text changes go through
3
- * `apply_patch`; the host's built-in `write` stays visible for whole-file rewrites.
4
- *
5
- * DSH 0.2.2-rc.1 owns tool declarations in the tool registry, not in the
6
- * `system-prompt/assemble` waterfall: the waterfall receives sections, contexts
7
- * and variables only. The authoritative schema filter is therefore the
8
- * per-agent registry restriction (`tools.restrict({ deny })`), which removes a
9
- * global tool from both the native schema list and the PTC `tools:sdk` section
10
- * because both are rendered from `tools.definitions(scope, toolSet)`.
11
- *
12
- * Three seams still back that up, because a restriction only governs the
13
- * registry view and a stale session or a hand-rolled section could carry a
14
- * residual binding:
15
- *
16
- * 1. `tools.restrict({ deny })` drops the hidden schemas for this agent;
17
- * 2. `system-prompt/assemble` empties the `tool:edit` guidance section (its
18
- * text is prose, never a tool mention) and deletes the hidden tools' member
19
- * blocks from any rendered PTC `tools:sdk` section;
20
- * 3. `tools.guard` is the monotonic execution backstop for a stale schema or
21
- * any residual binding.
22
- *
23
- * Only `edit`/`str_replace_editor` are hidden. `apply_patch` still owns
24
- * whole-file replacement as one `*** Update File:` identity hunk spanning every
25
- * served line with `+` lines for the new content; the built-in `write` remains
26
- * the profile's own whole-file rewrite path, integrated by `write-hook.ts`.
27
- * The native `apply_patch` name is also denied in the inherited/preset layer
28
- * when it exists; the plugin's own scoped registration shadows it otherwise.
29
- *
30
- * The layer is installed only when `apply_patch` actually registered: hiding
31
- * the native editors without the replacement would leave the profile with no
32
- * precise-edit entry point.
33
- *
34
- * @module dsh-hashline-edit/hide
35
- */
36
1
  /** A boolean config value, or a live getter (used when a host exposes volatile config). */
37
2
  type BooleanSource = boolean | (() => boolean);
38
3
  /** The hide-layer configuration after the plugin-level defaults are applied. */
39
4
  export interface NativeHideConfig {
40
- /** The registered replacement tool name, protected from `hiddenToolNames`. */
41
- readonly toolName: string;
5
+ /** The tool names this plugin registered; never part of the hidden set. */
6
+ readonly toolNames: readonly string[];
42
7
  /** Hide `edit`/`str_replace_editor`; defaults to true. The host's `write` stays visible. */
43
8
  readonly hideNativeWriteTools?: BooleanSource;
44
9
  /** Extra global tool names to hide alongside the native set. */
45
10
  readonly hiddenToolNames?: readonly string[];
11
+ /** Guidance sections to empty because this plugin provides no such tool. */
12
+ readonly guidanceToClear?: readonly string[];
46
13
  /** The Agent scope key used for the agent-view probe; absent keeps the global probe. */
47
14
  readonly scope?: unknown;
48
15
  }
@@ -68,8 +35,8 @@ declare function warn(rootCtx: {
68
35
  logger?: LoggerLike;
69
36
  }, message: string): void;
70
37
  /**
71
- * Install the hide layer for one agent. Only call this after `apply_patch`
72
- * registered successfully.
38
+ * Install the hide layer for one agent. Only call this after at least one
39
+ * mutation tool registered successfully.
73
40
  *
74
41
  * @param rootCtx - the plugin/root scope, used for the global-name probe and warnings.
75
42
  * @param agentCtx - the agent scope whose tool view is restricted.
@@ -4,15 +4,16 @@
4
4
  * On every `agent/created`, install the hashline tools on the AGENT's
5
5
  * own scope layer so they shadow the preset's built-in `read` for that
6
6
  * agent (nearest layer wins in dsh's tool registry) and unwind automatically
7
- * when the agent is disposed. The native `edit` and `str_replace_editor`
8
- * schemas are hidden on the same scope, so `apply_patch` owns precise and
9
- * batch text changes. The host's built-in `write` stays visible and is
10
- * integrated by the write hook.
7
+ * when the agent is disposed. The native `edit`, `str_replace_editor` and
8
+ * native `apply_patch` names are hidden on the same scope once the plugin's own
9
+ * replacement registers, so this plugin's `apply_patch` and `edit` tools own
10
+ * precise and batch text changes. The host's built-in `write` stays visible and
11
+ * is integrated by the write hook.
11
12
  *
12
13
  * `inject` deliberately lists only `tools` and `systemPrompt`: the read-path
13
14
  * `ctx.fs` bridge is optional and resolved with `ctx.get`, so a minimal
14
15
  * composition still loads with the local `node:fs` fallback. apply_patch and
15
- * undo stay local-only (the M5 bridge covers reads; M6 owns mutation).
16
+ * edit stay local-only (the M5 bridge covers reads; M6 owns mutation).
16
17
  * @module dsh-hashline-edit
17
18
  */
18
19
  import type { Context } from "@deepseek-ai/cordis";
@@ -34,11 +35,11 @@ export declare const inject: string[];
34
35
  export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
35
36
  read: Schema<boolean, boolean, "volatile-defined">;
36
37
  applyPatch: Schema<boolean, boolean, "volatile-defined">;
37
- undo: Schema<boolean, boolean, "volatile-defined">;
38
+ edit: Schema<boolean, boolean, "volatile-defined">;
38
39
  }>>, Schemastery.ObjectT<NoInfer<{
39
40
  read: Schema<boolean, boolean, "volatile-defined">;
40
41
  applyPatch: Schema<boolean, boolean, "volatile-defined">;
41
- undo: Schema<boolean, boolean, "volatile-defined">;
42
+ edit: Schema<boolean, boolean, "volatile-defined">;
42
43
  }>>, "plain">;
43
44
  /** The plugin configuration the loader passes as the second `apply` argument. */
44
45
  export interface PluginConfig {
@@ -48,24 +49,25 @@ export interface PluginConfig {
48
49
  */
49
50
  read?: boolean;
50
51
  /**
51
- * Expose the hashline `apply_patch` tool and hide the native
52
- * `edit`/`apply_patch`/`str_replace_editor` tools. Defaults to true;
53
- * off keeps every native editor tool. The host's `write` is never hidden.
52
+ * Expose the hashline `apply_patch` tool. Defaults to true. With either
53
+ * mutation tool on, the native `edit`/`apply_patch`/`str_replace_editor`
54
+ * names are hidden for the agent; the host's `write` is never hidden.
54
55
  */
55
56
  applyPatch?: boolean;
56
57
  /**
57
- * Expose the `undo_last_edit` tool. Defaults to false. The undo snapshot row is
58
- * still written on every commit; only the model-facing tool is opt-in.
58
+ * Expose the hashline range `edit` tool: one file per call, N anchored range
59
+ * items. Defaults to false. It shares the served anchors, the store and the
60
+ * mutation queue with `apply_patch`; both may be on at once.
59
61
  */
60
- undo?: boolean;
62
+ edit?: boolean;
61
63
  }
62
64
  /** The three feature switches after the shipped defaults are applied. */
63
65
  export interface ResolvedSwitches {
64
66
  readonly read: boolean;
65
67
  readonly applyPatch: boolean;
66
- readonly undo: boolean;
68
+ readonly edit: boolean;
67
69
  }
68
- /** Resolve the plugin's three switches with the shipped defaults: read and apply_patch on, undo off. */
70
+ /** Resolve the plugin's three switches with the shipped defaults: read and apply_patch on, edit off. */
69
71
  export declare function resolveSwitches(config?: PluginConfig): ResolvedSwitches;
70
72
  /**
71
73
  * Install the hashline toolset for one agent inside its own effect, so the
@@ -0,0 +1,3 @@
1
+ import type { ToolDefinition } from "@deepseek-ai/dsh-tools";
2
+ import type { ToolDependencies } from "../contracts.js";
3
+ export declare function buildEditTool(deps: ToolDependencies): ToolDefinition;
@@ -0,0 +1,41 @@
1
+ /** SAFETY: EditTool — deep module owning the edit Use Case seam.
2
+ *
3
+ * Graded surface: one narrow interface `EditTool { execute, preview }`
4
+ * hides pipeline delegation, warnings/drift stitching.
5
+ * Frameworks (pi TUI) never cross this seam — that lives in TuiPresenter.
6
+ * Clean Architecture: Use Cases depend inward only (mutation-engine),
7
+ * never outward to Frameworks.
8
+ *
9
+ * Typed boundaries: validate once at admission (payload-contract via normReq/assertReq),
10
+ * trust inside. Immutable state: never mutates caller-owned request.
11
+ */
12
+ type EditToolContext = {
13
+ cwd: string;
14
+ sessionManager?: {
15
+ getSessionId(): string;
16
+ };
17
+ };
18
+ type PreviewContext = {
19
+ sessionManager?: {
20
+ getSessionId(): string;
21
+ };
22
+ };
23
+ type PreviewResult = {
24
+ diff: string;
25
+ } | {
26
+ error: string;
27
+ };
28
+ export interface EditTool {
29
+ /** SAFETY: Execute a validated edit; returns pi tool_result or throws on failure. Admission: params validated by normReq/assertReq. */
30
+ execute(params: unknown, signal: AbortSignal | undefined, ctx: EditToolContext): Promise<{
31
+ content: Array<{
32
+ type: "text";
33
+ text: string;
34
+ }>;
35
+ details: unknown;
36
+ }>;
37
+ /** SAFETY: Preview without persisting — mirrors pi's compPreview(request, cwd, ctx). The ctx must carry the session whose serves the anchors came from (#165). */
38
+ preview(request: unknown, cwd: string, ctx: PreviewContext): Promise<PreviewResult>;
39
+ }
40
+ export declare function createEditTool(): EditTool;
41
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * SAFETY: MutationEngine — deep module behind the mutation seam.
3
+ *
4
+ * Small interface: `execute` + `preview`. Deep implementation: load → parse
5
+ * → mutate → finalize → drift → persist → serve hidden inside the pipeline.
6
+ * Internal seams (validate, verify, mutate, guard, persist, record) stay
7
+ * private — not exported. The interface is the test surface.
8
+ *
9
+ * Typed boundaries: validate once at admission (normalized edit-request types),
10
+ * trust inside. Errors fail loud with typed `MutationFailure`.
11
+ */
12
+ import type { PipelineOptions } from "./types.js";
13
+ import type { MutationResult } from "../mutation-result.js";
14
+ import type { NormalizedEditRequest } from "./edit-request.js";
15
+ declare function toFailure(error: unknown): MutationResult;
16
+ /**
17
+ * SAFETY: Execute a mutation against the file system (persist + undo + serve).
18
+ * Returns discriminated `MutationResult` — callers must switch on `ok`.
19
+ *
20
+ * No `any` threading: input is `NormalizedEditRequest` (validated at
21
+ * admission), output is typed. Failures are `ok:false` with `code`, not
22
+ * loose `isError` flags.
23
+ */
24
+ export declare function execute(request: NormalizedEditRequest, cwd: string, options?: PipelineOptions): Promise<MutationResult>;
25
+ /**
26
+ * SAFETY: Preview a mutation without persisting (noPersist). Same seam as `execute`,
27
+ * same `MutationResult` — one interface, N call sites (preview + apply share
28
+ * the internal path via `runMutations` with `noPersist:true`).
29
+ */
30
+ export declare function preview(request: NormalizedEditRequest, cwd: string, options?: Omit<PipelineOptions, "noPersist">): Promise<MutationResult>;
31
+ export { toFailure };
@@ -0,0 +1,35 @@
1
+ import type { DomainErrorCode, RangeCause, ServedRow } from "./domain-errors.js";
2
+ import type { EditDetails, RMetrics } from "./edit-response.js";
3
+ import type { ProcessedEditFile } from "./mutation-engine/types.js";
4
+ export interface MutationSuccess {
5
+ ok: true;
6
+ result: string;
7
+ diff: string;
8
+ drift: string | undefined;
9
+ metrics: RMetrics;
10
+ raw: ProcessedEditFile;
11
+ toolResult: {
12
+ content: Array<{
13
+ type: "text";
14
+ text: string;
15
+ }>;
16
+ details: EditDetails;
17
+ };
18
+ }
19
+ interface MutationFailure {
20
+ ok: false;
21
+ code: DomainErrorCode;
22
+ message: string;
23
+ servedBlock?: string;
24
+ servedRows?: ServedRow[];
25
+ payloadMessage?: string;
26
+ cause?: RangeCause;
27
+ details?: {
28
+ code: DomainErrorCode;
29
+ cause: RangeCause;
30
+ };
31
+ }
32
+ export type MutationResult = MutationSuccess | MutationFailure;
33
+ export declare function isMutationSuccess(r: MutationResult): r is MutationSuccess;
34
+ export declare function isMutationFailure(r: MutationResult): r is MutationFailure;
35
+ export {};
@@ -0,0 +1,64 @@
1
+ import type { EditPlacement } from "./hashline/resolve.js";
2
+ declare const normalizedEdit: unique symbol;
3
+ /**
4
+ * The `text_ref` payload: two inclusive bare anchors bounding a served span, an optional serving
5
+ * `file`, and a REQUIRED `mode` — `"copy"` re-inserts the span bytes, `"cut"` additionally retires
6
+ * them. Both modes apply to this file AND to another served file (ticket-04b): a foreign-source
7
+ * `"cut"` commits the insert and the source retirement as one correlated transaction (ADR-0028).
8
+ */
9
+ type SpanRef = {
10
+ anchor_from: string;
11
+ anchor_to: string;
12
+ file?: string;
13
+ mode: "copy" | "cut";
14
+ };
15
+ type EditMode = "general" | "literal";
16
+ /**
17
+ * Internal normalized vocabulary owned by the admission boundary (ticket-01, renamed ticket-04).
18
+ * The wire never names these shapes: `normReq` builds them once from the validated payload and
19
+ * everything downstream consumes the union — the engine switches on `payload.kind` exhaustively.
20
+ */
21
+ export type Placement = "in-place" | "before" | "after";
22
+ /**
23
+ * @public Intentional surface (knip): the tuple type is the wire/engine
24
+ * vocabulary check, so the binding is never imported — its reason to exist
25
+ * is the typecheck failure it produces when the unions drift.
26
+ */
27
+ export declare const _placementVocabularyAgreement: [
28
+ Placement extends EditPlacement ? true : never,
29
+ EditPlacement extends Placement ? true : never
30
+ ];
31
+ /** The anchor pair an item targets — placement and payload are relative to its resolved span. */
32
+ type AnchorSpan = {
33
+ anchor_from: string;
34
+ anchor_to: string;
35
+ };
36
+ type DesiredContent = {
37
+ kind: "literal";
38
+ text: string;
39
+ } | {
40
+ kind: "reference";
41
+ span: SpanRef;
42
+ mode: "copy" | "cut";
43
+ } | {
44
+ kind: "empty";
45
+ };
46
+ type NormalizedEditItem = {
47
+ target: AnchorSpan;
48
+ at: Placement;
49
+ payload: DesiredContent;
50
+ };
51
+ export type NormalizedEditRequest = {
52
+ file: string;
53
+ edits: NormalizedEditItem[];
54
+ mode?: EditMode;
55
+ };
56
+ type NormalizedPayload = NormalizedEditRequest & {
57
+ readonly [normalizedEdit]: true;
58
+ };
59
+ type RawPayload = string | number | boolean | null | undefined | Record<string, unknown>;
60
+ export type NormReqResult = NormalizedPayload | RawPayload;
61
+ export declare function normReq(input: unknown): NormReqResult;
62
+ export declare function prepareEditArguments(args: unknown): Record<string, unknown>;
63
+ export declare function assertReq(request: unknown): asserts request is NormalizedEditRequest;
64
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * GENERATED FILE — do not edit by hand.
3
+ *
4
+ * Source of truth: `prompts/*.md`. Regenerate with `node scripts/gen-prompts.mjs`
5
+ * (`pnpm run build` runs it first). The prose lives inline so reinstalling the plugin is
6
+ * the only way — and the only needed way — to change what the model reads.
7
+ *
8
+ * @module dsh-hashline-edit/prompts-bundled
9
+ */
10
+ /** Every shipped prompt body, keyed by its `prompts/<name>.md` basename. */
11
+ export declare const BUNDLED_PROMPTS: Readonly<Record<string, string>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.3.11",
4
- "description": "Hash-anchored read/apply_patch tools for DeepSeek Harness (dsh). Every line gets a unique 3- or 4-char hash (A-Za-z0-9, configurable) that stays stable across edits; apply_patch is the only file-mutation entry point and commits one patch batch per transaction. Undo persists across restarts.",
3
+ "version": "0.4.0",
4
+ "description": "Hash-anchored read/apply_patch/edit tools for DeepSeek Harness (dsh). Every line gets a unique 3- or 4-char hash (A-Za-z0-9, configurable) that stays stable across edits; apply_patch and the anchored range edit tool are the file-mutation entry points, each committing its whole batch as one transaction.",
5
5
  "keywords": [
6
6
  "anchors",
7
7
  "apply-patch",
@@ -9,6 +9,7 @@
9
9
  "deepseek-harness",
10
10
  "dsh",
11
11
  "dsh-plugin",
12
+ "edit",
12
13
  "file-editing",
13
14
  "hash",
14
15
  "hash-anchored",
@@ -29,7 +30,6 @@
29
30
  "files": [
30
31
  "lib",
31
32
  "cordis.patch.yml",
32
- "prompts",
33
33
  "src",
34
34
  "README.md",
35
35
  "LICENSE"
@@ -60,6 +60,8 @@
60
60
  "format:fix": "oxfmt .",
61
61
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.dsh.json",
62
62
  "build": "node scripts/build-dsh.mjs",
63
+ "prompts:gen": "node scripts/gen-prompts.mjs",
64
+ "prompts:check": "node scripts/gen-prompts.mjs --check",
63
65
  "prepublishOnly": "node scripts/build-dsh.mjs && pnpm run typecheck && pnpm run lint && pnpm run test:win",
64
66
  "canon:audit": "node scripts/canon-churn-audit.mjs",
65
67
  "prepack": "node scripts/build-dsh.mjs",
@@ -0,0 +1,118 @@
1
+ /** SAFETY: EditTool — deep module owning the edit Use Case seam.
2
+ *
3
+ * Graded surface: one narrow interface `EditTool { execute, preview }`
4
+ * hides pipeline delegation, warnings/drift stitching.
5
+ * Frameworks (pi TUI) never cross this seam — that lives in TuiPresenter.
6
+ * Clean Architecture: Use Cases depend inward only (mutation-engine),
7
+ * never outward to Frameworks.
8
+ *
9
+ * Typed boundaries: validate once at admission (payload-contract via normReq/assertReq),
10
+ * trust inside. Immutable state: never mutates caller-owned request.
11
+ */
12
+
13
+ import { constants } from "node:fs";
14
+ import { sessionKeyFor } from "./served-session/session.js";
15
+ import { normReq, assertReq, type NormalizedEditRequest } from "./payload-contract.js";
16
+ import { execute as engineExecute, preview as enginePreview } from "./mutation-engine/engine.js";
17
+ import { isMutationSuccess } from "./mutation-result.js";
18
+ import { attachEnvelope } from "./error-envelope.js";
19
+
20
+ type EditToolContext = {
21
+ cwd: string;
22
+ sessionManager?: { getSessionId(): string };
23
+ };
24
+
25
+ type PreviewContext = {
26
+ sessionManager?: { getSessionId(): string };
27
+ };
28
+
29
+ type PreviewResult = { diff: string } | { error: string };
30
+
31
+ export interface EditTool {
32
+ /** SAFETY: Execute a validated edit; returns pi tool_result or throws on failure. Admission: params validated by normReq/assertReq. */
33
+ execute(
34
+ params: unknown,
35
+ signal: AbortSignal | undefined,
36
+ ctx: EditToolContext,
37
+ ): Promise<{
38
+ content: Array<{ type: "text"; text: string }>;
39
+ details: unknown;
40
+ }>;
41
+ /** SAFETY: Preview without persisting — mirrors pi's compPreview(request, cwd, ctx). The ctx must carry the session whose serves the anchors came from (#165). */
42
+ preview(request: unknown, cwd: string, ctx: PreviewContext): Promise<PreviewResult>;
43
+ }
44
+
45
+ export function createEditTool(): EditTool {
46
+ return {
47
+ async execute(params, signal, ctx) {
48
+ const canonical = normReq(params);
49
+ assertReq(canonical);
50
+ // SAFETY: ctx is untyped at pi boundary — cast validated by pi's runtime context shape (cwd + sessionManager)
51
+ const sessionKey = sessionKeyFor(
52
+ ctx as unknown as { sessionManager?: { getSessionId(): string } },
53
+ );
54
+ // SAFETY: canonical is validated NormalizedEditRequest after assertReq — trusted inside boundary
55
+ const result = await engineExecute(canonical as NormalizedEditRequest, ctx.cwd, {
56
+ accessMode: constants.R_OK | constants.W_OK,
57
+ // SAFETY: signal is AbortSignal | undefined at pi boundary — runtime check via engine's abortIf
58
+ ...(signal !== undefined ? { signal } : {}),
59
+ sessionKey,
60
+ });
61
+ if (isMutationSuccess(result)) {
62
+ // SAFETY: toolResult is validated by isMutationSuccess discriminated union guard
63
+ return result.toolResult as {
64
+ content: Array<{ type: "text"; text: string }>;
65
+ details: unknown;
66
+ };
67
+ }
68
+ // WHY: every range-family producer emits `details.cause` (user-facing diagnosis) —
69
+ // WHY: carry it on the thrown error so callers catching the message still see the cause.
70
+ // WHY: the whole failure envelope (code, diagnosis, rows, block) is stamped through the
71
+ // WHY: envelope assembler (src/error-envelope.ts) — this seam never hand-copies fields.
72
+ const failure = new Error(result.message);
73
+ attachEnvelope(failure, {
74
+ code: result.code,
75
+ ...(result.cause !== undefined ? { cause: result.cause } : {}),
76
+ // WHY: the raw payload message rides the envelope so the adapter can name the tool.
77
+ // WHY: The rendered message alone cannot say which call raised the refusal.
78
+ ...(result.payloadMessage !== undefined ? { payloadMessage: result.payloadMessage } : {}),
79
+ servedRows: result.servedRows ?? [],
80
+ servedBlock: result.servedBlock ?? "",
81
+ });
82
+ throw failure;
83
+ },
84
+ async preview(request, cwd, ctx) {
85
+ try {
86
+ const normalized = normReq(request);
87
+ assertReq(normalized);
88
+ // SAFETY: normalized is validated NormalizedEditRequest after assertReq
89
+ // WHY: (#165) preview verifies against the SAME session the anchors were served to —
90
+ // WHY: without a session, sessionKeyFor fails loud here instead of minting a key whose
91
+ // WHY: lease lookups all miss as a misleading E_UNKNOWN_ANCHOR.
92
+ const result = await enginePreview(normalized as NormalizedEditRequest, cwd, {
93
+ accessMode: constants.R_OK,
94
+ sessionKey: sessionKeyFor(ctx),
95
+ });
96
+ if (!isMutationSuccess(result)) {
97
+ return { error: result.message };
98
+ }
99
+ const file = result.raw;
100
+ // WHY: the call's own classification, not the primary file's bytes: a multi-file edit may
101
+ // WHY: change another file while the primary stands still, and that IS a change to preview.
102
+ if (result.metrics.classification === "noop") {
103
+ return {
104
+ error: `No changes made to ${file.path}. The edit produced identical content.`,
105
+ };
106
+ }
107
+ return {
108
+ // WHY: #174 single projection — the engine's `preview` seam already produced the
109
+ // WHY: `genDiff` text with the pane's context; this display path renders it and
110
+ // WHY: never re-projects.
111
+ diff: result.diff,
112
+ };
113
+ } catch (error: unknown) {
114
+ return { error: error instanceof Error ? error.message : String(error) };
115
+ }
116
+ },
117
+ };
118
+ }