toolnet-memory 0.2.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 (329) hide show
  1. package/.env.example +28 -0
  2. package/README.md +147 -0
  3. package/bin/toolnet-memory +415 -0
  4. package/dist/packages/cli/commands.js +1 -0
  5. package/dist/packages/cli/index.js +1 -0
  6. package/dist/packages/sdk/client.js +78 -0
  7. package/dist/packages/sdk/index.js +1 -0
  8. package/dist/packages/sdk/types.js +1 -0
  9. package/dist/src/api/index.js +1 -0
  10. package/dist/src/api/routes/health.js +1 -0
  11. package/dist/src/api/routes/index.js +1 -0
  12. package/dist/src/api/routes/memory.js +1 -0
  13. package/dist/src/api/routes/projects.js +1 -0
  14. package/dist/src/api/routes/search.js +1 -0
  15. package/dist/src/api/server.js +1 -0
  16. package/dist/src/capture/activity-capture.js +21 -0
  17. package/dist/src/capture/command-capture.js +12 -0
  18. package/dist/src/capture/error-capture.js +14 -0
  19. package/dist/src/capture/event-deduplicator.js +28 -0
  20. package/dist/src/capture/event-queue.js +20 -0
  21. package/dist/src/capture/file-capture.js +23 -0
  22. package/dist/src/capture/index.js +8 -0
  23. package/dist/src/capture/session-capture.js +18 -0
  24. package/dist/src/capture/tool-capture.js +13 -0
  25. package/dist/src/code-intelligence/analysis/analysis-engine.js +26 -0
  26. package/dist/src/code-intelligence/analysis/dead-code-analyzer.js +127 -0
  27. package/dist/src/code-intelligence/analysis/dependency-analyzer.js +66 -0
  28. package/dist/src/code-intelligence/analysis/index.js +4 -0
  29. package/dist/src/code-intelligence/analysis/types.js +1 -0
  30. package/dist/src/code-intelligence/architecture/architecture-engine.js +48 -0
  31. package/dist/src/code-intelligence/architecture/clusters.js +322 -0
  32. package/dist/src/code-intelligence/architecture/entry-points.js +150 -0
  33. package/dist/src/code-intelligence/architecture/hotspots.js +136 -0
  34. package/dist/src/code-intelligence/architecture/index.js +6 -0
  35. package/dist/src/code-intelligence/architecture/layers.js +197 -0
  36. package/dist/src/code-intelligence/architecture/types.js +1 -0
  37. package/dist/src/code-intelligence/chunks/index.js +2 -0
  38. package/dist/src/code-intelligence/chunks/smart-chunker.js +125 -0
  39. package/dist/src/code-intelligence/chunks/types.js +1 -0
  40. package/dist/src/code-intelligence/git/git-diff.js +109 -0
  41. package/dist/src/code-intelligence/git/index.js +1 -0
  42. package/dist/src/code-intelligence/graph/architecture.js +26 -0
  43. package/dist/src/code-intelligence/graph/graph-builder.js +213 -0
  44. package/dist/src/code-intelligence/graph/graph-store.js +57 -0
  45. package/dist/src/code-intelligence/graph/index.js +1 -0
  46. package/dist/src/code-intelligence/graph/relationships.js +1 -0
  47. package/dist/src/code-intelligence/graph/trace.js +65 -0
  48. package/dist/src/code-intelligence/impact/blast-radius.js +160 -0
  49. package/dist/src/code-intelligence/impact/change-mapper.js +69 -0
  50. package/dist/src/code-intelligence/impact/edit-tool-detector.js +92 -0
  51. package/dist/src/code-intelligence/impact/impact-analyzer.js +60 -0
  52. package/dist/src/code-intelligence/impact/impact-guard.js +33 -0
  53. package/dist/src/code-intelligence/impact/index.js +5 -0
  54. package/dist/src/code-intelligence/incremental/file-hash.js +8 -0
  55. package/dist/src/code-intelligence/incremental/incremental-indexer.js +106 -0
  56. package/dist/src/code-intelligence/incremental/manifest-builder.js +19 -0
  57. package/dist/src/code-intelligence/incremental/manifest.js +31 -0
  58. package/dist/src/code-intelligence/index.js +23 -0
  59. package/dist/src/code-intelligence/indexer/file-watcher.js +1 -0
  60. package/dist/src/code-intelligence/indexer/incremental-indexer.js +1 -0
  61. package/dist/src/code-intelligence/indexer/index.js +1 -0
  62. package/dist/src/code-intelligence/indexer/repository-indexer.js +31 -0
  63. package/dist/src/code-intelligence/indexer/repository-scanner.js +50 -0
  64. package/dist/src/code-intelligence/parsers/index.js +1 -0
  65. package/dist/src/code-intelligence/parsers/tree-sitter/index.js +1 -0
  66. package/dist/src/code-intelligence/parsers/tree-sitter/languages.js +1 -0
  67. package/dist/src/code-intelligence/parsers/tree-sitter/parser.js +1 -0
  68. package/dist/src/code-intelligence/parsers/typescript-parser.js +190 -0
  69. package/dist/src/code-intelligence/query/graph-query-engine.js +275 -0
  70. package/dist/src/code-intelligence/query/index.js +2 -0
  71. package/dist/src/code-intelligence/query/types.js +1 -0
  72. package/dist/src/code-intelligence/resolution/index.js +2 -0
  73. package/dist/src/code-intelligence/resolution/types.js +1 -0
  74. package/dist/src/code-intelligence/resolution/typescript-resolver.js +316 -0
  75. package/dist/src/code-intelligence/rich/index.js +1 -0
  76. package/dist/src/code-intelligence/rich/rich-graph-enricher.js +463 -0
  77. package/dist/src/code-intelligence/semantic/index.js +2 -0
  78. package/dist/src/code-intelligence/semantic/semantic-code-engine.js +213 -0
  79. package/dist/src/code-intelligence/semantic/source-priority.js +22 -0
  80. package/dist/src/code-intelligence/symbols/index.js +1 -0
  81. package/dist/src/code-intelligence/symbols/reference-resolver.js +21 -0
  82. package/dist/src/code-intelligence/symbols/symbol-extractor.js +1 -0
  83. package/dist/src/code-intelligence/test-analysis.js +72 -0
  84. package/dist/src/code-intelligence/test-architecture.js +67 -0
  85. package/dist/src/code-intelligence/test-impact.js +47 -0
  86. package/dist/src/code-intelligence/test-incremental.js +24 -0
  87. package/dist/src/code-intelligence/test-index.js +39 -0
  88. package/dist/src/code-intelligence/test-resolution.js +54 -0
  89. package/dist/src/code-intelligence/test-rich-graph.js +48 -0
  90. package/dist/src/code-intelligence/test-semantic.js +57 -0
  91. package/dist/src/code-intelligence/test-visualization.js +36 -0
  92. package/dist/src/code-intelligence/types.js +1 -0
  93. package/dist/src/code-intelligence/visualization/index.js +2 -0
  94. package/dist/src/code-intelligence/visualization/types.js +1 -0
  95. package/dist/src/code-intelligence/visualization/visualization-builder.js +104 -0
  96. package/dist/src/core/config.js +66 -0
  97. package/dist/src/core/global-env.js +70 -0
  98. package/dist/src/core/importance.js +30 -0
  99. package/dist/src/core/index.js +5 -0
  100. package/dist/src/core/memory-engine.js +183 -0
  101. package/dist/src/core/project-manager.js +243 -0
  102. package/dist/src/core/types.js +1 -0
  103. package/dist/src/embeddings/batch-embedder.js +1 -0
  104. package/dist/src/embeddings/cache.js +1 -0
  105. package/dist/src/embeddings/embedder.js +51 -0
  106. package/dist/src/embeddings/index.js +4 -0
  107. package/dist/src/embeddings/local.js +37 -0
  108. package/dist/src/embeddings/provider.js +1 -0
  109. package/dist/src/embeddings/remote.js +76 -0
  110. package/dist/src/embeddings/test-connection.js +16 -0
  111. package/dist/src/hooks/after-edit.js +3 -0
  112. package/dist/src/hooks/after-tool.js +3 -0
  113. package/dist/src/hooks/auto-context.js +68 -0
  114. package/dist/src/hooks/auto-impact-guard.js +94 -0
  115. package/dist/src/hooks/auto-retrieval.js +27 -0
  116. package/dist/src/hooks/before-agent.js +18 -0
  117. package/dist/src/hooks/before-compact.js +3 -0
  118. package/dist/src/hooks/before-edit.js +20 -0
  119. package/dist/src/hooks/index.js +11 -0
  120. package/dist/src/hooks/runtime.js +110 -0
  121. package/dist/src/hooks/session-end.js +3 -0
  122. package/dist/src/hooks/session-start.js +3 -0
  123. package/dist/src/index.js +22 -0
  124. package/dist/src/mcp/bootstrap.js +68 -0
  125. package/dist/src/mcp/context.js +1 -0
  126. package/dist/src/mcp/index.js +3 -0
  127. package/dist/src/mcp/server.js +45 -0
  128. package/dist/src/mcp/tools/analyze-impact.js +41 -0
  129. package/dist/src/mcp/tools/dead-code.js +55 -0
  130. package/dist/src/mcp/tools/find-callers.js +24 -0
  131. package/dist/src/mcp/tools/find-dependencies.js +57 -0
  132. package/dist/src/mcp/tools/find-symbol.js +7 -0
  133. package/dist/src/mcp/tools/get-architecture.js +11 -0
  134. package/dist/src/mcp/tools/graph-dependents.js +24 -0
  135. package/dist/src/mcp/tools/graph-neighborhood.js +58 -0
  136. package/dist/src/mcp/tools/graph-path.js +43 -0
  137. package/dist/src/mcp/tools/graph-query-utils.js +32 -0
  138. package/dist/src/mcp/tools/impact-guard.js +34 -0
  139. package/dist/src/mcp/tools/index-repository.js +1 -0
  140. package/dist/src/mcp/tools/index.js +20 -0
  141. package/dist/src/mcp/tools/memory-decisions.js +1 -0
  142. package/dist/src/mcp/tools/memory-forget.js +14 -0
  143. package/dist/src/mcp/tools/memory-recent.js +1 -0
  144. package/dist/src/mcp/tools/memory-remember.js +33 -0
  145. package/dist/src/mcp/tools/memory-rules.js +1 -0
  146. package/dist/src/mcp/tools/memory-search.js +18 -0
  147. package/dist/src/mcp/tools/memory-todos.js +1 -0
  148. package/dist/src/mcp/tools/project-context.js +25 -0
  149. package/dist/src/mcp/tools/search-code.js +21 -0
  150. package/dist/src/mcp/tools/semantic-code-search.js +33 -0
  151. package/dist/src/mcp/tools/snapshot-create.js +13 -0
  152. package/dist/src/mcp/tools/snapshot-list.js +7 -0
  153. package/dist/src/mcp/tools/snapshot-restore.js +13 -0
  154. package/dist/src/mcp/tools/trace-calls.js +37 -0
  155. package/dist/src/memory/activity.js +5 -0
  156. package/dist/src/memory/conflict-detector.js +105 -0
  157. package/dist/src/memory/consolidator.js +104 -0
  158. package/dist/src/memory/decay.js +59 -0
  159. package/dist/src/memory/decisions.js +3 -0
  160. package/dist/src/memory/deduplicate.js +25 -0
  161. package/dist/src/memory/index.js +11 -0
  162. package/dist/src/memory/maintenance.js +16 -0
  163. package/dist/src/memory/remember.js +3 -0
  164. package/dist/src/memory/rules.js +3 -0
  165. package/dist/src/memory/search.js +3 -0
  166. package/dist/src/memory/summaries.js +1 -0
  167. package/dist/src/memory/todos.js +3 -0
  168. package/dist/src/processor/decision-extractor.js +13 -0
  169. package/dist/src/processor/importance-scorer.js +22 -0
  170. package/dist/src/processor/index.js +7 -0
  171. package/dist/src/processor/memory-extractor.js +59 -0
  172. package/dist/src/processor/memory-processor.js +105 -0
  173. package/dist/src/processor/rule-extractor.js +13 -0
  174. package/dist/src/processor/summarizer.js +71 -0
  175. package/dist/src/processor/todo-extractor.js +12 -0
  176. package/dist/src/production/config-check.js +34 -0
  177. package/dist/src/production/doctor.js +58 -0
  178. package/dist/src/production/full-index.js +114 -0
  179. package/dist/src/production/health.js +58 -0
  180. package/dist/src/production/index-pipeline.js +151 -0
  181. package/dist/src/production/index.js +4 -0
  182. package/dist/src/production/project-lock.js +95 -0
  183. package/dist/src/production/project-status.js +16 -0
  184. package/dist/src/production/recovery.js +15 -0
  185. package/dist/src/production/snapshot-cli.js +58 -0
  186. package/dist/src/project-manual/cli.js +77 -0
  187. package/dist/src/project-manual/index.js +2 -0
  188. package/dist/src/project-manual/manager.js +147 -0
  189. package/dist/src/project-manual/types.js +1 -0
  190. package/dist/src/retrieval/bm25/index.js +1 -0
  191. package/dist/src/retrieval/bm25/search.js +1 -0
  192. package/dist/src/retrieval/bm25.js +30 -0
  193. package/dist/src/retrieval/context-budget.js +1 -0
  194. package/dist/src/retrieval/context-builder.js +22 -0
  195. package/dist/src/retrieval/graph/index.js +1 -0
  196. package/dist/src/retrieval/graph/search.js +1 -0
  197. package/dist/src/retrieval/hybrid/hybrid-search.js +1 -0
  198. package/dist/src/retrieval/hybrid/index.js +1 -0
  199. package/dist/src/retrieval/hybrid-search.js +68 -0
  200. package/dist/src/retrieval/importance.js +16 -0
  201. package/dist/src/retrieval/index.js +12 -0
  202. package/dist/src/retrieval/query-analyzer.js +32 -0
  203. package/dist/src/retrieval/query-classifier.js +1 -0
  204. package/dist/src/retrieval/query-expansion.js +1 -0
  205. package/dist/src/retrieval/recency.js +12 -0
  206. package/dist/src/retrieval/reranker/index.js +1 -0
  207. package/dist/src/retrieval/reranker/reranker.js +1 -0
  208. package/dist/src/retrieval/retrieval-engine.js +17 -0
  209. package/dist/src/retrieval/tokenizer.js +9 -0
  210. package/dist/src/retrieval/type-priority.js +10 -0
  211. package/dist/src/retrieval/types.js +1 -0
  212. package/dist/src/retrieval/vector/index.js +4 -0
  213. package/dist/src/retrieval/vector/metadata-filter.js +1 -0
  214. package/dist/src/retrieval/vector/persistence.js +67 -0
  215. package/dist/src/retrieval/vector/search.js +12 -0
  216. package/dist/src/retrieval/vector/test-persistence.js +36 -0
  217. package/dist/src/retrieval/vector/upsert.js +40 -0
  218. package/dist/src/retrieval/vector/vector-store.js +89 -0
  219. package/dist/src/retrieval/vector-hybrid-engine.js +91 -0
  220. package/dist/src/runtime/bootstrap.js +28 -0
  221. package/dist/src/runtime/graceful.js +17 -0
  222. package/dist/src/runtime/index.js +3 -0
  223. package/dist/src/runtime/toolnet-memory-runtime.js +156 -0
  224. package/dist/src/security/encryption.js +1 -0
  225. package/dist/src/security/file-filter.js +30 -0
  226. package/dist/src/security/index.js +3 -0
  227. package/dist/src/security/sanitizer.js +49 -0
  228. package/dist/src/security/secret-scanner.js +56 -0
  229. package/dist/src/session/agy/adapter.js +159 -0
  230. package/dist/src/session/agy/cli.js +87 -0
  231. package/dist/src/session/agy/hook-installer.js +62 -0
  232. package/dist/src/session/agy/hook.js +167 -0
  233. package/dist/src/session/agy/index.js +5 -0
  234. package/dist/src/session/agy/project-resolver.js +27 -0
  235. package/dist/src/session/agy/recovery.js +112 -0
  236. package/dist/src/session/agy/transcript.js +191 -0
  237. package/dist/src/session/codex/adapter.js +138 -0
  238. package/dist/src/session/codex/cli.js +236 -0
  239. package/dist/src/session/codex/context-hook-installer.js +70 -0
  240. package/dist/src/session/codex/context-hook.js +69 -0
  241. package/dist/src/session/codex/discovery.js +138 -0
  242. package/dist/src/session/codex/index.js +6 -0
  243. package/dist/src/session/codex/notify-installer.js +135 -0
  244. package/dist/src/session/codex/project-resolver.js +25 -0
  245. package/dist/src/session/codex/recovery.js +27 -0
  246. package/dist/src/session/codex/rollout.js +186 -0
  247. package/dist/src/session/core.js +239 -0
  248. package/dist/src/session/identity.js +57 -0
  249. package/dist/src/session/index.js +9 -0
  250. package/dist/src/session/learner/cli.js +62 -0
  251. package/dist/src/session/learner/extractor.js +461 -0
  252. package/dist/src/session/learner/index.js +4 -0
  253. package/dist/src/session/learner/journal.js +159 -0
  254. package/dist/src/session/learner/learner.js +124 -0
  255. package/dist/src/session/learner/types.js +1 -0
  256. package/dist/src/session/opencode/adapter.js +553 -0
  257. package/dist/src/session/opencode/cli.js +121 -0
  258. package/dist/src/session/opencode/index.js +2 -0
  259. package/dist/src/session/opencode/plugin-installer.js +230 -0
  260. package/dist/src/session/store.js +242 -0
  261. package/dist/src/session/types.js +1 -0
  262. package/dist/src/session/utils.js +47 -0
  263. package/dist/src/session/wal.js +303 -0
  264. package/dist/src/snapshot/index.js +2 -0
  265. package/dist/src/snapshot/manager.js +130 -0
  266. package/dist/src/snapshot/test-snapshot.js +28 -0
  267. package/dist/src/snapshot/types.js +1 -0
  268. package/dist/src/storage/architecture-store.js +37 -0
  269. package/dist/src/storage/cleanup-health.js +20 -0
  270. package/dist/src/storage/code-analysis-store.js +35 -0
  271. package/dist/src/storage/code-chunk-store.js +25 -0
  272. package/dist/src/storage/code-graph-store.js +24 -0
  273. package/dist/src/storage/code-manifest-store.js +24 -0
  274. package/dist/src/storage/code-vector-store.js +25 -0
  275. package/dist/src/storage/github/client.js +1 -0
  276. package/dist/src/storage/github/index.js +1 -0
  277. package/dist/src/storage/google-drive/client.js +1 -0
  278. package/dist/src/storage/google-drive/index.js +1 -0
  279. package/dist/src/storage/huggingface/client.js +116 -0
  280. package/dist/src/storage/huggingface/index.js +1 -0
  281. package/dist/src/storage/index.js +16 -0
  282. package/dist/src/storage/list-bucket-raw.js +14 -0
  283. package/dist/src/storage/list-bucket-tree.js +38 -0
  284. package/dist/src/storage/local/client.js +99 -0
  285. package/dist/src/storage/local/index.js +1 -0
  286. package/dist/src/storage/memory-store.js +30 -0
  287. package/dist/src/storage/project/cleanup-layout-v1.js +72 -0
  288. package/dist/src/storage/project/folder.js +15 -0
  289. package/dist/src/storage/project/index.js +3 -0
  290. package/dist/src/storage/project/layout.js +74 -0
  291. package/dist/src/storage/project/migrate-layout-v2.js +101 -0
  292. package/dist/src/storage/project/migrate.js +73 -0
  293. package/dist/src/storage/project/scoped-provider.js +165 -0
  294. package/dist/src/storage/provider.js +26 -0
  295. package/dist/src/storage/retrying-provider.js +23 -0
  296. package/dist/src/storage/test-connection.js +32 -0
  297. package/dist/src/storage/type-resolution-store.js +26 -0
  298. package/dist/src/storage/types.js +1 -0
  299. package/dist/src/storage/vector-store.js +30 -0
  300. package/dist/src/storage/visualization-store.js +25 -0
  301. package/dist/src/sync/compressor.js +1 -0
  302. package/dist/src/sync/conflict-resolver.js +1 -0
  303. package/dist/src/sync/downloader.js +1 -0
  304. package/dist/src/sync/index.js +1 -0
  305. package/dist/src/sync/sync-engine.js +1 -0
  306. package/dist/src/sync/upload-queue.js +1 -0
  307. package/dist/src/utils/retry.js +29 -0
  308. package/dist/src/visualization/server.js +270 -0
  309. package/dist/src/work-continuity/brief-cache.js +107 -0
  310. package/dist/src/work-continuity/brief.js +349 -0
  311. package/dist/src/work-continuity/cli.js +96 -0
  312. package/dist/src/work-continuity/context-cli.js +106 -0
  313. package/dist/src/work-continuity/context-runtime-cli.js +88 -0
  314. package/dist/src/work-continuity/extractor.js +339 -0
  315. package/dist/src/work-continuity/handoff.js +185 -0
  316. package/dist/src/work-continuity/index.js +14 -0
  317. package/dist/src/work-continuity/injection.js +84 -0
  318. package/dist/src/work-continuity/journal.js +49 -0
  319. package/dist/src/work-continuity/learner.js +127 -0
  320. package/dist/src/work-continuity/reducer.js +316 -0
  321. package/dist/src/work-continuity/semantic-extractor.js +360 -0
  322. package/dist/src/work-continuity/semantic-journal.js +55 -0
  323. package/dist/src/work-continuity/semantic-learner.js +125 -0
  324. package/dist/src/work-continuity/semantic-reducer.js +268 -0
  325. package/dist/src/work-continuity/semantic-types.js +1 -0
  326. package/dist/src/work-continuity/types.js +1 -0
  327. package/dist/visualization/public/index.html +2896 -0
  328. package/dist/visualization/public/vendor/3d-force-graph.min.js +5 -0
  329. package/package.json +69 -0
