passport-bridge 0.13.2 → 0.14.0

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 (61) hide show
  1. package/README.md +92 -17
  2. package/dist/cli.js +4 -3
  3. package/dist/cliArgs.d.ts +1 -1
  4. package/dist/cliArgs.js +21 -5
  5. package/dist/cliAutopilot.d.ts +60 -0
  6. package/dist/cliAutopilot.js +389 -0
  7. package/dist/cliAutopilotPolicy.d.ts +94 -0
  8. package/dist/cliAutopilotPolicy.js +193 -0
  9. package/dist/cliClient.d.ts +7 -0
  10. package/dist/cliClient.js +36 -19
  11. package/dist/cliHook.d.ts +20 -9
  12. package/dist/cliHook.js +125 -32
  13. package/dist/cliHookClassify.d.ts +3 -0
  14. package/dist/cliHookClassify.js +2 -1
  15. package/dist/cliHookDecide.d.ts +89 -0
  16. package/dist/cliHookDecide.js +167 -0
  17. package/dist/cliHookEnvironment.d.ts +55 -0
  18. package/dist/cliHookEnvironment.js +219 -0
  19. package/dist/cliHookGuard.d.ts +61 -12
  20. package/dist/cliHookGuard.js +211 -24
  21. package/dist/cliHookInstall.js +19 -4
  22. package/dist/cliHookMode.d.ts +31 -0
  23. package/dist/cliHookMode.js +50 -0
  24. package/dist/cliHookRedact.d.ts +16 -0
  25. package/dist/cliHookRedact.js +136 -0
  26. package/dist/cliInit.d.ts +4 -1
  27. package/dist/cliInit.js +10 -3
  28. package/dist/cliLogin.js +18 -2
  29. package/dist/cliOffline.js +9 -9
  30. package/dist/cliOutput.js +11 -5
  31. package/dist/cliPolicy.d.ts +11 -3
  32. package/dist/cliPolicy.js +5 -2
  33. package/dist/cliPolicyV2.d.ts +18 -0
  34. package/dist/cliPolicyV2.js +234 -0
  35. package/dist/cliSetupOrg.d.ts +15 -0
  36. package/dist/cliSetupOrg.js +241 -0
  37. package/dist/cliSupport.d.ts +4 -0
  38. package/dist/cliSupport.js +12 -9
  39. package/dist/completion.js +12 -3
  40. package/dist/doctor.js +3 -3
  41. package/dist/enrollment.d.ts +18 -0
  42. package/dist/enrollment.js +79 -0
  43. package/dist/hookPlugin.d.ts +7 -0
  44. package/dist/hookPlugin.js +54 -0
  45. package/dist/initAgents.d.ts +3 -1
  46. package/dist/initAgents.js +7 -3
  47. package/dist/initAutopilotStep.d.ts +24 -0
  48. package/dist/initAutopilotStep.js +257 -0
  49. package/dist/initLocalSteps.d.ts +3 -0
  50. package/dist/initLocalSteps.js +30 -5
  51. package/dist/initState.d.ts +24 -0
  52. package/dist/initUi.js +5 -0
  53. package/dist/passport.js +27 -3
  54. package/dist/pluginPin.d.ts +7 -0
  55. package/dist/pluginPin.js +7 -0
  56. package/dist/universalUrl.d.ts +28 -0
  57. package/dist/universalUrl.js +59 -0
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/npm-shrinkwrap.json +2 -2
  61. package/package.json +1 -1
