telecoder 1.2.0 → 1.3.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.
Files changed (197) hide show
  1. package/.env.example +142 -130
  2. package/CHANGELOG.md +683 -2
  3. package/README.md +36 -32
  4. package/dist/audio/transcribe.js +0 -9
  5. package/dist/bin/mcp-server.js +46 -61
  6. package/dist/bot/bot.js +162 -181
  7. package/dist/bot/command-catalog.js +263 -0
  8. package/dist/bot/deleted-threads.js +103 -0
  9. package/dist/bot/file-access.js +35 -26
  10. package/dist/bot/handlers/album.handler.js +128 -0
  11. package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
  12. package/dist/bot/handlers/command/access.js +1 -1
  13. package/dist/bot/handlers/command/admin.js +86 -110
  14. package/dist/bot/handlers/command/all-view.js +33 -0
  15. package/dist/bot/handlers/command/auto-approve.js +3 -3
  16. package/dist/bot/handlers/command/background.js +37 -0
  17. package/dist/bot/handlers/command/botname.js +76 -0
  18. package/dist/bot/handlers/command/btw.js +20 -69
  19. package/dist/bot/handlers/command/cleanup.js +329 -0
  20. package/dist/bot/handlers/command/model.js +40 -119
  21. package/dist/bot/handlers/command/prefs-scope.js +255 -90
  22. package/dist/bot/handlers/command/project.js +31 -109
  23. package/dist/bot/handlers/command/resume.js +8 -4
  24. package/dist/bot/handlers/command/session.js +74 -213
  25. package/dist/bot/handlers/command/settings.js +92 -447
  26. package/dist/bot/handlers/command/shared.js +32 -35
  27. package/dist/bot/handlers/command/tasks.js +263 -95
  28. package/dist/bot/handlers/command/thread.js +128 -0
  29. package/dist/bot/handlers/command/topic-store.js +14 -53
  30. package/dist/bot/handlers/command/topic.js +8 -61
  31. package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
  32. package/dist/bot/handlers/command-fallback.js +179 -0
  33. package/dist/bot/handlers/command.handler.js +96 -422
  34. package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
  35. package/dist/bot/handlers/media-fallback.js +12 -7
  36. package/dist/bot/handlers/message/replies.js +10 -87
  37. package/dist/bot/handlers/message/shared.js +9 -31
  38. package/dist/bot/handlers/message/turn-notify.js +15 -49
  39. package/dist/bot/handlers/message/turn-runner.js +18 -103
  40. package/dist/bot/handlers/message.handler.js +59 -52
  41. package/dist/bot/handlers/newbot.handler.js +13 -4
  42. package/dist/bot/handlers/photo.handler.js +88 -129
  43. package/dist/bot/handlers/prompts.handler.js +11 -11
  44. package/dist/bot/handlers/running-note.js +2 -2
  45. package/dist/bot/handlers/session-guard.js +4 -4
  46. package/dist/bot/handlers/suggestion.handler.js +2 -2
  47. package/dist/bot/handlers/tree.handler.js +20 -20
  48. package/dist/bot/handlers/voice.handler.js +23 -85
  49. package/dist/bot/kept-threads.js +51 -0
  50. package/dist/bot/middleware/album-collector.js +69 -0
  51. package/dist/bot/middleware/auth.middleware.js +1 -1
  52. package/dist/bot/middleware/group-mention.middleware.js +11 -5
  53. package/dist/bot/middleware/queued-messages.js +143 -32
  54. package/dist/bot/middleware/stale-filter.js +0 -22
  55. package/dist/build-info.json +5 -5
  56. package/dist/claude/ask-user-form.js +517 -0
  57. package/dist/claude/ask-user.js +94 -26
  58. package/dist/claude/auto-topic-haiku.js +17 -0
  59. package/dist/claude/available-commands.js +22 -19
  60. package/dist/claude/background-hint.js +91 -0
  61. package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
  62. package/dist/claude/carry-over.js +0 -2
  63. package/dist/claude/ccr-shim.js +12 -10
  64. package/dist/claude/claude-auth.js +6 -10
  65. package/dist/claude/command-parser.js +49 -43
  66. package/dist/claude/cost-overlay-scraper.js +7 -2
  67. package/dist/claude/effort-level.js +5 -0
  68. package/dist/claude/enabled-plugins.js +12 -16
  69. package/dist/claude/in-flight-tracker.js +21 -0
  70. package/dist/claude/mcp-bridge.js +86 -58
  71. package/dist/claude/memory-guard.js +400 -0
  72. package/dist/claude/message-offsets.js +5 -5
  73. package/dist/claude/modal-relay.js +401 -34
  74. package/dist/claude/model-catalog.js +20 -3
  75. package/dist/claude/monitor-relay.js +130 -15
  76. package/dist/claude/native-commands.js +40 -0
  77. package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
  78. package/dist/claude/permission-gate.js +11 -10
  79. package/dist/claude/permission-mode.js +19 -45
  80. package/dist/claude/prewarm.js +70 -0
  81. package/dist/claude/pty-idle-reaper.js +96 -0
  82. package/dist/claude/pty-provider.js +473 -188
  83. package/dist/claude/pty-spawn-config.js +79 -32
  84. package/dist/claude/pty-watch.js +201 -0
  85. package/dist/claude/request-queue.js +7 -35
  86. package/dist/claude/rewind.js +111 -0
  87. package/dist/claude/scheduled-runner.js +1 -3
  88. package/dist/claude/scheduler.js +6 -2
  89. package/dist/claude/scope-guard.js +8 -3
  90. package/dist/claude/screen-marks.js +83 -0
  91. package/dist/claude/screen-render.js +96 -0
  92. package/dist/claude/session-history.js +4 -2
  93. package/dist/claude/session-jsonl.js +162 -15
  94. package/dist/claude/session-manager.js +29 -8
  95. package/dist/claude/session-move.js +70 -0
  96. package/dist/claude/shell-mode-gate.js +60 -0
  97. package/dist/claude/side-question.js +20 -17
  98. package/dist/claude/stage-images.js +5 -5
  99. package/dist/claude/tasks-overlay-scraper.js +143 -20
  100. package/dist/claude/thread-judge-haiku.js +88 -0
  101. package/dist/claude/tip-scraper.js +3 -4
  102. package/dist/claude/tui-modal.js +272 -27
  103. package/dist/claude/tui-state.js +74 -2
  104. package/dist/claude/turn-end.js +15 -1
  105. package/dist/claude/turn-prose.js +1 -1
  106. package/dist/claude/typed-answer.js +104 -0
  107. package/dist/claude/update-banner-relay.js +1 -1
  108. package/dist/cli/commands/doctor.js +48 -15
  109. package/dist/cli/commands/help.js +11 -2
  110. package/dist/cli/commands/init.js +16 -13
  111. package/dist/cli/commands/service.js +40 -8
  112. package/dist/cli/commands/start.js +10 -0
  113. package/dist/cli/commands/watch.js +322 -0
  114. package/dist/cli/dispatch.js +5 -0
  115. package/dist/cli/init/env-file.js +1 -1
  116. package/dist/cli/init/flow.js +114 -47
  117. package/dist/cli/init/prompter.js +8 -0
  118. package/dist/cli/init/telegram.js +35 -9
  119. package/dist/cli/service/render.js +3 -3
  120. package/dist/config.js +156 -131
  121. package/dist/index.js +107 -31
  122. package/dist/launcher.js +34 -7
  123. package/dist/providers/ccr-introspect.js +1 -8
  124. package/dist/providers/ccr-provider.js +19 -20
  125. package/dist/providers/claude-provider.js +4 -57
  126. package/dist/providers/prefs-sync.js +16 -59
  127. package/dist/providers/provider-router.js +24 -23
  128. package/dist/providers/spawn-settings.js +45 -0
  129. package/dist/providers/user-preferences.js +127 -19
  130. package/dist/restart-when-idle.js +27 -7
  131. package/dist/startup/auto-continue.js +2 -2
  132. package/dist/startup/auto-resume.js +3 -15
  133. package/dist/startup/notices.js +1 -1
  134. package/dist/startup/verify-token.js +4 -4
  135. package/dist/telegram/action-logger.js +3 -165
  136. package/dist/telegram/background-activity-card.js +1 -1
  137. package/dist/telegram/botname-settings.js +71 -125
  138. package/dist/telegram/client-options.js +6 -7
  139. package/dist/telegram/force-reply-tracker.js +55 -16
  140. package/dist/telegram/message-sender.js +92 -360
  141. package/dist/telegram/prompt-label.js +11 -5
  142. package/dist/telegram/streaming-turn.js +5 -7
  143. package/dist/telegram/table-lists.js +56 -0
  144. package/dist/telegram/task-list.js +4 -4
  145. package/dist/telegram/task-tracker.js +45 -126
  146. package/dist/telegram/terminal-renderer.js +1 -5
  147. package/dist/telegram/thread-titles.js +74 -2
  148. package/dist/telegram/threads-setup.js +1 -1
  149. package/dist/utils/admins.js +2 -2
  150. package/dist/utils/bot-icon.js +248 -0
  151. package/dist/utils/bot-token.js +8 -5
  152. package/dist/utils/build-info.js +3 -3
  153. package/dist/utils/caffeinate.js +6 -3
  154. package/dist/utils/claude-env.js +0 -1
  155. package/dist/utils/claude-version.js +2 -2
  156. package/dist/utils/config-home.js +3 -3
  157. package/dist/utils/download.js +41 -15
  158. package/dist/utils/exit-codes.js +11 -0
  159. package/dist/utils/format.js +3 -6
  160. package/dist/utils/home-project.js +1 -1
  161. package/dist/utils/idle-restart.js +1 -1
  162. package/dist/utils/install-mode.js +1 -1
  163. package/dist/utils/instance-config.js +1 -1
  164. package/dist/utils/instances.js +1 -1
  165. package/dist/utils/keyed-settings.js +2 -2
  166. package/dist/utils/memory-pressure.js +60 -0
  167. package/dist/utils/npm-version.js +2 -2
  168. package/dist/utils/resolve-claude-bin.js +13 -24
  169. package/dist/utils/respawn-backoff.js +9 -0
  170. package/dist/utils/stale-launcher.js +1 -1
  171. package/dist/utils/systemd.js +8 -8
  172. package/dist/utils/telegram-proxy.js +72 -0
  173. package/dist/utils/uploads-dir.js +27 -0
  174. package/dist/utils/verbosity.js +8 -8
  175. package/dist/utils/version-check.js +5 -5
  176. package/package.json +3 -4
  177. package/dist/bot/handlers/command/media.js +0 -197
  178. package/dist/bot/handlers/command/streaming-mode.js +0 -16
  179. package/dist/bot/handlers/message/throttle.js +0 -49
  180. package/dist/claude/agent-watchdog.js +0 -162
  181. package/dist/claude/agent.js +0 -1458
  182. package/dist/claude/held-query.js +0 -190
  183. package/dist/claude/mcp-tools.js +0 -354
  184. package/dist/claude/sdk-permission-gate.js +0 -77
  185. package/dist/claude/session-cost.js +0 -41
  186. package/dist/claude/system-prompt.js +0 -162
  187. package/dist/providers/sdk-provider.js +0 -37
  188. package/dist/telegram/telegraph-settings.js +0 -31
  189. package/dist/telegram/telegraph.js +0 -453
  190. package/dist/telegram/terminal-settings.js +0 -25
  191. package/dist/tts/tts-settings.js +0 -62
  192. package/dist/tts/tts.js +0 -245
  193. package/dist/tts/voice-reply.js +0 -78
  194. package/dist/utils/debug-agent.js +0 -117
  195. package/dist/utils/debug-watchdog.js +0 -121
  196. package/dist/utils/project-data-dir.js +0 -33
  197. package/dist/utils/reasoning-summary.js +0 -12
