agentix-cli 0.119.0 → 0.121.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/dist/{App-XMSNIAU6.js → App-AMIGKAXO.js} +2 -2
- package/dist/{ChatApp-BFYTIQF3.js → ChatApp-WMI4HQSY.js} +2 -2
- package/dist/{agent-E6W5VBYH.js → agent-TQQOAVMU.js} +2 -2
- package/dist/article-sync-TLZTHRZB.js +2 -0
- package/dist/article-sync-TLZTHRZB.js.map +1 -0
- package/dist/{board-dashboard-WDO6Z24C.js → board-dashboard-FNMZAP7A.js} +4 -4
- package/dist/{chunk-B6OXEIOF.js → chunk-25XR6QK2.js} +2 -2
- package/dist/{chunk-4PQREYBU.js → chunk-2IMK3NGJ.js} +2 -2
- package/dist/{chunk-PVQPXZHE.js → chunk-2NGXOYTS.js} +67 -67
- package/dist/chunk-2NGXOYTS.js.map +1 -0
- package/dist/{chunk-6PC4EZ4P.js → chunk-43CLFC4B.js} +2 -2
- package/dist/{chunk-NDPU6AX2.js → chunk-4GDLXWCH.js} +2 -2
- package/dist/chunk-56KNKUFF.js +3 -0
- package/dist/chunk-56KNKUFF.js.map +1 -0
- package/dist/chunk-6FVFD5WU.js +4 -0
- package/dist/chunk-6FVFD5WU.js.map +1 -0
- package/dist/{chunk-2G227TF3.js → chunk-6TUQHOO3.js} +2 -2
- package/dist/{chunk-RJBRYUKU.js → chunk-7KY7EEEI.js} +2 -2
- package/dist/{chunk-TJ7IUHC7.js → chunk-7ZABMMSW.js} +2 -2
- package/dist/{chunk-IOYRRGK7.js → chunk-BLEW5WQL.js} +2 -2
- package/dist/{chunk-5PR6DZYW.js → chunk-BWHHZJNJ.js} +3 -3
- package/dist/chunk-BWHHZJNJ.js.map +1 -0
- package/dist/{chunk-ZDWE47LM.js → chunk-CAS2IWSM.js} +2 -2
- package/dist/chunk-DJQMG6TH.js +4 -0
- package/dist/chunk-DJQMG6TH.js.map +1 -0
- package/dist/{chunk-U46G24CD.js → chunk-EI7D5V2L.js} +2 -2
- package/dist/{chunk-FTZCNID3.js → chunk-ELUEF4NC.js} +2 -2
- package/dist/{chunk-FSXWNVGL.js → chunk-H5Z42X7W.js} +2 -2
- package/dist/{chunk-JMFP35EU.js → chunk-I4IDZSGF.js} +180 -180
- package/dist/{chunk-JMFP35EU.js.map → chunk-I4IDZSGF.js.map} +1 -1
- package/dist/{chunk-HK7TU5NX.js → chunk-IKBWV7YJ.js} +2 -2
- package/dist/{chunk-5UFIHT66.js → chunk-MORRCYJE.js} +9 -9
- package/dist/chunk-MORRCYJE.js.map +1 -0
- package/dist/{chunk-IMLLHT7U.js → chunk-OPNZWQ6Y.js} +9 -9
- package/dist/{chunk-IMLLHT7U.js.map → chunk-OPNZWQ6Y.js.map} +1 -1
- package/dist/{chunk-NG677JHW.js → chunk-PAWCJIPZ.js} +2 -2
- package/dist/{chunk-GJKYOEDE.js → chunk-RMA7KKR7.js} +2 -2
- package/dist/{chunk-IVCFXLAR.js → chunk-Y4PR5LR3.js} +5 -5
- package/dist/chunk-Y4PR5LR3.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/{client-TSYZXEH7.js → client-ICDRAZBU.js} +2 -2
- package/dist/{config-QAE3LNFQ.js → config-K4UYPR7W.js} +2 -2
- package/dist/config-mutator-IGA6D4S5.js +2 -0
- package/dist/{doctor-PVLVKLRA.js → doctor-LRTOOCM6.js} +2 -2
- package/dist/{grants-V2ZNLWSJ.js → grants-ZMHSJMYE.js} +2 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +1 -1
- package/dist/{program-SOKOBCYN.js → program-OKPC77BN.js} +240 -229
- package/dist/program-OKPC77BN.js.map +1 -0
- package/dist/{promote-IRBBEXGG.js → promote-4LW53AMH.js} +2 -2
- package/dist/{query-NAU7J34H.js → query-4OPS5PET.js} +2 -2
- package/dist/{registry-I5PXGCO6.js → registry-YHSHGJ4K.js} +2 -2
- package/dist/{request-planner-CRG3OGGG.js → request-planner-GDXSBNN4.js} +2 -2
- package/dist/{review-candidates-HAP7P6SH.js → review-candidates-TUVDG2LR.js} +2 -2
- package/dist/{rotation-memo-5MTSJ4FH.js → rotation-memo-6UW6DTBQ.js} +2 -2
- package/dist/{rotation-memo-5MTSJ4FH.js.map → rotation-memo-6UW6DTBQ.js.map} +1 -1
- package/dist/{routing-G33LLOTF.js → routing-OKDZ4VYH.js} +2 -2
- package/dist/schedule-tool-MJLXMXN5.js +2 -0
- package/dist/scheduler-E5SASFAH.js +2 -0
- package/dist/{seat-IJN7NETF.js → seat-K6FNHYMY.js} +2 -2
- package/dist/{select-D7AZ2XZF.js → select-QMJXHNUP.js} +2 -2
- package/dist/{set-enabled-5YSDIQXU.js → set-enabled-I77LPL6Q.js} +2 -2
- package/dist/{tool-XADSW6NL.js → tool-BQUKONSF.js} +2 -2
- package/dist/{tool-GQIQWHWB.js → tool-QTGNWXUA.js} +2 -2
- package/dist/wiki-F6EZBBUH.js +2 -0
- package/package.json +1 -1
- package/dist/chunk-23SQSUBI.js +0 -3
- package/dist/chunk-23SQSUBI.js.map +0 -1
- package/dist/chunk-2GIDVZ4H.js +0 -3
- package/dist/chunk-2GIDVZ4H.js.map +0 -1
- package/dist/chunk-5PR6DZYW.js.map +0 -1
- package/dist/chunk-5UFIHT66.js.map +0 -1
- package/dist/chunk-BDJWN3PL.js +0 -4
- package/dist/chunk-BDJWN3PL.js.map +0 -1
- package/dist/chunk-IVCFXLAR.js.map +0 -1
- package/dist/chunk-PVQPXZHE.js.map +0 -1
- package/dist/config-mutator-WRQ7MFQL.js +0 -2
- package/dist/program-SOKOBCYN.js.map +0 -1
- package/dist/schedule-tool-IP7ZCQKI.js +0 -2
- package/dist/scheduler-QXLPYSNJ.js +0 -2
- package/dist/wiki-PPX3HYXW.js +0 -2
- /package/dist/{App-XMSNIAU6.js.map → App-AMIGKAXO.js.map} +0 -0
- /package/dist/{ChatApp-BFYTIQF3.js.map → ChatApp-WMI4HQSY.js.map} +0 -0
- /package/dist/{agent-E6W5VBYH.js.map → agent-TQQOAVMU.js.map} +0 -0
- /package/dist/{board-dashboard-WDO6Z24C.js.map → board-dashboard-FNMZAP7A.js.map} +0 -0
- /package/dist/{chunk-B6OXEIOF.js.map → chunk-25XR6QK2.js.map} +0 -0
- /package/dist/{chunk-4PQREYBU.js.map → chunk-2IMK3NGJ.js.map} +0 -0
- /package/dist/{chunk-6PC4EZ4P.js.map → chunk-43CLFC4B.js.map} +0 -0
- /package/dist/{chunk-NDPU6AX2.js.map → chunk-4GDLXWCH.js.map} +0 -0
- /package/dist/{chunk-2G227TF3.js.map → chunk-6TUQHOO3.js.map} +0 -0
- /package/dist/{chunk-RJBRYUKU.js.map → chunk-7KY7EEEI.js.map} +0 -0
- /package/dist/{chunk-TJ7IUHC7.js.map → chunk-7ZABMMSW.js.map} +0 -0
- /package/dist/{chunk-IOYRRGK7.js.map → chunk-BLEW5WQL.js.map} +0 -0
- /package/dist/{chunk-ZDWE47LM.js.map → chunk-CAS2IWSM.js.map} +0 -0
- /package/dist/{chunk-U46G24CD.js.map → chunk-EI7D5V2L.js.map} +0 -0
- /package/dist/{chunk-FTZCNID3.js.map → chunk-ELUEF4NC.js.map} +0 -0
- /package/dist/{chunk-FSXWNVGL.js.map → chunk-H5Z42X7W.js.map} +0 -0
- /package/dist/{chunk-HK7TU5NX.js.map → chunk-IKBWV7YJ.js.map} +0 -0
- /package/dist/{chunk-NG677JHW.js.map → chunk-PAWCJIPZ.js.map} +0 -0
- /package/dist/{chunk-GJKYOEDE.js.map → chunk-RMA7KKR7.js.map} +0 -0
- /package/dist/{client-TSYZXEH7.js.map → client-ICDRAZBU.js.map} +0 -0
- /package/dist/{config-QAE3LNFQ.js.map → config-K4UYPR7W.js.map} +0 -0
- /package/dist/{config-mutator-WRQ7MFQL.js.map → config-mutator-IGA6D4S5.js.map} +0 -0
- /package/dist/{doctor-PVLVKLRA.js.map → doctor-LRTOOCM6.js.map} +0 -0
- /package/dist/{grants-V2ZNLWSJ.js.map → grants-ZMHSJMYE.js.map} +0 -0
- /package/dist/{promote-IRBBEXGG.js.map → promote-4LW53AMH.js.map} +0 -0
- /package/dist/{query-NAU7J34H.js.map → query-4OPS5PET.js.map} +0 -0
- /package/dist/{registry-I5PXGCO6.js.map → registry-YHSHGJ4K.js.map} +0 -0
- /package/dist/{request-planner-CRG3OGGG.js.map → request-planner-GDXSBNN4.js.map} +0 -0
- /package/dist/{review-candidates-HAP7P6SH.js.map → review-candidates-TUVDG2LR.js.map} +0 -0
- /package/dist/{routing-G33LLOTF.js.map → routing-OKDZ4VYH.js.map} +0 -0
- /package/dist/{schedule-tool-IP7ZCQKI.js.map → schedule-tool-MJLXMXN5.js.map} +0 -0
- /package/dist/{scheduler-QXLPYSNJ.js.map → scheduler-E5SASFAH.js.map} +0 -0
- /package/dist/{seat-IJN7NETF.js.map → seat-K6FNHYMY.js.map} +0 -0
- /package/dist/{select-D7AZ2XZF.js.map → select-QMJXHNUP.js.map} +0 -0
- /package/dist/{set-enabled-5YSDIQXU.js.map → set-enabled-I77LPL6Q.js.map} +0 -0
- /package/dist/{tool-XADSW6NL.js.map → tool-BQUKONSF.js.map} +0 -0
- /package/dist/{tool-GQIQWHWB.js.map → tool-QTGNWXUA.js.map} +0 -0
- /package/dist/{wiki-PPX3HYXW.js.map → wiki-F6EZBBUH.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/wiki/query.ts"],"sourcesContent":["import { readFileSync, existsSync } from \"fs\"\nimport { buildIndex, scoreAll } from \"@/memory/bm25\"\nimport { askSeat } from \"@/decisions/seat\"\nimport { ancestryScore } from \"@/graph\"\nimport {\n DEFAULT_SHORTLIST,\n WIKI_RERANK_SEAT,\n rerankQuestions,\n rerankState,\n toRanking,\n type RerankCandidate,\n} from \"@/decisions/seats/wiki-rerank\"\nimport { stripAnthropicApiKey } from \"@/utils/workspace-env\"\nimport { resolve } from \"path\"\nimport { execSync } from \"child_process\"\nimport type { WikiArticle } from \"./types\"\nimport type { WikiStore } from \"./store\"\n\n/**\n * Agentic wiki query — the \"Farzapedia-faithful\" retrieval path.\n *\n * Two LLM calls + a deterministic graph walk:\n * 1. Selector (cheap): read `_index.md` + question → pick up to `maxCandidates`\n * candidate articles by title + type.\n * 2. Walk (pure code): starting from candidates, follow `related` wikilinks\n * up to `maxHops`, capped at `maxArticles` total.\n * 3. Synthesis (main): answer the question from the walked subgraph.\n *\n * Returns an answer with citations and a trace of which articles were walked,\n * so callers can audit the retrieval path.\n */\n\nexport interface AgenticQueryOptions {\n /** Candidate-selection model (cheap). Defaults to \"haiku\". */\n selectorModel?: string\n /** Synthesis model (main). Defaults to \"sonnet\". */\n synthModel?: string\n /** Number of candidates the selector is asked to return. Default 3. */\n maxCandidates?: number\n /** Wikilink hops from candidates. Default 2. */\n maxHops?: number\n /** Hard cap on total articles walked. Default 8. */\n maxArticles?: number\n /** Timeout per LLM call, ms. Default 60_000. */\n timeoutMs?: number\n /** Logger — defaults to console.error. */\n log?: (...args: unknown[]) => void\n /** Intent-graph path the question's request was classified under.\n * Articles on the same branch rank higher in candidate selection. */\n messagePath?: string[]\n /** Weight of the branch match against the text match, 0–1. Default 0.6\n * (`graph.retrievalWeights.graph`). */\n graphWeight?: number\n}\n\nexport interface AgenticQueryResult {\n answer: string\n citations: Array<{ title: string; path: string; type?: string }>\n /** Titles/paths the selector picked. */\n candidates: Array<{ title: string; path: string }>\n /** Full article subgraph the walk produced. */\n walked: Array<{ title: string; path: string; type?: string; hop: number }>\n /** \"no-catalog\" | \"no-candidates\" | \"ok\" */\n status: \"ok\" | \"no-catalog\" | \"no-candidates\" | \"error\"\n /** For operator debugging only. */\n trace?: {\n selectorMs: number\n synthesisMs: number\n selectorOutput?: string\n }\n error?: string\n}\n\n/**\n * Run an agentic query against a specific agent's WikiStore.\n *\n * `requesterId` is used for permission checks — only articles the requester\n * can read will be included in the synthesis input.\n */\nexport async function agenticQuery(\n question: string,\n store: WikiStore,\n requesterId: string | undefined,\n opts: AgenticQueryOptions = {},\n): Promise<AgenticQueryResult> {\n const selectorModel = opts.selectorModel ?? \"haiku\"\n const synthModel = opts.synthModel ?? \"sonnet\"\n const maxCandidates = opts.maxCandidates ?? 3\n const maxHops = opts.maxHops ?? 2\n const maxArticles = opts.maxArticles ?? 8\n const timeoutMs = opts.timeoutMs ?? 60_000\n const log = opts.log ?? console.error.bind(console, \"[wiki-query]\")\n const messagePath = opts.messagePath?.length ? opts.messagePath : undefined\n const graphWeight = opts.graphWeight ?? DEFAULT_GRAPH_WEIGHT\n\n // --- Step 1: Load the catalog ---\n const catalogPath = resolve(store.baseDir, \"_index.md\")\n if (!existsSync(catalogPath)) {\n return emptyResult(\"no-catalog\", question, \"No _index.md found — run `agentx wiki status` to rebuild.\")\n }\n const catalog = readFileSync(catalogPath, \"utf-8\")\n\n // --- Step 2: Selector — pick candidates ---\n const selectorStart = Date.now()\n let candidates: Array<{ title: string; path: string }> = []\n let selectorOutput = \"\"\n try {\n const viaSeat = await selectCandidatesViaSeat(question, store, requesterId, maxCandidates, messagePath, graphWeight)\n if (viaSeat) {\n candidates = viaSeat\n selectorOutput = `[wiki-rerank seat] ${viaSeat.map((c) => c.title).join(\" | \")}`\n } else {\n selectorOutput = await runClaude(\n buildSelectorPrompt(question, catalog, maxCandidates, messagePath),\n selectorModel,\n timeoutMs,\n )\n candidates = parseCandidates(selectorOutput)\n }\n } catch (e: any) {\n log(\"selector failed:\", e?.message)\n return { ...emptyResult(\"error\", question, `Selector: ${e?.message || \"unknown\"}`), trace: { selectorMs: Date.now() - selectorStart, synthesisMs: 0, selectorOutput } }\n }\n const selectorMs = Date.now() - selectorStart\n\n if (candidates.length === 0) {\n return { ...emptyResult(\"no-candidates\", question, \"Selector returned no candidates.\"), trace: { selectorMs, synthesisMs: 0, selectorOutput } }\n }\n\n // --- Step 3: Walk the subgraph via `related` wikilinks ---\n const walked = walkSubgraph(candidates, store, requesterId, maxHops, maxArticles)\n\n if (walked.length === 0) {\n return { ...emptyResult(\"no-candidates\", question, \"Candidates did not resolve to readable articles.\"), candidates, trace: { selectorMs, synthesisMs: 0, selectorOutput } }\n }\n\n // --- Step 4: Synthesize the answer ---\n const synthStart = Date.now()\n let answer = \"\"\n try {\n answer = await runClaude(\n buildSynthesisPrompt(question, walked),\n synthModel,\n timeoutMs * 2,\n )\n } catch (e: any) {\n log(\"synthesis failed:\", e?.message)\n return { ...emptyResult(\"error\", question, `Synthesis: ${e?.message || \"unknown\"}`), candidates, walked: walked.map(w => ({ title: w.meta.title, path: w.path, type: w.meta.type, hop: (w as any).hop ?? 0 })), trace: { selectorMs, synthesisMs: Date.now() - synthStart, selectorOutput } }\n }\n const synthesisMs = Date.now() - synthStart\n\n return {\n answer: answer.trim(),\n citations: walked.map(a => ({ title: a.meta.title, path: a.path, type: a.meta.type })),\n candidates,\n walked: walked.map(w => ({ title: w.meta.title, path: w.path, type: w.meta.type, hop: (w as any).hop ?? 0 })),\n status: \"ok\",\n trace: { selectorMs, synthesisMs, selectorOutput },\n }\n}\n\n// --- Helpers ---\n\nfunction emptyResult(\n status: AgenticQueryResult[\"status\"],\n _question: string,\n error?: string,\n): AgenticQueryResult {\n return {\n answer: \"\",\n citations: [],\n candidates: [],\n walked: [],\n status,\n error,\n }\n}\n\nfunction walkSubgraph(\n candidates: Array<{ title: string; path: string }>,\n store: WikiStore,\n requesterId: string | undefined,\n maxHops: number,\n maxArticles: number,\n): Array<WikiArticle & { hop: number }> {\n // Build a title → path index from the store so wikilinks resolve.\n const titleIndex = new Map<string, string>()\n for (const article of store.listArticles(requesterId || \"\")) {\n titleIndex.set(article.meta.title.toLowerCase(), article.path)\n }\n\n const opened = new Map<string, WikiArticle & { hop: number }>()\n let frontier: Array<{ path: string; hop: number }> = []\n\n for (const c of candidates) {\n if (!opened.has(c.path)) frontier.push({ path: c.path, hop: 0 })\n }\n\n while (frontier.length && opened.size < maxArticles) {\n const next = frontier.shift()!\n if (opened.has(next.path)) continue\n if (next.hop > maxHops) continue\n\n const article = requesterId\n ? store.readArticleAs(next.path, requesterId)\n : store.readArticle(next.path)\n if (!article) continue\n\n opened.set(next.path, { ...article, hop: next.hop })\n if (next.hop >= maxHops) continue\n\n for (const target of article.meta.related || []) {\n const path = titleIndex.get(target.toLowerCase())\n if (path && !opened.has(path)) {\n frontier.push({ path, hop: next.hop + 1 })\n }\n }\n }\n\n return Array.from(opened.values())\n}\n\n// --- Prompts ---\n\n/**\n * Pick candidates with the wiki-rerank seat instead of a Claude CLI call.\n *\n * The selector is 56% of a wiki query — 14.1s of a 25s total, measured —\n * and its whole job is \"pick 3 articles from this catalog\", which is a\n * Choice with per-option probabilities. Jev answers that in about a\n * second. Synthesis stays on Sonnet; it writes prose, which Jev cannot.\n *\n * BM25 shortlists first because the shared catalog carries 971 entries,\n * past the 255-option cap. Same two-stage shape as findRelevantReranked,\n * and it reuses that seat rather than introducing a second one.\n *\n * Returns null whenever the seat is off, errors, or has nothing to rank,\n * and the caller falls back to the CLI selector — so this is strictly an\n * accelerator, never a new way to fail.\n */\nasync function selectCandidatesViaSeat(\n question: string,\n store: WikiStore,\n requesterId: string | undefined,\n maxCandidates: number,\n messagePath?: string[],\n graphWeight: number = DEFAULT_GRAPH_WEIGHT,\n): Promise<Array<{ title: string; path: string }> | null> {\n try {\n const index = store.rebuildIndex()\n const pool = (index.articles ?? []).filter((a) => a.path && !a.path.includes(\"/_versions/\"))\n if (pool.length < 2) return null\n\n const shortlist = rankCatalogPool(question, pool, messagePath, graphWeight).slice(0, DEFAULT_SHORTLIST)\n\n const candidates: RerankCandidate[] = shortlist.map((i) => ({\n id: `k${i}`,\n title: pool[i].title || pool[i].path,\n tags: pool[i].tags,\n // The catalog has no body — a title, its type, its wikilinks and its\n // branch of the intent graph are what the selector chooses on.\n excerpt: [\n pool[i].type ? `type: ${pool[i].type}` : \"\",\n (pool[i].related ?? []).length ? `related: ${(pool[i].related ?? []).join(\", \")}` : \"\",\n (pool[i].graphPath ?? []).length ? `graph: ${(pool[i].graphPath ?? []).join(\" › \")}` : \"\",\n ].filter(Boolean).join(\" · \"),\n }))\n\n const result = await askSeat(\n WIKI_RERANK_SEAT,\n rerankState({ query: question, candidates, excerptChars: 300 }),\n rerankQuestions(candidates),\n { features: { agent: requesterId ?? \"unknown\", stage: \"catalog-selector\" } },\n )\n if (!result || result.mode !== \"active\") return null\n\n const ranking = toRanking(result.answers as never, candidates)\n const picked = ranking.ranked\n .slice(0, maxCandidates)\n .map((id) => pool[Number(id.slice(1))])\n .filter(Boolean)\n .map((a) => ({ title: a.title, path: a.path }))\n return picked.length > 0 ? picked : null\n } catch {\n return null\n }\n}\n\n/** Weight of the intent-graph branch match against the text match when\n * shortlisting catalog candidates. Mirrors `graph.retrievalWeights.graph`. */\nexport const DEFAULT_GRAPH_WEIGHT = 0.6\n\n/**\n * Order the catalog pool for a question. Three bands, never mixed:\n *\n * 1. articles the text match scored, ordered by `text * (1 + w * branch)`\n * when the request was classified: the branch reorders text matches\n * but cannot lift an unrelated article above one;\n * 2. articles on the request's branch that the text never matched, by\n * how much of the path they share;\n * 3. the rest, in catalog order.\n *\n * Band 1 comes first in full because the shortlist the reranker sees is\n * finite (DEFAULT_SHORTLIST): a busy category holds more same-branch\n * articles than that, and a blended score let them push the article that\n * actually answers the question out of the list.\n *\n * Exported for tests; the seat and the CLI selector both consume the order.\n */\nexport function rankCatalogPool(\n question: string,\n pool: Array<{ title: string; tags?: string[]; related?: string[]; graphPath?: string[] }>,\n messagePath?: string[],\n graphWeight: number = DEFAULT_GRAPH_WEIGHT,\n): number[] {\n const docs = pool.map((a) =>\n [a.title, (a.tags ?? []).join(\" \"), (a.related ?? []).join(\" \")].join(\" \"),\n )\n const bm25 = scoreAll(question, buildIndex(docs))\n const maxBm25 = bm25.reduce((m, r) => Math.max(m, r.score), 0)\n const text = new Map(bm25.map((r) => [r.docIndex, maxBm25 > 0 ? r.score / maxBm25 : 0]))\n const useGraph = !!messagePath?.length\n const branch = (a: { graphPath?: string[] }) =>\n useGraph && a.graphPath?.length ? ancestryScore(messagePath!, a.graphPath) : 0\n\n const byScore = (x: { i: number; score: number }, y: { i: number; score: number }) => y.score - x.score || x.i - y.i\n const matched = pool\n .map((a, i) => ({ i, score: (text.get(i) ?? 0) * (1 + graphWeight * branch(a)) }))\n .filter((c) => text.has(c.i))\n .sort(byScore)\n const branchOnly = pool\n .map((a, i) => ({ i, score: branch(a) }))\n .filter((c) => !text.has(c.i) && c.score > 0)\n .sort(byScore)\n const ranked = [...matched, ...branchOnly].map((c) => c.i)\n for (let i = 0; i < pool.length; i++) if (!ranked.includes(i)) ranked.push(i)\n return ranked\n}\n\nfunction buildSelectorPrompt(question: string, catalog: string, maxCandidates: number, messagePath?: string[]): string {\n const branch = messagePath?.length\n ? `\\n## Intent\\n\\nThe request was classified under the intent-graph path \"${messagePath.join(\" › \")}\". Prefer articles filed under the same branch when their titles are equally plausible.\\n`\n : \"\"\n return `You are picking candidate articles from a wiki catalog to answer a question. You do NOT answer the question. You pick which articles the answer is likely to come from.\n\n## Question\n\n${question}\n${branch}\n## Catalog (_index.md — articles grouped by type, with wikilink previews)\n\n${catalog}\n\n## Your task\n\nPick up to ${maxCandidates} articles from the catalog that are most likely to answer the question. Prefer:\n- Articles whose title directly names a subject in the question.\n- Articles of the right type (e.g. a \"who owns X\" question → person or project; a \"what happened on DATE\" → event).\n- Articles whose wikilinks suggest they sit at the center of a relevant subgraph.\n\nReturn ONLY valid JSON, no markdown fencing, no prose:\n\n[\n {\"title\": \"Exact Article Title\", \"path\": \"path/from/catalog.md\"},\n ...\n]\n\nIf none of the articles match, return [].`\n}\n\nfunction buildSynthesisPrompt(\n question: string,\n articles: Array<WikiArticle & { hop: number }>,\n): string {\n const articlesBlock = articles\n .map(a => {\n const header = `### ${a.meta.title} — ${a.meta.type || \"untyped\"} (${a.path}) [hop ${a.hop}]`\n const related = a.meta.related?.length ? `Related: ${a.meta.related.join(\", \")}` : \"\"\n return [header, related, \"\", a.content].filter(Boolean).join(\"\\n\")\n })\n .join(\"\\n\\n---\\n\\n\")\n\n return `You are answering a question using a small subgraph of wiki articles. The articles were walked from the catalog; trust them over your prior knowledge.\n\n## Question\n\n${question}\n\n## Articles (${articles.length} walked from the catalog)\n\n${articlesBlock}\n\n## Your task\n\nAnswer the question in 2–6 sentences. Cite articles by their title in square brackets like [Article Title]. If the articles do not answer the question, say so plainly (do not invent). Prefer concrete facts over hedging.\n\nOutput ONLY the answer — no preamble, no \"here is my answer:\", no markdown fencing.`\n}\n\nfunction parseCandidates(raw: string): Array<{ title: string; path: string }> {\n const match = raw.match(/\\[[\\s\\S]*?\\]/)\n if (!match) return []\n try {\n const parsed = JSON.parse(match[0])\n if (!Array.isArray(parsed)) return []\n return parsed\n .filter((x: any) => x && typeof x.title === \"string\" && typeof x.path === \"string\")\n .map((x: any) => ({ title: x.title, path: x.path }))\n } catch {\n return []\n }\n}\n\nasync function runClaude(prompt: string, model: string, timeoutMs: number): Promise<string> {\n // Use stdin via a temp-file pipe to avoid shell-escaping a huge prompt.\n // Prompts can exceed the `-E` arg buffer on macOS, so we always pipe.\n const { writeFileSync, mkdirSync, rmSync } = await import(\"fs\")\n const { tmpdir } = await import(\"os\")\n const dir = resolve(tmpdir(), `agentx-wiki-query-${process.pid}`)\n mkdirSync(dir, { recursive: true })\n const promptPath = resolve(dir, `prompt-${Date.now()}.txt`)\n writeFileSync(promptPath, prompt)\n try {\n const cmd = `cat '${promptPath}' | claude -p - --output-format json --max-turns 1 --model ${model} --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`\n const raw = execSync(cmd, { env: stripAnthropicApiKey({ ...process.env }), encoding: \"utf-8\", timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024 })\n try {\n const envelope = JSON.parse(raw)\n return String(envelope.result || envelope.content || \"\")\n } catch {\n return raw\n }\n } finally {\n try { rmSync(promptPath, { force: true }) } catch {}\n }\n}\n"],"mappings":"iNAAA,OAAS,gBAAAA,EAAc,cAAAC,MAAkB,KAEzCC,IAWA,OA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M,EAClBA,EACJ,OAAQZ,GAAWA,GAAK,OAAOA,EAAE,OAAU,UAAY,OAAOA,EAAE,MAAS,QAAQ,EACjF,IAAKA,IAAY,CAAE,MAAOA,EAAE,MAAO,KAAMA,EAAE,IAAK,EAAE,EAHlB,CAAC,CAItC,MAAE,CACA,MAAO,CAAC,CACV,CACF,CAEA,eAAe9C,EAAU2D,EAAgBC,EAAe5E,EAAoC,CAG1F,GAAM,CAAE,cAAA6E,EAAe,UAAAC,EAAW,OAAAC,CAAO,EAAI,KAAM,QAAO,IAAI,EACxD,CAAE,OAAAC,CAAO,EAAI,KAAM,QAAO,IAAI,EAC9BC,EAAM7F,EAAQ4F,EAAO,EAAG,qBAAqB,QAAQ,KAAK,EAChEF,EAAUG,EAAK,CAAE,UAAW,EAAK,CAAC,EAClC,IAAMC,EAAa9F,EAAQ6F,EAAK,UAAU,KAAK,IAAI,OAAO,EAC1DJ,EAAcK,EAAYP,CAAM,EAChC,GAAI,CACF,IAAMQ,EAAM,QAAQD,+DAAwEN,6FACtFJ,EAAMnF,EAAS8F,EAAK,CAAE,IAAKC,EAAqB,CAAE,GAAG,QAAQ,GAAI,CAAC,EAAG,SAAU,QAAS,QAASpF,EAAW,UAAW,EAAI,KAAO,IAAK,CAAC,EAC9I,GAAI,CACF,IAAMqF,EAAW,KAAK,MAAMb,CAAG,EAC/B,OAAO,OAAOa,EAAS,QAAUA,EAAS,SAAW,EAAE,CACzD,MAAE,CACA,OAAOb,CACT,CACF,QAAE,CACA,GAAI,CAAEO,EAAOG,EAAY,CAAE,MAAO,EAAK,CAAC,CAAE,MAAE,CAAO,CACrD,CACF","names":["readFileSync","existsSync","init_seat","resolve","execSync","agenticQuery","question","store","requesterId","opts","selectorModel","synthModel","maxCandidates","maxHops","maxArticles","timeoutMs","log","messagePath","graphWeight","DEFAULT_GRAPH_WEIGHT","catalogPath","existsSync","emptyResult","catalog","readFileSync","selectorStart","candidates","selectorOutput","viaSeat","selectCandidatesViaSeat","c","runClaude","buildSelectorPrompt","parseCandidates","e","selectorMs","walked","walkSubgraph","synthStart","answer","buildSynthesisPrompt","w","synthesisMs","a","status","_question","error","titleIndex","article","opened","frontier","next","target","path","pool","rankCatalogPool","DEFAULT_SHORTLIST","result","askSeat","WIKI_RERANK_SEAT","rerankState","rerankQuestions","picked","toRanking","id","docs","bm25","scoreAll","buildIndex","maxBm25","m","r","text","useGraph","branch","ancestryScore","byScore","x","y","matched","i","branchOnly","ranked","articles","articlesBlock","header","related","raw","match","parsed","prompt","model","writeFileSync","mkdirSync","rmSync","tmpdir","dir","promptPath","cmd","stripAnthropicApiKey","envelope"]}
|