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.
Files changed (85) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +317 -240
  3. package/README.zh.md +19 -11
  4. package/lib/constants.js +3 -1
  5. package/lib/contract.js +159 -63
  6. package/lib/drift.js +5 -98
  7. package/lib/dsh-context.js +2 -24
  8. package/lib/edit-engine.js +9 -8
  9. package/lib/edit-pipeline.js +3 -121
  10. package/lib/edit-response.js +16 -8
  11. package/lib/file-kind.js +6 -121
  12. package/lib/file-reader.js +4 -77
  13. package/lib/file-view.js +486 -0
  14. package/lib/guidance/index.js +8 -0
  15. package/lib/guidance/materialize.js +212 -0
  16. package/lib/guidance/parse.js +80 -0
  17. package/lib/guidance/resolve.js +116 -0
  18. package/lib/guidance.js +6 -388
  19. package/lib/hash-store.js +6 -4
  20. package/lib/hashline/alphabet.js +2 -6
  21. package/lib/hashline/anchor-pipeline.js +786 -0
  22. package/lib/hashline/apply.js +2 -223
  23. package/lib/hashline/hash-assign.js +255 -0
  24. package/lib/hashline/hash.js +67 -29
  25. package/lib/hashline/hasher.js +2 -23
  26. package/lib/hashline/index.js +9 -4
  27. package/lib/hashline/parse.js +2 -35
  28. package/lib/hashline/pure.js +2 -213
  29. package/lib/hashline/resolve.js +3 -361
  30. package/lib/hashline/served.js +2 -120
  31. package/lib/index.js +1 -3
  32. package/lib/mutation.js +266 -0
  33. package/lib/noop-guard.js +20 -0
  34. package/lib/preview-controller.js +65 -0
  35. package/lib/prompts.js +14 -20
  36. package/lib/read-and-serve.js +23 -23
  37. package/lib/read-render.js +3 -139
  38. package/lib/served-store.js +2 -216
  39. package/lib/session-view.js +332 -0
  40. package/lib/tool-batch-edit.js +9 -10
  41. package/lib/tool-edit.js +73 -129
  42. package/lib/tool-read.js +3 -5
  43. package/lib/tool-undo.js +16 -10
  44. package/lib/truncate.js +3 -95
  45. package/lib/types/constants.d.ts +2 -0
  46. package/lib/types/contract.d.ts +120 -15
  47. package/lib/types/drift.d.ts +5 -29
  48. package/lib/types/dsh-context.d.ts +2 -20
  49. package/lib/types/edit-engine.d.ts +2 -2
  50. package/lib/types/edit-pipeline.d.ts +3 -44
  51. package/lib/types/file-kind.d.ts +6 -18
  52. package/lib/types/file-reader.d.ts +4 -45
  53. package/lib/types/file-view.d.ts +139 -0
  54. package/lib/types/guidance/index.d.ts +8 -0
  55. package/lib/types/guidance/materialize.d.ts +23 -0
  56. package/lib/types/guidance/parse.d.ts +36 -0
  57. package/lib/types/guidance/resolve.d.ts +55 -0
  58. package/lib/types/guidance.d.ts +6 -127
  59. package/lib/types/hashline/alphabet.d.ts +1 -5
  60. package/lib/types/hashline/anchor-pipeline.d.ts +127 -0
  61. package/lib/types/hashline/apply.d.ts +1 -22
  62. package/lib/types/hashline/hash-assign.d.ts +25 -0
  63. package/lib/types/hashline/hash.d.ts +8 -9
  64. package/lib/types/hashline/hasher.d.ts +1 -8
  65. package/lib/types/hashline/index.d.ts +12 -4
  66. package/lib/types/hashline/parse.d.ts +1 -7
  67. package/lib/types/hashline/pure.d.ts +1 -26
  68. package/lib/types/hashline/resolve.d.ts +1 -58
  69. package/lib/types/hashline/served.d.ts +1 -43
  70. package/lib/types/mutation.d.ts +131 -0
  71. package/lib/types/noop-guard.d.ts +29 -0
  72. package/lib/types/preview-controller.d.ts +33 -0
  73. package/lib/types/prompts.d.ts +9 -9
  74. package/lib/types/read-and-serve.d.ts +6 -5
  75. package/lib/types/read-render.d.ts +3 -18
  76. package/lib/types/served-store.d.ts +2 -81
  77. package/lib/types/session-view.d.ts +92 -0
  78. package/lib/types/tool-edit.d.ts +3 -14
  79. package/lib/types/truncate.d.ts +3 -29
  80. package/lib/types/validation.d.ts +6 -7
  81. package/lib/types/workspace.d.ts +2 -21
  82. package/lib/validation.js +6 -33
  83. package/lib/workspace.js +2 -27
  84. package/lib/write-hook.js +2 -2
  85. package/package.json +2 -2
@@ -1,7 +1,6 @@
1
- import type { LFile } from "./file-kind.js";
2
- export declare function valAccess(absolutePath: string, path: string, accessMode?: number): Promise<void>;
3
- export declare function valKind(file: LFile, path: string): asserts file is {
4
- kind: "text";
5
- text: string;
6
- hadUtf8DecodeErrors?: true;
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";
@@ -1,24 +1,5 @@
1
1
  /**
2
- * Per-call workspace context. dsh serves several sessions in one process, each
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
- import { constants } from "node:fs";
2
- import { access as fsAccess } from "fs/promises";
3
- import { errCode } from "./utils.js";
4
- export async function valAccess(absolutePath, path, accessMode = constants.R_OK) {
5
- try {
6
- await fsAccess(absolutePath, accessMode);
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
- * Per-call workspace context. dsh serves several sessions in one process, each
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
- import { AsyncLocalStorage } from 'node:async_hooks';
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 './dsh-context.js';
10
- import { withWorkspace } from './workspace.js';
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.2.2",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
- "description": "Hash-anchored read/edit/batch_edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
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": {