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.
- package/README.md +92 -17
- package/dist/cli.js +4 -3
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +21 -5
- package/dist/cliAutopilot.d.ts +60 -0
- package/dist/cliAutopilot.js +389 -0
- package/dist/cliAutopilotPolicy.d.ts +94 -0
- package/dist/cliAutopilotPolicy.js +193 -0
- package/dist/cliClient.d.ts +7 -0
- package/dist/cliClient.js +36 -19
- package/dist/cliHook.d.ts +20 -9
- package/dist/cliHook.js +125 -32
- package/dist/cliHookClassify.d.ts +3 -0
- package/dist/cliHookClassify.js +2 -1
- package/dist/cliHookDecide.d.ts +89 -0
- package/dist/cliHookDecide.js +167 -0
- package/dist/cliHookEnvironment.d.ts +55 -0
- package/dist/cliHookEnvironment.js +219 -0
- package/dist/cliHookGuard.d.ts +61 -12
- package/dist/cliHookGuard.js +211 -24
- package/dist/cliHookInstall.js +19 -4
- package/dist/cliHookMode.d.ts +31 -0
- package/dist/cliHookMode.js +50 -0
- package/dist/cliHookRedact.d.ts +16 -0
- package/dist/cliHookRedact.js +136 -0
- package/dist/cliInit.d.ts +4 -1
- package/dist/cliInit.js +10 -3
- package/dist/cliLogin.js +18 -2
- package/dist/cliOffline.js +9 -9
- package/dist/cliOutput.js +11 -5
- package/dist/cliPolicy.d.ts +11 -3
- package/dist/cliPolicy.js +5 -2
- package/dist/cliPolicyV2.d.ts +18 -0
- package/dist/cliPolicyV2.js +234 -0
- package/dist/cliSetupOrg.d.ts +15 -0
- package/dist/cliSetupOrg.js +241 -0
- package/dist/cliSupport.d.ts +4 -0
- package/dist/cliSupport.js +12 -9
- package/dist/completion.js +12 -3
- package/dist/doctor.js +3 -3
- package/dist/enrollment.d.ts +18 -0
- package/dist/enrollment.js +79 -0
- package/dist/hookPlugin.d.ts +7 -0
- package/dist/hookPlugin.js +54 -0
- package/dist/initAgents.d.ts +3 -1
- package/dist/initAgents.js +7 -3
- package/dist/initAutopilotStep.d.ts +24 -0
- package/dist/initAutopilotStep.js +257 -0
- package/dist/initLocalSteps.d.ts +3 -0
- package/dist/initLocalSteps.js +30 -5
- package/dist/initState.d.ts +24 -0
- package/dist/initUi.js +5 -0
- package/dist/passport.js +27 -3
- package/dist/pluginPin.d.ts +7 -0
- package/dist/pluginPin.js +7 -0
- package/dist/universalUrl.d.ts +28 -0
- package/dist/universalUrl.js +59 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `passport setup --org <pek_…> [--yes] [--clients claude-code,cursor,…]`:
|
|
3
|
+
* `passport init` for MDM and scripts. It never asks anything and never signs
|
|
4
|
+
* in; each agent's own sign-in (or `passport login`) does that later.
|
|
5
|
+
*
|
|
6
|
+
* 1. A stable copy of the CLI in `$PASSPORT_HOME/cli/<version>/`.
|
|
7
|
+
* 2. Passport in every detected agent, at the one URL with the enrollment
|
|
8
|
+
* key as its workspace hint (`https://passportmcp.com/mcp?enroll=pek_…`).
|
|
9
|
+
* 3. The guard and audit hooks for agents that run shell commands.
|
|
10
|
+
* 4. The key, recorded in `$PASSPORT_HOME/enrollment.json` for sign-in hints.
|
|
11
|
+
*
|
|
12
|
+
* One line per agent, exit 0 even with no agents (an MDM run must not fail
|
|
13
|
+
* for a computer without them). Running it again repairs what drifted.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { value } from "./cliArgs.js";
|
|
19
|
+
import { HOOK_CLIENTS, applyGuardInstall, registeredEntries, nodeInvocation, planGuardInstall } from "./cliHookInstall.js";
|
|
20
|
+
import { CliFailure, cloudOrigin, failure } from "./cliSupport.js";
|
|
21
|
+
import { AGENT_NAMES, AGENT_ORDER, applyAgent, backupOnce, claudeCodeConfigPath, claudeDesktopConfigPath, codexConfigFile, cursorConfigPath, detectAgents, needsWork, planAgent, vscodeConfigPath } from "./initAgents.js";
|
|
22
|
+
import { copyVersionsIn, ensureStableCommand, pruneCopies } from "./initInstall.js";
|
|
23
|
+
import { PASSPORT_CLOUD, packageRootOf } from "./initState.js";
|
|
24
|
+
import { ensureOneLinerRuntime } from "./nodeVersion.js";
|
|
25
|
+
import { pluginInstalled } from "./hookPlugin.js";
|
|
26
|
+
import { isEnrollmentKey, lookupEnrollment, recordEnrollment } from "./enrollment.js";
|
|
27
|
+
import { supportsUniversalUrl, universalUrl } from "./universalUrl.js";
|
|
28
|
+
import { VERSION } from "./version.js";
|
|
29
|
+
export { ENROLLMENT_FILE } from "./enrollment.js";
|
|
30
|
+
/** Agents whose config folders exist here, even without their CLI on PATH. */
|
|
31
|
+
function agentsOnDisk(env, home, platform) {
|
|
32
|
+
const names = [];
|
|
33
|
+
const has = (path) => existsSync(path);
|
|
34
|
+
if (has(claudeCodeConfigPath(env, home)) || has(join(home, ".claude")))
|
|
35
|
+
names.push(AGENT_NAMES["claude-code"]);
|
|
36
|
+
if (has(dirname(cursorConfigPath(env, home))))
|
|
37
|
+
names.push(AGENT_NAMES.cursor);
|
|
38
|
+
if (has(dirname(codexConfigFile(env, home))))
|
|
39
|
+
names.push(AGENT_NAMES.codex);
|
|
40
|
+
if (has(dirname(vscodeConfigPath(env, home, platform))))
|
|
41
|
+
names.push(AGENT_NAMES.vscode);
|
|
42
|
+
if (has(dirname(claudeDesktopConfigPath(env, home, platform))))
|
|
43
|
+
names.push(AGENT_NAMES.claude);
|
|
44
|
+
return names;
|
|
45
|
+
}
|
|
46
|
+
function requestedClients(raw) {
|
|
47
|
+
if (!raw)
|
|
48
|
+
return null;
|
|
49
|
+
const wanted = raw
|
|
50
|
+
.split(",")
|
|
51
|
+
.map((part) => part.trim().toLowerCase())
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
const unknown = wanted.filter((id) => !AGENT_ORDER.includes(id));
|
|
54
|
+
if (unknown.length || !wanted.length) {
|
|
55
|
+
return failure(`--clients takes a list of ${AGENT_ORDER.join(", ")}.`, 6, "usage");
|
|
56
|
+
}
|
|
57
|
+
return new Set(wanted);
|
|
58
|
+
}
|
|
59
|
+
function shortKey(key) {
|
|
60
|
+
return `${key.slice(0, 4)}…${key.slice(-4)}`;
|
|
61
|
+
}
|
|
62
|
+
function mcpLine(line) {
|
|
63
|
+
switch (line.mcp) {
|
|
64
|
+
case "added":
|
|
65
|
+
return `✓ Passport added${line.next ? ` · sign in: ${line.next}` : ""}`;
|
|
66
|
+
case "updated":
|
|
67
|
+
return "✓ Passport updated";
|
|
68
|
+
case "already_set_up":
|
|
69
|
+
return "✓ Passport already set up";
|
|
70
|
+
case "needs_attention":
|
|
71
|
+
return `! ${line.next ?? "Add Passport yourself"}`;
|
|
72
|
+
case "unavailable":
|
|
73
|
+
return "– Not added: this Passport doesn't serve its one URL yet";
|
|
74
|
+
default:
|
|
75
|
+
return `! ${line.message ?? "Couldn't add Passport"}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function guardLine(line) {
|
|
79
|
+
if (line.guard === "on")
|
|
80
|
+
return " · guard on";
|
|
81
|
+
if (line.guard === "already_on")
|
|
82
|
+
return " · guard on";
|
|
83
|
+
if (line.guard === "plugin")
|
|
84
|
+
return " · guard: already covered by the Passport plugin";
|
|
85
|
+
if (line.guard === "failed")
|
|
86
|
+
return " · ! guard not installed";
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
/** Passport in one agent, at the one URL. */
|
|
90
|
+
function addPassport(line, context) {
|
|
91
|
+
const plan = planAgent(line.agent, context);
|
|
92
|
+
if (plan.method === "manual") {
|
|
93
|
+
line.mcp = plan.state.kind === "current" ? "already_set_up" : "needs_attention";
|
|
94
|
+
if (plan.state.kind !== "current")
|
|
95
|
+
line.next = plan.manual;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (plan.state.kind === "other" || plan.state.kind === "blocked") {
|
|
99
|
+
line.mcp = "left_alone";
|
|
100
|
+
line.message = plan.state.message;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!needsWork(plan)) {
|
|
104
|
+
line.mcp = "already_set_up";
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const outcome = applyAgent(plan, context);
|
|
108
|
+
if (!outcome.ok) {
|
|
109
|
+
line.mcp = "failed";
|
|
110
|
+
line.message = outcome.message;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
line.mcp = plan.state.kind === "stale" ? "updated" : "added";
|
|
114
|
+
if (outcome.next)
|
|
115
|
+
line.next = outcome.next;
|
|
116
|
+
}
|
|
117
|
+
/** The guard and audit hooks for one agent that runs shell commands. */
|
|
118
|
+
function addHooks(line, context, stable, installProblem) {
|
|
119
|
+
const { env, home } = context;
|
|
120
|
+
if (!HOOK_CLIENTS.includes(line.agent))
|
|
121
|
+
return;
|
|
122
|
+
if (pluginInstalled(line.agent, env, home)) {
|
|
123
|
+
line.guard = "plugin";
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!stable) {
|
|
127
|
+
line.guard = "failed";
|
|
128
|
+
line.message ??= installProblem;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const invocation = nodeInvocation(stable.node, stable.entry);
|
|
132
|
+
try {
|
|
133
|
+
const plan = planGuardInstall(line.agent, env, invocation);
|
|
134
|
+
if (!plan.changes.length) {
|
|
135
|
+
line.guard = "already_on";
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (plan.existed)
|
|
139
|
+
backupOnce(plan.path);
|
|
140
|
+
applyGuardInstall(plan, env, invocation);
|
|
141
|
+
line.guard = "on";
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
line.guard = "failed";
|
|
145
|
+
line.message ??= error instanceof CliFailure ? error.message : "Passport couldn't update its hooks.";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function installStable(deps, context) {
|
|
149
|
+
try {
|
|
150
|
+
return {
|
|
151
|
+
stable: (deps.install ?? ensureStableCommand)({
|
|
152
|
+
...context,
|
|
153
|
+
packageRoot: deps.packageRoot ?? packageRootOf(),
|
|
154
|
+
execPath: process.execPath,
|
|
155
|
+
nodeVersion: deps.nodeVersion ?? process.versions.node
|
|
156
|
+
})
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return { problem: error instanceof Error ? error.message : "Passport couldn't install itself." };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Keep this version and anything another hook still runs. */
|
|
164
|
+
function pruneStaleCopies(env, stable) {
|
|
165
|
+
const commands = HOOK_CLIENTS.flatMap((client) => {
|
|
166
|
+
const entries = registeredEntries(client, env);
|
|
167
|
+
return [entries.audit, entries.guard].filter((command) => Boolean(command));
|
|
168
|
+
});
|
|
169
|
+
pruneCopies([VERSION, stable.version, ...copyVersionsIn(commands)]);
|
|
170
|
+
}
|
|
171
|
+
function summary(where, key, url, lines) {
|
|
172
|
+
const width = Math.max(14, ...lines.map((line) => line.name.length + 2));
|
|
173
|
+
const working = lines.some((line) => ["added", "updated", "already_set_up"].includes(line.mcp));
|
|
174
|
+
return [
|
|
175
|
+
`Passport setup for ${where} (enrollment ${shortKey(key)})`,
|
|
176
|
+
...(lines.length
|
|
177
|
+
? lines.map((line) => `${line.name.padEnd(width)}${mcpLine(line)}${guardLine(line)}`)
|
|
178
|
+
: ["No supported agents found. Nothing to set up."]),
|
|
179
|
+
...(!url && lines.length ? ["Hooks are on. Add Passport to your agents with: passport init"] : []),
|
|
180
|
+
...(url && working ? ["Each agent asks you to sign in to Passport the first time it connects."] : [])
|
|
181
|
+
].join("\n");
|
|
182
|
+
}
|
|
183
|
+
export async function setupOrg(args, runtime, deps = {}) {
|
|
184
|
+
ensureOneLinerRuntime();
|
|
185
|
+
const key = value(args, "org")?.trim() ?? "";
|
|
186
|
+
if (!isEnrollmentKey(key)) {
|
|
187
|
+
return failure("--org takes your company's enrollment key, which starts with pek_.", 6, "usage");
|
|
188
|
+
}
|
|
189
|
+
if (args.positionals.length)
|
|
190
|
+
return failure("passport setup --org takes no other arguments.", 6, "usage");
|
|
191
|
+
const only = requestedClients(value(args, "clients"));
|
|
192
|
+
const env = runtime.env;
|
|
193
|
+
const home = deps.home ?? homedir();
|
|
194
|
+
const platform = deps.platform ?? process.platform;
|
|
195
|
+
const rawCloud = value(args, "cloud") || env.PASSPORT_CLOUD;
|
|
196
|
+
const origin = rawCloud ? cloudOrigin(rawCloud) : PASSPORT_CLOUD;
|
|
197
|
+
// Which workspace the key pre-selects; an invalid or revoked key stops here.
|
|
198
|
+
const lookup = await lookupEnrollment(origin, key, deps.fetch ?? fetch, runtime.signal);
|
|
199
|
+
if (lookup.kind === "invalid" || lookup.kind === "revoked") {
|
|
200
|
+
return failure(lookup.message, 6, lookup.kind === "revoked" ? "enrollment_revoked" : "enrollment_invalid");
|
|
201
|
+
}
|
|
202
|
+
const universal = await supportsUniversalUrl(origin, deps.fetch ?? fetch, runtime.signal);
|
|
203
|
+
const url = universal ? universalUrl(origin, { enroll: key }) : undefined;
|
|
204
|
+
const found = detectAgents(agentsOnDisk(env, home, platform), { env, home, platform, which: deps.agents?.which });
|
|
205
|
+
const agents = found.filter((agent) => !only || only.has(agent));
|
|
206
|
+
recordEnrollment(key, origin);
|
|
207
|
+
const needsHooks = agents.some((agent) => HOOK_CLIENTS.includes(agent));
|
|
208
|
+
const { stable, problem } = needsHooks ? installStable(deps, { env, home, platform }) : {};
|
|
209
|
+
const context = {
|
|
210
|
+
env,
|
|
211
|
+
home,
|
|
212
|
+
platform,
|
|
213
|
+
url: url ?? `${origin}/mcp`,
|
|
214
|
+
workspaceId: "",
|
|
215
|
+
version: VERSION,
|
|
216
|
+
...deps.agents
|
|
217
|
+
};
|
|
218
|
+
const lines = agents.map((agent) => {
|
|
219
|
+
const line = { agent, name: AGENT_NAMES[agent], mcp: "unavailable", guard: "not_applicable" };
|
|
220
|
+
if (url)
|
|
221
|
+
addPassport(line, context);
|
|
222
|
+
addHooks(line, { env, home }, stable, problem);
|
|
223
|
+
return line;
|
|
224
|
+
});
|
|
225
|
+
if (stable)
|
|
226
|
+
pruneStaleCopies(env, stable);
|
|
227
|
+
return {
|
|
228
|
+
json: {
|
|
229
|
+
version: 1,
|
|
230
|
+
origin,
|
|
231
|
+
universal,
|
|
232
|
+
...(url ? { url } : {}),
|
|
233
|
+
...(lookup.kind === "ok" ? { workspace: { id: lookup.workspaceId, name: lookup.workspaceName } } : {}),
|
|
234
|
+
enrollment: { recorded: true },
|
|
235
|
+
clients: lines
|
|
236
|
+
},
|
|
237
|
+
human: summary(lookup.kind === "ok" ? lookup.workspaceName : new URL(origin).host, key, url, lines),
|
|
238
|
+
essential: true,
|
|
239
|
+
exitCode: 0
|
|
240
|
+
};
|
|
241
|
+
}
|
package/dist/cliSupport.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export type CliNextAction = {
|
|
|
26
26
|
argv: string[];
|
|
27
27
|
description: string;
|
|
28
28
|
};
|
|
29
|
+
/** First sign-in needs nothing: bare `passport login` opens the browser to sign
|
|
30
|
+
* in or sign up and pick a workspace. `passport init` does the same, step by step. */
|
|
31
|
+
export declare const FIRST_LOGIN_HINT = "Run: passport login, or passport init to set up step by step.";
|
|
32
|
+
export declare const FIRST_LOGIN_NEXT: CliNextAction[];
|
|
29
33
|
export type CliRemediation = {
|
|
30
34
|
action: string;
|
|
31
35
|
description: string;
|
package/dist/cliSupport.js
CHANGED
|
@@ -10,6 +10,13 @@ export const BRIDGE_ONE_LINER = "npx passport-bridge@latest";
|
|
|
10
10
|
export function selfCommand(runtime) {
|
|
11
11
|
return runtime.invokedAs === "passport-bridge" ? BRIDGE_ONE_LINER : "passport";
|
|
12
12
|
}
|
|
13
|
+
/** First sign-in needs nothing: bare `passport login` opens the browser to sign
|
|
14
|
+
* in or sign up and pick a workspace. `passport init` does the same, step by step. */
|
|
15
|
+
export const FIRST_LOGIN_HINT = "Run: passport login, or passport init to set up step by step.";
|
|
16
|
+
export const FIRST_LOGIN_NEXT = [
|
|
17
|
+
{ argv: ["passport", "login"], description: "Sign in or sign up in the browser." },
|
|
18
|
+
{ argv: ["passport", "init"], description: "Set up Passport for your agents, step by step." }
|
|
19
|
+
];
|
|
13
20
|
export class CliFailure extends Error {
|
|
14
21
|
exitCode;
|
|
15
22
|
cause;
|
|
@@ -131,8 +138,8 @@ export function resolveCliAuth(args, env) {
|
|
|
131
138
|
const suffix = names.length ? ` Available profiles: ${names.join(", ")}.` : "";
|
|
132
139
|
const hint = names.length
|
|
133
140
|
? `Choose one with: passport use <name> (available: ${names.join(", ")}), or pass --profile <name>.`
|
|
134
|
-
:
|
|
135
|
-
return failure(`No Passport profile selected.${suffix}
|
|
141
|
+
: FIRST_LOGIN_HINT;
|
|
142
|
+
return failure(names.length ? `No Passport profile selected.${suffix}` : "Not signed in to Passport.", 2, "auth", {
|
|
136
143
|
hint,
|
|
137
144
|
...(names.length
|
|
138
145
|
? {
|
|
@@ -145,9 +152,7 @@ export function resolveCliAuth(args, env) {
|
|
|
145
152
|
}))
|
|
146
153
|
]
|
|
147
154
|
}
|
|
148
|
-
: {
|
|
149
|
-
requiredInput: ["workspace-id"]
|
|
150
|
-
})
|
|
155
|
+
: { next: FIRST_LOGIN_NEXT })
|
|
151
156
|
});
|
|
152
157
|
}
|
|
153
158
|
const saved = creds[profile];
|
|
@@ -155,7 +160,7 @@ export function resolveCliAuth(args, env) {
|
|
|
155
160
|
const suffix = names.length ? ` Available profiles: ${names.join(", ")}.` : "";
|
|
156
161
|
const hint = names.length
|
|
157
162
|
? `Choose one with: passport use <name> (available: ${names.join(", ")}), or pass --profile <name>.`
|
|
158
|
-
:
|
|
163
|
+
: FIRST_LOGIN_HINT;
|
|
159
164
|
return failure(`Passport profile "${profile}" does not exist.${suffix}`, 2, "auth", {
|
|
160
165
|
hint,
|
|
161
166
|
...(names.length
|
|
@@ -169,9 +174,7 @@ export function resolveCliAuth(args, env) {
|
|
|
169
174
|
}))
|
|
170
175
|
]
|
|
171
176
|
}
|
|
172
|
-
: {
|
|
173
|
-
requiredInput: ["workspace-id"]
|
|
174
|
-
})
|
|
177
|
+
: { next: FIRST_LOGIN_NEXT })
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
return { kind: "profile", endpoint: endpoint(saved.endpoint), profile, refreshToken: saved.refreshToken };
|
package/dist/completion.js
CHANGED
|
@@ -16,7 +16,10 @@ const DESCRIPTIONS = {
|
|
|
16
16
|
prompts: "List or get MCP prompts",
|
|
17
17
|
scan: "Find keys your agents can reach. Local, no account",
|
|
18
18
|
discover: "Scan local MCP configuration for fleet governance",
|
|
19
|
-
hook: "Record the CLIs your agents run, and
|
|
19
|
+
hook: "Record the CLIs your agents run, and decide before they run",
|
|
20
|
+
wait: "Wait for a person to decide an approval request",
|
|
21
|
+
rules: "Test what Autopilot decides for a command",
|
|
22
|
+
sessions: "List your agents' recent sessions",
|
|
20
23
|
session: "Reuse one authenticated session for NDJSON commands",
|
|
21
24
|
access: "Use the signed managed access gateway",
|
|
22
25
|
setup: "Install and maintain your assigned AI workflows",
|
|
@@ -34,8 +37,10 @@ const COMMAND_FLAGS = {
|
|
|
34
37
|
connect: ["--alias", "--open", "--wait"],
|
|
35
38
|
resources: ["--out"],
|
|
36
39
|
prompts: ["--set", "--out"],
|
|
37
|
-
setup: ["--client", "--apply"],
|
|
40
|
+
setup: ["--client", "--apply", "--org", "--clients", "--yes", "--cloud"],
|
|
38
41
|
hook: ["--client", "--guard", "--apply"],
|
|
42
|
+
rules: ["--environment"],
|
|
43
|
+
sessions: ["--status"],
|
|
39
44
|
access: [
|
|
40
45
|
"--workspace",
|
|
41
46
|
"--client-id",
|
|
@@ -66,7 +71,11 @@ const VALUE_FLAGS = new Set([
|
|
|
66
71
|
"--private-key-file",
|
|
67
72
|
"--public-jwk-file",
|
|
68
73
|
"--delegation-id",
|
|
69
|
-
"--client-id"
|
|
74
|
+
"--client-id",
|
|
75
|
+
"--environment",
|
|
76
|
+
"--status",
|
|
77
|
+
"--org",
|
|
78
|
+
"--clients"
|
|
70
79
|
]);
|
|
71
80
|
function flagsFor(command) {
|
|
72
81
|
return [...GLOBAL, ...(command ? (COMMAND_FLAGS[command] ?? []) : [])];
|
package/dist/doctor.js
CHANGED
|
@@ -27,7 +27,7 @@ function inspectStore(checks, agentMode) {
|
|
|
27
27
|
? agentMode
|
|
28
28
|
? "No local credential store is needed in agent-key mode."
|
|
29
29
|
: "No local credential store exists."
|
|
30
|
-
: "The credential store could not be inspected.", missing && !agentMode ? "Run `passport login
|
|
30
|
+
: "The credential store could not be inspected.", missing && !agentMode ? "Run `passport login`, or `passport init` to set up step by step." : undefined);
|
|
31
31
|
return { profiles: empty, count: 0 };
|
|
32
32
|
}
|
|
33
33
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
@@ -198,7 +198,7 @@ export async function runDoctor(options) {
|
|
|
198
198
|
? `No profile was selected from ${names.length} stored profiles.`
|
|
199
199
|
: "No usable profile is configured.", names.length > 1
|
|
200
200
|
? "Run `passport profiles`, then `passport use <name>` or retry with `--profile <name>`."
|
|
201
|
-
: "Run `passport login
|
|
201
|
+
: "Run `passport login`, or `passport init` to set up step by step.");
|
|
202
202
|
}
|
|
203
203
|
else {
|
|
204
204
|
try {
|
|
@@ -283,7 +283,7 @@ export async function runDoctor(options) {
|
|
|
283
283
|
check(checks, "server_protocol", "fail", `CLI tool surface is not exact (${missing} missing, ${extra} extra).`, "Deploy the matching Passport gateway release.");
|
|
284
284
|
}
|
|
285
285
|
else {
|
|
286
|
-
check(checks, "server_protocol", "pass",
|
|
286
|
+
check(checks, "server_protocol", "pass", `The server supports this CLI (protocol ${safeServer.name} ${safeServer.version}).`);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
catch (error) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const ENROLLMENT_FILE = "enrollment.json";
|
|
2
|
+
export declare function isEnrollmentKey(value: string): boolean;
|
|
3
|
+
export declare function recordEnrollment(key: string, origin: string, now?: number): void;
|
|
4
|
+
/** The recorded key for this Passport, if any. Never throws. */
|
|
5
|
+
export declare function recordedEnrollment(origin: string): string | undefined;
|
|
6
|
+
export type EnrollmentLookup = {
|
|
7
|
+
kind: "ok";
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
workspaceName: string;
|
|
10
|
+
emailDomain?: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "invalid" | "revoked";
|
|
13
|
+
message: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "unavailable";
|
|
16
|
+
};
|
|
17
|
+
/** `GET /api/auth/enrollment/:key`: public, no credential sent. */
|
|
18
|
+
export declare function lookupEnrollment(origin: string, key: string, fetcher?: typeof fetch, signal?: AbortSignal): Promise<EnrollmentLookup>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A company's enrollment key (`pek_…`) on this computer: recorded by
|
|
3
|
+
* `passport setup --org`, then passed as a sign-in hint by `passport login`
|
|
4
|
+
* (`POST /api/auth/cli/start { enroll }`) and for attribution when the CLI
|
|
5
|
+
* credential is minted (`POST /api/my/bridge-credential { enrollmentKey }`).
|
|
6
|
+
* It is a workspace hint, never a credential: it grants nothing.
|
|
7
|
+
*/
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
10
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
11
|
+
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
12
|
+
export const ENROLLMENT_FILE = "enrollment.json";
|
|
13
|
+
const ENROLLMENT_KEY = /^pek_[A-Za-z0-9_.-]{8,200}$/;
|
|
14
|
+
const LOOKUP_MS = 5_000;
|
|
15
|
+
export function isEnrollmentKey(value) {
|
|
16
|
+
return ENROLLMENT_KEY.test(value);
|
|
17
|
+
}
|
|
18
|
+
export function recordEnrollment(key, origin, now = Date.now()) {
|
|
19
|
+
ensurePrivateDirectory(true);
|
|
20
|
+
writePrivateAtomic(join(credentialDir(), ENROLLMENT_FILE), ".enrollment", `${JSON.stringify({ version: 1, key, origin, recordedAt: now })}\n`, "enrollment record");
|
|
21
|
+
}
|
|
22
|
+
/** The recorded key for this Passport, if any. Never throws. */
|
|
23
|
+
export function recordedEnrollment(origin) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(readBoundedUtf8File(join(credentialDir(), ENROLLMENT_FILE), 16 * 1024));
|
|
26
|
+
return typeof parsed.key === "string" && isEnrollmentKey(parsed.key) && parsed.origin === origin
|
|
27
|
+
? parsed.key
|
|
28
|
+
: undefined;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function text(value, max) {
|
|
35
|
+
return typeof value === "string"
|
|
36
|
+
? value
|
|
37
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
|
|
38
|
+
.trim()
|
|
39
|
+
.slice(0, max)
|
|
40
|
+
: "";
|
|
41
|
+
}
|
|
42
|
+
/** `GET /api/auth/enrollment/:key`: public, no credential sent. */
|
|
43
|
+
export async function lookupEnrollment(origin, key, fetcher = fetch, signal) {
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetcher(`${origin}/api/auth/enrollment/${encodeURIComponent(key)}`, {
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: { accept: "application/json" },
|
|
48
|
+
redirect: "error",
|
|
49
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(LOOKUP_MS)]) : AbortSignal.timeout(LOOKUP_MS)
|
|
50
|
+
});
|
|
51
|
+
const body = await readBoundedJson(response, 16 * 1024).catch(() => ({}));
|
|
52
|
+
if (response.status === 410) {
|
|
53
|
+
return {
|
|
54
|
+
kind: "revoked",
|
|
55
|
+
message: text(body.error, 160) || "This enrollment key was revoked. Ask your admin for a new one."
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// An older server 404s every unknown route; only its own answer names the key.
|
|
59
|
+
if (response.status === 404 && /enrollment key/i.test(text(body.error, 160))) {
|
|
60
|
+
return { kind: "invalid", message: text(body.error, 160) };
|
|
61
|
+
}
|
|
62
|
+
if (!response.ok)
|
|
63
|
+
return { kind: "unavailable" };
|
|
64
|
+
const workspaceId = text(body.workspaceId, 128);
|
|
65
|
+
const workspaceName = text(body.workspaceName, 80);
|
|
66
|
+
if (!workspaceId)
|
|
67
|
+
return { kind: "unavailable" };
|
|
68
|
+
const emailDomain = text(body.emailDomain, 120);
|
|
69
|
+
return {
|
|
70
|
+
kind: "ok",
|
|
71
|
+
workspaceId,
|
|
72
|
+
workspaceName: workspaceName || workspaceId,
|
|
73
|
+
...(emailDomain ? { emailDomain } : {})
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { kind: "unavailable" };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Env } from "./cliSupport.js";
|
|
2
|
+
export declare const PLUGIN_NAME = "passport";
|
|
3
|
+
/** Shown wherever Passport would add hooks the plugin already runs. */
|
|
4
|
+
export declare function coveredByPlugin(name: string): string;
|
|
5
|
+
/** The running hook came from the Passport plugin. */
|
|
6
|
+
export declare function hookViaPlugin(env: Env): boolean;
|
|
7
|
+
export declare function pluginInstalled(client: "claude-code" | "codex" | "cursor", env: Env, home?: string): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Passport plugin (rsyed94/passport-plugins) installs the same audit and
|
|
3
|
+
* guard hooks as `passport hook install`, from the agent's plugin folder
|
|
4
|
+
* instead of its settings file. Its hooks run with `PASSPORT_HOOK_VIA=plugin`.
|
|
5
|
+
*
|
|
6
|
+
* Where each agent keeps installed plugins:
|
|
7
|
+
* Claude Code <config>/plugins/installed_plugins.json, keys "passport@<marketplace>"
|
|
8
|
+
* Codex <CODEX_HOME>/plugins/cache/<marketplace>/passport/
|
|
9
|
+
* Cursor ~/.cursor/plugins/cache/<marketplace>/passport/ or plugins/local/passport/
|
|
10
|
+
*
|
|
11
|
+
* Read-only and bounded; any problem reads as "not installed".
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
17
|
+
export const PLUGIN_NAME = "passport";
|
|
18
|
+
const MAX_BYTES = 1024 * 1024;
|
|
19
|
+
/** Shown wherever Passport would add hooks the plugin already runs. */
|
|
20
|
+
export function coveredByPlugin(name) {
|
|
21
|
+
return `${name}: already covered by the Passport plugin.`;
|
|
22
|
+
}
|
|
23
|
+
/** The running hook came from the Passport plugin. */
|
|
24
|
+
export function hookViaPlugin(env) {
|
|
25
|
+
return env.PASSPORT_HOOK_VIA?.trim().toLowerCase() === "plugin";
|
|
26
|
+
}
|
|
27
|
+
function inMarketplaceCache(root) {
|
|
28
|
+
try {
|
|
29
|
+
return readdirSync(join(root, "cache")).some((marketplace) => existsSync(join(root, "cache", marketplace, PLUGIN_NAME)));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function pluginInstalled(client, env, home = homedir()) {
|
|
36
|
+
try {
|
|
37
|
+
if (client === "claude-code") {
|
|
38
|
+
const config = env.CLAUDE_CONFIG_DIR?.trim() || join(home, ".claude");
|
|
39
|
+
const file = join(config, "plugins", "installed_plugins.json");
|
|
40
|
+
if (!existsSync(file))
|
|
41
|
+
return false;
|
|
42
|
+
const parsed = JSON.parse(readBoundedUtf8File(file, MAX_BYTES));
|
|
43
|
+
return Object.keys(parsed.plugins ?? {}).some((key) => key.split("@")[0] === PLUGIN_NAME);
|
|
44
|
+
}
|
|
45
|
+
if (client === "codex") {
|
|
46
|
+
return inMarketplaceCache(join(env.CODEX_HOME?.trim() || join(home, ".codex"), "plugins"));
|
|
47
|
+
}
|
|
48
|
+
const root = join(env.PASSPORT_CURSOR_HOME?.trim() || join(home, ".cursor"), "plugins");
|
|
49
|
+
return inMarketplaceCache(root) || existsSync(join(root, "local", PLUGIN_NAME));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/initAgents.d.ts
CHANGED
|
@@ -12,8 +12,10 @@ export type AgentContext = {
|
|
|
12
12
|
env: NodeJS.ProcessEnv;
|
|
13
13
|
home: string;
|
|
14
14
|
platform: NodeJS.Platform;
|
|
15
|
-
/** The
|
|
15
|
+
/** The MCP URL agents get: the universal `{origin}/mcp?…` with a hint, or
|
|
16
|
+
* the workspace's own `{origin}/w/{ws}/mcp` on a server without it. */
|
|
16
17
|
url: string;
|
|
18
|
+
/** Empty when not known yet (`passport setup --org` before any sign-in). */
|
|
17
19
|
workspaceId: string;
|
|
18
20
|
/** The running Passport version, to tell an older Passport install from this one. */
|
|
19
21
|
version: string;
|
package/dist/initAgents.js
CHANGED
|
@@ -24,6 +24,7 @@ import { closeSync, constants, copyFileSync, existsSync, fsyncSync, lstatSync, m
|
|
|
24
24
|
import { dirname, join } from "node:path";
|
|
25
25
|
import { appConfigRoot } from "./discover.js";
|
|
26
26
|
import { findOnPath, isEphemeralPath, isOtherPassportInstall } from "./initInstall.js";
|
|
27
|
+
import { passportMcpPath } from "./universalUrl.js";
|
|
27
28
|
export const ENTRY_NAME = "passport";
|
|
28
29
|
export const AGENT_NAMES = {
|
|
29
30
|
"claude-code": "Claude Code",
|
|
@@ -152,7 +153,7 @@ function sameUrl(a, b) {
|
|
|
152
153
|
const left = new URL(a);
|
|
153
154
|
const right = new URL(b);
|
|
154
155
|
const path = (url) => url.pathname.replace(/\/+$/, "");
|
|
155
|
-
return left.origin === right.origin && path(left) === path(right) &&
|
|
156
|
+
return left.origin === right.origin && path(left) === path(right) && left.search === right.search && !left.hash;
|
|
156
157
|
}
|
|
157
158
|
catch {
|
|
158
159
|
return false;
|
|
@@ -171,10 +172,13 @@ export function classifyEntry(raw, context, agent) {
|
|
|
171
172
|
try {
|
|
172
173
|
const parsed = new URL(url);
|
|
173
174
|
const ours = new URL(context.url);
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
175
|
+
const theirs = parsed.origin === ours.origin ? passportMcpPath(parsed) : null;
|
|
176
|
+
if (theirs && "workspace" in theirs && context.workspaceId && theirs.workspace !== context.workspaceId) {
|
|
176
177
|
return { kind: "other", message: `${name} uses Passport for another workspace. Left as is.` };
|
|
177
178
|
}
|
|
179
|
+
// Already on this Passport, by the one URL or this workspace's own: it works.
|
|
180
|
+
if (theirs)
|
|
181
|
+
return { kind: "current" };
|
|
178
182
|
}
|
|
179
183
|
catch {
|
|
180
184
|
/* not a URL we recognize */
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { type Preset } from "./cliAutopilotPolicy.js";
|
|
14
|
+
import { type AutopilotView, type InitSession } from "./initState.js";
|
|
15
|
+
export declare const AUTOPILOT_PATH = "/api/my/autopilot";
|
|
16
|
+
/** The short copy each preset gets in the terminal (map W1). */
|
|
17
|
+
export declare const PRESET_SHORT: Record<Preset, string>;
|
|
18
|
+
type Presets = AutopilotView["presets"];
|
|
19
|
+
export declare function parseAutopilotView(raw: unknown): AutopilotView | null;
|
|
20
|
+
export declare function environmentsStep(s: InitSession): Promise<void>;
|
|
21
|
+
/** "Production changes, deletes outside Development, and irreversible actions". */
|
|
22
|
+
export declare function askedFor(presets: Presets): string;
|
|
23
|
+
export declare function autopilotStep(s: InitSession): Promise<void>;
|
|
24
|
+
export {};
|