passport-bridge 0.16.2 → 0.16.4

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.
@@ -1,5 +1,6 @@
1
1
  import { closeSync, constants, fchmodSync, fstatSync, lstatSync, openSync, readFileSync, unlinkSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { dropCachedAccess } from "./accessTokenCache.js";
3
4
  import { credentialDir, enforceOwner, ensurePrivateDirectory, isMissing, syncDirectory, withCredentialStoreWriteLock as withStoreWriteLock, withProfileLock as withProfileLockInternal, writePrivateAtomic } from "./credentialStorage.js";
4
5
  import { activeProfilePath, clearActiveProfileAtomic, prepareActiveProfileForSelection, readActiveProfile as readActiveProfileFile, readActiveProfileDocument, writeActiveProfileAtomic } from "./activeProfile.js";
5
6
  /**
@@ -281,6 +282,7 @@ export function persistProfileRotation(name, previousRefreshToken, next) {
281
282
  creds[name] = { ...latest, ...validatedNext };
282
283
  writeCredsAtomic(creds);
283
284
  clearRotationJournal(name);
285
+ dropCachedAccess(name);
284
286
  });
285
287
  }
286
288
  /** Persist a rotating child against the endpoint currently stored for this
@@ -311,6 +313,7 @@ export function recoverProfileRotation(name) {
311
313
  if (current.refreshToken === journal.previousRefreshToken) {
312
314
  creds[name] = { ...current, ...journal.next };
313
315
  writeCredsAtomic(creds);
316
+ dropCachedAccess(name);
314
317
  }
315
318
  else if (current.refreshToken !== journal.next.refreshToken) {
316
319
  throw new Error("Passport profile conflicts with its credential rotation recovery journal.");
@@ -327,6 +330,7 @@ export function writeProfile(name, profile) {
327
330
  creds[name] = { ...creds[name], ...profile };
328
331
  writeCredsAtomic(creds);
329
332
  clearRotationJournal(name);
333
+ dropCachedAccess(name);
330
334
  });
331
335
  }
332
336
  /** Replace a profile only if the credential that started an interactive
@@ -347,6 +351,7 @@ export function replaceProfileAfterRecovery(name, previousRefreshToken, profile)
347
351
  creds[name] = { ...current, ...profile };
348
352
  writeCredsAtomic(creds);
349
353
  clearRotationJournal(name);
354
+ dropCachedAccess(name);
350
355
  });
351
356
  }
352
357
  export function removeProfile(name) {
@@ -358,6 +363,7 @@ export function removeProfile(name) {
358
363
  delete creds[name];
359
364
  writeCredsAtomic(creds);
360
365
  clearRotationJournal(name);
366
+ dropCachedAccess(name);
361
367
  if (active.kind === "present" && active.profile === name) {
362
368
  const remaining = Object.keys(creds).sort();
363
369
  if (remaining.length === 1)
@@ -7,6 +7,9 @@ export type StableCommand = {
7
7
  source: "global" | "installed";
8
8
  /** Folder holding the `passport` shim, when this is Passport's own copy. */
9
9
  binDir?: string;
10
+ /** The version-independent launcher in `binDir` that hooks run. Upgrades
11
+ * rewrite it in place, so hooks follow without being edited. */
12
+ launcher?: string;
10
13
  /** Whether `passport` already resolves on PATH (outside npm's cache). */
11
14
  onPath: boolean;
12
15
  };
@@ -37,6 +40,15 @@ export declare function resolveStableNode(context: InstallContext): string | und
37
40
  * only where two versions conflict.
38
41
  */
39
42
  export declare function copyPackageClosure(packageRoot: string, target: string): number;
