@seanhogg/builderforce-memory 2026.10.80 → 2026.10.81
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/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +40 -3
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/cooperative.d.ts +51 -0
- package/dist/knowledge/cooperative.d.ts.map +1 -0
- package/dist/knowledge/cooperative.js +58 -0
- package/dist/knowledge/cooperative.js.map +1 -0
- package/dist/knowledge/ignoreMatcher.d.ts +25 -0
- package/dist/knowledge/ignoreMatcher.d.ts.map +1 -0
- package/dist/knowledge/ignoreMatcher.js +121 -0
- package/dist/knowledge/ignoreMatcher.js.map +1 -0
- package/dist/knowledge/index.d.ts +4 -0
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +3 -0
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/plan.d.ts +6 -0
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +17 -1
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/reviewAnalyse.d.ts.map +1 -1
- package/dist/knowledge/reviewAnalyse.js +6 -1
- package/dist/knowledge/reviewAnalyse.js.map +1 -1
- package/dist/knowledge/reviewFinish.d.ts.map +1 -1
- package/dist/knowledge/reviewFinish.js +7 -1
- package/dist/knowledge/reviewFinish.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +10 -0
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.js +24 -1
- package/dist/knowledge/rules/factStore.js.map +1 -1
- package/dist/knowledge/rules/fixpointRules.d.ts +68 -0
- package/dist/knowledge/rules/fixpointRules.d.ts.map +1 -0
- package/dist/knowledge/rules/fixpointRules.js +0 -0
- package/dist/knowledge/rules/fixpointRules.js.map +1 -0
- package/dist/knowledge/sources.d.ts +9 -9
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +11 -50
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/statManifest.d.ts +89 -0
- package/dist/knowledge/statManifest.d.ts.map +1 -0
- package/dist/knowledge/statManifest.js +125 -0
- package/dist/knowledge/statManifest.js.map +1 -0
- package/dist/stats/estimators.d.ts +8 -1
- package/dist/stats/estimators.d.ts.map +1 -1
- package/dist/stats/estimators.js +18 -7
- package/dist/stats/estimators.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +11 -0
- package/src/contract/regression.assets.test.ts +2 -2
- package/src/contract/regression.factStoreBatchedLoad.test.ts +62 -0
- package/src/contract/regression.ignoreMatcher.test.ts +116 -0
- package/src/knowledge/build.ts +32 -3
- package/src/knowledge/cooperative.test.ts +57 -0
- package/src/knowledge/cooperative.ts +76 -0
- package/src/knowledge/docs.test.ts +30 -0
- package/src/knowledge/ignoreMatcher.ts +143 -0
- package/src/knowledge/index.ts +7 -0
- package/src/knowledge/plan.ts +20 -1
- package/src/knowledge/reviewAnalyse.ts +6 -1
- package/src/knowledge/reviewFinish.ts +7 -1
- package/src/knowledge/reviewModel.ts +6 -0
- package/src/knowledge/rules/factStore.ts +22 -1
- package/src/knowledge/rules/fixpointRules.test.ts +94 -0
- package/src/knowledge/rules/fixpointRules.ts +0 -0
- package/src/knowledge/sources.ts +12 -46
- package/src/knowledge/statManifest.test.ts +122 -0
- package/src/knowledge/statManifest.ts +176 -0
- package/src/stats/estimators.ts +18 -7
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
import { canonicalJson, compareStr } from '../refs.js';
|
|
36
|
+
import { cooperativeBudget, type CooperativeBudget } from '../cooperative.js';
|
|
36
37
|
import { readFileFacts, type FileFacts } from '../facts/fileFacts.js';
|
|
37
38
|
import { factKindHashes, factsHash, factsJson } from '../facts/factsHash.js';
|
|
38
39
|
import { derivedRowKey, type DerivedRow } from './evaluateRules.js';
|
|
@@ -191,11 +192,30 @@ export interface LoadFactGraphOptions {
|
|
|
191
192
|
/** How many times a load retries when a write lands under it before rejecting `fact_store_generation_conflict:load`. */
|
|
192
193
|
export const FACT_STORE_LOAD_ATTEMPTS = 3;
|
|
193
194
|
|
|
195
|
+
/**
|
|
196
|
+
* How many hashes one `getObjects` call asks for during a load. A port may serve a call synchronously (the SQLite adapter
|
|
197
|
+
* reads it in one transaction on the caller's thread), so a load asks in bounded batches and yields between them.
|
|
198
|
+
*/
|
|
199
|
+
const LOAD_OBJECTS_BATCH = 512;
|
|
200
|
+
|
|
201
|
+
/** Every object of `hashes` the port holds, read in {@link LOAD_OBJECTS_BATCH}-sized calls with a yield between them. */
|
|
202
|
+
async function getObjectsBatched(port: FactStorePort, hashes: readonly string[], budget: CooperativeBudget): Promise<Map<string, string>> {
|
|
203
|
+
const raw = new Map<string, string>();
|
|
204
|
+
for (let i = 0; i < hashes.length; i += LOAD_OBJECTS_BATCH) {
|
|
205
|
+
if (i > 0 && budget.due()) await budget.pause();
|
|
206
|
+
for (const [hash, json] of await port.getObjects(hashes.slice(i, i + LOAD_OBJECTS_BATCH))) raw.set(hash, json);
|
|
207
|
+
}
|
|
208
|
+
return raw;
|
|
209
|
+
}
|
|
210
|
+
|
|
194
211
|
async function loadOnce(port: FactStorePort, stored: FactStoreManifest, verify: 'full' | 'manifest'): Promise<FactGraph> {
|
|
212
|
+
// A host may load on its UI thread: parsing and hashing every object hands the event loop back (cooperative.ts).
|
|
213
|
+
const budget = cooperativeBudget();
|
|
195
214
|
const hashes = [...new Set([...stored.files.values()].map((e) => e.factsHash))].sort(compareStr);
|
|
196
|
-
const raw = await port
|
|
215
|
+
const raw = await getObjectsBatched(port, hashes, budget);
|
|
197
216
|
const objects = new Map<string, FileFacts>();
|
|
198
217
|
for (const hash of hashes) {
|
|
218
|
+
if (budget.due()) await budget.pause();
|
|
199
219
|
const json = raw.get(hash);
|
|
200
220
|
if (json === undefined) throw new Error(`fact_store_object_missing:${hash}`);
|
|
201
221
|
let facts: FileFacts;
|
|
@@ -209,6 +229,7 @@ async function loadOnce(port: FactStorePort, stored: FactStoreManifest, verify:
|
|
|
209
229
|
}
|
|
210
230
|
const manifest = new Map<string, FactManifestEntry>();
|
|
211
231
|
for (const path of [...stored.files.keys()].sort(compareStr)) {
|
|
232
|
+
if (budget.due()) await budget.pause();
|
|
212
233
|
const e = stored.files.get(path)!;
|
|
213
234
|
const facts = objects.get(e.factsHash)!;
|
|
214
235
|
const entry: FactManifestEntry = { contentHash: facts.contentHash, factsHash: e.factsHash, kinds: factKindHashes(facts) };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/rules/fixpointRules.test.ts — the stratified fixed-point evaluator (PRD 41 §B5):
|
|
3
|
+
* strata from the declared derived-row edges, order-independent results, bounded iterations,
|
|
4
|
+
* a fixed point that reuses every row on the final pass, and rejection of recursive rules.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { FileFacts } from '../facts/fileFacts.js';
|
|
8
|
+
import { derivedRowKey } from './evaluateRules.js';
|
|
9
|
+
import { defineRule } from './factRule.js';
|
|
10
|
+
import { evaluateRulesFixpoint, MAX_FIXPOINT_ITERATIONS, type SourcedRule } from './fixpointRules.js';
|
|
11
|
+
import { emptyFacts, FIXTURE_RULES } from './rules.testkit.test-util.js';
|
|
12
|
+
|
|
13
|
+
const files = (): Map<string, FileFacts> => new Map([
|
|
14
|
+
['a.ts', { ...emptyFacts('ha'), calls: [{ callee: 'db.get', enclosing: 'a', awaited: true, inLoop: true, count: 3 }] }],
|
|
15
|
+
['b.ts', { ...emptyFacts('hb'), calls: [{ callee: 'fs.read', enclosing: 'b', awaited: false, inLoop: true, count: 5 }] }],
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/** A global rule whose `seen` input is the io-in-loop rule's row for focus '' (its global row). */
|
|
19
|
+
const ioTotal = defineRule<{ seen?: { findings: unknown[] } }>({
|
|
20
|
+
id: 'io-total', version: 1, reads: ['body'], scope: 'global', extraInputs: ['seen'],
|
|
21
|
+
derive: ({ files: fs, extra }) => {
|
|
22
|
+
const own = [...fs.values()].reduce((s, x) => s + x.calls.filter((c) => c.inLoop && c.awaited).length, 0);
|
|
23
|
+
const upstream = (extra.seen?.findings ?? []).length;
|
|
24
|
+
return upstream + own > 0
|
|
25
|
+
? [{ id: `io-total:${own + upstream}`, kind: 'io-total', pack: 'fixture', nodes: [], severity: 'info', params: { total: own + upstream } }]
|
|
26
|
+
: [];
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const ioTotalSourced: SourcedRule<{ seen?: { findings: unknown[] } }> = {
|
|
31
|
+
rule: ioTotal,
|
|
32
|
+
rowSources: { seen: { rowKey: derivedRowKey('io-in-loop', '') } },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const plain = FIXTURE_RULES.map((rule) => ({ rule }));
|
|
36
|
+
|
|
37
|
+
describe('evaluateRulesFixpoint: stratified semi-naive fixed point', () => {
|
|
38
|
+
it('places row-reading rules above their producers and reaches a fixed point', () => {
|
|
39
|
+
const r = evaluateRulesFixpoint([...plain, ioTotalSourced], { files: files() });
|
|
40
|
+
// Strata: every FIXTURE_RULE (no row sources) at 0; io-total (reads io-in-loop's row) at 1.
|
|
41
|
+
expect(r.strata).toHaveLength(2);
|
|
42
|
+
expect(r.strata[1]).toEqual(['io-total']);
|
|
43
|
+
// a.ts has 1 awaited io-in-loop call; the global row feeds io-total.
|
|
44
|
+
expect(r.evaluation.findings.map((x) => x.id)).toContain('io-total:1');
|
|
45
|
+
// The fixed point is audited: at least one iteration per stratum; the final pass reused rows.
|
|
46
|
+
expect(r.iterations).toHaveLength(2);
|
|
47
|
+
expect(r.iterations.every((n) => n >= 1)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('is order-independent: registration order never changes the rows or strata', () => {
|
|
51
|
+
const a = evaluateRulesFixpoint([...plain, ioTotalSourced].reverse(), { files: files() });
|
|
52
|
+
const b = evaluateRulesFixpoint([...plain, ioTotalSourced], { files: files() });
|
|
53
|
+
expect([...a.evaluation.rows.keys()].sort()).toEqual([...b.evaluation.rows.keys()].sort());
|
|
54
|
+
expect(a.evaluation.findings.map((x) => x.id).sort()).toEqual(b.evaluation.findings.map((x) => x.id).sort());
|
|
55
|
+
expect(a.strata).toEqual(b.strata);
|
|
56
|
+
expect(a.iterations).toEqual(b.iterations);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('reuses every row on a no-change rerun (early cutoff holds across the fixpoint)', () => {
|
|
60
|
+
const first = evaluateRulesFixpoint([...plain, ioTotalSourced], { files: files() });
|
|
61
|
+
const second = evaluateRulesFixpoint([...plain, ioTotalSourced], { files: files() }, first.evaluation.rows);
|
|
62
|
+
expect(second.evaluation.trace.filter((t) => t.outcome === 'ran')).toEqual([]);
|
|
63
|
+
expect(second.evaluation.findings.map((x) => x.id).sort()).toEqual(first.evaluation.findings.map((x) => x.id).sort());
|
|
64
|
+
expect(second.iterations.every((n) => n === 1)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('rejects a recursive derived-row cycle as unstratifiable', () => {
|
|
68
|
+
const cycA = defineRule<{ b?: unknown }>({ id: 'cyc-a', version: 1, reads: [], scope: 'global', extraInputs: ['b'], derive: () => [] });
|
|
69
|
+
const cycB = defineRule<{ a?: unknown }>({ id: 'cyc-b', version: 1, reads: [], scope: 'global', extraInputs: ['a'], derive: () => [] });
|
|
70
|
+
const a: SourcedRule<{ b?: unknown }> = { rule: cycA, rowSources: { b: { rowKey: derivedRowKey('cyc-b', '') } } };
|
|
71
|
+
const b: SourcedRule<{ a?: unknown }> = { rule: cycB, rowSources: { a: { rowKey: derivedRowKey('cyc-a', '') } } };
|
|
72
|
+
expect(() => evaluateRulesFixpoint([a, b], { files: new Map() })).toThrow(/fact_rule_unstratifiable/);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('rejects a self-reading rule as unstratifiable and never runs it', () => {
|
|
76
|
+
let calls = 0;
|
|
77
|
+
const noisy = defineRule<{ self?: { findings: unknown[] } }>({
|
|
78
|
+
id: 'noisy', version: 1, reads: [], scope: 'global', extraInputs: ['self'],
|
|
79
|
+
derive: () => { calls += 1; return []; },
|
|
80
|
+
});
|
|
81
|
+
const self: SourcedRule<{ self?: { findings: unknown[] } }> = { rule: noisy, rowSources: { self: { rowKey: derivedRowKey('noisy', '') } } };
|
|
82
|
+
expect(() => evaluateRulesFixpoint([self], { files: new Map() })).toThrow(/fact_rule_unstratifiable/);
|
|
83
|
+
expect(calls).toBe(0);
|
|
84
|
+
expect(MAX_FIXPOINT_ITERATIONS).toBeGreaterThan(0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('a stratum stabilizes after one pass when its row-source inputs never change', () => {
|
|
88
|
+
// io-total reads io-in-loop's row; io-in-loop is in stratum 0 and its inputs are static,
|
|
89
|
+
// so stratum 1 converges on its second pass (first computes, second reuses) or first reuse.
|
|
90
|
+
const r = evaluateRulesFixpoint([...plain, ioTotalSourced], { files: files() });
|
|
91
|
+
// Stratum 0 (7 rules) iterates until reuse; stratum 1 (io-total) needs at most 2 iterations.
|
|
92
|
+
expect(r.iterations[1]).toBeLessThanOrEqual(2);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
Binary file
|
package/src/knowledge/sources.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { htmlParser, markdownParser, ParserRegistry, plainTextParser } from '../
|
|
|
8
8
|
import { isBinaryDocumentType, mediaTypeOf } from '../ingest/parserSupport.js';
|
|
9
9
|
import { CONTENT_HASH_FIELD, type ChunkFingerprint, type IngestManifest, type SourceDocument } from '../ingest/types.js';
|
|
10
10
|
import type { Extracted, KnowledgePack, KnowledgeParser } from './model.js';
|
|
11
|
-
import { matchGlob } from './partitions.js';
|
|
12
11
|
import { compareStr, walkRelative } from './refs.js';
|
|
13
12
|
|
|
14
13
|
/** Default per-file size cap (bytes). */
|
|
@@ -24,7 +23,9 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
24
23
|
// 5 (2026-11-10, PRD 43 P0b): the code pack's file nodes carry the file→file rollup of the symbol-level edge kinds.
|
|
25
24
|
// 6 (2026-11-10, PRD 43 P0c): the agent-tools code pack resolves tsconfig path aliases, names callback-owner symbols,
|
|
26
25
|
// emits `new X().m()` call edges and reads JSX renders as calls, so cached code extracts re-run.
|
|
27
|
-
|
|
26
|
+
// 7 (2026-11-10, PRD 43): the code pack extracts deploy descriptors (Dockerfile, wrangler, compose, k8s, workflows, package.json)
|
|
27
|
+
// as deployable units and adds a per-file `concurrency` badge.
|
|
28
|
+
export const EXTRACTOR_VERSION = 7;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* THE test of "this extract (or this root's extractor entry) was made by today's extractor": today's
|
|
@@ -41,13 +42,6 @@ export function isCurrentExtractor(recorded: { version: number | undefined; key:
|
|
|
41
42
|
export function sameExtractorKey(a: string | undefined, b: string | undefined): boolean {
|
|
42
43
|
return (a || undefined) === (b || undefined);
|
|
43
44
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
|
|
46
|
-
* huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
|
|
47
|
-
* A `.builderforce/ignore` rule can still re-include one (`!yarn.lock`).
|
|
48
|
-
*/
|
|
49
|
-
const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
|
|
50
|
-
|
|
51
45
|
const MEDIA_TYPES: Record<string, string> = {
|
|
52
46
|
md: 'text/markdown', markdown: 'text/markdown', mdx: 'text/markdown',
|
|
53
47
|
html: 'text/html', htm: 'text/html', xhtml: 'application/xhtml+xml', xml: 'application/xml',
|
|
@@ -78,6 +72,13 @@ const MEDIA_TYPES: Record<string, string> = {
|
|
|
78
72
|
/** Binary documents whose text a HOST extractor may supply (§4.5); otherwise stored as an asset (never read). */
|
|
79
73
|
const DOCUMENT_EXT = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
|
|
80
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A markdown/html/text link target with no extension may name a sibling document (`troubleshooting` →
|
|
77
|
+
* `troubleshooting.md`). The set of extensions a target may resolve to — the docs pack's broken-link rule
|
|
78
|
+
* only judges targets that match these, so a target it would never flag is not resolved here either.
|
|
79
|
+
*/
|
|
80
|
+
export const LINKABLE_DOC_EXT = ['md', 'markdown', 'mdx', 'html', 'htm', 'txt', 'rst', 'adoc'];
|
|
81
|
+
|
|
81
82
|
const BINARY_EXT = new Set([
|
|
82
83
|
'png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'icns', 'tif', 'tiff', 'psd', 'avif', 'heic',
|
|
83
84
|
'mp3', 'mp4', 'mov', 'avi', 'mkv', 'webm', 'wav', 'flac', 'ogg', 'm4a',
|
|
@@ -217,43 +218,8 @@ export function composePacks(packs: readonly KnowledgePack[]): ComposedPacks {
|
|
|
217
218
|
};
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
/**
|
|
221
|
-
|
|
222
|
-
* `/` for directories only, a `/` elsewhere anchors to the root, otherwise any depth.
|
|
223
|
-
*/
|
|
224
|
-
export function ignoreMatcher(texts: ReadonlyArray<string | { text: string; base: string }>): (path: string) => boolean {
|
|
225
|
-
const rules: Array<{ glob: string; negate: boolean; dirOnly: boolean }> = [];
|
|
226
|
-
const lines = [
|
|
227
|
-
...DEFAULT_IGNORES.map((line) => ({ line, base: '' })),
|
|
228
|
-
...texts.flatMap((t) => {
|
|
229
|
-
const { text, base } = typeof t === 'string' ? { text: t, base: '' } : t;
|
|
230
|
-
return text.split(/\r?\n/).map((line) => ({ line, base }));
|
|
231
|
-
}),
|
|
232
|
-
];
|
|
233
|
-
for (const { line, base } of lines) {
|
|
234
|
-
let p = line.replace(/\s+$/, '');
|
|
235
|
-
if (!p || p.startsWith('#')) continue;
|
|
236
|
-
const negate = p.startsWith('!');
|
|
237
|
-
if (negate) p = p.slice(1);
|
|
238
|
-
const dirOnly = p.endsWith('/');
|
|
239
|
-
if (dirOnly) p = p.slice(0, -1);
|
|
240
|
-
const anchored = p.includes('/');
|
|
241
|
-
p = p.replace(/^\//, '');
|
|
242
|
-
// A nested `.gitignore` scopes its patterns to its own folder.
|
|
243
|
-
const prefix = base ? `${base}/` : '';
|
|
244
|
-
if (p) rules.push({ glob: anchored ? `${prefix}${p}` : `${prefix}**/${p}`, negate, dirOnly });
|
|
245
|
-
}
|
|
246
|
-
return (path) => {
|
|
247
|
-
const segments = path.split('/');
|
|
248
|
-
const dirs = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join('/'));
|
|
249
|
-
let ignored = false;
|
|
250
|
-
for (const r of rules) {
|
|
251
|
-
const hit = (r.dirOnly ? dirs : [...dirs, path]).some((c) => matchGlob(c, r.glob));
|
|
252
|
-
if (hit) ignored = !r.negate;
|
|
253
|
-
}
|
|
254
|
-
return ignored;
|
|
255
|
-
};
|
|
256
|
-
}
|
|
221
|
+
/** The `.gitignore`-style matcher lives in its own module (ignoreMatcher.ts); re-exported here, where callers import it. */
|
|
222
|
+
export { ignoreMatcher } from './ignoreMatcher.js';
|
|
257
223
|
|
|
258
224
|
/**
|
|
259
225
|
* The ignore files present in a listing, each with the folder its patterns are relative to,
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/statManifest.test.ts — the stat prefilter (PRD 41 §B2 steps 1–2): a size+mtimeNs+fileId
|
|
3
|
+
* manifest lets a warm plan reuse a stored hash without reading the file, and git's racy-file rule
|
|
4
|
+
* re-hashes a file whose mtime is within 2 s of the manifest write or of now.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { jest } from '@jest/globals';
|
|
8
|
+
import {
|
|
9
|
+
createStatPrefilter, isRacy, loadStatManifest, prefilterStats, RACY_WINDOW_MS, saveStatManifest, statMatches,
|
|
10
|
+
type StatManifestEntry, type StatRecord,
|
|
11
|
+
} from './statManifest.js';
|
|
12
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
13
|
+
|
|
14
|
+
const stat = (size: number, mtimeNs: bigint, fileId: bigint | null = null): StatRecord => ({ size, mtimeNs, fileId });
|
|
15
|
+
const entry = (size: number, mtimeNs: bigint, hash: string, recordedAtMs: number, fileId: bigint | null = null): StatManifestEntry =>
|
|
16
|
+
({ size, mtimeNs, fileId, hash, recordedAtMs });
|
|
17
|
+
|
|
18
|
+
const NOW = 1_000_000;
|
|
19
|
+
// An mtime far from both `recordedAtMs` and NOW so the racy rule does not fire unless a test moves it.
|
|
20
|
+
const OLD_MTIME = BigInt((NOW - 60_000) * 1_000_000);
|
|
21
|
+
|
|
22
|
+
describe('statMatches', () => {
|
|
23
|
+
it('requires size, full-precision mtimeNs and fileId', () => {
|
|
24
|
+
expect(statMatches(stat(10, OLD_MTIME, 5n), stat(10, OLD_MTIME, 5n))).toBe(true);
|
|
25
|
+
expect(statMatches(stat(10, OLD_MTIME, 5n), stat(11, OLD_MTIME, 5n))).toBe(false); // size moved
|
|
26
|
+
expect(statMatches(stat(10, OLD_MTIME, 5n), stat(10, OLD_MTIME + 1n, 5n))).toBe(false); // ns mtime moved
|
|
27
|
+
expect(statMatches(stat(10, OLD_MTIME, 5n), stat(10, OLD_MTIME, 6n))).toBe(false); // fileId moved
|
|
28
|
+
expect(statMatches(stat(10, OLD_MTIME, null), stat(10, OLD_MTIME, 6n))).toBe(false); // null matches only null
|
|
29
|
+
expect(statMatches(stat(10, OLD_MTIME, null), stat(10, OLD_MTIME, null))).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('isRacy (git racy-file rule, §B2 step 2)', () => {
|
|
34
|
+
it('is racy within 2 s of the manifest write time', () => {
|
|
35
|
+
expect(isRacy(stat(1, BigInt((NOW - RACY_WINDOW_MS + 1) * 1_000_000)), NOW, NOW)).toBe(true);
|
|
36
|
+
expect(isRacy(stat(1, BigInt((NOW + RACY_WINDOW_MS - 1) * 1_000_000)), NOW, NOW)).toBe(true);
|
|
37
|
+
expect(isRacy(stat(1, BigInt((NOW - RACY_WINDOW_MS - 1) * 1_000_000)), NOW, NOW)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('is racy within 2 s of now, whatever the manifest says', () => {
|
|
40
|
+
expect(isRacy(stat(1, BigInt(NOW * 1_000_000)), NOW - 60_000, NOW)).toBe(true);
|
|
41
|
+
expect(isRacy(stat(1, BigInt((NOW - 10_000) * 1_000_000)), NOW - 60_000, NOW)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('prefilterStats', () => {
|
|
46
|
+
const prior = new Map<string, StatManifestEntry>([
|
|
47
|
+
['a.ts', entry(10, OLD_MTIME, 'h-a', NOW)],
|
|
48
|
+
['b.ts', entry(20, OLD_MTIME, 'h-b', NOW)],
|
|
49
|
+
['c.ts', entry(30, OLD_MTIME, 'h-c', NOW)],
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
it('reuses the stored hash on a stat match and hashes everything else, both sorted', () => {
|
|
53
|
+
const decision = prefilterStats(
|
|
54
|
+
[
|
|
55
|
+
{ path: 'c.ts', stat: stat(30, OLD_MTIME) },
|
|
56
|
+
{ path: 'a.ts', stat: stat(10, OLD_MTIME) },
|
|
57
|
+
{ path: 'b.ts', stat: stat(21, OLD_MTIME) }, // size moved → hash
|
|
58
|
+
{ path: 'd.ts', stat: stat(40, OLD_MTIME) }, // new → hash
|
|
59
|
+
],
|
|
60
|
+
prior, NOW,
|
|
61
|
+
);
|
|
62
|
+
expect(decision.reused).toEqual(['a.ts', 'c.ts']);
|
|
63
|
+
expect(decision.hash).toEqual(['b.ts', 'd.ts']);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('re-hashes a racy file whatever its stat says', () => {
|
|
67
|
+
const racyMtime = BigInt(NOW * 1_000_000); // within 2 s of now
|
|
68
|
+
const decision = prefilterStats([{ path: 'a.ts', stat: stat(10, racyMtime) }], prior, NOW);
|
|
69
|
+
expect(decision.reused).toEqual([]);
|
|
70
|
+
expect(decision.hash).toEqual(['a.ts']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('is deterministic: input order never changes the output', () => {
|
|
74
|
+
const listed = [
|
|
75
|
+
{ path: 'a.ts', stat: stat(10, OLD_MTIME) },
|
|
76
|
+
{ path: 'b.ts', stat: stat(20, OLD_MTIME) },
|
|
77
|
+
{ path: 'c.ts', stat: stat(30, OLD_MTIME) },
|
|
78
|
+
];
|
|
79
|
+
expect(prefilterStats([...listed].reverse(), prior, NOW)).toEqual(prefilterStats(listed, prior, NOW));
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('createStatPrefilter', () => {
|
|
84
|
+
it('returns the stored hash without reading, and hashes a moved file through hashPath', async () => {
|
|
85
|
+
const prior = new Map<string, StatManifestEntry>([['a.ts', entry(10, OLD_MTIME, 'h-a', NOW)]]);
|
|
86
|
+
const hashPath = jest.fn(async (_: string) => 'h-fresh');
|
|
87
|
+
const prefilter = createStatPrefilter(prior, hashPath, () => NOW);
|
|
88
|
+
|
|
89
|
+
await expect(prefilter({ path: 'a.ts', stat: stat(10, OLD_MTIME) })).resolves.toEqual({ path: 'a.ts', hash: 'h-a' });
|
|
90
|
+
expect(hashPath).not.toHaveBeenCalled();
|
|
91
|
+
|
|
92
|
+
await expect(prefilter({ path: 'a.ts', stat: stat(11, OLD_MTIME) })).resolves.toEqual({ path: 'a.ts', hash: 'h-fresh' });
|
|
93
|
+
expect(hashPath).toHaveBeenCalledTimes(1);
|
|
94
|
+
expect(hashPath).toHaveBeenCalledWith('a.ts');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('stat manifest persistence', () => {
|
|
99
|
+
it('round-trips BigInt stat tuples through the ingest manifest and reloads them', async () => {
|
|
100
|
+
const manifest = new InMemoryIngestManifest();
|
|
101
|
+
const fileId = 12345678901234567890n; // exceeds a double: must survive as a BigInt
|
|
102
|
+
const mtimeNs = 1700000000123456789n;
|
|
103
|
+
const files = [
|
|
104
|
+
{ path: 'src/x.ts', hash: 'h-x', stat: stat(100, mtimeNs, fileId) },
|
|
105
|
+
{ path: 'src/y.ts', hash: 'h-y', stat: stat(200, OLD_MTIME, null) },
|
|
106
|
+
];
|
|
107
|
+
await saveStatManifest(manifest, 'root', files, NOW);
|
|
108
|
+
const loaded = await loadStatManifest(manifest, 'root');
|
|
109
|
+
expect(loaded.size).toBe(2);
|
|
110
|
+
expect(loaded.get('src/x.ts')).toEqual({ size: 100, mtimeNs, fileId, hash: 'h-x', recordedAtMs: NOW });
|
|
111
|
+
expect(loaded.get('src/y.ts')).toEqual({ size: 200, mtimeNs: OLD_MTIME, fileId: null, hash: 'h-y', recordedAtMs: NOW });
|
|
112
|
+
// A warm prefilter over the reloaded manifest reuses the stored hash.
|
|
113
|
+
expect(prefilterStats([{ path: 'src/x.ts', stat: stat(100, mtimeNs, fileId) }], loaded, NOW).reused).toEqual(['src/x.ts']);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns empty on a missing manifest (the first run hashes everything) and on a corrupt one', async () => {
|
|
117
|
+
const manifest = new InMemoryIngestManifest();
|
|
118
|
+
expect((await loadStatManifest(manifest, 'root')).size).toBe(0);
|
|
119
|
+
await manifest.set('stats:root', [{ id: 'entries', hash: '{not json' }]);
|
|
120
|
+
expect((await loadStatManifest(manifest, 'root')).size).toBe(0);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/statManifest.ts — the STAT PREFILTER (PRD 41 §B2 steps 1–2): a per-root manifest of
|
|
3
|
+
* `(path, size, mtimeNs, fileId, hash, recordedAtMs)` so a warm plan reuses a stored content hash
|
|
4
|
+
* without reading the file, and only stats — never content — decide it.
|
|
5
|
+
*
|
|
6
|
+
* Rules implemented here, straight from the PRD:
|
|
7
|
+
* 0. Content identity is unchanged by this module: the stored `hash` is the host's content hash
|
|
8
|
+
* (EOL-normalized for text, raw for binary — see contentHash.ts); this manifest only caches it.
|
|
9
|
+
* 1. Stat tuple match → reuse the stored hash. Stats are BigInt (`bigint: true` from fs.stat):
|
|
10
|
+
* Windows file ids and ns mtimes lose precision as JS numbers, so {@link StatRecord} carries
|
|
11
|
+
* them as bigint and the manifest persists them as decimal strings.
|
|
12
|
+
* 2. Racy-file rule (git's index): a file whose mtime is within {@link RACY_WINDOW_MS} of the
|
|
13
|
+
* manifest's write time, or of `now` at plan time, is re-hashed whatever its stat says.
|
|
14
|
+
* 4. Directory Merkle hashes stay the identity of a subtree (merkle.ts) — this manifest never
|
|
15
|
+
* enters a digest, a cache key or the plan output (PRD 41 §B8.3: mtime is only a hint).
|
|
16
|
+
*
|
|
17
|
+
* Determinism (§B8): every output here is sorted by path; the only clock use is the injected
|
|
18
|
+
* `now` (default `Date.now`) stamping `recordedAtMs`, which is persisted metadata, never part of
|
|
19
|
+
* any digest. Hosts that need a deterministic plan inject `now`.
|
|
20
|
+
*
|
|
21
|
+
* The plan itself consumes hashes from `DirectorySource.list()`; this module is the helper a
|
|
22
|
+
* host's listing calls per file ({@link createStatPrefilter}) plus the manifest persistence the
|
|
23
|
+
* plan updates after a successful run ({@link saveStatManifest}).
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { IngestManifest } from '../ingest/types.js';
|
|
27
|
+
import { canonicalJson, compareStr, normalizePath } from './refs.js';
|
|
28
|
+
import { manifestMap, saveManifestMap } from './sources.js';
|
|
29
|
+
|
|
30
|
+
/** git's racy-window: an mtime within this many ms of the index write is re-checked next plan. */
|
|
31
|
+
export const RACY_WINDOW_MS = 2000;
|
|
32
|
+
|
|
33
|
+
/** One file's stat tuple, read with `bigint: true`. `fileId` is `ino` on POSIX, the file id on Windows; null when the host cannot say. */
|
|
34
|
+
export interface StatRecord {
|
|
35
|
+
size: number;
|
|
36
|
+
mtimeNs: bigint;
|
|
37
|
+
fileId: bigint | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A stat-manifest row: the stat tuple the hash was cached under, the hash, and when the manifest was written (ms). */
|
|
41
|
+
export interface StatManifestEntry extends StatRecord {
|
|
42
|
+
hash: string;
|
|
43
|
+
recordedAtMs: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The manifest key under the ingest manifest: one stat manifest per root. */
|
|
47
|
+
export const statManifestKey = (rootId: string): string => `stats:${rootId}`;
|
|
48
|
+
|
|
49
|
+
/** Stat-tuple equality: same size, same mtime to the nanosecond, same file id (a null fileId matches only a null fileId). */
|
|
50
|
+
export function statMatches(a: StatRecord, b: StatRecord): boolean {
|
|
51
|
+
return a.size === b.size && a.mtimeNs === b.mtimeNs && a.fileId === b.fileId;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The racy-file rule (§B2 step 2): true when the file may have been written in the same tick as
|
|
56
|
+
* the manifest — its mtime is within {@link RACY_WINDOW_MS} of the manifest's `recordedAtMs`, or
|
|
57
|
+
* of `nowMs` (a file touched just now whose mtime we are about to record). A racy file is
|
|
58
|
+
* re-hashed on the next plan whatever its stat says.
|
|
59
|
+
*/
|
|
60
|
+
export function isRacy(stat: StatRecord, recordedAtMs: number, nowMs: number): boolean {
|
|
61
|
+
const mtimeMs = Number(stat.mtimeNs / 1_000_000n);
|
|
62
|
+
return Math.abs(mtimeMs - recordedAtMs) < RACY_WINDOW_MS || Math.abs(mtimeMs - nowMs) < RACY_WINDOW_MS;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface PrefilterDecision {
|
|
66
|
+
/** Paths whose stored hash is reused (stat matched, not racy), sorted. */
|
|
67
|
+
reused: readonly string[];
|
|
68
|
+
/** Paths that must be hashed (new, stat moved, or racy), sorted. */
|
|
69
|
+
hash: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The ONE prefilter decision, pure and order-independent: a path reuses its stored hash only when
|
|
74
|
+
* its prior entry exists, the stat tuple matches, and the racy rule does not fire. Everything else
|
|
75
|
+
* is hashed. `nowMs` is the plan's clock.
|
|
76
|
+
*/
|
|
77
|
+
export function prefilterStats(
|
|
78
|
+
listed: ReadonlyArray<{ path: string; stat: StatRecord }>,
|
|
79
|
+
prior: ReadonlyMap<string, StatManifestEntry>,
|
|
80
|
+
nowMs: number,
|
|
81
|
+
): PrefilterDecision {
|
|
82
|
+
const reused: string[] = [];
|
|
83
|
+
const hash: string[] = [];
|
|
84
|
+
for (const { path, stat } of listed) {
|
|
85
|
+
const p = normalizePath(path);
|
|
86
|
+
const entry = prior.get(p);
|
|
87
|
+
if (entry && statMatches(entry, stat) && !isRacy(stat, entry.recordedAtMs, nowMs)) reused.push(p);
|
|
88
|
+
else hash.push(p);
|
|
89
|
+
}
|
|
90
|
+
reused.sort(compareStr);
|
|
91
|
+
hash.sort(compareStr);
|
|
92
|
+
return { reused, hash };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A per-file hash provider for a host's `DirectorySource.list()`: returns the stored hash when
|
|
97
|
+
* {@link prefilterStats} reuses the path, else `hashPath(path)`. `hashPath` reads the file and
|
|
98
|
+
* hashes it (EOL-normalized, per the host's content-hash rule) — the only path that reads bytes.
|
|
99
|
+
* `now` defaults to `Date.now`; inject it for deterministic plans.
|
|
100
|
+
*/
|
|
101
|
+
export function createStatPrefilter(
|
|
102
|
+
prior: ReadonlyMap<string, StatManifestEntry>,
|
|
103
|
+
hashPath: (listedPath: string) => Promise<string>,
|
|
104
|
+
now: () => number = () => Date.now(),
|
|
105
|
+
): (entry: { path: string; stat: StatRecord }) => Promise<{ path: string; hash: string }> {
|
|
106
|
+
return async ({ path, stat }) => {
|
|
107
|
+
const normalized = normalizePath(path);
|
|
108
|
+
const entry = prior.get(normalized);
|
|
109
|
+
if (entry && statMatches(entry, stat) && !isRacy(stat, entry.recordedAtMs, now())) {
|
|
110
|
+
return { path: normalized, hash: entry.hash };
|
|
111
|
+
}
|
|
112
|
+
return { path: normalized, hash: await hashPath(path) };
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* ── persistence (the ingest manifest, one canonical JSON blob per root) ─────────────────────────── */
|
|
117
|
+
|
|
118
|
+
interface StatRow {
|
|
119
|
+
size: number;
|
|
120
|
+
mtimeNs: string;
|
|
121
|
+
fileId: string | null;
|
|
122
|
+
hash: string;
|
|
123
|
+
recordedAtMs: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const encode = (entries: ReadonlyMap<string, StatManifestEntry>): string => canonicalJson(
|
|
127
|
+
[...entries.entries()].sort((a, b) => compareStr(a[0], b[0])).map(([path, e]): [string, StatRow] => [path, {
|
|
128
|
+
size: e.size,
|
|
129
|
+
mtimeNs: e.mtimeNs.toString(),
|
|
130
|
+
fileId: e.fileId === null ? null : e.fileId.toString(),
|
|
131
|
+
hash: e.hash,
|
|
132
|
+
recordedAtMs: e.recordedAtMs,
|
|
133
|
+
}]),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const decode = (json: string): Map<string, StatManifestEntry> => {
|
|
137
|
+
const rows = JSON.parse(json) as Array<[string, StatRow]>;
|
|
138
|
+
const out = new Map<string, StatManifestEntry>();
|
|
139
|
+
for (const [path, r] of rows ?? []) {
|
|
140
|
+
out.set(path, {
|
|
141
|
+
size: r.size,
|
|
142
|
+
mtimeNs: BigInt(r.mtimeNs),
|
|
143
|
+
fileId: r.fileId === null ? null : BigInt(r.fileId),
|
|
144
|
+
hash: r.hash,
|
|
145
|
+
recordedAtMs: r.recordedAtMs,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/** The stored stat manifest for `rootId` (empty when none — the first run hashes everything, the existing fallback). */
|
|
152
|
+
export async function loadStatManifest(manifest: IngestManifest, rootId: string): Promise<Map<string, StatManifestEntry>> {
|
|
153
|
+
const map = await manifestMap(manifest, statManifestKey(rootId));
|
|
154
|
+
const raw = map.get('entries');
|
|
155
|
+
if (raw === undefined) return new Map();
|
|
156
|
+
try {
|
|
157
|
+
return decode(raw);
|
|
158
|
+
} catch {
|
|
159
|
+
return new Map(); // a corrupt stat cache is a perf fallback only: re-hash, never fail the plan
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Persists the stat manifest for `rootId`: every listed file's hash and the stat tuple it was
|
|
165
|
+
* cached under, stamped with `recordedAtMs` (the manifest write time the racy rule compares to).
|
|
166
|
+
*/
|
|
167
|
+
export async function saveStatManifest(
|
|
168
|
+
manifest: IngestManifest,
|
|
169
|
+
rootId: string,
|
|
170
|
+
files: ReadonlyArray<{ path: string; hash: string; stat: StatRecord }>,
|
|
171
|
+
recordedAtMs: number,
|
|
172
|
+
): Promise<void> {
|
|
173
|
+
const entries = new Map<string, StatManifestEntry>();
|
|
174
|
+
for (const f of files) entries.set(normalizePath(f.path), { ...f.stat, hash: f.hash, recordedAtMs });
|
|
175
|
+
await saveManifestMap(manifest, statManifestKey(rootId), new Map([['entries', encode(entries)]]));
|
|
176
|
+
}
|
package/src/stats/estimators.ts
CHANGED
|
@@ -57,7 +57,14 @@ export function kaplanMeier(rows: readonly { time: number; event: 0 | 1 }[]): Ka
|
|
|
57
57
|
/**
|
|
58
58
|
* Goel–Okumoto NHPP MLE: mean failures μ(t) = a(1 − e^{−bt}). a is solved in
|
|
59
59
|
* closed form given b; b is refined by bisection on the score equation
|
|
60
|
-
* Σ tᵢ = n/b − n·
|
|
60
|
+
* Σ tᵢ = n/b − n·tMax·e^{−b·tMax}/(1 − e^{−b·tMax}). Needs n ≥ 2 distinct times.
|
|
61
|
+
*
|
|
62
|
+
* The score uses tMax (the censoring horizon), not tMean: with likelihood
|
|
63
|
+
* L ∝ aⁿ e^{−a(1−e^{−bT})} · bⁿ e^{−bΣtᵢ} · Πe^{−btᵢ}, the b score after profiling out a
|
|
64
|
+
* substitutes the END time T = tMax in the per-observation exposure term, giving the
|
|
65
|
+
* root-finding target below. An earlier version used tMean, which has no stationary point
|
|
66
|
+
* on the data and drove b to the search bound (a saturated, meaningless fit) for every
|
|
67
|
+
* input.
|
|
61
68
|
*/
|
|
62
69
|
export function goelOkumotoMLE(
|
|
63
70
|
times: readonly number[],
|
|
@@ -66,19 +73,23 @@ export function goelOkumotoMLE(
|
|
|
66
73
|
const n = sorted.length;
|
|
67
74
|
if (n < 2) return { status: "insufficient-data" };
|
|
68
75
|
const tMax = sorted[n - 1]!;
|
|
69
|
-
const
|
|
76
|
+
const tSum = sorted.reduce((a, b) => a + b, 0);
|
|
77
|
+
// g(b) = n/b − n·tMax·e^{−b·tMax}/(1 − e^{−b·tMax}); the MLE b is the root of tSum = g(b).
|
|
78
|
+
// g is strictly decreasing in b (n/b falls, and the subtracted term grows toward n·tMax),
|
|
79
|
+
// so tSum − g(b) is strictly INCREASING: negative below the root, positive above it.
|
|
70
80
|
const score = (b: number) => {
|
|
71
|
-
if (b <= 0) return Infinity;
|
|
81
|
+
if (b <= 0) return -Infinity;
|
|
72
82
|
const denom = 1 - Math.exp(-b * tMax);
|
|
73
|
-
return n / b - (n *
|
|
83
|
+
return tSum - (n / b - (n * tMax * Math.exp(-b * tMax)) / denom);
|
|
74
84
|
};
|
|
75
85
|
let lo = 1e-9;
|
|
76
86
|
let hi = 1;
|
|
77
|
-
|
|
87
|
+
// Expand until the score is positive (past the increasing root); cap the search.
|
|
88
|
+
while (score(hi) < 0 && hi < 1e6) hi *= 2;
|
|
78
89
|
for (let i = 0; i < 100; i++) {
|
|
79
90
|
const mid = (lo + hi) / 2;
|
|
80
|
-
if (score(mid) > 0)
|
|
81
|
-
else
|
|
91
|
+
if (score(mid) > 0) hi = mid;
|
|
92
|
+
else lo = mid;
|
|
82
93
|
}
|
|
83
94
|
const b = (lo + hi) / 2;
|
|
84
95
|
const a = n / (1 - Math.exp(-b * tMax));
|