@vpxa/kb 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/package.json +1 -1
  2. package/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
  3. package/packages/analyzers/dist/dependency-analyzer.js +11 -425
  4. package/packages/analyzers/dist/diagram-generator.js +4 -86
  5. package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
  6. package/packages/analyzers/dist/index.js +1 -23
  7. package/packages/analyzers/dist/knowledge-producer.js +24 -113
  8. package/packages/analyzers/dist/pattern-analyzer.js +5 -359
  9. package/packages/analyzers/dist/regex-call-graph.js +1 -428
  10. package/packages/analyzers/dist/structure-analyzer.js +4 -258
  11. package/packages/analyzers/dist/symbol-analyzer.js +13 -442
  12. package/packages/analyzers/dist/ts-call-graph.js +1 -160
  13. package/packages/analyzers/dist/types.js +0 -1
  14. package/packages/chunker/dist/call-graph-extractor.js +1 -90
  15. package/packages/chunker/dist/chunker-factory.js +1 -36
  16. package/packages/chunker/dist/chunker.interface.js +0 -1
  17. package/packages/chunker/dist/code-chunker.js +14 -134
  18. package/packages/chunker/dist/generic-chunker.js +5 -72
  19. package/packages/chunker/dist/index.js +1 -21
  20. package/packages/chunker/dist/markdown-chunker.js +7 -119
  21. package/packages/chunker/dist/treesitter-chunker.js +8 -234
  22. package/packages/cli/dist/commands/analyze.js +3 -112
  23. package/packages/cli/dist/commands/context-cmds.js +1 -155
  24. package/packages/cli/dist/commands/environment.js +2 -204
  25. package/packages/cli/dist/commands/execution.js +1 -137
  26. package/packages/cli/dist/commands/graph.js +7 -81
  27. package/packages/cli/dist/commands/init.js +9 -87
  28. package/packages/cli/dist/commands/knowledge.js +1 -139
  29. package/packages/cli/dist/commands/search.js +8 -267
  30. package/packages/cli/dist/commands/system.js +4 -241
  31. package/packages/cli/dist/commands/workspace.js +2 -388
  32. package/packages/cli/dist/context.js +1 -14
  33. package/packages/cli/dist/helpers.js +3 -458
  34. package/packages/cli/dist/index.js +3 -69
  35. package/packages/cli/dist/kb-init.js +1 -82
  36. package/packages/cli/dist/types.js +0 -1
  37. package/packages/core/dist/constants.js +1 -43
  38. package/packages/core/dist/content-detector.js +1 -79
  39. package/packages/core/dist/errors.js +1 -40
  40. package/packages/core/dist/index.js +1 -9
  41. package/packages/core/dist/logger.js +1 -34
  42. package/packages/core/dist/types.js +0 -1
  43. package/packages/embeddings/dist/embedder.interface.js +0 -1
  44. package/packages/embeddings/dist/index.js +1 -5
  45. package/packages/embeddings/dist/onnx-embedder.js +1 -82
  46. package/packages/indexer/dist/file-hasher.js +1 -13
  47. package/packages/indexer/dist/filesystem-crawler.js +1 -125
  48. package/packages/indexer/dist/graph-extractor.js +1 -111
  49. package/packages/indexer/dist/incremental-indexer.js +1 -278
  50. package/packages/indexer/dist/index.js +1 -14
  51. package/packages/server/dist/api.js +1 -9
  52. package/packages/server/dist/config.js +1 -75
  53. package/packages/server/dist/curated-manager.js +9 -356
  54. package/packages/server/dist/index.js +1 -134
  55. package/packages/server/dist/replay-interceptor.js +1 -38
  56. package/packages/server/dist/resources/resources.js +2 -40
  57. package/packages/server/dist/server.js +1 -247
  58. package/packages/server/dist/tools/analyze.tools.js +1 -288
  59. package/packages/server/dist/tools/forge.tools.js +11 -499
  60. package/packages/server/dist/tools/forget.tool.js +3 -39
  61. package/packages/server/dist/tools/graph.tool.js +5 -110
  62. package/packages/server/dist/tools/list.tool.js +5 -53
  63. package/packages/server/dist/tools/lookup.tool.js +8 -51
  64. package/packages/server/dist/tools/onboard.tool.js +2 -112
  65. package/packages/server/dist/tools/produce.tool.js +4 -74
  66. package/packages/server/dist/tools/read.tool.js +4 -47
  67. package/packages/server/dist/tools/reindex.tool.js +2 -70
  68. package/packages/server/dist/tools/remember.tool.js +3 -42
  69. package/packages/server/dist/tools/replay.tool.js +6 -88
  70. package/packages/server/dist/tools/search.tool.js +17 -327
  71. package/packages/server/dist/tools/status.tool.js +3 -68
  72. package/packages/server/dist/tools/toolkit.tools.js +20 -1673
  73. package/packages/server/dist/tools/update.tool.js +3 -39
  74. package/packages/server/dist/tools/utility.tools.js +19 -456
  75. package/packages/store/dist/graph-store.interface.js +0 -1
  76. package/packages/store/dist/index.js +1 -9
  77. package/packages/store/dist/lance-store.js +1 -258
  78. package/packages/store/dist/sqlite-graph-store.js +8 -309
  79. package/packages/store/dist/store-factory.js +1 -14
  80. package/packages/store/dist/store.interface.js +0 -1
  81. package/packages/tools/dist/batch.js +1 -45
  82. package/packages/tools/dist/changelog.js +2 -112
  83. package/packages/tools/dist/check.js +2 -59
  84. package/packages/tools/dist/checkpoint.js +2 -43
  85. package/packages/tools/dist/codemod.js +2 -69
  86. package/packages/tools/dist/compact.js +3 -60
  87. package/packages/tools/dist/data-transform.js +1 -124
  88. package/packages/tools/dist/dead-symbols.js +2 -71
  89. package/packages/tools/dist/delegate.js +3 -128
  90. package/packages/tools/dist/diff-parse.js +3 -153
  91. package/packages/tools/dist/digest.js +7 -242
  92. package/packages/tools/dist/encode.js +1 -46
  93. package/packages/tools/dist/env-info.js +1 -58
  94. package/packages/tools/dist/eval.js +3 -79
  95. package/packages/tools/dist/evidence-map.js +3 -203
  96. package/packages/tools/dist/file-summary.js +2 -106
  97. package/packages/tools/dist/file-walk.js +1 -75
  98. package/packages/tools/dist/find-examples.js +3 -48
  99. package/packages/tools/dist/find.js +1 -120
  100. package/packages/tools/dist/forge-classify.js +2 -319
  101. package/packages/tools/dist/forge-ground.js +1 -184
  102. package/packages/tools/dist/git-context.js +3 -46
  103. package/packages/tools/dist/graph-query.js +1 -194
  104. package/packages/tools/dist/health.js +1 -118
  105. package/packages/tools/dist/http-request.js +1 -58
  106. package/packages/tools/dist/index.js +1 -273
  107. package/packages/tools/dist/lane.js +7 -227
  108. package/packages/tools/dist/measure.js +2 -119
  109. package/packages/tools/dist/onboard.js +42 -1136
  110. package/packages/tools/dist/parse-output.js +2 -158
  111. package/packages/tools/dist/process-manager.js +1 -69
  112. package/packages/tools/dist/queue.js +2 -126
  113. package/packages/tools/dist/regex-test.js +1 -39
  114. package/packages/tools/dist/rename.js +2 -70
  115. package/packages/tools/dist/replay.js +6 -108
  116. package/packages/tools/dist/schema-validate.js +1 -141
  117. package/packages/tools/dist/scope-map.js +1 -72
  118. package/packages/tools/dist/snippet.js +1 -80
  119. package/packages/tools/dist/stash.js +2 -60
  120. package/packages/tools/dist/stratum-card.js +5 -238
  121. package/packages/tools/dist/symbol.js +3 -87
  122. package/packages/tools/dist/test-run.js +2 -55
  123. package/packages/tools/dist/text-utils.js +2 -31
  124. package/packages/tools/dist/time-utils.js +1 -135
  125. package/packages/tools/dist/trace.js +2 -114
  126. package/packages/tools/dist/truncation.js +10 -41
  127. package/packages/tools/dist/watch.js +1 -61
  128. package/packages/tools/dist/web-fetch.js +9 -244
  129. package/packages/tools/dist/web-search.js +1 -46
  130. package/packages/tools/dist/workset.js +2 -77
  131. package/packages/tui/dist/App.js +260 -52468
  132. package/packages/tui/dist/index.js +286 -54551
  133. package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
  134. package/packages/tui/dist/panels/LogPanel.js +259 -51703
  135. package/packages/tui/dist/panels/SearchPanel.js +212 -34824
  136. package/packages/tui/dist/panels/StatusPanel.js +211 -34304