43
+ /**
44
+ * One launcher's text. It runs the recorded node when that still exists, else
45
+ * whichever node the shell finds, so removing an nvm version doesn't break
46
+ * hooks. The last line keeps the exact `exec '<node>' '<entry>' "$@"` (or
47
+ * `"<node>" "<entry>" %*`) form the Passport plugin reads.
48
+ */
49
+ export declare function launcherText(node: string, entry: string, platform: NodeJS.Platform): string;
50
+ /** The launcher hooks run: `passport` (or `passport.cmd`) in `binDir`. */
51
+ export declare function launcherPath(binDir: string, platform: NodeJS.Platform): string;
40
52
  export declare class StableInstallError extends Error {
41
53
  }
42
54
  /**
@@ -4,20 +4,25 @@
4
4
  * `npx passport-bridge@latest init` runs from npm's cache, which npm may clear at
5
5
  * any time. A hook that points there breaks silently. So init copies the running
6
6
  * package once into `$PASSPORT_HOME/cli/<version>/` (with its dependencies) and
7
- * registers `"<node>" "<that copy>/dist/passport.js"`, both absolute, so hooks
8
- * do not depend on the agent's PATH. A global `passport` from npm
9
- * that is the same version or newer is used instead of a copy.
7
+ * registers the launcher `$PASSPORT_HOME/cli/bin/passport` (`passport.cmd` on
8
+ * Windows), an absolute path, so hooks do not depend on the agent's PATH. The
9
+ * launcher names the version, so an upgrade rewrites it (and the `cli/current`
10
+ * link) and every hook follows without being edited. It runs the recorded node,
11
+ * or the node on PATH once that one is gone. A global `passport` from npm that
12
+ * is the same version or newer is used instead of a copy.
10
13
  *
11
14
  * Every write is atomic: the copy is built in a temporary folder and renamed
12
15
  * into place, so Ctrl-C never leaves a half-installed version behind.
13
16
  */
14
17
  import { randomBytes } from "node:crypto";
