dsh-better-edit 1.2.4 → 1.2.5
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 +19 -0
- package/lib/domain-errors.js +11 -9
- package/lib/edit-mode.js +11 -0
- package/lib/encoding.js +2 -0
- package/lib/file-encoding-state.js +42 -25
- package/lib/file-view.js +26 -205
- package/lib/fs-bridge.js +14 -49
- package/lib/hashline/anchor-pipeline.js +8 -499
- package/lib/hashline/hash-assign.js +55 -4
- package/lib/hashline/index.js +5 -2
- package/lib/hashline/served-evidence.js +531 -0
- package/lib/index.js +176 -47
- package/lib/mutation/engine.js +10 -13
- package/lib/mutation.js +36 -100
- package/lib/noop-guard.js +24 -39
- package/lib/paths.js +9 -5
- package/lib/read-and-serve.js +51 -53
- package/lib/reclaim.js +65 -0
- package/lib/self-heal.js +6 -10
- package/lib/session-view.js +61 -21
- package/lib/store/index.js +14 -14
- package/lib/store-config.js +4 -5
- package/lib/store-lifecycle.js +1 -1
- package/lib/tool-edit.js +0 -3
- package/lib/tool-read.js +2 -8
- package/lib/tool-str-replace-editor.js +3 -10
- package/lib/tool-undo.js +5 -13
- package/lib/types/contract.d.ts +2 -1
- package/lib/types/domain-errors.d.ts +8 -9
- package/lib/types/edit-mode.d.ts +11 -0
- package/lib/types/encoding.d.ts +1 -0
- package/lib/types/file-encoding-state.d.ts +10 -10
- package/lib/types/file-view.d.ts +18 -56
- package/lib/types/hashline/anchor-pipeline.d.ts +6 -128
- package/lib/types/hashline/hash-assign.d.ts +40 -0
- package/lib/types/hashline/index.d.ts +6 -4
- package/lib/types/hashline/served-evidence.d.ts +152 -0
- package/lib/types/mutation/engine.d.ts +4 -2
- package/lib/types/mutation.d.ts +9 -57
- package/lib/types/noop-guard.d.ts +2 -33
- package/lib/types/paths.d.ts +0 -1
- package/lib/types/reclaim.d.ts +36 -0
- package/lib/types/session-view.d.ts +28 -8
- package/lib/types/store/index.d.ts +12 -11
- package/lib/types/store-config.d.ts +1 -1
- package/lib/types/store-lifecycle.d.ts +12 -2
- package/lib/types/tool-edit.d.ts +0 -2
- package/lib/types/tool-read.d.ts +0 -5
- package/lib/types/tool-str-replace-editor.d.ts +0 -6
- package/lib/types/tool-undo.d.ts +0 -5
- package/package.json +3 -2
- package/lib/drift.js +0 -5
- package/lib/dsh-context.js +0 -5
- package/lib/edit-engine.js +0 -7
- package/lib/edit-normalize.js +0 -9
- package/lib/edit-pipeline.js +0 -6
- package/lib/file-kind.js +0 -6
- package/lib/file-reader.js +0 -6
- package/lib/guidance/index.js +0 -8
- package/lib/hashline/alphabet.js +0 -2
- package/lib/hashline/apply.js +0 -2
- package/lib/hashline/hasher.js +0 -2
- package/lib/hashline/parse.js +0 -2
- package/lib/hashline/pure.js +0 -2
- package/lib/hashline/resolve.js +0 -3
- package/lib/hashline/served.js +0 -2
- package/lib/preview-controller.js +0 -65
- package/lib/read-render.js +0 -6
- package/lib/schema.js +0 -24
- package/lib/served-store.js +0 -5
- package/lib/tool-batch-edit.js +0 -190
- package/lib/truncate.js +0 -6
- package/lib/types/drift.d.ts +0 -5
- package/lib/types/dsh-context.d.ts +0 -5
- package/lib/types/edit-engine.d.ts +0 -7
- package/lib/types/edit-normalize.d.ts +0 -1
- package/lib/types/edit-pipeline.d.ts +0 -6
- package/lib/types/file-kind.d.ts +0 -6
- package/lib/types/file-reader.d.ts +0 -6
- package/lib/types/guidance/index.d.ts +0 -8
- package/lib/types/hashline/alphabet.d.ts +0 -1
- package/lib/types/hashline/apply.d.ts +0 -1
- package/lib/types/hashline/hasher.d.ts +0 -1
- package/lib/types/hashline/parse.d.ts +0 -1
- package/lib/types/hashline/pure.d.ts +0 -1
- package/lib/types/hashline/resolve.d.ts +0 -1
- package/lib/types/hashline/served.d.ts +0 -1
- package/lib/types/preview-controller.d.ts +0 -33
- package/lib/types/read-render.d.ts +0 -6
- package/lib/types/schema.d.ts +0 -25
- package/lib/types/served-store.d.ts +0 -5
- package/lib/types/tool-batch-edit.d.ts +0 -25
- package/lib/types/truncate.d.ts +0 -6
- package/lib/types/validation.d.ts +0 -6
- package/lib/types/workspace.d.ts +0 -5
- package/lib/validation.js +0 -6
- package/lib/workspace.js +0 -5
package/lib/types/mutation.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mutation — deep module owning the full file mutation lifecycle.
|
|
3
3
|
*
|
|
4
|
-
* Previously fragmented: tool-edit → edit-pipeline →
|
|
5
|
-
* edit-response/diff/drift, and tool-batch-edit →
|
|
4
|
+
* Previously fragmented: tool-edit → edit-pipeline → engine.applyOne →
|
|
5
|
+
* edit-response/diff/drift, and tool-batch-edit → engine.runFileEdits
|
|
6
6
|
* (loop + unionRange + counters) → persistUndoAndWrite with a boolean flag.
|
|
7
7
|
* Warnings, hadUtf8DecodeErrors, firstChangedLine, driftNotice were threaded
|
|
8
8
|
* by mutation across 5 hops; bugs hid in wiring, not pure helpers.
|
|
@@ -13,13 +13,12 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Public surface:
|
|
15
15
|
* execute(io, items, {sessionKey, exec, sandbox, signal}) → string — deep seam: ONE interface
|
|
16
|
-
*
|
|
17
|
-
* commit(io, files, {exec, sandboxPolicy, signal}) → void — transaction
|
|
16
|
+
* persistUndoAndWrite(opts) → void — transaction (exported for tests)
|
|
18
17
|
*
|
|
19
18
|
* Depth: small interface (execute) with large implementation — locality and leverage.
|
|
20
19
|
*
|
|
21
|
-
* Internals (private): verifyServedRange, resToSpan, assemble,
|
|
22
|
-
*
|
|
20
|
+
* Internals (private): verifyServedRange, resToSpan, assemble, boundaryDups,
|
|
21
|
+
* noopGuard. Tested via FileEditResult, not via split e2e.
|
|
23
22
|
*
|
|
24
23
|
* @module dsh-better-edit/mutation
|
|
25
24
|
*/
|
|
@@ -28,27 +27,7 @@ import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
|
28
27
|
import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
|
29
28
|
import type { FsSandboxController } from "./sandbox.js";
|
|
30
29
|
import type { LineEnding } from "./edit-diff.js";
|
|
31
|
-
import {
|
|
32
|
-
import { runFileEdits } from "./mutation/engine.js";
|
|
33
|
-
import type { FileEditResult, PreparedItem } from "./mutation/engine.js";
|
|
34
|
-
import { restoreEndings } from "./edit-diff.js";
|
|
35
|
-
import { buildMetrics, buildNoop, buildChanged, buildBatchResult } from "./edit-response.js";
|
|
36
|
-
import type { RMeta, BatchSection } from "./edit-response.js";
|
|
37
|
-
import { genDiff, toLF, stripBOM } from "./edit-diff.js";
|
|
38
|
-
import { computeDrift } from "./session-view.js";
|
|
39
|
-
import { trackNoopPayload, clearNoopLoop, noopPayloadKey } from "./noop-guard.js";
|
|
40
|
-
/** Resolve the display path a caller names against the session cwd. */
|
|
41
|
-
export declare function resolveDisplayPath(path: string, cwd: string): string;
|
|
42
|
-
/** Snapshot bookkeeping for noop/success results (best-effort). */
|
|
43
|
-
export declare function snapshotIdFor(io: FileIO, absolutePath: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
44
|
-
export { runFileEdits };
|
|
45
|
-
export { persistUndoAndWrite };
|
|
46
|
-
export type { FileEditResult, PreparedItem };
|
|
47
|
-
export { buildMetrics, buildNoop, buildChanged, buildBatchResult };
|
|
48
|
-
export type { RMeta, BatchSection };
|
|
49
|
-
export { genDiff, restoreEndings, toLF, stripBOM };
|
|
50
|
-
export { computeDrift, scanDrift };
|
|
51
|
-
export { trackNoopPayload, clearNoopLoop, noopPayloadKey };
|
|
30
|
+
import type { PreparedItem } from "./mutation/engine.js";
|
|
52
31
|
interface UndoWriteFile {
|
|
53
32
|
absolutePath: string;
|
|
54
33
|
displayPath: string;
|
|
@@ -66,15 +45,12 @@ interface PersistWriteOptions {
|
|
|
66
45
|
sandboxPolicy: SandboxExecutionPolicy | undefined;
|
|
67
46
|
signal?: AbortSignal;
|
|
68
47
|
undoUnavailableMessage: (displayPath: string) => string;
|
|
69
|
-
restoreUnwrittenUndos: boolean;
|
|
70
48
|
}
|
|
71
|
-
declare function persistUndoAndWrite(opts: PersistWriteOptions): Promise<void>;
|
|
72
|
-
declare function commitSingle(opts: Omit<PersistWriteOptions, "restoreUnwrittenUndos">): Promise<void>;
|
|
73
|
-
declare function commitBatch(opts: Omit<PersistWriteOptions, "restoreUnwrittenUndos">): Promise<void>;
|
|
49
|
+
export declare function persistUndoAndWrite(opts: PersistWriteOptions): Promise<void>;
|
|
74
50
|
/**
|
|
75
51
|
* Deep seam: execute the full mutation lifecycle.
|
|
76
52
|
*
|
|
77
|
-
* Owns:
|
|
53
|
+
* Owns: runFileEdits → branch (single/multi × noop/applied) → commit →
|
|
78
54
|
* buildBatchResult → recordServedTruncated → return text.
|
|
79
55
|
*
|
|
80
56
|
* The tool layer (adapter) only validates and delegates; all
|
|
@@ -91,28 +67,4 @@ export declare function execute(opts: {
|
|
|
91
67
|
sandbox: FsSandboxController;
|
|
92
68
|
sandboxPolicy: SandboxExecutionPolicy | undefined;
|
|
93
69
|
}): Promise<string>;
|
|
94
|
-
|
|
95
|
-
export declare function applySequence(io: FileIO, items: PreparedItem[], ctx: {
|
|
96
|
-
sessionKey: string;
|
|
97
|
-
signal?: AbortSignal;
|
|
98
|
-
}): Promise<FileEditResult>;
|
|
99
|
-
/** Commit the transaction — owns persist-undo → write → restore. */
|
|
100
|
-
export declare function commit(opts: {
|
|
101
|
-
io: FileIO;
|
|
102
|
-
files: Array<{
|
|
103
|
-
absolutePath: string;
|
|
104
|
-
displayPath: string;
|
|
105
|
-
originalNormalized: string;
|
|
106
|
-
bom: string;
|
|
107
|
-
originalEnding: import("./edit-diff.js").LineEnding;
|
|
108
|
-
originalHashes: string[];
|
|
109
|
-
result: string;
|
|
110
|
-
}>;
|
|
111
|
-
exec: ToolExecution;
|
|
112
|
-
sandbox: FsSandboxController;
|
|
113
|
-
sandboxPolicy: SandboxExecutionPolicy | undefined;
|
|
114
|
-
signal?: AbortSignal;
|
|
115
|
-
undoUnavailableMessage: (displayPath: string) => string;
|
|
116
|
-
restoreUnwrittenUndos?: boolean;
|
|
117
|
-
}): Promise<void>;
|
|
118
|
-
export { commitSingle, commitBatch };
|
|
70
|
+
export {};
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
import { NOOP_LOOP_THRESHOLD } from "./constants.js";
|
|
2
1
|
export declare function noopPayloadKey(absolutePath: string, anchorFrom: string, anchorTo: string, replaceWith: string): string;
|
|
3
|
-
export declare function trackNoopPayload(absolutePath: string, payload: string): number;
|
|
4
|
-
export declare function clearNoopLoop(absolutePath: string): void;
|
|
5
|
-
export { NOOP_LOOP_THRESHOLD };
|
|
6
|
-
export interface NoopPolicyInput {
|
|
7
|
-
absolutePath: string;
|
|
8
|
-
anchorFrom: string;
|
|
9
|
-
anchorTo: string;
|
|
10
|
-
replaceWith: string;
|
|
11
|
-
ref: string;
|
|
12
|
-
batch: boolean;
|
|
13
|
-
range: {
|
|
14
|
-
startLine: number;
|
|
15
|
-
endLine: number;
|
|
16
|
-
};
|
|
17
|
-
hashes: string[];
|
|
18
|
-
lines: string[];
|
|
19
|
-
sessionKey: string;
|
|
20
|
-
}
|
|
21
|
-
export type NoopPolicyOutcome = {
|
|
22
|
-
action: "proceed";
|
|
23
|
-
count: number;
|
|
24
|
-
} | {
|
|
25
|
-
action: "warn";
|
|
26
|
-
count: number;
|
|
27
|
-
notice: string;
|
|
28
|
-
} | {
|
|
29
|
-
action: "reject";
|
|
30
|
-
count: number;
|
|
31
|
-
message: string;
|
|
32
|
-
};
|
|
33
|
-
export declare function runNoopPolicySync(input: NoopPolicyInput, count: number): NoopPolicyOutcome;
|
|
34
|
-
export declare function runNoopPolicy(input: NoopPolicyInput): Promise<NoopPolicyOutcome>;
|
|
2
|
+
export declare function trackNoopPayload(sessionKey: string, absolutePath: string, payload: string): number;
|
|
3
|
+
export declare function clearNoopLoop(sessionKey: string, absolutePath: string): void;
|
package/lib/types/paths.d.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tool reclamation utility for DSH scoped layers.
|
|
3
|
+
* Used by installAgentTools and createSelfHealWatcher.
|
|
4
|
+
* @module dsh-better-edit/reclaim
|
|
5
|
+
*/
|
|
6
|
+
export interface ScopedToolLayer {
|
|
7
|
+
get?: (name: string) => unknown;
|
|
8
|
+
data?: Map<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface LoggerChannel {
|
|
11
|
+
warn(msg: string): void;
|
|
12
|
+
error?(msg: string): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the agent's scoped tool layer from the DSH tools service.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAgentScopedToolLayer(toolsSvc: unknown, agent: unknown): ScopedToolLayer | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Reclaim an entry by deleting it from the scoped layer's data map.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reclaimToolEntry(layer: ScopedToolLayer | undefined, name: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Register a tool with collision detection, guarded reclaim, and single retry.
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerWithReclaim(options: {
|
|
26
|
+
toolsSvc: unknown;
|
|
27
|
+
agent: unknown;
|
|
28
|
+
agentCtx: {
|
|
29
|
+
tools: {
|
|
30
|
+
register(def: unknown): () => void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
name: string;
|
|
34
|
+
def: unknown;
|
|
35
|
+
logger?: LoggerChannel;
|
|
36
|
+
}): (() => void) | undefined;
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Public surface: _mergeServedRows, loadServed, recordServed,
|
|
11
11
|
* recordServedTruncated, driftReported, markDriftReported,
|
|
12
|
-
* clearDriftReported, wipeServedState, servedPositionsOf
|
|
13
|
-
* currentPositionOfDrifted, computeDrift, scanDrift, and
|
|
12
|
+
* clearDriftReported, wipeServedState, servedPositionsOf (re-exported from
|
|
13
|
+
* hashline/served-evidence), currentPositionOfDrifted, computeDrift, scanDrift, and
|
|
14
14
|
* hash-store persistence delegation (ServedPersistence).
|
|
15
15
|
*
|
|
16
16
|
* Ownership: This file OWNS the served-merge invariant
|
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
* @module dsh-better-edit/session-view
|
|
24
24
|
*/
|
|
25
25
|
import { type AnchorReservations, type ServedPersistence } from "./hash-store.js";
|
|
26
|
-
import type { ServedRow
|
|
26
|
+
import type { ServedRow } from "./domain-errors.js";
|
|
27
|
+
import { servedPositionsOf } from "./hashline/served-evidence.js";
|
|
28
|
+
import type { ResolvedRange } from "./hashline/served-evidence.js";
|
|
29
|
+
export { servedPositionsOf };
|
|
27
30
|
export { loadHashStore, loadServedStore, shutdownHashStore, withStore } from "./hash-store.js";
|
|
28
31
|
export type { HashStore } from "./hash-store.js";
|
|
29
32
|
export type ServedEntry = {
|
|
@@ -70,16 +73,30 @@ export declare function retireAnchors(sessionKey: string, path: string, hashes:
|
|
|
70
73
|
* does not matter — the anchor's line is back, so the whole entry goes.
|
|
71
74
|
*/
|
|
72
75
|
export declare function unretireAnchorsInStore(store: ServedPersistence, sessionKey: string, path: string, hashes: Iterable<string>): void;
|
|
73
|
-
/**
|
|
74
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Serve context: what the read showed of the file, plus the full-read verdict the read computed.
|
|
78
|
+
*
|
|
79
|
+
* `fullRead` is the ONE authority (ADR-0035). It is `FileView.fullRead` — a fact about the read
|
|
80
|
+
* REQUEST (no `offset`, no `limit`, no requested windows, no truncation) — and never a fact about
|
|
81
|
+
* the `rows` this call happens to carry: a page whose rows cover every line is still a page.
|
|
82
|
+
*/
|
|
83
|
+
export interface ServeContext {
|
|
75
84
|
hashes: readonly string[];
|
|
76
85
|
canons?: readonly (string | null)[];
|
|
77
86
|
/**
|
|
78
87
|
* Full content the hashes were computed from. When present (with `hashes`),
|
|
79
88
|
* recordServed also materializes-or-adopts the serve snapshot and grants
|
|
80
|
-
* leases for `rows` as-is through the store's single transaction
|
|
89
|
+
* leases for `rows` as-is through the store's single transaction — for a page too: a shown
|
|
90
|
+
* anchor must stay editable, so the grant is not a full-read effect.
|
|
81
91
|
*/
|
|
82
92
|
content?: string;
|
|
93
|
+
/**
|
|
94
|
+
* True only for an untruncated whole-file read with no page request — gates the three hazard/
|
|
95
|
+
* cache effects a full read owns (retired anchors, hazard cards, the whole canon array).
|
|
96
|
+
* Nothing else: the lease grant below is unconditional, and `recordServedTruncated` has no
|
|
97
|
+
* verdict at all.
|
|
98
|
+
*/
|
|
99
|
+
fullRead: boolean;
|
|
83
100
|
}
|
|
84
101
|
/** Serve-snapshot context for lease granting: content parallel to `hashes`. */
|
|
85
102
|
export interface ServeSnapshot {
|
|
@@ -93,8 +110,12 @@ export interface ServeSnapshot {
|
|
|
93
110
|
* `false` means the write rolled back and no lease was granted, so the caller must not advertise
|
|
94
111
|
* the rows' anchors as usable: that is a partial failure of the caller's operation, not a failed
|
|
95
112
|
* operation. The best-effort contract is unchanged — this never throws.
|
|
113
|
+
*
|
|
114
|
+
* The context's `fullRead` verdict — not the shape of `rows` — decides whether this serve also
|
|
115
|
+
* performs the full-read effects (clearing retired anchors and hazard cards, overwriting the whole
|
|
116
|
+
* canon array); everything else here belongs to every serve alike (ADR-0035).
|
|
96
117
|
*/
|
|
97
|
-
export declare function recordServed(sessionKey: string, path: string, rows: ServedEntry[], lineCount?: number, full?:
|
|
118
|
+
export declare function recordServed(sessionKey: string, path: string, rows: ServedEntry[], lineCount?: number, full?: ServeContext): Promise<boolean>;
|
|
98
119
|
/**
|
|
99
120
|
* Record a truncated serve — the `served` row merge and the lease grant derived from it — as ONE
|
|
100
121
|
* unit, and report whether it landed.
|
|
@@ -109,7 +130,6 @@ export declare function driftReported(sessionKey: string, path: string): Promise
|
|
|
109
130
|
export declare function markDriftReported(sessionKey: string, path: string, hashes: string[]): Promise<void>;
|
|
110
131
|
export declare function clearDriftReported(sessionKey: string, path: string): Promise<void>;
|
|
111
132
|
export declare function wipeServedState(sessionKey: string): Promise<void>;
|
|
112
|
-
export declare function servedPositionsOf(served: (string | null)[], hash: string): number[];
|
|
113
133
|
export declare function currentPositionOfDrifted(served: (string | null)[], currentPositions: Map<string, number>, surviving: Set<string>, servedIndex: number, delta: number): number;
|
|
114
134
|
export declare const DRIFT_NOTICE_HEADING = "[USER] drift:";
|
|
115
135
|
/**
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Store —
|
|
2
|
+
* Store — seam VIEW over tenancy + lifecycle + path resolution.
|
|
3
3
|
*
|
|
4
|
-
* Single seam that answers "which store, where, and is it open?"
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* Single seam that answers "which store, where, and is it open?" for its
|
|
5
|
+
* consumers. This file owns no behaviour: every export below is a re-export
|
|
6
|
+
* of code owned by a leaf module.
|
|
7
|
+
*
|
|
8
|
+
* Ownership direction, stated once and not to be inverted:
|
|
9
|
+
* `store-config` → `store-tenancy` → this barrel, and `hash-store` → this
|
|
10
|
+
* barrel. The leaves hold the code — `store-tenancy` resolves where the DB
|
|
11
|
+
* lives and imports `loadConfig` FROM `store-config`, which resolves its own
|
|
12
|
+
* path through `resolveDshHome` — while this file is the view they surface
|
|
13
|
+
* through.
|
|
10
14
|
*
|
|
11
15
|
* YAGNI-gated: DB plumbing (openDb/buildStore/quarantine/busy-retry/
|
|
12
16
|
* WAL/legacy JSON migration) stays in hash-store for now and is
|
|
13
17
|
* re-exported here for testability without importing domain helpers
|
|
14
|
-
* — full plumbing move is deferred to avoid contract risk.
|
|
15
|
-
* store-tenancy/store-lifecycle files are kept as compat shims
|
|
16
|
-
* re-exporting from this seam (reversible).
|
|
18
|
+
* — full plumbing move is deferred to avoid contract risk.
|
|
17
19
|
*
|
|
18
20
|
* @module dsh-better-edit/store
|
|
19
21
|
*/
|
|
20
22
|
export { tenancyFor, configDir, hashStorePath, hashStoreDir, legacyHashStorePath, loadConfig, _resetConfigCache, expand, } from "../store-tenancy.js";
|
|
21
23
|
export type { Tenancy, StoreConfig } from "../store-tenancy.js";
|
|
22
24
|
export { onStoreOpen, onAppStart, onSessionStart, setStoresGetter, runCentralJanitorIfDue, _resetLifecycleForTests, } from "../store-lifecycle.js";
|
|
23
|
-
export { loadConfig as loadStoreConfig } from "../store-config.js";
|
|
24
25
|
export { isCorruptionError, loadHashStore, shutdownHashStore, withStore, findSnapshotPathsByHashes, upsertSnapshotFor, } from "../hash-store.js";
|
|
25
26
|
export type { HashStore, InternalHashStore, ServedPersistence } from "../hash-store.js";
|
|
@@ -12,7 +12,7 @@ declare const StoreConfigSchema: z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>;
|
|
13
13
|
export type StoreConfig = z.infer<typeof StoreConfigSchema>;
|
|
14
14
|
/** Default config.yaml content with comments — generated when the file does not exist. */
|
|
15
|
-
export declare const DEFAULT_CONFIG_YAML
|
|
15
|
+
export declare const DEFAULT_CONFIG_YAML: string;
|
|
16
16
|
/**
|
|
17
17
|
* Ensure a default config.yaml exists in the plugin home.
|
|
18
18
|
* Idempotent and concurrent-safe (wx) — never overwrites an existing file.
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VacuumResult } from "./snapshot-store/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The store face `onStoreOpen` calls, typed structurally: the handle is a leaf here, and
|
|
4
|
+
* importing the store's own type re-closes the `hash-store ↔ store-lifecycle` cycle.
|
|
5
|
+
*/
|
|
6
|
+
interface OpenStoreFace {
|
|
7
|
+
pruneUndoOlderThan(ts: number): void;
|
|
8
|
+
pruneMissing(): Promise<void>;
|
|
9
|
+
vacuumSnapshots(): VacuumResult;
|
|
10
|
+
}
|
|
2
11
|
export declare function setStoresGetter(getS: () => Map<string, {
|
|
3
12
|
path: string;
|
|
4
13
|
}>, getO: () => Map<string, Promise<any>>): void;
|
|
5
14
|
export declare function runCentralJanitorIfDue(): Promise<void>;
|
|
6
15
|
export declare function onStoreOpen(storePath: string, stmts: {
|
|
7
16
|
servedPruneOlderThan: (ts: number) => void;
|
|
8
|
-
}, store:
|
|
17
|
+
}, store: OpenStoreFace): Promise<void>;
|
|
9
18
|
export declare function onAppStart(): Promise<void>;
|
|
10
19
|
export declare function onSessionStart(): Promise<void>;
|
|
11
20
|
export declare function _resetLifecycleForTests(): void;
|
|
21
|
+
export {};
|
package/lib/types/tool-edit.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* single-file atomic batch; the file is named explicitly, never inferred (#117).
|
|
6
6
|
* @module dsh-better-edit/tool-edit
|
|
7
7
|
*/
|
|
8
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
9
8
|
import type { FileIO } from "./fs-bridge.js";
|
|
10
9
|
import type { FsSandboxController } from "./sandbox.js";
|
|
11
10
|
export declare function buildEditTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
12
|
-
export declare function registerEditTool(_rootCtx: Context, agentCtx: Context, io: FileIO, sandbox: FsSandboxController): () => void;
|
package/lib/types/tool-read.d.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* shown the lines it targets.
|
|
6
6
|
* @module dsh-better-edit/tool-read
|
|
7
7
|
*/
|
|
8
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
9
8
|
import type { FileIO } from "./fs-bridge.js";
|
|
10
9
|
/**
|
|
11
10
|
* Register the hash-anchored `read` tool on the calling agent's scope.
|
|
@@ -15,7 +14,3 @@ import type { FileIO } from "./fs-bridge.js";
|
|
|
15
14
|
* @returns the exact disposer that unregisters the tool.
|
|
16
15
|
*/
|
|
17
16
|
export declare function buildReadTool(io: FileIO): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
18
|
-
/**
|
|
19
|
-
* Register the hashline tool on the calling agent’s scope (own layer).
|
|
20
|
-
*/
|
|
21
|
-
export declare function registerReadTool(_rootCtx: Context, agentCtx: Context, io: FileIO): () => void;
|
|
@@ -25,9 +25,3 @@ import type { FsSandboxController } from "./sandbox.js";
|
|
|
25
25
|
import type { FileIO } from "./fs-bridge.js";
|
|
26
26
|
export declare const STR_REPLACE_EDITOR_DESCRIPTION: string;
|
|
27
27
|
export declare function buildStrReplaceEditorTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
28
|
-
/** Register the shadow `str_replace_editor` on the calling agent's scope (own layer). */
|
|
29
|
-
export declare function registerStrReplaceEditorTool(agentCtx: {
|
|
30
|
-
tools: {
|
|
31
|
-
register(def: unknown): () => void;
|
|
32
|
-
};
|
|
33
|
-
}, io: FileIO, sandbox: FsSandboxController): () => void;
|
package/lib/types/tool-undo.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* external write clears the history instead of being overwritten.
|
|
5
5
|
* @module dsh-better-edit/tool-undo
|
|
6
6
|
*/
|
|
7
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
8
7
|
import type { FileIO } from "./fs-bridge.js";
|
|
9
8
|
import type { FsSandboxController } from "./sandbox.js";
|
|
10
9
|
/**
|
|
@@ -15,7 +14,3 @@ import type { FsSandboxController } from "./sandbox.js";
|
|
|
15
14
|
* @returns the exact disposer that unregisters the tool.
|
|
16
15
|
*/
|
|
17
16
|
export declare function buildUndoTool(io: FileIO, sandbox: FsSandboxController): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
18
|
-
/**
|
|
19
|
-
* Register the hashline tool on the calling agent’s scope (own layer).
|
|
20
|
-
*/
|
|
21
|
-
export declare function registerUndoTool(_rootCtx: Context, agentCtx: Context, io: FileIO, sandbox: FsSandboxController): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Hash-anchored read/edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anchors",
|
|
@@ -94,7 +94,8 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
|
-
"build": "tsc -p tsconfig.json",
|
|
97
|
+
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
98
|
+
"clean": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
98
99
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
99
100
|
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
100
101
|
"test": "vitest run",
|
package/lib/drift.js
DELETED
package/lib/dsh-context.js
DELETED
package/lib/edit-engine.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated — private to Mutation seam. Use `from "./mutation/engine.js"` instead.
|
|
3
|
-
* Thin shim re-exporting the engine now owned by Mutation.
|
|
4
|
-
* @module dsh-better-edit/edit-engine
|
|
5
|
-
*/
|
|
6
|
-
export * from "./mutation/engine.js";
|
|
7
|
-
export { persistUndoAndWrite, commit, commitSingle, commitBatch } from "./mutation.js";
|
package/lib/edit-normalize.js
DELETED
package/lib/edit-pipeline.js
DELETED
package/lib/file-kind.js
DELETED
package/lib/file-reader.js
DELETED
package/lib/guidance/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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";
|
package/lib/hashline/alphabet.js
DELETED
package/lib/hashline/apply.js
DELETED
package/lib/hashline/hasher.js
DELETED
package/lib/hashline/parse.js
DELETED
package/lib/hashline/pure.js
DELETED
package/lib/hashline/resolve.js
DELETED
package/lib/hashline/served.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debounced preview controller — extracted from buildToolDef so hashline seams
|
|
3
|
-
* stay pure and the debounce invariant is testable.
|
|
4
|
-
* @module dsh-better-edit/preview-controller
|
|
5
|
-
*/
|
|
6
|
-
export const PREVIEW_DEBOUNCE_MS = 150;
|
|
7
|
-
export function getPreviewInput(_args) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
export class DebouncedPreview {
|
|
11
|
-
compute;
|
|
12
|
-
debounceMs;
|
|
13
|
-
constructor(compute, debounceMs = PREVIEW_DEBOUNCE_MS) {
|
|
14
|
-
this.compute = compute;
|
|
15
|
-
this.debounceMs = debounceMs;
|
|
16
|
-
}
|
|
17
|
-
renderCall(host, args) {
|
|
18
|
-
const { state } = host;
|
|
19
|
-
const previewInput = getPreviewInput(args);
|
|
20
|
-
if (host.executionStarted || !host.argsComplete || !previewInput) {
|
|
21
|
-
this.cancel(state);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const argsKey = JSON.stringify(previewInput);
|
|
25
|
-
if (state.argsKey === argsKey)
|
|
26
|
-
return;
|
|
27
|
-
this.cancel(state);
|
|
28
|
-
state.argsKey = argsKey;
|
|
29
|
-
const previewGeneration = (state.previewGeneration ?? 0) + 1;
|
|
30
|
-
state.previewGeneration = previewGeneration;
|
|
31
|
-
state.previewTimer = setTimeout(() => {
|
|
32
|
-
state.previewTimer = undefined;
|
|
33
|
-
this.compute(args, host.cwd)
|
|
34
|
-
.then((preview) => {
|
|
35
|
-
if (state.argsKey === argsKey && state.previewGeneration === previewGeneration) {
|
|
36
|
-
state.preview = preview;
|
|
37
|
-
host.invalidate();
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
.catch((err) => {
|
|
41
|
-
if (state.argsKey === argsKey && state.previewGeneration === previewGeneration) {
|
|
42
|
-
state.preview = { error: err instanceof Error ? err.message : String(err) };
|
|
43
|
-
host.invalidate();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}, this.debounceMs);
|
|
47
|
-
}
|
|
48
|
-
cancel(state) {
|
|
49
|
-
if (state.previewTimer) {
|
|
50
|
-
clearTimeout(state.previewTimer);
|
|
51
|
-
state.previewTimer = undefined;
|
|
52
|
-
}
|
|
53
|
-
state.argsKey = undefined;
|
|
54
|
-
state.preview = undefined;
|
|
55
|
-
state.previewGeneration = (state.previewGeneration ?? 0) + 1;
|
|
56
|
-
}
|
|
57
|
-
clearResult(state) {
|
|
58
|
-
if (state.previewTimer) {
|
|
59
|
-
clearTimeout(state.previewTimer);
|
|
60
|
-
state.previewTimer = undefined;
|
|
61
|
-
}
|
|
62
|
-
state.preview = undefined;
|
|
63
|
-
state.previewGeneration = (state.previewGeneration ?? 0) + 1;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/lib/read-render.js
DELETED
package/lib/schema.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared model-facing parameter schemas for the hashline tools, expressed in
|
|
3
|
-
* the dsh schema DSL (not TypeBox). `path` is deliberately NOT `required` at
|
|
4
|
-
* the schema level: the tools accept the built-in `file_path` spelling too
|
|
5
|
-
* (the implicit parameter root stays open), and enforce path presence in
|
|
6
|
-
* `assertEditRequest` after `normalizeFilePath` aliasing.
|
|
7
|
-
* @module dsh-better-edit/schema
|
|
8
|
-
*/
|
|
9
|
-
export const replacementTextSchema = {
|
|
10
|
-
type: 'string',
|
|
11
|
-
description: 'Replacement text as a single string with \\n line separators; every \\n separates lines, so a trailing \\n adds a final empty line. Mirror the removed lines exactly, blank lines included. A replacement that is only blank lines is written as one \\n per blank line. Use "" to delete the range.',
|
|
12
|
-
};
|
|
13
|
-
export const removeFromSchema = {
|
|
14
|
-
type: 'string',
|
|
15
|
-
description: 'Bare 3-char HASH only (e.g. "aB3") — copy just the hash from the leftmost column of a read row like `aB3│content`; never the line content. Marks the FIRST line to remove (inclusive)',
|
|
16
|
-
};
|
|
17
|
-
export const removeToSchema = {
|
|
18
|
-
type: 'string',
|
|
19
|
-
description: 'Bare 3-char HASH only (e.g. "aB3") — copy just the hash from the leftmost column of a read row like `aB3│content`; never the line content. Marks the LAST line to remove (inclusive)',
|
|
20
|
-
};
|
|
21
|
-
export const pathSchema = {
|
|
22
|
-
type: 'string',
|
|
23
|
-
description: 'Path to edit. Required — always provide it explicitly; it is only auto-resolved from the anchors as a fallback when omitted by mistake.',
|
|
24
|
-
};
|