passport-bridge 0.50.0 → 0.52.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 +53 -146
- package/dist/cli.js +2 -3
- package/dist/cliArgs.d.ts +1 -7
- package/dist/cliArgs.js +17 -73
- package/dist/cliClient.d.ts +1 -6
- package/dist/cliClient.js +1 -16
- package/dist/cliConnect.d.ts +4 -21
- package/dist/cliConnect.js +14 -18
- package/dist/cliConnections.d.ts +5 -7
- package/dist/cliConnections.js +10 -21
- package/dist/cliGuardHealth.d.ts +3 -3
- package/dist/cliGuardHealth.js +4 -8
- package/dist/cliHook.d.ts +1 -4
- package/dist/cliHook.js +40 -43
- package/dist/cliHookAfter.d.ts +2 -25
- package/dist/cliHookAfter.js +9 -61
- package/dist/cliHookClassify.js +2 -2
- package/dist/cliHookDecide.d.ts +6 -1
- package/dist/cliHookDecide.js +25 -19
- package/dist/cliHookDeliver.d.ts +4 -7
- package/dist/cliHookDeliver.js +8 -7
- package/dist/cliHookGuard.d.ts +2 -3
- package/dist/cliHookGuard.js +2 -3
- package/dist/cliHookInstall.d.ts +1 -1
- package/dist/cliHookLinks.d.ts +2 -4
- package/dist/cliHookLinks.js +3 -22
- package/dist/cliHookParse.d.ts +16 -7
- package/dist/cliHookParse.js +140 -51
- package/dist/cliHookSessionState.d.ts +1 -2
- package/dist/cliHookSessionState.js +3 -7
- package/dist/cliInit.d.ts +1 -2
- package/dist/cliInit.js +5 -11
- package/dist/cliMain.js +21 -218
- package/dist/cliMemberCall.d.ts +1 -1
- package/dist/cliOutput.js +19 -48
- package/dist/cliResult.js +2 -6
- package/dist/cliSetupOrg.js +2 -4
- package/dist/cliStatus.d.ts +0 -3
- package/dist/cliStatus.js +5 -40
- package/dist/cliStatusLocal.d.ts +3 -13
- package/dist/cliStatusLocal.js +2 -11
- package/dist/cliSuggest.d.ts +1 -1
- package/dist/cliSuggest.js +2 -2
- package/dist/commandRepair.d.ts +1 -6
- package/dist/commandRepair.js +8 -31
- package/dist/completion.js +11 -50
- package/dist/connectPayload.d.ts +27 -0
- package/dist/connectPayload.js +18 -0
- package/dist/connectorKit/cli.generated.d.ts +2 -1
- package/dist/connectorKit/cli.generated.js +37 -7
- package/dist/connectorKit/launchers.generated.d.ts +34 -0
- package/dist/connectorKit/launchers.generated.js +194 -0
- package/dist/connectorKit/manifest.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/kubernetes.generated.js +5 -2
- package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +3 -2
- package/dist/connectorKit/manifests/kubernetesCli.generated.js +24 -3
- package/dist/connectorKit/manifests/kubernetesEffects.generated.js +9 -4
- package/dist/connectorKit/manifests/kubernetesObjects.generated.js +59 -11
- package/dist/connectorKit/manifests/sentryApi.generated.js +11 -9
- package/dist/connectorKit/manifests/sentryCapture.generated.js +2 -2
- package/dist/connectorKit/manifests/sentryCatalog.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.js +28 -2
- package/dist/connectorKit/manifests/sentryCli.generated.js +7 -6
- package/dist/connectorKit/manifests/sentryIssues.generated.d.ts +7 -2
- package/dist/connectorKit/manifests/sentryIssues.generated.js +39 -19
- package/dist/connectorKit/manifests/terraform.generated.js +20 -7
- package/dist/connectorKit/manifests/terraformPlan.generated.d.ts +2 -2
- package/dist/connectorKit/manifests/terraformPlan.generated.js +13 -3
- package/dist/connectorKit/shell.generated.d.ts +5 -3
- package/dist/connectorKit/shell.generated.js +58 -25
- package/dist/connectorKit/shellFed.generated.d.ts +30 -0
- package/dist/connectorKit/shellFed.generated.js +53 -0
- package/dist/{cliHookSpawn.js → connectorKit/spawns.generated.js} +1 -0
- package/dist/controlPlaneActions.generated.d.ts +7 -0
- package/dist/controlPlaneActions.generated.js +4 -0
- package/dist/controlPlaneAnswer.d.ts +1 -3
- package/dist/controlPlaneGuard.d.ts +5 -37
- package/dist/controlPlaneGuard.js +9 -46
- package/dist/controlPlaneIds.d.ts +8 -25
- package/dist/controlPlaneIds.js +10 -153
- package/dist/controlPlaneKubernetes.d.ts +3 -2
- package/dist/controlPlaneKubernetes.js +21 -3
- package/dist/controlPlaneLate.d.ts +9 -2
- package/dist/controlPlaneLate.js +37 -3
- package/dist/controlPlaneLateHold.d.ts +13 -7
- package/dist/controlPlaneLateHold.js +29 -10
- package/dist/controlPlaneNpm.generated.d.ts +3 -0
- package/dist/controlPlaneNpm.generated.js +13 -1
- package/dist/controlPlaneNpmGuard.js +7 -7
- package/dist/controlPlaneRailwayGuard.d.ts +20 -86
- package/dist/controlPlaneRailwayGuard.js +38 -231
- package/dist/controlPlaneRailwayReach.d.ts +0 -31
- package/dist/controlPlaneRailwayReach.js +5 -131
- package/dist/controlPlaneSupabase.d.ts +6 -21
- package/dist/controlPlaneSupabase.js +17 -51
- package/dist/controlPlaneTerraform.js +25 -11
- package/dist/controlPlaneUnnamed.generated.d.ts +1 -1
- package/dist/cpCli.d.ts +13 -2
- package/dist/cpCli.js +50 -5
- package/dist/execShims.d.ts +2 -72
- package/dist/execShims.js +24 -303
- package/dist/execVendors.d.ts +4 -59
- package/dist/execVendors.js +25 -332
- package/dist/gitDirs.d.ts +7 -0
- package/dist/gitDirs.js +54 -0
- package/dist/gitPush.d.ts +1 -3
- package/dist/gitPush.js +3 -11
- package/dist/gitRun.d.ts +6 -0
- package/dist/gitRun.js +18 -0
- package/dist/initAppsStep.d.ts +1 -1
- package/dist/initAppsStep.js +1 -1
- package/dist/initKeysStep.d.ts +5 -13
- package/dist/initKeysStep.js +23 -145
- package/dist/initOutro.d.ts +1 -4
- package/dist/initOutro.js +1 -28
- package/dist/initPlan.d.ts +0 -2
- package/dist/initPlan.js +4 -31
- package/dist/initState.d.ts +1 -2
- package/dist/keysHere.d.ts +4 -4
- package/dist/keysHere.js +3 -3
- package/dist/keysKept.d.ts +0 -3
- package/dist/keysKept.js +7 -20
- package/dist/keysLocal.d.ts +3 -70
- package/dist/keysLocal.js +19 -192
- package/dist/keysLocalGoogle.d.ts +0 -31
- package/dist/keysLocalGoogle.js +10 -109
- package/dist/keysReport.d.ts +2 -36
- package/dist/keysReport.js +31 -53
- package/dist/keysV1Cleanup.js +4 -1
- package/dist/launcherHealth.js +1 -2
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/psqlSupabase.d.ts +50 -0
- package/dist/psqlSupabase.js +391 -0
- package/dist/scanSignedIn.d.ts +0 -4
- package/dist/scanSignedIn.js +4 -6
- package/dist/statusKeys.d.ts +4 -1
- package/dist/statusKeys.js +6 -0
- package/dist/term.js +4 -6
- package/dist/terraformPlans.d.ts +3 -0
- package/dist/terraformPlans.js +3 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -10
- package/dist/accessClient.d.ts +0 -128
- package/dist/accessClient.js +0 -436
- package/dist/cliAccess.d.ts +0 -3
- package/dist/cliAccess.js +0 -119
- package/dist/cliExec.d.ts +0 -51
- package/dist/cliExec.js +0 -337
- package/dist/cliExecGuard.d.ts +0 -10
- package/dist/cliExecGuard.js +0 -36
- package/dist/cliGitCredential.d.ts +0 -41
- package/dist/cliGitCredential.js +0 -500
- package/dist/cliHookRedact.d.ts +0 -29
- package/dist/cliHookRedact.js +0 -196
- package/dist/cliHookRewrite.d.ts +0 -90
- package/dist/cliHookRewrite.js +0 -356
- package/dist/cliKeys.d.ts +0 -40
- package/dist/cliKeys.js +0 -606
- package/dist/cliKeysBack.d.ts +0 -55
- package/dist/cliKeysBack.js +0 -131
- package/dist/cliKeysKeep.d.ts +0 -34
- package/dist/cliKeysKeep.js +0 -111
- package/dist/cliKeysRotate.d.ts +0 -24
- package/dist/cliKeysRotate.js +0 -161
- package/dist/cliKeysShim.d.ts +0 -43
- package/dist/cliKeysShim.js +0 -121
- package/dist/cliKeysSignOut.d.ts +0 -33
- package/dist/cliKeysSignOut.js +0 -72
- package/dist/cliKeysTypes.d.ts +0 -74
- package/dist/cliKeysTypes.js +0 -1
- package/dist/cliKubeCredential.d.ts +0 -58
- package/dist/cliKubeCredential.js +0 -301
- package/dist/cliPagination.d.ts +0 -15
- package/dist/cliPagination.js +0 -55
- package/dist/cliReady.d.ts +0 -10
- package/dist/cliReady.js +0 -59
- package/dist/cliSession.d.ts +0 -20
- package/dist/cliSession.js +0 -163
- package/dist/controlPlaneExec.d.ts +0 -93
- package/dist/controlPlaneExec.js +0 -258
- package/dist/execAzure.d.ts +0 -79
- package/dist/execAzure.js +0 -280
- package/dist/execGit.d.ts +0 -20
- package/dist/execGit.js +0 -45
- package/dist/execGithubRepo.d.ts +0 -30
- package/dist/execGithubRepo.js +0 -191
- package/dist/execGoogle.d.ts +0 -17
- package/dist/execGoogle.js +0 -52
- package/dist/execLinks.d.ts +0 -63
- package/dist/execLinks.js +0 -120
- package/dist/execMarker.d.ts +0 -7
- package/dist/execMarker.js +0 -66
- package/dist/execMask.d.ts +0 -55
- package/dist/execMask.js +0 -189
- package/dist/execNoKey.d.ts +0 -9
- package/dist/execNoKey.js +0 -32
- package/dist/execSpawn.d.ts +0 -16
- package/dist/execSpawn.js +0 -47
- package/dist/execTarget.d.ts +0 -10
- package/dist/execTarget.js +0 -34
- package/dist/gitCredentialRetire.d.ts +0 -25
- package/dist/gitCredentialRetire.js +0 -143
- package/dist/gitCredentialSetup.d.ts +0 -94
- package/dist/gitCredentialSetup.js +0 -357
- package/dist/gitInvocation.d.ts +0 -41
- package/dist/gitInvocation.js +0 -207
- package/dist/gitPushDecisions.d.ts +0 -6
- package/dist/gitPushDecisions.js +0 -69
- package/dist/gitReadOnly.d.ts +0 -10
- package/dist/gitReadOnly.js +0 -57
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/keysAzure.d.ts +0 -14
- package/dist/keysAzure.js +0 -23
- package/dist/keysInV1.d.ts +0 -9
- package/dist/keysInV1.js +0 -48
- package/dist/keysKeychain.d.ts +0 -14
- package/dist/keysKeychain.js +0 -52
- package/dist/keysLocalEdit.d.ts +0 -13
- package/dist/keysLocalEdit.js +0 -153
- package/dist/keysSecret.d.ts +0 -6
- package/dist/keysSecret.js +0 -43
- package/dist/offInV1.d.ts +0 -26
- package/dist/offInV1.js +0 -28
- package/dist/railwayDecisions.d.ts +0 -12
- package/dist/railwayDecisions.js +0 -114
- package/dist/releaseTooling.d.ts +0 -7
- package/dist/releaseTooling.js +0 -29
- package/dist/supabaseDecisions.d.ts +0 -9
- package/dist/supabaseDecisions.js +0 -98
- /package/dist/{cliHookSpawn.d.ts → connectorKit/spawns.generated.d.ts} +0 -0
package/dist/cliClient.js
CHANGED
|
@@ -7,7 +7,6 @@ import { persistCurrentProfileRotation, recoverProfileRotation, withProfileLock
|
|
|
7
7
|
import { VERSION } from "./version.js";
|
|
8
8
|
import { AgentSignInError, SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
9
9
|
import { withCliDeadline } from "./cliDeadline.js";
|
|
10
|
-
import { collectCliPages } from "./cliPagination.js";
|
|
11
10
|
import { boundedMcpFetch } from "./boundedMcpFetch.js";
|
|
12
11
|
export { SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
13
12
|
const MIN_CLI_SERVER = [0, 5, 0];
|
|
@@ -109,7 +108,7 @@ function authedFetchFor(options) {
|
|
|
109
108
|
});
|
|
110
109
|
}
|
|
111
110
|
/** Same-origin REST calls without an MCP session, for commands that only
|
|
112
|
-
* need the member API (`passport
|
|
111
|
+
* need the member API (`passport update`, `passport connect`). */
|
|
113
112
|
export function memberApi(options) {
|
|
114
113
|
const origin = new URL(options.auth.endpoint).origin;
|
|
115
114
|
const authed = authedFetchFor(options);
|
|
@@ -194,20 +193,6 @@ export class CliGateway {
|
|
|
194
193
|
throw new Error("Passport API path must be relative.");
|
|
195
194
|
return this.apiFetch(`${this.origin}${path}`, init);
|
|
196
195
|
}
|
|
197
|
-
async listResources() {
|
|
198
|
-
const result = await collectCliPages("resource", (cursor) => this.client.listResources(cursor ? { cursor } : {}, this.requestOptions()), (page) => page.resources);
|
|
199
|
-
return { ...result.last, resources: result.items, nextCursor: undefined };
|
|
200
|
-
}
|
|
201
|
-
readResource(uri) {
|
|
202
|
-
return this.client.readResource({ uri }, this.requestOptions());
|
|
203
|
-
}
|
|
204
|
-
async listPrompts() {
|
|
205
|
-
const result = await collectCliPages("prompt", (cursor) => this.client.listPrompts(cursor ? { cursor } : {}, this.requestOptions()), (page) => page.prompts);
|
|
206
|
-
return { ...result.last, prompts: result.items, nextCursor: undefined };
|
|
207
|
-
}
|
|
208
|
-
getPrompt(name, args) {
|
|
209
|
-
return this.client.getPrompt({ name, arguments: args }, this.requestOptions());
|
|
210
|
-
}
|
|
211
196
|
async close() {
|
|
212
197
|
if (this.closed)
|
|
213
198
|
return;
|
package/dist/cliConnect.d.ts
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
-
import
|
|
2
|
+
import { managePayload, type GatewayRunner, type ManagePayload } from "./connectPayload.js";
|
|
3
|
+
export { managePayload, type GatewayRunner, type ManagePayload };
|
|
3
4
|
import { type CommandResult, type Runtime } from "./cliSupport.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
workspace: {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
10
|
-
/** Newer servers send the name and never the email; older ones send the email. */
|
|
11
|
-
member: {
|
|
12
|
-
id: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
email?: string;
|
|
15
|
-
};
|
|
16
|
-
client: string;
|
|
17
|
-
surface: string;
|
|
18
|
-
auth: string;
|
|
19
|
-
connections: Array<Record<string, unknown>>;
|
|
20
|
-
connectAllUrl?: string;
|
|
21
|
-
note?: string;
|
|
22
|
-
};
|
|
23
|
-
export declare function managePayload(result: ToolCall): ManagePayload;
|
|
5
|
+
/** `passport connect` with no app: a person's connections and their connections page (cliConnections.ts); an agent
|
|
6
|
+
* token, its connections. With apps (or `--alias`, `--open`, `--wait`): each app's sign-in link, and the wait. */
|
|
24
7
|
export declare function connect(args: ParsedArgs, runtime: Runtime, withGateway: GatewayRunner): Promise<CommandResult>;
|
package/dist/cliConnect.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import { bool, value } from "./cliArgs.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { firstText, requireSuccess } from "./cliResult.js";
|
|
3
|
+
import { managePayload } from "./connectPayload.js";
|
|
4
|
+
export { managePayload };
|
|
5
|
+
import { failure, openUrl, readBoundedJson, resolveCliAuth, sleep } from "./cliSupport.js";
|
|
5
6
|
import { countOf } from "./plural.js";
|
|
6
7
|
import { CONNECT_LINK_LIFETIME } from "./webLinks.js";
|
|
7
|
-
export function managePayload(result) {
|
|
8
|
-
requireSuccess(result);
|
|
9
|
-
const payload = payloadOf(result, "connection");
|
|
10
|
-
if (!payload.workspace ||
|
|
11
|
-
typeof payload.workspace !== "object" ||
|
|
12
|
-
!payload.member ||
|
|
13
|
-
typeof payload.member !== "object" ||
|
|
14
|
-
typeof payload.client !== "string" ||
|
|
15
|
-
payload.surface !== "cli" ||
|
|
16
|
-
typeof payload.auth !== "string" ||
|
|
17
|
-
!Array.isArray(payload.connections)) {
|
|
18
|
-
return failure(SERVER_TOO_OLD, 1, "server_too_old");
|
|
19
|
-
}
|
|
20
|
-
return payload;
|
|
21
|
-
}
|
|
22
8
|
/** The app a refusal says isn't offered to this person ("\"jira\" isn't offered to you at Northwind."). */
|
|
23
9
|
function notOfferedApp(error) {
|
|
24
10
|
if (!(error instanceof Error))
|
|
@@ -81,7 +67,17 @@ function assertConnectionCanStart(auth, needSignin, urls, human, shouldOpen, sho
|
|
|
81
67
|
});
|
|
82
68
|
}
|
|
83
69
|
}
|
|
70
|
+
/** Just `passport connect` (no app, `--alias`, `--open` or `--wait`), signed in as a person. */
|
|
71
|
+
function overview(args, runtime) {
|
|
72
|
+
if (args.positionals.length || value(args, "alias") !== undefined || bool(args, "open"))
|
|
73
|
+
return false;
|
|
74
|
+
return value(args, "wait") === undefined && resolveCliAuth(args, runtime.env).kind === "profile";
|
|
75
|
+
}
|
|
76
|
+
/** `passport connect` with no app: a person's connections and their connections page (cliConnections.ts); an agent
|
|
77
|
+
* token, its connections. With apps (or `--alias`, `--open`, `--wait`): each app's sign-in link, and the wait. */
|
|
84
78
|
export async function connect(args, runtime, withGateway) {
|
|
79
|
+
if (overview(args, runtime))
|
|
80
|
+
return (await import("./cliConnections.js")).connections(args, runtime, withGateway);
|
|
85
81
|
const alias = value(args, "alias");
|
|
86
82
|
if (alias !== undefined && !/^[A-Za-z0-9 -]{1,32}$/.test(alias.trim()))
|
|
87
83
|
return failure("--alias must contain 1-32 letters, numbers, spaces, or hyphens.", 6, "usage");
|
package/dist/cliConnections.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `passport
|
|
2
|
+
* `passport connect [--no-open]` with no app: the developer's own connections, in the terminal and
|
|
3
3
|
* in the browser. It prints what's connected for this person and what still needs them, then opens
|
|
4
4
|
* their connections page with a link that lasts fifteen minutes (`POST /api/my/connections-link`). The
|
|
5
5
|
* link never signs a browser in by itself: the page still needs the person's own sign-in.
|
|
6
|
-
*
|
|
7
|
-
* passport connections every app, and the page
|
|
8
|
-
* passport connections github the page with GitHub highlighted
|
|
6
|
+
* `passport connect <app…>` is cliConnect.ts.
|
|
9
7
|
*
|
|
10
8
|
* Agent hooks and the MCP point here when a connection is missing.
|
|
11
9
|
*/
|
|
12
10
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
13
|
-
import { type GatewayRunner } from "./
|
|
11
|
+
import { type GatewayRunner } from "./connectPayload.js";
|
|
14
12
|
import { type MemberCallDependencies } from "./cliMemberCall.js";
|
|
15
13
|
import { type CommandResult, type Runtime } from "./cliSupport.js";
|
|
16
14
|
import { type Term } from "./term.js";
|
|
17
|
-
/** One app as `passport
|
|
15
|
+
/** One app as `passport connect --json` reports it. */
|
|
18
16
|
export type ConnectionsRow = {
|
|
19
17
|
app: string;
|
|
20
18
|
name: string;
|
|
@@ -36,5 +34,5 @@ export type ConnectionsDependencies = MemberCallDependencies & {
|
|
|
36
34
|
open?: (url: string) => boolean;
|
|
37
35
|
term?: Term;
|
|
38
36
|
};
|
|
39
|
-
export declare function connectionsScreen(term: Term, view: ConnectionsJson,
|
|
37
|
+
export declare function connectionsScreen(term: Term, view: ConnectionsJson, linkNote: "opened" | "printed" | "none", now?: number): string;
|
|
40
38
|
export declare function connections(args: ParsedArgs, runtime: Runtime, withGateway: GatewayRunner, deps?: ConnectionsDependencies): Promise<CommandResult>;
|
package/dist/cliConnections.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `passport
|
|
2
|
+
* `passport connect [--no-open]` with no app: the developer's own connections, in the terminal and
|
|
3
3
|
* in the browser. It prints what's connected for this person and what still needs them, then opens
|
|
4
4
|
* their connections page with a link that lasts fifteen minutes (`POST /api/my/connections-link`). The
|
|
5
5
|
* link never signs a browser in by itself: the page still needs the person's own sign-in.
|
|
6
|
-
*
|
|
7
|
-
* passport connections every app, and the page
|
|
8
|
-
* passport connections github the page with GitHub highlighted
|
|
6
|
+
* `passport connect <app…>` is cliConnect.ts.
|
|
9
7
|
*
|
|
10
8
|
* Agent hooks and the MCP point here when a connection is missing.
|
|
11
9
|
*/
|
|
12
10
|
import { bool } from "./cliArgs.js";
|
|
13
|
-
import { managePayload } from "./
|
|
11
|
+
import { managePayload } from "./connectPayload.js";
|
|
14
12
|
import { api } from "./cliMemberCall.js";
|
|
15
13
|
import { failure, openUrl, readBoundedJson, resolveCliAuth, timeoutMs } from "./cliSupport.js";
|
|
16
14
|
import { countOf } from "./plural.js";
|
|
17
15
|
import { mark, table, termOf, wrap } from "./term.js";
|
|
18
|
-
const USAGE = "Use: passport connections [app] [--no-open]";
|
|
19
|
-
const APP_KEY = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
20
16
|
function rowsOf(connections) {
|
|
21
17
|
return connections.map((row) => ({
|
|
22
18
|
app: String(row.app ?? ""),
|
|
@@ -42,12 +38,12 @@ function said(row) {
|
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
const ORDER = { needs_your_signin: 0, connected: 1, org_managed: 2, needs_setup: 3 };
|
|
45
|
-
async function mintLink(args, runtime, deps
|
|
41
|
+
async function mintLink(args, runtime, deps) {
|
|
46
42
|
try {
|
|
47
43
|
const response = await api(args, runtime, deps).fetchApi("/api/my/connections-link", {
|
|
48
44
|
method: "POST",
|
|
49
45
|
headers: { "content-type": "application/json", accept: "application/json" },
|
|
50
|
-
body: JSON.stringify(
|
|
46
|
+
body: JSON.stringify({}),
|
|
51
47
|
signal: AbortSignal.any([runtime.signal, AbortSignal.timeout(timeoutMs(args))])
|
|
52
48
|
});
|
|
53
49
|
if (!response.ok) {
|
|
@@ -71,13 +67,11 @@ function linkLifetime(expiresAt, now) {
|
|
|
71
67
|
return undefined;
|
|
72
68
|
return countOf(Math.max(1, Math.round((expiresAt - now) / 60_000)), "minute");
|
|
73
69
|
}
|
|
74
|
-
export function connectionsScreen(term, view,
|
|
70
|
+
export function connectionsScreen(term, view, linkNote, now = Date.now()) {
|
|
75
71
|
const lines = [];
|
|
76
72
|
const width = term.width;
|
|
77
73
|
lines.push(...wrap(`Your connections in ${view.workspace}`, width));
|
|
78
|
-
const rows = [...view.apps].sort((a, b) =>
|
|
79
|
-
(ORDER[a.status] ?? 9) - (ORDER[b.status] ?? 9) ||
|
|
80
|
-
a.name.localeCompare(b.name));
|
|
74
|
+
const rows = [...view.apps].sort((a, b) => (ORDER[a.status] ?? 9) - (ORDER[b.status] ?? 9) || a.name.localeCompare(b.name));
|
|
81
75
|
if (!rows.length)
|
|
82
76
|
lines.push(" No apps yet. Your admin adds them.");
|
|
83
77
|
lines.push(...table(rows.map((row) => {
|
|
@@ -97,16 +91,11 @@ export function connectionsScreen(term, view, focus, linkNote, now = Date.now())
|
|
|
97
91
|
}
|
|
98
92
|
else if (!view.url) {
|
|
99
93
|
lines.push(...wrap("Couldn't make a link to your connections page. Connect from here instead:", width));
|
|
100
|
-
lines.push(
|
|
94
|
+
lines.push("Run: passport connect <app>");
|
|
101
95
|
}
|
|
102
96
|
return lines.join("\n");
|
|
103
97
|
}
|
|
104
98
|
export async function connections(args, runtime, withGateway, deps = {}) {
|
|
105
|
-
const [requested, extra] = args.positionals;
|
|
106
|
-
const focus = requested?.trim().toLowerCase();
|
|
107
|
-
if (extra !== undefined || (focus !== undefined && !APP_KEY.test(focus))) {
|
|
108
|
-
return failure("Name one app by its key, like github or linear.", 6, "usage", { hint: USAGE });
|
|
109
|
-
}
|
|
110
99
|
if (!deps.api && resolveCliAuth(args, runtime.env).kind !== "profile") {
|
|
111
100
|
return failure("Your connections page is a person's. Agent tokens have none.", 6, "member_profile_required", {
|
|
112
101
|
hint: "Run: passport login"
|
|
@@ -115,7 +104,7 @@ export async function connections(args, runtime, withGateway, deps = {}) {
|
|
|
115
104
|
const managed = await withGateway(args, runtime, async (gateway) => managePayload(await gateway.callTool("passport_manage_connections", { includeLinks: false })));
|
|
116
105
|
// An app that isn't granted still opens the page, which offers Request when the catalog has it.
|
|
117
106
|
const apps = rowsOf(managed.connections);
|
|
118
|
-
const link = await mintLink(args, runtime, deps
|
|
107
|
+
const link = await mintLink(args, runtime, deps);
|
|
119
108
|
const shouldOpen = Boolean(link) && !bool(args, "no-open") && !bool(args, "json");
|
|
120
109
|
const opened = shouldOpen ? (deps.open ?? openUrl)(link.url) : false;
|
|
121
110
|
const view = {
|
|
@@ -128,6 +117,6 @@ export async function connections(args, runtime, withGateway, deps = {}) {
|
|
|
128
117
|
const term = deps.term ?? termOf(runtime.stdout, runtime.env);
|
|
129
118
|
return {
|
|
130
119
|
json: view,
|
|
131
|
-
human: connectionsScreen(term, view,
|
|
120
|
+
human: connectionsScreen(term, view, link ? (opened ? "opened" : "printed") : "none")
|
|
132
121
|
};
|
|
133
122
|
}
|
package/dist/cliGuardHealth.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Home, and the bell show it. Self-reported, read-only, and counts and flags
|
|
5
5
|
* only: never a command, a path, or a setting's value.
|
|
6
6
|
*
|
|
7
|
-
* Sent from a guard run that has 300 ms of its budget left
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Sent from a guard run that has 300 ms of its budget left (through the hooks'
|
|
8
|
+
* flush) once a day, and every time from `passport init` (after the guard
|
|
9
|
+
* step).
|
|
10
10
|
*/
|
|
11
11
|
import { type CodexTrust } from "./cliCodexTrust.js";
|
|
12
12
|
import type { Env } from "./cliSupport.js";
|
package/dist/cliGuardHealth.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Home, and the bell show it. Self-reported, read-only, and counts and flags
|
|
5
5
|
* only: never a command, a path, or a setting's value.
|
|
6
6
|
*
|
|
7
|
-
* Sent from a guard run that has 300 ms of its budget left
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Sent from a guard run that has 300 ms of its budget left (through the hooks'
|
|
8
|
+
* flush) once a day, and every time from `passport init` (after the guard
|
|
9
|
+
* step).
|
|
10
10
|
*/
|
|
11
11
|
import { closeSync, constants, mkdirSync, openSync, readFileSync, statSync, utimesSync } from "node:fs";
|
|
12
12
|
import { join } from "node:path";
|
|
@@ -270,9 +270,5 @@ export async function guardHeartbeat(api, profile, env, signal, now = Date.now()
|
|
|
270
270
|
const due = claimGuardHeartbeat(profile, now);
|
|
271
271
|
if (!due && !(force && stampHeartbeat(profile, now)))
|
|
272
272
|
return null;
|
|
273
|
-
|
|
274
|
-
// Once a day too: has a key `passport keys move` removed come back?
|
|
275
|
-
if (due)
|
|
276
|
-
await (await import("./cliKeysBack.js")).checkKeysBack(api, signal, process.env, profile).catch(() => undefined);
|
|
277
|
-
return sent;
|
|
273
|
+
return sendGuardHealth(api, profile, env, signal);
|
|
278
274
|
}
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* - `passport hook guard` runs before a command. It decides only through the
|
|
5
5
|
* control plane (`cliHookDecide.ts`): a block refuses the command at once
|
|
6
6
|
* with Passport's own words. Anything Passport doesn't decide gets no answer,
|
|
7
|
-
* so the agent's own permission rules apply.
|
|
8
|
-
* rewrite to `passport exec` (Claude Code), where exec then decides.
|
|
7
|
+
* so the agent's own permission rules apply. It never answers allow.
|
|
9
8
|
* - `passport hook` (audit) runs after a command. It records the vendor
|
|
10
9
|
* commands the line ran (vendor, a coarse verb and a risk class), one
|
|
11
10
|
* Activity row per line. Everyday commands aren't classified or recorded.
|
|
@@ -37,8 +36,6 @@ export declare function safeVerb(raw: string | null): string;
|
|
|
37
36
|
export declare function detectRuntime(input: HookInput, env: Env, declared?: string): HookRuntime;
|
|
38
37
|
/** One row for a line that ran vendor commands; null for any other line. */
|
|
39
38
|
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string): CliHookReport | null;
|
|
40
|
-
/** `passport exec` records its own action, with its decision and credential. */
|
|
41
|
-
export declare function isPassportExec(command: string): boolean;
|
|
42
39
|
/** Calls that name the agent (`x-passport-caller`): its kind only. */
|
|
43
40
|
export declare function asCaller(api: ApiCall | null, client: GuardClient): ApiCall | null;
|
|
44
41
|
export declare function hook(args: ParsedArgs, runtime: Runtime, deps?: HookDependencies): Promise<CommandResult>;
|
package/dist/cliHook.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* - `passport hook guard` runs before a command. It decides only through the
|
|
5
5
|
* control plane (`cliHookDecide.ts`): a block refuses the command at once
|
|
6
6
|
* with Passport's own words. Anything Passport doesn't decide gets no answer,
|
|
7
|
-
* so the agent's own permission rules apply.
|
|
8
|
-
* rewrite to `passport exec` (Claude Code), where exec then decides.
|
|
7
|
+
* so the agent's own permission rules apply. It never answers allow.
|
|
9
8
|
* - `passport hook` (audit) runs after a command. It records the vendor
|
|
10
9
|
* commands the line ran (vendor, a coarse verb and a risk class), one
|
|
11
10
|
* Activity row per line. Everyday commands aren't classified or recorded.
|
|
@@ -23,12 +22,12 @@ import { localRefusal, planGuard } from "./cliHookDecide.js";
|
|
|
23
22
|
import { denyOutput } from "./cliHookGuard.js";
|
|
24
23
|
import { localIrreversibleVerbs } from "./localIrreversible.js";
|
|
25
24
|
import { permissionModeOf } from "./cliHookMode.js";
|
|
26
|
-
import { readInput, readRaw,
|
|
25
|
+
import { readInput, readRaw, subagentOf } from "./cliHookInput.js";
|
|
27
26
|
import { parsePayload, shellEvent, unreadableMessage } from "./hookAdapters.js";
|
|
28
27
|
export { shellEvent } from "./hookAdapters.js";
|
|
29
28
|
import { budgetSignal, HOOK_BUDGET_MS, HOOK_RUNTIMES, leftovers, localProfile, localSelection, agentKeyApi, profileApi, queueAfterCommand, reportSender, runFlush, startFlushIfDue } from "./cliHookDeliver.js";
|
|
30
29
|
export { HOOK_BUDGET_MS, HOOK_RUNTIMES } from "./cliHookDeliver.js";
|
|
31
|
-
import { readCpCli } from "./cpCli.js";
|
|
30
|
+
import { claimUpgradeRefresh, cpCliOutdated, readCpCli, refreshCpCli } from "./cpCli.js";
|
|
32
31
|
import { standDownForManaged } from "./managedHooks.js";
|
|
33
32
|
import { isCursorEvent, outcomeOfInput } from "./cliHookOutcome.js";
|
|
34
33
|
import { isGuardClient } from "./cliGuardHealth.js";
|
|
@@ -155,10 +154,6 @@ function hookEvent(input, phase, args, runtime) {
|
|
|
155
154
|
return null;
|
|
156
155
|
return managedElsewhere(input, args, runtime) ? null : event;
|
|
157
156
|
}
|
|
158
|
-
/** `passport exec` records its own action, with its decision and credential. */
|
|
159
|
-
export function isPassportExec(command) {
|
|
160
|
-
return /^\s*(?:\S*\/)?passport\s+exec\b|^\s*'[^']*'\s+'[^']*'\s+exec\b/.test(command);
|
|
161
|
-
}
|
|
162
157
|
async function runAudit(args, runtime, deps) {
|
|
163
158
|
if (runtime.env.PASSPORT_HOOK_DISABLED === "1")
|
|
164
159
|
return;
|
|
@@ -180,7 +175,8 @@ async function runAudit(args, runtime, deps) {
|
|
|
180
175
|
// It ran: a decision the guard couldn't wait for may still have been recorded as a block (controlPlaneLateHold).
|
|
181
176
|
if (profile) {
|
|
182
177
|
const [sessionId, toolUseId] = [sessionOfInput(input), text(input.tool_use_id, 128)];
|
|
183
|
-
|
|
178
|
+
const { exitCode } = outcomeOfInput(input);
|
|
179
|
+
await (await import("./controlPlaneLateHold.js")).releaseLate(profile, sessionId, toolUseId, now, exitCode);
|
|
184
180
|
// Ran while Passport couldn't be reached and no rules were known: Passport is told what it was.
|
|
185
181
|
await (await import("./controlPlaneOffline.js")).releaseOffline(profile, sessionId, toolUseId, now);
|
|
186
182
|
// A merge that didn't name its pull request: its number, from gh's output read here, goes to its decision. Only a
|
|
@@ -203,9 +199,6 @@ async function runAudit(args, runtime, deps) {
|
|
|
203
199
|
const facts = { input, profile, runtimeName, cursorImported: event.cursorImported, now };
|
|
204
200
|
const base = () => context(input, runtime.env, declared);
|
|
205
201
|
const { command } = event;
|
|
206
|
-
// `passport exec` records its own row; what it created or kept failing at still counts.
|
|
207
|
-
if (isPassportExec(command))
|
|
208
|
-
return void (await after.afterExec({ ...facts, command, args, runtime, deps, base }));
|
|
209
202
|
const findings = classifyLine(command, localMachine(workingFolder(input), runtime.env)).findings;
|
|
210
203
|
const built = buildReport(input, findings, runtime.env, declared);
|
|
211
204
|
// A sign-in that expired, what it created, a retry loop: the report, and what Claude Code reads.
|
|
@@ -346,43 +339,29 @@ async function guardLine(at) {
|
|
|
346
339
|
const { args, runtime, deps, input, event, machine, line, local, declared, client, budget } = at;
|
|
347
340
|
const clock = deps.now ?? Date.now;
|
|
348
341
|
const { profile, byDefault } = localSelection(args, runtime.env);
|
|
349
|
-
const cp = profile ? readCpCli(profile) : null;
|
|
350
342
|
const canReport = Boolean(profile) && !runtime.env.PASSPORT_AGENT_KEY && !runtime.env.PASSPORT_ENDPOINT;
|
|
351
343
|
const deadline = at.startedAt + HOOK_BUDGET_MS - PRINT_RESERVE_MS;
|
|
344
|
+
const cp = profile ? await currentCpCli(profile, canReport, { budget, deadline, clock, fetch: deps.fetch }) : null;
|
|
352
345
|
// An agent key asks with its own key: what it may run is decided like anyone's (cli:local's Always allow included).
|
|
353
346
|
const agentApi = agentKeyApi(runtime.env, deps.fetch ?? fetch);
|
|
354
347
|
// Every decision names the agent this hook runs in, so Passport records the action as that agent's.
|
|
355
348
|
const openApi = async () => asCaller(agentApi ?? (profile ? await profileApi(profile, budget, deps.fetch ?? fetch).catch(() => null) : null), client);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
:
|
|
371
|
-
|
|
372
|
-
canAsk: canReport || agentApi !== null,
|
|
373
|
-
cp,
|
|
374
|
-
...(profile ? { profile } : {}),
|
|
375
|
-
openApi,
|
|
376
|
-
report: context(input, runtime.env, declared),
|
|
377
|
-
command: event.command,
|
|
378
|
-
findings: line.findings,
|
|
379
|
-
local,
|
|
380
|
-
cwd: machine.cwd,
|
|
381
|
-
env: runtime.env,
|
|
382
|
-
budget,
|
|
383
|
-
deadline,
|
|
384
|
-
now: clock
|
|
385
|
-
});
|
|
349
|
+
const plan = await planGuard({
|
|
350
|
+
client,
|
|
351
|
+
canAsk: canReport || agentApi !== null,
|
|
352
|
+
cp,
|
|
353
|
+
...(profile ? { profile } : {}),
|
|
354
|
+
openApi,
|
|
355
|
+
report: context(input, runtime.env, declared),
|
|
356
|
+
command: event.command,
|
|
357
|
+
findings: line.findings,
|
|
358
|
+
local,
|
|
359
|
+
cwd: machine.cwd,
|
|
360
|
+
env: runtime.env,
|
|
361
|
+
budget,
|
|
362
|
+
deadline,
|
|
363
|
+
now: clock
|
|
364
|
+
});
|
|
386
365
|
if (plan.output)
|
|
387
366
|
runtime.stdout.write(`${JSON.stringify(plan.output)}\n`);
|
|
388
367
|
// Answered: nothing after this may refuse the line.
|
|
@@ -393,6 +372,24 @@ async function guardLine(at) {
|
|
|
393
372
|
/* Best effort. */
|
|
394
373
|
}
|
|
395
374
|
}
|
|
375
|
+
/** The most an outdated copy's refresh takes of the budget, so the decision keeps the rest. */
|
|
376
|
+
const UPGRADE_REFRESH_MS = 600;
|
|
377
|
+
/** This computer's copy of what Passport decides. One another CLI version fetched (an upgrade) is refreshed first,
|
|
378
|
+
* once per version, so a platform the new CLI knows is decided on its first command, not an hour later. */
|
|
379
|
+
async function currentCpCli(profile, canReport, at) {
|
|
380
|
+
const cp = readCpCli(profile);
|
|
381
|
+
if (!canReport || !cpCliOutdated(cp) || !claimUpgradeRefresh(profile, at.clock()))
|
|
382
|
+
return cp;
|
|
383
|
+
const left = Math.min(UPGRADE_REFRESH_MS, Math.floor((at.deadline - at.clock()) / 2));
|
|
384
|
+
if (left <= 0)
|
|
385
|
+
return cp;
|
|
386
|
+
const signal = AbortSignal.any([at.budget, AbortSignal.timeout(left)]);
|
|
387
|
+
const api = await profileApi(profile, signal, at.fetch ?? fetch).catch(() => null);
|
|
388
|
+
if (!api)
|
|
389
|
+
return cp;
|
|
390
|
+
const refreshed = await refreshCpCli(profile, signal, { api, now: at.clock });
|
|
391
|
+
return refreshed === "updated" ? (readCpCli(profile) ?? cp) : cp;
|
|
392
|
+
}
|
|
396
393
|
async function afterAnswer(at) {
|
|
397
394
|
const { args, runtime, deps, runtimeName, profile, byDefault, cp, plan, budget, clock, canReport } = at;
|
|
398
395
|
if (!profile || !canReport)
|
package/dist/cliHookAfter.d.ts
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* 4 KB of output, read locally and never sent);
|
|
8
8
|
* - what it created or removed that keeps running (`cliHookCreates.ts`);
|
|
9
9
|
* - how many times in a row the same command failed (`cliHookSessionState.ts`);
|
|
10
|
-
* - a `git push` GitHub refused because `passport git-credential` gave git a
|
|
11
|
-
* read-only token, not knowing it was a push (`gitReadOnly.ts`);
|
|
12
10
|
* - the non-default branch a `git push` that succeeded sent (`cliHookPushed.ts`),
|
|
13
11
|
* for the session's title, to any server (an older one refuses it and the
|
|
14
12
|
* report goes again without it);
|
|
@@ -18,17 +16,15 @@
|
|
|
18
16
|
* The report carries only the vendor, kinds, names, and counts. Claude Code
|
|
19
17
|
* hears about a sign-in or a retry loop in its own words, as `additionalContext`.
|
|
20
18
|
*/
|
|
21
|
-
import type { ParsedArgs } from "./cliArgs.js";
|
|
22
19
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
23
|
-
import type { CliHookReport,
|
|
20
|
+
import type { CliHookReport, HookRuntime } from "./cliHookDeliver.js";
|
|
24
21
|
import type { HookInput } from "./cliHookInput.js";
|
|
25
|
-
import type { Runtime } from "./cliSupport.js";
|
|
26
22
|
import { type ExecVendor } from "./execVendors.js";
|
|
27
23
|
import type { LinksMachine } from "./cliHookLinks.js";
|
|
28
24
|
/** The agent hears about a retry loop from this many failures in a row. */
|
|
29
25
|
export declare const RETRY_TELL_AT = 3;
|
|
30
26
|
/** What Claude Code reads when the sign-in expired. */
|
|
31
|
-
export declare function signInContext(vendor: ExecVendor
|
|
27
|
+
export declare function signInContext(vendor: ExecVendor): string;
|
|
32
28
|
/** What the agent reads when the same command keeps failing. */
|
|
33
29
|
export declare function retryContext(streak: number, program: string | undefined): string;
|
|
34
30
|
type AfterContext = {
|
|
@@ -42,8 +38,6 @@ type AfterContext = {
|
|
|
42
38
|
runtimeName: HookRuntime;
|
|
43
39
|
cursorImported: boolean;
|
|
44
40
|
now: number;
|
|
45
|
-
/** `passport exec` ran it with the key Passport holds: a sign-in here isn't the cause. */
|
|
46
|
-
exec?: true;
|
|
47
41
|
/** Where links are read from. Tests only; the computer's own files otherwise. */
|
|
48
42
|
linksMachine?: LinksMachine;
|
|
49
43
|
};
|
|
@@ -55,21 +49,4 @@ export declare function afterCommand(context: AfterContext): Promise<{
|
|
|
55
49
|
report: CliHookReport | null;
|
|
56
50
|
output: Record<string, unknown> | null;
|
|
57
51
|
}>;
|
|
58
|
-
/**
|
|
59
|
-
* `passport exec` records its own action, so the after-hook sends no row for
|
|
60
|
-
* it; what the command inside it created, removed, or kept failing at is
|
|
61
|
-
* still worth knowing. Queued like any report, never sent inline.
|
|
62
|
-
*/
|
|
63
|
-
export declare function afterExec(context: {
|
|
64
|
-
input: HookInput;
|
|
65
|
-
command: string;
|
|
66
|
-
args: ParsedArgs;
|
|
67
|
-
runtime: Runtime;
|
|
68
|
-
deps: HookDependencies;
|
|
69
|
-
base: () => Omit<CliHookReport, "findings" | "opaque">;
|
|
70
|
-
profile: string | undefined;
|
|
71
|
-
runtimeName: HookRuntime;
|
|
72
|
-
cursorImported: boolean;
|
|
73
|
-
now: number;
|
|
74
|
-
}): Promise<void>;
|
|
75
52
|
export {};
|
package/dist/cliHookAfter.js
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* 4 KB of output, read locally and never sent);
|
|
8
8
|
* - what it created or removed that keeps running (`cliHookCreates.ts`);
|
|
9
9
|
* - how many times in a row the same command failed (`cliHookSessionState.ts`);
|
|
10
|
-
* - a `git push` GitHub refused because `passport git-credential` gave git a
|
|
11
|
-
* read-only token, not knowing it was a push (`gitReadOnly.ts`);
|
|
12
10
|
* - the non-default branch a `git push` that succeeded sent (`cliHookPushed.ts`),
|
|
13
11
|
* for the session's title, to any server (an older one refuses it and the
|
|
14
12
|
* report goes again without it);
|
|
@@ -18,39 +16,21 @@
|
|
|
18
16
|
* The report carries only the vendor, kinds, names, and counts. Claude Code
|
|
19
17
|
* hears about a sign-in or a retry loop in its own words, as `additionalContext`.
|
|
20
18
|
*/
|
|
21
|
-
import {
|
|
22
|
-
import { execInner } from "./cliHookRewrite.js";
|
|
19
|
+
import { workingFolder } from "./hookLine.js";
|
|
23
20
|
import { nextRetry, readSessionState, writeSessionState } from "./cliHookSessionState.js";
|
|
24
|
-
import { EXEC_LOGIN_COMMAND, EXEC_VENDOR_NAMES
|
|
21
|
+
import { EXEC_LOGIN_COMMAND, EXEC_VENDOR_NAMES } from "./execVendors.js";
|
|
25
22
|
import { outcomeOfInput } from "./cliHookOutcome.js";
|
|
26
23
|
/** The agent hears about a retry loop from this many failures in a row. */
|
|
27
24
|
export const RETRY_TELL_AT = 3;
|
|
28
25
|
/** What Claude Code reads when the sign-in expired. */
|
|
29
|
-
export function signInContext(vendor
|
|
30
|
-
|
|
31
|
-
const command = vendorCommand(vendor);
|
|
32
|
-
if (held) {
|
|
33
|
-
return `Passport: the ${name} sign-in on this computer expired. Passport holds your ${name} key, so run it as \`passport exec -- ${command} <command>\`${rerouted ? " or just rerun it" : ""}.`;
|
|
34
|
-
}
|
|
35
|
-
return `Passport: the ${name} sign-in on this computer expired. Ask the user to run \`${EXEC_LOGIN_COMMAND[vendor]}\`, then retry.`;
|
|
26
|
+
export function signInContext(vendor) {
|
|
27
|
+
return `Passport: the ${EXEC_VENDOR_NAMES[vendor]} sign-in on this computer expired. Ask the user to run \`${EXEC_LOGIN_COMMAND[vendor]}\`, then retry.`;
|
|
36
28
|
}
|
|
37
29
|
/** What the agent reads when the same command keeps failing. */
|
|
38
30
|
export function retryContext(streak, program) {
|
|
39
31
|
const what = program ? `this ${program} command` : "this command";
|
|
40
32
|
return `Passport: ${what} failed ${streak} times in a row. Stop retrying and read the error, or ask for help.`;
|
|
41
33
|
}
|
|
42
|
-
/** Whether Passport holds a key for this vendor (this computer's list), and whether the guard sends the CLI
|
|
43
|
-
* through it. */
|
|
44
|
-
async function heldKey(profile, vendor) {
|
|
45
|
-
if (!profile)
|
|
46
|
-
return { held: false, rerouted: false };
|
|
47
|
-
const [{ readExecVendors }, { readKeysChoices }] = await Promise.all([
|
|
48
|
-
import("./execMarker.js"),
|
|
49
|
-
import("./keysKept.js")
|
|
50
|
-
]);
|
|
51
|
-
const marked = readExecVendors(profile).has(vendor);
|
|
52
|
-
return { held: marked, rerouted: marked && !readKeysChoices(profile).kept[vendor] };
|
|
53
|
-
}
|
|
54
34
|
/** A `terraform plan -out` that ran: its plan read now (counts and resource-type names only) and remembered for the
|
|
55
35
|
* session, so the apply that follows is decided on it at once (`terraformPlans.ts`). */
|
|
56
36
|
async function withTerraformPlans(context, state, failed) {
|
|
@@ -65,7 +45,7 @@ async function withTerraformPlans(context, state, failed) {
|
|
|
65
45
|
async function learn(context, state) {
|
|
66
46
|
const { exitCode } = outcomeOfInput(context.input);
|
|
67
47
|
const failed = exitCode !== undefined && exitCode !== 0;
|
|
68
|
-
const signIn = failed
|
|
48
|
+
const signIn = failed
|
|
69
49
|
? await import("./signInFailure.js").then(({ outputTail, signInFailureOf }) => signInFailureOf(context.findings, outputTail(context.input), exitCode))
|
|
70
50
|
: null;
|
|
71
51
|
const resources = failed || !context.findings.length
|
|
@@ -75,17 +55,13 @@ async function learn(context, state) {
|
|
|
75
55
|
const program = retry.state.retry?.program;
|
|
76
56
|
const pushes = context.findings.some((finding) => finding.vendor === "git" && finding.verb === "push");
|
|
77
57
|
const pushed = failed || !pushes ? undefined : (await import("./cliHookPushed.js")).pushedOf(context.findings);
|
|
78
|
-
const readOnly = failed && pushes
|
|
79
|
-
? await Promise.all([import("./gitReadOnly.js"), import("./signInFailure.js")]).then(([{ readOnlyPushContext }, { outputTail }]) => readOnlyPushContext(context.findings, outputTail(context.input), exitCode, context.now))
|
|
80
|
-
: null;
|
|
81
58
|
return {
|
|
82
59
|
learned: {
|
|
83
60
|
signIn,
|
|
84
61
|
resources,
|
|
85
62
|
streak: retry.streak,
|
|
86
63
|
...(program ? { program } : {}),
|
|
87
|
-
...(pushed ? { pushed } : {})
|
|
88
|
-
...(readOnly ? { readOnly } : {})
|
|
64
|
+
...(pushed ? { pushed } : {})
|
|
89
65
|
},
|
|
90
66
|
state: retry.state
|
|
91
67
|
};
|
|
@@ -114,12 +90,10 @@ function withFacts(context, learned) {
|
|
|
114
90
|
}
|
|
115
91
|
/** Links to what the command acted on, on its own row. */
|
|
116
92
|
async function withLinks(context, report) {
|
|
117
|
-
if (!report?.findings.length
|
|
93
|
+
if (!report?.findings.length)
|
|
118
94
|
return report;
|
|
119
|
-
// A `passport exec` part in the line sends its own command's links with its result.
|
|
120
|
-
const execPart = /\bpassport'?\s+'?exec\b/.test(context.command);
|
|
121
95
|
const { linksOf } = await import("./cliHookLinks.js");
|
|
122
|
-
const links = linksOf(context.findings, context.input, context.linksMachine
|
|
96
|
+
const links = linksOf(context.findings, context.input, context.linksMachine);
|
|
123
97
|
return links.length ? { ...report, links } : report;
|
|
124
98
|
}
|
|
125
99
|
/**
|
|
@@ -130,7 +104,6 @@ export async function afterCommand(context) {
|
|
|
130
104
|
const sessionId = context.report?.sessionId ?? context.base().sessionId;
|
|
131
105
|
const before = readSessionState(context.runtimeName, sessionId, context.now);
|
|
132
106
|
const { learned, state } = await learn(context, before);
|
|
133
|
-
const key = learned.signIn ? await heldKey(context.profile, learned.signIn) : { held: false, rerouted: false };
|
|
134
107
|
const claude = context.runtimeName === "claude-code" && !context.cursorImported;
|
|
135
108
|
if (JSON.stringify(state) !== JSON.stringify(before))
|
|
136
109
|
writeSessionState(context.runtimeName, sessionId, state);
|
|
@@ -138,8 +111,7 @@ export async function afterCommand(context) {
|
|
|
138
111
|
if (!claude)
|
|
139
112
|
return { report, output: null };
|
|
140
113
|
const lines = [
|
|
141
|
-
...(learned.
|
|
142
|
-
...(learned.signIn ? [signInContext(learned.signIn, key.held, key.rerouted && claude)] : []),
|
|
114
|
+
...(learned.signIn ? [signInContext(learned.signIn)] : []),
|
|
143
115
|
...(learned.streak >= RETRY_TELL_AT ? [retryContext(learned.streak, learned.program)] : [])
|
|
144
116
|
];
|
|
145
117
|
const event = typeof context.input.hook_event_name === "string" ? context.input.hook_event_name : "PostToolUse";
|
|
@@ -148,27 +120,3 @@ export async function afterCommand(context) {
|
|
|
148
120
|
output: lines.length ? { hookSpecificOutput: { hookEventName: event, additionalContext: lines.join("\n") } } : null
|
|
149
121
|
};
|
|
150
122
|
}
|
|
151
|
-
/**
|
|
152
|
-
* `passport exec` records its own action, so the after-hook sends no row for
|
|
153
|
-
* it; what the command inside it created, removed, or kept failing at is
|
|
154
|
-
* still worth knowing. Queued like any report, never sent inline.
|
|
155
|
-
*/
|
|
156
|
-
export async function afterExec(context) {
|
|
157
|
-
const inner = execInner(context.command);
|
|
158
|
-
if (!inner)
|
|
159
|
-
return;
|
|
160
|
-
const machine = localMachine(workingFolder(context.input), context.runtime.env);
|
|
161
|
-
const findings = classifyLine(inner, machine).findings;
|
|
162
|
-
const { report, output } = await afterCommand({ ...context, command: inner, findings, report: null, exec: true });
|
|
163
|
-
if (output)
|
|
164
|
-
context.runtime.stdout.write(`${JSON.stringify(output)}\n`);
|
|
165
|
-
if (!report)
|
|
166
|
-
return;
|
|
167
|
-
const deliver = await import("./cliHookDeliver.js");
|
|
168
|
-
if (!context.deps.send && !context.deps.fetch) {
|
|
169
|
-
await deliver.queueAfterCommand(report, context.args, context.runtime, context.runtimeName, context.now);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const send = await deliver.reportSender(context.args, context.runtime, deliver.budgetSignal(context.runtime, context.deps), context.deps);
|
|
173
|
-
await send?.(report).catch(() => undefined);
|
|
174
|
-
}
|