@swarmify/agents-cli 1.13.3 → 1.14.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 (567) hide show
  1. package/README.md +2 -319
  2. package/bin/agents.js +2 -0
  3. package/package.json +13 -79
  4. package/scripts/postinstall.js +4 -71
  5. package/CHANGELOG.md +0 -316
  6. package/LICENSE +0 -21
  7. package/dist/commands/__tests__/sessions-tail.test.d.ts +0 -2
  8. package/dist/commands/__tests__/sessions-tail.test.d.ts.map +0 -1
  9. package/dist/commands/__tests__/sessions-tail.test.js +0 -108
  10. package/dist/commands/__tests__/sessions-tail.test.js.map +0 -1
  11. package/dist/commands/__tests__/sessions.test.d.ts +0 -2
  12. package/dist/commands/__tests__/sessions.test.d.ts.map +0 -1
  13. package/dist/commands/__tests__/sessions.test.js +0 -636
  14. package/dist/commands/__tests__/sessions.test.js.map +0 -1
  15. package/dist/commands/cloud.d.ts +0 -11
  16. package/dist/commands/cloud.d.ts.map +0 -1
  17. package/dist/commands/cloud.js +0 -363
  18. package/dist/commands/cloud.js.map +0 -1
  19. package/dist/commands/commands.d.ts +0 -12
  20. package/dist/commands/commands.d.ts.map +0 -1
  21. package/dist/commands/commands.js +0 -629
  22. package/dist/commands/commands.js.map +0 -1
  23. package/dist/commands/daemon.d.ts +0 -11
  24. package/dist/commands/daemon.d.ts.map +0 -1
  25. package/dist/commands/daemon.js +0 -119
  26. package/dist/commands/daemon.js.map +0 -1
  27. package/dist/commands/drive.d.ts +0 -11
  28. package/dist/commands/drive.d.ts.map +0 -1
  29. package/dist/commands/drive.js +0 -175
  30. package/dist/commands/drive.js.map +0 -1
  31. package/dist/commands/exec.d.ts +0 -11
  32. package/dist/commands/exec.d.ts.map +0 -1
  33. package/dist/commands/exec.js +0 -251
  34. package/dist/commands/exec.js.map +0 -1
  35. package/dist/commands/factory.d.ts +0 -11
  36. package/dist/commands/factory.d.ts.map +0 -1
  37. package/dist/commands/factory.js +0 -445
  38. package/dist/commands/factory.js.map +0 -1
  39. package/dist/commands/fork.d.ts +0 -11
  40. package/dist/commands/fork.d.ts.map +0 -1
  41. package/dist/commands/fork.js +0 -147
  42. package/dist/commands/fork.js.map +0 -1
  43. package/dist/commands/hooks.d.ts +0 -12
  44. package/dist/commands/hooks.d.ts.map +0 -1
  45. package/dist/commands/hooks.js +0 -690
  46. package/dist/commands/hooks.js.map +0 -1
  47. package/dist/commands/init.d.ts +0 -15
  48. package/dist/commands/init.d.ts.map +0 -1
  49. package/dist/commands/init.js +0 -137
  50. package/dist/commands/init.js.map +0 -1
  51. package/dist/commands/mcp.d.ts +0 -12
  52. package/dist/commands/mcp.d.ts.map +0 -1
  53. package/dist/commands/mcp.js +0 -583
  54. package/dist/commands/mcp.js.map +0 -1
  55. package/dist/commands/models.d.ts +0 -11
  56. package/dist/commands/models.d.ts.map +0 -1
  57. package/dist/commands/models.js +0 -170
  58. package/dist/commands/models.js.map +0 -1
  59. package/dist/commands/packages.d.ts +0 -11
  60. package/dist/commands/packages.d.ts.map +0 -1
  61. package/dist/commands/packages.js +0 -551
  62. package/dist/commands/packages.js.map +0 -1
  63. package/dist/commands/permissions.d.ts +0 -12
  64. package/dist/commands/permissions.d.ts.map +0 -1
  65. package/dist/commands/permissions.js +0 -724
  66. package/dist/commands/permissions.js.map +0 -1
  67. package/dist/commands/plugins.d.ts +0 -11
  68. package/dist/commands/plugins.d.ts.map +0 -1
  69. package/dist/commands/plugins.js +0 -393
  70. package/dist/commands/plugins.js.map +0 -1
  71. package/dist/commands/profiles.d.ts +0 -12
  72. package/dist/commands/profiles.d.ts.map +0 -1
  73. package/dist/commands/profiles.js +0 -255
  74. package/dist/commands/profiles.js.map +0 -1
  75. package/dist/commands/pty.d.ts +0 -21
  76. package/dist/commands/pty.d.ts.map +0 -1
  77. package/dist/commands/pty.js +0 -391
  78. package/dist/commands/pty.js.map +0 -1
  79. package/dist/commands/pull.d.ts +0 -11
  80. package/dist/commands/pull.d.ts.map +0 -1
  81. package/dist/commands/pull.js +0 -456
  82. package/dist/commands/pull.js.map +0 -1
  83. package/dist/commands/push.d.ts +0 -11
  84. package/dist/commands/push.d.ts.map +0 -1
  85. package/dist/commands/push.js +0 -188
  86. package/dist/commands/push.js.map +0 -1
  87. package/dist/commands/refresh-memory.d.ts +0 -16
  88. package/dist/commands/refresh-memory.d.ts.map +0 -1
  89. package/dist/commands/refresh-memory.js +0 -52
  90. package/dist/commands/refresh-memory.js.map +0 -1
  91. package/dist/commands/resource-view.d.ts +0 -39
  92. package/dist/commands/resource-view.d.ts.map +0 -1
  93. package/dist/commands/resource-view.js +0 -197
  94. package/dist/commands/resource-view.js.map +0 -1
  95. package/dist/commands/routines.d.ts +0 -11
  96. package/dist/commands/routines.d.ts.map +0 -1
  97. package/dist/commands/routines.js +0 -590
  98. package/dist/commands/routines.js.map +0 -1
  99. package/dist/commands/rules.d.ts +0 -12
  100. package/dist/commands/rules.d.ts.map +0 -1
  101. package/dist/commands/rules.js +0 -489
  102. package/dist/commands/rules.js.map +0 -1
  103. package/dist/commands/secrets.d.ts +0 -11
  104. package/dist/commands/secrets.d.ts.map +0 -1
  105. package/dist/commands/secrets.js +0 -352
  106. package/dist/commands/secrets.js.map +0 -1
  107. package/dist/commands/sessions-picker.d.ts +0 -18
  108. package/dist/commands/sessions-picker.d.ts.map +0 -1
  109. package/dist/commands/sessions-picker.js +0 -265
  110. package/dist/commands/sessions-picker.js.map +0 -1
  111. package/dist/commands/sessions-tail.d.ts +0 -20
  112. package/dist/commands/sessions-tail.d.ts.map +0 -1
  113. package/dist/commands/sessions-tail.js +0 -236
  114. package/dist/commands/sessions-tail.js.map +0 -1
  115. package/dist/commands/sessions.d.ts +0 -18
  116. package/dist/commands/sessions.d.ts.map +0 -1
  117. package/dist/commands/sessions.js +0 -1173
  118. package/dist/commands/sessions.js.map +0 -1
  119. package/dist/commands/skills.d.ts +0 -12
  120. package/dist/commands/skills.d.ts.map +0 -1
  121. package/dist/commands/skills.js +0 -717
  122. package/dist/commands/skills.js.map +0 -1
  123. package/dist/commands/status.d.ts +0 -10
  124. package/dist/commands/status.d.ts.map +0 -1
  125. package/dist/commands/status.js +0 -26
  126. package/dist/commands/status.js.map +0 -1
  127. package/dist/commands/subagents.d.ts +0 -11
  128. package/dist/commands/subagents.d.ts.map +0 -1
  129. package/dist/commands/subagents.js +0 -361
  130. package/dist/commands/subagents.js.map +0 -1
  131. package/dist/commands/sync.d.ts +0 -11
  132. package/dist/commands/sync.d.ts.map +0 -1
  133. package/dist/commands/sync.js +0 -70
  134. package/dist/commands/sync.js.map +0 -1
  135. package/dist/commands/teams-picker.d.ts +0 -18
  136. package/dist/commands/teams-picker.d.ts.map +0 -1
  137. package/dist/commands/teams-picker.js +0 -290
  138. package/dist/commands/teams-picker.js.map +0 -1
  139. package/dist/commands/teams.d.ts +0 -18
  140. package/dist/commands/teams.d.ts.map +0 -1
  141. package/dist/commands/teams.js +0 -1144
  142. package/dist/commands/teams.js.map +0 -1
  143. package/dist/commands/utils.d.ts +0 -45
  144. package/dist/commands/utils.d.ts.map +0 -1
  145. package/dist/commands/utils.js +0 -106
  146. package/dist/commands/utils.js.map +0 -1
  147. package/dist/commands/versions.d.ts +0 -11
  148. package/dist/commands/versions.d.ts.map +0 -1
  149. package/dist/commands/versions.js +0 -701
  150. package/dist/commands/versions.js.map +0 -1
  151. package/dist/commands/view.d.ts +0 -43
  152. package/dist/commands/view.d.ts.map +0 -1
  153. package/dist/commands/view.js +0 -894
  154. package/dist/commands/view.js.map +0 -1
  155. package/dist/index.d.ts +0 -9
  156. package/dist/index.d.ts.map +0 -1
  157. package/dist/index.js +0 -496
  158. package/dist/index.js.map +0 -1
  159. package/dist/lib/__tests__/bugfixes.test.d.ts +0 -2
  160. package/dist/lib/__tests__/bugfixes.test.d.ts.map +0 -1
  161. package/dist/lib/__tests__/bugfixes.test.js +0 -192
  162. package/dist/lib/__tests__/bugfixes.test.js.map +0 -1
  163. package/dist/lib/__tests__/exec.test.d.ts +0 -2
  164. package/dist/lib/__tests__/exec.test.d.ts.map +0 -1
  165. package/dist/lib/__tests__/exec.test.js +0 -446
  166. package/dist/lib/__tests__/exec.test.js.map +0 -1
  167. package/dist/lib/__tests__/git-sync.test.d.ts +0 -2
  168. package/dist/lib/__tests__/git-sync.test.d.ts.map +0 -1
  169. package/dist/lib/__tests__/git-sync.test.js +0 -138
  170. package/dist/lib/__tests__/git-sync.test.js.map +0 -1
  171. package/dist/lib/__tests__/hooks.test.d.ts +0 -2
  172. package/dist/lib/__tests__/hooks.test.d.ts.map +0 -1
  173. package/dist/lib/__tests__/hooks.test.js +0 -203
  174. package/dist/lib/__tests__/hooks.test.js.map +0 -1
  175. package/dist/lib/__tests__/memory-compile.test.d.ts +0 -2
  176. package/dist/lib/__tests__/memory-compile.test.d.ts.map +0 -1
  177. package/dist/lib/__tests__/memory-compile.test.js +0 -95
  178. package/dist/lib/__tests__/memory-compile.test.js.map +0 -1
  179. package/dist/lib/__tests__/models.test.d.ts +0 -2
  180. package/dist/lib/__tests__/models.test.d.ts.map +0 -1
  181. package/dist/lib/__tests__/models.test.js +0 -239
  182. package/dist/lib/__tests__/models.test.js.map +0 -1
  183. package/dist/lib/__tests__/rotate.test.d.ts +0 -2
  184. package/dist/lib/__tests__/rotate.test.d.ts.map +0 -1
  185. package/dist/lib/__tests__/rotate.test.js +0 -80
  186. package/dist/lib/__tests__/rotate.test.js.map +0 -1
  187. package/dist/lib/__tests__/secrets-bundles.test.d.ts +0 -2
  188. package/dist/lib/__tests__/secrets-bundles.test.d.ts.map +0 -1
  189. package/dist/lib/__tests__/secrets-bundles.test.js +0 -104
  190. package/dist/lib/__tests__/secrets-bundles.test.js.map +0 -1
  191. package/dist/lib/__tests__/secrets.test.d.ts +0 -2
  192. package/dist/lib/__tests__/secrets.test.d.ts.map +0 -1
  193. package/dist/lib/__tests__/secrets.test.js +0 -90
  194. package/dist/lib/__tests__/secrets.test.js.map +0 -1
  195. package/dist/lib/__tests__/shims.test.d.ts +0 -2
  196. package/dist/lib/__tests__/shims.test.d.ts.map +0 -1
  197. package/dist/lib/__tests__/shims.test.js +0 -57
  198. package/dist/lib/__tests__/shims.test.js.map +0 -1
  199. package/dist/lib/__tests__/usage.test.d.ts +0 -2
  200. package/dist/lib/__tests__/usage.test.d.ts.map +0 -1
  201. package/dist/lib/__tests__/usage.test.js +0 -220
  202. package/dist/lib/__tests__/usage.test.js.map +0 -1
  203. package/dist/lib/__tests__/versions.test.d.ts +0 -2
  204. package/dist/lib/__tests__/versions.test.d.ts.map +0 -1
  205. package/dist/lib/__tests__/versions.test.js +0 -63
  206. package/dist/lib/__tests__/versions.test.js.map +0 -1
  207. package/dist/lib/agents.d.ts +0 -158
  208. package/dist/lib/agents.d.ts.map +0 -1
  209. package/dist/lib/agents.js +0 -1159
  210. package/dist/lib/agents.js.map +0 -1
  211. package/dist/lib/artifact-actions.d.ts +0 -27
  212. package/dist/lib/artifact-actions.d.ts.map +0 -1
  213. package/dist/lib/artifact-actions.js +0 -58
  214. package/dist/lib/artifact-actions.js.map +0 -1
  215. package/dist/lib/cloud/codex.d.ts +0 -26
  216. package/dist/lib/cloud/codex.d.ts.map +0 -1
  217. package/dist/lib/cloud/codex.js +0 -237
  218. package/dist/lib/cloud/codex.js.map +0 -1
  219. package/dist/lib/cloud/factory.d.ts +0 -32
  220. package/dist/lib/cloud/factory.d.ts.map +0 -1
  221. package/dist/lib/cloud/factory.js +0 -43
  222. package/dist/lib/cloud/factory.js.map +0 -1
  223. package/dist/lib/cloud/registry.d.ts +0 -16
  224. package/dist/lib/cloud/registry.d.ts.map +0 -1
  225. package/dist/lib/cloud/registry.js +0 -68
  226. package/dist/lib/cloud/registry.js.map +0 -1
  227. package/dist/lib/cloud/rush.d.ts +0 -37
  228. package/dist/lib/cloud/rush.d.ts.map +0 -1
  229. package/dist/lib/cloud/rush.js +0 -230
  230. package/dist/lib/cloud/rush.js.map +0 -1
  231. package/dist/lib/cloud/rush.test.d.ts +0 -2
  232. package/dist/lib/cloud/rush.test.d.ts.map +0 -1
  233. package/dist/lib/cloud/rush.test.js +0 -63
  234. package/dist/lib/cloud/rush.test.js.map +0 -1
  235. package/dist/lib/cloud/store.d.ts +0 -23
  236. package/dist/lib/cloud/store.d.ts.map +0 -1
  237. package/dist/lib/cloud/store.js +0 -116
  238. package/dist/lib/cloud/store.js.map +0 -1
  239. package/dist/lib/cloud/stream.d.ts +0 -24
  240. package/dist/lib/cloud/stream.d.ts.map +0 -1
  241. package/dist/lib/cloud/stream.js +0 -145
  242. package/dist/lib/cloud/stream.js.map +0 -1
  243. package/dist/lib/cloud/types.d.ts +0 -109
  244. package/dist/lib/cloud/types.d.ts.map +0 -1
  245. package/dist/lib/cloud/types.js +0 -33
  246. package/dist/lib/cloud/types.js.map +0 -1
  247. package/dist/lib/cloud/types.test.d.ts +0 -2
  248. package/dist/lib/cloud/types.test.d.ts.map +0 -1
  249. package/dist/lib/cloud/types.test.js +0 -41
  250. package/dist/lib/cloud/types.test.js.map +0 -1
  251. package/dist/lib/commands.d.ts +0 -141
  252. package/dist/lib/commands.d.ts.map +0 -1
  253. package/dist/lib/commands.js +0 -514
  254. package/dist/lib/commands.js.map +0 -1
  255. package/dist/lib/convert.d.ts +0 -21
  256. package/dist/lib/convert.d.ts.map +0 -1
  257. package/dist/lib/convert.js +0 -54
  258. package/dist/lib/convert.js.map +0 -1
  259. package/dist/lib/daemon.d.ts +0 -43
  260. package/dist/lib/daemon.d.ts.map +0 -1
  261. package/dist/lib/daemon.js +0 -332
  262. package/dist/lib/daemon.js.map +0 -1
  263. package/dist/lib/drive-sync.d.ts +0 -46
  264. package/dist/lib/drive-sync.d.ts.map +0 -1
  265. package/dist/lib/drive-sync.js +0 -209
  266. package/dist/lib/drive-sync.js.map +0 -1
  267. package/dist/lib/exec.d.ts +0 -101
  268. package/dist/lib/exec.d.ts.map +0 -1
  269. package/dist/lib/exec.js +0 -450
  270. package/dist/lib/exec.js.map +0 -1
  271. package/dist/lib/factory/__tests__/config.test.d.ts +0 -2
  272. package/dist/lib/factory/__tests__/config.test.d.ts.map +0 -1
  273. package/dist/lib/factory/__tests__/config.test.js +0 -128
  274. package/dist/lib/factory/__tests__/config.test.js.map +0 -1
  275. package/dist/lib/factory/config.d.ts +0 -49
  276. package/dist/lib/factory/config.d.ts.map +0 -1
  277. package/dist/lib/factory/config.js +0 -127
  278. package/dist/lib/factory/config.js.map +0 -1
  279. package/dist/lib/factory.d.ts +0 -57
  280. package/dist/lib/factory.d.ts.map +0 -1
  281. package/dist/lib/factory.js +0 -107
  282. package/dist/lib/factory.js.map +0 -1
  283. package/dist/lib/git.d.ts +0 -157
  284. package/dist/lib/git.d.ts.map +0 -1
  285. package/dist/lib/git.js +0 -647
  286. package/dist/lib/git.js.map +0 -1
  287. package/dist/lib/help.d.ts +0 -10
  288. package/dist/lib/help.d.ts.map +0 -1
  289. package/dist/lib/help.js +0 -66
  290. package/dist/lib/help.js.map +0 -1
  291. package/dist/lib/hooks.d.ts +0 -125
  292. package/dist/lib/hooks.d.ts.map +0 -1
  293. package/dist/lib/hooks.js +0 -846
  294. package/dist/lib/hooks.js.map +0 -1
  295. package/dist/lib/ledger/__tests__/local.test.d.ts +0 -2
  296. package/dist/lib/ledger/__tests__/local.test.d.ts.map +0 -1
  297. package/dist/lib/ledger/__tests__/local.test.js +0 -177
  298. package/dist/lib/ledger/__tests__/local.test.js.map +0 -1
  299. package/dist/lib/ledger/__tests__/sync.test.d.ts +0 -2
  300. package/dist/lib/ledger/__tests__/sync.test.d.ts.map +0 -1
  301. package/dist/lib/ledger/__tests__/sync.test.js +0 -117
  302. package/dist/lib/ledger/__tests__/sync.test.js.map +0 -1
  303. package/dist/lib/ledger/index.d.ts +0 -18
  304. package/dist/lib/ledger/index.d.ts.map +0 -1
  305. package/dist/lib/ledger/index.js +0 -32
  306. package/dist/lib/ledger/index.js.map +0 -1
  307. package/dist/lib/ledger/local.d.ts +0 -22
  308. package/dist/lib/ledger/local.d.ts.map +0 -1
  309. package/dist/lib/ledger/local.js +0 -333
  310. package/dist/lib/ledger/local.js.map +0 -1
  311. package/dist/lib/ledger/r2.d.ts +0 -41
  312. package/dist/lib/ledger/r2.d.ts.map +0 -1
  313. package/dist/lib/ledger/r2.js +0 -335
  314. package/dist/lib/ledger/r2.js.map +0 -1
  315. package/dist/lib/ledger/sync.d.ts +0 -33
  316. package/dist/lib/ledger/sync.d.ts.map +0 -1
  317. package/dist/lib/ledger/sync.js +0 -106
  318. package/dist/lib/ledger/sync.js.map +0 -1
  319. package/dist/lib/ledger/types.d.ts +0 -100
  320. package/dist/lib/ledger/types.d.ts.map +0 -1
  321. package/dist/lib/ledger/types.js +0 -21
  322. package/dist/lib/ledger/types.js.map +0 -1
  323. package/dist/lib/manifest.d.ts +0 -14
  324. package/dist/lib/manifest.d.ts.map +0 -1
  325. package/dist/lib/manifest.js +0 -48
  326. package/dist/lib/manifest.js.map +0 -1
  327. package/dist/lib/markdown.d.ts +0 -5
  328. package/dist/lib/markdown.d.ts.map +0 -1
  329. package/dist/lib/markdown.js +0 -17
  330. package/dist/lib/markdown.js.map +0 -1
  331. package/dist/lib/mcp.d.ts +0 -64
  332. package/dist/lib/mcp.d.ts.map +0 -1
  333. package/dist/lib/mcp.js +0 -327
  334. package/dist/lib/mcp.js.map +0 -1
  335. package/dist/lib/memory-compile.d.ts +0 -65
  336. package/dist/lib/memory-compile.d.ts.map +0 -1
  337. package/dist/lib/memory-compile.js +0 -174
  338. package/dist/lib/memory-compile.js.map +0 -1
  339. package/dist/lib/memory.d.ts +0 -64
  340. package/dist/lib/memory.d.ts.map +0 -1
  341. package/dist/lib/memory.js +0 -275
  342. package/dist/lib/memory.js.map +0 -1
  343. package/dist/lib/models.d.ts +0 -98
  344. package/dist/lib/models.d.ts.map +0 -1
  345. package/dist/lib/models.js +0 -728
  346. package/dist/lib/models.js.map +0 -1
  347. package/dist/lib/permissions.d.ts +0 -227
  348. package/dist/lib/permissions.d.ts.map +0 -1
  349. package/dist/lib/permissions.js +0 -1071
  350. package/dist/lib/permissions.js.map +0 -1
  351. package/dist/lib/picker.d.ts +0 -27
  352. package/dist/lib/picker.d.ts.map +0 -1
  353. package/dist/lib/picker.js +0 -110
  354. package/dist/lib/picker.js.map +0 -1
  355. package/dist/lib/plugins.d.ts +0 -80
  356. package/dist/lib/plugins.d.ts.map +0 -1
  357. package/dist/lib/plugins.js +0 -556
  358. package/dist/lib/plugins.js.map +0 -1
  359. package/dist/lib/profiles-keychain.d.ts +0 -11
  360. package/dist/lib/profiles-keychain.d.ts.map +0 -1
  361. package/dist/lib/profiles-keychain.js +0 -14
  362. package/dist/lib/profiles-keychain.js.map +0 -1
  363. package/dist/lib/profiles-presets.d.ts +0 -25
  364. package/dist/lib/profiles-presets.d.ts.map +0 -1
  365. package/dist/lib/profiles-presets.js +0 -104
  366. package/dist/lib/profiles-presets.js.map +0 -1
  367. package/dist/lib/profiles.d.ts +0 -70
  368. package/dist/lib/profiles.d.ts.map +0 -1
  369. package/dist/lib/profiles.js +0 -145
  370. package/dist/lib/profiles.js.map +0 -1
  371. package/dist/lib/pty-client.d.ts +0 -23
  372. package/dist/lib/pty-client.d.ts.map +0 -1
  373. package/dist/lib/pty-client.js +0 -181
  374. package/dist/lib/pty-client.js.map +0 -1
  375. package/dist/lib/pty-server.d.ts +0 -21
  376. package/dist/lib/pty-server.d.ts.map +0 -1
  377. package/dist/lib/pty-server.js +0 -427
  378. package/dist/lib/pty-server.js.map +0 -1
  379. package/dist/lib/registry.d.ts +0 -45
  380. package/dist/lib/registry.d.ts.map +0 -1
  381. package/dist/lib/registry.js +0 -220
  382. package/dist/lib/registry.js.map +0 -1
  383. package/dist/lib/resources.d.ts +0 -55
  384. package/dist/lib/resources.d.ts.map +0 -1
  385. package/dist/lib/resources.js +0 -103
  386. package/dist/lib/resources.js.map +0 -1
  387. package/dist/lib/rotate.d.ts +0 -58
  388. package/dist/lib/rotate.d.ts.map +0 -1
  389. package/dist/lib/rotate.js +0 -93
  390. package/dist/lib/rotate.js.map +0 -1
  391. package/dist/lib/routines.d.ts +0 -99
  392. package/dist/lib/routines.d.ts.map +0 -1
  393. package/dist/lib/routines.js +0 -352
  394. package/dist/lib/routines.js.map +0 -1
  395. package/dist/lib/runner.d.ts +0 -26
  396. package/dist/lib/runner.d.ts.map +0 -1
  397. package/dist/lib/runner.js +0 -325
  398. package/dist/lib/runner.js.map +0 -1
  399. package/dist/lib/sandbox.d.ts +0 -26
  400. package/dist/lib/sandbox.d.ts.map +0 -1
  401. package/dist/lib/sandbox.js +0 -218
  402. package/dist/lib/sandbox.js.map +0 -1
  403. package/dist/lib/scheduler.d.ts +0 -26
  404. package/dist/lib/scheduler.d.ts.map +0 -1
  405. package/dist/lib/scheduler.js +0 -77
  406. package/dist/lib/scheduler.js.map +0 -1
  407. package/dist/lib/secrets-bundles.d.ts +0 -38
  408. package/dist/lib/secrets-bundles.d.ts.map +0 -1
  409. package/dist/lib/secrets-bundles.js +0 -176
  410. package/dist/lib/secrets-bundles.js.map +0 -1
  411. package/dist/lib/secrets.d.ts +0 -53
  412. package/dist/lib/secrets.d.ts.map +0 -1
  413. package/dist/lib/secrets.js +0 -140
  414. package/dist/lib/secrets.js.map +0 -1
  415. package/dist/lib/session/__tests__/db.test.d.ts +0 -2
  416. package/dist/lib/session/__tests__/db.test.d.ts.map +0 -1
  417. package/dist/lib/session/__tests__/db.test.js +0 -54
  418. package/dist/lib/session/__tests__/db.test.js.map +0 -1
  419. package/dist/lib/session/__tests__/discover.test.d.ts +0 -2
  420. package/dist/lib/session/__tests__/discover.test.d.ts.map +0 -1
  421. package/dist/lib/session/__tests__/discover.test.js +0 -63
  422. package/dist/lib/session/__tests__/discover.test.js.map +0 -1
  423. package/dist/lib/session/__tests__/prompt.test.d.ts +0 -2
  424. package/dist/lib/session/__tests__/prompt.test.d.ts.map +0 -1
  425. package/dist/lib/session/__tests__/prompt.test.js +0 -44
  426. package/dist/lib/session/__tests__/prompt.test.js.map +0 -1
  427. package/dist/lib/session/__tests__/render.test.d.ts +0 -2
  428. package/dist/lib/session/__tests__/render.test.d.ts.map +0 -1
  429. package/dist/lib/session/__tests__/render.test.js +0 -602
  430. package/dist/lib/session/__tests__/render.test.js.map +0 -1
  431. package/dist/lib/session/active.d.ts +0 -44
  432. package/dist/lib/session/active.d.ts.map +0 -1
  433. package/dist/lib/session/active.js +0 -379
  434. package/dist/lib/session/active.js.map +0 -1
  435. package/dist/lib/session/artifacts.d.ts +0 -15
  436. package/dist/lib/session/artifacts.d.ts.map +0 -1
  437. package/dist/lib/session/artifacts.js +0 -86
  438. package/dist/lib/session/artifacts.js.map +0 -1
  439. package/dist/lib/session/db.d.ts +0 -140
  440. package/dist/lib/session/db.d.ts.map +0 -1
  441. package/dist/lib/session/db.js +0 -599
  442. package/dist/lib/session/db.js.map +0 -1
  443. package/dist/lib/session/discover.d.ts +0 -72
  444. package/dist/lib/session/discover.d.ts.map +0 -1
  445. package/dist/lib/session/discover.js +0 -1315
  446. package/dist/lib/session/discover.js.map +0 -1
  447. package/dist/lib/session/parse.d.ts +0 -34
  448. package/dist/lib/session/parse.d.ts.map +0 -1
  449. package/dist/lib/session/parse.js +0 -663
  450. package/dist/lib/session/parse.js.map +0 -1
  451. package/dist/lib/session/prompt.d.ts +0 -13
  452. package/dist/lib/session/prompt.d.ts.map +0 -1
  453. package/dist/lib/session/prompt.js +0 -79
  454. package/dist/lib/session/prompt.js.map +0 -1
  455. package/dist/lib/session/prompt.test.d.ts +0 -2
  456. package/dist/lib/session/prompt.test.d.ts.map +0 -1
  457. package/dist/lib/session/prompt.test.js +0 -57
  458. package/dist/lib/session/prompt.test.js.map +0 -1
  459. package/dist/lib/session/render.d.ts +0 -103
  460. package/dist/lib/session/render.d.ts.map +0 -1
  461. package/dist/lib/session/render.js +0 -798
  462. package/dist/lib/session/render.js.map +0 -1
  463. package/dist/lib/session/team-filter.d.ts +0 -35
  464. package/dist/lib/session/team-filter.d.ts.map +0 -1
  465. package/dist/lib/session/team-filter.js +0 -75
  466. package/dist/lib/session/team-filter.js.map +0 -1
  467. package/dist/lib/session/team-filter.test.d.ts +0 -2
  468. package/dist/lib/session/team-filter.test.d.ts.map +0 -1
  469. package/dist/lib/session/team-filter.test.js +0 -157
  470. package/dist/lib/session/team-filter.test.js.map +0 -1
  471. package/dist/lib/session/types.d.ts +0 -84
  472. package/dist/lib/session/types.d.ts.map +0 -1
  473. package/dist/lib/session/types.js +0 -11
  474. package/dist/lib/session/types.js.map +0 -1
  475. package/dist/lib/shims.d.ts +0 -272
  476. package/dist/lib/shims.d.ts.map +0 -1
  477. package/dist/lib/shims.js +0 -1322
  478. package/dist/lib/shims.js.map +0 -1
  479. package/dist/lib/skills.d.ts +0 -142
  480. package/dist/lib/skills.d.ts.map +0 -1
  481. package/dist/lib/skills.js +0 -791
  482. package/dist/lib/skills.js.map +0 -1
  483. package/dist/lib/state.d.ts +0 -87
  484. package/dist/lib/state.d.ts.map +0 -1
  485. package/dist/lib/state.js +0 -333
  486. package/dist/lib/state.js.map +0 -1
  487. package/dist/lib/subagents.d.ts +0 -84
  488. package/dist/lib/subagents.d.ts.map +0 -1
  489. package/dist/lib/subagents.js +0 -410
  490. package/dist/lib/subagents.js.map +0 -1
  491. package/dist/lib/teams/__tests__/oracle.test.d.ts +0 -2
  492. package/dist/lib/teams/__tests__/oracle.test.d.ts.map +0 -1
  493. package/dist/lib/teams/__tests__/oracle.test.js +0 -89
  494. package/dist/lib/teams/__tests__/oracle.test.js.map +0 -1
  495. package/dist/lib/teams/__tests__/supervisor.test.d.ts +0 -2
  496. package/dist/lib/teams/__tests__/supervisor.test.d.ts.map +0 -1
  497. package/dist/lib/teams/__tests__/supervisor.test.js +0 -179
  498. package/dist/lib/teams/__tests__/supervisor.test.js.map +0 -1
  499. package/dist/lib/teams/agents.d.ts +0 -247
  500. package/dist/lib/teams/agents.d.ts.map +0 -1
  501. package/dist/lib/teams/agents.js +0 -1244
  502. package/dist/lib/teams/agents.js.map +0 -1
  503. package/dist/lib/teams/api.d.ts +0 -91
  504. package/dist/lib/teams/api.d.ts.map +0 -1
  505. package/dist/lib/teams/api.js +0 -239
  506. package/dist/lib/teams/api.js.map +0 -1
  507. package/dist/lib/teams/cloud.d.ts +0 -11
  508. package/dist/lib/teams/cloud.d.ts.map +0 -1
  509. package/dist/lib/teams/cloud.js +0 -169
  510. package/dist/lib/teams/cloud.js.map +0 -1
  511. package/dist/lib/teams/debug.d.ts +0 -8
  512. package/dist/lib/teams/debug.d.ts.map +0 -1
  513. package/dist/lib/teams/debug.js +0 -12
  514. package/dist/lib/teams/debug.js.map +0 -1
  515. package/dist/lib/teams/file_ops.d.ts +0 -13
  516. package/dist/lib/teams/file_ops.d.ts.map +0 -1
  517. package/dist/lib/teams/file_ops.js +0 -66
  518. package/dist/lib/teams/file_ops.js.map +0 -1
  519. package/dist/lib/teams/index.d.ts +0 -16
  520. package/dist/lib/teams/index.d.ts.map +0 -1
  521. package/dist/lib/teams/index.js +0 -15
  522. package/dist/lib/teams/index.js.map +0 -1
  523. package/dist/lib/teams/oracle.d.ts +0 -20
  524. package/dist/lib/teams/oracle.d.ts.map +0 -1
  525. package/dist/lib/teams/oracle.js +0 -59
  526. package/dist/lib/teams/oracle.js.map +0 -1
  527. package/dist/lib/teams/parsers.d.ts +0 -9
  528. package/dist/lib/teams/parsers.d.ts.map +0 -1
  529. package/dist/lib/teams/parsers.js +0 -837
  530. package/dist/lib/teams/parsers.js.map +0 -1
  531. package/dist/lib/teams/persistence.d.ts +0 -43
  532. package/dist/lib/teams/persistence.d.ts.map +0 -1
  533. package/dist/lib/teams/persistence.js +0 -299
  534. package/dist/lib/teams/persistence.js.map +0 -1
  535. package/dist/lib/teams/ralph.d.ts +0 -8
  536. package/dist/lib/teams/ralph.d.ts.map +0 -1
  537. package/dist/lib/teams/ralph.js +0 -59
  538. package/dist/lib/teams/ralph.js.map +0 -1
  539. package/dist/lib/teams/registry.d.ts +0 -18
  540. package/dist/lib/teams/registry.d.ts.map +0 -1
  541. package/dist/lib/teams/registry.js +0 -68
  542. package/dist/lib/teams/registry.js.map +0 -1
  543. package/dist/lib/teams/summarizer.d.ts +0 -73
  544. package/dist/lib/teams/summarizer.d.ts.map +0 -1
  545. package/dist/lib/teams/summarizer.js +0 -780
  546. package/dist/lib/teams/summarizer.js.map +0 -1
  547. package/dist/lib/teams/supervisor.d.ts +0 -49
  548. package/dist/lib/teams/supervisor.d.ts.map +0 -1
  549. package/dist/lib/teams/supervisor.js +0 -74
  550. package/dist/lib/teams/supervisor.js.map +0 -1
  551. package/dist/lib/template.d.ts +0 -27
  552. package/dist/lib/template.d.ts.map +0 -1
  553. package/dist/lib/template.js +0 -60
  554. package/dist/lib/template.js.map +0 -1
  555. package/dist/lib/types.d.ts +0 -331
  556. package/dist/lib/types.d.ts.map +0 -1
  557. package/dist/lib/types.js +0 -29
  558. package/dist/lib/types.js.map +0 -1
  559. package/dist/lib/usage.d.ts +0 -105
  560. package/dist/lib/usage.d.ts.map +0 -1
  561. package/dist/lib/usage.js +0 -686
  562. package/dist/lib/usage.js.map +0 -1
  563. package/dist/lib/versions.d.ts +0 -253
  564. package/dist/lib/versions.d.ts.map +0 -1
  565. package/dist/lib/versions.js +0 -1796
  566. package/dist/lib/versions.js.map +0 -1
  567. package/scripts/rebuild-sqlite.sh +0 -46
