dsh-better-edit 0.3.0 → 0.3.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +9 -5
  3. package/README.zh.md +1 -2
  4. package/lib/constants.js +3 -1
  5. package/lib/contract.js +133 -76
  6. package/lib/drift.js +5 -98
  7. package/lib/dsh-context.js +2 -24
  8. package/lib/edit-engine.js +6 -5
  9. package/lib/edit-pipeline.js +3 -121
  10. package/lib/edit-response.js +16 -8
  11. package/lib/file-kind.js +6 -121
  12. package/lib/file-reader.js +4 -77
  13. package/lib/file-view.js +446 -23
  14. package/lib/guidance/materialize.js +25 -4
  15. package/lib/guidance/resolve.js +3 -9
  16. package/lib/hash-store.js +6 -3
  17. package/lib/hashline/alphabet.js +2 -6
  18. package/lib/hashline/anchor-pipeline.js +770 -7
  19. package/lib/hashline/apply.js +2 -223
  20. package/lib/hashline/hash-assign.js +248 -13
  21. package/lib/hashline/hash.js +67 -29
  22. package/lib/hashline/hasher.js +2 -23
  23. package/lib/hashline/index.js +7 -1
  24. package/lib/hashline/parse.js +2 -35
  25. package/lib/hashline/pure.js +2 -213
  26. package/lib/hashline/resolve.js +3 -366
  27. package/lib/hashline/served.js +2 -120
  28. package/lib/index.js +0 -2
  29. package/lib/mutation.js +218 -10
  30. package/lib/noop-guard.js +20 -0
  31. package/lib/preview-controller.js +65 -0
  32. package/lib/prompts.js +14 -20
  33. package/lib/read-render.js +3 -139
  34. package/lib/served-store.js +2 -216
  35. package/lib/session-view.js +309 -11
  36. package/lib/tool-edit.js +71 -125
  37. package/lib/tool-undo.js +11 -5
  38. package/lib/truncate.js +3 -95
  39. package/lib/types/constants.d.ts +2 -0
  40. package/lib/types/contract.d.ts +102 -28
  41. package/lib/types/drift.d.ts +5 -29
  42. package/lib/types/dsh-context.d.ts +2 -20
  43. package/lib/types/edit-pipeline.d.ts +3 -44
  44. package/lib/types/file-kind.d.ts +6 -18
  45. package/lib/types/file-reader.d.ts +4 -45
  46. package/lib/types/file-view.d.ts +99 -34
  47. package/lib/types/guidance/materialize.d.ts +3 -3
  48. package/lib/types/guidance/resolve.d.ts +2 -2
  49. package/lib/types/hashline/alphabet.d.ts +1 -5
  50. package/lib/types/hashline/anchor-pipeline.d.ts +111 -10
  51. package/lib/types/hashline/apply.d.ts +1 -22
  52. package/lib/types/hashline/hash-assign.d.ts +25 -19
  53. package/lib/types/hashline/hash.d.ts +8 -9
  54. package/lib/types/hashline/hasher.d.ts +1 -8
  55. package/lib/types/hashline/index.d.ts +7 -1
  56. package/lib/types/hashline/parse.d.ts +1 -7
  57. package/lib/types/hashline/pure.d.ts +1 -26
  58. package/lib/types/hashline/resolve.d.ts +1 -63
  59. package/lib/types/hashline/served.d.ts +1 -43
  60. package/lib/types/mutation.d.ts +63 -10
  61. package/lib/types/noop-guard.d.ts +29 -0
  62. package/lib/types/preview-controller.d.ts +33 -0
  63. package/lib/types/prompts.d.ts +9 -9
  64. package/lib/types/read-render.d.ts +3 -18
  65. package/lib/types/served-store.d.ts +2 -81
  66. package/lib/types/session-view.d.ts +68 -9
  67. package/lib/types/tool-edit.d.ts +3 -14
  68. package/lib/types/truncate.d.ts +3 -29
  69. package/lib/types/validation.d.ts +6 -7
  70. package/lib/types/workspace.d.ts +2 -21
  71. package/lib/validation.js +6 -33
  72. package/lib/workspace.js +2 -27
  73. package/package.json +2 -2
@@ -4,12 +4,12 @@ export declare const DEFAULT_PRESETS: readonly string[];
4
4
  * The root README: the per-preset customization convention users see in the
5
5
  * plugin home.
6
6
  */
