pi-plus-sdk 0.2.28 → 0.2.29

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/CHANGELOG.md CHANGED
@@ -12,6 +12,7 @@
12
12
  - Session recap failures are re-exported from the SDK surface (`packages/plus/src/extensions/recap/events.ts`): `subscribeToRecapFailures(listener)` — fires with a `{ sessionId, reason: "timeout" | "error", message }` `RecapFailure` after every failed auto-title call (the one-off recap LLM call after the first prompt or a compaction hitting its 30s timeout, or a provider error), returning an unsubscribe function — plus the `RecapFailure`/`RecapFailureReason` types. A host (e.g. the pi-plus desktop) can show its own "session name not set" indicator or trigger a retry without polling. In-process only. Hosts that wire `PlusUIDialogHandlers.notify` via `createPlusUIContext` also receive the failure as a transcript warning through the notify bridge, since the TUI warning that replaced the old stderr dump routes through the same `ui.notify`.
13
13
  - `/plan <prompt>` in the plan extension (shared core): any argument other than the `show` / `edit` subcommands turns plan mode on (when off) and forwards the text to the model as a user message (queued as steering while the agent is streaming).
14
14
  - The plan review dialog renders the plan as markdown instead of raw text (shared core, `packages/plus/src/extensions/plan/component.ts`): `ExitPlanMode` presents the plan file in a scrollable rendered-markdown view with the three Claude Code choices — Approve and proceed / Stay in plan mode / Edit plan — driven by ↑↓/j/k + enter, digit keys 1-3, or esc to stay (a plain-text `ui.select` remains the fallback for RPC / headless hosts). `/plan show` reuses the same view read-only, replacing the raw `ui.notify` dump.
15
+ - MCP server management is re-exported from the SDK surface (`src/mcp.ts`): the programmatic form of `pi mcp` for hosts (pi-plus disables the TUI `/mcp` commands). Config CRUD on the two files pi loads — `listMcpServers` (merged global `<agentDir>/mcp.json` + trusted-project `<cwd>/.pi/mcp.json`, never throws on a broken file), `addMcpServer` (validates via `validateMcpServer`, refuses project writes when untrusted), `removeMcpServer`, and `updateMcpServer` (`enabled`/`exposure` patches; auto-scope writes the file defining/overriding the entry, `scope: "project"` creates an override, extension-registered servers are rejected). `checkMcpServers` connects to every enabled server in parallel and reports state (`connected`/`needs-auth`/`failed`/`disabled`), namespaced tools, per-tool exposure, and errors like `pi mcp list`. `loginMcpServer` runs pi's OAuth authorization-code + loopback-callback flow (host supplies `openUrl`; optional `promptForRedirectUrl` for remote hosts; 5-minute default deadline, `McpSignInCancelledError` on abort/timeout), `logoutMcpServer` drops a server's stored credentials, and `listMcpCredentials` summarizes `<agentDir>/mcp-auth.json` without secret material. All entries take `cwd`/`agentDir`/`projectTrusted` and reuse pi's own MCP runtime (`extensions/mcp/*`) — no duplicated connection or credential logic.
15
16
 
16
17
  ### Fixed
17
18
 
package/README.md CHANGED
@@ -55,6 +55,14 @@ await session.prompt("Review this repository");
55
55
  explicit `cwd`/`agentDir` (or a caller-owned `SettingsManager`) plus `projectTrusted`
56
56
  and an `onProgress` callback; project-scope (`local`) writes are refused by the
57
57
  underlying manager when the project is not trusted.
58
+ - MCP server management ships as a library (`src/mcp.ts`): `listMcpServers`,
59
+ `addMcpServer`, `removeMcpServer`, and `updateMcpServer` are the programmatic form of
60
+ `pi mcp`'s config CRUD (the global `<agentDir>/mcp.json`, or the trusted project's
61
+ `<cwd>/.pi/mcp.json` via `local`/`scope`); `validateMcpServer` checks an entry without
62
+ writing it; `checkMcpServers` reports each server's connection state, tools, and errors
63
+ like `pi mcp list`; and `loginMcpServer`/`logoutMcpServer`/`listMcpCredentials` run pi's
64
+ OAuth sign-in (browser `openUrl` callback, loopback redirect) and credential management.
65
+ pi-plus disables the TUI `/mcp` commands, so this is the MCP management entry for hosts.
58
66
  - Provider login ships as a library (`src/auth.ts`): `loginProvider(providerId, { agentDir?, interaction?, signal?, method? })`
