kirograph 0.27.1 → 0.28.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.
Files changed (222) hide show
  1. package/README.md +35 -2
  2. package/dist/bin/commands/annotations.js +56 -0
  3. package/dist/bin/commands/annotations.js.map +7 -0
  4. package/dist/bin/commands/ast-rewrite.js +55 -0
  5. package/dist/bin/commands/ast-rewrite.js.map +7 -0
  6. package/dist/bin/commands/bench.js +103 -0
  7. package/dist/bin/commands/bench.js.map +7 -0
  8. package/dist/bin/commands/branch.js +133 -0
  9. package/dist/bin/commands/branch.js.map +7 -0
  10. package/dist/bin/commands/callees.js +76 -0
  11. package/dist/bin/commands/callees.js.map +7 -0
  12. package/dist/bin/commands/callers.js +76 -0
  13. package/dist/bin/commands/callers.js.map +7 -0
  14. package/dist/bin/commands/changelog.js +55 -0
  15. package/dist/bin/commands/changelog.js.map +7 -0
  16. package/dist/bin/commands/circular-deps.js +68 -0
  17. package/dist/bin/commands/circular-deps.js.map +7 -0
  18. package/dist/bin/commands/commit-context.js +55 -0
  19. package/dist/bin/commands/commit-context.js.map +7 -0
  20. package/dist/bin/commands/complexity.js +60 -0
  21. package/dist/bin/commands/complexity.js.map +7 -0
  22. package/dist/bin/commands/cost.js +146 -0
  23. package/dist/bin/commands/cost.js.map +7 -0
  24. package/dist/bin/commands/dependency-depth.js +55 -0
  25. package/dist/bin/commands/dependency-depth.js.map +7 -0
  26. package/dist/bin/commands/diff-context.js +55 -0
  27. package/dist/bin/commands/diff-context.js.map +7 -0
  28. package/dist/bin/commands/distribution.js +56 -0
  29. package/dist/bin/commands/distribution.js.map +7 -0
  30. package/dist/bin/commands/doc-coverage.js +56 -0
  31. package/dist/bin/commands/doc-coverage.js.map +7 -0
  32. package/dist/bin/commands/doctor.js +202 -0
  33. package/dist/bin/commands/doctor.js.map +7 -0
  34. package/dist/bin/commands/dsm.js +56 -0
  35. package/dist/bin/commands/dsm.js.map +7 -0
  36. package/dist/bin/commands/gini.js +55 -0
  37. package/dist/bin/commands/gini.js.map +7 -0
  38. package/dist/bin/commands/god-class.js +56 -0
  39. package/dist/bin/commands/god-class.js.map +7 -0
  40. package/dist/bin/commands/health.js +55 -0
  41. package/dist/bin/commands/health.js.map +7 -0
  42. package/dist/bin/commands/help.js +224 -45
  43. package/dist/bin/commands/help.js.map +2 -2
  44. package/dist/bin/commands/impact.js +76 -0
  45. package/dist/bin/commands/impact.js.map +7 -0
  46. package/dist/bin/commands/inheritance-depth.js +56 -0
  47. package/dist/bin/commands/inheritance-depth.js.map +7 -0
  48. package/dist/bin/commands/insert-at.js +55 -0
  49. package/dist/bin/commands/insert-at.js.map +7 -0
  50. package/dist/bin/commands/largest.js +56 -0
  51. package/dist/bin/commands/largest.js.map +7 -0
  52. package/dist/bin/commands/manifest.js +158 -0
  53. package/dist/bin/commands/manifest.js.map +7 -0
  54. package/dist/bin/commands/module-api.js +57 -0
  55. package/dist/bin/commands/module-api.js.map +7 -0
  56. package/dist/bin/commands/monitor.js +91 -0
  57. package/dist/bin/commands/monitor.js.map +7 -0
  58. package/dist/bin/commands/multi-replace.js +66 -0
  59. package/dist/bin/commands/multi-replace.js.map +7 -0
  60. package/dist/bin/commands/pr-context.js +55 -0
  61. package/dist/bin/commands/pr-context.js.map +7 -0
  62. package/dist/bin/commands/query.js +19 -1
  63. package/dist/bin/commands/query.js.map +3 -3
  64. package/dist/bin/commands/rank.js +56 -0
  65. package/dist/bin/commands/rank.js.map +7 -0
  66. package/dist/bin/commands/read.js +1 -1
  67. package/dist/bin/commands/read.js.map +2 -2
  68. package/dist/bin/commands/recursion.js +56 -0
  69. package/dist/bin/commands/recursion.js.map +7 -0
  70. package/dist/bin/commands/rename-preview.js +56 -0
  71. package/dist/bin/commands/rename-preview.js.map +7 -0
  72. package/dist/bin/commands/session.js +60 -0
  73. package/dist/bin/commands/session.js.map +7 -0
  74. package/dist/bin/commands/simplify-scan.js +56 -0
  75. package/dist/bin/commands/simplify-scan.js.map +7 -0
  76. package/dist/bin/commands/str-replace.js +55 -0
  77. package/dist/bin/commands/str-replace.js.map +7 -0
  78. package/dist/bin/commands/test-coverage.js +59 -0
  79. package/dist/bin/commands/test-coverage.js.map +7 -0
  80. package/dist/bin/commands/test-map.js +56 -0
  81. package/dist/bin/commands/test-map.js.map +7 -0
  82. package/dist/bin/commands/test-risk.js +59 -0
  83. package/dist/bin/commands/test-risk.js.map +7 -0
  84. package/dist/bin/commands/type-hierarchy.js +76 -0
  85. package/dist/bin/commands/type-hierarchy.js.map +7 -0
  86. package/dist/bin/commands/unused-imports.js +55 -0
  87. package/dist/bin/commands/unused-imports.js.map +7 -0
  88. package/dist/bin/commands/upgrade.js +78 -0
  89. package/dist/bin/commands/upgrade.js.map +7 -0
  90. package/dist/bin/installer/common.js +19 -9
  91. package/dist/bin/installer/common.js.map +2 -2
  92. package/dist/bin/installer/config-prompt.js +147 -12
  93. package/dist/bin/installer/config-prompt.js.map +3 -3
  94. package/dist/bin/installer/index.js +62 -6
  95. package/dist/bin/installer/index.js.map +2 -2
  96. package/dist/bin/installer/instructions.js +14 -25
  97. package/dist/bin/installer/instructions.js.map +2 -2
  98. package/dist/bin/installer/mcp.js.map +2 -2
  99. package/dist/bin/installer/steering.js +569 -100
  100. package/dist/bin/installer/steering.js.map +2 -2
  101. package/dist/bin/installer/targets/aider.js +3 -3
  102. package/dist/bin/installer/targets/aider.js.map +2 -2
  103. package/dist/bin/installer/targets/amp.js +3 -3
  104. package/dist/bin/installer/targets/amp.js.map +2 -2
  105. package/dist/bin/installer/targets/antigravity.js +4 -4
  106. package/dist/bin/installer/targets/antigravity.js.map +2 -2
  107. package/dist/bin/installer/targets/augment.js +3 -3
  108. package/dist/bin/installer/targets/augment.js.map +2 -2
  109. package/dist/bin/installer/targets/claude.js +3 -3
  110. package/dist/bin/installer/targets/claude.js.map +2 -2
  111. package/dist/bin/installer/targets/cline.js +4 -4
  112. package/dist/bin/installer/targets/cline.js.map +2 -2
  113. package/dist/bin/installer/targets/codex.js +4 -4
  114. package/dist/bin/installer/targets/codex.js.map +2 -2
  115. package/dist/bin/installer/targets/continue.js +4 -4
  116. package/dist/bin/installer/targets/continue.js.map +2 -2
  117. package/dist/bin/installer/targets/copilot-cli.js +4 -4
  118. package/dist/bin/installer/targets/copilot-cli.js.map +2 -2
  119. package/dist/bin/installer/targets/copilot.js +4 -4
  120. package/dist/bin/installer/targets/copilot.js.map +2 -2
  121. package/dist/bin/installer/targets/cursor.js +5 -5
  122. package/dist/bin/installer/targets/cursor.js.map +2 -2
  123. package/dist/bin/installer/targets/devin.js +4 -4
  124. package/dist/bin/installer/targets/devin.js.map +2 -2
  125. package/dist/bin/installer/targets/gemini-cli.js +4 -4
  126. package/dist/bin/installer/targets/gemini-cli.js.map +2 -2
  127. package/dist/bin/installer/targets/generic.js +2 -2
  128. package/dist/bin/installer/targets/generic.js.map +2 -2
  129. package/dist/bin/installer/targets/goose.js +3 -4
  130. package/dist/bin/installer/targets/goose.js.map +3 -3
  131. package/dist/bin/installer/targets/index.js.map +1 -1
  132. package/dist/bin/installer/targets/junie.js +4 -4
  133. package/dist/bin/installer/targets/junie.js.map +2 -2
  134. package/dist/bin/installer/targets/kilo.js +4 -4
  135. package/dist/bin/installer/targets/kilo.js.map +2 -2
  136. package/dist/bin/installer/targets/kiro.js +27 -3
  137. package/dist/bin/installer/targets/kiro.js.map +2 -2
  138. package/dist/bin/installer/targets/opencode.js +3 -3
  139. package/dist/bin/installer/targets/opencode.js.map +2 -2
  140. package/dist/bin/installer/targets/openhands.js +3 -3
  141. package/dist/bin/installer/targets/openhands.js.map +2 -2
  142. package/dist/bin/installer/targets/qoder.js +2 -2
  143. package/dist/bin/installer/targets/qoder.js.map +2 -2
  144. package/dist/bin/installer/targets/qwen.js +2 -2
  145. package/dist/bin/installer/targets/qwen.js.map +2 -2
  146. package/dist/bin/installer/targets/replit.js +3 -3
  147. package/dist/bin/installer/targets/replit.js.map +2 -2
  148. package/dist/bin/installer/targets/roo.js +4 -4
  149. package/dist/bin/installer/targets/roo.js.map +2 -2
  150. package/dist/bin/installer/targets/tabnine.js +3 -3
  151. package/dist/bin/installer/targets/tabnine.js.map +2 -2
  152. package/dist/bin/installer/targets/trae.js +3 -3
  153. package/dist/bin/installer/targets/trae.js.map +2 -2
  154. package/dist/bin/installer/targets/warp.js +4 -4
  155. package/dist/bin/installer/targets/warp.js.map +2 -2
  156. package/dist/bin/installer/targets/windsurf.js +4 -4
  157. package/dist/bin/installer/targets/windsurf.js.map +2 -2
  158. package/dist/bin/kirograph.js +83 -1
  159. package/dist/bin/kirograph.js.map +3 -3
  160. package/dist/config.js +30 -8
  161. package/dist/config.js.map +2 -2
  162. package/dist/core/branch-manager.js +111 -0
  163. package/dist/core/branch-manager.js.map +7 -0
  164. package/dist/core/pipeline.js +3 -3
  165. package/dist/core/pipeline.js.map +2 -2
  166. package/dist/data/pixelrag-bridge.js +93 -0
  167. package/dist/data/pixelrag-bridge.js.map +7 -0
  168. package/dist/data/pixelrag-manager.js +416 -0
  169. package/dist/data/pixelrag-manager.js.map +7 -0
  170. package/dist/db/database.js +34 -7
  171. package/dist/db/database.js.map +2 -2
  172. package/dist/db/schema.sql +7 -1
  173. package/dist/extraction/complexity.js +116 -0
  174. package/dist/extraction/complexity.js.map +7 -0
  175. package/dist/extraction/extractor.js +52 -1
  176. package/dist/extraction/extractor.js.map +2 -2
  177. package/dist/graph/git-context.js +229 -0
  178. package/dist/graph/git-context.js.map +7 -0
  179. package/dist/index.js +4 -2
  180. package/dist/index.js.map +2 -2
  181. package/dist/mcp/cache.js +1 -1
  182. package/dist/mcp/cache.js.map +2 -2
  183. package/dist/mcp/handler.js +446 -0
  184. package/dist/mcp/handler.js.map +7 -0
  185. package/dist/mcp/handlers/architecture.js +297 -0
  186. package/dist/mcp/handlers/architecture.js.map +7 -0
  187. package/dist/mcp/handlers/branch.js +175 -0
  188. package/dist/mcp/handlers/branch.js.map +7 -0
  189. package/dist/mcp/handlers/code-health.js +563 -0
  190. package/dist/mcp/handlers/code-health.js.map +7 -0
  191. package/dist/mcp/handlers/complexity.js +267 -0
  192. package/dist/mcp/handlers/complexity.js.map +7 -0
  193. package/dist/mcp/handlers/core.js +611 -0
  194. package/dist/mcp/handlers/core.js.map +7 -0
  195. package/dist/mcp/handlers/data.js +337 -0
  196. package/dist/mcp/handlers/data.js.map +7 -0
  197. package/dist/mcp/handlers/docs.js +159 -0
  198. package/dist/mcp/handlers/docs.js.map +7 -0
  199. package/dist/mcp/handlers/edit-primitives.js +200 -0
  200. package/dist/mcp/handlers/edit-primitives.js.map +7 -0
  201. package/dist/mcp/handlers/git-context.js +286 -0
  202. package/dist/mcp/handlers/git-context.js.map +7 -0
  203. package/dist/mcp/handlers/memory.js +363 -0
  204. package/dist/mcp/handlers/memory.js.map +7 -0
  205. package/dist/mcp/handlers/patterns.js +310 -0
  206. package/dist/mcp/handlers/patterns.js.map +7 -0
  207. package/dist/mcp/handlers/security.js +699 -0
  208. package/dist/mcp/handlers/security.js.map +7 -0
  209. package/dist/mcp/handlers/utils.js +97 -0
  210. package/dist/mcp/handlers/utils.js.map +7 -0
  211. package/dist/mcp/handlers/watchmen.js +104 -0
  212. package/dist/mcp/handlers/watchmen.js.map +7 -0
  213. package/dist/mcp/handlers/wiki.js +242 -0
  214. package/dist/mcp/handlers/wiki.js.map +7 -0
  215. package/dist/mcp/server.js +72 -3
  216. package/dist/mcp/server.js.map +2 -2
  217. package/dist/mcp/tool-names.js +136 -10
  218. package/dist/mcp/tool-names.js.map +2 -2
  219. package/dist/mcp/tools.js +846 -3019
  220. package/dist/mcp/tools.js.map +3 -3
  221. package/dist/types.js.map +2 -2
  222. package/package.json +36 -10