@@ -0,0 +1,257 @@
1
+ /**
2
+ * `passport init`: the Environments step (after Apps) and the Autopilot step
3
+ * (last; it replaced Safety). Both read `GET /api/my/autopilot`, so a re-run
4
+ * shows what's already set. An older server without Autopilot keeps the old
5
+ * Safety step.
6
+ *
7
+ * Autopilot How much can agents do on their own?
8
+ * Production Careful reads run, changes ask
9
+ * Staging Balanced reads and changes run, deletes ask
10
+ * Development Hands-off everything except irreversible runs
11
+ * Keep these? [Y/n]
12
+ */
13
+ import { OTHER_APPS, PRESETS, PRESET_LABEL, PRESET_ROWS, presetStrictness, rowLabel } from "./cliAutopilotPolicy.js";
14
+ import { ENV_LABEL, isEnvKind } from "./cliHookEnvironment.js";
15
+ import { readBoundedJson, safeApiError } from "./cliSupport.js";
16
+ import { safetyStep } from "./initLocalSteps.js";
17
+ import { printable } from "./initState.js";
18
+ import { listOf } from "./initUi.js";
19
+ export const AUTOPILOT_PATH = "/api/my/autopilot";
20
+ /** The short copy each preset gets in the terminal (map W1). */
21
+ export const PRESET_SHORT = {
22
+ careful: "reads run, changes ask",
23
+ balanced: "reads and changes run, deletes ask",
24
+ handsoff: "everything except irreversible runs"
25
+ };
26
+ const DEFAULTS = {
27
+ production: "careful",
28
+ staging: "balanced",
29
+ development: "handsoff",
30
+ other: "balanced"
31
+ };
32
+ /** The rows this server shows: three environments, and Other apps if it has them. */
33
+ function rowsOf(presets) {
34
+ return PRESET_ROWS.filter((row) => row !== OTHER_APPS || presets[row] !== undefined);
35
+ }
36
+ const PLATFORM_NAMES = {
37
+ railway: "Railway",
38
+ vercel: "Vercel",
39
+ supabase: "Supabase",
40
+ neon: "Neon",
41
+ github: "GitHub",
42
+ stripe: "Stripe",
43
+ cloudflare: "Cloudflare"
44
+ };
45
+ function isPreset(value) {
46
+ return typeof value === "string" && PRESETS.includes(value);
47
+ }
48
+ export function parseAutopilotView(raw) {
49
+ if (!raw || typeof raw !== "object")
50
+ return null;
51
+ const body = raw;
52
+ const presets = {};
53
+ const chosen = {};
54
+ const floors = {};
55
+ const rawPresets = (body.presets ?? {});
56
+ const rawChosen = (body.chosen ?? {});
57
+ const rawFloors = (body.floors ?? {});
58
+ for (const row of PRESET_ROWS) {
59
+ // Other apps is optional: only a server that has the row sends it.
60
+ if (row === OTHER_APPS && !isPreset(rawPresets[row]))
61
+ continue;
62
+ presets[row] = isPreset(rawPresets[row]) ? rawPresets[row] : DEFAULTS[row];
63
+ if (isPreset(rawChosen[row]))
64
+ chosen[row] = rawChosen[row];
65
+ floors[row] = isPreset(rawFloors[row]) ? rawFloors[row] : null;
66
+ }
67
+ const reason = printable(rawFloors.reason, 120);
68
+ const environments = (Array.isArray(body.environments) ? body.environments : [])
69
+ .filter((entry) => Boolean(entry) && typeof entry === "object")
70
+ .filter((entry) => isEnvKind(entry.kind) && typeof entry.appKey === "string")
71
+ .slice(0, 50)
72
+ .map((entry) => ({
73
+ appKey: printable(entry.appKey, 40),
74
+ label: printable(entry.label, 60) || printable(entry.resourceKey, 60),
75
+ kind: entry.kind,
76
+ source: typeof entry.source === "string" ? entry.source : "detected"
77
+ }));
78
+ return { presets, chosen, floors, ...(reason ? { floorReason: reason } : {}), environments };
79
+ }
80
+ /** Read the view once per init run; null on an older server. */
81
+ async function readView(s, fresh = false) {
82
+ if (s.autopilot !== undefined && !fresh)
83
+ return s.autopilot;
84
+ const response = await s.api(AUTOPILOT_PATH, {
85
+ method: "GET",
86
+ headers: { accept: "application/json" },
87
+ signal: s.signal
88
+ });
89
+ if (response.status === 404) {
90
+ await response.body?.cancel().catch(() => undefined);
91
+ s.autopilot = null;
92
+ return null;
93
+ }
94
+ if (!response.ok) {
95
+ await response.body?.cancel().catch(() => undefined);
96
+ return "failed";
97
+ }
98
+ s.autopilot = parseAutopilotView(await readBoundedJson(response));
99
+ return s.autopilot;
100
+ }
101
+ function platformName(key) {
102
+ return PLATFORM_NAMES[key] ?? key;
103
+ }
104
+ function anyAppConnected(s) {
105
+ if (s.connected.length)
106
+ return true;
107
+ return (s.managed?.connections ?? []).some((row) => row.status === "connected" || row.status === "org_managed");
108
+ }
109
+ // ---- Environments -------------------------------------------------------------
110
+ export async function environmentsStep(s) {
111
+ if (!anyAppConnected(s)) {
112
+ s.screen.result("skip", "Environments appear once an app is connected.", "Environments");
113
+ s.record("environments", "skipped", { environments: [] });
114
+ return;
115
+ }
116
+ const view = await readView(s);
117
+ if (view === null) {
118
+ s.screen.result("skip", "Environments need a newer Passport server.", "Environments");
119
+ s.record("environments", "unavailable");
120
+ return;
121
+ }
122
+ if (view === "failed") {
123
+ s.screen.result("warn", "Passport couldn't read your environments. See them any time in Rules.", "Environments");
124
+ s.record("environments", "failed");
125
+ return;
126
+ }
127
+ const found = view.environments;
128
+ const note = "Anything Passport can't place counts as Production. Change it any time in Rules.";
129
+ if (!found.length) {
130
+ s.screen.step("Environments", "None found yet. Passport places each one the first time an agent uses it.");
131
+ s.screen.line(note);
132
+ s.record("environments", "done", { environments: [] });
133
+ return;
134
+ }
135
+ const names = found.map((entry) => `${entry.label} (${platformName(entry.appKey)})`);
136
+ const shown = names.length > 4 ? [...names.slice(0, 4), `${names.length - 4} more`] : names;
137
+ s.screen.step("Environments", `Found ${found.length} environment${found.length === 1 ? "" : "s"}: ${names.length > 4 ? listOf(shown) : shown.join(", ")}`);
138
+ const width = Math.min(28, Math.max(...names.map((name) => name.length)));
139
+ found.slice(0, 8).forEach((entry, index) => {
140
+ const assumed = entry.source === "assumed" ? " (assumed)" : "";
141
+ s.screen.line(`${names[index].padEnd(width)} ${ENV_LABEL[entry.kind]}${assumed}`);
142
+ });
143
+ s.screen.line(note);
144
+ s.record("environments", "done", {
145
+ environments: found.map((entry) => ({ app: entry.appKey, label: entry.label, kind: entry.kind }))
146
+ });
147
+ }
148
+ // ---- Autopilot ----------------------------------------------------------------
149
+ function presetRows(s, presets, view) {
150
+ for (const env of rowsOf(presets)) {
151
+ const floor = view.floors[env];
152
+ const locked = floor && floor === presets[env] && (view.chosen[env] ?? DEFAULTS[env]) !== floor ? " (team floor)" : "";
153
+ s.screen.line(`${rowLabel(env).padEnd(12)} ${PRESET_LABEL[presets[env]].padEnd(10)} ${PRESET_SHORT[presets[env]]}${locked}`);
154
+ }
155
+ }
156
+ /** Floors stricter than a default, said once, with why. */
157
+ function floorLines(view) {
158
+ const lines = [];
159
+ for (const env of rowsOf(view.presets)) {
160
+ const floor = view.floors[env];
161
+ if (floor && presetStrictness(floor) > presetStrictness(DEFAULTS[env])) {
162
+ lines.push(`Your team requires ${PRESET_LABEL[floor]} or stricter in ${rowLabel(env)}.`);
163
+ }
164
+ }
165
+ if (lines.length && view.floorReason)
166
+ lines.push(view.floorReason);
167
+ return lines;
168
+ }
169
+ /** "Production changes, deletes outside Development, and irreversible actions". */
170
+ export function askedFor(presets) {
171
+ if (rowsOf(presets).every((env) => presets[env] === DEFAULTS[env])) {
172
+ return "Production changes, deletes outside Development, and irreversible actions";
173
+ }
174
+ const parts = [];
175
+ for (const env of rowsOf(presets)) {
176
+ if (presets[env] === "careful")
177
+ parts.push(`${rowLabel(env)} changes and deletes`);
178
+ else if (presets[env] === "balanced")
179
+ parts.push(`${rowLabel(env)} deletes`);
180
+ }
181
+ return listOf([...parts, "irreversible actions"]);
182
+ }
183
+ async function choosePresets(s, view) {
184
+ const picked = { ...view.presets };
185
+ for (const env of rowsOf(view.presets)) {
186
+ const floor = view.floors[env];
187
+ const allowed = PRESETS.filter((preset) => !floor || presetStrictness(preset) >= presetStrictness(floor));
188
+ const options = allowed.map((preset) => `${PRESET_LABEL[preset].padEnd(10)} ${PRESET_SHORT[preset]}`);
189
+ const index = await s.screen.choose(`${rowLabel(env)}:`, options, s.signal);
190
+ if (index !== undefined)
191
+ picked[env] = allowed[index];
192
+ }
193
+ return picked;
194
+ }
195
+ async function savePresets(s, presets) {
196
+ const response = await s.api(`${AUTOPILOT_PATH}/presets`, {
197
+ method: "PUT",
198
+ headers: { "content-type": "application/json", accept: "application/json" },
199
+ body: JSON.stringify(presets),
200
+ signal: s.signal
201
+ });
202
+ if (response.ok) {
203
+ await response.body?.cancel().catch(() => undefined);
204
+ return "saved";
205
+ }
206
+ if (response.status === 403) {
207
+ await response.body?.cancel().catch(() => undefined);
208
+ return "looser";
209
+ }
210
+ s.screen.result("warn", await safeApiError(response, "Passport couldn't save your Autopilot presets."));
211
+ return "failed";
212
+ }
213
+ export async function autopilotStep(s) {
214
+ const view = await readView(s, true);
215
+ if (view === null)
216
+ return safetyStep(s);
217
+ if (view === "failed") {
218
+ s.screen.result("warn", "Passport couldn't read your Autopilot presets. Set them any time in Rules.", "Autopilot");
219
+ s.record("autopilot", "failed");
220
+ return;
221
+ }
222
+ const already = PRESET_ROWS.some((env) => view.chosen[env] !== undefined);
223
+ s.screen.step("Autopilot", `How much can agents do on their own?${already ? " (already set up)" : ""}`);
224
+ presetRows(s, view.presets, view);
225
+ for (const line of floorLines(view))
226
+ s.screen.line(line);
227
+ let presets = view.presets;
228
+ let changed = false;
229
+ if (!already) {
230
+ const keep = await s.screen.confirm("Keep these?", s.signal);
231
+ if (!keep)
232
+ presets = await choosePresets(s, view);
233
+ const saved = await savePresets(s, presets);
234
+ if (saved === "looser") {
235
+ // A CLI credential may only tighten; the web can loosen.
236
+ s.screen.result("warn", "Passport can only make presets stricter from here. Loosen them in Rules on the web.");
237
+ presets = view.presets;
238
+ await savePresets(s, presets);
239
+ }
240
+ else if (saved === "failed") {
241
+ s.record("autopilot", "failed", { presets: view.presets });
242
+ return;
243
+ }
244
+ changed = true;
245
+ s.summary.changed = true;
246
+ }
247
+ s.autopilotSummary = `Autopilot on. You'll be asked only for ${askedFor(presets)}.`;
248
+ s.record("autopilot", changed ? "done" : "already_set_up", {
249
+ presets,
250
+ floors: view.floors
251
+ });
252
+ // The hook guard reads a local copy of these rules; bring it up to date.
253
+ const { refreshCliPolicy } = await import("./cliPolicy.js");
254
+ await refreshCliPolicy(s.profile, AbortSignal.any([s.signal, AbortSignal.timeout(5_000)]), {
255
+ api: (path, init) => s.api(path, init)
256
+ });
257
+ }
@@ -2,6 +2,9 @@ import { type AgentContext, type AgentId } from "./initAgents.js";
2
2
  import { type InitSession } from "./initState.js";
