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
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
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/validation
|
|
5
|
+
*/
|
|
6
|
+
export * from "./file-view.js";
|
package/lib/types/workspace.d.ts
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* with its own cwd, and only the tool execution knows which one it belongs to —
|
|
4
|
-
* so a module-global "current cwd" would race between parallel sessions. The
|
|
5
|
-
* store path is derived per tool call from the session cwd; this module carries
|
|
6
|
-
* that cwd through the async execution so every store access inside the call
|
|
7
|
-
* (served rows, undo, hash snapshots) lands in the right per-workspace store.
|
|
2
|
+
* @deprecated — private to SessionView seam. Use `from "./session-view.js"` instead.
|
|
8
3
|
* @module dsh-better-edit/workspace
|
|
9
4
|
*/
|
|
10
|
-
|
|
11
|
-
* Run `fn` with the given workspace cwd active for this async execution.
|
|
12
|
-
* Every `loadHashStore()` (and any store access) inside `fn` resolves the
|
|
13
|
-
* `<cwd>/.dsh_better_edit` store.
|
|
14
|
-
* @param cwd - the session workspace root (absolute).
|
|
15
|
-
* @param fn - the tool body.
|
|
16
|
-
* @returns the body's result.
|
|
17
|
-
*/
|
|
18
|
-
export declare function withWorkspace<T>(cwd: string, fn: () => Promise<T>): Promise<T>;
|
|
19
|
-
/**
|
|
20
|
-
* The workspace cwd active for this async execution, or undefined outside a
|
|
21
|
-
* tool call (tests, previews, startup) — callers fall back to the shared
|
|
22
|
-
* `$DSH_HOME` store then.
|
|
23
|
-
*/
|
|
24
|
-
export declare function workspaceCwd(): string | undefined;
|
|
5
|
+
export * from "./session-view.js";
|
package/lib/validation.js
CHANGED
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
const code = errCode(error);
|
|
10
|
-
if (code === "ENOENT") {
|
|
11
|
-
throw new Error(`[E_NOT_FOUND] File not found: ${path}`);
|
|
12
|
-
}
|
|
13
|
-
if (code === "EACCES" || code === "EPERM") {
|
|
14
|
-
const accessLabel = accessMode & constants.W_OK ? "not writable" : "not readable";
|
|
15
|
-
throw new Error(`[E_ACCESS] File is ${accessLabel}: ${path}`);
|
|
16
|
-
}
|
|
17
|
-
if (code === "ELOOP") {
|
|
18
|
-
throw new Error(`[E_ACCESS] Too many symbolic links while resolving: ${path}`);
|
|
19
|
-
}
|
|
20
|
-
throw new Error(`[E_ACCESS] Cannot access file: ${path}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export function valKind(file, path) {
|
|
24
|
-
if (file.kind === "directory") {
|
|
25
|
-
throw new Error(`[E_NOT_TEXT] Path is a directory: ${path}. Use ls to inspect directories.`);
|
|
26
|
-
}
|
|
27
|
-
if (file.kind === "binary") {
|
|
28
|
-
throw new Error(`[E_NOT_TEXT] Path is a binary file: ${path} (${file.description}). Hashline edit only supports text files.`);
|
|
29
|
-
}
|
|
30
|
-
if (file.kind === "image") {
|
|
31
|
-
throw new Error(`[E_NOT_TEXT] Path is an image file: ${path}. Hashline edit only supports text files.`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
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/validation
|
|
5
|
+
*/
|
|
6
|
+
export * from "./file-view.js";
|
package/lib/workspace.js
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* with its own cwd, and only the tool execution knows which one it belongs to —
|
|
4
|
-
* so a module-global "current cwd" would race between parallel sessions. The
|
|
5
|
-
* store path is derived per tool call from the session cwd; this module carries
|
|
6
|
-
* that cwd through the async execution so every store access inside the call
|
|
7
|
-
* (served rows, undo, hash snapshots) lands in the right per-workspace store.
|
|
2
|
+
* @deprecated — private to SessionView seam. Use `from "./session-view.js"` instead.
|
|
8
3
|
* @module dsh-better-edit/workspace
|
|
9
4
|
*/
|
|
10
|
-
|
|
11
|
-
const current = new AsyncLocalStorage();
|
|
12
|
-
/**
|
|
13
|
-
* Run `fn` with the given workspace cwd active for this async execution.
|
|
14
|
-
* Every `loadHashStore()` (and any store access) inside `fn` resolves the
|
|
15
|
-
* `<cwd>/.dsh_better_edit` store.
|
|
16
|
-
* @param cwd - the session workspace root (absolute).
|
|
17
|
-
* @param fn - the tool body.
|
|
18
|
-
* @returns the body's result.
|
|
19
|
-
*/
|
|
20
|
-
export function withWorkspace(cwd, fn) {
|
|
21
|
-
return current.run(cwd, fn);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The workspace cwd active for this async execution, or undefined outside a
|
|
25
|
-
* tool call (tests, previews, startup) — callers fall back to the shared
|
|
26
|
-
* `$DSH_HOME` store then.
|
|
27
|
-
*/
|
|
28
|
-
export function workspaceCwd() {
|
|
29
|
-
return current.getStore();
|
|
30
|
-
}
|
|
5
|
+
export * from "./session-view.js";
|
package/lib/write-hook.js
CHANGED
|
@@ -6,8 +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 } from './
|
|
10
|
-
import { withWorkspace } from './
|
|
9
|
+
import { execCwd, execSessionKey } from './session-view.js';
|
|
10
|
+
import { withWorkspace } from './session-view.js';
|
|
11
11
|
const AUTO_READ_HEADING = '--- Auto-read (hashline anchors) ---';
|
|
12
12
|
/**
|
|
13
13
|
* Register the post-write auto-read listener on the calling agent's scope.
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Hash-anchored read/edit/
|
|
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",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
8
8
|
"exports": {
|