dsh-better-edit 0.1.9 → 0.2.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 (58) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +168 -52
  3. package/README.zh.md +122 -46
  4. package/assets/logo.svg +183 -18
  5. package/lib/contract.js +95 -0
  6. package/lib/drift.js +1 -1
  7. package/lib/edit-diff.js +2 -2
  8. package/lib/edit-engine.js +456 -0
  9. package/lib/edit-pipeline.js +41 -116
  10. package/lib/file-reader.js +1 -2
  11. package/lib/fs-bridge.js +2 -2
  12. package/lib/fs-write.js +3 -46
  13. package/lib/guidance.js +282 -0
  14. package/lib/hash-store.js +246 -13
  15. package/lib/hashline/apply.js +2 -2
  16. package/lib/hashline/hash.js +16 -206
  17. package/lib/hashline/index.js +4 -3
  18. package/lib/hashline/parse.js +1 -1
  19. package/lib/hashline/pure.js +213 -0
  20. package/lib/hashline/resolve.js +1 -5
  21. package/lib/hashline/served.js +2 -2
  22. package/lib/index.js +48 -32
  23. package/lib/paths.js +55 -1
  24. package/lib/prompts.js +53 -49
  25. package/lib/read-and-serve.js +46 -0
  26. package/lib/schema.js +1 -1
  27. package/lib/served-store.js +144 -183
  28. package/lib/tool-batch-edit.js +28 -280
  29. package/lib/tool-edit.js +37 -32
  30. package/lib/tool-read.js +8 -31
  31. package/lib/tool-undo.js +4 -13
  32. package/lib/types/contract.d.ts +39 -0
  33. package/lib/types/edit-engine.d.ts +179 -0
  34. package/lib/types/edit-pipeline.d.ts +10 -17
  35. package/lib/types/fs-write.d.ts +0 -1
  36. package/lib/types/guidance.d.ts +98 -0
  37. package/lib/types/hash-store.d.ts +73 -25
  38. package/lib/types/hashline/hash.d.ts +8 -13
  39. package/lib/types/hashline/index.d.ts +4 -3
  40. package/lib/types/hashline/pure.d.ts +26 -0
  41. package/lib/types/hashline/resolve.d.ts +0 -1
  42. package/lib/types/index.d.ts +4 -0
  43. package/lib/types/paths.d.ts +9 -0
  44. package/lib/types/prompts.d.ts +19 -9
  45. package/lib/types/read-and-serve.d.ts +39 -0
  46. package/lib/types/schema.d.ts +2 -16
  47. package/lib/types/served-store.d.ts +63 -32
  48. package/lib/types/tool-batch-edit.d.ts +4 -1
  49. package/lib/types/tool-undo.d.ts +1 -1
  50. package/lib/undo-edit.js +16 -1
  51. package/lib/write-hook.js +30 -50
  52. package/package.json +5 -3
  53. package/lib/served-state.js +0 -34
  54. package/lib/snapshot-store.js +0 -108
  55. package/lib/types/served-state.d.ts +0 -3
  56. package/lib/types/snapshot-store.d.ts +0 -14
  57. package/lib/types/undo-store.d.ts +0 -14
  58. package/lib/undo-store.js +0 -43
