charness 4.3.0 → 4.4.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 (153) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/agent-plugin/skills/charness-orchestration/SKILL.md +8 -2
  4. package/dist/agentLogin/agentLogin.d.ts.map +1 -1
  5. package/dist/agentLogin/agentLogin.js +6 -5
  6. package/dist/agentLogin/agentLogin.js.map +1 -1
  7. package/dist/apiRetryKick.d.ts +15 -5
  8. package/dist/apiRetryKick.d.ts.map +1 -1
  9. package/dist/apiRetryKick.js +13 -8
  10. package/dist/apiRetryKick.js.map +1 -1
  11. package/dist/bot.d.ts.map +1 -1
  12. package/dist/bot.js +85 -46
  13. package/dist/bot.js.map +1 -1
  14. package/dist/cli/claudeProfiles.d.ts +4 -1
  15. package/dist/cli/claudeProfiles.d.ts.map +1 -1
  16. package/dist/cli/claudeProfiles.js +6 -2
  17. package/dist/cli/claudeProfiles.js.map +1 -1
  18. package/dist/connectors/jira/answerSink.d.ts.map +1 -1
  19. package/dist/connectors/jira/answerSink.js +3 -1
  20. package/dist/connectors/jira/answerSink.js.map +1 -1
  21. package/dist/connectors/telegram/commands/claudeAccounts.d.ts +12 -1
  22. package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
  23. package/dist/connectors/telegram/commands/claudeAccounts.js +253 -89
  24. package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
  25. package/dist/connectors/telegram/commands/fallbackChain.d.ts.map +1 -1
  26. package/dist/connectors/telegram/commands/fallbackChain.js +8 -7
  27. package/dist/connectors/telegram/commands/fallbackChain.js.map +1 -1
  28. package/dist/connectors/telegram/commands/limitsBoard.d.ts.map +1 -1
  29. package/dist/connectors/telegram/commands/limitsBoard.js +3 -1
  30. package/dist/connectors/telegram/commands/limitsBoard.js.map +1 -1
  31. package/dist/connectors/telegram/commands/modelPage.d.ts +2 -0
  32. package/dist/connectors/telegram/commands/modelPage.d.ts.map +1 -1
  33. package/dist/connectors/telegram/commands/modelPage.js +1 -1
  34. package/dist/connectors/telegram/commands/modelPage.js.map +1 -1
  35. package/dist/i18n/de.d.ts.map +1 -1
  36. package/dist/i18n/de.js +42 -25
  37. package/dist/i18n/de.js.map +1 -1
  38. package/dist/i18n/en.d.ts.map +1 -1
  39. package/dist/i18n/en.js +42 -25
  40. package/dist/i18n/en.js.map +1 -1
  41. package/dist/i18n/es.d.ts.map +1 -1
  42. package/dist/i18n/es.js +42 -25
  43. package/dist/i18n/es.js.map +1 -1
  44. package/dist/i18n/fr.d.ts.map +1 -1
  45. package/dist/i18n/fr.js +42 -25
  46. package/dist/i18n/fr.js.map +1 -1
  47. package/dist/i18n/hi.d.ts.map +1 -1
  48. package/dist/i18n/hi.js +42 -25
  49. package/dist/i18n/hi.js.map +1 -1
  50. package/dist/i18n/ja.d.ts.map +1 -1
  51. package/dist/i18n/ja.js +42 -25
  52. package/dist/i18n/ja.js.map +1 -1
  53. package/dist/i18n/ka.d.ts.map +1 -1
  54. package/dist/i18n/ka.js +42 -25
  55. package/dist/i18n/ka.js.map +1 -1
  56. package/dist/i18n/pt.d.ts.map +1 -1
  57. package/dist/i18n/pt.js +42 -25
  58. package/dist/i18n/pt.js.map +1 -1
  59. package/dist/i18n/ru.d.ts.map +1 -1
  60. package/dist/i18n/ru.js +42 -25
  61. package/dist/i18n/ru.js.map +1 -1
  62. package/dist/i18n/uk.d.ts.map +1 -1
  63. package/dist/i18n/uk.js +42 -25
  64. package/dist/i18n/uk.js.map +1 -1
  65. package/dist/i18n/uz.d.ts.map +1 -1
  66. package/dist/i18n/uz.js +42 -25
  67. package/dist/i18n/uz.js.map +1 -1
  68. package/dist/i18n/zh.d.ts.map +1 -1
  69. package/dist/i18n/zh.js +42 -25
  70. package/dist/i18n/zh.js.map +1 -1
  71. package/dist/i18n.d.ts +0 -12
  72. package/dist/i18n.d.ts.map +1 -1
  73. package/dist/i18n.js +6 -4
  74. package/dist/i18n.js.map +1 -1
  75. package/dist/requests/requestHeader.d.ts.map +1 -1
  76. package/dist/requests/requestHeader.js +30 -6
  77. package/dist/requests/requestHeader.js.map +1 -1
  78. package/dist/requests/sessionTurnProbe.d.ts +6 -1
  79. package/dist/requests/sessionTurnProbe.d.ts.map +1 -1
  80. package/dist/requests/sessionTurnProbe.js +4 -0
  81. package/dist/requests/sessionTurnProbe.js.map +1 -1
  82. package/dist/requests/types.d.ts +18 -4
  83. package/dist/requests/types.d.ts.map +1 -1
  84. package/dist/requests/wakeUpEngine.d.ts +13 -1
  85. package/dist/requests/wakeUpEngine.d.ts.map +1 -1
  86. package/dist/requests/wakeUpEngine.js +69 -8
  87. package/dist/requests/wakeUpEngine.js.map +1 -1
  88. package/dist/requests/wakeUpRules.d.ts +63 -2
  89. package/dist/requests/wakeUpRules.d.ts.map +1 -1
  90. package/dist/requests/wakeUpRules.js +67 -36
  91. package/dist/requests/wakeUpRules.js.map +1 -1
  92. package/dist/scheduler/mcpSurface.d.ts +30 -1
  93. package/dist/scheduler/mcpSurface.d.ts.map +1 -1
  94. package/dist/scheduler/mcpSurface.js +75 -15
  95. package/dist/scheduler/mcpSurface.js.map +1 -1
  96. package/dist/shutdown.d.ts +12 -0
  97. package/dist/shutdown.d.ts.map +1 -1
  98. package/dist/shutdown.js +11 -0
  99. package/dist/shutdown.js.map +1 -1
  100. package/dist/state.d.ts +11 -0
  101. package/dist/state.d.ts.map +1 -1
  102. package/dist/state.js +15 -0
  103. package/dist/state.js.map +1 -1
  104. package/dist/utils/backendSwitchPlan.d.ts +4 -1
  105. package/dist/utils/backendSwitchPlan.d.ts.map +1 -1
  106. package/dist/utils/backendSwitchPlan.js +6 -2
  107. package/dist/utils/backendSwitchPlan.js.map +1 -1
  108. package/dist/utils/claudeAccountAlert.d.ts +6 -3
  109. package/dist/utils/claudeAccountAlert.d.ts.map +1 -1
  110. package/dist/utils/claudeAccountAlert.js +13 -7
  111. package/dist/utils/claudeAccountAlert.js.map +1 -1
  112. package/dist/utils/claudeAccountPickerPlan.d.ts +17 -3
  113. package/dist/utils/claudeAccountPickerPlan.d.ts.map +1 -1
  114. package/dist/utils/claudeAccountPickerPlan.js +19 -4
  115. package/dist/utils/claudeAccountPickerPlan.js.map +1 -1
  116. package/dist/utils/claudeProfileLabels.d.ts +160 -0
  117. package/dist/utils/claudeProfileLabels.d.ts.map +1 -0
  118. package/dist/utils/claudeProfileLabels.js +283 -0
  119. package/dist/utils/claudeProfileLabels.js.map +1 -0
  120. package/dist/utils/claudeProfileUsageViews.d.ts +2 -0
  121. package/dist/utils/claudeProfileUsageViews.d.ts.map +1 -1
  122. package/dist/utils/claudeProfileUsageViews.js +3 -1
  123. package/dist/utils/claudeProfileUsageViews.js.map +1 -1
  124. package/dist/utils/claudeUsage.d.ts +5 -0
  125. package/dist/utils/claudeUsage.d.ts.map +1 -1
  126. package/dist/utils/claudeUsage.js +1 -0
  127. package/dist/utils/claudeUsage.js.map +1 -1
  128. package/dist/utils/fallbackChain.d.ts +4 -2
  129. package/dist/utils/fallbackChain.d.ts.map +1 -1
  130. package/dist/utils/fallbackChain.js +4 -3
  131. package/dist/utils/fallbackChain.js.map +1 -1
  132. package/dist/utils/fallbackSwitchNotice.d.ts +1 -1
  133. package/dist/utils/fallbackSwitchNotice.d.ts.map +1 -1
  134. package/dist/utils/fallbackSwitchNotice.js +4 -3
  135. package/dist/utils/fallbackSwitchNotice.js.map +1 -1
  136. package/dist/utils/limitSwitchPlan.d.ts +51 -14
  137. package/dist/utils/limitSwitchPlan.d.ts.map +1 -1
  138. package/dist/utils/limitSwitchPlan.js +33 -15
  139. package/dist/utils/limitSwitchPlan.js.map +1 -1
  140. package/dist/utils/limitsBoardPlan.d.ts +6 -4
  141. package/dist/utils/limitsBoardPlan.d.ts.map +1 -1
  142. package/dist/utils/limitsBoardPlan.js +11 -5
  143. package/dist/utils/limitsBoardPlan.js.map +1 -1
  144. package/dist/utils/threadStatusReport.d.ts +2 -0
  145. package/dist/utils/threadStatusReport.d.ts.map +1 -1
  146. package/dist/utils/threadStatusReport.js +4 -3
  147. package/dist/utils/threadStatusReport.js.map +1 -1
  148. package/dist/utils/workingSignals.d.ts +10 -0
  149. package/dist/utils/workingSignals.d.ts.map +1 -1
  150. package/dist/utils/workingSignals.js +22 -3
  151. package/dist/utils/workingSignals.js.map +1 -1
  152. package/npm-shrinkwrap.json +2 -2
  153. package/package.json +1 -1
