passport-bridge 0.30.0 → 0.30.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.
@@ -4,8 +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, from
8
- * `passport exec`, and from `passport status`.
7
+ * Sent from a guard run that has 300 ms of its budget left and from
8
+ * `passport exec` once a day, and every time from `passport init` (after the
9
+ * guard step) and `passport status`.
9
10
  */
10
11
  import { type GuardClient, type GuardClientReport, type GuardHealthReport, type ProblemFix } from "./cliGuardState.js";
11
12
  import type { Env } from "./cliSupport.js";
@@ -37,6 +38,10 @@ export type ReportedAgent = {
37
38
  * agent's state and fix) or null when it couldn't be sent.
38
39
  */
39
40
  export declare function sendGuardHealth(api: ApiCall, profile: string, env: Env, signal: AbortSignal): Promise<ReportedAgent[] | null>;
40
- /** The daily report, if due: claim, then send. */
41
- export declare function guardHeartbeat(api: ApiCall, profile: string, env: Env, signal: AbortSignal, now?: number): Promise<ReportedAgent[] | null>;
41
+ /**
42
+ * The daily report, if due: claim, then send. `force` sends it now anyway,
43
+ * for `init` (it just turned the guard on) and `status` (someone is looking),
44
+ * so Agents shows each agent's guard without waiting a day.
45
+ */
46
+ export declare function guardHeartbeat(api: ApiCall, profile: string, env: Env, signal: AbortSignal, now?: number, force?: boolean): Promise<ReportedAgent[] | null>;
42
47
  export {};
@@ -4,8 +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, from
8
- * `passport exec`, and from `passport status`.
7
+ * Sent from a guard run that has 300 ms of its budget left and from
8
+ * `passport exec` once a day, and every time from `passport init` (after the
9
+ * guard step) and `passport status`.
9
10
  */
10
11
  import { closeSync, constants, mkdirSync, openSync, readFileSync, statSync, utimesSync } from "node:fs";
11
12
  import { join } from "node:path";
@@ -143,12 +144,18 @@ export async function sendGuardHealth(api, profile, env, signal) {
143
144
  return null;
144
145
  }
145
146
  }
