charness 3.11.0 → 3.12.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/CHANGELOG.md +142 -0
- package/DEVELOPMENT.md +3 -3
- package/README.md +1 -1
- package/SETUP.md +6 -5
- package/agent-plugin/README.md +15 -6
- package/agent-plugin/skills/charness-delegate-claude/SKILL.md +23 -13
- package/agent-plugin/skills/charness-delegate-opencode/SKILL.md +10 -6
- package/agent-plugin/skills/charness-delivery-loop/SKILL.md +92 -0
- package/agent-plugin/skills/charness-orchestration/SKILL.md +116 -0
- package/dist/adapters/openCodeAdapter.d.ts +15 -0
- package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/openCodeAdapter.js +48 -4
- package/dist/adapters/openCodeAdapter.js.map +1 -1
- package/dist/agentLogin/agentLogin.d.ts +11 -0
- package/dist/agentLogin/agentLogin.d.ts.map +1 -1
- package/dist/agentLogin/agentLogin.js +18 -6
- package/dist/agentLogin/agentLogin.js.map +1 -1
- package/dist/apiErrorRetry.d.ts +5 -0
- package/dist/apiErrorRetry.d.ts.map +1 -1
- package/dist/apiErrorRetry.js +3 -3
- package/dist/apiErrorRetry.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +158 -20
- package/dist/bot.js.map +1 -1
- package/dist/cli/claudeProfiles.d.ts +5 -2
- package/dist/cli/claudeProfiles.d.ts.map +1 -1
- package/dist/cli/claudeProfiles.js +43 -20
- package/dist/cli/claudeProfiles.js.map +1 -1
- package/dist/cli/claudeProfilesCredit.d.ts +49 -0
- package/dist/cli/claudeProfilesCredit.d.ts.map +1 -0
- package/dist/cli/claudeProfilesCredit.js +160 -0
- package/dist/cli/claudeProfilesCredit.js.map +1 -0
- package/dist/cli/flagValue.d.ts +10 -0
- package/dist/cli/flagValue.d.ts.map +1 -0
- package/dist/cli/flagValue.js +17 -0
- package/dist/cli/flagValue.js.map +1 -0
- package/dist/connectors/telegram/commands/botSkills.js +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts +6 -1
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +9 -6
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/compaction.d.ts +11 -0
- package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/compaction.js +208 -22
- package/dist/connectors/telegram/commands/compaction.js.map +1 -1
- package/dist/connectors/telegram/commands/runners.d.ts +5 -1
- package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.js +146 -31
- package/dist/connectors/telegram/commands/runners.js.map +1 -1
- package/dist/connectors/telegram/runnerPairingMessages.d.ts +2 -7
- package/dist/connectors/telegram/runnerPairingMessages.d.ts.map +1 -1
- package/dist/connectors/telegram/runnerPairingMessages.js +5 -19
- package/dist/connectors/telegram/runnerPairingMessages.js.map +1 -1
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/de.js +52 -8
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +52 -8
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +52 -8
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +52 -8
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +52 -8
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +52 -8
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +52 -8
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +52 -8
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +52 -8
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +52 -8
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +52 -8
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +52 -8
- package/dist/i18n/zh.js.map +1 -1
- package/dist/installManager.d.ts.map +1 -1
- package/dist/installManager.js +3 -0
- package/dist/installManager.js.map +1 -1
- package/dist/instanceLock.d.ts.map +1 -1
- package/dist/instanceLock.js +2 -1
- package/dist/instanceLock.js.map +1 -1
- package/dist/platform/outbound.d.ts +14 -1
- package/dist/platform/outbound.d.ts.map +1 -1
- package/dist/platform/outbound.js.map +1 -1
- package/dist/remoteRun/cleanReport.d.ts +45 -0
- package/dist/remoteRun/cleanReport.d.ts.map +1 -0
- package/dist/remoteRun/cleanReport.js +84 -0
- package/dist/remoteRun/cleanReport.js.map +1 -0
- package/dist/remoteRun/cliArgs.d.ts +18 -0
- package/dist/remoteRun/cliArgs.d.ts.map +1 -1
- package/dist/remoteRun/cliArgs.js +100 -4
- package/dist/remoteRun/cliArgs.js.map +1 -1
- package/dist/remoteRun/commands.d.ts +30 -1
- package/dist/remoteRun/commands.d.ts.map +1 -1
- package/dist/remoteRun/commands.js +84 -9
- package/dist/remoteRun/commands.js.map +1 -1
- package/dist/remoteRun/exitCodes.d.ts +5 -0
- package/dist/remoteRun/exitCodes.d.ts.map +1 -1
- package/dist/remoteRun/exitCodes.js +6 -1
- package/dist/remoteRun/exitCodes.js.map +1 -1
- package/dist/remoteRun/foreground.d.ts +6 -0
- package/dist/remoteRun/foreground.d.ts.map +1 -1
- package/dist/remoteRun/foreground.js +13 -1
- package/dist/remoteRun/foreground.js.map +1 -1
- package/dist/remoteRun/interrupts.d.ts.map +1 -1
- package/dist/remoteRun/interrupts.js +2 -2
- package/dist/remoteRun/interrupts.js.map +1 -1
- package/dist/remoteRun/jobFiles.d.ts +6 -1
- package/dist/remoteRun/jobFiles.d.ts.map +1 -1
- package/dist/remoteRun/jobFiles.js +14 -0
- package/dist/remoteRun/jobFiles.js.map +1 -1
- package/dist/remoteRun/jobId.d.ts +5 -0
- package/dist/remoteRun/jobId.d.ts.map +1 -1
- package/dist/remoteRun/jobId.js +10 -0
- package/dist/remoteRun/jobId.js.map +1 -1
- package/dist/remoteRun/jobState.d.ts.map +1 -1
- package/dist/remoteRun/jobState.js +3 -2
- package/dist/remoteRun/jobState.js.map +1 -1
- package/dist/remoteRun/pairedRunners.d.ts +1 -1
- package/dist/remoteRun/pairedRunners.d.ts.map +1 -1
- package/dist/remoteRun/pairedRunners.js +4 -0
- package/dist/remoteRun/pairedRunners.js.map +1 -1
- package/dist/remoteRun/pathPatterns.d.ts +1 -1
- package/dist/remoteRun/pathPatterns.js +1 -1
- package/dist/remoteRun/probe.d.ts +58 -5
- package/dist/remoteRun/probe.d.ts.map +1 -1
- package/dist/remoteRun/probe.js +107 -11
- package/dist/remoteRun/probe.js.map +1 -1
- package/dist/remoteRun/probeTiming.d.ts +15 -0
- package/dist/remoteRun/probeTiming.d.ts.map +1 -0
- package/dist/remoteRun/probeTiming.js +23 -0
- package/dist/remoteRun/probeTiming.js.map +1 -0
- package/dist/remoteRun/project.d.ts +5 -0
- package/dist/remoteRun/project.d.ts.map +1 -1
- package/dist/remoteRun/project.js +10 -0
- package/dist/remoteRun/project.js.map +1 -1
- package/dist/remoteRun/projectConfig.d.ts +8 -1
- package/dist/remoteRun/projectConfig.d.ts.map +1 -1
- package/dist/remoteRun/projectConfig.js +18 -5
- package/dist/remoteRun/projectConfig.js.map +1 -1
- package/dist/remoteRun/pruneReport.d.ts +48 -0
- package/dist/remoteRun/pruneReport.d.ts.map +1 -0
- package/dist/remoteRun/pruneReport.js +80 -0
- package/dist/remoteRun/pruneReport.js.map +1 -0
- package/dist/remoteRun/remoteRunCli.d.ts +1 -1
- package/dist/remoteRun/remoteRunCli.d.ts.map +1 -1
- package/dist/remoteRun/remoteRunCli.js +20 -0
- package/dist/remoteRun/remoteRunCli.js.map +1 -1
- package/dist/remoteRun/runnerClient.d.ts +10 -0
- package/dist/remoteRun/runnerClient.d.ts.map +1 -1
- package/dist/remoteRun/runnerClient.js +19 -5
- package/dist/remoteRun/runnerClient.js.map +1 -1
- package/dist/remoteRun/runnerWait.d.ts.map +1 -1
- package/dist/remoteRun/runnerWait.js +2 -1
- package/dist/remoteRun/runnerWait.js.map +1 -1
- package/dist/remoteRun/runners.d.ts +48 -7
- package/dist/remoteRun/runners.d.ts.map +1 -1
- package/dist/remoteRun/runners.js +105 -40
- package/dist/remoteRun/runners.js.map +1 -1
- package/dist/remoteRun/runnersConfig.d.ts +24 -0
- package/dist/remoteRun/runnersConfig.d.ts.map +1 -1
- package/dist/remoteRun/runnersConfig.js +29 -2
- package/dist/remoteRun/runnersConfig.js.map +1 -1
- package/dist/remoteRun/ssh.d.ts +3 -3
- package/dist/remoteRun/ssh.d.ts.map +1 -1
- package/dist/remoteRun/ssh.js +19 -5
- package/dist/remoteRun/ssh.js.map +1 -1
- package/dist/remoteRun/submit.d.ts +1 -1
- package/dist/remoteRun/submit.d.ts.map +1 -1
- package/dist/remoteRun/submit.js +30 -2
- package/dist/remoteRun/submit.js.map +1 -1
- package/dist/runnerUtility/adminService.d.ts.map +1 -1
- package/dist/runnerUtility/adminService.js +5 -5
- package/dist/runnerUtility/adminService.js.map +1 -1
- package/dist/runnerUtility/appInstall.d.ts +9 -0
- package/dist/runnerUtility/appInstall.d.ts.map +1 -1
- package/dist/runnerUtility/appInstall.js +12 -2
- package/dist/runnerUtility/appInstall.js.map +1 -1
- package/dist/runnerUtility/execEnv.d.ts +1 -1
- package/dist/runnerUtility/execEnv.d.ts.map +1 -1
- package/dist/runnerUtility/execEnv.js +23 -5
- package/dist/runnerUtility/execEnv.js.map +1 -1
- package/dist/runnerUtility/guiAgentHeal.d.ts +3 -3
- package/dist/runnerUtility/guiAgentHeal.d.ts.map +1 -1
- package/dist/runnerUtility/guiAgentHeal.js +4 -2
- package/dist/runnerUtility/guiAgentHeal.js.map +1 -1
- package/dist/runnerUtility/homeFolders.d.ts +1 -0
- package/dist/runnerUtility/homeFolders.d.ts.map +1 -1
- package/dist/runnerUtility/homeFolders.js +2 -1
- package/dist/runnerUtility/homeFolders.js.map +1 -1
- package/dist/runnerUtility/iosCheck.d.ts +2 -0
- package/dist/runnerUtility/iosCheck.d.ts.map +1 -1
- package/dist/runnerUtility/iosCheck.js +12 -3
- package/dist/runnerUtility/iosCheck.js.map +1 -1
- package/dist/runnerUtility/keepAwake.d.ts +47 -10
- package/dist/runnerUtility/keepAwake.d.ts.map +1 -1
- package/dist/runnerUtility/keepAwake.js +108 -31
- package/dist/runnerUtility/keepAwake.js.map +1 -1
- package/dist/runnerUtility/launcher.d.ts +4 -0
- package/dist/runnerUtility/launcher.d.ts.map +1 -1
- package/dist/runnerUtility/launcher.js +31 -13
- package/dist/runnerUtility/launcher.js.map +1 -1
- package/dist/runnerUtility/linkLoop.d.ts +4 -0
- package/dist/runnerUtility/linkLoop.d.ts.map +1 -1
- package/dist/runnerUtility/linkLoop.js +15 -6
- package/dist/runnerUtility/linkLoop.js.map +1 -1
- package/dist/runnerUtility/managedNode.d.ts +84 -0
- package/dist/runnerUtility/managedNode.d.ts.map +1 -0
- package/dist/runnerUtility/managedNode.js +165 -0
- package/dist/runnerUtility/managedNode.js.map +1 -0
- package/dist/runnerUtility/nodeOnPath.d.ts +10 -0
- package/dist/runnerUtility/nodeOnPath.d.ts.map +1 -0
- package/dist/runnerUtility/nodeOnPath.js +49 -0
- package/dist/runnerUtility/nodeOnPath.js.map +1 -0
- package/dist/runnerUtility/nodeUpkeep.d.ts +140 -0
- package/dist/runnerUtility/nodeUpkeep.d.ts.map +1 -0
- package/dist/runnerUtility/nodeUpkeep.js +348 -0
- package/dist/runnerUtility/nodeUpkeep.js.map +1 -0
- package/dist/runnerUtility/nodeUpkeepTiming.d.ts +14 -0
- package/dist/runnerUtility/nodeUpkeepTiming.d.ts.map +1 -0
- package/dist/runnerUtility/nodeUpkeepTiming.js +21 -0
- package/dist/runnerUtility/nodeUpkeepTiming.js.map +1 -0
- package/dist/runnerUtility/packageManagerShims.d.ts +10 -0
- package/dist/runnerUtility/packageManagerShims.d.ts.map +1 -1
- package/dist/runnerUtility/packageManagerShims.js +67 -3
- package/dist/runnerUtility/packageManagerShims.js.map +1 -1
- package/dist/runnerUtility/pueueDaemon.d.ts +73 -8
- package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
- package/dist/runnerUtility/pueueDaemon.js +90 -15
- package/dist/runnerUtility/pueueDaemon.js.map +1 -1
- package/dist/runnerUtility/runnerCommands.d.ts +7 -1
- package/dist/runnerUtility/runnerCommands.d.ts.map +1 -1
- package/dist/runnerUtility/runnerCommands.js +119 -16
- package/dist/runnerUtility/runnerCommands.js.map +1 -1
- package/dist/runnerUtility/runnerHome.d.ts +34 -0
- package/dist/runnerUtility/runnerHome.d.ts.map +1 -1
- package/dist/runnerUtility/runnerHome.js +17 -3
- package/dist/runnerUtility/runnerHome.js.map +1 -1
- package/dist/runnerUtility/serviceCommon.d.ts +2 -0
- package/dist/runnerUtility/serviceCommon.d.ts.map +1 -1
- package/dist/runnerUtility/serviceCommon.js +3 -1
- package/dist/runnerUtility/serviceCommon.js.map +1 -1
- package/dist/runnerUtility/serviceManager.d.ts.map +1 -1
- package/dist/runnerUtility/serviceManager.js +7 -2
- package/dist/runnerUtility/serviceManager.js.map +1 -1
- package/dist/runnerUtility/simctlGuard.d.ts +38 -0
- package/dist/runnerUtility/simctlGuard.d.ts.map +1 -0
- package/dist/runnerUtility/simctlGuard.js +166 -0
- package/dist/runnerUtility/simctlGuard.js.map +1 -0
- package/dist/runners/bootstrapLine.d.ts +3 -4
- package/dist/runners/bootstrapLine.d.ts.map +1 -1
- package/dist/runners/bootstrapLine.js +108 -83
- package/dist/runners/bootstrapLine.js.map +1 -1
- package/dist/runners/hubPackage.d.ts +1 -1
- package/dist/runners/hubPackage.d.ts.map +1 -1
- package/dist/runners/hubPackage.js +5 -6
- package/dist/runners/hubPackage.js.map +1 -1
- package/dist/runners/hubPairing.d.ts +19 -0
- package/dist/runners/hubPairing.d.ts.map +1 -1
- package/dist/runners/hubPairing.js +38 -0
- package/dist/runners/hubPairing.js.map +1 -1
- package/dist/runners/hubRegistry.d.ts +8 -0
- package/dist/runners/hubRegistry.d.ts.map +1 -1
- package/dist/runners/hubRegistry.js +6 -0
- package/dist/runners/hubRegistry.js.map +1 -1
- package/dist/runners/pairCode.d.ts +34 -3
- package/dist/runners/pairCode.d.ts.map +1 -1
- package/dist/runners/pairCode.js +65 -13
- package/dist/runners/pairCode.js.map +1 -1
- package/dist/runners/runnerGroups.d.ts +22 -0
- package/dist/runners/runnerGroups.d.ts.map +1 -0
- package/dist/runners/runnerGroups.js +41 -0
- package/dist/runners/runnerGroups.js.map +1 -0
- package/dist/runners/runnersCli.d.ts +5 -2
- package/dist/runners/runnersCli.d.ts.map +1 -1
- package/dist/runners/runnersCli.js +59 -9
- package/dist/runners/runnersCli.js.map +1 -1
- package/dist/runners/runnersList.d.ts +1 -1
- package/dist/runners/runnersList.d.ts.map +1 -1
- package/dist/runners/runnersList.js +3 -1
- package/dist/runners/runnersList.js.map +1 -1
- package/dist/runners/runnersOverview.d.ts.map +1 -1
- package/dist/runners/runnersOverview.js +8 -4
- package/dist/runners/runnersOverview.js.map +1 -1
- package/dist/scheduler/checkStatus.d.ts +2 -0
- package/dist/scheduler/checkStatus.d.ts.map +1 -1
- package/dist/scheduler/checkStatus.js +5 -4
- package/dist/scheduler/checkStatus.js.map +1 -1
- package/dist/scheduler/delivery.d.ts +2 -1
- package/dist/scheduler/delivery.d.ts.map +1 -1
- package/dist/scheduler/delivery.js +5 -1
- package/dist/scheduler/delivery.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts +7 -3
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +48 -22
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/scheduler/workerWatch.d.ts +33 -10
- package/dist/scheduler/workerWatch.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.js +37 -11
- package/dist/scheduler/workerWatch.js.map +1 -1
- package/dist/state.d.ts +95 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +145 -7
- package/dist/state.js.map +1 -1
- package/dist/testTimings.d.ts +6 -2
- package/dist/testTimings.d.ts.map +1 -1
- package/dist/testTimings.js +12 -1
- package/dist/testTimings.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agentPlugin.d.ts +2 -1
- package/dist/utils/agentPlugin.d.ts.map +1 -1
- package/dist/utils/agentPlugin.js +2 -1
- package/dist/utils/agentPlugin.js.map +1 -1
- package/dist/utils/botSkills.d.ts +1 -1
- package/dist/utils/claudeApiAgentStop.d.ts +64 -0
- package/dist/utils/claudeApiAgentStop.d.ts.map +1 -0
- package/dist/utils/claudeApiAgentStop.js +85 -0
- package/dist/utils/claudeApiAgentStop.js.map +1 -0
- package/dist/utils/claudeApiCredit.d.ts +168 -0
- package/dist/utils/claudeApiCredit.d.ts.map +1 -0
- package/dist/utils/claudeApiCredit.js +260 -0
- package/dist/utils/claudeApiCredit.js.map +1 -0
- package/dist/utils/claudeApiCreditRecheck.d.ts +120 -0
- package/dist/utils/claudeApiCreditRecheck.d.ts.map +1 -0
- package/dist/utils/claudeApiCreditRecheck.js +173 -0
- package/dist/utils/claudeApiCreditRecheck.js.map +1 -0
- package/dist/utils/claudeCompactHook.d.ts +18 -10
- package/dist/utils/claudeCompactHook.d.ts.map +1 -1
- package/dist/utils/claudeCompactHook.js +35 -14
- package/dist/utils/claudeCompactHook.js.map +1 -1
- package/dist/utils/claudeProfileUsageLines.d.ts +13 -1
- package/dist/utils/claudeProfileUsageLines.d.ts.map +1 -1
- package/dist/utils/claudeProfileUsageLines.js +75 -4
- package/dist/utils/claudeProfileUsageLines.js.map +1 -1
- package/dist/utils/claudeProfileUsageViews.d.ts +46 -0
- package/dist/utils/claudeProfileUsageViews.d.ts.map +1 -0
- package/dist/utils/claudeProfileUsageViews.js +114 -0
- package/dist/utils/claudeProfileUsageViews.js.map +1 -0
- package/dist/utils/claudeProfiles.d.ts +15 -0
- package/dist/utils/claudeProfiles.d.ts.map +1 -1
- package/dist/utils/claudeProfiles.js +54 -0
- package/dist/utils/claudeProfiles.js.map +1 -1
- package/dist/utils/claudeUsage.d.ts +94 -36
- package/dist/utils/claudeUsage.d.ts.map +1 -1
- package/dist/utils/claudeUsage.js +134 -60
- package/dist/utils/claudeUsage.js.map +1 -1
- package/dist/utils/compactOnIdle.d.ts +140 -15
- package/dist/utils/compactOnIdle.d.ts.map +1 -1
- package/dist/utils/compactOnIdle.js +209 -23
- package/dist/utils/compactOnIdle.js.map +1 -1
- package/dist/utils/compactSelfReviewFlags.d.ts +50 -0
- package/dist/utils/compactSelfReviewFlags.d.ts.map +1 -0
- package/dist/utils/compactSelfReviewFlags.js +120 -0
- package/dist/utils/compactSelfReviewFlags.js.map +1 -0
- package/dist/utils/fallbackChain.d.ts +18 -7
- package/dist/utils/fallbackChain.d.ts.map +1 -1
- package/dist/utils/fallbackChain.js +28 -12
- package/dist/utils/fallbackChain.js.map +1 -1
- package/dist/utils/openCodeCompactPlugin.d.ts +28 -7
- package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
- package/dist/utils/openCodeCompactPlugin.js +80 -15
- package/dist/utils/openCodeCompactPlugin.js.map +1 -1
- package/dist/utils/runnersScreenPlan.d.ts +51 -20
- package/dist/utils/runnersScreenPlan.d.ts.map +1 -1
- package/dist/utils/runnersScreenPlan.js +143 -28
- package/dist/utils/runnersScreenPlan.js.map +1 -1
- package/dist/utils/streamedCompactionSummary.d.ts +65 -0
- package/dist/utils/streamedCompactionSummary.d.ts.map +1 -0
- package/dist/utils/streamedCompactionSummary.js +108 -0
- package/dist/utils/streamedCompactionSummary.js.map +1 -0
- package/package.json +2 -2
- package/remoteRun/ensureNode.sh +288 -0
- package/remoteRun/runner.sh +2252 -115
- package/agent-plugin/skills/charness-manager/SKILL.md +0 -157
- package/remoteRun/pickNode.sh +0 -65
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description The daily recheck of an API account the bot believes has used up its credit (`creditExhaustedAt`, shown as
|
|
3
|
+
* «probably used up», `claudeApiCredit.ts`): one tiny request on that account's OWN key, to learn whether the balance is
|
|
4
|
+
* back (the monthly bonus renews by itself, with no sign the bot can read).
|
|
5
|
+
*
|
|
6
|
+
* • refused for the balance («credit balance is too low») → still used up, nothing changes;
|
|
7
|
+
* • the probe's model is gone (404 `not_found_error`) → no conclusion, a WARNING naming the model: the constant needs updating
|
|
8
|
+
* or no account ever renews by itself again;
|
|
9
|
+
* • any other answer or failure (a 401, a 5xx, a timeout, no network) → no conclusion, ONE log line, no retry;
|
|
10
|
+
* • answered → the credit is back: the bot records a RENEWAL (`onRenewed`) and its spend counter starts over.
|
|
11
|
+
*
|
|
12
|
+
* Never on a subscription account (only `billing: 'api'`; the `default` profile included when it is billed that way and
|
|
13
|
+
* sessions run on the key a Console login left in `~/.claude.json`), never more than once per interval (a day) per account — the
|
|
14
|
+
* attempt is recorded BEFORE the request, in the account's persisted record, so a restart, a hang or a failure does not
|
|
15
|
+
* bring it round again sooner. A real turn that goes through on the account is a recheck too (the bot's turn-cost path),
|
|
16
|
+
* and a refused one moves the mark, so the day starts from it.
|
|
17
|
+
*
|
|
18
|
+
* The request is `POST {ANTHROPIC_BASE_URL or the API}/v1/messages` with `max_tokens: 1` on the cheapest model, a bounded
|
|
19
|
+
* timeout and no retries; the key travels only in the `x-api-key` header and is never logged or part of a result.
|
|
20
|
+
*/
|
|
21
|
+
import type { ClaudeProfileBilling } from './claudeProfiles';
|
|
22
|
+
/** One recheck a day per account. */
|
|
23
|
+
export declare const claudeApiCreditRecheckIntervalMs: number;
|
|
24
|
+
/** How often the bot looks for an account whose day is up (the granularity of «a day», not a rate of requests). */
|
|
25
|
+
export declare const claudeApiCreditRecheckPollMs: number;
|
|
26
|
+
/** The cheapest model: the request only has to be answered or refused for the balance. */
|
|
27
|
+
export declare const claudeApiCreditProbeModel = "claude-haiku-5-5";
|
|
28
|
+
/** The probe is bounded: a hung request ends the attempt (the day is spent) instead of holding the timer. */
|
|
29
|
+
export declare const claudeApiCreditProbeTimeoutMs = 15000;
|
|
30
|
+
/** What the request answered, as the recheck reads it. `inconclusive` names no key and no body: a status or an error kind. */
|
|
31
|
+
export type ClaudeApiCreditProbeOutcome = {
|
|
32
|
+
kind: 'renewed';
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'stillUsedUp';
|
|
35
|
+
}
|
|
36
|
+
/** The API does not know {@link claudeApiCreditProbeModel} any more: every probe would end this way until the constant is updated. */
|
|
37
|
+
| {
|
|
38
|
+
kind: 'modelNotFound';
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'inconclusive';
|
|
41
|
+
reason: string;
|
|
42
|
+
};
|
|
43
|
+
/** The part of `fetch` the probe uses, injectable so a test never reaches the network. */
|
|
44
|
+
export type ClaudeApiCreditProbeFetch = (url: string, init: {
|
|
45
|
+
method: 'POST';
|
|
46
|
+
headers: Record<string, string>;
|
|
47
|
+
body: string;
|
|
48
|
+
signal: AbortSignal;
|
|
49
|
+
}) => Promise<{
|
|
50
|
+
status: number;
|
|
51
|
+
text(): Promise<string>;
|
|
52
|
+
}>;
|
|
53
|
+
/** Where the request goes: `ANTHROPIC_BASE_URL` when it is a plain http(s) URL (what the account's sessions use), else the API. */
|
|
54
|
+
export declare function getClaudeApiCreditProbeUrl(env: Readonly<Record<string, string | undefined>>): string;
|
|
55
|
+
/**
|
|
56
|
+
* @description Ask the API with `apiKey` whether it still refuses for the balance (see the module). One request, no retry;
|
|
57
|
+
* never throws; the key is in the header only.
|
|
58
|
+
*/
|
|
59
|
+
export declare function probeClaudeApiCredit(apiKey: string, options?: {
|
|
60
|
+
url?: string;
|
|
61
|
+
fetchImpl?: ClaudeApiCreditProbeFetch;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
}): Promise<ClaudeApiCreditProbeOutcome>;
|
|
64
|
+
/**
|
|
65
|
+
* @description Is an account's recheck due? Only while it is marked used up, and a full interval after the LATER of the mark
|
|
66
|
+
* (the refusal that set it — fresh news in itself) and the last recheck.
|
|
67
|
+
*/
|
|
68
|
+
export declare function checkIsClaudeApiCreditRecheckDue(input: {
|
|
69
|
+
creditExhaustedAt: string | null;
|
|
70
|
+
creditRecheckedAt: string | null;
|
|
71
|
+
nowMs: number;
|
|
72
|
+
intervalMs: number;
|
|
73
|
+
}): boolean;
|
|
74
|
+
/** What the recheck reads of a profile. */
|
|
75
|
+
export interface ClaudeApiCreditRecheckProfile {
|
|
76
|
+
name: string;
|
|
77
|
+
billing: ClaudeProfileBilling | null;
|
|
78
|
+
/** The refusal the recheck waits a day after: the used-up mark, or the refusal the operator acted on and nothing has confirmed yet. */
|
|
79
|
+
creditExhaustedAt: string | null;
|
|
80
|
+
creditRecheckedAt: string | null;
|
|
81
|
+
}
|
|
82
|
+
/** What the recheck needs from the bot. */
|
|
83
|
+
export interface ClaudeApiCreditRecheckPorts {
|
|
84
|
+
nowMs: () => number;
|
|
85
|
+
intervalMs: number;
|
|
86
|
+
listProfiles: () => ClaudeApiCreditRecheckProfile[];
|
|
87
|
+
/** The key the profile's own sessions use (`readClaudeProfileApiKey`; the default profile's is in the home `.claude.json`); `null` = none the bot can read. */
|
|
88
|
+
readApiKey: (name: string) => string | null;
|
|
89
|
+
probe: (apiKey: string) => Promise<ClaudeApiCreditProbeOutcome>;
|
|
90
|
+
/** Persist that a recheck of `name` was ATTEMPTED at `atIso` (before the request goes out). */
|
|
91
|
+
markRechecked: (name: string, atIso: string) => void;
|
|
92
|
+
/** The balance is back: record the renewal at `atIso`. */
|
|
93
|
+
onRenewed: (name: string, atIso: string) => void;
|
|
94
|
+
log: (line: string) => void;
|
|
95
|
+
/** A line that must not be missed: the recheck cannot work until someone acts (the probe's model is gone). */
|
|
96
|
+
warn: (line: string) => void;
|
|
97
|
+
}
|
|
98
|
+
/** What one pass did to each account whose day was up. */
|
|
99
|
+
export interface ClaudeApiCreditRecheckResult {
|
|
100
|
+
name: string;
|
|
101
|
+
outcome: ClaudeApiCreditProbeOutcome | {
|
|
102
|
+
kind: 'noKey';
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @description The API accounts the bot can read no key for: their used-up credit is never rechecked (an account that runs
|
|
107
|
+
* on an `apiKeyHelper` of its own, a default profile whose `~/.claude.json` holds no key). Said ONCE at boot, naming them.
|
|
108
|
+
*/
|
|
109
|
+
export declare function listClaudeApiCreditProfilesWithoutKey(ports: Pick<ClaudeApiCreditRecheckPorts, 'listProfiles' | 'readApiKey'>): string[];
|
|
110
|
+
/**
|
|
111
|
+
* @description One pass: every API account marked used up whose day is up gets ONE probe, in turn. Subscription accounts and
|
|
112
|
+
* accounts not marked are not touched. An account the bot holds no key for says so in one line (the day is spent too).
|
|
113
|
+
*/
|
|
114
|
+
export declare function runDueClaudeApiCreditRechecks(ports: ClaudeApiCreditRecheckPorts): Promise<ClaudeApiCreditRecheckResult[]>;
|
|
115
|
+
/**
|
|
116
|
+
* @description Run {@link runDueClaudeApiCreditRechecks} now and then every `pollMs`; the timer does not hold the process
|
|
117
|
+
* open, a pass that is still running is not started twice. Returns the stop function.
|
|
118
|
+
*/
|
|
119
|
+
export declare function startClaudeApiCreditRechecks(ports: ClaudeApiCreditRecheckPorts, pollMs: number): () => void;
|
|
120
|
+
//# sourceMappingURL=claudeApiCreditRecheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeApiCreditRecheck.d.ts","sourceRoot":"","sources":["../../src/utils/claudeApiCreditRecheck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D;AAC1D,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,2BAA2B,GAAG;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1D;AAED;;;GAGG;AACH,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,IAAI,CAAC,2BAA2B,EAAE,cAAc,GAAG,YAAY,CAAC,GAAG,MAAM,EAAE,CAEvI;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,4BAA4B,EAAE,CAAC,CA0B/H;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,CAiB3G"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description The daily recheck of an API account the bot believes has used up its credit (`creditExhaustedAt`, shown as
|
|
4
|
+
* «probably used up», `claudeApiCredit.ts`): one tiny request on that account's OWN key, to learn whether the balance is
|
|
5
|
+
* back (the monthly bonus renews by itself, with no sign the bot can read).
|
|
6
|
+
*
|
|
7
|
+
* • refused for the balance («credit balance is too low») → still used up, nothing changes;
|
|
8
|
+
* • the probe's model is gone (404 `not_found_error`) → no conclusion, a WARNING naming the model: the constant needs updating
|
|
9
|
+
* or no account ever renews by itself again;
|
|
10
|
+
* • any other answer or failure (a 401, a 5xx, a timeout, no network) → no conclusion, ONE log line, no retry;
|
|
11
|
+
* • answered → the credit is back: the bot records a RENEWAL (`onRenewed`) and its spend counter starts over.
|
|
12
|
+
*
|
|
13
|
+
* Never on a subscription account (only `billing: 'api'`; the `default` profile included when it is billed that way and
|
|
14
|
+
* sessions run on the key a Console login left in `~/.claude.json`), never more than once per interval (a day) per account — the
|
|
15
|
+
* attempt is recorded BEFORE the request, in the account's persisted record, so a restart, a hang or a failure does not
|
|
16
|
+
* bring it round again sooner. A real turn that goes through on the account is a recheck too (the bot's turn-cost path),
|
|
17
|
+
* and a refused one moves the mark, so the day starts from it.
|
|
18
|
+
*
|
|
19
|
+
* The request is `POST {ANTHROPIC_BASE_URL or the API}/v1/messages` with `max_tokens: 1` on the cheapest model, a bounded
|
|
20
|
+
* timeout and no retries; the key travels only in the `x-api-key` header and is never logged or part of a result.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.claudeApiCreditProbeTimeoutMs = exports.claudeApiCreditProbeModel = exports.claudeApiCreditRecheckPollMs = exports.claudeApiCreditRecheckIntervalMs = void 0;
|
|
24
|
+
exports.getClaudeApiCreditProbeUrl = getClaudeApiCreditProbeUrl;
|
|
25
|
+
exports.probeClaudeApiCredit = probeClaudeApiCredit;
|
|
26
|
+
exports.checkIsClaudeApiCreditRecheckDue = checkIsClaudeApiCreditRecheckDue;
|
|
27
|
+
exports.listClaudeApiCreditProfilesWithoutKey = listClaudeApiCreditProfilesWithoutKey;
|
|
28
|
+
exports.runDueClaudeApiCreditRechecks = runDueClaudeApiCreditRechecks;
|
|
29
|
+
exports.startClaudeApiCreditRechecks = startClaudeApiCreditRechecks;
|
|
30
|
+
const apiErrorRetry_1 = require("../apiErrorRetry");
|
|
31
|
+
/** One recheck a day per account. */
|
|
32
|
+
exports.claudeApiCreditRecheckIntervalMs = 24 * 3_600_000;
|
|
33
|
+
/** How often the bot looks for an account whose day is up (the granularity of «a day», not a rate of requests). */
|
|
34
|
+
exports.claudeApiCreditRecheckPollMs = 30 * 60_000;
|
|
35
|
+
/** The API root the request goes to when `ANTHROPIC_BASE_URL` (the variable Claude Code itself honours) is not set. */
|
|
36
|
+
const anthropicApiRoot = 'https://api.anthropic.com';
|
|
37
|
+
/** The cheapest model: the request only has to be answered or refused for the balance. */
|
|
38
|
+
exports.claudeApiCreditProbeModel = 'claude-haiku-5-5';
|
|
39
|
+
const anthropicApiVersion = '2023-06-01';
|
|
40
|
+
/** The probe is bounded: a hung request ends the attempt (the day is spent) instead of holding the timer. */
|
|
41
|
+
exports.claudeApiCreditProbeTimeoutMs = 15_000;
|
|
42
|
+
/** How much of an error body is read to look for the balance wording. */
|
|
43
|
+
const probeBodyMaxChars = 2_000;
|
|
44
|
+
/** The API's error type for a model id it no longer serves. */
|
|
45
|
+
const modelNotFoundRe = /not_found_error/i;
|
|
46
|
+
/** Where the request goes: `ANTHROPIC_BASE_URL` when it is a plain http(s) URL (what the account's sessions use), else the API. */
|
|
47
|
+
function getClaudeApiCreditProbeUrl(env) {
|
|
48
|
+
const configured = env.ANTHROPIC_BASE_URL?.trim();
|
|
49
|
+
let root = anthropicApiRoot;
|
|
50
|
+
if (configured) {
|
|
51
|
+
try {
|
|
52
|
+
const parsed = new URL(configured);
|
|
53
|
+
if (parsed.protocol === 'http:' || parsed.protocol === 'https:')
|
|
54
|
+
root = configured.replace(/\/+$/, '');
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Not a URL: the sessions' own client would fail on it too; the recheck uses the API.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return `${root}/v1/messages`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @description Ask the API with `apiKey` whether it still refuses for the balance (see the module). One request, no retry;
|
|
64
|
+
* never throws; the key is in the header only.
|
|
65
|
+
*/
|
|
66
|
+
async function probeClaudeApiCredit(apiKey, options = {}) {
|
|
67
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? exports.claudeApiCreditProbeTimeoutMs);
|
|
70
|
+
try {
|
|
71
|
+
const response = await fetchImpl(options.url ?? getClaudeApiCreditProbeUrl(process.env), {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'x-api-key': apiKey, 'anthropic-version': anthropicApiVersion, 'content-type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({ model: exports.claudeApiCreditProbeModel, max_tokens: 1, messages: [{ role: 'user', content: '.' }] }),
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
});
|
|
77
|
+
if (response.status >= 200 && response.status < 300)
|
|
78
|
+
return { kind: 'renewed' };
|
|
79
|
+
const body = (await response.text()).slice(0, probeBodyMaxChars);
|
|
80
|
+
if (apiErrorRetry_1.creditBalanceExhaustedRe.test(body))
|
|
81
|
+
return { kind: 'stillUsedUp' };
|
|
82
|
+
if (response.status === 404 || modelNotFoundRe.test(body))
|
|
83
|
+
return { kind: 'modelNotFound' };
|
|
84
|
+
return { kind: 'inconclusive', reason: `http ${response.status}` };
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return { kind: 'inconclusive', reason: e instanceof Error && e.name === 'AbortError' ? 'timeout' : 'network error' };
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** The milliseconds of an ISO instant; 0 for none or an unreadable one (a mark nobody can date is as old as can be). */
|
|
94
|
+
function parseInstantMs(iso) {
|
|
95
|
+
const parsedMs = iso === null ? Number.NaN : Date.parse(iso);
|
|
96
|
+
return Number.isNaN(parsedMs) ? 0 : parsedMs;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @description Is an account's recheck due? Only while it is marked used up, and a full interval after the LATER of the mark
|
|
100
|
+
* (the refusal that set it — fresh news in itself) and the last recheck.
|
|
101
|
+
*/
|
|
102
|
+
function checkIsClaudeApiCreditRecheckDue(input) {
|
|
103
|
+
if (input.creditExhaustedAt === null)
|
|
104
|
+
return false;
|
|
105
|
+
const lastNewsMs = Math.max(parseInstantMs(input.creditExhaustedAt), parseInstantMs(input.creditRecheckedAt));
|
|
106
|
+
return input.nowMs - lastNewsMs >= input.intervalMs;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @description The API accounts the bot can read no key for: their used-up credit is never rechecked (an account that runs
|
|
110
|
+
* on an `apiKeyHelper` of its own, a default profile whose `~/.claude.json` holds no key). Said ONCE at boot, naming them.
|
|
111
|
+
*/
|
|
112
|
+
function listClaudeApiCreditProfilesWithoutKey(ports) {
|
|
113
|
+
return ports.listProfiles().filter((profile) => profile.billing === 'api' && ports.readApiKey(profile.name) === null).map((profile) => profile.name);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @description One pass: every API account marked used up whose day is up gets ONE probe, in turn. Subscription accounts and
|
|
117
|
+
* accounts not marked are not touched. An account the bot holds no key for says so in one line (the day is spent too).
|
|
118
|
+
*/
|
|
119
|
+
async function runDueClaudeApiCreditRechecks(ports) {
|
|
120
|
+
const results = [];
|
|
121
|
+
for (const profile of ports.listProfiles()) {
|
|
122
|
+
const nowMs = ports.nowMs();
|
|
123
|
+
if (profile.billing !== 'api')
|
|
124
|
+
continue;
|
|
125
|
+
if (!checkIsClaudeApiCreditRecheckDue({ creditExhaustedAt: profile.creditExhaustedAt, creditRecheckedAt: profile.creditRecheckedAt, nowMs, intervalMs: ports.intervalMs }))
|
|
126
|
+
continue;
|
|
127
|
+
const atIso = new Date(nowMs).toISOString();
|
|
128
|
+
ports.markRechecked(profile.name, atIso);
|
|
129
|
+
const apiKey = ports.readApiKey(profile.name);
|
|
130
|
+
if (apiKey === null) {
|
|
131
|
+
ports.log(`[credit] ${profile.name}: no API key the bot can read for the account, so its used-up credit cannot be rechecked`);
|
|
132
|
+
results.push({ name: profile.name, outcome: { kind: 'noKey' } });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const outcome = await ports.probe(apiKey);
|
|
136
|
+
results.push({ name: profile.name, outcome });
|
|
137
|
+
if (outcome.kind === 'renewed') {
|
|
138
|
+
ports.log(`[credit] ${profile.name}: the daily recheck was answered — the credit is back`);
|
|
139
|
+
ports.onRenewed(profile.name, atIso);
|
|
140
|
+
}
|
|
141
|
+
else if (outcome.kind === 'modelNotFound') {
|
|
142
|
+
ports.warn(`[credit] ${profile.name}: the daily recheck's model "${exports.claudeApiCreditProbeModel}" was not found by the API (404) — update claudeApiCreditProbeModel; used-up credits are not rechecked until then`);
|
|
143
|
+
}
|
|
144
|
+
else if (outcome.kind === 'inconclusive') {
|
|
145
|
+
ports.log(`[credit] ${profile.name}: the daily recheck gave no answer about the balance (${outcome.reason}); asked again in a day`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @description Run {@link runDueClaudeApiCreditRechecks} now and then every `pollMs`; the timer does not hold the process
|
|
152
|
+
* open, a pass that is still running is not started twice. Returns the stop function.
|
|
153
|
+
*/
|
|
154
|
+
function startClaudeApiCreditRechecks(ports, pollMs) {
|
|
155
|
+
const unreadable = listClaudeApiCreditProfilesWithoutKey(ports);
|
|
156
|
+
if (unreadable.length > 0) {
|
|
157
|
+
ports.log(`[credit] ${unreadable.join(', ')}: billed to API credits, but the bot can read no API key for ${unreadable.length === 1 ? 'it' : 'them'} (it runs on an apiKeyHelper or a variable of its own, or no Console login's key is stored for it — or /accounts has not probed it yet) — a used-up credit there is never rechecked`);
|
|
158
|
+
}
|
|
159
|
+
let isRunning = false;
|
|
160
|
+
const runPass = () => {
|
|
161
|
+
if (isRunning)
|
|
162
|
+
return;
|
|
163
|
+
isRunning = true;
|
|
164
|
+
runDueClaudeApiCreditRechecks(ports)
|
|
165
|
+
.catch((e) => ports.log(`[credit] the daily recheck failed: ${e instanceof Error ? e.message : 'unknown error'}`))
|
|
166
|
+
.finally(() => { isRunning = false; });
|
|
167
|
+
};
|
|
168
|
+
runPass();
|
|
169
|
+
const timer = setInterval(runPass, pollMs);
|
|
170
|
+
timer.unref?.();
|
|
171
|
+
return () => clearInterval(timer);
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=claudeApiCreditRecheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeApiCreditRecheck.js","sourceRoot":"","sources":["../../src/utils/claudeApi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,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;aACjH,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC;IACF,OAAO,EAAE,CAAC;IACV,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3C,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IAChB,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* default prompt: the loaded skills were not named and no next-steps checklist
|
|
10
10
|
* closed the summary, so the continuing session silently stopped following those
|
|
11
11
|
* skills. The hook adds the resume guidance (`compactionResumeGuidance`: the skills
|
|
12
|
-
* to load again, then that checklist). Claude Code runs `PreCompact` hooks before
|
|
12
|
+
* to load again, the self-review section the bot posts to the topic, then that checklist). Claude Code runs `PreCompact` hooks before
|
|
13
13
|
* EVERY compaction (`trigger` `auto` and `manual`) and appends a hook's stdout to
|
|
14
14
|
* that compaction's custom instructions — measured on v2.1.289: an
|
|
15
15
|
* overflow-triggered compaction's summary opened with the line the hook printed.
|
|
@@ -18,8 +18,13 @@
|
|
|
18
18
|
*
|
|
19
19
|
* A bot-issued compaction already carries the same text, so the hook prints
|
|
20
20
|
* nothing when the compaction's `custom_instructions` (part of the JSON the hook
|
|
21
|
-
* reads on stdin) already contain the resume guidance
|
|
22
|
-
* next-steps checklist) — otherwise the model would get the
|
|
21
|
+
* reads on stdin) already contain the resume guidance both variants share (the
|
|
22
|
+
* loaded skills and the next-steps checklist) — otherwise the model would get the
|
|
23
|
+
* instruction twice.
|
|
24
|
+
*
|
|
25
|
+
* The self-review section is the part `/compact_self_review` switches: the hook runs inside the agent's process, long after
|
|
26
|
+
* the bot started it, so it looks for the flag the bot keeps for the session (`utils/compactSelfReviewFlags.ts`, named by the
|
|
27
|
+
* `session_id` of its stdin) and prints the instruction without the section request while the flag exists.
|
|
23
28
|
*
|
|
24
29
|
* The same launch settings carry the shared todo lists' `PostToolUse` hook
|
|
25
30
|
* (`todos/midTurn.ts`): it prints the session's inbox — the project board's
|
|
@@ -33,21 +38,24 @@
|
|
|
33
38
|
export declare const claudeCompactHookSettingsFileName = "claude-compact-hook.json";
|
|
34
39
|
/**
|
|
35
40
|
* @description The instruction the hook adds to a compaction the bot did not
|
|
36
|
-
* issue: D3 + the resume guidance
|
|
41
|
+
* issue: D3 + the resume guidance, with the self-review section while `/compact_self_review` is on for the session's topic
|
|
42
|
+
* and without it while off. No closing section — that one exists for the
|
|
37
43
|
* bot's own idle-compaction report, which an overflow compaction never feeds; the
|
|
38
44
|
* checklist then ends the summary itself.
|
|
39
45
|
*/
|
|
40
|
-
export declare function getHookCompactionInstruction(): string;
|
|
46
|
+
export declare function getHookCompactionInstruction(isWithInstructionGaps: boolean): string;
|
|
41
47
|
/**
|
|
42
|
-
* @description Build the hook's shell command: print `
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* that it qualifies.
|
|
48
|
+
* @description Build the hook's shell command: print nothing when the hook's stdin (the `PreCompact` input JSON) already
|
|
49
|
+
* contains `alreadySentMarker`; otherwise print `instructionWithoutGaps` when a flag named after the input's `session_id`
|
|
50
|
+
* exists in `offFlagDir` (the topic's `/compact_self_review` is off, `utils/compactSelfReviewFlags.ts`) and `instruction` when it
|
|
51
|
+
* does not. The marker is matched as a fixed string against the raw JSON, so it must be text JSON leaves unescaped — the
|
|
52
|
+
* caller passes the resume guidance both variants share, and a test pins that it qualifies.
|
|
47
53
|
*/
|
|
48
54
|
export declare function buildPreCompactHookCommand(input: {
|
|
49
55
|
instruction: string;
|
|
56
|
+
instructionWithoutGaps: string;
|
|
50
57
|
alreadySentMarker: string;
|
|
58
|
+
offFlagDir: string;
|
|
51
59
|
}): string;
|
|
52
60
|
/** One command hook with no matcher (every compaction, every tool). */
|
|
53
61
|
type CommandHookGroups = Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCompactHook.d.ts","sourceRoot":"","sources":["../../src/utils/claudeCompactHook.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claudeCompactHook.d.ts","sourceRoot":"","sources":["../../src/utils/claudeCompactHook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAgBH;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,qBAAqB,EAAE,OAAO,GAAG,MAAM,CAOnF;AASD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAQT;AAED,uEAAuE;AACvE,KAAK,iBAAiB,GAAG,KAAK,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEvF;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG;IACpG,KAAK,EAAE;QAAE,UAAU,EAAE,iBAAiB,CAAC;QAAC,WAAW,EAAE,iBAAiB,CAAA;KAAE,CAAC;CAC1E,CAOA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,EAAE,CAiBxG"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* default prompt: the loaded skills were not named and no next-steps checklist
|
|
11
11
|
* closed the summary, so the continuing session silently stopped following those
|
|
12
12
|
* skills. The hook adds the resume guidance (`compactionResumeGuidance`: the skills
|
|
13
|
-
* to load again, then that checklist). Claude Code runs `PreCompact` hooks before
|
|
13
|
+
* to load again, the self-review section the bot posts to the topic, then that checklist). Claude Code runs `PreCompact` hooks before
|
|
14
14
|
* EVERY compaction (`trigger` `auto` and `manual`) and appends a hook's stdout to
|
|
15
15
|
* that compaction's custom instructions — measured on v2.1.289: an
|
|
16
16
|
* overflow-triggered compaction's summary opened with the line the hook printed.
|
|
@@ -19,8 +19,13 @@
|
|
|
19
19
|
*
|
|
20
20
|
* A bot-issued compaction already carries the same text, so the hook prints
|
|
21
21
|
* nothing when the compaction's `custom_instructions` (part of the JSON the hook
|
|
22
|
-
* reads on stdin) already contain the resume guidance
|
|
23
|
-
* next-steps checklist) — otherwise the model would get the
|
|
22
|
+
* reads on stdin) already contain the resume guidance both variants share (the
|
|
23
|
+
* loaded skills and the next-steps checklist) — otherwise the model would get the
|
|
24
|
+
* instruction twice.
|
|
25
|
+
*
|
|
26
|
+
* The self-review section is the part `/compact_self_review` switches: the hook runs inside the agent's process, long after
|
|
27
|
+
* the bot started it, so it looks for the flag the bot keeps for the session (`utils/compactSelfReviewFlags.ts`, named by the
|
|
28
|
+
* `session_id` of its stdin) and prints the instruction without the section request while the flag exists.
|
|
24
29
|
*
|
|
25
30
|
* The same launch settings carry the shared todo lists' `PostToolUse` hook
|
|
26
31
|
* (`todos/midTurn.ts`): it prints the session's inbox — the project board's
|
|
@@ -38,6 +43,7 @@ exports.prepareClaudeCompactHookFlags = prepareClaudeCompactHookFlags;
|
|
|
38
43
|
const fs_1 = __importDefault(require("fs"));
|
|
39
44
|
const path_1 = __importDefault(require("path"));
|
|
40
45
|
const compactOnIdle_1 = require("./compactOnIdle");
|
|
46
|
+
const compactSelfReviewFlags_1 = require("./compactSelfReviewFlags");
|
|
41
47
|
const tmuxExec_1 = require("./tmuxExec");
|
|
42
48
|
const claudeProfiles_1 = require("./claudeProfiles");
|
|
43
49
|
const claudeApiKeyHelper_1 = require("./claudeApiKeyHelper");
|
|
@@ -50,27 +56,40 @@ const midTurn_1 = require("../todos/midTurn");
|
|
|
50
56
|
exports.claudeCompactHookSettingsFileName = 'claude-compact-hook.json';
|
|
51
57
|
/**
|
|
52
58
|
* @description The instruction the hook adds to a compaction the bot did not
|
|
53
|
-
* issue: D3 + the resume guidance
|
|
59
|
+
* issue: D3 + the resume guidance, with the self-review section while `/compact_self_review` is on for the session's topic
|
|
60
|
+
* and without it while off. No closing section — that one exists for the
|
|
54
61
|
* bot's own idle-compaction report, which an overflow compaction never feeds; the
|
|
55
62
|
* checklist then ends the summary itself.
|
|
56
63
|
*/
|
|
57
|
-
function getHookCompactionInstruction() {
|
|
64
|
+
function getHookCompactionInstruction(isWithInstructionGaps) {
|
|
58
65
|
return (0, compactOnIdle_1.buildCompactionInstruction)({
|
|
59
66
|
bakesSummaryGuidance: false,
|
|
60
67
|
summaryGuidance: compactOnIdle_1.compactionSummaryGuidance,
|
|
61
68
|
bakesResumeGuidance: false,
|
|
62
|
-
resumeGuidance: compactOnIdle_1.
|
|
69
|
+
resumeGuidance: (0, compactOnIdle_1.getCompactionResumeGuidance)(isWithInstructionGaps),
|
|
63
70
|
}) ?? '';
|
|
64
71
|
}
|
|
65
72
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
* The shell that reads the session id out of the hook's stdin JSON (`session_id`, which is what the bot named the flag
|
|
74
|
+
* after) and empties it unless it is made of the characters a flag name may hold: the text comes from outside the bot and
|
|
75
|
+
* must never take the path out of the flag folder.
|
|
76
|
+
*/
|
|
77
|
+
const readSessionIdFromHookInputShell = `sed -n 's/.*"session_id" *: *"\\([^"]*\\)".*/\\1/p'`;
|
|
78
|
+
/**
|
|
79
|
+
* @description Build the hook's shell command: print nothing when the hook's stdin (the `PreCompact` input JSON) already
|
|
80
|
+
* contains `alreadySentMarker`; otherwise print `instructionWithoutGaps` when a flag named after the input's `session_id`
|
|
81
|
+
* exists in `offFlagDir` (the topic's `/compact_self_review` is off, `utils/compactSelfReviewFlags.ts`) and `instruction` when it
|
|
82
|
+
* does not. The marker is matched as a fixed string against the raw JSON, so it must be text JSON leaves unescaped — the
|
|
83
|
+
* caller passes the resume guidance both variants share, and a test pins that it qualifies.
|
|
71
84
|
*/
|
|
72
85
|
function buildPreCompactHookCommand(input) {
|
|
73
|
-
return
|
|
86
|
+
return [
|
|
87
|
+
'input=$(cat)',
|
|
88
|
+
`if printf '%s' "$input" | grep -qF -e ${(0, tmuxExec_1.shellSingleQuote)(input.alreadySentMarker)}; then exit 0; fi`,
|
|
89
|
+
`session=$(printf '%s' "$input" | ${readSessionIdFromHookInputShell})`,
|
|
90
|
+
`case "$session" in ''|*[!A-Za-z0-9_-]*) session= ;; esac`,
|
|
91
|
+
`if [ -n "$session" ] && [ -e ${(0, tmuxExec_1.shellSingleQuote)(input.offFlagDir)}/"$session" ]; then printf '%s\\n' ${(0, tmuxExec_1.shellSingleQuote)(input.instructionWithoutGaps)}; else printf '%s\\n' ${(0, tmuxExec_1.shellSingleQuote)(input.instruction)}; fi`,
|
|
92
|
+
].join('; ');
|
|
74
93
|
}
|
|
75
94
|
/**
|
|
76
95
|
* @description The `--settings` payload: the `PreCompact` command hook (auto AND manual compactions) and the shared
|
|
@@ -100,8 +119,10 @@ function buildClaudeLaunchHookSettings(commands) {
|
|
|
100
119
|
function prepareClaudeCompactHookFlags(dataDir, configDir = null) {
|
|
101
120
|
const hookSettings = buildClaudeLaunchHookSettings({
|
|
102
121
|
preCompact: buildPreCompactHookCommand({
|
|
103
|
-
instruction: getHookCompactionInstruction(),
|
|
104
|
-
|
|
122
|
+
instruction: getHookCompactionInstruction(true),
|
|
123
|
+
instructionWithoutGaps: getHookCompactionInstruction(false),
|
|
124
|
+
alreadySentMarker: compactOnIdle_1.compactionResumeGuidanceWithoutGaps,
|
|
125
|
+
offFlagDir: (0, compactSelfReviewFlags_1.getClaudeCompactSelfReviewOffDir)(dataDir),
|
|
105
126
|
}),
|
|
106
127
|
postToolUse: (0, midTurn_1.buildTodoInboxHookCommand)((0, midTurn_1.getTodoInboxDir)(dataDir)),
|
|
107
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCompactHook.js","sourceRoot":"","sources":["../../src/utils/claudeCompactHook.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"claudeCompactHook.js","sourceRoot":"","sources":["../../src/utils/claudeCompactHook.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;;;;AA8BH,oEAOC;AAgBD,gEAaC;AAUD,sEASC;AAcD,sEAiBC;AAlHD,4CAAoB;AACpB,gDAAwB;AACxB,mDAKyB;AACzB,qEAA4E;AAC5E,yCAA8C;AAC9C,qDAAoG;AACpG,6DAAuE;AACvE,8CAA8E;AAE9E;;;;GAIG;AACU,QAAA,iCAAiC,GAAG,0BAA0B,CAAC;AAE5E;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAAC,qBAA8B;IACzE,OAAO,IAAA,0CAA0B,EAAC;QAChC,oBAAoB,EAAE,KAAK;QAC3B,eAAe,EAAE,yCAAyB;QAC1C,mBAAmB,EAAE,KAAK;QAC1B,cAAc,EAAE,IAAA,2CAA2B,EAAC,qBAAqB,CAAC;KACnE,CAAC,IAAI,EAAE,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,+BAA+B,GAAG,qDAAqD,CAAC;AAE9F;;;;;;GAMG;AACH,SAAgB,0BAA0B,CAAC,KAK1C;IACC,OAAO;QACL,cAAc;QACd,yCAAyC,IAAA,2BAAgB,EAAC,KAAK,CAAC,iBAAiB,CAAC,mBAAmB;QACrG,oCAAoC,+BAA+B,GAAG;QACtE,0DAA0D;QAC1D,gCAAgC,IAAA,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
|
1
1
|
import type { ClaudeProfileBilling } from './claudeProfiles';
|
|
2
2
|
import { type ClaudeApiSpend } from './claudeApiSpend';
|
|
3
|
+
import { type ClaudeApiCreditAnchor, type ClaudeApiCreditSpend } from './claudeApiCredit';
|
|
3
4
|
import { type ClaudeUsageSnapshot } from './claudeUsage';
|
|
4
5
|
/**
|
|
5
6
|
* What the lines read of a profile: its usage snapshot, limit mark, billing and used-up-credits mark (a state record and
|
|
6
7
|
* a usage view both fit).
|
|
7
8
|
*/
|
|
8
9
|
export interface ClaudeProfileUsageSource {
|
|
10
|
+
/** The profile's name: the expired-credit line names the command that sets the new figure for it. */
|
|
11
|
+
name?: string;
|
|
9
12
|
usage?: ClaudeUsageSnapshot;
|
|
10
13
|
limitedUntil?: string | null;
|
|
11
14
|
billing?: ClaudeProfileBilling | null;
|
|
12
15
|
creditExhaustedAt?: string | null;
|
|
13
16
|
apiSpend?: ClaudeApiSpend;
|
|
17
|
+
/** The operator's Console figure (`utils/claudeApiCredit.ts`): an account billed to API credits shows its estimate. */
|
|
18
|
+
creditAnchor?: ClaudeApiCreditAnchor;
|
|
19
|
+
creditSpend?: ClaudeApiCreditSpend;
|
|
20
|
+
/** When the bot detected that the used-up credit was back (the credit period starts there). */
|
|
21
|
+
creditRenewedAt?: string;
|
|
22
|
+
/** The refusal the operator acted on: the account is usable again, the renewal still awaited. */
|
|
23
|
+
creditUnconfirmedSince?: string;
|
|
14
24
|
}
|
|
15
25
|
/**
|
|
16
26
|
* @description The profile's usage as display lines: the windows as `used% 🔄 reset` — 5h and weekly always (`—`
|
|
17
27
|
* for one the snapshot lacks), Fable only when the account HAS that window (a corporate seat has none: nothing
|
|
18
28
|
* is written about it) — `(stale)` when the last poll could not refresh, and the limit mark while it holds, the
|
|
19
29
|
* reset instant in `timezone`, and the used-up-credits mark while it holds. An account billed to API credits has no
|
|
20
|
-
* windows (its row already says it pays per use): what it spent through the bot
|
|
30
|
+
* windows (its row already says it pays per use): what it spent through the bot and the one credit line
|
|
31
|
+
* (`utils/claudeApiCredit.ts`: the spend of the credit period, the operator's figure when there is one, and the «probably
|
|
32
|
+
* used up» sign in place of the plain used-up mark). The lines carry the
|
|
21
33
|
* locale's own indentation (they hang under a row); empty for an account with nothing to show.
|
|
22
34
|
*/
|
|
23
35
|
export declare function formatClaudeProfileUsageLines(source: ClaudeProfileUsageSource | undefined, timezone: string, nowMs: number): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeProfileUsageLines.d.ts","sourceRoot":"","sources":["../../src/utils/claudeProfileUsageLines.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,eAAe,CAAC;AAEvB;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"claudeProfileUsageLines.d.ts","sourceRoot":"","sources":["../../src/utils/claudeProfileUsageLines.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAA8B,KAAK,qBAAqB,EAAgC,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACpJ,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,eAAe,CAAC;AAEvB;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,qGAAqG;IACrG,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