@chendpoc/pi-memory 0.1.13 → 0.2.1

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 (817) hide show
  1. package/README.md +284 -216
  2. package/UBIQUITOUS_LANGUAGE.md +81 -0
  3. package/dist/adapters/embed/factory.d.ts +7 -0
  4. package/dist/adapters/embed/factory.d.ts.map +1 -0
  5. package/dist/adapters/embed/factory.js +44 -0
  6. package/dist/adapters/embed/factory.js.map +1 -0
  7. package/dist/adapters/embed/hash.d.ts +3 -0
  8. package/dist/adapters/embed/hash.d.ts.map +1 -0
  9. package/dist/adapters/embed/hash.js +26 -0
  10. package/dist/adapters/embed/hash.js.map +1 -0
  11. package/dist/adapters/embed/normalize.d.ts +3 -0
  12. package/dist/adapters/embed/normalize.d.ts.map +1 -0
  13. package/dist/adapters/embed/normalize.js +15 -0
  14. package/dist/adapters/embed/normalize.js.map +1 -0
  15. package/dist/adapters/embed/ollama.d.ts +8 -0
  16. package/dist/adapters/embed/ollama.d.ts.map +1 -0
  17. package/dist/adapters/embed/ollama.js +31 -0
  18. package/dist/adapters/embed/ollama.js.map +1 -0
  19. package/dist/adapters/embed/openai.d.ts +8 -0
  20. package/dist/adapters/embed/openai.d.ts.map +1 -0
  21. package/dist/adapters/embed/openai.js +30 -0
  22. package/dist/adapters/embed/openai.js.map +1 -0
  23. package/dist/adapters/embed/types.d.ts +9 -0
  24. package/dist/adapters/embed/types.d.ts.map +1 -0
  25. package/dist/adapters/embed/types.js.map +1 -0
  26. package/dist/adapters/http.d.ts +13 -0
  27. package/dist/adapters/http.d.ts.map +1 -0
  28. package/dist/adapters/http.js +31 -0
  29. package/dist/adapters/http.js.map +1 -0
  30. package/dist/adapters/index.d.ts +4 -0
  31. package/dist/adapters/index.d.ts.map +1 -0
  32. package/dist/adapters/index.js +4 -0
  33. package/dist/adapters/index.js.map +1 -0
  34. package/dist/adapters/llm/extractText.d.ts +5 -0
  35. package/dist/adapters/llm/extractText.d.ts.map +1 -0
  36. package/dist/adapters/llm/extractText.js +7 -0
  37. package/dist/adapters/llm/extractText.js.map +1 -0
  38. package/dist/adapters/llm/factory.d.ts +11 -0
  39. package/dist/adapters/llm/factory.d.ts.map +1 -0
  40. package/dist/adapters/llm/factory.js +48 -0
  41. package/dist/adapters/llm/factory.js.map +1 -0
  42. package/dist/adapters/llm/index.d.ts +8 -0
  43. package/dist/adapters/llm/index.d.ts.map +1 -0
  44. package/dist/adapters/llm/index.js +7 -0
  45. package/dist/adapters/llm/index.js.map +1 -0
  46. package/dist/adapters/llm/modelSpec.d.ts +10 -0
  47. package/dist/adapters/llm/modelSpec.d.ts.map +1 -0
  48. package/dist/adapters/llm/modelSpec.js +21 -0
  49. package/dist/adapters/llm/modelSpec.js.map +1 -0
  50. package/dist/adapters/llm/ollama.d.ts +4 -0
  51. package/dist/adapters/llm/ollama.d.ts.map +1 -0
  52. package/dist/adapters/llm/ollama.js +32 -0
  53. package/dist/adapters/llm/ollama.js.map +1 -0
  54. package/dist/adapters/llm/openai-compat.d.ts +4 -0
  55. package/dist/adapters/llm/openai-compat.d.ts.map +1 -0
  56. package/dist/adapters/llm/openai-compat.js +36 -0
  57. package/dist/adapters/llm/openai-compat.js.map +1 -0
  58. package/dist/adapters/llm/pi-ai.d.ts +5 -0
  59. package/dist/adapters/llm/pi-ai.d.ts.map +1 -0
  60. package/dist/adapters/llm/pi-ai.js +60 -0
  61. package/dist/adapters/llm/pi-ai.js.map +1 -0
  62. package/dist/adapters/llm/standalone.d.ts +6 -0
  63. package/dist/adapters/llm/standalone.d.ts.map +1 -0
  64. package/dist/adapters/llm/standalone.js +44 -0
  65. package/dist/adapters/llm/standalone.js.map +1 -0
  66. package/dist/adapters/llm/types.d.ts +15 -0
  67. package/dist/adapters/llm/types.d.ts.map +1 -0
  68. package/dist/adapters/llm/types.js.map +1 -0
  69. package/dist/cli/init.d.ts +3 -0
  70. package/dist/cli/init.d.ts.map +1 -0
  71. package/dist/cli/init.js +13 -0
  72. package/dist/cli/init.js.map +1 -0
  73. package/dist/cli/jobs.d.ts +32 -0
  74. package/dist/cli/jobs.d.ts.map +1 -0
  75. package/dist/cli/jobs.js +100 -0
  76. package/dist/cli/jobs.js.map +1 -0
  77. package/dist/cli/log.d.ts +14 -0
  78. package/dist/cli/log.d.ts.map +1 -0
  79. package/dist/cli/log.js +32 -0
  80. package/dist/cli/log.js.map +1 -0
  81. package/dist/cli/parseArgs.d.ts +35 -0
  82. package/dist/cli/parseArgs.d.ts.map +1 -0
  83. package/dist/cli/parseArgs.js +127 -0
  84. package/dist/cli/parseArgs.js.map +1 -0
  85. package/dist/cli/status.d.ts +44 -0
  86. package/dist/cli/status.d.ts.map +1 -0
  87. package/dist/cli/status.js +238 -0
  88. package/dist/cli/status.js.map +1 -0
  89. package/dist/cli/theme.d.ts +14 -0
  90. package/dist/cli/theme.d.ts.map +1 -0
  91. package/dist/cli/theme.js +20 -0
  92. package/dist/cli/theme.js.map +1 -0
  93. package/dist/cli.js +70 -356
  94. package/dist/cli.js.map +1 -1
  95. package/dist/commands/index.d.ts +6 -0
  96. package/dist/commands/index.d.ts.map +1 -0
  97. package/dist/commands/index.js +14 -0
  98. package/dist/commands/index.js.map +1 -0
  99. package/dist/commands/parseMemoryStatusArgs.d.ts +3 -0
  100. package/dist/commands/parseMemoryStatusArgs.d.ts.map +1 -0
  101. package/dist/commands/parseMemoryStatusArgs.js +15 -0
  102. package/dist/commands/parseMemoryStatusArgs.js.map +1 -0
  103. package/dist/commands/parseRememberArgs.d.ts +10 -0
  104. package/dist/commands/parseRememberArgs.d.ts.map +1 -0
  105. package/dist/commands/parseRememberArgs.js +46 -0
  106. package/dist/commands/parseRememberArgs.js.map +1 -0
  107. package/dist/commands/remember.d.ts +8 -0
  108. package/dist/commands/remember.d.ts.map +1 -0
  109. package/dist/commands/remember.js +30 -0
  110. package/dist/commands/remember.js.map +1 -0
  111. package/dist/commands/status.d.ts +10 -0
  112. package/dist/commands/status.d.ts.map +1 -0
  113. package/dist/commands/status.js +81 -0
  114. package/dist/commands/status.js.map +1 -0
  115. package/dist/commands/types.d.ts +10 -0
  116. package/dist/commands/types.d.ts.map +1 -0
  117. package/dist/commands/types.js +2 -0
  118. package/dist/{consolidation → commands}/types.js.map +1 -1
  119. package/dist/compact/index.d.ts +5 -0
  120. package/dist/compact/index.d.ts.map +1 -0
  121. package/dist/compact/index.js +5 -0
  122. package/dist/compact/index.js.map +1 -0
  123. package/dist/compact/parseMemoryExport.d.ts +6 -0
  124. package/dist/compact/parseMemoryExport.d.ts.map +1 -0
  125. package/dist/compact/parseMemoryExport.js +62 -0
  126. package/dist/compact/parseMemoryExport.js.map +1 -0
  127. package/dist/compact/register.d.ts +10 -0
  128. package/dist/compact/register.d.ts.map +1 -0
  129. package/dist/compact/register.js +47 -0
  130. package/dist/compact/register.js.map +1 -0
  131. package/dist/compact/runSummary.d.ts +6 -0
  132. package/dist/compact/runSummary.d.ts.map +1 -0
  133. package/dist/compact/runSummary.js +29 -0
  134. package/dist/compact/runSummary.js.map +1 -0
  135. package/dist/compact/subagentDelta.d.ts +6 -0
  136. package/dist/compact/subagentDelta.d.ts.map +1 -0
  137. package/dist/compact/subagentDelta.js +13 -0
  138. package/dist/compact/subagentDelta.js.map +1 -0
  139. package/dist/compact/summaryPrompt.d.ts +3 -0
  140. package/dist/compact/summaryPrompt.d.ts.map +1 -0
  141. package/dist/compact/summaryPrompt.js +41 -0
  142. package/dist/compact/summaryPrompt.js.map +1 -0
  143. package/dist/config/agentDir.d.ts +11 -0
  144. package/dist/config/agentDir.d.ts.map +1 -0
  145. package/dist/config/agentDir.js +21 -0
  146. package/dist/config/agentDir.js.map +1 -0
  147. package/dist/config/chunking.d.ts +7 -0
  148. package/dist/config/chunking.d.ts.map +1 -0
  149. package/dist/config/chunking.js +20 -0
  150. package/dist/config/chunking.js.map +1 -0
  151. package/dist/config/env.d.ts +28 -0
  152. package/dist/config/env.d.ts.map +1 -0
  153. package/dist/config/env.js +43 -0
  154. package/dist/config/env.js.map +1 -0
  155. package/dist/config/index.d.ts +8 -0
  156. package/dist/config/index.d.ts.map +1 -0
  157. package/dist/config/index.js +8 -0
  158. package/dist/config/index.js.map +1 -0
  159. package/dist/config/loadEnv.d.ts +10 -0
  160. package/dist/config/loadEnv.d.ts.map +1 -0
  161. package/dist/config/loadEnv.js +25 -0
  162. package/dist/config/loadEnv.js.map +1 -0
  163. package/dist/config/preflight.d.ts +8 -0
  164. package/dist/config/preflight.d.ts.map +1 -0
  165. package/dist/config/preflight.js +22 -0
  166. package/dist/config/preflight.js.map +1 -0
  167. package/dist/config/preflightBudget.d.ts +9 -0
  168. package/dist/config/preflightBudget.d.ts.map +1 -0
  169. package/dist/config/preflightBudget.js +16 -0
  170. package/dist/config/preflightBudget.js.map +1 -0
  171. package/dist/config/retrieval.d.ts +10 -0
  172. package/dist/config/retrieval.d.ts.map +1 -0
  173. package/dist/config/retrieval.js +31 -0
  174. package/dist/config/retrieval.js.map +1 -0
  175. package/dist/consolidate/entryKey.d.ts +6 -0
  176. package/dist/consolidate/entryKey.d.ts.map +1 -0
  177. package/dist/consolidate/entryKey.js +5 -0
  178. package/dist/consolidate/entryKey.js.map +1 -0
  179. package/dist/consolidate/index.d.ts +5 -0
  180. package/dist/consolidate/index.d.ts.map +1 -0
  181. package/dist/consolidate/index.js +5 -0
  182. package/dist/consolidate/index.js.map +1 -0
  183. package/dist/consolidate/mergeEntries.d.ts +4 -0
  184. package/dist/consolidate/mergeEntries.d.ts.map +1 -0
  185. package/dist/consolidate/mergeEntries.js +17 -0
  186. package/dist/consolidate/mergeEntries.js.map +1 -0
  187. package/dist/consolidate/mergePrompt.d.ts +4 -0
  188. package/dist/consolidate/mergePrompt.d.ts.map +1 -0
  189. package/dist/consolidate/mergePrompt.js +40 -0
  190. package/dist/consolidate/mergePrompt.js.map +1 -0
  191. package/dist/consolidate/mergeWithLlm.d.ts +4 -0
  192. package/dist/consolidate/mergeWithLlm.d.ts.map +1 -0
  193. package/dist/consolidate/mergeWithLlm.js +27 -0
  194. package/dist/consolidate/mergeWithLlm.js.map +1 -0
  195. package/dist/consolidate/runJob.d.ts +29 -0
  196. package/dist/consolidate/runJob.d.ts.map +1 -0
  197. package/dist/consolidate/runJob.js +48 -0
  198. package/dist/consolidate/runJob.js.map +1 -0
  199. package/dist/consolidate/scheduler.d.ts +18 -0
  200. package/dist/consolidate/scheduler.d.ts.map +1 -0
  201. package/dist/consolidate/scheduler.js +32 -0
  202. package/dist/consolidate/scheduler.js.map +1 -0
  203. package/dist/constants/chunking.d.ts +7 -0
  204. package/dist/constants/chunking.d.ts.map +1 -0
  205. package/dist/constants/chunking.js +7 -0
  206. package/dist/constants/chunking.js.map +1 -0
  207. package/dist/constants/env.d.ts +47 -0
  208. package/dist/constants/env.d.ts.map +1 -0
  209. package/dist/constants/env.js +52 -0
  210. package/dist/constants/env.js.map +1 -0
  211. package/dist/constants/index.d.ts +8 -0
  212. package/dist/constants/index.d.ts.map +1 -0
  213. package/dist/constants/index.js +8 -0
  214. package/dist/constants/index.js.map +1 -0
  215. package/dist/constants/memory.d.ts +17 -0
  216. package/dist/constants/memory.d.ts.map +1 -0
  217. package/dist/constants/memory.js +16 -0
  218. package/dist/constants/memory.js.map +1 -0
  219. package/dist/constants/paths.d.ts +23 -0
  220. package/dist/constants/paths.d.ts.map +1 -0
  221. package/dist/constants/paths.js +23 -0
  222. package/dist/constants/paths.js.map +1 -0
  223. package/dist/constants/preflight.d.ts +17 -0
  224. package/dist/constants/preflight.d.ts.map +1 -0
  225. package/dist/constants/preflight.js +17 -0
  226. package/dist/constants/preflight.js.map +1 -0
  227. package/dist/constants/retrieval.d.ts +10 -0
  228. package/dist/constants/retrieval.d.ts.map +1 -0
  229. package/dist/constants/retrieval.js +10 -0
  230. package/dist/constants/retrieval.js.map +1 -0
  231. package/dist/constants/security.d.ts +5 -0
  232. package/dist/constants/security.d.ts.map +1 -0
  233. package/dist/constants/security.js +5 -0
  234. package/dist/constants/security.js.map +1 -0
  235. package/dist/constants/timing.d.ts +38 -0
  236. package/dist/constants/timing.d.ts.map +1 -0
  237. package/dist/constants/timing.js +38 -0
  238. package/dist/constants/timing.js.map +1 -0
  239. package/dist/index.d.ts +11 -29
  240. package/dist/index.d.ts.map +1 -1
  241. package/dist/index.js +11 -28
  242. package/dist/index.js.map +1 -1
  243. package/dist/init/workspace.d.ts +15 -0
  244. package/dist/init/workspace.d.ts.map +1 -0
  245. package/dist/init/workspace.js +32 -0
  246. package/dist/init/workspace.js.map +1 -0
  247. package/dist/ipc/jsonlFramer.d.ts +9 -0
  248. package/dist/ipc/jsonlFramer.d.ts.map +1 -0
  249. package/dist/ipc/jsonlFramer.js +26 -0
  250. package/dist/ipc/jsonlFramer.js.map +1 -0
  251. package/dist/pi-extension.d.ts +0 -2
  252. package/dist/pi-extension.d.ts.map +1 -1
  253. package/dist/pi-extension.js +175 -515
  254. package/dist/pi-extension.js.map +1 -1
  255. package/dist/preflight/episodic.d.ts +26 -0
  256. package/dist/preflight/episodic.d.ts.map +1 -0
  257. package/dist/preflight/episodic.js +125 -0
  258. package/dist/preflight/episodic.js.map +1 -0
  259. package/dist/preflight/intentCache.d.ts +13 -0
  260. package/dist/preflight/intentCache.d.ts.map +1 -0
  261. package/dist/preflight/intentCache.js +37 -0
  262. package/dist/preflight/intentCache.js.map +1 -0
  263. package/dist/preflight/queryCache.d.ts +15 -0
  264. package/dist/preflight/queryCache.d.ts.map +1 -0
  265. package/dist/preflight/queryCache.js +46 -0
  266. package/dist/preflight/queryCache.js.map +1 -0
  267. package/dist/preflight/queryIntent.d.ts +29 -0
  268. package/dist/preflight/queryIntent.d.ts.map +1 -0
  269. package/dist/preflight/queryIntent.js +91 -0
  270. package/dist/preflight/queryIntent.js.map +1 -0
  271. package/dist/preflight/render.d.ts +8 -33
  272. package/dist/preflight/render.d.ts.map +1 -1
  273. package/dist/preflight/render.js +29 -126
  274. package/dist/preflight/render.js.map +1 -1
  275. package/dist/preflight/session.d.ts +3 -0
  276. package/dist/preflight/session.d.ts.map +1 -0
  277. package/dist/preflight/session.js +6 -0
  278. package/dist/preflight/session.js.map +1 -0
  279. package/dist/preflight/strip.d.ts +0 -8
  280. package/dist/preflight/strip.d.ts.map +1 -1
  281. package/dist/preflight/strip.js +2 -11
  282. package/dist/preflight/strip.js.map +1 -1
  283. package/dist/shutdown/enqueue.d.ts +12 -0
  284. package/dist/shutdown/enqueue.d.ts.map +1 -0
  285. package/dist/shutdown/enqueue.js +14 -0
  286. package/dist/shutdown/enqueue.js.map +1 -0
  287. package/dist/shutdown/extractPrompt.d.ts +4 -0
  288. package/dist/shutdown/extractPrompt.d.ts.map +1 -0
  289. package/dist/shutdown/extractPrompt.js +29 -0
  290. package/dist/shutdown/extractPrompt.js.map +1 -0
  291. package/dist/shutdown/processed.d.ts +9 -0
  292. package/dist/shutdown/processed.d.ts.map +1 -0
  293. package/dist/shutdown/processed.js +28 -0
  294. package/dist/shutdown/processed.js.map +1 -0
  295. package/dist/shutdown/readQueue.d.ts +4 -0
  296. package/dist/shutdown/readQueue.d.ts.map +1 -0
  297. package/dist/shutdown/readQueue.js +26 -0
  298. package/dist/shutdown/readQueue.js.map +1 -0
  299. package/dist/shutdown/runDrainJob.d.ts +26 -0
  300. package/dist/shutdown/runDrainJob.d.ts.map +1 -0
  301. package/dist/shutdown/runDrainJob.js +143 -0
  302. package/dist/shutdown/runDrainJob.js.map +1 -0
  303. package/dist/shutdown/sessionReader.d.ts +6 -0
  304. package/dist/shutdown/sessionReader.d.ts.map +1 -0
  305. package/dist/shutdown/sessionReader.js +44 -0
  306. package/dist/shutdown/sessionReader.js.map +1 -0
  307. package/dist/sidecar/client.d.ts +17 -16
  308. package/dist/sidecar/client.d.ts.map +1 -1
  309. package/dist/sidecar/client.js +64 -100
  310. package/dist/sidecar/client.js.map +1 -1
  311. package/dist/sidecar/paths.d.ts +8 -0
  312. package/dist/sidecar/paths.d.ts.map +1 -0
  313. package/dist/sidecar/paths.js +23 -0
  314. package/dist/sidecar/paths.js.map +1 -0
  315. package/dist/sidecar/protocol.d.ts +54 -0
  316. package/dist/sidecar/protocol.d.ts.map +1 -0
  317. package/dist/sidecar/protocol.js +4 -0
  318. package/dist/sidecar/protocol.js.map +1 -0
  319. package/dist/sidecar/reindexBridge.d.ts +13 -0
  320. package/dist/sidecar/reindexBridge.d.ts.map +1 -0
  321. package/dist/sidecar/reindexBridge.js +37 -0
  322. package/dist/sidecar/reindexBridge.js.map +1 -0
  323. package/dist/sidecar/server/process.d.ts +2 -0
  324. package/dist/sidecar/server/process.d.ts.map +1 -0
  325. package/dist/sidecar/server/process.js +22 -0
  326. package/dist/sidecar/server/process.js.map +1 -0
  327. package/dist/sidecar/server/query.d.ts +8 -0
  328. package/dist/sidecar/server/query.d.ts.map +1 -0
  329. package/dist/sidecar/server/query.js +7 -0
  330. package/dist/sidecar/server/query.js.map +1 -0
  331. package/dist/sidecar/server/reindex.d.ts +8 -0
  332. package/dist/sidecar/server/reindex.d.ts.map +1 -0
  333. package/dist/sidecar/server/reindex.js +12 -0
  334. package/dist/sidecar/server/reindex.js.map +1 -0
  335. package/dist/sidecar/server/server.d.ts +11 -0
  336. package/dist/sidecar/server/server.d.ts.map +1 -0
  337. package/dist/sidecar/server/server.js +76 -0
  338. package/dist/sidecar/server/server.js.map +1 -0
  339. package/dist/sidecar/server/stats.d.ts +8 -0
  340. package/dist/sidecar/server/stats.d.ts.map +1 -0
  341. package/dist/sidecar/server/stats.js +18 -0
  342. package/dist/sidecar/server/stats.js.map +1 -0
  343. package/dist/sidecar/server/vec/embedder.d.ts +2 -0
  344. package/dist/sidecar/server/vec/embedder.d.ts.map +1 -0
  345. package/dist/sidecar/server/vec/embedder.js +2 -0
  346. package/dist/sidecar/server/vec/embedder.js.map +1 -0
  347. package/dist/sidecar/server/vec/mmr.d.ts +13 -0
  348. package/dist/sidecar/server/vec/mmr.d.ts.map +1 -0
  349. package/dist/sidecar/server/vec/mmr.js +36 -0
  350. package/dist/sidecar/server/vec/mmr.js.map +1 -0
  351. package/dist/sidecar/server/vec/store.d.ts +30 -0
  352. package/dist/sidecar/server/vec/store.d.ts.map +1 -0
  353. package/dist/sidecar/server/vec/store.js +179 -0
  354. package/dist/sidecar/server/vec/store.js.map +1 -0
  355. package/dist/sidecar/sidecarManager.d.ts +10 -0
  356. package/dist/sidecar/sidecarManager.d.ts.map +1 -0
  357. package/dist/sidecar/sidecarManager.js +111 -0
  358. package/dist/sidecar/sidecarManager.js.map +1 -0
  359. package/dist/sidecar/utils.d.ts +3 -0
  360. package/dist/sidecar/utils.d.ts.map +1 -0
  361. package/dist/sidecar/utils.js +27 -0
  362. package/dist/sidecar/utils.js.map +1 -0
  363. package/dist/sidecar/warmup.d.ts +6 -0
  364. package/dist/sidecar/warmup.d.ts.map +1 -0
  365. package/dist/sidecar/warmup.js +39 -0
  366. package/dist/sidecar/warmup.js.map +1 -0
  367. package/dist/store/backend.d.ts +12 -0
  368. package/dist/store/backend.d.ts.map +1 -0
  369. package/dist/store/backend.js +47 -0
  370. package/dist/store/backend.js.map +1 -0
  371. package/dist/store/index.d.ts +6 -0
  372. package/dist/store/index.d.ts.map +1 -0
  373. package/dist/store/index.js +6 -0
  374. package/dist/store/index.js.map +1 -0
  375. package/dist/store/indexChunks.d.ts +9 -0
  376. package/dist/store/indexChunks.d.ts.map +1 -0
  377. package/dist/store/indexChunks.js +78 -0
  378. package/dist/store/indexChunks.js.map +1 -0
  379. package/dist/store/markdown/format.d.ts +5 -0
  380. package/dist/store/markdown/format.d.ts.map +1 -0
  381. package/dist/store/markdown/format.js +14 -0
  382. package/dist/store/markdown/format.js.map +1 -0
  383. package/dist/store/markdown/parse.d.ts +5 -0
  384. package/dist/store/markdown/parse.d.ts.map +1 -0
  385. package/dist/store/markdown/parse.js +57 -0
  386. package/dist/store/markdown/parse.js.map +1 -0
  387. package/dist/store/markdown/template.d.ts +3 -0
  388. package/dist/store/markdown/template.d.ts.map +1 -0
  389. package/dist/store/markdown/template.js +22 -0
  390. package/dist/store/markdown/template.js.map +1 -0
  391. package/dist/store/memoryStore.d.ts +69 -0
  392. package/dist/store/memoryStore.d.ts.map +1 -0
  393. package/dist/store/memoryStore.js +421 -0
  394. package/dist/store/memoryStore.js.map +1 -0
  395. package/dist/store/paths.d.ts +10 -0
  396. package/dist/store/paths.d.ts.map +1 -0
  397. package/dist/store/paths.js +19 -0
  398. package/dist/store/paths.js.map +1 -0
  399. package/dist/store/types.d.ts +38 -0
  400. package/dist/store/types.d.ts.map +1 -0
  401. package/dist/store/types.js +3 -0
  402. package/dist/store/types.js.map +1 -0
  403. package/dist/ui/memoryStatusWidget.d.ts +20 -0
  404. package/dist/ui/memoryStatusWidget.d.ts.map +1 -0
  405. package/dist/ui/memoryStatusWidget.js +51 -0
  406. package/dist/ui/memoryStatusWidget.js.map +1 -0
  407. package/dist/utils/debugLog.d.ts +4 -0
  408. package/dist/utils/debugLog.d.ts.map +1 -0
  409. package/dist/utils/debugLog.js +14 -0
  410. package/dist/utils/debugLog.js.map +1 -0
  411. package/dist/utils/fs.d.ts +26 -0
  412. package/dist/utils/fs.d.ts.map +1 -0
  413. package/dist/utils/fs.js +101 -0
  414. package/dist/utils/fs.js.map +1 -0
  415. package/dist/utils/index.d.ts +8 -0
  416. package/dist/utils/index.d.ts.map +1 -0
  417. package/dist/utils/index.js +8 -0
  418. package/dist/utils/index.js.map +1 -0
  419. package/dist/utils/paths.d.ts +22 -0
  420. package/dist/utils/paths.d.ts.map +1 -0
  421. package/dist/utils/paths.js +51 -0
  422. package/dist/utils/paths.js.map +1 -0
  423. package/dist/utils/platform.d.ts +7 -0
  424. package/dist/utils/platform.d.ts.map +1 -0
  425. package/dist/utils/platform.js +18 -0
  426. package/dist/utils/platform.js.map +1 -0
  427. package/dist/utils/scheduler.d.ts +33 -0
  428. package/dist/utils/scheduler.d.ts.map +1 -0
  429. package/dist/utils/scheduler.js +63 -0
  430. package/dist/utils/scheduler.js.map +1 -0
  431. package/dist/utils/socket.d.ts +7 -0
  432. package/dist/utils/socket.d.ts.map +1 -0
  433. package/dist/utils/socket.js +35 -0
  434. package/dist/utils/socket.js.map +1 -0
  435. package/dist/utils/time.d.ts +22 -0
  436. package/dist/utils/time.d.ts.map +1 -0
  437. package/dist/utils/time.js +42 -0
  438. package/dist/utils/time.js.map +1 -0
  439. package/doc/README-zh.md +365 -0
  440. package/doc/ROADMAP-zh.md +52 -0
  441. package/doc/ROADMAP.md +52 -0
  442. package/package.json +31 -10
  443. package/scripts/init-memory-workspace.mjs +62 -0
  444. package/scripts/path-utils.mjs +12 -0
  445. package/scripts/platform-fs.mjs +65 -0
  446. package/scripts/postinstall.mjs +17 -0
  447. package/src/adapters/embed/factory.ts +50 -0
  448. package/src/adapters/embed/hash.ts +29 -0
  449. package/src/adapters/embed/normalize.ts +13 -0
  450. package/src/adapters/embed/ollama.ts +49 -0
  451. package/src/adapters/embed/openai.ts +46 -0
  452. package/src/adapters/embed/types.ts +9 -0
  453. package/src/adapters/http.ts +42 -0
  454. package/src/adapters/index.ts +16 -0
  455. package/src/adapters/llm/extractText.ts +6 -0
  456. package/src/adapters/llm/factory.ts +60 -0
  457. package/src/adapters/llm/index.ts +7 -0
  458. package/src/adapters/llm/modelSpec.ts +39 -0
  459. package/src/adapters/llm/ollama.ts +42 -0
  460. package/src/adapters/llm/openai-compat.ts +46 -0
  461. package/src/adapters/llm/pi-ai.ts +75 -0
  462. package/src/adapters/llm/standalone.ts +60 -0
  463. package/src/adapters/llm/types.ts +16 -0
  464. package/src/cli/init.ts +18 -0
  465. package/src/cli/jobs.ts +144 -0
  466. package/src/cli/log.ts +46 -0
  467. package/src/cli/parseArgs.ts +175 -0
  468. package/src/cli/status.ts +323 -0
  469. package/src/cli/theme.ts +26 -0
  470. package/src/cli.ts +80 -374
  471. package/src/commands/index.ts +20 -0
  472. package/src/commands/parseMemoryStatusArgs.ts +11 -0
  473. package/src/commands/parseRememberArgs.ts +55 -0
  474. package/src/commands/remember.ts +43 -0
  475. package/src/commands/status.ts +112 -0
  476. package/src/commands/types.ts +12 -0
  477. package/src/compact/index.ts +4 -0
  478. package/src/compact/parseMemoryExport.ts +71 -0
  479. package/src/compact/register.ts +57 -0
  480. package/src/compact/runSummary.ts +42 -0
  481. package/src/compact/subagentDelta.ts +22 -0
  482. package/src/compact/summaryPrompt.ts +45 -0
  483. package/src/config/agentDir.ts +24 -0
  484. package/src/config/chunking.ts +36 -0
  485. package/src/config/env.ts +97 -0
  486. package/src/config/index.ts +7 -0
  487. package/src/config/loadEnv.ts +26 -0
  488. package/src/config/preflight.ts +34 -0
  489. package/src/config/preflightBudget.ts +33 -0
  490. package/src/config/retrieval.ts +50 -0
  491. package/src/consolidate/entryKey.ts +4 -0
  492. package/src/consolidate/index.ts +4 -0
  493. package/src/consolidate/mergeEntries.ts +22 -0
  494. package/src/consolidate/mergePrompt.ts +46 -0
  495. package/src/consolidate/mergeWithLlm.ts +39 -0
  496. package/src/consolidate/runJob.ts +81 -0
  497. package/src/consolidate/scheduler.ts +54 -0
  498. package/src/constants/chunking.ts +8 -0
  499. package/src/constants/env.ts +59 -0
  500. package/src/constants/index.ts +7 -0
  501. package/src/constants/memory.ts +22 -0
  502. package/src/constants/paths.ts +26 -0
  503. package/src/constants/preflight.ts +22 -0
  504. package/src/constants/retrieval.ts +10 -0
  505. package/src/constants/security.ts +5 -0
  506. package/src/constants/timing.ts +48 -0
  507. package/src/index.ts +11 -247
  508. package/src/init/workspace.ts +44 -0
  509. package/src/ipc/jsonlFramer.ts +29 -0
  510. package/src/pi-extension.ts +196 -605
  511. package/src/preflight/episodic.ts +183 -0
  512. package/src/preflight/intentCache.ts +44 -0
  513. package/src/preflight/queryCache.ts +59 -0
  514. package/src/preflight/queryIntent.ts +126 -0
  515. package/src/preflight/render.ts +34 -180
  516. package/src/preflight/session.ts +7 -0
  517. package/src/preflight/strip.ts +4 -11
  518. package/src/shutdown/enqueue.ts +29 -0
  519. package/src/shutdown/extractPrompt.ts +27 -0
  520. package/src/shutdown/processed.ts +45 -0
  521. package/src/shutdown/readQueue.ts +26 -0
  522. package/src/shutdown/runDrainJob.ts +202 -0
  523. package/src/shutdown/sessionReader.ts +61 -0
  524. package/src/sidecar/client.ts +98 -150
  525. package/src/sidecar/paths.ts +31 -0
  526. package/src/sidecar/protocol.ts +38 -0
  527. package/src/sidecar/reindexBridge.ts +52 -0
  528. package/src/sidecar/server/process.ts +27 -0
  529. package/src/sidecar/server/query.ts +16 -0
  530. package/src/sidecar/server/reindex.ts +21 -0
  531. package/src/sidecar/server/server.ts +105 -0
  532. package/src/sidecar/server/stats.ts +23 -0
  533. package/src/sidecar/server/vec/embedder.ts +1 -0
  534. package/src/sidecar/server/vec/mmr.ts +55 -0
  535. package/src/sidecar/server/vec/store.ts +232 -0
  536. package/src/sidecar/sidecarManager.ts +134 -0
  537. package/src/sidecar/utils.ts +28 -0
  538. package/src/sidecar/warmup.ts +50 -0
  539. package/src/store/backend.ts +66 -0
  540. package/src/store/index.ts +5 -0
  541. package/src/store/indexChunks.ts +89 -0
  542. package/src/store/markdown/format.ts +16 -0
  543. package/src/store/markdown/parse.ts +63 -0
  544. package/src/store/markdown/template.ts +24 -0
  545. package/src/store/memoryStore.ts +518 -0
  546. package/src/store/paths.ts +33 -0
  547. package/src/store/proper-lockfile.d.ts +3 -0
  548. package/src/store/types.ts +46 -0
  549. package/src/ui/memoryStatusWidget.ts +80 -0
  550. package/src/utils/debugLog.ts +22 -0
  551. package/src/utils/fs.ts +115 -0
  552. package/src/utils/index.ts +68 -0
  553. package/src/utils/paths.ts +67 -0
  554. package/src/utils/platform.ts +20 -0
  555. package/src/utils/scheduler.ts +98 -0
  556. package/src/utils/socket.ts +33 -0
  557. package/src/utils/time.ts +51 -0
  558. package/templates/MEMORY.md.example +22 -0
  559. package/dist/adapters/ollamaClient.d.ts +0 -11
  560. package/dist/adapters/ollamaClient.d.ts.map +0 -1
  561. package/dist/adapters/ollamaClient.js +0 -122
  562. package/dist/adapters/ollamaClient.js.map +0 -1
  563. package/dist/adapters/openaiCompatClient.d.ts +0 -11
  564. package/dist/adapters/openaiCompatClient.d.ts.map +0 -1
  565. package/dist/adapters/openaiCompatClient.js +0 -118
  566. package/dist/adapters/openaiCompatClient.js.map +0 -1
  567. package/dist/adapters/piComplete.d.ts +0 -17
  568. package/dist/adapters/piComplete.d.ts.map +0 -1
  569. package/dist/adapters/piComplete.js +0 -169
  570. package/dist/adapters/piComplete.js.map +0 -1
  571. package/dist/bundle/install.d.ts +0 -34
  572. package/dist/bundle/install.d.ts.map +0 -1
  573. package/dist/bundle/install.js +0 -183
  574. package/dist/bundle/install.js.map +0 -1
  575. package/dist/cache/memoryCaches.d.ts +0 -32
  576. package/dist/cache/memoryCaches.d.ts.map +0 -1
  577. package/dist/cache/memoryCaches.js +0 -59
  578. package/dist/cache/memoryCaches.js.map +0 -1
  579. package/dist/config.d.ts +0 -55
  580. package/dist/config.d.ts.map +0 -1
  581. package/dist/config.js +0 -85
  582. package/dist/config.js.map +0 -1
  583. package/dist/consolidation/enqueue.d.ts +0 -33
  584. package/dist/consolidation/enqueue.d.ts.map +0 -1
  585. package/dist/consolidation/enqueue.js +0 -145
  586. package/dist/consolidation/enqueue.js.map +0 -1
  587. package/dist/consolidation/index.d.ts +0 -19
  588. package/dist/consolidation/index.d.ts.map +0 -1
  589. package/dist/consolidation/index.js +0 -15
  590. package/dist/consolidation/index.js.map +0 -1
  591. package/dist/consolidation/lock.d.ts +0 -5
  592. package/dist/consolidation/lock.d.ts.map +0 -1
  593. package/dist/consolidation/lock.js +0 -33
  594. package/dist/consolidation/lock.js.map +0 -1
  595. package/dist/consolidation/log.d.ts +0 -8
  596. package/dist/consolidation/log.d.ts.map +0 -1
  597. package/dist/consolidation/log.js +0 -32
  598. package/dist/consolidation/log.js.map +0 -1
  599. package/dist/consolidation/memoryIndex.d.ts +0 -18
  600. package/dist/consolidation/memoryIndex.d.ts.map +0 -1
  601. package/dist/consolidation/memoryIndex.js +0 -100
  602. package/dist/consolidation/memoryIndex.js.map +0 -1
  603. package/dist/consolidation/phase2/runPhase2.d.ts +0 -23
  604. package/dist/consolidation/phase2/runPhase2.d.ts.map +0 -1
  605. package/dist/consolidation/phase2/runPhase2.js +0 -196
  606. package/dist/consolidation/phase2/runPhase2.js.map +0 -1
  607. package/dist/consolidation/scheduler/launchd.d.ts +0 -5
  608. package/dist/consolidation/scheduler/launchd.d.ts.map +0 -1
  609. package/dist/consolidation/scheduler/launchd.js +0 -54
  610. package/dist/consolidation/scheduler/launchd.js.map +0 -1
  611. package/dist/consolidation/scheduler/runConsolidate.d.ts +0 -26
  612. package/dist/consolidation/scheduler/runConsolidate.d.ts.map +0 -1
  613. package/dist/consolidation/scheduler/runConsolidate.js +0 -83
  614. package/dist/consolidation/scheduler/runConsolidate.js.map +0 -1
  615. package/dist/consolidation/scheduler/setupSchedule.d.ts +0 -3
  616. package/dist/consolidation/scheduler/setupSchedule.d.ts.map +0 -1
  617. package/dist/consolidation/scheduler/setupSchedule.js +0 -79
  618. package/dist/consolidation/scheduler/setupSchedule.js.map +0 -1
  619. package/dist/consolidation/scheduler/systemd.d.ts +0 -9
  620. package/dist/consolidation/scheduler/systemd.d.ts.map +0 -1
  621. package/dist/consolidation/scheduler/systemd.js +0 -57
  622. package/dist/consolidation/scheduler/systemd.js.map +0 -1
  623. package/dist/consolidation/scheduler/types.d.ts +0 -24
  624. package/dist/consolidation/scheduler/types.d.ts.map +0 -1
  625. package/dist/consolidation/scheduler/types.js.map +0 -1
  626. package/dist/consolidation/scope.d.ts +0 -12
  627. package/dist/consolidation/scope.d.ts.map +0 -1
  628. package/dist/consolidation/scope.js +0 -51
  629. package/dist/consolidation/scope.js.map +0 -1
  630. package/dist/consolidation/stage1/deltaExtract.d.ts +0 -3
  631. package/dist/consolidation/stage1/deltaExtract.d.ts.map +0 -1
  632. package/dist/consolidation/stage1/deltaExtract.js +0 -19
  633. package/dist/consolidation/stage1/deltaExtract.js.map +0 -1
  634. package/dist/consolidation/stage1/drainQueue.d.ts +0 -21
  635. package/dist/consolidation/stage1/drainQueue.d.ts.map +0 -1
  636. package/dist/consolidation/stage1/drainQueue.js +0 -113
  637. package/dist/consolidation/stage1/drainQueue.js.map +0 -1
  638. package/dist/consolidation/stage1/extractSession.d.ts +0 -6
  639. package/dist/consolidation/stage1/extractSession.d.ts.map +0 -1
  640. package/dist/consolidation/stage1/extractSession.js +0 -47
  641. package/dist/consolidation/stage1/extractSession.js.map +0 -1
  642. package/dist/consolidation/stage1/store.d.ts +0 -45
  643. package/dist/consolidation/stage1/store.d.ts.map +0 -1
  644. package/dist/consolidation/stage1/store.js +0 -297
  645. package/dist/consolidation/stage1/store.js.map +0 -1
  646. package/dist/consolidation/types.d.ts +0 -49
  647. package/dist/consolidation/types.d.ts.map +0 -1
  648. package/dist/errclass.d.ts +0 -7
  649. package/dist/errclass.d.ts.map +0 -1
  650. package/dist/errclass.js +0 -32
  651. package/dist/errclass.js.map +0 -1
  652. package/dist/extension.d.ts +0 -24
  653. package/dist/extension.d.ts.map +0 -1
  654. package/dist/extension.js +0 -7
  655. package/dist/extension.js.map +0 -1
  656. package/dist/fallback/index.d.ts +0 -11
  657. package/dist/fallback/index.d.ts.map +0 -1
  658. package/dist/fallback/index.js +0 -16
  659. package/dist/fallback/index.js.map +0 -1
  660. package/dist/fallback/llmRerank.d.ts +0 -19
  661. package/dist/fallback/llmRerank.d.ts.map +0 -1
  662. package/dist/fallback/llmRerank.js +0 -68
  663. package/dist/fallback/llmRerank.js.map +0 -1
  664. package/dist/fallback/memoryMd.d.ts +0 -6
  665. package/dist/fallback/memoryMd.d.ts.map +0 -1
  666. package/dist/fallback/memoryMd.js +0 -35
  667. package/dist/fallback/memoryMd.js.map +0 -1
  668. package/dist/fallback/sessionIndex.d.ts +0 -35
  669. package/dist/fallback/sessionIndex.d.ts.map +0 -1
  670. package/dist/fallback/sessionIndex.js +0 -239
  671. package/dist/fallback/sessionIndex.js.map +0 -1
  672. package/dist/fallback/sessionSearch.d.ts +0 -18
  673. package/dist/fallback/sessionSearch.d.ts.map +0 -1
  674. package/dist/fallback/sessionSearch.js +0 -234
  675. package/dist/fallback/sessionSearch.js.map +0 -1
  676. package/dist/local/graphQuery.d.ts +0 -31
  677. package/dist/local/graphQuery.d.ts.map +0 -1
  678. package/dist/local/graphQuery.js +0 -195
  679. package/dist/local/graphQuery.js.map +0 -1
  680. package/dist/paths.d.ts +0 -7
  681. package/dist/paths.d.ts.map +0 -1
  682. package/dist/paths.js +0 -26
  683. package/dist/paths.js.map +0 -1
  684. package/dist/preflight/detectIntents.d.ts +0 -102
  685. package/dist/preflight/detectIntents.d.ts.map +0 -1
  686. package/dist/preflight/detectIntents.js +0 -631
  687. package/dist/preflight/detectIntents.js.map +0 -1
  688. package/dist/preflight/hook.d.ts +0 -76
  689. package/dist/preflight/hook.d.ts.map +0 -1
  690. package/dist/preflight/hook.js +0 -122
  691. package/dist/preflight/hook.js.map +0 -1
  692. package/dist/service.d.ts +0 -72
  693. package/dist/service.d.ts.map +0 -1
  694. package/dist/service.js +0 -257
  695. package/dist/service.js.map +0 -1
  696. package/dist/session/activeBranch.d.ts +0 -17
  697. package/dist/session/activeBranch.d.ts.map +0 -1
  698. package/dist/session/activeBranch.js +0 -251
  699. package/dist/session/activeBranch.js.map +0 -1
  700. package/dist/settings.d.ts +0 -41
  701. package/dist/settings.d.ts.map +0 -1
  702. package/dist/settings.js +0 -85
  703. package/dist/settings.js.map +0 -1
  704. package/dist/sidecar/bundle.d.ts +0 -19
  705. package/dist/sidecar/bundle.d.ts.map +0 -1
  706. package/dist/sidecar/bundle.js +0 -39
  707. package/dist/sidecar/bundle.js.map +0 -1
  708. package/dist/sidecar/process.d.ts +0 -14
  709. package/dist/sidecar/process.d.ts.map +0 -1
  710. package/dist/sidecar/process.js +0 -138
  711. package/dist/sidecar/process.js.map +0 -1
  712. package/dist/tools/memoryAppend.d.ts +0 -47
  713. package/dist/tools/memoryAppend.d.ts.map +0 -1
  714. package/dist/tools/memoryAppend.js +0 -138
  715. package/dist/tools/memoryAppend.js.map +0 -1
  716. package/dist/tools/memoryRecall.d.ts +0 -113
  717. package/dist/tools/memoryRecall.d.ts.map +0 -1
  718. package/dist/tools/memoryRecall.js +0 -351
  719. package/dist/tools/memoryRecall.js.map +0 -1
  720. package/dist/trainer/bundleBuilder.d.ts +0 -30
  721. package/dist/trainer/bundleBuilder.d.ts.map +0 -1
  722. package/dist/trainer/bundleBuilder.js +0 -106
  723. package/dist/trainer/bundleBuilder.js.map +0 -1
  724. package/dist/trainer/bundleLoader.d.ts +0 -12
  725. package/dist/trainer/bundleLoader.d.ts.map +0 -1
  726. package/dist/trainer/bundleLoader.js +0 -59
  727. package/dist/trainer/bundleLoader.js.map +0 -1
  728. package/dist/trainer/deltaMerge.d.ts +0 -38
  729. package/dist/trainer/deltaMerge.d.ts.map +0 -1
  730. package/dist/trainer/deltaMerge.js +0 -183
  731. package/dist/trainer/deltaMerge.js.map +0 -1
  732. package/dist/trainer/entityResolver.d.ts +0 -27
  733. package/dist/trainer/entityResolver.d.ts.map +0 -1
  734. package/dist/trainer/entityResolver.js +0 -92
  735. package/dist/trainer/entityResolver.js.map +0 -1
  736. package/dist/trainer/extractFacts.d.ts +0 -67
  737. package/dist/trainer/extractFacts.d.ts.map +0 -1
  738. package/dist/trainer/extractFacts.js +0 -213
  739. package/dist/trainer/extractFacts.js.map +0 -1
  740. package/dist/trainer/index.d.ts +0 -54
  741. package/dist/trainer/index.d.ts.map +0 -1
  742. package/dist/trainer/index.js +0 -82
  743. package/dist/trainer/index.js.map +0 -1
  744. package/dist/trainer/llmExtractor.d.ts +0 -16
  745. package/dist/trainer/llmExtractor.d.ts.map +0 -1
  746. package/dist/trainer/llmExtractor.js +0 -146
  747. package/dist/trainer/llmExtractor.js.map +0 -1
  748. package/dist/trainer/marker.d.ts +0 -10
  749. package/dist/trainer/marker.d.ts.map +0 -1
  750. package/dist/trainer/marker.js +0 -28
  751. package/dist/trainer/marker.js.map +0 -1
  752. package/dist/trainer/scheduler.d.ts +0 -33
  753. package/dist/trainer/scheduler.d.ts.map +0 -1
  754. package/dist/trainer/scheduler.js +0 -73
  755. package/dist/trainer/scheduler.js.map +0 -1
  756. package/dist/trainer/sessionLoader.d.ts +0 -26
  757. package/dist/trainer/sessionLoader.d.ts.map +0 -1
  758. package/dist/trainer/sessionLoader.js +0 -145
  759. package/dist/trainer/sessionLoader.js.map +0 -1
  760. package/dist/types.d.ts +0 -135
  761. package/dist/types.d.ts.map +0 -1
  762. package/dist/types.js +0 -8
  763. package/dist/types.js.map +0 -1
  764. package/src/adapters/ollamaClient.ts +0 -179
  765. package/src/adapters/openaiCompatClient.ts +0 -155
  766. package/src/adapters/piComplete.ts +0 -233
  767. package/src/bundle/install.ts +0 -206
  768. package/src/cache/memoryCaches.ts +0 -72
  769. package/src/config.ts +0 -180
  770. package/src/consolidation/enqueue.ts +0 -205
  771. package/src/consolidation/index.ts +0 -90
  772. package/src/consolidation/lock.ts +0 -41
  773. package/src/consolidation/log.ts +0 -43
  774. package/src/consolidation/memoryIndex.ts +0 -127
  775. package/src/consolidation/phase2/runPhase2.ts +0 -255
  776. package/src/consolidation/scheduler/launchd.ts +0 -62
  777. package/src/consolidation/scheduler/runConsolidate.ts +0 -115
  778. package/src/consolidation/scheduler/setupSchedule.ts +0 -106
  779. package/src/consolidation/scheduler/systemd.ts +0 -78
  780. package/src/consolidation/scheduler/types.ts +0 -27
  781. package/src/consolidation/scope.ts +0 -58
  782. package/src/consolidation/stage1/deltaExtract.ts +0 -29
  783. package/src/consolidation/stage1/drainQueue.ts +0 -143
  784. package/src/consolidation/stage1/extractSession.ts +0 -58
  785. package/src/consolidation/stage1/store.ts +0 -411
  786. package/src/consolidation/types.ts +0 -52
  787. package/src/errclass.ts +0 -37
  788. package/src/extension.ts +0 -23
  789. package/src/fallback/index.ts +0 -24
  790. package/src/fallback/llmRerank.ts +0 -97
  791. package/src/fallback/memoryMd.ts +0 -36
  792. package/src/fallback/sessionIndex.ts +0 -290
  793. package/src/fallback/sessionSearch.ts +0 -261
  794. package/src/local/graphQuery.ts +0 -252
  795. package/src/paths.ts +0 -28
  796. package/src/preflight/detectIntents.ts +0 -660
  797. package/src/preflight/hook.ts +0 -213
  798. package/src/service.ts +0 -306
  799. package/src/session/activeBranch.ts +0 -294
  800. package/src/settings.ts +0 -161
  801. package/src/sidecar/bundle.ts +0 -52
  802. package/src/sidecar/process.ts +0 -160
  803. package/src/tools/memoryAppend.ts +0 -166
  804. package/src/tools/memoryRecall.ts +0 -388
  805. package/src/trainer/bundleBuilder.ts +0 -192
  806. package/src/trainer/bundleLoader.ts +0 -105
  807. package/src/trainer/deltaMerge.ts +0 -221
  808. package/src/trainer/entityResolver.ts +0 -140
  809. package/src/trainer/extractFacts.ts +0 -312
  810. package/src/trainer/index.ts +0 -147
  811. package/src/trainer/llmExtractor.ts +0 -206
  812. package/src/trainer/marker.ts +0 -30
  813. package/src/trainer/scheduler.ts +0 -107
  814. package/src/trainer/sessionLoader.ts +0 -176
  815. package/src/types.ts +0 -168
  816. /package/dist/{consolidation/scheduler → adapters/embed}/types.js +0 -0
  817. /package/dist/{consolidation → adapters/llm}/types.js +0 -0
