dsh-better-edit 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/lib/edit-engine.js +4 -454
- package/lib/edit-response.js +24 -2
- package/lib/file-encoding-state.js +263 -0
- package/lib/fs-bridge.js +94 -251
- package/lib/hash-store.js +1 -1
- package/lib/hashline/anchor-pipeline.js +19 -165
- package/lib/index.js +2 -2
- package/lib/mutation/engine.js +388 -0
- package/lib/mutation.js +84 -11
- package/lib/paths.js +1 -1
- package/lib/session-view.js +16 -49
- package/lib/store/index.js +28 -0
- package/lib/store-lifecycle.js +1 -1
- package/lib/tool-edit.js +2 -2
- package/lib/tool-read.js +2 -2
- package/lib/tool-undo.js +2 -2
- package/lib/types/edit-diff.d.ts +1 -1
- package/lib/types/edit-engine.d.ts +4 -176
- package/lib/types/edit-response.d.ts +1 -1
- package/lib/types/file-encoding-state.d.ts +77 -0
- package/lib/types/file-view.d.ts +1 -1
- package/lib/types/fs-bridge.d.ts +4 -11
- package/lib/types/hashline/anchor-pipeline.d.ts +6 -20
- package/lib/types/hashline/index.d.ts +1 -1
- package/lib/types/mutation/engine.d.ts +143 -0
- package/lib/types/mutation.d.ts +30 -5
- package/lib/types/paths.d.ts +1 -1
- package/lib/types/read-and-serve.d.ts +1 -1
- package/lib/types/session-view.d.ts +16 -30
- package/lib/types/store/index.d.ts +25 -0
- package/lib/types/workspace-context.d.ts +23 -0
- package/lib/workspace-context.js +44 -0
- package/lib/write-hook.js +2 -1
- package/package.json +1 -1
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
* AnchorPipeline — deep module owning the anchor autofix chain.
|
|
3
3
|
*
|
|
4
4
|
* Single ordering invariant (private):
|
|
5
|
-
* swapReversed → stripBare → stripDiff → valEdit →
|
|
5
|
+
* swapReversed → stripBare → stripDiff → valEdit → verifyServed → resToSpan
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* were split across resolve.ts / apply.ts with an implicit coupling.
|
|
9
|
-
* This seam co-locates that invariant. Public surface is two functions:
|
|
7
|
+
* This seam co-locates the ordering invariant. Public surface is two functions:
|
|
10
8
|
* resEdit — pre-validation (tool-layer, no file state)
|
|
11
9
|
* applyEdit — full pipeline (file + hashes + served verification)
|
|
12
10
|
*
|
|
13
11
|
* Private to this seam (not re-exported): stripBarePrefixes, stripDiffPrefixes,
|
|
14
|
-
* swapReversedRanges, valEdit,
|
|
12
|
+
* swapReversedRanges, valEdit, warnUnicodeEsc,
|
|
15
13
|
* resAnchorFromMap, assertAligned, etc. They remain exported from resolve.ts
|
|
16
14
|
* for backwards compat but are marked @internal and should be imported via this
|
|
17
15
|
* module only.
|
|
@@ -37,15 +35,6 @@ export type RHEdit = {
|
|
|
37
35
|
content_lines: string[];
|
|
38
36
|
hash_bounds: [RAnchor, RAnchor];
|
|
39
37
|
};
|
|
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
38
|
export interface NEdit {
|
|
50
39
|
loc: string;
|
|
51
40
|
currentContent: string;
|
|
@@ -57,11 +46,7 @@ export type HTEdit = {
|
|
|
57
46
|
};
|
|
58
47
|
export declare function resEdit(edit: HTEdit, warnings?: string[]): HEdit;
|
|
59
48
|
declare function warnUnicodeEsc(edit: HEdit, warnings: string[]): void;
|
|
60
|
-
|
|
61
|
-
export declare function findNewEdge(contentLines: string[], rangeLines: string[], fromEnd: boolean): {
|
|
62
|
-
index: number;
|
|
63
|
-
line: string;
|
|
64
|
-
} | undefined;
|
|
49
|
+
export declare function findNewEdge(): undefined;
|
|
65
50
|
export { warnUnicodeEsc };
|
|
66
51
|
export type ServedCode = "E_RANGE_STALE" | "E_RANGE_UNSERVED" | "E_RANGE_UNVERIFIED";
|
|
67
52
|
export interface ServedRow {
|
|
@@ -125,10 +110,11 @@ export declare function applyEdit(content: string, edit: HEdit, signal?: AbortSi
|
|
|
125
110
|
range: ResolvedRange;
|
|
126
111
|
warnings?: string[];
|
|
127
112
|
noopEdit?: NEdit;
|
|
128
|
-
autoFixes?: AutoFix[];
|
|
129
113
|
};
|
|
130
114
|
export declare function fmtRegion(hashes: string[], lines: string[]): string;
|
|
131
115
|
export declare function changedRange(original: string, result: string): {
|
|
132
116
|
firstChangedLine: number;
|
|
133
117
|
lastChangedLine: number;
|
|
134
118
|
} | null;
|
|
119
|
+
export { HASH_RE, HASH_CLASS, HASH_SEP, ANCHOR_LEN, ALPH_RE, ALPH, HASH_LEN, HASH_SPACE, MAX_HASH_LINES, HASH_PROBE_STRIDE, CANON_VERSION, canon, lineHashesPure, mapStableHashes, initHasher, contentChecksum, getCanonForHash, rememberHashCanon, } from "./hash-assign.js";
|
|
120
|
+
export { lineHashes } from "./hash.js";
|
|
@@ -8,6 +8,6 @@ export { lineHashes } from "./hash.js";
|
|
|
8
8
|
export { parseHashRef, parseText } from "./parse.js";
|
|
9
9
|
export type { Anchor } from "./parse.js";
|
|
10
10
|
export { resEdit } from "./anchor-pipeline.js";
|
|
11
|
-
export type { HEdit, HTEdit, NEdit
|
|
11
|
+
export type { HEdit, HTEdit, NEdit } from "./anchor-pipeline.js";
|
|
12
12
|
export { applyEdit, fmtRegion, changedRange, buildIdx, ServedRejectionError, AnchorMismatchError, EditHashEchoError, findEditHashEcho, isServedRejection, isAnchorMismatch, verifyServedRange, buildRangeEcho, fmtServedRows, } from "./anchor-pipeline.js";
|
|
13
13
|
export type { ServedRow, ResolvedRange, ServedCode, } from "./anchor-pipeline.js";
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal — private to Mutation seam. Do not import from outside src/mutation.
|
|
3
|
+
* The edit-sequence engine private to Mutation:
|
|
4
|
+
* apply-one-edit against in-memory content with served verification and the
|
|
5
|
+
* multi-edit sequencer that drives a whole file's item list against evolving
|
|
6
|
+
* content, the noop-loop guard, and the persist-undo → write → restore
|
|
7
|
+
* Transaction (persist-undo → write → restore) is owned by Mutation, not this engine.
|
|
8
|
+
*
|
|
9
|
+
* The model-facing contract lives here unchanged: [E_BATCH_ABORT],
|
|
10
|
+
* [E_NOOP_LOOP], [E_UNDO_UNAVAILABLE] carry byte-identical messages, and
|
|
11
|
+
* reject-and-serve records the same echo serves.
|
|
12
|
+
* @module dsh-better-edit/mutation/engine
|
|
13
|
+
*/
|
|
14
|
+
import type { FileIO } from "../fs-bridge.js";
|
|
15
|
+
import type { HashStore } from "../hash-store.js";
|
|
16
|
+
import type { LineEnding } from "../edit-diff.js";
|
|
17
|
+
import { type HEdit, type NEdit } from "../hashline/anchor-pipeline.js";
|
|
18
|
+
import { type ResolvedRange, type ServedRow } from "../hashline/anchor-pipeline.js";
|
|
19
|
+
export interface PreparedItem {
|
|
20
|
+
index: number;
|
|
21
|
+
path: string;
|
|
22
|
+
absolutePath: string;
|
|
23
|
+
remove_from: string;
|
|
24
|
+
remove_to: string;
|
|
25
|
+
replacement_text: string;
|
|
26
|
+
pathWarning?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface FileEditResult {
|
|
29
|
+
displayPath: string;
|
|
30
|
+
absolutePath: string;
|
|
31
|
+
originalNormalized: string;
|
|
32
|
+
result: string;
|
|
33
|
+
bom: string;
|
|
34
|
+
originalEnding: LineEnding;
|
|
35
|
+
hadUtf8DecodeErrors: boolean;
|
|
36
|
+
warnings: string[];
|
|
37
|
+
originalHashes: string[];
|
|
38
|
+
resultHashes: string[];
|
|
39
|
+
appliedCount: number;
|
|
40
|
+
noopCount: number;
|
|
41
|
+
totalAddedLines: number;
|
|
42
|
+
totalRemovedLines: number;
|
|
43
|
+
driftNotice: string | undefined;
|
|
44
|
+
range: ResolvedRange;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a request's missing `path` from its anchors: the only file whose
|
|
48
|
+
* stored hashes contain both anchors. Returns the path plus an autocorrect
|
|
49
|
+
* warning, or undefined when no resolution is possible.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveMissingPath(request: Record<string, unknown>): Promise<{
|
|
52
|
+
path: string;
|
|
53
|
+
warning: string;
|
|
54
|
+
} | undefined>;
|
|
55
|
+
/** The hashes a range edit removes, for stable re-hash bookkeeping. */
|
|
56
|
+
export declare function collectRemovedHashes(edit: HEdit, originalHashes: string[]): Set<string>;
|
|
57
|
+
/** Added/removed line counts for one resolved edit against a file's original hashes. */
|
|
58
|
+
export declare function countLineChanges(edit: HEdit, originalHashes: string[], isNoop: boolean, removedAutoFixes: number): {
|
|
59
|
+
totalAddedLines: number;
|
|
60
|
+
totalRemovedLines: number;
|
|
61
|
+
};
|
|
62
|
+
export interface ApplyOneInput {
|
|
63
|
+
content: string;
|
|
64
|
+
hashes: string[];
|
|
65
|
+
served: (string | null)[];
|
|
66
|
+
removeFrom: string;
|
|
67
|
+
removeTo: string;
|
|
68
|
+
replacementText: string;
|
|
69
|
+
absolutePath: string;
|
|
70
|
+
displayPath: string;
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
/** Shared warnings array; resEdit warnings are pushed here. */
|
|
73
|
+
warnings: string[];
|
|
74
|
+
/**
|
|
75
|
+
* The hashes to count added/removed lines against. Defaults to `hashes`;
|
|
76
|
+
* the batch sequencer passes the file's ORIGINAL hashes so later edits in
|
|
77
|
+
* a sequence still count against the file as first served.
|
|
78
|
+
*/
|
|
79
|
+
countHashes?: string[];
|
|
80
|
+
store?: HashStore;
|
|
81
|
+
persist: boolean;
|
|
82
|
+
/** Pre-resolved edit (single path keeps resEdit before IO for error order). */
|
|
83
|
+
edit?: HEdit;
|
|
84
|
+
}
|
|
85
|
+
export interface ApplyOneResult {
|
|
86
|
+
result: string;
|
|
87
|
+
/** Stable re-hash after the edit (equals `hashes` for a noop). */
|
|
88
|
+
hashes: string[];
|
|
89
|
+
range: ResolvedRange;
|
|
90
|
+
noop: boolean;
|
|
91
|
+
edit: HEdit;
|
|
92
|
+
noopEdit?: NEdit;
|
|
93
|
+
firstChangedLine?: number;
|
|
94
|
+
lastChangedLine?: number;
|
|
95
|
+
removedHashes: Set<string> | undefined;
|
|
96
|
+
totalAddedLines: number;
|
|
97
|
+
totalRemovedLines: number;
|
|
98
|
+
anchorWarnings: string[] | undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* One edit against in-memory content: resolve (unless a pre-resolved edit was
|
|
102
|
+
* given) → apply with served verification → stable re-hash → line counts.
|
|
103
|
+
*
|
|
104
|
+
* `onReject` owns the reject-and-serve policy: it receives resolve/verify
|
|
105
|
+
* failures (and the edit that failed, when resolved) and MUST throw. The
|
|
106
|
+
* single path rethrows the original anchor error after recording echo serves;
|
|
107
|
+
* the batch path wraps with [E_BATCH_ABORT] plus the current-range echo.
|
|
108
|
+
*/
|
|
109
|
+
export declare function applyOne(input: ApplyOneInput, onReject: (error: unknown, edit: HEdit | undefined) => Promise<never>): Promise<ApplyOneResult>;
|
|
110
|
+
export interface NoopLoopOptions {
|
|
111
|
+
absolutePath: string;
|
|
112
|
+
removeFrom: string;
|
|
113
|
+
removeTo: string;
|
|
114
|
+
replacementText: string;
|
|
115
|
+
displayPath: string;
|
|
116
|
+
/** Batch item index; undefined = single-edit flavor. */
|
|
117
|
+
index?: number;
|
|
118
|
+
count: number;
|
|
119
|
+
sessionKey: string;
|
|
120
|
+
originalHashes: string[];
|
|
121
|
+
originalNormalized: string;
|
|
122
|
+
/** Single-edit flavor only: the edit's range, for the echo rows. */
|
|
123
|
+
range?: ResolvedRange;
|
|
124
|
+
/** Batch flavor: precomputed echo rows for the failed item (may be absent). */
|
|
125
|
+
echoRows?: ServedRow[];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The shared noop-loop guard. Returns the "twice in a row" notice for the
|
|
129
|
+
* caller to append to warnings, or throws [E_NOOP_LOOP] (after recording the
|
|
130
|
+
* echo serves) once the payload has been submitted NOOP_LOOP_THRESHOLD times
|
|
131
|
+
* with no change. Messages are byte-identical to the pre-engine tools.
|
|
132
|
+
*/
|
|
133
|
+
export declare function enforceNoopLoop(opts: NoopLoopOptions): Promise<string | undefined>;
|
|
134
|
+
/**
|
|
135
|
+
* Run a file's item list against freshly-read content with served
|
|
136
|
+
* verification, evolving content/hashes, union range, noop tracking, and a
|
|
137
|
+
* per-file drift notice. All-or-nothing is enforced by the caller's
|
|
138
|
+
* transaction ({@link persistUndoAndWrite}): nothing here writes to disk.
|
|
139
|
+
*/
|
|
140
|
+
export declare function runFileEdits(io: FileIO, items: PreparedItem[], opts: {
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
sessionKey: string;
|
|
143
|
+
}): Promise<FileEditResult>;
|
package/lib/types/mutation.d.ts
CHANGED
|
@@ -34,12 +34,13 @@ import type { LineEnding } from "./edit-diff.js";
|
|
|
34
34
|
import { type NEdit } from "./hashline/anchor-pipeline.js";
|
|
35
35
|
import type { ResolvedRange } from "./hashline/anchor-pipeline.js";
|
|
36
36
|
import { scanDrift } from "./session-view.js";
|
|
37
|
-
import { runFileEdits, resolveMissingPath
|
|
38
|
-
import type { FileEditResult, PreparedItem } from "./
|
|
37
|
+
import { runFileEdits, resolveMissingPath } from "./mutation/engine.js";
|
|
38
|
+
import type { FileEditResult, PreparedItem } from "./mutation/engine.js";
|
|
39
|
+
import { restoreEndings } from "./edit-diff.js";
|
|
39
40
|
import { buildMetrics, buildNoop, buildChanged, buildBatchResult } from "./edit-response.js";
|
|
40
41
|
import type { RMeta, BatchSection } from "./edit-response.js";
|
|
41
|
-
import { genDiff,
|
|
42
|
-
import { computeDrift } from "./
|
|
42
|
+
import { genDiff, toLF, stripBOM } from "./edit-diff.js";
|
|
43
|
+
import { computeDrift } from "./session-view.js";
|
|
43
44
|
import { trackNoopPayload, clearNoopLoop, noopPayloadKey } from "./noop-guard.js";
|
|
44
45
|
export interface PipelineResult {
|
|
45
46
|
path: string;
|
|
@@ -71,13 +72,36 @@ export declare function execPipeline(io: FileIO, params: EditParams, cwd: string
|
|
|
71
72
|
export declare function resolveDisplayPath(path: string, cwd: string): string;
|
|
72
73
|
/** Snapshot bookkeeping for noop/success results (best-effort). */
|
|
73
74
|
export declare function snapshotIdFor(io: FileIO, absolutePath: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
74
|
-
export { runFileEdits, resolveMissingPath
|
|
75
|
+
export { runFileEdits, resolveMissingPath };
|
|
76
|
+
export { persistUndoAndWrite };
|
|
75
77
|
export type { FileEditResult, PreparedItem };
|
|
76
78
|
export { buildMetrics, buildNoop, buildChanged, buildBatchResult };
|
|
77
79
|
export type { RMeta, BatchSection };
|
|
78
80
|
export { genDiff, restoreEndings, toLF, stripBOM };
|
|
79
81
|
export { computeDrift, scanDrift };
|
|
80
82
|
export { trackNoopPayload, clearNoopLoop, noopPayloadKey };
|
|
83
|
+
interface UndoWriteFile {
|
|
84
|
+
absolutePath: string;
|
|
85
|
+
displayPath: string;
|
|
86
|
+
originalNormalized: string;
|
|
87
|
+
bom: string;
|
|
88
|
+
originalEnding: LineEnding;
|
|
89
|
+
originalHashes: string[];
|
|
90
|
+
result: string;
|
|
91
|
+
}
|
|
92
|
+
interface PersistWriteOptions {
|
|
93
|
+
io: FileIO;
|
|
94
|
+
files: UndoWriteFile[];
|
|
95
|
+
exec: ToolExecution;
|
|
96
|
+
sandbox: FsSandboxController;
|
|
97
|
+
sandboxPolicy: SandboxExecutionPolicy | undefined;
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
undoUnavailableMessage: (displayPath: string) => string;
|
|
100
|
+
restoreUnwrittenUndos: boolean;
|
|
101
|
+
}
|
|
102
|
+
declare function persistUndoAndWrite(opts: PersistWriteOptions): Promise<void>;
|
|
103
|
+
declare function commitSingle(opts: Omit<PersistWriteOptions, "restoreUnwrittenUndos">): Promise<void>;
|
|
104
|
+
declare function commitBatch(opts: Omit<PersistWriteOptions, "restoreUnwrittenUndos">): Promise<void>;
|
|
81
105
|
/**
|
|
82
106
|
* Deep seam: execute the full mutation lifecycle.
|
|
83
107
|
*
|
|
@@ -129,3 +153,4 @@ export declare function commit(opts: {
|
|
|
129
153
|
undoUnavailableMessage: (displayPath: string) => string;
|
|
130
154
|
restoreUnwrittenUndos?: boolean;
|
|
131
155
|
}): Promise<void>;
|
|
156
|
+
export { commitSingle, commitBatch };
|
package/lib/types/paths.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module dsh-better-edit/read-and-serve
|
|
9
9
|
*/
|
|
10
10
|
import type { FileIO } from "./fs-bridge.js";
|
|
11
|
-
import type { ServedRow } from "./hashline/
|
|
11
|
+
import type { ServedRow } from "./hashline/anchor-pipeline.js";
|
|
12
12
|
/** Appended when the file had non-UTF-8 bytes; editing rewrites it as UTF-8. */
|
|
13
13
|
export declare const UTF8_REWRITE_NOTE = "[Non-UTF-8 bytes shown as U+FFFD; editing rewrites the file as UTF-8.]";
|
|
14
14
|
export interface ReadAndServeOptions {
|
|
@@ -1,41 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SessionView — deep module owning served rows + drift + position reconstruction.
|
|
3
3
|
*
|
|
4
|
-
* Previously
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* +
|
|
4
|
+
* Previously also owned workspace/session context (AsyncLocalStorage +
|
|
5
|
+
* execCwd/execSessionKey/sessionKeyFor + path re-exports) as
|
|
6
|
+
* "private to this seam, @internal". That mixed two invariants:
|
|
7
|
+
* served-merge+drift vs context propagation. Now this seam owns ONLY
|
|
8
|
+
* served state and drift; WorkspaceContext owns execution context.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* servedPositionsOf, currentPositionOfDrifted, _mergeServedRows (via served-store)
|
|
10
|
+
* Public surface: _mergeServedRows, loadServed, recordServed,
|
|
11
|
+
* recordServedTruncated, driftReported, markDriftReported,
|
|
12
|
+
* clearDriftReported, wipeServedState, servedPositionsOf,
|
|
13
|
+
* currentPositionOfDrifted, computeDrift, scanDrift, and
|
|
14
|
+
* hash-store persistence delegation (ServedPersistence).
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* but are marked deprecated.
|
|
22
|
-
*
|
|
23
|
-
* Ownership: This file now OWNS the served-merge invariant
|
|
24
|
-
* (_mergeServedRows), the position-reconstruction math, and the drift
|
|
25
|
-
* computation. Deleting it would scatter the served+drift invariant
|
|
26
|
-
* across 4 files — it concentrates (deep).
|
|
16
|
+
* Ownership: This file OWNS the served-merge invariant
|
|
17
|
+
* (_mergeServedRows with orphan healing per ADR-0008), the
|
|
18
|
+
* position-reconstruction math, and the drift computation. Deleting
|
|
19
|
+
* it would scatter the served+drift invariant across 4 files — it
|
|
20
|
+
* concentrates (deep).
|
|
27
21
|
*
|
|
28
22
|
* @module dsh-better-edit/session-view
|
|
29
23
|
*/
|
|
30
|
-
import type {
|
|
31
|
-
import type { ServedRow, ResolvedRange } from "./hashline/served.js";
|
|
32
|
-
import { configDir, hashStorePath, resolveTarget } from "./paths.js";
|
|
33
|
-
export declare function withWorkspace<T>(cwd: string, fn: () => Promise<T>): Promise<T>;
|
|
34
|
-
export declare function workspaceCwd(): string | undefined;
|
|
35
|
-
export declare function sessionKeyFor(sessionId?: string): string;
|
|
36
|
-
export declare function execCwd(exec: ToolExecution): string;
|
|
37
|
-
export declare function execSessionKey(exec: ToolExecution): string;
|
|
38
|
-
export { configDir, hashStorePath, resolveTarget };
|
|
24
|
+
import type { ServedRow, ResolvedRange } from "./hashline/anchor-pipeline.js";
|
|
39
25
|
export { loadHashStore, loadServedStore, shutdownHashStore, withStore } from "./hash-store.js";
|
|
40
26
|
export type { HashStore } from "./hash-store.js";
|
|
41
27
|
export type ServedEntry = {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store — deep module owning tenancy + lifecycle + path resolution.
|
|
3
|
+
*
|
|
4
|
+
* Single seam that answers "which store, where, and is it open?"
|
|
5
|
+
* Tenancy (where DB lives) and lifecycle (central GC + row TTL + WAL)
|
|
6
|
+
* are private details of this seam; hash-store keeps only schema +
|
|
7
|
+
* row-family domain logic and imports path resolution from here.
|
|
8
|
+
* StoreConfig remains the config complement seam but its path is
|
|
9
|
+
* resolved via this Store seam.
|
|
10
|
+
*
|
|
11
|
+
* YAGNI-gated: DB plumbing (openDb/buildStore/quarantine/busy-retry/
|
|
12
|
+
* WAL/legacy JSON migration) stays in hash-store for now and is
|
|
13
|
+
* re-exported here for testability without importing domain helpers
|
|
14
|
+
* — full plumbing move is deferred to avoid contract risk. Old
|
|
15
|
+
* store-tenancy/store-lifecycle files are kept as compat shims
|
|
16
|
+
* re-exporting from this seam (reversible).
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-better-edit/store
|
|
19
|
+
*/
|
|
20
|
+
export { tenancyFor, configDir, hashStorePath, hashStoreDir, legacyHashStorePath, loadConfig, _resetConfigCache, expand, } from "../store-tenancy.js";
|
|
21
|
+
export type { Tenancy, StoreConfig } from "../store-tenancy.js";
|
|
22
|
+
export { onStoreOpen, onAppStart, onSessionStart, setStoresGetter, runCentralJanitorIfDue, _resetLifecycleForTests, } from "../store-lifecycle.js";
|
|
23
|
+
export { loadConfig as loadStoreConfig } from "../store-config.js";
|
|
24
|
+
export { isCorruptionError, loadHashStore, shutdownHashStore, withStore, findSnapshotPathsByHashes, upsertSnapshotFor, } from "../hash-store.js";
|
|
25
|
+
export type { HashStore, InternalHashStore, ServedPersistence } from "../hash-store.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkspaceContext — deep module owning execution context propagation.
|
|
3
|
+
*
|
|
4
|
+
* Single job: propagate `cwd` and `sessionKey` from the DSH tool execution
|
|
5
|
+
* into the plugin's async chain. Previously co-located inside
|
|
6
|
+
* `session-view.ts` (served+drift+workspace+paths re-exports) as
|
|
7
|
+
* "private to this seam, @internal" with an AsyncLocalStorage. That god
|
|
8
|
+
* seam mixed two invariants: served-merge+drift vs context propagation.
|
|
9
|
+
*
|
|
10
|
+
* Deleting this module would scatter `withWorkspace`/`workspaceCwd` and
|
|
11
|
+
* `execCwd`/`execSessionKey`/`sessionKeyFor` across every tool and IO
|
|
12
|
+
* caller — it concentrates (deep). Tested via scoped-execution tests,
|
|
13
|
+
* not drift.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-better-edit/workspace-context
|
|
16
|
+
*/
|
|
17
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
18
|
+
export declare function withWorkspace<T>(cwd: string, fn: () => Promise<T>): Promise<T>;
|
|
19
|
+
export declare function workspaceCwd(): string | undefined;
|
|
20
|
+
export declare function sessionKeyFor(sessionId?: string): string;
|
|
21
|
+
export declare function execCwd(exec: ToolExecution): string;
|
|
22
|
+
export declare function execSessionKey(exec: ToolExecution): string;
|
|
23
|
+
export declare function _resetWorkspaceContextForTests(): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkspaceContext — deep module owning execution context propagation.
|
|
3
|
+
*
|
|
4
|
+
* Single job: propagate `cwd` and `sessionKey` from the DSH tool execution
|
|
5
|
+
* into the plugin's async chain. Previously co-located inside
|
|
6
|
+
* `session-view.ts` (served+drift+workspace+paths re-exports) as
|
|
7
|
+
* "private to this seam, @internal" with an AsyncLocalStorage. That god
|
|
8
|
+
* seam mixed two invariants: served-merge+drift vs context propagation.
|
|
9
|
+
*
|
|
10
|
+
* Deleting this module would scatter `withWorkspace`/`workspaceCwd` and
|
|
11
|
+
* `execCwd`/`execSessionKey`/`sessionKeyFor` across every tool and IO
|
|
12
|
+
* caller — it concentrates (deep). Tested via scoped-execution tests,
|
|
13
|
+
* not drift.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-better-edit/workspace-context
|
|
16
|
+
*/
|
|
17
|
+
import { randomUUID } from "node:crypto";
|
|
18
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
19
|
+
// --- AsyncLocalStorage for cwd propagation ---
|
|
20
|
+
const current = new AsyncLocalStorage();
|
|
21
|
+
export function withWorkspace(cwd, fn) {
|
|
22
|
+
return current.run(cwd, fn);
|
|
23
|
+
}
|
|
24
|
+
export function workspaceCwd() {
|
|
25
|
+
return current.getStore();
|
|
26
|
+
}
|
|
27
|
+
// --- sessionKey helpers ---
|
|
28
|
+
let fallbackSessionKey;
|
|
29
|
+
export function sessionKeyFor(sessionId) {
|
|
30
|
+
if (sessionId && sessionId.length > 0)
|
|
31
|
+
return sessionId;
|
|
32
|
+
// fallback for previews/tests
|
|
33
|
+
return fallbackSessionKey ??= randomUUID();
|
|
34
|
+
}
|
|
35
|
+
export function execCwd(exec) {
|
|
36
|
+
return exec.agent?.session.header.cwd ?? process.cwd();
|
|
37
|
+
}
|
|
38
|
+
export function execSessionKey(exec) {
|
|
39
|
+
return sessionKeyFor(exec.agent?.session.id);
|
|
40
|
+
}
|
|
41
|
+
// For tests: reset the fallback UUID so tests can be isolated
|
|
42
|
+
export function _resetWorkspaceContextForTests() {
|
|
43
|
+
fallbackSessionKey = undefined;
|
|
44
|
+
}
|
package/lib/write-hook.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* @module dsh-better-edit/write-hook
|
|
7
7
|
*/
|
|
8
8
|
import { readAndServe } from './read-and-serve.js';
|
|
9
|
-
import { execCwd, execSessionKey,
|
|
9
|
+
import { execCwd, execSessionKey, withWorkspace } from './workspace-context.js';
|
|
10
|
+
import { loadServed } from './session-view.js';
|
|
10
11
|
import { HASH_SEP } from './hashline/hash-assign.js';
|
|
11
12
|
import { abortIf, splitLines } from './utils.js';
|
|
12
13
|
const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hash-anchored read/edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
|
|
6
6
|
"main": "lib/index.js",
|