@@ -24,7 +24,7 @@
24
24
  * that was taken back and otherwise takes the ack down and lets it through.
25
25
  *
26
26
  * It also holds a message bound for Claude while Claude is busy with something
27
- * sequentialize knows nothing about: a /schedule fire, or a turn Claude started
27
+ * sequentialize knows nothing about: a /loop run, or a turn Claude started
28
28
  * itself when a background task reported back. Holding here rather than in the
29
29
  * pty provider's readiness wait means taking the message back leaves that turn
30
30
  * alone, no "thinking" bubble goes up for a prompt that hasn't been delivered,
@@ -60,12 +60,18 @@
60
60
  * asking, or the question would go up at once. `/later` alone lists what's set
61
61
  * aside in the chat.
62
62
  *
63
+ * A message set aside can still go before the question, from its notice: "Interrupt
64
+ * & send" while a turn runs, which it then goes in place of, and "Send now" while
65
+ * nothing does, since then sending it is all there is to do. One set aside from a
66
+ * place in line it still holds takes that place back, as if the button had been
67
+ * tapped on its ack. Otherwise it goes through the chain again as /steer sends one.
68
+ *
63
69
  * A question left unanswered while the conversation moves on would scroll out of
64
70
  * sight, so once another turn has run it's taken down and asked again below the
