@integrity-labs/agt-cli 0.28.1206 → 0.28.1207

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/dist/bin/agt.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  success,
41
41
  table,
42
42
  warn
43
- } from "../chunk-4KVM4X2T.js";
43
+ } from "../chunk-2OGWB6NR.js";
44
44
  import {
45
45
  getProjectDir,
46
46
  isSessionResumeDisabled,
@@ -5200,7 +5200,7 @@ import { execFileSync, execSync } from "child_process";
5200
5200
  import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
5201
5201
  import chalk17 from "chalk";
5202
5202
  import ora15 from "ora";
5203
- var cliVersion = true ? "0.28.1206" : "dev";
5203
+ var cliVersion = true ? "0.28.1207" : "dev";
5204
5204
  async function fetchLatestVersion() {
5205
5205
  const host2 = getHost();
5206
5206
  if (!host2) return null;
@@ -6460,7 +6460,7 @@ function handleError(err) {
6460
6460
  }
6461
6461
 
6462
6462
  // src/bin/agt.ts
6463
- var cliVersion2 = true ? "0.28.1206" : "dev";
6463
+ var cliVersion2 = true ? "0.28.1207" : "dev";
6464
6464
  var program = new Command();
6465
6465
  program.name("agt").description("Augmented CLI \u2014 agent provisioning and management").version(cliVersion2).option("--json", "Emit machine-readable JSON output (suppress spinners and colors)").option("--skip-update-check", "Skip the automatic update check on startup");
6466
6466
  program.hook("preAction", async (thisCommand, actionCommand) => {
@@ -8082,7 +8082,7 @@ function exchangeFailureKind(err) {
8082
8082
  }
8083
8083
 
8084
8084
  // src/lib/api-client.ts
8085
- var agtCliVersion = true ? "0.28.1206" : "dev";
8085
+ var agtCliVersion = true ? "0.28.1207" : "dev";
8086
8086
  var lastConfigHash = null;
8087
8087
  function setConfigHash(hash) {
8088
8088
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -13683,4 +13683,4 @@ export {
13683
13683
  managerInstallSystemUnitCommand,
13684
13684
  managerUninstallSystemUnitCommand
13685
13685
  };
13686
- //# sourceMappingURL=chunk-4KVM4X2T.js.map
13686
+ //# sourceMappingURL=chunk-2OGWB6NR.js.map
@@ -85,7 +85,7 @@ import {
85
85
  tripClass,
86
86
  writeEtcEnvironment,
87
87
  writeProfileDScript
88
- } from "../chunk-4KVM4X2T.js";
88
+ } from "../chunk-2OGWB6NR.js";
89
89
  import {
90
90
  CLAUDE_CODE_SECURITY_FLOOR,
91
91
  SELF_UPDATE_TIMEOUTS,
@@ -9701,6 +9701,26 @@ function pickHintVariant(rng = Math.random) {
9701
9701
  return HINT_VARIANTS[idx];
9702
9702
  }
9703
9703
 
9704
+ // src/lib/manager/channels/transient-retry.ts
9705
+ var MAX_DELIVERY_ATTEMPTS = 3;
9706
+ var DELIVERY_RETRY_BUDGET_MS = 2e4;
9707
+ var BACKOFF_MS = [500, 1500];
9708
+ var defaultSleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
9709
+ function deliveryRetryDeadline() {
9710
+ return Date.now() + DELIVERY_RETRY_BUDGET_MS;
9711
+ }
9712
+ async function withTransientRetry(attempt, options = {}) {
9713
+ const deadline = options.deadline ?? deliveryRetryDeadline();
9714
+ const sleep2 = options.sleep ?? defaultSleep;
9715
+ for (let n = 1; ; n += 1) {
9716
+ const result = await attempt();
9717
+ if (!result.transient || n >= MAX_DELIVERY_ATTEMPTS) return result.value;
9718
+ const waitMs = Math.max(BACKOFF_MS[n - 1] ?? 0, result.retryAfterMs ?? 0);
9719
+ if (Date.now() + waitMs > deadline) return result.value;
9720
+ await sleep2(waitMs);
9721
+ }
9722
+ }
9723
+
9704
9724
  // src/lib/manager/channels/slack.ts
9705
9725
  async function sendSlackWebhookMessage(text) {
9706
9726
  const alertSlackWebhook2 = getAlertSlackWebhook();
@@ -9728,44 +9748,88 @@ async function sendSlackWebhookMessage(text) {
9728
9748
  log(`Slack webhook error: ${err.message}`);
9729
9749
  }
9730
9750
  }
9731
- async function sendSlackChannelMessage(agentCodeName, channelId, text) {
9732
- const result = await postSlackChannelMessage(agentCodeName, channelId, text);
9733
- return result.ok;
9734
- }
9735
- async function postSlackChannelMessage(agentCodeName, channelId, text, threadTs) {
9751
+ async function postSlackChannelMessage(agentCodeName, channelId, text, threadTs, options = {}) {
9736
9752
  const botToken = agentChannelTokens.get(agentCodeName)?.slack;
9737
9753
  if (!botToken) {
9738
9754
  log(`No Slack bot token cached for '${agentCodeName}' \u2014 cannot post to ${channelId}`);
9739
9755
  return { ok: false };
9740
9756
  }
9757
+ const body = { channel: channelId, text };
9758
+ if (threadTs) body.thread_ts = threadTs;
9759
+ const attempt = async () => {
9760
+ const result = await slackApiAttempt(botToken, "chat.postMessage", body);
9761
+ if (!result.value.ok) {
9762
+ log(`Slack chat.postMessage failed for '${agentCodeName}' to ${channelId}: ${result.value.error}`);
9763
+ return { ...result, value: { ok: false, error: result.value.error } };
9764
+ }
9765
+ return { ...result, value: { ok: true, ts: result.value.ts } };
9766
+ };
9767
+ if (!options.retry) return (await attempt()).value;
9768
+ return withTransientRetry(attempt, { deadline: options.deadline });
9769
+ }
9770
+ async function openSlackDmChannel(agentCodeName, botToken, slackUserId, options = {}) {
9771
+ const opened = await withTransientRetry(async () => {
9772
+ const result = await slackApiAttempt(
9773
+ botToken,
9774
+ "conversations.open",
9775
+ { users: slackUserId }
9776
+ );
9777
+ if (!result.value.ok) {
9778
+ log(`Slack conversations.open failed for '${agentCodeName}': ${result.value.error}`);
9779
+ }
9780
+ return result;
9781
+ }, options);
9782
+ if (!opened.ok || !opened.channel?.id) return { ok: false, error: opened.error ?? "unknown" };
9783
+ return { ok: true, channelId: opened.channel.id };
9784
+ }
9785
+ var TRANSIENT_SLACK_ERRORS = /* @__PURE__ */ new Set([
9786
+ "ratelimited",
9787
+ "rate_limited",
9788
+ "internal_error",
9789
+ "fatal_error",
9790
+ "service_unavailable",
9791
+ "request_timeout"
9792
+ ]);
9793
+ function parseRetryAfterMs(header) {
9794
+ if (header === null) return void 0;
9795
+ const seconds = Number(header);
9796
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : void 0;
9797
+ }
9798
+ async function slackApiAttempt(botToken, method, body) {
9799
+ const fail = (error, transient, retryAfterMs) => ({
9800
+ value: { ok: false, error },
9801
+ transient,
9802
+ retryAfterMs
9803
+ });
9804
+ const controller = new AbortController();
9805
+ const timeout = setTimeout(() => controller.abort(), 5e3);
9741
9806
  try {
9742
- const controller = new AbortController();
9743
- const timeout = setTimeout(() => controller.abort(), 5e3);
9744
- try {
9745
- const body = { channel: channelId, text };
9746
- if (threadTs) body.thread_ts = threadTs;
9747
- const response = await fetch("https://slack.com/api/chat.postMessage", {
9748
- method: "POST",
9749
- headers: {
9750
- "Authorization": `Bearer ${botToken}`,
9751
- "Content-Type": "application/json"
9752
- },
9753
- body: JSON.stringify(body),
9754
- signal: controller.signal
9755
- });
9756
- clearTimeout(timeout);
9757
- const data = await response.json();
9758
- if (!data.ok) {
9759
- log(`Slack chat.postMessage failed for '${agentCodeName}' to ${channelId}: ${data.error}`);
9760
- return { ok: false, error: data.error };
9761
- }
9762
- return { ok: true, ts: data.ts };
9763
- } finally {
9764
- clearTimeout(timeout);
9807
+ const response = await fetch(`https://slack.com/api/${method}`, {
9808
+ method: "POST",
9809
+ headers: {
9810
+ "Authorization": `Bearer ${botToken}`,
9811
+ "Content-Type": "application/json; charset=utf-8"
9812
+ },
9813
+ body: JSON.stringify(body),
9814
+ signal: controller.signal
9815
+ });
9816
+ if (response.status === 429) {
9817
+ return fail("ratelimited", true, parseRetryAfterMs(response.headers.get("retry-after")));
9765
9818
  }
9819
+ if (response.status >= 500) return fail(`http_${response.status}`, true);
9820
+ if (!response.ok) return fail(`http_${response.status}`, false);
9821
+ const data = await response.json();
9822
+ return {
9823
+ value: data,
9824
+ transient: !data.ok && TRANSIENT_SLACK_ERRORS.has(data.error ?? ""),
9825
+ retryAfterMs: parseRetryAfterMs(response.headers.get("retry-after"))
9826
+ };
9766
9827
  } catch (err) {
9767
- log(`Slack channel message error for '${agentCodeName}': ${err.message}`);
9768
- return { ok: false };
9828
+ const name = err.name;
9829
+ if (name === "AbortError") return fail("timeout", true);
9830
+ return fail(name === "SyntaxError" ? "invalid_response" : "network_error", true);
9831
+ } finally {
9832
+ clearTimeout(timeout);
9769
9833
  }
9770
9834
  }
9771
9835
  async function maybePostSlackThreadHint(agentCodeName, channelId, primaryTs) {
@@ -9782,6 +9846,27 @@ async function maybePostSlackThreadHint(agentCodeName, channelId, primaryTs) {
9782
9846
 
9783
9847
  // src/lib/manager/channels/telegram.ts
9784
9848
  import https from "https";
9849
+ async function sendTelegramMessageWithRetry(botToken, body, options = {}) {
9850
+ let thrown;
9851
+ const result = await withTransientRetry(async () => {
9852
+ thrown = void 0;
9853
+ try {
9854
+ const value = await telegramApiCall(botToken, "sendMessage", body);
9855
+ const code = value.error_code ?? 0;
9856
+ const retryAfter = value.parameters?.retry_after;
9857
+ return {
9858
+ value,
9859
+ transient: !value.ok && (code === 429 || code >= 500),
9860
+ retryAfterMs: typeof retryAfter === "number" ? retryAfter * 1e3 : void 0
9861
+ };
9862
+ } catch (err) {
9863
+ thrown = err;
9864
+ return { value: null, transient: true };
9865
+ }
9866
+ }, options);
9867
+ if (result === null) throw thrown;
9868
+ return result;
9869
+ }
9785
9870
  function telegramApiCall(botToken, method, body) {
9786
9871
  return new Promise((resolve2, reject) => {
9787
9872
  const postData = JSON.stringify(body);
@@ -9984,8 +10069,9 @@ async function sendTaskNotification(agentCodeName, channel, to, text) {
9984
10069
  log(`No Slack bot token for '${agentCodeName}' \u2014 targeted notification dropped`);
9985
10070
  return { ok: false, error_code: "SLACK_NO_TOKEN" };
9986
10071
  }
9987
- const sent = await sendSlackChannelMessage(agentCodeName, channelId, text);
9988
- return sent ? { ok: true } : { ok: false, error_code: "SLACK_SEND_FAILED" };
10072
+ const sent = await postSlackChannelMessage(agentCodeName, channelId, text, void 0, { retry: true });
10073
+ if (sent.ok) return { ok: true };
10074
+ return { ok: false, error_code: sent.error ? `SLACK_SEND_FAILED:${sent.error}` : "SLACK_SEND_FAILED" };
9989
10075
  }
9990
10076
  if (channel === "telegram") {
9991
10077
  const botToken = tokens?.telegram;
@@ -10000,7 +10086,7 @@ async function sendTaskNotification(agentCodeName, channel, to, text) {
10000
10086
  return { ok: false, error_code: "TELEGRAM_CHAT_NOT_ALLOWED" };
10001
10087
  }
10002
10088
  try {
10003
- const result = await telegramApiCall(botToken, "sendMessage", { chat_id: chatId, text });
10089
+ const result = await sendTelegramMessageWithRetry(botToken, { chat_id: chatId, text });
10004
10090
  if (!result.ok) {
10005
10091
  log(`Telegram sendMessage failed for '${agentCodeName}': ${result.description}`);
10006
10092
  return { ok: false, error_code: `TELEGRAM_SEND_FAILED:${result.description ?? "unknown"}` };
@@ -10228,11 +10314,19 @@ async function enqueueScheduledTaskNotice(opts) {
10228
10314
 
10229
10315
  // src/lib/manager/delivery/scheduled-output.ts
10230
10316
  async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, body, taskId) {
10317
+ let last = null;
10318
+ await runDelivery(agentCodeName, agentId, rawTarget, body, taskId, async (report) => {
10319
+ last = report;
10320
+ await reportDeliveryStatus(agentId, taskId, report);
10321
+ });
10322
+ return last;
10323
+ }
10324
+ async function runDelivery(agentCodeName, agentId, rawTarget, body, taskId, report) {
10231
10325
  const withLink = (b, medium) => withScheduleLinkFooter({ body: b, medium, codeName: agentCodeName, agentId, taskId, log });
10232
10326
  if (typeof rawTarget === "string") {
10233
10327
  if (rawTarget.startsWith("channel:")) {
10234
10328
  const result = await sendTaskNotification(agentCodeName, "slack", rawTarget, withLink(body, "slack"));
10235
- await reportDeliveryStatus(agentId, taskId, {
10329
+ await report({
10236
10330
  status: result.ok ? "ok" : "failed",
10237
10331
  medium: "slack",
10238
10332
  error_code: result.ok ? null : result.error_code ?? "SLACK_SEND_FAILED"
@@ -10241,7 +10335,7 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10241
10335
  }
10242
10336
  if (rawTarget.startsWith("chat:")) {
10243
10337
  const result = await sendTaskNotification(agentCodeName, "telegram", rawTarget, withLink(body, "telegram"));
10244
- await reportDeliveryStatus(agentId, taskId, {
10338
+ await report({
10245
10339
  status: result.ok ? "ok" : "failed",
10246
10340
  medium: "telegram",
10247
10341
  error_code: result.ok ? null : result.error_code ?? "TELEGRAM_SEND_FAILED"
@@ -10249,27 +10343,28 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10249
10343
  return;
10250
10344
  }
10251
10345
  log(`[delivery] Unrecognised legacy delivery_to string for '${agentCodeName}': ${rawTarget.slice(0, 60)}`);
10252
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: "LEGACY_DELIVERY_TO_UNRECOGNISED" });
10346
+ await report({ status: "failed", error_code: "LEGACY_DELIVERY_TO_UNRECOGNISED" });
10253
10347
  return;
10254
10348
  }
10255
10349
  const parsed = parseDeliveryTarget(rawTarget);
10256
10350
  if (isParseError(parsed)) {
10257
10351
  log(`[delivery] Malformed delivery_to for '${agentCodeName}': ${parsed.code} \u2014 ${parsed.detail}`);
10258
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: parsed.code });
10352
+ await report({ status: "failed", error_code: parsed.code });
10259
10353
  return;
10260
10354
  }
10261
10355
  if (parsed.kind === "channel") {
10262
10356
  if (parsed.provider === "slack") {
10263
10357
  const channelId = parsed.channel_id ?? "";
10264
10358
  const threadTs = parsed.thread_ts;
10265
- let sent = await postSlackChannelMessage(agentCodeName, channelId, withLink(body, "slack"), threadTs);
10359
+ const retry = { retry: true, deadline: deliveryRetryDeadline() };
10360
+ let sent = await postSlackChannelMessage(agentCodeName, channelId, withLink(body, "slack"), threadTs, retry);
10266
10361
  let deliveredInThread = Boolean(threadTs);
10267
10362
  if (!sent.ok && threadTs && (sent.error === "thread_not_found" || sent.error === "message_not_found")) {
10268
10363
  log(`[delivery] Originating thread ${threadTs} gone in ${channelId} for '${agentCodeName}' \u2014 falling back to top-level post`);
10269
- sent = await postSlackChannelMessage(agentCodeName, channelId, withLink(body, "slack"));
10364
+ sent = await postSlackChannelMessage(agentCodeName, channelId, withLink(body, "slack"), void 0, retry);
10270
10365
  deliveredInThread = false;
10271
10366
  }
10272
- await reportDeliveryStatus(agentId, taskId, {
10367
+ await report({
10273
10368
  status: sent.ok ? "ok" : "failed",
10274
10369
  medium: "slack",
10275
10370
  // Preserve Slack's concrete failure code (channel_not_found,
@@ -10290,7 +10385,7 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10290
10385
  const chatId = parsed.chat_id ?? "";
10291
10386
  const toStr = `chat:${chatId}`;
10292
10387
  const result = await sendTaskNotification(agentCodeName, "telegram", toStr, withLink(body, "telegram"));
10293
- await reportDeliveryStatus(agentId, taskId, {
10388
+ await report({
10294
10389
  status: result.ok ? "ok" : "failed",
10295
10390
  medium: "telegram",
10296
10391
  error_code: result.ok ? null : result.error_code ?? "TELEGRAM_SEND_FAILED"
@@ -10304,13 +10399,13 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10304
10399
  const agentRow = agentInfoForDelivery.get(agentCodeName);
10305
10400
  if (!agentRow) {
10306
10401
  log(`[delivery] No agent metadata cached for '${agentCodeName}' \u2014 dropping DM`);
10307
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: "AGENT_METADATA_UNAVAILABLE" });
10402
+ await report({ status: "failed", error_code: "AGENT_METADATA_UNAVAILABLE" });
10308
10403
  return;
10309
10404
  }
10310
10405
  const resolved = resolveDmTarget(parsed, agentRow.resolverAgent, agentRow.peopleByPersonId);
10311
10406
  if (isResolveError(resolved)) {
10312
10407
  log(`[delivery] Cannot resolve DM target for '${agentCodeName}': ${resolved.code} \u2014 ${resolved.detail}`);
10313
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: resolved.code });
10408
+ await report({ status: "failed", error_code: resolved.code });
10314
10409
  return;
10315
10410
  }
10316
10411
  const attributionBody = appendDmFooter(
@@ -10323,47 +10418,24 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10323
10418
  const tokens = agentChannelTokens.get(agentCodeName);
10324
10419
  const botToken = tokens?.slack;
10325
10420
  if (!botToken) {
10326
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: "SLACK_MISSING_SCOPE", medium: "slack" });
10421
+ await report({ status: "failed", error_code: "SLACK_MISSING_SCOPE", medium: "slack" });
10327
10422
  log(`[delivery] No Slack bot token for '${agentCodeName}' \u2014 DM dropped`);
10328
10423
  return;
10329
10424
  }
10330
- try {
10331
- const controller = new AbortController();
10332
- const timeoutHandle = setTimeout(() => controller.abort(), 5e3);
10333
- let openJson;
10334
- try {
10335
- const openResp = await fetch("https://slack.com/api/conversations.open", {
10336
- method: "POST",
10337
- headers: {
10338
- Authorization: `Bearer ${botToken}`,
10339
- "Content-Type": "application/json; charset=utf-8"
10340
- },
10341
- body: JSON.stringify({ users: resolved.slack_user_id }),
10342
- signal: controller.signal
10343
- });
10344
- openJson = await openResp.json();
10345
- } finally {
10346
- clearTimeout(timeoutHandle);
10347
- }
10348
- if (!openJson.ok || !openJson.channel?.id) {
10349
- const errCode = openJson.error === "missing_scope" ? "SLACK_MISSING_SCOPE" : `SLACK_OPEN_FAILED:${openJson.error ?? "unknown"}`;
10350
- log(`[delivery] conversations.open failed for '${agentCodeName}': ${openJson.error}`);
10351
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: errCode, medium: "slack" });
10352
- return;
10353
- }
10354
- const sent = await postSlackChannelMessage(agentCodeName, openJson.channel.id, footeredBody);
10355
- await reportDeliveryStatus(agentId, taskId, {
10356
- status: sent.ok ? "ok" : "failed",
10357
- medium: "slack",
10358
- error_code: sent.ok ? null : "SLACK_SEND_FAILED"
10359
- });
10360
- if (sent.ok) await maybePostSlackThreadHint(agentCodeName, openJson.channel.id, sent.ts);
10361
- } catch (err) {
10362
- const isAbort = err.name === "AbortError";
10363
- const errCode = isAbort ? "SLACK_OPEN_TIMEOUT" : "SLACK_EXCEPTION";
10364
- log(`[delivery] Slack DM ${isAbort ? "timeout" : "failure"} for '${agentCodeName}': ${err.message}`);
10365
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: errCode, medium: "slack" });
10425
+ const deadline = deliveryRetryDeadline();
10426
+ const opened = await openSlackDmChannel(agentCodeName, botToken, resolved.slack_user_id, { deadline });
10427
+ if (!opened.ok || !opened.channelId) {
10428
+ const errCode = opened.error === "missing_scope" ? "SLACK_MISSING_SCOPE" : opened.error === "timeout" ? "SLACK_OPEN_TIMEOUT" : `SLACK_OPEN_FAILED:${opened.error ?? "unknown"}`;
10429
+ await report({ status: "failed", error_code: errCode, medium: "slack" });
10430
+ return;
10366
10431
  }
10432
+ const sent = await postSlackChannelMessage(agentCodeName, opened.channelId, footeredBody, void 0, { retry: true, deadline });
10433
+ await report({
10434
+ status: sent.ok ? "ok" : "failed",
10435
+ medium: "slack",
10436
+ error_code: sent.ok ? null : sent.error ? `SLACK_SEND_FAILED:${sent.error}` : "SLACK_SEND_FAILED"
10437
+ });
10438
+ if (sent.ok) await maybePostSlackThreadHint(agentCodeName, opened.channelId, sent.ts);
10367
10439
  return;
10368
10440
  }
10369
10441
  if (resolved.kind === "dm" && resolved.medium === "telegram") {
@@ -10371,24 +10443,24 @@ async function deliverScheduledTaskOutput(agentCodeName, agentId, rawTarget, bod
10371
10443
  const botToken = tokens?.telegram;
10372
10444
  if (!botToken) {
10373
10445
  log(`[delivery] No Telegram bot token for '${agentCodeName}' \u2014 DM dropped`);
10374
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: "TELEGRAM_NO_TOKEN", medium: "telegram" });
10446
+ await report({ status: "failed", error_code: "TELEGRAM_NO_TOKEN", medium: "telegram" });
10375
10447
  return;
10376
10448
  }
10377
10449
  try {
10378
- const result = await telegramApiCall(botToken, "sendMessage", {
10450
+ const result = await sendTelegramMessageWithRetry(botToken, {
10379
10451
  chat_id: resolved.telegram_chat_id,
10380
10452
  text: footeredBody
10381
10453
  });
10382
10454
  if (!result.ok) {
10383
10455
  log(`[delivery] Telegram DM failed for '${agentCodeName}': ${result.description}`);
10384
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: `TELEGRAM_SEND_FAILED:${result.description ?? "unknown"}`, medium: "telegram" });
10456
+ await report({ status: "failed", error_code: `TELEGRAM_SEND_FAILED:${result.description ?? "unknown"}`, medium: "telegram" });
10385
10457
  return;
10386
10458
  }
10387
- await reportDeliveryStatus(agentId, taskId, { status: "ok", medium: "telegram" });
10459
+ await report({ status: "ok", medium: "telegram" });
10388
10460
  await maybeSendTelegramFollowUpHint(agentCodeName, botToken, resolved.telegram_chat_id);
10389
10461
  } catch (err) {
10390
10462
  log(`[delivery] Telegram DM exception for '${agentCodeName}': ${err.message}`);
10391
- await reportDeliveryStatus(agentId, taskId, { status: "failed", error_code: "TELEGRAM_EXCEPTION", medium: "telegram" });
10463
+ await report({ status: "failed", error_code: "TELEGRAM_EXCEPTION", medium: "telegram" });
10392
10464
  }
10393
10465
  }
10394
10466
  }
@@ -10502,9 +10574,22 @@ async function runScheduledCardDelivery(codeName, agentId, cardId, completedBy,
10502
10574
  return "retry";
10503
10575
  }
10504
10576
  markScheduledCardDeliveryComplete(cardId);
10577
+ if (outcome.deliveryFailed) {
10578
+ log(`[scheduled-kanban] delivery: result from card ${cardId} (task '${task.name}') on '${codeName}' NOT delivered: ${outcome.deliveryFailed.error_code ?? "unknown"}`);
10579
+ await recordDeliveryFailureOnCard(codeName, agentId, cardId, outcome.deliveryFailed);
10580
+ return "delivered";
10581
+ }
10505
10582
  log(`[scheduled-kanban] Delivered result from card ${cardId} (task '${task.name}') for '${codeName}'`);
10506
10583
  return "delivered";
10507
10584
  }
10585
+ async function recordDeliveryFailureOnCard(codeName, agentId, cardId, failure) {
10586
+ const note = `Delivery failed: this result did not reach its destination on ${failure.medium ?? "its channel"} (${failure.error_code ?? "unknown"}). Automatic attempts are finished, so nothing will re-send it. The result is still on this card: re-send it by hand.`;
10587
+ try {
10588
+ await api.post("/host/kanban", { agent_id: agentId, update: [{ id: cardId, notes: note }] });
10589
+ } catch (err) {
10590
+ log(`[scheduled-kanban] delivery: could not record the failed delivery on card ${cardId} on '${codeName}': ${err.message}`);
10591
+ }
10592
+ }
10508
10593
  async function reconcileScheduledRuns(codeName, agentId, board) {
10509
10594
  const m = scheduledRunsByCode.get(codeName);
10510
10595
  if (!m || m.size === 0) return;
@@ -10770,13 +10855,16 @@ async function processClaudeTaskResult(codeName, agentId, templateId, rawOutput,
10770
10855
  }
10771
10856
  }
10772
10857
  if (delivery?.mode === "announce" && delivery.to) {
10773
- await deliverScheduledTaskOutput(
10858
+ const report = await deliverScheduledTaskOutput(
10774
10859
  codeName,
10775
10860
  agentId,
10776
10861
  delivery.to,
10777
10862
  truncateForDelivery(output),
10778
10863
  delivery.taskId
10779
10864
  );
10865
+ if (report?.status === "failed") {
10866
+ return { ok: true, deliveryFailed: { medium: report.medium ?? null, error_code: report.error_code ?? null } };
10867
+ }
10780
10868
  }
10781
10869
  return { ok: true };
10782
10870
  } catch (err) {
@@ -16359,7 +16447,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
16359
16447
  var lastVersionCheckAt = 0;
16360
16448
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
16361
16449
  var lastResponsivenessProbeAt = 0;
16362
- var agtCliVersion = true ? "0.28.1206" : "dev";
16450
+ var agtCliVersion = true ? "0.28.1207" : "dev";
16363
16451
  function resolveBrewPath(execFileSync3) {
16364
16452
  try {
16365
16453
  const out = execFileSync3("which", ["brew"], { timeout: 5e3 }).toString().trim();