59
67
  runs pi's model-runtime login flow (OAuth login page / API-key setup — the same
60
68
  flow `pipi profile add <name> -p <provider>` and the `--sign-in` flag on
package/api.d.ts CHANGED
@@ -25,7 +25,10 @@ import type {
25
25
  ExtensionError,
26
26
  ExtensionUIContext,
27
27
  InlineExtension,
28
+ LoadedMcpConfig,
28
29
  LoadExtensionsResult,
30
+ McpExposure,
31
+ McpServerConfig,
29
32
  PromptTemplate,
30
33
  ResourceDiagnostic,
31
34
  SessionInfo,
@@ -424,6 +427,146 @@ export declare function updatePackages(source?: string, options?: PlusPackageMai
424
427
  */
425
428
  export declare function clearExtensionCache(): void;
426
429
 
430
+ // ---------------------------------------------------------------------------
431
+ // MCP server maintenance — the programmatic equivalent of `pi mcp
432
+ // list/add/remove/login/logout`. pi-plus disables the TUI's /mcp commands, so
433
+ // hosts (desktop frontends, IDE adapters) manage MCP servers through these
434
+ // entries: config CRUD on the same two files pi loads (<agentDir>/mcp.json and
435
+ // a trusted project's <cwd>/.pi/mcp.json), live status checks, and the OAuth
436
+ // sign-in/out flow — all reusing pi's own MCP runtime. Re-exported from
437
+ // packages/plus-api/src/mcp.ts; the runtime bundle inlines the module.
438
+ // ---------------------------------------------------------------------------
439
+
440
+ /**
441
+ * Copy of the type from packages/coding-agent/src/extensions/mcp/config.ts
442
+ * (not exported by the upstream barrel). Only presentation keys are patchable;
443
+ * connection config changes go through addMcpServer.
444
+ */
445
+ export interface McpServerConfigPatch {
446
+ enabled?: boolean | undefined;
447
+ exposure?: McpExposure | undefined;
448
+ }
449
+
450
+ /** Host options locating the two MCP config files. */
451
+ export interface PlusMcpOptions {
452
+ /** Project root whose `.pi/mcp.json` participates. Defaults to `process.cwd()`. */
453
+ cwd?: string;
454
+ /** Pi agent directory holding the global `mcp.json`. Defaults to `getAgentDir()`. */
455
+ agentDir?: string;
456
+ /** Whether the project may contribute local MCP config. Defaults to true. */
457
+ projectTrusted?: boolean;
458
+ }
459
+
460
+ /** Options for writes choosing between the global and the project file. */
461
+ export interface PlusMcpEditOptions extends PlusMcpOptions {
462
+ /** true targets `<cwd>/.pi/mcp.json`; false/undefined `<agentDir>/mcp.json`. */
463
+ local?: boolean;
464
+ }
465
+
466
+ /** Options for updates that need to find the file actually defining the server. */
467
+ export interface PlusMcpUpdateOptions extends PlusMcpOptions {
468
+ /**
469
+ * Where to write the patch. Omitted: the file that defines or overrides the
470
+ * server. "project" writes/creates a project override; "user" forces the
471
+ * global file.
472
+ */
473
+ scope?: "user" | "project";
474
+ }
475
+
476
+ /** Absolute paths of the two mcp.json files for these options. */
477
+ export declare function getMcpConfigPaths(options?: PlusMcpOptions): { global: string; project: string };
478
+ /** Merged MCP config pi would start a session with; broken files report in `errors`, never throw. */
479
+ export declare function listMcpServers(options?: PlusMcpOptions): LoadedMcpConfig;
480
+ /** Validate a raw mcp.json entry pi's way without writing it: config or error string. */
481
+ export declare function validateMcpServer(name: string, raw: unknown): McpServerConfig | string;
482
+ /** Add or replace a server in the scope's mcp.json (validated first; invalid configs throw). */
483
+ export declare function addMcpServer(
484
+ name: string,
485
+ config: McpServerConfig,
486
+ options?: PlusMcpEditOptions,
487
+ ): { replaced: boolean; path: string };
488
+ /** Remove a server from the scope's mcp.json. Does not touch OAuth credentials. */
489
+ export declare function removeMcpServer(name: string, options?: PlusMcpEditOptions): { removed: boolean; path: string };
490
+ /** Patch `enabled`/`exposure` of an existing server without touching its connection config. */
491
+ export declare function updateMcpServer(
492
+ name: string,
493
+ patch: McpServerConfigPatch,
494
+ options?: PlusMcpUpdateOptions,
495
+ ): { path: string };
496
+
497
+ /** One server as `pi mcp list` reports it: static config plus live state when enabled. */
498
+ export interface McpServerStatus {
499
+ name: string;
500
+ scope: "global" | "project" | "extension";
501
+ /** File defining the entry. */
502
+ source: string;
503
+ /** File overriding it, when a project override exists. */
504
+ override?: string;
505
+ enabled: boolean;
506
+ /** Server-level exposure; pi defaults to "codemode". */
507
+ exposure: string;
508
+ /** `"stdio"` (command line) or the server URL. */
509
+ transport: string;
510
+ /** "disabled" when not enabled; otherwise the runtime state after a connect attempt. */
511
+ state: "disabled" | "connecting" | "connected" | "disconnected" | "needs-auth" | "failed" | "closed";
512
+ /** Registered tool names (namespaced), empty unless connected. */
513
+ tools: string[];
514
+ /** Per-tool exposure overrides differing from `exposure`. */
515
+ toolExposure?: Record<string, string>;
516
+ resources?: boolean;
517
+ error?: string;
518
+ }
519
+
520
+ /** Result of checkMcpServers. */
521
+ export interface PlusMcpCheckResult {
522
+ servers: McpServerStatus[];
523
+ /** Config-load problems (unreadable file, invalid entries). */
524
+ errors: string[];
525
+ /** Set when the project config exists but the project is not trusted. */
526
+ note?: string;
527
+ }
528
+
529
+ /** Connect to every enabled server in parallel and report state/tools, like `pi mcp list`. */
530
+ export declare function checkMcpServers(options?: PlusMcpOptions): Promise<PlusMcpCheckResult>;
531
+
532
+ /** Options for loginMcpServer. */
533
+ export interface PlusMcpLoginOptions extends PlusMcpOptions {
534
+ /** Open the authorization URL in the user's browser (hosts own shell access). */
535
+ openUrl: (url: string) => void;
536
+ /**
537
+ * Ask the user to paste the redirected URL when the loopback callback cannot
538
+ * reach this machine. Omitted: sign-in waits for the callback only.
539
+ */
540
+ promptForRedirectUrl?: (signal: AbortSignal) => Promise<string | undefined>;
541
+ /** Whole-flow timeout in ms. Defaults to 300000, like `pi mcp login`. */
542
+ timeoutMs?: number;
543
+ /** Cancels the flow with McpSignInCancelledError. */
544
+ signal?: AbortSignal;
545
+ }
546
+
547
+ /** Default deadline for `pi mcp login`-equivalent sign-in. */
548
+ export declare const DEFAULT_MCP_LOGIN_TIMEOUT_MS: number;
549
+ /**
550
+ * Run pi's OAuth sign-in for one configured server. An already-authenticated
551
+ * server resolves immediately; `needs-auth` opens `openUrl` and waits for the
552
+ * loopback callback. Returns the connected tool names; tokens are stored in
553
+ * `<agentDir>/mcp-auth.json`.
554
+ */
555
+ export declare function loginMcpServer(name: string, options: PlusMcpLoginOptions): Promise<string[]>;
556
+ /** Remove a server's stored OAuth credentials; false when it never signed in. */
557
+ export declare function logoutMcpServer(name: string, options?: PlusMcpOptions): boolean;
558
+
559
+ /** One stored OAuth credential record, keyed like `<agentDir>/mcp-auth.json`. */
560
+ export interface McpCredentialInfo {
561
+ key: string;
562
+ hasClientInformation: boolean;
563
+ hasTokens: boolean;
564
+ tokensExpireAt?: number;
565
+ }
566
+
567
+ /** Summarize `<agentDir>/mcp-auth.json` without secret material; empty when absent. */
568
+ export declare function listMcpCredentials(options?: PlusMcpOptions): McpCredentialInfo[];
569
+
427
570
  export interface CreatePlusAgentSessionOptions extends CreateAgentSessionOptions {
428
571
  extensionFactories?: InlineExtension[];
429
572
  ui?: PlusUIDialogHandlers;