@integrity-labs/agt-cli 0.27.138 → 0.27.139

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.
@@ -1,16 +1,22 @@
1
1
  import {
2
2
  claudeModelAlias,
3
3
  isClaudeFastMode
4
- } from "./chunk-PDDU4Z5V.js";
4
+ } from "./chunk-WCXA7EEP.js";
5
+ import {
6
+ getOrCreateDailySession,
7
+ markDailySessionSpawn,
8
+ rotateDailySession,
9
+ sessionFileExists
10
+ } from "./chunk-354FAVQR.js";
5
11
  import {
6
12
  reapOrphanChannelMcps
7
13
  } from "./chunk-XWVM4KPK.js";
8
14
 
9
15
  // src/lib/persistent-session.ts
10
16
  import { spawn, execSync, execFileSync as execFileSync3 } from "child_process";
11
- import { join as join2, dirname } from "path";
12
- import { homedir as homedir2, platform, userInfo } from "os";
13
- import { existsSync as existsSync3, readFileSync as readFileSync4, readdirSync, writeFileSync as writeFileSync3, appendFileSync, mkdirSync as mkdirSync2, chmodSync, copyFileSync, rmSync } from "fs";
17
+ import { join, dirname } from "path";
18
+ import { homedir, platform, userInfo } from "os";
19
+ import { existsSync as existsSync2, readFileSync as readFileSync3, readdirSync, writeFileSync as writeFileSync2, appendFileSync, mkdirSync, chmodSync, copyFileSync, rmSync } from "fs";
14
20
  import { fileURLToPath } from "url";
15
21
 
16
22
  // src/lib/mcp-sanitize.ts
@@ -153,156 +159,7 @@ function probeMcpEnvSubstitution(args) {
153
159
  }
154
160
 
155
161
  // src/lib/persistent-session.ts
156
- import { randomUUID as randomUUID2 } from "crypto";
157
-
158
- // src/lib/daily-session.ts
159
162
  import { randomUUID } from "crypto";
