import { z } from 'zod'; import { PluginClient } from './plugin-client.js'; /** * Session Manager - Native IPC-based session management * * This module provides lightweight native session management using Tauri IPC. * The "session" concept is maintained for API compatibility. * * Connection Strategy: * 1. Try localhost first (most reliable for simulators/emulators/desktop) * 2. If localhost fails and a remote host is configured, try that host * 3. Return error if all connection attempts fail */ export declare const ManageDriverSessionSchema: z.ZodObject<{ action: z.ZodEnum<["start", "stop", "status"]>; host: z.ZodOptional; port: z.ZodOptional; appIdentifier: z.ZodOptional>; }, "strip", z.ZodTypeAny, { action: "status" | "start" | "stop"; host?: string | undefined; port?: number | undefined; appIdentifier?: string | number | undefined; }, { action: "status" | "start" | "stop"; host?: string | undefined; port?: number | undefined; appIdentifier?: string | number | undefined; }>; export interface SessionInfo { name: string; identifier: string | null; /** * Working directory of the host Tauri process at session-start time. * `null` when the plugin is too old to advertise it (pre-v0.11) or * when the lookup failed; in that case CWD-based routing skips this * session and falls back to default behavior. */ cwd: string | null; host: string; port: number; client: PluginClient; connected: boolean; } /** * Check if any session is currently active. * @returns true if at least one session exists */ export declare function hasActiveSession(): boolean; /** * Get a specific session by port. */ export declare function getSession(port: number): SessionInfo | null; /** * Get the default session (most recently connected). */ export declare function getDefaultSession(): SessionInfo | null; /** * Get all active sessions. */ export declare function getAllSessions(): SessionInfo[]; /** * Find the session whose `cwd` best matches `hintCwd`. * * Used to disambiguate multiple concurrent Tauri instances when the caller * did not pass an explicit appIdentifier. The "best match" is the longest * shared prefix between the hint and a session's CWD, in either direction: * * - `session.cwd === hintCwd` (exact) * - `hintCwd.startsWith(session.cwd + '/')` (TS server runs inside a * subdirectory of the host process's CWD; rare) * - `session.cwd.startsWith(hintCwd + '/')` (host process runs inside * the workspace the TS server was launched from; the common case * when VSCode opens a parent dir and moss runs from a worktree) * * Sessions whose `cwd` is null (older plugin without CWD support) are * skipped — they cannot be matched and stay eligible for the existing * "use default app" fallback in `resolveTargetApp`. * * Pure function (takes `sessions` as a parameter) so it can be unit-tested * without touching module state. * * @returns The best-matching session, or null if no session matches. */ export declare function findSessionByCwd(sessions: Iterable, hintCwd: string | null): SessionInfo | null; /** * Resolve target app from port or identifier. * Returns the appropriate session based on the routing logic. * * Order of precedence: * 1. Explicit `portOrIdentifier` (port number or bundle id) * 2. CWD match via `findSessionByCwd` against `MCP_BRIDGE_CWD` or * `process.cwd()` — lets each MCP client target the Tauri instance * running in its own workspace/worktree without manual routing * 3. The default app (most-recently-connected) */ export declare function resolveTargetApp(portOrIdentifier?: string | number): SessionInfo; /** * Manage session lifecycle (start, stop, or status). * * Connection strategy for 'start': * 1. Try localhost:{port} first (most reliable for simulators/emulators/desktop) * 2. If localhost fails AND a different host is configured, try {host}:{port} * 3. If both fail, try auto-discovery on localhost * 4. Return error if all attempts fail * * @param action - 'start', 'stop', or 'status' * @param host - Optional host address (defaults to env var or localhost) * @param port - Optional port number (defaults to 9223) * @param appIdentifier - Optional app identifier for 'stop' action (port or bundle ID) * @returns For 'start'/'stop': A message string describing the result. * For 'status': A JSON string with connection details */ export declare function manageDriverSession(action: 'start' | 'stop' | 'status', host?: string, port?: number, appIdentifier?: string | number): Promise;