charness 3.9.1 → 3.11.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 +155 -0
- package/DEVELOPMENT.md +4 -1
- package/README.md +2 -1
- package/SETUP.md +6 -4
- package/agent-plugin/README.md +2 -2
- package/agent-plugin/skills/charness-delegate-opencode/SKILL.md +1 -1
- package/agent-plugin/skills/charness-manager/SKILL.md +11 -6
- package/dist/bot.d.ts +27 -18
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +390 -231
- package/dist/bot.js.map +1 -1
- package/dist/connectors/jira/adf.d.ts.map +1 -1
- package/dist/connectors/jira/adf.js +2 -3
- package/dist/connectors/jira/adf.js.map +1 -1
- package/dist/connectors/telegram/commands/botCore.d.ts +17 -0
- package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +3 -3
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/runners.d.ts +10 -1
- package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.js +85 -17
- 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/runnerLinkNotices.d.ts +24 -0
- package/dist/connectors/telegram/runnerLinkNotices.d.ts.map +1 -0
- package/dist/connectors/telegram/runnerLinkNotices.js +95 -0
- package/dist/connectors/telegram/runnerLinkNotices.js.map +1 -0
- package/dist/connectors/telegram/runnerPairingMessages.d.ts +9 -0
- package/dist/connectors/telegram/runnerPairingMessages.d.ts.map +1 -1
- package/dist/connectors/telegram/runnerPairingMessages.js +17 -1
- 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 +30 -3
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +30 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +30 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +30 -3
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +30 -3
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +30 -3
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +30 -3
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +30 -3
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +30 -3
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +30 -3
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +30 -3
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +30 -3
- package/dist/i18n/zh.js.map +1 -1
- package/dist/outputTrace.d.ts +6 -0
- package/dist/outputTrace.d.ts.map +1 -1
- package/dist/outputTrace.js +15 -9
- package/dist/outputTrace.js.map +1 -1
- package/dist/rateLimiter.d.ts +3 -1
- package/dist/rateLimiter.d.ts.map +1 -1
- package/dist/rateLimiter.js +3 -1
- package/dist/rateLimiter.js.map +1 -1
- package/dist/remoteRun/cliArgs.d.ts +6 -1
- package/dist/remoteRun/cliArgs.d.ts.map +1 -1
- package/dist/remoteRun/cliArgs.js +39 -2
- package/dist/remoteRun/cliArgs.js.map +1 -1
- package/dist/remoteRun/exitCodes.d.ts +12 -2
- package/dist/remoteRun/exitCodes.d.ts.map +1 -1
- package/dist/remoteRun/exitCodes.js +3 -0
- package/dist/remoteRun/exitCodes.js.map +1 -1
- package/dist/remoteRun/foreground.d.ts +13 -0
- package/dist/remoteRun/foreground.d.ts.map +1 -1
- package/dist/remoteRun/foreground.js +15 -2
- package/dist/remoteRun/foreground.js.map +1 -1
- package/dist/remoteRun/heldBackNotice.d.ts +7 -0
- package/dist/remoteRun/heldBackNotice.d.ts.map +1 -0
- package/dist/remoteRun/heldBackNotice.js +92 -0
- package/dist/remoteRun/heldBackNotice.js.map +1 -0
- package/dist/remoteRun/interrupts.d.ts +6 -2
- package/dist/remoteRun/interrupts.d.ts.map +1 -1
- package/dist/remoteRun/interrupts.js +18 -3
- package/dist/remoteRun/interrupts.js.map +1 -1
- package/dist/remoteRun/leaseTiming.d.ts +1 -2
- package/dist/remoteRun/leaseTiming.d.ts.map +1 -1
- package/dist/remoteRun/leaseTiming.js +3 -17
- package/dist/remoteRun/leaseTiming.js.map +1 -1
- package/dist/remoteRun/output.d.ts +16 -1
- package/dist/remoteRun/output.d.ts.map +1 -1
- package/dist/remoteRun/output.js +28 -2
- package/dist/remoteRun/output.js.map +1 -1
- package/dist/remoteRun/probe.d.ts +40 -2
- package/dist/remoteRun/probe.d.ts.map +1 -1
- package/dist/remoteRun/probe.js +58 -2
- package/dist/remoteRun/probe.js.map +1 -1
- package/dist/remoteRun/project.d.ts +2 -2
- package/dist/remoteRun/project.d.ts.map +1 -1
- package/dist/remoteRun/project.js +5 -4
- package/dist/remoteRun/project.js.map +1 -1
- package/dist/remoteRun/remoteRunCli.d.ts +1 -1
- package/dist/remoteRun/remoteRunCli.d.ts.map +1 -1
- package/dist/remoteRun/remoteRunCli.js +6 -3
- package/dist/remoteRun/remoteRunCli.js.map +1 -1
- package/dist/remoteRun/runnerWait.d.ts +3 -3
- package/dist/remoteRun/runnerWait.d.ts.map +1 -1
- package/dist/remoteRun/runnerWait.js +12 -6
- package/dist/remoteRun/runnerWait.js.map +1 -1
- package/dist/remoteRun/runnerWaitTiming.d.ts +1 -1
- package/dist/remoteRun/runnerWaitTiming.d.ts.map +1 -1
- package/dist/remoteRun/runnerWaitTiming.js +3 -16
- package/dist/remoteRun/runnerWaitTiming.js.map +1 -1
- package/dist/remoteRun/runners.d.ts +16 -3
- package/dist/remoteRun/runners.d.ts.map +1 -1
- package/dist/remoteRun/runners.js +42 -4
- package/dist/remoteRun/runners.js.map +1 -1
- package/dist/remoteRun/sendPlan.d.ts +11 -1
- package/dist/remoteRun/sendPlan.d.ts.map +1 -1
- package/dist/remoteRun/sendPlan.js +29 -5
- package/dist/remoteRun/sendPlan.js.map +1 -1
- package/dist/remoteRun/submit.d.ts.map +1 -1
- package/dist/remoteRun/submit.js +13 -3
- package/dist/remoteRun/submit.js.map +1 -1
- package/dist/runnerUtility/adminService.d.ts +30 -2
- package/dist/runnerUtility/adminService.d.ts.map +1 -1
- package/dist/runnerUtility/adminService.js +104 -6
- package/dist/runnerUtility/adminService.js.map +1 -1
- package/dist/runnerUtility/appInstall.d.ts +13 -4
- package/dist/runnerUtility/appInstall.d.ts.map +1 -1
- package/dist/runnerUtility/appInstall.js +46 -19
- package/dist/runnerUtility/appInstall.js.map +1 -1
- package/dist/runnerUtility/appUpdate.js +1 -1
- package/dist/runnerUtility/appUpdate.js.map +1 -1
- package/dist/runnerUtility/execEnv.d.ts +2 -0
- package/dist/runnerUtility/execEnv.d.ts.map +1 -1
- package/dist/runnerUtility/execEnv.js +6 -2
- package/dist/runnerUtility/execEnv.js.map +1 -1
- package/dist/runnerUtility/guiAgent.d.ts +126 -0
- package/dist/runnerUtility/guiAgent.d.ts.map +1 -0
- package/dist/runnerUtility/guiAgent.js +591 -0
- package/dist/runnerUtility/guiAgent.js.map +1 -0
- package/dist/runnerUtility/guiAgentHeal.d.ts +128 -0
- package/dist/runnerUtility/guiAgentHeal.d.ts.map +1 -0
- package/dist/runnerUtility/guiAgentHeal.js +284 -0
- package/dist/runnerUtility/guiAgentHeal.js.map +1 -0
- package/dist/runnerUtility/homeFolders.d.ts +33 -0
- package/dist/runnerUtility/homeFolders.d.ts.map +1 -0
- package/dist/runnerUtility/homeFolders.js +158 -0
- package/dist/runnerUtility/homeFolders.js.map +1 -0
- package/dist/runnerUtility/hubClient.d.ts +12 -2
- package/dist/runnerUtility/hubClient.d.ts.map +1 -1
- package/dist/runnerUtility/hubClient.js +24 -3
- package/dist/runnerUtility/hubClient.js.map +1 -1
- package/dist/runnerUtility/iosCheck.d.ts +7 -1
- package/dist/runnerUtility/iosCheck.d.ts.map +1 -1
- package/dist/runnerUtility/iosCheck.js +14 -5
- package/dist/runnerUtility/iosCheck.js.map +1 -1
- package/dist/runnerUtility/isolatedCommand.d.ts +31 -0
- package/dist/runnerUtility/isolatedCommand.d.ts.map +1 -0
- package/dist/runnerUtility/isolatedCommand.js +132 -0
- package/dist/runnerUtility/isolatedCommand.js.map +1 -0
- package/dist/runnerUtility/keepAwake.d.ts +67 -0
- package/dist/runnerUtility/keepAwake.d.ts.map +1 -0
- package/dist/runnerUtility/keepAwake.js +211 -0
- package/dist/runnerUtility/keepAwake.js.map +1 -0
- package/dist/runnerUtility/lidPollTiming.d.ts +11 -0
- package/dist/runnerUtility/lidPollTiming.d.ts.map +1 -0
- package/dist/runnerUtility/lidPollTiming.js +18 -0
- package/dist/runnerUtility/lidPollTiming.js.map +1 -0
- package/dist/runnerUtility/lidState.d.ts +57 -0
- package/dist/runnerUtility/lidState.d.ts.map +1 -0
- package/dist/runnerUtility/lidState.js +195 -0
- package/dist/runnerUtility/lidState.js.map +1 -0
- package/dist/runnerUtility/linkLoop.d.ts +5 -0
- package/dist/runnerUtility/linkLoop.d.ts.map +1 -1
- package/dist/runnerUtility/linkLoop.js +37 -1
- package/dist/runnerUtility/linkLoop.js.map +1 -1
- package/dist/runnerUtility/packageManagerShims.d.ts +44 -0
- package/dist/runnerUtility/packageManagerShims.d.ts.map +1 -0
- package/dist/runnerUtility/packageManagerShims.js +130 -0
- package/dist/runnerUtility/packageManagerShims.js.map +1 -0
- package/dist/runnerUtility/progress.d.ts +43 -0
- package/dist/runnerUtility/progress.d.ts.map +1 -0
- package/dist/runnerUtility/progress.js +78 -0
- package/dist/runnerUtility/progress.js.map +1 -0
- package/dist/runnerUtility/pueueDaemon.d.ts +8 -4
- package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
- package/dist/runnerUtility/pueueDaemon.js +12 -7
- package/dist/runnerUtility/pueueDaemon.js.map +1 -1
- package/dist/runnerUtility/rootServiceCli.d.ts +23 -3
- package/dist/runnerUtility/rootServiceCli.d.ts.map +1 -1
- package/dist/runnerUtility/rootServiceCli.js +56 -10
- package/dist/runnerUtility/rootServiceCli.js.map +1 -1
- package/dist/runnerUtility/runnerCli.d.ts +1 -0
- package/dist/runnerUtility/runnerCli.d.ts.map +1 -1
- package/dist/runnerUtility/runnerCli.js +14 -7
- package/dist/runnerUtility/runnerCli.js.map +1 -1
- package/dist/runnerUtility/runnerCommands.d.ts +45 -0
- package/dist/runnerUtility/runnerCommands.d.ts.map +1 -1
- package/dist/runnerUtility/runnerCommands.js +188 -21
- package/dist/runnerUtility/runnerCommands.js.map +1 -1
- package/dist/runnerUtility/runnerHome.d.ts +8 -0
- package/dist/runnerUtility/runnerHome.d.ts.map +1 -1
- package/dist/runnerUtility/runnerHome.js +7 -0
- package/dist/runnerUtility/runnerHome.js.map +1 -1
- package/dist/runnerUtility/serviceCommon.d.ts +4 -0
- package/dist/runnerUtility/serviceCommon.d.ts.map +1 -1
- package/dist/runnerUtility/serviceCommon.js +8 -1
- package/dist/runnerUtility/serviceCommon.js.map +1 -1
- package/dist/runnerUtility/serviceManager.d.ts +5 -2
- package/dist/runnerUtility/serviceManager.d.ts.map +1 -1
- package/dist/runnerUtility/serviceManager.js +40 -17
- package/dist/runnerUtility/serviceManager.js.map +1 -1
- package/dist/runnerUtility/serviceUnits.d.ts +11 -0
- package/dist/runnerUtility/serviceUnits.d.ts.map +1 -1
- package/dist/runnerUtility/serviceUnits.js +8 -2
- package/dist/runnerUtility/serviceUnits.js.map +1 -1
- package/dist/runnerUtility/simulatorSilencer.d.ts +55 -0
- package/dist/runnerUtility/simulatorSilencer.d.ts.map +1 -0
- package/dist/runnerUtility/simulatorSilencer.js +203 -0
- package/dist/runnerUtility/simulatorSilencer.js.map +1 -0
- package/dist/runnerUtility/stopSignals.d.ts +10 -0
- package/dist/runnerUtility/stopSignals.d.ts.map +1 -0
- package/dist/runnerUtility/stopSignals.js +27 -0
- package/dist/runnerUtility/stopSignals.js.map +1 -0
- package/dist/runnerUtility/versionPollTiming.d.ts +2 -3
- package/dist/runnerUtility/versionPollTiming.d.ts.map +1 -1
- package/dist/runnerUtility/versionPollTiming.js +4 -18
- package/dist/runnerUtility/versionPollTiming.js.map +1 -1
- package/dist/runners/bootstrapLine.d.ts.map +1 -1
- package/dist/runners/bootstrapLine.js +35 -19
- package/dist/runners/bootstrapLine.js.map +1 -1
- package/dist/runners/gate.d.ts.map +1 -1
- package/dist/runners/gate.js +28 -1
- package/dist/runners/gate.js.map +1 -1
- package/dist/runners/gateLink.d.ts +7 -0
- package/dist/runners/gateLink.d.ts.map +1 -1
- package/dist/runners/gateLink.js +36 -3
- package/dist/runners/gateLink.js.map +1 -1
- package/dist/runners/gateProtocol.d.ts +37 -2
- package/dist/runners/gateProtocol.d.ts.map +1 -1
- package/dist/runners/gateProtocol.js +45 -4
- package/dist/runners/gateProtocol.js.map +1 -1
- package/dist/runners/hubPackage.d.ts +2 -1
- package/dist/runners/hubPackage.d.ts.map +1 -1
- package/dist/runners/hubPackage.js +32 -11
- package/dist/runners/hubPackage.js.map +1 -1
- package/dist/runners/hubPairing.d.ts +1 -1
- package/dist/runners/hubPairing.d.ts.map +1 -1
- package/dist/runners/hubPairing.js +8 -1
- package/dist/runners/hubPairing.js.map +1 -1
- package/dist/runners/hubPaths.d.ts +2 -0
- package/dist/runners/hubPaths.d.ts.map +1 -1
- package/dist/runners/hubPaths.js +1 -1
- package/dist/runners/hubPaths.js.map +1 -1
- package/dist/runners/linkConcern.d.ts +75 -0
- package/dist/runners/linkConcern.d.ts.map +1 -0
- package/dist/runners/linkConcern.js +85 -0
- package/dist/runners/linkConcern.js.map +1 -0
- package/dist/runners/linkControl.d.ts +25 -1
- package/dist/runners/linkControl.d.ts.map +1 -1
- package/dist/runners/linkControl.js +46 -4
- package/dist/runners/linkControl.js.map +1 -1
- package/dist/runners/pairingTiming.d.ts +2 -3
- package/dist/runners/pairingTiming.d.ts.map +1 -1
- package/dist/runners/pairingTiming.js +4 -18
- package/dist/runners/pairingTiming.js.map +1 -1
- package/dist/runners/runnerLock.d.ts +112 -0
- package/dist/runners/runnerLock.d.ts.map +1 -0
- package/dist/runners/runnerLock.js +292 -0
- package/dist/runners/runnerLock.js.map +1 -0
- package/dist/runners/runnersCli.d.ts +6 -3
- package/dist/runners/runnersCli.d.ts.map +1 -1
- package/dist/runners/runnersCli.js +33 -6
- package/dist/runners/runnersCli.js.map +1 -1
- package/dist/runners/runnersList.d.ts +3 -3
- package/dist/runners/runnersList.d.ts.map +1 -1
- package/dist/runners/runnersList.js +9 -2
- package/dist/runners/runnersList.js.map +1 -1
- package/dist/runners/runnersOverview.d.ts +29 -3
- package/dist/runners/runnersOverview.d.ts.map +1 -1
- package/dist/runners/runnersOverview.js +71 -6
- package/dist/runners/runnersOverview.js.map +1 -1
- package/dist/runners/serviceRemoval.d.ts +43 -0
- package/dist/runners/serviceRemoval.d.ts.map +1 -0
- package/dist/runners/serviceRemoval.js +114 -0
- package/dist/runners/serviceRemoval.js.map +1 -0
- 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 +75 -0
- package/dist/scheduler/checkStatus.d.ts.map +1 -0
- package/dist/scheduler/checkStatus.js +117 -0
- package/dist/scheduler/checkStatus.js.map +1 -0
- package/dist/scheduler/delivery.d.ts +106 -38
- package/dist/scheduler/delivery.d.ts.map +1 -1
- package/dist/scheduler/delivery.js +199 -73
- package/dist/scheduler/delivery.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts +8 -2
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +96 -20
- 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 +23 -2
- package/dist/scheduler/store.d.ts.map +1 -1
- package/dist/scheduler/store.js +57 -3
- package/dist/scheduler/store.js.map +1 -1
- package/dist/scheduler/types.d.ts +26 -10
- package/dist/scheduler/types.d.ts.map +1 -1
- package/dist/scheduler/unbindPause.d.ts +27 -0
- package/dist/scheduler/unbindPause.d.ts.map +1 -0
- package/dist/scheduler/unbindPause.js +21 -0
- package/dist/scheduler/unbindPause.js.map +1 -0
- package/dist/scheduler/workerActivity.d.ts +25 -0
- package/dist/scheduler/workerActivity.d.ts.map +1 -0
- package/dist/scheduler/workerActivity.js +195 -0
- package/dist/scheduler/workerActivity.js.map +1 -0
- package/dist/scheduler/workerWatch.d.ts +36 -9
- package/dist/scheduler/workerWatch.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.js +41 -11
- package/dist/scheduler/workerWatch.js.map +1 -1
- package/dist/state.d.ts +8 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +30 -0
- package/dist/state.js.map +1 -1
- package/dist/stt/sttRuntime.d.ts.map +1 -1
- package/dist/stt/sttRuntime.js +8 -1
- package/dist/stt/sttRuntime.js.map +1 -1
- package/dist/stt/sttSettings.d.ts +56 -6
- package/dist/stt/sttSettings.d.ts.map +1 -1
- package/dist/stt/sttSettings.js +128 -7
- package/dist/stt/sttSettings.js.map +1 -1
- package/dist/stt/sttSidecarOwner.d.ts +13 -5
- package/dist/stt/sttSidecarOwner.d.ts.map +1 -1
- package/dist/stt/sttSidecarOwner.js +72 -31
- package/dist/stt/sttSidecarOwner.js.map +1 -1
- package/dist/stt/transcribeChain.d.ts +23 -1
- package/dist/stt/transcribeChain.d.ts.map +1 -1
- package/dist/stt/transcribeChain.js +59 -4
- package/dist/stt/transcribeChain.js.map +1 -1
- package/dist/testTimings.d.ts +4 -2
- package/dist/testTimings.d.ts.map +1 -1
- package/dist/testTimings.js +7 -1
- package/dist/testTimings.js.map +1 -1
- package/dist/testTimingsSeam.d.ts +10 -0
- package/dist/testTimingsSeam.d.ts.map +1 -0
- package/dist/testTimingsSeam.js +29 -0
- package/dist/testTimingsSeam.js.map +1 -0
- package/dist/utils/claudeUsage.d.ts +3 -0
- package/dist/utils/claudeUsage.d.ts.map +1 -1
- package/dist/utils/claudeUsage.js +8 -1
- 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/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/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 +14 -0
- package/dist/utils/runnersScreenPlan.d.ts.map +1 -1
- package/dist/utils/runnersScreenPlan.js +49 -5
- package/dist/utils/runnersScreenPlan.js.map +1 -1
- 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/surrogateSafeCut.d.ts +14 -0
- package/dist/utils/surrogateSafeCut.d.ts.map +1 -0
- package/dist/utils/surrogateSafeCut.js +30 -0
- package/dist/utils/surrogateSafeCut.js.map +1 -0
- package/dist/utils/telegramError.d.ts +13 -0
- package/dist/utils/telegramError.d.ts.map +1 -1
- package/dist/utils/telegramError.js +45 -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/transientFrames.d.ts +51 -6
- package/dist/utils/transientFrames.d.ts.map +1 -1
- package/dist/utils/transientFrames.js +52 -2
- package/dist/utils/transientFrames.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/dist/voiceProgressNote.d.ts +73 -0
- package/dist/voiceProgressNote.d.ts.map +1 -0
- package/dist/voiceProgressNote.js +142 -0
- package/dist/voiceProgressNote.js.map +1 -0
- package/package.json +4 -1
- package/remoteRun/pickNode.sh +65 -0
- package/remoteRun/runner-package-lock.json +59 -0
- package/remoteRun/runner.sh +304 -6
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");
|
|
@@ -170,6 +172,7 @@ const topicView_1 = require("./utils/topicView");
|
|
|
170
172
|
const topicRequest_1 = require("./utils/topicRequest");
|
|
171
173
|
const serialQueue_1 = require("./utils/serialQueue");
|
|
172
174
|
const voiceQueue_1 = require("./voiceQueue");
|
|
175
|
+
const voiceProgressNote_1 = require("./voiceProgressNote");
|
|
173
176
|
const claudeLivenessAction_1 = require("./utils/claudeLivenessAction");
|
|
174
177
|
const isoTimestamp_1 = require("./utils/isoTimestamp");
|
|
175
178
|
const effortLevels_1 = require("./effortLevels");
|
|
@@ -186,7 +189,7 @@ const updatePolicy_1 = require("./selfUpdate/updatePolicy");
|
|
|
186
189
|
const updateRuntime_1 = require("./selfUpdate/updateRuntime");
|
|
187
190
|
const threadContextPreamble_1 = require("./threadContextPreamble");
|
|
188
191
|
const pinnedBannerSkipDecision_1 = require("./utils/pinnedBannerSkipDecision");
|
|
189
|
-
const
|
|
192
|
+
const messageContext_1 = require("./utils/messageContext");
|
|
190
193
|
const fileIntake_1 = require("./connectors/telegram/fileIntake");
|
|
191
194
|
const mediaGroupCollector_1 = require("./utils/mediaGroupCollector");
|
|
192
195
|
const openCodeSessionTitle_1 = require("./openCodeSessionTitle");
|
|
@@ -195,6 +198,8 @@ const jsonStreamHost_1 = require("./utils/jsonStreamHost");
|
|
|
195
198
|
const runLedger_1 = require("./scheduler/runLedger");
|
|
196
199
|
const delivery_1 = require("./scheduler/delivery");
|
|
197
200
|
const checkRun_1 = require("./scheduler/checkRun");
|
|
201
|
+
const checkStatus_1 = require("./scheduler/checkStatus");
|
|
202
|
+
const workerActivity_1 = require("./scheduler/workerActivity");
|
|
198
203
|
const engine_1 = require("./scheduler/engine");
|
|
199
204
|
const recurrence_1 = require("./scheduler/recurrence");
|
|
200
205
|
const mcpSurface_1 = require("./scheduler/mcpSurface");
|
|
@@ -221,7 +226,8 @@ const wakeUpRules_1 = require("./requests/wakeUpRules");
|
|
|
221
226
|
const requestHeader_1 = require("./requests/requestHeader");
|
|
222
227
|
const directoryThreads_1 = require("./scheduler/directoryThreads");
|
|
223
228
|
const rebindResume_1 = require("./scheduler/rebindResume");
|
|
224
|
-
const
|
|
229
|
+
const store_2 = require("./scheduler/store");
|
|
230
|
+
const unbindPause_1 = require("./scheduler/unbindPause");
|
|
225
231
|
const apiErrorRetry_1 = require("./apiErrorRetry");
|
|
226
232
|
const wedgeRecovery_1 = require("./utils/wedgeRecovery");
|
|
227
233
|
const claudeAuthLogin_1 = require("./utils/claudeAuthLogin");
|
|
@@ -846,22 +852,25 @@ const noTopicRequest = { header: '', requestId: null };
|
|
|
846
852
|
* the topic's view has requests on and the text is not a slash command. Called
|
|
847
853
|
* at the USER entry points — text, voice, file, album, `/schedule`, the
|
|
848
854
|
* scheduler's forward — BEFORE the prompt is forwarded or buffered: the ledger
|
|
849
|
-
* keeps the header + text as the request's prompt
|
|
850
|
-
* never took it in), and `createRequest` resolves only once the id is on disk. A
|
|
855
|
+
* keeps the header + text as the request's prompt, with the message context (reply
|
|
856
|
+
* 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
|
|
851
857
|
* conversation of another platform opens its requests itself (Jira: J5). A
|
|
852
858
|
* `null` intake is a prompt that is not a request by rule — an answer to the
|
|
853
859
|
* agent's own question, delivered as a prompt. The intake's requester decides
|
|
854
860
|
* which open request, if any, the new one supersedes (`requestGroup.ts`); the
|
|
855
861
|
* header then names the replaced ones.
|
|
856
862
|
*/
|
|
857
|
-
async function openTopicRequest(key, text, intake) {
|
|
863
|
+
async function openTopicRequest(key, text, intake, messageContext) {
|
|
858
864
|
if (intake === null || !topicRequestLedger || !(0, sessionKeyCodec_1.checkIsTelegramKey)(key))
|
|
859
865
|
return noTopicRequest;
|
|
860
866
|
const view = state.getDisplayPrefs(key).view;
|
|
861
|
-
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0,
|
|
867
|
+
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0, messageContext_1.checkIsSlashCommandPrompt)(text, messageContext)))
|
|
862
868
|
return noTopicRequest;
|
|
869
|
+
// The ledger keeps the prompt as it is posted — the message context folded in — because a stored prompt is what is posted
|
|
870
|
+
// AGAIN when the session never took it in; the raw text would come back without the forwarded mark or the quote.
|
|
871
|
+
const promptBody = getPromptWithThreadMessageContext(key, text, messageContext);
|
|
863
872
|
const request = await topicRequestLedger.createRequest(key, (0, topicRequest_1.getTopicRequestOrigin)(intake), {
|
|
864
|
-
createPrompt: (requestId, supersededRequestIds) =>
|
|
873
|
+
createPrompt: (requestId, supersededRequestIds) => (0, topicRequest_1.buildTopicRequestPrompt)({ requestId, source: intake.source, view, supersededRequestIds, promptBody }),
|
|
865
874
|
});
|
|
866
875
|
return { header: (0, topicRequest_1.buildTopicRequestHeader)(request.id, intake.source, view, request.supersededRequestIds), requestId: request.id };
|
|
867
876
|
}
|
|
@@ -2334,19 +2343,19 @@ function getThreadMessageState(key) {
|
|
|
2334
2343
|
const k = (0, sessionKey_1.keyToString)(key);
|
|
2335
2344
|
let s = threadMessageStates.get(k);
|
|
2336
2345
|
if (!s) {
|
|
2337
|
-
s = { lastMessageId: null, lastMessageText: null, needsNewMessage: true, typingLoaderTimer: null, statusMessageId: null, thinkingMessageId: null, thinkingFrameGeneration: 0, statusFrameGeneration: 0, livenessTimer: null, lastActivityText: null, livenessGlyphIndex: 0, wasBusy: false, workingSince: null, lastLivenessSentAt: 0, statusIdleSuppressed: false, busyOnsetArmedUntil: 0, subagentStatusMessageId: null, subagentStartedAt: null, subagentTitle: null, subagentTimer: null, lastSubagentText: null, subagentEditInFlight: false };
|
|
2346
|
+
s = { lastMessageId: null, lastMessageText: null, needsNewMessage: true, typingLoaderTimer: null, statusMessageId: null, thinkingMessageId: null, thinkingFrameGeneration: 0, statusFrameGeneration: 0, livenessTimer: null, lastActivityText: null, livenessGlyphIndex: 0, wasBusy: false, workingSince: null, lastLivenessSentAt: 0, statusIdleSuppressed: false, busyOnsetArmedUntil: 0, subagentStatusMessageId: null, subagentStartedAt: null, subagentTitle: null, subagentTimer: null, lastSubagentText: null, subagentEditInFlight: false, voiceProgressNoteIds: [], undeletedMessageIds: [] };
|
|
2338
2347
|
threadMessageStates.set(k, s);
|
|
2339
2348
|
}
|
|
2340
2349
|
return s;
|
|
2341
2350
|
}
|
|
2342
2351
|
/**
|
|
2343
|
-
* @description Persist the thread's CURRENT transient
|
|
2344
|
-
* non-null `statusMessageId` / `thinkingMessageId` / `subagentStatusMessageId`
|
|
2345
|
-
* so an UNGRACEFUL restart (crash / SIGKILL — no graceful sweep ran) can delete
|
|
2352
|
+
* @description Persist the thread's CURRENT transient message ids (the
|
|
2353
|
+
* non-null `statusMessageId` / `thinkingMessageId` / `subagentStatusMessageId`
|
|
2354
|
+
* and the `voiceProgressNoteIds` and `undeletedMessageIds`) so an UNGRACEFUL restart (crash / SIGKILL — no graceful sweep ran) can delete
|
|
2346
2355
|
* whatever frame was on screen on the next boot (S2). The in-memory
|
|
2347
2356
|
* `ThreadMessageState` is the live source of truth; this just keeps disk in step.
|
|
2348
|
-
* Debounced + fire-and-forget. Single collection point shared by the
|
|
2349
|
-
*
|
|
2357
|
+
* Debounced + fire-and-forget. Single collection point shared by the frame-id
|
|
2358
|
+
* setters below so memory and disk never drift.
|
|
2350
2359
|
*/
|
|
2351
2360
|
function persistTransientFrames(key) {
|
|
2352
2361
|
const ids = (0, transientFrames_1.getTransientFrameIds)(getThreadMessageState(key));
|
|
@@ -2371,6 +2380,21 @@ function setSubagentFrameId(key, id) {
|
|
|
2371
2380
|
getThreadMessageState(key).subagentStatusMessageId = id;
|
|
2372
2381
|
persistTransientFrames(key);
|
|
2373
2382
|
}
|
|
2383
|
+
/** The voice notes' list is edited by value: a thread can have several, each owned by its own voice message. */
|
|
2384
|
+
function addVoiceProgressNoteId(key, id) {
|
|
2385
|
+
getThreadMessageState(key).voiceProgressNoteIds.push(id);
|
|
2386
|
+
persistTransientFrames(key);
|
|
2387
|
+
}
|
|
2388
|
+
function removeVoiceProgressNoteId(key, id) {
|
|
2389
|
+
const noteState = getThreadMessageState(key);
|
|
2390
|
+
noteState.voiceProgressNoteIds = noteState.voiceProgressNoteIds.filter((noteId) => noteId !== id);
|
|
2391
|
+
persistTransientFrames(key);
|
|
2392
|
+
}
|
|
2393
|
+
/** The leftovers still to delete (see {@link ThreadMessageState.undeletedMessageIds}): replaced as a whole, then mirrored to disk. */
|
|
2394
|
+
function setUndeletedMessageIds(key, ids) {
|
|
2395
|
+
getThreadMessageState(key).undeletedMessageIds = ids;
|
|
2396
|
+
persistTransientFrames(key);
|
|
2397
|
+
}
|
|
2374
2398
|
function getOutputQueueState(key) {
|
|
2375
2399
|
const k = (0, sessionKey_1.keyToString)(key);
|
|
2376
2400
|
let s = outputQueues.get(k);
|
|
@@ -2411,7 +2435,7 @@ function getThinkingCoalesceState(key) {
|
|
|
2411
2435
|
const k = (0, sessionKey_1.keyToString)(key);
|
|
2412
2436
|
let s = thinkingCoalescers.get(k);
|
|
2413
2437
|
if (!s) {
|
|
2414
|
-
s = {
|
|
2438
|
+
s = { pending: null, inFlight: false, lastSentHtml: null, detachAfterDrain: false };
|
|
2415
2439
|
thinkingCoalescers.set(k, s);
|
|
2416
2440
|
}
|
|
2417
2441
|
return s;
|
|
@@ -2428,7 +2452,7 @@ function clearThinkingMessage(key) {
|
|
|
2428
2452
|
const s = getThreadMessageState(key);
|
|
2429
2453
|
const coalescer = thinkingCoalescers.get((0, sessionKey_1.keyToString)(key));
|
|
2430
2454
|
if (coalescer) {
|
|
2431
|
-
coalescer.
|
|
2455
|
+
coalescer.pending = null;
|
|
2432
2456
|
coalescer.lastSentHtml = null;
|
|
2433
2457
|
coalescer.detachAfterDrain = false;
|
|
2434
2458
|
}
|
|
@@ -2824,6 +2848,10 @@ async function pinMessageQuiet(key, messageId, options) {
|
|
|
2824
2848
|
return false;
|
|
2825
2849
|
}
|
|
2826
2850
|
}
|
|
2851
|
+
/** @description One unpin call through the rate-limit queue; rejects with Telegram's error. */
|
|
2852
|
+
async function sendUnpin(key, messageId) {
|
|
2853
|
+
await (0, rateLimiter_1.enqueueSend)(key, () => bot.telegram.unpinChatMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId));
|
|
2854
|
+
}
|
|
2827
2855
|
/**
|
|
2828
2856
|
* @description Unpin `messageId` for `key` through the rate-limit queue,
|
|
2829
2857
|
* swallowing + logging failures (already-unpinned / deleted / lost permission).
|
|
@@ -2833,7 +2861,7 @@ async function unpinMessageQuiet(key, messageId) {
|
|
|
2833
2861
|
if (!checkIsTelegramPrimitiveKey(key, 'unpinMessage'))
|
|
2834
2862
|
return;
|
|
2835
2863
|
try {
|
|
2836
|
-
await (
|
|
2864
|
+
await sendUnpin(key, messageId);
|
|
2837
2865
|
}
|
|
2838
2866
|
catch (e) {
|
|
2839
2867
|
console.warn(`[question-pin] unpin ${(0, sessionKey_1.keyToString)(key)} msg ${messageId} failed: ${describeSendError(e)}`);
|
|
@@ -3136,9 +3164,9 @@ function buildSendExtra(key, extra) {
|
|
|
3136
3164
|
async function replyToThread(key, text, extra = {}, options = {}) {
|
|
3137
3165
|
if (!checkIsTelegramPrimitiveKey(key, 'replyToThread'))
|
|
3138
3166
|
return null;
|
|
3139
|
-
const sendOnce = (sendExtra) => {
|
|
3140
|
-
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key),
|
|
3141
|
-
return options.unpaced ? (0, rateLimiter_1.sendUnpaced)(key, send) : (0, rateLimiter_1.enqueueSend)(key, send);
|
|
3167
|
+
const sendOnce = (sendExtra, sentText = text) => {
|
|
3168
|
+
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), sentText, sendExtra);
|
|
3169
|
+
return options.unpaced ? (0, rateLimiter_1.sendUnpaced)(key, send, options.signal) : (0, rateLimiter_1.enqueueSend)(key, send, options.signal);
|
|
3142
3170
|
};
|
|
3143
3171
|
// A sent message is tracked for `/clear_messages`, and a `/bind` picker is remembered to be closed by the next bind or leave.
|
|
3144
3172
|
const trackSent = async (sent) => {
|
|
@@ -3148,11 +3176,14 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3148
3176
|
openBindMessages.remember((0, sessionKey_1.keyToString)(key), messageId, Date.now());
|
|
3149
3177
|
return messageId;
|
|
3150
3178
|
};
|
|
3151
|
-
|
|
3179
|
+
// 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.
|
|
3180
|
+
const releaseSecret = options.isSecret ? (0, outputTrace_1.markOutboundTextsSecret)([text, options.plainFallbackText]) : null;
|
|
3152
3181
|
try {
|
|
3153
3182
|
return await trackSent(await sendOnce(buildSendExtra(key, extra)));
|
|
3154
3183
|
}
|
|
3155
3184
|
catch (e) {
|
|
3185
|
+
if (options.signal?.aborted && (0, utils_1.checkIsAbortError)(e))
|
|
3186
|
+
return null;
|
|
3156
3187
|
// Markdown parse failure fallback. Several `t(...)` templates interpolate
|
|
3157
3188
|
// user-controlled content (subdir names, branch names, error strings)
|
|
3158
3189
|
// into Markdown body — a backtick or stray `*` inside the content
|
|
@@ -3168,7 +3199,7 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3168
3199
|
const plainExtra = { ...extra };
|
|
3169
3200
|
delete plainExtra.parse_mode;
|
|
3170
3201
|
try {
|
|
3171
|
-
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra)));
|
|
3202
|
+
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra), options.plainFallbackText ?? text));
|
|
3172
3203
|
}
|
|
3173
3204
|
catch (e2) {
|
|
3174
3205
|
await handleSendError(key, e2);
|
|
@@ -3199,20 +3230,27 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3199
3230
|
* rendering passes it.
|
|
3200
3231
|
*/
|
|
3201
3232
|
async function editThreadMessage(key, messageId, text, extra = {}, plainFallbackText = text) {
|
|
3233
|
+
return (await editThreadMessageDetailed(key, messageId, text, extra, plainFallbackText)) === 'edited';
|
|
3234
|
+
}
|
|
3235
|
+
/**
|
|
3236
|
+
* @description {@link editThreadMessage} telling a message that is not there (deleted by hand: «message to edit not found») from any
|
|
3237
|
+
* other failure — see {@link ThreadMessageEdit}. The failure is logged either way, as before.
|
|
3238
|
+
*/
|
|
3239
|
+
async function editThreadMessageDetailed(key, messageId, text, extra = {}, plainFallbackText = text) {
|
|
3202
3240
|
if (!checkIsTelegramPrimitiveKey(key, 'editThreadMessage'))
|
|
3203
|
-
return
|
|
3241
|
+
return 'failed';
|
|
3204
3242
|
const editOnce = (editText, editExtra) => (0, rateLimiter_1.enqueueSend)(key, () => bot.telegram.editMessageText((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId, undefined, editText, editExtra));
|
|
3205
3243
|
try {
|
|
3206
3244
|
await editOnce(text, extra);
|
|
3207
|
-
return
|
|
3245
|
+
return 'edited';
|
|
3208
3246
|
}
|
|
3209
3247
|
catch (e) {
|
|
3210
3248
|
const desc = (0, sendErrorClassifier_1.checkIsApiError)(e) ? (0, sendErrorClassifier_1.getErrorDescription)(e) : '';
|
|
3211
3249
|
if (/message is not modified/i.test(desc))
|
|
3212
|
-
return
|
|
3250
|
+
return 'edited'; // benign
|
|
3213
3251
|
if (/thread not found|TOPIC_CLOSED|topic is closed/i.test(desc)) {
|
|
3214
3252
|
await handleSendError(key, e);
|
|
3215
|
-
return
|
|
3253
|
+
return 'failed';
|
|
3216
3254
|
}
|
|
3217
3255
|
// Symmetric markdown-parse-fail fallback to `replyToThread`. See the
|
|
3218
3256
|
// long comment there — same rationale: prefer a plain-text edit over
|
|
@@ -3224,18 +3262,18 @@ async function editThreadMessage(key, messageId, text, extra = {}, plainFallback
|
|
|
3224
3262
|
delete plainExtra.parse_mode;
|
|
3225
3263
|
try {
|
|
3226
3264
|
await editOnce(plainFallbackText, plainExtra);
|
|
3227
|
-
return
|
|
3265
|
+
return 'edited';
|
|
3228
3266
|
}
|
|
3229
3267
|
catch (e2) {
|
|
3230
3268
|
const desc2 = (0, sendErrorClassifier_1.checkIsApiError)(e2) ? (0, sendErrorClassifier_1.getErrorDescription)(e2) : '';
|
|
3231
3269
|
if (/message is not modified/i.test(desc2))
|
|
3232
|
-
return
|
|
3270
|
+
return 'edited';
|
|
3233
3271
|
console.error(`[edit] ${(0, sessionKey_1.keyToString)(key)}#${messageId} retry failed:`, desc2 || e2);
|
|
3234
|
-
return
|
|
3272
|
+
return (0, telegramError_1.checkIsMessageNotFoundError)(e2) ? 'gone' : 'failed';
|
|
3235
3273
|
}
|
|
3236
3274
|
}
|
|
3237
3275
|
console.error(`[edit] ${(0, sessionKey_1.keyToString)(key)}#${messageId}:`, desc || e);
|
|
3238
|
-
return
|
|
3276
|
+
return (0, telegramError_1.checkIsMessageNotFoundError)(e) ? 'gone' : 'failed';
|
|
3239
3277
|
}
|
|
3240
3278
|
}
|
|
3241
3279
|
/**
|
|
@@ -3258,11 +3296,17 @@ async function editThreadKeyboard(key, messageId, keyboard, logTag) {
|
|
|
3258
3296
|
return false;
|
|
3259
3297
|
}
|
|
3260
3298
|
}
|
|
3261
|
-
|
|
3299
|
+
/**
|
|
3300
|
+
* @description {@link deleteThreadMessage} telling a message that was already gone from one that stayed — see {@link ThreadMessageDeletion}. None of them is logged: all are expected.
|
|
3301
|
+
* `isUnpaced` sends the delete outside the global pacer, for a message whose disappearance is part of an answer that is already
|
|
3302
|
+
* on screen (the «transcribing…» note, which must not outlive the 🎤 echo behind queued agent output).
|
|
3303
|
+
*/
|
|
3304
|
+
async function deleteThreadMessageDetailed(key, messageId, options = {}) {
|
|
3262
3305
|
if (!checkIsTelegramPrimitiveKey(key, 'deleteThreadMessage'))
|
|
3263
3306
|
return 'stayed';
|
|
3264
3307
|
try {
|
|
3265
|
-
|
|
3308
|
+
const deleteMessage = () => bot.telegram.deleteMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId);
|
|
3309
|
+
await (options.isUnpaced ? (0, rateLimiter_1.sendUnpaced)(key, deleteMessage) : (0, rateLimiter_1.enqueueSend)(key, deleteMessage));
|
|
3266
3310
|
return 'deleted';
|
|
3267
3311
|
}
|
|
3268
3312
|
catch (e) {
|
|
@@ -3676,7 +3720,7 @@ async function sendOutputImmediate(key, output, isContinuation = false, startsNe
|
|
|
3676
3720
|
let startIndex = 0;
|
|
3677
3721
|
if (shouldEditFirstChunk) {
|
|
3678
3722
|
const editedOk = chunks[0] === msgState.lastMessageText ||
|
|
3679
|
-
(await editThreadMessage(key, msgState.lastMessageId, (0, renderAgentHtml_1.renderAgentHtml)(chunks[0]), { parse_mode: 'HTML' }));
|
|
3723
|
+
(await editThreadMessage(key, msgState.lastMessageId, (0, renderAgentHtml_1.renderAgentHtml)(chunks[0]), { parse_mode: 'HTML' }, chunks[0]));
|
|
3680
3724
|
if (editedOk) {
|
|
3681
3725
|
msgState.lastMessageText = chunks[0];
|
|
3682
3726
|
startIndex = 1;
|
|
@@ -3713,7 +3757,8 @@ async function replyChunkWithFallback(key, renderedHtml, plainFallback, replyMar
|
|
|
3713
3757
|
if (!checkIsTelegramPrimitiveKey(key, 'replyChunkWithFallback'))
|
|
3714
3758
|
return null;
|
|
3715
3759
|
const markupExtra = replyMarkup ? { reply_markup: replyMarkup } : {};
|
|
3716
|
-
|
|
3760
|
+
// Telegram refusing the markup is answered INSIDE replyToThread, with the plain twin — without it the retry would show the tags.
|
|
3761
|
+
const id = await replyToThread(key, renderedHtml, { parse_mode: 'HTML', ...markupExtra }, { plainFallbackText: plainFallback });
|
|
3717
3762
|
if (id)
|
|
3718
3763
|
return id;
|
|
3719
3764
|
return replyToThread(key, plainFallback, markupExtra);
|
|
@@ -3772,7 +3817,7 @@ const shutdownFrameSweepMs = 1500;
|
|
|
3772
3817
|
* them up orphans the messages forever in the topic (the reported incident:
|
|
3773
3818
|
* ~25 hot reloads left "✽ работаю…" frames stuck; and a 🔧 tool status stranded
|
|
3774
3819
|
* as a topic's last message when a hot reload landed mid-tool). Iterates every
|
|
3775
|
-
* tracked thread, and for each
|
|
3820
|
+
* tracked thread, and for each `clearTransientFramesForShutdown` (inside `sweepTransientMessages`) BUMPS both
|
|
3776
3821
|
* frame generations (so a `sendStatusFrame`/thinking create still mid-`await`
|
|
3777
3822
|
* discards its just-sent message instead of orphaning it — see that helper) and
|
|
3778
3823
|
* nulls the in-memory ids so a racing per-thread tick can't re-edit a just-deleted
|
|
@@ -3784,43 +3829,52 @@ const shutdownFrameSweepMs = 1500;
|
|
|
3784
3829
|
* an orphan after the sweep. Threads that had nothing on screen still skip the
|
|
3785
3830
|
* (fire-and-forget) persist + delete work.
|
|
3786
3831
|
*
|
|
3832
|
+
* A delete that fails for a reason a later try can fix (no answer from Telegram, a
|
|
3833
|
+
* 429, a 5xx) no longer forgets the message: the collected ids are PARKED in the
|
|
3834
|
+
* thread's in-memory `undeletedMessageIds` (the clear does that), the deletes run, and
|
|
3835
|
+
* the list is replaced by the ones to try again through `setUndeletedMessageIds` — the
|
|
3836
|
+
* same save every other writer of the persisted set uses, so a late frame setter or
|
|
3837
|
+
* note removal that persists the thread meanwhile still carries them, and so does a
|
|
3838
|
+
* sweep cut short by its bound. The next boot's {@link reconcileTransientFrames}
|
|
3839
|
+
* tries again. Final answers (already gone, too old, refused) settle an id.
|
|
3840
|
+
*
|
|
3787
3841
|
* Wired into {@link gracefulShutdown} as `clearTransientFrames`: runs AFTER
|
|
3788
3842
|
* `cleanupTimers()` (no interval re-creates a frame mid-sweep) and BEFORE
|
|
3789
3843
|
* `bot.stop()` (the Telegram client must still send the deletes). Self-bounded by
|
|
3790
3844
|
* {@link shutdownFrameSweepMs} — a slow API must not starve `state.flush()`.
|
|
3791
3845
|
*/
|
|
3792
3846
|
async function sweepTransientFramesOnShutdown() {
|
|
3793
|
-
|
|
3847
|
+
// The voice notes first: their timers and sends in flight are stopped and cleaned (bounded), so nothing can register an id
|
|
3848
|
+
// behind the sweep. `cleanupTimers` already started this; the sweep waits for it.
|
|
3849
|
+
await voiceProgressNotes.shutDown();
|
|
3850
|
+
const threads = [];
|
|
3794
3851
|
for (const [keyStr, msgState] of threadMessageStates) {
|
|
3795
|
-
let key;
|
|
3796
3852
|
try {
|
|
3797
|
-
key
|
|
3853
|
+
threads.push({ key: (0, sessionKey_1.keyFromString)(keyStr), state: msgState });
|
|
3798
3854
|
}
|
|
3799
3855
|
catch {
|
|
3800
3856
|
continue;
|
|
3801
3857
|
}
|
|
3802
|
-
// Bump generations + null ids for EVERY tracked thread (fixes the racing
|
|
3803
|
-
// create that resolves after the sweep). Only threads that HAD a frame on
|
|
3804
|
-
// screen need the persist + delete.
|
|
3805
|
-
const ids = (0, transientFrames_1.clearTransientFramesForShutdown)(msgState);
|
|
3806
|
-
if (ids.length === 0)
|
|
3807
|
-
continue;
|
|
3808
|
-
for (const id of ids) {
|
|
3809
|
-
deletes.push(bot.telegram.deleteMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), id).catch(() => { }));
|
|
3810
|
-
}
|
|
3811
|
-
// Clear the S2 persisted set too, so the next boot's reconciliation finds
|
|
3812
|
-
// nothing to redo after a graceful exit.
|
|
3813
|
-
state.setTransientFrames(key, []).catch(() => { });
|
|
3814
3858
|
}
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3859
|
+
const sweeping = (0, transientFrames_1.sweepTransientMessages)(threads, {
|
|
3860
|
+
deleteMessage: async (key, messageId) => { await bot.telegram.deleteMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId); },
|
|
3861
|
+
checkIsRetryable: telegramError_1.checkIsRetryableTelegramError,
|
|
3862
|
+
saveKeptIds: setUndeletedMessageIds,
|
|
3863
|
+
logProblem: (line) => console.warn(line),
|
|
3864
|
+
});
|
|
3865
|
+
let boundTimer;
|
|
3866
|
+
try {
|
|
3867
|
+
await Promise.race([
|
|
3868
|
+
sweeping,
|
|
3869
|
+
new Promise((resolve) => {
|
|
3870
|
+
boundTimer = setTimeout(resolve, shutdownFrameSweepMs);
|
|
3871
|
+
boundTimer.unref?.();
|
|
3872
|
+
}),
|
|
3873
|
+
]);
|
|
3874
|
+
}
|
|
3875
|
+
finally {
|
|
3876
|
+
clearTimeout(boundTimer);
|
|
3877
|
+
}
|
|
3824
3878
|
}
|
|
3825
3879
|
/**
|
|
3826
3880
|
* Hard bound (ms) on the whole shutdown output flush (finalize + FIFO drain):
|
|
@@ -3974,7 +4028,7 @@ async function bootSttLocalEngine() {
|
|
|
3974
4028
|
* precedes: queued behind agent output it could land after the retry already
|
|
3975
4029
|
* succeeded.
|
|
3976
4030
|
*/
|
|
3977
|
-
async function transcribeVoiceFile(key, filePath, durationSeconds) {
|
|
4031
|
+
async function transcribeVoiceFile(key, filePath, durationSeconds, warmedEndpoint) {
|
|
3978
4032
|
const { engines, settings } = getResolvedSttSettings();
|
|
3979
4033
|
if (engines.length === 0)
|
|
3980
4034
|
return { ok: false, error: 'no speech engine available' };
|
|
@@ -3982,6 +4036,7 @@ async function transcribeVoiceFile(key, filePath, durationSeconds) {
|
|
|
3982
4036
|
const result = await (0, transcribeChain_1.transcribeWithEngines)(filePath, engines, {
|
|
3983
4037
|
durationSeconds,
|
|
3984
4038
|
language: settings.language,
|
|
4039
|
+
warmedEndpoint,
|
|
3985
4040
|
onFallback: ({ from, to, error }) => {
|
|
3986
4041
|
console.warn(`[transcribe] ${from} failed (${error}); falling back to ${to}`);
|
|
3987
4042
|
},
|
|
@@ -3999,6 +4054,33 @@ async function transcribeVoiceFile(key, filePath, durationSeconds) {
|
|
|
3999
4054
|
}
|
|
4000
4055
|
return result;
|
|
4001
4056
|
}
|
|
4057
|
+
/**
|
|
4058
|
+
* The notes armed right now: a shutdown stops them (`cleanupTimers` and the sweep), so a timer that fires or a send that lands
|
|
4059
|
+
* after the sweep cannot strand a message past the last state flush.
|
|
4060
|
+
*/
|
|
4061
|
+
const voiceProgressNotes = (0, voiceProgressNote_1.createVoiceProgressNoteRegistry)();
|
|
4062
|
+
/**
|
|
4063
|
+
* @description Arm the «🎙 Transcribing the voice message…» note for a voice message that just arrived in `key`. While the
|
|
4064
|
+
* local engine loads (up to 2 minutes, `src/stt/README.md`) the topic would show nothing and the voice would look lost; the note
|
|
4065
|
+
* appears only when the text is later than `voiceProgressNoteDelayMs`, is SILENT (a muted topic stays quiet, an unmuted one makes
|
|
4066
|
+
* no sound), goes out UNPACED like the 🎤 echo it makes way for, and is deleted unpaced the moment the text arrives or the
|
|
4067
|
+
* transcription fails (`VoiceProgressNote.finish`, which the voice job AWAITS before it answers — bounded, so a stalled delete
|
|
4068
|
+
* cannot hold the transcript back). Its id is kept in the thread's transient-message set, so a restart that kills the voice job
|
|
4069
|
+
* still deletes the note: the graceful sweep, or the next boot after a crash.
|
|
4070
|
+
*/
|
|
4071
|
+
function startVoiceProgressNote(key) {
|
|
4072
|
+
return voiceProgressNotes.start({
|
|
4073
|
+
postNote: (signal) => replyToThread(key, withThreadLocale(key, () => (0, i18n_1.t)('voice.transcribing')), { disable_notification: true }, { unpaced: true, signal }),
|
|
4074
|
+
rememberNote: (messageId) => addVoiceProgressNoteId(key, messageId),
|
|
4075
|
+
deleteNote: async (messageId) => {
|
|
4076
|
+
const deletion = await deleteThreadMessageDetailed(key, messageId, { isUnpaced: true });
|
|
4077
|
+
// A note that stayed keeps its place in the set: the next sweep or boot retries it.
|
|
4078
|
+
if (deletion !== 'stayed')
|
|
4079
|
+
removeVoiceProgressNoteId(key, messageId);
|
|
4080
|
+
},
|
|
4081
|
+
logProblem: (line) => console.warn(line),
|
|
4082
|
+
});
|
|
4083
|
+
}
|
|
4002
4084
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
4003
4085
|
// Adapter lifecycle helpers
|
|
4004
4086
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -4785,7 +4867,7 @@ async function forwardPromptToAgent(key, adapter, text, sentAtMs, options = {})
|
|
|
4785
4867
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
4786
4868
|
checkIsSessionActive: () => adapter.checkIsActive(key) && !(isTechnicalPrompt && (adapter.checkIsBusy?.(key) ?? false)),
|
|
4787
4869
|
buffer: async () => {
|
|
4788
|
-
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${
|
|
4870
|
+
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${getPromptWithThreadMessageContext(key, text, options.messageContext)}`, true);
|
|
4789
4871
|
},
|
|
4790
4872
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
4791
4873
|
forward: async () => {
|
|
@@ -4807,11 +4889,14 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4807
4889
|
// A forwarded prompt is thread activity — reset the compact-on-idle watchdog (F2).
|
|
4808
4890
|
noteThreadActivity(key);
|
|
4809
4891
|
const isTechnicalPrompt = options.isTechnicalPrompt ?? false;
|
|
4892
|
+
// A slash command typed by the operator is a control token; the same words FORWARDED from elsewhere are
|
|
4893
|
+
// content (the mark ahead of them says so) and are decorated and replayed like any prompt.
|
|
4894
|
+
const isSlashCommand = (0, messageContext_1.checkIsSlashCommandPrompt)(text, options.messageContext);
|
|
4810
4895
|
// Skip slash commands (not worth replaying), the recovery replay itself (keeps
|
|
4811
4896
|
// the once-per-episode guard intact), a request reminder (the request's own
|
|
4812
4897
|
// prompt stays the one to replay) and a bot-made technical prompt.
|
|
4813
4898
|
const isReplayable = (0, wedgeRecovery_1.checkIsReplayablePrompt)({
|
|
4814
|
-
isSlashCommand
|
|
4899
|
+
isSlashCommand,
|
|
4815
4900
|
isRecoveryReplay: options.isRecoveryReplay ?? false,
|
|
4816
4901
|
isRequestReminder: options.isRequestReminder ?? false,
|
|
4817
4902
|
isTechnicalPrompt,
|
|
@@ -4820,19 +4905,21 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4820
4905
|
// forwarded to a live session once no wait holds them — after it, in arrival
|
|
4821
4906
|
// order (the resume's, the operator's message that ended the wait, a later
|
|
4822
4907
|
// post). Only a replayable one carries them, so a wedge recovery replays them too.
|
|
4823
|
-
|
|
4824
|
-
//
|
|
4825
|
-
//
|
|
4826
|
-
//
|
|
4827
|
-
//
|
|
4828
|
-
//
|
|
4829
|
-
//
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4908
|
+
// Fold the message-context block (the reply quote of a Telegram REPLY, the mark of a
|
|
4909
|
+
// FORWARD) ahead of the user's text so the agent sees WHAT is being referenced and
|
|
4910
|
+
// WHOSE words these are — only for a normal prompt, since a slash command forwarded to
|
|
4911
|
+
// the agent is a control token a prefixed block would corrupt, and a terminal's input
|
|
4912
|
+
// is a shell line the block's `> ` lines would turn into file-overwriting redirections.
|
|
4913
|
+
// The held prompts come AFTER the folded text, under a header line of their own: the
|
|
4914
|
+
// block describes the message's own words, and a held scheduled run must not read as
|
|
4915
|
+
// part of a forwarded message. The folded `body` is what gets cached,
|
|
4916
|
+
// preamble-wrapped and timestamped below.
|
|
4917
|
+
const ownBody = (0, messageContext_1.getPromptWithMessageContext)(text, {
|
|
4918
|
+
context: options.messageContext,
|
|
4833
4919
|
isShellInput: adapter.name === 'terminal',
|
|
4834
4920
|
});
|
|
4835
|
-
|
|
4921
|
+
const quotedBody = isReplayable && adapter.checkIsActive(key) ? limitHeldPrompts.releaseWithForward(key, ownBody) : ownBody;
|
|
4922
|
+
// The request header (S7) leads the per-message body, like the message context and
|
|
4836
4923
|
// unlike the once-per-change thread preamble: it names THIS message's request.
|
|
4837
4924
|
const messageBody = options.requestHeader ? `${options.requestHeader}${quotedBody}` : quotedBody;
|
|
4838
4925
|
// A loss the agent was not told about yet (`utils/lostWork.ts`) rides the first real prompt, once, ahead of it.
|
|
@@ -4860,13 +4947,13 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4860
4947
|
// (scheduled runs, buffered replay, api-retry nudge, file intake) fall back
|
|
4861
4948
|
// to now. Slash commands skip it for the same reason they skip the preamble.
|
|
4862
4949
|
let promptText = getPromptWithThreadContext(key, body);
|
|
4863
|
-
if (state.checkIsTimestampsEnabled(key) && !
|
|
4950
|
+
if (state.checkIsTimestampsEnabled(key) && !isSlashCommand) {
|
|
4864
4951
|
promptText = `${(0, isoTimestamp_1.formatIsoLocalOffset)(sentAtMs ?? Date.now())}\n\n${promptText}`;
|
|
4865
4952
|
}
|
|
4866
4953
|
// The project board rides every turn start the bot makes (D20: whole on a fresh context, else only what changed),
|
|
4867
4954
|
// then the todo list's staleness reminder rides the next real prompt from any source (D11 form a) — never a slash
|
|
4868
4955
|
// command or a shell line; the reminder never rides the standalone reminder itself.
|
|
4869
|
-
const isTodoDecorated = !
|
|
4956
|
+
const isTodoDecorated = !isSlashCommand && adapter.name !== 'terminal';
|
|
4870
4957
|
if (isTodoDecorated)
|
|
4871
4958
|
discardTodoInbox(key);
|
|
4872
4959
|
const todoBoardBlock = isTodoDecorated ? takeTodoPromptBoard(key) : null;
|
|
@@ -4965,16 +5052,17 @@ function getPromptWithThreadContext(key, text) {
|
|
|
4965
5052
|
}
|
|
4966
5053
|
/**
|
|
4967
5054
|
* @description Bridge a telegraf message (text, voice, or a file) to the
|
|
4968
|
-
* agent-facing
|
|
5055
|
+
* agent-facing message-context block. When the operator uses Telegram's REPLY
|
|
4969
5056
|
* feature, this folds the replied-to message's content into the forwarded prompt
|
|
4970
|
-
* so the agent sees WHAT is being referenced
|
|
5057
|
+
* so the agent sees WHAT is being referenced; when the message was FORWARDED, it
|
|
5058
|
+
* folds the mark that says whose words they are. Returns the block, or `undefined`
|
|
4971
5059
|
* when there is nothing to inject — the connector's
|
|
4972
|
-
* {@link
|
|
5060
|
+
* {@link getTelegramMessageContext} decides. The bot's own id
|
|
4973
5061
|
* (`bot.botInfo.id`) drives the `from: assistant` attribution; a replied-to file
|
|
4974
5062
|
* is looked up among the files this thread took in.
|
|
4975
5063
|
*/
|
|
4976
|
-
function
|
|
4977
|
-
return (0, inbound_1.
|
|
5064
|
+
function getMessageContext(key, message) {
|
|
5065
|
+
return (0, inbound_1.getTelegramMessageContext)(message, { userId: bot.botInfo?.id }, (meta) => findThreadSavedFile(key, meta));
|
|
4978
5066
|
}
|
|
4979
5067
|
/**
|
|
4980
5068
|
* @description The bot's saved copy of a file sent to this thread earlier
|
|
@@ -4994,16 +5082,15 @@ function findThreadSavedFile(key, meta) {
|
|
|
4994
5082
|
return name === undefined ? undefined : path.join(dir, name);
|
|
4995
5083
|
}
|
|
4996
5084
|
/**
|
|
4997
|
-
* @description Fold a
|
|
5085
|
+
* @description Fold a message-context block into a prompt that leaves as finished
|
|
4998
5086
|
* text through {@link deliverPromptOrBuffer} — one buffered behind a session
|
|
4999
5087
|
* start, whose replay forwards it as is, or a file announcement — by the one
|
|
5000
5088
|
* rule `forwardPromptToAgent` applies to a live prompt. The thread's adapter is
|
|
5001
5089
|
* the one the text reaches, so a terminal keeps the block out of its shell line.
|
|
5002
5090
|
*/
|
|
5003
|
-
function
|
|
5004
|
-
return (0,
|
|
5005
|
-
|
|
5006
|
-
isSlashCommand: (0, threadContextPreamble_1.checkShouldSkipPreambleForText)(text),
|
|
5091
|
+
function getPromptWithThreadMessageContext(key, text, messageContext) {
|
|
5092
|
+
return (0, messageContext_1.getPromptWithMessageContext)(text, {
|
|
5093
|
+
context: messageContext,
|
|
5007
5094
|
isShellInput: (0, createAdapter_1.getThreadAdapter)(key).name === 'terminal',
|
|
5008
5095
|
});
|
|
5009
5096
|
}
|
|
@@ -5077,8 +5164,10 @@ const botCore = {
|
|
|
5077
5164
|
getState: () => state,
|
|
5078
5165
|
replyToThread,
|
|
5079
5166
|
editThreadMessage,
|
|
5167
|
+
editThreadMessageDetailed,
|
|
5080
5168
|
editThreadKeyboard,
|
|
5081
5169
|
deleteThreadMessage,
|
|
5170
|
+
deleteThreadMessageDetailed,
|
|
5082
5171
|
authoriseContext,
|
|
5083
5172
|
withThreadLocale,
|
|
5084
5173
|
checkIsGeneral,
|
|
@@ -5541,28 +5630,24 @@ async function stripWelcomeKeyboards(key, messageIds) {
|
|
|
5541
5630
|
await (0, bindSweep_1.stripStaleKeyboards)(messageIds, (messageId) => editThreadKeyboard(key, messageId, null, 'welcome'));
|
|
5542
5631
|
}
|
|
5543
5632
|
/**
|
|
5544
|
-
* @description
|
|
5545
|
-
*
|
|
5546
|
-
*
|
|
5547
|
-
* NOT touched (user decision: pins accumulate). Returns the number paused so the
|
|
5548
|
-
* caller can decide whether anything happened. The engine stays generic — this
|
|
5549
|
-
* unbound-specific policy lives here in bot.ts.
|
|
5550
|
-
*
|
|
5551
|
-
* Reminders are EXEMPT ({@link getUnboundPausableSchedules}): they post + pin with
|
|
5552
|
-
* no agent and no folder, so pausing them on unbind would break the one kind that
|
|
5553
|
-
* could still have fired. A thread holding only reminders pauses nothing and posts
|
|
5554
|
-
* no notice.
|
|
5633
|
+
* @description The ports the status line's CLEARING runs over — shared by the scheduler's delivery (a failed run, a topic that
|
|
5634
|
+
* stopped showing the stream, the final run) and by the unbind pause, so the one `clearCheckStatusLine` works the same from both.
|
|
5635
|
+
* The delete is best effort (`deleteThreadMessage` never rejects: a message that is gone or too old to delete stays).
|
|
5555
5636
|
*/
|
|
5637
|
+
const checkStatusLinePorts = {
|
|
5638
|
+
recordStatusLine: (jobId, line) => (0, store_2.recordCheckStatusLine)(state, jobId, line),
|
|
5639
|
+
deleteMessage: async (threadKeyStr, messageId) => {
|
|
5640
|
+
await deleteThreadMessage((0, sessionKey_1.keyFromString)(threadKeyStr), messageId);
|
|
5641
|
+
},
|
|
5642
|
+
};
|
|
5643
|
+
/** @description The `/unbind` wiring of `pauseSchedulesOnUnbind` (`scheduler/unbindPause.ts`, which holds the policy) over the shared status-line ports. */
|
|
5556
5644
|
async function pauseThreadSchedulesOnUnbind(key) {
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
}
|
|
5564
|
-
await replyToThread(key, (0, i18n_1.t)('schedule.pausedUnbound', { count: records.length }));
|
|
5565
|
-
return records.length;
|
|
5645
|
+
return (0, unbindPause_1.pauseSchedulesOnUnbind)({
|
|
5646
|
+
store: state,
|
|
5647
|
+
disarmJob: (jobId) => schedulerEngine?.disarmJob(jobId),
|
|
5648
|
+
statusLinePorts: checkStatusLinePorts,
|
|
5649
|
+
announcePaused: (count) => replyToThread(key, (0, i18n_1.t)('schedule.pausedUnbound', { count })),
|
|
5650
|
+
}, key);
|
|
5566
5651
|
}
|
|
5567
5652
|
/**
|
|
5568
5653
|
* @description Resume the schedules paused for `'unbound'` on `key` when its
|
|
@@ -5985,7 +6070,11 @@ command('whoami', async (ctx, key) => {
|
|
|
5985
6070
|
* locked by `ALLOWED_GROUP_ID` env. Only a creator/administrator of the target
|
|
5986
6071
|
* group may pair, so a random group can't hijack the binding.
|
|
5987
6072
|
*/
|
|
5988
|
-
bot.command('pair', async (ctx) => {
|
|
6073
|
+
bot.command('pair', async (ctx, next) => {
|
|
6074
|
+
// A forwarded `/pair` is somebody else's words: it re-points the bot to no group, and it is not swallowed either —
|
|
6075
|
+
// it goes on to the text handler, which hands it to the agent under its mark like any other forwarded text.
|
|
6076
|
+
if ((0, inbound_1.checkIsTelegramForward)(ctx.message))
|
|
6077
|
+
return next();
|
|
5989
6078
|
const userId = ctx.from?.id;
|
|
5990
6079
|
if (!userId)
|
|
5991
6080
|
return;
|
|
@@ -6605,6 +6694,11 @@ const { registerRunnersCommands, registerRunnersCallbacks, handleRunnersAddressT
|
|
|
6605
6694
|
hub: runnersHub,
|
|
6606
6695
|
// The pairing messages this instance sent: its own record (the hub registry is shared by every instance of the OS user).
|
|
6607
6696
|
pairingMessagesPath: path.join((0, state_1.resolveDataDir)(), 'runner-pairing-messages.json'),
|
|
6697
|
+
// What this instance has told about where the runners' links come from: once per new concern, pinned in General.
|
|
6698
|
+
linkNoticesPath: path.join((0, state_1.resolveDataDir)(), 'runner-link-notices.json'),
|
|
6699
|
+
cacheDir: runnersCacheDir,
|
|
6700
|
+
getGeneralKey: () => getOperatorGeneralKey(),
|
|
6701
|
+
pinMessage: (key, messageId) => pinMessageQuiet(key, messageId, { disableNotification: false }),
|
|
6608
6702
|
sweepExpiredCodes: async (nowMs) => { await (0, hubPairing_1.sweepExpiredPairings)(runnersHub, nowMs); },
|
|
6609
6703
|
readRunnerHost: (0, instanceSettings_1.createRunnerHostReader)(() => (0, instanceSettings_1.getInstanceSettingsPath)(), (line) => console.error(line)),
|
|
6610
6704
|
saveRunnerHost: (address) => (0, instanceSettings_1.saveInstanceSettingsChange)((0, instanceSettings_1.getInstanceSettingsPath)(), { runnerHost: address }),
|
|
@@ -6724,8 +6818,9 @@ const claudeUsageRefresher = (0, claudeUsageRefresher_1.createClaudeUsageRefresh
|
|
|
6724
6818
|
getSnapshot: (name) => state.getClaudeProfileInfo(name)?.usage,
|
|
6725
6819
|
saveSnapshot: (name, snapshot) => state.setClaudeProfileUsage(name, snapshot),
|
|
6726
6820
|
readToken: (configDir) => (0, claudeUsage_1.readClaudeOAuthToken)(configDir),
|
|
6727
|
-
fetchUsage: (accessToken) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken),
|
|
6821
|
+
fetchUsage: (accessToken, signal) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken, { signal }),
|
|
6728
6822
|
refreshOpenCode: (options) => openCodeUsagePoller.refreshAll(options),
|
|
6823
|
+
markOpenCodeStale: (reason) => openCodeUsagePoller.markAllStale(reason),
|
|
6729
6824
|
});
|
|
6730
6825
|
/** The profile that owns a config directory (`null` = default); `null` for a directory outside the profiles root. */
|
|
6731
6826
|
function resolveClaudeProfileNameForDir(configDir) {
|
|
@@ -6930,8 +7025,9 @@ async function planFallbackSwitch(key, cls, episodeId) {
|
|
|
6930
7025
|
fallbackMs: apiErrorRetry_1.usageLimitDefaultMs,
|
|
6931
7026
|
}));
|
|
6932
7027
|
}
|
|
6933
|
-
// The Claude rungs are judged on fresh figures whatever backend hit the limit (a minute's cache)
|
|
6934
|
-
|
|
7028
|
+
// The Claude rungs are judged on fresh figures whatever backend hit the limit (a minute's cache) — waited for only briefly:
|
|
7029
|
+
// a stuck usage endpoint must never hold the switch or the wait notice of a topic that just hit its limit.
|
|
7030
|
+
await (0, usageRefreshBudget_1.refreshUsageWithinBudget)((options) => claudeUsageRefresher.refreshAll(options));
|
|
6935
7031
|
const detection = await detectFallbackOptions();
|
|
6936
7032
|
let chain = state.getFallbackChain();
|
|
6937
7033
|
if (chain.length === 0 && from.backend === 'claude') {
|
|
@@ -7390,7 +7486,9 @@ async function takeFallbackSwitchOffer(key, episodeId, index) {
|
|
|
7390
7486
|
/**
|
|
7391
7487
|
* The `claude_profiles` MCP tool's answer: snapshots refreshed on demand (a minute's cache; the account a resumed session
|
|
7392
7488
|
* 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.
|
|
7393
|
-
* The accounts the operator switched off in the `/limits` list are never picked for a new agent.
|
|
7489
|
+
* The accounts the operator switched off in the `/limits` list are never picked for a new agent. The refresh is waited for
|
|
7490
|
+
* only up to `claudeLaunchRefreshBudgetMs`; past it the cached figures are answered (an agent that waits on a silent tool
|
|
7491
|
+
* call is dropped by its own client after 300 s).
|
|
7394
7492
|
*/
|
|
7395
7493
|
async function listClaudeProfilesForAgent(query) {
|
|
7396
7494
|
await (0, claudeUsageRefresher_1.refreshClaudeUsageForLaunch)(claudeUsageRefresher, { currentProfile: query.currentProfile, isStoppedByLimit: query.isStoppedByLimit, maxAgeMs: claudeUsageRefresher_1.claudeUsageOnDemandMaxAgeMs });
|
|
@@ -8115,8 +8213,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8115
8213
|
// back when that one was still forwarded).
|
|
8116
8214
|
const text = (0, utils_1.stripCommandBotMention)(ctx.message.text.trim());
|
|
8117
8215
|
const kStr = (0, sessionKey_1.keyToString)(key);
|
|
8216
|
+
// A FORWARDED message is content, never control input: its words are somebody else's, so a `/quit` in it is not an
|
|
8217
|
+
// 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
|
|
8218
|
+
// that take text as an ANSWER the bot asked for (a pasted code, a name, a key, a reminder's text) still take it.
|
|
8219
|
+
const isForwarded = (0, inbound_1.checkIsTelegramForward)(ctx.message);
|
|
8220
|
+
const isSlashText = !isForwarded && text.startsWith('/');
|
|
8118
8221
|
// Slash commands we don't own → forward to the agent (e.g. `/context`, `/help`).
|
|
8119
|
-
if (
|
|
8222
|
+
if (isSlashText) {
|
|
8120
8223
|
const cmd = text.slice(1).split(' ')[0].split('@')[0].toLowerCase();
|
|
8121
8224
|
// A slash command ends a pending «Add account» name prompt (the command itself runs normally).
|
|
8122
8225
|
cancelProfileNameCapture(key);
|
|
@@ -8154,7 +8257,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8154
8257
|
// keeps a message typed in the pre-URL boot window from being swallowed/deleted
|
|
8155
8258
|
// as a code. A slash command falls through (so /quit, /new, etc. still run and
|
|
8156
8259
|
// their teardown cancels the pending login; /esc cancels it outright).
|
|
8157
|
-
if (checkIsAuthLoginAwaitingCode(key) && !
|
|
8260
|
+
if (checkIsAuthLoginAwaitingCode(key) && !isSlashText) {
|
|
8158
8261
|
await submitClaudeAuthLoginCode(key, text, ctx.message.message_id);
|
|
8159
8262
|
return;
|
|
8160
8263
|
}
|
|
@@ -8164,25 +8267,25 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8164
8267
|
// a secret; NOT recognised → the flow stays armed and hints (never forwarded
|
|
8165
8268
|
// to the agent). A slash command falls through so /quit, /new, etc. still run
|
|
8166
8269
|
// + cancel the flow.
|
|
8167
|
-
if (checkIsOpenCodeOAuthAwaitingReply(key) && !
|
|
8270
|
+
if (checkIsOpenCodeOAuthAwaitingReply(key) && !isSlashText) {
|
|
8168
8271
|
await submitOpenCodeOAuthReply(key, text, ctx.message.message_id);
|
|
8169
8272
|
return;
|
|
8170
8273
|
}
|
|
8171
8274
|
// `/account` «Add» asked for the new profile's name → this message is it (a bad name keeps the prompt
|
|
8172
8275
|
// armed and says so; a slash command above already disarmed it).
|
|
8173
|
-
if (checkIsAwaitingProfileName(key) && !
|
|
8276
|
+
if (checkIsAwaitingProfileName(key) && !isSlashText) {
|
|
8174
8277
|
await submitProfileName(key, text, ctx.message.message_id);
|
|
8175
8278
|
return;
|
|
8176
8279
|
}
|
|
8177
8280
|
// `/topic` asked for the new topic's name, or for the name of a folder to create → this message is the answer (a bad
|
|
8178
8281
|
// name keeps the prompt armed and says so; a slash command above already ended it).
|
|
8179
|
-
if (checkIsAwaitingTopicInput(key) && !
|
|
8282
|
+
if (checkIsAwaitingTopicInput(key) && !isSlashText) {
|
|
8180
8283
|
await submitTopicInput(key, text);
|
|
8181
8284
|
return;
|
|
8182
8285
|
}
|
|
8183
8286
|
// `/stt` asked for a server address or an API key → this message is the answer. A plausible key is deleted at
|
|
8184
8287
|
// once and never echoed; anything else re-arms the step. A slash command above already disarmed it.
|
|
8185
|
-
if (getAwaitedSttStep(key) !== null && !
|
|
8288
|
+
if (getAwaitedSttStep(key) !== null && !isSlashText) {
|
|
8186
8289
|
await submitSttInput(key, text, ctx.message.message_id);
|
|
8187
8290
|
return;
|
|
8188
8291
|
}
|
|
@@ -8191,13 +8294,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8191
8294
|
// must NOT be forwarded to the agent as a prompt — that both leaks the code
|
|
8192
8295
|
// into the transcript and produced the confusing header error (live
|
|
8193
8296
|
// 2026-07-20). Delete it as a secret and hint to re-run /connect.
|
|
8194
|
-
if (!
|
|
8297
|
+
if (!isSlashText && (0, openCodeAuthLogin_1.parseOAuthCallbackFromReply)(text)) {
|
|
8195
8298
|
await deleteThreadMessage(key, ctx.message.message_id);
|
|
8196
8299
|
await replyToThread(key, (0, i18n_1.t)('connect.oauth_callback_no_flow'));
|
|
8197
8300
|
return;
|
|
8198
8301
|
}
|
|
8199
8302
|
const pendingProviderConnect = pendingProviderConnects.get(kStr);
|
|
8200
|
-
if (pendingProviderConnect &&
|
|
8303
|
+
if (pendingProviderConnect && isSlashText) {
|
|
8201
8304
|
pendingProviderConnects.delete(kStr);
|
|
8202
8305
|
await replyToThread(key, (0, i18n_1.t)('connect.cancelled'));
|
|
8203
8306
|
}
|
|
@@ -8217,7 +8320,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8217
8320
|
// one wizard yields exactly one reminder.
|
|
8218
8321
|
const reminderTextRoute = claimReminderTextCapture(key);
|
|
8219
8322
|
if (reminderTextRoute === 'capture' || reminderTextRoute === 'expired') {
|
|
8220
|
-
if (
|
|
8323
|
+
if (isSlashText) {
|
|
8221
8324
|
await cancelReminderWizard(key);
|
|
8222
8325
|
}
|
|
8223
8326
|
else if (reminderTextRoute === 'expired') {
|
|
@@ -8234,7 +8337,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8234
8337
|
// Session is mid-startup → buffer the prompt and replay it once the agent is
|
|
8235
8338
|
// ready, instead of dropping it into the "no agent running" guidance below.
|
|
8236
8339
|
if (startupPromptBuffer.checkIsStarting(kStr)) {
|
|
8237
|
-
await bufferPromptDuringStartup(key, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) },
|
|
8340
|
+
await bufferPromptDuringStartup(key, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, getMessageContext(key, ctx.message));
|
|
8238
8341
|
return;
|
|
8239
8342
|
}
|
|
8240
8343
|
// Set when this very message bound the topic: its welcome is already the answer, so the idle-thread hint at the end
|
|
@@ -8295,14 +8398,14 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8295
8398
|
// natural-language start + forwarded to the agent. `applyNumberedModelPick`
|
|
8296
8399
|
// always replies (even for the unsupported case), so we always return after a
|
|
8297
8400
|
// numeric pick — the user clearly intended a model pick, not a prompt.
|
|
8298
|
-
if (/^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8401
|
+
if (!isForwarded && /^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8299
8402
|
await applyNumberedModelPick(adapter, key, parseInt(text, 10));
|
|
8300
8403
|
return;
|
|
8301
8404
|
}
|
|
8302
8405
|
// Session-pick mode (armed by `/sessions` / `/resume`). Only while the
|
|
8303
8406
|
// thread is armed is a bare digit treated as a pick — a normal numeric
|
|
8304
8407
|
// prompt is never hijacked. See `checkSessionPickAction` for the rules.
|
|
8305
|
-
if (awaitingSessionSelection.has(kStr)) {
|
|
8408
|
+
if (!isForwarded && awaitingSessionSelection.has(kStr)) {
|
|
8306
8409
|
const sessionList = threadSessionLists.get(kStr) ?? [];
|
|
8307
8410
|
const pick = (0, sessionPick_1.checkSessionPickAction)(text, sessionList.length);
|
|
8308
8411
|
if (pick.kind === 'invalid') {
|
|
@@ -8328,7 +8431,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8328
8431
|
awaitingSessionSelection.delete(kStr);
|
|
8329
8432
|
}
|
|
8330
8433
|
// Natural-language start.
|
|
8331
|
-
if (!adapter.checkIsActive(key)) {
|
|
8434
|
+
if (!isForwarded && !adapter.checkIsActive(key)) {
|
|
8332
8435
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(text);
|
|
8333
8436
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8334
8437
|
if (checkIsGeneral(key)) {
|
|
@@ -8374,7 +8477,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8374
8477
|
// never surfaced, so a bare digit during a survey window is NOT a route here —
|
|
8375
8478
|
// it falls through to the normal prompt path instead of being dropped.
|
|
8376
8479
|
const replyRoute = (0, claudeCliAdapter_1.getClaudeReplyRoute)({
|
|
8377
|
-
isQuestionPending: adapter.isQuestionPending?.(key) ?? false,
|
|
8480
|
+
isQuestionPending: !isForwarded && (adapter.isQuestionPending?.(key) ?? false),
|
|
8378
8481
|
isLoginPastePending: adapter.isLoginPastePending?.(key) ?? false,
|
|
8379
8482
|
text,
|
|
8380
8483
|
});
|
|
@@ -8409,16 +8512,16 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8409
8512
|
// branches above already returned for their own cases, so this is reached only
|
|
8410
8513
|
// for a generic active prompt. The message's real send time (Telegram `date`,
|
|
8411
8514
|
// unix seconds) rides along for the `/timestamps` injection, and a Telegram
|
|
8412
|
-
// REPLY folds
|
|
8515
|
+
// REPLY or FORWARD folds its context into the prompt (see `getMessageContext`).
|
|
8413
8516
|
if (adapter.checkIsActive(key)) {
|
|
8414
|
-
const
|
|
8415
|
-
await deliverActivePrompt(key, adapter, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
8517
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
8518
|
+
await deliverActivePrompt(key, adapter, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000, messageContext);
|
|
8416
8519
|
return;
|
|
8417
8520
|
}
|
|
8418
8521
|
// A sleeping conversation (its process stopped, its session kept) is resumed by
|
|
8419
8522
|
// the message itself (L-D4) — the prompt continues the same conversation.
|
|
8420
8523
|
if (await resumeSleepingSessionForPrompt(key)) {
|
|
8421
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
8524
|
+
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));
|
|
8422
8525
|
return;
|
|
8423
8526
|
}
|
|
8424
8527
|
// Idle thread — guide the user. Three sub-states:
|
|
@@ -8456,6 +8559,9 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8456
8559
|
await replyToThread(key, (0, i18n_1.t)((0, sttSettings_1.getNoEngineNoticeCode)(sttSettings)));
|
|
8457
8560
|
return;
|
|
8458
8561
|
}
|
|
8562
|
+
// The local engine may be cold: start its load now, so it overlaps the download and the topic's voice queue. The voice's
|
|
8563
|
+
// job reuses this one ask, so the engine is started once per voice, whatever the outcome.
|
|
8564
|
+
const warmedEndpoint = (0, transcribeChain_1.warmUpFirstEngine)(sttSettings.engines, (line) => console.warn(line));
|
|
8459
8565
|
// Offload the slow download+transcribe+forward off the telegraf update loop:
|
|
8460
8566
|
// awaiting it here would stall intake of EVERY update until Groq replies
|
|
8461
8567
|
// (up to 20s, longer on retries) and freeze the whole bot. The per-thread
|
|
@@ -8466,15 +8572,20 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8466
8572
|
const fileId = ctx.message.voice.file_id;
|
|
8467
8573
|
const durationSeconds = ctx.message.voice.duration;
|
|
8468
8574
|
const sentAtMs = ctx.message.date * 1000;
|
|
8469
|
-
// A Telegram REPLY on the voice note folds the quoted message into the prompt
|
|
8470
|
-
// Compute it HERE (only the handler has
|
|
8471
|
-
// update loop and only sees `key`/`bot`.
|
|
8472
|
-
const
|
|
8575
|
+
// A Telegram REPLY on the voice note folds the quoted message into the prompt, a
|
|
8576
|
+
// FORWARD of it the mark of its origin. Compute it HERE (only the handler has
|
|
8577
|
+
// `ctx`); the job runs later off the update loop and only sees `key`/`bot`.
|
|
8578
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
8579
|
+
// Armed LAST, right before the job is queued: nothing between here and the queue may throw and strand an armed note. The
|
|
8580
|
+
// 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
|
|
8581
|
+
// the moment its text arrives, and the `finally` is the backstop for a job that never ran or ended some other way.
|
|
8582
|
+
const progressNote = startVoiceProgressNote(key);
|
|
8473
8583
|
void (0, voiceQueue_1.getVoiceTranscriptionQueue)(key)
|
|
8474
|
-
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), sentAtMs,
|
|
8584
|
+
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), warmedEndpoint, progressNote, sentAtMs, messageContext))
|
|
8475
8585
|
.catch((err) => {
|
|
8476
8586
|
console.error('[Bot] Voice job error (already handled):', err);
|
|
8477
|
-
})
|
|
8587
|
+
})
|
|
8588
|
+
.finally(() => progressNote.finish());
|
|
8478
8589
|
});
|
|
8479
8590
|
/**
|
|
8480
8591
|
* @description Background worker for a single voice note: download → transcribe
|
|
@@ -8484,12 +8595,17 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8484
8595
|
* Uses only `key`/`bot`, never the request `ctx`, so it survives past the
|
|
8485
8596
|
* handler's return. `sentAtMs` is the voice note's real Telegram send time,
|
|
8486
8597
|
* captured by the handler for the `/timestamps` injection (transcription can
|
|
8487
|
-
* take ~20s, so "now" at forward time would drift). `
|
|
8488
|
-
*
|
|
8489
|
-
* the voice note), plumbed here since the job no longer has `ctx`; so is
|
|
8490
|
-
* `requesterId`, the sender the transcript's request is filed under
|
|
8491
|
-
|
|
8492
|
-
|
|
8598
|
+
* take ~20s, so "now" at forward time would drift). `messageContext` is the
|
|
8599
|
+
* message-context block the handler built from `ctx.message` (a Telegram REPLY
|
|
8600
|
+
* or a FORWARD of the voice note), plumbed here since the job no longer has `ctx`; so is
|
|
8601
|
+
* `requesterId`, the sender the transcript's request is filed under, and
|
|
8602
|
+
* `warmedEndpoint`, the first engine's endpoint asked for when the note arrived
|
|
8603
|
+
* (the job reuses that one ask — see `warmUpFirstEngine`), and `progressNote`, the
|
|
8604
|
+
* «transcribing…» note armed on arrival, which the job finishes as soon as the
|
|
8605
|
+
* text is here or the voice failed — BEFORE the echo or the failure notice, never
|
|
8606
|
+
* at the end of the job (delivering the prompt may take long).
|
|
8607
|
+
*/
|
|
8608
|
+
async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmedEndpoint, progressNote, sentAtMs, messageContext) {
|
|
8493
8609
|
try {
|
|
8494
8610
|
// Audit S14 / #33: `getFileLink` builds the bot-token URL in one
|
|
8495
8611
|
// place inside Telegraf instead of us materialising the token in a
|
|
@@ -8516,11 +8632,15 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, sentAt
|
|
|
8516
8632
|
catch (downloadErr) {
|
|
8517
8633
|
const msg = downloadErr instanceof Error ? downloadErr.message : String(downloadErr);
|
|
8518
8634
|
console.warn(`[Bot] voice download failed after retries: ${msg}`);
|
|
8635
|
+
await progressNote.finish();
|
|
8519
8636
|
await replyToThread(key, `${(0, i18n_1.t)('voice.failed')} (${msg})`);
|
|
8520
8637
|
return;
|
|
8521
8638
|
}
|
|
8522
|
-
const result = await transcribeVoiceFile(key, tempFile, durationSeconds);
|
|
8639
|
+
const result = await transcribeVoiceFile(key, tempFile, durationSeconds, warmedEndpoint);
|
|
8523
8640
|
fs.unlink(tempFile, () => { });
|
|
8641
|
+
// Text or failure — either way the wait is over. The note is gone BEFORE the echo or the failure notice goes out (the finish is
|
|
8642
|
+
// bounded, so a stalled delete holds the answer back for a moment at most; what it cut short ends in the background).
|
|
8643
|
+
await progressNote.finish();
|
|
8524
8644
|
if (!result.ok) {
|
|
8525
8645
|
await replyToThread(key, `${(0, i18n_1.t)('voice.failed')} (${result.error})`);
|
|
8526
8646
|
return;
|
|
@@ -8544,10 +8664,11 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, sentAt
|
|
|
8544
8664
|
await expireReminderWizard(key);
|
|
8545
8665
|
// Session is mid-startup → buffer the transcript and replay it once ready.
|
|
8546
8666
|
if (startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key))) {
|
|
8547
|
-
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId },
|
|
8667
|
+
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId }, messageContext);
|
|
8548
8668
|
return;
|
|
8549
8669
|
}
|
|
8550
|
-
|
|
8670
|
+
// A FORWARDED voice note saying «Claude» is somebody else's words, not the operator's order to start an agent.
|
|
8671
|
+
if (messageContext?.isForwarded !== true && !(0, createAdapter_1.getThreadAdapter)(key).checkIsActive(key)) {
|
|
8551
8672
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(transcript);
|
|
8552
8673
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8553
8674
|
if (checkIsGeneral(key)) {
|
|
@@ -8597,10 +8718,11 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, sentAt
|
|
|
8597
8718
|
// delivered as a fresh prompt — closing the gap where voice queued behind a
|
|
8598
8719
|
// blocked question-turn and the user got no reply.
|
|
8599
8720
|
// Read AFTER the wake: the resume may have switched the thread's adapter.
|
|
8600
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs,
|
|
8721
|
+
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs, messageContext);
|
|
8601
8722
|
}
|
|
8602
8723
|
catch (err) {
|
|
8603
8724
|
console.error('[Bot] Voice handling error:', err);
|
|
8725
|
+
await progressNote.finish();
|
|
8604
8726
|
await replyToThread(key, 'Error processing voice message');
|
|
8605
8727
|
}
|
|
8606
8728
|
}
|
|
@@ -8749,7 +8871,7 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8749
8871
|
const orderedItems = [...items].sort((a, b) => a.messageId - b.messageId);
|
|
8750
8872
|
const files = orderedItems.map((item) => item.albumFile);
|
|
8751
8873
|
const caption = orderedItems.find((item) => item.caption && item.caption.trim())?.caption;
|
|
8752
|
-
const
|
|
8874
|
+
const messageContext = orderedItems.find((item) => item.messageContext)?.messageContext;
|
|
8753
8875
|
const promptText = (0, fileIntake_1.buildAlbumPromptText)(files, caption);
|
|
8754
8876
|
const isStarting = startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key));
|
|
8755
8877
|
// User took over (album upload) before a pending API-error retry fired →
|
|
@@ -8758,8 +8880,8 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8758
8880
|
// A user album is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8759
8881
|
notePersonActivity(key);
|
|
8760
8882
|
try {
|
|
8761
|
-
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId });
|
|
8762
|
-
const quotedPrompt =
|
|
8883
|
+
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId }, messageContext);
|
|
8884
|
+
const quotedPrompt = getPromptWithThreadMessageContext(key, promptText, messageContext);
|
|
8763
8885
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8764
8886
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8765
8887
|
}
|
|
@@ -8811,7 +8933,7 @@ async function handleAlbumFile(ctx, key, meta, mediaGroupId) {
|
|
|
8811
8933
|
messageId: ctx.message.message_id,
|
|
8812
8934
|
albumFile: { kind: meta.kind, savedPath, fileSize: meta.fileSize },
|
|
8813
8935
|
caption: meta.caption,
|
|
8814
|
-
|
|
8936
|
+
messageContext: getMessageContext(key, ctx.message),
|
|
8815
8937
|
requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from),
|
|
8816
8938
|
});
|
|
8817
8939
|
}
|
|
@@ -8841,9 +8963,10 @@ async function handleIncomingFile(ctx, key) {
|
|
|
8841
8963
|
cancelApiRetry(key);
|
|
8842
8964
|
// A user file is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8843
8965
|
notePersonActivity(key);
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
const
|
|
8966
|
+
// A file sent as a REPLY carries the message it answers, a forwarded one its origin, as a typed or spoken message does.
|
|
8967
|
+
const messageContext = getMessageContext(key, ctx.message);
|
|
8968
|
+
const opening = await openTopicRequest(key, promptText, { source: 'file', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, messageContext);
|
|
8969
|
+
const quotedPrompt = getPromptWithThreadMessageContext(key, promptText, messageContext);
|
|
8847
8970
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8848
8971
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8849
8972
|
}
|
|
@@ -9522,20 +9645,21 @@ bot.action(/^qa_(\d+)_(\d+)$/, async (ctx) => {
|
|
|
9522
9645
|
* @description Buffer a free-form prompt (text OR voice) that arrived while the
|
|
9523
9646
|
* thread's session is starting — the startup twin of {@link deliverActivePrompt}.
|
|
9524
9647
|
* The request is opened at capture time (S7), so the buffered text carries its
|
|
9525
|
-
* header; the
|
|
9526
|
-
* the buffered text as is and a REPLY made during the boot would
|
|
9527
|
-
* the agent without the message it points at.
|
|
9648
|
+
* header; the message-context block is folded in here too, since the replay forwards
|
|
9649
|
+
* the buffered text as is and a REPLY or a FORWARD made during the boot would
|
|
9650
|
+
* otherwise reach the agent without the message it points at, or as the operator's own words.
|
|
9528
9651
|
*/
|
|
9529
|
-
async function bufferPromptDuringStartup(key, text, intake,
|
|
9530
|
-
// The same for a bare option number typed in that window: it answers the question asked again.
|
|
9531
|
-
|
|
9652
|
+
async function bufferPromptDuringStartup(key, text, intake, messageContext) {
|
|
9653
|
+
// The same for a bare option number typed in that window: it answers the question asked again. A FORWARDED "1" is somebody
|
|
9654
|
+
// else's words, not the operator's pick: it is delivered, marked, like any other message.
|
|
9655
|
+
if (messageContext?.isForwarded !== true && await answerReAskedQuestionByNumber(key, text))
|
|
9532
9656
|
return;
|
|
9533
9657
|
// A person wrote, in a window where the session is starting or being stopped: it counts like a message that reaches
|
|
9534
9658
|
// `deliverActivePrompt` — the idle latch clears, and a question the idle compaction re-asked is closed (the idle fire
|
|
9535
9659
|
// posts it just before the stop, so this window is where a message instead of a tap most often lands).
|
|
9536
9660
|
notePersonActivity(key);
|
|
9537
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9538
|
-
const quotedText =
|
|
9661
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9662
|
+
const quotedText = getPromptWithThreadMessageContext(key, text, messageContext);
|
|
9539
9663
|
await deliverPromptOrBuffer(key, `${opening.header}${quotedText}`, true);
|
|
9540
9664
|
trackTopicRequestTurn(key, opening);
|
|
9541
9665
|
}
|
|
@@ -9556,9 +9680,11 @@ async function bufferPromptDuringStartup(key, text, intake, replyContext) {
|
|
|
9556
9680
|
* `answerQuestion`). The tmux-scrape Claude and the terminal never reach it (no `pendingQuestions` entry): for them
|
|
9557
9681
|
* `forwardPromptToAgent` interrupts the TUI selector itself.
|
|
9558
9682
|
*/
|
|
9559
|
-
async function deliverActivePrompt(key, adapter, text, intake, sentAtMs,
|
|
9683
|
+
async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, messageContext) {
|
|
9684
|
+
// A FORWARDED message is content, never control input: it answers no question and purges no context, whatever its words are.
|
|
9685
|
+
const isForwarded = messageContext?.isForwarded === true;
|
|
9560
9686
|
// A bare option number answers the question the idle compaction asked again (a tap's own label comes in with no intake).
|
|
9561
|
-
if (intake !== null && await answerReAskedQuestionByNumber(key, text))
|
|
9687
|
+
if (intake !== null && !isForwarded && await answerReAskedQuestionByNumber(key, text))
|
|
9562
9688
|
return null;
|
|
9563
9689
|
// A genuine USER message (text or voice) — clear the compact-on-idle latch so
|
|
9564
9690
|
// the next idle period can compact again (D2), whether it answers a pending
|
|
@@ -9568,16 +9694,17 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9568
9694
|
if (pending && adapter.answerQuestion) {
|
|
9569
9695
|
const currentQuestion = pending.data.questions[pending.currentIndex];
|
|
9570
9696
|
const route = (0, openCodeQuestionFlow_1.getQuestionReplyRoute)(text, currentQuestion);
|
|
9571
|
-
if (route.kind === 'answer') {
|
|
9697
|
+
if (route.kind === 'answer' && !isForwarded) {
|
|
9572
9698
|
// Answering a pending question (bare digit) is a pick, not a prompt about
|
|
9573
9699
|
// the quote — the reply context is deliberately dropped here. Not a request
|
|
9574
|
-
// either: the turn it unblocks continues under the open one.
|
|
9700
|
+
// either: the turn it unblocks continues under the open one. A forwarded digit
|
|
9701
|
+
// is not a pick: it falls to the free-form route below and reaches the agent marked.
|
|
9575
9702
|
await applyQuestionAnswer(key, route.labels);
|
|
9576
9703
|
return null;
|
|
9577
9704
|
}
|
|
9578
9705
|
// Free-form text cancels the question and is a fresh prompt — a request (S7).
|
|
9579
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9580
|
-
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9706
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9707
|
+
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, opening.header);
|
|
9581
9708
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
9582
9709
|
return null;
|
|
9583
9710
|
}
|
|
@@ -9586,7 +9713,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9586
9713
|
// before forwarding — the slash text itself never gets a preamble. The agent's
|
|
9587
9714
|
// context is gone, so any intake files it might reference are now useless —
|
|
9588
9715
|
// purge the thread's files dir in the same breath.
|
|
9589
|
-
if (text === forwardedClearCommand) {
|
|
9716
|
+
if (text === forwardedClearCommand && !isForwarded) {
|
|
9590
9717
|
clearThreadContextMarker(key);
|
|
9591
9718
|
await (0, botFileStorage_1.purgeThreadFiles)(getDataDir(), key).catch((e) => console.warn(`[file] purge on /clear failed for ${(0, sessionKey_1.keyToString)(key)}:`, e));
|
|
9592
9719
|
}
|
|
@@ -9605,7 +9732,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9605
9732
|
// The request (S7) is opened AFTER the user takeover cancelled an armed limit
|
|
9606
9733
|
// wait (the handlers' `cancelApiRetry`) and before the forward, so its id is
|
|
9607
9734
|
// durable by the time the agent reads it.
|
|
9608
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9735
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9609
9736
|
// Routed now, not when the message arrived: the idle stop may have begun or ended during the awaits since.
|
|
9610
9737
|
// The forward can itself end in no session — a prompt that waited for an adopt replay found the session gone and nothing to wake;
|
|
9611
9738
|
// it has told the person already (`forwardPromptToAgent`), so what is left here is the request this prompt opened.
|
|
@@ -9613,10 +9740,10 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9613
9740
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
9614
9741
|
checkIsSessionActive: () => adapter.checkIsActive(key),
|
|
9615
9742
|
buffer: async () => {
|
|
9616
|
-
await deliverPromptOrBuffer(key, `${opening.header}${
|
|
9743
|
+
await deliverPromptOrBuffer(key, `${opening.header}${getPromptWithThreadMessageContext(key, text, messageContext)}`, true);
|
|
9617
9744
|
},
|
|
9618
9745
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
9619
|
-
forward: () => forwardPromptToAgent(key, (0, createAdapter_1.getThreadAdapter)(key), text, sentAtMs, {
|
|
9746
|
+
forward: () => forwardPromptToAgent(key, (0, createAdapter_1.getThreadAdapter)(key), text, sentAtMs, { messageContext, requestHeader: opening.header }),
|
|
9620
9747
|
reportNoSession: async (isAlreadyTold) => {
|
|
9621
9748
|
if (!isAlreadyTold)
|
|
9622
9749
|
await replyToThread(key, (0, i18n_1.t)('agent.no_session'));
|
|
@@ -9664,7 +9791,7 @@ function retirePendingQuestionInBackground(key) {
|
|
|
9664
9791
|
* close it on the server, abort the wedged OpenCode turn (`SIGINT` → `/session/:id/
|
|
9665
9792
|
* abort`), post the "previous question cancelled" notice, then forward.
|
|
9666
9793
|
*/
|
|
9667
|
-
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9794
|
+
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, requestHeader) {
|
|
9668
9795
|
// When the question bubble itself was closed with its «not answered» note, that IS the
|
|
9669
9796
|
// cancellation notice — a second standalone "previous question cancelled" line is
|
|
9670
9797
|
// pure noise (the reported triple message). The standalone notice is kept only
|
|
@@ -9683,7 +9810,7 @@ async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, rep
|
|
|
9683
9810
|
if (!didLabelQuestionMessage) {
|
|
9684
9811
|
await replyToThread(key, (0, i18n_1.t)('agent.question_cancelled_for_prompt'));
|
|
9685
9812
|
}
|
|
9686
|
-
return forwardPromptToAgent(key, adapter, text, sentAtMs, {
|
|
9813
|
+
return forwardPromptToAgent(key, adapter, text, sentAtMs, { messageContext, requestHeader });
|
|
9687
9814
|
}
|
|
9688
9815
|
/**
|
|
9689
9816
|
* @description Record one answer for the CURRENTLY shown OpenCode question and
|
|
@@ -10082,7 +10209,7 @@ async function sendStatusFrame(key, status) {
|
|
|
10082
10209
|
const editId = msgState.statusMessageId;
|
|
10083
10210
|
const ok = await editThreadMessage(key, editId, firstRendered, {
|
|
10084
10211
|
parse_mode: 'HTML',
|
|
10085
|
-
});
|
|
10212
|
+
}, chunks[0]);
|
|
10086
10213
|
// A delete that landed during the edit already nulled (or replaced) the id;
|
|
10087
10214
|
// don't claim the frame as live — let the create path below re-evaluate.
|
|
10088
10215
|
if (ok && msgState.statusMessageId === editId) {
|
|
@@ -10213,7 +10340,7 @@ function finishThinkingMessage(key) {
|
|
|
10213
10340
|
*/
|
|
10214
10341
|
function queueThinkingFrame(key, frameText, isTerminal) {
|
|
10215
10342
|
const c = getThinkingCoalesceState(key);
|
|
10216
|
-
c.
|
|
10343
|
+
c.pending = (0, renderAgentHtml_1.renderAgentFrame)(frameText);
|
|
10217
10344
|
if (isTerminal)
|
|
10218
10345
|
c.detachAfterDrain = true;
|
|
10219
10346
|
if (!c.inFlight)
|
|
@@ -10233,14 +10360,14 @@ async function flushThinkingCoalescer(key) {
|
|
|
10233
10360
|
return;
|
|
10234
10361
|
c.inFlight = true;
|
|
10235
10362
|
try {
|
|
10236
|
-
while (c.
|
|
10237
|
-
const
|
|
10238
|
-
c.
|
|
10239
|
-
if (html === c.lastSentHtml)
|
|
10363
|
+
while (c.pending !== null) {
|
|
10364
|
+
const frame = c.pending;
|
|
10365
|
+
c.pending = null;
|
|
10366
|
+
if (frame.html === c.lastSentHtml)
|
|
10240
10367
|
continue;
|
|
10241
|
-
const sent = await sendThinkingFrame(key,
|
|
10368
|
+
const sent = await sendThinkingFrame(key, frame);
|
|
10242
10369
|
if (sent)
|
|
10243
|
-
c.lastSentHtml = html;
|
|
10370
|
+
c.lastSentHtml = frame.html;
|
|
10244
10371
|
}
|
|
10245
10372
|
if (c.detachAfterDrain) {
|
|
10246
10373
|
c.detachAfterDrain = false;
|
|
@@ -10254,14 +10381,15 @@ async function flushThinkingCoalescer(key) {
|
|
|
10254
10381
|
/**
|
|
10255
10382
|
* @description Edit the thread's thinking message in place, or create it on the
|
|
10256
10383
|
* first frame. The frame is pre-rendered HTML (one message — `full`-mode bodies
|
|
10257
|
-
* are tail-trimmed to fit)
|
|
10384
|
+
* are tail-trimmed to fit) with its source text as the plain twin that goes out
|
|
10385
|
+
* if Telegram refuses the markup. Returns `true` when the frame reached Telegram.
|
|
10258
10386
|
*/
|
|
10259
|
-
async function sendThinkingFrame(key,
|
|
10387
|
+
async function sendThinkingFrame(key, frame) {
|
|
10260
10388
|
const msgState = getThreadMessageState(key);
|
|
10261
10389
|
try {
|
|
10262
10390
|
if (msgState.thinkingMessageId !== null) {
|
|
10263
10391
|
const editId = msgState.thinkingMessageId;
|
|
10264
|
-
const ok = await editThreadMessage(key, editId,
|
|
10392
|
+
const ok = await editThreadMessage(key, editId, frame.html, { parse_mode: 'HTML' }, frame.plain);
|
|
10265
10393
|
// A clear (session end / takeover) may have nulled the id mid-edit — only
|
|
10266
10394
|
// treat the edit as live if the id still points at the message we edited.
|
|
10267
10395
|
if (ok && msgState.thinkingMessageId === editId)
|
|
@@ -10275,7 +10403,7 @@ async function sendThinkingFrame(key, renderedHtml) {
|
|
|
10275
10403
|
// just-created message instead of resurrecting it as an orphan under a
|
|
10276
10404
|
// "session ended" / question UI (the leftover-frame guard).
|
|
10277
10405
|
const generationAtStart = msgState.thinkingFrameGeneration;
|
|
10278
|
-
const id = await replyChunkWithFallback(key,
|
|
10406
|
+
const id = await replyChunkWithFallback(key, frame.html, frame.plain);
|
|
10279
10407
|
if (id === null)
|
|
10280
10408
|
return false;
|
|
10281
10409
|
if (msgState.thinkingFrameGeneration !== generationAtStart) {
|
|
@@ -10570,7 +10698,7 @@ async function refreshSubagentStatus(key) {
|
|
|
10570
10698
|
// send finally lands.
|
|
10571
10699
|
state.lastSubagentText = text;
|
|
10572
10700
|
try {
|
|
10573
|
-
const sent = await editThreadMessage(key, messageId, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' });
|
|
10701
|
+
const sent = await editThreadMessage(key, messageId, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' }, text);
|
|
10574
10702
|
// Guard the post-await mutations against a close+reopen that swapped the
|
|
10575
10703
|
// frame WHILE this edit was draining the pacer: `lastSubagentText` /
|
|
10576
10704
|
// `subagentEditInFlight` now belong to a DIFFERENT frame that owns its own
|
|
@@ -10695,7 +10823,7 @@ function handleSubagentStatus(key, payload) {
|
|
|
10695
10823
|
state.lastSubagentText = null;
|
|
10696
10824
|
state.subagentEditInFlight = false;
|
|
10697
10825
|
const text = (0, subagentStatusRender_1.buildSubagentElapsedText)(state.subagentTitle, 0);
|
|
10698
|
-
const id = await replyToThread(key, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' });
|
|
10826
|
+
const id = await replyToThread(key, (0, renderAgentHtml_1.renderAgentHtml)(text), { parse_mode: 'HTML' }, { plainFallbackText: text });
|
|
10699
10827
|
if (id === null)
|
|
10700
10828
|
return;
|
|
10701
10829
|
// A close (teardown) may have landed during the create — don't leave the
|
|
@@ -11926,26 +12054,30 @@ function healSchedulerMcpForActiveSessions() {
|
|
|
11926
12054
|
}
|
|
11927
12055
|
const defaultReconcileTransientFramesDeps = {
|
|
11928
12056
|
deleteMessage: (chatId, messageId) => bot.telegram.deleteMessage(chatId, messageId),
|
|
11929
|
-
|
|
12057
|
+
setUndeletedMessageIds,
|
|
12058
|
+
checkIsRetryable: telegramError_1.checkIsRetryableTelegramError,
|
|
11930
12059
|
};
|
|
11931
12060
|
/**
|
|
11932
|
-
* @description Delete transient
|
|
11933
|
-
*
|
|
11934
|
-
* "✽ working…" / thinking /
|
|
11935
|
-
* (S2, the crash safety net
|
|
11936
|
-
* snapshot
|
|
11937
|
-
*
|
|
11938
|
-
*
|
|
11939
|
-
* the
|
|
11940
|
-
*
|
|
11941
|
-
*
|
|
11942
|
-
*
|
|
11943
|
-
*
|
|
11944
|
-
*
|
|
11945
|
-
*
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
12061
|
+
* @description Delete transient messages left on screen by an exit that did not
|
|
12062
|
+
* finish its own cleanup — a crash / SIGKILL (the graceful shutdown sweep never
|
|
12063
|
+
* ran) or a sweep whose deletes hit a bad moment: the "✽ working…" / thinking /
|
|
12064
|
+
* sub-agent frames and the «transcribing…» voice notes (S2, the crash safety net
|
|
12065
|
+
* behind S1). The snapshot MUST be captured BEFORE reattach (see {@link startBot}):
|
|
12066
|
+
* a reattached session's frame setters persist the fresh in-memory state and would
|
|
12067
|
+
* clobber the live persisted set first. Every snapshot id is stale by definition
|
|
12068
|
+
* (the fresh process holds no handle to it; a still-busy reattached session
|
|
12069
|
+
* repaints its OWN fresh frame), so deleting is always safe.
|
|
12070
|
+
*
|
|
12071
|
+
* The stale ids are first parked in the thread's `undeletedMessageIds` (persisted
|
|
12072
|
+
* with the live ids), then deleted; a delete that fails for a reason a later try can
|
|
12073
|
+
* fix (no answer from Telegram, a 429, a 5xx) KEEPS its id there — the next sweep and
|
|
12074
|
+
* the next boot retry it — while a final answer (already gone, too old to delete,
|
|
12075
|
+
* refused) settles it. Before, the persisted set was re-synced to the live ids at
|
|
12076
|
+
* once and a failed delete was forgotten: the frame stayed in the topic with no
|
|
12077
|
+
* record left. Resolves with how many stale ids were settled; never rejects.
|
|
12078
|
+
*/
|
|
12079
|
+
async function reconcileTransientFrames(orphaned, deps = defaultReconcileTransientFramesDeps) {
|
|
12080
|
+
const threads = [];
|
|
11949
12081
|
for (const [keyStr, ids] of Object.entries(orphaned)) {
|
|
11950
12082
|
let key;
|
|
11951
12083
|
try {
|
|
@@ -11956,17 +12088,21 @@ function reconcileTransientFrames(orphaned, deps = defaultReconcileTransientFram
|
|
|
11956
12088
|
// keep booting. Tolerated-and-skipped, like restorePendingQuestions.
|
|
11957
12089
|
continue;
|
|
11958
12090
|
}
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
deleted += 1;
|
|
11962
|
-
}
|
|
11963
|
-
// Sync disk to the LIVE in-memory frames (post-reattach): a still-busy
|
|
11964
|
-
// session that repainted a fresh frame keeps its new id; an idle one clears.
|
|
11965
|
-
deps.persistFrames(key);
|
|
12091
|
+
deps.setUndeletedMessageIds(key, ids);
|
|
12092
|
+
threads.push({ key, ids });
|
|
11966
12093
|
}
|
|
11967
|
-
|
|
11968
|
-
|
|
11969
|
-
|
|
12094
|
+
const settledCounts = await Promise.all(threads.map(async ({ key, ids }) => {
|
|
12095
|
+
const keptIds = await (0, transientFrames_1.deleteTransientMessages)(ids, async (messageId) => { await deps.deleteMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId); }, deps.checkIsRetryable);
|
|
12096
|
+
deps.setUndeletedMessageIds(key, keptIds);
|
|
12097
|
+
return ids.length - keptIds.length;
|
|
12098
|
+
}));
|
|
12099
|
+
const settled = settledCounts.reduce((total, count) => total + count, 0);
|
|
12100
|
+
const kept = threads.reduce((total, { ids }) => total + ids.length, 0) - settled;
|
|
12101
|
+
if (settled > 0)
|
|
12102
|
+
console.log(`[reattach] transient frames: deleted ${settled} stale`);
|
|
12103
|
+
if (kept > 0)
|
|
12104
|
+
console.warn(`[reattach] transient frames: ${kept} could not be deleted now; they stay recorded and are tried again at the next sweep and boot`);
|
|
12105
|
+
return settled;
|
|
11970
12106
|
}
|
|
11971
12107
|
/**
|
|
11972
12108
|
* Bot composition for the reusable file-send service. Every gateway method
|
|
@@ -12226,15 +12362,33 @@ function createSessionPostDeps() {
|
|
|
12226
12362
|
function wireScheduler(wiring) {
|
|
12227
12363
|
const { jiraConnector } = wiring;
|
|
12228
12364
|
const ledger = new runLedger_1.RunLedger();
|
|
12365
|
+
// 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.
|
|
12366
|
+
const unpinThreadMessages = async (threadKeyStr, messageIds) => {
|
|
12367
|
+
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12368
|
+
if (!checkIsTelegramPrimitiveKey(key, 'unpinMessage'))
|
|
12369
|
+
return [];
|
|
12370
|
+
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)}`));
|
|
12371
|
+
};
|
|
12229
12372
|
const delivery = (0, delivery_1.createScheduleDelivery)({
|
|
12230
12373
|
...createSessionPostDeps(),
|
|
12231
|
-
|
|
12232
|
-
|
|
12374
|
+
...checkStatusLinePorts,
|
|
12375
|
+
// A scheduled fire and a check alert are ordinary silent output; a folded detail (the prompt, a check's output) goes
|
|
12376
|
+
// in an expandable quotation. Only a reminder is sent as it is, and pinned.
|
|
12377
|
+
announce: (threadKeyStr, text, options) => {
|
|
12233
12378
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
|
|
12379
|
+
const extra = options?.isSilent ? { disable_notification: true } : {};
|
|
12380
|
+
if (options?.foldedDetail === undefined)
|
|
12381
|
+
return replyToThread(key, text, extra);
|
|
12382
|
+
// If Telegram ever rejects the markup, the retry is the same words as plain text — never the tags shown literally.
|
|
12383
|
+
const foldedMessage = (0, foldedMessage_1.buildFoldedMessage)(text, options.foldedDetail);
|
|
12384
|
+
return replyToThread(key, foldedMessage.html, { ...extra, parse_mode: 'HTML' }, { plainFallbackText: foldedMessage.plain });
|
|
12385
|
+
},
|
|
12386
|
+
// The only scheduler pin left: a reminder, which pierces a muted topic on purpose.
|
|
12387
|
+
pin: async (threadKeyStr, messageId) => {
|
|
12388
|
+
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12389
|
+
await (0, rateLimiter_1.enqueueSend)(key, () => bot.telegram.pinChatMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), messageId, { disable_notification: false }));
|
|
12237
12390
|
},
|
|
12391
|
+
unpinMessages: unpinThreadMessages,
|
|
12238
12392
|
runCheck: async (threadKeyStr, command, timeoutMs) => {
|
|
12239
12393
|
const decision = (0, validation_1.resolveBoundWorkDir)(ENV.workRoot, state.getBinding((0, sessionKey_1.keyFromString)(threadKeyStr)));
|
|
12240
12394
|
if (decision.kind !== 'proceed')
|
|
@@ -12248,15 +12402,19 @@ function wireScheduler(wiring) {
|
|
|
12248
12402
|
await state.upsertSchedule({ ...record, isCheckFailing: isFailing, updatedAt: new Date().toISOString() });
|
|
12249
12403
|
await state.flush();
|
|
12250
12404
|
},
|
|
12251
|
-
|
|
12252
|
-
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
const alertPinMessageIds = [...(record.alertPinMessageIds ?? []), messageId];
|
|
12256
|
-
await state.upsertSchedule({ ...record, alertPinMessageIds, updatedAt: new Date().toISOString() });
|
|
12257
|
-
// Saved at once, like the failing flag: an id lost in a crash would leave its alert pinned for good.
|
|
12258
|
-
await state.flush();
|
|
12405
|
+
clearAlertPins: (jobId, releasedMessageIds) => (0, store_2.clearCheckAlertPins)(state, jobId, releasedMessageIds),
|
|
12406
|
+
checkIsStatusShown: (threadKeyStr) => {
|
|
12407
|
+
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12408
|
+
return (0, checkStatus_1.checkIsCheckStatusShown)({ isTelegram: (0, sessionKeyCodec_1.checkIsTelegramKey)(key), view: state.getDisplayPrefs(key).view });
|
|
12259
12409
|
},
|
|
12410
|
+
// The status line is the bot's own message: silent (a heartbeat must never notify) and never pinned. Nothing here reaches an agent.
|
|
12411
|
+
postStatus: (threadKeyStr, text) => replyToThread((0, sessionKey_1.keyFromString)(threadKeyStr), text, { disable_notification: true }),
|
|
12412
|
+
readWorkerActivity: async (threadKeyStr, runDir) => {
|
|
12413
|
+
const decision = (0, validation_1.resolveBoundWorkDir)(ENV.workRoot, state.getBinding((0, sessionKey_1.keyFromString)(threadKeyStr)));
|
|
12414
|
+
// A relative run directory is read from the bound folder, like a check command's working directory.
|
|
12415
|
+
return decision.kind === 'proceed' ? (0, workerActivity_1.readWorkerActivity)(path.resolve(decision.workDir, runDir)) : null;
|
|
12416
|
+
},
|
|
12417
|
+
statusIntervalOverrideMs: ENV.testTimings.checkStatusIntervalMs,
|
|
12260
12418
|
});
|
|
12261
12419
|
/**
|
|
12262
12420
|
* The engine's deliver callback: the S4 pipeline plus the S8 unbound-pause
|
|
@@ -12292,11 +12450,9 @@ function wireScheduler(wiring) {
|
|
|
12292
12450
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12293
12451
|
return (0, createAdapter_1.getThreadAdapterNameRaw)(key) ?? state.getAgent(key)?.name;
|
|
12294
12452
|
},
|
|
12295
|
-
unpinMessages:
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
await unpinMessageQuiet(key, messageId);
|
|
12299
|
-
},
|
|
12453
|
+
unpinMessages: unpinThreadMessages,
|
|
12454
|
+
// A cancelled check's status line goes through the same best-effort delete the delivery uses.
|
|
12455
|
+
deleteMessage: checkStatusLinePorts.deleteMessage,
|
|
12300
12456
|
// Routed through the outbound seam: the agent-facing file tool is a
|
|
12301
12457
|
// connector delivery, not a direct call into the Telegram send pipeline.
|
|
12302
12458
|
// The MCP surface is string-keyed (its `threadKey` arrives as text), so the
|
|
@@ -12946,7 +13102,7 @@ async function startBot() {
|
|
|
12946
13102
|
// repaint). A graceful exit already cleared the set in its sweep, so this
|
|
12947
13103
|
// is normally a no-op. Uses the pre-reattach snapshot (the setters clobber
|
|
12948
13104
|
// the live persisted set during reattach).
|
|
12949
|
-
reconcileTransientFrames(orphanedTransientFrames);
|
|
13105
|
+
void reconcileTransientFrames(orphanedTransientFrames).catch((error) => console.error('[reattach] transient frame cleanup failed:', error));
|
|
12950
13106
|
},
|
|
12951
13107
|
// The bot MCP tools that read session state (compact_conversation) wait
|
|
12952
13108
|
// for this: until now a surviving session would read as not running.
|
|
@@ -13167,6 +13323,9 @@ async function startBot() {
|
|
|
13167
13323
|
// A hot worker's reload keeps the sidecar for the next worker to adopt; the supervisor stops it for good.
|
|
13168
13324
|
stopSidecars: (0, installManager_1.checkIsOpenCodeExternalHost)() ? undefined : () => sttOwner.stop(),
|
|
13169
13325
|
cleanupTimers: () => {
|
|
13326
|
+
// Voice notes that have not posted yet stop NOW (timers cleared, unstarted sends cancelled); the cleanup of the ones on
|
|
13327
|
+
// screen or in flight runs on, and the sweep waits for it.
|
|
13328
|
+
void voiceProgressNotes.shutDown();
|
|
13170
13329
|
clearInterval(inMemoryGcInterval);
|
|
13171
13330
|
clearInterval(heartbeatInterval);
|
|
13172
13331
|
clearInterval(fileSweepInterval);
|