dsh-better-edit 0.6.3 → 0.7.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 +29 -0
- package/README.md +14 -13
- package/lib/constants.js +5 -1
- package/lib/contract.js +64 -15
- package/lib/edit-response.js +5 -10
- package/lib/encoding.js +1 -1
- package/lib/file-encoding-state.js +4 -4
- package/lib/file-view.js +14 -12
- package/lib/fs-bridge.js +8 -7
- package/lib/hash-store.js +123 -25
- package/lib/hashline/anchor-pipeline.js +97 -66
- package/lib/hashline/hash-assign.js +58 -19
- package/lib/hashline/hash.js +3 -3
- package/lib/mutation/engine.js +81 -20
- package/lib/mutation.js +8 -8
- package/lib/prompts.js +6 -6
- package/lib/read-and-serve.js +90 -15
- package/lib/session-view.js +157 -24
- package/lib/tool-edit.js +5 -4
- package/lib/tool-undo.js +6 -6
- package/lib/types/constants.d.ts +2 -0
- package/lib/types/contract.d.ts +2 -1
- package/lib/types/edit-response.d.ts +4 -0
- package/lib/types/encoding.d.ts +1 -1
- package/lib/types/file-encoding-state.d.ts +1 -1
- package/lib/types/file-view.d.ts +15 -0
- package/lib/types/hash-store.d.ts +12 -1
- package/lib/types/hashline/anchor-pipeline.d.ts +16 -6
- package/lib/types/hashline/hash-assign.d.ts +10 -2
- package/lib/types/mutation/engine.d.ts +2 -1
- package/lib/types/session-view.d.ts +13 -4
- package/lib/types/utils.d.ts +7 -0
- package/lib/utils.js +22 -1
- package/lib/write-hook.js +1 -1
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ export function rejectUnknownFields(obj, allowed, label, hint) {
|
|
|
23
23
|
const unknown = Object.keys(obj).filter((key) => !allowed.has(key));
|
|
24
24
|
if (unknown.length > 0) {
|
|
25
25
|
const suffix = hint ? ` ${hint}` : "";
|
|
26
|
-
throw new Error(`[
|
|
26
|
+
throw new Error(`[MODEL] [E_BAD_PAYLOAD] ${label} contains unknown or unsupported fields: ${unknown.join(", ")}.${suffix}`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
export function cntDiff(diff, marker) {
|
|
@@ -74,3 +74,24 @@ export function clipLine(line, maxLen = 200) {
|
|
|
74
74
|
const flat = line.replace(/\n/g, "\\n");
|
|
75
75
|
return flat.length > maxLen ? `${flat.slice(0, maxLen)}...` : flat;
|
|
76
76
|
}
|
|
77
|
+
/** Machine-readable error-code carrier — bare `E_*` code alongside the human message. */
|
|
78
|
+
export class CodedError extends Error {
|
|
79
|
+
code;
|
|
80
|
+
constructor(code, message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = "CodedError";
|
|
83
|
+
this.code = code;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const CODED_RE = /\[(E_[A-Z_]+)\]/;
|
|
87
|
+
/** Structured bare-code read for any tool error: carrier first, `[E_*]` message convention as fallback. */
|
|
88
|
+
export function codeOf(error) {
|
|
89
|
+
if (error instanceof CodedError)
|
|
90
|
+
return error.code;
|
|
91
|
+
if (error instanceof Error) {
|
|
92
|
+
const m = error.message.match(CODED_RE);
|
|
93
|
+
if (m)
|
|
94
|
+
return m[1];
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
package/lib/write-hook.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function servedHashEchoDenial(io, rawPath, content, cwd, sessionKey
|
|
|
40
40
|
const match = findServedHashEcho(content, served);
|
|
41
41
|
if (!match)
|
|
42
42
|
return undefined;
|
|
43
|
-
return (`[
|
|
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.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"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
6
|
"main": "lib/index.js",
|