import type { AgentSession } from "./agent-session.js"; import type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from "./agent-session-services.js"; import type { ReplacedSessionContext, SessionStartEvent } from "./extensions/index.js"; import type { CreateAgentSessionResult } from "./sdk.js"; import { SessionManager } from "./session-manager.js"; /** * Result returned by runtime creation. * * The caller gets the created session, its cwd-bound services, and all * diagnostics collected during setup. */ export interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult { services: AgentSessionServices; diagnostics: AgentSessionRuntimeDiagnostic[]; } /** * Creates a full runtime for a target cwd and session manager. * * The factory closes over process-global fixed inputs, recreates cwd-bound * services for the effective cwd, resolves session options against those * services, and finally creates the AgentSession. */ export type CreateAgentSessionRuntimeFactory = (options: { cwd: string; agentDir: string; sessionManager: SessionManager; sessionStartEvent?: SessionStartEvent; }) => Promise; /** * Thrown when `/cd` is pointed at something that is not a usable directory. */ export declare class ChangeDirectoryError extends Error { readonly path: string; constructor(message: string, path: string); } /** * Thrown when /import references a JSONL file path that does not exist. */ export declare class SessionImportFileNotFoundError extends Error { readonly filePath: string; constructor(filePath: string); } /** * Owns the current AgentSession plus its cwd-bound services. * * Session replacement methods tear down the current runtime first, then create * and apply the next runtime. If creation fails, the error is propagated to the * caller. The caller is responsible for user-facing error handling. */ export declare class AgentSessionRuntime { private _session; private _services; private readonly createRuntime; private _diagnostics; private _modelFallbackMessage?; private rebindSession?; private beforeSessionInvalidate?; constructor(_session: AgentSession, _services: AgentSessionServices, createRuntime: CreateAgentSessionRuntimeFactory, _diagnostics?: AgentSessionRuntimeDiagnostic[], _modelFallbackMessage?: string | undefined); get services(): AgentSessionServices; get session(): AgentSession; get cwd(): string; get diagnostics(): readonly AgentSessionRuntimeDiagnostic[]; get modelFallbackMessage(): string | undefined; setRebindSession(rebindSession?: (session: AgentSession) => Promise): void; /** * Set a synchronous callback that runs after `session_shutdown` handlers finish * but before the current session is invalidated. * * This is for host-owned UI teardown that must not yield to the event loop, * such as detaching extension-provided TUI components before the old extension * context becomes stale. */ setBeforeSessionInvalidate(beforeSessionInvalidate?: () => void): void; private emitBeforeSwitch; private emitBeforeFork; private teardownCurrent; private apply; private finishSessionReplacement; switchSession(sessionPath: string, options?: { cwdOverride?: string; withSession?: (ctx: ReplacedSessionContext) => Promise; }): Promise<{ cancelled: boolean; }>; newSession(options?: { parentSession?: string; setup?: (sessionManager: SessionManager) => Promise; withSession?: (ctx: ReplacedSessionContext) => Promise; }): Promise<{ cancelled: boolean; }>; /** * Move the whole runtime to another directory without leaving the process. * * Everything cwd-bound is rebuilt for the new root — tools, context files * (AGENTS.md and friends), project settings, extensions, skills, agents, the * MCP server set — which is exactly why this cannot just reassign a string: * those services are constructed per cwd and a half-moved runtime would run * the new repo's code against the old repo's rules. * * Sessions are stored per project, so the move starts a fresh session in the * target directory rather than dragging the current transcript across. The * old session is already persisted; `/resume` in the old directory reopens * it. A session directory the user pinned explicitly (`--session-dir`, the * env var, or the setting) is *not* cwd-derived and is carried over as-is. * * @throws {ChangeDirectoryError} When the target is missing or not a directory. */ changeDirectory(targetCwd: string): Promise<{ cancelled: boolean; cwd: string; }>; fork(entryId: string, options?: { position?: "before" | "at"; withSession?: (ctx: ReplacedSessionContext) => Promise; }): Promise<{ cancelled: boolean; selectedText?: string; }>; /** * Import a session JSONL file and switch runtime state to the imported session. * * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`. * @throws {SessionImportFileNotFoundError} When the input path does not exist. * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided. */ importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean; }>; dispose(): Promise; } /** * Create the initial runtime from a runtime factory and initial session target. * * The same factory is stored on the returned AgentSessionRuntime and reused for * later /new, /resume, /fork, and import flows. */ export declare function createAgentSessionRuntime(createRuntime: CreateAgentSessionRuntimeFactory, options: { cwd: string; agentDir: string; sessionManager: SessionManager; sessionStartEvent?: SessionStartEvent; }): Promise; export { type AgentSessionRuntimeDiagnostic, type AgentSessionServices, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionServicesOptions, createAgentSessionFromServices, createAgentSessionServices, } from "./agent-session-services.js"; //# sourceMappingURL=agent-session-runtime.d.ts.map