@tangle-network/agent-knowledge 19.1.5 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/README.md +17 -91
  3. package/dist/benchmarks/index.d.ts +2 -2
  4. package/dist/benchmarks/index.js +2 -2
  5. package/dist/benchmarks-jir3ZP-M.js +162 -0
  6. package/dist/benchmarks-jir3ZP-M.js.map +1 -0
  7. package/dist/cli.js +2 -3
  8. package/dist/cli.js.map +1 -1
  9. package/dist/index-BhvSH4E4.d.ts +512 -0
  10. package/dist/index-BhvSH4E4.d.ts.map +1 -0
  11. package/dist/index-OAxtm6is.d.ts +9 -0
  12. package/dist/index-OAxtm6is.d.ts.map +1 -0
  13. package/dist/index.d.ts +197 -1332
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +561 -3653
  16. package/dist/index.js.map +1 -1
  17. package/dist/{inspect-C6c4zuKp.js → inspect-CMigdsD5.js} +282 -24
  18. package/dist/inspect-CMigdsD5.js.map +1 -0
  19. package/dist/memory/index.d.ts +3 -3
  20. package/dist/memory/index.js +3 -3
  21. package/dist/memory-BH6oT1Qe.js +2728 -0
  22. package/dist/memory-BH6oT1Qe.js.map +1 -0
  23. package/dist/source-record-CdWvzvO6.js +39 -0
  24. package/dist/source-record-CdWvzvO6.js.map +1 -0
  25. package/dist/types-BWV_Fvp7.d.ts +224 -0
  26. package/dist/types-BWV_Fvp7.d.ts.map +1 -0
  27. package/dist/{types-m2QB86fF.d.ts → types-BekdNwGD.d.ts} +4 -19
  28. package/dist/types-BekdNwGD.d.ts.map +1 -0
  29. package/dist/viz/index.d.ts +1 -1
  30. package/docs/architecture.md +2 -30
  31. package/docs/eval/investment-material-facts.md +2 -0
  32. package/docs/results/research-driving.md +8 -8
  33. package/docs/verified-research-ab.md +12 -10
  34. package/package.json +6 -12
  35. package/skills/build-with-agent-knowledge/SKILL.md +2 -15
  36. package/dist/benchmarks-BjXxjAke.js +0 -2824
  37. package/dist/benchmarks-BjXxjAke.js.map +0 -1
  38. package/dist/index-Bh9wLd0_.d.ts +0 -1097
  39. package/dist/index-Bh9wLd0_.d.ts.map +0 -1
  40. package/dist/index-DZeFm-BP.d.ts +0 -680
  41. package/dist/index-DZeFm-BP.d.ts.map +0 -1
  42. package/dist/inspect-C6c4zuKp.js.map +0 -1
  43. package/dist/memory-CUk1mgPY.js +0 -5778
  44. package/dist/memory-CUk1mgPY.js.map +0 -1
  45. package/dist/search-BBr5eUyT.js +0 -275
  46. package/dist/search-BBr5eUyT.js.map +0 -1
  47. package/dist/sources/index.d.ts +0 -376
  48. package/dist/sources/index.d.ts.map +0 -1
  49. package/dist/sources/index.js +0 -615
  50. package/dist/sources/index.js.map +0 -1
  51. package/dist/types-m2QB86fF.d.ts.map +0 -1
  52. package/docs/eval/rag-eval-roadmap.md +0 -123
