charness 3.11.0 → 3.13.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 (537) hide show
  1. package/.env.example +5 -0
  2. package/CHANGELOG.md +169 -0
  3. package/DEVELOPMENT.md +81 -18
  4. package/README.md +3 -2
  5. package/SETUP.md +71 -25
  6. package/agent-plugin/README.md +15 -6
  7. package/agent-plugin/skills/charness-delegate-claude/SKILL.md +37 -18
  8. package/agent-plugin/skills/charness-delegate-opencode/SKILL.md +10 -6
  9. package/agent-plugin/skills/charness-delivery-loop/SKILL.md +92 -0
  10. package/agent-plugin/skills/charness-orchestration/SKILL.md +116 -0
  11. package/dist/accessControl.d.ts +43 -0
  12. package/dist/accessControl.d.ts.map +1 -1
  13. package/dist/accessControl.js +50 -1
  14. package/dist/accessControl.js.map +1 -1
  15. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
  16. package/dist/adapters/claudeCliAdapter.js +9 -4
  17. package/dist/adapters/claudeCliAdapter.js.map +1 -1
  18. package/dist/adapters/claudeJsonStreamAdapter.js +1 -1
  19. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
  20. package/dist/adapters/claudePlatformFlags.d.ts +4 -3
  21. package/dist/adapters/claudePlatformFlags.d.ts.map +1 -1
  22. package/dist/adapters/claudePlatformFlags.js +4 -3
  23. package/dist/adapters/claudePlatformFlags.js.map +1 -1
  24. package/dist/adapters/openCodeAdapter.d.ts +52 -13
  25. package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
  26. package/dist/adapters/openCodeAdapter.js +121 -45
  27. package/dist/adapters/openCodeAdapter.js.map +1 -1
  28. package/dist/adapters/terminalAdapter.d.ts.map +1 -1
  29. package/dist/adapters/terminalAdapter.js +5 -3
  30. package/dist/adapters/terminalAdapter.js.map +1 -1
  31. package/dist/agentLogin/agentLogin.d.ts +11 -0
  32. package/dist/agentLogin/agentLogin.d.ts.map +1 -1
  33. package/dist/agentLogin/agentLogin.js +20 -20
  34. package/dist/agentLogin/agentLogin.js.map +1 -1
  35. package/dist/apiErrorRetry.d.ts +5 -0
  36. package/dist/apiErrorRetry.d.ts.map +1 -1
  37. package/dist/apiErrorRetry.js +3 -3
  38. package/dist/apiErrorRetry.js.map +1 -1
  39. package/dist/bot.d.ts +12 -3
  40. package/dist/bot.d.ts.map +1 -1
  41. package/dist/bot.js +634 -153
  42. package/dist/bot.js.map +1 -1
  43. package/dist/cli/claudeProfiles.d.ts +5 -2
  44. package/dist/cli/claudeProfiles.d.ts.map +1 -1
  45. package/dist/cli/claudeProfiles.js +45 -22
  46. package/dist/cli/claudeProfiles.js.map +1 -1
  47. package/dist/cli/claudeProfilesCredit.d.ts +49 -0
  48. package/dist/cli/claudeProfilesCredit.d.ts.map +1 -0
  49. package/dist/cli/claudeProfilesCredit.js +160 -0
  50. package/dist/cli/claudeProfilesCredit.js.map +1 -0
  51. package/dist/cli/flagValue.d.ts +10 -0
  52. package/dist/cli/flagValue.d.ts.map +1 -0
  53. package/dist/cli/flagValue.js +17 -0
  54. package/dist/cli/flagValue.js.map +1 -0
  55. package/dist/connectors/jira/client.js +1 -1
  56. package/dist/connectors/jira/client.js.map +1 -1
  57. package/dist/connectors/jira/config.d.ts +7 -0
  58. package/dist/connectors/jira/config.d.ts.map +1 -1
  59. package/dist/connectors/jira/config.js +12 -1
  60. package/dist/connectors/jira/config.js.map +1 -1
  61. package/dist/connectors/jira/connector.d.ts +7 -0
  62. package/dist/connectors/jira/connector.d.ts.map +1 -1
  63. package/dist/connectors/jira/connector.js +20 -3
  64. package/dist/connectors/jira/connector.js.map +1 -1
  65. package/dist/connectors/jira/inbound.d.ts.map +1 -1
  66. package/dist/connectors/jira/inbound.js +4 -3
  67. package/dist/connectors/jira/inbound.js.map +1 -1
  68. package/dist/connectors/jira/issueBlocks.d.ts +1 -1
  69. package/dist/connectors/jira/trustedGroup.d.ts +21 -6
  70. package/dist/connectors/jira/trustedGroup.d.ts.map +1 -1
  71. package/dist/connectors/jira/trustedGroup.js +46 -6
  72. package/dist/connectors/jira/trustedGroup.js.map +1 -1
  73. package/dist/connectors/telegram/commands/botCore.d.ts +19 -2
  74. package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
  75. package/dist/connectors/telegram/commands/botSkills.js +1 -1
  76. package/dist/connectors/telegram/commands/claudeAccounts.d.ts +6 -1
  77. package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
  78. package/dist/connectors/telegram/commands/claudeAccounts.js +9 -6
  79. package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
  80. package/dist/connectors/telegram/commands/compaction.d.ts +16 -3
  81. package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -1
  82. package/dist/connectors/telegram/commands/compaction.js +216 -27
  83. package/dist/connectors/telegram/commands/compaction.js.map +1 -1
  84. package/dist/connectors/telegram/commands/runners.d.ts +5 -1
  85. package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
  86. package/dist/connectors/telegram/commands/runners.js +146 -31
  87. package/dist/connectors/telegram/commands/runners.js.map +1 -1
  88. package/dist/connectors/telegram/commands/todo.d.ts.map +1 -1
  89. package/dist/connectors/telegram/commands/todo.js +2 -2
  90. package/dist/connectors/telegram/commands/todo.js.map +1 -1
  91. package/dist/connectors/telegram/commands/topicAccess.d.ts +30 -0
  92. package/dist/connectors/telegram/commands/topicAccess.d.ts.map +1 -0
  93. package/dist/connectors/telegram/commands/topicAccess.js +399 -0
  94. package/dist/connectors/telegram/commands/topicAccess.js.map +1 -0
  95. package/dist/connectors/telegram/inbound.d.ts +44 -7
  96. package/dist/connectors/telegram/inbound.d.ts.map +1 -1
  97. package/dist/connectors/telegram/inbound.js +142 -24
  98. package/dist/connectors/telegram/inbound.js.map +1 -1
  99. package/dist/connectors/telegram/runnerPairingMessages.d.ts +2 -7
  100. package/dist/connectors/telegram/runnerPairingMessages.d.ts.map +1 -1
  101. package/dist/connectors/telegram/runnerPairingMessages.js +5 -19
  102. package/dist/connectors/telegram/runnerPairingMessages.js.map +1 -1
  103. package/dist/i18n/de.d.ts.map +1 -1
  104. package/dist/i18n/de.js +120 -8
  105. package/dist/i18n/de.js.map +1 -1
  106. package/dist/i18n/en.d.ts.map +1 -1
  107. package/dist/i18n/en.js +120 -8
  108. package/dist/i18n/en.js.map +1 -1
  109. package/dist/i18n/es.d.ts.map +1 -1
  110. package/dist/i18n/es.js +120 -8
  111. package/dist/i18n/es.js.map +1 -1
  112. package/dist/i18n/fr.d.ts.map +1 -1
  113. package/dist/i18n/fr.js +120 -8
  114. package/dist/i18n/fr.js.map +1 -1
  115. package/dist/i18n/hi.d.ts.map +1 -1
  116. package/dist/i18n/hi.js +120 -8
  117. package/dist/i18n/hi.js.map +1 -1
  118. package/dist/i18n/ja.d.ts.map +1 -1
  119. package/dist/i18n/ja.js +120 -8
  120. package/dist/i18n/ja.js.map +1 -1
  121. package/dist/i18n/ka.d.ts.map +1 -1
  122. package/dist/i18n/ka.js +120 -8
  123. package/dist/i18n/ka.js.map +1 -1
  124. package/dist/i18n/pt.d.ts.map +1 -1
  125. package/dist/i18n/pt.js +120 -8
  126. package/dist/i18n/pt.js.map +1 -1
  127. package/dist/i18n/ru.d.ts.map +1 -1
  128. package/dist/i18n/ru.js +120 -8
  129. package/dist/i18n/ru.js.map +1 -1
  130. package/dist/i18n/uk.d.ts.map +1 -1
  131. package/dist/i18n/uk.js +120 -8
  132. package/dist/i18n/uk.js.map +1 -1
  133. package/dist/i18n/uz.d.ts.map +1 -1
  134. package/dist/i18n/uz.js +120 -8
  135. package/dist/i18n/uz.js.map +1 -1
  136. package/dist/i18n/zh.d.ts.map +1 -1
  137. package/dist/i18n/zh.js +120 -8
  138. package/dist/i18n/zh.js.map +1 -1
  139. package/dist/installManager.d.ts +37 -1
  140. package/dist/installManager.d.ts.map +1 -1
  141. package/dist/installManager.js +208 -14
  142. package/dist/installManager.js.map +1 -1
  143. package/dist/instanceLock.d.ts.map +1 -1
  144. package/dist/instanceLock.js +2 -1
  145. package/dist/instanceLock.js.map +1 -1
  146. package/dist/platform/commandRouter.d.ts +13 -1
  147. package/dist/platform/commandRouter.d.ts.map +1 -1
  148. package/dist/platform/commandRouter.js +14 -2
  149. package/dist/platform/commandRouter.js.map +1 -1
  150. package/dist/platform/inbound.d.ts +2 -0
  151. package/dist/platform/inbound.d.ts.map +1 -1
  152. package/dist/platform/outbound.d.ts +14 -1
  153. package/dist/platform/outbound.d.ts.map +1 -1
  154. package/dist/platform/outbound.js.map +1 -1
  155. package/dist/remoteRun/cleanReport.d.ts +45 -0
  156. package/dist/remoteRun/cleanReport.d.ts.map +1 -0
  157. package/dist/remoteRun/cleanReport.js +84 -0
  158. package/dist/remoteRun/cleanReport.js.map +1 -0
  159. package/dist/remoteRun/cliArgs.d.ts +18 -0
  160. package/dist/remoteRun/cliArgs.d.ts.map +1 -1
  161. package/dist/remoteRun/cliArgs.js +100 -4
  162. package/dist/remoteRun/cliArgs.js.map +1 -1
  163. package/dist/remoteRun/commands.d.ts +30 -1
  164. package/dist/remoteRun/commands.d.ts.map +1 -1
  165. package/dist/remoteRun/commands.js +84 -9
  166. package/dist/remoteRun/commands.js.map +1 -1
  167. package/dist/remoteRun/exitCodes.d.ts +5 -0
  168. package/dist/remoteRun/exitCodes.d.ts.map +1 -1
  169. package/dist/remoteRun/exitCodes.js +6 -1
  170. package/dist/remoteRun/exitCodes.js.map +1 -1
  171. package/dist/remoteRun/foreground.d.ts +6 -0
  172. package/dist/remoteRun/foreground.d.ts.map +1 -1
  173. package/dist/remoteRun/foreground.js +13 -1
  174. package/dist/remoteRun/foreground.js.map +1 -1
  175. package/dist/remoteRun/interrupts.d.ts.map +1 -1
  176. package/dist/remoteRun/interrupts.js +2 -2
  177. package/dist/remoteRun/interrupts.js.map +1 -1
  178. package/dist/remoteRun/jobFiles.d.ts +6 -1
  179. package/dist/remoteRun/jobFiles.d.ts.map +1 -1
  180. package/dist/remoteRun/jobFiles.js +14 -0
  181. package/dist/remoteRun/jobFiles.js.map +1 -1
  182. package/dist/remoteRun/jobId.d.ts +5 -0
  183. package/dist/remoteRun/jobId.d.ts.map +1 -1
  184. package/dist/remoteRun/jobId.js +10 -0
  185. package/dist/remoteRun/jobId.js.map +1 -1
  186. package/dist/remoteRun/jobState.d.ts.map +1 -1
  187. package/dist/remoteRun/jobState.js +3 -2
  188. package/dist/remoteRun/jobState.js.map +1 -1
  189. package/dist/remoteRun/pairedRunners.d.ts +1 -1
  190. package/dist/remoteRun/pairedRunners.d.ts.map +1 -1
  191. package/dist/remoteRun/pairedRunners.js +4 -0
  192. package/dist/remoteRun/pairedRunners.js.map +1 -1
  193. package/dist/remoteRun/pathPatterns.d.ts +1 -1
  194. package/dist/remoteRun/pathPatterns.js +1 -1
  195. package/dist/remoteRun/probe.d.ts +58 -5
  196. package/dist/remoteRun/probe.d.ts.map +1 -1
  197. package/dist/remoteRun/probe.js +107 -11
  198. package/dist/remoteRun/probe.js.map +1 -1
  199. package/dist/remoteRun/probeTiming.d.ts +15 -0
  200. package/dist/remoteRun/probeTiming.d.ts.map +1 -0
  201. package/dist/remoteRun/probeTiming.js +23 -0
  202. package/dist/remoteRun/probeTiming.js.map +1 -0
  203. package/dist/remoteRun/project.d.ts +5 -0
  204. package/dist/remoteRun/project.d.ts.map +1 -1
  205. package/dist/remoteRun/project.js +10 -0
  206. package/dist/remoteRun/project.js.map +1 -1
  207. package/dist/remoteRun/projectConfig.d.ts +8 -1
  208. package/dist/remoteRun/projectConfig.d.ts.map +1 -1
  209. package/dist/remoteRun/projectConfig.js +18 -5
  210. package/dist/remoteRun/projectConfig.js.map +1 -1
  211. package/dist/remoteRun/pruneReport.d.ts +48 -0
  212. package/dist/remoteRun/pruneReport.d.ts.map +1 -0
  213. package/dist/remoteRun/pruneReport.js +80 -0
  214. package/dist/remoteRun/pruneReport.js.map +1 -0
  215. package/dist/remoteRun/remoteRunCli.d.ts +1 -1
  216. package/dist/remoteRun/remoteRunCli.d.ts.map +1 -1
  217. package/dist/remoteRun/remoteRunCli.js +20 -0
  218. package/dist/remoteRun/remoteRunCli.js.map +1 -1
  219. package/dist/remoteRun/runnerClient.d.ts +10 -0
  220. package/dist/remoteRun/runnerClient.d.ts.map +1 -1
  221. package/dist/remoteRun/runnerClient.js +19 -5
  222. package/dist/remoteRun/runnerClient.js.map +1 -1
  223. package/dist/remoteRun/runnerWait.d.ts.map +1 -1
  224. package/dist/remoteRun/runnerWait.js +2 -1
  225. package/dist/remoteRun/runnerWait.js.map +1 -1
  226. package/dist/remoteRun/runners.d.ts +48 -7
  227. package/dist/remoteRun/runners.d.ts.map +1 -1
  228. package/dist/remoteRun/runners.js +105 -40
  229. package/dist/remoteRun/runners.js.map +1 -1
  230. package/dist/remoteRun/runnersConfig.d.ts +24 -0
  231. package/dist/remoteRun/runnersConfig.d.ts.map +1 -1
  232. package/dist/remoteRun/runnersConfig.js +29 -2
  233. package/dist/remoteRun/runnersConfig.js.map +1 -1
  234. package/dist/remoteRun/ssh.d.ts +3 -3
  235. package/dist/remoteRun/ssh.d.ts.map +1 -1
  236. package/dist/remoteRun/ssh.js +19 -5
  237. package/dist/remoteRun/ssh.js.map +1 -1
  238. package/dist/remoteRun/submit.d.ts +1 -1
  239. package/dist/remoteRun/submit.d.ts.map +1 -1
  240. package/dist/remoteRun/submit.js +30 -2
  241. package/dist/remoteRun/submit.js.map +1 -1
  242. package/dist/runnerUtility/adminService.d.ts.map +1 -1
  243. package/dist/runnerUtility/adminService.js +5 -5
  244. package/dist/runnerUtility/adminService.js.map +1 -1
  245. package/dist/runnerUtility/appInstall.d.ts +9 -0
  246. package/dist/runnerUtility/appInstall.d.ts.map +1 -1
  247. package/dist/runnerUtility/appInstall.js +12 -2
  248. package/dist/runnerUtility/appInstall.js.map +1 -1
  249. package/dist/runnerUtility/execEnv.d.ts +1 -1
  250. package/dist/runnerUtility/execEnv.d.ts.map +1 -1
  251. package/dist/runnerUtility/execEnv.js +23 -5
  252. package/dist/runnerUtility/execEnv.js.map +1 -1
  253. package/dist/runnerUtility/guiAgentHeal.d.ts +3 -3
  254. package/dist/runnerUtility/guiAgentHeal.d.ts.map +1 -1
  255. package/dist/runnerUtility/guiAgentHeal.js +4 -2
  256. package/dist/runnerUtility/guiAgentHeal.js.map +1 -1
  257. package/dist/runnerUtility/homeFolders.d.ts +1 -0
  258. package/dist/runnerUtility/homeFolders.d.ts.map +1 -1
  259. package/dist/runnerUtility/homeFolders.js +2 -1
  260. package/dist/runnerUtility/homeFolders.js.map +1 -1
  261. package/dist/runnerUtility/iosCheck.d.ts +2 -0
  262. package/dist/runnerUtility/iosCheck.d.ts.map +1 -1
  263. package/dist/runnerUtility/iosCheck.js +12 -3
  264. package/dist/runnerUtility/iosCheck.js.map +1 -1
  265. package/dist/runnerUtility/keepAwake.d.ts +47 -10
  266. package/dist/runnerUtility/keepAwake.d.ts.map +1 -1
  267. package/dist/runnerUtility/keepAwake.js +108 -31
  268. package/dist/runnerUtility/keepAwake.js.map +1 -1
  269. package/dist/runnerUtility/launcher.d.ts +4 -0
  270. package/dist/runnerUtility/launcher.d.ts.map +1 -1
  271. package/dist/runnerUtility/launcher.js +31 -13
  272. package/dist/runnerUtility/launcher.js.map +1 -1
  273. package/dist/runnerUtility/linkLoop.d.ts +4 -0
  274. package/dist/runnerUtility/linkLoop.d.ts.map +1 -1
  275. package/dist/runnerUtility/linkLoop.js +15 -6
  276. package/dist/runnerUtility/linkLoop.js.map +1 -1
  277. package/dist/runnerUtility/managedNode.d.ts +84 -0
  278. package/dist/runnerUtility/managedNode.d.ts.map +1 -0
  279. package/dist/runnerUtility/managedNode.js +165 -0
  280. package/dist/runnerUtility/managedNode.js.map +1 -0
  281. package/dist/runnerUtility/nodeOnPath.d.ts +10 -0
  282. package/dist/runnerUtility/nodeOnPath.d.ts.map +1 -0
  283. package/dist/runnerUtility/nodeOnPath.js +49 -0
  284. package/dist/runnerUtility/nodeOnPath.js.map +1 -0
  285. package/dist/runnerUtility/nodeUpkeep.d.ts +140 -0
  286. package/dist/runnerUtility/nodeUpkeep.d.ts.map +1 -0
  287. package/dist/runnerUtility/nodeUpkeep.js +348 -0
  288. package/dist/runnerUtility/nodeUpkeep.js.map +1 -0
  289. package/dist/runnerUtility/nodeUpkeepTiming.d.ts +14 -0
  290. package/dist/runnerUtility/nodeUpkeepTiming.d.ts.map +1 -0
  291. package/dist/runnerUtility/nodeUpkeepTiming.js +21 -0
  292. package/dist/runnerUtility/nodeUpkeepTiming.js.map +1 -0
  293. package/dist/runnerUtility/packageManagerShims.d.ts +10 -0
  294. package/dist/runnerUtility/packageManagerShims.d.ts.map +1 -1
  295. package/dist/runnerUtility/packageManagerShims.js +67 -3
  296. package/dist/runnerUtility/packageManagerShims.js.map +1 -1
  297. package/dist/runnerUtility/pueueDaemon.d.ts +73 -8
  298. package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
  299. package/dist/runnerUtility/pueueDaemon.js +90 -15
  300. package/dist/runnerUtility/pueueDaemon.js.map +1 -1
  301. package/dist/runnerUtility/runnerCommands.d.ts +7 -1
  302. package/dist/runnerUtility/runnerCommands.d.ts.map +1 -1
  303. package/dist/runnerUtility/runnerCommands.js +119 -16
  304. package/dist/runnerUtility/runnerCommands.js.map +1 -1
  305. package/dist/runnerUtility/runnerHome.d.ts +34 -0
  306. package/dist/runnerUtility/runnerHome.d.ts.map +1 -1
  307. package/dist/runnerUtility/runnerHome.js +17 -3
  308. package/dist/runnerUtility/runnerHome.js.map +1 -1
  309. package/dist/runnerUtility/serviceCommon.d.ts +2 -0
  310. package/dist/runnerUtility/serviceCommon.d.ts.map +1 -1
  311. package/dist/runnerUtility/serviceCommon.js +3 -1
  312. package/dist/runnerUtility/serviceCommon.js.map +1 -1
  313. package/dist/runnerUtility/serviceManager.d.ts.map +1 -1
  314. package/dist/runnerUtility/serviceManager.js +7 -2
  315. package/dist/runnerUtility/serviceManager.js.map +1 -1
  316. package/dist/runnerUtility/simctlGuard.d.ts +38 -0
  317. package/dist/runnerUtility/simctlGuard.d.ts.map +1 -0
  318. package/dist/runnerUtility/simctlGuard.js +166 -0
  319. package/dist/runnerUtility/simctlGuard.js.map +1 -0
  320. package/dist/runners/bootstrapLine.d.ts +3 -4
  321. package/dist/runners/bootstrapLine.d.ts.map +1 -1
  322. package/dist/runners/bootstrapLine.js +108 -83
  323. package/dist/runners/bootstrapLine.js.map +1 -1
  324. package/dist/runners/hubPackage.d.ts +1 -1
  325. package/dist/runners/hubPackage.d.ts.map +1 -1
  326. package/dist/runners/hubPackage.js +5 -6
  327. package/dist/runners/hubPackage.js.map +1 -1
  328. package/dist/runners/hubPairing.d.ts +19 -0
  329. package/dist/runners/hubPairing.d.ts.map +1 -1
  330. package/dist/runners/hubPairing.js +38 -0
  331. package/dist/runners/hubPairing.js.map +1 -1
  332. package/dist/runners/hubRegistry.d.ts +8 -0
  333. package/dist/runners/hubRegistry.d.ts.map +1 -1
  334. package/dist/runners/hubRegistry.js +6 -0
  335. package/dist/runners/hubRegistry.js.map +1 -1
  336. package/dist/runners/pairCode.d.ts +34 -3
  337. package/dist/runners/pairCode.d.ts.map +1 -1
  338. package/dist/runners/pairCode.js +65 -13
  339. package/dist/runners/pairCode.js.map +1 -1
  340. package/dist/runners/runnerGroups.d.ts +22 -0
  341. package/dist/runners/runnerGroups.d.ts.map +1 -0
  342. package/dist/runners/runnerGroups.js +41 -0
  343. package/dist/runners/runnerGroups.js.map +1 -0
  344. package/dist/runners/runnerLock.d.ts +36 -1
  345. package/dist/runners/runnerLock.d.ts.map +1 -1
  346. package/dist/runners/runnerLock.js +94 -30
  347. package/dist/runners/runnerLock.js.map +1 -1
  348. package/dist/runners/runnersCli.d.ts +5 -2
  349. package/dist/runners/runnersCli.d.ts.map +1 -1
  350. package/dist/runners/runnersCli.js +59 -9
  351. package/dist/runners/runnersCli.js.map +1 -1
  352. package/dist/runners/runnersList.d.ts +1 -1
  353. package/dist/runners/runnersList.d.ts.map +1 -1
  354. package/dist/runners/runnersList.js +3 -1
  355. package/dist/runners/runnersList.js.map +1 -1
  356. package/dist/runners/runnersOverview.d.ts.map +1 -1
  357. package/dist/runners/runnersOverview.js +8 -4
  358. package/dist/runners/runnersOverview.js.map +1 -1
  359. package/dist/scheduler/checkRun.d.ts +0 -2
  360. package/dist/scheduler/checkRun.d.ts.map +1 -1
  361. package/dist/scheduler/checkRun.js +0 -10
  362. package/dist/scheduler/checkRun.js.map +1 -1
  363. package/dist/scheduler/checkStatus.d.ts +2 -0
  364. package/dist/scheduler/checkStatus.d.ts.map +1 -1
  365. package/dist/scheduler/checkStatus.js +5 -4
  366. package/dist/scheduler/checkStatus.js.map +1 -1
  367. package/dist/scheduler/delivery.d.ts +2 -1
  368. package/dist/scheduler/delivery.d.ts.map +1 -1
  369. package/dist/scheduler/delivery.js +5 -1
  370. package/dist/scheduler/delivery.js.map +1 -1
  371. package/dist/scheduler/mcpSurface.d.ts +7 -3
  372. package/dist/scheduler/mcpSurface.d.ts.map +1 -1
  373. package/dist/scheduler/mcpSurface.js +48 -22
  374. package/dist/scheduler/mcpSurface.js.map +1 -1
  375. package/dist/scheduler/workerWatch.d.ts +33 -10
  376. package/dist/scheduler/workerWatch.d.ts.map +1 -1
  377. package/dist/scheduler/workerWatch.js +37 -11
  378. package/dist/scheduler/workerWatch.js.map +1 -1
  379. package/dist/selfUpdate/bootRollback.d.ts.map +1 -1
  380. package/dist/selfUpdate/bootRollback.js +3 -2
  381. package/dist/selfUpdate/bootRollback.js.map +1 -1
  382. package/dist/selfUpdate/updateRuntime.d.ts.map +1 -1
  383. package/dist/selfUpdate/updateRuntime.js +6 -3
  384. package/dist/selfUpdate/updateRuntime.js.map +1 -1
  385. package/dist/state.d.ts +144 -2
  386. package/dist/state.d.ts.map +1 -1
  387. package/dist/state.js +257 -7
  388. package/dist/state.js.map +1 -1
  389. package/dist/testTimings.d.ts +6 -2
  390. package/dist/testTimings.d.ts.map +1 -1
  391. package/dist/testTimings.js +12 -1
  392. package/dist/testTimings.js.map +1 -1
  393. package/dist/threadContextPreamble.d.ts +15 -1
  394. package/dist/threadContextPreamble.d.ts.map +1 -1
  395. package/dist/threadContextPreamble.js +15 -3
  396. package/dist/threadContextPreamble.js.map +1 -1
  397. package/dist/threadRouting.d.ts +47 -4
  398. package/dist/threadRouting.d.ts.map +1 -1
  399. package/dist/threadRouting.js +31 -4
  400. package/dist/threadRouting.js.map +1 -1
  401. package/dist/todos/projects.d.ts +1 -1
  402. package/dist/todos/projects.d.ts.map +1 -1
  403. package/dist/todos/projects.js +3 -14
  404. package/dist/todos/projects.js.map +1 -1
  405. package/dist/topicTalkerMemory.d.ts +37 -0
  406. package/dist/topicTalkerMemory.d.ts.map +1 -0
  407. package/dist/topicTalkerMemory.js +61 -0
  408. package/dist/topicTalkerMemory.js.map +1 -0
  409. package/dist/topicTalkers.d.ts +123 -0
  410. package/dist/topicTalkers.d.ts.map +1 -0
  411. package/dist/topicTalkers.js +276 -0
  412. package/dist/topicTalkers.js.map +1 -0
  413. package/dist/types.d.ts +7 -5
  414. package/dist/types.d.ts.map +1 -1
  415. package/dist/utils/agentEnvironment.d.ts +23 -0
  416. package/dist/utils/agentEnvironment.d.ts.map +1 -1
  417. package/dist/utils/agentEnvironment.js +33 -1
  418. package/dist/utils/agentEnvironment.js.map +1 -1
  419. package/dist/utils/agentPlugin.d.ts +9 -3
  420. package/dist/utils/agentPlugin.d.ts.map +1 -1
  421. package/dist/utils/agentPlugin.js +13 -6
  422. package/dist/utils/agentPlugin.js.map +1 -1
  423. package/dist/utils/authorMark.d.ts +59 -0
  424. package/dist/utils/authorMark.d.ts.map +1 -0
  425. package/dist/utils/authorMark.js +86 -0
  426. package/dist/utils/authorMark.js.map +1 -0
  427. package/dist/utils/botSkills.d.ts +1 -1
  428. package/dist/utils/claudeApiAgentStop.d.ts +64 -0
  429. package/dist/utils/claudeApiAgentStop.d.ts.map +1 -0
  430. package/dist/utils/claudeApiAgentStop.js +85 -0
  431. package/dist/utils/claudeApiAgentStop.js.map +1 -0
  432. package/dist/utils/claudeApiCredit.d.ts +168 -0
  433. package/dist/utils/claudeApiCredit.d.ts.map +1 -0
  434. package/dist/utils/claudeApiCredit.js +260 -0
  435. package/dist/utils/claudeApiCredit.js.map +1 -0
  436. package/dist/utils/claudeApiCreditRecheck.d.ts +120 -0
  437. package/dist/utils/claudeApiCreditRecheck.d.ts.map +1 -0
  438. package/dist/utils/claudeApiCreditRecheck.js +173 -0
  439. package/dist/utils/claudeApiCreditRecheck.js.map +1 -0
  440. package/dist/utils/claudeCompactHook.d.ts +18 -10
  441. package/dist/utils/claudeCompactHook.d.ts.map +1 -1
  442. package/dist/utils/claudeCompactHook.js +35 -14
  443. package/dist/utils/claudeCompactHook.js.map +1 -1
  444. package/dist/utils/claudeLimitSwitch.d.ts +5 -1
  445. package/dist/utils/claudeLimitSwitch.d.ts.map +1 -1
  446. package/dist/utils/claudeLimitSwitch.js +6 -2
  447. package/dist/utils/claudeLimitSwitch.js.map +1 -1
  448. package/dist/utils/claudeProfileUsageLines.d.ts +14 -2
  449. package/dist/utils/claudeProfileUsageLines.d.ts.map +1 -1
  450. package/dist/utils/claudeProfileUsageLines.js +78 -7
  451. package/dist/utils/claudeProfileUsageLines.js.map +1 -1
  452. package/dist/utils/claudeProfileUsageViews.d.ts +46 -0
  453. package/dist/utils/claudeProfileUsageViews.d.ts.map +1 -0
  454. package/dist/utils/claudeProfileUsageViews.js +114 -0
  455. package/dist/utils/claudeProfileUsageViews.js.map +1 -0
  456. package/dist/utils/claudeProfiles.d.ts +22 -0
  457. package/dist/utils/claudeProfiles.d.ts.map +1 -1
  458. package/dist/utils/claudeProfiles.js +69 -0
  459. package/dist/utils/claudeProfiles.js.map +1 -1
  460. package/dist/utils/claudeUsage.d.ts +145 -51
  461. package/dist/utils/claudeUsage.d.ts.map +1 -1
  462. package/dist/utils/claudeUsage.js +211 -94
  463. package/dist/utils/claudeUsage.js.map +1 -1
  464. package/dist/utils/compactOnIdle.d.ts +140 -15
  465. package/dist/utils/compactOnIdle.d.ts.map +1 -1
  466. package/dist/utils/compactOnIdle.js +209 -23
  467. package/dist/utils/compactOnIdle.js.map +1 -1
  468. package/dist/utils/compactSelfReviewFlags.d.ts +50 -0
  469. package/dist/utils/compactSelfReviewFlags.d.ts.map +1 -0
  470. package/dist/utils/compactSelfReviewFlags.js +120 -0
  471. package/dist/utils/compactSelfReviewFlags.js.map +1 -0
  472. package/dist/utils/fallbackChain.d.ts +18 -7
  473. package/dist/utils/fallbackChain.d.ts.map +1 -1
  474. package/dist/utils/fallbackChain.js +36 -16
  475. package/dist/utils/fallbackChain.js.map +1 -1
  476. package/dist/utils/folderGit.d.ts +9 -0
  477. package/dist/utils/folderGit.d.ts.map +1 -0
  478. package/dist/utils/folderGit.js +33 -0
  479. package/dist/utils/folderGit.js.map +1 -0
  480. package/dist/utils/forwardedMark.d.ts +8 -0
  481. package/dist/utils/forwardedMark.d.ts.map +1 -1
  482. package/dist/utils/forwardedMark.js +2 -0
  483. package/dist/utils/forwardedMark.js.map +1 -1
  484. package/dist/utils/jsonStreamHost.d.ts +2 -1
  485. package/dist/utils/jsonStreamHost.d.ts.map +1 -1
  486. package/dist/utils/jsonStreamHost.js +4 -2
  487. package/dist/utils/jsonStreamHost.js.map +1 -1
  488. package/dist/utils/messageContext.d.ts +22 -7
  489. package/dist/utils/messageContext.d.ts.map +1 -1
  490. package/dist/utils/messageContext.js +19 -5
  491. package/dist/utils/messageContext.js.map +1 -1
  492. package/dist/utils/openCodeCompactPlugin.d.ts +28 -7
  493. package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
  494. package/dist/utils/openCodeCompactPlugin.js +80 -15
  495. package/dist/utils/openCodeCompactPlugin.js.map +1 -1
  496. package/dist/utils/personLabel.d.ts +13 -0
  497. package/dist/utils/personLabel.d.ts.map +1 -0
  498. package/dist/utils/personLabel.js +15 -0
  499. package/dist/utils/personLabel.js.map +1 -0
  500. package/dist/utils/replyQuote.d.ts +17 -3
  501. package/dist/utils/replyQuote.d.ts.map +1 -1
  502. package/dist/utils/replyQuote.js +25 -2
  503. package/dist/utils/replyQuote.js.map +1 -1
  504. package/dist/utils/runnersScreenPlan.d.ts +51 -20
  505. package/dist/utils/runnersScreenPlan.d.ts.map +1 -1
  506. package/dist/utils/runnersScreenPlan.js +143 -28
  507. package/dist/utils/runnersScreenPlan.js.map +1 -1
  508. package/dist/utils/streamedCompactionSummary.d.ts +65 -0
  509. package/dist/utils/streamedCompactionSummary.d.ts.map +1 -0
  510. package/dist/utils/streamedCompactionSummary.js +108 -0
  511. package/dist/utils/streamedCompactionSummary.js.map +1 -0
  512. package/dist/utils/talkerAccess.d.ts +9 -0
  513. package/dist/utils/talkerAccess.d.ts.map +1 -0
  514. package/dist/utils/talkerAccess.js +20 -0
  515. package/dist/utils/talkerAccess.js.map +1 -0
  516. package/dist/utils/tmuxExec.d.ts +20 -8
  517. package/dist/utils/tmuxExec.d.ts.map +1 -1
  518. package/dist/utils/tmuxExec.js +27 -7
  519. package/dist/utils/tmuxExec.js.map +1 -1
  520. package/dist/utils/topicAccessScreenPlan.d.ts +253 -0
  521. package/dist/utils/topicAccessScreenPlan.d.ts.map +1 -0
  522. package/dist/utils/topicAccessScreenPlan.js +287 -0
  523. package/dist/utils/topicAccessScreenPlan.js.map +1 -0
  524. package/dist/utils/topicLabel.d.ts +12 -0
  525. package/dist/utils/topicLabel.d.ts.map +1 -0
  526. package/dist/utils/topicLabel.js +12 -0
  527. package/dist/utils/topicLabel.js.map +1 -0
  528. package/dist/utils/topicRequest.d.ts +8 -5
  529. package/dist/utils/topicRequest.d.ts.map +1 -1
  530. package/dist/utils/topicRequest.js +9 -7
  531. package/dist/utils/topicRequest.js.map +1 -1
  532. package/npm-shrinkwrap.json +1003 -0
  533. package/package.json +5 -3
  534. package/remoteRun/ensureNode.sh +288 -0
  535. package/remoteRun/runner.sh +2252 -115
  536. package/agent-plugin/skills/charness-manager/SKILL.md +0 -157
  537. package/remoteRun/pickNode.sh +0 -65
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  /**
3
3
  * @description Per-profile Claude USAGE — how much of each subscription window an account profile
4
- * (`utils/claudeProfiles.ts`) has used, and which profile a process should run on: a NEW agent goes to the
5
- * account whose weekly window resets soonest (spend first what burns soonest), a WARM session stays on the
4
+ * (`utils/claudeProfiles.ts`) has used, and which profile a process should run on: only the accounts the operator's
5
+ * `/limits` list holds (when it holds any Claude account); a NEW agent goes to an API-credit account of the list first, then
6
+ * to the subscription whose weekly window resets soonest (spend first what burns soonest), a WARM session stays on the
6
7
  * account it worked on ({@link getClaudeLaunchPick}).
7
8
  *
8
9
  * Two sources feed one snapshot per profile (`ClaudeProfileRecord.usage`):
@@ -15,7 +16,12 @@
15
16
  * — the last one IS the Fable window: same utilization and reset instant as the endpoint's scoped limit).
16
17
  *
17
18
  * Token refresh is the CLI's job: a token past its `expiresAt` is never used (nor refreshed here) — the
18
- * snapshot is marked stale and the next CLI run renews it. The token itself is never logged or returned.
19
+ * snapshot is marked stale and the next CLI run renews it (every poll re-reads the token file, so the poll after that run
20
+ * recovers by itself). An account no CLI runs on keeps that stale snapshot for as long as it sits idle, so every reader reads
21
+ * the used percent of a bucket AGAINST THE CLOCK ({@link getClaudeUsagePercentAsOf}): a window whose reset has passed is over,
22
+ * whatever was read. What the account has used since — through a login on another machine or another host user — is invisible
23
+ * here (nothing can be polled without a live token), and a screen shows no reset for the next period: nothing says when it ends.
24
+ * The token itself is never logged or returned.
19
25
  *
20
26
  * Pure except {@link readClaudeOAuthToken} (one file read) and {@link fetchClaudeUsage} (one GET through an
21
27
  * injectable `fetch`), so the rest is unit-tested without the network.
@@ -54,7 +60,7 @@ var __importStar = (this && this.__importStar) || (function () {
54
60
  };
55
61
  })();
56
62
  Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.englishRelativeResetWords = exports.claudeSessionWindowMs = exports.claudeWeeklyWindowMs = exports.claudeLaunchResetTieMs = exports.claudeLaunchSessionCeilingPercent = exports.claudeUsageBucketKinds = exports.claudeUsageFetchTimeoutMs = exports.claudeUsageEndpoint = void 0;
63
+ exports.englishRelativeResetWords = exports.claudeChainExclusionWords = exports.claudeChainExclusions = exports.claudeSessionWindowMs = exports.claudeWeeklyWindowMs = exports.claudeLaunchResetTieMs = exports.claudeLaunchSessionCeilingPercent = exports.claudeUsageBucketKinds = exports.claudeUsageFetchTimeoutMs = exports.claudeUsageEndpoint = void 0;
58
64
  exports.readClaudeOAuthToken = readClaudeOAuthToken;
59
65
  exports.checkIsClaudeTokenExpired = checkIsClaudeTokenExpired;
60
66
  exports.fetchUsageBuckets = fetchUsageBuckets;
@@ -69,13 +75,17 @@ exports.checkIsScopedWeeklyModel = checkIsScopedWeeklyModel;
69
75
  exports.getRelevantClaudeUsageKinds = getRelevantClaudeUsageKinds;
70
76
  exports.checkHasHeadroomForClaudeModel = checkHasHeadroomForClaudeModel;
71
77
  exports.checkIsClaudeUsageExhausted = checkIsClaudeUsageExhausted;
78
+ exports.checkHaveClaudeUsageWindowsReset = checkHaveClaudeUsageWindowsReset;
72
79
  exports.checkIsClaudeModelClearOfLimit = checkIsClaudeModelClearOfLimit;
80
+ exports.getClaudeChainExclusion = getClaudeChainExclusion;
81
+ exports.getClaudeUsagePercentAsOf = getClaudeUsagePercentAsOf;
82
+ exports.getClaudeUsageBucketAsOf = getClaudeUsageBucketAsOf;
73
83
  exports.checkIsClaudeProfileLaunchable = checkIsClaudeProfileLaunchable;
74
84
  exports.sortClaudeProfilesByLaunchRank = sortClaudeProfilesByLaunchRank;
75
85
  exports.getClaudeLaunchPick = getClaudeLaunchPick;
76
86
  exports.describeClaudeLaunchOutcome = describeClaudeLaunchOutcome;
87
+ exports.describeClaudeChainExclusions = describeClaudeChainExclusions;
77
88
  exports.buildClaudeProfilesReport = buildClaudeProfilesReport;
78
- exports.buildClaudeProfileUsageViews = buildClaudeProfileUsageViews;
79
89
  exports.getClaudeProfileRecordsFromState = getClaudeProfileRecordsFromState;
80
90
  exports.formatClaudeUsageResetAt = formatClaudeUsageResetAt;
81
91
  exports.formatClaudeUsageRelativeReset = formatClaudeUsageRelativeReset;
@@ -268,15 +278,16 @@ function getRelevantClaudeUsageKinds(model) {
268
278
  return checkIsScopedWeeklyModel(model) ? ['session', 'weekly_all', 'weekly_scoped'] : ['session', 'weekly_all'];
269
279
  }
270
280
  /**
271
- * @description Whether every window a launch of `model` drains is KNOWN and below 100 % — the model is clear of an exhausted
272
- * window: a Fable-only weekly limit does not stop `sonnet`, while an exhausted session or shared weekly window stops every
273
- * model, Fable included. Unknown figures (no snapshot, a window the snapshot lacks) are `false`: a limit nobody can tell the
274
- * scope of is taken to cover the model. A stale snapshot still counts — its last figures are the best there are.
281
+ * @description Whether every window a launch of `model` drains is KNOWN and below 100 % at `nowMs` — the model is clear of an
282
+ * exhausted window: a Fable-only weekly limit does not stop `sonnet`, while an exhausted session or shared weekly window stops
283
+ * every model, Fable included. Unknown figures (no snapshot, a window the snapshot lacks) are `false`: a limit nobody can tell
284
+ * the scope of is taken to cover the model. A stale snapshot still counts — its last figures are the best there are — read
285
+ * against the clock ({@link getClaudeUsagePercentAsOf}): a window whose reset has passed counts as empty.
275
286
  */
