passport-bridge 0.7.1 → 0.8.1
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 +63 -12
- package/dist/activeProfile.js +122 -0
- package/dist/bridge.js +2 -9
- package/dist/cli.js +3 -1
- package/dist/cliArgs.js +8 -1
- package/dist/cliConnect.js +161 -0
- package/dist/cliDescribe.js +18 -0
- package/dist/cliLogin.js +96 -24
- package/dist/cliOffline.js +106 -19
- package/dist/cliOutput.js +14 -2
- package/dist/cliReady.js +56 -0
- package/dist/cliResult.js +29 -5
- package/dist/cliSupport.js +79 -7
- package/dist/completion.js +4 -1
- package/dist/credentialStorage.js +293 -0
- package/dist/credentials.js +67 -291
- package/dist/doctor.js +73 -6
- package/dist/passport.js +100 -129
- package/dist/tokenWorkspace.js +5 -0
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/cliLogin.js
CHANGED
|
@@ -1,25 +1,73 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { workspaceOfToken } from "./tokenWorkspace.js";
|
|
3
|
+
import { bool, value } from "./cliArgs.js";
|
|
4
|
+
import { assertCredentialStoreMutationReady, credsPath, getProfile, getProfileStrict, readActiveProfile, readCreds, setActiveProfile, withProfileLock, writeProfile } from "./credentials.js";
|
|
4
5
|
import { cloudOrigin, endpoint, failure, openUrl, profileName, readBoundedJson, safeApiError, sameOriginWebUrl, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
6
|
+
const PASSPORT_CLOUD = "https://passportmcp.com";
|
|
7
|
+
function workspaceFromEndpoint(raw) {
|
|
8
|
+
try {
|
|
9
|
+
const match = new URL(endpoint(raw)).pathname.match(/^\/w\/([^/]+)\/mcp\/?$/);
|
|
10
|
+
const workspace = match ? decodeURIComponent(match[1]) : "";
|
|
11
|
+
return /^[A-Za-z0-9_-]{1,80}$/.test(workspace) ? workspace : "";
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
5
17
|
function loginOptions(args, runtime) {
|
|
6
18
|
const explicitProfile = value(args, "profile");
|
|
19
|
+
const workspaceOption = value(args, "workspace");
|
|
20
|
+
const explicitWorkspace = workspaceOption !== undefined;
|
|
21
|
+
const workspaceFromOption = workspaceOption?.trim() ?? "";
|
|
22
|
+
if (explicitWorkspace && !/^[A-Za-z0-9_-]{1,80}$/.test(workspaceFromOption)) {
|
|
23
|
+
return failure("--workspace must be a valid workspace id.", 6, "usage");
|
|
24
|
+
}
|
|
25
|
+
const creds = readCreds();
|
|
26
|
+
const names = Object.keys(creds).sort();
|
|
27
|
+
const active = readActiveProfile();
|
|
7
28
|
const requestedProfile = explicitProfile !== undefined
|
|
8
29
|
? profileName(explicitProfile)
|
|
9
30
|
: runtime.env.PASSPORT_PROFILE
|
|
10
31
|
? profileName(runtime.env.PASSPORT_PROFILE)
|
|
11
|
-
:
|
|
32
|
+
: explicitWorkspace
|
|
33
|
+
? `cli@${workspaceFromOption}`
|
|
34
|
+
: active && creds[active]
|
|
35
|
+
? active
|
|
36
|
+
: names.length === 1
|
|
37
|
+
? names[0]
|
|
38
|
+
: "";
|
|
12
39
|
const existing = requestedProfile ? getProfile(requestedProfile) : undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
if (explicitWorkspace && existing) {
|
|
41
|
+
const existingWorkspace = workspaceFromEndpoint(existing.endpoint) || workspaceOfToken(existing.refreshToken);
|
|
42
|
+
if (!existingWorkspace || existingWorkspace !== workspaceFromOption) {
|
|
43
|
+
return failure(`Profile "${requestedProfile}" belongs to another workspace and will not be overwritten. Choose a new --profile name.`, 6, "usage");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const workspace = explicitWorkspace ? workspaceFromOption : existing ? workspaceFromEndpoint(existing.endpoint) : "";
|
|
47
|
+
const cloudRaw = value(args, "cloud") ||
|
|
48
|
+
runtime.env.PASSPORT_CLOUD ||
|
|
49
|
+
(existing ? new URL(endpoint(existing.endpoint)).origin : workspace ? PASSPORT_CLOUD : "");
|
|
50
|
+
if (!cloudRaw) {
|
|
51
|
+
if (names.length > 1) {
|
|
52
|
+
return failure(`Choose a profile before signing in. Available profiles: ${names.join(", ")}.`, 2, "auth", {
|
|
53
|
+
hint: "Run: passport profiles\nThen: passport use <name>\nOr create another profile with --cloud and --workspace.",
|
|
54
|
+
profiles: names,
|
|
55
|
+
next: [
|
|
56
|
+
{ argv: ["passport", "profiles"], description: "List saved profiles." },
|
|
57
|
+
...names.map((name) => ({
|
|
58
|
+
argv: ["passport", "use", name],
|
|
59
|
+
description: `Select the saved profile "${name}" to refresh.`
|
|
60
|
+
}))
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return failure("Tell Passport which workspace to sign in to.", 6, "usage", {
|
|
65
|
+
hint: `Run: passport login --workspace <workspace-id>\nFor self-hosted Passport, also pass --cloud <origin>.`,
|
|
66
|
+
requiredInput: ["workspace-id"]
|
|
67
|
+
});
|
|
20
68
|
}
|
|
21
69
|
const clientOption = value(args, "client");
|
|
22
|
-
const client = clientOption === undefined ? "cli" : clientOption.trim();
|
|
70
|
+
const client = clientOption === undefined ? existing?.client || "cli" : clientOption.trim();
|
|
23
71
|
if (!/^[A-Za-z0-9._-]{1,40}$/.test(client)) {
|
|
24
72
|
return failure("--client must be a valid client id (1-40 characters).", 6, "usage");
|
|
25
73
|
}
|
|
@@ -61,11 +109,18 @@ export async function login(args, runtime) {
|
|
|
61
109
|
return failure("Passport returned an invalid device sign-in response.", 1, "invalid_server_response");
|
|
62
110
|
}
|
|
63
111
|
const verifyUrl = sameOriginWebUrl(started.verifyUrl, cloud, "a sign-in URL");
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
112
|
+
const shouldOpen = !bool(args, "no-open") && !runtime.env.PASSPORT_NO_OPEN;
|
|
113
|
+
runtime.stderr.write(`Sign in to Passport${workspace ? ` workspace ${workspace}` : ""}\n${shouldOpen ? "Opening your browser..." : "Browser opening is disabled."}\nOpen: ${verifyUrl}\nConfirm code: ${started.userCode}\nWaiting for approval (up to 10 minutes; press Ctrl-C to cancel)...\n`);
|
|
114
|
+
if (shouldOpen && !openUrl(verifyUrl)) {
|
|
115
|
+
runtime.stderr.write("Could not open a browser automatically. Open the URL above to continue.\n");
|
|
116
|
+
}
|
|
67
117
|
const sessionToken = await waitForDeviceApproval(cloud, started.code, args, runtime);
|
|
68
|
-
|
|
118
|
+
runtime.stderr.write("Sign-in approved. Creating your CLI credential...\n");
|
|
119
|
+
const approvedWorkspace = workspaceOfToken(sessionToken);
|
|
120
|
+
if (workspace && approvedWorkspace && approvedWorkspace !== workspace) {
|
|
121
|
+
return failure("Passport approved a different workspace than the one requested; no credential was saved.", 2, "auth");
|
|
122
|
+
}
|
|
123
|
+
const tokenWorkspace = workspace || approvedWorkspace || "workspace";
|
|
69
124
|
const profile = profileName(requestedProfile || `cli@${tokenWorkspace}`);
|
|
70
125
|
const storedInstanceId = getProfileStrict(profile)?.instanceId;
|
|
71
126
|
const instanceId = storedInstanceId && /^[A-Za-z0-9._:-]{1,128}$/.test(storedInstanceId) ? storedInstanceId : randomUUID();
|
|
@@ -89,15 +144,32 @@ export async function login(args, runtime) {
|
|
|
89
144
|
return failure("Passport returned an invalid credential response.", 1, "invalid_server_response");
|
|
90
145
|
}
|
|
91
146
|
const credentialEndpoint = sameOriginWebUrl(body.endpoint, cloud, "a credential endpoint");
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
147
|
+
const endpointWorkspace = workspaceFromEndpoint(credentialEndpoint);
|
|
148
|
+
if (workspace && endpointWorkspace && endpointWorkspace !== workspace) {
|
|
149
|
+
return failure("Passport returned a credential for a different workspace; no credential was saved.", 2, "auth");
|
|
150
|
+
}
|
|
151
|
+
await withProfileLock(profile, async () => {
|
|
152
|
+
writeProfile(profile, {
|
|
153
|
+
refreshToken: body.refreshToken,
|
|
154
|
+
endpoint: credentialEndpoint,
|
|
155
|
+
instanceId,
|
|
156
|
+
client,
|
|
157
|
+
target: "workspace"
|
|
158
|
+
});
|
|
159
|
+
// Login is an intentional profile choice. Persist it as the local
|
|
160
|
+
// default so the very next bare `passport status`/`search` works even
|
|
161
|
+
// when other client/workspace profiles already exist.
|
|
162
|
+
setActiveProfile(profile);
|
|
163
|
+
});
|
|
99
164
|
return {
|
|
100
|
-
json: {
|
|
101
|
-
|
|
165
|
+
json: {
|
|
166
|
+
profile,
|
|
167
|
+
endpoint: credentialEndpoint,
|
|
168
|
+
client,
|
|
169
|
+
surface: "cli",
|
|
170
|
+
active: true,
|
|
171
|
+
next: [{ argv: ["passport", "status", "--json"], description: "Verify the active profile and connections." }]
|
|
172
|
+
},
|
|
173
|
+
human: `Signed in as profile "${profile}".\nActive profile: "${profile}".\nCredential saved to ${credsPath()}.\nNext: passport status`
|
|
102
174
|
};
|
|
103
175
|
}
|
package/dist/cliOffline.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { value } from "./cliArgs.js";
|
|
2
2
|
import { completionScript } from "./completion.js";
|
|
3
|
-
import { readCreds } from "./credentials.js";
|
|
4
|
-
import { endpoint, failure, profileName } from "./cliSupport.js";
|
|
3
|
+
import { inferredProfileClient, readActiveProfile, readCreds, setActiveProfile } from "./credentials.js";
|
|
4
|
+
import { endpoint, failure, profileName, selectStoredProfile } from "./cliSupport.js";
|
|
5
5
|
import { VERSION } from "./version.js";
|
|
6
6
|
export function completionResult(args) {
|
|
7
7
|
const shell = args.positionals[0];
|
|
@@ -11,33 +11,115 @@ export function completionResult(args) {
|
|
|
11
11
|
const script = completionScript(shell);
|
|
12
12
|
return { json: { shell, script }, human: script, essential: true, raw: true };
|
|
13
13
|
}
|
|
14
|
+
export function profilesResult(_args) {
|
|
15
|
+
const creds = readCreds();
|
|
16
|
+
const names = Object.keys(creds).sort();
|
|
17
|
+
const selection = selectStoredProfile(_args, {}, creds, true);
|
|
18
|
+
const selected = readActiveProfile();
|
|
19
|
+
const active = selected && creds[selected] ? selected : undefined;
|
|
20
|
+
const profiles = names.map((name) => ({
|
|
21
|
+
name,
|
|
22
|
+
active: name === active,
|
|
23
|
+
...(inferredProfileClient(name, creds[name]) ? { client: inferredProfileClient(name, creds[name]) } : {})
|
|
24
|
+
}));
|
|
25
|
+
if (!profiles.length) {
|
|
26
|
+
return {
|
|
27
|
+
json: { profiles: [], selectionSource: selection.source },
|
|
28
|
+
human: "No Passport profiles saved.\nRun: passport login --workspace <workspace-id>.",
|
|
29
|
+
essential: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const lines = [
|
|
33
|
+
"Passport profiles:",
|
|
34
|
+
...profiles.map((profile) => ` ${profile.active ? "*" : " "} ${profile.name}${profile.active ? " (active)" : ""}${profile.client ? ` [${profile.client}]` : ""}`),
|
|
35
|
+
"",
|
|
36
|
+
"Use `passport use <name>` to select a profile."
|
|
37
|
+
];
|
|
38
|
+
return {
|
|
39
|
+
json: { profiles, ...(active ? { active } : {}), selectionSource: selection.source },
|
|
40
|
+
human: lines.join("\n"),
|
|
41
|
+
essential: true
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function useProfileResult(args, env) {
|
|
45
|
+
const profile = profileName(args.positionals[0]);
|
|
46
|
+
const creds = readCreds();
|
|
47
|
+
const names = Object.keys(creds).sort();
|
|
48
|
+
if (!creds[profile]) {
|
|
49
|
+
const suffix = names.length ? ` Available profiles: ${names.join(", ")}.` : "";
|
|
50
|
+
return failure(`Passport profile "${profile}" does not exist.${suffix}`, 2, "auth", {
|
|
51
|
+
hint: names.length
|
|
52
|
+
? `Choose one with: passport use <name> (available: ${names.join(", ")}).`
|
|
53
|
+
: "Run: passport login --workspace <workspace-id>.",
|
|
54
|
+
...(names.length
|
|
55
|
+
? {
|
|
56
|
+
profiles: names,
|
|
57
|
+
next: names.map((name) => ({
|
|
58
|
+
argv: ["passport", "use", name],
|
|
59
|
+
description: `Select the saved profile "${name}".`
|
|
60
|
+
}))
|
|
61
|
+
}
|
|
62
|
+
: { requiredInput: ["workspace-id"] })
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
setActiveProfile(profile);
|
|
66
|
+
const environmentProfile = env.PASSPORT_PROFILE ? profileName(env.PASSPORT_PROFILE) : undefined;
|
|
67
|
+
const overridden = environmentProfile && environmentProfile !== profile;
|
|
68
|
+
return {
|
|
69
|
+
json: {
|
|
70
|
+
profile,
|
|
71
|
+
active: true,
|
|
72
|
+
effectiveProfile: overridden ? environmentProfile : profile,
|
|
73
|
+
...(overridden ? { overriddenBy: "PASSPORT_PROFILE" } : {})
|
|
74
|
+
},
|
|
75
|
+
human: overridden
|
|
76
|
+
? `Saved active profile: "${profile}".\nPASSPORT_PROFILE still overrides it with "${environmentProfile}" for authenticated commands.`
|
|
77
|
+
: `Active profile: "${profile}".\nNext: passport status`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
14
80
|
export function versionResult(args, env) {
|
|
15
81
|
let profile;
|
|
16
82
|
let resolvedEndpoint;
|
|
17
|
-
|
|
83
|
+
const agentMode = Boolean(env.PASSPORT_AGENT_KEY && env.PASSPORT_ENDPOINT);
|
|
84
|
+
if (agentMode && value(args, "profile") !== undefined) {
|
|
18
85
|
return failure("--profile cannot be used with PASSPORT_AGENT_KEY.", 6, "usage");
|
|
19
86
|
}
|
|
20
|
-
|
|
21
|
-
|
|
87
|
+
const creds = readCreds();
|
|
88
|
+
const profileCount = Object.keys(creds).length;
|
|
89
|
+
const selection = agentMode
|
|
90
|
+
? { profile: undefined, source: "none", names: Object.keys(creds).sort(), cliCandidates: [] }
|
|
91
|
+
: selectStoredProfile(args, env, creds, true);
|
|
92
|
+
if (agentMode) {
|
|
93
|
+
resolvedEndpoint = endpoint(env.PASSPORT_ENDPOINT ?? "");
|
|
22
94
|
}
|
|
23
95
|
else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const candidate = explicitProfile !== undefined
|
|
28
|
-
? profileName(explicitProfile)
|
|
29
|
-
: env.PASSPORT_PROFILE
|
|
30
|
-
? profileName(env.PASSPORT_PROFILE)
|
|
31
|
-
: names.length === 1
|
|
32
|
-
? profileName(names[0])
|
|
33
|
-
: "";
|
|
34
|
-
if (candidate && creds[candidate]) {
|
|
35
|
-
profile = candidate;
|
|
36
|
-
resolvedEndpoint = endpoint(creds[candidate].endpoint);
|
|
96
|
+
if (selection.profile && creds[selection.profile]) {
|
|
97
|
+
profile = selection.profile;
|
|
98
|
+
resolvedEndpoint = endpoint(creds[profile].endpoint);
|
|
37
99
|
}
|
|
38
100
|
}
|
|
101
|
+
const selected = profile ?? null;
|
|
102
|
+
const next = agentMode
|
|
103
|
+
? [{ argv: ["passport", "status"], description: "Check the agent-key connection and visible connections." }]
|
|
104
|
+
: profile
|
|
105
|
+
? [{ argv: ["passport", "status"], description: "Check the selected profile and visible connections." }]
|
|
106
|
+
: profileCount > 1
|
|
107
|
+
? [
|
|
108
|
+
{ argv: ["passport", "profiles"], description: "List saved profiles." },
|
|
109
|
+
...Object.keys(creds)
|
|
110
|
+
.sort()
|
|
111
|
+
.map((name) => ({ argv: ["passport", "use", name], description: `Select the saved profile "${name}".` }))
|
|
112
|
+
]
|
|
113
|
+
: profileCount === 1
|
|
114
|
+
? [{ argv: ["passport", "status"], description: "Use the saved profile and check visible connections." }]
|
|
115
|
+
: [{ argv: ["passport", "help", "login"], description: "Show the required inputs for first login." }];
|
|
39
116
|
const data = {
|
|
40
117
|
version: VERSION,
|
|
118
|
+
profileCount,
|
|
119
|
+
profileSelected: selected,
|
|
120
|
+
selectionSource: agentMode ? "agent-key" : selection.source,
|
|
121
|
+
next,
|
|
122
|
+
...(profileCount === 0 && !agentMode ? { requiredInput: ["workspace-id"] } : {}),
|
|
41
123
|
...(resolvedEndpoint ? { endpoint: resolvedEndpoint } : {}),
|
|
42
124
|
...(profile ? { profile } : {})
|
|
43
125
|
};
|
|
@@ -45,8 +127,13 @@ export function versionResult(args, env) {
|
|
|
45
127
|
json: data,
|
|
46
128
|
human: [
|
|
47
129
|
`passport ${VERSION}`,
|
|
130
|
+
`Profiles: ${profileCount}`,
|
|
48
131
|
...(resolvedEndpoint ? [`Endpoint: ${resolvedEndpoint}`] : []),
|
|
49
|
-
...(
|
|
132
|
+
...(agentMode
|
|
133
|
+
? ["Authentication: agent-key", "Next: passport status"]
|
|
134
|
+
: profile
|
|
135
|
+
? [`Profile: ${profile} (${selection.source})`, "Next: passport status"]
|
|
136
|
+
: ["No profile selected.", ...next.slice(0, 1).map((action) => `Next: ${action.argv.join(" ")}`)])
|
|
50
137
|
].join("\n"),
|
|
51
138
|
essential: true
|
|
52
139
|
};
|
package/dist/cliOutput.js
CHANGED
|
@@ -4,10 +4,13 @@ import { CliFailure, sanitize } from "./cliSupport.js";
|
|
|
4
4
|
import { VERSION } from "./version.js";
|
|
5
5
|
function helpText(verb) {
|
|
6
6
|
const details = {
|
|
7
|
-
login: "passport login --
|
|
7
|
+
login: "passport login [--workspace <id>] [--cloud <origin>] [--client <id>] [--profile <name>] [--no-open]\nStarts device sign-in, stores a cli-surface rotating credential, and makes that profile active. Passport Cloud is used when --workspace is provided without --cloud.",
|
|
8
8
|
logout: "passport logout [--profile <name>]\nRevokes the rotating credential and always removes the local profile.",
|
|
9
|
+
profiles: "passport profiles\nLists saved profiles and marks the active profile. Works offline.",
|
|
10
|
+
use: "passport use <name>\nSelects a saved profile as the default for subsequent commands. Works offline.",
|
|
9
11
|
status: "passport status\nJSON: {workspace,member,endpoint,auth,profile?,client,mcps:[{app,name,status,toolCount}]}",
|
|
10
12
|
doctor: "passport doctor [--profile <name>]\nChecks Node, credential-store safety, endpoint security, server health, authentication, serverInfo, and the exact CLI protocol. JSON includes {ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}.",
|
|
13
|
+
ready: "passport ready [--profile <name>]\nRuns the local, authentication, server, and exact CLI-protocol preflight. JSON includes {ready,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}.",
|
|
11
14
|
search: "passport search [query...] [--app <key>]\nEmpty query lists the complete permitted catalog. JSON is the server search payload.",
|
|
12
15
|
describe: "passport describe <tool>\nShows the exact tool definition and complete parameter schema.",
|
|
13
16
|
run: "passport run <tool> [json-object]\n --args - read the JSON object from stdin\n --set key=value set a string argument (repeatable)\n --set-json key=<json> set a typed argument (repeatable)\n --wait <sec> retry only a definite approval_pending call\nJSON is the complete MCP tool result; human stdout is verbatim tool text.",
|
|
@@ -28,8 +31,11 @@ Usage: passport <command> [options]
|
|
|
28
31
|
|
|
29
32
|
login Sign in with the device flow
|
|
30
33
|
logout Revoke and remove a profile
|
|
34
|
+
profiles List saved profiles and the active selection
|
|
35
|
+
use Select a saved profile for subsequent commands
|
|
31
36
|
status Show identity and visible MCP connection state
|
|
32
37
|
doctor Diagnose local setup and server compatibility
|
|
38
|
+
ready Check whether this CLI is ready to use
|
|
33
39
|
search Find permitted tools or list the catalog
|
|
34
40
|
describe Show one exact tool definition
|
|
35
41
|
run Run a governed tool
|
|
@@ -101,6 +107,12 @@ export function failurePayload(error) {
|
|
|
101
107
|
exitCode: error.exitCode,
|
|
102
108
|
...(error.details.approvalId ? { approvalId: error.details.approvalId } : {}),
|
|
103
109
|
...(error.details.app ? { app: error.details.app } : {}),
|
|
104
|
-
...(error.details.connectUrl ? { connectUrl: error.details.connectUrl } : {})
|
|
110
|
+
...(error.details.connectUrl ? { connectUrl: error.details.connectUrl } : {}),
|
|
111
|
+
...(error.details.hint ? { hint: error.details.hint } : {}),
|
|
112
|
+
...(error.details.profiles ? { profiles: error.details.profiles } : {}),
|
|
113
|
+
...(error.details.next ? { next: error.details.next } : {}),
|
|
114
|
+
...(error.details.remediation ? { remediation: error.details.remediation } : {}),
|
|
115
|
+
...(error.details.retry ? { retry: error.details.retry } : {}),
|
|
116
|
+
...(error.details.requiredInput ? { requiredInput: error.details.requiredInput } : {})
|
|
105
117
|
};
|
|
106
118
|
}
|
package/dist/cliReady.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { value } from "./cliArgs.js";
|
|
2
|
+
import { callerFrom, endpoint, resolveCliAuth, sanitize, timeoutMs } from "./cliSupport.js";
|
|
3
|
+
import { formatDoctorReport, runDoctor } from "./doctor.js";
|
|
4
|
+
import { VERSION } from "./version.js";
|
|
5
|
+
/**
|
|
6
|
+
* Run the same local, auth, server, and protocol checks as doctor, with a
|
|
7
|
+
* machine-friendly `ready` field for agents and CI preflight scripts.
|
|
8
|
+
*/
|
|
9
|
+
export async function ready(args, runtime) {
|
|
10
|
+
// resolveCliAuth owns profile selection and legacy migration. Resolve once
|
|
11
|
+
// before doctor so a deterministic CLI profile can become active for the
|
|
12
|
+
// checks below. Doctor remains the source of truth for the surfaced report;
|
|
13
|
+
// failures here are intentionally left for doctor to explain precisely.
|
|
14
|
+
try {
|
|
15
|
+
resolveCliAuth(args, runtime.env);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Doctor reports incomplete, ambiguous, or malformed authentication with
|
|
19
|
+
// safe checks and exact remediation. Do not mask that report here.
|
|
20
|
+
}
|
|
21
|
+
const report = await runDoctor({
|
|
22
|
+
version: VERSION,
|
|
23
|
+
profile: value(args, "profile"),
|
|
24
|
+
env: runtime.env,
|
|
25
|
+
timeoutMs: timeoutMs(args),
|
|
26
|
+
signal: runtime.signal,
|
|
27
|
+
caller: callerFrom(args, runtime.env),
|
|
28
|
+
normalizeEndpoint: endpoint,
|
|
29
|
+
redactError: sanitize
|
|
30
|
+
});
|
|
31
|
+
const json = {
|
|
32
|
+
ready: report.ok,
|
|
33
|
+
version: report.version,
|
|
34
|
+
ok: report.ok,
|
|
35
|
+
auth: report.auth,
|
|
36
|
+
...(report.profile ? { profile: report.profile } : {}),
|
|
37
|
+
profileCount: report.profileCount,
|
|
38
|
+
...(report.endpointOrigin ? { endpointOrigin: report.endpointOrigin } : {}),
|
|
39
|
+
...(report.server ? { server: report.server } : {}),
|
|
40
|
+
checks: report.checks
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
json,
|
|
44
|
+
human: formatReadyReport(report),
|
|
45
|
+
essential: true,
|
|
46
|
+
exitCode: report.ok ? 0 : 1
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function formatReadyReport(report) {
|
|
50
|
+
const lines = formatDoctorReport(report).split("\n");
|
|
51
|
+
lines[0] = `Passport ready ${report.version}`;
|
|
52
|
+
lines[lines.length - 1] = report.ok
|
|
53
|
+
? "Ready: all required checks passed."
|
|
54
|
+
: "Not ready: fix the failed checks above.";
|
|
55
|
+
return lines.join("\n");
|
|
56
|
+
}
|
package/dist/cliResult.js
CHANGED
|
@@ -60,20 +60,44 @@ export function refusalOf(result) {
|
|
|
60
60
|
app,
|
|
61
61
|
connectUrl,
|
|
62
62
|
hint: connectUrl
|
|
63
|
-
?
|
|
64
|
-
:
|
|
63
|
+
? `Open: ${connectUrl}\nFinish the browser sign-in, then retry the command.`
|
|
64
|
+
: app
|
|
65
|
+
? "Run the connect action below, then retry the command."
|
|
66
|
+
: "Run passport status to identify the app that needs connecting.",
|
|
67
|
+
next: app
|
|
68
|
+
? [
|
|
69
|
+
{
|
|
70
|
+
argv: ["passport", "connect", app, "--wait", "120"],
|
|
71
|
+
description: "Connect the required app, then retry the tool call."
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
: [{ argv: ["passport", "status"], description: "Identify the app that needs connecting." }]
|
|
65
75
|
});
|
|
66
76
|
}
|
|
67
77
|
if (cause === "approval_pending") {
|
|
68
78
|
if (approvalId && !message.includes(approvalId))
|
|
69
79
|
message = `${message}\nApproval ID: ${approvalId}`;
|
|
70
|
-
return new CliFailure(message, 4, cause, {
|
|
80
|
+
return new CliFailure(message, 4, cause, {
|
|
81
|
+
app,
|
|
82
|
+
approvalId,
|
|
83
|
+
hint: "Approve the request in Passport, then retry it. For future calls, add --wait <seconds>."
|
|
84
|
+
});
|
|
71
85
|
}
|
|
72
86
|
if (cause === "approval_denied" || cause === "blocked") {
|
|
73
87
|
return new CliFailure(message, 5, cause, { app, approvalId });
|
|
74
88
|
}
|
|
75
|
-
if (cause === "unknown_tool")
|
|
76
|
-
return new CliFailure(message, 6, cause, {
|
|
89
|
+
if (cause === "unknown_tool") {
|
|
90
|
+
return new CliFailure(message, 6, cause, {
|
|
91
|
+
app,
|
|
92
|
+
hint: `Run: passport search${app ? ` --app ${app}` : ""}`,
|
|
93
|
+
next: [
|
|
94
|
+
{
|
|
95
|
+
argv: app ? ["passport", "search", "", "--app", app] : ["passport", "search", ""],
|
|
96
|
+
description: "List permitted tool names."
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
77
101
|
return new CliFailure(`Passport returned an unsupported refusal cause: ${cause}.`, 1, "invalid_server_response", {
|
|
78
102
|
app,
|
|
79
103
|
approvalId
|
package/dist/cliSupport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { value } from "./cliArgs.js";
|
|
3
|
-
import { assertProfileName, readCreds } from "./credentials.js";
|
|
3
|
+
import { assertProfileName, isCliProfile, readActiveProfile, readCreds, setActiveProfile } from "./credentials.js";
|
|
4
4
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
5
5
|
export { readBoundedJson } from "./boundedResponse.js";
|
|
6
6
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -59,6 +59,42 @@ export function cloudOrigin(raw) {
|
|
|
59
59
|
}
|
|
60
60
|
return parsed.origin;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve a local profile without ever guessing between workspaces. Explicit
|
|
64
|
+
* CLI and environment selectors win over the active pointer. In the absence
|
|
65
|
+
* of those selectors, exactly one CLI-owned profile is deterministic enough
|
|
66
|
+
* to migrate to the active pointer; otherwise only the historical sole
|
|
67
|
+
* profile fallback is retained.
|
|
68
|
+
*/
|
|
69
|
+
export function selectStoredProfile(args, env, creds = readCreds(), persistDetected = false) {
|
|
70
|
+
const names = Object.keys(creds).sort();
|
|
71
|
+
const explicit = args ? value(args, "profile") : undefined;
|
|
72
|
+
if (explicit !== undefined) {
|
|
73
|
+
return { profile: profileName(explicit), source: "explicit", names, cliCandidates: [] };
|
|
74
|
+
}
|
|
75
|
+
if (env.PASSPORT_PROFILE) {
|
|
76
|
+
return { profile: profileName(env.PASSPORT_PROFILE), source: "environment", names, cliCandidates: [] };
|
|
77
|
+
}
|
|
78
|
+
const active = readActiveProfile();
|
|
79
|
+
if (active && creds[active]) {
|
|
80
|
+
return { profile: active, source: "active", names, cliCandidates: [] };
|
|
81
|
+
}
|
|
82
|
+
const cliCandidates = names.filter((name) => isCliProfile(name, creds[name]));
|
|
83
|
+
if (cliCandidates.length === 1) {
|
|
84
|
+
const profile = cliCandidates[0];
|
|
85
|
+
if (persistDetected)
|
|
86
|
+
setActiveProfile(profile);
|
|
87
|
+
return { profile, source: "detected-client", names, cliCandidates };
|
|
88
|
+
}
|
|
89
|
+
if (names.length === 1) {
|
|
90
|
+
return { profile: names[0], source: "sole-profile", names, cliCandidates };
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
source: names.length > 1 ? "ambiguous" : "none",
|
|
94
|
+
names,
|
|
95
|
+
cliCandidates
|
|
96
|
+
};
|
|
97
|
+
}
|
|
62
98
|
export function sameOriginWebUrl(raw, trustedOrigin, label) {
|
|
63
99
|
const normalized = endpoint(raw);
|
|
64
100
|
if (new URL(normalized).origin !== trustedOrigin) {
|
|
@@ -73,7 +109,7 @@ export function resolveCliAuth(args, env) {
|
|
|
73
109
|
if (agentKey || agentEndpoint) {
|
|
74
110
|
if (!agentKey || !agentEndpoint) {
|
|
75
111
|
return failure("PASSPORT_AGENT_KEY and PASSPORT_ENDPOINT must be set together.", 2, "auth", {
|
|
76
|
-
hint: "Set both variables, or
|
|
112
|
+
hint: "Set both variables, or unset both before running passport login."
|
|
77
113
|
});
|
|
78
114
|
}
|
|
79
115
|
if (explicitProfile !== undefined) {
|
|
@@ -82,18 +118,54 @@ export function resolveCliAuth(args, env) {
|
|
|
82
118
|
return { kind: "agent-key", endpoint: endpoint(agentEndpoint), agentKey };
|
|
83
119
|
}
|
|
84
120
|
const creds = readCreds();
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const profile =
|
|
121
|
+
const selection = selectStoredProfile(args, env, creds, true);
|
|
122
|
+
const names = selection.names;
|
|
123
|
+
const profile = selection.profile ?? "";
|
|
88
124
|
if (!profile) {
|
|
89
125
|
const suffix = names.length ? ` Available profiles: ${names.join(", ")}.` : "";
|
|
90
|
-
|
|
126
|
+
const hint = names.length
|
|
127
|
+
? `Choose one with: passport use <name> (available: ${names.join(", ")}), or pass --profile <name>.`
|
|
128
|
+
: "Run: passport login --workspace <workspace-id>.";
|
|
129
|
+
return failure(`No Passport profile selected.${suffix}`, 2, "auth", {
|
|
130
|
+
hint,
|
|
131
|
+
...(names.length
|
|
132
|
+
? {
|
|
133
|
+
profiles: names,
|
|
134
|
+
next: [
|
|
135
|
+
{ argv: ["passport", "profiles"], description: "List saved profiles." },
|
|
136
|
+
...names.map((name) => ({
|
|
137
|
+
argv: ["passport", "use", name],
|
|
138
|
+
description: `Select the saved profile "${name}".`
|
|
139
|
+
}))
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
: {
|
|
143
|
+
requiredInput: ["workspace-id"]
|
|
144
|
+
})
|
|
145
|
+
});
|
|
91
146
|
}
|
|
92
147
|
const saved = creds[profile];
|
|
93
148
|
if (!saved) {
|
|
94
149
|
const suffix = names.length ? ` Available profiles: ${names.join(", ")}.` : "";
|
|
150
|
+
const hint = names.length
|
|
151
|
+
? `Choose one with: passport use <name> (available: ${names.join(", ")}), or pass --profile <name>.`
|
|
152
|
+
: "Run: passport login --workspace <workspace-id>.";
|
|
95
153
|
return failure(`Passport profile "${profile}" does not exist.${suffix}`, 2, "auth", {
|
|
96
|
-
hint
|
|
154
|
+
hint,
|
|
155
|
+
...(names.length
|
|
156
|
+
? {
|
|
157
|
+
profiles: names,
|
|
158
|
+
next: [
|
|
159
|
+
{ argv: ["passport", "profiles"], description: "List saved profiles." },
|
|
160
|
+
...names.map((name) => ({
|
|
161
|
+
argv: ["passport", "use", name],
|
|
162
|
+
description: `Select the saved profile "${name}".`
|
|
163
|
+
}))
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
: {
|
|
167
|
+
requiredInput: ["workspace-id"]
|
|
168
|
+
})
|
|
97
169
|
});
|
|
98
170
|
}
|
|
99
171
|
return { kind: "profile", endpoint: endpoint(saved.endpoint), profile, refreshToken: saved.refreshToken };
|
package/dist/completion.js
CHANGED
|
@@ -2,8 +2,11 @@ import { COMMANDS } from "./cliArgs.js";
|
|
|
2
2
|
const DESCRIPTIONS = {
|
|
3
3
|
login: "Sign in with the device flow",
|
|
4
4
|
logout: "Revoke and remove a profile",
|
|
5
|
+
profiles: "List saved profiles and the active selection",
|
|
6
|
+
use: "Select a saved profile for subsequent commands",
|
|
5
7
|
status: "Show identity and MCP connection state",
|
|
6
8
|
doctor: "Diagnose local configuration and server compatibility",
|
|
9
|
+
ready: "Check whether this CLI is ready to use",
|
|
7
10
|
search: "Find permitted tools",
|
|
8
11
|
describe: "Show one exact tool definition",
|
|
9
12
|
run: "Run a governed tool",
|
|
@@ -18,7 +21,7 @@ const DESCRIPTIONS = {
|
|
|
18
21
|
};
|
|
19
22
|
const GLOBAL = ["--profile", "--json", "--timeout", "--quiet", "--caller", "--help"];
|
|
20
23
|
const COMMAND_FLAGS = {
|
|
21
|
-
login: ["--cloud", "--workspace", "--client"],
|
|
24
|
+
login: ["--cloud", "--workspace", "--client", "--no-open"],
|
|
22
25
|
search: ["--app"],
|
|
23
26
|
run: ["--args", "--set", "--set-json", "--wait"],
|
|
24
27
|
connect: ["--alias", "--open", "--wait"],
|