@integrity-labs/agt-cli 0.28.1281 → 0.28.1282

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.
Files changed (30) hide show
  1. package/dist/{api-client-UW5GPDR5.js → api-client-5L5TDFEN.js} +3 -3
  2. package/dist/bin/agt.js +7 -7
  3. package/dist/{chunk-O5D6I72R.js → chunk-AG2YIBH2.js} +1 -1
  4. package/dist/chunk-AG2YIBH2.js.map +1 -0
  5. package/dist/{chunk-FQMFWJUD.js → chunk-EUD5VDGR.js} +2 -2
  6. package/dist/{chunk-CCWVPE2F.js → chunk-FP4Z5C4N.js} +3 -3
  7. package/dist/{chunk-A26WJ7TB.js → chunk-KZ55FIP5.js} +2 -2
  8. package/dist/{chunk-SHBU7NAQ.js → chunk-PLL64X3Q.js} +5 -5
  9. package/dist/{chunk-XNHTH267.js → chunk-URE73ODK.js} +3 -3
  10. package/dist/{claude-code-updater-L3NMDSSG.js → claude-code-updater-C7BXV6S7.js} +3 -3
  11. package/dist/{claude-pair-runtime-TUVLJDJZ.js → claude-pair-runtime-7W5TM3MA.js} +3 -3
  12. package/dist/lib/manager-worker.js +295 -24
  13. package/dist/lib/manager-worker.js.map +1 -1
  14. package/dist/mcp/index.js +1 -0
  15. package/dist/{persistent-session-LMR3WHVO.js → persistent-session-C6G3R6BI.js} +4 -4
  16. package/dist/{responsiveness-probe-FWPQTPQ5.js → responsiveness-probe-Q4GRRSHY.js} +4 -4
  17. package/dist/{session-auth-dead-5PNG5ILK.js → session-auth-dead-MAJHZEHU.js} +3 -3
  18. package/package.json +1 -1
  19. package/dist/chunk-O5D6I72R.js.map +0 -1
  20. /package/dist/{api-client-UW5GPDR5.js.map → api-client-5L5TDFEN.js.map} +0 -0
  21. /package/dist/{chunk-FQMFWJUD.js.map → chunk-EUD5VDGR.js.map} +0 -0
  22. /package/dist/{chunk-CCWVPE2F.js.map → chunk-FP4Z5C4N.js.map} +0 -0
  23. /package/dist/{chunk-A26WJ7TB.js.map → chunk-KZ55FIP5.js.map} +0 -0
  24. /package/dist/{chunk-SHBU7NAQ.js.map → chunk-PLL64X3Q.js.map} +0 -0
  25. /package/dist/{chunk-XNHTH267.js.map → chunk-URE73ODK.js.map} +0 -0
  26. /package/dist/{claude-code-updater-L3NMDSSG.js.map → claude-code-updater-C7BXV6S7.js.map} +0 -0
  27. /package/dist/{claude-pair-runtime-TUVLJDJZ.js.map → claude-pair-runtime-7W5TM3MA.js.map} +0 -0
  28. /package/dist/{persistent-session-LMR3WHVO.js.map → persistent-session-C6G3R6BI.js.map} +0 -0
  29. /package/dist/{responsiveness-probe-FWPQTPQ5.js.map → responsiveness-probe-Q4GRRSHY.js.map} +0 -0
  30. /package/dist/{session-auth-dead-5PNG5ILK.js.map → session-auth-dead-MAJHZEHU.js.map} +0 -0
