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,34 @@
1
+ export function checkProductionConfig() {
2
+ const errors = [];
3
+ const warnings = [];
4
+ const provider = process.env
5
+ .MEMORY_STORAGE_PROVIDER ??
6
+ "local";
7
+ if (provider ===
8
+ "huggingface") {
9
+ const required = [
10
+ "HF_NAMESPACE",
11
+ "HF_BUCKET",
12
+ "HF_S3_ACCESS_KEY_ID",
13
+ "HF_S3_SECRET_ACCESS_KEY",
14
+ ];
15
+ for (const key of required) {
16
+ if (!process.env[key]) {
17
+ errors.push(`Missing ${key}`);
18
+ }
19
+ }
20
+ if (!process.env.HF_TOKEN) {
21
+ warnings.push("HF_TOKEN missing: semantic embedding will use fallback");
22
+ }
23
+ }
24
+ const model = process.env
25
+ .HF_EMBEDDING_MODEL;
26
+ if (!model) {
27
+ warnings.push("HF_EMBEDDING_MODEL not set; default model will be used");
28
+ }
29
+ return {
30
+ ok: errors.length === 0,
31
+ errors,
32
+ warnings,
33
+ };
34
+ }
@@ -0,0 +1,58 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, MemoryStore, PersistentCodeGraphStore, PersistentVectorStore, PersistentCodeChunkStore, PersistentCodeVectorStore, } from "../storage/index.js";
4
+ import { createEmbeddingProvider, } from "../embeddings/index.js";
5
+ import { SnapshotManager, } from "../snapshot/index.js";
6
+ import { checkProductionConfig, } from "./config-check.js";
7
+ import { ProductionHealth, } from "./health.js";
8
+ async function main() {
9
+ const configCheck = checkProductionConfig();
10
+ if (!configCheck.ok) {
11
+ console.log({
12
+ ok: false,
13
+ config: configCheck,
14
+ });
15
+ process.exit(1);
16
+ }
17
+ const config = loadConfig();
18
+ const project = new ProjectManager()
19
+ .detect();
20
+ const storage = withStorageRetry(createStorageProvider({
21
+ provider: config.storage.provider,
22
+ huggingface: config.storage.huggingface,
23
+ localRoot: config.storage.localRoot,
24
+ }), {
25
+ attempts: 3,
26
+ });
27
+ const embeddings = createEmbeddingProvider();
28
+ const health = await new ProductionHealth(storage, embeddings).run();
29
+ const memories = await new MemoryStore(storage).load(project.id);
30
+ const graph = await new PersistentCodeGraphStore(storage).load(project.id);
31
+ const vectors = await new PersistentVectorStore(storage).load(project.id);
32
+ const chunks = await new PersistentCodeChunkStore(storage).load(project.id);
33
+ const codeVectors = await new PersistentCodeVectorStore(storage).load(project.id);
34
+ const snapshots = await new SnapshotManager(storage).list(project.id);
35
+ console.log({
36
+ ok: health.ok,
37
+ project: project.name,
38
+ storage: health.storage,
39
+ embedding: health.embedding,
40
+ memory: memories.length,
41
+ graphSymbols: graph?.symbols.length ?? 0,
42
+ graphEdges: graph?.edges.length ?? 0,
43
+ memoryVectors: vectors?.records.length ?? 0,
44
+ codeChunks: chunks?.chunks.length ?? 0,
45
+ codeVectors: codeVectors?.records.length ?? 0,
46
+ snapshots: snapshots.length,
47
+ warnings: configCheck.warnings,
48
+ });
49
+ if (!health.ok) {
50
+ process.exit(1);
51
+ }
52
+ }
53
+ main().catch((error) => {
54
+ console.error(error instanceof Error
55
+ ? error.message
56
+ : error);
57
+ process.exit(1);
58
+ });
@@ -0,0 +1,114 @@
1
+ import { closeSync, mkdirSync, openSync, rmSync, writeFileSync, } from "node:fs";
2
+ import { join, } from "node:path";
3
+ import { ProjectManager, } from "../core/index.js";
4
+ import { runProductionIndex, } from "./index-pipeline.js";
5
+ const project = new ProjectManager()
6
+ .detect();
7
+ const toolnetDir = join(project.rootPath, ".toolnet");
8
+ const lockFile = join(toolnetDir, "index.lock");
9
+ const statusFile = join(toolnetDir, "last-index.json");
10
+ mkdirSync(toolnetDir, {
11
+ recursive: true,
12
+ });
13
+ function writeStatus(value) {
14
+ writeFileSync(statusFile, JSON.stringify(value, null, 2) + "\n", {
15
+ encoding: "utf8",
16
+ mode: 0o600,
17
+ });
18
+ }
19
+ let lockFd;
20
+ try {
21
+ lockFd =
22
+ openSync(lockFile, "wx", 0o600);
23
+ }
24
+ catch {
25
+ console.error("❌ Index already running for this project.");
26
+ console.error(`Lock: ${lockFile}`);
27
+ process.exit(2);
28
+ }
29
+ const startedAt = new Date()
30
+ .toISOString();
31
+ const completedStages = [];
32
+ try {
33
+ console.log();
34
+ console.log("==============================================");
35
+ console.log(" ToolNet Production Index");
36
+ console.log("==============================================");
37
+ console.log(`Project : ${project.name}`);
38
+ console.log(`Remote : projects/${project.remote ??
39
+ project.name}/`);
40
+ console.log("Runtime : production/dist");
41
+ console.log("Snapshot: disabled");
42
+ writeStatus({
43
+ version: 2,
44
+ state: "running",
45
+ startedAt,
46
+ completedStages,
47
+ project,
48
+ });
49
+ const result = await runProductionIndex(project, {
50
+ onStage: async (event) => {
51
+ if (event.state ===
52
+ "start") {
53
+ console.log();
54
+ console.log(`===== ${event.title} =====`);
55
+ }
56
+ else {
57
+ completedStages.push(event.id);
58
+ console.log(`✅ ${event.title} (${((event.durationMs ??
59
+ 0) /
60
+ 1000).toFixed(1)}s)`);
61
+ }
62
+ writeStatus({
63
+ version: 2,
64
+ state: "running",
65
+ startedAt,
66
+ currentStage: event.id,
67
+ completedStages: [
68
+ ...completedStages,
69
+ ],
70
+ project,
71
+ });
72
+ },
73
+ });
74
+ writeStatus({
75
+ version: 2,
76
+ state: "complete",
77
+ startedAt,
78
+ finishedAt: new Date()
79
+ .toISOString(),
80
+ completedStages,
81
+ result,
82
+ });
83
+ console.log();
84
+ console.log("==============================================");
85
+ console.log(" FULL INDEX COMPLETE ✅");
86
+ console.log("==============================================");
87
+ console.log(JSON.stringify(result, null, 2));
88
+ }
89
+ catch (error) {
90
+ writeStatus({
91
+ version: 2,
92
+ state: "failed",
93
+ startedAt,
94
+ failedAt: new Date()
95
+ .toISOString(),
96
+ completedStages,
97
+ error: error instanceof Error
98
+ ? error.message
99
+ : String(error),
100
+ });
101
+ console.error("FULL INDEX FAILED ❌");
102
+ console.error(error);
103
+ process.exitCode =
104
+ 1;
105
+ }
106
+ finally {
107
+ if (lockFd !==
108
+ undefined) {
109
+ closeSync(lockFd);
110
+ }
111
+ rmSync(lockFile, {
112
+ force: true,
113
+ });
114
+ }
@@ -0,0 +1,58 @@
1
+ import { randomUUID, } from "node:crypto";
2
+ export class ProductionHealth {
3
+ storage;
4
+ embeddings;
5
+ constructor(storage, embeddings) {
6
+ this.storage = storage;
7
+ this.embeddings = embeddings;
8
+ }
9
+ async run() {
10
+ const key = `_health/production-${randomUUID()}.txt`;
11
+ const payload = `toolnet-memory:${Date.now()}`;
12
+ let storageOk = false;
13
+ try {
14
+ await this.storage.put(key, payload, "text/plain");
15
+ const value = await this.storage.getText(key);
16
+ storageOk =
17
+ value === payload;
18
+ }
19
+ finally {
20
+ try {
21
+ await this.storage.delete(key);
22
+ }
23
+ catch {
24
+ // cleanup only
25
+ }
26
+ }
27
+ let embedding = null;
28
+ if (this.embeddings) {
29
+ try {
30
+ const vector = await this.embeddings.embed("ToolNet Memory production health check");
31
+ embedding = {
32
+ ok: vector.length > 0,
33
+ dimensions: vector.length,
34
+ mode: vector.length === 384
35
+ ? "huggingface"
36
+ : "fallback-or-custom",
37
+ };
38
+ }
39
+ catch {
40
+ embedding = {
41
+ ok: false,
42
+ dimensions: 0,
43
+ mode: "failed",
44
+ };
45
+ }
46
+ }
47
+ return {
48
+ ok: storageOk &&
49
+ (embedding === null ||
50
+ embedding.ok),
51
+ storage: {
52
+ ok: storageOk,
53
+ provider: this.storage.name,
54
+ },
55
+ embedding,
56
+ };
57
+ }
58
+ }
@@ -0,0 +1,151 @@
1
+ import { loadConfig, } from "../core/index.js";
2
+ import { createEmbeddingProvider, } from "../embeddings/index.js";
3
+ import { ArchitectureEngine, CodeAnalysisEngine, RepositoryIndexer, RichGraphEnricher, SemanticCodeEngine, TypeScriptTypeResolver, VisualizationBuilder, } from "../code-intelligence/index.js";
4
+ import { createStorageProvider, PersistentArchitectureStore, PersistentCodeAnalysisStore, PersistentCodeGraphStore, PersistentTypeResolutionStore, PersistentVisualizationStore, ProjectScopedStorageProvider, withStorageRetry, } from "../storage/index.js";
5
+ export async function runProductionIndex(project, options = {}) {
6
+ const started = Date.now();
7
+ async function stage(id, title, run) {
8
+ await options.onStage?.({
9
+ id,
10
+ title,
11
+ state: "start",
12
+ });
13
+ const stageStarted = Date.now();
14
+ const result = await run();
15
+ await options.onStage?.({
16
+ id,
17
+ title,
18
+ state: "complete",
19
+ durationMs: Date.now() -
20
+ stageStarted,
21
+ });
22
+ return result;
23
+ }
24
+ const config = loadConfig();
25
+ const rawStorage = withStorageRetry(createStorageProvider({
26
+ provider: config.storage.provider,
27
+ huggingface: config.storage.huggingface,
28
+ localRoot: config.storage.localRoot,
29
+ }), {
30
+ attempts: 3,
31
+ });
32
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ??
33
+ project.name);
34
+ const graphStore = new PersistentCodeGraphStore(storage);
35
+ /*
36
+ * 1. SOURCE INDEX
37
+ */
38
+ const indexed = await stage("source-index", "Source Index", async () => {
39
+ const result = await new RepositoryIndexer()
40
+ .index(project.id, project.rootPath);
41
+ await graphStore.save({
42
+ version: 1,
43
+ projectId: project.id,
44
+ updatedAt: new Date()
45
+ .toISOString(),
46
+ files: result.files,
47
+ symbols: result.graph
48
+ .allSymbols(project.id),
49
+ edges: result.graph
50
+ .allEdges(project.id),
51
+ });
52
+ return result;
53
+ });
54
+ const graph = indexed.graph;
55
+ /*
56
+ * 2. TYPE RESOLUTION
57
+ */
58
+ const resolution = await stage("type-resolution", "Type Resolution", async () => {
59
+ const result = await new TypeScriptTypeResolver(graph).resolveProject(project.id, project.rootPath);
60
+ await new PersistentTypeResolutionStore(storage).save(result);
61
+ return result;
62
+ });
63
+ /*
64
+ * 3. RICH GRAPH
65
+ */
66
+ await stage("rich-graph", "Rich Graph", async () => {
67
+ const stats = new RichGraphEnricher(graph).enrich(project.id, project.rootPath, resolution);
68
+ const symbols = graph.allSymbols(project.id);
69
+ const edges = graph.allEdges(project.id);
70
+ await graphStore.save({
71
+ version: 1,
72
+ projectId: project.id,
73
+ updatedAt: new Date()
74
+ .toISOString(),
75
+ files: symbols.filter(item => item.type ===
76
+ "file").length,
77
+ symbols,
78
+ edges,
79
+ });
80
+ return stats;
81
+ });
82
+ /*
83
+ * 4. SEMANTIC INDEX
84
+ */
85
+ const semantic = await stage("semantic-index", "Semantic Code Index", async () => {
86
+ const engine = new SemanticCodeEngine({
87
+ projectId: project.id,
88
+ rootPath: project.rootPath,
89
+ model: process.env
90
+ .HF_EMBEDDING_MODEL ??
91
+ "sentence-transformers/all-MiniLM-L6-v2",
92
+ storage,
93
+ embeddings: createEmbeddingProvider(),
94
+ graph,
95
+ });
96
+ return engine.initialize();
97
+ });
98
+ /*
99
+ * 5. ARCHITECTURE
100
+ */
101
+ const architecture = await stage("architecture", "Architecture Intelligence", async () => {
102
+ const result = new ArchitectureEngine(graph).analyze(project.id);
103
+ await new PersistentArchitectureStore(storage).save(result);
104
+ return result;
105
+ });
106
+ /*
107
+ * 6. ANALYSIS
108
+ */
109
+ const analysis = await stage("analysis", "Graph Analysis", async () => {
110
+ const result = new CodeAnalysisEngine(graph).analyze(project.id);
111
+ await new PersistentCodeAnalysisStore(storage).save(result);
112
+ return result;
113
+ });
114
+ /*
115
+ * 7. VISUALIZATION
116
+ */
117
+ const visualization = await stage("visualization", "3D Visualization Dataset", async () => {
118
+ const result = new VisualizationBuilder(graph).build(project.id, architecture, analysis);
119
+ await new PersistentVisualizationStore(storage).save(result);
120
+ return result;
121
+ });
122
+ return {
123
+ project: {
124
+ id: project.id,
125
+ name: project.name,
126
+ remote: project.remote ??
127
+ project.name,
128
+ },
129
+ storage: storage.name,
130
+ durationMs: Date.now() -
131
+ started,
132
+ graph: {
133
+ symbols: graph
134
+ .allSymbols(project.id)
135
+ .length,
136
+ edges: graph
137
+ .allEdges(project.id)
138
+ .length,
139
+ },
140
+ resolution: {
141
+ total: resolution.total,
142
+ exact: resolution.exact,
143
+ high: resolution.high,
144
+ fallback: resolution.fallback,
145
+ },
146
+ semantic,
147
+ architecture: architecture.summary,
148
+ analysis: analysis.summary,
149
+ visualization: visualization.summary,
150
+ };
151
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./project-lock.js";
2
+ export * from "./config-check.js";
3
+ export * from "./health.js";
4
+ export * from "./recovery.js";
@@ -0,0 +1,95 @@
1
+ import { closeSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
2
+ import { tmpdir, } from "node:os";
3
+ import { join, } from "node:path";
4
+ function processAlive(pid) {
5
+ try {
6
+ process.kill(pid, 0);
7
+ return true;
8
+ }
9
+ catch (error) {
10
+ return (error?.code ===
11
+ "EPERM");
12
+ }
13
+ }
14
+ export class ProjectLock {
15
+ acquired = false;
16
+ path;
17
+ exitHandler = () => {
18
+ this.releaseSync();
19
+ };
20
+ constructor(projectId) {
21
+ const root = join(tmpdir(), "toolnet-memory-locks");
22
+ mkdirSync(root, {
23
+ recursive: true,
24
+ });
25
+ const safeId = projectId.replace(/[^A-Za-z0-9_.-]/g, "_");
26
+ this.path =
27
+ join(root, `${safeId}.lock`);
28
+ }
29
+ async acquire() {
30
+ if (this.acquired) {
31
+ return;
32
+ }
33
+ for (let attempt = 0; attempt < 2; attempt++) {
34
+ try {
35
+ const fd = openSync(this.path, "wx");
36
+ writeFileSync(fd, JSON.stringify({
37
+ pid: process.pid,
38
+ createdAt: new Date()
39
+ .toISOString(),
40
+ }));
41
+ closeSync(fd);
42
+ this.acquired =
43
+ true;
44
+ process.once("exit", this.exitHandler);
45
+ return;
46
+ }
47
+ catch (error) {
48
+ if (error?.code !==
49
+ "EEXIST") {
50
+ throw error;
51
+ }
52
+ let stale = true;
53
+ try {
54
+ const data = JSON.parse(readFileSync(this.path, "utf8"));
55
+ if (Number.isInteger(data.pid) &&
56
+ processAlive(data.pid)) {
57
+ stale =
58
+ false;
59
+ }
60
+ }
61
+ catch {
62
+ stale =
63
+ true;
64
+ }
65
+ if (!stale) {
66
+ throw new Error("ToolNet Memory is already running for this project");
67
+ }
68
+ try {
69
+ unlinkSync(this.path);
70
+ }
71
+ catch {
72
+ // retry once
73
+ }
74
+ }
75
+ }
76
+ throw new Error("Unable to acquire ToolNet Memory project lock");
77
+ }
78
+ async release() {
79
+ this.releaseSync();
80
+ }
81
+ releaseSync() {
82
+ if (!this.acquired) {
83
+ return;
84
+ }
85
+ try {
86
+ unlinkSync(this.path);
87
+ }
88
+ catch {
89
+ // already removed
90
+ }
91
+ this.acquired =
92
+ false;
93
+ process.off("exit", this.exitHandler);
94
+ }
95
+ }
@@ -0,0 +1,16 @@
1
+ import { join, } from "node:path";
2
+ import { ProjectManager, } from "../core/index.js";
3
+ import { sanitizeProjectFolder, } from "../storage/project/folder.js";
4
+ const project = new ProjectManager()
5
+ .detect();
6
+ const remote = sanitizeProjectFolder(project.remote ??
7
+ project.name);
8
+ console.log(JSON.stringify({
9
+ id: project.id,
10
+ name: project.name,
11
+ remote,
12
+ rootPath: project.rootPath,
13
+ localManifest: join(project.rootPath, ".toolnet", "project.json"),
14
+ remoteNamespace: `projects/${remote}/`,
15
+ isolation: "1 folder = 1 project = 1 remote namespace",
16
+ }, null, 2));
@@ -0,0 +1,15 @@
1
+ import { SnapshotManager, } from "../snapshot/index.js";
2
+ export async function restoreLatestSnapshot(storage, projectId) {
3
+ const manager = new SnapshotManager(storage);
4
+ const snapshots = await manager.list(projectId);
5
+ const latest = snapshots[0];
6
+ if (!latest) {
7
+ throw new Error("No snapshot available");
8
+ }
9
+ const result = await manager.restore(projectId, latest.id);
10
+ return {
11
+ snapshot: latest.id,
12
+ createdAt: latest.createdAt,
13
+ ...result,
14
+ };
15
+ }
@@ -0,0 +1,58 @@
1
+ import "dotenv/config";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, } from "../storage/index.js";
4
+ import { SnapshotManager, } from "../snapshot/index.js";
5
+ import { restoreLatestSnapshot, } from "./recovery.js";
6
+ async function main() {
7
+ const command = process.argv[2];
8
+ const config = loadConfig();
9
+ const project = new ProjectManager()
10
+ .detect();
11
+ const rawStorage = withStorageRetry(createStorageProvider({
12
+ provider: config.storage.provider,
13
+ huggingface: config.storage.huggingface,
14
+ localRoot: config.storage.localRoot,
15
+ }), {
16
+ attempts: 3,
17
+ });
18
+ const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
19
+ const manager = new SnapshotManager(storage);
20
+ if (command === "list") {
21
+ const list = await manager.list(project.id);
22
+ console.log(list.map((snapshot) => ({
23
+ id: snapshot.id,
24
+ createdAt: snapshot.createdAt,
25
+ reason: snapshot.reason,
26
+ })));
27
+ return;
28
+ }
29
+ if (command === "create") {
30
+ const reason = process.argv
31
+ .slice(3)
32
+ .join(" ") ||
33
+ "manual-cli";
34
+ console.log(await manager.create(project.id, reason));
35
+ return;
36
+ }
37
+ if (command === "restore") {
38
+ const id = process.argv[3];
39
+ if (!id) {
40
+ throw new Error("snapshot id required");
41
+ }
42
+ await manager.create(project.id, "before-cli-restore");
43
+ console.log(await manager.restore(project.id, id));
44
+ return;
45
+ }
46
+ if (command ===
47
+ "recover-latest") {
48
+ console.log(await restoreLatestSnapshot(storage, project.id));
49
+ return;
50
+ }
51
+ throw new Error("Usage: snapshot-cli list|create|restore|recover-latest");
52
+ }
53
+ main().catch((error) => {
54
+ console.error(error instanceof Error
55
+ ? error.message
56
+ : error);
57
+ process.exit(1);
58
+ });
@@ -0,0 +1,77 @@
1
+ import { readFileSync, } from "node:fs";
2
+ import { loadConfig, ProjectManager, } from "../core/index.js";
3
+ import { createStorageProvider, ProjectScopedStorageProvider, withStorageRetry, } from "../storage/index.js";
4
+ import { ensureProjectManual, loadProjectManual, syncProjectManual, } from "./manager.js";
5
+ function after(args, flag) {
6
+ const index = args.indexOf(flag);
7
+ return index >=
8
+ 0
9
+ ? args[index + 1]
10
+ : undefined;
11
+ }
12
+ function storageFor(project) {
13
+ const config = loadConfig();
14
+ const raw = withStorageRetry(createStorageProvider({
15
+ provider: config.storage
16
+ .provider,
17
+ huggingface: config.storage
18
+ .huggingface,
19
+ localRoot: config.storage
20
+ .localRoot,
21
+ }), {
22
+ attempts: 3,
23
+ });
24
+ return new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ??
25
+ project.name);
26
+ }
27
+ async function main() {
28
+ const [command = "help", ...args] = process.argv.slice(2);
29
+ const project = new ProjectManager()
30
+ .detect(after(args, "--project") ??
31
+ process.cwd());
32
+ if (command ===
33
+ "init") {
34
+ const file = ensureProjectManual(project);
35
+ console.log(`✅ Project manual: ${file}`);
36
+ return;
37
+ }
38
+ if (command ===
39
+ "show") {
40
+ const manual = loadProjectManual(project, false);
41
+ if (!manual) {
42
+ console.log("No .toolnet/PROJECT.md yet.");
43
+ return;
44
+ }
45
+ process.stdout.write(readFileSync(manual.path, "utf8"));
46
+ return;
47
+ }
48
+ if (command ===
49
+ "sync") {
50
+ const manual = await syncProjectManual(project, storageFor(project));
51
+ console.log(JSON.stringify({
52
+ project: project.name,
53
+ path: manual.path,
54
+ digest: manual.digest,
55
+ bytes: manual.bytes,
56
+ rules: manual.rules.length,
57
+ enforce: manual.rules.filter(rule => rule.mode ===
58
+ "enforce").length,
59
+ advisory: manual.rules.filter(rule => rule.mode ===
60
+ "advisory").length,
61
+ }, null, 2));
62
+ return;
63
+ }
64
+ console.log(`Project Manual
65
+
66
+ Commands:
67
+ init [--project PATH]
68
+ show [--project PATH]
69
+ sync [--project PATH]
70
+ `);
71
+ }
72
+ main().catch(error => {
73
+ console.error(error instanceof Error
74
+ ? error.message
75
+ : error);
76
+ process.exit(1);
77
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./types.js";
2
+ export * from "./manager.js";