65
71
  * new reply, without a buzz the second time.
66
72
  *
67
73
  * A message doesn't have to wait for the turn at all. "Ask as /btw" answers it
68
- * on the side straight away, and "Ask in a fork" sends it to a new thread whose
74
+ * on the side straight away, and "Ask in a branch" sends it to a new thread whose
69
75
  * conversation is this one as it stood before the running turn, so the two carry
70
76
  * on side by side. Either way it leaves the line, as a taken-back message does.
71
77
  * What does the asking lives with the handlers, which hand it in through
@@ -79,6 +85,7 @@ import { getBotCommandNames } from '../../claude/command-parser.js';
79
85
  import { hasSelfStartedTurn, whenRepliesSent } from '../../claude/monitor-relay.js';
80
86
  import { cancelRequest, clearQueue, isProcessing } from '../../claude/request-queue.js';
81
87
  import { cancelSecretRequest } from '../../claude/secret-request.js';
88
+ import { stopTypedAnswers } from '../../claude/typed-answer.js';
82
89
  import { getPtyProvider } from '../../providers/claude-provider.js';
83
90
  import { isAdmin } from '../../utils/admins.js';
84
91
  import { ensureStateDir, getStateDir, readJsonFile, writeJsonFile } from '../../utils/json-store.js';
