charness 3.10.0 → 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 +29 -0
- package/README.md +2 -1
- package/agent-plugin/skills/charness-manager/SKILL.md +6 -5
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +176 -135
- package/dist/bot.js.map +1 -1
- package/dist/connectors/telegram/commands/botCore.d.ts +1 -0
- package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +3 -3
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.js +11 -5
- 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/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 +11 -3
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +11 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +11 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +11 -3
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +11 -3
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +11 -3
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +11 -3
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +11 -3
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +11 -3
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +11 -3
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +11 -3
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +11 -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 +13 -0
- package/dist/outputTrace.js.map +1 -1
- package/dist/runnerUtility/guiAgentHeal.js +2 -2
- package/dist/runnerUtility/guiAgentHeal.js.map +1 -1
- package/dist/runnerUtility/isolatedCommand.d.ts +0 -2
- package/dist/runnerUtility/isolatedCommand.d.ts.map +1 -1
- package/dist/runnerUtility/isolatedCommand.js +4 -11
- package/dist/runnerUtility/isolatedCommand.js.map +1 -1
- package/dist/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 +2 -5
- package/dist/scheduler/checkStatus.d.ts.map +1 -1
- package/dist/scheduler/checkStatus.js +6 -11
- package/dist/scheduler/checkStatus.js.map +1 -1
- package/dist/scheduler/delivery.d.ts +79 -37
- package/dist/scheduler/delivery.d.ts.map +1 -1
- package/dist/scheduler/delivery.js +117 -68
- package/dist/scheduler/delivery.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts +6 -2
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +39 -15
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/scheduler/recurrence.d.ts +32 -0
- package/dist/scheduler/recurrence.d.ts.map +1 -1
- package/dist/scheduler/recurrence.js +56 -18
- package/dist/scheduler/recurrence.js.map +1 -1
- package/dist/scheduler/scheduleText.d.ts +7 -0
- package/dist/scheduler/scheduleText.d.ts.map +1 -0
- package/dist/scheduler/scheduleText.js +55 -0
- package/dist/scheduler/scheduleText.js.map +1 -0
- package/dist/scheduler/store.d.ts +8 -2
- package/dist/scheduler/store.d.ts.map +1 -1
- package/dist/scheduler/store.js +25 -4
- package/dist/scheduler/store.js.map +1 -1
- package/dist/scheduler/types.d.ts +4 -10
- package/dist/scheduler/types.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.d.ts +24 -9
- package/dist/scheduler/workerWatch.d.ts.map +1 -1
- package/dist/scheduler/workerWatch.js +29 -11
- package/dist/scheduler/workerWatch.js.map +1 -1
- 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/stripControlCharacters.d.ts +8 -0
- package/dist/utils/stripControlCharacters.d.ts.map +1 -0
- package/dist/utils/stripControlCharacters.js +16 -0
- package/dist/utils/stripControlCharacters.js.map +1 -0
- package/dist/utils/telegramError.d.ts +6 -0
- package/dist/utils/telegramError.d.ts.map +1 -1
- package/dist/utils/telegramError.js +30 -0
- package/dist/utils/telegramError.js.map +1 -1
- package/dist/utils/topicRequest.d.ts +13 -0
- package/dist/utils/topicRequest.d.ts.map +1 -1
- package/dist/utils/topicRequest.js +10 -0
- package/dist/utils/topicRequest.js.map +1 -1
- package/dist/utils/usageRefreshBudget.d.ts.map +1 -1
- package/dist/utils/usageRefreshBudget.js +4 -10
- package/dist/utils/usageRefreshBudget.js.map +1 -1
- package/dist/utils/waitUpTo.d.ts +8 -0
- package/dist/utils/waitUpTo.d.ts.map +1 -0
- package/dist/utils/waitUpTo.js +20 -0
- package/dist/utils/waitUpTo.js.map +1 -0
- package/package.json +1 -1
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");
|
|
@@ -187,7 +189,7 @@ const updatePolicy_1 = require("./selfUpdate/updatePolicy");
|
|
|
187
189
|
const updateRuntime_1 = require("./selfUpdate/updateRuntime");
|
|
188
190
|
const threadContextPreamble_1 = require("./threadContextPreamble");
|
|
189
191
|
const pinnedBannerSkipDecision_1 = require("./utils/pinnedBannerSkipDecision");
|
|
190
|
-
const
|
|
192
|
+
const messageContext_1 = require("./utils/messageContext");
|
|
191
193
|
const fileIntake_1 = require("./connectors/telegram/fileIntake");
|
|
192
194
|
const mediaGroupCollector_1 = require("./utils/mediaGroupCollector");
|
|
193
195
|
const openCodeSessionTitle_1 = require("./openCodeSessionTitle");
|
|
@@ -850,22 +852,25 @@ const noTopicRequest = { header: '', requestId: null };
|
|
|
850
852
|
* the topic's view has requests on and the text is not a slash command. Called
|
|
851
853
|
* at the USER entry points — text, voice, file, album, `/schedule`, the
|
|
852
854
|
* scheduler's forward — BEFORE the prompt is forwarded or buffered: the ledger
|
|
853
|
-
* keeps the header + text as the request's prompt
|
|
854
|
-
* never took it in), and `createRequest` resolves only once the id is on disk. A
|
|
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
|
|
855
857
|
* conversation of another platform opens its requests itself (Jira: J5). A
|
|
856
858
|
* `null` intake is a prompt that is not a request by rule — an answer to the
|
|
857
859
|
* agent's own question, delivered as a prompt. The intake's requester decides
|
|
858
860
|
* which open request, if any, the new one supersedes (`requestGroup.ts`); the
|
|
859
861
|
* header then names the replaced ones.
|
|
860
862
|
*/
|
|
861
|
-
async function openTopicRequest(key, text, intake) {
|
|
863
|
+
async function openTopicRequest(key, text, intake, messageContext) {
|
|
862
864
|
if (intake === null || !topicRequestLedger || !(0, sessionKeyCodec_1.checkIsTelegramKey)(key))
|
|
863
865
|
return noTopicRequest;
|
|
864
866
|
const view = state.getDisplayPrefs(key).view;
|
|
865
|
-
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0,
|
|
867
|
+
if (!(0, topicRequest_1.checkShouldOpenTopicRequest)(view, (0, messageContext_1.checkIsSlashCommandPrompt)(text, messageContext)))
|
|
866
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);
|
|
867
872
|
const request = await topicRequestLedger.createRequest(key, (0, topicRequest_1.getTopicRequestOrigin)(intake), {
|
|
868
|
-
createPrompt: (requestId, supersededRequestIds) =>
|
|
873
|
+
createPrompt: (requestId, supersededRequestIds) => (0, topicRequest_1.buildTopicRequestPrompt)({ requestId, source: intake.source, view, supersededRequestIds, promptBody }),
|
|
869
874
|
});
|
|
870
875
|
return { header: (0, topicRequest_1.buildTopicRequestHeader)(request.id, intake.source, view, request.supersededRequestIds), requestId: request.id };
|
|
871
876
|
}
|
|
@@ -2430,7 +2435,7 @@ function getThinkingCoalesceState(key) {
|
|
|
2430
2435
|
const k = (0, sessionKey_1.keyToString)(key);
|
|
2431
2436
|
let s = thinkingCoalescers.get(k);
|
|
2432
2437
|
if (!s) {
|
|
2433
|
-
s = {
|
|
2438
|
+
s = { pending: null, inFlight: false, lastSentHtml: null, detachAfterDrain: false };
|
|
2434
2439
|
thinkingCoalescers.set(k, s);
|
|
2435
2440
|
}
|
|
2436
2441
|
return s;
|
|
@@ -2447,7 +2452,7 @@ function clearThinkingMessage(key) {
|
|
|
2447
2452
|
const s = getThreadMessageState(key);
|
|
2448
2453
|
const coalescer = thinkingCoalescers.get((0, sessionKey_1.keyToString)(key));
|
|
2449
2454
|
if (coalescer) {
|
|
2450
|
-
coalescer.
|
|
2455
|
+
coalescer.pending = null;
|
|
2451
2456
|
coalescer.lastSentHtml = null;
|
|
2452
2457
|
coalescer.detachAfterDrain = false;
|
|
2453
2458
|
}
|
|
@@ -2843,6 +2848,10 @@ async function pinMessageQuiet(key, messageId, options) {
|
|
|
2843
2848
|
return false;
|
|
2844
2849
|
}
|
|
2845
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
|
+
}
|
|
2846
2855
|
/**
|
|
2847
2856
|
* @description Unpin `messageId` for `key` through the rate-limit queue,
|
|
2848
2857
|
* swallowing + logging failures (already-unpinned / deleted / lost permission).
|
|
@@ -2852,7 +2861,7 @@ async function unpinMessageQuiet(key, messageId) {
|
|
|
2852
2861
|
if (!checkIsTelegramPrimitiveKey(key, 'unpinMessage'))
|
|
2853
2862
|
return;
|
|
2854
2863
|
try {
|
|
2855
|
-
await (
|
|
2864
|
+
await sendUnpin(key, messageId);
|
|
2856
2865
|
}
|
|
2857
2866
|
catch (e) {
|
|
2858
2867
|
console.warn(`[question-pin] unpin ${(0, sessionKey_1.keyToString)(key)} msg ${messageId} failed: ${describeSendError(e)}`);
|
|
@@ -3155,8 +3164,8 @@ function buildSendExtra(key, extra) {
|
|
|
3155
3164
|
async function replyToThread(key, text, extra = {}, options = {}) {
|
|
3156
3165
|
if (!checkIsTelegramPrimitiveKey(key, 'replyToThread'))
|
|
3157
3166
|
return null;
|
|
3158
|
-
const sendOnce = (sendExtra) => {
|
|
3159
|
-
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key),
|
|
3167
|
+
const sendOnce = (sendExtra, sentText = text) => {
|
|
3168
|
+
const send = () => bot.telegram.sendMessage((0, sessionKeyCodec_1.getTelegramChatId)(key), sentText, sendExtra);
|
|
3160
3169
|
return options.unpaced ? (0, rateLimiter_1.sendUnpaced)(key, send, options.signal) : (0, rateLimiter_1.enqueueSend)(key, send, options.signal);
|
|
3161
3170
|
};
|
|
3162
3171
|
// A sent message is tracked for `/clear_messages`, and a `/bind` picker is remembered to be closed by the next bind or leave.
|
|
@@ -3167,7 +3176,8 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3167
3176
|
openBindMessages.remember((0, sessionKey_1.keyToString)(key), messageId, Date.now());
|
|
3168
3177
|
return messageId;
|
|
3169
3178
|
};
|
|
3170
|
-
|
|
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;
|
|
3171
3181
|
try {
|
|
3172
3182
|
return await trackSent(await sendOnce(buildSendExtra(key, extra)));
|
|
3173
3183
|
}
|
|
@@ -3189,7 +3199,7 @@ async function replyToThread(key, text, extra = {}, options = {}) {
|
|
|
3189
3199
|
const plainExtra = { ...extra };
|
|
3190
3200
|
delete plainExtra.parse_mode;
|
|
3191
3201
|
try {
|
|
3192
|
-
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra)));
|
|
3202
|
+
return await trackSent(await sendOnce(buildSendExtra(key, plainExtra), options.plainFallbackText ?? text));
|
|
3193
3203
|
}
|
|
3194
3204
|
catch (e2) {
|
|
3195
3205
|
await handleSendError(key, e2);
|
|
@@ -3710,7 +3720,7 @@ async function sendOutputImmediate(key, output, isContinuation = false, startsNe
|
|
|
3710
3720
|
let startIndex = 0;
|
|
3711
3721
|
if (shouldEditFirstChunk) {
|
|
3712
3722
|
const editedOk = chunks[0] === msgState.lastMessageText ||
|
|
3713
|
-
(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]));
|
|
3714
3724
|
if (editedOk) {
|
|
3715
3725
|
msgState.lastMessageText = chunks[0];
|
|
3716
3726
|
startIndex = 1;
|
|
@@ -3747,7 +3757,8 @@ async function replyChunkWithFallback(key, renderedHtml, plainFallback, replyMar
|
|
|
3747
3757
|
if (!checkIsTelegramPrimitiveKey(key, 'replyChunkWithFallback'))
|
|
3748
3758
|
return null;
|
|
3749
3759
|
const markupExtra = replyMarkup ? { reply_markup: replyMarkup } : {};
|
|
3750
|
-
|
|
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 });
|
|
3751
3762
|
if (id)
|
|
3752
3763
|
return id;
|
|
3753
3764
|
return replyToThread(key, plainFallback, markupExtra);
|
|
@@ -4856,7 +4867,7 @@ async function forwardPromptToAgent(key, adapter, text, sentAtMs, options = {})
|
|
|
4856
4867
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
4857
4868
|
checkIsSessionActive: () => adapter.checkIsActive(key) && !(isTechnicalPrompt && (adapter.checkIsBusy?.(key) ?? false)),
|
|
4858
4869
|
buffer: async () => {
|
|
4859
|
-
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${
|
|
4870
|
+
await deliverPromptOrBuffer(key, `${options.requestHeader ?? ''}${getPromptWithThreadMessageContext(key, text, options.messageContext)}`, true);
|
|
4860
4871
|
},
|
|
4861
4872
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
4862
4873
|
forward: async () => {
|
|
@@ -4878,11 +4889,14 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4878
4889
|
// A forwarded prompt is thread activity — reset the compact-on-idle watchdog (F2).
|
|
4879
4890
|
noteThreadActivity(key);
|
|
4880
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);
|
|
4881
4895
|
// Skip slash commands (not worth replaying), the recovery replay itself (keeps
|
|
4882
4896
|
// the once-per-episode guard intact), a request reminder (the request's own
|
|
4883
4897
|
// prompt stays the one to replay) and a bot-made technical prompt.
|
|
4884
4898
|
const isReplayable = (0, wedgeRecovery_1.checkIsReplayablePrompt)({
|
|
4885
|
-
isSlashCommand
|
|
4899
|
+
isSlashCommand,
|
|
4886
4900
|
isRecoveryReplay: options.isRecoveryReplay ?? false,
|
|
4887
4901
|
isRequestReminder: options.isRequestReminder ?? false,
|
|
4888
4902
|
isTechnicalPrompt,
|
|
@@ -4891,19 +4905,21 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4891
4905
|
// forwarded to a live session once no wait holds them — after it, in arrival
|
|
4892
4906
|
// order (the resume's, the operator's message that ended the wait, a later
|
|
4893
4907
|
// post). Only a replayable one carries them, so a wedge recovery replays them too.
|
|
4894
|
-
|
|
4895
|
-
//
|
|
4896
|
-
//
|
|
4897
|
-
//
|
|
4898
|
-
//
|
|
4899
|
-
//
|
|
4900
|
-
//
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
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,
|
|
4904
4919
|
isShellInput: adapter.name === 'terminal',
|
|
4905
4920
|
});
|
|
4906
|
-
|
|
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
|
|
4907
4923
|
// unlike the once-per-change thread preamble: it names THIS message's request.
|
|
4908
4924
|
const messageBody = options.requestHeader ? `${options.requestHeader}${quotedBody}` : quotedBody;
|
|
4909
4925
|
// A loss the agent was not told about yet (`utils/lostWork.ts`) rides the first real prompt, once, ahead of it.
|
|
@@ -4931,13 +4947,13 @@ async function forwardPromptToLiveAgent(key, adapter, text, sentAtMs, options =
|
|
|
4931
4947
|
// (scheduled runs, buffered replay, api-retry nudge, file intake) fall back
|
|
4932
4948
|
// to now. Slash commands skip it for the same reason they skip the preamble.
|
|
4933
4949
|
let promptText = getPromptWithThreadContext(key, body);
|
|
4934
|
-
if (state.checkIsTimestampsEnabled(key) && !
|
|
4950
|
+
if (state.checkIsTimestampsEnabled(key) && !isSlashCommand) {
|
|
4935
4951
|
promptText = `${(0, isoTimestamp_1.formatIsoLocalOffset)(sentAtMs ?? Date.now())}\n\n${promptText}`;
|
|
4936
4952
|
}
|
|
4937
4953
|
// The project board rides every turn start the bot makes (D20: whole on a fresh context, else only what changed),
|
|
4938
4954
|
// then the todo list's staleness reminder rides the next real prompt from any source (D11 form a) — never a slash
|
|
4939
4955
|
// command or a shell line; the reminder never rides the standalone reminder itself.
|
|
4940
|
-
const isTodoDecorated = !
|
|
4956
|
+
const isTodoDecorated = !isSlashCommand && adapter.name !== 'terminal';
|
|
4941
4957
|
if (isTodoDecorated)
|
|
4942
4958
|
discardTodoInbox(key);
|
|
4943
4959
|
const todoBoardBlock = isTodoDecorated ? takeTodoPromptBoard(key) : null;
|
|
@@ -5036,16 +5052,17 @@ function getPromptWithThreadContext(key, text) {
|
|
|
5036
5052
|
}
|
|
5037
5053
|
/**
|
|
5038
5054
|
* @description Bridge a telegraf message (text, voice, or a file) to the
|
|
5039
|
-
* agent-facing
|
|
5055
|
+
* agent-facing message-context block. When the operator uses Telegram's REPLY
|
|
5040
5056
|
* feature, this folds the replied-to message's content into the forwarded prompt
|
|
5041
|
-
* 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`
|
|
5042
5059
|
* when there is nothing to inject — the connector's
|
|
5043
|
-
* {@link
|
|
5060
|
+
* {@link getTelegramMessageContext} decides. The bot's own id
|
|
5044
5061
|
* (`bot.botInfo.id`) drives the `from: assistant` attribution; a replied-to file
|
|
5045
5062
|
* is looked up among the files this thread took in.
|
|
5046
5063
|
*/
|
|
5047
|
-
function
|
|
5048
|
-
return (0, inbound_1.
|
|
5064
|
+
function getMessageContext(key, message) {
|
|
5065
|
+
return (0, inbound_1.getTelegramMessageContext)(message, { userId: bot.botInfo?.id }, (meta) => findThreadSavedFile(key, meta));
|
|
5049
5066
|
}
|
|
5050
5067
|
/**
|
|
5051
5068
|
* @description The bot's saved copy of a file sent to this thread earlier
|
|
@@ -5065,16 +5082,15 @@ function findThreadSavedFile(key, meta) {
|
|
|
5065
5082
|
return name === undefined ? undefined : path.join(dir, name);
|
|
5066
5083
|
}
|
|
5067
5084
|
/**
|
|
5068
|
-
* @description Fold a
|
|
5085
|
+
* @description Fold a message-context block into a prompt that leaves as finished
|
|
5069
5086
|
* text through {@link deliverPromptOrBuffer} — one buffered behind a session
|
|
5070
5087
|
* start, whose replay forwards it as is, or a file announcement — by the one
|
|
5071
5088
|
* rule `forwardPromptToAgent` applies to a live prompt. The thread's adapter is
|
|
5072
5089
|
* the one the text reaches, so a terminal keeps the block out of its shell line.
|
|
5073
5090
|
*/
|
|
5074
|
-
function
|
|
5075
|
-
return (0,
|
|
5076
|
-
|
|
5077
|
-
isSlashCommand: (0, threadContextPreamble_1.checkShouldSkipPreambleForText)(text),
|
|
5091
|
+
function getPromptWithThreadMessageContext(key, text, messageContext) {
|
|
5092
|
+
return (0, messageContext_1.getPromptWithMessageContext)(text, {
|
|
5093
|
+
context: messageContext,
|
|
5078
5094
|
isShellInput: (0, createAdapter_1.getThreadAdapter)(key).name === 'terminal',
|
|
5079
5095
|
});
|
|
5080
5096
|
}
|
|
@@ -6054,7 +6070,11 @@ command('whoami', async (ctx, key) => {
|
|
|
6054
6070
|
* locked by `ALLOWED_GROUP_ID` env. Only a creator/administrator of the target
|
|
6055
6071
|
* group may pair, so a random group can't hijack the binding.
|
|
6056
6072
|
*/
|
|
6057
|
-
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();
|
|
6058
6078
|
const userId = ctx.from?.id;
|
|
6059
6079
|
if (!userId)
|
|
6060
6080
|
return;
|
|
@@ -6798,8 +6818,9 @@ const claudeUsageRefresher = (0, claudeUsageRefresher_1.createClaudeUsageRefresh
|
|
|
6798
6818
|
getSnapshot: (name) => state.getClaudeProfileInfo(name)?.usage,
|
|
6799
6819
|
saveSnapshot: (name, snapshot) => state.setClaudeProfileUsage(name, snapshot),
|
|
6800
6820
|
readToken: (configDir) => (0, claudeUsage_1.readClaudeOAuthToken)(configDir),
|
|
6801
|
-
fetchUsage: (accessToken) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken),
|
|
6821
|
+
fetchUsage: (accessToken, signal) => (0, claudeUsage_1.fetchClaudeUsage)(accessToken, { signal }),
|
|
6802
6822
|
refreshOpenCode: (options) => openCodeUsagePoller.refreshAll(options),
|
|
6823
|
+
markOpenCodeStale: (reason) => openCodeUsagePoller.markAllStale(reason),
|
|
6803
6824
|
});
|
|
6804
6825
|
/** The profile that owns a config directory (`null` = default); `null` for a directory outside the profiles root. */
|
|
6805
6826
|
function resolveClaudeProfileNameForDir(configDir) {
|
|
@@ -7004,8 +7025,9 @@ async function planFallbackSwitch(key, cls, episodeId) {
|
|
|
7004
7025
|
fallbackMs: apiErrorRetry_1.usageLimitDefaultMs,
|
|
7005
7026
|
}));
|
|
7006
7027
|
}
|
|
7007
|
-
// The Claude rungs are judged on fresh figures whatever backend hit the limit (a minute's cache)
|
|
7008
|
-
|
|
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));
|
|
7009
7031
|
const detection = await detectFallbackOptions();
|
|
7010
7032
|
let chain = state.getFallbackChain();
|
|
7011
7033
|
if (chain.length === 0 && from.backend === 'claude') {
|
|
@@ -7464,7 +7486,9 @@ async function takeFallbackSwitchOffer(key, episodeId, index) {
|
|
|
7464
7486
|
/**
|
|
7465
7487
|
* The `claude_profiles` MCP tool's answer: snapshots refreshed on demand (a minute's cache; the account a resumed session
|
|
7466
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.
|
|
7467
|
-
* 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).
|
|
7468
7492
|
*/
|
|
7469
7493
|
async function listClaudeProfilesForAgent(query) {
|
|
7470
7494
|
await (0, claudeUsageRefresher_1.refreshClaudeUsageForLaunch)(claudeUsageRefresher, { currentProfile: query.currentProfile, isStoppedByLimit: query.isStoppedByLimit, maxAgeMs: claudeUsageRefresher_1.claudeUsageOnDemandMaxAgeMs });
|
|
@@ -8189,8 +8213,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8189
8213
|
// back when that one was still forwarded).
|
|
8190
8214
|
const text = (0, utils_1.stripCommandBotMention)(ctx.message.text.trim());
|
|
8191
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('/');
|
|
8192
8221
|
// Slash commands we don't own → forward to the agent (e.g. `/context`, `/help`).
|
|
8193
|
-
if (
|
|
8222
|
+
if (isSlashText) {
|
|
8194
8223
|
const cmd = text.slice(1).split(' ')[0].split('@')[0].toLowerCase();
|
|
8195
8224
|
// A slash command ends a pending «Add account» name prompt (the command itself runs normally).
|
|
8196
8225
|
cancelProfileNameCapture(key);
|
|
@@ -8228,7 +8257,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8228
8257
|
// keeps a message typed in the pre-URL boot window from being swallowed/deleted
|
|
8229
8258
|
// as a code. A slash command falls through (so /quit, /new, etc. still run and
|
|
8230
8259
|
// their teardown cancels the pending login; /esc cancels it outright).
|
|
8231
|
-
if (checkIsAuthLoginAwaitingCode(key) && !
|
|
8260
|
+
if (checkIsAuthLoginAwaitingCode(key) && !isSlashText) {
|
|
8232
8261
|
await submitClaudeAuthLoginCode(key, text, ctx.message.message_id);
|
|
8233
8262
|
return;
|
|
8234
8263
|
}
|
|
@@ -8238,25 +8267,25 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8238
8267
|
// a secret; NOT recognised → the flow stays armed and hints (never forwarded
|
|
8239
8268
|
// to the agent). A slash command falls through so /quit, /new, etc. still run
|
|
8240
8269
|
// + cancel the flow.
|
|
8241
|
-
if (checkIsOpenCodeOAuthAwaitingReply(key) && !
|
|
8270
|
+
if (checkIsOpenCodeOAuthAwaitingReply(key) && !isSlashText) {
|
|
8242
8271
|
await submitOpenCodeOAuthReply(key, text, ctx.message.message_id);
|
|
8243
8272
|
return;
|
|
8244
8273
|
}
|
|
8245
8274
|
// `/account` «Add» asked for the new profile's name → this message is it (a bad name keeps the prompt
|
|
8246
8275
|
// armed and says so; a slash command above already disarmed it).
|
|
8247
|
-
if (checkIsAwaitingProfileName(key) && !
|
|
8276
|
+
if (checkIsAwaitingProfileName(key) && !isSlashText) {
|
|
8248
8277
|
await submitProfileName(key, text, ctx.message.message_id);
|
|
8249
8278
|
return;
|
|
8250
8279
|
}
|
|
8251
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
|
|
8252
8281
|
// name keeps the prompt armed and says so; a slash command above already ended it).
|
|
8253
|
-
if (checkIsAwaitingTopicInput(key) && !
|
|
8282
|
+
if (checkIsAwaitingTopicInput(key) && !isSlashText) {
|
|
8254
8283
|
await submitTopicInput(key, text);
|
|
8255
8284
|
return;
|
|
8256
8285
|
}
|
|
8257
8286
|
// `/stt` asked for a server address or an API key → this message is the answer. A plausible key is deleted at
|
|
8258
8287
|
// once and never echoed; anything else re-arms the step. A slash command above already disarmed it.
|
|
8259
|
-
if (getAwaitedSttStep(key) !== null && !
|
|
8288
|
+
if (getAwaitedSttStep(key) !== null && !isSlashText) {
|
|
8260
8289
|
await submitSttInput(key, text, ctx.message.message_id);
|
|
8261
8290
|
return;
|
|
8262
8291
|
}
|
|
@@ -8265,13 +8294,13 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8265
8294
|
// must NOT be forwarded to the agent as a prompt — that both leaks the code
|
|
8266
8295
|
// into the transcript and produced the confusing header error (live
|
|
8267
8296
|
// 2026-07-20). Delete it as a secret and hint to re-run /connect.
|
|
8268
|
-
if (!
|
|
8297
|
+
if (!isSlashText && (0, openCodeAuthLogin_1.parseOAuthCallbackFromReply)(text)) {
|
|
8269
8298
|
await deleteThreadMessage(key, ctx.message.message_id);
|
|
8270
8299
|
await replyToThread(key, (0, i18n_1.t)('connect.oauth_callback_no_flow'));
|
|
8271
8300
|
return;
|
|
8272
8301
|
}
|
|
8273
8302
|
const pendingProviderConnect = pendingProviderConnects.get(kStr);
|
|
8274
|
-
if (pendingProviderConnect &&
|
|
8303
|
+
if (pendingProviderConnect && isSlashText) {
|
|
8275
8304
|
pendingProviderConnects.delete(kStr);
|
|
8276
8305
|
await replyToThread(key, (0, i18n_1.t)('connect.cancelled'));
|
|
8277
8306
|
}
|
|
@@ -8291,7 +8320,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8291
8320
|
// one wizard yields exactly one reminder.
|
|
8292
8321
|
const reminderTextRoute = claimReminderTextCapture(key);
|
|
8293
8322
|
if (reminderTextRoute === 'capture' || reminderTextRoute === 'expired') {
|
|
8294
|
-
if (
|
|
8323
|
+
if (isSlashText) {
|
|
8295
8324
|
await cancelReminderWizard(key);
|
|
8296
8325
|
}
|
|
8297
8326
|
else if (reminderTextRoute === 'expired') {
|
|
@@ -8308,7 +8337,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8308
8337
|
// Session is mid-startup → buffer the prompt and replay it once the agent is
|
|
8309
8338
|
// ready, instead of dropping it into the "no agent running" guidance below.
|
|
8310
8339
|
if (startupPromptBuffer.checkIsStarting(kStr)) {
|
|
8311
|
-
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));
|
|
8312
8341
|
return;
|
|
8313
8342
|
}
|
|
8314
8343
|
// Set when this very message bound the topic: its welcome is already the answer, so the idle-thread hint at the end
|
|
@@ -8369,14 +8398,14 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8369
8398
|
// natural-language start + forwarded to the agent. `applyNumberedModelPick`
|
|
8370
8399
|
// always replies (even for the unsupported case), so we always return after a
|
|
8371
8400
|
// numeric pick — the user clearly intended a model pick, not a prompt.
|
|
8372
|
-
if (/^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8401
|
+
if (!isForwarded && /^\d+$/.test(text) && awaitingModelSelection.has(kStr)) {
|
|
8373
8402
|
await applyNumberedModelPick(adapter, key, parseInt(text, 10));
|
|
8374
8403
|
return;
|
|
8375
8404
|
}
|
|
8376
8405
|
// Session-pick mode (armed by `/sessions` / `/resume`). Only while the
|
|
8377
8406
|
// thread is armed is a bare digit treated as a pick — a normal numeric
|
|
8378
8407
|
// prompt is never hijacked. See `checkSessionPickAction` for the rules.
|
|
8379
|
-
if (awaitingSessionSelection.has(kStr)) {
|
|
8408
|
+
if (!isForwarded && awaitingSessionSelection.has(kStr)) {
|
|
8380
8409
|
const sessionList = threadSessionLists.get(kStr) ?? [];
|
|
8381
8410
|
const pick = (0, sessionPick_1.checkSessionPickAction)(text, sessionList.length);
|
|
8382
8411
|
if (pick.kind === 'invalid') {
|
|
@@ -8402,7 +8431,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8402
8431
|
awaitingSessionSelection.delete(kStr);
|
|
8403
8432
|
}
|
|
8404
8433
|
// Natural-language start.
|
|
8405
|
-
if (!adapter.checkIsActive(key)) {
|
|
8434
|
+
if (!isForwarded && !adapter.checkIsActive(key)) {
|
|
8406
8435
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(text);
|
|
8407
8436
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8408
8437
|
if (checkIsGeneral(key)) {
|
|
@@ -8448,7 +8477,7 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8448
8477
|
// never surfaced, so a bare digit during a survey window is NOT a route here —
|
|
8449
8478
|
// it falls through to the normal prompt path instead of being dropped.
|
|
8450
8479
|
const replyRoute = (0, claudeCliAdapter_1.getClaudeReplyRoute)({
|
|
8451
|
-
isQuestionPending: adapter.isQuestionPending?.(key) ?? false,
|
|
8480
|
+
isQuestionPending: !isForwarded && (adapter.isQuestionPending?.(key) ?? false),
|
|
8452
8481
|
isLoginPastePending: adapter.isLoginPastePending?.(key) ?? false,
|
|
8453
8482
|
text,
|
|
8454
8483
|
});
|
|
@@ -8483,16 +8512,16 @@ bot.on((0, filters_1.message)('text'), async (ctx) => {
|
|
|
8483
8512
|
// branches above already returned for their own cases, so this is reached only
|
|
8484
8513
|
// for a generic active prompt. The message's real send time (Telegram `date`,
|
|
8485
8514
|
// unix seconds) rides along for the `/timestamps` injection, and a Telegram
|
|
8486
|
-
// REPLY folds
|
|
8515
|
+
// REPLY or FORWARD folds its context into the prompt (see `getMessageContext`).
|
|
8487
8516
|
if (adapter.checkIsActive(key)) {
|
|
8488
|
-
const
|
|
8489
|
-
await deliverActivePrompt(key, adapter, text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
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);
|
|
8490
8519
|
return;
|
|
8491
8520
|
}
|
|
8492
8521
|
// A sleeping conversation (its process stopped, its session kept) is resumed by
|
|
8493
8522
|
// the message itself (L-D4) — the prompt continues the same conversation.
|
|
8494
8523
|
if (await resumeSleepingSessionForPrompt(key)) {
|
|
8495
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), text, { source: 'text', requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from) }, ctx.message.date * 1000,
|
|
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));
|
|
8496
8525
|
return;
|
|
8497
8526
|
}
|
|
8498
8527
|
// Idle thread — guide the user. Three sub-states:
|
|
@@ -8543,16 +8572,16 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8543
8572
|
const fileId = ctx.message.voice.file_id;
|
|
8544
8573
|
const durationSeconds = ctx.message.voice.duration;
|
|
8545
8574
|
const sentAtMs = ctx.message.date * 1000;
|
|
8546
|
-
// A Telegram REPLY on the voice note folds the quoted message into the prompt
|
|
8547
|
-
// Compute it HERE (only the handler has
|
|
8548
|
-
// update loop and only sees `key`/`bot`.
|
|
8549
|
-
const
|
|
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);
|
|
8550
8579
|
// Armed LAST, right before the job is queued: nothing between here and the queue may throw and strand an armed note. The
|
|
8551
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
|
|
8552
8581
|
// the moment its text arrives, and the `finally` is the backstop for a job that never ran or ended some other way.
|
|
8553
8582
|
const progressNote = startVoiceProgressNote(key);
|
|
8554
8583
|
void (0, voiceQueue_1.getVoiceTranscriptionQueue)(key)
|
|
8555
|
-
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), warmedEndpoint, progressNote, sentAtMs,
|
|
8584
|
+
.run(() => processVoiceJob(key, fileId, durationSeconds, (0, topicRequest_1.getTopicRequesterId)(ctx.from), warmedEndpoint, progressNote, sentAtMs, messageContext))
|
|
8556
8585
|
.catch((err) => {
|
|
8557
8586
|
console.error('[Bot] Voice job error (already handled):', err);
|
|
8558
8587
|
})
|
|
@@ -8566,9 +8595,9 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8566
8595
|
* Uses only `key`/`bot`, never the request `ctx`, so it survives past the
|
|
8567
8596
|
* handler's return. `sentAtMs` is the voice note's real Telegram send time,
|
|
8568
8597
|
* captured by the handler for the `/timestamps` injection (transcription can
|
|
8569
|
-
* take ~20s, so "now" at forward time would drift). `
|
|
8570
|
-
*
|
|
8571
|
-
* the voice note), plumbed here since the job no longer has `ctx`; so is
|
|
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
|
|
8572
8601
|
* `requesterId`, the sender the transcript's request is filed under, and
|
|
8573
8602
|
* `warmedEndpoint`, the first engine's endpoint asked for when the note arrived
|
|
8574
8603
|
* (the job reuses that one ask — see `warmUpFirstEngine`), and `progressNote`, the
|
|
@@ -8576,7 +8605,7 @@ bot.on((0, filters_1.message)('voice'), async (ctx) => {
|
|
|
8576
8605
|
* text is here or the voice failed — BEFORE the echo or the failure notice, never
|
|
8577
8606
|
* at the end of the job (delivering the prompt may take long).
|
|
8578
8607
|
*/
|
|
8579
|
-
async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmedEndpoint, progressNote, sentAtMs,
|
|
8608
|
+
async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmedEndpoint, progressNote, sentAtMs, messageContext) {
|
|
8580
8609
|
try {
|
|
8581
8610
|
// Audit S14 / #33: `getFileLink` builds the bot-token URL in one
|
|
8582
8611
|
// place inside Telegraf instead of us materialising the token in a
|
|
@@ -8635,10 +8664,11 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmed
|
|
|
8635
8664
|
await expireReminderWizard(key);
|
|
8636
8665
|
// Session is mid-startup → buffer the transcript and replay it once ready.
|
|
8637
8666
|
if (startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key))) {
|
|
8638
|
-
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId },
|
|
8667
|
+
await bufferPromptDuringStartup(key, transcript, { source: 'voice', requesterId }, messageContext);
|
|
8639
8668
|
return;
|
|
8640
8669
|
}
|
|
8641
|
-
|
|
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)) {
|
|
8642
8672
|
const startMatch = (0, agentTrigger_1.parseAgentTrigger)(transcript);
|
|
8643
8673
|
if (startMatch.isMatch && startMatch.adapterName) {
|
|
8644
8674
|
if (checkIsGeneral(key)) {
|
|
@@ -8688,7 +8718,7 @@ async function processVoiceJob(key, fileId, durationSeconds, requesterId, warmed
|
|
|
8688
8718
|
// delivered as a fresh prompt — closing the gap where voice queued behind a
|
|
8689
8719
|
// blocked question-turn and the user got no reply.
|
|
8690
8720
|
// Read AFTER the wake: the resume may have switched the thread's adapter.
|
|
8691
|
-
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs,
|
|
8721
|
+
await deliverActivePrompt(key, (0, createAdapter_1.getThreadAdapter)(key), transcript, { source: 'voice', requesterId }, sentAtMs, messageContext);
|
|
8692
8722
|
}
|
|
8693
8723
|
catch (err) {
|
|
8694
8724
|
console.error('[Bot] Voice handling error:', err);
|
|
@@ -8841,7 +8871,7 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8841
8871
|
const orderedItems = [...items].sort((a, b) => a.messageId - b.messageId);
|
|
8842
8872
|
const files = orderedItems.map((item) => item.albumFile);
|
|
8843
8873
|
const caption = orderedItems.find((item) => item.caption && item.caption.trim())?.caption;
|
|
8844
|
-
const
|
|
8874
|
+
const messageContext = orderedItems.find((item) => item.messageContext)?.messageContext;
|
|
8845
8875
|
const promptText = (0, fileIntake_1.buildAlbumPromptText)(files, caption);
|
|
8846
8876
|
const isStarting = startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key));
|
|
8847
8877
|
// User took over (album upload) before a pending API-error retry fired →
|
|
@@ -8850,8 +8880,8 @@ const albumCollector = (0, mediaGroupCollector_1.createMediaGroupCollector)({
|
|
|
8850
8880
|
// A user album is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8851
8881
|
notePersonActivity(key);
|
|
8852
8882
|
try {
|
|
8853
|
-
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId });
|
|
8854
|
-
const quotedPrompt =
|
|
8883
|
+
const opening = await openTopicRequest(key, promptText, { source: 'album', requesterId: orderedItems[0].requesterId }, messageContext);
|
|
8884
|
+
const quotedPrompt = getPromptWithThreadMessageContext(key, promptText, messageContext);
|
|
8855
8885
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8856
8886
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8857
8887
|
}
|
|
@@ -8903,7 +8933,7 @@ async function handleAlbumFile(ctx, key, meta, mediaGroupId) {
|
|
|
8903
8933
|
messageId: ctx.message.message_id,
|
|
8904
8934
|
albumFile: { kind: meta.kind, savedPath, fileSize: meta.fileSize },
|
|
8905
8935
|
caption: meta.caption,
|
|
8906
|
-
|
|
8936
|
+
messageContext: getMessageContext(key, ctx.message),
|
|
8907
8937
|
requesterId: (0, topicRequest_1.getTopicRequesterId)(ctx.from),
|
|
8908
8938
|
});
|
|
8909
8939
|
}
|
|
@@ -8933,9 +8963,10 @@ async function handleIncomingFile(ctx, key) {
|
|
|
8933
8963
|
cancelApiRetry(key);
|
|
8934
8964
|
// A user file is genuine user activity → clear the compact-on-idle latch (D2).
|
|
8935
8965
|
notePersonActivity(key);
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
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);
|
|
8939
8970
|
const delivery = await deliverPromptOrBuffer(key, `${opening.header}${quotedPrompt}`, isStarting);
|
|
8940
8971
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
8941
8972
|
}
|
|
@@ -9614,20 +9645,21 @@ bot.action(/^qa_(\d+)_(\d+)$/, async (ctx) => {
|
|
|
9614
9645
|
* @description Buffer a free-form prompt (text OR voice) that arrived while the
|
|
9615
9646
|
* thread's session is starting — the startup twin of {@link deliverActivePrompt}.
|
|
9616
9647
|
* The request is opened at capture time (S7), so the buffered text carries its
|
|
9617
|
-
* header; the
|
|
9618
|
-
* the buffered text as is and a REPLY made during the boot would
|
|
9619
|
-
* the agent without the message it points at.
|
|
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.
|
|
9620
9651
|
*/
|
|
9621
|
-
async function bufferPromptDuringStartup(key, text, intake,
|
|
9622
|
-
// The same for a bare option number typed in that window: it answers the question asked again.
|
|
9623
|
-
|
|
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))
|
|
9624
9656
|
return;
|
|
9625
9657
|
// A person wrote, in a window where the session is starting or being stopped: it counts like a message that reaches
|
|
9626
9658
|
// `deliverActivePrompt` — the idle latch clears, and a question the idle compaction re-asked is closed (the idle fire
|
|
9627
9659
|
// posts it just before the stop, so this window is where a message instead of a tap most often lands).
|
|
9628
9660
|
notePersonActivity(key);
|
|
9629
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9630
|
-
const quotedText =
|
|
9661
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9662
|
+
const quotedText = getPromptWithThreadMessageContext(key, text, messageContext);
|
|
9631
9663
|
await deliverPromptOrBuffer(key, `${opening.header}${quotedText}`, true);
|
|
9632
9664
|
trackTopicRequestTurn(key, opening);
|
|
9633
9665
|
}
|
|
@@ -9648,9 +9680,11 @@ async function bufferPromptDuringStartup(key, text, intake, replyContext) {
|
|
|
9648
9680
|
* `answerQuestion`). The tmux-scrape Claude and the terminal never reach it (no `pendingQuestions` entry): for them
|
|
9649
9681
|
* `forwardPromptToAgent` interrupts the TUI selector itself.
|
|
9650
9682
|
*/
|
|
9651
|
-
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;
|
|
9652
9686
|
// A bare option number answers the question the idle compaction asked again (a tap's own label comes in with no intake).
|
|
9653
|
-
if (intake !== null && await answerReAskedQuestionByNumber(key, text))
|
|
9687
|
+
if (intake !== null && !isForwarded && await answerReAskedQuestionByNumber(key, text))
|
|
9654
9688
|
return null;
|
|
9655
9689
|
// A genuine USER message (text or voice) — clear the compact-on-idle latch so
|
|
9656
9690
|
// the next idle period can compact again (D2), whether it answers a pending
|
|
@@ -9660,16 +9694,17 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9660
9694
|
if (pending && adapter.answerQuestion) {
|
|
9661
9695
|
const currentQuestion = pending.data.questions[pending.currentIndex];
|
|
9662
9696
|
const route = (0, openCodeQuestionFlow_1.getQuestionReplyRoute)(text, currentQuestion);
|
|
9663
|
-
if (route.kind === 'answer') {
|
|
9697
|
+
if (route.kind === 'answer' && !isForwarded) {
|
|
9664
9698
|
// Answering a pending question (bare digit) is a pick, not a prompt about
|
|
9665
9699
|
// the quote — the reply context is deliberately dropped here. Not a request
|
|
9666
|
-
// 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.
|
|
9667
9702
|
await applyQuestionAnswer(key, route.labels);
|
|
9668
9703
|
return null;
|
|
9669
9704
|
}
|
|
9670
9705
|
// Free-form text cancels the question and is a fresh prompt — a request (S7).
|
|
9671
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9672
|
-
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9706
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9707
|
+
const delivery = await cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, opening.header);
|
|
9673
9708
|
await settleTopicRequestAfterDelivery(key, opening, delivery);
|
|
9674
9709
|
return null;
|
|
9675
9710
|
}
|
|
@@ -9678,7 +9713,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9678
9713
|
// before forwarding — the slash text itself never gets a preamble. The agent's
|
|
9679
9714
|
// context is gone, so any intake files it might reference are now useless —
|
|
9680
9715
|
// purge the thread's files dir in the same breath.
|
|
9681
|
-
if (text === forwardedClearCommand) {
|
|
9716
|
+
if (text === forwardedClearCommand && !isForwarded) {
|
|
9682
9717
|
clearThreadContextMarker(key);
|
|
9683
9718
|
await (0, botFileStorage_1.purgeThreadFiles)(getDataDir(), key).catch((e) => console.warn(`[file] purge on /clear failed for ${(0, sessionKey_1.keyToString)(key)}:`, e));
|
|
9684
9719
|
}
|
|
@@ -9697,7 +9732,7 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9697
9732
|
// The request (S7) is opened AFTER the user takeover cancelled an armed limit
|
|
9698
9733
|
// wait (the handlers' `cancelApiRetry`) and before the forward, so its id is
|
|
9699
9734
|
// durable by the time the agent reads it.
|
|
9700
|
-
const opening = await openTopicRequest(key, text, intake);
|
|
9735
|
+
const opening = await openTopicRequest(key, text, intake, messageContext);
|
|
9701
9736
|
// Routed now, not when the message arrived: the idle stop may have begun or ended during the awaits since.
|
|
9702
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;
|
|
9703
9738
|
// it has told the person already (`forwardPromptToAgent`), so what is left here is the request this prompt opened.
|
|
@@ -9705,10 +9740,10 @@ async function deliverActivePrompt(key, adapter, text, intake, sentAtMs, replyCo
|
|
|
9705
9740
|
checkIsWindowOpen: () => startupPromptBuffer.checkIsStarting((0, sessionKey_1.keyToString)(key)),
|
|
9706
9741
|
checkIsSessionActive: () => adapter.checkIsActive(key),
|
|
9707
9742
|
buffer: async () => {
|
|
9708
|
-
await deliverPromptOrBuffer(key, `${opening.header}${
|
|
9743
|
+
await deliverPromptOrBuffer(key, `${opening.header}${getPromptWithThreadMessageContext(key, text, messageContext)}`, true);
|
|
9709
9744
|
},
|
|
9710
9745
|
wake: () => wakeSleepingSessionForPrompt(key),
|
|
9711
|
-
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 }),
|
|
9712
9747
|
reportNoSession: async (isAlreadyTold) => {
|
|
9713
9748
|
if (!isAlreadyTold)
|
|
9714
9749
|
await replyToThread(key, (0, i18n_1.t)('agent.no_session'));
|
|
@@ -9756,7 +9791,7 @@ function retirePendingQuestionInBackground(key) {
|
|
|
9756
9791
|
* close it on the server, abort the wedged OpenCode turn (`SIGINT` → `/session/:id/
|
|
9757
9792
|
* abort`), post the "previous question cancelled" notice, then forward.
|
|
9758
9793
|
*/
|
|
9759
|
-
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs,
|
|
9794
|
+
async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, messageContext, requestHeader) {
|
|
9760
9795
|
// When the question bubble itself was closed with its «not answered» note, that IS the
|
|
9761
9796
|
// cancellation notice — a second standalone "previous question cancelled" line is
|
|
9762
9797
|
// pure noise (the reported triple message). The standalone notice is kept only
|
|
@@ -9775,7 +9810,7 @@ async function cancelPendingQuestionAndForward(key, adapter, text, sentAtMs, rep
|
|
|
9775
9810
|
if (!didLabelQuestionMessage) {
|
|
9776
9811
|
await replyToThread(key, (0, i18n_1.t)('agent.question_cancelled_for_prompt'));
|
|
9777
9812
|
}
|
|
9778
|
-
return forwardPromptToAgent(key, adapter, text, sentAtMs, {
|
|
9813
|
+
return forwardPromptToAgent(key, adapter, text, sentAtMs, { messageContext, requestHeader });
|
|
9779
9814
|
}
|
|
9780
9815
|
/**
|
|
9781
9816
|
* @description Record one answer for the CURRENTLY shown OpenCode question and
|
|
@@ -10174,7 +10209,7 @@ async function sendStatusFrame(key, status) {
|
|
|
10174
10209
|
const editId = msgState.statusMessageId;
|
|
10175
10210
|
const ok = await editThreadMessage(key, editId, firstRendered, {
|
|
10176
10211
|
parse_mode: 'HTML',
|
|
10177
|
-
});
|
|
10212
|
+
}, chunks[0]);
|
|
10178
10213
|
// A delete that landed during the edit already nulled (or replaced) the id;
|
|
10179
10214
|
// don't claim the frame as live — let the create path below re-evaluate.
|
|
10180
10215
|
if (ok && msgState.statusMessageId === editId) {
|
|
@@ -10305,7 +10340,7 @@ function finishThinkingMessage(key) {
|
|
|
10305
10340
|
*/
|
|
10306
10341
|
function queueThinkingFrame(key, frameText, isTerminal) {
|
|
10307
10342
|
const c = getThinkingCoalesceState(key);
|
|
10308
|
-
c.
|
|
10343
|
+
c.pending = (0, renderAgentHtml_1.renderAgentFrame)(frameText);
|
|
10309
10344
|
if (isTerminal)
|
|
10310
10345
|
c.detachAfterDrain = true;
|
|
10311
10346
|
if (!c.inFlight)
|
|
@@ -10325,14 +10360,14 @@ async function flushThinkingCoalescer(key) {
|
|
|
10325
10360
|
return;
|
|
10326
10361
|
c.inFlight = true;
|
|
10327
10362
|
try {
|
|
10328
|
-
while (c.
|
|
10329
|
-
const
|
|
10330
|
-
c.
|
|
10331
|
-
if (html === c.lastSentHtml)
|
|
10363
|
+
while (c.pending !== null) {
|
|
10364
|
+
const frame = c.pending;
|
|
10365
|
+
c.pending = null;
|
|
10366
|
+
if (frame.html === c.lastSentHtml)
|
|
10332
10367
|
continue;
|
|
10333
|
-
const sent = await sendThinkingFrame(key,
|
|
10368
|
+
const sent = await sendThinkingFrame(key, frame);
|
|
10334
10369
|
if (sent)
|
|
10335
|
-
c.lastSentHtml = html;
|
|
10370
|
+
c.lastSentHtml = frame.html;
|
|
10336
10371
|
}
|
|
10337
10372
|
if (c.detachAfterDrain) {
|
|
10338
10373
|
c.detachAfterDrain = false;
|
|
@@ -10346,14 +10381,15 @@ async function flushThinkingCoalescer(key) {
|
|
|
10346
10381
|
/**
|
|
10347
10382
|
* @description Edit the thread's thinking message in place, or create it on the
|
|
10348
10383
|
* first frame. The frame is pre-rendered HTML (one message — `full`-mode bodies
|
|
10349
|
-
* 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.
|
|
10350
10386
|
*/
|
|
10351
|
-
async function sendThinkingFrame(key,
|
|
10387
|
+
async function sendThinkingFrame(key, frame) {
|
|
10352
10388
|
const msgState = getThreadMessageState(key);
|
|
10353
10389
|
try {
|
|
10354
10390
|
if (msgState.thinkingMessageId !== null) {
|
|
10355
10391
|
const editId = msgState.thinkingMessageId;
|
|
10356
|
-
const ok = await editThreadMessage(key, editId,
|
|
10392
|
+
const ok = await editThreadMessage(key, editId, frame.html, { parse_mode: 'HTML' }, frame.plain);
|
|
10357
10393
|
// A clear (session end / takeover) may have nulled the id mid-edit — only
|
|
10358
10394
|
// treat the edit as live if the id still points at the message we edited.
|
|
10359
10395
|
if (ok && msgState.thinkingMessageId === editId)
|
|
@@ -10367,7 +10403,7 @@ async function sendThinkingFrame(key, renderedHtml) {
|
|
|
10367
10403
|
// just-created message instead of resurrecting it as an orphan under a
|
|
10368
10404
|
// "session ended" / question UI (the leftover-frame guard).
|
|
10369
10405
|
const generationAtStart = msgState.thinkingFrameGeneration;
|
|
10370
|
-
const id = await replyChunkWithFallback(key,
|
|
10406
|
+
const id = await replyChunkWithFallback(key, frame.html, frame.plain);
|
|
10371
10407
|
if (id === null)
|
|
10372
10408
|
return false;
|
|
10373
10409
|
if (msgState.thinkingFrameGeneration !== generationAtStart) {
|
|
@@ -10662,7 +10698,7 @@ async function refreshSubagentStatus(key) {
|
|
|
10662
10698
|
// send finally lands.
|
|
10663
10699
|
state.lastSubagentText = text;
|
|
10664
10700
|
try {
|
|
10665
|
-
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);
|
|
10666
10702
|
// Guard the post-await mutations against a close+reopen that swapped the
|
|
10667
10703
|
// frame WHILE this edit was draining the pacer: `lastSubagentText` /
|
|
10668
10704
|
// `subagentEditInFlight` now belong to a DIFFERENT frame that owns its own
|
|
@@ -10787,7 +10823,7 @@ function handleSubagentStatus(key, payload) {
|
|
|
10787
10823
|
state.lastSubagentText = null;
|
|
10788
10824
|
state.subagentEditInFlight = false;
|
|
10789
10825
|
const text = (0, subagentStatusRender_1.buildSubagentElapsedText)(state.subagentTitle, 0);
|
|
10790
|
-
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 });
|
|
10791
10827
|
if (id === null)
|
|
10792
10828
|
return;
|
|
10793
10829
|
// A close (teardown) may have landed during the create — don't leave the
|
|
@@ -12326,16 +12362,33 @@ function createSessionPostDeps() {
|
|
|
12326
12362
|
function wireScheduler(wiring) {
|
|
12327
12363
|
const { jiraConnector } = wiring;
|
|
12328
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
|
+
};
|
|
12329
12372
|
const delivery = (0, delivery_1.createScheduleDelivery)({
|
|
12330
12373
|
...createSessionPostDeps(),
|
|
12331
12374
|
...checkStatusLinePorts,
|
|
12332
|
-
|
|
12333
|
-
|
|
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) => {
|
|
12334
12378
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
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 }));
|
|
12338
12390
|
},
|
|
12391
|
+
unpinMessages: unpinThreadMessages,
|
|
12339
12392
|
runCheck: async (threadKeyStr, command, timeoutMs) => {
|
|
12340
12393
|
const decision = (0, validation_1.resolveBoundWorkDir)(ENV.workRoot, state.getBinding((0, sessionKey_1.keyFromString)(threadKeyStr)));
|
|
12341
12394
|
if (decision.kind !== 'proceed')
|
|
@@ -12349,15 +12402,7 @@ function wireScheduler(wiring) {
|
|
|
12349
12402
|
await state.upsertSchedule({ ...record, isCheckFailing: isFailing, updatedAt: new Date().toISOString() });
|
|
12350
12403
|
await state.flush();
|
|
12351
12404
|
},
|
|
12352
|
-
|
|
12353
|
-
const record = state.getSchedules()[jobId];
|
|
12354
|
-
if (!record)
|
|
12355
|
-
return;
|
|
12356
|
-
const alertPinMessageIds = [...(record.alertPinMessageIds ?? []), messageId];
|
|
12357
|
-
await state.upsertSchedule({ ...record, alertPinMessageIds, updatedAt: new Date().toISOString() });
|
|
12358
|
-
// Saved at once, like the failing flag: an id lost in a crash would leave its alert pinned for good.
|
|
12359
|
-
await state.flush();
|
|
12360
|
-
},
|
|
12405
|
+
clearAlertPins: (jobId, releasedMessageIds) => (0, store_2.clearCheckAlertPins)(state, jobId, releasedMessageIds),
|
|
12361
12406
|
checkIsStatusShown: (threadKeyStr) => {
|
|
12362
12407
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12363
12408
|
return (0, checkStatus_1.checkIsCheckStatusShown)({ isTelegram: (0, sessionKeyCodec_1.checkIsTelegramKey)(key), view: state.getDisplayPrefs(key).view });
|
|
@@ -12405,11 +12450,7 @@ function wireScheduler(wiring) {
|
|
|
12405
12450
|
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12406
12451
|
return (0, createAdapter_1.getThreadAdapterNameRaw)(key) ?? state.getAgent(key)?.name;
|
|
12407
12452
|
},
|
|
12408
|
-
unpinMessages:
|
|
12409
|
-
const key = (0, sessionKey_1.keyFromString)(threadKeyStr);
|
|
12410
|
-
for (const messageId of messageIds)
|
|
12411
|
-
await unpinMessageQuiet(key, messageId);
|
|
12412
|
-
},
|
|
12453
|
+
unpinMessages: unpinThreadMessages,
|
|
12413
12454
|
// A cancelled check's status line goes through the same best-effort delete the delivery uses.
|
|
12414
12455
|
deleteMessage: checkStatusLinePorts.deleteMessage,
|
|
12415
12456
|
// Routed through the outbound seam: the agent-facing file tool is a
|