@integrity-labs/agt-cli 0.28.1250 → 0.28.1252

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 (36) hide show
  1. package/dist/api-client-6A36YH3M.js +39 -0
  2. package/dist/bin/agt.js +17 -15
  3. package/dist/bin/agt.js.map +1 -1
  4. package/dist/{chunk-IUMFAYZO.js → chunk-3HRBU4H6.js} +3 -3
  5. package/dist/{chunk-SMD577FW.js → chunk-4VOQ6D7X.js} +2 -2
  6. package/dist/chunk-5ZNYCNMI.js +471 -0
  7. package/dist/chunk-5ZNYCNMI.js.map +1 -0
  8. package/dist/{chunk-DFJ5E5EW.js → chunk-RUKGOBVA.js} +214 -1
  9. package/dist/chunk-RUKGOBVA.js.map +1 -0
  10. package/dist/{chunk-5ALBA7KT.js → chunk-S3DUSCWR.js} +94 -552
  11. package/dist/chunk-S3DUSCWR.js.map +1 -0
  12. package/dist/{chunk-JOBL3ZF4.js → chunk-XTFVVZIR.js} +2 -2
  13. package/dist/{claude-code-updater-5MPOBIWN.js → claude-code-updater-WSQTK6TQ.js} +3 -3
  14. package/dist/{claude-pair-runtime-SNU3CU3K.js → claude-pair-runtime-WWF5BCK3.js} +3 -3
  15. package/dist/lib/manager-worker.js +172 -61
  16. package/dist/lib/manager-worker.js.map +1 -1
  17. package/dist/mcp/direct-chat-channel.js +92 -4
  18. package/dist/mcp/index.js +27 -0
  19. package/dist/mcp/origami.js +27 -0
  20. package/dist/mcp/slack-channel.js +27 -0
  21. package/dist/mcp/telegram-channel.js +389 -186
  22. package/dist/{persistent-session-SYCA6MW2.js → persistent-session-HS33PGZZ.js} +4 -4
  23. package/dist/persistent-session-HS33PGZZ.js.map +1 -0
  24. package/dist/{responsiveness-probe-BUXWVOSA.js → responsiveness-probe-32AWSVSL.js} +4 -4
  25. package/dist/{session-auth-dead-G5NHWSRP.js → session-auth-dead-2L2NLMMB.js} +3 -3
  26. package/package.json +1 -1
  27. package/dist/chunk-5ALBA7KT.js.map +0 -1
  28. package/dist/chunk-DFJ5E5EW.js.map +0 -1
  29. /package/dist/{claude-code-updater-5MPOBIWN.js.map → api-client-6A36YH3M.js.map} +0 -0
  30. /package/dist/{chunk-IUMFAYZO.js.map → chunk-3HRBU4H6.js.map} +0 -0
  31. /package/dist/{chunk-SMD577FW.js.map → chunk-4VOQ6D7X.js.map} +0 -0
  32. /package/dist/{chunk-JOBL3ZF4.js.map → chunk-XTFVVZIR.js.map} +0 -0
  33. /package/dist/{persistent-session-SYCA6MW2.js.map → claude-code-updater-WSQTK6TQ.js.map} +0 -0
  34. /package/dist/{claude-pair-runtime-SNU3CU3K.js.map → claude-pair-runtime-WWF5BCK3.js.map} +0 -0
  35. /package/dist/{responsiveness-probe-BUXWVOSA.js.map → responsiveness-probe-32AWSVSL.js.map} +0 -0
  36. /package/dist/{session-auth-dead-G5NHWSRP.js.map → session-auth-dead-2L2NLMMB.js.map} +0 -0
