@geminilight/mindos 1.1.25 → 1.1.28

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 (359) hide show
  1. package/dist/agent/bridges/index.d.ts +3 -0
  2. package/dist/agent/bridges/index.d.ts.map +1 -0
  3. package/dist/agent/bridges/index.js +3 -0
  4. package/dist/agent/bridges/index.js.map +1 -0
  5. package/dist/agent/bridges/runtime-permission-bridge.d.ts +34 -0
  6. package/dist/agent/bridges/runtime-permission-bridge.d.ts.map +1 -0
  7. package/dist/agent/bridges/runtime-permission-bridge.js +284 -0
  8. package/dist/agent/bridges/runtime-permission-bridge.js.map +1 -0
  9. package/dist/agent/bridges/user-question-bridge.d.ts +90 -0
  10. package/dist/agent/bridges/user-question-bridge.d.ts.map +1 -0
  11. package/dist/agent/bridges/user-question-bridge.js +260 -0
  12. package/dist/agent/bridges/user-question-bridge.js.map +1 -0
  13. package/dist/agent/index.d.ts +6 -7
  14. package/dist/agent/index.d.ts.map +1 -1
  15. package/dist/agent/index.js +6 -7
  16. package/dist/agent/index.js.map +1 -1
  17. package/dist/agent/ledger/index.d.ts +5 -0
  18. package/dist/agent/ledger/index.d.ts.map +1 -0
  19. package/dist/agent/ledger/index.js +5 -0
  20. package/dist/agent/ledger/index.js.map +1 -0
  21. package/dist/agent/ledger/run-cancellation.d.ts +13 -0
  22. package/dist/agent/ledger/run-cancellation.d.ts.map +1 -0
  23. package/dist/agent/ledger/run-cancellation.js +97 -0
  24. package/dist/agent/ledger/run-cancellation.js.map +1 -0
  25. package/dist/agent/ledger/run-ledger-types.d.ts +197 -0
  26. package/dist/agent/ledger/run-ledger-types.d.ts.map +1 -0
  27. package/dist/agent/ledger/run-ledger-types.js +9 -0
  28. package/dist/agent/ledger/run-ledger-types.js.map +1 -0
  29. package/dist/agent/ledger/run-ledger.d.ts +44 -0
  30. package/dist/agent/ledger/run-ledger.d.ts.map +1 -0
  31. package/dist/agent/ledger/run-ledger.js +814 -0
  32. package/dist/agent/ledger/run-ledger.js.map +1 -0
  33. package/dist/agent/ledger/run-timeline-events.d.ts +3 -0
  34. package/dist/agent/ledger/run-timeline-events.d.ts.map +1 -0
  35. package/dist/agent/ledger/run-timeline-events.js +239 -0
  36. package/dist/agent/ledger/run-timeline-events.js.map +1 -0
  37. package/dist/agent/mindos-pi/extension/extension-tools.d.ts +16 -0
  38. package/dist/agent/mindos-pi/extension/extension-tools.d.ts.map +1 -0
  39. package/dist/agent/mindos-pi/extension/extension-tools.js +115 -0
  40. package/dist/agent/mindos-pi/extension/extension-tools.js.map +1 -0
  41. package/dist/agent/mindos-pi/extension/index.d.ts +3 -0
  42. package/dist/agent/mindos-pi/extension/index.d.ts.map +1 -0
  43. package/dist/agent/mindos-pi/extension/index.js +3 -0
  44. package/dist/agent/mindos-pi/extension/index.js.map +1 -0
  45. package/dist/agent/mindos-pi/extension/kb-extension.d.ts +38 -0
  46. package/dist/agent/mindos-pi/extension/kb-extension.d.ts.map +1 -0
  47. package/dist/agent/mindos-pi/extension/kb-extension.js +140 -0
  48. package/dist/agent/mindos-pi/extension/kb-extension.js.map +1 -0
  49. package/dist/agent/mindos-pi/index.d.ts +5 -0
  50. package/dist/agent/mindos-pi/index.d.ts.map +1 -0
  51. package/dist/agent/mindos-pi/index.js +5 -0
  52. package/dist/agent/mindos-pi/index.js.map +1 -0
  53. package/dist/agent/mindos-pi/prompt.d.ts +3 -0
  54. package/dist/agent/mindos-pi/prompt.d.ts.map +1 -0
  55. package/dist/agent/mindos-pi/prompt.js +22 -0
  56. package/dist/agent/mindos-pi/prompt.js.map +1 -0
  57. package/dist/agent/mindos-pi/resource-types.d.ts +27 -0
  58. package/dist/agent/mindos-pi/resource-types.d.ts.map +1 -0
  59. package/dist/agent/mindos-pi/resource-types.js +2 -0
  60. package/dist/agent/mindos-pi/resource-types.js.map +1 -0
  61. package/dist/agent/mindos-pi/runtime.d.ts +10 -0
  62. package/dist/agent/mindos-pi/runtime.d.ts.map +1 -0
  63. package/dist/agent/mindos-pi/runtime.js +31 -0
  64. package/dist/agent/mindos-pi/runtime.js.map +1 -0
  65. package/dist/agent/pi/extension-tools.d.ts +2 -0
  66. package/dist/agent/pi/extension-tools.d.ts.map +1 -0
  67. package/dist/agent/pi/extension-tools.js +2 -0
  68. package/dist/agent/pi/extension-tools.js.map +1 -0
  69. package/dist/agent/pi/index.d.ts +2 -0
  70. package/dist/agent/pi/index.d.ts.map +1 -0
  71. package/dist/agent/pi/index.js +2 -0
  72. package/dist/agent/pi/index.js.map +1 -0
  73. package/dist/agent/pi/resource-types.d.ts +2 -0
  74. package/dist/agent/pi/resource-types.d.ts.map +1 -0
  75. package/dist/agent/pi/resource-types.js +2 -0
  76. package/dist/agent/pi/resource-types.js.map +1 -0
  77. package/dist/agent/pi/runtime.d.ts +2 -0
  78. package/dist/agent/pi/runtime.d.ts.map +1 -0
  79. package/dist/agent/pi/runtime.js +2 -0
  80. package/dist/agent/pi/runtime.js.map +1 -0
  81. package/dist/agent/prompt/base-prompt.d.ts.map +1 -1
  82. package/dist/agent/prompt/base-prompt.js +24 -6
  83. package/dist/agent/prompt/base-prompt.js.map +1 -1
  84. package/dist/agent/prompt/context-prompt.d.ts +24 -0
  85. package/dist/agent/prompt/context-prompt.d.ts.map +1 -1
  86. package/dist/agent/prompt/context-prompt.js +15 -38
  87. package/dist/agent/prompt/context-prompt.js.map +1 -1
  88. package/dist/agent/prompt/index.d.ts +1 -1
  89. package/dist/agent/prompt/index.d.ts.map +1 -1
  90. package/dist/agent/prompt/index.js +1 -1
  91. package/dist/agent/prompt/index.js.map +1 -1
  92. package/dist/agent/result-reducer.d.ts +1 -1
  93. package/dist/agent/result-reducer.d.ts.map +1 -1
  94. package/dist/agent/run-cancellation.d.ts +1 -12
  95. package/dist/agent/run-cancellation.d.ts.map +1 -1
  96. package/dist/agent/run-cancellation.js +1 -96
  97. package/dist/agent/run-cancellation.js.map +1 -1
  98. package/dist/agent/run-ledger-types.d.ts +1 -196
  99. package/dist/agent/run-ledger-types.d.ts.map +1 -1
  100. package/dist/agent/run-ledger-types.js +1 -8
  101. package/dist/agent/run-ledger-types.js.map +1 -1
  102. package/dist/agent/run-ledger.d.ts +1 -43
  103. package/dist/agent/run-ledger.d.ts.map +1 -1
  104. package/dist/agent/run-ledger.js +1 -813
  105. package/dist/agent/run-ledger.js.map +1 -1
  106. package/dist/agent/run-timeline-events.d.ts +1 -2
  107. package/dist/agent/run-timeline-events.d.ts.map +1 -1
  108. package/dist/agent/run-timeline-events.js +1 -238
  109. package/dist/agent/run-timeline-events.js.map +1 -1
  110. package/dist/agent/runtime/adapters/index.d.ts +2 -0
  111. package/dist/agent/runtime/adapters/index.d.ts.map +1 -0
  112. package/dist/agent/runtime/adapters/index.js +2 -0
  113. package/dist/agent/runtime/adapters/index.js.map +1 -0
  114. package/dist/agent/runtime/adapters/mindos.d.ts +21 -0
  115. package/dist/agent/runtime/adapters/mindos.d.ts.map +1 -0
  116. package/dist/agent/runtime/adapters/mindos.js +14 -0
  117. package/dist/agent/runtime/adapters/mindos.js.map +1 -0
  118. package/dist/agent/runtime/attachments.d.ts +37 -0
  119. package/dist/agent/runtime/attachments.d.ts.map +1 -0
  120. package/dist/agent/runtime/attachments.js +187 -0
  121. package/dist/agent/runtime/attachments.js.map +1 -0
  122. package/dist/agent/runtime/capabilities.d.ts +10 -0
  123. package/dist/agent/runtime/capabilities.d.ts.map +1 -0
  124. package/dist/agent/runtime/capabilities.js +100 -0
  125. package/dist/agent/runtime/capabilities.js.map +1 -0
  126. package/dist/agent/runtime/child-process.d.ts +21 -0
  127. package/dist/agent/runtime/child-process.d.ts.map +1 -0
  128. package/dist/agent/runtime/child-process.js +29 -0
  129. package/dist/agent/runtime/child-process.js.map +1 -0
  130. package/dist/agent/runtime/claude-code-cli.d.ts +40 -0
  131. package/dist/agent/runtime/claude-code-cli.d.ts.map +1 -0
  132. package/dist/agent/runtime/claude-code-cli.js +288 -0
  133. package/dist/agent/runtime/claude-code-cli.js.map +1 -0
  134. package/dist/agent/runtime/claude-code-sdk.d.ts +62 -0
  135. package/dist/agent/runtime/claude-code-sdk.d.ts.map +1 -0
  136. package/dist/agent/runtime/claude-code-sdk.js +613 -0
  137. package/dist/agent/runtime/claude-code-sdk.js.map +1 -0
  138. package/dist/agent/runtime/codex-app-server.d.ts +172 -0
  139. package/dist/agent/runtime/codex-app-server.d.ts.map +1 -0
  140. package/dist/agent/runtime/codex-app-server.js +700 -0
  141. package/dist/agent/runtime/codex-app-server.js.map +1 -0
  142. package/dist/agent/runtime/codex-env.d.ts +42 -0
  143. package/dist/agent/runtime/codex-env.d.ts.map +1 -0
  144. package/dist/agent/runtime/codex-env.js +290 -0
  145. package/dist/agent/runtime/codex-env.js.map +1 -0
  146. package/dist/agent/runtime/descriptors.d.ts +19 -0
  147. package/dist/agent/runtime/descriptors.d.ts.map +1 -0
  148. package/dist/agent/runtime/descriptors.js +143 -0
  149. package/dist/agent/runtime/descriptors.js.map +1 -0
  150. package/dist/agent/runtime/detection.d.ts +15 -0
  151. package/dist/agent/runtime/detection.d.ts.map +1 -0
  152. package/dist/agent/runtime/detection.js +124 -0
  153. package/dist/agent/runtime/detection.js.map +1 -0
  154. package/dist/agent/runtime/index.d.ts +15 -0
  155. package/dist/agent/runtime/index.d.ts.map +1 -0
  156. package/dist/agent/runtime/index.js +15 -0
  157. package/dist/agent/runtime/index.js.map +1 -0
  158. package/dist/agent/runtime/registry.d.ts +152 -0
  159. package/dist/agent/runtime/registry.d.ts.map +1 -0
  160. package/dist/agent/runtime/registry.js +84 -0
  161. package/dist/agent/runtime/registry.js.map +1 -0
  162. package/dist/agent/runtime/run.d.ts +129 -0
  163. package/dist/agent/runtime/run.d.ts.map +1 -0
  164. package/dist/agent/runtime/run.js +739 -0
  165. package/dist/agent/runtime/run.js.map +1 -0
  166. package/dist/agent/runtime/runtime-env.d.ts +28 -0
  167. package/dist/agent/runtime/runtime-env.d.ts.map +1 -0
  168. package/dist/agent/runtime/runtime-env.js +66 -0
  169. package/dist/agent/runtime/runtime-env.js.map +1 -0
  170. package/dist/agent/runtime/runtime-errors.d.ts +20 -0
  171. package/dist/agent/runtime/runtime-errors.d.ts.map +1 -0
  172. package/dist/agent/runtime/runtime-errors.js +95 -0
  173. package/dist/agent/runtime/runtime-errors.js.map +1 -0
  174. package/dist/agent/runtime-permission-bridge.d.ts +1 -33
  175. package/dist/agent/runtime-permission-bridge.d.ts.map +1 -1
  176. package/dist/agent/runtime-permission-bridge.js +1 -283
  177. package/dist/agent/runtime-permission-bridge.js.map +1 -1
  178. package/dist/agent/selected-skills.d.ts +8 -0
  179. package/dist/agent/selected-skills.d.ts.map +1 -0
  180. package/dist/agent/selected-skills.js +27 -0
  181. package/dist/agent/selected-skills.js.map +1 -0
  182. package/dist/agent/session/index.d.ts +618 -0
  183. package/dist/agent/session/index.d.ts.map +1 -0
  184. package/dist/agent/session/index.js +1330 -0
  185. package/dist/agent/session/index.js.map +1 -0
  186. package/dist/agent/session/redaction.d.ts +3 -0
  187. package/dist/agent/session/redaction.d.ts.map +1 -0
  188. package/dist/agent/session/redaction.js +47 -0
  189. package/dist/agent/session/redaction.js.map +1 -0
  190. package/dist/agent/stream/index.d.ts +3 -0
  191. package/dist/agent/stream/index.d.ts.map +1 -0
  192. package/dist/agent/stream/index.js +3 -0
  193. package/dist/agent/stream/index.js.map +1 -0
  194. package/dist/agent/stream/stream-consumer.d.ts +65 -0
  195. package/dist/agent/stream/stream-consumer.d.ts.map +1 -0
  196. package/dist/agent/stream/stream-consumer.js +664 -0
  197. package/dist/agent/stream/stream-consumer.js.map +1 -0
  198. package/dist/agent/stream/stream-message-types.d.ts +128 -0
  199. package/dist/agent/stream/stream-message-types.d.ts.map +1 -0
  200. package/dist/agent/stream/stream-message-types.js +14 -0
  201. package/dist/agent/stream/stream-message-types.js.map +1 -0
  202. package/dist/agent/stream-consumer.d.ts +1 -64
  203. package/dist/agent/stream-consumer.d.ts.map +1 -1
  204. package/dist/agent/stream-consumer.js +1 -663
  205. package/dist/agent/stream-consumer.js.map +1 -1
  206. package/dist/agent/stream-message-types.d.ts +1 -137
  207. package/dist/agent/stream-message-types.d.ts.map +1 -1
  208. package/dist/agent/stream-message-types.js +1 -13
  209. package/dist/agent/stream-message-types.js.map +1 -1
  210. package/dist/agent/subagent/index.d.ts +3 -0
  211. package/dist/agent/subagent/index.d.ts.map +1 -0
  212. package/dist/agent/subagent/index.js +3 -0
  213. package/dist/agent/subagent/index.js.map +1 -0
  214. package/dist/agent/subagent/subagent-ledger-extension.d.ts +36 -0
  215. package/dist/agent/subagent/subagent-ledger-extension.d.ts.map +1 -0
  216. package/dist/agent/subagent/subagent-ledger-extension.js +572 -0
  217. package/dist/agent/subagent/subagent-ledger-extension.js.map +1 -0
  218. package/dist/agent/subagent/subagent-orchestrator.d.ts +62 -0
  219. package/dist/agent/subagent/subagent-orchestrator.d.ts.map +1 -0
  220. package/dist/agent/subagent/subagent-orchestrator.js +350 -0
  221. package/dist/agent/subagent/subagent-orchestrator.js.map +1 -0
  222. package/dist/agent/subagent-ledger-extension.d.ts +1 -35
  223. package/dist/agent/subagent-ledger-extension.d.ts.map +1 -1
  224. package/dist/agent/subagent-ledger-extension.js +1 -571
  225. package/dist/agent/subagent-ledger-extension.js.map +1 -1
  226. package/dist/agent/subagent-orchestrator.d.ts +1 -61
  227. package/dist/agent/subagent-orchestrator.d.ts.map +1 -1
  228. package/dist/agent/subagent-orchestrator.js +1 -349
  229. package/dist/agent/subagent-orchestrator.js.map +1 -1
  230. package/dist/agent/tool/executable-tool.d.ts +12 -0
  231. package/dist/agent/tool/executable-tool.d.ts.map +1 -0
  232. package/dist/agent/tool/executable-tool.js +2 -0
  233. package/dist/agent/tool/executable-tool.js.map +1 -0
  234. package/dist/agent/tool/index.d.ts +1 -1
  235. package/dist/agent/tool/index.d.ts.map +1 -1
  236. package/dist/agent/tool/index.js +1 -1
  237. package/dist/agent/tool/index.js.map +1 -1
  238. package/dist/agent/tool/kb-extension.d.ts +1 -37
  239. package/dist/agent/tool/kb-extension.d.ts.map +1 -1
  240. package/dist/agent/tool/kb-extension.js +1 -139
  241. package/dist/agent/tool/kb-extension.js.map +1 -1
  242. package/dist/agent/tool/permission-policy.d.ts +1 -1
  243. package/dist/agent/tool/permission-policy.d.ts.map +1 -1
  244. package/dist/agent/tool/permission-policy.js +0 -1
  245. package/dist/agent/tool/permission-policy.js.map +1 -1
  246. package/dist/agent/user-question-bridge.d.ts +1 -89
  247. package/dist/agent/user-question-bridge.d.ts.map +1 -1
  248. package/dist/agent/user-question-bridge.js +1 -259
  249. package/dist/agent/user-question-bridge.js.map +1 -1
  250. package/dist/agent-runtime/adapters/index.d.ts +2 -0
  251. package/dist/agent-runtime/adapters/index.d.ts.map +1 -0
  252. package/dist/agent-runtime/adapters/index.js +2 -0
  253. package/dist/agent-runtime/adapters/index.js.map +1 -0
  254. package/dist/agent-runtime/adapters/mindos.d.ts +2 -0
  255. package/dist/agent-runtime/adapters/mindos.d.ts.map +1 -0
  256. package/dist/agent-runtime/adapters/mindos.js +2 -0
  257. package/dist/agent-runtime/adapters/mindos.js.map +1 -0
  258. package/dist/agent-runtime/capabilities.d.ts +1 -9
  259. package/dist/agent-runtime/capabilities.d.ts.map +1 -1
  260. package/dist/agent-runtime/capabilities.js +1 -99
  261. package/dist/agent-runtime/capabilities.js.map +1 -1
  262. package/dist/agent-runtime/child-process.d.ts +1 -20
  263. package/dist/agent-runtime/child-process.d.ts.map +1 -1
  264. package/dist/agent-runtime/child-process.js +1 -28
  265. package/dist/agent-runtime/child-process.js.map +1 -1
  266. package/dist/agent-runtime/claude-code-cli.d.ts +1 -35
  267. package/dist/agent-runtime/claude-code-cli.d.ts.map +1 -1
  268. package/dist/agent-runtime/claude-code-cli.js +1 -287
  269. package/dist/agent-runtime/claude-code-cli.js.map +1 -1
  270. package/dist/agent-runtime/claude-code-sdk.d.ts +1 -40
  271. package/dist/agent-runtime/claude-code-sdk.d.ts.map +1 -1
  272. package/dist/agent-runtime/claude-code-sdk.js +1 -571
  273. package/dist/agent-runtime/claude-code-sdk.js.map +1 -1
  274. package/dist/agent-runtime/codex-app-server.d.ts +1 -157
  275. package/dist/agent-runtime/codex-app-server.d.ts.map +1 -1
  276. package/dist/agent-runtime/codex-app-server.js +1 -665
  277. package/dist/agent-runtime/codex-app-server.js.map +1 -1
  278. package/dist/agent-runtime/codex-env.d.ts +1 -41
  279. package/dist/agent-runtime/codex-env.d.ts.map +1 -1
  280. package/dist/agent-runtime/codex-env.js +1 -289
  281. package/dist/agent-runtime/codex-env.js.map +1 -1
  282. package/dist/agent-runtime/descriptors.d.ts +1 -18
  283. package/dist/agent-runtime/descriptors.d.ts.map +1 -1
  284. package/dist/agent-runtime/descriptors.js +1 -142
  285. package/dist/agent-runtime/descriptors.js.map +1 -1
  286. package/dist/agent-runtime/detection.d.ts +1 -14
  287. package/dist/agent-runtime/detection.d.ts.map +1 -1
  288. package/dist/agent-runtime/detection.js +1 -123
  289. package/dist/agent-runtime/detection.js.map +1 -1
  290. package/dist/agent-runtime/index.d.ts +1 -8
  291. package/dist/agent-runtime/index.d.ts.map +1 -1
  292. package/dist/agent-runtime/index.js +1 -8
  293. package/dist/agent-runtime/index.js.map +1 -1
  294. package/dist/agent-runtime/registry.d.ts +1 -151
  295. package/dist/agent-runtime/registry.d.ts.map +1 -1
  296. package/dist/agent-runtime/registry.js +1 -83
  297. package/dist/agent-runtime/registry.js.map +1 -1
  298. package/dist/agent-runtime/run.d.ts +1 -124
  299. package/dist/agent-runtime/run.d.ts.map +1 -1
  300. package/dist/agent-runtime/run.js +1 -720
  301. package/dist/agent-runtime/run.js.map +1 -1
  302. package/dist/agent-runtime/runtime-env.d.ts +1 -27
  303. package/dist/agent-runtime/runtime-env.d.ts.map +1 -1
  304. package/dist/agent-runtime/runtime-env.js +1 -65
  305. package/dist/agent-runtime/runtime-env.js.map +1 -1
  306. package/dist/agent-runtime/runtime-errors.d.ts +1 -19
  307. package/dist/agent-runtime/runtime-errors.d.ts.map +1 -1
  308. package/dist/agent-runtime/runtime-errors.js +1 -94
  309. package/dist/agent-runtime/runtime-errors.js.map +1 -1
  310. package/dist/agent-runtime.d.ts +1 -1
  311. package/dist/agent-runtime.js +1 -1
  312. package/dist/client.d.ts +8 -4
  313. package/dist/client.d.ts.map +1 -1
  314. package/dist/client.js.map +1 -1
  315. package/dist/foundation/config/schema.d.ts +1 -1
  316. package/dist/server/handlers/agent-runtime-codex.d.ts +1 -1
  317. package/dist/server/handlers/agent-runtime-codex.js +2 -2
  318. package/dist/server/handlers/agent-runtimes.d.ts +3 -3
  319. package/dist/server/handlers/agent-runtimes.js +5 -5
  320. package/dist/server/handlers/ask.d.ts +8 -4
  321. package/dist/server/handlers/ask.d.ts.map +1 -1
  322. package/dist/server/handlers/ask.js +7 -1
  323. package/dist/server/handlers/ask.js.map +1 -1
  324. package/dist/server/handlers/inbox-source.d.ts +1 -1
  325. package/dist/server/handlers/inbox-source.d.ts.map +1 -1
  326. package/dist/server/handlers/inbox-source.js +22 -0
  327. package/dist/server/handlers/inbox-source.js.map +1 -1
  328. package/dist/server/handlers/settings.d.ts +1 -1
  329. package/dist/server/handlers/settings.js +1 -1
  330. package/dist/server/handlers/setup.d.ts +2 -1
  331. package/dist/server/handlers/setup.d.ts.map +1 -1
  332. package/dist/server/handlers/setup.js +1 -0
  333. package/dist/server/handlers/setup.js.map +1 -1
  334. package/dist/server/index.d.ts +1 -1
  335. package/dist/server/index.d.ts.map +1 -1
  336. package/dist/server/index.js +1 -1
  337. package/dist/server/index.js.map +1 -1
  338. package/dist/server/runtime.d.ts +1 -1
  339. package/dist/session/index.d.ts +1 -644
  340. package/dist/session/index.d.ts.map +1 -1
  341. package/dist/session/index.js +1 -1318
  342. package/dist/session/index.js.map +1 -1
  343. package/dist/session/pi-coding-agent-runtime.d.ts +1 -9
  344. package/dist/session/pi-coding-agent-runtime.d.ts.map +1 -1
  345. package/dist/session/pi-coding-agent-runtime.js +1 -30
  346. package/dist/session/pi-coding-agent-runtime.js.map +1 -1
  347. package/dist/session/redaction.d.ts +1 -2
  348. package/dist/session/redaction.d.ts.map +1 -1
  349. package/dist/session/redaction.js +1 -46
  350. package/dist/session/redaction.js.map +1 -1
  351. package/dist/session.d.ts +1 -1
  352. package/dist/session.d.ts.map +1 -1
  353. package/dist/session.js +1 -1
  354. package/dist/session.js.map +1 -1
  355. package/dist/setup/index.d.ts +24 -3
  356. package/dist/setup/index.d.ts.map +1 -1
  357. package/dist/setup/index.js +102 -2
  358. package/dist/setup/index.js.map +1 -1
  359. package/package.json +97 -9
