dsh-hashline-edit 0.2.0 → 0.2.2

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 (109) hide show
  1. package/README.md +59 -55
  2. package/cordis.patch.yml +1 -1
  3. package/lib/index.js +7225 -6445
  4. package/lib/types/dsh/contracts.d.ts +3 -12
  5. package/lib/types/dsh/fs.d.ts +0 -3
  6. package/lib/types/dsh/guidance.d.ts +5 -5
  7. package/lib/types/dsh/host-compat.d.ts +78 -7
  8. package/lib/types/dsh/index.d.ts +7 -17
  9. package/lib/types/dsh/metrics/events.d.ts +1 -1
  10. package/lib/types/dsh/metrics/observer.d.ts +1 -1
  11. package/lib/types/dsh/sandbox.d.ts +2 -2
  12. package/lib/types/dsh/shell-hook.d.ts +1 -1
  13. package/lib/types/dsh/tools/edit.d.ts +10 -0
  14. package/lib/types/dsh/tools/read.d.ts +3 -3
  15. package/lib/types/src/domain-errors.d.ts +2 -16
  16. package/lib/types/src/edit-tool.d.ts +41 -0
  17. package/lib/types/src/edit-undo.d.ts +2 -11
  18. package/lib/types/src/file-content/index.d.ts +1 -1
  19. package/lib/types/src/file-content/preview.d.ts +1 -1
  20. package/lib/types/src/hash-store.d.ts +2 -2
  21. package/lib/types/src/hashline/alphabet.d.ts +16 -1
  22. package/lib/types/src/hashline/hash-identity.d.ts +10 -4
  23. package/lib/types/src/mutation-engine/engine.d.ts +31 -0
  24. package/lib/types/src/mutation-engine/pipeline.d.ts +1 -8
  25. package/lib/types/src/mutation-engine/types.d.ts +50 -40
  26. package/lib/types/src/payload-contract.d.ts +135 -0
  27. package/lib/types/src/served-session/serve-render.d.ts +0 -6
  28. package/lib/types/src/undo-store.d.ts +1 -17
  29. package/package.json +21 -10
  30. package/prompts/edit-guidelines.md +10 -0
  31. package/prompts/edit-snippet.md +1 -0
  32. package/prompts/edit.md +1 -0
  33. package/prompts/read-guidelines.md +4 -4
  34. package/prompts/read.md +1 -1
  35. package/prompts/undo-last-edit-guidelines.md +2 -2
  36. package/prompts/undo-last-edit-snippet.md +1 -1
  37. package/prompts/undo-last-edit.md +1 -1
  38. package/src/bash-classifier.ts +1626 -0
  39. package/src/bash-conversion/decide.ts +812 -0
  40. package/src/bash-display-transform.ts +50 -0
  41. package/src/bash-multifile-config.ts +239 -0
  42. package/src/bash-view-config.ts +158 -0
  43. package/src/cut-repair.ts +11 -77
  44. package/src/domain-errors.ts +3 -35
  45. package/src/edit-normalize.ts +8 -0
  46. package/src/edit-render.ts +161 -0
  47. package/src/edit-tool.ts +118 -0
  48. package/src/edit-undo.ts +25 -379
  49. package/src/edit.ts +136 -0
  50. package/src/file-content/index.ts +1 -1
  51. package/src/file-content/preview.ts +1 -1
  52. package/src/file-content/served-header.ts +1 -1
  53. package/src/hash-store.ts +1 -18
  54. package/src/hashline/alphabet.ts +42 -1
  55. package/src/hashline/hash-identity.ts +12 -3
  56. package/src/integrations/pi-lens/command.ts +712 -0
  57. package/src/integrations/pi-lens/config.ts +148 -0
  58. package/src/integrations/pi-lens/io-bridge-adapter.ts +234 -0
  59. package/src/integrations/pi-lens/io-bridge.ts +112 -0
  60. package/src/integrations/pi-lens/settings-overlay.ts +272 -0
  61. package/src/lifecycle-hooks/index.ts +1992 -0
  62. package/src/lifecycle-hooks/types.ts +64 -0
  63. package/src/mutated-files.ts +75 -0
  64. package/src/mutation-engine/engine.ts +239 -0
  65. package/src/mutation-engine/index.ts +17 -0
  66. package/src/mutation-engine/pipeline.ts +27 -198
  67. package/src/mutation-engine/types.ts +57 -39
  68. package/src/mutation-queue.ts +1 -1
  69. package/src/payload-contract.ts +685 -0
  70. package/src/preview-controller.ts +84 -0
  71. package/src/prompts.ts +43 -10
  72. package/src/read.ts +865 -0
  73. package/src/search-hook.ts +41 -0
  74. package/src/served-session/serve-render.ts +2 -2
  75. package/src/store-config.ts +73 -0
  76. package/src/store-janitor-warning.ts +169 -0
  77. package/src/store-janitor.ts +539 -0
  78. package/src/store-kernel/settings.ts +233 -0
  79. package/src/store.ts +154 -0
  80. package/src/tui-presenter.ts +134 -0
  81. package/src/undo-store.ts +5 -74
  82. package/src/write-hook.ts +130 -0
  83. package/lib/types/dsh/hide.d.ts +0 -78
  84. package/lib/types/dsh/tools/apply-patch.d.ts +0 -38
  85. package/lib/types/src/apply-patch/commit.d.ts +0 -49
  86. package/lib/types/src/apply-patch/grammar.d.ts +0 -29
  87. package/lib/types/src/apply-patch/lifecycle.d.ts +0 -32
  88. package/lib/types/src/apply-patch/plan.d.ts +0 -50
  89. package/lib/types/src/apply-patch/render.d.ts +0 -51
  90. package/lib/types/src/apply-patch/resolve.d.ts +0 -129
  91. package/lib/types/src/apply-patch/tool.d.ts +0 -54
  92. package/lib/types/src/apply-patch/types.d.ts +0 -362
  93. package/lib/types/src/fs-lifecycle.d.ts +0 -44
  94. package/lib/types/src/host-utils.d.ts +0 -63
  95. package/lib/types/src/mutation-engine/edit-request.d.ts +0 -34
  96. package/prompts/apply-patch-guidelines.md +0 -10
  97. package/prompts/apply-patch.md +0 -1
  98. package/src/apply-patch/commit.ts +0 -190
  99. package/src/apply-patch/grammar.ts +0 -620
  100. package/src/apply-patch/index.ts +0 -17
  101. package/src/apply-patch/lifecycle.ts +0 -195
  102. package/src/apply-patch/plan.ts +0 -800
  103. package/src/apply-patch/render.ts +0 -137
  104. package/src/apply-patch/resolve.ts +0 -470
  105. package/src/apply-patch/tool.ts +0 -257
  106. package/src/apply-patch/types.ts +0 -387
  107. package/src/fs-lifecycle.ts +0 -201
  108. package/src/host-utils.ts +0 -224
  109. package/src/mutation-engine/edit-request.ts +0 -39
