@coool/opencode-adaptive 0.0.0-stage → 1.0.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 (440) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -2
  3. package/dist/adapters/codex-capacity/index.d.ts +5 -0
  4. package/dist/adapters/codex-capacity/index.d.ts.map +1 -0
  5. package/dist/adapters/codex-capacity/index.js +5 -0
  6. package/dist/adapters/codex-capacity/index.js.map +1 -0
  7. package/dist/adapters/codex-capacity/parse.d.ts +28 -0
  8. package/dist/adapters/codex-capacity/parse.d.ts.map +1 -0
  9. package/dist/adapters/codex-capacity/parse.js +130 -0
  10. package/dist/adapters/codex-capacity/parse.js.map +1 -0
  11. package/dist/adapters/codex-capacity/reading.d.ts +10 -0
  12. package/dist/adapters/codex-capacity/reading.d.ts.map +1 -0
  13. package/dist/adapters/codex-capacity/reading.js +45 -0
  14. package/dist/adapters/codex-capacity/reading.js.map +1 -0
  15. package/dist/adapters/codex-capacity/sensor.d.ts +24 -0
  16. package/dist/adapters/codex-capacity/sensor.d.ts.map +1 -0
  17. package/dist/adapters/codex-capacity/sensor.js +30 -0
  18. package/dist/adapters/codex-capacity/sensor.js.map +1 -0
  19. package/dist/adapters/codex-capacity/types.d.ts +35 -0
  20. package/dist/adapters/codex-capacity/types.d.ts.map +1 -0
  21. package/dist/adapters/codex-capacity/types.js +4 -0
  22. package/dist/adapters/codex-capacity/types.js.map +1 -0
  23. package/dist/adapters/opencode/escalation-tool.d.ts +52 -0
  24. package/dist/adapters/opencode/escalation-tool.d.ts.map +1 -0
  25. package/dist/adapters/opencode/escalation-tool.js +59 -0
  26. package/dist/adapters/opencode/escalation-tool.js.map +1 -0
  27. package/dist/adapters/opencode/events.d.ts +24 -0
  28. package/dist/adapters/opencode/events.d.ts.map +1 -0
  29. package/dist/adapters/opencode/events.js +68 -0
  30. package/dist/adapters/opencode/events.js.map +1 -0
  31. package/dist/adapters/opencode/hooks.d.ts +35 -0
  32. package/dist/adapters/opencode/hooks.d.ts.map +1 -0
  33. package/dist/adapters/opencode/hooks.js +12 -0
  34. package/dist/adapters/opencode/hooks.js.map +1 -0
  35. package/dist/adapters/opencode/index.d.ts +17 -0
  36. package/dist/adapters/opencode/index.d.ts.map +1 -0
  37. package/dist/adapters/opencode/index.js +9 -0
  38. package/dist/adapters/opencode/index.js.map +1 -0
  39. package/dist/adapters/opencode/inventory.d.ts +31 -0
  40. package/dist/adapters/opencode/inventory.d.ts.map +1 -0
  41. package/dist/adapters/opencode/inventory.js +53 -0
  42. package/dist/adapters/opencode/inventory.js.map +1 -0
  43. package/dist/adapters/opencode/report.d.ts +92 -0
  44. package/dist/adapters/opencode/report.d.ts.map +1 -0
  45. package/dist/adapters/opencode/report.js +145 -0
  46. package/dist/adapters/opencode/report.js.map +1 -0
  47. package/dist/adapters/opencode/session-ops.d.ts +40 -0
  48. package/dist/adapters/opencode/session-ops.d.ts.map +1 -0
  49. package/dist/adapters/opencode/session-ops.js +32 -0
  50. package/dist/adapters/opencode/session-ops.js.map +1 -0
  51. package/dist/adapters/opencode/storage.d.ts +16 -0
  52. package/dist/adapters/opencode/storage.d.ts.map +1 -0
  53. package/dist/adapters/opencode/storage.js +8 -0
  54. package/dist/adapters/opencode/storage.js.map +1 -0
  55. package/dist/adapters/opencode/tier-tool.d.ts +38 -0
  56. package/dist/adapters/opencode/tier-tool.d.ts.map +1 -0
  57. package/dist/adapters/opencode/tier-tool.js +72 -0
  58. package/dist/adapters/opencode/tier-tool.js.map +1 -0
  59. package/dist/adapters/opencode/types.d.ts +102 -0
  60. package/dist/adapters/opencode/types.d.ts.map +1 -0
  61. package/dist/adapters/opencode/types.js +2 -0
  62. package/dist/adapters/opencode/types.js.map +1 -0
  63. package/dist/core/compatibility/gate.d.ts +10 -0
  64. package/dist/core/compatibility/gate.d.ts.map +1 -0
  65. package/dist/core/compatibility/gate.js +55 -0
  66. package/dist/core/compatibility/gate.js.map +1 -0
  67. package/dist/core/compatibility/index.d.ts +3 -0
  68. package/dist/core/compatibility/index.d.ts.map +1 -0
  69. package/dist/core/compatibility/index.js +3 -0
  70. package/dist/core/compatibility/index.js.map +1 -0
  71. package/dist/core/compatibility/types.d.ts +54 -0
  72. package/dist/core/compatibility/types.d.ts.map +1 -0
  73. package/dist/core/compatibility/types.js +27 -0
  74. package/dist/core/compatibility/types.js.map +1 -0
  75. package/dist/core/scheduler/admit.d.ts +7 -0
  76. package/dist/core/scheduler/admit.d.ts.map +1 -0
  77. package/dist/core/scheduler/admit.js +153 -0
  78. package/dist/core/scheduler/admit.js.map +1 -0
  79. package/dist/core/scheduler/escalate.d.ts +7 -0
  80. package/dist/core/scheduler/escalate.d.ts.map +1 -0
  81. package/dist/core/scheduler/escalate.js +56 -0
  82. package/dist/core/scheduler/escalate.js.map +1 -0
  83. package/dist/core/scheduler/index.d.ts +5 -0
  84. package/dist/core/scheduler/index.d.ts.map +1 -0
  85. package/dist/core/scheduler/index.js +5 -0
  86. package/dist/core/scheduler/index.js.map +1 -0
  87. package/dist/core/scheduler/mode.d.ts +9 -0
  88. package/dist/core/scheduler/mode.d.ts.map +1 -0
  89. package/dist/core/scheduler/mode.js +10 -0
  90. package/dist/core/scheduler/mode.js.map +1 -0
  91. package/dist/core/scheduler/types.d.ts +143 -0
  92. package/dist/core/scheduler/types.d.ts.map +1 -0
  93. package/dist/core/scheduler/types.js +74 -0
  94. package/dist/core/scheduler/types.js.map +1 -0
  95. package/dist/core/tier-policy/index.d.ts +4 -0
  96. package/dist/core/tier-policy/index.d.ts.map +1 -0
  97. package/dist/core/tier-policy/index.js +4 -0
  98. package/dist/core/tier-policy/index.js.map +1 -0
  99. package/dist/core/tier-policy/resolve.d.ts +19 -0
  100. package/dist/core/tier-policy/resolve.d.ts.map +1 -0
  101. package/dist/core/tier-policy/resolve.js +52 -0
  102. package/dist/core/tier-policy/resolve.js.map +1 -0
  103. package/dist/core/tier-policy/tier-list.d.ts +11 -0
  104. package/dist/core/tier-policy/tier-list.d.ts.map +1 -0
  105. package/dist/core/tier-policy/tier-list.js +23 -0
  106. package/dist/core/tier-policy/tier-list.js.map +1 -0
  107. package/dist/core/tier-policy/types.d.ts +85 -0
  108. package/dist/core/tier-policy/types.d.ts.map +1 -0
  109. package/dist/core/tier-policy/types.js +45 -0
  110. package/dist/core/tier-policy/types.js.map +1 -0
  111. package/dist/core/work-unit/index.d.ts +4 -0
  112. package/dist/core/work-unit/index.d.ts.map +1 -0
  113. package/dist/core/work-unit/index.js +4 -0
  114. package/dist/core/work-unit/index.js.map +1 -0
  115. package/dist/core/work-unit/interruption.d.ts +8 -0
  116. package/dist/core/work-unit/interruption.d.ts.map +1 -0
  117. package/dist/core/work-unit/interruption.js +12 -0
  118. package/dist/core/work-unit/interruption.js.map +1 -0
  119. package/dist/core/work-unit/tracker.d.ts +46 -0
  120. package/dist/core/work-unit/tracker.d.ts.map +1 -0
  121. package/dist/core/work-unit/tracker.js +136 -0
  122. package/dist/core/work-unit/tracker.js.map +1 -0
  123. package/dist/core/work-unit/types.d.ts +146 -0
  124. package/dist/core/work-unit/types.d.ts.map +1 -0
  125. package/dist/core/work-unit/types.js +23 -0
  126. package/dist/core/work-unit/types.js.map +1 -0
  127. package/dist/execution/continuation/execute.d.ts +19 -0
  128. package/dist/execution/continuation/execute.d.ts.map +1 -0
  129. package/dist/execution/continuation/execute.js +31 -0
  130. package/dist/execution/continuation/execute.js.map +1 -0
  131. package/dist/execution/continuation/index.d.ts +6 -0
  132. package/dist/execution/continuation/index.d.ts.map +1 -0
  133. package/dist/execution/continuation/index.js +5 -0
  134. package/dist/execution/continuation/index.js.map +1 -0
  135. package/dist/execution/continuation/ledger.d.ts +20 -0
  136. package/dist/execution/continuation/ledger.d.ts.map +1 -0
  137. package/dist/execution/continuation/ledger.js +31 -0
  138. package/dist/execution/continuation/ledger.js.map +1 -0
  139. package/dist/execution/continuation/plan.d.ts +13 -0
  140. package/dist/execution/continuation/plan.d.ts.map +1 -0
  141. package/dist/execution/continuation/plan.js +20 -0
  142. package/dist/execution/continuation/plan.js.map +1 -0
  143. package/dist/execution/continuation/prompts.d.ts +8 -0
  144. package/dist/execution/continuation/prompts.d.ts.map +1 -0
  145. package/dist/execution/continuation/prompts.js +8 -0
  146. package/dist/execution/continuation/prompts.js.map +1 -0
  147. package/dist/execution/continuation/types.d.ts +70 -0
  148. package/dist/execution/continuation/types.d.ts.map +1 -0
  149. package/dist/execution/continuation/types.js +15 -0
  150. package/dist/execution/continuation/types.js.map +1 -0
  151. package/dist/execution/escalation/index.d.ts +2 -0
  152. package/dist/execution/escalation/index.d.ts.map +1 -0
  153. package/dist/execution/escalation/index.js +2 -0
  154. package/dist/execution/escalation/index.js.map +1 -0
  155. package/dist/execution/escalation/types.d.ts +31 -0
  156. package/dist/execution/escalation/types.d.ts.map +1 -0
  157. package/dist/execution/escalation/types.js +49 -0
  158. package/dist/execution/escalation/types.js.map +1 -0
  159. package/dist/execution/index.d.ts +5 -0
  160. package/dist/execution/index.d.ts.map +1 -0
  161. package/dist/execution/index.js +5 -0
  162. package/dist/execution/index.js.map +1 -0
  163. package/dist/execution/parking/index.d.ts +3 -0
  164. package/dist/execution/parking/index.d.ts.map +1 -0
  165. package/dist/execution/parking/index.js +2 -0
  166. package/dist/execution/parking/index.js.map +1 -0
  167. package/dist/execution/parking/plan.d.ts +40 -0
  168. package/dist/execution/parking/plan.d.ts.map +1 -0
  169. package/dist/execution/parking/plan.js +34 -0
  170. package/dist/execution/parking/plan.js.map +1 -0
  171. package/dist/execution/recovery/gate.d.ts +20 -0
  172. package/dist/execution/recovery/gate.d.ts.map +1 -0
  173. package/dist/execution/recovery/gate.js +23 -0
  174. package/dist/execution/recovery/gate.js.map +1 -0
  175. package/dist/execution/recovery/index.d.ts +3 -0
  176. package/dist/execution/recovery/index.d.ts.map +1 -0
  177. package/dist/execution/recovery/index.js +2 -0
  178. package/dist/execution/recovery/index.js.map +1 -0
  179. package/dist/execution/retry/decide.d.ts +30 -0
  180. package/dist/execution/retry/decide.d.ts.map +1 -0
  181. package/dist/execution/retry/decide.js +76 -0
  182. package/dist/execution/retry/decide.js.map +1 -0
  183. package/dist/execution/retry/index.d.ts +3 -0
  184. package/dist/execution/retry/index.d.ts.map +1 -0
  185. package/dist/execution/retry/index.js +3 -0
  186. package/dist/execution/retry/index.js.map +1 -0
  187. package/dist/execution/retry/types.d.ts +66 -0
  188. package/dist/execution/retry/types.d.ts.map +1 -0
  189. package/dist/execution/retry/types.js +9 -0
  190. package/dist/execution/retry/types.js.map +1 -0
  191. package/dist/gui-experimental.cjs +1 -0
  192. package/dist/gui.d.ts +17 -0
  193. package/dist/gui.d.ts.map +1 -0
  194. package/dist/gui.js +70 -0
  195. package/dist/gui.js.map +1 -0
  196. package/dist/health/capacity/index.d.ts +4 -0
  197. package/dist/health/capacity/index.d.ts.map +1 -0
  198. package/dist/health/capacity/index.js +4 -0
  199. package/dist/health/capacity/index.js.map +1 -0
  200. package/dist/health/capacity/merge.d.ts +58 -0
  201. package/dist/health/capacity/merge.d.ts.map +1 -0
  202. package/dist/health/capacity/merge.js +154 -0
  203. package/dist/health/capacity/merge.js.map +1 -0
  204. package/dist/health/capacity/registry.d.ts +41 -0
  205. package/dist/health/capacity/registry.d.ts.map +1 -0
  206. package/dist/health/capacity/registry.js +106 -0
  207. package/dist/health/capacity/registry.js.map +1 -0
  208. package/dist/health/capacity/types.d.ts +74 -0
  209. package/dist/health/capacity/types.d.ts.map +1 -0
  210. package/dist/health/capacity/types.js +6 -0
  211. package/dist/health/capacity/types.js.map +1 -0
  212. package/dist/health/circuit-breaker/breaker.d.ts +84 -0
  213. package/dist/health/circuit-breaker/breaker.d.ts.map +1 -0
  214. package/dist/health/circuit-breaker/breaker.js +132 -0
  215. package/dist/health/circuit-breaker/breaker.js.map +1 -0
  216. package/dist/health/circuit-breaker/index.d.ts +3 -0
  217. package/dist/health/circuit-breaker/index.d.ts.map +1 -0
  218. package/dist/health/circuit-breaker/index.js +3 -0
  219. package/dist/health/circuit-breaker/index.js.map +1 -0
  220. package/dist/health/circuit-breaker/types.d.ts +53 -0
  221. package/dist/health/circuit-breaker/types.d.ts.map +1 -0
  222. package/dist/health/circuit-breaker/types.js +13 -0
  223. package/dist/health/circuit-breaker/types.js.map +1 -0
  224. package/dist/health/classifier/classify.d.ts +9 -0
  225. package/dist/health/classifier/classify.d.ts.map +1 -0
  226. package/dist/health/classifier/classify.js +245 -0
  227. package/dist/health/classifier/classify.js.map +1 -0
  228. package/dist/health/classifier/index.d.ts +3 -0
  229. package/dist/health/classifier/index.d.ts.map +1 -0
  230. package/dist/health/classifier/index.js +3 -0
  231. package/dist/health/classifier/index.js.map +1 -0
  232. package/dist/health/classifier/types.d.ts +72 -0
  233. package/dist/health/classifier/types.d.ts.map +1 -0
  234. package/dist/health/classifier/types.js +27 -0
  235. package/dist/health/classifier/types.js.map +1 -0
  236. package/dist/health/index.d.ts +5 -0
  237. package/dist/health/index.d.ts.map +1 -0
  238. package/dist/health/index.js +5 -0
  239. package/dist/health/index.js.map +1 -0
  240. package/dist/health/resource-health/index.d.ts +5 -0
  241. package/dist/health/resource-health/index.d.ts.map +1 -0
  242. package/dist/health/resource-health/index.js +5 -0
  243. package/dist/health/resource-health/index.js.map +1 -0
  244. package/dist/health/resource-health/key.d.ts +19 -0
  245. package/dist/health/resource-health/key.d.ts.map +1 -0
  246. package/dist/health/resource-health/key.js +54 -0
  247. package/dist/health/resource-health/key.js.map +1 -0
  248. package/dist/health/resource-health/registry.d.ts +41 -0
  249. package/dist/health/resource-health/registry.d.ts.map +1 -0
  250. package/dist/health/resource-health/registry.js +258 -0
  251. package/dist/health/resource-health/registry.js.map +1 -0
  252. package/dist/health/resource-health/transitions.d.ts +11 -0
  253. package/dist/health/resource-health/transitions.d.ts.map +1 -0
  254. package/dist/health/resource-health/transitions.js +165 -0
  255. package/dist/health/resource-health/transitions.js.map +1 -0
  256. package/dist/health/resource-health/types.d.ts +116 -0
  257. package/dist/health/resource-health/types.d.ts.map +1 -0
  258. package/dist/health/resource-health/types.js +43 -0
  259. package/dist/health/resource-health/types.js.map +1 -0
  260. package/dist/index.d.ts +17 -0
  261. package/dist/index.d.ts.map +1 -0
  262. package/dist/index.js +80 -0
  263. package/dist/index.js.map +1 -0
  264. package/dist/plugin-id.d.ts +3 -0
  265. package/dist/plugin-id.d.ts.map +1 -0
  266. package/dist/plugin-id.js +3 -0
  267. package/dist/plugin-id.js.map +1 -0
  268. package/dist/rpc/definition.d.ts +100 -0
  269. package/dist/rpc/definition.d.ts.map +1 -0
  270. package/dist/rpc/definition.js +104 -0
  271. package/dist/rpc/definition.js.map +1 -0
  272. package/dist/rpc/handlers.d.ts +65 -0
  273. package/dist/rpc/handlers.d.ts.map +1 -0
  274. package/dist/rpc/handlers.js +111 -0
  275. package/dist/rpc/handlers.js.map +1 -0
  276. package/dist/rpc/status.d.ts +43 -0
  277. package/dist/rpc/status.d.ts.map +1 -0
  278. package/dist/rpc/status.js +45 -0
  279. package/dist/rpc/status.js.map +1 -0
  280. package/dist/rpc.d.ts +11 -0
  281. package/dist/rpc.d.ts.map +1 -0
  282. package/dist/rpc.js +8 -0
  283. package/dist/rpc.js.map +1 -0
  284. package/dist/state/capacity/index.d.ts +4 -0
  285. package/dist/state/capacity/index.d.ts.map +1 -0
  286. package/dist/state/capacity/index.js +4 -0
  287. package/dist/state/capacity/index.js.map +1 -0
  288. package/dist/state/capacity/parse.d.ts +3 -0
  289. package/dist/state/capacity/parse.d.ts.map +1 -0
  290. package/dist/state/capacity/parse.js +110 -0
  291. package/dist/state/capacity/parse.js.map +1 -0
  292. package/dist/state/capacity/store.d.ts +19 -0
  293. package/dist/state/capacity/store.d.ts.map +1 -0
  294. package/dist/state/capacity/store.js +64 -0
  295. package/dist/state/capacity/store.js.map +1 -0
  296. package/dist/state/capacity/types.d.ts +38 -0
  297. package/dist/state/capacity/types.d.ts.map +1 -0
  298. package/dist/state/capacity/types.js +11 -0
  299. package/dist/state/capacity/types.js.map +1 -0
  300. package/dist/state/health/index.d.ts +5 -0
  301. package/dist/state/health/index.d.ts.map +1 -0
  302. package/dist/state/health/index.js +4 -0
  303. package/dist/state/health/index.js.map +1 -0
  304. package/dist/state/health/parse.d.ts +3 -0
  305. package/dist/state/health/parse.d.ts.map +1 -0
  306. package/dist/state/health/parse.js +121 -0
  307. package/dist/state/health/parse.js.map +1 -0
  308. package/dist/state/health/store.d.ts +18 -0
  309. package/dist/state/health/store.d.ts.map +1 -0
  310. package/dist/state/health/store.js +55 -0
  311. package/dist/state/health/store.js.map +1 -0
  312. package/dist/state/health/types.d.ts +24 -0
  313. package/dist/state/health/types.d.ts.map +1 -0
  314. package/dist/state/health/types.js +5 -0
  315. package/dist/state/health/types.js.map +1 -0
  316. package/dist/state/parked-work/index.d.ts +5 -0
  317. package/dist/state/parked-work/index.d.ts.map +1 -0
  318. package/dist/state/parked-work/index.js +4 -0
  319. package/dist/state/parked-work/index.js.map +1 -0
  320. package/dist/state/parked-work/parse.d.ts +7 -0
  321. package/dist/state/parked-work/parse.d.ts.map +1 -0
  322. package/dist/state/parked-work/parse.js +83 -0
  323. package/dist/state/parked-work/parse.js.map +1 -0
  324. package/dist/state/parked-work/store.d.ts +18 -0
  325. package/dist/state/parked-work/store.d.ts.map +1 -0
  326. package/dist/state/parked-work/store.js +81 -0
  327. package/dist/state/parked-work/store.js.map +1 -0
  328. package/dist/state/parked-work/types.d.ts +42 -0
  329. package/dist/state/parked-work/types.d.ts.map +1 -0
  330. package/dist/state/parked-work/types.js +7 -0
  331. package/dist/state/parked-work/types.js.map +1 -0
  332. package/dist/state/receipts/bound.d.ts +15 -0
  333. package/dist/state/receipts/bound.d.ts.map +1 -0
  334. package/dist/state/receipts/bound.js +77 -0
  335. package/dist/state/receipts/bound.js.map +1 -0
  336. package/dist/state/receipts/index.d.ts +7 -0
  337. package/dist/state/receipts/index.d.ts.map +1 -0
  338. package/dist/state/receipts/index.js +5 -0
  339. package/dist/state/receipts/index.js.map +1 -0
  340. package/dist/state/receipts/parse.d.ts +7 -0
  341. package/dist/state/receipts/parse.d.ts.map +1 -0
  342. package/dist/state/receipts/parse.js +226 -0
  343. package/dist/state/receipts/parse.js.map +1 -0
  344. package/dist/state/receipts/store.d.ts +35 -0
  345. package/dist/state/receipts/store.d.ts.map +1 -0
  346. package/dist/state/receipts/store.js +128 -0
  347. package/dist/state/receipts/store.js.map +1 -0
  348. package/dist/state/receipts/types.d.ts +62 -0
  349. package/dist/state/receipts/types.d.ts.map +1 -0
  350. package/dist/state/receipts/types.js +12 -0
  351. package/dist/state/receipts/types.js.map +1 -0
  352. package/dist/state/session-modes/index.d.ts +5 -0
  353. package/dist/state/session-modes/index.d.ts.map +1 -0
  354. package/dist/state/session-modes/index.js +4 -0
  355. package/dist/state/session-modes/index.js.map +1 -0
  356. package/dist/state/session-modes/parse.d.ts +9 -0
  357. package/dist/state/session-modes/parse.d.ts.map +1 -0
  358. package/dist/state/session-modes/parse.js +62 -0
  359. package/dist/state/session-modes/parse.js.map +1 -0
  360. package/dist/state/session-modes/store.d.ts +21 -0
  361. package/dist/state/session-modes/store.d.ts.map +1 -0
  362. package/dist/state/session-modes/store.js +73 -0
  363. package/dist/state/session-modes/store.js.map +1 -0
  364. package/dist/state/session-modes/types.d.ts +42 -0
  365. package/dist/state/session-modes/types.d.ts.map +1 -0
  366. package/dist/state/session-modes/types.js +7 -0
  367. package/dist/state/session-modes/types.js.map +1 -0
  368. package/dist/state/settings/index.d.ts +5 -0
  369. package/dist/state/settings/index.d.ts.map +1 -0
  370. package/dist/state/settings/index.js +4 -0
  371. package/dist/state/settings/index.js.map +1 -0
  372. package/dist/state/settings/parse.d.ts +34 -0
  373. package/dist/state/settings/parse.d.ts.map +1 -0
  374. package/dist/state/settings/parse.js +261 -0
  375. package/dist/state/settings/parse.js.map +1 -0
  376. package/dist/state/settings/store.d.ts +22 -0
  377. package/dist/state/settings/store.d.ts.map +1 -0
  378. package/dist/state/settings/store.js +57 -0
  379. package/dist/state/settings/store.js.map +1 -0
  380. package/dist/state/settings/types.d.ts +63 -0
  381. package/dist/state/settings/types.d.ts.map +1 -0
  382. package/dist/state/settings/types.js +12 -0
  383. package/dist/state/settings/types.js.map +1 -0
  384. package/dist/supervisor/index.d.ts +5 -0
  385. package/dist/supervisor/index.d.ts.map +1 -0
  386. package/dist/supervisor/index.js +4 -0
  387. package/dist/supervisor/index.js.map +1 -0
  388. package/dist/supervisor/log.d.ts +11 -0
  389. package/dist/supervisor/log.d.ts.map +1 -0
  390. package/dist/supervisor/log.js +14 -0
  391. package/dist/supervisor/log.js.map +1 -0
  392. package/dist/supervisor/supervisor.d.ts +69 -0
  393. package/dist/supervisor/supervisor.d.ts.map +1 -0
  394. package/dist/supervisor/supervisor.js +1343 -0
  395. package/dist/supervisor/supervisor.js.map +1 -0
  396. package/dist/supervisor/types.d.ts +50 -0
  397. package/dist/supervisor/types.d.ts.map +1 -0
  398. package/dist/supervisor/types.js +3 -0
  399. package/dist/supervisor/types.js.map +1 -0
  400. package/dist/supervisor/view.d.ts +4 -0
  401. package/dist/supervisor/view.d.ts.map +1 -0
  402. package/dist/supervisor/view.js +4 -0
  403. package/dist/supervisor/view.js.map +1 -0
  404. package/dist/tui.d.ts +16 -0
  405. package/dist/tui.d.ts.map +1 -0
  406. package/dist/tui.js +252 -0
  407. package/dist/tui.js.map +1 -0
  408. package/dist/ui/gui/api.d.ts +18 -0
  409. package/dist/ui/gui/api.d.ts.map +1 -0
  410. package/dist/ui/gui/api.js +21 -0
  411. package/dist/ui/gui/api.js.map +1 -0
  412. package/dist/ui/gui/view.d.ts +27 -0
  413. package/dist/ui/gui/view.d.ts.map +1 -0
  414. package/dist/ui/gui/view.js +49 -0
  415. package/dist/ui/gui/view.js.map +1 -0
  416. package/dist/ui/tui/controller.d.ts +98 -0
  417. package/dist/ui/tui/controller.d.ts.map +1 -0
  418. package/dist/ui/tui/controller.js +399 -0
  419. package/dist/ui/tui/controller.js.map +1 -0
  420. package/dist/ui/tui/menu.d.ts +56 -0
  421. package/dist/ui/tui/menu.d.ts.map +1 -0
  422. package/dist/ui/tui/menu.js +176 -0
  423. package/dist/ui/tui/menu.js.map +1 -0
  424. package/dist/ui/tui/options.d.ts +20 -0
  425. package/dist/ui/tui/options.d.ts.map +1 -0
  426. package/dist/ui/tui/options.js +17 -0
  427. package/dist/ui/tui/options.js.map +1 -0
  428. package/dist/ui/tui/receipts.d.ts +22 -0
  429. package/dist/ui/tui/receipts.d.ts.map +1 -0
  430. package/dist/ui/tui/receipts.js +109 -0
  431. package/dist/ui/tui/receipts.js.map +1 -0
  432. package/dist/ui/tui/status.d.ts +23 -0
  433. package/dist/ui/tui/status.d.ts.map +1 -0
  434. package/dist/ui/tui/status.js +90 -0
  435. package/dist/ui/tui/status.js.map +1 -0
  436. package/dist/ui/tui/tiers.d.ts +52 -0
  437. package/dist/ui/tui/tiers.d.ts.map +1 -0
  438. package/dist/ui/tui/tiers.js +108 -0
  439. package/dist/ui/tui/tiers.js.map +1 -0
  440. package/package.json +85 -4