7
- export declare const GUIDANCE_HOME_README = "# dsh-better-edit guidance\n\nEach agent preset has its own guidance directory here: `<preset>/<section>.md`.\nOn first boot the plugin seeds the shipped presets (`standard`, `code`,\n`minimal`, `cordis`) with the compiled defaults; existing files are never\noverwritten, so your edits survive.\n\nEach file is one tool section:\n\n- `read.md` -> `tool:read`\n- `edit.md` -> `tool:edit`\n- `batch_edit.md` -> `tool:batch_edit`\n- `undo_last_edit.md` -> `tool:undo_last_edit`\n\n## Customize\n\nEdit the `<section>.md` file for the preset and section you want to change \u2014\nthe file body IS the text the model reads for that section. Files are read once\nper agent at session-start, so edits apply to new sessions.\n\nAn optional YAML front-matter fence places the section at a custom position in\nthe assembled system prompt:\n\n ---\n order: 150\n ---\n\n <section text>\n\nA file without front-matter keeps the default order. A malformed fence (a\nmissing closing `---`, a non-integer `order`, an unknown key) makes the whole\nfile plain prose.\n\n## Fallback\n\nA preset with no directory here, or a missing section file, falls back to the\ncompiled defaults in the plugin bundle. To customize a preset that has no\nseeded directory, copy a seeded one to its name.\n";
8
- export declare const GUIDANCE_HOME_README_ZH = "# dsh-better-edit \u6307\u5F15\n\n\u6BCF\u4E2A agent preset \u5728\u8FD9\u91CC\u90FD\u6709\u81EA\u5DF1\u7684\u6307\u5F15\u76EE\u5F55\uFF1A`<preset>/<section>.md`\u3002\u9996\u6B21\u542F\u52A8\u65F6\n\u63D2\u4EF6\u4F1A\u4E3A\u968F\u9644\u7684 preset\uFF08`standard`\u3001`code`\u3001`minimal`\u3001`cordis`\uFF09\u5199\u5165\u7F16\u8BD1\u5185\u7F6E\u7684\n\u9ED8\u8BA4\u5185\u5BB9\uFF1B\u5DF2\u6709\u6587\u4EF6\u7EDD\u4E0D\u88AB\u8986\u76D6\uFF0C\u56E0\u6B64\u4F60\u7684\u7F16\u8F91\u4F1A\u4FDD\u7559\u3002\n\n\u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A\n\n- `read.md` -> `tool:read`\n- `edit.md` -> `tool:edit`\n- `batch_edit.md` -> `tool:batch_edit`\n- `undo_last_edit.md` -> `tool:undo_last_edit`\n\n## \u81EA\u5B9A\u4E49\n\n\u7F16\u8F91\u4F60\u60F3\u4FEE\u6539\u7684 preset \u4E0E\u7247\u6BB5\u7684 `<section>.md` \u6587\u4EF6\u5373\u53EF\u2014\u2014\u6587\u4EF6\u6B63\u6587\u5C31\u662F\u8BE5\u7247\u6BB5\u5448\n\u73B0\u7ED9\u6A21\u578B\u7684\u6587\u672C\u3002\u6587\u4EF6\u5728 agent \u7684 session-start \u65F6\u8BFB\u53D6\u4E00\u6B21\uFF0C\u56E0\u6B64\u4FEE\u6539\u53EA\u5F71\u54CD\u65B0\u4F1A\u8BDD\u3002\n\n\u53EF\u4EE5\u7528\u53EF\u9009\u7684 YAML front-matter \u6805\u680F\u628A\u7247\u6BB5\u653E\u5230\u7EC4\u88C5\u540E\u7CFB\u7EDF\u63D0\u793A\u4E2D\u7684\u81EA\u5B9A\u4E49\u4F4D\u7F6E\uFF1A\n\n ---\n order: 150\n ---\n\n <\u7247\u6BB5\u6587\u672C>\n\n\u6CA1\u6709 front-matter \u7684\u6587\u4EF6\u4FDD\u6301\u9ED8\u8BA4\u987A\u5E8F\u3002\u683C\u5F0F\u9519\u8BEF\u7684\u6805\u680F\uFF08\u7F3A\u5C11\u6536\u5C3E `---`\u3001\u975E\u6574\u6570\n`order`\u3001\u672A\u77E5\u952E\uFF09\u4F1A\u8BA9\u6574\u4E2A\u6587\u4EF6\u9000\u5316\u4E3A\u7EAF\u6587\u672C\u3002\n\n## \u56DE\u9000\n\n\u8FD9\u91CC\u6CA1\u6709\u5BF9\u5E94\u76EE\u5F55\u7684 preset\u3001\u6216\u7F3A\u5931\u67D0\u4E2A\u7247\u6BB5\u6587\u4EF6\u65F6\uFF0C\u4F1A\u56DE\u9000\u5230\u63D2\u4EF6\u5305\u5185\u7684\u7F16\u8BD1\u5185\u7F6E\u9ED8\u8BA4\n\u503C\u3002\u8981\u81EA\u5B9A\u4E49\u6CA1\u6709\u79CD\u5B50\u76EE\u5F55\u7684 preset\uFF0C\u628A\u4E00\u4E2A\u79CD\u5B50\u76EE\u5F55\u590D\u5236\u6210\u5B83\u7684\u540D\u5B57\u5373\u53EF\u3002\n";
7
+ export declare const GUIDANCE_HOME_README = "# dsh-better-edit guidance\n\nEach agent preset has its own guidance directory here: `<preset>/<section>.md`.\nOn first boot the plugin seeds the shipped presets (`standard`, `code`,\n`minimal`, `cordis`) with the compiled defaults; existing files are never\noverwritten, so your edits survive.\n\nEach file is one tool section:\n\n- `read.md` -> `tool:read`\n- `edit.md` -> `tool:edit`\n- `undo_last_edit.md` -> `tool:undo_last_edit`\n\n## Customize\n\nEdit the `<section>.md` file for the preset and section you want to change \u2014\nthe file body IS the text the model reads for that section. Files are read once\nper agent at session-start, so edits apply to new sessions.\n\nAn optional YAML front-matter fence places the section at a custom position in\nthe assembled system prompt:\n\n ---\n order: 150\n ---\n\n <section text>\n\nA file without front-matter keeps the default order. A malformed fence (a\nmissing closing `---`, a non-integer `order`, an unknown key) makes the whole\nfile plain prose.\n\n## Fallback\n\nA preset with no directory here, or a missing section file, falls back to the\ncompiled defaults in the plugin bundle. To customize a preset that has no\nseeded directory, copy a seeded one to its name.\n";
8
+ export declare const GUIDANCE_HOME_README_ZH = "# dsh-better-edit \u6307\u5F15\n\n\u6BCF\u4E2A agent preset \u5728\u8FD9\u91CC\u90FD\u6709\u81EA\u5DF1\u7684\u6307\u5F15\u76EE\u5F55\uFF1A`<preset>/<section>.md`\u3002\u9996\u6B21\u542F\u52A8\u65F6\n\u63D2\u4EF6\u4F1A\u4E3A\u968F\u9644\u7684 preset\uFF08`standard`\u3001`code`\u3001`minimal`\u3001`cordis`\uFF09\u5199\u5165\u7F16\u8BD1\u5185\u7F6E\u7684\n\u9ED8\u8BA4\u5185\u5BB9\uFF1B\u5DF2\u6709\u6587\u4EF6\u7EDD\u4E0D\u88AB\u8986\u76D6\uFF0C\u56E0\u6B64\u4F60\u7684\u7F16\u8F91\u4F1A\u4FDD\u7559\u3002\n\n\u6BCF\u4E2A\u6587\u4EF6\u5BF9\u5E94\u4E00\u4E2A\u5DE5\u5177\u7247\u6BB5\uFF1A\n\n- `read.md` -> `tool:read`\n- `edit.md` -> `tool:edit`\n- `undo_last_edit.md` -> `tool:undo_last_edit`\n\n## \u81EA\u5B9A\u4E49\n\n\u7F16\u8F91\u4F60\u60F3\u4FEE\u6539\u7684 preset \u4E0E\u7247\u6BB5\u7684 `<section>.md` \u6587\u4EF6\u5373\u53EF\u2014\u2014\u6587\u4EF6\u6B63\u6587\u5C31\u662F\u8BE5\u7247\u6BB5\u5448\n\u73B0\u7ED9\u6A21\u578B\u7684\u6587\u672C\u3002\u6587\u4EF6\u5728 agent \u7684 session-start \u65F6\u8BFB\u53D6\u4E00\u6B21\uFF0C\u56E0\u6B64\u4FEE\u6539\u53EA\u5F71\u54CD\u65B0\u4F1A\u8BDD\u3002\n\n\u53EF\u4EE5\u7528\u53EF\u9009\u7684 YAML front-matter \u6805\u680F\u628A\u7247\u6BB5\u653E\u5230\u7EC4\u88C5\u540E\u7CFB\u7EDF\u63D0\u793A\u4E2D\u7684\u81EA\u5B9A\u4E49\u4F4D\u7F6E\uFF1A\n\n ---\n order: 150\n ---\n\n <\u7247\u6BB5\u6587\u672C>\n\n\u6CA1\u6709 front-matter \u7684\u6587\u4EF6\u4FDD\u6301\u9ED8\u8BA4\u987A\u5E8F\u3002\u683C\u5F0F\u9519\u8BEF\u7684\u6805\u680F\uFF08\u7F3A\u5C11\u6536\u5C3E `---`\u3001\u975E\u6574\u6570\n`order`\u3001\u672A\u77E5\u952E\uFF09\u4F1A\u8BA9\u6574\u4E2A\u6587\u4EF6\u9000\u5316\u4E3A\u7EAF\u6587\u672C\u3002\n\n## \u56DE\u9000\n\n\u8FD9\u91CC\u6CA1\u6709\u5BF9\u5E94\u76EE\u5F55\u7684 preset\u3001\u6216\u7F3A\u5931\u67D0\u4E2A\u7247\u6BB5\u6587\u4EF6\u65F6\uFF0C\u4F1A\u56DE\u9000\u5230\u63D2\u4EF6\u5305\u5185\u7684\u7F16\u8BD1\u5185\u7F6E\u9ED8\u8BA4\n\u503C\u3002\u8981\u81EA\u5B9A\u4E49\u6CA1\u6709\u79CD\u5B50\u76EE\u5F55\u7684 preset\uFF0C\u628A\u4E00\u4E2A\u79CD\u5B50\u76EE\u5F55\u590D\u5236\u6210\u5B83\u7684\u540D\u5B57\u5373\u53EF\u3002\n";
9
9
  /**
10
10
  * Materialize per-preset guidance directories in the plugin home.
11
11
  *
12
- * For each of `DEFAULT_PRESETS` creates `<preset>/{read,edit,batch_edit,
12
+ * For each of `DEFAULT_PRESETS` creates `<preset>/{read,edit,
13
13
  * undo_last_edit}.md` rendered from the compiled defaults (with order
14
14
  * front-matter), plus a root `README.md` documenting the convention.
15
15
  * Idempotent: a user-edited file survives repeated calls. A blank override file
@@ -9,7 +9,7 @@ export interface GuidanceSection {
9
9
  /** The compiled default text, byte-identical to today's inline rendering. */
