@seanhogg/builderforce-memory 2026.10.45 → 2026.10.47
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 +21 -0
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +13 -7
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/extractFile.d.ts +9 -1
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +25 -5
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +30 -5
- package/dist/knowledge/extractJob.d.ts.map +1 -1
- package/dist/knowledge/extractJob.js +9 -1
- package/dist/knowledge/extractJob.js.map +1 -1
- package/dist/knowledge/index.d.ts +5 -3
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +2 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/jobDeadline.d.ts +17 -0
- package/dist/knowledge/jobDeadline.d.ts.map +1 -0
- package/dist/knowledge/jobDeadline.js +46 -0
- package/dist/knowledge/jobDeadline.js.map +1 -0
- package/dist/knowledge/judgeCalls.d.ts +16 -0
- package/dist/knowledge/judgeCalls.d.ts.map +1 -1
- package/dist/knowledge/judgeCalls.js +20 -1
- package/dist/knowledge/judgeCalls.js.map +1 -1
- package/dist/knowledge/judgePriority.d.ts +22 -0
- package/dist/knowledge/judgePriority.d.ts.map +1 -0
- package/dist/knowledge/judgePriority.js +28 -0
- package/dist/knowledge/judgePriority.js.map +1 -0
- package/dist/knowledge/pack/crc32.d.ts +7 -0
- package/dist/knowledge/pack/crc32.d.ts.map +1 -0
- package/dist/knowledge/pack/crc32.js +22 -0
- package/dist/knowledge/pack/crc32.js.map +1 -0
- package/dist/knowledge/pack/decode.d.ts +14 -0
- package/dist/knowledge/pack/decode.d.ts.map +1 -0
- package/dist/knowledge/pack/decode.js +66 -0
- package/dist/knowledge/pack/decode.js.map +1 -0
- package/dist/knowledge/pack/deflate.d.ts +9 -0
- package/dist/knowledge/pack/deflate.d.ts.map +1 -0
- package/dist/knowledge/pack/deflate.js +45 -0
- package/dist/knowledge/pack/deflate.js.map +1 -0
- package/dist/knowledge/pack/encode.d.ts +26 -0
- package/dist/knowledge/pack/encode.d.ts.map +1 -0
- package/dist/knowledge/pack/encode.js +86 -0
- package/dist/knowledge/pack/encode.js.map +1 -0
- package/dist/knowledge/pack/extrDiff.d.ts +26 -0
- package/dist/knowledge/pack/extrDiff.d.ts.map +1 -0
- package/dist/knowledge/pack/extrDiff.js +129 -0
- package/dist/knowledge/pack/extrDiff.js.map +1 -0
- package/dist/knowledge/pack/frame.d.ts +45 -0
- package/dist/knowledge/pack/frame.d.ts.map +1 -0
- package/dist/knowledge/pack/frame.js +101 -0
- package/dist/knowledge/pack/frame.js.map +1 -0
- package/dist/knowledge/pack/hex.d.ts +7 -0
- package/dist/knowledge/pack/hex.d.ts.map +1 -0
- package/dist/knowledge/pack/hex.js +17 -0
- package/dist/knowledge/pack/hex.js.map +1 -0
- package/dist/knowledge/pack/index.d.ts +19 -0
- package/dist/knowledge/pack/index.d.ts.map +1 -0
- package/dist/knowledge/pack/index.js +17 -0
- package/dist/knowledge/pack/index.js.map +1 -0
- package/dist/knowledge/pack/jsonSize.d.ts +5 -0
- package/dist/knowledge/pack/jsonSize.d.ts.map +1 -0
- package/dist/knowledge/pack/jsonSize.js +8 -0
- package/dist/knowledge/pack/jsonSize.js.map +1 -0
- package/dist/knowledge/pack/manifest.d.ts +66 -0
- package/dist/knowledge/pack/manifest.d.ts.map +1 -0
- package/dist/knowledge/pack/manifest.js +104 -0
- package/dist/knowledge/pack/manifest.js.map +1 -0
- package/dist/knowledge/pack/sections/columns.d.ts +32 -0
- package/dist/knowledge/pack/sections/columns.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/columns.js +53 -0
- package/dist/knowledge/pack/sections/columns.js.map +1 -0
- package/dist/knowledge/pack/sections/extr.d.ts +8 -0
- package/dist/knowledge/pack/sections/extr.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/extr.js +99 -0
- package/dist/knowledge/pack/sections/extr.js.map +1 -0
- package/dist/knowledge/pack/sections/extrLists.d.ts +23 -0
- package/dist/knowledge/pack/sections/extrLists.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/extrLists.js +200 -0
- package/dist/knowledge/pack/sections/extrLists.js.map +1 -0
- package/dist/knowledge/pack/sections/facts.d.ts +8 -0
- package/dist/knowledge/pack/sections/facts.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/facts.js +172 -0
- package/dist/knowledge/pack/sections/facts.js.map +1 -0
- package/dist/knowledge/pack/sections/index.d.ts +6 -0
- package/dist/knowledge/pack/sections/index.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/index.js +9 -0
- package/dist/knowledge/pack/sections/index.js.map +1 -0
- package/dist/knowledge/pack/sections/rows.d.ts +31 -0
- package/dist/knowledge/pack/sections/rows.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/rows.js +227 -0
- package/dist/knowledge/pack/sections/rows.js.map +1 -0
- package/dist/knowledge/pack/strings.d.ts +43 -0
- package/dist/knowledge/pack/strings.d.ts.map +1 -0
- package/dist/knowledge/pack/strings.js +117 -0
- package/dist/knowledge/pack/strings.js.map +1 -0
- package/dist/knowledge/pack/types.d.ts +118 -0
- package/dist/knowledge/pack/types.d.ts.map +1 -0
- package/dist/knowledge/pack/types.js +17 -0
- package/dist/knowledge/pack/types.js.map +1 -0
- package/dist/knowledge/pack/varint.d.ts +57 -0
- package/dist/knowledge/pack/varint.d.ts.map +1 -0
- package/dist/knowledge/pack/varint.js +145 -0
- package/dist/knowledge/pack/varint.js.map +1 -0
- package/dist/knowledge/partitions.d.ts +1 -1
- package/dist/knowledge/partitions.d.ts.map +1 -1
- package/dist/knowledge/partitions.js +6 -1
- package/dist/knowledge/partitions.js.map +1 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +58 -16
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewJudge.d.ts +8 -1
- package/dist/knowledge/reviewJudge.d.ts.map +1 -1
- package/dist/knowledge/reviewJudge.js +14 -8
- package/dist/knowledge/reviewJudge.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +41 -1
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.d.ts +10 -2
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +60 -25
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/dist/knowledge/reviewRun.d.ts +15 -3
- package/dist/knowledge/reviewRun.d.ts.map +1 -1
- package/dist/knowledge/reviewRun.js +19 -2
- package/dist/knowledge/reviewRun.js.map +1 -1
- package/dist/knowledge/reviewRunModel.d.ts +8 -1
- package/dist/knowledge/reviewRunModel.d.ts.map +1 -1
- package/dist/knowledge/reviewRunModel.js.map +1 -1
- package/dist/knowledge/stores/localSnapshotStore.d.ts +72 -6
- package/dist/knowledge/stores/localSnapshotStore.d.ts.map +1 -1
- package/dist/knowledge/stores/localSnapshotStore.js +279 -75
- package/dist/knowledge/stores/localSnapshotStore.js.map +1 -1
- package/package.json +8 -3
- package/src/contract/dist.contract.test.ts +44 -0
- package/src/contract/exports.contract.test.ts +90 -0
- package/src/contract/exports.snapshot.json +605 -0
- package/src/contract/pack.contract.test.ts +31 -0
- package/src/contract/regression.review.test.ts +236 -0
- package/src/contract/regression.store.test.ts +84 -0
- package/src/contract/types.contract.test.ts +183 -0
- package/src/knowledge/build.ts +11 -5
- package/src/knowledge/extractFile.ts +28 -6
- package/src/knowledge/extractJob.ts +26 -7
- package/src/knowledge/index.ts +5 -3
- package/src/knowledge/jobDeadline.ts +43 -0
- package/src/knowledge/judgeCalls.ts +19 -2
- package/src/knowledge/judgePriority.ts +36 -0
- package/src/knowledge/pack/crc32.ts +21 -0
- package/src/knowledge/pack/decode.ts +60 -0
- package/src/knowledge/pack/deflate.ts +43 -0
- package/src/knowledge/pack/encode.ts +89 -0
- package/src/knowledge/pack/extrDiff.ts +116 -0
- package/src/knowledge/pack/frame.ts +94 -0
- package/src/knowledge/pack/hex.ts +17 -0
- package/src/knowledge/pack/index.ts +26 -0
- package/src/knowledge/pack/jsonSize.ts +11 -0
- package/src/knowledge/pack/manifest.ts +128 -0
- package/src/knowledge/pack/pack.guards.test.ts +109 -0
- package/src/knowledge/pack/pack.reconcile.test.ts +96 -0
- package/src/knowledge/pack/pack.roundtrip.test.ts +50 -0
- package/src/knowledge/pack/pack.size.test.ts +22 -0
- package/src/knowledge/pack/pack.testkit.test-util.ts +90 -0
- package/src/knowledge/pack/sections/columns.ts +61 -0
- package/src/knowledge/pack/sections/extr.ts +90 -0
- package/src/knowledge/pack/sections/extrLists.ts +151 -0
- package/src/knowledge/pack/sections/facts.ts +126 -0
- package/src/knowledge/pack/sections/index.ts +13 -0
- package/src/knowledge/pack/sections/rows.ts +184 -0
- package/src/knowledge/pack/strings.ts +126 -0
- package/src/knowledge/pack/types.ts +97 -0
- package/src/knowledge/pack/varint.ts +145 -0
- package/src/knowledge/partitions.test.ts +4 -0
- package/src/knowledge/partitions.ts +3 -1
- package/src/knowledge/review.throughput.test.ts +122 -0
- package/src/knowledge/review.ts +54 -16
- package/src/knowledge/review.twoPass.test.ts +224 -0
- package/src/knowledge/reviewJudge.ts +19 -8
- package/src/knowledge/reviewModel.ts +38 -1
- package/src/knowledge/reviewPrefetch.ts +60 -24
- package/src/knowledge/reviewRun.test.ts +20 -3
- package/src/knowledge/reviewRun.ts +33 -6
- package/src/knowledge/reviewRunModel.ts +4 -1
- package/src/knowledge/stores/localSnapshotStore.batched.test.ts +25 -3
- package/src/knowledge/stores/localSnapshotStore.extractedLog.test.ts +280 -0
- package/src/knowledge/stores/localSnapshotStore.ts +283 -76
- package/src/knowledge/systems.test.ts +12 -0
- package/src/knowledge/testkit.test-util.ts +13 -2
|
@@ -18,6 +18,20 @@ export interface SectionAnswer {
|
|
|
18
18
|
section: SectionToJudge;
|
|
19
19
|
v: ReturnType<typeof validateExtract>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Stops a run's judging after consecutive provider failures (PRD 41 A10 rule 9): with the network down every
|
|
23
|
+
* section would otherwise cost the full call timeout. Sections cut by it stay unjudged and owed.
|
|
24
|
+
*/
|
|
25
|
+
export declare class JudgeBreaker {
|
|
26
|
+
private readonly limit;
|
|
27
|
+
private streak;
|
|
28
|
+
private reason;
|
|
29
|
+
constructor(limit?: number);
|
|
30
|
+
/** Why judging stopped; undefined while it runs. */
|
|
31
|
+
get stopped(): string | undefined;
|
|
32
|
+
ok(): void;
|
|
33
|
+
fail(reason: string): void;
|
|
34
|
+
}
|
|
21
35
|
export interface CallSectionsArgs {
|
|
22
36
|
port: JudgementPort;
|
|
23
37
|
fileHash: string;
|
|
@@ -27,6 +41,8 @@ export interface CallSectionsArgs {
|
|
|
27
41
|
/** Shared across the files of a review: caps the calls in flight and adapts to rate limits. */
|
|
28
42
|
limiter?: ModelLimiter;
|
|
29
43
|
signal?: AbortSignal;
|
|
44
|
+
/** Counts consecutive failures across the files of a run; once it trips, no further call is made. */
|
|
45
|
+
breaker?: JudgeBreaker;
|
|
30
46
|
}
|
|
31
47
|
export interface CallSectionsResult {
|
|
32
48
|
answers: SectionAnswer[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"judgeCalls.d.ts","sourceRoot":"","sources":["../../src/knowledge/judgeCalls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAC6E,eAAe,EAC/F,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAC1D,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AAKrE,yGAAyG;AACzG,MAAM,WAAW,aAAa;IAAG,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MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IACpC,+DAA+D;IAC/D,MAAM,EAAE,WAAW,CAAC;IACpB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qGAAqG;IACrG,OAAO,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,2DAA2D;AAC3D,wBAAsB,YAAY,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6BnF;AAED,4GAA4G;AAC5G,wBAAsB,aAAa,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAMlG;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CACxB,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC,EACtF,OAAO,EAAE,SAAS,aAAa,EAAE,GAClC,KAAK,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CA0CvC"}
|
|
@@ -15,6 +15,23 @@ import { budgetLeft, call, claimContent, JUDGE_CONCURRENCY, REVIEW_FACT_SOURCE,
|
|
|
15
15
|
import { compareStr, factRef } from './refs.js';
|
|
16
16
|
import { entityKey, normalizeKey } from './resolve.js';
|
|
17
17
|
import { reasonOf } from './reviewRunModel.js';
|
|
18
|
+
/**
|
|
19
|
+
* Stops a run's judging after consecutive provider failures (PRD 41 A10 rule 9): with the network down every
|
|
20
|
+
* section would otherwise cost the full call timeout. Sections cut by it stay unjudged and owed.
|
|
21
|
+
*/
|
|
22
|
+
export class JudgeBreaker {
|
|
23
|
+
limit;
|
|
24
|
+
streak = 0;
|
|
25
|
+
reason;
|
|
26
|
+
constructor(limit = 5) {
|
|
27
|
+
this.limit = limit;
|
|
28
|
+
}
|
|
29
|
+
/** Why judging stopped; undefined while it runs. */
|
|
30
|
+
get stopped() { return this.reason; }
|
|
31
|
+
ok() { this.streak = 0; }
|
|
32
|
+
fail(reason) { this.streak += 1; if (this.streak >= this.limit)
|
|
33
|
+
this.reason ??= `${this.streak} model calls failed in a row: ${reason}`; }
|
|
34
|
+
}
|
|
18
35
|
/** Answers come back in section order. Throws on abort. */
|
|
19
36
|
export async function callSections(a) {
|
|
20
37
|
const slots = new Array(a.sections.length);
|
|
@@ -32,7 +49,7 @@ export async function callSections(a) {
|
|
|
32
49
|
// Honoured per section, not only when the port throws: the caller drops this file whole.
|
|
33
50
|
if (a.signal?.aborted)
|
|
34
51
|
throw abortError();
|
|
35
|
-
if (!budgetLeft(a.budget)) {
|
|
52
|
+
if (!budgetLeft(a.budget) || a.breaker?.stopped) {
|
|
36
53
|
unjudged += 1;
|
|
37
54
|
return;
|
|
38
55
|
}
|
|
@@ -43,8 +60,10 @@ export async function callSections(a) {
|
|
|
43
60
|
// A failed call judged nothing: not counted judged, so the file stays changed and is retried.
|
|
44
61
|
if (!answer) {
|
|
45
62
|
unjudged += 1;
|
|
63
|
+
a.breaker?.fail(firstError ?? 'model call failed');
|
|
46
64
|
return;
|
|
47
65
|
}
|
|
66
|
+
a.breaker?.ok();
|
|
48
67
|
// The abort can land while a call is in flight (the port sees the signal): a section that
|
|
49
68
|
// finished after the abort must not count as judged, or the caller would not re-judge it.
|
|
50
69
|
if (a.signal?.aborted)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"judgeCalls.js","sourceRoot":"","sources":["../../src/knowledge/judgeCalls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACH,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,OAAO,EAAE,eAAe,GAElG,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"judgeCalls.js","sourceRoot":"","sources":["../../src/knowledge/judgeCalls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACH,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,OAAO,EAAE,eAAe,GAElG,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAK/C;;;GAGG;AACH,MAAM,OAAO,YAAY;IAGQ,KAAK;IAF1B,MAAM,GAAG,CAAC,CAAC;IACX,MAAM,CAAqB;IACnC,YAA6B,KAAK,GAAW,CAAC;qBAAjB,KAAK;IAAe,CAAC;IAClD,oDAAoD;IACpD,IAAI,OAAO,KAAyB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,EAAE,KAAW,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAc,IAAU,I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AAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/judgePriority.ts — the order pass 2 judges owed files in (PRD 41 A10 rule 1).
|
|
3
|
+
*
|
|
4
|
+
* 1. entry points and manifests,
|
|
5
|
+
* 2. files with the most inbound references,
|
|
6
|
+
* 3. recently changed files,
|
|
7
|
+
* 4. the rest.
|
|
8
|
+
*
|
|
9
|
+
* Pure and deterministic: ties break by path, so equal input is the same order on every host. The caller
|
|
10
|
+
* supplies the signals (it owns the graph and the history); a missing signal simply ranks nobody.
|
|
11
|
+
*/
|
|
12
|
+
export interface JudgeSignals {
|
|
13
|
+
/** Entry points and manifests (a package.json, a README, a declared `main`). */
|
|
14
|
+
entry?: (path: string) => boolean;
|
|
15
|
+
/** Inbound reference count per path. */
|
|
16
|
+
inbound?: ReadonlyMap<string, number>;
|
|
17
|
+
/** Files changed since the last review (or by the latest commits). */
|
|
18
|
+
recent?: ReadonlySet<string>;
|
|
19
|
+
}
|
|
20
|
+
/** `paths` in judging order. The input is not mutated. */
|
|
21
|
+
export declare function orderForJudging(paths: readonly string[], signals?: JudgeSignals): string[];
|
|
22
|
+
//# sourceMappingURL=judgePriority.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judgePriority.d.ts","sourceRoot":"","sources":["../../src/knowledge/judgePriority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,YAAY;IACzB,gFAAgF;IAChF,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,wCAAwC;IACxC,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,sEAAsE;IACtE,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAChC;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,EAAE,CAW9F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/judgePriority.ts — the order pass 2 judges owed files in (PRD 41 A10 rule 1).
|
|
3
|
+
*
|
|
4
|
+
* 1. entry points and manifests,
|
|
5
|
+
* 2. files with the most inbound references,
|
|
6
|
+
* 3. recently changed files,
|
|
7
|
+
* 4. the rest.
|
|
8
|
+
*
|
|
9
|
+
* Pure and deterministic: ties break by path, so equal input is the same order on every host. The caller
|
|
10
|
+
* supplies the signals (it owns the graph and the history); a missing signal simply ranks nobody.
|
|
11
|
+
*/
|
|
12
|
+
import { compareStr } from './refs.js';
|
|
13
|
+
/** `paths` in judging order. The input is not mutated. */
|
|
14
|
+
export function orderForJudging(paths, signals = {}) {
|
|
15
|
+
const tier = (p) => (signals.entry?.(p) ? 0 : (signals.inbound?.get(p) ?? 0) > 0 ? 1 : signals.recent?.has(p) ? 2 : 3);
|
|
16
|
+
return [...paths].sort((a, b) => {
|
|
17
|
+
const ta = tier(a), tb = tier(b);
|
|
18
|
+
if (ta !== tb)
|
|
19
|
+
return ta - tb;
|
|
20
|
+
if (ta === 1) {
|
|
21
|
+
const d = (signals.inbound.get(b) ?? 0) - (signals.inbound.get(a) ?? 0);
|
|
22
|
+
if (d !== 0)
|
|
23
|
+
return d;
|
|
24
|
+
}
|
|
25
|
+
return compareStr(a, b);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=judgePriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judgePriority.js","sourceRoot":"","sources":["../../src/knowledge/judgePriority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAAC,KAAwB,EAAE,OAAO,GAAiB,EAAE;IAChF,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvI,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QAC9B,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,OAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,IAAI,CAAC,KAAK,CAAC;gBAAE,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/crc32.ts — CRC-32 (IEEE 802.3) of a byte range; the trailer of a BFKP frame (PRD 41 A11).
|
|
3
|
+
* `crc32(b, crc32(a))` equals `crc32(a ++ b)`, so a frame's CRC covers its header and its body without a copy.
|
|
4
|
+
*/
|
|
5
|
+
/** The CRC-32 of `data`, continuing from `previous` (the CRC of what came before; 0 to start). */
|
|
6
|
+
export declare function crc32(data: Uint8Array, previous?: number): number;
|
|
7
|
+
//# sourceMappingURL=crc32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc32.d.ts","sourceRoot":"","sources":["../../../src/knowledge/pack/crc32.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,kGAAkG;AAClG,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,SAAI,GAAG,MAAM,CAI5D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/crc32.ts — CRC-32 (IEEE 802.3) of a byte range; the trailer of a BFKP frame (PRD 41 A11).
|
|
3
|
+
* `crc32(b, crc32(a))` equals `crc32(a ++ b)`, so a frame's CRC covers its header and its body without a copy.
|
|
4
|
+
*/
|
|
5
|
+
const TABLE = (() => {
|
|
6
|
+
const t = new Uint32Array(256);
|
|
7
|
+
for (let n = 0; n < 256; n++) {
|
|
8
|
+
let c = n;
|
|
9
|
+
for (let k = 0; k < 8; k++)
|
|
10
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
11
|
+
t[n] = c >>> 0;
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
})();
|
|
15
|
+
/** The CRC-32 of `data`, continuing from `previous` (the CRC of what came before; 0 to start). */
|
|
16
|
+
export function crc32(data, previous = 0) {
|
|
17
|
+
let c = (previous ^ 0xffffffff) >>> 0;
|
|
18
|
+
for (let i = 0; i < data.length; i++)
|
|
19
|
+
c = TABLE[(c ^ data[i]) & 0xff] ^ (c >>> 8);
|
|
20
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=crc32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc32.js","sourceRoot":"","sources":["../../../src/knowledge/pack/crc32.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,KAAK,GAAgB,CAAC,GAAG,EAAE;IAC7B,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACzE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,CAAC,CAAC;AACb,CAAC,CAAC,EAAE,CAAC;AAEL,kGAAkG;AAClG,MAAM,UAAU,KAAK,CAAC,IAAgB,EAAE,QAAQ,GAAG,CAAC;IAChD,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,GAAG,IAAI,CAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACpF,OAAO,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/decode.ts — `decodePack` (PRD 41 A11). Guards run before any row is built: the
|
|
3
|
+
* magic and version, the CRC-32 of the header and the decoded body, the inflate cap (`PackTooLargeError` past
|
|
4
|
+
* `maxDecodedBytes`) and the string/row counts. A malformed pack is a `PackFormatError`.
|
|
5
|
+
*/
|
|
6
|
+
import { type Pack, type PackLimits } from './types.js';
|
|
7
|
+
/** The frame's header, without inflating the body (cheap: for routing and the generation check). */
|
|
8
|
+
export declare function peekPack(bytes: Uint8Array): {
|
|
9
|
+
rootId: string;
|
|
10
|
+
baseGeneration: number;
|
|
11
|
+
targetDigest: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function decodePack(bytes: Uint8Array, limits?: Partial<PackLimits>): Promise<Pack>;
|
|
14
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/knowledge/pack/decode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EAA0C,KAAK,IAAI,EAAE,KAAK,UAAU,EAAmB,MAAM,YAAY,CAAC;AAKjH,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAG5G;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCnG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/decode.ts — `decodePack` (PRD 41 A11). Guards run before any row is built: the
|
|
3
|
+
* magic and version, the CRC-32 of the header and the decoded body, the inflate cap (`PackTooLargeError` past
|
|
4
|
+
* `maxDecodedBytes`) and the string/row counts. A malformed pack is a `PackFormatError`.
|
|
5
|
+
*/
|
|
6
|
+
import { crc32 } from './crc32.js';
|
|
7
|
+
import { inflateRaw } from './deflate.js';
|
|
8
|
+
import { FLAG_DEFLATED, readFrame, readSections } from './frame.js';
|
|
9
|
+
import { ROW_SECTIONS, TAG } from './sections/index.js';
|
|
10
|
+
import { readHashTable, readStringTable, readTables } from './strings.js';
|
|
11
|
+
import { DEFAULT_PACK_LIMITS, PackTooLargeError } from './types.js';
|
|
12
|
+
import { PackFormatError } from './varint.js';
|
|
13
|
+
const NONE = new Uint8Array([0]);
|
|
14
|
+
/** The frame's header, without inflating the body (cheap: for routing and the generation check). */
|
|
15
|
+
export function peekPack(bytes) {
|
|
16
|
+
const { header } = readFrame(bytes);
|
|
17
|
+
return { rootId: header.rootId, baseGeneration: header.baseGeneration, targetDigest: header.targetDigest };
|
|
18
|
+
}
|
|
19
|
+
export async function decodePack(bytes, limits = {}) {
|
|
20
|
+
const base0 = { ...DEFAULT_PACK_LIMITS, ...limits };
|
|
21
|
+
// ONE row budget for the whole pack: every list of every section draws from it.
|
|
22
|
+
const lim = { ...base0, budget: { left: base0.maxRows } };
|
|
23
|
+
const { header, headerBytes, stored, crc } = readFrame(bytes);
|
|
24
|
+
let body;
|
|
25
|
+
if (header.flags & FLAG_DEFLATED) {
|
|
26
|
+
try {
|
|
27
|
+
body = await inflateRaw(stored, lim.maxDecodedBytes);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof PackTooLargeError)
|
|
31
|
+
throw error;
|
|
32
|
+
throw new PackFormatError('corrupt deflate stream');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (stored.length > lim.maxDecodedBytes)
|
|
37
|
+
throw new PackTooLargeError(lim.maxDecodedBytes);
|
|
38
|
+
body = stored;
|
|
39
|
+
}
|
|
40
|
+
if (crc32(body, crc32(headerBytes)) !== crc)
|
|
41
|
+
throw new PackFormatError('CRC-32 mismatch');
|
|
42
|
+
try {
|
|
43
|
+
const sections = readSections(body);
|
|
44
|
+
const strings = readStringTable(sections.get(TAG.STR) ?? NONE, lim.maxStrings, lim.maxDecodedBytes);
|
|
45
|
+
const hashes = readHashTable(sections.get(TAG.HASH) ?? NONE, lim.maxStrings);
|
|
46
|
+
const used = new Set();
|
|
47
|
+
const base = readTables(strings, hashes);
|
|
48
|
+
const tables = { str: base.str, hash: (i) => { const h = base.hash(i); used.add(h); return h; } };
|
|
49
|
+
const pack = { rootId: header.rootId, baseGeneration: header.baseGeneration, targetDigest: header.targetDigest };
|
|
50
|
+
for (const s of ROW_SECTIONS) {
|
|
51
|
+
const bytes = sections.get(s.tag);
|
|
52
|
+
if (bytes)
|
|
53
|
+
s.read(bytes, tables, lim, pack);
|
|
54
|
+
}
|
|
55
|
+
const extra = hashes.filter((h) => !used.has(h));
|
|
56
|
+
if (extra.length > 0)
|
|
57
|
+
pack.hashes = extra;
|
|
58
|
+
return pack;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof PackFormatError || error instanceof PackTooLargeError)
|
|
62
|
+
throw error;
|
|
63
|
+
throw new PackFormatError(error instanceof Error ? error.message : 'malformed pack');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/knowledge/pack/decode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAA+C,MAAM,YAAY,CAAC;AACjH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,IAAI,GAAG,IA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AChD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAC1C,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,KAAK,YAAY,eAAe,IAAI,KAAK,YAAY,iBAAiB;YAAE,MAAM,KAAK,CAAC;QACxF,MAAM,IAAI,eAAe,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACzF,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/deflate.ts — `deflate-raw` through `CompressionStream` / `DecompressionStream`, which
|
|
3
|
+
* Node 18+, Cloudflare Workers and browsers all have (PRD 41 A11). Inflation is CAPPED: a stream that
|
|
4
|
+
* produces more than `maxBytes` is cancelled at once, so a bomb never holds more than the cap.
|
|
5
|
+
*/
|
|
6
|
+
export declare const deflateRaw: (data: Uint8Array) => Promise<Uint8Array>;
|
|
7
|
+
/** Throws {@link PackTooLargeError} past `maxBytes` of output, and `Error` on a corrupt stream. */
|
|
8
|
+
export declare const inflateRaw: (data: Uint8Array, maxBytes: number) => Promise<Uint8Array>;
|
|
9
|
+
//# sourceMappingURL=deflate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deflate.d.ts","sourceRoot":"","sources":["../../../src/knowledge/pack/deflate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiCH,eAAO,MAAM,UAAU,SAAU,UAAU,KAAG,OAAO,CAAC,UAAU,CACyB,CAAC;AAE1F,mGAAmG;AACnG,eAAO,MAAM,UAAU,SAAU,UAAU,YAAY,MAAM,KAAG,OAAO,CAAC,UAAU,CACN,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/deflate.ts — `deflate-raw` through `CompressionStream` / `DecompressionStream`, which
|
|
3
|
+
* Node 18+, Cloudflare Workers and browsers all have (PRD 41 A11). Inflation is CAPPED: a stream that
|
|
4
|
+
* produces more than `maxBytes` is cancelled at once, so a bomb never holds more than the cap.
|
|
5
|
+
*/
|
|
6
|
+
import { PackTooLargeError } from './types.js';
|
|
7
|
+
async function drain(stream, maxBytes) {
|
|
8
|
+
const reader = stream.getReader();
|
|
9
|
+
const chunks = [];
|
|
10
|
+
let total = 0;
|
|
11
|
+
for (;;) {
|
|
12
|
+
const { done, value } = await reader.read();
|
|
13
|
+
if (done)
|
|
14
|
+
break;
|
|
15
|
+
total += value.length;
|
|
16
|
+
if (total > maxBytes) {
|
|
17
|
+
await reader.cancel().catch(() => undefined);
|
|
18
|
+
throw new PackTooLargeError(maxBytes);
|
|
19
|
+
}
|
|
20
|
+
chunks.push(value);
|
|
21
|
+
}
|
|
22
|
+
const out = new Uint8Array(total);
|
|
23
|
+
let at = 0;
|
|
24
|
+
for (const c of chunks) {
|
|
25
|
+
out.set(c, at);
|
|
26
|
+
at += c.length;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
async function through(data, transform, maxBytes) {
|
|
31
|
+
const writer = transform.writable.getWriter();
|
|
32
|
+
// Written without waiting: the reader below must drain it, or a large input would stall on backpressure.
|
|
33
|
+
const wrote = writer.write(data).then(() => writer.close());
|
|
34
|
+
wrote.catch(() => undefined);
|
|
35
|
+
try {
|
|
36
|
+
return await drain(transform.readable, maxBytes);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
await wrote.catch(() => undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export const deflateRaw = (data) => through(data, new CompressionStream('deflate-raw'), Number.MAX_SAFE_INTEGER);
|
|
43
|
+
/** Throws {@link PackTooLargeError} past `maxBytes` of output, and `Error` on a corrupt stream. */
|
|
44
|
+
export const inflateRaw = (data, maxBytes) => through(data, new DecompressionStream('deflate-raw'), maxBytes);
|
|
45
|
+
//# sourceMappingURL=deflate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deflate.js","sourceRoot":"","sources":["../../../src/knowledge/pack/deflate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,KAAK,CAAC,MAAkC,EAAE,QAAgB;IACrE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,SAAS,CAAC;QACN,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAChB,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC;QACtB,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YAAC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAAC,MAAM,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAAC,CAAC;QAC9G,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAAC,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC;IAAC,CAAC;IAC3D,OAAO,GAAG,CAAC;AACf,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,IAAgB,EAAE,SAA2F,EAAE,QAAgB;IAClJ,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC9C,yGAAyG;IACzG,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAA+B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACvF,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAI,CAAC;QACD,OAAO,MAAM,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC;YAAS,CAAC;QACP,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAgB,EAAuB,EAAE,CAChE,OAAO,CAAC,IAAI,EAAE,IAAI,iBAAiB,CAAC,aAAa,CAAU,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE1F,mGAAmG;AACnG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAgB,EAAE,QAAgB,EAAuB,EAAE,CAClF,OAAO,CAAC,IAAI,EAAE,IAAI,mBAAmB,CAAC,aAAa,CAAU,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/encode.ts — `encodePack` and `normalizePack` (PRD 41 A11).
|
|
3
|
+
*
|
|
4
|
+
* Deterministic: rows are put in canonical order first, the tables are sorted, and every section
|
|
5
|
+
* is written from the same normalized pack, so equal input (in any row order) gives equal bytes.
|
|
6
|
+
* Two passes over the section writers: the first collects every string and hash they use, the
|
|
7
|
+
* second writes real table indexes.
|
|
8
|
+
*
|
|
9
|
+
* NORMALISATION (lossless for every value the model produces, documented where it is not): rows are sorted and
|
|
10
|
+
* empty parts dropped; object keys of badges and of the analysis document are written in sorted order; a
|
|
11
|
+
* negative zero is written as zero; a string holding a lone UTF-16 surrogate is written with U+FFFD in its place
|
|
12
|
+
* (UTF-8 cannot carry it). Equal normalised input gives equal bytes.
|
|
13
|
+
*/
|
|
14
|
+
import type { Pack } from './types.js';
|
|
15
|
+
/** The pack in canonical form: rows sorted, empty parts dropped, `hashes` reduced to those no section references. */
|
|
16
|
+
export declare function normalizePack(pack: Pack): Pack;
|
|
17
|
+
export interface EncodeOptions {
|
|
18
|
+
/** Deflate the body (default true). Off, the bytes are the plain columnar form (tests, size comparisons). */
|
|
19
|
+
deflate?: boolean;
|
|
20
|
+
/** Filled with the size of the DECODED body: a client cuts a pack by it before the server's cap refuses it. */
|
|
21
|
+
stats?: {
|
|
22
|
+
decodedBytes: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function encodePack(input: Pack, opts?: EncodeOptions): Promise<Uint8Array>;
|
|
26
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/knowledge/pack/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAanD,qHAAqH;AACrH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAyB9C;AAED,MAAM,WAAW,aAAa;IAC1B,6GAA6G;IAC7G,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+GAA+G;IAC/G,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;CACpC;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAqB3F"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/encode.ts — `encodePack` and `normalizePack` (PRD 41 A11).
|
|
3
|
+
*
|
|
4
|
+
* Deterministic: rows are put in canonical order first, the tables are sorted, and every section
|
|
5
|
+
* is written from the same normalized pack, so equal input (in any row order) gives equal bytes.
|
|
6
|
+
* Two passes over the section writers: the first collects every string and hash they use, the
|
|
7
|
+
* second writes real table indexes.
|
|
8
|
+
*
|
|
9
|
+
* NORMALISATION (lossless for every value the model produces, documented where it is not): rows are sorted and
|
|
10
|
+
* empty parts dropped; object keys of badges and of the analysis document are written in sorted order; a
|
|
11
|
+
* negative zero is written as zero; a string holding a lone UTF-16 surrogate is written with U+FFFD in its place
|
|
12
|
+
* (UTF-8 cannot carry it). Equal normalised input gives equal bytes.
|
|
13
|
+
*/
|
|
14
|
+
import { deflateRaw } from './deflate.js';
|
|
15
|
+
import { FLAG_DEFLATED, writeFrame, writeSection } from './frame.js';
|
|
16
|
+
import { ROW_SECTIONS, TAG } from './sections/index.js';
|
|
17
|
+
import { compare } from './sections/columns.js';
|
|
18
|
+
import { collector, tablesOf, writeHashTable, writeStringTable } from './strings.js';
|
|
19
|
+
import { ByteWriter } from './varint.js';
|
|
20
|
+
const nonEmpty = (xs) => (xs && xs.length > 0 ? [...xs] : undefined);
|
|
21
|
+
const byRelation = (a, b) => compare(a.from, b.from) || compare(a.to, b.to) || compare(a.kind, b.kind);
|
|
22
|
+
/** The hashes the row sections reference (a `have` request's explicit hashes are not among them). */
|
|
23
|
+
function referencedHashes(pack) {
|
|
24
|
+
const col = collector();
|
|
25
|
+
for (const s of ROW_SECTIONS)
|
|
26
|
+
s.write(pack, col);
|
|
27
|
+
return col.hashes;
|
|
28
|
+
}
|
|
29
|
+
/** The pack in canonical form: rows sorted, empty parts dropped, `hashes` reduced to those no section references. */
|
|
30
|
+
export function normalizePack(pack) {
|
|
31
|
+
const out = { rootId: pack.rootId, baseGeneration: pack.baseGeneration, targetDigest: pack.targetDigest };
|
|
32
|
+
const files = nonEmpty(pack.files)?.sort((a, b) => compare(a.path, b.path));
|
|
33
|
+
if (files)
|
|
34
|
+
out.files = files;
|
|
35
|
+
const extracted = nonEmpty(pack.extracted)?.sort((a, b) => compare(a.hash, b.hash));
|
|
36
|
+
if (extracted)
|
|
37
|
+
out.extracted = extracted;
|
|
38
|
+
const facts = nonEmpty(pack.facts)?.sort((a, b) => compare(a.key, b.key));
|
|
39
|
+
if (facts)
|
|
40
|
+
out.facts = facts;
|
|
41
|
+
const relations = nonEmpty(pack.relations)?.sort((a, b) => byRelation(a, b));
|
|
42
|
+
if (relations)
|
|
43
|
+
out.relations = relations;
|
|
44
|
+
const stale = nonEmpty(pack.stale)?.sort((a, b) => compare(a.sourceRef, b.sourceRef));
|
|
45
|
+
if (stale)
|
|
46
|
+
out.stale = stale;
|
|
47
|
+
const d = pack.deletes;
|
|
48
|
+
if (d && d.files.length + d.facts.length + d.relations.length > 0) {
|
|
49
|
+
out.deletes = { files: [...d.files].sort(compare), facts: [...d.facts].sort(compare), relations: [...d.relations].sort(byRelation) };
|
|
50
|
+
}
|
|
51
|
+
if (pack.scope)
|
|
52
|
+
out.scope = pack.scope;
|
|
53
|
+
if (pack.analysis !== undefined)
|
|
54
|
+
out.analysis = pack.analysis;
|
|
55
|
+
const leaves = nonEmpty(pack.leaves)?.sort((a, b) => compare(a.key, b.key));
|
|
56
|
+
if (leaves)
|
|
57
|
+
out.leaves = leaves;
|
|
58
|
+
if (pack.buckets)
|
|
59
|
+
out.buckets = pack.buckets;
|
|
60
|
+
const used = referencedHashes(out);
|
|
61
|
+
const extra = [...new Set(pack.hashes ?? [])].filter((h) => !used.has(h)).sort(compare);
|
|
62
|
+
if (extra.length > 0)
|
|
63
|
+
out.hashes = extra;
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
export async function encodePack(input, opts = {}) {
|
|
67
|
+
const pack = normalizePack(input);
|
|
68
|
+
const col = collector();
|
|
69
|
+
for (const s of ROW_SECTIONS)
|
|
70
|
+
s.write(pack, col);
|
|
71
|
+
const tables = tablesOf(col.strings, [...col.hashes, ...(pack.hashes ?? [])]);
|
|
72
|
+
const body = new ByteWriter();
|
|
73
|
+
writeSection(body, TAG.STR, writeStringTable(tables.strings));
|
|
74
|
+
writeSection(body, TAG.HASH, writeHashTable(tables.hashes));
|
|
75
|
+
for (const s of ROW_SECTIONS) {
|
|
76
|
+
const bytes = s.write(pack, tables);
|
|
77
|
+
if (bytes)
|
|
78
|
+
writeSection(body, s.tag, bytes);
|
|
79
|
+
}
|
|
80
|
+
const plain = body.finish();
|
|
81
|
+
if (opts.stats)
|
|
82
|
+
opts.stats.decodedBytes = plain.length;
|
|
83
|
+
const deflate = opts.deflate ?? true;
|
|
84
|
+
return writeFrame({ flags: deflate ? FLAG_DEFLATED : 0, rootId: pack.rootId, baseGeneration: pack.baseGeneration, targetDigest: pack.targetDigest }, plain, deflate ? await deflateRaw(plain) : plain);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/knowledge/pack/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,QAAQ,GAAG,CAAI,EAA4B,EAAmB,EAAE,CAAC,CAA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,KAAK,CAC5C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/extrDiff.ts — within-file diff (PRD 41 A11 rule 2): a re-extracted file sends the
|
|
3
|
+
* nodes, edges and keys that changed against the acknowledged prior extraction of the same source,
|
|
4
|
+
* plus the identities that vanished, instead of its whole extraction.
|
|
5
|
+
*
|
|
6
|
+
* Lossless by construction: `applyEntryDiff(prior, diffEntry(prior, next))` deep-equals `next`
|
|
7
|
+
* (order included). `diffEntry` returns undefined when it cannot promise that — an identity that
|
|
8
|
+
* repeats within a list, or surviving items that changed relative order — and the caller sends the whole entry.
|
|
9
|
+
*
|
|
10
|
+
* A diff arrives from an untrusted pack: `applyEntryDiff` validates it (positions integer, strictly increasing,
|
|
11
|
+
* inside the rebuilt list) and throws on a malformed one.
|
|
12
|
+
*/
|
|
13
|
+
import type { Extracted } from './types.js';
|
|
14
|
+
import type { ExtrEntryDiff } from './types.js';
|
|
15
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
16
|
+
export declare function diffEntry(prior: Extracted, next: Extracted): ExtrEntryDiff | undefined;
|
|
17
|
+
export declare function applyEntryDiff(prior: Extracted, diff: ExtrEntryDiff): Extracted;
|
|
18
|
+
/**
|
|
19
|
+
* The entries of `next` as diffs against the entries of `prior` with the same `sourceRef`, or undefined
|
|
20
|
+
* when any entry has no usable prior (then the hash is sent whole). A diff only pays when it is smaller:
|
|
21
|
+
* the caller compares sizes if it cares; this decides only what is possible.
|
|
22
|
+
*/
|
|
23
|
+
export declare function diffEntries(prior: readonly Extracted[], next: readonly Extracted[]): ExtrEntryDiff[] | undefined;
|
|
24
|
+
/** Rebuilds a hash's entries from its diffs and the prior hash's entries; throws when a prior entry is missing or a diff is malformed. */
|
|
25
|
+
export declare function applyEntryDiffs(prior: readonly Extracted[], diffs: readonly ExtrEntryDiff[]): Extracted[];
|
|
26
|
+
//# sourceMappingURL=extrDiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extrDiff.d.ts","sourceRoot":"","sources":["../../../src/knowledge/pack/extrDiff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,YAAY,CAAC;AAE1D,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQzD;AA6CD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,aAAa,GAAG,SAAS,CAWtF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,SAAS,CAQ/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,aAAa,EAAE,GAAG,SAAS,CAShH;AAED,0IAA0I;AAC1I,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,EAAE,CAMzG"}
|