package/dist/lib/usage.js DELETED
@@ -1,686 +0,0 @@
1
- /**
2
- * Usage and rate-limit tracking for Claude and Codex agents.
3
- *
4
- * Fetches live usage data from the Anthropic OAuth API (Claude) or parses
5
- * rate-limit events from Codex session logs. Results are normalized into a
6
- * common UsageSnapshot shape, cached to disk, and rendered as terminal
7
- * progress bars for the `agents view` and `agents status` commands.
8
- */
9
- import { execFile } from 'child_process';
10
- import { createHash } from 'crypto';
11
- import * as fs from 'fs';
12
- import * as os from 'os';
13
- import * as path from 'path';
14
- import * as readline from 'readline';
15
- import { promisify } from 'util';
16
- import chalk from 'chalk';
17
- import { getAgentsDir } from './state.js';
18
- import { walkForFiles } from './session/discover.js';
19
- const execFileAsync = promisify(execFile);
20
- const CLAUDE_USAGE_URL = 'https://api.anthropic.com/api/oauth/usage';
21
- const CLAUDE_TOKEN_URL = 'https://platform.claude.com/v1/oauth/token';
22
- const CLAUDE_CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e';
23
- const CLAUDE_OAUTH_BETA_HEADER = 'oauth-2025-04-20';
24
- const CLAUDE_REFRESH_LEEWAY_MS = 5 * 60 * 1000;
25
- const CLAUDE_SCOPES = [
26
- 'user:profile',
27
- 'user:inference',
28
- 'user:sessions:claude_code',
29
- 'user:mcp_servers',
30
- 'user:file_upload',
31
- ];
32
- const CLAUDE_KEYCHAIN_SERVICE = 'Claude Code-credentials';
33
- const getClaudeUsageCachePath = () => path.join(getAgentsDir(), 'cache', 'claude-usage.json');
34
- const CACHED_CLAUDE_USAGE_SOURCE_LABEL = 'last seen live account data';
35
- const COMPACT_BAR_LEN = 5;
36
- const USAGE_BAR_LEN = 10;
37
- const FULL = '\u2588';
38
- const EMPTY = '\u2591';
39
- /** Fetch usage info for a given agent, dispatching to the agent-specific implementation. */
40
- export async function getUsageInfo(agentId, options) {
41
- switch (agentId) {
42
- case 'claude':
43
- return getClaudeUsageInfo(options);
44
- case 'codex':
45
- return getCodexUsageInfo(options);
46
- default:
47
- return { snapshot: null, error: null };
48
- }
49
- }
50
- /** Derive a stable lookup key from account info for usage deduplication. */
51
- export function getUsageLookupKey(info) {
52
- return info?.usageKey || info?.accountKey || null;
53
- }
54
- /**
55
- * Deduplicate identity inputs into canonical (most-recently-active) accounts
56
- * and build the corresponding fetch inputs for each unique usage key.
57
- */
58
- export function buildCanonicalUsageContext(inputs) {
59
- const canonicalByUsageKey = new Map();
60
- const usageFetchInputs = new Map();
61
- for (const input of inputs) {
62
- const key = getUsageLookupKey(input.info);
63
- if (!key)
64
- continue;
65
- const existing = canonicalByUsageKey.get(key);
66
- const existingMs = existing?.lastActive?.getTime() ?? -1;
67
- const currentMs = input.info.lastActive?.getTime() ?? -1;
68
- if (existing && existingMs >= currentMs) {
69
- continue;
70
- }
71
- canonicalByUsageKey.set(key, input.info);
72
- usageFetchInputs.set(key, {
73
- agentId: input.agentId,
74
- home: input.home,
75
- cliVersion: input.cliVersion || null,
76
- organizationId: input.info.organizationId,
77
- });
78
- }
79
- return { canonicalByUsageKey, usageFetchInputs };
80
- }
81
- /** Fetch usage info for all unique accounts in parallel, keyed by usage key. */
82
- export async function getUsageInfoByIdentity(inputs) {
83
- const { canonicalByUsageKey, usageFetchInputs } = buildCanonicalUsageContext(inputs);
84
- const usageResults = await Promise.all([...usageFetchInputs.entries()].map(async ([key, input]) => ({
85
- key,
86
- usage: await getUsageInfoForIdentity({
87
- agentId: input.agentId,
88
- home: input.home,
89
- cliVersion: input.cliVersion,
90
- info: canonicalByUsageKey.get(key),
91
- }),
92
- })));
93
- return {
94
- canonicalByUsageKey,
95
- usageByKey: new Map(usageResults.map(({ key, usage }) => [key, usage])),
96
- };
97
- }
98
- const USAGE_CACHE_FRESH_MS = 2 * 60 * 1000; // 2 minutes
99
- /**
100
- * Fetch usage for a single identity, with a 2-minute cache fast path.
101
- * Falls back to cached data when the live fetch fails.
102
- */
103
- export async function getUsageInfoForIdentity(input) {
104
- const usageKey = getUsageLookupKey(input.info);
105
- // Fast path: serve from cache if fresh. Skips the network call entirely.
106
- if (input.agentId === 'claude' && usageKey) {
107
- const cached = readClaudeUsageCache(usageKey);
108
- if (cached?.capturedAt) {
109
- const ageMs = Date.now() - cached.capturedAt.getTime();
110
- if (ageMs < USAGE_CACHE_FRESH_MS) {
111
- return { snapshot: cached, error: null };
112
- }
113
- }
114
- }
115
- // Cache miss or stale -- make the network call.
116
- const usage = await getUsageInfo(input.agentId, {
117
- home: input.home,
118
- cliVersion: input.cliVersion,
119
- organizationId: input.info.organizationId,
120
- });
121
- if (input.agentId !== 'claude' || !usageKey) {
122
- return usage;
123
- }
124
- if (usage.snapshot?.source === 'live') {
125
- writeClaudeUsageCache(usageKey, usage.snapshot);
126
- return usage;
127
- }
128
- const cached = readClaudeUsageCache(usageKey);
129
- if (cached) {
130
- return { snapshot: cached, error: usage.error };
131
- }
132
- return usage;
133
- }
134
- /** Format a one-line usage summary with compact bars for inline display. */
135
- export function formatUsageSummary(plan, snapshot, planWidth = 3) {
136
- const parts = [];
137
- if (plan) {
138
- parts.push(chalk.gray(plan.padEnd(planWidth)));
139
- }
140
- if (snapshot) {
141
- const windows = snapshot.windows
142
- .filter((window) => window.key !== 'sonnet_week')
143
- .map((window) => `${chalk.gray(`${window.shortLabel}:`)} ${renderCompactUsageBar(window.usedPercent)}`);
144
- if (windows.length > 0) {
145
- parts.push(windows.join(' '));
146
- }
147
- }
148
- return parts.join(' ');
149
- }
150
- /** Format a multi-line usage section for detailed agent views. */
151
- export function formatUsageSection(usage) {
152
- if (!usage.snapshot && !usage.error) {
153
- return [];
154
- }
155
- const lines = [' Usage', ''];
156
- if (!usage.snapshot) {
157
- lines.push(` ${chalk.dim(usage.error || 'Usage data unavailable right now.')}`);
158
- return lines;
159
- }
160
- const labelWidth = usage.snapshot.windows.reduce((max, window) => Math.max(max, window.label.length), 0);
161
- for (const window of usage.snapshot.windows) {
162
- const bar = renderUsageBar(window.usedPercent);
163
- lines.push(` ${chalk.bold(window.label.padEnd(labelWidth))} ${bar} ${formatPercent(window.usedPercent)}% used`);
164
- if (window.resetsAt) {
165
- lines.push(` ${chalk.dim(`Resets ${formatResetAt(window.resetsAt)}`)}`);
166
- }
167
- lines.push('');
168
- }
169
- if (lines[lines.length - 1] === '') {
170
- lines.pop();
171
- }
172
- lines.push(` ${chalk.dim(`Source: ${usage.snapshot.sourceLabel}`)}`);
173
- return lines;
174
- }
175
- /** Fetch Codex usage by scanning the most recent session files for rate-limit events. */
176
- async function getCodexUsageInfo(options) {
177
- try {
178
- const files = collectCodexSessionFiles(options?.home);
179
- for (const filePath of files) {
180
- const match = await readLatestCodexRateLimits(filePath);
181
- if (!match)
182
- continue;
183
- const windows = normalizeCodexWindows(match.rateLimits);
184
- if (windows.length === 0)
185
- continue;
186
- return {
187
- snapshot: {
188
- source: 'last_seen',
189
- sourceLabel: 'last seen in latest Codex session',
190
- capturedAt: match.capturedAt,
191
- windows,
192
- },
193
- error: null,
194
- };
195
- }
196
- return { snapshot: null, error: null };
197
- }
198
- catch {
199
- return { snapshot: null, error: null };
200
- }
201
- }
202
- /** Fetch Claude usage via the Anthropic OAuth usage API. */
203
- async function getClaudeUsageInfo(options) {
204
- try {
205
- const oauth = await loadClaudeOauth(options?.home);
206
- if (!oauth?.accessToken) {
207
- return { snapshot: null, error: null };
208
- }
209
- const requestedOrgId = normalizeString(options?.organizationId);
210
- const liveOrgId = normalizeString(oauth.organizationUuid);
211
- if (!isClaudeUsageOrgMatch(requestedOrgId, liveOrgId)) {
212
- return { snapshot: null, error: null };
213
- }
214
- const accessToken = await getClaudeAccessToken(oauth);
215
- if (!accessToken) {
216
- return { snapshot: null, error: null };
217
- }
218
- const response = await fetch(CLAUDE_USAGE_URL, {
219
- method: 'GET',
220
- headers: {
221
- Authorization: `Bearer ${accessToken}`,
222
- 'Content-Type': 'application/json',
223
- 'anthropic-beta': CLAUDE_OAUTH_BETA_HEADER,
224
- 'User-Agent': getClaudeUserAgent(options?.cliVersion),
225
- },
226
- signal: AbortSignal.timeout(5000),
227
- });
228
- if (!response.ok) {
229
- return { snapshot: null, error: formatClaudeUsageError(response.status) };
230
- }
231
- const data = await response.json();
232
- const windows = normalizeClaudeWindows(data);
233
- if (windows.length === 0) {
234
- return { snapshot: null, error: null };
235
- }
236
- return {
237
- snapshot: {
238
- source: 'live',
239
- sourceLabel: 'live account data',
240
- capturedAt: new Date(),
241
- windows,
242
- },
243
- error: null,
244
- };
245
- }
246
- catch {
247
- return { snapshot: null, error: 'Usage data unavailable right now.' };
248
- }
249
- }
250
- /** Collect Codex JSONL session files sorted newest-first. */
251
- function collectCodexSessionFiles(home) {
252
- const base = home || os.homedir();
253
- const dir = path.join(base, '.codex', 'sessions');
254
- if (!fs.existsSync(dir))
255
- return [];
256
- const seenFiles = new Set();
257
- const files = [];
258
- for (const filePath of walkForFiles(dir, '.jsonl', 20)) {
259
- const real = safeRealpathSync(filePath) || filePath;
260
- if (seenFiles.has(real))
261
- continue;
262
- seenFiles.add(real);
263
- const stat = safeStatSync(filePath);
264
- if (!stat)
265
- continue;
266
- files.push({ path: filePath, mtime: stat.mtimeMs });
267
- }
268
- files.sort((a, b) => b.mtime - a.mtime);
269
- return files.map((file) => file.path);
270
- }
271
- /** Stream a Codex JSONL file and return the last rate_limits payload found. */
272
- async function readLatestCodexRateLimits(filePath) {
273
- return new Promise((resolve) => {
274
- let latest = null;
275
- const stream = fs.createReadStream(filePath, { encoding: 'utf-8' });
276
- const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
277
- rl.on('line', (line) => {
278
- if (!line.trim())
279
- return;
280
- try {
281
- const parsed = JSON.parse(line);
282
- if (parsed.type !== 'event_msg' || parsed.payload?.type !== 'token_count' || !parsed.payload?.rate_limits) {
283
- return;
284
- }
285
- latest = {
286
- capturedAt: parseDateValue(parsed.timestamp),
287
- rateLimits: parsed.payload.rate_limits,
288
- };
289
- }
290
- catch {
291
- /* malformed session line */
292
- }
293
- });
294
- rl.on('close', () => resolve(latest));
295
- rl.on('error', () => resolve(latest));
296
- });
297
- }
298
- /** Normalize Codex rate-limit windows into the common UsageWindow shape. */
299
- function normalizeCodexWindows(rateLimits) {
300
- const windows = [];
301
- const primary = normalizeCodexWindow(rateLimits.primary, 'session', 'Current session', 'S');
302
- if (primary)
303
- windows.push(primary);
304
- const secondary = normalizeCodexWindow(rateLimits.secondary, 'week', 'Current week', 'W');
305
- if (secondary)
306
- windows.push(secondary);
307
- return windows;
308
- }
309
- /** Normalize a single Codex rate-limit window. */
310
- function normalizeCodexWindow(window, key, label, shortLabel) {
311
- const usedPercent = normalizePercent(window?.used_percent);
312
- if (usedPercent === null)
313
- return null;
314
- return {
315
- key,
316
- label,
317
- shortLabel,
318
- usedPercent,
319
- resetsAt: parseDateValue(window?.resets_at),
320
- windowMinutes: normalizeWindowMinutes(window?.window_minutes),
321
- };
322
- }
323
- /** Normalize Claude API usage windows into the common UsageWindow shape. */
324
- function normalizeClaudeWindows(data) {
325
- const windows = [
326
- normalizeClaudeWindow(data.five_hour, 'session', 'Current session', 'S'),
327
- normalizeClaudeWindow(data.seven_day, 'week', 'Current week (all models)', 'W'),
328
- normalizeClaudeWindow(data.seven_day_sonnet, 'sonnet_week', 'Current week (Sonnet only)', 'So'),
329
- ];
330
- return windows.filter((window) => window !== null);
331
- }
332
- /** Normalize a single Claude API usage window. */
333
- function normalizeClaudeWindow(window, key, label, shortLabel) {
334
- const usedPercent = normalizePercent(window?.utilization);
335
- if (usedPercent === null)
336
- return null;
337
- return {
338
- key,
339
- label,
340
- shortLabel,
341
- usedPercent,
342
- resetsAt: parseDateValue(window?.resets_at),
343
- windowMinutes: inferWindowMinutes(key),
344
- };
345
- }
346
- /** Load Claude OAuth credentials from the macOS Keychain. */
347
- export async function loadClaudeOauth(home) {
348
- if (process.platform !== 'darwin') {
349
- return null;
350
- }
351
- try {
352
- const account = os.userInfo().username;
353
- const { stdout } = await execFileAsync('security', [
354
- 'find-generic-password',
355
- '-a',
356
- account,
357
- '-s',
358
- // Managed Claude homes must stay pinned to their own service name.
359
- getClaudeKeychainService(home),
360
- '-w',
361
- ]);
362
- const payload = JSON.parse(stdout.trim());
363
- if (!payload.claudeAiOauth) {
364
- return null;
365
- }
366
- return {
367
- ...payload.claudeAiOauth,
368
- organizationUuid: normalizeString(payload.organizationUuid),
369
- };
370
- }
371
- catch {
372
- return null;
373
- }
374
- }
375
- /**
376
- * Derive the Keychain service name for a Claude home directory.
377
- * Managed (non-default) homes get a hash suffix for isolation.
378
- */
379
- export function getClaudeKeychainService(home) {
380
- if (!home) {
381
- return CLAUDE_KEYCHAIN_SERVICE;
382
- }
383
- const configDir = path.join(home, '.claude').normalize('NFC');
384
- const hash = createHash('sha256').update(configDir).digest('hex').slice(0, 8);
385
- return `${CLAUDE_KEYCHAIN_SERVICE}-${hash}`;
386
- }
387
- /**
388
- * Check whether a requested org ID matches the live OAuth org ID.
389
- * Returns true when either is absent (no filtering) or when they match.
390
- */
391
- export function isClaudeUsageOrgMatch(requestedOrgId, liveOrgId) {
392
- const requested = normalizeString(requestedOrgId);
393
- const live = normalizeString(liveOrgId);
394
- return !requested || !live || requested === live;
395
- }
396
- /** Read a cached usage snapshot for a given usage key. Returns null if absent or stale. */
397
- export function readClaudeUsageCache(usageKey, cachePath = getClaudeUsageCachePath(), now = new Date()) {
398
- const cache = readClaudeUsageCacheFile(cachePath);
399
- const cached = cache[usageKey];
400
- if (!cached) {
401
- return null;
402
- }
403
- const snapshot = deserializeClaudeUsageSnapshot(cached, now);
404
- if (!snapshot) {
405
- delete cache[usageKey];
406
- writeClaudeUsageCacheFile(cache, cachePath);
407
- }
408
- return snapshot;
409
- }
410
- /** Write a usage snapshot to the on-disk cache. */
411
- export function writeClaudeUsageCache(usageKey, snapshot, cachePath = getClaudeUsageCachePath()) {
412
- const cache = readClaudeUsageCacheFile(cachePath);
413
- cache[usageKey] = serializeClaudeUsageSnapshot(snapshot);
414
- writeClaudeUsageCacheFile(cache, cachePath);
415
- }
416
- /** Read the entire usage cache file from disk. */
417
- function readClaudeUsageCacheFile(cachePath) {
418
- if (!fs.existsSync(cachePath)) {
419
- return {};
420
- }
421
- try {
422
- const parsed = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
423
- return parsed && typeof parsed === 'object' ? parsed : {};
424
- }
425
- catch {
426
- return {};
427
- }
428
- }
429
- /** Write the entire usage cache to disk. Best-effort; failures are silent. */
430
- function writeClaudeUsageCacheFile(cache, cachePath) {
431
- try {
432
- fs.mkdirSync(path.dirname(cachePath), { recursive: true });
433
- fs.writeFileSync(cachePath, JSON.stringify(cache, null, 2), 'utf-8');
434
- }
435
- catch {
436
- /* best-effort cache write */
437
- }
438
- }
439
- /** Convert a live UsageSnapshot to its JSON-serializable cached form. */
440
- function serializeClaudeUsageSnapshot(snapshot) {
441
- return {
442
- capturedAt: snapshot.capturedAt?.toISOString() || null,
443
- windows: snapshot.windows.map((window) => ({
444
- key: window.key,
445
- label: window.label,
446
- shortLabel: window.shortLabel,
447
- usedPercent: window.usedPercent,
448
- resetsAt: window.resetsAt?.toISOString() || null,
449
- windowMinutes: window.windowMinutes,
450
- })),
451
- };
452
- }
453
- /** Deserialize a cached snapshot, zeroing out windows whose reset time has passed. */
454
- function deserializeClaudeUsageSnapshot(snapshot, now) {
455
- const capturedAt = parseDateValue(snapshot.capturedAt);
456
- const windows = snapshot.windows
457
- .map((window) => {
458
- const w = {
459
- key: window.key,
460
- label: window.label,
461
- shortLabel: window.shortLabel,
462
- usedPercent: window.usedPercent,
463
- resetsAt: parseDateValue(window.resetsAt),
464
- windowMinutes: window.windowMinutes,
465
- };
466
- if (!isCachedUsageWindowFresh(w, capturedAt, now)) {
467
- w.usedPercent = 0;
468
- }
469
- return w;
470
- });
471
- if (windows.length === 0) {
472
- return null;
473
- }
474
- return {
475
- source: 'last_seen',
476
- sourceLabel: CACHED_CLAUDE_USAGE_SOURCE_LABEL,
477
- capturedAt,
478
- windows,
479
- };
480
- }
481
- /** Check whether a cached usage window is still relevant (not expired or reset). */
482
- function isCachedUsageWindowFresh(window, capturedAt, now) {
483
- if (window.resetsAt && window.resetsAt.getTime() <= now.getTime()) {
484
- return false;
485
- }
486
- if (capturedAt && window.windowMinutes !== null) {
487
- const expiresAt = capturedAt.getTime() + window.windowMinutes * 60 * 1000;
488
- if (expiresAt <= now.getTime()) {
489
- return false;
490
- }
491
- }
492
- return true;
493
- }
494
- /** Obtain a valid access token, refreshing if expired. */
495
- async function getClaudeAccessToken(oauth) {
496
- const accessToken = oauth.accessToken?.trim();
497
- if (!accessToken) {
498
- return null;
499
- }
500
- const expiresAt = oauth.expiresAt ?? null;
501
- if (expiresAt === null || Date.now() + CLAUDE_REFRESH_LEEWAY_MS < expiresAt) {
502
- return accessToken;
503
- }
504
- if (!oauth.refreshToken) {
505
- return null;
506
- }
507
- const refreshed = await refreshClaudeToken(oauth);
508
- return refreshed?.accessToken?.trim() || null;
509
- }
510
- /** Refresh an expired Claude OAuth access token using the refresh token. */
511
- async function refreshClaudeToken(oauth) {
512
- const response = await fetch(CLAUDE_TOKEN_URL, {
513
- method: 'POST',
514
- headers: {
515
- 'Content-Type': 'application/json',
516
- },
517
- body: JSON.stringify({
518
- grant_type: 'refresh_token',
519
- refresh_token: oauth.refreshToken,
520
- client_id: CLAUDE_CLIENT_ID,
521
- scope: (oauth.scopes?.length ? oauth.scopes : CLAUDE_SCOPES).join(' '),
522
- }),
523
- signal: AbortSignal.timeout(15000),
524
- });
525
- if (!response.ok) {
526
- return null;
527
- }
528
- const data = await response.json();
529
- if (!data.access_token || !data.expires_in) {
530
- return null;
531
- }
532
- return {
533
- accessToken: data.access_token,
534
- refreshToken: data.refresh_token || oauth.refreshToken || null,
535
- expiresAt: Date.now() + data.expires_in * 1000,
536
- scopes: data.scope ? data.scope.split(/\s+/).filter(Boolean) : (oauth.scopes || CLAUDE_SCOPES),
537
- };
538
- }
539
- /**
540
- * Check whether the Claude OAuth credentials for a given home are usable.
541
- * Attempts a token refresh if the access token is expired.
542
- * Returns true only when a valid access token can be obtained.
543
- */
544
- export async function isClaudeAuthValid(home) {
545
- const oauth = await loadClaudeOauth(home);
546
- if (!oauth)
547
- return false;
548
- const token = await getClaudeAccessToken(oauth);
549
- return token !== null;
550
- }
551
- /** Build a User-Agent string for Claude API requests. */
552
- function getClaudeUserAgent(cliVersion) {
553
- return cliVersion ? `claude-code/${cliVersion}` : 'claude-code';
554
- }
555
- /** Map an HTTP status code to a user-facing error message. */
556
- function formatClaudeUsageError(status) {
557
- if (status === 429) {
558
- return 'Usage data unavailable right now.';
559
- }
560
- return 'Could not load usage data right now.';
561
- }
562
- /** Clamp a numeric value to 0..100, returning null for non-finite values. */
563
- function normalizePercent(value) {
564
- if (typeof value !== 'number' || !Number.isFinite(value)) {
565
- return null;
566
- }
567
- return Math.max(0, Math.min(100, value));
568
- }
569
- /** Validate and return a positive window duration, or null. */
570
- function normalizeWindowMinutes(value) {
571
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
572
- return null;
573
- }
574
- return value;
575
- }
576
- /** Infer the window duration in minutes from a well-known window key. */
577
- function inferWindowMinutes(key) {
578
- switch (key) {
579
- case 'session':
580
- return 300;
581
- case 'week':
582
- case 'sonnet_week':
583
- return 10080;
584
- }
585
- }
586
- /** Parse a date value from a number (epoch seconds or ms) or ISO string. */
587
- function parseDateValue(value) {
588
- if (value === null || value === undefined || value === '') {
589
- return null;
590
- }
591
- if (typeof value === 'number' && Number.isFinite(value)) {
592
- return new Date(value < 1e12 ? value * 1000 : value);
593
- }
594
- if (typeof value === 'string') {
595
- const numeric = Number(value);
596
- if (!Number.isNaN(numeric)) {
597
- return parseDateValue(numeric);
598
- }
599
- const date = new Date(value);
600
- return Number.isNaN(date.getTime()) ? null : date;
601
- }
602
- return null;
603
- }
604
- /** Trim and return a string, or null if empty/non-string. */
605
- function normalizeString(value) {
606
- if (typeof value !== 'string')
607
- return null;
608
- const trimmed = value.trim();
609
- return trimmed || null;
610
- }
611
- /** Render a full-width usage bar for detailed views. */
612
- function renderUsageBar(usedPercent) {
613
- return renderBar(usedPercent, USAGE_BAR_LEN);
614
- }
615
- /** Render a compact usage bar for inline summaries. */
616
- function renderCompactUsageBar(usedPercent) {
617
- return renderBar(usedPercent, COMPACT_BAR_LEN, usedPercent > 0 ? 1 : 0);
618
- }
619
- /** Render a colored block-character progress bar. */
620
- function renderBar(usedPercent, length, minimumVisible = 0) {
621
- const rounded = Math.round((usedPercent / 100) * length);
622
- const filled = Math.max(minimumVisible, Math.max(0, Math.min(length, rounded)));
623
- const color = getUsageColor(usedPercent);
624
- return color(FULL.repeat(filled)) + chalk.dim(EMPTY.repeat(length - filled));
625
- }
626
- /** Apply the appropriate color to a text string based on usage percentage. */
627
- function colorUsage(text, usedPercent) {
628
- return getUsageColor(usedPercent)(text);
629
- }
630
- /** Return a chalk color function based on the usage percentage threshold. */
631
- function getUsageColor(usedPercent) {
632
- if (usedPercent >= 100)
633
- return chalk.red;
634
- if (usedPercent >= 80)
635
- return chalk.yellow;
636
- return chalk.cyan;
637
- }
638
- /** Format a percentage value with at most one decimal place. */
639
- function formatPercent(value) {
640
- const rounded = Math.round(value * 10) / 10;
641
- return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
642
- }
643
- /** Format a reset timestamp as a human-readable relative or absolute time. */
644
- function formatResetAt(date) {
645
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
646
- const now = new Date();
647
- const isWithinDay = (date.getTime() - now.getTime()) / 3600000 <= 24;
648
- const minutes = date.getMinutes();
649
- if (isWithinDay) {
650
- return `${date.toLocaleTimeString('en-US', {
651
- hour: 'numeric',
652
- minute: minutes === 0 ? undefined : '2-digit',
653
- hour12: true,
654
- })} (${timezone})`;
655
- }
656
- const options = {
657
- month: 'short',
658
- day: 'numeric',
659
- hour: 'numeric',
660
- minute: minutes === 0 ? undefined : '2-digit',
661
- hour12: true,
662
- };
663
- if (date.getFullYear() !== now.getFullYear()) {
664
- options.year = 'numeric';
665
- }
666
- return `${date.toLocaleString('en-US', options)} (${timezone})`;
667
- }
668
- /** Safe wrapper around fs.realpathSync that returns null on error. */
669
- function safeRealpathSync(filePath) {
670
- try {
671
- return fs.realpathSync(filePath);
672
- }
673
- catch {
674
- return null;
675
- }
676
- }
677
- /** Safe wrapper around fs.statSync that returns null on error. */
678
- function safeStatSync(filePath) {
679
- try {
680
- return fs.statSync(filePath);
681
- }
682
- catch {
683
- return null;
684
- }
685
- }
686
- //# sourceMappingURL=usage.js.map