@integrity-labs/agt-cli 0.28.1253 → 0.28.1254

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 (35) hide show
  1. package/dist/{api-client-5ZXNFF4W.js → api-client-EW7NBMWI.js} +3 -3
  2. package/dist/bin/agt.js +7 -7
  3. package/dist/{chunk-233HXJ2D.js → chunk-AZOT5URF.js} +2 -2
  4. package/dist/{chunk-UHT6L77A.js → chunk-EWD3K6YD.js} +40 -3
  5. package/dist/{chunk-UHT6L77A.js.map → chunk-EWD3K6YD.js.map} +1 -1
  6. package/dist/{chunk-2HF77X4C.js → chunk-FD3GWWVL.js} +3 -3
  7. package/dist/{chunk-UBGHZ2O2.js → chunk-SEXB6LTM.js} +194 -9
  8. package/dist/chunk-SEXB6LTM.js.map +1 -0
  9. package/dist/{chunk-CMLBFY5C.js → chunk-ZDON4IXL.js} +2 -2
  10. package/dist/{chunk-GRTMENH5.js → chunk-ZKLOPCWS.js} +20 -9
  11. package/dist/{chunk-GRTMENH5.js.map → chunk-ZKLOPCWS.js.map} +1 -1
  12. package/dist/{claude-code-updater-EKABTDXO.js → claude-code-updater-CHEL6LOF.js} +3 -3
  13. package/dist/{claude-pair-runtime-ZA24UQ7V.js → claude-pair-runtime-AGJH54AR.js} +3 -3
  14. package/dist/lib/manager-worker.js +50 -33
  15. package/dist/lib/manager-worker.js.map +1 -1
  16. package/dist/mcp/direct-chat-channel.js +33 -2
  17. package/dist/mcp/index.js +33 -2
  18. package/dist/mcp/origami.js +33 -2
  19. package/dist/mcp/remote-oauth-proxy.js +142 -5
  20. package/dist/mcp/slack-channel.js +33 -2
  21. package/dist/mcp/telegram-channel.js +33 -2
  22. package/dist/{persistent-session-HXK2Z6GH.js → persistent-session-HQPQPNPK.js} +4 -4
  23. package/dist/{responsiveness-probe-TPKISRGQ.js → responsiveness-probe-6GNSPLD2.js} +4 -4
  24. package/dist/{session-auth-dead-KMB35KRB.js → session-auth-dead-4Z24MU6C.js} +3 -3
  25. package/package.json +1 -1
  26. package/dist/chunk-UBGHZ2O2.js.map +0 -1
  27. /package/dist/{api-client-5ZXNFF4W.js.map → api-client-EW7NBMWI.js.map} +0 -0
  28. /package/dist/{chunk-233HXJ2D.js.map → chunk-AZOT5URF.js.map} +0 -0
  29. /package/dist/{chunk-2HF77X4C.js.map → chunk-FD3GWWVL.js.map} +0 -0
  30. /package/dist/{chunk-CMLBFY5C.js.map → chunk-ZDON4IXL.js.map} +0 -0
  31. /package/dist/{claude-code-updater-EKABTDXO.js.map → claude-code-updater-CHEL6LOF.js.map} +0 -0
  32. /package/dist/{claude-pair-runtime-ZA24UQ7V.js.map → claude-pair-runtime-AGJH54AR.js.map} +0 -0
  33. /package/dist/{persistent-session-HXK2Z6GH.js.map → persistent-session-HQPQPNPK.js.map} +0 -0
  34. /package/dist/{responsiveness-probe-TPKISRGQ.js.map → responsiveness-probe-6GNSPLD2.js.map} +0 -0
  35. /package/dist/{session-auth-dead-KMB35KRB.js.map → session-auth-dead-4Z24MU6C.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HOST_ROTATE_KEY_CONFLICT
3
- } from "./chunk-UHT6L77A.js";
3
+ } from "./chunk-EWD3K6YD.js";
4
4
 
5
5
  // src/lib/config.ts
6
6
  import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
@@ -103,7 +103,7 @@ function exchangeFailureKind(err) {
103
103
  }
104
104
 
105
105
  // src/lib/api-client.ts
106
- var agtCliVersion = true ? "0.28.1253" : "dev";
106
+ var agtCliVersion = true ? "0.28.1254" : "dev";
107
107
  var lastConfigHash = null;
