dsh-better-edit 0.8.1 → 1.0.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 +162 -97
- package/README.md +2 -2
- package/README.zh.md +3 -3
- package/cordis.patch.yml +1 -1
- package/lib/constants.js +19 -4
- package/lib/contract.js +136 -79
- package/lib/domain-errors.js +570 -0
- package/lib/edit-diff.js +33 -7
- package/lib/file-encoding-state.js +27 -7
- package/lib/file-view.js +305 -82
- package/lib/fs-bridge.js +23 -7
- package/lib/hash-store.js +404 -278
- package/lib/hashline/anchor-pipeline.js +586 -378
- package/lib/hashline/hash-assign.js +21 -22
- package/lib/hashline/hash.js +6 -6
- package/lib/hashline/index.js +1 -1
- package/lib/hashline/resolve.js +1 -1
- package/lib/hashline/served-guard.js +181 -0
- package/lib/index.js +2 -2
- package/lib/mutation/engine.js +392 -96
- package/lib/mutation.js +22 -130
- package/lib/noop-guard.js +20 -9
- package/lib/prompts.js +20 -18
- package/lib/read-and-serve.js +44 -20
- package/lib/sandbox.js +1 -1
- package/lib/session-view.js +57 -43
- package/lib/snapshot-store/index.js +97 -0
- package/lib/snapshot-store/lineage-store.js +400 -0
- package/lib/snapshot-store/migrate.js +80 -0
- package/lib/snapshot-store/pairing.js +412 -0
- package/lib/snapshot-store/txn.js +63 -0
- package/lib/snapshot-store/vacuum.js +243 -0
- package/lib/store-lifecycle.js +13 -1
- package/lib/store-retry.js +34 -0
- package/lib/tool-edit.js +90 -44
- package/lib/tool-read.js +29 -1
- package/lib/tool-str-replace-editor.js +59 -24
- package/lib/tool-undo.js +25 -8
- package/lib/types/constants.d.ts +5 -2
- package/lib/types/contract.d.ts +76 -71
- package/lib/types/domain-errors.d.ts +410 -0
- package/lib/types/edit-response.d.ts +1 -1
- package/lib/types/file-encoding-state.d.ts +1 -0
- package/lib/types/file-view.d.ts +35 -6
- package/lib/types/hash-store.d.ts +38 -19
- package/lib/types/hashline/anchor-pipeline.d.ts +117 -36
- package/lib/types/hashline/hash-assign.d.ts +5 -5
- package/lib/types/hashline/hash.d.ts +1 -1
- package/lib/types/hashline/index.d.ts +2 -2
- package/lib/types/hashline/served-guard.d.ts +100 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/mutation/engine.d.ts +49 -30
- package/lib/types/mutation.d.ts +1 -39
- package/lib/types/noop-guard.d.ts +4 -4
- package/lib/types/prompts.d.ts +1 -1
- package/lib/types/read-and-serve.d.ts +6 -0
- package/lib/types/sandbox.d.ts +1 -1
- package/lib/types/session-view.d.ts +38 -9
- package/lib/types/snapshot-store/index.d.ts +28 -0
- package/lib/types/snapshot-store/lineage-store.d.ts +96 -0
- package/lib/types/snapshot-store/migrate.d.ts +16 -0
- package/lib/types/snapshot-store/pairing.d.ts +99 -0
- package/lib/types/snapshot-store/txn.d.ts +12 -0
- package/lib/types/snapshot-store/vacuum.d.ts +79 -0
- package/lib/types/store-lifecycle.d.ts +0 -1
- package/lib/types/store-retry.d.ts +6 -0
- package/lib/types/tool-edit.d.ts +2 -2
- package/lib/types/tool-str-replace-editor.d.ts +10 -4
- package/lib/types/utils.d.ts +5 -6
- package/lib/types/workspace-context.d.ts +0 -1
- package/lib/undo-edit.js +27 -11
- package/lib/utils.js +12 -12
- package/lib/workspace-context.js +4 -8
- package/lib/write-hook.js +13 -4
- package/package.json +9 -10
package/lib/workspace-context.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module dsh-better-edit/workspace-context
|
|
16
16
|
*/
|
|
17
|
-
import { randomUUID } from "node:crypto";
|
|
18
17
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
19
18
|
// --- AsyncLocalStorage for cwd propagation ---
|
|
20
19
|
const current = new AsyncLocalStorage();
|
|
@@ -25,12 +24,13 @@ export function workspaceCwd() {
|
|
|
25
24
|
return current.getStore();
|
|
26
25
|
}
|
|
27
26
|
// --- sessionKey helpers ---
|
|
28
|
-
|
|
27
|
+
// WHY: (#165) there is deliberately no fallback key: a minted key that was never served anything
|
|
28
|
+
// WHY: makes every lease lookup miss and surfaces a misleading E_UNKNOWN_ANCHOR. Entrypoints
|
|
29
|
+
// WHY: without a session fail here, at the boundary, with the real cause.
|
|
29
30
|
export function sessionKeyFor(sessionId) {
|
|
30
31
|
if (sessionId && sessionId.length > 0)
|
|
31
32
|
return sessionId;
|
|
32
|
-
|
|
33
|
-
return (fallbackSessionKey ??= randomUUID());
|
|
33
|
+
throw new Error("sessionKeyFor: tool context carries no session — entrypoints must supply the ToolExecution's session id");
|
|
34
34
|
}
|
|
35
35
|
export function execCwd(exec) {
|
|
36
36
|
return exec.agent?.session.header.cwd ?? process.cwd();
|
|
@@ -38,7 +38,3 @@ export function execCwd(exec) {
|
|
|
38
38
|
export function execSessionKey(exec) {
|
|
39
39
|
return sessionKeyFor(exec.agent?.session.id);
|
|
40
40
|
}
|
|
41
|
-
// For tests: reset the fallback UUID so tests can be isolated
|
|
42
|
-
export function _resetWorkspaceContextForTests() {
|
|
43
|
-
fallbackSessionKey = undefined;
|
|
44
|
-
}
|
package/lib/write-hook.js
CHANGED
|
@@ -10,6 +10,7 @@ import { execCwd, execSessionKey, withWorkspace } from "./workspace-context.js";
|
|
|
10
10
|
import { loadServed } from "./session-view.js";
|
|
11
11
|
import { HASH_SEP } from "./hashline/hash-assign.js";
|
|
12
12
|
import { abortIf, splitLines } from "./utils.js";
|
|
13
|
+
import { formatError } from "./domain-errors.js";
|
|
13
14
|
const AUTO_READ_HEADING = "--- Auto-read (hashline anchors) ---";
|
|
14
15
|
/**
|
|
15
16
|
* Find a copied hashline prefix without treating arbitrary `3-char│` text as
|
|
@@ -40,10 +41,15 @@ export async function servedHashEchoDenial(io, rawPath, content, cwd, sessionKey
|
|
|
40
41
|
const match = findServedHashEcho(content, served);
|
|
41
42
|
if (!match)
|
|
42
43
|
return undefined;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
// A write echo names the same session/path/line the anchor was served for,
|
|
45
|
+
// so the served line equals the content line.
|
|
46
|
+
return formatError("E_SUSPICIOUS_TEXT", {
|
|
47
|
+
target: "write",
|
|
48
|
+
path: rawPath,
|
|
49
|
+
line: match.line,
|
|
50
|
+
hash: match.hash,
|
|
51
|
+
servedLine: match.line,
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* Register the pre-write echo guard and post-write auto-read on the calling
|
|
@@ -65,6 +71,9 @@ export function registerWriteHook(rootCtx, agentCtx, io) {
|
|
|
65
71
|
const content = args?.content;
|
|
66
72
|
if (typeof rawPath !== "string" || typeof content !== "string")
|
|
67
73
|
return next();
|
|
74
|
+
// F2: no mode escape here — the built-in write tool takes file_path /
|
|
75
|
+
// content only, so a mode branch would be dead and the refusal below
|
|
76
|
+
// must not promise it.
|
|
68
77
|
const cwd = execCwd(exec);
|
|
69
78
|
return withWorkspace(cwd, async () => {
|
|
70
79
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
@@ -52,12 +52,11 @@
|
|
|
52
52
|
"prepare": "tsc -p tsconfig.json && husky",
|
|
53
53
|
"build": "tsc -p tsconfig.json",
|
|
54
54
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
55
|
+
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
55
56
|
"test": "vitest run",
|
|
56
57
|
"test:watch": "vitest",
|
|
57
58
|
"prepublishOnly": "npm run typecheck && npm test && node scripts/assert-tagged.mjs",
|
|
58
59
|
"benchmark": "node benchmark/run.mjs",
|
|
59
|
-
"postpublish": "node scripts/tag-current.mjs",
|
|
60
|
-
"release": "node scripts/release.mjs",
|
|
61
60
|
"lint": "oxlint .",
|
|
62
61
|
"lint:fix": "oxlint --fix .",
|
|
63
62
|
"format": "oxfmt --check .",
|
|
@@ -77,12 +76,12 @@
|
|
|
77
76
|
"@commitlint/cli": "^21.2.2",
|
|
78
77
|
"@commitlint/config-conventional": "^21.2.2",
|
|
79
78
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
80
|
-
"@deepseek-ai/dsh-agent": "0.1.
|
|
81
|
-
"@deepseek-ai/dsh-fs": "0.1.
|
|
82
|
-
"@deepseek-ai/dsh-home-paths": "0.1.
|
|
83
|
-
"@deepseek-ai/dsh-sandbox": "0.1.
|
|
84
|
-
"@deepseek-ai/dsh-session": "0.1.
|
|
85
|
-
"@deepseek-ai/dsh-tools": "0.1.
|
|
79
|
+
"@deepseek-ai/dsh-agent": "0.1.6-alpha.2",
|
|
80
|
+
"@deepseek-ai/dsh-fs": "0.1.6-alpha.2",
|
|
81
|
+
"@deepseek-ai/dsh-home-paths": "0.1.6-alpha.2",
|
|
82
|
+
"@deepseek-ai/dsh-sandbox": "0.1.6-alpha.2",
|
|
83
|
+
"@deepseek-ai/dsh-session": "0.1.6-alpha.2",
|
|
84
|
+
"@deepseek-ai/dsh-tools": "0.1.6-alpha.2",
|
|
86
85
|
"@semantic-release/changelog": "^7.0.0",
|
|
87
86
|
"@semantic-release/git": "^11.0.1",
|
|
88
87
|
"@semantic-release/github": "^12.0.9",
|
|
@@ -91,7 +90,7 @@
|
|
|
91
90
|
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
92
91
|
"husky": "^9.1.7",
|
|
93
92
|
"js-tiktoken": "1.0.21",
|
|
94
|
-
"oxfmt": "
|
|
93
|
+
"oxfmt": "0.67.0",
|
|
95
94
|
"oxlint": ">=1",
|
|
96
95
|
"semantic-release": "^25.0.9",
|
|
97
96
|
"tsx": ">=4",
|