dsh-better-edit 0.2.2 → 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.
- package/CHANGELOG.md +33 -0
- package/README.md +317 -240
- package/README.zh.md +19 -11
- package/lib/constants.js +3 -1
- package/lib/contract.js +159 -63
- package/lib/drift.js +5 -98
- package/lib/dsh-context.js +2 -24
- package/lib/edit-engine.js +9 -8
- package/lib/edit-pipeline.js +3 -121
- package/lib/edit-response.js +16 -8
- package/lib/file-kind.js +6 -121
- package/lib/file-reader.js +4 -77
- package/lib/file-view.js +486 -0
- package/lib/guidance/index.js +8 -0
- package/lib/guidance/materialize.js +212 -0
- package/lib/guidance/parse.js +80 -0
- package/lib/guidance/resolve.js +116 -0
- package/lib/guidance.js +6 -388
- package/lib/hash-store.js +6 -4
- package/lib/hashline/alphabet.js +2 -6
- package/lib/hashline/anchor-pipeline.js +786 -0
- package/lib/hashline/apply.js +2 -223
- package/lib/hashline/hash-assign.js +255 -0
- package/lib/hashline/hash.js +67 -29
- package/lib/hashline/hasher.js +2 -23
- package/lib/hashline/index.js +9 -4
- package/lib/hashline/parse.js +2 -35
- package/lib/hashline/pure.js +2 -213
- package/lib/hashline/resolve.js +3 -361
- package/lib/hashline/served.js +2 -120
- package/lib/index.js +1 -3
- package/lib/mutation.js +266 -0
- package/lib/noop-guard.js +20 -0
- package/lib/preview-controller.js +65 -0
- package/lib/prompts.js +14 -20
- package/lib/read-and-serve.js +23 -23
- package/lib/read-render.js +3 -139
- package/lib/served-store.js +2 -216
- package/lib/session-view.js +332 -0
- package/lib/tool-batch-edit.js +9 -10
- package/lib/tool-edit.js +73 -129
- package/lib/tool-read.js +3 -5
- package/lib/tool-undo.js +16 -10
- package/lib/truncate.js +3 -95
- package/lib/types/constants.d.ts +2 -0
- package/lib/types/contract.d.ts +120 -15
- package/lib/types/drift.d.ts +5 -29
- package/lib/types/dsh-context.d.ts +2 -20
- package/lib/types/edit-engine.d.ts +2 -2
- package/lib/types/edit-pipeline.d.ts +3 -44
- package/lib/types/file-kind.d.ts +6 -18
- package/lib/types/file-reader.d.ts +4 -45
- package/lib/types/file-view.d.ts +139 -0
- package/lib/types/guidance/index.d.ts +8 -0
- package/lib/types/guidance/materialize.d.ts +23 -0
- package/lib/types/guidance/parse.d.ts +36 -0
- package/lib/types/guidance/resolve.d.ts +55 -0
- package/lib/types/guidance.d.ts +6 -127
- package/lib/types/hashline/alphabet.d.ts +1 -5
- package/lib/types/hashline/anchor-pipeline.d.ts +127 -0
- package/lib/types/hashline/apply.d.ts +1 -22
- package/lib/types/hashline/hash-assign.d.ts +25 -0
- package/lib/types/hashline/hash.d.ts +8 -9
- package/lib/types/hashline/hasher.d.ts +1 -8
- package/lib/types/hashline/index.d.ts +12 -4
- package/lib/types/hashline/parse.d.ts +1 -7
- package/lib/types/hashline/pure.d.ts +1 -26
- package/lib/types/hashline/resolve.d.ts +1 -58
- package/lib/types/hashline/served.d.ts +1 -43
- package/lib/types/mutation.d.ts +131 -0
- package/lib/types/noop-guard.d.ts +29 -0
- package/lib/types/preview-controller.d.ts +33 -0
- package/lib/types/prompts.d.ts +9 -9
- package/lib/types/read-and-serve.d.ts +6 -5
- package/lib/types/read-render.d.ts +3 -18
- package/lib/types/served-store.d.ts +2 -81
- package/lib/types/session-view.d.ts +92 -0
- package/lib/types/tool-edit.d.ts +3 -14
- package/lib/types/truncate.d.ts +3 -29
- package/lib/types/validation.d.ts +6 -7
- package/lib/types/workspace.d.ts +2 -21
- package/lib/validation.js +6 -33
- package/lib/workspace.js +2 -27
- package/lib/write-hook.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileView — deep module owning "what the model sees".
|
|
3
|
+
*
|
|
4
|
+
* Single seam for normalize → hash → render → truncate → served-row
|
|
5
|
+
* selection. Previously split across file-reader, read-render, truncate,
|
|
6
|
+
* file-kind, validation — each shallow (interface≈implementation). Now one
|
|
7
|
+
* file owns the invariant; deleting it would scatter complexity (deep).
|
|
8
|
+
*
|
|
9
|
+
* Private helpers inlined from file-reader (normFromText/fileSnap),
|
|
10
|
+
* read-render (fmtReadPreview), truncate (truncateHead), file-kind
|
|
11
|
+
* (loadFileKindAndText), validation (valKind/valAccess).
|
|
12
|
+
* Old files are shims re-exporting from this seam for compat.
|
|
13
|
+
*
|
|
14
|
+
* Two surfaces:
|
|
15
|
+
* - `preview` (pure, no IO) — tested without filesystem
|
|
16
|
+
* - `readView` (IO) — read + normalize + render + truncate + hashes
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-better-edit/file-view
|
|
19
|
+
*/
|
|
20
|
+
import { type LineEnding } from "./edit-diff.js";
|
|
21
|
+
import type { FileIO } from "./fs-bridge.js";
|
|
22
|
+
import type { ServedRow } from "./hashline/served.js";
|
|
23
|
+
import type { HashStore } from "./hash-store.js";
|
|
24
|
+
export declare const MAX_HASH_LINES: number;
|
|
25
|
+
export declare const DEFAULT_MAX_LINES = 2000;
|
|
26
|
+
export declare const DEFAULT_MAX_BYTES: number;
|
|
27
|
+
export interface TruncationResult {
|
|
28
|
+
content: string;
|
|
29
|
+
truncated: boolean;
|
|
30
|
+
truncatedBy: 'lines' | 'bytes' | null;
|
|
31
|
+
totalLines: number;
|
|
32
|
+
totalBytes: number;
|
|
33
|
+
outputLines: number;
|
|
34
|
+
outputBytes: number;
|
|
35
|
+
lastLinePartial: boolean;
|
|
36
|
+
firstLineExceedsLimit: boolean;
|
|
37
|
+
maxLines: number;
|
|
38
|
+
maxBytes: number;
|
|
39
|
+
}
|
|
40
|
+
export declare function formatSize(bytes: number): string;
|
|
41
|
+
export declare function truncateHead(content: string, options?: {
|
|
42
|
+
maxLines?: number;
|
|
43
|
+
maxBytes?: number;
|
|
44
|
+
}): TruncationResult;
|
|
45
|
+
export type LFile = {
|
|
46
|
+
kind: "directory";
|
|
47
|
+
} | {
|
|
48
|
+
kind: "image";
|
|
49
|
+
mimeType: string;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "text";
|
|
52
|
+
text: string;
|
|
53
|
+
hadUtf8DecodeErrors?: true;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "binary";
|
|
56
|
+
description: string;
|
|
57
|
+
};
|
|
58
|
+
export interface LoadFileOptions {
|
|
59
|
+
maxLines?: number;
|
|
60
|
+
displayPath?: string;
|
|
61
|
+
}
|
|
62
|
+
export declare function loadFileKindAndText(filePath: string, options?: LoadFileOptions): Promise<LFile>;
|
|
63
|
+
export declare function valAccess(absolutePath: string, path: string, accessMode?: number): Promise<void>;
|
|
64
|
+
export declare function valKind(file: LFile, path: string): asserts file is {
|
|
65
|
+
kind: "text";
|
|
66
|
+
text: string;
|
|
67
|
+
hadUtf8DecodeErrors?: true;
|
|
68
|
+
};
|
|
69
|
+
export interface NormFile {
|
|
70
|
+
absolutePath: string;
|
|
71
|
+
normalized: string;
|
|
72
|
+
bom: string;
|
|
73
|
+
originalEnding: LineEnding;
|
|
74
|
+
fileHashes: string[];
|
|
75
|
+
hadUtf8DecodeErrors: boolean;
|
|
76
|
+
}
|
|
77
|
+
export type SnapInfo = {
|
|
78
|
+
snapshotId: string;
|
|
79
|
+
ino: number;
|
|
80
|
+
mtimeMs: number;
|
|
81
|
+
ctimeMs: number;
|
|
82
|
+
size: number;
|
|
83
|
+
};
|
|
84
|
+
export declare function fileSnap(absolutePath: string): Promise<SnapInfo>;
|
|
85
|
+
export interface ReadNormOptions {
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
accessMode?: number;
|
|
88
|
+
preloadedFile?: LFile;
|
|
89
|
+
maxLines?: number;
|
|
90
|
+
store?: HashStore;
|
|
91
|
+
noPersist?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export declare function normFromText(input: {
|
|
94
|
+
absolutePath: string;
|
|
95
|
+
rawText: string;
|
|
96
|
+
displayPath: string;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
maxLines?: number;
|
|
99
|
+
store?: HashStore;
|
|
100
|
+
noPersist?: boolean;
|
|
101
|
+
hadUtf8DecodeErrors?: boolean;
|
|
102
|
+
}): Promise<NormFile>;
|
|
103
|
+
export declare function readNormFile(path: string, cwd: string, options?: ReadNormOptions): Promise<NormFile>;
|
|
104
|
+
export declare function formatPaginationHint(startLine: number, endLine: number, totalLines: number, nextOffset: number, byteLimit?: number): string;
|
|
105
|
+
export declare function fmtReadPreview(text: string, options: {
|
|
106
|
+
offset?: number;
|
|
107
|
+
limit?: number;
|
|
108
|
+
}, precomputedHashes?: string[], path?: string, maxLineBytes?: number, maxTruncLines?: number): Promise<{
|
|
109
|
+
text: string;
|
|
110
|
+
truncation?: TruncationResult;
|
|
111
|
+
nextOffset?: number;
|
|
112
|
+
served: ServedRow[];
|
|
113
|
+
}>;
|
|
114
|
+
export interface FileView {
|
|
115
|
+
text: string;
|
|
116
|
+
hashes: string[];
|
|
117
|
+
served: ServedRow[];
|
|
118
|
+
absolutePath: string;
|
|
119
|
+
truncation?: TruncationResult;
|
|
120
|
+
nextOffset?: number;
|
|
121
|
+
hadUtf8DecodeErrors: boolean;
|
|
122
|
+
bom: string;
|
|
123
|
+
originalEnding: LineEnding;
|
|
124
|
+
normalized: string;
|
|
125
|
+
}
|
|
126
|
+
export interface PreviewOpts {
|
|
127
|
+
offset?: number;
|
|
128
|
+
limit?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface ReadViewOpts extends PreviewOpts {
|
|
131
|
+
signal?: AbortSignal;
|
|
132
|
+
}
|
|
133
|
+
export declare function preview(content: string, hashes: string[], opts?: PreviewOpts, absolutePath?: string): Promise<{
|
|
134
|
+
text: string;
|
|
135
|
+
served: ServedRow[];
|
|
136
|
+
truncation?: TruncationResult;
|
|
137
|
+
nextOffset?: number;
|
|
138
|
+
}>;
|
|
139
|
+
export declare function readView(io: FileIO, path: string, cwd: string, opts?: ReadViewOpts): Promise<FileView>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for guidance sub-seams — parse (pure), resolve (IO-light), materialize (IO-heavy).
|
|
3
|
+
* Re-exported via `src/guidance.ts` so existing `from "./guidance.js"` imports keep working.
|
|
4
|
+
* @module dsh-better-edit/guidance/index
|
|
5
|
+
*/
|
|
6
|
+
export * from "./parse.js";
|
|
7
|
+
export * from "./resolve.js";
|
|
8
|
+
export * from "./materialize.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The presets shipped by the harness, each seeded with editable guidance. */
|
|
2
|
+
export declare const DEFAULT_PRESETS: readonly string[];
|
|
3
|
+
/**
|
|
4
|
+
* The root README: the per-preset customization convention users see in the
|
|
5
|
+
* plugin home.
|
|
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- `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
|
+
/**
|
|
10
|
+
* Materialize per-preset guidance directories in the plugin home.
|
|
11
|
+
*
|
|
12
|
+
* For each of `DEFAULT_PRESETS` creates `<preset>/{read,edit,
|
|
13
|
+
* undo_last_edit}.md` rendered from the compiled defaults (with order
|
|
14
|
+
* front-matter), plus a root `README.md` documenting the convention.
|
|
15
|
+
* Idempotent: a user-edited file survives repeated calls. A blank override file
|
|
16
|
+
* (whitespace-only body, no fence) is re-seeded with the current compiled
|
|
17
|
+
* default; malformed, non-blank, and deliberate-blank (valid-fence) files are
|
|
18
|
+
* never touched. Custom preset directories present on disk are scanned the same
|
|
19
|
+
* way but never fabricated. Missing directories are created on demand (shipped
|
|
20
|
+
* presets only), and shipped files are written exclusively so two concurrent
|
|
21
|
+
* first runs race safely.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ensurePresetGuidance(homeDir: string): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parser for per-preset guidance override files.
|
|
3
|
+
*
|
|
4
|
+
* Only a leading `---` fence whose lines are empty or `order: <integer>` is
|
|
5
|
+
* accepted. This module has zero IO — exhaustive unit testing without a temp
|
|
6
|
+
* home.
|
|
7
|
+
* @module dsh-better-edit/guidance/parse
|
|
8
|
+
*/
|
|
9
|
+
/** The parsed content of one override file. */
|
|
10
|
+
export interface ParsedSection {
|
|
11
|
+
/** Front-matter `order`, when present and valid. */
|
|
12
|
+
order?: number;
|
|
13
|
+
/** The section text: the file body, or the whole file when no fence is present. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** True when a leading `---` fence is present but does not parse (fast fail). */
|
|
16
|
+
malformed?: boolean;
|
|
17
|
+
/** Human-readable parse reason, present only when `malformed` is true. */
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse an override file. Only a leading `---` fence whose lines are empty or
|
|
22
|
+
* `order: <integer>` is accepted. A leading `---` that does not parse (no
|
|
23
|
+
* closing fence, unknown key, non-integer value) is a malformed override;
|
|
24
|
+
* anything else is pure prose (the whole file as text).
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseSectionFile(content: string): ParsedSection;
|
|
27
|
+
/**
|
|
28
|
+
* True when an override file is blank: whitespace-only body and NO front-matter
|
|
29
|
+
* fence (the "I want the default" case). The single source of truth for whether
|
|
30
|
+
* a boot-time materialization pass should re-seed a file. False for prose with
|
|
31
|
+
* content, for any valid fence (including a keyless/empty one — a deliberate
|
|
32
|
+
* blank), and for malformed files.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isBlankOverride(content: string): boolean;
|
|
35
|
+
/** True when an override file opens with a leading `---` fence that is malformed. */
|
|
36
|
+
export declare function isMalformedOverride(content: string): boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** One overridable tool section. */
|
|
2
|
+
export interface GuidanceSection {
|
|
3
|
+
/** Registry section name, e.g. `tool:edit`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Override file name inside a preset directory, e.g. `edit.md`. */
|
|
6
|
+
file: string;
|
|
7
|
+
/** Order used when the override file carries no front-matter `order`. */
|
|
8
|
+
defaultOrder: number;
|
|
9
|
+
/** The compiled default text, byte-identical to today's inline rendering. */
|
|
10
|
+
renderDefault(): string;
|
|
11
|
+
}
|
|
12
|
+
/** The three sections, in default-order sequence. */
|
|
13
|
+
export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
|
|
14
|
+
/** Render the compiled default text for one section. */
|
|
15
|
+
export declare function renderSectionDefault(name: string): string;
|
|
16
|
+
/** Options for resolving one section's guidance. */
|
|
17
|
+
export interface ResolveGuidanceOptions {
|
|
18
|
+
/** Agent preset id, or undefined to skip the preset layer. */
|
|
19
|
+
presetId?: string;
|
|
20
|
+
/** Plugin shared home directory (`$DSH_HOME/plugins/dsh-better-edit`). */
|
|
21
|
+
homeDir: string;
|
|
22
|
+
}
|
|
23
|
+
/** The resolved text and order for one section. */
|
|
24
|
+
export interface GuidanceResolution {
|
|
25
|
+
order: number;
|
|
26
|
+
text: string;
|
|
27
|
+
/** Set when the override file was malformed and the compiled default was used. */
|
|
28
|
+
malformed?: {
|
|
29
|
+
file: string;
|
|
30
|
+
reason: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve one section's guidance: the first override file that exists wins,
|
|
35
|
+
* falling back to the compiled default. A missing or blank file (ENOENT, or
|
|
36
|
+
* whitespace-only with no fence) advances the chain; a malformed file resolves
|
|
37
|
+
* to the compiled default and reports itself; any other read error propagates.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveSection(name: string, options: ResolveGuidanceOptions): Promise<GuidanceResolution>;
|
|
40
|
+
/** The resolved configuration of one section, ready for the systemPrompt registry. */
|
|
41
|
+
export interface SectionOverride {
|
|
42
|
+
name: string;
|
|
43
|
+
order: number;
|
|
44
|
+
text: string;
|
|
45
|
+
/** Set when the override file was malformed and the compiled default was used. */
|
|
46
|
+
malformed?: {
|
|
47
|
+
file: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve all three sections for a preset. `presetId === undefined` skips the
|
|
53
|
+
* `<preset>/` layer and resolves straight to the compiled defaults.
|
|
54
|
+
*/
|
|
55
|
+
export declare function composeSections(presetId: string | undefined, homeDir: string): Promise<SectionOverride[]>;
|
package/lib/types/guidance.d.ts
CHANGED
|
@@ -1,130 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* compiled default rendered from `prompts.ts` (byte-identical to the inline
|
|
6
|
-
* rendering `src/index.ts` uses today). A user can override any section's text
|
|
7
|
-
* and `order` with a plain markdown file keyed by agent preset: the override
|
|
8
|
-
* files live in the plugin's shared home (`$DSH_HOME/plugins/dsh-better-edit`,
|
|
9
|
-
* never the workspace store) and are resolved per section as
|
|
10
|
-
* `<preset>/<section>.md` → compiled default.
|
|
11
|
-
*
|
|
12
|
-
* fence carrying only an `order` key (`---` / `order: N` / `---`). Any
|
|
13
|
-
* well-formed fence — even keyless, even an empty body — is deliberate content
|
|
14
|
-
* and wins. A leading `---` that does not parse (a missing closing fence, a
|
|
15
|
-
* non-integer `order`, an unknown key) is a MALFORMED override and must never
|
|
16
|
-
* reach the model: resolution falls back to the compiled default and reports
|
|
17
|
-
* the file and parse reason. An absent or blank override (whitespace-only body,
|
|
18
|
-
* no fence) means "use the default" and is re-seeded at boot.
|
|
19
|
-
*
|
|
20
|
-
* Resolution is pure: no cordis services, no harness wiring. The installer
|
|
21
|
-
* ticket reads the resolved sections once per agent at session-start;
|
|
22
|
-
* nothing here watches or caches files.
|
|
2
|
+
* Backwards-compat barrel — the real seams live in `src/guidance/`:
|
|
3
|
+
* `parse.ts` (pure), `resolve.ts` (IO-light), `materialize.ts` (IO-heavy).
|
|
4
|
+
* Keeping this file means existing `from "./guidance.js"` imports keep working.
|
|
23
5
|
* @module dsh-better-edit/guidance
|
|
24
6
|
*/
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
export interface GuidanceSection {
|
|
29
|
-
/** Registry section name, e.g. `tool:edit`. */
|
|
30
|
-
name: string;
|
|
31
|
-
/** Override file name inside a preset directory, e.g. `edit.md`. */
|
|
32
|
-
file: string;
|
|
33
|
-
/** Order used when the override file carries no front-matter `order`. */
|
|
34
|
-
defaultOrder: number;
|
|
35
|
-
/** The compiled default text, byte-identical to today's inline rendering. */
|
|
36
|
-
renderDefault(): string;
|
|
37
|
-
}
|
|
38
|
-
/** The four sections, in default-order sequence. */
|
|
39
|
-
export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
|
|
40
|
-
/** Render the compiled default text for one section. */
|
|
41
|
-
export declare function renderSectionDefault(name: string): string;
|
|
42
|
-
/** The parsed content of one override file. */
|
|
43
|
-
export interface ParsedSection {
|
|
44
|
-
/** Front-matter `order`, when present and valid. */
|
|
45
|
-
order?: number;
|
|
46
|
-
/** The section text: the file body, or the whole file when no fence is present. */
|
|
47
|
-
text: string;
|
|
48
|
-
/** True when a leading `---` fence is present but does not parse (fast fail). */
|
|
49
|
-
malformed?: boolean;
|
|
50
|
-
/** Human-readable parse reason, present only when `malformed` is true. */
|
|
51
|
-
reason?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Parse an override file. Only a leading `---` fence whose lines are empty or
|
|
55
|
-
* `order: <integer>` is accepted. A leading `---` that does not parse (no
|
|
56
|
-
* closing fence, unknown key, non-integer value) is a malformed override;
|
|
57
|
-
* anything else is pure prose (the whole file as text).
|
|
58
|
-
*/
|
|
59
|
-
export declare function parseSectionFile(content: string): ParsedSection;
|
|
60
|
-
/**
|
|
61
|
-
* True when an override file is blank: whitespace-only body and NO front-matter
|
|
62
|
-
* fence (the "I want the default" case). The single source of truth for whether
|
|
63
|
-
* a boot-time materialization pass should re-seed a file. False for prose with
|
|
64
|
-
* content, for any valid fence (including a keyless/empty one — a deliberate
|
|
65
|
-
* blank), and for malformed files.
|
|
66
|
-
*/
|
|
67
|
-
export declare function isBlankOverride(content: string): boolean;
|
|
68
|
-
/** True when an override file opens with a leading `---` fence that is malformed. */
|
|
69
|
-
export declare function isMalformedOverride(content: string): boolean;
|
|
70
|
-
/** Options for resolving one section's guidance. */
|
|
71
|
-
export interface ResolveGuidanceOptions {
|
|
72
|
-
/** Agent preset id, or undefined to skip the preset layer. */
|
|
73
|
-
presetId?: string;
|
|
74
|
-
/** Plugin shared home directory (`$DSH_HOME/plugins/dsh-better-edit`). */
|
|
75
|
-
homeDir: string;
|
|
76
|
-
}
|
|
77
|
-
/** The resolved text and order for one section. */
|
|
78
|
-
export interface GuidanceResolution {
|
|
79
|
-
order: number;
|
|
80
|
-
text: string;
|
|
81
|
-
/** Set when the override file was malformed and the compiled default was used. */
|
|
82
|
-
malformed?: {
|
|
83
|
-
file: string;
|
|
84
|
-
reason: string;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Resolve one section's guidance: the first override file that exists wins,
|
|
89
|
-
* falling back to the compiled default. A missing or blank file (ENOENT, or
|
|
90
|
-
* whitespace-only with no fence) advances the chain; a malformed file resolves
|
|
91
|
-
* to the compiled default and reports itself; any other read error propagates.
|
|
92
|
-
*/
|
|
93
|
-
export declare function resolveSection(name: string, options: ResolveGuidanceOptions): Promise<GuidanceResolution>;
|
|
94
|
-
/** The resolved configuration of one section, ready for the systemPrompt registry. */
|
|
95
|
-
export interface SectionOverride {
|
|
96
|
-
name: string;
|
|
97
|
-
order: number;
|
|
98
|
-
text: string;
|
|
99
|
-
/** Set when the override file was malformed and the compiled default was used. */
|
|
100
|
-
malformed?: {
|
|
101
|
-
file: string;
|
|
102
|
-
reason: string;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Resolve all four sections for a preset. `presetId === undefined` skips the
|
|
107
|
-
* `<preset>/` layer and resolves straight to the compiled defaults.
|
|
108
|
-
*/
|
|
109
|
-
export declare function composeSections(presetId: string | undefined, homeDir: string): Promise<SectionOverride[]>;
|
|
110
|
-
/**
|
|
111
|
-
* The root README: the per-preset customization convention users see in the
|
|
112
|
-
* plugin home.
|
|
113
|
-
*/
|
|
114
|
-
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";
|
|
115
|
-
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";
|
|
116
|
-
/**
|
|
117
|
-
* Materialize per-preset guidance directories in the plugin home.
|
|
118
|
-
*
|
|
119
|
-
* For each of \`DEFAULT_PRESETS\` creates \`<preset>/{read,edit,batch_edit,
|
|
120
|
-
* undo_last_edit}.md\` rendered from the compiled defaults (with order
|
|
121
|
-
* front-matter), plus a root \`README.md\` documenting the convention.
|
|
122
|
-
* Idempotent: a user-edited file survives repeated calls. A blank override file
|
|
123
|
-
* (whitespace-only body, no fence) is re-seeded with the current compiled
|
|
124
|
-
* default; malformed, non-blank, and deliberate-blank (valid-fence) files are
|
|
125
|
-
* never touched. Custom preset directories present on disk are scanned the same
|
|
126
|
-
* way but never fabricated. Missing directories are created on demand (shipped
|
|
127
|
-
* presets only), and shipped files are written exclusively so two concurrent
|
|
128
|
-
* first runs race safely.
|
|
129
|
-
*/
|
|
130
|
-
export declare function ensurePresetGuidance(homeDir: string): Promise<void>;
|
|
7
|
+
export * from "./guidance/parse.js";
|
|
8
|
+
export * from "./guidance/resolve.js";
|
|
9
|
+
export * from "./guidance/materialize.js";
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export
|
|
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";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnchorPipeline — deep module owning the anchor autofix chain.
|
|
3
|
+
*
|
|
4
|
+
* Single ordering invariant (private):
|
|
5
|
+
* swapReversed → stripBare → stripDiff → valEdit → boundaryDups splice → valEdit → verifyServed → resToSpan
|
|
6
|
+
*
|
|
7
|
+
* Detection (valEdit → boundaryDups[]) and correction (splice + second valEdit)
|
|
8
|
+
* were split across resolve.ts / apply.ts with an implicit coupling.
|
|
9
|
+
* This seam co-locates that invariant. Public surface is two functions:
|
|
10
|
+
* resEdit — pre-validation (tool-layer, no file state)
|
|
11
|
+
* applyEdit — full pipeline (file + hashes + served verification)
|
|
12
|
+
*
|
|
13
|
+
* Private to this seam (not re-exported): stripBarePrefixes, stripDiffPrefixes,
|
|
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.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-better-edit/hashline/anchor-pipeline
|
|
20
|
+
*/
|
|
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
|
-
|
|
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";
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
},
|
|
13
|
+
}, ioOrStore?: HashStore | HashSnapshotIO, persist?: boolean): Promise<string[]>;
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
export
|
|
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,5 +1,13 @@
|
|
|
1
|
-
|
|
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";
|
|
2
7
|
export { lineHashes } from "./hash.js";
|
|
3
|
-
export { parseHashRef, parseText
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
8
|
+
export { parseHashRef, parseText } from "./parse.js";
|
|
9
|
+
export type { Anchor } from "./parse.js";
|
|
10
|
+
export { resEdit } from "./anchor-pipeline.js";
|
|
11
|
+
export type { HEdit, HTEdit, NEdit, BDup, AutoFix } from "./anchor-pipeline.js";
|
|
12
|
+
export { applyEdit, fmtRegion, changedRange, buildIdx, ServedRejectionError, AnchorMismatchError, isServedRejection, isAnchorMismatch, verifyServedRange, buildRangeEcho, fmtServedRows, } from "./anchor-pipeline.js";
|
|
13
|
+
export type { ServedRow, ResolvedRange, ServedCode, } from "./anchor-pipeline.js";
|