@openrig/cli 0.1.12 → 0.2.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 (518) hide show
  1. package/daemon/assets/openrig-activity-hook-relay.cjs +104 -0
  2. package/daemon/dist/adapters/claude-code-adapter.d.ts +14 -6
  3. package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
  4. package/daemon/dist/adapters/claude-code-adapter.js +183 -65
  5. package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
  6. package/daemon/dist/adapters/claude-resume.d.ts +5 -0
  7. package/daemon/dist/adapters/claude-resume.d.ts.map +1 -1
  8. package/daemon/dist/adapters/claude-resume.js +13 -0
  9. package/daemon/dist/adapters/claude-resume.js.map +1 -1
  10. package/daemon/dist/adapters/codex-resume.d.ts +8 -1
  11. package/daemon/dist/adapters/codex-resume.d.ts.map +1 -1
  12. package/daemon/dist/adapters/codex-resume.js +74 -5
  13. package/daemon/dist/adapters/codex-resume.js.map +1 -1
  14. package/daemon/dist/adapters/codex-runtime-adapter.d.ts +9 -5
  15. package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
  16. package/daemon/dist/adapters/codex-runtime-adapter.js +255 -28
  17. package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
  18. package/daemon/dist/adapters/terminal-adapter.d.ts +2 -1
  19. package/daemon/dist/adapters/terminal-adapter.d.ts.map +1 -1
  20. package/daemon/dist/adapters/terminal-adapter.js +7 -1
  21. package/daemon/dist/adapters/terminal-adapter.js.map +1 -1
  22. package/daemon/dist/adapters/tmux.d.ts.map +1 -1
  23. package/daemon/dist/adapters/tmux.js +53 -5
  24. package/daemon/dist/adapters/tmux.js.map +1 -1
  25. package/daemon/dist/db/migrations/021_seat_handover_observability.d.ts +3 -0
  26. package/daemon/dist/db/migrations/021_seat_handover_observability.d.ts.map +1 -0
  27. package/daemon/dist/db/migrations/021_seat_handover_observability.js +11 -0
  28. package/daemon/dist/db/migrations/021_seat_handover_observability.js.map +1 -0
  29. package/daemon/dist/db/migrations/022_node_codex_config_profile.d.ts +3 -0
  30. package/daemon/dist/db/migrations/022_node_codex_config_profile.d.ts.map +1 -0
  31. package/daemon/dist/db/migrations/022_node_codex_config_profile.js +7 -0
  32. package/daemon/dist/db/migrations/022_node_codex_config_profile.js.map +1 -0
  33. package/daemon/dist/db/migrations/023_stream_items.d.ts +16 -0
  34. package/daemon/dist/db/migrations/023_stream_items.d.ts.map +1 -0
  35. package/daemon/dist/db/migrations/023_stream_items.js +37 -0
  36. package/daemon/dist/db/migrations/023_stream_items.js.map +1 -0
  37. package/daemon/dist/db/migrations/024_queue_items.d.ts +19 -0
  38. package/daemon/dist/db/migrations/024_queue_items.d.ts.map +1 -0
  39. package/daemon/dist/db/migrations/024_queue_items.js +52 -0
  40. package/daemon/dist/db/migrations/024_queue_items.js.map +1 -0
  41. package/daemon/dist/db/migrations/025_queue_transitions.d.ts +13 -0
  42. package/daemon/dist/db/migrations/025_queue_transitions.d.ts.map +1 -0
  43. package/daemon/dist/db/migrations/025_queue_transitions.js +28 -0
  44. package/daemon/dist/db/migrations/025_queue_transitions.js.map +1 -0
  45. package/daemon/dist/db/migrations/026_inbox_entries.d.ts +14 -0
  46. package/daemon/dist/db/migrations/026_inbox_entries.d.ts.map +1 -0
  47. package/daemon/dist/db/migrations/026_inbox_entries.js +35 -0
  48. package/daemon/dist/db/migrations/026_inbox_entries.js.map +1 -0
  49. package/daemon/dist/db/migrations/027_outbox_entries.d.ts +12 -0
  50. package/daemon/dist/db/migrations/027_outbox_entries.d.ts.map +1 -0
  51. package/daemon/dist/db/migrations/027_outbox_entries.js +30 -0
  52. package/daemon/dist/db/migrations/027_outbox_entries.js.map +1 -0
  53. package/daemon/dist/db/migrations/028_project_classifications.d.ts +26 -0
  54. package/daemon/dist/db/migrations/028_project_classifications.d.ts.map +1 -0
  55. package/daemon/dist/db/migrations/028_project_classifications.js +44 -0
  56. package/daemon/dist/db/migrations/028_project_classifications.js.map +1 -0
  57. package/daemon/dist/db/migrations/029_classifier_leases.d.ts +22 -0
  58. package/daemon/dist/db/migrations/029_classifier_leases.d.ts.map +1 -0
  59. package/daemon/dist/db/migrations/029_classifier_leases.js +41 -0
  60. package/daemon/dist/db/migrations/029_classifier_leases.js.map +1 -0
  61. package/daemon/dist/db/migrations/030_views_custom.d.ts +15 -0
  62. package/daemon/dist/db/migrations/030_views_custom.d.ts.map +1 -0
  63. package/daemon/dist/db/migrations/030_views_custom.js +27 -0
  64. package/daemon/dist/db/migrations/030_views_custom.js.map +1 -0
  65. package/daemon/dist/db/migrations/031_watchdog_jobs.d.ts +34 -0
  66. package/daemon/dist/db/migrations/031_watchdog_jobs.d.ts.map +1 -0
  67. package/daemon/dist/db/migrations/031_watchdog_jobs.js +59 -0
  68. package/daemon/dist/db/migrations/031_watchdog_jobs.js.map +1 -0
  69. package/daemon/dist/db/migrations/032_watchdog_history.d.ts +28 -0
  70. package/daemon/dist/db/migrations/032_watchdog_history.d.ts.map +1 -0
  71. package/daemon/dist/db/migrations/032_watchdog_history.js +46 -0
  72. package/daemon/dist/db/migrations/032_watchdog_history.js.map +1 -0
  73. package/daemon/dist/db/migrations/033_workflow_specs.d.ts +30 -0
  74. package/daemon/dist/db/migrations/033_workflow_specs.d.ts.map +1 -0
  75. package/daemon/dist/db/migrations/033_workflow_specs.js +50 -0
  76. package/daemon/dist/db/migrations/033_workflow_specs.js.map +1 -0
  77. package/daemon/dist/db/migrations/034_workflow_instances.d.ts +42 -0
  78. package/daemon/dist/db/migrations/034_workflow_instances.d.ts.map +1 -0
  79. package/daemon/dist/db/migrations/034_workflow_instances.js +63 -0
  80. package/daemon/dist/db/migrations/034_workflow_instances.js.map +1 -0
  81. package/daemon/dist/db/migrations/035_workflow_step_trails.d.ts +29 -0
  82. package/daemon/dist/db/migrations/035_workflow_step_trails.d.ts.map +1 -0
  83. package/daemon/dist/db/migrations/035_workflow_step_trails.js +48 -0
  84. package/daemon/dist/db/migrations/035_workflow_step_trails.js.map +1 -0
  85. package/daemon/dist/db/migrations/036_watchdog_policy_enum_extension.d.ts +35 -0
  86. package/daemon/dist/db/migrations/036_watchdog_policy_enum_extension.d.ts.map +1 -0
  87. package/daemon/dist/db/migrations/036_watchdog_policy_enum_extension.js +43 -0
  88. package/daemon/dist/db/migrations/036_watchdog_policy_enum_extension.js.map +1 -0
  89. package/daemon/dist/domain/agent-activity-store.d.ts +42 -0
  90. package/daemon/dist/domain/agent-activity-store.d.ts.map +1 -0
  91. package/daemon/dist/domain/agent-activity-store.js +177 -0
  92. package/daemon/dist/domain/agent-activity-store.js.map +1 -0
  93. package/daemon/dist/domain/agent-manifest.d.ts.map +1 -1
  94. package/daemon/dist/domain/agent-manifest.js +3 -0
  95. package/daemon/dist/domain/agent-manifest.js.map +1 -1
  96. package/daemon/dist/domain/agent-starter-resolver.d.ts +100 -0
  97. package/daemon/dist/domain/agent-starter-resolver.d.ts.map +1 -0
  98. package/daemon/dist/domain/agent-starter-resolver.js +200 -0
  99. package/daemon/dist/domain/agent-starter-resolver.js.map +1 -0
  100. package/daemon/dist/domain/classifier-lease-manager.d.ts +130 -0
  101. package/daemon/dist/domain/classifier-lease-manager.d.ts.map +1 -0
  102. package/daemon/dist/domain/classifier-lease-manager.js +285 -0
  103. package/daemon/dist/domain/classifier-lease-manager.js.map +1 -0
  104. package/daemon/dist/domain/context-usage-store.d.ts +1 -1
  105. package/daemon/dist/domain/context-usage-store.js +1 -1
  106. package/daemon/dist/domain/context-usage-store.js.map +1 -1
  107. package/daemon/dist/domain/hot-potato-enforcer.d.ts +45 -0
  108. package/daemon/dist/domain/hot-potato-enforcer.d.ts.map +1 -0
  109. package/daemon/dist/domain/hot-potato-enforcer.js +94 -0
  110. package/daemon/dist/domain/hot-potato-enforcer.js.map +1 -0
  111. package/daemon/dist/domain/inbox-handler.d.ts +68 -0
  112. package/daemon/dist/domain/inbox-handler.d.ts.map +1 -0
  113. package/daemon/dist/domain/inbox-handler.js +177 -0
  114. package/daemon/dist/domain/inbox-handler.js.map +1 -0
  115. package/daemon/dist/domain/native-resume-probe.d.ts +1 -1
  116. package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
  117. package/daemon/dist/domain/native-resume-probe.js +67 -0
  118. package/daemon/dist/domain/native-resume-probe.js.map +1 -1
  119. package/daemon/dist/domain/node-inventory.d.ts +29 -1
  120. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  121. package/daemon/dist/domain/node-inventory.js +160 -38
  122. package/daemon/dist/domain/node-inventory.js.map +1 -1
  123. package/daemon/dist/domain/node-launcher.d.ts +2 -0
  124. package/daemon/dist/domain/node-launcher.d.ts.map +1 -1
  125. package/daemon/dist/domain/node-launcher.js +14 -2
  126. package/daemon/dist/domain/node-launcher.js.map +1 -1
  127. package/daemon/dist/domain/outbox-handler.d.ts +48 -0
  128. package/daemon/dist/domain/outbox-handler.d.ts.map +1 -0
  129. package/daemon/dist/domain/outbox-handler.js +106 -0
  130. package/daemon/dist/domain/outbox-handler.js.map +1 -0
  131. package/daemon/dist/domain/policies/artifact-pool-helpers.d.ts +64 -0
  132. package/daemon/dist/domain/policies/artifact-pool-helpers.d.ts.map +1 -0
  133. package/daemon/dist/domain/policies/artifact-pool-helpers.js +226 -0
  134. package/daemon/dist/domain/policies/artifact-pool-helpers.js.map +1 -0
  135. package/daemon/dist/domain/policies/artifact-pool-ready.d.ts +3 -0
  136. package/daemon/dist/domain/policies/artifact-pool-ready.d.ts.map +1 -0
  137. package/daemon/dist/domain/policies/artifact-pool-ready.js +41 -0
  138. package/daemon/dist/domain/policies/artifact-pool-ready.js.map +1 -0
  139. package/daemon/dist/domain/policies/edge-artifact-required.d.ts +3 -0
  140. package/daemon/dist/domain/policies/edge-artifact-required.d.ts.map +1 -0
  141. package/daemon/dist/domain/policies/edge-artifact-required.js +90 -0
  142. package/daemon/dist/domain/policies/edge-artifact-required.js.map +1 -0
  143. package/daemon/dist/domain/policies/periodic-reminder.d.ts +3 -0
  144. package/daemon/dist/domain/policies/periodic-reminder.d.ts.map +1 -0
  145. package/daemon/dist/domain/policies/periodic-reminder.js +30 -0
  146. package/daemon/dist/domain/policies/periodic-reminder.js.map +1 -0
  147. package/daemon/dist/domain/policies/types.d.ts +51 -0
  148. package/daemon/dist/domain/policies/types.d.ts.map +1 -0
  149. package/daemon/dist/domain/policies/types.js +9 -0
  150. package/daemon/dist/domain/policies/types.js.map +1 -0
  151. package/daemon/dist/domain/policies/workflow-keepalive.d.ts +7 -0
  152. package/daemon/dist/domain/policies/workflow-keepalive.d.ts.map +1 -0
  153. package/daemon/dist/domain/policies/workflow-keepalive.js +123 -0
  154. package/daemon/dist/domain/policies/workflow-keepalive.js.map +1 -0
  155. package/daemon/dist/domain/project-classifier.d.ts +75 -0
  156. package/daemon/dist/domain/project-classifier.d.ts.map +1 -0
  157. package/daemon/dist/domain/project-classifier.js +132 -0
  158. package/daemon/dist/domain/project-classifier.js.map +1 -0
  159. package/daemon/dist/domain/projection-planner.d.ts +1 -0
  160. package/daemon/dist/domain/projection-planner.d.ts.map +1 -1
  161. package/daemon/dist/domain/projection-planner.js +3 -0
  162. package/daemon/dist/domain/projection-planner.js.map +1 -1
  163. package/daemon/dist/domain/ps-projection.d.ts +31 -0
  164. package/daemon/dist/domain/ps-projection.d.ts.map +1 -1
  165. package/daemon/dist/domain/ps-projection.js +38 -0
  166. package/daemon/dist/domain/ps-projection.js.map +1 -1
  167. package/daemon/dist/domain/queue-repository.d.ts +322 -0
  168. package/daemon/dist/domain/queue-repository.d.ts.map +1 -0
  169. package/daemon/dist/domain/queue-repository.js +686 -0
  170. package/daemon/dist/domain/queue-repository.js.map +1 -0
  171. package/daemon/dist/domain/queue-transition-log.d.ts +38 -0
  172. package/daemon/dist/domain/queue-transition-log.d.ts.map +1 -0
  173. package/daemon/dist/domain/queue-transition-log.js +52 -0
  174. package/daemon/dist/domain/queue-transition-log.js.map +1 -0
  175. package/daemon/dist/domain/restore-check-service.d.ts +203 -0
  176. package/daemon/dist/domain/restore-check-service.d.ts.map +1 -0
  177. package/daemon/dist/domain/restore-check-service.js +1047 -0
  178. package/daemon/dist/domain/restore-check-service.js.map +1 -0
  179. package/daemon/dist/domain/restore-orchestrator.d.ts +49 -3
  180. package/daemon/dist/domain/restore-orchestrator.d.ts.map +1 -1
  181. package/daemon/dist/domain/restore-orchestrator.js +460 -62
  182. package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
  183. package/daemon/dist/domain/rig-expansion-service.d.ts.map +1 -1
  184. package/daemon/dist/domain/rig-expansion-service.js +13 -0
  185. package/daemon/dist/domain/rig-expansion-service.js.map +1 -1
  186. package/daemon/dist/domain/rig-repository.d.ts +17 -1
  187. package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
  188. package/daemon/dist/domain/rig-repository.js +63 -5
  189. package/daemon/dist/domain/rig-repository.js.map +1 -1
  190. package/daemon/dist/domain/rigspec-codec.d.ts.map +1 -1
  191. package/daemon/dist/domain/rigspec-codec.js +13 -0
  192. package/daemon/dist/domain/rigspec-codec.js.map +1 -1
  193. package/daemon/dist/domain/rigspec-exporter.d.ts.map +1 -1
  194. package/daemon/dist/domain/rigspec-exporter.js +2 -0
  195. package/daemon/dist/domain/rigspec-exporter.js.map +1 -1
  196. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  197. package/daemon/dist/domain/rigspec-instantiator.js +61 -1
  198. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  199. package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
  200. package/daemon/dist/domain/rigspec-schema.js +196 -0
  201. package/daemon/dist/domain/rigspec-schema.js.map +1 -1
  202. package/daemon/dist/domain/runtime-adapter.d.ts +27 -2
  203. package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
  204. package/daemon/dist/domain/runtime-adapter.js +5 -0
  205. package/daemon/dist/domain/runtime-adapter.js.map +1 -1
  206. package/daemon/dist/domain/seat-handover-planner.d.ts +84 -0
  207. package/daemon/dist/domain/seat-handover-planner.d.ts.map +1 -0
  208. package/daemon/dist/domain/seat-handover-planner.js +188 -0
  209. package/daemon/dist/domain/seat-handover-planner.js.map +1 -0
  210. package/daemon/dist/domain/seat-handover-service.d.ts +104 -0
  211. package/daemon/dist/domain/seat-handover-service.d.ts.map +1 -0
  212. package/daemon/dist/domain/seat-handover-service.js +343 -0
  213. package/daemon/dist/domain/seat-handover-service.js.map +1 -0
  214. package/daemon/dist/domain/seat-status-service.d.ts +50 -0
  215. package/daemon/dist/domain/seat-status-service.d.ts.map +1 -0
  216. package/daemon/dist/domain/seat-status-service.js +66 -0
  217. package/daemon/dist/domain/seat-status-service.js.map +1 -0
  218. package/daemon/dist/domain/session-source-rebuild-resolver.d.ts +53 -0
  219. package/daemon/dist/domain/session-source-rebuild-resolver.d.ts.map +1 -0
  220. package/daemon/dist/domain/session-source-rebuild-resolver.js +59 -0
  221. package/daemon/dist/domain/session-source-rebuild-resolver.js.map +1 -0
  222. package/daemon/dist/domain/session-transport.d.ts +30 -0
  223. package/daemon/dist/domain/session-transport.d.ts.map +1 -1
  224. package/daemon/dist/domain/session-transport.js +322 -12
  225. package/daemon/dist/domain/session-transport.js.map +1 -1
  226. package/daemon/dist/domain/snapshot-repository.d.ts +18 -0
  227. package/daemon/dist/domain/snapshot-repository.d.ts.map +1 -1
  228. package/daemon/dist/domain/snapshot-repository.js +77 -0
  229. package/daemon/dist/domain/snapshot-repository.js.map +1 -1
  230. package/daemon/dist/domain/startup-orchestrator.d.ts +22 -3
  231. package/daemon/dist/domain/startup-orchestrator.d.ts.map +1 -1
  232. package/daemon/dist/domain/startup-orchestrator.js +31 -5
  233. package/daemon/dist/domain/startup-orchestrator.js.map +1 -1
  234. package/daemon/dist/domain/stream-store.d.ts +56 -0
  235. package/daemon/dist/domain/stream-store.d.ts.map +1 -0
  236. package/daemon/dist/domain/stream-store.js +108 -0
  237. package/daemon/dist/domain/stream-store.js.map +1 -0
  238. package/daemon/dist/domain/transcript-redaction.d.ts +13 -0
  239. package/daemon/dist/domain/transcript-redaction.d.ts.map +1 -0
  240. package/daemon/dist/domain/transcript-redaction.js +34 -0
  241. package/daemon/dist/domain/transcript-redaction.js.map +1 -0
  242. package/daemon/dist/domain/transcript-store.d.ts +15 -0
  243. package/daemon/dist/domain/transcript-store.d.ts.map +1 -1
  244. package/daemon/dist/domain/transcript-store.js +57 -1
  245. package/daemon/dist/domain/transcript-store.js.map +1 -1
  246. package/daemon/dist/domain/types.d.ts +316 -3
  247. package/daemon/dist/domain/types.d.ts.map +1 -1
  248. package/daemon/dist/domain/view-event-bridge.d.ts +12 -0
  249. package/daemon/dist/domain/view-event-bridge.d.ts.map +1 -0
  250. package/daemon/dist/domain/view-event-bridge.js +92 -0
  251. package/daemon/dist/domain/view-event-bridge.js.map +1 -0
  252. package/daemon/dist/domain/view-projector.d.ts +83 -0
  253. package/daemon/dist/domain/view-projector.d.ts.map +1 -0
  254. package/daemon/dist/domain/view-projector.js +296 -0
  255. package/daemon/dist/domain/view-projector.js.map +1 -0
  256. package/daemon/dist/domain/watchdog-history-log.d.ts +49 -0
  257. package/daemon/dist/domain/watchdog-history-log.d.ts.map +1 -0
  258. package/daemon/dist/domain/watchdog-history-log.js +67 -0
  259. package/daemon/dist/domain/watchdog-history-log.js.map +1 -0
  260. package/daemon/dist/domain/watchdog-jobs-repository.d.ts +81 -0
  261. package/daemon/dist/domain/watchdog-jobs-repository.d.ts.map +1 -0
  262. package/daemon/dist/domain/watchdog-jobs-repository.js +164 -0
  263. package/daemon/dist/domain/watchdog-jobs-repository.js.map +1 -0
  264. package/daemon/dist/domain/watchdog-policy-engine.d.ts +92 -0
  265. package/daemon/dist/domain/watchdog-policy-engine.d.ts.map +1 -0
  266. package/daemon/dist/domain/watchdog-policy-engine.js +442 -0
  267. package/daemon/dist/domain/watchdog-policy-engine.js.map +1 -0
  268. package/daemon/dist/domain/watchdog-scheduler.d.ts +76 -0
  269. package/daemon/dist/domain/watchdog-scheduler.d.ts.map +1 -0
  270. package/daemon/dist/domain/watchdog-scheduler.js +112 -0
  271. package/daemon/dist/domain/watchdog-scheduler.js.map +1 -0
  272. package/daemon/dist/domain/workflow-instance-store.d.ts +46 -0
  273. package/daemon/dist/domain/workflow-instance-store.d.ts.map +1 -0
  274. package/daemon/dist/domain/workflow-instance-store.js +116 -0
  275. package/daemon/dist/domain/workflow-instance-store.js.map +1 -0
  276. package/daemon/dist/domain/workflow-projector.d.ts +64 -0
  277. package/daemon/dist/domain/workflow-projector.d.ts.map +1 -0
  278. package/daemon/dist/domain/workflow-projector.js +424 -0
  279. package/daemon/dist/domain/workflow-projector.js.map +1 -0
  280. package/daemon/dist/domain/workflow-runtime.d.ts +63 -0
  281. package/daemon/dist/domain/workflow-runtime.d.ts.map +1 -0
  282. package/daemon/dist/domain/workflow-runtime.js +150 -0
  283. package/daemon/dist/domain/workflow-runtime.js.map +1 -0
  284. package/daemon/dist/domain/workflow-spec-cache.d.ts +35 -0
  285. package/daemon/dist/domain/workflow-spec-cache.d.ts.map +1 -0
  286. package/daemon/dist/domain/workflow-spec-cache.js +171 -0
  287. package/daemon/dist/domain/workflow-spec-cache.js.map +1 -0
  288. package/daemon/dist/domain/workflow-step-trail-log.d.ts +27 -0
  289. package/daemon/dist/domain/workflow-step-trail-log.d.ts.map +1 -0
  290. package/daemon/dist/domain/workflow-step-trail-log.js +73 -0
  291. package/daemon/dist/domain/workflow-step-trail-log.js.map +1 -0
  292. package/daemon/dist/domain/workflow-types.d.ts +108 -0
  293. package/daemon/dist/domain/workflow-types.d.ts.map +1 -0
  294. package/daemon/dist/domain/workflow-types.js +11 -0
  295. package/daemon/dist/domain/workflow-types.js.map +1 -0
  296. package/daemon/dist/domain/workflow-validator.d.ts +31 -0
  297. package/daemon/dist/domain/workflow-validator.d.ts.map +1 -0
  298. package/daemon/dist/domain/workflow-validator.js +115 -0
  299. package/daemon/dist/domain/workflow-validator.js.map +1 -0
  300. package/daemon/dist/index.d.ts.map +1 -1
  301. package/daemon/dist/index.js +21 -2
  302. package/daemon/dist/index.js.map +1 -1
  303. package/daemon/dist/routes/activity.d.ts +3 -0
  304. package/daemon/dist/routes/activity.d.ts.map +1 -0
  305. package/daemon/dist/routes/activity.js +47 -0
  306. package/daemon/dist/routes/activity.js.map +1 -0
  307. package/daemon/dist/routes/projects.d.ts +12 -0
  308. package/daemon/dist/routes/projects.d.ts.map +1 -0
  309. package/daemon/dist/routes/projects.js +178 -0
  310. package/daemon/dist/routes/projects.js.map +1 -0
  311. package/daemon/dist/routes/queue.d.ts +10 -0
  312. package/daemon/dist/routes/queue.d.ts.map +1 -0
  313. package/daemon/dist/routes/queue.js +374 -0
  314. package/daemon/dist/routes/queue.js.map +1 -0
  315. package/daemon/dist/routes/restore-check.d.ts +3 -0
  316. package/daemon/dist/routes/restore-check.d.ts.map +1 -0
  317. package/daemon/dist/routes/restore-check.js +200 -0
  318. package/daemon/dist/routes/restore-check.js.map +1 -0
  319. package/daemon/dist/routes/rigs.d.ts.map +1 -1
  320. package/daemon/dist/routes/rigs.js +60 -4
  321. package/daemon/dist/routes/rigs.js.map +1 -1
  322. package/daemon/dist/routes/seat.d.ts +3 -0
  323. package/daemon/dist/routes/seat.d.ts.map +1 -0
  324. package/daemon/dist/routes/seat.js +69 -0
  325. package/daemon/dist/routes/seat.js.map +1 -0
  326. package/daemon/dist/routes/sessions.d.ts.map +1 -1
  327. package/daemon/dist/routes/sessions.js +25 -4
  328. package/daemon/dist/routes/sessions.js.map +1 -1
  329. package/daemon/dist/routes/snapshots.js +66 -29
  330. package/daemon/dist/routes/snapshots.js.map +1 -1
  331. package/daemon/dist/routes/stream.d.ts +9 -0
  332. package/daemon/dist/routes/stream.d.ts.map +1 -0
  333. package/daemon/dist/routes/stream.js +119 -0
  334. package/daemon/dist/routes/stream.js.map +1 -0
  335. package/daemon/dist/routes/transcripts.d.ts.map +1 -1
  336. package/daemon/dist/routes/transcripts.js +38 -0
  337. package/daemon/dist/routes/transcripts.js.map +1 -1
  338. package/daemon/dist/routes/transport.d.ts.map +1 -1
  339. package/daemon/dist/routes/transport.js +21 -0
  340. package/daemon/dist/routes/transport.js.map +1 -1
  341. package/daemon/dist/routes/up.js +24 -3
  342. package/daemon/dist/routes/up.js.map +1 -1
  343. package/daemon/dist/routes/views.d.ts +13 -0
  344. package/daemon/dist/routes/views.d.ts.map +1 -0
  345. package/daemon/dist/routes/views.js +120 -0
  346. package/daemon/dist/routes/views.js.map +1 -0
  347. package/daemon/dist/routes/watchdog.d.ts +18 -0
  348. package/daemon/dist/routes/watchdog.d.ts.map +1 -0
  349. package/daemon/dist/routes/watchdog.js +148 -0
  350. package/daemon/dist/routes/watchdog.js.map +1 -0
  351. package/daemon/dist/routes/workflow.d.ts +20 -0
  352. package/daemon/dist/routes/workflow.d.ts.map +1 -0
  353. package/daemon/dist/routes/workflow.js +184 -0
  354. package/daemon/dist/routes/workflow.js.map +1 -0
  355. package/daemon/dist/server.d.ts +30 -0
  356. package/daemon/dist/server.d.ts.map +1 -1
  357. package/daemon/dist/server.js +33 -0
  358. package/daemon/dist/server.js.map +1 -1
  359. package/daemon/dist/startup.d.ts.map +1 -1
  360. package/daemon/dist/startup.js +202 -8
  361. package/daemon/dist/startup.js.map +1 -1
  362. package/daemon/docs/reference/agent-spec.md +12 -5
  363. package/daemon/docs/reference/agent-startup-guide.md +9 -9
  364. package/daemon/specs/agents/apps/vault-specialist/agent.yaml +1 -1
  365. package/daemon/specs/agents/design/product-designer/agent.yaml +1 -1
  366. package/daemon/specs/agents/development/implementer/agent.yaml +1 -1
  367. package/daemon/specs/agents/development/qa/agent.yaml +1 -1
  368. package/daemon/specs/agents/orchestration/orchestrator/agent.yaml +1 -1
  369. package/daemon/specs/agents/product-management/pm/agent.yaml +4 -0
  370. package/daemon/specs/agents/research/analyst/agent.yaml +1 -1
  371. package/daemon/specs/agents/research/synthesizer/agent.yaml +1 -1
  372. package/daemon/specs/agents/review/independent-reviewer/agent.yaml +1 -1
  373. package/daemon/specs/agents/shared/agent.yaml +17 -0
  374. package/daemon/specs/agents/shared/runtime/claude-mcp.fragment.json +12 -0
  375. package/daemon/specs/agents/shared/runtime/claude-settings.fragment.json +16 -0
  376. package/daemon/specs/agents/shared/runtime/codex-config.fragment.toml +5 -0
  377. package/daemon/specs/agents/shared/skills/claude-compact-in-place/SKILL.md +100 -0
  378. package/daemon/specs/agents/shared/skills/core/openrig-operator/SKILL.md +110 -0
  379. package/daemon/specs/agents/shared/skills/core/openrig-user/SKILL.md +44 -1
  380. package/daemon/specs/agents/shared/skills/mental-model-ha/SKILL.md +3 -0
  381. package/daemon/specs/agents/shared/skills/pods/orchestration-team/SKILL.md +3 -0
  382. package/daemon/specs/agents/shared/skills/rig-architect/SKILL.md +11 -1
  383. package/dist/bin-wrapper.js +0 -0
  384. package/dist/commands/capture.d.ts +7 -1
  385. package/dist/commands/capture.d.ts.map +1 -1
  386. package/dist/commands/capture.js +59 -1
  387. package/dist/commands/capture.js.map +1 -1
  388. package/dist/commands/compact-plan.d.ts +9 -0
  389. package/dist/commands/compact-plan.d.ts.map +1 -0
  390. package/dist/commands/compact-plan.js +354 -0
  391. package/dist/commands/compact-plan.js.map +1 -0
  392. package/dist/commands/context.d.ts +9 -0
  393. package/dist/commands/context.d.ts.map +1 -0
  394. package/dist/commands/context.js +220 -0
  395. package/dist/commands/context.js.map +1 -0
  396. package/dist/commands/expand.d.ts.map +1 -1
  397. package/dist/commands/expand.js +15 -4
  398. package/dist/commands/expand.js.map +1 -1
  399. package/dist/commands/heartbeat.d.ts +99 -0
  400. package/dist/commands/heartbeat.d.ts.map +1 -0
  401. package/dist/commands/heartbeat.js +393 -0
  402. package/dist/commands/heartbeat.js.map +1 -0
  403. package/dist/commands/project.d.ts +14 -0
  404. package/dist/commands/project.d.ts.map +1 -0
  405. package/dist/commands/project.js +157 -0
  406. package/dist/commands/project.js.map +1 -0
  407. package/dist/commands/ps.d.ts +20 -3
  408. package/dist/commands/ps.d.ts.map +1 -1
  409. package/dist/commands/ps.js +455 -33
  410. package/dist/commands/ps.js.map +1 -1
  411. package/dist/commands/queue.d.ts +16 -0
  412. package/dist/commands/queue.d.ts.map +1 -0
  413. package/dist/commands/queue.js +401 -0
  414. package/dist/commands/queue.js.map +1 -0
  415. package/dist/commands/restore-check.d.ts +9 -0
  416. package/dist/commands/restore-check.d.ts.map +1 -0
  417. package/dist/commands/restore-check.js +234 -0
  418. package/dist/commands/restore-check.js.map +1 -0
  419. package/dist/commands/restore-packet.d.ts +9 -0
  420. package/dist/commands/restore-packet.d.ts.map +1 -0
  421. package/dist/commands/restore-packet.js +383 -0
  422. package/dist/commands/restore-packet.js.map +1 -0
  423. package/dist/commands/restore.d.ts.map +1 -1
  424. package/dist/commands/restore.js +44 -1
  425. package/dist/commands/restore.js.map +1 -1
  426. package/dist/commands/seat.d.ts +5 -0
  427. package/dist/commands/seat.d.ts.map +1 -0
  428. package/dist/commands/seat.js +170 -0
  429. package/dist/commands/seat.js.map +1 -0
  430. package/dist/commands/send.d.ts +12 -1
  431. package/dist/commands/send.d.ts.map +1 -1
  432. package/dist/commands/send.js +93 -5
  433. package/dist/commands/send.js.map +1 -1
  434. package/dist/commands/setup.js +3 -3
  435. package/dist/commands/setup.js.map +1 -1
  436. package/dist/commands/specs.d.ts.map +1 -1
  437. package/dist/commands/specs.js +99 -16
  438. package/dist/commands/specs.js.map +1 -1
  439. package/dist/commands/stream.d.ts +12 -0
  440. package/dist/commands/stream.d.ts.map +1 -0
  441. package/dist/commands/stream.js +111 -0
  442. package/dist/commands/stream.js.map +1 -0
  443. package/dist/commands/up.d.ts.map +1 -1
  444. package/dist/commands/up.js +63 -3
  445. package/dist/commands/up.js.map +1 -1
  446. package/dist/commands/view.d.ts +12 -0
  447. package/dist/commands/view.d.ts.map +1 -0
  448. package/dist/commands/view.js +82 -0
  449. package/dist/commands/view.js.map +1 -0
  450. package/dist/commands/watchdog.d.ts +15 -0
  451. package/dist/commands/watchdog.d.ts.map +1 -0
  452. package/dist/commands/watchdog.js +120 -0
  453. package/dist/commands/watchdog.js.map +1 -0
  454. package/dist/commands/whoami.d.ts +8 -1
  455. package/dist/commands/whoami.d.ts.map +1 -1
  456. package/dist/commands/whoami.js +60 -1
  457. package/dist/commands/whoami.js.map +1 -1
  458. package/dist/commands/workflow.d.ts +17 -0
  459. package/dist/commands/workflow.d.ts.map +1 -0
  460. package/dist/commands/workflow.js +138 -0
  461. package/dist/commands/workflow.js.map +1 -0
  462. package/dist/cross-host-cli-helpers.d.ts +12 -0
  463. package/dist/cross-host-cli-helpers.d.ts.map +1 -0
  464. package/dist/cross-host-cli-helpers.js +48 -0
  465. package/dist/cross-host-cli-helpers.js.map +1 -0
  466. package/dist/cross-host-executor.d.ts +84 -0
  467. package/dist/cross-host-executor.d.ts.map +1 -0
  468. package/dist/cross-host-executor.js +138 -0
  469. package/dist/cross-host-executor.js.map +1 -0
  470. package/dist/host-registry.d.ts +50 -0
  471. package/dist/host-registry.d.ts.map +1 -0
  472. package/dist/host-registry.js +116 -0
  473. package/dist/host-registry.js.map +1 -0
  474. package/dist/index.d.ts +20 -0
  475. package/dist/index.d.ts.map +1 -1
  476. package/dist/index.js +24 -0
  477. package/dist/index.js.map +1 -1
  478. package/dist/mcp-server.d.ts.map +1 -1
  479. package/dist/mcp-server.js +22 -2
  480. package/dist/mcp-server.js.map +1 -1
  481. package/dist/restore-packet/claude-transcript-parser.d.ts +12 -0
  482. package/dist/restore-packet/claude-transcript-parser.d.ts.map +1 -0
  483. package/dist/restore-packet/claude-transcript-parser.js +221 -0
  484. package/dist/restore-packet/claude-transcript-parser.js.map +1 -0
  485. package/dist/restore-packet/codex-jsonl-parser.d.ts +11 -0
  486. package/dist/restore-packet/codex-jsonl-parser.d.ts.map +1 -0
  487. package/dist/restore-packet/codex-jsonl-parser.js +159 -0
  488. package/dist/restore-packet/codex-jsonl-parser.js.map +1 -0
  489. package/dist/restore-packet/omitted-records.d.ts +60 -0
  490. package/dist/restore-packet/omitted-records.d.ts.map +1 -0
  491. package/dist/restore-packet/omitted-records.js +116 -0
  492. package/dist/restore-packet/omitted-records.js.map +1 -0
  493. package/dist/restore-packet/packet-writer.d.ts +59 -0
  494. package/dist/restore-packet/packet-writer.d.ts.map +1 -0
  495. package/dist/restore-packet/packet-writer.js +224 -0
  496. package/dist/restore-packet/packet-writer.js.map +1 -0
  497. package/dist/restore-packet/redaction.d.ts +30 -0
  498. package/dist/restore-packet/redaction.d.ts.map +1 -0
  499. package/dist/restore-packet/redaction.js +71 -0
  500. package/dist/restore-packet/redaction.js.map +1 -0
  501. package/dist/restore-packet/runtime-detect.d.ts +19 -0
  502. package/dist/restore-packet/runtime-detect.d.ts.map +1 -0
  503. package/dist/restore-packet/runtime-detect.js +81 -0
  504. package/dist/restore-packet/runtime-detect.js.map +1 -0
  505. package/dist/restore-packet/schema-validator.d.ts +13 -0
  506. package/dist/restore-packet/schema-validator.d.ts.map +1 -0
  507. package/dist/restore-packet/schema-validator.js +245 -0
  508. package/dist/restore-packet/schema-validator.js.map +1 -0
  509. package/dist/restore-packet/types.d.ts +76 -0
  510. package/dist/restore-packet/types.d.ts.map +1 -0
  511. package/dist/restore-packet/types.js +15 -0
  512. package/dist/restore-packet/types.js.map +1 -0
  513. package/dist/schemas/restore-summary.schema.json +98 -0
  514. package/package.json +10 -3
  515. package/scripts/check-abi.mjs +123 -0
  516. package/ui/dist/assets/{index-DlMH-REm.css → index-Dec25siz.css} +1 -1
  517. package/ui/dist/assets/{index-Ccd-jwRN.js → index-GNYaWmBj.js} +2 -2
  518. package/ui/dist/index.html +2 -2