10
10
  renderDefault(): string;
11
11
  }
12
- /** The four sections, in default-order sequence. */
12
+ /** The three sections, in default-order sequence. */
13
13
  export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
14
14
  /** Render the compiled default text for one section. */
15
15
  export declare function renderSectionDefault(name: string): string;
@@ -49,7 +49,7 @@ export interface SectionOverride {
49
49
  };
50
50
  }
51
51
  /**
52
- * Resolve all four sections for a preset. `presetId === undefined` skips the
52
+ * Resolve all three sections for a preset. `presetId === undefined` skips the
53
53
  * `<preset>/` layer and resolves straight to the compiled defaults.
54
54
  */
55
55
  export declare function composeSections(presetId: string | undefined, homeDir: string): Promise<SectionOverride[]>;
@@ -1,5 +1 @@
1
- export declare const HASH_LEN = 3;
2
- export declare const ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
3
- export declare const ALPH_RE: RegExp;
4
- export declare const HASH_CLASS: string;
5
- export declare const HASH_RE: RegExp;
1
+ export * from "./hash-assign.js";
@@ -11,16 +11,117 @@
11
11
  * applyEdit — full pipeline (file + hashes + served verification)
12
12
  *
13
13
  * Private to this seam (not re-exported): stripBarePrefixes, stripDiffPrefixes,
