@clinebot/core 0.0.18 → 0.0.21

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 (356) hide show
  1. package/dist/account/cline-account-service.d.ts +3 -2
  2. package/dist/account/cline-account-service.d.ts.map +1 -0
  3. package/dist/account/index.d.ts +1 -0
  4. package/dist/account/index.d.ts.map +1 -0
  5. package/dist/account/rpc.d.ts +1 -0
  6. package/dist/account/rpc.d.ts.map +1 -0
  7. package/dist/account/types.d.ts +1 -0
  8. package/dist/account/types.d.ts.map +1 -0
  9. package/dist/agents/agent-config-loader.d.ts +1 -0
  10. package/dist/agents/agent-config-loader.d.ts.map +1 -0
  11. package/dist/agents/agent-config-parser.d.ts +1 -0
  12. package/dist/agents/agent-config-parser.d.ts.map +1 -0
  13. package/dist/agents/hooks-config-loader.d.ts +1 -0
  14. package/dist/agents/hooks-config-loader.d.ts.map +1 -0
  15. package/dist/agents/index.d.ts +1 -0
  16. package/dist/agents/index.d.ts.map +1 -0
  17. package/dist/agents/plugin-config-loader.d.ts +1 -0
  18. package/dist/agents/plugin-config-loader.d.ts.map +1 -0
  19. package/dist/agents/plugin-loader.d.ts +1 -0
  20. package/dist/agents/plugin-loader.d.ts.map +1 -0
  21. package/dist/agents/plugin-sandbox.d.ts +1 -0
  22. package/dist/agents/plugin-sandbox.d.ts.map +1 -0
  23. package/dist/agents/unified-config-file-watcher.d.ts +1 -0
  24. package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
  25. package/dist/agents/user-instruction-config-loader.d.ts +1 -0
  26. package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
  27. package/dist/auth/client.d.ts +1 -0
  28. package/dist/auth/client.d.ts.map +1 -0
  29. package/dist/auth/cline.d.ts +1 -0
  30. package/dist/auth/cline.d.ts.map +1 -0
  31. package/dist/auth/codex.d.ts +1 -0
  32. package/dist/auth/codex.d.ts.map +1 -0
  33. package/dist/auth/oca.d.ts +1 -0
  34. package/dist/auth/oca.d.ts.map +1 -0
  35. package/dist/auth/server.d.ts +1 -0
  36. package/dist/auth/server.d.ts.map +1 -0
  37. package/dist/auth/types.d.ts +1 -0
  38. package/dist/auth/types.d.ts.map +1 -0
  39. package/dist/auth/utils.d.ts +1 -0
  40. package/dist/auth/utils.d.ts.map +1 -0
  41. package/dist/chat/chat-schema.d.ts +13 -12
  42. package/dist/chat/chat-schema.d.ts.map +1 -0
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.node.d.ts +2 -0
  46. package/dist/index.node.d.ts.map +1 -0
  47. package/dist/index.node.js +303 -302
  48. package/dist/input/file-indexer.d.ts +1 -0
  49. package/dist/input/file-indexer.d.ts.map +1 -0
  50. package/dist/input/index.d.ts +1 -0
  51. package/dist/input/index.d.ts.map +1 -0
  52. package/dist/input/mention-enricher.d.ts +1 -0
  53. package/dist/input/mention-enricher.d.ts.map +1 -0
  54. package/dist/mcp/config-loader.d.ts +1 -0
  55. package/dist/mcp/config-loader.d.ts.map +1 -0
  56. package/dist/mcp/index.d.ts +1 -0
  57. package/dist/mcp/index.d.ts.map +1 -0
  58. package/dist/mcp/manager.d.ts +1 -0
  59. package/dist/mcp/manager.d.ts.map +1 -0
  60. package/dist/mcp/types.d.ts +1 -0
  61. package/dist/mcp/types.d.ts.map +1 -0
  62. package/dist/providers/local-provider-registry.d.ts +36 -0
  63. package/dist/providers/local-provider-registry.d.ts.map +1 -0
  64. package/dist/providers/local-provider-service.d.ts +2 -1
  65. package/dist/providers/local-provider-service.d.ts.map +1 -0
  66. package/dist/runtime/commands.d.ts +1 -0
  67. package/dist/runtime/commands.d.ts.map +1 -0
  68. package/dist/runtime/hook-file-hooks.d.ts +1 -0
  69. package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
  70. package/dist/runtime/rules.d.ts +1 -0
  71. package/dist/runtime/rules.d.ts.map +1 -0
  72. package/dist/runtime/runtime-builder.d.ts +1 -0
  73. package/dist/runtime/runtime-builder.d.ts.map +1 -0
  74. package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
  75. package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
  76. package/dist/runtime/session-runtime.d.ts +2 -0
  77. package/dist/runtime/session-runtime.d.ts.map +1 -0
  78. package/dist/runtime/skills.d.ts +1 -0
  79. package/dist/runtime/skills.d.ts.map +1 -0
  80. package/dist/runtime/tool-approval.d.ts +1 -0
  81. package/dist/runtime/tool-approval.d.ts.map +1 -0
  82. package/dist/runtime/workflows.d.ts +1 -0
  83. package/dist/runtime/workflows.d.ts.map +1 -0
  84. package/dist/session/default-session-manager.d.ts +4 -0
  85. package/dist/session/default-session-manager.d.ts.map +1 -0
  86. package/dist/session/file-session-service.d.ts +1 -0
  87. package/dist/session/file-session-service.d.ts.map +1 -0
  88. package/dist/session/rpc-session-service.d.ts +1 -0
  89. package/dist/session/rpc-session-service.d.ts.map +1 -0
  90. package/dist/session/rpc-spawn-lease.d.ts +1 -0
  91. package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
  92. package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
  93. package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
  94. package/dist/session/session-agent-events.d.ts +20 -1
  95. package/dist/session/session-agent-events.d.ts.map +1 -0
  96. package/dist/session/session-artifacts.d.ts +1 -0
  97. package/dist/session/session-artifacts.d.ts.map +1 -0
  98. package/dist/session/session-config-builder.d.ts +1 -0
  99. package/dist/session/session-config-builder.d.ts.map +1 -0
  100. package/dist/session/session-graph.d.ts +1 -0
  101. package/dist/session/session-graph.d.ts.map +1 -0
  102. package/dist/session/session-host.d.ts +1 -0
  103. package/dist/session/session-host.d.ts.map +1 -0
  104. package/dist/session/session-manager.d.ts +1 -0
  105. package/dist/session/session-manager.d.ts.map +1 -0
  106. package/dist/session/session-manifest.d.ts +2 -1
  107. package/dist/session/session-manifest.d.ts.map +1 -0
  108. package/dist/session/session-service.d.ts +1 -0
  109. package/dist/session/session-service.d.ts.map +1 -0
  110. package/dist/session/session-team-coordination.d.ts +1 -0
  111. package/dist/session/session-team-coordination.d.ts.map +1 -0
  112. package/dist/session/session-telemetry.d.ts +3 -1
  113. package/dist/session/session-telemetry.d.ts.map +1 -0
  114. package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
  115. package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
  116. package/dist/session/unified-session-persistence-service.d.ts +1 -0
  117. package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
  118. package/dist/session/utils/helpers.d.ts +1 -0
  119. package/dist/session/utils/helpers.d.ts.map +1 -0
  120. package/dist/session/utils/types.d.ts +1 -0
  121. package/dist/session/utils/types.d.ts.map +1 -0
  122. package/dist/session/utils/usage.d.ts +1 -0
  123. package/dist/session/utils/usage.d.ts.map +1 -0
  124. package/dist/session/workspace-manager.d.ts +1 -0
  125. package/dist/session/workspace-manager.d.ts.map +1 -0
  126. package/dist/session/workspace-manifest.d.ts +1 -0
  127. package/dist/session/workspace-manifest.d.ts.map +1 -0
  128. package/dist/storage/file-team-store.d.ts +1 -0
  129. package/dist/storage/file-team-store.d.ts.map +1 -0
  130. package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
  131. package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
  132. package/dist/storage/provider-settings-manager.d.ts +1 -0
  133. package/dist/storage/provider-settings-manager.d.ts.map +1 -0
  134. package/dist/storage/sqlite-session-store.d.ts +1 -0
  135. package/dist/storage/sqlite-session-store.d.ts.map +1 -0
  136. package/dist/storage/sqlite-team-store.d.ts +1 -0
  137. package/dist/storage/sqlite-team-store.d.ts.map +1 -0
  138. package/dist/storage/team-store.d.ts +1 -0
  139. package/dist/storage/team-store.d.ts.map +1 -0
  140. package/dist/team/index.d.ts +1 -0
  141. package/dist/team/index.d.ts.map +1 -0
  142. package/dist/team/projections.d.ts +1 -0
  143. package/dist/team/projections.d.ts.map +1 -0
  144. package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
  145. package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
  146. package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
  147. package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
  148. package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
  149. package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
  150. package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
  151. package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
  152. package/dist/telemetry/TelemetryService.d.ts +1 -0
  153. package/dist/telemetry/TelemetryService.d.ts.map +1 -0
  154. package/dist/telemetry/core-events.d.ts +55 -22
  155. package/dist/telemetry/core-events.d.ts.map +1 -0
  156. package/dist/telemetry/opentelemetry.d.ts +1 -0
  157. package/dist/telemetry/opentelemetry.d.ts.map +1 -0
  158. package/dist/tools/constants.d.ts +1 -0
  159. package/dist/tools/constants.d.ts.map +1 -0
  160. package/dist/tools/definitions.d.ts +8 -1
  161. package/dist/tools/definitions.d.ts.map +1 -0
  162. package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
  163. package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
  164. package/dist/tools/executors/apply-patch.d.ts +1 -0
  165. package/dist/tools/executors/apply-patch.d.ts.map +1 -0
  166. package/dist/tools/executors/bash.d.ts +2 -1
  167. package/dist/tools/executors/bash.d.ts.map +1 -0
  168. package/dist/tools/executors/editor.d.ts +1 -0
  169. package/dist/tools/executors/editor.d.ts.map +1 -0
  170. package/dist/tools/executors/file-read.d.ts +1 -0
  171. package/dist/tools/executors/file-read.d.ts.map +1 -0
  172. package/dist/tools/executors/index.d.ts +14 -7
  173. package/dist/tools/executors/index.d.ts.map +1 -0
  174. package/dist/tools/executors/search.d.ts +1 -0
  175. package/dist/tools/executors/search.d.ts.map +1 -0
  176. package/dist/tools/executors/web-fetch.d.ts +1 -0
  177. package/dist/tools/executors/web-fetch.d.ts.map +1 -0
  178. package/dist/tools/helpers.d.ts +15 -0
  179. package/dist/tools/helpers.d.ts.map +1 -0
  180. package/dist/tools/index.d.ts +2 -1
  181. package/dist/tools/index.d.ts.map +1 -0
  182. package/dist/tools/model-tool-routing.d.ts +1 -0
  183. package/dist/tools/model-tool-routing.d.ts.map +1 -0
  184. package/dist/tools/presets.d.ts +1 -0
  185. package/dist/tools/presets.d.ts.map +1 -0
  186. package/dist/tools/schemas.d.ts +41 -0
  187. package/dist/tools/schemas.d.ts.map +1 -0
  188. package/dist/tools/types.d.ts +3 -2
  189. package/dist/tools/types.d.ts.map +1 -0
  190. package/dist/types/common.d.ts +1 -0
  191. package/dist/types/common.d.ts.map +1 -0
  192. package/dist/types/config.d.ts +1 -0
  193. package/dist/types/config.d.ts.map +1 -0
  194. package/dist/types/events.d.ts +1 -0
  195. package/dist/types/events.d.ts.map +1 -0
  196. package/dist/types/provider-settings.d.ts +1 -0
  197. package/dist/types/provider-settings.d.ts.map +1 -0
  198. package/dist/types/sessions.d.ts +1 -0
  199. package/dist/types/sessions.d.ts.map +1 -0
  200. package/dist/types/storage.d.ts +1 -0
  201. package/dist/types/storage.d.ts.map +1 -0
  202. package/dist/types/workspace.d.ts +1 -0
  203. package/dist/types/workspace.d.ts.map +1 -0
  204. package/dist/types.d.ts +1 -0
  205. package/dist/types.d.ts.map +1 -0
  206. package/package.json +8 -6
  207. package/src/account/cline-account-service.test.ts +0 -101
  208. package/src/account/cline-account-service.ts +0 -287
  209. package/src/account/index.ts +0 -22
  210. package/src/account/rpc.test.ts +0 -62
  211. package/src/account/rpc.ts +0 -172
  212. package/src/account/types.ts +0 -98
  213. package/src/agents/agent-config-loader.test.ts +0 -236
  214. package/src/agents/agent-config-loader.ts +0 -108
  215. package/src/agents/agent-config-parser.ts +0 -198
  216. package/src/agents/hooks-config-loader.test.ts +0 -20
  217. package/src/agents/hooks-config-loader.ts +0 -118
  218. package/src/agents/index.ts +0 -85
  219. package/src/agents/plugin-config-loader.test.ts +0 -140
  220. package/src/agents/plugin-config-loader.ts +0 -97
  221. package/src/agents/plugin-loader.test.ts +0 -228
  222. package/src/agents/plugin-loader.ts +0 -172
  223. package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
  224. package/src/agents/plugin-sandbox.test.ts +0 -317
  225. package/src/agents/plugin-sandbox.ts +0 -341
  226. package/src/agents/unified-config-file-watcher.test.ts +0 -196
  227. package/src/agents/unified-config-file-watcher.ts +0 -483
  228. package/src/agents/user-instruction-config-loader.test.ts +0 -158
  229. package/src/agents/user-instruction-config-loader.ts +0 -438
  230. package/src/auth/client.test.ts +0 -40
  231. package/src/auth/client.ts +0 -25
  232. package/src/auth/cline.test.ts +0 -130
  233. package/src/auth/cline.ts +0 -420
  234. package/src/auth/codex.test.ts +0 -170
  235. package/src/auth/codex.ts +0 -491
  236. package/src/auth/oca.test.ts +0 -215
  237. package/src/auth/oca.ts +0 -573
  238. package/src/auth/server.ts +0 -216
  239. package/src/auth/types.ts +0 -81
  240. package/src/auth/utils.test.ts +0 -128
  241. package/src/auth/utils.ts +0 -247
  242. package/src/chat/chat-schema.ts +0 -82
  243. package/src/index.node.ts +0 -285
  244. package/src/index.ts +0 -211
  245. package/src/input/file-indexer.d.ts +0 -11
  246. package/src/input/file-indexer.test.ts +0 -127
  247. package/src/input/file-indexer.ts +0 -327
  248. package/src/input/index.ts +0 -7
  249. package/src/input/mention-enricher.test.ts +0 -85
  250. package/src/input/mention-enricher.ts +0 -122
  251. package/src/mcp/config-loader.test.ts +0 -238
  252. package/src/mcp/config-loader.ts +0 -219
  253. package/src/mcp/index.ts +0 -26
  254. package/src/mcp/manager.test.ts +0 -106
  255. package/src/mcp/manager.ts +0 -262
  256. package/src/mcp/types.ts +0 -88
  257. package/src/providers/local-provider-service.ts +0 -608
  258. package/src/runtime/commands.test.ts +0 -98
  259. package/src/runtime/commands.ts +0 -83
  260. package/src/runtime/hook-file-hooks.test.ts +0 -237
  261. package/src/runtime/hook-file-hooks.ts +0 -859
  262. package/src/runtime/index.ts +0 -37
  263. package/src/runtime/rules.ts +0 -34
  264. package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
  265. package/src/runtime/runtime-builder.test.ts +0 -371
  266. package/src/runtime/runtime-builder.ts +0 -589
  267. package/src/runtime/runtime-parity.test.ts +0 -143
  268. package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
  269. package/src/runtime/session-runtime.ts +0 -46
  270. package/src/runtime/skills.ts +0 -44
  271. package/src/runtime/tool-approval.ts +0 -104
  272. package/src/runtime/workflows.test.ts +0 -119
  273. package/src/runtime/workflows.ts +0 -45
  274. package/src/session/default-session-manager.e2e.test.ts +0 -384
  275. package/src/session/default-session-manager.test.ts +0 -1741
  276. package/src/session/default-session-manager.ts +0 -1233
  277. package/src/session/file-session-service.ts +0 -280
  278. package/src/session/index.ts +0 -42
  279. package/src/session/rpc-session-service.ts +0 -107
  280. package/src/session/rpc-spawn-lease.test.ts +0 -49
  281. package/src/session/rpc-spawn-lease.ts +0 -122
  282. package/src/session/runtime-oauth-token-manager.test.ts +0 -137
  283. package/src/session/runtime-oauth-token-manager.ts +0 -272
  284. package/src/session/session-agent-events.ts +0 -159
  285. package/src/session/session-artifacts.ts +0 -106
  286. package/src/session/session-config-builder.ts +0 -113
  287. package/src/session/session-graph.ts +0 -92
  288. package/src/session/session-host.test.ts +0 -29
  289. package/src/session/session-host.ts +0 -242
  290. package/src/session/session-manager.ts +0 -69
  291. package/src/session/session-manifest.ts +0 -29
  292. package/src/session/session-service.team-persistence.test.ts +0 -48
  293. package/src/session/session-service.ts +0 -673
  294. package/src/session/session-team-coordination.ts +0 -229
  295. package/src/session/session-telemetry.ts +0 -95
  296. package/src/session/sqlite-rpc-session-backend.ts +0 -303
  297. package/src/session/unified-session-persistence-service.test.ts +0 -85
  298. package/src/session/unified-session-persistence-service.ts +0 -996
  299. package/src/session/utils/helpers.ts +0 -139
  300. package/src/session/utils/types.ts +0 -57
  301. package/src/session/utils/usage.ts +0 -32
  302. package/src/session/workspace-manager.ts +0 -98
  303. package/src/session/workspace-manifest.ts +0 -100
  304. package/src/storage/artifact-store.ts +0 -1
  305. package/src/storage/file-team-store.ts +0 -257
  306. package/src/storage/index.ts +0 -11
  307. package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
  308. package/src/storage/provider-settings-legacy-migration.ts +0 -689
  309. package/src/storage/provider-settings-manager.test.ts +0 -145
  310. package/src/storage/provider-settings-manager.ts +0 -150
  311. package/src/storage/session-store.ts +0 -1
  312. package/src/storage/sqlite-session-store.ts +0 -275
  313. package/src/storage/sqlite-team-store.ts +0 -454
  314. package/src/storage/team-store.ts +0 -40
  315. package/src/team/index.ts +0 -4
  316. package/src/team/projections.ts +0 -285
  317. package/src/telemetry/ITelemetryAdapter.ts +0 -94
  318. package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
  319. package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
  320. package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
  321. package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
  322. package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
  323. package/src/telemetry/OpenTelemetryProvider.ts +0 -322
  324. package/src/telemetry/TelemetryService.test.ts +0 -134
  325. package/src/telemetry/TelemetryService.ts +0 -141
  326. package/src/telemetry/core-events.ts +0 -344
  327. package/src/telemetry/opentelemetry.ts +0 -20
  328. package/src/tools/constants.ts +0 -35
  329. package/src/tools/definitions.test.ts +0 -658
  330. package/src/tools/definitions.ts +0 -726
  331. package/src/tools/executors/apply-patch-parser.ts +0 -520
  332. package/src/tools/executors/apply-patch.ts +0 -359
  333. package/src/tools/executors/bash.ts +0 -205
  334. package/src/tools/executors/editor.test.ts +0 -35
  335. package/src/tools/executors/editor.ts +0 -219
  336. package/src/tools/executors/file-read.test.ts +0 -49
  337. package/src/tools/executors/file-read.ts +0 -110
  338. package/src/tools/executors/index.ts +0 -75
  339. package/src/tools/executors/search.ts +0 -278
  340. package/src/tools/executors/web-fetch.ts +0 -259
  341. package/src/tools/index.ts +0 -168
  342. package/src/tools/model-tool-routing.test.ts +0 -86
  343. package/src/tools/model-tool-routing.ts +0 -132
  344. package/src/tools/presets.test.ts +0 -62
  345. package/src/tools/presets.ts +0 -168
  346. package/src/tools/schemas.ts +0 -284
  347. package/src/tools/types.ts +0 -328
  348. package/src/types/common.ts +0 -14
  349. package/src/types/config.ts +0 -84
  350. package/src/types/events.ts +0 -74
  351. package/src/types/index.ts +0 -24
  352. package/src/types/provider-settings.ts +0 -43
  353. package/src/types/sessions.ts +0 -16
  354. package/src/types/storage.ts +0 -64
  355. package/src/types/workspace.ts +0 -7
  356. package/src/types.ts +0 -128
