@integrity-labs/agt-cli 0.28.1253 → 0.28.1255

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