package/dist/bot.js CHANGED
@@ -203,6 +203,7 @@ const instanceSettings_1 = require("./instanceSettings");
203
203
  const taskAgentLimit_1 = require("./trackers/taskAgentLimit");
204
204
  const taskAgentSlots_1 = require("./trackers/taskAgentSlots");
205
205
  const botSkills_1 = require("./utils/botSkills");
206
+ const claudeProfileLabels_1 = require("./utils/claudeProfileLabels");
206
207
  const constants_1 = require("./selfUpdate/constants");
207
208
  const launchEnvironment_1 = require("./selfUpdate/launchEnvironment");
208
209
  const restart_1 = require("./selfUpdate/restart");
@@ -2015,10 +2016,23 @@ const apiRetryKickDeps = {
2015
2016
  },
2016
2017
  resumeOnRung: async (key, rung) => {
2017
2018
  const from = getTopicFallbackPosition(key);
2019
+ const ownLimitedUntil = from?.backend === 'claude' ? state.getClaudeProfileInfo(from.profile)?.limitedUntil : undefined;
2020
+ const end = (0, limitSwitchPlan_1.decideAimedWaitEnd)({
2021
+ isTelegram: (0, sessionKeyCodec_1.checkIsTelegramKey)(key),
2022
+ isAutoSwitchEnabled: state.checkIsClaudeAutoSwitchOnLimitEnabled(key),
2023
+ ownLimitedUntilMs: ownLimitedUntil === undefined ? null : Date.parse(ownLimitedUntil),
2024
+ nowMs: Date.now(),
2025
+ });
2026
+ if (end.action === 'waitOwnReset') {
2027
+ await rearmLimitWaitForOwnReset(key, end.untilMs);
2028
+ return 'waitingAgain';
2029
+ }
2030
+ if (end.action === 'resumeHere')
2031
+ return 'notMoved';
2018
2032
  if (from !== null && (0, fallbackChain_1.checkIsSameFallbackAccount)(from, rung))
2019
- return false; // already there
2033
+ return 'notMoved'; // already there
2020
2034
  const outcome = await switchTopicToFallbackEntry(key, from, rung, { isAnnounced: true, isAutomatic: true });
2021
- return outcome.isSwitched;
2035
+ return outcome.isSwitched ? 'moved' : 'notMoved';
2022
2036
  },