@@ -1,673 +0,0 @@
1
- import {
2
- appendFileSync,
3
- existsSync,
4
- mkdirSync,
5
- readFileSync,
6
- renameSync,
7
- unlinkSync,
8
- writeFileSync,
9
- } from "node:fs";
10
- import { join } from "node:path";
11
- import type {
12
- AgentTeamsRuntime,
13
- TeamEvent,
14
- TeamTeammateSpec,
15
- } from "@clinebot/agents";
16
- import { resolveTeamDataDir } from "@clinebot/shared/storage";
17
- import type { SqliteSessionStore } from "../storage/sqlite-session-store";
18
- import type { SessionSource, SessionStatus } from "../types/common";
19
- import { nowIso } from "./session-artifacts";
20
- import type { SessionManifest } from "./session-manifest";
21
- import type {
22
- PersistedSessionUpdateInput,
23
- SessionPersistenceAdapter,
24
- } from "./unified-session-persistence-service";
25
- import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
26
-
27
- export interface SessionRow {
28
- sessionId: string;
29
- source: string;
30
- pid: number;
31
- startedAt: string;
32
- endedAt?: string | null;
33
- exitCode?: number | null;
34
- status: SessionStatus;
35
- statusLock: number;
36
- interactive: boolean;
37
- provider: string;
38
- model: string;
39
- cwd: string;
40
- workspaceRoot: string;
41
- teamName?: string | null;
42
- enableTools: boolean;
43
- enableSpawn: boolean;
44
- enableTeams: boolean;
45
- parentSessionId?: string | null;
46
- parentAgentId?: string | null;
47
- agentId?: string | null;
48
- conversationId?: string | null;
49
- isSubagent: boolean;
50
- prompt?: string | null;
51
- metadata?: Record<string, unknown> | null;
52
- transcriptPath: string;
53
- hookPath: string;
54
- messagesPath?: string | null;
55
- updatedAt: string;
56
- }
57
-
58
- export interface CreateRootSessionInput {
59
- sessionId: string;
60
- source: SessionSource;
61
- pid: number;
62
- startedAt: string;
63
- interactive: boolean;
64
- provider: string;
65
- model: string;
66
- cwd: string;
67
- workspaceRoot: string;
68
- teamName?: string;
69
- enableTools: boolean;
70
- enableSpawn: boolean;
71
- enableTeams: boolean;
72
- prompt?: string;
73
- metadata?: Record<string, unknown>;
74
- transcriptPath: string;
75
- hookPath: string;
76
- messagesPath: string;
77
- }
78
-
79
- export interface CreateRootSessionWithArtifactsInput {
80
- sessionId: string;
81
- source: SessionSource;
82
- pid: number;
83
- interactive: boolean;
84
- provider: string;
85
- model: string;
86
- cwd: string;
87
- workspaceRoot: string;
88
- teamName?: string;
89
- enableTools: boolean;
90
- enableSpawn: boolean;
91
- enableTeams: boolean;
92
- prompt?: string;
93
- metadata?: Record<string, unknown>;
94
- startedAt?: string;
95
- }
96
-
97
- export interface RootSessionArtifacts {
98
- manifestPath: string;
99
- transcriptPath: string;
100
- hookPath: string;
101
- messagesPath: string;
102
- manifest: SessionManifest;
103
- }
104
-
105
- export interface UpsertSubagentInput {
106
- agentId: string;
107
- parentAgentId: string;
108
- conversationId: string;
109
- prompt?: string;
110
- rootSessionId?: string;
111
- }
112
-
113
- // ── SQLite helpers ───────────────────────────────────────────────────
114
-
115
- /** SELECT clause that aliases snake_case columns to camelCase SessionRow keys. */
116
- const SESSION_SELECT_COLUMNS = `
117
- session_id AS sessionId,
118
- source,
119
- pid,
120
- started_at AS startedAt,
121
- ended_at AS endedAt,
122
- exit_code AS exitCode,
123
- status,
124
- status_lock AS statusLock,
125
- interactive,
126
- provider,
127
- model,
128
- cwd,
129
- workspace_root AS workspaceRoot,
130
- team_name AS teamName,
131
- enable_tools AS enableTools,
132
- enable_spawn AS enableSpawn,
133
- enable_teams AS enableTeams,
134
- parent_session_id AS parentSessionId,
135
- parent_agent_id AS parentAgentId,
136
- agent_id AS agentId,
137
- conversation_id AS conversationId,
138
- is_subagent AS isSubagent,
139
- prompt,
140
- metadata_json AS metadata,
141
- transcript_path AS transcriptPath,
142
- hook_path AS hookPath,
143
- messages_path AS messagesPath,
144
- updated_at AS updatedAt`;
145
-
146
- /**
147
- * Patch a raw SQLite result into a proper SessionRow.
148
- * SQLite returns 0/1 for booleans and a JSON string for metadata —
149
- * this converts them in-place to avoid allocating a second object.
150
- */
151
- function patchSqliteRow(raw: Record<string, unknown>): SessionRow {
152
- raw.interactive = raw.interactive === 1;
153
- raw.enableTools = raw.enableTools === 1;
154
- raw.enableSpawn = raw.enableSpawn === 1;
155
- raw.enableTeams = raw.enableTeams === 1;
156
- raw.isSubagent = raw.isSubagent === 1;
157
- const meta = raw.metadata;
158
- if (typeof meta === "string" && meta.trim()) {
159
- try {
160
- const parsed = JSON.parse(meta) as unknown;
161
- raw.metadata =
162
- parsed && typeof parsed === "object" && !Array.isArray(parsed)
163
- ? parsed
164
- : null;
165
- } catch {
166
- raw.metadata = null;
167
- }
168
- } else {
169
- raw.metadata = null;
170
- }
171
- return raw as unknown as SessionRow;
172
- }
173
-
174
- function stringifyMetadata(
175
- metadata: Record<string, unknown> | null | undefined,
176
- ): string | null {
177
- if (!metadata || Object.keys(metadata).length === 0) return null;
178
- return JSON.stringify(metadata);
179
- }
180
-
181
- function reviveTeamStateDates(state: TeamRuntimeState): TeamRuntimeState {
182
- return {
183
- ...state,
184
- tasks: state.tasks.map((task) => ({
185
- ...task,
186
- createdAt: new Date(task.createdAt),
187
- updatedAt: new Date(task.updatedAt),
188
- })),
189
- mailbox: state.mailbox.map((message) => ({
190
- ...message,
191
- sentAt: new Date(message.sentAt),
192
- readAt: message.readAt ? new Date(message.readAt) : undefined,
193
- })),
194
- missionLog: state.missionLog.map((entry) => ({
195
- ...entry,
196
- ts: new Date(entry.ts),
197
- })),
198
- runs: (state.runs ?? []).map((run) => ({
199
- ...run,
200
- startedAt: new Date(run.startedAt),
201
- endedAt: run.endedAt ? new Date(run.endedAt) : undefined,
202
- nextAttemptAt: run.nextAttemptAt
203
- ? new Date(run.nextAttemptAt)
204
- : undefined,
205
- heartbeatAt: run.heartbeatAt ? new Date(run.heartbeatAt) : undefined,
206
- })),
207
- outcomes: (state.outcomes ?? []).map((outcome) => ({
208
- ...outcome,
209
- createdAt: new Date(outcome.createdAt),
210
- finalizedAt: outcome.finalizedAt
211
- ? new Date(outcome.finalizedAt)
212
- : undefined,
213
- })),
214
- outcomeFragments: (state.outcomeFragments ?? []).map((fragment) => ({
215
- ...fragment,
216
- createdAt: new Date(fragment.createdAt),
217
- reviewedAt: fragment.reviewedAt
218
- ? new Date(fragment.reviewedAt)
219
- : undefined,
220
- })),
221
- };
222
- }
223
-
224
- function sanitizeTeamName(name: string): string {
225
- return name
226
- .toLowerCase()
227
- .replace(/[^a-z0-9._-]+/g, "-")
228
- .replace(/^-+|-+$/g, "");
229
- }
230
-
231
- interface PersistedTeamEnvelope {
232
- version: 1;
233
- updatedAt: string;
234
- teamState: TeamRuntimeState;
235
- teammates: TeamTeammateSpec[];
236
- }
237
-
238
- type TeamRuntimeState = ReturnType<AgentTeamsRuntime["exportState"]>;
239
-
240
- export interface FileTeamPersistenceStoreOptions {
241
- teamName: string;
242
- baseDir?: string;
243
- }
244
-
245
- export class FileTeamPersistenceStore {
246
- private readonly dirPath: string;
247
- private readonly statePath: string;
248
- private readonly taskHistoryPath: string;
249
- private readonly teammateSpecs: Map<string, TeamTeammateSpec> = new Map();
250
-
251
- constructor(options: FileTeamPersistenceStoreOptions) {
252
- const safeTeamName = sanitizeTeamName(options.teamName);
253
- const baseDir = options.baseDir?.trim() || resolveTeamDataDir();
254
- this.dirPath = join(baseDir, safeTeamName);
255
- this.statePath = join(this.dirPath, "state.json");
256
- this.taskHistoryPath = join(this.dirPath, "task-history.jsonl");
257
- }
258
-
259
- loadState(): TeamRuntimeState | undefined {
260
- if (!existsSync(this.statePath)) {
261
- return undefined;
262
- }
263
- try {
264
- const raw = readFileSync(this.statePath, "utf8");
265
- const parsed = JSON.parse(raw) as PersistedTeamEnvelope;
266
- if (parsed.version !== 1 || !parsed.teamState) {
267
- return undefined;
268
- }
269
- for (const spec of parsed.teammates ?? []) {
270
- this.teammateSpecs.set(spec.agentId, spec);
271
- }
272
- return reviveTeamStateDates(parsed.teamState);
273
- } catch {
274
- return undefined;
275
- }
276
- }
277
-
278
- getTeammateSpecs(): TeamTeammateSpec[] {
279
- return Array.from(this.teammateSpecs.values());
280
- }
281
-
282
- upsertTeammateSpec(spec: TeamTeammateSpec): void {
283
- this.teammateSpecs.set(spec.agentId, spec);
284
- }
285
-
286
- removeTeammateSpec(agentId: string): void {
287
- this.teammateSpecs.delete(agentId);
288
- }
289
-
290
- persist(runtime: AgentTeamsRuntime): void {
291
- if (!this.hasPersistableState(runtime)) {
292
- this.clearPersistedState();
293
- return;
294
- }
295
- this.ensureDir();
296
- const envelope: PersistedTeamEnvelope = {
297
- version: 1,
298
- updatedAt: new Date().toISOString(),
299
- teamState: runtime.exportState(),
300
- teammates: Array.from(this.teammateSpecs.values()),
301
- };
302
- const tmpPath = `${this.statePath}.tmp`;
303
- writeFileSync(tmpPath, `${JSON.stringify(envelope, null, 2)}\n`, "utf8");
304
- renameSync(tmpPath, this.statePath);
305
- }
306
-
307
- appendTaskHistory(event: TeamEvent): void {
308
- let task: Record<string, unknown> = {};
309
- switch (event.type) {
310
- case "team_task_updated":
311
- task = event.task as unknown as Record<string, unknown>;
312
- break;
313
- case "team_message":
314
- task = {
315
- agentId: event.message.fromAgentId,
316
- toAgentId: event.message.toAgentId,
317
- subject: event.message.subject,
318
- taskId: event.message.taskId,
319
- };
320
- break;
321
- case "team_mission_log":
322
- task = {
323
- agentId: event.entry.agentId,
324
- kind: event.entry.kind,
325
- summary: event.entry.summary,
326
- taskId: event.entry.taskId,
327
- };
328
- break;
329
- case "teammate_spawned":
330
- case "teammate_shutdown":
331
- case "task_start":
332
- task = {
333
- agentId: event.agentId,
334
- message: "message" in event ? event.message : undefined,
335
- };
336
- break;
337
- case "task_end":
338
- task = {
339
- agentId: event.agentId,
340
- finishReason: event.result?.finishReason,
341
- error: event.error?.message,
342
- };
343
- break;
344
- case "agent_event":
345
- task = {
346
- agentId: event.agentId,
347
- eventType: event.event.type,
348
- };
349
- break;
350
- }
351
- this.ensureDir();
352
- appendFileSync(
353
- this.taskHistoryPath,
354
- `${JSON.stringify({
355
- ts: new Date().toISOString(),
356
- type: event.type,
357
- task,
358
- })}\n`,
359
- "utf8",
360
- );
361
- }
362
-
363
- private ensureDir(): void {
364
- if (!existsSync(this.dirPath)) {
365
- mkdirSync(this.dirPath, { recursive: true });
366
- }
367
- }
368
-
369
- private hasPersistableState(runtime: AgentTeamsRuntime): boolean {
370
- const state = runtime.exportState();
371
- if (this.teammateSpecs.size > 0) {
372
- return true;
373
- }
374
- if (state.members.some((member) => member.role === "teammate")) {
375
- return true;
376
- }
377
- return (
378
- state.tasks.length > 0 ||
379
- state.mailbox.length > 0 ||
380
- state.missionLog.length > 0
381
- );
382
- }
383
-
384
- private clearPersistedState(): void {
385
- if (existsSync(this.statePath)) {
386
- unlinkSync(this.statePath);
387
- }
388
- }
389
- }
390
-
391
- class LocalSessionPersistenceAdapter implements SessionPersistenceAdapter {
392
- constructor(private readonly store: SqliteSessionStore) {}
393
-
394
- ensureSessionsDir(): string {
395
- return this.store.ensureSessionsDir();
396
- }
397
-
398
- async upsertSession(row: SessionRow): Promise<void> {
399
- this.store.run(
400
- `INSERT OR REPLACE INTO sessions (
401
- session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
402
- provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
403
- parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
404
- metadata_json, transcript_path, hook_path, messages_path, updated_at
405
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
406
- [
407
- row.sessionId,
408
- row.source,
409
- row.pid,
410
- row.startedAt,
411
- row.endedAt ?? null,
412
- row.exitCode ?? null,
413
- row.status,
414
- row.statusLock,
415
- row.interactive ? 1 : 0,
416
- row.provider,
417
- row.model,
418
- row.cwd,
419
- row.workspaceRoot,
420
- row.teamName ?? null,
421
- row.enableTools ? 1 : 0,
422
- row.enableSpawn ? 1 : 0,
423
- row.enableTeams ? 1 : 0,
424
- row.parentSessionId ?? null,
425
- row.parentAgentId ?? null,
426
- row.agentId ?? null,
427
- row.conversationId ?? null,
428
- row.isSubagent ? 1 : 0,
429
- row.prompt ?? null,
430
- stringifyMetadata(row.metadata),
431
- row.transcriptPath,
432
- row.hookPath,
433
- row.messagesPath ?? null,
434
- row.updatedAt,
435
- ],
436
- );
437
- }
438
-
439
- async getSession(sessionId: string): Promise<SessionRow | undefined> {
440
- const row = this.store.queryOne<Record<string, unknown>>(
441
- `SELECT ${SESSION_SELECT_COLUMNS} FROM sessions WHERE session_id = ?`,
442
- [sessionId],
443
- );
444
- return row ? patchSqliteRow(row) : undefined;
445
- }
446
-
447
- async listSessions(options: {
448
- limit: number;
449
- parentSessionId?: string;
450
- status?: string;
451
- }): Promise<SessionRow[]> {
452
- const whereClauses: string[] = [];
453
- const params: unknown[] = [];
454
- if (options.parentSessionId) {
455
- whereClauses.push("parent_session_id = ?");
456
- params.push(options.parentSessionId);
457
- }
458
- if (options.status) {
459
- whereClauses.push("status = ?");
460
- params.push(options.status);
461
- }
462
- const where =
463
- whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
464
- return this.store
465
- .queryAll<Record<string, unknown>>(
466
- `SELECT ${SESSION_SELECT_COLUMNS}
467
- FROM sessions
468
- ${where}
469
- ORDER BY started_at DESC
470
- LIMIT ?`,
471
- [...params, options.limit],
472
- )
473
- .map(patchSqliteRow);
474
- }
475
-
476
- async updateSession(
477
- input: PersistedSessionUpdateInput,
478
- ): Promise<{ updated: boolean; statusLock: number }> {
479
- if (input.setRunning) {
480
- if (input.expectedStatusLock === undefined) {
481
- return { updated: false, statusLock: 0 };
482
- }
483
- const changed = this.store.run(
484
- `UPDATE sessions
485
- SET status = 'running', ended_at = NULL, exit_code = NULL, updated_at = ?, status_lock = ?,
486
- parent_session_id = ?, parent_agent_id = ?, agent_id = ?, conversation_id = ?, is_subagent = 1,
487
- prompt = COALESCE(prompt, ?)
488
- WHERE session_id = ? AND status_lock = ?`,
489
- [
490
- nowIso(),
491
- input.expectedStatusLock + 1,
492
- input.parentSessionId ?? null,
493
- input.parentAgentId ?? null,
494
- input.agentId ?? null,
495
- input.conversationId ?? null,
496
- input.prompt ?? null,
497
- input.sessionId,
498
- input.expectedStatusLock,
499
- ],
500
- );
501
- return {
502
- updated: (changed.changes ?? 0) > 0,
503
- statusLock: input.expectedStatusLock + 1,
504
- };
505
- }
506
-
507
- const fields: string[] = [];
508
- const params: unknown[] = [];
509
- if (input.status !== undefined) {
510
- fields.push("status = ?");
511
- params.push(input.status);
512
- }
513
- if (input.endedAt !== undefined) {
514
- fields.push("ended_at = ?");
515
- params.push(input.endedAt);
516
- }
517
- if (input.exitCode !== undefined) {
518
- fields.push("exit_code = ?");
519
- params.push(input.exitCode);
520
- }
521
- if (input.prompt !== undefined) {
522
- fields.push("prompt = ?");
523
- params.push(input.prompt ?? null);
524
- }
525
- if (input.metadata !== undefined) {
526
- fields.push("metadata_json = ?");
527
- params.push(stringifyMetadata(input.metadata));
528
- }
529
- if (input.parentSessionId !== undefined) {
530
- fields.push("parent_session_id = ?");
531
- params.push(input.parentSessionId ?? null);
532
- }
533
- if (input.parentAgentId !== undefined) {
534
- fields.push("parent_agent_id = ?");
535
- params.push(input.parentAgentId ?? null);
536
- }
537
- if (input.agentId !== undefined) {
538
- fields.push("agent_id = ?");
539
- params.push(input.agentId ?? null);
540
- }
541
- if (input.conversationId !== undefined) {
542
- fields.push("conversation_id = ?");
543
- params.push(input.conversationId ?? null);
544
- }
545
- if (fields.length === 0) {
546
- const row = await this.getSession(input.sessionId);
547
- return { updated: !!row, statusLock: row?.statusLock ?? 0 };
548
- }
549
-
550
- let statusLock = 0;
551
- if (input.expectedStatusLock !== undefined) {
552
- statusLock = input.expectedStatusLock + 1;
553
- fields.push("status_lock = ?");
554
- params.push(statusLock);
555
- }
556
- fields.push("updated_at = ?");
557
- params.push(nowIso());
558
-
559
- let sql = `UPDATE sessions SET ${fields.join(", ")} WHERE session_id = ?`;
560
- params.push(input.sessionId);
561
- if (input.expectedStatusLock !== undefined) {
562
- sql += " AND status_lock = ?";
563
- params.push(input.expectedStatusLock);
564
- }
565
- const changed = this.store.run(sql, params);
566
- if ((changed.changes ?? 0) === 0) {
567
- return { updated: false, statusLock: 0 };
568
- }
569
- if (input.expectedStatusLock === undefined) {
570
- const row = await this.getSession(input.sessionId);
571
- statusLock = row?.statusLock ?? 0;
572
- }
573
- return { updated: true, statusLock };
574
- }
575
-
576
- async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
577
- const changed =
578
- this.store.run(`DELETE FROM sessions WHERE session_id = ?`, [sessionId])
579
- .changes ?? 0;
580
- if (cascade) {
581
- this.store.run(`DELETE FROM sessions WHERE parent_session_id = ?`, [
582
- sessionId,
583
- ]);
584
- }
585
- return changed > 0;
586
- }
587
-
588
- async enqueueSpawnRequest(input: {
589
- rootSessionId: string;
590
- parentAgentId: string;
591
- task?: string;
592
- systemPrompt?: string;
593
- }): Promise<void> {
594
- this.store.run(
595
- `INSERT INTO subagent_spawn_queue (root_session_id, parent_agent_id, task, system_prompt, created_at, consumed_at)
596
- VALUES (?, ?, ?, ?, ?, NULL)`,
597
- [
598
- input.rootSessionId,
599
- input.parentAgentId,
600
- input.task ?? null,
601
- input.systemPrompt ?? null,
602
- nowIso(),
603
- ],
604
- );
605
- }
606
-
607
- async claimSpawnRequest(
608
- rootSessionId: string,
609
- parentAgentId: string,
610
- ): Promise<string | undefined> {
611
- const row = this.store.queryOne<{ id?: number; task?: string | null }>(
612
- `SELECT id, task FROM subagent_spawn_queue
613
- WHERE root_session_id = ? AND parent_agent_id = ? AND consumed_at IS NULL
614
- ORDER BY id ASC LIMIT 1`,
615
- [rootSessionId, parentAgentId],
616
- );
617
- if (!row || typeof row.id !== "number") {
618
- return undefined;
619
- }
620
- this.store.run(
621
- `UPDATE subagent_spawn_queue SET consumed_at = ? WHERE id = ?`,
622
- [nowIso(), row.id],
623
- );
624
- return row.task ?? undefined;
625
- }
626
- }
627
-
628
- export class CoreSessionService extends UnifiedSessionPersistenceService {
629
- constructor(private readonly store: SqliteSessionStore) {
630
- super(new LocalSessionPersistenceAdapter(store));
631
- }
632
-
633
- createRootSession(input: CreateRootSessionInput): void {
634
- this.store.run(
635
- `INSERT OR REPLACE INTO sessions (
636
- session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
637
- provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
638
- parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
639
- metadata_json, transcript_path, hook_path, messages_path, updated_at
640
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
641
- [
642
- input.sessionId,
643
- input.source,
644
- input.pid,
645
- input.startedAt,
646
- null,
647
- null,
648
- "running",
649
- 0,
650
- input.interactive ? 1 : 0,
651
- input.provider,
652
- input.model,
653
- input.cwd,
654
- input.workspaceRoot,
655
- input.teamName ?? null,
656
- input.enableTools ? 1 : 0,
657
- input.enableSpawn ? 1 : 0,
658
- input.enableTeams ? 1 : 0,
659
- null,
660
- null,
661
- null,
662
- null,
663
- 0,
664
- input.prompt ?? null,
665
- input.metadata ? JSON.stringify(input.metadata) : null,
666
- input.transcriptPath,
667
- input.hookPath,
668
- input.messagesPath,
669
- nowIso(),
670
- ],
671
- );
672
- }
673
- }