@integrity-labs/agt-cli 0.28.1087 → 0.28.1089

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.
@@ -18867,7 +18867,7 @@ var require_filters = __commonJS({
18867
18867
  return r.copySafeness(str, res);
18868
18868
  }
18869
18869
  _exports.indent = indent;
18870
- function join17(arr, del, attr) {
18870
+ function join18(arr, del, attr) {
18871
18871
  del = del || "";
18872
18872
  if (attr) {
18873
18873
  arr = lib.map(arr, function(v) {
@@ -18876,7 +18876,7 @@ var require_filters = __commonJS({
18876
18876
  }
18877
18877
  return arr.join(del);
18878
18878
  }
18879
- _exports.join = join17;
18879
+ _exports.join = join18;
18880
18880
  function last(arr) {
18881
18881
  return arr[arr.length - 1];
18882
18882
  }
@@ -20042,9 +20042,9 @@ var require_handler = __commonJS({
20042
20042
  if (this.fsw.closed) {
20043
20043
  return;
20044
20044
  }
20045
- const dirname3 = sysPath.dirname(file);
20045
+ const dirname4 = sysPath.dirname(file);
20046
20046
  const basename = sysPath.basename(file);
20047
- const parent = this.fsw._getWatchedDir(dirname3);
20047
+ const parent = this.fsw._getWatchedDir(dirname4);
20048
20048
  let prevStats = stats;
20049
20049
  if (parent.has(basename))
20050
20050
  return;
@@ -20071,7 +20071,7 @@ var require_handler = __commonJS({
20071
20071
  prevStats = newStats2;
20072
20072
  }
20073
20073
  } catch (error2) {
20074
- this.fsw._remove(dirname3, basename);
20074
+ this.fsw._remove(dirname4, basename);
20075
20075
  }
20076
20076
  } else if (parent.has(basename)) {
20077
20077
  const at = newStats.atimeMs;
@@ -39375,6 +39375,9 @@ function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX
39375
39375
  sender_id: marker.sender_id,
39376
39376
  ...marker.sender_name ? { sender_name: marker.sender_name } : {},
39377
39377
  ...marker.channel_ref ? { channel_ref: marker.channel_ref } : {},
39378
+ ...marker.chat_kind ? { chat_kind: marker.chat_kind } : {},
39379
+ ...marker.chat_id ? { chat_id: marker.chat_id } : {},
39380
+ ...marker.unattributed ? { unattributed: true } : {},
39378
39381
  ts: marker.ts
39379
39382
  });
39380
39383
  kept.sort((a, b) => b.ts - a.ts);
@@ -39389,7 +39392,7 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
39389
39392
  } catch {
39390
39393
  }
39391
39394
  const next = foldTurnInitiatorLedger(existing, marker);
39392
- const tmp = `${ledgerFile}.tmp`;
39395
+ const tmp = `${ledgerFile}.${process.pid}.${Date.now()}.tmp`;
39393
39396
  writeFileSync2(tmp, JSON.stringify(next), "utf8");
39394
39397
  renameSync2(tmp, ledgerFile);
39395
39398
  }
@@ -39410,30 +39413,103 @@ function writeTurnInitiatorMarker(input) {
39410
39413
  }
39411
39414
  }
39412
39415
 
39416
+ // src/turn-context.ts
39417
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync5 } from "fs";
39418
+ import { homedir } from "os";
39419
+ import { dirname as dirname3, join as join6 } from "path";
39420
+
39421
+ // ../core/dist/provisioning/frameworks/claudecode/agent-dir-alias.js
39422
+ import { isAbsolute, join as join4, relative, sep } from "path";
39423
+ var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
39424
+ var VALID_AGENT_ID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
39425
+ var INITIATOR_BASENAME = ".current-turn-initiator.json";
39426
+ function isSafeAgentSegment(segment) {
39427
+ return VALID_CODE_NAME.test(segment) || VALID_AGENT_ID.test(segment);
39428
+ }
39429
+ function initiatorDirSegment(initiatorFile, homeDir) {
39430
+ const rel = relative(join4(homeDir, ".augmented"), initiatorFile);
39431
+ if (!rel || isAbsolute(rel))
39432
+ return null;
39433
+ const parts = rel.split(sep);
39434
+ if (parts.length !== 2 || parts[1] !== INITIATOR_BASENAME)
39435
+ return null;
39436
+ const segment = parts[0];
39437
+ if (segment === void 0)
39438
+ return null;
39439
+ return isSafeAgentSegment(segment) ? segment : null;
39440
+ }
39441
+ function resolveAgentDirAlias(input) {
39442
+ const { codeName, turnInitiatorFile, agentId, homeDir } = input;
39443
+ const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
39444
+ if (codeNameTrimmed && VALID_CODE_NAME.test(codeNameTrimmed)) {
39445
+ return join4(homeDir, ".augmented", codeNameTrimmed);
39446
+ }
39447
+ const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
39448
+ if (initiator) {
39449
+ const segment = initiatorDirSegment(initiator, homeDir);
39450
+ if (segment)
39451
+ return join4(homeDir, ".augmented", segment);
39452
+ }
39453
+ const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
39454
+ if (agentIdTrimmed && VALID_AGENT_ID.test(agentIdTrimmed)) {
39455
+ return join4(homeDir, ".augmented", agentIdTrimmed);
39456
+ }
39457
+ return null;
39458
+ }
39459
+
39413
39460
  // src/scheduled-turn-marker.ts
39414
39461
  import { readFileSync as readFileSync4, unlinkSync } from "fs";
39415
- import { join as join4 } from "path";
39462
+ import { join as join5 } from "path";
39416
39463
  var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
39417
39464
  var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
39418
39465
  function clearScheduledTurnMarker(agentDir) {
39419
39466
  if (!agentDir) return;
39420
39467
  try {
39421
- unlinkSync(join4(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
39468
+ unlinkSync(join5(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
39422
39469
  } catch {
39423
39470
  }
39424
39471
  }
39425
39472
 
39473
+ // src/turn-context.ts
39474
+ var TURN_INITIATOR_MARKER_FILENAME = ".current-turn-initiator.json";
39475
+ function writeUnattributedTurnMarker(channel, opts = {}) {
39476
+ try {
39477
+ const file = resolveTurnInitiatorFile(opts.env ?? process.env, opts.home ?? homedir());
39478
+ if (!file) return;
39479
+ mkdirSync3(dirname3(file), { recursive: true });
39480
+ updateTurnInitiatorLedger(file, {
39481
+ channel,
39482
+ sender_id: "",
39483
+ channel_ref: "unattributed",
39484
+ unattributed: true,
39485
+ ts: opts.now ?? Date.now()
39486
+ });
39487
+ } catch {
39488
+ }
39489
+ }
39490
+ function resolveTurnInitiatorFile(env2 = process.env, home = homedir()) {
39491
+ const injected = env2["AGT_TURN_INITIATOR_FILE"]?.trim();
39492
+ if (injected) return injected;
39493
+ const dir = resolveAgentDirAlias({
39494
+ codeName: env2["AGT_AGENT_CODE_NAME"],
39495
+ agentId: env2["AGT_AGENT_ID"],
39496
+ turnInitiatorFile: null,
39497
+ homeDir: home
39498
+ });
39499
+ return dir ? join6(dir, TURN_INITIATOR_MARKER_FILENAME) : null;
39500
+ }
39501
+
39426
39502
  // src/direct-chat-pending-inbound.ts
39427
39503
  import {
39428
39504
  existsSync as existsSync2,
39429
- mkdirSync as mkdirSync3,
39505
+ mkdirSync as mkdirSync4,
39430
39506
  readdirSync,
39431
- readFileSync as readFileSync5,
39507
+ readFileSync as readFileSync6,
39432
39508
  renameSync as renameSync3,
39433
39509
  unlinkSync as unlinkSync2,
39434
39510
  writeFileSync as writeFileSync3
39435
39511
  } from "fs";
39436
- import { join as join5 } from "path";
39512
+ import { join as join7 } from "path";
39437
39513
  function hexEncodeSegment(value) {
39438
39514
  return Buffer.from(value, "utf8").toString("hex");
39439
39515
  }
@@ -39452,7 +39528,7 @@ function directChatInboundId(sessionId, messageId) {
39452
39528
  function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
39453
39529
  if (!dir || !sessionId || !messageId) return;
39454
39530
  try {
39455
- mkdirSync3(dir, { recursive: true });
39531
+ mkdirSync4(dir, { recursive: true });
39456
39532
  const marker = {
39457
39533
  channel: "direct-chat",
39458
39534
  session_id: sessionId,
@@ -39460,7 +39536,7 @@ function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
39460
39536
  received_at: (/* @__PURE__ */ new Date()).toISOString(),
39461
39537
  inbound_id: directChatInboundId(sessionId, messageId)
39462
39538
  };
39463
- const final = join5(dir, directChatMarkerName(sessionId, messageId));
39539
+ const final = join7(dir, directChatMarkerName(sessionId, messageId));
39464
39540
  const tmp = `${final}.tmp`;
39465
39541
  writeFileSync3(tmp, JSON.stringify(marker), "utf8");
39466
39542
  renameSync3(tmp, final);
@@ -39479,15 +39555,15 @@ function clearDirectChatPendingMarkersForSession(dir, sessionId, op = defaultCle
39479
39555
  }
39480
39556
  for (const name of names) {
39481
39557
  if (!name.startsWith(prefix) || !name.endsWith(".json")) continue;
39482
- op(join5(dir, name));
39558
+ op(join7(dir, name));
39483
39559
  cleared += 1;
39484
39560
  }
39485
39561
  return cleared;
39486
39562
  }
39487
- function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) => readFileSync5(path, "utf8")) {
39563
+ function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) => readFileSync6(path, "utf8")) {
39488
39564
  if (!dir || !sessionId || !messageId) return null;
39489
39565
  try {
39490
- const raw = readFileImpl(join5(dir, directChatMarkerName(sessionId, messageId)));
39566
+ const raw = readFileImpl(join7(dir, directChatMarkerName(sessionId, messageId)));
39491
39567
  return JSON.parse(raw);
39492
39568
  } catch {
39493
39569
  return null;
@@ -39510,7 +39586,7 @@ function sweepAgedDirectChatMarkers(dir, deps) {
39510
39586
  }
39511
39587
  for (const name of names) {
39512
39588
  if (!name.endsWith(".json") || name.startsWith(".")) continue;
39513
- const full = join5(dir, name);
39589
+ const full = join7(dir, name);
39514
39590
  let marker;
39515
39591
  try {
39516
39592
  marker = JSON.parse(deps.readFile(full));
@@ -39609,17 +39685,17 @@ async function consumeDirectChatRecoveryFile(fullPath, filename, deps) {
39609
39685
  }
39610
39686
 
39611
39687
  // src/inbound-delivery-ledger.ts
39612
- import { existsSync as existsSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync6, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
39613
- import { join as join6 } from "path";
39688
+ import { existsSync as existsSync3, mkdirSync as mkdirSync5, readdirSync as readdirSync2, readFileSync as readFileSync7, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
39689
+ import { join as join8 } from "path";
39614
39690
  function safeInboundId(inboundId) {
39615
39691
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
39616
39692
  }
39617
39693
  var defaultDeps = {
39618
- mkdir: (dir) => mkdirSync4(dir, { recursive: true }),
39694
+ mkdir: (dir) => mkdirSync5(dir, { recursive: true }),
39619
39695
  writeFile: (path, data) => writeFileSync4(path, data, "utf8"),
39620
39696
  rename: (from, to) => renameSync4(from, to),
39621
39697
  readdir: (dir) => readdirSync2(dir),
39622
- readFile: (path) => readFileSync6(path, "utf8"),
39698
+ readFile: (path) => readFileSync7(path, "utf8"),
39623
39699
  exists: (path) => existsSync3(path)
39624
39700
  };
39625
39701
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
@@ -39628,7 +39704,7 @@ function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
39628
39704
  if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return;
39629
39705
  try {
39630
39706
  deps.mkdir(dir);
39631
- const final = join6(dir, `${safe}.json`);
39707
+ const final = join8(dir, `${safe}.json`);
39632
39708
  const tmp = `${final}.tmp`;
39633
39709
  deps.writeFile(tmp, JSON.stringify(record2));
39634
39710
  deps.rename(tmp, final);
@@ -39640,22 +39716,22 @@ function inboundDeliveryLedgerHas(dir, inboundId, deps = defaultDeps) {
39640
39716
  const safe = safeInboundId(inboundId);
39641
39717
  if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return false;
39642
39718
  try {
39643
- return deps.exists(join6(dir, `${safe}.json`));
39719
+ return deps.exists(join8(dir, `${safe}.json`));
39644
39720
  } catch {
39645
39721
  return false;
39646
39722
  }
39647
39723
  }
39648
39724
 
39649
39725
  // src/ack-reaction.ts
39650
- import { readdirSync as readdirSync3, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "fs";
39651
- import { join as join8 } from "path";
39726
+ import { readdirSync as readdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
39727
+ import { join as join10 } from "path";
39652
39728
 
39653
39729
  // src/flags-cache-read.ts
39654
- import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
39655
- import { homedir } from "os";
39656
- import { join as join7 } from "path";
39730
+ import { existsSync as existsSync4, readFileSync as readFileSync8 } from "fs";
39731
+ import { homedir as homedir2 } from "os";
39732
+ import { join as join9 } from "path";
39657
39733
  function defaultFlagsCachePath() {
39658
- return join7(homedir(), ".augmented", "flags-cache.json");
39734
+ return join9(homedir2(), ".augmented", "flags-cache.json");
39659
39735
  }
39660
39736
  function envBoolean(raw) {
39661
39737
  if (raw === void 0) return void 0;
@@ -39668,7 +39744,7 @@ function envBoolean(raw) {
39668
39744
  function cachedBoolean(key, path) {
39669
39745
  try {
39670
39746
  if (!existsSync4(path)) return void 0;
39671
- const parsed = JSON.parse(readFileSync7(path, "utf8"));
39747
+ const parsed = JSON.parse(readFileSync8(path, "utf8"));
39672
39748
  if (!parsed || typeof parsed !== "object") return void 0;
39673
39749
  const flags = parsed.flags;
39674
39750
  if (!flags || typeof flags !== "object") return void 0;
@@ -39749,7 +39825,7 @@ function undeliverableNoticeTextForRepeat(i) {
39749
39825
  }
39750
39826
  return null;
39751
39827
  }
39752
- function channelInboundGateOpen(readFile = (p2) => readFileSync8(p2, "utf-8")) {
39828
+ function channelInboundGateOpen(readFile = (p2) => readFileSync9(p2, "utf-8")) {
39753
39829
  const path = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : "/etc/claude-code/managed-settings.json";
39754
39830
  let raw;
39755
39831
  try {
@@ -39814,7 +39890,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
39814
39890
  function readGiveUpSignal(path, now = Date.now()) {
39815
39891
  if (!path) return null;
39816
39892
  try {
39817
- const raw = JSON.parse(readFileSync8(path, "utf8"));
39893
+ const raw = JSON.parse(readFileSync9(path, "utf8"));
39818
39894
  if (typeof raw.gave_up_at !== "string") return null;
39819
39895
  const t = Date.parse(raw.gave_up_at);
39820
39896
  if (!Number.isFinite(t) || t > now) return null;
@@ -39828,12 +39904,12 @@ function readGiveUpSignal(path, now = Date.now()) {
39828
39904
  var USAGE_LIMIT_LIVE_WINDOW_MS = 3 * 6e4;
39829
39905
  function readUsageLimitForBusyAck(agentDir, now = Date.now()) {
39830
39906
  if (!agentDir) return null;
39831
- const path = join8(agentDir, GIVE_UP_SIGNAL_FILENAME);
39907
+ const path = join10(agentDir, GIVE_UP_SIGNAL_FILENAME);
39832
39908
  const sig = readGiveUpSignal(path, now);
39833
39909
  if (sig?.reason !== "usage_limit") return null;
39834
39910
  let lastSeenMs = null;
39835
39911
  try {
39836
- const raw = JSON.parse(readFileSync8(path, "utf8"));
39912
+ const raw = JSON.parse(readFileSync9(path, "utf8"));
39837
39913
  if (typeof raw.usage_limit_last_seen_at === "string") {
39838
39914
  const t = Date.parse(raw.usage_limit_last_seen_at);
39839
39915
  if (Number.isFinite(t) && t <= now) lastSeenMs = t;
@@ -39852,7 +39928,7 @@ function readBlockedPromptForBusyAck(agentDir, now = Date.now()) {
39852
39928
  if (!agentDir) return null;
39853
39929
  let raw;
39854
39930
  try {
39855
- raw = JSON.parse(readFileSync8(join8(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
39931
+ raw = JSON.parse(readFileSync9(join10(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
39856
39932
  } catch {
39857
39933
  return null;
39858
39934
  }
@@ -39905,7 +39981,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
39905
39981
  if (!name.endsWith(".json")) continue;
39906
39982
  let receivedAt;
39907
39983
  try {
39908
- const raw = JSON.parse(readFileSync8(join8(dir, name), "utf-8"));
39984
+ const raw = JSON.parse(readFileSync9(join10(dir, name), "utf-8"));
39909
39985
  if (raw.discretionary === true) continue;
39910
39986
  if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
39911
39987
  receivedAt = raw.received_at;
@@ -39959,14 +40035,14 @@ function isMarkerGenuinelyAged(receivedAt, nowMs, thresholdMs) {
39959
40035
  }
39960
40036
  var DEFLECTION_COUNTER_SUFFIX = "-deflections.json";
39961
40037
  function deflectionCounterPath(agentDir, channel) {
39962
- return join8(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
40038
+ return join10(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
39963
40039
  }
39964
40040
  function recordChannelDeflection(agentDir, channel, cause) {
39965
40041
  if (!agentDir) return;
39966
40042
  const path = deflectionCounterPath(agentDir, channel);
39967
40043
  let counts = {};
39968
40044
  try {
39969
- const parsed = JSON.parse(readFileSync8(path, "utf-8"));
40045
+ const parsed = JSON.parse(readFileSync9(path, "utf-8"));
39970
40046
  if (parsed && typeof parsed === "object") counts = parsed;
39971
40047
  } catch {
39972
40048
  }
@@ -39979,12 +40055,12 @@ function recordChannelDeflection(agentDir, channel, cause) {
39979
40055
 
39980
40056
  // src/turn-failure-watch.ts
39981
40057
  import { readdirSync as readdirSync5, statSync as statSync2 } from "fs";
39982
- import { join as join10 } from "path";
40058
+ import { join as join12 } from "path";
39983
40059
 
39984
40060
  // src/rate-limit-watch.ts
39985
40061
  import { closeSync, fstatSync, openSync, readSync, readdirSync as readdirSync4, statSync } from "fs";
39986
- import { homedir as homedir2 } from "os";
39987
- import { join as join9 } from "path";
40062
+ import { homedir as homedir3 } from "os";
40063
+ import { join as join11 } from "path";
39988
40064
  var DEFAULT_WATCH_MS = 5e3;
39989
40065
  var DEFAULT_POLL_MS = 400;
39990
40066
  var INITIAL_TAIL_BYTES = 256 * 1024;
@@ -40055,8 +40131,8 @@ function oldestTimestampMs(text) {
40055
40131
  }
40056
40132
  function agentTranscriptDir(opts) {
40057
40133
  const cwd = opts?.cwd ?? process.cwd();
40058
- const home = opts?.home ?? homedir2();
40059
- return join9(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
40134
+ const home = opts?.home ?? homedir3();
40135
+ return join11(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
40060
40136
  }
40061
40137
  function classifyTranscriptSince(opts) {
40062
40138
  const dir = opts.transcriptDir ?? agentTranscriptDir({ cwd: opts.cwd, home: opts.home });
@@ -40069,7 +40145,7 @@ function classifyTranscriptSince(opts) {
40069
40145
  let newest = UNKNOWN_RATE_LIMIT;
40070
40146
  for (const name of entries) {
40071
40147
  if (!name.endsWith(".jsonl")) continue;
40072
- const path = join9(dir, name);
40148
+ const path = join11(dir, name);
40073
40149
  try {
40074
40150
  const st = statSync(path);
40075
40151
  if (!st.isFile() || st.mtimeMs < opts.sinceMs) continue;
@@ -40144,7 +40220,7 @@ function classifyTurnFailureSince(opts) {
40144
40220
  const unrecognised = /* @__PURE__ */ new Set();
40145
40221
  for (const name of entries) {
40146
40222
  if (!name.endsWith(".jsonl")) continue;
40147
- const path = join10(dir, name);
40223
+ const path = join12(dir, name);
40148
40224
  let fingerprint;
40149
40225
  try {
40150
40226
  const st = statSync2(path);
@@ -40331,15 +40407,15 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
40331
40407
  // src/mcp-spawn-lock.ts
40332
40408
  import {
40333
40409
  existsSync as existsSync5,
40334
- mkdirSync as mkdirSync5,
40335
- readFileSync as readFileSync9,
40410
+ mkdirSync as mkdirSync6,
40411
+ readFileSync as readFileSync10,
40336
40412
  renameSync as renameSync5,
40337
40413
  statSync as statSync3,
40338
40414
  unlinkSync as unlinkSync3,
40339
40415
  utimesSync,
40340
40416
  writeFileSync as writeFileSync6
40341
40417
  } from "fs";
40342
- import { join as join11 } from "path";
40418
+ import { join as join13 } from "path";
40343
40419
  var STALE_LOCK_MS = 9e4;
40344
40420
  var HEARTBEAT_INTERVAL_MS = 3e4;
40345
40421
  function defaultIsPidAlive(pid) {
@@ -40362,7 +40438,7 @@ function acquireMcpSpawnLock(args) {
40362
40438
  const nowMs = options.nowMs ?? (() => Date.now());
40363
40439
  const lockMtimeMs = options.lockMtimeMs ?? defaultLockMtimeMs;
40364
40440
  const staleMs = options.staleMs ?? STALE_LOCK_MS;
40365
- const path = join11(agentDir, basename);
40441
+ const path = join13(agentDir, basename);
40366
40442
  const existing = readLockHolder(path);
40367
40443
  if (existing) {
40368
40444
  if (existing.pid === selfPid) {
@@ -40376,7 +40452,7 @@ function acquireMcpSpawnLock(args) {
40376
40452
  }
40377
40453
  }
40378
40454
  }
40379
- mkdirSync5(agentDir, { recursive: true, mode: 448 });
40455
+ mkdirSync6(agentDir, { recursive: true, mode: 448 });
40380
40456
  const tmpPath = `${path}.${selfPid}.tmp`;
40381
40457
  const payload = { pid: selfPid, started_at: now() };
40382
40458
  writeFileSync6(tmpPath, JSON.stringify(payload), { mode: 384 });
@@ -40429,7 +40505,7 @@ function defaultLockMtimeMs(path) {
40429
40505
  function readLockHolder(path) {
40430
40506
  if (!existsSync5(path)) return null;
40431
40507
  try {
40432
- const raw = readFileSync9(path, "utf8");
40508
+ const raw = readFileSync10(path, "utf8");
40433
40509
  const parsed = JSON.parse(raw);
40434
40510
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
40435
40511
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -40441,14 +40517,14 @@ function readLockHolder(path) {
40441
40517
  }
40442
40518
 
40443
40519
  // src/direct-chat-channel.ts
40444
- import { homedir as homedir4 } from "os";
40445
- import { join as join16 } from "path";
40520
+ import { homedir as homedir5 } from "os";
40521
+ import { join as join17 } from "path";
40446
40522
  import { randomUUID } from "crypto";
40447
40523
  import {
40448
40524
  watch,
40449
- mkdirSync as mkdirSync6,
40525
+ mkdirSync as mkdirSync7,
40450
40526
  writeFileSync as writeFileSync8,
40451
- readFileSync as readFileSync12,
40527
+ readFileSync as readFileSync13,
40452
40528
  readdirSync as readdirSync6,
40453
40529
  existsSync as existsSync6,
40454
40530
  renameSync as renameSync6,
@@ -40458,53 +40534,12 @@ import {
40458
40534
  } from "fs";
40459
40535
 
40460
40536
  // src/direct-chat-inbound-attachments.ts
40461
- import { join as join13 } from "path";
40462
-
40463
- // ../core/dist/provisioning/frameworks/claudecode/agent-dir-alias.js
40464
- import { isAbsolute, join as join12, relative, sep } from "path";
40465
- var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
40466
- var VALID_AGENT_ID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
40467
- var INITIATOR_BASENAME = ".current-turn-initiator.json";
40468
- function isSafeAgentSegment(segment) {
40469
- return VALID_CODE_NAME.test(segment) || VALID_AGENT_ID.test(segment);
40470
- }
40471
- function initiatorDirSegment(initiatorFile, homeDir) {
40472
- const rel = relative(join12(homeDir, ".augmented"), initiatorFile);
40473
- if (!rel || isAbsolute(rel))
40474
- return null;
40475
- const parts = rel.split(sep);
40476
- if (parts.length !== 2 || parts[1] !== INITIATOR_BASENAME)
40477
- return null;
40478
- const segment = parts[0];
40479
- if (segment === void 0)
40480
- return null;
40481
- return isSafeAgentSegment(segment) ? segment : null;
40482
- }
40483
- function resolveAgentDirAlias(input) {
40484
- const { codeName, turnInitiatorFile, agentId, homeDir } = input;
40485
- const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
40486
- if (codeNameTrimmed && VALID_CODE_NAME.test(codeNameTrimmed)) {
40487
- return join12(homeDir, ".augmented", codeNameTrimmed);
40488
- }
40489
- const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
40490
- if (initiator) {
40491
- const segment = initiatorDirSegment(initiator, homeDir);
40492
- if (segment)
40493
- return join12(homeDir, ".augmented", segment);
40494
- }
40495
- const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
40496
- if (agentIdTrimmed && VALID_AGENT_ID.test(agentIdTrimmed)) {
40497
- return join12(homeDir, ".augmented", agentIdTrimmed);
40498
- }
40499
- return null;
40500
- }
40501
-
40502
- // src/direct-chat-inbound-attachments.ts
40537
+ import { join as join14 } from "path";
40503
40538
  var MAX_INBOUND_ATTACHMENT_BYTES = 10 * 1024 * 1024;
40504
40539
  var INBOUND_ATTACHMENTS_SUBDIR = "direct-chat-inbound";
40505
40540
  function resolveInboundAttachmentsDir(input) {
40506
40541
  const alias = resolveAgentDirAlias(input);
40507
- return alias === null ? null : join13(alias, INBOUND_ATTACHMENTS_SUBDIR);
40542
+ return alias === null ? null : join14(alias, INBOUND_ATTACHMENTS_SUBDIR);
40508
40543
  }
40509
40544
  function isImageContentType(contentType) {
40510
40545
  return typeof contentType === "string" && contentType.toLowerCase().startsWith("image/");
@@ -40987,19 +41022,19 @@ function isMaintenanceModeActive(opts) {
40987
41022
  }
40988
41023
 
40989
41024
  // src/account-enforcement-notice.ts
40990
- import { readFileSync as readFileSync10 } from "fs";
40991
- import { homedir as homedir3 } from "os";
40992
- import { join as join14 } from "path";
41025
+ import { readFileSync as readFileSync11 } from "fs";
41026
+ import { homedir as homedir4 } from "os";
41027
+ import { join as join15 } from "path";
40993
41028
  function accountEnforcementMarkerPath(codeName) {
40994
41029
  if (!codeName) return null;
40995
- return join14(homedir3(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
41030
+ return join15(homedir4(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
40996
41031
  }
40997
41032
  function readAccountEnforcementMarker(opts) {
40998
41033
  const path = opts.filePath ?? accountEnforcementMarkerPath(opts.codeName);
40999
41034
  if (!path) return null;
41000
41035
  let raw;
41001
41036
  try {
41002
- raw = readFileSync10(path, "utf-8");
41037
+ raw = readFileSync11(path, "utf-8");
41003
41038
  } catch {
41004
41039
  return null;
41005
41040
  }
@@ -41025,8 +41060,8 @@ function shouldSendAccountWarn(opts) {
41025
41060
  }
41026
41061
 
41027
41062
  // ../core/dist/direct-chat/cursor-advance-telemetry.js
41028
- import { readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "fs";
41029
- import { join as join15 } from "path";
41063
+ import { readFileSync as readFileSync12, writeFileSync as writeFileSync7 } from "fs";
41064
+ import { join as join16 } from "path";
41030
41065
  var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
41031
41066
  function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
41032
41067
  if (!agentDir)
@@ -41034,10 +41069,10 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
41034
41069
  const key = cursorAdvanceCounterKey(route, verdict);
41035
41070
  if (key === null)
41036
41071
  return;
41037
- const path = join15(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
41072
+ const path = join16(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
41038
41073
  const counts = {};
41039
41074
  try {
41040
- const parsed = JSON.parse(readFileSync11(path, "utf-8"));
41075
+ const parsed = JSON.parse(readFileSync12(path, "utf-8"));
41041
41076
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
41042
41077
  for (const [k, v] of Object.entries(parsed)) {
41043
41078
  if (typeof v === "number" && Number.isInteger(v) && v >= 0)
@@ -41170,21 +41205,21 @@ var DIRECT_CHAT_ACCOUNT_WARN_COOLDOWN_MS = (() => {
41170
41205
  var AGT_HOST = process.env.AGT_HOST;
41171
41206
  var AGT_API_KEY = process.env.AGT_API_KEY;
41172
41207
  var AGT_AGENT_ID = process.env.AGT_AGENT_ID;
41173
- var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join16(homedir4(), ".augmented", AGT_AGENT_ID) : null;
41208
+ var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join17(homedir5(), ".augmented", AGT_AGENT_ID) : null;
41174
41209
  var INBOUND_ATTACHMENTS_DIR = resolveInboundAttachmentsDir({
41175
41210
  codeName: process.env.AGT_AGENT_CODE_NAME,
41176
41211
  turnInitiatorFile: process.env.AGT_TURN_INITIATOR_FILE,
41177
41212
  agentId: AGT_AGENT_ID,
41178
- homeDir: homedir4()
41213
+ homeDir: homedir5()
41179
41214
  });
41180
41215
  var AGT_AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME;
41181
41216
  var directChatStderrLogStream = null;
41182
41217
  if (AGT_AGENT_CODE_NAME) {
41183
41218
  try {
41184
- const logDir = join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME);
41185
- mkdirSync6(logDir, { recursive: true });
41219
+ const logDir = join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME);
41220
+ mkdirSync7(logDir, { recursive: true });
41186
41221
  directChatStderrLogStream = createWriteStream(
41187
- join16(logDir, "direct-chat-channel-stderr.log"),
41222
+ join17(logDir, "direct-chat-channel-stderr.log"),
41188
41223
  { flags: "a", mode: 384 }
41189
41224
  );
41190
41225
  directChatStderrLogStream.on("error", () => {
@@ -41203,10 +41238,10 @@ if (AGT_AGENT_CODE_NAME) {
41203
41238
  } catch {
41204
41239
  }
41205
41240
  }
41206
- var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
41207
- var DIRECT_CHAT_PENDING_INBOUND_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-pending-inbound") : null;
41208
- var DIRECT_CHAT_DELIVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-inbound-delivery-ledger") : null;
41209
- var DIRECT_CHAT_CODE_NAME_AGENT_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME) : null;
41241
+ var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
41242
+ var DIRECT_CHAT_PENDING_INBOUND_DIR = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-pending-inbound") : null;
41243
+ var DIRECT_CHAT_DELIVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-inbound-delivery-ledger") : null;
41244
+ var DIRECT_CHAT_CODE_NAME_AGENT_DIR = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME) : null;
41210
41245
  var DIRECT_CHAT_STALE_MARKER_MS = 24 * 60 * 60 * 1e3;
41211
41246
  function judgeCursorAdvance(input, ctx) {
41212
41247
  const verdict = classifyCursorAdvance(input);
@@ -41226,8 +41261,8 @@ function recordDirectChatDelivery(sessionId, messageIds) {
41226
41261
  delivered_at: (/* @__PURE__ */ new Date()).toISOString()
41227
41262
  });
41228
41263
  }
41229
- var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-recovery-outbox") : null;
41230
- var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-direct-chat-recovery-ledger") : null;
41264
+ var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-recovery-outbox") : null;
41265
+ var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-direct-chat-recovery-ledger") : null;
41231
41266
  var progressReceivedAt = /* @__PURE__ */ new Map();
41232
41267
  var directChatProgressState = { tracked: null };
41233
41268
  var directChatProgressTickRunning = false;
@@ -41246,7 +41281,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
41246
41281
  function readProgressHeartbeat() {
41247
41282
  if (!PROGRESS_HEARTBEAT_PATH || !existsSync6(PROGRESS_HEARTBEAT_PATH)) return null;
41248
41283
  try {
41249
- return parseProgressHeartbeat(readFileSync12(PROGRESS_HEARTBEAT_PATH, "utf-8"));
41284
+ return parseProgressHeartbeat(readFileSync13(PROGRESS_HEARTBEAT_PATH, "utf-8"));
41250
41285
  } catch {
41251
41286
  return null;
41252
41287
  }
@@ -41255,7 +41290,7 @@ function seedProgressHeartbeat() {
41255
41290
  if (!PROGRESS_HEARTBEAT_PATH) return;
41256
41291
  const tmp = `${PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
41257
41292
  try {
41258
- mkdirSync6(join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
41293
+ mkdirSync7(join17(homedir5(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
41259
41294
  writeFileSync8(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
41260
41295
  renameSync6(tmp, PROGRESS_HEARTBEAT_PATH);
41261
41296
  } catch {
@@ -41450,9 +41485,9 @@ var inboundAttachmentDeps = {
41450
41485
  bytes: async () => new Uint8Array(await res.arrayBuffer())
41451
41486
  };
41452
41487
  },
41453
- ensureDir: (dir) => mkdirSync6(dir, { recursive: true }),
41488
+ ensureDir: (dir) => mkdirSync7(dir, { recursive: true }),
41454
41489
  writeFile: (path, bytes) => writeFileSync8(path, bytes, { mode: 384 }),
41455
- joinPath: (...parts) => join16(...parts),
41490
+ joinPath: (...parts) => join17(...parts),
41456
41491
  warn: (msg) => process.stderr.write(`${msg}
41457
41492
  `)
41458
41493
  };
@@ -41886,7 +41921,7 @@ function directChatSessionReplayFacts(sessionId) {
41886
41921
  sessionId,
41887
41922
  (fullPath) => {
41888
41923
  try {
41889
- const marker = JSON.parse(readFileSync12(fullPath, "utf-8"));
41924
+ const marker = JSON.parse(readFileSync13(fullPath, "utf-8"));
41890
41925
  found.push({ hasPayload: Boolean(marker.payload), discretionary: marker.discretionary });
41891
41926
  } catch {
41892
41927
  found.push({ hasPayload: false });
@@ -41945,7 +41980,7 @@ function scheduleDirectChatBusyAck(sessionId, messageId, arrivedWhileBusy) {
41945
41980
  let paneLogFreshAgeMs = null;
41946
41981
  if (DIRECT_CHAT_CODE_NAME_AGENT_DIR) {
41947
41982
  try {
41948
- const paneMtimeMs = statSync4(join16(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "pane.log")).mtimeMs;
41983
+ const paneMtimeMs = statSync4(join17(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "pane.log")).mtimeMs;
41949
41984
  paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
41950
41985
  } catch {
41951
41986
  }
@@ -42295,8 +42330,14 @@ async function pollForMessages(sinceMs) {
42295
42330
  writeTurnInitiatorMarker({
42296
42331
  channel: "direct-chat",
42297
42332
  sender_id: msg.sender_id,
42298
- channel_ref: msg.session_id
42333
+ channel_ref: msg.session_id,
42334
+ // ENG-11348: one sender per session from this side. Whether the
42335
+ // TRANSCRIPT is private (only for a manager-only agent) is decided
42336
+ // server-side, so 'direct' here is not the last word.
42337
+ chat_kind: "direct"
42299
42338
  });
42339
+ } else {
42340
+ writeUnattributedTurnMarker("direct-chat");
42300
42341
  }
42301
42342
  if (isNotice) {
42302
42343
  try {
@@ -42414,7 +42455,7 @@ var doorbellWatcher = null;
42414
42455
  var safetyNetTimer = null;
42415
42456
  if (DOORBELL_ENABLED && DIRECT_CHAT_AGENT_DIR) {
42416
42457
  try {
42417
- mkdirSync6(DIRECT_CHAT_AGENT_DIR, { recursive: true });
42458
+ mkdirSync7(DIRECT_CHAT_AGENT_DIR, { recursive: true });
42418
42459
  } catch {
42419
42460
  }
42420
42461
  const sessionState = readDirectChatSessionState(DIRECT_CHAT_AGENT_DIR, Date.now());
@@ -42485,7 +42526,7 @@ function sweepAgedDirectChatMarkersNow(thresholdMs) {
42485
42526
  const now = Date.now();
42486
42527
  const res = sweepAgedDirectChatMarkers(DIRECT_CHAT_PENDING_INBOUND_DIR, {
42487
42528
  readdir: (dir) => readdirSync6(dir),
42488
- readFile: (p2) => readFileSync12(p2, "utf8"),
42529
+ readFile: (p2) => readFileSync13(p2, "utf8"),
42489
42530
  unlink: (p2) => {
42490
42531
  if (existsSync6(p2)) unlinkSync4(p2);
42491
42532
  },
@@ -42534,7 +42575,7 @@ function sanitizeRecoveryText(text) {
42534
42575
  }
42535
42576
  function directChatRecoveryDeps() {
42536
42577
  return {
42537
- readFile: (p2) => readFileSync12(p2, "utf-8"),
42578
+ readFile: (p2) => readFileSync13(p2, "utf-8"),
42538
42579
  renameFile: (from, to) => renameSync6(from, to),
42539
42580
  unlinkFile: (p2) => {
42540
42581
  if (existsSync6(p2)) unlinkSync4(p2);
@@ -42547,7 +42588,7 @@ function directChatRecoveryDeps() {
42547
42588
  if (!DIRECT_CHAT_RECOVERY_LEDGER_DIR) return;
42548
42589
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
42549
42590
  try {
42550
- const p2 = join16(DIRECT_CHAT_RECOVERY_LEDGER_DIR, markerName);
42591
+ const p2 = join17(DIRECT_CHAT_RECOVERY_LEDGER_DIR, markerName);
42551
42592
  if (existsSync6(p2)) unlinkSync4(p2);
42552
42593
  } catch {
42553
42594
  }
@@ -42598,7 +42639,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
42598
42639
  if (!enabled) return;
42599
42640
  directChatRecoveryInFlight.add(filename);
42600
42641
  try {
42601
- const fullPath = join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, filename);
42642
+ const fullPath = join17(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, filename);
42602
42643
  await consumeDirectChatRecoveryFile(fullPath, filename, directChatRecoveryDeps());
42603
42644
  } catch (err) {
42604
42645
  process.stderr.write(
@@ -42612,7 +42653,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
42612
42653
  var directChatRecoveryWatcher = null;
42613
42654
  if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
42614
42655
  try {
42615
- mkdirSync6(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
42656
+ mkdirSync7(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
42616
42657
  } catch {
42617
42658
  }
42618
42659
  try {
@@ -42626,7 +42667,7 @@ if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
42626
42667
  if (!filename) return;
42627
42668
  const name = filename.toString();
42628
42669
  if (!name.endsWith(".json")) return;
42629
- if (existsSync6(join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, name))) {
42670
+ if (existsSync6(join17(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, name))) {
42630
42671
  void processDirectChatRecoveryOutboxFile(name);
42631
42672
  }
42632
42673
  });