@vpxa/kb 0.1.5 → 0.1.7

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.7",
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};
@@ -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 registerMcpTools(server: McpServer, kb: KnowledgeBaseComponents, config: KBConfig): void;
17
18
  export declare function createServer(config: KBConfig): 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 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 B,registerAnalyzeStructureTool as y,registerAnalyzeSymbolsTool as C,registerBlastRadiusTool as I}from"./tools/analyze.tools.js";import{registerDigestTool as P,registerEvidenceMapTool as z,registerForgeClassifyTool as M,registerForgeGroundTool as R,registerStratumCardTool as E}from"./tools/forge.tools.js";import{registerForgetTool as F}from"./tools/forget.tool.js";import{registerGraphTool as $}from"./tools/graph.tool.js";import{registerListTool as G}from"./tools/list.tool.js";import{registerLookupTool as A}from"./tools/lookup.tool.js";import{registerOnboardTool as D}from"./tools/onboard.tool.js";import{registerProduceKnowledgeTool as O}from"./tools/produce.tool.js";import{registerReadTool as W}from"./tools/read.tool.js";import{registerReindexTool as j}from"./tools/reindex.tool.js";import{registerRememberTool as L}from"./tools/remember.tool.js";import{registerReplayTool as H}from"./tools/replay.tool.js";import{registerSearchTool as q}from"./tools/search.tool.js";import{registerStatusTool as N}from"./tools/status.tool.js";import{registerBatchTool as Q,registerCheckpointTool as U,registerCheckTool as V,registerCodemodTool as _,registerCompactTool as J,registerDataTransformTool as X,registerDeadSymbolsTool as Y,registerDelegateTool as Z,registerDiffParseTool as b,registerEvalTool as k,registerFileSummaryTool as v,registerFindExamplesTool as ee,registerFindTool as oe,registerGitContextTool as re,registerHealthTool as te,registerLaneTool as ie,registerParseOutputTool as ne,registerProcessTool as se,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 Be,registerRegexTestTool as ye,registerSchemaValidateTool as Ce,registerSnippetTool as Ie,registerTimeTool as Pe,registerWebSearchTool as ze}from"./tools/utility.tools.js";async function Me(e){console.error("[KB] Initializing knowledge base components...");const o=new m({model:e.embedding.model,dimensions:e.embedding.dimensions});await o.initialize(),console.error(`[KB] Embedder loaded: ${o.modelId} (${o.dimensions}d)`);const t=await p({backend:e.store.backend,path:e.store.path});await t.initialize(),console.error("[KB] Store initialized");const a=new g(o,t),i=e.curated.path,d=new f(i,t,o),n=new T({path:e.store.path});await n.initialize(),console.error("[KB] Graph store initialized"),a.setGraphStore(n);const s=await c();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:a,curated:d,graphStore:n}}function Re(e,o){const t=new u({name:"kb",version:"0.1.0"});return Ee(t,e,o),t}function Ee(e,o,t){h(e),q(e,o.embedder,o.store,o.graphStore),A(e,o.store),N(e,o.store,o.graphStore),j(e,o.indexer,t,o.curated,o.store),L(e,o.curated),he(e,o.curated),F(e,o.curated),W(e,o.curated),G(e,o.curated),y(e,o.store,o.embedder),x(e,o.store,o.embedder),C(e,o.store,o.embedder),B(e,o.store,o.embedder),K(e,o.store,o.embedder),w(e,o.store,o.embedder),I(e,o.store,o.embedder),O(e),D(e,o.store,o.embedder),$(e,o.graphStore),J(e,o.embedder),de(e,o.embedder,o.store),oe(e,o.embedder,o.store),ne(e),fe(e),V(e),Q(e,o.embedder,o.store),me(e,o.embedder,o.store),k(e),ge(e),ce(e),re(e),b(e),le(e),_(e),v(e),U(e),X(e),pe(e,o.embedder,o.store),ee(e,o.embedder,o.store),se(e),Te(e),Y(e,o.embedder,o.store),Z(e),te(e),ie(e),ae(e),ue(e),z(e),P(e,o.embedder),M(e),E(e,o.embedder),R(e,o.embedder,o.store),ze(e),Ke(e),ye(e),xe(e),Be(e),Se(e),Ce(e),Ie(e),we(e),Pe(e),S(e,o.store),H(e)}async function ro(e){const o=await Me(e),t=Re(o,e);console.error("[KB] MCP server configured with 64 tools and 2 resources");const a=async()=>{try{const s=e.sources.map(r=>r.path).join(", ");console.error(`[KB] Running initial index for sources: ${s}`);const l=await o.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 o.store.createFtsIndex()}catch(r){console.error("[KB] FTS index creation failed (non-fatal):",r)}try{const r=await o.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(s){console.error("[KB] Initial index failed (will retry on kb_reindex):",s)}},i=async()=>{console.error("[KB] Shutting down..."),await o.graphStore.close().catch(()=>{}),await o.store.close(),process.exit(0)};process.on("SIGINT",i),process.on("SIGTERM",i);const d=process.ppid,n=setInterval(()=>{try{process.kill(d,0)}catch{console.error("[KB] Parent process died \u2014 orphan detected, shutting down..."),clearInterval(n),i()}},5e3);return n.unref(),{server:t,runInitialIndex:a,shutdown:i}}export{Re as createMcpServer,ro as createServer,Me as initializeKnowledgeBase,Ee as registerMcpTools};