passport-bridge 0.9.0 → 0.11.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.
Files changed (50) hide show
  1. package/README.md +174 -342
  2. package/dist/bridge.d.ts +31 -61
  3. package/dist/bridge.js +154 -313
  4. package/dist/bridgeExchange.d.ts +108 -0
  5. package/dist/bridgeExchange.js +473 -0
  6. package/dist/bridgeHeal.d.ts +61 -0
  7. package/dist/bridgeHeal.js +142 -0
  8. package/dist/bridgeLog.d.ts +2 -0
  9. package/dist/bridgeLog.js +4 -0
  10. package/dist/bridgePoller.d.ts +34 -0
  11. package/dist/bridgePoller.js +123 -0
  12. package/dist/bridgeShutdown.d.ts +37 -0
  13. package/dist/bridgeShutdown.js +77 -1
  14. package/dist/cli.js +68 -14
  15. package/dist/cliArgs.d.ts +1 -1
  16. package/dist/cliArgs.js +6 -1
  17. package/dist/cliConnect.js +6 -6
  18. package/dist/cliHook.d.ts +58 -0
  19. package/dist/cliHook.js +200 -0
  20. package/dist/cliHookClassify.d.ts +30 -0
  21. package/dist/cliHookClassify.js +354 -0
  22. package/dist/cliHookInstall.d.ts +34 -0
  23. package/dist/cliHookInstall.js +246 -0
  24. package/dist/cliHookParse.d.ts +40 -0
  25. package/dist/cliHookParse.js +325 -0
  26. package/dist/cliHookVendors.d.ts +23 -0
  27. package/dist/cliHookVendors.js +578 -0
  28. package/dist/cliOutput.js +8 -2
  29. package/dist/cliSetup.d.ts +10 -0
  30. package/dist/cliSetup.js +157 -0
  31. package/dist/cliSupport.d.ts +3 -0
  32. package/dist/completion.js +6 -2
  33. package/dist/credentialStorage.d.ts +47 -1
  34. package/dist/credentialStorage.js +231 -52
  35. package/dist/credentials.d.ts +1 -1
  36. package/dist/managedSkills.d.ts +7 -0
  37. package/dist/managedSkills.js +268 -0
  38. package/dist/managedSkillsContract.generated.d.ts +82 -0
  39. package/dist/managedSkillsContract.generated.js +32 -0
  40. package/dist/managedSkillsFiles.d.ts +23 -0
  41. package/dist/managedSkillsFiles.js +215 -0
  42. package/dist/managedSkillsIpc.d.ts +5 -0
  43. package/dist/managedSkillsIpc.js +44 -0
  44. package/dist/managedSkillsValidation.d.ts +14 -0
  45. package/dist/managedSkillsValidation.js +118 -0
  46. package/dist/passport.js +6 -2
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/npm-shrinkwrap.json +5 -5
  50. package/package.json +2 -2
package/dist/bridge.d.ts CHANGED
@@ -1,66 +1,12 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
3
+ import { type ProcessShutdown } from "./bridgeShutdown.js";
4
+ import { type TokenManager } from "./bridgeExchange.js";
5
+ import { type BridgeCredentialSource, type BridgeHealSchedule } from "./bridgeHeal.js";
3
6
  export { workspaceOfToken } from "./tokenWorkspace.js";
