@integrity-labs/agt-cli 0.28.330 → 0.28.332

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.
@@ -16199,6 +16199,29 @@ function clearOldestSlackPendingMarkerInChannel(dir, channel, clear = defaultCle
16199
16199
  }
16200
16200
  }
16201
16201
 
16202
+ // src/recovery-ledger.ts
16203
+ import { existsSync as existsSync5, unlinkSync as unlinkSync2 } from "fs";
16204
+ import { join as join7 } from "path";
16205
+ function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p) => existsSync5(p)) {
16206
+ if (!ledgerDir || !markerName) return false;
16207
+ if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return false;
16208
+ try {
16209
+ return exists(join7(ledgerDir, markerName));
16210
+ } catch {
16211
+ return false;
16212
+ }
16213
+ }
16214
+ function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p) => {
16215
+ if (existsSync5(p)) unlinkSync2(p);
16216
+ }) {
16217
+ if (!ledgerDir || !markerName) return;
16218
+ if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
16219
+ try {
16220
+ unlink(join7(ledgerDir, markerName));
16221
+ } catch {
16222
+ }
16223
+ }
16224
+
16202
16225
  // src/channel-progress.ts
16203
16226
  function channelLiveProgressEnabled() {
16204
16227
  return resolveHostBooleanFlag({
@@ -16390,7 +16413,7 @@ function resolveReplyThreadTs(input) {
16390
16413
  }
16391
16414
 
16392
16415
  // src/restart-confirm.ts
16393
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "fs";
16416
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync3 } from "fs";
16394
16417
  import { dirname } from "path";
16395
16418
  import { randomUUID } from "crypto";
16396
16419
  var RESTART_CONFIRM_MAX_AGE_MS = 10 * 60 * 1e3;
@@ -16408,14 +16431,14 @@ function buildBackOnlineText(name) {
16408
16431
  }
16409
16432
  function writeRestartConfirmMarker(filePath, marker) {
16410
16433
  const dir = dirname(filePath);
16411
- if (!existsSync5(dir)) mkdirSync2(dir, { recursive: true, mode: 448 });
16434
+ if (!existsSync6(dir)) mkdirSync2(dir, { recursive: true, mode: 448 });
16412
16435
  const tmpPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
16413
16436
  writeFileSync3(tmpPath, JSON.stringify(marker) + "\n", { encoding: "utf8", mode: 384 });
16414
16437
  renameSync(tmpPath, filePath);
16415
16438
  }
16416
16439
  function readRestartConfirmMarker(filePath) {
16417
16440
  try {
16418
- if (!existsSync5(filePath)) return null;
16441
+ if (!existsSync6(filePath)) return null;
16419
16442
  const parsed = JSON.parse(readFileSync4(filePath, "utf8"));
16420
16443
  if (!parsed || typeof parsed !== "object") return null;
16421
16444
  return parsed;
@@ -16425,7 +16448,7 @@ function readRestartConfirmMarker(filePath) {
16425
16448
  }
16426
16449
  function clearRestartConfirmMarker(filePath) {
16427
16450
  try {
16428
- if (existsSync5(filePath)) unlinkSync2(filePath);
16451
+ if (existsSync6(filePath)) unlinkSync3(filePath);
16429
16452
  } catch {
16430
16453
  }
16431
16454
  }
@@ -16527,20 +16550,20 @@ import {
16527
16550
  chmodSync,
16528
16551
  closeSync,
16529
16552
  createWriteStream,
16530
- existsSync as existsSync8,
16553
+ existsSync as existsSync10,
16531
16554
  ftruncateSync,
16532
- mkdirSync as mkdirSync8,
16555
+ mkdirSync as mkdirSync9,
16533
16556
  openSync,
16534
- readFileSync as readFileSync15,
16535
- readdirSync as readdirSync4,
16536
- renameSync as renameSync4,
16557
+ readFileSync as readFileSync16,
16558
+ readdirSync as readdirSync5,
16559
+ renameSync as renameSync5,
16537
16560
  statSync as statSync2,
16538
- unlinkSync as unlinkSync6,
16561
+ unlinkSync as unlinkSync7,
16539
16562
  watch,
16540
- writeFileSync as writeFileSync12,
16563
+ writeFileSync as writeFileSync13,
16541
16564
  writeSync
16542
16565
  } from "fs";
16543
- import { basename, join as join14, resolve as resolve2 } from "path";
16566
+ import { basename, join as join16, resolve as resolve2 } from "path";
16544
16567
  import { homedir as homedir4 } from "os";
16545
16568
  import { createHash as createHash2, randomUUID as randomUUID2 } from "crypto";
16546
16569
 
@@ -16661,7 +16684,7 @@ function isThreadEntry(value) {
16661
16684
  }
16662
16685
 
16663
16686
  // src/dm-restart-notice.ts
16664
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, unlinkSync as unlinkSync3, writeFileSync as writeFileSync5 } from "fs";
16687
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, unlinkSync as unlinkSync4, writeFileSync as writeFileSync5 } from "fs";
16665
16688
  import { dirname as dirname3 } from "path";
16666
16689
  var RECENT_DM_VERSION = 1;
16667
16690
  var DEFAULT_RECENT_DM_TTL_MS = 30 * 60 * 1e3;
@@ -16795,7 +16818,7 @@ function shouldPostChannelAddNotice(marker, bootMs, maxAgeMs = CHANNEL_ADD_RESTA
16795
16818
  }
16796
16819
  function clearChannelAddRestartMarker(filePath) {
16797
16820
  try {
16798
- unlinkSync3(filePath);
16821
+ unlinkSync4(filePath);
16799
16822
  } catch {
16800
16823
  }
16801
16824
  }
@@ -16829,12 +16852,12 @@ async function runOrRetry(fn, opts) {
16829
16852
 
16830
16853
  // src/turn-initiator-marker.ts
16831
16854
  import { writeFileSync as writeFileSync6, readFileSync as readFileSync7, mkdirSync as mkdirSync5, renameSync as renameSync2 } from "fs";
16832
- import { dirname as dirname4, join as join7 } from "path";
16855
+ import { dirname as dirname4, join as join8 } from "path";
16833
16856
  var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
16834
16857
  var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
16835
16858
  var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
16836
16859
  function turnInitiatorLedgerPath(singleSlotFile) {
16837
- return join7(dirname4(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
16860
+ return join8(dirname4(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
16838
16861
  }
16839
16862
  function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
16840
16863
  const now = marker.ts;
@@ -16886,7 +16909,7 @@ function writeTurnInitiatorMarker(input) {
16886
16909
  }
16887
16910
 
16888
16911
  // src/slack-bot-photo.ts
16889
- import { existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "fs";
16912
+ import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "fs";
16890
16913
  import { dirname as dirname5 } from "path";
16891
16914
  async function applyBotPhoto(opts) {
16892
16915
  const fetchImpl = opts.fetchImpl ?? fetch;
@@ -16894,7 +16917,7 @@ async function applyBotPhoto(opts) {
16894
16917
  process.stderr.write(m);
16895
16918
  });
16896
16919
  const { token, avatarUrl, markerPath } = opts;
16897
- if (markerPath && existsSync6(markerPath)) {
16920
+ if (markerPath && existsSync7(markerPath)) {
16898
16921
  try {
16899
16922
  if (readFileSync8(markerPath, "utf-8").trim() === avatarUrl) {
16900
16923
  return { status: "skipped-unchanged" };
@@ -17022,7 +17045,7 @@ function conversationalLaneMeta(expectsReply = true) {
17022
17045
 
17023
17046
  // src/inbound-lane-telemetry.ts
17024
17047
  import { readFileSync as readFileSync9, writeFileSync as writeFileSync8 } from "fs";
17025
- import { join as join8 } from "path";
17048
+ import { join as join9 } from "path";
17026
17049
  var LANE_CLASSIFICATION_COUNTER_SUFFIX = "-lane-classifications.json";
17027
17050
  var SUSPECTED_MISCLASSIFICATION_KEY = "suspected_misclassification";
17028
17051
  var HUMAN_CHANNEL_SOURCES = /* @__PURE__ */ new Set([
@@ -17039,7 +17062,7 @@ function isSuspectedMisclassification(lane, source) {
17039
17062
  }
17040
17063
  function recordLaneClassification(agentDir, channel, classification) {
17041
17064
  if (!agentDir) return;
17042
- const path = join8(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
17065
+ const path = join9(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
17043
17066
  let counts = {};
17044
17067
  try {
17045
17068
  const parsed = JSON.parse(readFileSync9(path, "utf-8"));
@@ -17059,7 +17082,7 @@ function recordLaneClassification(agentDir, channel, classification) {
17059
17082
 
17060
17083
  // src/slack-inbound-registry.ts
17061
17084
  import { readdirSync as readdirSync3, readFileSync as readFileSync10 } from "fs";
17062
- import { join as join9 } from "path";
17085
+ import { join as join10 } from "path";
17063
17086
  var DEFAULT_MAX_ENTRIES = 500;
17064
17087
  var DEFAULT_CLEARED_TTL_MS = 6 * 60 * 60 * 1e3;
17065
17088
  function entryKey(channel, messageTs) {
@@ -17180,7 +17203,7 @@ function createInboundRegistry(opts = {}) {
17180
17203
  if (name.includes(".retry-") || name.includes(".poison")) continue;
17181
17204
  let marker;
17182
17205
  try {
17183
- marker = JSON.parse(readFileSync10(join9(dir, name), "utf-8"));
17206
+ marker = JSON.parse(readFileSync10(join10(dir, name), "utf-8"));
17184
17207
  } catch {
17185
17208
  continue;
17186
17209
  }
@@ -17224,6 +17247,34 @@ function slackInboundId(channel, threadTs, messageTs) {
17224
17247
  return `ib_${digest}`;
17225
17248
  }
17226
17249
 
17250
+ // src/inbound-delivery-ledger.ts
17251
+ import { existsSync as existsSync8, mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync11, renameSync as renameSync3, writeFileSync as writeFileSync9 } from "fs";
17252
+ import { join as join11 } from "path";
17253
+ function safeInboundId(inboundId) {
17254
+ return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
17255
+ }
17256
+ var defaultDeps = {
17257
+ mkdir: (dir) => mkdirSync7(dir, { recursive: true }),
17258
+ writeFile: (path, data) => writeFileSync9(path, data, "utf8"),
17259
+ rename: (from, to) => renameSync3(from, to),
17260
+ readdir: (dir) => readdirSync4(dir),
17261
+ readFile: (path) => readFileSync11(path, "utf8"),
17262
+ exists: (path) => existsSync8(path)
17263
+ };
17264
+ function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
17265
+ if (!dir || !record2.inbound_id || !record2.conv_key) return;
17266
+ const safe = safeInboundId(record2.inbound_id);
17267
+ if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return;
17268
+ try {
17269
+ deps.mkdir(dir);
17270
+ const final = join11(dir, `${safe}.json`);
17271
+ const tmp = `${final}.tmp`;
17272
+ deps.writeFile(tmp, JSON.stringify(record2));
17273
+ deps.rename(tmp, final);
17274
+ } catch {
17275
+ }
17276
+ }
17277
+
17227
17278
  // src/slack-reply-binding.ts
17228
17279
  function matchByCoords(registry2, channel, messageTs, threadTs) {
17229
17280
  if (!channel) return null;
@@ -17360,8 +17411,8 @@ function buildSlackMcpInstructions(opts) {
17360
17411
  }
17361
17412
 
17362
17413
  // src/slack-reply-binding-telemetry.ts
17363
- import { readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "fs";
17364
- import { join as join10 } from "path";
17414
+ import { readFileSync as readFileSync12, writeFileSync as writeFileSync10 } from "fs";
17415
+ import { join as join12 } from "path";
17365
17416
  var REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX = "-reply-binding-classifications.json";
17366
17417
  var UNKNOWN_INBOUND_ID_KEY = "unknown_inbound_id";
17367
17418
  var CHANNEL_MISTARGET_CORRECTED_KEY = "channel_mistarget_corrected";
@@ -17374,10 +17425,10 @@ function slackReplyBindingMode() {
17374
17425
  }
17375
17426
  function recordReplyBindingClassification(agentDir, channel, input) {
17376
17427
  if (!agentDir) return;
17377
- const path = join10(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
17428
+ const path = join12(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
17378
17429
  let counts = {};
17379
17430
  try {
17380
- const parsed = JSON.parse(readFileSync11(path, "utf-8"));
17431
+ const parsed = JSON.parse(readFileSync12(path, "utf-8"));
17381
17432
  if (parsed && typeof parsed === "object") counts = parsed;
17382
17433
  } catch {
17383
17434
  }
@@ -17386,16 +17437,16 @@ function recordReplyBindingClassification(agentDir, channel, input) {
17386
17437
  counts[UNKNOWN_INBOUND_ID_KEY] = (counts[UNKNOWN_INBOUND_ID_KEY] ?? 0) + 1;
17387
17438
  }
17388
17439
  try {
17389
- writeFileSync9(path, JSON.stringify(counts), { mode: 384 });
17440
+ writeFileSync10(path, JSON.stringify(counts), { mode: 384 });
17390
17441
  } catch {
17391
17442
  }
17392
17443
  }
17393
17444
  function recordChannelMistarget(agentDir, channel, input) {
17394
17445
  if (!agentDir) return;
17395
- const path = join10(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
17446
+ const path = join12(agentDir, `${channel}${REPLY_BINDING_CLASSIFICATION_COUNTER_SUFFIX}`);
17396
17447
  let counts = {};
17397
17448
  try {
17398
- const parsed = JSON.parse(readFileSync11(path, "utf-8"));
17449
+ const parsed = JSON.parse(readFileSync12(path, "utf-8"));
17399
17450
  if (parsed && typeof parsed === "object") counts = parsed;
17400
17451
  } catch {
17401
17452
  }
@@ -17404,14 +17455,14 @@ function recordChannelMistarget(agentDir, channel, input) {
17404
17455
  counts[DM_CHANNEL_MISTARGET_KEY] = (counts[DM_CHANNEL_MISTARGET_KEY] ?? 0) + 1;
17405
17456
  }
17406
17457
  try {
17407
- writeFileSync9(path, JSON.stringify(counts), { mode: 384 });
17458
+ writeFileSync10(path, JSON.stringify(counts), { mode: 384 });
17408
17459
  } catch {
17409
17460
  }
17410
17461
  }
17411
17462
 
17412
17463
  // src/slack-reply-target-telemetry.ts
17413
- import { readFileSync as readFileSync12, writeFileSync as writeFileSync10 } from "fs";
17414
- import { join as join11 } from "path";
17464
+ import { readFileSync as readFileSync13, writeFileSync as writeFileSync11 } from "fs";
17465
+ import { join as join13 } from "path";
17415
17466
  var REPLY_TARGET_CLASSIFICATION_COUNTER_SUFFIX = "-reply-target-classifications.json";
17416
17467
  function pendingThreadsBucket(n) {
17417
17468
  if (n <= 0) return "0";
@@ -17444,10 +17495,10 @@ function classifyReplyTarget(input) {
17444
17495
  }
17445
17496
  function recordReplyTargetClassification(agentDir, channel, classification) {
17446
17497
  if (!agentDir) return;
17447
- const path = join11(agentDir, `${channel}${REPLY_TARGET_CLASSIFICATION_COUNTER_SUFFIX}`);
17498
+ const path = join13(agentDir, `${channel}${REPLY_TARGET_CLASSIFICATION_COUNTER_SUFFIX}`);
17448
17499
  let counts = {};
17449
17500
  try {
17450
- const parsed = JSON.parse(readFileSync12(path, "utf-8"));
17501
+ const parsed = JSON.parse(readFileSync13(path, "utf-8"));
17451
17502
  if (parsed && typeof parsed === "object") counts = parsed;
17452
17503
  } catch {
17453
17504
  }
@@ -17457,14 +17508,14 @@ function recordReplyTargetClassification(agentDir, channel, classification) {
17457
17508
  );
17458
17509
  counts[key2] = (counts[key2] ?? 0) + 1;
17459
17510
  try {
17460
- writeFileSync10(path, JSON.stringify(counts), { mode: 384 });
17511
+ writeFileSync11(path, JSON.stringify(counts), { mode: 384 });
17461
17512
  } catch {
17462
17513
  }
17463
17514
  }
17464
17515
 
17465
17516
  // src/scheduled-turn-marker.ts
17466
- import { readFileSync as readFileSync13, unlinkSync as unlinkSync4 } from "fs";
17467
- import { join as join12 } from "path";
17517
+ import { readFileSync as readFileSync14, unlinkSync as unlinkSync5 } from "fs";
17518
+ import { join as join14 } from "path";
17468
17519
  var SCHEDULED_TURN_MARKER_FILENAME = ".current-scheduled-turn.json";
17469
17520
  var SCHEDULED_TURN_MAX_AGE_MS = 30 * 60 * 1e3;
17470
17521
  function validateScheduledTurnMarker(raw, now, maxAgeMs = SCHEDULED_TURN_MAX_AGE_MS) {
@@ -17502,7 +17553,7 @@ function readScheduledTurnMarker(agentDir, now = Date.now()) {
17502
17553
  if (!agentDir) return null;
17503
17554
  try {
17504
17555
  const raw = JSON.parse(
17505
- readFileSync13(join12(agentDir, SCHEDULED_TURN_MARKER_FILENAME), "utf8")
17556
+ readFileSync14(join14(agentDir, SCHEDULED_TURN_MARKER_FILENAME), "utf8")
17506
17557
  );
17507
17558
  return validateScheduledTurnMarker(raw, now);
17508
17559
  } catch {
@@ -17512,7 +17563,7 @@ function readScheduledTurnMarker(agentDir, now = Date.now()) {
17512
17563
  function clearScheduledTurnMarker(agentDir) {
17513
17564
  if (!agentDir) return;
17514
17565
  try {
17515
- unlinkSync4(join12(agentDir, SCHEDULED_TURN_MARKER_FILENAME));
17566
+ unlinkSync5(join14(agentDir, SCHEDULED_TURN_MARKER_FILENAME));
17516
17567
  } catch {
17517
17568
  }
17518
17569
  }
@@ -18292,14 +18343,14 @@ async function actuateHostRestart(opts) {
18292
18343
 
18293
18344
  // src/mcp-spawn-lock.ts
18294
18345
  import {
18295
- existsSync as existsSync7,
18296
- mkdirSync as mkdirSync7,
18297
- readFileSync as readFileSync14,
18298
- renameSync as renameSync3,
18299
- unlinkSync as unlinkSync5,
18300
- writeFileSync as writeFileSync11
18346
+ existsSync as existsSync9,
18347
+ mkdirSync as mkdirSync8,
18348
+ readFileSync as readFileSync15,
18349
+ renameSync as renameSync4,
18350
+ unlinkSync as unlinkSync6,
18351
+ writeFileSync as writeFileSync12
18301
18352
  } from "fs";
18302
- import { join as join13 } from "path";
18353
+ import { join as join15 } from "path";
18303
18354
  function defaultIsPidAlive(pid) {
18304
18355
  if (!Number.isFinite(pid) || pid <= 0) return false;
18305
18356
  try {
@@ -18317,7 +18368,7 @@ function acquireMcpSpawnLock(args) {
18317
18368
  const isPidAlive = options.isPidAlive ?? defaultIsPidAlive;
18318
18369
  const selfPid = options.selfPid ?? process.pid;
18319
18370
  const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
18320
- const path = join13(agentDir, basename2);
18371
+ const path = join15(agentDir, basename2);
18321
18372
  const existing = readLockHolder(path);
18322
18373
  if (existing) {
18323
18374
  if (existing.pid === selfPid) {
@@ -18327,11 +18378,11 @@ function acquireMcpSpawnLock(args) {
18327
18378
  return { kind: "blocked", path, holder: existing };
18328
18379
  }
18329
18380
  }
18330
- mkdirSync7(agentDir, { recursive: true, mode: 448 });
18381
+ mkdirSync8(agentDir, { recursive: true, mode: 448 });
18331
18382
  const tmpPath = `${path}.${selfPid}.tmp`;
18332
18383
  const payload = { pid: selfPid, started_at: now() };
18333
- writeFileSync11(tmpPath, JSON.stringify(payload), { mode: 384 });
18334
- renameSync3(tmpPath, path);
18384
+ writeFileSync12(tmpPath, JSON.stringify(payload), { mode: 384 });
18385
+ renameSync4(tmpPath, path);
18335
18386
  return { kind: "acquired", path };
18336
18387
  }
18337
18388
  function releaseMcpSpawnLock(lockPath, opts = {}) {
@@ -18341,14 +18392,14 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
18341
18392
  if (!existing) return;
18342
18393
  if (existing.pid !== selfPid) return;
18343
18394
  try {
18344
- unlinkSync5(lockPath);
18395
+ unlinkSync6(lockPath);
18345
18396
  } catch {
18346
18397
  }
18347
18398
  }
18348
18399
  function readLockHolder(path) {
18349
- if (!existsSync7(path)) return null;
18400
+ if (!existsSync9(path)) return null;
18350
18401
  try {
18351
- const raw = readFileSync14(path, "utf8");
18402
+ const raw = readFileSync15(path, "utf8");
18352
18403
  const parsed = JSON.parse(raw);
18353
18404
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
18354
18405
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -18603,8 +18654,8 @@ var SLACK_TEAM_PEER_USER_IDS = parseTeamPeerUserIdsEnv(
18603
18654
  process.env.SLACK_TEAM_PEER_USER_IDS
18604
18655
  );
18605
18656
  var PEER_HINT_SEEN = /* @__PURE__ */ new Set();
18606
- var SLACK_AGENT_DIR = AGENT_CODE_NAME ? join14(homedir4(), ".augmented", AGENT_CODE_NAME) : null;
18607
- var SLACK_MCP_CONFIG_PATH = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "project", ".mcp.json") : null;
18657
+ var SLACK_AGENT_DIR = AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGENT_CODE_NAME) : null;
18658
+ var SLACK_MCP_CONFIG_PATH = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "project", ".mcp.json") : null;
18608
18659
  var liveAllowedUsersCache = null;
18609
18660
  function readLiveAllowedUsers() {
18610
18661
  if (!SLACK_MCP_CONFIG_PATH) return null;
@@ -18614,7 +18665,7 @@ function readLiveAllowedUsers() {
18614
18665
  return liveAllowedUsersCache.value;
18615
18666
  }
18616
18667
  const value = extractAllowedUsersFromMcpJson(
18617
- readFileSync15(SLACK_MCP_CONFIG_PATH, "utf-8")
18668
+ readFileSync16(SLACK_MCP_CONFIG_PATH, "utf-8")
18618
18669
  );
18619
18670
  if (value === null) return null;
18620
18671
  liveAllowedUsersCache = { mtimeMs, value };
@@ -18635,7 +18686,7 @@ function readLivePingAllowedUsers() {
18635
18686
  return livePingAllowedUsersCache.value;
18636
18687
  }
18637
18688
  const value = extractPingAllowedUsersFromMcpJson(
18638
- readFileSync15(SLACK_MCP_CONFIG_PATH, "utf-8")
18689
+ readFileSync16(SLACK_MCP_CONFIG_PATH, "utf-8")
18639
18690
  );
18640
18691
  if (value === null) return null;
18641
18692
  livePingAllowedUsersCache = { mtimeMs, value };
@@ -18647,14 +18698,16 @@ function readLivePingAllowedUsers() {
18647
18698
  function getEffectivePingAllowedUsers() {
18648
18699
  return readLivePingAllowedUsers() ?? PING_ALLOWED_USERS;
18649
18700
  }
18650
- var SLACK_PENDING_INBOUND_DIR = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-pending-inbound") : null;
18651
- var SLACK_RECOVERY_OUTBOX_DIR = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-recovery-outbox") : null;
18701
+ var SLACK_PENDING_INBOUND_DIR = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-pending-inbound") : null;
18702
+ var SLACK_RECOVERY_OUTBOX_DIR = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-recovery-outbox") : null;
18703
+ var SLACK_RECOVERY_LEDGER_DIR = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, ".agt-slack-recovery-ledger") : null;
18704
+ var SLACK_DELIVERY_LEDGER_DIR = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, ".agt-inbound-delivery-ledger") : null;
18652
18705
  var slackInboundRegistry = createInboundRegistry();
18653
- var SLACK_RESTART_CONFIRM_FILE = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-restart-confirm.json") : null;
18654
- var SLACK_RECENT_DMS_FILE = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-recent-dms.json") : null;
18655
- var SLACK_CHANNEL_ADD_RESTART_FILE = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-channel-add-restart.json") : null;
18706
+ var SLACK_RESTART_CONFIRM_FILE = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-restart-confirm.json") : null;
18707
+ var SLACK_RECENT_DMS_FILE = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-recent-dms.json") : null;
18708
+ var SLACK_CHANNEL_ADD_RESTART_FILE = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-channel-add-restart.json") : null;
18656
18709
  var SLACK_MAX_RECOVERY_ATTEMPTS = 3;
18657
- var SLACK_AVATAR_MARKER_PATH = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-avatar-applied") : null;
18710
+ var SLACK_AVATAR_MARKER_PATH = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-avatar-applied") : null;
18658
18711
  function redactSlackId(id) {
18659
18712
  if (!id) return "<none>";
18660
18713
  return createHash2("sha256").update(id).digest("hex").slice(0, 8);
@@ -18665,7 +18718,7 @@ function safeSlackMarkerName(channel, threadTs, messageTs) {
18665
18718
  }
18666
18719
  function slackPendingInboundPath(channel, threadTs, messageTs) {
18667
18720
  if (!SLACK_PENDING_INBOUND_DIR) return null;
18668
- return join14(SLACK_PENDING_INBOUND_DIR, safeSlackMarkerName(channel, threadTs, messageTs));
18721
+ return join16(SLACK_PENDING_INBOUND_DIR, safeSlackMarkerName(channel, threadTs, messageTs));
18669
18722
  }
18670
18723
  function writeSlackPendingInboundMarker(channel, threadTs, messageTs, undeliverable = false, discretionary = false, payload) {
18671
18724
  const path = slackPendingInboundPath(channel, threadTs, messageTs);
@@ -18687,8 +18740,8 @@ function writeSlackPendingInboundMarker(channel, threadTs, messageTs, undelivera
18687
18740
  ...payload ? { payload } : {}
18688
18741
  };
18689
18742
  try {
18690
- mkdirSync8(SLACK_PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
18691
- writeFileSync12(path, JSON.stringify(marker), { mode: 384 });
18743
+ mkdirSync9(SLACK_PENDING_INBOUND_DIR, { recursive: true, mode: 448 });
18744
+ writeFileSync13(path, JSON.stringify(marker), { mode: 384 });
18692
18745
  } catch (err) {
18693
18746
  process.stderr.write(
18694
18747
  `slack-channel(${AGENT_CODE_NAME}): pending-inbound marker write failed: ${err.message}
@@ -18716,7 +18769,7 @@ function rewriteSlackMarkerInPlace(path, marker) {
18716
18769
  function markSlackMarkerSeenInPlace(fullPath) {
18717
18770
  let marker;
18718
18771
  try {
18719
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
18772
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
18720
18773
  } catch {
18721
18774
  return;
18722
18775
  }
@@ -18730,7 +18783,7 @@ function attachSlackReplayPayload(channel, threadTs, messageTs, payload) {
18730
18783
  if (!path) return;
18731
18784
  let marker;
18732
18785
  try {
18733
- marker = JSON.parse(readFileSync15(path, "utf-8"));
18786
+ marker = JSON.parse(readFileSync16(path, "utf-8"));
18734
18787
  } catch {
18735
18788
  return;
18736
18789
  }
@@ -18739,9 +18792,9 @@ function attachSlackReplayPayload(channel, threadTs, messageTs, payload) {
18739
18792
  }
18740
18793
  function readSlackPendingInboundMarker(channel, threadTs, messageTs) {
18741
18794
  const path = slackPendingInboundPath(channel, threadTs, messageTs);
18742
- if (!path || !existsSync8(path)) return null;
18795
+ if (!path || !existsSync10(path)) return null;
18743
18796
  try {
18744
- return JSON.parse(readFileSync15(path, "utf-8"));
18797
+ return JSON.parse(readFileSync16(path, "utf-8"));
18745
18798
  } catch {
18746
18799
  return null;
18747
18800
  }
@@ -18857,7 +18910,7 @@ function scheduleBusyAck(channel, threadTs, messageTs, isThreadReply, arrivedWhi
18857
18910
  let paneLogFreshAgeMs = null;
18858
18911
  if (SLACK_AGENT_DIR) {
18859
18912
  try {
18860
- const paneMtimeMs = statSync2(join14(SLACK_AGENT_DIR, "pane.log")).mtimeMs;
18913
+ const paneMtimeMs = statSync2(join16(SLACK_AGENT_DIR, "pane.log")).mtimeMs;
18861
18914
  paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
18862
18915
  } catch {
18863
18916
  }
@@ -18890,7 +18943,7 @@ function __resetSlackBusyAckNoticeThrottle() {
18890
18943
  function clearSlackMarkerFileWithHeal(fullPath) {
18891
18944
  let marker = null;
18892
18945
  try {
18893
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
18946
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
18894
18947
  } catch {
18895
18948
  }
18896
18949
  if (marker && decideRecoveryHeal({
@@ -18901,14 +18954,14 @@ function clearSlackMarkerFileWithHeal(fullPath) {
18901
18954
  deleteSlackUndeliverableNotice(undeliverableNoticeConversationKeyFromMarker(marker));
18902
18955
  }
18903
18956
  try {
18904
- if (existsSync8(fullPath)) unlinkSync6(fullPath);
18957
+ if (existsSync10(fullPath)) unlinkSync7(fullPath);
18905
18958
  } catch {
18906
18959
  }
18907
18960
  }
18908
18961
  function markSlackMarkerSeenWithHeal(fullPath) {
18909
18962
  let marker = null;
18910
18963
  try {
18911
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
18964
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
18912
18965
  } catch {
18913
18966
  return;
18914
18967
  }
@@ -18977,17 +19030,17 @@ function slackNextRetryName(filename) {
18977
19030
  async function processSlackRecoveryOutboxFile(filename) {
18978
19031
  if (!SLACK_RECOVERY_OUTBOX_DIR) return;
18979
19032
  if (filename.endsWith(".poison.json") || filename.endsWith(".tmp")) return;
18980
- const fullPath = join14(SLACK_RECOVERY_OUTBOX_DIR, filename);
19033
+ const fullPath = join16(SLACK_RECOVERY_OUTBOX_DIR, filename);
18981
19034
  let payload;
18982
19035
  try {
18983
- payload = JSON.parse(readFileSync15(fullPath, "utf-8"));
19036
+ payload = JSON.parse(readFileSync16(fullPath, "utf-8"));
18984
19037
  } catch (err) {
18985
19038
  process.stderr.write(
18986
19039
  `slack-channel(${AGENT_CODE_NAME}): recovery outbox parse failed (${filename}): ${err.message}
18987
19040
  `
18988
19041
  );
18989
19042
  try {
18990
- renameSync4(fullPath, `${fullPath}.parse-error.poison`);
19043
+ renameSync5(fullPath, `${fullPath}.parse-error.poison`);
18991
19044
  } catch {
18992
19045
  }
18993
19046
  return;
@@ -18997,8 +19050,9 @@ async function processSlackRecoveryOutboxFile(filename) {
18997
19050
  `slack-channel(${AGENT_CODE_NAME}): recovery outbox malformed (${filename}): missing channel or text
18998
19051
  `
18999
19052
  );
19053
+ removeRecoveryLedgerEntry(SLACK_RECOVERY_LEDGER_DIR, payload.marker_name);
19000
19054
  try {
19001
- renameSync4(fullPath, `${fullPath}.malformed.poison`);
19055
+ renameSync5(fullPath, `${fullPath}.malformed.poison`);
19002
19056
  } catch {
19003
19057
  }
19004
19058
  return;
@@ -19024,8 +19078,9 @@ async function processSlackRecoveryOutboxFile(filename) {
19024
19078
  );
19025
19079
  if (decision.action === "suppress") {
19026
19080
  if (payload.thread_ts) clearPendingMessage(payload.channel, payload.thread_ts);
19081
+ removeRecoveryLedgerEntry(SLACK_RECOVERY_LEDGER_DIR, payload.marker_name);
19027
19082
  try {
19028
- unlinkSync6(fullPath);
19083
+ unlinkSync7(fullPath);
19029
19084
  } catch {
19030
19085
  }
19031
19086
  return;
@@ -19072,8 +19127,9 @@ async function processSlackRecoveryOutboxFile(filename) {
19072
19127
  clearTimeout(timeoutId);
19073
19128
  }
19074
19129
  if (sendSucceeded) {
19130
+ removeRecoveryLedgerEntry(SLACK_RECOVERY_LEDGER_DIR, payload.marker_name);
19075
19131
  try {
19076
- unlinkSync6(fullPath);
19132
+ unlinkSync7(fullPath);
19077
19133
  } catch {
19078
19134
  }
19079
19135
  return;
@@ -19081,12 +19137,13 @@ async function processSlackRecoveryOutboxFile(filename) {
19081
19137
  const next = slackNextRetryName(filename);
19082
19138
  if (next) {
19083
19139
  try {
19084
- renameSync4(fullPath, join14(SLACK_RECOVERY_OUTBOX_DIR, next.next));
19140
+ renameSync5(fullPath, join16(SLACK_RECOVERY_OUTBOX_DIR, next.next));
19085
19141
  if (next.attempt >= SLACK_MAX_RECOVERY_ATTEMPTS) {
19086
19142
  process.stderr.write(
19087
19143
  `slack-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
19088
19144
  `
19089
19145
  );
19146
+ removeRecoveryLedgerEntry(SLACK_RECOVERY_LEDGER_DIR, payload.marker_name);
19090
19147
  }
19091
19148
  } catch {
19092
19149
  }
@@ -19111,7 +19168,7 @@ function scanSlackRecoveryRetries() {
19111
19168
  if (!SLACK_RECOVERY_OUTBOX_DIR) return;
19112
19169
  let entries;
19113
19170
  try {
19114
- entries = readdirSync4(SLACK_RECOVERY_OUTBOX_DIR);
19171
+ entries = readdirSync5(SLACK_RECOVERY_OUTBOX_DIR);
19115
19172
  } catch {
19116
19173
  return;
19117
19174
  }
@@ -19120,7 +19177,7 @@ function scanSlackRecoveryRetries() {
19120
19177
  if (!f.includes(".retry-") || f.endsWith(".poison.json")) continue;
19121
19178
  let mtimeMs;
19122
19179
  try {
19123
- mtimeMs = statSync2(join14(SLACK_RECOVERY_OUTBOX_DIR, f)).mtimeMs;
19180
+ mtimeMs = statSync2(join16(SLACK_RECOVERY_OUTBOX_DIR, f)).mtimeMs;
19124
19181
  } catch {
19125
19182
  continue;
19126
19183
  }
@@ -19132,7 +19189,7 @@ function scanSlackRecoveryRetries() {
19132
19189
  function startSlackRecoveryOutboxWatcher() {
19133
19190
  if (!SLACK_RECOVERY_OUTBOX_DIR) return;
19134
19191
  try {
19135
- mkdirSync8(SLACK_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
19192
+ mkdirSync9(SLACK_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
19136
19193
  } catch (err) {
19137
19194
  process.stderr.write(
19138
19195
  `slack-channel(${AGENT_CODE_NAME}): recovery outbox mkdir failed: ${err.message}
@@ -19141,7 +19198,7 @@ function startSlackRecoveryOutboxWatcher() {
19141
19198
  return;
19142
19199
  }
19143
19200
  try {
19144
- for (const f of readdirSync4(SLACK_RECOVERY_OUTBOX_DIR)) {
19201
+ for (const f of readdirSync5(SLACK_RECOVERY_OUTBOX_DIR)) {
19145
19202
  if (isFirstAttemptSlackOutboxFile(f)) void processSlackRecoveryOutboxFile(f);
19146
19203
  }
19147
19204
  } catch {
@@ -19150,7 +19207,7 @@ function startSlackRecoveryOutboxWatcher() {
19150
19207
  const watcher = watch(SLACK_RECOVERY_OUTBOX_DIR, (event, filename) => {
19151
19208
  if (event !== "rename" || !filename) return;
19152
19209
  if (!isFirstAttemptSlackOutboxFile(filename)) return;
19153
- if (existsSync8(join14(SLACK_RECOVERY_OUTBOX_DIR, filename))) {
19210
+ if (existsSync10(join16(SLACK_RECOVERY_OUTBOX_DIR, filename))) {
19154
19211
  void processSlackRecoveryOutboxFile(filename);
19155
19212
  }
19156
19213
  });
@@ -19165,7 +19222,7 @@ function startSlackRecoveryOutboxWatcher() {
19165
19222
  retryTimer.unref?.();
19166
19223
  }
19167
19224
  startSlackRecoveryOutboxWatcher();
19168
- var SLACK_NOTICE_OUTBOX_DIR = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "slack-notice-outbox") : null;
19225
+ var SLACK_NOTICE_OUTBOX_DIR = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "slack-notice-outbox") : null;
19169
19226
  var SLACK_NOTICE_MAX_AGE_MS = 9e4;
19170
19227
  var SLACK_NOTICE_INFLIGHT = /* @__PURE__ */ new Set();
19171
19228
  async function processSlackNoticeOutboxFile(filename) {
@@ -19173,7 +19230,7 @@ async function processSlackNoticeOutboxFile(filename) {
19173
19230
  if (filename.startsWith(".") || filename.endsWith(".tmp") || !filename.endsWith(".json")) return;
19174
19231
  if (SLACK_NOTICE_INFLIGHT.has(filename)) return;
19175
19232
  SLACK_NOTICE_INFLIGHT.add(filename);
19176
- const fullPath = join14(SLACK_NOTICE_OUTBOX_DIR, filename);
19233
+ const fullPath = join16(SLACK_NOTICE_OUTBOX_DIR, filename);
19177
19234
  try {
19178
19235
  let mtimeMs;
19179
19236
  try {
@@ -19183,26 +19240,26 @@ async function processSlackNoticeOutboxFile(filename) {
19183
19240
  }
19184
19241
  if (Date.now() - mtimeMs > SLACK_NOTICE_MAX_AGE_MS) {
19185
19242
  try {
19186
- unlinkSync6(fullPath);
19243
+ unlinkSync7(fullPath);
19187
19244
  } catch {
19188
19245
  }
19189
19246
  return;
19190
19247
  }
19191
19248
  let payload;
19192
19249
  try {
19193
- const parsed = JSON.parse(readFileSync15(fullPath, "utf-8"));
19250
+ const parsed = JSON.parse(readFileSync16(fullPath, "utf-8"));
19194
19251
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
19195
19252
  payload = parsed;
19196
19253
  } catch {
19197
19254
  try {
19198
- unlinkSync6(fullPath);
19255
+ unlinkSync7(fullPath);
19199
19256
  } catch {
19200
19257
  }
19201
19258
  return;
19202
19259
  }
19203
19260
  if (!payload.channel || !payload.text) {
19204
19261
  try {
19205
- unlinkSync6(fullPath);
19262
+ unlinkSync7(fullPath);
19206
19263
  } catch {
19207
19264
  }
19208
19265
  return;
@@ -19213,7 +19270,7 @@ async function processSlackNoticeOutboxFile(filename) {
19213
19270
  defaultValue: false
19214
19271
  })) {
19215
19272
  try {
19216
- unlinkSync6(fullPath);
19273
+ unlinkSync7(fullPath);
19217
19274
  } catch {
19218
19275
  }
19219
19276
  return;
@@ -19254,7 +19311,7 @@ async function processSlackNoticeOutboxFile(filename) {
19254
19311
  clearTimeout(timeoutId);
19255
19312
  }
19256
19313
  try {
19257
- unlinkSync6(fullPath);
19314
+ unlinkSync7(fullPath);
19258
19315
  } catch {
19259
19316
  }
19260
19317
  } finally {
@@ -19264,7 +19321,7 @@ async function processSlackNoticeOutboxFile(filename) {
19264
19321
  function startSlackNoticeOutboxWatcher() {
19265
19322
  if (!SLACK_NOTICE_OUTBOX_DIR) return;
19266
19323
  try {
19267
- mkdirSync8(SLACK_NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
19324
+ mkdirSync9(SLACK_NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
19268
19325
  } catch (err) {
19269
19326
  process.stderr.write(
19270
19327
  `slack-channel(${AGENT_CODE_NAME}): notice outbox mkdir failed: ${err.message}
@@ -19273,13 +19330,13 @@ function startSlackNoticeOutboxWatcher() {
19273
19330
  return;
19274
19331
  }
19275
19332
  try {
19276
- for (const f of readdirSync4(SLACK_NOTICE_OUTBOX_DIR)) void processSlackNoticeOutboxFile(f);
19333
+ for (const f of readdirSync5(SLACK_NOTICE_OUTBOX_DIR)) void processSlackNoticeOutboxFile(f);
19277
19334
  } catch {
19278
19335
  }
19279
19336
  try {
19280
19337
  const watcher = watch(SLACK_NOTICE_OUTBOX_DIR, (event, filename) => {
19281
19338
  if (event !== "rename" || !filename) return;
19282
- if (existsSync8(join14(SLACK_NOTICE_OUTBOX_DIR, filename))) {
19339
+ if (existsSync10(join16(SLACK_NOTICE_OUTBOX_DIR, filename))) {
19283
19340
  void processSlackNoticeOutboxFile(filename);
19284
19341
  }
19285
19342
  });
@@ -19299,10 +19356,10 @@ function trackPendingMessage(channel, threadTs, messageTs, undeliverable = false
19299
19356
  }
19300
19357
  function sweepSlackStaleMarkers(thresholdMs) {
19301
19358
  if (!SLACK_PENDING_INBOUND_DIR) return;
19302
- if (!existsSync8(SLACK_PENDING_INBOUND_DIR)) return;
19359
+ if (!existsSync10(SLACK_PENDING_INBOUND_DIR)) return;
19303
19360
  let filenames;
19304
19361
  try {
19305
- filenames = readdirSync4(SLACK_PENDING_INBOUND_DIR);
19362
+ filenames = readdirSync5(SLACK_PENDING_INBOUND_DIR);
19306
19363
  } catch (err) {
19307
19364
  process.stderr.write(
19308
19365
  `slack-channel(${AGENT_CODE_NAME}): stale-marker readdir failed: ${err.message}
@@ -19315,17 +19372,17 @@ function sweepSlackStaleMarkers(thresholdMs) {
19315
19372
  for (const filename of filenames) {
19316
19373
  if (!filename.endsWith(".json")) continue;
19317
19374
  if (filename.endsWith(".tmp")) continue;
19318
- const fullPath = join14(SLACK_PENDING_INBOUND_DIR, filename);
19375
+ const fullPath = join16(SLACK_PENDING_INBOUND_DIR, filename);
19319
19376
  let marker;
19320
19377
  try {
19321
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
19378
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
19322
19379
  } catch (err) {
19323
19380
  process.stderr.write(
19324
19381
  `slack-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactSlackId(filename)}: ${err.message}
19325
19382
  `
19326
19383
  );
19327
19384
  try {
19328
- unlinkSync6(fullPath);
19385
+ unlinkSync7(fullPath);
19329
19386
  } catch {
19330
19387
  }
19331
19388
  cleared++;
@@ -19344,7 +19401,7 @@ function sweepSlackStaleMarkers(thresholdMs) {
19344
19401
  );
19345
19402
  }
19346
19403
  try {
19347
- unlinkSync6(fullPath);
19404
+ unlinkSync7(fullPath);
19348
19405
  } catch {
19349
19406
  }
19350
19407
  cleared++;
@@ -19368,13 +19425,13 @@ var slackOrphanSweepTimer = setInterval(() => {
19368
19425
  checkSlackWatchdogGiveUpNotice();
19369
19426
  }, orphanSweepIntervalMs());
19370
19427
  slackOrphanSweepTimer.unref?.();
19371
- var SLACK_PROGRESS_HEARTBEAT_PATH = SLACK_AGENT_DIR ? join14(SLACK_AGENT_DIR, "channel-progress-heartbeat.json") : null;
19428
+ var SLACK_PROGRESS_HEARTBEAT_PATH = SLACK_AGENT_DIR ? join16(SLACK_AGENT_DIR, "channel-progress-heartbeat.json") : null;
19372
19429
  var slackTrackedProgress = null;
19373
19430
  var slackProgressTickRunning = false;
19374
19431
  function readSlackProgressHeartbeat() {
19375
- if (!SLACK_PROGRESS_HEARTBEAT_PATH || !existsSync8(SLACK_PROGRESS_HEARTBEAT_PATH)) return null;
19432
+ if (!SLACK_PROGRESS_HEARTBEAT_PATH || !existsSync10(SLACK_PROGRESS_HEARTBEAT_PATH)) return null;
19376
19433
  try {
19377
- return parseProgressHeartbeat(readFileSync15(SLACK_PROGRESS_HEARTBEAT_PATH, "utf-8"));
19434
+ return parseProgressHeartbeat(readFileSync16(SLACK_PROGRESS_HEARTBEAT_PATH, "utf-8"));
19378
19435
  } catch {
19379
19436
  return null;
19380
19437
  }
@@ -19383,25 +19440,25 @@ function seedSlackProgressHeartbeat() {
19383
19440
  if (!SLACK_PROGRESS_HEARTBEAT_PATH) return;
19384
19441
  const tmp = `${SLACK_PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
19385
19442
  try {
19386
- writeFileSync12(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
19387
- renameSync4(tmp, SLACK_PROGRESS_HEARTBEAT_PATH);
19443
+ writeFileSync13(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
19444
+ renameSync5(tmp, SLACK_PROGRESS_HEARTBEAT_PATH);
19388
19445
  } catch {
19389
19446
  try {
19390
- unlinkSync6(tmp);
19447
+ unlinkSync7(tmp);
19391
19448
  } catch {
19392
19449
  }
19393
19450
  }
19394
19451
  }
19395
19452
  function findSlackProgressTarget() {
19396
- if (!SLACK_PENDING_INBOUND_DIR || !existsSync8(SLACK_PENDING_INBOUND_DIR)) return null;
19453
+ if (!SLACK_PENDING_INBOUND_DIR || !existsSync10(SLACK_PENDING_INBOUND_DIR)) return null;
19397
19454
  let best = null;
19398
19455
  let bestMs = Infinity;
19399
19456
  try {
19400
- for (const name of readdirSync4(SLACK_PENDING_INBOUND_DIR)) {
19457
+ for (const name of readdirSync5(SLACK_PENDING_INBOUND_DIR)) {
19401
19458
  if (!name.endsWith(".json")) continue;
19402
19459
  let m;
19403
19460
  try {
19404
- m = JSON.parse(readFileSync15(join14(SLACK_PENDING_INBOUND_DIR, name), "utf-8"));
19461
+ m = JSON.parse(readFileSync16(join16(SLACK_PENDING_INBOUND_DIR, name), "utf-8"));
19405
19462
  } catch {
19406
19463
  continue;
19407
19464
  }
@@ -19545,14 +19602,14 @@ if (BOT_TOKEN && SLACK_PENDING_INBOUND_DIR) {
19545
19602
  }
19546
19603
  var lastSlackGiveUpHandledAtMs = null;
19547
19604
  function listPendingSlackConversations() {
19548
- if (!SLACK_PENDING_INBOUND_DIR || !existsSync8(SLACK_PENDING_INBOUND_DIR)) return [];
19605
+ if (!SLACK_PENDING_INBOUND_DIR || !existsSync10(SLACK_PENDING_INBOUND_DIR)) return [];
19549
19606
  const byKey = /* @__PURE__ */ new Map();
19550
19607
  try {
19551
- for (const name of readdirSync4(SLACK_PENDING_INBOUND_DIR)) {
19608
+ for (const name of readdirSync5(SLACK_PENDING_INBOUND_DIR)) {
19552
19609
  if (!name.endsWith(".json")) continue;
19553
19610
  try {
19554
19611
  const marker = JSON.parse(
19555
- readFileSync15(join14(SLACK_PENDING_INBOUND_DIR, name), "utf8")
19612
+ readFileSync16(join16(SLACK_PENDING_INBOUND_DIR, name), "utf8")
19556
19613
  );
19557
19614
  if (typeof marker.channel !== "string" || !marker.channel) continue;
19558
19615
  if (typeof marker.thread_ts !== "string" || !marker.thread_ts) continue;
@@ -19604,7 +19661,7 @@ function postSlackWatchdogGiveUpNotice(channel, threadTs, isThreadReply, reason)
19604
19661
  }
19605
19662
  function checkSlackWatchdogGiveUpNotice() {
19606
19663
  if (!SLACK_AGENT_DIR) return;
19607
- const signal = readGiveUpSignal(join14(SLACK_AGENT_DIR, GIVE_UP_SIGNAL_FILENAME));
19664
+ const signal = readGiveUpSignal(join16(SLACK_AGENT_DIR, GIVE_UP_SIGNAL_FILENAME));
19608
19665
  const signalAtMs = signal?.atMs ?? null;
19609
19666
  const act = decideGiveUpNotice({
19610
19667
  signalAtMs,
@@ -19638,10 +19695,10 @@ async function notifyStrandedInboundsOnFirstConnect() {
19638
19695
  strandedInboundNoticeInFlight = true;
19639
19696
  let hadFailure = false;
19640
19697
  try {
19641
- if (!SLACK_PENDING_INBOUND_DIR || !existsSync8(SLACK_PENDING_INBOUND_DIR)) return;
19698
+ if (!SLACK_PENDING_INBOUND_DIR || !existsSync10(SLACK_PENDING_INBOUND_DIR)) return;
19642
19699
  let filenames;
19643
19700
  try {
19644
- filenames = readdirSync4(SLACK_PENDING_INBOUND_DIR);
19701
+ filenames = readdirSync5(SLACK_PENDING_INBOUND_DIR);
19645
19702
  } catch {
19646
19703
  hadFailure = true;
19647
19704
  return;
@@ -19651,10 +19708,10 @@ async function notifyStrandedInboundsOnFirstConnect() {
19651
19708
  let notified = 0;
19652
19709
  for (const filename of filenames) {
19653
19710
  if (!filename.endsWith(".json")) continue;
19654
- const fullPath = join14(SLACK_PENDING_INBOUND_DIR, filename);
19711
+ const fullPath = join16(SLACK_PENDING_INBOUND_DIR, filename);
19655
19712
  let marker;
19656
19713
  try {
19657
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
19714
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
19658
19715
  } catch {
19659
19716
  continue;
19660
19717
  }
@@ -19667,7 +19724,7 @@ async function notifyStrandedInboundsOnFirstConnect() {
19667
19724
  const key2 = `${channel}__${thread_ts}`;
19668
19725
  if (seen.has(key2)) {
19669
19726
  try {
19670
- unlinkSync6(fullPath);
19727
+ unlinkSync7(fullPath);
19671
19728
  } catch {
19672
19729
  }
19673
19730
  continue;
@@ -19681,7 +19738,7 @@ async function notifyStrandedInboundsOnFirstConnect() {
19681
19738
  if (res.ok) {
19682
19739
  notified += 1;
19683
19740
  try {
19684
- unlinkSync6(fullPath);
19741
+ unlinkSync7(fullPath);
19685
19742
  } catch {
19686
19743
  }
19687
19744
  } else {
@@ -19825,7 +19882,7 @@ function noteThreadActivityByMessageTs(channel, messageTs) {
19825
19882
  markSeenAllSlackPendingMarkersForThread2(channel, messageTs);
19826
19883
  markSeenSlackPendingMarkerByMessageTs2(channel, messageTs);
19827
19884
  }
19828
- var RESTART_FLAGS_DIR = join14(homedir4(), ".augmented", "restart-flags");
19885
+ var RESTART_FLAGS_DIR = join16(homedir4(), ".augmented", "restart-flags");
19829
19886
  function actuateHostRestartSlack() {
19830
19887
  return actuateHostRestart({
19831
19888
  agtHost: AGT_HOST,
@@ -20427,10 +20484,10 @@ async function handleSlashCommandEnvelope(payload) {
20427
20484
  writeSlackRestartConfirm(confirmReply, payload.user_name);
20428
20485
  } else {
20429
20486
  writeSlackRestartConfirm(confirmReply, payload.user_name);
20430
- if (!existsSync8(RESTART_FLAGS_DIR)) {
20431
- mkdirSync8(RESTART_FLAGS_DIR, { recursive: true });
20487
+ if (!existsSync10(RESTART_FLAGS_DIR)) {
20488
+ mkdirSync9(RESTART_FLAGS_DIR, { recursive: true });
20432
20489
  }
20433
- const flagPath = join14(RESTART_FLAGS_DIR, `${codeName}.flag`);
20490
+ const flagPath = join16(RESTART_FLAGS_DIR, `${codeName}.flag`);
20434
20491
  const flag = {
20435
20492
  codeName,
20436
20493
  source: "slack",
@@ -20438,8 +20495,8 @@ async function handleSlashCommandEnvelope(payload) {
20438
20495
  reply: confirmReply
20439
20496
  };
20440
20497
  const tmpPath = `${flagPath}.${process.pid}.${randomUUID2()}.tmp`;
20441
- writeFileSync12(tmpPath, JSON.stringify(flag) + "\n", "utf8");
20442
- renameSync4(tmpPath, flagPath);
20498
+ writeFileSync13(tmpPath, JSON.stringify(flag) + "\n", "utf8");
20499
+ renameSync5(tmpPath, flagPath);
20443
20500
  }
20444
20501
  process.stderr.write(
20445
20502
  `slack-channel(${codeName}): /restart slash-command queued from channel ${hashChannelId(payload.channel_id)}
@@ -20570,10 +20627,10 @@ async function handleRestartCommand(opts) {
20570
20627
  writeSlackRestartConfirm(confirmReply, opts.requesterName);
20571
20628
  } else {
20572
20629
  writeSlackRestartConfirm(confirmReply, opts.requesterName);
20573
- if (!existsSync8(RESTART_FLAGS_DIR)) {
20574
- mkdirSync8(RESTART_FLAGS_DIR, { recursive: true });
20630
+ if (!existsSync10(RESTART_FLAGS_DIR)) {
20631
+ mkdirSync9(RESTART_FLAGS_DIR, { recursive: true });
20575
20632
  }
20576
- const flagPath = join14(RESTART_FLAGS_DIR, `${codeName}.flag`);
20633
+ const flagPath = join16(RESTART_FLAGS_DIR, `${codeName}.flag`);
20577
20634
  const flag = {
20578
20635
  codeName,
20579
20636
  source: "slack",
@@ -20581,8 +20638,8 @@ async function handleRestartCommand(opts) {
20581
20638
  reply: { ...confirmReply, message_ts: opts.ts }
20582
20639
  };
20583
20640
  const tmpPath = `${flagPath}.${process.pid}.${randomUUID2()}.tmp`;
20584
- writeFileSync12(tmpPath, JSON.stringify(flag) + "\n", "utf8");
20585
- renameSync4(tmpPath, flagPath);
20641
+ writeFileSync13(tmpPath, JSON.stringify(flag) + "\n", "utf8");
20642
+ renameSync5(tmpPath, flagPath);
20586
20643
  }
20587
20644
  process.stderr.write(
20588
20645
  `slack-channel(${codeName}): /restart queued from channel ${hashChannelId(opts.channel)}
@@ -20686,7 +20743,7 @@ var THREAD_STORE_TTL_DAYS = parseTtlDays(process.env.SLACK_THREAD_FOLLOW_TTL_DAY
20686
20743
  var threadPersister = null;
20687
20744
  function resolveThreadStorePath() {
20688
20745
  if (!AGENT_CODE_NAME) return null;
20689
- return join14(homedir4(), ".augmented", AGENT_CODE_NAME, "slack-tracked-threads.json");
20746
+ return join16(homedir4(), ".augmented", AGENT_CODE_NAME, "slack-tracked-threads.json");
20690
20747
  }
20691
20748
  function parseTtlDays(raw) {
20692
20749
  if (!raw) return void 0;
@@ -20725,9 +20782,9 @@ if (!BOT_TOKEN || !APP_TOKEN) {
20725
20782
  var slackStderrLogStream = null;
20726
20783
  if (AGENT_CODE_NAME) {
20727
20784
  try {
20728
- const logDir = join14(homedir4(), ".augmented", AGENT_CODE_NAME);
20729
- mkdirSync8(logDir, { recursive: true });
20730
- slackStderrLogStream = createWriteStream(join14(logDir, "slack-channel-stderr.log"), {
20785
+ const logDir = join16(homedir4(), ".augmented", AGENT_CODE_NAME);
20786
+ mkdirSync9(logDir, { recursive: true });
20787
+ slackStderrLogStream = createWriteStream(join16(logDir, "slack-channel-stderr.log"), {
20731
20788
  flags: "a",
20732
20789
  mode: 384
20733
20790
  });
@@ -21305,6 +21362,14 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
21305
21362
  };
21306
21363
  }
21307
21364
  settlePendingMarker();
21365
+ if (effectiveThreadTs) {
21366
+ writeInboundDeliveryLedgerEntry(SLACK_DELIVERY_LEDGER_DIR, {
21367
+ inbound_id: slackInboundId(effectiveChannel, effectiveThreadTs, effectiveMessageTs ?? ""),
21368
+ source: "slack",
21369
+ conv_key: effectiveThreadTs,
21370
+ delivered_at: (/* @__PURE__ */ new Date()).toISOString()
21371
+ });
21372
+ }
21308
21373
  recordReply(effectiveChannel, throttleKey, throttleNow, throttleCfg);
21309
21374
  recordActivity("reply");
21310
21375
  if (THREAD_AUTO_FOLLOW !== "off") {
@@ -21530,7 +21595,7 @@ ${result.formatted}` : "No messages in range, or the bot is not a member of this
21530
21595
  };
21531
21596
  }
21532
21597
  size = stat2.size;
21533
- bytes = readFileSync15(resolvedPath);
21598
+ bytes = readFileSync16(resolvedPath);
21534
21599
  } catch (err) {
21535
21600
  return {
21536
21601
  content: [{ type: "text", text: `Failed to read file: ${err.message}` }],
@@ -22243,8 +22308,8 @@ async function downloadSlackFile(fileId, codeName) {
22243
22308
  if (!isPathInside(savedPath, dir)) {
22244
22309
  throw new Error(`refusing to write ${savedPath} outside ${dir}`);
22245
22310
  }
22246
- mkdirSync8(dir, { recursive: true });
22247
- writeFileSync12(savedPath, bytes, { mode: 384 });
22311
+ mkdirSync9(dir, { recursive: true });
22312
+ writeFileSync13(savedPath, bytes, { mode: 384 });
22248
22313
  try {
22249
22314
  chmodSync(savedPath, 384);
22250
22315
  } catch {
@@ -22299,13 +22364,13 @@ await mcp.connect(new StdioServerTransport());
22299
22364
  var SLACK_REPLAY_SCAN_INTERVAL_MS = 6e4;
22300
22365
  async function replayPendingSlackMarkers() {
22301
22366
  if (!channelReplayEnabled()) return;
22302
- if (!SLACK_PENDING_INBOUND_DIR || !existsSync8(SLACK_PENDING_INBOUND_DIR)) return;
22367
+ if (!SLACK_PENDING_INBOUND_DIR || !existsSync10(SLACK_PENDING_INBOUND_DIR)) return;
22303
22368
  const probe = process.env.TMUX && AGENT_CODE_NAME ? probeAgentSessionCached(AGENT_CODE_NAME) : { tmux: "unknown", claude: "unknown" };
22304
22369
  const sessionAlive = probe.tmux === "alive" && probe.claude === "alive";
22305
22370
  if (!sessionAlive) return;
22306
22371
  let filenames;
22307
22372
  try {
22308
- filenames = readdirSync4(SLACK_PENDING_INBOUND_DIR);
22373
+ filenames = readdirSync5(SLACK_PENDING_INBOUND_DIR);
22309
22374
  } catch {
22310
22375
  return;
22311
22376
  }
@@ -22313,7 +22378,7 @@ async function replayPendingSlackMarkers() {
22313
22378
  let paneFreshAgeMs = null;
22314
22379
  if (SLACK_AGENT_DIR) {
22315
22380
  try {
22316
- paneFreshAgeMs = Math.max(0, now - statSync2(join14(SLACK_AGENT_DIR, "pane.log")).mtimeMs);
22381
+ paneFreshAgeMs = Math.max(0, now - statSync2(join16(SLACK_AGENT_DIR, "pane.log")).mtimeMs);
22317
22382
  } catch {
22318
22383
  }
22319
22384
  }
@@ -22321,10 +22386,10 @@ async function replayPendingSlackMarkers() {
22321
22386
  const entries = [];
22322
22387
  for (const name of filenames) {
22323
22388
  if (!name.endsWith(".json") || name.endsWith(".tmp")) continue;
22324
- const fullPath = join14(SLACK_PENDING_INBOUND_DIR, name);
22389
+ const fullPath = join16(SLACK_PENDING_INBOUND_DIR, name);
22325
22390
  let marker;
22326
22391
  try {
22327
- marker = JSON.parse(readFileSync15(fullPath, "utf-8"));
22392
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
22328
22393
  } catch {
22329
22394
  continue;
22330
22395
  }
@@ -22334,6 +22399,7 @@ async function replayPendingSlackMarkers() {
22334
22399
  }
22335
22400
  entries.sort((a, b) => b.ageMs - a.ageMs);
22336
22401
  for (const { path, marker, ageMs } of entries) {
22402
+ if (recoveryLedgerEntryExists(SLACK_RECOVERY_LEDGER_DIR, basename(path))) continue;
22337
22403
  if (!shouldReplayMarker({
22338
22404
  enabled: true,
22339
22405
  hasPayload: Boolean(marker.payload),
@@ -22881,7 +22947,7 @@ async function connectSocketMode() {
22881
22947
  let paneLogFreshAgeMs = null;
22882
22948
  if (SLACK_AGENT_DIR) {
22883
22949
  try {
22884
- const paneMtimeMs = statSync2(join14(SLACK_AGENT_DIR, "pane.log")).mtimeMs;
22950
+ const paneMtimeMs = statSync2(join16(SLACK_AGENT_DIR, "pane.log")).mtimeMs;
22885
22951
  paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
22886
22952
  } catch {
22887
22953
  }