@idleware/ringi 0.4.0 → 0.6.0

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 (375) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -1
  3. package/target/dts/adapters/fs/index.d.ts +2 -0
  4. package/target/dts/adapters/fs/lock.d.ts +1 -0
  5. package/target/dts/adapters/fs/write.d.ts +5 -0
  6. package/target/dts/adapters/host-posix/group-state.d.ts +7 -0
  7. package/target/dts/adapters/host-posix/groups.d.ts +1 -0
  8. package/target/dts/adapters/host-posix/index.d.ts +2 -0
  9. package/target/dts/adapters/host-posix/launch.d.ts +7 -0
  10. package/target/dts/adapters/host-posix/probes.d.ts +5 -0
  11. package/target/dts/adapters/host-posix/stats.d.ts +9 -0
  12. package/target/dts/adapters/keys-file/index.d.ts +2 -0
  13. package/target/dts/adapters/state-fs/index.d.ts +5 -0
  14. package/target/dts/adapters/tool-claude/index.d.ts +2 -0
  15. package/target/dts/adapters/tool-codex/index.d.ts +2 -0
  16. package/target/dts/adapters/tool-cursor/index.d.ts +2 -0
  17. package/target/dts/adapters/tool-traces/index.d.ts +3 -0
  18. package/target/dts/adapters/transport-git/branches.d.ts +43 -0
  19. package/target/dts/adapters/transport-git/files.d.ts +2 -0
  20. package/target/dts/adapters/transport-git/index.d.ts +32 -0
  21. package/target/dts/adapters/transport-git/marks.d.ts +20 -0
  22. package/target/dts/adapters/transport-git/remote/admit.d.ts +7 -0
  23. package/target/dts/adapters/transport-git/remote/alarms.d.ts +3 -0
  24. package/target/dts/adapters/transport-git/remote/bootstrap.d.ts +7 -0
  25. package/target/dts/adapters/transport-git/remote/branch-commit.d.ts +3 -0
  26. package/target/dts/adapters/transport-git/remote/branch-control.d.ts +15 -0
  27. package/target/dts/adapters/transport-git/remote/branch-scan.d.ts +2 -0
  28. package/target/dts/adapters/transport-git/remote/branch.d.ts +5 -0
  29. package/target/dts/adapters/transport-git/remote/cache.d.ts +3 -0
  30. package/target/dts/adapters/transport-git/remote/commits.d.ts +2 -0
  31. package/target/dts/adapters/transport-git/remote/forget.d.ts +2 -0
  32. package/target/dts/adapters/transport-git/remote/git.d.ts +26 -0
  33. package/target/dts/adapters/transport-git/remote/heartbeat-facts.d.ts +1 -0
  34. package/target/dts/adapters/transport-git/remote/heartbeat-name.d.ts +6 -0
  35. package/target/dts/adapters/transport-git/remote/heartbeat-object.d.ts +10 -0
  36. package/target/dts/adapters/transport-git/remote/heartbeat-push.d.ts +2 -0
  37. package/target/dts/adapters/transport-git/remote/heartbeat.d.ts +7 -0
  38. package/target/dts/adapters/transport-git/remote/keys.d.ts +13 -0
  39. package/target/dts/adapters/transport-git/remote/main.d.ts +11 -0
  40. package/target/dts/adapters/transport-git/remote/process.d.ts +20 -0
  41. package/target/dts/adapters/transport-git/remote/push-retry.d.ts +2 -0
  42. package/target/dts/adapters/transport-git/remote/push-validate.d.ts +2 -0
  43. package/target/dts/adapters/transport-git/remote/push.d.ts +16 -0
  44. package/target/dts/adapters/transport-git/remote/roster.d.ts +7 -0
  45. package/target/dts/adapters/transport-git/remote/signals.d.ts +15 -0
  46. package/target/dts/adapters/transport-git/remote/signature.d.ts +5 -0
  47. package/target/dts/adapters/transport-git/remote/sync-heartbeat.d.ts +2 -0
  48. package/target/dts/adapters/transport-git/remote/sync-rooms.d.ts +6 -0
  49. package/target/dts/adapters/transport-git/remote/sync-tags.d.ts +8 -0
  50. package/target/dts/adapters/transport-git/remote/sync.d.ts +2 -0
  51. package/target/dts/adapters/transport-git/remote/types.d.ts +64 -0
  52. package/target/dts/adapters/transport-git/remote.d.ts +17 -0
  53. package/target/dts/adapters/transport-git/repo.d.ts +31 -0
  54. package/target/dts/adapters/transport-git/run.d.ts +21 -0
  55. package/target/dts/adapters/transport-git/signing.d.ts +4 -0
  56. package/target/dts/adapters/transport-git/tags.d.ts +15 -0
  57. package/target/dts/adapters/transport-git/transport.d.ts +7 -0
  58. package/target/dts/adapters/transport-kafka/index.d.ts +2 -0
  59. package/target/dts/adapters/transport-temporal/index.d.ts +2 -0
  60. package/target/dts/cli.d.ts +2 -1
  61. package/target/dts/{cli/agent.d.ts → clients/cli/agent/index.d.ts} +3 -3
  62. package/target/dts/{cli → clients/cli/agent}/session.d.ts +2 -2
  63. package/target/dts/clients/cli/arg-parse.d.ts +2 -0
  64. package/target/dts/{cli → clients/cli}/args.d.ts +2 -2
  65. package/target/dts/clients/cli/commands.d.ts +2 -0
  66. package/target/dts/clients/cli/context.d.ts +4 -0
  67. package/target/dts/{cli/index.d.ts → clients/cli/help.d.ts} +1 -3
  68. package/target/dts/clients/cli/index.d.ts +4 -0
  69. package/target/dts/clients/cli/operator/heartbeat-format.d.ts +5 -0
  70. package/target/dts/clients/cli/operator/heartbeat.d.ts +3 -0
  71. package/target/dts/clients/cli/operator/hub-commands.d.ts +6 -0
  72. package/target/dts/clients/cli/operator/hub.d.ts +2 -0
  73. package/target/dts/clients/cli/operator/index.d.ts +5 -0
  74. package/target/dts/clients/cli/operator/room-lifecycle.d.ts +5 -0
  75. package/target/dts/clients/cli/operator/room-list.d.ts +5 -0
  76. package/target/dts/clients/cli/operator/room-members.d.ts +4 -0
  77. package/target/dts/clients/cli/operator/room.d.ts +2 -0
  78. package/target/dts/clients/cli/operator/sessions.d.ts +5 -0
  79. package/target/dts/clients/cli/operator/watch.d.ts +2 -0
  80. package/target/dts/clients/cli/operator/where-format.d.ts +7 -0
  81. package/target/dts/clients/cli/operator/where.d.ts +2 -0
  82. package/target/dts/clients/cli/shared/budget.d.ts +7 -0
  83. package/target/dts/clients/cli/shared/files.d.ts +4 -0
  84. package/target/dts/clients/cli/shared/index.d.ts +7 -0
  85. package/target/dts/clients/cli/shared/messages.d.ts +7 -0
  86. package/target/dts/clients/cli/shared/profile.d.ts +4 -0
  87. package/target/dts/clients/cli/shared/session.d.ts +6 -0
  88. package/target/dts/clients/cli/shared/signals.d.ts +3 -0
  89. package/target/dts/clients/cli/shared/work.d.ts +6 -0
  90. package/target/dts/clients/cli/skill/index.d.ts +3 -0
  91. package/target/dts/{cli/skill.d.ts → clients/cli/skill/targets.d.ts} +1 -2
  92. package/target/dts/composition/index.d.ts +2 -0
  93. package/target/dts/core/agents/heartbeat/index.d.ts +33 -0
  94. package/target/dts/core/agents/heartbeat/pulse.d.ts +32 -0
  95. package/target/dts/core/agents/heartbeat/singleton.d.ts +3 -0
  96. package/target/dts/core/agents/heartbeat/tools.d.ts +6 -0
  97. package/target/dts/{app → core/agents}/overview.d.ts +12 -6
  98. package/target/dts/core/agents/ports/host.d.ts +47 -0
  99. package/target/dts/core/agents/ports/index.d.ts +9 -0
  100. package/target/dts/core/agents/ports/tools.d.ts +18 -0
  101. package/target/dts/core/agents/sessions/agent.d.ts +70 -0
  102. package/target/dts/core/agents/sessions/binding.d.ts +9 -0
  103. package/target/dts/core/agents/sessions/context.d.ts +8 -0
  104. package/target/dts/{runtime/session.d.ts → core/agents/sessions/index.d.ts} +2 -9
  105. package/target/dts/core/agents/sessions/join.d.ts +20 -0
  106. package/target/dts/core/agents/sessions/resume.d.ts +2 -0
  107. package/target/dts/core/agents/sessions/session.d.ts +46 -0
  108. package/target/dts/core/agents/sessions/wait.d.ts +38 -0
  109. package/target/dts/core/agents/turns/budgets.d.ts +5 -0
  110. package/target/dts/core/agents/turns/dispatch.d.ts +9 -0
  111. package/target/dts/core/agents/turns/exhaustion.d.ts +11 -0
  112. package/target/dts/core/agents/turns/grants.d.ts +4 -0
  113. package/target/dts/core/agents/turns/index.d.ts +4 -0
  114. package/target/dts/core/agents/turns/limits.d.ts +2 -0
  115. package/target/dts/core/agents/turns/messages.d.ts +10 -0
  116. package/target/dts/core/agents/turns/pings.d.ts +5 -0
  117. package/target/dts/core/agents/turns/plan.d.ts +3 -0
  118. package/target/dts/core/agents/turns/poll.d.ts +8 -0
  119. package/target/dts/core/agents/turns/results.d.ts +3 -0
  120. package/target/dts/core/agents/turns/seat.d.ts +2 -0
  121. package/target/dts/core/agents/turns/types.d.ts +59 -0
  122. package/target/dts/core/hub/decisions/budget.d.ts +15 -0
  123. package/target/dts/core/hub/decisions/check.d.ts +6 -0
  124. package/target/dts/core/hub/decisions/index.d.ts +5 -0
  125. package/target/dts/core/hub/decisions/proposal.d.ts +38 -0
  126. package/target/dts/core/hub/decisions/usage.d.ts +12 -0
  127. package/target/dts/{runtime/reader.d.ts → core/hub/history/index.d.ts} +12 -6
  128. package/target/dts/core/hub/ports/index.d.ts +16 -0
  129. package/target/dts/core/hub/ports/state.d.ts +12 -0
  130. package/target/dts/{store/index.d.ts → core/hub/ports/store.d.ts} +58 -17
  131. package/target/dts/core/hub/protocol/index.d.ts +5 -0
  132. package/target/dts/{protocol/index.d.ts → core/hub/protocol/model.d.ts} +0 -25
  133. package/target/dts/core/hub/protocol/order.d.ts +2 -0
  134. package/target/dts/core/hub/protocol/reading.d.ts +8 -0
  135. package/target/dts/core/hub/protocol/text.d.ts +11 -0
  136. package/target/dts/core/hub/protocol/threads.d.ts +5 -0
  137. package/target/dts/core/hub/rooms/compat.d.ts +5 -0
  138. package/target/dts/core/hub/rooms/hubs.d.ts +14 -0
  139. package/target/dts/core/hub/rooms/index.d.ts +53 -0
  140. package/target/dts/core/hub/rooms/messages.d.ts +8 -0
  141. package/target/dts/core/hub/rooms/rooms.d.ts +10 -0
  142. package/target/dts/core/hub/signals/check.d.ts +3 -0
  143. package/target/dts/core/hub/signals/effective.d.ts +3 -0
  144. package/target/dts/core/hub/signals/index.d.ts +5 -0
  145. package/target/dts/core/hub/signals/marks.d.ts +4 -0
  146. package/target/dts/core/hub/signals/model.d.ts +28 -0
  147. package/target/dts/core/hub/signals/pins.d.ts +5 -0
  148. package/target/dts/{hub/signals.d.ts → core/hub/signals/write.d.ts} +1 -1
  149. package/target/dts/core/hub/usecases/actor.d.ts +6 -0
  150. package/target/dts/{app → core/hub/usecases}/budget.d.ts +5 -18
  151. package/target/dts/core/hub/usecases/config.d.ts +6 -0
  152. package/target/dts/{app → core/hub/usecases}/context.d.ts +3 -8
  153. package/target/dts/{app → core/hub/usecases}/hubs.d.ts +1 -1
  154. package/target/dts/core/hub/usecases/propose.d.ts +17 -0
  155. package/target/dts/{app → core/hub/usecases}/room.d.ts +8 -33
  156. package/target/dts/{app → core/hub/usecases}/rooms.d.ts +2 -6
  157. package/target/dts/core/hub/usecases/roster.d.ts +5 -0
  158. package/target/dts/core/hub/usecases/send.d.ts +21 -0
  159. package/target/dts/core/hub/usecases/staging.d.ts +8 -0
  160. package/target/dts/{app → core/hub/usecases}/view.d.ts +4 -4
  161. package/target/dts/{domain/profiles.d.ts → core/hub/work/index.d.ts} +3 -7
  162. package/target/dts/core/hub/work/parse.d.ts +2 -0
  163. package/target/dts/core/hub/work/task.d.ts +6 -0
  164. package/target/dts/core/signing/index.d.ts +35 -0
  165. package/target/dts/index.d.ts +8 -8
  166. package/target/dts/lib/fail.d.ts +8 -0
  167. package/target/dts/lib/index.d.ts +3 -11
  168. package/target/dts/lib/json.d.ts +1 -0
  169. package/target/esm/adapters/fs/index.js +5 -0
  170. package/target/esm/adapters/fs/lock.js +83 -0
  171. package/target/esm/adapters/fs/write.js +25 -0
  172. package/target/esm/adapters/host-posix/group-state.js +24 -0
  173. package/target/esm/adapters/host-posix/groups.js +43 -0
  174. package/target/esm/adapters/host-posix/index.js +35 -0
  175. package/target/esm/adapters/host-posix/launch.js +80 -0
  176. package/target/esm/adapters/host-posix/probes.js +66 -0
  177. package/target/esm/adapters/host-posix/stats.js +27 -0
  178. package/target/esm/adapters/keys-file/index.js +68 -0
  179. package/target/esm/adapters/state-fs/index.js +79 -0
  180. package/target/esm/adapters/tool-claude/index.js +32 -0
  181. package/target/esm/adapters/tool-codex/index.js +38 -0
  182. package/target/esm/adapters/tool-cursor/index.js +8 -0
  183. package/target/esm/adapters/tool-traces/index.js +18 -0
  184. package/target/esm/adapters/transport-git/branches.js +155 -0
  185. package/target/esm/adapters/transport-git/files.js +48 -0
  186. package/target/esm/adapters/transport-git/index.js +128 -0
  187. package/target/esm/adapters/transport-git/marks.js +88 -0
  188. package/target/esm/adapters/transport-git/remote/admit.js +71 -0
  189. package/target/esm/adapters/transport-git/remote/alarms.js +30 -0
  190. package/target/esm/adapters/transport-git/remote/bootstrap.js +47 -0
  191. package/target/esm/adapters/transport-git/remote/branch-commit.js +36 -0
  192. package/target/esm/adapters/transport-git/remote/branch-control.js +37 -0
  193. package/target/esm/adapters/transport-git/remote/branch-scan.js +28 -0
  194. package/target/esm/adapters/transport-git/remote/branch.js +37 -0
  195. package/target/esm/adapters/transport-git/remote/cache.js +23 -0
  196. package/target/esm/adapters/transport-git/remote/commits.js +25 -0
  197. package/target/esm/adapters/transport-git/remote/forget.js +35 -0
  198. package/target/esm/adapters/transport-git/remote/git.js +58 -0
  199. package/target/esm/adapters/transport-git/remote/heartbeat-facts.js +35 -0
  200. package/target/esm/adapters/transport-git/remote/heartbeat-name.js +19 -0
  201. package/target/esm/adapters/transport-git/remote/heartbeat-object.js +40 -0
  202. package/target/esm/adapters/transport-git/remote/heartbeat-push.js +44 -0
  203. package/target/esm/adapters/transport-git/remote/heartbeat.js +44 -0
  204. package/target/esm/adapters/transport-git/remote/keys.js +75 -0
  205. package/target/esm/adapters/transport-git/remote/main.js +41 -0
  206. package/target/esm/adapters/transport-git/remote/process.js +37 -0
  207. package/target/esm/adapters/transport-git/remote/push-retry.js +46 -0
  208. package/target/esm/adapters/transport-git/remote/push-validate.js +39 -0
  209. package/target/esm/adapters/transport-git/remote/push.js +62 -0
  210. package/target/esm/adapters/transport-git/remote/roster.js +48 -0
  211. package/target/esm/adapters/transport-git/remote/signals.js +63 -0
  212. package/target/esm/adapters/transport-git/remote/signature.js +56 -0
  213. package/target/esm/adapters/transport-git/remote/sync-heartbeat.js +26 -0
  214. package/target/esm/adapters/transport-git/remote/sync-rooms.js +38 -0
  215. package/target/esm/adapters/transport-git/remote/sync-tags.js +48 -0
  216. package/target/esm/adapters/transport-git/remote/sync.js +38 -0
  217. package/target/esm/adapters/transport-git/remote/types.js +10 -0
  218. package/target/esm/adapters/transport-git/remote.js +17 -0
  219. package/target/esm/adapters/transport-git/repo.js +115 -0
  220. package/target/esm/adapters/transport-git/run.js +57 -0
  221. package/target/esm/adapters/transport-git/signing.js +44 -0
  222. package/target/esm/adapters/transport-git/tags.js +21 -0
  223. package/target/esm/adapters/transport-git/transport.js +29 -0
  224. package/target/esm/adapters/transport-kafka/index.js +4 -0
  225. package/target/esm/adapters/transport-temporal/index.js +4 -0
  226. package/target/esm/cli.js +5 -4
  227. package/target/esm/{cli/agent.js → clients/cli/agent/index.js} +8 -7
  228. package/target/esm/{cli → clients/cli/agent}/session.js +13 -7
  229. package/target/esm/clients/cli/arg-parse.js +41 -0
  230. package/target/esm/{cli → clients/cli}/args.js +3 -36
  231. package/target/esm/clients/cli/commands.js +45 -0
  232. package/target/esm/clients/cli/context.js +6 -0
  233. package/target/esm/{cli/index.js → clients/cli/help.js} +6 -73
  234. package/target/esm/clients/cli/index.js +27 -0
  235. package/target/esm/clients/cli/operator/heartbeat-format.js +8 -0
  236. package/target/esm/clients/cli/operator/heartbeat.js +35 -0
  237. package/target/esm/clients/cli/operator/hub-commands.js +37 -0
  238. package/target/esm/clients/cli/operator/hub.js +10 -0
  239. package/target/esm/clients/cli/operator/index.js +8 -0
  240. package/target/esm/clients/cli/operator/room-lifecycle.js +23 -0
  241. package/target/esm/clients/cli/operator/room-list.js +27 -0
  242. package/target/esm/clients/cli/operator/room-members.js +15 -0
  243. package/target/esm/clients/cli/operator/room.js +15 -0
  244. package/target/esm/clients/cli/operator/sessions.js +32 -0
  245. package/target/esm/clients/cli/operator/watch.js +15 -0
  246. package/target/esm/clients/cli/operator/where-format.js +24 -0
  247. package/target/esm/clients/cli/operator/where.js +32 -0
  248. package/target/esm/clients/cli/shared/budget.js +50 -0
  249. package/target/esm/clients/cli/shared/files.js +26 -0
  250. package/target/esm/clients/cli/shared/index.js +10 -0
  251. package/target/esm/clients/cli/shared/messages.js +41 -0
  252. package/target/esm/clients/cli/shared/profile.js +17 -0
  253. package/target/esm/clients/cli/shared/session.js +8 -0
  254. package/target/esm/clients/cli/shared/signals.js +21 -0
  255. package/target/esm/clients/cli/shared/work.js +26 -0
  256. package/target/esm/clients/cli/skill/index.js +40 -0
  257. package/target/esm/clients/cli/skill/targets.js +20 -0
  258. package/target/esm/composition/index.js +34 -0
  259. package/target/esm/core/agents/heartbeat/index.js +43 -0
  260. package/target/esm/core/agents/heartbeat/pulse.js +86 -0
  261. package/target/esm/core/agents/heartbeat/singleton.js +38 -0
  262. package/target/esm/core/agents/heartbeat/tools.js +24 -0
  263. package/target/esm/{app → core/agents}/overview.js +15 -9
  264. package/target/esm/core/agents/ports/host.js +4 -0
  265. package/target/esm/core/agents/ports/index.js +7 -0
  266. package/target/esm/core/agents/ports/tools.js +5 -0
  267. package/target/esm/{app → core/agents/sessions}/agent.js +11 -43
  268. package/target/esm/core/agents/sessions/binding.js +43 -0
  269. package/target/esm/core/agents/sessions/context.js +11 -0
  270. package/target/esm/core/agents/sessions/index.js +59 -0
  271. package/target/esm/core/agents/sessions/join.js +55 -0
  272. package/target/esm/core/agents/sessions/resume.js +54 -0
  273. package/target/esm/core/agents/sessions/session.js +28 -0
  274. package/target/esm/core/agents/sessions/wait.js +47 -0
  275. package/target/esm/core/agents/turns/budgets.js +48 -0
  276. package/target/esm/core/agents/turns/dispatch.js +40 -0
  277. package/target/esm/core/agents/turns/exhaustion.js +16 -0
  278. package/target/esm/core/agents/turns/grants.js +36 -0
  279. package/target/esm/core/agents/turns/index.js +33 -0
  280. package/target/esm/core/agents/turns/limits.js +11 -0
  281. package/target/esm/core/agents/turns/messages.js +32 -0
  282. package/target/esm/core/agents/turns/pings.js +30 -0
  283. package/target/esm/core/agents/turns/plan.js +29 -0
  284. package/target/esm/core/agents/turns/poll.js +48 -0
  285. package/target/esm/core/agents/turns/results.js +40 -0
  286. package/target/esm/core/agents/turns/seat.js +44 -0
  287. package/target/esm/core/agents/turns/types.js +3 -0
  288. package/target/esm/{domain/index.js → core/hub/capabilities.js} +3 -3
  289. package/target/esm/core/hub/decisions/budget.js +40 -0
  290. package/target/esm/core/hub/decisions/check.js +43 -0
  291. package/target/esm/core/hub/decisions/index.js +10 -0
  292. package/target/esm/core/hub/decisions/proposal.js +73 -0
  293. package/target/esm/core/hub/decisions/usage.js +39 -0
  294. package/target/esm/core/hub/history/index.js +90 -0
  295. package/target/esm/core/hub/ports/index.js +10 -0
  296. package/target/esm/core/hub/ports/state.js +5 -0
  297. package/target/esm/core/hub/ports/store.js +10 -0
  298. package/target/esm/{protocol → core/hub/protocol}/files.js +4 -2
  299. package/target/esm/core/hub/protocol/index.js +9 -0
  300. package/target/esm/core/hub/protocol/model.js +15 -0
  301. package/target/esm/core/hub/protocol/order.js +39 -0
  302. package/target/esm/core/hub/protocol/reading.js +29 -0
  303. package/target/esm/core/hub/protocol/text.js +95 -0
  304. package/target/esm/core/hub/protocol/threads.js +52 -0
  305. package/target/esm/core/hub/rooms/compat.js +42 -0
  306. package/target/esm/core/hub/rooms/hubs.js +92 -0
  307. package/target/esm/core/hub/rooms/index.js +23 -0
  308. package/target/esm/core/hub/rooms/messages.js +47 -0
  309. package/target/esm/core/hub/rooms/rooms.js +84 -0
  310. package/target/esm/core/hub/signals/check.js +33 -0
  311. package/target/esm/core/hub/signals/effective.js +31 -0
  312. package/target/esm/core/hub/signals/index.js +23 -0
  313. package/target/esm/core/hub/signals/marks.js +30 -0
  314. package/target/esm/core/hub/signals/model.js +5 -0
  315. package/target/esm/core/hub/signals/pins.js +21 -0
  316. package/target/esm/{hub/signals.js → core/hub/signals/write.js} +4 -4
  317. package/target/esm/core/hub/usecases/actor.js +3 -0
  318. package/target/esm/core/hub/usecases/budget.js +78 -0
  319. package/target/esm/core/hub/usecases/config.js +5 -0
  320. package/target/esm/core/hub/usecases/context.js +13 -0
  321. package/target/esm/core/hub/usecases/hubs.js +95 -0
  322. package/target/esm/core/hub/usecases/propose.js +39 -0
  323. package/target/esm/core/hub/usecases/room.js +82 -0
  324. package/target/esm/{app → core/hub/usecases}/rooms.js +11 -63
  325. package/target/esm/core/hub/usecases/roster.js +47 -0
  326. package/target/esm/core/hub/usecases/send.js +78 -0
  327. package/target/esm/core/hub/usecases/staging.js +60 -0
  328. package/target/esm/{app → core/hub/usecases}/view.js +33 -33
  329. package/target/esm/core/hub/work/index.js +13 -0
  330. package/target/esm/core/hub/work/parse.js +37 -0
  331. package/target/esm/core/hub/work/task.js +68 -0
  332. package/target/esm/core/signing/index.js +4 -0
  333. package/target/esm/index.js +7 -6
  334. package/target/esm/lib/fail.js +18 -0
  335. package/target/esm/lib/index.js +20 -195
  336. package/target/esm/lib/json.js +81 -0
  337. package/target/dts/app/agent.d.ts +0 -109
  338. package/target/dts/app/session.d.ts +0 -65
  339. package/target/dts/cli/context.d.ts +0 -6
  340. package/target/dts/cli/operator.d.ts +0 -8
  341. package/target/dts/cli/shared.d.ts +0 -27
  342. package/target/dts/domain/decisions.d.ts +0 -65
  343. package/target/dts/domain/signals.d.ts +0 -37
  344. package/target/dts/home/index.d.ts +0 -21
  345. package/target/dts/hub/index.d.ts +0 -72
  346. package/target/dts/runtime/watch.d.ts +0 -17
  347. package/target/dts/store/git/index.d.ts +0 -79
  348. package/target/dts/store/git/remote.d.ts +0 -86
  349. package/target/dts/store/kafka/index.d.ts +0 -2
  350. package/target/dts/store/temporal/index.d.ts +0 -2
  351. package/target/esm/app/budget.js +0 -95
  352. package/target/esm/app/context.js +0 -16
  353. package/target/esm/app/hubs.js +0 -76
  354. package/target/esm/app/room.js +0 -163
  355. package/target/esm/app/session.js +0 -99
  356. package/target/esm/cli/context.js +0 -8
  357. package/target/esm/cli/operator.js +0 -157
  358. package/target/esm/cli/shared.js +0 -159
  359. package/target/esm/cli/skill.js +0 -54
  360. package/target/esm/domain/decisions.js +0 -178
  361. package/target/esm/domain/profiles.js +0 -96
  362. package/target/esm/domain/signals.js +0 -134
  363. package/target/esm/home/index.js +0 -88
  364. package/target/esm/hub/index.js +0 -224
  365. package/target/esm/protocol/index.js +0 -219
  366. package/target/esm/runtime/reader.js +0 -65
  367. package/target/esm/runtime/session.js +0 -116
  368. package/target/esm/runtime/watch.js +0 -321
  369. package/target/esm/store/git/index.js +0 -644
  370. package/target/esm/store/git/remote.js +0 -758
  371. package/target/esm/store/index.js +0 -15
  372. package/target/esm/store/kafka/index.js +0 -3
  373. package/target/esm/store/temporal/index.js +0 -3
  374. /package/target/dts/{domain/index.d.ts → core/hub/capabilities.d.ts} +0 -0
  375. /package/target/dts/{protocol → core/hub/protocol}/files.d.ts +0 -0
