dsh-hashline-edit 0.2.1 → 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.
- package/README.md +60 -56
- package/cordis.patch.yml +3 -3
- package/lib/index.js +7224 -6454
- package/lib/types/dsh/contracts.d.ts +3 -12
- package/lib/types/dsh/fs.d.ts +0 -3
- package/lib/types/dsh/guidance.d.ts +5 -5
- package/lib/types/dsh/host-compat.d.ts +78 -7
- package/lib/types/dsh/index.d.ts +9 -21
- package/lib/types/dsh/metrics/events.d.ts +1 -1
- package/lib/types/dsh/metrics/observer.d.ts +1 -1
- package/lib/types/dsh/sandbox.d.ts +2 -2
- package/lib/types/dsh/shell-hook.d.ts +1 -1
- package/lib/types/dsh/tools/edit.d.ts +10 -0
- package/lib/types/dsh/tools/read.d.ts +3 -3
- package/lib/types/src/domain-errors.d.ts +2 -16
- package/lib/types/src/edit-tool.d.ts +41 -0
- package/lib/types/src/edit-undo.d.ts +2 -11
- package/lib/types/src/file-content/index.d.ts +1 -1
- package/lib/types/src/file-content/preview.d.ts +1 -1
- package/lib/types/src/hash-store.d.ts +2 -2
- package/lib/types/src/hashline/alphabet.d.ts +16 -1
- package/lib/types/src/hashline/hash-identity.d.ts +10 -4
- package/lib/types/src/mutation-engine/engine.d.ts +31 -0
- package/lib/types/src/mutation-engine/pipeline.d.ts +1 -8
- package/lib/types/src/mutation-engine/types.d.ts +50 -40
- package/lib/types/src/payload-contract.d.ts +135 -0
- package/lib/types/src/served-session/serve-render.d.ts +0 -6
- package/lib/types/src/undo-store.d.ts +1 -17
- package/package.json +21 -18
- package/prompts/edit-guidelines.md +10 -0
- package/prompts/edit-snippet.md +1 -0
- package/prompts/edit.md +1 -0
- package/prompts/read-guidelines.md +4 -4
- package/prompts/read.md +1 -1
- package/prompts/undo-last-edit-guidelines.md +2 -2
- package/prompts/undo-last-edit-snippet.md +1 -1
- package/prompts/undo-last-edit.md +1 -1
- package/src/bash-classifier.ts +1626 -0
- package/src/bash-conversion/decide.ts +812 -0
- package/src/bash-display-transform.ts +50 -0
- package/src/bash-multifile-config.ts +239 -0
- package/src/bash-view-config.ts +158 -0
- package/src/cut-repair.ts +11 -77
- package/src/domain-errors.ts +3 -35
- package/src/edit-normalize.ts +8 -0
- package/src/edit-render.ts +161 -0
- package/src/edit-tool.ts +118 -0
- package/src/edit-undo.ts +25 -379
- package/src/edit.ts +136 -0
- package/src/file-content/index.ts +1 -1
- package/src/file-content/preview.ts +1 -1
- package/src/file-content/served-header.ts +1 -1
- package/src/hash-store.ts +1 -18
- package/src/hashline/alphabet.ts +42 -1
- package/src/hashline/hash-identity.ts +12 -3
- package/src/integrations/pi-lens/command.ts +712 -0
- package/src/integrations/pi-lens/config.ts +148 -0
- package/src/integrations/pi-lens/io-bridge-adapter.ts +234 -0
- package/src/integrations/pi-lens/io-bridge.ts +112 -0
- package/src/integrations/pi-lens/settings-overlay.ts +272 -0
- package/src/lifecycle-hooks/index.ts +1992 -0
- package/src/lifecycle-hooks/types.ts +64 -0
- package/src/mutated-files.ts +75 -0
- package/src/mutation-engine/engine.ts +239 -0
- package/src/mutation-engine/index.ts +17 -0
- package/src/mutation-engine/pipeline.ts +27 -198
- package/src/mutation-engine/types.ts +57 -39
- package/src/mutation-queue.ts +1 -1
- package/src/payload-contract.ts +685 -0
- package/src/preview-controller.ts +84 -0
- package/src/prompts.ts +43 -10
- package/src/read.ts +865 -0
- package/src/search-hook.ts +41 -0
- package/src/served-session/serve-render.ts +2 -2
- package/src/store-config.ts +73 -0
- package/src/store-janitor-warning.ts +169 -0
- package/src/store-janitor.ts +539 -0
- package/src/store-kernel/settings.ts +233 -0
- package/src/store.ts +154 -0
- package/src/tui-presenter.ts +134 -0
- package/src/undo-store.ts +5 -74
- package/src/write-hook.ts +130 -0
- package/lib/types/dsh/hide.d.ts +0 -79
- package/lib/types/dsh/tools/apply-patch.d.ts +0 -38
- package/lib/types/src/apply-patch/commit.d.ts +0 -49
- package/lib/types/src/apply-patch/grammar.d.ts +0 -29
- package/lib/types/src/apply-patch/lifecycle.d.ts +0 -32
- package/lib/types/src/apply-patch/plan.d.ts +0 -50
- package/lib/types/src/apply-patch/render.d.ts +0 -51
- package/lib/types/src/apply-patch/resolve.d.ts +0 -129
- package/lib/types/src/apply-patch/tool.d.ts +0 -54
- package/lib/types/src/apply-patch/types.d.ts +0 -362
- package/lib/types/src/fs-lifecycle.d.ts +0 -44
- package/lib/types/src/host-utils.d.ts +0 -63
- package/lib/types/src/mutation-engine/edit-request.d.ts +0 -34
- package/prompts/apply-patch-guidelines.md +0 -10
- package/prompts/apply-patch.md +0 -1
- package/src/apply-patch/commit.ts +0 -190
- package/src/apply-patch/grammar.ts +0 -620
- package/src/apply-patch/index.ts +0 -17
- package/src/apply-patch/lifecycle.ts +0 -195
- package/src/apply-patch/plan.ts +0 -800
- package/src/apply-patch/render.ts +0 -137
- package/src/apply-patch/resolve.ts +0 -470
- package/src/apply-patch/tool.ts +0 -257
- package/src/apply-patch/types.ts +0 -387
- package/src/fs-lifecycle.ts +0 -201
- package/src/host-utils.ts +0 -224
- package/src/mutation-engine/edit-request.ts +0 -39
package/src/hashline/alphabet.ts
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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}
|