passport-bridge 0.51.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.
@@ -5,7 +5,7 @@
5
5
  * framework does, positional arguments as $1..$n. Anything the vendor's spec
6
6
  * wouldn't accept is a `problem`: the request fails closed.
7
7
  */
8
- import { launcherEnd } from "./launchers.generated.js";
8
+ import { launcherEnd, neverLaunches } from "./launchers.generated.js";
9
9
  const COBRA_TRUE = new Set(["1", "t", "T", "true", "TRUE", "True"]);
10
10
  const COBRA_FALSE = new Set(["0", "f", "F", "false", "FALSE", "False"]);
11
11
  const tables = new WeakMap();
@@ -194,6 +194,30 @@ function findOp(m, words) {
194
194
  const defaulted = cli.defaultCommand !== undefined && (named.length === 0 || !topWords.has(named[0]));
195
195
  return { op: defaulted ? cli.defaultCommand : undefined, defaulted };
196
196
  }
197
+ /**
198
+ * Whether a program we don't know (`words[0]`) may be running the CLI: the CLI's name is one of its words and a
199
+ * command the CLI knows follows it (`foo supabase db reset`). A name with no command after it is an argument
200
+ * (`foo supabase .`, `npm i supabase`), and so is any name a program that never runs another one is given
201
+ * (`ls supabase`, `grep -rn railway .`, `git grep terraform`). A CLI that runs a default command with no command
202
+ * word counts any name followed by words.
203
+ */
204
+ function launchedBehind(m, words, programs) {
205
+ if (!words.length || neverLaunches(programName(words[0]), words.slice(1)))
206
+ return false;
207
+ const cli = m.capture.cli;
208
+ const { topWords, anyFlags } = tablesOf(m);
209
+ for (let i = 1; i < words.length; i++) {
210
+ if (!programs.includes(programName(words[i])))
211
+ continue;
212
+ const after = words.slice(i + 1);
213
+ if (cli.defaultCommand !== undefined)
214
+ return true;
215
+ const named = canonicalWords(parseArgs(after, anyFlags, false, cli.framework).positional, cli.aliases ?? {});
216
+ if (named.length && topWords.has(named[0]))
217
+ return true;
218
+ }
219
+ return false;
220
+ }
197
221
  /** More arguments than the vendor's usage line allows means something we can't read rides along. */