@@ -0,0 +1,200 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join, basename } from "node:path";
3
+ import os from "node:os";
4
+ /**
5
+ * Thrown by `resolveStarter` when the no-credentials scan fails. Per
6
+ * review-independent finding 2, the resolver MUST throw rather than
7
+ * return a structured "ok: false" result the orchestrator could ignore;
8
+ * a failed scan is a hard refusal point that aborts the launch.
9
+ */
10
+ export class AgentStarterCredentialScanFailedError extends Error {
11
+ starterName;
12
+ reason;
13
+ constructor(starterName, reason) {
14
+ super(`Agent Starter "${starterName}" credential scan failed: ${reason}`);
15
+ this.name = "AgentStarterCredentialScanFailedError";
16
+ this.starterName = starterName;
17
+ this.reason = reason;
18
+ }
19
+ }
20
+ const DEFAULT_ENV_VAR = "OPENRIG_AGENT_STARTER_ROOT";
21
+ const DEFAULT_HOME_SUBPATH = ".openrig/agent-starters";
22
+ const DEFAULT_SUBSTRATE_FALLBACK = "/Users/wrandom/code/substrate/shared-docs/openrig-work/specs/agent-starters";
23
+ export class AgentStarterResolver {
24
+ registryRoot;
25
+ exists;
26
+ readFile;
27
+ constructor(opts = {}) {
28
+ this.exists = opts.exists ?? existsSync;
29
+ this.readFile = opts.readFile ?? ((p) => readFileSync(p, "utf-8"));
30
+ this.registryRoot = AgentStarterResolver.resolveRegistryRoot(opts, this.exists);
31
+ }
32
+ /** Exposed for tests + diagnostics. */
33
+ getRegistryRoot() {
34
+ return this.registryRoot;
35
+ }
36
+ /**
37
+ * Look up the registry root via the documented chain:
38
+ * opts.registryRoot > env[envVarName] > homeDirRoot (if exists) > substrateFallback
39
+ *
40
+ * The first three are explicit; the substrate fallback is the dogfood
41
+ * default and always returns even if the path doesn't exist (resolveStarter
42
+ * will throw with a missing-entry error when the fallback is dead). This
43
+ * keeps the constructor side-effect-free; the file-existence check lives
44
+ * inside `resolveStarter`.
45
+ */
46
+ static resolveRegistryRoot(opts, exists) {
47
+ if (typeof opts.registryRoot === "string" && opts.registryRoot !== "") {
48
+ return opts.registryRoot;
49
+ }
50
+ const env = opts.env ?? process.env;
51
+ const envVarName = opts.envVarName ?? DEFAULT_ENV_VAR;
52
+ const fromEnv = env[envVarName];
53
+ if (typeof fromEnv === "string" && fromEnv !== "") {
54
+ return fromEnv;
55
+ }
56
+ const homeBase = opts.homeDirRoot
57
+ ?? join(env.HOME ?? os.homedir(), DEFAULT_HOME_SUBPATH);
58
+ if (exists(homeBase)) {
59
+ return homeBase;
60
+ }
61
+ return opts.substrateFallback ?? DEFAULT_SUBSTRATE_FALLBACK;
62
+ }
63
+ /**
64
+ * Resolve a starter by registry name. THROWS on:
65
+ * - missing registry entry (no `<root>/<name>.yaml`);
66
+ * - malformed YAML (best-effort detection — empty file, unparseable
67
+ * front-matter shape — driver does not pull in a YAML parser at
68
+ * M1 to keep the dependency surface narrow);
69
+ * - failed no-credentials scan (`AgentStarterCredentialScanFailedError`).
70
+ *
71
+ * On a clean scan, emits `ResolvedStartupFile[]`. v1 M1 scaffolding
72
+ * shape: one entry per registry-relative file the starter declares
73
+ * (currently the registry entry YAML itself, treated as guidance_merge
74
+ * content; later milestones can extend the resolver to walk the
75
+ * priming-pack manifest's `read_full` paths once M2/M3 wiring is in
76
+ * place). All emitted files are tagged `appliesOn: ["fresh_start"]`
77
+ * because starter context seeds a fresh-launch conversation.
78
+ */
79
+ resolveStarter(name) {
80
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(name)) {
81
+ throw new Error(`Agent Starter resolver: invalid name ${JSON.stringify(name)} (must be alphanumeric with optional "_" or "-")`);
82
+ }
83
+ const registryPath = join(this.registryRoot, `${name}.yaml`);
84
+ if (!this.exists(registryPath)) {
85
+ throw new Error(`Agent Starter resolver: no registry entry found at ${registryPath}`);
86
+ }
87
+ let content;
88
+ try {
89
+ content = this.readFile(registryPath);
90
+ }
91
+ catch (err) {
92
+ throw new Error(`Agent Starter resolver: failed to read ${registryPath}: ${err.message}`);
93
+ }
94
+ if (typeof content !== "string" || content.trim() === "") {
95
+ throw new Error(`Agent Starter resolver: ${registryPath} is empty or unreadable`);
96
+ }
97
+ // Smoke check that the file parses as YAML front-matter shape: it must
98
+ // contain `starter_id:` line. Keeps M1 dependency surface narrow (no
99
+ // yaml parser pulled in); M2 can swap in a real parser when it walks
100
+ // the priming-pack manifest.
101
+ if (!/^starter_id:\s*\S+/m.test(content)) {
102
+ throw new Error(`Agent Starter resolver: ${registryPath} does not match registry-entry shape (missing "starter_id:" field)`);
103
+ }
104
+ // Path-aware + content-aware credential scan. Mirrors the v0 wrapper
105
+ // helper at `specs/agent-starters/lib/agent-starter-helpers.sh`
106
+ // `scan_starter_file`. THROWS on match (per finding 2: refuse, do
107
+ // not return).
108
+ const scanResult = scanForCredentials(content, registryPath);
109
+ if (!scanResult.ok) {
110
+ throw new AgentStarterCredentialScanFailedError(name, scanResult.reason);
111
+ }
112
+ // M1 scaffolding shape: one ResolvedStartupFile pointing at the
113
+ // registry entry itself. The orchestrator's `deliverStartup` seam
114
+ // already accepts `deliveryHint: "guidance_merge"`. Later milestones
115
+ // (M2 instantiator integration; M3 Claude e2e; M4 Codex parity) can
116
+ // extend the resolver to walk the priming-pack manifest's `read_full`
117
+ // paths if the e2e proof requires richer per-layer artifacts. The
118
+ // type contract and refusal semantics are what M1 is locking in.
119
+ const files = [
120
+ {
121
+ path: basename(registryPath),
122
+ absolutePath: registryPath,
123
+ ownerRoot: this.registryRoot,
124
+ deliveryHint: "guidance_merge",
125
+ required: true,
126
+ appliesOn: ["fresh_start"],
127
+ },
128
+ ];
129
+ return { files, registryPath };
130
+ }
131
+ }
132
+ // --- No-credentials scan (mirrors `lib/agent-starter-helpers.sh::scan_starter_file`) ---
133
+ const CRED_PATH_LITERALS = [
134
+ ".claude/.credentials.json",
135
+ ".codex/auth.json",
136
+ ".aws/credentials",
137
+ ".ssh/",
138
+ ];
139
+ const CRED_PATH_RE = /(credentials|auth\.json|secrets|tokens?\.json)([^a-zA-Z0-9._-]|$)/;
140
+ const CRED_STRING_RE = /(api[_-]?key|secret[_-]?key|bearer[_-]?token|sk-[A-Za-z0-9]{20,}|gh[ps]_[A-Za-z0-9]{20,}|password[\s]*[:=])/i;
141
+ function scanForCredentials(content, filePath) {
142
+ // Allowlist exception: `transcript_path` field values under
143
+ // `~/.claude/projects/` or `~/.openrig/transcripts/` are accepted
144
+ // (mirrors the v0 wrapper); same paths under any other field/key/comment
145
+ // are rejected as suspicious copying.
146
+ const transcriptPath = extractFieldValue(content, "transcript_path");
147
+ let lineNo = 0;
148
+ for (const rawLine of content.split("\n")) {
149
+ lineNo += 1;
150
+ const line = rawLine;
151
+ // Allowlist check for transcript_path's own line.
152
+ const stripped = line.replace(/^\s+/, "");
153
+ let isAllowlistedTranscript = false;
154
+ if (transcriptPath && stripped.startsWith("transcript_path:")) {
155
+ if (transcriptPath.includes("/.claude/projects/")
156
+ || transcriptPath.includes("/.openrig/transcripts/")) {
157
+ isAllowlistedTranscript = true;
158
+ }
159
+ }
160
+ // 1. Literal credential paths.
161
+ // Refusal reason intentionally REDACTS the matched line content. The
162
+ // daemon-tier resolver flows error messages into logs/API responses;
163
+ // echoing the matched line would leak the credential-bearing content
164
+ // the deny-list is meant to catch. Operators see refusal code + line
165
+ // number + file path; that's enough to triage. Closes the v0 wrapper
166
+ // diagnostic-`match`-field caveat at the daemon-tier productization
167
+ // layer (per M1 Revision 2 finding 3).
168
+ for (const literal of CRED_PATH_LITERALS) {
169
+ if (line.includes(literal)) {
170
+ return {
171
+ ok: false,
172
+ reason: `credential_path_disallowed: line ${lineNo} of ${filePath} matches a deny-list literal credential path (content redacted)`,
173
+ };
174
+ }
175
+ }
176
+ // 2. Path regex (credentials|auth.json|secrets|tokens.json).
177
+ if (!isAllowlistedTranscript && CRED_PATH_RE.test(line)) {
178
+ return {
179
+ ok: false,
180
+ reason: `credential_path_disallowed: line ${lineNo} of ${filePath} matches credential path pattern (content redacted)`,
181
+ };
182
+ }
183
+ // 3. Credential string regex (case-insensitive).
184
+ if (CRED_STRING_RE.test(line)) {
185
+ return {
186
+ ok: false,
187
+ reason: `credential_content_disallowed: line ${lineNo} of ${filePath} matches credential content pattern (content redacted)`,
188
+ };
189
+ }
190
+ }
191
+ return { ok: true };
192
+ }
193
+ function extractFieldValue(content, field) {
194
+ const re = new RegExp(`^\\s*${field}:\\s*(.*?)\\s*$`, "m");
195
+ const match = content.match(re);
196
+ if (!match || !match[1])
197
+ return "";
198
+ return match[1].replace(/^['"]|['"]$/g, "").trim();
199
+ }
200
+ //# sourceMappingURL=agent-starter-resolver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B,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,MAAM,EAAE,oCAAoC,MAAM,OAAO,QAAQ,iEAAiE;iBACnI,CAAC;YACJ,CAAC;QACH,CAAC;QAED,6DAA6D;QAC7D,IAAI,CAAC,uBAAuB,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,oCAAoC,MAAM,OAAO,QAAQ,qDAAqD;aACvH,CAAC;QACJ,CAAC;QAED,iDAAiD;QACjD,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,uCAAuC,MAAM,OAAO,QAAQ,wDAAwD;aAC7H,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe,EAAE,KAAa;IACvD,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,QAAQ,KAAK,iBAAiB,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,130 @@
1
+ import type Database from "better-sqlite3";
2
+ import type { EventBus } from "./event-bus.js";
3
+ /**
4
+ * Classifier lease manager (PL-004 Phase B; L2 founder-resolved).
5
+ *
6
+ * Daemon-enforced single-writer lease for the project (classifier) primitive.
7
+ * Per PRD § L2 hard rule + slice IMPL § Guard Checkpoint Focus item 2:
8
+ *
9
+ * - Single-writer: at most one lease in `state='active'` at any time, enforced
10
+ * via partial UNIQUE index `idx_classifier_leases_active_singleton`.
11
+ * - TTL-based expiry: every lease has an `expires_at` (acquired_at + ttlMs).
12
+ * - Heartbeat: `last_heartbeat` is updated by the lease holder. Stale heartbeat
13
+ * past TTL signals deadness.
14
+ * - Deadness detection: caller of `evaluateDeadness` is the project verb path
15
+ * OR a watchdog. The manager itself does NOT auto-reclaim — only marks
16
+ * `expired` when heartbeat is stale.
17
+ * - Reclaim is OPERATOR-VERB ONLY: `rig project --reclaim-classifier
18
+ * [--if-dead]`. Daemon does NOT auto-reclaim. The reclaim path takes the
19
+ * active lease away from the previous holder and emits classifier.reclaimed.
20
+ *
21
+ * Pattern mirrors Phase A's hot-potato-enforcer.ts shape: pure validation +
22
+ * lifecycle methods, no Hono. Routes import this; this does not import routes.
23
+ */
24
+ export declare const LEASE_STATES: readonly ["active", "expired", "reclaimed"];
25
+ export type LeaseState = (typeof LEASE_STATES)[number];
26
+ export interface ClassifierLease {
27
+ leaseId: string;
28
+ classifierSession: string;
29
+ acquiredAt: string;
30
+ expiresAt: string;
31
+ lastHeartbeat: string;
32
+ state: LeaseState;
33
+ reclaimedBySession: string | null;
34
+ reclaimReason: string | null;
35
+ }
36
+ export declare class ClassifierLeaseError extends Error {
37
+ readonly code: string;
38
+ readonly meta: Record<string, unknown> | undefined;
39
+ constructor(code: string, message: string, meta?: Record<string, unknown>);
40
+ }
41
+ export interface ClassifierLeaseManagerOptions {
42
+ ttlMs?: number;
43
+ /** For tests: inject a deterministic clock. Defaults to `() => new Date()`. */
44
+ now?: () => Date;
45
+ /**
46
+ * Liveness check (per PRD: via whoami-service / node-inventory). Returns
47
+ * true if the session is still alive. The lease-manager calls this when
48
+ * evaluating deadness; if the function returns false AND the lease's
49
+ * heartbeat is stale, the lease is marked expired.
50
+ *
51
+ * Defaults to `() => true` (no liveness check; tests can stub).
52
+ */
53
+ isAlive?: (classifierSession: string) => boolean;
54
+ }
55
+ export declare class ClassifierLeaseManager {
56
+ readonly db: Database.Database;
57
+ private readonly eventBus;
58
+ private readonly ttlMs;
59
+ private readonly now;
60
+ private isAlive;
61
+ constructor(db: Database.Database, eventBus: EventBus, opts?: ClassifierLeaseManagerOptions);
62
+ /**
63
+ * Wire post-construction liveness check (used by startup.ts when
64
+ * whoami-service is constructed later in the dep graph).
65
+ */
66
+ attachIsAlive(check: (classifierSession: string) => boolean): void;
67
+ /**
68
+ * Acquire the active lease for a classifier session. Fails with
69
+ * `lease_held` (409) if another session currently holds an active lease
70
+ * AND that session is alive. If the held lease is by a dead session, the
71
+ * caller should first invoke `evaluateDeadness` (which marks it expired)
72
+ * or use the operator reclaim path.
73
+ *
74
+ * Idempotent for the SAME classifier_session: re-calling acquire on the
75
+ * lease holder's behalf returns the existing lease unchanged (heartbeat
76
+ * is updated separately via `heartbeat`).
77
+ */
78
+ acquire(classifierSession: string): ClassifierLease;
79
+ /**
80
+ * Heartbeat from the lease holder. Updates `last_heartbeat` and extends
81
+ * `expires_at` by the TTL (sliding-window TTL semantics).
82
+ */
83
+ heartbeat(leaseId: string, classifierSession: string): ClassifierLease;
84
+ /**
85
+ * Evaluate deadness for the currently-active lease. If the lease's
86
+ * heartbeat is stale (now > expires_at) OR the holder is reported dead
87
+ * by `isAlive`, mark the lease expired and emit classifier.lease_expired
88
+ * + classifier.dead. Returns the (now-expired) lease, or null if no
89
+ * active lease exists or it remains alive.
90
+ *
91
+ * Called by: project verb path (before acquire, to clear dead leases),
92
+ * watchdog (periodic sweep), or operator-driven check.
93
+ *
94
+ * Per PRD: this method does NOT reclaim — it only marks expired. The
95
+ * next `acquire` call by ANY session can then succeed (since the partial
96
+ * UNIQUE on state='active' is now empty).
97
+ */
98
+ evaluateDeadness(): ClassifierLease | null;
99
+ /**
100
+ * Operator-verb reclaim. Per PRD § L2 hard rule: ONLY this path may take
101
+ * an active lease away from its holder. Daemon does NOT auto-reclaim.
102
+ *
103
+ * - If `ifDead`: only succeed when isAlive(holder) returns false. If the
104
+ * holder is alive, refuse with `lease_still_active`.
105
+ * - If `!ifDead`: take the lease unconditionally.
106
+ *
107
+ * Marks the active lease state='reclaimed', records reclaimed_by_session
108
+ * + reclaim_reason, and emits classifier.reclaimed. The next acquire
109
+ * (by ANY session) can then succeed.
110
+ */
111
+ reclaim(byClassifierSession: string, opts?: {
112
+ ifDead?: boolean;
113
+ reason?: string;
114
+ }): ClassifierLease;
115
+ /**
116
+ * Validation hook used by project-classifier: returns the active lease
117
+ * iff the supplied session holds it, else throws. Centralizes the
118
+ * "must hold the lease to project" check.
119
+ */
120
+ requireActiveHolder(classifierSession: string): ClassifierLease;
121
+ getActiveLease(): ClassifierLease | null;
122
+ getById(leaseId: string): ClassifierLease | null;
123
+ list(opts?: {
124
+ classifierSession?: string;
125
+ limit?: number;
126
+ }): ClassifierLease[];
127
+ private getByIdOrThrow;
128
+ private rowToLease;
129
+ }
130
+ //# sourceMappingURL=classifier-lease-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier-lease-manager.d.ts","sourceRoot":"","sources":["../../src/domain/classifier-lease-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,YAAY,6CAA8C,CAAC;AACxE,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,UAAU,CAAC;IAClB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,aAAa,EAAE,MAAM,GAA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B,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe;IA4CnG;;;;OAIG;IACH,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,GAAG,eAAe;IAwB/D,cAAc,IAAI,eAAe,GAAG,IAAI;IAOxC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAOhD,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,EAAE;IAgB9E,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,UAAU;CAYnB"}
@@ -0,0 +1,285 @@
1
+ import { ulid } from "ulid";
2
+ /**
3
+ * Classifier lease manager (PL-004 Phase B; L2 founder-resolved).
4
+ *
5
+ * Daemon-enforced single-writer lease for the project (classifier) primitive.
6
+ * Per PRD § L2 hard rule + slice IMPL § Guard Checkpoint Focus item 2:
7
+ *
8
+ * - Single-writer: at most one lease in `state='active'` at any time, enforced
9
+ * via partial UNIQUE index `idx_classifier_leases_active_singleton`.
10
+ * - TTL-based expiry: every lease has an `expires_at` (acquired_at + ttlMs).
11
+ * - Heartbeat: `last_heartbeat` is updated by the lease holder. Stale heartbeat
12
+ * past TTL signals deadness.
13
+ * - Deadness detection: caller of `evaluateDeadness` is the project verb path
14
+ * OR a watchdog. The manager itself does NOT auto-reclaim — only marks
15
+ * `expired` when heartbeat is stale.
16
+ * - Reclaim is OPERATOR-VERB ONLY: `rig project --reclaim-classifier
17
+ * [--if-dead]`. Daemon does NOT auto-reclaim. The reclaim path takes the
18
+ * active lease away from the previous holder and emits classifier.reclaimed.
19
+ *
20
+ * Pattern mirrors Phase A's hot-potato-enforcer.ts shape: pure validation +
21
+ * lifecycle methods, no Hono. Routes import this; this does not import routes.
22
+ */
23
+ export const LEASE_STATES = ["active", "expired", "reclaimed"];
24
+ export class ClassifierLeaseError extends Error {
25
+ code;
26
+ meta;
27
+ constructor(code, message, meta) {
28
+ super(message);
29
+ this.code = code;
30
+ this.meta = meta;
31
+ }
32
+ }
33
+ /**
34
+ * Default lease TTL: 15 minutes. Per PRD: "TTL-based"; concrete value is
35
+ * implementation choice. 15 min is the operator-friendly midpoint between
36
+ * stale-detection latency (longer = slower deadness signal) and unnecessary
37
+ * heartbeat traffic (shorter = more wake-ups). Configurable via constructor
38
+ * option for tests + future tuning.
39
+ */
40
+ const DEFAULT_LEASE_TTL_MS = 15 * 60 * 1000;
41
+ export class ClassifierLeaseManager {
42
+ db;
43
+ eventBus;
44
+ ttlMs;
45
+ now;
46
+ isAlive;
47
+ constructor(db, eventBus, opts) {
48
+ this.db = db;
49
+ this.eventBus = eventBus;
50
+ this.ttlMs = opts?.ttlMs ?? DEFAULT_LEASE_TTL_MS;
51
+ this.now = opts?.now ?? (() => new Date());
52
+ this.isAlive = opts?.isAlive ?? (() => true);
53
+ }
54
+ /**
55
+ * Wire post-construction liveness check (used by startup.ts when
56
+ * whoami-service is constructed later in the dep graph).
57
+ */
58
+ attachIsAlive(check) {
59
+ this.isAlive = check;
60
+ }
61
+ /**
62
+ * Acquire the active lease for a classifier session. Fails with
63
+ * `lease_held` (409) if another session currently holds an active lease
64
+ * AND that session is alive. If the held lease is by a dead session, the
65
+ * caller should first invoke `evaluateDeadness` (which marks it expired)
66
+ * or use the operator reclaim path.
67
+ *
68
+ * Idempotent for the SAME classifier_session: re-calling acquire on the
69
+ * lease holder's behalf returns the existing lease unchanged (heartbeat
70
+ * is updated separately via `heartbeat`).
71
+ */
72
+ acquire(classifierSession) {
73
+ const active = this.getActiveLease();
74
+ if (active) {
75
+ if (active.classifierSession === classifierSession) {
76
+ // Idempotent re-acquire by current holder.
77
+ return active;
78
+ }
79
+ throw new ClassifierLeaseError("lease_held", `classifier lease is held by ${active.classifierSession} until ${active.expiresAt}; reclaim via 'rig project --reclaim-classifier' if needed`, { holder: active.classifierSession, expiresAt: active.expiresAt });
80
+ }
81
+ const leaseId = ulid();
82
+ const acquiredAt = this.now().toISOString();
83
+ const expiresAt = new Date(this.now().getTime() + this.ttlMs).toISOString();
84
+ const txn = this.db.transaction(() => {
85
+ this.db
86
+ .prepare(`INSERT INTO classifier_leases (
87
+ lease_id, classifier_session, acquired_at, expires_at,
88
+ last_heartbeat, state
89
+ ) VALUES (?, ?, ?, ?, ?, 'active')`)
90
+ .run(leaseId, classifierSession, acquiredAt, expiresAt, acquiredAt);
91
+ return this.eventBus.persistWithinTransaction({
92
+ type: "classifier.lease_acquired",
93
+ leaseId,
94
+ classifierSession,
95
+ acquiredAt,
96
+ expiresAt,
97
+ });
98
+ });
99
+ const persisted = txn();
100
+ this.eventBus.notifySubscribers(persisted);
101
+ return this.getByIdOrThrow(leaseId);
102
+ }
103
+ /**
104
+ * Heartbeat from the lease holder. Updates `last_heartbeat` and extends
105
+ * `expires_at` by the TTL (sliding-window TTL semantics).
106
+ */
107
+ heartbeat(leaseId, classifierSession) {
108
+ const lease = this.getById(leaseId);
109
+ if (!lease) {
110
+ throw new ClassifierLeaseError("lease_not_found", `lease ${leaseId} not found`);
111
+ }
112
+ if (lease.classifierSession !== classifierSession) {
113
+ throw new ClassifierLeaseError("lease_session_mismatch", `lease ${leaseId} is held by ${lease.classifierSession}, not ${classifierSession}`);
114
+ }
115
+ if (lease.state !== "active") {
116
+ throw new ClassifierLeaseError("lease_not_active", `lease ${leaseId} is in state ${lease.state}; cannot heartbeat`);
117
+ }
118
+ const now = this.now();
119
+ const lastHeartbeat = now.toISOString();
120
+ const expiresAt = new Date(now.getTime() + this.ttlMs).toISOString();
121
+ this.db
122
+ .prepare(`UPDATE classifier_leases
123
+ SET last_heartbeat = ?, expires_at = ?
124
+ WHERE lease_id = ?`)
125
+ .run(lastHeartbeat, expiresAt, leaseId);
126
+ return this.getByIdOrThrow(leaseId);
127
+ }
128
+ /**
129
+ * Evaluate deadness for the currently-active lease. If the lease's
130
+ * heartbeat is stale (now > expires_at) OR the holder is reported dead
131
+ * by `isAlive`, mark the lease expired and emit classifier.lease_expired
132
+ * + classifier.dead. Returns the (now-expired) lease, or null if no
133
+ * active lease exists or it remains alive.
134
+ *
135
+ * Called by: project verb path (before acquire, to clear dead leases),
136
+ * watchdog (periodic sweep), or operator-driven check.
137
+ *
138
+ * Per PRD: this method does NOT reclaim — it only marks expired. The
139
+ * next `acquire` call by ANY session can then succeed (since the partial
140
+ * UNIQUE on state='active' is now empty).
141
+ */
142
+ evaluateDeadness() {
143
+ const active = this.getActiveLease();
144
+ if (!active)
145
+ return null;
146
+ const nowIso = this.now().toISOString();
147
+ const ttlPassed = nowIso > active.expiresAt;
148
+ const sessionDead = !this.isAlive(active.classifierSession);
149
+ if (!ttlPassed && !sessionDead)
150
+ return null;
151
+ const events = [];
152
+ const txn = this.db.transaction(() => {
153
+ this.db
154
+ .prepare(`UPDATE classifier_leases SET state = 'expired' WHERE lease_id = ? AND state = 'active'`)
155
+ .run(active.leaseId);
156
+ events.push(this.eventBus.persistWithinTransaction({
157
+ type: "classifier.lease_expired",
158
+ leaseId: active.leaseId,
159
+ classifierSession: active.classifierSession,
160
+ expiredAt: nowIso,
161
+ }));
162
+ if (sessionDead) {
163
+ events.push(this.eventBus.persistWithinTransaction({
164
+ type: "classifier.dead",
165
+ leaseId: active.leaseId,
166
+ classifierSession: active.classifierSession,
167
+ lastHeartbeat: active.lastHeartbeat,
168
+ detectedAt: nowIso,
169
+ }));
170
+ }
171
+ });
172
+ txn();
173
+ for (const e of events)
174
+ this.eventBus.notifySubscribers(e);
175
+ return this.getByIdOrThrow(active.leaseId);
176
+ }
177
+ /**
178
+ * Operator-verb reclaim. Per PRD § L2 hard rule: ONLY this path may take
179
+ * an active lease away from its holder. Daemon does NOT auto-reclaim.
180
+ *
181
+ * - If `ifDead`: only succeed when isAlive(holder) returns false. If the
182
+ * holder is alive, refuse with `lease_still_active`.
183
+ * - If `!ifDead`: take the lease unconditionally.
184
+ *
185
+ * Marks the active lease state='reclaimed', records reclaimed_by_session
186
+ * + reclaim_reason, and emits classifier.reclaimed. The next acquire
187
+ * (by ANY session) can then succeed.
188
+ */
189
+ reclaim(byClassifierSession, opts) {
190
+ const active = this.getActiveLease();
191
+ if (!active) {
192
+ throw new ClassifierLeaseError("no_active_lease", "no active classifier lease to reclaim");
193
+ }
194
+ if (opts?.ifDead === true && this.isAlive(active.classifierSession)) {
195
+ throw new ClassifierLeaseError("lease_still_active", `classifier lease holder ${active.classifierSession} is still alive; --if-dead refuses to reclaim`, { holder: active.classifierSession });
196
+ }
197
+ const reason = opts?.reason ?? (opts?.ifDead ? "operator-reclaim --if-dead" : "operator-reclaim");
198
+ const reclaimedAt = this.now().toISOString();
199
+ const txn = this.db.transaction(() => {
200
+ this.db
201
+ .prepare(`UPDATE classifier_leases
202
+ SET state = 'reclaimed',
203
+ reclaimed_by_session = ?,
204
+ reclaim_reason = ?
205
+ WHERE lease_id = ? AND state = 'active'`)
206
+ .run(byClassifierSession, reason, active.leaseId);
207
+ return this.eventBus.persistWithinTransaction({
208
+ type: "classifier.reclaimed",
209
+ leaseId: active.leaseId,
210
+ previousClassifierSession: active.classifierSession,
211
+ reclaimedBySession: byClassifierSession,
212
+ reason,
213
+ reclaimedAt,
214
+ });
215
+ });
216
+ const persisted = txn();
217
+ this.eventBus.notifySubscribers(persisted);
218
+ return this.getByIdOrThrow(active.leaseId);
219
+ }
220
+ /**
221
+ * Validation hook used by project-classifier: returns the active lease
222
+ * iff the supplied session holds it, else throws. Centralizes the
223
+ * "must hold the lease to project" check.
224
+ */
225
+ requireActiveHolder(classifierSession) {
226
+ const active = this.getActiveLease();
227
+ if (!active) {
228
+ throw new ClassifierLeaseError("no_active_lease", "no active classifier lease; call acquire first");
229
+ }
230
+ if (active.classifierSession !== classifierSession) {
231
+ throw new ClassifierLeaseError("lease_held", `classifier lease is held by ${active.classifierSession}, not ${classifierSession}`, { holder: active.classifierSession });
232
+ }
233
+ if (active.expiresAt < this.now().toISOString()) {
234
+ throw new ClassifierLeaseError("lease_expired", `classifier lease for ${classifierSession} expired at ${active.expiresAt}`);
235
+ }
236
+ return active;
237
+ }
238
+ getActiveLease() {
239
+ const row = this.db
240
+ .prepare(`SELECT * FROM classifier_leases WHERE state = 'active' LIMIT 1`)
241
+ .get();
242
+ return row ? this.rowToLease(row) : null;
243
+ }
244
+ getById(leaseId) {
245
+ const row = this.db
246
+ .prepare(`SELECT * FROM classifier_leases WHERE lease_id = ?`)
247
+ .get(leaseId);
248
+ return row ? this.rowToLease(row) : null;
249
+ }
250
+ list(opts) {
251
+ const limit = opts?.limit ?? 100;
252
+ const conditions = [];
253
+ const params = [];
254
+ if (opts?.classifierSession) {
255
+ conditions.push("classifier_session = ?");
256
+ params.push(opts.classifierSession);
257
+ }
258
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
259
+ params.push(limit);
260
+ const rows = this.db
261
+ .prepare(`SELECT * FROM classifier_leases ${where} ORDER BY acquired_at DESC LIMIT ?`)
262
+ .all(...params);
263
+ return rows.map((r) => this.rowToLease(r));
264
+ }
265
+ getByIdOrThrow(leaseId) {
266
+ const lease = this.getById(leaseId);
267
+ if (!lease) {
268
+ throw new ClassifierLeaseError("lease_not_found", `lease ${leaseId} not found after write`);
269
+ }
270
+ return lease;
271
+ }
272
+ rowToLease(row) {
273
+ return {
274
+ leaseId: row.lease_id,
275
+ classifierSession: row.classifier_session,
276
+ acquiredAt: row.acquired_at,
277
+ expiresAt: row.expires_at,
278
+ lastHeartbeat: row.last_heartbeat,
279
+ state: row.state,
280
+ reclaimedBySession: row.reclaimed_by_session,
281
+ reclaimReason: row.reclaim_reason,
282
+ };
283
+ }
284
+ }
285
+ //# sourceMappingURL=classifier-lease-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier-lease-manager.js","sourceRoot":"","sources":["../../src/domain/classifier-lease-manager.ts"],"names":[],"mappings":"AACA,OAAO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,KAAK,EAAE,GAAG,CAAC,KAAmB;YAC9B,kBAAkB,EAAE,GAAG,CAAC,oBAAoB;YAC5C,aAAa,EAAE,GAAG,CAAC,cAAc;SAClC,CAAC;IACJ,CAAC;CACF"}
@@ -1,7 +1,7 @@
1
1
  import type Database from "better-sqlite3";
2
2
  import type { ContextUsage, ContextUnknownReason } from "./types.js";
3
3
  /** Freshness threshold: samples older than this are considered stale for compact displays. */
4
- export declare const FRESHNESS_THRESHOLD_MS = 120000;
4
+ export declare const FRESHNESS_THRESHOLD_MS = 600000;
5
5
  export interface ContextUsageStoreOpts {
6
6
  stateDir: string;
7
7
  }