@tangle-network/agent-knowledge 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/benchmarks/index.d.ts +2 -53
- package/dist/benchmarks/index.js +2 -49
- package/dist/benchmarks-CmW6iORW.js +2718 -0
- package/dist/benchmarks-CmW6iORW.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +180 -274
- package/dist/cli.js.map +1 -1
- package/dist/ids-DRqPZ42_.js +15 -0
- package/dist/ids-DRqPZ42_.js.map +1 -0
- package/dist/index-CGBctbit.d.ts +857 -0
- package/dist/index-CGBctbit.d.ts.map +1 -0
- package/dist/index-CIW3G4s_.d.ts +680 -0
- package/dist/index-CIW3G4s_.d.ts.map +1 -0
- package/dist/index.d.ts +1671 -1868
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5836 -6528
- package/dist/index.js.map +1 -1
- package/dist/inspect-D5iarJc2.js +1864 -0
- package/dist/inspect-D5iarJc2.js.map +1 -0
- package/dist/memory/index.d.ts +3 -8
- package/dist/memory/index.js +3 -81
- package/dist/memory-C6KPRhoU.js +4494 -0
- package/dist/memory-C6KPRhoU.js.map +1 -0
- package/dist/search-CP0QtBJZ.js +113 -0
- package/dist/search-CP0QtBJZ.js.map +1 -0
- package/dist/sources/index.d.ts +212 -205
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +614 -33
- package/dist/sources/index.js.map +1 -1
- package/dist/types-DcCCzreS.d.ts +175 -0
- package/dist/types-DcCCzreS.d.ts.map +1 -0
- package/dist/viz/index.d.ts +23 -22
- package/dist/viz/index.d.ts.map +1 -0
- package/dist/viz/index.js +134 -10
- package/dist/viz/index.js.map +1 -1
- package/package.json +22 -11
- package/dist/benchmarks/index.js.map +0 -1
- package/dist/chunk-46YPZHAX.js +0 -5443
- package/dist/chunk-46YPZHAX.js.map +0 -1
- package/dist/chunk-4PNXQ2NT.js +0 -147
- package/dist/chunk-4PNXQ2NT.js.map +0 -1
- package/dist/chunk-AKYJG2MR.js +0 -2183
- package/dist/chunk-AKYJG2MR.js.map +0 -1
- package/dist/chunk-DQ3PDMDP.js +0 -115
- package/dist/chunk-DQ3PDMDP.js.map +0 -1
- package/dist/chunk-MYFM6LKH.js +0 -551
- package/dist/chunk-MYFM6LKH.js.map +0 -1
- package/dist/chunk-PVCSESAF.js +0 -3153
- package/dist/chunk-PVCSESAF.js.map +0 -1
- package/dist/chunk-YMKHCTS2.js +0 -19
- package/dist/chunk-YMKHCTS2.js.map +0 -1
- package/dist/index-C--N5wQV.d.ts +0 -796
- package/dist/memory/index.js.map +0 -1
- package/dist/types-6x0OpfW6.d.ts +0 -173
- package/dist/types-BY-xLVw-.d.ts +0 -622
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["BASE_URL","extractTitle"],"sources":["../../src/sources/html.ts","../../src/sources/http.ts","../../src/sources/cornell-lii.ts","../../src/sources/irs-publications.ts","../../src/sources/state-sos.ts"],"sourcesContent":["/**\n * Minimal HTML helpers used by the shipped sources.\n *\n * Deliberately not a full DOM parser: every authority we ship against\n * (Cornell LII, IRS.gov, state SOS portals) has well-behaved server-rendered\n * HTML where regex-based extraction is correct and cheap. Bringing in cheerio\n * would add a 1.5MB dependency to a package whose purpose is shipping\n * primitives, not parsing arbitrary web pages.\n *\n * If a future source needs real DOM traversal, it should depend on its own\n * parser locally rather than promoting one into the package-wide deps.\n *\n * @stable\n */\n\n/**\n * Strip HTML tags, collapse whitespace, decode common entities.\n *\n * Preserves paragraph and line breaks (`</p>`, `<br>`, `</li>`, `</div>`,\n * `</h*>`) as `\\n` so statute text retains its subsection structure.\n */\nexport function htmlToText(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, '')\n .replace(/<style[\\s\\S]*?<\\/style>/gi, '')\n .replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '')\n .replace(/<!--([\\s\\S]*?)-->/g, '')\n .replace(/<\\s*br\\s*\\/?>/gi, '\\n')\n .replace(/<\\/(p|li|div|tr|h[1-6]|blockquote|section|article)>/gi, '\\n')\n .replace(/<[^>]+>/g, '')\n .replace(/ /gi, ' ')\n .replace(/&/gi, '&')\n .replace(/</gi, '<')\n .replace(/>/gi, '>')\n .replace(/"/gi, '\"')\n .replace(/'/gi, \"'\")\n .replace(/§/gi, '§')\n .replace(/—/gi, '—')\n .replace(/–/gi, '–')\n .replace(/&#(\\d+);/g, (_, code) => String.fromCodePoint(Number(code)))\n .replace(/&#x([0-9a-f]+);/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16)))\n .split('\\n')\n .map((line) => line.replace(/[\\t ]+/g, ' ').trim())\n .filter((line, idx, all) => !(line === '' && all[idx - 1] === ''))\n .join('\\n')\n .trim()\n}\n\n/** Extract the first match of a regex's first capture group, or undefined. */\nexport function firstMatch(html: string, pattern: RegExp): string | undefined {\n return pattern.exec(html)?.[1]?.trim()\n}\n\n/** Extract the inner HTML of the first matching tag with id `id`. */\nexport function innerHtmlById(html: string, id: string): string | undefined {\n const escaped = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n const tagPattern = new RegExp(\n `<([a-z][a-z0-9]*)\\\\b[^>]*\\\\sid=[\"']${escaped}[\"'][^>]*>([\\\\s\\\\S]*?)<\\\\/\\\\1>`,\n 'i',\n )\n return tagPattern.exec(html)?.[2]\n}\n\n/**\n * Extract every (href, text) pair matching the URL regex.\n * Returns absolute URLs by resolving against `baseUrl`.\n */\nexport function extractLinks(\n html: string,\n hrefPattern: RegExp,\n baseUrl: string,\n): { href: string; text: string }[] {\n const out: { href: string; text: string }[] = []\n const anchor = /<a\\b[^>]*\\shref=[\"']([^\"']+)[\"'][^>]*>([\\s\\S]*?)<\\/a>/gi\n for (const match of html.matchAll(anchor)) {\n const href = match[1]\n const inner = match[2]\n if (!href || !inner) continue\n if (!hrefPattern.test(href)) continue\n const text = htmlToText(inner)\n if (!text) continue\n try {\n out.push({ href: new URL(href, baseUrl).toString(), text })\n } catch {\n /* skip malformed URL */\n }\n }\n return out\n}\n","import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { sha256 } from '../ids'\n\n/**\n * Polite HTTP fetcher shared by remote sources.\n *\n * Independent sources share a per-origin throttle because rate-limited sites\n * may return block pages instead of 429 responses. Responses are cached by URL\n * because many publishers omit reliable ETag and Last-Modified headers. Bodies\n * are checked even after a 2xx response because captcha and block pages often\n * use successful status codes.\n */\n\n/** User-Agent string sent on every outbound request. */\nexport const POLITE_USER_AGENT =\n 'agent-knowledge (+https://github.com/tangle-network/agent-knowledge)'\n\n/** Minimum gap between successive requests to the same origin (ms). */\nexport const MIN_REQUEST_GAP_MS = 1_000\n\n/** Maximum response body we will buffer in memory (bytes). */\nexport const MAX_RESPONSE_BYTES = 8 * 1024 * 1024\n\nconst hostThrottle = new Map<string, Promise<void>>()\n\nexport interface PoliteFetchOptions {\n signal?: AbortSignal\n cacheDir?: string\n /**\n * Cache age beyond which we re-fetch. Default 1 hour, long enough to\n * batch a cron sweep across many selectors, short enough that hourly\n * authoritative-page changes get picked up next tick.\n */\n cacheTtlMs?: number\n /**\n * Extra request headers. The fetcher always sets `User-Agent` and\n * `Accept`; callers can add `Accept-Language` etc.\n */\n headers?: Record<string, string>\n}\n\nexport interface PoliteFetchResult {\n url: string\n status: number\n /** Decoded UTF-8 body. Truncated to `MAX_RESPONSE_BYTES`. */\n body: string\n /**\n * Best-effort source-attested timestamp. Reads `Last-Modified`,\n * falling back to `Date`, falling back to fetch time. Always ISO 8601.\n */\n sourceUpdatedAt: string\n fetchedAt: string\n /** True iff the response was satisfied from disk cache. */\n fromCache: boolean\n /**\n * False on: non-2xx status, captcha/block page heuristic match, or\n * decoded body below 200 chars from a host known to serve real content\n * (Cornell, IRS, state SOS). `unverifiableReason` carries the why.\n */\n verifiable: boolean\n unverifiableReason?: string\n}\n\n/**\n * Fetch one URL with per-host throttling, on-disk cache, and block-page\n * detection. Never throws on network/HTTP failure. It returns a result with\n * `verifiable: false` and `unverifiableReason` set so the caller can decide\n * whether to skip, retry, or surface.\n *\n * Throws ONLY on `AbortError` (caller asked to stop) and on cache-write\n * failures that indicate a misconfigured filesystem.\n */\nexport async function politeFetch(\n url: string,\n options: PoliteFetchOptions = {},\n): Promise<PoliteFetchResult> {\n const cacheTtl = options.cacheTtlMs ?? 60 * 60 * 1000\n const cached = options.cacheDir ? await readCache(options.cacheDir, url, cacheTtl) : undefined\n if (cached) return cached\n\n const host = safeHost(url)\n await throttleHost(host)\n\n const fetchedAt = new Date().toISOString()\n let response: Response\n try {\n response = await fetch(url, {\n signal: options.signal,\n redirect: 'follow',\n headers: {\n 'User-Agent': POLITE_USER_AGENT,\n Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.9',\n ...(options.headers ?? {}),\n },\n })\n } catch (error) {\n if ((error as { name?: string }).name === 'AbortError') throw error\n const result: PoliteFetchResult = {\n url,\n status: 0,\n body: '',\n sourceUpdatedAt: fetchedAt,\n fetchedAt,\n fromCache: false,\n verifiable: false,\n unverifiableReason: `network error: ${(error as Error).message}`,\n }\n if (options.cacheDir) await writeCache(options.cacheDir, url, result)\n return result\n }\n\n const text = await readBoundedText(response)\n const lastModified = response.headers.get('last-modified')\n const dateHeader = response.headers.get('date')\n const sourceUpdatedAt = parseHttpDate(lastModified) ?? parseHttpDate(dateHeader) ?? fetchedAt\n\n const result: PoliteFetchResult = {\n url,\n status: response.status,\n body: text,\n sourceUpdatedAt,\n fetchedAt,\n fromCache: false,\n verifiable: true,\n }\n\n if (response.status < 200 || response.status >= 300) {\n result.verifiable = false\n result.unverifiableReason = `non-2xx status: ${response.status}`\n } else if (looksLikeBlockPage(text)) {\n result.verifiable = false\n result.unverifiableReason = 'block-page heuristic matched'\n } else if (text.length < 200 && knownLargeAuthority(host)) {\n result.verifiable = false\n result.unverifiableReason = `body shorter than expected (${text.length} chars)`\n }\n\n if (options.cacheDir) await writeCache(options.cacheDir, url, result)\n return result\n}\n\n/** Reset the in-process throttle map. Test-only. */\nexport function __resetHttpThrottle(): void {\n hostThrottle.clear()\n}\n\nfunction safeHost(url: string): string {\n try {\n return new URL(url).host\n } catch {\n return 'unknown'\n }\n}\n\nasync function throttleHost(host: string): Promise<void> {\n const prev = hostThrottle.get(host) ?? Promise.resolve()\n let release: () => void = () => {}\n const next = new Promise<void>((resolve) => {\n release = resolve\n })\n hostThrottle.set(\n host,\n prev.then(() => next),\n )\n await prev\n setTimeout(release, MIN_REQUEST_GAP_MS)\n}\n\nasync function readBoundedText(response: Response): Promise<string> {\n if (!response.body) return ''\n const reader = response.body.getReader()\n const chunks: Uint8Array[] = []\n let total = 0\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n if (!value) continue\n total += value.length\n if (total > MAX_RESPONSE_BYTES) {\n // Stop reading; release the underlying connection.\n await reader.cancel()\n break\n }\n chunks.push(value)\n }\n const merged = new Uint8Array(Math.min(total, MAX_RESPONSE_BYTES))\n let offset = 0\n for (const chunk of chunks) {\n const take = Math.min(chunk.length, merged.length - offset)\n if (take <= 0) break\n merged.set(chunk.subarray(0, take), offset)\n offset += take\n }\n return new TextDecoder('utf-8', { fatal: false }).decode(merged)\n}\n\nfunction parseHttpDate(value: string | null): string | undefined {\n if (!value) return undefined\n const ms = Date.parse(value)\n return Number.isFinite(ms) ? new Date(ms).toISOString() : undefined\n}\n\n/** Cheap heuristic that catches CAPTCHA, WAF block pages, and \"Just a moment\" interstitials. */\nexport function looksLikeBlockPage(body: string): boolean {\n if (!body) return false\n const lower = body.toLowerCase()\n const markers = [\n 'verify you are human',\n 'please enable javascript and cookies',\n 'just a moment',\n 'access denied',\n 'request unsuccessful',\n 'cf-error-details',\n 'captcha',\n 'incapsula',\n 'pardon our interruption',\n ]\n for (const marker of markers) {\n if (lower.includes(marker)) return true\n }\n return false\n}\n\nfunction knownLargeAuthority(host: string): boolean {\n return (\n host.endsWith('law.cornell.edu') ||\n host.endsWith('irs.gov') ||\n host.endsWith('sos.ca.gov') ||\n host.endsWith('sos.state.tx.us') ||\n host.endsWith('sos.state.us')\n )\n}\n\nfunction cachePath(cacheDir: string, url: string): string {\n const key = sha256(url)\n return join(cacheDir, 'http', `${key.slice(0, 2)}`, `${key}.json`)\n}\n\nasync function readCache(\n cacheDir: string,\n url: string,\n ttlMs: number,\n): Promise<PoliteFetchResult | undefined> {\n const path = cachePath(cacheDir, url)\n try {\n const info = await stat(path)\n if (Date.now() - info.mtimeMs > ttlMs) return undefined\n const raw = await readFile(path, 'utf8')\n const parsed = JSON.parse(raw) as PoliteFetchResult\n return { ...parsed, fromCache: true }\n } catch {\n return undefined\n }\n}\n\nasync function writeCache(cacheDir: string, url: string, value: PoliteFetchResult): Promise<void> {\n const path = cachePath(cacheDir, url)\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, JSON.stringify(value), 'utf8')\n}\n","import { sha256 } from '../ids'\nimport { htmlToText, innerHtmlById } from './html'\nimport { politeFetch } from './http'\nimport type { FetchOpts, KnowledgeFragment, KnowledgeSource } from './types'\n\n/**\n * Cornell Legal Information Institute (LII) source.\n *\n * Pulls federal US Code sections and Wex encyclopedia entries — the two\n * Cornell LII surfaces an agent typically grounds against. The Wex\n * \"non-compete\" page is the canonical test case for the Ryan-LLC v. FTC\n * vacatur drift the continuous-ingestion story is designed to catch.\n *\n * @stable\n */\n\nconst BASE_URL = 'https://www.law.cornell.edu'\n\nexport interface CornellLiiSelector {\n /** Either 'uscode' or 'wex'. */\n kind: 'uscode' | 'wex'\n /**\n * For `uscode`: `<title>/<section>` (e.g. `'18/1836'` for DTSA).\n * For `wex`: the slug (e.g. `'non-compete'`).\n */\n path: string\n /**\n * Optional pre-declared eval dimensions affected by this section. If\n * omitted, defaults are chosen from `kind` + path heuristics.\n */\n dimensionHints?: string[]\n}\n\nexport interface CornellLiiSourceOptions {\n /**\n * Selectors to fetch on each `fetch()` call. The caller (a per-tenant\n * workspace config, typically) lists exactly the authorities they need\n * tracked. There is no auto-discovery; that would crawl Cornell at\n * cron speed, which is what the polite-fetch contract exists to avoid.\n */\n selectors: CornellLiiSelector[]\n /** Source id override; default is `'cornell-lii'`. */\n id?: string\n}\n\n/**\n * Build a Cornell LII source for the listed selectors.\n *\n * Example: track DTSA + non-compete:\n * ```\n * createCornellLiiSource({\n * selectors: [\n * { kind: 'uscode', path: '18/1836' },\n * { kind: 'wex', path: 'non-compete', dimensionHints: ['jurisdictional_accuracy'] },\n * ],\n * })\n * ```\n */\nexport function createCornellLiiSource(options: CornellLiiSourceOptions): KnowledgeSource {\n const id = options.id ?? 'cornell-lii'\n return {\n id,\n name: 'Cornell Legal Information Institute',\n description:\n 'Federal US Code sections (uscode/text/...) and Wex legal encyclopedia entries from law.cornell.edu.',\n async fetch(opts: FetchOpts): Promise<KnowledgeFragment[]> {\n const limit = opts.limit ?? options.selectors.length\n const selectors = options.selectors.slice(0, limit)\n const out: KnowledgeFragment[] = []\n for (const selector of selectors) {\n out.push(await fetchOne(id, selector, opts))\n }\n return out\n },\n }\n}\n\nasync function fetchOne(\n sourceId: string,\n selector: CornellLiiSelector,\n opts: FetchOpts,\n): Promise<KnowledgeFragment> {\n const path = selector.path.replace(/^\\/+/, '')\n const url =\n selector.kind === 'uscode' ? `${BASE_URL}/uscode/text/${path}` : `${BASE_URL}/wex/${path}`\n\n const response = await politeFetch(url, {\n signal: opts.signal,\n cacheDir: opts.cacheDir,\n })\n\n const fragmentId = `${selector.kind}:${selector.path}`\n const dimensionHints = selector.dimensionHints ?? defaultDimensionHints(selector)\n\n if (!response.verifiable) {\n return {\n id: fragmentId,\n title: `Cornell LII ${selector.kind} ${selector.path}`,\n body: '',\n bodyHash: sha256(''),\n provenance: {\n url,\n sourceUpdatedAt: response.sourceUpdatedAt,\n fetchedAt: response.fetchedAt,\n jurisdiction: 'US-FED',\n verifiable: false,\n unverifiableReason: response.unverifiableReason,\n },\n dimensionHints,\n metadata: { sourceId, status: response.status, fromCache: response.fromCache },\n }\n }\n\n const html = response.body\n const title = extractTitle(html, selector)\n const body = extractBody(html, selector)\n const effective = extractEffectiveDate(html) ?? response.sourceUpdatedAt\n\n const verifiable = body.length > 50\n return {\n id: fragmentId,\n title,\n body,\n bodyHash: sha256(body),\n provenance: {\n url,\n sourceUpdatedAt: effective,\n fetchedAt: response.fetchedAt,\n jurisdiction: 'US-FED',\n verifiable,\n unverifiableReason: verifiable ? undefined : 'extracted body too short',\n },\n dimensionHints,\n metadata: { sourceId, status: response.status, fromCache: response.fromCache },\n }\n}\n\nfunction extractTitle(html: string, selector: CornellLiiSelector): string {\n const h1 = /<h1[^>]*\\bid=[\"']page_title[\"'][^>]*>([\\s\\S]*?)<\\/h1>/i.exec(html)?.[1]\n if (h1) return htmlToText(h1)\n const t = /<title>([\\s\\S]*?)<\\/title>/i.exec(html)?.[1]\n if (t) return htmlToText(t).split(' | ')[0] ?? `Cornell LII ${selector.path}`\n return `Cornell LII ${selector.kind} ${selector.path}`\n}\n\nfunction extractBody(html: string, selector: CornellLiiSelector): string {\n if (selector.kind === 'uscode') {\n // The statute text lives inside a <text><div class=\"text\">…</div></text>\n // block on US Code section pages. Prefer it; fall back to #tab_default_1\n // which always contains the section body.\n const text = /<text>([\\s\\S]*?)<\\/text>/i.exec(html)?.[1]\n if (text) return htmlToText(text)\n const tab = innerHtmlById(html, 'tab_default_1')\n if (tab) return htmlToText(tab)\n }\n // Wex pages wrap the encyclopedia entry under <div id=\"main-content\"> (newer\n // Drupal template) or directly inside <div id=\"extracted-content\"> (older\n // template). Try both — lazy regex matching against a nested-div container\n // returns the wrong (shorter) slice, so we anchor on the leaf containers.\n const mainContent = innerHtmlById(html, 'main-content')\n if (mainContent) {\n return htmlToText(mainContent.replace(/<h1[\\s\\S]*?<\\/h1>/i, ''))\n }\n const extracted = innerHtmlById(html, 'extracted-content')\n if (extracted) {\n return htmlToText(extracted.replace(/<h1[\\s\\S]*?<\\/h1>/i, ''))\n }\n return htmlToText(html)\n}\n\nfunction extractEffectiveDate(html: string): string | undefined {\n // Cornell LII includes \"Editorial Notes\" / \"Amendments\" blocks with\n // dates; the most reliable machine-readable signal is the last\n // amendment year embedded near the section text.\n const amend = /Amendments[\\s\\S]{0,200}?(\\d{4})/i.exec(html)?.[1]\n if (amend) {\n const y = Number.parseInt(amend, 10)\n if (Number.isFinite(y) && y > 1900 && y <= new Date().getUTCFullYear() + 1) {\n return new Date(Date.UTC(y, 11, 31)).toISOString()\n }\n }\n return undefined\n}\n\nfunction defaultDimensionHints(selector: CornellLiiSelector): string[] {\n if (selector.kind === 'uscode') return ['jurisdictional_accuracy', 'citation_hygiene']\n return ['citation_hygiene']\n}\n","import { sha256 } from '../ids'\nimport { htmlToText } from './html'\nimport { politeFetch } from './http'\nimport type { FetchOpts, KnowledgeFragment, KnowledgeSource } from './types'\n\n/**\n * IRS publications source.\n *\n * Two surfaces:\n *\n * 1. The publications index at https://www.irs.gov/publications enumerates\n * every active publication with its revision year — a single fragment\n * with the full table lets change detection notice when a publication\n * year flips (e.g. Pub 15 (2025) → Pub 15 (2026)).\n *\n * 2. Individual publication landing pages at /publications/p<N>[<suffix>]\n * return one fragment per publication with summary text. Callers list\n * the publications they need tracked via `selectors`.\n *\n * Revenue procedures are fetched under their numbered URLs; the IRS does\n * not maintain a stable HTML index of rev-procs, so the caller passes the\n * specific rev-proc paths they care about.\n *\n * @stable\n */\n\nconst BASE_URL = 'https://www.irs.gov'\nconst INDEX_URL = `${BASE_URL}/publications`\n\nexport interface IrsPublicationsSourceOptions {\n /**\n * Specific publication slugs to fetch (e.g. `['p15', 'p17', 'p463']`).\n * When `includeIndex` is true (default), the publications index page is\n * also fetched as a single fragment so change detection can notice\n * year/revision shifts across the whole catalogue.\n */\n publications?: string[]\n /**\n * Revenue procedure paths to fetch (e.g. `['/irb/2024-31_IRB']`). The\n * caller passes the exact path; this source does not auto-discover.\n */\n revenueProcedures?: string[]\n includeIndex?: boolean\n id?: string\n}\n\n/** Default eval dimensions for IRS-sourced fragments. */\nexport const IRS_DIMENSION_HINTS = ['tax_compliance', 'regulatory_currency', 'citation_hygiene']\n\nexport function createIrsPublicationsSource(\n options: IrsPublicationsSourceOptions = {},\n): KnowledgeSource {\n const id = options.id ?? 'irs-publications'\n const includeIndex = options.includeIndex ?? true\n return {\n id,\n name: 'IRS Publications',\n description:\n 'Internal Revenue Service publications index and individual publication landing pages from irs.gov.',\n async fetch(opts: FetchOpts): Promise<KnowledgeFragment[]> {\n const out: KnowledgeFragment[] = []\n const limit = opts.limit ?? Number.POSITIVE_INFINITY\n\n if (includeIndex && out.length < limit) {\n out.push(await fetchIndex(id, opts))\n }\n for (const slug of options.publications ?? []) {\n if (out.length >= limit) break\n out.push(await fetchPublication(id, slug, opts))\n }\n for (const path of options.revenueProcedures ?? []) {\n if (out.length >= limit) break\n out.push(await fetchRevenueProcedure(id, path, opts))\n }\n return out\n },\n }\n}\n\nasync function fetchIndex(sourceId: string, opts: FetchOpts): Promise<KnowledgeFragment> {\n const response = await politeFetch(INDEX_URL, { signal: opts.signal, cacheDir: opts.cacheDir })\n const tablePattern = /<table[\\s\\S]*?<\\/table>/gi\n const matches = response.body.match(tablePattern) ?? []\n // Extract the table that lists current-year publications. IRS publishes\n // one table per year on the index; the most recent table is always the\n // first that mentions a year ≥ current.\n const tables = matches.map((t) => htmlToText(t))\n const body = tables\n .filter((t) => /Publication\\s*\\d+/i.test(t))\n .join('\\n\\n')\n .slice(0, 200_000)\n\n const verifiable = response.verifiable && body.length > 200\n return {\n id: 'index',\n title: 'IRS Publications Index',\n body,\n bodyHash: sha256(body),\n provenance: {\n url: INDEX_URL,\n sourceUpdatedAt: response.sourceUpdatedAt,\n fetchedAt: response.fetchedAt,\n jurisdiction: 'US-FED',\n verifiable,\n unverifiableReason:\n response.unverifiableReason ?? (verifiable ? undefined : 'no publication rows extracted'),\n },\n dimensionHints: IRS_DIMENSION_HINTS,\n metadata: { sourceId, status: response.status, fromCache: response.fromCache, kind: 'index' },\n }\n}\n\nasync function fetchPublication(\n sourceId: string,\n slug: string,\n opts: FetchOpts,\n): Promise<KnowledgeFragment> {\n const url = `${BASE_URL}/publications/${slug.replace(/^\\/+/, '')}`\n const response = await politeFetch(url, { signal: opts.signal, cacheDir: opts.cacheDir })\n\n const title = extractTitle(response.body, `IRS Publication ${slug}`)\n const body = extractMainContent(response.body)\n const verifiable = response.verifiable && body.length > 200\n\n return {\n id: `publication:${slug}`,\n title,\n body,\n bodyHash: sha256(body),\n provenance: {\n url,\n sourceUpdatedAt: extractRevisionDate(response.body) ?? response.sourceUpdatedAt,\n fetchedAt: response.fetchedAt,\n jurisdiction: 'US-FED',\n verifiable,\n unverifiableReason:\n response.unverifiableReason ?? (verifiable ? undefined : 'no publication body extracted'),\n },\n dimensionHints: IRS_DIMENSION_HINTS,\n metadata: {\n sourceId,\n status: response.status,\n fromCache: response.fromCache,\n kind: 'publication',\n slug,\n },\n }\n}\n\nasync function fetchRevenueProcedure(\n sourceId: string,\n path: string,\n opts: FetchOpts,\n): Promise<KnowledgeFragment> {\n const url = `${BASE_URL}${path.startsWith('/') ? path : `/${path}`}`\n const response = await politeFetch(url, { signal: opts.signal, cacheDir: opts.cacheDir })\n const body = extractMainContent(response.body)\n const verifiable = response.verifiable && body.length > 200\n return {\n id: `rev-proc:${path}`,\n title: extractTitle(response.body, `IRS Revenue Procedure ${path}`),\n body,\n bodyHash: sha256(body),\n provenance: {\n url,\n sourceUpdatedAt: response.sourceUpdatedAt,\n fetchedAt: response.fetchedAt,\n jurisdiction: 'US-FED',\n verifiable,\n unverifiableReason:\n response.unverifiableReason ??\n (verifiable ? undefined : 'no revenue-procedure body extracted'),\n },\n dimensionHints: [...IRS_DIMENSION_HINTS, 'procedural_currency'],\n metadata: {\n sourceId,\n status: response.status,\n fromCache: response.fromCache,\n kind: 'rev-proc',\n path,\n },\n }\n}\n\nfunction extractTitle(html: string, fallback: string): string {\n const og = /<meta\\s+property=[\"']og:title[\"']\\s+content=[\"']([^\"']+)[\"']/i.exec(html)?.[1]\n if (og) return decodeHtml(og)\n const title = /<title>([\\s\\S]*?)<\\/title>/i.exec(html)?.[1]\n if (title) return htmlToText(title).split(' | ')[0] ?? fallback\n return fallback\n}\n\nfunction extractMainContent(html: string): string {\n // IRS uses Drupal — the main publication body is inside <main role=\"main\">\n // or under .field--name-body. We try main first; on miss, body.\n const main = /<main\\b[\\s\\S]*?<\\/main>/i.exec(html)?.[0]\n if (main) {\n const noNav = main\n .replace(/<nav[\\s\\S]*?<\\/nav>/gi, '')\n .replace(/<header[\\s\\S]*?<\\/header>/gi, '')\n .replace(/<footer[\\s\\S]*?<\\/footer>/gi, '')\n return htmlToText(noNav).slice(0, 200_000)\n }\n const body = /<body\\b[\\s\\S]*?<\\/body>/i.exec(html)?.[0]\n return body ? htmlToText(body).slice(0, 200_000) : htmlToText(html).slice(0, 200_000)\n}\n\nfunction extractRevisionDate(html: string): string | undefined {\n // IRS publication pages typically show \"Publication X (YYYY)\" in the title;\n // pulling the year gives a stable revision marker.\n const m = /Publication\\s+\\S+\\s*\\((\\d{4})\\)/i.exec(html)\n if (m?.[1]) {\n const year = Number.parseInt(m[1], 10)\n if (Number.isFinite(year) && year >= 2000 && year <= new Date().getUTCFullYear() + 1) {\n return new Date(Date.UTC(year, 0, 1)).toISOString()\n }\n }\n return undefined\n}\n\nfunction decodeHtml(value: string): string {\n return htmlToText(value)\n}\n","import { sha256 } from '../ids'\nimport { htmlToText } from './html'\nimport { politeFetch } from './http'\nimport type { FetchOpts, KnowledgeFragment, KnowledgeSource } from './types'\n\n/**\n * Generic Secretary-of-State source.\n *\n * Every US state SOS surfaces LLC/Corp formation requirements differently\n * (CA via static forms pages, DE via division of corporations pages, TX\n * via SOSDirect content pages). Rather than baking 50 state-specific\n * parsers into this package, the source takes a config that names the URL\n * pattern + CSS-equivalent selector + jurisdiction tag. Callers supply one\n * config per state they need tracked.\n *\n * The selector is interpreted as a substring/regex of an HTML element id\n * or class — see `StateSosSourceConfig` for the contract. This is\n * intentionally minimal; richer extraction belongs in a state-specific\n * adapter the consumer authors.\n *\n * @experimental Interface will likely grow as we add more state coverage.\n */\n\nexport interface StateSosEntity {\n /** Stable id for this fragment within the state (e.g. 'llc-formation', 'corp-formation'). */\n id: string\n /** Path under the configured `baseUrl` for this entity. */\n path: string\n /**\n * Extraction selector. Choose one:\n * - `{ kind: 'id', value: 'main-content' }` — innermost match of element with that id\n * - `{ kind: 'class', value: 'field--name-body' }` — innermost match of element with that class\n * - `{ kind: 'regex', value: /<article[\\s\\S]*?<\\/article>/i }` — raw regex\n * - `{ kind: 'whole' }` — full body, tags stripped (fallback for unstructured pages)\n */\n selector:\n | { kind: 'id'; value: string }\n | { kind: 'class'; value: string }\n | { kind: 'regex'; value: RegExp }\n | { kind: 'whole' }\n title: string\n /** Eval dimensions this entity feeds. */\n dimensionHints?: string[]\n}\n\nexport interface StateSosSourceConfig {\n /** US state postal code, e.g. 'CA', 'DE', 'TX'. */\n state: string\n /** Base URL for the state SOS — e.g. 'https://www.sos.ca.gov'. */\n baseUrl: string\n /** Entities this state exposes (LLC, Corp, etc). */\n entities: StateSosEntity[]\n /** Source id; default `state-sos:<state>`. */\n id?: string\n /** Display name; default `<state> Secretary of State`. */\n name?: string\n}\n\nexport function createStateSosSource(config: StateSosSourceConfig): KnowledgeSource {\n const id = config.id ?? `state-sos:${config.state.toLowerCase()}`\n const name = config.name ?? `${config.state} Secretary of State`\n return {\n id,\n name,\n description: `${config.state} Secretary of State filings and formation guidance pages.`,\n async fetch(opts: FetchOpts): Promise<KnowledgeFragment[]> {\n const limit = opts.limit ?? config.entities.length\n const entities = config.entities.slice(0, limit)\n const out: KnowledgeFragment[] = []\n for (const entity of entities) {\n out.push(await fetchEntity(id, config, entity, opts))\n }\n return out\n },\n }\n}\n\nasync function fetchEntity(\n sourceId: string,\n config: StateSosSourceConfig,\n entity: StateSosEntity,\n opts: FetchOpts,\n): Promise<KnowledgeFragment> {\n const url = joinUrl(config.baseUrl, entity.path)\n const response = await politeFetch(url, { signal: opts.signal, cacheDir: opts.cacheDir })\n\n const body = response.verifiable ? extractBySelector(response.body, entity.selector) : ''\n const verifiable = response.verifiable && body.length > 100\n\n return {\n id: entity.id,\n title: entity.title,\n body,\n bodyHash: sha256(body),\n provenance: {\n url,\n sourceUpdatedAt: response.sourceUpdatedAt,\n fetchedAt: response.fetchedAt,\n jurisdiction: `US-${config.state.toUpperCase()}`,\n verifiable,\n unverifiableReason:\n response.unverifiableReason ?? (verifiable ? undefined : 'extracted body too short'),\n },\n dimensionHints: entity.dimensionHints ?? [\n 'jurisdictional_accuracy',\n 'corporate_formation',\n 'citation_hygiene',\n ],\n metadata: {\n sourceId,\n status: response.status,\n fromCache: response.fromCache,\n state: config.state,\n },\n }\n}\n\nfunction extractBySelector(html: string, selector: StateSosEntity['selector']): string {\n if (selector.kind === 'whole') {\n const main = /<main\\b[\\s\\S]*?<\\/main>/i.exec(html)?.[0]\n return htmlToText(main ?? html).slice(0, 200_000)\n }\n if (selector.kind === 'regex') {\n const m = selector.value.exec(html)?.[0]\n return m ? htmlToText(m).slice(0, 200_000) : ''\n }\n if (selector.kind === 'id') {\n const escaped = selector.value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n const pattern = new RegExp(\n `<([a-z][a-z0-9]*)\\\\b[^>]*\\\\sid=[\"']${escaped}[\"'][^>]*>([\\\\s\\\\S]*?)<\\\\/\\\\1>`,\n 'i',\n )\n const inner = pattern.exec(html)?.[2]\n return inner ? htmlToText(inner).slice(0, 200_000) : ''\n }\n const escaped = selector.value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n const pattern = new RegExp(\n `<([a-z][a-z0-9]*)\\\\b[^>]*\\\\sclass=[\"'][^\"']*\\\\b${escaped}\\\\b[^\"']*[\"'][^>]*>([\\\\s\\\\S]*?)<\\\\/\\\\1>`,\n 'i',\n )\n const inner = pattern.exec(html)?.[2]\n return inner ? htmlToText(inner).slice(0, 200_000) : ''\n}\n\nfunction joinUrl(base: string, path: string): string {\n try {\n return new URL(path, base.endsWith('/') ? base : `${base}/`).toString()\n } catch {\n return `${base.replace(/\\/+$/, '')}/${path.replace(/^\\/+/, '')}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,WAAW,MAAsB;CAC/C,OAAO,KACJ,QAAQ,+BAA+B,EAAE,CAAC,CAC1C,QAAQ,6BAA6B,EAAE,CAAC,CACxC,QAAQ,mCAAmC,EAAE,CAAC,CAC9C,QAAQ,sBAAsB,EAAE,CAAC,CACjC,QAAQ,mBAAmB,IAAI,CAAC,CAChC,QAAQ,yDAAyD,IAAI,CAAC,CACtE,QAAQ,YAAY,EAAE,CAAC,CACvB,QAAQ,YAAY,GAAG,CAAC,CACxB,QAAQ,WAAW,GAAG,CAAC,CACvB,QAAQ,UAAU,GAAG,CAAC,CACtB,QAAQ,UAAU,GAAG,CAAC,CACtB,QAAQ,YAAY,IAAG,CAAC,CACxB,QAAQ,WAAW,GAAG,CAAC,CACvB,QAAQ,YAAY,GAAG,CAAC,CACxB,QAAQ,aAAa,GAAG,CAAC,CACzB,QAAQ,aAAa,GAAG,CAAC,CACzB,QAAQ,cAAc,GAAG,SAAS,OAAO,cAAc,OAAO,IAAI,CAAC,CAAC,CAAC,CACrE,QAAQ,sBAAsB,GAAG,SAAS,OAAO,cAAc,OAAO,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,CAC1F,MAAM,IAAI,CAAC,CACX,KAAK,SAAS,KAAK,QAAQ,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CACnD,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CACjE,KAAK,IAAI,CAAC,CACV,KAAK;AACV;;AAGA,SAAgB,WAAW,MAAc,SAAqC;CAC5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M,KAAK,IAAI,CAAC,GAAG;EACtC,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,GAAG,GAAO,IAAI;CAC/C;CACA,IAAI,SAAS,SAAS,MAAM;EAC1B,MAAM,UAAU,SAAS,MAAM,QAAQ,uBAAuB,MAAM;EAKpE,MAAM,QAAQ,IAJM,OAClB,sCAAsC,QAAQ,iCAC9C,GAEkB,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG;EACnC,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,MAAM,GAAG,GAAO,IAAI;CACvD;CACA,MAAM,UAAU,SAAS,MAAM,QAAQ,uBAAuB,MAAM;CAKpE,MAAM,QAAQ,IAJM,OAClB,kDAAkD,QAAQ,0CAC1D,GAEkB,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG;CACnC,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,MAAM,GAAG,GAAO,IAAI;AACvD;AAEA,SAAS,QAAQ,MAAc,MAAsB;CACnD,IAAI;EACF,OAAO,IAAI,IAAI,MAAM,KAAK,SAAS,GAAG,IAAI,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,SAAS;CACxE,QAAQ;EACN,OAAO,GAAG,KAAK,QAAQ,QAAQ,EAAE,EAAE,GAAG,KAAK,QAAQ,QAAQ,EAAE;CAC/D;AACF"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type KnowledgeId = string;
|
|
3
|
+
interface SourceAnchor {
|
|
4
|
+
id: string;
|
|
5
|
+
sourceId: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
page?: number;
|
|
8
|
+
lineStart?: number;
|
|
9
|
+
lineEnd?: number;
|
|
10
|
+
charStart?: number;
|
|
11
|
+
charEnd?: number;
|
|
12
|
+
timestampMs?: number;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
interface SourceRecord {
|
|
16
|
+
id: KnowledgeId;
|
|
17
|
+
uri: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
mediaType?: string;
|
|
20
|
+
contentHash: string;
|
|
21
|
+
text?: string;
|
|
22
|
+
anchors?: SourceAnchor[];
|
|
23
|
+
/** ISO timestamp after which consumers should treat this source as stale. */
|
|
24
|
+
validUntil?: string;
|
|
25
|
+
/** ISO timestamp for the last successful source freshness verification. */
|
|
26
|
+
lastVerifiedAt?: string;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
}
|
|
30
|
+
interface SourceRegistry {
|
|
31
|
+
generatedAt: string;
|
|
32
|
+
sources: SourceRecord[];
|
|
33
|
+
}
|
|
34
|
+
interface ClaimRef {
|
|
35
|
+
sourceId: string;
|
|
36
|
+
anchorId?: string;
|
|
37
|
+
quote?: string;
|
|
38
|
+
}
|
|
39
|
+
interface KnowledgeClaim {
|
|
40
|
+
id: KnowledgeId;
|
|
41
|
+
text: string;
|
|
42
|
+
refs: ClaimRef[];
|
|
43
|
+
confidence?: number;
|
|
44
|
+
status?: 'draft' | 'active' | 'superseded' | 'rejected';
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
interface KnowledgeRelation {
|
|
48
|
+
sourceId: KnowledgeId;
|
|
49
|
+
targetId: KnowledgeId;
|
|
50
|
+
predicate: string;
|
|
51
|
+
weight?: number;
|
|
52
|
+
metadata?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
interface KnowledgeUnit {
|
|
55
|
+
id: KnowledgeId;
|
|
56
|
+
title: string;
|
|
57
|
+
text: string;
|
|
58
|
+
claims?: KnowledgeClaim[];
|
|
59
|
+
relations?: KnowledgeRelation[];
|
|
60
|
+
sourceIds?: string[];
|
|
61
|
+
tags?: string[];
|
|
62
|
+
metadata?: Record<string, unknown>;
|
|
63
|
+
updatedAt?: string;
|
|
64
|
+
}
|
|
65
|
+
interface KnowledgePage {
|
|
66
|
+
id: KnowledgeId;
|
|
67
|
+
path: string;
|
|
68
|
+
title: string;
|
|
69
|
+
text: string;
|
|
70
|
+
frontmatter: Record<string, unknown>;
|
|
71
|
+
sourceIds: string[];
|
|
72
|
+
tags: string[];
|
|
73
|
+
outLinks: string[];
|
|
74
|
+
}
|
|
75
|
+
interface KnowledgeGraphNode {
|
|
76
|
+
id: KnowledgeId;
|
|
77
|
+
title: string;
|
|
78
|
+
path: string;
|
|
79
|
+
tags: string[];
|
|
80
|
+
sourceIds: string[];
|
|
81
|
+
outDegree: number;
|
|
82
|
+
inDegree: number;
|
|
83
|
+
}
|
|
84
|
+
interface KnowledgeGraphEdge {
|
|
85
|
+
source: KnowledgeId;
|
|
86
|
+
target: KnowledgeId;
|
|
87
|
+
weight: number;
|
|
88
|
+
reasons: string[];
|
|
89
|
+
}
|
|
90
|
+
interface KnowledgeGraph {
|
|
91
|
+
nodes: KnowledgeGraphNode[];
|
|
92
|
+
edges: KnowledgeGraphEdge[];
|
|
93
|
+
}
|
|
94
|
+
interface KnowledgeIndex {
|
|
95
|
+
root: string;
|
|
96
|
+
generatedAt: string;
|
|
97
|
+
sources: SourceRecord[];
|
|
98
|
+
pages: KnowledgePage[];
|
|
99
|
+
graph: KnowledgeGraph;
|
|
100
|
+
}
|
|
101
|
+
interface KnowledgeSearchResult {
|
|
102
|
+
page: KnowledgePage;
|
|
103
|
+
/**
|
|
104
|
+
* Raw reciprocal rank fusion score. Mathematically meaningful for ordering
|
|
105
|
+
* but not on a [0, 1] confidence scale — typical absolute values are in the
|
|
106
|
+
* 0.01–0.05 range. Equal to `rrfScore`; preserved as `score` for backward
|
|
107
|
+
* compatibility with consumers built against earlier releases.
|
|
108
|
+
*/
|
|
109
|
+
score: number;
|
|
110
|
+
/** Alias of `score` — the raw RRF value. Use this when intent matters. */
|
|
111
|
+
rrfScore: number;
|
|
112
|
+
/**
|
|
113
|
+
* Score linearly normalized to [0, 1] relative to the top hit *in this
|
|
114
|
+
* result set*. The top hit is always 1 (when present); subsequent hits are
|
|
115
|
+
* `score / topScore`. Designed to match human intuition for "how confident
|
|
116
|
+
* is this match" — safe to compare against fixed thresholds. Note: this is
|
|
117
|
+
* a within-set ranking, not a cross-query absolute confidence.
|
|
118
|
+
*/
|
|
119
|
+
normalizedScore: number;
|
|
120
|
+
rank: number;
|
|
121
|
+
snippet: string;
|
|
122
|
+
reasons: string[];
|
|
123
|
+
}
|
|
124
|
+
interface KnowledgeLintFinding {
|
|
125
|
+
type: 'broken-link' | 'orphan' | 'no-outlinks' | 'uncited-claim' | 'missing-source' | 'duplicate-title' | 'duplicate-page-id' | 'duplicate-source-hash' | 'missing-frontmatter';
|
|
126
|
+
severity: 'info' | 'warning' | 'error';
|
|
127
|
+
page?: string;
|
|
128
|
+
message: string;
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
interface KnowledgePolicy {
|
|
132
|
+
id: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
requiredCitationRate?: number;
|
|
135
|
+
allowedPathPrefixes?: string[];
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
}
|
|
138
|
+
interface KnowledgeBaseCandidate {
|
|
139
|
+
id: KnowledgeId;
|
|
140
|
+
units: KnowledgeUnit[];
|
|
141
|
+
retrievalPolicy?: string;
|
|
142
|
+
synthesisPolicy?: string;
|
|
143
|
+
questionPolicy?: string;
|
|
144
|
+
updatePolicy?: string;
|
|
145
|
+
metadata?: Record<string, unknown>;
|
|
146
|
+
}
|
|
147
|
+
interface KnowledgeWriteBlock {
|
|
148
|
+
path: string;
|
|
149
|
+
content: string;
|
|
150
|
+
}
|
|
151
|
+
interface KnowledgeWriteParseResult {
|
|
152
|
+
blocks: KnowledgeWriteBlock[];
|
|
153
|
+
warnings: string[];
|
|
154
|
+
}
|
|
155
|
+
type KnowledgeEventType = 'source.added' | 'proposal.applied' | 'index.built' | 'lint.run' | 'research.iteration' | 'optimization.run' | 'release.promoted' | 'release.rejected';
|
|
156
|
+
interface KnowledgeEvent {
|
|
157
|
+
id: string;
|
|
158
|
+
type: KnowledgeEventType;
|
|
159
|
+
createdAt: string;
|
|
160
|
+
actor?: string;
|
|
161
|
+
target?: string;
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
interface KnowledgeRelease {
|
|
165
|
+
id: string;
|
|
166
|
+
candidateId: string;
|
|
167
|
+
createdAt: string;
|
|
168
|
+
promoted: boolean;
|
|
169
|
+
scorecard?: unknown;
|
|
170
|
+
runRecordIds?: string[];
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { SourceRegistry as S, KnowledgeUnit as _, KnowledgeEventType as a, SourceAnchor as b, KnowledgeGraphNode as c, KnowledgeLintFinding as d, KnowledgePage as f, KnowledgeSearchResult as g, KnowledgeRelease as h, KnowledgeEvent as i, KnowledgeId as l, KnowledgeRelation as m, KnowledgeBaseCandidate as n, KnowledgeGraph as o, KnowledgePolicy as p, KnowledgeClaim as r, KnowledgeGraphEdge as s, ClaimRef as t, KnowledgeIndex as u, KnowledgeWriteBlock as v, SourceRecord as x, KnowledgeWriteParseResult as y };
|
|
175
|
+
//# sourceMappingURL=types-DcCCzreS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DcCCzreS.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KAAY;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;;UAGI;EACf,IAAI;EACJ;EACA;EACA;EACA;EACA;EACA,UAAU;;EAEV;;EAEA;EACA,WAAW;EACX;;UAGe;EACf;EACA,SAAS;;UAGM;EACf;EACA;EACA;;UAGe;EACf,IAAI;EACJ;EACA,MAAM;EACN;EACA;EACA,WAAW;;UAGI;EACf,UAAU;EACV,UAAU;EACV;EACA;EACA,WAAW;;UAGI;EACf,IAAI;EACJ;EACA;EACA,SAAS;EACT,YAAY;EACZ;EACA;EACA,WAAW;EACX;;UAGe;EACf,IAAI;EACJ;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;;UAGe;EACf,IAAI;EACJ;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,QAAQ;EACR,QAAQ;EACR;EACA;;UAGe;EACf,OAAO;EACP,OAAO;;UAGQ;EACf;EACA;EACA,SAAS;EACT,OAAO;EACP,OAAO;;UAGQ;EACf,MAAM;;;;;;;EAON;;EAEA;;;;;;;;EAQA;EACA;EACA;EACA;;UAGe;EACf;EAUA;EACA;EACA;EACA,WAAW;;UAGI;EACf;EACA;EACA;EACA;EACA,WAAW;;UAGI;EACf,IAAI;EACJ,OAAO;EACP;EACA;EACA;EACA;EACA,WAAW;;UAGI;EACf;EACA;;UAGe;EACf,QAAQ;EACR;;KAGU;UAUK;EACf;EACA,MAAM;EACN;EACA;EACA;EACA,WAAW;;UAGI;EACf;EACA;EACA;EACA;EACA;EACA;EACA,WAAW"}
|
package/dist/viz/index.d.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { c as KnowledgeGraphNode, o as KnowledgeGraph, s as KnowledgeGraphEdge } from "../types-DcCCzreS.js";
|
|
2
|
+
//#region src/viz/index.d.ts
|
|
3
3
|
interface KnowledgeVizNode extends KnowledgeGraphNode {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
degree: number;
|
|
5
|
+
community: number;
|
|
6
6
|
}
|
|
7
7
|
interface KnowledgeVizEdge extends KnowledgeGraphEdge {
|
|
8
|
-
|
|
8
|
+
id: string;
|
|
9
9
|
}
|
|
10
10
|
interface KnowledgeCommunity {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
id: number;
|
|
12
|
+
nodeIds: string[];
|
|
13
|
+
topTitles: string[];
|
|
14
|
+
cohesion: number;
|
|
15
15
|
}
|
|
16
16
|
interface KnowledgeVizGraph {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
nodes: KnowledgeVizNode[];
|
|
18
|
+
edges: KnowledgeVizEdge[];
|
|
19
|
+
communities: KnowledgeCommunity[];
|
|
20
20
|
}
|
|
21
21
|
interface KnowledgeGap {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
type: 'isolated-node' | 'sparse-community' | 'bridge-node';
|
|
23
|
+
title: string;
|
|
24
|
+
nodeIds: string[];
|
|
25
|
+
suggestion: string;
|
|
26
26
|
}
|
|
27
27
|
interface SurprisingConnection {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
source: KnowledgeVizNode;
|
|
29
|
+
target: KnowledgeVizNode;
|
|
30
|
+
score: number;
|
|
31
|
+
reasons: string[];
|
|
32
32
|
}
|
|
33
33
|
declare function toKnowledgeVizGraph(graph: KnowledgeGraph): KnowledgeVizGraph;
|
|
34
34
|
declare function detectKnowledgeGaps(graph: KnowledgeVizGraph, limit?: number): KnowledgeGap[];
|
|
35
35
|
declare function findSurprisingConnections(graph: KnowledgeVizGraph, limit?: number): SurprisingConnection[];
|
|
36
|
-
|
|
37
|
-
export {
|
|
36
|
+
//#endregion
|
|
37
|
+
export { KnowledgeCommunity, KnowledgeGap, KnowledgeVizEdge, KnowledgeVizGraph, KnowledgeVizNode, SurprisingConnection, detectKnowledgeGaps, findSurprisingConnections, toKnowledgeVizGraph };
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/viz/index.ts"],"mappings":";;UAEiB,yBAAyB;EACxC;EACA;;UAGe,yBAAyB;EACxC;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,OAAO;EACP,aAAa;;UAGE;EACf;EACA;EACA;EACA;;UAGe;EACf,QAAQ;EACR,QAAQ;EACR;EACA;;iBAGc,oBAAoB,OAAO,iBAAiB;iBAmB5C,oBAAoB,OAAO,mBAAmB,iBAAa;iBA+C3D,0BACd,OAAO,mBACP,iBACC"}
|
package/dist/viz/index.js
CHANGED
|
@@ -1,11 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//#region src/viz/index.ts
|
|
2
|
+
function toKnowledgeVizGraph(graph) {
|
|
3
|
+
const adjacency = buildAdjacency(graph);
|
|
4
|
+
const communities = assignCommunities(graph.nodes, adjacency);
|
|
5
|
+
const communityByNode = /* @__PURE__ */ new Map();
|
|
6
|
+
communities.forEach((community) => {
|
|
7
|
+
for (const nodeId of community.nodeIds) communityByNode.set(hashNode(nodeId), community.id);
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
nodes: graph.nodes.map((node) => ({
|
|
11
|
+
...node,
|
|
12
|
+
degree: node.inDegree + node.outDegree,
|
|
13
|
+
community: communityByNode.get(hashNode(node.id)) ?? 0
|
|
14
|
+
})),
|
|
15
|
+
edges: graph.edges.map((edge) => ({
|
|
16
|
+
...edge,
|
|
17
|
+
id: `${edge.source}->${edge.target}`
|
|
18
|
+
})),
|
|
19
|
+
communities
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function detectKnowledgeGaps(graph, limit = 10) {
|
|
23
|
+
const gaps = [];
|
|
24
|
+
const isolated = graph.nodes.filter((node) => node.degree <= 1 && !isStructural(node.path));
|
|
25
|
+
if (isolated.length > 0) gaps.push({
|
|
26
|
+
type: "isolated-node",
|
|
27
|
+
title: `${isolated.length} isolated page${isolated.length === 1 ? "" : "s"}`,
|
|
28
|
+
nodeIds: isolated.map((node) => node.id),
|
|
29
|
+
suggestion: "Add cross-links, sources, or follow-up research to connect these pages to the knowledge graph."
|
|
30
|
+
});
|
|
31
|
+
for (const community of graph.communities) if (community.nodeIds.length >= 3 && community.cohesion < .15) gaps.push({
|
|
32
|
+
type: "sparse-community",
|
|
33
|
+
title: `Sparse cluster: ${community.topTitles[0] ?? `community ${community.id}`}`,
|
|
34
|
+
nodeIds: community.nodeIds,
|
|
35
|
+
suggestion: "This cluster has weak internal evidence. Add synthesis pages or relation links between its strongest concepts."
|
|
36
|
+
});
|
|
37
|
+
const byCommunityNeighbors = /* @__PURE__ */ new Map();
|
|
38
|
+
const nodeById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
39
|
+
for (const edge of graph.edges) {
|
|
40
|
+
const source = nodeById.get(edge.source);
|
|
41
|
+
const target = nodeById.get(edge.target);
|
|
42
|
+
if (!source || !target) continue;
|
|
43
|
+
if (!byCommunityNeighbors.has(source.id)) byCommunityNeighbors.set(source.id, /* @__PURE__ */ new Set());
|
|
44
|
+
if (!byCommunityNeighbors.has(target.id)) byCommunityNeighbors.set(target.id, /* @__PURE__ */ new Set());
|
|
45
|
+
byCommunityNeighbors.get(source.id).add(target.community);
|
|
46
|
+
byCommunityNeighbors.get(target.id).add(source.community);
|
|
47
|
+
}
|
|
48
|
+
for (const node of graph.nodes) if ((byCommunityNeighbors.get(node.id)?.size ?? 0) >= 3) gaps.push({
|
|
49
|
+
type: "bridge-node",
|
|
50
|
+
title: `Bridge page: ${node.title}`,
|
|
51
|
+
nodeIds: [node.id],
|
|
52
|
+
suggestion: "This page connects multiple knowledge areas. Keep it well cited and current."
|
|
53
|
+
});
|
|
54
|
+
return gaps.slice(0, limit);
|
|
55
|
+
}
|
|
56
|
+
function findSurprisingConnections(graph, limit = 10) {
|
|
57
|
+
const nodeById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
58
|
+
const scored = [];
|
|
59
|
+
for (const edge of graph.edges) {
|
|
60
|
+
const source = nodeById.get(edge.source);
|
|
61
|
+
const target = nodeById.get(edge.target);
|
|
62
|
+
if (!source || !target) continue;
|
|
63
|
+
let score = edge.weight;
|
|
64
|
+
const reasons = [...edge.reasons];
|
|
65
|
+
if (source.community !== target.community) {
|
|
66
|
+
score += 3;
|
|
67
|
+
reasons.push("cross-community");
|
|
68
|
+
}
|
|
69
|
+
if (source.tags.some((tag) => !target.tags.includes(tag))) {
|
|
70
|
+
score += 1;
|
|
71
|
+
reasons.push("cross-tag");
|
|
72
|
+
}
|
|
73
|
+
if (score >= 3) scored.push({
|
|
74
|
+
source,
|
|
75
|
+
target,
|
|
76
|
+
score,
|
|
77
|
+
reasons
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
81
|
+
}
|
|
82
|
+
function buildAdjacency(graph) {
|
|
83
|
+
const out = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const node of graph.nodes) out.set(node.id, /* @__PURE__ */ new Set());
|
|
85
|
+
for (const edge of graph.edges) {
|
|
86
|
+
out.get(edge.source)?.add(edge.target);
|
|
87
|
+
out.get(edge.target)?.add(edge.source);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function assignCommunities(nodes, adjacency) {
|
|
92
|
+
const seen = /* @__PURE__ */ new Set();
|
|
93
|
+
const communities = [];
|
|
94
|
+
for (const node of nodes) {
|
|
95
|
+
if (seen.has(node.id)) continue;
|
|
96
|
+
const queue = [node.id];
|
|
97
|
+
const ids = [];
|
|
98
|
+
seen.add(node.id);
|
|
99
|
+
while (queue.length > 0) {
|
|
100
|
+
const id = queue.shift();
|
|
101
|
+
ids.push(id);
|
|
102
|
+
for (const next of adjacency.get(id) ?? []) if (!seen.has(next)) {
|
|
103
|
+
seen.add(next);
|
|
104
|
+
queue.push(next);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const memberNodes = ids.map((id) => nodes.find((candidate) => candidate.id === id)).filter((item) => Boolean(item));
|
|
108
|
+
communities.push({
|
|
109
|
+
id: communities.length,
|
|
110
|
+
nodeIds: ids,
|
|
111
|
+
topTitles: memberNodes.sort((a, b) => b.inDegree + b.outDegree - (a.inDegree + a.outDegree)).slice(0, 5).map((item) => item.title),
|
|
112
|
+
cohesion: cohesion(ids, adjacency)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return communities.sort((a, b) => b.nodeIds.length - a.nodeIds.length);
|
|
116
|
+
}
|
|
117
|
+
function cohesion(ids, adjacency) {
|
|
118
|
+
if (ids.length < 2) return 0;
|
|
119
|
+
let edges = 0;
|
|
120
|
+
const idSet = new Set(ids);
|
|
121
|
+
for (const id of ids) for (const next of adjacency.get(id) ?? []) if (idSet.has(next)) edges++;
|
|
122
|
+
return edges / (ids.length * (ids.length - 1));
|
|
123
|
+
}
|
|
124
|
+
function hashNode(id) {
|
|
125
|
+
let hash = 0;
|
|
126
|
+
for (const char of id) hash = hash * 31 + char.charCodeAt(0) | 0;
|
|
127
|
+
return hash;
|
|
128
|
+
}
|
|
129
|
+
function isStructural(path) {
|
|
130
|
+
return path.endsWith("/index.md") || path.endsWith("/log.md");
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { detectKnowledgeGaps, findSurprisingConnections, toKnowledgeVizGraph };
|
|
134
|
+
|
|
11
135
|
//# sourceMappingURL=index.js.map
|
package/dist/viz/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/viz/index.ts"],"sourcesContent":["import type { KnowledgeGraph, KnowledgeGraphEdge, KnowledgeGraphNode } from '../types'\n\nexport interface KnowledgeVizNode extends KnowledgeGraphNode {\n degree: number\n community: number\n}\n\nexport interface KnowledgeVizEdge extends KnowledgeGraphEdge {\n id: string\n}\n\nexport interface KnowledgeCommunity {\n id: number\n nodeIds: string[]\n topTitles: string[]\n cohesion: number\n}\n\nexport interface KnowledgeVizGraph {\n nodes: KnowledgeVizNode[]\n edges: KnowledgeVizEdge[]\n communities: KnowledgeCommunity[]\n}\n\nexport interface KnowledgeGap {\n type: 'isolated-node' | 'sparse-community' | 'bridge-node'\n title: string\n nodeIds: string[]\n suggestion: string\n}\n\nexport interface SurprisingConnection {\n source: KnowledgeVizNode\n target: KnowledgeVizNode\n score: number\n reasons: string[]\n}\n\nexport function toKnowledgeVizGraph(graph: KnowledgeGraph): KnowledgeVizGraph {\n const adjacency = buildAdjacency(graph)\n const communities = assignCommunities(graph.nodes, adjacency)\n const communityByNode = new Map<number, number>()\n communities.forEach((community) => {\n for (const nodeId of community.nodeIds) communityByNode.set(hashNode(nodeId), community.id)\n })\n const nodes = graph.nodes.map((node) => ({\n ...node,\n degree: node.inDegree + node.outDegree,\n community: communityByNode.get(hashNode(node.id)) ?? 0,\n }))\n return {\n nodes,\n edges: graph.edges.map((edge) => ({ ...edge, id: `${edge.source}->${edge.target}` })),\n communities,\n }\n}\n\nexport function detectKnowledgeGaps(graph: KnowledgeVizGraph, limit = 10): KnowledgeGap[] {\n const gaps: KnowledgeGap[] = []\n const isolated = graph.nodes.filter((node) => node.degree <= 1 && !isStructural(node.path))\n if (isolated.length > 0) {\n gaps.push({\n type: 'isolated-node',\n title: `${isolated.length} isolated page${isolated.length === 1 ? '' : 's'}`,\n nodeIds: isolated.map((node) => node.id),\n suggestion:\n 'Add cross-links, sources, or follow-up research to connect these pages to the knowledge graph.',\n })\n }\n for (const community of graph.communities) {\n if (community.nodeIds.length >= 3 && community.cohesion < 0.15) {\n gaps.push({\n type: 'sparse-community',\n title: `Sparse cluster: ${community.topTitles[0] ?? `community ${community.id}`}`,\n nodeIds: community.nodeIds,\n suggestion:\n 'This cluster has weak internal evidence. Add synthesis pages or relation links between its strongest concepts.',\n })\n }\n }\n const byCommunityNeighbors = new Map<string, Set<number>>()\n const nodeById = new Map(graph.nodes.map((node) => [node.id, node]))\n for (const edge of graph.edges) {\n const source = nodeById.get(edge.source)\n const target = nodeById.get(edge.target)\n if (!source || !target) continue\n if (!byCommunityNeighbors.has(source.id)) byCommunityNeighbors.set(source.id, new Set())\n if (!byCommunityNeighbors.has(target.id)) byCommunityNeighbors.set(target.id, new Set())\n byCommunityNeighbors.get(source.id)!.add(target.community)\n byCommunityNeighbors.get(target.id)!.add(source.community)\n }\n for (const node of graph.nodes) {\n if ((byCommunityNeighbors.get(node.id)?.size ?? 0) >= 3) {\n gaps.push({\n type: 'bridge-node',\n title: `Bridge page: ${node.title}`,\n nodeIds: [node.id],\n suggestion: 'This page connects multiple knowledge areas. Keep it well cited and current.',\n })\n }\n }\n return gaps.slice(0, limit)\n}\n\nexport function findSurprisingConnections(\n graph: KnowledgeVizGraph,\n limit = 10,\n): SurprisingConnection[] {\n const nodeById = new Map(graph.nodes.map((node) => [node.id, node]))\n const scored: SurprisingConnection[] = []\n for (const edge of graph.edges) {\n const source = nodeById.get(edge.source)\n const target = nodeById.get(edge.target)\n if (!source || !target) continue\n let score = edge.weight\n const reasons = [...edge.reasons]\n if (source.community !== target.community) {\n score += 3\n reasons.push('cross-community')\n }\n if (source.tags.some((tag) => !target.tags.includes(tag))) {\n score += 1\n reasons.push('cross-tag')\n }\n if (score >= 3) scored.push({ source, target, score, reasons })\n }\n return scored.sort((a, b) => b.score - a.score).slice(0, limit)\n}\n\nfunction buildAdjacency(graph: KnowledgeGraph): Map<string, Set<string>> {\n const out = new Map<string, Set<string>>()\n for (const node of graph.nodes) out.set(node.id, new Set())\n for (const edge of graph.edges) {\n out.get(edge.source)?.add(edge.target)\n out.get(edge.target)?.add(edge.source)\n }\n return out\n}\n\nfunction assignCommunities(\n nodes: KnowledgeGraphNode[],\n adjacency: Map<string, Set<string>>,\n): KnowledgeCommunity[] {\n const seen = new Set<string>()\n const communities: KnowledgeCommunity[] = []\n for (const node of nodes) {\n if (seen.has(node.id)) continue\n const queue = [node.id]\n const ids: string[] = []\n seen.add(node.id)\n while (queue.length > 0) {\n const id = queue.shift()!\n ids.push(id)\n for (const next of adjacency.get(id) ?? []) {\n if (!seen.has(next)) {\n seen.add(next)\n queue.push(next)\n }\n }\n }\n const memberNodes = ids\n .map((id) => nodes.find((candidate) => candidate.id === id))\n .filter((item): item is KnowledgeGraphNode => Boolean(item))\n communities.push({\n id: communities.length,\n nodeIds: ids,\n topTitles: memberNodes\n .sort((a, b) => b.inDegree + b.outDegree - (a.inDegree + a.outDegree))\n .slice(0, 5)\n .map((item) => item.title),\n cohesion: cohesion(ids, adjacency),\n })\n }\n return communities.sort((a, b) => b.nodeIds.length - a.nodeIds.length)\n}\n\nfunction cohesion(ids: string[], adjacency: Map<string, Set<string>>): number {\n if (ids.length < 2) return 0\n let edges = 0\n const idSet = new Set(ids)\n for (const id of ids) {\n for (const next of adjacency.get(id) ?? []) {\n if (idSet.has(next)) edges++\n }\n }\n return edges / (ids.length * (ids.length - 1))\n}\n\nfunction hashNode(id: string): number {\n let hash = 0\n for (const char of id) hash = (hash * 31 + char.charCodeAt(0)) | 0\n return hash\n}\n\nfunction isStructural(path: string): boolean {\n return path.endsWith('/index.md') || path.endsWith('/log.md')\n}\n"],"mappings":";AAsCA,SAAgB,oBAAoB,OAA0C;CAC5E,MAAM,YAAY,eAAe,KAAK;CACtC,MAAM,cAAc,kBAAkB,MAAM,OAAO,SAAS;CAC5D,MAAM,kCAAkB,IAAI,IAAoB;CAChD,YAAY,SAAS,cAAc;EACjC,KAAK,MAAM,UAAU,UAAU,SAAS,gBAAgB,IAAI,SAAS,MAAM,GAAG,UAAU,EAAE;CAC5F,CAAC;CAMD,OAAO;EACL,OANY,MAAM,MAAM,KAAK,UAAU;GACvC,GAAG;GACH,QAAQ,KAAK,WAAW,KAAK;GAC7B,WAAW,gBAAgB,IAAI,SAAS,KAAK,EAAE,CAAC,KAAK;EACvD,EAEM;EACJ,OAAO,MAAM,MAAM,KAAK,UAAU;GAAE,GAAG;GAAM,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK;EAAS,EAAE;EACpF;CACF;AACF;AAEA,SAAgB,oBAAoB,OAA0B,QAAQ,IAAoB;CACxF,MAAM,OAAuB,CAAC;CAC9B,MAAM,WAAW,MAAM,MAAM,QAAQ,SAAS,KAAK,UAAU,KAAK,CAAC,aAAa,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ACT;AAEA,SAAS,aAAa,MAAuB;CAC3C,OAAO,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,SAAS;AAC9D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-knowledge",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Build, search, evaluate, and improve source-backed knowledge bases.",
|
|
5
5
|
"homepage": "https://github.com/tangle-network/agent-knowledge#readme",
|
|
6
6
|
"repository": {
|
|
@@ -60,36 +60,47 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"dev": "
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"dev": "tsdown --watch",
|
|
65
65
|
"prepublishOnly": "pnpm build",
|
|
66
66
|
"test": "vitest run",
|
|
67
67
|
"test:watch": "vitest",
|
|
68
|
-
"typecheck": "
|
|
68
|
+
"typecheck": "pnpm run typecheck:src && pnpm run typecheck:contracts",
|
|
69
|
+
"typecheck:src": "tsc --noEmit",
|
|
70
|
+
"typecheck:contracts": "tsc --noEmit -p tsconfig.contracts.json",
|
|
69
71
|
"lint": "biome check src tests",
|
|
70
72
|
"format": "biome format --write src tests",
|
|
71
73
|
"check:skills": "node scripts/check-skills.mjs",
|
|
72
|
-
"verify:package": "pnpm run check:skills && node scripts/verify-package.mjs",
|
|
74
|
+
"verify:package": "pnpm run check:skills && publint && attw --pack --profile esm-only . && node scripts/verify-package.mjs",
|
|
73
75
|
"verify:official-optimizers": "node scripts/verify-official-optimizers.mjs"
|
|
74
76
|
},
|
|
75
77
|
"dependencies": {
|
|
76
|
-
"@tangle-network/agent-eval": "0.
|
|
77
|
-
"@tangle-network/agent-interface": "0.
|
|
78
|
+
"@tangle-network/agent-eval": "0.130.1",
|
|
79
|
+
"@tangle-network/agent-interface": "0.35.0",
|
|
78
80
|
"proper-lockfile": "4.1.2",
|
|
79
81
|
"zod": "^4.4.3"
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
84
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
82
85
|
"@biomejs/biome": "^2.5.5",
|
|
83
86
|
"@neo4j-labs/agent-memory": "0.4.1",
|
|
84
87
|
"@types/node": "^26.1.1",
|
|
85
88
|
"@types/proper-lockfile": "4.1.4",
|
|
86
|
-
"mem0ai": "3.1.
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
+
"mem0ai": "3.1.2",
|
|
90
|
+
"publint": "^0.3.22",
|
|
91
|
+
"tsdown": "^0.22.14",
|
|
92
|
+
"typescript": "^7.0.2",
|
|
89
93
|
"vite": "8.1.5",
|
|
90
94
|
"vitest": "^4.1.10"
|
|
91
95
|
},
|
|
92
96
|
"pnpm": {
|
|
97
|
+
"ignoredBuiltDependencies": [
|
|
98
|
+
"@ax-llm/ax",
|
|
99
|
+
"esbuild"
|
|
100
|
+
],
|
|
101
|
+
"onlyBuiltDependencies": [
|
|
102
|
+
"better-sqlite3"
|
|
103
|
+
],
|
|
93
104
|
"minimumReleaseAge": 4320,
|
|
94
105
|
"minimumReleaseAgeExclude": [
|
|
95
106
|
"@tangle-network/agent-eval",
|
|
@@ -98,7 +109,7 @@
|
|
|
98
109
|
"vite"
|
|
99
110
|
],
|
|
100
111
|
"overrides": {
|
|
101
|
-
"@hono/node-server": "2.0.
|
|
112
|
+
"@hono/node-server": "2.0.12",
|
|
102
113
|
"esbuild": "0.28.1",
|
|
103
114
|
"hono": "4.12.32",
|
|
104
115
|
"vite": "8.1.5",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|