15
- import { accessSync, chmodSync, constants, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
18
+ import { accessSync, chmodSync, constants, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
16
19
  import { spawnSync } from "node:child_process";
17
20
  import { basename, delimiter, dirname, join, relative, resolve, sep } from "node:path";
18
21
  import { credentialDir, ensurePrivateDirectory } from "./credentialStorage.js";
19
22
  import { ONE_LINER_MIN_NODE } from "./nodeVersion.js";
20
23
  const INSTALL_MARKER = ".passport-install.json";
24
+ /** `cli/current`: a link to the installed version (POSIX), read by the plugin. */
25
+ const CURRENT = "current";
21
26
  /** npm's cache and the one-off folders npx and pnpm dlx run from. */
22
27
  export function isEphemeralPath(path) {
23
28
  const normalized = path.split(sep).join("/");
@@ -236,7 +241,42 @@ export function copyPackageClosure(packageRoot, target) {
236
241
  function quoteSh(value) {
237
242
  return `'${value.replace(/'/g, `'\\''`)}'`;
238
243
  }
239
- /** Version-independent `passport` and `passport-bridge` launchers for PATH. */
244
+ /**
245
+ * One launcher's text. It runs the recorded node when that still exists, else
246
+ * whichever node the shell finds, so removing an nvm version doesn't break
247
+ * hooks. The last line keeps the exact `exec '<node>' '<entry>' "$@"` (or
248
+ * `"<node>" "<entry>" %*`) form the Passport plugin reads.
249
+ */
250
+ export function launcherText(node, entry, platform) {
251
+ if (platform === "win32") {
252
+ return [
253
+ "@echo off",
254
+ `if not exist "${node}" goto fallback`,
255
+ `"${node}" "${entry}" %*`,
256
+ "exit /b %ERRORLEVEL%",
257
+ ":fallback",
258
+ `node "${entry}" %*`,
259
+ ""
260
+ ].join("\r\n");
261
+ }
262
+ return [
263
+ "#!/bin/sh",
264
+ "# Passport CLI launcher. Upgrades rewrite this file; agent hooks run it.",
265
+ `if [ ! -x ${quoteSh(node)} ]; then`,
266
+ ` for candidate in "$(command -v node 2>/dev/null)" /opt/homebrew/bin/node /usr/local/bin/node; do`,
267
+ ` if [ -n "$candidate" ] && [ -x "$candidate" ]; then exec "$candidate" ${quoteSh(entry)} "$@"; fi`,
268
+ " done",
269
+ "fi",
270
+ `exec ${quoteSh(node)} ${quoteSh(entry)} "$@"`,
271
+ ""
272
+ ].join("\n");
273
+ }
274
+ /** The launcher hooks run: `passport` (or `passport.cmd`) in `binDir`. */
275
+ export function launcherPath(binDir, platform) {
276
+ return join(binDir, platform === "win32" ? "passport.cmd" : "passport");
277
+ }
278
+ /** Version-independent `passport` and `passport-bridge` launchers. Each is
279
+ * replaced with one rename, so a hook never runs a half-written file. */
240
280
  function writeShims(binDir, node, versionDir, platform) {
241
281
  mkdirSync(binDir, { recursive: true, mode: 0o700 });
242
282
  const shims = [
@@ -245,9 +285,7 @@ function writeShims(binDir, node, versionDir, platform) {
245
285
  ];
246
286
  for (const [name, entry] of shims) {
247
287
  const file = join(binDir, platform === "win32" ? `${name}.cmd` : name);
248
- const body = platform === "win32"
249
- ? `@echo off\r\n"${node}" "${entry}" %*\r\n`
250
- : `#!/bin/sh\nexec ${quoteSh(node)} ${quoteSh(entry)} "$@"\n`;
288
+ const body = launcherText(node, entry, platform);
251
289
  try {
252
290
  if (readFileSync(file, "utf8") === body)
253
291
  continue;
@@ -261,6 +299,37 @@ function writeShims(binDir, node, versionDir, platform) {
261
299
  renameSync(temporary, file);
262
300
  }
263
301
  }
302
+ /** `cli/current` → the installed version, swapped with one rename. POSIX only:
303
+ * Windows has the launcher alone. Best effort; the launcher is what hooks run. */
304
+ function pointCurrent(root, version, platform) {
305
+ if (platform === "win32")
306
+ return;
307
+ const link = join(root, CURRENT);
308
+ try {
309
+ if (lstatSync(link).isSymbolicLink() && readlinkSync(link) === version)
310
+ return;
311
+ }
312
+ catch {
313
+ /* not there yet */
314
+ }
315
+ const temporary = join(root, `.current-${randomBytes(6).toString("hex")}.tmp`);
316
+ try {
317
+ symlinkSync(version, temporary);
318
+ renameSync(temporary, link);
319
+ }
320
+ catch {
321
+ rmSync(temporary, { force: true });
322
+ }
323
+ }
324
+ /** The version `cli/current` points at, if any. */
325
+ function currentVersion() {
326
+ try {
327
+ return readlinkSync(join(cliRoot(), CURRENT));
328
+ }
329
+ catch {
330
+ return undefined;
331
+ }
332
+ }
264
333
  export class StableInstallError extends Error {
265
334
  }
266
335
  /**
@@ -301,7 +370,16 @@ export function ensureStableCommand(context) {
301
370
  }
302
371
  const binDir = join(root, "bin");
303
372
  writeShims(binDir, node, versionDir, context.platform);
304
- return { node, entry: join(versionDir, "dist", "passport.js"), version, source: "installed", binDir, onPath };
373
+ pointCurrent(root, version, context.platform);
374
+ return {
375
+ node,
376
+ entry: join(versionDir, "dist", "passport.js"),
377
+ version,
378
+ source: "installed",
379
+ binDir,
380
+ launcher: launcherPath(binDir, context.platform),
381
+ onPath
382
+ };
305
383
  }
306
384
  /** The versions of Passport's own copies that these commands run. */
307
385
  export function copyVersionsIn(commands) {
@@ -326,6 +404,9 @@ export function copyVersionsIn(commands) {
326
404
  */
327
405
  export function pruneCopies(keep) {
328
406
  const kept = new Set(keep);
407
+ const linked = currentVersion();
408
+ if (linked)
409
+ kept.add(linked);
329
410
  const removed = [];
330
411
  let entries;
331
412
  try {
@@ -335,7 +416,7 @@ export function pruneCopies(keep) {
335
416
  return removed;
336
417
  }
337
418
  for (const entry of entries) {
338
- if (entry === "bin" || entry.startsWith(".") || kept.has(entry))
419
+ if (entry === "bin" || entry === CURRENT || entry.startsWith(".") || kept.has(entry))
339
420
  continue;
340
421
  const directory = join(cliRoot(), entry);
341
422
  if (!existsSync(join(directory, INSTALL_MARKER)))
@@ -357,7 +438,7 @@ export function isOtherPassportInstall(path, version) {
357
438
  if (rel.startsWith("..") || rel === "")
358
439
  return false;
359
440
  const [installed] = rel.split(sep);
360
- return installed !== version && installed !== "bin";
441
+ return installed !== version && installed !== "bin" && installed !== CURRENT;
361
442
  }
362
443
  /** One line a person can paste to put `passport` on PATH. Printed, never run. */
363
444
  export function pathLine(binDir, env, home, platform) {
@@ -4,7 +4,7 @@
4
4
  * destructive production actions ask first.
5
5
  */
6
6
  import { bool } from "./cliArgs.js";
7
- import { HOOK_CLIENTS, applyGuardInstall, nodeInvocation, planGuardInstall, registeredEntries } from "./cliHookInstall.js";
7
+ import { HOOK_CLIENTS, applyGuardInstall, stableInvocation, planGuardInstall, registeredEntries } from "./cliHookInstall.js";
8
8
  import { CliFailure, readBoundedJson, safeApiError } from "./cliSupport.js";
9
9
  import { AGENT_NAMES, applyAgent, backupOnce, detectAgents, displayHome, editsExistingFile, needsWork, planAgent } from "./initAgents.js";
10
10
  import { copyVersionsIn, ensureStableCommand, pruneCopies } from "./initInstall.js";
@@ -209,7 +209,7 @@ async function guardSetup(s) {
209
209
  return;
210
210
  }
211
211
  s.stable = stable;
212
- const invocation = nodeInvocation(stable.node, stable.entry);
212
+ const invocation = stableInvocation(stable);
213
213
  const plans = [];
214
214
  const problems = [];
215
215
  for (const client of clients) {
@@ -241,8 +241,9 @@ function interpreter(program, words, ctx) {
241
241
  return local(fromVerdict(args[1], answer, ctx.here));
242
242
  return unknown(`python -m ${args[1]} not recognized`);
243
243
  }
244
- if (program === "node" && args[0] === "--test")
245
- return local(fromVerdict("node", R("test"), ctx.here));
244
+ // `node --test` and `tsx --test` run the project's own test files.
245
+ if ((program === "node" || program === "tsx") && args[0] === "--test")
246
+ return local(fromVerdict(program, R("test"), ctx.here));
246
247
  if (program === "node" && (args[0] === "--check" || args[0] === "-c"))
247
248
  return local(fromVerdict("node", R("check"), ctx.here));
248
249
  return unknown(`${program} runs code Passport can't see`);
@@ -257,6 +258,8 @@ function packageRunner(words, ctx) {
257
258
  const tool = basename(name);
258
259
  if (ctx.isVendor(tool) || /^@(railway|sentry|stripe)\//.test(name) || /^(vercel|wrangler|supabase)$/.test(tool))
259
260
  return { kind: "vendor" };
261
+ if (tool === "tsx")
262
+ return interpreter(tool, words.slice(index + 1), ctx);
260
263
  return toolCommand(tool, words.slice(index + 1), ctx);
261
264
  }
262
265
  function toolCommand(program, words, ctx) {
@@ -409,7 +412,7 @@ const PROGRAMS = {
409
412
  : toolCommand(program, rest, ctx),
410
413
  ...each(["docker", "podman", "docker-compose"], (program, rest, ctx) => docker(program, rest, ctx)),
411
414
  ...each(["kill", "pkill", "killall"], (program, rest) => processControl(program, rest)),
412
- ...each(["node", "python", "python3", "ruby", "perl"], (program, rest, ctx) => interpreter(program, rest, ctx)),
415
+ ...each(["node", "tsx", "python", "python3", "ruby", "perl"], (program, rest, ctx) => interpreter(program, rest, ctx)),
413
416
  deno: (program, rest, ctx) => rest[0] && !rest[0].text.startsWith("-") ? toolCommand(program, rest, ctx) : interpreter(program, rest, ctx),
414
417
  ...each(["env", "printenv"], () => unknown("prints the environment")),
415
418
  ...each(["dd", "mkfs", "diskutil", "fdisk"], (program) => unknown(`${program} writes disks`))
@@ -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.16.2";
7
+ export declare const PLUGIN_PIN = "0.16.4";
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.16.2";
7
+ export const PLUGIN_PIN = "0.16.4";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.16.2";
1
+ export declare const VERSION = "0.16.4";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Keep in lockstep with bridge/package.json.
2
- export const VERSION = "0.16.2";
2
+ export const VERSION = "0.16.4";
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.16.2",
3
+ "version": "0.16.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.16.2",
9
+ "version": "0.16.4",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@modelcontextprotocol/sdk": "1.30.0"
12
+ "@modelcontextprotocol/sdk": "1.32.1"
13
13
  },
14
14
  "bin": {
15
15
  "passport": "dist/passport.js",
@@ -479,9 +479,9 @@
479
479
  }
480
480
  },
481
481
  "node_modules/@modelcontextprotocol/sdk": {
482
- "version": "1.30.0",
483
- "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.30.0.tgz",
484
- "integrity": "sha512-xKd8OIzlqNzcqcNumGAa6g+PW2kjD5vrpcKOnfldAUPP3j7lnqMPwlTXQm8gF+UwH72z0lqaRbjr9hqGz0eITA==",
482
+ "version": "1.32.1",
483
+ "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.1.tgz",
484
+ "integrity": "sha512-2DdE+SJDtzLEEWzY1ZjY7Q+VcPhcV1KisD3zI4u0XZyktsjHum1mwbMI+JaulUBi2OZk+KJAi2uPXzxichPkdw==",
485
485
  "license": "MIT",
486
486
  "dependencies": {
487
487
  "@hono/node-server": "^1.19.9 || ^2.0.5",
@@ -1359,9 +1359,9 @@
1359
1359
  }
1360
1360
  },
1361
1361
  "node_modules/proxy-addr": {
1362
- "version": "2.0.7",
1363
- "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
1364
- "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
1362
+ "version": "2.0.8",
1363
+ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz",
1364
+ "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==",
1365
1365
  "license": "MIT",
1366
1366
  "dependencies": {
1367
1367
  "forwarded": "0.2.0",
@@ -1369,6 +1369,10 @@
1369
1369
  },
1370
1370
  "engines": {
1371
1371
  "node": ">= 0.10"
1372
+ },
1373
+ "funding": {
1374
+ "type": "opencollective",
1375
+ "url": "https://opencollective.com/express"
1372
1376
  }
1373
1377
  },
1374
1378
  "node_modules/qs": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.16.2",
3
+ "version": "0.16.4",
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": {
@@ -64,7 +64,7 @@
64
64
  "prepublishOnly": "npm run build"
65
65
  },
66
66
  "dependencies": {
67
- "@modelcontextprotocol/sdk": "1.30.0"
67
+ "@modelcontextprotocol/sdk": "1.32.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^24.13.1",