charness 3.10.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 +171 -0
- package/DEVELOPMENT.md +3 -3
- package/README.md +3 -2
- 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 +331 -152
- 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/botCore.d.ts +1 -0
- package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
- 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 +12 -9
- 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 +151 -30
- package/dist/connectors/telegram/commands/runners.js.map +1 -1
- package/dist/connectors/telegram/foldedMessage.d.ts +24 -0
- package/dist/connectors/telegram/foldedMessage.d.ts.map +1 -0
- package/dist/connectors/telegram/foldedMessage.js +39 -0
- package/dist/connectors/telegram/foldedMessage.js.map +1 -0
- package/dist/connectors/telegram/inbound.d.ts +24 -1
- package/dist/connectors/telegram/inbound.d.ts.map +1 -1
- package/dist/connectors/telegram/inbound.js +77 -1
- package/dist/connectors/telegram/inbound.js.map +1 -1
- package/dist/connectors/telegram/renderAgentHtml.d.ts +15 -0
- package/dist/connectors/telegram/renderAgentHtml.d.ts.map +1 -1
- package/dist/connectors/telegram/renderAgentHtml.js +11 -1
- package/dist/connectors/telegram/renderAgentHtml.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/connectors/telegram/unpinMessages.d.ts +12 -0
- package/dist/connectors/telegram/unpinMessages.d.ts.map +1 -0
- package/dist/connectors/telegram/unpinMessages.js +44 -0
- package/dist/connectors/telegram/unpinMessages.js.map +1 -0
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/de.js +63 -11
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +63 -11
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +63 -11
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +63 -11
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +63 -11
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +63 -11
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +63 -11
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +63 -11
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +63 -11
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +63 -11
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +63 -11
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +63 -11
- 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/outputTrace.d.ts +6 -0
- package/dist/outputTrace.d.ts.map +1 -1
- package/dist/outputTrace.js +13 -0
- package/dist/outputTrace.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 +6 -4
- 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/isolatedCommand.d.ts +0 -2
- package/dist/runnerUtility/isolatedCommand.d.ts.map +1 -1
- package/dist/runnerUtility/isolatedCommand.js +4 -11
- package/dist/runnerUtility/isolatedCommand.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/checkRun.d.ts +9 -10
- package/dist/scheduler/checkRun.d.ts.map +1 -1
- package/dist/scheduler/checkRun.js +8 -16
- package/dist/scheduler/checkRun.js.map +1 -1
- package/dist/scheduler/checkStatus.d.ts +4 -5
- package/dist/scheduler/checkStatus.d.ts.map +1 -1
- package/dist/scheduler/checkStatus.js +11 -15
- package/dist/scheduler/checkStatus.js.map +1 -1
- package/dist/scheduler/delivery.d.ts +80 -37
- package/dist/scheduler/delivery.d.ts.map +1 -1
- package/dist/scheduler/delivery.js +121 -68
- package/dist/scheduler/delivery.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts +13 -5
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +84 -34
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/scheduler/recurrence.d.ts +32 -0
- package/dist/scheduler/recurrence.d.ts.map +1 -1
- package/dist/scheduler/recurrence.js +56 -18
- package/dist/scheduler/recurrence.js.map +1 -1
- package/dist/scheduler/scheduleText.d.ts +7 -0
- package/dist/scheduler/scheduleText.d.ts.map +1 -0
- package/dist/scheduler/scheduleText.js +55 -0
- package/dist/scheduler/scheduleText.js.map +1 -0
- package/dist/scheduler/store.d.ts +8 -2
- package/dist/scheduler/store.d.ts.map +1 -1
- package/dist/scheduler/store.js +25 -4
- package/dist/scheduler/store.js.map +1 -1
- package/dist/scheduler/types.d.ts +4 -10
- package/dist/scheduler/types.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.d.ts +49 -11
- package/dist/scheduler/workerWatch.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.js +57 -13
- 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 +97 -36
- package/dist/utils/claudeUsage.d.ts.map +1 -1
- package/dist/utils/claudeUsage.js +142 -61
- package/dist/utils/claudeUsage.js.map +1 -1
- package/dist/utils/claudeUsageRefresher.d.ts +27 -3
- package/dist/utils/claudeUsageRefresher.d.ts.map +1 -1
- package/dist/utils/claudeUsageRefresher.js +113 -14
- package/dist/utils/claudeUsageRefresher.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/forwardedMark.d.ts +54 -0
- package/dist/utils/forwardedMark.d.ts.map +1 -0
- package/dist/utils/forwardedMark.js +80 -0
- package/dist/utils/forwardedMark.js.map +1 -0
- package/dist/utils/limitHeldPrompts.d.ts +8 -2
- package/dist/utils/limitHeldPrompts.d.ts.map +1 -1
- package/dist/utils/limitHeldPrompts.js +11 -4
- package/dist/utils/limitHeldPrompts.js.map +1 -1
- package/dist/utils/messageContext.d.ts +54 -0
- package/dist/utils/messageContext.d.ts.map +1 -0
- package/dist/utils/messageContext.js +58 -0
- package/dist/utils/messageContext.js.map +1 -0
- 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/openCodeUsage.d.ts +10 -3
- package/dist/utils/openCodeUsage.d.ts.map +1 -1
- package/dist/utils/openCodeUsage.js +19 -5
- package/dist/utils/openCodeUsage.js.map +1 -1
- package/dist/utils/replyQuote.d.ts +11 -26
- package/dist/utils/replyQuote.d.ts.map +1 -1
- package/dist/utils/replyQuote.js +9 -31
- package/dist/utils/replyQuote.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/dist/utils/stripControlCharacters.d.ts +8 -0
- package/dist/utils/stripControlCharacters.d.ts.map +1 -0
- package/dist/utils/stripControlCharacters.js +16 -0
- package/dist/utils/stripControlCharacters.js.map +1 -0
- package/dist/utils/telegramError.d.ts +6 -0
- package/dist/utils/telegramError.d.ts.map +1 -1
- package/dist/utils/telegramError.js +30 -0
- package/dist/utils/telegramError.js.map +1 -1
- package/dist/utils/topicRequest.d.ts +13 -0
- package/dist/utils/topicRequest.d.ts.map +1 -1
- package/dist/utils/topicRequest.js +10 -0
- package/dist/utils/topicRequest.js.map +1 -1
- package/dist/utils/usageRefreshBudget.d.ts.map +1 -1
- package/dist/utils/usageRefreshBudget.js +4 -10
- package/dist/utils/usageRefreshBudget.js.map +1 -1
- package/dist/utils/waitUpTo.d.ts +8 -0
- package/dist/utils/waitUpTo.d.ts.map +1 -0
- package/dist/utils/waitUpTo.js +20 -0
- package/dist/utils/waitUpTo.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 -156
- package/remoteRun/pickNode.sh +0 -65
package/dist/bot.js
CHANGED
|
@@ -133,6 +133,8 @@ const progressLine_1 = require("./progressLine");
|
|
|
133
133
|
const startupPromptBuffer_1 = require("./startupPromptBuffer");
|
|
134
134
|
const renderAgentHtml_1 = require("./connectors/telegram/renderAgentHtml");
|
|
135
135
|
const messageSplit_1 = require("./connectors/telegram/messageSplit");
|
|
136
|
+
const foldedMessage_1 = require("./connectors/telegram/foldedMessage");
|
|
137
|
+
const unpinMessages_1 = require("./connectors/telegram/unpinMessages");
|
|
136
138
|
const outputFlushPlan_1 = require("./connectors/telegram/outputFlushPlan");
|
|
137
139
|
const outputBacklogGlue_1 = require("./connectors/telegram/outputBacklogGlue");
|
|
138
140
|
const typingActive_1 = require("./utils/typingActive");
|
|
@@ -155,6 +157,8 @@ const adoptedToolList_1 = require("./utils/adoptedToolList");
|
|
|
155
157
|
const lostWork_1 = require("./utils/lostWork");
|
|
156
158
|
const jsonStreamPendingWork_1 = require("./utils/jsonStreamPendingWork");
|
|
157
159
|
const compactOnIdle_1 = require("./utils/compactOnIdle");
|
|
160
|
+
const compactSelfReviewFlags_1 = require("./utils/compactSelfReviewFlags");
|
|
161
|
+
const openCodeCompactPlugin_1 = require("./utils/openCodeCompactPlugin");
|
|
158
162
|
const fileSendService_1 = require("./utils/fileSendService");
|
|
159
163
|
const messageSendService_1 = require("./utils/messageSendService");
|
|
160
164
|
const fileSendGateway_1 = require("./connectors/telegram/fileSendGateway");
|
|
@@ -187,7 +191,7 @@ const updatePolicy_1 = require("./selfUpdate/updatePolicy");
|
|
|
187
191
|
const updateRuntime_1 = require("./selfUpdate/updateRuntime");
|
|
188
192
|
const threadContextPreamble_1 = require("./threadContextPreamble");
|
|
189
193
|
const pinnedBannerSkipDecision_1 = require("./utils/pinnedBannerSkipDecision");
|
|
190
|
-
const
|
|
194
|
+
const messageContext_1 = require("./utils/messageContext");
|
|
191
195
|
const fileIntake_1 = require("./connectors/telegram/fileIntake");
|
|
192
196
|
const mediaGroupCollector_1 = require("./utils/mediaGroupCollector");
|
|
193
197
|
const openCodeSessionTitle_1 = require("./openCodeSessionTitle");
|
|
@@ -249,6 +253,7 @@ const hubAddress_1 = require("./runners/hubAddress");
|
|
|
249
253
|
const hubAddressCandidates_1 = require("./runners/hubAddressCandidates");
|
|
250
254
|
const hubPaths_1 = require("./runners/hubPaths");
|
|
251
255
|
const hubPairing_1 = require("./runners/hubPairing");
|
|
256
|
+
const runnerGroups_1 = require("./runners/runnerGroups");
|
|
252
257
|
const runnersOverview_1 = require("./runners/runnersOverview");
|
|
253
258
|
const ssh_1 = require("./remoteRun/ssh");
|
|
254
259
|
const claudeAccounts_1 = require("./connectors/telegram/commands/claudeAccounts");
|
|
@@ -273,6 +278,10 @@ const backendSwitchPlan_1 = require("./utils/backendSwitchPlan");
|
|
|
273
278
|
const selfUpdate_1 = require("./connectors/telegram/commands/selfUpdate");
|
|
274
279
|
const stt_1 = require("./connectors/telegram/commands/stt");
|
|
275
280
|
const claudeApiSpend_1 = require("./utils/claudeApiSpend");
|
|
281
|
+
const claudeProfileUsageViews_1 = require("./utils/claudeProfileUsageViews");
|
|
282
|
+
const claudeApiAgentStop_1 = require("./utils/claudeApiAgentStop");
|
|
283
|
+
const claudeApiCredit_1 = require("./utils/claudeApiCredit");
|
|
284
|
+
const claudeApiCreditRecheck_1 = require("./utils/claudeApiCreditRecheck");
|
|
276
285
|
const claudeProfileUsageLines_1 = require("./utils/claudeProfileUsageLines");
|
|
277
286
|
const resolveBinary_1 = require("./utils/resolveBinary");
|
|
278
287
|
const runnerSummary_1 = require("./remoteRun/runnerSummary");
|
|
@@ -850,22 +859,25 @@ const noTopicRequest = { header: '', requestId: null };
|
|
|
850
859
|
* the topic's view has requests on and the text is not a slash command. Called
|
|
851
860
|
* at the USER entry points — text, voice, file, album, `/schedule`, the
|
|
852
861
|
* scheduler's forward — BEFORE the prompt is forwarded or buffered: the ledger
|
|
853
|
-
* keeps the header + text as the request's prompt
|
|
854
|
-
* never took it in), and `createRequest` resolves only once the id is on disk. A
|
|
862
|
+
* keeps the header + text as the request's prompt, with the message context (reply
|
|
863
|
+
* quote, forwarded mark) folded in (re-posted when the session never took it in), and `createRequest` resolves only once the id is on disk. A
|
|
855
864
|
* conversation of another platform opens its requests itself (Jira: J5). A
|
|
856
865
|
* `null` intake is a prompt that is not a request by rule — an answer to the
|
|
857
866
|
* agent's own question, delivered as a prompt. The intake's requester decides
|
|
858
867
|
* which open request, if any, the new one supersedes (`requestGroup.ts`); the
|
|
859
868
|
* header then names the replaced ones.
|
|
860
869
|
*/
|
|
861
|
-
async function openTopicRequest(key, text, intake) {
|
|
870
|
+
async function openTopicRequest(key, text, intake, messageContext) {
|
|
862
871
|
if (intake === null || !topicRequestLedger || !(0, sessionKeyCodec_1.checkIsTelegramKey)(key))
|
|
863
872
|
return noTopicRequest;
|
|
864
873
|
const view = state.getDisplayPrefs(key).view;
|
|
865
|
-
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0,
|
|
874
|
+
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0, messageContext_1.checkIsSlashCommandPrompt)(text, messageContext)))
|
|
866
875
|
return noTopicRequest;
|
|
876
|
+
// The ledger keeps the prompt as it is posted — the message context folded in — because a stored prompt is what is posted
|
|
877
|
+
// AGAIN when the session never took it in; the raw text would come back without the forwarded mark or the quote.
|
|
878
|
+
const promptBody = getPromptWithThreadMessageContext(key, text, messageContext);
|
|
867
879
|
const request = await topicRequestLedger.createRequest(key, (0, topicRequest_1.getTopicRequestOrigin)(intake), {
|
|
868
|
-
createPrompt: (requestId, supersededRequestIds) =>
|
|
880
|
+
createPrompt: (requestId, supersededRequestIds) => (0, topicRequest_1.buildTopicRequestPrompt)({ requestId, source: intake.source, view, supersededRequestIds, promptBody }),
|
|
869
881
|
});
|
|
870
882
|
return { header: (0, topicRequest_1.buildTopicRequestHeader)(request.id, intake.source, view, request.supersededRequestIds), requestId: request.id };
|
|
871
883
|
}
|
|
@@ -2197,6 +2209,7 @@ const { cancelPendingLogin, checkIsAuthLoginAwaitingCode, cancelClaudeAuthLogin,
|
|
|
2197
2209
|
execFileAsync,
|
|
2198
2210
|
onClaudeProfileAuthStatus: (key, profile, status) => claudeProfileAuthStatusSink?.(key, profile, status) ?? Promise.resolve(),
|
|
2199
2211
|
onClaudeProfileApiKey: (key, profile, apiKey) => claudeProfileApiKeySink?.(key, profile, apiKey) ?? Promise.resolve((0, i18n_1.t)('account.apiKeyNoDirectory', { name: profile.name })),
|
|
2212
|
+
checkIsProfileMissingFromLimitsList: (name) => (0, fallbackChain_1.checkIsClaudeProfileMissingFromChain)(state.getFallbackChain(), name),
|
|
2200
2213
|
});
|
|
2201
2214
|
/**
|
|
2202
2215
|
* @description Buffers prompts typed while an agent session is still booting so
|
|
@@ -2430,7 +2443,7 @@ function getThinkingCoalesceState(key) {
|
|
|
2430
2443
|
const k = (0, sessionKey_1.keyToString)(key);
|
|
2431
2444
|
let s = thinkingCoalescers.get(k);
|
|
2432
2445
|
if (!s) {
|
|
2433
|
-
s = {
|
|
2446
|
+
s = { pending: null, inFlight: false, lastSentHtml: null, detachAfterDrain: false };
|
|
2434
2447
|
thinkingCoalescers.set(k, s);
|
|
2435
2448
|
}
|
|
2436
2449
|
return s;
|
|
@@ -2447,7 +2460,7 @@ function clearThinkingMessage(key) {
|
|
|
2447
2460
|
const s = getThreadMessageState(key);
|
|
2448
2461
|
const coalescer = thinkingCoalescers.get((0, sessionKey_1.keyToString)(key));
|
|
2449
2462
|
if (coalescer) {
|
|
2450
|
-
coalescer.
|
|
2463
|
+
coalescer.pending = null;
|
|
2451
2464
|
coalescer.lastSentHtml = null;
|
|
2452
2465
|
coalescer.detachAfterDrain = false;
|
|
2453
2466
|
}
|
|
@@ -2843,6 +2856,10 @@ async function pinMessageQuiet(key, messageId, options) {
|
|
|
2843
2856
|
return false;
|
|
2844
2857
|
}
|
|
2845
2858
|
}
|
|
2859
|
+
/** @description One unpin call through the rate-limit queue; rejects with Telegram's error. */
|
|
2860
|
+
async function sendUnpin(key, messageId) {
|
|
2861
|
+
await (0, rateLimiter_1.enqueueSend)(key, () => bot.telegram.unpinChatMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId));
|
|
2862
|
+
}
|
|
2846
2863
|
/**
|
|
2847
2864
|
* @description Unpin `messageId` for `key` through the rate-limit queue,
|
|
2848
2865
|
* swallowing + logging failures (already-unpinned / deleted / lost permission).
|
|
@@ -2852,7 +2869,7 @@ async function unpinMessageQuiet(key, messageId) {
|
|
|
2852
2869
|
if (!checkIsTelegramPrimitiveKey(key, 'unpinMessage'))
|
|
2853
2870
|
return;
|
|
2854
2871
|
try {
|
|
2855
|
-
await (
|
|
2872
|
+
await sendUnpin(key, messageId);
|
|
2856
2873
|
}
|
|
2857
2874
|
catch (e) {
|
|
2858
2875
|
console.warn(`[question-pin] unpin ${(0, sessionKey_1.keyToString)(key)} msg ${messageId} failed: ${describeSendError(e)}`);
|
|
@@ -3155,8 +3172,8 @@ function buildSendExtra(key, extra) {
|
|
|
3155
3172
|
async function replyToThread(key, text, extra = {}, options = {}) {
|
|
3156
3173
|
if (!checkIsTelegramPrimitiveKey(key, 'replyToThread'))
|
|
3157
3174
|
return null;
|
|
3158
|
-
const sendOnce = (sendExtra) => {
|
|
3159
|
-
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key),
|
|
3175
|
+
const sendOnce = (sendExtra, sentText = text) => {
|
|
3176
|
+
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), sentText, sendExtra);
|
|
3160
3177
|
return options.unpaced ? (0, rateLimiter_1.sendUnpaced)(key, send, options.signal) : (0, rateLimiter_1.enqueueSend)(key, send, options.signal);
|
|
3161
3178
|
};
|
|
3162
3179
|
// A sent message is tracked for `/clear_messages`, and a `/bind` picker is remembered to be closed by the next bind or leave.
|
|
@@ -3167,7 +3184,8 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3167
3184
|
openBindMessages.remember((0, sessionKey_1.keyToString)(key), messageId, Date.now());
|
|
3168
3185
|
return messageId;
|
|
3169
3186
|
};
|
|
3170
|
-
|
|
3187
|
+
// The plain twin goes out in place of `text` when Telegram refuses the markup: it is as much a secret, and the trace must not quote it.
|
|
3188
|
+
const releaseSecret = options.isSecret ? (0, outputTrace_1.markOutboundTextsSecret)([text, options.plainFallbackText]) : null;
|
|
3171
3189
|
try {
|
|
3172
3190
|
return await trackSent(await sendOnce(buildSendExtra(key, extra)));
|
|
3173
3191
|
}
|
|
@@ -3189,7 +3207,7 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3189
3207
|
const plainExtra = { ...extra };
|
|
3190
3208
|
delete plainExtra.parse_mode;
|
|
3191
3209
|
try {
|
|
3192
|
-
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra)));
|
|
3210
|
+
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra), options.plainFallbackText ?? text));
|
|
3193
3211
|
}
|
|
3194
3212
|
catch (e2) {
|
|
3195
3213
|
await handleSendError(key, e2);
|
|
@@ -3710,7 +3728,7 @@ async function sendOutputImmediate(key, output, isContinuation = false, startsNe
|
|
|
3710
3728
|
let startIndex = 0;
|
|
3711
3729
|
if (shouldEditFirstChunk) {
|
|
3712
3730
|
const editedOk = chunks[0] === msgState.lastMessageText ||
|
|
3713
|
-
(await editThreadMessage(key, msgState.lastMessageId, (0, renderAgentHtml_1.renderAgentHtml)(chunks[0]), { parse_mode: 'HTML' }));
|
|
3731
|
+
(await editThreadMessage(key, msgState.lastMessageId, (0, renderAgentHtml_1.renderAgentHtml)(chunks[0]), { parse_mode: 'HTML' }, chunks[0]));
|
|
3714
3732
|
if (editedOk) {
|
|
3715
3733
|
msgState.lastMessageText = chunks[0];
|
|
3716
3734
|
startIndex = 1;
|
|
@@ -3747,7 +3765,8 @@ async function replyChunkWithFallback(key, renderedHtml, plainFallback, replyMar
|
|
|
3747
3765
|
if (!checkIsTelegramPrimitiveKey(key, 'replyChunkWithFallback'))
|
|
3748
3766
|
return null;
|
|
3749
3767
|
const markupExtra = replyMarkup ? { reply_markup: replyMarkup } : {};
|
|
3750
|
-
|
|
3768
|
+
// Telegram refusing the markup is answered INSIDE replyToThread, with the plain twin — without it the retry would show the tags.
|
|
3769
|
+
const id = await replyToThread(key, renderedHtml, { parse_mode: 'HTML', ...markupExtra }, { plainFallbackText: plainFallback });
|
|
3751
3770
|
if (id)
|
|
3752
3771
|
return id;
|
|
3753
3772
|
return replyToThread(key, plainFallback, markupExtra);
|
|
@@ -4407,6 +4426,8 @@ function getPerTurnRefusal(key) {
|
|
|
4407
4426
|
*/
|
|
4408
4427
|
async function persistSessionStart(key, adapter) {
|
|
4409
4428
|
await (0, persistAdapterSessionIds_1.persistAdapterSessionIds)(key, adapter, state);
|
|
4429
|
+
// The session id is new or changed: the hook's and the plugin's flags for it (`/compact_self_review`) are due.
|
|
4430
|
+
syncThreadCompactSelfReviewFlags(key);
|
|
4410
4431
|
if ((0, adapterNames_1.checkIsJsonStreamBackend)(adapter.name) && botMcpToolDigestReader) {
|
|
4411
4432
|
await state.setAgentMcpToolDigest(key, botMcpToolDigestReader(key));
|
|
4412
4433
|
}
|
|
@@ -4856,7 +4877,7 @@ async function forwardPromptToAgent(key, adapter, text, sentAtMs, options = {})
|
|
|
4856
4877
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
4857
4878
|
checkIsSessionActive: () => adapter.checkIsActive(key) && !(isTechnicalPrompt && (adapter.checkIsBusy?.(key) ?? false)),
|
|
4858
4879
|
buffer: async () => {
|
|
4859
|
-
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${
|
|
4880
|
+
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${getPromptWithThreadMessageContext(key, text, options.messageContext)}`, true);
|
|
4860
4881
|
},
|
|
4861
4882
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
4862
4883
|
forward: async () => {
|
|
@@ -4878,11 +4899,14 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4878
4899
|
// A forwarded prompt is thread activity — reset the compact-on-idle watchdog (F2).
|
|
4879
4900
|
noteThreadActivity(key);
|
|
4880
4901
|
const isTechnicalPrompt = options.isTechnicalPrompt ?? false;
|
|
4902
|
+
// A slash command typed by the operator is a control token; the same words FORWARDED from elsewhere are
|
|
4903
|
+
// content (the mark ahead of them says so) and are decorated and replayed like any prompt.
|
|
4904
|
+
const isSlashCommand = (0, messageContext_1.checkIsSlashCommandPrompt)(text, options.messageContext);
|
|
4881
4905
|
// Skip slash commands (not worth replaying), the recovery replay itself (keeps
|
|
4882
4906
|
// the once-per-episode guard intact), a request reminder (the request's own
|
|
4883
4907
|
// prompt stays the one to replay) and a bot-made technical prompt.
|
|
4884
4908
|
const isReplayable = (0, wedgeRecovery_1.checkIsReplayablePrompt)({
|
|
4885
|
-
isSlashCommand
|
|
4909
|
+
isSlashCommand,
|
|
4886
4910
|
isRecoveryReplay: options.isRecoveryReplay ?? false,
|
|
4887
4911
|
isRequestReminder: options.isRequestReminder ?? false,
|
|
4888
4912
|
isTechnicalPrompt,
|
|
@@ -4891,19 +4915,21 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4891
4915
|
// forwarded to a live session once no wait holds them — after it, in arrival
|
|
4892
4916
|
// order (the resume's, the operator's message that ended the wait, a later
|
|
4893
4917
|
// post). Only a replayable one carries them, so a wedge recovery replays them too.
|
|
4894
|
-
|
|
4895
|
-
//
|
|
4896
|
-
//
|
|
4897
|
-
//
|
|
4898
|
-
//
|
|
4899
|
-
//
|
|
4900
|
-
//
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4918
|
+
// Fold the message-context block (the reply quote of a Telegram REPLY, the mark of a
|
|
4919
|
+
// FORWARD) ahead of the user's text so the agent sees WHAT is being referenced and
|
|
4920
|
+
// WHOSE words these are — only for a normal prompt, since a slash command forwarded to
|
|
4921
|
+
// the agent is a control token a prefixed block would corrupt, and a terminal's input
|
|
4922
|
+
// is a shell line the block's `> ` lines would turn into file-overwriting redirections.
|
|
4923
|
+
// The held prompts come AFTER the folded text, under a header line of their own: the
|
|
4924
|
+
// block describes the message's own words, and a held scheduled run must not read as
|
|
4925
|
+
// part of a forwarded message. The folded `body` is what gets cached,
|
|
4926
|
+
// preamble-wrapped and timestamped below.
|
|
4927
|
+
const ownBody = (0, messageContext_1.getPromptWithMessageContext)(text, {
|
|
4928
|
+
context: options.messageContext,
|
|
4904
4929
|
isShellInput: adapter.name === 'terminal',
|
|
4905
4930
|
});
|
|
4906
|
-
|
|
4931
|
+
const quotedBody = isReplayable && adapter.checkIsActive(key) ? limitHeldPrompts.releaseWithForward(key, ownBody) : ownBody;
|
|
4932
|
+
// The request header (S7) leads the per-message body, like the message context and
|
|
4907
4933
|
// unlike the once-per-change thread preamble: it names THIS message's request.
|
|
4908
4934
|
const messageBody = options.requestHeader ? `${options.requestHeader}${quotedBody}` : quotedBody;
|
|
4909
4935
|
// A loss the agent was not told about yet (`utils/lostWork.ts`) rides the first real prompt, once, ahead of it.
|
|
@@ -4931,13 +4957,13 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4931
4957
|
// (scheduled runs, buffered replay, api-retry nudge, file intake) fall back
|
|
4932
4958
|
// to now. Slash commands skip it for the same reason they skip the preamble.
|
|
4933
4959
|
let promptText = getPromptWithThreadContext(key, body);
|
|
4934
|
-
if (state.checkIsTimestampsEnabled(key) && !
|
|
4960
|
+
if (state.checkIsTimestampsEnabled(key) && !isSlashCommand) {
|
|
4935
4961
|
promptText = `${(0, isoTimestamp_1.formatIsoLocalOffset)(sentAtMs ?? Date.now())}\n\n${promptText}`;
|
|
4936
4962
|
}
|
|
4937
4963
|
// The project board rides every turn start the bot makes (D20: whole on a fresh context, else only what changed),
|
|
4938
4964
|
// then the todo list's staleness reminder rides the next real prompt from any source (D11 form a) — never a slash
|
|
4939
4965
|
// command or a shell line; the reminder never rides the standalone reminder itself.
|
|
4940
|
-
const isTodoDecorated = !
|
|
4966
|
+
const isTodoDecorated = !isSlashCommand && adapter.name !== 'terminal';
|
|
4941
4967
|
if (isTodoDecorated)
|
|
4942
4968
|
discardTodoInbox(key);
|
|
4943
4969
|
const todoBoardBlock = isTodoDecorated ? takeTodoPromptBoard(key) : null;
|
|
@@ -5036,16 +5062,17 @@ function getPromptWithThreadContext(key, text) {
|
|
|
5036
5062
|
}
|
|
5037
5063
|
/**
|
|
5038
5064
|
* @description Bridge a telegraf message (text, voice, or a file) to the
|
|
5039
|
-
* agent-facing
|
|
5065
|
+
* agent-facing message-context block. When the operator uses Telegram's REPLY
|
|
5040
5066
|
* feature, this folds the replied-to message's content into the forwarded prompt
|
|
5041
|
-
* so the agent sees WHAT is being referenced
|
|
5067
|
+
* so the agent sees WHAT is being referenced; when the message was FORWARDED, it
|
|
5068
|
+
* folds the mark that says whose words they are. Returns the block, or `undefined`
|
|
5042
5069
|
* when there is nothing to inject — the connector's
|
|
5043
|
-
* {@link
|
|
5070
|
+
* {@link getTelegramMessageContext} decides. The bot's own id
|
|
5044
5071
|
* (`bot.botInfo.id`) drives the `from: assistant` attribution; a replied-to file
|
|
5045
5072
|
* is looked up among the files this thread took in.
|
|
5046
5073
|
*/
|
|
5047
|
-
function
|
|
5048
|
-
return (0, inbound_1.
|
|
5074
|
+
function getMessageContext(key, message) {
|
|
5075
|
+
return (0, inbound_1.getTelegramMessageContext)(message, { userId: bot.botInfo?.id }, (meta) => findThreadSavedFile(key, meta));
|
|
5049
5076
|
}
|
|
5050
5077
|
/**
|
|
5051
5078
|
* @description The bot's saved copy of a file sent to this thread earlier
|
|
@@ -5065,16 +5092,15 @@ function findThreadSavedFile(key, meta) {
|
|
|
5065
5092
|
return name === undefined ? undefined : path.join(dir, name);
|
|
5066
5093
|
}
|
|
5067
5094
|
/**
|
|
5068
|
-
* @description Fold a
|
|
5095
|
+
* @description Fold a message-context block into a prompt that leaves as finished
|
|
5069
5096
|
* text through {@link deliverPromptOrBuffer} — one buffered behind a session
|
|
5070
5097
|
* start, whose replay forwards it as is, or a file announcement — by the one
|
|
5071
5098
|
* rule `forwardPromptToAgent` applies to a live prompt. The thread's adapter is
|
|
5072
5099
|
* the one the text reaches, so a terminal keeps the block out of its shell line.
|
|
5073
5100
|
*/
|
|
5074
|
-
function
|
|
5075
|
-
return (0,
|
|
5076
|
-
|
|
5077
|
-
isSlashCommand: (0, threadContextPreamble_1.checkShouldSkipPreambleForText)(text),
|
|
5101
|
+
function getPromptWithThreadMessageContext(key, text, messageContext) {
|
|
5102
|
+
return (0, messageContext_1.getPromptWithMessageContext)(text, {
|
|
5103
|
+
context: messageContext,
|
|
5078
5104
|
isShellInput: (0, createAdapter_1.getThreadAdapter)(key).name === 'terminal',
|
|
5079
5105
|
});
|
|
5080
5106
|
}
|
|
@@ -5159,7 +5185,7 @@ const botCore = {
|
|
|
5159
5185
|
cancelConversationRequest,
|
|
5160
5186
|
wakeSleepingSession,
|
|
5161
5187
|
};
|
|
5162
|
-
const { checkIsThreadCompacting, noteThreadActivity, noteThreadUserActivity, markThreadTurnProducedOutput, clearThreadCompaction, rearmThreadIdleTimer, armDeferredCompaction, checkIsDeferredCompactionArmed, threadsCompacting, answerReAskedQuestionByNumber, reAskInterruptedQuestion, restoreReAskedQuestion, closeSavedReAskedQuestion, closeReAskedQuestion, registerCompactionCommands, registerCompactionCallbacks, } = (0, compaction_1.createCompaction)({
|
|
5188
|
+
const { checkIsThreadCompacting, noteThreadActivity, noteThreadUserActivity, markThreadTurnProducedOutput, postOwnCompactionInstructionGaps, routeStreamedCompactionSummaryTail, clearThreadCompaction, rearmThreadIdleTimer, armDeferredCompaction, checkIsDeferredCompactionArmed, threadsCompacting, answerReAskedQuestionByNumber, reAskInterruptedQuestion, restoreReAskedQuestion, closeSavedReAskedQuestion, closeReAskedQuestion, syncThreadCompactSelfReviewFlags, syncAllCompactSelfReviewFlags, registerCompactionCommands, registerCompactionCallbacks, } = (0, compaction_1.createCompaction)({
|
|
5163
5189
|
...botCore,
|
|
5164
5190
|
startTypingLoader,
|
|
5165
5191
|
forwardPromptToAgent: async (key, adapter, text) => { await forwardPromptToAgent(key, adapter, text); },
|
|
@@ -5178,6 +5204,7 @@ const { checkIsThreadCompacting, noteThreadActivity, noteThreadUserActivity, mar
|
|
|
5178
5204
|
checkIsStarting: (key) => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
5179
5205
|
closeOrphanQuestionMessage,
|
|
5180
5206
|
notePersonActivity,
|
|
5207
|
+
compactSelfReviewFlagDirs: (0, compactSelfReviewFlags_1.getCompactSelfReviewFlagDirs)((0, state_1.resolveDataDir)(), (0, openCodeCompactPlugin_1.resolveOpenCodeGlobalPluginDir)(process.env)),
|
|
5181
5208
|
});
|
|
5182
5209
|
/**
|
|
5183
5210
|
* @description True iff the neutral router owns `name`, i.e. a `/name` message
|
|
@@ -6054,7 +6081,11 @@ command('whoami', async (ctx, key) => {
|
|
|
6054
6081
|
* locked by `ALLOWED_GROUP_ID` env. Only a creator/administrator of the target
|
|
6055
6082
|
* group may pair, so a random group can't hijack the binding.
|
|
6056
6083
|
*/
|
|
6057
|
-
bot.command('pair', async (ctx) => {
|
|
6084
|
+
bot.command('pair', async (ctx, next) => {
|
|
6085
|
+
// A forwarded `/pair` is somebody else's words: it re-points the bot to no group, and it is not swallowed either —
|
|
6086
|
+
// it goes on to the text handler, which hands it to the agent under its mark like any other forwarded text.
|
|
6087
|
+
if ((0, inbound_1.checkIsTelegramForward)(ctx.message))
|
|
6088
|
+
return next();
|
|
6058
6089
|
const userId = ctx.from?.id;
|
|
6059
6090
|
if (!userId)
|
|
6060
6091
|
return;
|
|
@@ -6680,11 +6711,13 @@ const { registerRunnersCommands, registerRunnersCallbacks, handleRunnersAddressT
|
|
|
6680
6711
|
getGeneralKey: () => getOperatorGeneralKey(),
|
|
6681
6712
|
pinMessage: (key, messageId) => pinMessageQuiet(key, messageId, { disableNotification: false }),
|
|
6682
6713
|
sweepExpiredCodes: async (nowMs) => { await (0, hubPairing_1.sweepExpiredPairings)(runnersHub, nowMs); },
|
|
6714
|
+
applyGroups: (runner) => (0, runnerGroups_1.applyRunnerGroups)(runnersHub, runner, runnersCacheDir),
|
|
6683
6715
|
readRunnerHost: (0, instanceSettings_1.createRunnerHostReader)(() => (0, instanceSettings_1.getInstanceSettingsPath)(), (line) => console.error(line)),
|
|
6684
6716
|
saveRunnerHost: (address) => (0, instanceSettings_1.saveInstanceSettingsChange)((0, instanceSettings_1.getInstanceSettingsPath)(), { runnerHost: address }),
|
|
6685
6717
|
getBotLabel: () => (bot.botInfo?.username === undefined ? os.hostname() : `@${bot.botInfo.username}`),
|
|
6686
6718
|
readOverview: (nowMs) => (0, runnersOverview_1.readRunnersOverview)(runnersHub, runnersCacheDir, nowMs),
|
|
6687
|
-
|
|
6719
|
+
// The 20 s deadline of the live probe, which the test seam may shorten (a flow that must see a BUSY machine cannot wait it out).
|
|
6720
|
+
probeOverview: (overview, nowMs) => (0, runnersOverview_1.probeRunnersOverview)(runnersHub, overview, runnersCacheDir, nowMs, ENV.testTimings.remoteRunProbeDeadlineMs),
|
|
6688
6721
|
listAddressCandidates: () => (0, hubAddressCandidates_1.listPublicAddressCandidates)(),
|
|
6689
6722
|
scanHostKey: hubAddress_1.scanHostKey,
|
|
6690
6723
|
ensureGateWrapper: () => { (0, gateWrapper_1.ensureGateWrapper)(runnersHub); },
|
|
@@ -6798,9 +6831,60 @@ const claudeUsageRefresher = (0, claudeUsageRefresher_1.createClaudeUsageRefresh
|
|
|
6798
6831
|
getSnapshot: (name) => state.getClaudeProfileInfo(name)?.usage,
|
|
6799
6832
|
saveSnapshot: (name, snapshot) => state.setClaudeProfileUsage(name, snapshot),
|
|
6800
6833
|
readToken: (configDir) => (0, claudeUsage_1.readClaudeOAuthToken)(configDir),
|
|
6801
|
-
fetchUsage: (accessToken) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken),
|
|
6834
|
+
fetchUsage: (accessToken, signal) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken, { signal }),
|
|
6802
6835
|
refreshOpenCode: (options) => openCodeUsagePoller.refreshAll(options),
|
|
6836
|
+
markOpenCodeStale: (reason) => openCodeUsagePoller.markAllStale(reason),
|
|
6803
6837
|
});
|
|
6838
|
+
/**
|
|
6839
|
+
* What the daily recheck of a used-up API credit (`utils/claudeApiCreditRecheck.ts`) reads and does in the bot: the profiles
|
|
6840
|
+
* with their marks (after the operator's newer figures have ended the marks they supersede), their own keys, and the state it
|
|
6841
|
+
* writes — the attempt BEFORE the request, the renewal after an answer.
|
|
6842
|
+
*/
|
|
6843
|
+
const claudeApiCreditRecheckPorts = {
|
|
6844
|
+
nowMs: () => Date.now(),
|
|
6845
|
+
intervalMs: ENV.testTimings.creditRecheckIntervalMs ?? claudeApiCreditRecheck_1.claudeApiCreditRecheckIntervalMs,
|
|
6846
|
+
listProfiles: () => {
|
|
6847
|
+
syncClaudeApiCreditAnchors();
|
|
6848
|
+
return Object.entries(state.getAllClaudeProfileInfos()).map(([name, record]) => ({
|
|
6849
|
+
name,
|
|
6850
|
+
billing: record.billing ?? null,
|
|
6851
|
+
// The refusal the operator acted on awaits its answer too: the account is in use again, but nothing has confirmed the credit.
|
|
6852
|
+
creditExhaustedAt: record.creditExhaustedAt ?? record.creditUnconfirmedSince ?? null,
|
|
6853
|
+
creditRecheckedAt: record.creditRecheckedAt ?? null,
|
|
6854
|
+
}));
|
|
6855
|
+
},
|
|
6856
|
+
readApiKey: (name) => {
|
|
6857
|
+
if (name === claudeProfiles_1.defaultClaudeProfileName)
|
|
6858
|
+
return (0, claudeProfiles_1.readDefaultClaudeProfileApiKey)(state.getClaudeProfileInfo(name)?.isConsoleLoginKey === true);
|
|
6859
|
+
const configDir = (0, claudeProfiles_1.resolveClaudeProfileDir)((0, state_1.resolveDataDir)(), name);
|
|
6860
|
+
return configDir === null ? null : (0, claudeProfiles_1.readClaudeProfileApiKey)(configDir);
|
|
6861
|
+
},
|
|
6862
|
+
probe: (apiKey) => (0, claudeApiCreditRecheck_1.probeClaudeApiCredit)(apiKey),
|
|
6863
|
+
markRechecked: (name, atIso) => state.setClaudeProfileCreditRechecked(name, atIso),
|
|
6864
|
+
onRenewed: (name, atIso) => {
|
|
6865
|
+
if (!state.setClaudeProfileCreditRenewed(name, atIso))
|
|
6866
|
+
console.log(`[credit] ${name}: a refusal came in while the recheck was running, so the credit is not marked renewed`);
|
|
6867
|
+
},
|
|
6868
|
+
log: (line) => console.log(line),
|
|
6869
|
+
warn: (line) => console.warn(line),
|
|
6870
|
+
};
|
|
6871
|
+
/**
|
|
6872
|
+
* What the check of an agent's stop report on an API account (`utils/claudeApiAgentStop.ts`) reads and does in the bot: the same
|
|
6873
|
+
* key, attempt record and probe as the daily recheck above, a probe with a timeout of its own, and — instead of an unverified
|
|
6874
|
+
* used-up mark — a mark only on a refusal for the balance, an hour off AGENTS (their own field, never the topics' limit mark) otherwise.
|
|
6875
|
+
*/
|
|
6876
|
+
const claudeApiAgentStopPorts = {
|
|
6877
|
+
nowMs: () => Date.now(),
|
|
6878
|
+
readApiKey: (name) => claudeApiCreditRecheckPorts.readApiKey(name),
|
|
6879
|
+
probe: (apiKey, timeoutMs) => (0, claudeApiCreditRecheck_1.probeClaudeApiCredit)(apiKey, { timeoutMs }),
|
|
6880
|
+
markRechecked: (name, atIso) => state.setClaudeProfileCreditRechecked(name, atIso),
|
|
6881
|
+
markUsedUp: (name, atIso) => state.setClaudeProfileCreditExhausted(name, atIso),
|
|
6882
|
+
holdOff: (name, untilIso) => state.setClaudeProfileAgentHoldUntil(name, untilIso),
|
|
6883
|
+
checkIsRenewalAwaited: (name) => state.getClaudeProfileInfo(name)?.creditUnconfirmedSince !== undefined,
|
|
6884
|
+
onRenewed: (name, atIso) => claudeApiCreditRecheckPorts.onRenewed(name, atIso),
|
|
6885
|
+
log: (line) => console.log(line),
|
|
6886
|
+
warn: (line) => console.warn(line),
|
|
6887
|
+
};
|
|
6804
6888
|
/** The profile that owns a config directory (`null` = default); `null` for a directory outside the profiles root. */
|
|
6805
6889
|
function resolveClaudeProfileNameForDir(configDir) {
|
|
6806
6890
|
if (configDir === null)
|
|
@@ -6840,14 +6924,52 @@ function onClaudeTurnCost(key, configDir, report) {
|
|
|
6840
6924
|
const name = resolveClaudeProfileNameForDir(configDir);
|
|
6841
6925
|
if (name === null)
|
|
6842
6926
|
return;
|
|
6927
|
+
// Read first: a figure newer than the account's used-up evidence ends it before this turn is judged against it.
|
|
6928
|
+
const creditAnchors = syncClaudeApiCreditAnchors();
|
|
6843
6929
|
const info = state.getClaudeProfileInfo(name);
|
|
6930
|
+
// The refusal the operator acted on (picked the account again) is still evidence: the turn that now goes through renews.
|
|
6844
6931
|
const outcome = (0, claudeApiSpend_1.getClaudeTurnCostOutcome)({
|
|
6845
|
-
billing: info?.billing ?? null,
|
|
6932
|
+
billing: info?.billing ?? null,
|
|
6933
|
+
isCreditExhausted: info?.creditExhaustedAt !== undefined || info?.creditUnconfirmedSince !== undefined,
|
|
6934
|
+
isError: report.isError,
|
|
6935
|
+
turnCostUsd,
|
|
6846
6936
|
});
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6937
|
+
const nowIso = new Date().toISOString();
|
|
6938
|
+
// A billed turn that goes through on an API account marked used up — or one the operator picked again after the refusal — is
|
|
6939
|
+
// the proof the daily recheck looks for: the credit is back, and the account's spend counter starts over from this turn.
|
|
6940
|
+
if (outcome.isCreditMarkCleared && info?.billing === 'api')
|
|
6941
|
+
state.setClaudeProfileCreditRenewed(name, nowIso);
|
|
6942
|
+
else if (outcome.isCreditMarkCleared)
|
|
6943
|
+
state.liftClaudeProfileCreditExhaustion(name);
|
|
6944
|
+
if (outcome.spendUsd === null)
|
|
6945
|
+
return;
|
|
6946
|
+
const apiSpend = (0, claudeApiSpend_1.addClaudeApiSpend)(info?.apiSpend, outcome.spendUsd, nowIso);
|
|
6947
|
+
state.setClaudeProfileApiSpend(name, apiSpend);
|
|
6948
|
+
// The same spend also counts in the account's credit period (`utils/claudeApiCredit.ts`), read AFTER a renewal above.
|
|
6949
|
+
const period = (0, claudeApiCredit_1.getClaudeApiCreditPeriod)({ anchor: creditAnchors[name], renewedAt: state.getClaudeProfileInfo(name)?.creditRenewedAt, apiSpend });
|
|
6950
|
+
const creditSpend = (0, claudeApiCredit_1.addClaudeApiCreditSpend)(state.getClaudeProfileInfo(name)?.creditSpend, period, outcome.spendUsd);
|
|
6951
|
+
if (creditSpend)
|
|
6952
|
+
state.setClaudeProfileCreditSpend(name, creditSpend);
|
|
6953
|
+
}
|
|
6954
|
+
/**
|
|
6955
|
+
* Read the operator's credit figures (`utils/claudeApiCredit.ts`) AND settle what they supersede: a figure newer than an
|
|
6956
|
+
* account's used-up evidence (the mark, or the refusal the operator acted on) ends that evidence — the operator saying there is
|
|
6957
|
+
* money is the signal a billed turn going through is — so the stored mark, the fallback chain and the screens never contradict
|
|
6958
|
+
* the figure. It writes state: a call whose result is dropped is meant (a read path that must see the settled marks).
|
|
6959
|
+
*/
|
|
6960
|
+
function syncClaudeApiCreditAnchors() {
|
|
6961
|
+
const anchors = (0, claudeApiCredit_1.readClaudeApiCreditAnchors)((0, state_1.resolveDataDir)());
|
|
6962
|
+
for (const name of (0, claudeApiCredit_1.listProfilesWithSupersededCreditEvidence)(state.getAllClaudeProfileInfos(), anchors))
|
|
6963
|
+
state.clearClaudeProfileCreditEvidence(name);
|
|
6964
|
+
return anchors;
|
|
6965
|
+
}
|
|
6966
|
+
/** Every Claude profile's usage view as the bot knows it now: its record plus the operator's credit figures. */
|
|
6967
|
+
function getClaudeProfileUsageViews() {
|
|
6968
|
+
return (0, claudeProfileUsageViews_1.buildClaudeProfileUsageViews)({ dataDir: (0, state_1.resolveDataDir)(), records: state.getAllClaudeProfileInfos(), creditAnchors: syncClaudeApiCreditAnchors() });
|
|
6969
|
+
}
|
|
6970
|
+
/** One profile's usage view — the very one `/limits` renders, for the rows of `/accounts`. */
|
|
6971
|
+
function getClaudeProfileUsageView(name) {
|
|
6972
|
+
return (0, claudeProfileUsageViews_1.buildClaudeProfileUsageView)({ dataDir: (0, state_1.resolveDataDir)(), name, record: state.getClaudeProfileInfo(name), creditAnchor: syncClaudeApiCreditAnchors()[name] });
|
|
6851
6973
|
}
|
|
6852
6974
|
/** The model a topic's Claude session runs (or last ran), for the usage ranking's choice of windows. */
|
|
6853
6975
|
function getThreadClaudeModel(key) {
|
|
@@ -6855,6 +6977,7 @@ function getThreadClaudeModel(key) {
|
|
|
6855
6977
|
}
|
|
6856
6978
|
/** What `/status` names of a Claude profile: its last probed sign-in and email, and its limit mark (none until probed). */
|
|
6857
6979
|
function readStatusAccountSource(name) {
|
|
6980
|
+
syncClaudeApiCreditAnchors();
|
|
6858
6981
|
const info = state.getClaudeProfileInfo(name);
|
|
6859
6982
|
return {
|
|
6860
6983
|
name, email: info?.email ?? null, loggedIn: info?.loggedIn, limitedUntil: info?.limitedUntil ?? null,
|
|
@@ -6886,7 +7009,7 @@ async function detectFallbackOptions() {
|
|
|
6886
7009
|
console.warn('[fallback] the OpenCode catalog is unavailable:', e instanceof Error ? e.message : e);
|
|
6887
7010
|
}
|
|
6888
7011
|
return {
|
|
6889
|
-
claudeProfiles: (
|
|
7012
|
+
claudeProfiles: getClaudeProfileUsageViews(),
|
|
6890
7013
|
openCodeModels,
|
|
6891
7014
|
recentOpenCodeModels: (0, openCodeAdapter_1.listSavedOpenCodeModelLabels)().reverse(),
|
|
6892
7015
|
openCodeLimits: state.getOpenCodeModelLimits(),
|
|
@@ -6953,6 +7076,7 @@ function getConversationAccountState(key) {
|
|
|
6953
7076
|
const checkIsFuture = (instant) => instant !== undefined && Date.parse(instant) > nowMs;
|
|
6954
7077
|
if (position.backend === 'opencode')
|
|
6955
7078
|
return { isLimited: checkIsFuture(state.getOpenCodeModelLimitedUntil((0, fallbackChain_1.buildOpenCodeModelLabel)(position))), isApiBilled: false };
|
|
7079
|
+
syncClaudeApiCreditAnchors();
|
|
6956
7080
|
const info = state.getClaudeProfileInfo(position.profile);
|
|
6957
7081
|
return { isLimited: checkIsFuture(info?.limitedUntil) || info?.creditExhaustedAt !== undefined, isApiBilled: info?.billing === 'api' };
|
|
6958
7082
|
}
|
|
@@ -7004,8 +7128,9 @@ async function planFallbackSwitch(key, cls, episodeId) {
|
|
|
7004
7128
|
fallbackMs: apiErrorRetry_1.usageLimitDefaultMs,
|
|
7005
7129
|
}));
|
|
7006
7130
|
}
|
|
7007
|
-
// The Claude rungs are judged on fresh figures whatever backend hit the limit (a minute's cache)
|
|
7008
|
-
|
|
7131
|
+
// The Claude rungs are judged on fresh figures whatever backend hit the limit (a minute's cache) — waited for only briefly:
|
|
7132
|
+
// a stuck usage endpoint must never hold the switch or the wait notice of a topic that just hit its limit.
|
|
7133
|
+
await (0, usageRefreshBudget_1.refreshUsageWithinBudget)((options) => claudeUsageRefresher.refreshAll(options));
|
|
7009
7134
|
const detection = await detectFallbackOptions();
|
|
7010
7135
|
let chain = state.getFallbackChain();
|
|
7011
7136
|
if (chain.length === 0 && from.backend === 'claude') {
|
|
@@ -7381,9 +7506,10 @@ function buildBackendSwitchTargetOfRung(to) {
|
|
|
7381
7506
|
*/
|
|
7382
7507
|
async function switchTopicByOperator(key, to) {
|
|
7383
7508
|
// The operator's own pick of an account whose API credits were used up is the act that ends that mark (topped up, or
|
|
7384
|
-
// trying anyway): a failing request marks it again.
|
|
7509
|
+
// trying anyway): a failing request marks it again. An API account keeps the refusal as unconfirmed, so the first turn that
|
|
7510
|
+
// goes through still records the renewal.
|
|
7385
7511
|
if (to.backend === 'claude')
|
|
7386
|
-
state.
|
|
7512
|
+
state.liftClaudeProfileCreditExhaustion(to.profile);
|
|
7387
7513
|
const currentFamily = getTopicBackendFamily(key);
|
|
7388
7514
|
const from = getTopicFallbackPosition(key);
|
|
7389
7515
|
const isUsageLimitWaitArmed = getArmedApiRetry(key)?.kind === 'usageLimit';
|
|
@@ -7464,11 +7590,23 @@ async function takeFallbackSwitchOffer(key, episodeId, index) {
|
|
|
7464
7590
|
/**
|
|
7465
7591
|
* The `claude_profiles` MCP tool's answer: snapshots refreshed on demand (a minute's cache; the account a resumed session
|
|
7466
7592
|
* was stopped on is re-read at once), then the launch pick — a new agent, or the session's own account when it is warm.
|
|
7467
|
-
*
|
|
7593
|
+
* Only the accounts the operator's `/limits` list holds with an enabled rung are named once it lists any Claude account (an
|
|
7594
|
+
* account billed to API credits among them goes first, `getClaudeLaunchPick`). A resumed session reported stopped on an API
|
|
7595
|
+
* account is CHECKED, not believed (`verifyClaudeApiAgentStop`): one probe on its key marks the credit used up only if the API
|
|
7596
|
+
* refuses for the balance; otherwise the account is just kept off agents for an hour. The check runs beside the usage refresh
|
|
7597
|
+
* with a timeout of its own, so the answer is held for the longer of the two, never their sum. The refresh is waited for only
|
|
7598
|
+
* up to `claudeLaunchRefreshBudgetMs`; past it the cached figures are answered (an agent that waits on a silent tool call is
|
|
7599
|
+
* dropped by its own client after 300 s).
|
|
7468
7600
|
*/
|
|
7469
7601
|
async function listClaudeProfilesForAgent(query) {
|
|
7470
|
-
|
|
7471
|
-
|
|
7602
|
+
const stoppedApiProfile = (0, claudeApiAgentStop_1.getApiProfileStoppedByAgent)(getClaudeProfileUsageViews(), query, Date.now());
|
|
7603
|
+
await Promise.all([
|
|
7604
|
+
(0, claudeUsageRefresher_1.refreshClaudeUsageForLaunch)(claudeUsageRefresher, { currentProfile: query.currentProfile, isStoppedByLimit: query.isStoppedByLimit, maxAgeMs: claudeUsageRefresher_1.claudeUsageOnDemandMaxAgeMs }),
|
|
7605
|
+
stoppedApiProfile === null
|
|
7606
|
+
? Promise.resolve()
|
|
7607
|
+
: (0, claudeApiAgentStop_1.verifyClaudeApiAgentStop)(stoppedApiProfile, claudeApiAgentStopPorts).then(() => undefined, (e) => console.warn(`[credit] ${stoppedApiProfile}: checking an agent's stop report failed:`, e instanceof Error ? e.message : e)),
|
|
7608
|
+
]);
|
|
7609
|
+
return (0, claudeProfileUsageViews_1.buildClaudeProfilesCreditReport)(getClaudeProfileUsageViews(), query.model, Date.now(), { currentProfile: query.currentProfile, isStoppedByLimit: query.isStoppedByLimit, chainScope: (0, fallbackChain_1.getClaudeLaunchChainScope)(state.getFallbackChain()) });
|
|
7472
7610
|
}
|
|
7473
7611
|
const { registerFallbackChainCommands, registerFallbackChainCallbacks, openAutoSwitchView, runAutoSwitchCommand, applyAutoSwitch } = (0, fallbackChain_2.createFallbackChain)({
|
|
7474
7612
|
...botCore,
|
|
@@ -7518,6 +7656,8 @@ const { registerClaudeAccountCommands, registerClaudeAccountCallbacks, checkIsAw
|
|
|
7518
7656
|
startOpenCodeConnect: showConnectMethodPicker,
|
|
7519
7657
|
applyAutoSwitch,
|
|
7520
7658
|
verifyAnthropicApiKey: (apiKey) => (0, anthropicApiKeyCheck_1.verifyAnthropicApiKey)(apiKey),
|
|
7659
|
+
getProfileUsageView: getClaudeProfileUsageView,
|
|
7660
|
+
checkIsProfileMissingFromLimitsList: (name) => (0, fallbackChain_1.checkIsClaudeProfileMissingFromChain)(state.getFallbackChain(), name),
|
|
7521
7661
|
});
|
|
7522
7662
|
claudeProfileAuthStatusSink = recordClaudeProfileAuthStatus;
|
|
7523
7663
|
claudeProfileApiKeySink = storeClaudeProfileApiKey;
|
|
@@ -8160,7 +8300,7 @@ const botCommands = new Set([
|
|
|
8160
8300
|
'start', 'claude', 'opencode', 'oc', 'terminal', 'agent', 'sessions', 'resume', 'cancel', 'model', 'connect',
|
|
8161
8301
|
'disconnect', 'stop', 'stopall', 'stop-all', 'quit-all', 'status', 'c', 'y', 'n', 'enter', 'up', 'down', 'tab', 'esc', 'escape', 'interrupt', 'output', 'clear_messages',
|
|
8162
8302
|
'bind', 'topic', 'unbind', 'where', 'ls', 'list', 'new', 'whoami', 'version', 'help', 'language', 'lang',
|
|
8163
|
-
'doctor', 'mcp', 'rename_session', 'compact', 'compact_on_idle', 'compact_summary', 'bot_skills', 'task_agents', 'runners', 'auto_continue_limits', 'limits', 'limits_autoswitch', 'trace', 'timestamps', 'timezone', 'schedule', 'reminders', 'todo', 'thinking', 'tool_results',
|
|
8303
|
+
'doctor', 'mcp', 'rename_session', 'compact', 'compact_on_idle', 'compact_summary', 'compact_self_review', 'bot_skills', 'task_agents', 'runners', 'auto_continue_limits', 'limits', 'limits_autoswitch', 'trace', 'timestamps', 'timezone', 'schedule', 'reminders', 'todo', 'thinking', 'tool_results',
|
|
8164
8304
|
'subagent', 'claude_mode', 'effort', 'verbosity', 'quit', 'q', 'quitall', 'pair', 'account', 'accounts', 'fallback', 'stt', 'voice', 'speech', 'update',
|
|
8165
8305
|
]);
|
|
8166
8306
|
/**
|
|
@@ -8189,8 +8329,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8189
8329
|
// back when that one was still forwarded).
|
|
8190
8330
|
const text = (0, utils_1.stripCommandBotMention)(ctx.message.text.trim());
|
|
8191
8331
|
const kStr = (0, sessionKey_1.keyToString)(key);
|
|
8332
|
+
// A FORWARDED message is content, never control input: its words are somebody else's, so a `/quit` in it is not an
|
|
8333
|
+
// order, a bare digit is not a pick or an answer, a phrase is not a start — the mark the agent reads says so. The routes
|
|
8334
|
+
// that take text as an ANSWER the bot asked for (a pasted code, a name, a key, a reminder's text) still take it.
|
|
8335
|
+
const isForwarded = (0, inbound_1.checkIsTelegramForward)(ctx.message);
|
|
8336
|
+
const isSlashText = !isForwarded && text.startsWith('/');
|
|
8192
8337
|
// Slash commands we don't own → forward to the agent (e.g. `/context`, `/help`).
|
|
8193
|
-
if (
|
|
8338
|
+
if (isSlashText) {
|
|
8194
8339
|
const cmd = text.slice(1).split(' ')[0].split('@')[0].toLowerCase();
|
|
8195
8340
|
// A slash command ends a pending «Add account» name prompt (the command itself runs normally).
|
|
8196
8341
|
cancelProfileNameCapture(key);
|
|
@@ -8228,7 +8373,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8228
8373
|
// keeps a message typed in the pre-URL boot window from being swallowed/deleted
|
|
8229
8374
|
// as a code. A slash command falls through (so /quit, /new, etc. still run and
|
|
8230
8375
|
// their teardown cancels the pending login; /esc cancels it outright).
|
|
8231
|
-
if (checkIsAuthLoginAwaitingCode(key) && !
|
|
8376
|
+
if (checkIsAuthLoginAwaitingCode(key) && !isSlashText) {
|
|
8232
8377
|
await submitClaudeAuthLoginCode(key, text, ctx.message.message_id);
|
|
8233
8378
|
return;
|
|
8234
8379
|
}
|
|
@@ -8238,25 +8383,25 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8238
8383
|
// a secret; NOT recognised → the flow stays armed and hints (never forwarded
|
|
8239
8384
|
// to the agent). A slash command falls through so /quit, /new, etc. still run
|
|
8240
8385
|
// + cancel the flow.
|
|
8241
|
-
if (checkIsOpenCodeOAuthAwaitingReply(key) && !
|
|
8386
|
+
if (checkIsOpenCodeOAuthAwaitingReply(key) && !isSlashText) {
|
|
8242
8387
|
await submitOpenCodeOAuthReply(key, text, ctx.message.message_id);
|
|
8243
8388
|
return;
|
|
8244
8389
|
}
|
|
8245
8390
|
// `/account` «Add» asked for the new profile's name → this message is it (a bad name keeps the prompt
|
|
8246
8391
|
// armed and says so; a slash command above already disarmed it).
|
|
8247
|
-
if (checkIsAwaitingProfileName(key) && !
|
|
8392
|
+
if (checkIsAwaitingProfileName(key) && !isSlashText) {
|
|
8248
8393
|
await submitProfileName(key, text, ctx.message.message_id);
|
|
8249
8394
|
return;
|
|
8250
8395
|
}
|
|
8251
8396
|
// `/topic` asked for the new topic's name, or for the name of a folder to create → this message is the answer (a bad
|
|
8252
8397
|
// name keeps the prompt armed and says so; a slash command above already ended it).
|
|
8253
|
-
if (checkIsAwaitingTopicInput(key) && !
|
|
8398
|
+
if (checkIsAwaitingTopicInput(key) && !isSlashText) {
|
|
8254
8399
|
await submitTopicInput(key, text);
|
|
8255
8400
|
return;
|
|
8256
8401
|
}
|
|
8257
8402
|
// `/stt` asked for a server address or an API key → this message is the answer. A plausible key is deleted at
|
|
8258
8403
|
// once and never echoed; anything else re-arms the step. A slash command above already disarmed it.
|
|
8259
|
-
if (getAwaitedSttStep(key) !== null && !
|
|
8404
|
+
if (getAwaitedSttStep(key) !== null && !isSlashText) {
|
|
8260
8405
|
await submitSttInput(key, text, ctx.message.message_id);
|
|
8261
8406
|
return;
|
|
8262
8407
|
}
|
|
@@ -8265,13 +8410,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8265
8410
|
// must NOT be forwarded to the agent as a prompt — that both leaks the code
|
|
8266
8411
|
// into the transcript and produced the confusing header error (live
|
|
8267
8412
|
// 2026-07-20). Delete it as a secret and hint to re-run /connect.
|
|
8268
|
-
if (!
|
|
8413
|
+
if (!isSlashText && (0, openCodeAuthLogin_1.parseOAuthCallbackFromReply)(text)) {
|
|
8269
8414
|
await deleteThreadMessage(key, ctx.message.message_id);
|
|
8270
8415
|
await replyToThread(key, (0, i18n_1.t)('connect.oauth_callback_no_flow'));
|
|
8271
8416
|
return;
|
|
8272
8417
|
}
|
|
8273
8418
|
const pendingProviderConnect = pendingProviderConnects.get(kStr);
|
|
8274
|
-
if (pendingProviderConnect &&
|
|
8419
|
+
if (pendingProviderConnect && isSlashText) {
|
|
8275
8420
|
pendingProviderConnects.delete(kStr);
|
|
8276
8421
|
await replyToThread(key, (0, i18n_1.t)('connect.cancelled'));
|
|
8277
8422
|
}
|
|
@@ -8291,7 +8436,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8291
8436
|
// one wizard yields exactly one reminder.
|
|
8292
8437
|
const reminderTextRoute = claimReminderTextCapture(key);
|
|
8293
8438
|
if (reminderTextRoute === 'capture' || reminderTextRoute === 'expired') {
|
|
8294
|
-
if (
|
|
8439
|
+
if (isSlashText) {
|
|
8295
8440
|
await cancelReminderWizard(key);
|
|
8296
8441
|
}
|
|
8297
8442
|
else if (reminderTextRoute === 'expired') {
|
|
@@ -8308,7 +8453,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8308
8453
|
// Session is mid-startup → buffer the prompt and replay it once the agent is
|
|
8309
8454
|
// ready, instead of dropping it into the "no agent running" guidance below.
|
|
8310
8455
|
if (startupPromptBuffer.checkIsStarting(kStr)) {
|
|
8311
|
-
await bufferPromptDuringStartup(key, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) },
|
|
8456
|
+
await bufferPromptDuringStartup(key, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, getMessageContext(key, ctx.message));
|
|
8312
8457
|
return;
|
|
8313
8458
|
}
|
|
8314
8459
|
// Set when this very message bound the topic: its welcome is already the answer, so the idle-thread hint at the end
|
|
@@ -8369,14 +8514,14 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8369
8514
|
// natural-language start + forwarded to the agent. `applyNumberedModelPick`
|
|
8370
8515
|
// always replies (even for the unsupported case), so we always return after a
|
|
8371
8516
|
// numeric pick — the user clearly intended a model pick, not a prompt.
|
|
8372
|
-
if (/^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8517
|
+
if (!isForwarded && /^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8373
8518
|
await applyNumberedModelPick(adapter, key, parseInt(text, 10));
|
|
8374
8519
|
return;
|
|
8375
8520
|
}
|
|
8376
8521
|
// Session-pick mode (armed by `/sessions` / `/resume`). Only while the
|
|
8377
8522
|
// thread is armed is a bare digit treated as a pick — a normal numeric
|
|
8378
8523
|
// prompt is never hijacked. See `checkSessionPickAction` for the rules.
|
|
8379
|
-
if (awaitingSessionSelection.has(kStr)) {
|
|
8524
|
+
if (!isForwarded && awaitingSessionSelection.has(kStr)) {
|
|
8380
8525
|
const sessionList = threadSessionLists.get(kStr) ?? [];
|
|
8381
8526
|
const pick = (0, sessionPick_1.checkSessionPickAction)(text, sessionList.length);
|
|
8382
8527
|
if (pick.kind === 'invalid') {
|
|
@@ -8402,7 +8547,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8402
8547
|
awaitingSessionSelection.delete(kStr);
|
|
8403
8548
|
}
|
|
8404
8549
|
// Natural-language start.
|
|
8405
|
-
if (!adapter.checkIsActive(key)) {
|
|
8550
|
+
if (!isForwarded && !adapter.checkIsActive(key)) {
|
|
8406
8551
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(text);
|
|
8407
8552
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8408
8553
|
if (checkIsGeneral(key)) {
|
|
@@ -8448,7 +8593,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8448
8593
|
// never surfaced, so a bare digit during a survey window is NOT a route here —
|
|
8449
8594
|
// it falls through to the normal prompt path instead of being dropped.
|
|
8450
8595
|
const replyRoute = (0, claudeCliAdapter_1.getClaudeReplyRoute)({
|
|
8451
|
-
isQuestionPending: adapter.isQuestionPending?.(key) ?? false,
|
|
8596
|
+
isQuestionPending: !isForwarded && (adapter.isQuestionPending?.(key) ?? false),
|
|
8452
8597
|
isLoginPastePending: adapter.isLoginPastePending?.(key) ?? false,
|
|
8453
8598
|
text,
|
|
8454
8599
|
});
|
|
@@ -8483,16 +8628,16 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8483
8628
|
// branches above already returned for their own cases, so this is reached only
|
|
8484
8629
|
// for a generic active prompt. The message's real send time (Telegram `date`,
|
|
8485
8630
|
// unix seconds) rides along for the `/timestamps` injection, and a Telegram
|
|
8486
|
-
// REPLY folds
|
|
8631
|
+
// REPLY or FORWARD folds its context into the prompt (see `getMessageContext`).
|
|
8487
8632
|
if (adapter.checkIsActive(key)) {
|
|
8488
|
-
const
|
|
8489
|
-
await deliverActivePrompt(key, adapter, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
8633
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
8634
|
+
await deliverActivePrompt(key, adapter, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000, messageContext);
|
|
8490
8635
|
return;
|
|
8491
8636
|
}
|
|
8492
8637
|
// A sleeping conversation (its process stopped, its session kept) is resumed by
|
|
8493
8638
|
// the message itself (L-D4) — the prompt continues the same conversation.
|
|
8494
8639
|
if (await resumeSleepingSessionForPrompt(key)) {
|
|
8495
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
8640
|
+
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000, getMessageContext(key, ctx.message));
|
|
8496
8641
|
return;
|
|
8497
8642
|
}
|
|
8498
8643
|
// Idle thread — guide the user. Three sub-states:
|
|
@@ -8543,16 +8688,16 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8543
8688
|
const fileId = ctx.message.voice.file_id;
|
|
8544
8689
|
const durationSeconds = ctx.message.voice.duration;
|
|
8545
8690
|
const sentAtMs = ctx.message.date * 1000;
|
|
8546
|
-
// A Telegram REPLY on the voice note folds the quoted message into the prompt
|
|
8547
|
-
// Compute it HERE (only the handler has
|
|
8548
|
-
// update loop and only sees `key`/`bot`.
|
|
8549
|
-
const
|
|
8691
|
+
// A Telegram REPLY on the voice note folds the quoted message into the prompt, a
|
|
8692
|
+
// FORWARD of it the mark of its origin. Compute it HERE (only the handler has
|
|
8693
|
+
// `ctx`); the job runs later off the update loop and only sees `key`/`bot`.
|
|
8694
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
8550
8695
|
// Armed LAST, right before the job is queued: nothing between here and the queue may throw and strand an armed note. The
|
|
8551
8696
|
// clock runs from the voice's arrival, so a voice waiting in line behind an earlier one gets its note too; the job finishes it
|
|
8552
8697
|
// the moment its text arrives, and the `finally` is the backstop for a job that never ran or ended some other way.
|
|
8553
8698
|
const progressNote = startVoiceProgressNote(key);
|
|
8554
8699
|
void (0, voiceQueue_1.getVoiceTranscriptionQueue)(key)
|
|
8555
|
-
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), warmedEndpoint, progressNote, sentAtMs,
|
|
8700
|
+
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), warmedEndpoint, progressNote, sentAtMs, messageContext))
|
|
8556
8701
|
.catch((err) => {
|
|
8557
8702
|
console.error('[Bot] Voice job error (already handled):', err);
|
|
8558
8703
|
})
|
|
@@ -8566,9 +8711,9 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8566
8711
|
* Uses only `key`/`bot`, never the request `ctx`, so it survives past the
|
|
8567
8712
|
* handler's return. `sentAtMs` is the voice note's real Telegram send time,
|
|
8568
8713
|
* captured by the handler for the `/timestamps` injection (transcription can
|
|
8569
|
-
* take ~20s, so "now" at forward time would drift). `
|
|
8570
|
-
*
|
|
8571
|
-
* the voice note), plumbed here since the job no longer has `ctx`; so is
|
|
8714
|
+
* take ~20s, so "now" at forward time would drift). `messageContext` is the
|
|
8715
|
+
* message-context block the handler built from `ctx.message` (a Telegram REPLY
|
|
8716
|
+
* or a FORWARD of the voice note), plumbed here since the job no longer has `ctx`; so is
|
|
8572
8717
|
* `requesterId`, the sender the transcript's request is filed under, and
|
|
8573
8718
|
* `warmedEndpoint`, the first engine's endpoint asked for when the note arrived
|
|
8574
8719
|
* (the job reuses that one ask — see `warmUpFirstEngine`), and `progressNote`, the
|
|
@@ -8576,7 +8721,7 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8576
8721
|
* text is here or the voice failed — BEFORE the echo or the failure notice, never
|
|
8577
8722
|
* at the end of the job (delivering the prompt may take long).
|
|
8578
8723
|
*/
|
|
8579
|
-
async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmedEndpoint, progressNote, sentAtMs,
|
|
8724
|
+
async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmedEndpoint, progressNote, sentAtMs, messageContext) {
|
|
8580
8725
|
try {
|
|
8581
8726
|
// Audit S14 / #33: `getFileLink` builds the bot-token URL in one
|
|
8582
8727
|
// place inside Telegraf instead of us materialising the token in a
|
|
@@ -8635,10 +8780,11 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmed
|
|
|
8635
8780
|
await expireReminderWizard(key);
|
|
8636
8781
|
// Session is mid-startup → buffer the transcript and replay it once ready.
|
|
8637
8782
|
if (startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key))) {
|
|
8638
|
-
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId },
|
|
8783
|
+
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId }, messageContext);
|
|
8639
8784
|
return;
|
|
8640
8785
|
}
|
|
8641
|
-
|
|
8786
|
+
// A FORWARDED voice note saying «Claude» is somebody else's words, not the operator's order to start an agent.
|
|
8787
|
+
if (messageContext?.isForwarded !== true && !(0, createAdapter_1.getThreadAdapter)(key).checkIsActive(key)) {
|
|
8642
8788
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(transcript);
|
|
8643
8789
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8644
8790
|
if (checkIsGeneral(key)) {
|
|
@@ -8688,7 +8834,7 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmed
|
|
|
8688
8834
|
// delivered as a fresh prompt — closing the gap where voice queued behind a
|
|
8689
8835
|
// blocked question-turn and the user got no reply.
|
|
8690
8836
|
// Read AFTER the wake: the resume may have switched the thread's adapter.
|
|
8691
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs,
|
|
8837
|
+
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs, messageContext);
|
|
8692
8838
|
}
|
|
8693
8839
|
catch (err) {
|
|
8694
8840
|
console.error('[Bot] Voice handling error:', err);
|
|
@@ -8841,7 +8987,7 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8841
8987
|
const orderedItems = [...items].sort((a, b) => a.messageId - b.messageId);
|
|
8842
8988
|
const files = orderedItems.map((item) => item.albumFile);
|
|
8843
8989
|
const caption = orderedItems.find((item) => item.caption && item.caption.trim())?.caption;
|
|
8844
|
-
const
|
|
8990
|
+
const messageContext = orderedItems.find((item) => item.messageContext)?.messageContext;
|
|
8845
8991
|
const promptText = (0, fileIntake_1.buildAlbumPromptText)(files, caption);
|
|
8846
8992
|
const isStarting = startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key));
|
|
8847
8993
|
// User took over (album upload) before a pending API-error retry fired →
|
|
@@ -8850,8 +8996,8 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8850
8996
|
// A user album is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8851
8997
|
notePersonActivity(key);
|
|
8852
8998
|
try {
|
|
8853
|
-
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId });
|
|
8854
|
-
const quotedPrompt =
|
|
8999
|
+
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId }, messageContext);
|
|
9000
|
+
const quotedPrompt = getPromptWithThreadMessageContext(key, promptText, messageContext);
|
|
8855
9001
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8856
9002
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8857
9003
|
}
|
|
@@ -8903,7 +9049,7 @@ async function handleAlbumFile(ctx, key, meta, mediaGroupId) {
|
|
|
8903
9049
|
messageId: ctx.message.message_id,
|
|
8904
9050
|
albumFile: { kind: meta.kind, savedPath, fileSize: meta.fileSize },
|
|
8905
9051
|
caption: meta.caption,
|
|
8906
|
-
|
|
9052
|
+
messageContext: getMessageContext(key, ctx.message),
|
|
8907
9053
|
requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from),
|
|
8908
9054
|
});
|
|
8909
9055
|
}
|
|
@@ -8933,9 +9079,10 @@ async function handleIncomingFile(ctx, key) {
|
|
|
8933
9079
|
cancelApiRetry(key);
|
|
8934
9080
|
// A user file is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8935
9081
|
notePersonActivity(key);
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
const
|
|
9082
|
+
// A file sent as a REPLY carries the message it answers, a forwarded one its origin, as a typed or spoken message does.
|
|
9083
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
9084
|
+
const opening = await openTopicRequest(key, promptText, { source: 'file', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, messageContext);
|
|
9085
|
+
const quotedPrompt = getPromptWithThreadMessageContext(key, promptText, messageContext);
|
|
8939
9086
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8940
9087
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8941
9088
|
}
|
|
@@ -9614,20 +9761,21 @@ bot.action(/^qa_(\d+)_(\d+)$/, async (ctx) => {
|
|
|
9614
9761
|
* @description Buffer a free-form prompt (text OR voice) that arrived while the
|
|
9615
9762
|
* thread's session is starting — the startup twin of {@link deliverActivePrompt}.
|
|
9616
9763
|
* The request is opened at capture time (S7), so the buffered text carries its
|
|
9617
|
-
* header; the
|
|
9618
|
-
* the buffered text as is and a REPLY made during the boot would
|
|
9619
|
-
* the agent without the message it points at.
|
|
9764
|
+
* header; the message-context block is folded in here too, since the replay forwards
|
|
9765
|
+
* the buffered text as is and a REPLY or a FORWARD made during the boot would
|
|
9766
|
+
* otherwise reach the agent without the message it points at, or as the operator's own words.
|
|
9620
9767
|
*/
|
|
9621
|
-
async function bufferPromptDuringStartup(key, text, intake,
|
|
9622
|
-
// The same for a bare option number typed in that window: it answers the question asked again.
|
|
9623
|
-
|
|
9768
|
+
async function bufferPromptDuringStartup(key, text, intake, messageContext) {
|
|
9769
|
+
// The same for a bare option number typed in that window: it answers the question asked again. A FORWARDED "1" is somebody
|
|
9770
|
+
// else's words, not the operator's pick: it is delivered, marked, like any other message.
|
|
9771
|
+
if (messageContext?.isForwarded !== true && await answerReAskedQuestionByNumber(key, text))
|
|
9624
9772
|
return;
|
|
9625
9773
|
// A person wrote, in a window where the session is starting or being stopped: it counts like a message that reaches
|
|
9626
9774
|
// `deliverActivePrompt` — the idle latch clears, and a question the idle compaction re-asked is closed (the idle fire
|
|
9627
9775
|
// posts it just before the stop, so this window is where a message instead of a tap most often lands).
|
|
9628
9776
|
notePersonActivity(key);
|
|
9629
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9630
|
-
const quotedText =
|
|
9777
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9778
|
+
const quotedText = getPromptWithThreadMessageContext(key, text, messageContext);
|
|
9631
9779
|
await deliverPromptOrBuffer(key, `${opening.header}${quotedText}`, true);
|
|
9632
9780
|
trackTopicRequestTurn(key, opening);
|
|
9633
9781
|
}
|
|
@@ -9648,9 +9796,11 @@ async function bufferPromptDuringStartup(key, text, intake, replyContext) {
|
|
|
9648
9796
|
* `answerQuestion`). The tmux-scrape Claude and the terminal never reach it (no `pendingQuestions` entry): for them
|
|
9649
9797
|
* `forwardPromptToAgent` interrupts the TUI selector itself.
|
|
9650
9798
|
*/
|
|
9651
|
-
async function deliverActivePrompt(key, adapter, text, intake, sentAtMs,
|
|
9799
|
+
async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, messageContext) {
|
|
9800
|
+
// A FORWARDED message is content, never control input: it answers no question and purges no context, whatever its words are.
|
|
9801
|
+
const isForwarded = messageContext?.isForwarded === true;
|
|
9652
9802
|
// A bare option number answers the question the idle compaction asked again (a tap's own label comes in with no intake).
|
|
9653
|
-
if (intake !== null && await answerReAskedQuestionByNumber(key, text))
|
|
9803
|
+
if (intake !== null && !isForwarded && await answerReAskedQuestionByNumber(key, text))
|
|
9654
9804
|
return null;
|
|
9655
9805
|
// A genuine USER message (text or voice) — clear the compact-on-idle latch so
|
|
9656
9806
|
// the next idle period can compact again (D2), whether it answers a pending
|
|
@@ -9660,16 +9810,17 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9660
9810
|
if (pending && adapter.answerQuestion) {
|
|
9661
9811
|
const currentQuestion = pending.data.questions[pending.currentIndex];
|
|
9662
9812
|
const route = (0, openCodeQuestionFlow_1.getQuestionReplyRoute)(text, currentQuestion);
|
|
9663
|
-
if (route.kind === 'answer') {
|
|
9813
|
+
if (route.kind === 'answer' && !isForwarded) {
|
|
9664
9814
|
// Answering a pending question (bare digit) is a pick, not a prompt about
|
|
9665
9815
|
// the quote — the reply context is deliberately dropped here. Not a request
|
|
9666
|
-
// either: the turn it unblocks continues under the open one.
|
|
9816
|
+
// either: the turn it unblocks continues under the open one. A forwarded digit
|
|
9817
|
+
// is not a pick: it falls to the free-form route below and reaches the agent marked.
|
|
9667
9818
|
await applyQuestionAnswer(key, route.labels);
|
|
9668
9819
|
return null;
|
|
9669
9820
|
}
|
|
9670
9821
|
// Free-form text cancels the question and is a fresh prompt — a request (S7).
|
|
9671
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9672
|
-
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9822
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9823
|
+
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, opening.header);
|
|
9673
9824
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
9674
9825
|
return null;
|
|
9675
9826
|
}
|
|
@@ -9678,7 +9829,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9678
9829
|
// before forwarding — the slash text itself never gets a preamble. The agent's
|
|
9679
9830
|
// context is gone, so any intake files it might reference are now useless —
|
|
9680
9831
|
// purge the thread's files dir in the same breath.
|
|
9681
|
-
if (text === forwardedClearCommand) {
|
|
9832
|
+
if (text === forwardedClearCommand && !isForwarded) {
|
|
9682
9833
|
clearThreadContextMarker(key);
|
|
9683
9834
|
await (0, botFileStorage_1.purgeThreadFiles)(getDataDir(), key).catch((e) => console.warn(`[file] purge on /clear failed for ${(0, sessionKey_1.keyToString)(key)}:`, e));
|
|
9684
9835
|
}
|
|
@@ -9697,7 +9848,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9697
9848
|
// The request (S7) is opened AFTER the user takeover cancelled an armed limit
|
|
9698
9849
|
// wait (the handlers' `cancelApiRetry`) and before the forward, so its id is
|
|
9699
9850
|
// durable by the time the agent reads it.
|
|
9700
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9851
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9701
9852
|
// Routed now, not when the message arrived: the idle stop may have begun or ended during the awaits since.
|
|
9702
9853
|
// The forward can itself end in no session — a prompt that waited for an adopt replay found the session gone and nothing to wake;
|
|
9703
9854
|
// it has told the person already (`forwardPromptToAgent`), so what is left here is the request this prompt opened.
|
|
@@ -9705,10 +9856,10 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9705
9856
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
9706
9857
|
checkIsSessionActive: () => adapter.checkIsActive(key),
|
|
9707
9858
|
buffer: async () => {
|
|
9708
|
-
await deliverPromptOrBuffer(key, `${opening.header}${
|
|
9859
|
+
await deliverPromptOrBuffer(key, `${opening.header}${getPromptWithThreadMessageContext(key, text, messageContext)}`, true);
|
|
9709
9860
|
},
|
|
9710
9861
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
9711
|
-
forward: () => forwardPromptToAgent(key, (0, createAdapter_1.getThreadAdapter)(key), text, sentAtMs, {
|
|
9862
|
+
forward: () => forwardPromptToAgent(key, (0, createAdapter_1.getThreadAdapter)(key), text, sentAtMs, { messageContext, requestHeader: opening.header }),
|
|
9712
9863
|
reportNoSession: async (isAlreadyTold) => {
|
|
9713
9864
|
if (!isAlreadyTold)
|
|
9714
9865
|
await replyToThread(key, (0, i18n_1.t)('agent.no_session'));
|
|
@@ -9756,7 +9907,7 @@ function retirePendingQuestionInBackground(key) {
|
|
|
9756
9907
|
* close it on the server, abort the wedged OpenCode turn (`SIGINT` → `/session/:id/
|
|
9757
9908
|
* abort`), post the "previous question cancelled" notice, then forward.
|
|
9758
9909
|
*/
|
|
9759
|
-
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9910
|
+
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, requestHeader) {
|
|
9760
9911
|
// When the question bubble itself was closed with its «not answered» note, that IS the
|
|
9761
9912
|
// cancellation notice — a second standalone "previous question cancelled" line is
|
|
9762
9913
|
// pure noise (the reported triple message). The standalone notice is kept only
|
|
@@ -9775,7 +9926,7 @@ async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, rep
|
|
|
9775
9926
|
if (!didLabelQuestionMessage) {
|
|
9776
9927
|
await replyToThread(key, (0, i18n_1.t)('agent.question_cancelled_for_prompt'));
|
|
9777
9928
|
}
|
|
9778
|
-
return forwardPromptToAgent(key, adapter, text, sentAtMs, {
|
|
9929
|
+
return forwardPromptToAgent(key, adapter, text, sentAtMs, { messageContext, requestHeader });
|
|
9779
9930
|
}
|
|
9780
9931
|
/**
|
|
9781
9932
|
* @description Record one answer for the CURRENTLY shown OpenCode question and
|
|
@@ -9856,10 +10007,23 @@ function handleAgentOutput(key, output, meta) {
|
|
|
9856
10007
|
// skip while THIS thread's own compaction streams (loop guard).
|
|
9857
10008
|
markThreadTurnProducedOutput(key);
|
|
9858
10009
|
noteThreadActivity(key);
|
|
9859
|
-
// A backend's own streamed compaction summary (OpenCode) obeys `/compact_summary`, like the
|
|
9860
|
-
//
|
|
9861
|
-
|
|
10010
|
+
// A backend's own streamed compaction summary (OpenCode) obeys `/compact_summary`, like the summary the bot posts for the
|
|
10011
|
+
// other backends: off → the compaction ends in its short notices, plus the summary's self-review section, which is
|
|
10012
|
+
// shown in hide mode too; on → the summary is shown without the marker lines the agent was asked to write.
|
|
10013
|
+
if (meta?.isCompactionSummary) {
|
|
10014
|
+
const summaryTail = routeStreamedCompactionSummaryTail(key, output, meta);
|
|
10015
|
+
if (summaryTail === null)
|
|
10016
|
+
return;
|
|
10017
|
+
deliverAgentOutput(key, summaryTail.text, { ...meta, isContinuation: summaryTail.isContinuation });
|
|
9862
10018
|
return;
|
|
10019
|
+
}
|
|
10020
|
+
deliverAgentOutput(key, output, meta);
|
|
10021
|
+
}
|
|
10022
|
+
/**
|
|
10023
|
+
* @description The rest of {@link handleAgentOutput} for the text that is going to the topic: the answers-only view, the
|
|
10024
|
+
* sub-agent chunks, the questions and the answer itself.
|
|
10025
|
+
*/
|
|
10026
|
+
function deliverAgentOutput(key, output, meta) {
|
|
9863
10027
|
// Answers-only view (S9): the agent's text — sub-agent chunks and progress
|
|
9864
10028
|
// bursts included — never reaches the topic; a native question still does (it
|
|
9865
10029
|
// falls through to its branch below). A real answer still retires a pinned
|
|
@@ -10174,7 +10338,7 @@ async function sendStatusFrame(key, status) {
|
|
|
10174
10338
|
const editId = msgState.statusMessageId;
|
|
10175
10339
|
const ok = await editThreadMessage(key, editId, firstRendered, {
|
|
10176
10340
|
parse_mode: 'HTML',
|
|
10177
|
-
});
|
|
10341
|
+
}, chunks[0]);
|
|
10178
10342
|
// A delete that landed during the edit already nulled (or replaced) the id;
|
|
10179
10343
|
// don't claim the frame as live — let the create path below re-evaluate.
|
|
10180
10344
|
if (ok && msgState.statusMessageId === editId) {
|
|
@@ -10305,7 +10469,7 @@ function finishThinkingMessage(key) {
|
|
|
10305
10469
|
*/
|
|
10306
10470
|
function queueThinkingFrame(key, frameText, isTerminal) {
|
|
10307
10471
|
const c = getThinkingCoalesceState(key);
|
|
10308
|
-
c.
|
|
10472
|
+
c.pending = (0, renderAgentHtml_1.renderAgentFrame)(frameText);
|
|
10309
10473
|
if (isTerminal)
|
|
10310
10474
|
c.detachAfterDrain = true;
|
|
10311
10475
|
if (!c.inFlight)
|
|
@@ -10325,14 +10489,14 @@ async function flushThinkingCoalescer(key) {
|
|
|
10325
10489
|
return;
|
|
10326
10490
|
c.inFlight = true;
|
|
10327
10491
|
try {
|
|
10328
|
-
while (c.
|
|
10329
|
-
const
|
|
10330
|
-
c.
|
|
10331
|
-
if (html === c.lastSentHtml)
|
|
10492
|
+
while (c.pending !== null) {
|
|
10493
|
+
const frame = c.pending;
|
|
10494
|
+
c.pending = null;
|
|
10495
|
+
if (frame.html === c.lastSentHtml)
|
|
10332
10496
|
continue;
|
|
10333
|
-
const sent = await sendThinkingFrame(key,
|
|
10497
|
+
const sent = await sendThinkingFrame(key, frame);
|
|
10334
10498
|
if (sent)
|
|
10335
|
-
c.lastSentHtml = html;
|
|
10499
|
+
c.lastSentHtml = frame.html;
|
|
10336
10500
|
}
|
|
10337
10501
|
if (c.detachAfterDrain) {
|
|
10338
10502
|
c.detachAfterDrain = false;
|
|
@@ -10346,14 +10510,15 @@ async function flushThinkingCoalescer(key) {
|
|
|
10346
10510
|
/**
|
|
10347
10511
|
* @description Edit the thread's thinking message in place, or create it on the
|
|
10348
10512
|
* first frame. The frame is pre-rendered HTML (one message — `full`-mode bodies
|
|
10349
|
-
* are tail-trimmed to fit)
|
|
10513
|
+
* are tail-trimmed to fit) with its source text as the plain twin that goes out
|
|
10514
|
+
* if Telegram refuses the markup. Returns `true` when the frame reached Telegram.
|
|
10350
10515
|
*/
|
|
10351
|
-
async function sendThinkingFrame(key,
|
|
10516
|
+
async function sendThinkingFrame(key, frame) {
|
|
10352
10517
|
const msgState = getThreadMessageState(key);
|
|
10353
10518
|
try {
|
|
10354
10519
|
if (msgState.thinkingMessageId !== null) {
|
|
10355
10520
|
const editId = msgState.thinkingMessageId;
|
|
10356
|
-
const ok = await editThreadMessage(key, editId,
|
|
10521
|
+
const ok = await editThreadMessage(key, editId, frame.html, { parse_mode: 'HTML' }, frame.plain);
|
|
10357
10522
|
// A clear (session end / takeover) may have nulled the id mid-edit — only
|
|
10358
10523
|
// treat the edit as live if the id still points at the message we edited.
|
|
10359
10524
|
if (ok && msgState.thinkingMessageId === editId)
|
|
@@ -10367,7 +10532,7 @@ async function sendThinkingFrame(key, renderedHtml) {
|
|
|
10367
10532
|
// just-created message instead of resurrecting it as an orphan under a
|
|
10368
10533
|
// "session ended" / question UI (the leftover-frame guard).
|
|
10369
10534
|
const generationAtStart = msgState.thinkingFrameGeneration;
|
|
10370
|
-
const id = await replyChunkWithFallback(key,
|
|
10535
|
+
const id = await replyChunkWithFallback(key, frame.html, frame.plain);
|
|
10371
10536
|
if (id === null)
|
|
10372
10537
|
return false;
|
|
10373
10538
|
if (msgState.thinkingFrameGeneration !== generationAtStart) {
|
|
@@ -10662,7 +10827,7 @@ async function refreshSubagentStatus(key) {
|
|
|
10662
10827
|
// send finally lands.
|
|
10663
10828
|
state.lastSubagentText = text;
|
|
10664
10829
|
try {
|
|
10665
|
-
const sent = await editThreadMessage(key, messageId, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' });
|
|
10830
|
+
const sent = await editThreadMessage(key, messageId, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' }, text);
|
|
10666
10831
|
// Guard the post-await mutations against a close+reopen that swapped the
|
|
10667
10832
|
// frame WHILE this edit was draining the pacer: `lastSubagentText` /
|
|
10668
10833
|
// `subagentEditInFlight` now belong to a DIFFERENT frame that owns its own
|
|
@@ -10787,7 +10952,7 @@ function handleSubagentStatus(key, payload) {
|
|
|
10787
10952
|
state.lastSubagentText = null;
|
|
10788
10953
|
state.subagentEditInFlight = false;
|
|
10789
10954
|
const text = (0, subagentStatusRender_1.buildSubagentElapsedText)(state.subagentTitle, 0);
|
|
10790
|
-
const id = await replyToThread(key, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' });
|
|
10955
|
+
const id = await replyToThread(key, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' }, { plainFallbackText: text });
|
|
10791
10956
|
if (id === null)
|
|
10792
10957
|
return;
|
|
10793
10958
|
// A close (teardown) may have landed during the create — don't leave the
|
|
@@ -11248,6 +11413,7 @@ exports.COMMANDS_MENU = [
|
|
|
11248
11413
|
{ command: 'compact', description: '🧹 Compact agent context' },
|
|
11249
11414
|
{ command: 'compact_on_idle', description: '🧹 Auto-compact after idle (toggle)' },
|
|
11250
11415
|
{ command: 'compact_summary', description: '📄 Post the compaction summary (toggle)' },
|
|
11416
|
+
{ command: 'compact_self_review', description: '💡 Agent self-review on compaction: its mistakes and what to change in its instructions' },
|
|
11251
11417
|
{ command: 'bot_skills', description: '🧰 The bot\'s own skills for agents (on/off)' },
|
|
11252
11418
|
{ command: 'task_agents', description: '🧵 How many tracker task agents work at once' },
|
|
11253
11419
|
{ command: 'runners', description: '🖥 Runners — machines for the agents\' tests and builds' },
|
|
@@ -12326,16 +12492,33 @@ function createSessionPostDeps() {
|
|
|
12326
12492
|
function wireScheduler(wiring) {
|
|
12327
12493
|
const { jiraConnector } = wiring;
|
|
12328
12494
|
const ledger = new runLedger_1.RunLedger();
|
|
12495
|
+
// The scheduler's unpin port: the ids that are worth another try come back, so a pin Telegram did not answer for is not forgotten.
|
|
12496
|
+
const unpinThreadMessages = async (threadKeyStr, messageIds) => {
|
|
12497
|
+
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12498
|
+
if (!checkIsTelegramPrimitiveKey(key, 'unpinMessage'))
|
|
12499
|
+
return [];
|
|
12500
|
+
return (0, unpinMessages_1.unpinMessagesReportingRetryable)(messageIds, (messageId) => sendUnpin(key, messageId), (messageId, error) => console.warn(`[scheduler] unpin ${(0, sessionKey_1.keyToString)(key)} msg ${messageId} failed: ${describeSendError(error)}`));
|
|
12501
|
+
};
|
|
12329
12502
|
const delivery = (0, delivery_1.createScheduleDelivery)({
|
|
12330
12503
|
...createSessionPostDeps(),
|
|
12331
12504
|
...checkStatusLinePorts,
|
|
12332
|
-
|
|
12333
|
-
|
|
12505
|
+
// A scheduled fire and a check alert are ordinary silent output; a folded detail (the prompt, a check's output) goes
|
|
12506
|
+
// in an expandable quotation. Only a reminder is sent as it is, and pinned.
|
|
12507
|
+
announce: (threadKeyStr, text, options) => {
|
|
12334
12508
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
12509
|
+
const extra = options?.isSilent ? { disable_notification: true } : {};
|
|
12510
|
+
if (options?.foldedDetail === undefined)
|
|
12511
|
+
return replyToThread(key, text, extra);
|
|
12512
|
+
// If Telegram ever rejects the markup, the retry is the same words as plain text — never the tags shown literally.
|
|
12513
|
+
const foldedMessage = (0, foldedMessage_1.buildFoldedMessage)(text, options.foldedDetail);
|
|
12514
|
+
return replyToThread(key, foldedMessage.html, { ...extra, parse_mode: 'HTML' }, { plainFallbackText: foldedMessage.plain });
|
|
12515
|
+
},
|
|
12516
|
+
// The only scheduler pin left: a reminder, which pierces a muted topic on purpose.
|
|
12517
|
+
pin: async (threadKeyStr, messageId) => {
|
|
12518
|
+
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12519
|
+
await (0, rateLimiter_1.enqueueSend)(key, () => bot.telegram.pinChatMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId, { disable_notification: false }));
|
|
12338
12520
|
},
|
|
12521
|
+
unpinMessages: unpinThreadMessages,
|
|
12339
12522
|
runCheck: async (threadKeyStr, command, timeoutMs) => {
|
|
12340
12523
|
const decision = (0, validation_1.resolveBoundWorkDir)(ENV.workRoot, state.getBinding((0, sessionKey_1.keyFromString)(threadKeyStr)));
|
|
12341
12524
|
if (decision.kind !== 'proceed')
|
|
@@ -12349,15 +12532,7 @@ function wireScheduler(wiring) {
|
|
|
12349
12532
|
await state.upsertSchedule({ ...record, isCheckFailing: isFailing, updatedAt: new Date().toISOString() });
|
|
12350
12533
|
await state.flush();
|
|
12351
12534
|
},
|
|
12352
|
-
|
|
12353
|
-
const record = state.getSchedules()[jobId];
|
|
12354
|
-
if (!record)
|
|
12355
|
-
return;
|
|
12356
|
-
const alertPinMessageIds = [...(record.alertPinMessageIds ?? []), messageId];
|
|
12357
|
-
await state.upsertSchedule({ ...record, alertPinMessageIds, updatedAt: new Date().toISOString() });
|
|
12358
|
-
// Saved at once, like the failing flag: an id lost in a crash would leave its alert pinned for good.
|
|
12359
|
-
await state.flush();
|
|
12360
|
-
},
|
|
12535
|
+
clearAlertPins: (jobId, releasedMessageIds) => (0, store_2.clearCheckAlertPins)(state, jobId, releasedMessageIds),
|
|
12361
12536
|
checkIsStatusShown: (threadKeyStr) => {
|
|
12362
12537
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12363
12538
|
return (0, checkStatus_1.checkIsCheckStatusShown)({ isTelegram: (0, sessionKeyCodec_1.checkIsTelegramKey)(key), view: state.getDisplayPrefs(key).view });
|
|
@@ -12405,11 +12580,7 @@ function wireScheduler(wiring) {
|
|
|
12405
12580
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12406
12581
|
return (0, createAdapter_1.getThreadAdapterNameRaw)(key) ?? state.getAgent(key)?.name;
|
|
12407
12582
|
},
|
|
12408
|
-
unpinMessages:
|
|
12409
|
-
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12410
|
-
for (const messageId of messageIds)
|
|
12411
|
-
await unpinMessageQuiet(key, messageId);
|
|
12412
|
-
},
|
|
12583
|
+
unpinMessages: unpinThreadMessages,
|
|
12413
12584
|
// A cancelled check's status line goes through the same best-effort delete the delivery uses.
|
|
12414
12585
|
deleteMessage: checkStatusLinePorts.deleteMessage,
|
|
12415
12586
|
// Routed through the outbound seam: the agent-facing file tool is a
|
|
@@ -12733,6 +12904,8 @@ async function startBot() {
|
|
|
12733
12904
|
(0, createAdapter_1.registerClaudeConfigDirReader)(resolveThreadClaudeConfigDir);
|
|
12734
12905
|
// The «Bot skills» switch (`/bot_skills`): every agent start, the OpenCode server's start and the bot MCP's instructions read it.
|
|
12735
12906
|
(0, botSkills_1.setBotSkillsReader)(botSkillsReader);
|
|
12907
|
+
// The flags the CLI's and OpenCode's own compactions read for `/compact_self_review` follow the saved settings from the start.
|
|
12908
|
+
syncAllCompactSelfReviewFlags();
|
|
12736
12909
|
(0, createAdapter_1.registerClaudeRateLimitSink)(onClaudeRateLimitEvent);
|
|
12737
12910
|
(0, createAdapter_1.registerClaudeTurnCostSink)(onClaudeTurnCost);
|
|
12738
12911
|
if (ENV.testTimings.openCodeServerUpBudgetMs !== undefined)
|
|
@@ -12740,6 +12913,8 @@ async function startBot() {
|
|
|
12740
12913
|
// The usage cache: a first poll now (off the boot path), then the timer.
|
|
12741
12914
|
claudeUsageRefresher.start();
|
|
12742
12915
|
void claudeUsageRefresher.refreshAll();
|
|
12916
|
+
// The daily recheck of API accounts marked used up (`utils/claudeApiCreditRecheck.ts`): a pass now — a day may have passed while the bot was down — then the timer.
|
|
12917
|
+
(0, claudeApiCreditRecheck_1.startClaudeApiCreditRechecks)(claudeApiCreditRecheckPorts, ENV.testTimings.creditRecheckPollMs ?? claudeApiCreditRecheck_1.claudeApiCreditRecheckPollMs);
|
|
12743
12918
|
const jiraConnector = ENV.servedPlatforms.has('jira') ? await prepareJiraConnectorOrExit() : null;
|
|
12744
12919
|
todoJiraConversations = jiraConnector;
|
|
12745
12920
|
if (jiraConnector) {
|
|
@@ -12922,7 +13097,11 @@ async function startBot() {
|
|
|
12922
13097
|
void todoReminderEngine?.noteAdapterTurnEnd(key).catch((e) => console.warn(`[todos] the turn end of ${(0, sessionKey_1.keyToString)(key)} was not noted:`, e instanceof Error ? e.message : e));
|
|
12923
13098
|
handleAgentTurnEnded(key);
|
|
12924
13099
|
}),
|
|
12925
|
-
onContextCompacted: (key, trigger) => (0, adapterEventRouting_1.dispatchAdapterEvent)(key, 'contextCompacted', () =>
|
|
13100
|
+
onContextCompacted: (key, trigger) => (0, adapterEventRouting_1.dispatchAdapterEvent)(key, 'contextCompacted', () => {
|
|
13101
|
+
noteConversationContextReset(key, `compaction (${trigger ?? 'bot'})`);
|
|
13102
|
+
// The CLI's own overflow compaction: nobody else posts its self-review section (a bot-issued one is its caller's).
|
|
13103
|
+
void postOwnCompactionInstructionGaps(key).catch((e) => console.warn(`[compact] ${(0, sessionKey_1.keyToString)(key)} the self-review section of the CLI's own compaction was not posted:`, e instanceof Error ? e.message : e));
|
|
13104
|
+
}),
|
|
12926
13105
|
onConversationLost: (key) => (0, adapterEventRouting_1.dispatchAdapterEvent)(key, 'conversationLost', () => withThreadLocale(key, () => handleConversationLost(key)), () => { dropLostConversationWatermark(key); noteConversationContextReset(key, 'its transcript was lost'); }),
|
|
12927
13106
|
onError: (key, error) => (0, adapterEventRouting_1.dispatchAdapterEvent)(key, 'error', () => withThreadLocale(key, () => handleAgentError(key, error)), () => {
|
|
12928
13107
|
console.error(`[Bot] adapter error ${(0, sessionKey_1.keyToString)(key)}:`, error.message);
|