dsh-better-edit 0.7.1 → 0.8.1
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 +50 -25
- package/README.md +72 -66
- package/README.zh.md +83 -83
- package/lib/canonical-path.js +4 -1
- package/lib/contract.js +67 -22
- package/lib/edit-diff.js +1 -5
- package/lib/encoding.js +22 -5
- package/lib/file-encoding-state.js +50 -11
- package/lib/file-view.js +28 -41
- package/lib/fs-bridge.js +59 -23
- package/lib/fs-write.js +1 -1
- package/lib/guidance/materialize.js +1 -6
- package/lib/guidance/resolve.js +1 -1
- package/lib/hash-store.js +12 -20
- package/lib/hashline/anchor-pipeline.js +29 -29
- package/lib/hashline/hash-assign.js +7 -4
- package/lib/hashline/hash.js +3 -3
- package/lib/index.js +6 -0
- package/lib/mutation/engine.js +11 -14
- package/lib/mutation.js +7 -6
- package/lib/prompts.js +9 -8
- package/lib/read-and-serve.js +22 -11
- package/lib/render-text-warning.js +21 -0
- package/lib/sandbox.js +2 -5
- package/lib/self-heal.js +30 -27
- package/lib/session-view.js +5 -1
- package/lib/store-config.js +7 -2
- package/lib/store-lifecycle.js +7 -2
- package/lib/tool-edit.js +5 -2
- package/lib/tool-read.js +6 -9
- package/lib/tool-str-replace-editor.js +274 -0
- package/lib/tool-undo.js +2 -3
- package/lib/types/contract.d.ts +104 -17
- package/lib/types/file-encoding-state.d.ts +3 -0
- package/lib/types/file-view.d.ts +1 -1
- package/lib/types/hashline/index.d.ts +1 -1
- package/lib/types/render-text-warning.d.ts +22 -0
- package/lib/types/self-heal.d.ts +2 -0
- package/lib/types/tool-str-replace-editor.d.ts +27 -0
- package/lib/types/undo-edit.d.ts +1 -1
- package/lib/types/write-hook.d.ts +2 -2
- package/lib/undo-edit.js +6 -8
- package/lib/utils.js +1 -2
- package/lib/workspace-context.js +1 -1
- package/lib/write-hook.js +19 -22
- package/package.json +63 -57
package/lib/types/undo-edit.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* overwritten. Undo survives restarts (the store is on disk).
|
|
8
8
|
* @module dsh-better-edit/undo-edit
|
|
9
9
|
*/
|
|
10
|
-
import type { LineEnding } from
|
|
10
|
+
import type { LineEnding } from "./edit-diff.js";
|
|
11
11
|
export interface UndoEntry {
|
|
12
12
|
content: string;
|
|
13
13
|
bom: string;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* anchors to the model-facing content (mirroring pi-hashline-edit-lsz).
|
|
6
6
|
* @module dsh-better-edit/write-hook
|
|
7
7
|
*/
|
|
8
|
-
import type { Context } from
|
|
9
|
-
import type { FileIO } from
|
|
8
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
9
|
+
import type { FileIO } from "./fs-bridge.js";
|
|
10
10
|
export interface ServedHashEcho {
|
|
11
11
|
/** One-based candidate line carrying the copied anchor. */
|
|
12
12
|
line: number;
|
package/lib/undo-edit.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* overwritten. Undo survives restarts (the store is on disk).
|
|
8
8
|
* @module dsh-better-edit/undo-edit
|
|
9
9
|
*/
|
|
10
|
-
import { loadHashStore } from
|
|
10
|
+
import { loadHashStore } from "./hash-store.js";
|
|
11
11
|
/** Load the last undo row for a path from the active store, if any. */
|
|
12
12
|
async function readUndo(path) {
|
|
13
13
|
const store = await loadHashStore();
|
|
@@ -43,7 +43,7 @@ export async function saveUndo(path, entry) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
46
|
-
console.error(
|
|
46
|
+
console.error("Failed to persist undo entry:", error);
|
|
47
47
|
return { persisted: false, restore: async () => undefined };
|
|
48
48
|
}
|
|
49
49
|
return {
|
|
@@ -56,7 +56,7 @@ export async function saveUndo(path, entry) {
|
|
|
56
56
|
await removeUndo(path);
|
|
57
57
|
}
|
|
58
58
|
catch (error) {
|
|
59
|
-
console.error(
|
|
59
|
+
console.error("Failed to restore previous undo entry:", error);
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
};
|
|
@@ -68,9 +68,7 @@ export async function getUndo(path) {
|
|
|
68
68
|
if (!record)
|
|
69
69
|
return undefined;
|
|
70
70
|
const originalEnding = record.ending;
|
|
71
|
-
if (originalEnding !==
|
|
72
|
-
originalEnding !== '\n' &&
|
|
73
|
-
originalEnding !== '\r') {
|
|
71
|
+
if (originalEnding !== "\r\n" && originalEnding !== "\n" && originalEnding !== "\r") {
|
|
74
72
|
await removeUndo(path);
|
|
75
73
|
return undefined;
|
|
76
74
|
}
|
|
@@ -83,7 +81,7 @@ export async function getUndo(path) {
|
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
83
|
catch (error) {
|
|
86
|
-
console.error(
|
|
84
|
+
console.error("Failed to load undo entry:", error);
|
|
87
85
|
return undefined;
|
|
88
86
|
}
|
|
89
87
|
}
|
|
@@ -93,6 +91,6 @@ export async function clearUndo(path) {
|
|
|
93
91
|
await removeUndo(path);
|
|
94
92
|
}
|
|
95
93
|
catch (error) {
|
|
96
|
-
console.error(
|
|
94
|
+
console.error("Failed to clear undo entry:", error);
|
|
97
95
|
}
|
|
98
96
|
}
|
package/lib/utils.js
CHANGED
|
@@ -31,8 +31,7 @@ export function cntDiff(diff, marker) {
|
|
|
31
31
|
return 0;
|
|
32
32
|
let count = 0;
|
|
33
33
|
for (const line of diff.split("\n")) {
|
|
34
|
-
if (line.startsWith(marker) &&
|
|
35
|
-
!line.startsWith(`${marker}${marker}${marker}`)) {
|
|
34
|
+
if (line.startsWith(marker) && !line.startsWith(`${marker}${marker}${marker}`)) {
|
|
36
35
|
count += 1;
|
|
37
36
|
}
|
|
38
37
|
}
|
package/lib/workspace-context.js
CHANGED
|
@@ -30,7 +30,7 @@ export function sessionKeyFor(sessionId) {
|
|
|
30
30
|
if (sessionId && sessionId.length > 0)
|
|
31
31
|
return sessionId;
|
|
32
32
|
// fallback for previews/tests
|
|
33
|
-
return fallbackSessionKey ??= randomUUID();
|
|
33
|
+
return (fallbackSessionKey ??= randomUUID());
|
|
34
34
|
}
|
|
35
35
|
export function execCwd(exec) {
|
|
36
36
|
return exec.agent?.session.header.cwd ?? process.cwd();
|
package/lib/write-hook.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* anchors to the model-facing content (mirroring pi-hashline-edit-lsz).
|
|
6
6
|
* @module dsh-better-edit/write-hook
|
|
7
7
|
*/
|
|
8
|
-
import { readAndServe } from
|
|
9
|
-
import { execCwd, execSessionKey, withWorkspace } from
|
|
10
|
-
import { loadServed } from
|
|
11
|
-
import { HASH_SEP } from
|
|
12
|
-
import { abortIf, splitLines } from
|
|
13
|
-
const AUTO_READ_HEADING =
|
|
8
|
+
import { readAndServe } from "./read-and-serve.js";
|
|
9
|
+
import { execCwd, execSessionKey, withWorkspace } from "./workspace-context.js";
|
|
10
|
+
import { loadServed } from "./session-view.js";
|
|
11
|
+
import { HASH_SEP } from "./hashline/hash-assign.js";
|
|
12
|
+
import { abortIf, splitLines } from "./utils.js";
|
|
13
|
+
const AUTO_READ_HEADING = "--- Auto-read (hashline anchors) ---";
|
|
14
14
|
/**
|
|
15
15
|
* Find a copied hashline prefix without treating arbitrary `3-char│` text as
|
|
16
16
|
* metadata. A match requires the exact hash currently recorded at the same
|
|
@@ -43,7 +43,7 @@ export async function servedHashEchoDenial(io, rawPath, content, cwd, sessionKey
|
|
|
43
43
|
return (`[MODEL] [E_SERVED_ECHO] Refused write to ${rawPath}: line ${match.line} begins with ` +
|
|
44
44
|
`the exact ${match.hash}${HASH_SEP} anchor served for this session, path, and line. ` +
|
|
45
45
|
`HASH${HASH_SEP} anchors are tool output, not file content. ` +
|
|
46
|
-
|
|
46
|
+
"Retry with file content only (remove the entire copied anchor chain). Nothing was written.");
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Register the pre-write echo guard and post-write auto-read on the calling
|
|
@@ -57,19 +57,19 @@ export async function servedHashEchoDenial(io, rawPath, content, cwd, sessionKey
|
|
|
57
57
|
* @returns the exact disposer that unregisters the listener.
|
|
58
58
|
*/
|
|
59
59
|
export function registerWriteHook(rootCtx, agentCtx, io) {
|
|
60
|
-
const disposeGuard = agentCtx.on(
|
|
61
|
-
if (exec.name !==
|
|
60
|
+
const disposeGuard = agentCtx.on("tools/pre-execute", async (exec, next) => {
|
|
61
|
+
if (exec.name !== "write")
|
|
62
62
|
return next();
|
|
63
63
|
const args = exec.arguments;
|
|
64
64
|
const rawPath = args?.file_path ?? args?.path;
|
|
65
65
|
const content = args?.content;
|
|
66
|
-
if (typeof rawPath !==
|
|
66
|
+
if (typeof rawPath !== "string" || typeof content !== "string")
|
|
67
67
|
return next();
|
|
68
68
|
const cwd = execCwd(exec);
|
|
69
69
|
return withWorkspace(cwd, async () => {
|
|
70
70
|
try {
|
|
71
71
|
const reason = await servedHashEchoDenial(io, rawPath, content, cwd, execSessionKey(exec), exec.signal);
|
|
72
|
-
return reason === undefined ? next() : { kind:
|
|
72
|
+
return reason === undefined ? next() : { kind: "deny", reason };
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
75
75
|
if (exec.signal.aborted)
|
|
@@ -79,19 +79,16 @@ export function registerWriteHook(rootCtx, agentCtx, io) {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
|
-
const disposeAutoRead = agentCtx.on(
|
|
82
|
+
const disposeAutoRead = agentCtx.on("tools/post-execute", async (exec, result, next) => {
|
|
83
83
|
return withWorkspace(execCwd(exec), async () => {
|
|
84
84
|
const decision = await next();
|
|
85
|
-
if (exec.name !==
|
|
86
|
-
result.isError ||
|
|
87
|
-
decision.kind !== 'accept') {
|
|
85
|
+
if (exec.name !== "write" || result.isError || decision.kind !== "accept") {
|
|
88
86
|
return decision;
|
|
89
87
|
}
|
|
90
88
|
const decisionContent = decision.content ?? result.content;
|
|
91
|
-
const rawPath = exec.arguments
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (typeof rawPath !== 'string')
|
|
89
|
+
const rawPath = exec.arguments?.file_path ??
|
|
90
|
+
exec.arguments?.path;
|
|
91
|
+
if (typeof rawPath !== "string")
|
|
95
92
|
return decision;
|
|
96
93
|
try {
|
|
97
94
|
const cwd = execCwd(exec);
|
|
@@ -99,10 +96,10 @@ export function registerWriteHook(rootCtx, agentCtx, io) {
|
|
|
99
96
|
const signal = exec.signal;
|
|
100
97
|
const { text } = await readAndServe(io, rawPath, cwd, { sessionKey, signal });
|
|
101
98
|
return {
|
|
102
|
-
kind:
|
|
99
|
+
kind: "accept",
|
|
103
100
|
content: [
|
|
104
|
-
...
|
|
105
|
-
{ type:
|
|
101
|
+
...decisionContent,
|
|
102
|
+
{ type: "text", text: `\n\n${AUTO_READ_HEADING}\n${text}` },
|
|
106
103
|
],
|
|
107
104
|
};
|
|
108
105
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.8.1",
|
|
5
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.",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"anchors",
|
|
7
|
+
"batch-edit",
|
|
8
|
+
"coding-agent",
|
|
9
|
+
"deepseek-harness",
|
|
10
|
+
"dsh",
|
|
11
|
+
"dsh-plugin",
|
|
12
|
+
"edit",
|
|
13
|
+
"file-editing",
|
|
14
|
+
"hash",
|
|
15
|
+
"hash-anchored",
|
|
16
|
+
"hashline",
|
|
17
|
+
"oh-my-pi",
|
|
18
|
+
"read",
|
|
19
|
+
"stable",
|
|
20
|
+
"undo"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://github.com/Rianico/dsh-better-edit",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Rianico/dsh-better-edit/issues"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "dsh-better-edit contributors",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Rianico/dsh-better-edit.git"
|
|
14
31
|
},
|
|
15
32
|
"files": [
|
|
16
33
|
"lib",
|
|
@@ -21,47 +38,15 @@
|
|
|
21
38
|
"assets/",
|
|
22
39
|
"CHANGELOG.md"
|
|
23
40
|
],
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"keywords": [
|
|
34
|
-
"dsh",
|
|
35
|
-
"dsh-plugin",
|
|
36
|
-
"deepseek-harness",
|
|
37
|
-
"coding-agent",
|
|
38
|
-
"oh-my-pi",
|
|
39
|
-
"hashline",
|
|
40
|
-
"hash-anchored",
|
|
41
|
-
"hash",
|
|
42
|
-
"anchors",
|
|
43
|
-
"read",
|
|
44
|
-
"edit",
|
|
45
|
-
"batch-edit",
|
|
46
|
-
"undo",
|
|
47
|
-
"file-editing",
|
|
48
|
-
"stable"
|
|
49
|
-
],
|
|
50
|
-
"license": "MIT",
|
|
51
|
-
"dsh": {
|
|
52
|
-
"bundle": {
|
|
53
|
-
"patch": "./cordis.patch.yml"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"diff": "^8.0.2",
|
|
58
|
-
"file-type": "^21.3.0",
|
|
59
|
-
"iconv-lite": "^0.6.3",
|
|
60
|
-
"xxhash-wasm": "^1.1.0",
|
|
61
|
-
"zod": "^3.25.76"
|
|
62
|
-
},
|
|
63
|
-
"engines": {
|
|
64
|
-
"node": "^22.19.0 || >=24.0.0"
|
|
41
|
+
"type": "module",
|
|
42
|
+
"main": "lib/index.js",
|
|
43
|
+
"types": "lib/types/index.d.ts",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./lib/types/index.d.ts",
|
|
47
|
+
"default": "./lib/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
65
50
|
},
|
|
66
51
|
"scripts": {
|
|
67
52
|
"prepare": "tsc -p tsconfig.json && husky",
|
|
@@ -73,11 +58,19 @@
|
|
|
73
58
|
"benchmark": "node benchmark/run.mjs",
|
|
74
59
|
"postpublish": "node scripts/tag-current.mjs",
|
|
75
60
|
"release": "node scripts/release.mjs",
|
|
76
|
-
"lint": "
|
|
77
|
-
"lint:fix": "
|
|
78
|
-
"format": "
|
|
79
|
-
"format:check": "
|
|
80
|
-
"test:coverage": "vitest run --coverage"
|
|
61
|
+
"lint": "oxlint .",
|
|
62
|
+
"lint:fix": "oxlint --fix .",
|
|
63
|
+
"format": "oxfmt --check .",
|
|
64
|
+
"format:check": "oxfmt --check .",
|
|
65
|
+
"test:coverage": "vitest run --coverage",
|
|
66
|
+
"format:fix": "oxfmt ."
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"diff": "^8.0.2",
|
|
70
|
+
"file-type": "^21.3.0",
|
|
71
|
+
"iconv-lite": "^0.6.3",
|
|
72
|
+
"xxhash-wasm": "^1.1.0",
|
|
73
|
+
"zod": "^3.25.76"
|
|
81
74
|
},
|
|
82
75
|
"devDependencies": {
|
|
83
76
|
"@biomejs/biome": "^2.1.0",
|
|
@@ -98,11 +91,24 @@
|
|
|
98
91
|
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
99
92
|
"husky": "^9.1.7",
|
|
100
93
|
"js-tiktoken": "1.0.21",
|
|
94
|
+
"oxfmt": ">=0.15",
|
|
95
|
+
"oxlint": ">=1",
|
|
101
96
|
"semantic-release": "^25.0.9",
|
|
102
|
-
"
|
|
97
|
+
"tsx": ">=4",
|
|
98
|
+
"typescript": ">=7",
|
|
99
|
+
"vite": ">=8",
|
|
103
100
|
"vitest": "^4.1.8"
|
|
104
101
|
},
|
|
105
102
|
"optionalDependencies": {
|
|
106
103
|
"chardet": "2.2.0"
|
|
104
|
+
},
|
|
105
|
+
"engines": {
|
|
106
|
+
"node": ">=24"
|
|
107
|
+
},
|
|
108
|
+
"packageManager": "pnpm@12.0.0",
|
|
109
|
+
"dsh": {
|
|
110
|
+
"bundle": {
|
|
111
|
+
"patch": "./cordis.patch.yml"
|
|
112
|
+
}
|
|
107
113
|
}
|
|
108
114
|
}
|