@@ -1,110 +1,5 @@
1
- import { graphQuery } from "@kb/tools";
2
- import { z } from "zod";
3
- const nodeSchema = z.object({
4
- id: z.string().optional().describe("Node ID (auto-generated if omitted)"),
5
- type: z.string().describe("Node type (entity, service, api, concept, decision)"),
6
- name: z.string().describe("Display name"),
7
- properties: z.record(z.string(), z.unknown()).optional().describe("Arbitrary properties"),
8
- sourceRecordId: z.string().optional().describe("Back-link to knowledge record ID"),
9
- sourcePath: z.string().optional().describe("Source file path")
10
- });
11
- const edgeSchema = z.object({
12
- id: z.string().optional().describe("Edge ID (auto-generated if omitted)"),
13
- fromId: z.string().describe("Source node ID"),
14
- toId: z.string().describe("Target node ID"),
15
- type: z.string().describe("Relationship type (depends-on, implements, calls, affects)"),
16
- weight: z.number().min(0).max(1).optional().describe("Relationship weight"),
17
- properties: z.record(z.string(), z.unknown()).optional().describe("Arbitrary properties")
18
- });
19
- function registerGraphTool(server, graphStore) {
20
- server.registerTool(
21
- "graph",
22
- {
23
- description: "Query and manage the knowledge graph. Find nodes/edges, traverse connections, add entities and relationships. The graph captures structural relationships between concepts discovered in the codebase.",
24
- inputSchema: {
25
- action: z.enum([
26
- "find_nodes",
27
- "find_edges",
28
- "neighbors",
29
- "traverse",
30
- "stats",
31
- "add",
32
- "delete",
33
- "clear"
34
- ]).describe(
35
- "Action: find_nodes (search nodes), find_edges (search edges), neighbors (direct connections), traverse (multi-hop), stats (graph overview), add (insert nodes/edges), delete (remove nodes), clear (remove all)"
36
- ),
37
- node_type: z.string().optional().describe("Node type filter (for find_nodes)"),
38
- name_pattern: z.string().optional().describe("Name substring match (for find_nodes)"),
39
- source_path: z.string().optional().describe("Source path filter"),
40
- node_id: z.string().optional().describe("Node ID (for neighbors, traverse, delete)"),
41
- edge_type: z.string().optional().describe("Edge type filter"),
42
- from_id: z.string().optional().describe("Source node ID (for find_edges)"),
43
- to_id: z.string().optional().describe("Target node ID (for find_edges)"),
44
- direction: z.enum(["outgoing", "incoming", "both"]).default("both").describe("Traversal direction"),
45
- max_depth: z.number().min(1).max(5).default(2).describe("Max traversal depth"),
46
- limit: z.number().min(1).max(100).default(50).describe("Max results"),
47
- nodes: z.array(nodeSchema).optional().describe("Nodes to add (for action=add)"),
48
- edges: z.array(edgeSchema).optional().describe("Edges to add (for action=add)")
49
- }
50
- },
51
- async (args) => {
52
- try {
53
- const result = await graphQuery(graphStore, {
54
- action: args.action,
55
- nodeType: args.node_type,
56
- namePattern: args.name_pattern,
57
- sourcePath: args.source_path,
58
- nodeId: args.node_id,
59
- edgeType: args.edge_type,
60
- fromId: args.from_id,
61
- toId: args.to_id,
62
- direction: args.direction,
63
- maxDepth: args.max_depth,
64
- limit: args.limit,
65
- nodes: args.nodes,
66
- edges: args.edges
67
- });
68
- const parts = [result.summary];
69
- if (result.nodes && result.nodes.length > 0) {
70
- parts.push("\n### Nodes");
71
- for (const n of result.nodes) {
72
- const props = Object.keys(n.properties).length > 0 ? ` \u2014 ${JSON.stringify(n.properties)}` : "";
73
- parts.push(`- **${n.name}** (${n.type}, id: \`${n.id}\`)${props}`);
74
- }
75
- }
76
- if (result.edges && result.edges.length > 0) {
77
- parts.push("\n### Edges");
78
- for (const e of result.edges) {
79
- parts.push(
80
- `- \`${e.fromId}\` \u2014[${e.type}]\u2192 \`${e.toId}\`${e.weight !== 1 ? ` (weight: ${e.weight})` : ""}`
81
- );
82
- }
83
- }
84
- if (result.stats) {
85
- parts.push(`
86
- Node types: ${JSON.stringify(result.stats.nodeTypes)}`);
87
- parts.push(`Edge types: ${JSON.stringify(result.stats.edgeTypes)}`);
88
- }
89
- parts.push(
90
- "\n---\n_Next: Use `graph(traverse)` to explore connections, `graph(add)` to insert entities, or `search` with graph-augmented results._"
91
- );
92
- return {
93
- content: [{ type: "text", text: parts.join("\n") }]
94
- };
95
- } catch (err) {
96
- console.error("[KB] Graph query failed:", err);
97
- return {
98
- content: [
99
- { type: "text", text: `Graph query failed: ${err.message}` }
100
- ],
101
- isError: true
102
- };
103
- }
104
- }
105
- );
106
- }
107
- export {
108
- registerGraphTool
109
- };
110
- //# sourceMappingURL=graph.tool.js.map
1
+ import{graphQuery as a}from"@kb/tools";import{z as e}from"zod";const p=e.object({id:e.string().optional().describe("Node ID (auto-generated if omitted)"),type:e.string().describe("Node type (entity, service, api, concept, decision)"),name:e.string().describe("Display name"),properties:e.record(e.string(),e.unknown()).optional().describe("Arbitrary properties"),sourceRecordId:e.string().optional().describe("Back-link to knowledge record ID"),sourcePath:e.string().optional().describe("Source file path")}),c=e.object({id:e.string().optional().describe("Edge ID (auto-generated if omitted)"),fromId:e.string().describe("Source node ID"),toId:e.string().describe("Target node ID"),type:e.string().describe("Relationship type (depends-on, implements, calls, affects)"),weight:e.number().min(0).max(1).optional().describe("Relationship weight"),properties:e.record(e.string(),e.unknown()).optional().describe("Arbitrary properties")});function h(n,s){n.registerTool("graph",{description:"Query and manage the knowledge graph. Find nodes/edges, traverse connections, add entities and relationships. The graph captures structural relationships between concepts discovered in the codebase.",inputSchema:{action:e.enum(["find_nodes","find_edges","neighbors","traverse","stats","add","delete","clear"]).describe("Action: find_nodes (search nodes), find_edges (search edges), neighbors (direct connections), traverse (multi-hop), stats (graph overview), add (insert nodes/edges), delete (remove nodes), clear (remove all)"),node_type:e.string().optional().describe("Node type filter (for find_nodes)"),name_pattern:e.string().optional().describe("Name substring match (for find_nodes)"),source_path:e.string().optional().describe("Source path filter"),node_id:e.string().optional().describe("Node ID (for neighbors, traverse, delete)"),edge_type:e.string().optional().describe("Edge type filter"),from_id:e.string().optional().describe("Source node ID (for find_edges)"),to_id:e.string().optional().describe("Target node ID (for find_edges)"),direction:e.enum(["outgoing","incoming","both"]).default("both").describe("Traversal direction"),max_depth:e.number().min(1).max(5).default(2).describe("Max traversal depth"),limit:e.number().min(1).max(100).default(50).describe("Max results"),nodes:e.array(p).optional().describe("Nodes to add (for action=add)"),edges:e.array(c).optional().describe("Edges to add (for action=add)")}},async t=>{try{const r=await a(s,{action:t.action,nodeType:t.node_type,namePattern:t.name_pattern,sourcePath:t.source_path,nodeId:t.node_id,edgeType:t.edge_type,fromId:t.from_id,toId:t.to_id,direction:t.direction,maxDepth:t.max_depth,limit:t.limit,nodes:t.nodes,edges:t.edges}),i=[r.summary];if(r.nodes&&r.nodes.length>0){i.push(`
2
+ ### Nodes`);for(const o of r.nodes){const d=Object.keys(o.properties).length>0?` \u2014 ${JSON.stringify(o.properties)}`:"";i.push(`- **${o.name}** (${o.type}, id: \`${o.id}\`)${d}`)}}if(r.edges&&r.edges.length>0){i.push(`
3
+ ### Edges`);for(const o of r.edges)i.push(`- \`${o.fromId}\` \u2014[${o.type}]\u2192 \`${o.toId}\`${o.weight!==1?` (weight: ${o.weight})`:""}`)}return r.stats&&(i.push(`
4
+ Node types: ${JSON.stringify(r.stats.nodeTypes)}`),i.push(`Edge types: ${JSON.stringify(r.stats.edgeTypes)}`)),i.push("\n---\n_Next: Use `graph(traverse)` to explore connections, `graph(add)` to insert entities, or `search` with graph-augmented results._"),{content:[{type:"text",text:i.join(`
5
+ `)}]}}catch(r){return console.error("[KB] Graph query failed:",r),{content:[{type:"text",text:`Graph query failed: ${r.message}`}],isError:!0}}})}export{h as registerGraphTool};
@@ -1,56 +1,8 @@
1
- import { z } from "zod";
2
- function registerListTool(server, curated) {
3
- server.registerTool(
4
- "list",
5
- {
6
- description: "List curated knowledge entries. Optionally filter by category or tag.",
7
- inputSchema: {
8
- category: z.string().optional().describe('Filter by category (e.g., "decisions", "patterns")'),
9
- tag: z.string().optional().describe("Filter by tag")
10
- }
11
- },
12
- async ({ category, tag }) => {
13
- try {
14
- const entries = await curated.list({ category, tag });
15
- if (entries.length === 0) {
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: "No curated knowledge entries found." + (category ? ` (category: ${category})` : "") + (tag ? ` (tag: ${tag})` : "")
21
- }
22
- ]
23
- };
24
- }
25
- const formatted = entries.map((e) => {
26
- const tags = e.tags.length > 0 ? ` [${e.tags.join(", ")}]` : "";
27
- return `- **${e.title}** (v${e.version})${tags}
28
- \`${e.path}\` \u2014 ${e.contentPreview.slice(0, 80)}\u2026`;
29
- }).join("\n");
30
- return {
31
- content: [
32
- {
33
- type: "text",
34
- text: `## Curated Knowledge (${entries.length} entries)
1
+ import{z as o}from"zod";function g(s,i){s.registerTool("list",{description:"List curated knowledge entries. Optionally filter by category or tag.",inputSchema:{category:o.string().optional().describe('Filter by category (e.g., "decisions", "patterns")'),tag:o.string().optional().describe("Filter by tag")}},async({category:r,tag:n})=>{try{const t=await i.list({category:r,tag:n});if(t.length===0)return{content:[{type:"text",text:"No curated knowledge entries found."+(r?` (category: ${r})`:"")+(n?` (tag: ${n})`:"")}]};const a=t.map(e=>{const c=e.tags.length>0?` [${e.tags.join(", ")}]`:"";return`- **${e.title}** (v${e.version})${c}
2
+ \`${e.path}\` \u2014 ${e.contentPreview.slice(0,80)}\u2026`}).join(`
3
+ `);return{content:[{type:"text",text:`## Curated Knowledge (${t.length} entries)
35
4
 
36
- ${formatted}
5
+ ${a}
37
6
 
38
7
  ---
39
- _Next: Use \`read\` to view full content of any entry, or \`remember\` to store new knowledge._`
40
- }
41
- ]
42
- };
43
- } catch (err) {
44
- console.error("[KB] List failed:", err);
45
- return {
46
- content: [{ type: "text", text: `List failed: ${err.message}` }],
47
- isError: true
48
- };
49
- }
50
- }
51
- );
52
- }
53
- export {
54
- registerListTool
55
- };
56
- //# sourceMappingURL=list.tool.js.map
8
+ _Next: Use \`read\` to view full content of any entry, or \`remember\` to store new knowledge._`}]}}catch(t){return console.error("[KB] List failed:",t),{content:[{type:"text",text:`List failed: ${t.message}`}],isError:!0}}})}export{g as registerListTool};
@@ -1,53 +1,10 @@
1
- import { z } from "zod";
2
- function registerLookupTool(server, store) {
3
- server.registerTool(
4
- "lookup",
5
- {
6
- description: "Look up all indexed chunks for a specific file path. Returns all chunks sorted by position.",
7
- inputSchema: {
8
- path: z.string().describe('Relative file path to look up (e.g., "src/index.ts")')
9
- }
10
- },
11
- async ({ path }) => {
12
- try {
13
- const records = await store.getBySourcePath(path);
14
- if (records.length === 0) {
15
- return {
16
- content: [{ type: "text", text: `No indexed content found for: ${path}` }]
17
- };
18
- }
19
- records.sort((a, b) => a.chunkIndex - b.chunkIndex);
20
- const header = `## ${path}
21
- **Chunks**: ${records.length} | **Type**: ${records[0].contentType}
22
- `;
23
- const chunks = records.map((r) => {
24
- const lineInfo = r.startLine ? ` (lines ${r.startLine}-${r.endLine})` : "";
25
- return `### Chunk ${r.chunkIndex + 1}/${r.totalChunks}${lineInfo}
26
- ${r.content}`;
27
- }).join("\n\n");
28
- return {
29
- content: [
30
- {
31
- type: "text",
32
- text: `${header}
33
- ${chunks}
1
+ import{z as p}from"zod";function d(r,s){r.registerTool("lookup",{description:"Look up all indexed chunks for a specific file path. Returns all chunks sorted by position.",inputSchema:{path:p.string().describe('Relative file path to look up (e.g., "src/index.ts")')}},async({path:n})=>{try{const e=await s.getBySourcePath(n);if(e.length===0)return{content:[{type:"text",text:`No indexed content found for: ${n}`}]};e.sort((t,o)=>t.chunkIndex-o.chunkIndex);const c=`## ${n}
2
+ **Chunks**: ${e.length} | **Type**: ${e[0].contentType}
3
+ `,i=e.map(t=>{const o=t.startLine?` (lines ${t.startLine}-${t.endLine})`:"";return`### Chunk ${t.chunkIndex+1}/${t.totalChunks}${o}
4
+ ${t.content}`}).join(`
5
+
6
+ `);return{content:[{type:"text",text:`${c}
7
+ ${i}
34
8
 
35
9
  ---
36
- _Next: Use \`search\` to find related content, or \`analyze_dependencies\` to see what this file imports._`
37
- }
38
- ]
39
- };
40
- } catch (err) {
41
- console.error("[KB] Lookup failed:", err);
42
- return {
43
- content: [{ type: "text", text: `Lookup failed: ${err.message}` }],
44
- isError: true
45
- };
46
- }
47
- }
48
- );
49
- }
50
- export {
51
- registerLookupTool
52
- };
53
- //# sourceMappingURL=lookup.tool.js.map
10
+ _Next: Use \`search\` to find related content, or \`analyze_dependencies\` to see what this file imports._`}]}}catch(e){return console.error("[KB] Lookup failed:",e),{content:[{type:"text",text:`Lookup failed: ${e.message}`}],isError:!0}}})}export{d as registerLookupTool};
@@ -1,112 +1,2 @@
1
- import { createHash } from "node:crypto";
2
- import { onboard } from "@kb/tools";
3
- import { z } from "zod";
4
- async function persistOnboardResults(store, embedder, result) {
5
- for (const step of result.steps) {
6
- if (step.status !== "success" || !step.output) continue;
7
- try {
8
- const pathHash = createHash("sha256").update(result.path).digest("hex").slice(0, 12);
9
- const sourcePath = `produced/onboard/${step.name}/${pathHash}.md`;
10
- const contentHash = createHash("sha256").update(step.output).digest("hex").slice(0, 16);
11
- const now = (/* @__PURE__ */ new Date()).toISOString();
12
- const sections = step.output.length > 2e3 ? step.output.split(/(?=^## )/m).filter((s) => s.trim().length > 0) : [step.output];
13
- const records = sections.map((text, i) => ({
14
- id: createHash("sha256").update(`${sourcePath}::${i}`).digest("hex").slice(0, 16),
15
- content: text.trim(),
16
- sourcePath,
17
- contentType: "produced-knowledge",
18
- chunkIndex: i,
19
- totalChunks: sections.length,
20
- startLine: 0,
21
- endLine: 0,
22
- fileHash: contentHash,
23
- indexedAt: now,
24
- origin: "produced",
25
- tags: ["onboard", step.name],
26
- category: "analysis",
27
- version: 1
28
- }));
29
- const vectors = await embedder.embedBatch(records.map((r) => r.content));
30
- await store.upsert(records, vectors);
31
- } catch (err) {
32
- console.error(`[KB] Auto-persist onboard/${step.name} failed:`, err);
33
- }
34
- }
35
- }
36
- function registerOnboardTool(server, store, embedder) {
37
- server.registerTool(
38
- "onboard",
39
- {
40
- description: "First-time codebase onboarding: runs all analysis tools (structure, dependencies, entry-points, symbols, patterns, diagram) in one command. Results are auto-persisted to KB. Use mode=generate to also write structured output to .ai/kb/ directory.",
41
- inputSchema: {
42
- path: z.string().describe("Root path of the codebase to onboard"),
43
- mode: z.enum(["memory", "generate"]).default("memory").describe(
44
- "Output mode: memory = KB vector store only; generate = also write to .ai/kb/ directory"
45
- ),
46
- out_dir: z.string().optional().describe("Custom output directory for generate mode (default: <path>/.ai/kb)")
47
- }
48
- },
49
- async ({ path, mode, out_dir }) => {
50
- try {
51
- console.error(`[KB] Starting onboard for: ${path} (mode: ${mode})`);
52
- const result = await onboard({
53
- path,
54
- mode,
55
- outDir: out_dir
56
- });
57
- persistOnboardResults(store, embedder, result);
58
- const lines = [
59
- "## Onboard Complete",
60
- "",
61
- `**Path:** \`${result.path}\``,
62
- `**Mode:** ${result.mode}`,
63
- `**Duration:** ${result.totalDurationMs}ms`,
64
- ""
65
- ];
66
- if (result.outDir) {
67
- lines.push(`**Output directory:** \`${result.outDir}\``);
68
- lines.push("");
69
- }
70
- lines.push("### Analysis Results", "");
71
- const successSteps = [];
72
- const failedSteps = [];
73
- for (const step of result.steps) {
74
- if (step.status === "success") {
75
- successSteps.push(
76
- `- \u2713 **${step.name}** (${step.durationMs}ms) \u2014 ${step.output.length} chars`
77
- );
78
- } else {
79
- failedSteps.push(`- \u2717 **${step.name}** \u2014 ${step.error}`);
80
- }
81
- }
82
- lines.push(...successSteps);
83
- if (failedSteps.length > 0) {
84
- lines.push("", "### Failed", "", ...failedSteps);
85
- }
86
- lines.push("", "---", "");
87
- for (const step of result.steps) {
88
- if (step.status !== "success") continue;
89
- lines.push(`### ${step.name}`, "", step.output, "", "---", "");
90
- }
91
- lines.push(
92
- "_All results auto-saved to KB.",
93
- result.mode === "generate" ? ` Files written to \`${result.outDir}\`.` : "",
94
- " Next: Use `search` to query the knowledge, or `remember` to add custom insights._"
95
- );
96
- return {
97
- content: [{ type: "text", text: lines.join("\n") }]
98
- };
99
- } catch (err) {
100
- console.error("[KB] Onboard failed:", err);
101
- return {
102
- content: [{ type: "text", text: `Onboard failed: ${err.message}` }],
103
- isError: true
104
- };
105
- }
106
- }
107
- );
108
- }
109
- export {
110
- registerOnboardTool
111
- };
112
- //# sourceMappingURL=onboard.tool.js.map
1
+ import{createHash as m}from"node:crypto";import{onboard as g}from"@kb/tools";import{z as l}from"zod";async function b(c,p,d){for(const t of d.steps)if(!(t.status!=="success"||!t.output))try{const s=m("sha256").update(d.path).digest("hex").slice(0,12),u=`produced/onboard/${t.name}/${s}.md`,e=m("sha256").update(t.output).digest("hex").slice(0,16),r=new Date().toISOString(),a=t.output.length>2e3?t.output.split(/(?=^## )/m).filter(i=>i.trim().length>0):[t.output],n=a.map((i,h)=>({id:m("sha256").update(`${u}::${h}`).digest("hex").slice(0,16),content:i.trim(),sourcePath:u,contentType:"produced-knowledge",chunkIndex:h,totalChunks:a.length,startLine:0,endLine:0,fileHash:e,indexedAt:r,origin:"produced",tags:["onboard",t.name],category:"analysis",version:1})),o=await p.embedBatch(n.map(i=>i.content));await c.upsert(n,o)}catch(s){console.error(`[KB] Auto-persist onboard/${t.name} failed:`,s)}}function w(c,p,d){c.registerTool("onboard",{description:"First-time codebase onboarding: runs all analysis tools (structure, dependencies, entry-points, symbols, patterns, diagram) in one command. Results are auto-persisted to KB. Use mode=generate to also write structured output to .ai/kb/ directory.",inputSchema:{path:l.string().describe("Root path of the codebase to onboard"),mode:l.enum(["memory","generate"]).default("memory").describe("Output mode: memory = KB vector store only; generate = also write to .ai/kb/ directory"),out_dir:l.string().optional().describe("Custom output directory for generate mode (default: <path>/.ai/kb)")}},async({path:t,mode:s,out_dir:u})=>{try{console.error(`[KB] Starting onboard for: ${t} (mode: ${s})`);const e=await g({path:t,mode:s,outDir:u});b(p,d,e);const r=["## Onboard Complete","",`**Path:** \`${e.path}\``,`**Mode:** ${e.mode}`,`**Duration:** ${e.totalDurationMs}ms`,""];e.outDir&&(r.push(`**Output directory:** \`${e.outDir}\``),r.push("")),r.push("### Analysis Results","");const a=[],n=[];for(const o of e.steps)o.status==="success"?a.push(`- \u2713 **${o.name}** (${o.durationMs}ms) \u2014 ${o.output.length} chars`):n.push(`- \u2717 **${o.name}** \u2014 ${o.error}`);r.push(...a),n.length>0&&r.push("","### Failed","",...n),r.push("","---","");for(const o of e.steps)o.status==="success"&&r.push(`### ${o.name}`,"",o.output,"","---","");return r.push("_All results auto-saved to KB.",e.mode==="generate"?` Files written to \`${e.outDir}\`.`:""," Next: Use `search` to query the knowledge, or `remember` to add custom insights._"),{content:[{type:"text",text:r.join(`
2
+ `)}]}}catch(e){return console.error("[KB] Onboard failed:",e),{content:[{type:"text",text:`Onboard failed: ${e.message}`}],isError:!0}}})}export{w as registerOnboardTool};
@@ -1,74 +1,4 @@
1
- import {
2
- DependencyAnalyzer,
3
- DiagramGenerator,
4
- EntryPointAnalyzer,
5
- KnowledgeProducer,
6
- PatternAnalyzer,
7
- StructureAnalyzer,
8
- SymbolAnalyzer
9
- } from "@kb/analyzers";
10
- import { z } from "zod";
11
- function registerProduceKnowledgeTool(server) {
12
- const analyzers = {
13
- structure: new StructureAnalyzer(),
14
- dependencies: new DependencyAnalyzer(),
15
- symbols: new SymbolAnalyzer(),
16
- patterns: new PatternAnalyzer(),
17
- entryPoints: new EntryPointAnalyzer(),
18
- diagrams: new DiagramGenerator()
19
- };
20
- const producer = new KnowledgeProducer(analyzers);
21
- server.registerTool(
22
- "produce_knowledge",
23
- {
24
- description: "Run automated codebase analysis and produce synthesis instructions. Executes Tier 1 deterministic analyzers, then returns structured baselines and instructions for you to synthesize knowledge using remember.",
25
- inputSchema: {
26
- scope: z.string().optional().describe("Root path to analyze (defaults to workspace root)"),
27
- aspects: z.array(
28
- z.enum([
29
- "all",
30
- "structure",
31
- "dependencies",
32
- "symbols",
33
- "patterns",
34
- "entry-points",
35
- "diagrams"
36
- ])
37
- ).default(["all"]).describe("Which analysis aspects to run")
38
- }
39
- },
40
- async ({ scope, aspects }) => {
41
- try {
42
- const rootPath = scope ?? ".";
43
- console.error(
44
- `[KB] Running knowledge production for: ${rootPath}, aspects: ${aspects.join(", ")}`
45
- );
46
- const baselines = await producer.runExtraction(rootPath, aspects);
47
- const instructions = producer.buildSynthesisInstructions(baselines, aspects);
48
- return {
49
- content: [
50
- {
51
- type: "text",
52
- text: instructions + "\n\n---\n_Next: Review the baselines above and use `remember` to store synthesized knowledge entries._"
53
- }
54
- ]
55
- };
56
- } catch (err) {
57
- console.error("[KB] Knowledge production failed:", err);
58
- return {
59
- content: [
60
- {
61
- type: "text",
62
- text: `Knowledge production failed: ${err.message}`
63
- }
64
- ],
65
- isError: true
66
- };
67
- }
68
- }
69
- );
70
- }
71
- export {
72
- registerProduceKnowledgeTool
73
- };
74
- //# sourceMappingURL=produce.tool.js.map
1
+ import{DependencyAnalyzer as c,DiagramGenerator as d,EntryPointAnalyzer as l,KnowledgeProducer as u,PatternAnalyzer as p,StructureAnalyzer as y,SymbolAnalyzer as m}from"@kb/analyzers";import{z as n}from"zod";function h(o){const s={structure:new y,dependencies:new c,symbols:new m,patterns:new p,entryPoints:new l,diagrams:new d},r=new u(s);o.registerTool("produce_knowledge",{description:"Run automated codebase analysis and produce synthesis instructions. Executes Tier 1 deterministic analyzers, then returns structured baselines and instructions for you to synthesize knowledge using remember.",inputSchema:{scope:n.string().optional().describe("Root path to analyze (defaults to workspace root)"),aspects:n.array(n.enum(["all","structure","dependencies","symbols","patterns","entry-points","diagrams"])).default(["all"]).describe("Which analysis aspects to run")}},async({scope:i,aspects:t})=>{try{const e=i??".";console.error(`[KB] Running knowledge production for: ${e}, aspects: ${t.join(", ")}`);const a=await r.runExtraction(e,t);return{content:[{type:"text",text:r.buildSynthesisInstructions(a,t)+`
2
+
3
+ ---
4
+ _Next: Review the baselines above and use \`remember\` to store synthesized knowledge entries._`}]}}catch(e){return console.error("[KB] Knowledge production failed:",e),{content:[{type:"text",text:`Knowledge production failed: ${e.message}`}],isError:!0}}})}export{h as registerProduceKnowledgeTool};
@@ -1,49 +1,6 @@
1
- import { z } from "zod";
2
- function registerReadTool(server, curated) {
3
- server.registerTool(
4
- "read",
5
- {
6
- description: "Read the full content of a specific curated knowledge entry by its path. Use list first to discover available entries.",
7
- inputSchema: {
8
- path: z.string().describe('Relative path within curated/ (e.g., "decisions/use-lancedb.md")')
9
- }
10
- },
11
- async ({ path }) => {
12
- try {
13
- const entry = await curated.read(path);
14
- const meta = [
15
- `## ${entry.title}`,
16
- `- **Path**: curated/${path}`,
17
- `- **Category**: ${entry.category}`,
18
- entry.tags.length ? `- **Tags**: ${entry.tags.join(", ")}` : null,
19
- `- **Version**: ${entry.version}`,
20
- `- **Created**: ${entry.created}`,
21
- entry.updated !== entry.created ? `- **Updated**: ${entry.updated}` : null,
22
- ""
23
- ].filter((l) => l !== null).join("\n");
24
- return {
25
- content: [
26
- {
27
- type: "text",
28
- text: `${meta}
29
- ${entry.content}
1
+ import{z as o}from"zod";function i(r,a){r.registerTool("read",{description:"Read the full content of a specific curated knowledge entry by its path. Use list first to discover available entries.",inputSchema:{path:o.string().describe('Relative path within curated/ (e.g., "decisions/use-lancedb.md")')}},async({path:t})=>{try{const e=await a.read(t);return{content:[{type:"text",text:`${[`## ${e.title}`,`- **Path**: curated/${t}`,`- **Category**: ${e.category}`,e.tags.length?`- **Tags**: ${e.tags.join(", ")}`:null,`- **Version**: ${e.version}`,`- **Created**: ${e.created}`,e.updated!==e.created?`- **Updated**: ${e.updated}`:null,""].filter(n=>n!==null).join(`
2
+ `)}
3
+ ${e.content}
30
4
 
31
5
  ---
32
- _Next: Use \`update\` to modify this entry, or \`search\` to find related entries._`
33
- }
34
- ]
35
- };
36
- } catch (err) {
37
- console.error("[KB] Read failed:", err);
38
- return {
39
- content: [{ type: "text", text: `Read failed: ${err.message}` }],
40
- isError: true
41
- };
42
- }
43
- }
44
- );
45
- }
46
- export {
47
- registerReadTool
48
- };
49
- //# sourceMappingURL=read.tool.js.map
6
+ _Next: Use \`update\` to modify this entry, or \`search\` to find related entries._`}]}}catch(e){return console.error("[KB] Read failed:",e),{content:[{type:"text",text:`Read failed: ${e.message}`}],isError:!0}}})}export{i as registerReadTool};
@@ -1,70 +1,2 @@
1
- import { z } from "zod";
2
- function registerReindexTool(server, indexer, config, curated, store) {
3
- server.registerTool(
4
- "reindex",
5
- {
6
- description: "Trigger re-indexing of the knowledge base. Can do incremental (only changed files) or full re-index.",
7
- inputSchema: {
8
- full: z.boolean().default(false).describe("If true, force full re-index ignoring file hashes")
9
- }
10
- },
11
- async ({ full }) => {
12
- try {
13
- console.error(`[KB] Starting ${full ? "full" : "incremental"} re-index...`);
14
- const logProgress = (prefix) => (p) => {
15
- if (p.phase === "chunking" && p.currentFile) {
16
- console.error(
17
- `[KB] ${prefix} [${p.filesProcessed + 1}/${p.filesTotal}] ${p.currentFile}`
18
- );
19
- }
20
- };
21
- const result = full ? await indexer.reindexAll(config, logProgress("Reindex")) : await indexer.index(config, logProgress("Index"));
22
- const text = [
23
- "## Re-index Complete",
24
- "",
25
- `- **Files Processed**: ${result.filesProcessed}`,
26
- `- **Files Skipped** (unchanged): ${result.filesSkipped}`,
27
- `- **Chunks Created**: ${result.chunksCreated}`,
28
- `- **Files Removed**: ${result.filesRemoved}`,
29
- `- **Duration**: ${(result.durationMs / 1e3).toFixed(1)}s`
30
- ];
31
- if (store) {
32
- try {
33
- await store.createFtsIndex();
34
- } catch (ftsErr) {
35
- text.push("", `- **FTS Index Failed**: ${ftsErr.message}`);
36
- }
37
- }
38
- try {
39
- const curatedResult = await curated.reindexAll();
40
- text.push("", `- **Curated Entries Re-indexed**: ${curatedResult.indexed}`);
41
- if (curatedResult.errors.length > 0) {
42
- text.push(`- **Curated Errors**: ${curatedResult.errors.length}`);
43
- }
44
- console.error(`[KB] Curated re-index: ${curatedResult.indexed} entries`);
45
- } catch (curatedErr) {
46
- text.push("", `- **Curated Re-index Failed**: ${curatedErr.message}`);
47
- console.error("[KB] Curated re-index failed:", curatedErr);
48
- }
49
- return {
50
- content: [
51
- {
52
- type: "text",
53
- text: text.join("\n") + "\n\n---\n_Next: Use `search` to query the refreshed index, or `status` to verify index stats._"
54
- }
55
- ]
56
- };
57
- } catch (err) {
58
- console.error("[KB] Reindex failed:", err);
59
- return {
60
- content: [{ type: "text", text: `Reindex failed: ${err.message}` }],
61
- isError: true
62
- };
63
- }
64
- }
65
- );
66
- }
67
- export {
68
- registerReindexTool
69
- };
70
- //# sourceMappingURL=reindex.tool.js.map
1
+ import{z as u}from"zod";function f(l,s,i,c,d){l.registerTool("reindex",{description:"Trigger re-indexing of the knowledge base. Can do incremental (only changed files) or full re-index.",inputSchema:{full:u.boolean().default(!1).describe("If true, force full re-index ignoring file hashes")}},async({full:a})=>{try{console.error(`[KB] Starting ${a?"full":"incremental"} re-index...`);const r=e=>o=>{o.phase==="chunking"&&o.currentFile&&console.error(`[KB] ${e} [${o.filesProcessed+1}/${o.filesTotal}] ${o.currentFile}`)},t=a?await s.reindexAll(i,r("Reindex")):await s.index(i,r("Index")),n=["## Re-index Complete","",`- **Files Processed**: ${t.filesProcessed}`,`- **Files Skipped** (unchanged): ${t.filesSkipped}`,`- **Chunks Created**: ${t.chunksCreated}`,`- **Files Removed**: ${t.filesRemoved}`,`- **Duration**: ${(t.durationMs/1e3).toFixed(1)}s`];if(d)try{await d.createFtsIndex()}catch(e){n.push("",`- **FTS Index Failed**: ${e.message}`)}try{const e=await c.reindexAll();n.push("",`- **Curated Entries Re-indexed**: ${e.indexed}`),e.errors.length>0&&n.push(`- **Curated Errors**: ${e.errors.length}`),console.error(`[KB] Curated re-index: ${e.indexed} entries`)}catch(e){n.push("",`- **Curated Re-index Failed**: ${e.message}`),console.error("[KB] Curated re-index failed:",e)}return{content:[{type:"text",text:n.join(`
2
+ `)+"\n\n---\n_Next: Use `search` to query the refreshed index, or `status` to verify index stats._"}]}}catch(r){return console.error("[KB] Reindex failed:",r),{content:[{type:"text",text:`Reindex failed: ${r.message}`}],isError:!0}}})}export{f as registerReindexTool};
@@ -1,45 +1,6 @@
1
- import { z } from "zod";
2
- function registerRememberTool(server, curated) {
3
- server.registerTool(
4
- "remember",
5
- {
6
- description: "Store a new piece of curated knowledge. Use this to persist decisions, patterns, conventions, or any insight worth remembering across sessions.",
7
- inputSchema: {
8
- title: z.string().min(3).max(120).describe("Short descriptive title for the knowledge entry"),
9
- content: z.string().min(10).describe("The markdown content to store"),
10
- category: z.string().regex(/^[a-z][a-z0-9-]*$/).describe(
11
- 'Category slug (e.g., "decisions", "patterns", "conventions", "api-contracts")'
12
- ),
13
- tags: z.array(z.string()).default([]).describe("Optional tags for filtering")
14
- }
15
- },
16
- async ({ title, content, category, tags }) => {
17
- try {
18
- const result = await curated.remember(title, content, category, tags);
19
- return {
20
- content: [
21
- {
22
- type: "text",
23
- text: `Remembered: **${title}**
1
+ import{z as e}from"zod";function d(n,o){n.registerTool("remember",{description:"Store a new piece of curated knowledge. Use this to persist decisions, patterns, conventions, or any insight worth remembering across sessions.",inputSchema:{title:e.string().min(3).max(120).describe("Short descriptive title for the knowledge entry"),content:e.string().min(10).describe("The markdown content to store"),category:e.string().regex(/^[a-z][a-z0-9-]*$/).describe('Category slug (e.g., "decisions", "patterns", "conventions", "api-contracts")'),tags:e.array(e.string()).default([]).describe("Optional tags for filtering")}},async({title:t,content:s,category:i,tags:a})=>{try{const r=await o.remember(t,s,i,a);return{content:[{type:"text",text:`Remembered: **${t}**
24
2
 
25
- Stored at \`curated/${result.path}\` and indexed for semantic search.
3
+ Stored at \`curated/${r.path}\` and indexed for semantic search.
26
4
 
27
5
  ---
28
- _Next: Use \`search\` to verify the entry is findable, or \`list\` to see all curated entries._`
29
- }
30
- ]
31
- };
32
- } catch (err) {
33
- console.error("[KB] Remember failed:", err);
34
- return {
35
- content: [{ type: "text", text: `Remember failed: ${err.message}` }],
36
- isError: true
37
- };
38
- }
39
- }
40
- );
41
- }
42
- export {
43
- registerRememberTool
44
- };
45
- //# sourceMappingURL=remember.tool.js.map
6
+ _Next: Use \`search\` to verify the entry is findable, or \`list\` to see all curated entries._`}]}}catch(r){return console.error("[KB] Remember failed:",r),{content:[{type:"text",text:`Remember failed: ${r.message}`}],isError:!0}}})}export{d as registerRememberTool};