2023
2037
  clearSavedRetry: clearSavedApiRetry,
2024
2038
  saveFiredLimitProbe: (key, firedAt) => {
@@ -2066,7 +2080,7 @@ async function announceUsageLimitOrSwitch(key, cls, episodeId, initialWait, atte
2066
2080
  if (plan.action === 'auto') {
2067
2081
  const to = plan.to;
2068
2082
  const outcome = await switchTopicToFallbackEntry(key, plan.from, to, { isAnnounced: true, isAutomatic: true }).catch((e) => {
2069
- console.warn(`[fallback] ${(0, sessionKey_1.keyToString)(key)}: the auto-switch to ${formatFallbackEntry(to)} failed:`, e instanceof Error ? e.message : e);
2083
+ console.warn(`[fallback] ${(0, sessionKey_1.keyToString)(key)}: the auto-switch to ${formatFallbackEntryById(to)} failed:`, e instanceof Error ? e.message : e);
2070
2084
  return { isSwitched: false };
2071
2085
  });
2072
2086
  if (outcome.isSwitched)
@@ -2094,11 +2108,11 @@ function buildFallbackSwitchKeyboard(episodeId, candidates) {
2094
2108
  telegraf_1.Markup.button.callback((0, i18n_1.t)('fallback.switchButton', { label: formatFallbackEntry(entry) }), (0, fallbackChain_1.buildFallbackSwitchCallbackData)(episodeId, index)),
2095
2109
  ]));
2096
2110
  }
2097
- /** Whose API credits a balance notice names: a Claude account `«console»`, an OpenCode `provider/model`. */
2111
+ /** Whose API credits a balance notice names: a Claude account by its display name `«Console»`, an OpenCode `provider/model`. */
2098
2112
  function formatBalanceOwner(from) {
2099
2113
  if (from === null)
2100
2114
  return (0, i18n_1.t)('fallback.backendClaude');
2101
- return from.backend === 'claude' ? `«${from.profile}»` : (0, fallbackChain_1.buildOpenCodeModelLabel)(from);
2115
+ return from.backend === 'claude' ? `«${(0, claudeProfileLabels_1.getClaudeProfileLabel)(from.profile)}»` : (0, fallbackChain_1.buildOpenCodeModelLabel)(from);
2102
2116
  }
2103
2117
  /**
2104
2118
  * @description A used-up API credit balance on `key` («Credit balance is too low», `isBalanceExhausted`): nothing resets
@@ -2148,7 +2162,7 @@ async function handleBalanceExhausted(key, cls) {
2148
2162
  if ((0, sessionKeyCodec_1.checkIsTelegramKey)(key))
2149
2163
  await replyToThread(key, notice);
2150
2164
  outcome = await switchTopicToFallbackEntry(key, plan.from, to, { isAnnounced: true, isAutomatic: true, ending }).catch((e) => {
2151
- console.warn(`[fallback] ${k}: the auto-switch to ${formatFallbackEntry(to)} failed:`, e instanceof Error ? e.message : e);
2165
+ console.warn(`[fallback] ${k}: the auto-switch to ${formatFallbackEntryById(to)} failed:`, e instanceof Error ? e.message : e);
2152
2166
  return { isSwitched: false };
2153
2167
  });
2154
2168
  }
@@ -2202,6 +2216,21 @@ function retargetLimitWait(key, episodeId, earliest) {
2202
2216
  .catch((e) => console.error('[apiRetry] persist failed:', e));
2203
2217
  return wait;
2204
2218
  }
2219
+ /**
2220
+ * @description The end of a wait aimed at another account, for a tracker conversation whose automatic switch was turned OFF
2221
+ * meanwhile (`decideAimedWaitEnd`): it stays where it is, and a new wait is armed for its own account's reset (`untilMs` + the
2222
+ * usual buffer), its record replacing the one that fired, and told to the open request like any limit wait.
2223
+ */
2224
+ async function rearmLimitWaitForOwnReset(key, untilMs) {
2225
+ const k = (0, sessionKey_1.keyToString)(key);
2226
+ const fired = apiRetryTimers.get(k);
2227
+ const attempt = fired?.attempt ?? 1;
2228
+ const fireAt = untilMs + apiErrorRetry_1.resetBufferMs;
2229
+ const wait = { kind: 'afterReset', resetAt: untilMs, fireAt };
2230
+ armApiRetryTimer(key, { kind: 'usageLimit', attempt, fireAt, delayMs: Math.max(fireAt - Date.now(), 0), attemptsByKind: fired?.attemptsByKind, limitWait: wait });
2231
+ console.log(`[fallback] ${k}: auto switch is off now — the wait aimed at another account goes on until its own account is back (${new Date(untilMs).toISOString()})`);
2232
+ await announceLimitWait(key, wait, getLimitWaitTexts(key, wait, attempt), false);
2233
+ }
2205
2234
  /**
2206
2235
  * @description A request opened during a usage-limit wait hears about it too
2207
2236
  * (the ledger's create hook): a scheduled run or a tracker event does not cancel
@@ -2224,7 +2253,8 @@ function announceLimitWaitToNewRequest(key) {
2224
2253
  * @description Both texts of a limit wait, from ONE branch on how it ends, in the
2225
2254
  * thread's locale. A wait ending on another day names the date. The
2226
2255
  * `/limits` + `/limits_autoswitch` pointer names Telegram commands — elsewhere it would
2227
- * be noise; the "auto-resume is off" text carries its own.
2256
+ * be noise; the "auto-resume is off" text carries its own. A wait aimed at another
2257
+ * rung names it in a topic only (`resumeOn`).
2228
2258
  */
