UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

131 lines • 8.58 kB
import type { ExtensionAPI, ExtensionUIContext, SessionShutdownEvent, SessionStartEvent } from "../../types.ts"; import type { McpServerDeclaredConfig } from "./config-schema.ts"; import type { ServerConnection } from "./connection.ts"; import type { McpServerExposureStatus } from "./expose/status.ts"; import { McpOutputArtifacts } from "./guard/output-guard.ts"; import type { McpResourceServer } from "./resources.ts"; import type { McpDisposeReason, McpServerSnapshot, McpServiceSnapshot, McpSessionContext, McpSessionOptions, McpWireAuthStatus, McpWireStatusSnapshot } from "./service-types.ts"; import type { SkillServerRegistration } from "./skills.ts"; import { type McpStartupRaceResult } from "./startup-race.ts"; type McpElicitationUi = Pick<ExtensionUIContext, "input" | "select" | "confirm"> & Partial<Pick<ExtensionUIContext, "notify">>; type McpToolRegistrar = Pick<ExtensionAPI, "getActiveTools" | "setActiveTools" | "registerTool"> & Partial<Pick<ExtensionAPI, "events">>; export { registerToolsPreservingActiveSet } from "./active-set.ts"; export declare class McpService { #private; /** `servesManySessions` marks the process-wide service every classic session attaches to. */ constructor(options?: Pick<McpSessionOptions, "mcpRegistry"> & { readonly servesManySessions?: boolean; }); attachSession(event: SessionStartEvent, ctx: McpSessionContext, _pi?: McpToolRegistrar, options?: McpSessionOptions): Promise<void>; /** * A further execution scope of the runtime that owns `pi` joins its binding (brain/hand S16c) without a rebind, a * config re-sync or an abort; only its own wire status is published. A `session_start` drops every joined scope. */ attachScope(ctx: McpSessionContext, pi: McpToolRegistrar): Promise<void>; /** * Release the binding of the session that owns `pi` (#2514). The shared connections keep * serving every other live session; once none is left, `disposeReason` disposes the service * the way that last session's own exit would. */ releaseSession(pi: object, disposeReason?: McpDisposeReason): Promise<void>; /** * Register skill-declared MCP servers (todo 37). Skill servers are forced * into search mode with no directTools, so their catalogs register with * ZERO active tools until activateSkillMcpTools reveals them. A name * collision with a system-configured server keeps the system config and * returns a warning (system wins). `${VAR}` expansion follows the declaring * skill's trust (skill-server.ts); each trust warning is returned once per session. */ attachSkillMcpServers(declared: ReadonlyMap<string, SkillServerRegistration>, pi?: object): Promise<string[]>; /** Registered searchable catalog (mapped name + server-side tool name), * used by the skills loader to compute activation targets. */ getTierBSearchable(pi?: object): ReadonlyArray<{ name: string; toolName: string; server: string; }>; /** Connected servers that list prompts (todo 40), for slash registration. */ getMcpPromptServers(pi?: object): readonly import("./prompts.ts").McpPromptServer[]; /** Connected servers that list resources (todo 39), for mention expansion. */ getMcpResourceServers(pi?: object): readonly McpResourceServer[]; /** Subscribe to completed catalog registrations. Consumers must inspect the * resulting snapshot because tool, resource, and prompt catalogs can become * available in different startup-race generations. */ onMcpRegistrationChanged(listener: () => void): () => void; /** * Await the startup connects the race backgrounded, bounded by `timeoutMs`. * `attachSession` resolves at the race deadline, so code that must OBSERVE the * attach's catalog (tests, and hosts that watch the attach from outside; the * first turn itself awaits the attach promise in `before_agent_start`) calls * this. A `"timeout"` result means some connects are still running. * * An attach (or re-sync) still on the queue has not handed its backgrounded connects over yet, so the queue is * awaited first, within the same budget: an early call must never read an empty pending set as settled (senpi#4027). */ whenAttachSettled(timeoutMs?: number): Promise<McpStartupRaceResult>; /** Subscribe to live MCP inventory transitions for session-scoped hosts. */ onWireStatusChanged(listener: McpWireStatusListener): () => void; /** Refresh and return the current session-owned MCP wire inventory. */ refreshWireStatusSnapshot(sessionId?: string): Promise<McpWireStatusSnapshot>; /** Reveal skill-owned tools (todo 37): activation is effective the next * turn, exactly like an tool_search promotion. Unknown names are ignored. */ activateSkillMcpTools(names: readonly string[], pi?: object): void; handleSessionShutdown(event: SessionShutdownEvent): Promise<void>; dispose(reason: McpDisposeReason): Promise<void>; getMcpOutputArtifacts(): McpOutputArtifacts; isDisposed(): boolean; getConnection(name: string): ServerConnection | undefined; reconnectServer(name: string): Promise<void>; /** * The lifecycle-only server snapshots. Without a session id these still list the merged config of all live * sessions, as the /mcp command and the manager TUI expect. With one, only the servers that session declares * (senpi#3001): a caller that can name its session gets no peer data. */ getServerSnapshots(sessionId?: string): McpServerSnapshot[]; getLogLines(name: string, maxLines: number): string[]; getServerExposureStatus(name: string): Promise<McpServerExposureStatus>; recordCall(name: string, elapsedMs: number, failed: boolean): void; getSnapshot(): McpServiceSnapshot; /** * Return the attach-time inventory captured for one session. This is the * handoff consumed by RPC's session-owned adapter; it deliberately * does not expose or derive from the lifecycle-only server snapshots. * A caller that passes no session id gets no peer data while more than * one session is live (senpi#3001): with a single live session the stored * snapshot is that session's own, so the id-less read keeps working. */ getWireStatusSnapshot(sessionId?: string): McpWireStatusSnapshot; /** Route compatibility callers through the shared ownership-aware scanner. */ rehydrateActiveToolsFromHistory(messages: readonly unknown[], pi?: object): string[]; /** Shared service memoization keeps this scan once-per-catalog-generation. */ maybeRehydrateFromHistory(messages: readonly unknown[], pi?: object): string[]; setMcpInstructions(instructions: string): void; getMcpInstructions(): string; setMcpElicitationUiProvider(provider: (() => McpElicitationUi | undefined) | undefined): void; bindMcpMrtrPresentation(pi: object, ui: ExtensionUIContext, sessionManager?: object): void; getMcpElicitationUi(): McpElicitationUi | undefined; isMcpPromptCommandRegistered(name: string): boolean; markMcpPromptCommandRegistered(name: string): void; beginInteractiveAuth(serverName: string): boolean; endInteractiveAuth(serverName: string): void; getPendingAuth(): Map<string, import("./auth/oauth-provider.ts").McpOAuthProvider>; getAuthTarget(name: string): { config: McpServerDeclaredConfig; agentDir?: string; env?: Record<string, string | undefined>; callbackUrl?: string; } | undefined; /** Live auth status without fetching catalogs or exposing credentials. */ getServerAuthStatus(name: string): McpWireAuthStatus; getCachedInstructions(name: string): string | undefined; /** Resolved `settings.nativeToolSearch` (auto | true | false | undefined). * Drives the native provider tool-search adapter gate. */ getNativeToolSearchSetting(): "auto" | boolean | undefined; } /** `startupSettled` marks the one announcement that closes a session's startup window (senpi#4828). */ type McpWireStatusListener = (sessionId: string | undefined, snapshot: McpWireStatusSnapshot, startupSettled: boolean) => void; export declare function getMcpService(): McpService; export declare function shouldDisposeMcpService(reason: SessionShutdownEvent["reason"]): reason is McpDisposeReason; export declare function resetMcpServiceForTests(): void; export declare const MCP_DEFERRED_DISPOSE_TIMEOUT_ENV = "SENPI_MCP_DEFERRED_DISPOSE_TIMEOUT_MS"; //# sourceMappingURL=service.d.ts.map