dsh-better-edit 0.6.1 → 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.
@@ -42,21 +42,27 @@ export declare function _mergeServedRows(current: (string | null)[], rows: Serve
42
42
  }): (string | null)[];
43
43
  export declare function loadServed(sessionKey: string, path: string): Promise<(string | null)[]>;
44
44
  /** Anchors that must not be allocated while any session can still remember them. */
45
- export declare function loadAnchorReservations(path: string): Promise<AnchorReservations>;
45
+ export declare function loadAnchorReservations(sessionKey: string, path: string): Promise<AnchorReservations>;
46
46
  export declare function loadServedCanons(sessionKey: string, path: string): Promise<(string | null)[]>;
47
47
  export declare function loadEpochSnapshotId(sessionKey: string, path: string): Promise<string | undefined>;
48
48
  export declare function loadRetiredAnchors(sessionKey: string, path: string): Promise<Set<string>>;
49
49
  /** Keep freed anchors dead for this session until it has seen the whole file again. */
50
50
  export declare function retireAnchors(sessionKey: string, path: string, hashes: Iterable<string>): Promise<void>;
51
- export declare function recordServed(sessionKey: string, path: string, rows: ServedEntry[], lineCount?: number, fullReadHashes?: readonly string[], fullReadCanons?: readonly (string | null)[], fullReadSnapshotId?: string): Promise<void>;
52
- export declare function recordServedTruncated(sessionKey: string, path: string, rows: ServedEntry[], lineCount: number, clearFrom?: number): Promise<void>;
51
+ /** Full-file context for a complete read — when present and matching `rows`, the call is a full read. */
52
+ export interface FullReadContext {
53
+ hashes: readonly string[];
54
+ canons?: readonly (string | null)[];
55
+ snapshotId?: string;
56
+ }
57
+ export declare function recordServed(sessionKey: string, path: string, rows: ServedEntry[], lineCount?: number, full?: FullReadContext): Promise<void>;
58
+ export declare function recordServedTruncated(sessionKey: string, path: string, rows: ServedEntry[], lineCount: number, clearFrom?: number, fullCanons?: readonly (string | null)[]): Promise<void>;
53
59
  export declare function driftReported(sessionKey: string, path: string): Promise<Set<string>>;
54
60
  export declare function markDriftReported(sessionKey: string, path: string, hashes: string[]): Promise<void>;
55
61
  export declare function clearDriftReported(sessionKey: string, path: string): Promise<void>;
56
62
  export declare function wipeServedState(sessionKey: string): Promise<void>;
57
63
  export declare function servedPositionsOf(served: (string | null)[], hash: string): number[];
58
64
  export declare function currentPositionOfDrifted(served: (string | null)[], currentPositions: Map<string, number>, surviving: Set<string>, servedIndex: number, delta: number): number;
59
- export declare const DRIFT_NOTICE_HEADING = "drift:";
65
+ export declare const DRIFT_NOTICE_HEADING = "[USER] drift:";
60
66
  export interface DriftRow extends ServedRow {
61
67
  content: string;
62
68
  drifted: boolean;
@@ -68,6 +74,9 @@ export interface ComputeDriftInput {
68
74
  range: ResolvedRange;
69
75
  reported: Set<string>;
70
76
  cap?: number;
77
+ /** WHY (#68): parallel to `served`, whitespace-stripped form at serve time.
78
+ * Absent/empty preserves legacy hash-equality (old DBs, unit callers). */
79
+ servedCanons?: (string | null)[];
71
80
  }
72
81
  export interface DriftNoticeResult {
73
82
  text: string;
@@ -11,3 +11,10 @@ export declare function firstNonEmptyIndex(lines: string[]): number;
11
11
  export declare function lastNonEmpty(lines: string[]): string | undefined;
12
12
  export declare function firstNonEmpty(lines: string[]): string | undefined;
13
13
  export declare function clipLine(line: string, maxLen?: number): string;
14
+ /** Machine-readable error-code carrier — bare `E_*` code alongside the human message. */
15
+ export declare class CodedError extends Error {
16
+ readonly code: string;
17
+ constructor(code: string, message: string);
18
+ }
19
+ /** Structured bare-code read for any tool error: carrier first, `[E_*]` message convention as fallback. */
20
+ export declare function codeOf(error: unknown): string | undefined;
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(`[E_BAD_SHAPE] ${label} contains unknown or unsupported fields: ${unknown.join(", ")}.${suffix}`);
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 (`[E_WRITE_HASH_ECHO] Refused write to ${rawPath}: line ${match.line} begins with ` +
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.6.1",
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",
@@ -84,12 +84,12 @@
84
84
  "@commitlint/cli": "^21.2.2",
85
85
  "@commitlint/config-conventional": "^21.2.2",
86
86
  "@deepseek-ai/cordis": "^4.0.1",
87
- "@deepseek-ai/dsh-agent": "0.1.0-rc.6",
88
- "@deepseek-ai/dsh-fs": "0.1.0-rc.6",
89
- "@deepseek-ai/dsh-home-paths": "0.1.0-rc.6",
90
- "@deepseek-ai/dsh-sandbox": "^0.1.0-rc.6",
91
- "@deepseek-ai/dsh-session": "0.1.0-rc.6",
92
- "@deepseek-ai/dsh-tools": "0.1.0-rc.6",
87
+ "@deepseek-ai/dsh-agent": "0.1.1-rc.2",
88
+ "@deepseek-ai/dsh-fs": "0.1.1-rc.2",
89
+ "@deepseek-ai/dsh-home-paths": "0.1.1-rc.2",
90
+ "@deepseek-ai/dsh-sandbox": "0.1.1-rc.2",
91
+ "@deepseek-ai/dsh-session": "0.1.1-rc.2",
92
+ "@deepseek-ai/dsh-tools": "0.1.1-rc.2",
93
93
  "@semantic-release/changelog": "^7.0.0",
94
94
  "@semantic-release/git": "^11.0.1",
95
95
  "@semantic-release/github": "^12.0.9",