2229
2259
  function getLimitWaitTexts(key, wait, attempt, resumeOn) {
2230
2260
  if (wait.kind === 'autoResumeOff') {
@@ -2237,7 +2267,8 @@ function getLimitWaitTexts(key, wait, attempt, resumeOn) {
2237
2267
  const zoneSuffix = (0, sessionKeyCodec_1.checkIsTelegramKey)(key) ? '' : ` ${getCurrentTimezone()}`;
2238
2268
  const time = `${(0, localClock_1.formatLocalClockWithDateIfNotToday)(wait.kind === 'afterReset' ? wait.resetAt : wait.fireAt, nowMs)}${zoneSuffix}`;
2239
2269
  const model = resumeOn ? formatFallbackEntry(resumeOn) : '';
2240
- const [noticeText, answerText] = wait.kind === 'afterReset' && resumeOn
2270
+ // A tracker's requester learns when the answer comes, not on which of the operator's accounts.
2271
+ const [noticeText, answerText] = wait.kind === 'afterReset' && resumeOn && (0, sessionKeyCodec_1.checkIsTelegramKey)(key)
2241
2272
  ? [(0, i18n_1.t)('apiRetry.usageLimitResetOnRungNotice', { time, model }), (0, i18n_1.t)('requests.limit.answerAfterResetOnRungNotice', { time, model })]
2242
2273
  : wait.kind === 'afterReset'
2243
2274
  ? [(0, i18n_1.t)('apiRetry.usageLimitResetNotice', { time }), (0, i18n_1.t)('requests.limit.answerAfterResetNotice', { time })]
@@ -2453,7 +2484,7 @@ const { cancelPendingLogin, checkIsAuthLoginAwaitingCode, cancelClaudeAuthLogin,
2453
2484
  clearAuthNotice,
2454
2485
  execFileAsync,
2455
2486
  onClaudeProfileAuthStatus: (key, profile, status) => claudeProfileAuthStatusSink?.(key, profile, status) ?? Promise.resolve(),
2456
- onClaudeProfileApiKey: (key, profile, apiKey) => claudeProfileApiKeySink?.(key, profile, apiKey) ?? Promise.resolve((0, i18n_1.t)('account.apiKeyNoDirectory', { name: profile.name })),
2487
+ onClaudeProfileApiKey: (key, profile, apiKey) => claudeProfileApiKeySink?.(key, profile, apiKey) ?? Promise.resolve((0, i18n_1.t)('account.apiKeyNoDirectory', { name: (0, claudeProfileLabels_1.getClaudeProfileLabel)(profile.name) })),
2457
2488
  checkIsProfileMissingFromLimitsList: (name) => (0, fallbackChain_1.checkIsClaudeProfileMissingFromChain)(state.getFallbackChain(), name),
2458
2489
  });
2459
2490
  /**
@@ -7855,7 +7886,8 @@ async function deliverClaudeAccountAlert(alert) {
7855
7886
  posts.push(postClaudeAccountAlertToTelegram(alert));
7856
7887
  const isActionRequired = alert.lost.length > 0;
7857
7888
  for (const channel of operatorAlertChannels) {
7858
- const text = (0, i18n_1.runWithLocale)('en', () => (0, claudeAccountAlert_1.renderClaudeAccountAlert)(alert, getHostClaudeSignInHow));
7889
+ // The connectors' channels render Markdown (a Jira comment): the operator's free-text names are escaped there.
7890
+ const text = (0, i18n_1.runWithLocale)('en', () => (0, claudeAccountAlert_1.renderClaudeAccountAlert)(alert, getHostClaudeSignInHow, { formatLabel: claudeProfileLabels_1.escapeClaudeProfileLabelForMarkdown }));
7859
7891
  posts.push(channel.post(text, { isActionRequired }).then((result) => {
7860
7892
  if (!result.ok)
7861
7893
  console.warn(`[accounts] the operator alert did not reach ${channel.label}: ${result.error}`);
@@ -7865,7 +7897,7 @@ async function deliverClaudeAccountAlert(alert) {
7865
7897
  }
7866
7898
  /**
7867
7899
  * @description The account alert in General, like the updater's: worded in that chat's language, the sign-in named as
7868
- * `/accounts login <name>`; an alert that asks to act is pinned (the pin is what reaches a muted operator) in place of the previous
7900
+ * `/accounts login <display name>` (its id when that name would find another account); an alert that asks to act is pinned (the pin is what reaches a muted operator) in place of the previous
7869
7901
  * one, and once no told account is left unusable the pin goes. `isPrivateChatClosed`: Telegram refused the private message about a
7870
7902
  * signed-out account (403) — the alert then also asks the operator to open a private chat with the bot.
7871
7903
  */
@@ -7876,7 +7908,7 @@ async function postClaudeAccountAlertToGeneral(alert, options) {
7876
7908
  return;
7877
7909
  }
7878
7910
  const renderOptions = options.isPrivateChatClosed ? { closedPrivateChatBot: getBotLabel() } : {};
7879
- const text = withThreadLocale(generalKey, () => (0, claudeAccountAlert_1.renderClaudeAccountAlert)(alert, (name) => `/accounts login ${name}`, renderOptions));
7911
+ const text = withThreadLocale(generalKey, () => (0, claudeAccountAlert_1.renderClaudeAccountAlert)(alert, (name) => `/accounts login ${(0, claudeProfileLabels_1.getClaudeProfileCommandName)(name)}`, renderOptions));
7880
7912
  const messageId = await replyToThread(generalKey, text);
7881
7913
  if (alert.lost.length === 0 || messageId === null) {
7882
7914
  await releaseClaudeAccountAlertPin();
@@ -7954,7 +7986,7 @@ async function settleClaudeAccountSignOutDms(alert) {
7954
7986
  */
7955
7987
  async function markClaudeAccountSignOutDmSignedIn(privateKey, name, messageId) {
7956
7988
  await state.setClaudeAccountAlertSignOutMessageId(name, null);
7957
- const text = withThreadLocale(privateKey, () => (0, i18n_1.t)('accounts.alert.back', { name }));
7989
+ const text = withThreadLocale(privateKey, () => (0, i18n_1.t)('accounts.alert.back', { name: (0, claudeProfileLabels_1.getClaudeProfileLabel)(name) }));
7958
7990
  if (await editThreadMessage(privateKey, messageId, text))
7959
7991
  console.log(`[accounts] the private message about ${name} now says it is signed in again`);
7960
7992
  else
@@ -8051,7 +8083,8 @@ async function handleClaudeAuthRefusal(key, cls) {
8051
8083
  if (!(0, sessionKeyCodec_1.checkIsTelegramKey)(key) && requestLimitWaitAnswerDeps) {
8052
8084
  await (0, limitWaitAnswer_1.answerOpenRequestsWithBotNotice)(requestLimitWaitAnswerDeps, key, {
8053
8085
  identity: `claudeAccountMove:${instead}`,
8054
- body: (0, i18n_1.t)('requests.account.movedAnswer', { from: from.profile, reason: (0, claudeAccountAlert_1.formatClaudeAccountRefusal)(reason), to: instead }),
8086
+ // A tracker's comment renders Markdown: the operator's free-text names are escaped.
8087
+ body: (0, i18n_1.t)('requests.account.movedAnswer', { from: (0, claudeProfileLabels_1.escapeClaudeProfileLabelForMarkdown)((0, claudeProfileLabels_1.getClaudeProfileLabel)(from.profile)), reason: (0, claudeAccountAlert_1.formatClaudeAccountRefusal)(reason), to: (0, claudeProfileLabels_1.escapeClaudeProfileLabelForMarkdown)((0, claudeProfileLabels_1.getClaudeProfileLabel)(instead)) }),
8055
8088
  isWakeStopped: false,
8056
8089
  }).catch((e) => console.warn(`[accounts] ${k}: telling the requests about the move failed:`, e instanceof Error ? e.message : e));
8057
8090
  }
@@ -8079,7 +8112,7 @@ async function waitForClaudeAccount(key) {
8079
8112
  }
8080
8113
  const reasons = getClaudeProfileUsageViews()
8081
8114
  .map((view) => ({ name: view.name, usability: (0, claudeAuthRefusal_1.getClaudeProfileUsability)(state.getClaudeProfileInfo(view.name)) }))
8082
- .flatMap(({ name, usability }) => (usability === 'usable' ? [] : [`«${name}» ${(0, claudeAccountAlert_1.formatClaudeAccountRefusal)(usability)}`]))
8115
+ .flatMap(({ name, usability }) => (usability === 'usable' ? [] : [`«${(0, claudeProfileLabels_1.escapeClaudeProfileLabelForMarkdown)((0, claudeProfileLabels_1.getClaudeProfileLabel)(name))}» ${(0, claudeAccountAlert_1.formatClaudeAccountRefusal)(usability)}`]))
8083
8116
  .join('; ');
8084
8117
  await (0, limitWaitAnswer_1.answerOpenRequestsWithBotNotice)(requestLimitWaitAnswerDeps, key, {
8085
8118
  // One wait, one answer per request: a later refused turn of the same wait (a new request's prompt) answers only the new request.
@@ -8336,7 +8369,7 @@ function getClaudeProfileUsageViews() {
8336
8369
  }
8337
8370
  /** One profile's usage view — the very one `/limits` renders, for the rows of `/accounts`. */
8338
8371
  function getClaudeProfileUsageView(name) {
8339
- return (0, claudeProfileUsageViews_1.buildClaudeProfileUsageView)({ dataDir: (0, state_1.resolveDataDir)(), name, record: state.getClaudeProfileInfo(name), creditAnchor: syncClaudeApiCreditAnchors()[name] });
8372
+ return (0, claudeProfileUsageViews_1.buildClaudeProfileUsageView)({ dataDir: (0, state_1.resolveDataDir)(), name, record: state.getClaudeProfileInfo(name), creditAnchor: syncClaudeApiCreditAnchors()[name], records: state.getAllClaudeProfileInfos() });
8340
8373
  }
8341
8374
  /** The model a topic's Claude session runs (or last ran), for the usage ranking's choice of windows. */
8342
8375
  function getThreadClaudeModel(key) {
@@ -8347,7 +8380,7 @@ function readStatusAccountSource(name) {
8347
8380
  syncClaudeApiCreditAnchors();
8348
8381
  const info = state.getClaudeProfileInfo(name);
8349
8382
  return {
8350
- name, email: info?.email ?? null, loggedIn: (0, claudeAuthRefusal_1.getClaudeProfileSignedIn)(info), limitedUntil: info?.limitedUntil ?? null,
8383
+ name, label: (0, claudeProfileLabels_1.getClaudeProfileLabel)(name), email: info?.email ?? null, loggedIn: (0, claudeAuthRefusal_1.getClaudeProfileSignedIn)(info), limitedUntil: info?.limitedUntil ?? null,
8351
8384
  billing: info?.billing ?? null, creditExhaustedAt: info?.creditExhaustedAt ?? null, ...(info?.apiSpend ? { apiSpend: info.apiSpend } : {}),
8352
8385
  };
8353
8386
  }
@@ -8357,8 +8390,15 @@ function checkIsClaudeProfileBackend(key) {
8357
8390
  return adapter instanceof claudeJsonStreamAdapter_1.ClaudeJsonStreamAdapter || adapter instanceof claudeCliAdapter_1.ClaudeCliAdapter;
8358
8391
  }
8359
8392
  // ── the fallback chain (`/fallback`): `utils/fallbackChain.ts`, `utils/fallbackBridge.ts`, `commands/fallbackChain.ts` ──
8360
- /** A chain rung for the topic's own language (the picker and the notices name it the same way). */
8393
+ /** A chain rung for the topic's own language (the picker and the notices name it the same way: an account by its display name). */
8361
8394
  function formatFallbackEntry(entry) {
8395
+ return (0, fallbackChain_1.formatFallbackEntryLabel)(entry, { claude: (0, i18n_1.t)('fallback.backendClaude'), openCode: (0, i18n_1.t)('fallback.backendOpenCode'), topicModel: (0, i18n_1.t)('fallback.topicModel'), profileLabel: claudeProfileLabels_1.getClaudeProfileLabel });
8396
+ }
8397
+ /**
8398
+ * A chain rung for the log and for the agent's context bridge: the same words, an account by its fixed id — what agents record and pass
8399
+ * to `claude_profiles` (a display name may change, and may hold an email).
8400
+ */
8401
+ function formatFallbackEntryById(entry) {
8362
8402
  return (0, fallbackChain_1.formatFallbackEntryLabel)(entry, { claude: (0, i18n_1.t)('fallback.backendClaude'), openCode: (0, i18n_1.t)('fallback.backendOpenCode'), topicModel: (0, i18n_1.t)('fallback.topicModel') });
8363
8403
  }
8364
8404
  /**
@@ -8472,10 +8512,10 @@ function notePersonActivity(key) {
8472
8512
  * offer is remembered per thread under its episode so only ITS buttons can act on it. `none` for a topic with no account to
8473
8513
  * switch from, or when no rung can take over.
8474
8514
  *
8475
- * A conversation of another platform (a Jira issue) takes the AUTOMATIC move only, and only between Claude accounts: the chain's
8476
- * Claude rungs when it has any (else the ranking), never an OpenCode rung (a cross-backend hand-over has no surface there). The
8477
- * offer's buttons and the wait aimed at the rung that resets first (the retry kick moves a topic there only for Telegram) are
8478
- * Telegram's: with auto-switch OFF, with no account free, or on OpenCode such a conversation waits for the reset as it always did.
8515
+ * A conversation of another platform (a Jira issue) takes the AUTOMATIC moves only, and only between Claude accounts: the chain's
8516
+ * Claude rungs when it has any (else the ranking), never an OpenCode rung (a cross-backend hand-over has no surface there). With no
8517
+ * account free its wait, like a topic's, ends at the EARLIEST reset of those accounts (`earliest`) and the retry kick moves it there;
8518
+ * the offer's buttons are Telegram's. With auto-switch OFF, or on OpenCode, such a conversation waits for its own reset.
8479
8519
  */
8480
8520
  async function planFallbackSwitch(key, cls, episodeId) {
8481
8521
  const from = getTopicFallbackPosition(key);
@@ -8509,7 +8549,7 @@ async function planFallbackSwitch(key, cls, episodeId) {
8509
8549
  // a stuck usage endpoint must never hold the switch or the wait notice of a topic that just hit its limit.
8510
8550
  await (0, usageRefreshBudget_1.refreshUsageWithinBudget)((options) => claudeUsageRefresher.refreshAll(options));
8511
8551
  const detection = await detectFallbackOptions();
8512
- const { plan, waitRungs } = (0, limitSwitchPlan_1.decideLimitSwitch)({
8552
+ const { plan, waitTarget } = (0, limitSwitchPlan_1.decideLimitSwitch)({
8513
8553
  isTelegram,
8514
8554
  from,
8515
8555
  chain: state.getFallbackChain(),
@@ -8521,16 +8561,10 @@ async function planFallbackSwitch(key, cls, episodeId) {
8521
8561
  fallbackSwitchOffers.set(k, { episodeId, from, candidates: plan.candidates });
8522
8562
  else
8523
8563
  fallbackSwitchOffers.delete(k);
8524
- const detail = plan.action === 'auto' ? ` → ${formatFallbackEntry(plan.to)}` : plan.action === 'offer' ? ` [${plan.candidates.map(formatFallbackEntry).join(', ')}]` : '';
8525
- // Nothing has room: the wait should end on the rung whose limit resets EARLIEST, not necessarily this one (a topic's wait only).
8526
- let earliest = null;
8527
- if (waitRungs.length > 0) {
8528
- const found = (0, fallbackChain_1.pickEarliestResetRung)({ chain: waitRungs, current: from, detection, nowMs: Date.now() });
8529
- if (found && !found.isCurrent)
8530
- earliest = { entry: found.entry, untilMs: found.untilMs };
8531
- }
8532
- console.log(`[fallback] ${k}: usage limit on ${formatFallbackEntry(from)}; switch plan: ${plan.action}${detail}${earliest ? `; earliest reset: ${formatFallbackEntry(earliest.entry)} at ${new Date(earliest.untilMs).toISOString()}` : ''}`);
8533
- return { ...plan, from, earliest };
8564
+ const detail = plan.action === 'auto' ? ` → ${formatFallbackEntryById(plan.to)}` : plan.action === 'offer' ? ` [${plan.candidates.map(formatFallbackEntryById).join(', ')}]` : '';
8565
+ // Nothing has room: the wait should end on the rung whose limit resets EARLIEST, not necessarily this one.
8566
+ console.log(`[fallback] ${k}: usage limit on ${formatFallbackEntryById(from)}; switch plan: ${plan.action}${detail}${waitTarget ? `; earliest reset: ${formatFallbackEntryById(waitTarget.entry)} at ${new Date(waitTarget.untilMs).toISOString()}` : ''}`);
8567
+ return { ...plan, from, earliest: waitTarget };
8534
8568
  }
8535
8569
  /** When the rung that hit the limit comes back, as a clock in the topic's zone; `null` when unknown or past. */
8536
8570
  function getFallbackResetTime(from) {
@@ -8553,7 +8587,7 @@ function getFallbackSwitchedNotice(from, to, runningModel, reason = 'limit') {
8553
8587
  const info = to.backend === 'claude' ? state.getClaudeProfileInfo(to.profile) : undefined;
8554
8588
  if (to.backend !== 'claude' || info?.billing !== 'api')
8555
8589
  return notice;
8556
- return `${notice}\n${(0, i18n_1.t)('fallback.switchedToApi', { name: to.profile, spent: (0, claudeApiSpend_1.formatUsd)(info.apiSpend?.totalUsd ?? 0) })}`;
8590
+ return `${notice}\n${(0, i18n_1.t)('fallback.switchedToApi', { name: (0, claudeProfileLabels_1.getClaudeProfileLabel)(to.profile), spent: (0, claudeApiSpend_1.formatUsd)(info.apiSpend?.totalUsd ?? 0) })}`;
8557
8591
  }
8558
8592
  /** The spend line a «credits used up» notice ends with (what the account spent through the bot); `''` before any spend. */
8559
8593
  function getBalanceSpentLine(from) {
@@ -8662,7 +8696,6 @@ async function switchTopicToFallbackEntry(key, from, to, options) {
8662
8696
  async function switchTopicToFallbackEntryNow(key, from, to, options) {
8663
8697
  const reason = options.reason ?? 'limit';
8664
8698
  const k = (0, sessionKey_1.keyToString)(key);
8665
- const fromLabel = from ? formatFallbackEntry(from) : '?';
8666
8699
  const toLabel = formatFallbackEntry(to);
8667
8700
  const runningModel = readRunningModelBeforeMove(key, from, to);
8668
8701
  // The notice is a topic message: a conversation of another platform (a Jira issue) hears nothing — the log line below says it — and
@@ -8718,8 +8751,8 @@ async function switchTopicToFallbackEntryNow(key, from, to, options) {
8718
8751
  let bridge;
8719
8752
  try {
8720
8753
  bridge = await buildFallbackBridge(key, {
8721
- fromLabel: from ? formatFallbackEntry(from) : formatThreadBackend(key),
8722
- toLabel: toLabel,
8754
+ fromLabel: from ? formatFallbackEntryById(from) : formatThreadBackend(key),
8755
+ toLabel: formatFallbackEntryById(to),
8723
8756
  reason: 'limit',
8724
8757
  resetsAtText: getFallbackResetTime(from),
8725
8758
  });
@@ -8745,7 +8778,7 @@ async function switchTopicToFallbackEntryNow(key, from, to, options) {
8745
8778
  try {
8746
8779
  cancelApiRetry(key); // retires the offer too: the switch consumed it
8747
8780
  const notice = `${getFallbackSwitchedNotice(from, to, runningModel, reason)}${isStoppingBackground ? `\n${(0, i18n_1.t)('fallback.backgroundStopped')}` : ''}`;
8748
- console.log(`[fallback] ${k}: switched from ${fromLabel} to ${toLabel} after ${reason === 'signIn' ? 'its account was refused' : 'a usage limit'}${firstPrompt ? ' (cross-backend, bridged)' : ''}; resuming`);
8781
+ console.log(`[fallback] ${k}: switched from ${from ? formatFallbackEntryById(from) : '?'} to ${formatFallbackEntryById(to)} after ${reason === 'signIn' ? 'its account was refused' : 'a usage limit'}${firstPrompt ? ' (cross-backend, bridged)' : ''}; resuming`);
8749
8782
  await say(notice);
8750
8783
  await resumeTopicOnNewSession(key, {
8751
8784
  modelToPin: (0, fallbackChain_1.getFallbackModelToPin)(to, runningModel),
@@ -8988,7 +9021,7 @@ async function switchTopicByOperator(key, to) {
8988
9021
  return { kind: 'refused', text: moved.notice };
8989
9022
  if (to.backend === 'opencode')
8990
9023
  return { kind: 'switched', text: (0, i18n_1.t)('backendSwitch.switched', { to: label }), label };
8991
- return { kind: 'switched', text: (0, i18n_1.t)('account.setThisTopic', { name: to.profile, apply: (0, i18n_1.t)(`account.applied.${moved.isSwitched ? 'respawned' : 'deferred'}`) }), label };
9024
+ return { kind: 'switched', text: (0, i18n_1.t)('account.setThisTopic', { name: (0, claudeProfileLabels_1.getClaudeProfileLabel)(to.profile), apply: (0, i18n_1.t)(`account.applied.${moved.isSwitched ? 'respawned' : 'deferred'}`) }), label };
8992
9025
  }
8993
9026
  case 'sameFamily': {
8994
9027
  if (to.backend === 'opencode') {
@@ -9003,7 +9036,7 @@ async function switchTopicByOperator(key, to) {
9003
9036
  if (!isModelChangeOnly) {
9004
9037
  await state.setClaudeProfileOverride(key, to.profile);
9005
9038
  const outcome = await applyClaudeProfileToThread(key);
9006
- switchedText = (0, i18n_1.t)('account.setThisTopic', { name: to.profile, apply: (0, i18n_1.t)(`account.applied.${outcome}`) });
9039
+ switchedText = (0, i18n_1.t)('account.setThisTopic', { name: (0, claudeProfileLabels_1.getClaudeProfileLabel)(to.profile), apply: (0, i18n_1.t)(`account.applied.${outcome}`) });
9007
9040
  }
9008
9041
  const modelToPin = (0, fallbackChain_1.getFallbackModelToPin)(to, runningModel);
9009
9042
  if (modelToPin === null)
@@ -9536,10 +9569,11 @@ command(escapeCommandNames, async (ctx, key) => {
9536
9569
  // A talker's /esc only interrupts the running turn: the prompts below are an admin's (a sign-in, a name for an account or a
9537
9570
  // topic), and ending one is the admin's own word.
9538
9571
  if ((await authoriseTopicSpeaker(ctx))?.role !== 'talker') {
9539
- // A pending «Add account» name prompt, a pending sign-in (`/login`, `/connect` OAuth) and a `/topic` wizard take
9540
- // priority: the first /esc only cancels it, so the topic stops waiting for typed input.
9541
- if (cancelProfileNameCapture(key)) {
9542
- await replyToThread(key, (0, i18n_1.t)('account.askNameCancelled'));
9572
+ // A pending «Add account» name prompt (or ✏️'s new name), a pending sign-in (`/login`, `/connect` OAuth) and a `/topic` wizard
9573
+ // take priority: the first /esc only cancels it, so the topic stops waiting for typed input.
9574
+ const cancelledCapture = cancelProfileNameCapture(key);
9575
+ if (cancelledCapture !== null) {
9576
+ await replyToThread(key, (0, i18n_1.t)(cancelledCapture === 'rename' ? 'account.renameCancelled' : 'account.askNameCancelled'));
9543
9577
  return;
9544
9578
  }
9545
9579
  if (cancelPendingLogin(key)) {
@@ -15227,6 +15261,8 @@ async function startBot() {
15227
15261
  (0, createAdapter_1.registerClaudeConfigDirReader)(resolveThreadClaudeConfigDir);
15228
15262
  // The «Bot skills» switch (`/bot_skills`): every agent start, the OpenCode server's start and the bot MCP's instructions read it.
15229
15263
  (0, botSkills_1.setBotSkillsReader)(botSkillsReader);
15264
+ // Every screen that names a Claude account shows its display name (`/accounts` ✏️), read live off the registry.
15265
+ (0, claudeProfileLabels_1.setClaudeProfileLabelReader)(() => state.getAllClaudeProfileInfos());
15230
15266
  // The flags the CLI's and OpenCode's own compactions read for `/compact_self_review` follow the saved settings from the start.
15231
15267
  syncAllCompactSelfReviewFlags();
15232
15268
  (0, createAdapter_1.registerClaudeRateLimitSink)(onClaudeRateLimitEvent);
@@ -15306,6 +15342,8 @@ async function startBot() {
15306
15342
  progressFollowUpMs: ENV.testTimings.progressFollowUpMs,
15307
15343
  // A request waits for its schedule while a job armed under it counts (`requests/scheduleWait.ts`): read when a decision is made.
15308
15344
  getScheduleWait: (key, request) => (0, scheduleWait_1.getRequestScheduleWait)(state.getThreadSchedules(key), request),
15345
+ // A tracker issue is never reminded on a clock: a progress note with nothing armed under it gets one nudge, the next stall the give-up.
15346
+ getWakeUpRules: (key) => ((0, sessionKeyCodec_1.checkIsTelegramKey)(key) ? 'topic' : 'tracker'),
15309
15347
  // Only a Telegram topic in the answers-only view hides the stream from someone who expects to see the work.
15310
15348
  checkIsAnswerTailWatched: (key) => (0, sessionKeyCodec_1.checkIsTelegramKey)(key) && !(0, topicView_1.checkIsStreamShown)(state.getDisplayPrefs(key).view),
15311
15349
  remindAnswerTail,
@@ -15829,6 +15867,9 @@ async function startBot() {
15829
15867
  exit,
15830
15868
  drainPendingUpdates: () => updateDispatcher.drainIdle(updateDrainTimeoutMs),
15831
15869
  finalizePendingOutput: () => finalizePendingOutputOnShutdown(),
15870
+ // The agents' tool calls already running (an answer being posted and pinned) finish before the server goes: cut, the agent
15871
+ // would be told the call failed although the requester already sees its answer.
15872
+ stopBotMcp: isSchedulerMcpStarted ? () => schedulerMcpHandle.stop({ drainMs: mcpSurface_1.schedulerMcpShutdownDrainMs }) : undefined,
15832
15873
  clearTransientFrames: () => sweepTransientFramesOnShutdown(),
15833
15874
  // A hot worker's reload keeps the sidecar for the next worker to adopt; the supervisor stops it for good.
15834
15875
  stopSidecars: (0, installManager_1.checkIsOpenCodeExternalHost)() ? undefined : () => sttOwner.stop(),
@@ -15848,8 +15889,6 @@ async function startBot() {
15848
15889
  limitNotesEngine?.stop();
15849
15890
  topicIndicator.stop();
15850
15891
  jiraConnector?.stop();
15851
- if (isSchedulerMcpStarted)
15852
- void schedulerMcpHandle.stop().catch(() => { });
15853
15892
  updateEngine?.stop();
15854
15893
  },
15855
15894
  });