@integrity-labs/agt-cli 0.28.237 → 0.28.239

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.
@@ -14196,8 +14196,46 @@ function buildDirectChatChannelMeta(input) {
14196
14196
  }
14197
14197
 
14198
14198
  // src/turn-initiator-marker.ts
14199
- import { writeFileSync, mkdirSync, renameSync } from "fs";
14200
- import { dirname } from "path";
14199
+ import { writeFileSync, readFileSync as readFileSync2, mkdirSync, renameSync } from "fs";
14200
+ import { dirname, join as join2 } from "path";
14201
+ var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
14202
+ var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
14203
+ var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
14204
+ function turnInitiatorLedgerPath(singleSlotFile) {
14205
+ return join2(dirname(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
14206
+ }
14207
+ function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
14208
+ const now = marker.ts;
14209
+ const key = (e) => `${e.channel}\0${e.channel_ref ?? ""}`;
14210
+ const markerKey = key(marker);
14211
+ const prior = existing && Array.isArray(existing.entries) ? existing.entries : [];
14212
+ const kept = prior.filter(
14213
+ (e) => e && typeof e.ts === "number" && Number.isFinite(e.ts) && now - e.ts <= maxAgeMs && now - e.ts >= 0 && key(e) !== markerKey
14214
+ // the same thread is replaced by the new entry below
14215
+ );
14216
+ kept.push({
14217
+ channel: marker.channel,
14218
+ sender_id: marker.sender_id,
14219
+ ...marker.sender_name ? { sender_name: marker.sender_name } : {},
14220
+ ...marker.channel_ref ? { channel_ref: marker.channel_ref } : {},
14221
+ ts: marker.ts
14222
+ });
14223
+ kept.sort((a, b) => b.ts - a.ts);
14224
+ return { v: 1, entries: kept.slice(0, maxEntries) };
14225
+ }
14226
+ function updateTurnInitiatorLedger(singleSlotFile, marker) {
14227
+ const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
14228
+ let existing = null;
14229
+ try {
14230
+ const parsed = JSON.parse(readFileSync2(ledgerFile, "utf8"));
14231
+ if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
14232
+ } catch {
14233
+ }
14234
+ const next = foldTurnInitiatorLedger(existing, marker);
14235
+ const tmp = `${ledgerFile}.tmp`;
14236
+ writeFileSync(tmp, JSON.stringify(next), "utf8");
14237
+ renameSync(tmp, ledgerFile);
14238
+ }
14201
14239
  function writeTurnInitiatorMarker(input) {
14202
14240
  const file = process.env["AGT_TURN_INITIATOR_FILE"];
14203
14241
  if (!file || !input.sender_id) return;
@@ -14207,6 +14245,10 @@ function writeTurnInitiatorMarker(input) {
14207
14245
  const tmp = `${file}.tmp`;
14208
14246
  writeFileSync(tmp, JSON.stringify(marker), "utf8");
14209
14247
  renameSync(tmp, file);
14248
+ try {
14249
+ updateTurnInitiatorLedger(file, marker);
14250
+ } catch {
14251
+ }
14210
14252
  } catch {
14211
14253
  }
14212
14254
  }
@@ -14235,12 +14277,12 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
14235
14277
  import {
14236
14278
  existsSync as existsSync2,
14237
14279
  mkdirSync as mkdirSync2,
14238
- readFileSync as readFileSync2,
14280
+ readFileSync as readFileSync3,
14239
14281
  renameSync as renameSync2,
14240
14282
  unlinkSync,
14241
14283
  writeFileSync as writeFileSync2
14242
14284
  } from "fs";
14243
- import { join as join2 } from "path";
14285
+ import { join as join3 } from "path";
14244
14286
  function defaultIsPidAlive(pid) {
14245
14287
  if (!Number.isFinite(pid) || pid <= 0) return false;
14246
14288
  try {
@@ -14258,7 +14300,7 @@ function acquireMcpSpawnLock(args) {
14258
14300
  const isPidAlive = options.isPidAlive ?? defaultIsPidAlive;
14259
14301
  const selfPid = options.selfPid ?? process.pid;
14260
14302
  const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
14261
- const path = join2(agentDir, basename);
14303
+ const path = join3(agentDir, basename);
14262
14304
  const existing = readLockHolder(path);
14263
14305
  if (existing) {
14264
14306
  if (existing.pid === selfPid) {
@@ -14289,7 +14331,7 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
14289
14331
  function readLockHolder(path) {
14290
14332
  if (!existsSync2(path)) return null;
14291
14333
  try {
14292
- const raw = readFileSync2(path, "utf8");
14334
+ const raw = readFileSync3(path, "utf8");
14293
14335
  const parsed = JSON.parse(raw);
14294
14336
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
14295
14337
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -14302,35 +14344,35 @@ function readLockHolder(path) {
14302
14344
 
14303
14345
  // src/direct-chat-channel.ts
14304
14346
  import { homedir as homedir2 } from "os";
14305
- import { join as join5 } from "path";
14347
+ import { join as join6 } from "path";
14306
14348
  import { randomUUID } from "crypto";
14307
14349
  import {
14308
14350
  watch,
14309
14351
  mkdirSync as mkdirSync3,
14310
14352
  writeFileSync as writeFileSync3,
14311
- readFileSync as readFileSync4,
14353
+ readFileSync as readFileSync5,
14312
14354
  existsSync as existsSync4,
14313
14355
  renameSync as renameSync3,
14314
14356
  unlinkSync as unlinkSync2
14315
14357
  } from "fs";
14316
14358
 
14317
14359
  // src/direct-chat-inbound-attachments.ts
14318
- import { dirname as dirname2, join as join3 } from "path";
14360
+ import { dirname as dirname2, join as join4 } from "path";
14319
14361
  var MAX_INBOUND_ATTACHMENT_BYTES = 10 * 1024 * 1024;
14320
14362
  var INBOUND_ATTACHMENTS_SUBDIR = "direct-chat-inbound";
14321
14363
  function resolveInboundAttachmentsDir(input) {
14322
14364
  const { codeName, turnInitiatorFile, agentId, homeDir } = input;
14323
14365
  const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
14324
14366
  if (codeNameTrimmed) {
14325
- return join3(homeDir, ".augmented", codeNameTrimmed, INBOUND_ATTACHMENTS_SUBDIR);
14367
+ return join4(homeDir, ".augmented", codeNameTrimmed, INBOUND_ATTACHMENTS_SUBDIR);
14326
14368
  }
14327
14369
  const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
14328
14370
  if (initiator) {
14329
- return join3(dirname2(initiator), INBOUND_ATTACHMENTS_SUBDIR);
14371
+ return join4(dirname2(initiator), INBOUND_ATTACHMENTS_SUBDIR);
14330
14372
  }
14331
14373
  const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
14332
14374
  if (agentIdTrimmed) {
14333
- return join3(homeDir, ".augmented", agentIdTrimmed, INBOUND_ATTACHMENTS_SUBDIR);
14375
+ return join4(homeDir, ".augmented", agentIdTrimmed, INBOUND_ATTACHMENTS_SUBDIR);
14334
14376
  }
14335
14377
  return null;
14336
14378
  }
@@ -14428,11 +14470,11 @@ async function downloadInboundAttachments(attachments, dir, deps) {
14428
14470
  }
14429
14471
 
14430
14472
  // src/flags-cache-read.ts
14431
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
14473
+ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
14432
14474
  import { homedir } from "os";
14433
- import { join as join4 } from "path";
14475
+ import { join as join5 } from "path";
14434
14476
  function defaultFlagsCachePath() {
14435
- return join4(homedir(), ".augmented", "flags-cache.json");
14477
+ return join5(homedir(), ".augmented", "flags-cache.json");
14436
14478
  }
14437
14479
  function envBoolean(raw) {
14438
14480
  if (raw === void 0) return void 0;
@@ -14445,7 +14487,7 @@ function envBoolean(raw) {
14445
14487
  function cachedBoolean(key, path) {
14446
14488
  try {
14447
14489
  if (!existsSync3(path)) return void 0;
14448
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
14490
+ const parsed = JSON.parse(readFileSync4(path, "utf8"));
14449
14491
  if (!parsed || typeof parsed !== "object") return void 0;
14450
14492
  const flags = parsed.flags;
14451
14493
  if (!flags || typeof flags !== "object") return void 0;
@@ -14746,7 +14788,7 @@ var DIRECT_CHAT_MAINTENANCE_COOLDOWN_MS = (() => {
14746
14788
  var AGT_HOST = process.env.AGT_HOST;
14747
14789
  var AGT_API_KEY = process.env.AGT_API_KEY;
14748
14790
  var AGT_AGENT_ID = process.env.AGT_AGENT_ID;
14749
- var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join5(homedir2(), ".augmented", AGT_AGENT_ID) : null;
14791
+ var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join6(homedir2(), ".augmented", AGT_AGENT_ID) : null;
14750
14792
  var INBOUND_ATTACHMENTS_DIR = resolveInboundAttachmentsDir({
14751
14793
  codeName: process.env.AGT_AGENT_CODE_NAME,
14752
14794
  turnInitiatorFile: process.env.AGT_TURN_INITIATOR_FILE,
@@ -14754,7 +14796,7 @@ var INBOUND_ATTACHMENTS_DIR = resolveInboundAttachmentsDir({
14754
14796
  homeDir: homedir2()
14755
14797
  });
14756
14798
  var AGT_AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME;
14757
- var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join5(homedir2(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
14799
+ var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join6(homedir2(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
14758
14800
  var progressReceivedAt = /* @__PURE__ */ new Map();
14759
14801
  var directChatProgressState = { tracked: null };
14760
14802
  var directChatProgressTickRunning = false;
@@ -14773,7 +14815,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
14773
14815
  function readProgressHeartbeat() {
14774
14816
  if (!PROGRESS_HEARTBEAT_PATH || !existsSync4(PROGRESS_HEARTBEAT_PATH)) return null;
14775
14817
  try {
14776
- return parseProgressHeartbeat(readFileSync4(PROGRESS_HEARTBEAT_PATH, "utf-8"));
14818
+ return parseProgressHeartbeat(readFileSync5(PROGRESS_HEARTBEAT_PATH, "utf-8"));
14777
14819
  } catch {
14778
14820
  return null;
14779
14821
  }
@@ -14782,7 +14824,7 @@ function seedProgressHeartbeat() {
14782
14824
  if (!PROGRESS_HEARTBEAT_PATH) return;
14783
14825
  const tmp = `${PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
14784
14826
  try {
14785
- mkdirSync3(join5(homedir2(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
14827
+ mkdirSync3(join6(homedir2(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
14786
14828
  writeFileSync3(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
14787
14829
  renameSync3(tmp, PROGRESS_HEARTBEAT_PATH);
14788
14830
  } catch {
@@ -14940,7 +14982,7 @@ var inboundAttachmentDeps = {
14940
14982
  },
14941
14983
  ensureDir: (dir) => mkdirSync3(dir, { recursive: true }),
14942
14984
  writeFile: (path, bytes) => writeFileSync3(path, bytes, { mode: 384 }),
14943
- joinPath: (...parts) => join5(...parts),
14985
+ joinPath: (...parts) => join6(...parts),
14944
14986
  warn: (msg) => process.stderr.write(`${msg}
14945
14987
  `)
14946
14988
  };