@seanhogg/builderforce-memory 2026.10.75 → 2026.10.77
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/facts/factsHash.d.ts +27 -0
- package/dist/knowledge/facts/factsHash.d.ts.map +1 -0
- package/dist/knowledge/facts/factsHash.js +67 -0
- package/dist/knowledge/facts/factsHash.js.map +1 -0
- package/dist/knowledge/facts/fileFacts.d.ts +70 -12
- package/dist/knowledge/facts/fileFacts.d.ts.map +1 -1
- package/dist/knowledge/facts/fileFacts.js +42 -33
- package/dist/knowledge/facts/fileFacts.js.map +1 -1
- package/dist/knowledge/facts/guards.d.ts +101 -0
- package/dist/knowledge/facts/guards.d.ts.map +1 -0
- package/dist/knowledge/facts/guards.js +260 -0
- package/dist/knowledge/facts/guards.js.map +1 -0
- package/dist/knowledge/index.d.ts +9 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +7 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/rules/evaluateRules.d.ts.map +1 -1
- package/dist/knowledge/rules/evaluateRules.js +2 -1
- package/dist/knowledge/rules/evaluateRules.js.map +1 -1
- package/dist/knowledge/rules/factGraph.d.ts +2 -0
- package/dist/knowledge/rules/factGraph.d.ts.map +1 -1
- package/dist/knowledge/rules/factGraph.js +6 -2
- package/dist/knowledge/rules/factGraph.js.map +1 -1
- package/dist/knowledge/rules/factStore.d.ts +139 -0
- package/dist/knowledge/rules/factStore.d.ts.map +1 -0
- package/dist/knowledge/rules/factStore.js +252 -0
- package/dist/knowledge/rules/factStore.js.map +1 -0
- package/dist/stats/prng.d.ts +5 -1
- package/dist/stats/prng.d.ts.map +1 -1
- package/dist/stats/prng.js +11 -3
- package/dist/stats/prng.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +14 -0
- package/src/contract/regression.prng.test.ts +126 -0
- package/src/contract/types.contract.test.ts +57 -2
- package/src/knowledge/facts/factsHash.test.ts +50 -0
- package/src/knowledge/facts/factsHash.ts +71 -0
- package/src/knowledge/facts/fileFacts.test.ts +2 -1
- package/src/knowledge/facts/fileFacts.ts +104 -36
- package/src/knowledge/facts/guards.test.ts +276 -0
- package/src/knowledge/facts/guards.ts +296 -0
- package/src/knowledge/index.ts +13 -1
- package/src/knowledge/rules/evaluateRules.ts +2 -1
- package/src/knowledge/rules/factGraph.ts +8 -2
- package/src/knowledge/rules/factStore.test.ts +303 -0
- package/src/knowledge/rules/factStore.ts +317 -0
- package/src/stats/prng.ts +11 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/facts/factsHash.ts — the identity of a `FileFacts` object (PRD 41 §B1, §B4, §B8): its WIRE form, its canonical
|
|
3
|
+
* JSON, its content address (`factsHash`) and the per-kind hashes early cutoff compares.
|
|
4
|
+
*
|
|
5
|
+
* Hash stability across additive fields: `mounts` and `uses` (§C5.1) were added after v3 shipped. A canonical object always
|
|
6
|
+
* carries them (`[]` when none), but the wire form OMITS them when empty — as it omits every absent optional field — so a
|
|
7
|
+
* facts object written before they existed keeps its `factsHash` and kind hashes when read back. A golden test pins one
|
|
8
|
+
* address computed by the code before the change (factsHash.test.ts).
|
|
9
|
+
*/
|
|
10
|
+
import { type FactKind, type FileFacts } from './fileFacts.js';
|
|
11
|
+
/**
|
|
12
|
+
* The WIRE form of `f` (canonicalized): the canonical object with each empty added list field (`mounts`, `uses`) omitted.
|
|
13
|
+
* What every hash, the stored object JSON and the dump are built from. Frozen; cached per canonical object.
|
|
14
|
+
*/
|
|
15
|
+
export declare function factsWireForm(f: FileFacts): FileFacts;
|
|
16
|
+
/** The canonical JSON of a facts object (its wire form): the bytes a fact store keeps under {@link factsHash}. */
|
|
17
|
+
export declare function factsJson(f: FileFacts): string;
|
|
18
|
+
/** The content address of a facts object: sha256 of its canonical JSON ({@link factsJson}). */
|
|
19
|
+
export declare function factsHash(f: FileFacts): string;
|
|
20
|
+
/**
|
|
21
|
+
* The hash of each fact kind of `f` (canonicalized first). `content` is the content hash itself; `structure` and `body`
|
|
22
|
+
* are sha256 over the canonical JSON of the header plus that kind's fields (from the wire form). Cached per CANONICAL
|
|
23
|
+
* (deep-frozen) object; a non-canonical input is canonicalized and hashed again on every call, so mutating it can never
|
|
24
|
+
* serve a stale hash.
|
|
25
|
+
*/
|
|
26
|
+
export declare function factKindHashes(f: FileFacts): Readonly<Record<FactKind, string>>;
|
|
27
|
+
//# sourceMappingURL=factsHash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factsHash.d.ts","sourceRoot":"","sources":["../../../src/knowledge/facts/factsHash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAwC,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOrG;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAUrD;AAED,kHAAkH;AAClH,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAE9C;AAOD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAc/E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/facts/factsHash.ts — the identity of a `FileFacts` object (PRD 41 §B1, §B4, §B8): its WIRE form, its canonical
|
|
3
|
+
* JSON, its content address (`factsHash`) and the per-kind hashes early cutoff compares.
|
|
4
|
+
*
|
|
5
|
+
* Hash stability across additive fields: `mounts` and `uses` (§C5.1) were added after v3 shipped. A canonical object always
|
|
6
|
+
* carries them (`[]` when none), but the wire form OMITS them when empty — as it omits every absent optional field — so a
|
|
7
|
+
* facts object written before they existed keeps its `factsHash` and kind hashes when read back. A golden test pins one
|
|
8
|
+
* address computed by the code before the change (factsHash.test.ts).
|
|
9
|
+
*/
|
|
10
|
+
import { canonicalJson } from '../refs.js';
|
|
11
|
+
import { sha256Hex } from '../../retrieval/knowledge-index/sha256.js';
|
|
12
|
+
import { canonicalFileFacts, FACT_KIND_FIELDS } from './fileFacts.js';
|
|
13
|
+
/** The optional list fields added after v3 shipped; omitted from the wire form when empty. */
|
|
14
|
+
const ADDED_LIST_FIELDS = ['mounts', 'uses'];
|
|
15
|
+
const wireCache = new WeakMap();
|
|
16
|
+
/**
|
|
17
|
+
* The WIRE form of `f` (canonicalized): the canonical object with each empty added list field (`mounts`, `uses`) omitted.
|
|
18
|
+
* What every hash, the stored object JSON and the dump are built from. Frozen; cached per canonical object.
|
|
19
|
+
*/
|
|
20
|
+
export function factsWireForm(f) {
|
|
21
|
+
const c = canonicalFileFacts(f);
|
|
22
|
+
let hit = wireCache.get(c);
|
|
23
|
+
if (!hit) {
|
|
24
|
+
const out = { ...c };
|
|
25
|
+
for (const field of ADDED_LIST_FIELDS)
|
|
26
|
+
if ((out[field]?.length ?? 0) === 0)
|
|
27
|
+
delete out[field];
|
|
28
|
+
hit = Object.freeze(out);
|
|
29
|
+
wireCache.set(c, hit);
|
|
30
|
+
}
|
|
31
|
+
return hit;
|
|
32
|
+
}
|
|
33
|
+
/** The canonical JSON of a facts object (its wire form): the bytes a fact store keeps under {@link factsHash}. */
|
|
34
|
+
export function factsJson(f) {
|
|
35
|
+
return canonicalJson(factsWireForm(f));
|
|
36
|
+
}
|
|
37
|
+
/** The content address of a facts object: sha256 of its canonical JSON ({@link factsJson}). */
|
|
38
|
+
export function factsHash(f) {
|
|
39
|
+
return sha256Hex(factsJson(f));
|
|
40
|
+
}
|
|
41
|
+
/** The header every kind hash includes. */
|
|
42
|
+
const headerOf = (f) => ({ factsVersion: f.factsVersion, extractor: f.extractor, language: f.language });
|
|
43
|
+
const kindCache = new WeakMap();
|
|
44
|
+
/**
|
|
45
|
+
* The hash of each fact kind of `f` (canonicalized first). `content` is the content hash itself; `structure` and `body`
|
|
46
|
+
* are sha256 over the canonical JSON of the header plus that kind's fields (from the wire form). Cached per CANONICAL
|
|
47
|
+
* (deep-frozen) object; a non-canonical input is canonicalized and hashed again on every call, so mutating it can never
|
|
48
|
+
* serve a stale hash.
|
|
49
|
+
*/
|
|
50
|
+
export function factKindHashes(f) {
|
|
51
|
+
const c = canonicalFileFacts(f);
|
|
52
|
+
const hit = kindCache.get(c);
|
|
53
|
+
if (hit)
|
|
54
|
+
return hit;
|
|
55
|
+
const w = factsWireForm(c);
|
|
56
|
+
const of = (kind) => {
|
|
57
|
+
const body = { header: headerOf(c) };
|
|
58
|
+
// An empty added list is absent from the wire form, so it never enters the hash (canonicalJson drops undefined).
|
|
59
|
+
for (const field of FACT_KIND_FIELDS[kind])
|
|
60
|
+
body[field] = w[field];
|
|
61
|
+
return sha256Hex(canonicalJson(body));
|
|
62
|
+
};
|
|
63
|
+
const hashes = Object.freeze({ body: of('body'), content: c.contentHash, structure: of('structure') });
|
|
64
|
+
kindCache.set(c, hashes);
|
|
65
|
+
return hashes;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=factsHash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factsHash.js","sourceRoot":"","sources":["../../../src/knowledge/facts/factsHash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAiC,MAAM,gBAAgB,CAAC;AAErG,8FAA8F;AAC9F,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAU,CAAC;AAEtD,MAAM,SAAS,GAAG,IAAI,OAAO,EAAwB,CAAC;AAEtD;;;GAGG;AACH,MA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,CAAC,CAAC,CAAC;IAC7B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IACpB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,EAAE,GAAG,CAAC,IAAc,EAAE,EAAE;QAC1B,MAAM,IAAI,GAA4B,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,iHAAiH;QACjH,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACnE,OAAO,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACvG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
*
|
|
8
8
|
* The fields split into three FACT KINDS ({@link FACT_KIND_FIELDS}), each with its own hash, so a rule
|
|
9
9
|
* that `reads` only `structure` never reruns for a body or comment edit (early cutoff, §B1):
|
|
10
|
-
* - `structure`: symbols, imports, exports, entry points
|
|
11
|
-
* removed from a route registration moves it);
|
|
10
|
+
* - `structure`: symbols, imports, exports, entry points, router mounts and `use` registrations (the
|
|
11
|
+
* declared surface; a guard added to or removed from a route registration moves it);
|
|
12
12
|
* - `body`: calls, complexity, capability imports, test facts;
|
|
13
13
|
* - `content`: the EOL-normalized bytes themselves, i.e. `contentHash` (contentHash.ts).
|
|
14
14
|
*
|
|
15
15
|
* The header (`factsVersion`, `extractor`, `language`) enters every kind's hash: facts of another
|
|
16
16
|
* extractor are never "the same structure". The extractors live in the hosts (Builderforce.ai
|
|
17
|
-
* agent-tools); memory owns only this shape and its hashing.
|
|
17
|
+
* agent-tools); memory owns only this shape and its hashing (the hashes and the wire form: factsHash.ts).
|
|
18
18
|
*/
|
|
19
19
|
/** The three fact kinds a rule may read (§B1). Sorted. */
|
|
20
20
|
export type FactKind = 'body' | 'content' | 'structure';
|
|
@@ -67,7 +67,13 @@ export interface EntryPointFact {
|
|
|
67
67
|
key: string;
|
|
68
68
|
/** The handler symbol path. */
|
|
69
69
|
symbol: string;
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Guard names on the REGISTRATION itself (inline middleware arguments, wrappers around the handler), sorted. Which names
|
|
72
|
+
* are guards is registry data (run-delta). File-level `use(path?, guard)` registrations are recorded in
|
|
73
|
+
* {@link FileFacts.uses} and composed by `effectiveGuards` (guards.ts): a producer that records `uses` does not also fold
|
|
74
|
+
* them in here. A producer with no `uses` may fold them, by the same rule (a `use` guards only routes registered AFTER it
|
|
75
|
+
* whose path its pattern covers).
|
|
76
|
+
*/
|
|
71
77
|
guards: string[];
|
|
72
78
|
/** Untrusted input accessors the handler uses (`req.body`, `c.req.json`, `msg.data`, `argv`), sorted. */
|
|
73
79
|
inputs: string[];
|
|
@@ -76,6 +82,57 @@ export interface EntryPointFact {
|
|
|
76
82
|
* registration, sorted. A neighbourhood rule with `readsGuardChain` reads these files' facts whatever their import distance.
|
|
77
83
|
*/
|
|
78
84
|
chain: string[];
|
|
85
|
+
/**
|
|
86
|
+
* The registration ORDER within the file: the 0-based index of this registration among the file's route, `use` and
|
|
87
|
+
* mount registrations (ONE counter shared with {@link UseFact.order} and {@link MountFact.order}). A registration index,
|
|
88
|
+
* not a line number and not a byte offset, so an edit that adds no registration never moves it. A non-negative integer.
|
|
89
|
+
* A producer that emits `uses` MUST set `order` on every entry point; absent ⇒ unknown, and `effectiveGuards` applies
|
|
90
|
+
* every covering `use` but reports those guards as inferred (`guardsInferred`).
|
|
91
|
+
*/
|
|
92
|
+
order?: number;
|
|
93
|
+
/** The local router binding the route is registered on (`app`, `adminRouter`). Absent ⇒ the file's one default router. */
|
|
94
|
+
router?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* One file-level middleware registration (§C5.1): `app.use(path?, guard…)`. It guards the routes of its router registered
|
|
98
|
+
* AFTER it (by `order`) whose path `path` covers, and every sub-router that router mounts after it ({@link MountFact}).
|
|
99
|
+
*/
|
|
100
|
+
export interface UseFact {
|
|
101
|
+
/**
|
|
102
|
+
* The use-path pattern: '' (or '*', '/*') for every path; `:param` (also `:param?`, `:param{regex}`) matches one segment;
|
|
103
|
+
* a trailing `*` (`/api/*`, `/api*`) matches the rest.
|
|
104
|
+
*/
|
|
105
|
+
path: string;
|
|
106
|
+
/**
|
|
107
|
+
* `prefix` (Express `use`, the default; canonical form omits it): the pattern covers every path under it.
|
|
108
|
+
* `exact` (Hono `use('/api')`): that path only.
|
|
109
|
+
*/
|
|
110
|
+
match?: 'prefix' | 'exact';
|
|
111
|
+
/** Guard names it registers, sorted. */
|
|
112
|
+
guards: string[];
|
|
113
|
+
/** Registration order (see {@link EntryPointFact.order}). */
|
|
114
|
+
order: number;
|
|
115
|
+
/** The router binding it is registered on (see {@link EntryPointFact.router}). */
|
|
116
|
+
router?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* One sub-router mount (§C5.1): `app.route('/api', sub)` (Hono) / `app.use('/api', subRouter)` (Express). The sub-router's
|
|
120
|
+
* routes answer under `prefix`, and the mounting router's `use` guards registered before the mount apply to them.
|
|
121
|
+
*/
|
|
122
|
+
export interface MountFact {
|
|
123
|
+
/** The mount prefix ('/api'); '/' for the root. Canonical form: leading `/`, no trailing `/`. */
|
|
124
|
+
prefix: string;
|
|
125
|
+
/**
|
|
126
|
+
* The sub-router: an import specifier resolved to a file by the host (`ResolvedMount`), or the name of a LOCAL router
|
|
127
|
+
* binding of this file (one that registers routes, uses or mounts here), which `effectiveGuards` resolves itself.
|
|
128
|
+
*/
|
|
129
|
+
target: string;
|
|
130
|
+
/** Registration order (see {@link EntryPointFact.order}). */
|
|
131
|
+
order: number;
|
|
132
|
+
/** The router binding that registers the mount (see {@link EntryPointFact.router}). */
|
|
133
|
+
router?: string;
|
|
134
|
+
/** Guards given inline at the mount (`router.use('/api', requireAuth, apiRouter)`), sorted; applied to every mounted route. */
|
|
135
|
+
guards?: string[];
|
|
79
136
|
}
|
|
80
137
|
export type CapabilityKind = 'process-exec' | 'fs-write' | 'network-client' | 'network-server' | 'dynamic-code' | 'native-addon' | 'crypto' | 'env-read' | 'secret-read';
|
|
81
138
|
/** One capability the file reaches (§C5.3): the module (and member) that grants it, and the algorithm for crypto. */
|
|
@@ -127,6 +184,10 @@ export interface FileFacts {
|
|
|
127
184
|
imports: ImportFact[];
|
|
128
185
|
exports: ExportFact[];
|
|
129
186
|
entryPoints: EntryPointFact[];
|
|
187
|
+
/** Sub-router mounts (§C5.1). Optional on input; a canonical object always carries it (`[]` when none). */
|
|
188
|
+
mounts?: MountFact[];
|
|
189
|
+
/** File-level `use()` middleware registrations (§C5.1). Optional on input; a canonical object always carries it. */
|
|
190
|
+
uses?: UseFact[];
|
|
130
191
|
calls: CallFact[];
|
|
131
192
|
complexity: ComplexityFact[];
|
|
132
193
|
capabilityImports: CapabilityImportFact[];
|
|
@@ -134,27 +195,24 @@ export interface FileFacts {
|
|
|
134
195
|
}
|
|
135
196
|
/** Which fields each kind hashes (data: the ONE place the split is declared). */
|
|
136
197
|
export declare const FACT_KIND_FIELDS: Readonly<Record<FactKind, readonly (keyof FileFacts)[]>>;
|
|
198
|
+
/** The ONE mount-prefix form: leading `/`, no trailing or doubled `/` ('' and '/' → '/', 'api/' → '/api'). */
|
|
199
|
+
export declare function normalizeMountPrefix(prefix: string): string;
|
|
137
200
|
/**
|
|
138
201
|
* The canonical form: a deep copy with every array sorted by its declared keys then by the whole item, nested string
|
|
139
202
|
* lists sorted, and every path field (`imports[].resolved`, `entryPoints[].chain`, `testFacts.snapshotFiles`) in the
|
|
140
203
|
* ONE path form (`normalizePath`, §B8.1). The result is DEEP-FROZEN: facts are immutable values, and the kind-hash and
|
|
141
204
|
* projection caches key on the object. Idempotent; a canonical object is returned as is.
|
|
205
|
+
*
|
|
206
|
+
* Throws `file_facts_invalid_order:<what>:<value>` when a registration `order` is not a non-negative integer; producers must
|
|
207
|
+
* catch it per file at extraction time and treat it as an extract failure of that file (never let it abort a whole build).
|
|
142
208
|
*/
|
|
143
209
|
export declare function canonicalFileFacts(f: FileFacts): FileFacts;
|
|
144
|
-
/**
|
|
145
|
-
* The hash of each fact kind of `f` (canonicalized first). `content` is the content hash itself; `structure` and `body`
|
|
146
|
-
* are sha256 over the canonical JSON of the header plus that kind's fields. Cached per CANONICAL (deep-frozen) object;
|
|
147
|
-
* a non-canonical input is canonicalized and hashed again on every call, so mutating it can never serve a stale hash.
|
|
148
|
-
*/
|
|
149
|
-
export declare function factKindHashes(f: FileFacts): Readonly<Record<FactKind, string>>;
|
|
150
210
|
/**
|
|
151
211
|
* `f` (canonicalized) as a rule that reads `reads` sees it: the header plus the fields of the read kinds; every other
|
|
152
212
|
* kind's fields empty. So an undeclared read sees nothing, and can never hide a dependency from the trace (§B5).
|
|
153
213
|
* Deep-frozen; cached per (canonical object, reads).
|
|
154
214
|
*/
|
|
155
215
|
export declare function projectFileFacts(f: FileFacts, reads: readonly FactKind[]): FileFacts;
|
|
156
|
-
/** The content address of a facts object: sha256 of its canonical JSON. */
|
|
157
|
-
export declare function factsHash(f: FileFacts): string;
|
|
158
216
|
/**
|
|
159
217
|
* Reads facts from any producer: a v3 object as is (canonicalized), a v2 one (repo-map's symbols + imports, no
|
|
160
218
|
* `factsVersion`) with every v3 list empty and `factsVersion: 2`. A v2 fact set is never comparable with a v3 one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFacts.d.ts","sourceRoot":"","sources":["../../../src/knowledge/facts/fileFacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"fileFacts.d.ts","sourceRoot":"","sources":["../../../src/knowledge/facts/fileFacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,0DAA0D;AAC1D,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;AACxD,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAA6D,CAAC;AAExG,sHAAsH;AACtH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,6GAA6G;IAC7G,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,mGAAmG;AACnG,MAAM,WAAW,UAAU;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,uIAAuI;AACvI,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wGAAwG;AACxG,MAAM,WAAW,QAAQ;IACrB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,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9
|
* that `reads` only `structure` never reruns for a body or comment edit (early cutoff, §B1):
|
|
10
|
-
* - `structure`: symbols, imports, exports, entry points
|
|
11
|
-
* removed from a route registration moves it);
|
|
10
|
+
* - `structure`: symbols, imports, exports, entry points, router mounts and `use` registrations (the
|
|
11
|
+
* declared surface; a guard added to or removed from a route registration moves it);
|
|
12
12
|
* - `body`: calls, complexity, capability imports, test facts;
|
|
13
13
|
* - `content`: the EOL-normalized bytes themselves, i.e. `contentHash` (contentHash.ts).
|
|
14
14
|
*
|
|
15
15
|
* The header (`factsVersion`, `extractor`, `language`) enters every kind's hash: facts of another
|
|
16
16
|
* extractor are never "the same structure". The extractors live in the hosts (Builderforce.ai
|
|
17
|
-
* agent-tools); memory owns only this shape and its hashing.
|
|
17
|
+
* agent-tools); memory owns only this shape and its hashing (the hashes and the wire form: factsHash.ts).
|
|
18
18
|
*/
|
|
19
19
|
import { canonicalJson, compareStr, normalizePath, sortBy } from '../refs.js';
|
|
20
|
-
import { sha256Hex } from '../../retrieval/knowledge-index/sha256.js';
|
|
21
20
|
import { FACTS_EXTRACTOR_VERSION } from './extractorVersion.js';
|
|
22
21
|
export const FACT_KINDS = Object.freeze(['body', 'content', 'structure']);
|
|
23
22
|
export const MATCHER_STRENGTH_ORDER = Object.freeze(['exact', 'partial', 'presence']);
|
|
24
23
|
/** Which fields each kind hashes (data: the ONE place the split is declared). */
|
|
25
24
|
export const FACT_KIND_FIELDS = Object.freeze({
|
|
26
|
-
structure: ['symbols', 'imports', 'exports', 'entryPoints'],
|
|
25
|
+
structure: ['symbols', 'imports', 'exports', 'entryPoints', 'mounts', 'uses'],
|
|
27
26
|
body: ['calls', 'complexity', 'capabilityImports', 'testFacts'],
|
|
28
27
|
content: ['contentHash'],
|
|
29
28
|
});
|
|
@@ -32,6 +31,24 @@ const sorted = (xs) => [...(xs ?? [])].sort(compareStr);
|
|
|
32
31
|
const paths = (xs) => sorted((xs ?? []).map(normalizePath));
|
|
33
32
|
/** The final sort key of every list: the whole item, so items equal on the declared keys still sort one way. */
|
|
34
33
|
const whole = (x) => canonicalJson(x);
|
|
34
|
+
/** A registration order as a string that sorts numerically. */
|
|
35
|
+
const ord = (n) => String(n).padStart(16, '0');
|
|
36
|
+
/** Refuses a registration order that is not a non-negative safe integer: `file_facts_invalid_order:<what>:<value>`. */
|
|
37
|
+
function checkOrder(what, order) {
|
|
38
|
+
if (order === undefined)
|
|
39
|
+
return;
|
|
40
|
+
if (!Number.isSafeInteger(order) || order < 0)
|
|
41
|
+
throw new Error(`file_facts_invalid_order:${what}:${String(order)}`);
|
|
42
|
+
}
|
|
43
|
+
/** The ONE mount-prefix form: leading `/`, no trailing or doubled `/` ('' and '/' → '/', 'api/' → '/api'). */
|
|
44
|
+
export function normalizeMountPrefix(prefix) {
|
|
45
|
+
return `/${prefix.split('/').filter((s) => s !== '').join('/')}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The ONE `use`-path form: '' stays '' (every path); anything else as {@link normalizeMountPrefix} ('/admin/' → '/admin',
|
|
49
|
+
* '*' → '/*'), so a trailing or doubled `/` never moves a hash.
|
|
50
|
+
*/
|
|
51
|
+
const normalizeUsePath = (path) => (path === '' ? '' : normalizeMountPrefix(path));
|
|
35
52
|
/** Facts objects produced by {@link canonicalFileFacts}: deep-frozen, so every cache keyed by object identity holds. */
|
|
36
53
|
const canonicalSet = new WeakSet();
|
|
37
54
|
function deepFreeze(value) {
|
|
@@ -47,16 +64,33 @@ function deepFreeze(value) {
|
|
|
47
64
|
* lists sorted, and every path field (`imports[].resolved`, `entryPoints[].chain`, `testFacts.snapshotFiles`) in the
|
|
48
65
|
* ONE path form (`normalizePath`, §B8.1). The result is DEEP-FROZEN: facts are immutable values, and the kind-hash and
|
|
49
66
|
* projection caches key on the object. Idempotent; a canonical object is returned as is.
|
|
67
|
+
*
|
|
68
|
+
* Throws `file_facts_invalid_order:<what>:<value>` when a registration `order` is not a non-negative integer; producers must
|
|
69
|
+
* catch it per file at extraction time and treat it as an extract failure of that file (never let it abort a whole build).
|
|
50
70
|
*/
|
|
51
71
|
export function canonicalFileFacts(f) {
|
|
52
72
|
if (canonicalSet.has(f))
|
|
53
73
|
return f;
|
|
74
|
+
for (const e of f.entryPoints)
|
|
75
|
+
checkOrder(`entryPoint:${e.key}`, e.order);
|
|
76
|
+
for (const u of f.uses ?? [])
|
|
77
|
+
checkOrder(`use:${u.path}`, u.order);
|
|
78
|
+
for (const m of f.mounts ?? [])
|
|
79
|
+
checkOrder(`mount:${m.prefix}`, m.order);
|
|
54
80
|
const out = {
|
|
55
81
|
...f,
|
|
56
82
|
symbols: sortBy(f.symbols.map((s) => ({ ...s })), (s) => s.name, (s) => s.kind, (s) => str(s.signatureHash), whole),
|
|
57
83
|
imports: sortBy(f.imports.map((i) => ({ ...i, names: sorted(i.names), ...(i.resolved !== undefined ? { resolved: normalizePath(i.resolved) } : {}) })), (i) => i.specifier, (i) => str(i.resolved), (i) => i.names.join('\u0000'), whole),
|
|
58
84
|
exports: sortBy(f.exports.map((e) => ({ ...e })), (e) => e.name, (e) => e.kind, (e) => e.signatureHash, (e) => str(e.from), whole),
|
|
59
85
|
entryPoints: sortBy(f.entryPoints.map((e) => ({ ...e, guards: sorted(e.guards), inputs: sorted(e.inputs), chain: paths(e.chain) })), (e) => e.kind, (e) => e.key, (e) => e.symbol, whole),
|
|
86
|
+
mounts: sortBy((f.mounts ?? []).map((m) => {
|
|
87
|
+
const { guards, ...rest } = m;
|
|
88
|
+
return { ...rest, prefix: normalizeMountPrefix(m.prefix), ...((guards?.length ?? 0) > 0 ? { guards: sorted(guards) } : {}) };
|
|
89
|
+
}), (m) => ord(m.order), (m) => m.prefix, (m) => m.target, whole),
|
|
90
|
+
uses: sortBy((f.uses ?? []).map((u) => {
|
|
91
|
+
const { match, ...rest } = u;
|
|
92
|
+
return { ...rest, path: normalizeUsePath(u.path), guards: sorted(u.guards), ...(match === 'exact' ? { match } : {}) };
|
|
93
|
+
}), (u) => ord(u.order), (u) => u.path, whole),
|
|
60
94
|
calls: sortBy(f.calls.map((c) => ({ ...c })), (c) => c.enclosing, (c) => c.callee, (c) => str(c.awaited), (c) => str(c.inLoop), whole),
|
|
61
95
|
complexity: sortBy(f.complexity.map((c) => ({ ...c })), (c) => c.symbol, whole),
|
|
62
96
|
capabilityImports: sortBy(f.capabilityImports.map((c) => ({ ...c })), (c) => c.capability, (c) => c.module, (c) => str(c.symbol), (c) => str(c.algorithm), whole),
|
|
@@ -72,32 +106,9 @@ export function canonicalFileFacts(f) {
|
|
|
72
106
|
canonicalSet.add(out);
|
|
73
107
|
return out;
|
|
74
108
|
}
|
|
75
|
-
/** The header every kind hash includes. */
|
|
76
|
-
const headerOf = (f) => ({ factsVersion: f.factsVersion, extractor: f.extractor, language: f.language });
|
|
77
|
-
const kindCache = new WeakMap();
|
|
78
|
-
/**
|
|
79
|
-
* The hash of each fact kind of `f` (canonicalized first). `content` is the content hash itself; `structure` and `body`
|
|
80
|
-
* are sha256 over the canonical JSON of the header plus that kind's fields. Cached per CANONICAL (deep-frozen) object;
|
|
81
|
-
* a non-canonical input is canonicalized and hashed again on every call, so mutating it can never serve a stale hash.
|
|
82
|
-
*/
|
|
83
|
-
export function factKindHashes(f) {
|
|
84
|
-
const c = canonicalFileFacts(f);
|
|
85
|
-
const hit = kindCache.get(c);
|
|
86
|
-
if (hit)
|
|
87
|
-
return hit;
|
|
88
|
-
const of = (kind) => {
|
|
89
|
-
const body = { header: headerOf(c) };
|
|
90
|
-
for (const field of FACT_KIND_FIELDS[kind])
|
|
91
|
-
body[field] = c[field];
|
|
92
|
-
return sha256Hex(canonicalJson(body));
|
|
93
|
-
};
|
|
94
|
-
const hashes = Object.freeze({ body: of('body'), content: c.contentHash, structure: of('structure') });
|
|
95
|
-
kindCache.set(c, hashes);
|
|
96
|
-
return hashes;
|
|
97
|
-
}
|
|
98
109
|
/** The empty value of every kind's fields: what a rule that does not read that kind sees. */
|
|
99
110
|
const EMPTY_FIELDS = Object.freeze({
|
|
100
|
-
structure: { symbols: [], imports: [], exports: [], entryPoints: [] },
|
|
111
|
+
structure: { symbols: [], imports: [], exports: [], entryPoints: [], mounts: [], uses: [] },
|
|
101
112
|
body: { calls: [], complexity: [], capabilityImports: [], testFacts: undefined },
|
|
102
113
|
content: { contentHash: '' },
|
|
103
114
|
});
|
|
@@ -126,10 +137,6 @@ export function projectFileFacts(f, reads) {
|
|
|
126
137
|
}
|
|
127
138
|
return hit;
|
|
128
139
|
}
|
|
129
|
-
/** The content address of a facts object: sha256 of its canonical JSON. */
|
|
130
|
-
export function factsHash(f) {
|
|
131
|
-
return sha256Hex(canonicalJson(canonicalFileFacts(f)));
|
|
132
|
-
}
|
|
133
140
|
/**
|
|
134
141
|
* Reads facts from any producer: a v3 object as is (canonicalized), a v2 one (repo-map's symbols + imports, no
|
|
135
142
|
* `factsVersion`) with every v3 list empty and `factsVersion: 2`. A v2 fact set is never comparable with a v3 one
|
|
@@ -145,6 +152,8 @@ export function readFileFacts(raw) {
|
|
|
145
152
|
imports: raw.imports ?? [],
|
|
146
153
|
exports: raw.exports ?? [],
|
|
147
154
|
entryPoints: raw.entryPoints ?? [],
|
|
155
|
+
mounts: raw.mounts ?? [],
|
|
156
|
+
uses: raw.uses ?? [],
|
|
148
157
|
calls: raw.calls ?? [],
|
|
149
158
|
complexity: raw.complexity ?? [],
|
|
150
159
|
capabilityImports: raw.capabilityImports ?? [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFacts.js","sourceRoot":"","sources":["../../../src/knowledge/facts/fileFacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fileFacts.js","sourceRoot":"","sources":["../../../src/knowledge/facts/fileFacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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AAG,CAAC,WAAW,IAAI,EAAE;QAClC,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;QACxB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE;QACtB,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE;QAChC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,IAAI,EAAE;QAC9C,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC,CAAC;AACP,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAkC,EAAW,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/facts/guards.ts — the guard-chain semantics of entry points across `use()` registrations and router mounts
|
|
3
|
+
* (PRD 41 §C5.1). Pure: the host resolves each imported mount's target to a file and its facts; this module composes.
|
|
4
|
+
*
|
|
5
|
+
* The rules, explicit:
|
|
6
|
+
* 1. ROUTER IDENTITY. Routes, uses and mounts belong to the router binding that registers them (`router`; absent = the
|
|
7
|
+
* file's one default router). A `use` on `adminRouter` never guards a route on `publicRouter`, even in one file.
|
|
8
|
+
* 2. ORDER. A `use(path?, guard)` ({@link UseFact}) guards a route of its router only when it was registered BEFORE the
|
|
9
|
+
* route (`order`) and its path pattern covers the route's path. A path-scoped `use` registered after a route never
|
|
10
|
+
* guards it. A route with no `order` takes every covering `use`, and those guards are reported in `guardsInferred`
|
|
11
|
+
* (a C5.1 rule downgrades them to heuristic). A producer that emits `uses` MUST set `order` on every entry point.
|
|
12
|
+
* 3. MOUNTS. A mounted sub-router (`app.route('/api', sub)`, `app.use('/api', subRouter)`, {@link MountFact}) answers its
|
|
13
|
+
* routes under the prefix-joined path, and inherits every `use` of the mounting router registered before the mount
|
|
14
|
+
* that covers the joined path, plus the mount's own inline `guards` — transitively, up to {@link MAX_MOUNT_DEPTH}
|
|
15
|
+
* levels. A target naming a local router binding of the same file is resolved here; other targets come from the host
|
|
16
|
+
* ({@link ResolvedMount}). Cycles are cut by the (file, router) pairs on the stack.
|
|
17
|
+
* 4. A route's own `guards` (inline middleware, wrappers) always apply.
|
|
18
|
+
*
|
|
19
|
+
* CALL SITES. `effectiveGuards` is called on ROOT routers only: files no other file mounts ({@link rootRouters}), and
|
|
20
|
+
* within a file the routers no local mount targets. A sub-router's routes are reported through their root (prefix-joined,
|
|
21
|
+
* with the inherited guards); calling it on a mounted file as well would report a bare, under-guarded copy of each route.
|
|
22
|
+
* Consumers that read `entryPoints[].guards` directly must switch to this function in the same change in which a producer
|
|
23
|
+
* starts emitting `uses`.
|
|
24
|
+
*
|
|
25
|
+
* Route paths come from the entry key: `'<METHOD> /path'` or `'/path'`. An entry point without a path (a VS Code command,
|
|
26
|
+
* an exported API) gets only path-less (`''`, `'*'`, `'/*'`) uses of its router, and is never mounted.
|
|
27
|
+
*/
|
|
28
|
+
import { type EntryPointFact, type FileFacts, type MountFact, type UseFact } from './fileFacts.js';
|
|
29
|
+
/** How many mount levels `effectiveGuards` descends at most (mount nesting, not import hops). */
|
|
30
|
+
export declare const MAX_MOUNT_DEPTH = 8;
|
|
31
|
+
/** A mount the host resolved: the target (as written in {@link MountFact.target}) → the sub-router's file and facts. */
|
|
32
|
+
export interface ResolvedMount {
|
|
33
|
+
/** The {@link MountFact.target} this resolves (a file may mount one target at several prefixes). */
|
|
34
|
+
target: string;
|
|
35
|
+
/** The sub-router's root-relative file. */
|
|
36
|
+
path: string;
|
|
37
|
+
facts: FileFacts;
|
|
38
|
+
/** The router binding in that file that is mounted. Absent ⇒ that file's root routers. */
|
|
39
|
+
router?: string;
|
|
40
|
+
/** The sub-router file's own imported mounts, resolved the same way (nested routers). */
|
|
41
|
+
mounts?: readonly ResolvedMount[];
|
|
42
|
+
}
|
|
43
|
+
/** An entry point with its effective guards: prefix-joined key, composed guards, the mounting files on its chain. */
|
|
44
|
+
export interface EffectiveEntryPoint extends EntryPointFact {
|
|
45
|
+
/** The file that registers the handler: `opts.path` (default '') for the given file, the sub-router's path otherwise. */
|
|
46
|
+
file: string;
|
|
47
|
+
/** The mount prefixes from the root router down to the registering router, outermost first; empty for root routes. */
|
|
48
|
+
via: string[];
|
|
49
|
+
/** Guards in `guards` that apply only because the route has no `order` (rule 2), sorted. Empty when the order is known. */
|
|
50
|
+
guardsInferred: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface EffectiveGuardsOptions {
|
|
53
|
+
/** The given file's root-relative path: reported as `file`, and added to a mounted route's `chain`. */
|
|
54
|
+
path?: string;
|
|
55
|
+
/** The root router binding to start from ('' = the file's default router). Absent ⇒ every router of the file that no local mount targets. */
|
|
56
|
+
router?: string;
|
|
57
|
+
/** Mount levels to descend (0..{@link MAX_MOUNT_DEPTH}). Default {@link MAX_MOUNT_DEPTH}. */
|
|
58
|
+
maxDepth?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface EffectiveGuardsResult {
|
|
61
|
+
/** Sorted by file, kind, key, symbol, via. */
|
|
62
|
+
entryPoints: EffectiveEntryPoint[];
|
|
63
|
+
/** Mounts not followed because of the depth limit or a cycle. */
|
|
64
|
+
truncated: number;
|
|
65
|
+
/** Mounts whose target was neither a local router nor in `resolvedMounts`. */
|
|
66
|
+
unresolved: number;
|
|
67
|
+
}
|
|
68
|
+
/** Joins a mount prefix and a route path into one `/`-rooted path ('/api' + '/x' → '/api/x'; '/api' + '/' → '/api'). */
|
|
69
|
+
export declare function joinRoutePath(prefix: string, path: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a `use` path pattern covers `path` (rule 2's path half). Segments: a literal matches itself; `:x`, `:x{regex}`
|
|
72
|
+
* match one segment; `:x?` matches one segment or none; `*` as the last segment matches the rest (zero or more segments);
|
|
73
|
+
* a last segment ending in `*` (`api*`) matches any segment starting with its stem, and the rest. `prefix` (default)
|
|
74
|
+
* covers every path under the pattern; `exact` that path only.
|
|
75
|
+
*/
|
|
76
|
+
export declare function routePathCovers(pattern: string, path: string, match?: UseFact['match']): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Every entry point of the root router(s) of `fileFacts` and of the sub-routers they mount, with its EFFECTIVE guards
|
|
79
|
+
* (rules 1–4 of the header). Mounted routes get prefix-joined keys and the mounting files added to their `chain`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function effectiveGuards(fileFacts: FileFacts, resolvedMounts: readonly ResolvedMount[], opts?: EffectiveGuardsOptions): EffectiveGuardsResult;
|
|
82
|
+
/** One root router: a file and the router binding in it ('' = the file's default router). */
|
|
83
|
+
export interface RootRouter {
|
|
84
|
+
path: string;
|
|
85
|
+
router: string;
|
|
86
|
+
}
|
|
87
|
+
/** Where an imported mount lands: the mounted file, and the router binding in it (absent ⇒ that file's root routers). */
|
|
88
|
+
export interface MountTarget {
|
|
89
|
+
path: string;
|
|
90
|
+
router?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The ROOT routers of a set of files, PER ROUTER: every (file, router) that registers something and that no other router's
|
|
94
|
+
* mount reaches — so a mounted file's second, unmounted router is still a root. Routers mounted only inside a cycle (files
|
|
95
|
+
* mounting each other) are not dropped: the lowest unreached (path, router) becomes a root, then everything it reaches is
|
|
96
|
+
* covered, repeated until every router is covered (deterministic). `resolveMount` maps a mount of the file at `from` to
|
|
97
|
+
* its target (undefined when unresolved); local-binding mounts stay within their file. Sorted by path, then router. Call
|
|
98
|
+
* `effectiveGuards(facts, mounts, { path, router })` on each (see CALL SITES in the header).
|
|
99
|
+
*/
|
|
100
|
+
export declare function rootRouters(files: ReadonlyMap<string, FileFacts>, resolveMount: (from: string, mount: MountFact) => MountTarget | undefined): RootRouter[];
|
|
101
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
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