@integrity-labs/agt-cli 0.28.536 → 0.28.538

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.
@@ -42,7 +42,7 @@ import {
42
42
  resolveConnectivityProbe,
43
43
  worseConnectivityOutcome,
44
44
  wrapScheduledTaskPrompt
45
- } from "./chunk-TPJ57PWU.js";
45
+ } from "./chunk-N6HD5UG4.js";
46
46
  import {
47
47
  parsePsRows
48
48
  } from "./chunk-XWVM4KPK.js";
@@ -685,18 +685,81 @@ var TOKEN_RESOLVER_PRELUDE = `
685
685
  const AGT_HOST = (process.env.AGT_HOST || '').replace(/\\/+$/, '');
686
686
  const AGT_API_KEY = process.env.AGT_API_KEY || '';
687
687
  const AGT_AGENT_ID = process.env.AGT_AGENT_ID || '';
688
+ const SELF_FILE = __filename;
689
+
690
+ /**
691
+ * The agent ids the manager wrote into THIS agent's own .mcp.json.
692
+ *
693
+ * This program lives at <projectDir>/.claude/agt-bin/<name>, so the project dir
694
+ * is three dirnames up. Best-effort and never fatal: an agent with no .mcp.json,
695
+ * an unreadable file or a relocated bin dir yields [] and the caller stays quiet.
696
+ * Scraped with a regex rather than JSON.parse because the file is a rendered
697
+ * config that may carry unsubstituted variable placeholders in other fields, and
698
+ * a parse failure there must not swallow the identity we came for.
699
+ */
700
+ function mcpConfigAgentIds() {
701
+ try {
702
+ const { readFileSync } = require('node:fs');
703
+ const { dirname, join } = require('node:path');
704
+ const projectDir = dirname(dirname(dirname(SELF_FILE)));
705
+ const raw = readFileSync(join(projectDir, '.mcp.json'), 'utf8');
706
+ const ids = [];
707
+ const re = /"AGT_AGENT_ID"\\s*:\\s*"([0-9a-fA-F-]{8,})"/g;
708
+ let m;
709
+ while ((m = re.exec(raw)) !== null) {
710
+ if (ids.indexOf(m[1]) === -1) ids.push(m[1]);
711
+ }
712
+ return ids;
713
+ } catch {
714
+ return [];
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Extra sentence for the "Integration not found" case, which is the single most
720
+ * misleading response this program can get: it reads as "GitHub is disconnected"
721
+ * when the real cause can be that the PROCESS env carries a different agent's
722
+ * uuid than the one this agent actually is. That happened in the field - the
723
+ * .mcp.json blocks held the right id (they are rendered per agent) while the
724
+ * process env held a stale one inherited from elsewhere, so the broker was asked
725
+ * for an integration belonging to somebody else and answered, correctly, 404.
726
+ *
727
+ * DIAGNOSTIC ONLY. It deliberately does NOT fall back to the .mcp.json value.
728
+ * The broker authorises with the HOST key, which covers every agent on the host,
729
+ * so honouring an agent-writable file as the identity would let any agent mint
730
+ * another agent's GitHub token. The process env stays the only accepted source;
731
+ * a mismatch is something an operator fixes at the provisioner.
732
+ */
733
+ function identityMismatchHint() {
734
+ const ids = mcpConfigAgentIds();
735
+ if (ids.length === 0 || ids.indexOf(AGT_AGENT_ID) !== -1) return '';
736
+ return (
737
+ '\\naugmented: IDENTITY MISMATCH - process.env.AGT_AGENT_ID is ' + AGT_AGENT_ID +
738
+ ', but this agent\\'s own .mcp.json says ' + ids.join(', ') + '. The broker was ' +
739
+ 'asked for an integration belonging to a DIFFERENT agent, which is why it ' +
740
+ 'answered "not found". Your GitHub integration is probably fine. Fix the ' +
741
+ 'agent id the session was spawned with; this program will not use the ' +
742
+ '.mcp.json value, because that file is agent-writable and the broker ' +
743
+ 'authorises with the host key.'
744
+ );
745
+ }
688
746
 
689
747
  /**
690
748
  * Every failure exits through here, so an operator always gets a sentence that
691
749
  * names the credential fetch as the failing step. A bare 401 from GitHub sends
692
750
  * people auditing App permissions; "broker credential fetch failed: 503" sends
693
751
  * them at the API. Constraint D of ENG-8344.
752
+ *
753
+ * The agent id is echoed on every failure. It is not a secret, and a 404 whose
754
+ * message does not say WHICH agent was looked up is unfalsifiable from the
755
+ * operator's side.
694
756
  */
695
757
  function fail(reason) {
696
758
  process.stderr.write(
697
759
  'augmented: GitHub credential fetch failed: ' + reason + '\\n' +
698
760
  'augmented: the token is fetched per use from ' + (AGT_HOST || '<AGT_HOST unset>') +
699
- '${GITHUB_CREDENTIAL_PATH}' + ' (ENG-8344). This is NOT a GitHub permissions problem.\\n',
761
+ '${GITHUB_CREDENTIAL_PATH}' + ' for agent_id=' + (AGT_AGENT_ID || '<unset>') +
762
+ ' (ENG-8344). This is NOT a GitHub permissions problem.\\n',
700
763
  );
701
764
  process.exit(1);
702
765
  }
@@ -751,7 +814,7 @@ async function resolveToken() {
751
814
  { Authorization: 'Bearer ' + jwt },
752
815
  );
753
816
  } catch (err) {
754
- fail('broker credential fetch failed - ' + err.message);
817
+ fail('broker credential fetch failed - ' + err.message + identityMismatchHint());
755
818
  }
756
819
  const token = credential && credential.access_token;
757
820
  if (typeof token !== 'string' || token === '') {
@@ -5486,7 +5549,7 @@ function exchangeFailureKind(err) {
5486
5549
  }
5487
5550
 
5488
5551
  // src/lib/api-client.ts
5489
- var agtCliVersion = true ? "0.28.536" : "dev";
5552
+ var agtCliVersion = true ? "0.28.538" : "dev";
5490
5553
  var lastConfigHash = null;
5491
5554
  function setConfigHash(hash) {
5492
5555
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -8798,4 +8861,4 @@ export {
8798
8861
  managerInstallSystemUnitCommand,
8799
8862
  managerUninstallSystemUnitCommand
8800
8863
  };
8801
- //# sourceMappingURL=chunk-NOOKTWZP.js.map
8864
+ //# sourceMappingURL=chunk-XREQUTXK.js.map