@@ -70,7 +70,7 @@ import {
70
70
  tripClass,
71
71
  writeEtcEnvironment,
72
72
  writeProfileDScript
73
- } from "../chunk-SHBU7NAQ.js";
73
+ } from "../chunk-PLL64X3Q.js";
74
74
  import {
75
75
  ApiError,
76
76
  adoptHostKeyInProcess,
@@ -88,7 +88,7 @@ import {
88
88
  probeHostKey,
89
89
  requireHost,
90
90
  setConfigHash
91
- } from "../chunk-CCWVPE2F.js";
91
+ } from "../chunk-FP4Z5C4N.js";
92
92
  import {
93
93
  BLOCKED_ON_PROMPT_DECISION,
94
94
  CHANNEL_SECRET_ENV_KEYS,
@@ -180,7 +180,7 @@ import {
180
180
  webFetchBaselineValue,
181
181
  webFetchRestartNeeded,
182
182
  writeEgressAllowlist
183
- } from "../chunk-XNHTH267.js";
183
+ } from "../chunk-URE73ODK.js";
184
184
  import {
185
185
  isAgentIdle,
186
186
  isStaleForToday,
@@ -191,7 +191,7 @@ import {
191
191
  subagentActivityAgeSeconds,
192
192
  subagentTranscriptDir,
193
193
  transcriptActivityAgeSeconds
194
- } from "../chunk-FQMFWJUD.js";
194
+ } from "../chunk-EUD5VDGR.js";
195
195
  import {
196
196
  classifyUnanswerablePane,
197
197
  focusedConfirmDialogBlock,
@@ -217,7 +217,7 @@ import {
217
217
  runSafeCleanup,
218
218
  tightestDiskStat,
219
219
  withPackageCacheLock
220
- } from "../chunk-A26WJ7TB.js";
220
+ } from "../chunk-KZ55FIP5.js";
221
221
  import {
222
222
  parsePsRows,
223
223
  reapOrphanChannelMcps
@@ -346,7 +346,7 @@ import {
346
346
  stabiliseResetInstant,
347
347
  sumTranscriptUsageInWindow,
348
348
  summarizeTranscriptActivity
349
- } from "../chunk-O5D6I72R.js";
349
+ } from "../chunk-AG2YIBH2.js";
350
350
  import {
351
351
  CLAUDE_CONFIG_DIR_ENV,
352
352
  claudeConfigDirFor,
@@ -369,6 +369,157 @@ import {
369
369
  } from "../chunk-FIGZJ6AU.js";
370
370
  import "../chunk-DGUM43GV.js";
371
371
 
372
+ // src/lib/credit-exhaustion.ts
373
+ var CREDIT_EXHAUSTED_PATTERN = /credit balance (?:is )?too low/i;
374
+ var PANE_CREDIT_EXHAUSTED_PATTERN = /^credit balance (?:is )?too low\s*·\s*add funds\s*$/i;
375
+ var RECOVERY_REPORT_MS = 60 * 60 * 1e3;
376
+ var RESULT_LINE = /^\s+⎿\s*(.*)$/;
377
+ function isCreditExhaustedText(text) {
378
+ return typeof text === "string" && CREDIT_EXHAUSTED_PATTERN.test(text);
379
+ }
380
+ function isPaneCreditLine(line) {
381
+ return typeof line === "string" && PANE_CREDIT_EXHAUSTED_PATTERN.test(line);
382
+ }
383
+ function paneResultSighting(rawLog) {
384
+ if (typeof rawLog !== "string") return { ordinal: 0, latest: null };
385
+ const stripped = rawLog.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
386
+ let ordinal = 0;
387
+ let latest = null;
388
+ for (const line of stripped.split("\n")) {
389
+ const m = RESULT_LINE.exec(line);
390
+ if (m) {
391
+ ordinal += 1;
392
+ latest = (m[1] ?? "").trim();
393
+ }
394
+ }
395
+ return { ordinal, latest };
396
+ }
397
+ function isNewPaneResult(args) {
398
+ return args.previous !== void 0 && args.ordinal !== args.previous;
399
+ }
400
+ var PROBE_INTERVAL_MS = 10 * 60 * 1e3;
401
+ var PROBE_MODEL = "claude-haiku-4-5-20251001";
402
+ var CreditExhaustionTracker = class {
403
+ hitFingerprint = null;
404
+ lastHitMs = null;
405
+ lastEvidence = null;
406
+ lastSuccessMs = null;
407
+ successFingerprint = null;
408
+ lastProbeMs = null;
409
+ serverFlagFingerprint = null;
410
+ /**
411
+ * Record a sighting on the key with fingerprint `fp`. A string that does not
412
+ * match, or an unknown key, is ignored: a verdict that cannot be bound to a
413
+ * credential is not reported.
414
+ */
415
+ noteError(source, text, fp, nowMs) {
416
+ if (!isCreditExhaustedText(text) || !isFingerprint(fp)) return false;
417
+ this.hitFingerprint = fp;
418
+ this.lastHitMs = nowMs;
419
+ this.lastEvidence = `${source}: ${String(text).replace(/\s+/g, " ").trim().slice(0, 280)}`;
420
+ return true;
421
+ }
422
+ /** A probe on the key with fingerprint `fp` SUCCEEDED. */
423
+ noteSuccess(fp, nowMs) {
424
+ if (!isFingerprint(fp)) return;
425
+ this.lastSuccessMs = nowMs;
426
+ this.successFingerprint = fp;
427
+ }
428
+ /** Is the key with fingerprint `fp` out of credit, on the evidence held? */
429
+ isExhausted(fp) {
430
+ if (!isFingerprint(fp) || this.hitFingerprint !== fp || this.lastHitMs === null) return false;
431
+ return !(this.successFingerprint === fp && this.lastSuccessMs !== null && this.lastSuccessMs > this.lastHitMs);
432
+ }
433
+ /**
434
+ * The heartbeat response's stored flag: the fingerprint of the key the API
435
+ * holds as out of credit, or null. The STORED flag is the source of truth, so
436
+ * a restarted manager (which remembers no sighting), or one whose recovery
437
+ * report lapsed undelivered, keeps probing while the API still holds the flag.
438
+ */
439
+ noteServerFlag(fp) {
440
+ this.serverFlagFingerprint = isFingerprint(fp) ? fp : null;
441
+ }
442
+ /** Does the API's stored flag name exactly this (well-formed) key? */
443
+ serverFlagMatches(fp) {
444
+ return isFingerprint(fp) && this.serverFlagFingerprint === fp;
445
+ }
446
+ /**
447
+ * Is a probe due now? Only while flagged (on this process's evidence, or the
448
+ * API's stored flag for this key), at most once per interval.
449
+ *
450
+ * CodeRabbit on 5fc19a7069: an UNKNOWN local key (`fp` null, i.e. a restarted
451
+ * manager that has not run /host/exchange yet, which on a host with no agents
452
+ * is forever) counts as flagged when the API holds a flag. The caller then
453
+ * loads the key and re-checks with the real fingerprint, so a flag about some
454
+ * OTHER key never gets that key probed.
455
+ */
456
+ probeDue(fp, nowMs) {
457
+ const serverFlagged = this.serverFlagFingerprint !== null && (fp === null || fp === void 0 || this.serverFlagFingerprint === fp);
458
+ const flagged = this.isExhausted(fp) || serverFlagged;
459
+ if (!flagged) return false;
460
+ return this.lastProbeMs === null || nowMs - this.lastProbeMs >= PROBE_INTERVAL_MS;
461
+ }
462
+ /** Mark a probe as started. No retries: the next one waits a full interval. */
463
+ noteProbeStarted(nowMs) {
464
+ this.lastProbeMs = nowMs;
465
+ }
466
+ /**
467
+ * The heartbeat's `claude_credit` field for the CURRENT key, or undefined to
468
+ * omit it. Sent only on an `api_key` host with a known key fingerprint.
469
+ *
470
+ * - Exhausted on this key: sent.
471
+ * - A probe succeeded on this key within {@link RECOVERY_REPORT_MS}: sent as
472
+ * `exhausted: false`, so the API clears the status and closes the alert.
473
+ * - Anything about a different key, or no evidence: omitted.
474
+ */
475
+ heartbeatField(mode, fp, nowMs) {
476
+ if (mode !== "api_key" || !isFingerprint(fp)) return void 0;
477
+ if (this.isExhausted(fp)) {
478
+ return {
479
+ exhausted: true,
480
+ key_fingerprint: fp,
481
+ ...this.lastEvidence ? { evidence: this.lastEvidence } : {},
482
+ ...this.lastHitMs !== null ? { observed_at: new Date(this.lastHitMs).toISOString() } : {}
483
+ };
484
+ }
485
+ if (this.successFingerprint === fp && this.lastSuccessMs !== null && nowMs - this.lastSuccessMs < RECOVERY_REPORT_MS) {
486
+ return { exhausted: false, key_fingerprint: fp };
487
+ }
488
+ return void 0;
489
+ }
490
+ };
491
+ function isFingerprint(fp) {
492
+ return typeof fp === "string" && /^[0-9a-f]{8}$/.test(fp);
493
+ }
494
+ var creditExhaustion = new CreditExhaustionTracker();
495
+ async function probeCredit(apiKey, opts = {}) {
496
+ const doFetch = opts.fetchImpl ?? fetch;
497
+ let res;
498
+ try {
499
+ res = await doFetch(opts.url ?? "https://api.anthropic.com/v1/messages", {
500
+ method: "POST",
501
+ headers: { "Content-Type": "application/json", "x-api-key": apiKey, "anthropic-version": "2023-06-01" },
502
+ body: JSON.stringify({ model: PROBE_MODEL, max_tokens: 1, messages: [{ role: "user", content: "ok" }] }),
503
+ signal: AbortSignal.timeout(opts.timeoutMs ?? 15e3)
504
+ });
505
+ } catch (err) {
506
+ return { other: err?.name ?? "fetch_failed" };
507
+ }
508
+ if (res.ok) return "ok";
509
+ let message = "";
510
+ try {
511
+ const body = await res.json();
512
+ message = typeof body?.error?.message === "string" ? body.error.message : "";
513
+ } catch {
514
+ message = "";
515
+ }
516
+ return isCreditExhaustedText(message) ? "credit_exhausted" : { other: String(res.status) };
517
+ }
518
+ function evalBackendSharesHostKey(kind) {
519
+ const k = (kind ?? "").trim().toLowerCase();
520
+ return k === "" || k === "claude-p";
521
+ }
522
+
372
523
  // src/lib/manager-restart-gate.ts
373
524
  import { execFileSync } from "child_process";
374
525
  var MANAGER_RESTART_REASON = "manager-restart";
@@ -15285,7 +15436,7 @@ function createFileMigrationReportIO(codeName, log2) {
15285
15436
  };
15286
15437
  }