108
108
  function setConfigHash(hash) {
109
109
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -468,4 +468,4 @@ export {
468
468
  api,
469
469
  getHostId
470
470
  };
471
- //# sourceMappingURL=chunk-2HF77X4C.js.map
471
+ //# sourceMappingURL=chunk-FD3GWWVL.js.map
@@ -2,7 +2,7 @@ import {
2
2
  exchangeApiKey,
3
3
  getApiKey,
4
4
  getHost
5
- } from "./chunk-2HF77X4C.js";
5
+ } from "./chunk-FD3GWWVL.js";
6
6
  import {
7
7
  LATE_BOUND_VARS,
8
8
  PLATFORM_DENY_PERMISSIONS,
@@ -23,11 +23,11 @@ import {
23
23
  requiresRemoteMcpToolGate,
24
24
  shellQuote,
25
25
  withheldRemoteMcpMessage
26
- } from "./chunk-GRTMENH5.js";
26
+ } from "./chunk-ZKLOPCWS.js";
27
27
  import {
28
28
  readDailySessionPin,
29
29
  sessionTranscriptDir
30
- } from "./chunk-CMLBFY5C.js";
30
+ } from "./chunk-ZDON4IXL.js";
31
31
  import {
32
32
  classifyUnanswerablePane,
33
33
  isConsumerTermsDialogVisible,
@@ -99,7 +99,7 @@ import {
99
99
  scanConfigForLiteralSecrets,
100
100
  worseConnectivityOutcome,
101
101
  wrapScheduledTaskPrompt
102
- } from "./chunk-UHT6L77A.js";
102
+ } from "./chunk-EWD3K6YD.js";
103
103
  import {
104
104
  claudeJsonPathFor,
105
105
  effectiveClaudeJsonPath,
@@ -2854,6 +2854,11 @@ function readExistingMcpEnvVar(codeName, serverId, envKey) {
2854
2854
  }
2855
2855
  }
2856
2856
  var PLACEHOLDER_LITERAL_RE = /\$\{[^}]+\}/;
