@clinebot/core 0.0.20 → 0.0.22

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,280 +0,0 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- readFileSync,
5
- renameSync,
6
- writeFileSync,
7
- } from "node:fs";
8
- import { join } from "node:path";
9
- import { resolveSessionDataDir } from "@clinebot/shared/storage";
10
- import type { SessionRow } from "./session-service";
11
- import type {
12
- PersistedSessionUpdateInput,
13
- SessionPersistenceAdapter,
14
- } from "./unified-session-persistence-service";
15
- import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
16
-
17
- interface FileSessionIndex {
18
- version: 1;
19
- sessions: Record<string, SessionRow>;
20
- }
21
-
22
- interface FileSpawnRequest {
23
- id: number;
24
- rootSessionId: string;
25
- parentAgentId: string;
26
- task?: string;
27
- systemPrompt?: string;
28
- createdAt: string;
29
- consumedAt?: string;
30
- }
31
-
32
- interface FileSpawnQueue {
33
- version: 1;
34
- nextId: number;
35
- requests: FileSpawnRequest[];
36
- }
37
-
38
- function nowIso(): string {
39
- return new Date().toISOString();
40
- }
41
-
42
- function atomicWriteJson(path: string, value: unknown): void {
43
- const tempPath = `${path}.tmp`;
44
- writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
45
- renameSync(tempPath, path);
46
- }
47
-
48
- function defaultSessionsDir(): string {
49
- return resolveSessionDataDir();
50
- }
51
-
52
- class FileSessionPersistenceAdapter implements SessionPersistenceAdapter {
53
- constructor(
54
- private readonly sessionsDirPath: string = defaultSessionsDir(),
55
- ) {}
56
-
57
- ensureSessionsDir(): string {
58
- if (!existsSync(this.sessionsDirPath)) {
59
- mkdirSync(this.sessionsDirPath, { recursive: true });
60
- }
61
- return this.sessionsDirPath;
62
- }
63
-
64
- private indexPath(): string {
65
- return join(this.ensureSessionsDir(), "sessions.index.json");
66
- }
67
-
68
- private spawnQueuePath(): string {
69
- return join(this.ensureSessionsDir(), "subagent-spawn-queue.json");
70
- }
71
-
72
- private readIndex(): FileSessionIndex {
73
- const path = this.indexPath();
74
- if (!existsSync(path)) {
75
- return { version: 1, sessions: {} };
76
- }
77
- try {
78
- const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSessionIndex;
79
- if (parsed?.version === 1 && parsed.sessions) {
80
- return parsed;
81
- }
82
- } catch {
83
- // Ignore invalid persistence and fall back to an empty index.
84
- }
85
- return { version: 1, sessions: {} };
86
- }
87
-
88
- private writeIndex(index: FileSessionIndex): void {
89
- atomicWriteJson(this.indexPath(), index);
90
- }
91
-
92
- private readQueue(): FileSpawnQueue {
93
- const path = this.spawnQueuePath();
94
- if (!existsSync(path)) {
95
- return { version: 1, nextId: 1, requests: [] };
96
- }
97
- try {
98
- const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSpawnQueue;
99
- if (
100
- parsed?.version === 1 &&
101
- typeof parsed.nextId === "number" &&
102
- Array.isArray(parsed.requests)
103
- ) {
104
- return parsed;
105
- }
106
- } catch {
107
- // Ignore invalid persistence and fall back to an empty queue.
108
- }
109
- return { version: 1, nextId: 1, requests: [] };
110
- }
111
-
112
- private writeQueue(queue: FileSpawnQueue): void {
113
- atomicWriteJson(this.spawnQueuePath(), queue);
114
- }
115
-
116
- async upsertSession(row: SessionRow): Promise<void> {
117
- const index = this.readIndex();
118
- index.sessions[row.sessionId] = row;
119
- this.writeIndex(index);
120
- }
121
-
122
- async getSession(sessionId: string): Promise<SessionRow | undefined> {
123
- return this.readIndex().sessions[sessionId];
124
- }
125
-
126
- async listSessions(options: {
127
- limit: number;
128
- parentSessionId?: string;
129
- status?: string;
130
- }): Promise<SessionRow[]> {
131
- return Object.values(this.readIndex().sessions)
132
- .filter((row) =>
133
- options.parentSessionId !== undefined
134
- ? row.parentSessionId === options.parentSessionId
135
- : true,
136
- )
137
- .filter((row) =>
138
- options.status !== undefined ? row.status === options.status : true,
139
- )
140
- .sort((a, b) => b.startedAt.localeCompare(a.startedAt))
141
- .slice(0, options.limit);
142
- }
143
-
144
- async updateSession(
145
- input: PersistedSessionUpdateInput,
146
- ): Promise<{ updated: boolean; statusLock: number }> {
147
- const index = this.readIndex();
148
- const existing = index.sessions[input.sessionId];
149
- if (!existing) {
150
- return { updated: false, statusLock: 0 };
151
- }
152
- if (
153
- input.expectedStatusLock !== undefined &&
154
- existing.statusLock !== input.expectedStatusLock
155
- ) {
156
- return { updated: false, statusLock: existing.statusLock };
157
- }
158
-
159
- const nextStatusLock =
160
- input.expectedStatusLock !== undefined
161
- ? input.expectedStatusLock + 1
162
- : existing.statusLock;
163
- const next: SessionRow = {
164
- ...existing,
165
- status: input.status ?? existing.status,
166
- endedAt:
167
- input.endedAt !== undefined
168
- ? input.endedAt
169
- : (existing.endedAt ?? null),
170
- exitCode:
171
- input.exitCode !== undefined
172
- ? input.exitCode
173
- : (existing.exitCode ?? null),
174
- prompt:
175
- input.prompt !== undefined ? input.prompt : (existing.prompt ?? null),
176
- metadata:
177
- input.metadata !== undefined
178
- ? (input.metadata ?? null)
179
- : (existing.metadata ?? null),
180
- parentSessionId:
181
- input.parentSessionId !== undefined
182
- ? (input.parentSessionId ?? null)
183
- : (existing.parentSessionId ?? null),
184
- parentAgentId:
185
- input.parentAgentId !== undefined
186
- ? (input.parentAgentId ?? null)
187
- : (existing.parentAgentId ?? null),
188
- agentId:
189
- input.agentId !== undefined
190
- ? (input.agentId ?? null)
191
- : (existing.agentId ?? null),
192
- conversationId:
193
- input.conversationId !== undefined
194
- ? (input.conversationId ?? null)
195
- : (existing.conversationId ?? null),
196
- statusLock: nextStatusLock,
197
- isSubagent:
198
- input.setRunning || input.parentSessionId !== undefined
199
- ? true
200
- : existing.isSubagent,
201
- updatedAt: nowIso(),
202
- };
203
-
204
- if (input.setRunning) {
205
- next.status = "running";
206
- next.endedAt = null;
207
- next.exitCode = null;
208
- }
209
-
210
- index.sessions[input.sessionId] = next;
211
- this.writeIndex(index);
212
- return { updated: true, statusLock: next.statusLock };
213
- }
214
-
215
- async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
216
- const index = this.readIndex();
217
- const existing = index.sessions[sessionId];
218
- if (!existing) {
219
- return false;
220
- }
221
- delete index.sessions[sessionId];
222
- if (cascade) {
223
- for (const row of Object.values(index.sessions)) {
224
- if (row.parentSessionId === sessionId) {
225
- delete index.sessions[row.sessionId];
226
- }
227
- }
228
- }
229
- this.writeIndex(index);
230
- return true;
231
- }
232
-
233
- async enqueueSpawnRequest(input: {
234
- rootSessionId: string;
235
- parentAgentId: string;
236
- task?: string;
237
- systemPrompt?: string;
238
- }): Promise<void> {
239
- const queue = this.readQueue();
240
- queue.requests.push({
241
- id: queue.nextId,
242
- rootSessionId: input.rootSessionId,
243
- parentAgentId: input.parentAgentId,
244
- task: input.task,
245
- systemPrompt: input.systemPrompt,
246
- createdAt: nowIso(),
247
- });
248
- queue.nextId += 1;
249
- this.writeQueue(queue);
250
- }
251
-
252
- async claimSpawnRequest(
253
- rootSessionId: string,
254
- parentAgentId: string,
255
- ): Promise<string | undefined> {
256
- const queue = this.readQueue();
257
- const request = queue.requests.find(
258
- (item) =>
259
- item.rootSessionId === rootSessionId &&
260
- item.parentAgentId === parentAgentId &&
261
- !item.consumedAt,
262
- );
263
- if (!request) {
264
- return undefined;
265
- }
266
- request.consumedAt = nowIso();
267
- this.writeQueue(queue);
268
- return request.task;
269
- }
270
- }
271
-
272
- export class FileSessionService extends UnifiedSessionPersistenceService {
273
- constructor(sessionsDir?: string) {
274
- super(new FileSessionPersistenceAdapter(sessionsDir));
275
- }
276
-
277
- override ensureSessionsDir(): string {
278
- return super.ensureSessionsDir();
279
- }
280
- }
@@ -1,42 +0,0 @@
1
- export { DefaultSessionManager } from "./default-session-manager";
2
- export { RpcCoreSessionService } from "./rpc-session-service";
3
- export {
4
- deriveSubsessionStatus,
5
- makeSubSessionId,
6
- makeTeamTaskSubSessionId,
7
- sanitizeSessionToken,
8
- } from "./session-graph";
9
- export type {
10
- CreateSessionHostOptions,
11
- SessionBackend,
12
- SessionHost,
13
- } from "./session-host";
14
- export { createSessionHost, resolveSessionBackend } from "./session-host";
15
- export type {
16
- SendSessionInput,
17
- SessionAccumulatedUsage,
18
- SessionManager,
19
- StartSessionInput,
20
- StartSessionResult,
21
- } from "./session-manager";
22
- export type { SessionManifest } from "./session-manifest";
23
- export type {
24
- CreateRootSessionWithArtifactsInput,
25
- RootSessionArtifacts,
26
- } from "./session-service";
27
- export { CoreSessionService } from "./session-service";
28
- export type {
29
- WorkspaceManager,
30
- WorkspaceManagerEvent,
31
- } from "./workspace-manager";
32
- export { InMemoryWorkspaceManager } from "./workspace-manager";
33
- export type { WorkspaceManifest } from "./workspace-manifest";
34
- export {
35
- buildWorkspaceMetadata,
36
- emptyWorkspaceManifest,
37
- generateWorkspaceInfo,
38
- normalizeWorkspacePath,
39
- upsertWorkspaceInfo,
40
- WorkspaceInfoSchema,
41
- WorkspaceManifestSchema,
42
- } from "./workspace-manifest";
@@ -1,107 +0,0 @@
1
- import { existsSync, mkdirSync } from "node:fs";
2
- import { RpcSessionClient, type RpcSessionRow } from "@clinebot/rpc";
3
- import type { SessionRow } from "./session-service";
4
- import type {
5
- PersistedSessionUpdateInput,
6
- SessionPersistenceAdapter,
7
- } from "./unified-session-persistence-service";
8
- import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
9
-
10
- // ── Adapter ──────────────────────────────────────────────────────────
11
-
12
- class RpcSessionPersistenceAdapter implements SessionPersistenceAdapter {
13
- constructor(private readonly client: RpcSessionClient) {}
14
-
15
- ensureSessionsDir(): string {
16
- return "";
17
- }
18
-
19
- async upsertSession(row: SessionRow): Promise<void> {
20
- await this.client.upsertSession(row as RpcSessionRow);
21
- }
22
-
23
- async getSession(sessionId: string): Promise<SessionRow | undefined> {
24
- const row = await this.client.getSession(sessionId);
25
- return (row as SessionRow | undefined) ?? undefined;
26
- }
27
-
28
- async listSessions(options: {
29
- limit: number;
30
- parentSessionId?: string;
31
- status?: string;
32
- }): Promise<SessionRow[]> {
33
- const rows = await this.client.listSessions(options);
34
- return rows as SessionRow[];
35
- }
36
-
37
- async updateSession(
38
- input: PersistedSessionUpdateInput,
39
- ): Promise<{ updated: boolean; statusLock: number }> {
40
- return this.client.updateSession({
41
- sessionId: input.sessionId,
42
- status: input.status,
43
- endedAt: input.endedAt,
44
- exitCode: input.exitCode,
45
- prompt: input.prompt,
46
- metadata: input.metadata,
47
- parentSessionId: input.parentSessionId,
48
- parentAgentId: input.parentAgentId,
49
- agentId: input.agentId,
50
- conversationId: input.conversationId,
51
- expectedStatusLock: input.expectedStatusLock,
52
- setRunning: input.setRunning,
53
- });
54
- }
55
-
56
- async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
57
- return this.client.deleteSession(sessionId, cascade);
58
- }
59
-
60
- async enqueueSpawnRequest(input: {
61
- rootSessionId: string;
62
- parentAgentId: string;
63
- task?: string;
64
- systemPrompt?: string;
65
- }): Promise<void> {
66
- await this.client.enqueueSpawnRequest(input);
67
- }
68
-
69
- async claimSpawnRequest(
70
- rootSessionId: string,
71
- parentAgentId: string,
72
- ): Promise<string | undefined> {
73
- return this.client.claimSpawnRequest(rootSessionId, parentAgentId);
74
- }
75
- }
76
-
77
- // ── Service ──────────────────────────────────────────────────────────
78
-
79
- export interface RpcCoreSessionServiceOptions {
80
- address?: string;
81
- sessionsDir: string;
82
- }
83
-
84
- export class RpcCoreSessionService extends UnifiedSessionPersistenceService {
85
- private readonly sessionsDirPath: string;
86
- private readonly client: RpcSessionClient;
87
-
88
- constructor(options: RpcCoreSessionServiceOptions) {
89
- const client = new RpcSessionClient({
90
- address: options.address?.trim() || "127.0.0.1:4317",
91
- });
92
- super(new RpcSessionPersistenceAdapter(client));
93
- this.sessionsDirPath = options.sessionsDir;
94
- this.client = client;
95
- }
96
-
97
- override ensureSessionsDir(): string {
98
- if (!existsSync(this.sessionsDirPath)) {
99
- mkdirSync(this.sessionsDirPath, { recursive: true });
100
- }
101
- return this.sessionsDirPath;
102
- }
103
-
104
- close(): void {
105
- this.client.close();
106
- }
107
- }
@@ -1,49 +0,0 @@
1
- import { mkdtempSync, rmSync } from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import { tryAcquireRpcSpawnLease } from "./rpc-spawn-lease";
6
-
7
- describe("tryAcquireRpcSpawnLease", () => {
8
- const tempDirs: string[] = [];
9
-
10
- afterEach(() => {
11
- delete process.env.CLINE_DATA_DIR;
12
- for (const dir of tempDirs.splice(0)) {
13
- rmSync(dir, { recursive: true, force: true });
14
- }
15
- });
16
-
17
- it("allows only one active lease per address", () => {
18
- const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
19
- tempDirs.push(dataDir);
20
- process.env.CLINE_DATA_DIR = dataDir;
21
-
22
- const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
23
- const second = tryAcquireRpcSpawnLease("127.0.0.1:4317");
24
-
25
- expect(first).toBeDefined();
26
- expect(second).toBeUndefined();
27
-
28
- first?.release();
29
-
30
- const third = tryAcquireRpcSpawnLease("127.0.0.1:4317");
31
- expect(third).toBeDefined();
32
- third?.release();
33
- });
34
-
35
- it("lets different addresses acquire independent leases", () => {
36
- const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
37
- tempDirs.push(dataDir);
38
- process.env.CLINE_DATA_DIR = dataDir;
39
-
40
- const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
41
- const second = tryAcquireRpcSpawnLease("127.0.0.1:4318");
42
-
43
- expect(first).toBeDefined();
44
- expect(second).toBeDefined();
45
-
46
- first?.release();
47
- second?.release();
48
- });
49
- });
@@ -1,122 +0,0 @@
1
- import {
2
- closeSync,
3
- existsSync,
4
- mkdirSync,
5
- openSync,
6
- readFileSync,
7
- rmSync,
8
- writeFileSync,
9
- } from "node:fs";
10
- import { dirname, resolve } from "node:path";
11
- import { resolveSessionDataDir } from "@clinebot/shared/storage";
12
-
13
- const DEFAULT_LEASE_TTL_MS = 15_000;
14
-
15
- interface RpcSpawnLeaseRecord {
16
- address: string;
17
- pid: number;
18
- createdAt: number;
19
- }
20
-
21
- export interface RpcSpawnLease {
22
- path: string;
23
- release: () => void;
24
- }
25
-
26
- function encodeAddress(address: string): string {
27
- return Buffer.from(address).toString("base64url");
28
- }
29
-
30
- function getLeasePath(address: string): string {
31
- return resolve(
32
- resolveSessionDataDir(),
33
- "rpc",
34
- "spawn-leases",
35
- `${encodeAddress(address)}.lock`,
36
- );
37
- }
38
-
39
- function isProcessAlive(pid: number): boolean {
40
- if (!Number.isInteger(pid) || pid <= 0) {
41
- return false;
42
- }
43
- try {
44
- process.kill(pid, 0);
45
- return true;
46
- } catch {
47
- return false;
48
- }
49
- }
50
-
51
- function shouldClearLease(path: string, ttlMs: number): boolean {
52
- try {
53
- const raw = readFileSync(path, "utf8");
54
- const parsed = JSON.parse(raw) as Partial<RpcSpawnLeaseRecord>;
55
- const createdAt = Number(parsed.createdAt ?? 0);
56
- if (!Number.isFinite(createdAt) || createdAt <= 0) {
57
- return true;
58
- }
59
- if (Date.now() - createdAt > ttlMs) {
60
- return true;
61
- }
62
- return !isProcessAlive(Number(parsed.pid ?? 0));
63
- } catch {
64
- return true;
65
- }
66
- }
67
-
68
- export function tryAcquireRpcSpawnLease(
69
- address: string,
70
- options?: { ttlMs?: number },
71
- ): RpcSpawnLease | undefined {
72
- const ttlMs = Math.max(1_000, options?.ttlMs ?? DEFAULT_LEASE_TTL_MS);
73
- const path = getLeasePath(address);
74
- mkdirSync(dirname(path), { recursive: true });
75
-
76
- if (existsSync(path) && shouldClearLease(path, ttlMs)) {
77
- rmSync(path, { force: true });
78
- }
79
-
80
- let fd: number | undefined;
81
- try {
82
- fd = openSync(path, "wx");
83
- const record: RpcSpawnLeaseRecord = {
84
- address,
85
- pid: process.pid,
86
- createdAt: Date.now(),
87
- };
88
- writeFileSync(fd, JSON.stringify(record), "utf8");
89
- } catch {
90
- if (typeof fd === "number") {
91
- try {
92
- closeSync(fd);
93
- } catch {
94
- // Best effort.
95
- }
96
- }
97
- return undefined;
98
- }
99
-
100
- let released = false;
101
- return {
102
- path,
103
- release: () => {
104
- if (released) {
105
- return;
106
- }
107
- released = true;
108
- try {
109
- if (typeof fd === "number") {
110
- closeSync(fd);
111
- }
112
- } catch {
113
- // Best effort.
114
- }
115
- try {
116
- rmSync(path, { force: true });
117
- } catch {
118
- // Best effort.
119
- }
120
- },
121
- };
122
- }