passport-bridge 0.48.0 → 0.48.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/dist/cliHook.js CHANGED
@@ -232,7 +232,9 @@ function refuseUnreadable(args, runtime) {
232
232
  runtime.stderr.write(`${unreadableMessage(client)}\n`);
233
233
  return 2;
234
234
  }
235
- async function runGuard(args, runtime, deps) {
235
+ /** Cursor has no "no decision" answer, and a fail-closed hook that prints nothing blocks the command. */
236
+ const CURSOR_NO_DECISION = { permission: "allow" };
237
+ async function runGuard(args, runtime, deps, seen = { cursor: false }) {
236
238
  if (runtime.env.PASSPORT_HOOK_DISABLED === "1")
237
239
  return undefined;
238
240
  const clock = deps.now ?? Date.now;
@@ -253,6 +255,7 @@ async function runGuard(args, runtime, deps) {
253
255
  const declared = value(args, "client");
254
256
  const runtimeName = detectRuntime(input, runtime.env, declared);
255
257
  const client = outputClient(event, runtimeName);
258
+ seen.cursor = client === "cursor";
256
259
  // A command that can't be undone runs only on Passport's allow: out of time or failing, it is refused.
257
260
  const local = localIrreversibleVerbs(event.command, machine);
258
261
  deps.budget?.read?.();
@@ -414,8 +417,23 @@ export async function hook(args, runtime, deps = {}) {
414
417
  }
415
418
  let exitCode;
416
419
  try {
417
- if (action === "guard")
418
- exitCode = await runGuard(args, runtime, deps);
420
+ if (action === "guard") {
421
+ // Cursor reads no output as a failure: when Passport has nothing to say, the guard says allow.
422
+ let wrote = false;
423
+ const seen = { cursor: false };
424
+ const watched = {
425
+ ...runtime,
426
+ stdout: {
427
+ write: (chunk) => {
428
+ wrote = true;
429
+ return runtime.stdout.write(chunk);
430
+ }
431
+ }
432
+ };
433
+ exitCode = await runGuard(args, watched, deps, seen);
434
+ if (seen.cursor && !wrote && !exitCode)
435
+ runtime.stdout.write(`${JSON.stringify(CURSOR_NO_DECISION)}\n`);
436
+ }
419
437
  else if (action === "flush")
420
438
  await runFlush(args, runtime, deps);
421
439
  else
@@ -0,0 +1,23 @@
1
+ import type { Effect } from "../controlPlaneActions.generated.js";
2
+ /**
3
+ * One GitHub call's effects from its arguments (docs/design/control-plane.md, "Action model", Layer 2 inputs): they
4
+ * replace the action's defaults for that call. Only what the arguments settle is decided here; anything unread keeps
5
+ * the defaults, which already assume the worst (a possible public audience, a possible later run). Reads names and
6
+ * flags only, never values beyond the few words that decide (visibility, role).
7
+ */
8
+ /** What a call's arguments say, from whichever interface sent it. `flags` are gh's (`--public`), `fields` a body's. */
9
+ export type CallArgs = {
10
+ fields?: Record<string, unknown>;
11
+ flags?: readonly string[];
12
+ };
13
+ /** What decide reads from a call beyond its effects: the deployment environment it names, for production. */
14
+ export type CallFacts = {
15
+ effects?: Effect[];
16
+ environment?: string;
17
+ /** Grants admin or owner: it reaches everything beneath where it is granted, so it counts as production. */
18
+ elevated?: true;
19
+ };
20
+ /** gh's words as call arguments: its flags by name, and `-f`/`-F` fields (`gh api`) with true and false read. */
21
+ export declare function ghCallArgs(argv: readonly string[]): CallArgs;
22
+ /** This call's facts; `effects` absent when its arguments change nothing about the defaults. */
23
+ export declare function githubCallFacts(actionKey: string, args: CallArgs, bodyRead: boolean): CallFacts;
@@ -0,0 +1,99 @@
1
+ import { GITHUB_EFFECTS } from "./manifests/githubActionList.generated.js";
2
+ /** New repositories: public unless the call says private or internal (the REST default is `private: false`). */
3
+ const CREATES_REPO = new Set([
4
+ "github.repos.create_for_authenticated_user",
5
+ "github.repos.create_in_org",
6
+ "github.repos.create_using_template",
7
+ "github.codespaces.publish_for_authenticated_user"
8
+ ]);
9
+ /** Updates that can't make a repository public when the body is read: a public one is `github.repo.public`. */
10
+ const UPDATES_REPO = new Set(["github.repos.update"]);
11
+ /** Grants that hand someone a role: admin or owner is the most access GitHub gives. */
12
+ const GRANTS_ROLE = new Set([
13
+ "github.org.invite",
14
+ "github.org.owner",
15
+ "github.repo.collaborator",
16
+ "github.team.member",
17
+ "github.team.repo",
18
+ "github.orgs.update_membership_for_authenticated_user"
19
+ ]);
20
+ const ELEVATED = new Set(["admin", "owner", "maintain"]);
21
+ /** Calls that name a deployment environment, read for production. */
22
+ const NAMES_ENVIRONMENT = new Set(["github.repos.create_deployment", "github.repos.create_or_update_environment"]);
23
+ const text = (value) => (typeof value === "string" ? value.trim().toLowerCase() : undefined);
24
+ const hasFlag = (args, ...names) => names.some((name) => args.flags?.includes(name));
25
+ /** Whether a new repository or gist is public: true, false, or unknown when nothing says. */
26
+ function publicOf(args) {
27
+ const fields = args.fields ?? {};
28
+ const visibility = text(fields.visibility);
29
+ if (visibility === "public" || fields.private === false || fields.public === true)
30
+ return true;
31
+ if (visibility === "private" || visibility === "internal" || fields.private === true)
32
+ return false;
33
+ if (hasFlag(args, "--public", "-p"))
34
+ return true;
35
+ if (hasFlag(args, "--private", "--internal"))
36
+ return false;
37
+ return undefined;
38
+ }
39
+ /** The defaults with their possible public audience settled one way or the other. */
40
+ function settleAudience(defaults, isPublic) {
41
+ return defaults.map((effect) => {
42
+ if (!effect.audience || !effect.possible)
43
+ return effect;
44
+ const { audience: _audience, possible: _possible, ...rest } = effect;
45
+ return isPublic ? { ...rest, audience: "public" } : rest;
46
+ });
47
+ }
48
+ /** gh's words as call arguments: its flags by name, and `-f`/`-F` fields (`gh api`) with true and false read. */
49
+ export function ghCallArgs(argv) {
50
+ const flags = [];
51
+ const fields = {};
52
+ for (let index = 0; index < argv.length; index++) {
53
+ const word = argv[index];
54
+ if (!word.startsWith("-"))
55
+ continue;
56
+ const name = word.split("=", 1)[0];
57
+ flags.push(name);
58
+ if (["-f", "-F", "--field", "--raw-field"].includes(name)) {
59
+ const pair = word.includes("=") && name.startsWith("--") ? word.slice(name.length + 1) : argv[++index];
60
+ const at = pair?.indexOf("=") ?? -1;
61
+ if (pair && at > 0) {
62
+ const value = pair.slice(at + 1);
63
+ fields[pair.slice(0, at)] = value === "true" ? true : value === "false" ? false : value;
64
+ }
65
+ }
66
+ }
67
+ return { flags, fields };
68
+ }
69
+ /** This call's facts; `effects` absent when its arguments change nothing about the defaults. */
70
+ export function githubCallFacts(actionKey, args, bodyRead) {
71
+ const defaults = GITHUB_EFFECTS.get(actionKey) ?? [];
72
+ const facts = {};
73
+ const environment = NAMES_ENVIRONMENT.has(actionKey) ? text(args.fields?.environment) : undefined;
74
+ if (environment)
75
+ facts.environment = environment;
76
+ if (CREATES_REPO.has(actionKey)) {
77
+ // gh asks for a visibility; the REST and MCP default is public.
78
+ const isPublic = publicOf(args) ?? (bodyRead && !args.flags ? true : undefined);
79
+ if (isPublic !== undefined)
80
+ facts.effects = settleAudience(defaults, isPublic);
81
+ }
82
+ else if (UPDATES_REPO.has(actionKey) && bodyRead) {
83
+ facts.effects = settleAudience(defaults, publicOf(args) === true);
84
+ }
85
+ else if (actionKey === "github.gists.create" && publicOf(args) === true) {
86
+ facts.effects = [{ verb: "create", object: "code", audience: "public" }];
87
+ }
88
+ else if (GRANTS_ROLE.has(actionKey)) {
89
+ const role = text(args.fields?.role) ?? text(args.fields?.permission);
90
+ // Admin or owner reaches everything beneath where it is granted: a change of access, decided as production.
91
+ if (role && ELEVATED.has(role)) {
92
+ facts.elevated = true;
93
+ if (!defaults.some((effect) => effect.object === "access")) {
94
+ facts.effects = [...defaults, { verb: "create", object: "access" }];
95
+ }
96
+ }
97
+ }
98
+ return facts;
99
+ }
@@ -15,6 +15,7 @@ import { httpLineOf, urlParts } from "./http.generated.js";
15
15
  import { GITHUB } from "./manifests/github.generated.js";
16
16
  import { githubHooks, worstCasePush as kitWorstCase } from "./manifests/githubHooks.generated.js";
17
17
  import { GH_COMMANDS } from "./manifests/githubReads.generated.js";
18
+ import { ghCallArgs, githubCallFacts } from "./githubCallEffects.generated.js";
18
19
  /** Without branches the hooks hold nothing per call: built once. */
19
20
  let exactHooks;
20
21
  function asKit(request, org) {
@@ -63,7 +64,20 @@ export function classifyGithubAll(request, context) {
63
64
  }
64
65
  const kit = asKit(request, context?.org);
65
66
  const found = classify(GITHUB, kit.request, kit.context, hooks);
66
- return (found === null ? [] : Array.isArray(found) ? found : [found]).map(asGithub);
67
+ const list = (found === null ? [] : Array.isArray(found) ? found : [found]).map(asGithub);
68
+ const args = request.interface === "mcp"
69
+ ? { fields: request.args }
70
+ : request.interface === "api"
71
+ ? request.body
72
+ ? { fields: request.body }
73
+ : {}
74
+ : ghCallArgs(request.argv);
75
+ // MCP and API bodies are read whole; a gh command line is read by its flags and `-f` fields.
76
+ return list.map((entry) => withFacts(entry, args, request.interface !== "api" || Boolean(request.body)));
77
+ }
78
+ /** A classification with what its call's arguments say (effects, environment, an elevated grant). */
79
+ function withFacts(found, args, bodyRead) {
80
+ return { ...found, ...githubCallFacts(found.actionKey, args, bodyRead) };
67
81
  }
68
82
  /* ------------------------------------------------------------------ */
69
83
  /* Raw HTTP to GitHub's API (Phase 3): curl, wget, httpie */
@@ -134,8 +148,10 @@ function githubHttp(line, argv, enterprise, hooks) {
134
148
  ...(line.opaque ? { body: { force: true } } : line.body ? { body: line.body } : {})
135
149
  }, {}, hooks);
136
150
  const list = (found === null ? [] : [found].flat()).map(asGithub);
151
+ const args = !line.opaque && line.body ? { fields: line.body } : {};
152
+ const decided = list.map((entry) => withFacts(entry, args, Boolean(args.fields)));
137
153
  // A body that can't be read names no exact target.
138
- return line.opaque ? list.map(({ target: _target, ...rest }) => rest) : list;
154
+ return line.opaque ? decided.map(({ target: _target, ...rest }) => rest) : decided;
139
155
  }
140
156
  const PUSH_ORDER = ["github.branch.delete", "github.branch.force", "github.repo.tag", "github.branch.push"];
141
157
  /** A push's order: a delete, then a force-push, a tag, a push (anything else ranks before them). */
@@ -1,4 +1,5 @@
1
1
  /** GitHub node ids, branch matching, and the builders the webhook mapping writes summaries with (`manifests/githubEvents.ts`). Requests are classified by the kit (`githubDecide.ts`). */
2
+ import type { Effect } from "../controlPlaneActions.generated.js";
2
3
  import type { UnnamedHit } from "../controlPlaneUnnamed.generated.js";
3
4
  export declare const lower: (value: string) => string;
4
5
  export declare const githubNodeIds: {
@@ -67,6 +68,12 @@ export type GithubClassification = {
67
68
  target?: string;
68
69
  /** On `github.unclassified`: the endpoint or command it hit, coarse (`controlPlaneUnnamed.ts`). */
69
70
  unnamed?: UnnamedHit;
71
+ /** This call's effects from its arguments (`githubCallEffects.ts`); absent: the action's defaults. */
72
+ effects?: Effect[];
73
+ /** The deployment environment it names ("production"), for production. */
74
+ environment?: string;
75
+ /** It grants admin or owner, so it counts as production wherever it lands. */
76
+ elevated?: true;
70
77
  };
71
78
  export type GithubRepo = {
72
79
  owner: string;
@@ -1,4 +1,5 @@
1
1
  import type { ActionDef } from "../../controlPlane.generated.js";
2
+ import type { Effect } from "../../controlPlaneActions.generated.js";
2
3
  /**
3
4
  * GitHub's generated action list (`sources/github/actions.json`, docs/design/v23/github-kit.md, Phase 2), as data
4
5
  * only: the server catalog and the web app read it without loading the routes or the classifier.
@@ -12,16 +13,22 @@ export type GithubActionsFile = {
12
13
  kind: string;
13
14
  label: string;
14
15
  on: string;
16
+ /** Default effects (`githubEffects.ts`): `kindOf(effects)` is the kind. */
17
+ effects: Effect[];
15
18
  hand?: true;
16
19
  common?: true;
17
20
  }>;
18
21
  /** Every common action's key, in the review table's order. */
19
22
  common: string[];
23
+ /** The default effects of hand-written actions no source route takes (force-push, a tag push). */
24
+ handEffects: Record<string, Effect[]>;
20
25
  /** Keys the review table renamed, old to new (the server treats the old one as a removed action). */
21
26
  renamed: Record<string, string>;
22
27
  };
23
28
  /** Every action GitHub's sources name, the hand-written ones (`hand`) included. */
24
29
  export declare const GITHUB_ACTION_LIST: GithubActionsFile["actions"];
30
+ /** Every action's default effects, by key (the hand-written ones included). */
31
+ export declare const GITHUB_EFFECTS: ReadonlyMap<string, readonly Effect[]>;
25
32
  /** The actions the rules picker shows first (why each is common: `manifests/github/review.json`). */
26
33
  export declare const GITHUB_COMMON_KEYS: ReadonlySet<string>;
27
34
  /** Generated keys renamed in the review table, old to new: events and rules on the old key follow the new one. */
@@ -2,6 +2,11 @@ import LIST from "../sources/github/actions.generated.js";
2
2
  const FILE = LIST;
3
3
  /** Every action GitHub's sources name, the hand-written ones (`hand`) included. */
4
4
  export const GITHUB_ACTION_LIST = FILE.actions;
5
+ /** Every action's default effects, by key (the hand-written ones included). */
6
+ export const GITHUB_EFFECTS = new Map([
7
+ ...FILE.actions.map((action) => [action.key, action.effects]),
8
+ ...Object.entries(FILE.handEffects ?? {})
9
+ ]);
5
10
  /** The actions the rules picker shows first (why each is common: `manifests/github/review.json`). */
6
11
  export const GITHUB_COMMON_KEYS = new Set(FILE.common);
7
12
  /** Generated keys renamed in the review table, old to new: events and rules on the old key follow the new one. */
@@ -17,6 +22,7 @@ export const GITHUB_GENERATED_DEFS = FILE.actions
17
22
  kind: action.kind,
18
23
  appliesTo: action.on,
19
24
  label: action.label,
25
+ effects: action.effects,
20
26
  ...(PARENT[action.on] ? { parent: PARENT[action.on] } : {}),
21
27
  ...(action.common ? { common: true } : {})
22
28
  }));