14
- * swapReversedRanges, valEdit, boundaryDups helpers, warnUnicodeEsc, findNewEdge.
15
- * They remain exported from resolve.ts for backwards compat but are marked
16
- * @internal and should be imported via this module only.
14
+ * swapReversedRanges, valEdit, boundaryDups helpers, warnUnicodeEsc, findNewEdge,
15
+ * resAnchorFromMap, assertAligned, etc. They remain exported from resolve.ts
16
+ * for backwards compat but are marked @internal and should be imported via this
17
+ * module only.
17
18
  *
18
19
  * @module dsh-better-edit/hashline/anchor-pipeline
19
20
  */
20
- export { resEdit } from "./resolve.js";
21
- export type { HEdit, HTEdit, NEdit, BDup, AutoFix } from "./resolve.js";
22
- export { applyEdit, fmtRegion, changedRange, buildIdx } from "./apply.js";
23
- export type { Anchor } from "./parse.js";
24
- export { parseHashRef, parseText } from "./parse.js";
25
- export { ServedRejectionError, AnchorMismatchError, isServedRejection, isAnchorMismatch, verifyServedRange, buildRangeEcho, fmtServedRows, recordEchoServes, } from "./served.js";
26
- export type { ServedRow, ResolvedRange, ServedCode, ServeRecordPolicy, } from "./served.js";
21
+ export type Anchor = {
22
+ hash: string;
23
+ };
24
+ declare function parseRef(ref: string): Anchor;
25
+ export declare const parseHashRef: typeof parseRef;
26
+ export declare function parseText(edit: string): string[];
27
+ export type RAnchor = {
28
+ line: number;
29
+ hash: string;
30
+ hashMatched: boolean;
31
+ };
32
+ export type HEdit = {
33
+ content_lines: string[];
34
+ hash_bounds: [Anchor, Anchor];
35
+ };
36
+ export type RHEdit = {
37
+ content_lines: string[];
38
+ hash_bounds: [RAnchor, RAnchor];
39
+ };
40
+ export interface BDup {
41
+ kind: "trailing" | "leading" | "first-new-after" | "last-new-before";
42
+ replacementLineIndex: number;
43
+ }
44
+ export interface AutoFix {
45
+ kind: "trailing" | "leading" | "first-new-after" | "last-new-before";
46
+ removedLine: string;
47
+ removedLineIndex: number;
48
+ }
49
+ export interface NEdit {
50
+ loc: string;
51
+ currentContent: string;
52
+ }
53
+ export type HTEdit = {
54
+ replacement_text: string;
55
+ remove_from: string;
56
+ remove_to: string;
57
+ };
58
+ export declare function resEdit(edit: HTEdit, warnings?: string[]): HEdit;
59
+ declare function warnUnicodeEsc(edit: HEdit, warnings: string[]): void;
60
+ /** @internal — private to anchor-pipeline seam */
61
+ export declare function findNewEdge(contentLines: string[], rangeLines: string[], fromEnd: boolean): {
62
+ index: number;
63
+ line: string;
64
+ } | undefined;
65
+ export { warnUnicodeEsc };
66
+ export type ServedCode = "E_RANGE_STALE" | "E_RANGE_UNSERVED" | "E_RANGE_UNVERIFIED";
67
+ export interface ServedRow {
68
+ position: number;
69
+ hash: string;
70
+ }
71
+ export declare class ServedRejectionError extends Error {
72
+ readonly code: ServedCode;
73
+ readonly firstOffendingLine: number | undefined;
74
+ readonly servedRows: ServedRow[];
75
+ constructor(opts: {
76
+ code: ServedCode;
77
+ message: string;
78
+ firstOffendingLine?: number;
79
+ servedRows: ServedRow[];
80
+ });
81
+ }
82
+ export declare function isServedRejection(error: unknown): error is ServedRejectionError;
83
+ export declare class AnchorMismatchError extends Error {
84
+ readonly servedRows: ServedRow[];
85
+ constructor(message: string, servedRows: ServedRow[]);
86
+ }
87
+ export declare function isAnchorMismatch(error: unknown): error is AnchorMismatchError;
88
+ export declare function buildRangeEcho(startLine: number, endLine: number, fileHashes: string[]): ServedRow[];
89
+ export declare function fmtServedRows(rows: ServedRow[], fileLines: string[]): string;
90
+ export declare function verifyServedRange(args: {
91
+ served: (string | null)[];
92
+ startHash: string;
93
+ endHash: string;
94
+ startLine: number;
95
+ endLine: number;
96
+ fileHashes: string[];
97
+ fileLines: string[];
98
+ filePath?: string;
99
+ }): void;
100
+ export interface ResolvedRange {
101
+ startLine: number;
102
+ endLine: number;
103
+ startHash: string;
104
+ endHash: string;
105
+ delta: number;
106
+ }
107
+ export type ServeRecordPolicy = "live" | "preview";
108
+ export declare function recordEchoServes(sessionKey: string, path: string, rows: ServedRow[], policy: ServeRecordPolicy, lineCount?: number): Promise<void>;
109
+ type LIdx = {
110
+ fileLines: string[];
111
+ lineStarts: number[];
112
+ };
113
+ export declare function buildIdx(content: string): LIdx;
114
+ export declare function applyEdit(content: string, edit: HEdit, signal?: AbortSignal, precomputedHashes?: string[], filePath?: string, served?: (string | null)[]): {
115
+ content: string;
116
+ firstChangedLine: number | undefined;
117
+ lastChangedLine: number | undefined;
118
+ range: ResolvedRange;
119
+ warnings?: string[];
120
+ noopEdit?: NEdit;
121
+ autoFixes?: AutoFix[];
122
+ };
123
+ export declare function fmtRegion(hashes: string[], lines: string[]): string;
124
+ export declare function changedRange(original: string, result: string): {
125
+ firstChangedLine: number;
126
+ lastChangedLine: number;
127
+ } | null;
@@ -1,22 +1 @@
1
- import { type ResolvedRange } from "./served.js";
2
- import { type NEdit, type HEdit, type AutoFix } from "./resolve.js";
3
- type LIdx = {
4
- fileLines: string[];
5
- lineStarts: number[];
6
- };
7
- export declare function buildIdx(content: string): LIdx;
8
- export declare function applyEdit(content: string, edit: HEdit, signal?: AbortSignal, precomputedHashes?: string[], filePath?: string, served?: (string | null)[]): {
9
- content: string;
10
- firstChangedLine: number | undefined;
11
- lastChangedLine: number | undefined;
12
- range: ResolvedRange;
13
- warnings?: string[];
14
- noopEdit?: NEdit;
15
- autoFixes?: AutoFix[];
16
- };
17
- export declare function fmtRegion(hashes: string[], lines: string[]): string;
18
- export declare function changedRange(original: string, result: string): {
19
- firstChangedLine: number;
20
- lastChangedLine: number;
21
- } | null;
22
- export {};
1
+ export * from "./anchor-pipeline.js";
@@ -1,19 +1,25 @@
1
- /**
2
- * HashAssign — deep module owning hash assignment.
3
- *
4
- * Owns the `HASH_SPACE = 62^3` allocation invariant: every line of a file
5
- * gets a unique 3-char anchor derived from canonicalized content via xxHash
6
- * + probe-stride allocation. The triad `alphabet + hasher + pure + hash`
7
- * is interdependent; this seam hides that coupling.
8
- *
9
- * Private internals (not re-exported as public API): ALPH, idxToHash/hashAt,
10
- * nextZeroBit/assignHash, getBit/setBit, hashToIndex/nearestNew, xxh32 internals.
11
- * Callers use the deep interface below — one test surface for determinism +
12
- * stable mapping + persistence.
13
- *
14
- * @module dsh-better-edit/hashline/hash-assign
15
- */
16
- export { ANCHOR_LEN, HASH_SEP, HASH_SPACE, HASH_PROBE_STRIDE, MAX_HASH_LINES, HL_PREFIX_PLUS_RE, HL_PREFIX_MINUS_RE, HL_BARE_PREFIX_RE, ALPH_RE, HASH_CLASS, HASH_LEN, canon, lineHashesPure, mapStableHashes, initHasher, } from "./pure.js";
17
- export { HASH_RE } from "./alphabet.js";
18
- export { contentChecksum } from "./hasher.js";
19
- export { lineHashes } from "./hash.js";
1
+ export type Hasher = {
2
+ h32(input: string, seed?: number): number;
3
+ h64ToString(input: string, seed?: bigint): string;
4
+ };
5
+ export declare function getH(): Hasher;
6
+ export declare function initHasher(): Promise<Hasher>;
7
+ export declare function xxh32(input: string, seed?: number): number;
8
+ export declare function contentChecksum(content: string): string;
9
+ export declare const HASH_LEN = 3;
10
+ export declare const ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
11
+ export declare const ALPH_RE: RegExp;
12
+ export declare const HASH_CLASS: string;
13
+ export declare const HASH_RE: RegExp;
14
+ export declare const ANCHOR_LEN = 3;
15
+ export declare const HASH_SEP = "\u2502";
16
+ export declare const HASH_SPACE: number;
17
+ export declare const MAX_HASH_LINES: number;
18
+ export declare const HASH_PROBE_STRIDE: number;
19
+ export declare const HL_PREFIX_PLUS_RE: RegExp;
20
+ export declare const HL_PREFIX_MINUS_RE: RegExp;
21
+ export declare const HL_BARE_PREFIX_RE: RegExp;
22
+ export declare const CANON_VERSION = 2;
23
+ export declare function canon(line: string): string;
24
+ export declare function lineHashesPure(content: string): string[];
25
+ export declare function mapStableHashes(oldContent: string, oldHashes: string[], newContent: string, removedHashes?: Set<string>): string[];
@@ -1,14 +1,13 @@
1
1
  import { type HashStore } from "../hash-store.js";
