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
package/lib/tool-undo.js
CHANGED
|
@@ -8,15 +8,16 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
|
8
8
|
import { toLF, stripBOM, genDiff, restoreEndings } from "./edit-diff.js";
|
|
9
9
|
import { cntDiff, splitLines } from "./utils.js";
|
|
10
10
|
import { assertUndoRequest } from "./contract.js";
|
|
11
|
-
import { normReq } from "./
|
|
11
|
+
import { normalizeRequest as normReq } from "./contract.js";
|
|
12
12
|
import { upsertSnapshotFor } from "./hash-store.js";
|
|
13
|
-
import { contentChecksum } from "./hashline/
|
|
14
|
-
import { lineHashes
|
|
13
|
+
import { contentChecksum } from "./hashline/hash-assign.js";
|
|
14
|
+
import { lineHashes } from "./hashline/hash.js";
|
|
15
|
+
import { changedRange } from "./hashline/anchor-pipeline.js";
|
|
15
16
|
import { getUndo, clearUndo } from "./undo-edit.js";
|
|
16
|
-
import { recordServedTruncated } from "./
|
|
17
|
+
import { recordServedTruncated } from "./session-view.js";
|
|
17
18
|
import { UNDO_DESCRIPTION } from "./prompts.js";
|
|
18
|
-
import { execCwd, execSessionKey } from "./
|
|
19
|
-
import { withWorkspace } from "./
|
|
19
|
+
import { execCwd, execSessionKey } from "./session-view.js";
|
|
20
|
+
import { withWorkspace } from "./session-view.js";
|
|
20
21
|
/**
|
|
21
22
|
* Register the `undo_last_edit` tool on the calling agent's scope.
|
|
22
23
|
* @param _rootCtx - host context.
|
|
@@ -49,6 +50,7 @@ export function buildUndoTool(io, sandbox) {
|
|
|
49
50
|
assertUndoRequest(canonical);
|
|
50
51
|
const path = canonical.path;
|
|
51
52
|
const absolutePath = await io.resolve(path, cwd, signal);
|
|
53
|
+
// SAFETY: canonical validated by assertUndoRequest; shape is compatible with FsEscalationArgs (path + optional sandbox fields) — narrowing for sandbox.resolvePolicy
|
|
52
54
|
const sandboxPolicy = await sandbox.resolvePolicy("undo_last_edit", canonical, exec);
|
|
53
55
|
const undo = await getUndo(absolutePath);
|
|
54
56
|
if (!undo) {
|
|
@@ -62,14 +64,14 @@ export function buildUndoTool(io, sandbox) {
|
|
|
62
64
|
const message = error instanceof Error ? error.message : String(error);
|
|
63
65
|
if (message.includes("[E_NOT_FOUND]")) {
|
|
64
66
|
await clearUndo(absolutePath);
|
|
65
|
-
return `[E_UNDO_STALE]
|
|
67
|
+
return `[E_UNDO_STALE] cannot undo on ${path}: file no longer exists.`;
|
|
66
68
|
}
|
|
67
69
|
throw error;
|
|
68
70
|
}
|
|
69
71
|
if (currentRaw !==
|
|
70
72
|
undo.bom + restoreEndings(undo.resultContent, undo.originalEnding)) {
|
|
71
73
|
await clearUndo(absolutePath);
|
|
72
|
-
return `[E_UNDO_STALE]
|
|
74
|
+
return `[E_UNDO_STALE] cannot undo on ${path}: file modified after edit — undo would overwrite changes.`;
|
|
73
75
|
}
|
|
74
76
|
const { text: currentStripped } = stripBOM(currentRaw);
|
|
75
77
|
const currentNormalized = toLF(currentStripped);
|
|
@@ -79,6 +81,10 @@ export function buildUndoTool(io, sandbox) {
|
|
|
79
81
|
const linesRemovedByEdit = cntDiff(diffResult.diff, "-");
|
|
80
82
|
const undoDiffResult = genDiff(currentNormalized, undo.content, 1, undo.hashes, currentHashes);
|
|
81
83
|
const undoDiff = undoDiffResult.diff;
|
|
84
|
+
const undoDenseRows = [];
|
|
85
|
+
for (let i = 0; i < undo.hashes.length; i++) {
|
|
86
|
+
undoDenseRows.push({ position: i, hash: undo.hashes[i] });
|
|
87
|
+
}
|
|
82
88
|
const restoredRange = changedRange(currentNormalized, undo.content);
|
|
83
89
|
try {
|
|
84
90
|
await io.writeText(absolutePath, undo.bom + restoreEndings(undo.content, undo.originalEnding), signal, exec, sandboxPolicy);
|
|
@@ -98,8 +104,8 @@ export function buildUndoTool(io, sandbox) {
|
|
|
98
104
|
parts.push(`Removed ${linesAddedByEdit} line(s) that were added and restored ${linesRemovedByEdit} line(s) that were removed.`);
|
|
99
105
|
}
|
|
100
106
|
parts.push("File reverted to previous state. The post-edit diff rows carry the restored file\u2019s fresh anchors for follow-up edits.");
|
|
101
|
-
if (
|
|
102
|
-
await recordServedTruncated(sessionKey, absolutePath,
|
|
107
|
+
if (undoDenseRows.length > 0) {
|
|
108
|
+
await recordServedTruncated(sessionKey, absolutePath, undoDenseRows, splitLines(undo.content).length, restoredRange?.firstChangedLine ?? undoDiffResult.firstChangedLine ?? 0);
|
|
103
109
|
}
|
|
104
110
|
return [parts.join("\n"), "", "Diff of the revert:", "", undoDiff].join("\n");
|
|
105
111
|
});
|
package/lib/truncate.js
CHANGED
|
@@ -1,98 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* never emitting partial lines.
|
|
2
|
+
* @deprecated — private to FileView seam. Use `from "./file-view.js"` instead.
|
|
3
|
+
* Thin shim re-exporting the read path now owned by FileView.
|
|
5
4
|
* @module dsh-better-edit/truncate
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
export const DEFAULT_MAX_BYTES = 50 * 1024;
|
|
9
|
-
function splitLinesForCounting(content) {
|
|
10
|
-
if (content.length === 0)
|
|
11
|
-
return [];
|
|
12
|
-
const lines = content.split('\n');
|
|
13
|
-
if (content.endsWith('\n'))
|
|
14
|
-
lines.pop();
|
|
15
|
-
return lines;
|
|
16
|
-
}
|
|
17
|
-
/** Format bytes as a human-readable size. */
|
|
18
|
-
export function formatSize(bytes) {
|
|
19
|
-
if (bytes < 1024)
|
|
20
|
-
return `${bytes}B`;
|
|
21
|
-
if (bytes < 1024 * 1024)
|
|
22
|
-
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
23
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Truncate content from the head (keep the first N lines/bytes). Suitable for
|
|
27
|
-
* file reads; never returns partial lines. When the first line alone exceeds
|
|
28
|
-
* the byte limit the content is emptied with `firstLineExceedsLimit`.
|
|
29
|
-
*/
|
|
30
|
-
export function truncateHead(content, options = {}) {
|
|
31
|
-
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
32
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
33
|
-
const totalBytes = Buffer.byteLength(content, 'utf-8');
|
|
34
|
-
const lines = splitLinesForCounting(content);
|
|
35
|
-
const totalLines = lines.length;
|
|
36
|
-
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
37
|
-
return {
|
|
38
|
-
content,
|
|
39
|
-
truncated: false,
|
|
40
|
-
truncatedBy: null,
|
|
41
|
-
totalLines,
|
|
42
|
-
totalBytes,
|
|
43
|
-
outputLines: totalLines,
|
|
44
|
-
outputBytes: totalBytes,
|
|
45
|
-
lastLinePartial: false,
|
|
46
|
-
firstLineExceedsLimit: false,
|
|
47
|
-
maxLines,
|
|
48
|
-
maxBytes,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
const firstLineBytes = Buffer.byteLength(lines[0] ?? '', 'utf-8');
|
|
52
|
-
if (firstLineBytes > maxBytes) {
|
|
53
|
-
return {
|
|
54
|
-
content: '',
|
|
55
|
-
truncated: true,
|
|
56
|
-
truncatedBy: 'bytes',
|
|
57
|
-
totalLines,
|
|
58
|
-
totalBytes,
|
|
59
|
-
outputLines: 0,
|
|
60
|
-
outputBytes: 0,
|
|
61
|
-
lastLinePartial: false,
|
|
62
|
-
firstLineExceedsLimit: true,
|
|
63
|
-
maxLines,
|
|
64
|
-
maxBytes,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const outputLinesArr = [];
|
|
68
|
-
let outputBytesCount = 0;
|
|
69
|
-
let truncatedBy = 'lines';
|
|
70
|
-
for (let i = 0; i < lines.length && i < maxLines; i++) {
|
|
71
|
-
const line = lines[i];
|
|
72
|
-
const lineBytes = Buffer.byteLength(line, 'utf-8') + (i > 0 ? 1 : 0);
|
|
73
|
-
if (outputBytesCount + lineBytes > maxBytes) {
|
|
74
|
-
truncatedBy = 'bytes';
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
outputLinesArr.push(line);
|
|
78
|
-
outputBytesCount += lineBytes;
|
|
79
|
-
}
|
|
80
|
-
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
81
|
-
truncatedBy = 'lines';
|
|
82
|
-
}
|
|
83
|
-
const outputContent = outputLinesArr.join('\n');
|
|
84
|
-
const finalOutputBytes = Buffer.byteLength(outputContent, 'utf-8');
|
|
85
|
-
return {
|
|
86
|
-
content: outputContent,
|
|
87
|
-
truncated: true,
|
|
88
|
-
truncatedBy,
|
|
89
|
-
totalLines,
|
|
90
|
-
totalBytes,
|
|
91
|
-
outputLines: outputLinesArr.length,
|
|
92
|
-
outputBytes: finalOutputBytes,
|
|
93
|
-
lastLinePartial: false,
|
|
94
|
-
firstLineExceedsLimit: false,
|
|
95
|
-
maxLines,
|
|
96
|
-
maxBytes,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
6
|
+
export * from "./file-view.js";
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare const MAX_BYTES: number;
|
|
|
4
4
|
export declare const MAX_READ_LINE_BYTES: number;
|
|
5
5
|
export declare const HASH_STORE_BUSY_TIMEOUT = 1000;
|
|
6
6
|
export declare const HASH_STORE_VERSION = 6;
|
|
7
|
+
export declare const EDITS_MAX_ITEMS = 32;
|
|
8
|
+
/** @deprecated batch_edit seam removed (ADR-0003) — use EDITS_MAX_ITEMS */
|
|
7
9
|
export declare const BATCH_EDIT_MAX_ITEMS = 32;
|
|
8
10
|
export declare const SERVED_TTL_MS: number;
|
|
9
11
|
export declare const SERVED_ECHO_CAP = 150;
|
package/lib/types/contract.d.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One module owns the request shapes for the hashline tools — edit,
|
|
3
|
-
*
|
|
3
|
+
* read, undo_last_edit — plus their validation. Field sets are
|
|
4
4
|
* declared once here; every tool validates through these asserts, and the
|
|
5
5
|
* [E_BAD_SHAPE] vocabulary is shared instead of re-implemented per tool.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* decoupled from the tool-layer request contract so the hashline module does
|
|
10
|
-
* not depend on this one.
|
|
7
|
+
* Contract now mirrors upstream ADR-0007: {path: string|null, edits: [[remove_from,remove_to,replacement_text],...]} tuple payload,
|
|
8
|
+
* single-file, atomic. batch_edit is removed.
|
|
11
9
|
* @module dsh-better-edit/contract
|
|
12
10
|
*/
|
|
13
|
-
export
|
|
14
|
-
path: string;
|
|
11
|
+
export type EditItem = {
|
|
15
12
|
remove_from: string;
|
|
16
13
|
remove_to: string;
|
|
17
14
|
replacement_text: string;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
20
|
-
path
|
|
15
|
+
};
|
|
16
|
+
export type EditRequest = {
|
|
17
|
+
path: string | null;
|
|
18
|
+
edits: EditItem[];
|
|
19
|
+
};
|
|
20
|
+
export interface EditParams {
|
|
21
|
+
path: string;
|
|
21
22
|
remove_from: string;
|
|
22
23
|
remove_to: string;
|
|
23
24
|
replacement_text: string;
|
|
24
25
|
}
|
|
25
|
-
export interface BatchEditParams {
|
|
26
|
-
edits: BatchItemParams[];
|
|
27
|
-
}
|
|
28
26
|
export interface ReadParams {
|
|
29
27
|
path: string;
|
|
30
28
|
offset?: number;
|
|
@@ -33,7 +31,114 @@ export interface ReadParams {
|
|
|
33
31
|
export interface UndoParams {
|
|
34
32
|
path: string;
|
|
35
33
|
}
|
|
36
|
-
export
|
|
37
|
-
|
|
34
|
+
export interface BatchItemParams {
|
|
35
|
+
path?: string;
|
|
36
|
+
remove_from: string;
|
|
37
|
+
remove_to: string;
|
|
38
|
+
replacement_text: string;
|
|
39
|
+
}
|
|
40
|
+
export interface BatchEditParams {
|
|
41
|
+
edits: BatchItemParams[];
|
|
42
|
+
}
|
|
43
|
+
export declare const normalizedEdit: unique symbol;
|
|
44
|
+
export type NormalizedEditRequest = EditRequest & {
|
|
45
|
+
[normalizedEdit]?: true;
|
|
46
|
+
};
|
|
47
|
+
export declare function isNormalizedEdit(input: unknown): input is NormalizedEditRequest;
|
|
48
|
+
export declare function itemFromTuple(value: unknown): EditItem | undefined;
|
|
49
|
+
export declare function editRequestFrom(input: unknown): NormalizedEditRequest | undefined;
|
|
50
|
+
export declare const EDIT_TUPLE_HINT: string;
|
|
51
|
+
/**
|
|
52
|
+
* Normalize `file_path` → `path` alias on the request record and tuple edits → objects.
|
|
53
|
+
* Returns the input unchanged when not a record; otherwise returns a shallow copy with
|
|
54
|
+
* the alias applied so callers never mutate the original `args` object.
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeRequest(input: unknown): unknown;
|
|
57
|
+
/** @deprecated use normalizeRequest — kept as alias for migration */
|
|
58
|
+
export declare const normReq: typeof normalizeRequest;
|
|
59
|
+
export declare function prepareEditArguments(args: unknown): Record<string, unknown>;
|
|
60
|
+
export declare function assertEditRequest(request: unknown): asserts request is NormalizedEditRequest;
|
|
61
|
+
export declare function assertBatchEditRequest(_request: unknown): asserts _request is BatchEditParams;
|
|
38
62
|
export declare function assertReadRequest(request: unknown): asserts request is ReadParams;
|
|
39
63
|
export declare function assertUndoRequest(request: unknown): asserts request is UndoParams;
|
|
64
|
+
export declare const replacementTextSchema: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
readonly description: "Complete replacement for the range; use \"\" to delete";
|
|
67
|
+
};
|
|
68
|
+
export declare const removeFromSchema: {
|
|
69
|
+
readonly type: "string";
|
|
70
|
+
readonly description: "First line to remove (inclusive)";
|
|
71
|
+
};
|
|
72
|
+
export declare const removeToSchema: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
readonly description: "Last line to remove (inclusive)";
|
|
75
|
+
};
|
|
76
|
+
export declare const pathSchema: {
|
|
77
|
+
readonly type: "string";
|
|
78
|
+
readonly description: "File path; null infers it from anchors";
|
|
79
|
+
};
|
|
80
|
+
export declare const editPathSchema: {
|
|
81
|
+
readonly anyOf: readonly [{
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
readonly minLength: 1;
|
|
84
|
+
readonly description: "File path; null infers it from anchors";
|
|
85
|
+
}, {
|
|
86
|
+
readonly type: "null";
|
|
87
|
+
readonly description: "null infers path from anchors";
|
|
88
|
+
}];
|
|
89
|
+
};
|
|
90
|
+
export declare const editTupleSchema: {
|
|
91
|
+
readonly type: "array";
|
|
92
|
+
readonly prefixItems: readonly [{
|
|
93
|
+
readonly type: "string";
|
|
94
|
+
readonly description: "First line to remove (inclusive)";
|
|
95
|
+
}, {
|
|
96
|
+
readonly type: "string";
|
|
97
|
+
readonly description: "Last line to remove (inclusive)";
|
|
98
|
+
}, {
|
|
99
|
+
readonly type: "string";
|
|
100
|
+
readonly description: "Complete replacement for the range; use \"\" to delete";
|
|
101
|
+
}];
|
|
102
|
+
readonly minItems: 3;
|
|
103
|
+
readonly maxItems: 3;
|
|
104
|
+
readonly description: "[remove_from, remove_to, replacement_text]";
|
|
105
|
+
};
|
|
106
|
+
export declare const editToolSchema: {
|
|
107
|
+
readonly type: "object";
|
|
108
|
+
readonly additionalProperties: false;
|
|
109
|
+
readonly required: readonly ["path", "edits"];
|
|
110
|
+
readonly properties: {
|
|
111
|
+
readonly path: {
|
|
112
|
+
readonly anyOf: readonly [{
|
|
113
|
+
readonly type: "string";
|
|
114
|
+
readonly minLength: 1;
|
|
115
|
+
readonly description: "File path; null infers it from anchors";
|
|
116
|
+
}, {
|
|
117
|
+
readonly type: "null";
|
|
118
|
+
readonly description: "null infers path from anchors";
|
|
119
|
+
}];
|
|
120
|
+
};
|
|
121
|
+
readonly edits: {
|
|
122
|
+
readonly type: "array";
|
|
123
|
+
readonly description: "Ordered list of edit tuples";
|
|
124
|
+
readonly minItems: 1;
|
|
125
|
+
readonly maxItems: 32;
|
|
126
|
+
readonly items: {
|
|
127
|
+
readonly type: "array";
|
|
128
|
+
readonly prefixItems: readonly [{
|
|
129
|
+
readonly type: "string";
|
|
130
|
+
readonly description: "First line to remove (inclusive)";
|
|
131
|
+
}, {
|
|
132
|
+
readonly type: "string";
|
|
133
|
+
readonly description: "Last line to remove (inclusive)";
|
|
134
|
+
}, {
|
|
135
|
+
readonly type: "string";
|
|
136
|
+
readonly description: "Complete replacement for the range; use \"\" to delete";
|
|
137
|
+
}];
|
|
138
|
+
readonly minItems: 3;
|
|
139
|
+
readonly maxItems: 3;
|
|
140
|
+
readonly description: "[remove_from, remove_to, replacement_text]";
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
package/lib/types/drift.d.ts
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export interface ComputeDriftInput {
|
|
8
|
-
served: (string | null)[];
|
|
9
|
-
resultHashes: string[];
|
|
10
|
-
resultLines: string[];
|
|
11
|
-
range: ResolvedRange;
|
|
12
|
-
reported: Set<string>;
|
|
13
|
-
cap?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface DriftNoticeResult {
|
|
16
|
-
text: string;
|
|
17
|
-
rows: DriftRow[];
|
|
18
|
-
total: number;
|
|
19
|
-
allAlreadyReported: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function computeDrift(input: ComputeDriftInput): DriftNoticeResult | undefined;
|
|
22
|
-
export declare function scanDrift(input: {
|
|
23
|
-
sessionKey: string;
|
|
24
|
-
served: (string | null)[];
|
|
25
|
-
resultHashes: string[];
|
|
26
|
-
resultLines: string[];
|
|
27
|
-
range: ResolvedRange;
|
|
28
|
-
path: string;
|
|
29
|
-
}): Promise<string | undefined>;
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated — private to SessionView seam. Use `from "./session-view.js"` instead.
|
|
3
|
+
* @module dsh-better-edit/drift
|
|
4
|
+
*/
|
|
5
|
+
export * from "./session-view.js";
|
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* served-state session key derived from the dsh {@link ToolExecution}.
|
|
2
|
+
* @deprecated — private to SessionView seam. Use `from "./session-view.js"` instead.
|
|
4
3
|
* @module dsh-better-edit/dsh-context
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The workspace directory a model-facing filesystem tool resolves relative
|
|
9
|
-
* paths against: the calling agent's per-session cwd (each session's tools act
|
|
10
|
-
* on ITS workspace), falling back to the process cwd for non-agent callers.
|
|
11
|
-
* Mirrors how `dsh-tool-bash` defaults a bash `workdir` to the session cwd.
|
|
12
|
-
* @param exec - the tool-execution context; only its optional `agent` is read.
|
|
13
|
-
* @returns the session cwd, or the process cwd when no agent applies.
|
|
14
|
-
*/
|
|
15
|
-
export declare function execCwd(exec: ToolExecution): string;
|
|
16
|
-
/**
|
|
17
|
-
* The served-state session key for one execution: the live session id. A
|
|
18
|
-
* stable key per session keeps served rows (what the model was shown) and
|
|
19
|
-
* undo history correctly scoped — never shared across sessions.
|
|
20
|
-
* @param exec - the tool-execution context.
|
|
21
|
-
* @returns the session key.
|
|
22
|
-
*/
|
|
23
|
-
export declare function execSessionKey(exec: ToolExecution): string;
|
|
5
|
+
export * from "./session-view.js";
|
|
@@ -15,8 +15,8 @@ import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
|
|
15
15
|
import type { FileIO } from "./fs-bridge.js";
|
|
16
16
|
import type { HashStore } from "./hash-store.js";
|
|
17
17
|
import type { LineEnding } from "./edit-diff.js";
|
|
18
|
-
import { type HEdit, type NEdit } from "./hashline/
|
|
19
|
-
import { type ResolvedRange, type ServeRecordPolicy, type ServedRow } from "./hashline/
|
|
18
|
+
import { type HEdit, type NEdit } from "./hashline/anchor-pipeline.js";
|
|
19
|
+
import { type ResolvedRange, type ServeRecordPolicy, type ServedRow } from "./hashline/anchor-pipeline.js";
|
|
20
20
|
import type { FsSandboxController } from "./sandbox.js";
|
|
21
21
|
export interface PreparedItem {
|
|
22
22
|
index: number;
|
|
@@ -1,47 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* served state → apply → re-hash with stable anchors → drift notice. The
|
|
5
|
-
* apply/reject/re-hash computation lives in the edit engine
|
|
6
|
-
* ({@link edit-engine}); this module keeps the single-edit orchestration
|
|
7
|
-
* shape, preview-mode options, and the pipeline result type. All IO goes
|
|
8
|
-
* through the {@link FileIO} bridge so the same pipeline runs on `ctx.fs` and
|
|
9
|
-
* on the host filesystem.
|
|
2
|
+
* @deprecated — private to Mutation seam. Use `from "./mutation.js"` instead.
|
|
3
|
+
* Thin shim re-exporting the pipeline now owned by Mutation.
|
|
10
4
|
* @module dsh-better-edit/edit-pipeline
|
|
11
5
|
*/
|
|
12
|
-
|
|
13
|
-
import type { FileIO } from './fs-bridge.js';
|
|
14
|
-
import type { LineEnding } from './edit-diff.js';
|
|
15
|
-
import { type NEdit } from './hashline/index.js';
|
|
16
|
-
import type { ResolvedRange } from './hashline/served.js';
|
|
17
|
-
import type { EditParams } from './contract.js';
|
|
18
|
-
export interface PipelineResult {
|
|
19
|
-
path: string;
|
|
20
|
-
absolutePath: string;
|
|
21
|
-
originalNormalized: string;
|
|
22
|
-
result: string;
|
|
23
|
-
bom: string;
|
|
24
|
-
originalEnding: LineEnding;
|
|
25
|
-
hadUtf8DecodeErrors: boolean;
|
|
26
|
-
warnings: string[];
|
|
27
|
-
noopEdit?: NEdit;
|
|
28
|
-
firstChangedLine?: number;
|
|
29
|
-
lastChangedLine?: number;
|
|
30
|
-
originalHashes: string[];
|
|
31
|
-
resultHashes: string[];
|
|
32
|
-
totalAddedLines: number;
|
|
33
|
-
totalRemovedLines: number;
|
|
34
|
-
driftNotice?: string;
|
|
35
|
-
range: ResolvedRange;
|
|
36
|
-
}
|
|
37
|
-
export interface ExecPipelineOptions {
|
|
38
|
-
signal?: AbortSignal;
|
|
39
|
-
store?: HashStore;
|
|
40
|
-
noPersist?: boolean;
|
|
41
|
-
sessionKey?: string;
|
|
42
|
-
}
|
|
43
|
-
export declare function execPipeline(io: FileIO, params: EditParams, cwd: string, options?: ExecPipelineOptions): Promise<PipelineResult>;
|
|
44
|
-
/** Resolve the display path a caller names against the session cwd. */
|
|
45
|
-
export declare function resolveDisplayPath(path: string, cwd: string): string;
|
|
46
|
-
/** Snapshot bookkeeping for noop/success results (best-effort). */
|
|
47
|
-
export declare function snapshotIdFor(io: FileIO, absolutePath: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
6
|
+
export * from "./mutation.js";
|
package/lib/types/file-kind.d.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
kind: "text";
|
|
8
|
-
text: string;
|
|
9
|
-
hadUtf8DecodeErrors?: true;
|
|
10
|
-
} | {
|
|
11
|
-
kind: "binary";
|
|
12
|
-
description: string;
|
|
13
|
-
};
|
|
14
|
-
export interface LoadFileOptions {
|
|
15
|
-
maxLines?: number;
|
|
16
|
-
displayPath?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function loadFileKindAndText(filePath: string, options?: LoadFileOptions): Promise<LFile>;
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated — private to FileView seam. Use `from "./file-view.js"` instead.
|
|
3
|
+
* Thin shim re-exporting the read path now owned by FileView.
|
|
4
|
+
* @module dsh-better-edit/file-kind
|
|
5
|
+
*/
|
|
6
|
+
export * from "./file-view.js";
|
|
@@ -1,47 +1,6 @@
|
|
|
1
|
-
import { type LFile } from "./file-kind.js";
|
|
2
|
-
import { type LineEnding } from "./edit-diff.js";
|
|
3
|
-
import type { HashStore } from "./hash-store.js";
|
|
4
|
-
export interface NormFile {
|
|
5
|
-
absolutePath: string;
|
|
6
|
-
normalized: string;
|
|
7
|
-
bom: string;
|
|
8
|
-
originalEnding: LineEnding;
|
|
9
|
-
fileHashes: string[];
|
|
10
|
-
hadUtf8DecodeErrors: boolean;
|
|
11
|
-
}
|
|
12
|
-
export type SnapInfo = {
|
|
13
|
-
snapshotId: string;
|
|
14
|
-
ino: number;
|
|
15
|
-
mtimeMs: number;
|
|
16
|
-
ctimeMs: number;
|
|
17
|
-
size: number;
|
|
18
|
-
};
|
|
19
|
-
export declare function fileSnap(absolutePath: string): Promise<SnapInfo>;
|
|
20
|
-
export interface ReadNormOptions {
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
accessMode?: number;
|
|
23
|
-
preloadedFile?: LFile;
|
|
24
|
-
maxLines?: number;
|
|
25
|
-
store?: HashStore;
|
|
26
|
-
noPersist?: boolean;
|
|
27
|
-
}
|
|
28
1
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* This is the string-level core of the read/edit pipeline; the caller owns
|
|
34
|
-
* path resolution and raw IO (local filesystem, `ctx.fs`, or a sandbox
|
|
35
|
-
* backend) so the same anchors are produced no matter where the file lives.
|
|
2
|
+
* @deprecated — private to FileView seam. Use `from "./file-view.js"` instead.
|
|
3
|
+
* Thin shim re-exporting the read path now owned by FileView.
|
|
4
|
+
* @module dsh-better-edit/file-reader
|
|
36
5
|
*/
|
|
37
|
-
export
|
|
38
|
-
absolutePath: string;
|
|
39
|
-
rawText: string;
|
|
40
|
-
displayPath: string;
|
|
41
|
-
signal?: AbortSignal;
|
|
42
|
-
maxLines?: number;
|
|
43
|
-
store?: HashStore;
|
|
44
|
-
noPersist?: boolean;
|
|
45
|
-
hadUtf8DecodeErrors?: boolean;
|
|
46
|
-
}): Promise<NormFile>;
|
|
47
|
-
export declare function readNormFile(path: string, cwd: string, options?: ReadNormOptions): Promise<NormFile>;
|
|
6
|
+
export * from "./file-view.js";
|