@@ -1,4 +1,19 @@
1
- import { type HashStore } from "./hash-store.js";
1
+ /**
2
+ * Served state — what the model has been shown, per session and path.
3
+ *
4
+ * This is the ONE module that owns the served-state concept: the served-row
5
+ * merge invariant, the reported-drift set, and the position-reconstruction
6
+ * math used by drift notices. Persistence goes through the hash store's
7
+ * served domain API (`hash-store.ts`); the reject-and-serve errors and range
8
+ * verification live with the hashline module (`hashline/served.ts`); drift
9
+ * computation lives in `drift.ts`. Both import from here.
10
+ *
11
+ * The API is async-only: every operation loads the per-workspace hash store
12
+ * and resolves it through the active workspace context. There is deliberately
13
+ * no sync half — the two-vocabulary, every-op-twice surface it produced is
14
+ * gone.
15
+ * @module dsh-better-edit/served-store
16
+ */
2
17
  export type ServedEntry = {
3
18
  position: number;
4
19
  hash: string | null;
@@ -9,45 +24,61 @@ export type ServedEntry = {
9
24
  * process-local fallback so hashline verification never fabricates a session.
10
25
  */
11
26
  export declare function sessionKeyFor(sessionId?: string): string;
12
- export declare function getServed(store: HashStore, sessionKey: string, path: string): (string | null)[];
13
- export declare function upsertServed(store: HashStore, sessionKey: string, path: string, entries: Array<{
14
- position: number;
15
- hash: string | null;
16
- }>): void;
17
- export declare function recordServes(store: HashStore, sessionKey: string, path: string, rows: Array<{
18
- position: number;
19
- hash: string | null;
20
- }>, lineCount?: number): void;
21
27
  /**
22
- * Record post-mutation diff serves against the file's CURRENT length. Before
23
- * upserting the diff rows, positions beyond `lineCount` are dropped from the
24
- * stored array: after an edit/undo the file has a new shape, and a hash that
25
- * survived into the diff must not keep its pre-edit position claim — that
26
- * stale claim is what makes a chained edit's boundary anchor look ambiguous
27
- * (`E_RANGE_UNVERIFIED`) instead of verifying cleanly.
28
- * @param store - open hash store.
29
- * @param sessionKey - the session whose served rows are being updated.
30
- * @param path - canonical absolute path.
31
- * @param rows - diff rows (position → post-mutation hash) to record.
32
- * @param lineCount - the file's line count AFTER the mutation.
28
+ * Merge served rows into a copy of the stored array. This single helper owns
29
+ * the served-merge invariant shared by {@link recordServed} and
30
+ * {@link recordServedTruncated}:
31
+ *
32
+ * - positions are validated before anything is written (invalid rows throw
33
+ * and never reach the store);
34
+ * - when `truncateTo` is given, positions beyond the file's line count are
35
+ * dropped FIRST — a serve of the current file state must never leave a hash
36
+ * at an old position beyond the line count, because that stale claim makes
37
+ * a chained edit's boundary anchor look ambiguous (`E_RANGE_UNVERIFIED`,
38
+ * "served at N positions") instead of verifying cleanly;
39
+ * - when `clearFrom` is given, positions at/after the mutation's first
40
+ * changed line are re-shaped by the edit, so the model's previous view of
41
+ * them is cleared before the diff rows land;
42
+ * - trailing never-served markers are trimmed so an empty tail never grows
43
+ * the stored array.
44
+ *
45
+ * Underscore-prefixed: internal, exported only so the invariant has a direct
46
+ * test seam.
33
47
  */
34
- export declare function recordServesTruncated(store: HashStore, sessionKey: string, path: string, rows: Array<{
35
- position: number;
36
- hash: string | null;
37
- }>, lineCount: number, clearFrom?: number): void;
38
- export declare function getReported(store: HashStore, sessionKey: string, path: string): Set<string>;
39
- export declare function addReported(store: HashStore, sessionKey: string, path: string, hashes: string[]): void;
40
- export declare function clearReported(store: HashStore, sessionKey: string, path: string): void;
41
- export declare function deleteServed(store: HashStore, sessionKey: string, path: string): void;
42
- export declare function wipeServed(store: HashStore, sessionKey: string): void;
48
+ export declare function _mergeServedRows(current: (string | null)[], rows: ServedEntry[], options?: {
49
+ truncateTo?: number;
50
+ clearFrom?: number;
51
+ }): (string | null)[];
52
+ /** The served array for one session+path, or `[]` when nothing was served. */
43
53
  export declare function loadServed(sessionKey: string, path: string): Promise<(string | null)[]>;
54
+ /**
55
+ * Record served rows for one session+path. Without `lineCount` the rows merge
56
+ * into the stored array as-is; with it, the stored array is truncated to the
57
+ * file's current line count before the rows land (see
58
+ * {@link _mergeServedRows} for why). Failures are logged, never thrown — a
59
+ * store problem must not fail the read that produced these rows.
60
+ */
44
61
  export declare function recordServed(sessionKey: string, path: string, rows: ServedEntry[], lineCount?: number): Promise<void>;
45
62
  /**
46
- * Async sibling of {@link recordServesTruncated}: record post-mutation diff
47
- * rows against the file's current line count.
63
+ * Record post-mutation diff serves against the file's CURRENT length. The
64
+ * stored array is truncated to `lineCount` and cleared from `clearFrom`
65
+ * (the edit's first changed line) before the diff rows land, so a hash that
66
+ * survived into the diff never keeps its pre-edit position claim.
48
67
  */
49
68
  export declare function recordServedTruncated(sessionKey: string, path: string, rows: ServedEntry[], lineCount: number, clearFrom?: number): Promise<void>;
69
+ /** The hashes already reported as drifted for one session+path. */
50
70
  export declare function driftReported(sessionKey: string, path: string): Promise<Set<string>>;
71
+ /** Mark hashes as already reported as drifted, so later notices skip them. */
51
72
  export declare function markDriftReported(sessionKey: string, path: string, hashes: string[]): Promise<void>;
73
+ /** Clear the reported-drift set for one session+path (a fresh read resets it). */
52
74
  export declare function clearDriftReported(sessionKey: string, path: string): Promise<void>;
75
+ /** Drop every served row and reported-drift mark for one session. */
53
76
  export declare function wipeServedState(sessionKey: string): Promise<void>;
77
+ /** Every served position of a hash in a served array (the E_RANGE_UNVERIFIED probe). */
78
+ export declare function servedPositionsOf(served: (string | null)[], hash: string): number[];
79
+ /**
80
+ * Reconstruct where a drifted hash sits in the current file: map through the
81
+ * nearest surviving served neighbor (below, else above), else fall back to
82
+ * the served index plus the range's line delta.
83
+ */
84
+ export declare function currentPositionOfDrifted(served: (string | null)[], currentPositions: Map<string, number>, surviving: Set<string>, servedIndex: number, delta: number): number;
@@ -2,7 +2,9 @@
2
2
  * The dsh `batch_edit` tool: several hash-anchored edits in one all-or-nothing
3
3
  * call. Items targeting the same file are applied in order against the served
4
4
  * state; any failing item rejects the whole batch with nothing written, and
5
- * the failing item's current range is echoed as fresh serves.
5
+ * the failing item's current range is echoed as fresh serves. The per-file
6
+ * sequencing and the persist-undo → write → restore transaction live in the
7
+ * edit engine; this module owns request preparation and result rendering.
6
8
  * @module dsh-better-edit/tool-batch-edit
7
9
  */
8
10
  import type { Context } from "@deepseek-ai/cordis";
@@ -13,6 +15,7 @@ import type { FsSandboxController } from "./sandbox.js";
13
15
  * @param _rootCtx - host context.
14
16
  * @param agentCtx - the agent's scoped context (own scope layer).
15
17
  * @param io - the filesystem bridge.
18
+ * @param sandbox - the sandbox-escalation controller.
16
19
  * @returns the exact disposer that unregisters the tool.
17
20
  */
18
21
  export declare function buildBatchEditTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { Context } from "@deepseek-ai/cordis";
8
8
  import type { FileIO } from "./fs-bridge.js";
9
- import { FsSandboxController } from "./sandbox.js";
9
+ import type { FsSandboxController } from "./sandbox.js";
10
10
  /**
11
11
  * Register the `undo_last_edit` tool on the calling agent's scope.
12
12
  * @param _rootCtx - host context.
package/lib/undo-edit.js CHANGED
@@ -7,7 +7,22 @@
7
7
  * overwritten. Undo survives restarts (the store is on disk).
8
8
  * @module dsh-better-edit/undo-edit
9
9
  */
10
- import { readUndo, writeUndo, removeUndo } from './undo-store.js';
10
+ import { loadHashStore } from './hash-store.js';
11
+ /** Load the last undo row for a path from the active store, if any. */
12
+ async function readUndo(path) {
13
+ const store = await loadHashStore();
14
+ return store.getUndo(path);
15
+ }
16
+ /** Persist the undo row for a path to the active store. */
17
+ async function writeUndo(path, entry) {
18
+ const store = await loadHashStore();
19
+ store.upsertUndo(path, entry);
20
+ }
21
+ /** Drop the undo row for a path from the active store. */
22
+ async function removeUndo(path) {
23
+ const store = await loadHashStore();
24
+ store.deleteUndo(path);
25
+ }
11
26
  /**
12
27
  * Persist an undo entry for one path before mutating it.
13
28
  * @param path - canonical absolute path.
package/lib/write-hook.js CHANGED
@@ -5,9 +5,7 @@
5
5
  * anchors without an explicit read call (mirroring pi-hashline-edit-lsz).
6
6
  * @module dsh-better-edit/write-hook
7
7
  */
8
- import { normFromText } from './file-reader.js';
9
- import { fmtReadPreview, MAX_HASH_LINES } from './read-render.js';
10
- import { recordServed, clearDriftReported } from './served-store.js';
8
+ import { readAndServe } from './read-and-serve.js';
11
9
  import { execCwd, execSessionKey } from './dsh-context.js';
12
10
  import { withWorkspace } from './workspace.js';
13
11
  const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
@@ -25,53 +23,35 @@ const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
25
23
  export function registerWriteHook(rootCtx, agentCtx, io) {
26
24
  return agentCtx.on('tools/post-execute', async (exec, result, next) => {
27
25
  return withWorkspace(execCwd(exec), async () => {
28
- return withWorkspace(execCwd(exec), async () => {
29
- const decision = await next();
30
- if (exec.name !== 'write' ||
31
- result.isError ||
32
- decision.kind !== 'accept') {
33
- return decision;
34
- }
35
- const decisionContent = decision.content ?? result.content;
36
- const rawPath = exec.arguments
37
- ?.file_path ?? exec.arguments
38
- ?.path;
39
- if (typeof rawPath !== 'string')
40
- return decision;
41
- try {
42
- const cwd = execCwd(exec);
43
- const sessionKey = execSessionKey(exec);
44
- const signal = exec.signal;
45
- const absolutePath = await io.resolve(rawPath, cwd, signal);
46
- const rawText = await io.readText(absolutePath, signal);
47
- const { normalized, fileHashes, hadUtf8DecodeErrors } = await normFromText({
48
- absolutePath,
49
- rawText,
50
- displayPath: rawPath,
51
- signal,
52
- maxLines: MAX_HASH_LINES,
53
- });
54
- const preview = await fmtReadPreview(normalized, {}, fileHashes, absolutePath);
55
- if (preview.served.length > 0) {
56
- await recordServed(sessionKey, absolutePath, preview.served, fileHashes.length);
57
- }
58
- await clearDriftReported(sessionKey, absolutePath);
59
- const text = hadUtf8DecodeErrors
60
- ? `${preview.text}\n\n[Non-UTF-8 bytes shown as U+FFFD; editing rewrites the file as UTF-8.]`
61
- : preview.text;
62
- return {
63
- kind: 'accept',
64
- content: [
65
- ...(decisionContent),
66
- { type: 'text', text: `\n\n${AUTO_READ_HEADING}\n${text}` },
67
- ],
68
- };
69
- }
70
- catch (error) {
71
- rootCtx.logger.warn(`dsh-better-edit: auto-read after write failed: ${error instanceof Error ? error.message : String(error)}`);
72
- return decision;
73
- }
74
- });
26
+ const decision = await next();
27
+ if (exec.name !== 'write' ||
28
+ result.isError ||
29
+ decision.kind !== 'accept') {
30
+ return decision;
31
+ }
32
+ const decisionContent = decision.content ?? result.content;
33
+ const rawPath = exec.arguments
34
+ ?.file_path ?? exec.arguments
35
+ ?.path;
36
+ if (typeof rawPath !== 'string')
37
+ return decision;
38
+ try {
39
+ const cwd = execCwd(exec);
40
+ const sessionKey = execSessionKey(exec);
41
+ const signal = exec.signal;
42
+ const { text } = await readAndServe(io, rawPath, cwd, { sessionKey, signal });
43
+ return {
44
+ kind: 'accept',
45
+ content: [
46
+ ...(decisionContent),
47
+ { type: 'text', text: `\n\n${AUTO_READ_HEADING}\n${text}` },
48
+ ],
49
+ };
50
+ }
51
+ catch (error) {
52
+ rootCtx.logger.warn(`dsh-better-edit: auto-read after write failed: ${error instanceof Error ? error.message : String(error)}`);
53
+ return decision;
54
+ }
75
55
  });
76
56
  });
77
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/edit/batch_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",
@@ -35,6 +35,7 @@
35
35
  "dsh-plugin",
36
36
  "deepseek-harness",
37
37
  "coding-agent",
38
+ "oh-my-pi",
38
39
  "hashline",
39
40
  "hash-anchored",
40
41
  "hash",
@@ -74,9 +75,10 @@
74
75
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
75
76
  "test": "vitest run",
76
77
  "test:watch": "vitest",
77
- "prepublishOnly": "npm run typecheck && npm test",
78
+ "prepublishOnly": "npm run typecheck && npm test && node scripts/assert-tagged.mjs",
78
79
  "benchmark": "node benchmark/run.mjs",
79
- "postpublish": "node scripts/tag-current.mjs"
80
+ "postpublish": "node scripts/tag-current.mjs",
81
+ "release": "node scripts/release.mjs"
80
82
  },
81
83
  "devDependencies": {
82
84
  "@deepseek-ai/cordis": "^4.0.1",
@@ -1,34 +0,0 @@
1
- export { loadServed, recordServed, driftReported, markDriftReported, clearDriftReported, wipeServedState, sessionKeyFor, } from "./served-store.js";
2
- export function servedPositionsOf(served, hash) {
3
- const out = [];
4
- for (let i = 0; i < served.length; i++) {
5
- if (served[i] === hash)
6
- out.push(i);
7
- }
8
- return out;
9
- }
10
- function nearestSurvivingPosition(served, surviving, from, direction) {
11
- if (direction === "below") {
12
- for (let q = from - 1; q >= 0; q--) {
13
- const hash = served[q];
14
- if (hash !== null && surviving.has(hash))
15
- return q;
16
- }
17
- return undefined;
18
- }
19
- for (let q = from + 1; q < served.length; q++) {
20
- const hash = served[q];
21
- if (hash !== null && surviving.has(hash))
22
- return q;
23
- }
24
- return undefined;
25
- }
26
- export function currentPositionOfDrifted(served, currentPositions, surviving, servedIndex, delta) {
27
- const below = nearestSurvivingPosition(served, surviving, servedIndex, "below");
28
- if (below !== undefined)
29
- return currentPositions.get(served[below]) + 1;
30
- const above = nearestSurvivingPosition(served, surviving, servedIndex, "above");
31
- if (above !== undefined)
32
- return currentPositions.get(served[above]) - 1;
33
- return servedIndex + delta;
34
- }
@@ -1,108 +0,0 @@
1
- import { stat } from "fs/promises";
2
- import { HASH_RE } from "./hashline/alphabet.js";
3
- import { contentChecksum } from "./hashline/hasher.js";
4
- import { splitLines } from "./utils.js";
5
- import { loadHashStore, withStore } from "./hash-store.js";
6
- export function isValidHashList(value) {
7
- if (!Array.isArray(value))
8
- return false;
9
- for (const hash of value) {
10
- if (typeof hash !== "string" || !HASH_RE.test(hash))
11
- return false;
12
- }
13
- return true;
14
- }
15
- export function isValidSnapshot(value) {
16
- if (typeof value !== "object" || value === null)
17
- return false;
18
- const v = value;
19
- if (typeof v.content !== "string")
20
- return false;
21
- return isValidHashList(v.hashes);
22
- }
23
- export function getSnapshot(store, path, content, deleteCorrupt = true) {
24
- const checksum = contentChecksum(content);
25
- const lineCount = splitLines(content).length;
26
- const row = store.stmts.get(path, checksum, lineCount);
27
- if (!row)
28
- return undefined;
29
- try {
30
- const parsed = JSON.parse(row.hashes);
31
- if (isValidHashList(parsed))
32
- return parsed;
33
- if (deleteCorrupt)
34
- store.stmts.deleteOne(path);
35
- return undefined;
36
- }
37
- catch {
38
- if (deleteCorrupt)
39
- store.stmts.deleteOne(path);
40
- return undefined;
41
- }
42
- }
43
- export function upsertSnapshot(store, path, checksum, lineCount, hashes) {
44
- store.stmts.upsert(path, checksum, lineCount, JSON.stringify(hashes), Date.now());
45
- }
46
- export async function findSnapshotPathsByHashes(hashes) {
47
- const store = await loadHashStore();
48
- return findSnapshotPaths(store, hashes);
49
- }
50
- export async function pruneMissingAll() {
51
- const store = await loadHashStore();
52
- await pruneMissing(store);
53
- }
54
- export async function upsertSnapshotFor(path, checksum, lineCount, hashes) {
55
- const store = await loadHashStore();
56
- upsertSnapshot(store, path, checksum, lineCount, hashes);
57
- }
58
- export function findSnapshotPaths(store, hashes) {
59
- const rows = store.stmts.allHashes();
60
- const matches = [];
61
- for (const row of rows) {
62
- try {
63
- const parsed = JSON.parse(row.hashes);
64
- if (!isValidHashList(parsed))
65
- continue;
66
- if (hashes.every((h) => parsed.includes(h)))
67
- matches.push(row.path);
68
- }
69
- catch {
70
- continue;
71
- }
72
- }
73
- return matches;
74
- }
75
- const STAT_BATCH = 64;
76
- async function statMissing(rows) {
77
- const missing = [];
78
- for (let i = 0; i < rows.length; i += STAT_BATCH) {
79
- const batch = rows.slice(i, i + STAT_BATCH);
80
- const results = await Promise.all(batch.map(async (row) => {
81
- try {
82
- await stat(row.path);
83
- return undefined;
84
- }
85
- catch {
86
- return row.path;
87
- }
88
- }));
89
- for (const path of results) {
90
- if (path !== undefined)
91
- missing.push(path);
92
- }
93
- }
94
- return missing;
95
- }
96
- export async function pruneMissing(store) {
97
- const rows = store.stmts.allPaths();
98
- const missing = await statMissing(rows);
99
- if (missing.length === 0)
100
- return;
101
- withStore(() => {
102
- for (const path of missing) {
103
- store.stmts.deleteOne(path);
104
- store.stmts.undoDelete(path);
105
- store.stmts.servedDeletePath(path);
106
- }
107
- });
108
- }
@@ -1,3 +0,0 @@
1
- export { type ServedEntry, loadServed, recordServed, driftReported, markDriftReported, clearDriftReported, wipeServedState, sessionKeyFor, } from "./served-store.js";
2
- export declare function servedPositionsOf(served: (string | null)[], hash: string): number[];
3
- export declare function currentPositionOfDrifted(served: (string | null)[], currentPositions: Map<string, number>, surviving: Set<string>, servedIndex: number, delta: number): number;
@@ -1,14 +0,0 @@
1
- import { type HashStore } from "./hash-store.js";
2
- export interface LegacySnapshot {
3
- content: string;
4
- hashes: string[];
5
- }
6
- export declare function isValidHashList(value: unknown): value is string[];
7
- export declare function isValidSnapshot(value: unknown): value is LegacySnapshot;
8
- export declare function getSnapshot(store: HashStore, path: string, content: string, deleteCorrupt?: boolean): string[] | undefined;
9
- export declare function upsertSnapshot(store: HashStore, path: string, checksum: string, lineCount: number, hashes: string[]): void;
10
- export declare function findSnapshotPathsByHashes(hashes: string[]): Promise<string[]>;
11
- export declare function pruneMissingAll(): Promise<void>;
12
- export declare function upsertSnapshotFor(path: string, checksum: string, lineCount: number, hashes: string[]): Promise<void>;
13
- export declare function findSnapshotPaths(store: HashStore, hashes: string[]): string[];
14
- export declare function pruneMissing(store: HashStore): Promise<void>;
@@ -1,14 +0,0 @@
1
- import { type HashStore } from "./hash-store.js";
2
- export interface UndoRecord {
3
- content: string;
4
- bom: string;
5
- ending: string;
6
- hashes: string[];
7
- resultContent: string;
8
- }
9
- export declare function upsertUndo(store: HashStore, path: string, entry: UndoRecord): void;
10
- export declare function getUndoEntry(store: HashStore, path: string): UndoRecord | undefined;
11
- export declare function deleteUndo(store: HashStore, path: string): void;
12
- export declare function readUndo(path: string): Promise<UndoRecord | undefined>;
13
- export declare function writeUndo(path: string, entry: UndoRecord): Promise<void>;
14
- export declare function removeUndo(path: string): Promise<void>;
package/lib/undo-store.js DELETED
@@ -1,43 +0,0 @@
1
- import { loadHashStore } from "./hash-store.js";
2
- import { isValidHashList } from "./snapshot-store.js";
3
- export function upsertUndo(store, path, entry) {
4
- store.stmts.undoUpsert(path, entry.content, entry.bom, entry.ending, JSON.stringify(entry.hashes), entry.resultContent, Date.now());
5
- }
6
- export function getUndoEntry(store, path) {
7
- const row = store.stmts.undoGet(path);
8
- if (!row)
9
- return undefined;
10
- try {
11
- const parsed = JSON.parse(row.hashes);
12
- if (!isValidHashList(parsed)) {
13
- store.stmts.undoDelete(path);
14
- return undefined;
15
- }
16
- return {
17
- content: row.content,
18
- bom: row.bom,
19
- ending: row.ending,
20
- hashes: parsed,
21
- resultContent: row.result_content,
22
- };
23
- }
24
- catch {
25
- store.stmts.undoDelete(path);
26
- return undefined;
27
- }
28
- }
29
- export function deleteUndo(store, path) {
30
- store.stmts.undoDelete(path);
31
- }
32
- export async function readUndo(path) {
33
- const store = await loadHashStore();
34
- return getUndoEntry(store, path);
35
- }
36
- export async function writeUndo(path, entry) {
37
- const store = await loadHashStore();
38
- upsertUndo(store, path, entry);
39
- }
40
- export async function removeUndo(path) {
41
- const store = await loadHashStore();
42
- deleteUndo(store, path);
43
- }