@@ -100,14 +107,15 @@ const HOLD_POLL_MS = 500;
100
107
  * How long a message waits on a turn Claude started itself before it moves on
101
108
  * to the pty provider's readiness wait, which reports a turn that never ends
102
109
  * instead of sitting on it. Matches that wait's own patience. A turn TeleCoder
103
- * started has no ceiling here, because the agent watchdog already looks after it.
110
+ * started has no ceiling here, because CLAUDE_PTY_HARD_TIMEOUT_MS already caps
111
+ * it.
104
112
  */
105
113
  const OWN_TURN_CEILING_MS = 30 * 60_000;
106
114
  /** How often a message set aside looks again at whether it can be asked about. */
107
115
  const REMIND_POLL_MS = 1_000;
108
116
  const CALLBACK_PREFIX = 'queued:';
109
- /** A bare message id is Take back, which is what acks already in chats carry. */
110
- const CALLBACK_PATTERN = /^queued:(?:(park|send|drop|btw|fork|steer):)?(\d+)$/;
117
+ /** A bare message id is Take back. */
118
+ const CALLBACK_PATTERN = /^queued:(?:(park|send|drop|btw|branch|steer):)?(\d+)$/;
111
119
  const BEHIND_TURN = '⏳ Queued behind the running turn.';
112
120
  const BEHIND_OWN_TURN = '⏳ Queued behind a turn Claude started itself.';
113
121
  const STEERING = '⚡ Stopping the turn, then sending this.';
@@ -128,10 +136,11 @@ const STEER_COMMAND = /^\/steer(?:@\w+)?(?:\s+|$)/i;
128
136
  const STEER_USAGE = '⚡ /steer <text> stops the running turn and sends <text> in its place. '
129
137
  + 'Claude keeps what it had done, so <text> can be a correction to it.';
130
138
  const SENT = '📤 Sent.';
139
+ const SENT_IN_PLACE = '⚡ Sent in place of the turn.';
131
140
  const DROPPED = '🗑 Dropped before it reached Claude.';
132
141
  const NOT_YOURS = 'Only the person who sent this, or an admin, can do that.';
133
142
  const ASKED_AS_BTW = '💬 Asked as /btw instead. The answer is below.';
134
- const ASKED_IN_FORK = '🍴 Asked in a fork instead:';
143
+ const ASKED_IN_BRANCH = '🌱 Asked in a branch instead:';
135
144
  /** From arrival until the message is let through or dropped, keyed by entryKey. */
136
145
  const queued = new Map();
137
146
  /** Sent with /steer and on their way back through the chain, keyed by entryKey. */