3
3
  export declare function agentContext(s: InitSession): AgentContext;
4
4
  export declare function detected(s: InitSession): AgentId[];
5
+ /** The one URL with this workspace as its hint, or the workspace's own URL on
6
+ * a server that doesn't serve `/mcp` yet. Read once per run. */
7
+ export declare function resolveMcpUrl(s: InitSession): Promise<string>;
5
8
  export declare function agentsStep(s: InitSession): Promise<void>;
6
9
  export declare function guardStep(s: InitSession): Promise<void>;
7
10
  export declare function safetyStep(s: InitSession): Promise<void>;
@@ -6,10 +6,12 @@
6
6
  import { bool } from "./cliArgs.js";
7
7
  import { HOOK_CLIENTS, applyGuardInstall, nodeInvocation, planGuardInstall, registeredEntries } from "./cliHookInstall.js";
8
8
  import { CliFailure, readBoundedJson, safeApiError } from "./cliSupport.js";
9
- import { applyAgent, backupOnce, detectAgents, displayHome, editsExistingFile, needsWork, planAgent } from "./initAgents.js";
9
+ import { AGENT_NAMES, applyAgent, backupOnce, detectAgents, displayHome, editsExistingFile, needsWork, planAgent } from "./initAgents.js";
10
10
  import { copyVersionsIn, ensureStableCommand, pruneCopies } from "./initInstall.js";