160
- import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync3, renameSync, statSync, writeFileSync as writeFileSync2 } from "fs";
161
- import { homedir } from "os";
162
- import { join } from "path";
163
- var HISTORY_DAYS = 7;
164
- function profileDir(codeName) {
165
- return join(homedir(), ".augmented", codeName);
166
- }
167
- function dailySessionPath(codeName) {
168
- return join(profileDir(codeName), "daily-session.json");
169
- }
170
- function todayLocalIso(now = /* @__PURE__ */ new Date(), timezone) {
171
- if (timezone) {
172
- try {
173
- const fmt = new Intl.DateTimeFormat("en-CA", {
174
- timeZone: timezone,
175
- year: "numeric",
176
- month: "2-digit",
177
- day: "2-digit"
178
- });
179
- return fmt.format(now);
180
- } catch {
181
- }
182
- }
183
- const y = now.getFullYear();
184
- const m = String(now.getMonth() + 1).padStart(2, "0");
185
- const d = String(now.getDate()).padStart(2, "0");
186
- return `${y}-${m}-${d}`;
187
- }
188
- function readFile(codeName) {
189
- const path = dailySessionPath(codeName);
190
- if (!existsSync2(path)) return { current: null, history: [] };
191
- try {
192
- const raw = readFileSync3(path, "utf-8");
193
- const parsed = JSON.parse(raw);
194
- return {
195
- current: parsed.current ?? null,
196
- history: Array.isArray(parsed.history) ? parsed.history : []
197
- };
198
- } catch {
199
- return { current: null, history: [] };
200
- }
201
- }
202
- function writeFile(codeName, data) {
203
- const dir = profileDir(codeName);
204
- mkdirSync(dir, { recursive: true });
205
- const finalPath = dailySessionPath(codeName);
206
- const tmpPath = `${finalPath}.${process.pid}.${randomUUID()}.tmp`;
207
- writeFileSync2(tmpPath, JSON.stringify(data, null, 2), "utf-8");
208
- renameSync(tmpPath, finalPath);
209
- }
210
- function trimHistory(history, now, timezone) {
211
- const cutoff = new Date(now);
212
- cutoff.setDate(cutoff.getDate() - HISTORY_DAYS);
213
- const cutoffIso = todayLocalIso(cutoff, timezone);
214
- return history.filter((h) => h.date >= cutoffIso).slice(0, HISTORY_DAYS);
215
- }
216
- function getOrCreateDailySession(codeName, now = /* @__PURE__ */ new Date(), timezone) {
217
- const today = todayLocalIso(now, timezone);
218
- const file = readFile(codeName);
219
- if (file.current && file.current.date === today) {
220
- return { sessionId: file.current.sessionId, isNew: false };
221
- }
222
- const next = {
223
- date: today,
224
- sessionId: randomUUID(),
225
- startedAt: now.toISOString()
226
- };
227
- const history = trimHistory(
228
- [...file.current ? [file.current] : [], ...file.history],
229
- now,
230
- timezone
231
- );
232
- writeFile(codeName, { current: next, history });
233
- return { sessionId: next.sessionId, isNew: true };
234
- }
235
- function markDailySessionSpawn(codeName, sessionId, now = /* @__PURE__ */ new Date(), timezone) {
236
- const today = todayLocalIso(now, timezone);
237
- const file = readFile(codeName);
238
- if (file.current && file.current.date === today && file.current.sessionId === sessionId) {
239
- return;
240
- }
241
- const next = {
242
- date: today,
243
- sessionId,
244
- startedAt: now.toISOString()
245
- };
246
- const history = trimHistory(
247
- [...file.current ? [file.current] : [], ...file.history],
248
- now,
249
- timezone
250
- );
251
- writeFile(codeName, { current: next, history });
252
- }
253
- function rotateDailySession(codeName, now = /* @__PURE__ */ new Date(), timezone) {
254
- const today = todayLocalIso(now, timezone);
255
- const file = readFile(codeName);
256
- const next = {
257
- date: today,
258
- sessionId: randomUUID(),
259
- startedAt: now.toISOString()
260
- };
261
- const history = trimHistory(
262
- [...file.current ? [file.current] : [], ...file.history],
263
- now,
264
- timezone
265
- );
266
- writeFile(codeName, { current: next, history });
267
- return next.sessionId;
268
- }
269
- function encodeProjectPath(projectDir) {
270
- return "-" + projectDir.replace(/^\//, "").replace(/[/.]/g, "-");
271
- }
272
- function sessionFileExists(projectDir, sessionId) {
273
- const path = join(
274
- homedir(),
275
- ".claude",
276
- "projects",
277
- encodeProjectPath(projectDir),
278
- `${sessionId}.jsonl`
279
- );
280
- return existsSync2(path);
281
- }
282
- function sessionTranscriptDir(projectDir) {
283
- return join(homedir(), ".claude", "projects", encodeProjectPath(projectDir));
284
- }
285
- function sessionFilePath(projectDir, sessionId) {
286
- return join(sessionTranscriptDir(projectDir), `${sessionId}.jsonl`);
287
- }
288
- function isAgentIdle(projectDir, sessionId, idleSeconds = 60, now = /* @__PURE__ */ new Date()) {
289
- const path = sessionFilePath(projectDir, sessionId);
290
- if (!existsSync2(path)) return true;
291
- try {
292
- const mtimeMs = statSync(path).mtimeMs;
293
- return now.getTime() - mtimeMs >= idleSeconds * 1e3;
294
- } catch {
295
- return false;
296
- }
297
- }
298
- function isStaleForToday(codeName, now = /* @__PURE__ */ new Date(), timezone) {
299
- const file = readFile(codeName);
300
- if (!file.current) return false;
301
- return file.current.date !== todayLocalIso(now, timezone);
302
- }
303
- function peekCurrentSession(codeName) {
304
- return readFile(codeName).current;
305
- }
306
163
 
307
164
  // ../../packages/core/dist/runtime/session-probe.js
308
165
  import { execFileSync } from "child_process";
@@ -584,7 +441,7 @@ function syncClaudeCredsToRoot() {
584
441
  if (platform() !== "linux") return true;
585
442
  if (typeof process.getuid !== "function" || process.getuid() !== 0) return true;
586
443
  for (const filename of [".credentials.json", "credentials.json"]) {
587
- if (existsSync3(join2("/root/.claude", filename))) return true;
444
+ if (existsSync2(join("/root/.claude", filename))) return true;
588
445
  }
589
446
  let sourcePath = null;
590
447
  try {
@@ -592,8 +449,8 @@ function syncClaudeCredsToRoot() {
592
449
  outer: for (const entry of entries) {
593
450
  if (!entry.isDirectory()) continue;
594
451
  for (const filename of [".credentials.json", "credentials.json"]) {
595
- const candidate = join2("/home", entry.name, ".claude", filename);
596
- if (existsSync3(candidate)) {
452
+ const candidate = join("/home", entry.name, ".claude", filename);
453
+ if (existsSync2(candidate)) {
597
454
  sourcePath = candidate;
598
455
  break outer;
599
456
  }
@@ -604,9 +461,9 @@ function syncClaudeCredsToRoot() {
604
461
  if (!sourcePath) return false;
605
462
  const targetDir = "/root/.claude";
606
463
  const sourceFilename = sourcePath.endsWith("credentials.json") && !sourcePath.endsWith(".credentials.json") ? "credentials.json" : ".credentials.json";
607
- const targetPath = join2(targetDir, sourceFilename);
464
+ const targetPath = join(targetDir, sourceFilename);
608
465
  try {
609
- if (!existsSync3(targetDir)) mkdirSync2(targetDir, { recursive: true, mode: 448 });
466
+ if (!existsSync2(targetDir)) mkdirSync(targetDir, { recursive: true, mode: 448 });
610
467
  copyFileSync(sourcePath, targetPath);
611
468
  chmodSync(targetPath, 384);
612
469
  return true;
@@ -618,13 +475,13 @@ var cachedClaudePath = null;
618
475
  function resolveClaudeBinary() {
619
476
  if (cachedClaudePath) return cachedClaudePath;
620
477
  const override = process.env.CLAUDE_PATH;
621
- if (override && existsSync3(override)) {
478
+ if (override && existsSync2(override)) {
622
479
  cachedClaudePath = override;
623
480
  return override;
624
481
  }
625
482
  try {
626
483
  const out = execSync("which claude 2>/dev/null", { encoding: "utf-8" }).trim();
627
- if (out && existsSync3(out)) {
484
+ if (out && existsSync2(out)) {
628
485
  cachedClaudePath = out;
629
486
  return out;
630
487
  }
@@ -636,7 +493,7 @@ function resolveClaudeBinary() {
636
493
  "/usr/local/bin/claude"
637
494
  ];
638
495
  for (const p of candidates) {
639
- if (existsSync3(p)) {
496
+ if (existsSync2(p)) {
640
497
  cachedClaudePath = p;
641
498
  return p;
642
499
  }
@@ -645,8 +502,8 @@ function resolveClaudeBinary() {
645
502
  }
646
503
  function writePersistentClaudeWrapper(args) {
647
504
  const { projectDir, claudeBin, initPrompt, claudeArgsJoined } = args;
648
- const envIntegrationsPath = join2(projectDir, ".env.integrations");
649
- const wrapperPath = join2(projectDir, ".claude", "persistent-claude.sh");
505
+ const envIntegrationsPath = join(projectDir, ".env.integrations");
506
+ const wrapperPath = join(projectDir, ".claude", "persistent-claude.sh");
650
507
  const wrapperLines = [
651
508
  "#!/usr/bin/env bash",
652
509
  "set -e",
@@ -654,7 +511,7 @@ function writePersistentClaudeWrapper(args) {
654
511
  // --dangerously-skip-permissions on dedicated EC2 hosts.
655
512
  "export IS_SANDBOX=1"
656
513
  ];
657
- if (existsSync3(envIntegrationsPath)) {
514
+ if (existsSync2(envIntegrationsPath)) {
658
515
  wrapperLines.push(
659
516
  "set -a",
660
517
  `source ${JSON.stringify(envIntegrationsPath)}`,
@@ -665,15 +522,15 @@ function writePersistentClaudeWrapper(args) {
665
522
  wrapperLines.push(
666
523
  `exec ${JSON.stringify(claudeBin)} ${initPromptArg}${claudeArgsJoined}`
667
524
  );
668
- mkdirSync2(join2(projectDir, ".claude"), { recursive: true });
669
- writeFileSync3(wrapperPath, wrapperLines.join("\n") + "\n", { mode: 448 });
525
+ mkdirSync(join(projectDir, ".claude"), { recursive: true });
526
+ writeFileSync2(wrapperPath, wrapperLines.join("\n") + "\n", { mode: 448 });
670
527
  chmodSync(wrapperPath, 448);
671
528
  return wrapperPath;
672
529
  }
673
530
  function collectMcpServerNames(mcpConfigPath) {
674
- if (!existsSync3(mcpConfigPath)) return [];
531
+ if (!existsSync2(mcpConfigPath)) return [];
675
532
  try {
676
- const data = JSON.parse(readFileSync4(mcpConfigPath, "utf-8"));
533
+ const data = JSON.parse(readFileSync3(mcpConfigPath, "utf-8"));
677
534
  const servers = data.mcpServers;
678
535
  return servers ? Object.keys(servers) : [];
679
536
  } catch {
@@ -686,8 +543,8 @@ function getAcpxBin() {
686
543
  const moduleDir = dirname(fileURLToPath(import.meta.url));
687
544
  let dir = moduleDir;
688
545
  for (let i = 0; i < 6; i++) {
689
- const candidate = join2(dir, "node_modules", ".bin", "acpx");
690
- if (existsSync3(candidate)) {
546
+ const candidate = join(dir, "node_modules", ".bin", "acpx");
547
+ if (existsSync2(candidate)) {
691
548
  _acpxBin = candidate;
692
549
  return _acpxBin;
693
550
  }
@@ -735,15 +592,15 @@ function hasAcpxSession(acpxBin, projectDir, codeName) {
735
592
  return available;
736
593
  }
737
594
  var sessions = /* @__PURE__ */ new Map();
738
- var PANE_LOG_DIR = join2(homedir2(), ".augmented");
595
+ var PANE_LOG_DIR = join(homedir(), ".augmented");
739
596
  var PANE_TAIL_LINES = 20;
740
597
  function paneLogPath(codeName) {
741
- return join2(PANE_LOG_DIR, codeName, "pane.log");
598
+ return join(PANE_LOG_DIR, codeName, "pane.log");
742
599
  }
743
600
  function setupPaneLog(tmuxSession, codeName, log) {
744
601
  const logPath = paneLogPath(codeName);
745
602
  try {
746
- mkdirSync2(dirname(logPath), { recursive: true });
603
+ mkdirSync(dirname(logPath), { recursive: true });
747
604
  appendFileSync(
748
605
  logPath,
749
606
  `
@@ -761,9 +618,9 @@ function setupPaneLog(tmuxSession, codeName, log) {
761
618
  }
762
619
  function readPaneLogTail(codeName, lines = PANE_TAIL_LINES) {
763
620
  const logPath = paneLogPath(codeName);
764
- if (!existsSync3(logPath)) return null;
621
+ if (!existsSync2(logPath)) return null;
765
622
  try {
766
- const raw = readFileSync4(logPath, "utf-8");
623
+ const raw = readFileSync3(logPath, "utf-8");
767
624
  if (!raw) return null;
768
625
  const stripped = raw.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
769
626
  const all = stripped.split("\n").filter((l) => l.length > 0);
@@ -818,7 +675,7 @@ function resolveSessionSpawnDecision(args) {
818
675
  const disableFlag = process.env["AGT_DISABLE_SESSION_RESUME"];
819
676
  const resumeDisabled = disableFlag === "1" || disableFlag?.toLowerCase() === "true";
820
677
  if (resumeDisabled) {
821
- return { flag: "--session-id", sessionId: randomUUID2(), reason: "resume-disabled" };
678
+ return { flag: "--session-id", sessionId: randomUUID(), reason: "resume-disabled" };
822
679
  }
823
680
  const daily = getOrCreateDailySession(codeName, now, agentTimezone);
824
681
  if (!daily.isNew && sessionFileExists(projectDir, daily.sessionId)) {
@@ -878,10 +735,10 @@ function spawnSession(config, session) {
878
735
  log(`[persistent-session] No Claude Code credentials found under /root/.claude or /home/*. Pair via browser from the host page, or run 'claude /login' on the host.`);
879
736
  }
880
737
  } else {
881
- const claudeDir = join2(homedir2(), ".claude");
738
+ const claudeDir = join(homedir(), ".claude");
882
739
  for (const filename of [".credentials.json", "credentials.json"]) {
883
- const p = join2(claudeDir, filename);
884
- if (existsSync3(p)) {
740
+ const p = join(claudeDir, filename);
741
+ if (existsSync2(p)) {
885
742
  try {
886
743
  rmSync(p, { force: true });
887
744
  log(`[persistent-session] Removed ${p} (api_key mode active \u2014 preventing OAuth fallback)`);
@@ -915,7 +772,7 @@ function spawnSession(config, session) {
915
772
  if (channels.length > 0) args.push("--channels", ...channels);
916
773
  if (devChannels.length > 0) args.push("--dangerously-load-development-channels", ...devChannels);
917
774
  args.push("--mcp-config", mcpConfigPath);
918
- if (existsSync3(claudeMdPath)) args.push("--system-prompt-file", claudeMdPath);
775
+ if (existsSync2(claudeMdPath)) args.push("--system-prompt-file", claudeMdPath);
919
776
  const modelAlias = claudeModelAlias(config.primaryModel);
920
777
  if (modelAlias) args.push("--model", modelAlias);
921
778
  args.push("--allow-dangerously-skip-permissions");
@@ -943,7 +800,7 @@ function spawnSession(config, session) {
943
800
  // Treat empty-string as missing too — `HOME=""` makes ~ resolve
944
801
  // to cwd, which is the same broken outcome as no HOME, just
945
802
  // better hidden.
946
- HOME: process.env.HOME?.trim() || homedir2(),
803
+ HOME: process.env.HOME?.trim() || homedir(),
947
804
  USER: process.env.USER?.trim() || userInfo().username
948
805
  };
949
806
  if (config.runId) {
@@ -951,7 +808,7 @@ function spawnSession(config, session) {
951
808
  }
952
809
  for (const f of probeMcpEnvSubstitution({
953
810
  mcpConfigPath,
954
- envIntegrationsPath: join2(projectDir, ".env.integrations"),
811
+ envIntegrationsPath: join(projectDir, ".env.integrations"),
955
812
  baseEnv: {
956
813
  ...tmuxEnv,
957
814
  ...claudeAuthMode === "api_key" && config.anthropicApiKey ? { ANTHROPIC_API_KEY: config.anthropicApiKey } : {}
@@ -1267,10 +1124,10 @@ async function injectMessageWithStatus(codeName, type, content, meta, log) {
1267
1124
  const acpx = getAcpxBin();
1268
1125
  if (acpx && hasAcpxSession(acpx, projectDir, codeName)) {
1269
1126
  try {
1270
- const tmpDir = join2(projectDir, ".claude");
1271
- mkdirSync2(tmpDir, { recursive: true });
1272
- const tmpFile = join2(tmpDir, ".agt-inject-prompt.txt");
1273
- writeFileSync3(tmpFile, text);
1127
+ const tmpDir = join(projectDir, ".claude");
1128
+ mkdirSync(tmpDir, { recursive: true });
1129
+ const tmpFile = join(tmpDir, ".agt-inject-prompt.txt");
1130
+ writeFileSync2(tmpFile, text);
1274
1131
  _log(`[inject] acpx exec (fire-and-forget): cwd=${projectDir}, file=${tmpFile}`);
1275
1132
  const child = spawn(acpx, ["claude", "exec", "-f", tmpFile], {
1276
1133
  cwd: projectDir,
@@ -1520,7 +1377,7 @@ async function stopAllSessionsAndWait(log, opts) {
1520
1377
  await new Promise((resolve) => setTimeout(resolve, Math.min(opts.timeoutMs, 2e3)));
1521
1378
  }
1522
1379
  function getProjectDir(codeName) {
1523
- return join2(homedir2(), ".augmented", codeName, "project");
1380
+ return join(homedir(), ".augmented", codeName, "project");
1524
1381
  }
1525
1382
  function writeAcpxConfig(config) {
1526
1383
  const {
@@ -1536,7 +1393,7 @@ function writeAcpxConfig(config) {
1536
1393
  if (channels.length > 0) claudeArgs.push("--channels", ...channels);
1537
1394
  if (devChannels.length > 0) claudeArgs.push("--dangerously-load-development-channels", ...devChannels);
1538
1395
  claudeArgs.push("--mcp-config", mcpConfigPath);
1539
- if (existsSync3(claudeMdPath)) claudeArgs.push("--system-prompt-file", claudeMdPath);
1396
+ if (existsSync2(claudeMdPath)) claudeArgs.push("--system-prompt-file", claudeMdPath);
1540
1397
  const acpModelAlias = claudeModelAlias(config.primaryModel);
1541
1398
  if (acpModelAlias) claudeArgs.push("--model", acpModelAlias);
1542
1399
  claudeArgs.push("--allow-dangerously-skip-permissions");
@@ -1545,18 +1402,18 @@ function writeAcpxConfig(config) {
1545
1402
  const mcpServerNames2 = collectMcpServerNames(mcpConfigPath);
1546
1403
  claudeArgs.push("--allowedTools", buildAllowedTools(mcpServerNames2));
1547
1404
  const acpCmd = `npx -y @agentclientprotocol/claude-agent-acp ${claudeArgs.map((a) => a.includes(" ") || a.includes("*") ? JSON.stringify(a) : a).join(" ")}`;
1548
- const envIntegrationsPath = join2(projectDir, ".env.integrations");
1549
- const wrapperPath = join2(projectDir, ".claude", "acpx-agent.sh");
1405
+ const envIntegrationsPath = join(projectDir, ".env.integrations");
1406
+ const wrapperPath = join(projectDir, ".claude", "acpx-agent.sh");
1550
1407
  const wrapperLines = ["#!/usr/bin/env bash"];
1551
- if (existsSync3(envIntegrationsPath)) {
1408
+ if (existsSync2(envIntegrationsPath)) {
1552
1409
  wrapperLines.push(`set -a`, `source ${JSON.stringify(envIntegrationsPath)}`, `set +a`);
1553
1410
  }
1554
1411
  if (claudeAuthMode === "api_key" && anthropicApiKey) {
1555
1412
  wrapperLines.push(`export ANTHROPIC_API_KEY=${JSON.stringify(anthropicApiKey)}`);
1556
1413
  }
1557
1414
  wrapperLines.push(`exec ${acpCmd}`);
1558
- mkdirSync2(join2(projectDir, ".claude"), { recursive: true });
1559
- writeFileSync3(wrapperPath, wrapperLines.join("\n") + "\n", { mode: 493 });
1415
+ mkdirSync(join(projectDir, ".claude"), { recursive: true });
1416
+ writeFileSync2(wrapperPath, wrapperLines.join("\n") + "\n", { mode: 493 });
1560
1417
  chmodSync(wrapperPath, 493);
1561
1418
  const acpxConfig = {
1562
1419
  defaultAgent: "claude",
@@ -1567,7 +1424,7 @@ function writeAcpxConfig(config) {
1567
1424
  }
1568
1425
  }
1569
1426
  };
1570
- writeFileSync3(join2(projectDir, ".acpxrc.json"), JSON.stringify(acpxConfig, null, 2));
1427
+ writeFileSync2(join(projectDir, ".acpxrc.json"), JSON.stringify(acpxConfig, null, 2));
1571
1428
  }
1572
1429
 
1573
1430
  export {
@@ -1577,10 +1434,6 @@ export {
1577
1434
  probeMcpEnvSubstitution,
1578
1435
  sanitizeMcpJson,
1579
1436
  buildAllowedTools,
1580
- sessionTranscriptDir,
1581
- isAgentIdle,
1582
- isStaleForToday,
1583
- peekCurrentSession,
1584
1437
  checkChannelInputs,
1585
1438
  takeWatchdogGiveUpCount,
1586
1439
  creditWatchdogGiveUpCount,
@@ -1611,4 +1464,4 @@ export {
1611
1464
  stopAllSessionsAndWait,
1612
1465
  getProjectDir
1613
1466
  };
1614
- //# sourceMappingURL=chunk-RT37WJXI.js.map
1467
+ //# sourceMappingURL=chunk-IDDSO7Q5.js.map