@@ -4,6 +4,11 @@ declare const _default: {
4
4
  key: string;
5
5
  kind: string;
6
6
  label: string;
7
+ effects: {
8
+ verb: string;
9
+ object: string;
10
+ restorable: boolean;
11
+ }[];
7
12
  on: string;
8
13
  common?: undefined;
9
14
  hand?: undefined;
@@ -11,6 +16,31 @@ declare const _default: {
11
16
  key: string;
12
17
  kind: string;
13
18
  label: string;
19
+ effects: ({
20
+ verb: string;
21
+ object: string;
22
+ disrupts?: undefined;
23
+ } | {
24
+ verb: string;
25
+ object: string;
26
+ disrupts: boolean;
27
+ })[];
28
+ on: string;
29
+ common?: undefined;
30
+ hand?: undefined;
31
+ } | {
32
+ key: string;
33
+ kind: string;
34
+ label: string;
35
+ effects: ({
36
+ verb: string;
37
+ object: string;
38
+ disrupts?: undefined;
39
+ } | {
40
+ verb: string;
41
+ object: string;
42
+ disrupts: boolean;
43
+ })[];
14
44
  on: string;
15
45
  common: boolean;
16
46
  hand?: undefined;
@@ -18,6 +48,33 @@ declare const _default: {
18
48
  key: string;
19
49
  kind: string;
20
50
  label: string;
51
+ effects: ({
52
+ verb: string;
53
+ object: string;
54
+ audience?: undefined;
55
+ when?: undefined;
56
+ } | {
57
+ verb: string;
58
+ object: string;
59
+ audience: string;
60
+ when: string;
61
+ })[];
62
+ on: string;
63
+ common?: undefined;
64
+ hand?: undefined;
65
+ } | {
66
+ key: string;
67
+ kind: string;
68
+ label: string;
69
+ effects: ({
70
+ verb: string;
71
+ object: string;
72
+ disrupts?: undefined;
73
+ } | {
74
+ verb: string;
75
+ object: string;
76
+ disrupts: boolean;
77
+ })[];
21
78
  on: string;
22
79
  hand: boolean;
23
80
  common: boolean;
@@ -25,11 +82,225 @@ declare const _default: {
25
82
  key: string;
26
83
  kind: string;
27
84
  label: string;
85
+ effects: ({
86
+ verb: string;
87
+ object: string;
88
+ when?: undefined;
89
+ possible?: undefined;
90
+ } | {
91
+ verb: string;
92
+ object: string;
93
+ when: string;
94
+ possible: boolean;
95
+ })[];
28
96
  on: string;
29
97
  hand: boolean;
98
+ common: boolean;
99
+ } | {
100
+ key: string;
101
+ kind: string;
102
+ label: string;
103
+ effects: ({
104
+ verb: string;
105
+ object: string;
106
+ when?: undefined;
107
+ possible?: undefined;
108
+ } | {
109
+ verb: string;
110
+ object: string;
111
+ when: string;
112
+ possible: boolean;
113
+ })[];
114
+ on: string;
30
115
  common?: undefined;
116
+ hand?: undefined;
117
+ } | {
118
+ key: string;
119
+ kind: string;
120
+ label: string;
121
+ effects: ({
122
+ verb: string;
123
+ object: string;
124
+ when?: undefined;
125
+ possible?: undefined;
126
+ } | {
127
+ verb: string;
128
+ object: string;
129
+ when: string;
130
+ possible: boolean;
131
+ })[];
132
+ on: string;
133
+ common: boolean;
134
+ hand?: undefined;
135
+ } | {
136
+ key: string;
137
+ kind: string;
138
+ label: string;
139
+ effects: ({
140
+ verb: string;
141
+ object: string;
142
+ audience?: undefined;
143
+ } | {
144
+ verb: string;
145
+ object: string;
146
+ audience: string;
147
+ })[];
148
+ on: string;
149
+ common?: undefined;
150
+ hand?: undefined;
151
+ } | {
152
+ key: string;
153
+ kind: string;
154
+ label: string;
155
+ effects: {
156
+ verb: string;
157
+ object: string;
158
+ }[];
159
+ on: string;
160
+ hand: boolean;
161
+ common?: undefined;
162
+ } | {
163
+ key: string;
164
+ kind: string;
165
+ label: string;
166
+ effects: ({
167
+ verb: string;
168
+ object: string;
169
+ audience?: undefined;
170
+ } | {
171
+ verb: string;
172
+ object: string;
173
+ audience: string;
174
+ })[];
175
+ on: string;
176
+ hand: boolean;
177
+ common: boolean;
178
+ } | {
179
+ key: string;
180
+ kind: string;
181
+ label: string;
182
+ effects: ({
183
+ verb: string;
184
+ object: string;
185
+ audience?: undefined;
186
+ when?: undefined;
187
+ } | {
188
+ verb: string;
189
+ object: string;
190
+ audience: string;
191
+ when: string;
192
+ })[];
193
+ on: string;
194
+ common: boolean;
195
+ hand?: undefined;
196
+ } | {
197
+ key: string;
198
+ kind: string;
199
+ label: string;
200
+ effects: ({
201
+ verb: string;
202
+ object: string;
203
+ possible?: undefined;
204
+ disrupts?: undefined;
205
+ } | {
206
+ verb: string;
207
+ object: string;
208
+ possible: boolean;
209
+ disrupts?: undefined;
210
+ } | {
211
+ verb: string;
212
+ object: string;
213
+ disrupts: boolean;
214
+ possible: boolean;
215
+ })[];
216
+ on: string;
217
+ common?: undefined;
218
+ hand?: undefined;
219
+ } | {
220
+ key: string;
221
+ kind: string;
222
+ label: string;
223
+ effects: ({
224
+ verb: string;
225
+ object: string;
226
+ audience?: undefined;
227
+ possible?: undefined;
228
+ } | {
229
+ verb: string;
230
+ object: string;
231
+ audience: string;
232
+ possible: boolean;
233
+ })[];
234
+ on: string;
235
+ common?: undefined;
236
+ hand?: undefined;
237
+ } | {
238
+ key: string;
239
+ kind: string;
240
+ label: string;
241
+ effects: ({
242
+ verb: string;
243
+ object: string;
244
+ audience?: undefined;
245
+ possible?: undefined;
246
+ } | {
247
+ verb: string;
248
+ object: string;
249
+ audience: string;
250
+ possible: boolean;
251
+ })[];
252
+ on: string;
253
+ common: boolean;
254
+ hand?: undefined;
31
255
  })[];
32
256
  common: string[];
257
+ handEffects: {
258
+ "github.repo.tag": ({
259
+ verb: string;
260
+ object: string;
261
+ when?: undefined;
262
+ possible?: undefined;
263
+ } | {
264
+ verb: string;
265
+ object: string;
266
+ when: string;
267
+ possible: boolean;
268
+ })[];
269
+ "github.repo.public": {
270
+ verb: string;
271
+ object: string;
272
+ audience: string;
273
+ }[];
274
+ "github.repo.change": {
275
+ verb: string;
276
+ object: string;
277
+ }[];
278
+ "github.unclassified": {
279
+ verb: string;
280
+ object: string;
281
+ possible: boolean;
282
+ disrupts: boolean;
283
+ }[];
284
+ "github.branch.force": ({
285
+ verb: string;
286
+ object: string;
287
+ when?: undefined;
288
+ possible?: undefined;
289
+ } | {
290
+ verb: string;
291
+ object: string;
292
+ when: string;
293
+ possible: boolean;
294
+ })[];
295
+ "github.org.owner": {
296
+ verb: string;
297
+ object: string;
298
+ }[];
299
+ "github.org.change": {
300
+ verb: string;
301
+ object: string;
302
+ }[];
303
+ };
33
304
  renamed: {};
34
305
  };
35
306
  export default _default;