@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.
- package/README.md +2 -319
- package/bin/agents.js +2 -0
- package/package.json +13 -79
- package/scripts/postinstall.js +4 -71
- package/CHANGELOG.md +0 -316
- package/LICENSE +0 -21
- package/dist/commands/__tests__/sessions-tail.test.d.ts +0 -2
- package/dist/commands/__tests__/sessions-tail.test.d.ts.map +0 -1
- package/dist/commands/__tests__/sessions-tail.test.js +0 -108
- package/dist/commands/__tests__/sessions-tail.test.js.map +0 -1
- package/dist/commands/__tests__/sessions.test.d.ts +0 -2
- package/dist/commands/__tests__/sessions.test.d.ts.map +0 -1
- package/dist/commands/__tests__/sessions.test.js +0 -636
- package/dist/commands/__tests__/sessions.test.js.map +0 -1
- package/dist/commands/cloud.d.ts +0 -11
- package/dist/commands/cloud.d.ts.map +0 -1
- package/dist/commands/cloud.js +0 -363
- package/dist/commands/cloud.js.map +0 -1
- package/dist/commands/commands.d.ts +0 -12
- package/dist/commands/commands.d.ts.map +0 -1
- package/dist/commands/commands.js +0 -629
- package/dist/commands/commands.js.map +0 -1
- package/dist/commands/daemon.d.ts +0 -11
- package/dist/commands/daemon.d.ts.map +0 -1
- package/dist/commands/daemon.js +0 -119
- package/dist/commands/daemon.js.map +0 -1
- package/dist/commands/drive.d.ts +0 -11
- package/dist/commands/drive.d.ts.map +0 -1
- package/dist/commands/drive.js +0 -175
- package/dist/commands/drive.js.map +0 -1
- package/dist/commands/exec.d.ts +0 -11
- package/dist/commands/exec.d.ts.map +0 -1
- package/dist/commands/exec.js +0 -251
- package/dist/commands/exec.js.map +0 -1
- package/dist/commands/factory.d.ts +0 -11
- package/dist/commands/factory.d.ts.map +0 -1
- package/dist/commands/factory.js +0 -445
- package/dist/commands/factory.js.map +0 -1
- package/dist/commands/fork.d.ts +0 -11
- package/dist/commands/fork.d.ts.map +0 -1
- package/dist/commands/fork.js +0 -147
- package/dist/commands/fork.js.map +0 -1
- package/dist/commands/hooks.d.ts +0 -12
- package/dist/commands/hooks.d.ts.map +0 -1
- package/dist/commands/hooks.js +0 -690
- package/dist/commands/hooks.js.map +0 -1
- package/dist/commands/init.d.ts +0 -15
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -137
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -12
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js +0 -583
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/models.d.ts +0 -11
- package/dist/commands/models.d.ts.map +0 -1
- package/dist/commands/models.js +0 -170
- package/dist/commands/models.js.map +0 -1
- package/dist/commands/packages.d.ts +0 -11
- package/dist/commands/packages.d.ts.map +0 -1
- package/dist/commands/packages.js +0 -551
- package/dist/commands/packages.js.map +0 -1
- package/dist/commands/permissions.d.ts +0 -12
- package/dist/commands/permissions.d.ts.map +0 -1
- package/dist/commands/permissions.js +0 -724
- package/dist/commands/permissions.js.map +0 -1
- package/dist/commands/plugins.d.ts +0 -11
- package/dist/commands/plugins.d.ts.map +0 -1
- package/dist/commands/plugins.js +0 -393
- package/dist/commands/plugins.js.map +0 -1
- package/dist/commands/profiles.d.ts +0 -12
- package/dist/commands/profiles.d.ts.map +0 -1
- package/dist/commands/profiles.js +0 -255
- package/dist/commands/profiles.js.map +0 -1
- package/dist/commands/pty.d.ts +0 -21
- package/dist/commands/pty.d.ts.map +0 -1
- package/dist/commands/pty.js +0 -391
- package/dist/commands/pty.js.map +0 -1
- package/dist/commands/pull.d.ts +0 -11
- package/dist/commands/pull.d.ts.map +0 -1
- package/dist/commands/pull.js +0 -456
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/push.d.ts +0 -11
- package/dist/commands/push.d.ts.map +0 -1
- package/dist/commands/push.js +0 -188
- package/dist/commands/push.js.map +0 -1
- package/dist/commands/refresh-memory.d.ts +0 -16
- package/dist/commands/refresh-memory.d.ts.map +0 -1
- package/dist/commands/refresh-memory.js +0 -52
- package/dist/commands/refresh-memory.js.map +0 -1
- package/dist/commands/resource-view.d.ts +0 -39
- package/dist/commands/resource-view.d.ts.map +0 -1
- package/dist/commands/resource-view.js +0 -197
- package/dist/commands/resource-view.js.map +0 -1
- package/dist/commands/routines.d.ts +0 -11
- package/dist/commands/routines.d.ts.map +0 -1
- package/dist/commands/routines.js +0 -590
- package/dist/commands/routines.js.map +0 -1
- package/dist/commands/rules.d.ts +0 -12
- package/dist/commands/rules.d.ts.map +0 -1
- package/dist/commands/rules.js +0 -489
- package/dist/commands/rules.js.map +0 -1
- package/dist/commands/secrets.d.ts +0 -11
- package/dist/commands/secrets.d.ts.map +0 -1
- package/dist/commands/secrets.js +0 -352
- package/dist/commands/secrets.js.map +0 -1
- package/dist/commands/sessions-picker.d.ts +0 -18
- package/dist/commands/sessions-picker.d.ts.map +0 -1
- package/dist/commands/sessions-picker.js +0 -265
- package/dist/commands/sessions-picker.js.map +0 -1
- package/dist/commands/sessions-tail.d.ts +0 -20
- package/dist/commands/sessions-tail.d.ts.map +0 -1
- package/dist/commands/sessions-tail.js +0 -236
- package/dist/commands/sessions-tail.js.map +0 -1
- package/dist/commands/sessions.d.ts +0 -18
- package/dist/commands/sessions.d.ts.map +0 -1
- package/dist/commands/sessions.js +0 -1173
- package/dist/commands/sessions.js.map +0 -1
- package/dist/commands/skills.d.ts +0 -12
- package/dist/commands/skills.d.ts.map +0 -1
- package/dist/commands/skills.js +0 -717
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/status.d.ts +0 -10
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -26
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/subagents.d.ts +0 -11
- package/dist/commands/subagents.d.ts.map +0 -1
- package/dist/commands/subagents.js +0 -361
- package/dist/commands/subagents.js.map +0 -1
- package/dist/commands/sync.d.ts +0 -11
- package/dist/commands/sync.d.ts.map +0 -1
- package/dist/commands/sync.js +0 -70
- package/dist/commands/sync.js.map +0 -1
- package/dist/commands/teams-picker.d.ts +0 -18
- package/dist/commands/teams-picker.d.ts.map +0 -1
- package/dist/commands/teams-picker.js +0 -290
- package/dist/commands/teams-picker.js.map +0 -1
- package/dist/commands/teams.d.ts +0 -18
- package/dist/commands/teams.d.ts.map +0 -1
- package/dist/commands/teams.js +0 -1144
- package/dist/commands/teams.js.map +0 -1
- package/dist/commands/utils.d.ts +0 -45
- package/dist/commands/utils.d.ts.map +0 -1
- package/dist/commands/utils.js +0 -106
- package/dist/commands/utils.js.map +0 -1
- package/dist/commands/versions.d.ts +0 -11
- package/dist/commands/versions.d.ts.map +0 -1
- package/dist/commands/versions.js +0 -701
- package/dist/commands/versions.js.map +0 -1
- package/dist/commands/view.d.ts +0 -43
- package/dist/commands/view.d.ts.map +0 -1
- package/dist/commands/view.js +0 -894
- package/dist/commands/view.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -496
- package/dist/index.js.map +0 -1
- package/dist/lib/__tests__/bugfixes.test.d.ts +0 -2
- package/dist/lib/__tests__/bugfixes.test.d.ts.map +0 -1
- package/dist/lib/__tests__/bugfixes.test.js +0 -192
- package/dist/lib/__tests__/bugfixes.test.js.map +0 -1
- package/dist/lib/__tests__/exec.test.d.ts +0 -2
- package/dist/lib/__tests__/exec.test.d.ts.map +0 -1
- package/dist/lib/__tests__/exec.test.js +0 -446
- package/dist/lib/__tests__/exec.test.js.map +0 -1
- package/dist/lib/__tests__/git-sync.test.d.ts +0 -2
- package/dist/lib/__tests__/git-sync.test.d.ts.map +0 -1
- package/dist/lib/__tests__/git-sync.test.js +0 -138
- package/dist/lib/__tests__/git-sync.test.js.map +0 -1
- package/dist/lib/__tests__/hooks.test.d.ts +0 -2
- package/dist/lib/__tests__/hooks.test.d.ts.map +0 -1
- package/dist/lib/__tests__/hooks.test.js +0 -203
- package/dist/lib/__tests__/hooks.test.js.map +0 -1
- package/dist/lib/__tests__/memory-compile.test.d.ts +0 -2
- package/dist/lib/__tests__/memory-compile.test.d.ts.map +0 -1
- package/dist/lib/__tests__/memory-compile.test.js +0 -95
- package/dist/lib/__tests__/memory-compile.test.js.map +0 -1
- package/dist/lib/__tests__/models.test.d.ts +0 -2
- package/dist/lib/__tests__/models.test.d.ts.map +0 -1
- package/dist/lib/__tests__/models.test.js +0 -239
- package/dist/lib/__tests__/models.test.js.map +0 -1
- package/dist/lib/__tests__/rotate.test.d.ts +0 -2
- package/dist/lib/__tests__/rotate.test.d.ts.map +0 -1
- package/dist/lib/__tests__/rotate.test.js +0 -80
- package/dist/lib/__tests__/rotate.test.js.map +0 -1
- package/dist/lib/__tests__/secrets-bundles.test.d.ts +0 -2
- package/dist/lib/__tests__/secrets-bundles.test.d.ts.map +0 -1
- package/dist/lib/__tests__/secrets-bundles.test.js +0 -104
- package/dist/lib/__tests__/secrets-bundles.test.js.map +0 -1
- package/dist/lib/__tests__/secrets.test.d.ts +0 -2
- package/dist/lib/__tests__/secrets.test.d.ts.map +0 -1
- package/dist/lib/__tests__/secrets.test.js +0 -90
- package/dist/lib/__tests__/secrets.test.js.map +0 -1
- package/dist/lib/__tests__/shims.test.d.ts +0 -2
- package/dist/lib/__tests__/shims.test.d.ts.map +0 -1
- package/dist/lib/__tests__/shims.test.js +0 -57
- package/dist/lib/__tests__/shims.test.js.map +0 -1
- package/dist/lib/__tests__/usage.test.d.ts +0 -2
- package/dist/lib/__tests__/usage.test.d.ts.map +0 -1
- package/dist/lib/__tests__/usage.test.js +0 -220
- package/dist/lib/__tests__/usage.test.js.map +0 -1
- package/dist/lib/__tests__/versions.test.d.ts +0 -2
- package/dist/lib/__tests__/versions.test.d.ts.map +0 -1
- package/dist/lib/__tests__/versions.test.js +0 -63
- package/dist/lib/__tests__/versions.test.js.map +0 -1
- package/dist/lib/agents.d.ts +0 -158
- package/dist/lib/agents.d.ts.map +0 -1
- package/dist/lib/agents.js +0 -1159
- package/dist/lib/agents.js.map +0 -1
- package/dist/lib/artifact-actions.d.ts +0 -27
- package/dist/lib/artifact-actions.d.ts.map +0 -1
- package/dist/lib/artifact-actions.js +0 -58
- package/dist/lib/artifact-actions.js.map +0 -1
- package/dist/lib/cloud/codex.d.ts +0 -26
- package/dist/lib/cloud/codex.d.ts.map +0 -1
- package/dist/lib/cloud/codex.js +0 -237
- package/dist/lib/cloud/codex.js.map +0 -1
- package/dist/lib/cloud/factory.d.ts +0 -32
- package/dist/lib/cloud/factory.d.ts.map +0 -1
- package/dist/lib/cloud/factory.js +0 -43
- package/dist/lib/cloud/factory.js.map +0 -1
- package/dist/lib/cloud/registry.d.ts +0 -16
- package/dist/lib/cloud/registry.d.ts.map +0 -1
- package/dist/lib/cloud/registry.js +0 -68
- package/dist/lib/cloud/registry.js.map +0 -1
- package/dist/lib/cloud/rush.d.ts +0 -37
- package/dist/lib/cloud/rush.d.ts.map +0 -1
- package/dist/lib/cloud/rush.js +0 -230
- package/dist/lib/cloud/rush.js.map +0 -1
- package/dist/lib/cloud/rush.test.d.ts +0 -2
- package/dist/lib/cloud/rush.test.d.ts.map +0 -1
- package/dist/lib/cloud/rush.test.js +0 -63
- package/dist/lib/cloud/rush.test.js.map +0 -1
- package/dist/lib/cloud/store.d.ts +0 -23
- package/dist/lib/cloud/store.d.ts.map +0 -1
- package/dist/lib/cloud/store.js +0 -116
- package/dist/lib/cloud/store.js.map +0 -1
- package/dist/lib/cloud/stream.d.ts +0 -24
- package/dist/lib/cloud/stream.d.ts.map +0 -1
- package/dist/lib/cloud/stream.js +0 -145
- package/dist/lib/cloud/stream.js.map +0 -1
- package/dist/lib/cloud/types.d.ts +0 -109
- package/dist/lib/cloud/types.d.ts.map +0 -1
- package/dist/lib/cloud/types.js +0 -33
- package/dist/lib/cloud/types.js.map +0 -1
- package/dist/lib/cloud/types.test.d.ts +0 -2
- package/dist/lib/cloud/types.test.d.ts.map +0 -1
- package/dist/lib/cloud/types.test.js +0 -41
- package/dist/lib/cloud/types.test.js.map +0 -1
- package/dist/lib/commands.d.ts +0 -141
- package/dist/lib/commands.d.ts.map +0 -1
- package/dist/lib/commands.js +0 -514
- package/dist/lib/commands.js.map +0 -1
- package/dist/lib/convert.d.ts +0 -21
- package/dist/lib/convert.d.ts.map +0 -1
- package/dist/lib/convert.js +0 -54
- package/dist/lib/convert.js.map +0 -1
- package/dist/lib/daemon.d.ts +0 -43
- package/dist/lib/daemon.d.ts.map +0 -1
- package/dist/lib/daemon.js +0 -332
- package/dist/lib/daemon.js.map +0 -1
- package/dist/lib/drive-sync.d.ts +0 -46
- package/dist/lib/drive-sync.d.ts.map +0 -1
- package/dist/lib/drive-sync.js +0 -209
- package/dist/lib/drive-sync.js.map +0 -1
- package/dist/lib/exec.d.ts +0 -101
- package/dist/lib/exec.d.ts.map +0 -1
- package/dist/lib/exec.js +0 -450
- package/dist/lib/exec.js.map +0 -1
- package/dist/lib/factory/__tests__/config.test.d.ts +0 -2
- package/dist/lib/factory/__tests__/config.test.d.ts.map +0 -1
- package/dist/lib/factory/__tests__/config.test.js +0 -128
- package/dist/lib/factory/__tests__/config.test.js.map +0 -1
- package/dist/lib/factory/config.d.ts +0 -49
- package/dist/lib/factory/config.d.ts.map +0 -1
- package/dist/lib/factory/config.js +0 -127
- package/dist/lib/factory/config.js.map +0 -1
- package/dist/lib/factory.d.ts +0 -57
- package/dist/lib/factory.d.ts.map +0 -1
- package/dist/lib/factory.js +0 -107
- package/dist/lib/factory.js.map +0 -1
- package/dist/lib/git.d.ts +0 -157
- package/dist/lib/git.d.ts.map +0 -1
- package/dist/lib/git.js +0 -647
- package/dist/lib/git.js.map +0 -1
- package/dist/lib/help.d.ts +0 -10
- package/dist/lib/help.d.ts.map +0 -1
- package/dist/lib/help.js +0 -66
- package/dist/lib/help.js.map +0 -1
- package/dist/lib/hooks.d.ts +0 -125
- package/dist/lib/hooks.d.ts.map +0 -1
- package/dist/lib/hooks.js +0 -846
- package/dist/lib/hooks.js.map +0 -1
- package/dist/lib/ledger/__tests__/local.test.d.ts +0 -2
- package/dist/lib/ledger/__tests__/local.test.d.ts.map +0 -1
- package/dist/lib/ledger/__tests__/local.test.js +0 -177
- package/dist/lib/ledger/__tests__/local.test.js.map +0 -1
- package/dist/lib/ledger/__tests__/sync.test.d.ts +0 -2
- package/dist/lib/ledger/__tests__/sync.test.d.ts.map +0 -1
- package/dist/lib/ledger/__tests__/sync.test.js +0 -117
- package/dist/lib/ledger/__tests__/sync.test.js.map +0 -1
- package/dist/lib/ledger/index.d.ts +0 -18
- package/dist/lib/ledger/index.d.ts.map +0 -1
- package/dist/lib/ledger/index.js +0 -32
- package/dist/lib/ledger/index.js.map +0 -1
- package/dist/lib/ledger/local.d.ts +0 -22
- package/dist/lib/ledger/local.d.ts.map +0 -1
- package/dist/lib/ledger/local.js +0 -333
- package/dist/lib/ledger/local.js.map +0 -1
- package/dist/lib/ledger/r2.d.ts +0 -41
- package/dist/lib/ledger/r2.d.ts.map +0 -1
- package/dist/lib/ledger/r2.js +0 -335
- package/dist/lib/ledger/r2.js.map +0 -1
- package/dist/lib/ledger/sync.d.ts +0 -33
- package/dist/lib/ledger/sync.d.ts.map +0 -1
- package/dist/lib/ledger/sync.js +0 -106
- package/dist/lib/ledger/sync.js.map +0 -1
- package/dist/lib/ledger/types.d.ts +0 -100
- package/dist/lib/ledger/types.d.ts.map +0 -1
- package/dist/lib/ledger/types.js +0 -21
- package/dist/lib/ledger/types.js.map +0 -1
- package/dist/lib/manifest.d.ts +0 -14
- package/dist/lib/manifest.d.ts.map +0 -1
- package/dist/lib/manifest.js +0 -48
- package/dist/lib/manifest.js.map +0 -1
- package/dist/lib/markdown.d.ts +0 -5
- package/dist/lib/markdown.d.ts.map +0 -1
- package/dist/lib/markdown.js +0 -17
- package/dist/lib/markdown.js.map +0 -1
- package/dist/lib/mcp.d.ts +0 -64
- package/dist/lib/mcp.d.ts.map +0 -1
- package/dist/lib/mcp.js +0 -327
- package/dist/lib/mcp.js.map +0 -1
- package/dist/lib/memory-compile.d.ts +0 -65
- package/dist/lib/memory-compile.d.ts.map +0 -1
- package/dist/lib/memory-compile.js +0 -174
- package/dist/lib/memory-compile.js.map +0 -1
- package/dist/lib/memory.d.ts +0 -64
- package/dist/lib/memory.d.ts.map +0 -1
- package/dist/lib/memory.js +0 -275
- package/dist/lib/memory.js.map +0 -1
- package/dist/lib/models.d.ts +0 -98
- package/dist/lib/models.d.ts.map +0 -1
- package/dist/lib/models.js +0 -728
- package/dist/lib/models.js.map +0 -1
- package/dist/lib/permissions.d.ts +0 -227
- package/dist/lib/permissions.d.ts.map +0 -1
- package/dist/lib/permissions.js +0 -1071
- package/dist/lib/permissions.js.map +0 -1
- package/dist/lib/picker.d.ts +0 -27
- package/dist/lib/picker.d.ts.map +0 -1
- package/dist/lib/picker.js +0 -110
- package/dist/lib/picker.js.map +0 -1
- package/dist/lib/plugins.d.ts +0 -80
- package/dist/lib/plugins.d.ts.map +0 -1
- package/dist/lib/plugins.js +0 -556
- package/dist/lib/plugins.js.map +0 -1
- package/dist/lib/profiles-keychain.d.ts +0 -11
- package/dist/lib/profiles-keychain.d.ts.map +0 -1
- package/dist/lib/profiles-keychain.js +0 -14
- package/dist/lib/profiles-keychain.js.map +0 -1
- package/dist/lib/profiles-presets.d.ts +0 -25
- package/dist/lib/profiles-presets.d.ts.map +0 -1
- package/dist/lib/profiles-presets.js +0 -104
- package/dist/lib/profiles-presets.js.map +0 -1
- package/dist/lib/profiles.d.ts +0 -70
- package/dist/lib/profiles.d.ts.map +0 -1
- package/dist/lib/profiles.js +0 -145
- package/dist/lib/profiles.js.map +0 -1
- package/dist/lib/pty-client.d.ts +0 -23
- package/dist/lib/pty-client.d.ts.map +0 -1
- package/dist/lib/pty-client.js +0 -181
- package/dist/lib/pty-client.js.map +0 -1
- package/dist/lib/pty-server.d.ts +0 -21
- package/dist/lib/pty-server.d.ts.map +0 -1
- package/dist/lib/pty-server.js +0 -427
- package/dist/lib/pty-server.js.map +0 -1
- package/dist/lib/registry.d.ts +0 -45
- package/dist/lib/registry.d.ts.map +0 -1
- package/dist/lib/registry.js +0 -220
- package/dist/lib/registry.js.map +0 -1
- package/dist/lib/resources.d.ts +0 -55
- package/dist/lib/resources.d.ts.map +0 -1
- package/dist/lib/resources.js +0 -103
- package/dist/lib/resources.js.map +0 -1
- package/dist/lib/rotate.d.ts +0 -58
- package/dist/lib/rotate.d.ts.map +0 -1
- package/dist/lib/rotate.js +0 -93
- package/dist/lib/rotate.js.map +0 -1
- package/dist/lib/routines.d.ts +0 -99
- package/dist/lib/routines.d.ts.map +0 -1
- package/dist/lib/routines.js +0 -352
- package/dist/lib/routines.js.map +0 -1
- package/dist/lib/runner.d.ts +0 -26
- package/dist/lib/runner.d.ts.map +0 -1
- package/dist/lib/runner.js +0 -325
- package/dist/lib/runner.js.map +0 -1
- package/dist/lib/sandbox.d.ts +0 -26
- package/dist/lib/sandbox.d.ts.map +0 -1
- package/dist/lib/sandbox.js +0 -218
- package/dist/lib/sandbox.js.map +0 -1
- package/dist/lib/scheduler.d.ts +0 -26
- package/dist/lib/scheduler.d.ts.map +0 -1
- package/dist/lib/scheduler.js +0 -77
- package/dist/lib/scheduler.js.map +0 -1
- package/dist/lib/secrets-bundles.d.ts +0 -38
- package/dist/lib/secrets-bundles.d.ts.map +0 -1
- package/dist/lib/secrets-bundles.js +0 -176
- package/dist/lib/secrets-bundles.js.map +0 -1
- package/dist/lib/secrets.d.ts +0 -53
- package/dist/lib/secrets.d.ts.map +0 -1
- package/dist/lib/secrets.js +0 -140
- package/dist/lib/secrets.js.map +0 -1
- package/dist/lib/session/__tests__/db.test.d.ts +0 -2
- package/dist/lib/session/__tests__/db.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/db.test.js +0 -54
- package/dist/lib/session/__tests__/db.test.js.map +0 -1
- package/dist/lib/session/__tests__/discover.test.d.ts +0 -2
- package/dist/lib/session/__tests__/discover.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/discover.test.js +0 -63
- package/dist/lib/session/__tests__/discover.test.js.map +0 -1
- package/dist/lib/session/__tests__/prompt.test.d.ts +0 -2
- package/dist/lib/session/__tests__/prompt.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/prompt.test.js +0 -44
- package/dist/lib/session/__tests__/prompt.test.js.map +0 -1
- package/dist/lib/session/__tests__/render.test.d.ts +0 -2
- package/dist/lib/session/__tests__/render.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/render.test.js +0 -602
- package/dist/lib/session/__tests__/render.test.js.map +0 -1
- package/dist/lib/session/active.d.ts +0 -44
- package/dist/lib/session/active.d.ts.map +0 -1
- package/dist/lib/session/active.js +0 -379
- package/dist/lib/session/active.js.map +0 -1
- package/dist/lib/session/artifacts.d.ts +0 -15
- package/dist/lib/session/artifacts.d.ts.map +0 -1
- package/dist/lib/session/artifacts.js +0 -86
- package/dist/lib/session/artifacts.js.map +0 -1
- package/dist/lib/session/db.d.ts +0 -140
- package/dist/lib/session/db.d.ts.map +0 -1
- package/dist/lib/session/db.js +0 -599
- package/dist/lib/session/db.js.map +0 -1
- package/dist/lib/session/discover.d.ts +0 -72
- package/dist/lib/session/discover.d.ts.map +0 -1
- package/dist/lib/session/discover.js +0 -1315
- package/dist/lib/session/discover.js.map +0 -1
- package/dist/lib/session/parse.d.ts +0 -34
- package/dist/lib/session/parse.d.ts.map +0 -1
- package/dist/lib/session/parse.js +0 -663
- package/dist/lib/session/parse.js.map +0 -1
- package/dist/lib/session/prompt.d.ts +0 -13
- package/dist/lib/session/prompt.d.ts.map +0 -1
- package/dist/lib/session/prompt.js +0 -79
- package/dist/lib/session/prompt.js.map +0 -1
- package/dist/lib/session/prompt.test.d.ts +0 -2
- package/dist/lib/session/prompt.test.d.ts.map +0 -1
- package/dist/lib/session/prompt.test.js +0 -57
- package/dist/lib/session/prompt.test.js.map +0 -1
- package/dist/lib/session/render.d.ts +0 -103
- package/dist/lib/session/render.d.ts.map +0 -1
- package/dist/lib/session/render.js +0 -798
- package/dist/lib/session/render.js.map +0 -1
- package/dist/lib/session/team-filter.d.ts +0 -35
- package/dist/lib/session/team-filter.d.ts.map +0 -1
- package/dist/lib/session/team-filter.js +0 -75
- package/dist/lib/session/team-filter.js.map +0 -1
- package/dist/lib/session/team-filter.test.d.ts +0 -2
- package/dist/lib/session/team-filter.test.d.ts.map +0 -1
- package/dist/lib/session/team-filter.test.js +0 -157
- package/dist/lib/session/team-filter.test.js.map +0 -1
- package/dist/lib/session/types.d.ts +0 -84
- package/dist/lib/session/types.d.ts.map +0 -1
- package/dist/lib/session/types.js +0 -11
- package/dist/lib/session/types.js.map +0 -1
- package/dist/lib/shims.d.ts +0 -272
- package/dist/lib/shims.d.ts.map +0 -1
- package/dist/lib/shims.js +0 -1322
- package/dist/lib/shims.js.map +0 -1
- package/dist/lib/skills.d.ts +0 -142
- package/dist/lib/skills.d.ts.map +0 -1
- package/dist/lib/skills.js +0 -791
- package/dist/lib/skills.js.map +0 -1
- package/dist/lib/state.d.ts +0 -87
- package/dist/lib/state.d.ts.map +0 -1
- package/dist/lib/state.js +0 -333
- package/dist/lib/state.js.map +0 -1
- package/dist/lib/subagents.d.ts +0 -84
- package/dist/lib/subagents.d.ts.map +0 -1
- package/dist/lib/subagents.js +0 -410
- package/dist/lib/subagents.js.map +0 -1
- package/dist/lib/teams/__tests__/oracle.test.d.ts +0 -2
- package/dist/lib/teams/__tests__/oracle.test.d.ts.map +0 -1
- package/dist/lib/teams/__tests__/oracle.test.js +0 -89
- package/dist/lib/teams/__tests__/oracle.test.js.map +0 -1
- package/dist/lib/teams/__tests__/supervisor.test.d.ts +0 -2
- package/dist/lib/teams/__tests__/supervisor.test.d.ts.map +0 -1
- package/dist/lib/teams/__tests__/supervisor.test.js +0 -179
- package/dist/lib/teams/__tests__/supervisor.test.js.map +0 -1
- package/dist/lib/teams/agents.d.ts +0 -247
- package/dist/lib/teams/agents.d.ts.map +0 -1
- package/dist/lib/teams/agents.js +0 -1244
- package/dist/lib/teams/agents.js.map +0 -1
- package/dist/lib/teams/api.d.ts +0 -91
- package/dist/lib/teams/api.d.ts.map +0 -1
- package/dist/lib/teams/api.js +0 -239
- package/dist/lib/teams/api.js.map +0 -1
- package/dist/lib/teams/cloud.d.ts +0 -11
- package/dist/lib/teams/cloud.d.ts.map +0 -1
- package/dist/lib/teams/cloud.js +0 -169
- package/dist/lib/teams/cloud.js.map +0 -1
- package/dist/lib/teams/debug.d.ts +0 -8
- package/dist/lib/teams/debug.d.ts.map +0 -1
- package/dist/lib/teams/debug.js +0 -12
- package/dist/lib/teams/debug.js.map +0 -1
- package/dist/lib/teams/file_ops.d.ts +0 -13
- package/dist/lib/teams/file_ops.d.ts.map +0 -1
- package/dist/lib/teams/file_ops.js +0 -66
- package/dist/lib/teams/file_ops.js.map +0 -1
- package/dist/lib/teams/index.d.ts +0 -16
- package/dist/lib/teams/index.d.ts.map +0 -1
- package/dist/lib/teams/index.js +0 -15
- package/dist/lib/teams/index.js.map +0 -1
- package/dist/lib/teams/oracle.d.ts +0 -20
- package/dist/lib/teams/oracle.d.ts.map +0 -1
- package/dist/lib/teams/oracle.js +0 -59
- package/dist/lib/teams/oracle.js.map +0 -1
- package/dist/lib/teams/parsers.d.ts +0 -9
- package/dist/lib/teams/parsers.d.ts.map +0 -1
- package/dist/lib/teams/parsers.js +0 -837
- package/dist/lib/teams/parsers.js.map +0 -1
- package/dist/lib/teams/persistence.d.ts +0 -43
- package/dist/lib/teams/persistence.d.ts.map +0 -1
- package/dist/lib/teams/persistence.js +0 -299
- package/dist/lib/teams/persistence.js.map +0 -1
- package/dist/lib/teams/ralph.d.ts +0 -8
- package/dist/lib/teams/ralph.d.ts.map +0 -1
- package/dist/lib/teams/ralph.js +0 -59
- package/dist/lib/teams/ralph.js.map +0 -1
- package/dist/lib/teams/registry.d.ts +0 -18
- package/dist/lib/teams/registry.d.ts.map +0 -1
- package/dist/lib/teams/registry.js +0 -68
- package/dist/lib/teams/registry.js.map +0 -1
- package/dist/lib/teams/summarizer.d.ts +0 -73
- package/dist/lib/teams/summarizer.d.ts.map +0 -1
- package/dist/lib/teams/summarizer.js +0 -780
- package/dist/lib/teams/summarizer.js.map +0 -1
- package/dist/lib/teams/supervisor.d.ts +0 -49
- package/dist/lib/teams/supervisor.d.ts.map +0 -1
- package/dist/lib/teams/supervisor.js +0 -74
- package/dist/lib/teams/supervisor.js.map +0 -1
- package/dist/lib/template.d.ts +0 -27
- package/dist/lib/template.d.ts.map +0 -1
- package/dist/lib/template.js +0 -60
- package/dist/lib/template.js.map +0 -1
- package/dist/lib/types.d.ts +0 -331
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js +0 -29
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/usage.d.ts +0 -105
- package/dist/lib/usage.d.ts.map +0 -1
- package/dist/lib/usage.js +0 -686
- package/dist/lib/usage.js.map +0 -1
- package/dist/lib/versions.d.ts +0 -253
- package/dist/lib/versions.d.ts.map +0 -1
- package/dist/lib/versions.js +0 -1796
- package/dist/lib/versions.js.map +0 -1
- 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
|