@@ -1,4 +1,45 @@
1
- export const HASH_LEN = 4;
1
+ /**
2
+ * Anchor width — the single owner of the anchor's length and shape.
3
+ *
4
+ * WHY an environment variable rather than a settings-file key: `alphabet.ts` is a zero-import leaf
5
+ * and every shape, regex, bitset and capacity constant below is derived at module load, so the
6
+ * width can only be a process-wide, load-time value. Switching it changes every served anchor; the
7
+ * persisted store stays safe because the anchor generation (`hash-identity.ts`) folds the width in,
8
+ * so a switch is a hard generation miss (re-read), never a cross-width hit.
9
+ */
10
+ export const ANCHOR_WIDTH_ENV_VAR = "PI_BETTER_EDIT_ANCHOR_WIDTH";
11
+
12
+ /** Supported widths; anything else is rejected at load so a typo cannot silently pick a stale width. */
13
+ const SUPPORTED_WIDTH_TOKENS = ["3", "4"] as const;
14
+
15
+ /** Default width when the env var is unset/empty — the historical default. */
16
+ const DEFAULT_WIDTH = 4;
17
+
18
+ /**
19
+ * Resolve the anchor width from an environment map. Pure and dependency-free so the leaf stays a
20
+ * leaf and the ladder is unit-testable without mutating `process.env`.
21
+ */
22
+ export function resolveAnchorWidth(env: Record<string, string | undefined>): number {
23
+ const raw = env[ANCHOR_WIDTH_ENV_VAR];
24
+ if (raw === undefined || raw.trim() === "") return DEFAULT_WIDTH;
25
+ const value = raw.trim();
26
+ if (value === "3") return 3;
27
+ if (value === "4") return 4;
28
+ throw new Error(
29
+ `${ANCHOR_WIDTH_ENV_VAR} must be ${SUPPORTED_WIDTH_TOKENS.join(" or ")} (got ${JSON.stringify(raw)}).`,
30
+ );
31
+ }
32
+
33
+ /**
34
+ * Build-time bake hook. The dsh/pi builds pass esbuild `define: __ANCHOR_WIDTH__ = <width>` so the
35
+ * shipped bundle carries a literal width and NEVER consults the environment at runtime. When there
36
+ * is no define (vitest / an unbundled dev import), the `typeof` guard falls back to the resolver
37
+ * below, keeping the zero-import leaf usable in tests without a build step.
38
+ */
39
+ declare const __ANCHOR_WIDTH__: number | undefined;
40
+
41
+ export const HASH_LEN =
42
+ typeof __ANCHOR_WIDTH__ === "number" ? __ANCHOR_WIDTH__ : resolveAnchorWidth(process.env);
2
43
 
