@vpxa/kb 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpxa/kb",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents",
6
6
  "license": "MIT",
@@ -1 +1 @@
1
- import{pipeline as m}from"@huggingface/transformers";import{EMBEDDING_DEFAULTS as l}from"../../core/dist/index.js";class h{pipe=null;dimensions;modelId;queryPrefix;constructor(e){this.modelId=e?.model??l.model,this.dimensions=e?.dimensions??l.dimensions,this.queryPrefix=e?.queryPrefix??this.detectQueryPrefix(this.modelId)}detectQueryPrefix(e){const i=e.toLowerCase();return i.includes("bge")||i.includes("mxbai-embed")?"Represent this sentence for searching relevant passages: ":i.includes("/e5-")||i.includes("multilingual-e5")?"query: ":""}async initialize(){if(!this.pipe)try{this.pipe=await m("feature-extraction",this.modelId,{dtype:"fp32"})}catch(e){throw new Error(`Failed to initialize embedding model "${this.modelId}": ${e.message}`)}}async shutdown(){this.pipe=null}async embed(e){this.pipe||await this.initialize();const i=await this.pipe?.(e,{pooling:"mean",normalize:!0});if(!i)throw new Error("Embedding pipeline returned no output");return new Float32Array(i.data)}async embedQuery(e){return this.embed(this.queryPrefix+e)}async embedBatch(e){if(e.length===0)return[];this.pipe||await this.initialize();const i=[],a=32;for(let r=0;r<e.length;r+=a){const t=e.slice(r,r+a),n=await this.pipe?.(t,{pooling:"mean",normalize:!0});if(!n)throw new Error("Embedding pipeline returned no output");if(t.length===1)i.push(new Float32Array(n.data));else for(let s=0;s<t.length;s++){const o=s*this.dimensions,d=n.data.slice(o,o+this.dimensions);i.push(new Float32Array(d))}}return i}}export{h as OnnxEmbedder};
1
+ import{homedir as m}from"node:os";import{join as u}from"node:path";import{env as p,pipeline as c}from"@huggingface/transformers";import{EMBEDDING_DEFAULTS as l}from"../../core/dist/index.js";p.cacheDir=u(m(),".cache","huggingface","transformers-js");class w{pipe=null;dimensions;modelId;queryPrefix;constructor(e){this.modelId=e?.model??l.model,this.dimensions=e?.dimensions??l.dimensions,this.queryPrefix=e?.queryPrefix??this.detectQueryPrefix(this.modelId)}detectQueryPrefix(e){const i=e.toLowerCase();return i.includes("bge")||i.includes("mxbai-embed")?"Represent this sentence for searching relevant passages: ":i.includes("/e5-")||i.includes("multilingual-e5")?"query: ":""}async initialize(){if(!this.pipe)try{this.pipe=await c("feature-extraction",this.modelId,{dtype:"fp32"})}catch(e){throw new Error(`Failed to initialize embedding model "${this.modelId}": ${e.message}`)}}async shutdown(){this.pipe=null}async embed(e){this.pipe||await this.initialize();const i=await this.pipe?.(e,{pooling:"mean",normalize:!0});if(!i)throw new Error("Embedding pipeline returned no output");return new Float32Array(i.data)}async embedQuery(e){return this.embed(this.queryPrefix+e)}async embedBatch(e){if(e.length===0)return[];this.pipe||await this.initialize();const i=[],o=32;for(let r=0;r<e.length;r+=o){const t=e.slice(r,r+o),n=await this.pipe?.(t,{pooling:"mean",normalize:!0});if(!n)throw new Error("Embedding pipeline returned no output");if(t.length===1)i.push(new Float32Array(n.data));else for(let s=0;s<t.length;s++){const a=s*this.dimensions,d=n.data.slice(a,a+this.dimensions);i.push(new Float32Array(d))}}return i}}export{w as OnnxEmbedder};
@@ -1 +1 @@
1
- import{parseArgs as m}from"node:util";import{loadConfig as f}from"./config.js";import{createMcpServer as w,createServer as x,initializeKnowledgeBase as g}from"./server.js";const{values:u}=m({options:{transport:{type:"string",default:process.env.KB_TRANSPORT??"stdio"},port:{type:"string",default:process.env.KB_PORT??"3210"}}});async function I(){console.error("[KB] Starting MCP Knowledge Base server...");const t=f();if(console.error(`[KB] Config loaded: ${t.sources.length} source(s), store at ${t.store.path}`),u.transport==="http"){const{StreamableHTTPServerTransport:d}=await import("@modelcontextprotocol/sdk/server/streamableHttp.js"),a=(await import("express")).default,i=await g(t),c=w(i,t);console.error("[KB] MCP server configured with 46 tools and 2 resources");const n=a();n.use(a.json()),n.use((s,e,o)=>{if(e.setHeader("Access-Control-Allow-Origin",process.env.KB_CORS_ORIGIN??"*"),e.setHeader("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),s.method==="OPTIONS"){e.status(204).end();return}o()}),n.get("/health",(s,e)=>{e.json({status:"ok"})}),n.post("/mcp",async(s,e)=>{try{const o=new d({sessionIdGenerator:void 0});await c.connect(o),await o.handleRequest(s,e,s.body),e.on("close",()=>{o.close()})}catch(o){console.error("[KB] MCP handler error:",o),e.headersSent||e.status(500).json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null})}}),n.get("/mcp",(s,e)=>{e.writeHead(405).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))}),n.delete("/mcp",(s,e)=>{e.writeHead(405).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))});const l=Number(u.port),h=n.listen(l,()=>{console.error(`[KB] MCP server listening on http://0.0.0.0:${l}/mcp`),(async()=>{try{const e=t.sources.map(r=>r.path).join(", ");console.error(`[KB] Running initial index for sources: ${e}`);const o=await i.indexer.index(t,r=>{r.phase==="crawling"||r.phase==="done"||r.phase==="chunking"&&r.currentFile&&console.error(`[KB] [${r.filesProcessed+1}/${r.filesTotal}] ${r.currentFile}`)});console.error(`[KB] Indexed ${o.filesProcessed} files (${o.filesSkipped} skipped, ${o.chunksCreated} chunks) in ${(o.durationMs/1e3).toFixed(1)}s`);try{const r=await i.curated.reindexAll();console.error(`[KB] Curated re-index: ${r.indexed} entries restored to vector store`)}catch(r){console.error("[KB] Curated re-index failed:",r)}}catch(e){console.error("[KB] Initial index failed (will retry on kb_reindex):",e)}})()}),p=async s=>{console.error(`[KB] ${s} received \u2014 shutting down...`),h.close(),await c.close(),await i.store.close(),await i.embedder.shutdown(),process.exit(0)};process.on("SIGINT",()=>p("SIGINT")),process.on("SIGTERM",()=>p("SIGTERM"))}else{const{server:d,runInitialIndex:a}=await x(t),{StdioServerTransport:i}=await import("@modelcontextprotocol/sdk/server/stdio.js"),c=new i;await d.connect(c),console.error("[KB] MCP server started (stdio)"),process.env.KB_AUTO_INDEX!=="false"?a():console.error("[KB] Auto-index disabled (KB_AUTO_INDEX=false). Use kb_reindex to index manually.")}}I().catch(t=>{console.error("[KB] Fatal error:",t),process.exit(1)});
1
+ import{parseArgs as w}from"node:util";import{loadConfig as h}from"./config.js";import{createMcpServer as f,createServer as x,initializeKnowledgeBase as g}from"./server.js";const{values:u}=w({options:{transport:{type:"string",default:process.env.KB_TRANSPORT??"stdio"},port:{type:"string",default:process.env.KB_PORT??"3210"}}});async function I(){console.error("[KB] Starting MCP Knowledge Base server...");const t=h();if(console.error(`[KB] Config loaded: ${t.sources.length} source(s), store at ${t.store.path}`),u.transport==="http"){const{StreamableHTTPServerTransport:d}=await import("@modelcontextprotocol/sdk/server/streamableHttp.js"),a=(await import("express")).default,i=await g(t),c=f(i,t);console.error("[KB] MCP server configured with 46 tools and 2 resources");const n=a();n.use(a.json()),n.use((s,e,o)=>{if(e.setHeader("Access-Control-Allow-Origin",process.env.KB_CORS_ORIGIN??"*"),e.setHeader("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),s.method==="OPTIONS"){e.status(204).end();return}o()}),n.get("/health",(s,e)=>{e.json({status:"ok"})}),n.post("/mcp",async(s,e)=>{try{const o=new d({sessionIdGenerator:void 0});await c.connect(o),await o.handleRequest(s,e,s.body),e.on("close",()=>{o.close()})}catch(o){console.error("[KB] MCP handler error:",o),e.headersSent||e.status(500).json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null})}}),n.get("/mcp",(s,e)=>{e.writeHead(405).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))}),n.delete("/mcp",(s,e)=>{e.writeHead(405).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))});const l=Number(u.port),m=n.listen(l,()=>{console.error(`[KB] MCP server listening on http://0.0.0.0:${l}/mcp`),(async()=>{try{const e=t.sources.map(r=>r.path).join(", ");console.error(`[KB] Running initial index for sources: ${e}`);const o=await i.indexer.index(t,r=>{r.phase==="crawling"||r.phase==="done"||r.phase==="chunking"&&r.currentFile&&console.error(`[KB] [${r.filesProcessed+1}/${r.filesTotal}] ${r.currentFile}`)});console.error(`[KB] Indexed ${o.filesProcessed} files (${o.filesSkipped} skipped, ${o.chunksCreated} chunks) in ${(o.durationMs/1e3).toFixed(1)}s`);try{const r=await i.curated.reindexAll();console.error(`[KB] Curated re-index: ${r.indexed} entries restored to vector store`)}catch(r){console.error("[KB] Curated re-index failed:",r)}}catch(e){console.error("[KB] Initial index failed (will retry on kb_reindex):",e)}})()}),p=async s=>{console.error(`[KB] ${s} received \u2014 shutting down...`),m.close(),await c.close(),await i.store.close(),await i.embedder.shutdown(),process.exit(0)};process.on("SIGINT",()=>p("SIGINT")),process.on("SIGTERM",()=>p("SIGTERM"))}else{const{McpServer:d}=await import("@modelcontextprotocol/sdk/server/mcp.js"),{StdioServerTransport:a}=await import("@modelcontextprotocol/sdk/server/stdio.js"),i=new d({name:"kb",version:"0.1.0"}),c=new a;await i.connect(c),console.error("[KB] MCP server started (stdio)");const{runInitialIndex:n}=await x(t,i);console.error("[KB] MCP server configured with 64 tools and 2 resources"),process.env.KB_AUTO_INDEX!=="false"?n():console.error("[KB] Auto-index disabled (KB_AUTO_INDEX=false). Use kb_reindex to index manually.")}}I().catch(t=>{console.error("[KB] Fatal error:",t),process.exit(1)});
@@ -14,8 +14,10 @@ export interface KnowledgeBaseComponents {
14
14
  }
15
15
  export declare function initializeKnowledgeBase(config: KBConfig): Promise<KnowledgeBaseComponents>;
16
16
  export declare function createMcpServer(kb: KnowledgeBaseComponents, config: KBConfig): McpServer;
17
- export declare function createServer(config: KBConfig): Promise<{
17
+ export declare function registerMcpTools(server: McpServer, kb: KnowledgeBaseComponents, config: KBConfig): void;
18
+ export declare function createServer(config: KBConfig, existingServer?: McpServer): Promise<{
18
19
  server: McpServer;
19
20
  runInitialIndex: () => Promise<void>;
21
+ shutdown: () => Promise<void>;
20
22
  }>;
21
23
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- import{initializeTreeSitter as c}from"../../chunker/dist/index.js";import{OnnxEmbedder as m}from"../../embeddings/dist/index.js";import{IncrementalIndexer as g}from"../../indexer/dist/index.js";import{createStore as p,SqliteGraphStore as T}from"../../store/dist/index.js";import{McpServer as u}from"@modelcontextprotocol/sdk/server/mcp.js";import{CuratedKnowledgeManager as f}from"./curated-manager.js";import{installReplayInterceptor as h}from"./replay-interceptor.js";import{registerResources as S}from"./resources/resources.js";import{registerAnalyzeDependenciesTool as x,registerAnalyzeDiagramTool as w,registerAnalyzeEntryPointsTool as K,registerAnalyzePatternsTool as y,registerAnalyzeStructureTool as B,registerAnalyzeSymbolsTool as C,registerBlastRadiusTool as I}from"./tools/analyze.tools.js";import{registerDigestTool as v,registerEvidenceMapTool as P,registerForgeClassifyTool as z,registerForgeGroundTool as R,registerStratumCardTool as E}from"./tools/forge.tools.js";import{registerForgetTool as F}from"./tools/forget.tool.js";import{registerGraphTool as M}from"./tools/graph.tool.js";import{registerListTool as $}from"./tools/list.tool.js";import{registerLookupTool as G}from"./tools/lookup.tool.js";import{registerOnboardTool as A}from"./tools/onboard.tool.js";import{registerProduceKnowledgeTool as D}from"./tools/produce.tool.js";import{registerReadTool as O}from"./tools/read.tool.js";import{registerReindexTool as W}from"./tools/reindex.tool.js";import{registerRememberTool as j}from"./tools/remember.tool.js";import{registerReplayTool as L}from"./tools/replay.tool.js";import{registerSearchTool as H}from"./tools/search.tool.js";import{registerStatusTool as q}from"./tools/status.tool.js";import{registerBatchTool as N,registerCheckpointTool as Q,registerCheckTool as U,registerCodemodTool as V,registerCompactTool as _,registerDataTransformTool as J,registerDeadSymbolsTool as X,registerDelegateTool as Y,registerDiffParseTool as Z,registerEvalTool as b,registerFileSummaryTool as k,registerFindExamplesTool as ee,registerFindTool as re,registerGitContextTool as oe,registerHealthTool as te,registerLaneTool as se,registerParseOutputTool as ie,registerProcessTool as ne,registerQueueTool as ae,registerRenameTool as le,registerScopeMapTool as de,registerStashTool as ce,registerSymbolTool as me,registerTestRunTool as ge,registerTraceTool as pe,registerWatchTool as Te,registerWebFetchTool as ue,registerWorksetTool as fe}from"./tools/toolkit.tools.js";import{registerUpdateTool as he}from"./tools/update.tool.js";import{registerChangelogTool as Se,registerEncodeTool as xe,registerEnvTool as we,registerHttpTool as Ke,registerMeasureTool as ye,registerRegexTestTool as Be,registerSchemaValidateTool as Ce,registerSnippetTool as Ie,registerTimeTool as ve,registerWebSearchTool as Pe}from"./tools/utility.tools.js";async function ze(r){console.error("[KB] Initializing knowledge base components...");const t=new m({model:r.embedding.model,dimensions:r.embedding.dimensions});await t.initialize(),console.error(`[KB] Embedder loaded: ${t.modelId} (${t.dimensions}d)`);const e=await p({backend:r.store.backend,path:r.store.path});await e.initialize(),console.error("[KB] Store initialized");const a=new g(t,e),i=r.curated.path,d=new f(i,e,t),s=new T({path:r.store.path});await s.initialize(),console.error("[KB] Graph store initialized"),a.setGraphStore(s);const n=await c();return console.error(n?"[KB] Tree-sitter chunking enabled":"[KB] Tree-sitter not available \u2014 using regex-based code chunking"),{embedder:t,store:e,indexer:a,curated:d,graphStore:s}}function Re(r,t){const e=new u({name:"kb",version:"0.1.0"});return h(e),H(e,r.embedder,r.store,r.graphStore),G(e,r.store),q(e,r.store,r.graphStore),W(e,r.indexer,t,r.curated,r.store),j(e,r.curated),he(e,r.curated),F(e,r.curated),O(e,r.curated),$(e,r.curated),B(e,r.store,r.embedder),x(e,r.store,r.embedder),C(e,r.store,r.embedder),y(e,r.store,r.embedder),K(e,r.store,r.embedder),w(e,r.store,r.embedder),I(e,r.store,r.embedder),D(e),A(e,r.store,r.embedder),M(e,r.graphStore),_(e,r.embedder),de(e,r.embedder,r.store),re(e,r.embedder,r.store),ie(e),fe(e),U(e),N(e,r.embedder,r.store),me(e,r.embedder,r.store),b(e),ge(e),ce(e),oe(e),Z(e),le(e),V(e),k(e),Q(e),J(e),pe(e,r.embedder,r.store),ee(e,r.embedder,r.store),ne(e),Te(e),X(e,r.embedder,r.store),Y(e),te(e),se(e),ae(e),ue(e),P(e),v(e,r.embedder),z(e),E(e,r.embedder),R(e,r.embedder,r.store),Pe(e),Ke(e),Be(e),xe(e),ye(e),Se(e),Ce(e),Ie(e),we(e),ve(e),S(e,r.store),L(e),e}async function rr(r){const t=await ze(r),e=Re(t,r);console.error("[KB] MCP server configured with 64 tools and 2 resources");const a=async()=>{try{const n=r.sources.map(o=>o.path).join(", ");console.error(`[KB] Running initial index for sources: ${n}`);const l=await t.indexer.index(r,o=>{o.phase==="crawling"||o.phase==="done"||(o.phase==="chunking"&&o.currentFile&&console.error(`[KB] [${o.filesProcessed+1}/${o.filesTotal}] ${o.currentFile}`),o.phase==="cleanup"&&console.error(`[KB] cleanup: removing ${o.filesTotal-o.filesProcessed} stale entries`))});console.error(`[KB] Indexed ${l.filesProcessed} files (${l.filesSkipped} skipped, ${l.chunksCreated} chunks) in ${(l.durationMs/1e3).toFixed(1)}s`);try{await t.store.createFtsIndex()}catch(o){console.error("[KB] FTS index creation failed (non-fatal):",o)}try{const o=await t.curated.reindexAll();console.error(`[KB] Curated re-index: ${o.indexed} entries restored to vector store`)}catch(o){console.error("[KB] Curated re-index failed:",o)}}catch(n){console.error("[KB] Initial index failed (will retry on kb_reindex):",n)}},i=async()=>{console.error("[KB] Shutting down..."),await t.graphStore.close().catch(()=>{}),await t.store.close(),process.exit(0)};process.on("SIGINT",i),process.on("SIGTERM",i);const d=process.ppid,s=setInterval(()=>{try{process.kill(d,0)}catch{console.error("[KB] Parent process died \u2014 orphan detected, shutting down..."),clearInterval(s),i()}},5e3);return s.unref(),{server:e,runInitialIndex:a}}export{Re as createMcpServer,rr as createServer,ze as initializeKnowledgeBase};
1
+ import{initializeTreeSitter as g}from"../../chunker/dist/index.js";import{OnnxEmbedder as p}from"../../embeddings/dist/index.js";import{IncrementalIndexer as T}from"../../indexer/dist/index.js";import{createStore as u,SqliteGraphStore as f}from"../../store/dist/index.js";import{McpServer as h}from"@modelcontextprotocol/sdk/server/mcp.js";import{CuratedKnowledgeManager as S}from"./curated-manager.js";import{installReplayInterceptor as x}from"./replay-interceptor.js";import{registerResources as w}from"./resources/resources.js";import{registerAnalyzeDependenciesTool as K,registerAnalyzeDiagramTool as B,registerAnalyzeEntryPointsTool as y,registerAnalyzePatternsTool as C,registerAnalyzeStructureTool as I,registerAnalyzeSymbolsTool as P,registerBlastRadiusTool as M}from"./tools/analyze.tools.js";import{registerDigestTool as z,registerEvidenceMapTool as R,registerForgeClassifyTool as E,registerForgeGroundTool as F,registerStratumCardTool as $}from"./tools/forge.tools.js";import{registerForgetTool as G}from"./tools/forget.tool.js";import{registerGraphTool as A}from"./tools/graph.tool.js";import{registerListTool as D}from"./tools/list.tool.js";import{registerLookupTool as O}from"./tools/lookup.tool.js";import{registerOnboardTool as W}from"./tools/onboard.tool.js";import{registerProduceKnowledgeTool as j}from"./tools/produce.tool.js";import{registerReadTool as L}from"./tools/read.tool.js";import{registerReindexTool as H}from"./tools/reindex.tool.js";import{registerRememberTool as q}from"./tools/remember.tool.js";import{registerReplayTool as N}from"./tools/replay.tool.js";import{registerSearchTool as Q}from"./tools/search.tool.js";import{registerStatusTool as U}from"./tools/status.tool.js";import{registerBatchTool as V,registerCheckpointTool as _,registerCheckTool as J,registerCodemodTool as X,registerCompactTool as Y,registerDataTransformTool as Z,registerDeadSymbolsTool as b,registerDelegateTool as k,registerDiffParseTool as v,registerEvalTool as ee,registerFileSummaryTool as oe,registerFindExamplesTool as re,registerFindTool as te,registerGitContextTool as ie,registerHealthTool as ne,registerLaneTool as ae,registerParseOutputTool as se,registerProcessTool as le,registerQueueTool as de,registerRenameTool as ce,registerScopeMapTool as me,registerStashTool as ge,registerSymbolTool as pe,registerTestRunTool as Te,registerTraceTool as ue,registerWatchTool as fe,registerWebFetchTool as he,registerWorksetTool as Se}from"./tools/toolkit.tools.js";import{registerUpdateTool as xe}from"./tools/update.tool.js";import{registerChangelogTool as we,registerEncodeTool as Ke,registerEnvTool as Be,registerHttpTool as ye,registerMeasureTool as Ce,registerRegexTestTool as Ie,registerSchemaValidateTool as Pe,registerSnippetTool as Me,registerTimeTool as ze,registerWebSearchTool as Re}from"./tools/utility.tools.js";async function Ee(e){console.error("[KB] Initializing knowledge base components...");const o=new p({model:e.embedding.model,dimensions:e.embedding.dimensions});await o.initialize(),console.error(`[KB] Embedder loaded: ${o.modelId} (${o.dimensions}d)`);const t=await u({backend:e.store.backend,path:e.store.path});await t.initialize(),console.error("[KB] Store initialized");const i=new T(o,t),d=e.curated.path,n=new S(d,t,o),a=new f({path:e.store.path});await a.initialize(),console.error("[KB] Graph store initialized"),i.setGraphStore(a);const s=await g();return console.error(s?"[KB] Tree-sitter chunking enabled":"[KB] Tree-sitter not available \u2014 using regex-based code chunking"),{embedder:o,store:t,indexer:i,curated:n,graphStore:a}}function Fe(e,o){const t=new h({name:"kb",version:"0.1.0"});return m(t,e,o),t}function m(e,o,t){x(e),Q(e,o.embedder,o.store,o.graphStore),O(e,o.store),U(e,o.store,o.graphStore),H(e,o.indexer,t,o.curated,o.store),q(e,o.curated),xe(e,o.curated),G(e,o.curated),L(e,o.curated),D(e,o.curated),I(e,o.store,o.embedder),K(e,o.store,o.embedder),P(e,o.store,o.embedder),C(e,o.store,o.embedder),y(e,o.store,o.embedder),B(e,o.store,o.embedder),M(e,o.store,o.embedder),j(e),W(e,o.store,o.embedder),A(e,o.graphStore),Y(e,o.embedder),me(e,o.embedder,o.store),te(e,o.embedder,o.store),se(e),Se(e),J(e),V(e,o.embedder,o.store),pe(e,o.embedder,o.store),ee(e),Te(e),ge(e),ie(e),v(e),ce(e),X(e),oe(e),_(e),Z(e),ue(e,o.embedder,o.store),re(e,o.embedder,o.store),le(e),fe(e),b(e,o.embedder,o.store),k(e),ne(e),ae(e),de(e),he(e),R(e),z(e,o.embedder),E(e),$(e,o.embedder),F(e,o.embedder,o.store),Re(e),ye(e),Ie(e),Ke(e),Ce(e),we(e),Pe(e),Me(e),Be(e),ze(e),w(e,o.store),N(e)}async function to(e,o){const t=await Ee(e);let i;o?(m(o,t,e),i=o):i=Fe(t,e);const d=async()=>{try{const c=e.sources.map(r=>r.path).join(", ");console.error(`[KB] Running initial index for sources: ${c}`);const l=await t.indexer.index(e,r=>{r.phase==="crawling"||r.phase==="done"||(r.phase==="chunking"&&r.currentFile&&console.error(`[KB] [${r.filesProcessed+1}/${r.filesTotal}] ${r.currentFile}`),r.phase==="cleanup"&&console.error(`[KB] cleanup: removing ${r.filesTotal-r.filesProcessed} stale entries`))});console.error(`[KB] Indexed ${l.filesProcessed} files (${l.filesSkipped} skipped, ${l.chunksCreated} chunks) in ${(l.durationMs/1e3).toFixed(1)}s`);try{await t.store.createFtsIndex()}catch(r){console.error("[KB] FTS index creation failed (non-fatal):",r)}try{const r=await t.curated.reindexAll();console.error(`[KB] Curated re-index: ${r.indexed} entries restored to vector store`)}catch(r){console.error("[KB] Curated re-index failed:",r)}}catch(c){console.error("[KB] Initial index failed (will retry on kb_reindex):",c)}},n=async()=>{console.error("[KB] Shutting down..."),await t.graphStore.close().catch(()=>{}),await t.store.close(),process.exit(0)};process.on("SIGINT",n),process.on("SIGTERM",n);const a=process.ppid,s=setInterval(()=>{try{process.kill(a,0)}catch{console.error("[KB] Parent process died \u2014 orphan detected, shutting down..."),clearInterval(s),n()}},5e3);return s.unref(),{server:i,runInitialIndex:d,shutdown:n}}export{Fe as createMcpServer,to as createServer,Ee as initializeKnowledgeBase,m as registerMcpTools};