@@ -1,376 +0,0 @@
1
- //#region src/sources/types.d.ts
2
- /**
3
- * Pluggable knowledge source contract.
4
- *
5
- * A `KnowledgeSource` is one external provider of authoritative content that
6
- * an agent's knowledge base should track over time (e.g. Cornell LII US Code,
7
- * IRS publications, a state secretary-of-state filing portal). It returns
8
- * hashable, embed-ready `KnowledgeFragment`s plus enough provenance metadata
9
- * for downstream consumers to:
10
- *
11
- * 1. detect change against a previous snapshot (see `./changes`)
12
- * 2. score freshness on a per-source-id basis (see `./freshness`)
13
- * 3. decide which evals to re-run when the underlying authority moves
14
- * (the `dimensionHints` field is the binding contract for that decision)
15
- *
16
- * Sources MUST be pure with respect to local filesystem state outside the
17
- * cache directory the caller hands them — they read remote authorities and
18
- * return data. They MUST mark `verifiable: false` on any fragment they could
19
- * not fetch and extract (block page, 4xx, parse failure) rather than silently
20
- * substituting empty or partial content. The control loop downstream uses
21
- * `verifiable` to refuse promotion of unusable content.
22
- *
23
- * @stable
24
- */
25
- /**
26
- * Per-fetch options the host (control loop / cron / CLI) passes in.
27
- *
28
- * `signal` lets the host abort long-running fetches (rate-limited authority,
29
- * congested network). `cacheDir` is where the source SHOULD write its disk
30
- * cache; an undefined value disables caching (useful in tests). `now` is
31
- * injected for deterministic tests of change-detection windows.
32
- */
33
- export interface FetchOpts {
34
- /** Abort signal forwarded to the underlying HTTP fetcher. */
35
- signal?: AbortSignal;
36
- /** Absolute path under which the source may cache raw bytes. */
37
- cacheDir?: string;
38
- /** Clock injection for deterministic tests. */
39
- now?: () => Date;
40
- /**
41
- * Maximum number of authority pages the source should fetch in this call.
42
- * Sources MUST respect this bound — exhaustively crawling Cornell LII on
43
- * every cron tick would be both rude and slow. Default is source-specific.
44
- */
45
- limit?: number;
46
- /**
47
- * Source-specific selector string. Examples:
48
- * - cornell-lii: `'uscode/text/18/1836'` or `'wex/non-compete'`
49
- * - irs-publications: `'index'` or `'p15'`
50
- * - state-sos: opaque, see `StateSosSourceConfig`
51
- *
52
- * Sources that don't need a selector ignore this field.
53
- */
54
- selector?: string;
55
- }
56
- /**
57
- * The standard provenance shape every fragment carries. Kept separate from
58
- * `KnowledgeFragment` so freshness/change code can pass it around without
59
- * also dragging the body text.
60
- */
61
- export interface FragmentProvenance {
62
- /** Canonical URL the fragment was extracted from. */
63
- url: string;
64
- /**
65
- * Source-attested timestamp: the time the AUTHORITY last updated this
66
- * content, as reported by the source (Last-Modified header, in-page
67
- * effective date, registry generated-at, etc). Falls back to the fetch
68
- * time only when the authority publishes no timestamp.
69
- */
70
- sourceUpdatedAt: string;
71
- /** ISO timestamp the fragment was fetched. */
72
- fetchedAt: string;
73
- /**
74
- * Jurisdiction the content is binding within, if applicable. Use ISO
75
- * country code, US state abbreviation, or 'US-FED' for federal scope.
76
- * Statute sources MUST populate this; reference / encyclopedia sources
77
- * MAY leave it undefined.
78
- */
79
- jurisdiction?: string;
80
- /**
81
- * True iff the configured URL returned an acceptable response and the
82
- * expected content was extracted. False on a block page, rate-limit
83
- * response, 4xx/5xx, or selector miss. This is not publisher authentication
84
- * or cryptographic content verification. Consumers MUST refuse to promote
85
- * `verifiable: false` fragments into citable knowledge.
86
- */
87
- verifiable: boolean;
88
- /** If `verifiable === false`, the reason — surfaced to operators. */
89
- unverifiableReason?: string;
90
- }
91
- /**
92
- * One unit of authoritative content. Stable hash on `(id, body)` lets change
93
- * detection reason about identity across snapshots.
94
- */
95
- export interface KnowledgeFragment {
96
- /**
97
- * Stable identity within (sourceId, selector-space). Two fetches against
98
- * the same authority section MUST produce the same `id`. The (sourceId,
99
- * id) pair is the primary key for change detection.
100
- */
101
- id: string;
102
- /** Free-form title — section heading, publication name, etc. */
103
- title: string;
104
- /** Body text, normalised: no HTML tags, line breaks preserved. */
105
- body: string;
106
- /** SHA-256 of `body`. Pre-computed so consumers don't re-hash on diff. */
107
- bodyHash: string;
108
- provenance: FragmentProvenance;
109
- /**
110
- * Eval dimensions an agent-eval campaign should re-score when this
111
- * fragment changes. Examples: `citation_hygiene`, `jurisdictional_accuracy`,
112
- * `tax_compliance`, `regulatory_currency`. The eval cron treats this as a
113
- * set, not a contract — adding a new dimension is non-breaking.
114
- *
115
- * This is the load-bearing field for the continuous-ingestion story: a
116
- * Ryan-LLC-style ruling vacates the FTC non-compete rule → the source
117
- * returns a fragment with `jurisdictional_accuracy` in this list →
118
- * `detectChanges()` emits a `KnowledgeChange` carrying that hint → the
119
- * cron knows exactly which agent-eval campaigns to re-run.
120
- */
121
- dimensionHints: string[];
122
- /** Arbitrary source-specific metadata for debugging / connector wiring. */
123
- metadata?: Record<string, unknown>;
124
- }
125
- /**
126
- * One pluggable knowledge source.
127
- *
128
- * Implementations: see `./cornell-lii`, `./irs-publications`, `./state-sos`.
129
- * To author a new source, follow the same shape and register it in your
130
- * application's source list — there is no global registry by design (per
131
- * the per-tenant isolation contract; see README).
132
- */
133
- export interface KnowledgeSource {
134
- /** Stable id — used to key freshness state. MUST NOT change once shipped. */
135
- id: string;
136
- /** Human-readable name for dashboards. */
137
- name: string;
138
- /** One-sentence description: what authority + scope. */
139
- description: string;
140
- /**
141
- * Pull fragments for this source. Sources MUST:
142
- * - rate-limit themselves (>=1 req/sec per source by convention)
143
- * - send a polite User-Agent
144
- * - cache to disk when `opts.cacheDir` is set
145
- * - mark `verifiable: false` rather than throwing on parse/block
146
- * - honour `opts.signal`
147
- * - honour `opts.limit`
148
- */
149
- fetch(opts: FetchOpts): Promise<KnowledgeFragment[]>;
150
- }
151
- //#endregion
152
- //#region src/sources/cornell-lii.d.ts
153
- export interface CornellLiiSelector {
154
- /** Either 'uscode' or 'wex'. */
155
- kind: 'uscode' | 'wex';
156
- /**
157
- * For `uscode`: `<title>/<section>` (e.g. `'18/1836'` for DTSA).
158
- * For `wex`: the slug (e.g. `'non-compete'`).
159
- */
160
- path: string;
161
- /**
162
- * Optional pre-declared eval dimensions affected by this section. If
163
- * omitted, defaults are chosen from `kind` + path heuristics.
164
- */
165
- dimensionHints?: string[];
166
- }
167
- export interface CornellLiiSourceOptions {
168
- /**
169
- * Selectors to fetch on each `fetch()` call. The caller (a per-tenant
170
- * workspace config, typically) lists exactly the authorities they need
171
- * tracked. There is no auto-discovery; that would crawl Cornell at
172
- * cron speed, which is what the polite-fetch contract exists to avoid.
173
- */
174
- selectors: CornellLiiSelector[];
175
- /** Source id override; default is `'cornell-lii'`. */
176
- id?: string;
177
- }
178
- /**
179
- * Build a Cornell LII source for the listed selectors.
180
- *
181
- * Example: track DTSA + non-compete:
182
- * ```
183
- * createCornellLiiSource({
184
- * selectors: [
185
- * { kind: 'uscode', path: '18/1836' },
186
- * { kind: 'wex', path: 'non-compete', dimensionHints: ['jurisdictional_accuracy'] },
187
- * ],
188
- * })
189
- * ```
190
- */
191
- export declare function createCornellLiiSource(options: CornellLiiSourceOptions): KnowledgeSource;
192
- //#endregion
193
- //#region src/sources/html.d.ts
194
- /**
195
- * Minimal HTML helpers used by the shipped sources.
196
- *
197
- * Deliberately not a full DOM parser: every authority we ship against
198
- * (Cornell LII, IRS.gov, state SOS portals) has well-behaved server-rendered
199
- * HTML where regex-based extraction is correct and cheap. Bringing in cheerio
200
- * would add a 1.5MB dependency to a package whose purpose is shipping
201
- * primitives, not parsing arbitrary web pages.
202
- *
203
- * If a future source needs real DOM traversal, it should depend on its own
204
- * parser locally rather than promoting one into the package-wide deps.
205
- *
206
- * @stable
207
- */
208
- /**
209
- * Strip HTML tags, collapse whitespace, decode common entities.
210
- *
211
- * Preserves paragraph and line breaks (`</p>`, `<br>`, `</li>`, `</div>`,
212
- * `</h*>`) as `\n` so statute text retains its subsection structure.
213
- */
214
- export declare function htmlToText(html: string): string;
215
- /** Extract the first match of a regex's first capture group, or undefined. */
216
- export declare function firstMatch(html: string, pattern: RegExp): string | undefined;
217
- /** Extract the inner HTML of the first matching tag with id `id`. */
218
- export declare function innerHtmlById(html: string, id: string): string | undefined;
219
- /**
220
- * Extract every (href, text) pair matching the URL regex.
221
- * Returns absolute URLs by resolving against `baseUrl`.
222
- */
223
- export declare function extractLinks(html: string, hrefPattern: RegExp, baseUrl: string): {
224
- href: string;
225
- text: string;
226
- }[];
227
- //#endregion
228
- //#region src/sources/http.d.ts
229
- /**
230
- * Polite HTTP fetcher shared by remote sources.
231
- *
232
- * Independent sources share a per-origin throttle because rate-limited sites
233
- * may return block pages instead of 429 responses. Responses are cached by URL
234
- * because many publishers omit reliable ETag and Last-Modified headers. Bodies
235
- * are checked even after a 2xx response because captcha and block pages often
236
- * use successful status codes.
237
- */
238
- /** User-Agent string sent on every outbound request. */
239
- export declare const POLITE_USER_AGENT = "agent-knowledge (+https://github.com/tangle-network/agent-knowledge)";
240
- /** Minimum gap between successive requests to the same origin (ms). */
241
- export declare const MIN_REQUEST_GAP_MS = 1000;
242
- /** Maximum response body we will buffer in memory (bytes). */
243
- export declare const MAX_RESPONSE_BYTES: number;
244
- export interface PoliteFetchOptions {
245
- signal?: AbortSignal;
246
- cacheDir?: string;
247
- /**
248
- * Cache age beyond which we re-fetch. Default 1 hour, long enough to
249
- * batch a cron sweep across many selectors, short enough that hourly
250
- * authoritative-page changes get picked up next tick.
251
- */
252
- cacheTtlMs?: number;
253
- /**
254
- * Extra request headers. The fetcher always sets `User-Agent` and
255
- * `Accept`; callers can add `Accept-Language` etc.
256
- */
257
- headers?: Record<string, string>;
258
- }
259
- export interface PoliteFetchResult {
260
- url: string;
261
- status: number;
262
- /** Decoded UTF-8 body. Truncated to `MAX_RESPONSE_BYTES`. */
263
- body: string;
264
- /**
265
- * Best-effort source-attested timestamp. Reads `Last-Modified`,
266
- * falling back to `Date`, falling back to fetch time. Always ISO 8601.
267
- */
268
- sourceUpdatedAt: string;
269
- fetchedAt: string;
270
- /** True iff the response was satisfied from disk cache. */
271
- fromCache: boolean;
272
- /**
273
- * False on: non-2xx status, captcha/block page heuristic match, or
274
- * decoded body below 200 chars from a host known to serve real content
275
- * (Cornell, IRS, state SOS). `unverifiableReason` carries the why.
276
- */
277
- verifiable: boolean;
278
- unverifiableReason?: string;
279
- }
280
- /**
281
- * Fetch one URL with per-host throttling, on-disk cache, and block-page
282
- * detection. Never throws on network/HTTP failure. It returns a result with
283
- * `verifiable: false` and `unverifiableReason` set so the caller can decide
284
- * whether to skip, retry, or surface.
285
- *
286
- * Throws ONLY on `AbortError` (caller asked to stop) and on cache-write
287
- * failures that indicate a misconfigured filesystem.
288
- */
289
- export declare function politeFetch(url: string, options?: PoliteFetchOptions): Promise<PoliteFetchResult>;
290
- /** Reset the in-process throttle map. Test-only. */
291
- export declare function __resetHttpThrottle(): void;
292
- /** Cheap heuristic that catches CAPTCHA, WAF block pages, and "Just a moment" interstitials. */
293
- export declare function looksLikeBlockPage(body: string): boolean;
294
- //#endregion
295
- //#region src/sources/irs-publications.d.ts
296
- export interface IrsPublicationsSourceOptions {
297
- /**
298
- * Specific publication slugs to fetch (e.g. `['p15', 'p17', 'p463']`).
299
- * When `includeIndex` is true (default), the publications index page is
300
- * also fetched as a single fragment so change detection can notice
301
- * year/revision shifts across the whole catalogue.
302
- */
303
- publications?: string[];
304
- /**
305
- * Revenue procedure paths to fetch (e.g. `['/irb/2024-31_IRB']`). The
306
- * caller passes the exact path; this source does not auto-discover.
307
- */
308
- revenueProcedures?: string[];
309
- includeIndex?: boolean;
310
- id?: string;
311
- }
312
- /** Default eval dimensions for IRS-sourced fragments. */
313
- export declare const IRS_DIMENSION_HINTS: string[];
314
- export declare function createIrsPublicationsSource(options?: IrsPublicationsSourceOptions): KnowledgeSource;
315
- //#endregion
316
- //#region src/sources/state-sos.d.ts
317
- /**
318
- * Generic Secretary-of-State source.
319
- *
320
- * Every US state SOS surfaces LLC/Corp formation requirements differently
321
- * (CA via static forms pages, DE via division of corporations pages, TX
322
- * via SOSDirect content pages). Rather than baking 50 state-specific
323
- * parsers into this package, the source takes a config that names the URL
324
- * pattern + CSS-equivalent selector + jurisdiction tag. Callers supply one
325
- * config per state they need tracked.
326
- *
327
- * The selector is interpreted as a substring/regex of an HTML element id
328
- * or class — see `StateSosSourceConfig` for the contract. This is
329
- * intentionally minimal; richer extraction belongs in a state-specific
330
- * adapter the consumer authors.
331
- *
332
- * @experimental Interface will likely grow as we add more state coverage.
333
- */
334
- export interface StateSosEntity {
335
- /** Stable id for this fragment within the state (e.g. 'llc-formation', 'corp-formation'). */
336
- id: string;
337
- /** Path under the configured `baseUrl` for this entity. */
338
- path: string;
339
- /**
340
- * Extraction selector. Choose one:
341
- * - `{ kind: 'id', value: 'main-content' }` — innermost match of element with that id
342
- * - `{ kind: 'class', value: 'field--name-body' }` — innermost match of element with that class
343
- * - `{ kind: 'regex', value: /<article[\s\S]*?<\/article>/i }` — raw regex
344
- * - `{ kind: 'whole' }` — full body, tags stripped (fallback for unstructured pages)
345
- */
346
- selector: {
347
- kind: 'id';
348
- value: string;
349
- } | {
350
- kind: 'class';
351
- value: string;
352
- } | {
353
- kind: 'regex';
354
- value: RegExp;
355
- } | {
356
- kind: 'whole';
357
- };
358
- title: string;
359
- /** Eval dimensions this entity feeds. */
360
- dimensionHints?: string[];
361
- }
362
- export interface StateSosSourceConfig {
363
- /** US state postal code, e.g. 'CA', 'DE', 'TX'. */
364
- state: string;
365
- /** Base URL for the state SOS — e.g. 'https://www.sos.ca.gov'. */
366
- baseUrl: string;
367
- /** Entities this state exposes (LLC, Corp, etc). */
368
- entities: StateSosEntity[];
369
- /** Source id; default `state-sos:<state>`. */
370
- id?: string;
371
- /** Display name; default `<state> Secretary of State`. */
372
- name?: string;
373
- }
374
- export declare function createStateSosSource(config: StateSosSourceConfig): KnowledgeSource;
375
- //#endregion
376
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/sources/types.ts","../../src/sources/cornell-lii.ts","../../src/sources/html.ts","../../src/sources/http.ts","../../src/sources/irs-publications.ts","../../src/sources/state-sos.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCiB;;EAEf,SAAS;;EAET;;EAEA,YAAY;;;;;;EAMZ;;;;;;;;;EASA;;;;;;;iBAQe;;EAEf;;;;;;;EAOA;;EAEA;;;;;;;EAOA;;;;;;;;EAQA;;EAEA;;;;;;iBAOe;;;;;;EAMf;;EAEA;;EAEA;;EAEA;EACA,YAAY;;;;;;;;;;;;;EAaZ;;EAEA,WAAW;;;;;;;;;;iBAWI;;EAEf;;EAEA;;EAEA;;;;;;;;;;EAUA,MAAM,MAAM,YAAY,QAAQ;;;;iBCrIjB;;EAEf;;;;;EAKA;;;;;EAKA;;iBAGe;;;;;;;EAOf,WAAW;;EAEX;;;;;;;;;;;;;;;wBAgBc,uBAAuB,SAAS,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;wBCrC1D,WAAW;;wBA4BX,WAAW,cAAc,SAAS;;wBAKlC,cAAc,cAAc;;;;;wBAa5B,aACd,cACA,aAAa,QACb;EACG;EAAc;;;;;;;;;;;;;;qBCxDN;;qBAIA;;qBAGA;iBAII;EACf,SAAS;EACT;;;;;;EAMA;;;;;EAKA,UAAU;;iBAGK;EACf;EACA;;EAEA;;;;;EAKA;EACA;;EAEA;;;;;;EAMA;EACA;;;;;;;;;;;wBAYoB,YACpB,aACA,UAAS,qBACR,QAAQ;;wBAoEK;;wBA6DA,mBAAmB;;;iBChLlB;;;;;;;EAOf;;;;;EAKA;EACA;EACA;;;qBAIW;wBAEG,4BACd,UAAS,+BACR;;;;;;;;;;;;;;;;;;;;iBC5Bc;;EAEf;;EAEA;;;;;;;;EAQA;IACM;IAAY;;IACZ;IAAe;;IACf;IAAe,OAAO;;IACtB;;EACN;;EAEA;;iBAGe;;EAEf;;EAEA;;EAEA,UAAU;;EAEV;;EAEA;;wBAGc,qBAAqB,QAAQ,uBAAuB"}