146
- /** The daily report, if due: claim, then send. */
147
- export async function guardHeartbeat(api, profile, env, signal, now = Date.now()) {
148
- if (!claimGuardHeartbeat(profile, now))
147
+ /**
148
+ * The daily report, if due: claim, then send. `force` sends it now anyway,
149
+ * for `init` (it just turned the guard on) and `status` (someone is looking),
150
+ * so Agents shows each agent's guard without waiting a day.
151
+ */
152
+ export async function guardHeartbeat(api, profile, env, signal, now = Date.now(), force = false) {
153
+ const due = claimGuardHeartbeat(profile, now);
154
+ if (!due && !(force && stampHeartbeat(profile, now)))
149
155
  return null;
150
156
  const sent = await sendGuardHealth(api, profile, env, signal);
151
157
  // Once a day too: has a key `passport keys move` removed come back?
152
- await (await import("./cliKeysBack.js")).checkKeysBack(api, signal, process.env, profile).catch(() => undefined);
158
+ if (due)
159
+ await (await import("./cliKeysBack.js")).checkKeysBack(api, signal, process.env, profile).catch(() => undefined);
153
160
  return sent;
154
161
  }
package/dist/cliHook.d.ts CHANGED
@@ -18,6 +18,7 @@ import { type ParsedArgs } from "./cliArgs.js";
18
18
  import { type CliFinding } from "./cliHookClassify.js";
19
19
  import { type DecidedFinding, type GuardDecision } from "./cliHookGuard.js";
20
20
  import { type HookInput } from "./cliHookInput.js";
21
+ export { pairingId } from "./cliHookPairing.js";
21
22
  import { type CliHookReport, type HookDependencies, type HookRuntime } from "./cliHookDeliver.js";
22
23
  export { HOOK_BUDGET_MS, HOOK_RUNTIMES, legacyReport, type CliHookReport, type HookDependencies, type HookRuntime, type ReportedFinding } from "./cliHookDeliver.js";
23
24
  export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
package/dist/cliHook.js CHANGED
@@ -23,6 +23,8 @@ import { guardMachineOf } from "./cliHookGuard.js";
23
23
  import { detectMode } from "./cliHookMode.js";
24
24
  import { cappedHold, holdSeconds } from "./cliHookHold.js";
25
25
  import { commandText, readInput } from "./cliHookInput.js";
26
+ import { pairingId, withPairing, withParked } from "./cliHookPairing.js";
27
+ export { pairingId } from "./cliHookPairing.js";
26
28
  import { budgetSignal, expiredAsks, HOOK_BUDGET_MS, HOOK_RUNTIMES, leftovers, localProfile, localSelection, profileApi, queueAfterCommand, reportSender, runFlush, startFlushIfDue } from "./cliHookDeliver.js";
27
29
  export { HOOK_BUDGET_MS, HOOK_RUNTIMES, legacyReport } from "./cliHookDeliver.js";
28
30
  import { hookViaPlugin } from "./hookPlugin.js";
@@ -30,7 +32,7 @@ import { guardLocalBackups, markLocalBackups } from "./localBackups.js";
30
32
  import { auditBackups, auditDecision, auditedCommand, markTrashed } from "./cliHookAudit.js";
31
33
  import { opaqueParts } from "./cliHookOpaque.js";
32
34
  export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
33
- import { hasExpired, holdAsk, takeAsk } from "./cliHookPending.js";
35
+ import { hasExpired, holdAsk } from "./cliHookPending.js";
34
36
  import { readCliPolicy } from "./cliPolicy.js";
35
37
  import { saveScriptCache, scriptReader, scriptReport } from "./cliScriptRead.js";
36
38
  import { standDownForManaged } from "./managedHooks.js";
@@ -309,7 +311,7 @@ async function runAudit(args, runtime, deps) {
309
311
  const findings = line.findings;
310
312
  saveScriptCache(scripts);
311
313
  // v2: the same decision the guard made, so the row says why it ran.
312
- const key = context(input, runtime.env, value(args, "client"));
314
+ const key = withPairing(context(input, runtime.env, value(args, "client")), input, event.command);
313
315
  const { taken, backedUp } = auditBackups(findings, key, Boolean(trashed));
314
316
  const guardAt = { ...guardAtFor(machine, input, runtime.env), ...taken };
315
317
  const { decision, local, decided } = auditDecision(findings, policy, command, line.complete, guardAt);
@@ -323,7 +325,7 @@ async function runAudit(args, runtime, deps) {
323
325
  // The guard parked what it decided before this exact command: send one row
324
326
  // for both, "asked first, then ran" (or the server's own allow).
325
327
  if (report && !event.cursorImported)
326
- report = await withParked(report, input, profile, now);
328
+ report = await withParked(report, pairingId(input, event.command), profile, now);
327
329
  if (!report && !hasExpired(now))
328
330
  return;
329
331
  if (!deps.send && !deps.fetch) {
@@ -339,20 +341,6 @@ async function runAudit(args, runtime, deps) {
339
341
  await Promise.allSettled(reports.map((entry) => send(entry)));
340
342
  }
341
343
  /** One row for an ask and the run that followed it; how long the person took to say yes. */
342
- async function withParked(report, input, profile, now) {
343
- const toolUseId = text(input.tool_use_id, 128);
344
- const parked = toolUseId ? takeAsk(report.runtime, report.sessionId, toolUseId) : null;
345
- if (!parked)
346
- return report;
347
- const held = parked.report;
348
- if (held.decision === "allow")
349
- return { ...report, decision: "allow" };
350
- // From the prompt to the command finishing, less its own run time.
351
- const waited = now - parked.createdAt - (report.durationMs ?? 0);
352
- if (profile && waited >= 0)
353
- (await import("./cliSpeed.js")).noteApprovalWait(profile, report.runtime, waited, now);
354
- return { ...report, decision: "ask", ran: true };
355
- }
356
344
  function outputClient(event, runtime) {
357
345
  if (event.cursorNative)
358
346
  return "cursor";
@@ -365,7 +353,7 @@ function outputClient(event, runtime) {
365
353
  * allow, or an ask parked until the command runs). */
366
354
  async function guardReport(base, plan, context) {
367
355
  if (plan.server && base)
368
- return serverDecidedReport(base, plan.server, context.now, plan.held);
356
+ return serverDecidedReport(base, plan.server, context.now, plan.held, context.pairingId);
369
357
  // Offline, this computer's answer replaces the local Ask on the record.
370
358
  const decided = base && plan.offline && plan.verdict ? { ...base, decision: plan.verdict } : base;
371
359
  const report = decided && context.v2 && decided.decision === "allow" ? null : codexAskBlocked(decided);
@@ -384,21 +372,22 @@ async function guardReport(base, plan, context) {
384
372
  * earlier) is parked for the run's own row; a waiting request is "asked"; a
385
373
  * declined one is "asked, not run"; a block is a block.
386
374
  */
387
- function serverDecidedReport(base, server, now, held) {
375
+ function serverDecidedReport(base, server, now, held, pairingId = base.toolUseId) {
388
376
  if (server.decision === "none")
389
377
  return null;
390
378
  // Held, and approved in time: "asked first, then ran", once the run reports.
391
379
  if (held === "approved") {
392
380
  const asked = { ...base, decision: "ask" };
393
- if (base.toolUseId && holdAsk(base.runtime, base.sessionId, base.toolUseId, asked, now))
381
+ if (pairingId && holdAsk(base.runtime, base.sessionId, pairingId, asked, now))
394
382
  return null;
395
383
  return { ...asked, ran: true };
396
384
  }
397
385
  if (held === "declined" || held === "expired")
398
386
  return { ...base, decision: "ask", ran: false };
399
387
  if (server.decision === "allow") {
400
- if (base.toolUseId)
401
- holdAsk(base.runtime, base.sessionId, base.toolUseId, { ...base, decision: "allow" }, now);
388
+ // Cursor too (by its pairing id), so the run's own row says it was allowed, not asked.
389
+ if (pairingId)
390
+ holdAsk(base.runtime, base.sessionId, pairingId, { ...base, decision: "allow" }, now);
402
391
  return null;
403
392
  }
404
393
  if (server.decision === "ask")
@@ -474,8 +463,9 @@ async function runGuard(args, runtime, deps) {
474
463
  const declared = value(args, "client");
475
464
  const client = outputClient(event, detectRuntime(input, runtime.env, declared));
476
465
  // Which deletes will have a backup on this computer, so the rules decide knowing it.
466
+ const key = withPairing(context(input, runtime.env, declared), input, event.command);
477
467
  const backups = guardLocalBackups(event.command, line, policy, {
478
- ...{ ...guardAtFor(machine, input, runtime.env), machine, key: context(input, runtime.env, declared) },
468
+ ...{ ...guardAtFor(machine, input, runtime.env), machine, key },
479
469
  rewrite: client === "claude-code" && !event.cursorImported
480
470
  });
481
471
  let decision = backups.decision;
@@ -551,7 +541,8 @@ async function runGuard(args, runtime, deps) {
551
541
  const report = await guardReport(withStep(base && plan.output ? base : null, input, policy), plan, {
552
542
  v2: policy?.version === 2,
553
543
  runtime,
554
- now: clock()
544
+ now: clock(),
545
+ pairingId: pairingId(input, event.command)
555
546
  });
556
547
  if (!deps.send && !deps.fetch) {
557
548
  // The agent is waiting for this process to exit: never wait on the network
@@ -20,6 +20,7 @@ export type HookInput = {
20
20
  /** Cursor's native shell events. */
21
21
  command?: unknown;
22
22
  conversation_id?: unknown;
23
+ generation_id?: unknown;
23
24
  cursor_version?: unknown;
24
25
  duration?: unknown;
25
26
  workspace_roots?: unknown;
@@ -0,0 +1,9 @@
1
+ import type { CliHookReport } from "./cliHookDeliver.js";
2
+ import type { HookInput } from "./cliHookInput.js";
3
+ export declare function pairingId(input: HookInput, command: string): string | undefined;
4
+ /** A backup key with the local pairing id, so the guard and audit runs find the same backup. */
5
+ export declare function withPairing<T extends {
6
+ toolUseId?: string;
7
+ }>(key: T, input: HookInput, command: string): T;
8
+ /** The guard parked what it decided before this exact command: one row for both, "asked first, then ran" (or the server's own allow). */
9
+ export declare function withParked(report: CliHookReport, toolUseId: string | undefined, profile: string | undefined, now: number): Promise<CliHookReport>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What pairs a command's guard run with its audit run on this computer: the
3
+ * agent's tool-use id. Cursor sends none, so its conversation, generation, and
4
+ * the command stand in, the same before and after the command. Only ever a
5
+ * local file key (parked answers, backups); never reported.
6
+ */
7
+ import { createHash } from "node:crypto";
8
+ import { takeAsk } from "./cliHookPending.js";
9
+ function text(candidate) {
10
+ return typeof candidate === "string" && candidate.length > 0 && candidate.length <= 128 ? candidate : undefined;
11
+ }
12
+ export function pairingId(input, command) {
13
+ const toolUseId = text(input.tool_use_id);
14
+ const cursor = input.hook_event_name === "beforeShellExecution" || input.hook_event_name === "afterShellExecution";
15
+ if (toolUseId || !cursor)
16
+ return toolUseId;
17
+ const conversation = text(input.conversation_id);
18
+ const generation = text(input.generation_id);
19
+ if (!conversation || !generation)
20
+ return undefined;
21
+ const digest = createHash("sha256").update(`${conversation}\u0000${generation}\u0000${command}`).digest("hex");
22
+ return `cursor:${digest.slice(0, 32)}`;
23
+ }
24
+ /** A backup key with the local pairing id, so the guard and audit runs find the same backup. */
25
+ export function withPairing(key, input, command) {
26
+ const toolUseId = pairingId(input, command);
27
+ return toolUseId ? { ...key, toolUseId } : key;
28
+ }
29
+ /** The guard parked what it decided before this exact command: one row for both, "asked first, then ran" (or the server's own allow). */
30
+ export async function withParked(report, toolUseId, profile, now) {
31
+ const parked = toolUseId ? takeAsk(report.runtime, report.sessionId, toolUseId) : null;
32
+ if (!parked)
33
+ return report;
34
+ const held = parked.report;
35
+ if (held.decision === "allow")
36
+ return { ...report, decision: "allow" };
37
+ // From the prompt to the command finishing, less its own run time.
38
+ const waited = now - parked.createdAt - (report.durationMs ?? 0);
39
+ if (profile && waited >= 0)
40
+ (await import("./cliSpeed.js")).noteApprovalWait(profile, report.runtime, waited, now);
41
+ return { ...report, decision: "ask", ran: true };
42
+ }
@@ -40,7 +40,7 @@ async function coverage(api, signal) {
40
40
  export async function guardStatus(api, profile, signal, now = Date.now(), env = process.env) {
41
41
  try {
42
42
  const local = (await localGuardStates(env)).filter((entry) => entry.state);
43
- const reported = api && profile ? await guardHeartbeat(api, profile, env, signal, now) : null;
43
+ const reported = api && profile ? await guardHeartbeat(api, profile, env, signal, now, true) : null;
44
44
  const agents = local.map((entry) => {
45
45
  // Passport knows what this computer can't (an agent turned off since it was on).
46
46
  const server = reported?.find((agent) => agent.client === entry.client);
@@ -266,6 +266,17 @@ export async function applyGuard(s, plan, mode) {
266
266
  await guardSetup(s, plan, mode);
267
267
  if (s.stable)
268
268
  pruneOldCopies(s, s.stable);
269
+ await reportGuard(s);
270
+ }
271
+ /** Tell Passport now which agents have the guard, so Agents and Get started show them. Never fails init. */
272
+ async function reportGuard(s) {
273
+ const status = s.summary.steps.guard?.status;
274
+ if (!s.profile || !s.gateway || (status !== "done" && status !== "already_set_up" && status !== "needs_attention"))
275
+ return;
276
+ const { guardHeartbeat } = await import("./cliGuardHealth.js");
277
+ const signal = AbortSignal.any([s.signal, AbortSignal.timeout(1_500)]);
278
+ // Now when this run turned it on; otherwise only if today's report is due.
279
+ await guardHeartbeat((path, init) => s.api(path, init), s.profile, s.env, signal, Date.now(), status === "done").catch(() => undefined);
269
280
  }
270
281
  /** Keep the running version and whatever a hook still runs; drop the rest. */
271
282
  function pruneOldCopies(s, stable) {
package/dist/initOutro.js CHANGED
@@ -6,7 +6,8 @@
6
6
  * ✓ Passport added to Claude Code and Cursor
7
7
  * ! Railway connects to Passport once you finish signing in
8
8
  *
9
- * Next: ask your agent to do something. Its work shows up on Work:
9
+ * Next: ask your agent to work with one of your apps, like GitHub or
10
+ * Railway. You'll see each step on Work:
10
11
  * https://passportmcp.com/#work
11
12
  */
12
13
  import { EXEC_TOKEN_PAGES, EXEC_VENDOR_NAMES } from "./execVendors.js";
@@ -115,15 +116,17 @@ function agentFollowUps(s) {
115
116
  }
116
117
  return items;
117
118
  }
118
- /** The one next step: put passport on PATH, finish app sign-ins, try an
119
- * agent, or watch its work on Work, the page a new person's Get started is
120
- * waiting on. A command or link is never wrapped. */
119
+ /** The one next step: put passport on PATH (then Work), finish app sign-ins,
120
+ * try an agent, or watch its work on Work, the page a new person's Get started
121
+ * is waiting on. A command or link is never wrapped. */
121
122
  function nextCommand(s, waiting) {
122
123
  const stable = s.stable;
123
124
  if (stable?.binDir && !stable.onPath) {
124
125
  const line = pathLine(stable.binDir, s.env, s.home, s.platform);
125
126
  s.summary.pathLine = line;
126
- return pathNext(line, s.terminal.width);
127
+ // PATH first, then the step Get started waits for, so a first npx run still ends on Work.
128
+ const work = workNext(s, "Then");
129
+ return [...pathNext(line, s.terminal.width), ...(work.length ? ["", ...work] : [])];
127
130
  }
128
131
  if (waiting && !s.terminal.interactive)
129
132
  return ["Run: passport connect --wait 300"];
@@ -133,10 +136,16 @@ function nextCommand(s, waiting) {
133
136
  const ask = app ? TRY_IT[app] : "list your Passport tools";
134
137
  return wrap(`Next: in Claude Code, run /mcp to sign in, then ask it to ${ask}.`, s.terminal.width);
135
138
  }
139
+ const work = workNext(s, "Next:");
140
+ return work.length ? work : ["Run: passport status"];
141
+ }
142
+ /** "Next: ask your agent to work with an app…" and the Work link; nothing without a server to link to. */
143
+ function workNext(s, lead) {
136
144
  const work = hashLink(s.gateway?.origin, "#work");
137
145
  if (!work)
138
- return ["Run: passport status"];
139
- return [...wrap("Next: ask your agent to do something. Its work shows up on Work:", s.terminal.width), work];
146
+ return [];
147
+ const step = `${lead} ask your agent to work with one of your apps, like GitHub or Railway. You'll see each step on Work:`;
148
+ return [...wrap(step, s.terminal.width), work];
140
149
  }
141
150
  /** What to do next about PATH: the step, then the command on its own line. */
142
151
  export function pathNext(line, width) {
@@ -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.30.0";
7
+ export declare const PLUGIN_PIN = "0.30.1";
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.30.0";
7
+ export const PLUGIN_PIN = "0.30.1";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.30.0";
1
+ export declare const VERSION = "0.30.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Keep in lockstep with bridge/package.json.
2
- export const VERSION = "0.30.0";
2
+ export const VERSION = "0.30.1";
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.30.0",
9
+ "version": "0.30.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.32.1"
@@ -363,15 +363,15 @@
363
363
  }
364
364
  },
365
365
  "node_modules/@hono/node-server": {
366
- "version": "2.0.12",
367
- "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.0.12.tgz",
368
- "integrity": "sha512-eWpQYr67tqJLeaSUl0Q+TquuYfUdTibpOJlUMV2FfUP7+KqCC5TufnwnlXL6mobZBJbGAYRd7ZvEBDCbLInjhg==",
366
+ "version": "2.1.5",
367
+ "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.5.tgz",
368
+ "integrity": "sha512-MgP/I06GdvsilDspMk/qmRzpk8LOUStP6jFAbSRi40W09DhoyUn+Mj7eyKICPqeYKybOjVFLVIAQzvu1bfIa7Q==",
369
369
  "license": "MIT",
370
370
  "engines": {
371
371
  "node": ">=20"
372
372
  },
373
373
  "peerDependencies": {
374
- "hono": "^4"
374
+ "hono": "^4 || ^5.0.0-0"
375
375
  }
376
376
  },
377
377
  "node_modules/@modelcontextprotocol/sdk": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
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": {