2
- /**
3
- * Persistence-aware hash-anchor assignment: the pure hasher
4
- * ({@link lineHashesPure} / {@link mapStableHashes} in ./pure.js) composed
5
- * with snapshot load/upsert in the hash store, keyed by
6
- * (path, content checksum, line count). Without a `path` this never touches
7
- * the store and is exactly the pure path. With `previous` the stable re-hash
8
- * mapping keeps surviving anchors stable across edits.
9
- */
2
+ export interface HashSnapshotIO {
3
+ get(path: string, content: string, deleteCorrupt: boolean): Promise<string[] | undefined>;
4
+ upsert(path: string, checksum: string, lineCount: number, hashes: string[]): Promise<void>;
5
+ }
6
+ export declare function setDefaultHashSnapshotIO(io: HashSnapshotIO | undefined): void;
7
+ export declare function snapshotIOFor(store?: HashStore): HashSnapshotIO | undefined;
8
+ export declare function isValidHashList(value: unknown): value is string[];
10
9
  export declare function lineHashes(content: string, path?: string, previous?: {
11
10
  content: string;
12
11
  hashes: string[];
13
12
  removedHashes?: Set<string>;
14
- }, store?: HashStore, persist?: boolean): Promise<string[]>;
13
+ }, ioOrStore?: HashStore | HashSnapshotIO, persist?: boolean): Promise<string[]>;
@@ -1,8 +1 @@
1
- export type Hasher = {
2
- h32(input: string, seed?: number): number;
3
- h64ToString(input: string, seed?: bigint): string;
4
- };
5
- export declare function getH(): Hasher;
6
- export declare function initHasher(): Promise<Hasher>;
7
- export declare function xxh32(input: string, seed?: number): number;
8
- export declare function contentChecksum(content: string): string;
1
+ export * from "./hash-assign.js";
@@ -1,4 +1,10 @@
1
- export { ANCHOR_LEN, HASH_SEP, HASH_SPACE, HASH_PROBE_STRIDE, MAX_HASH_LINES, HASH_LEN, HASH_CLASS, HASH_RE, ALPH_RE, HL_PREFIX_PLUS_RE, HL_PREFIX_MINUS_RE, HL_BARE_PREFIX_RE, canon, lineHashesPure, mapStableHashes, initHasher, lineHashes, contentChecksum, } from "./hash-assign.js";
1
+ /**
2
+ * Hashline barrel — thin re-export via deep seams.
3
+ * Deep seams: hash-assign (allocation), anchor-pipeline (ordering), hash (persistence).
4
+ * @module dsh-better-edit/hashline
5
+ */
6
+ export { CANON_VERSION, ANCHOR_LEN, HASH_SEP, HASH_SPACE, HASH_PROBE_STRIDE, MAX_HASH_LINES, HASH_LEN, HASH_CLASS, HASH_RE, ALPH_RE, HL_PREFIX_PLUS_RE, HL_PREFIX_MINUS_RE, HL_BARE_PREFIX_RE, canon, lineHashesPure, mapStableHashes, initHasher, contentChecksum, } from "./hash-assign.js";
7
+ export { lineHashes } from "./hash.js";
2
8
  export { parseHashRef, parseText } from "./parse.js";
