@integrity-labs/agt-cli 0.28.1250 → 0.28.1251

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-ECOBF6BM.js +39 -0
  2. package/dist/bin/agt.js +17 -15
  3. package/dist/bin/agt.js.map +1 -1
  4. package/dist/chunk-2VGFSHFP.js +471 -0
  5. package/dist/chunk-2VGFSHFP.js.map +1 -0
  6. package/dist/{chunk-5ALBA7KT.js → chunk-4AUE34MF.js} +94 -552
  7. package/dist/chunk-4AUE34MF.js.map +1 -0
  8. package/dist/{chunk-DFJ5E5EW.js → chunk-6KY5FKXC.js} +192 -1
  9. package/dist/chunk-6KY5FKXC.js.map +1 -0
  10. package/dist/{chunk-IUMFAYZO.js → chunk-O6WRX5FE.js} +3 -3
  11. package/dist/{chunk-JOBL3ZF4.js → chunk-OAAKFU3J.js} +2 -2
  12. package/dist/{chunk-SMD577FW.js → chunk-VOMOPWFI.js} +2 -2
  13. package/dist/{claude-code-updater-5MPOBIWN.js → claude-code-updater-2TZ4TSOB.js} +3 -3
  14. package/dist/{claude-pair-runtime-SNU3CU3K.js → claude-pair-runtime-CTJCJNK4.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 +5 -0
  18. package/dist/mcp/index.js +5 -0
  19. package/dist/mcp/origami.js +5 -0
  20. package/dist/mcp/slack-channel.js +5 -0
  21. package/dist/mcp/telegram-channel.js +367 -186
  22. package/dist/{persistent-session-SYCA6MW2.js → persistent-session-TBE4KP4K.js} +4 -4
  23. package/dist/persistent-session-TBE4KP4K.js.map +1 -0
  24. package/dist/{responsiveness-probe-BUXWVOSA.js → responsiveness-probe-J7DA3AB4.js} +4 -4
  25. package/dist/{session-auth-dead-G5NHWSRP.js → session-auth-dead-OL5ODQRN.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-ECOBF6BM.js.map} +0 -0
  30. /package/dist/{chunk-IUMFAYZO.js.map → chunk-O6WRX5FE.js.map} +0 -0
  31. /package/dist/{chunk-JOBL3ZF4.js.map → chunk-OAAKFU3J.js.map} +0 -0
  32. /package/dist/{chunk-SMD577FW.js.map → chunk-VOMOPWFI.js.map} +0 -0
  33. /package/dist/{persistent-session-SYCA6MW2.js.map → claude-code-updater-2TZ4TSOB.js.map} +0 -0
  34. /package/dist/{claude-pair-runtime-SNU3CU3K.js.map → claude-pair-runtime-CTJCJNK4.js.map} +0 -0
  35. /package/dist/{responsiveness-probe-BUXWVOSA.js.map → responsiveness-probe-J7DA3AB4.js.map} +0 -0
  36. /package/dist/{session-auth-dead-G5NHWSRP.js.map → session-auth-dead-OL5ODQRN.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;
@@ -42045,7 +42212,7 @@ var TEAM_SLUG_MAX_ATTEMPTS = 20;
42045
42212
  var SUFFIX_RESERVE = `-${TEAM_SLUG_MAX_ATTEMPTS}`.length;
42046
42213
 
42047
42214
  // src/account-enforcement-notice.ts
42048
- import { readFileSync as readFileSync4 } from "fs";
42215
+ import { readFileSync as readFileSync5 } from "fs";
42049
42216
  import { homedir as homedir3 } from "os";
42050
42217
  import { join as join3 } from "path";
42051
42218
  function accountEnforcementMarkerPath(codeName) {
@@ -42057,7 +42224,7 @@ function readAccountEnforcementMarker(opts) {
42057
42224
  if (!path) return null;
42058
42225
  let raw;
42059
42226
  try {
42060
- raw = readFileSync4(path, "utf-8");
42227
+ raw = readFileSync5(path, "utf-8");
42061
42228
  } catch {
42062
42229
  return null;
42063
42230
  }
@@ -42083,7 +42250,7 @@ function shouldSendAccountWarn(opts) {
42083
42250
  }
42084
42251
 
42085
42252
  // src/turn-initiator-marker.ts
42086
- import { writeFileSync as writeFileSync4, readFileSync as readFileSync5, mkdirSync as mkdirSync4, renameSync as renameSync3 } from "fs";
42253
+ import { writeFileSync as writeFileSync5, readFileSync as readFileSync6, mkdirSync as mkdirSync5, renameSync as renameSync4 } from "fs";
42087
42254
  import { dirname as dirname3, join as join4 } from "path";
42088
42255
  var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
42089
42256
  var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
@@ -42119,24 +42286,24 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
42119
42286
  const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
42120
42287
  let existing = null;
42121
42288
  try {
42122
- const parsed = JSON.parse(readFileSync5(ledgerFile, "utf8"));
42289
+ const parsed = JSON.parse(readFileSync6(ledgerFile, "utf8"));
42123
42290
  if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
42124
42291
  } catch {
42125
42292
  }
42126
42293
  const next = foldTurnInitiatorLedger(existing, marker);
42127
42294
  const tmp = `${ledgerFile}.${process.pid}.${Date.now()}.tmp`;
42128
- writeFileSync4(tmp, JSON.stringify(next), "utf8");
42129
- renameSync3(tmp, ledgerFile);
42295
+ writeFileSync5(tmp, JSON.stringify(next), "utf8");
42296
+ renameSync4(tmp, ledgerFile);
42130
42297
  }
42131
42298
  function writeTurnInitiatorMarker(input) {
42132
42299
  const file = process.env["AGT_TURN_INITIATOR_FILE"];
42133
42300
  if (!file || !input.sender_id) return;
42134
42301
  try {
42135
- mkdirSync4(dirname3(file), { recursive: true });
42302
+ mkdirSync5(dirname3(file), { recursive: true });
42136
42303
  const marker = { ...input, ts: Date.now() };
42137
42304
  const tmp = `${file}.tmp`;
42138
- writeFileSync4(tmp, JSON.stringify(marker), "utf8");
42139
- renameSync3(tmp, file);
42305
+ writeFileSync5(tmp, JSON.stringify(marker), "utf8");
42306
+ renameSync4(tmp, file);
42140
42307
  try {
42141
42308
  updateTurnInitiatorLedger(file, marker);
42142
42309
  } catch {
@@ -42146,7 +42313,7 @@ function writeTurnInitiatorMarker(input) {
42146
42313
  }
42147
42314
 
42148
42315
  // src/turn-context.ts
42149
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync7 } from "fs";
42316
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync8 } from "fs";
42150
42317
  import { homedir as homedir4 } from "os";
42151
42318
  import { dirname as dirname4, join as join7 } from "path";
42152
42319
 
@@ -42190,14 +42357,14 @@ function resolveAgentDirAlias(input) {
42190
42357
  }
42191
42358
 
42192
42359
  // src/scheduled-turn-marker.ts
42193
- import { readFileSync as readFileSync6, unlinkSync as unlinkSync4 } from "fs";
42360
+ import { readFileSync as readFileSync7, unlinkSync as unlinkSync5 } from "fs";
42194
42361
  import { join as join6 } from "path";
42195
42362
  var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
42196
42363
  var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
42197
42364
  function clearScheduledTurnMarker(agentDir) {
42198
42365
  if (!agentDir) return;
42199
42366
  try {
42200
- unlinkSync4(join6(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
42367
+ unlinkSync5(join6(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
42201
42368
  } catch {
42202
42369
  }
42203
42370
  }
@@ -42208,7 +42375,7 @@ function writeUnattributedTurnMarker(channel, opts = {}) {
42208
42375
  try {
42209
42376
  const file = resolveTurnInitiatorFile(opts.env ?? process.env, opts.home ?? homedir4());
42210
42377
  if (!file) return;
42211
- mkdirSync5(dirname4(file), { recursive: true });
42378
+ mkdirSync6(dirname4(file), { recursive: true });
42212
42379
  updateTurnInitiatorLedger(file, {
42213
42380
  channel,
42214
42381
  sender_id: "",
@@ -42881,19 +43048,19 @@ function buildCommandRegistrations() {
42881
43048
 
42882
43049
  // src/telegram-offset-store.ts
42883
43050
  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
43051
+ existsSync as existsSync4,
43052
+ mkdirSync as mkdirSync7,
43053
+ readFileSync as readFileSync9,
43054
+ renameSync as renameSync5,
43055
+ unlinkSync as unlinkSync6,
43056
+ writeFileSync as writeFileSync6
42890
43057
  } from "fs";
42891
- import { randomUUID as randomUUID2 } from "crypto";
43058
+ import { randomUUID as randomUUID3 } from "crypto";
42892
43059
  function loadPersistedOffset(filePath) {
42893
43060
  if (!filePath) return 0;
42894
43061
  try {
42895
43062
  const parsed = JSON.parse(
42896
- readFileSync8(filePath, "utf-8")
43063
+ readFileSync9(filePath, "utf-8")
42897
43064
  );
42898
43065
  const offset = parsed?.offset;
42899
43066
  if (typeof offset === "number" && Number.isFinite(offset) && offset > 0) {
@@ -42913,15 +43080,15 @@ function persistOffset(opts) {
42913
43080
  offset,
42914
43081
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
42915
43082
  };
42916
- const tmpPath = `${filePath}.${process.pid}.${randomUUID2()}.tmp`;
43083
+ const tmpPath = `${filePath}.${process.pid}.${randomUUID3()}.tmp`;
42917
43084
  try {
42918
- mkdirSync6(dir, { recursive: true, mode: 448 });
42919
- writeFileSync5(tmpPath, JSON.stringify(marker), { mode: 384 });
42920
- renameSync4(tmpPath, filePath);
43085
+ mkdirSync7(dir, { recursive: true, mode: 448 });
43086
+ writeFileSync6(tmpPath, JSON.stringify(marker), { mode: 384 });
43087
+ renameSync5(tmpPath, filePath);
42921
43088
  } catch (err) {
42922
43089
  onError?.(`getUpdates offset persist failed: ${err.message}`);
42923
43090
  try {
42924
- if (existsSync3(tmpPath)) unlinkSync5(tmpPath);
43091
+ if (existsSync4(tmpPath)) unlinkSync6(tmpPath);
42925
43092
  } catch {
42926
43093
  }
42927
43094
  }
@@ -42937,7 +43104,7 @@ function conversationalLaneMeta(expectsReply = true) {
42937
43104
  }
42938
43105
 
42939
43106
  // src/inbound-lane-telemetry.ts
42940
- import { readFileSync as readFileSync9, writeFileSync as writeFileSync6 } from "fs";
43107
+ import { readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "fs";
42941
43108
  import { join as join8 } from "path";
42942
43109
  var LANE_CLASSIFICATION_COUNTER_SUFFIX = "-lane-classifications.json";
42943
43110
  var SUSPECTED_MISCLASSIFICATION_KEY = "suspected_misclassification";
@@ -42958,7 +43125,7 @@ function recordLaneClassification(agentDir, channel, classification) {
42958
43125
  const path = join8(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
42959
43126
  let counts = {};
42960
43127
  try {
42961
- const parsed = JSON.parse(readFileSync9(path, "utf-8"));
43128
+ const parsed = JSON.parse(readFileSync10(path, "utf-8"));
42962
43129
  if (parsed && typeof parsed === "object") counts = parsed;
42963
43130
  } catch {
42964
43131
  }
@@ -42968,21 +43135,21 @@ function recordLaneClassification(agentDir, channel, classification) {
42968
43135
  counts[SUSPECTED_MISCLASSIFICATION_KEY] = (counts[SUSPECTED_MISCLASSIFICATION_KEY] ?? 0) + 1;
42969
43136
  }
42970
43137
  try {
42971
- writeFileSync6(path, JSON.stringify(counts), { mode: 384 });
43138
+ writeFileSync7(path, JSON.stringify(counts), { mode: 384 });
42972
43139
  } catch {
42973
43140
  }
42974
43141
  }
42975
43142
 
42976
43143
  // src/agent-config-state.ts
42977
- import { existsSync as existsSync4, readFileSync as readFileSync10 } from "fs";
43144
+ import { existsSync as existsSync5, readFileSync as readFileSync11 } from "fs";
42978
43145
  import { join as join9 } from "path";
42979
43146
  var SESSION_STATE_FILENAME = "session-state.json";
42980
43147
  function readAgentSessionState(stateDir) {
42981
43148
  if (!stateDir) return null;
42982
43149
  const path = join9(stateDir, SESSION_STATE_FILENAME);
42983
- if (!existsSync4(path)) return null;
43150
+ if (!existsSync5(path)) return null;
42984
43151
  try {
42985
- const parsed = JSON.parse(readFileSync10(path, "utf-8"));
43152
+ const parsed = JSON.parse(readFileSync11(path, "utf-8"));
42986
43153
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
42987
43154
  return parsed;
42988
43155
  } catch {
@@ -43946,7 +44113,7 @@ function emitToolCallMarkupRedactionTelemetry(channel) {
43946
44113
  }
43947
44114
 
43948
44115
  // src/rate-limit-watch.ts
43949
- import { closeSync, fstatSync, openSync, readSync, readdirSync, statSync } from "fs";
44116
+ import { closeSync as closeSync2, fstatSync, openSync as openSync2, readSync, readdirSync, statSync } from "fs";
43950
44117
  import { homedir as homedir5 } from "os";
43951
44118
  import { join as join10 } from "path";
43952
44119
  var DEFAULT_WATCH_MS = 5e3;
@@ -43968,7 +44135,7 @@ function readClassifiableTail(path, sinceMs, opts) {
43968
44135
  function readTailSlice(path, bytes) {
43969
44136
  let fd;
43970
44137
  try {
43971
- fd = openSync(path, "r");
44138
+ fd = openSync2(path, "r");
43972
44139
  } catch {
43973
44140
  return null;
43974
44141
  }
@@ -43994,7 +44161,7 @@ function readTailSlice(path, bytes) {
43994
44161
  } catch {
43995
44162
  return null;
43996
44163
  } finally {
43997
- closeSync(fd);
44164
+ closeSync2(fd);
43998
44165
  }
43999
44166
  }
44000
44167
  function oldestTimestampMs(text) {
@@ -44252,7 +44419,7 @@ function describeUnparsedRefusal(text) {
44252
44419
 
44253
44420
  // src/reply-intent-runtime.ts
44254
44421
  import { execFile as execFile2 } from "child_process";
44255
- import { existsSync as existsSync5, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "fs";
44422
+ import { existsSync as existsSync6, mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "fs";
44256
44423
  import { homedir as homedir6 } from "os";
44257
44424
  import { join as join12 } from "path";
44258
44425
  var DEFAULT_CLAUDE_EVAL_MODEL = "claude-haiku-4-5-20251001";
@@ -44352,14 +44519,14 @@ async function runAnthropicMessages(prompt, opts) {
44352
44519
  }
44353
44520
  var emptyMcpConfigPath = null;
44354
44521
  function ensureEmptyMcpConfig() {
44355
- if (emptyMcpConfigPath && existsSync5(emptyMcpConfigPath)) return emptyMcpConfigPath;
44522
+ if (emptyMcpConfigPath && existsSync6(emptyMcpConfigPath)) return emptyMcpConfigPath;
44356
44523
  const dir = join12(homedir6(), ".augmented");
44357
44524
  try {
44358
- mkdirSync7(dir, { recursive: true });
44525
+ mkdirSync8(dir, { recursive: true });
44359
44526
  } catch {
44360
44527
  }
44361
44528
  const p2 = join12(dir, ".reply-intent-empty-mcp.json");
44362
- writeFileSync7(p2, JSON.stringify({ mcpServers: {} }));
44529
+ writeFileSync8(p2, JSON.stringify({ mcpServers: {} }));
44363
44530
  emptyMcpConfigPath = p2;
44364
44531
  return p2;
44365
44532
  }
@@ -44505,11 +44672,11 @@ function emitTransientApiErrorTelemetry(channel, match, original) {
44505
44672
  }
44506
44673
 
44507
44674
  // src/telegram-pending-inbound-cleanup.ts
44508
- import { readdirSync as readdirSync3, readFileSync as readFileSync11, statSync as statSync3 } from "fs";
44675
+ import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
44509
44676
  import { join as join13 } from "path";
44510
44677
  function markerArrivalMs(fullPath) {
44511
44678
  try {
44512
- const received = JSON.parse(readFileSync11(fullPath, "utf-8")).received_at;
44679
+ const received = JSON.parse(readFileSync12(fullPath, "utf-8")).received_at;
44513
44680
  const parsed = received ? Date.parse(received) : Number.NaN;
44514
44681
  if (Number.isFinite(parsed)) return parsed;
44515
44682
  } catch {
@@ -44536,7 +44703,7 @@ function markerMayDrain(i) {
44536
44703
  let hasPayload = false;
44537
44704
  try {
44538
44705
  if (i.dir) {
44539
- const read = i.read ?? ((path) => readFileSync11(path, "utf-8"));
44706
+ const read = i.read ?? ((path) => readFileSync12(path, "utf-8"));
44540
44707
  hasPayload = Boolean(JSON.parse(read(join13(i.dir, i.filename))).payload);
44541
44708
  }
44542
44709
  } catch (err) {
@@ -44603,9 +44770,9 @@ function applyToChatMarkers(pendingDir, chatId, op, cutoffMs, reachedSession) {
44603
44770
  }
44604
44771
 
44605
44772
  // src/recovery-ledger.ts
44606
- import { existsSync as existsSync6, unlinkSync as unlinkSync6 } from "fs";
44773
+ import { existsSync as existsSync7, unlinkSync as unlinkSync7 } from "fs";
44607
44774
  import { join as join14 } from "path";
44608
- function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => existsSync6(p2)) {
44775
+ function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => existsSync7(p2)) {
44609
44776
  if (!ledgerDir || !markerName) return false;
44610
44777
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return false;
44611
44778
  try {
@@ -44615,7 +44782,7 @@ function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => exist
44615
44782
  }
44616
44783
  }
44617
44784
  function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
44618
- if (existsSync6(p2)) unlinkSync6(p2);
44785
+ if (existsSync7(p2)) unlinkSync7(p2);
44619
44786
  }) {
44620
44787
  if (!ledgerDir || !markerName) return;
44621
44788
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
@@ -44626,18 +44793,18 @@ function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
44626
44793
  }
44627
44794
 
44628
44795
  // 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";
44796
+ import { existsSync as existsSync8, mkdirSync as mkdirSync9, readdirSync as readdirSync4, readFileSync as readFileSync13, renameSync as renameSync6, writeFileSync as writeFileSync9 } from "fs";
44630
44797
  import { join as join15 } from "path";
44631
44798
  function safeInboundId(inboundId) {
44632
44799
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
44633
44800
  }
44634
44801
  var defaultDeps = {
44635
- mkdir: (dir) => mkdirSync8(dir, { recursive: true }),
44636
- writeFile: (path, data) => writeFileSync8(path, data, "utf8"),
44637
- rename: (from, to) => renameSync5(from, to),
44802
+ mkdir: (dir) => mkdirSync9(dir, { recursive: true }),
44803
+ writeFile: (path, data) => writeFileSync9(path, data, "utf8"),
44804
+ rename: (from, to) => renameSync6(from, to),
44638
44805
  readdir: (dir) => readdirSync4(dir),
44639
- readFile: (path) => readFileSync12(path, "utf8"),
44640
- exists: (path) => existsSync7(path)
44806
+ readFile: (path) => readFileSync13(path, "utf8"),
44807
+ exists: (path) => existsSync8(path)
44641
44808
  };
44642
44809
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
44643
44810
  if (!dir || !record2.inbound_id || !record2.conv_key) return;
@@ -44876,14 +45043,14 @@ function createKanbanCardActiveClient(args) {
44876
45043
 
44877
45044
  // src/mcp-spawn-lock.ts
44878
45045
  import {
44879
- existsSync as existsSync8,
44880
- mkdirSync as mkdirSync9,
44881
- readFileSync as readFileSync13,
44882
- renameSync as renameSync6,
45046
+ existsSync as existsSync9,
45047
+ mkdirSync as mkdirSync10,
45048
+ readFileSync as readFileSync14,
45049
+ renameSync as renameSync7,
44883
45050
  statSync as statSync4,
44884
- unlinkSync as unlinkSync7,
45051
+ unlinkSync as unlinkSync8,
44885
45052
  utimesSync,
44886
- writeFileSync as writeFileSync9
45053
+ writeFileSync as writeFileSync10
44887
45054
  } from "fs";
44888
45055
  import { join as join16 } from "path";
44889
45056
  var STALE_LOCK_MS = 9e4;
@@ -44922,11 +45089,11 @@ function acquireMcpSpawnLock(args) {
44922
45089
  }
44923
45090
  }
44924
45091
  }
44925
- mkdirSync9(agentDir, { recursive: true, mode: 448 });
45092
+ mkdirSync10(agentDir, { recursive: true, mode: 448 });
44926
45093
  const tmpPath = `${path}.${selfPid}.tmp`;
44927
45094
  const payload = { pid: selfPid, started_at: now() };
44928
- writeFileSync9(tmpPath, JSON.stringify(payload), { mode: 384 });
44929
- renameSync6(tmpPath, path);
45095
+ writeFileSync10(tmpPath, JSON.stringify(payload), { mode: 384 });
45096
+ renameSync7(tmpPath, path);
44930
45097
  return { kind: "acquired", path };
44931
45098
  }
44932
45099
  function releaseMcpSpawnLock(lockPath, opts = {}) {
@@ -44936,7 +45103,7 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
44936
45103
  if (!existing) return;
44937
45104
  if (existing.pid !== selfPid) return;
44938
45105
  try {
44939
- unlinkSync7(lockPath);
45106
+ unlinkSync8(lockPath);
44940
45107
  } catch {
44941
45108
  }
44942
45109
  }
@@ -44973,9 +45140,9 @@ function defaultLockMtimeMs(path) {
44973
45140
  }
44974
45141
  }
44975
45142
  function readLockHolder(path) {
44976
- if (!existsSync8(path)) return null;
45143
+ if (!existsSync9(path)) return null;
44977
45144
  try {
44978
- const raw = readFileSync13(path, "utf8");
45145
+ const raw = readFileSync14(path, "utf8");
44979
45146
  const parsed = JSON.parse(raw);
44980
45147
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
44981
45148
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -44987,7 +45154,7 @@ function readLockHolder(path) {
44987
45154
  }
44988
45155
 
44989
45156
  // src/ack-reaction.ts
44990
- import { readdirSync as readdirSync5, readFileSync as readFileSync14, writeFileSync as writeFileSync10 } from "fs";
45157
+ import { readdirSync as readdirSync5, readFileSync as readFileSync15, writeFileSync as writeFileSync11 } from "fs";
44991
45158
  import { join as join17 } from "path";
44992
45159
 
44993
45160
  // ../core/dist/channels/deflection-causes.js
@@ -45288,7 +45455,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
45288
45455
  function readGiveUpSignal(path, now = Date.now()) {
45289
45456
  if (!path) return null;
45290
45457
  try {
45291
- const raw = JSON.parse(readFileSync14(path, "utf8"));
45458
+ const raw = JSON.parse(readFileSync15(path, "utf8"));
45292
45459
  if (typeof raw.gave_up_at !== "string") return null;
45293
45460
  const t = Date.parse(raw.gave_up_at);
45294
45461
  if (!Number.isFinite(t) || t > now) return null;
@@ -45307,7 +45474,7 @@ function readUsageLimitForBusyAck(agentDir, now = Date.now()) {
45307
45474
  if (sig?.reason !== "usage_limit") return null;
45308
45475
  let lastSeenMs = null;
45309
45476
  try {
45310
- const raw = JSON.parse(readFileSync14(path, "utf8"));
45477
+ const raw = JSON.parse(readFileSync15(path, "utf8"));
45311
45478
  if (typeof raw.usage_limit_last_seen_at === "string") {
45312
45479
  const t = Date.parse(raw.usage_limit_last_seen_at);
45313
45480
  if (Number.isFinite(t) && t <= now) lastSeenMs = t;
@@ -45326,7 +45493,7 @@ function readBlockedPromptForBusyAck(agentDir, now = Date.now()) {
45326
45493
  if (!agentDir) return null;
45327
45494
  let raw;
45328
45495
  try {
45329
- raw = JSON.parse(readFileSync14(join17(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
45496
+ raw = JSON.parse(readFileSync15(join17(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
45330
45497
  } catch {
45331
45498
  return null;
45332
45499
  }
@@ -45390,7 +45557,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
45390
45557
  if (opts?.exclude?.(name)) continue;
45391
45558
  let receivedAt;
45392
45559
  try {
45393
- const raw = JSON.parse(readFileSync14(join17(dir, name), "utf-8"));
45560
+ const raw = JSON.parse(readFileSync15(join17(dir, name), "utf-8"));
45394
45561
  if (markerOwesNoReply(raw)) continue;
45395
45562
  if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
45396
45563
  receivedAt = raw.received_at;
@@ -45493,13 +45660,13 @@ function recordChannelDeflection(agentDir, channel, cause) {
45493
45660
  const path = deflectionCounterPath(agentDir, channel);
45494
45661
  let counts = {};
45495
45662
  try {
45496
- const parsed = JSON.parse(readFileSync14(path, "utf-8"));
45663
+ const parsed = JSON.parse(readFileSync15(path, "utf-8"));
45497
45664
  if (parsed && typeof parsed === "object") counts = parsed;
45498
45665
  } catch {
45499
45666
  }
45500
45667
  counts[cause] = (counts[cause] ?? 0) + 1;
45501
45668
  try {
45502
- writeFileSync10(path, JSON.stringify(counts), { mode: 384 });
45669
+ writeFileSync11(path, JSON.stringify(counts), { mode: 384 });
45503
45670
  } catch {
45504
45671
  }
45505
45672
  }
@@ -45713,7 +45880,7 @@ var PEER_PRESENCE_STATE_FILE = TELEGRAM_AGENT_DIR ? join18(TELEGRAM_AGENT_DIR, "
45713
45880
  function readPeerPresenceState() {
45714
45881
  if (!PEER_PRESENCE_STATE_FILE) return null;
45715
45882
  try {
45716
- const parsed = JSON.parse(readFileSync15(PEER_PRESENCE_STATE_FILE, "utf-8"));
45883
+ const parsed = JSON.parse(readFileSync16(PEER_PRESENCE_STATE_FILE, "utf-8"));
45717
45884
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
45718
45885
  return parsed;
45719
45886
  } catch {
@@ -45724,9 +45891,9 @@ function writePeerPresenceState(snapshot) {
45724
45891
  if (!PEER_PRESENCE_STATE_FILE || !TELEGRAM_AGENT_DIR) return;
45725
45892
  const tmp = `${PEER_PRESENCE_STATE_FILE}.tmp`;
45726
45893
  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);
45894
+ mkdirSync11(TELEGRAM_AGENT_DIR, { recursive: true, mode: 448 });
45895
+ writeFileSync12(tmp, JSON.stringify(snapshot), { mode: 384 });
45896
+ renameSync8(tmp, PEER_PRESENCE_STATE_FILE);
45730
45897
  } catch (err) {
45731
45898
  process.stderr.write(
45732
45899
  `telegram-channel(${AGENT_CODE_NAME}): peer-presence persist failed: ${err.message}
@@ -45749,7 +45916,7 @@ var stderrLogStream = null;
45749
45916
  if (AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown") {
45750
45917
  try {
45751
45918
  const logDir = join18(homedir7(), ".augmented", AGENT_CODE_NAME);
45752
- mkdirSync10(logDir, { recursive: true });
45919
+ mkdirSync11(logDir, { recursive: true });
45753
45920
  stderrLogStream = createWriteStream(join18(logDir, "telegram-channel-stderr.log"), {
45754
45921
  flags: "a",
45755
45922
  mode: 384
@@ -45808,7 +45975,7 @@ function telegramApiCall(method, body, timeoutMs) {
45808
45975
  }
45809
45976
  function sendTelegramFileMultipart(method, fileField, file, fields, timeoutMs) {
45810
45977
  return new Promise((resolvePromise, reject) => {
45811
- const boundary = `----augmented${randomUUID3().replace(/-/g, "")}`;
45978
+ const boundary = `----augmented${randomUUID4().replace(/-/g, "")}`;
45812
45979
  const body = buildTelegramMultipartBody(boundary, fileField, file, fields);
45813
45980
  const req = https.request(
45814
45981
  {
@@ -46122,9 +46289,9 @@ function notifyUndeliverable(chatId, messageId, cause = "unknown") {
46122
46289
  }
46123
46290
  function telegramMarkerReplayFacts(chatId, messageId) {
46124
46291
  const path = pendingInboundPath(chatId, messageId);
46125
- if (!path || !existsSync9(path)) return null;
46292
+ if (!path || !existsSync10(path)) return null;
46126
46293
  try {
46127
- const marker = JSON.parse(readFileSync15(path, "utf-8"));
46294
+ const marker = JSON.parse(readFileSync16(path, "utf-8"));
46128
46295
  const facts = combineMarkerReplayFacts([
46129
46296
  { hasPayload: Boolean(marker.payload), discretionary: marker.discretionary }
46130
46297
  ]);
@@ -46673,8 +46840,8 @@ async function handleRestartCommand(opts) {
46673
46840
  writeTelegramRestartConfirm({ chat_id: opts.chatId, message_id: opts.messageId }, opts.requesterName);
46674
46841
  } else {
46675
46842
  writeTelegramRestartConfirm({ chat_id: opts.chatId, message_id: opts.messageId }, opts.requesterName);
46676
- if (!existsSync9(RESTART_FLAGS_DIR)) {
46677
- mkdirSync10(RESTART_FLAGS_DIR, { recursive: true });
46843
+ if (!existsSync10(RESTART_FLAGS_DIR)) {
46844
+ mkdirSync11(RESTART_FLAGS_DIR, { recursive: true });
46678
46845
  }
46679
46846
  const flagPath = join18(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
46680
46847
  const flag = {
@@ -46683,9 +46850,9 @@ async function handleRestartCommand(opts) {
46683
46850
  ts: Date.now(),
46684
46851
  reply: { chat_id: opts.chatId, message_id: opts.messageId }
46685
46852
  };
46686
- const tmpPath = `${flagPath}.${process.pid}.${randomUUID3()}.tmp`;
46687
- writeFileSync11(tmpPath, JSON.stringify(flag) + "\n", "utf8");
46688
- renameSync7(tmpPath, flagPath);
46853
+ const tmpPath = `${flagPath}.${process.pid}.${randomUUID4()}.tmp`;
46854
+ writeFileSync12(tmpPath, JSON.stringify(flag) + "\n", "utf8");
46855
+ renameSync8(tmpPath, flagPath);
46689
46856
  }
46690
46857
  process.stderr.write(
46691
46858
  `telegram-channel(${AGENT_CODE_NAME}): /restart queued from chat ${redactId(opts.chatId)}
@@ -47098,6 +47265,17 @@ var TELEGRAM_PROCESS_BOOT_MS = Date.now();
47098
47265
  var TELEGRAM_RECENT_DMS_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-recent-dms.json") : null;
47099
47266
  var TELEGRAM_CHANNEL_ADD_RESTART_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-channel-add-restart.json") : null;
47100
47267
  var TELEGRAM_OFFSET_FILE = AGENT_DIR ? join18(AGENT_DIR, "telegram-getupdates-offset.json") : null;
47268
+ var migrationReports = createMigrationReportQueue({
47269
+ io: createFileMigrationReportIO({
47270
+ filePath: AGENT_DIR ? join18(AGENT_DIR, "telegram-migration-reports.json") : null,
47271
+ dir: AGENT_DIR,
47272
+ onError: (m) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${m}
47273
+ `)
47274
+ }),
47275
+ report: (fromChatId, toChatId) => reportGroupMigrationViaApi(fromChatId, toChatId),
47276
+ log: (m) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${m}
47277
+ `)
47278
+ });
47101
47279
  var recentDms = /* @__PURE__ */ new Map();
47102
47280
  var recentDmPersister = TELEGRAM_RECENT_DMS_FILE ? createRecentDmPersister({
47103
47281
  filePath: TELEGRAM_RECENT_DMS_FILE,
@@ -47182,8 +47360,8 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
47182
47360
  ...payload ? { payload } : {}
47183
47361
  };
47184
47362
  try {
47185
- mkdirSync10(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
47186
- writeFileSync11(path, JSON.stringify(marker), { mode: 384 });
47363
+ mkdirSync11(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
47364
+ writeFileSync12(path, JSON.stringify(marker), { mode: 384 });
47187
47365
  } catch (err) {
47188
47366
  process.stderr.write(
47189
47367
  `telegram-channel(${AGENT_CODE_NAME}): pending-inbound marker write failed: ${err.message}
@@ -47194,7 +47372,7 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
47194
47372
  function rewriteTelegramMarkerInPlace(path, marker) {
47195
47373
  let fd;
47196
47374
  try {
47197
- fd = openSync2(path, "r+");
47375
+ fd = openSync3(path, "r+");
47198
47376
  const buf = Buffer.from(JSON.stringify(marker));
47199
47377
  ftruncateSync(fd, 0);
47200
47378
  writeSync(fd, buf, 0, buf.length, 0);
@@ -47202,7 +47380,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
47202
47380
  } finally {
47203
47381
  if (fd !== void 0) {
47204
47382
  try {
47205
- closeSync2(fd);
47383
+ closeSync3(fd);
47206
47384
  } catch {
47207
47385
  }
47208
47386
  }
@@ -47211,7 +47389,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
47211
47389
  function clearTelegramMarkerFileWithHeal(fullPath) {
47212
47390
  let marker = null;
47213
47391
  try {
47214
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47392
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47215
47393
  } catch {
47216
47394
  }
47217
47395
  if (marker?.chat_id) {
@@ -47224,7 +47402,7 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
47224
47402
  notifyBackOnline(marker.chat_id);
47225
47403
  }
47226
47404
  try {
47227
- if (existsSync9(fullPath)) unlinkSync8(fullPath);
47405
+ if (existsSync10(fullPath)) unlinkSync9(fullPath);
47228
47406
  sessionMarkers.release(basename(fullPath));
47229
47407
  } catch {
47230
47408
  }
@@ -47232,14 +47410,14 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
47232
47410
  function clearTelegramMarkerFileSilently(fullPath) {
47233
47411
  let marker = null;
47234
47412
  try {
47235
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47413
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47236
47414
  } catch {
47237
47415
  }
47238
47416
  if (marker?.chat_id) {
47239
47417
  cancelScheduledUndeliverableNotice(marker.chat_id);
47240
47418
  }
47241
47419
  try {
47242
- if (existsSync9(fullPath)) unlinkSync8(fullPath);
47420
+ if (existsSync10(fullPath)) unlinkSync9(fullPath);
47243
47421
  sessionMarkers.release(basename(fullPath));
47244
47422
  } catch {
47245
47423
  }
@@ -47253,7 +47431,7 @@ function markTelegramMarkerPromisedInPlace(fullPath) {
47253
47431
  function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47254
47432
  let marker;
47255
47433
  try {
47256
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47434
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47257
47435
  } catch {
47258
47436
  return false;
47259
47437
  }
@@ -47269,7 +47447,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47269
47447
  rewriteTelegramMarkerInPlace(fullPath, marker);
47270
47448
  if (!opts.promise) return false;
47271
47449
  try {
47272
- const readBack = JSON.parse(readFileSync15(fullPath, "utf-8"));
47450
+ const readBack = JSON.parse(readFileSync16(fullPath, "utf-8"));
47273
47451
  return typeof readBack.promised_at === "string" && readBack.promised_at.length > 0;
47274
47452
  } catch {
47275
47453
  return false;
@@ -47278,7 +47456,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
47278
47456
  function markTelegramMarkerSeenWithHeal(fullPath) {
47279
47457
  let marker = null;
47280
47458
  try {
47281
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47459
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47282
47460
  } catch {
47283
47461
  return;
47284
47462
  }
@@ -47294,7 +47472,7 @@ function markTelegramMarkerSeenWithHeal(fullPath) {
47294
47472
  function markTelegramMarkerPromisedWithHeal(fullPath) {
47295
47473
  let marker = null;
47296
47474
  try {
47297
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47475
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47298
47476
  } catch {
47299
47477
  return;
47300
47478
  }
@@ -47310,9 +47488,9 @@ function markTelegramMarkerPromisedWithHeal(fullPath) {
47310
47488
  var telegramPromiseStampOutcome = { attempted: 0, stamped: 0 };
47311
47489
  function readPendingInboundMarker(chatId, messageId) {
47312
47490
  const path = pendingInboundPath(chatId, messageId);
47313
- if (!path || !existsSync9(path)) return null;
47491
+ if (!path || !existsSync10(path)) return null;
47314
47492
  try {
47315
- return JSON.parse(readFileSync15(path, "utf-8"));
47493
+ return JSON.parse(readFileSync16(path, "utf-8"));
47316
47494
  } catch {
47317
47495
  return null;
47318
47496
  }
@@ -47335,7 +47513,7 @@ async function processRecoveryOutboxFile(filename) {
47335
47513
  const fullPath = join18(RECOVERY_OUTBOX_DIR, filename);
47336
47514
  let payload;
47337
47515
  try {
47338
- const raw = readFileSync15(fullPath, "utf-8");
47516
+ const raw = readFileSync16(fullPath, "utf-8");
47339
47517
  payload = JSON.parse(raw);
47340
47518
  } catch (err) {
47341
47519
  process.stderr.write(
@@ -47343,7 +47521,7 @@ async function processRecoveryOutboxFile(filename) {
47343
47521
  `
47344
47522
  );
47345
47523
  try {
47346
- renameSync7(fullPath, `${fullPath}.parse-error.poison`);
47524
+ renameSync8(fullPath, `${fullPath}.parse-error.poison`);
47347
47525
  } catch {
47348
47526
  }
47349
47527
  return;
@@ -47355,7 +47533,7 @@ async function processRecoveryOutboxFile(filename) {
47355
47533
  );
47356
47534
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47357
47535
  try {
47358
- renameSync7(fullPath, `${fullPath}.malformed.poison`);
47536
+ renameSync8(fullPath, `${fullPath}.malformed.poison`);
47359
47537
  } catch {
47360
47538
  }
47361
47539
  return;
@@ -47385,7 +47563,7 @@ async function processRecoveryOutboxFile(filename) {
47385
47563
  clearPendingMessage(payload.chat_id, recoveryDrainCutoffMs);
47386
47564
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47387
47565
  try {
47388
- unlinkSync8(fullPath);
47566
+ unlinkSync9(fullPath);
47389
47567
  } catch {
47390
47568
  }
47391
47569
  return;
@@ -47423,7 +47601,7 @@ async function processRecoveryOutboxFile(filename) {
47423
47601
  if (sendSucceeded) {
47424
47602
  removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
47425
47603
  try {
47426
- unlinkSync8(fullPath);
47604
+ unlinkSync9(fullPath);
47427
47605
  } catch {
47428
47606
  }
47429
47607
  return;
@@ -47431,7 +47609,7 @@ async function processRecoveryOutboxFile(filename) {
47431
47609
  const next = nextRetryName(filename);
47432
47610
  if (next) {
47433
47611
  try {
47434
- renameSync7(fullPath, join18(RECOVERY_OUTBOX_DIR, next.next));
47612
+ renameSync8(fullPath, join18(RECOVERY_OUTBOX_DIR, next.next));
47435
47613
  if (next.attempt >= MAX_RECOVERY_ATTEMPTS) {
47436
47614
  process.stderr.write(
47437
47615
  `telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
@@ -47484,7 +47662,7 @@ function scanRecoveryRetries() {
47484
47662
  function startRecoveryOutboxWatcher() {
47485
47663
  if (!RECOVERY_OUTBOX_DIR) return;
47486
47664
  try {
47487
- mkdirSync10(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
47665
+ mkdirSync11(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
47488
47666
  } catch (err) {
47489
47667
  process.stderr.write(
47490
47668
  `telegram-channel(${AGENT_CODE_NAME}): recovery outbox mkdir failed: ${err.message}
@@ -47502,7 +47680,7 @@ function startRecoveryOutboxWatcher() {
47502
47680
  const watcher = watch(RECOVERY_OUTBOX_DIR, (event, filename) => {
47503
47681
  if (event !== "rename" || !filename) return;
47504
47682
  if (!isFirstAttemptOutboxFile(filename)) return;
47505
- if (existsSync9(join18(RECOVERY_OUTBOX_DIR, filename))) {
47683
+ if (existsSync10(join18(RECOVERY_OUTBOX_DIR, filename))) {
47506
47684
  void processRecoveryOutboxFile(filename);
47507
47685
  }
47508
47686
  });
@@ -47535,26 +47713,26 @@ async function processNoticeOutboxFile(filename) {
47535
47713
  }
47536
47714
  if (Date.now() - mtimeMs > NOTICE_MAX_AGE_MS) {
47537
47715
  try {
47538
- unlinkSync8(fullPath);
47716
+ unlinkSync9(fullPath);
47539
47717
  } catch {
47540
47718
  }
47541
47719
  return;
47542
47720
  }
47543
47721
  let payload;
47544
47722
  try {
47545
- const parsed = JSON.parse(readFileSync15(fullPath, "utf-8"));
47723
+ const parsed = JSON.parse(readFileSync16(fullPath, "utf-8"));
47546
47724
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
47547
47725
  payload = parsed;
47548
47726
  } catch {
47549
47727
  try {
47550
- unlinkSync8(fullPath);
47728
+ unlinkSync9(fullPath);
47551
47729
  } catch {
47552
47730
  }
47553
47731
  return;
47554
47732
  }
47555
47733
  if (!payload.chat_id || !payload.text) {
47556
47734
  try {
47557
- unlinkSync8(fullPath);
47735
+ unlinkSync9(fullPath);
47558
47736
  } catch {
47559
47737
  }
47560
47738
  return;
@@ -47565,7 +47743,7 @@ async function processNoticeOutboxFile(filename) {
47565
47743
  defaultValue: false
47566
47744
  })) {
47567
47745
  try {
47568
- unlinkSync8(fullPath);
47746
+ unlinkSync9(fullPath);
47569
47747
  } catch {
47570
47748
  }
47571
47749
  return;
@@ -47594,7 +47772,7 @@ async function processNoticeOutboxFile(filename) {
47594
47772
  );
47595
47773
  }
47596
47774
  try {
47597
- unlinkSync8(fullPath);
47775
+ unlinkSync9(fullPath);
47598
47776
  } catch {
47599
47777
  }
47600
47778
  } finally {
@@ -47604,7 +47782,7 @@ async function processNoticeOutboxFile(filename) {
47604
47782
  function startNoticeOutboxWatcher() {
47605
47783
  if (!NOTICE_OUTBOX_DIR) return;
47606
47784
  try {
47607
- mkdirSync10(NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
47785
+ mkdirSync11(NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
47608
47786
  } catch (err) {
47609
47787
  process.stderr.write(
47610
47788
  `telegram-channel(${AGENT_CODE_NAME}): notice outbox mkdir failed: ${err.message}
@@ -47619,7 +47797,7 @@ function startNoticeOutboxWatcher() {
47619
47797
  try {
47620
47798
  const watcher = watch(NOTICE_OUTBOX_DIR, (event, filename) => {
47621
47799
  if (event !== "rename" || !filename) return;
47622
- if (existsSync9(join18(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
47800
+ if (existsSync10(join18(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
47623
47801
  });
47624
47802
  watcher.unref?.();
47625
47803
  } catch (err) {
@@ -47636,7 +47814,7 @@ function trackPendingMessage(chatId, messageId, chatType, undeliverable = false,
47636
47814
  }
47637
47815
  function sweepTelegramStaleMarkers(thresholdMs) {
47638
47816
  if (!PENDING_INBOUND_DIR) return;
47639
- if (!existsSync9(PENDING_INBOUND_DIR)) return;
47817
+ if (!existsSync10(PENDING_INBOUND_DIR)) return;
47640
47818
  let filenames;
47641
47819
  try {
47642
47820
  filenames = readdirSync6(PENDING_INBOUND_DIR);
@@ -47656,14 +47834,14 @@ function sweepTelegramStaleMarkers(thresholdMs) {
47656
47834
  const fullPath = join18(PENDING_INBOUND_DIR, filename);
47657
47835
  let marker;
47658
47836
  try {
47659
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
47837
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
47660
47838
  } catch (err) {
47661
47839
  process.stderr.write(
47662
47840
  `telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
47663
47841
  `
47664
47842
  );
47665
47843
  try {
47666
- unlinkSync8(fullPath);
47844
+ unlinkSync9(fullPath);
47667
47845
  sessionMarkers.release(filename);
47668
47846
  } catch {
47669
47847
  }
@@ -47694,7 +47872,7 @@ function sweepTelegramStaleMarkers(thresholdMs) {
47694
47872
  );
47695
47873
  }
47696
47874
  try {
47697
- unlinkSync8(fullPath);
47875
+ unlinkSync9(fullPath);
47698
47876
  sessionMarkers.release(filename);
47699
47877
  } catch {
47700
47878
  }
@@ -47720,9 +47898,9 @@ var TELEGRAM_PROGRESS_HEARTBEAT_PATH = AGENT_DIR ? join18(AGENT_DIR, "channel-pr
47720
47898
  var telegramTrackedProgress = null;
47721
47899
  var telegramProgressTickRunning = false;
47722
47900
  function readTelegramProgressHeartbeat() {
47723
- if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync9(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
47901
+ if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync10(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
47724
47902
  try {
47725
- return parseProgressHeartbeat(readFileSync15(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
47903
+ return parseProgressHeartbeat(readFileSync16(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
47726
47904
  } catch {
47727
47905
  return null;
47728
47906
  }
@@ -47731,17 +47909,17 @@ function seedTelegramProgressHeartbeat() {
47731
47909
  if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH) return;
47732
47910
  const tmp = `${TELEGRAM_PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
47733
47911
  try {
47734
- writeFileSync11(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
47735
- renameSync7(tmp, TELEGRAM_PROGRESS_HEARTBEAT_PATH);
47912
+ writeFileSync12(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
47913
+ renameSync8(tmp, TELEGRAM_PROGRESS_HEARTBEAT_PATH);
47736
47914
  } catch {
47737
47915
  try {
47738
- unlinkSync8(tmp);
47916
+ unlinkSync9(tmp);
47739
47917
  } catch {
47740
47918
  }
47741
47919
  }
47742
47920
  }
47743
47921
  function findTelegramProgressTarget() {
47744
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return null;
47922
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return null;
47745
47923
  let best = null;
47746
47924
  let bestMs = Infinity;
47747
47925
  try {
@@ -47749,7 +47927,7 @@ function findTelegramProgressTarget() {
47749
47927
  if (!name.endsWith(".json")) continue;
47750
47928
  let m;
47751
47929
  try {
47752
- m = JSON.parse(readFileSync15(join18(PENDING_INBOUND_DIR, name), "utf-8"));
47930
+ m = JSON.parse(readFileSync16(join18(PENDING_INBOUND_DIR, name), "utf-8"));
47753
47931
  } catch {
47754
47932
  continue;
47755
47933
  }
@@ -47873,14 +48051,14 @@ if (BOT_TOKEN && PENDING_INBOUND_DIR) {
47873
48051
  }
47874
48052
  var lastGiveUpHandledAtMs = null;
47875
48053
  function listPendingInboundChatIds() {
47876
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return [];
48054
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return [];
47877
48055
  const chats = /* @__PURE__ */ new Set();
47878
48056
  try {
47879
48057
  for (const name of readdirSync6(PENDING_INBOUND_DIR)) {
47880
48058
  if (!name.endsWith(".json")) continue;
47881
48059
  try {
47882
48060
  const marker = JSON.parse(
47883
- readFileSync15(join18(PENDING_INBOUND_DIR, name), "utf8")
48061
+ readFileSync16(join18(PENDING_INBOUND_DIR, name), "utf8")
47884
48062
  );
47885
48063
  if (typeof marker.seen_at === "string" && marker.seen_at) continue;
47886
48064
  if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
@@ -48061,7 +48239,7 @@ async function deliverQueuedReply(p2) {
48061
48239
  }
48062
48240
  }
48063
48241
  function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48064
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48242
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48065
48243
  clearAllTelegramPendingMarkersForChat(
48066
48244
  PENDING_INBOUND_DIR,
48067
48245
  chatId,
@@ -48071,7 +48249,7 @@ function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48071
48249
  );
48072
48250
  }
48073
48251
  function consumePendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48074
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48252
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48075
48253
  clearAllTelegramPendingMarkersForChat(
48076
48254
  PENDING_INBOUND_DIR,
48077
48255
  chatId,
@@ -48081,7 +48259,7 @@ function consumePendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48081
48259
  );
48082
48260
  }
48083
48261
  function markSeenPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48084
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48262
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48085
48263
  markSeenAllTelegramPendingMarkersForChat(
48086
48264
  PENDING_INBOUND_DIR,
48087
48265
  chatId,
@@ -48093,7 +48271,7 @@ function markSeenPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48093
48271
  function markPromisedPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
48094
48272
  telegramPromiseStampOutcome.attempted = 0;
48095
48273
  telegramPromiseStampOutcome.stamped = 0;
48096
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
48274
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
48097
48275
  markSeenAllTelegramPendingMarkersForChat(
48098
48276
  PENDING_INBOUND_DIR,
48099
48277
  chatId,
@@ -48424,7 +48602,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
48424
48602
  isError: true
48425
48603
  };
48426
48604
  }
48427
- bytes = readFileSync15(realPath);
48605
+ bytes = readFileSync16(realPath);
48428
48606
  } catch (err) {
48429
48607
  return { content: [{ type: "text", text: `Failed to read file: ${err.message}` }], isError: true };
48430
48608
  }
@@ -49074,14 +49252,14 @@ async function claimGroupLinkCodeViaApi(code2, chat, from) {
49074
49252
  );
49075
49253
  }
49076
49254
  async function reportGroupMigrationViaApi(fromChatId, toChatId) {
49077
- if (!channelRequestInputAvailable()) return false;
49255
+ if (!channelRequestInputAvailable()) return "drop";
49078
49256
  const apiCallRuntime = await Promise.resolve().then(() => (init_ask_user_runtime(), ask_user_runtime_exports));
49079
49257
  const cfg = {
49080
49258
  apiHost: AGT_HOST,
49081
49259
  apiKey: AGT_API_KEY,
49082
49260
  agentId: AGT_AGENT_ID
49083
49261
  };
49084
- return reportTelegramGroupMigration(
49262
+ return reportTelegramGroupMigrationOutcome(
49085
49263
  async (path, body) => {
49086
49264
  const res = await apiCallRuntime.apiCall(cfg, "POST", path, body);
49087
49265
  return { status: res.status, json: await res.json().catch(() => null) };
@@ -49175,7 +49353,7 @@ await mcp.connect(new StdioServerTransport());
49175
49353
  var REPLAY_SCAN_INTERVAL_MS = 6e4;
49176
49354
  async function replayPendingTelegramMarkers() {
49177
49355
  if (!channelReplayEnabled()) return;
49178
- if (!PENDING_INBOUND_DIR || !existsSync9(PENDING_INBOUND_DIR)) return;
49356
+ if (!PENDING_INBOUND_DIR || !existsSync10(PENDING_INBOUND_DIR)) return;
49179
49357
  const sessionState = resolveSessionLiveness({
49180
49358
  env: process.env,
49181
49359
  codeName: AGENT_CODE_NAME,
@@ -49203,7 +49381,7 @@ async function replayPendingTelegramMarkers() {
49203
49381
  const fullPath = join18(PENDING_INBOUND_DIR, name);
49204
49382
  let marker;
49205
49383
  try {
49206
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
49384
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
49207
49385
  } catch {
49208
49386
  continue;
49209
49387
  }
@@ -49356,6 +49534,7 @@ var acquiredLockPath = null;
49356
49534
  var stopLockHeartbeat = null;
49357
49535
  async function pollLoop() {
49358
49536
  while (!isShuttingDown) {
49537
+ await migrationReports.flushDue();
49359
49538
  try {
49360
49539
  const resp = await telegramApiCall(
49361
49540
  "getUpdates",
@@ -49411,7 +49590,9 @@ async function pollLoop() {
49411
49590
  const fromChatId = String(msg.chat.id);
49412
49591
  const toChatId = String(msg.migrate_to_chat_id);
49413
49592
  const admittedNow = applyMigrationToAllowlist(ALLOWED_CHATS, fromChatId, toChatId);
49414
- const reported = await reportGroupMigrationViaApi(fromChatId, toChatId);
49593
+ migrationReports.enqueue(fromChatId, toChatId);
49594
+ const outcomes = await migrationReports.flushDue();
49595
+ const reported = outcomes.get(`${fromChatId}->${toChatId}`) ?? "retry";
49415
49596
  process.stderr.write(
49416
49597
  `telegram-channel(${AGENT_CODE_NAME}): group migrated ${redactId(fromChatId)} -> ${redactId(toChatId)} admitted_now=${admittedNow} reported=${reported}
49417
49598
  `