dsh-better-edit 0.2.1 → 0.3.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.
- package/CHANGELOG.md +18 -0
- package/README.md +327 -238
- package/README.zh.md +44 -16
- package/lib/contract.js +40 -1
- package/lib/edit-engine.js +4 -4
- package/lib/edit-pipeline.js +4 -4
- package/lib/file-view.js +63 -0
- package/lib/guidance/index.js +8 -0
- package/lib/guidance/materialize.js +191 -0
- package/lib/guidance/parse.js +80 -0
- package/lib/guidance/resolve.js +122 -0
- package/lib/guidance.js +6 -279
- package/lib/hash-store.js +1 -2
- package/lib/hashline/anchor-pipeline.js +23 -0
- package/lib/hashline/hash-assign.js +20 -0
- package/lib/hashline/index.js +4 -5
- package/lib/hashline/resolve.js +5 -0
- package/lib/index.js +10 -2
- package/lib/mutation.js +58 -0
- package/lib/read-and-serve.js +23 -23
- package/lib/served-store.js +1 -1
- package/lib/session-view.js +34 -0
- package/lib/tool-batch-edit.js +9 -10
- package/lib/tool-edit.js +9 -11
- package/lib/tool-read.js +3 -5
- package/lib/tool-undo.js +6 -6
- package/lib/types/contract.d.ts +31 -0
- package/lib/types/edit-engine.d.ts +2 -2
- package/lib/types/edit-pipeline.d.ts +2 -2
- package/lib/types/file-view.d.ts +74 -0
- package/lib/types/guidance/index.d.ts +8 -0
- package/lib/types/guidance/materialize.d.ts +23 -0
- package/lib/types/guidance/parse.d.ts +36 -0
- package/lib/types/guidance/resolve.d.ts +55 -0
- package/lib/types/guidance.d.ts +6 -95
- package/lib/types/hashline/anchor-pipeline.d.ts +26 -0
- package/lib/types/hashline/hash-assign.d.ts +19 -0
- package/lib/types/hashline/index.d.ts +7 -5
- package/lib/types/hashline/resolve.d.ts +5 -0
- package/lib/types/mutation.d.ts +78 -0
- package/lib/types/read-and-serve.d.ts +6 -5
- package/lib/types/session-view.d.ts +33 -0
- package/lib/write-hook.js +2 -2
- package/package.json +2 -10
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation — deep module owning the full file mutation lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Previously fragmented: tool-edit → edit-pipeline → edit-engine.applyOne →
|
|
5
|
+
* edit-response/diff/drift, and tool-batch-edit → edit-engine.runFileEdits
|
|
6
|
+
* (loop + unionRange + counters) → persistUndoAndWrite with a boolean flag.
|
|
7
|
+
* Warnings, hadUtf8DecodeErrors, firstChangedLine, driftNotice were threaded
|
|
8
|
+
* by mutation across 5 hops; bugs hid in wiring, not pure helpers.
|
|
9
|
+
*
|
|
10
|
+
* This seam owns: read → normalize → loadServed → applyOne* → stableRehash →
|
|
11
|
+
* drift → persist. Tools become thin adapters: validate → delegate → render.
|
|
12
|
+
* edit-diff, drift, noop-guard are private helpers of this seam.
|
|
13
|
+
*
|
|
14
|
+
* Public surface:
|
|
15
|
+
* applySingle(io, params, {cwd, sessionKey, signal}) → PipelineResult
|
|
16
|
+
* applySequence(io, items, {cwd, sessionKey, signal}) → FileEditResult[]
|
|
17
|
+
* commit(io, files, {exec, sandboxPolicy, signal}) → void
|
|
18
|
+
*
|
|
19
|
+
* Internals (private): verifyServedRange, resToSpan, assemble, scanDrift,
|
|
20
|
+
* boundaryDups, noopGuard. Tested via PipelineResult/FileEditResult, not via split e2e.
|
|
21
|
+
*
|
|
22
|
+
* @module dsh-better-edit/mutation
|
|
23
|
+
*/
|
|
24
|
+
import type { FileIO } from "./fs-bridge.js";
|
|
25
|
+
import type { EditParams } from "./contract.js";
|
|
26
|
+
import type { HashStore } from "./hash-store.js";
|
|
27
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
28
|
+
import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
|
29
|
+
import type { FsSandboxController } from "./sandbox.js";
|
|
30
|
+
import { execPipeline, snapshotIdFor } from "./edit-pipeline.js";
|
|
31
|
+
import type { PipelineResult } from "./edit-pipeline.js";
|
|
32
|
+
import { runFileEdits, resolveMissingPath, persistUndoAndWrite, enforceNoopLoop, collectRemovedHashes, countLineChanges } from "./edit-engine.js";
|
|
33
|
+
import type { FileEditResult, PreparedItem } from "./edit-engine.js";
|
|
34
|
+
import { buildMetrics, buildNoop, buildChanged, buildBatchResult } from "./edit-response.js";
|
|
35
|
+
import type { RMeta, BatchSection } from "./edit-response.js";
|
|
36
|
+
import { genDiff, restoreEndings, toLF, stripBOM } from "./edit-diff.js";
|
|
37
|
+
import { computeDrift, scanDrift } from "./drift.js";
|
|
38
|
+
import { trackNoopPayload, clearNoopLoop, noopPayloadKey } from "./noop-guard.js";
|
|
39
|
+
export { execPipeline, snapshotIdFor };
|
|
40
|
+
export type { PipelineResult };
|
|
41
|
+
export { runFileEdits, resolveMissingPath, persistUndoAndWrite, enforceNoopLoop, collectRemovedHashes, countLineChanges };
|
|
42
|
+
export type { FileEditResult, PreparedItem };
|
|
43
|
+
export { buildMetrics, buildNoop, buildChanged, buildBatchResult };
|
|
44
|
+
export type { RMeta, BatchSection };
|
|
45
|
+
export { genDiff, restoreEndings, toLF, stripBOM };
|
|
46
|
+
export { computeDrift, scanDrift };
|
|
47
|
+
export { trackNoopPayload, clearNoopLoop, noopPayloadKey };
|
|
48
|
+
/** Apply a single edit — owns read→normalize→loadServed→applyOne→stableRehash→drift. */
|
|
49
|
+
export declare function applySingle(io: FileIO, params: EditParams, cwd: string, opts?: {
|
|
50
|
+
sessionKey?: string;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
store?: HashStore;
|
|
53
|
+
noPersist?: boolean;
|
|
54
|
+
}): Promise<PipelineResult>;
|
|
55
|
+
/** Apply a per-file sequence (batch's group) — owns the loop + unionRange + counters. */
|
|
56
|
+
export declare function applySequence(io: FileIO, items: PreparedItem[], ctx: {
|
|
57
|
+
sessionKey: string;
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
}): Promise<FileEditResult>;
|
|
60
|
+
/** Commit the transaction — owns persist-undo → write → restore. */
|
|
61
|
+
export declare function commit(opts: {
|
|
62
|
+
io: FileIO;
|
|
63
|
+
files: Array<{
|
|
64
|
+
absolutePath: string;
|
|
65
|
+
displayPath: string;
|
|
66
|
+
originalNormalized: string;
|
|
67
|
+
bom: string;
|
|
68
|
+
originalEnding: import("./edit-diff.js").LineEnding;
|
|
69
|
+
originalHashes: string[];
|
|
70
|
+
result: string;
|
|
71
|
+
}>;
|
|
72
|
+
exec: ToolExecution;
|
|
73
|
+
sandbox: FsSandboxController;
|
|
74
|
+
sandboxPolicy: SandboxExecutionPolicy | undefined;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
undoUnavailableMessage: (displayPath: string) => string;
|
|
77
|
+
restoreUnwrittenUndos?: boolean;
|
|
78
|
+
}): Promise<void>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The shared read-and-serve operation
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* The shared read-and-serve operation — now a thin wrapper over FileView.
|
|
3
|
+
*
|
|
4
|
+
* FileView owns normalize → hash → render → truncate → served selection.
|
|
5
|
+
* This module only adds the persistence seam: recordServed + clearDriftReported
|
|
6
|
+
* + UTF-8 rewrite note. Used by the `read` tool and by the write auto-read
|
|
7
|
+
* hook, so the model is always shown fresh anchors the same way.
|
|
7
8
|
* @module dsh-better-edit/read-and-serve
|
|
8
9
|
*/
|
|
9
10
|
import type { FileIO } from "./fs-bridge.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionView — deep module owning served rows + drift + position reconstruction.
|
|
3
|
+
*
|
|
4
|
+
* Previously split: served-store (merge invariant, persistence via hash-store)
|
|
5
|
+
* and drift (pure computeDrift + IO scanDrift that reads+writes served state).
|
|
6
|
+
* The drift notice both *reads* served state and *writes* it (marking reported
|
|
7
|
+
* + recording drift rows) — a side effect hidden inside a "notice" module.
|
|
8
|
+
*
|
|
9
|
+
* This seam co-locates that invariant. Public surface:
|
|
10
|
+
* view(sessionKey, path) → {served, reported}
|
|
11
|
+
* recordRead(sessionKey, path, rows, lineCount)
|
|
12
|
+
* recordEdit(sessionKey, path, rows, lineCount, clearFrom)
|
|
13
|
+
* scanDrift(sessionKey, path, resultHashes, resultLines, range) → notice?
|
|
14
|
+
* servedPositionsOf, currentPositionOfDrifted, _mergeServedRows (via served-store)
|
|
15
|
+
*
|
|
16
|
+
* Explicit Workspace note: loadHashStore(cwd) now requires cwd. The
|
|
17
|
+
* AsyncLocalStorage magic in workspace.ts is @internal — new code should pass
|
|
18
|
+
* cwd explicitly through read-and-serve / edit-pipeline / drift. Forgetting
|
|
19
|
+
* cwd is now a compile error where callers use this seam; legacy callers
|
|
20
|
+
* via served-store still fall back to workspaceCwd() for backwards compat
|
|
21
|
+
* but are marked deprecated.
|
|
22
|
+
*
|
|
23
|
+
* @module dsh-better-edit/session-view
|
|
24
|
+
*/
|
|
25
|
+
export { sessionKeyFor, _mergeServedRows, loadServed, recordServed, recordServedTruncated, driftReported, markDriftReported, clearDriftReported, wipeServedState, servedPositionsOf, currentPositionOfDrifted, } from "./served-store.js";
|
|
26
|
+
export type { ServedEntry } from "./served-store.js";
|
|
27
|
+
export { computeDrift, scanDrift, DRIFT_NOTICE_HEADING } from "./drift.js";
|
|
28
|
+
export type { DriftRow, ComputeDriftInput, DriftNoticeResult, } from "./drift.js";
|
|
29
|
+
export { withWorkspace, workspaceCwd } from "./workspace.js";
|
|
30
|
+
export { execCwd, execSessionKey } from "./dsh-context.js";
|
|
31
|
+
export { configDir, hashStorePath, resolveTarget } from "./paths.js";
|
|
32
|
+
export { loadHashStore, shutdownHashStore, withStore } from "./hash-store.js";
|
|
33
|
+
export type { HashStore } from "./hash-store.js";
|
package/lib/write-hook.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* @module dsh-better-edit/write-hook
|
|
7
7
|
*/
|
|
8
8
|
import { readAndServe } from './read-and-serve.js';
|
|
9
|
-
import { execCwd, execSessionKey } from './
|
|
10
|
-
import { withWorkspace } from './
|
|
9
|
+
import { execCwd, execSessionKey } from './session-view.js';
|
|
10
|
+
import { withWorkspace } from './session-view.js';
|
|
11
11
|
const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
|
|
12
12
|
/**
|
|
13
13
|
* Register the post-write auto-read listener on the calling agent's scope.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -54,19 +54,10 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@deepseek-ai/dsh-sandbox": "^0.1.0-rc.6",
|
|
58
57
|
"diff": "^8.0.2",
|
|
59
58
|
"file-type": "^21.3.0",
|
|
60
59
|
"xxhash-wasm": "^1.1.0"
|
|
61
60
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"@deepseek-ai/cordis": "^4.0.0",
|
|
64
|
-
"@deepseek-ai/dsh-agent": "^0.1.0-rc.6",
|
|
65
|
-
"@deepseek-ai/dsh-fs": "^0.1.0-rc.6",
|
|
66
|
-
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.6",
|
|
67
|
-
"@deepseek-ai/dsh-session": "^0.1.0-rc.6",
|
|
68
|
-
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6"
|
|
69
|
-
},
|
|
70
61
|
"engines": {
|
|
71
62
|
"node": "^22.19.0 || >=24.0.0"
|
|
72
63
|
},
|
|
@@ -87,6 +78,7 @@
|
|
|
87
78
|
"@deepseek-ai/dsh-home-paths": "0.1.0-rc.6",
|
|
88
79
|
"@deepseek-ai/dsh-session": "0.1.0-rc.6",
|
|
89
80
|
"@deepseek-ai/dsh-tools": "0.1.0-rc.6",
|
|
81
|
+
"@deepseek-ai/dsh-sandbox": "^0.1.0-rc.6",
|
|
90
82
|
"@types/node": "^24.0.0",
|
|
91
83
|
"@vitest/coverage-v8": "^4.1.10",
|
|
92
84
|
"js-tiktoken": "1.0.21",
|