@integrity-labs/agt-cli 0.7.5 → 0.7.7

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.
@@ -8,7 +8,7 @@ import {
8
8
  provision,
9
9
  requireHost,
10
10
  resolveChannels
11
- } from "../chunk-GBTJNYNP.js";
11
+ } from "../chunk-QS2GCIWQ.js";
12
12
  import {
13
13
  findTaskByTemplate,
14
14
  getProjectDir,
@@ -909,13 +909,24 @@ async function ensureFrameworkBinary(frameworkId) {
909
909
  }
910
910
  function checkClaudeAuth(execFileSync) {
911
911
  try {
912
- const authOutput = execFileSync("claude", ["auth", "status"], { timeout: 1e4, stdio: "pipe" }).toString();
913
- const authStatus = JSON.parse(authOutput);
914
- if (authStatus.loggedIn) {
915
- return true;
912
+ const authOutput = execFileSync("claude", ["auth", "status"], { timeout: 1e4, stdio: "pipe" }).toString().trim();
913
+ let loggedIn = null;
914
+ try {
915
+ const parsed = JSON.parse(authOutput);
916
+ if (typeof parsed.loggedIn === "boolean") loggedIn = parsed.loggedIn;
917
+ } catch {
918
+ const lower = authOutput.toLowerCase();
919
+ if (lower.includes("not logged in") || lower.includes("logged out")) loggedIn = false;
920
+ else if (lower.includes("logged in")) loggedIn = true;
916
921
  }
917
- log('\u26A0\uFE0F Claude Code is not authenticated. Run "claude" in a terminal to log in, then restart the manager.');
918
- return false;
922
+ if (loggedIn === false) {
923
+ log('\u26A0\uFE0F Claude Code is not authenticated. Run "claude" in a terminal to log in, then restart the manager.');
924
+ return false;
925
+ } else if (loggedIn === null) {
926
+ log('\u26A0\uFE0F Could not determine Claude Code auth state. Run "claude" in a terminal to verify login.');
927
+ return false;
928
+ }
929
+ return true;
919
930
  } catch {
920
931
  log('\u26A0\uFE0F Could not check Claude Code auth status. Run "claude" in a terminal to ensure it is logged in.');
921
932
  return false;
@@ -1297,10 +1308,13 @@ async function pollCycle() {
1297
1308
  const currentIds = new Set(agents.map((a) => a.agent_id));
1298
1309
  for (const prev of state.agents) {
1299
1310
  if (!currentIds.has(prev.agentId)) {
1300
- log(`Agent '${prev.codeName}' unassigned from host`);
1311
+ log(`Agent '${prev.codeName}' removed from host (deleted or unassigned)`);
1301
1312
  const adapter = resolveAgentFramework(prev.codeName);
1302
- clearAgentCaches(prev.agentId, prev.codeName);
1303
1313
  await stopGatewayIfRunning(prev.codeName, adapter);
1314
+ freePort(prev.codeName);
1315
+ const agentDir = join2(config.configDir, prev.codeName, "provision");
1316
+ await cleanupAgentFiles(prev.codeName, agentDir);
1317
+ clearAgentCaches(prev.agentId, prev.codeName);
1304
1318
  }
1305
1319
  }
1306
1320
  await healthCheckGateways(agentStates);
@@ -2534,8 +2548,23 @@ var realtimeDriftStarted = false;
2534
2548
  var realtimeKanbanStarted = false;
2535
2549
  var realtimeAssignStarted = false;
2536
2550
  var realtimeConfigStarted = false;
2551
+ var realtimeSubscribedAgentIds = /* @__PURE__ */ new Set();
2537
2552
  function ensureRealtimeStarted(agentStates) {
2538
- if (realtimeStarted) return;
2553
+ const currentActiveIds = new Set(
2554
+ agentStates.filter((a) => a.status === "active").map((a) => a.agentId)
2555
+ );
2556
+ if (realtimeStarted) {
2557
+ const sameSize = currentActiveIds.size === realtimeSubscribedAgentIds.size;
2558
+ const sameMembers = sameSize && [...currentActiveIds].every((id) => realtimeSubscribedAgentIds.has(id));
2559
+ if (sameMembers) return;
2560
+ log("[realtime] Agent set changed \u2014 reconnecting subscriptions");
2561
+ stopRealtimeChat();
2562
+ realtimeStarted = false;
2563
+ realtimeDriftStarted = false;
2564
+ realtimeAssignStarted = false;
2565
+ realtimeConfigStarted = false;
2566
+ realtimeKanbanStarted = false;
2567
+ }
2539
2568
  const activeAgentIds = agentStates.filter((a) => a.status === "active").map((a) => a.agentId);
2540
2569
  if (activeAgentIds.length === 0) return;
2541
2570
  const apiKey = process.env["AGT_API_KEY"];
@@ -2579,6 +2608,7 @@ function ensureRealtimeStarted(agentStates) {
2579
2608
  log
2580
2609
  });
2581
2610
  realtimeStarted = true;
2611
+ realtimeSubscribedAgentIds = new Set(activeAgentIds);
2582
2612
  log(`[realtime-chat] Started for ${activeAgentIds.length} agent(s)`);
2583
2613
  }).catch((err) => {
2584
2614
  log(`[realtime-chat] Failed to start: ${err.message}`);
@@ -3481,9 +3511,40 @@ function stopGatewayPool() {
3481
3511
  gatewayPool = null;
3482
3512
  }
3483
3513
  }
3514
+ var caffeinateProc = null;
3515
+ async function startCaffeinate() {
3516
+ if (process.platform !== "darwin") return;
3517
+ try {
3518
+ const { spawn: spawn2 } = await import("child_process");
3519
+ caffeinateProc = spawn2("caffeinate", ["-dims"], {
3520
+ stdio: "ignore",
3521
+ detached: false
3522
+ });
3523
+ caffeinateProc.on("error", (err) => {
3524
+ log(`caffeinate failed: ${err.message} \u2014 Mac may sleep during operation`);
3525
+ caffeinateProc = null;
3526
+ });
3527
+ caffeinateProc.on("exit", () => {
3528
+ caffeinateProc = null;
3529
+ });
3530
+ if (caffeinateProc.pid) {
3531
+ log(`caffeinate started (PID ${caffeinateProc.pid}) \u2014 Mac sleep prevented while manager is running`);
3532
+ }
3533
+ } catch (err) {
3534
+ log(`caffeinate not available: ${err.message} \u2014 Mac may sleep during operation`);
3535
+ }
3536
+ }
3537
+ function stopCaffeinate() {
3538
+ if (caffeinateProc) {
3539
+ caffeinateProc.kill();
3540
+ caffeinateProc = null;
3541
+ log("caffeinate stopped");
3542
+ }
3543
+ }
3484
3544
  function startPolling() {
3485
3545
  if (!config || running) return;
3486
3546
  running = true;
3547
+ void startCaffeinate();
3487
3548
  log(`Starting poll loop (interval=${config.intervalMs}ms, configDir=${config.configDir})`);
3488
3549
  void migrateToProfiles().then(() => {
3489
3550
  startGatewayPool();
@@ -3504,6 +3565,7 @@ async function stopPolling() {
3504
3565
  clearTimeout(pollTimer);
3505
3566
  pollTimer = null;
3506
3567
  }
3568
+ stopCaffeinate();
3507
3569
  stopRealtimeChat();
3508
3570
  stopGatewayPool();
3509
3571
  await stopAllGateways();