@@ -1,206 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
-
5
- import type { BundleManifest } from "../sidecar/bundle.js";
6
-
7
- export interface InstallBundleOptions {
8
- bundleRoot: string;
9
- sourceDir: string;
10
- /** Number of old bundles to keep after install (default 3). */
11
- retain?: number;
12
- }
13
-
14
- export interface InstallBundleResult {
15
- bundle_ts: string;
16
- bundle_version: string;
17
- installed_dir: string;
18
- files_copied: number;
19
- }
20
-
21
- /**
22
- * Enforces [0.4.0, 0.7.0) — producers guarantee additive minor bumps in this
23
- * range; breaking schema changes move to 0.7.0+ to trip this gate.
24
- * Ported from Kocoro internal/memory/bundle.go versionInRange.
25
- */
26
- export function versionInRange(v: string): boolean {
27
- const parts = v.split(".");
28
- if (parts.length !== 3) return false;
29
- const [maj, min, pat] = parts.map(Number);
30
- if (maj !== 0 || isNaN(min!) || isNaN(pat!)) return false;
31
- if (min! < 4 || min! >= 7) return false;
32
- return pat! >= 0;
33
- }
34
-
35
- /**
36
- * Keep the newest `keep` bundle dirs plus the current symlink target.
37
- * Best-effort — failures are silently ignored.
38
- * Ported from Kocoro internal/memory/bundle.go Puller.retain.
39
- */
40
- export async function retainBundles(bundleRoot: string, keep: number): Promise<void> {
41
- const bundlesDir = path.join(bundleRoot, "bundles");
42
- let names: string[];
43
- try {
44
- names = await fs.readdir(bundlesDir);
45
- } catch {
46
- return;
47
- }
48
- const dirs: string[] = [];
49
- for (const name of names) {
50
- try {
51
- const st = await fs.stat(path.join(bundlesDir, name));
52
- if (st.isDirectory()) dirs.push(name);
53
- } catch { /* skip unreadable */ }
54
- }
55
- dirs.sort().reverse();
56
- if (dirs.length <= keep) return;
57
-
58
- let currentTarget = "";
59
- try {
60
- const target = await fs.readlink(path.join(bundleRoot, "current"));
61
- currentTarget = path.basename(target);
62
- } catch { /* no current pointer */ }
63
-
64
- const keepSet = new Set<string>();
65
- for (let i = 0; i < Math.min(keep, dirs.length); i++) {
66
- keepSet.add(dirs[i]!);
67
- }
68
- if (currentTarget) keepSet.add(currentTarget);
69
-
70
- for (const d of dirs) {
71
- if (!keepSet.has(d)) {
72
- await fs.rm(path.join(bundlesDir, d), { recursive: true, force: true }).catch(() => {});
73
- }
74
- }
75
- }
76
-
77
- /**
78
- * Path sandboxing rules from Kocoro bundle.go validateManifestPath (§4.2).
79
- */
80
- export function validateManifestPath(rel: string, stagingDir: string): string | null {
81
- if (!rel) return "empty path";
82
- if (rel.includes("\0")) return "null byte in path";
83
- if (path.isAbsolute(rel)) return "absolute path";
84
- const cleaned = path.normalize(rel);
85
- if (
86
- cleaned === ".." ||
87
- cleaned.startsWith(`..${path.sep}`) ||
88
- cleaned.includes(`${path.sep}..`)
89
- ) {
90
- return "contains parent traversal";
91
- }
92
- const abs = path.join(stagingDir, cleaned);
93
- const cleanedAbs = path.normalize(abs);
94
- const prefix = path.normalize(stagingDir) + path.sep;
95
- if (!cleanedAbs.startsWith(prefix)) {
96
- return "escapes staging dir";
97
- }
98
- return null;
99
- }
100
-
101
- async function sha256File(filePath: string): Promise<string> {
102
- const data = await fs.readFile(filePath);
103
- return createHash("sha256").update(data).digest("hex");
104
- }
105
-
106
- /**
107
- * Points <bundleRoot>/current at finalDir. On Windows uses a directory junction
108
- * (unprivileged, no Developer Mode needed — os.Symlink would fail with
109
- * ERROR_PRIVILEGE_NOT_HELD on stock hosts). On POSIX uses atomic tmp-symlink +
110
- * rename. Ported from Kocoro bundle_link_{unix,windows}.go.
111
- */
112
- async function swapCurrent(bundleRoot: string, finalDir: string): Promise<void> {
113
- const currentLink = path.join(bundleRoot, "current");
114
-
115
- if (process.platform === "win32") {
116
- try { await fs.rm(currentLink, { recursive: true, force: true }); } catch { /* absent */ }
117
- await fs.symlink(finalDir, currentLink, "junction");
118
- return;
119
- }
120
-
121
- const tmpLink = path.join(bundleRoot, "current.tmp");
122
- try { await fs.unlink(tmpLink); } catch { /* absent */ }
123
- await fs.symlink(finalDir, tmpLink);
124
- await fs.rename(tmpLink, currentLink);
125
- }
126
-
127
- /**
128
- * Install a local bundle directory into bundleRoot (staging → bundles/<ts> → current).
129
- * Verifies per-file sha256 when manifest lists hashes.
130
- */
131
- export async function installBundle(
132
- opts: InstallBundleOptions,
133
- ): Promise<InstallBundleResult> {
134
- const sourceDir = path.resolve(opts.sourceDir);
135
- const bundleRoot = path.resolve(opts.bundleRoot);
136
-
137
- const manifestPath = path.join(sourceDir, "manifest.json");
138
- const raw = await fs.readFile(manifestPath, "utf8");
139
- const manifest = JSON.parse(raw) as BundleManifest;
140
-
141
- if (!manifest.bundle_ts?.trim()) {
142
- throw new Error("manifest missing bundle_ts");
143
- }
144
- if (!versionInRange(manifest.bundle_version ?? "")) {
145
- throw new Error(
146
- `bundle_version "${manifest.bundle_version}" outside supported range [0.4.0, 0.7.0)`,
147
- );
148
- }
149
-
150
- await fs.mkdir(bundleRoot, { recursive: true, mode: 0o700 });
151
-
152
- const staging = path.join(bundleRoot, "staging", manifest.bundle_ts);
153
- await fs.rm(staging, { recursive: true, force: true });
154
- await fs.mkdir(staging, { recursive: true, mode: 0o700 });
155
-
156
- let filesCopied = 0;
157
- for (const f of manifest.files ?? []) {
158
- const err = validateManifestPath(f.path, staging);
159
- if (err) {
160
- await fs.rm(staging, { recursive: true, force: true });
161
- throw new Error(`unsafe manifest path ${f.path}: ${err}`);
162
- }
163
- const src = path.join(sourceDir, path.normalize(f.path));
164
- const dest = path.join(staging, path.normalize(f.path));
165
- await fs.mkdir(path.dirname(dest), { recursive: true, mode: 0o700 });
166
- await fs.copyFile(src, dest, fs.constants.COPYFILE_EXCL).catch(async () => {
167
- await fs.copyFile(src, dest);
168
- });
169
-
170
- if (f.sha256) {
171
- const got = await sha256File(dest);
172
- if (got !== f.sha256) {
173
- await fs.rm(staging, { recursive: true, force: true });
174
- throw new Error(`sha256 mismatch on ${f.path}: got ${got} want ${f.sha256}`);
175
- }
176
- }
177
- filesCopied++;
178
- }
179
-
180
- // Copy manifest itself if not listed in files[]
181
- const manifestDest = path.join(staging, "manifest.json");
182
- try {
183
- await fs.access(manifestDest);
184
- } catch {
185
- await fs.copyFile(manifestPath, manifestDest);
186
- }
187
-
188
- const bundlesDir = path.join(bundleRoot, "bundles");
189
- await fs.mkdir(bundlesDir, { recursive: true, mode: 0o700 });
190
- const finalDir = path.join(bundlesDir, manifest.bundle_ts);
191
- await fs.rm(finalDir, { recursive: true, force: true });
192
- await fs.rename(staging, finalDir);
193
- await swapCurrent(bundleRoot, finalDir);
194
-
195
- const keep = opts.retain ?? 3;
196
- if (keep > 0) {
197
- await retainBundles(bundleRoot, keep);
198
- }
199
-
200
- return {
201
- bundle_ts: manifest.bundle_ts,
202
- bundle_version: manifest.bundle_version,
203
- installed_dir: finalDir,
204
- files_copied: filesCopied,
205
- };
206
- }
@@ -1,72 +0,0 @@
1
- import { LRUCache } from "lru-cache";
2
- import type { QueryIntent } from "../types.js";
3
- import type { RankedResult } from "../fallback/llmRerank.js";
4
- import type { SessionSearchHit } from "../fallback/sessionSearch.js";
5
-
6
- const INTENT_TTL_MS = 15 * 60_000;
7
- const RERANK_TTL_MS = 15 * 60_000;
8
- const NEGATIVE_TTL_MS = 60_000;
9
-
10
- /**
11
- * In-process LRU + TTL caches for pi-memory.
12
- *
13
- * - intentCache : helper-LLM compile_memory_intents results, keyed by
14
- * normalised query text. TTL 15 min, LRU 128 entries.
15
- * - rerankCache : LLM rerank results, keyed by query + hit fingerprint.
16
- * TTL 15 min, LRU 256 entries.
17
- * - negativeCache: queries that recently returned no usable context.
18
- * TTL 60 s, max 512 entries.
19
- *
20
- * All three caches must be invalidated together (`invalidateMemoryCaches()`)
21
- * after bundle reload so stale negative entries never block fresh graph data.
22
- */
23
- export const intentCache = new LRUCache<string, QueryIntent[]>({
24
- max: 128,
25
- ttl: INTENT_TTL_MS,
26
- });
27
-
28
- export const rerankCache = new LRUCache<string, RankedResult[]>({
29
- max: 256,
30
- ttl: RERANK_TTL_MS,
31
- });
32
-
33
- export const negativeCache = new LRUCache<string, true>({
34
- max: 512,
35
- ttl: NEGATIVE_TTL_MS,
36
- });
37
-
38
- function normalizeQuery(query: string): string {
39
- return query.trim();
40
- }
41
-
42
- export function cacheKeyForIntents(query: string): string {
43
- return normalizeQuery(query);
44
- }
45
-
46
- /**
47
- * Rerank cache key combines the query with a fingerprint of the hit set so
48
- * different FTS results for the same query get their own entry.
49
- */
50
- export function cacheKeyForRerank(query: string, hits: SessionSearchHit[]): string {
51
- const hitIds = hits.map((h) => `${h.session_id}:${h.msg_index}`).join("|");
52
- return `${normalizeQuery(query)}|${hitIds}`;
53
- }
54
-
55
- export function isNegativeCached(query: string): boolean {
56
- return negativeCache.has(cacheKeyForIntents(query));
57
- }
58
-
59
- export function setNegativeCache(query: string): void {
60
- negativeCache.set(cacheKeyForIntents(query), true);
61
- }
62
-
63
- export function deleteNegativeCache(query: string): void {
64
- negativeCache.delete(cacheKeyForIntents(query));
65
- }
66
-
67
- /** Clear all three caches. Call after bundle reload or session shutdown. */
68
- export function invalidateMemoryCaches(): void {
69
- intentCache.clear();
70
- rerankCache.clear();
71
- negativeCache.clear();
72
- }
package/src/config.ts DELETED
@@ -1,180 +0,0 @@
1
- import path from "node:path";
2
-
3
- import {
4
- defaultBundleRoot,
5
- defaultPiHome,
6
- defaultSessionsDir,
7
- defaultSocketPath,
8
- expandPath,
9
- } from "./paths.js";
10
-
11
- export type MemoryProvider = "disabled" | "local" | "cloud";
12
-
13
- export type ExtractorType = "regex" | "llm";
14
-
15
- export interface TrainerConfig {
16
- /** Which extractor to use (default "regex"). */
17
- extractor: ExtractorType;
18
- /** How many turns per LLM call when extractor is "llm" (default 10). */
19
- llm_batch_size: number;
20
- /** Auto-train interval: "1h"|"6h"|"12h"|"24h"|null (default null — disabled). */
21
- auto_interval: string | null;
22
- }
23
-
24
- export interface ConsolidationScheduleConfig {
25
- /** Local hour for the background consolidation job (default 3). */
26
- hour: number;
27
- /** Local minute for the background consolidation job (default 0). */
28
- minute: number;
29
- /** Structured JSONL log path (default ~/.pi/memory/consolidation.log). */
30
- log_path: string;
31
- }
32
-
33
- export interface ConsolidationConfig {
34
- /** Whether session_shutdown enqueues sessions for offline consolidation. */
35
- enabled: boolean;
36
- /** Minimum non-empty user turns before enqueue (default 3). */
37
- min_user_turns: number;
38
- /** MEMORY.md session cap by line count (default 200). */
39
- memory_index_max_lines: number;
40
- /** MEMORY.md session cap by UTF-8 bytes (default 25KB). */
41
- memory_index_max_bytes: number;
42
- /** Maximum stage1 rows selected per Phase2 run (default 20). */
43
- phase2_top_n: number;
44
- /** M4 prune threshold by last usage (default 90 days). */
45
- max_unused_days: number;
46
- /** Daily OS scheduler defaults. */
47
- schedule: ConsolidationScheduleConfig;
48
- }
49
-
50
- export interface MemoryConfig {
51
- provider: MemoryProvider;
52
- tlmPath: string;
53
- socketPath: string;
54
- bundleRoot: string;
55
- sidecarReadyTimeoutMs: number;
56
- queryTimeoutMs: number;
57
- clientRequestTimeoutMs: number;
58
- sessionsDir: string;
59
- memoryMdPaths: string[];
60
- trainer: TrainerConfig;
61
- consolidation: ConsolidationConfig;
62
- }
63
-
64
- export const defaultTrainerConfig: TrainerConfig = {
65
- extractor: "regex",
66
- llm_batch_size: 10,
67
- auto_interval: null,
68
- };
69
-
70
- export function defaultConsolidationConfig(
71
- overrides: Partial<ConsolidationConfig> & {
72
- schedule?: Partial<ConsolidationScheduleConfig>;
73
- } = {},
74
- ): ConsolidationConfig {
75
- const defaultSchedule: ConsolidationScheduleConfig = {
76
- hour: 3,
77
- minute: 0,
78
- log_path: path.join(defaultBundleRoot(), "consolidation.log"),
79
- };
80
- const { schedule, ...rest } = overrides;
81
- return {
82
- enabled: true,
83
- min_user_turns: 3,
84
- memory_index_max_lines: 200,
85
- memory_index_max_bytes: 25_600,
86
- phase2_top_n: 20,
87
- max_unused_days: 90,
88
- schedule: { ...defaultSchedule, ...schedule },
89
- ...rest,
90
- };
91
- }
92
-
93
- export function defaultMemoryConfig(
94
- overrides: Partial<MemoryConfig> = {},
95
- ): MemoryConfig {
96
- const {
97
- trainer: trainerOverrides,
98
- consolidation: consolidationOverrides,
99
- ...rest
100
- } = overrides;
101
- return {
102
- provider: "local",
103
- tlmPath: "tlm",
104
- socketPath: defaultSocketPath(),
105
- bundleRoot: defaultBundleRoot(),
106
- sidecarReadyTimeoutMs: 15_000,
107
- queryTimeoutMs: 2_000,
108
- clientRequestTimeoutMs: 5_000,
109
- sessionsDir: defaultSessionsDir(),
110
- memoryMdPaths: [path.join(defaultPiHome(), "MEMORY.md")],
111
- trainer: { ...defaultTrainerConfig, ...trainerOverrides },
112
- consolidation: defaultConsolidationConfig(consolidationOverrides),
113
- ...rest,
114
- };
115
- }
116
-
117
- /** Normalize user-supplied paths after JSON/env load. */
118
- export function normalizeMemoryConfig(
119
- raw: Partial<MemoryConfig> & Record<string, unknown>,
120
- ): MemoryConfig {
121
- const base = defaultMemoryConfig();
122
- const rawTrainer = (raw.trainer ?? {}) as Partial<TrainerConfig>;
123
- const rawConsolidation = (raw.consolidation ?? {}) as
124
- Partial<ConsolidationConfig> & {
125
- schedule?: Partial<ConsolidationScheduleConfig>;
126
- };
127
- const rawSchedule = (rawConsolidation.schedule ?? {}) as
128
- Partial<ConsolidationScheduleConfig>;
129
- return {
130
- provider: (raw.provider as MemoryProvider) ?? base.provider,
131
- tlmPath: expandPath(String(raw.tlmPath ?? base.tlmPath)),
132
- socketPath: expandPath(String(raw.socketPath ?? base.socketPath)),
133
- bundleRoot: expandPath(String(raw.bundleRoot ?? base.bundleRoot)),
134
- sidecarReadyTimeoutMs: Number(
135
- raw.sidecarReadyTimeoutMs ?? base.sidecarReadyTimeoutMs,
136
- ),
137
- queryTimeoutMs: Number(raw.queryTimeoutMs ?? base.queryTimeoutMs),
138
- clientRequestTimeoutMs: Number(
139
- raw.clientRequestTimeoutMs ?? base.clientRequestTimeoutMs,
140
- ),
141
- sessionsDir: expandPath(String(raw.sessionsDir ?? base.sessionsDir)),
142
- memoryMdPaths: Array.isArray(raw.memoryMdPaths)
143
- ? raw.memoryMdPaths.map((p) => expandPath(String(p)))
144
- : base.memoryMdPaths,
145
- trainer: {
146
- extractor: (rawTrainer.extractor as ExtractorType) ?? base.trainer.extractor,
147
- llm_batch_size: Number(rawTrainer.llm_batch_size ?? base.trainer.llm_batch_size),
148
- auto_interval: rawTrainer.auto_interval !== undefined
149
- ? rawTrainer.auto_interval
150
- : base.trainer.auto_interval,
151
- },
152
- consolidation: {
153
- enabled: rawConsolidation.enabled ?? base.consolidation.enabled,
154
- min_user_turns: Number(
155
- rawConsolidation.min_user_turns ?? base.consolidation.min_user_turns,
156
- ),
157
- memory_index_max_lines: Number(
158
- rawConsolidation.memory_index_max_lines ??
159
- base.consolidation.memory_index_max_lines,
160
- ),
161
- memory_index_max_bytes: Number(
162
- rawConsolidation.memory_index_max_bytes ??
163
- base.consolidation.memory_index_max_bytes,
164
- ),
165
- phase2_top_n: Number(
166
- rawConsolidation.phase2_top_n ?? base.consolidation.phase2_top_n,
167
- ),
168
- max_unused_days: Number(
169
- rawConsolidation.max_unused_days ?? base.consolidation.max_unused_days,
170
- ),
171
- schedule: {
172
- hour: Number(rawSchedule.hour ?? base.consolidation.schedule.hour),
173
- minute: Number(rawSchedule.minute ?? base.consolidation.schedule.minute),
174
- log_path: expandPath(
175
- String(rawSchedule.log_path ?? base.consolidation.schedule.log_path),
176
- ),
177
- },
178
- },
179
- };
180
- }
@@ -1,205 +0,0 @@
1
- import fs from "node:fs";
2
-
3
- import type {
4
- ConsolidationStatus,
5
- JobReport,
6
- PendingSession,
7
- ConsolidationStatusReport,
8
- } from "./types.js";
9
- import { openConsolidationStore, type SqliteDatabase } from "./stage1/store.js";
10
-
11
- export interface EnqueueSessionInput {
12
- session_id: string;
13
- session_file: string;
14
- cwd: string;
15
- git_root: string | null;
16
- project_hash: string | null;
17
- parent_session_id: string | null;
18
- parent_session_file: string | null;
19
- user_turn_count: number;
20
- ended_at: string;
21
- }
22
-
23
- export interface EnqueueOptions {
24
- enabled?: boolean;
25
- minUserTurns?: number;
26
- /** Injected sqlite handle for tests. */
27
- db?: SqliteDatabase;
28
- /** Force replacing existing done/skipped sessions. */
29
- force?: boolean;
30
- /** Override status for the newly enqueued job (default: pending). */
31
- status?: ConsolidationStatus;
32
- /** Optional now source for created_at / updated_at. */
33
- now?: Date | string;
34
- /** Test seam: production defaults to checking session file existence. */
35
- checkFileExists?: boolean;
36
- }
37
-
38
- function toIso(value: Date | string | undefined): string {
39
- const dt = value ? new Date(value) : new Date();
40
- return dt.toISOString();
41
- }
42
-
43
- function isMissingFile(file: string): boolean {
44
- return typeof file !== "string" || !file.trim();
45
- }
46
-
47
- function isAllowedStatus(status: string): status is ConsolidationStatus {
48
- return status === "pending" || status === "processing" || status === "done" || status === "skipped" ||
49
- status === "failed";
50
- }
51
-
52
- export function enqueueSession(
53
- dbPath: string,
54
- meta: EnqueueSessionInput,
55
- opts: EnqueueOptions = {},
56
- ): JobReport {
57
- const enabled = opts.enabled !== false;
58
- const minUserTurns = opts.minUserTurns ?? 3;
59
- const now = toIso(opts.now);
60
-
61
- if (!enabled) {
62
- return {
63
- session_id: meta.session_id,
64
- enqueued: false,
65
- action: "skipped",
66
- status: "skipped",
67
- reason: "consolidation_disabled",
68
- now,
69
- };
70
- }
71
-
72
- if (isMissingFile(meta.session_file)) {
73
- return {
74
- session_id: meta.session_id,
75
- enqueued: false,
76
- action: "skipped",
77
- status: "skipped",
78
- reason: "missing_session_file",
79
- now,
80
- };
81
- }
82
-
83
- if (opts.checkFileExists !== false && !fs.existsSync(meta.session_file)) {
84
- return {
85
- session_id: meta.session_id,
86
- enqueued: false,
87
- action: "skipped",
88
- status: "skipped",
89
- reason: "session_file_not_found",
90
- now,
91
- };
92
- }
93
-
94
- if (meta.user_turn_count < minUserTurns) {
95
- return {
96
- session_id: meta.session_id,
97
- enqueued: false,
98
- action: "skipped",
99
- status: "skipped",
100
- reason: "insufficient_user_turns",
101
- now,
102
- };
103
- }
104
-
105
- const store = openConsolidationStore(dbPath, opts.db);
106
- if (!store) {
107
- return {
108
- session_id: meta.session_id,
109
- enqueued: false,
110
- action: "skipped",
111
- status: "skipped",
112
- reason: "missing_sqlite",
113
- now,
114
- };
115
- }
116
-
117
- const incomingStatus: ConsolidationStatus = isAllowedStatus(opts.status ?? "") ? opts.status! : "pending";
118
- const existing = store.getPendingSession(meta.session_id);
119
- const isFinal = existing?.status === "done" || existing?.status === "skipped";
120
-
121
- if (existing && isFinal && !opts.force) {
122
- store.close();
123
- return {
124
- session_id: meta.session_id,
125
- enqueued: false,
126
- action: "skipped",
127
- status: existing.status,
128
- reason: "already_finalized",
129
- now,
130
- };
131
- }
132
-
133
- const existingCreatedAt = existing?.created_at ?? now;
134
- const payload: Omit<PendingSession, "created_at" | "updated_at"> & {
135
- created_at: string;
136
- updated_at: string;
137
- } = {
138
- session_id: meta.session_id,
139
- session_file: meta.session_file,
140
- cwd: meta.cwd,
141
- git_root: meta.git_root,
142
- project_hash: meta.project_hash,
143
- parent_session_id: meta.parent_session_id,
144
- parent_session_file: meta.parent_session_file,
145
- user_turn_count: meta.user_turn_count,
146
- ended_at: meta.ended_at,
147
- status: incomingStatus,
148
- error_message: null,
149
- created_at: existingCreatedAt,
150
- updated_at: now,
151
- };
152
-
153
- try {
154
- store.upsertPendingSession(payload);
155
- const action = existing ? "updated" : "created";
156
- return {
157
- session_id: meta.session_id,
158
- enqueued: true,
159
- action,
160
- status: incomingStatus,
161
- now,
162
- };
163
- } finally {
164
- store.close();
165
- }
166
- }
167
-
168
- export interface ConsolidationStatusQueryOptions {
169
- db?: SqliteDatabase;
170
- }
171
-
172
- export function getConsolidationStatus(
173
- dbPath: string,
174
- opts: ConsolidationStatusQueryOptions = {},
175
- ): ConsolidationStatusReport {
176
- const store = openConsolidationStore(dbPath, opts.db);
177
- if (!store) {
178
- return {
179
- pending: 0,
180
- processing: 0,
181
- done: 0,
182
- skipped: 0,
183
- failed: 0,
184
- stage1Count: 0,
185
- lastGeneratedAt: null,
186
- lastUpdatedAt: null,
187
- };
188
- }
189
-
190
- try {
191
- const byStatus = store.getConsolidationStatusCounts();
192
- return {
193
- pending: byStatus.pending,
194
- processing: byStatus.processing,
195
- done: byStatus.done,
196
- skipped: byStatus.skipped,
197
- failed: byStatus.failed,
198
- stage1Count: store.getStage1Count(),
199
- lastGeneratedAt: store.getLastGeneratedAt(),
200
- lastUpdatedAt: store.getLastUpdatedAt(),
201
- };
202
- } finally {
203
- store.close();
204
- }
205
- }