@@ -1,116 +0,0 @@
1
- // session: which chat is which, and which seat it holds. A seat is one (hub, room genesis, agent); it ends only with
2
- // leave or the operator's explicit takeover. Every agent command passes `bound()` first.
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import crypto from 'node:crypto';
6
- import { spawnSync } from 'node:child_process';
7
- import { HOME, guard, locked, readJson, writeJson } from '../home/index.js';
8
- import { openHub, openRoom, roomNames } from '../hub/index.js';
9
- import { errno, fail, stamp } from '../lib/index.js';
10
- export const LEASE = 60 * 60 * 1000;
11
- const detectProduct = () => {
12
- const env = process.env;
13
- if (env.CLAUDECODE === '1' || env.CLAUDE_CODE_SESSION_ID)
14
- return 'claude';
15
- if (Object.keys(env).some(k => k.startsWith('CODEX_')))
16
- return 'codex';
17
- if (Object.keys(env).some(k => k.startsWith('CURSOR_')))
18
- return 'cursor';
19
- return null;
20
- };
21
- const ancestry = () => {
22
- let pid = process.ppid;
23
- for (let i = 0; i < 12 && pid > 1; i++) {
24
- const r = spawnSync('ps', ['-o', 'ppid=,comm=', '-p', String(pid)], { encoding: 'utf8' });
25
- const m = r.status === 0 ? /^\s*(\d+)\s+(.*)$/.exec(String(r.stdout ?? '').trim()) : null;
26
- if (!m)
27
- return null;
28
- const comm = path.basename(m[2].trim()).toLowerCase();
29
- if (/^(claude|codex|cursor|cursor-agent)$/.test(comm))
30
- return { pid, product: comm.replace('-agent', '') };
31
- pid = Number(m[1]);
32
- }
33
- return null;
34
- };
35
- // A chat is known by a stable handle: RINGI_SESSION, else the chat id the UI exposes, else the UI process as a last
36
- // resort (ps may be denied in a sandbox; then RINGI_SESSION is required).
37
- export const whoAmI = () => {
38
- const env = process.env;
39
- const product = detectProduct();
40
- if (env.RINGI_SESSION)
41
- return { handle: `env:${env.RINGI_SESSION}`, product, pid: null };
42
- if (env.CLAUDE_CODE_SESSION_ID)
43
- return { handle: `claude:${env.CLAUDE_CODE_SESSION_ID}`, product: 'claude', pid: Number(env.CLAUDE_PID) || null };
44
- const a = ancestry() ?? fail('cannot tell which session this is: set RINGI_SESSION to a stable id of this chat (for Codex: its thread id) on every ringi command');
45
- return { handle: `pid:${a.pid}`, product: product ?? a.product, pid: a.pid };
46
- };
47
- const sessionsDir = () => path.join(HOME, 'sessions');
48
- const sessionFile = (handle) => path.join(sessionsDir(), `${handle.replace(/[^A-Za-z0-9._-]/g, '_').slice(0, 100)}-${crypto.createHash('sha256').update(handle).digest('hex').slice(0, 10)}.json`);
49
- export const allSessions = () => {
50
- let files = [];
51
- try {
52
- files = fs.readdirSync(sessionsDir()).filter(f => f.endsWith('.json'));
53
- }
54
- catch { }
55
- return files.map(f => readJson(path.join(sessionsDir(), f), null)).filter((s) => !!s?.handle);
56
- };
57
- export const readSession = (handle) => {
58
- const s = readJson(sessionFile(handle), null);
59
- return s?.handle === handle ? s : null;
60
- };
61
- export const saveSession = (s) => writeJson(sessionFile(s.handle), s);
62
- export const dropSession = (handle) => { guard(() => fs.rmSync(sessionFile(handle), { force: true })); };
63
- export const pidAlive = (pid) => {
64
- try {
65
- process.kill(pid, 0);
66
- return true;
67
- }
68
- catch (e) {
69
- return errno(e) === 'EPERM';
70
- }
71
- };
72
- // active: in use within the lease by a living process; stopped: paused by the operator; gone: neither. A gone or
73
- // stopped binding keeps its seat and scope. A watcher is alive exactly while its process is: a run may outlast any
74
- // lease.
75
- export const liveness = (s) => s.state === 'stopped' ? 'stopped'
76
- : s.product === 'watch' ? (s.pid && pidAlive(s.pid) ? 'active' : 'gone')
77
- : Date.now() - Date.parse(s.lastSeen) < LEASE && (!s.pid || pidAlive(s.pid)) ? 'active' : 'gone';
78
- export const seatHolder = (hub, genesis, agent, except) => allSessions().find(s => s.hub === hub && s.genesis === genesis && s.agent === agent && s.handle !== except);
79
- // An explicit chat-to-watch handoff remembers only that chat; it never selects another chat's seat.
80
- export const ownSession = (handle) => readSession(handle)
81
- ?? allSessions().find(s => s.product === 'watch' && s.takenFrom === handle) ?? null;
82
- // The binding, checked on every agent command: joined, not stopped, room alive and the same room, still a member.
83
- export const bound = () => {
84
- const me = whoAmI();
85
- const s = readSession(me.handle) ?? fail(`this session is not in a room. Take part only when the operator says so in this chat:
86
- "join <room> as <id>" runs ringi join local <room> --as <id> --scope "<what they delegate>";
87
- after a restart, "continue" runs ringi continue.`);
88
- if (s.state === 'stopped')
89
- fail('this session is stopped: the operator paused it. It reacts to nothing until the operator says "continue" (ringi continue)');
90
- const H = openHub(s.hub);
91
- const R = openRoom(H, s.room, { quiet: true });
92
- if (!R || R.genesis !== s.genesis) {
93
- // The room's branch is gone (deleted, archived, or deleted and made anew): the session leaves it on its own. A hub
94
- // that cannot be reached fails above and leaves nothing.
95
- locked('sessions', () => { if (readSession(me.handle)?.genesis === s.genesis)
96
- dropSession(me.handle); });
97
- const gone = roomNames(H, true).find(a => a === `${s.room}@${s.genesis.slice(0, 8)}`);
98
- fail(gone ? `room ${s.room} was archived as ${gone}; this session left it`
99
- : R ? `room ${s.room} was deleted and created again; this session left the old room. The operator joins it anew`
100
- : `room ${s.room} is gone from hub ${s.hub}; this session left it`);
101
- }
102
- if (!R.members[s.agent])
103
- fail(`${s.agent} was removed from room ${s.room}; returning needs a fresh join by the operator`);
104
- locked('sessions', () => {
105
- const cur = readSession(me.handle) ?? fail('this session lost its seat');
106
- if (cur.state !== 'active' || cur.genesis !== s.genesis || cur.agent !== s.agent)
107
- fail('this session was stopped or its seat changed');
108
- saveSession({ ...cur, lastSeen: stamp(), pid: me.pid ?? cur.pid });
109
- });
110
- return { s, H, R: R, me: s.agent };
111
- };
112
- export const parseSelector = (sel) => {
113
- const m = /^(?:([a-z0-9._-]+):)?([^/]+)\/([^/]+)$/.exec(sel ?? '');
114
- return m ? { hub: m[1] ?? null, room: m[2], agent: m[3] } : fail('a session is named <room>/<agent> or <hub>:<room>/<agent>');
115
- };
116
- //# sourceMappingURL=session.js.map
@@ -1,321 +0,0 @@
1
- // watch: headless turns for one agent of one room (core-1 §7). It holds that agent's seat, answers heartbeats in
2
- // code, and spends only within a grant (decisions-1) or its own run budget. Usage receipts are written here, by the
3
- // runner, never by the model.
4
- import { spawn } from 'node:child_process';
5
- import * as D from '../domain/decisions.js';
6
- import { HOME, OPERATOR, config, locked } from '../home/index.js';
7
- import { HIDDEN, append, openHub, openRoom, pongText, start } from '../hub/index.js';
8
- import { loadRoomUnlocked, loadState, readerLock, saveState } from './reader.js';
9
- import { isOpen, taskFor, taskOf } from '../domain/profiles.js';
10
- import { compose, link, unread, wakes } from '../protocol/index.js';
11
- import { dropSession, liveness, parseSelector, pidAlive, readSession, saveSession, seatHolder, whoAmI } from './session.js';
12
- import { fail, note, short, sleep, stamp } from '../lib/index.js';
13
- // One turn: the command runs in a process group of its own (POSIX). At the deadline, or when the command itself
14
- // ends, whatever is left of the group is asked to stop and, after a grace, killed; the turn ends when the group is
15
- // empty, so no descendant outlives the run it was counted as.
16
- const GRACE = 5000;
17
- const groupAlive = (pid) => {
18
- try {
19
- process.kill(-pid, 0);
20
- return true;
21
- }
22
- catch (e) {
23
- return e.code === 'EPERM';
24
- }
25
- };
26
- const signalGroup = (pid, sig) => {
27
- try {
28
- process.kill(-pid, sig);
29
- }
30
- catch { }
31
- };
32
- const turn = (cmd, seconds, env) => new Promise(resolve => {
33
- const t0 = Date.now();
34
- const child = spawn('sh', ['-c', cmd], { stdio: 'inherit', env, detached: true });
35
- const pid = child.pid;
36
- let timedOut = false;
37
- let exit = null;
38
- const end = async () => {
39
- signalGroup(pid, 'SIGTERM');
40
- const until = Date.now() + GRACE;
41
- while (groupAlive(pid) && Date.now() < until)
42
- await sleep(50);
43
- if (groupAlive(pid))
44
- signalGroup(pid, 'SIGKILL');
45
- while (groupAlive(pid))
46
- await sleep(50);
47
- resolve({ code: exit?.code ?? null, signal: exit?.signal ?? null, timedOut, seconds: Math.round((Date.now() - t0) / 1000) });
48
- };
49
- // At the deadline: SIGTERM to the group, and SIGKILL after the grace even if the shell ignores it.
50
- let hard;
51
- const timer = seconds ? setTimeout(() => {
52
- timedOut = true;
53
- signalGroup(pid, 'SIGTERM');
54
- hard = setTimeout(() => signalGroup(pid, 'SIGKILL'), GRACE);
55
- }, seconds * 1000) : undefined;
56
- const stopAll = () => signalGroup(pid, 'SIGTERM');
57
- process.once('SIGINT', stopAll);
58
- process.once('SIGTERM', stopAll);
59
- child.on('exit', (code, signal) => {
60
- exit = { code, signal };
61
- clearTimeout(timer);
62
- clearTimeout(hard);
63
- process.removeListener('SIGINT', stopAll);
64
- process.removeListener('SIGTERM', stopAll);
65
- void end();
66
- });
67
- });
68
- export const watch = async (w, log = note) => {
69
- for (const [name, value] of [['interval', w.interval], ['window', w.window]])
70
- if (value !== undefined && (!Number.isFinite(value) || value <= 0))
71
- fail(`watch ${name} must be positive seconds`);
72
- for (const [name, value] of [['max-runs', w.maxRuns], ['max-hop', w.maxHop]])
73
- if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
74
- fail(`watch ${name} must be a nonnegative integer`);
75
- const sel = parseSelector(w.seat);
76
- const cmd = w.exec;
77
- const H0 = openHub(sel.hub ?? w.hub ?? config().hub);
78
- const R0 = openRoom(H0, sel.room);
79
- const me = sel.agent;
80
- if (R0.archived)
81
- fail(`${R0.name} is archived`);
82
- if (!R0.members[me])
83
- fail(`${me} is not a member of ${R0.name}; the operator adds it with a join, or watch another agent`);
84
- // Each watcher process is its own session, so two of them can never share one seat record.
85
- const raw = `watch-${H0.name}-${R0.genesis.slice(0, 8)}-${me}-${process.pid}`;
86
- const handle = `env:${raw}`;
87
- locked('sessions', () => {
88
- const holder = seatHolder(H0.name, R0.genesis, me, handle);
89
- const handoff = w.handoff && holder?.product !== 'watch' && holder?.handle === whoAmI().handle;
90
- if (w.handoff && !handoff)
91
- fail('watch --handoff needs the invoking chat to own this seat');
92
- if (handoff && holder.state === 'stopped')
93
- fail('this chat is stopped; continue it before a handoff');
94
- if (holder && !handoff && (holder.product !== 'watch' || (holder.pid && pidAlive(holder.pid))))
95
- fail(`${R0.name}/${me} is held by session ${holder.handle} (${liveness(holder)}); one seat per agent. Its chat may use watch --handoff`);
96
- if (holder)
97
- dropSession(holder.handle);
98
- saveSession({ handle, product: 'watch', hub: H0.name, room: R0.name, genesis: R0.genesis, agent: me, scope: w.scope ?? holder?.scope ?? null,
99
- state: holder?.state === 'stopped' ? 'stopped' : 'active', since: stamp(), lastSeen: stamp(), pid: process.pid,
100
- takenFrom: handoff ? holder.handle : holder?.takenFrom });
101
- });
102
- const interval = (w.interval ?? 5) * 1000;
103
- const allow = w.from ? new Set(w.from) : null;
104
- const maxHop = w.maxHop ?? 8;
105
- const maxRuns = w.maxRuns ?? 10;
106
- const span = w.window ?? 86400;
107
- let runSeq = 0;
108
- for (;;) {
109
- const s = locked('sessions', () => {
110
- const cur = readSession(handle);
111
- if (cur?.state === 'active')
112
- saveSession({ ...cur, lastSeen: stamp(), pid: process.pid });
113
- return cur;
114
- });
115
- if (!s) {
116
- log(`watch: the seat of ${me} was released or taken over; stopping`);
117
- return 0;
118
- }
119
- if (s.state === 'stopped') {
120
- if (w.once) {
121
- log('watch: stopped by the operator');
122
- return 0;
123
- }
124
- await sleep(interval);
125
- continue;
126
- }
127
- const H = openHub(H0.name, { refresh: true });
128
- const R = openRoom(H, R0.name, { quiet: true });
129
- if (!R || R.genesis !== R0.genesis) {
130
- // The room's branch is gone: the watcher leaves its seat (a hub it cannot reach fails above and leaves nothing).
131
- locked('sessions', () => { if (readSession(handle)?.genesis === R0.genesis)
132
- dropSession(handle); });
133
- log(`watch: ${R0.name} is gone, recreated or archived; ${me} left it`);
134
- return 0;
135
- }
136
- if (!R.members[me]) {
137
- log(`watch: ${me} was removed from ${R0.name}; stopping`);
138
- return 0;
139
- }
140
- // A room waiting for its quorum runs no turn yet.
141
- const st = start(R);
142
- if (!st.started) {
143
- if (w.once) {
144
- log(`watch: ${R0.name} waits for a quorum of ${st.quorum} agents and has ${st.agents}; nothing to do yet`);
145
- return 0;
146
- }
147
- await sleep(interval);
148
- continue;
149
- }
150
- const P = R.profile;
151
- // Lock order throughout planning and dispatch: grant, reader, sessions (then the store's own writes).
152
- const plan = locked(`grant-${H.name}`, () => readerLock(R, me, () => {
153
- const { logs, st } = loadRoomUnlocked(R, me);
154
- if (st.inflight) {
155
- st.seen = st.inflight.seen;
156
- st.inflight = undefined;
157
- saveState(R, me, st);
158
- }
159
- const all = link(logs);
160
- // Heartbeats: one pong per allowed ping, in code; a separate durable cursor, never a model run.
161
- const heartbeatSeen = { ...st.heartbeatSeen };
162
- const answered = new Set((logs.get(me) ?? []).filter(m => m.kind === 'pong').map(m => m.reId));
163
- for (const [id, msgs] of logs) {
164
- if (id === me)
165
- continue;
166
- const at = msgs.findIndex(m => m.id === heartbeatSeen[id]);
167
- for (const m of msgs.slice(at + 1)) {
168
- if (m.bad || m.kind !== 'ping' || !m.to.includes(me) || answered.has(m.id) || m.hopEff >= maxHop || (allow && !allow.has(m.from)))
169
- continue;
170
- append(R, me, pongText(me, m, 'has a watcher'));
171
- note(`watch: answered heartbeat ${short(m.id)} from ${m.from}`);
172
- }
173
- if (msgs.length)
174
- heartbeatSeen[id] = msgs.at(-1).id;
175
- }
176
- const { msgs: fresh, cursors } = unread(logs, me, st.watched ?? st.seen ?? {}, Infinity, HIDDEN);
177
- const retry = (st.pending ?? []).flatMap(id => {
178
- const m = all.get(id);
179
- if (!m)
180
- return [];
181
- const task = taskFor(all, m, P);
182
- return !task || isOpen(taskOf(all, task, P), P) ? [m] : [];
183
- });
184
- const msgs = [...new Map([...retry, ...fresh].map(m => [m.id, m])).values()];
185
- const go = msgs.filter(m => wakes(m, me, HIDDEN) && m.hopEff < maxHop && (!allow || allow.has(m.from)));
186
- for (const m of msgs)
187
- if (!go.includes(m))
188
- note(`watch: not waking for ${short(m.id)} from ${m.from} (to ${m.to.join(',')}, hop ${m.hopEff})`);
189
- // Group by the grant of each message's work; a message outside a grant spends the watcher's own budget.
190
- const groups = new Map();
191
- for (const m of go) {
192
- const task = taskFor(all, m, P);
193
- const g = task ? taskOf(all, task, P).grant : null;
194
- if (!groups.has(g))
195
- groups.set(g, { grant: g, msgs: [], task });
196
- groups.get(g).msgs.push(m);
197
- }
198
- const runs = [];
199
- let hold = false;
200
- const now = Date.now() / 1000;
201
- let ownRuns = (st.runs ?? []).filter(t => t > now - span);
202
- const exhausted = { ...st.exhausted };
203
- for (const grp of groups.values()) {
204
- if (!grp.grant) {
205
- if (w.requireGrant) {
206
- for (const m of grp.msgs)
207
- note(`watch: ${short(m.id)} is outside any grant; --require-grant: not starting a turn`);
208
- continue;
209
- }
210
- if (ownRuns.length >= maxRuns) {
211
- hold = true;
212
- note(`watch: own run budget spent (${maxRuns} per ${span}s); ${grp.msgs.length} message(s) wait`);
213
- continue;
214
- }
215
- ownRuns = [...ownRuns, now];
216
- runs.push({ ...grp, timeout: null });
217
- continue;
218
- }
219
- // The grant lock covers reservation and decisions on this machine.
220
- const r = (() => {
221
- // Fence: only the watcher that holds the seat reserves.
222
- if (readSession(handle)?.pid !== process.pid)
223
- return { why: 'this watcher no longer holds the seat', lost: true };
224
- const gr = D.grantOf(all, R.authorityAt, grp.grant);
225
- if (!gr)
226
- return { why: `grant ${short(grp.grant)} is not an approved decision with a budget` };
227
- if (gr.revoked)
228
- return { why: `grant ${short(gr.id)} was revoked`, exhausted: true, gr };
229
- const u = D.usageOf(all, gr);
230
- if (u.left <= 0)
231
- return { why: `grant ${short(gr.id)} is spent: ${u.runs}/${gr.budget.runs} runs`, exhausted: true, gr };
232
- if (u.open >= gr.budget.concurrency)
233
- return { why: `grant ${short(gr.id)} has ${u.open} run(s) open, concurrency ${gr.budget.concurrency}`, wait: true };
234
- const run = `${raw}.${process.pid}.${Date.now().toString(36)}.${runSeq++}`;
235
- append(R, me, compose(`usage: reserve a run of ${me}`, [['To', OPERATOR], ['Kind', 'usage'], ['Grant', gr.id], ['Usage', 'reserve'], ['Run', run]]));
236
- return { gr, run };
237
- })();
238
- if (r.lost)
239
- return { runs: [], hold: true, lost: true };
240
- if (r.wait) {
241
- hold = true;
242
- note(`watch: ${r.why}; waiting`);
243
- continue;
244
- }
245
- if (r.why) {
246
- note(`watch: ${r.why}`);
247
- const key = `${grp.task?.id}/${grp.grant}`;
248
- if (r.exhausted && grp.task && !exhausted[key]) {
249
- exhausted[key] = true;
250
- const t = taskOf(all, grp.task, P);
251
- const last = grp.msgs.at(-1);
252
- // The profile names its waiting state, if it has one; otherwise the answer carries no state.
253
- if (isOpen(t, P))
254
- append(R, me, compose(`${r.why}; waiting for a new grant`, [['To', [...new Set([t.requester, OPERATOR])].join(', ')], ['Re', last.id], ['State', P.waiting], ['Hop', String(last.hopEff + 1)]]));
255
- }
256
- continue;
257
- }
258
- runs.push({ ...grp, run: r.run, timeout: r.gr.budget['run-seconds'] });
259
- }
260
- const pending = [...new Set([...retry.map(m => m.id), ...runs.flatMap(r => r.msgs.map(m => m.id))])];
261
- saveState(R, me, { ...loadState(R, me), heartbeatSeen, exhausted, pending, runs: ownRuns,
262
- ...(hold ? {} : { watched: cursors }) });
263
- return { runs, hold, lost: false };
264
- }));
265
- if (plan.lost) {
266
- log(`watch: the seat of ${me} was taken over; stopping`);
267
- return 0;
268
- }
269
- let exitCode = 0;
270
- const settle = (run, seconds, exit, why) => append(R, me, compose(`usage: settle a run of ${me}${why ? ` (${why})` : ''}`, [['To', OPERATOR], ['Kind', 'usage'], ['Grant', run.grant], ['Usage', 'settle'], ['Run', run.run], ['Seconds', String(seconds)], ['Exit', String(exit)]]));
271
- for (const run of plan.runs) {
272
- // Spawn under the same locks as revocation and stop; wait for the turn after releasing them.
273
- const next = locked(`grant-${H.name}`, () => {
274
- if (run.grant) {
275
- const { logs } = readerLock(R, me, () => loadRoomUnlocked(R, me));
276
- const gr = D.grantOf(link(logs), R.authorityAt, run.grant);
277
- if (!gr || gr.revoked)
278
- return { why: !gr ? 'its grant is no longer valid' : 'its grant was revoked' };
279
- }
280
- readerLock(R, me, () => {
281
- const st = loadState(R, me);
282
- saveState(R, me, { ...st, inflight: { seen: st.seen ?? {} } });
283
- });
284
- return locked('sessions', () => {
285
- const cur = readSession(handle);
286
- if (!cur || cur.pid !== process.pid)
287
- return { why: 'the seat was taken over' };
288
- if (cur.state !== 'active')
289
- return { why: 'the watcher was stopped' };
290
- note(`watch: ${run.msgs.length} new${run.grant ? ` under grant ${short(run.grant)}` : ''}: ${cmd}`);
291
- return { done: turn(cmd, run.timeout, { ...process.env, RINGI_HOME: HOME, RINGI_SESSION: raw, RINGI_MSGS: run.msgs.map(m => m.id).join('\n'), RINGI_GRANT: run.grant ?? '' }) };
292
- });
293
- });
294
- if (next.why) {
295
- note(`watch: not starting the next turn: ${next.why}`);
296
- if (run.run)
297
- settle(run, 0, 125, `not started: ${next.why}`);
298
- continue;
299
- }
300
- const r = await next.done;
301
- note(`watch: exit ${r.code ?? r.signal}${r.timedOut ? ' (stopped at the grant\'s run-seconds)' : ''} after ${r.seconds}s`);
302
- // Settled only once the whole turn, descendants included, has ended.
303
- if (run.run)
304
- settle(run, r.seconds, r.code ?? 128);
305
- readerLock(R, me, () => {
306
- const st = loadState(R, me), delivered = new Set(run.msgs.map(m => m.id));
307
- // A deadline is an intentional budget stop, not a delivery failure to spend another run on.
308
- const deliveredTurn = r.code === 0 || r.timedOut;
309
- saveState(R, me, { ...st, inflight: undefined, ...(deliveredTurn
310
- ? { pending: (st.pending ?? []).filter(id => !delivered.has(id)) }
311
- : { seen: st.inflight?.seen ?? st.seen }) });
312
- });
313
- if (r.code !== 0 || r.timedOut)
314
- exitCode ||= r.code || 128;
315
- }
316
- if (w.once)
317
- return exitCode || (plan.hold ? 4 : 0);
318
- await sleep(interval);
319
- }
320
- };
321
- //# sourceMappingURL=watch.js.map