11
11
  import { SAFETY_APPS, appLabel, packageRootOf } from "./initState.js";
12
12
  import { listOf } from "./initUi.js";
13
+ import { coveredByPlugin, pluginInstalled } from "./hookPlugin.js";
14
+ import { supportsUniversalUrl, universalUrl, workspaceUrl } from "./universalUrl.js";
13
15
  import { VERSION } from "./version.js";
14
16
  export function agentContext(s) {
15
17
  const origin = s.gateway.origin;
@@ -18,7 +20,7 @@ export function agentContext(s) {
18
20
  env: s.env,
19
21
  home: s.home,
20
22
  platform: s.platform,
21
- url: `${origin}/w/${encodeURIComponent(workspaceId)}/mcp`,
23
+ url: s.mcpUrl ?? workspaceUrl(origin, workspaceId),
22
24
  workspaceId,
23
25
  version: VERSION,
24
26
  ...s.deps.agents
@@ -32,12 +34,25 @@ export function detected(s) {
32
34
  which: s.deps.agents?.which
33
35
  });
34
36
  }
37
+ /** The one URL with this workspace as its hint, or the workspace's own URL on
38
+ * a server that doesn't serve `/mcp` yet. Read once per run. */
39
+ export async function resolveMcpUrl(s) {
40
+ if (s.mcpUrl)
41
+ return s.mcpUrl;
42
+ const origin = s.gateway.origin;
43
+ const workspace = s.summary.workspace.id;
44
+ s.mcpUrl = (await supportsUniversalUrl(origin, s.deps.fetch ?? fetch, s.signal))
45
+ ? universalUrl(origin, { workspace })
46
+ : workspaceUrl(origin, workspace);
47
+ return s.mcpUrl;
48
+ }
35
49
  export async function agentsStep(s) {
36
50
  if (bool(s.args, "skip-agents")) {
37
51
  s.screen.result("skip", "Skipped", "Agents");
38
52
  s.record("agents", "skipped");
39
53
  return;
40
54
  }
55
+ await resolveMcpUrl(s);
41
56
  const context = agentContext(s);
42
57
  const agents = detected(s);
43
58
  if (!agents.length) {
@@ -161,7 +176,17 @@ async function guardSetup(s) {
161
176
  s.record("guard", "skipped");
162
177
  return;
163
178
  }
164
- const clients = detected(s).filter((agent) => HOOK_CLIENTS.includes(agent));
179
+ const hookAgents = detected(s).filter((agent) => HOOK_CLIENTS.includes(agent));
180
+ const covered = hookAgents.filter((agent) => pluginInstalled(agent, s.env, s.home));
181
+ for (const agent of covered)
182
+ s.screen.result("done", coveredByPlugin(AGENT_NAMES[agent]), "Guard");
183
+ const clients = hookAgents.filter((agent) => !covered.includes(agent));
184
+ if (!clients.length && covered.length) {
185
+ s.record("guard", "already_set_up", {
186
+ agents: covered.map((agent) => ({ agent, name: AGENT_NAMES[agent], status: "covered_by_plugin" }))
187
+ });
188
+ return;
189
+ }
165
190
  if (!clients.length) {
166
191
  s.screen.result("skip", "No agents that run shell commands.", "Guard");
167
192
  s.record("guard", "skipped", { agents: [] });
@@ -224,7 +249,7 @@ async function guardSetup(s) {
224
249
  if (existing.length) {
225
250
  s.screen.line(`Adds Passport hooks to ${listOf(existing.map((plan) => displayHome(plan.path, s.home)))}. Keeps a backup.`, "Guard");
226
251
  }
227
- const yes = await s.screen.confirm(`Ask before destructive commands in ${names(todo)}?`, s.signal, "Guard");
252
+ const yes = await s.screen.confirm(`Apply your Autopilot rules before each shell command in ${names(todo)}?`, s.signal, "Guard");
228
253
  if (!yes) {
229
254
  s.screen.result("skip", "Skipped");
230
255
  s.record("guard", "skipped", detail("skipped"));
@@ -248,7 +273,7 @@ async function guardSetup(s) {
248
273
  else
249
274
  s.screen.result("done", "On");
250
275
  if (todo.some((plan) => plan.client === "codex")) {
251
- s.screen.result("warn", "In Codex, trust the Passport hooks in /hooks. Codex can block but not ask.");
276
+ s.screen.result("warn", "Codex: blocks only. Trust the Passport hooks in Codex's /hooks.");
252
277
  }
253
278
  s.summary.changed = true;
254
279
  s.record("guard", failedPlans.length ? "failed" : problems.length ? "needs_attention" : "done", detail("done"));
@@ -3,6 +3,8 @@ import type { CliAuth, CliGateway } from "./cliClient.js";
3
3
  import type { ManagePayload } from "./cliConnect.js";
4
4
  import type { login } from "./cliLogin.js";
5
5
  import type { Env } from "./cliSupport.js";
6
+ import type { Preset, PresetRow } from "./cliAutopilotPolicy.js";
7
+ import type { EnvKind } from "./cliHookEnvironment.js";
6
8
  import type { AgentContext, AgentId } from "./initAgents.js";
7
9
  import type { InstallContext, StableCommand } from "./initInstall.js";
8
10
  import type { InitScreen, InitTerminal } from "./initUi.js";
@@ -26,6 +28,20 @@ export declare const WAIT_INTERACTIVE_MS: number;
26
28
  /** How long the printed `passport connect --wait` command waits. */
27
29
  export declare const WAIT_NEXT_SECONDS = 300;
28
30
  export declare const WAIT_CHUNK_SECONDS = 10;
31
+ /** What init reads from `GET /api/my/autopilot`. */
32
+ export type AutopilotView = {
33
+ /** The three environments, plus "other" (Other apps) when the server has it. */
34
+ presets: Record<EnvKind, Preset> & Partial<Record<PresetRow, Preset>>;
35
+ chosen: Partial<Record<PresetRow, Preset>>;
36
+ floors: Partial<Record<PresetRow, Preset | null>>;
37
+ floorReason?: string;
38
+ environments: Array<{
39
+ appKey: string;
40
+ label: string;
41
+ kind: EnvKind;
42
+ source: string;
43
+ }>;
44
+ };
29
45
  export type StepStatus = "done" | "already_set_up" | "skipped" | "needs_attention" | "failed" | "unavailable";
30
46
  export type Gateway = Pick<CliGateway, "callTool" | "fetchApi" | "close" | "origin">;
31
47
  export type InitDependencies = {
@@ -43,6 +59,8 @@ export type InitDependencies = {
43
59
  packageRoot?: string;
44
60
  nodeVersion?: string;
45
61
  waitMs?: number;
62
+ /** Network seam for the server's discovery metadata. */
63
+ fetch?: typeof fetch;
46
64
  };
47
65
  export type AppRow = {
48
66
  app: string;
@@ -105,6 +123,12 @@ export interface InitSession {
105
123
  agentsReady: AgentId[];
106
124
  newlyAddedClaudeCode: boolean;
107
125
  stable?: StableCommand;
126
+ /** `GET /api/my/autopilot`, read once; null on a server without Autopilot. */
127
+ autopilot?: AutopilotView | null;
128
+ /** The closing line the Autopilot step leaves for the outro. */
129
+ autopilotSummary?: string;
130
+ /** The MCP URL agents get (universal or per-workspace), read once. */
131
+ mcpUrl?: string;
108
132
  pause(): void;
109
133
  checkPaused(): void;
110
134
  record(step: string, status: StepStatus, detail?: Record<string, unknown>): void;
package/dist/initUi.js CHANGED
@@ -177,6 +177,11 @@ export class InitScreen {
177
177
  this.clearLive();
178
178
  const width = this.terminal.width - CONTINUATION.length;
179
179
  const lines = wrapText(this.text(text), width);
180
+ // A label wider than the column ("Environments") gets a row of its own.
181
+ if (label !== undefined && label.length >= LABEL_WIDTH) {
182
+ this.terminal.write(`${INDENT}${label}\n`);
183
+ label = undefined;
184
+ }
180
185
  lines.forEach((line, index) => {
181
186
  const lead = index === 0 && label !== undefined ? `${INDENT}${label.padEnd(LABEL_WIDTH)}` : CONTINUATION;
182
187
  this.terminal.write(`${lead}${line}\n`);
package/dist/passport.js CHANGED
@@ -75,6 +75,16 @@ async function logout(args, runtime) {
75
75
  runtime.stderr.write(`${warning}\n`);
76
76
  return { json: { profile: auth.profile, removed: true, revoked }, human: `Signed out profile "${auth.profile}".` };
77
77
  }
78
+ /** Plain words for a connection state in human output; --json keeps the code. */
79
+ const CONNECTION_STATUS_LABELS = {
80
+ connected: "connected",
81
+ org_managed: "company-managed",
82
+ needs_your_signin: "needs your sign-in",
83
+ needs_setup: "needs admin setup"
84
+ };
85
+ function connectionStatusLabel(status) {
86
+ return CONNECTION_STATUS_LABELS[status] ?? status.replace(/_/g, " ");
87
+ }
78
88
  async function status(args, runtime) {
79
89
  return withGateway(args, runtime, async (gateway, auth) => {
80
90
  // In parallel with the status call; it never rejects.
@@ -115,6 +125,11 @@ async function status(args, runtime) {
115
125
  description: `Connect ${mcp.name}.`
116
126
  }))
117
127
  : [];
128
+ // After the sync, so the cache age shown is the one the guard now reads.
129
+ await synced;
130
+ const autopilot = auth.kind === "profile"
131
+ ? await (await import("./cliAutopilot.js")).autopilotStatus((path, init) => gateway.fetchApi(path, init), auth.profile, AbortSignal.any([runtime.signal, AbortSignal.timeout(Math.min(timeoutMs(args), CLI_POLICY_SYNC_MS))]))
132
+ : undefined;
118
133
  const data = {
119
134
  workspace: { id: String(managed.workspace.id), name: String(managed.workspace.name) },
120
135
  member: { id: String(managed.member.id), email: String(managed.member.email) },
@@ -123,6 +138,7 @@ async function status(args, runtime) {
123
138
  ...(auth.kind === "profile" ? { profile: auth.profile } : {}),
124
139
  client: managed.client,
125
140
  mcps,
141
+ ...(autopilot ? { autopilot } : {}),
126
142
  ...(connectionActions.length ? { next: connectionActions } : {})
127
143
  };
128
144
  const lines = [
@@ -132,16 +148,16 @@ async function status(args, runtime) {
132
148
  ...(auth.kind === "profile" ? [`Profile: ${auth.profile}`] : []),
133
149
  `Client: ${managed.client} · Surface: ${managed.surface} · Auth: ${managed.auth}`,
134
150
  ...(mcps.length
135
- ? mcps.map((mcp) => `${mcp.name} (${mcp.app}): ${mcp.status} · ${mcp.toolCount} permitted tool${mcp.toolCount === 1 ? "" : "s"}${mcp.status === "needs_your_signin"
151
+ ? mcps.map((mcp) => `${mcp.name} (${mcp.app}): ${connectionStatusLabel(mcp.status)} · ${mcp.toolCount} permitted tool${mcp.toolCount === 1 ? "" : "s"}${mcp.status === "needs_your_signin"
136
152
  ? auth.kind === "agent-key"
137
153
  ? " · Requires an interactive member profile, delegation, or a company-managed connection"
138
154
  : /^[A-Za-z0-9._-]+$/.test(mcp.app)
139
155
  ? ` · Run: passport connect ${mcp.app} --wait 120`
140
156
  : " · Run passport status --json for the safe connect argv"
141
157
  : ""}`)
142
- : ["No visible apps."])
158
+ : ["No visible apps."]),
159
+ ...(autopilot ? (await import("./cliAutopilot.js")).autopilotLines(autopilot) : [])
143
160
  ];
144
- await synced;
145
161
  return { json: data, human: lines.join("\n") };
146
162
  });
147
163
  }
@@ -532,7 +548,15 @@ async function dispatch(args, runtime) {
532
548
  return (await import("./cliScan.js")).scan(args, runtime);
533
549
  case "hook":
534
550
  return (await import("./cliHook.js")).hook(args, runtime);
551
+ case "wait":
552
+ return (await import("./cliAutopilot.js")).wait(args, runtime);
553
+ case "rules":
554
+ return (await import("./cliAutopilot.js")).rules(args, runtime);
555
+ case "sessions":
556
+ return (await import("./cliAutopilot.js")).sessions(args, runtime);
535
557
  case "setup":
558
+ if (value(args, "org") !== undefined)
559
+ return (await import("./cliSetupOrg.js")).setupOrg(args, runtime);
536
560
  return (await import("./cliSetup.js")).setup(args, runtime, withGateway);
537
561
  case "session":
538
562
  return runCliSession(args, runtime, dispatch);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The bridge version the Passport plugin (rsyed94/passport-plugins) pins: its
3
+ * hooks install and run exactly this CLI. Each bridge release bumps it with
4
+ * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
+ * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
+ */
7
+ export declare const PLUGIN_PIN = "0.14.0";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The bridge version the Passport plugin (rsyed94/passport-plugins) pins: its
3
+ * hooks install and run exactly this CLI. Each bridge release bumps it with
4
+ * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
+ * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
+ */
7
+ export const PLUGIN_PIN = "0.14.0";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The one MCP URL every agent can use: `https://passportmcp.com/mcp`. The
3
+ * agent's own sign-in picks the workspace; an optional hint pre-selects it
4
+ * (`?ws=<workspace>` after a sign-in, `?enroll=<pek_…>` from a company's
5
+ * enrollment key). A server that doesn't serve `/mcp` yet keeps the
6
+ * per-workspace URL, `/w/<workspace>/mcp`.
7
+ *
8
+ * Support is read from the server's own discovery metadata: OAuth protected
9
+ * resource metadata for `/mcp` (RFC 9728, path-suffixed form) naming `/mcp`
10
+ * as its resource. No credential is sent.
11
+ */
12
+ export declare const UNIVERSAL_PATH = "/mcp";
13
+ export declare const WORKSPACE_HINT = "ws";
14
+ export declare const ENROLL_HINT = "enroll";
15
+ export { isEnrollmentKey } from "./enrollment.js";
16
+ /** Does this Passport serve the universal URL? Never throws; false when unsure. */
17
+ export declare function supportsUniversalUrl(origin: string, fetcher?: typeof fetch, signal?: AbortSignal): Promise<boolean>;
18
+ export declare function universalUrl(origin: string, hint?: {
19
+ workspace?: string;
20
+ enroll?: string;
21
+ }): string;
22
+ export declare function workspaceUrl(origin: string, workspace: string): string;
23
+ /** Is this a Passport MCP URL on the same server: universal or per-workspace? */
24
+ export declare function passportMcpPath(url: URL): {
25
+ universal: true;
26
+ } | {
27
+ workspace: string;
28
+ } | null;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The one MCP URL every agent can use: `https://passportmcp.com/mcp`. The
3
+ * agent's own sign-in picks the workspace; an optional hint pre-selects it
4
+ * (`?ws=<workspace>` after a sign-in, `?enroll=<pek_…>` from a company's
5
+ * enrollment key). A server that doesn't serve `/mcp` yet keeps the
6
+ * per-workspace URL, `/w/<workspace>/mcp`.
7
+ *
8
+ * Support is read from the server's own discovery metadata: OAuth protected
9
+ * resource metadata for `/mcp` (RFC 9728, path-suffixed form) naming `/mcp`
10
+ * as its resource. No credential is sent.
11
+ */
12
+ import { readBoundedJson } from "./boundedResponse.js";
13
+ export const UNIVERSAL_PATH = "/mcp";
14
+ export const WORKSPACE_HINT = "ws";
15
+ export const ENROLL_HINT = "enroll";
16
+ const PROBE_MS = 5_000;
17
+ export { isEnrollmentKey } from "./enrollment.js";
18
+ /** Does this Passport serve the universal URL? Never throws; false when unsure. */
19
+ export async function supportsUniversalUrl(origin, fetcher = fetch, signal) {
20
+ try {
21
+ const response = await fetcher(`${origin}/.well-known/oauth-protected-resource${UNIVERSAL_PATH}`, {
22
+ method: "GET",
23
+ headers: { accept: "application/json" },
24
+ redirect: "error",
25
+ signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(PROBE_MS)]) : AbortSignal.timeout(PROBE_MS)
26
+ });
27
+ if (!response.ok) {
28
+ await response.body?.cancel().catch(() => undefined);
29
+ return false;
30
+ }
31
+ const body = await readBoundedJson(response, 64 * 1024);
32
+ if (typeof body.resource !== "string")
33
+ return false;
34
+ const resource = new URL(body.resource);
35
+ return resource.origin === origin && resource.pathname.replace(/\/+$/, "") === UNIVERSAL_PATH;
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
41
+ export function universalUrl(origin, hint = {}) {
42
+ const url = new URL(UNIVERSAL_PATH, origin);
43
+ if (hint.workspace)
44
+ url.searchParams.set(WORKSPACE_HINT, hint.workspace);
45
+ if (hint.enroll)
46
+ url.searchParams.set(ENROLL_HINT, hint.enroll);
47
+ return url.toString();
48
+ }
49
+ export function workspaceUrl(origin, workspace) {
50
+ return `${origin}/w/${encodeURIComponent(workspace)}/mcp`;
51
+ }
52
+ /** Is this a Passport MCP URL on the same server: universal or per-workspace? */
53
+ export function passportMcpPath(url) {
54
+ const path = url.pathname.replace(/\/+$/, "");
55
+ if (path === UNIVERSAL_PATH)
56
+ return { universal: true };
57
+ const workspace = /^\/w\/([^/]+)\/mcp$/.exec(path)?.[1];
58
+ return workspace ? { workspace: decodeURIComponent(workspace) } : null;
59
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.13.2";
1
+ export declare const VERSION = "0.14.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Keep in lockstep with bridge/package.json.
2
- export const VERSION = "0.13.2";
2
+ export const VERSION = "0.14.0";
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.13.2",
9
+ "version": "0.14.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.30.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "description": "Passport CLI for governed terminal and CI agents, plus the local stdio-to-cloud MCP bridge.",
5
5
  "license": "MIT",
6
6
  "repository": {