@@ -1,814 +1,2 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { effectiveMindRoot } from '../foundation/mind-root/index.js';
4
- import { resolveExistingSafe } from '../foundation/security/index.js';
5
- import { getCurrentAgentRunContext } from './agent-run-context.js';
6
- import { AGENT_RUN_LEDGER_SHARD_KEY, AGENT_RUN_LEDGER_STORE_KEY, AGENT_RUN_LEDGER_SUBSCRIBERS_KEY, deleteProcessGlobal, getProcessGlobal, } from './global-state.js';
7
- import { redactSensitiveObject, redactSensitiveText } from './redaction.js';
8
- /**
9
- * Cross-runtime agent run ledger — an INDEX CARD store, not a transcript
10
- * store (spec-agent-core-consolidation B.1/C).
11
- *
12
- * Each runtime keeps its own full archive (Claude Code: ~/.claude, Codex:
13
- * ~/.codex, embedded pi: in-memory session injected per request). The ledger
14
- * persists only run records — id / kind / status / parent-child links /
15
- * timestamps / capped summaries / an `archive` pointer into the runtime's
16
- * own archive. Fine-grained timeline events still flow through the in-memory
17
- * store and realtime subscribers for live UI, but are NOT written to disk;
18
- * after a restart the UI can list runs and their terminal state (the ledger's
19
- * minimal crash-survival contract), not replay old timelines.
20
- *
21
- * Persistence model — one shard per process, no shared writers:
22
- * <mindRoot>/.mindos/agent-run-ledger.<pid>-<startTs>.jsonl
23
- * Reads scan the directory and merge every shard plus the two legacy files
24
- * (agent-run-ledger.json v1, agent-run-ledger.jsonl v2), which are read-only
25
- * and never written again. Compaction rewrites ONLY this process's shard —
26
- * single writer per file, so no cross-process locking exists or is needed.
27
- * Nothing in this module may rewrite a file another process wrote.
28
- */
29
- export * from './run-ledger-types.js';
30
- const MAX_RUNS = 500;
31
- const MAX_EVENTS = 1000;
32
- const MAX_SUMMARY_CHARS = 4000;
33
- const MAX_SHARD_LOG_BYTES = 1024 * 1024;
34
- const LEDGER_DIR_NAME = '.mindos';
35
- const LEDGER_LEGACY_JSON_NAME = 'agent-run-ledger.json';
36
- const LEDGER_LEGACY_JSONL_NAME = 'agent-run-ledger.jsonl';
37
- const SHARD_FILE_PATTERN = /^agent-run-ledger\.(\d+)-(\d+)\.jsonl$/;
38
- function shardIdentity() {
39
- return getProcessGlobal(AGENT_RUN_LEDGER_SHARD_KEY, () => ({
40
- pid: process.pid,
41
- // performance.timeOrigin is identical for every module copy in the
42
- // process, unlike a Date.now() captured at each copy's load time.
43
- startTs: Math.round(performance.timeOrigin),
44
- }));
45
- }
46
- function emptyStore(mindRoot) {
47
- return { records: [], events: [], ownRecordIds: new Set(), ...(mindRoot ? { mindRoot } : {}) };
48
- }
49
- function resolveLedgerRoot() {
50
- try {
51
- const root = effectiveMindRoot();
52
- return typeof root === 'string' && root.trim() ? root : undefined;
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- }
58
- function ledgerDirPath(mindRoot) {
59
- return resolveExistingSafe(mindRoot, LEDGER_DIR_NAME);
60
- }
61
- function ownShardPath(mindRoot) {
62
- const { pid, startTs } = shardIdentity();
63
- return resolveExistingSafe(mindRoot, path.posix.join(LEDGER_DIR_NAME, `agent-run-ledger.${pid}-${startTs}.jsonl`));
64
- }
65
- function legacyJsonPath(mindRoot) {
66
- return resolveExistingSafe(mindRoot, path.posix.join(LEDGER_DIR_NAME, LEDGER_LEGACY_JSON_NAME));
67
- }
68
- function legacyJsonlPath(mindRoot) {
69
- return resolveExistingSafe(mindRoot, path.posix.join(LEDGER_DIR_NAME, LEDGER_LEGACY_JSONL_NAME));
70
- }
71
- function normalizeRecord(value) {
72
- if (!value || typeof value !== 'object')
73
- return null;
74
- const record = value;
75
- if (typeof record.id !== 'string' || typeof record.runtimeId !== 'string' || typeof record.displayName !== 'string')
76
- return null;
77
- if (typeof record.startedAt !== 'number' || typeof record.inputSummary !== 'string')
78
- return null;
79
- if (!record.agentKind || !record.status || !record.permissionMode)
80
- return null;
81
- return record;
82
- }
83
- function normalizeEvent(value) {
84
- if (!value || typeof value !== 'object')
85
- return null;
86
- const event = value;
87
- if (typeof event.id !== 'string' || typeof event.runId !== 'string' || typeof event.type !== 'string')
88
- return null;
89
- if (typeof event.ts !== 'number' || !event.status || !event.record)
90
- return null;
91
- const type = event.type;
92
- const category = normalizeEventCategory(event.category, type);
93
- return {
94
- ...event,
95
- type,
96
- category,
97
- ...(event.message !== undefined ? { message: truncateSummary(event.message) } : {}),
98
- data: normalizeAgentEventData(event.data, category, event),
99
- ...(event.metadata ? { metadata: redactMetadata(event.metadata) } : {}),
100
- };
101
- }
102
- function normalizeEventCategory(value, type) {
103
- if (value === 'status' || value === 'text' || value === 'tool' || value === 'file' || value === 'permission' || value === 'question' || value === 'error') {
104
- return value;
105
- }
106
- if (type === 'text')
107
- return 'text';
108
- if (type === 'tool_started' || type === 'tool_updated' || type === 'tool_completed')
109
- return 'tool';
110
- if (type === 'file_changed')
111
- return 'file';
112
- if (type === 'permission_requested' || type === 'permission_resolved')
113
- return 'permission';
114
- if (type === 'user_question_started' || type === 'user_question_resolved')
115
- return 'question';
116
- if (type === 'run_failed' || type === 'error')
117
- return 'error';
118
- if (type === 'tool')
119
- return 'tool';
120
- if (type === 'file')
121
- return 'file';
122
- if (type === 'permission')
123
- return 'permission';
124
- if (type === 'status' || type === 'runtime_status')
125
- return 'status';
126
- return 'status';
127
- }
128
- function truncateEventDataValue(value, depth = 0) {
129
- if (typeof value === 'string')
130
- return truncateSummary(value);
131
- if (typeof value !== 'object' || value === null)
132
- return value;
133
- if (depth > 4)
134
- return '[truncated]';
135
- if (Array.isArray(value)) {
136
- return value.slice(0, 50).map((item) => truncateEventDataValue(item, depth + 1));
137
- }
138
- const next = {};
139
- for (const [key, item] of Object.entries(value)) {
140
- next[key] = truncateEventDataValue(item, depth + 1);
141
- }
142
- return next;
143
- }
144
- function redactEventData(data) {
145
- if (!data)
146
- return undefined;
147
- return truncateEventDataValue(redactSensitiveObject(data));
148
- }
149
- function statusLabel(status) {
150
- return status === 'timed_out' ? 'timed out' : status.replace(/_/g, ' ');
151
- }
152
- function defaultEventData(record, type, category, message, input) {
153
- const summary = message === undefined ? undefined : truncateSummary(message);
154
- if (category === 'error') {
155
- return {
156
- kind: 'error',
157
- message: summary || record.error || statusLabel(record.status),
158
- };
159
- }
160
- if (category === 'text') {
161
- return {
162
- kind: 'text',
163
- text: summary || '',
164
- channel: 'assistant',
165
- };
166
- }
167
- if (category === 'tool') {
168
- const status = type === 'tool_started'
169
- ? 'started'
170
- : type === 'tool_completed'
171
- ? 'completed'
172
- : undefined;
173
- return {
174
- kind: 'tool',
175
- name: input?.toolName ? truncateSummary(input.toolName) : 'tool',
176
- ...(status ? { status } : {}),
177
- ...(summary ? { outputSummary: summary } : {}),
178
- };
179
- }
180
- if (category === 'file') {
181
- return {
182
- kind: 'file',
183
- path: input?.filePath ? truncateSummary(input.filePath) : 'unknown',
184
- action: 'unknown',
185
- ...(summary ? { summary } : {}),
186
- };
187
- }
188
- if (category === 'permission') {
189
- return {
190
- kind: 'permission',
191
- action: input?.toolName ? truncateSummary(input.toolName) : 'approval',
192
- status: type === 'permission_resolved' || type === 'user_question_resolved' ? 'approved' : 'requested',
193
- ...(input?.filePath ? { resource: truncateSummary(input.filePath) } : {}),
194
- ...(summary ? { prompt: summary } : {}),
195
- };
196
- }
197
- if (category === 'question') {
198
- return {
199
- kind: 'question',
200
- status: type === 'user_question_resolved' ? 'answered' : 'requested',
201
- ...(summary ? { prompt: summary } : {}),
202
- };
203
- }
204
- return {
205
- kind: 'status',
206
- nextStatus: input?.status ?? record.status,
207
- ...(summary ? { summary } : {}),
208
- };
209
- }
210
- function normalizeAgentEventData(data, category, event) {
211
- if (data)
212
- return redactEventData(data) ?? defaultEventData(event.record, event.type, category, event.message);
213
- return defaultEventData(event.record, event.type, category, event.message, {
214
- type: event.type,
215
- category,
216
- status: event.status,
217
- message: event.message,
218
- toolName: event.toolName,
219
- filePath: event.filePath,
220
- });
221
- }
222
- function normalizeEventPatch(record, input) {
223
- const category = normalizeEventCategory(input.category, input.type);
224
- const status = input.status ?? record.status;
225
- const message = input.message !== undefined ? truncateSummary(input.message) : undefined;
226
- const legacyInput = {
227
- toolName: input.toolName,
228
- filePath: input.filePath,
229
- status,
230
- message,
231
- };
232
- return {
233
- type: input.type,
234
- category,
235
- ...(input.status ? { status } : {}),
236
- ...(message !== undefined ? { message } : {}),
237
- data: input.data
238
- ? redactEventData(input.data) ?? defaultEventData(record, input.type, category, message, legacyInput)
239
- : defaultEventData(record, input.type, category, message, legacyInput),
240
- ...(input.title ? { title: truncateSummary(input.title) } : {}),
241
- ...(input.toolCallId ? { toolCallId: truncateSummary(input.toolCallId) } : {}),
242
- ...(input.toolName ? { toolName: truncateSummary(input.toolName) } : {}),
243
- ...(input.filePath ? { filePath: truncateSummary(input.filePath) } : {}),
244
- ...(input.runtime ? { runtime: truncateSummary(input.runtime) } : {}),
245
- ...(input.visibility ? { visibility: input.visibility } : {}),
246
- ...(input.metadata ? { metadata: redactMetadata(input.metadata) } : {}),
247
- };
248
- }
249
- // --- disk: legacy readers (read-only, never written again) ---
250
- function recordWriteTs(record) {
251
- return record.completedAt ?? record.startedAt;
252
- }
253
- function mergeLegacyJson(mindRoot, merged, events) {
254
- try {
255
- const file = legacyJsonPath(mindRoot);
256
- if (!fs.existsSync(file))
257
- return;
258
- const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
259
- for (const value of Array.isArray(parsed.records) ? parsed.records : []) {
260
- const record = normalizeRecord(value);
261
- if (record)
262
- mergeRecordEntry(merged, { record, ts: recordWriteTs(record), shard: null });
263
- }
264
- for (const value of Array.isArray(parsed.events) ? parsed.events : []) {
265
- const event = normalizeEvent(value);
266
- if (event)
267
- events.push(event);
268
- }
269
- }
270
- catch {
271
- // Unreadable legacy data must never block the ledger.
272
- }
273
- }
274
- function mergeLegacyJsonl(mindRoot, merged, events) {
275
- try {
276
- const file = legacyJsonlPath(mindRoot);
277
- if (!fs.existsSync(file))
278
- return;
279
- // Replay the v2 op log into a local view first — later ops override
280
- // earlier ones within the file, independent of cross-shard merge order.
281
- const local = new Map();
282
- const localEvents = [];
283
- for (const line of fs.readFileSync(file, 'utf-8').split('\n')) {
284
- const trimmed = line.trim();
285
- if (!trimmed)
286
- continue;
287
- let op;
288
- try {
289
- op = JSON.parse(trimmed);
290
- }
291
- catch {
292
- continue;
293
- }
294
- if (op.version !== 2 || typeof op.type !== 'string')
295
- continue;
296
- if (op.type === 'reset') {
297
- local.clear();
298
- localEvents.length = 0;
299
- continue;
300
- }
301
- if (op.type === 'compact') {
302
- local.clear();
303
- localEvents.length = 0;
304
- const compact = op;
305
- for (const value of Array.isArray(compact.records) ? compact.records : []) {
306
- const record = normalizeRecord(value);
307
- if (record)
308
- local.set(record.id, record);
309
- }
310
- for (const value of Array.isArray(compact.events) ? compact.events : []) {
311
- const event = normalizeEvent(value);
312
- if (event)
313
- localEvents.push(event);
314
- }
315
- continue;
316
- }
317
- if (op.type === 'record_upsert') {
318
- const record = normalizeRecord(op.record);
319
- if (record)
320
- local.set(record.id, record);
321
- continue;
322
- }
323
- if (op.type === 'event_append') {
324
- const event = normalizeEvent(op.event);
325
- if (event)
326
- localEvents.push(event);
327
- }
328
- }
329
- for (const record of local.values()) {
330
- mergeRecordEntry(merged, { record, ts: recordWriteTs(record), shard: null });
331
- }
332
- events.push(...localEvents);
333
- }
334
- catch {
335
- // Unreadable legacy data must never block the ledger.
336
- }
337
- }
338
- // --- disk: shard readers + merge ---
339
- function listShardFiles(mindRoot) {
340
- try {
341
- const dir = ledgerDirPath(mindRoot);
342
- if (!fs.existsSync(dir))
343
- return [];
344
- const shards = [];
345
- for (const name of fs.readdirSync(dir)) {
346
- const match = SHARD_FILE_PATTERN.exec(name);
347
- if (!match)
348
- continue;
349
- shards.push({ file: path.join(dir, name), pid: Number(match[1]), startTs: Number(match[2]) });
350
- }
351
- // Deterministic merge order so every reader resolves ties identically.
352
- return shards.sort((a, b) => (a.startTs - b.startTs) || (a.pid - b.pid));
353
- }
354
- catch {
355
- return [];
356
- }
357
- }
358
- const conflictWarnedRunIds = new Set();
359
- function mergeRecordEntry(merged, entry) {
360
- const existing = merged.get(entry.record.id);
361
- if (!existing) {
362
- merged.set(entry.record.id, entry);
363
- return;
364
- }
365
- // Same run id written from two places (spec edge case: cross-process id
366
- // collision). Runs are owned by the creating process; resolve
367
- // last-write-wins by timestamp and surface the anomaly once.
368
- const differentWriter = existing.shard?.pid !== entry.shard?.pid || existing.shard?.startTs !== entry.shard?.startTs;
369
- if (differentWriter && !conflictWarnedRunIds.has(entry.record.id)) {
370
- conflictWarnedRunIds.add(entry.record.id);
371
- console.warn(`[mindos] agent run ledger: run id ${entry.record.id} appears in multiple ledger sources; keeping the most recent write.`);
372
- }
373
- if (entry.ts >= existing.ts)
374
- merged.set(entry.record.id, entry);
375
- }
376
- function mergeShard(shard, merged) {
377
- try {
378
- if (!fs.existsSync(shard.file))
379
- return;
380
- const local = new Map();
381
- for (const line of fs.readFileSync(shard.file, 'utf-8').split('\n')) {
382
- const trimmed = line.trim();
383
- if (!trimmed)
384
- continue;
385
- let op;
386
- try {
387
- op = JSON.parse(trimmed);
388
- }
389
- catch {
390
- continue;
391
- }
392
- if (op.version !== 3 || typeof op.type !== 'string')
393
- continue;
394
- if (op.type === 'compact') {
395
- local.clear();
396
- const compact = op;
397
- for (const value of Array.isArray(compact.records) ? compact.records : []) {
398
- const record = normalizeRecord(value);
399
- if (record)
400
- local.set(record.id, { record, ts: typeof op.ts === 'number' ? op.ts : recordWriteTs(record) });
401
- }
402
- continue;
403
- }
404
- if (op.type === 'record_upsert') {
405
- const record = normalizeRecord(op.record);
406
- if (record)
407
- local.set(record.id, { record, ts: typeof op.ts === 'number' ? op.ts : recordWriteTs(record) });
408
- }
409
- }
410
- for (const { record, ts } of local.values()) {
411
- mergeRecordEntry(merged, { record, ts, shard: { pid: shard.pid, startTs: shard.startTs } });
412
- }
413
- }
414
- catch {
415
- // A torn or unreadable shard must never block the ledger.
416
- }
417
- }
418
- function isPidAlive(pid) {
419
- try {
420
- process.kill(pid, 0);
421
- return true;
422
- }
423
- catch (error) {
424
- // EPERM = exists but owned by another user; anything else (ESRCH) = gone.
425
- return error.code === 'EPERM';
426
- }
427
- }
428
- function isDeadWriter(entry) {
429
- // Legacy global files have no owning process — since the migration, no live
430
- // process appends to them, so a non-terminal record there can never
431
- // progress again.
432
- if (!entry.shard)
433
- return true;
434
- const self = shardIdentity();
435
- if (entry.shard.pid === self.pid) {
436
- // Same pid but a different start timestamp is a previous incarnation of
437
- // a recycled pid — that writer is gone even though the pid looks alive.
438
- return entry.shard.startTs !== self.startTs;
439
- }
440
- return !isPidAlive(entry.shard.pid);
441
- }
442
- /**
443
- * Orphaned runs: the owning process died before reaching a terminal status.
444
- * Marked failed at merge time, in memory only — the shard stays untouched on
445
- * disk for audit, and every reader computes the same result.
446
- */
447
- function markOrphanedRun(record) {
448
- return {
449
- ...record,
450
- status: 'failed',
451
- error: record.error ?? 'MindOS process that owned this run exited before it finished.',
452
- metadata: { ...(record.metadata ?? {}), failureReason: 'process-died' },
453
- };
454
- }
455
- function readPersistedStore(mindRoot) {
456
- const merged = new Map();
457
- const events = [];
458
- mergeLegacyJson(mindRoot, merged, events);
459
- mergeLegacyJsonl(mindRoot, merged, events);
460
- const self = shardIdentity();
461
- const ownRecordIds = new Set();
462
- for (const shard of listShardFiles(mindRoot)) {
463
- mergeShard(shard, merged);
464
- }
465
- const records = [];
466
- for (const entry of merged.values()) {
467
- const ownedBySelf = entry.shard?.pid === self.pid && entry.shard?.startTs === self.startTs;
468
- if (ownedBySelf)
469
- ownRecordIds.add(entry.record.id);
470
- if (!isTerminalStatus(entry.record.status) && !ownedBySelf && isDeadWriter(entry)) {
471
- records.push(markOrphanedRun(entry.record));
472
- }
473
- else {
474
- records.push(entry.record);
475
- }
476
- }
477
- records.sort((a, b) => b.startedAt - a.startedAt);
478
- events.sort((a, b) => b.ts - a.ts);
479
- return {
480
- mindRoot,
481
- records: records.slice(0, MAX_RUNS),
482
- events: events.slice(0, MAX_EVENTS),
483
- ownRecordIds,
484
- };
485
- }
486
- // --- disk: own-shard writer (the ONLY writes this module performs) ---
487
- function appendOwnShardOperation(store, record) {
488
- if (!store.mindRoot)
489
- return;
490
- try {
491
- const file = ownShardPath(store.mindRoot);
492
- fs.mkdirSync(path.dirname(file), { recursive: true });
493
- const op = { version: 3, type: 'record_upsert', ts: nowMs(), record };
494
- fs.appendFileSync(file, `${JSON.stringify(op)}\n`, 'utf-8');
495
- store.ownRecordIds.add(record.id);
496
- if (fs.statSync(file).size > MAX_SHARD_LOG_BYTES) {
497
- compactOwnShard(store);
498
- }
499
- }
500
- catch {
501
- // Ledger persistence must never affect agent execution.
502
- }
503
- }
504
- function compactOwnShard(store) {
505
- if (!store.mindRoot)
506
- return;
507
- try {
508
- const file = ownShardPath(store.mindRoot);
509
- fs.mkdirSync(path.dirname(file), { recursive: true });
510
- // This process is the shard's single writer, so the in-memory view of its
511
- // OWN records is authoritative — foreign records live in foreign shards
512
- // and are deliberately not written here.
513
- const op = {
514
- version: 3,
515
- type: 'compact',
516
- ts: nowMs(),
517
- records: store.records.filter((record) => store.ownRecordIds.has(record.id)).slice(0, MAX_RUNS),
518
- };
519
- const tmp = `${file}.tmp`;
520
- fs.writeFileSync(tmp, `${JSON.stringify(op)}\n`, 'utf-8');
521
- fs.renameSync(tmp, file);
522
- }
523
- catch {
524
- // Ledger persistence must never affect agent execution.
525
- }
526
- }
527
- // --- in-memory store + subscribers ---
528
- function getStore() {
529
- const mindRoot = resolveLedgerRoot();
530
- const store = getProcessGlobal(AGENT_RUN_LEDGER_STORE_KEY, () => (mindRoot ? readPersistedStore(mindRoot) : emptyStore()));
531
- if (store.mindRoot !== mindRoot) {
532
- deleteProcessGlobal(AGENT_RUN_LEDGER_STORE_KEY);
533
- return getProcessGlobal(AGENT_RUN_LEDGER_STORE_KEY, () => (mindRoot ? readPersistedStore(mindRoot) : emptyStore()));
534
- }
535
- return store;
536
- }
537
- function getSubscribers() {
538
- return getProcessGlobal(AGENT_RUN_LEDGER_SUBSCRIBERS_KEY, () => new Set());
539
- }
540
- function notifyAgentEventSubscribers(event) {
541
- for (const subscriber of Array.from(getSubscribers())) {
542
- try {
543
- subscriber(event);
544
- }
545
- catch {
546
- // Realtime observers must never affect agent execution or ledger persistence.
547
- }
548
- }
549
- }
550
- function nowMs() {
551
- return Date.now();
552
- }
553
- function createRunId() {
554
- return `agent-run-${nowMs().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
555
- }
556
- function createEventId() {
557
- return `agent-event-${nowMs().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
558
- }
559
- function truncateSummary(value) {
560
- if (typeof value === 'string') {
561
- const redacted = redactSensitiveText(value);
562
- return redacted.length > MAX_SUMMARY_CHARS ? `${redacted.slice(0, MAX_SUMMARY_CHARS)}...` : redacted;
563
- }
564
- if (value == null)
565
- return '';
566
- try {
567
- const serialized = JSON.stringify(redactSensitiveObject(value));
568
- return serialized.length > MAX_SUMMARY_CHARS ? `${serialized.slice(0, MAX_SUMMARY_CHARS)}...` : serialized;
569
- }
570
- catch {
571
- return redactSensitiveText(String(value));
572
- }
573
- }
574
- function redactMetadata(metadata) {
575
- return redactSensitiveObject(metadata);
576
- }
577
- function normalizePermissionMode(mode) {
578
- if (mode === 'readonly')
579
- return 'readonly';
580
- if (mode === 'organize')
581
- return 'organize';
582
- return 'agent';
583
- }
584
- function normalizeArchiveRef(value) {
585
- if (!value || typeof value !== 'object')
586
- return undefined;
587
- const archive = {};
588
- if (typeof value.sessionId === 'string' && value.sessionId.trim())
589
- archive.sessionId = truncateSummary(value.sessionId);
590
- if (typeof value.path === 'string' && value.path.trim())
591
- archive.path = truncateSummary(value.path);
592
- return Object.keys(archive).length > 0 ? archive : undefined;
593
- }
594
- function errorMessage(error) {
595
- if (error instanceof Error)
596
- return error.message;
597
- if (typeof error === 'string')
598
- return error;
599
- try {
600
- return JSON.stringify(error);
601
- }
602
- catch {
603
- return String(error);
604
- }
605
- }
606
- function isTerminalStatus(status) {
607
- return status === 'completed' || status === 'failed' || status === 'canceled' || status === 'timed_out';
608
- }
609
- function appendAgentEvent(record, input, message) {
610
- const store = getStore();
611
- const patch = typeof input === 'string'
612
- ? normalizeEventPatch(record, { type: input, category: normalizeEventCategory(undefined, input), ...(message ? { message } : {}) })
613
- : normalizeEventPatch(record, input);
614
- const event = {
615
- id: createEventId(),
616
- runId: record.id,
617
- ...patch,
618
- ts: nowMs(),
619
- status: patch.status ?? record.status,
620
- record,
621
- };
622
- store.events.unshift(event);
623
- if (store.events.length > MAX_EVENTS) {
624
- store.events = store.events.slice(0, MAX_EVENTS);
625
- }
626
- notifyAgentEventSubscribers(event);
627
- return event;
628
- }
629
- export function appendAgentRunEvent(runId, input) {
630
- const record = getAgentRun(runId);
631
- if (!record)
632
- return undefined;
633
- return appendAgentEvent(record, input);
634
- }
635
- function finishRun(id, patch) {
636
- const store = getStore();
637
- const index = store.records.findIndex((record) => record.id === id);
638
- if (index < 0)
639
- return undefined;
640
- const current = store.records[index];
641
- if (isTerminalStatus(current.status))
642
- return current;
643
- const archivePatch = normalizeArchiveRef(patch.archive);
644
- const completedAt = nowMs();
645
- const next = {
646
- ...current,
647
- status: patch.status,
648
- ...(patch.outputSummary !== undefined ? { outputSummary: truncateSummary(patch.outputSummary) } : {}),
649
- ...(patch.error !== undefined ? { error: truncateSummary(patch.error) } : {}),
650
- ...(patch.metadata ? { metadata: redactMetadata({ ...(current.metadata ?? {}), ...patch.metadata }) } : {}),
651
- ...(archivePatch ? { archive: { ...(current.archive ?? {}), ...archivePatch } } : {}),
652
- completedAt,
653
- durationMs: Math.max(0, completedAt - current.startedAt),
654
- };
655
- store.records[index] = next;
656
- appendOwnShardOperation(store, next);
657
- const eventType = patch.status === 'completed'
658
- ? 'run_completed'
659
- : patch.status === 'canceled'
660
- ? 'run_canceled'
661
- : 'run_failed';
662
- appendAgentEvent(next, eventType, patch.error);
663
- return next;
664
- }
665
- export function startAgentRun(input) {
666
- const startedAt = nowMs();
667
- const context = getCurrentAgentRunContext();
668
- const id = input.id ?? createRunId();
669
- const parentRunId = input.parentRunId ?? context?.parentRunId;
670
- const rootRunId = input.rootRunId ?? context?.rootRunId ?? (parentRunId || id);
671
- const chatSessionId = input.chatSessionId ?? context?.chatSessionId;
672
- const archive = normalizeArchiveRef(input.archive);
673
- const record = {
674
- id,
675
- rootRunId,
676
- ...(parentRunId ? { parentRunId } : {}),
677
- ...(chatSessionId ? { chatSessionId } : {}),
678
- agentKind: input.agentKind,
679
- runtimeId: input.runtimeId,
680
- displayName: input.displayName,
681
- status: input.status ?? 'running',
682
- ...(input.cwd ? { cwd: input.cwd } : {}),
683
- permissionMode: normalizePermissionMode(input.permissionMode),
684
- inputSummary: truncateSummary(input.inputSummary),
685
- startedAt,
686
- ...(archive ? { archive } : {}),
687
- ...(input.metadata ? { metadata: redactMetadata(input.metadata) } : {}),
688
- };
689
- const store = getStore();
690
- store.records.unshift(record);
691
- if (store.records.length > MAX_RUNS) {
692
- store.records = store.records.slice(0, MAX_RUNS);
693
- }
694
- appendOwnShardOperation(store, record);
695
- appendAgentEvent(record, 'run_started');
696
- return record;
697
- }
698
- export function updateAgentRun(id, input) {
699
- const store = getStore();
700
- const index = store.records.findIndex((record) => record.id === id);
701
- if (index < 0)
702
- return undefined;
703
- const current = store.records[index];
704
- const archivePatch = normalizeArchiveRef(input.archive);
705
- const next = {
706
- ...current,
707
- ...(input.displayName !== undefined ? { displayName: input.displayName } : {}),
708
- ...(input.runtimeId !== undefined ? { runtimeId: input.runtimeId } : {}),
709
- ...(input.cwd !== undefined ? { cwd: input.cwd } : {}),
710
- ...(input.permissionMode !== undefined ? { permissionMode: normalizePermissionMode(input.permissionMode) } : {}),
711
- ...(input.inputSummary !== undefined ? { inputSummary: truncateSummary(input.inputSummary) } : {}),
712
- ...(input.outputSummary !== undefined ? { outputSummary: truncateSummary(input.outputSummary) } : {}),
713
- ...(input.error !== undefined ? { error: truncateSummary(input.error) } : {}),
714
- ...(input.status !== undefined ? { status: input.status } : {}),
715
- ...(archivePatch ? { archive: { ...(current.archive ?? {}), ...archivePatch } } : {}),
716
- ...(input.metadata ? { metadata: redactMetadata({ ...(current.metadata ?? {}), ...input.metadata }) } : {}),
717
- };
718
- store.records[index] = next;
719
- appendOwnShardOperation(store, next);
720
- appendAgentEvent(next, 'run_updated', input.error ?? input.outputSummary);
721
- return next;
722
- }
723
- export function completeAgentRun(id, input = {}) {
724
- return finishRun(id, {
725
- status: 'completed',
726
- outputSummary: input.outputSummary,
727
- archive: input.archive,
728
- metadata: input.metadata,
729
- });
730
- }
731
- export function failAgentRun(id, input) {
732
- return finishRun(id, {
733
- status: input.status ?? 'failed',
734
- outputSummary: input.outputSummary,
735
- error: errorMessage(input.error),
736
- archive: input.archive,
737
- metadata: input.metadata,
738
- });
739
- }
740
- export function cancelAgentRun(id, input = {}) {
741
- return finishRun(id, {
742
- status: 'canceled',
743
- outputSummary: input.outputSummary,
744
- error: errorMessage(input.reason ?? 'Agent run was canceled.'),
745
- metadata: input.metadata,
746
- });
747
- }
748
- export function getAgentRun(id) {
749
- return getStore().records.find((record) => record.id === id);
750
- }
751
- export function listAgentRuns(options = {}) {
752
- const limit = Math.max(1, Math.min(options.limit ?? 100, MAX_RUNS));
753
- return getStore().records
754
- .filter((record) => !options.runId || record.id === options.runId)
755
- .filter((record) => !options.rootRunId || record.rootRunId === options.rootRunId || record.id === options.rootRunId)
756
- .filter((record) => !options.kind || record.agentKind === options.kind)
757
- .filter((record) => !options.status || record.status === options.status)
758
- .filter((record) => !options.parentRunId || record.parentRunId === options.parentRunId)
759
- .filter((record) => !options.chatSessionId || record.chatSessionId === options.chatSessionId)
760
- .filter((record) => options.startedAfter === undefined || record.startedAt >= options.startedAfter)
761
- .slice(0, limit);
762
- }
763
- export function listAgentEvents(options = {}) {
764
- const limit = Math.max(1, Math.min(options.limit ?? 100, MAX_EVENTS));
765
- return getStore().events
766
- .filter((event) => !options.runId || event.runId === options.runId)
767
- .filter((event) => !options.rootRunId || event.record.rootRunId === options.rootRunId || event.record.id === options.rootRunId)
768
- .filter((event) => !options.chatSessionId || event.record.chatSessionId === options.chatSessionId)
769
- .filter((event) => !options.type || event.type === options.type)
770
- .filter((event) => !options.category || event.category === options.category)
771
- .filter((event) => options.startedAfter === undefined || event.ts >= options.startedAfter || event.record.startedAt >= options.startedAfter)
772
- .slice(0, limit);
773
- }
774
- export function subscribeAgentRunEvents(subscriber) {
775
- const subscribers = getSubscribers();
776
- subscribers.add(subscriber);
777
- return () => {
778
- subscribers.delete(subscriber);
779
- };
780
- }
781
- export function coerceAgentRunPermissionMode(mode) {
782
- return normalizePermissionMode(mode);
783
- }
784
- /**
785
- * Test-only: clear memory and delete every ledger file under the current
786
- * mind root — shards of other (test) processes and legacy files included.
787
- * Production code must never delete foreign shards; tests need a clean slate.
788
- */
789
- export function resetAgentRunsForTest() {
790
- const store = getStore();
791
- store.records = [];
792
- store.events = [];
793
- store.ownRecordIds.clear();
794
- if (!store.mindRoot)
795
- return;
796
- try {
797
- const dir = ledgerDirPath(store.mindRoot);
798
- if (!fs.existsSync(dir))
799
- return;
800
- for (const name of fs.readdirSync(dir)) {
801
- if (SHARD_FILE_PATTERN.test(name) || name === LEDGER_LEGACY_JSON_NAME || name === LEDGER_LEGACY_JSONL_NAME) {
802
- fs.rmSync(path.join(dir, name), { force: true });
803
- }
804
- }
805
- }
806
- catch {
807
- // Test cleanup is best-effort.
808
- }
809
- }
810
- /** Test-only: drop the in-memory store so the next access re-merges from disk. */
811
- export function reloadAgentRunsFromDiskForTest() {
812
- deleteProcessGlobal(AGENT_RUN_LEDGER_STORE_KEY);
813
- }
1
+ export * from './ledger/run-ledger.js';
814
2
  //# sourceMappingURL=run-ledger.js.map