@integrity-labs/agt-cli 0.10.19 → 0.10.22

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.
@@ -10,7 +10,7 @@ import {
10
10
  provisionStopHook,
11
11
  requireHost,
12
12
  resolveChannels
13
- } from "../chunk-XTETZ2D5.js";
13
+ } from "../chunk-VWYAPGHB.js";
14
14
  import {
15
15
  findTaskByTemplate,
16
16
  getProjectDir,
@@ -28,7 +28,7 @@ import {
28
28
  startPersistentSession,
29
29
  stopAllSessionsAndWait,
30
30
  stopPersistentSession
31
- } from "../chunk-B37H4CPW.js";
31
+ } from "../chunk-QALSARWM.js";
32
32
 
33
33
  // src/lib/manager-worker.ts
34
34
  import { createHash } from "crypto";
@@ -355,11 +355,7 @@ async function detectClaudeAuth() {
355
355
  if (!creds) return null;
356
356
  return computeSubscriptionStatus(creds);
357
357
  }
358
- async function readOauthCredentials() {
359
- if (platform() === "darwin") {
360
- const fromKeychain = await readMacKeychain();
361
- if (fromKeychain) return fromKeychain;
362
- }
358
+ async function findClaudeCredentialsPaths() {
363
359
  const candidates = [
364
360
  join(homedir(), ".claude", ".credentials.json"),
365
361
  join(homedir(), ".claude", "credentials.json")
@@ -376,6 +372,14 @@ async function readOauthCredentials() {
376
372
  } catch {
377
373
  }
378
374
  }
375
+ return candidates;
376
+ }
377
+ async function readOauthCredentials() {
378
+ if (platform() === "darwin") {
379
+ const fromKeychain = await readMacKeychain();
380
+ if (fromKeychain) return fromKeychain;
381
+ }
382
+ const candidates = await findClaudeCredentialsPaths();
379
383
  for (const path of candidates) {
380
384
  const parsed = await readJsonSilently(path);
381
385
  if (parsed) {
@@ -1328,7 +1332,7 @@ async function pollCycle() {
1328
1332
  }
1329
1333
  try {
1330
1334
  const { detectHostSecurity } = await import("../host-security-6PDFG7F5.js");
1331
- const { collectDiagnostics } = await import("../persistent-session-5YGASFOA.js");
1335
+ const { collectDiagnostics } = await import("../persistent-session-RPSYBZYO.js");
1332
1336
  const diagCodeNames = [...persistentSessionAgents];
1333
1337
  const agentDiagnostics = diagCodeNames.length > 0 ? collectDiagnostics(diagCodeNames) : void 0;
1334
1338
  let tailscaleHostname;
@@ -2796,6 +2800,7 @@ function fireClaudeWorkTrigger(codeName, agentId, boardItems) {
2796
2800
  });
2797
2801
  }
2798
2802
  var persistentSessionAgents = /* @__PURE__ */ new Set();
2803
+ var claudeAuthTupleBySession = /* @__PURE__ */ new Map();
2799
2804
  async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
2800
2805
  const codeName = agent.code_name;
2801
2806
  const projectDir = getProjectDir2(codeName);
@@ -2823,6 +2828,36 @@ async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
2823
2828
  return;
2824
2829
  }
2825
2830
  }
2831
+ let claudeAuthMode;
2832
+ let anthropicApiKey;
2833
+ let anthropicApiKeyFingerprint;
2834
+ try {
2835
+ const apiKey = getApiKey();
2836
+ if (!apiKey) {
2837
+ log(`[persistent-session] Skipping '${codeName}' \u2014 AGT_API_KEY not set`);
2838
+ return;
2839
+ }
2840
+ const exchange = await exchangeApiKey(apiKey, false, { forceRefresh: true });
2841
+ claudeAuthMode = exchange.claudeAuthMode;
2842
+ anthropicApiKey = exchange.anthropicApiKey;
2843
+ anthropicApiKeyFingerprint = exchange.anthropicApiKeyFingerprint;
2844
+ } catch (err) {
2845
+ const msg = err.message;
2846
+ log(`[persistent-session] Failed to resolve auth for '${codeName}': ${msg} \u2014 refusing to spawn`);
2847
+ if (isSessionHealthy(codeName)) {
2848
+ stopPersistentSession(codeName, log);
2849
+ persistentSessionAgents.delete(codeName);
2850
+ claudeAuthTupleBySession.delete(codeName);
2851
+ }
2852
+ return;
2853
+ }
2854
+ const currentAuthTuple = `${claudeAuthMode}:${anthropicApiKeyFingerprint ?? "none"}`;
2855
+ const recordedAuthTuple = claudeAuthTupleBySession.get(codeName);
2856
+ if (recordedAuthTuple && recordedAuthTuple !== currentAuthTuple && isSessionHealthy(codeName)) {
2857
+ log(`[persistent-session] Auth config changed for '${codeName}' (${recordedAuthTuple} \u2192 ${currentAuthTuple}) \u2014 restarting session`);
2858
+ stopPersistentSession(codeName, log);
2859
+ persistentSessionAgents.delete(codeName);
2860
+ }
2826
2861
  if (!isSessionHealthy(codeName)) {
2827
2862
  if (persistentSessionAgents.has(codeName)) {
2828
2863
  log(`[persistent-session] Session for '${codeName}' is unhealthy, will restart`);
@@ -2846,12 +2881,18 @@ async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
2846
2881
  channels,
2847
2882
  devChannels,
2848
2883
  apiHost: requireHost(),
2884
+ claudeAuthMode,
2885
+ anthropicApiKey,
2849
2886
  log
2850
2887
  });
2851
2888
  persistentSessionAgents.add(codeName);
2889
+ claudeAuthTupleBySession.set(codeName, currentAuthTuple);
2852
2890
  return;
2853
2891
  }
2854
2892
  resetRestartCount(codeName);
2893
+ if (!claudeAuthTupleBySession.has(codeName)) {
2894
+ claudeAuthTupleBySession.set(codeName, currentAuthTuple);
2895
+ }
2855
2896
  const stableTasksHash = createHash("sha256").update(JSON.stringify(tasks)).digest("hex").slice(0, 16);
2856
2897
  const prevHash = knownTasksHashes.get(agent.agent_id);
2857
2898
  if (stableTasksHash !== prevHash) {