3
9
  export type { Anchor } from "./parse.js";
4
10
  export { resEdit } from "./anchor-pipeline.js";
@@ -1,7 +1 @@
1
- export type Anchor = {
2
- hash: string;
3
- };
4
- declare function parseRef(ref: string): Anchor;
5
- export declare const parseHashRef: typeof parseRef;
6
- export declare function parseText(edit: string): string[];
7
- export {};
1
+ export * from "./anchor-pipeline.js";
@@ -1,26 +1 @@
1
- import { initHasher } from "./hasher.js";
2
- import { HASH_LEN, ALPH_RE, HASH_CLASS } from "./alphabet.js";
3
- export { initHasher, HASH_LEN, ALPH_RE, HASH_CLASS };
4
- export declare const ANCHOR_LEN = 3;
5
- export declare const HASH_SEP = "\u2502";
6
- export declare const HASH_SPACE: number;
7
- export declare const MAX_HASH_LINES: number;
8
- export declare const HASH_PROBE_STRIDE: number;
9
- export declare const HL_PREFIX_PLUS_RE: RegExp;
10
- export declare const HL_PREFIX_MINUS_RE: RegExp;
11
- export declare const HL_BARE_PREFIX_RE: RegExp;
12
- export declare function canon(line: string): string;
13
- /**
14
- * Pure hash-anchor assignment: every line of `content` gets a unique 3-char
15
- * anchor derived from its canonicalized content via xxhash32 + probe-stride
16
- * allocation. No I/O, no store — the persistence-aware wrapper
17
- * {@link lineHashes} (in ./hash.js) composes this with snapshot load/upsert.
18
- */
19
- export declare function lineHashesPure(content: string): string[];
20
- /**
21
- * Pure stable re-hash: given the pre-edit content + anchors and the new
22
- * content (plus the hashes removed by the edit), map surviving lines to
23
- * their old anchors, re-claim removed anchors for identical lines, and
24
- * allocate fresh anchors for the rest. No I/O, no store.
25
- */
26
- export declare function mapStableHashes(oldContent: string, oldHashes: string[], newContent: string, removedHashes?: Set<string>): string[];
1
+ export * from "./hash-assign.js";
@@ -1,63 +1 @@
1
- import { type Anchor } from "./parse.js";
2
- import type { ServedRow } from "./served.js";
3
- export type RAnchor = {
4
- line: number;
5
- hash: string;
6
- hashMatched: boolean;
7
- };
8
- export type HEdit = {
9
- content_lines: string[];
10
- hash_bounds: [Anchor, Anchor];
11
- };
12
- export type RHEdit = {
13
- content_lines: string[];
14
- hash_bounds: [RAnchor, RAnchor];
15
- };
16
- interface HMismatch {
17
- ref: Anchor;
18
- kind: "not_found" | "ambiguous";
19
- candidates?: number[];
20
- context?: RAnchor;
21
- }
22
- export interface BDup {
23
- kind: "trailing" | "leading" | "first-new-after" | "last-new-before";
24
- replacementLineIndex: number;
25
- }
26
- export interface AutoFix {
27
- kind: "trailing" | "leading" | "first-new-after" | "last-new-before";
28
- removedLine: string;
29
- removedLineIndex: number;
30
- }
31
- export interface NEdit {
32
- loc: string;
33
- currentContent: string;
34
- }
35
- export type HTEdit = {
36
- replacement_text: string;
37
- remove_from: string;
38
- remove_to: string;
39
- };
40
- export declare function fmtMismatchWithServes(mismatches: HMismatch[], fileLines: string[], fileHashes: string[], filePath?: string): {
41
- message: string;
42
- servedRows: ServedRow[];
43
- };
44
- export declare function resEdit(edit: HTEdit, warnings?: string[]): HEdit;
45
- declare function warnUnicodeEsc(edit: HEdit, warnings: string[]): void;
46
- /** @internal — private to anchor-pipeline seam; do not import directly, use anchor-pipeline.ts */
47
- export declare function stripBarePrefixes(edit: HEdit, fileHashes: string[], warnings: string[]): HEdit;
48
- /** @internal — private to anchor-pipeline seam */
49
- export declare function stripDiffPrefixes(edit: HEdit, warnings: string[]): HEdit;
50
- /** @internal — private to anchor-pipeline seam */
51
- export declare function swapReversedRanges(edit: HEdit, fileHashes: string[], warnings: string[]): HEdit;
52
- /** @internal — private to anchor-pipeline seam */
53
- export declare function findNewEdge(contentLines: string[], rangeLines: string[], fromEnd: boolean): {
54
- index: number;
55
- line: string;
56
- } | undefined;
57
- /** @internal — private to anchor-pipeline seam: detection + boundaryDups belongs to AnchorPipeline ordering */
58
- export declare function valEdit(edit: HEdit, fileLines: string[], fileHashes: string[], warnings: string[], signal: AbortSignal | undefined): {
59
- resolved: RHEdit | undefined;
60
- mismatches: HMismatch[];
61
- boundaryDups: BDup[];
62
- };
63
- export { warnUnicodeEsc };
1
+ export * from "./anchor-pipeline.js";
@@ -1,43 +1 @@
1
- export type ServedCode = "E_RANGE_STALE" | "E_RANGE_UNSERVED" | "E_RANGE_UNVERIFIED";
2
- export interface ServedRow {
3
- position: number;
4
- hash: string;
5
- }
6
- export declare class ServedRejectionError extends Error {
7
- readonly code: ServedCode;
8
- readonly firstOffendingLine: number | undefined;
9
- readonly servedRows: ServedRow[];
10
- constructor(opts: {
11
- code: ServedCode;
12
- message: string;
13
- firstOffendingLine?: number;
14
- servedRows: ServedRow[];
15
- });
16
- }
17
- export declare function isServedRejection(error: unknown): error is ServedRejectionError;
18
- export declare class AnchorMismatchError extends Error {
19
- readonly servedRows: ServedRow[];
20
- constructor(message: string, servedRows: ServedRow[]);
21
- }
22
- export declare function isAnchorMismatch(error: unknown): error is AnchorMismatchError;
23
- export declare function buildRangeEcho(startLine: number, endLine: number, fileHashes: string[]): ServedRow[];
24
- export declare function fmtServedRows(rows: ServedRow[], fileLines: string[]): string;
25
- export declare function verifyServedRange(args: {
26
- served: (string | null)[];
27
- startHash: string;
28
- endHash: string;
29
- startLine: number;
30
- endLine: number;
31
- fileHashes: string[];
32
- fileLines: string[];
33
- filePath?: string;
34
- }): void;
35
- export interface ResolvedRange {
36
- startLine: number;
37
- endLine: number;
38
- startHash: string;
39
- endHash: string;
40
- delta: number;
41
- }
42
- export type ServeRecordPolicy = "live" | "preview";
43
- export declare function recordEchoServes(sessionKey: string, path: string, rows: ServedRow[], policy: ServeRecordPolicy, lineCount?: number): Promise<void>;
1
+ export * from "./anchor-pipeline.js";
@@ -8,13 +8,16 @@
8
8
  * by mutation across 5 hops; bugs hid in wiring, not pure helpers.
