@stackmemoryai/stackmemory 0.5.59 → 0.5.62

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 (652) hide show
  1. package/README.md +105 -1
  2. package/dist/scripts/initialize.js +68 -1
  3. package/dist/scripts/initialize.js.map +2 -2
  4. package/dist/src/cli/claude-sm.js +130 -50
  5. package/dist/src/cli/claude-sm.js.map +2 -2
  6. package/dist/src/cli/index.js +18 -3
  7. package/dist/src/cli/index.js.map +3 -3
  8. package/dist/src/core/extensions/custom-tools.js +567 -0
  9. package/dist/src/core/extensions/custom-tools.js.map +7 -0
  10. package/dist/src/core/extensions/index.js +55 -0
  11. package/dist/src/core/extensions/index.js.map +7 -0
  12. package/dist/src/core/extensions/loader.js +709 -0
  13. package/dist/src/core/extensions/loader.js.map +7 -0
  14. package/dist/src/core/extensions/plugin-system.js +506 -0
  15. package/dist/src/core/extensions/plugin-system.js.map +7 -0
  16. package/dist/src/core/extensions/provider-adapter.js +617 -0
  17. package/dist/src/core/extensions/provider-adapter.js.map +7 -0
  18. package/dist/src/core/extensions/sandbox-runtime.js +664 -0
  19. package/dist/src/core/extensions/sandbox-runtime.js.map +7 -0
  20. package/dist/src/core/retrieval/index.js +2 -0
  21. package/dist/src/core/retrieval/index.js.map +2 -2
  22. package/dist/src/core/retrieval/privacy-filter.js +129 -0
  23. package/dist/src/core/retrieval/privacy-filter.js.map +7 -0
  24. package/dist/src/core/retrieval/unified-context-assembler.js +273 -0
  25. package/dist/src/core/retrieval/unified-context-assembler.js.map +7 -0
  26. package/dist/src/core/storage/chromadb-adapter.js +32 -6
  27. package/dist/src/core/storage/chromadb-adapter.js.map +2 -2
  28. package/dist/src/hooks/diffmem-hooks.js +377 -0
  29. package/dist/src/hooks/diffmem-hooks.js.map +7 -0
  30. package/dist/src/integrations/diffmem/client.js +209 -0
  31. package/dist/src/integrations/diffmem/client.js.map +7 -0
  32. package/dist/src/integrations/diffmem/config.js +15 -0
  33. package/dist/src/integrations/diffmem/config.js.map +7 -0
  34. package/dist/{core/session → src/integrations/diffmem}/index.js +5 -8
  35. package/dist/src/integrations/diffmem/index.js.map +7 -0
  36. package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +456 -0
  37. package/dist/src/integrations/mcp/handlers/diffmem-handlers.js.map +7 -0
  38. package/dist/src/integrations/mcp/server.js +121 -0
  39. package/dist/src/integrations/mcp/server.js.map +2 -2
  40. package/dist/src/skills/repo-ingestion-skill.js +35 -12
  41. package/dist/src/skills/repo-ingestion-skill.js.map +2 -2
  42. package/package.json +13 -7
  43. package/scripts/background-sync-manager.js +145 -83
  44. package/scripts/claude-sm-autostart.js +17 -12
  45. package/scripts/gepa/README.md +275 -0
  46. package/scripts/gepa/config.json +53 -0
  47. package/scripts/gepa/evals/coding-tasks.jsonl +5 -0
  48. package/scripts/gepa/evals/fixtures/buggy-loop.js +18 -0
  49. package/scripts/gepa/evals/fixtures/callback-hell.js +53 -0
  50. package/scripts/gepa/generations/gen-000/baseline.md +124 -0
  51. package/scripts/gepa/hooks/auto-optimize.js +494 -0
  52. package/scripts/gepa/hooks/eval-tracker.js +203 -0
  53. package/scripts/gepa/hooks/reflect.js +311 -0
  54. package/scripts/gepa/optimize.js +611 -0
  55. package/scripts/gepa/state.json +14 -0
  56. package/scripts/initialize.ts +83 -1
  57. package/scripts/test-pre-publish-quick.sh +1 -1
  58. package/dist/agents/core/agent-task-manager.js +0 -527
  59. package/dist/agents/core/agent-task-manager.js.map +0 -7
  60. package/dist/agents/testing-agent.js +0 -614
  61. package/dist/agents/testing-agent.js.map +0 -7
  62. package/dist/agents/verifiers/base-verifier.js +0 -133
  63. package/dist/agents/verifiers/base-verifier.js.map +0 -7
  64. package/dist/agents/verifiers/formatter-verifier.js +0 -130
  65. package/dist/agents/verifiers/formatter-verifier.js.map +0 -7
  66. package/dist/agents/verifiers/llm-judge.js +0 -252
  67. package/dist/agents/verifiers/llm-judge.js.map +0 -7
  68. package/dist/cli/auto-detect.js +0 -321
  69. package/dist/cli/auto-detect.js.map +0 -7
  70. package/dist/cli/browser-test.js +0 -33
  71. package/dist/cli/browser-test.js.map +0 -7
  72. package/dist/cli/claude-sm-danger.js +0 -21
  73. package/dist/cli/claude-sm-danger.js.map +0 -7
  74. package/dist/cli/claude-sm.js +0 -1156
  75. package/dist/cli/claude-sm.js.map +0 -7
  76. package/dist/cli/codex-sm-danger.js +0 -21
  77. package/dist/cli/codex-sm-danger.js.map +0 -7
  78. package/dist/cli/codex-sm.js +0 -349
  79. package/dist/cli/codex-sm.js.map +0 -7
  80. package/dist/cli/commands/api.js +0 -232
  81. package/dist/cli/commands/api.js.map +0 -7
  82. package/dist/cli/commands/auto-background.js +0 -180
  83. package/dist/cli/commands/auto-background.js.map +0 -7
  84. package/dist/cli/commands/cleanup-processes.js +0 -68
  85. package/dist/cli/commands/cleanup-processes.js.map +0 -7
  86. package/dist/cli/commands/clear.js +0 -202
  87. package/dist/cli/commands/clear.js.map +0 -7
  88. package/dist/cli/commands/config.js +0 -445
  89. package/dist/cli/commands/config.js.map +0 -7
  90. package/dist/cli/commands/context-rehydrate.js +0 -751
  91. package/dist/cli/commands/context-rehydrate.js.map +0 -7
  92. package/dist/cli/commands/context.js +0 -343
  93. package/dist/cli/commands/context.js.map +0 -7
  94. package/dist/cli/commands/daemon.js +0 -392
  95. package/dist/cli/commands/daemon.js.map +0 -7
  96. package/dist/cli/commands/dashboard.js +0 -210
  97. package/dist/cli/commands/dashboard.js.map +0 -7
  98. package/dist/cli/commands/db.js +0 -147
  99. package/dist/cli/commands/db.js.map +0 -7
  100. package/dist/cli/commands/decision.js +0 -266
  101. package/dist/cli/commands/decision.js.map +0 -7
  102. package/dist/cli/commands/discovery.js +0 -279
  103. package/dist/cli/commands/discovery.js.map +0 -7
  104. package/dist/cli/commands/handoff.js +0 -624
  105. package/dist/cli/commands/handoff.js.map +0 -7
  106. package/dist/cli/commands/hooks.js +0 -298
  107. package/dist/cli/commands/hooks.js.map +0 -7
  108. package/dist/cli/commands/linear-unified.js +0 -353
  109. package/dist/cli/commands/linear-unified.js.map +0 -7
  110. package/dist/cli/commands/linear.js +0 -529
  111. package/dist/cli/commands/linear.js.map +0 -7
  112. package/dist/cli/commands/log.js +0 -169
  113. package/dist/cli/commands/log.js.map +0 -7
  114. package/dist/cli/commands/login.js +0 -172
  115. package/dist/cli/commands/login.js.map +0 -7
  116. package/dist/cli/commands/migrate.js +0 -240
  117. package/dist/cli/commands/migrate.js.map +0 -7
  118. package/dist/cli/commands/model.js +0 -533
  119. package/dist/cli/commands/model.js.map +0 -7
  120. package/dist/cli/commands/monitor.js +0 -313
  121. package/dist/cli/commands/monitor.js.map +0 -7
  122. package/dist/cli/commands/onboard.js +0 -536
  123. package/dist/cli/commands/onboard.js.map +0 -7
  124. package/dist/cli/commands/projects.js +0 -199
  125. package/dist/cli/commands/projects.js.map +0 -7
  126. package/dist/cli/commands/quality.js +0 -413
  127. package/dist/cli/commands/quality.js.map +0 -7
  128. package/dist/cli/commands/ralph.js +0 -909
  129. package/dist/cli/commands/ralph.js.map +0 -7
  130. package/dist/cli/commands/retrieval.js +0 -248
  131. package/dist/cli/commands/retrieval.js.map +0 -7
  132. package/dist/cli/commands/search.js +0 -173
  133. package/dist/cli/commands/search.js.map +0 -7
  134. package/dist/cli/commands/service.js +0 -749
  135. package/dist/cli/commands/service.js.map +0 -7
  136. package/dist/cli/commands/session.js +0 -200
  137. package/dist/cli/commands/session.js.map +0 -7
  138. package/dist/cli/commands/settings.js +0 -306
  139. package/dist/cli/commands/settings.js.map +0 -7
  140. package/dist/cli/commands/setup.js +0 -701
  141. package/dist/cli/commands/setup.js.map +0 -7
  142. package/dist/cli/commands/shell.js +0 -249
  143. package/dist/cli/commands/shell.js.map +0 -7
  144. package/dist/cli/commands/signup.js +0 -50
  145. package/dist/cli/commands/signup.js.map +0 -7
  146. package/dist/cli/commands/skills.js +0 -470
  147. package/dist/cli/commands/skills.js.map +0 -7
  148. package/dist/cli/commands/sms-notify.js +0 -795
  149. package/dist/cli/commands/sms-notify.js.map +0 -7
  150. package/dist/cli/commands/storage-tier.js +0 -183
  151. package/dist/cli/commands/storage-tier.js.map +0 -7
  152. package/dist/cli/commands/storage.js +0 -360
  153. package/dist/cli/commands/storage.js.map +0 -7
  154. package/dist/cli/commands/sweep.js +0 -249
  155. package/dist/cli/commands/sweep.js.map +0 -7
  156. package/dist/cli/commands/tasks.js +0 -213
  157. package/dist/cli/commands/tasks.js.map +0 -7
  158. package/dist/cli/commands/test.js +0 -286
  159. package/dist/cli/commands/test.js.map +0 -7
  160. package/dist/cli/commands/workflow.js +0 -142
  161. package/dist/cli/commands/workflow.js.map +0 -7
  162. package/dist/cli/commands/worktree.js +0 -319
  163. package/dist/cli/commands/worktree.js.map +0 -7
  164. package/dist/cli/index.js +0 -594
  165. package/dist/cli/index.js.map +0 -7
  166. package/dist/cli/opencode-sm.js +0 -448
  167. package/dist/cli/opencode-sm.js.map +0 -7
  168. package/dist/cli/utils/viewer.js +0 -96
  169. package/dist/cli/utils/viewer.js.map +0 -7
  170. package/dist/core/analytics/team-analytics.js +0 -378
  171. package/dist/core/analytics/team-analytics.js.map +0 -7
  172. package/dist/core/config/config-manager.js +0 -398
  173. package/dist/core/config/config-manager.js.map +0 -7
  174. package/dist/core/config/feature-flags.js +0 -76
  175. package/dist/core/config/feature-flags.js.map +0 -7
  176. package/dist/core/config/storage-config.js +0 -115
  177. package/dist/core/config/storage-config.js.map +0 -7
  178. package/dist/core/config/types.js +0 -144
  179. package/dist/core/config/types.js.map +0 -7
  180. package/dist/core/context/auto-context.js +0 -80
  181. package/dist/core/context/auto-context.js.map +0 -7
  182. package/dist/core/context/dual-stack-manager.js +0 -870
  183. package/dist/core/context/dual-stack-manager.js.map +0 -7
  184. package/dist/core/context/enhanced-rehydration.js +0 -994
  185. package/dist/core/context/enhanced-rehydration.js.map +0 -7
  186. package/dist/core/context/frame-database.js +0 -479
  187. package/dist/core/context/frame-database.js.map +0 -7
  188. package/dist/core/context/frame-digest.js +0 -250
  189. package/dist/core/context/frame-digest.js.map +0 -7
  190. package/dist/core/context/frame-handoff-manager.js +0 -778
  191. package/dist/core/context/frame-handoff-manager.js.map +0 -7
  192. package/dist/core/context/frame-lifecycle-hooks.js +0 -119
  193. package/dist/core/context/frame-lifecycle-hooks.js.map +0 -7
  194. package/dist/core/context/frame-manager.js +0 -1069
  195. package/dist/core/context/frame-manager.js.map +0 -7
  196. package/dist/core/context/frame-recovery.js +0 -302
  197. package/dist/core/context/frame-recovery.js.map +0 -7
  198. package/dist/core/context/frame-stack.js +0 -314
  199. package/dist/core/context/frame-stack.js.map +0 -7
  200. package/dist/core/context/frame-types.js +0 -5
  201. package/dist/core/context/frame-types.js.map +0 -7
  202. package/dist/core/context/incremental-gc.js +0 -290
  203. package/dist/core/context/incremental-gc.js.map +0 -7
  204. package/dist/core/context/index.js +0 -25
  205. package/dist/core/context/index.js.map +0 -7
  206. package/dist/core/context/model-aware-compaction.js +0 -623
  207. package/dist/core/context/model-aware-compaction.js.map +0 -7
  208. package/dist/core/context/permission-manager.js +0 -185
  209. package/dist/core/context/permission-manager.js.map +0 -7
  210. package/dist/core/context/recursive-context-manager.js +0 -592
  211. package/dist/core/context/recursive-context-manager.js.map +0 -7
  212. package/dist/core/context/refactored-frame-manager.js +0 -754
  213. package/dist/core/context/refactored-frame-manager.js.map +0 -7
  214. package/dist/core/context/shared-context-layer.js +0 -621
  215. package/dist/core/context/shared-context-layer.js.map +0 -7
  216. package/dist/core/context/stack-merge-resolver.js +0 -749
  217. package/dist/core/context/stack-merge-resolver.js.map +0 -7
  218. package/dist/core/context/validation.js +0 -130
  219. package/dist/core/context/validation.js.map +0 -7
  220. package/dist/core/database/batch-operations.js +0 -384
  221. package/dist/core/database/batch-operations.js.map +0 -7
  222. package/dist/core/database/connection-pool.js +0 -330
  223. package/dist/core/database/connection-pool.js.map +0 -7
  224. package/dist/core/database/database-adapter.js +0 -60
  225. package/dist/core/database/database-adapter.js.map +0 -7
  226. package/dist/core/database/migration-manager.js +0 -614
  227. package/dist/core/database/migration-manager.js.map +0 -7
  228. package/dist/core/database/paradedb-adapter.js +0 -990
  229. package/dist/core/database/paradedb-adapter.js.map +0 -7
  230. package/dist/core/database/query-cache.js +0 -298
  231. package/dist/core/database/query-cache.js.map +0 -7
  232. package/dist/core/database/query-router.js +0 -430
  233. package/dist/core/database/query-router.js.map +0 -7
  234. package/dist/core/database/sqlite-adapter.js +0 -738
  235. package/dist/core/database/sqlite-adapter.js.map +0 -7
  236. package/dist/core/digest/enhanced-hybrid-digest.js +0 -277
  237. package/dist/core/digest/enhanced-hybrid-digest.js.map +0 -7
  238. package/dist/core/digest/frame-digest-integration.js +0 -176
  239. package/dist/core/digest/frame-digest-integration.js.map +0 -7
  240. package/dist/core/digest/hybrid-digest-generator.js +0 -553
  241. package/dist/core/digest/hybrid-digest-generator.js.map +0 -7
  242. package/dist/core/digest/index.js +0 -9
  243. package/dist/core/digest/index.js.map +0 -7
  244. package/dist/core/digest/types.js +0 -25
  245. package/dist/core/digest/types.js.map +0 -7
  246. package/dist/core/errors/error-utils.js +0 -208
  247. package/dist/core/errors/error-utils.js.map +0 -7
  248. package/dist/core/errors/index.js +0 -521
  249. package/dist/core/errors/index.js.map +0 -7
  250. package/dist/core/errors/recovery.js +0 -269
  251. package/dist/core/errors/recovery.js.map +0 -7
  252. package/dist/core/execution/parallel-executor.js +0 -258
  253. package/dist/core/execution/parallel-executor.js.map +0 -7
  254. package/dist/core/frame/workflow-templates.js +0 -319
  255. package/dist/core/frame/workflow-templates.js.map +0 -7
  256. package/dist/core/merge/conflict-detector.js +0 -431
  257. package/dist/core/merge/conflict-detector.js.map +0 -7
  258. package/dist/core/merge/index.js +0 -9
  259. package/dist/core/merge/index.js.map +0 -7
  260. package/dist/core/merge/resolution-engine.js +0 -558
  261. package/dist/core/merge/resolution-engine.js.map +0 -7
  262. package/dist/core/merge/stack-diff.js +0 -532
  263. package/dist/core/merge/stack-diff.js.map +0 -7
  264. package/dist/core/merge/unified-merge-resolver.js +0 -303
  265. package/dist/core/merge/unified-merge-resolver.js.map +0 -7
  266. package/dist/core/models/fallback-monitor.js +0 -232
  267. package/dist/core/models/fallback-monitor.js.map +0 -7
  268. package/dist/core/models/model-router.js +0 -340
  269. package/dist/core/models/model-router.js.map +0 -7
  270. package/dist/core/monitoring/error-handler.js +0 -49
  271. package/dist/core/monitoring/error-handler.js.map +0 -7
  272. package/dist/core/monitoring/logger.js +0 -202
  273. package/dist/core/monitoring/logger.js.map +0 -7
  274. package/dist/core/monitoring/metrics.js +0 -172
  275. package/dist/core/monitoring/metrics.js.map +0 -7
  276. package/dist/core/monitoring/progress-tracker.js +0 -189
  277. package/dist/core/monitoring/progress-tracker.js.map +0 -7
  278. package/dist/core/monitoring/session-monitor.js +0 -300
  279. package/dist/core/monitoring/session-monitor.js.map +0 -7
  280. package/dist/core/performance/context-cache.js +0 -273
  281. package/dist/core/performance/context-cache.js.map +0 -7
  282. package/dist/core/performance/index.js +0 -11
  283. package/dist/core/performance/index.js.map +0 -7
  284. package/dist/core/performance/lazy-context-loader.js +0 -327
  285. package/dist/core/performance/lazy-context-loader.js.map +0 -7
  286. package/dist/core/performance/monitor.js +0 -221
  287. package/dist/core/performance/monitor.js.map +0 -7
  288. package/dist/core/performance/optimized-frame-context.js +0 -345
  289. package/dist/core/performance/optimized-frame-context.js.map +0 -7
  290. package/dist/core/performance/performance-benchmark.js +0 -277
  291. package/dist/core/performance/performance-benchmark.js.map +0 -7
  292. package/dist/core/performance/performance-profiler.js +0 -370
  293. package/dist/core/performance/performance-profiler.js.map +0 -7
  294. package/dist/core/performance/streaming-jsonl-parser.js +0 -195
  295. package/dist/core/performance/streaming-jsonl-parser.js.map +0 -7
  296. package/dist/core/persistence/postgres-adapter.js +0 -349
  297. package/dist/core/persistence/postgres-adapter.js.map +0 -7
  298. package/dist/core/projects/project-isolation.js +0 -201
  299. package/dist/core/projects/project-isolation.js.map +0 -7
  300. package/dist/core/projects/project-manager.js +0 -697
  301. package/dist/core/projects/project-manager.js.map +0 -7
  302. package/dist/core/query/query-parser.js +0 -370
  303. package/dist/core/query/query-parser.js.map +0 -7
  304. package/dist/core/query/query-templates.js +0 -321
  305. package/dist/core/query/query-templates.js.map +0 -7
  306. package/dist/core/retrieval/context-retriever.js +0 -479
  307. package/dist/core/retrieval/context-retriever.js.map +0 -7
  308. package/dist/core/retrieval/graph-retrieval.js +0 -662
  309. package/dist/core/retrieval/graph-retrieval.js.map +0 -7
  310. package/dist/core/retrieval/hierarchical-retrieval.js +0 -656
  311. package/dist/core/retrieval/hierarchical-retrieval.js.map +0 -7
  312. package/dist/core/retrieval/index.js +0 -8
  313. package/dist/core/retrieval/index.js.map +0 -7
  314. package/dist/core/retrieval/llm-context-retrieval.js +0 -613
  315. package/dist/core/retrieval/llm-context-retrieval.js.map +0 -7
  316. package/dist/core/retrieval/llm-provider.js +0 -151
  317. package/dist/core/retrieval/llm-provider.js.map +0 -7
  318. package/dist/core/retrieval/retrieval-audit.js +0 -236
  319. package/dist/core/retrieval/retrieval-audit.js.map +0 -7
  320. package/dist/core/retrieval/retrieval-benchmarks.js +0 -521
  321. package/dist/core/retrieval/retrieval-benchmarks.js.map +0 -7
  322. package/dist/core/retrieval/summary-generator.js +0 -589
  323. package/dist/core/retrieval/summary-generator.js.map +0 -7
  324. package/dist/core/retrieval/types.js +0 -21
  325. package/dist/core/retrieval/types.js.map +0 -7
  326. package/dist/core/security/index.js +0 -35
  327. package/dist/core/security/index.js.map +0 -7
  328. package/dist/core/security/input-sanitizer.js +0 -321
  329. package/dist/core/security/input-sanitizer.js.map +0 -7
  330. package/dist/core/session/clear-survival.js +0 -465
  331. package/dist/core/session/clear-survival.js.map +0 -7
  332. package/dist/core/session/enhanced-handoff.js +0 -792
  333. package/dist/core/session/enhanced-handoff.js.map +0 -7
  334. package/dist/core/session/handoff-generator.js +0 -343
  335. package/dist/core/session/handoff-generator.js.map +0 -7
  336. package/dist/core/session/index.js.map +0 -7
  337. package/dist/core/session/session-manager.js +0 -347
  338. package/dist/core/session/session-manager.js.map +0 -7
  339. package/dist/core/skills/index.js +0 -7
  340. package/dist/core/skills/index.js.map +0 -7
  341. package/dist/core/skills/skill-storage.js +0 -764
  342. package/dist/core/skills/skill-storage.js.map +0 -7
  343. package/dist/core/skills/types.js +0 -193
  344. package/dist/core/skills/types.js.map +0 -7
  345. package/dist/core/storage/chromadb-adapter.js +0 -354
  346. package/dist/core/storage/chromadb-adapter.js.map +0 -7
  347. package/dist/core/storage/infinite-storage.js +0 -510
  348. package/dist/core/storage/infinite-storage.js.map +0 -7
  349. package/dist/core/storage/railway-optimized-storage.js +0 -591
  350. package/dist/core/storage/railway-optimized-storage.js.map +0 -7
  351. package/dist/core/storage/remote-storage.js +0 -489
  352. package/dist/core/storage/remote-storage.js.map +0 -7
  353. package/dist/core/storage/two-tier-storage.js +0 -766
  354. package/dist/core/storage/two-tier-storage.js.map +0 -7
  355. package/dist/core/trace/cli-trace-wrapper.js +0 -132
  356. package/dist/core/trace/cli-trace-wrapper.js.map +0 -7
  357. package/dist/core/trace/db-trace-wrapper.js +0 -247
  358. package/dist/core/trace/db-trace-wrapper.js.map +0 -7
  359. package/dist/core/trace/debug-trace.js +0 -417
  360. package/dist/core/trace/debug-trace.js.map +0 -7
  361. package/dist/core/trace/index.js +0 -109
  362. package/dist/core/trace/index.js.map +0 -7
  363. package/dist/core/trace/linear-api-wrapper.js +0 -178
  364. package/dist/core/trace/linear-api-wrapper.js.map +0 -7
  365. package/dist/core/trace/trace-demo.js +0 -154
  366. package/dist/core/trace/trace-demo.js.map +0 -7
  367. package/dist/core/trace/trace-detector.demo.js +0 -142
  368. package/dist/core/trace/trace-detector.demo.js.map +0 -7
  369. package/dist/core/trace/trace-detector.js +0 -528
  370. package/dist/core/trace/trace-detector.js.map +0 -7
  371. package/dist/core/trace/trace-store.js +0 -345
  372. package/dist/core/trace/trace-store.js.map +0 -7
  373. package/dist/core/trace/types.js +0 -77
  374. package/dist/core/trace/types.js.map +0 -7
  375. package/dist/core/utils/async-mutex.js +0 -114
  376. package/dist/core/utils/async-mutex.js.map +0 -7
  377. package/dist/core/utils/compression.js +0 -83
  378. package/dist/core/utils/compression.js.map +0 -7
  379. package/dist/core/utils/update-checker.js +0 -218
  380. package/dist/core/utils/update-checker.js.map +0 -7
  381. package/dist/core/worktree/worktree-manager.js +0 -465
  382. package/dist/core/worktree/worktree-manager.js.map +0 -7
  383. package/dist/daemon/daemon-config.js +0 -149
  384. package/dist/daemon/daemon-config.js.map +0 -7
  385. package/dist/daemon/services/context-service.js +0 -122
  386. package/dist/daemon/services/context-service.js.map +0 -7
  387. package/dist/daemon/services/linear-service.js +0 -136
  388. package/dist/daemon/services/linear-service.js.map +0 -7
  389. package/dist/daemon/session-daemon.js +0 -312
  390. package/dist/daemon/session-daemon.js.map +0 -7
  391. package/dist/daemon/unified-daemon.js +0 -276
  392. package/dist/daemon/unified-daemon.js.map +0 -7
  393. package/dist/features/analytics/api/analytics-api.js +0 -287
  394. package/dist/features/analytics/api/analytics-api.js.map +0 -7
  395. package/dist/features/analytics/core/analytics-service.js +0 -282
  396. package/dist/features/analytics/core/analytics-service.js.map +0 -7
  397. package/dist/features/analytics/index.js +0 -18
  398. package/dist/features/analytics/index.js.map +0 -7
  399. package/dist/features/analytics/queries/metrics-queries.js +0 -277
  400. package/dist/features/analytics/queries/metrics-queries.js.map +0 -7
  401. package/dist/features/analytics/types/metrics.js +0 -5
  402. package/dist/features/analytics/types/metrics.js.map +0 -7
  403. package/dist/features/browser/browser-mcp.js +0 -492
  404. package/dist/features/browser/browser-mcp.js.map +0 -7
  405. package/dist/features/sweep/index.js +0 -20
  406. package/dist/features/sweep/index.js.map +0 -7
  407. package/dist/features/sweep/prediction-client.js +0 -155
  408. package/dist/features/sweep/prediction-client.js.map +0 -7
  409. package/dist/features/sweep/prompt-builder.js +0 -85
  410. package/dist/features/sweep/prompt-builder.js.map +0 -7
  411. package/dist/features/sweep/pty-wrapper.js +0 -171
  412. package/dist/features/sweep/pty-wrapper.js.map +0 -7
  413. package/dist/features/sweep/state-watcher.js +0 -87
  414. package/dist/features/sweep/state-watcher.js.map +0 -7
  415. package/dist/features/sweep/status-bar.js +0 -88
  416. package/dist/features/sweep/status-bar.js.map +0 -7
  417. package/dist/features/sweep/sweep-server-manager.js +0 -226
  418. package/dist/features/sweep/sweep-server-manager.js.map +0 -7
  419. package/dist/features/sweep/tab-interceptor.js +0 -38
  420. package/dist/features/sweep/tab-interceptor.js.map +0 -7
  421. package/dist/features/sweep/types.js +0 -18
  422. package/dist/features/sweep/types.js.map +0 -7
  423. package/dist/features/tasks/linear-task-manager.js +0 -487
  424. package/dist/features/tasks/linear-task-manager.js.map +0 -7
  425. package/dist/features/tasks/task-aware-context.js +0 -410
  426. package/dist/features/tasks/task-aware-context.js.map +0 -7
  427. package/dist/features/tui/simple-monitor.js +0 -116
  428. package/dist/features/tui/simple-monitor.js.map +0 -7
  429. package/dist/features/tui/swarm-monitor.js +0 -648
  430. package/dist/features/tui/swarm-monitor.js.map +0 -7
  431. package/dist/features/web/client/stores/task-store.js +0 -26
  432. package/dist/features/web/client/stores/task-store.js.map +0 -7
  433. package/dist/features/web/server/index.js +0 -194
  434. package/dist/features/web/server/index.js.map +0 -7
  435. package/dist/hooks/auto-background.js +0 -151
  436. package/dist/hooks/auto-background.js.map +0 -7
  437. package/dist/hooks/claude-code-whatsapp-hook.js +0 -197
  438. package/dist/hooks/claude-code-whatsapp-hook.js.map +0 -7
  439. package/dist/hooks/config.js +0 -150
  440. package/dist/hooks/config.js.map +0 -7
  441. package/dist/hooks/daemon.js +0 -364
  442. package/dist/hooks/daemon.js.map +0 -7
  443. package/dist/hooks/events.js +0 -58
  444. package/dist/hooks/events.js.map +0 -7
  445. package/dist/hooks/index.js +0 -12
  446. package/dist/hooks/index.js.map +0 -7
  447. package/dist/hooks/linear-task-picker.js +0 -186
  448. package/dist/hooks/linear-task-picker.js.map +0 -7
  449. package/dist/hooks/schemas.js +0 -197
  450. package/dist/hooks/schemas.js.map +0 -7
  451. package/dist/hooks/secure-fs.js +0 -49
  452. package/dist/hooks/secure-fs.js.map +0 -7
  453. package/dist/hooks/security-logger.js +0 -155
  454. package/dist/hooks/security-logger.js.map +0 -7
  455. package/dist/hooks/session-summary.js +0 -222
  456. package/dist/hooks/session-summary.js.map +0 -7
  457. package/dist/hooks/sms-action-runner.js +0 -371
  458. package/dist/hooks/sms-action-runner.js.map +0 -7
  459. package/dist/hooks/sms-notify.js +0 -506
  460. package/dist/hooks/sms-notify.js.map +0 -7
  461. package/dist/hooks/sms-watcher.js +0 -93
  462. package/dist/hooks/sms-watcher.js.map +0 -7
  463. package/dist/hooks/sms-webhook.js +0 -555
  464. package/dist/hooks/sms-webhook.js.map +0 -7
  465. package/dist/hooks/whatsapp-commands.js +0 -479
  466. package/dist/hooks/whatsapp-commands.js.map +0 -7
  467. package/dist/hooks/whatsapp-scheduler.js +0 -317
  468. package/dist/hooks/whatsapp-scheduler.js.map +0 -7
  469. package/dist/hooks/whatsapp-sync.js +0 -409
  470. package/dist/hooks/whatsapp-sync.js.map +0 -7
  471. package/dist/index.js +0 -25
  472. package/dist/index.js.map +0 -7
  473. package/dist/integrations/anthropic/client.js +0 -263
  474. package/dist/integrations/anthropic/client.js.map +0 -7
  475. package/dist/integrations/claude-code/agent-bridge.js +0 -768
  476. package/dist/integrations/claude-code/agent-bridge.js.map +0 -7
  477. package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js +0 -459
  478. package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js.map +0 -7
  479. package/dist/integrations/claude-code/lifecycle-hooks.js +0 -254
  480. package/dist/integrations/claude-code/lifecycle-hooks.js.map +0 -7
  481. package/dist/integrations/claude-code/post-task-hooks.js +0 -545
  482. package/dist/integrations/claude-code/post-task-hooks.js.map +0 -7
  483. package/dist/integrations/claude-code/subagent-client-stub.js +0 -20
  484. package/dist/integrations/claude-code/subagent-client-stub.js.map +0 -7
  485. package/dist/integrations/claude-code/subagent-client.js +0 -511
  486. package/dist/integrations/claude-code/subagent-client.js.map +0 -7
  487. package/dist/integrations/claude-code/task-coordinator.js +0 -360
  488. package/dist/integrations/claude-code/task-coordinator.js.map +0 -7
  489. package/dist/integrations/linear/auth.js +0 -337
  490. package/dist/integrations/linear/auth.js.map +0 -7
  491. package/dist/integrations/linear/auto-sync.js +0 -258
  492. package/dist/integrations/linear/auto-sync.js.map +0 -7
  493. package/dist/integrations/linear/client.js +0 -634
  494. package/dist/integrations/linear/client.js.map +0 -7
  495. package/dist/integrations/linear/config.js +0 -130
  496. package/dist/integrations/linear/config.js.map +0 -7
  497. package/dist/integrations/linear/migration.js +0 -361
  498. package/dist/integrations/linear/migration.js.map +0 -7
  499. package/dist/integrations/linear/oauth-server.js +0 -454
  500. package/dist/integrations/linear/oauth-server.js.map +0 -7
  501. package/dist/integrations/linear/rest-client.js +0 -213
  502. package/dist/integrations/linear/rest-client.js.map +0 -7
  503. package/dist/integrations/linear/sync-manager.js +0 -236
  504. package/dist/integrations/linear/sync-manager.js.map +0 -7
  505. package/dist/integrations/linear/sync-service.js +0 -231
  506. package/dist/integrations/linear/sync-service.js.map +0 -7
  507. package/dist/integrations/linear/sync.js +0 -782
  508. package/dist/integrations/linear/sync.js.map +0 -7
  509. package/dist/integrations/linear/types.js +0 -5
  510. package/dist/integrations/linear/types.js.map +0 -7
  511. package/dist/integrations/linear/unified-sync.js +0 -589
  512. package/dist/integrations/linear/unified-sync.js.map +0 -7
  513. package/dist/integrations/linear/webhook-handler.js +0 -219
  514. package/dist/integrations/linear/webhook-handler.js.map +0 -7
  515. package/dist/integrations/linear/webhook-server.js +0 -218
  516. package/dist/integrations/linear/webhook-server.js.map +0 -7
  517. package/dist/integrations/linear/webhook.js +0 -291
  518. package/dist/integrations/linear/webhook.js.map +0 -7
  519. package/dist/integrations/mcp/handlers/code-execution-handlers.js +0 -266
  520. package/dist/integrations/mcp/handlers/code-execution-handlers.js.map +0 -7
  521. package/dist/integrations/mcp/handlers/context-handlers.js +0 -257
  522. package/dist/integrations/mcp/handlers/context-handlers.js.map +0 -7
  523. package/dist/integrations/mcp/handlers/discovery-handlers.js +0 -497
  524. package/dist/integrations/mcp/handlers/discovery-handlers.js.map +0 -7
  525. package/dist/integrations/mcp/handlers/index.js +0 -166
  526. package/dist/integrations/mcp/handlers/index.js.map +0 -7
  527. package/dist/integrations/mcp/handlers/linear-handlers.js +0 -247
  528. package/dist/integrations/mcp/handlers/linear-handlers.js.map +0 -7
  529. package/dist/integrations/mcp/handlers/skill-handlers.js +0 -529
  530. package/dist/integrations/mcp/handlers/skill-handlers.js.map +0 -7
  531. package/dist/integrations/mcp/handlers/task-handlers.js +0 -239
  532. package/dist/integrations/mcp/handlers/task-handlers.js.map +0 -7
  533. package/dist/integrations/mcp/handlers/trace-handlers.js +0 -308
  534. package/dist/integrations/mcp/handlers/trace-handlers.js.map +0 -7
  535. package/dist/integrations/mcp/index.js +0 -23
  536. package/dist/integrations/mcp/index.js.map +0 -7
  537. package/dist/integrations/mcp/middleware/tool-scoring.js +0 -356
  538. package/dist/integrations/mcp/middleware/tool-scoring.js.map +0 -7
  539. package/dist/integrations/mcp/refactored-server.js +0 -374
  540. package/dist/integrations/mcp/refactored-server.js.map +0 -7
  541. package/dist/integrations/mcp/remote-server.js +0 -682
  542. package/dist/integrations/mcp/remote-server.js.map +0 -7
  543. package/dist/integrations/mcp/schemas.js +0 -147
  544. package/dist/integrations/mcp/schemas.js.map +0 -7
  545. package/dist/integrations/mcp/server.js +0 -1975
  546. package/dist/integrations/mcp/server.js.map +0 -7
  547. package/dist/integrations/mcp/tool-definitions-code.js +0 -125
  548. package/dist/integrations/mcp/tool-definitions-code.js.map +0 -7
  549. package/dist/integrations/mcp/tool-definitions.js +0 -702
  550. package/dist/integrations/mcp/tool-definitions.js.map +0 -7
  551. package/dist/integrations/mcp/trace-test.js +0 -48
  552. package/dist/integrations/mcp/trace-test.js.map +0 -7
  553. package/dist/integrations/pg-aiguide/embedding-provider.js +0 -189
  554. package/dist/integrations/pg-aiguide/embedding-provider.js.map +0 -7
  555. package/dist/integrations/pg-aiguide/semantic-search.js +0 -187
  556. package/dist/integrations/pg-aiguide/semantic-search.js.map +0 -7
  557. package/dist/integrations/pg-aiguide/timescale-analytics.js +0 -224
  558. package/dist/integrations/pg-aiguide/timescale-analytics.js.map +0 -7
  559. package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -860
  560. package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +0 -7
  561. package/dist/integrations/ralph/context/context-budget-manager.js +0 -301
  562. package/dist/integrations/ralph/context/context-budget-manager.js.map +0 -7
  563. package/dist/integrations/ralph/context/stackmemory-context-loader.js +0 -360
  564. package/dist/integrations/ralph/context/stackmemory-context-loader.js.map +0 -7
  565. package/dist/integrations/ralph/coordination/enhanced-coordination.js +0 -410
  566. package/dist/integrations/ralph/coordination/enhanced-coordination.js.map +0 -7
  567. package/dist/integrations/ralph/index.js +0 -18
  568. package/dist/integrations/ralph/index.js.map +0 -7
  569. package/dist/integrations/ralph/learning/pattern-learner.js +0 -401
  570. package/dist/integrations/ralph/learning/pattern-learner.js.map +0 -7
  571. package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
  572. package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js.map +0 -7
  573. package/dist/integrations/ralph/monitoring/swarm-dashboard.js +0 -294
  574. package/dist/integrations/ralph/monitoring/swarm-dashboard.js.map +0 -7
  575. package/dist/integrations/ralph/monitoring/swarm-registry.js +0 -108
  576. package/dist/integrations/ralph/monitoring/swarm-registry.js.map +0 -7
  577. package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -463
  578. package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +0 -7
  579. package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -400
  580. package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js.map +0 -7
  581. package/dist/integrations/ralph/patterns/extended-coherence-sessions.js +0 -473
  582. package/dist/integrations/ralph/patterns/extended-coherence-sessions.js.map +0 -7
  583. package/dist/integrations/ralph/patterns/oracle-worker-pattern.js +0 -388
  584. package/dist/integrations/ralph/patterns/oracle-worker-pattern.js.map +0 -7
  585. package/dist/integrations/ralph/performance/performance-optimizer.js +0 -358
  586. package/dist/integrations/ralph/performance/performance-optimizer.js.map +0 -7
  587. package/dist/integrations/ralph/ralph-integration-demo.js +0 -182
  588. package/dist/integrations/ralph/ralph-integration-demo.js.map +0 -7
  589. package/dist/integrations/ralph/recovery/crash-recovery.js +0 -462
  590. package/dist/integrations/ralph/recovery/crash-recovery.js.map +0 -7
  591. package/dist/integrations/ralph/state/state-reconciler.js +0 -404
  592. package/dist/integrations/ralph/state/state-reconciler.js.map +0 -7
  593. package/dist/integrations/ralph/swarm/git-workflow-manager.js +0 -428
  594. package/dist/integrations/ralph/swarm/git-workflow-manager.js.map +0 -7
  595. package/dist/integrations/ralph/swarm/swarm-coordinator.js +0 -996
  596. package/dist/integrations/ralph/swarm/swarm-coordinator.js.map +0 -7
  597. package/dist/integrations/ralph/types.js +0 -5
  598. package/dist/integrations/ralph/types.js.map +0 -7
  599. package/dist/integrations/ralph/visualization/ralph-debugger.js +0 -585
  600. package/dist/integrations/ralph/visualization/ralph-debugger.js.map +0 -7
  601. package/dist/mcp/stackmemory-mcp-server.js +0 -554
  602. package/dist/mcp/stackmemory-mcp-server.js.map +0 -7
  603. package/dist/middleware/exponential-rate-limiter.js +0 -289
  604. package/dist/middleware/exponential-rate-limiter.js.map +0 -7
  605. package/dist/models/user.model.js +0 -358
  606. package/dist/models/user.model.js.map +0 -7
  607. package/dist/servers/production/auth-middleware.js +0 -528
  608. package/dist/servers/production/auth-middleware.js.map +0 -7
  609. package/dist/servers/railway/config.js +0 -55
  610. package/dist/servers/railway/config.js.map +0 -7
  611. package/dist/servers/railway/index-enhanced.js +0 -160
  612. package/dist/servers/railway/index-enhanced.js.map +0 -7
  613. package/dist/servers/railway/index.js +0 -1349
  614. package/dist/servers/railway/index.js.map +0 -7
  615. package/dist/servers/railway/simple.js +0 -64
  616. package/dist/servers/railway/simple.js.map +0 -7
  617. package/dist/servers/railway/storage-test.js +0 -459
  618. package/dist/servers/railway/storage-test.js.map +0 -7
  619. package/dist/services/config-service.js +0 -65
  620. package/dist/services/config-service.js.map +0 -7
  621. package/dist/services/context-service.js +0 -194
  622. package/dist/services/context-service.js.map +0 -7
  623. package/dist/skills/api-discovery.js +0 -354
  624. package/dist/skills/api-discovery.js.map +0 -7
  625. package/dist/skills/api-skill.js +0 -475
  626. package/dist/skills/api-skill.js.map +0 -7
  627. package/dist/skills/claude-skills.js +0 -1061
  628. package/dist/skills/claude-skills.js.map +0 -7
  629. package/dist/skills/dashboard-launcher.js +0 -216
  630. package/dist/skills/dashboard-launcher.js.map +0 -7
  631. package/dist/skills/recursive-agent-orchestrator.js +0 -575
  632. package/dist/skills/recursive-agent-orchestrator.js.map +0 -7
  633. package/dist/skills/repo-ingestion-skill.js +0 -609
  634. package/dist/skills/repo-ingestion-skill.js.map +0 -7
  635. package/dist/skills/security-secrets-scanner.js +0 -284
  636. package/dist/skills/security-secrets-scanner.js.map +0 -7
  637. package/dist/skills/unified-rlm-orchestrator.js +0 -404
  638. package/dist/skills/unified-rlm-orchestrator.js.map +0 -7
  639. package/dist/types/task.js +0 -5
  640. package/dist/types/task.js.map +0 -7
  641. package/dist/utils/env.js +0 -50
  642. package/dist/utils/env.js.map +0 -7
  643. package/dist/utils/formatting.js +0 -62
  644. package/dist/utils/formatting.js.map +0 -7
  645. package/dist/utils/process-cleanup.js +0 -136
  646. package/dist/utils/process-cleanup.js.map +0 -7
  647. package/dist/validation/schemas.js +0 -222
  648. package/dist/validation/schemas.js.map +0 -7
  649. /package/dist/{core/merge → src/core/extensions}/types.js +0 -0
  650. /package/dist/{core/merge → src/core/extensions}/types.js.map +0 -0
  651. /package/dist/{core → src/integrations/diffmem}/types.js +0 -0
  652. /package/dist/{core → src/integrations/diffmem}/types.js.map +0 -0
