@memnexus-ai/mx-agent-cli 0.1.303 → 0.1.305
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.
- package/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +1 -1
- package/dist/agent-config/agents/bar-raiser.md +41 -1
- package/dist/agent-config/agents/git-expert.md +58 -54
- package/dist/agent-config/claude-md/CLAUDE.core.md +1 -1
- package/dist/agent-config/hooks/session-idle-gate.sh +14 -1
- package/dist/agent-config/hooks/subagent-write-guard.sh +198 -12
- package/dist/agent-config/hooks/worktree-guard.sh +8 -6
- package/dist/agent-config/skills/mx-post-merge-sync/SKILL.md +59 -51
- package/dist/commands/codex-agent-gate.d.ts +1 -2
- package/dist/commands/codex-agent-gate.d.ts.map +1 -1
- package/dist/commands/codex-agent-gate.js +1 -2
- package/dist/commands/codex-agent-gate.js.map +1 -1
- package/dist/commands/codex-deploy-config.d.ts +6 -0
- package/dist/commands/codex-deploy-config.d.ts.map +1 -1
- package/dist/commands/codex-deploy-config.js +28 -8
- package/dist/commands/codex-deploy-config.js.map +1 -1
- package/dist/commands/codex-prove-guards.d.ts +2 -0
- package/dist/commands/codex-prove-guards.d.ts.map +1 -1
- package/dist/commands/codex-prove-guards.js +31 -3
- package/dist/commands/codex-prove-guards.js.map +1 -1
- package/dist/commands/codex-trust-keys.d.ts +2 -0
- package/dist/commands/codex-trust-keys.d.ts.map +1 -1
- package/dist/commands/codex-trust-keys.js +27 -7
- package/dist/commands/codex-trust-keys.js.map +1 -1
- package/dist/commands/coordination.d.ts +16 -0
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +24 -2
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts +164 -7
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +293 -91
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/doctor.d.ts +17 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +33 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/gh.d.ts +3 -2
- package/dist/commands/gh.d.ts.map +1 -1
- package/dist/commands/gh.js +3 -2
- package/dist/commands/gh.js.map +1 -1
- package/dist/commands/new.d.ts +132 -17
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +426 -74
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/start.d.ts +6 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +105 -17
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +21 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-session.d.ts +11 -0
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +26 -7
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/behavioral-injection.d.ts.map +1 -1
- package/dist/lib/behavioral-injection.js +25 -7
- package/dist/lib/behavioral-injection.js.map +1 -1
- package/dist/lib/catalog-commit.d.ts.map +1 -1
- package/dist/lib/catalog-commit.js +17 -14
- package/dist/lib/catalog-commit.js.map +1 -1
- package/dist/lib/catalog.d.ts +93 -2
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +116 -9
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +28 -4
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/fleet-data.d.ts +98 -9
- package/dist/lib/fleet-data.d.ts.map +1 -1
- package/dist/lib/fleet-data.js +353 -34
- package/dist/lib/fleet-data.js.map +1 -1
- package/dist/lib/fleet-render.d.ts +8 -1
- package/dist/lib/fleet-render.d.ts.map +1 -1
- package/dist/lib/fleet-render.js +10 -3
- package/dist/lib/fleet-render.js.map +1 -1
- package/dist/lib/gh-remote.d.ts +15 -1
- package/dist/lib/gh-remote.d.ts.map +1 -1
- package/dist/lib/gh-remote.js +27 -2
- package/dist/lib/gh-remote.js.map +1 -1
- package/dist/lib/gh-token-run.d.ts +140 -14
- package/dist/lib/gh-token-run.d.ts.map +1 -1
- package/dist/lib/gh-token-run.js +187 -15
- package/dist/lib/gh-token-run.js.map +1 -1
- package/dist/lib/git-identity.d.ts +6 -2
- package/dist/lib/git-identity.d.ts.map +1 -1
- package/dist/lib/git-identity.js +17 -8
- package/dist/lib/git-identity.js.map +1 -1
- package/dist/lib/guarded-read.d.ts +15 -0
- package/dist/lib/guarded-read.d.ts.map +1 -0
- package/dist/lib/guarded-read.js +73 -0
- package/dist/lib/guarded-read.js.map +1 -0
- package/dist/lib/machine-setup.d.ts +165 -0
- package/dist/lib/machine-setup.d.ts.map +1 -0
- package/dist/lib/machine-setup.js +441 -0
- package/dist/lib/machine-setup.js.map +1 -0
- package/dist/lib/native-realpath.d.ts +70 -0
- package/dist/lib/native-realpath.d.ts.map +1 -0
- package/dist/lib/native-realpath.js +95 -0
- package/dist/lib/native-realpath.js.map +1 -0
- package/dist/lib/project-config.d.ts +2 -6
- package/dist/lib/project-config.d.ts.map +1 -1
- package/dist/lib/project-config.js.map +1 -1
- package/dist/lib/project-name.d.ts +15 -0
- package/dist/lib/project-name.d.ts.map +1 -0
- package/dist/lib/project-name.js +22 -0
- package/dist/lib/project-name.js.map +1 -0
- package/dist/lib/push-to.d.ts +113 -0
- package/dist/lib/push-to.d.ts.map +1 -0
- package/dist/lib/push-to.js +240 -0
- package/dist/lib/push-to.js.map +1 -0
- package/dist/lib/runtime/claude-gateway-routing.d.ts +161 -0
- package/dist/lib/runtime/claude-gateway-routing.d.ts.map +1 -0
- package/dist/lib/runtime/claude-gateway-routing.js +466 -0
- package/dist/lib/runtime/claude-gateway-routing.js.map +1 -0
- package/dist/lib/runtime/codex-adapter.d.ts +91 -5
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +204 -44
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +6 -12
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +17 -24
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/dist/lib/runtime/codex-guard-proof.d.ts +4 -7
- package/dist/lib/runtime/codex-guard-proof.d.ts.map +1 -1
- package/dist/lib/runtime/codex-guard-proof.js +16 -14
- package/dist/lib/runtime/codex-guard-proof.js.map +1 -1
- package/dist/lib/runtime/codex-hooks-list.d.ts +20 -0
- package/dist/lib/runtime/codex-hooks-list.d.ts.map +1 -1
- package/dist/lib/runtime/codex-hooks-list.js +20 -8
- package/dist/lib/runtime/codex-hooks-list.js.map +1 -1
- package/dist/lib/runtime/types.d.ts +1 -1
- package/dist/lib/runtime/types.d.ts.map +1 -1
- package/dist/lib/standards.d.ts +3 -0
- package/dist/lib/standards.d.ts.map +1 -1
- package/dist/lib/standards.js +1 -0
- package/dist/lib/standards.js.map +1 -1
- package/dist/lib/team-identity.d.ts.map +1 -1
- package/dist/lib/team-identity.js +18 -53
- package/dist/lib/team-identity.js.map +1 -1
- package/dist/lib/team-restore.d.ts +281 -0
- package/dist/lib/team-restore.d.ts.map +1 -0
- package/dist/lib/team-restore.js +533 -0
- package/dist/lib/team-restore.js.map +1 -0
- package/dist/lib/window-view.d.ts +5 -0
- package/dist/lib/window-view.d.ts.map +1 -1
- package/dist/lib/window-view.js +67 -6
- package/dist/lib/window-view.js.map +1 -1
- package/dist/lib/worktree-sync.d.ts +139 -11
- package/dist/lib/worktree-sync.d.ts.map +1 -1
- package/dist/lib/worktree-sync.js +327 -46
- package/dist/lib/worktree-sync.js.map +1 -1
- package/dist/standards/merge-gates.md +26 -0
- package/package.json +2 -2
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one destination. Adding another is a code change and a release (amendment 3, item 6).
|
|
3
|
+
*
|
|
4
|
+
* #1099: if the relay gains a second hostname (a prod host or a regional alias), add it
|
|
5
|
+
* to `GATEWAY_HOSTNAMES` below. Otherwise an inherited ANTHROPIC_BASE_URL pointing at the
|
|
6
|
+
* new host is not recognised as the relay, and no launcher strips it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CLAUDE_GATEWAY_URL = "https://relay.dev.memnexus.ai";
|
|
9
|
+
/** The `mx-agent.config.json` key. */
|
|
10
|
+
export declare const CLAUDE_GATEWAY_CONFIG_KEY = "claudeGatewayRouting";
|
|
11
|
+
/** Header the relay reads the caller token from. Pinned to `CALLER_TOKEN_HEADER` in hosted.rs by a test. */
|
|
12
|
+
export declare const RELAY_TOKEN_HEADER = "x-mx-relay-token";
|
|
13
|
+
/** Shortest token the relay accepts. Pinned to `MIN_TOKEN_CHARS` in hosted.rs by a test. */
|
|
14
|
+
export declare const MIN_RELAY_TOKEN_CHARS = 43;
|
|
15
|
+
/** Largest token file we will read. */
|
|
16
|
+
export declare const MAX_TOKEN_FILE_BYTES = 4096;
|
|
17
|
+
/** Per-start bypass. Only `off` (any case, trimmed) has any effect. */
|
|
18
|
+
export declare const GATEWAY_ROUTING_BYPASS_ENV = "MX_GATEWAY_ROUTING";
|
|
19
|
+
/** The env variables this module sets, and the inherited ones it warns about when it sets nothing. */
|
|
20
|
+
export declare const ROUTING_ENV_VARS: readonly ["ANTHROPIC_BASE_URL", "ANTHROPIC_CUSTOM_HEADERS"];
|
|
21
|
+
/**
|
|
22
|
+
* Claude Code provider switches. When one is set, Claude Code talks to that provider
|
|
23
|
+
* and ignores ANTHROPIC_BASE_URL, so a "routed" start would go elsewhere, possibly
|
|
24
|
+
* with the relay token (security review S2 on PR #1082). A listed team refuses.
|
|
25
|
+
*/
|
|
26
|
+
export declare const PROVIDER_SWITCH_VARS: readonly ["CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY"];
|
|
27
|
+
export declare const ROUTED_LINE = "Claude session routed through https://relay.dev.memnexus.ai (claudeGatewayRouting in mx-agent.config.json)";
|
|
28
|
+
export declare const BYPASS_LINE = "Gateway routing skipped for this start (MX_GATEWAY_ROUTING=off)";
|
|
29
|
+
/** A refusal. The message is fixed text: path and check name only, never a value or a length. */
|
|
30
|
+
export declare class ClaudeGatewayRoutingError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
/** `~/.mx-agent/gateway-ledger/team-tokens/<team>`. `team` must already be a validated slug. */
|
|
34
|
+
export declare function teamTokenPath(team: string, home?: string): string;
|
|
35
|
+
export declare const INVALID_JSON_WARNING: string;
|
|
36
|
+
export interface GatewayTeamsRead {
|
|
37
|
+
teams: string[];
|
|
38
|
+
/** Fixed-text warnings to print. Never holds file content. */
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read `claudeGatewayRouting.teams` from `<worktreePath>/mx-agent.config.json`.
|
|
43
|
+
*
|
|
44
|
+
* Absent file or absent key: `[]`. A present but malformed key throws, so a typo in
|
|
45
|
+
* the list refuses the start rather than silently sending a listed team direct.
|
|
46
|
+
*
|
|
47
|
+
* A file that is not valid JSON (red-team Step 6 #1): refuse only if its raw text
|
|
48
|
+
* contains the string `claudeGatewayRouting`, because then a team may be listed and
|
|
49
|
+
* the spec forbids falling back to direct for a listed team. Otherwise no team can
|
|
50
|
+
* be listed, so the start goes on unrouted with one fixed warning, as it did before
|
|
51
|
+
* this module existed (`loadProjectConfig` returns null for such a file).
|
|
52
|
+
*/
|
|
53
|
+
export declare function readClaudeGatewayTeams(worktreePath: string): string[];
|
|
54
|
+
export declare function readClaudeGatewayTeamsWithWarnings(worktreePath: string): GatewayTeamsRead;
|
|
55
|
+
/** Validate the key's value and return its team list. Throws a named reason on any defect. */
|
|
56
|
+
export declare function validateClaudeGatewayRouting(raw: unknown): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Read and check a team token file. Returns the token. Throws `ClaudeGatewayRoutingError`
|
|
59
|
+
* naming the path and the check, never the content or its length.
|
|
60
|
+
*
|
|
61
|
+
* Checks, in order: opened with O_NOFOLLOW (a symlink fails) and O_NONBLOCK (a FIFO
|
|
62
|
+
* cannot hang the open); `fstat` on the open
|
|
63
|
+
* descriptor shows a regular file, no group or other mode bits, size ≤ 4 KiB; after
|
|
64
|
+
* trimming exactly one trailing newline, at least MIN_RELAY_TOKEN_CHARS bytes, every
|
|
65
|
+
* byte in 0x21-0x7e except ',' (0x2c), which ANTHROPIC_CUSTOM_HEADERS may treat as a
|
|
66
|
+
* header separator (credential-custody review N1). The relay trims all trailing whitespace; this is stricter on
|
|
67
|
+
* purpose (amendment 2, bar-raiser addendum).
|
|
68
|
+
*/
|
|
69
|
+
export declare function readTeamToken(path: string): string;
|
|
70
|
+
export interface RoutingInputs {
|
|
71
|
+
worktreePath: string;
|
|
72
|
+
teamName: string;
|
|
73
|
+
/** The environment of `mx-agent start`. Read for the bypass and the inherited-variable warning only. */
|
|
74
|
+
env?: NodeJS.ProcessEnv;
|
|
75
|
+
platform?: NodeJS.Platform;
|
|
76
|
+
home?: string;
|
|
77
|
+
/** Injected for tests, so a test can prove the token file is never read. */
|
|
78
|
+
readToken?: (path: string) => string;
|
|
79
|
+
}
|
|
80
|
+
export type RoutingEnvVar = (typeof ROUTING_ENV_VARS)[number];
|
|
81
|
+
/**
|
|
82
|
+
* Every hostname the relay answers on, lower case, no trailing dot (#1099). Today it
|
|
83
|
+
* holds one entry, derived from CLAUDE_GATEWAY_URL. A second relay host is added here,
|
|
84
|
+
* as a literal entry, when one exists; see the comment on CLAUDE_GATEWAY_URL.
|
|
85
|
+
*/
|
|
86
|
+
export declare const GATEWAY_HOSTNAMES: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* True when `value` parses as a URL whose hostname is the relay's (#1097). The
|
|
89
|
+
* hostname, not `host`, is compared, so a port, scheme or letter-case variant of the
|
|
90
|
+
* relay address still matches: a miss here sends a token to the relay, and a false
|
|
91
|
+
* match only removes a variable that pointed at the relay anyway. A value that does
|
|
92
|
+
* not parse is not the relay. `hosts` defaults to GATEWAY_HOSTNAMES; a test passes a
|
|
93
|
+
* synthetic list to prove every entry is compared, not only the first (#1099).
|
|
94
|
+
*/
|
|
95
|
+
export declare function baseUrlIsGateway(value: string | undefined, hosts?: readonly string[]): boolean;
|
|
96
|
+
/** True when any newline-separated header line in `value` is an x-mx-relay-token header (#1097). */
|
|
97
|
+
export declare function headersHoldRelayToken(value: string | undefined): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The inherited routing variables that hold relay values (#1097): the ones a routed
|
|
100
|
+
* session gives its children. Reads the values to match them; returns names only.
|
|
101
|
+
*/
|
|
102
|
+
export declare function inheritedRelayVars(env: NodeJS.ProcessEnv): RoutingEnvVar[];
|
|
103
|
+
/**
|
|
104
|
+
* Remove inherited relay values from `env` IN PLACE (#1097, plan amendment 1):
|
|
105
|
+
* - ANTHROPIC_BASE_URL is deleted when its hostname is the relay's;
|
|
106
|
+
* - from ANTHROPIC_CUSTOM_HEADERS only the x-mx-relay-token lines are removed, the
|
|
107
|
+
* other lines are kept, and the variable is deleted only when no non-empty line
|
|
108
|
+
* remains.
|
|
109
|
+
* Returns the names of the variables changed. The one function every launcher uses:
|
|
110
|
+
* `applyClaudeGatewayRouting` (Claude Code), `buildAgentSessionEnv` (`--exp`), and,
|
|
111
|
+
* unconditionally, every Codex child env (#1099: `CodexAdapter.launch`, `codexChildEnv`,
|
|
112
|
+
* `codex trust-keys` and `codex prove-guards`).
|
|
113
|
+
*/
|
|
114
|
+
export declare function stripInheritedRelayVars(env: NodeJS.ProcessEnv | Record<string, string>): RoutingEnvVar[];
|
|
115
|
+
/** The line printed for a stripped relay variable. Names the variable, never a value. */
|
|
116
|
+
export declare function inheritedRelayRemovedLine(v: RoutingEnvVar): string;
|
|
117
|
+
export type RoutingDecision = {
|
|
118
|
+
kind: 'direct';
|
|
119
|
+
lines: string[];
|
|
120
|
+
warnings: string[];
|
|
121
|
+
/**
|
|
122
|
+
* Set only under the bypass for a listed team: drop inherited ANTHROPIC_BASE_URL
|
|
123
|
+
* and ANTHROPIC_CUSTOM_HEADERS so the bypass really goes direct even when the
|
|
124
|
+
* shell exports a gateway URL (wire-reliability review SF1).
|
|
125
|
+
*/
|
|
126
|
+
removeInherited?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Set for every direct decision for an unlisted team (#1097): strip inherited
|
|
129
|
+
* relay values from the child env with `stripInheritedRelayVars`.
|
|
130
|
+
*/
|
|
131
|
+
stripRelay?: boolean;
|
|
132
|
+
} | {
|
|
133
|
+
kind: 'routed';
|
|
134
|
+
lines: string[];
|
|
135
|
+
warnings: string[];
|
|
136
|
+
token: string;
|
|
137
|
+
};
|
|
138
|
+
export declare function setRoutingPlatformForTests(platform: NodeJS.Platform | undefined): void;
|
|
139
|
+
export declare function setRoutingHomeForTests(home: string | undefined): void;
|
|
140
|
+
/**
|
|
141
|
+
* Decide routing for one start. Throws `ClaudeGatewayRoutingError` on refusal.
|
|
142
|
+
* The returned `token` is only for `applyClaudeGatewayRouting`; never log a decision.
|
|
143
|
+
*/
|
|
144
|
+
export declare function resolveClaudeGatewayRouting(inputs: RoutingInputs): RoutingDecision;
|
|
145
|
+
/**
|
|
146
|
+
* Apply a decision to the child env IN PLACE. A `direct` decision touches nothing,
|
|
147
|
+
* which is what makes an unlisted launch byte-identical to before, except under the
|
|
148
|
+
* bypass for a listed team, where it removes the two inherited gateway variables, and
|
|
149
|
+
* for an unlisted team with inherited relay values, where it removes those (#1097).
|
|
150
|
+
*/
|
|
151
|
+
export declare function applyClaudeGatewayRouting(childEnv: NodeJS.ProcessEnv, decision: RoutingDecision): void;
|
|
152
|
+
/**
|
|
153
|
+
* The `--exp` (Agent SDK) check. A listed team refuses, because that launcher does
|
|
154
|
+
* not carry the routing env, and a listed team never silently goes direct. The
|
|
155
|
+
* bypass wins here too (amendment 4, item B). Never reads the token file.
|
|
156
|
+
* Returns the lines to print (the skipped line under the bypass, if listed, or the
|
|
157
|
+
* fixed invalid-JSON warning). Inherited relay values are stripped where the SDK
|
|
158
|
+
* child env is built, `buildAgentSessionEnv` in lib/agent-session.ts (#1097).
|
|
159
|
+
*/
|
|
160
|
+
export declare function assertExpRoutingAllowed(inputs: Omit<RoutingInputs, 'readToken' | 'home'>): string[];
|
|
161
|
+
//# sourceMappingURL=claude-gateway-routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-gateway-routing.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/claude-gateway-routing.ts"],"names":[],"mappings":"AA6DA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAElE,sCAAsC;AACtC,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAEhE,4GAA4G;AAC5G,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAErD,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,uCAAuC;AACvC,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,uEAAuE;AACvE,eAAO,MAAM,0BAA0B,uBAAuB,CAAC;AAE/D,sGAAsG;AACtG,eAAO,MAAM,gBAAgB,6DAA8D,CAAC;AAE5F;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,2FAIvB,CAAC;AAEX,eAAO,MAAM,WAAW,+GACsF,CAAC;AAC/G,eAAO,MAAM,WAAW,oEAA+E,CAAC;AAExG,iGAAiG;AACjG,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAkB,GAAG,MAAM,CAE5E;AAED,eAAO,MAAM,oBAAoB,QAEI,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8DAA8D;IAC9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hold
|
|
6
|
+
*
|
|
7
|
+
* "claudeGatewayRouting": { "teams": ["<slug>", ...] }
|
|
8
|
+
*
|
|
9
|
+
* When the starting team is listed, the Claude child process gets three changes to
|
|
10
|
+
* its environment and nothing else changes:
|
|
11
|
+
* - `ANTHROPIC_BASE_URL` = CLAUDE_GATEWAY_URL (a code constant, never config);
|
|
12
|
+
* - `ANTHROPIC_CUSTOM_HEADERS` = `x-mx-relay-token: <team token>`, overriding any
|
|
13
|
+
* inherited value;
|
|
14
|
+
* - `ANTHROPIC_API_KEY` and `ANTHROPIC_AUTH_TOKEN` removed (the relay refuses
|
|
15
|
+
* API-key sessions, #973, and an inherited auth token would reach the relay as a
|
|
16
|
+
* bearer header). `CLAUDE_CODE_OAUTH_TOKEN` is kept: the relay needs the
|
|
17
|
+
* subscription login.
|
|
18
|
+
* When the team is not listed, the env object is not touched, so the launch is
|
|
19
|
+
* byte-identical to the launch before this module existed, with one exception (#1097):
|
|
20
|
+
* an inherited ANTHROPIC_BASE_URL whose hostname is the relay's is removed, and an
|
|
21
|
+
* inherited ANTHROPIC_CUSTOM_HEADERS loses its x-mx-relay-token lines. Those are
|
|
22
|
+
* the values a routed session gives its children, and a nested start of an unlisted
|
|
23
|
+
* team would otherwise reach the relay on the parent team's token.
|
|
24
|
+
*
|
|
25
|
+
* WHERE THE SETTING IS READ. From the TEAM WORKTREE's `mx-agent.config.json`, never
|
|
26
|
+
* from the main checkout that start.ts loads through `findProjectRoot()`. The
|
|
27
|
+
* worktree copy is the rebased one a session actually runs from, and it is the same
|
|
28
|
+
* source `launchClaudeSession` already reads for `projectSlug` (#1080 amendment 3,
|
|
29
|
+
* item 1). `lib/project-config.ts` is deliberately NOT changed: it is on the
|
|
30
|
+
* provisioning path (create.ts, catalog.ts, memory.ts, init.ts, new.ts), and a
|
|
31
|
+
* malformed routing key must not break `provision` or `catalog` (amendment 2, Must
|
|
32
|
+
* Fix 1). `loadProjectConfig` therefore keeps ignoring this key as an unknown
|
|
33
|
+
* top-level key, and it is validated only here, at the worktree read.
|
|
34
|
+
*
|
|
35
|
+
* ORDER OF DECISIONS (amendment 4, item B):
|
|
36
|
+
* 1. `MX_GATEWAY_ROUTING=off` (any case, trimmed) wins over everything, including
|
|
37
|
+
* the win32 and `--exp` refusals. The token file is not read. When the team is
|
|
38
|
+
* listed (would have routed), inherited ANTHROPIC_BASE_URL and
|
|
39
|
+
* ANTHROPIC_CUSTOM_HEADERS are removed from the child env and the "skipped" line
|
|
40
|
+
* prints; an unlisted team gets case 2's strip of relay values only (#1097).
|
|
41
|
+
* 2. Team not listed: no change, except that inherited relay values are removed
|
|
42
|
+
* (#1097, see `inheritedRelayVars`). `bootstrap` is never listed, so it is always
|
|
43
|
+
* in this case.
|
|
44
|
+
* 3. Listed on win32: refuse (the token file's mode and symlink checks cannot be
|
|
45
|
+
* enforced there).
|
|
46
|
+
* 4. Listed with a provider switch (CLAUDE_CODE_USE_BEDROCK / _VERTEX / _FOUNDRY)
|
|
47
|
+
* set: refuse, since Claude Code would ignore the gateway URL.
|
|
48
|
+
* 5. Listed: read and check the token file; any failure refuses. Never direct.
|
|
49
|
+
* In cases 1 and 2 a warning names (never prints the value of) an inherited
|
|
50
|
+
* ANTHROPIC_BASE_URL or ANTHROPIC_CUSTOM_HEADERS: that it reaches the child unchanged,
|
|
51
|
+
* or, when it was removed, that it was removed.
|
|
52
|
+
*
|
|
53
|
+
* CREDENTIAL HANDLING. The token value, and its length, never appear in a message.
|
|
54
|
+
* Every refusal is fixed text naming the token file path and the check that failed.
|
|
55
|
+
* Nothing here logs an env object.
|
|
56
|
+
*/
|
|
57
|
+
import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync, existsSync, readSync } from 'fs';
|
|
58
|
+
import { homedir } from 'os';
|
|
59
|
+
import { join } from 'path';
|
|
60
|
+
import { isValidProjectSlug, PROJECT_SLUG_RE_SOURCE } from '../slug.js';
|
|
61
|
+
/**
|
|
62
|
+
* The one destination. Adding another is a code change and a release (amendment 3, item 6).
|
|
63
|
+
*
|
|
64
|
+
* #1099: if the relay gains a second hostname (a prod host or a regional alias), add it
|
|
65
|
+
* to `GATEWAY_HOSTNAMES` below. Otherwise an inherited ANTHROPIC_BASE_URL pointing at the
|
|
66
|
+
* new host is not recognised as the relay, and no launcher strips it.
|
|
67
|
+
*/
|
|
68
|
+
export const CLAUDE_GATEWAY_URL = 'https://relay.dev.memnexus.ai';
|
|
69
|
+
/** The `mx-agent.config.json` key. */
|
|
70
|
+
export const CLAUDE_GATEWAY_CONFIG_KEY = 'claudeGatewayRouting';
|
|
71
|
+
/** Header the relay reads the caller token from. Pinned to `CALLER_TOKEN_HEADER` in hosted.rs by a test. */
|
|
72
|
+
export const RELAY_TOKEN_HEADER = 'x-mx-relay-token';
|
|
73
|
+
/** Shortest token the relay accepts. Pinned to `MIN_TOKEN_CHARS` in hosted.rs by a test. */
|
|
74
|
+
export const MIN_RELAY_TOKEN_CHARS = 43;
|
|
75
|
+
/** Largest token file we will read. */
|
|
76
|
+
export const MAX_TOKEN_FILE_BYTES = 4096;
|
|
77
|
+
/** Per-start bypass. Only `off` (any case, trimmed) has any effect. */
|
|
78
|
+
export const GATEWAY_ROUTING_BYPASS_ENV = 'MX_GATEWAY_ROUTING';
|
|
79
|
+
/** The env variables this module sets, and the inherited ones it warns about when it sets nothing. */
|
|
80
|
+
export const ROUTING_ENV_VARS = ['ANTHROPIC_BASE_URL', 'ANTHROPIC_CUSTOM_HEADERS'];
|
|
81
|
+
/**
|
|
82
|
+
* Claude Code provider switches. When one is set, Claude Code talks to that provider
|
|
83
|
+
* and ignores ANTHROPIC_BASE_URL, so a "routed" start would go elsewhere, possibly
|
|
84
|
+
* with the relay token (security review S2 on PR #1082). A listed team refuses.
|
|
85
|
+
*/
|
|
86
|
+
export const PROVIDER_SWITCH_VARS = [
|
|
87
|
+
'CLAUDE_CODE_USE_BEDROCK',
|
|
88
|
+
'CLAUDE_CODE_USE_VERTEX',
|
|
89
|
+
'CLAUDE_CODE_USE_FOUNDRY',
|
|
90
|
+
];
|
|
91
|
+
export const ROUTED_LINE = `Claude session routed through ${CLAUDE_GATEWAY_URL} (${CLAUDE_GATEWAY_CONFIG_KEY} in mx-agent.config.json)`;
|
|
92
|
+
export const BYPASS_LINE = `Gateway routing skipped for this start (${GATEWAY_ROUTING_BYPASS_ENV}=off)`;
|
|
93
|
+
/** A refusal. The message is fixed text: path and check name only, never a value or a length. */
|
|
94
|
+
export class ClaudeGatewayRoutingError extends Error {
|
|
95
|
+
constructor(message) {
|
|
96
|
+
super(message);
|
|
97
|
+
this.name = 'ClaudeGatewayRoutingError';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** `~/.mx-agent/gateway-ledger/team-tokens/<team>`. `team` must already be a validated slug. */
|
|
101
|
+
export function teamTokenPath(team, home = homedir()) {
|
|
102
|
+
return join(home, '.mx-agent', 'gateway-ledger', 'team-tokens', team);
|
|
103
|
+
}
|
|
104
|
+
export const INVALID_JSON_WARNING = `mx-agent.config.json in the worktree is not valid JSON and does not mention ${CLAUDE_GATEWAY_CONFIG_KEY}; ` +
|
|
105
|
+
`starting without gateway routing.`;
|
|
106
|
+
/**
|
|
107
|
+
* Read `claudeGatewayRouting.teams` from `<worktreePath>/mx-agent.config.json`.
|
|
108
|
+
*
|
|
109
|
+
* Absent file or absent key: `[]`. A present but malformed key throws, so a typo in
|
|
110
|
+
* the list refuses the start rather than silently sending a listed team direct.
|
|
111
|
+
*
|
|
112
|
+
* A file that is not valid JSON (red-team Step 6 #1): refuse only if its raw text
|
|
113
|
+
* contains the string `claudeGatewayRouting`, because then a team may be listed and
|
|
114
|
+
* the spec forbids falling back to direct for a listed team. Otherwise no team can
|
|
115
|
+
* be listed, so the start goes on unrouted with one fixed warning, as it did before
|
|
116
|
+
* this module existed (`loadProjectConfig` returns null for such a file).
|
|
117
|
+
*/
|
|
118
|
+
export function readClaudeGatewayTeams(worktreePath) {
|
|
119
|
+
return readClaudeGatewayTeamsWithWarnings(worktreePath).teams;
|
|
120
|
+
}
|
|
121
|
+
export function readClaudeGatewayTeamsWithWarnings(worktreePath) {
|
|
122
|
+
const configPath = join(worktreePath, 'mx-agent.config.json');
|
|
123
|
+
if (!existsSync(configPath))
|
|
124
|
+
return { teams: [], warnings: [] };
|
|
125
|
+
const text = readFileSync(configPath, 'utf-8');
|
|
126
|
+
let parsed;
|
|
127
|
+
try {
|
|
128
|
+
parsed = JSON.parse(text);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
if (!text.includes(CLAUDE_GATEWAY_CONFIG_KEY)) {
|
|
132
|
+
return { teams: [], warnings: [INVALID_JSON_WARNING] };
|
|
133
|
+
}
|
|
134
|
+
throw new ClaudeGatewayRoutingError(`${configPath} could not be parsed as JSON, so "${CLAUDE_GATEWAY_CONFIG_KEY}" cannot be read. ` +
|
|
135
|
+
`Fix the file, or start with ${GATEWAY_ROUTING_BYPASS_ENV}=off.`);
|
|
136
|
+
}
|
|
137
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
138
|
+
return { teams: [], warnings: [] };
|
|
139
|
+
const raw = parsed[CLAUDE_GATEWAY_CONFIG_KEY];
|
|
140
|
+
if (raw === undefined)
|
|
141
|
+
return { teams: [], warnings: [] };
|
|
142
|
+
return { teams: validateClaudeGatewayRouting(raw), warnings: [] };
|
|
143
|
+
}
|
|
144
|
+
/** Validate the key's value and return its team list. Throws a named reason on any defect. */
|
|
145
|
+
export function validateClaudeGatewayRouting(raw) {
|
|
146
|
+
const where = `mx-agent.config.json: "${CLAUDE_GATEWAY_CONFIG_KEY}"`;
|
|
147
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
148
|
+
throw new ClaudeGatewayRoutingError(`${where} must be an object of the form { "teams": [...] }.`);
|
|
149
|
+
}
|
|
150
|
+
for (const key of Object.keys(raw)) {
|
|
151
|
+
if (key !== 'teams') {
|
|
152
|
+
throw new ClaudeGatewayRoutingError(`${where} has an unknown key "${sanitizeForMessage(key)}". "teams" is the only key; the URL is fixed in code.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const teams = raw.teams;
|
|
156
|
+
if (teams === undefined)
|
|
157
|
+
return [];
|
|
158
|
+
if (!Array.isArray(teams)) {
|
|
159
|
+
throw new ClaudeGatewayRoutingError(`${where}.teams must be an array of team slugs.`);
|
|
160
|
+
}
|
|
161
|
+
for (const team of teams) {
|
|
162
|
+
if (typeof team !== 'string' || !isValidProjectSlug(team)) {
|
|
163
|
+
throw new ClaudeGatewayRoutingError(`${where}.teams holds an entry that is not a team slug (${PROJECT_SLUG_RE_SOURCE}, no "--", not "all").`);
|
|
164
|
+
}
|
|
165
|
+
if (team === 'bootstrap') {
|
|
166
|
+
throw new ClaudeGatewayRoutingError(`${where}.teams lists "bootstrap". The team that builds the start path is never routed.`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return teams;
|
|
170
|
+
}
|
|
171
|
+
/** Keep a config key printable and short in a refusal message. */
|
|
172
|
+
function sanitizeForMessage(s) {
|
|
173
|
+
return s.replace(/[^\x21-\x7e]/g, '?').slice(0, 64);
|
|
174
|
+
}
|
|
175
|
+
function tokenRefusal(path, check) {
|
|
176
|
+
return new ClaudeGatewayRoutingError(`Gateway routing refused: token file ${path} failed the ${check}. ` +
|
|
177
|
+
`The token is not shown. Start with ${GATEWAY_ROUTING_BYPASS_ENV}=off to go direct for this start.`);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Read and check a team token file. Returns the token. Throws `ClaudeGatewayRoutingError`
|
|
181
|
+
* naming the path and the check, never the content or its length.
|
|
182
|
+
*
|
|
183
|
+
* Checks, in order: opened with O_NOFOLLOW (a symlink fails) and O_NONBLOCK (a FIFO
|
|
184
|
+
* cannot hang the open); `fstat` on the open
|
|
185
|
+
* descriptor shows a regular file, no group or other mode bits, size ≤ 4 KiB; after
|
|
186
|
+
* trimming exactly one trailing newline, at least MIN_RELAY_TOKEN_CHARS bytes, every
|
|
187
|
+
* byte in 0x21-0x7e except ',' (0x2c), which ANTHROPIC_CUSTOM_HEADERS may treat as a
|
|
188
|
+
* header separator (credential-custody review N1). The relay trims all trailing whitespace; this is stricter on
|
|
189
|
+
* purpose (amendment 2, bar-raiser addendum).
|
|
190
|
+
*/
|
|
191
|
+
export function readTeamToken(path) {
|
|
192
|
+
let fd;
|
|
193
|
+
try {
|
|
194
|
+
// O_NONBLOCK: a FIFO at the path would otherwise block this open until a writer
|
|
195
|
+
// appears, hanging start before the fstat regular-file check can refuse it
|
|
196
|
+
// (wire-reliability review). It has no effect on reads from a regular file.
|
|
197
|
+
fd = openSync(path, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
const code = err.code;
|
|
201
|
+
if (code === 'ENOENT')
|
|
202
|
+
throw tokenRefusal(path, 'exists check');
|
|
203
|
+
if (code === 'ELOOP')
|
|
204
|
+
throw tokenRefusal(path, 'no-symlink check');
|
|
205
|
+
throw tokenRefusal(path, 'open check');
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const st = fstatSync(fd);
|
|
209
|
+
if (!st.isFile())
|
|
210
|
+
throw tokenRefusal(path, 'regular-file check');
|
|
211
|
+
if ((st.mode & 0o077) !== 0)
|
|
212
|
+
throw tokenRefusal(path, 'permission check (no group or other access)');
|
|
213
|
+
if (st.size > MAX_TOKEN_FILE_BYTES)
|
|
214
|
+
throw tokenRefusal(path, 'size check');
|
|
215
|
+
// Read one byte past the cap so a file that grew after fstat is still refused.
|
|
216
|
+
const buf = Buffer.alloc(MAX_TOKEN_FILE_BYTES + 1);
|
|
217
|
+
let total = 0;
|
|
218
|
+
for (;;) {
|
|
219
|
+
const n = readSync(fd, buf, total, buf.length - total, null);
|
|
220
|
+
if (n === 0)
|
|
221
|
+
break;
|
|
222
|
+
total += n;
|
|
223
|
+
if (total >= buf.length)
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (total > MAX_TOKEN_FILE_BYTES)
|
|
227
|
+
throw tokenRefusal(path, 'size check');
|
|
228
|
+
let end = total;
|
|
229
|
+
if (end > 0 && buf[end - 1] === 0x0a)
|
|
230
|
+
end -= 1;
|
|
231
|
+
let ok = end >= MIN_RELAY_TOKEN_CHARS;
|
|
232
|
+
for (let i = 0; ok && i < end; i++) {
|
|
233
|
+
const b = buf[i];
|
|
234
|
+
if (b < 0x21 || b > 0x7e || b === 0x2c)
|
|
235
|
+
ok = false;
|
|
236
|
+
}
|
|
237
|
+
if (!ok) {
|
|
238
|
+
buf.fill(0);
|
|
239
|
+
throw tokenRefusal(path, 'length or character check');
|
|
240
|
+
}
|
|
241
|
+
const token = buf.toString('latin1', 0, end);
|
|
242
|
+
buf.fill(0);
|
|
243
|
+
return token;
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
closeSync(fd);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function normalizeHostname(hostname) {
|
|
250
|
+
return hostname.toLowerCase().replace(/\.$/, '');
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Every hostname the relay answers on, lower case, no trailing dot (#1099). Today it
|
|
254
|
+
* holds one entry, derived from CLAUDE_GATEWAY_URL. A second relay host is added here,
|
|
255
|
+
* as a literal entry, when one exists; see the comment on CLAUDE_GATEWAY_URL.
|
|
256
|
+
*/
|
|
257
|
+
export const GATEWAY_HOSTNAMES = [normalizeHostname(new URL(CLAUDE_GATEWAY_URL).hostname)];
|
|
258
|
+
/**
|
|
259
|
+
* True when `value` parses as a URL whose hostname is the relay's (#1097). The
|
|
260
|
+
* hostname, not `host`, is compared, so a port, scheme or letter-case variant of the
|
|
261
|
+
* relay address still matches: a miss here sends a token to the relay, and a false
|
|
262
|
+
* match only removes a variable that pointed at the relay anyway. A value that does
|
|
263
|
+
* not parse is not the relay. `hosts` defaults to GATEWAY_HOSTNAMES; a test passes a
|
|
264
|
+
* synthetic list to prove every entry is compared, not only the first (#1099).
|
|
265
|
+
*/
|
|
266
|
+
export function baseUrlIsGateway(value, hosts = GATEWAY_HOSTNAMES) {
|
|
267
|
+
if (value === undefined)
|
|
268
|
+
return false;
|
|
269
|
+
let url;
|
|
270
|
+
try {
|
|
271
|
+
url = new URL(value.trim());
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const host = normalizeHostname(url.hostname);
|
|
277
|
+
return hosts.some((h) => normalizeHostname(h) === host);
|
|
278
|
+
}
|
|
279
|
+
/** True when one header line's name (text before its first ':', trimmed, any case) is x-mx-relay-token. */
|
|
280
|
+
function isRelayTokenLine(line) {
|
|
281
|
+
const colon = line.indexOf(':');
|
|
282
|
+
const name = (colon === -1 ? line : line.slice(0, colon)).trim().toLowerCase();
|
|
283
|
+
return name === RELAY_TOKEN_HEADER;
|
|
284
|
+
}
|
|
285
|
+
/** True when any newline-separated header line in `value` is an x-mx-relay-token header (#1097). */
|
|
286
|
+
export function headersHoldRelayToken(value) {
|
|
287
|
+
if (value === undefined)
|
|
288
|
+
return false;
|
|
289
|
+
return value.split(/\r?\n/).some(isRelayTokenLine);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The inherited routing variables that hold relay values (#1097): the ones a routed
|
|
293
|
+
* session gives its children. Reads the values to match them; returns names only.
|
|
294
|
+
*/
|
|
295
|
+
export function inheritedRelayVars(env) {
|
|
296
|
+
const out = [];
|
|
297
|
+
if (baseUrlIsGateway(env.ANTHROPIC_BASE_URL))
|
|
298
|
+
out.push('ANTHROPIC_BASE_URL');
|
|
299
|
+
if (headersHoldRelayToken(env.ANTHROPIC_CUSTOM_HEADERS))
|
|
300
|
+
out.push('ANTHROPIC_CUSTOM_HEADERS');
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Remove inherited relay values from `env` IN PLACE (#1097, plan amendment 1):
|
|
305
|
+
* - ANTHROPIC_BASE_URL is deleted when its hostname is the relay's;
|
|
306
|
+
* - from ANTHROPIC_CUSTOM_HEADERS only the x-mx-relay-token lines are removed, the
|
|
307
|
+
* other lines are kept, and the variable is deleted only when no non-empty line
|
|
308
|
+
* remains.
|
|
309
|
+
* Returns the names of the variables changed. The one function every launcher uses:
|
|
310
|
+
* `applyClaudeGatewayRouting` (Claude Code), `buildAgentSessionEnv` (`--exp`), and,
|
|
311
|
+
* unconditionally, every Codex child env (#1099: `CodexAdapter.launch`, `codexChildEnv`,
|
|
312
|
+
* `codex trust-keys` and `codex prove-guards`).
|
|
313
|
+
*/
|
|
314
|
+
export function stripInheritedRelayVars(env) {
|
|
315
|
+
const changed = inheritedRelayVars(env);
|
|
316
|
+
if (changed.includes('ANTHROPIC_BASE_URL'))
|
|
317
|
+
delete env.ANTHROPIC_BASE_URL;
|
|
318
|
+
if (changed.includes('ANTHROPIC_CUSTOM_HEADERS')) {
|
|
319
|
+
const kept = (env.ANTHROPIC_CUSTOM_HEADERS ?? '').split(/\r?\n/).filter((line) => !isRelayTokenLine(line));
|
|
320
|
+
if (kept.some((line) => line.trim() !== ''))
|
|
321
|
+
env.ANTHROPIC_CUSTOM_HEADERS = kept.join('\n');
|
|
322
|
+
else
|
|
323
|
+
delete env.ANTHROPIC_CUSTOM_HEADERS;
|
|
324
|
+
}
|
|
325
|
+
return changed;
|
|
326
|
+
}
|
|
327
|
+
/** The line printed for a stripped relay variable. Names the variable, never a value. */
|
|
328
|
+
export function inheritedRelayRemovedLine(v) {
|
|
329
|
+
return v === 'ANTHROPIC_CUSTOM_HEADERS'
|
|
330
|
+
? `${v} was inherited from a routed session; its ${RELAY_TOKEN_HEADER} line was removed for this start.`
|
|
331
|
+
: `${v} was inherited from a routed session and was removed for this start.`;
|
|
332
|
+
}
|
|
333
|
+
function inheritedWarnings(env, removed = false, relayRemoved = []) {
|
|
334
|
+
return ROUTING_ENV_VARS.filter((v) => env[v] !== undefined).map((v) => removed
|
|
335
|
+
? `${v} was set in this environment and was removed for this start (${GATEWAY_ROUTING_BYPASS_ENV}=off).`
|
|
336
|
+
: relayRemoved.includes(v)
|
|
337
|
+
? inheritedRelayRemovedLine(v)
|
|
338
|
+
: `${v} is already set in this environment and reaches the Claude session unchanged.`);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* The decision for an unlisted team, with or without the bypass (#1097, amendment 1):
|
|
342
|
+
* strip inherited relay values, warn about the rest as before.
|
|
343
|
+
*/
|
|
344
|
+
function unlistedDecision(env, readWarnings) {
|
|
345
|
+
const relay = inheritedRelayVars(env);
|
|
346
|
+
return {
|
|
347
|
+
kind: 'direct',
|
|
348
|
+
lines: [],
|
|
349
|
+
warnings: [...readWarnings, ...inheritedWarnings(env, false, relay)],
|
|
350
|
+
stripRelay: true,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* TEST SEAM ONLY. Overrides the platform `resolveClaudeGatewayRouting` uses when the
|
|
355
|
+
* caller passes none, so a test can drive `launchClaudeSession` as 'linux' or 'win32'
|
|
356
|
+
* on any OS (QA, PR #1082, criterion 7: the windows-latest suite ran the routed tests
|
|
357
|
+
* against the real win32 refusal). Unset in production: `process.platform` is used.
|
|
358
|
+
*/
|
|
359
|
+
let platformForTests;
|
|
360
|
+
export function setRoutingPlatformForTests(platform) {
|
|
361
|
+
platformForTests = platform;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* TEST SEAM ONLY. Overrides the home directory the token path resolves under when the
|
|
365
|
+
* caller passes none, so no test can resolve the real home on any OS (QA, PR #1082:
|
|
366
|
+
* `os.homedir()` reads USERPROFILE on Windows, not HOME, so a test that set only HOME
|
|
367
|
+
* looked under the runner's real profile). Unset in production: `os.homedir()` is used.
|
|
368
|
+
*/
|
|
369
|
+
let homeForTests;
|
|
370
|
+
export function setRoutingHomeForTests(home) {
|
|
371
|
+
homeForTests = home;
|
|
372
|
+
}
|
|
373
|
+
/** `off` in any letter case, after trimming whitespace (wire-reliability review N1). Any other value is ignored. */
|
|
374
|
+
function bypassOn(env) {
|
|
375
|
+
return (env[GATEWAY_ROUTING_BYPASS_ENV] ?? '').trim().toLowerCase() === 'off';
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Decide routing for one start. Throws `ClaudeGatewayRoutingError` on refusal.
|
|
379
|
+
* The returned `token` is only for `applyClaudeGatewayRouting`; never log a decision.
|
|
380
|
+
*/
|
|
381
|
+
export function resolveClaudeGatewayRouting(inputs) {
|
|
382
|
+
const env = inputs.env ?? process.env;
|
|
383
|
+
const platform = inputs.platform ?? platformForTests ?? process.platform;
|
|
384
|
+
if (bypassOn(env)) {
|
|
385
|
+
// Bypass wins over every refusal. A malformed list cannot block the bypass: it
|
|
386
|
+
// counts as "would have routed", so the skipped line prints.
|
|
387
|
+
let listed;
|
|
388
|
+
try {
|
|
389
|
+
listed = readClaudeGatewayTeams(inputs.worktreePath).includes(inputs.teamName);
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
listed = true;
|
|
393
|
+
}
|
|
394
|
+
return listed
|
|
395
|
+
? { kind: 'direct', lines: [BYPASS_LINE], warnings: inheritedWarnings(env, true), removeInherited: true }
|
|
396
|
+
: unlistedDecision(env, []);
|
|
397
|
+
}
|
|
398
|
+
const read = readClaudeGatewayTeamsWithWarnings(inputs.worktreePath);
|
|
399
|
+
if (!read.teams.includes(inputs.teamName)) {
|
|
400
|
+
return unlistedDecision(env, read.warnings);
|
|
401
|
+
}
|
|
402
|
+
if (platform === 'win32') {
|
|
403
|
+
throw new ClaudeGatewayRoutingError(`Gateway routing refused: team "${inputs.teamName}" is listed in ${CLAUDE_GATEWAY_CONFIG_KEY}, ` +
|
|
404
|
+
`and on win32 the token file's permission and symlink checks cannot be enforced. ` +
|
|
405
|
+
`Start with ${GATEWAY_ROUTING_BYPASS_ENV}=off to go direct for this start.`);
|
|
406
|
+
}
|
|
407
|
+
// Before the token read, so a refused start never opens the token file.
|
|
408
|
+
for (const v of PROVIDER_SWITCH_VARS) {
|
|
409
|
+
if (env[v] !== undefined && env[v] !== '') {
|
|
410
|
+
throw new ClaudeGatewayRoutingError(`Gateway routing refused: ${v} is set, and Claude Code would then ignore the gateway URL. ` +
|
|
411
|
+
`Unset it, or start with ${GATEWAY_ROUTING_BYPASS_ENV}=off to go direct for this start.`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const readToken = inputs.readToken ?? readTeamToken;
|
|
415
|
+
const token = readToken(teamTokenPath(inputs.teamName, inputs.home ?? homeForTests ?? homedir()));
|
|
416
|
+
return { kind: 'routed', lines: [ROUTED_LINE], warnings: [], token };
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Apply a decision to the child env IN PLACE. A `direct` decision touches nothing,
|
|
420
|
+
* which is what makes an unlisted launch byte-identical to before, except under the
|
|
421
|
+
* bypass for a listed team, where it removes the two inherited gateway variables, and
|
|
422
|
+
* for an unlisted team with inherited relay values, where it removes those (#1097).
|
|
423
|
+
*/
|
|
424
|
+
export function applyClaudeGatewayRouting(childEnv, decision) {
|
|
425
|
+
if (decision.kind !== 'routed') {
|
|
426
|
+
if (decision.removeInherited) {
|
|
427
|
+
for (const v of ROUTING_ENV_VARS)
|
|
428
|
+
delete childEnv[v];
|
|
429
|
+
}
|
|
430
|
+
if (decision.stripRelay)
|
|
431
|
+
stripInheritedRelayVars(childEnv);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
childEnv.ANTHROPIC_BASE_URL = CLAUDE_GATEWAY_URL;
|
|
435
|
+
childEnv.ANTHROPIC_CUSTOM_HEADERS = `${RELAY_TOKEN_HEADER}: ${decision.token}`;
|
|
436
|
+
delete childEnv.ANTHROPIC_API_KEY;
|
|
437
|
+
delete childEnv.ANTHROPIC_AUTH_TOKEN;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The `--exp` (Agent SDK) check. A listed team refuses, because that launcher does
|
|
441
|
+
* not carry the routing env, and a listed team never silently goes direct. The
|
|
442
|
+
* bypass wins here too (amendment 4, item B). Never reads the token file.
|
|
443
|
+
* Returns the lines to print (the skipped line under the bypass, if listed, or the
|
|
444
|
+
* fixed invalid-JSON warning). Inherited relay values are stripped where the SDK
|
|
445
|
+
* child env is built, `buildAgentSessionEnv` in lib/agent-session.ts (#1097).
|
|
446
|
+
*/
|
|
447
|
+
export function assertExpRoutingAllowed(inputs) {
|
|
448
|
+
const env = inputs.env ?? process.env;
|
|
449
|
+
if (bypassOn(env)) {
|
|
450
|
+
let listed;
|
|
451
|
+
try {
|
|
452
|
+
listed = readClaudeGatewayTeams(inputs.worktreePath).includes(inputs.teamName);
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
listed = true;
|
|
456
|
+
}
|
|
457
|
+
return listed ? [BYPASS_LINE] : [];
|
|
458
|
+
}
|
|
459
|
+
const read = readClaudeGatewayTeamsWithWarnings(inputs.worktreePath);
|
|
460
|
+
if (read.teams.includes(inputs.teamName)) {
|
|
461
|
+
throw new ClaudeGatewayRoutingError(`Gateway routing refused: team "${inputs.teamName}" is listed in ${CLAUDE_GATEWAY_CONFIG_KEY}, ` +
|
|
462
|
+
`and routing is not supported under --exp. Start without --exp, or with ${GATEWAY_ROUTING_BYPASS_ENV}=off to go direct.`);
|
|
463
|
+
}
|
|
464
|
+
return read.warnings;
|
|
465
|
+
}
|
|
466
|
+
//# sourceMappingURL=claude-gateway-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-gateway-routing.js","sourceRoot":"","sources":["../../../src/lib/runtime/claude-gateway-routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAClH,OAAO,EAAE,OA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