@@ -0,0 +1,21 @@
1
+ export class ReferenceResolver {
2
+ graph;
3
+ constructor(graph) {
4
+ this.graph = graph;
5
+ }
6
+ findSymbol(projectId, name) {
7
+ return this.graph.findByName(projectId, name);
8
+ }
9
+ findCallers(projectId, symbolId) {
10
+ const callerIds = this.graph
11
+ .allEdges(projectId)
12
+ .filter((edge) => edge.type ===
13
+ "CALLS" &&
14
+ edge.to ===
15
+ symbolId)
16
+ .map((edge) => edge.from);
17
+ return callerIds
18
+ .map((id) => this.graph.getSymbol(id))
19
+ .filter((symbol) => Boolean(symbol));
20
+ }
21
+ }
@@ -0,0 +1,72 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeAnalysisStore, PersistentCodeGraphStore, } from "../storage/index.js";
4
+ import { CodeAnalysisEngine, CodeGraphStore, GraphQueryEngine, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const rawStorage = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
17
+ const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!graphSnapshot) {
19
+ throw new Error("Code graph missing");
20
+ }
21
+ const graph = new CodeGraphStore();
22
+ graph.import(graphSnapshot.symbols, graphSnapshot.edges);
23
+ const analysis = new CodeAnalysisEngine(graph).analyze(project.id);
24
+ await new PersistentCodeAnalysisStore(storage).save(analysis);
25
+ const query = new GraphQueryEngine(graph);
26
+ const memoryStore = query.findSymbols(project.id, "MemoryStore")[0];
27
+ console.log({
28
+ ok: true,
29
+ project: project.name,
30
+ summary: analysis.summary,
31
+ highConfidenceDeadCode: analysis.deadCode
32
+ .filter((item) => item.confidence ===
33
+ "high")
34
+ .slice(0, 20)
35
+ .map((item) => ({
36
+ symbol: item.qualifiedName ??
37
+ item.name,
38
+ type: item.type,
39
+ file: item.filePath,
40
+ line: item.startLine,
41
+ score: item.score,
42
+ })),
43
+ topDependencyHubs: analysis.dependencies
44
+ .slice()
45
+ .sort((a, b) => (b.incomingEdges +
46
+ b.outgoingEdges) -
47
+ (a.incomingEdges +
48
+ a.outgoingEdges))
49
+ .slice(0, 15)
50
+ .map((item) => ({
51
+ file: item.filePath,
52
+ dependencies: item.dependencies.length,
53
+ dependents: item.dependents.length,
54
+ incoming: item.incomingEdges,
55
+ outgoing: item.outgoingEdges,
56
+ })),
57
+ memoryStore: memoryStore
58
+ ? {
59
+ symbol: memoryStore
60
+ .qualifiedName ??
61
+ memoryStore.name,
62
+ callers: query.callers(project.id, memoryStore.id).length,
63
+ dependents: query.dependents(project.id, memoryStore.id).length,
64
+ dependencies: query.dependencies(project.id, memoryStore.id).length,
65
+ }
66
+ : null,
67
+ });
68
+ }
69
+ main().catch((error) => {
70
+ console.error(error);
71
+ process.exit(1);
72
+ });
@@ -0,0 +1,67 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentArchitectureStore, PersistentCodeGraphStore, } from "../storage/index.js";
4
+ import { ArchitectureEngine, CodeGraphStore, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const rawStorage = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
17
+ const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!graphSnapshot) {
19
+ throw new Error("Code graph missing");
20
+ }
21
+ const graph = new CodeGraphStore();
22
+ graph.import(graphSnapshot.symbols, graphSnapshot.edges);
23
+ const architecture = new ArchitectureEngine(graph).analyze(project.id);
24
+ await new PersistentArchitectureStore(storage).save(architecture);
25
+ const layerCounts = architecture.layers
26
+ .reduce((result, item) => {
27
+ result[item.layer] =
28
+ (result[item.layer] ?? 0) + 1;
29
+ return result;
30
+ }, {});
31
+ console.log({
32
+ ok: true,
33
+ project: project.name,
34
+ summary: architecture.summary,
35
+ layers: layerCounts,
36
+ topEntryPoints: architecture.entryPoints
37
+ .slice(0, 10)
38
+ .map((item) => ({
39
+ kind: item.kind,
40
+ file: item.filePath,
41
+ name: item.name,
42
+ score: item.score,
43
+ })),
44
+ topHotspots: architecture.hotspots
45
+ .slice(0, 10)
46
+ .map((item) => ({
47
+ file: item.filePath,
48
+ score: item.score,
49
+ incoming: item.incoming,
50
+ outgoing: item.outgoing,
51
+ })),
52
+ largestClusters: architecture.clusters
53
+ .slice(0, 10)
54
+ .map((item) => ({
55
+ id: item.id,
56
+ label: item.label,
57
+ subsystem: item.subsystem,
58
+ size: item.size,
59
+ cohesion: item.cohesion,
60
+ sample: item.files.slice(0, 5),
61
+ })),
62
+ });
63
+ }
64
+ main().catch((error) => {
65
+ console.error(error);
66
+ process.exit(1);
67
+ });
@@ -0,0 +1,47 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, } from "../storage/index.js";
4
+ import { CodeGraphStore, ImpactGuard, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const raw = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ?? project.name);
17
+ const snapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!snapshot) {
19
+ throw new Error("Code graph missing");
20
+ }
21
+ const graph = new CodeGraphStore();
22
+ graph.import(snapshot.symbols, snapshot.edges);
23
+ const guard = new ImpactGuard(graph);
24
+ const filePath = process.argv[2];
25
+ const result = filePath
26
+ ? guard.analyzeFile(project.id, filePath)
27
+ : await guard.analyzeGitDiff(project.id, project.rootPath);
28
+ console.log({
29
+ risk: result.risk,
30
+ riskScore: result.riskScore,
31
+ changedSymbols: result.changedSymbols.map((item) => ({
32
+ symbol: item.symbol
33
+ .qualifiedName,
34
+ file: item.symbol
35
+ .filePath,
36
+ type: item.symbol
37
+ .type,
38
+ })),
39
+ impactedFiles: result.impactedFiles,
40
+ suggestedTests: result.suggestedTests,
41
+ impactedCount: result.impacted.length,
42
+ });
43
+ }
44
+ main().catch((error) => {
45
+ console.error(error);
46
+ process.exit(1);
47
+ });
@@ -0,0 +1,24 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, ProjectScopedStorageProvider, } from "../storage/index.js";
4
+ import { IncrementalRepositoryIndexer, } from "./incremental/incremental-indexer.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager().detect();
8
+ const rawStorage = createStorageProvider({
9
+ provider: config.storage.provider,
10
+ huggingface: config.storage.huggingface,
11
+ localRoot: config.storage.localRoot,
12
+ });
13
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
14
+ const result = await new IncrementalRepositoryIndexer(storage).index(project.id, project.rootPath);
15
+ console.log({
16
+ ok: true,
17
+ storage: storage.name,
18
+ ...result,
19
+ });
20
+ }
21
+ main().catch((error) => {
22
+ console.error(error);
23
+ process.exit(1);
24
+ });
@@ -0,0 +1,39 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { RepositoryIndexer, getArchitecture, } from "./index.js";
4
+ import { createStorageProvider, PersistentCodeGraphStore, ProjectScopedStorageProvider, } from "../storage/index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const rawStorage = createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ });
14
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
15
+ const result = await new RepositoryIndexer()
16
+ .index(project.id, project.rootPath);
17
+ const architecture = getArchitecture(result.graph, project.id);
18
+ const persistent = new PersistentCodeGraphStore(storage);
19
+ await persistent.save({
20
+ version: 1,
21
+ projectId: project.id,
22
+ updatedAt: new Date()
23
+ .toISOString(),
24
+ files: result.files,
25
+ symbols: result.graph
26
+ .allSymbols(project.id),
27
+ edges: result.graph
28
+ .allEdges(project.id),
29
+ });
30
+ console.log({
31
+ ok: true,
32
+ storage: storage.name,
33
+ ...architecture,
34
+ });
35
+ }
36
+ main().catch((error) => {
37
+ console.error(error);
38
+ process.exit(1);
39
+ });
@@ -0,0 +1,54 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, PersistentTypeResolutionStore, } from "../storage/index.js";
4
+ import { CodeGraphStore, TypeScriptTypeResolver, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const rawStorage = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
17
+ const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!graphSnapshot) {
19
+ throw new Error("Code graph missing. Run code:index:test first.");
20
+ }
21
+ const graph = new CodeGraphStore();
22
+ graph.import(graphSnapshot.symbols, graphSnapshot.edges);
23
+ const resolver = new TypeScriptTypeResolver(graph);
24
+ const resolution = await resolver.resolveProject(project.id, project.rootPath);
25
+ await new PersistentTypeResolutionStore(storage).save(resolution);
26
+ console.log({
27
+ ok: true,
28
+ project: project.name,
29
+ total: resolution.total,
30
+ exact: resolution.exact,
31
+ high: resolution.high,
32
+ fallback: resolution.fallback,
33
+ exactRate: resolution.total
34
+ ? Number(((resolution.exact /
35
+ resolution.total) *
36
+ 100).toFixed(2))
37
+ : 0,
38
+ samples: resolution.resolutions
39
+ .filter((item) => item.targetFile)
40
+ .slice(0, 10)
41
+ .map((item) => ({
42
+ expression: item.expression,
43
+ from: `${item.sourceFile}:${item.sourceLine}`,
44
+ to: `${item.targetFile}:${item.targetLine ?? "?"}`,
45
+ target: item.targetQualifiedName ??
46
+ item.targetName,
47
+ confidence: item.confidence,
48
+ })),
49
+ });
50
+ }
51
+ main().catch((error) => {
52
+ console.error(error);
53
+ process.exit(1);
54
+ });
@@ -0,0 +1,48 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, PersistentTypeResolutionStore, } from "../storage/index.js";
4
+ import { CodeGraphStore, RichGraphEnricher, getArchitecture, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const raw = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ?? project.name);
17
+ const store = new PersistentCodeGraphStore(storage);
18
+ const snapshot = await store.load(project.id);
19
+ if (!snapshot) {
20
+ throw new Error("Code graph missing");
21
+ }
22
+ const graph = new CodeGraphStore();
23
+ graph.import(snapshot.symbols, snapshot.edges);
24
+ const resolution = await new PersistentTypeResolutionStore(storage).load(project.id);
25
+ const stats = new RichGraphEnricher(graph).enrich(project.id, project.rootPath, resolution);
26
+ const symbols = graph.allSymbols(project.id);
27
+ const edges = graph.allEdges(project.id);
28
+ await store.save({
29
+ version: 1,
30
+ projectId: project.id,
31
+ updatedAt: new Date()
32
+ .toISOString(),
33
+ files: symbols.filter((item) => item.type ===
34
+ "file").length,
35
+ symbols,
36
+ edges,
37
+ });
38
+ console.log({
39
+ ok: true,
40
+ project: project.name,
41
+ added: stats,
42
+ architecture: getArchitecture(graph, project.id),
43
+ });
44
+ }
45
+ main().catch((error) => {
46
+ console.error(error);
47
+ process.exit(1);
48
+ });
@@ -0,0 +1,57 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, PersistentCodeGraphStore, ProjectScopedStorageProvider, } from "../storage/index.js";
4
+ import { CodeGraphStore, SemanticCodeEngine, } from "./index.js";
5
+ import { createEmbeddingProvider, } from "../embeddings/index.js";
6
+ async function main() {
7
+ const config = loadConfig();
8
+ const project = new ProjectManager()
9
+ .detect();
10
+ const rawStorage = createStorageProvider({
11
+ provider: config.storage.provider,
12
+ huggingface: config.storage.huggingface,
13
+ localRoot: config.storage.localRoot,
14
+ });
15
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
16
+ const graph = new CodeGraphStore();
17
+ const snapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!snapshot) {
19
+ throw new Error("Code graph missing. Run npm run code:index:test first.");
20
+ }
21
+ graph.import(snapshot.symbols, snapshot.edges);
22
+ const engine = new SemanticCodeEngine({
23
+ projectId: project.id,
24
+ rootPath: project.rootPath,
25
+ model: process.env
26
+ .HF_EMBEDDING_MODEL ??
27
+ "sentence-transformers/all-MiniLM-L6-v2",
28
+ storage,
29
+ embeddings: createEmbeddingProvider(),
30
+ graph,
31
+ });
32
+ const stats = await engine.initialize();
33
+ const query = process.argv
34
+ .slice(2)
35
+ .join(" ") ||
36
+ "memory storage hugging face";
37
+ const results = await engine.search(query, 5);
38
+ console.log({
39
+ ok: true,
40
+ query,
41
+ ...stats,
42
+ results: results.map((item) => ({
43
+ score: Number(item.score
44
+ .toFixed(4)),
45
+ file: item.chunk.filePath,
46
+ symbol: item.chunk.symbolName,
47
+ lines: `${item.chunk.startLine}-${item.chunk.endLine}`,
48
+ preview: item.chunk.content
49
+ .replace(/\s+/g, " ")
50
+ .slice(0, 140),
51
+ })),
52
+ });
53
+ }
54
+ main().catch((error) => {
55
+ console.error(error);
56
+ process.exit(1);
57
+ });
@@ -0,0 +1,36 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentArchitectureStore, PersistentCodeAnalysisStore, PersistentCodeGraphStore, PersistentVisualizationStore, } from "../storage/index.js";
4
+ import { CodeGraphStore, VisualizationBuilder, } from "./index.js";
5
+ async function main() {
6
+ const config = loadConfig();
7
+ const project = new ProjectManager()
8
+ .detect();
9
+ const rawStorage = withStorageRetry(createStorageProvider({
10
+ provider: config.storage.provider,
11
+ huggingface: config.storage.huggingface,
12
+ localRoot: config.storage.localRoot,
13
+ }), {
14
+ attempts: 3,
15
+ });
16
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
17
+ const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
18
+ if (!graphSnapshot) {
19
+ throw new Error("Code graph missing");
20
+ }
21
+ const architecture = await new PersistentArchitectureStore(storage).load(project.id);
22
+ const analysis = await new PersistentCodeAnalysisStore(storage).load(project.id);
23
+ const graph = new CodeGraphStore();
24
+ graph.import(graphSnapshot.symbols, graphSnapshot.edges);
25
+ const visualization = new VisualizationBuilder(graph).build(project.id, architecture, analysis);
26
+ await new PersistentVisualizationStore(storage).save(visualization);
27
+ console.log({
28
+ ok: true,
29
+ project: project.name,
30
+ ...visualization.summary,
31
+ });
32
+ }
33
+ main().catch((error) => {
34
+ console.error(error);
35
+ process.exit(1);
36
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./types.js";
2
+ export * from "./visualization-builder.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ export class VisualizationBuilder {
2
+ graph;
3
+ constructor(graph) {
4
+ this.graph = graph;
5
+ }
6
+ build(projectId, architecture, analysis) {
7
+ const symbols = this.graph.allSymbols(projectId);
8
+ const edges = this.graph.allEdges(projectId);
9
+ const layers = new Map(architecture
10
+ ?.layers
11
+ .map((item) => [
12
+ item.filePath,
13
+ item.layer,
14
+ ]) ??
15
+ []);
16
+ const clusterByFile = new Map();
17
+ for (const cluster of architecture?.clusters ??
18
+ []) {
19
+ for (const file of cluster.files) {
20
+ clusterByFile.set(file, {
21
+ id: cluster.id,
22
+ label: cluster.label,
23
+ });
24
+ }
25
+ }
26
+ const hotspotByFile = new Map(architecture
27
+ ?.hotspots
28
+ .map((item) => [
29
+ item.filePath,
30
+ item.score,
31
+ ]) ??
32
+ []);
33
+ const deadCodeBySymbol = new Map(analysis
34
+ ?.deadCode
35
+ .map((item) => [
36
+ item.symbolId,
37
+ {
38
+ confidence: item.confidence,
39
+ score: item.score,
40
+ },
41
+ ]) ??
42
+ []);
43
+ const incoming = new Map();
44
+ const outgoing = new Map();
45
+ for (const edge of edges) {
46
+ outgoing.set(edge.from, (outgoing.get(edge.from) ?? 0) + 1);
47
+ incoming.set(edge.to, (incoming.get(edge.to) ?? 0) + 1);
48
+ }
49
+ const nodes = symbols.map((symbol) => {
50
+ const cluster = clusterByFile.get(symbol.filePath);
51
+ return {
52
+ id: symbol.id,
53
+ name: symbol.name,
54
+ qualifiedName: symbol.qualifiedName,
55
+ type: symbol.type,
56
+ filePath: symbol.filePath,
57
+ layer: layers.get(symbol.filePath),
58
+ cluster: cluster?.id,
59
+ clusterLabel: cluster?.label,
60
+ hotspotScore: hotspotByFile.get(symbol.filePath),
61
+ deadCode: deadCodeBySymbol.get(symbol.id),
62
+ incoming: incoming.get(symbol.id) ?? 0,
63
+ outgoing: outgoing.get(symbol.id) ?? 0,
64
+ };
65
+ });
66
+ const symbolIds = new Set(nodes.map((node) => node.id));
67
+ const links = edges
68
+ .filter((edge) => symbolIds.has(edge.from) &&
69
+ symbolIds.has(edge.to))
70
+ .map((edge) => ({
71
+ source: edge.from,
72
+ target: edge.to,
73
+ type: edge.type,
74
+ confidence: typeof edge.metadata
75
+ ?.confidence ===
76
+ "string"
77
+ ? edge.metadata
78
+ .confidence
79
+ : undefined,
80
+ resolver: typeof edge.metadata
81
+ ?.resolver ===
82
+ "string"
83
+ ? edge.metadata
84
+ .resolver
85
+ : undefined,
86
+ }));
87
+ return {
88
+ version: 1,
89
+ projectId,
90
+ generatedAt: new Date()
91
+ .toISOString(),
92
+ summary: {
93
+ nodes: nodes.length,
94
+ links: links.length,
95
+ files: new Set(nodes.map((node) => node.filePath)).size,
96
+ clusters: new Set(nodes
97
+ .map((node) => node.cluster)
98
+ .filter(Boolean)).size,
99
+ },
100
+ nodes,
101
+ links,
102
+ };
103
+ }
104
+ }
@@ -0,0 +1,66 @@
1
+ import "./global-env.js";
2
+ function envBool(value, fallback) {
3
+ if (value === undefined) {
4
+ return fallback;
5
+ }
6
+ return [
7
+ "1",
8
+ "true",
9
+ "yes",
10
+ "on",
11
+ ].includes(value.toLowerCase());
12
+ }
13
+ function envNumber(value, fallback) {
14
+ if (!value) {
15
+ return fallback;
16
+ }
17
+ const parsed = Number(value);
18
+ return Number.isFinite(parsed)
19
+ ? parsed
20
+ : fallback;
21
+ }
22
+ export function loadConfig() {
23
+ return {
24
+ memory: {
25
+ autoCapture: envBool(process.env
26
+ .MEMORY_AUTO_CAPTURE, true),
27
+ autoRetrieve: envBool(process.env
28
+ .MEMORY_AUTO_RETRIEVE, true),
29
+ autoSummarize: envBool(process.env
30
+ .MEMORY_AUTO_SUMMARIZE, true),
31
+ autoSync: envBool(process.env
32
+ .MEMORY_AUTO_SYNC, true),
33
+ },
34
+ retrieval: {
35
+ maxCandidates: envNumber(process.env
36
+ .MEMORY_MAX_CANDIDATES, 50),
37
+ rerankTop: envNumber(process.env
38
+ .MEMORY_RERANK_TOP, 10),
39
+ finalContext: envNumber(process.env
40
+ .MEMORY_FINAL_CONTEXT, 5),
41
+ tokenBudget: envNumber(process.env
42
+ .MEMORY_TOKEN_BUDGET, 2000),
43
+ },
44
+ storage: {
45
+ provider: process.env
46
+ .MEMORY_STORAGE_PROVIDER ??
47
+ "huggingface",
48
+ huggingface: {
49
+ namespace: process.env
50
+ .HF_NAMESPACE,
51
+ bucket: process.env
52
+ .HF_BUCKET,
53
+ accessKeyId: process.env
54
+ .HF_S3_ACCESS_KEY_ID,
55
+ secretAccessKey: process.env
56
+ .HF_S3_SECRET_ACCESS_KEY,
57
+ },
58
+ localRoot: process.env
59
+ .MEMORY_LOCAL_STORAGE_PATH,
60
+ },
61
+ cache: {
62
+ maxMb: envNumber(process.env
63
+ .MEMORY_LOCAL_CACHE_MB, 200),
64
+ },
65
+ };
66
+ }