@runcore-sh/runcore 0.1.2

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 (1112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -0
  3. package/dist/activity/log.d.ts +37 -0
  4. package/dist/activity/log.d.ts.map +1 -0
  5. package/dist/activity/log.js +259 -0
  6. package/dist/activity/log.js.map +1 -0
  7. package/dist/adapters/storage/gdrive-backup.d.ts +20 -0
  8. package/dist/adapters/storage/gdrive-backup.d.ts.map +1 -0
  9. package/dist/adapters/storage/gdrive-backup.js +244 -0
  10. package/dist/adapters/storage/gdrive-backup.js.map +1 -0
  11. package/dist/adapters/storage/local.d.ts +19 -0
  12. package/dist/adapters/storage/local.d.ts.map +1 -0
  13. package/dist/adapters/storage/local.js +101 -0
  14. package/dist/adapters/storage/local.js.map +1 -0
  15. package/dist/adapters/storage/types.d.ts +44 -0
  16. package/dist/adapters/storage/types.d.ts.map +1 -0
  17. package/dist/adapters/storage/types.js +6 -0
  18. package/dist/adapters/storage/types.js.map +1 -0
  19. package/dist/agents/autonomous.d.ts +67 -0
  20. package/dist/agents/autonomous.d.ts.map +1 -0
  21. package/dist/agents/autonomous.js +710 -0
  22. package/dist/agents/autonomous.js.map +1 -0
  23. package/dist/agents/commit.d.ts +22 -0
  24. package/dist/agents/commit.d.ts.map +1 -0
  25. package/dist/agents/commit.js +120 -0
  26. package/dist/agents/commit.js.map +1 -0
  27. package/dist/agents/continue.d.ts +19 -0
  28. package/dist/agents/continue.d.ts.map +1 -0
  29. package/dist/agents/continue.js +158 -0
  30. package/dist/agents/continue.js.map +1 -0
  31. package/dist/agents/cooldown.d.ts +127 -0
  32. package/dist/agents/cooldown.d.ts.map +1 -0
  33. package/dist/agents/cooldown.js +396 -0
  34. package/dist/agents/cooldown.js.map +1 -0
  35. package/dist/agents/dedup-guard.d.ts +15 -0
  36. package/dist/agents/dedup-guard.d.ts.map +1 -0
  37. package/dist/agents/dedup-guard.js +128 -0
  38. package/dist/agents/dedup-guard.js.map +1 -0
  39. package/dist/agents/index.d.ts +34 -0
  40. package/dist/agents/index.d.ts.map +1 -0
  41. package/dist/agents/index.js +51 -0
  42. package/dist/agents/index.js.map +1 -0
  43. package/dist/agents/instance-manager.d.ts +262 -0
  44. package/dist/agents/instance-manager.d.ts.map +1 -0
  45. package/dist/agents/instance-manager.js +850 -0
  46. package/dist/agents/instance-manager.js.map +1 -0
  47. package/dist/agents/locks.d.ts +81 -0
  48. package/dist/agents/locks.d.ts.map +1 -0
  49. package/dist/agents/locks.js +234 -0
  50. package/dist/agents/locks.js.map +1 -0
  51. package/dist/agents/memory.d.ts +37 -0
  52. package/dist/agents/memory.d.ts.map +1 -0
  53. package/dist/agents/memory.js +92 -0
  54. package/dist/agents/memory.js.map +1 -0
  55. package/dist/agents/monitor.d.ts +16 -0
  56. package/dist/agents/monitor.d.ts.map +1 -0
  57. package/dist/agents/monitor.js +235 -0
  58. package/dist/agents/monitor.js.map +1 -0
  59. package/dist/agents/orchestration.d.ts +218 -0
  60. package/dist/agents/orchestration.d.ts.map +1 -0
  61. package/dist/agents/orchestration.js +715 -0
  62. package/dist/agents/orchestration.js.map +1 -0
  63. package/dist/agents/recover.d.ts +30 -0
  64. package/dist/agents/recover.d.ts.map +1 -0
  65. package/dist/agents/recover.js +166 -0
  66. package/dist/agents/recover.js.map +1 -0
  67. package/dist/agents/reflection.d.ts +36 -0
  68. package/dist/agents/reflection.d.ts.map +1 -0
  69. package/dist/agents/reflection.js +198 -0
  70. package/dist/agents/reflection.js.map +1 -0
  71. package/dist/agents/runtime/bus.d.ts +46 -0
  72. package/dist/agents/runtime/bus.d.ts.map +1 -0
  73. package/dist/agents/runtime/bus.js +174 -0
  74. package/dist/agents/runtime/bus.js.map +1 -0
  75. package/dist/agents/runtime/config.d.ts +14 -0
  76. package/dist/agents/runtime/config.d.ts.map +1 -0
  77. package/dist/agents/runtime/config.js +100 -0
  78. package/dist/agents/runtime/config.js.map +1 -0
  79. package/dist/agents/runtime/driver.d.ts +25 -0
  80. package/dist/agents/runtime/driver.d.ts.map +1 -0
  81. package/dist/agents/runtime/driver.js +215 -0
  82. package/dist/agents/runtime/driver.js.map +1 -0
  83. package/dist/agents/runtime/errors.d.ts +30 -0
  84. package/dist/agents/runtime/errors.d.ts.map +1 -0
  85. package/dist/agents/runtime/errors.js +40 -0
  86. package/dist/agents/runtime/errors.js.map +1 -0
  87. package/dist/agents/runtime/index.d.ts +29 -0
  88. package/dist/agents/runtime/index.d.ts.map +1 -0
  89. package/dist/agents/runtime/index.js +54 -0
  90. package/dist/agents/runtime/index.js.map +1 -0
  91. package/dist/agents/runtime/lifecycle.d.ts +46 -0
  92. package/dist/agents/runtime/lifecycle.d.ts.map +1 -0
  93. package/dist/agents/runtime/lifecycle.js +116 -0
  94. package/dist/agents/runtime/lifecycle.js.map +1 -0
  95. package/dist/agents/runtime/manager.d.ts +129 -0
  96. package/dist/agents/runtime/manager.d.ts.map +1 -0
  97. package/dist/agents/runtime/manager.js +947 -0
  98. package/dist/agents/runtime/manager.js.map +1 -0
  99. package/dist/agents/runtime/registry.d.ts +66 -0
  100. package/dist/agents/runtime/registry.d.ts.map +1 -0
  101. package/dist/agents/runtime/registry.js +195 -0
  102. package/dist/agents/runtime/registry.js.map +1 -0
  103. package/dist/agents/runtime/resources.d.ts +49 -0
  104. package/dist/agents/runtime/resources.d.ts.map +1 -0
  105. package/dist/agents/runtime/resources.js +146 -0
  106. package/dist/agents/runtime/resources.js.map +1 -0
  107. package/dist/agents/runtime/types.d.ts +168 -0
  108. package/dist/agents/runtime/types.d.ts.map +1 -0
  109. package/dist/agents/runtime/types.js +24 -0
  110. package/dist/agents/runtime/types.js.map +1 -0
  111. package/dist/agents/runtime.d.ts +240 -0
  112. package/dist/agents/runtime.d.ts.map +1 -0
  113. package/dist/agents/runtime.js +577 -0
  114. package/dist/agents/runtime.js.map +1 -0
  115. package/dist/agents/spawn.d.ts +49 -0
  116. package/dist/agents/spawn.d.ts.map +1 -0
  117. package/dist/agents/spawn.js +975 -0
  118. package/dist/agents/spawn.js.map +1 -0
  119. package/dist/agents/store.d.ts +29 -0
  120. package/dist/agents/store.d.ts.map +1 -0
  121. package/dist/agents/store.js +174 -0
  122. package/dist/agents/store.js.map +1 -0
  123. package/dist/agents/triage.d.ts +23 -0
  124. package/dist/agents/triage.d.ts.map +1 -0
  125. package/dist/agents/triage.js +81 -0
  126. package/dist/agents/triage.js.map +1 -0
  127. package/dist/agents/types.d.ts +37 -0
  128. package/dist/agents/types.d.ts.map +1 -0
  129. package/dist/agents/types.js +2 -0
  130. package/dist/agents/types.js.map +1 -0
  131. package/dist/agents/workflow.d.ts +137 -0
  132. package/dist/agents/workflow.d.ts.map +1 -0
  133. package/dist/agents/workflow.js +542 -0
  134. package/dist/agents/workflow.js.map +1 -0
  135. package/dist/auth/crypto.d.ts +22 -0
  136. package/dist/auth/crypto.d.ts.map +1 -0
  137. package/dist/auth/crypto.js +42 -0
  138. package/dist/auth/crypto.js.map +1 -0
  139. package/dist/auth/identity.d.ts +89 -0
  140. package/dist/auth/identity.d.ts.map +1 -0
  141. package/dist/auth/identity.js +264 -0
  142. package/dist/auth/identity.js.map +1 -0
  143. package/dist/avatar/client.d.ts +34 -0
  144. package/dist/avatar/client.d.ts.map +1 -0
  145. package/dist/avatar/client.js +172 -0
  146. package/dist/avatar/client.js.map +1 -0
  147. package/dist/avatar/sidecar.d.ts +16 -0
  148. package/dist/avatar/sidecar.d.ts.map +1 -0
  149. package/dist/avatar/sidecar.js +125 -0
  150. package/dist/avatar/sidecar.js.map +1 -0
  151. package/dist/board/provider.d.ts +13 -0
  152. package/dist/board/provider.d.ts.map +1 -0
  153. package/dist/board/provider.js +19 -0
  154. package/dist/board/provider.js.map +1 -0
  155. package/dist/board/types.d.ts +76 -0
  156. package/dist/board/types.d.ts.map +1 -0
  157. package/dist/board/types.js +7 -0
  158. package/dist/board/types.js.map +1 -0
  159. package/dist/brain/skills.d.ts +177 -0
  160. package/dist/brain/skills.d.ts.map +1 -0
  161. package/dist/brain/skills.js +452 -0
  162. package/dist/brain/skills.js.map +1 -0
  163. package/dist/brain.d.ts +42 -0
  164. package/dist/brain.d.ts.map +1 -0
  165. package/dist/brain.js +98 -0
  166. package/dist/brain.js.map +1 -0
  167. package/dist/browser/sessions.d.ts +23 -0
  168. package/dist/browser/sessions.d.ts.map +1 -0
  169. package/dist/browser/sessions.js +121 -0
  170. package/dist/browser/sessions.js.map +1 -0
  171. package/dist/cache/file.d.ts +56 -0
  172. package/dist/cache/file.d.ts.map +1 -0
  173. package/dist/cache/file.js +176 -0
  174. package/dist/cache/file.js.map +1 -0
  175. package/dist/cache/index.d.ts +64 -0
  176. package/dist/cache/index.d.ts.map +1 -0
  177. package/dist/cache/index.js +108 -0
  178. package/dist/cache/index.js.map +1 -0
  179. package/dist/cache/keys.d.ts +29 -0
  180. package/dist/cache/keys.d.ts.map +1 -0
  181. package/dist/cache/keys.js +52 -0
  182. package/dist/cache/keys.js.map +1 -0
  183. package/dist/cache/llm-cache.d.ts +70 -0
  184. package/dist/cache/llm-cache.d.ts.map +1 -0
  185. package/dist/cache/llm-cache.js +165 -0
  186. package/dist/cache/llm-cache.js.map +1 -0
  187. package/dist/cache/memory.d.ts +53 -0
  188. package/dist/cache/memory.d.ts.map +1 -0
  189. package/dist/cache/memory.js +114 -0
  190. package/dist/cache/memory.js.map +1 -0
  191. package/dist/calendar/google-adapter.d.ts +16 -0
  192. package/dist/calendar/google-adapter.d.ts.map +1 -0
  193. package/dist/calendar/google-adapter.js +163 -0
  194. package/dist/calendar/google-adapter.js.map +1 -0
  195. package/dist/calendar/index.d.ts +8 -0
  196. package/dist/calendar/index.d.ts.map +1 -0
  197. package/dist/calendar/index.js +7 -0
  198. package/dist/calendar/index.js.map +1 -0
  199. package/dist/calendar/routes.d.ts +7 -0
  200. package/dist/calendar/routes.d.ts.map +1 -0
  201. package/dist/calendar/routes.js +199 -0
  202. package/dist/calendar/routes.js.map +1 -0
  203. package/dist/calendar/store.d.ts +73 -0
  204. package/dist/calendar/store.d.ts.map +1 -0
  205. package/dist/calendar/store.js +373 -0
  206. package/dist/calendar/store.js.map +1 -0
  207. package/dist/calendar/types.d.ts +99 -0
  208. package/dist/calendar/types.d.ts.map +1 -0
  209. package/dist/calendar/types.js +7 -0
  210. package/dist/calendar/types.js.map +1 -0
  211. package/dist/capabilities/definitions/board.d.ts +7 -0
  212. package/dist/capabilities/definitions/board.d.ts.map +1 -0
  213. package/dist/capabilities/definitions/board.js +232 -0
  214. package/dist/capabilities/definitions/board.js.map +1 -0
  215. package/dist/capabilities/definitions/browser.d.ts +18 -0
  216. package/dist/capabilities/definitions/browser.d.ts.map +1 -0
  217. package/dist/capabilities/definitions/browser.js +242 -0
  218. package/dist/capabilities/definitions/browser.js.map +1 -0
  219. package/dist/capabilities/definitions/calendar-context.d.ts +8 -0
  220. package/dist/capabilities/definitions/calendar-context.d.ts.map +1 -0
  221. package/dist/capabilities/definitions/calendar-context.js +41 -0
  222. package/dist/capabilities/definitions/calendar-context.js.map +1 -0
  223. package/dist/capabilities/definitions/calendar.d.ts +7 -0
  224. package/dist/capabilities/definitions/calendar.d.ts.map +1 -0
  225. package/dist/capabilities/definitions/calendar.js +173 -0
  226. package/dist/capabilities/definitions/calendar.js.map +1 -0
  227. package/dist/capabilities/definitions/docs.d.ts +6 -0
  228. package/dist/capabilities/definitions/docs.d.ts.map +1 -0
  229. package/dist/capabilities/definitions/docs.js +62 -0
  230. package/dist/capabilities/definitions/docs.js.map +1 -0
  231. package/dist/capabilities/definitions/email-context.d.ts +7 -0
  232. package/dist/capabilities/definitions/email-context.d.ts.map +1 -0
  233. package/dist/capabilities/definitions/email-context.js +55 -0
  234. package/dist/capabilities/definitions/email-context.js.map +1 -0
  235. package/dist/capabilities/definitions/email.d.ts +7 -0
  236. package/dist/capabilities/definitions/email.d.ts.map +1 -0
  237. package/dist/capabilities/definitions/email.js +94 -0
  238. package/dist/capabilities/definitions/email.js.map +1 -0
  239. package/dist/capabilities/definitions/task-done.d.ts +10 -0
  240. package/dist/capabilities/definitions/task-done.d.ts.map +1 -0
  241. package/dist/capabilities/definitions/task-done.js +83 -0
  242. package/dist/capabilities/definitions/task-done.js.map +1 -0
  243. package/dist/capabilities/definitions/vault-context.d.ts +12 -0
  244. package/dist/capabilities/definitions/vault-context.d.ts.map +1 -0
  245. package/dist/capabilities/definitions/vault-context.js +62 -0
  246. package/dist/capabilities/definitions/vault-context.js.map +1 -0
  247. package/dist/capabilities/definitions/web-search-context.d.ts +22 -0
  248. package/dist/capabilities/definitions/web-search-context.d.ts.map +1 -0
  249. package/dist/capabilities/definitions/web-search-context.js +60 -0
  250. package/dist/capabilities/definitions/web-search-context.js.map +1 -0
  251. package/dist/capabilities/index.d.ts +18 -0
  252. package/dist/capabilities/index.d.ts.map +1 -0
  253. package/dist/capabilities/index.js +21 -0
  254. package/dist/capabilities/index.js.map +1 -0
  255. package/dist/capabilities/registry.d.ts +84 -0
  256. package/dist/capabilities/registry.d.ts.map +1 -0
  257. package/dist/capabilities/registry.js +248 -0
  258. package/dist/capabilities/registry.js.map +1 -0
  259. package/dist/capabilities/types.d.ts +157 -0
  260. package/dist/capabilities/types.d.ts.map +1 -0
  261. package/dist/capabilities/types.js +35 -0
  262. package/dist/capabilities/types.js.map +1 -0
  263. package/dist/channels/whatsapp.d.ts +88 -0
  264. package/dist/channels/whatsapp.d.ts.map +1 -0
  265. package/dist/channels/whatsapp.js +200 -0
  266. package/dist/channels/whatsapp.js.map +1 -0
  267. package/dist/cli/backup.d.ts +13 -0
  268. package/dist/cli/backup.d.ts.map +1 -0
  269. package/dist/cli/backup.js +176 -0
  270. package/dist/cli/backup.js.map +1 -0
  271. package/dist/cli.d.ts +12 -0
  272. package/dist/cli.d.ts.map +1 -0
  273. package/dist/cli.js +231 -0
  274. package/dist/cli.js.map +1 -0
  275. package/dist/config/defaults.d.ts +45 -0
  276. package/dist/config/defaults.d.ts.map +1 -0
  277. package/dist/config/defaults.js +54 -0
  278. package/dist/config/defaults.js.map +1 -0
  279. package/dist/contacts/index.d.ts +3 -0
  280. package/dist/contacts/index.d.ts.map +1 -0
  281. package/dist/contacts/index.js +2 -0
  282. package/dist/contacts/index.js.map +1 -0
  283. package/dist/contacts/store.d.ts +58 -0
  284. package/dist/contacts/store.d.ts.map +1 -0
  285. package/dist/contacts/store.js +278 -0
  286. package/dist/contacts/store.js.map +1 -0
  287. package/dist/contacts/types.d.ts +47 -0
  288. package/dist/contacts/types.d.ts.map +1 -0
  289. package/dist/contacts/types.js +5 -0
  290. package/dist/contacts/types.js.map +1 -0
  291. package/dist/context/assembler.d.ts +26 -0
  292. package/dist/context/assembler.d.ts.map +1 -0
  293. package/dist/context/assembler.js +65 -0
  294. package/dist/context/assembler.js.map +1 -0
  295. package/dist/context/compaction.d.ts +34 -0
  296. package/dist/context/compaction.d.ts.map +1 -0
  297. package/dist/context/compaction.js +84 -0
  298. package/dist/context/compaction.js.map +1 -0
  299. package/dist/context/index.d.ts +3 -0
  300. package/dist/context/index.d.ts.map +1 -0
  301. package/dist/context/index.js +2 -0
  302. package/dist/context/index.js.map +1 -0
  303. package/dist/core/registry/index.d.ts +12 -0
  304. package/dist/core/registry/index.d.ts.map +1 -0
  305. package/dist/core/registry/index.js +14 -0
  306. package/dist/core/registry/index.js.map +1 -0
  307. package/dist/core/registry/publisher.d.ts +22 -0
  308. package/dist/core/registry/publisher.d.ts.map +1 -0
  309. package/dist/core/registry/publisher.js +195 -0
  310. package/dist/core/registry/publisher.js.map +1 -0
  311. package/dist/core/registry/registry.d.ts +92 -0
  312. package/dist/core/registry/registry.d.ts.map +1 -0
  313. package/dist/core/registry/registry.js +254 -0
  314. package/dist/core/registry/registry.js.map +1 -0
  315. package/dist/core/registry/search.d.ts +12 -0
  316. package/dist/core/registry/search.d.ts.map +1 -0
  317. package/dist/core/registry/search.js +132 -0
  318. package/dist/core/registry/search.js.map +1 -0
  319. package/dist/core/registry/store.d.ts +55 -0
  320. package/dist/core/registry/store.d.ts.map +1 -0
  321. package/dist/core/registry/store.js +185 -0
  322. package/dist/core/registry/store.js.map +1 -0
  323. package/dist/core/registry/types.d.ts +141 -0
  324. package/dist/core/registry/types.d.ts.map +1 -0
  325. package/dist/core/registry/types.js +30 -0
  326. package/dist/core/registry/types.js.map +1 -0
  327. package/dist/core/registry/versions.d.ts +56 -0
  328. package/dist/core/registry/versions.d.ts.map +1 -0
  329. package/dist/core/registry/versions.js +101 -0
  330. package/dist/core/registry/versions.js.map +1 -0
  331. package/dist/credentials/store.d.ts +59 -0
  332. package/dist/credentials/store.d.ts.map +1 -0
  333. package/dist/credentials/store.js +178 -0
  334. package/dist/credentials/store.js.map +1 -0
  335. package/dist/files/agent-api.d.ts +50 -0
  336. package/dist/files/agent-api.d.ts.map +1 -0
  337. package/dist/files/agent-api.js +126 -0
  338. package/dist/files/agent-api.js.map +1 -0
  339. package/dist/files/compress.d.ts +20 -0
  340. package/dist/files/compress.d.ts.map +1 -0
  341. package/dist/files/compress.js +83 -0
  342. package/dist/files/compress.js.map +1 -0
  343. package/dist/files/extract.d.ts +11 -0
  344. package/dist/files/extract.d.ts.map +1 -0
  345. package/dist/files/extract.js +33 -0
  346. package/dist/files/extract.js.map +1 -0
  347. package/dist/files/gdrive.d.ts +56 -0
  348. package/dist/files/gdrive.d.ts.map +1 -0
  349. package/dist/files/gdrive.js +246 -0
  350. package/dist/files/gdrive.js.map +1 -0
  351. package/dist/files/ingest-folder.d.ts +22 -0
  352. package/dist/files/ingest-folder.d.ts.map +1 -0
  353. package/dist/files/ingest-folder.js +71 -0
  354. package/dist/files/ingest-folder.js.map +1 -0
  355. package/dist/files/ingest.d.ts +13 -0
  356. package/dist/files/ingest.d.ts.map +1 -0
  357. package/dist/files/ingest.js +127 -0
  358. package/dist/files/ingest.js.map +1 -0
  359. package/dist/files/manager.d.ts +117 -0
  360. package/dist/files/manager.d.ts.map +1 -0
  361. package/dist/files/manager.js +306 -0
  362. package/dist/files/manager.js.map +1 -0
  363. package/dist/files/store.d.ts +41 -0
  364. package/dist/files/store.d.ts.map +1 -0
  365. package/dist/files/store.js +271 -0
  366. package/dist/files/store.js.map +1 -0
  367. package/dist/files/templates.d.ts +45 -0
  368. package/dist/files/templates.d.ts.map +1 -0
  369. package/dist/files/templates.js +179 -0
  370. package/dist/files/templates.js.map +1 -0
  371. package/dist/files/types.d.ts +115 -0
  372. package/dist/files/types.d.ts.map +1 -0
  373. package/dist/files/types.js +20 -0
  374. package/dist/files/types.js.map +1 -0
  375. package/dist/files/validate.d.ts +15 -0
  376. package/dist/files/validate.d.ts.map +1 -0
  377. package/dist/files/validate.js +213 -0
  378. package/dist/files/validate.js.map +1 -0
  379. package/dist/files/version.d.ts +31 -0
  380. package/dist/files/version.d.ts.map +1 -0
  381. package/dist/files/version.js +129 -0
  382. package/dist/files/version.js.map +1 -0
  383. package/dist/github/client.d.ts +83 -0
  384. package/dist/github/client.d.ts.map +1 -0
  385. package/dist/github/client.js +408 -0
  386. package/dist/github/client.js.map +1 -0
  387. package/dist/github/commit-analysis.d.ts +30 -0
  388. package/dist/github/commit-analysis.d.ts.map +1 -0
  389. package/dist/github/commit-analysis.js +276 -0
  390. package/dist/github/commit-analysis.js.map +1 -0
  391. package/dist/github/contributor-stats.d.ts +18 -0
  392. package/dist/github/contributor-stats.d.ts.map +1 -0
  393. package/dist/github/contributor-stats.js +119 -0
  394. package/dist/github/contributor-stats.js.map +1 -0
  395. package/dist/github/issue-sla.d.ts +25 -0
  396. package/dist/github/issue-sla.d.ts.map +1 -0
  397. package/dist/github/issue-sla.js +220 -0
  398. package/dist/github/issue-sla.js.map +1 -0
  399. package/dist/github/issue-triage.d.ts +49 -0
  400. package/dist/github/issue-triage.d.ts.map +1 -0
  401. package/dist/github/issue-triage.js +286 -0
  402. package/dist/github/issue-triage.js.map +1 -0
  403. package/dist/github/pr-readiness.d.ts +18 -0
  404. package/dist/github/pr-readiness.d.ts.map +1 -0
  405. package/dist/github/pr-readiness.js +197 -0
  406. package/dist/github/pr-readiness.js.map +1 -0
  407. package/dist/github/pr-review.d.ts +17 -0
  408. package/dist/github/pr-review.d.ts.map +1 -0
  409. package/dist/github/pr-review.js +410 -0
  410. package/dist/github/pr-review.js.map +1 -0
  411. package/dist/github/release-notes.d.ts +32 -0
  412. package/dist/github/release-notes.d.ts.map +1 -0
  413. package/dist/github/release-notes.js +227 -0
  414. package/dist/github/release-notes.js.map +1 -0
  415. package/dist/github/repo-health.d.ts +17 -0
  416. package/dist/github/repo-health.d.ts.map +1 -0
  417. package/dist/github/repo-health.js +303 -0
  418. package/dist/github/repo-health.js.map +1 -0
  419. package/dist/github/retry.d.ts +39 -0
  420. package/dist/github/retry.d.ts.map +1 -0
  421. package/dist/github/retry.js +117 -0
  422. package/dist/github/retry.js.map +1 -0
  423. package/dist/github/types.d.ts +527 -0
  424. package/dist/github/types.d.ts.map +1 -0
  425. package/dist/github/types.js +8 -0
  426. package/dist/github/types.js.map +1 -0
  427. package/dist/github/webhooks.d.ts +36 -0
  428. package/dist/github/webhooks.d.ts.map +1 -0
  429. package/dist/github/webhooks.js +153 -0
  430. package/dist/github/webhooks.js.map +1 -0
  431. package/dist/goals/loop.d.ts +27 -0
  432. package/dist/goals/loop.d.ts.map +1 -0
  433. package/dist/goals/loop.js +239 -0
  434. package/dist/goals/loop.js.map +1 -0
  435. package/dist/goals/notifications.d.ts +20 -0
  436. package/dist/goals/notifications.d.ts.map +1 -0
  437. package/dist/goals/notifications.js +101 -0
  438. package/dist/goals/notifications.js.map +1 -0
  439. package/dist/goals/timer.d.ts +21 -0
  440. package/dist/goals/timer.d.ts.map +1 -0
  441. package/dist/goals/timer.js +60 -0
  442. package/dist/goals/timer.js.map +1 -0
  443. package/dist/google/auth.d.ts +84 -0
  444. package/dist/google/auth.d.ts.map +1 -0
  445. package/dist/google/auth.js +323 -0
  446. package/dist/google/auth.js.map +1 -0
  447. package/dist/google/calendar-timer.d.ts +20 -0
  448. package/dist/google/calendar-timer.d.ts.map +1 -0
  449. package/dist/google/calendar-timer.js +91 -0
  450. package/dist/google/calendar-timer.js.map +1 -0
  451. package/dist/google/calendar.d.ts +126 -0
  452. package/dist/google/calendar.d.ts.map +1 -0
  453. package/dist/google/calendar.js +270 -0
  454. package/dist/google/calendar.js.map +1 -0
  455. package/dist/google/docs.d.ts +87 -0
  456. package/dist/google/docs.d.ts.map +1 -0
  457. package/dist/google/docs.js +309 -0
  458. package/dist/google/docs.js.map +1 -0
  459. package/dist/google/gmail-send.d.ts +58 -0
  460. package/dist/google/gmail-send.d.ts.map +1 -0
  461. package/dist/google/gmail-send.js +219 -0
  462. package/dist/google/gmail-send.js.map +1 -0
  463. package/dist/google/gmail-timer.d.ts +34 -0
  464. package/dist/google/gmail-timer.d.ts.map +1 -0
  465. package/dist/google/gmail-timer.js +223 -0
  466. package/dist/google/gmail-timer.js.map +1 -0
  467. package/dist/google/gmail.d.ts +172 -0
  468. package/dist/google/gmail.d.ts.map +1 -0
  469. package/dist/google/gmail.js +470 -0
  470. package/dist/google/gmail.js.map +1 -0
  471. package/dist/google/tasks-timer.d.ts +20 -0
  472. package/dist/google/tasks-timer.d.ts.map +1 -0
  473. package/dist/google/tasks-timer.js +107 -0
  474. package/dist/google/tasks-timer.js.map +1 -0
  475. package/dist/google/tasks.d.ts +167 -0
  476. package/dist/google/tasks.d.ts.map +1 -0
  477. package/dist/google/tasks.js +331 -0
  478. package/dist/google/tasks.js.map +1 -0
  479. package/dist/google/temporal.d.ts +76 -0
  480. package/dist/google/temporal.d.ts.map +1 -0
  481. package/dist/google/temporal.js +176 -0
  482. package/dist/google/temporal.js.map +1 -0
  483. package/dist/health/alert-defaults.d.ts +12 -0
  484. package/dist/health/alert-defaults.d.ts.map +1 -0
  485. package/dist/health/alert-defaults.js +88 -0
  486. package/dist/health/alert-defaults.js.map +1 -0
  487. package/dist/health/alert-types.d.ts +97 -0
  488. package/dist/health/alert-types.d.ts.map +1 -0
  489. package/dist/health/alert-types.js +8 -0
  490. package/dist/health/alert-types.js.map +1 -0
  491. package/dist/health/alerting.d.ts +66 -0
  492. package/dist/health/alerting.d.ts.map +1 -0
  493. package/dist/health/alerting.js +373 -0
  494. package/dist/health/alerting.js.map +1 -0
  495. package/dist/health/checker.d.ts +32 -0
  496. package/dist/health/checker.d.ts.map +1 -0
  497. package/dist/health/checker.js +138 -0
  498. package/dist/health/checker.js.map +1 -0
  499. package/dist/health/checks/openrouter.d.ts +29 -0
  500. package/dist/health/checks/openrouter.d.ts.map +1 -0
  501. package/dist/health/checks/openrouter.js +75 -0
  502. package/dist/health/checks/openrouter.js.map +1 -0
  503. package/dist/health/checks.d.ts +26 -0
  504. package/dist/health/checks.d.ts.map +1 -0
  505. package/dist/health/checks.js +122 -0
  506. package/dist/health/checks.js.map +1 -0
  507. package/dist/health/components.d.ts +38 -0
  508. package/dist/health/components.d.ts.map +1 -0
  509. package/dist/health/components.js +112 -0
  510. package/dist/health/components.js.map +1 -0
  511. package/dist/health/index.d.ts +19 -0
  512. package/dist/health/index.d.ts.map +1 -0
  513. package/dist/health/index.js +23 -0
  514. package/dist/health/index.js.map +1 -0
  515. package/dist/health/recovery.d.ts +42 -0
  516. package/dist/health/recovery.d.ts.map +1 -0
  517. package/dist/health/recovery.js +138 -0
  518. package/dist/health/recovery.js.map +1 -0
  519. package/dist/health/types.d.ts +68 -0
  520. package/dist/health/types.d.ts.map +1 -0
  521. package/dist/health/types.js +5 -0
  522. package/dist/health/types.js.map +1 -0
  523. package/dist/index.d.ts +25 -0
  524. package/dist/index.d.ts.map +1 -0
  525. package/dist/index.js +22 -0
  526. package/dist/index.js.map +1 -0
  527. package/dist/instance.d.ts +24 -0
  528. package/dist/instance.d.ts.map +1 -0
  529. package/dist/instance.js +48 -0
  530. package/dist/instance.js.map +1 -0
  531. package/dist/integrations/github.d.ts +83 -0
  532. package/dist/integrations/github.d.ts.map +1 -0
  533. package/dist/integrations/github.js +331 -0
  534. package/dist/integrations/github.js.map +1 -0
  535. package/dist/integrations/google-tasks.d.ts +232 -0
  536. package/dist/integrations/google-tasks.d.ts.map +1 -0
  537. package/dist/integrations/google-tasks.js +432 -0
  538. package/dist/integrations/google-tasks.js.map +1 -0
  539. package/dist/learning/extractor.d.ts +28 -0
  540. package/dist/learning/extractor.d.ts.map +1 -0
  541. package/dist/learning/extractor.js +135 -0
  542. package/dist/learning/extractor.js.map +1 -0
  543. package/dist/lib/BasePlugin.d.ts +58 -0
  544. package/dist/lib/BasePlugin.d.ts.map +1 -0
  545. package/dist/lib/BasePlugin.js +181 -0
  546. package/dist/lib/BasePlugin.js.map +1 -0
  547. package/dist/lib/PluginRegistry.d.ts +56 -0
  548. package/dist/lib/PluginRegistry.d.ts.map +1 -0
  549. package/dist/lib/PluginRegistry.js +172 -0
  550. package/dist/lib/PluginRegistry.js.map +1 -0
  551. package/dist/lib/brain-io.d.ts +60 -0
  552. package/dist/lib/brain-io.d.ts.map +1 -0
  553. package/dist/lib/brain-io.js +180 -0
  554. package/dist/lib/brain-io.js.map +1 -0
  555. package/dist/lib/encryption-config.d.ts +16 -0
  556. package/dist/lib/encryption-config.d.ts.map +1 -0
  557. package/dist/lib/encryption-config.js +40 -0
  558. package/dist/lib/encryption-config.js.map +1 -0
  559. package/dist/lib/encryption.d.ts +19 -0
  560. package/dist/lib/encryption.d.ts.map +1 -0
  561. package/dist/lib/encryption.js +65 -0
  562. package/dist/lib/encryption.js.map +1 -0
  563. package/dist/lib/key-store.d.ts +24 -0
  564. package/dist/lib/key-store.d.ts.map +1 -0
  565. package/dist/lib/key-store.js +38 -0
  566. package/dist/lib/key-store.js.map +1 -0
  567. package/dist/lib/schema-migration.d.ts +34 -0
  568. package/dist/lib/schema-migration.d.ts.map +1 -0
  569. package/dist/lib/schema-migration.js +77 -0
  570. package/dist/lib/schema-migration.js.map +1 -0
  571. package/dist/library/brain-shadow.d.ts +10 -0
  572. package/dist/library/brain-shadow.d.ts.map +1 -0
  573. package/dist/library/brain-shadow.js +158 -0
  574. package/dist/library/brain-shadow.js.map +1 -0
  575. package/dist/library/index.d.ts +7 -0
  576. package/dist/library/index.d.ts.map +1 -0
  577. package/dist/library/index.js +6 -0
  578. package/dist/library/index.js.map +1 -0
  579. package/dist/library/routes.d.ts +7 -0
  580. package/dist/library/routes.d.ts.map +1 -0
  581. package/dist/library/routes.js +473 -0
  582. package/dist/library/routes.js.map +1 -0
  583. package/dist/library/store.d.ts +54 -0
  584. package/dist/library/store.d.ts.map +1 -0
  585. package/dist/library/store.js +403 -0
  586. package/dist/library/store.js.map +1 -0
  587. package/dist/library/types.d.ts +56 -0
  588. package/dist/library/types.d.ts.map +1 -0
  589. package/dist/library/types.js +12 -0
  590. package/dist/library/types.js.map +1 -0
  591. package/dist/llm/cache.d.ts +42 -0
  592. package/dist/llm/cache.d.ts.map +1 -0
  593. package/dist/llm/cache.js +104 -0
  594. package/dist/llm/cache.js.map +1 -0
  595. package/dist/llm/complete.d.ts +24 -0
  596. package/dist/llm/complete.d.ts.map +1 -0
  597. package/dist/llm/complete.js +56 -0
  598. package/dist/llm/complete.js.map +1 -0
  599. package/dist/llm/errors.d.ts +28 -0
  600. package/dist/llm/errors.d.ts.map +1 -0
  601. package/dist/llm/errors.js +82 -0
  602. package/dist/llm/errors.js.map +1 -0
  603. package/dist/llm/ollama.d.ts +21 -0
  604. package/dist/llm/ollama.d.ts.map +1 -0
  605. package/dist/llm/ollama.js +116 -0
  606. package/dist/llm/ollama.js.map +1 -0
  607. package/dist/llm/openrouter.d.ts +13 -0
  608. package/dist/llm/openrouter.d.ts.map +1 -0
  609. package/dist/llm/openrouter.js +105 -0
  610. package/dist/llm/openrouter.js.map +1 -0
  611. package/dist/llm/providers/anthropic.d.ts +8 -0
  612. package/dist/llm/providers/anthropic.d.ts.map +1 -0
  613. package/dist/llm/providers/anthropic.js +189 -0
  614. package/dist/llm/providers/anthropic.js.map +1 -0
  615. package/dist/llm/providers/index.d.ts +20 -0
  616. package/dist/llm/providers/index.d.ts.map +1 -0
  617. package/dist/llm/providers/index.js +47 -0
  618. package/dist/llm/providers/index.js.map +1 -0
  619. package/dist/llm/providers/ollama.d.ts +13 -0
  620. package/dist/llm/providers/ollama.d.ts.map +1 -0
  621. package/dist/llm/providers/ollama.js +188 -0
  622. package/dist/llm/providers/ollama.js.map +1 -0
  623. package/dist/llm/providers/openai.d.ts +8 -0
  624. package/dist/llm/providers/openai.d.ts.map +1 -0
  625. package/dist/llm/providers/openai.js +144 -0
  626. package/dist/llm/providers/openai.js.map +1 -0
  627. package/dist/llm/providers/openrouter.d.ts +7 -0
  628. package/dist/llm/providers/openrouter.d.ts.map +1 -0
  629. package/dist/llm/providers/openrouter.js +158 -0
  630. package/dist/llm/providers/openrouter.js.map +1 -0
  631. package/dist/llm/providers/types.d.ts +29 -0
  632. package/dist/llm/providers/types.d.ts.map +1 -0
  633. package/dist/llm/providers/types.js +6 -0
  634. package/dist/llm/providers/types.js.map +1 -0
  635. package/dist/llm/retry.d.ts +29 -0
  636. package/dist/llm/retry.d.ts.map +1 -0
  637. package/dist/llm/retry.js +139 -0
  638. package/dist/llm/retry.js.map +1 -0
  639. package/dist/memory/file-backed.d.ts +36 -0
  640. package/dist/memory/file-backed.d.ts.map +1 -0
  641. package/dist/memory/file-backed.js +178 -0
  642. package/dist/memory/file-backed.js.map +1 -0
  643. package/dist/memory/index.d.ts +7 -0
  644. package/dist/memory/index.d.ts.map +1 -0
  645. package/dist/memory/index.js +6 -0
  646. package/dist/memory/index.js.map +1 -0
  647. package/dist/memory/long-term.d.ts +38 -0
  648. package/dist/memory/long-term.d.ts.map +1 -0
  649. package/dist/memory/long-term.js +58 -0
  650. package/dist/memory/long-term.js.map +1 -0
  651. package/dist/memory/vector-index.d.ts +55 -0
  652. package/dist/memory/vector-index.d.ts.map +1 -0
  653. package/dist/memory/vector-index.js +207 -0
  654. package/dist/memory/vector-index.js.map +1 -0
  655. package/dist/memory/visual.d.ts +53 -0
  656. package/dist/memory/visual.d.ts.map +1 -0
  657. package/dist/memory/visual.js +218 -0
  658. package/dist/memory/visual.js.map +1 -0
  659. package/dist/memory/working.d.ts +12 -0
  660. package/dist/memory/working.d.ts.map +1 -0
  661. package/dist/memory/working.js +34 -0
  662. package/dist/memory/working.js.map +1 -0
  663. package/dist/metrics/aggregator.d.ts +58 -0
  664. package/dist/metrics/aggregator.d.ts.map +1 -0
  665. package/dist/metrics/aggregator.js +253 -0
  666. package/dist/metrics/aggregator.js.map +1 -0
  667. package/dist/metrics/collector.d.ts +26 -0
  668. package/dist/metrics/collector.d.ts.map +1 -0
  669. package/dist/metrics/collector.js +346 -0
  670. package/dist/metrics/collector.js.map +1 -0
  671. package/dist/metrics/firewall-metrics.d.ts +95 -0
  672. package/dist/metrics/firewall-metrics.d.ts.map +1 -0
  673. package/dist/metrics/firewall-metrics.js +261 -0
  674. package/dist/metrics/firewall-metrics.js.map +1 -0
  675. package/dist/metrics/index.d.ts +20 -0
  676. package/dist/metrics/index.d.ts.map +1 -0
  677. package/dist/metrics/index.js +23 -0
  678. package/dist/metrics/index.js.map +1 -0
  679. package/dist/metrics/instruments.d.ts +89 -0
  680. package/dist/metrics/instruments.d.ts.map +1 -0
  681. package/dist/metrics/instruments.js +172 -0
  682. package/dist/metrics/instruments.js.map +1 -0
  683. package/dist/metrics/middleware.d.ts +12 -0
  684. package/dist/metrics/middleware.d.ts.map +1 -0
  685. package/dist/metrics/middleware.js +47 -0
  686. package/dist/metrics/middleware.js.map +1 -0
  687. package/dist/metrics/prometheus.d.ts +39 -0
  688. package/dist/metrics/prometheus.d.ts.map +1 -0
  689. package/dist/metrics/prometheus.js +115 -0
  690. package/dist/metrics/prometheus.js.map +1 -0
  691. package/dist/metrics/registry.d.ts +58 -0
  692. package/dist/metrics/registry.d.ts.map +1 -0
  693. package/dist/metrics/registry.js +145 -0
  694. package/dist/metrics/registry.js.map +1 -0
  695. package/dist/metrics/reporter.d.ts +21 -0
  696. package/dist/metrics/reporter.d.ts.map +1 -0
  697. package/dist/metrics/reporter.js +207 -0
  698. package/dist/metrics/reporter.js.map +1 -0
  699. package/dist/metrics/store.d.ts +47 -0
  700. package/dist/metrics/store.d.ts.map +1 -0
  701. package/dist/metrics/store.js +209 -0
  702. package/dist/metrics/store.js.map +1 -0
  703. package/dist/metrics/system.d.ts +20 -0
  704. package/dist/metrics/system.d.ts.map +1 -0
  705. package/dist/metrics/system.js +109 -0
  706. package/dist/metrics/system.js.map +1 -0
  707. package/dist/metrics/types.d.ts +101 -0
  708. package/dist/metrics/types.d.ts.map +1 -0
  709. package/dist/metrics/types.js +6 -0
  710. package/dist/metrics/types.js.map +1 -0
  711. package/dist/modules/index.d.ts +6 -0
  712. package/dist/modules/index.d.ts.map +1 -0
  713. package/dist/modules/index.js +6 -0
  714. package/dist/modules/index.js.map +1 -0
  715. package/dist/modules/registry.d.ts +36 -0
  716. package/dist/modules/registry.d.ts.map +1 -0
  717. package/dist/modules/registry.js +155 -0
  718. package/dist/modules/registry.js.map +1 -0
  719. package/dist/modules/types.d.ts +37 -0
  720. package/dist/modules/types.d.ts.map +1 -0
  721. package/dist/modules/types.js +9 -0
  722. package/dist/modules/types.js.map +1 -0
  723. package/dist/notifications/channel.d.ts +25 -0
  724. package/dist/notifications/channel.d.ts.map +1 -0
  725. package/dist/notifications/channel.js +83 -0
  726. package/dist/notifications/channel.js.map +1 -0
  727. package/dist/notifications/email.d.ts +27 -0
  728. package/dist/notifications/email.d.ts.map +1 -0
  729. package/dist/notifications/email.js +72 -0
  730. package/dist/notifications/email.js.map +1 -0
  731. package/dist/notifications/index.d.ts +16 -0
  732. package/dist/notifications/index.d.ts.map +1 -0
  733. package/dist/notifications/index.js +12 -0
  734. package/dist/notifications/index.js.map +1 -0
  735. package/dist/notifications/phone.d.ts +16 -0
  736. package/dist/notifications/phone.d.ts.map +1 -0
  737. package/dist/notifications/phone.js +48 -0
  738. package/dist/notifications/phone.js.map +1 -0
  739. package/dist/notifications/sms.d.ts +26 -0
  740. package/dist/notifications/sms.d.ts.map +1 -0
  741. package/dist/notifications/sms.js +65 -0
  742. package/dist/notifications/sms.js.map +1 -0
  743. package/dist/notifications/webhook.d.ts +28 -0
  744. package/dist/notifications/webhook.d.ts.map +1 -0
  745. package/dist/notifications/webhook.js +65 -0
  746. package/dist/notifications/webhook.js.map +1 -0
  747. package/dist/openloop/foldback.d.ts +24 -0
  748. package/dist/openloop/foldback.d.ts.map +1 -0
  749. package/dist/openloop/foldback.js +127 -0
  750. package/dist/openloop/foldback.js.map +1 -0
  751. package/dist/openloop/index.d.ts +11 -0
  752. package/dist/openloop/index.d.ts.map +1 -0
  753. package/dist/openloop/index.js +9 -0
  754. package/dist/openloop/index.js.map +1 -0
  755. package/dist/openloop/lifecycle.d.ts +16 -0
  756. package/dist/openloop/lifecycle.d.ts.map +1 -0
  757. package/dist/openloop/lifecycle.js +304 -0
  758. package/dist/openloop/lifecycle.js.map +1 -0
  759. package/dist/openloop/resolution-scanner.d.ts +17 -0
  760. package/dist/openloop/resolution-scanner.d.ts.map +1 -0
  761. package/dist/openloop/resolution-scanner.js +551 -0
  762. package/dist/openloop/resolution-scanner.js.map +1 -0
  763. package/dist/openloop/scanner.d.ts +28 -0
  764. package/dist/openloop/scanner.d.ts.map +1 -0
  765. package/dist/openloop/scanner.js +587 -0
  766. package/dist/openloop/scanner.js.map +1 -0
  767. package/dist/openloop/store.d.ts +41 -0
  768. package/dist/openloop/store.d.ts.map +1 -0
  769. package/dist/openloop/store.js +154 -0
  770. package/dist/openloop/store.js.map +1 -0
  771. package/dist/openloop/types.d.ts +94 -0
  772. package/dist/openloop/types.d.ts.map +1 -0
  773. package/dist/openloop/types.js +6 -0
  774. package/dist/openloop/types.js.map +1 -0
  775. package/dist/plugins/google-tasks/index.d.ts +55 -0
  776. package/dist/plugins/google-tasks/index.d.ts.map +1 -0
  777. package/dist/plugins/google-tasks/index.js +135 -0
  778. package/dist/plugins/google-tasks/index.js.map +1 -0
  779. package/dist/pulse/activation-event.d.ts +66 -0
  780. package/dist/pulse/activation-event.d.ts.map +1 -0
  781. package/dist/pulse/activation-event.js +139 -0
  782. package/dist/pulse/activation-event.js.map +1 -0
  783. package/dist/pulse/activation-log.d.ts +37 -0
  784. package/dist/pulse/activation-log.d.ts.map +1 -0
  785. package/dist/pulse/activation-log.js +101 -0
  786. package/dist/pulse/activation-log.js.map +1 -0
  787. package/dist/pulse/index.d.ts +11 -0
  788. package/dist/pulse/index.d.ts.map +1 -0
  789. package/dist/pulse/index.js +13 -0
  790. package/dist/pulse/index.js.map +1 -0
  791. package/dist/pulse/pressure.d.ts +69 -0
  792. package/dist/pulse/pressure.d.ts.map +1 -0
  793. package/dist/pulse/pressure.js +304 -0
  794. package/dist/pulse/pressure.js.map +1 -0
  795. package/dist/pulse/types.d.ts +89 -0
  796. package/dist/pulse/types.d.ts.map +1 -0
  797. package/dist/pulse/types.js +6 -0
  798. package/dist/pulse/types.js.map +1 -0
  799. package/dist/queue/grooming.d.ts +16 -0
  800. package/dist/queue/grooming.d.ts.map +1 -0
  801. package/dist/queue/grooming.js +269 -0
  802. package/dist/queue/grooming.js.map +1 -0
  803. package/dist/queue/provider.d.ts +50 -0
  804. package/dist/queue/provider.d.ts.map +1 -0
  805. package/dist/queue/provider.js +131 -0
  806. package/dist/queue/provider.js.map +1 -0
  807. package/dist/queue/store.d.ts +97 -0
  808. package/dist/queue/store.d.ts.map +1 -0
  809. package/dist/queue/store.js +448 -0
  810. package/dist/queue/store.js.map +1 -0
  811. package/dist/queue/types.d.ts +47 -0
  812. package/dist/queue/types.d.ts.map +1 -0
  813. package/dist/queue/types.js +22 -0
  814. package/dist/queue/types.js.map +1 -0
  815. package/dist/rate-limit.d.ts +26 -0
  816. package/dist/rate-limit.d.ts.map +1 -0
  817. package/dist/rate-limit.js +74 -0
  818. package/dist/rate-limit.js.map +1 -0
  819. package/dist/registry/discovery.d.ts +30 -0
  820. package/dist/registry/discovery.d.ts.map +1 -0
  821. package/dist/registry/discovery.js +171 -0
  822. package/dist/registry/discovery.js.map +1 -0
  823. package/dist/registry/index.d.ts +14 -0
  824. package/dist/registry/index.d.ts.map +1 -0
  825. package/dist/registry/index.js +18 -0
  826. package/dist/registry/index.js.map +1 -0
  827. package/dist/registry/installer.d.ts +45 -0
  828. package/dist/registry/installer.d.ts.map +1 -0
  829. package/dist/registry/installer.js +175 -0
  830. package/dist/registry/installer.js.map +1 -0
  831. package/dist/registry/registry.d.ts +70 -0
  832. package/dist/registry/registry.d.ts.map +1 -0
  833. package/dist/registry/registry.js +153 -0
  834. package/dist/registry/registry.js.map +1 -0
  835. package/dist/registry/store.d.ts +69 -0
  836. package/dist/registry/store.d.ts.map +1 -0
  837. package/dist/registry/store.js +242 -0
  838. package/dist/registry/store.js.map +1 -0
  839. package/dist/registry/types.d.ts +116 -0
  840. package/dist/registry/types.d.ts.map +1 -0
  841. package/dist/registry/types.js +9 -0
  842. package/dist/registry/types.js.map +1 -0
  843. package/dist/registry/validator.d.ts +24 -0
  844. package/dist/registry/validator.d.ts.map +1 -0
  845. package/dist/registry/validator.js +203 -0
  846. package/dist/registry/validator.js.map +1 -0
  847. package/dist/scheduling/index.d.ts +4 -0
  848. package/dist/scheduling/index.d.ts.map +1 -0
  849. package/dist/scheduling/index.js +3 -0
  850. package/dist/scheduling/index.js.map +1 -0
  851. package/dist/scheduling/store.d.ts +41 -0
  852. package/dist/scheduling/store.d.ts.map +1 -0
  853. package/dist/scheduling/store.js +237 -0
  854. package/dist/scheduling/store.js.map +1 -0
  855. package/dist/scheduling/timer.d.ts +25 -0
  856. package/dist/scheduling/timer.d.ts.map +1 -0
  857. package/dist/scheduling/timer.js +118 -0
  858. package/dist/scheduling/timer.js.map +1 -0
  859. package/dist/scheduling/types.d.ts +43 -0
  860. package/dist/scheduling/types.d.ts.map +1 -0
  861. package/dist/scheduling/types.js +5 -0
  862. package/dist/scheduling/types.js.map +1 -0
  863. package/dist/search/brain-docs.d.ts +20 -0
  864. package/dist/search/brain-docs.d.ts.map +1 -0
  865. package/dist/search/brain-docs.js +103 -0
  866. package/dist/search/brain-docs.js.map +1 -0
  867. package/dist/search/browse.d.ts +45 -0
  868. package/dist/search/browse.d.ts.map +1 -0
  869. package/dist/search/browse.js +225 -0
  870. package/dist/search/browse.js.map +1 -0
  871. package/dist/search/classify.d.ts +23 -0
  872. package/dist/search/classify.d.ts.map +1 -0
  873. package/dist/search/classify.js +132 -0
  874. package/dist/search/classify.js.map +1 -0
  875. package/dist/search/client.d.ts +32 -0
  876. package/dist/search/client.d.ts.map +1 -0
  877. package/dist/search/client.js +72 -0
  878. package/dist/search/client.js.map +1 -0
  879. package/dist/search/perplexity.d.ts +13 -0
  880. package/dist/search/perplexity.d.ts.map +1 -0
  881. package/dist/search/perplexity.js +41 -0
  882. package/dist/search/perplexity.js.map +1 -0
  883. package/dist/search/sidecar.d.ts +20 -0
  884. package/dist/search/sidecar.d.ts.map +1 -0
  885. package/dist/search/sidecar.js +103 -0
  886. package/dist/search/sidecar.js.map +1 -0
  887. package/dist/server.d.ts +8 -0
  888. package/dist/server.d.ts.map +1 -0
  889. package/dist/server.js +4851 -0
  890. package/dist/server.js.map +1 -0
  891. package/dist/services/backlogReview.d.ts +66 -0
  892. package/dist/services/backlogReview.d.ts.map +1 -0
  893. package/dist/services/backlogReview.js +285 -0
  894. package/dist/services/backlogReview.js.map +1 -0
  895. package/dist/services/backup.d.ts +43 -0
  896. package/dist/services/backup.d.ts.map +1 -0
  897. package/dist/services/backup.js +334 -0
  898. package/dist/services/backup.js.map +1 -0
  899. package/dist/services/credit-monitor.d.ts +40 -0
  900. package/dist/services/credit-monitor.d.ts.map +1 -0
  901. package/dist/services/credit-monitor.js +147 -0
  902. package/dist/services/credit-monitor.js.map +1 -0
  903. package/dist/services/morningBriefing.d.ts +125 -0
  904. package/dist/services/morningBriefing.d.ts.map +1 -0
  905. package/dist/services/morningBriefing.js +660 -0
  906. package/dist/services/morningBriefing.js.map +1 -0
  907. package/dist/services/routine-patterns.d.ts +21 -0
  908. package/dist/services/routine-patterns.d.ts.map +1 -0
  909. package/dist/services/routine-patterns.js +46 -0
  910. package/dist/services/routine-patterns.js.map +1 -0
  911. package/dist/services/traceInsights.d.ts +53 -0
  912. package/dist/services/traceInsights.d.ts.map +1 -0
  913. package/dist/services/traceInsights.js +762 -0
  914. package/dist/services/traceInsights.js.map +1 -0
  915. package/dist/services/training.d.ts +63 -0
  916. package/dist/services/training.d.ts.map +1 -0
  917. package/dist/services/training.js +697 -0
  918. package/dist/services/training.js.map +1 -0
  919. package/dist/services/whatsapp.d.ts +45 -0
  920. package/dist/services/whatsapp.d.ts.map +1 -0
  921. package/dist/services/whatsapp.js +194 -0
  922. package/dist/services/whatsapp.js.map +1 -0
  923. package/dist/sessions/store.d.ts +21 -0
  924. package/dist/sessions/store.d.ts.map +1 -0
  925. package/dist/sessions/store.js +47 -0
  926. package/dist/sessions/store.js.map +1 -0
  927. package/dist/settings.d.ts +111 -0
  928. package/dist/settings.d.ts.map +1 -0
  929. package/dist/settings.js +256 -0
  930. package/dist/settings.js.map +1 -0
  931. package/dist/skills/index.d.ts +10 -0
  932. package/dist/skills/index.d.ts.map +1 -0
  933. package/dist/skills/index.js +11 -0
  934. package/dist/skills/index.js.map +1 -0
  935. package/dist/skills/loader.d.ts +22 -0
  936. package/dist/skills/loader.d.ts.map +1 -0
  937. package/dist/skills/loader.js +65 -0
  938. package/dist/skills/loader.js.map +1 -0
  939. package/dist/skills/registry.d.ts +161 -0
  940. package/dist/skills/registry.d.ts.map +1 -0
  941. package/dist/skills/registry.js +664 -0
  942. package/dist/skills/registry.js.map +1 -0
  943. package/dist/skills/types.d.ts +83 -0
  944. package/dist/skills/types.d.ts.map +1 -0
  945. package/dist/skills/types.js +31 -0
  946. package/dist/skills/types.js.map +1 -0
  947. package/dist/skills/validator.d.ts +36 -0
  948. package/dist/skills/validator.d.ts.map +1 -0
  949. package/dist/skills/validator.js +114 -0
  950. package/dist/skills/validator.js.map +1 -0
  951. package/dist/slack/channels.d.ts +102 -0
  952. package/dist/slack/channels.d.ts.map +1 -0
  953. package/dist/slack/channels.js +277 -0
  954. package/dist/slack/channels.js.map +1 -0
  955. package/dist/slack/client.d.ts +151 -0
  956. package/dist/slack/client.d.ts.map +1 -0
  957. package/dist/slack/client.js +468 -0
  958. package/dist/slack/client.js.map +1 -0
  959. package/dist/slack/retry.d.ts +36 -0
  960. package/dist/slack/retry.d.ts.map +1 -0
  961. package/dist/slack/retry.js +100 -0
  962. package/dist/slack/retry.js.map +1 -0
  963. package/dist/slack/types.d.ts +271 -0
  964. package/dist/slack/types.d.ts.map +1 -0
  965. package/dist/slack/types.js +52 -0
  966. package/dist/slack/types.js.map +1 -0
  967. package/dist/slack/webhooks.d.ts +55 -0
  968. package/dist/slack/webhooks.d.ts.map +1 -0
  969. package/dist/slack/webhooks.js +285 -0
  970. package/dist/slack/webhooks.js.map +1 -0
  971. package/dist/stt/client.d.ts +18 -0
  972. package/dist/stt/client.d.ts.map +1 -0
  973. package/dist/stt/client.js +66 -0
  974. package/dist/stt/client.js.map +1 -0
  975. package/dist/stt/sidecar.d.ts +16 -0
  976. package/dist/stt/sidecar.d.ts.map +1 -0
  977. package/dist/stt/sidecar.js +115 -0
  978. package/dist/stt/sidecar.js.map +1 -0
  979. package/dist/tracing/bridge.d.ts +14 -0
  980. package/dist/tracing/bridge.d.ts.map +1 -0
  981. package/dist/tracing/bridge.js +70 -0
  982. package/dist/tracing/bridge.js.map +1 -0
  983. package/dist/tracing/correlation.d.ts +34 -0
  984. package/dist/tracing/correlation.d.ts.map +1 -0
  985. package/dist/tracing/correlation.js +49 -0
  986. package/dist/tracing/correlation.js.map +1 -0
  987. package/dist/tracing/index.d.ts +15 -0
  988. package/dist/tracing/index.d.ts.map +1 -0
  989. package/dist/tracing/index.js +18 -0
  990. package/dist/tracing/index.js.map +1 -0
  991. package/dist/tracing/init.d.ts +42 -0
  992. package/dist/tracing/init.d.ts.map +1 -0
  993. package/dist/tracing/init.js +81 -0
  994. package/dist/tracing/init.js.map +1 -0
  995. package/dist/tracing/instrument.d.ts +39 -0
  996. package/dist/tracing/instrument.d.ts.map +1 -0
  997. package/dist/tracing/instrument.js +145 -0
  998. package/dist/tracing/instrument.js.map +1 -0
  999. package/dist/tracing/middleware.d.ts +18 -0
  1000. package/dist/tracing/middleware.d.ts.map +1 -0
  1001. package/dist/tracing/middleware.js +69 -0
  1002. package/dist/tracing/middleware.js.map +1 -0
  1003. package/dist/tracing/tracer.d.ts +105 -0
  1004. package/dist/tracing/tracer.d.ts.map +1 -0
  1005. package/dist/tracing/tracer.js +327 -0
  1006. package/dist/tracing/tracer.js.map +1 -0
  1007. package/dist/tts/client.d.ts +18 -0
  1008. package/dist/tts/client.d.ts.map +1 -0
  1009. package/dist/tts/client.js +48 -0
  1010. package/dist/tts/client.js.map +1 -0
  1011. package/dist/tts/sidecar.d.ts +16 -0
  1012. package/dist/tts/sidecar.d.ts.map +1 -0
  1013. package/dist/tts/sidecar.js +148 -0
  1014. package/dist/tts/sidecar.js.map +1 -0
  1015. package/dist/twilio/call.d.ts +22 -0
  1016. package/dist/twilio/call.d.ts.map +1 -0
  1017. package/dist/twilio/call.js +79 -0
  1018. package/dist/twilio/call.js.map +1 -0
  1019. package/dist/types/plugin.d.ts +342 -0
  1020. package/dist/types/plugin.d.ts.map +1 -0
  1021. package/dist/types/plugin.js +10 -0
  1022. package/dist/types/plugin.js.map +1 -0
  1023. package/dist/types.d.ts +97 -0
  1024. package/dist/types.d.ts.map +1 -0
  1025. package/dist/types.js +5 -0
  1026. package/dist/types.js.map +1 -0
  1027. package/dist/utils/logger.d.ts +53 -0
  1028. package/dist/utils/logger.d.ts.map +1 -0
  1029. package/dist/utils/logger.js +169 -0
  1030. package/dist/utils/logger.js.map +1 -0
  1031. package/dist/vault/matcher.d.ts +39 -0
  1032. package/dist/vault/matcher.d.ts.map +1 -0
  1033. package/dist/vault/matcher.js +197 -0
  1034. package/dist/vault/matcher.js.map +1 -0
  1035. package/dist/vault/personal.d.ts +60 -0
  1036. package/dist/vault/personal.d.ts.map +1 -0
  1037. package/dist/vault/personal.js +162 -0
  1038. package/dist/vault/personal.js.map +1 -0
  1039. package/dist/vault/store.d.ts +39 -0
  1040. package/dist/vault/store.d.ts.map +1 -0
  1041. package/dist/vault/store.js +111 -0
  1042. package/dist/vault/store.js.map +1 -0
  1043. package/dist/webhooks/config.d.ts +64 -0
  1044. package/dist/webhooks/config.d.ts.map +1 -0
  1045. package/dist/webhooks/config.js +214 -0
  1046. package/dist/webhooks/config.js.map +1 -0
  1047. package/dist/webhooks/event-log.d.ts +90 -0
  1048. package/dist/webhooks/event-log.d.ts.map +1 -0
  1049. package/dist/webhooks/event-log.js +132 -0
  1050. package/dist/webhooks/event-log.js.map +1 -0
  1051. package/dist/webhooks/handler.d.ts +92 -0
  1052. package/dist/webhooks/handler.d.ts.map +1 -0
  1053. package/dist/webhooks/handler.js +103 -0
  1054. package/dist/webhooks/handler.js.map +1 -0
  1055. package/dist/webhooks/handlers.d.ts +100 -0
  1056. package/dist/webhooks/handlers.d.ts.map +1 -0
  1057. package/dist/webhooks/handlers.js +178 -0
  1058. package/dist/webhooks/handlers.js.map +1 -0
  1059. package/dist/webhooks/index.d.ts +29 -0
  1060. package/dist/webhooks/index.d.ts.map +1 -0
  1061. package/dist/webhooks/index.js +33 -0
  1062. package/dist/webhooks/index.js.map +1 -0
  1063. package/dist/webhooks/mount.d.ts +77 -0
  1064. package/dist/webhooks/mount.d.ts.map +1 -0
  1065. package/dist/webhooks/mount.js +400 -0
  1066. package/dist/webhooks/mount.js.map +1 -0
  1067. package/dist/webhooks/registry.d.ts +52 -0
  1068. package/dist/webhooks/registry.d.ts.map +1 -0
  1069. package/dist/webhooks/registry.js +143 -0
  1070. package/dist/webhooks/registry.js.map +1 -0
  1071. package/dist/webhooks/relay.d.ts +25 -0
  1072. package/dist/webhooks/relay.d.ts.map +1 -0
  1073. package/dist/webhooks/relay.js +53 -0
  1074. package/dist/webhooks/relay.js.map +1 -0
  1075. package/dist/webhooks/retry.d.ts +92 -0
  1076. package/dist/webhooks/retry.d.ts.map +1 -0
  1077. package/dist/webhooks/retry.js +270 -0
  1078. package/dist/webhooks/retry.js.map +1 -0
  1079. package/dist/webhooks/router.d.ts +94 -0
  1080. package/dist/webhooks/router.d.ts.map +1 -0
  1081. package/dist/webhooks/router.js +290 -0
  1082. package/dist/webhooks/router.js.map +1 -0
  1083. package/dist/webhooks/twilio.d.ts +63 -0
  1084. package/dist/webhooks/twilio.d.ts.map +1 -0
  1085. package/dist/webhooks/twilio.js +129 -0
  1086. package/dist/webhooks/twilio.js.map +1 -0
  1087. package/dist/webhooks/types.d.ts +142 -0
  1088. package/dist/webhooks/types.d.ts.map +1 -0
  1089. package/dist/webhooks/types.js +8 -0
  1090. package/dist/webhooks/types.js.map +1 -0
  1091. package/dist/webhooks/verify.d.ts +51 -0
  1092. package/dist/webhooks/verify.d.ts.map +1 -0
  1093. package/dist/webhooks/verify.js +98 -0
  1094. package/dist/webhooks/verify.js.map +1 -0
  1095. package/package.json +70 -0
  1096. package/public/board.html +1316 -0
  1097. package/public/browser.html +600 -0
  1098. package/public/help.html +655 -0
  1099. package/public/index.html +4689 -0
  1100. package/public/library.html +3642 -0
  1101. package/public/observatory.html +1693 -0
  1102. package/public/ops.html +1129 -0
  1103. package/public/share-modal.js +211 -0
  1104. package/skills/README.md +34 -0
  1105. package/skills/core-architecture.md +33 -0
  1106. package/skills/form-fill.md +98 -0
  1107. package/skills/form-review.md +110 -0
  1108. package/skills/form-scout.md +94 -0
  1109. package/skills/log-decision.md +27 -0
  1110. package/skills/onboard.md +98 -0
  1111. package/skills/voice-guide.md +22 -0
  1112. package/skills/write-blog.md +43 -0
@@ -0,0 +1,975 @@
1
+ import { spawn } from "node:child_process";
2
+ import { writeFileSync, mkdirSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { writeTask, updateTask, readTask, readTaskOutput, listTasks, LOGS_DIR } from "./store.js";
5
+ import { pushNotification } from "../goals/notifications.js";
6
+ import { logActivity } from "../activity/log.js";
7
+ import { rememberTaskOutcome, recordScar } from "./memory.js";
8
+ import { makeCall } from "../twilio/call.js";
9
+ import { attemptRecovery, recordRecoveryFailure } from "./recover.js";
10
+ import { TaskCooldownManager } from "./cooldown.js";
11
+ import { triageAgentOutput } from "./triage.js";
12
+ import { releaseLocks } from "./locks.js";
13
+ import { recordAgentSpawn, recordAgentCompletion } from "../metrics/collector.js";
14
+ import { recordSpawnRateBlock, recordBridgeReport as recordBridgeReportMetric } from "../metrics/firewall-metrics.js";
15
+ import { traceAgentSpawn } from "../tracing/instrument.js";
16
+ import { getCorrelationId } from "../tracing/correlation.js";
17
+ import { completeChat } from "../llm/complete.js";
18
+ import { resolveProvider, resolveUtilityModel } from "../settings.js";
19
+ import { createLogger } from "../utils/logger.js";
20
+ import { resolveEnv, getInstanceName, getInstanceNameLower, getAlertEmailFrom } from "../instance.js";
21
+ import { getSkillRegistry } from "../skills/registry.js";
22
+ import { getBoardProvider } from "../board/provider.js";
23
+ const log = createLogger("agent-spawn");
24
+ /**
25
+ * Update a board task's state/assignee. Best-effort — failures are logged, not thrown.
26
+ * Used to move board items through in_progress → done/todo as agents work.
27
+ * Exported so the monitor can also update board state on recovered completions.
28
+ */
29
+ export async function updateBoardTaskState(boardTaskId, changes) {
30
+ try {
31
+ const bp = getBoardProvider();
32
+ const store = bp?.getStore?.();
33
+ if (store) {
34
+ await store.update(boardTaskId, changes);
35
+ log.debug(`Board task ${boardTaskId} updated: ${JSON.stringify(changes)}`);
36
+ }
37
+ }
38
+ catch (err) {
39
+ log.warn(`Failed to update board task ${boardTaskId}: ${err instanceof Error ? err.message : String(err)}`);
40
+ }
41
+ }
42
+ /** Track recent failures — email first, phone only as last resort. */
43
+ const recentFailures = [];
44
+ const FAILURE_WINDOW_MS = 5 * 60 * 1000; // 5 minutes
45
+ const EMAIL_THRESHOLD = 2; // 2+ failures in window → email
46
+ const CALL_THRESHOLD = 5; // 5+ failures in window → phone (last resort)
47
+ let lastEmailTime = 0;
48
+ let lastCallTime = 0;
49
+ const EMAIL_COOLDOWN_MS = 10 * 60 * 1000; // Don't email more than once per 10 min
50
+ const CALL_COOLDOWN_MS = 30 * 60 * 1000; // Don't call more than once per 30 min
51
+ /**
52
+ * Global spawn rate limiter — prevents burst-spawning agents.
53
+ * Tracks timestamps of recent spawns and enforces minimum spacing.
54
+ */
55
+ const recentSpawnTimestamps = [];
56
+ const SPAWN_RATE_WINDOW_MS = 60_000; // 1 minute window
57
+ const MAX_SPAWNS_PER_WINDOW = 10; // Max 10 spawns per minute
58
+ function isSpawnRateLimited() {
59
+ const now = Date.now();
60
+ // Prune old entries
61
+ while (recentSpawnTimestamps.length > 0 && recentSpawnTimestamps[0] < now - SPAWN_RATE_WINDOW_MS) {
62
+ recentSpawnTimestamps.shift();
63
+ }
64
+ return recentSpawnTimestamps.length >= MAX_SPAWNS_PER_WINDOW;
65
+ }
66
+ function recordSpawn() {
67
+ recentSpawnTimestamps.push(Date.now());
68
+ }
69
+ // ─── Skill Enrichment ─────────────────────────────────────────────────────────
70
+ /**
71
+ * Enrich a task's prompt with matched skill instructions from the SkillRegistry.
72
+ * Transparent: if the registry isn't initialized or no skills match, returns the
73
+ * original prompt unchanged.
74
+ */
75
+ async function enrichPromptWithSkills(task) {
76
+ const registry = getSkillRegistry();
77
+ if (!registry)
78
+ return task.prompt;
79
+ try {
80
+ const matches = registry.matchSkills({ description: task.label });
81
+ if (matches.length === 0)
82
+ return task.prompt;
83
+ // Load bodies and collect formatted prompts (cap at 3 to avoid bloat)
84
+ const skillPrompts = [];
85
+ for (const match of matches.slice(0, 3)) {
86
+ await registry.loadBody(match.skill.meta.name);
87
+ const formatted = registry.getSkillPrompt(match.skill.meta.name);
88
+ if (formatted) {
89
+ skillPrompts.push(formatted);
90
+ }
91
+ }
92
+ if (skillPrompts.length === 0)
93
+ return task.prompt;
94
+ const skillNames = matches.slice(0, 3).filter((m) => {
95
+ const s = registry.getSkillPrompt(m.skill.meta.name);
96
+ return s !== null;
97
+ }).map((m) => m.skill.meta.name);
98
+ log.info(`Enriching agent "${task.label}" with ${skillPrompts.length} skill(s): ${skillNames.join(", ")}`, { taskId: task.id });
99
+ return [
100
+ task.prompt,
101
+ "",
102
+ "---",
103
+ "## Relevant Skills",
104
+ "",
105
+ ...skillPrompts,
106
+ ].join("\n");
107
+ }
108
+ catch (err) {
109
+ log.warn(`Skill enrichment failed for "${task.label}", using original prompt: ${err instanceof Error ? err.message : String(err)}`, { taskId: task.id });
110
+ return task.prompt;
111
+ }
112
+ }
113
+ /** Map of task ID → spawned ChildProcess (only for tasks we spawned this session). */
114
+ const activeProcesses = new Map();
115
+ /** Tasks that fell back from pool to direct — skip recovery to prevent double-retry. */
116
+ const poolFallbackTasks = new Set();
117
+ /** Track batch membership: sessionId → set of task IDs spawned together. */
118
+ const sessionBatches = new Map();
119
+ /** Collect results from each agent as they finish (sessionId → results[]) */
120
+ const batchResults = new Map();
121
+ /** Callback invoked when all agents from a session batch have completed. */
122
+ let onBatchComplete = null;
123
+ /** Register a callback for when an agent batch finishes. */
124
+ export function setOnBatchComplete(cb) {
125
+ onBatchComplete = cb;
126
+ }
127
+ /** Map of task ID → timeout timer. */
128
+ const activeTimers = new Map();
129
+ export { activeProcesses };
130
+ /** Check if any agents are currently running (active processes or pending batches). */
131
+ export function isAgentsBusy() {
132
+ return activeProcesses.size > 0 || sessionBatches.size > 0;
133
+ }
134
+ /** Number of currently active agent processes. */
135
+ export function activeAgentCount() {
136
+ return activeProcesses.size;
137
+ }
138
+ /** Reference to the runtime pool. Set via setAgentPool() when the pool is initialized. */
139
+ let agentPool = null;
140
+ /** Wire the runtime pool into spawn.ts so spawnAgent delegates to it. */
141
+ export function setAgentPool(pool) {
142
+ agentPool = pool;
143
+ }
144
+ /** Check if the runtime pool is active. */
145
+ export function hasAgentPool() {
146
+ return agentPool !== null && !agentPool.isShuttingDown;
147
+ }
148
+ /**
149
+ * Spawn the claude CLI for a task.
150
+ *
151
+ * When the runtime AgentPool is available, delegates to it for lifecycle
152
+ * management, resource tracking, circuit breakers, and isolation.
153
+ * Falls back to direct process spawning when the pool isn't initialized.
154
+ *
155
+ * Mutates task in-place (status, pid, startedAt) and writes to disk.
156
+ */
157
+ export async function spawnAgent(task) {
158
+ return traceAgentSpawn(task.id, task.label, task.origin, async (span) => {
159
+ const correlationId = getCorrelationId();
160
+ if (correlationId) {
161
+ span.setAttribute("dash.correlation_id", correlationId);
162
+ }
163
+ if (task.sessionId) {
164
+ span.setAttribute("agent.session_id", task.sessionId);
165
+ }
166
+ log.info(`Spawning agent: ${task.label}`, { taskId: task.id, origin: task.origin, sessionId: task.sessionId });
167
+ // Enrich prompt with matched skill instructions (transparent — no-op if registry unavailable)
168
+ task.prompt = await enrichPromptWithSkills(task);
169
+ // Global spawn rate limiter — prevent burst-spawning
170
+ if (isSpawnRateLimited()) {
171
+ log.warn(`Spawn rate-limited, skipping: ${task.label}`, { taskId: task.id });
172
+ span.setAttribute("agent.rate_limited", true);
173
+ recordSpawnRateBlock();
174
+ logActivity({
175
+ source: "agent",
176
+ summary: `Spawn rate-limited, skipping: ${task.label}`,
177
+ detail: `Max ${MAX_SPAWNS_PER_WINDOW} spawns per ${SPAWN_RATE_WINDOW_MS / 1000}s`,
178
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
179
+ reason: "spawn rate limit exceeded",
180
+ });
181
+ return;
182
+ }
183
+ recordSpawn();
184
+ // Delegate to runtime pool when available
185
+ if (agentPool && !agentPool.isShuttingDown) {
186
+ log.debug(`Using pool spawn for: ${task.label}`, { taskId: task.id });
187
+ span.setAttribute("agent.spawn_mode", "pool");
188
+ return spawnViaPool(task);
189
+ }
190
+ // Fallback: direct process spawning (original behavior)
191
+ log.debug(`Using direct spawn for: ${task.label}`, { taskId: task.id });
192
+ span.setAttribute("agent.spawn_mode", "direct");
193
+ return spawnDirect(task);
194
+ });
195
+ }
196
+ /**
197
+ * Spawn through the AgentPool runtime.
198
+ * The pool handles resource allocation, circuit breakers, isolation, and monitoring.
199
+ */
200
+ async function spawnViaPool(task) {
201
+ try {
202
+ const instance = await agentPool.spawn({
203
+ taskId: task.id,
204
+ label: task.label,
205
+ prompt: task.prompt,
206
+ cwd: task.cwd,
207
+ origin: task.origin,
208
+ tags: task.sessionId ? [`session:${task.sessionId}`] : [],
209
+ config: {
210
+ timeoutMs: task.timeoutMs ?? 600000,
211
+ maxRetries: 2,
212
+ backoffMs: 2000,
213
+ backoffMultiplier: 2,
214
+ maxBackoffMs: 30000,
215
+ env: {},
216
+ isolation: "shared",
217
+ priority: 50,
218
+ },
219
+ });
220
+ // Sync task state from runtime instance
221
+ task.status = "running";
222
+ task.pid = instance.pid;
223
+ task.startedAt = new Date().toISOString();
224
+ await writeTask(task);
225
+ // Move board task to in_progress and write back the agent task ID for causal backrefs
226
+ if (task.boardTaskId) {
227
+ updateBoardTaskState(task.boardTaskId, { state: "in_progress", assignee: `${getInstanceNameLower()}-agent`, agentTaskId: task.id });
228
+ }
229
+ // Track batch membership (still needed for continuation)
230
+ if (task.sessionId) {
231
+ if (!sessionBatches.has(task.sessionId)) {
232
+ sessionBatches.set(task.sessionId, new Set());
233
+ }
234
+ sessionBatches.get(task.sessionId).add(task.id);
235
+ }
236
+ // Listen for completion via the runtime bus
237
+ // Use .on() with self-removal instead of .once() to avoid race conditions
238
+ // where another agent's event consumes this listener
239
+ const onCompleted = (data) => {
240
+ if (data.agentId === instance.id) {
241
+ agentPool?.runtimeManager.bus.off("agent:completed", onCompleted);
242
+ agentPool?.runtimeManager.bus.off("agent:failed", onFailed);
243
+ handlePoolCompletion(task, "completed", data.exitCode ?? 0);
244
+ }
245
+ };
246
+ const onFailed = (data) => {
247
+ if (data.agentId === instance.id) {
248
+ agentPool?.runtimeManager.bus.off("agent:completed", onCompleted);
249
+ agentPool?.runtimeManager.bus.off("agent:failed", onFailed);
250
+ handlePoolCompletion(task, "failed", null);
251
+ }
252
+ };
253
+ agentPool.runtimeManager.bus.on("agent:completed", onCompleted);
254
+ agentPool.runtimeManager.bus.on("agent:failed", onFailed);
255
+ recordAgentSpawn();
256
+ logActivity({
257
+ source: "agent",
258
+ summary: `Spawned agent via pool: ${task.label}`,
259
+ detail: `Instance ${instance.id}, PID ${instance.pid}, task ${task.id}`,
260
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
261
+ reason: task.origin === "ai" ? "planner selected from backlog" : "user chat triggered agent",
262
+ });
263
+ }
264
+ catch (err) {
265
+ // Pool rejected the spawn (circuit breaker, resources, etc.)
266
+ // Fall back to direct spawning, but mark task to skip recovery
267
+ // (pool already handles retries — don't double up with recovery agents)
268
+ poolFallbackTasks.add(task.id);
269
+ logActivity({
270
+ source: "agent",
271
+ summary: `Pool spawn failed, falling back to direct (no recovery): ${task.label}`,
272
+ detail: err instanceof Error ? err.message : String(err),
273
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
274
+ reason: "pool spawn failed, falling back",
275
+ });
276
+ return spawnDirect(task);
277
+ }
278
+ }
279
+ /** Handle completion callbacks when spawned via pool. */
280
+ async function handlePoolCompletion(task, status, exitCode) {
281
+ log.info(`Agent ${status}: ${task.label}`, { taskId: task.id, exitCode, sessionId: task.sessionId });
282
+ // Release file locks held by this agent
283
+ releaseLocks(task.id).catch((err) => {
284
+ log.warn(`Failed to release locks for agent ${task.id}: ${err instanceof Error ? err.message : String(err)}`);
285
+ });
286
+ // Record agent completion metric
287
+ if (task.startedAt) {
288
+ const durationMs = Date.now() - new Date(task.startedAt).getTime();
289
+ recordAgentCompletion(durationMs, status === "completed");
290
+ }
291
+ // DASH-143: Record cooldown IMMEDIATELY on failure — before setting
292
+ // board task back to "todo". This closes the race window where the
293
+ // autonomous loop re-plans the same task before batch-level cooldown fires.
294
+ if (status === "failed" && task.boardTaskId) {
295
+ TaskCooldownManager.getInstance().recordFailure(task.boardTaskId, task.label, `Pool terminal failure (exit ${exitCode})`);
296
+ }
297
+ // Update board task state: done on success, back to todo on failure
298
+ if (task.boardTaskId) {
299
+ if (status === "completed") {
300
+ await updateBoardTaskState(task.boardTaskId, { state: "done" });
301
+ }
302
+ else {
303
+ // Failed: move back to todo and clear assignee so it can be retried
304
+ await updateBoardTaskState(task.boardTaskId, { state: "todo", assignee: null });
305
+ }
306
+ }
307
+ const output = await readTaskOutput(task.id).catch(() => "");
308
+ const resultSummary = output.trim().slice(0, 1000) || undefined;
309
+ // Notifications
310
+ const outputSnippet = resultSummary ? `\nOutput:\n${resultSummary}` : "";
311
+ pushNotification({
312
+ timestamp: new Date().toISOString(),
313
+ source: "agent",
314
+ message: `Agent task "${task.label}" ${status} (exit ${exitCode}).${outputSnippet}`,
315
+ });
316
+ // Triage: check if agent surfaced questions for the human
317
+ const needsHuman = await triageAgentOutput({ ...task, status, exitCode: exitCode ?? undefined }, output).catch(() => false);
318
+ // On failure via pool: the RuntimeManager already handles retries at the
319
+ // instance level (maybeRetry with exponential backoff). Don't also spawn
320
+ // a recovery agent — that creates double-retry fan-out. Only track for
321
+ // phone alerts and record if this was a recovery task that failed.
322
+ if (status === "failed") {
323
+ if (task.label.startsWith("Fix: ")) {
324
+ recordRecoveryFailure();
325
+ }
326
+ if (!needsHuman) {
327
+ trackFailureForAlert(task.label);
328
+ }
329
+ }
330
+ // Post-completion reflection for autonomous tasks (skip for recovery agents —
331
+ // session-level reflection already covers them, and per-agent LLM calls add latency)
332
+ if (!task.label.startsWith("Fix: ")) {
333
+ reflectOnCompletion({ ...task, status, exitCode: exitCode ?? undefined }, output).catch(() => { });
334
+ }
335
+ // Scar evaluation for successful Fix: agents — check if the repair qualifies as a scar
336
+ if (task.label.startsWith("Fix: ") && status === "completed") {
337
+ evaluateScar({ ...task, status, exitCode: exitCode ?? undefined }, output).catch(() => { });
338
+ }
339
+ // Batch continuation
340
+ if (task.sessionId && sessionBatches.has(task.sessionId)) {
341
+ const batch = sessionBatches.get(task.sessionId);
342
+ batch.delete(task.id);
343
+ if (!batchResults.has(task.sessionId)) {
344
+ batchResults.set(task.sessionId, []);
345
+ }
346
+ batchResults.get(task.sessionId).push({ label: task.label, status });
347
+ if (batch.size === 0) {
348
+ sessionBatches.delete(task.sessionId);
349
+ const allResults = batchResults.get(task.sessionId) ?? [{ label: task.label, status }];
350
+ batchResults.delete(task.sessionId);
351
+ if (onBatchComplete) {
352
+ const sid = task.sessionId;
353
+ // 500ms settlement: task store writes are sync, just need metadata flush
354
+ setTimeout(() => {
355
+ logActivity({ source: "agent", summary: `Agent batch complete for session ${sid} (${allResults.length} agents)`, actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED", reason: "agent batch completed" });
356
+ Promise.resolve(onBatchComplete(sid, allResults)).catch((err) => {
357
+ logActivity({ source: "agent", summary: `Auto-continue callback error: ${err instanceof Error ? err.message : String(err)}`, actionLabel: "AUTONOMOUS", reason: "batch continuation error" });
358
+ });
359
+ }, 500);
360
+ }
361
+ }
362
+ }
363
+ }
364
+ /** Send agent failure alert email via Resend (fire-and-forget). */
365
+ async function sendFailureEmail(count, names) {
366
+ const apiKey = process.env.RESEND_API_KEY;
367
+ if (!apiKey) {
368
+ log.warn("No RESEND_API_KEY — skipping agent failure email");
369
+ return;
370
+ }
371
+ try {
372
+ const res = await fetch("https://api.resend.com/emails", {
373
+ method: "POST",
374
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
375
+ body: JSON.stringify({
376
+ from: `${getInstanceName()} <${getAlertEmailFrom()}>`,
377
+ to: [resolveEnv("ALERT_EMAIL_TO") ?? ""].filter(Boolean),
378
+ subject: `[AGENT ALERT] ${count} agent failures in the last few minutes`,
379
+ html: `<div style="font-family:sans-serif;max-width:600px;">
380
+ <div style="background:#f59e0b;color:white;padding:16px;border-radius:8px 8px 0 0;">
381
+ <h2 style="margin:0;">Agent Failures</h2>
382
+ </div>
383
+ <div style="border:1px solid #e5e7eb;border-top:none;padding:16px;border-radius:0 0 8px 8px;">
384
+ <p><strong>${count} agents</strong> failed within a 5-minute window.</p>
385
+ <p><strong>Agents:</strong> ${names}</p>
386
+ <p style="color:#6b7280;font-size:12px;">Check the agent logs at /ops for details. A phone call will follow only if failures continue to escalate.</p>
387
+ </div>
388
+ </div>`,
389
+ }),
390
+ });
391
+ if (res.ok) {
392
+ logActivity({ source: "agent", summary: `Emailed you about ${count} agent failures` });
393
+ }
394
+ else {
395
+ log.error("Agent failure email failed", { status: res.status });
396
+ }
397
+ }
398
+ catch (err) {
399
+ log.error("Agent failure email exception", { error: String(err) });
400
+ }
401
+ }
402
+ /** Track failure — email first, phone only as last resort. */
403
+ function trackFailureForAlert(label) {
404
+ const now = Date.now();
405
+ recentFailures.push({ label, time: now });
406
+ while (recentFailures.length > 0 && recentFailures[0].time < now - FAILURE_WINDOW_MS) {
407
+ recentFailures.shift();
408
+ }
409
+ const count = recentFailures.length;
410
+ const names = recentFailures.map((f) => f.label).join(", ");
411
+ // Tier 1: Email at 2+ failures
412
+ if (count >= EMAIL_THRESHOLD && now - lastEmailTime > EMAIL_COOLDOWN_MS) {
413
+ lastEmailTime = now;
414
+ sendFailureEmail(count, names).catch(() => { });
415
+ }
416
+ // Tier 2: Phone call at 5+ failures (last resort, after email)
417
+ if (count >= CALL_THRESHOLD && now - lastCallTime > CALL_COOLDOWN_MS) {
418
+ lastCallTime = now;
419
+ makeCall({
420
+ message: `Hey, it's ${getInstanceName()}. ${count} agents have failed in the last few minutes. I already sent you an email with details. This is getting serious — please check the logs.`,
421
+ }).then((r) => {
422
+ logActivity({ source: "agent", summary: r.ok ? `Called you about ${count} agent failures (escalated from email)` : `Failed to call: ${r.message}` });
423
+ }).catch(() => { });
424
+ }
425
+ }
426
+ /** Direct process spawning — original behavior without runtime pool. */
427
+ async function spawnDirect(task) {
428
+ const stdoutPath = join(LOGS_DIR, `${task.id}.stdout.log`);
429
+ const stderrPath = join(LOGS_DIR, `${task.id}.stderr.log`);
430
+ const promptPath = join(LOGS_DIR, `${task.id}.prompt.txt`);
431
+ // Write prompt to file to avoid shell escaping issues
432
+ writeFileSync(promptPath, task.prompt, "utf-8");
433
+ // Clean environment: remove CLAUDECODE to allow nested Claude Code sessions.
434
+ // Claude CLI refuses to run inside another session if this env var is set.
435
+ const cleanEnv = { ...process.env };
436
+ delete cleanEnv.CLAUDECODE;
437
+ // Use node as the wrapper — avoids all shell encoding/escaping issues.
438
+ // spawnSync with windowsHide prevents claude from opening a console window.
439
+ const wrapperScript = `
440
+ const fs = require("fs");
441
+ const { spawnSync } = require("child_process");
442
+ const prompt = fs.readFileSync(${JSON.stringify(promptPath)}, "utf-8");
443
+ const r = spawnSync("claude", [
444
+ "--print", "--output-format", "text", "--dangerously-skip-permissions", prompt
445
+ ], {
446
+ cwd: ${JSON.stringify(task.cwd)},
447
+ encoding: "utf-8",
448
+ maxBuffer: 50 * 1024 * 1024,
449
+ timeout: ${task.timeoutMs ?? 600000},
450
+ windowsHide: true
451
+ });
452
+ fs.writeFileSync(${JSON.stringify(stdoutPath)}, r.stdout || "", "utf-8");
453
+ fs.writeFileSync(${JSON.stringify(stderrPath)}, r.stderr || "", "utf-8");
454
+ process.exit(r.status || 0);
455
+ `;
456
+ const child = spawn(process.execPath, ["--eval", wrapperScript], {
457
+ cwd: task.cwd,
458
+ detached: true,
459
+ stdio: "ignore",
460
+ env: cleanEnv,
461
+ windowsHide: true,
462
+ });
463
+ // Let the instance exit without killing the child
464
+ child.unref();
465
+ task.status = "running";
466
+ task.pid = child.pid;
467
+ task.startedAt = new Date().toISOString();
468
+ await writeTask(task);
469
+ activeProcesses.set(task.id, child);
470
+ // Move board task to in_progress and write back the agent task ID for causal backrefs
471
+ if (task.boardTaskId) {
472
+ updateBoardTaskState(task.boardTaskId, { state: "in_progress", assignee: `${getInstanceNameLower()}-agent`, agentTaskId: task.id });
473
+ }
474
+ // Track batch: group tasks by sessionId so we know when a batch finishes
475
+ if (task.sessionId) {
476
+ if (!sessionBatches.has(task.sessionId)) {
477
+ sessionBatches.set(task.sessionId, new Set());
478
+ }
479
+ sessionBatches.get(task.sessionId).add(task.id);
480
+ }
481
+ recordAgentSpawn();
482
+ logActivity({
483
+ source: "agent",
484
+ summary: `Spawned agent: ${task.label}`,
485
+ detail: `PID ${child.pid}, task ${task.id}`,
486
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
487
+ reason: task.origin === "ai" ? "planner selected from backlog" : "user chat triggered agent",
488
+ });
489
+ // Exit handler
490
+ child.on("exit", async (code) => {
491
+ log.info(`Agent process exited: ${task.label}`, { taskId: task.id, exitCode: code, pid: child.pid });
492
+ activeProcesses.delete(task.id);
493
+ clearTaskTimer(task.id);
494
+ // Release file locks held by this agent
495
+ releaseLocks(task.id).catch((err) => {
496
+ log.warn(`Failed to release locks for agent ${task.id}: ${err instanceof Error ? err.message : String(err)}`);
497
+ });
498
+ // Brief delay to ensure file buffers are flushed.
499
+ // writeFileSync in the wrapper script guarantees data is on disk,
500
+ // but the OS may still be updating file metadata. 100ms is sufficient.
501
+ await new Promise((r) => setTimeout(r, 100));
502
+ const output = await readTaskOutput(task.id);
503
+ const resultSummary = output.trim().slice(0, 1000) || undefined;
504
+ // Determine success: exit 0 is clean success, but a null/non-zero exit code
505
+ // with substantial output likely means the agent did its work but the process
506
+ // exited uncleanly (signal, timeout, claude CLI quirk). Trust the output.
507
+ const hasSubstantialOutput = output.trim().length > 100;
508
+ const finalStatus = code === 0 || (code == null && hasSubstantialOutput)
509
+ ? "completed"
510
+ : "failed";
511
+ // Record agent completion metric
512
+ if (task.startedAt) {
513
+ const durationMs = Date.now() - new Date(task.startedAt).getTime();
514
+ recordAgentCompletion(durationMs, finalStatus === "completed");
515
+ }
516
+ await updateTask(task.id, {
517
+ status: finalStatus,
518
+ exitCode: code ?? undefined,
519
+ finishedAt: new Date().toISOString(),
520
+ resultSummary,
521
+ });
522
+ // DASH-143: Record cooldown IMMEDIATELY on failure — before setting
523
+ // board task back to "todo". Prevents autonomous re-planning race.
524
+ if (finalStatus === "failed" && task.boardTaskId) {
525
+ TaskCooldownManager.getInstance().recordFailure(task.boardTaskId, task.label, `Direct spawn failure (exit ${code})`);
526
+ }
527
+ // Update board task state: done on success, back to todo on failure
528
+ if (task.boardTaskId) {
529
+ if (finalStatus === "completed") {
530
+ await updateBoardTaskState(task.boardTaskId, { state: "done" });
531
+ }
532
+ else {
533
+ await updateBoardTaskState(task.boardTaskId, { state: "todo", assignee: null });
534
+ }
535
+ }
536
+ // Durable memory — survives restarts, retrievable by future turns
537
+ rememberTaskOutcome({ ...task, status: finalStatus, exitCode: code ?? undefined }, output).catch(() => { });
538
+ // Post-completion reflection for autonomous tasks (skip for recovery agents —
539
+ // session-level reflection already covers them, and per-agent LLM calls add latency)
540
+ if (!task.label.startsWith("Fix: ")) {
541
+ reflectOnCompletion({ ...task, status: finalStatus, exitCode: code ?? undefined }, output).catch(() => { });
542
+ }
543
+ // Scar evaluation for successful Fix: agents — check if the repair qualifies as a scar
544
+ if (task.label.startsWith("Fix: ") && finalStatus === "completed") {
545
+ evaluateScar({ ...task, status: finalStatus, exitCode: code ?? undefined }, output).catch(() => { });
546
+ }
547
+ logActivity({
548
+ source: "agent",
549
+ summary: `Agent ${finalStatus}: ${task.label}`,
550
+ detail: `Exit code ${code}, task ${task.id}`,
551
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
552
+ reason: `agent ${finalStatus}`,
553
+ });
554
+ const outputSnippet = resultSummary
555
+ ? `\nOutput:\n${resultSummary}`
556
+ : "";
557
+ pushNotification({
558
+ timestamp: new Date().toISOString(),
559
+ source: "agent",
560
+ message: `Agent task "${task.label}" ${finalStatus} (exit ${code}).${outputSnippet}`,
561
+ });
562
+ // Triage: check if agent surfaced questions for the human
563
+ const needsHuman = await triageAgentOutput({ ...task, status: finalStatus, exitCode: code ?? undefined }, output).catch(() => false);
564
+ // On failure: attempt recovery ONLY if not blocked on human questions
565
+ // and not a pool-fallback task (pool already handles retries)
566
+ if (finalStatus === "failed" && !needsHuman) {
567
+ // Record if this was itself a recovery agent that failed
568
+ if (task.label.startsWith("Fix: ")) {
569
+ recordRecoveryFailure();
570
+ }
571
+ const isPoolFallback = poolFallbackTasks.has(task.id);
572
+ if (isPoolFallback) {
573
+ poolFallbackTasks.delete(task.id);
574
+ logActivity({
575
+ source: "agent",
576
+ summary: `Skipping recovery for pool-fallback task: ${task.label}`,
577
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
578
+ reason: "pool-fallback task — no double retry",
579
+ });
580
+ }
581
+ else {
582
+ attemptRecovery({ ...task, status: "failed", exitCode: code ?? undefined }, output).catch(() => { });
583
+ }
584
+ trackFailureForAlert(task.label);
585
+ }
586
+ // Check if this was the last agent in a batch → trigger continuation
587
+ if (task.sessionId && sessionBatches.has(task.sessionId)) {
588
+ const batch = sessionBatches.get(task.sessionId);
589
+ batch.delete(task.id);
590
+ // Collect this agent's result
591
+ if (!batchResults.has(task.sessionId)) {
592
+ batchResults.set(task.sessionId, []);
593
+ }
594
+ batchResults.get(task.sessionId).push({ label: task.label, status: finalStatus });
595
+ if (batch.size === 0) {
596
+ sessionBatches.delete(task.sessionId);
597
+ const allResults = batchResults.get(task.sessionId) ?? [{ label: task.label, status: finalStatus }];
598
+ batchResults.delete(task.sessionId);
599
+ // All agents done — pass all results to continuation
600
+ if (onBatchComplete) {
601
+ const sid = task.sessionId;
602
+ // 500ms settlement: task store writes are sync, just need metadata flush
603
+ setTimeout(() => {
604
+ logActivity({ source: "agent", summary: `Agent batch complete for session ${sid} (${allResults.length} agents)`, actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED", reason: "agent batch completed" });
605
+ Promise.resolve(onBatchComplete(sid, allResults)).catch((err) => {
606
+ logActivity({ source: "agent", summary: `Auto-continue callback error: ${err instanceof Error ? err.message : String(err)}`, actionLabel: "AUTONOMOUS", reason: "batch continuation error" });
607
+ });
608
+ }, 500);
609
+ }
610
+ }
611
+ }
612
+ });
613
+ // Error handler (spawn failure)
614
+ child.on("error", async (err) => {
615
+ activeProcesses.delete(task.id);
616
+ clearTaskTimer(task.id);
617
+ poolFallbackTasks.delete(task.id);
618
+ // Record agent failure metric — balances the in-flight gauge from recordAgentSpawn()
619
+ if (task.startedAt) {
620
+ const durationMs = Date.now() - new Date(task.startedAt).getTime();
621
+ recordAgentCompletion(durationMs, false);
622
+ }
623
+ else {
624
+ // Spawned but never got startedAt — still need to decrement in-flight
625
+ recordAgentCompletion(0, false);
626
+ }
627
+ // Release file locks held by this agent
628
+ releaseLocks(task.id).catch(() => { });
629
+ await updateTask(task.id, {
630
+ status: "failed",
631
+ error: err.message,
632
+ finishedAt: new Date().toISOString(),
633
+ });
634
+ rememberTaskOutcome({ ...task, status: "failed", error: err.message }).catch(() => { });
635
+ logActivity({
636
+ source: "agent",
637
+ summary: `Agent spawn error: ${task.label}`,
638
+ detail: err.message,
639
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
640
+ reason: "agent spawn error",
641
+ });
642
+ pushNotification({
643
+ timestamp: new Date().toISOString(),
644
+ source: "agent",
645
+ message: `Agent task "${task.label}" failed to spawn: ${err.message}`,
646
+ });
647
+ // Clean up batch membership so batch completion isn't stuck
648
+ if (task.sessionId && sessionBatches.has(task.sessionId)) {
649
+ const batch = sessionBatches.get(task.sessionId);
650
+ batch.delete(task.id);
651
+ if (!batchResults.has(task.sessionId)) {
652
+ batchResults.set(task.sessionId, []);
653
+ }
654
+ batchResults.get(task.sessionId).push({ label: task.label, status: "failed" });
655
+ if (batch.size === 0) {
656
+ sessionBatches.delete(task.sessionId);
657
+ const allResults = batchResults.get(task.sessionId) ?? [{ label: task.label, status: "failed" }];
658
+ batchResults.delete(task.sessionId);
659
+ if (onBatchComplete) {
660
+ const sid = task.sessionId;
661
+ setTimeout(() => {
662
+ Promise.resolve(onBatchComplete(sid, allResults)).catch(() => { });
663
+ }, 2000);
664
+ }
665
+ }
666
+ }
667
+ });
668
+ // Timeout
669
+ if (task.timeoutMs && task.timeoutMs > 0) {
670
+ const timer = setTimeout(() => {
671
+ if (activeProcesses.has(task.id)) {
672
+ logActivity({
673
+ source: "agent",
674
+ summary: `Agent timed out: ${task.label}`,
675
+ detail: `Killing PID ${child.pid} after ${task.timeoutMs}ms`,
676
+ actionLabel: task.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
677
+ reason: "agent timeout exceeded",
678
+ });
679
+ try {
680
+ if (process.platform === "win32" && child.pid) {
681
+ spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { shell: true });
682
+ }
683
+ else {
684
+ child.kill("SIGTERM");
685
+ }
686
+ }
687
+ catch { }
688
+ }
689
+ }, task.timeoutMs);
690
+ activeTimers.set(task.id, timer);
691
+ }
692
+ }
693
+ /** Cancel a running agent task. Tries pool first, then direct process kill. */
694
+ export async function cancelAgent(taskId) {
695
+ // Try cancelling via pool (it tracks runtime instances by taskId)
696
+ if (agentPool) {
697
+ const instance = agentPool.runtimeManager.getByTaskId(taskId);
698
+ if (instance) {
699
+ try {
700
+ await agentPool.terminate(instance.id, "Cancelled by user");
701
+ }
702
+ catch {
703
+ // Fall through to direct cancellation
704
+ }
705
+ }
706
+ }
707
+ // Direct process kill (for legacy/direct spawns)
708
+ const child = activeProcesses.get(taskId);
709
+ if (child) {
710
+ activeProcesses.delete(taskId);
711
+ clearTaskTimer(taskId);
712
+ try {
713
+ if (process.platform === "win32" && child.pid) {
714
+ spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { shell: true });
715
+ }
716
+ else {
717
+ child.kill("SIGTERM");
718
+ }
719
+ }
720
+ catch { }
721
+ }
722
+ // Release file locks held by this agent
723
+ releaseLocks(taskId).catch((err) => {
724
+ log.warn(`Failed to release locks on cancel for ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
725
+ });
726
+ // Record cancellation as a failed completion to keep in-flight gauge accurate
727
+ const taskRecord = await readTask(taskId);
728
+ if (taskRecord?.startedAt) {
729
+ const durationMs = Date.now() - new Date(taskRecord.startedAt).getTime();
730
+ recordAgentCompletion(durationMs, false);
731
+ }
732
+ const updated = await updateTask(taskId, {
733
+ status: "cancelled",
734
+ finishedAt: new Date().toISOString(),
735
+ });
736
+ if (updated) {
737
+ logActivity({
738
+ source: "agent",
739
+ summary: `Agent cancelled: ${updated.label}`,
740
+ detail: `Task ${taskId}`,
741
+ actionLabel: updated.origin === "ai" ? "AUTONOMOUS" : "PROMPTED",
742
+ reason: "agent cancelled by user",
743
+ });
744
+ pushNotification({
745
+ timestamp: new Date().toISOString(),
746
+ source: "agent",
747
+ message: `Agent task "${updated.label}" was cancelled.`,
748
+ });
749
+ }
750
+ return updated !== null;
751
+ }
752
+ // ─── Reflection ───────────────────────────────────────────────────────────────
753
+ const reflectionLog = createLogger("reflection");
754
+ const REFLECTION_PROMPT = `You are reflecting on a completed autonomous agent task. Answer concisely in JSON:
755
+ {
756
+ "movedGoalForward": true/false,
757
+ "hitGuardrail": true/false,
758
+ "adjustment": "what to do differently next time, or null if nothing",
759
+ "summary": "1 sentence: what happened and was it useful?"
760
+ }
761
+ Be honest. If the task failed or produced nothing useful, say so.`;
762
+ async function reflectOnCompletion(task, output) {
763
+ // Only reflect on autonomous actions
764
+ if (task.origin !== "ai")
765
+ return;
766
+ try {
767
+ // Tier 1: Micro-reflection for routine successes — skip LLM call
768
+ const isRoutineSuccess = task.exitCode === 0 && output.trim().length > 100;
769
+ if (isRoutineSuccess) {
770
+ const microReflection = {
771
+ movedGoalForward: true,
772
+ hitGuardrail: false,
773
+ adjustment: undefined,
774
+ summary: `Completed "${task.label}" successfully.`,
775
+ };
776
+ await updateTask(task.id, { reflection: microReflection });
777
+ reflectionLog.info(`Micro-reflection (routine success): "${task.label}"`);
778
+ return;
779
+ }
780
+ // Tier 2: Full LLM reflection for non-routine completions
781
+ const provider = resolveProvider();
782
+ const model = resolveUtilityModel();
783
+ const response = await completeChat({
784
+ messages: [
785
+ { role: "system", content: REFLECTION_PROMPT },
786
+ { role: "user", content: JSON.stringify({
787
+ label: task.label,
788
+ status: task.status,
789
+ output: output.slice(0, 1000),
790
+ exitCode: task.exitCode,
791
+ }) },
792
+ ],
793
+ model,
794
+ provider,
795
+ });
796
+ // Parse JSON response — strip markdown fences if present
797
+ const jsonStr = response.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "").trim();
798
+ const reflection = JSON.parse(jsonStr);
799
+ // Write reflection to task record
800
+ await updateTask(task.id, { reflection });
801
+ // Log reflective activity entry (only for non-routine cases that warranted LLM analysis)
802
+ logActivity({
803
+ source: "agent",
804
+ summary: `Reflection on "${task.label}": ${reflection.summary}`,
805
+ actionLabel: "REFLECTIVE",
806
+ reason: "post-completion autonomous reflection",
807
+ backref: task.id,
808
+ });
809
+ reflectionLog.info(`Reflected on "${task.label}": ${reflection.summary}`);
810
+ }
811
+ catch (err) {
812
+ reflectionLog.warn(`Reflection failed for "${task.label}": ${err instanceof Error ? err.message : String(err)}`);
813
+ }
814
+ }
815
+ // ─── Scar Evaluation ──────────────────────────────────────────────────────────
816
+ const SCAR_EVAL_PROMPT = `You are evaluating whether a completed "Fix:" agent's work qualifies as a scar — a self-repair proven by code, tests, and validation.
817
+
818
+ A fix qualifies as a scar ONLY if the output shows ALL of these:
819
+ 1. A clear root cause was identified (the "anchor")
820
+ 2. Code was changed to correct the defect
821
+ 3. Tests or validation were added/run to prove the fix works
822
+
823
+ Respond in JSON:
824
+ {
825
+ "isScar": true/false,
826
+ "anchor": "root cause description (or null if not a scar)",
827
+ "woundSummary": "one-line description of the original failure (or null)",
828
+ "artifacts": {
829
+ "prevention": ["measures added to prevent recurrence"],
830
+ "detection": ["signals added to detect the issue earlier"],
831
+ "correction": ["code changes that corrected the defect"],
832
+ "regressionTests": ["test files/cases that guard against regression"]
833
+ }
834
+ }
835
+
836
+ If the fix was partial, untested, or just a workaround, set isScar to false.`;
837
+ /**
838
+ * Evaluate whether a completed Fix: agent produced a scar-worthy repair.
839
+ * Called for successful Fix: agents after completion.
840
+ */
841
+ async function evaluateScar(task, output) {
842
+ // Only evaluate successful Fix: agents
843
+ if (!task.label.startsWith("Fix: "))
844
+ return;
845
+ if (task.status !== "completed")
846
+ return;
847
+ try {
848
+ const provider = resolveProvider();
849
+ const model = resolveUtilityModel();
850
+ const response = await completeChat({
851
+ messages: [
852
+ { role: "system", content: SCAR_EVAL_PROMPT },
853
+ { role: "user", content: JSON.stringify({
854
+ label: task.label,
855
+ output: output.slice(0, 2000),
856
+ exitCode: task.exitCode,
857
+ }) },
858
+ ],
859
+ model,
860
+ provider,
861
+ });
862
+ const jsonStr = response.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "").trim();
863
+ const evaluation = JSON.parse(jsonStr);
864
+ if (!evaluation.isScar) {
865
+ reflectionLog.info(`Fix "${task.label}" did not qualify as scar`);
866
+ return;
867
+ }
868
+ await recordScar({
869
+ anchor: evaluation.anchor,
870
+ woundSummary: evaluation.woundSummary,
871
+ healedAt: new Date().toISOString(),
872
+ agentId: task.id,
873
+ artifacts: {
874
+ prevention: evaluation.artifacts?.prevention ?? [],
875
+ detection: evaluation.artifacts?.detection ?? [],
876
+ correction: evaluation.artifacts?.correction ?? [],
877
+ regressionTests: evaluation.artifacts?.regressionTests ?? [],
878
+ },
879
+ });
880
+ logActivity({
881
+ source: "agent",
882
+ summary: `Scar recorded for "${task.label}": ${evaluation.woundSummary}`,
883
+ actionLabel: "REFLECTIVE",
884
+ reason: "fix agent produced validated self-repair",
885
+ backref: task.id,
886
+ });
887
+ }
888
+ catch (err) {
889
+ reflectionLog.warn(`Scar evaluation failed for "${task.label}": ${err instanceof Error ? err.message : String(err)}`);
890
+ }
891
+ }
892
+ /**
893
+ * Generate a consolidated handoff report when a board task hits 3+ failures.
894
+ * Persists to brain/agents/bridge-reports/ and pushes a notification.
895
+ */
896
+ export async function generateBridgeReport(boardTaskId, taskLabel, failureCount) {
897
+ try {
898
+ const allTasks = await listTasks();
899
+ const related = allTasks
900
+ .filter((t) => t.label === taskLabel || t.label === `Fix: ${taskLabel}`)
901
+ .sort((a, b) => (a.createdAt ?? "").localeCompare(b.createdAt ?? ""));
902
+ const attempts = related
903
+ .filter((t) => t.label === taskLabel)
904
+ .map((t, i) => ({
905
+ round: i + 1,
906
+ exitCode: t.exitCode ?? null,
907
+ outputSnippet: (t.resultSummary ?? "").slice(0, 300),
908
+ timestamp: t.finishedAt ?? t.createdAt ?? "",
909
+ }));
910
+ const recoveryAttempts = related
911
+ .filter((t) => t.label.startsWith("Fix: "))
912
+ .map((t) => `Recovery ${t.status}: ${(t.resultSummary ?? "").slice(0, 200)}`);
913
+ const rootCauses = [];
914
+ for (const t of related) {
915
+ if (t.reflection?.adjustment)
916
+ rootCauses.push(t.reflection.adjustment);
917
+ }
918
+ const report = {
919
+ taskId: boardTaskId,
920
+ taskLabel,
921
+ failureCount,
922
+ attempts,
923
+ rootCauses: [...new Set(rootCauses)],
924
+ recoveryAttempts,
925
+ recommendation: rootCauses.length > 0
926
+ ? `Repeated root cause: ${rootCauses[0]}. Manual investigation needed.`
927
+ : `${failureCount} failures with no clear root cause. Check agent logs for ${taskLabel}.`,
928
+ };
929
+ const reportText = [
930
+ `## Bridge Report: "${taskLabel}"`,
931
+ `**${failureCount} consecutive failures** — handing off to human.`,
932
+ ``,
933
+ `### Attempts`,
934
+ ...attempts.map((a) => `- Round ${a.round} (exit ${a.exitCode}): ${a.outputSnippet.slice(0, 100)}...`),
935
+ ``,
936
+ `### Root Causes Identified`,
937
+ ...(rootCauses.length > 0 ? rootCauses.map((r) => `- ${r}`) : ["- No root causes identified by reflection"]),
938
+ ``,
939
+ `### Recovery Attempts`,
940
+ ...(recoveryAttempts.length > 0 ? recoveryAttempts.map((r) => `- ${r}`) : ["- None"]),
941
+ ``,
942
+ `### Recommendation`,
943
+ report.recommendation,
944
+ ].join("\n");
945
+ pushNotification({
946
+ timestamp: new Date().toISOString(),
947
+ source: "agent",
948
+ message: reportText,
949
+ });
950
+ recordBridgeReportMetric();
951
+ logActivity({
952
+ source: "agent",
953
+ summary: `Bridge report generated for "${taskLabel}" (${failureCount} failures)`,
954
+ detail: JSON.stringify(report),
955
+ actionLabel: "AUTONOMOUS",
956
+ reason: "structural impasse — repeated same-task failures",
957
+ });
958
+ // Persist as brain document for future reference
959
+ const reportsDir = join(resolveEnv("BRAIN_DIR") ?? join(process.cwd(), "brain"), "agents", "bridge-reports");
960
+ mkdirSync(reportsDir, { recursive: true });
961
+ const reportPath = join(reportsDir, `${boardTaskId}-${Date.now()}.md`);
962
+ writeFileSync(reportPath, reportText, "utf-8");
963
+ }
964
+ catch (err) {
965
+ reflectionLog.warn(`Bridge report failed for "${taskLabel}": ${err instanceof Error ? err.message : String(err)}`);
966
+ }
967
+ }
968
+ function clearTaskTimer(taskId) {
969
+ const timer = activeTimers.get(taskId);
970
+ if (timer) {
971
+ clearTimeout(timer);
972
+ activeTimers.delete(taskId);
973
+ }
974
+ }
975
+ //# sourceMappingURL=spawn.js.map