@@ -30310,22 +30310,22 @@ var StdioServerTransport = class {
30310
30310
 
30311
30311
  // src/telegram-channel.ts
30312
30312
  import https from "https";
30313
- import { createHash as createHash3, randomUUID as randomUUID3 } from "crypto";
30313
+ import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
30314
30314
  import {
30315
- closeSync as closeSync2,
30315
+ closeSync as closeSync3,
30316
30316
  createWriteStream,
30317
- existsSync as existsSync9,
30317
+ existsSync as existsSync10,
30318
30318
  ftruncateSync,
30319
- mkdirSync as mkdirSync10,
30320
- openSync as openSync2,
30321
- readFileSync as readFileSync15,
30319
+ mkdirSync as mkdirSync11,
30320
+ openSync as openSync3,
30321
+ readFileSync as readFileSync16,
30322
30322
  readdirSync as readdirSync6,
30323
30323
  realpathSync,
30324
- renameSync as renameSync7,
30324
+ renameSync as renameSync8,
30325
30325
  statSync as statSync5,
30326
- unlinkSync as unlinkSync8,
30326
+ unlinkSync as unlinkSync9,
30327
30327
  watch,
30328
- writeFileSync as writeFileSync11,
30328
+ writeFileSync as writeFileSync12,
30329
30329
  writeSync
30330
30330
  } from "fs";
30331
30331
  import { homedir as homedir7 } from "os";
@@ -31028,6 +31028,9 @@ function parseTelegramGroupLinkStart(input) {
31028
31028
  const match = GROUP_START_WITH_CODE_RE.exec(input.text.trim());
31029
31029
  return match ? match[1] : null;
31030
31030
  }
31031
+ function isTelegramGroupChatId(id) {
31032
+ return typeof id === "string" && /^-[1-9][0-9]{0,19}$/.test(id);
31033
+ }
31031
31034
  function classifyTelegramBotGroupStatus(status) {
31032
31035
  switch (status) {
31033
31036
  case "creator":
@@ -31045,7 +31048,7 @@ function classifyTelegramBotGroupStatus(status) {
31045
31048
  }
31046
31049
  }
31047
31050
 
31048
- // src/telegram-group-link.ts
31051
+ // ../core/dist/channels/telegram-group-link-host.js
31049
31052
  var GROUP_LINK_TIMEOUT_MS = 5e3;
31050
31053
  async function postWithTimeout(post, path, body, timeoutMs) {
31051
31054
  let timer;
@@ -31057,43 +31060,42 @@ async function postWithTimeout(post, path, body, timeoutMs) {
31057
31060
  } catch {
31058
31061
  return null;
31059
31062
  } finally {
31060
- if (timer) clearTimeout(timer);
31063
+ if (timer)
31064
+ clearTimeout(timer);
31061
31065
  }
31062
31066
  }
31063
31067
  async function claimTelegramGroupLinkCode(post, input, timeoutMs = GROUP_LINK_TIMEOUT_MS) {
31064
- const res = await postWithTimeout(
31065
- post,
31066
- "/host/telegram-link/group-claim",
31067
- {
31068
- agent_id: input.agentId,
31069
- code: input.code,
31070
- chat_id: input.chatId,
31071
- chat_type: input.chatType,
31072
- ...input.chatTitle ? { chat_title: input.chatTitle } : {},
31073
- ...input.fromId ? { from_id: input.fromId } : {},
31074
- ...input.firstName ? { first_name: input.firstName } : {},
31075
- ...input.lastName ? { last_name: input.lastName } : {}
31076
- },
31077
- timeoutMs
31078
- );
31079
- if (!res || res.status < 200 || res.status >= 300) return false;
31068
+ const res = await postWithTimeout(post, "/host/telegram-link/group-claim", {
31069
+ agent_id: input.agentId,
31070
+ code: input.code,
31071
+ chat_id: input.chatId,
31072
+ chat_type: input.chatType,
31073
+ ...input.chatTitle ? { chat_title: input.chatTitle } : {},
31074
+ ...input.fromId ? { from_id: input.fromId } : {},
31075
+ ...input.firstName ? { first_name: input.firstName } : {},
31076
+ ...input.lastName ? { last_name: input.lastName } : {}
31077
+ }, timeoutMs);
31078
+ if (!res || res.status < 200 || res.status >= 300)
31079
+ return false;
31080
31080
  return res.json?.ok === true;
31081
31081
  }
31082
- async function reportTelegramGroupMigration(post, input, timeoutMs = GROUP_LINK_TIMEOUT_MS) {
31083
- const res = await postWithTimeout(
31084
- post,
31085
- "/host/telegram-link/group-migrate",
31086
- { agent_id: input.agentId, from_chat_id: input.fromChatId, to_chat_id: input.toChatId },
31087
- timeoutMs
31088
- );
31089
- if (!res || res.status < 200 || res.status >= 300) return false;
31090
- return res.json?.ok === true;
31082
+ async function reportTelegramGroupMigrationOutcome(post, input, timeoutMs = GROUP_LINK_TIMEOUT_MS) {
31083
+ const res = await postWithTimeout(post, "/host/telegram-link/group-migrate", { agent_id: input.agentId, from_chat_id: input.fromChatId, to_chat_id: input.toChatId }, timeoutMs);
31084
+ if (!res)
31085
+ return "retry";
31086
+ if (res.status === 400)
31087
+ return "drop";
31088
+ if (res.status < 200 || res.status >= 300)
31089
+ return "retry";
31090
+ return res.json?.ok === true ? "done" : "retry";
31091
31091
  }
31092
31092
  var GROUP_CLAIMED_REPLY = "Thanks for adding me. Go back to the setup screen to finish: I will answer here once it is confirmed.";
31093
31093
  function observedChatFromMembership(update) {
31094
- if (!isTelegramGroupChatType(update.chat?.type)) return null;
31094
+ if (!isTelegramGroupChatType(update.chat?.type))
31095
+ return null;
31095
31096
  const access = classifyTelegramBotGroupStatus(update.new_chat_member?.status);
31096
- if (access !== "admin" && access !== "member" && access !== "restricted") return null;
31097
+ if (access !== "admin" && access !== "member" && access !== "restricted")
31098
+ return null;
31097
31099
  return {
31098
31100
  chat_id: String(update.chat.id),
31099
31101
  chat_title: typeof update.chat.title === "string" ? update.chat.title : null,
@@ -31101,10 +31103,175 @@ function observedChatFromMembership(update) {
31101
31103
  };
31102
31104
  }
31103
31105
  function applyMigrationToAllowlist(allowed, fromChatId, toChatId) {
31104
- if (!allowed.has(fromChatId) || allowed.has(toChatId)) return false;
31106
+ if (!allowed.has(fromChatId) || allowed.has(toChatId))
31107
+ return false;
31105
31108
  allowed.add(toChatId);
31106
31109
  return true;
31107
31110
  }
31111
+ var MIGRATION_REPORT_BASE_DELAY_MS = 3e4;
31112
+ var MIGRATION_REPORT_MAX_DELAY_MS = 60 * 6e4;
31113
+ var MIGRATION_REPORT_MAX_AGE_MS = 7 * 24 * 60 * 6e4;
31114
+ var MIGRATION_REPORT_MAX_PENDING = 32;
31115
+ var MIGRATION_REPORT_MAX_PER_FLUSH = 4;
31116
+ function migrationReportRetryDelayMs(attempts) {
31117
+ const exp = Math.max(0, attempts - 1);
31118
+ return Math.min(MIGRATION_REPORT_MAX_DELAY_MS, MIGRATION_REPORT_BASE_DELAY_MS * 2 ** Math.min(exp, 20));
31119
+ }
31120
+ var MIGRATION_REPORT_CLOCK_SKEW_MS = 5 * 6e4;
31121
+ function isPendingMigrationReport(v) {
31122
+ if (typeof v !== "object" || v === null)
31123
+ return false;
31124
+ const r = v;
31125
+ return isTelegramGroupChatId(r["from_chat_id"]) && isTelegramGroupChatId(r["to_chat_id"]) && r["from_chat_id"] !== r["to_chat_id"] && typeof r["first_seen_at"] === "number" && Number.isFinite(r["first_seen_at"]) && typeof r["attempts"] === "number" && Number.isInteger(r["attempts"]) && r["attempts"] >= 0 && typeof r["next_attempt_at"] === "number" && Number.isFinite(r["next_attempt_at"]);
31126
+ }
31127
+ function parsePendingMigrationReports(raw, now = Date.now()) {
31128
+ if (!raw)
31129
+ return [];
31130
+ let parsed;
31131
+ try {
31132
+ parsed = JSON.parse(raw);
31133
+ } catch {
31134
+ return [];
31135
+ }
31136
+ const list = parsed?.pending;
31137
+ if (!Array.isArray(list))
31138
+ return [];
31139
+ return list.filter(isPendingMigrationReport).filter((r) => r.first_seen_at <= now + MIGRATION_REPORT_CLOCK_SKEW_MS && now - r.first_seen_at < MIGRATION_REPORT_MAX_AGE_MS).map((r) => r.next_attempt_at > now + MIGRATION_REPORT_MAX_DELAY_MS ? { ...r, next_attempt_at: now + MIGRATION_REPORT_MAX_DELAY_MS } : r).slice(-MIGRATION_REPORT_MAX_PENDING);
31140
+ }
31141
+ function serializePendingMigrationReports(list) {
31142
+ return JSON.stringify({ pending: list });
31143
+ }
31144
+ function enqueueMigrationReport(list, fromChatId, toChatId, now) {
31145
+ if (!isTelegramGroupChatId(fromChatId) || !isTelegramGroupChatId(toChatId) || fromChatId === toChatId) {
31146
+ return [...list];
31147
+ }
31148
+ if (list.some((r) => r.from_chat_id === fromChatId && r.to_chat_id === toChatId))
31149
+ return [...list];
31150
+ const next = [
31151
+ ...list,
31152
+ { from_chat_id: fromChatId, to_chat_id: toChatId, first_seen_at: now, attempts: 0, next_attempt_at: now }
31153
+ ];
31154
+ return next.slice(-MIGRATION_REPORT_MAX_PENDING);
31155
+ }
31156
+ function settleMigrationReport(list, entry, outcome, now) {
31157
+ const same = (r) => r.from_chat_id === entry.from_chat_id && r.to_chat_id === entry.to_chat_id;
31158
+ if (outcome !== "retry" || now - entry.first_seen_at >= MIGRATION_REPORT_MAX_AGE_MS) {
31159
+ return list.filter((r) => !same(r));
31160
+ }
31161
+ return list.map((r) => {
31162
+ if (!same(r))
31163
+ return r;
31164
+ const attempts = r.attempts + 1;
31165
+ return { ...r, attempts, next_attempt_at: now + migrationReportRetryDelayMs(attempts) };
31166
+ });
31167
+ }
31168
+ function createMigrationReportQueue(deps) {
31169
+ const now = deps.now ?? Date.now;
31170
+ let list = parsePendingMigrationReports(safeLoad(deps.io), now());
31171
+ let inFlight = null;
31172
+ const persist = () => {
31173
+ try {
31174
+ deps.io.save(serializePendingMigrationReports(list));
31175
+ } catch (err) {
31176
+ deps.log(`migration-report persist failed: ${err instanceof Error ? err.message : String(err)}`);
31177
+ }
31178
+ };
31179
+ const flush = async () => {
31180
+ const outcomes = /* @__PURE__ */ new Map();
31181
+ const t = now();
31182
+ const due = list.filter((r) => r.next_attempt_at <= t).sort((a, b) => a.attempts - b.attempts).slice(0, MIGRATION_REPORT_MAX_PER_FLUSH);
31183
+ for (const entry of due) {
31184
+ let outcome;
31185
+ try {
31186
+ outcome = await deps.report(entry.from_chat_id, entry.to_chat_id);
31187
+ } catch {
31188
+ outcome = "retry";
31189
+ }
31190
+ const before = list.length;
31191
+ list = settleMigrationReport(list, entry, outcome, now());
31192
+ outcomes.set(`${entry.from_chat_id}->${entry.to_chat_id}`, outcome);
31193
+ if (outcome === "retry" && list.length < before) {
31194
+ deps.log(`migration-report gave up after ${entry.attempts + 1} attempt(s) (aged out)`);
31195
+ }
31196
+ persist();
31197
+ }
31198
+ return outcomes;
31199
+ };
31200
+ return {
31201
+ pending: () => [...list],
31202
+ enqueue(fromChatId, toChatId) {
31203
+ const next = enqueueMigrationReport(list, fromChatId, toChatId, now());
31204
+ if (next.length === list.length && next.every((r, i) => r === list[i]))
31205
+ return;
31206
+ list = next;
31207
+ persist();
31208
+ },
31209
+ flushDue() {
31210
+ if (!list.some((r) => r.next_attempt_at <= now()))
31211
+ return Promise.resolve(/* @__PURE__ */ new Map());
31212
+ if (!inFlight) {
31213
+ inFlight = flush().finally(() => {
31214
+ inFlight = null;
31215
+ });
31216
+ }
31217
+ return inFlight;
31218
+ }
31219
+ };
31220
+ }
31221
+ function safeLoad(io) {
31222
+ try {
31223
+ return io.load();
31224
+ } catch {
31225
+ return null;
31226
+ }
31227
+ }
31228
+
31229
+ // src/telegram-migration-report-store.ts
31230
+ import { closeSync, existsSync as existsSync2, fsyncSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync3, renameSync as renameSync3, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "fs";
31231
+ import { randomUUID as randomUUID2 } from "crypto";
31232
+ function createFileMigrationReportIO(opts) {
31233
+ const { filePath, dir, onError } = opts;
31234
+ return {
31235
+ load() {
31236
+ if (!filePath) return null;
31237
+ try {
31238
+ return readFileSync3(filePath, "utf-8");
31239
+ } catch {
31240
+ return null;
31241
+ }
31242
+ },
31243
+ save(data) {
31244
+ if (!filePath || !dir) return;
31245
+ const tmpPath = `${filePath}.${process.pid}.${randomUUID2()}.tmp`;
31246
+ try {
31247
+ mkdirSync4(dir, { recursive: true, mode: 448 });
31248
+ const fd = openSync(tmpPath, "w", 384);
31249
+ try {
31250
+ writeFileSync4(fd, data);
31251
+ fsyncSync(fd);
31252
+ } finally {
31253
+ closeSync(fd);
31254
+ }
31255
+ renameSync3(tmpPath, filePath);
31256
+ try {
31257
+ const dirFd = openSync(dir, "r");
31258
+ try {
31259
+ fsyncSync(dirFd);
31260
+ } finally {
31261
+ closeSync(dirFd);
31262
+ }
31263
+ } catch {
31264
+ }
31265
+ } catch (err) {
31266
+ onError?.(`migration-report persist failed: ${err.message}`);
31267
+ try {
31268
+ if (existsSync2(tmpPath)) unlinkSync4(tmpPath);
31269
+ } catch {
31270
+ }
31271
+ }
31272
+ }
31273
+ };
31274
+ }
31108
31275
 
31109
31276
  // ../core/dist/channels/governance/telegram-chat-type.js
31110
31277
  function isTelegramPrivateChat(chatType) {
@@ -31115,13 +31282,13 @@ function isTelegramPrivateChat(chatType) {
31115
31282
  var ONBOARDING_DM_ONLY_MESSAGE = "Sorry, I can only be onboarded from a Direct Message (DM).";
31116
31283
 
31117
31284
  // src/flags-cache-read.ts
31118
- import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
31285
+ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
31119
31286
  import { homedir as homedir2 } from "os";
31120
31287
  import { join as join2 } from "path";
31121
31288
  function hasUsableFlags(path) {
31122
31289
  try {
31123
- if (!existsSync2(path)) return false;
31124
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
31290
+ if (!existsSync3(path)) return false;
31291
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
31125
31292
  if (!parsed || typeof parsed !== "object") return false;
31126
31293
  const flags = parsed.flags;
31127
31294
  return !!flags && typeof flags === "object" && !Array.isArray(flags);
@@ -31131,8 +31298,8 @@ function hasUsableFlags(path) {
31131
31298
  }
31132
31299
  function cacheUpdatedAt(path) {
31133
31300
  try {
31134
- if (!existsSync2(path)) return void 0;
31135
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
31301
+ if (!existsSync3(path)) return void 0;
31302
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
31136
31303
  if (!parsed || typeof parsed !== "object") return void 0;
31137
31304
  const u = parsed.updated_at;
31138
31305
  return typeof u === "string" && u.length > 0 ? u : void 0;
@@ -31161,8 +31328,8 @@ function envBoolean(raw) {
31161
31328
  }
31162
31329
  function cachedBoolean(key2, path) {
31163
31330
  try {
31164
- if (!existsSync2(path)) return void 0;
31165
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
31331
+ if (!existsSync3(path)) return void 0;
31332
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
31166
31333
  if (!parsed || typeof parsed !== "object") return void 0;
31167
31334
  const flags = parsed.flags;
31168
31335
  if (!flags || typeof flags !== "object") return void 0;
@@ -31193,8 +31360,8 @@ function parseGhostReplyMode(raw) {
31193
31360
  }
31194
31361
  function cachedGhostReplyMode(path) {
31195
31362
  try {
31196
- if (!existsSync2(path)) return void 0;
31197
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
31363
+ if (!existsSync3(path)) return void 0;
31364
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
31198
31365
  if (!parsed || typeof parsed !== "object") return void 0;
31199
31366
  const flags = parsed.flags;
31200
31367
  if (!flags || typeof flags !== "object") return void 0;
@@ -31229,8 +31396,8 @@ function parseMaintenanceMode(raw) {
31229
31396
  }
31230
31397
  function cachedMaintenanceMode(path) {
31231
31398
  try {
31232
- if (!existsSync2(path)) return void 0;
31233
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
31399
+ if (!existsSync3(path)) return void 0;
31400
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
31234
31401
  if (!parsed || typeof parsed !== "object") return void 0;
31235
31402
  const flags = parsed.flags;
31236
31403
  if (!flags || typeof flags !== "object") return void 0;
@@ -41112,6 +41279,28 @@ var FLAG_REGISTRY = [
41112
41279
  // edec921a519f); THREATS_FOUND rows stay hidden either way.
41113
41280
  defaultValue: false
41114
41281
  },
41282
+ {
41283
+ key: "direct-chat-extracted-text",
41284
+ // ENG-11967 part 2b. Read stage-wide only (empty scope), like
41285
+ // direct-chat-malware-scan: a scoped override would do nothing.
41286
+ stageWideOnly: true,
41287
+ sensitive: true,
41288
+ description: `Serve a Direct Chat PDF or DOCX to the agent as its EXTRACTED TEXT instead of the raw file (ENG-11967 part 2b, Sherlock ruling (a)). off = today: the agent gets the raw file (scan-gated). hold-30s / hold-60s / hold-120s = armed, and the value is the HOLD CAP: the agent poll does not claim a message whose text is not ready yet for up to that long, and holds the rest of its session with it so order is kept. Holds chain: a message also waits for every document sent after it in the same session, so its delay is bounded by the cap measured from the LAST document in a run of sends, not from its own send. Ready text is delivered as <name>.txt. If extraction finished without text, or died, the message is released at once with "text extraction unavailable for <name> (couldn't read the file)" or "(timed out)"; at the cap it is released with "(timed out)" and the release is logged. Takes effect only while direct-chat-malware-scan is on, because extraction runs on GuardDuty's clean-scan event. ARM ONLY AFTER DIRECT_CHAT_TEXT_EXTRACTION=true has deployed the DirectChatTextExtract Lambda: armed without it, every PDF/DOCX waits out the cap and arrives as a timed-out notice. A flag-store read error counts as off on this read path. GLOBAL ONLY: evaluated with an empty context, so scoped overrides have no effect.`,
41289
+ flagType: "enum",
41290
+ allowedValues: ["off", "hold-30s", "hold-60s", "hold-120s"],
41291
+ // Off is the pre-2b behaviour: no hold, no .txt read, the raw file.
41292
+ defaultValue: "off",
41293
+ // The flag is evaluated server-side, but its notice entries need the host's
41294
+ // direct-chat MCP to render them: an older agt-cli shows a notice as
41295
+ // "download failed; ask the user to re-send", which sends users in circles
41296
+ // (Sherlock, 13 Nov). So the flip-reach modal must count hosts by the CLI
41297
+ // that renders notices. DELIBERATE UNREACHABLE PLACEHOLDER until this PR
41298
+ // merges and "Publish CLI on adapter changes (main)" publishes the first
41299
+ // agt-cli carrying the MCP change: replace it with that exact version in a
41300
+ // one-line follow-up, and arm only when the modal shows 0 stale and 0
41301
+ // unknown hosts. A placeholder over-reports stale hosts; it never hides one.
41302
+ since: "0.29.0"
41303
+ },
41115
41304
  {
41116
41305
  key: "platform-held-key-central-probe",
41117
41306
  description: "Arm the scheduled CENTRAL connectivity probe lane for platform-held-key integrations (ENG-10086). These store no customer credential (auth_type none), so the host cannot probe them and reports unverified forever. When on, the hourly PlatformHeldKeyProbe cron runs each central probe that exists (today only ninjafy-notes: org entitlement + broker routing, never note contents) and writes the result through the monitor observation path, so consecutive_connectivity_failures / _ok_cycles move and integration_down alerts can open and close on it. Definitions with no central probe are skipped, never written as a failure. When off the cron reads nothing and writes nothing. Boolean gate; ships dark because a new writer of the escalation counters is a paging change. GLOBAL ONLY: the cron and the host connectivity route both evaluate this flag with an empty context, so an org-, team- or agent-scoped override is stored but has NO effect. Arm it by its global value, not as a staged per-org rollout (Obi Wan 63053d02035e).",
@@ -42045,7 +42234,7 @@ var TEAM_SLUG_MAX_ATTEMPTS = 20;
42045
42234
  var SUFFIX_RESERVE = `-${TEAM_SLUG_MAX_ATTEMPTS}`.length;
42046
42235
 
42047
42236
  // src/account-enforcement-notice.ts
42048
- import { readFileSync as readFileSync4 } from "fs";
42237
+ import { readFileSync as readFileSync5 } from "fs";
42049
42238
  import { homedir as homedir3 } from "os";
42050
42239
  import { join as join3 } from "path";
42051
42240
  function accountEnforcementMarkerPath(codeName) {
@@ -42057,7 +42246,7 @@ function readAccountEnforcementMarker(opts) {
42057
42246
  if (!path) return null;
42058
42247
  let raw;
42059
42248
  try {
42060
- raw = readFileSync4(path, "utf-8");
42249
+ raw = readFileSync5(path, "utf-8");
42061
42250
  } catch {
42062
42251
  return null;
42063
42252
  }
@@ -42083,7 +42272,7 @@ function shouldSendAccountWarn(opts) {
42083
42272
  }
42084
42273
 
42085
42274
  // src/turn-initiator-marker.ts
42086
- import { writeFileSync as writeFileSync4, readFileSync as readFileSync5, mkdirSync as mkdirSync4, renameSync as renameSync3 } from "fs";
42275
+ import { writeFileSync as writeFileSync5, readFileSync as readFileSync6, mkdirSync as mkdirSync5, renameSync as renameSync4 } from "fs";
42087
42276
  import { dirname as dirname3, join as join4 } from "path";
42088
42277
  var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
42089
42278
  var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
@@ -42119,24 +42308,24 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
42119
42308
  const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
42120
42309
  let existing = null;
42121
42310
  try {
42122
- const parsed = JSON.parse(readFileSync5(ledgerFile, "utf8"));
42311
+ const parsed = JSON.parse(readFileSync6(ledgerFile, "utf8"));
42123
42312
  if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
42124
42313
  } catch {
42125
42314
  }
42126
42315
  const next = foldTurnInitiatorLedger(existing, marker);
42127
42316
  const tmp = `${ledgerFile}.${process.pid}.${Date.now()}.tmp`;
42128
- writeFileSync4(tmp, JSON.stringify(next), "utf8");
42129
- renameSync3(tmp, ledgerFile);
42317
+ writeFileSync5(tmp, JSON.stringify(next), "utf8");
42318
+ renameSync4(tmp, ledgerFile);
42130
42319
  }
42131
42320
  function writeTurnInitiatorMarker(input) {
42132
42321
  const file = process.env["AGT_TURN_INITIATOR_FILE"];
42133
42322
  if (!file || !input.sender_id) return;
42134
42323
  try {
42135
- mkdirSync4(dirname3(file), { recursive: true });
42324
+ mkdirSync5(dirname3(file), { recursive: true });
42136
42325
  const marker = { ...input, ts: Date.now() };
42137
42326
  const tmp = `${file}.tmp`;
42138
- writeFileSync4(tmp, JSON.stringify(marker), "utf8");
42139
- renameSync3(tmp, file);
42327
+ writeFileSync5(tmp, JSON.stringify(marker), "utf8");
42328
+ renameSync4(tmp, file);
42140
42329
  try {
42141
42330
  updateTurnInitiatorLedger(file, marker);
42142
42331
  } catch {
@@ -42146,7 +42335,7 @@ function writeTurnInitiatorMarker(input) {
42146
42335
  }
42147
42336
 
42148
42337
  // src/turn-context.ts
42149
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync7 } from "fs";
42338
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync8 } from "fs";
42150
42339
  import { homedir as homedir4 } from "os";
42151
42340
  import { dirname as dirname4, join as join7 } from "path";
42152
42341
 
@@ -42190,14 +42379,14 @@ function resolveAgentDirAlias(input) {
42190
42379
  }
42191
42380
 
42192
42381
  // src/scheduled-turn-marker.ts
42193
- import { readFileSync as readFileSync6, unlinkSync as unlinkSync4 } from "fs";
42382
+ import { readFileSync as readFileSync7, unlinkSync as unlinkSync5 } from "fs";
42194
42383
  import { join as join6 } from "path";
42195
42384
  var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
42196
42385
  var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
42197
42386
  function clearScheduledTurnMarker(agentDir) {
42198
42387
  if (!agentDir) return;
42199
42388
  try {
42200
- unlinkSync4(join6(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
42389
+ unlinkSync5(join6(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
42201
42390
  } catch {
42202
42391
  }
42203
42392
  }
@@ -42208,7 +42397,7 @@ function writeUnattributedTurnMarker(channel, opts = {}) {
42208
42397
  try {
42209
42398
  const file = resolveTurnInitiatorFile(opts.env ?? process.env, opts.home ?? homedir4());
42210
42399
  if (!file) return;
42211
- mkdirSync5(dirname4(file), { recursive: true });
42400
+ mkdirSync6(dirname4(file), { recursive: true });
42212
42401
  updateTurnInitiatorLedger(file, {
42213
42402
  channel,
42214
42403
  sender_id: "",
@@ -42881,19 +43070,19 @@ function buildCommandRegistrations() {
42881
43070
 
42882
43071
  // src/telegram-offset-store.ts
42883
43072
  import {
42884
- existsSync as existsSync3,
42885
- mkdirSync as mkdirSync6,
42886
- readFileSync as readFileSync8,
42887
- renameSync as renameSync4,
42888
- unlinkSync as unlinkSync5,
42889
- writeFileSync as writeFileSync5
43073
+ existsSync as existsSync4,
43074
+ mkdirSync as mkdirSync7,
43075
+ readFileSync as readFileSync9,
43076
+ renameSync as renameSync5,
43077
+ unlinkSync as unlinkSync6,
43078
+ writeFileSync as writeFileSync6
42890
43079
  } from "fs";
42891
- import { randomUUID as randomUUID2 } from "crypto";
43080
+ import { randomUUID as randomUUID3 } from "crypto";
42892
43081
  function loadPersistedOffset(filePath) {
42893
43082
  if (!filePath) return 0;
42894
43083
  try {
42895
43084
  const parsed = JSON.parse(
42896
- readFileSync8(filePath, "utf-8")
43085
+ readFileSync9(filePath, "utf-8")
42897
43086
  );
42898
43087
  const offset = parsed?.offset;
42899
43088
  if (typeof offset === "number" && Number.isFinite(offset) && offset > 0) {
@@ -42913,15 +43102,15 @@ function persistOffset(opts) {
42913
43102
  offset,
42914
43103
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
42915
43104
  };
42916
- const tmpPath = `${filePath}.${process.pid}.${randomUUID2()}.tmp`;
43105
+ const tmpPath = `${filePath}.${process.pid}.${randomUUID3()}.tmp`;
42917
43106
  try {
42918
- mkdirSync6(dir, { recursive: true, mode: 448 });
42919
- writeFileSync5(tmpPath, JSON.stringify(marker), { mode: 384 });
42920
- renameSync4(tmpPath, filePath);
43107
+ mkdirSync7(dir, { recursive: true, mode: 448 });
43108
+ writeFileSync6(tmpPath, JSON.stringify(marker), { mode: 384 });
43109
+ renameSync5(tmpPath, filePath);
42921
43110
  } catch (err) {
42922
43111
  onError?.(`getUpdates offset persist failed: ${err.message}`);
42923
43112
  try {
42924
- if (existsSync3(tmpPath)) unlinkSync5(tmpPath);
43113
+ if (existsSync4(tmpPath)) unlinkSync6(tmpPath);
42925
43114
  } catch {
42926
43115
  }
42927
43116
  }
@@ -42937,7 +43126,7 @@ function conversationalLaneMeta(expectsReply = true) {
42937
43126
  }
42938
43127
 
42939
43128
  // src/inbound-lane-telemetry.ts
42940
- import { readFileSync as readFileSync9, writeFileSync as writeFileSync6 } from "fs";
43129
+ import { readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "fs";
42941
43130
  import { join as join8 } from "path";
42942
43131
  var LANE_CLASSIFICATION_COUNTER_SUFFIX = "-lane-classifications.json";
42943
43132
  var SUSPECTED_MISCLASSIFICATION_KEY = "suspected_misclassification";
@@ -42958,7 +43147,7 @@ function recordLaneClassification(agentDir, channel, classification) {
42958
43147
  const path = join8(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
42959
43148
  let counts = {};
42960
43149
  try {
42961
- const parsed = JSON.parse(readFileSync9(path, "utf-8"));
43150
+ const parsed = JSON.parse(readFileSync10(path, "utf-8"));
42962
43151
  if (parsed && typeof parsed === "object") counts = parsed;
42963
43152
  } catch {
42964
43153
  }
@@ -42968,21 +43157,21 @@ function recordLaneClassification(agentDir, channel, classification) {
42968
43157
  counts[SUSPECTED_MISCLASSIFICATION_KEY] = (counts[SUSPECTED_MISCLASSIFICATION_KEY] ?? 0) + 1;
42969
43158
  }
42970
43159
  try {
42971
- writeFileSync6(path, JSON.stringify(counts), { mode: 384 });
43160
+ writeFileSync7(path, JSON.stringify(counts), { mode: 384 });
42972
43161
  } catch {
42973
43162
  }
42974
43163
  }
42975
43164
 
42976
43165
  // src/agent-config-state.ts
42977
- import { existsSync as existsSync4, readFileSync as readFileSync10 } from "fs";
43166
+ import { existsSync as existsSync5, readFileSync as readFileSync11 } from "fs";
42978
43167
  import { join as join9 } from "path";
42979
43168
  var SESSION_STATE_FILENAME = "session-state.json";
42980
43169
  function readAgentSessionState(stateDir) {
42981
43170
  if (!stateDir) return null;
42982
43171
  const path = join9(stateDir, SESSION_STATE_FILENAME);
42983
- if (!existsSync4(path)) return null;
43172
+ if (!existsSync5(path)) return null;
42984
43173
  try {
42985
- const parsed = JSON.parse(readFileSync10(path, "utf-8"));
43174
+ const parsed = JSON.parse(readFileSync11(path, "utf-8"));
42986
43175
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
42987
43176
  return parsed;
42988
43177
  } catch {
@@ -43946,7 +44135,7 @@ function emitToolCallMarkupRedactionTelemetry(channel) {
43946
44135
  }
43947
44136
 
43948
44137
  // src/rate-limit-watch.ts
43949
- import { closeSync, fstatSync, openSync, readSync, readdirSync, statSync } from "fs";
44138
+ import { closeSync as closeSync2, fstatSync, openSync as openSync2, readSync, readdirSync, statSync } from "fs";
43950
44139
  import { homedir as homedir5 } from "os";
43951
44140
  import { join as join10 } from "path";
43952
44141
  var DEFAULT_WATCH_MS = 5e3;
@@ -43968,7 +44157,7 @@ function readClassifiableTail(path, sinceMs, opts) {
43968
44157
  function readTailSlice(path, bytes) {
43969
44158
  let fd;
43970
44159
  try {
43971
- fd = openSync(path, "r");
44160
+ fd = openSync2(path, "r");
43972
44161
  } catch {
43973
44162
  return null;
43974
44163
  }
@@ -43994,7 +44183,7 @@ function readTailSlice(path, bytes) {
43994
44183
  } catch {
43995
44184
  return null;
43996
44185
  } finally {
43997
- closeSync(fd);
44186
+ closeSync2(fd);
43998
44187
  }
43999
44188
  }
44000
44189
  function oldestTimestampMs(text) {
@@ -44252,7 +44441,7 @@ function describeUnparsedRefusal(text) {
44252
44441
 
44253
44442
  // src/reply-intent-runtime.ts
44254
44443
  import { execFile as execFile2 } from "child_process";
44255
- import { existsSync as existsSync5, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "fs";
44444
+ import { existsSync as existsSync6, mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "fs";
44256
44445
  import { homedir as homedir6 } from "os";
44257
44446
  import { join as join12 } from "path";
44258
44447
  var DEFAULT_CLAUDE_EVAL_MODEL = "claude-haiku-4-5-20251001";
@@ -44352,14 +44541,14 @@ async function runAnthropicMessages(prompt, opts) {
44352
44541
  }
44353
44542
  var emptyMcpConfigPath = null;
44354
44543
  function ensureEmptyMcpConfig() {
44355
- if (emptyMcpConfigPath && existsSync5(emptyMcpConfigPath)) return emptyMcpConfigPath;
44544
+ if (emptyMcpConfigPath && existsSync6(emptyMcpConfigPath)) return emptyMcpConfigPath;
44356
44545
  const dir = join12(homedir6(), ".augmented");
44357
44546
  try {
44358
- mkdirSync7(dir, { recursive: true });
44547
+ mkdirSync8(dir, { recursive: true });
44359
44548
  } catch {
44360
44549
  }
44361
44550
  const p2 = join12(dir, ".reply-intent-empty-mcp.json");
44362
- writeFileSync7(p2, JSON.stringify({ mcpServers: {} }));
44551
+ writeFileSync8(p2, JSON.stringify({ mcpServers: {} }));
44363
44552
  emptyMcpConfigPath = p2;
44364
44553
  return p2;
44365
44554
  }
@@ -44505,11 +44694,11 @@ function emitTransientApiErrorTelemetry(channel, match, original) {
44505
44694
  }
44506
44695
 
44507
44696
  // src/telegram-pending-inbound-cleanup.ts
44508
- import { readdirSync as readdirSync3, readFileSync as readFileSync11, statSync as statSync3 } from "fs";
44697
+ import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
44509
44698
  import { join as join13 } from "path";
44510
44699
  function markerArrivalMs(fullPath) {
44511
44700
  try {
44512
- const received = JSON.parse(readFileSync11(fullPath, "utf-8")).received_at;
44701
+ const received = JSON.parse(readFileSync12(fullPath, "utf-8")).received_at;
44513
44702
  const parsed = received ? Date.parse(received) : Number.NaN;
44514
44703
  if (Number.isFinite(parsed)) return parsed;
44515
44704
  } catch {
@@ -44536,7 +44725,7 @@ function markerMayDrain(i) {
44536
44725
  let hasPayload = false;
44537
44726
  try {
44538
44727
  if (i.dir) {
44539
- const read = i.read ?? ((path) => readFileSync11(path, "utf-8"));
44728
+ const read = i.read ?? ((path) => readFileSync12(path, "utf-8"));
44540
44729
  hasPayload = Boolean(JSON.parse(read(join13(i.dir, i.filename))).payload);
44541
44730
  }
44542
44731
  } catch (err) {
@@ -44603,9 +44792,9 @@ function applyToChatMarkers(pendingDir, chatId, op, cutoffMs, reachedSession) {
44603
44792
  }
44604
44793
 
44605
44794
  // src/recovery-ledger.ts
44606
- import { existsSync as existsSync6, unlinkSync as unlinkSync6 } from "fs";
44795
+ import { existsSync as existsSync7, unlinkSync as unlinkSync7 } from "fs";
44607
44796
  import { join as join14 } from "path";
44608
- function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => existsSync6(p2)) {
44797
+ function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => existsSync7(p2)) {
44609
44798
  if (!ledgerDir || !markerName) return false;
44610
44799
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return false;
44611
44800
  try {
@@ -44615,7 +44804,7 @@ function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => exist
44615
44804
  }
44616
44805
  }
44617
44806
  function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
44618
- if (existsSync6(p2)) unlinkSync6(p2);
44807
+ if (existsSync7(p2)) unlinkSync7(p2);
44619
44808
  }) {
44620
44809
  if (!ledgerDir || !markerName) return;
44621
44810
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
@@ -44626,18 +44815,18 @@ function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
44626
44815
  }
44627
44816
 
44628
44817
  // src/inbound-delivery-ledger.ts
44629
- import { existsSync as existsSync7, mkdirSync as mkdirSync8, readdirSync as readdirSync4, readFileSync as readFileSync12, renameSync as renameSync5, writeFileSync as writeFileSync8 } from "fs";
44818
+ import { existsSync as existsSync8, mkdirSync as mkdirSync9, readdirSync as readdirSync4, readFileSync as readFileSync13, renameSync as renameSync6, writeFileSync as writeFileSync9 } from "fs";
44630
44819
  import { join as join15 } from "path";
44631
44820
  function safeInboundId(inboundId) {
44632
44821
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
44633
44822
  }
44634
44823
  var defaultDeps = {
44635
- mkdir: (dir) => mkdirSync8(dir, { recursive: true }),
44636
- writeFile: (path, data) => writeFileSync8(path, data, "utf8"),
44637
- rename: (from, to) => renameSync5(from, to),
44824
+ mkdir: (dir) => mkdirSync9(dir, { recursive: true }),
44825
+ writeFile: (path, data) => writeFileSync9(path, data, "utf8"),
44826
+ rename: (from, to) => renameSync6(from, to),
44638
44827
  readdir: (dir) => readdirSync4(dir),
44639
- readFile: (path) => readFileSync12(path, "utf8"),
44640
- exists: (path) => existsSync7(path)
44828
+ readFile: (path) => readFileSync13(path, "utf8"),
44829
+ exists: (path) => existsSync8(path)
44641
44830
  };
44642
44831
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
44643
44832
  if (!dir || !record2.inbound_id || !record2.conv_key) return;
@@ -44876,14 +45065,14 @@ function createKanbanCardActiveClient(args) {
44876
45065
 
44877
45066
  // src/mcp-spawn-lock.ts
44878
45067
  import {
44879
- existsSync as existsSync8,
44880
- mkdirSync as mkdirSync9,
44881
- readFileSync as readFileSync13,
44882
- renameSync as renameSync6,
45068
+ existsSync as existsSync9,
45069
+ mkdirSync as mkdirSync10,
45070
+ readFileSync as readFileSync14,
45071
+ renameSync as renameSync7,
44883
45072
  statSync as statSync4,
44884
- unlinkSync as unlinkSync7,
45073
+ unlinkSync as unlinkSync8,
44885
45074
  utimesSync,
44886
- writeFileSync as writeFileSync9
45075
+ writeFileSync as writeFileSync10
44887
45076
  } from "fs";
44888
45077
  import { join as join16 } from "path";
44889
45078
  var STALE_LOCK_MS = 9e4;
@@ -44922,11 +45111,11 @@ function acquireMcpSpawnLock(args) {
44922
45111
  }
44923
45112
  }
44924
45113
  }
44925
- mkdirSync9(agentDir, { recursive: true, mode: 448 });
45114
+ mkdirSync10(agentDir, { recursive: true, mode: 448 });
44926
45115
  const tmpPath = `${path}.${selfPid}.tmp`;
44927
45116
  const payload = { pid: selfPid, started_at: now() };
44928
- writeFileSync9(tmpPath, JSON.stringify(payload), { mode: 384 });
44929
- renameSync6(tmpPath, path);
45117
+ writeFileSync10(tmpPath, JSON.stringify(payload), { mode: 384 });
45118
+ renameSync7(tmpPath, path);
44930
45119
  return { kind: "acquired", path };
44931
45120
  }
44932
45121
  function releaseMcpSpawnLock(lockPath, opts = {}) {
@@ -44936,7 +45125,7 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
44936
45125
  if (!existing) return;
44937
45126
  if (existing.pid !== selfPid) return;
44938
45127
  try {
44939
- unlinkSync7(lockPath);
45128
+ unlinkSync8(lockPath);
44940
45129
  } catch {
44941
45130
  }
44942
45131
  }
@@ -44973,9 +45162,9 @@ function defaultLockMtimeMs(path) {
44973
45162
  }
44974
45163
  }
44975
45164
  function readLockHolder(path) {
44976
- if (!existsSync8(path)) return null;
45165
+ if (!existsSync9(path)) return null;
44977
45166
  try {
44978
- const raw = readFileSync13(path, "utf8");
45167
+ const raw = readFileSync14(path, "utf8");
44979
45168
  const parsed = JSON.parse(raw);
44980
45169
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
44981
45170
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -44987,7 +45176,7 @@ function readLockHolder(path) {
44987
45176
  }
44988
45177
 
44989
45178
  // src/ack-reaction.ts
44990
- import { readdirSync as readdirSync5, readFileSync as readFileSync14, writeFileSync as writeFileSync10 } from "fs";
45179
+ import { readdirSync as readdirSync5, readFileSync as readFileSync15, writeFileSync as writeFileSync11 } from "fs";
44991
45180
  import { join as join17 } from "path";
44992
45181
 
44993
45182
  // ../core/dist/channels/deflection-causes.js
@@ -45288,7 +45477,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
45288
45477
  function readGiveUpSignal(path, now = Date.now()) {
45289
45478
  if (!path) return null;
45290
45479
  try {
45291
- const raw = JSON.parse(readFileSync14(path, "utf8"));
45480
+ const raw = JSON.parse(readFileSync15(path, "utf8"));
45292
45481
  if (typeof raw.gave_up_at !== "string") return null;
45293
45482
  const t = Date.parse(raw.gave_up_at);
45294
45483
  if (!Number.isFinite(t) || t > now) return null;
@@ -45307,7 +45496,7 @@ function readUsageLimitForBusyAck(agentDir, now = Date.now()) {
45307
45496
  if (sig?.reason !== "usage_limit") return null;
45308
45497
  let lastSeenMs = null;
45309
45498
  try {
45310
- const raw = JSON.parse(readFileSync14(path, "utf8"));
45499
+ const raw = JSON.parse(readFileSync15(path, "utf8"));
45311
45500
  if (typeof raw.usage_limit_last_seen_at === "string") {
45312
45501
  const t = Date.parse(raw.usage_limit_last_seen_at);
45313
45502
  if (Number.isFinite(t) && t <= now) lastSeenMs = t;
@@ -45326,7 +45515,7 @@ function readBlockedPromptForBusyAck(agentDir, now = Date.now()) {
45326
45515
  if (!agentDir) return null;
45327
45516
  let raw;
45328
45517
  try {
45329
- raw = JSON.parse(readFileSync14(join17(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
45518
+ raw = JSON.parse(readFileSync15(join17(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
45330
45519
  } catch {
45331
45520
  return null;
45332
45521
  }
@@ -45390,7 +45579,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
45390
45579
  if (opts?.exclude?.(name)) continue;
45391
45580
  let receivedAt;
45392
45581
  try {
45393
- const raw = JSON.parse(readFileSync14(join17(dir, name), "utf-8"));
45582
+ const raw = JSON.parse(readFileSync15(join17(dir, name), "utf-8"));
45394
45583
  if (markerOwesNoReply(raw)) continue;
45395
45584
  if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
45396
45585
  receivedAt = raw.received_at;
@@ -45493,13 +45682,13 @@ function recordChannelDeflection(agentDir, channel, cause) {
45493
45682
  const path = deflectionCounterPath(agentDir, channel);
45494
45683
  let counts = {};
45495
45684
  try {
45496
- const parsed = JSON.parse(readFileSync14(path, "utf-8"));
45685
+ const parsed = JSON.parse(readFileSync15(path, "utf-8"));
45497
45686
  if (parsed && typeof parsed === "object") counts = parsed;
45498
45687
  } catch {
45499
45688
  }
45500
45689
  counts[cause] = (counts[cause] ?? 0) + 1;
45501
45690
  try {
45502
- writeFileSync10(path, JSON.stringify(counts), { mode: 384 });
45691
+ writeFileSync11(path, JSON.stringify(counts), { mode: 384 });
45503
45692
  } catch {
45504
45693
  }
45505
45694
  }
@@ -45713,7 +45902,7 @@ var PEER_PRESENCE_STATE_FILE = TELEGRAM_AGENT_DIR ? join18(TELEGRAM_AGENT_DIR, "
45713
45902
  function readPeerPresenceState() {
45714
45903
  if (!PEER_PRESENCE_STATE_FILE) return null;
45715
45904
  try {
45716
- const parsed = JSON.parse(readFileSync15(PEER_PRESENCE_STATE_FILE, "utf-8"));
45905
+ const parsed = JSON.parse(readFileSync16(PEER_PRESENCE_STATE_FILE, "utf-8"));
45717
45906
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
45718
45907
  return parsed;
45719
45908
  } catch {
@@ -45724,9 +45913,9 @@ function writePeerPresenceState(snapshot) {
45724
45913
  if (!PEER_PRESENCE_STATE_FILE || !TELEGRAM_AGENT_DIR) return;
45725
45914
  const tmp = `${PEER_PRESENCE_STATE_FILE}.tmp`;
45726
45915
  try {
45727
- mkdirSync10(TELEGRAM_AGENT_DIR, { recursive: true, mode: 448 });
45728
- writeFileSync11(tmp, JSON.stringify(snapshot), { mode: 384 });
45729
- renameSync7(tmp, PEER_PRESENCE_STATE_FILE);
45916
+ mkdirSync11(TELEGRAM_AGENT_DIR, { recursive: true, mode: 448 });
45917
+ writeFileSync12(tmp, JSON.stringify(snapshot), { mode: 384 });
45918
+ renameSync8(tmp, PEER_PRESENCE_STATE_FILE);
45730
45919
  } catch (err) {
45731
45920
  process.stderr.write(
45732
45921
  `telegram-channel(${AGENT_CODE_NAME}): peer-presence persist failed: ${err.message}
@@ -45749,7 +45938,7 @@ var stderrLogStream = null;
45749
45938
  if (AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown") {
45750
45939
  try {
45751
45940
  const logDir = join18(homedir7(), ".augmented", AGENT_CODE_NAME);
45752
- mkdirSync10(logDir, { recursive: true });
45941
+ mkdirSync11(logDir, { recursive: true });
45753
45942
  stderrLogStream = createWriteStream(join18(logDir, "telegram-channel-stderr.log"), {
45754
45943
  flags: "a",
45755
45944
  mode: 384
@@ -45808,7 +45997,7 @@ function telegramApiCall(method, body, timeoutMs) {
45808
45997
  }
45809
45998
  function sendTelegramFileMultipart(method, fileField, file, fields, timeoutMs) {
45810
45999
  return new Promise((resolvePromise, reject) => {
45811
- const boundary = `----augmented${randomUUID3().replace(/-/g, "")}`;
46000
+ const boundary = `----augmented${randomUUID4().replace(/-/g, "")}`;
45812
46001
  const body = buildTelegramMultipartBody(boundary, fileField, file, fields);
45813
46002
  const req = https.request(
45814
46003
  {
@@ -46122,9 +46311,9 @@ function notifyUndeliverable(chatId, messageId, cause = "unknown") {
46122
46311
  }
46123
46312
  function telegramMarkerReplayFacts(chatId, messageId) {
46124
46313
  const path = pendingInboundPath(chatId, messageId);
46125
- if (!path || !existsSync9(path)) return null;
46314
+ if (!path || !existsSync10(path)) return null;
46126
46315
  try {
46127
- const marker = JSON.parse(readFileSync15(path, "utf-8"));
46316
+ const marker = JSON.parse(readFileSync16(path, "utf-8"));
46128
46317
  const facts = combineMarkerReplayFacts([
46129
46318
  { hasPayload: Boolean(marker.payload), discretionary: marker.discretionary }
46130
46319
  ]);
@@ -46673,8 +46862,8 @@ async function handleRestartCommand(opts) {
46673
46862
  writeTelegramRestartConfirm({ chat_id: opts.chatId, message_id: opts.messageId }, opts.requesterName);
46674
46863
  } else {
46675
46864
  writeTelegramRestartConfirm({ chat_id: opts.chatId, message_id: opts.messageId }, opts.requesterName);
46676
- if (!existsSync9(RESTART_FLAGS_DIR)) {
46677
- mkdirSync10(RESTART_FLAGS_DIR, { recursive: true });
46865
+ if (!existsSync10(RESTART_FLAGS_DIR)) {
46866
+ mkdirSync11(RESTART_FLAGS_DIR, { recursive: true });
46678
46867
  }
46679
46868
  const flagPath = join18(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
46680
46869
  const flag = {
@@ -46683,9 +46872,9 @@ async function handleRestartCommand(opts) {
46683
46872
  ts: Date.now(),
46684
46873
  reply: { chat_id: opts.chatId, message_id: opts.messageId }
46685
46874
  };
46686
- const tmpPath = `${flagPath}.${process.pid}.${randomUUID3()}.tmp`;
46687
- writeFileSync11(tmpPath, JSON.stringify(flag) + "\n", "utf8");
46688
- renameSync7(tmpPath, flagPath);
46875
+ const tmpPath = `${flagPath}.${process.pid}.${randomUUID4()}.tmp`;
46876
+ writeFileSync12(tmpPath, JSON.stringify(flag) + "\n", "utf8");
46877
+ renameSync8(tmpPath, flagPath);
46689
46878
  }
46690
46879
  process.stderr.write(
46691
46880
  `telegram-channel(${AGENT_CODE_NAME}): /restart queued from chat ${redactId(opts.chatId)}
@@ -47098,6 +47287,17 @@ var TELEGRAM_PROCESS_BOOT_MS = Date.now();
47098
47287
  var TELEGRAM_RECENT_DMS_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-recent-dms.json") : null;
47099
47288
  var TELEGRAM_CHANNEL_ADD_RESTART_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-channel-add-restart.json") : null;
47100
47289
  var TELEGRAM_OFFSET_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-getupdates-offset.json") : null;
47290
+ var migrationReports = createMigrationReportQueue({
47291
+ io: createFileMigrationReportIO({
47292
+ filePath: AGENT_DIR ? join18(AGENT_DIR, "telegram-migration-reports.json") : null,
47293
+ dir: AGENT_DIR,
47294
+ onError: (m) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${m}
47295
+ `)
47296
+ }),
47297
+ report: (fromChatId, toChatId) => reportGroupMigrationViaApi(fromChatId, toChatId),
47298
+ log: (m) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${m}
47299
+ `)
47300
+ });
47101
47301
  var recentDms = /* @__PURE__ */ new Map();
47102
47302
  var recentDmPersister = TELEGRAM_RECENT_DMS_FILE ? createRecentDmPersister({
47103
47303
  filePath: TELEGRAM_RECENT_DMS_FILE,
@@ -47182,8 +47382,8 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
47182
47382
  ...payload ? { payload } : {}
47183
47383
  };
47184
47384
  try {
47185
- mkdirSync10(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
47186
- writeFileSync11(path, JSON.stringify(marker), { mode: 384 });
47385
+ mkdirSync11(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
47386
+ writeFileSync12(path, JSON.stringify(marker), { mode: 384 });
47187
47387
  } catch (err) {
47188
47388
  process.stderr.write(
47189
47389
  `telegram-channel(${AGENT_CODE_NAME}): pending-inbound marker write failed: ${err.message}
@@ -47194,7 +47394,7 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
47194
47394
  function rewriteTelegramMarkerInPlace(path, marker) {
47195
47395
  let fd;
47196
47396
  try {
47197
- fd = openSync2(path, "r+");
47397
+ fd = openSync3(path, "r+");
47198
47398
  const buf = Buffer.from(JSON.stringify(marker));
47199
47399
  ftruncateSync(fd, 0);
47200
47400
  writeSync(fd, buf, 0, buf.length, 0);
@@ -47202,7 +47402,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
47202
47402
  } finally {
47203
47403
  if (fd !== void 0) {
47204
47404
  try {
47205
- closeSync2(fd);
47405
+ closeSync3(fd);
47206
47406
  } catch {
47207
47407
  }
47208
47408
  }
@@ -47211,7 +47411,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
47211
47411
  function clearTelegramMarkerFileWithHeal(fullPath) {
47212
47412
  let marker = null;
47213
47413
  try {
47214
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47414
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47215
47415
  } catch {
47216
47416
  }
47217
47417
  if (marker?.chat_id) {
@@ -47224,7 +47424,7 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
47224
47424
  notifyBackOnline(marker.chat_id);
47225
47425
  }
47226
47426
  try {
47227
- if (existsSync9(fullPath)) unlinkSync8(fullPath);
47427
+ if (existsSync10(fullPath)) unlinkSync9(fullPath);
47228
47428
  sessionMarkers.release(basename(fullPath));
47229
47429
  } catch {
47230
47430
  }
@@ -47232,14 +47432,14 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
47232
47432
  function clearTelegramMarkerFileSilently(fullPath) {
47233
47433
  let marker = null;
47234
47434
  try {
47235
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47435
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47236
47436
  } catch {
47237
47437
  }
47238
47438
  if (marker?.chat_id) {
47239
47439
  cancelScheduledUndeliverableNotice(marker.chat_id);
47240
47440
  }
47241
47441
  try {
47242
- if (existsSync9(fullPath)) unlinkSync8(fullPath);
47442
+ if (existsSync10(fullPath)) unlinkSync9(fullPath);
47243
47443
  sessionMarkers.release(basename(fullPath));
47244
47444
  } catch {
47245
47445
  }
@@ -47253,7 +47453,7 @@ function markTelegramMarkerPromisedInPlace(fullPath) {
47253
47453
  function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47254
47454
  let marker;
47255
47455
  try {
47256
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47456
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47257
47457
  } catch {
47258
47458
  return false;
47259
47459
  }
@@ -47269,7 +47469,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47269
47469
  rewriteTelegramMarkerInPlace(fullPath, marker);
47270
47470
  if (!opts.promise) return false;
47271
47471
  try {
47272
- const readBack = JSON.parse(readFileSync15(fullPath, "utf-8"));
47472
+ const readBack = JSON.parse(readFileSync16(fullPath, "utf-8"));
47273
47473
  return typeof readBack.promised_at === "string" && readBack.promised_at.length > 0;
47274
47474
  } catch {
47275
47475
  return false;
@@ -47278,7 +47478,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47278
47478
  function markTelegramMarkerSeenWithHeal(fullPath) {
47279
47479
  let marker = null;
47280
47480
  try {
47281
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47481
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47282
47482
  } catch {
47283
47483
  return;
47284
47484
  }
@@ -47294,7 +47494,7 @@ function markTelegramMarkerSeenWithHeal(fullPath) {
47294
47494
  function markTelegramMarkerPromisedWithHeal(fullPath) {
47295
47495
  let marker = null;
47296
47496
  try {
47297
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47497
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47298
47498
  } catch {
47299
47499
  return;
47300
47500
  }
@@ -47310,9 +47510,9 @@ function markTelegramMarkerPromisedWithHeal(fullPath) {
47310
47510
  var telegramPromiseStampOutcome = { attempted: 0, stamped: 0 };
47311
47511
  function readPendingInboundMarker(chatId, messageId) {
47312
47512
  const path = pendingInboundPath(chatId, messageId);
47313
- if (!path || !existsSync9(path)) return null;
47513
+ if (!path || !existsSync10(path)) return null;
47314
47514
  try {
47315
- return JSON.parse(readFileSync15(path, "utf-8"));
47515
+ return JSON.parse(readFileSync16(path, "utf-8"));
47316
47516
  } catch {
47317
47517
  return null;
47318
47518
  }
@@ -47335,7 +47535,7 @@ async function processRecoveryOutboxFile(filename) {
47335
47535
  const fullPath = join18(RECOVERY_OUTBOX_DIR, filename);
47336
47536
  let payload;
47337
47537
  try {
47338
- const raw = readFileSync15(fullPath, "utf-8");
47538
+ const raw = readFileSync16(fullPath, "utf-8");
47339
47539
  payload = JSON.parse(raw);
47340
47540
  } catch (err) {
47341
47541
  process.stderr.write(
@@ -47343,7 +47543,7 @@ async function processRecoveryOutboxFile(filename) {
47343
47543
  `
47344
47544
  );
47345
47545
  try {
47346
- renameSync7(fullPath, `${fullPath}.parse-error.poison`);
47546
+ renameSync8(fullPath, `${fullPath}.parse-error.poison`);
47347
47547
  } catch {
47348
47548
  }
47349
47549
  return;
@@ -47355,7 +47555,7 @@ async function processRecoveryOutboxFile(filename) {
47355
47555
  );
47356
47556
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47357
47557
  try {
47358
- renameSync7(fullPath, `${fullPath}.malformed.poison`);
47558
+ renameSync8(fullPath, `${fullPath}.malformed.poison`);
47359
47559
  } catch {
47360
47560
  }
47361
47561
  return;
@@ -47385,7 +47585,7 @@ async function processRecoveryOutboxFile(filename) {
47385
47585
  clearPendingMessage(payload.chat_id, recoveryDrainCutoffMs);
47386
47586
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47387
47587
  try {
47388
- unlinkSync8(fullPath);
47588
+ unlinkSync9(fullPath);
47389
47589
  } catch {
47390
47590
  }
47391
47591
  return;
@@ -47423,7 +47623,7 @@ async function processRecoveryOutboxFile(filename) {
47423
47623
  if (sendSucceeded) {
47424
47624
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47425
47625
  try {
47426
- unlinkSync8(fullPath);
47626
+ unlinkSync9(fullPath);
47427
47627
  } catch {
47428
47628
  }
47429
47629
  return;
@@ -47431,7 +47631,7 @@ async function processRecoveryOutboxFile(filename) {
47431
47631
  const next = nextRetryName(filename);
47432
47632
  if (next) {
47433
47633
  try {
47434
- renameSync7(fullPath, join18(RECOVERY_OUTBOX_DIR, next.next));
47634
+ renameSync8(fullPath, join18(RECOVERY_OUTBOX_DIR, next.next));
47435
47635
  if (next.attempt >= MAX_RECOVERY_ATTEMPTS) {
47436
47636
  process.stderr.write(
47437
47637
  `telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
@@ -47484,7 +47684,7 @@ function scanRecoveryRetries() {
47484
47684
  function startRecoveryOutboxWatcher() {
47485
47685
  if (!RECOVERY_OUTBOX_DIR) return;
47486
47686
  try {
47487
- mkdirSync10(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
47687
+ mkdirSync11(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
47488
47688
  } catch (err) {
47489
47689
  process.stderr.write(
47490
47690
  `telegram-channel(${AGENT_CODE_NAME}): recovery outbox mkdir failed: ${err.message}
@@ -47502,7 +47702,7 @@ function startRecoveryOutboxWatcher() {
47502
47702
  const watcher = watch(RECOVERY_OUTBOX_DIR, (event, filename) => {
47503
47703
  if (event !== "rename" || !filename) return;
47504
47704
  if (!isFirstAttemptOutboxFile(filename)) return;
47505
- if (existsSync9(join18(RECOVERY_OUTBOX_DIR, filename))) {
47705
+ if (existsSync10(join18(RECOVERY_OUTBOX_DIR, filename))) {
47506
47706
  void processRecoveryOutboxFile(filename);
47507
47707
  }
47508
47708
  });
@@ -47535,26 +47735,26 @@ async function processNoticeOutboxFile(filename) {
47535
47735
  }
47536
47736
  if (Date.now() - mtimeMs > NOTICE_MAX_AGE_MS) {
47537
47737
  try {
47538
- unlinkSync8(fullPath);
47738
+ unlinkSync9(fullPath);
47539
47739
  } catch {
47540
47740
  }
47541
47741
  return;
47542
47742
  }
47543
47743
  let payload;
47544
47744
  try {
47545
- const parsed = JSON.parse(readFileSync15(fullPath, "utf-8"));
47745
+ const parsed = JSON.parse(readFileSync16(fullPath, "utf-8"));
47546
47746
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
47547
47747
  payload = parsed;
47548
47748
  } catch {
47549
47749
  try {
47550
- unlinkSync8(fullPath);
47750
+ unlinkSync9(fullPath);
47551
47751
  } catch {
47552
47752
  }
47553
47753
  return;
47554
47754
  }
47555
47755
  if (!payload.chat_id || !payload.text) {
47556
47756
  try {
47557
- unlinkSync8(fullPath);
47757
+ unlinkSync9(fullPath);
47558
47758
  } catch {
47559
47759
  }
47560
47760
  return;
@@ -47565,7 +47765,7 @@ async function processNoticeOutboxFile(filename) {
47565
47765
  defaultValue: false
47566
47766
  })) {
47567
47767
  try {
47568
- unlinkSync8(fullPath);
47768
+ unlinkSync9(fullPath);
47569
47769
  } catch {
47570
47770
  }
47571
47771
  return;
@@ -47594,7 +47794,7 @@ async function processNoticeOutboxFile(filename) {
47594
47794
  );
47595
47795
  }
47596
47796
  try {
47597
- unlinkSync8(fullPath);
47797
+ unlinkSync9(fullPath);
47598
47798
  } catch {
47599
47799
  }
47600
47800
  } finally {
@@ -47604,7 +47804,7 @@ async function processNoticeOutboxFile(filename) {
47604
47804
  function startNoticeOutboxWatcher() {
47605
47805
  if (!NOTICE_OUTBOX_DIR) return;
47606
47806
  try {
47607
- mkdirSync10(NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
47807
+ mkdirSync11(NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
47608
47808
  } catch (err) {
47609
47809
  process.stderr.write(
47610
47810
  `telegram-channel(${AGENT_CODE_NAME}): notice outbox mkdir failed: ${err.message}
@@ -47619,7 +47819,7 @@ function startNoticeOutboxWatcher() {
47619
47819
  try {
47620
47820
  const watcher = watch(NOTICE_OUTBOX_DIR, (event, filename) => {
47621
47821
  if (event !== "rename" || !filename) return;
47622
- if (existsSync9(join18(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
47822
+ if (existsSync10(join18(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
47623
47823
  });
47624
47824
  watcher.unref?.();
47625
47825
  } catch (err) {
@@ -47636,7 +47836,7 @@ function trackPendingMessage(chatId, messageId, chatType, undeliverable = false,
47636
47836
  }
47637
47837
  function sweepTelegramStaleMarkers(thresholdMs) {
47638
47838
  if (!PENDING_INBOUND_DIR) return;
47639
- if (!existsSync9(PENDING_INBOUND_DIR)) return;
47839
+ if (!existsSync10(PENDING_INBOUND_DIR)) return;
47640
47840
  let filenames;
47641
47841
  try {
47642
47842
  filenames = readdirSync6(PENDING_INBOUND_DIR);
@@ -47656,14 +47856,14 @@ function sweepTelegramStaleMarkers(thresholdMs) {
47656
47856
  const fullPath = join18(PENDING_INBOUND_DIR, filename);
47657
47857
  let marker;
47658
47858
  try {
47659
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47859
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47660
47860
  } catch (err) {
47661
47861
  process.stderr.write(
47662
47862
  `telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
47663
47863
  `
47664
47864
  );
47665
47865
  try {
47666
- unlinkSync8(fullPath);
47866
+ unlinkSync9(fullPath);
47667
47867
  sessionMarkers.release(filename);
47668
47868
  } catch {
47669
47869
  }
@@ -47694,7 +47894,7 @@ function sweepTelegramStaleMarkers(thresholdMs) {
47694
47894
  );
47695
47895
  }
47696
47896
  try {
47697
- unlinkSync8(fullPath);
47897
+ unlinkSync9(fullPath);
47698
47898
  sessionMarkers.release(filename);
47699
47899
  } catch {
47700
47900
  }
@@ -47720,9 +47920,9 @@ var TELEGRAM_PROGRESS_HEARTBEAT_PATH = AGENT_DIR ? join18(AGENT_DIR, "channel-pr
47720
47920
  var telegramTrackedProgress = null;
47721
47921
  var telegramProgressTickRunning = false;
47722
47922
  function readTelegramProgressHeartbeat() {
47723
- if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync9(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
47923
+ if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync10(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
47724
47924
  try {
47725
- return parseProgressHeartbeat(readFileSync15(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
47925
+ return parseProgressHeartbeat(readFileSync16(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
47726
47926
  } catch {
47727
47927
  return null;
47728
47928
  }
@@ -47731,17 +47931,17 @@ function seedTelegramProgressHeartbeat() {
47731
47931
  if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH) return;
47732
47932
  const tmp = `${TELEGRAM_PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
47733
47933
  try {
47734
- writeFileSync11(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
47735
- renameSync7(tmp, TELEGRAM_PROGRESS_HEARTBEAT_PATH);
47934
+ writeFileSync12(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
47935
+ renameSync8(tmp, TELEGRAM_PROGRESS_HEARTBEAT_PATH);
47736
47936
  } catch {
47737
47937
  try {
47738
- unlinkSync8(tmp);
47938
+ unlinkSync9(tmp);
47739
47939
  } catch {
47740
47940
  }
47741
47941
  }
47742
47942
  }
47743
47943
  function findTelegramProgressTarget() {
47744
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return null;
47944
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return null;
47745
47945
  let best = null;
47746
47946
  let bestMs = Infinity;
47747
47947
  try {
@@ -47749,7 +47949,7 @@ function findTelegramProgressTarget() {
47749
47949
  if (!name.endsWith(".json")) continue;
47750
47950
  let m;
47751
47951
  try {
47752
- m = JSON.parse(readFileSync15(join18(PENDING_INBOUND_DIR, name), "utf-8"));
47952
+ m = JSON.parse(readFileSync16(join18(PENDING_INBOUND_DIR, name), "utf-8"));
47753
47953
  } catch {
47754
47954
  continue;
47755
47955
  }
@@ -47873,14 +48073,14 @@ if (BOT_TOKEN && PENDING_INBOUND_DIR) {
47873
48073
  }
47874
48074
  var lastGiveUpHandledAtMs = null;
47875
48075
  function listPendingInboundChatIds() {
47876
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return [];
48076
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return [];
47877
48077
  const chats = /* @__PURE__ */ new Set();
47878
48078
  try {
47879
48079
  for (const name of readdirSync6(PENDING_INBOUND_DIR)) {
47880
48080
  if (!name.endsWith(".json")) continue;
47881
48081
  try {
47882
48082
  const marker = JSON.parse(
47883
- readFileSync15(join18(PENDING_INBOUND_DIR, name), "utf8")
48083
+ readFileSync16(join18(PENDING_INBOUND_DIR, name), "utf8")
47884
48084
  );
47885
48085
  if (typeof marker.seen_at === "string" && marker.seen_at) continue;
47886
48086
  if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
@@ -48061,7 +48261,7 @@ async function deliverQueuedReply(p2) {
48061
48261
  }
48062
48262
  }
48063
48263
  function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48064
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48264
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48065
48265
  clearAllTelegramPendingMarkersForChat(
48066
48266
  PENDING_INBOUND_DIR,
48067
48267
  chatId,
@@ -48071,7 +48271,7 @@ function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48071
48271
  );
48072
48272
  }
48073
48273
  function consumePendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48074
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48274
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48075
48275
  clearAllTelegramPendingMarkersForChat(
48076
48276
  PENDING_INBOUND_DIR,
48077
48277
  chatId,
@@ -48081,7 +48281,7 @@ function consumePendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48081
48281
  );
48082
48282
  }
48083
48283
  function markSeenPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48084
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48284
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48085
48285
  markSeenAllTelegramPendingMarkersForChat(
48086
48286
  PENDING_INBOUND_DIR,
48087
48287
  chatId,
@@ -48093,7 +48293,7 @@ function markSeenPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48093
48293
  function markPromisedPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48094
48294
  telegramPromiseStampOutcome.attempted = 0;
48095
48295
  telegramPromiseStampOutcome.stamped = 0;
48096
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48296
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48097
48297
  markSeenAllTelegramPendingMarkersForChat(
48098
48298
  PENDING_INBOUND_DIR,
48099
48299
  chatId,
@@ -48424,7 +48624,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
48424
48624
  isError: true
48425
48625
  };
48426
48626
  }
48427
- bytes = readFileSync15(realPath);
48627
+ bytes = readFileSync16(realPath);
48428
48628
  } catch (err) {
48429
48629
  return { content: [{ type: "text", text: `Failed to read file: ${err.message}` }], isError: true };
48430
48630
  }
@@ -49074,14 +49274,14 @@ async function claimGroupLinkCodeViaApi(code2, chat, from) {
49074
49274
  );
49075
49275
  }
49076
49276
  async function reportGroupMigrationViaApi(fromChatId, toChatId) {
49077
- if (!channelRequestInputAvailable()) return false;
49277
+ if (!channelRequestInputAvailable()) return "drop";
49078
49278
  const apiCallRuntime = await Promise.resolve().then(() => (init_ask_user_runtime(), ask_user_runtime_exports));
49079
49279
  const cfg = {
49080
49280
  apiHost: AGT_HOST,
49081
49281
  apiKey: AGT_API_KEY,
49082
49282
  agentId: AGT_AGENT_ID
49083
49283
  };
49084
- return reportTelegramGroupMigration(
49284
+ return reportTelegramGroupMigrationOutcome(
49085
49285
  async (path, body) => {
49086
49286
  const res = await apiCallRuntime.apiCall(cfg, "POST", path, body);
49087
49287
  return { status: res.status, json: await res.json().catch(() => null) };
@@ -49175,7 +49375,7 @@ await mcp.connect(new StdioServerTransport());
49175
49375
  var REPLAY_SCAN_INTERVAL_MS = 6e4;
49176
49376
  async function replayPendingTelegramMarkers() {
49177
49377
  if (!channelReplayEnabled()) return;
49178
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
49378
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
49179
49379
  const sessionState = resolveSessionLiveness({
49180
49380
  env: process.env,
49181
49381
  codeName: AGENT_CODE_NAME,
@@ -49203,7 +49403,7 @@ async function replayPendingTelegramMarkers() {
49203
49403
  const fullPath = join18(PENDING_INBOUND_DIR, name);
49204
49404
  let marker;
49205
49405
  try {
49206
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
49406
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
49207
49407
  } catch {
49208
49408
  continue;
49209
49409
  }
@@ -49356,6 +49556,7 @@ var acquiredLockPath = null;
49356
49556
  var stopLockHeartbeat = null;
49357
49557
  async function pollLoop() {
49358
49558
  while (!isShuttingDown) {
49559
+ await migrationReports.flushDue();
49359
49560
  try {
49360
49561
  const resp = await telegramApiCall(
49361
49562
  "getUpdates",
@@ -49411,7 +49612,9 @@ async function pollLoop() {
49411
49612
  const fromChatId = String(msg.chat.id);
49412
49613
  const toChatId = String(msg.migrate_to_chat_id);
49413
49614
  const admittedNow = applyMigrationToAllowlist(ALLOWED_CHATS, fromChatId, toChatId);
49414
- const reported = await reportGroupMigrationViaApi(fromChatId, toChatId);
49615
+ migrationReports.enqueue(fromChatId, toChatId);
49616
+ const outcomes = await migrationReports.flushDue();
49617
+ const reported = outcomes.get(`${fromChatId}->${toChatId}`) ?? "retry";
49415
49618
  process.stderr.write(
49416
49619
  `telegram-channel(${AGENT_CODE_NAME}): group migrated ${redactId(fromChatId)} -> ${redactId(toChatId)} admitted_now=${admittedNow} reported=${reported}
49417
49620
  `