import type { ChatAgentId } from "../chat-agents/index.js"; import type { WorkspaceMode } from "./session-types.js"; import type { BackgroundSession, BackgroundSessionEnd } from "@kenkaiiii/gg-protocol"; export type { BackgroundSession, BackgroundSessionEnd }; /** What the registry needs from a live session. */ export interface DetachableSession { id: string; cwd: string; mode: WorkspaceMode; chatAgent: ChatAgentId; sessionPath: () => string | undefined; /** The project it belongs to when it works in a GG-made worktree of it. */ ggWorktreeOf?: () => string | null; title?: () => string; isBusy: () => boolean; /** Something it started is still running (a dev server): kept alive, but not listed as working. */ hasLiveProcesses?: () => boolean; /** * It holds state only its memory has (a plan awaiting review, plan mode, an * open question...), which closing it would lose: kept alive, not listed. */ holdsState?: () => boolean; /** Waiting on the user (a plan to review, an open question): kept and listed as waiting. */ awaitsUser?: () => boolean; /** How its latest run ended, once it has. */ lastRunOutcome?: () => BackgroundSessionEnd["outcome"] | null; } export type KeepReason = "working" | "waiting on the user" | "background processes" | "unsaved state"; /** Why it's worth keeping with no window: working, or owning something (a running app, state only in memory) that closing it would lose. Null: close it. */ export declare function keepReason(s: DetachableSession): KeepReason | null; /** * Sessions a window switched away from mid-run, or with an app still running. They keep working with no * window, every window's sidebar lists them as working, opening one again * picks it back up, and each closes once it goes idle (`sweep`). */ export declare function createDetachedSessions(deps: { get: (id: string) => DetachableSession | undefined; close: (id: string) => void; /** `ended`: sessions that just stopped working, and how their run ended. */ announce: (sessions: BackgroundSession[], ended?: BackgroundSessionEnd[]) => void; }): { list: () => BackgroundSession[]; readonly size: number; /** Why a session would stay alive with no window (null: it would close). */ reasonFor(id: string): KeepReason | null; /** Keep a working session alive with no window. False: it's idle, close it. */ detach(id: string): boolean; /** A window opens this conversation again: hand back the live session. */ reattach(sessionPath: string, mode: WorkspaceMode, chatAgent: ChatAgentId): string | null; /** Close every detached session that has finished. */ sweep(): void; }; /** * Reattach the live session for a conversation a window reopens. Compaction * moves a conversation to a new file, so a window holding the old path is * matched through its newest checkpoint; missing it would open a second live * session on the same file and fork the history. */ export declare function reattachConversation(reg: Pick, "reattach">, sessionPath: string, mode: WorkspaceMode, chatAgent: ChatAgentId, newestCheckpoint: (sessionPath: string) => Promise): Promise;