9
9
  *
10
10
  * This seam owns: read → normalize → loadServed → applyOne* → stableRehash →
11
- * drift → persist. Tools become thin adapters: validate → delegate → render.
11
+ * drift → persist → render. Tools become thin adapters: validate → delegate → return.
12
12
  * edit-diff, drift, noop-guard are private helpers of this seam.
13
13
  *
14
14
  * Public surface:
15
- * applySingle(io, params, {cwd, sessionKey, signal}) → PipelineResult
16
- * applySequence(io, items, {cwd, sessionKey, signal}) → FileEditResult[]
17
- * commit(io, files, {exec, sandboxPolicy, signal}) → void
15
+ * execute(io, items, {sessionKey, exec, sandbox, signal}) → string — deep seam: ONE interface
16
+ * applySingle(io, params, cwd, opts) → PipelineResult — single-edit helper
17
+ * applySequence(io, items, ctx) → FileEditResult — per-file sequencer
18
+ * commit(io, files, {exec, sandboxPolicy, signal}) → void — transaction
19
+ *
20
+ * Depth: small interface (execute) with large implementation — locality and leverage.
18
21
  *
19
22
  * Internals (private): verifyServedRange, resToSpan, assemble, scanDrift,
20
23
  * boundaryDups, noopGuard. Tested via PipelineResult/FileEditResult, not via split e2e.
@@ -27,24 +30,74 @@ import type { HashStore } from "./hash-store.js";
27
30
  import type { ToolExecution } from "@deepseek-ai/dsh-tools";
28
31
  import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
29
32
  import type { FsSandboxController } from "./sandbox.js";
30
- import { execPipeline, snapshotIdFor } from "./edit-pipeline.js";
31
- import type { PipelineResult } from "./edit-pipeline.js";
33
+ import type { LineEnding } from "./edit-diff.js";
34
+ import { type NEdit } from "./hashline/anchor-pipeline.js";
35
+ import type { ResolvedRange } from "./hashline/anchor-pipeline.js";
36
+ import { scanDrift } from "./session-view.js";
32
37
  import { runFileEdits, resolveMissingPath, persistUndoAndWrite, enforceNoopLoop, collectRemovedHashes, countLineChanges } from "./edit-engine.js";
33
38
  import type { FileEditResult, PreparedItem } from "./edit-engine.js";
34
39
  import { buildMetrics, buildNoop, buildChanged, buildBatchResult } from "./edit-response.js";
35
40
  import type { RMeta, BatchSection } from "./edit-response.js";
36
41
  import { genDiff, restoreEndings, toLF, stripBOM } from "./edit-diff.js";
37
- import { computeDrift, scanDrift } from "./drift.js";
42
+ import { computeDrift } from "./drift.js";
38
43
  import { trackNoopPayload, clearNoopLoop, noopPayloadKey } from "./noop-guard.js";