2857
+ function currentOrResolvedBrokerAgentId(codeName, current) {
2858
+ if (current && !current.includes("${"))
2859
+ return current;
2860
+ return resolveBrokerAgentId(codeName);
2861
+ }
2857
2862
  function resolveBrokerAgentId(codeName, fallback) {
2858
2863
  const existing = readExistingMcpEnvVar(codeName, "cloud-broker", "AGT_AGENT_ID");
2859
2864
  if (existing && !PLACEHOLDER_LITERAL_RE.test(existing))
@@ -6102,7 +6107,18 @@ function buildMcpJson(input) {
6102
6107
  mcpServers[serverKey] = liveEntry;
6103
6108
  continue;
6104
6109
  }
6105
- const proxyEntry = buildOAuthRemoteMcpProxyEntry(integration.definition_id, remoteOAuthProxyPaths, connectionKey, integration.toolTiers);
6110
+ const proxyEntry = buildOAuthRemoteMcpProxyEntry(
6111
+ integration.definition_id,
6112
+ remoteOAuthProxyPaths,
6113
+ connectionKey,
6114
+ integration.toolTiers,
6115
+ // ENG-12046: a broker-delivered row has no token in .env.integrations, so
6116
+ // its proxy names the row and fetches the bearer per use.
6117
+ integration.credentialDelivery === "broker" ? integration.id : null,
6118
+ // CodeRabbit on 5ddf5d6d: the CURRENT agent id first; the on-disk
6119
+ // lookup only when it is missing or a placeholder.
6120
+ currentOrResolvedBrokerAgentId(input.agent.code_name, input.agent.agent_id)
6121
+ );
6106
6122
  if (proxyEntry) {
6107
6123
  mcpServers[serverKey] = proxyEntry;
6108
6124
  continue;
@@ -7416,7 +7432,15 @@ ${sections}`
7416
7432
  this.writeMcpServer(codeName, serverKey, liveEntry);
7417
7433
  continue;
7418
7434
  }
7419
- const proxyEntry = buildOAuthRemoteMcpProxyEntry(integration.definition_id, remoteOAuthProxyPaths, connectionKey, integration.toolTiers);
7435
+ const proxyEntry = buildOAuthRemoteMcpProxyEntry(
7436
+ integration.definition_id,
7437
+ remoteOAuthProxyPaths,
7438
+ connectionKey,
7439
+ integration.toolTiers,
7440
+ // ENG-12046: see the spawn-path call above.
7441
+ integration.credentialDelivery === "broker" ? integration.id : null,
7442
+ currentOrResolvedBrokerAgentId(codeName, agentId)
7443
+ );
7420
7444
  if (proxyEntry) {
7421
7445
  this.writeMcpServer(codeName, serverKey, proxyEntry);
7422
7446
  continue;
@@ -10456,6 +10480,121 @@ async function probeMcpStdio(config) {
10456
10480
  });
10457
10481
  }
10458
10482
 
10483
+ // ../../packages/core/dist/integrations/remote-mcp-broker-token.js
10484
+ var BROKER_TOKEN_EXPIRY_SKEW_MS = 6e4;
10485
+ var BROKER_TOKEN_UNKNOWN_EXPIRY_TTL_MS = 6e4;
10486
+ var BROKER_FETCH_TIMEOUT_MS = 15e3;
10487
+ function trimTrailingSlashes(host) {
10488
+ let end = host.length;
10489
+ while (end > 0 && host.charCodeAt(end - 1) === 47)
10490
+ end -= 1;
10491
+ return host.slice(0, end);
10492
+ }
10493
+ function brokerCredentialPath(integrationId) {
10494
+ return `/host/agent-integrations/${encodeURIComponent(integrationId)}/credential`;
10495
+ }
10496
+ var BROKER_FORCED_REFRESH_MIN_INTERVAL_MS = 5 * 60 * 1e3;
10497
+ function createBrokerTokenSource(config, deps = {}) {
10498
+ const fetchImpl = deps.fetchImpl ?? fetch;
10499
+ const now = deps.now ?? (() => Date.now());
10500
+ const host = trimTrailingSlashes(config.host);
10501
+ let cached = null;
10502
+ let inFlight = null;
10503
+ let refreshNext = false;
10504
+ let lastForcedRefreshAt = Number.NEGATIVE_INFINITY;
10505
+ let generation = 0;
10506
+ const missing = [
10507
+ !host ? "AGT_HOST" : null,
10508
+ !config.apiKey ? "AGT_API_KEY" : null,
10509
+ !config.agentId ? "AGT_AGENT_ID" : null,
10510
+ !config.integrationId ? "AGT_REMOTE_MCP_INTEGRATION_ID" : null
10511
+ ].filter((v) => v !== null);
10512
+ async function postJson(path, body, bearer) {
10513
+ let res;
10514
+ try {
10515
+ res = await fetchImpl(host + path, {
10516
+ method: "POST",
10517
+ headers: { "Content-Type": "application/json", ...bearer ? { Authorization: `Bearer ${bearer}` } : {} },
10518
+ body: JSON.stringify(body),
10519
+ signal: AbortSignal.timeout(BROKER_FETCH_TIMEOUT_MS)
10520
+ });
10521
+ } catch (err) {
10522
+ return { ok: false, reason: `cannot reach ${path} (${err instanceof Error ? err.message : String(err)})` };
10523
+ }
10524
+ const text = await res.text().catch(() => "");
10525
+ if (!res.ok) {
10526
+ let detail = "";
10527
+ let needsReauth = false;
10528
+ try {
10529
+ const parsed = JSON.parse(text);
10530
+ if (parsed && typeof parsed.error === "string")
10531
+ detail = `: ${parsed.error}`;
10532
+ needsReauth = parsed?.needs_reauth === true;
10533
+ } catch {
10534
+ }
10535
+ return { ok: false, reason: `${path} returned HTTP ${res.status}${detail}`, status: res.status, needsReauth };
10536
+ }
10537
+ try {
10538
+ return { ok: true, json: JSON.parse(text) };
10539
+ } catch {
10540
+ return { ok: false, reason: `${path} returned a non-JSON body` };
10541
+ }
10542
+ }
10543
+ async function fetchToken() {
10544
+ if (missing.length > 0)
10545
+ return { ok: false, reason: `${missing.join(", ")} not set in the proxy environment` };
10546
+ const startedAt = generation;
10547
+ const exchanged = await postJson("/host/exchange", { host_key: config.apiKey, agent_id: config.agentId });
10548
+ if (!exchanged.ok)
10549
+ return { ok: false, reason: `host key exchange failed - ${exchanged.reason}` };
10550
+ const jwt = exchanged.json?.token;
10551
+ if (typeof jwt !== "string" || jwt.length === 0)
10552
+ return { ok: false, reason: "host key exchange returned no token" };
10553
+ const onMissingExpiry = refreshNext ? "refresh" : "serve";
10554
+ if (refreshNext) {
10555
+ refreshNext = false;
10556
+ lastForcedRefreshAt = now();
10557
+ }
10558
+ const cred = await postJson(brokerCredentialPath(config.integrationId), { agent_id: config.agentId, on_missing_expiry: onMissingExpiry }, jwt);
10559
+ if (!cred.ok) {
10560
+ const needsReauth = cred.needsReauth === true || cred.status === 400;
10561
+ return { ok: false, reason: `credential fetch failed - ${cred.reason}`, ...needsReauth ? { needsReauth: true } : {} };
10562
+ }
10563
+ const body = cred.json;
10564
+ const token = body?.access_token;
10565
+ if (typeof token !== "string" || token.length === 0)
10566
+ return { ok: false, reason: "credential fetch returned no access_token" };
10567
+ const expiresAtMs = typeof body?.expires_at === "string" ? Date.parse(body.expires_at) : NaN;
10568
+ const freshUntil = Number.isFinite(expiresAtMs) ? expiresAtMs - BROKER_TOKEN_EXPIRY_SKEW_MS : now() + BROKER_TOKEN_UNKNOWN_EXPIRY_TTL_MS;
10569
+ cached = freshUntil > now() && startedAt === generation ? { token, freshUntil } : null;
10570
+ return { ok: true, token };
10571
+ }
10572
+ return {
10573
+ async get() {
10574
+ if (cached && cached.freshUntil > now())
10575
+ return { ok: true, token: cached.token };
10576
+ cached = null;
10577
+ if (!inFlight) {
10578
+ inFlight = fetchToken().finally(() => {
10579
+ inFlight = null;
10580
+ });
10581
+ }
10582
+ return inFlight;
10583
+ },
10584
+ /**
10585
+ * Drop the cached token, e.g. after the remote answered 401 with it. The
10586
+ * next fetch also asks for a refresh of a no-expiry row, at most once per
10587
+ * BROKER_FORCED_REFRESH_MIN_INTERVAL_MS.
10588
+ */
10589
+ invalidate() {
10590
+ cached = null;
10591
+ generation += 1;
10592
+ if (now() - lastForcedRefreshAt >= BROKER_FORCED_REFRESH_MIN_INTERVAL_MS)
10593
+ refreshNext = true;
10594
+ }
10595
+ };
10596
+ }
10597
+
10459
10598
  // src/lib/cli-probe.ts
10460
10599
  import { execFile as execFile2 } from "child_process";
10461
10600
  var DEFAULT_TIMEOUT_MS2 = 8e3;
@@ -10836,7 +10975,12 @@ function classifyMcpServer(entry) {
10836
10975
  const e = entry;
10837
10976
  if (typeof e.command === "string") {
10838
10977
  const env = e.env;
10839
- if (env && typeof env === "object" && typeof env["AGT_REMOTE_MCP_URL"] === "string" && typeof env["AGT_REMOTE_MCP_TOKEN_VAR"] === "string") {
10978
+ if (env && typeof env === "object" && typeof env["AGT_REMOTE_MCP_URL"] === "string" && // ENG-12046 (Obi Wan 74b5829c5d75): a broker-delivered proxy names its
10979
+ // integration row instead of a token var. Both are the remote-OAuth
10980
+ // proxy: without this a broker entry reads as plain stdio, losing the
10981
+ // ENG-7318 upstream-reachability check AND orphan-prune coverage
10982
+ // (orphanedRemoteMcpKeys keys on this kind).
10983
+ (typeof env["AGT_REMOTE_MCP_TOKEN_VAR"] === "string" || typeof env["AGT_REMOTE_MCP_INTEGRATION_ID"] === "string")) {
10840
10984
  return "oauth-proxy";
10841
10985
  }
10842
10986
  return "stdio";
@@ -11052,6 +11196,25 @@ async function runSessionToolBindProbes(integrations, options) {
11052
11196
  }
11053
11197
 
11054
11198
  // src/lib/connectivity-probe-context.ts
11199
+ function brokerProbeTokenKey(integrationId) {
11200
+ return `__AGT_BROKER_TOKEN__${integrationId}`;
11201
+ }
11202
+ async function withBrokerProbeToken(entry, probeEnv, deps = {}) {
11203
+ const integrationId = entry?.env?.[REMOTE_MCP_PROXY_ENV.integrationId];
11204
+ if (!entry?.command || typeof integrationId !== "string" || !integrationId) return probeEnv;
11205
+ const source = (deps.createSource ?? createBrokerTokenSource)({
11206
+ host: probeEnv["AGT_HOST"] ?? "",
11207
+ apiKey: probeEnv["AGT_API_KEY"] ?? "",
11208
+ agentId: probeEnv["AGT_AGENT_ID"] ?? "",
11209
+ integrationId
11210
+ });
11211
+ const r = await source.get();
11212
+ if (!r.ok) {
11213
+ console.warn(`[connectivity-probe] broker token prefetch failed for integration ${integrationId}: ${r.reason}`);
11214
+ return probeEnv;
11215
+ }
11216
+ return { ...probeEnv, [brokerProbeTokenKey(integrationId)]: r.token };
11217
+ }
11055
11218
  function resolveHttpServerEntry(entry, env) {
11056
11219
  const unresolved = /* @__PURE__ */ new Set();
11057
11220
  const sub = (value) => {
@@ -11071,6 +11234,15 @@ function resolveHttpServerEntry(entry, env) {
11071
11234
  }
11072
11235
  const proxyUrl = entry.env?.[REMOTE_MCP_PROXY_ENV.url];
11073
11236
  const tokenVar = entry.env?.[REMOTE_MCP_PROXY_ENV.tokenVar];
11237
+ const brokerIntegrationId = entry.env?.[REMOTE_MCP_PROXY_ENV.integrationId];
11238
+ if (entry.command && typeof proxyUrl === "string" && typeof brokerIntegrationId === "string" && brokerIntegrationId) {
11239
+ const url = sub(proxyUrl);
11240
+ const fetched = env?.[brokerProbeTokenKey(brokerIntegrationId)];
11241
+ if (typeof fetched !== "string" || fetched.length === 0) unresolved.add(`broker token for integration ${brokerIntegrationId}`);
11242
+ const { authHeader, extras } = readRemoteMcpAuthConfig(entry.env);
11243
+ const headers = buildForwardHeaders(typeof fetched === "string" ? fetched : "", authHeader, extras, () => null);
11244
+ return { url, headers, unresolved: [...unresolved] };
11245
+ }
11074
11246
  if (entry.command && typeof proxyUrl === "string" && typeof tokenVar === "string") {
11075
11247
  const url = sub(proxyUrl);
11076
11248
  const token = sub(`\${${tokenVar}}`);
@@ -11083,6 +11255,15 @@ function resolveHttpServerEntry(entry, env) {
11083
11255
  }
11084
11256
  return null;
11085
11257
  }
11258
+ function readMcpServerEntry(projectDir, serverKey) {
11259
+ try {
11260
+ const raw = readFileSync7(join7(projectDir, ".mcp.json"), "utf-8");
11261
+ const servers = JSON.parse(raw).mcpServers ?? {};
11262
+ return servers[serverKey] ?? null;
11263
+ } catch {
11264
+ return null;
11265
+ }
11266
+ }
11086
11267
  function readMcpHttpServerConfig(projectDir, serverKey, env) {
11087
11268
  let servers;
11088
11269
  try {
@@ -11211,7 +11392,11 @@ function buildConnectivityProbeDeps(projectDir, probeEnv) {
11211
11392
  runCli: (binary, args) => runCliProbe(binary, args, { env: probeEnv }),
11212
11393
  mcpProbe: async (target) => {
11213
11394
  const serverKey = target.inlineServerEntry ? target.serverKey : resolveDeclaredServerKey(projectDir, target.definitionId, target.serverKey) ?? target.serverKey;
11214
- const lookup = target.inlineServerEntry ? inlineEntryLookup(resolveHttpServerEntry(target.inlineServerEntry, probeEnv)) : readMcpHttpServerConfig(projectDir, serverKey, probeEnv);
11395
+ const entryEnv = await withBrokerProbeToken(
11396
+ target.inlineServerEntry ?? readMcpServerEntry(projectDir, serverKey),
11397
+ probeEnv
11398
+ );
11399
+ const lookup = target.inlineServerEntry ? inlineEntryLookup(resolveHttpServerEntry(target.inlineServerEntry, entryEnv)) : readMcpHttpServerConfig(projectDir, serverKey, entryEnv);
11215
11400
  if (!lookup.ok) {
11216
11401
  return verdictForUnavailableMcpConfig(lookup.cause, {
11217
11402
  serverKey,
@@ -13347,4 +13532,4 @@ export {
13347
13532
  managerInstallSystemUnitCommand,
13348
13533
  managerUninstallSystemUnitCommand
13349
13534
  };
13350
- //# sourceMappingURL=chunk-UBGHZ2O2.js.map
13535
+ //# sourceMappingURL=chunk-SEXB6LTM.js.map