3
44
  export const ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
4
45
 
@@ -112,19 +112,28 @@ export const HASH_PROBE_STRIDE = ALPHA.length ** 2 + ALPHA.length + 1;
112
112
  export const CANON_VERSION = 3;
113
113
 
114
114
  /**
115
- * ANCHOR_GENERATION 1 (issue #20, ADR-0031): the file-scoped anchor-derivation generation.
115
+ * The file-scoped anchor-derivation generation (issue #20, ADR-0031; ADR-0020 for the width axis).
116
116
  * It covers exactly: (1) the width (`HASH_LEN`, `ALPHA`, `HASH_SPACE`/`USABLE_HASH_SPACE`);
117
117
  * (2) the (path, content) seeding (`fileBaseIndex` seeds xxh32 with the canonical absolute path,
118
118
  * `contentBaseIndex` is the explicit content-only fallback); (3) the all-digit reservation
119
119
  * (`DIGIT_CHARS`/`RESERVED_HASH_SPELLINGS`/`RESERVED_BITS` pre-marked in allocation); (4) the probe
120
120
  * stride (`HASH_PROBE_STRIDE`, coprime with both spaces). Bump it whenever any of those change.
121
121
  *
122
- * WHY: single owner of the anchor-generation literal — anchor-bearing artifacts (the undo/snapshot
122
+ * WHY it is a function of the width now: the width is a runtime switch (default 4, optional 3), so a
123
+ * width change MUST flip the generation or a store written at one width could be read at another.
124
+ * Width 4 stays generation 1 — the original persisted generation — so existing stores keep their
125
+ * anchors across this change; width 3 gets generation 2, and any future width gets `100 + width`.
126
+ *
127
+ * WHY: single owner of the anchor-generation value — anchor-bearing artifacts (the undo/snapshot
123
128
  * generation gate and the open-time sweep) read this axis only, never `CANON_VERSION`; the snapshot
124
129
  * cache key carries both (`${CANON_VERSION}:${ANCHOR_GENERATION}:${checksum}`), so a canon-only change
125
130
  * misses the cache without invalidating anchor state while a generation change invalidates both.
126
131
  */
127
- export const ANCHOR_GENERATION = 1;
132
+ export function anchorGenerationFor(width: number): number {
133
+ return width === 4 ? 1 : width === 3 ? 2 : 100 + width;
134
+ }
135
+
136
+ export const ANCHOR_GENERATION = anchorGenerationFor(HASH_LEN);
128
137
 
129
138
  /**
130
139
  * WHY: an explicit code-point list, never a Unicode property escape — \p{White_Space} and \p{Cf}