@integrity-labs/agt-cli 0.28.482 → 0.28.484

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/agt.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  success,
41
41
  table,
42
42
  warn
43
- } from "../chunk-B6AXXPYQ.js";
43
+ } from "../chunk-I63LLKQJ.js";
44
44
  import {
45
45
  AnchorSessionClient,
46
46
  CHANNEL_REGISTRY,
@@ -4830,7 +4830,7 @@ import { execFileSync, execSync } from "child_process";
4830
4830
  import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
4831
4831
  import chalk18 from "chalk";
4832
4832
  import ora16 from "ora";
4833
- var cliVersion = true ? "0.28.482" : "dev";
4833
+ var cliVersion = true ? "0.28.484" : "dev";
4834
4834
  async function fetchLatestVersion() {
4835
4835
  const host2 = getHost();
4836
4836
  if (!host2) return null;
@@ -6002,7 +6002,7 @@ function handleError(err) {
6002
6002
  }
6003
6003
 
6004
6004
  // src/bin/agt.ts
6005
- var cliVersion2 = true ? "0.28.482" : "dev";
6005
+ var cliVersion2 = true ? "0.28.484" : "dev";
6006
6006
  var program = new Command();
6007
6007
  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");
6008
6008
  program.hook("preAction", async (thisCommand, actionCommand) => {
@@ -4938,7 +4938,7 @@ function exchangeFailureKind(err) {
4938
4938
  }
4939
4939
 
4940
4940
  // src/lib/api-client.ts
4941
- var agtCliVersion = true ? "0.28.482" : "dev";
4941
+ var agtCliVersion = true ? "0.28.484" : "dev";
4942
4942
  var lastConfigHash = null;
4943
4943
  function setConfigHash(hash) {
4944
4944
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -7667,4 +7667,4 @@ export {
7667
7667
  managerInstallSystemUnitCommand,
7668
7668
  managerUninstallSystemUnitCommand
7669
7669
  };
7670
- //# sourceMappingURL=chunk-B6AXXPYQ.js.map
7670
+ //# sourceMappingURL=chunk-I63LLKQJ.js.map
@@ -44,7 +44,7 @@ import {
44
44
  resolveEffectivePinRaw,
45
45
  safeWriteJsonAtomic,
46
46
  setConfigHash
47
- } from "../chunk-B6AXXPYQ.js";
47
+ } from "../chunk-I63LLKQJ.js";
48
48
  import {
49
49
  getProjectDir as getProjectDir2,
50
50
  getReadyTasks,
@@ -10064,7 +10064,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
10064
10064
  var lastVersionCheckAt = 0;
10065
10065
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
10066
10066
  var lastResponsivenessProbeAt = 0;
10067
- var agtCliVersion = true ? "0.28.482" : "dev";
10067
+ var agtCliVersion = true ? "0.28.484" : "dev";
10068
10068
  function resolveBrewPath(execFileSync2) {
10069
10069
  try {
10070
10070
  const out = execFileSync2("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -30218,7 +30218,7 @@ function recordChannelDeflection(agentDir, channel, cause) {
30218
30218
  }
30219
30219
 
30220
30220
  // src/turn-failure-watch.ts
30221
- import { readFileSync as readFileSync9, readdirSync as readdirSync5, statSync as statSync2 } from "fs";
30221
+ import { readdirSync as readdirSync5, statSync as statSync2 } from "fs";
30222
30222
  import { join as join9 } from "path";
30223
30223
 
30224
30224
  // ../core/dist/types/integration.js
@@ -35352,11 +35352,77 @@ function deriveBindFailureQuarantineThreshold(provisioningMax) {
35352
35352
  var MIN_PROVISIONING_MAX_FOR_QUARANTINE_ORDERING = BIND_FAILURE_QUARANTINE_THRESHOLD + 1;
35353
35353
 
35354
35354
  // src/rate-limit-watch.ts
35355
- import { readFileSync as readFileSync8, readdirSync as readdirSync4, statSync } from "fs";
35355
+ import { closeSync, fstatSync, openSync, readSync, readdirSync as readdirSync4, statSync } from "fs";
35356
35356
  import { homedir as homedir2 } from "os";
35357
35357
  import { join as join8 } from "path";
35358
35358
  var DEFAULT_WATCH_MS = 5e3;
35359
35359
  var DEFAULT_POLL_MS = 400;
35360
+ var INITIAL_TAIL_BYTES = 256 * 1024;
35361
+ var TAIL_WIDEN_FACTOR = 8;
35362
+ var TAIL_SKEW_TOLERANCE_MS = 5 * 6e4;
35363
+ function readClassifiableTail(path, sinceMs, opts) {
35364
+ let want = Math.max(1, opts?.initialBytes ?? INITIAL_TAIL_BYTES);
35365
+ for (; ; ) {
35366
+ const slice = readTailSlice(path, want);
35367
+ if (slice === null) return "";
35368
+ if (slice.fromStart) return slice.text;
35369
+ const oldest = oldestTimestampMs(slice.text);
35370
+ if (oldest !== null && oldest < sinceMs - TAIL_SKEW_TOLERANCE_MS) return slice.text;
35371
+ want *= TAIL_WIDEN_FACTOR;
35372
+ }
35373
+ }
35374
+ function readTailSlice(path, bytes) {
35375
+ let fd;
35376
+ try {
35377
+ fd = openSync(path, "r");
35378
+ } catch {
35379
+ return null;
35380
+ }
35381
+ try {
35382
+ const size = fstatSync(fd).size;
35383
+ const start = size > bytes ? size - bytes : 0;
35384
+ const len = size - start;
35385
+ if (len <= 0) return { text: "", fromStart: true };
35386
+ const buf = Buffer.allocUnsafe(len);
35387
+ let read = 0;
35388
+ while (read < len) {
35389
+ const n = readSync(fd, buf, read, len - read, start + read);
35390
+ if (n <= 0) break;
35391
+ read += n;
35392
+ }
35393
+ if (read < len) return null;
35394
+ let text = buf.subarray(0, read).toString("utf-8");
35395
+ if (start > 0) {
35396
+ const nl = text.indexOf("\n");
35397
+ text = nl === -1 ? "" : text.slice(nl + 1);
35398
+ }
35399
+ return { text, fromStart: start === 0 };
35400
+ } catch {
35401
+ return null;
35402
+ } finally {
35403
+ closeSync(fd);
35404
+ }
35405
+ }
35406
+ function oldestTimestampMs(text) {
35407
+ let idx = 0;
35408
+ while (idx < text.length) {
35409
+ const nl = text.indexOf("\n", idx);
35410
+ const line = (nl === -1 ? text.slice(idx) : text.slice(idx, nl)).trim();
35411
+ if (line) {
35412
+ try {
35413
+ const ts = JSON.parse(line).timestamp;
35414
+ if (typeof ts === "string") {
35415
+ const ms = new Date(ts).getTime();
35416
+ if (Number.isFinite(ms)) return ms;
35417
+ }
35418
+ } catch {
35419
+ }
35420
+ }
35421
+ if (nl === -1) break;
35422
+ idx = nl + 1;
35423
+ }
35424
+ return null;
35425
+ }
35360
35426
  function agentTranscriptDir(opts) {
35361
35427
  const cwd = opts?.cwd ?? process.cwd();
35362
35428
  const home = opts?.home ?? homedir2();
@@ -35380,12 +35446,10 @@ function classifyTranscriptSince(opts) {
35380
35446
  } catch {
35381
35447
  continue;
35382
35448
  }
35383
- let content;
35384
- try {
35385
- content = readFileSync8(path, "utf-8");
35386
- } catch {
35387
- continue;
35388
- }
35449
+ const content = readClassifiableTail(path, opts.sinceMs, {
35450
+ ...opts.initialTailBytes != null ? { initialBytes: opts.initialTailBytes } : {}
35451
+ });
35452
+ if (!content) continue;
35389
35453
  newest = pickNewerClassification(
35390
35454
  newest,
35391
35455
  classifyTranscriptRateLimit(content, opts.sinceMs, opts.nowMs, new Date(opts.nowMs))
@@ -35463,12 +35527,8 @@ function classifyTurnFailureSince(opts) {
35463
35527
  if (cached2 && cached2.fingerprint === fingerprint) {
35464
35528
  scan = cached2.scan;
35465
35529
  } else {
35466
- let content;
35467
- try {
35468
- content = readFileSync9(path, "utf-8");
35469
- } catch {
35470
- continue;
35471
- }
35530
+ const content = readClassifiableTail(path, opts.sinceMs);
35531
+ if (!content) continue;
35472
35532
  const analysis = analyzeTranscriptTurnFailure(content, opts.sinceMs, opts.nowMs);
35473
35533
  scan = {
35474
35534
  result: analysis.result,
@@ -35637,7 +35697,7 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
35637
35697
  import {
35638
35698
  existsSync as existsSync5,
35639
35699
  mkdirSync as mkdirSync4,
35640
- readFileSync as readFileSync10,
35700
+ readFileSync as readFileSync8,
35641
35701
  renameSync as renameSync4,
35642
35702
  statSync as statSync3,
35643
35703
  unlinkSync as unlinkSync3,
@@ -35734,7 +35794,7 @@ function defaultLockMtimeMs(path) {
35734
35794
  function readLockHolder(path) {
35735
35795
  if (!existsSync5(path)) return null;
35736
35796
  try {
35737
- const raw = readFileSync10(path, "utf8");
35797
+ const raw = readFileSync8(path, "utf8");
35738
35798
  const parsed = JSON.parse(raw);
35739
35799
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
35740
35800
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -35753,7 +35813,7 @@ import {
35753
35813
  watch,
35754
35814
  mkdirSync as mkdirSync5,
35755
35815
  writeFileSync as writeFileSync6,
35756
- readFileSync as readFileSync12,
35816
+ readFileSync as readFileSync10,
35757
35817
  readdirSync as readdirSync6,
35758
35818
  existsSync as existsSync6,
35759
35819
  renameSync as renameSync5,
@@ -36186,7 +36246,7 @@ function isMaintenanceModeActive(opts) {
36186
36246
  }
36187
36247
 
36188
36248
  // src/account-enforcement-notice.ts
36189
- import { readFileSync as readFileSync11 } from "fs";
36249
+ import { readFileSync as readFileSync9 } from "fs";
36190
36250
  import { homedir as homedir3 } from "os";
36191
36251
  import { join as join12 } from "path";
36192
36252
 
@@ -36213,7 +36273,7 @@ function readAccountEnforcementLevel(opts) {
36213
36273
  if (!path) return null;
36214
36274
  let raw;
36215
36275
  try {
36216
- raw = readFileSync11(path, "utf-8");
36276
+ raw = readFileSync9(path, "utf-8");
36217
36277
  } catch {
36218
36278
  return null;
36219
36279
  }
@@ -36352,7 +36412,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
36352
36412
  function readProgressHeartbeat() {
36353
36413
  if (!PROGRESS_HEARTBEAT_PATH || !existsSync6(PROGRESS_HEARTBEAT_PATH)) return null;
36354
36414
  try {
36355
- return parseProgressHeartbeat(readFileSync12(PROGRESS_HEARTBEAT_PATH, "utf-8"));
36415
+ return parseProgressHeartbeat(readFileSync10(PROGRESS_HEARTBEAT_PATH, "utf-8"));
36356
36416
  } catch {
36357
36417
  return null;
36358
36418
  }
@@ -37319,7 +37379,7 @@ function sweepAgedDirectChatMarkersNow(thresholdMs) {
37319
37379
  const now = Date.now();
37320
37380
  const res = sweepAgedDirectChatMarkers(DIRECT_CHAT_PENDING_INBOUND_DIR, {
37321
37381
  readdir: (dir) => readdirSync6(dir),
37322
- readFile: (p2) => readFileSync12(p2, "utf8"),
37382
+ readFile: (p2) => readFileSync10(p2, "utf8"),
37323
37383
  unlink: (p2) => {
37324
37384
  if (existsSync6(p2)) unlinkSync4(p2);
37325
37385
  },
@@ -37355,7 +37415,7 @@ function sanitizeRecoveryText(text) {
37355
37415
  }
37356
37416
  function directChatRecoveryDeps() {
37357
37417
  return {
37358
- readFile: (p2) => readFileSync12(p2, "utf-8"),
37418
+ readFile: (p2) => readFileSync10(p2, "utf-8"),
37359
37419
  renameFile: (from, to) => renameSync5(from, to),
37360
37420
  unlinkFile: (p2) => {
37361
37421
  if (existsSync6(p2)) unlinkSync4(p2);
@@ -36745,11 +36745,77 @@ function emitToolCallMarkupRedactionTelemetry(channel) {
36745
36745
  }
36746
36746
 
36747
36747
  // src/rate-limit-watch.ts
36748
- import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync } from "fs";
36748
+ import { closeSync, fstatSync, openSync, readSync, readdirSync as readdirSync2, statSync } from "fs";
36749
36749
  import { homedir as homedir4 } from "os";
36750
36750
  import { join as join6 } from "path";
36751
36751
  var DEFAULT_WATCH_MS = 5e3;
36752
36752
  var DEFAULT_POLL_MS = 400;
36753
+ var INITIAL_TAIL_BYTES = 256 * 1024;
36754
+ var TAIL_WIDEN_FACTOR = 8;
36755
+ var TAIL_SKEW_TOLERANCE_MS = 5 * 6e4;
36756
+ function readClassifiableTail(path, sinceMs, opts) {
36757
+ let want = Math.max(1, opts?.initialBytes ?? INITIAL_TAIL_BYTES);
36758
+ for (; ; ) {
36759
+ const slice = readTailSlice(path, want);
36760
+ if (slice === null) return "";
36761
+ if (slice.fromStart) return slice.text;
36762
+ const oldest = oldestTimestampMs(slice.text);
36763
+ if (oldest !== null && oldest < sinceMs - TAIL_SKEW_TOLERANCE_MS) return slice.text;
36764
+ want *= TAIL_WIDEN_FACTOR;
36765
+ }
36766
+ }
36767
+ function readTailSlice(path, bytes) {
36768
+ let fd;
36769
+ try {
36770
+ fd = openSync(path, "r");
36771
+ } catch {
36772
+ return null;
36773
+ }
36774
+ try {
36775
+ const size = fstatSync(fd).size;
36776
+ const start = size > bytes ? size - bytes : 0;
36777
+ const len = size - start;
36778
+ if (len <= 0) return { text: "", fromStart: true };
36779
+ const buf = Buffer.allocUnsafe(len);
36780
+ let read = 0;
36781
+ while (read < len) {
36782
+ const n = readSync(fd, buf, read, len - read, start + read);
36783
+ if (n <= 0) break;
36784
+ read += n;
36785
+ }
36786
+ if (read < len) return null;
36787
+ let text = buf.subarray(0, read).toString("utf-8");
36788
+ if (start > 0) {
36789
+ const nl = text.indexOf("\n");
36790
+ text = nl === -1 ? "" : text.slice(nl + 1);
36791
+ }
36792
+ return { text, fromStart: start === 0 };
36793
+ } catch {
36794
+ return null;
36795
+ } finally {
36796
+ closeSync(fd);
36797
+ }
36798
+ }
36799
+ function oldestTimestampMs(text) {
36800
+ let idx = 0;
36801
+ while (idx < text.length) {
36802
+ const nl = text.indexOf("\n", idx);
36803
+ const line = (nl === -1 ? text.slice(idx) : text.slice(idx, nl)).trim();
36804
+ if (line) {
36805
+ try {
36806
+ const ts = JSON.parse(line).timestamp;
36807
+ if (typeof ts === "string") {
36808
+ const ms = new Date(ts).getTime();
36809
+ if (Number.isFinite(ms)) return ms;
36810
+ }
36811
+ } catch {
36812
+ }
36813
+ }
36814
+ if (nl === -1) break;
36815
+ idx = nl + 1;
36816
+ }
36817
+ return null;
36818
+ }
36753
36819
  function agentTranscriptDir(opts) {
36754
36820
  const cwd = opts?.cwd ?? process.cwd();
36755
36821
  const home = opts?.home ?? homedir4();
@@ -36773,12 +36839,10 @@ function classifyTranscriptSince(opts) {
36773
36839
  } catch {
36774
36840
  continue;
36775
36841
  }
36776
- let content;
36777
- try {
36778
- content = readFileSync5(path, "utf-8");
36779
- } catch {
36780
- continue;
36781
- }
36842
+ const content = readClassifiableTail(path, opts.sinceMs, {
36843
+ ...opts.initialTailBytes != null ? { initialBytes: opts.initialTailBytes } : {}
36844
+ });
36845
+ if (!content) continue;
36782
36846
  newest = pickNewerClassification(
36783
36847
  newest,
36784
36848
  classifyTranscriptRateLimit(content, opts.sinceMs, opts.nowMs, new Date(opts.nowMs))
@@ -36814,7 +36878,7 @@ async function watchForRateLimitRefusal(opts) {
36814
36878
  }
36815
36879
 
36816
36880
  // src/turn-failure-watch.ts
36817
- import { readFileSync as readFileSync6, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
36881
+ import { readdirSync as readdirSync3, statSync as statSync2 } from "fs";
36818
36882
  import { join as join7 } from "path";
36819
36883
  function turnFailureNoticeEnabled(env2) {
36820
36884
  return resolveHostBooleanFlag({
@@ -36858,12 +36922,8 @@ function classifyTurnFailureSince(opts) {
36858
36922
  if (cached2 && cached2.fingerprint === fingerprint) {
36859
36923
  scan = cached2.scan;
36860
36924
  } else {
36861
- let content;
36862
- try {
36863
- content = readFileSync6(path, "utf-8");
36864
- } catch {
36865
- continue;
36866
- }
36925
+ const content = readClassifiableTail(path, opts.sinceMs);
36926
+ if (!content) continue;
36867
36927
  const analysis = analyzeTranscriptTurnFailure(content, opts.sinceMs, opts.nowMs);
36868
36928
  scan = {
36869
36929
  result: analysis.result,
@@ -37614,7 +37674,7 @@ function applyHotThreadGuard(input) {
37614
37674
  }
37615
37675
 
37616
37676
  // src/slack-hot-thread-telemetry.ts
37617
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
37677
+ import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
37618
37678
  import { join as join11 } from "path";
37619
37679
  var HOT_THREAD_CLASSIFICATION_COUNTER_SUFFIX = "-hot-thread-classifications.json";
37620
37680
  function hotThreadKey(mode, outcome, proactive) {
@@ -37625,7 +37685,7 @@ function recordHotThreadClassification(agentDir, channel, classification) {
37625
37685
  const path = join11(agentDir, `${channel}${HOT_THREAD_CLASSIFICATION_COUNTER_SUFFIX}`);
37626
37686
  let counts = {};
37627
37687
  try {
37628
- const parsed = JSON.parse(readFileSync7(path, "utf-8"));
37688
+ const parsed = JSON.parse(readFileSync5(path, "utf-8"));
37629
37689
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
37630
37690
  for (const [k, v] of Object.entries(parsed)) {
37631
37691
  if (typeof v === "number" && Number.isInteger(v) && v >= 0) counts[k] = v;
@@ -37642,7 +37702,7 @@ function recordHotThreadClassification(agentDir, channel, classification) {
37642
37702
  }
37643
37703
 
37644
37704
  // src/restart-confirm.ts
37645
- import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync8, renameSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "fs";
37705
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, renameSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "fs";
37646
37706
  import { dirname } from "path";
37647
37707
  import { randomUUID } from "crypto";
37648
37708
  var RESTART_CONFIRM_MAX_AGE_MS = 10 * 60 * 1e3;
@@ -37668,7 +37728,7 @@ function writeRestartConfirmMarker(filePath, marker) {
37668
37728
  function readRestartConfirmMarker(filePath) {
37669
37729
  try {
37670
37730
  if (!existsSync6(filePath)) return null;
37671
- const parsed = JSON.parse(readFileSync8(filePath, "utf8"));
37731
+ const parsed = JSON.parse(readFileSync6(filePath, "utf8"));
37672
37732
  if (!parsed || typeof parsed !== "object") return null;
37673
37733
  return parsed;
37674
37734
  } catch {
@@ -37807,13 +37867,13 @@ var StdioServerTransport = class {
37807
37867
  // src/slack-channel.ts
37808
37868
  import {
37809
37869
  chmodSync,
37810
- closeSync,
37870
+ closeSync as closeSync2,
37811
37871
  createWriteStream,
37812
37872
  existsSync as existsSync10,
37813
37873
  ftruncateSync,
37814
37874
  mkdirSync as mkdirSync9,
37815
- openSync,
37816
- readFileSync as readFileSync20,
37875
+ openSync as openSync2,
37876
+ readFileSync as readFileSync18,
37817
37877
  readdirSync as readdirSync7,
37818
37878
  renameSync as renameSync5,
37819
37879
  statSync as statSync5,
@@ -37827,7 +37887,7 @@ import { homedir as homedir6 } from "os";
37827
37887
  import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
37828
37888
 
37829
37889
  // src/slack-thread-store.ts
37830
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
37890
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "fs";
37831
37891
  import { dirname as dirname2 } from "path";
37832
37892
  function isParticipatingThread(entry) {
37833
37893
  if (!entry) return false;
@@ -37842,7 +37902,7 @@ function loadThreadStore(filePath, opts = {}) {
37842
37902
  const ttlMs = ttlDays * 24 * 60 * 60 * 1e3;
37843
37903
  let raw;
37844
37904
  try {
37845
- raw = readFileSync9(filePath, "utf-8");
37905
+ raw = readFileSync7(filePath, "utf-8");
37846
37906
  } catch {
37847
37907
  return { threads: /* @__PURE__ */ new Map(), pruned: 0 };
37848
37908
  }
@@ -37943,7 +38003,7 @@ function isThreadEntry(value) {
37943
38003
  }
37944
38004
 
37945
38005
  // src/dm-restart-notice.ts
37946
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync10, unlinkSync as unlinkSync4, writeFileSync as writeFileSync6 } from "fs";
38006
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync8, unlinkSync as unlinkSync4, writeFileSync as writeFileSync6 } from "fs";
37947
38007
  import { dirname as dirname3 } from "path";
37948
38008
  var RECENT_DM_VERSION = 1;
37949
38009
  var DEFAULT_RECENT_DM_TTL_MS = 30 * 60 * 1e3;
@@ -37967,7 +38027,7 @@ function loadRecentDms(filePath, opts = {}) {
37967
38027
  const ttlMs = opts.ttlMs ?? DEFAULT_RECENT_DM_TTL_MS;
37968
38028
  let raw;
37969
38029
  try {
37970
- raw = readFileSync10(filePath, "utf-8");
38030
+ raw = readFileSync8(filePath, "utf-8");
37971
38031
  } catch (err) {
37972
38032
  const code = err.code;
37973
38033
  if (code !== "ENOENT") {
@@ -38052,7 +38112,7 @@ var CHANNEL_ADD_RESTART_MAX_AGE_MS = 15 * 60 * 1e3;
38052
38112
  function readChannelAddRestartMarker(filePath) {
38053
38113
  let raw;
38054
38114
  try {
38055
- raw = readFileSync10(filePath, "utf-8");
38115
+ raw = readFileSync8(filePath, "utf-8");
38056
38116
  } catch {
38057
38117
  return null;
38058
38118
  }
@@ -38110,7 +38170,7 @@ async function runOrRetry(fn, opts) {
38110
38170
  }
38111
38171
 
38112
38172
  // src/turn-initiator-marker.ts
38113
- import { writeFileSync as writeFileSync7, readFileSync as readFileSync11, mkdirSync as mkdirSync5, renameSync as renameSync2 } from "fs";
38173
+ import { writeFileSync as writeFileSync7, readFileSync as readFileSync9, mkdirSync as mkdirSync5, renameSync as renameSync2 } from "fs";
38114
38174
  import { dirname as dirname4, join as join12 } from "path";
38115
38175
  var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
38116
38176
  var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
@@ -38141,7 +38201,7 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
38141
38201
  const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
38142
38202
  let existing = null;
38143
38203
  try {
38144
- const parsed = JSON.parse(readFileSync11(ledgerFile, "utf8"));
38204
+ const parsed = JSON.parse(readFileSync9(ledgerFile, "utf8"));
38145
38205
  if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
38146
38206
  } catch {
38147
38207
  }
@@ -38168,7 +38228,7 @@ function writeTurnInitiatorMarker(input) {
38168
38228
  }
38169
38229
 
38170
38230
  // src/slack-bot-photo.ts
38171
- import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync12, writeFileSync as writeFileSync8 } from "fs";
38231
+ import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "fs";
38172
38232
  import { dirname as dirname5 } from "path";
38173
38233
  async function applyBotPhoto(opts) {
38174
38234
  const fetchImpl = opts.fetchImpl ?? fetch;
@@ -38178,7 +38238,7 @@ async function applyBotPhoto(opts) {
38178
38238
  const { token, avatarUrl, markerPath } = opts;
38179
38239
  if (markerPath && existsSync7(markerPath)) {
38180
38240
  try {
38181
- if (readFileSync12(markerPath, "utf-8").trim() === avatarUrl) {
38241
+ if (readFileSync10(markerPath, "utf-8").trim() === avatarUrl) {
38182
38242
  return { status: "skipped-unchanged" };
38183
38243
  }
38184
38244
  } catch {
@@ -38303,7 +38363,7 @@ function conversationalLaneMeta(expectsReply = true) {
38303
38363
  }
38304
38364
 
38305
38365
  // src/inbound-lane-telemetry.ts
38306
- import { readFileSync as readFileSync13, writeFileSync as writeFileSync9 } from "fs";
38366
+ import { readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "fs";
38307
38367
  import { join as join13 } from "path";
38308
38368
  var LANE_CLASSIFICATION_COUNTER_SUFFIX = "-lane-classifications.json";
38309
38369
  var SUSPECTED_MISCLASSIFICATION_KEY = "suspected_misclassification";
@@ -38324,7 +38384,7 @@ function recordLaneClassification(agentDir, channel, classification) {
38324
38384
  const path = join13(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
38325
38385
  let counts = {};
38326
38386
  try {
38327
- const parsed = JSON.parse(readFileSync13(path, "utf-8"));
38387
+ const parsed = JSON.parse(readFileSync11(path, "utf-8"));
38328
38388
  if (parsed && typeof parsed === "object") counts = parsed;
38329
38389
  } catch {
38330
38390
  }
@@ -38340,7 +38400,7 @@ function recordLaneClassification(agentDir, channel, classification) {
38340
38400
  }
38341
38401
 
38342
38402
  // src/slack-inbound-registry.ts
38343
- import { readdirSync as readdirSync5, readFileSync as readFileSync14 } from "fs";
38403
+ import { readdirSync as readdirSync5, readFileSync as readFileSync12 } from "fs";
38344
38404
  import { join as join14 } from "path";
38345
38405
  var DEFAULT_MAX_ENTRIES = 500;
38346
38406
  var DEFAULT_CLEARED_TTL_MS = 6 * 60 * 60 * 1e3;
@@ -38462,7 +38522,7 @@ function createInboundRegistry(opts = {}) {
38462
38522
  if (name.includes(".retry-") || name.includes(".poison")) continue;
38463
38523
  let marker;
38464
38524
  try {
38465
- marker = JSON.parse(readFileSync14(join14(dir, name), "utf-8"));
38525
+ marker = JSON.parse(readFileSync12(join14(dir, name), "utf-8"));
38466
38526
  } catch {
38467
38527
  continue;
38468
38528
  }
@@ -38507,7 +38567,7 @@ function slackInboundId(channel, threadTs, messageTs) {
38507
38567
  }
38508
38568
 
38509
38569
  // src/inbound-delivery-ledger.ts
38510
- import { existsSync as existsSync8, mkdirSync as mkdirSync7, readdirSync as readdirSync6, readFileSync as readFileSync15, renameSync as renameSync3, writeFileSync as writeFileSync10 } from "fs";
38570
+ import { existsSync as existsSync8, mkdirSync as mkdirSync7, readdirSync as readdirSync6, readFileSync as readFileSync13, renameSync as renameSync3, writeFileSync as writeFileSync10 } from "fs";
38511
38571
  import { join as join15 } from "path";
38512
38572
  function safeInboundId(inboundId) {
38513
38573
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
@@ -38517,7 +38577,7 @@ var defaultDeps = {
38517
38577
  writeFile: (path, data) => writeFileSync10(path, data, "utf8"),
38518
38578
  rename: (from, to) => renameSync3(from, to),
38519
38579
  readdir: (dir) => readdirSync6(dir),
38520
- readFile: (path) => readFileSync15(path, "utf8"),
38580
+ readFile: (path) => readFileSync13(path, "utf8"),
38521
38581
  exists: (path) => existsSync8(path)
38522
38582
  };
38523
38583
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
@@ -38707,7 +38767,7 @@ function describeSendOutcome(dest) {
38707
38767
  }
38708
38768
 
38709
38769
  // src/slack-reply-binding-telemetry.ts
38710
- import { readFileSync as readFileSync16, writeFileSync as writeFileSync11 } from "fs";
38770
+ import { readFileSync as readFileSync14, writeFileSync as writeFileSync11 } from "fs";
38711
38771
  import { join as join16 } from "path";
38712
38772
  var REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX = "-reply-binding-classifications.json";
38713
38773
  var UNKNOWN_INBOUND_ID_KEY = "unknown_inbound_id";
@@ -38726,7 +38786,7 @@ function recordReplyBindingClassification(agentDir, channel, input) {
38726
38786
  const path = join16(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
38727
38787
  let counts = {};
38728
38788
  try {
38729
- const parsed = JSON.parse(readFileSync16(path, "utf-8"));
38789
+ const parsed = JSON.parse(readFileSync14(path, "utf-8"));
38730
38790
  if (parsed && typeof parsed === "object") counts = parsed;
38731
38791
  } catch {
38732
38792
  }
@@ -38744,7 +38804,7 @@ function recordScheduledChannelOverride(agentDir, channel, input) {
38744
38804
  const path = join16(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
38745
38805
  let counts = {};
38746
38806
  try {
38747
- const parsed = JSON.parse(readFileSync16(path, "utf-8"));
38807
+ const parsed = JSON.parse(readFileSync14(path, "utf-8"));
38748
38808
  if (parsed && typeof parsed === "object") counts = parsed;
38749
38809
  } catch {
38750
38810
  }
@@ -38760,7 +38820,7 @@ function recordChannelMistarget(agentDir, channel, input) {
38760
38820
  const path = join16(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
38761
38821
  let counts = {};
38762
38822
  try {
38763
- const parsed = JSON.parse(readFileSync16(path, "utf-8"));
38823
+ const parsed = JSON.parse(readFileSync14(path, "utf-8"));
38764
38824
  if (parsed && typeof parsed === "object") counts = parsed;
38765
38825
  } catch {
38766
38826
  }
@@ -38775,7 +38835,7 @@ function recordChannelMistarget(agentDir, channel, input) {
38775
38835
  }
38776
38836
 
38777
38837
  // src/slack-reply-target-telemetry.ts
38778
- import { readFileSync as readFileSync17, writeFileSync as writeFileSync12 } from "fs";
38838
+ import { readFileSync as readFileSync15, writeFileSync as writeFileSync12 } from "fs";
38779
38839
  import { join as join17 } from "path";
38780
38840
  var REPLY_TARGET_CLASSIFICATION_COUNTER_SUFFIX = "-reply-target-classifications.json";
38781
38841
  function pendingThreadsBucket(n) {
@@ -38812,7 +38872,7 @@ function recordReplyTargetClassification(agentDir, channel, classification) {
38812
38872
  const path = join17(agentDir, `${channel}${REPLY_TARGET_CLASSIFICATION_COUNTER_SUFFIX}`);
38813
38873
  let counts = {};
38814
38874
  try {
38815
- const parsed = JSON.parse(readFileSync17(path, "utf-8"));
38875
+ const parsed = JSON.parse(readFileSync15(path, "utf-8"));
38816
38876
  if (parsed && typeof parsed === "object") counts = parsed;
38817
38877
  } catch {
38818
38878
  }
@@ -38828,7 +38888,7 @@ function recordReplyTargetClassification(agentDir, channel, classification) {
38828
38888
  }
38829
38889
 
38830
38890
  // src/scheduled-turn-marker.ts
38831
- import { readFileSync as readFileSync18, unlinkSync as unlinkSync5 } from "fs";
38891
+ import { readFileSync as readFileSync16, unlinkSync as unlinkSync5 } from "fs";
38832
38892
  import { join as join18 } from "path";
38833
38893
  var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
38834
38894
  var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
@@ -38867,7 +38927,7 @@ function readScheduledTurnMarker(agentDir, now = Date.now()) {
38867
38927
  if (!agentDir) return null;
38868
38928
  try {
38869
38929
  const raw = JSON.parse(
38870
- readFileSync18(join18(agentDir, SCHEDULED_TURN_MARKER_FILENAME2), "utf8")
38930
+ readFileSync16(join18(agentDir, SCHEDULED_TURN_MARKER_FILENAME2), "utf8")
38871
38931
  );
38872
38932
  return validateScheduledTurnMarker(raw, now);
38873
38933
  } catch {
@@ -39679,7 +39739,7 @@ async function actuateHostRestart(opts) {
39679
39739
  import {
39680
39740
  existsSync as existsSync9,
39681
39741
  mkdirSync as mkdirSync8,
39682
- readFileSync as readFileSync19,
39742
+ readFileSync as readFileSync17,
39683
39743
  renameSync as renameSync4,
39684
39744
  statSync as statSync4,
39685
39745
  unlinkSync as unlinkSync6,
@@ -39776,7 +39836,7 @@ function defaultLockMtimeMs(path) {
39776
39836
  function readLockHolder(path) {
39777
39837
  if (!existsSync9(path)) return null;
39778
39838
  try {
39779
- const raw = readFileSync19(path, "utf8");
39839
+ const raw = readFileSync17(path, "utf8");
39780
39840
  const parsed = JSON.parse(raw);
39781
39841
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
39782
39842
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -40238,7 +40298,7 @@ function readLiveAllowedUsers() {
40238
40298
  return liveAllowedUsersCache.value;
40239
40299
  }
40240
40300
  const value = extractAllowedUsersFromMcpJson(
40241
- readFileSync20(SLACK_MCP_CONFIG_PATH, "utf-8")
40301
+ readFileSync18(SLACK_MCP_CONFIG_PATH, "utf-8")
40242
40302
  );
40243
40303
  if (value === null) return null;
40244
40304
  liveAllowedUsersCache = { mtimeMs, value };
@@ -40259,7 +40319,7 @@ function readLivePingAllowedUsers() {
40259
40319
  return livePingAllowedUsersCache.value;
40260
40320
  }
40261
40321
  const value = extractPingAllowedUsersFromMcpJson(
40262
- readFileSync20(SLACK_MCP_CONFIG_PATH, "utf-8")
40322
+ readFileSync18(SLACK_MCP_CONFIG_PATH, "utf-8")
40263
40323
  );
40264
40324
  if (value === null) return null;
40265
40325
  livePingAllowedUsersCache = { mtimeMs, value };
@@ -40326,7 +40386,7 @@ function writeSlackPendingInboundMarker(channel, threadTs, messageTs, undelivera
40326
40386
  function rewriteSlackMarkerInPlace(path, marker) {
40327
40387
  let fd;
40328
40388
  try {
40329
- fd = openSync(path, "r+");
40389
+ fd = openSync2(path, "r+");
40330
40390
  const buf = Buffer.from(JSON.stringify(marker));
40331
40391
  ftruncateSync(fd, 0);
40332
40392
  writeSync(fd, buf, 0, buf.length, 0);
@@ -40334,7 +40394,7 @@ function rewriteSlackMarkerInPlace(path, marker) {
40334
40394
  } finally {
40335
40395
  if (fd !== void 0) {
40336
40396
  try {
40337
- closeSync(fd);
40397
+ closeSync2(fd);
40338
40398
  } catch {
40339
40399
  }
40340
40400
  }
@@ -40349,7 +40409,7 @@ function markSlackMarkerPromisedInPlace(fullPath) {
40349
40409
  function markSlackMarkerEngagedInPlace(fullPath, opts) {
40350
40410
  let marker;
40351
40411
  try {
40352
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
40412
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
40353
40413
  } catch {
40354
40414
  return false;
40355
40415
  }
@@ -40364,7 +40424,7 @@ function markSlackMarkerEngagedInPlace(fullPath, opts) {
40364
40424
  rewriteSlackMarkerInPlace(fullPath, marker);
40365
40425
  if (!opts.promise) return false;
40366
40426
  try {
40367
- const readBack = JSON.parse(readFileSync20(fullPath, "utf-8"));
40427
+ const readBack = JSON.parse(readFileSync18(fullPath, "utf-8"));
40368
40428
  return typeof readBack.promised_at === "string" && readBack.promised_at.length > 0;
40369
40429
  } catch {
40370
40430
  return false;
@@ -40375,7 +40435,7 @@ function attachSlackReplayPayload(channel, threadTs, messageTs, payload) {
40375
40435
  if (!path) return;
40376
40436
  let marker;
40377
40437
  try {
40378
- marker = JSON.parse(readFileSync20(path, "utf-8"));
40438
+ marker = JSON.parse(readFileSync18(path, "utf-8"));
40379
40439
  } catch {
40380
40440
  return;
40381
40441
  }
@@ -40386,7 +40446,7 @@ function readSlackPendingInboundMarker(channel, threadTs, messageTs) {
40386
40446
  const path = slackPendingInboundPath(channel, threadTs, messageTs);
40387
40447
  if (!path || !existsSync10(path)) return null;
40388
40448
  try {
40389
- return JSON.parse(readFileSync20(path, "utf-8"));
40449
+ return JSON.parse(readFileSync18(path, "utf-8"));
40390
40450
  } catch {
40391
40451
  return null;
40392
40452
  }
@@ -40535,7 +40595,7 @@ function __resetSlackBusyAckNoticeThrottle() {
40535
40595
  function clearSlackMarkerFileWithHeal(fullPath) {
40536
40596
  let marker = null;
40537
40597
  try {
40538
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
40598
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
40539
40599
  } catch {
40540
40600
  }
40541
40601
  if (marker && decideRecoveryHeal({
@@ -40562,7 +40622,7 @@ var slackPromiseStampOutcome = { attempted: 0, stamped: 0 };
40562
40622
  function healThenEngageSlackMarker(fullPath, opts) {
40563
40623
  let marker = null;
40564
40624
  try {
40565
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
40625
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
40566
40626
  } catch {
40567
40627
  return false;
40568
40628
  }
@@ -40650,7 +40710,7 @@ async function processSlackRecoveryOutboxFile(filename) {
40650
40710
  const fullPath = join20(SLACK_RECOVERY_OUTBOX_DIR, filename);
40651
40711
  let payload;
40652
40712
  try {
40653
- payload = JSON.parse(readFileSync20(fullPath, "utf-8"));
40713
+ payload = JSON.parse(readFileSync18(fullPath, "utf-8"));
40654
40714
  } catch (err) {
40655
40715
  process.stderr.write(
40656
40716
  `slack-channel(${AGENT_CODE_NAME}): recovery outbox parse failed (${filename}): ${err.message}
@@ -40866,7 +40926,7 @@ async function processSlackNoticeOutboxFile(filename) {
40866
40926
  }
40867
40927
  let payload;
40868
40928
  try {
40869
- const parsed = JSON.parse(readFileSync20(fullPath, "utf-8"));
40929
+ const parsed = JSON.parse(readFileSync18(fullPath, "utf-8"));
40870
40930
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
40871
40931
  payload = parsed;
40872
40932
  } catch {
@@ -40995,7 +41055,7 @@ function sweepSlackStaleMarkers(thresholdMs) {
40995
41055
  const fullPath = join20(SLACK_PENDING_INBOUND_DIR, filename);
40996
41056
  let marker;
40997
41057
  try {
40998
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
41058
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
40999
41059
  } catch (err) {
41000
41060
  process.stderr.write(
41001
41061
  `slack-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactSlackId(filename)}: ${err.message}
@@ -41059,7 +41119,7 @@ var slackProgressTickRunning = false;
41059
41119
  function readSlackProgressHeartbeat() {
41060
41120
  if (!SLACK_PROGRESS_HEARTBEAT_PATH || !existsSync10(SLACK_PROGRESS_HEARTBEAT_PATH)) return null;
41061
41121
  try {
41062
- return parseProgressHeartbeat(readFileSync20(SLACK_PROGRESS_HEARTBEAT_PATH, "utf-8"));
41122
+ return parseProgressHeartbeat(readFileSync18(SLACK_PROGRESS_HEARTBEAT_PATH, "utf-8"));
41063
41123
  } catch {
41064
41124
  return null;
41065
41125
  }
@@ -41086,7 +41146,7 @@ function findSlackProgressTarget() {
41086
41146
  if (!name.endsWith(".json")) continue;
41087
41147
  let m;
41088
41148
  try {
41089
- m = JSON.parse(readFileSync20(join20(SLACK_PENDING_INBOUND_DIR, name), "utf-8"));
41149
+ m = JSON.parse(readFileSync18(join20(SLACK_PENDING_INBOUND_DIR, name), "utf-8"));
41090
41150
  } catch {
41091
41151
  continue;
41092
41152
  }
@@ -41237,7 +41297,7 @@ function listPendingSlackConversations() {
41237
41297
  if (!name.endsWith(".json")) continue;
41238
41298
  try {
41239
41299
  const marker = JSON.parse(
41240
- readFileSync20(join20(SLACK_PENDING_INBOUND_DIR, name), "utf8")
41300
+ readFileSync18(join20(SLACK_PENDING_INBOUND_DIR, name), "utf8")
41241
41301
  );
41242
41302
  if (typeof marker.channel !== "string" || !marker.channel) continue;
41243
41303
  if (typeof marker.thread_ts !== "string" || !marker.thread_ts) continue;
@@ -41410,7 +41470,7 @@ function readRestartTopicForMarker(filename, channel, threadTs) {
41410
41470
  if (!SLACK_RESTART_CONTEXT_DIR) return null;
41411
41471
  let raw;
41412
41472
  try {
41413
- raw = readFileSync20(join20(SLACK_RESTART_CONTEXT_DIR, filename), "utf-8");
41473
+ raw = readFileSync18(join20(SLACK_RESTART_CONTEXT_DIR, filename), "utf-8");
41414
41474
  } catch {
41415
41475
  return null;
41416
41476
  }
@@ -41464,7 +41524,7 @@ async function notifyStrandedInboundsOnFirstConnect() {
41464
41524
  const fullPath = join20(SLACK_PENDING_INBOUND_DIR, filename);
41465
41525
  let marker;
41466
41526
  try {
41467
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
41527
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
41468
41528
  } catch {
41469
41529
  continue;
41470
41530
  }
@@ -43492,7 +43552,7 @@ ${result.formatted}` : "No messages in range, or the bot is not a member of this
43492
43552
  };
43493
43553
  }
43494
43554
  size = stat2.size;
43495
- bytes = readFileSync20(resolvedPath);
43555
+ bytes = readFileSync18(resolvedPath);
43496
43556
  } catch (err) {
43497
43557
  return {
43498
43558
  content: [{ type: "text", text: `Failed to read file: ${err.message}` }],
@@ -44286,7 +44346,7 @@ async function replayPendingSlackMarkers() {
44286
44346
  const fullPath = join20(SLACK_PENDING_INBOUND_DIR, name);
44287
44347
  let marker;
44288
44348
  try {
44289
- marker = JSON.parse(readFileSync20(fullPath, "utf-8"));
44349
+ marker = JSON.parse(readFileSync18(fullPath, "utf-8"));
44290
44350
  } catch {
44291
44351
  continue;
44292
44352
  }
@@ -30126,13 +30126,13 @@ var StdioServerTransport = class {
30126
30126
  import https from "https";
30127
30127
  import { createHash as createHash3, randomUUID as randomUUID3 } from "crypto";
30128
30128
  import {
30129
- closeSync,
30129
+ closeSync as closeSync2,
30130
30130
  createWriteStream,
30131
30131
  existsSync as existsSync9,
30132
30132
  ftruncateSync,
30133
30133
  mkdirSync as mkdirSync9,
30134
- openSync,
30135
- readFileSync as readFileSync16,
30134
+ openSync as openSync2,
30135
+ readFileSync as readFileSync14,
30136
30136
  readdirSync as readdirSync6,
30137
30137
  realpathSync,
30138
30138
  renameSync as renameSync7,
@@ -37553,11 +37553,77 @@ function emitToolCallMarkupRedactionTelemetry(channel) {
37553
37553
  }
37554
37554
 
37555
37555
  // src/rate-limit-watch.ts
37556
- import { readFileSync as readFileSync10, readdirSync, statSync } from "fs";
37556
+ import { closeSync, fstatSync, openSync, readSync, readdirSync, statSync } from "fs";
37557
37557
  import { homedir as homedir4 } from "os";
37558
37558
  import { join as join8 } from "path";
37559
37559
  var DEFAULT_WATCH_MS = 5e3;
37560
37560
  var DEFAULT_POLL_MS = 400;
37561
+ var INITIAL_TAIL_BYTES = 256 * 1024;
37562
+ var TAIL_WIDEN_FACTOR = 8;
37563
+ var TAIL_SKEW_TOLERANCE_MS = 5 * 6e4;
37564
+ function readClassifiableTail(path, sinceMs, opts) {
37565
+ let want = Math.max(1, opts?.initialBytes ?? INITIAL_TAIL_BYTES);
37566
+ for (; ; ) {
37567
+ const slice = readTailSlice(path, want);
37568
+ if (slice === null) return "";
37569
+ if (slice.fromStart) return slice.text;
37570
+ const oldest = oldestTimestampMs(slice.text);
37571
+ if (oldest !== null && oldest < sinceMs - TAIL_SKEW_TOLERANCE_MS) return slice.text;
37572
+ want *= TAIL_WIDEN_FACTOR;
37573
+ }
37574
+ }
37575
+ function readTailSlice(path, bytes) {
37576
+ let fd;
37577
+ try {
37578
+ fd = openSync(path, "r");
37579
+ } catch {
37580
+ return null;
37581
+ }
37582
+ try {
37583
+ const size = fstatSync(fd).size;
37584
+ const start = size > bytes ? size - bytes : 0;
37585
+ const len = size - start;
37586
+ if (len <= 0) return { text: "", fromStart: true };
37587
+ const buf = Buffer.allocUnsafe(len);
37588
+ let read = 0;
37589
+ while (read < len) {
37590
+ const n = readSync(fd, buf, read, len - read, start + read);
37591
+ if (n <= 0) break;
37592
+ read += n;
37593
+ }
37594
+ if (read < len) return null;
37595
+ let text = buf.subarray(0, read).toString("utf-8");
37596
+ if (start > 0) {
37597
+ const nl = text.indexOf("\n");
37598
+ text = nl === -1 ? "" : text.slice(nl + 1);
37599
+ }
37600
+ return { text, fromStart: start === 0 };
37601
+ } catch {
37602
+ return null;
37603
+ } finally {
37604
+ closeSync(fd);
37605
+ }
37606
+ }
37607
+ function oldestTimestampMs(text) {
37608
+ let idx = 0;
37609
+ while (idx < text.length) {
37610
+ const nl = text.indexOf("\n", idx);
37611
+ const line = (nl === -1 ? text.slice(idx) : text.slice(idx, nl)).trim();
37612
+ if (line) {
37613
+ try {
37614
+ const ts = JSON.parse(line).timestamp;
37615
+ if (typeof ts === "string") {
37616
+ const ms = new Date(ts).getTime();
37617
+ if (Number.isFinite(ms)) return ms;
37618
+ }
37619
+ } catch {
37620
+ }
37621
+ }
37622
+ if (nl === -1) break;
37623
+ idx = nl + 1;
37624
+ }
37625
+ return null;
37626
+ }
37561
37627
  function agentTranscriptDir(opts) {
37562
37628
  const cwd = opts?.cwd ?? process.cwd();
37563
37629
  const home = opts?.home ?? homedir4();
@@ -37581,12 +37647,10 @@ function classifyTranscriptSince(opts) {
37581
37647
  } catch {
37582
37648
  continue;
37583
37649
  }
37584
- let content;
37585
- try {
37586
- content = readFileSync10(path, "utf-8");
37587
- } catch {
37588
- continue;
37589
- }
37650
+ const content = readClassifiableTail(path, opts.sinceMs, {
37651
+ ...opts.initialTailBytes != null ? { initialBytes: opts.initialTailBytes } : {}
37652
+ });
37653
+ if (!content) continue;
37590
37654
  newest = pickNewerClassification(
37591
37655
  newest,
37592
37656
  classifyTranscriptRateLimit(content, opts.sinceMs, opts.nowMs, new Date(opts.nowMs))
@@ -37622,7 +37686,7 @@ async function watchForRateLimitRefusal(opts) {
37622
37686
  }
37623
37687
 
37624
37688
  // src/turn-failure-watch.ts
37625
- import { readFileSync as readFileSync11, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
37689
+ import { readdirSync as readdirSync2, statSync as statSync2 } from "fs";
37626
37690
  import { join as join9 } from "path";
37627
37691
  function turnFailureNoticeEnabled(env2) {
37628
37692
  return resolveHostBooleanFlag({
@@ -37666,12 +37730,8 @@ function classifyTurnFailureSince(opts) {
37666
37730
  if (cached2 && cached2.fingerprint === fingerprint) {
37667
37731
  scan = cached2.scan;
37668
37732
  } else {
37669
- let content;
37670
- try {
37671
- content = readFileSync11(path, "utf-8");
37672
- } catch {
37673
- continue;
37674
- }
37733
+ const content = readClassifiableTail(path, opts.sinceMs);
37734
+ if (!content) continue;
37675
37735
  const analysis = analyzeTranscriptTurnFailure(content, opts.sinceMs, opts.nowMs);
37676
37736
  scan = {
37677
37737
  result: analysis.result,
@@ -38048,11 +38108,11 @@ function emitTransientApiErrorTelemetry(channel, match, original) {
38048
38108
  }
38049
38109
 
38050
38110
  // src/telegram-pending-inbound-cleanup.ts
38051
- import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
38111
+ import { readdirSync as readdirSync3, readFileSync as readFileSync10, statSync as statSync3 } from "fs";
38052
38112
  import { join as join11 } from "path";
38053
38113
  function markerArrivalMs(fullPath) {
38054
38114
  try {
38055
- const received = JSON.parse(readFileSync12(fullPath, "utf-8")).received_at;
38115
+ const received = JSON.parse(readFileSync10(fullPath, "utf-8")).received_at;
38056
38116
  const parsed = received ? Date.parse(received) : Number.NaN;
38057
38117
  if (Number.isFinite(parsed)) return parsed;
38058
38118
  } catch {
@@ -38114,7 +38174,7 @@ function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
38114
38174
  }
38115
38175
 
38116
38176
  // src/inbound-delivery-ledger.ts
38117
- import { existsSync as existsSync7, mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync13, renameSync as renameSync5, writeFileSync as writeFileSync8 } from "fs";
38177
+ import { existsSync as existsSync7, mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync11, renameSync as renameSync5, writeFileSync as writeFileSync8 } from "fs";
38118
38178
  import { join as join13 } from "path";
38119
38179
  function safeInboundId(inboundId) {
38120
38180
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
@@ -38124,7 +38184,7 @@ var defaultDeps = {
38124
38184
  writeFile: (path, data) => writeFileSync8(path, data, "utf8"),
38125
38185
  rename: (from, to) => renameSync5(from, to),
38126
38186
  readdir: (dir) => readdirSync4(dir),
38127
- readFile: (path) => readFileSync13(path, "utf8"),
38187
+ readFile: (path) => readFileSync11(path, "utf8"),
38128
38188
  exists: (path) => existsSync7(path)
38129
38189
  };
38130
38190
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
@@ -38338,7 +38398,7 @@ function createKanbanCardActiveClient(args) {
38338
38398
  import {
38339
38399
  existsSync as existsSync8,
38340
38400
  mkdirSync as mkdirSync8,
38341
- readFileSync as readFileSync14,
38401
+ readFileSync as readFileSync12,
38342
38402
  renameSync as renameSync6,
38343
38403
  statSync as statSync4,
38344
38404
  unlinkSync as unlinkSync7,
@@ -38435,7 +38495,7 @@ function defaultLockMtimeMs(path) {
38435
38495
  function readLockHolder(path) {
38436
38496
  if (!existsSync8(path)) return null;
38437
38497
  try {
38438
- const raw = readFileSync14(path, "utf8");
38498
+ const raw = readFileSync12(path, "utf8");
38439
38499
  const parsed = JSON.parse(raw);
38440
38500
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
38441
38501
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -38447,7 +38507,7 @@ function readLockHolder(path) {
38447
38507
  }
38448
38508
 
38449
38509
  // src/ack-reaction.ts
38450
- import { readdirSync as readdirSync5, readFileSync as readFileSync15, writeFileSync as writeFileSync10 } from "fs";
38510
+ import { readdirSync as readdirSync5, readFileSync as readFileSync13, writeFileSync as writeFileSync10 } from "fs";
38451
38511
  import { join as join15 } from "path";
38452
38512
  var REPLY_WEDGED_THRESHOLD_MS = 5 * 60 * 1e3;
38453
38513
  var ACK_STARTUP_GRACE_MS = 6e4;
@@ -38521,7 +38581,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
38521
38581
  function readGiveUpSignal(path, now = Date.now()) {
38522
38582
  if (!path) return null;
38523
38583
  try {
38524
- const raw = JSON.parse(readFileSync15(path, "utf8"));
38584
+ const raw = JSON.parse(readFileSync13(path, "utf8"));
38525
38585
  if (typeof raw.gave_up_at !== "string") return null;
38526
38586
  const t = Date.parse(raw.gave_up_at);
38527
38587
  if (!Number.isFinite(t) || t > now) return null;
@@ -38562,7 +38622,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
38562
38622
  if (!name.endsWith(".json")) continue;
38563
38623
  let receivedAt;
38564
38624
  try {
38565
- const raw = JSON.parse(readFileSync15(join15(dir, name), "utf-8"));
38625
+ const raw = JSON.parse(readFileSync13(join15(dir, name), "utf-8"));
38566
38626
  if (raw.discretionary === true) continue;
38567
38627
  if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
38568
38628
  receivedAt = raw.received_at;
@@ -38646,7 +38706,7 @@ function recordChannelDeflection(agentDir, channel, cause) {
38646
38706
  const path = deflectionCounterPath(agentDir, channel);
38647
38707
  let counts = {};
38648
38708
  try {
38649
- const parsed = JSON.parse(readFileSync15(path, "utf-8"));
38709
+ const parsed = JSON.parse(readFileSync13(path, "utf-8"));
38650
38710
  if (parsed && typeof parsed === "object") counts = parsed;
38651
38711
  } catch {
38652
38712
  }
@@ -38834,7 +38894,7 @@ var PEER_PRESENCE_STATE_FILE = TELEGRAM_AGENT_DIR ? join16(TELEGRAM_AGENT_DIR, "
38834
38894
  function readPeerPresenceState() {
38835
38895
  if (!PEER_PRESENCE_STATE_FILE) return null;
38836
38896
  try {
38837
- const parsed = JSON.parse(readFileSync16(PEER_PRESENCE_STATE_FILE, "utf-8"));
38897
+ const parsed = JSON.parse(readFileSync14(PEER_PRESENCE_STATE_FILE, "utf-8"));
38838
38898
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
38839
38899
  return parsed;
38840
38900
  } catch {
@@ -40220,7 +40280,7 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
40220
40280
  function rewriteTelegramMarkerInPlace(path, marker) {
40221
40281
  let fd;
40222
40282
  try {
40223
- fd = openSync(path, "r+");
40283
+ fd = openSync2(path, "r+");
40224
40284
  const buf = Buffer.from(JSON.stringify(marker));
40225
40285
  ftruncateSync(fd, 0);
40226
40286
  writeSync(fd, buf, 0, buf.length, 0);
@@ -40228,7 +40288,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
40228
40288
  } finally {
40229
40289
  if (fd !== void 0) {
40230
40290
  try {
40231
- closeSync(fd);
40291
+ closeSync2(fd);
40232
40292
  } catch {
40233
40293
  }
40234
40294
  }
@@ -40237,7 +40297,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
40237
40297
  function clearTelegramMarkerFileWithHeal(fullPath) {
40238
40298
  let marker = null;
40239
40299
  try {
40240
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40300
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
40241
40301
  } catch {
40242
40302
  }
40243
40303
  if (marker && decideRecoveryHeal({
@@ -40260,7 +40320,7 @@ function markTelegramMarkerPromisedInPlace(fullPath) {
40260
40320
  function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40261
40321
  let marker;
40262
40322
  try {
40263
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40323
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
40264
40324
  } catch {
40265
40325
  return false;
40266
40326
  }
@@ -40275,7 +40335,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40275
40335
  rewriteTelegramMarkerInPlace(fullPath, marker);
40276
40336
  if (!opts.promise) return false;
40277
40337
  try {
40278
- const readBack = JSON.parse(readFileSync16(fullPath, "utf-8"));
40338
+ const readBack = JSON.parse(readFileSync14(fullPath, "utf-8"));
40279
40339
  return typeof readBack.promised_at === "string" && readBack.promised_at.length > 0;
40280
40340
  } catch {
40281
40341
  return false;
@@ -40284,7 +40344,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40284
40344
  function markTelegramMarkerSeenWithHeal(fullPath) {
40285
40345
  let marker = null;
40286
40346
  try {
40287
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40347
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
40288
40348
  } catch {
40289
40349
  return;
40290
40350
  }
@@ -40299,7 +40359,7 @@ function markTelegramMarkerSeenWithHeal(fullPath) {
40299
40359
  function markTelegramMarkerPromisedWithHeal(fullPath) {
40300
40360
  let marker = null;
40301
40361
  try {
40302
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40362
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
40303
40363
  } catch {
40304
40364
  return;
40305
40365
  }
@@ -40317,7 +40377,7 @@ function readPendingInboundMarker(chatId, messageId) {
40317
40377
  const path = pendingInboundPath(chatId, messageId);
40318
40378
  if (!path || !existsSync9(path)) return null;
40319
40379
  try {
40320
- return JSON.parse(readFileSync16(path, "utf-8"));
40380
+ return JSON.parse(readFileSync14(path, "utf-8"));
40321
40381
  } catch {
40322
40382
  return null;
40323
40383
  }
@@ -40340,7 +40400,7 @@ async function processRecoveryOutboxFile(filename) {
40340
40400
  const fullPath = join16(RECOVERY_OUTBOX_DIR, filename);
40341
40401
  let payload;
40342
40402
  try {
40343
- const raw = readFileSync16(fullPath, "utf-8");
40403
+ const raw = readFileSync14(fullPath, "utf-8");
40344
40404
  payload = JSON.parse(raw);
40345
40405
  } catch (err) {
40346
40406
  process.stderr.write(
@@ -40545,7 +40605,7 @@ async function processNoticeOutboxFile(filename) {
40545
40605
  }
40546
40606
  let payload;
40547
40607
  try {
40548
- const parsed = JSON.parse(readFileSync16(fullPath, "utf-8"));
40608
+ const parsed = JSON.parse(readFileSync14(fullPath, "utf-8"));
40549
40609
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
40550
40610
  payload = parsed;
40551
40611
  } catch {
@@ -40659,7 +40719,7 @@ function sweepTelegramStaleMarkers(thresholdMs) {
40659
40719
  const fullPath = join16(PENDING_INBOUND_DIR, filename);
40660
40720
  let marker;
40661
40721
  try {
40662
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40722
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
40663
40723
  } catch (err) {
40664
40724
  process.stderr.write(
40665
40725
  `telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
@@ -40718,7 +40778,7 @@ var telegramProgressTickRunning = false;
40718
40778
  function readTelegramProgressHeartbeat() {
40719
40779
  if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync9(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
40720
40780
  try {
40721
- return parseProgressHeartbeat(readFileSync16(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
40781
+ return parseProgressHeartbeat(readFileSync14(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
40722
40782
  } catch {
40723
40783
  return null;
40724
40784
  }
@@ -40745,7 +40805,7 @@ function findTelegramProgressTarget() {
40745
40805
  if (!name.endsWith(".json")) continue;
40746
40806
  let m;
40747
40807
  try {
40748
- m = JSON.parse(readFileSync16(join16(PENDING_INBOUND_DIR, name), "utf-8"));
40808
+ m = JSON.parse(readFileSync14(join16(PENDING_INBOUND_DIR, name), "utf-8"));
40749
40809
  } catch {
40750
40810
  continue;
40751
40811
  }
@@ -40876,7 +40936,7 @@ function listPendingInboundChatIds() {
40876
40936
  if (!name.endsWith(".json")) continue;
40877
40937
  try {
40878
40938
  const marker = JSON.parse(
40879
- readFileSync16(join16(PENDING_INBOUND_DIR, name), "utf8")
40939
+ readFileSync14(join16(PENDING_INBOUND_DIR, name), "utf8")
40880
40940
  );
40881
40941
  if (typeof marker.seen_at === "string" && marker.seen_at) continue;
40882
40942
  if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
@@ -41369,7 +41429,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
41369
41429
  isError: true
41370
41430
  };
41371
41431
  }
41372
- bytes = readFileSync16(realPath);
41432
+ bytes = readFileSync14(realPath);
41373
41433
  } catch (err) {
41374
41434
  return { content: [{ type: "text", text: `Failed to read file: ${err.message}` }], isError: true };
41375
41435
  }
@@ -41949,7 +42009,7 @@ async function replayPendingTelegramMarkers() {
41949
42009
  const fullPath = join16(PENDING_INBOUND_DIR, name);
41950
42010
  let marker;
41951
42011
  try {
41952
- marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
42012
+ marker = JSON.parse(readFileSync14(fullPath, "utf-8"));
41953
42013
  } catch {
41954
42014
  continue;
41955
42015
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integrity-labs/agt-cli",
3
- "version": "0.28.482",
3
+ "version": "0.28.484",
4
4
  "description": "Augmented Team CLI — agent provisioning and management",
5
5
  "type": "module",
6
6
  "engines": {