package/dist/index.js CHANGED
@@ -74,7 +74,7 @@ class KiroGraph {
74
74
  await kg.vectors.initialize(onModelProgress);
75
75
  return kg;
76
76
  }
77
- static async open(projectRoot, onModelProgress) {
77
+ static async open(projectRoot, onModelProgress, opts) {
78
78
  const resolved = path.resolve(projectRoot);
79
79
  (0, import_utils.validateProjectPath)(resolved);
80
80
  if (!fs.existsSync(path.join(resolved, KIROGRAPH_DIR))) {
@@ -83,7 +83,9 @@ class KiroGraph {
83
83
  const cfg = await (0, import_config.loadConfig)(resolved);
84
84
  const db = new import_database.GraphDatabase(resolved);
85
85
  const kg = new KiroGraph(resolved, db, cfg);
86
- await kg.vectors.initialize(onModelProgress);
86
+ if (!opts?.skipVectors) {
87
+ await kg.vectors.initialize(onModelProgress);
88
+ }
87
89
  return kg;
88
90
  }
89
91
  static isInitialized(projectRoot) {
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * KiroGraph \u2014 Semantic code knowledge graph for Kiro\n *\n * Pure facade. Every method delegates to a focused sub-system.\n * No business logic lives here.\n */\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { GraphDatabase } from './db/database';\nimport { validatePathWithinRoot, validateProjectPath } from './utils';\nimport { loadConfig, createDefaultConfig, saveConfig } from './config';\nimport type { KiroGraphConfig } from './config';\nimport { GraphQueryManager } from './graph/queries';\nimport { ReferenceResolver } from './resolution/index';\nimport { VectorManager } from './vectors/index';\nimport { ContextBuilder } from './context/index';\nimport { ArchitectureAnalyzer } from './architecture/index';\nimport { LockManager } from './core/lock-manager';\nimport { IndexPipeline } from './core/pipeline';\nimport { buildFileTree } from './core/file-tree';\nimport { SnapshotManager } from './core/snapshot';\nimport { Searcher } from './search/searcher';\nimport type { FileTreeNode, FileTree } from './core/file-tree';\nimport type { GraphSnapshot, GraphDiff } from './core/snapshot';\n\nexport type { GraphSnapshot, GraphDiff };\nimport type {\n Node, Edge, NodeKind, IndexResult, IndexProgress, SyncResult, TaskContext,\n SearchResult, SearchOptions, NodeContext, NodeMetrics,\n} from './types';\nimport type { ArchitectureResult } from './architecture/types';\n\nexport type { FileTreeNode, FileTree };\n\nconst KIROGRAPH_DIR = '.kirograph';\n\nexport default class KiroGraph {\n private readonly db: GraphDatabase;\n private readonly config: KiroGraphConfig;\n private readonly projectRoot: string;\n private readonly queryManager: GraphQueryManager;\n private readonly resolver: ReferenceResolver;\n private readonly vectors: VectorManager;\n private readonly contextBuilder: ContextBuilder;\n private readonly arch: ArchitectureAnalyzer;\n private readonly lock: LockManager;\n private readonly pipeline: IndexPipeline;\n private readonly searcher: Searcher;\n\n private constructor(projectRoot: string, db: GraphDatabase, config: KiroGraphConfig) {\n this.projectRoot = projectRoot;\n this.db = db;\n this.config = config;\n this.queryManager = new GraphQueryManager(db);\n this.resolver = new ReferenceResolver(db, config, projectRoot);\n this.vectors = new VectorManager(db, config, projectRoot);\n this.contextBuilder = new ContextBuilder(db, this.resolver, this.vectors, projectRoot);\n this.arch = new ArchitectureAnalyzer(db, config, projectRoot);\n this.lock = new LockManager(projectRoot);\n this.pipeline = new IndexPipeline(db, this.vectors, this.resolver, this.arch, this.lock, config, projectRoot);\n this.searcher = new Searcher(db);\n }\n\n // \u2500\u2500 Factory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n static async init(\n projectRoot: string,\n config?: Partial<KiroGraphConfig>,\n onModelProgress?: (file: string, loaded: number, total: number, done: boolean) => void,\n ): Promise<KiroGraph> {\n const resolved = path.resolve(projectRoot);\n validateProjectPath(resolved);\n fs.mkdirSync(path.join(resolved, KIROGRAPH_DIR), { recursive: true });\n const cfg = { ...createDefaultConfig(resolved), ...config };\n await saveConfig(resolved, cfg);\n const db = new GraphDatabase(resolved);\n const kg = new KiroGraph(resolved, db, cfg);\n await kg.vectors.initialize(onModelProgress);\n return kg;\n }\n\n static async open(\n projectRoot: string,\n onModelProgress?: (file: string, loaded: number, total: number, done: boolean) => void,\n ): Promise<KiroGraph> {\n const resolved = path.resolve(projectRoot);\n validateProjectPath(resolved);\n if (!fs.existsSync(path.join(resolved, KIROGRAPH_DIR))) {\n throw new Error(`KiroGraph not initialized at ${resolved}. Run: kirograph init`);\n }\n const cfg = await loadConfig(resolved);\n const db = new GraphDatabase(resolved);\n const kg = new KiroGraph(resolved, db, cfg);\n await kg.vectors.initialize(onModelProgress);\n return kg;\n }\n\n static isInitialized(projectRoot: string): boolean {\n return fs.existsSync(path.join(path.resolve(projectRoot), KIROGRAPH_DIR));\n }\n\n // \u2500\u2500 Lock / dirty marker \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n unlockForce(): void { this.lock.forceRelease(); }\n markDirty(): void { this.lock.markDirty(); }\n clearDirty(): void { this.lock.clearDirty(); }\n isDirty(): boolean { return this.lock.isDirty(); }\n isIndexLocked(): boolean { return this.lock.isLocked(); }\n\n async syncIfDirty(): Promise<SyncResult | null> {\n if (!this.isDirty()) return null;\n return this.sync();\n }\n\n /**\n * Returns the number of files that have changed on disk but are not yet\n * reflected in the index. Used by the MCP status tool to warn the agent\n * when the index may be stale.\n */\n async getPendingSyncCount(): Promise<number> {\n try {\n const { getChangedFiles, scanDirectory } = await Promise.resolve().then(() => require('./sync/index.js'));\n const gitChanged = await getChangedFiles(this.projectRoot, this.config);\n const hasGitChanges =\n gitChanged.added.length > 0 ||\n gitChanged.modified.length > 0 ||\n gitChanged.removed.length > 0;\n\n if (hasGitChanges) {\n return gitChanged.added.length + gitChanged.modified.length + gitChanged.removed.length;\n }\n\n // Fallback: compare indexed set vs current filesystem set\n const indexed = new Set(this.db.getAllFiles().map((f: { path: string }) => f.path));\n const current = new Set(\n (await scanDirectory(this.projectRoot, this.config))\n .map(f => require('path').relative(this.projectRoot, f).replace(/\\\\/g, '/'))\n );\n let pending = 0;\n for (const p of indexed) { if (!current.has(p)) pending++; }\n for (const p of current) { if (!indexed.has(p)) pending++; }\n return pending;\n } catch {\n return 0;\n }\n }\n\n // \u2500\u2500 Indexing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async indexAll(opts?: { onProgress?: (p: IndexProgress) => void; force?: boolean; signal?: AbortSignal }): Promise<IndexResult> {\n return this.pipeline.indexAll(opts);\n }\n\n async sync(changedFilesOrOpts?: string[] | { files?: string[]; onProgress?: (p: IndexProgress) => void }): Promise<SyncResult> {\n if (Array.isArray(changedFilesOrOpts)) {\n return this.pipeline.sync({ changedFiles: changedFilesOrOpts });\n }\n return this.pipeline.sync({\n changedFiles: changedFilesOrOpts?.files,\n onProgress: changedFilesOrOpts?.onProgress,\n });\n }\n\n // \u2500\u2500 Symbol search \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n searchNodes(query: string, kindOrOpts?: NodeKind | SearchOptions, limit = 20): SearchResult[] {\n return this.searcher.search(query, kindOrOpts, limit);\n }\n\n // \u2500\u2500 Graph queries \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getCallers(nodeId: string, limit = 30): Promise<Node[]> { return this.queryManager.getCallers(nodeId, limit); }\n async getCallees(nodeId: string, limit = 30): Promise<Node[]> { return this.queryManager.getCallees(nodeId, limit); }\n async getImpactRadius(nodeId: string, depth = 2): Promise<Node[]> { return this.queryManager.getImpactRadius(nodeId, depth); }\n getAllNodes(): Node[] { return this.db.getAllNodes(); }\n getAllEdges(): Edge[] { return this.db.getAllEdges(); }\n findDeadCode(limit = 50): Node[] { return this.db.findDeadCode(limit); }\n findCircularDependencies(): string[][] { return this.db.findCircularDependencies(); }\n async findPath(fromId: string, toId: string, maxDepth = 10): Promise<Node[]> { return this.queryManager.findPath(fromId, toId, maxDepth); }\n getTypeHierarchy(nodeId: string, direction: 'up' | 'down' | 'both' = 'both'): Node[] { return this.db.getTypeHierarchy(nodeId, direction); }\n getNode(id: string): Node | null { return this.db.getNode(id); }\n getNodeContext(nodeId: string): NodeContext | null { return this.db.getNodeContext(nodeId); }\n getNodeMetrics(nodeId: string): NodeMetrics { return this.db.getNodeMetrics(nodeId); }\n\n getNodeSource(node: Node): string | null {\n const absPath = validatePathWithinRoot(path.join(this.projectRoot, node.filePath), this.projectRoot);\n if (!absPath) return null;\n try {\n return fs.readFileSync(absPath, 'utf8').split('\\n').slice(node.startLine - 1, node.endLine).join('\\n');\n } catch { return null; }\n }\n\n // \u2500\u2500 Context building \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async buildContext(task: string, opts?: { maxNodes?: number; includeCode?: boolean }): Promise<TaskContext> {\n return this.contextBuilder.buildTaskContext(task, opts);\n }\n\n // \u2500\u2500 File browsing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getFiles(opts?: { filterPath?: string; pattern?: string; maxDepth?: number }): FileTree {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const picomatch = opts?.pattern ? require('picomatch')(opts.pattern) : null;\n const filtered = this.db.getAllFiles().filter(f => {\n if (opts?.filterPath && !f.path.startsWith(opts.filterPath)) return false;\n if (picomatch && !picomatch(f.path)) return false;\n return true;\n });\n return buildFileTree(filtered, opts?.maxDepth);\n }\n\n getAffectedTests(changedFiles: string[], opts?: { depth?: number; testPattern?: string }): string[] {\n return this.queryManager.getAffectedTests(changedFiles, opts);\n }\n\n // \u2500\u2500 Graph insights \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n findHotspots(limit = 20): Array<Node & { degree: number; inDegree: number; outDegree: number }> {\n return this.db.findHotspots(limit);\n }\n\n findSurprisingConnections(limit = 20): Array<{ source: Node; target: Node; kind: string; score: number }> {\n return this.db.findSurprisingConnections(limit);\n }\n\n // \u2500\u2500 Snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n createSnapshotManager(): SnapshotManager {\n return new SnapshotManager(this.db, this.projectRoot);\n }\n\n // \u2500\u2500 Stats \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getStats() {\n const stats = this.db.getStats();\n const vecIndexCount = await this.vectors.vecIndexCount();\n const embeddingCount = vecIndexCount > 0 ? vecIndexCount : stats.embeddingCount;\n const EMBEDDABLE = ['function', 'method', 'class', 'interface', 'type_alias', 'component', 'module'];\n const embeddableNodeCount = EMBEDDABLE.reduce((sum, k) => sum + (stats.nodesByKind[k] ?? 0), 0);\n const pendingFiles = await this.getPendingSyncCount();\n const syncRunning = this.isIndexLocked();\n return {\n ...stats,\n embeddingCount,\n embeddableNodeCount,\n embeddingsEnabled: this.config.enableEmbeddings ?? false,\n embeddingModel: this.config.embeddingModel,\n useVecIndex: this.config.useVecIndex ?? false,\n semanticEngine: this.config.semanticEngine ?? 'cosine',\n turbovecBits: this.config.turbovecBits,\n vecIndexCount,\n engineFallback: this.vectors.getEngineFallback(),\n frameworks: this.config.frameworkHints ?? [],\n architectureEnabled: this.config.enableArchitecture ?? false,\n ...(this.config.enableArchitecture ? { architectureStats: this.db.getArchStats() } : {}),\n pendingFiles,\n syncRunning,\n syncWarningThreshold: this.config.syncWarningThreshold ?? 10,\n };\n }\n\n getEngineFallback(): string | null { return this.vectors.getEngineFallback(); }\n\n // \u2500\u2500 Architecture API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getArchitecture(): ArchitectureResult & {\n filePackages: Record<string, string[]>;\n fileLayers: Record<string, Array<{ layerId: string; confidence: number; matchedPattern: string }>>;\n } {\n const base = this.db.getArchitectureResult();\n\n const filePackages: Record<string, string[]> = {};\n for (const { filePath, packageId } of this.db.getArchFilePackages()) {\n if (!filePackages[filePath]) filePackages[filePath] = [];\n filePackages[filePath].push(packageId);\n }\n\n const fileLayers: Record<string, Array<{ layerId: string; confidence: number; matchedPattern: string }>> = {};\n for (const row of this.db.getArchFileLayers()) {\n if (!fileLayers[row.filePath]) fileLayers[row.filePath] = [];\n fileLayers[row.filePath].push({ layerId: row.layerId, confidence: row.confidence, matchedPattern: row.matchedPattern });\n }\n\n return { ...base, filePackages, fileLayers };\n }\n\n isArchitectureEnabled(): boolean { return this.config.enableArchitecture ?? false; }\n\n // \u2500\u2500 Misc \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getProjectRoot(): string { return this.projectRoot; }\n\n getDatabase(): GraphDatabase { return this.db; }\n\n close(): void {\n this.vectors.close();\n this.lock.release();\n this.db.close();\n }\n}\n\n// \u2500\u2500 Module-level helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** Walk up directories to find the nearest .kirograph/ folder. */\nexport function findNearestKiroGraphRoot(startPath: string): string | null {\n let current = path.resolve(startPath);\n while (true) {\n if (fs.existsSync(path.join(current, KIROGRAPH_DIR))) return current;\n const parent = path.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,WAAsB;AACtB,SAAoB;AACpB,sBAA8B;AAC9B,mBAA4D;AAC5D,oBAA4D;AAE5D,qBAAkC;AAClC,wBAAkC;AAClC,qBAA8B;AAC9B,qBAA+B;AAC/B,0BAAqC;AACrC,0BAA4B;AAC5B,sBAA8B;AAC9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KO,SAAS,yBAAyB,WAAkC;AACzE,MAAI,UAAU,KAAK,QAAQ,SAAS;AACpC,SAAO,MAAM;AACX,QAAI,GAAG,WAAW,KAAK,KAAK,SAAS,aAAa,CAAC,EAAG,QAAO;AAC7D,UAAM,SAAS,KAAK,QAAQ,OAAO;AACnC,QAAI,WAAW,QAAS,QAAO;AAC/B,cAAU;AAAA,EACZ;AACF;",
4
+ "sourcesContent": ["/**\n * KiroGraph \u2014 Semantic code knowledge graph for Kiro\n *\n * Pure facade. Every method delegates to a focused sub-system.\n * No business logic lives here.\n */\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { GraphDatabase } from './db/database';\nimport { validatePathWithinRoot, validateProjectPath } from './utils';\nimport { loadConfig, createDefaultConfig, saveConfig } from './config';\nimport type { KiroGraphConfig } from './config';\nimport { GraphQueryManager } from './graph/queries';\nimport { ReferenceResolver } from './resolution/index';\nimport { VectorManager } from './vectors/index';\nimport { ContextBuilder } from './context/index';\nimport { ArchitectureAnalyzer } from './architecture/index';\nimport { LockManager } from './core/lock-manager';\nimport { IndexPipeline } from './core/pipeline';\nimport { buildFileTree } from './core/file-tree';\nimport { SnapshotManager } from './core/snapshot';\nimport { Searcher } from './search/searcher';\nimport type { FileTreeNode, FileTree } from './core/file-tree';\nimport type { GraphSnapshot, GraphDiff } from './core/snapshot';\n\nexport type { GraphSnapshot, GraphDiff };\nimport type {\n Node, Edge, NodeKind, IndexResult, IndexProgress, SyncResult, TaskContext,\n SearchResult, SearchOptions, NodeContext, NodeMetrics,\n} from './types';\nimport type { ArchitectureResult } from './architecture/types';\n\nexport type { FileTreeNode, FileTree };\n\nconst KIROGRAPH_DIR = '.kirograph';\n\nexport default class KiroGraph {\n private readonly db: GraphDatabase;\n private readonly config: KiroGraphConfig;\n private readonly projectRoot: string;\n private readonly queryManager: GraphQueryManager;\n private readonly resolver: ReferenceResolver;\n private readonly vectors: VectorManager;\n private readonly contextBuilder: ContextBuilder;\n private readonly arch: ArchitectureAnalyzer;\n private readonly lock: LockManager;\n private readonly pipeline: IndexPipeline;\n private readonly searcher: Searcher;\n\n private constructor(projectRoot: string, db: GraphDatabase, config: KiroGraphConfig) {\n this.projectRoot = projectRoot;\n this.db = db;\n this.config = config;\n this.queryManager = new GraphQueryManager(db);\n this.resolver = new ReferenceResolver(db, config, projectRoot);\n this.vectors = new VectorManager(db, config, projectRoot);\n this.contextBuilder = new ContextBuilder(db, this.resolver, this.vectors, projectRoot);\n this.arch = new ArchitectureAnalyzer(db, config, projectRoot);\n this.lock = new LockManager(projectRoot);\n this.pipeline = new IndexPipeline(db, this.vectors, this.resolver, this.arch, this.lock, config, projectRoot);\n this.searcher = new Searcher(db);\n }\n\n // \u2500\u2500 Factory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n static async init(\n projectRoot: string,\n config?: Partial<KiroGraphConfig>,\n onModelProgress?: (file: string, loaded: number, total: number, done: boolean) => void,\n ): Promise<KiroGraph> {\n const resolved = path.resolve(projectRoot);\n validateProjectPath(resolved);\n fs.mkdirSync(path.join(resolved, KIROGRAPH_DIR), { recursive: true });\n const cfg = { ...createDefaultConfig(resolved), ...config };\n await saveConfig(resolved, cfg);\n const db = new GraphDatabase(resolved);\n const kg = new KiroGraph(resolved, db, cfg);\n await kg.vectors.initialize(onModelProgress);\n return kg;\n }\n\n static async open(\n projectRoot: string,\n onModelProgress?: (file: string, loaded: number, total: number, done: boolean) => void,\n opts?: { skipVectors?: boolean },\n ): Promise<KiroGraph> {\n const resolved = path.resolve(projectRoot);\n validateProjectPath(resolved);\n if (!fs.existsSync(path.join(resolved, KIROGRAPH_DIR))) {\n throw new Error(`KiroGraph not initialized at ${resolved}. Run: kirograph init`);\n }\n const cfg = await loadConfig(resolved);\n const db = new GraphDatabase(resolved);\n const kg = new KiroGraph(resolved, db, cfg);\n if (!opts?.skipVectors) {\n await kg.vectors.initialize(onModelProgress);\n }\n return kg;\n }\n\n static isInitialized(projectRoot: string): boolean {\n return fs.existsSync(path.join(path.resolve(projectRoot), KIROGRAPH_DIR));\n }\n\n // \u2500\u2500 Lock / dirty marker \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n unlockForce(): void { this.lock.forceRelease(); }\n markDirty(): void { this.lock.markDirty(); }\n clearDirty(): void { this.lock.clearDirty(); }\n isDirty(): boolean { return this.lock.isDirty(); }\n isIndexLocked(): boolean { return this.lock.isLocked(); }\n\n async syncIfDirty(): Promise<SyncResult | null> {\n if (!this.isDirty()) return null;\n return this.sync();\n }\n\n /**\n * Returns the number of files that have changed on disk but are not yet\n * reflected in the index. Used by the MCP status tool to warn the agent\n * when the index may be stale.\n */\n async getPendingSyncCount(): Promise<number> {\n try {\n const { getChangedFiles, scanDirectory } = await Promise.resolve().then(() => require('./sync/index.js'));\n const gitChanged = await getChangedFiles(this.projectRoot, this.config);\n const hasGitChanges =\n gitChanged.added.length > 0 ||\n gitChanged.modified.length > 0 ||\n gitChanged.removed.length > 0;\n\n if (hasGitChanges) {\n return gitChanged.added.length + gitChanged.modified.length + gitChanged.removed.length;\n }\n\n // Fallback: compare indexed set vs current filesystem set\n const indexed = new Set(this.db.getAllFiles().map((f: { path: string }) => f.path));\n const current = new Set(\n (await scanDirectory(this.projectRoot, this.config))\n .map(f => require('path').relative(this.projectRoot, f).replace(/\\\\/g, '/'))\n );\n let pending = 0;\n for (const p of indexed) { if (!current.has(p)) pending++; }\n for (const p of current) { if (!indexed.has(p)) pending++; }\n return pending;\n } catch {\n return 0;\n }\n }\n\n // \u2500\u2500 Indexing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async indexAll(opts?: { onProgress?: (p: IndexProgress) => void; force?: boolean; signal?: AbortSignal }): Promise<IndexResult> {\n return this.pipeline.indexAll(opts);\n }\n\n async sync(changedFilesOrOpts?: string[] | { files?: string[]; onProgress?: (p: IndexProgress) => void }): Promise<SyncResult> {\n if (Array.isArray(changedFilesOrOpts)) {\n return this.pipeline.sync({ changedFiles: changedFilesOrOpts });\n }\n return this.pipeline.sync({\n changedFiles: changedFilesOrOpts?.files,\n onProgress: changedFilesOrOpts?.onProgress,\n });\n }\n\n // \u2500\u2500 Symbol search \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n searchNodes(query: string, kindOrOpts?: NodeKind | SearchOptions, limit = 20): SearchResult[] {\n return this.searcher.search(query, kindOrOpts, limit);\n }\n\n // \u2500\u2500 Graph queries \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getCallers(nodeId: string, limit = 30): Promise<Node[]> { return this.queryManager.getCallers(nodeId, limit); }\n async getCallees(nodeId: string, limit = 30): Promise<Node[]> { return this.queryManager.getCallees(nodeId, limit); }\n async getImpactRadius(nodeId: string, depth = 2): Promise<Node[]> { return this.queryManager.getImpactRadius(nodeId, depth); }\n getAllNodes(): Node[] { return this.db.getAllNodes(); }\n getAllEdges(): Edge[] { return this.db.getAllEdges(); }\n findDeadCode(limit = 50): Node[] { return this.db.findDeadCode(limit); }\n findCircularDependencies(): string[][] { return this.db.findCircularDependencies(); }\n async findPath(fromId: string, toId: string, maxDepth = 10): Promise<Node[]> { return this.queryManager.findPath(fromId, toId, maxDepth); }\n getTypeHierarchy(nodeId: string, direction: 'up' | 'down' | 'both' = 'both'): Node[] { return this.db.getTypeHierarchy(nodeId, direction); }\n getNode(id: string): Node | null { return this.db.getNode(id); }\n getNodeContext(nodeId: string): NodeContext | null { return this.db.getNodeContext(nodeId); }\n getNodeMetrics(nodeId: string): NodeMetrics { return this.db.getNodeMetrics(nodeId); }\n\n getNodeSource(node: Node): string | null {\n const absPath = validatePathWithinRoot(path.join(this.projectRoot, node.filePath), this.projectRoot);\n if (!absPath) return null;\n try {\n return fs.readFileSync(absPath, 'utf8').split('\\n').slice(node.startLine - 1, node.endLine).join('\\n');\n } catch { return null; }\n }\n\n // \u2500\u2500 Context building \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async buildContext(task: string, opts?: { maxNodes?: number; includeCode?: boolean }): Promise<TaskContext> {\n return this.contextBuilder.buildTaskContext(task, opts);\n }\n\n // \u2500\u2500 File browsing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getFiles(opts?: { filterPath?: string; pattern?: string; maxDepth?: number }): FileTree {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const picomatch = opts?.pattern ? require('picomatch')(opts.pattern) : null;\n const filtered = this.db.getAllFiles().filter(f => {\n if (opts?.filterPath && !f.path.startsWith(opts.filterPath)) return false;\n if (picomatch && !picomatch(f.path)) return false;\n return true;\n });\n return buildFileTree(filtered, opts?.maxDepth);\n }\n\n getAffectedTests(changedFiles: string[], opts?: { depth?: number; testPattern?: string }): string[] {\n return this.queryManager.getAffectedTests(changedFiles, opts);\n }\n\n // \u2500\u2500 Graph insights \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n findHotspots(limit = 20): Array<Node & { degree: number; inDegree: number; outDegree: number }> {\n return this.db.findHotspots(limit);\n }\n\n findSurprisingConnections(limit = 20): Array<{ source: Node; target: Node; kind: string; score: number }> {\n return this.db.findSurprisingConnections(limit);\n }\n\n // \u2500\u2500 Snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n createSnapshotManager(): SnapshotManager {\n return new SnapshotManager(this.db, this.projectRoot);\n }\n\n // \u2500\u2500 Stats \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getStats() {\n const stats = this.db.getStats();\n const vecIndexCount = await this.vectors.vecIndexCount();\n const embeddingCount = vecIndexCount > 0 ? vecIndexCount : stats.embeddingCount;\n const EMBEDDABLE = ['function', 'method', 'class', 'interface', 'type_alias', 'component', 'module'];\n const embeddableNodeCount = EMBEDDABLE.reduce((sum, k) => sum + (stats.nodesByKind[k] ?? 0), 0);\n const pendingFiles = await this.getPendingSyncCount();\n const syncRunning = this.isIndexLocked();\n return {\n ...stats,\n embeddingCount,\n embeddableNodeCount,\n embeddingsEnabled: this.config.enableEmbeddings ?? false,\n embeddingModel: this.config.embeddingModel,\n useVecIndex: this.config.useVecIndex ?? false,\n semanticEngine: this.config.semanticEngine ?? 'cosine',\n turbovecBits: this.config.turbovecBits,\n vecIndexCount,\n engineFallback: this.vectors.getEngineFallback(),\n frameworks: this.config.frameworkHints ?? [],\n architectureEnabled: this.config.enableArchitecture ?? false,\n ...(this.config.enableArchitecture ? { architectureStats: this.db.getArchStats() } : {}),\n pendingFiles,\n syncRunning,\n syncWarningThreshold: this.config.syncWarningThreshold ?? 10,\n };\n }\n\n getEngineFallback(): string | null { return this.vectors.getEngineFallback(); }\n\n // \u2500\u2500 Architecture API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getArchitecture(): ArchitectureResult & {\n filePackages: Record<string, string[]>;\n fileLayers: Record<string, Array<{ layerId: string; confidence: number; matchedPattern: string }>>;\n } {\n const base = this.db.getArchitectureResult();\n\n const filePackages: Record<string, string[]> = {};\n for (const { filePath, packageId } of this.db.getArchFilePackages()) {\n if (!filePackages[filePath]) filePackages[filePath] = [];\n filePackages[filePath].push(packageId);\n }\n\n const fileLayers: Record<string, Array<{ layerId: string; confidence: number; matchedPattern: string }>> = {};\n for (const row of this.db.getArchFileLayers()) {\n if (!fileLayers[row.filePath]) fileLayers[row.filePath] = [];\n fileLayers[row.filePath].push({ layerId: row.layerId, confidence: row.confidence, matchedPattern: row.matchedPattern });\n }\n\n return { ...base, filePackages, fileLayers };\n }\n\n isArchitectureEnabled(): boolean { return this.config.enableArchitecture ?? false; }\n\n // \u2500\u2500 Misc \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getProjectRoot(): string { return this.projectRoot; }\n\n getDatabase(): GraphDatabase { return this.db; }\n\n close(): void {\n this.vectors.close();\n this.lock.release();\n this.db.close();\n }\n}\n\n// \u2500\u2500 Module-level helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** Walk up directories to find the nearest .kirograph/ folder. */\nexport function findNearestKiroGraphRoot(startPath: string): string | null {\n let current = path.resolve(startPath);\n while (true) {\n if (fs.existsSync(path.join(current, KIROGRAPH_DIR))) return current;\n const parent = path.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,WAAsB;AACtB,SAAoB;AACpB,sBAA8B;AAC9B,mBAA4D;AAC5D,oBAA4D;AAE5D,qBAAkC;AAClC,wBAAkC;AAClC,qBAA8B;AAC9B,qBAA+B;AAC/B,0BAAqC;AACrC,0BAA4B;AAC5B,sBAA8B;AAC9B,uBAA8B;AAC9B,sBAAgC;AAChC,sBAAyB;AAazB,MAAM,gBAAgB;AAEtB,MAAO,UAAwB;AAAA,EAarB,YAAY,aAAqB,IAAmB,QAAyB;A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AM;AACX,QAAI,GAAG,WAAW,KAAK,KAAK,SAAS,aAAa,CAAC,EAAG,QAAO;AAC7D,UAAM,SAAS,KAAK,QAAQ,OAAO;AACnC,QAAI,WAAW,QAAS,QAAO;AAC/B,cAAU;AAAA,EACZ;AACF;",
6
6
  "names": []
7
7
  }
package/dist/mcp/cache.js CHANGED
@@ -71,7 +71,7 @@ class FileReadCache {
71
71
  existing.lastRead = Date.now();
72
72
  existing.readCount++;
73
73
  return {
74
- content: `[cached: unchanged since ${this.formatTimestamp(existing.lastRead)}] (${existing.readCount} reads)`,
74
+ content: `[cached: file unchanged \u2014 use kirograph_retrieve to get full content, or noCache:true to force re-read]`,
75
75
  cached: true,
76
76
  changed: false
77
77
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mcp/cache.ts"],
4
- "sourcesContent": ["/**\n * KiroGraph File Read Cache\n *\n * In-memory, session-scoped file cache. First read returns full content,\n * subsequent reads of unchanged files return a compact \"cached\" marker (~13 tokens).\n * Uses content hashing (SHA-256) to detect changes.\n */\n\nimport * as fs from 'fs';\nimport * as crypto from 'crypto';\n\nexport interface CacheEntry {\n contentHash: string;\n content: string;\n lastRead: number;\n readCount: number;\n}\n\nexport interface CacheStats {\n entries: number;\n hits: number;\n misses: number;\n hitRate: number;\n}\n\nexport interface ReadResult {\n content: string;\n cached: boolean;\n changed: boolean;\n /** Previous content (for diff mode) */\n previousContent?: string;\n}\n\nexport class FileReadCache {\n private cache = new Map<string, CacheEntry>();\n private hits = 0;\n private misses = 0;\n\n /**\n * Read a file with caching. Returns full content on first read or if changed,\n * returns a compact marker if unchanged since last read.\n */\n read(filePath: string, noCache = false): ReadResult {\n let content: string;\n try {\n content = fs.readFileSync(filePath, 'utf8');\n } catch (err: any) {\n throw new Error(`Cannot read file: ${err.message}`);\n }\n\n if (noCache) {\n const hash = this.hashContent(content);\n const previous = this.cache.get(filePath);\n this.cache.set(filePath, {\n contentHash: hash,\n content,\n lastRead: Date.now(),\n readCount: (previous?.readCount ?? 0) + 1,\n });\n this.misses++;\n return { content, cached: false, changed: false };\n }\n\n const hash = this.hashContent(content);\n const existing = this.cache.get(filePath);\n\n if (existing && existing.contentHash === hash) {\n // Cache hit \u2014 file unchanged\n this.hits++;\n existing.lastRead = Date.now();\n existing.readCount++;\n return {\n content: `[cached: unchanged since ${this.formatTimestamp(existing.lastRead)}] (${existing.readCount} reads)`,\n cached: true,\n changed: false,\n };\n }\n\n // Cache miss or file changed\n this.misses++;\n const previousContent = existing?.content;\n this.cache.set(filePath, {\n contentHash: hash,\n content,\n lastRead: Date.now(),\n readCount: (existing?.readCount ?? 0) + 1,\n });\n\n if (existing) {\n // File changed since last read\n return { content, cached: false, changed: true, previousContent };\n }\n\n // First read\n return { content, cached: false, changed: false };\n }\n\n /**\n * Get the previously cached content for a file (used by diff mode).\n */\n getPreviousContent(filePath: string): string | undefined {\n return this.cache.get(filePath)?.content;\n }\n\n /**\n * Check if a file is in the cache.\n */\n has(filePath: string): boolean {\n return this.cache.has(filePath);\n }\n\n /**\n * Invalidate cache entries for specific files (e.g., after sync).\n */\n invalidate(filePaths: string[]): void {\n for (const fp of filePaths) {\n this.cache.delete(fp);\n }\n }\n\n /**\n * Clear all cached entries.\n */\n clear(): void {\n this.cache.clear();\n this.hits = 0;\n this.misses = 0;\n }\n\n /**\n * Get cache statistics.\n */\n getStats(): CacheStats {\n const total = this.hits + this.misses;\n return {\n entries: this.cache.size,\n hits: this.hits,\n misses: this.misses,\n hitRate: total > 0 ? Math.round((this.hits / total) * 100) : 0,\n };\n }\n\n /**\n * List all cached file paths with their metadata.\n */\n listEntries(): Array<{ path: string; readCount: number; lastRead: number }> {\n return [...this.cache.entries()].map(([p, e]) => ({\n path: p,\n readCount: e.readCount,\n lastRead: e.lastRead,\n }));\n }\n\n private hashContent(content: string): string {\n return crypto.createHash('sha256').update(content).digest('hex');\n }\n\n private formatTimestamp(ts: number): string {\n const diff = Date.now() - ts;\n const seconds = Math.floor(diff / 1000);\n if (seconds < 60) return `${seconds}s ago`;\n const minutes = Math.floor(seconds / 60);\n if (minutes < 60) return `${minutes}m ago`;\n const hours = Math.floor(minutes / 60);\n return `${hours}h ago`;\n }\n}\n\n// Singleton instance \u2014 session-scoped (lives as long as the MCP server process)\nlet _instance: FileReadCache | null = null;\n\nexport function getFileReadCache(): FileReadCache {\n if (!_instance) {\n _instance = new FileReadCache();\n }\n return _instance;\n}\n\nexport function resetFileReadCache(): void {\n _instance?.clear();\n _instance = null;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAoB;AACpB,aAAwB;AAwBjB,MAAM,cAAc;AAAA,EAApB;AACL,SAAQ,QAAQ,oBAAI,IAAwB;AAC5C,SAAQ,OAAO;AACf,SAAQ,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,KAAK,UAAkB,UAAU,OAAmB;AAClD,QAAI;AACJ,QAAI;AACF,gBAAU,GAAG,aAAa,UAAU,MAAM;AAAA,IAC5C,SAAS,KAAU;AACjB,YAAM,IAAI,MAAM,qBAAqB,IAAI,OAAO,EAAE;AAAA,IACpD;AAEA,QAAI,SAAS;AACX,YAAMA,QAAO,KAAK,YAAY,OAAO;AACrC,YAAM,WAAW,KAAK,MAAM,IAAI,QAAQ;AACxC,WAAK,MAAM,IAAI,UAAU;AAAA,QACvB,aAAaA;AAAA,QACb;AAAA,QACA,UAAU,KAAK,IAAI;AAAA,QACnB,YAAY,UAAU,aAAa,KAAK;AAAA,MAC1C,CAAC;AACD,WAAK;AACL,aAAO,EAAE,SAAS,QAAQ,OAAO,SAAS,MAAM;AAAA,IAClD;AAEA,UAAM,OAAO,KAAK,YAAY,OAAO;AACrC,UAAM,WAAW,KAAK,MAAM,IAAI,QAAQ;AAExC,QAAI,YAAY,SAAS,gBAAgB,MAAM;AAE7C,WAAK;AACL,eAAS,WAAW,KAAK,IA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C,GAAG,KAAK,MAAM,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO;AAAA,MAChD,MAAM;AAAA,MACN,WAAW,EAAE;AAAA,MACb,UAAU,EAAE;AAAA,IACd,EAAE;AAAA,EACJ;AAAA,EAEQ,YAAY,SAAyB;AAC3C,WAAO,OAAO,WAAW,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAAA,EACjE;AAAA,EAEQ,gBAAgB,IAAoB;AAC1C,UAAM,OAAO,KAAK,IAAI,IAAI;AAC1B,UAAM,UAAU,KAAK,MAAM,OAAO,GAAI;AACtC,QAAI,UAAU,GAAI,QAAO,GAAG,OAAO;AACnC,UAAM,UAAU,KAAK,MAAM,UAAU,EAAE;AACvC,QAAI,UAAU,GAAI,QAAO,GAAG,OAAO;AACnC,UAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;AACrC,WAAO,GAAG,KAAK;AAAA,EACjB;AACF;AAGA,IAAI,YAAkC;AAE/B,SAAS,mBAAkC;AAChD,MAAI,CAAC,WAAW;AACd,gBAAY,IAAI,cAAc;AAAA,EAChC;AACA,SAAO;AACT;AAEO,SAAS,qBAA2B;AACzC,aAAW,MAAM;AACjB,cAAY;AACd;",
4
+ "sourcesContent": ["/**\n * KiroGraph File Read Cache\n *\n * In-memory, session-scoped file cache. First read returns full content,\n * subsequent reads of unchanged files return a compact \"cached\" marker (~13 tokens).\n * Uses content hashing (SHA-256) to detect changes.\n */\n\nimport * as fs from 'fs';\nimport * as crypto from 'crypto';\n\nexport interface CacheEntry {\n contentHash: string;\n content: string;\n lastRead: number;\n readCount: number;\n}\n\nexport interface CacheStats {\n entries: number;\n hits: number;\n misses: number;\n hitRate: number;\n}\n\nexport interface ReadResult {\n content: string;\n cached: boolean;\n changed: boolean;\n /** Previous content (for diff mode) */\n previousContent?: string;\n}\n\nexport class FileReadCache {\n private cache = new Map<string, CacheEntry>();\n private hits = 0;\n private misses = 0;\n\n /**\n * Read a file with caching. Returns full content on first read or if changed,\n * returns a compact marker if unchanged since last read.\n */\n read(filePath: string, noCache = false): ReadResult {\n let content: string;\n try {\n content = fs.readFileSync(filePath, 'utf8');\n } catch (err: any) {\n throw new Error(`Cannot read file: ${err.message}`);\n }\n\n if (noCache) {\n const hash = this.hashContent(content);\n const previous = this.cache.get(filePath);\n this.cache.set(filePath, {\n contentHash: hash,\n content,\n lastRead: Date.now(),\n readCount: (previous?.readCount ?? 0) + 1,\n });\n this.misses++;\n return { content, cached: false, changed: false };\n }\n\n const hash = this.hashContent(content);\n const existing = this.cache.get(filePath);\n\n if (existing && existing.contentHash === hash) {\n // Cache hit \u2014 file unchanged\n this.hits++;\n existing.lastRead = Date.now();\n existing.readCount++;\n return {\n content: `[cached: file unchanged \u2014 use kirograph_retrieve to get full content, or noCache:true to force re-read]`,\n cached: true,\n changed: false,\n };\n }\n\n // Cache miss or file changed\n this.misses++;\n const previousContent = existing?.content;\n this.cache.set(filePath, {\n contentHash: hash,\n content,\n lastRead: Date.now(),\n readCount: (existing?.readCount ?? 0) + 1,\n });\n\n if (existing) {\n // File changed since last read\n return { content, cached: false, changed: true, previousContent };\n }\n\n // First read\n return { content, cached: false, changed: false };\n }\n\n /**\n * Get the previously cached content for a file (used by diff mode).\n */\n getPreviousContent(filePath: string): string | undefined {\n return this.cache.get(filePath)?.content;\n }\n\n /**\n * Check if a file is in the cache.\n */\n has(filePath: string): boolean {\n return this.cache.has(filePath);\n }\n\n /**\n * Invalidate cache entries for specific files (e.g., after sync).\n */\n invalidate(filePaths: string[]): void {\n for (const fp of filePaths) {\n this.cache.delete(fp);\n }\n }\n\n /**\n * Clear all cached entries.\n */\n clear(): void {\n this.cache.clear();\n this.hits = 0;\n this.misses = 0;\n }\n\n /**\n * Get cache statistics.\n */\n getStats(): CacheStats {\n const total = this.hits + this.misses;\n return {\n entries: this.cache.size,\n hits: this.hits,\n misses: this.misses,\n hitRate: total > 0 ? Math.round((this.hits / total) * 100) : 0,\n };\n }\n\n /**\n * List all cached file paths with their metadata.\n */\n listEntries(): Array<{ path: string; readCount: number; lastRead: number }> {\n return [...this.cache.entries()].map(([p, e]) => ({\n path: p,\n readCount: e.readCount,\n lastRead: e.lastRead,\n }));\n }\n\n private hashContent(content: string): string {\n return crypto.createHash('sha256').update(content).digest('hex');\n }\n\n private formatTimestamp(ts: number): string {\n const diff = Date.now() - ts;\n const seconds = Math.floor(diff / 1000);\n if (seconds < 60) return `${seconds}s ago`;\n const minutes = Math.floor(seconds / 60);\n if (minutes < 60) return `${minutes}m ago`;\n const hours = Math.floor(minutes / 60);\n return `${hours}h ago`;\n }\n}\n\n// Singleton instance \u2014 session-scoped (lives as long as the MCP server process)\nlet _instance: FileReadCache | null = null;\n\nexport function getFileReadCache(): FileReadCache {\n if (!_instance) {\n _instance = new FileReadCache();\n }\n return _instance;\n}\n\nexport function resetFileReadCache(): void {\n _instance?.clear();\n _instance = null;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAoB;AACpB,aAAwB;AAwBjB,MAAM,cAAc;AAAA,EAApB;AACL,SAAQ,QAAQ,oBAAI,IAAwB;AAC5C,SAAQ,OAAO;AACf,SAAQ,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,KAAK,UAAkB,UAAU,OAAmB;AAClD,QAAI;AACJ,QAAI;AACF,gBAAU,GAAG,aAAa,UAAU,MAAM;AAAA,IAC5C,SAAS,KAAU;AACjB,YAAM,IAAI,MAAM,qBAAqB,IAAI,OAAO,EAAE;AAAA,IACpD;AAEA,QAAI,SAAS;AACX,YAAMA,QAAO,KAAK,YAAY,OAAO;AACrC,YAAM,WAAW,KAAK,MAAM,IAAI,QAAQ;AACxC,WAAK,MAAM,IAAI,UAAU;AAAA,QACvB,aAAaA;AAAA,QACb;AAAA,QACA,UAAU,KAAK,IAAI;AAAA,QACnB,YAAY,UAAU,aAAa,KAAK;A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AM,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,MACb,SAAS,QAAQ,IAAI,KAAK,MAAO,KAAK,OAAO,QAAS,GAAG,IAAI;AAAA,IAC/D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,cAA4E;AAC1E,WAAO,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO;AAAA,MAChD,MAAM;AAAA,MACN,WAAW,EAAE;AAAA,MACb,UAAU,EAAE;AAAA,IACd,EAAE;AAAA,EACJ;AAAA,EAEQ,YAAY,SAAyB;AAC3C,WAAO,OAAO,WAAW,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAAA,EACjE;AAAA,EAEQ,gBAAgB,IAAoB;AAC1C,UAAM,OAAO,KAAK,IAAI,IAAI;AAC1B,UAAM,UAAU,KAAK,MAAM,OAAO,GAAI;AACtC,QAAI,UAAU,GAAI,QAAO,GAAG,OAAO;AACnC,UAAM,UAAU,KAAK,MAAM,UAAU,EAAE;AACvC,QAAI,UAAU,GAAI,QAAO,GAAG,OAAO;AACnC,UAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;AACrC,WAAO,GAAG,KAAK;AAAA,EACjB;AACF;AAGA,IAAI,YAAkC;AAE/B,SAAS,mBAAkC;AAChD,MAAI,CAAC,WAAW;AACd,gBAAY,IAAI,cAAc;AAAA,EAChC;AACA,SAAO;AACT;AAEO,SAAS,qBAA2B;AACzC,aAAW,MAAM;AACjB,cAAY;AACd;",
6
6
  "names": ["hash"]
7
7
  }
@@ -0,0 +1,446 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var handler_exports = {};
30
+ __export(handler_exports, {
31
+ ToolHandler: () => ToolHandler
32
+ });
33
+ module.exports = __toCommonJS(handler_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_child_process = require("child_process");
37
+ var import__ = __toESM(require("../index"));
38
+ var import_errors = require("../errors");
39
+ var import_compression = require("../compression/index");
40
+ var import_tracker = require("../compression/tracker");
41
+ var import_utils = require("./handlers/utils");
42
+ var import_core = require("./handlers/core");
43
+ var import_code_health = require("./handlers/code-health");
44
+ var import_architecture = require("./handlers/architecture");
45
+ var import_edit_primitives = require("./handlers/edit-primitives");
46
+ var import_git_context = require("./handlers/git-context");
47
+ var import_complexity = require("./handlers/complexity");
48
+ var import_memory = require("./handlers/memory");
49
+ var import_docs = require("./handlers/docs");
50
+ var import_data = require("./handlers/data");
51
+ var import_watchmen = require("./handlers/watchmen");
52
+ var import_security = require("./handlers/security");
53
+ var import_patterns = require("./handlers/patterns");
54
+ var import_wiki = require("./handlers/wiki");
55
+ var import_branch = require("./handlers/branch");
56
+ const CORE_TOOLS = /* @__PURE__ */ new Set([
57
+ "kirograph_search",
58
+ "kirograph_context",
59
+ "kirograph_callers",
60
+ "kirograph_callees",
61
+ "kirograph_impact",
62
+ "kirograph_node",
63
+ "kirograph_status",
64
+ "kirograph_files",
65
+ "kirograph_affected"
66
+ ]);
67
+ const CODE_HEALTH_TOOLS = /* @__PURE__ */ new Set([
68
+ "kirograph_dead_code",
69
+ "kirograph_circular_deps",
70
+ "kirograph_path",
71
+ "kirograph_type_hierarchy",
72
+ "kirograph_hotspots",
73
+ "kirograph_surprising",
74
+ "kirograph_diff",
75
+ "kirograph_snapshot_save",
76
+ "kirograph_snapshot_list",
77
+ "kirograph_module_api",
78
+ "kirograph_rename_preview",
79
+ "kirograph_doc_coverage",
80
+ "kirograph_god_class",
81
+ "kirograph_inheritance_depth",
82
+ "kirograph_recursion",
83
+ "kirograph_largest",
84
+ "kirograph_rank",
85
+ "kirograph_distribution",
86
+ "kirograph_annotations",
87
+ "kirograph_session_start",
88
+ "kirograph_session_end",
89
+ "kirograph_unused_imports",
90
+ "kirograph_gini",
91
+ "kirograph_dependency_depth"
92
+ ]);
93
+ const ARCHITECTURE_TOOLS = /* @__PURE__ */ new Set([
94
+ "kirograph_architecture",
95
+ "kirograph_coupling",
96
+ "kirograph_package",
97
+ "kirograph_communities",
98
+ "kirograph_manifest"
99
+ ]);
100
+ const GIT_CONTEXT_TOOLS = /* @__PURE__ */ new Set([
101
+ "kirograph_flows",
102
+ "kirograph_diff_context",
103
+ "kirograph_commit_context",
104
+ "kirograph_pr_context",
105
+ "kirograph_changelog",
106
+ "kirograph_test_map",
107
+ "kirograph_test_coverage"
108
+ ]);
109
+ const COMPLEXITY_TOOLS = /* @__PURE__ */ new Set([
110
+ "kirograph_complexity",
111
+ "kirograph_simplify_scan",
112
+ "kirograph_health",
113
+ "kirograph_dsm",
114
+ "kirograph_test_risk"
115
+ ]);
116
+ const BRANCH_TOOLS = /* @__PURE__ */ new Set(["kirograph_branch_list", "kirograph_branch_diff", "kirograph_branch_search"]);
117
+ const EDIT_PRIMITIVES_TOOLS = /* @__PURE__ */ new Set([
118
+ "kirograph_refactor",
119
+ "kirograph_str_replace",
120
+ "kirograph_multi_str_replace",
121
+ "kirograph_insert_at",
122
+ "kirograph_ast_grep_rewrite"
123
+ ]);
124
+ const SECURITY_TOOLS = /* @__PURE__ */ new Set([
125
+ "kirograph_security",
126
+ "kirograph_vulns",
127
+ "kirograph_vuln_add",
128
+ "kirograph_vuln_suppress",
129
+ "kirograph_sbom",
130
+ "kirograph_vex",
131
+ "kirograph_reachability",
132
+ "kirograph_staleness",
133
+ "kirograph_licenses",
134
+ "kirograph_attack_surface",
135
+ "kirograph_secrets",
136
+ "kirograph_security_flows",
137
+ "kirograph_supply_chain",
138
+ "kirograph_dep_confusion",
139
+ "kirograph_remediation"
140
+ ]);
141
+ const PATTERNS_TOOLS = /* @__PURE__ */ new Set([
142
+ "kirograph_live_search",
143
+ "kirograph_pattern_coverage",
144
+ "kirograph_pattern_save_baseline",
145
+ "kirograph_pattern_diff"
146
+ ]);
147
+ const WATCHMEN_TOOLS = /* @__PURE__ */ new Set([
148
+ "kirograph_watchmen_status",
149
+ "kirograph_watchmen_synthesize",
150
+ "kirograph_watchmen_reset"
151
+ ]);
152
+ class ToolHandler {
153
+ constructor(cg) {
154
+ this.connections = /* @__PURE__ */ new Map();
155
+ this.defaultCg = cg;
156
+ }
157
+ setDefaultKiroGraph(cg) {
158
+ this.defaultCg = cg;
159
+ }
160
+ /** Close all cached cross-project connections. */
161
+ closeAll() {
162
+ for (const cg of this.connections.values()) {
163
+ try {
164
+ cg.close();
165
+ } catch {
166
+ }
167
+ }
168
+ this.connections.clear();
169
+ }
170
+ async getConnection(projectPath) {
171
+ if (!projectPath) return this.defaultCg;
172
+ const resolved = import_path.default.resolve(projectPath);
173
+ if (!import_path.default.isAbsolute(resolved)) return null;
174
+ if (this.connections.has(resolved)) return this.connections.get(resolved);
175
+ try {
176
+ const cg = await import__.default.open(resolved);
177
+ this.connections.set(resolved, cg);
178
+ return cg;
179
+ } catch {
180
+ return null;
181
+ }
182
+ }
183
+ async handle(toolName, args) {
184
+ try {
185
+ const text = await this.dispatch(toolName, args);
186
+ const truncated = (0, import_utils.truncate)(text);
187
+ let metricsTrailer = "";
188
+ if (toolName !== "kirograph_exec" && toolName !== "kirograph_gain") {
189
+ try {
190
+ const projectRoot = args.projectPath || this.defaultCg?.getProjectRoot() || process.cwd();
191
+ const { estimateNaiveCost } = await Promise.resolve().then(() => require("../compression/naive-cost.js"));
192
+ const { estimateTokens } = await Promise.resolve().then(() => require("../compression/index.js"));
193
+ const outputTokens = estimateTokens(truncated);
194
+ const naiveCost = estimateNaiveCost(toolName, outputTokens, args);
195
+ if (naiveCost !== null && naiveCost > outputTokens) {
196
+ const tracker = new import_tracker.TokenTracker(projectRoot);
197
+ if (toolName.startsWith("kirograph_mem_")) {
198
+ tracker.recordMemorySaving(toolName, outputTokens, naiveCost);
199
+ } else if (toolName.startsWith("kirograph_docs_")) {
200
+ tracker.recordDocsSaving(toolName, outputTokens, naiveCost);
201
+ } else if (toolName.startsWith("kirograph_data_")) {
202
+ tracker.recordDataSaving(toolName, outputTokens, naiveCost);
203
+ } else {
204
+ tracker.recordGraphSaving(toolName, outputTokens, naiveCost);
205
+ }
206
+ const saved = Math.round((naiveCost - outputTokens) / naiveCost * 100);
207
+ metricsTrailer = `
208
+
209
+ [kirograph_metrics: before=${naiveCost} after=${outputTokens} saved=${saved}%]`;
210
+ } else {
211
+ metricsTrailer = `
212
+
213
+ [kirograph_metrics: tokens=${outputTokens}]`;
214
+ }
215
+ } catch {
216
+ }
217
+ }
218
+ return { content: [{ type: "text", text: truncated + metricsTrailer }] };
219
+ } catch (err) {
220
+ (0, import_errors.logError)("MCP tool error", { tool: toolName, error: err });
221
+ const message = err instanceof Error ? err.message : String(err);
222
+ return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
223
+ }
224
+ }
225
+ async dispatch(toolName, args) {
226
+ if (toolName === "kirograph_exec") {
227
+ const cmd = args.command;
228
+ if (!cmd) return "Error: command is required.";
229
+ const projectRoot = args.projectPath || args.cwd || process.cwd();
230
+ const execCwd = args.cwd || projectRoot;
231
+ let defaultLevel = "normal";
232
+ try {
233
+ const { loadConfig } = await Promise.resolve().then(() => require("../config.js"));
234
+ const config = await loadConfig(projectRoot);
235
+ if (config.shellCompressionLevel && config.shellCompressionLevel !== "off") {
236
+ defaultLevel = config.shellCompressionLevel;
237
+ }
238
+ } catch {
239
+ }
240
+ const level = args.level ?? defaultLevel;
241
+ const timeout = (args.timeout ?? 60) * 1e3;
242
+ let rawOutput;
243
+ let exitCode = 0;
244
+ try {
245
+ rawOutput = (0, import_child_process.execSync)(cmd, {
246
+ cwd: execCwd,
247
+ timeout,
248
+ encoding: "utf8",
249
+ stdio: ["pipe", "pipe", "pipe"],
250
+ maxBuffer: 10 * 1024 * 1024
251
+ });
252
+ } catch (err) {
253
+ rawOutput = (err.stdout || "") + (err.stderr || "");
254
+ exitCode = err.status ?? 1;
255
+ }
256
+ const result = (0, import_compression.compress)(cmd, rawOutput, { level, preserveErrors: exitCode !== 0 });
257
+ const tracker = new import_tracker.TokenTracker(projectRoot);
258
+ tracker.record(cmd, result.originalTokens, result.compressedTokens, result.strategy);
259
+ const header = exitCode !== 0 ? `[exit ${exitCode}] ` : "";
260
+ const footer = result.savings > 5 ? `
261
+
262
+ [${result.savings}% tokens saved | ${result.originalTokens}\u2192${result.compressedTokens} | ${result.strategy}]` : "";
263
+ return `${header}${result.output}${footer}`;
264
+ }
265
+ if (toolName === "kirograph_gain") {
266
+ const projectRoot = args.projectPath || process.cwd();
267
+ const period = args.period ?? "session";
268
+ const tracker = new import_tracker.TokenTracker(projectRoot);
269
+ const stats = tracker.getStats(period);
270
+ if (stats.totalCommands === 0) {
271
+ return "No savings recorded yet. Use kirograph tools and kirograph_exec \u2014 savings are tracked automatically.";
272
+ }
273
+ const lines = [
274
+ `Token Savings (${period}):`,
275
+ ` Total calls: ${stats.totalCommands}`,
276
+ ` Tokens without KiroGraph: ~${stats.totalOriginal.toLocaleString()}`,
277
+ ` Tokens with KiroGraph: ~${stats.totalCompressed.toLocaleString()}`,
278
+ ` Saved: ${stats.totalSaved.toLocaleString()} tokens (${stats.savingsPercent}%)`
279
+ ];
280
+ if (stats.bySource.exec.count > 0 || stats.bySource.graph.count > 0 || stats.bySource.memory.count > 0 || stats.bySource.docs.count > 0) {
281
+ lines.push("", "By source:");
282
+ if (stats.bySource.graph.count > 0) {
283
+ lines.push(` Graph tools: ${stats.bySource.graph.count} calls, ~${stats.bySource.graph.saved.toLocaleString()} tokens saved (vs file reads/grep)`);
284
+ }
285
+ if (stats.bySource.docs.count > 0) {
286
+ lines.push(` Docs tools: ${stats.bySource.docs.count} calls, ~${stats.bySource.docs.saved.toLocaleString()} tokens saved (vs reading full doc files)`);
287
+ }
288
+ if (stats.bySource.data.count > 0) {
289
+ lines.push(` Data tools: ${stats.bySource.data.count} calls, ~${stats.bySource.data.saved.toLocaleString()} tokens saved (vs loading raw data files)`);
290
+ }
291
+ if (stats.bySource.exec.count > 0) {
292
+ lines.push(` Compression: ${stats.bySource.exec.count} calls, ~${stats.bySource.exec.saved.toLocaleString()} tokens saved (vs raw output)`);
293
+ }
294
+ if (stats.bySource.memory.count > 0) {
295
+ lines.push(` Memory: ${stats.bySource.memory.count} calls, ~${stats.bySource.memory.saved.toLocaleString()} tokens saved (vs re-discovering context)`);
296
+ }
297
+ }
298
+ if (Object.keys(stats.byFamily).length > 0) {
299
+ lines.push("", "Top families:");
300
+ for (const [family, data] of Object.entries(stats.byFamily).slice(0, 7)) {
301
+ lines.push(` ${family}: ${data.count} calls, ${data.savings}% avg savings`);
302
+ }
303
+ }
304
+ if (stats.recentCommands.length > 0) {
305
+ lines.push("", "Recent:");
306
+ for (const cmd of stats.recentCommands.slice(0, 5)) {
307
+ const tag = cmd.source === "graph" ? "\u{1F4CA}" : "\u26A1";
308
+ lines.push(` ${tag} ${cmd.command.slice(0, 40)} \u2192 ${cmd.savings}% saved`);
309
+ }
310
+ }
311
+ return lines.join("\n");
312
+ }
313
+ if (toolName === "kirograph_read") {
314
+ const filePath = args.path;
315
+ if (!filePath) return "Error: path is required.";
316
+ const projectRoot = args.projectPath || process.cwd();
317
+ const resolvedPath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.join(projectRoot, filePath);
318
+ const mode = args.mode ?? "full";
319
+ const noCache = args.noCache ?? false;
320
+ if (!import_fs.default.existsSync(resolvedPath)) {
321
+ return `Error: File not found: ${resolvedPath}`;
322
+ }
323
+ const { getFileReadCache } = await Promise.resolve().then(() => require("./cache.js"));
324
+ const { executeReadMode } = await Promise.resolve().then(() => require("./read-modes.js"));
325
+ const cache = getFileReadCache();
326
+ if (mode !== "full") {
327
+ let cg2 = null;
328
+ try {
329
+ cg2 = await this.getConnection(args.projectPath);
330
+ } catch {
331
+ }
332
+ const result2 = executeReadMode({
333
+ mode,
334
+ filePath: resolvedPath,
335
+ start: args.start,
336
+ end: args.end,
337
+ cg: cg2
338
+ });
339
+ cache.read(resolvedPath, true);
340
+ return result2.content;
341
+ }
342
+ const result = cache.read(resolvedPath, noCache);
343
+ if (result.cached) {
344
+ return result.content;
345
+ }
346
+ if (result.changed) {
347
+ return `[file changed since last read]
348
+
349
+ ${result.content}`;
350
+ }
351
+ return result.content;
352
+ }
353
+ if (toolName === "kirograph_retrieve") {
354
+ const filePath = args.path;
355
+ if (!filePath) return "Error: path is required.";
356
+ const projectRoot = args.projectPath || process.cwd();
357
+ const resolvedPath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.join(projectRoot, filePath);
358
+ const { getFileReadCache } = await Promise.resolve().then(() => require("./cache.js"));
359
+ const cache = getFileReadCache();
360
+ const cached = cache.getPreviousContent(resolvedPath);
361
+ if (cached !== void 0) {
362
+ return cached;
363
+ }
364
+ if (!import_fs.default.existsSync(resolvedPath)) {
365
+ return `Error: File not found: ${resolvedPath}`;
366
+ }
367
+ const result = cache.read(resolvedPath, true);
368
+ return result.content;
369
+ }
370
+ if (toolName === "kirograph_compress") {
371
+ const text = args.text;
372
+ if (!text) return "Error: text is required.";
373
+ const rawLevel = args.level ?? "full";
374
+ const command = args.command;
375
+ const { estimateTokens: est } = await Promise.resolve().then(() => require("../compression/index.js"));
376
+ const originalTokens = est(text);
377
+ let compressed;
378
+ let strategy;
379
+ if (command) {
380
+ const shellLevel = rawLevel === "ultra" ? "ultra" : rawLevel === "lite" || rawLevel === "normal" ? "normal" : "aggressive";
381
+ const { compress: compress2 } = await Promise.resolve().then(() => require("../compression/index.js"));
382
+ const result = compress2(command, text, { level: shellLevel });
383
+ compressed = result.output;
384
+ strategy = `rtk:${result.commandFamily}:${shellLevel}`;
385
+ } else {
386
+ const cavemanLevel = rawLevel === "normal" || rawLevel === "lite" ? "lite" : rawLevel === "aggressive" ? "full" : rawLevel;
387
+ const { compressObservation } = await Promise.resolve().then(() => require("../memory/compress.js"));
388
+ const result = compressObservation(text, cavemanLevel);
389
+ compressed = result.compressed;
390
+ strategy = `caveman:${cavemanLevel}`;
391
+ }
392
+ const compressedTokens = est(compressed);
393
+ const savings = originalTokens > 0 ? Math.round((originalTokens - compressedTokens) / originalTokens * 100) : 0;
394
+ const footer = savings > 5 ? `
395
+
396
+ [${savings}% tokens saved | ${originalTokens}\u2192${compressedTokens} | ${strategy}]` : "";
397
+ return compressed + footer;
398
+ }
399
+ if (toolName === "kirograph_budget") {
400
+ const projectRoot = args.projectPath || process.cwd();
401
+ const reset = args.reset ?? false;
402
+ const { BudgetTracker } = await Promise.resolve().then(() => require("../compression/tracker.js"));
403
+ const budget = BudgetTracker.getInstance(projectRoot);
404
+ if (reset) {
405
+ budget.reset();
406
+ return "Context budget counters reset.";
407
+ }
408
+ const status = budget.getStatus();
409
+ const lines = [
410
+ "Context Budget:",
411
+ ` Tokens consumed: ${status.consumed.toLocaleString()}`,
412
+ ` Budget limit: ${status.limit > 0 ? status.limit.toLocaleString() : "unlimited"}`,
413
+ ` Remaining: ${status.limit > 0 ? status.remaining.toLocaleString() : "\u221E"}`,
414
+ ` Utilization: ${status.utilization}%`
415
+ ];
416
+ if (status.warning) {
417
+ lines.push(`
418
+ \u26A0 ${status.warning}`);
419
+ }
420
+ return lines.join("\n");
421
+ }
422
+ const cg = await this.getConnection(args.projectPath);
423
+ if (!cg) return "KiroGraph not initialized. Run `kirograph init` in your project first.";
424
+ (0, import_utils.writeSessionMarker)(cg.getProjectRoot());
425
+ if (CORE_TOOLS.has(toolName)) return (0, import_core.handleCore)(toolName, args, cg);
426
+ if (CODE_HEALTH_TOOLS.has(toolName)) return (0, import_code_health.handleCodeHealth)(toolName, args, cg);
427
+ if (ARCHITECTURE_TOOLS.has(toolName)) return (0, import_architecture.handleArchitecture)(toolName, args, cg);
428
+ if (GIT_CONTEXT_TOOLS.has(toolName)) return (0, import_git_context.handleGitContext)(toolName, args, cg);
429
+ if (COMPLEXITY_TOOLS.has(toolName)) return (0, import_complexity.handleComplexity)(toolName, args, cg);
430
+ if (BRANCH_TOOLS.has(toolName)) return (0, import_branch.handleBranch)(toolName, args, cg);
431
+ if (EDIT_PRIMITIVES_TOOLS.has(toolName)) return (0, import_edit_primitives.handleEditPrimitives)(toolName, args, cg);
432
+ if (SECURITY_TOOLS.has(toolName)) return (0, import_security.handleSecurity)(toolName, args, cg);
433
+ if (PATTERNS_TOOLS.has(toolName)) return (0, import_patterns.handlePatterns)(toolName, args, cg);
434
+ if (WATCHMEN_TOOLS.has(toolName)) return (0, import_watchmen.handleWatchmen)(toolName, args, cg);
435
+ if (toolName.startsWith("kirograph_mem_")) return (0, import_memory.handleMemory)(toolName, args, cg);
436
+ if (toolName.startsWith("kirograph_docs_")) return (0, import_docs.handleDocs)(toolName, args, cg);
437
+ if (toolName.startsWith("kirograph_data_")) return (0, import_data.handleData)(toolName, args, cg);
438
+ if (toolName.startsWith("kirograph_wiki_")) return (0, import_wiki.handleWiki)(toolName, args, cg);
439
+ return `Unknown tool: ${toolName}`;
440
+ }
441
+ }
442
+ // Annotate the CommonJS export names for ESM import in node:
443
+ 0 && (module.exports = {
444
+ ToolHandler
445
+ });
446
+ //# sourceMappingURL=handler.js.map