@integrity-labs/agt-cli 0.28.83 → 0.28.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/agt.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  success,
38
38
  table,
39
39
  warn
40
- } from "../chunk-WFIKSR3G.js";
40
+ } from "../chunk-EIXW7L6A.js";
41
41
  import {
42
42
  CHANNEL_REGISTRY,
43
43
  DEPLOYMENT_TEMPLATES,
@@ -4777,7 +4777,7 @@ import { execFileSync, execSync } from "child_process";
4777
4777
  import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
4778
4778
  import chalk18 from "chalk";
4779
4779
  import ora16 from "ora";
4780
- var cliVersion = true ? "0.28.83" : "dev";
4780
+ var cliVersion = true ? "0.28.84" : "dev";
4781
4781
  async function fetchLatestVersion() {
4782
4782
  const host2 = getHost();
4783
4783
  if (!host2) return null;
@@ -5791,7 +5791,7 @@ function handleError(err) {
5791
5791
  }
5792
5792
 
5793
5793
  // src/bin/agt.ts
5794
- var cliVersion2 = true ? "0.28.83" : "dev";
5794
+ var cliVersion2 = true ? "0.28.84" : "dev";
5795
5795
  var program = new Command();
5796
5796
  program.name("agt").description("Augmented CLI \u2014 agent provisioning and management").version(cliVersion2).option("--json", "Emit machine-readable JSON output (suppress spinners and colors)").option("--skip-update-check", "Skip the automatic update check on startup");
5797
5797
  program.hook("preAction", async (thisCommand, actionCommand) => {
@@ -7531,7 +7531,7 @@ function requireHost() {
7531
7531
  }
7532
7532
 
7533
7533
  // src/lib/api-client.ts
7534
- var agtCliVersion = true ? "0.28.83" : "dev";
7534
+ var agtCliVersion = true ? "0.28.84" : "dev";
7535
7535
  var lastConfigHash = null;
7536
7536
  function setConfigHash(hash) {
7537
7537
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -8828,4 +8828,4 @@ export {
8828
8828
  managerInstallSystemUnitCommand,
8829
8829
  managerUninstallSystemUnitCommand
8830
8830
  };
8831
- //# sourceMappingURL=chunk-WFIKSR3G.js.map
8831
+ //# sourceMappingURL=chunk-EIXW7L6A.js.map
@@ -28,7 +28,7 @@ import {
28
28
  requireHost,
29
29
  safeWriteJsonAtomic,
30
30
  setConfigHash
31
- } from "../chunk-WFIKSR3G.js";
31
+ } from "../chunk-EIXW7L6A.js";
32
32
  import {
33
33
  getProjectDir as getProjectDir2,
34
34
  getReadyTasks,
@@ -6803,7 +6803,7 @@ var cachedMaintenanceWindow = null;
6803
6803
  var lastVersionCheckAt = 0;
6804
6804
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
6805
6805
  var lastResponsivenessProbeAt = 0;
6806
- var agtCliVersion = true ? "0.28.83" : "dev";
6806
+ var agtCliVersion = true ? "0.28.84" : "dev";
6807
6807
  function resolveBrewPath(execFileSync4) {
6808
6808
  try {
6809
6809
  const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -14465,21 +14465,21 @@ var StdioServerTransport = class {
14465
14465
 
14466
14466
  // src/telegram-channel.ts
14467
14467
  import https from "https";
14468
- import { createHash, randomUUID as randomUUID2 } from "crypto";
14468
+ import { createHash, randomUUID as randomUUID3 } from "crypto";
14469
14469
  import {
14470
14470
  closeSync,
14471
14471
  createWriteStream,
14472
- existsSync as existsSync5,
14472
+ existsSync as existsSync6,
14473
14473
  ftruncateSync,
14474
- mkdirSync as mkdirSync5,
14474
+ mkdirSync as mkdirSync6,
14475
14475
  openSync,
14476
- readFileSync as readFileSync8,
14476
+ readFileSync as readFileSync9,
14477
14477
  readdirSync as readdirSync3,
14478
- renameSync as renameSync4,
14478
+ renameSync as renameSync5,
14479
14479
  statSync as statSync2,
14480
- unlinkSync as unlinkSync5,
14480
+ unlinkSync as unlinkSync6,
14481
14481
  watch,
14482
- writeFileSync as writeFileSync6,
14482
+ writeFileSync as writeFileSync7,
14483
14483
  writeSync
14484
14484
  } from "fs";
14485
14485
  import { homedir as homedir3 } from "os";
@@ -15693,16 +15693,64 @@ function buildCommandRegistrations() {
15693
15693
  ];
15694
15694
  }
15695
15695
 
15696
+ // src/telegram-offset-store.ts
15697
+ import {
15698
+ existsSync as existsSync3,
15699
+ mkdirSync as mkdirSync4,
15700
+ readFileSync as readFileSync4,
15701
+ renameSync as renameSync3,
15702
+ unlinkSync as unlinkSync4,
15703
+ writeFileSync as writeFileSync4
15704
+ } from "fs";
15705
+ import { randomUUID as randomUUID2 } from "crypto";
15706
+ function loadPersistedOffset(filePath) {
15707
+ if (!filePath) return 0;
15708
+ try {
15709
+ const parsed = JSON.parse(
15710
+ readFileSync4(filePath, "utf-8")
15711
+ );
15712
+ const offset = parsed?.offset;
15713
+ if (typeof offset === "number" && Number.isFinite(offset) && offset > 0) {
15714
+ const normalized = Math.floor(offset);
15715
+ if (Number.isSafeInteger(normalized) && normalized > 0) {
15716
+ return normalized;
15717
+ }
15718
+ }
15719
+ } catch {
15720
+ }
15721
+ return 0;
15722
+ }
15723
+ function persistOffset(opts) {
15724
+ const { filePath, dir, offset, onError } = opts;
15725
+ if (!filePath || !dir) return;
15726
+ const marker = {
15727
+ offset,
15728
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
15729
+ };
15730
+ const tmpPath = `${filePath}.${process.pid}.${randomUUID2()}.tmp`;
15731
+ try {
15732
+ mkdirSync4(dir, { recursive: true, mode: 448 });
15733
+ writeFileSync4(tmpPath, JSON.stringify(marker), { mode: 384 });
15734
+ renameSync3(tmpPath, filePath);
15735
+ } catch (err) {
15736
+ onError?.(`getUpdates offset persist failed: ${err.message}`);
15737
+ try {
15738
+ if (existsSync3(tmpPath)) unlinkSync4(tmpPath);
15739
+ } catch {
15740
+ }
15741
+ }
15742
+ }
15743
+
15696
15744
  // src/agent-config-state.ts
15697
- import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
15745
+ import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
15698
15746
  import { join as join3 } from "path";
15699
15747
  var SESSION_STATE_FILENAME = "session-state.json";
15700
15748
  function readAgentSessionState(stateDir) {
15701
15749
  if (!stateDir) return null;
15702
15750
  const path = join3(stateDir, SESSION_STATE_FILENAME);
15703
- if (!existsSync3(path)) return null;
15751
+ if (!existsSync4(path)) return null;
15704
15752
  try {
15705
- const parsed = JSON.parse(readFileSync4(path, "utf-8"));
15753
+ const parsed = JSON.parse(readFileSync5(path, "utf-8"));
15706
15754
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
15707
15755
  return parsed;
15708
15756
  } catch {
@@ -16216,11 +16264,11 @@ var TELEGRAM_EGRESS_TOOLS = /* @__PURE__ */ new Set([
16216
16264
  ]);
16217
16265
 
16218
16266
  // src/telegram-pending-inbound-cleanup.ts
16219
- import { readdirSync, readFileSync as readFileSync5, statSync } from "fs";
16267
+ import { readdirSync, readFileSync as readFileSync6, statSync } from "fs";
16220
16268
  import { join as join4 } from "path";
16221
16269
  function markerArrivalMs(fullPath) {
16222
16270
  try {
16223
- const received = JSON.parse(readFileSync5(fullPath, "utf-8")).received_at;
16271
+ const received = JSON.parse(readFileSync6(fullPath, "utf-8")).received_at;
16224
16272
  const parsed = received ? Date.parse(received) : Number.NaN;
16225
16273
  if (Number.isFinite(parsed)) return parsed;
16226
16274
  } catch {
@@ -16313,12 +16361,12 @@ function parseProgressHeartbeat(raw) {
16313
16361
 
16314
16362
  // src/mcp-spawn-lock.ts
16315
16363
  import {
16316
- existsSync as existsSync4,
16317
- mkdirSync as mkdirSync4,
16318
- readFileSync as readFileSync6,
16319
- renameSync as renameSync3,
16320
- unlinkSync as unlinkSync4,
16321
- writeFileSync as writeFileSync4
16364
+ existsSync as existsSync5,
16365
+ mkdirSync as mkdirSync5,
16366
+ readFileSync as readFileSync7,
16367
+ renameSync as renameSync4,
16368
+ unlinkSync as unlinkSync5,
16369
+ writeFileSync as writeFileSync5
16322
16370
  } from "fs";
16323
16371
  import { join as join5 } from "path";
16324
16372
  function defaultIsPidAlive(pid) {
@@ -16348,11 +16396,11 @@ function acquireMcpSpawnLock(args) {
16348
16396
  return { kind: "blocked", path, holder: existing };
16349
16397
  }
16350
16398
  }
16351
- mkdirSync4(agentDir, { recursive: true, mode: 448 });
16399
+ mkdirSync5(agentDir, { recursive: true, mode: 448 });
16352
16400
  const tmpPath = `${path}.${selfPid}.tmp`;
16353
16401
  const payload = { pid: selfPid, started_at: now() };
16354
- writeFileSync4(tmpPath, JSON.stringify(payload), { mode: 384 });
16355
- renameSync3(tmpPath, path);
16402
+ writeFileSync5(tmpPath, JSON.stringify(payload), { mode: 384 });
16403
+ renameSync4(tmpPath, path);
16356
16404
  return { kind: "acquired", path };
16357
16405
  }
16358
16406
  function releaseMcpSpawnLock(lockPath, opts = {}) {
@@ -16362,14 +16410,14 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
16362
16410
  if (!existing) return;
16363
16411
  if (existing.pid !== selfPid) return;
16364
16412
  try {
16365
- unlinkSync4(lockPath);
16413
+ unlinkSync5(lockPath);
16366
16414
  } catch {
16367
16415
  }
16368
16416
  }
16369
16417
  function readLockHolder(path) {
16370
- if (!existsSync4(path)) return null;
16418
+ if (!existsSync5(path)) return null;
16371
16419
  try {
16372
- const raw = readFileSync6(path, "utf8");
16420
+ const raw = readFileSync7(path, "utf8");
16373
16421
  const parsed = JSON.parse(raw);
16374
16422
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
16375
16423
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -16381,7 +16429,7 @@ function readLockHolder(path) {
16381
16429
  }
16382
16430
 
16383
16431
  // src/ack-reaction.ts
16384
- import { readdirSync as readdirSync2, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "fs";
16432
+ import { readdirSync as readdirSync2, readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "fs";
16385
16433
  import { join as join6 } from "path";
16386
16434
  var REPLY_WEDGED_THRESHOLD_MS = 5 * 60 * 1e3;
16387
16435
  var ACK_STARTUP_GRACE_MS = 6e4;
@@ -16455,7 +16503,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
16455
16503
  function readGiveUpSignalAtMs(path, now = Date.now()) {
16456
16504
  if (!path) return null;
16457
16505
  try {
16458
- const raw = JSON.parse(readFileSync7(path, "utf8"));
16506
+ const raw = JSON.parse(readFileSync8(path, "utf8"));
16459
16507
  if (typeof raw.gave_up_at !== "string") return null;
16460
16508
  const t = Date.parse(raw.gave_up_at);
16461
16509
  if (!Number.isFinite(t) || t > now) return null;
@@ -16487,7 +16535,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now()) {
16487
16535
  if (!name.endsWith(".json")) continue;
16488
16536
  let receivedAt;
16489
16537
  try {
16490
- const raw = JSON.parse(readFileSync7(join6(dir, name), "utf-8"));
16538
+ const raw = JSON.parse(readFileSync8(join6(dir, name), "utf-8"));
16491
16539
  if (raw.discretionary === true) continue;
16492
16540
  if (typeof raw.seen_at === "string" && raw.seen_at) continue;
16493
16541
  receivedAt = raw.received_at;
@@ -16549,13 +16597,13 @@ function recordChannelDeflection(agentDir, channel, cause) {
16549
16597
  const path = deflectionCounterPath(agentDir, channel);
16550
16598
  let counts = {};
16551
16599
  try {
16552
- const parsed = JSON.parse(readFileSync7(path, "utf-8"));
16600
+ const parsed = JSON.parse(readFileSync8(path, "utf-8"));
16553
16601
  if (parsed && typeof parsed === "object") counts = parsed;
16554
16602
  } catch {
16555
16603
  }
16556
16604
  counts[cause] = (counts[cause] ?? 0) + 1;
16557
16605
  try {
16558
- writeFileSync5(path, JSON.stringify(counts), { mode: 384 });
16606
+ writeFileSync6(path, JSON.stringify(counts), { mode: 384 });
16559
16607
  } catch {
16560
16608
  }
16561
16609
  }
@@ -16692,7 +16740,7 @@ var stderrLogStream = null;
16692
16740
  if (AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown") {
16693
16741
  try {
16694
16742
  const logDir = join7(homedir3(), ".augmented", AGENT_CODE_NAME);
16695
- mkdirSync5(logDir, { recursive: true });
16743
+ mkdirSync6(logDir, { recursive: true });
16696
16744
  stderrLogStream = createWriteStream(join7(logDir, "telegram-channel-stderr.log"), {
16697
16745
  flags: "a",
16698
16746
  mode: 384
@@ -17211,8 +17259,8 @@ async function handleOnboardingCommand(opts) {
17211
17259
  }
17212
17260
  async function handleRestartCommand(opts) {
17213
17261
  try {
17214
- if (!existsSync5(RESTART_FLAGS_DIR)) {
17215
- mkdirSync5(RESTART_FLAGS_DIR, { recursive: true });
17262
+ if (!existsSync6(RESTART_FLAGS_DIR)) {
17263
+ mkdirSync6(RESTART_FLAGS_DIR, { recursive: true });
17216
17264
  }
17217
17265
  const flagPath = join7(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
17218
17266
  writeTelegramRestartConfirm(
@@ -17225,9 +17273,9 @@ async function handleRestartCommand(opts) {
17225
17273
  ts: Date.now(),
17226
17274
  reply: { chat_id: opts.chatId, message_id: opts.messageId }
17227
17275
  };
17228
- const tmpPath = `${flagPath}.${process.pid}.${randomUUID2()}.tmp`;
17229
- writeFileSync6(tmpPath, JSON.stringify(flag) + "\n", "utf8");
17230
- renameSync4(tmpPath, flagPath);
17276
+ const tmpPath = `${flagPath}.${process.pid}.${randomUUID3()}.tmp`;
17277
+ writeFileSync7(tmpPath, JSON.stringify(flag) + "\n", "utf8");
17278
+ renameSync5(tmpPath, flagPath);
17231
17279
  process.stderr.write(
17232
17280
  `telegram-channel(${AGENT_CODE_NAME}): /restart queued from chat ${redactId(opts.chatId)}
17233
17281
  `
@@ -17612,6 +17660,7 @@ var RESTART_CONFIRM_FILE = AGENT_DIR ? join7(AGENT_DIR, "telegram-restart-confir
17612
17660
  var TELEGRAM_PROCESS_BOOT_MS = Date.now();
17613
17661
  var TELEGRAM_RECENT_DMS_FILE = AGENT_DIR ? join7(AGENT_DIR, "telegram-recent-dms.json") : null;
17614
17662
  var TELEGRAM_CHANNEL_ADD_RESTART_FILE = AGENT_DIR ? join7(AGENT_DIR, "telegram-channel-add-restart.json") : null;
17663
+ var TELEGRAM_OFFSET_FILE = AGENT_DIR ? join7(AGENT_DIR, "telegram-getupdates-offset.json") : null;
17615
17664
  var recentDms = /* @__PURE__ */ new Map();
17616
17665
  var recentDmPersister = TELEGRAM_RECENT_DMS_FILE ? createRecentDmPersister({
17617
17666
  filePath: TELEGRAM_RECENT_DMS_FILE,
@@ -17683,8 +17732,8 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
17683
17732
  ...payload ? { payload } : {}
17684
17733
  };
17685
17734
  try {
17686
- mkdirSync5(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
17687
- writeFileSync6(path, JSON.stringify(marker), { mode: 384 });
17735
+ mkdirSync6(PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
17736
+ writeFileSync7(path, JSON.stringify(marker), { mode: 384 });
17688
17737
  } catch (err) {
17689
17738
  process.stderr.write(
17690
17739
  `telegram-channel(${AGENT_CODE_NAME}): pending-inbound marker write failed: ${err.message}
@@ -17712,7 +17761,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
17712
17761
  function clearTelegramMarkerFileWithHeal(fullPath) {
17713
17762
  let marker = null;
17714
17763
  try {
17715
- marker = JSON.parse(readFileSync8(fullPath, "utf-8"));
17764
+ marker = JSON.parse(readFileSync9(fullPath, "utf-8"));
17716
17765
  } catch {
17717
17766
  }
17718
17767
  if (marker && decideRecoveryHeal({
@@ -17722,14 +17771,14 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
17722
17771
  notifyBackOnline(marker.chat_id);
17723
17772
  }
17724
17773
  try {
17725
- if (existsSync5(fullPath)) unlinkSync5(fullPath);
17774
+ if (existsSync6(fullPath)) unlinkSync6(fullPath);
17726
17775
  } catch {
17727
17776
  }
17728
17777
  }
17729
17778
  function markTelegramMarkerSeenInPlace(fullPath) {
17730
17779
  let marker;
17731
17780
  try {
17732
- marker = JSON.parse(readFileSync8(fullPath, "utf-8"));
17781
+ marker = JSON.parse(readFileSync9(fullPath, "utf-8"));
17733
17782
  } catch {
17734
17783
  return;
17735
17784
  }
@@ -17741,7 +17790,7 @@ function markTelegramMarkerSeenInPlace(fullPath) {
17741
17790
  function markTelegramMarkerSeenWithHeal(fullPath) {
17742
17791
  let marker = null;
17743
17792
  try {
17744
- marker = JSON.parse(readFileSync8(fullPath, "utf-8"));
17793
+ marker = JSON.parse(readFileSync9(fullPath, "utf-8"));
17745
17794
  } catch {
17746
17795
  return;
17747
17796
  }
@@ -17755,9 +17804,9 @@ function markTelegramMarkerSeenWithHeal(fullPath) {
17755
17804
  }
17756
17805
  function readPendingInboundMarker(chatId, messageId) {
17757
17806
  const path = pendingInboundPath(chatId, messageId);
17758
- if (!path || !existsSync5(path)) return null;
17807
+ if (!path || !existsSync6(path)) return null;
17759
17808
  try {
17760
- return JSON.parse(readFileSync8(path, "utf-8"));
17809
+ return JSON.parse(readFileSync9(path, "utf-8"));
17761
17810
  } catch {
17762
17811
  return null;
17763
17812
  }
@@ -17780,7 +17829,7 @@ async function processRecoveryOutboxFile(filename) {
17780
17829
  const fullPath = join7(RECOVERY_OUTBOX_DIR, filename);
17781
17830
  let payload;
17782
17831
  try {
17783
- const raw = readFileSync8(fullPath, "utf-8");
17832
+ const raw = readFileSync9(fullPath, "utf-8");
17784
17833
  payload = JSON.parse(raw);
17785
17834
  } catch (err) {
17786
17835
  process.stderr.write(
@@ -17788,7 +17837,7 @@ async function processRecoveryOutboxFile(filename) {
17788
17837
  `
17789
17838
  );
17790
17839
  try {
17791
- renameSync4(fullPath, `${fullPath}.parse-error.poison`);
17840
+ renameSync5(fullPath, `${fullPath}.parse-error.poison`);
17792
17841
  } catch {
17793
17842
  }
17794
17843
  return;
@@ -17799,7 +17848,7 @@ async function processRecoveryOutboxFile(filename) {
17799
17848
  `
17800
17849
  );
17801
17850
  try {
17802
- renameSync4(fullPath, `${fullPath}.malformed.poison`);
17851
+ renameSync5(fullPath, `${fullPath}.malformed.poison`);
17803
17852
  } catch {
17804
17853
  }
17805
17854
  return;
@@ -17838,7 +17887,7 @@ ${payload.text}`;
17838
17887
  }
17839
17888
  if (sendSucceeded) {
17840
17889
  try {
17841
- unlinkSync5(fullPath);
17890
+ unlinkSync6(fullPath);
17842
17891
  } catch {
17843
17892
  }
17844
17893
  return;
@@ -17846,7 +17895,7 @@ ${payload.text}`;
17846
17895
  const next = nextRetryName(filename);
17847
17896
  if (next) {
17848
17897
  try {
17849
- renameSync4(fullPath, join7(RECOVERY_OUTBOX_DIR, next.next));
17898
+ renameSync5(fullPath, join7(RECOVERY_OUTBOX_DIR, next.next));
17850
17899
  if (next.attempt >= MAX_RECOVERY_ATTEMPTS) {
17851
17900
  process.stderr.write(
17852
17901
  `telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
@@ -17898,7 +17947,7 @@ function scanRecoveryRetries() {
17898
17947
  function startRecoveryOutboxWatcher() {
17899
17948
  if (!RECOVERY_OUTBOX_DIR) return;
17900
17949
  try {
17901
- mkdirSync5(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
17950
+ mkdirSync6(RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
17902
17951
  } catch (err) {
17903
17952
  process.stderr.write(
17904
17953
  `telegram-channel(${AGENT_CODE_NAME}): recovery outbox mkdir failed: ${err.message}
@@ -17916,7 +17965,7 @@ function startRecoveryOutboxWatcher() {
17916
17965
  const watcher = watch(RECOVERY_OUTBOX_DIR, (event, filename) => {
17917
17966
  if (event !== "rename" || !filename) return;
17918
17967
  if (!isFirstAttemptOutboxFile(filename)) return;
17919
- if (existsSync5(join7(RECOVERY_OUTBOX_DIR, filename))) {
17968
+ if (existsSync6(join7(RECOVERY_OUTBOX_DIR, filename))) {
17920
17969
  void processRecoveryOutboxFile(filename);
17921
17970
  }
17922
17971
  });
@@ -17937,7 +17986,7 @@ function trackPendingMessage(chatId, messageId, chatType, undeliverable = false,
17937
17986
  }
17938
17987
  function sweepTelegramStaleMarkers(thresholdMs) {
17939
17988
  if (!PENDING_INBOUND_DIR) return;
17940
- if (!existsSync5(PENDING_INBOUND_DIR)) return;
17989
+ if (!existsSync6(PENDING_INBOUND_DIR)) return;
17941
17990
  let filenames;
17942
17991
  try {
17943
17992
  filenames = readdirSync3(PENDING_INBOUND_DIR);
@@ -17956,14 +18005,14 @@ function sweepTelegramStaleMarkers(thresholdMs) {
17956
18005
  const fullPath = join7(PENDING_INBOUND_DIR, filename);
17957
18006
  let marker;
17958
18007
  try {
17959
- marker = JSON.parse(readFileSync8(fullPath, "utf-8"));
18008
+ marker = JSON.parse(readFileSync9(fullPath, "utf-8"));
17960
18009
  } catch (err) {
17961
18010
  process.stderr.write(
17962
18011
  `telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
17963
18012
  `
17964
18013
  );
17965
18014
  try {
17966
- unlinkSync5(fullPath);
18015
+ unlinkSync6(fullPath);
17967
18016
  } catch {
17968
18017
  }
17969
18018
  cleared++;
@@ -17977,7 +18026,7 @@ function sweepTelegramStaleMarkers(thresholdMs) {
17977
18026
  recordChannelDeflection(AGENT_DIR, "telegram", "replay_orphaned");
17978
18027
  }
17979
18028
  try {
17980
- unlinkSync5(fullPath);
18029
+ unlinkSync6(fullPath);
17981
18030
  } catch {
17982
18031
  }
17983
18032
  cleared++;
@@ -18002,15 +18051,15 @@ var TELEGRAM_PROGRESS_HEARTBEAT_PATH = AGENT_DIR ? join7(AGENT_DIR, "channel-pro
18002
18051
  var telegramTrackedProgress = null;
18003
18052
  var telegramProgressTickRunning = false;
18004
18053
  function readTelegramProgressHeartbeat() {
18005
- if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync5(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
18054
+ if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync6(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
18006
18055
  try {
18007
- return parseProgressHeartbeat(readFileSync8(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
18056
+ return parseProgressHeartbeat(readFileSync9(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
18008
18057
  } catch {
18009
18058
  return null;
18010
18059
  }
18011
18060
  }
18012
18061
  function findTelegramProgressTarget() {
18013
- if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return null;
18062
+ if (!PENDING_INBOUND_DIR || !existsSync6(PENDING_INBOUND_DIR)) return null;
18014
18063
  let best = null;
18015
18064
  let bestMs = Infinity;
18016
18065
  try {
@@ -18018,7 +18067,7 @@ function findTelegramProgressTarget() {
18018
18067
  if (!name.endsWith(".json")) continue;
18019
18068
  let m;
18020
18069
  try {
18021
- m = JSON.parse(readFileSync8(join7(PENDING_INBOUND_DIR, name), "utf-8"));
18070
+ m = JSON.parse(readFileSync9(join7(PENDING_INBOUND_DIR, name), "utf-8"));
18022
18071
  } catch {
18023
18072
  continue;
18024
18073
  }
@@ -18137,14 +18186,14 @@ if (BOT_TOKEN && PENDING_INBOUND_DIR) {
18137
18186
  }
18138
18187
  var lastGiveUpHandledAtMs = null;
18139
18188
  function listPendingInboundChatIds() {
18140
- if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return [];
18189
+ if (!PENDING_INBOUND_DIR || !existsSync6(PENDING_INBOUND_DIR)) return [];
18141
18190
  const chats = /* @__PURE__ */ new Set();
18142
18191
  try {
18143
18192
  for (const name of readdirSync3(PENDING_INBOUND_DIR)) {
18144
18193
  if (!name.endsWith(".json")) continue;
18145
18194
  try {
18146
18195
  const marker = JSON.parse(
18147
- readFileSync8(join7(PENDING_INBOUND_DIR, name), "utf8")
18196
+ readFileSync9(join7(PENDING_INBOUND_DIR, name), "utf8")
18148
18197
  );
18149
18198
  if (typeof marker.seen_at === "string" && marker.seen_at) continue;
18150
18199
  if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
@@ -18261,7 +18310,7 @@ async function deliverQueuedReply(p) {
18261
18310
  }
18262
18311
  }
18263
18312
  function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
18264
- if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return;
18313
+ if (!PENDING_INBOUND_DIR || !existsSync6(PENDING_INBOUND_DIR)) return;
18265
18314
  clearAllTelegramPendingMarkersForChat(
18266
18315
  PENDING_INBOUND_DIR,
18267
18316
  chatId,
@@ -18270,7 +18319,7 @@ function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
18270
18319
  );
18271
18320
  }
18272
18321
  function markSeenPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
18273
- if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return;
18322
+ if (!PENDING_INBOUND_DIR || !existsSync6(PENDING_INBOUND_DIR)) return;
18274
18323
  markSeenAllTelegramPendingMarkersForChat(
18275
18324
  PENDING_INBOUND_DIR,
18276
18325
  chatId,
@@ -18883,7 +18932,7 @@ await mcp.connect(new StdioServerTransport());
18883
18932
  var REPLAY_SCAN_INTERVAL_MS = 6e4;
18884
18933
  async function replayPendingTelegramMarkers() {
18885
18934
  if (!channelReplayEnabled()) return;
18886
- if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return;
18935
+ if (!PENDING_INBOUND_DIR || !existsSync6(PENDING_INBOUND_DIR)) return;
18887
18936
  const probe = process.env.TMUX && AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? probeAgentSessionCached(AGENT_CODE_NAME) : { tmux: "unknown", claude: "unknown" };
18888
18937
  const sessionAlive = probe.tmux === "alive" && probe.claude === "alive";
18889
18938
  if (!sessionAlive) return;
@@ -18907,7 +18956,7 @@ async function replayPendingTelegramMarkers() {
18907
18956
  const fullPath = join7(PENDING_INBOUND_DIR, name);
18908
18957
  let marker;
18909
18958
  try {
18910
- marker = JSON.parse(readFileSync8(fullPath, "utf-8"));
18959
+ marker = JSON.parse(readFileSync9(fullPath, "utf-8"));
18911
18960
  } catch {
18912
18961
  continue;
18913
18962
  }
@@ -19041,7 +19090,7 @@ var telegramHttp = {
19041
19090
  });
19042
19091
  }
19043
19092
  };
19044
- var nextOffset = 0;
19093
+ var nextOffset = loadPersistedOffset(TELEGRAM_OFFSET_FILE);
19045
19094
  var isShuttingDown = false;
19046
19095
  var acquiredLockPath = null;
19047
19096
  async function pollLoop() {
@@ -19069,6 +19118,7 @@ async function pollLoop() {
19069
19118
  await sleep2(5e3);
19070
19119
  continue;
19071
19120
  }
19121
+ const offsetBeforeBatch = nextOffset;
19072
19122
  for (const update of resp.result ?? []) {
19073
19123
  nextOffset = Math.max(nextOffset, update.update_id + 1);
19074
19124
  if (update.callback_query) {
@@ -19476,6 +19526,17 @@ async function pollLoop() {
19476
19526
  });
19477
19527
  }
19478
19528
  }
19529
+ if (nextOffset > offsetBeforeBatch) {
19530
+ persistOffset({
19531
+ filePath: TELEGRAM_OFFSET_FILE,
19532
+ dir: AGENT_DIR,
19533
+ offset: nextOffset,
19534
+ onError: (m) => process.stderr.write(
19535
+ `telegram-channel(${AGENT_CODE_NAME}): ${redactAugmentedPaths(m)}
19536
+ `
19537
+ )
19538
+ });
19539
+ }
19479
19540
  } catch (err) {
19480
19541
  if (isShuttingDown) return;
19481
19542
  process.stderr.write(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integrity-labs/agt-cli",
3
- "version": "0.28.83",
3
+ "version": "0.28.84",
4
4
  "description": "Augmented Team CLI — agent provisioning and management",
5
5
  "type": "module",
6
6
  "engines": {