@@ -1,1975 +0,0 @@
1
- #!/usr/bin/env node
2
- import { fileURLToPath as __fileURLToPath } from 'url';
3
- import { dirname as __pathDirname } from 'path';
4
- const __filename = __fileURLToPath(import.meta.url);
5
- const __dirname = __pathDirname(__filename);
6
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
7
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
- import { z } from "zod";
9
- import Database from "better-sqlite3";
10
- import {
11
- validateInput,
12
- StartFrameSchema,
13
- AddAnchorSchema,
14
- CreateTaskSchema
15
- } from "./schemas.js";
16
- import { readFileSync, existsSync, mkdirSync } from "fs";
17
- import { join, dirname } from "path";
18
- import { execSync } from "child_process";
19
- import { FrameManager } from "../../core/context/index.js";
20
- import { logger } from "../../core/monitoring/logger.js";
21
- import { isFeatureEnabled } from "../../core/config/feature-flags.js";
22
- import {
23
- TaskPriority,
24
- TaskStatus
25
- } from "../../features/tasks/linear-task-manager.js";
26
- import { BrowserMCPIntegration } from "../../features/browser/browser-mcp.js";
27
- import { TraceDetector } from "../../core/trace/trace-detector.js";
28
- import { LLMContextRetrieval } from "../../core/retrieval/index.js";
29
- import { DiscoveryHandlers } from "./handlers/discovery-handlers.js";
30
- import { v4 as uuidv4 } from "uuid";
31
- function getEnv(key, defaultValue) {
32
- const value = process.env[key];
33
- if (value === void 0) {
34
- if (defaultValue !== void 0) return defaultValue;
35
- throw new Error(`Environment variable ${key} is required`);
36
- }
37
- return value;
38
- }
39
- function getOptionalEnv(key) {
40
- return process.env[key];
41
- }
42
- class LocalStackMemoryMCP {
43
- server;
44
- db;
45
- projectRoot;
46
- frameManager;
47
- taskStore = null;
48
- linearAuthManager = null;
49
- linearSync = null;
50
- projectId;
51
- contexts = /* @__PURE__ */ new Map();
52
- browserMCP;
53
- traceDetector;
54
- contextRetrieval;
55
- discoveryHandlers;
56
- constructor() {
57
- this.projectRoot = this.findProjectRoot();
58
- this.projectId = this.getProjectId();
59
- const dbDir = join(this.projectRoot, ".stackmemory");
60
- if (!existsSync(dbDir)) {
61
- mkdirSync(dbDir, { recursive: true });
62
- }
63
- const dbPath = join(dbDir, "context.db");
64
- this.db = new Database(dbPath);
65
- this.initDB();
66
- this.frameManager = new FrameManager(this.db, this.projectId);
67
- this.initLinearIfEnabled();
68
- this.server = new Server(
69
- {
70
- name: "stackmemory-local",
71
- version: "0.1.0"
72
- },
73
- {
74
- capabilities: {
75
- tools: {}
76
- }
77
- }
78
- );
79
- this.browserMCP = new BrowserMCPIntegration({
80
- headless: process.env["BROWSER_HEADLESS"] !== "false",
81
- defaultViewport: { width: 1280, height: 720 }
82
- });
83
- this.traceDetector = new TraceDetector({}, void 0, this.db);
84
- this.contextRetrieval = new LLMContextRetrieval(
85
- this.db,
86
- this.frameManager,
87
- this.projectId
88
- );
89
- this.discoveryHandlers = new DiscoveryHandlers({
90
- frameManager: this.frameManager,
91
- contextRetrieval: this.contextRetrieval,
92
- db: this.db,
93
- projectRoot: this.projectRoot
94
- });
95
- this.setupHandlers();
96
- this.loadInitialContext();
97
- this.browserMCP.initialize(this.server).catch((error) => {
98
- logger.error("Failed to initialize Browser MCP", error);
99
- });
100
- logger.info("StackMemory MCP Server initialized", {
101
- projectRoot: this.projectRoot,
102
- projectId: this.projectId
103
- });
104
- }
105
- findProjectRoot() {
106
- let dir = process.cwd();
107
- while (dir !== "/") {
108
- if (existsSync(join(dir, ".git"))) {
109
- return dir;
110
- }
111
- dir = dirname(dir);
112
- }
113
- return process.cwd();
114
- }
115
- /**
116
- * Initialize Linear integration if enabled and credentials available
117
- */
118
- async initLinearIfEnabled() {
119
- if (!isFeatureEnabled("linear")) {
120
- logger.info("Linear integration disabled (no API key or LOCAL mode)");
121
- return;
122
- }
123
- try {
124
- const { LinearTaskManager } = await import("../../features/tasks/linear-task-manager.js");
125
- const { LinearAuthManager } = await import("../linear/auth.js");
126
- const { LinearSyncEngine, DEFAULT_SYNC_CONFIG: DEFAULT_SYNC_CONFIG2 } = await import("../linear/sync.js");
127
- this.taskStore = new LinearTaskManager(this.projectRoot, this.db);
128
- this.linearAuthManager = new LinearAuthManager(this.projectRoot);
129
- this.linearSync = new LinearSyncEngine(
130
- this.taskStore,
131
- this.linearAuthManager,
132
- DEFAULT_SYNC_CONFIG2
133
- );
134
- logger.info("Linear integration initialized");
135
- } catch (error) {
136
- logger.warn("Failed to initialize Linear integration", { error });
137
- }
138
- }
139
- initDB() {
140
- this.db.exec(`
141
- CREATE TABLE IF NOT EXISTS contexts (
142
- id TEXT PRIMARY KEY,
143
- type TEXT NOT NULL,
144
- content TEXT NOT NULL,
145
- importance REAL DEFAULT 0.5,
146
- created_at INTEGER DEFAULT (unixepoch()),
147
- last_accessed INTEGER DEFAULT (unixepoch()),
148
- access_count INTEGER DEFAULT 1
149
- );
150
-
151
- CREATE TABLE IF NOT EXISTS attention_log (
152
- id INTEGER PRIMARY KEY AUTOINCREMENT,
153
- context_id TEXT,
154
- query TEXT,
155
- response TEXT,
156
- influence_score REAL,
157
- timestamp INTEGER DEFAULT (unixepoch())
158
- );
159
- `);
160
- }
161
- loadInitialContext() {
162
- const projectInfo = this.getProjectInfo();
163
- this.addContext(
164
- "project",
165
- `Project: ${projectInfo.name}
166
- Path: ${projectInfo.path}`,
167
- 0.9
168
- );
169
- try {
170
- const recentCommits = execSync("git log --oneline -10", {
171
- cwd: this.projectRoot
172
- }).toString();
173
- this.addContext("git_history", `Recent commits:
174
- ${recentCommits}`, 0.6);
175
- } catch {
176
- }
177
- const readmePath = join(this.projectRoot, "README.md");
178
- if (existsSync(readmePath)) {
179
- const readme = readFileSync(readmePath, "utf-8");
180
- const summary = readme.substring(0, 500);
181
- this.addContext("readme", `Project README:
182
- ${summary}...`, 0.8);
183
- }
184
- this.loadStoredContexts();
185
- }
186
- getProjectId() {
187
- let identifier;
188
- try {
189
- identifier = execSync("git config --get remote.origin.url", {
190
- cwd: this.projectRoot,
191
- stdio: "pipe",
192
- timeout: 5e3
193
- }).toString().trim();
194
- } catch {
195
- identifier = this.projectRoot;
196
- }
197
- const cleaned = identifier.replace(/\.git$/, "").replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase();
198
- return cleaned.substring(cleaned.length - 50) || "unknown";
199
- }
200
- getProjectInfo() {
201
- const packageJsonPath = join(this.projectRoot, "package.json");
202
- if (existsSync(packageJsonPath)) {
203
- const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
204
- return {
205
- name: pkg.name || "unknown",
206
- path: this.projectRoot
207
- };
208
- }
209
- return {
210
- name: this.projectRoot.split("/").pop() || "unknown",
211
- path: this.projectRoot
212
- };
213
- }
214
- addContext(type, content, importance = 0.5) {
215
- const id = `${type}_${Date.now()}`;
216
- this.db.prepare(
217
- `
218
- INSERT OR REPLACE INTO contexts (id, type, content, importance)
219
- VALUES (?, ?, ?, ?)
220
- `
221
- ).run(id, type, content, importance);
222
- this.contexts.set(id, { type, content, importance });
223
- return id;
224
- }
225
- loadStoredContexts() {
226
- const stored = this.db.prepare(
227
- `
228
- SELECT * FROM contexts
229
- ORDER BY importance DESC, last_accessed DESC
230
- LIMIT 50
231
- `
232
- ).all();
233
- stored.forEach((ctx) => {
234
- this.contexts.set(ctx.id, ctx);
235
- });
236
- }
237
- setupHandlers() {
238
- this.server.setRequestHandler(
239
- z.object({
240
- method: z.literal("tools/list")
241
- }),
242
- async () => {
243
- return {
244
- tools: [
245
- {
246
- name: "get_context",
247
- description: "Get current project context",
248
- inputSchema: {
249
- type: "object",
250
- properties: {
251
- query: {
252
- type: "string",
253
- description: "What you want to know"
254
- },
255
- limit: {
256
- type: "number",
257
- description: "Max contexts to return"
258
- }
259
- }
260
- }
261
- },
262
- {
263
- name: "add_decision",
264
- description: "Record a decision or important information",
265
- inputSchema: {
266
- type: "object",
267
- properties: {
268
- content: {
269
- type: "string",
270
- description: "The decision or information"
271
- },
272
- type: {
273
- type: "string",
274
- enum: ["decision", "constraint", "learning"]
275
- }
276
- },
277
- required: ["content", "type"]
278
- }
279
- },
280
- {
281
- name: "start_frame",
282
- description: "Start a new frame (task/subtask) on the call stack",
283
- inputSchema: {
284
- type: "object",
285
- properties: {
286
- name: { type: "string", description: "Frame name/goal" },
287
- type: {
288
- type: "string",
289
- enum: [
290
- "task",
291
- "subtask",
292
- "tool_scope",
293
- "review",
294
- "write",
295
- "debug"
296
- ],
297
- description: "Frame type"
298
- },
299
- constraints: {
300
- type: "array",
301
- items: { type: "string" },
302
- description: "Constraints for this frame"
303
- }
304
- },
305
- required: ["name", "type"]
306
- }
307
- },
308
- {
309
- name: "close_frame",
310
- description: "Close current frame and generate digest",
311
- inputSchema: {
312
- type: "object",
313
- properties: {
314
- result: {
315
- type: "string",
316
- description: "Frame completion result"
317
- },
318
- outputs: {
319
- type: "object",
320
- description: "Final outputs from frame"
321
- }
322
- }
323
- }
324
- },
325
- {
326
- name: "add_anchor",
327
- description: "Add anchored fact/decision/constraint to current frame",
328
- inputSchema: {
329
- type: "object",
330
- properties: {
331
- type: {
332
- type: "string",
333
- enum: [
334
- "FACT",
335
- "DECISION",
336
- "CONSTRAINT",
337
- "INTERFACE_CONTRACT",
338
- "TODO",
339
- "RISK"
340
- ],
341
- description: "Anchor type"
342
- },
343
- text: { type: "string", description: "Anchor content" },
344
- priority: {
345
- type: "number",
346
- description: "Priority (0-10)",
347
- minimum: 0,
348
- maximum: 10
349
- }
350
- },
351
- required: ["type", "text"]
352
- }
353
- },
354
- {
355
- name: "get_hot_stack",
356
- description: "Get current active frames and context",
357
- inputSchema: {
358
- type: "object",
359
- properties: {
360
- maxEvents: {
361
- type: "number",
362
- description: "Max recent events per frame",
363
- default: 20
364
- }
365
- }
366
- }
367
- },
368
- {
369
- name: "create_task",
370
- description: "Create a new task in git-tracked JSONL storage",
371
- inputSchema: {
372
- type: "object",
373
- properties: {
374
- title: { type: "string", description: "Task title" },
375
- description: {
376
- type: "string",
377
- description: "Task description"
378
- },
379
- priority: {
380
- type: "string",
381
- enum: ["low", "medium", "high", "urgent"],
382
- description: "Task priority"
383
- },
384
- estimatedEffort: {
385
- type: "number",
386
- description: "Estimated effort in minutes"
387
- },
388
- dependsOn: {
389
- type: "array",
390
- items: { type: "string" },
391
- description: "Task IDs this depends on"
392
- },
393
- tags: {
394
- type: "array",
395
- items: { type: "string" },
396
- description: "Tags for categorization"
397
- }
398
- },
399
- required: ["title"]
400
- }
401
- },
402
- {
403
- name: "update_task_status",
404
- description: "Update task status with automatic time tracking",
405
- inputSchema: {
406
- type: "object",
407
- properties: {
408
- taskId: { type: "string", description: "Task ID to update" },
409
- status: {
410
- type: "string",
411
- enum: [
412
- "pending",
413
- "in_progress",
414
- "completed",
415
- "blocked",
416
- "cancelled"
417
- ],
418
- description: "New status"
419
- },
420
- reason: {
421
- type: "string",
422
- description: "Reason for status change (especially for blocked)"
423
- }
424
- },
425
- required: ["taskId", "status"]
426
- }
427
- },
428
- {
429
- name: "get_active_tasks",
430
- description: "Get currently active tasks synced from Linear",
431
- inputSchema: {
432
- type: "object",
433
- properties: {
434
- frameId: {
435
- type: "string",
436
- description: "Filter by specific frame ID"
437
- },
438
- status: {
439
- type: "string",
440
- enum: [
441
- "pending",
442
- "in_progress",
443
- "completed",
444
- "blocked",
445
- "cancelled"
446
- ],
447
- description: "Filter by status"
448
- },
449
- priority: {
450
- type: "string",
451
- enum: ["low", "medium", "high", "urgent"],
452
- description: "Filter by priority"
453
- },
454
- search: {
455
- type: "string",
456
- description: "Search in task title or description"
457
- },
458
- limit: {
459
- type: "number",
460
- description: "Max number of tasks to return (default: 20)"
461
- }
462
- }
463
- }
464
- },
465
- {
466
- name: "get_task_metrics",
467
- description: "Get project task metrics and analytics",
468
- inputSchema: {
469
- type: "object",
470
- properties: {}
471
- }
472
- },
473
- {
474
- name: "add_task_dependency",
475
- description: "Add dependency relationship between tasks",
476
- inputSchema: {
477
- type: "object",
478
- properties: {
479
- taskId: {
480
- type: "string",
481
- description: "Task that depends on another"
482
- },
483
- dependsOnId: {
484
- type: "string",
485
- description: "Task ID that this depends on"
486
- }
487
- },
488
- required: ["taskId", "dependsOnId"]
489
- }
490
- },
491
- {
492
- name: "linear_sync",
493
- description: "Sync tasks with Linear",
494
- inputSchema: {
495
- type: "object",
496
- properties: {
497
- direction: {
498
- type: "string",
499
- enum: ["bidirectional", "to_linear", "from_linear"],
500
- description: "Sync direction"
501
- }
502
- }
503
- }
504
- },
505
- {
506
- name: "linear_update_task",
507
- description: "Update a Linear task status",
508
- inputSchema: {
509
- type: "object",
510
- properties: {
511
- issueId: {
512
- type: "string",
513
- description: "Linear issue ID or identifier (e.g., STA-34)"
514
- },
515
- status: {
516
- type: "string",
517
- enum: ["todo", "in-progress", "done", "canceled"],
518
- description: "New status for the task"
519
- },
520
- title: {
521
- type: "string",
522
- description: "Update task title (optional)"
523
- },
524
- description: {
525
- type: "string",
526
- description: "Update task description (optional)"
527
- },
528
- priority: {
529
- type: "number",
530
- enum: [1, 2, 3, 4],
531
- description: "Priority (1=urgent, 2=high, 3=medium, 4=low)"
532
- }
533
- },
534
- required: ["issueId"]
535
- }
536
- },
537
- {
538
- name: "linear_get_tasks",
539
- description: "Get Linear tasks",
540
- inputSchema: {
541
- type: "object",
542
- properties: {
543
- status: {
544
- type: "string",
545
- enum: ["todo", "in-progress", "done", "all"],
546
- description: "Filter by status"
547
- },
548
- limit: {
549
- type: "number",
550
- description: "Maximum number of tasks to return"
551
- }
552
- }
553
- }
554
- },
555
- {
556
- name: "linear_status",
557
- description: "Get Linear integration status",
558
- inputSchema: {
559
- type: "object",
560
- properties: {}
561
- }
562
- },
563
- {
564
- name: "get_traces",
565
- description: "Get detected traces (bundled tool call sequences)",
566
- inputSchema: {
567
- type: "object",
568
- properties: {
569
- type: {
570
- type: "string",
571
- enum: [
572
- "search_driven",
573
- "error_recovery",
574
- "feature_implementation",
575
- "refactoring",
576
- "testing",
577
- "exploration",
578
- "debugging",
579
- "documentation",
580
- "build_deploy",
581
- "unknown"
582
- ],
583
- description: "Filter by trace type"
584
- },
585
- minScore: {
586
- type: "number",
587
- description: "Minimum importance score (0-1)"
588
- },
589
- limit: {
590
- type: "number",
591
- description: "Maximum number of traces to return"
592
- }
593
- }
594
- }
595
- },
596
- {
597
- name: "get_trace_statistics",
598
- description: "Get statistics about detected traces",
599
- inputSchema: {
600
- type: "object",
601
- properties: {}
602
- }
603
- },
604
- {
605
- name: "flush_traces",
606
- description: "Flush any pending trace and finalize detection",
607
- inputSchema: {
608
- type: "object",
609
- properties: {}
610
- }
611
- },
612
- {
613
- name: "compress_old_traces",
614
- description: "Compress traces older than specified hours",
615
- inputSchema: {
616
- type: "object",
617
- properties: {
618
- ageHours: {
619
- type: "number",
620
- description: "Age threshold in hours (default: 24)"
621
- }
622
- }
623
- }
624
- },
625
- {
626
- name: "smart_context",
627
- description: "LLM-driven context retrieval - intelligently selects relevant frames based on query",
628
- inputSchema: {
629
- type: "object",
630
- properties: {
631
- query: {
632
- type: "string",
633
- description: "Natural language query describing what context you need"
634
- },
635
- tokenBudget: {
636
- type: "number",
637
- description: "Maximum tokens to use for context (default: 4000)"
638
- },
639
- forceRefresh: {
640
- type: "boolean",
641
- description: "Force refresh of cached summaries"
642
- }
643
- },
644
- required: ["query"]
645
- }
646
- },
647
- {
648
- name: "get_summary",
649
- description: "Get compressed summary of project memory for analysis",
650
- inputSchema: {
651
- type: "object",
652
- properties: {
653
- forceRefresh: {
654
- type: "boolean",
655
- description: "Force refresh of cached summary"
656
- }
657
- }
658
- }
659
- },
660
- // Discovery tools
661
- {
662
- name: "sm_discover",
663
- description: "Discover relevant files based on current context. Extracts keywords from active frames and searches codebase.",
664
- inputSchema: {
665
- type: "object",
666
- properties: {
667
- query: {
668
- type: "string",
669
- description: "Optional query to focus the discovery"
670
- },
671
- depth: {
672
- type: "string",
673
- enum: ["shallow", "medium", "deep"],
674
- description: "Search depth"
675
- },
676
- maxFiles: {
677
- type: "number",
678
- description: "Maximum files to return"
679
- }
680
- }
681
- }
682
- },
683
- {
684
- name: "sm_related_files",
685
- description: "Find files related to a specific file or concept",
686
- inputSchema: {
687
- type: "object",
688
- properties: {
689
- file: {
690
- type: "string",
691
- description: "File path to find related files for"
692
- },
693
- concept: {
694
- type: "string",
695
- description: "Concept to search for"
696
- },
697
- maxFiles: {
698
- type: "number",
699
- description: "Maximum files to return"
700
- }
701
- }
702
- }
703
- },
704
- {
705
- name: "sm_session_summary",
706
- description: "Get summary of current session with active tasks, files, and decisions",
707
- inputSchema: {
708
- type: "object",
709
- properties: {
710
- includeFiles: {
711
- type: "boolean",
712
- description: "Include recently accessed files"
713
- },
714
- includeDecisions: {
715
- type: "boolean",
716
- description: "Include recent decisions"
717
- }
718
- }
719
- }
720
- },
721
- {
722
- name: "sm_search",
723
- description: "Search across StackMemory - frames, events, decisions, tasks",
724
- inputSchema: {
725
- type: "object",
726
- properties: {
727
- query: {
728
- type: "string",
729
- description: "Search query"
730
- },
731
- scope: {
732
- type: "string",
733
- enum: ["all", "frames", "events", "decisions", "tasks"],
734
- description: "Scope of search"
735
- },
736
- limit: {
737
- type: "number",
738
- description: "Maximum results"
739
- }
740
- },
741
- required: ["query"]
742
- }
743
- }
744
- ]
745
- };
746
- }
747
- );
748
- this.server.setRequestHandler(
749
- z.object({
750
- method: z.literal("tools/call"),
751
- params: z.object({
752
- name: z.string(),
753
- arguments: z.record(z.unknown())
754
- })
755
- }),
756
- async (request) => {
757
- const { name, arguments: args } = request.params;
758
- const callId = uuidv4();
759
- const startTime = Date.now();
760
- const currentFrameId = this.frameManager.getCurrentFrameId();
761
- if (currentFrameId) {
762
- this.frameManager.addEvent("tool_call", {
763
- tool_name: name,
764
- arguments: args,
765
- timestamp: startTime
766
- });
767
- }
768
- const toolCall = {
769
- id: callId,
770
- tool: name,
771
- arguments: args,
772
- timestamp: startTime
773
- };
774
- let result;
775
- let error;
776
- try {
777
- switch (name) {
778
- case "get_context":
779
- result = await this.handleGetContext(args);
780
- break;
781
- case "add_decision":
782
- result = await this.handleAddDecision(args);
783
- break;
784
- case "start_frame":
785
- result = await this.handleStartFrame(args);
786
- break;
787
- case "close_frame":
788
- result = await this.handleCloseFrame(args);
789
- break;
790
- case "add_anchor":
791
- result = await this.handleAddAnchor(args);
792
- break;
793
- case "get_hot_stack":
794
- result = await this.handleGetHotStack(args);
795
- break;
796
- case "create_task":
797
- result = await this.handleCreateTask(args);
798
- break;
799
- case "update_task_status":
800
- result = await this.handleUpdateTaskStatus(args);
801
- break;
802
- case "get_active_tasks":
803
- result = await this.handleGetActiveTasks(args);
804
- break;
805
- case "get_task_metrics":
806
- result = await this.handleGetTaskMetrics(args);
807
- break;
808
- case "add_task_dependency":
809
- result = await this.handleAddTaskDependency(args);
810
- break;
811
- case "linear_sync":
812
- result = await this.handleLinearSync(args);
813
- break;
814
- case "linear_update_task":
815
- result = await this.handleLinearUpdateTask(args);
816
- break;
817
- case "linear_get_tasks":
818
- result = await this.handleLinearGetTasks(args);
819
- break;
820
- case "linear_status":
821
- result = await this.handleLinearStatus(args);
822
- break;
823
- case "get_traces":
824
- result = await this.handleGetTraces(args);
825
- break;
826
- case "get_trace_statistics":
827
- result = await this.handleGetTraceStatistics(args);
828
- break;
829
- case "flush_traces":
830
- result = await this.handleFlushTraces(args);
831
- break;
832
- case "compress_old_traces":
833
- result = await this.handleCompressOldTraces(args);
834
- break;
835
- case "smart_context":
836
- result = await this.handleSmartContext(args);
837
- break;
838
- case "get_summary":
839
- result = await this.handleGetSummary(args);
840
- break;
841
- // Discovery tools
842
- case "sm_discover":
843
- result = await this.handleSmDiscover(args);
844
- break;
845
- case "sm_related_files":
846
- result = await this.handleSmRelatedFiles(args);
847
- break;
848
- case "sm_session_summary":
849
- result = await this.handleSmSessionSummary(args);
850
- break;
851
- case "sm_search":
852
- result = await this.handleSmSearch(args);
853
- break;
854
- default:
855
- throw new Error(`Unknown tool: ${name}`);
856
- }
857
- } catch (err) {
858
- error = err instanceof Error ? err : new Error(String(err));
859
- toolCall.error = error.message;
860
- throw err;
861
- } finally {
862
- const endTime = Date.now();
863
- if (currentFrameId && name !== "close_frame") {
864
- try {
865
- this.frameManager.addEvent("tool_result", {
866
- tool_name: name,
867
- success: !error,
868
- result: error ? { error: error.message } : result,
869
- timestamp: endTime
870
- });
871
- } catch {
872
- }
873
- }
874
- toolCall.result = error ? void 0 : result;
875
- toolCall.duration = endTime - startTime;
876
- if (args.file_path || args.path) {
877
- toolCall.filesAffected = [args.file_path || args.path].filter(
878
- Boolean
879
- );
880
- } else if (result?.files) {
881
- const files = result.files;
882
- toolCall.filesAffected = Array.isArray(files) ? files : [files];
883
- }
884
- this.traceDetector.addToolCall(toolCall);
885
- }
886
- return result;
887
- }
888
- );
889
- }
890
- async handleGetContext(args) {
891
- const { query: query2 = "", limit = 10 } = args;
892
- const contexts = Array.from(this.contexts.values()).sort((a, b) => b.importance - a.importance).slice(0, limit);
893
- contexts.forEach((ctx) => {
894
- this.db.prepare(
895
- `
896
- UPDATE contexts
897
- SET last_accessed = unixepoch(),
898
- access_count = access_count + 1
899
- WHERE id = ?
900
- `
901
- ).run(ctx.id);
902
- });
903
- const response = contexts.map(
904
- (ctx) => `[${ctx.type.toUpperCase()}] (importance: ${ctx.importance.toFixed(2)})
905
- ${ctx.content}`
906
- ).join("\n\n---\n\n");
907
- this.logAttention(query2, response);
908
- return {
909
- content: [
910
- {
911
- type: "text",
912
- text: response || "No context available yet. Start adding decisions and information!"
913
- }
914
- ]
915
- };
916
- }
917
- async handleAddDecision(args) {
918
- const { content, type = "decision" } = args;
919
- const id = this.addContext(type, content, 0.8);
920
- return {
921
- content: [
922
- {
923
- type: "text",
924
- text: `\u2713 Added ${type}: ${content}
925
- ID: ${id}`
926
- }
927
- ]
928
- };
929
- }
930
- async handleStartFrame(args) {
931
- const { name, type, constraints } = validateInput(
932
- StartFrameSchema,
933
- args,
934
- "start_frame"
935
- );
936
- const inputs = {};
937
- if (constraints) {
938
- inputs.constraints = constraints;
939
- }
940
- const frameId = this.frameManager.createFrame({
941
- type,
942
- name,
943
- inputs
944
- });
945
- this.frameManager.addEvent("user_message", {
946
- action: "start_frame",
947
- name,
948
- type,
949
- constraints
950
- });
951
- this.addContext("active_frame", `Active frame: ${name} (${type})`, 0.9);
952
- const stackDepth = this.frameManager.getStackDepth();
953
- return {
954
- content: [
955
- {
956
- type: "text",
957
- text: `\u{1F680} Started ${type}: ${name}
958
- Frame ID: ${frameId}
959
- Stack depth: ${stackDepth}`
960
- }
961
- ]
962
- };
963
- }
964
- async handleCloseFrame(args) {
965
- const { result, outputs } = args;
966
- const currentFrameId = this.frameManager.getCurrentFrameId();
967
- if (!currentFrameId) {
968
- return {
969
- content: [
970
- {
971
- type: "text",
972
- text: "\u26A0\uFE0F No active frame to close"
973
- }
974
- ]
975
- };
976
- }
977
- this.frameManager.addEvent("assistant_message", {
978
- action: "close_frame",
979
- result,
980
- outputs
981
- });
982
- this.frameManager.closeFrame(currentFrameId, outputs);
983
- const newStackDepth = this.frameManager.getStackDepth();
984
- return {
985
- content: [
986
- {
987
- type: "text",
988
- text: `\u2705 Closed frame: ${result || "completed"}
989
- Stack depth: ${newStackDepth}`
990
- }
991
- ]
992
- };
993
- }
994
- async handleAddAnchor(args) {
995
- const { type, text, priority } = validateInput(
996
- AddAnchorSchema,
997
- args,
998
- "add_anchor"
999
- );
1000
- const anchorId = this.frameManager.addAnchor(type, text, priority);
1001
- this.frameManager.addEvent("decision", {
1002
- anchor_type: type,
1003
- text,
1004
- priority,
1005
- anchor_id: anchorId
1006
- });
1007
- return {
1008
- content: [
1009
- {
1010
- type: "text",
1011
- text: `\u{1F4CC} Added ${type}: ${text}
1012
- Anchor ID: ${anchorId}`
1013
- }
1014
- ]
1015
- };
1016
- }
1017
- async handleGetHotStack(args) {
1018
- const { maxEvents = 20 } = args;
1019
- const hotStack = this.frameManager.getHotStackContext(maxEvents);
1020
- const activePath = this.frameManager.getActiveFramePath();
1021
- if (hotStack.length === 0) {
1022
- return {
1023
- content: [
1024
- {
1025
- type: "text",
1026
- text: "\u{1F4DA} No active frames. Start a frame with start_frame tool."
1027
- }
1028
- ]
1029
- };
1030
- }
1031
- let response = "\u{1F4DA} **Active Call Stack:**\n\n";
1032
- activePath.forEach((frame, index) => {
1033
- const indent = " ".repeat(index);
1034
- const context = hotStack[index];
1035
- response += `${indent}${index + 1}. **${frame.name}** (${frame.type})
1036
- `;
1037
- if (context && context.anchors && context.anchors.length > 0) {
1038
- response += `${indent} \u{1F4CC} ${context.anchors.length} anchors
1039
- `;
1040
- }
1041
- if (context && context.recentEvents && context.recentEvents.length > 0) {
1042
- response += `${indent} \u{1F4DD} ${context.recentEvents.length} recent events
1043
- `;
1044
- }
1045
- response += "\n";
1046
- });
1047
- response += `**Total stack depth:** ${hotStack.length}`;
1048
- this.frameManager.addEvent("observation", {
1049
- action: "get_hot_stack",
1050
- stack_depth: hotStack.length,
1051
- total_anchors: hotStack.reduce(
1052
- (sum, frame) => sum + frame.anchors.length,
1053
- 0
1054
- ),
1055
- total_events: hotStack.reduce(
1056
- (sum, frame) => sum + frame.recentEvents.length,
1057
- 0
1058
- )
1059
- });
1060
- return {
1061
- content: [
1062
- {
1063
- type: "text",
1064
- text: response
1065
- }
1066
- ]
1067
- };
1068
- }
1069
- logAttention(query2, response) {
1070
- this.db.prepare(
1071
- `
1072
- INSERT INTO attention_log (query, response)
1073
- VALUES (?, ?)
1074
- `
1075
- ).run(query2, response);
1076
- }
1077
- async handleCreateTask(args) {
1078
- const validated = validateInput(CreateTaskSchema, args, "create_task");
1079
- const { title, description, priority, tags } = validated;
1080
- const { estimatedEffort, dependsOn } = args;
1081
- const currentFrameId = this.frameManager.getCurrentFrameId();
1082
- if (!currentFrameId) {
1083
- return {
1084
- content: [
1085
- {
1086
- type: "text",
1087
- text: "\u26A0\uFE0F No active frame. Start a frame first with start_frame tool."
1088
- }
1089
- ]
1090
- };
1091
- }
1092
- const taskId = this.taskStore.createTask({
1093
- title,
1094
- description,
1095
- priority,
1096
- frameId: currentFrameId,
1097
- dependsOn,
1098
- tags,
1099
- estimatedEffort
1100
- });
1101
- this.frameManager.addEvent("decision", {
1102
- action: "create_task",
1103
- task_id: taskId,
1104
- title,
1105
- priority: priority || "medium"
1106
- });
1107
- return {
1108
- content: [
1109
- {
1110
- type: "text",
1111
- text: `\u2705 Created task: ${title}
1112
- ID: ${taskId}
1113
- Frame: ${currentFrameId}
1114
- Stored in: .stackmemory/tasks.jsonl`
1115
- }
1116
- ]
1117
- };
1118
- }
1119
- async handleUpdateTaskStatus(args) {
1120
- const { taskId, status, reason } = args;
1121
- try {
1122
- this.taskStore.updateTaskStatus(taskId, status, reason);
1123
- this.frameManager.addEvent("observation", {
1124
- action: "update_task_status",
1125
- task_id: taskId,
1126
- new_status: status,
1127
- reason
1128
- });
1129
- return {
1130
- content: [
1131
- {
1132
- type: "text",
1133
- text: `\u2705 Updated task ${taskId} to ${status}${reason ? `
1134
- Reason: ${reason}` : ""}`
1135
- }
1136
- ]
1137
- };
1138
- } catch (error) {
1139
- return {
1140
- content: [
1141
- {
1142
- type: "text",
1143
- text: `\u274C Failed to update task: ${error}`
1144
- }
1145
- ]
1146
- };
1147
- }
1148
- }
1149
- async handleGetActiveTasks(args) {
1150
- const { frameId, status, priority, search, limit = 20 } = args;
1151
- let tasks = this.taskStore.getActiveTasks(frameId);
1152
- if (status) {
1153
- tasks = tasks.filter((t) => t.status === status);
1154
- }
1155
- if (priority) {
1156
- tasks = tasks.filter((t) => t.priority === priority);
1157
- }
1158
- if (search) {
1159
- const searchLower = search.toLowerCase();
1160
- tasks = tasks.filter(
1161
- (t) => t.title.toLowerCase().includes(searchLower) || t.description && t.description.toLowerCase().includes(searchLower)
1162
- );
1163
- }
1164
- const priorityOrder = { urgent: 0, high: 1, medium: 2, low: 3 };
1165
- tasks.sort((a, b) => {
1166
- const pa = priorityOrder[a.priority] ?? 2;
1167
- const pb = priorityOrder[b.priority] ?? 2;
1168
- if (pa !== pb) return pa - pb;
1169
- return b.created_at - a.created_at;
1170
- });
1171
- tasks = tasks.slice(0, limit);
1172
- if (tasks.length === 0) {
1173
- return {
1174
- content: [
1175
- {
1176
- type: "text",
1177
- text: search ? `\u{1F4DD} No tasks matching "${search}"` : "\u{1F4DD} No active tasks found"
1178
- }
1179
- ]
1180
- };
1181
- }
1182
- let response = `\u{1F4DD} **Tasks** (${tasks.length} found)
1183
-
1184
- `;
1185
- tasks.forEach((task) => {
1186
- const priorityIcon = { urgent: "\u{1F534}", high: "\u{1F7E0}", medium: "\u{1F7E1}", low: "\u{1F7E2}" }[task.priority] || "\u26AA";
1187
- const statusIcon = {
1188
- pending: "\u23F3",
1189
- in_progress: "\u{1F504}",
1190
- completed: "\u2705",
1191
- blocked: "\u{1F6AB}",
1192
- cancelled: "\u274C"
1193
- }[task.status] || "\u26AA";
1194
- const effort = task.estimated_effort ? ` (~${task.estimated_effort}m)` : "";
1195
- const linearMatch = task.title.match(/\[ENG-\d+\]/);
1196
- const linearId = linearMatch ? linearMatch[0] : "";
1197
- const title = linearId ? task.title.replace(linearId, "").trim() : task.title;
1198
- response += `${statusIcon} ${priorityIcon} **${linearId || task.id}** ${title}${effort}
1199
- `;
1200
- if (task.description) {
1201
- const desc = task.description.split("\n")[0].slice(0, 100);
1202
- response += ` ${desc}${task.description.length > 100 ? "..." : ""}
1203
- `;
1204
- }
1205
- if (task.tags && task.tags.length > 0) {
1206
- response += ` \u{1F3F7}\uFE0F ${task.tags.join(", ")}
1207
- `;
1208
- }
1209
- response += "\n";
1210
- });
1211
- return {
1212
- content: [
1213
- {
1214
- type: "text",
1215
- text: response
1216
- }
1217
- ]
1218
- };
1219
- }
1220
- async handleGetTaskMetrics(_args) {
1221
- const metrics = this.taskStore.getMetrics();
1222
- let response = "\u{1F4CA} **Task Metrics**\n\n";
1223
- response += `**Total Tasks:** ${metrics.total_tasks}
1224
- `;
1225
- response += `**Completion Rate:** ${(metrics.completion_rate * 100).toFixed(1)}%
1226
-
1227
- `;
1228
- response += "**By Status:**\n";
1229
- Object.entries(metrics.by_status).forEach(([status, count]) => {
1230
- response += `- ${status}: ${count}
1231
- `;
1232
- });
1233
- response += "\n**By Priority:**\n";
1234
- Object.entries(metrics.by_priority).forEach(([priority, count]) => {
1235
- response += `- ${priority}: ${count}
1236
- `;
1237
- });
1238
- if (metrics.blocked_tasks > 0) {
1239
- response += `
1240
- \u26A0\uFE0F **${metrics.blocked_tasks} blocked tasks**`;
1241
- }
1242
- if (metrics.avg_effort_accuracy > 0) {
1243
- response += `
1244
- \u{1F3AF} **Effort Accuracy:** ${(metrics.avg_effort_accuracy * 100).toFixed(1)}%`;
1245
- }
1246
- return {
1247
- content: [
1248
- {
1249
- type: "text",
1250
- text: response
1251
- }
1252
- ]
1253
- };
1254
- }
1255
- async handleAddTaskDependency(args) {
1256
- const { taskId, dependsOnId } = args;
1257
- try {
1258
- this.taskStore.addDependency(taskId, dependsOnId);
1259
- this.frameManager.addEvent("decision", {
1260
- action: "add_task_dependency",
1261
- task_id: taskId,
1262
- depends_on_id: dependsOnId
1263
- });
1264
- return {
1265
- content: [
1266
- {
1267
- type: "text",
1268
- text: `\u{1F517} Added dependency: ${taskId} depends on ${dependsOnId}`
1269
- }
1270
- ]
1271
- };
1272
- } catch (error) {
1273
- return {
1274
- content: [
1275
- {
1276
- type: "text",
1277
- text: `\u274C Failed to add dependency: ${error}`
1278
- }
1279
- ]
1280
- };
1281
- }
1282
- }
1283
- // Linear Integration Handlers
1284
- async handleLinearSync(args) {
1285
- try {
1286
- const tokens = this.linearAuthManager.loadTokens();
1287
- if (!tokens) {
1288
- return {
1289
- content: [
1290
- {
1291
- type: "text",
1292
- text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
1293
- }
1294
- ]
1295
- };
1296
- }
1297
- const syncConfig = { ...DEFAULT_SYNC_CONFIG, enabled: true };
1298
- if (args.direction) {
1299
- syncConfig.direction = args.direction;
1300
- }
1301
- this.linearSync.updateConfig(syncConfig);
1302
- const result = await this.linearSync.sync();
1303
- return {
1304
- content: [
1305
- {
1306
- type: "text",
1307
- text: `\u2705 Linear sync completed
1308
- - To Linear: ${result.synced.toLinear} tasks
1309
- - From Linear: ${result.synced.fromLinear} tasks
1310
- - Updated: ${result.synced.updated} tasks`
1311
- }
1312
- ]
1313
- };
1314
- } catch (error) {
1315
- const message = error instanceof Error ? error.message : String(error);
1316
- logger.error("Linear sync failed", { error: message });
1317
- return {
1318
- content: [
1319
- {
1320
- type: "text",
1321
- text: `\u274C Linear sync failed: ${message}`
1322
- }
1323
- ]
1324
- };
1325
- }
1326
- }
1327
- async handleLinearUpdateTask(args) {
1328
- try {
1329
- const { LinearClient } = await import("../linear/client.js");
1330
- const tokens = this.linearAuthManager.loadTokens();
1331
- if (!tokens) {
1332
- return {
1333
- content: [
1334
- {
1335
- type: "text",
1336
- text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
1337
- }
1338
- ]
1339
- };
1340
- }
1341
- const client = new LinearClient({
1342
- apiKey: tokens.accessToken,
1343
- useBearer: true,
1344
- onUnauthorized: async () => {
1345
- const refreshed = await this.linearAuthManager.refreshAccessToken();
1346
- return refreshed.accessToken;
1347
- }
1348
- });
1349
- let issue = await client.getIssue(args.issueId);
1350
- if (!issue) {
1351
- issue = await client.findIssueByIdentifier(args.issueId);
1352
- }
1353
- if (!issue) {
1354
- return {
1355
- content: [
1356
- {
1357
- type: "text",
1358
- text: `\u274C Linear issue ${args.issueId} not found`
1359
- }
1360
- ]
1361
- };
1362
- }
1363
- const updates = {};
1364
- if (args.status) {
1365
- const team = await client.getTeam();
1366
- const states = await client.getWorkflowStates(team.id);
1367
- const statusMap = {
1368
- todo: "unstarted",
1369
- "in-progress": "started",
1370
- done: "completed",
1371
- canceled: "cancelled"
1372
- };
1373
- const targetType = statusMap[args.status] || args.status;
1374
- const targetState = states.find((s) => s.type === targetType);
1375
- if (!targetState) {
1376
- return {
1377
- content: [
1378
- {
1379
- type: "text",
1380
- text: `\u274C Invalid status: ${args.status}`
1381
- }
1382
- ]
1383
- };
1384
- }
1385
- updates.stateId = targetState.id;
1386
- }
1387
- if (args.title) updates.title = args.title;
1388
- if (args.description) updates.description = args.description;
1389
- if (args.priority) updates.priority = args.priority;
1390
- const updatedIssue = await client.updateIssue(issue.id, updates);
1391
- this.linearSync.updateConfig({
1392
- ...DEFAULT_SYNC_CONFIG,
1393
- enabled: true,
1394
- direction: "from_linear"
1395
- });
1396
- const syncResult = await this.linearSync.sync();
1397
- let response = `\u2705 Updated ${updatedIssue.identifier}: ${updatedIssue.title}
1398
- `;
1399
- if (args.status) {
1400
- response += `Status: ${updatedIssue.state.name}
1401
- `;
1402
- }
1403
- response += `URL: ${updatedIssue.url}
1404
- `;
1405
- response += `
1406
- \u{1F504} Local sync: ${syncResult.synced.fromLinear} new, ${syncResult.synced.updated} updated`;
1407
- return {
1408
- content: [
1409
- {
1410
- type: "text",
1411
- text: response
1412
- }
1413
- ]
1414
- };
1415
- } catch (error) {
1416
- const message = error instanceof Error ? error.message : String(error);
1417
- logger.error("Failed to update Linear task", { error: message });
1418
- return {
1419
- content: [
1420
- {
1421
- type: "text",
1422
- text: `\u274C Failed to update Linear task: ${message}`
1423
- }
1424
- ]
1425
- };
1426
- }
1427
- }
1428
- async handleLinearGetTasks(args) {
1429
- try {
1430
- const { LinearClient } = await import("../linear/client.js");
1431
- const tokens = this.linearAuthManager.loadTokens();
1432
- if (!tokens) {
1433
- return {
1434
- content: [
1435
- {
1436
- type: "text",
1437
- text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
1438
- }
1439
- ]
1440
- };
1441
- }
1442
- const client = new LinearClient({
1443
- apiKey: tokens.accessToken,
1444
- useBearer: true,
1445
- onUnauthorized: async () => {
1446
- const refreshed = await this.linearAuthManager.refreshAccessToken();
1447
- return refreshed.accessToken;
1448
- }
1449
- });
1450
- let stateType = void 0;
1451
- if (args.status && args.status !== "all") {
1452
- const statusMap = {
1453
- todo: "unstarted",
1454
- "in-progress": "started",
1455
- done: "completed"
1456
- };
1457
- stateType = statusMap[args.status] || args.status;
1458
- }
1459
- const issues = await client.getIssues({
1460
- stateType,
1461
- limit: args.limit || 20
1462
- });
1463
- if (!issues || issues.length === 0) {
1464
- return {
1465
- content: [
1466
- {
1467
- type: "text",
1468
- text: "No Linear tasks found"
1469
- }
1470
- ]
1471
- };
1472
- }
1473
- let response = `\u{1F4CB} **Linear Tasks** (${issues.length} items)
1474
-
1475
- `;
1476
- issues.forEach((issue) => {
1477
- const priority = issue.priority ? `P${issue.priority}` : "-";
1478
- response += `- **${issue.identifier}**: ${issue.title}
1479
- `;
1480
- response += ` Status: ${issue.state.name} | Priority: ${priority}
1481
- `;
1482
- if (issue.assignee) {
1483
- response += ` Assignee: ${issue.assignee.name}
1484
- `;
1485
- }
1486
- response += ` ${issue.url}
1487
-
1488
- `;
1489
- });
1490
- return {
1491
- content: [
1492
- {
1493
- type: "text",
1494
- text: response
1495
- }
1496
- ]
1497
- };
1498
- } catch (error) {
1499
- const message = error instanceof Error ? error.message : String(error);
1500
- logger.error("Failed to get Linear tasks", { error: message });
1501
- return {
1502
- content: [
1503
- {
1504
- type: "text",
1505
- text: `\u274C Failed to get Linear tasks: ${message}`
1506
- }
1507
- ]
1508
- };
1509
- }
1510
- }
1511
- async handleLinearStatus(_args) {
1512
- try {
1513
- const { LinearClient } = await import("../linear/client.js");
1514
- const tokens = this.linearAuthManager.loadTokens();
1515
- if (!tokens) {
1516
- return {
1517
- content: [
1518
- {
1519
- type: "text",
1520
- text: "\u274C Linear integration not configured\nRun: stackmemory linear setup"
1521
- }
1522
- ]
1523
- };
1524
- }
1525
- try {
1526
- const client = new LinearClient({
1527
- apiKey: tokens.accessToken,
1528
- useBearer: true,
1529
- onUnauthorized: async () => {
1530
- const refreshed = await this.linearAuthManager.refreshAccessToken();
1531
- return refreshed.accessToken;
1532
- }
1533
- });
1534
- const viewer = await client.getViewer();
1535
- const team = await client.getTeam();
1536
- return {
1537
- content: [
1538
- {
1539
- type: "text",
1540
- text: `\u2705 **Linear Integration Status**
1541
-
1542
- Connected as: ${viewer.name} (${viewer.email})
1543
- Team: ${team.name} (${team.key})
1544
- Tokens: Valid`
1545
- }
1546
- ]
1547
- };
1548
- } catch (error) {
1549
- const message = error instanceof Error ? error.message : String(error);
1550
- return {
1551
- content: [
1552
- {
1553
- type: "text",
1554
- text: `\u26A0\uFE0F Linear configured but connection failed: ${message}`
1555
- }
1556
- ]
1557
- };
1558
- }
1559
- } catch (error) {
1560
- const message = error instanceof Error ? error.message : String(error);
1561
- logger.error("Linear status check failed", { error: message });
1562
- return {
1563
- content: [
1564
- {
1565
- type: "text",
1566
- text: `\u274C Linear status check failed: ${message}`
1567
- }
1568
- ]
1569
- };
1570
- }
1571
- }
1572
- async handleGetTraces(args) {
1573
- const { type, minScore, limit = 20 } = args;
1574
- this.traceDetector.flush();
1575
- let traces = this.traceDetector.getTraces();
1576
- if (type) {
1577
- traces = traces.filter((t) => t.type === type);
1578
- }
1579
- if (minScore !== void 0) {
1580
- traces = traces.filter((t) => t.score >= minScore);
1581
- }
1582
- traces = traces.sort((a, b) => b.score - a.score).slice(0, limit);
1583
- const formattedTraces = traces.map((trace) => ({
1584
- id: trace.id,
1585
- type: trace.type,
1586
- score: trace.score.toFixed(2),
1587
- summary: trace.summary,
1588
- toolCount: trace.tools.length,
1589
- duration: `${((trace.metadata.endTime - trace.metadata.startTime) / 1e3).toFixed(1)}s`,
1590
- filesModified: trace.metadata.filesModified.length,
1591
- hasErrors: trace.metadata.errorsEncountered.length > 0,
1592
- compressed: !!trace.compressed
1593
- }));
1594
- return {
1595
- content: [
1596
- {
1597
- type: "text",
1598
- text: `Found ${formattedTraces.length} traces:
1599
-
1600
- ${formattedTraces.map(
1601
- (t) => `[${t.type}] Score: ${t.score} | Tools: ${t.toolCount} | Duration: ${t.duration}
1602
- ${t.summary}`
1603
- ).join("\n\n")}`
1604
- }
1605
- ]
1606
- };
1607
- }
1608
- async handleGetTraceStatistics(args) {
1609
- this.traceDetector.flush();
1610
- const stats = this.traceDetector.getStatistics();
1611
- const typeBreakdown = Object.entries(stats.tracesByType).map(([type, count]) => ` ${type}: ${count}`).join("\n");
1612
- return {
1613
- content: [
1614
- {
1615
- type: "text",
1616
- text: `**Trace Statistics**
1617
-
1618
- Total Traces: ${stats.totalTraces}
1619
- Average Score: ${stats.averageScore.toFixed(2)}
1620
- Average Length: ${stats.averageLength.toFixed(1)} tools
1621
- High Importance (>0.7): ${stats.highImportanceCount}
1622
- Compressed: ${stats.compressedCount}
1623
-
1624
- **Trace Types:**
1625
- ${typeBreakdown}`
1626
- }
1627
- ]
1628
- };
1629
- }
1630
- async handleFlushTraces(args) {
1631
- this.traceDetector.flush();
1632
- return {
1633
- content: [
1634
- {
1635
- type: "text",
1636
- text: "Pending traces have been flushed and finalized."
1637
- }
1638
- ]
1639
- };
1640
- }
1641
- async handleCompressOldTraces(args) {
1642
- const { ageHours = 24 } = args;
1643
- const compressedCount = this.traceDetector.compressOldTraces(ageHours);
1644
- return {
1645
- content: [
1646
- {
1647
- type: "text",
1648
- text: `Compressed ${compressedCount} traces older than ${ageHours} hours.`
1649
- }
1650
- ]
1651
- };
1652
- }
1653
- async handleSmartContext(args) {
1654
- const { query: query2, tokenBudget = 4e3, forceRefresh = false } = args;
1655
- try {
1656
- const result = await this.contextRetrieval.retrieveContext(query2, {
1657
- tokenBudget,
1658
- forceRefresh
1659
- });
1660
- const currentFrameId = this.frameManager.getCurrentFrameId();
1661
- if (currentFrameId) {
1662
- this.frameManager.addEvent("observation", {
1663
- action: "smart_context",
1664
- query: query2,
1665
- framesRetrieved: result.frames.length,
1666
- tokenUsage: result.tokenUsage,
1667
- confidence: result.analysis.confidenceScore
1668
- });
1669
- }
1670
- let response = result.context;
1671
- response += `
1672
-
1673
- ---
1674
- \u{1F4CA} **Retrieval Stats**
1675
- `;
1676
- response += `- Frames included: ${result.frames.length}
1677
- `;
1678
- response += `- Tokens used: ${result.tokenUsage.used}/${result.tokenUsage.budget}
1679
- `;
1680
- response += `- Confidence: ${(result.analysis.confidenceScore * 100).toFixed(0)}%
1681
- `;
1682
- response += `- Time: ${result.metadata.retrievalTimeMs}ms`;
1683
- return {
1684
- content: [
1685
- {
1686
- type: "text",
1687
- text: response
1688
- }
1689
- ]
1690
- };
1691
- } catch (error) {
1692
- const message = error instanceof Error ? error.message : String(error);
1693
- logger.error("Context retrieval failed", { error: message });
1694
- return {
1695
- content: [
1696
- {
1697
- type: "text",
1698
- text: `\u274C Context retrieval failed: ${message}`
1699
- }
1700
- ]
1701
- };
1702
- }
1703
- }
1704
- async handleGetSummary(args) {
1705
- const { forceRefresh = false } = args;
1706
- try {
1707
- const summary = this.contextRetrieval.getSummary(forceRefresh);
1708
- let response = "\u{1F4CB} **Compressed Memory Summary**\n\n";
1709
- response += "## Recent Session\n";
1710
- response += `- Frames: ${summary.recentSession.frames.length}
1711
- `;
1712
- response += `- Time range: ${new Date(summary.recentSession.timeRange.start).toLocaleString()} - ${new Date(summary.recentSession.timeRange.end).toLocaleString()}
1713
- `;
1714
- if (summary.recentSession.dominantOperations.length > 0) {
1715
- response += `- Dominant ops: ${summary.recentSession.dominantOperations.slice(0, 5).map((o) => `${o.operation}(${o.count})`).join(", ")}
1716
- `;
1717
- }
1718
- if (summary.recentSession.filesTouched.length > 0) {
1719
- response += `- Files touched: ${summary.recentSession.filesTouched.slice(0, 5).map((f) => f.path).join(", ")}
1720
- `;
1721
- }
1722
- if (summary.recentSession.errorsEncountered.length > 0) {
1723
- response += `- Errors: ${summary.recentSession.errorsEncountered.length}
1724
- `;
1725
- }
1726
- response += "\n## Historical Patterns\n";
1727
- response += `- Topic counts: ${Object.keys(summary.historicalPatterns.topicFrameCounts).length} topics
1728
- `;
1729
- if (summary.historicalPatterns.keyDecisions.length > 0) {
1730
- response += `
1731
- ### Key Decisions (${summary.historicalPatterns.keyDecisions.length})
1732
- `;
1733
- summary.historicalPatterns.keyDecisions.slice(0, 5).forEach((d) => {
1734
- response += `- ${d.text.substring(0, 80)}${d.text.length > 80 ? "..." : ""}
1735
- `;
1736
- });
1737
- }
1738
- if (summary.historicalPatterns.recurringIssues.length > 0) {
1739
- response += `
1740
- ### Recurring Issues (${summary.historicalPatterns.recurringIssues.length})
1741
- `;
1742
- summary.historicalPatterns.recurringIssues.slice(0, 3).forEach((i) => {
1743
- response += `- ${i.issueType} (${i.occurrenceCount} times)
1744
- `;
1745
- });
1746
- }
1747
- response += "\n## Available Indices\n";
1748
- response += `- By time: ${Object.keys(summary.queryableIndices.byTimeframe).length} periods
1749
- `;
1750
- response += `- By file: ${Object.keys(summary.queryableIndices.byFile).length} files
1751
- `;
1752
- response += `- By topic: ${Object.keys(summary.queryableIndices.byTopic).length} topics
1753
- `;
1754
- response += `- By error: ${Object.keys(summary.queryableIndices.byErrorType).length} error types
1755
- `;
1756
- response += `
1757
- ## Stats
1758
- `;
1759
- response += `- Total frames: ${summary.stats.totalFrames}
1760
- `;
1761
- response += `- Total anchors: ${summary.stats.totalAnchors}
1762
- `;
1763
- response += `- Total events: ${summary.stats.totalEvents}
1764
- `;
1765
- response += `- Generated: ${new Date(summary.generatedAt).toLocaleString()}`;
1766
- return {
1767
- content: [
1768
- {
1769
- type: "text",
1770
- text: response
1771
- }
1772
- ]
1773
- };
1774
- } catch (error) {
1775
- const message = error instanceof Error ? error.message : String(error);
1776
- logger.error("Failed to get summary", { error: message });
1777
- return {
1778
- content: [
1779
- {
1780
- type: "text",
1781
- text: `\u274C Failed to get summary: ${message}`
1782
- }
1783
- ]
1784
- };
1785
- }
1786
- }
1787
- // ============================================
1788
- // Discovery Tools Handlers
1789
- // ============================================
1790
- async handleSmDiscover(args) {
1791
- return this.discoveryHandlers.handleDiscover(args);
1792
- }
1793
- async handleSmRelatedFiles(args) {
1794
- return this.discoveryHandlers.handleRelatedFiles(args);
1795
- }
1796
- async handleSmSessionSummary(args) {
1797
- return this.discoveryHandlers.handleSessionSummary(args);
1798
- }
1799
- async handleSmSearch(args) {
1800
- try {
1801
- const { query: query2, scope: scope2 = "all", limit = 20 } = args;
1802
- if (!query2) {
1803
- throw new Error("Query is required");
1804
- }
1805
- const results = [];
1806
- if (scope2 === "all" || scope2 === "frames") {
1807
- const frames = this.db.prepare(
1808
- `
1809
- SELECT frame_id, name, type, created_at, inputs, outputs
1810
- FROM frames
1811
- WHERE project_id = ? AND (name LIKE ? OR inputs LIKE ? OR outputs LIKE ?)
1812
- ORDER BY created_at DESC
1813
- LIMIT ?
1814
- `
1815
- ).all(
1816
- this.projectId,
1817
- `%${query2}%`,
1818
- `%${query2}%`,
1819
- `%${query2}%`,
1820
- limit
1821
- );
1822
- frames.forEach((f) => {
1823
- results.push({
1824
- type: "frame",
1825
- id: f.frame_id,
1826
- name: f.name,
1827
- frameType: f.type,
1828
- created: new Date(f.created_at * 1e3).toISOString()
1829
- });
1830
- });
1831
- }
1832
- if (scope2 === "all" || scope2 === "events") {
1833
- const events = this.db.prepare(
1834
- `
1835
- SELECT e.event_id, e.type, e.data, e.timestamp, f.name as frame_name
1836
- FROM events e
1837
- JOIN frames f ON e.frame_id = f.frame_id
1838
- WHERE f.project_id = ? AND e.data LIKE ?
1839
- ORDER BY e.timestamp DESC
1840
- LIMIT ?
1841
- `
1842
- ).all(this.projectId, `%${query2}%`, limit);
1843
- events.forEach((e) => {
1844
- results.push({
1845
- type: "event",
1846
- id: e.event_id,
1847
- eventType: e.type,
1848
- frame: e.frame_name,
1849
- timestamp: new Date(e.timestamp * 1e3).toISOString()
1850
- });
1851
- });
1852
- }
1853
- if (scope2 === "all" || scope2 === "decisions") {
1854
- const anchors = this.db.prepare(
1855
- `
1856
- SELECT a.anchor_id, a.type, a.text, a.priority, a.created_at, f.name as frame_name
1857
- FROM anchors a
1858
- JOIN frames f ON a.frame_id = f.frame_id
1859
- WHERE f.project_id = ? AND a.text LIKE ?
1860
- ORDER BY a.created_at DESC
1861
- LIMIT ?
1862
- `
1863
- ).all(this.projectId, `%${query2}%`, limit);
1864
- anchors.forEach((a) => {
1865
- results.push({
1866
- type: "decision",
1867
- id: a.anchor_id,
1868
- decisionType: a.type,
1869
- text: a.text,
1870
- priority: a.priority,
1871
- frame: a.frame_name
1872
- });
1873
- });
1874
- }
1875
- if (scope2 === "all" || scope2 === "tasks") {
1876
- try {
1877
- const tasks = this.db.prepare(
1878
- `
1879
- SELECT id, title, description, status, priority
1880
- FROM task_cache
1881
- WHERE title LIKE ? OR description LIKE ?
1882
- ORDER BY created_at DESC
1883
- LIMIT ?
1884
- `
1885
- ).all(`%${query2}%`, `%${query2}%`, limit);
1886
- tasks.forEach((t) => {
1887
- results.push({
1888
- type: "task",
1889
- id: t.id,
1890
- title: t.title,
1891
- status: t.status,
1892
- priority: t.priority
1893
- });
1894
- });
1895
- } catch {
1896
- }
1897
- }
1898
- let response = `# Search Results for "${query2}"
1899
-
1900
- `;
1901
- response += `Found ${results.length} results
1902
-
1903
- `;
1904
- const grouped = results.reduce(
1905
- (acc, r) => {
1906
- if (!acc[r.type]) acc[r.type] = [];
1907
- acc[r.type].push(r);
1908
- return acc;
1909
- },
1910
- {}
1911
- );
1912
- for (const [type, items] of Object.entries(grouped)) {
1913
- response += `## ${type.charAt(0).toUpperCase() + type.slice(1)}s (${items.length})
1914
- `;
1915
- for (const item of items.slice(0, 10)) {
1916
- if (type === "frame") {
1917
- response += `- [${item.frameType}] ${item.name}
1918
- `;
1919
- } else if (type === "decision") {
1920
- response += `- [${item.decisionType}] ${item.text.slice(0, 60)}...
1921
- `;
1922
- } else if (type === "task") {
1923
- response += `- [${item.status}] ${item.title}
1924
- `;
1925
- } else {
1926
- response += `- ${JSON.stringify(item).slice(0, 80)}...
1927
- `;
1928
- }
1929
- }
1930
- response += "\n";
1931
- }
1932
- return {
1933
- content: [
1934
- {
1935
- type: "text",
1936
- text: response
1937
- }
1938
- ],
1939
- metadata: { results, query: query2, scope: scope2 }
1940
- };
1941
- } catch (error) {
1942
- const message = error instanceof Error ? error.message : String(error);
1943
- logger.error("Search failed", { error: message, query, scope });
1944
- return {
1945
- content: [
1946
- {
1947
- type: "text",
1948
- text: `\u274C Search failed: ${message}`
1949
- }
1950
- ]
1951
- };
1952
- }
1953
- }
1954
- async start() {
1955
- const transport = new StdioServerTransport();
1956
- await this.server.connect(transport);
1957
- console.error("StackMemory MCP Server started");
1958
- }
1959
- }
1960
- var server_default = LocalStackMemoryMCP;
1961
- async function runMCPServer() {
1962
- const server = new LocalStackMemoryMCP();
1963
- await server.start();
1964
- }
1965
- if (import.meta.url === `file://${process.argv[1]}`) {
1966
- const server = new LocalStackMemoryMCP();
1967
- server.start().catch(console.error);
1968
- }
1969
- export {
1970
- TaskPriority,
1971
- TaskStatus,
1972
- server_default as default,
1973
- runMCPServer
1974
- };
1975
- //# sourceMappingURL=server.js.map