@@ -0,0 +1,4 @@
1
+ export { CAPACITY_KEY, CAPACITY_VERSION, MAX_CAPACITY_READINGS, type CapacityPayload, type CapacityStorage, type PersistedCapacityReading, } from "./types.js";
2
+ export { parseCapacityPayload } from "./parse.js";
3
+ export { CapacityReadingStore } from "./store.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/state/capacity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { CAPACITY_KEY, CAPACITY_VERSION, MAX_CAPACITY_READINGS, } from "./types.js";
2
+ export { parseCapacityPayload } from "./parse.js";
3
+ export { CapacityReadingStore } from "./store.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/state/capacity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,GAItB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { type PersistedCapacityReading } from "./types.js";
2
+ export declare function parseCapacityPayload(raw: unknown): PersistedCapacityReading[];
3
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/state/capacity/parse.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2C,KAAK,wBAAwB,EAAE,MAAM,YAAY,CAAA;AA8FnG,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,wBAAwB,EAAE,CAW7E"}
@@ -0,0 +1,110 @@
1
+ import { CONFIDENCE_LEVELS } from "../../health/capacity/types.js";
2
+ import { CAPACITY_VERSION, MAX_CAPACITY_READINGS } from "./types.js";
3
+ // Defensive readers: persisted data is untrusted. Every parser is total —
4
+ // accepts unknown, returns typed records, and drops anything invalid — so a
5
+ // corrupted file can never take the plugin down (ADP-031). An older plugin
6
+ // reading a newer payload drops unknown-vocabulary entries; the version field
7
+ // guards the schema itself.
8
+ function isRecord(value) {
9
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10
+ }
11
+ function isFiniteNumber(raw) {
12
+ return typeof raw === "number" && Number.isFinite(raw);
13
+ }
14
+ function parseIdentifier(raw) {
15
+ if (typeof raw !== "string")
16
+ return undefined;
17
+ return raw.length > 128 ? raw.slice(0, 128) : raw;
18
+ }
19
+ function parseKey(raw) {
20
+ if (!isRecord(raw))
21
+ return undefined;
22
+ const providerID = parseIdentifier(raw["providerID"]);
23
+ if (providerID === undefined)
24
+ return undefined;
25
+ const accountID = parseIdentifier(raw["accountID"]);
26
+ const modelID = parseIdentifier(raw["modelID"]);
27
+ const variantID = parseIdentifier(raw["variantID"]);
28
+ // Scope fields must form a valid prefix: a variant without a model is not
29
+ // addressable against a model inventory and is not a real resource.
30
+ if (variantID !== undefined && modelID === undefined)
31
+ return undefined;
32
+ return {
33
+ providerID,
34
+ ...(accountID !== undefined ? { accountID } : {}),
35
+ ...(modelID !== undefined ? { modelID } : {}),
36
+ ...(variantID !== undefined ? { variantID } : {}),
37
+ };
38
+ }
39
+ function parseRatio(raw) {
40
+ return isFiniteNumber(raw) && raw >= 0 && raw <= 1 ? raw : undefined;
41
+ }
42
+ function parseReading(raw) {
43
+ if (!isRecord(raw))
44
+ return undefined;
45
+ const confidence = CONFIDENCE_LEVELS.find((level) => level === raw["confidence"]);
46
+ if (confidence === undefined)
47
+ return undefined;
48
+ const observedAt = raw["observedAt"];
49
+ if (!isFiniteNumber(observedAt) || observedAt < 0)
50
+ return undefined;
51
+ const usedRatio = parseRatio(raw["usedRatio"]);
52
+ const remainingRatio = parseRatio(raw["remainingRatio"]);
53
+ const retryAfterMs = isFiniteNumber(raw["retryAfterMs"]) && raw["retryAfterMs"] >= 0
54
+ ? raw["retryAfterMs"]
55
+ : undefined;
56
+ const resetAt = isFiniteNumber(raw["resetAt"]) && raw["resetAt"] >= 0 ? raw["resetAt"] : undefined;
57
+ // A reading with none of the measured fields carries no information and is
58
+ // discarded (mirrors the domain rule in health/capacity/types.ts).
59
+ if (usedRatio === undefined &&
60
+ remainingRatio === undefined &&
61
+ retryAfterMs === undefined &&
62
+ resetAt === undefined) {
63
+ return undefined;
64
+ }
65
+ const evidence = raw["evidence"];
66
+ return {
67
+ ...(usedRatio !== undefined ? { usedRatio } : {}),
68
+ ...(remainingRatio !== undefined ? { remainingRatio } : {}),
69
+ ...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
70
+ ...(resetAt !== undefined ? { resetAt } : {}),
71
+ confidence,
72
+ observedAt,
73
+ ...(typeof evidence === "string" && evidence.length > 0
74
+ ? { evidence: evidence.slice(0, 128) }
75
+ : {}),
76
+ };
77
+ }
78
+ function parseEntry(raw) {
79
+ if (!isRecord(raw))
80
+ return undefined;
81
+ const key = parseKey(raw["key"]);
82
+ if (key === undefined)
83
+ return undefined;
84
+ const reading = parseReading(raw["reading"]);
85
+ if (reading === undefined)
86
+ return undefined;
87
+ return { key, reading };
88
+ }
89
+ // Every parser is total: accepts unknown, returns typed records, and drops
90
+ // anything invalid — a corrupted file can never take the plugin down
91
+ // (ADP-031). An older plugin reading newer records may drop
92
+ // unknown-vocabulary entries — records are bounded mirrors of an in-memory
93
+ // registry, and the payload version guards the schema itself.
94
+ export function parseCapacityPayload(raw) {
95
+ if (!isRecord(raw))
96
+ return [];
97
+ if (raw["version"] !== CAPACITY_VERSION)
98
+ return [];
99
+ if (!Array.isArray(raw["readings"]))
100
+ return [];
101
+ const list = raw["readings"];
102
+ const readings = [];
103
+ for (const entry of list.slice(0, MAX_CAPACITY_READINGS)) {
104
+ const parsed = parseEntry(entry);
105
+ if (parsed !== undefined)
106
+ readings.push(parsed);
107
+ }
108
+ return readings;
109
+ }
110
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/state/capacity/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAGlE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAA;AAEnG,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,4BAA4B;AAE5B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK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IAC3C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AACzB,CAAC;AAED,2EAA2E;AAC3E,qEAAqE;AACrE,4DAA4D;AAC5D,2EAA2E;AAC3E,8DAA8D;AAC9D,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAA;IAC7B,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,gBAAgB;QAAE,OAAO,EAAE,CAAA;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAAE,OAAO,EAAE,CAAA;IAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAA;IAC5B,MAAM,QAAQ,GAA+B,EAAE,CAAA;IAC/C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC,EAAE,CAAC;QACzD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAChC,IAAI,MAAM,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type CapacityStorage, type PersistedCapacityReading } from "./types.js";
2
+ export declare class CapacityReadingStore {
3
+ #private;
4
+ private readonly storage;
5
+ constructor(storage: CapacityStorage);
6
+ /** Load the persisted mirror; unreadable or corrupt data is empty, not an error. */
7
+ load(): Promise<void>;
8
+ snapshot(): readonly PersistedCapacityReading[];
9
+ /**
10
+ * Merge one refresh batch into the mirror and persist it. Merge — not
11
+ * replace — per resource key, with the newest `observedAt` winning: the TUI
12
+ * host loads this plugin into several supervisor instances, and an instance
13
+ * whose sensors have seen nothing must never clobber what the observing
14
+ * instance persisted. Bound by MAX_CAPACITY_READINGS, evicting the oldest
15
+ * observations first.
16
+ */
17
+ replace(entries: readonly PersistedCapacityReading[]): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/state/capacity/store.ts"],"names":[],"mappings":"AAWA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC9B,MAAM,YAAY,CAAA;AAGnB,qBAAa,oBAAoB;;IAGnB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,eAAe;IAErD,oFAAoF;IAC9E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,QAAQ,IAAI,SAAS,wBAAwB,EAAE;IAI/C;;;;;;;OAOG;IACG,OAAO,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB3E"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Persistence mirror of the in-memory capacity registry: loads what any
3
+ * instance observed and keeps it bounded (oldest-observed evicted), merging
4
+ * per resource key on every replace.
5
+ *
6
+ * As everywhere else in state/, memory is only advanced after a successful
7
+ * write, so memory and disk never diverge; write failures propagate to the
8
+ * caller — the wiring layer's fail-open wrapper decides how to degrade
9
+ * (ADP-031).
10
+ */
11
+ import { resourceKeyID } from "../../health/resource-health/key.js";
12
+ import { CAPACITY_VERSION, MAX_CAPACITY_READINGS, } from "./types.js";
13
+ import { parseCapacityPayload } from "./parse.js";
14
+ export class CapacityReadingStore {
15
+ storage;
16
+ #readings = [];
17
+ constructor(storage) {
18
+ this.storage = storage;
19
+ }
20
+ /** Load the persisted mirror; unreadable or corrupt data is empty, not an error. */
21
+ async load() {
22
+ let raw;
23
+ try {
24
+ raw = await this.storage.read();
25
+ }
26
+ catch {
27
+ this.#readings = [];
28
+ return;
29
+ }
30
+ this.#readings = parseCapacityPayload(raw);
31
+ }
32
+ snapshot() {
33
+ return this.#readings;
34
+ }
35
+ /**
36
+ * Merge one refresh batch into the mirror and persist it. Merge — not
37
+ * replace — per resource key, with the newest `observedAt` winning: the TUI
38
+ * host loads this plugin into several supervisor instances, and an instance
39
+ * whose sensors have seen nothing must never clobber what the observing
40
+ * instance persisted. Bound by MAX_CAPACITY_READINGS, evicting the oldest
41
+ * observations first.
42
+ */
43
+ async replace(entries) {
44
+ const byKey = new Map();
45
+ for (const entry of this.#readings) {
46
+ byKey.set(resourceKeyID(entry.key), entry);
47
+ }
48
+ for (const entry of entries) {
49
+ const id = resourceKeyID(entry.key);
50
+ const previous = byKey.get(id);
51
+ if (previous === undefined || entry.reading.observedAt > previous.reading.observedAt) {
52
+ byKey.set(id, entry);
53
+ }
54
+ }
55
+ const merged = [...byKey.values()];
56
+ merged.sort((a, b) => b.reading.observedAt - a.reading.observedAt);
57
+ const next = merged.slice(0, MAX_CAPACITY_READINGS);
58
+ // Persist BEFORE committing memory: a write failure must leave memory and
59
+ // disk consistent (the caller decides how to fail open).
60
+ await this.storage.write({ version: CAPACITY_VERSION, readings: next });
61
+ this.#readings = next;
62
+ }
63
+ }
64
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/state/capacity/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAGtB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEjD,MAAM,OAAO,oBAAoB;IAGF;IAF7B,SAAS,GAA+B,EAAE,CAAA;IAE1C,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEzD,oFAAoF;IACpF,KAAK,CAAC,IAAI;QACR,IAAI,GAAY,CAAA;QAChB,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;QACjC,CAA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AAC,KAAK,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;QACvE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;IACvB,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Persisted capacity readings (ADP-020/ADP-031).
3
+ *
4
+ * The host's TUI-mode plugin reconciliation can load the plugin several times
5
+ * into one process: the session hooks (the event pump that observes capacity
6
+ * headers) and the RPC registration that serves status.get can land on
7
+ * DIFFERENT supervisor instances. The in-memory capacity registry lives only
8
+ * on the hook instance, so capacity would be invisible to the status-serving
9
+ * instance — the same trap that health records solve with their persisted
10
+ * mirror. Persisting readings lets every instance read what any instance
11
+ * observed, like receipts/settings/parked work.
12
+ */
13
+ import type { ResourceKey } from "../../health/resource-health/types.js";
14
+ import type { CapacityReading } from "../../health/capacity/types.js";
15
+ /** Storage key for the capacity mirror (bound by the adapter to ctx.storage). */
16
+ export declare const CAPACITY_KEY = "coool.adaptive/capacity";
17
+ export declare const CAPACITY_VERSION = 1;
18
+ /**
19
+ * Product bound — not a user knob. A capacity reading is only useful while it
20
+ * is fresh (readings older than the max age are treated as absent), so far
21
+ * fewer entries than the health bound suffice to cover every configured
22
+ * resource.
23
+ */
24
+ export declare const MAX_CAPACITY_READINGS = 64;
25
+ export interface PersistedCapacityReading {
26
+ readonly key: ResourceKey;
27
+ readonly reading: CapacityReading;
28
+ }
29
+ export interface CapacityPayload {
30
+ readonly version: typeof CAPACITY_VERSION;
31
+ readonly readings: readonly PersistedCapacityReading[];
32
+ }
33
+ /** Storage seam — the adapter binds `CAPACITY_KEY` to `ctx.storage`. */
34
+ export interface CapacityStorage {
35
+ read(): Promise<unknown>;
36
+ write(payload: CapacityPayload): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/state/capacity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAErE,iFAAiF;AACjF,eAAO,MAAM,YAAY,4BAA4B,CAAA;AAErD,eAAO,MAAM,gBAAgB,IAAI,CAAA;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAEvC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,gBAAgB,CAAA;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,wBAAwB,EAAE,CAAA;CACvD;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IACxB,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/C"}
@@ -0,0 +1,11 @@
1
+ /** Storage key for the capacity mirror (bound by the adapter to ctx.storage). */
2
+ export const CAPACITY_KEY = "coool.adaptive/capacity";
3
+ export const CAPACITY_VERSION = 1;
4
+ /**
5
+ * Product bound — not a user knob. A capacity reading is only useful while it
6
+ * is fresh (readings older than the max age are treated as absent), so far
7
+ * fewer entries than the health bound suffice to cover every configured
8
+ * resource.
9
+ */
10
+ export const MAX_CAPACITY_READINGS = 64;
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/state/capacity/types.ts"],"names":[],"mappings":"AAeA,iFAAiF;AACjF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAA;AAErD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { parseHealthPayload } from "./parse.js";
2
+ export { HealthRecordStore } from "./store.js";
3
+ export { HEALTH_KEY, HEALTH_VERSION, MAX_HEALTH_RECORDS } from "./types.js";
4
+ export type { HealthPayload, HealthStorage } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/state/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC3E,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { parseHealthPayload } from "./parse.js";
2
+ export { HealthRecordStore } from "./store.js";
3
+ export { HEALTH_KEY, HEALTH_VERSION, MAX_HEALTH_RECORDS } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/state/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ResourceRecord } from "../../health/resource-health/types.js";
2
+ export declare function parseHealthPayload(raw: unknown): ResourceRecord[];
3
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/state/health/parse.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,uCAAuC,CAAA;AA8F9C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,EAAE,CAWjE"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Read-side parsing for persisted health records. Every parser is total: it
3
+ * accepts `unknown` and returns typed records, dropping anything invalid — a
4
+ * corrupted health file can never take the plugin down (ADP-031). State and
5
+ * breaker vocabularies are membership-checked; timestamps must be finite
6
+ * numbers. An older plugin reading newer records may drop unknown-vocabulary
7
+ * entries — health records are bounded mirrors of an in-memory registry, and
8
+ * the payload version guards the schema itself.
9
+ */
10
+ import { BREAKER_STATES } from "../../health/circuit-breaker/types.js";
11
+ import { HEALTH_STATES } from "../../health/resource-health/types.js";
12
+ import { HEALTH_VERSION } from "./types.js";
13
+ function isRecord(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function isFiniteNumber(raw) {
17
+ return typeof raw === "number" && Number.isFinite(raw);
18
+ }
19
+ function isNonNegativeInt(raw) {
20
+ return isFiniteNumber(raw) && Number.isInteger(raw) && raw >= 0;
21
+ }
22
+ function parseVocab(raw, vocabulary) {
23
+ if (typeof raw !== "string")
24
+ return undefined;
25
+ return vocabulary.find((entry) => entry === raw);
26
+ }
27
+ /** A non-empty bounded identifier string (provider/model/variant/account ids). */
28
+ function parseIdentifier(raw) {
29
+ if (typeof raw !== "string")
30
+ return undefined;
31
+ const value = raw.length > 128 ? raw.slice(0, 128) : raw;
32
+ return value === "" ? undefined : value;
33
+ }
34
+ function parseKey(raw) {
35
+ if (!isRecord(raw))
36
+ return undefined;
37
+ const providerID = parseIdentifier(raw["providerID"]);
38
+ if (providerID === undefined)
39
+ return undefined;
40
+ const accountID = parseIdentifier(raw["accountID"]);
41
+ const modelID = parseIdentifier(raw["modelID"]);
42
+ const variantID = parseIdentifier(raw["variantID"]);
43
+ // Scope fields must form a valid prefix: a variant without a model, or a
44
+ // model without its variant's provider context, is not a real resource.
45
+ if (variantID !== undefined && modelID === undefined)
46
+ return undefined;
47
+ return {
48
+ providerID,
49
+ ...(accountID !== undefined ? { accountID } : {}),
50
+ ...(modelID !== undefined ? { modelID } : {}),
51
+ ...(variantID !== undefined ? { variantID } : {}),
52
+ };
53
+ }
54
+ function parseBreaker(raw) {
55
+ if (!isRecord(raw))
56
+ return undefined;
57
+ const state = parseVocab(raw["state"], BREAKER_STATES);
58
+ const failures = raw["failures"];
59
+ const openCount = raw["openCount"];
60
+ if (state === undefined)
61
+ return undefined;
62
+ if (!(isNonNegativeInt(failures) && isNonNegativeInt(openCount)))
63
+ return undefined;
64
+ const reopenAt = raw["reopenAt"];
65
+ const probeId = parseIdentifier(raw["probeId"]);
66
+ const probeAt = raw["probeAt"];
67
+ return {
68
+ state,
69
+ failures,
70
+ openCount,
71
+ ...(isFiniteNumber(reopenAt) ? { reopenAt } : {}),
72
+ ...(probeId !== undefined ? { probeId } : {}),
73
+ ...(isFiniteNumber(probeAt) ? { probeAt } : {}),
74
+ };
75
+ }
76
+ function parseWindow(raw) {
77
+ if (!isRecord(raw))
78
+ return undefined;
79
+ const kind = parseVocab(raw["kind"], ["rate-limit", "quota"]);
80
+ const until = raw["until"];
81
+ if (kind === undefined || !isFiniteNumber(until))
82
+ return undefined;
83
+ return { kind, until };
84
+ }
85
+ function parseRecord(raw) {
86
+ if (!isRecord(raw))
87
+ return undefined;
88
+ const key = parseKey(raw["key"]);
89
+ const health = parseVocab(raw["health"], HEALTH_STATES);
90
+ const breaker = parseBreaker(raw["breaker"]);
91
+ const updatedAt = raw["updatedAt"];
92
+ if (key === undefined || health === undefined || breaker === undefined)
93
+ return undefined;
94
+ if (!isFiniteNumber(updatedAt))
95
+ return undefined;
96
+ const window = parseWindow(raw["window"]);
97
+ return {
98
+ key,
99
+ health,
100
+ breaker,
101
+ ...(window !== undefined ? { window } : {}),
102
+ updatedAt,
103
+ };
104
+ }
105
+ export function parseHealthPayload(raw) {
106
+ if (!isRecord(raw))
107
+ return [];
108
+ if (raw["version"] !== HEALTH_VERSION)
109
+ return [];
110
+ const list = raw["records"];
111
+ if (!Array.isArray(list))
112
+ return [];
113
+ const parsed = [];
114
+ for (const entry of list.slice(0, 512)) {
115
+ const record = parseRecord(entry);
116
+ if (record !== undefined)
117
+ parsed.push(record);
118
+ }
119
+ return parsed;
120
+ }
121
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/state/health/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAA;AAMrE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACxD,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAY;IACpC,OAAO,cAAc,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;AACjE,CAAC;AAED,SAAS,UAAU,CACjB,GAAY,EACZ,UAAa;IAEb,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC,CAAA;AAClD,CAAC;AAED,kFAAkF;AAClF,SAAS,eAAe,CAAC,GAAY;IACnC,IAAI,OAAO,GAA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AK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IACnC,MAAM,MAAM,GAAqB,EAAE,CAAA;IACnC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { HealthStorage } from "./types.js";
2
+ import type { ResourceRecord } from "../../health/resource-health/types.js";
3
+ export declare class HealthRecordStore {
4
+ #private;
5
+ private readonly storage;
6
+ constructor(storage: HealthStorage);
7
+ /** Rebuild from storage (restart behavior). A read failure yields an empty store. */
8
+ load(): Promise<void>;
9
+ /** All retained records. */
10
+ snapshot(): readonly ResourceRecord[];
11
+ /**
12
+ * Replace the whole record set with a fresh registry snapshot. The bound
13
+ * keeps the most recently updated records — stale scopes matter less than
14
+ * the resources that are actually failing right now.
15
+ */
16
+ replace(records: readonly ResourceRecord[]): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/state/health/store.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAE3E,qBAAa,iBAAiB;;IAGhB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,aAAa;IAEnD,qFAAqF;IAC/E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,4BAA4B;IAC5B,QAAQ,IAAI,SAAS,cAAc,EAAE;IAIrC;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBjE"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Bounded health-record store: a persistence mirror of the in-memory
3
+ * resource-health registry. The store keeps the newest-updated records
4
+ * (bounded, least-recently-updated evicted) and persists on every replace.
5
+ * As everywhere else in `state/`, memory is only advanced after a successful
6
+ * write, so memory and disk never diverge; write failures propagate to the
7
+ * caller — the wiring layer's fail-open wrapper decides how to degrade
8
+ * (ADP-031).
9
+ */
10
+ import { parseHealthPayload } from "./parse.js";
11
+ import { MAX_HEALTH_RECORDS, HEALTH_VERSION } from "./types.js";
12
+ export class HealthRecordStore {
13
+ storage;
14
+ #records = [];
15
+ constructor(storage) {
16
+ this.storage = storage;
17
+ }
18
+ /** Rebuild from storage (restart behavior). A read failure yields an empty store. */
19
+ async load() {
20
+ let raw;
21
+ try {
22
+ raw = await this.storage.read();
23
+ }
24
+ catch {
25
+ this.#records = [];
26
+ return;
27
+ }
28
+ this.#records = parseHealthPayload(raw);
29
+ }
30
+ /** All retained records. */
31
+ snapshot() {
32
+ return this.#records;
33
+ }
34
+ /**
35
+ * Replace the whole record set with a fresh registry snapshot. The bound
36
+ * keeps the most recently updated records — stale scopes matter less than
37
+ * the resources that are actually failing right now.
38
+ */
39
+ async replace(records) {
40
+ const next = records.length > MAX_HEALTH_RECORDS
41
+ ? [...records]
42
+ .sort((left, right) => right.updatedAt - left.updatedAt)
43
+ .slice(0, MAX_HEALTH_RECORDS)
44
+ : [...records];
45
+ // Persist BEFORE committing memory: a write failure must leave memory
46
+ // and disk consistent (the caller decides how to fail open).
47
+ const payload = {
48
+ version: HEALTH_VERSION,
49
+ records: next,
50
+ };
51
+ await this.storage.write(payload);
52
+ this.#records = next;
53
+ }
54
+ }
55
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/state/health/store.ts"],"names":[],"mappings":"AAAA;;;;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C;CACF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Persisted resource health records. Health is otherwise memory-only state,
3
+ * but the host's TUI-mode plugin reconciliation can load the plugin several
4
+ * times into one process — hooks (the event pump) and RPC registration can
5
+ * end up on different instances. Without persistence the status surface is
6
+ * served by an instance whose registry never observed anything; persisted
7
+ * records make health readable by every instance, exactly like receipts,
8
+ * settings and parked work.
9
+ */
10
+ import type { ResourceRecord } from "../../health/resource-health/types.js";
11
+ export declare const HEALTH_KEY = "coool.adaptive/health";
12
+ export declare const HEALTH_VERSION = 1;
13
+ /** Product bound — not a user knob. Keeps the most recently updated records. */
14
+ export declare const MAX_HEALTH_RECORDS = 512;
15
+ export interface HealthPayload {
16
+ readonly version: typeof HEALTH_VERSION;
17
+ readonly records: readonly ResourceRecord[];
18
+ }
19
+ /** Storage seam — the adapter binds `HEALTH_KEY` to `ctx.storage`. */
20
+ export interface HealthStorage {
21
+ read(): Promise<unknown>;
22
+ write(payload: HealthPayload): Promise<void>;
23
+ }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/state/health/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAE3E,eAAO,MAAM,UAAU,0BAA0B,CAAA;AACjD,eAAO,MAAM,cAAc,IAAI,CAAA;AAC/B,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,cAAc,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAC5C;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IACxB,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7C"}
@@ -0,0 +1,5 @@
1
+ export const HEALTH_KEY = "coool.adaptive/health";
2
+ export const HEALTH_VERSION = 1;
3
+ /** Product bound — not a user knob. Keeps the most recently updated records. */
4
+ export const MAX_HEALTH_RECORDS = 512;
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/state/health/types.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAA;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAA;AAC/B,gFAAgF;AAChF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { parseParkedPayload } from "./parse.js";
2
+ export { ParkedWorkStore } from "./store.js";
3
+ export { MAX_PARKED, MAX_PARKED_TEXT, PARKED_KEY, PARKED_VERSION } from "./types.js";
4
+ export type { ParkedPayload, ParkedRecord, ParkedStorage } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/state/parked-work/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACpF,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { parseParkedPayload } from "./parse.js";
2
+ export { ParkedWorkStore } from "./store.js";
3
+ export { MAX_PARKED, MAX_PARKED_TEXT, PARKED_KEY, PARKED_VERSION } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/state/parked-work/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { ParkedRecord } from "./types.js";
2
+ /**
3
+ * Parse a persisted parked payload. Accepts the versioned shape and a
4
+ * versionless draft array; anything else yields no records.
5
+ */
6
+ export declare function parseParkedPayload(raw: unknown): ParkedRecord[];
7
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/state/parked-work/parse.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA2D9C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,EAAE,CAc/D"}