dsh-hashline-edit 0.4.2 → 0.5.0
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 +5 -6
- package/grammars/go-0.25.0-9504573f352b20be.wasm +0 -0
- package/grammars/java-0.23.5-4fdeac4ca6ca089f.wasm +0 -0
- package/grammars/python-0.25.0-16108b50df4ee9a3.wasm +0 -0
- package/grammars/rust-0.24.2-24c89bd9252255e4.wasm +0 -0
- package/grammars/tsx-0.23.2-79e5da75ea62855a.wasm +0 -0
- package/grammars/typescript-0.23.2-778025db5a8be0e7.wasm +0 -0
- package/grammars/vue-0.1.0-193c01119229352f.wasm +0 -0
- package/lib/index.js +267 -31
- package/lib/types/dsh/syntax-health.d.ts +60 -0
- package/lib/types/dsh/tools/output.d.ts +10 -0
- package/lib/types/src/bundled-assets.d.ts +13 -0
- package/lib/types/src/hashline/resolve.d.ts +2 -1
- package/lib/types/src/mutation-engine/edit-request.d.ts +4 -0
- package/lib/types/src/payload-contract.d.ts +9 -1
- package/lib/types/src/read-expansion/grammar-manifest.d.ts +3 -1
- package/lib/types/src/read-expansion/grammar-runtime.d.ts +1 -1
- package/package.json +3 -2
- package/prompts/edit-guidelines.md +4 -2
- package/prompts/edit.md +1 -1
- package/src/bundled-assets.ts +23 -0
- package/src/hashline/resolve.ts +8 -4
- package/src/mutation-engine/edit-request.ts +4 -1
- package/src/mutation-engine/pipeline.ts +17 -1
- package/src/payload-contract.ts +134 -33
- package/src/read-expansion/grammar-cache.ts +33 -1
- package/src/read-expansion/grammar-manifest.ts +3 -1
- package/src/read-expansion/grammar-runtime.ts +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lazy, hash-pinned grammar cache.
|
|
3
3
|
*
|
|
4
|
-
* WHY
|
|
4
|
+
* WHY bundled first and fetched only as a fallback: ADR-0026 ships all seven grammars inside the
|
|
5
|
+
* package (`grammars/`), so a first read never waits on — and never needs — the network. Bytes are
|
|
6
|
+
* digest-verified whichever source they come from; the committed manifest stays the trust anchor.
|
|
5
7
|
* small extension bundle, and most sessions never touch most languages. The committed manifest is
|
|
6
8
|
* the trust anchor: bytes are cached only after their SHA-256 matches, and a cache entry whose
|
|
7
9
|
* digest no longer matches is deleted rather than parsed.
|
|
@@ -14,6 +16,7 @@ import { createHash } from "node:crypto";
|
|
|
14
16
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
15
17
|
import { dirname, join } from "node:path";
|
|
16
18
|
import { stateRoot } from "../config-dir.js";
|
|
19
|
+
import { readBundledAsset } from "../bundled-assets.js";
|
|
17
20
|
import {
|
|
18
21
|
GRAMMAR_MANIFEST,
|
|
19
22
|
type GrammarManifest,
|
|
@@ -179,6 +182,13 @@ export async function requestGrammar(
|
|
|
179
182
|
const path = grammarCachePath(language, entry, options.cacheRoot);
|
|
180
183
|
const cached = readVerifiedCache(path, entry.sha256);
|
|
181
184
|
if (cached !== undefined) return { status: "ready", artifact: { language, path, bytes: cached } };
|
|
185
|
+
// WHY: bundled before the network — the shipped grammars are the common path now, so a first
|
|
186
|
+
// WHY: read never waits on a fetch. A miss falls through to the lazy download below.
|
|
187
|
+
const bundled = bundledGrammarBytes(language, entry);
|
|
188
|
+
if (bundled !== undefined) {
|
|
189
|
+
writeCache(path, bundled);
|
|
190
|
+
return { status: "ready", artifact: { language, path, bytes: bundled } };
|
|
191
|
+
}
|
|
182
192
|
|
|
183
193
|
let pending = inFlight.get(path);
|
|
184
194
|
if (pending === undefined) {
|
|
@@ -207,3 +217,25 @@ export async function ensureGrammar(
|
|
|
207
217
|
const result = await requestGrammar(language, options);
|
|
208
218
|
return result.status === "ready" ? result.artifact : undefined;
|
|
209
219
|
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Verified bytes taken from this package's own `grammars/` directory, or undefined.
|
|
223
|
+
*
|
|
224
|
+
* WHY bundle AND keep the fetch: the shipped artifact must work offline and instantly, but a
|
|
225
|
+
* language can enter the manifest before it enters the tarball, so the download stays as the
|
|
226
|
+
* fallback for that window.
|
|
227
|
+
* @param language - manifest key.
|
|
228
|
+
* @param entry - the pinned version and digest for that key.
|
|
229
|
+
* @returns the verified bytes, or undefined when the asset is absent or no longer matches the pin.
|
|
230
|
+
*/
|
|
231
|
+
function bundledGrammarBytes(
|
|
232
|
+
language: string,
|
|
233
|
+
entry: GrammarManifestEntry,
|
|
234
|
+
): Uint8Array | undefined {
|
|
235
|
+
const name = `${language}-${entry.version}-${entry.sha256.slice(0, 16)}.wasm`;
|
|
236
|
+
const bytes = readBundledAsset(`grammars/${name}`);
|
|
237
|
+
if (bytes === undefined) return undefined;
|
|
238
|
+
// WHY: bundled bytes are verified too — a truncated download, a bad publish or a hand-edited
|
|
239
|
+
// WHY: file in the tarball must never reach the parser, exactly as for a fetched grammar.
|
|
240
|
+
return sha256Hex(bytes) === entry.sha256 ? bytes : undefined;
|
|
241
|
+
}
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* cache file, so a manifest bump cannot keep serving the previous grammar.
|
|
7
7
|
*
|
|
8
8
|
* WHY nothing here is imported as a module: the runtime (`web-tree-sitter`) is the only dependency;
|
|
9
|
-
*
|
|
9
|
+
* WHY nothing here is imported as a module: the runtime (`web-tree-sitter`) is the only dependency;
|
|
10
|
+
* the pinned `.wasm` files ship inside this package under `grammars/` (ADR-0026) and are fetched only
|
|
11
|
+
* when that copy is missing, so a first read parses offline and never waits on the network.
|
|
10
12
|
*/
|
|
11
13
|
export interface GrammarManifestEntry {
|
|
12
14
|
readonly language: string;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* the wasm host. `hasWebTreeSitterRuntime` is the cheap preflight; grammar bytes are only fetched
|
|
7
7
|
* after it answered yes, and a resolution failure is the same answer as an offline grammar.
|
|
8
8
|
*
|
|
9
|
-
* WHY the runtime is the only
|
|
9
|
+
* WHY the runtime is the only DEPENDENCY: grammar bytes ship in this package (`grammars/`, ADR-0026)
|
|
10
10
|
* the wasm host, never by a grammar set. `Language.load` accepts the verified bytes directly, so no
|
|
11
11
|
* second disk read is needed after the cache check.
|
|
12
12
|
*/
|