198
222
  function tooManyArgs(usage, count) {
199
223
  if (usage === undefined || usage.includes("..."))
@@ -205,12 +229,13 @@ export function normalizeCli(m, argv, given) {
205
229
  const programs = [...cli.programs, ...(cli.aliasPrograms ?? [])];
206
230
  const words = [...argv];
207
231
  stripLaunchers(words, programs);
208
- if (!programs.includes(programName(words.shift() ?? ""))) {
209
- // A known program anywhere in the line, behind a launcher we don't know: never call it a read.
210
- if (argv.some((word) => programs.includes(programName(word))))
232
+ if (!programs.includes(programName(words[0] ?? ""))) {
233
+ // The CLI run by a program we don't know: never call it a read.
234
+ if (launchedBehind(m, words, programs))
211
235
  return { iface: "cli", op: "", params: {}, local: false, remote: false, problem: "unrecognised launcher" };
212
236
  return null;
213
237
  }
238
+ words.shift();
214
239
  const { op, defaulted } = findOp(m, words);
215
240
  const own = op ? (cli.flags.commands[op] ?? []) : [];
216
241
  // Deprecated target flags (--linked, --local, --db-url) still work only where the command takes a target.
@@ -28,3 +28,7 @@ export type Unwrapped = {
28
28
  export declare function launcherEnd(words: readonly string[], at: number): number | null;
29
29
  /** See through leading assignments and launchers to the command they run. */
30
30
  export declare function unwrapLaunchers(words: readonly string[]): Unwrapped;
31
+ /** Whether `head` (a program name) given `args` only reads or edits files and runs no other program. */
32
+ export declare function neverLaunches(head: string, args: readonly string[]): boolean;
33
+ /** Where the command `xargs` runs starts in its `args`, or null when an option can't be read. */
34
+ export declare function xargsCommand(args: readonly string[]): number | null;
@@ -79,3 +79,116 @@ export function unwrapLaunchers(words) {
79
79
  }
80
80
  return { start: Math.min(at, words.length), via, assignments };
81
81
  }
82
+ /**
83
+ * Programs that never run another program: a CLI's name among their words is an argument (`ls supabase`, `grep -rn
84
+ * railway .`, `git grep terraform`, `rm -rf supabase`), not that CLI being run. Each reader of a shell line uses it
85
+ * before failing closed on a CLI's name behind a program it doesn't know (`cli.ts`, `shell.ts`).
86
+ */
87
+ const NEVER_LAUNCH = new Set([
88
+ "ls",
89
+ "cat",
90
+ "bat",
91
+ "head",
92
+ "tail",
93
+ "less",
94
+ "more",
95
+ "grep",
96
+ "egrep",
97
+ "fgrep",
98
+ "rg",
99
+ "ag",
100
+ "ack",
101
+ "wc",
102
+ "file",
103
+ "stat",
104
+ "tree",
105
+ "du",
106
+ "echo",
107
+ "printf",
108
+ "which",
109
+ "whereis",
110
+ "type",
111
+ "jq",
112
+ "yq",
113
+ "diff",
114
+ "cmp",
115
+ "sort",
116
+ "uniq",
117
+ "cut",
118
+ "tr",
119
+ "basename",
120
+ "dirname",
121
+ "realpath",
122
+ "readlink",
123
+ "mkdir",
124
+ "rmdir",
125
+ "touch",
126
+ "rm",
127
+ "cp",
128
+ "mv",
129
+ "ln",
130
+ "chmod",
131
+ "chown",
132
+ "code",
133
+ "cursor",
134
+ "pbcopy"
135
+ ]);
136
+ /** `git` subcommands that read the repository and run nothing (no pager or tool option is read past). */
137
+ const GIT_READS = new Set(["grep", "log", "show", "diff", "status", "blame", "ls-files", "shortlog"]);
138
+ /** Whether `head` (a program name) given `args` only reads or edits files and runs no other program. */
139
+ export function neverLaunches(head, args) {
140
+ if (NEVER_LAUNCH.has(head))
141
+ return true;
142
+ // Tools that do run commands when asked to: only without the options that ask.
143
+ if (head === "git")
144
+ return (GIT_READS.has(args[0] ?? "") && !args.some((a) => /^(-O|--open-files-in-pager|--ext-diff|--textconv)/.test(a)));
145
+ if (head === "find")
146
+ return !args.some((a) => /^-(exec|execdir|ok|okdir)$/.test(a));
147
+ if (head === "fd" || head === "fdfind")
148
+ return !args.some((a) => /^(-x|-X|--exec|--exec-batch)(=|$)/.test(a));
149
+ if (head === "sed")
150
+ return args.includes("-n");
151
+ if (head === "awk" || head === "gawk" || head === "mawk")
152
+ return !args.some((a) => /system\s*\(|\|\s*["$a-zA-Z]|["$)]\s*\|/.test(a));
153
+ if (head === "open")
154
+ return !args.includes("--args");
155
+ return false;
156
+ }
157
+ /** GNU and BSD `xargs` options that take the next word as their value. */
158
+ const XARGS_VALUED = new Set([
159
+ "-I",
160
+ "-L",
161
+ "-n",
162
+ "-P",
163
+ "-s",
164
+ "-d",
165
+ "-E",
166
+ "-a",
167
+ "-J",
168
+ "-R",
169
+ "-S",
170
+ "--arg-file",
171
+ "--delimiter",
172
+ "--max-args",
173
+ "--max-procs",
174
+ "--max-chars",
175
+ "--process-slot-var"
176
+ ]);
177
+ /** Where the command `xargs` runs starts in its `args`, or null when an option can't be read. */
178
+ export function xargsCommand(args) {
179
+ for (let i = 0; i < args.length; i++) {
180
+ const word = args[i];
181
+ if (word === "--")
182
+ return i + 1;
183
+ if (!word.startsWith("-") || word === "-")
184
+ return i;
185
+ if (XARGS_VALUED.has(word))
186
+ i += 1;
187
+ else if (!/^(-[0trpx]+|-[ILnPsdEaJRS].+|-[eil].*|--[a-z-]+(=.*)?)$/.test(word))
188
+ return null;
189
+ else if (/^--[a-z-]+$/.test(word) &&
190
+ !/^--(null|interactive|no-run-if-empty|exit|verbose|open-tty|show-limits)$/.test(word))
191
+ return null;
192
+ }
193
+ return args.length;
194
+ }
@@ -21,7 +21,7 @@
21
21
  */
22
22
  import { programName } from "./cli.generated.js";
23
23
  import { explain, normalize } from "./engine.generated.js";
24
- import { launcherEnd, launcherName } from "./launchers.generated.js";
24
+ import { launcherEnd, launcherName, neverLaunches, xargsCommand } from "./launchers.generated.js";
25
25
  import { fedScript, mentions, SHELLS } from "./shellFed.generated.js";
26
26
  /** A variable set to something the resolver couldn't read. */
27
27
  const UNKNOWN = "\u0000";
@@ -341,6 +341,20 @@ export function readLink(m, folder, guard) {
341
341
  const HEREDOC = /^\d*<<-?(?!<)/;
342
342
  /** Programs that run another command given as words or a string, which the resolver doesn't read into. */
343
343
  const RUNNERS = /^(python[0-9.]*|node|perl|ruby|php|deno|bun|osascript|pwsh|powershell|lua|Rscript|alias|ssh|docker|podman|kubectl|xargs|watch|parallel|su|script|flock|chroot|nsenter|taskset|systemd-run|tmux|screen|find|fd|entr|nodemon|concurrently|devbox|nix-shell|direnv|dotenv|op|doppler|infisical|aws-vault)$/;
344
+ /** The words a runner may run a command from: what follows `find -exec` or `fd -x` (none without them), none when
345
+ * `xargs` runs a program that never runs another (`xargs grep supabase`), else all of them. */
346
+ function runArgs(head, args) {
347
+ const texts = args.map((w) => w.text);
348
+ if (head === "find" || head === "fd" || head === "fdfind") {
349
+ const exec = texts.findIndex((t) => /^(-exec|-execdir|-ok|-okdir|-x|-X|--exec|--exec-batch)(=|$)/.test(t));
350
+ return exec < 0 ? [] : args.slice(exec);
351
+ }
352
+ if (head !== "xargs")
353
+ return args;
354
+ const start = xargsCommand(texts);
355
+ const run = start === null ? undefined : args[start];
356
+ return run && !run.unknown && neverLaunches(programName(run.text), texts.slice(start + 1)) ? [] : args;
357
+ }
344
358
  /** One simple command, split from its assignments, redirections and here-strings (`<<< "text"`). */
345
359
  function simple(words) {
346
360
  const assignments = [];
@@ -570,7 +584,7 @@ function command(m, words, guard, state, out, depth, lineWords, stdin = []) {
570
584
  return failing(m, out, "a script the guard cannot read");
571
585
  if (body.length)
572
586
  return script(m, body.map((w) => w.text).join(" "), guard, state, out, depth + 1);
573
- if (RUNNERS.test(head) && mentions(args, programs))
587
+ if (RUNNERS.test(head) && mentions(runArgs(head, args), programs))
574
588
  return failing(m, out, `run by ${head}`);
575
589
  const request = { interface: "cli", argv: rest.map((w) => w.text) };
576
590
  const n = normalize(m, request);
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export declare const PLUGIN_PIN = "0.51.0";
7
+ export declare const PLUGIN_PIN = "0.52.0";
package/dist/pluginPin.js CHANGED
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export const PLUGIN_PIN = "0.51.0";
7
+ export const PLUGIN_PIN = "0.52.0";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.51.0";
1
+ export declare const VERSION = "0.52.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Keep in lockstep with bridge/package.json.
2
- export const VERSION = "0.51.0";
2
+ export const VERSION = "0.52.0";
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.51.0",
9
+ "version": "0.52.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.32.1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "Passport CLI for governed terminal and CI agents, plus the local stdio-to-cloud MCP bridge.",
5
5
  "license": "MIT",
6
6
  "repository": {