4
- /** Everything but the MCP protocol goes to stderr — stdout is the transport. */
5
- export declare function log(...args: unknown[]): void;
6
- /**
7
- * Shown to the AI client (and logged) when the bridge refuses to switch tenants:
8
- * the on-disk credential now belongs to a DIFFERENT workspace than this process
9
- * started serving. We fail closed rather than silently attribute activity to the
10
- * wrong workspace.
11
- */
12
- export declare const TENANT_FLIP_MESSAGE = "This machine's Passport credential now belongs to a different workspace. Reconnect this client from the Passport app.";
13
- export declare class BridgeCredentialError extends Error {
14
- readonly status: 401;
15
- constructor(status: 401);
16
- }
17
- /**
18
- * Holds the long-lived refresh token and mints short-lived access tokens
19
- * from the cloud, transparently refreshing on expiry or a 401.
20
- */
21
- export declare class TokenManager {
22
- private readonly onRotate?;
23
- private readonly coordinate?;
24
- private readonly requestTimeoutMs?;
25
- private readonly requestSignal?;
26
- private readonly fetcher;
27
- private origin;
28
- private refreshToken;
29
- private access?;
30
- private expiresAt;
31
- private inflight?;
32
- private pendingRotation?;
33
- /** The workspace this process started serving, read from its initial refresh
34
- * token. The tenant-flip guard refuses to adopt an on-disk credential whose
35
- * workspace differs from this. */
36
- private readonly homeWorkspace;
37
- private tenantFlipLogged;
38
- /**
39
- * @param onRotate durably persist a rotated refresh token before its access
40
- * token is usable. Rejection leaves the child pending for local retry.
41
- * Without it (e.g. env-only auth), the server is told not to rotate.
42
- * @param coordinate cross-process coordination for a shared profile (Cursor
43
- * runs one bridge per window): `reload` returns the freshest persisted
44
- * refresh token, `lock` serializes the exchange across processes. Without
45
- * them, a sibling process's rotation makes our in-memory token a replay —
46
- * which the server treats as theft and answers by revoking the family.
47
- */
48
- constructor(endpoint: string, refreshToken: string, onRotate?: ((next: string, previous: string) => void | Promise<void>) | undefined, coordinate?: {
49
- reload: () => string | undefined;
50
- lock: <T>(fn: () => Promise<T>) => Promise<T>;
51
- } | undefined, requestTimeoutMs?: number | undefined, requestSignal?: AbortSignal | undefined, fetcher?: typeof fetch);
52
- private assertHomeWorkspace;
53
- private settlePendingRotation;
54
- accessToken(force?: boolean): Promise<string>;
55
- /** Adopt a newly persisted credential after an interactive recovery. The
56
- * original workspace remains authoritative for this running bridge. */
57
- replaceRefreshToken(next: string): void;
58
- /** Adopt a newly persisted credential and its approved gateway endpoint. */
59
- replaceCredential(next: string, endpoint: string): void;
60
- private exchange;
61
- /** fetch wrapper that attaches the current access token and refreshes on 401. */
62
- authedFetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
63
- }
7
+ export { log } from "./bridgeLog.js";
8
+ export { BridgeCredentialError, TENANT_FLIP_MESSAGE, TokenManager, isBridgeCredentialError, type ExchangeRetryPolicy } from "./bridgeExchange.js";
9
+ export type { BridgeCredentialSource } from "./bridgeHeal.js";
64
10
  export type BridgeRecoveryFlow = {
65
11
  verifyUrl: string;
66
12
  userCode: string;
@@ -79,11 +25,35 @@ export type BridgeRunOptions = {
79
25
  /** Test hook for an in-process upstream connection. */
80
26
  connectUpstream?: (client: Client) => Promise<void>;
81
27
  recovery?: BridgeRecovery;
28
+ /** Enables self-heal from a credential another process saved. */
29
+ credentialSource?: BridgeCredentialSource;
30
+ /** Test hook for the self-heal backoff. */
31
+ healSchedule?: BridgeHealSchedule;
32
+ /** Test hook for process signal coordination. */
33
+ shutdown?: ProcessShutdown;
82
34
  };
35
+ /**
36
+ * Resolve once the client has written its first bytes (its initialize
37
+ * request), or false if stdin ends first. The chunk is pushed back so the MCP
38
+ * transport reads it unchanged. A client that spawns and kills a bridge
39
+ * before speaking therefore never makes it rotate the shared credential.
40
+ */
41
+ export declare function waitForFirstInput(stdin?: NodeJS.ReadStream): Promise<boolean>;
83
42
  /**
84
43
  * The proxy: a stdio MCP server (what the AI client talks to) that forwards
85
44
  * verbatim to the cloud gateway over Streamable HTTP. Tool definitions and
86
45
  * arguments pass through unchanged; cancellation and progress are forwarded;
87
- * a periodic re-list notifies the client when the toolset changes.
46
+ * a periodic re-list notifies the client when the toolset changes. While
47
+ * degraded it heals itself: it retries on a backoff, adopts a credential
48
+ * another process saved, and notifies the client when tools return.
88
49
  */
89
50
  export declare function runBridge(endpoint: string, tokens: TokenManager, options?: BridgeRunOptions): Promise<void>;
51
+ export type ToolSignatureDefinition = {
52
+ name: string;
53
+ description?: string;
54
+ inputSchema?: unknown;
55
+ };
56
+ /** Canonical hash of the complete visible tool definitions. Kept pure so the
57
+ * bridge can prove hashing cost independently from MCP transport latency. */
58
+ export declare function canonicalToolSignature(tools: readonly ToolSignatureDefinition[]): string;
59
+ export declare function toolSignature(client: Client, signal?: AbortSignal): Promise<string>;