276
- function checkHasHeadroomForClaudeModel(usage, model) {
287
+ function checkHasHeadroomForClaudeModel(usage, model, nowMs) {
277
288
  return getRelevantClaudeUsageKinds(model).every((kind) => {
278
289
  const bucket = getClaudeUsageBucket(usage, kind);
279
- return bucket !== null && bucket.percent < 100;
290
+ return bucket !== null && getClaudeUsagePercentAsOf(bucket, nowMs) < 100;
280
291
  });
281
292
  }
282
293
  /**
@@ -290,27 +301,35 @@ function checkIsClaudeUsageExhausted(usage, model, nowMs) {
290
301
  return false;
291
302
  return getRelevantClaudeUsageKinds(model).some((kind) => {
292
303
  const bucket = getClaudeUsageBucket(usage, kind);
293
- if (!bucket || bucket.percent < 100)
294
- return false;
295
- const resetsAtMs = bucket.resetsAt === null ? Number.NaN : Date.parse(bucket.resetsAt);
296
- return !(Number.isFinite(resetsAtMs) && resetsAtMs <= nowMs);
304
+ return bucket !== null && getClaudeUsagePercentAsOf(bucket, nowMs) >= 100;
297
305
  });
298
306
  }
307
+ /**
308
+ * @description Whether every window a launch of `model` drains that the snapshot carries has passed its reset instant by
309
+ * `nowMs` — the clock proves the windows that were read are OVER, whether or not the snapshot could be re-read (an account no
310
+ * CLI runs on keeps an expired token and a stale snapshot for good). It does NOT say what was used since: a login of the same
311
+ * account elsewhere (another machine, another host user) leaves no trace here. `false` for no figures, and for any window
312
+ * that is still running or names no reset.
313
+ */
314
+ function checkHaveClaudeUsageWindowsReset(usage, model, nowMs) {
315
+ const buckets = getRelevantClaudeUsageBuckets(usage, model);
316
+ return buckets.length > 0 && buckets.every((bucket) => checkIsClaudeBucketResetPassed(bucket, nowMs));
317
+ }
299
318
  /**
300
319
  * @description Whether a pick of `pickedModel`, on the account a usage limit stopped while it ran `limitedModel`, is clear of that
301
320
  * limit. The window that stopped the limited model is one of the windows IT drains, so a picked model that drains all of them
302
321
  * (the same model, a model on the same windows, or Fable after any other model — Fable drains the shared windows too) is covered
303
322
  * by the limit however far the figures lag behind it. Only a model draining FEWER windows — a non-Fable model after Fable, which
304
- * may have stopped on its own weekly window alone — is judged by {@link checkHasHeadroomForClaudeModel}. An unknown
323
+ * may have stopped on its own weekly window alone — is judged by {@link checkHasHeadroomForClaudeModel} at `nowMs`. An unknown
305
324
  * `limitedModel` leaves it to the figures.
306
325
  */
307
- function checkIsClaudeModelClearOfLimit(usage, limitedModel, pickedModel) {
326
+ function checkIsClaudeModelClearOfLimit(usage, limitedModel, pickedModel, nowMs) {
308
327
  if (limitedModel !== null) {
309
328
  const pickedKinds = getRelevantClaudeUsageKinds(pickedModel);
310
329
  if (getRelevantClaudeUsageKinds(limitedModel).every((kind) => pickedKinds.includes(kind)))
311
330
  return false;
312
331
  }
313
- return checkHasHeadroomForClaudeModel(usage, pickedModel);
332
+ return checkHasHeadroomForClaudeModel(usage, pickedModel, nowMs);
314
333
  }
315
334
  // ── the launch pick ──
316
335
  /** A new agent never starts on an account whose five-hour window is already this full: it would hit the limit within minutes. */
@@ -319,10 +338,23 @@ exports.claudeLaunchSessionCeilingPercent = 90;
319
338
  exports.claudeLaunchResetTieMs = 60_000;
320
339
  exports.claudeWeeklyWindowMs = 7 * 24 * 3_600_000;
321
340
  exports.claudeSessionWindowMs = 5 * 3_600_000;
341
+ /** Every exclusion, in the order an answer names them. */
342
+ exports.claudeChainExclusions = ['notListed', 'switchedOff'];
343
+ /** The words of an exclusion for the first line of an answer and the command line. */
344
+ exports.claudeChainExclusionWords = {
345
+ notListed: 'not in the /limits list',
346
+ switchedOff: 'switched off in the /limits list',
347
+ };
348
+ /** Why `scope` keeps agents off the account `name`; `null` when it does not (no Claude account listed, or an enabled rung of it). */
349
+ function getClaudeChainExclusion(name, scope) {
350
+ if (!scope || scope.enabledNames.has(name))
351
+ return null;
352
+ return scope.disabledNames.has(name) ? 'switchedOff' : 'notListed';
353
+ }
322
354
  /**
323
355
  * The account itself can run: signed in, not marked limited, its API credits not used up, and none of the windows
324
356
  * the model drains (`relevantBuckets`, read by the caller) at 100 %. The one hard-eligibility rule of the report's
325
- * `isEligible` (figures as recorded) and of the launch pick (figures as of now).
357
+ * `isEligible` and of the launch pick, both on the figures as of now.
326
358
  */
327
359
  function checkIsClaudeProfileEligible(profile, relevantBuckets, nowMs) {
328
360
  const isLimited = profile.limitedUntil !== null && Date.parse(profile.limitedUntil) > nowMs;
@@ -337,20 +369,37 @@ function getRelevantClaudeUsageBuckets(usage, model) {
337
369
  .map((kind) => getClaudeUsageBucket(usage, kind))
338
370
  .filter((bucket) => bucket !== null);
339
371
  }
372
+ /** Whether the bucket names a reset instant that is no later than `nowMs`. */
373
+ function checkIsClaudeBucketResetPassed(bucket, nowMs) {
374
+ const resetMs = getBucketResetMs(bucket);
375
+ return Number.isFinite(resetMs) && resetMs <= nowMs;
376
+ }
340
377
  /**
341
- * A bucket as it stands at `nowMs`: a window whose reset instant has passed since the figure was read is empty again
342
- * (0 %) and resets one window length per elapsed period later. A bucket without a usable reset stays as read.
378
+ * @description The used percent of a bucket against the clock — THE one rule every screen and every pick reads a figure by:
379
+ * a window whose reset instant has passed since the figure was read is over, so 0 %; a window with a reset ahead, with none or
380
+ * with an unreadable one keeps the figure as read. It says the OLD window ended, nothing about use since (another login of the
381
+ * account, on another machine or host user, is invisible here).
343
382
  */
344
- function readClaudeBucketAsOf(bucket, nowMs) {
345
- const resetMs = getBucketResetMs(bucket);
346
- if (!Number.isFinite(resetMs) || resetMs > nowMs)
383
+ function getClaudeUsagePercentAsOf(bucket, nowMs) {
384
+ return checkIsClaudeBucketResetPassed(bucket, nowMs) ? 0 : bucket.percent;
385
+ }
386
+ /**
387
+ * @description A bucket as the RANKING of accounts reads it at `nowMs` ({@link sortClaudeProfilesByLaunchRank}, the soonest-reset
388
+ * pick, `nextAvailable`): a window that has reset is empty ({@link getClaudeUsagePercentAsOf}) and its reset moves one window
389
+ * length per elapsed period ahead. That instant is an ESTIMATE made only so such an account has a place in an order — nothing
390
+ * shows that the next window started then (a five-hour window starts at the account's first use), so no screen, report or
391
+ * message may show it as a reset; they keep the instant that passed.
392
+ */
393
+ function getClaudeUsageBucketAsOf(bucket, nowMs) {
394
+ if (!checkIsClaudeBucketResetPassed(bucket, nowMs))
347
395
  return bucket;
396
+ const resetMs = getBucketResetMs(bucket);
348
397
  const windowMs = bucket.kind === 'session' ? exports.claudeSessionWindowMs : exports.claudeWeeklyWindowMs;
349
398
  const rolledMs = resetMs + (Math.floor((nowMs - resetMs) / windowMs) + 1) * windowMs;
350
- return { ...bucket, percent: 0, resetsAt: new Date(rolledMs).toISOString() };
399
+ return { ...bucket, percent: getClaudeUsagePercentAsOf(bucket, nowMs), resetsAt: new Date(rolledMs).toISOString() };
351
400
  }
352
401
  function getRelevantClaudeBucketsAsOf(profile, model, nowMs) {
353
- return getRelevantClaudeUsageBuckets(profile.usage, model).map((bucket) => readClaudeBucketAsOf(bucket, nowMs));
402
+ return getRelevantClaudeUsageBuckets(profile.usage, model).map((bucket) => getClaudeUsageBucketAsOf(bucket, nowMs));
354
403
  }
355
404
  /**
356
405
  * @description Whether a NEW agent of `model` may start on the profile now: a subscription account that is eligible by the
@@ -445,21 +494,36 @@ function getClaudeProfileFreeAtMs(profile, model, nowMs) {
445
494
  /** When the profile's five-hour window resets (as of `nowMs`); `null` when the snapshot has none or names no reset. */
446
495
  function getSessionResetMs(profile, nowMs) {
447
496
  const session = getClaudeUsageBucket(profile.usage, 'session');
448
- const resetMs = session === null ? Number.NaN : getBucketResetMs(readClaudeBucketAsOf(session, nowMs));
497
+ const resetMs = session === null ? Number.NaN : getBucketResetMs(getClaudeUsageBucketAsOf(session, nowMs));
449
498
  return Number.isFinite(resetMs) ? resetMs : null;
450
499
  }
451
500
  /**
452
- * The subscription account that frees up first, when nothing is usable now; `null` when no account names a time. The
453
- * account a limit just stopped (`stoppedName`) may show no blocker at all — its figures lag the limit — and is then
454
- * taken to free up when its five-hour window resets, so a single account is never left without a time to come back.
501
+ * The instant the API-billed account `profile` the list holds becomes usable for a new agent: the later of its limited mark and
502
+ * its agents-only hold (`agentHoldUntil`). `nowMs` when nothing blocks it; `null` for an account that never comes back at a
503
+ * known time — not held by the list, past its expiry day, or with no hold or mark ahead to name.
504
+ */
505
+ function getClaudeApiProfileFreeAtMs(profile, chainScope, expiredApiNames, nowMs) {
506
+ if (chainScope === null || !chainScope.enabledNames.has(profile.name) || expiredApiNames.has(profile.name))
507
+ return null;
508
+ const aheadMs = [profile.limitedUntil, profile.agentHoldUntil]
509
+ .map((instant) => (instant ? Date.parse(instant) : Number.NaN))
510
+ .filter((instantMs) => Number.isFinite(instantMs) && instantMs > nowMs);
511
+ return aheadMs.length === 0 ? nowMs : Math.max(...aheadMs);
512
+ }
513
+ /**
514
+ * The account that frees up first, when nothing is usable now; `null` when no account names a time. The account a limit just
515
+ * stopped (`stoppedName`) may show no blocker at all — its figures lag the limit — and is then taken to free up when its
516
+ * five-hour window resets, so a single account is never left without a time to come back. An API-billed account the list holds
517
+ * is named only at the end of a hold or limited mark it carries.
455
518
  */
456
- function getClaudeNextAvailable(profiles, model, nowMs, excludedNames, stoppedName) {
519
+ function getClaudeNextAvailable(input) {
520
+ const { model, nowMs, chainScope, expiredApiNames, stoppedName } = input;
457
521
  let next = null;
458
- for (const profile of profiles) {
459
- // These never come back at a known time: switched off, signed out, API-billed, out of credits.
460
- if (excludedNames.has(profile.name) || profile.loggedIn === false || profile.billing === 'api' || profile.creditExhaustedAt !== null)
522
+ for (const profile of input.profiles) {
523
+ // These never come back at a known time: kept off agents by the /limits list, signed out, out of credits.
524
+ if (getClaudeChainExclusion(profile.name, chainScope) !== null || profile.loggedIn === false || profile.creditExhaustedAt !== null)
461
525
  continue;
462
- let freeAtMs = getClaudeProfileFreeAtMs(profile, model, nowMs);
526
+ let freeAtMs = profile.billing === 'api' ? getClaudeApiProfileFreeAtMs(profile, chainScope, expiredApiNames, nowMs) : getClaudeProfileFreeAtMs(profile, model, nowMs);
463
527
  // The limit stopped this account, yet its figures show no blocker, so nothing says WHICH limit it was (a weekly window
464
528
  // the usage endpoint has not caught up with, or the five-hour one). The five-hour reset is a guess — the earliest it
465
529
  // could be free. A wrong guess just hits the limit again on the resume and asks again: at most about one try per five hours.
@@ -472,45 +536,80 @@ function getClaudeNextAvailable(profiles, model, nowMs, excludedNames, stoppedNa
472
536
  }
473
537
  return next === null ? null : { profile: next.profile, at: new Date(next.atMs).toISOString() };
474
538
  }
539
+ /** Whether `profile` is held off agents at `nowMs` (`agentHoldUntil` ahead). Never read by the topics' fallback. */
540
+ function checkIsClaudeProfileHeldFromAgents(profile, nowMs) {
541
+ const heldUntilMs = profile.agentHoldUntil ? Date.parse(profile.agentHoldUntil) : Number.NaN;
542
+ return Number.isFinite(heldUntilMs) && heldUntilMs > nowMs;
543
+ }
544
+ /**
545
+ * Whether a NEW agent may start on the account billed to API credits `profile` now: the operator's `/limits` list holds it as an
546
+ * enabled rung (without such a list an API account is never picked: it would look inexhaustible and spend money unasked), it is
547
+ * signed in, not marked limited, not held off agents (`agentHoldUntil`), its credits not marked used up and not past the expiry
548
+ * day the operator gave. No window to read: the balance is its only limit.
549
+ */
550
+ function checkIsClaudeApiProfileLaunchable(profile, chainScope, expiredApiNames, nowMs) {
551
+ return chainScope !== null && chainScope.enabledNames.has(profile.name) && !expiredApiNames.has(profile.name)
552
+ && !checkIsClaudeProfileHeldFromAgents(profile, nowMs) && checkIsClaudeProfileEligible(profile, [], nowMs);
553
+ }
475
554
  /**
476
555
  * @description The account a process of `model` should run on.
477
556
  *
478
- * NEW agent (no `currentProfile`): of the USABLE accounts — subscription, signed in, not marked limited, not out of API
479
- * credits, not switched off (`excludedNames`), every weekly window the model drains below 100 % and the five-hour window
480
- * below {@link claudeLaunchSessionCeilingPercent} — the one whose weekly window resets soonest
481
- * ({@link sortClaudeProfilesByLaunchRank}): spend first what burns first, and move to a farther reset only when the
482
- * five-hour window is exhausted. Fable's own window at 100 % takes only Fable out.
557
+ * The operator's `/limits` list rules who may be named at all (`chainScope`): once it names any Claude account, only an account
558
+ * with an ENABLED rung there is recommended — one the list leaves out or switches off never is, for a new agent or a resumed one.
559
+ * A list with no Claude rung restricts nothing.
560
+ *
561
+ * NEW agent (no `currentProfile`): first an account billed to API credits the list holds (the operator's choice: spend the
562
+ * bonus credit before any subscription), as long as it is signed in, not marked limited, not held off agents (`agentHoldUntil`),
563
+ * its credits are not marked used up and the expiry day the operator gave (`expiredApiNames`) has not passed;
564
+ * then, of the USABLE subscription accounts — signed in, not marked limited, not out of API credits, every weekly window the
565
+ * model drains below 100 % and the five-hour window below {@link claudeLaunchSessionCeilingPercent} — the one whose weekly
566
+ * window resets soonest ({@link sortClaudeProfilesByLaunchRank}): spend first what burns first, and move to a farther reset only
567
+ * when the five-hour window is exhausted. Fable's own window at 100 % takes only Fable out. The list's ORDER ranks nothing but
568
+ * several API accounts among themselves: it was written for a topic's fallback, the agents' order is "API credit, then what
569
+ * burns soonest".
483
570
  *
484
- * WARM session (`currentProfile` known): it stays on that account unless the account is signed out, marked limited, out
485
- * of API credits or at 100 % on a window the model drains — the ceiling does not apply, and an API-billed account the
486
- * session already works on is kept (the spend was approved). `isStoppedByLimit` takes `currentProfile` out of the answer
487
- * whatever the figures say (they may lag the limit); the rest follows the new-agent rule, and the reason says the
488
- * session moved (`movedFromLimited`, or `movedFromUnavailable` when the account could no longer run by its own figures).
571
+ * WARM session (`currentProfile` known): it stays on that account unless the account is signed out, marked limited, held off
572
+ * agents (`agentHoldUntil`), out of API credits, at 100 % on a window the model drains, or no longer allowed by the list — the
573
+ * ceiling does not apply, and an
574
+ * API-billed account the session already works on is kept (the spend was approved) while the list does not take it out.
575
+ * `isStoppedByLimit` takes `currentProfile` out of the answer whatever the figures say (they may lag the limit); the rest
576
+ * follows the new-agent rule, and the reason says the session moved (`movedFromLimited`, or `movedFromUnavailable` when the
577
+ * account could no longer run by its own figures or the list).
489
578
  *
490
579
  * Nothing usable → `pick: null` and {@link ClaudeLaunchPick.nextAvailable}.
491
580
  */
492
581
  function getClaudeLaunchPick(input) {
493
- const excludedNames = input.excludedNames ?? new Set();
582
+ const chainScope = input.chainScope ?? null;
583
+ const expiredApiNames = input.expiredApiNames ?? new Set();
494
584
  const current = input.currentProfile ? input.profiles.find((profile) => profile.name === input.currentProfile) : undefined;
495
585
  const isStopped = current !== undefined && input.isStoppedByLimit === true;
496
586
  if (current && !isStopped
587
+ && getClaudeChainExclusion(current.name, chainScope) === null
588
+ && !checkIsClaudeProfileHeldFromAgents(current, input.nowMs)
497
589
  && checkIsClaudeProfileEligible(current, getRelevantClaudeBucketsAsOf(current, input.model, input.nowMs), input.nowMs)) {
498
590
  return { pick: current.name, reason: 'warm', nextAvailable: null };
499
591
  }
500
592
  const movedFrom = current?.name ?? null;
501
- const usable = input.profiles.filter((profile) => profile.name !== movedFrom
502
- && !excludedNames.has(profile.name)
503
- && checkIsClaudeProfileLaunchable(profile, input.model, input.nowMs));
504
- const [first] = sortClaudeProfilesByLaunchRank(usable, input.model, input.nowMs);
593
+ const allowed = input.profiles.filter((profile) => profile.name !== movedFrom && getClaudeChainExclusion(profile.name, chainScope) === null);
594
+ const chainOrder = chainScope === null ? [] : [...chainScope.enabledNames];
595
+ const apiFirst = allowed
596
+ .filter((profile) => profile.billing === 'api' && checkIsClaudeApiProfileLaunchable(profile, chainScope, expiredApiNames, input.nowMs))
597
+ .sort((a, b) => chainOrder.indexOf(a.name) - chainOrder.indexOf(b.name));
598
+ const subscriptions = sortClaudeProfilesByLaunchRank(allowed.filter((profile) => profile.billing !== 'api' && checkIsClaudeProfileLaunchable(profile, input.model, input.nowMs)), input.model, input.nowMs);
599
+ const [first] = [...apiFirst, ...subscriptions];
505
600
  if (first) {
506
- const reason = movedFrom === null ? 'soonestWeeklyReset' : isStopped ? 'movedFromLimited' : 'movedFromUnavailable';
601
+ const reason = movedFrom !== null ? (isStopped ? 'movedFromLimited' : 'movedFromUnavailable') : first.billing === 'api' ? 'apiCreditFirst' : 'soonestWeeklyReset';
507
602
  return { pick: first.name, reason, nextAvailable: null };
508
603
  }
509
- return { pick: null, reason: 'none', nextAvailable: getClaudeNextAvailable(input.profiles, input.model, input.nowMs, excludedNames, isStopped ? movedFrom : null) };
604
+ return {
605
+ pick: null,
606
+ reason: 'none',
607
+ nextAvailable: getClaudeNextAvailable({ profiles: input.profiles, model: input.model, nowMs: input.nowMs, chainScope, expiredApiNames, stoppedName: isStopped ? movedFrom : null }),
608
+ };
510
609
  }
511
610
  /**
512
611
  * @description The pick in words, for the first line of the `claude_profiles` answer and the CLI: why the account was chosen
513
- * (`stays on the warm account`, `moved: <name> stopped on a limit` / `can no longer run`, `soonest weekly reset`), or that nothing is usable
612
+ * (`stays on the warm account`, `moved: <name> stopped on a limit` / `can no longer run`, `soonest weekly reset`, `API credit first`), or that nothing is usable
514
613
  * and which account frees up when. `currentProfile` is the account the caller passed for a resumed session.
515
614
  */
516
615
  function describeClaudeLaunchOutcome(report, currentProfile) {
@@ -523,24 +622,57 @@ function describeClaudeLaunchOutcome(report, currentProfile) {
523
622
  return `moved: ${currentProfile ?? 'the warm account'} can no longer run`;
524
623
  case 'soonestWeeklyReset':
525
624
  return 'soonest weekly reset';
625
+ case 'apiCreditFirst':
626
+ return 'API credit first, as the /limits list allows';
526
627
  case 'none':
527
628
  return report.nextAvailable === null
528
629
  ? 'none usable — no account names a time it frees up'
529
630
  : `none usable — next: ${report.nextAvailable.profile} at ${report.nextAvailable.at}`;
530
631
  }
531
632
  }
633
+ /**
634
+ * @description The accounts the `/limits` list keeps agents off, one clause per reason (`not offered — not in the /limits list:
635
+ * a, b; switched off in the /limits list: c`), or `null` when there are none. The first lines of the `claude_profiles` answer
636
+ * and the CLI add it, so an agent that sees a signed-in account missing from `recommended` is told why.
637
+ */
638
+ function describeClaudeChainExclusions(report) {
639
+ const clauses = exports.claudeChainExclusions
640
+ .map((exclusion) => ({ exclusion, names: report.profiles.filter((entry) => entry.chainExclusion === exclusion).map((entry) => entry.name) }))
641
+ .filter(({ names }) => names.length > 0)
642
+ .map(({ exclusion, names }) => `${exports.claudeChainExclusionWords[exclusion]}: ${names.join(', ')}`);
643
+ return clauses.length === 0 ? null : `not offered — ${clauses.join('; ')}`;
644
+ }
645
+ /**
646
+ * The credit fields of a report entry before the bot's estimate is added (`utils/claudeProfileUsageViews.ts` fills them for an
647
+ * API account): this module is loaded by the connector guards, before any env file is read, and must not reach the credit
648
+ * module (its file store, zod).
649
+ */
650
+ const emptyClaudeProfileReportCredit = {
651
+ spentUsd: null,
652
+ remainingEstimateUsd: null,
653
+ expiresOn: null,
654
+ probablyUsedUp: false,
655
+ renewedAt: null,
656
+ };
532
657
  /**
533
658
  * @description The report of every profile for a launch of `model`, with the pick of {@link getClaudeLaunchPick}
534
- * (`options`: the warm account, the limit stop, the switched-off accounts). `isEligible` is the strict reading — signed in,
535
- * not marked limited, its API credits not used up, not at 100 % on a relevant window as recorded — which the explicit
536
- * fallback chain's availability reads; `recommended` is the pick, an account billed to API credits only when a warm
537
- * session already runs on it. The entries keep the input order.
659
+ * (`options`: the warm account, the limit stop, the `/limits` list). The figures of an entry are read as of `nowMs`
660
+ * ({@link getClaudeUsagePercentAsOf}: a window whose reset has passed since it was read counts as empty), its `isUsageStale` says
661
+ * they were not re-read; the pick itself ranks by the estimated next reset of {@link getClaudeUsageBucketAsOf}. `isEligible` is the strict reading — signed in, not marked limited, its API credits not used up, not
662
+ * at 100 % on a relevant window, no five-hour ceiling, not kept off agents by the list (`chainExclusion`) — which the
663
+ * explicit fallback chain's availability reads (it passes no list); `recommended` is the pick. The entries keep the input order.
664
+ *
665
+ * The credit fields of the entries (`spentUsd`, `remainingEstimateUsd`, `expiresOn`, `probablyUsedUp`, `renewedAt`) are left
666
+ * EMPTY here: this module is loaded by the connector guards, which may not reach the credit module. Anything that is shown to
667
+ * an agent or an operator — the `claude_profiles` tool, `charness claude-profiles` — uses `buildClaudeProfilesCreditReport`
668
+ * (`utils/claudeProfileUsageViews.ts`) instead; this builder is for the ranking (`fallbackChain.ts` reads `isEligible`).
538
669
  */
539
670
  function buildClaudeProfilesReport(profiles, model, nowMs, options = {}) {
540
671
  const relevantBuckets = getRelevantClaudeUsageKinds(model);
541
672
  const entries = profiles.map((profile) => {
542
- const relevant = getRelevantClaudeUsageBuckets(profile.usage, model);
673
+ const relevant = getRelevantClaudeBucketsAsOf(profile, model, nowMs);
543
674
  const maxPercent = relevant.length === 0 ? null : Math.max(...relevant.map((bucket) => bucket.percent));
675
+ const chainExclusion = getClaudeChainExclusion(profile.name, options.chainScope);
544
676
  return {
545
677
  name: profile.name,
546
678
  configDir: profile.configDir,
@@ -549,12 +681,14 @@ function buildClaudeProfilesReport(profiles, model, nowMs, options = {}) {
549
681
  subscriptionType: profile.subscriptionType,
550
682
  billing: profile.billing,
551
683
  loggedIn: profile.loggedIn ?? null,
552
- buckets: profile.usage?.buckets ?? [],
684
+ buckets: (profile.usage?.buckets ?? []).map((bucket) => ({ ...bucket, percent: getClaudeUsagePercentAsOf(bucket, nowMs) })),
553
685
  usageFetchedAt: profile.usage?.fetchedAt ?? null,
554
686
  isUsageStale: profile.usage?.isStale === true,
555
687
  limitedUntil: profile.limitedUntil,
556
688
  creditExhaustedAt: profile.creditExhaustedAt,
557
- isEligible: checkIsClaudeProfileEligible(profile, relevant, nowMs),
689
+ ...emptyClaudeProfileReportCredit,
690
+ isEligible: chainExclusion === null && checkIsClaudeProfileEligible(profile, relevant, nowMs),
691
+ chainExclusion,
558
692
  headroomPercent: maxPercent === null ? null : 100 - maxPercent,
559
693
  isRecommended: false,
560
694
  };
@@ -565,31 +699,6 @@ function buildClaudeProfilesReport(profiles, model, nowMs, options = {}) {
565
699
  recommended.isRecommended = true;
566
700
  return { model, relevantBuckets, recommended: launch.pick, pickReason: launch.reason, nextAvailable: launch.nextAvailable, profiles: entries };
567
701
  }
568
- /**
569
- * @description The ranking's view of every profile off the registry: `default` (its hidden record, when the
570
- * bot has written one) first, then the added profiles in creation order. Shared by the bot (live state) and
571
- * the CLI (`state.json` read directly).
572
- */
573
- function buildClaudeProfileUsageViews(input) {
574
- // A `default` the operator signed out through /accounts stays out of every ranking until it is signed in again.
575
- const isDefaultRemoved = input.records.default?.isRemoved === true;
576
- const toView = (name, record) => ({
577
- name,
578
- configDir: (0, claudeProfiles_1.resolveClaudeProfileDir)(input.dataDir, name),
579
- loggedIn: record?.loggedIn,
580
- email: record?.email ?? null,
581
- subscriptionType: record?.subscriptionType ?? null,
582
- usage: record?.usage,
583
- limitedUntil: record?.limitedUntil ?? null,
584
- billing: record?.billing ?? null,
585
- creditExhaustedAt: record?.creditExhaustedAt ?? null,
586
- ...(record?.apiSpend ? { apiSpend: record.apiSpend } : {}),
587
- });
588
- const added = Object.entries(input.records)
589
- .filter(([name]) => name !== 'default')
590
- .sort(([, a], [, b]) => a.createdAt.localeCompare(b.createdAt));
591
- return [...(isDefaultRemoved ? [] : [toView('default', input.records.default)]), ...added.map(([name, record]) => toView(name, record))];
592
- }
593
702
  /** The profile registry out of a `state.json` already read (`stateFile.ts`): entries without a creation time are dropped. */
594
703
  function getClaudeProfileRecordsFromState(stateFile) {
595
704
  const registry = stateFile.claudeProfiles;
@@ -630,8 +739,9 @@ exports.englishRelativeResetWords = { pattern: '🔄 in {time}', day: 'd', hour:
630
739
  /**
631
740
  * @description A reset instant as a time from now: `🔄 in 2d 1h`, `🔄 in 2h`, `🔄 in 30m`. The two largest
632
741
  * units at most, minutes only under an hour: from a day up it is days + hours (hours dropped when zero), from
633
- * an hour up whole hours (rounded), below that minutes (at least one). An instant already past reads as
634
- * `🔄 in 1m` (the window is about to roll over). `?` for a missing or unparseable instant.
742
+ * an hour up whole hours (rounded), below that minutes (at least one: the last seconds before a reset read `in 1m`).
743
+ * Pass an instant AHEAD — a past one is not a countdown ({@link formatClaudeUsageBucket} shows a window whose reset
744
+ * has passed as a bare percent, so it never passes one). `?` for a missing or unparseable instant.
635
745
  */
636
746
  function formatClaudeUsageRelativeReset(resetsAt, nowMs, words = exports.englishRelativeResetWords) {
637
747
  if (resetsAt === null)
@@ -660,18 +770,25 @@ function formatClaudeUsageRelativeReset(resetsAt, nowMs, words = exports.english
660
770
  return words.pattern.replace('{time}', time);
661
771
  }
662
772
  /**
663
- * @description `81% 🔄 in 2h` for a bucket, `—` for a missing one. A bucket whose reset is unknown shows
664
- * `fallbackResetsAt` instead (the session window's reset is often missing while the weekly one is known);
665
- * with neither it is the bare percent — a «?» after a number would read as a doubt about the number.
773
+ * @description `81% 🔄 in 2h` for a bucket, `—` for a missing one. A bucket whose reset has passed since it was read shows a
774
+ * bare `0%` ({@link getClaudeUsagePercentAsOf}) — never the old figure with a reset «in 1m», and no countdown either: nothing
775
+ * says when its next period ends. A snapshot nobody could re-read (an expired token) must not claim a used-up window for ever;
776
+ * its stale mark is the caller's. A bucket whose reset is unknown shows the reset of `fallbackBucket` instead (the session
777
+ * window's reset is often missing while the weekly one is known) while that one is still ahead; with neither it is the bare
778
+ * percent — a «?» after a number would read as a doubt about the number.
666
779
  */
667
780
  function formatClaudeUsageBucket(bucket, nowMs, options = {}) {
668
781
  if (bucket === null)
669
782
  return '—';
670
- const known = bucket.resetsAt !== null && !Number.isNaN(Date.parse(bucket.resetsAt));
671
- const resetsAt = known ? bucket.resetsAt : options.fallbackResetsAt ?? null;
783
+ const percent = getClaudeUsagePercentAsOf(bucket, nowMs);
784
+ if (checkIsClaudeBucketResetPassed(bucket, nowMs))
785
+ return `${percent}%`;
786
+ const isOwnResetKnown = bucket.resetsAt !== null && !Number.isNaN(Date.parse(bucket.resetsAt));
787
+ const fallbackBucket = options.fallbackBucket && !checkIsClaudeBucketResetPassed(options.fallbackBucket, nowMs) ? options.fallbackBucket : null;
788
+ const resetsAt = isOwnResetKnown ? bucket.resetsAt : fallbackBucket?.resetsAt ?? null;
672
789
  if (resetsAt === null || Number.isNaN(Date.parse(resetsAt)))
673
- return `${bucket.percent}%`;
674
- return `${bucket.percent}% ${formatClaudeUsageRelativeReset(resetsAt, nowMs, options.words)}`;
790
+ return `${percent}%`;
791
+ return `${percent}% ${formatClaudeUsageRelativeReset(resetsAt, nowMs, options.words)}`;
675
792
  }
676
793
  // ── small readers ──
677
794
  function checkIsRecord(value) {