39
- export { execPipeline, snapshotIdFor };
40
- export type { PipelineResult };
41
- export { runFileEdits, resolveMissingPath, persistUndoAndWrite, enforceNoopLoop, collectRemovedHashes, countLineChanges };
44
+ export interface PipelineResult {
45
+ path: string;
46
+ absolutePath: string;
47
+ originalNormalized: string;
48
+ result: string;
49
+ bom: string;
50
+ originalEnding: LineEnding;
51
+ hadUtf8DecodeErrors: boolean;
52
+ warnings: string[];
53
+ noopEdit?: NEdit;
54
+ firstChangedLine?: number;
55
+ lastChangedLine?: number;
56
+ originalHashes: string[];
57
+ resultHashes: string[];
58
+ totalAddedLines: number;
59
+ totalRemovedLines: number;
60
+ driftNotice?: string;
61
+ range: ResolvedRange;
62
+ }
63
+ export interface ExecPipelineOptions {
64
+ signal?: AbortSignal;
65
+ store?: HashStore;
66
+ noPersist?: boolean;
67
+ sessionKey?: string;
68
+ }
69
+ export declare function execPipeline(io: FileIO, params: EditParams, cwd: string, options?: ExecPipelineOptions): Promise<PipelineResult>;
70
+ /** Resolve the display path a caller names against the session cwd. */
71
+ export declare function resolveDisplayPath(path: string, cwd: string): string;
72
+ /** Snapshot bookkeeping for noop/success results (best-effort). */
73
+ export declare function snapshotIdFor(io: FileIO, absolutePath: string, signal?: AbortSignal): Promise<string | undefined>;
74
+ export { runFileEdits, resolveMissingPath, persistUndoAndWrite, enforceNoopLoop, collectRemovedHashes, countLineChanges, };
42
75
  export type { FileEditResult, PreparedItem };
43
76
  export { buildMetrics, buildNoop, buildChanged, buildBatchResult };
44
77
  export type { RMeta, BatchSection };
45
78
  export { genDiff, restoreEndings, toLF, stripBOM };
46
79
  export { computeDrift, scanDrift };
47
80
  export { trackNoopPayload, clearNoopLoop, noopPayloadKey };
81
+ /**
82
+ * Deep seam: execute the full mutation lifecycle.
83
+ *
84
+ * Owns: applySequence → branch (single/multi × noop/applied) → commit →
85
+ * buildBatchResult → recordServedTruncated → return text.
86
+ *
87
+ * The tool layer (adapter) only validates and resolves the nullable path; all
88
+ * lifecycle branching concentrates here (locality). One interface serves N
89
+ * call sites (leverage). Deleting this module would scatter the lifecycle
90
+ * across every tool — it concentrates (deep).
91
+ */
92
+ export declare function execute(opts: {
93
+ io: FileIO;
94
+ items: PreparedItem[];
95
+ sessionKey: string;
96
+ signal?: AbortSignal;
97
+ exec: ToolExecution;
98
+ sandbox: FsSandboxController;
99
+ sandboxPolicy: SandboxExecutionPolicy | undefined;
100
+ }): Promise<string>;
48
101
  /** Apply a single edit — owns read→normalize→loadServed→applyOne→stableRehash→drift. */
49
102
  export declare function applySingle(io: FileIO, params: EditParams, cwd: string, opts?: {
50
103
  sessionKey?: string;
@@ -3,3 +3,32 @@ export declare function noopPayloadKey(absolutePath: string, removeFrom: string,
3
3
  export declare function trackNoopPayload(absolutePath: string, payload: string): number;
4
4
  export declare function clearNoopLoop(absolutePath: string): void;
5
5
  export { NOOP_LOOP_THRESHOLD };
6
+ export interface NoopPolicyInput {
7
+ absolutePath: string;
8
+ removeFrom: string;
9
+ removeTo: string;
10
+ replacementText: string;
11
+ ref: string;
12
+ batch: boolean;
13
+ range: {
14
+ startLine: number;
15
+ endLine: number;
16
+ };
17
+ hashes: string[];
18
+ lines: string[];
19
+ sessionKey: string;
20
+ }
21
+ export type NoopPolicyOutcome = {
22
+ action: "proceed";
23
+ count: number;
24
+ } | {
25
+ action: "warn";
26
+ count: number;
27
+ notice: string;
28
+ } | {
29
+ action: "reject";
30
+ count: number;
31
+ message: string;
32
+ };
33
+ export declare function runNoopPolicySync(input: NoopPolicyInput, count: number): NoopPolicyOutcome;
34
+ export declare function runNoopPolicy(input: NoopPolicyInput): Promise<NoopPolicyOutcome>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Debounced preview controller — extracted from buildToolDef so hashline seams
3
+ * stay pure and the debounce invariant is testable.
4
+ * @module dsh-better-edit/preview-controller
5
+ */
6
+ export declare const PREVIEW_DEBOUNCE_MS = 150;
7
+ export interface PreviewHost {
8
+ cwd: string;
9
+ executionStarted: boolean;
10
+ argsComplete: boolean;
11
+ state: RRState;
12
+ invalidate: () => void;
13
+ }
14
+ export type PreviewCompute = (args: unknown, cwd: string) => Promise<RPreview>;
15
+ export interface RPreview {
16
+ error?: string;
17
+ text?: string;
18
+ }
19
+ export interface RRState {
20
+ argsKey?: string;
21
+ preview?: RPreview;
22
+ previewGeneration?: number;
23
+ previewTimer?: ReturnType<typeof setTimeout>;
24
+ }
25
+ export declare function getPreviewInput(_args: unknown): unknown;
26
+ export declare class DebouncedPreview {
27
+ private readonly compute;
28
+ private readonly debounceMs;
29
+ constructor(compute: PreviewCompute, debounceMs?: number);
30
+ renderCall(host: PreviewHost, args: unknown): void;
31
+ cancel(state: RRState): void;
32
+ clearResult(state: RRState): void;
33
+ }