dsh-better-edit 1.1.0 → 1.2.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 CHANGED
@@ -11,6 +11,22 @@ All notable changes to this project will be documented in this file.
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [1.2.0] - 2026-10-29
15
+
16
+ ### Features
17
+
18
+ * **edit-diff:** formalize single-projection contract with counted span markers (#92)
19
+
20
+ ### Bug Fixes
21
+
22
+ * **edit-diff:** render ctx-0 middle gaps marker-only with correct skip (#92)
23
+ * **edit-diff:** render small middle gaps whole, keep anchors aligned (#92)
24
+
25
+ ### Documentation
26
+
27
+ * **agents:** replace CONTEXT with GLOSSARY single-context (#86)
28
+ * **absorb:** record the upstream v2.3.0 gap-projection range — basis `b92e0ec`..`v2.3.0`, 3 semantic commits ported (`31d67d8` small middle gaps render whole with aligned anchors, `71e0107` single-projection contract with counted span markers, `ab06895` ctx-0 middle gaps marker-only with correct skip); the release commit `0925f1a` is deliberately not ported and no downstream version bump rides the absorb (#92)
29
+
14
30
  ## [1.1.0] - 2026-10-22
15
31
 
16
32
  ### Bug Fixes
package/lib/edit-diff.js CHANGED
@@ -32,8 +32,8 @@ function fmtDiffLine(prefix, line, hash) {
32
32
  }
33
33
  return `${prefix}${hash}${HASH_SEP}${line}`;
34
34
  }
35
- const ELLIPSIS_MARKER = Symbol("ellipsis");
36
- const isEllipsisMarker = (line) => line === ELLIPSIS_MARKER;
35
+ const UNTOUCHED_MARKER = Symbol("untouched");
36
+ const isUntouchedMarker = (line) => line === UNTOUCHED_MARKER;
37
37
  function formatRemovedLines(displayLines, oldContentHashes, oldLineNum) {
38
38
  const rows = [];
39
39
  let cursor = oldLineNum;
@@ -50,14 +50,28 @@ function formatRemovedLines(displayLines, oldContentHashes, oldLineNum) {
50
50
  const omitted = displayLines.length - DIFF_REMOVED_EDGE * 2;
51
51
  for (const line of displayLines.slice(0, DIFF_REMOVED_EDGE))
52
52
  emit(line);
53
- // WHY: ADR-0024/D3 — the model sees the deletion's head, tail, and exact size; the omitted rows
53
+ // WHY: ADR-0024/D3 — the model sees the deletion's head, tail, and exact size; the hidden rows
54
54
  // WHY: still advance the cursor so every later row keeps its exact old line number and hash.
55
- rows.push(` - ... [${omitted} lines omitted] ...`);
55
+ // WHY: #169 — the marker's count is the exact deleted span and uses the unified `lines deleted` diction.
56
+ rows.push(` - ... [${omitted} lines deleted] ...`);
56
57
  cursor += omitted;
57
58
  for (const line of displayLines.slice(-DIFF_REMOVED_EDGE))
58
59
  emit(line);
59
60
  return { rows, nextOldLineNum: cursor };
60
61
  }
62
+ /**
63
+ * genDiff is the single diff projection (#169). Return contract:
64
+ * - every emitted row's anchor equals the true new-file line content hash at that
65
+ * position; removed rows carry the true old-file hash when old hashes are provided.
66
+ * - every emitted marker's count equals the span it hides:
67
+ * ` ... [N lines untouched] ...` advances both cursors past N hidden rows (lease-covered,
68
+ * they stay addressable through the served leases), and ` - ... [N lines deleted] ...`
69
+ * advances the old cursor past N deleted rows (cursor-exact).
70
+ * - collapse invariant: a middle gap smaller than 2×context renders whole (#166/#172);
71
+ * at context 0 every non-empty middle gap collapses to a single counted untouched
72
+ * marker (#170); bare ` ...` appears only at leading/trailing edges; added spans are never collapsed.
73
+ * - servedRows mirror exactly the rendered context/addition rows (position + hash).
74
+ */
61
75
  export function genDiff(oldContent, newContent, contextLines = 2, newContentHashes, oldContentHashes) {
62
76
  const effectiveNewHashes = newContentHashes ?? lineHashesPure(newContent);
63
77
  const parts = Diff.diffLines(oldContent, newContent);
@@ -105,11 +119,15 @@ export function genDiff(oldContent, newContent, contextLines = 2, newContentHash
105
119
  linesToShow = displayLines.slice(skipStart);
106
120
  }
107
121
  else if (nextPartIsChange && displayLines.length > contextLines * 2) {
108
- const tail = displayLines.slice(-contextLines);
109
- linesToShow = [...displayLines.slice(0, contextLines), ELLIPSIS_MARKER, ...tail];
122
+ // WHY: #170 — slice(-0) returns the whole array, so at context 0 the tail is taken
123
+ // WHY: explicitly; the gap then renders marker-only with the count covering the full span.
124
+ const tail = contextLines === 0 ? [] : displayLines.slice(-contextLines);
125
+ linesToShow = [...displayLines.slice(0, contextLines), UNTOUCHED_MARKER, ...tail];
110
126
  skipMiddle = displayLines.length - contextLines * 2;
111
127
  }
112
- else if (linesToShow.length > contextLines) {
128
+ else if (!nextPartIsChange && linesToShow.length > contextLines) {
129
+ // WHY: #166 — only trailing gaps may be sliced away silently; a middle gap renders whole
130
+ // WHY: below 2×context, otherwise hidden rows would desync the anchors that follow it.
113
131
  linesToShow = linesToShow.slice(0, contextLines);
114
132
  }
115
133
  if (skipStart > 0) {
@@ -118,8 +136,10 @@ export function genDiff(oldContent, newContent, contextLines = 2, newContentHash
118
136
  oldLineNum += skipStart;
119
137
  }
120
138
  for (const line of linesToShow) {
121
- if (isEllipsisMarker(line)) {
122
- output.push(" ...");
139
+ if (isUntouchedMarker(line)) {
140
+ // WHY: #169 — a hidden middle span is a counted `lines untouched` marker; both cursors
141
+ // WHY: advance past the exact hidden count, so anchors after it stay aligned.
142
+ output.push(` ... [${skipMiddle} lines untouched] ...`);
123
143
  newLineNum += skipMiddle;
124
144
  oldLineNum += skipMiddle;
125
145
  continue;
@@ -7,6 +7,19 @@ export declare function stripBOM(content: string): {
7
7
  bom: string;
8
8
  text: string;
9
9
  };
10
+ /**
11
+ * genDiff is the single diff projection (#169). Return contract:
12
+ * - every emitted row's anchor equals the true new-file line content hash at that
13
+ * position; removed rows carry the true old-file hash when old hashes are provided.
14
+ * - every emitted marker's count equals the span it hides:
15
+ * ` ... [N lines untouched] ...` advances both cursors past N hidden rows (lease-covered,
16
+ * they stay addressable through the served leases), and ` - ... [N lines deleted] ...`
17
+ * advances the old cursor past N deleted rows (cursor-exact).
18
+ * - collapse invariant: a middle gap smaller than 2×context renders whole (#166/#172);
19
+ * at context 0 every non-empty middle gap collapses to a single counted untouched
20
+ * marker (#170); bare ` ...` appears only at leading/trailing edges; added spans are never collapsed.
21
+ * - servedRows mirror exactly the rendered context/addition rows (position + hash).
22
+ */
10
23
  export declare function genDiff(oldContent: string, newContent: string, contextLines?: number, newContentHashes?: string[], oldContentHashes?: string[]): {
11
24
  diff: string;
12
25
  firstChangedLine: number | undefined;
@@ -1,33 +1,15 @@
1
1
  import { z } from "zod";
2
2
  export declare function expand(filePath: string): string;
3
3
  declare const StoreConfigSchema: z.ZodObject<{
4
- storeDir: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
4
+ storeDir: z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>;
5
5
  autoGitignore: z.ZodDefault<z.ZodBoolean>;
6
6
  autoGuessEncoding: z.ZodDefault<z.ZodBoolean>;
7
7
  normalizeToUtf8: z.ZodDefault<z.ZodBoolean>;
8
- supportedEncodings: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
8
+ supportedEncodings: z.ZodDefault<z.ZodArray<z.ZodString>>;
9
9
  undo_ttl_s: z.ZodDefault<z.ZodNumber>;
10
10
  storeMaxAgeS: z.ZodDefault<z.ZodNumber>;
11
11
  storeMaxTotalBytes: z.ZodDefault<z.ZodNumber>;
12
- }, "strip", z.ZodTypeAny, {
13
- storeDir: string;
14
- autoGitignore: boolean;
15
- autoGuessEncoding: boolean;
16
- normalizeToUtf8: boolean;
17
- supportedEncodings: string[];
18
- undo_ttl_s: number;
19
- storeMaxAgeS: number;
20
- storeMaxTotalBytes: number;
21
- }, {
22
- storeDir?: string | undefined;
23
- autoGitignore?: boolean | undefined;
24
- autoGuessEncoding?: boolean | undefined;
25
- normalizeToUtf8?: boolean | undefined;
26
- supportedEncodings?: string[] | undefined;
27
- undo_ttl_s?: number | undefined;
28
- storeMaxAgeS?: number | undefined;
29
- storeMaxTotalBytes?: number | undefined;
30
- }>;
12
+ }, z.core.$strip>;
31
13
  export type StoreConfig = z.infer<typeof StoreConfigSchema>;
32
14
  /** Default config.yaml content with comments — generated when the file does not exist. */
33
15
  export declare const DEFAULT_CONFIG_YAML = "# dsh-better-edit config\n# Location: $DSH_HOME/plugins/dsh-better-edit/config.yaml\n# Docs: https://github.com/Rianico/dsh-better-edit#configuration\n# Generated with defaults on first load \u2014 edit or delete freely.\n# DB files are disposable caches \u2014 safe to delete, rebuilt on next `read`.\n\n# where the store lives: \"central\" (default, in $DSH_HOME/.../runtime/<name>-<hash8>/) | \"workspace\" (legacy <ws>/.dsh_better_edit/) | \"/abs/path\" (custom root)\nstoreDir: central\n\n# workspace only: when .git exists but .gitignore lacks .dsh_better_edit/, true = auto-append \".dsh_better_edit/\", false = warn once\nautoGitignore: false\n\n# encoding: deterministic BOM\u2192UTF-8 first, guessing only when autoGuessEncoding:true\n# when true, FS_NOT_TEXT scores supportedEncodings and surfaces top-3 previews for model pick\nautoGuessEncoding: false\n# when true, legacy files (GBK etc.) migrate to UTF-8 on first write\nnormalizeToUtf8: false\n# allowlist scored for top-3 previews when autoGuessEncoding:true\nsupportedEncodings: [gbk, big5, shift_jis, euc-kr, windows-1251, iso-8859-1]\n\n# undo history TTL in seconds; -1 = keep forever (default 604800 = 7 days)\nundo_ttl_s: 604800\n\n# central janitor: max idle age in seconds before evicting runtime/<name>-<hash8>/ (default 2592000 = 30 days)\nstoreMaxAgeS: 2592000\n\n# central janitor: max total bytes under runtime/ before LRU eviction (default 524288000 = 500 MB)\nstoreMaxTotalBytes: 524288000\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",
@@ -53,7 +53,7 @@
53
53
  "file-type": "^21.3.0",
54
54
  "iconv-lite": "^0.6.3",
55
55
  "xxhash-wasm": "^1.1.0",
56
- "zod": "^3.25.76"
56
+ "zod": "^4.6.7"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@biomejs/biome": "^2.1.0",
@@ -68,7 +68,7 @@
68
68
  "@deepseek-ai/dsh-tools": "0.2.1-rc.2",
69
69
  "@semantic-release/changelog": "^7.0.0",
70
70
  "@semantic-release/git": "^11.0.1",
71
- "@semantic-release/github": "^12.0.9",
71
+ "@semantic-release/github": "^12.0.10",
72
72
  "@types/node": "^24.0.0",
73
73
  "@vitest/coverage-v8": "^4.1.10",
74
74
  "conventional-changelog-conventionalcommits": "^8.0.0",