@integrity-labs/agt-cli 0.28.26 → 0.28.28

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.
@@ -14032,6 +14032,26 @@ function readDirectChatSessionState(agentDir, nowMs) {
14032
14032
  }
14033
14033
  }
14034
14034
 
14035
+ // src/direct-chat-poll-guard.ts
14036
+ function evaluatePollGuard(state, nowMs, stuckMs) {
14037
+ if (!state.inFlight) return { run: true, stuck: false };
14038
+ if (state.inFlightSinceMs != null && nowMs - state.inFlightSinceMs >= stuckMs) {
14039
+ return { run: true, stuck: true };
14040
+ }
14041
+ return { run: false, stuck: false };
14042
+ }
14043
+ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
14044
+ const controller = new AbortController();
14045
+ const timer = setTimeout(() => {
14046
+ controller.abort(new Error(`request timed out after ${timeoutMs}ms`));
14047
+ }, timeoutMs);
14048
+ try {
14049
+ return await fetchImpl(input, { ...init, signal: controller.signal });
14050
+ } finally {
14051
+ clearTimeout(timer);
14052
+ }
14053
+ }
14054
+
14035
14055
  // src/mcp-spawn-lock.ts
14036
14056
  import {
14037
14057
  existsSync as existsSync2,
@@ -14163,13 +14183,14 @@ if (!AGT_HOST || !AGT_API_KEY || !AGT_AGENT_ID) {
14163
14183
  }
14164
14184
  var authToken = null;
14165
14185
  var authExpiry = 0;
14186
+ var HTTP_TIMEOUT_MS = 2e4;
14166
14187
  async function getAuthToken() {
14167
14188
  if (authToken && Date.now() < authExpiry) return authToken;
14168
- const res = await fetch(`${AGT_HOST}/host/exchange`, {
14189
+ const res = await fetchWithTimeout(`${AGT_HOST}/host/exchange`, {
14169
14190
  method: "POST",
14170
14191
  headers: { "Content-Type": "application/json" },
14171
14192
  body: JSON.stringify({ host_key: AGT_API_KEY })
14172
- });
14193
+ }, HTTP_TIMEOUT_MS);
14173
14194
  if (!res.ok) {
14174
14195
  const body = await res.text().catch(() => "");
14175
14196
  throw new Error(`Auth exchange failed (${res.status}): ${body.slice(0, 200)}`);
@@ -14181,26 +14202,26 @@ async function getAuthToken() {
14181
14202
  }
14182
14203
  async function apiPost(path, body) {
14183
14204
  const token = await getAuthToken();
14184
- const res = await fetch(`${AGT_HOST}${path}`, {
14205
+ const res = await fetchWithTimeout(`${AGT_HOST}${path}`, {
14185
14206
  method: "POST",
14186
14207
  headers: {
14187
14208
  "Content-Type": "application/json",
14188
14209
  Authorization: `Bearer ${token}`
14189
14210
  },
14190
14211
  body: JSON.stringify(body)
14191
- });
14212
+ }, HTTP_TIMEOUT_MS);
14192
14213
  if (res.status === 401) {
14193
14214
  authToken = null;
14194
14215
  authExpiry = 0;
14195
14216
  const freshToken = await getAuthToken();
14196
- return fetch(`${AGT_HOST}${path}`, {
14217
+ return fetchWithTimeout(`${AGT_HOST}${path}`, {
14197
14218
  method: "POST",
14198
14219
  headers: {
14199
14220
  "Content-Type": "application/json",
14200
14221
  Authorization: `Bearer ${freshToken}`
14201
14222
  },
14202
14223
  body: JSON.stringify(body)
14203
- });
14224
+ }, HTTP_TIMEOUT_MS);
14204
14225
  }
14205
14226
  return res;
14206
14227
  }
@@ -14383,7 +14404,13 @@ async function pollForMessages(sinceMs) {
14383
14404
  agent_id: AGT_AGENT_ID,
14384
14405
  ...typeof sinceMs === "number" ? { since_ms: sinceMs } : {}
14385
14406
  });
14386
- if (!res.ok) return;
14407
+ if (!res.ok) {
14408
+ process.stderr.write(
14409
+ `direct-chat-channel: poll returned HTTP ${res.status} \u2014 pull skipped this tick
14410
+ `
14411
+ );
14412
+ return;
14413
+ }
14387
14414
  const data = await res.json();
14388
14415
  const markProcessed = (id) => {
14389
14416
  processedIds.add(id);
@@ -14467,14 +14494,24 @@ var DOORBELL_ENABLED = resolveHostBooleanFlag({
14467
14494
  });
14468
14495
  var DOORBELL_FILE = "direct-chat-doorbell";
14469
14496
  var SAFETY_NET_POLL_MS = 3e4;
14470
- var pollInFlight = false;
14497
+ var POLL_STUCK_MS = 9e4;
14498
+ var pollGuard = { inFlight: false, inFlightSinceMs: null };
14471
14499
  async function pollOnce(sinceMs) {
14472
- if (pollInFlight) return;
14473
- pollInFlight = true;
14500
+ const decision = evaluatePollGuard(pollGuard, Date.now(), POLL_STUCK_MS);
14501
+ if (!decision.run) return;
14502
+ if (decision.stuck) {
14503
+ process.stderr.write(
14504
+ `direct-chat-channel: previous poll wedged >${POLL_STUCK_MS}ms \u2014 superseding so the pull loop self-heals
14505
+ `
14506
+ );
14507
+ }
14508
+ pollGuard.inFlight = true;
14509
+ pollGuard.inFlightSinceMs = Date.now();
14474
14510
  try {
14475
14511
  await pollForMessages(sinceMs);
14476
14512
  } finally {
14477
- pollInFlight = false;
14513
+ pollGuard.inFlight = false;
14514
+ pollGuard.inFlightSinceMs = null;
14478
14515
  }
14479
14516
  }
14480
14517
  var doorbellWatcher = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integrity-labs/agt-cli",
3
- "version": "0.28.26",
3
+ "version": "0.28.28",
4
4
  "description": "Augmented Team CLI — agent provisioning and management",
5
5
  "type": "module",
6
6
  "engines": {