@@ -214,8 +223,8 @@ function ackKeyboard(entry) {
214
223
  if (entry.canBtw && diverters) {
215
224
  second.push({ text: '💬 Ask as /btw', callback_data: `${CALLBACK_PREFIX}btw:${entry.messageId}` });
216
225
  }
217
- if (entry.canFork && diverters) {
218
- second.push({ text: '🍴 Ask in a fork', callback_data: `${CALLBACK_PREFIX}fork:${entry.messageId}` });
226
+ if (entry.canBranch && diverters) {
227
+ second.push({ text: '🌱 Ask in a branch', callback_data: `${CALLBACK_PREFIX}branch:${entry.messageId}` });
219
228
  }
220
229
  // Last, as the one that stops something.
221
230
  const steer = [{ text: '⚡ Interrupt & send', callback_data: `${CALLBACK_PREFIX}steer:${entry.messageId}` }];
@@ -260,11 +269,6 @@ function noteArrival(ctx) {
260
269
  if (queued.has(key))
261
270
  return null;
262
271
  const steering = steered.delete(key);
263
- if (forClaude && config.CANCEL_ON_NEW_MESSAGE && isProcessing(keyInfo.sessionKey)) {
264
- takeBackAllQueued(ctx.api, keyInfo.sessionKey);
265
- clearQueue(keyInfo.sessionKey);
266
- void cancelRequest(keyInfo.sessionKey);
267
- }
268
272
  const { api } = ctx;
269
273
  // A slash command typed at Claude means something to the conversation it's
270
274
  // in, so it neither goes on the side nor somewhere new.
@@ -281,7 +285,7 @@ function noteArrival(ctx) {
281
285
  takenBack: false,
282
286
  parked: false,
283
287
  canBtw: forClaude && msg.text !== undefined && msg.text.trim() !== '' && !command,
284
- canFork: forClaude && !command && ctx.chat?.type === 'private' && ctx.me?.has_topics_enabled === true,
288
+ canBranch: forClaude && !command && ctx.chat?.type === 'private' && ctx.me?.has_topics_enabled === true,
285
289
  diverting: false,
286
290
  steering,
287
291
  ackTimer: null,
@@ -344,7 +348,8 @@ export function takeBackAllQueued(api, sessionKey, keep) {
344
348
  }
345
349
  /**
346
350
  * What /cancel does to a session: drop what's waiting, withdraw a request for a
347
- * secret, and stop the turn, whoever started it. `keep` stays in line, to go once
351
+ * secret, stop taking messages as answers to a question, and stop the turn,
352
+ * whoever started it. `keep` stays in line, to go once
348
353
  * the turn has stopped. Whether anything was stopped, and how many were dropped.
349
354
  */
350
355
  export async function stopTurn(api, sessionKey, keep) {
@@ -353,6 +358,7 @@ export async function stopTurn(api, sessionKey, keep) {
353
358
  // Before the turn, too: until the request is withdrawn, the next message
354
359
  // would still be taken for the secret it asked for.
355
360
  const secretCancelled = cancelSecretRequest(sessionKey);
361
+ stopTypedAnswers(sessionKey);
356
362
  // A turn claude started itself has no handle for cancelRequest to find.
357
363
  const stopped = await cancelRequest(sessionKey) || getPtyProvider().interruptOwnTurn(sessionKey) || secretCancelled;
358
364
  return { stopped, dropped: takenBack + clearQueue(sessionKey) };
@@ -387,6 +393,24 @@ function turnRunning(sessionKey) {
387
393
  || getPtyProvider().isSessionGenerating(sessionKey)
388
394
  || hasSelfStartedTurn(sessionKey);
389
395
  }
396
+ /**
397
+ * What the session still has going on that deleting its thread would lose: a
398
+ * turn, a message on its way or waiting for one, or one set aside with
399
+ * /later. Undefined when there's none of that.
400
+ */
401
+ export function pendingWork(sessionKey) {
402
+ if (inFlight.has(sessionKey) || turnRunning(sessionKey))
403
+ return 'working';
404
+ for (const entry of queued.values()) {
405
+ if (entry.sessionKey === sessionKey && !entry.takenBack && !entry.parked)
406
+ return 'messages waiting';
407
+ }
408
+ for (const message of parked.values()) {
409
+ if (message.sessionKey === sessionKey)
410
+ return 'message set aside';
411
+ }
412
+ return undefined;
413
+ }
390
414
  /**
391
415
  * Whether the session has nothing left that would change the answer the question
392
416
  * is about. Background tasks don't count: they can run for hours with the session
@@ -453,6 +477,7 @@ async function remindWhereIdle() {
453
477
  if (running) {
454
478
  delete message.awaitsTurn;
455
479
  saveParked();
480
+ void noticeTurnStarted(botRef.api, message);
456
481
  }
457
482
  continue;
458
483
  }
@@ -501,12 +526,49 @@ function stripCommand(msg, command) {
501
526
  msg.text = msg.text.replace(command, '');
502
527
  delete msg.entities;
503
528
  }
529
+ /**
530
+ * The buttons on the notice of a message set aside. While a turn runs it can go in
531
+ * place of that turn. With nothing running, sending it starts one, so it can just go.
532
+ */
533
+ function setAsideKeyboard(messageId, turnRunning) {
534
+ if (!turnRunning) {
535
+ return {
536
+ inline_keyboard: [[
537
+ takeBackButton(messageId),
538
+ { text: '📤 Send now', callback_data: `${CALLBACK_PREFIX}send:${messageId}` },
539
+ ]],
540
+ };
541
+ }
542
+ // On a row of its own, as on the ack, as the one that stops something.
543
+ return {
544
+ inline_keyboard: [
545
+ [takeBackButton(messageId)],
546
+ [{ text: '⚡ Interrupt & send', callback_data: `${CALLBACK_PREFIX}steer:${messageId}` }],
547
+ ],
548
+ };
549
+ }
550
+ /**
551
+ * The turn a message set aside while nothing was running has started. Send now
552
+ * would only put it behind that turn, so the notice offers to interrupt it instead.
553
+ */
554
+ async function noticeTurnStarted(api, message) {
555
+ if (message.noticeId === undefined)
556
+ return;
557
+ try {
558
+ await api.editMessageText(message.chatId, message.noticeId, PARKED, {
559
+ reply_markup: setAsideKeyboard(message.messageId, true),
560
+ });
561
+ }
562
+ catch (err) {
563
+ console.warn('[Queued] Could not update the notice:', sanitizeError(err));
564
+ }
565
+ }
504
566
  async function postNotice(api, message, text) {
505
567
  try {
506
568
  const sent = await api.sendMessage(message.chatId, text, {
507
569
  // Answering the person who just typed it, who is looking at the chat.
508
570
  reply_parameters: { message_id: message.messageId, allow_sending_without_reply: true },
509
- reply_markup: { inline_keyboard: [[takeBackButton(message.messageId)]] },
571
+ reply_markup: setAsideKeyboard(message.messageId, !message.awaitsTurn),
510
572
  disable_notification: true,
511
573
  ...(message.threadId !== undefined ? { message_thread_id: message.threadId } : {}),
512
574
  });
@@ -585,6 +647,9 @@ export async function handleLater(ctx) {
585
647
  if (parked.get(key) === message && message.reminderId === undefined) {
586
648
  message.noticeId = noticeId;
587
649
  saveParked();
650
+ // The turn it was waiting for started while the notice was on its way.
651
+ if (awaitsTurn && !message.awaitsTurn)
652
+ void noticeTurnStarted(ctx.api, message);
588
653
  }
589
654
  else {
590
655
  // Dealt with, or asked about, while the notice was on its way.
@@ -669,7 +734,7 @@ export const holdQueuedMessage = async (ctx, next) => {
669
734
  const msg = ctx.message;
670
735
  const chatId = ctx.chat?.id;
671
736
  const found = msg && chatId !== undefined ? queued.get(entryKey(chatId, msg.message_id)) : undefined;
672
- // A message asked in a fork arrives again under its own id, in the fork's
737
+ // A message asked in a branch arrives again under its own id, in the branch's
673
738
  // thread, while the original is still being dropped here.
674
739
  const entry = found?.sessionKey === getSessionKeyFromCtx(ctx)?.sessionKey ? found : undefined;
675
740
  if (!entry)
@@ -786,7 +851,8 @@ async function handleParkTap(ctx, key) {
786
851
  armReminders();
787
852
  await ctx.answerCallbackQuery({ text: 'Set aside.' });
788
853
  try {
789
- await ctx.editMessageText(PARKED, { reply_markup: { inline_keyboard: [[takeBackButton(entry.messageId)]] } });
854
+ // It was waiting behind something, which it can still go in place of.
855
+ await ctx.editMessageText(PARKED, { reply_markup: setAsideKeyboard(entry.messageId, true) });
790
856
  }
791
857
  catch (err) {
792
858
  console.warn('[Queued] Could not update the ack:', sanitizeError(err));
@@ -803,7 +869,7 @@ async function claimWaiting(ctx, key) {
803
869
  await ctx.answerCallbackQuery({
804
870
  text: entry.takenBack ? 'Already taken back.'
805
871
  : entry.parked ? 'Already set aside.'
806
- : entry.diverting ? 'Already opening a fork.'
872
+ : entry.diverting ? 'Already opening a branch.'
807
873
  : 'Already stopping the turn for it.',
808
874
  });
809
875
  return undefined;
@@ -830,9 +896,15 @@ async function handleBtwTap(ctx, key) {
830
896
  });
831
897
  }
832
898
  async function handleSteerTap(ctx, key) {
899
+ const setAside = parked.get(key);
900
+ if (setAside)
901
+ return steerSetAside(ctx, key, setAside);
833
902
  const entry = await claimWaiting(ctx, key);
834
- if (!entry)
835
- return;
903
+ if (entry)
904
+ await steer(ctx, entry);
905
+ }
906
+ /** Interrupt & send, on a message with its place in line. */
907
+ async function steer(ctx, entry) {
836
908
  // Set at once, so a second tap can't stop a turn that has already moved on to this one.
837
909
  entry.steering = true;
838
910
  // Started before anything else awaits, so what's waiting is dropped before the turn can end.
@@ -847,13 +919,52 @@ async function handleSteerTap(ctx, key) {
847
919
  }
848
920
  await stopping;
849
921
  }
922
+ /**
923
+ * Interrupt & send, on the notice of a message set aside. One that still holds its
924
+ * place behind the turn it was set aside from, whose notice is its ack, takes that
925
+ * place back. Otherwise it goes back through the chain, as /steer sends one, and
926
+ * with nothing to interrupt it simply goes.
927
+ */
928
+ async function steerSetAside(ctx, key, message) {
929
+ if (!maySettle(ctx, message.senderId)) {
930
+ await ctx.answerCallbackQuery({ text: NOT_YOURS, show_alert: true });
931
+ return;
932
+ }
933
+ // Before anything that awaits, or the question could go up meanwhile.
934
+ parked.delete(key);
935
+ saveParked();
936
+ const entry = queued.get(key);
937
+ if (entry?.parked && !entry.takenBack) {
938
+ entry.parked = false;
939
+ return steer(ctx, entry);
940
+ }
941
+ const running = turnRunning(message.sessionKey);
942
+ // Started first, so what's waiting is dropped before the turn can end and let it through.
943
+ const stopping = running ? stopTurn(ctx.api, message.sessionKey) : undefined;
944
+ console.log(running
945
+ ? `[Queued] Stopping the turn in ${message.sessionKey} for set-aside message ${message.messageId}`
946
+ : `[Queued] Sending set-aside message ${message.messageId} in ${message.sessionKey}, with nothing to interrupt`);
947
+ await ctx.answerCallbackQuery({ text: running ? 'Stopping the turn.' : 'Sent.' });
948
+ try {
949
+ await ctx.editMessageText(running ? SENT_IN_PLACE : SENT, { reply_markup: { inline_keyboard: [] } });
950
+ }
951
+ catch (err) {
952
+ console.warn('[Queued] Could not update the notice:', sanitizeError(err));
953
+ }
954
+ if (stopping) {
955
+ await stopping;
956
+ // Its ack, should it have to wait for the turn to wind down, says why.
957
+ steered.add(key);
958
+ }
959
+ sendParked(message);
960
+ }
850
961
  /**
851
962
  * The message as if it had been sent in the new thread: the same update, with
852
963
  * the thread's id on it, through the whole chain the way Send replays one.
853
964
  */
854
965
  function sendIntoThread(update, threadId) {
855
966
  void replayIntoThread(update, threadId).catch((err) => {
856
- console.error(`[Queued] Sending message ${update.message.message_id} into the fork failed:`, sanitizeError(err));
967
+ console.error(`[Queued] Sending message ${update.message.message_id} into the branch failed:`, sanitizeError(err));
857
968
  });
858
969
  }
859
970
  /**
@@ -875,21 +986,21 @@ export async function replayIntoThread(update, threadId, changes = {}) {
875
986
  markAlreadyAddressed(copy);
876
987
  await botRef.handleUpdate(copy);
877
988
  }
878
- async function handleForkTap(ctx, key) {
989
+ async function handleBranchTap(ctx, key) {
879
990
  const entry = await claimWaiting(ctx, key);
880
991
  if (!entry || !diverters)
881
992
  return;
882
993
  // Holds its place while the thread is opened, so it can go back in line if
883
994
  // that fails, and doesn't slip through to the running conversation meanwhile.
884
995
  entry.diverting = true;
885
- await ctx.answerCallbackQuery({ text: 'Opening a fork…' });
996
+ await ctx.answerCallbackQuery({ text: 'Opening a branch…' });
886
997
  let opened;
887
998
  try {
888
- opened = await diverters.fork(ctx, entry.sessionKey, entry.update.message);
999
+ opened = await diverters.branch(ctx, entry.sessionKey, entry.update.message);
889
1000
  }
890
1001
  catch (err) {
891
- console.error(`[Queued] Fork for message ${entry.messageId} failed:`, sanitizeError(err));
892
- opened = { error: 'Could not open a fork.' };
1002
+ console.error(`[Queued] Branch for message ${entry.messageId} failed:`, sanitizeError(err));
1003
+ opened = { error: 'Could not open a branch.' };
893
1004
  }
894
1005
  if ('error' in opened) {
895
1006
  entry.diverting = false;
@@ -897,7 +1008,7 @@ async function handleForkTap(ctx, key) {
897
1008
  if (entry.takenBack)
898
1009
  return;
899
1010
  try {
900
- await ctx.editMessageText(`${ackText(entry)}\n🍴 ${opened.error}`, { reply_markup: ackKeyboard(entry) });
1011
+ await ctx.editMessageText(`${ackText(entry)}\n🌱 ${opened.error}`, { reply_markup: ackKeyboard(entry) });
901
1012
  }
902
1013
  catch (err) {
903
1014
  console.warn('[Queued] Could not update the ack:', sanitizeError(err));
@@ -907,10 +1018,10 @@ async function handleForkTap(ctx, key) {
907
1018
  entry.diverting = false;
908
1019
  entry.takenBack = true;
909
1020
  stopAckTimer(entry);
910
- console.log(`[Queued] Asked message ${entry.messageId} in ${entry.sessionKey} in a fork, thread ${opened.threadId}`);
1021
+ console.log(`[Queued] Asked message ${entry.messageId} in ${entry.sessionKey} in a branch, thread ${opened.threadId}`);
911
1022
  sendIntoThread(entry.update, opened.threadId);
912
1023
  try {
913
- await ctx.editMessageText(`${ASKED_IN_FORK} ${opened.name}`, {
1024
+ await ctx.editMessageText(`${ASKED_IN_BRANCH} ${opened.name}`, {
914
1025
  reply_markup: {
915
1026
  inline_keyboard: opened.link ? [[{ text: `Open ${opened.name}`, url: opened.link }]] : [],
916
1027
  },
@@ -962,8 +1073,8 @@ export async function handleQueuedCallback(ctx) {
962
1073
  return handleReminderTap(ctx, key, action);
963
1074
  if (action === 'btw')
964
1075
  return handleBtwTap(ctx, key);
965
- if (action === 'fork')
966
- return handleForkTap(ctx, key);
1076
+ if (action === 'branch')
1077
+ return handleBranchTap(ctx, key);
967
1078
  if (action === 'steer')
968
1079
  return handleSteerTap(ctx, key);
969
1080
  return handleTakeBackTap(ctx, key);
@@ -6,26 +6,4 @@ export function isStaleMessage(messageDate) {
6
6
  // Ignore messages sent before bot started (minus threshold)
7
7
  return messageDateMs < BOT_START_TIME - STALE_THRESHOLD;
8
8
  }
9
- export function getUptimeSeconds() {
10
- return Math.floor((Date.now() - BOT_START_TIME) / 1000);
11
- }
12
- export function getUptimeFormatted() {
13
- const seconds = getUptimeSeconds();
14
- if (seconds < 60) {
15
- return `${seconds}s`;
16
- }
17
- const minutes = Math.floor(seconds / 60);
18
- const remainingSeconds = seconds % 60;
19
- if (minutes < 60) {
20
- return `${minutes}m ${remainingSeconds}s`;
21
- }
22
- const hours = Math.floor(minutes / 60);
23
- const remainingMinutes = minutes % 60;
24
- if (hours < 24) {
25
- return `${hours}h ${remainingMinutes}m`;
26
- }
27
- const days = Math.floor(hours / 24);
28
- const remainingHours = hours % 24;
29
- return `${days}d ${remainingHours}h`;
30
- }
31
9
  //# sourceMappingURL=stale-filter.js.map
@@ -1,8 +1,8 @@
1
1
  {
2
- "version": "1.2.0",
3
- "commit": "743487e",
4
- "subject": "release: 1.2.0, the first npm release",
2
+ "version": "1.3.0",
3
+ "commit": "7a9fc17",
4
+ "subject": "release: 1.3.0",
5
5
  "dirty": false,
6
- "sourceHash": "d5769fb55a820e3a",
7
- "builtAt": "2026-11-14T08:14:54.181Z"
6
+ "sourceHash": "f5119649be2ee357",
7
+ "builtAt": "2026-12-01T05:40:17.889Z"
8
8
  }