15287
15438
  var managerHostPost = async (path, body) => {
15288
- const { api: api2, ApiError: ApiError3 } = await import("../api-client-UW5GPDR5.js");
15439
+ const { api: api2, ApiError: ApiError3 } = await import("../api-client-5L5TDFEN.js");
15289
15440
  try {
15290
15441
  const json = await api2.post(path, body);
15291
15442
  return { status: 200, json };
@@ -17340,7 +17491,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
17340
17491
  var dayRolloverInboundHold = /* @__PURE__ */ new Map();
17341
17492
  var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
17342
17493
  async function channelInboundActivityAgeSecondsFor(codeName) {
17343
- const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-FWPQTPQ5.js");
17494
+ const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-Q4GRRSHY.js");
17344
17495
  const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
17345
17496
  if (newest === null) return null;
17346
17497
  return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
@@ -18221,7 +18372,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
18221
18372
  var lastVersionCheckAt = 0;
18222
18373
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
18223
18374
  var lastResponsivenessProbeAt = 0;
18224
- var agtCliVersion = true ? "0.28.1281" : "dev";
18375
+ var agtCliVersion = true ? "0.28.1282" : "dev";
18225
18376
  function resolveBrewPath(execFileSync5) {
18226
18377
  try {
18227
18378
  const out = execFileSync5("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -20025,6 +20176,103 @@ function hostFlagStore() {
20025
20176
  function shouldRenderIntegrationsSection() {
20026
20177
  return hostFlagStore().getBoolean("claude-md-integrations-section");
20027
20178
  }
20179
+ function creditContextAtStart() {
20180
+ return {
20181
+ fingerprint: creditHostKey.fingerprint,
20182
+ sharesHostKey: evalBackendSharesHostKey(hostFlagStore().getString("conversation-eval-backend"))
20183
+ };
20184
+ }
20185
+ function noteCreditFromError(source, err, atStart) {
20186
+ if (!atStart.sharesHostKey) return;
20187
+ if (atStart.fingerprint !== creditHostKey.fingerprint) return;
20188
+ const text = err instanceof Error ? err.message : typeof err === "string" ? err : null;
20189
+ if (creditExhaustion.noteError(source, text, atStart.fingerprint, Date.now())) {
20190
+ log(`[credit-exhaustion] ${source} hit "Credit balance is too low": this host's API key is out of Anthropic credit`);
20191
+ }
20192
+ }
20193
+ var creditHostKey = { key: null, fingerprint: null };
20194
+ function maybeProbeHostCredit() {
20195
+ const nowMs = Date.now();
20196
+ if (!creditExhaustion.probeDue(creditHostKey.fingerprint, nowMs)) return;
20197
+ const knownMode = getCachedClaudeAuthModeRaw();
20198
+ if (knownMode != null && knownMode !== "api_key") return;
20199
+ creditExhaustion.noteProbeStarted(nowMs);
20200
+ void (async () => {
20201
+ if (!creditHostKey.key) {
20202
+ const hostApiKey = getApiKey();
20203
+ if (!hostApiKey) {
20204
+ log("[credit-exhaustion] probe cannot run: flagged out of credit but AGT_API_KEY is not set");
20205
+ return;
20206
+ }
20207
+ try {
20208
+ const exchange = await exchangeApiKey(hostApiKey, false, { maxAgeMs: AUTH_EXCHANGE_MAX_AGE_MS });
20209
+ setCreditHostKey(exchange.anthropicApiKey ?? null, exchange.anthropicApiKeyFingerprint ?? null);
20210
+ } catch {
20211
+ log("[credit-exhaustion] probe cannot run: could not load the host API key (exchange failed); next try in one interval");
20212
+ return;
20213
+ }
20214
+ }
20215
+ const { key, fingerprint: fingerprint3 } = creditHostKey;
20216
+ if (getCachedClaudeAuthModeRaw() !== "api_key" || !key) {
20217
+ log("[credit-exhaustion] probe skipped: the host is not on an Anthropic API key");
20218
+ return;
20219
+ }
20220
+ if (!creditExhaustion.isExhausted(fingerprint3) && !creditExhaustion.serverFlagMatches(fingerprint3)) return;
20221
+ const outcome = await probeCredit(key);
20222
+ if (fingerprint3 !== creditHostKey.fingerprint) {
20223
+ log("[credit-exhaustion] probe result dropped: the host API key changed while the probe ran");
20224
+ return;
20225
+ }
20226
+ if (outcome === "ok") {
20227
+ creditExhaustion.noteSuccess(fingerprint3, Date.now());
20228
+ log("[credit-exhaustion] probe: the host API key has credit again; reporting the recovery");
20229
+ } else if (outcome === "credit_exhausted") {
20230
+ creditExhaustion.noteError("probe", "Credit balance is too low", fingerprint3, Date.now());
20231
+ log("[credit-exhaustion] probe: still out of Anthropic credit");
20232
+ } else {
20233
+ log(`[credit-exhaustion] probe inconclusive (${outcome.other}); next probe in one interval`);
20234
+ }
20235
+ })().catch(() => {
20236
+ log("[credit-exhaustion] probe failed to run; next probe in one interval");
20237
+ });
20238
+ }
20239
+ var creditPaneCheckedAt = /* @__PURE__ */ new Map();
20240
+ var creditPaneLastOrdinal = /* @__PURE__ */ new Map();
20241
+ var CREDIT_PANE_CHECK_INTERVAL_MS = 6e4;
20242
+ function setCreditHostKey(key, fingerprint3) {
20243
+ const changed = creditHostKey.fingerprint !== null && fingerprint3 !== creditHostKey.fingerprint;
20244
+ creditHostKey.key = key;
20245
+ creditHostKey.fingerprint = fingerprint3;
20246
+ if (!changed) return;
20247
+ for (const codeName of [...creditPaneLastOrdinal.keys()]) {
20248
+ try {
20249
+ creditPaneLastOrdinal.set(codeName, paneResultSighting(readFileSync39(paneLogPath(codeName), "utf-8")).ordinal);
20250
+ } catch {
20251
+ creditPaneLastOrdinal.delete(codeName);
20252
+ }
20253
+ }
20254
+ }
20255
+ function checkPaneForCreditExhaustion(codeName) {
20256
+ const nowMs = Date.now();
20257
+ const last = creditPaneCheckedAt.get(codeName);
20258
+ if (last !== void 0 && nowMs - last < CREDIT_PANE_CHECK_INTERVAL_MS) return;
20259
+ creditPaneCheckedAt.set(codeName, nowMs);
20260
+ let rawLog;
20261
+ try {
20262
+ rawLog = readFileSync39(paneLogPath(codeName), "utf-8");
20263
+ } catch {
20264
+ return;
20265
+ }
20266
+ const { ordinal, latest } = paneResultSighting(rawLog);
20267
+ const previous = creditPaneLastOrdinal.get(codeName);
20268
+ creditPaneLastOrdinal.set(codeName, ordinal);
20269
+ if (!isNewPaneResult({ ordinal, previous })) return;
20270
+ if (isPaneCreditLine(latest)) {
20271
+ if (creditExhaustion.noteError("pane", latest, creditHostKey.fingerprint, nowMs)) {
20272
+ log(`[credit-exhaustion] '${codeName}' pane: "${latest}": this host's API key is out of Anthropic credit`);
20273
+ }
20274
+ }
20275
+ }
20028
20276
  function reportManagerModelCallError(source, err, modelId) {
20029
20277
  try {
20030
20278
  if (!hostFlagStore().getBoolean("model-api-error-reporting")) return;
@@ -20235,7 +20483,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
20235
20483
  if (codeNames.length === 0) return;
20236
20484
  void (async () => {
20237
20485
  try {
20238
- const { collectDiagnostics } = await import("../persistent-session-LMR3WHVO.js");
20486
+ const { collectDiagnostics } = await import("../persistent-session-C6G3R6BI.js");
20239
20487
  await api.post("/host/heartbeat", {
20240
20488
  host_id: hostId,
20241
20489
  agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -20378,7 +20626,7 @@ async function pollCycleInner() {
20378
20626
  }
20379
20627
  try {
20380
20628
  const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
20381
- const { collectDiagnostics } = await import("../persistent-session-LMR3WHVO.js");
20629
+ const { collectDiagnostics } = await import("../persistent-session-C6G3R6BI.js");
20382
20630
  const diagCodeNames = [...agentState.persistentSessionAgents];
20383
20631
  const agentDiagnostics = diagCodeNames.length > 0 ? collectDiagnostics(diagCodeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor) : void 0;
20384
20632
  let tailscaleHostname;
@@ -20496,6 +20744,9 @@ async function pollCycleInner() {
20496
20744
  detected: claudeAuth,
20497
20745
  detectionFailed: claudeAuthDetectionFailed
20498
20746
  }),
20747
+ // ENG-12162: api_key hosts only; omitted when there is nothing to say,
20748
+ // and the API reads an omitted field as no signal (never a recovery).
20749
+ claude_credit: creditExhaustion.heartbeatField(getCachedClaudeAuthModeRaw(), creditHostKey.fingerprint, Date.now()),
20499
20750
  // OMITTED rather than sent as null when it cannot be read. The API
20500
20751
  // treats absence as "no observation" and leaves the stored label
20501
20752
  // alone; sending null would let a transient unreadable config WIPE a
@@ -20599,6 +20850,9 @@ async function pollCycleInner() {
20599
20850
  if (hbResp?.maintenance_window) {
20600
20851
  cachedMaintenanceWindow = hbResp.maintenance_window;
20601
20852
  }
20853
+ if (hbResp) {
20854
+ creditExhaustion.noteServerFlag(hbResp.claude_credit_exhausted?.key_fingerprint ?? null);
20855
+ }
20602
20856
  if (hbResp && Object.prototype.hasOwnProperty.call(hbResp, "claude_code_security_floor")) {
20603
20857
  const serverFloor = hbResp.claude_code_security_floor;
20604
20858
  cachedServerSecurityFloor = typeof serverFloor === "string" ? serverFloor : null;
@@ -20671,7 +20925,7 @@ async function pollCycleInner() {
20671
20925
  }
20672
20926
  try {
20673
20927
  const desiredClaudeCodeVersion = hbResp?.desired_claude_code_version?.trim();
20674
- const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-L3NMDSSG.js");
20928
+ const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-C7BXV6S7.js");
20675
20929
  const securityFloor = currentSecurityFloor();
20676
20930
  claudeUpdaterInFlight = true;
20677
20931
  if (desiredClaudeCodeVersion && (claudePairLoop.busy || claudePairingInProgress())) {
@@ -20706,7 +20960,7 @@ async function pollCycleInner() {
20706
20960
  collectPanelessActivityProbes,
20707
20961
  getResponsivenessIntervalMs,
20708
20962
  occupancyQualificationClassifications
20709
- } = await import("../responsiveness-probe-FWPQTPQ5.js");
20963
+ } = await import("../responsiveness-probe-Q4GRRSHY.js");
20710
20964
  const probeIntervalMs = getResponsivenessIntervalMs();
20711
20965
  if (now - lastResponsivenessProbeAt > probeIntervalMs) {
20712
20966
  const probeCodeNames = [...agentState.persistentSessionAgents];
@@ -20823,7 +21077,7 @@ async function pollCycleInner() {
20823
21077
  collectResponsivenessProbes,
20824
21078
  livePendingInboundOldestAgeSeconds,
20825
21079
  parkPendingInbound
20826
- } = await import("../responsiveness-probe-FWPQTPQ5.js");
21080
+ } = await import("../responsiveness-probe-Q4GRRSHY.js");
20827
21081
  const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
20828
21082
  const wedgeNow = /* @__PURE__ */ new Date();
20829
21083
  const liveAgents = agentState.persistentSessionAgents;
@@ -21109,7 +21363,7 @@ async function pollCycleInner() {
21109
21363
  }
21110
21364
  }
21111
21365
  );
21112
- const { parkPendingInbound } = await import("../responsiveness-probe-FWPQTPQ5.js");
21366
+ const { parkPendingInbound } = await import("../responsiveness-probe-Q4GRRSHY.js");
21113
21367
  const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
21114
21368
  paneFatalStreak.delete(codeName);
21115
21369
  paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
@@ -21140,7 +21394,7 @@ async function pollCycleInner() {
21140
21394
  TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
21141
21395
  bindSourceEscalations
21142
21396
  } = await import("../transcript-mount-health-OHE6IVJV.js");
21143
- const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-LMR3WHVO.js");
21397
+ const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-C6G3R6BI.js");
21144
21398
  const mountConfig = resolveTranscriptMountConfig();
21145
21399
  const liveAgents = agentState.persistentSessionAgents;
21146
21400
  for (const tracked of [
@@ -21305,7 +21559,7 @@ async function pollCycleInner() {
21305
21559
  }
21306
21560
  try {
21307
21561
  const { scrapeMcpFailedBannerCount } = await import("../pane-mcp-banner-scraper-VR5QGP3J.js");
21308
- const { probeSessionAuth } = await import("../session-auth-dead-5PNG5ILK.js");
21562
+ const { probeSessionAuth } = await import("../session-auth-dead-MAJHZEHU.js");
21309
21563
  const observations = [];
21310
21564
  const pendingCacheCommits = [];
21311
21565
  const modelApiErrorReportingOn = hostFlagStore().getBoolean("model-api-error-reporting");
@@ -21749,6 +22003,7 @@ async function pollCycleInner() {
21749
22003
  pollCycleBoardFetched = 0;
21750
22004
  pollCycleBoardGated = 0;
21751
22005
  boardTokenCache.resetStats();
22006
+ maybeProbeHostCredit();
21752
22007
  for (const agent of processOrder) {
21753
22008
  if (restartInFlight.has(agent.agent_id)) {
21754
22009
  const existing = state9.agents.find((a) => a.agentId === agent.agent_id);
@@ -22208,6 +22463,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
22208
22463
  agentFrameworkCache.set(agent.code_name, agent.framework);
22209
22464
  }
22210
22465
  if (agent.framework === "claude-code" && agent.status === "active") {
22466
+ checkPaneForCreditExhaustion(agent.code_name);
22211
22467
  void maybeReportUsageBanner({
22212
22468
  api,
22213
22469
  codeName: agent.code_name,
@@ -22239,24 +22495,32 @@ async function processAgent(agent, agentStates, managedToolkits) {
22239
22495
  }
22240
22496
  if (!scorerSuppressed) {
22241
22497
  const evalBackend = resolveConversationEvalBackend();
22498
+ const evalCredit = creditContextAtStart();
22242
22499
  void maybeEvaluateConversations({
22243
22500
  api,
22244
22501
  backend: evalBackend,
22245
22502
  codeName: agent.code_name,
22246
22503
  agentId: agent.agent_id,
22247
22504
  log,
22248
- onModelCallError: (err) => reportManagerModelCallError("conversation_eval", err, evalBackend.model ?? null)
22505
+ onModelCallError: (err) => {
22506
+ noteCreditFromError("conversation_eval", err, evalCredit);
22507
+ reportManagerModelCallError("conversation_eval", err, evalBackend.model ?? null);
22508
+ }
22249
22509
  });
22250
22510
  }
22251
22511
  if (memoryExtractionEnabled() && !scorerSuppressed) {
22252
22512
  const memBackend = resolveConversationEvalBackend();
22513
+ const memCredit = creditContextAtStart();
22253
22514
  void maybeExtractMemories({
22254
22515
  api,
22255
22516
  backend: memBackend,
22256
22517
  codeName: agent.code_name,
22257
22518
  agentId: agent.agent_id,
22258
22519
  log,
22259
- onModelCallError: (err) => reportManagerModelCallError("memory_extraction", err, memBackend.model ?? null)
22520
+ onModelCallError: (err) => {
22521
+ noteCreditFromError("memory_extraction", err, memCredit);
22522
+ reportManagerModelCallError("memory_extraction", err, memBackend.model ?? null);
22523
+ }
22260
22524
  });
22261
22525
  }
22262
22526
  if (toolCallAuditEnabled()) {
@@ -24488,7 +24752,13 @@ async function processAgent(agent, agentStates, managedToolkits) {
24488
24752
  const normalizedDetail = psResult.detail?.replace(/\s+/g, " ").trim();
24489
24753
  const detailSuffix = normalizedDetail ? ` detail=${JSON.stringify(normalizedDetail)}` : "";
24490
24754
  log(
24491
- `[persistent-session-decision] agent=${agent.code_name} decision=${psResult.decision} spawn_attempted=${psResult.spawnAttempted} session_healthy_after=${psResult.sessionHealthyAfter}${detailSuffix}`
24755
+ `[persistent-session-decision] agent=${agent.code_name} decision=${psResult.decision} spawn_attempted=${psResult.spawnAttempted} session_healthy_after=${psResult.sessionHealthyAfter}${detailSuffix}` + // ENG-12162 (AC4, as changed by Sherlock's ruling): the decision line
24756
+ // says the host key is out of credit, so a "healthy" read here can no
24757
+ // longer hide it. The decision ITSELF is left alone: rewriting it broke
24758
+ // the respawn-confirmation logic (Obi Wan 5b581c53073d, 9b95bff220e9).
24759
+ // CodeRabbit on 40a73e7d24: a restored server flag with no local hit (a
24760
+ // restarted manager, an inconclusive probe) is still out of credit.
24761
+ (creditExhaustion.isExhausted(creditHostKey.fingerprint) || creditExhaustion.serverFlagMatches(creditHostKey.fingerprint) ? " credit_exhausted=true" : "")
24492
24762
  );
24493
24763
  recordSpawnOutcome(agent.code_name, psResult);
24494
24764
  const stuck = persistentSessionStuckTracker.record({
@@ -25432,6 +25702,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
25432
25702
  claudeAuthMode = exchange.claudeAuthMode;
25433
25703
  anthropicApiKey = exchange.anthropicApiKey;
25434
25704
  anthropicApiKeyFingerprint = exchange.anthropicApiKeyFingerprint;
25705
+ setCreditHostKey(exchange.anthropicApiKey ?? null, exchange.anthropicApiKeyFingerprint ?? null);
25435
25706
  hostKind = exchange.hostKind;
25436
25707
  rawHostKey = apiKey;
25437
25708
  } catch (err) {
@@ -26374,7 +26645,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
26374
26645
  if (!refreshData) return;
26375
26646
  const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
26376
26647
  const hostId = await getHostId();
26377
- const parkForRestart = await import("../responsiveness-probe-FWPQTPQ5.js").then(
26648
+ const parkForRestart = await import("../responsiveness-probe-Q4GRRSHY.js").then(
26378
26649
  (m) => m.parkPendingInbound,
26379
26650
  (err) => err
26380
26651
  );
@@ -26451,7 +26722,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
26451
26722
  void api.post("/host/restart-ack", { host_id: hostId, agent_id: agentId, restart_requested_at: requestedAt }).catch((err) => log(`[restart-lane] ack failed for '${codeName}': ${err.message}`));
26452
26723
  void (async () => {
26453
26724
  try {
26454
- const { collectDiagnostics } = await import("../persistent-session-LMR3WHVO.js");
26725
+ const { collectDiagnostics } = await import("../persistent-session-C6G3R6BI.js");
26455
26726
  await api.post("/host/heartbeat", {
26456
26727
  host_id: hostId,
26457
26728
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -26504,7 +26775,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
26504
26775
  }
26505
26776
  try {
26506
26777
  const hostId = await getHostId();
26507
- const { collectDiagnostics } = await import("../persistent-session-LMR3WHVO.js");
26778
+ const { collectDiagnostics } = await import("../persistent-session-C6G3R6BI.js");
26508
26779
  await api.post("/host/heartbeat", {
26509
26780
  host_id: hostId,
26510
26781
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -27231,7 +27502,7 @@ async function processClaudePairSessions(agents) {
27231
27502
  snapshotPairConfig,
27232
27503
  // ENG-11659: result -> report body + the manager.log line that records it.
27233
27504
  planPairStartReport
27234
- } = await import("../claude-pair-runtime-TUVLJDJZ.js");
27505
+ } = await import("../claude-pair-runtime-7W5TM3MA.js");
27235
27506
  const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
27236
27507
  for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
27237
27508
  log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);