feat: prefill forked session prompt draft

This commit is contained in:
Federico Jaramillo Martinez
2026-05-21 22:56:03 +02:00
parent 2f5293a8c9
commit 9e3d272731
9 changed files with 51 additions and 8 deletions
+6 -2
View File
@@ -33,7 +33,7 @@ export interface CommandSession {
export interface CommandRuntime<TSession extends CommandSession = CommandSession> {
cwd: string;
session: TSession;
fork: (entryId: string, options?: { position?: "before" | "at" }) => Promise<{ cancelled: boolean }>;
fork: (entryId: string, options?: { position?: "before" | "at" }) => Promise<{ cancelled: boolean; selectedText?: string }>;
}
export interface CommandActiveSession<TSession extends CommandSession = CommandSession> {
@@ -96,7 +96,7 @@ export class SessionCommandService<TSession extends CommandSession = CommandSess
if (sessionHasActiveWork(active.runtime.session)) return forkActiveUnsupported("fork");
const result = await active.runtime.fork(value);
if (result.cancelled) return { type: "done", message: "Fork cancelled" };
return { type: "done", message: "Session forked", session: clientSessionFromRuntime(active.runtime) };
return { type: "done", message: "Session forked", session: clientSessionFromRuntime(active.runtime), ...promptDraft(result.selectedText) };
}
private nameSession(active: CommandActiveSession<TSession>, name: string): ClientCommandResult {
@@ -179,6 +179,10 @@ function forkActiveUnsupported(command: "fork" | "clone"): ClientCommandResult {
return { type: "unsupported", message: `Cannot ${command} while the session is active. Stop current activity before ${command === "fork" ? "forking" : "cloning"}.` };
}
function promptDraft(text: string | undefined): Partial<Pick<Extract<ClientCommandResult, { type: "done" }>, "promptDraft">> {
return text === undefined ? {} : { promptDraft: text };
}
function formatSessionStats(session: CommandSession): string {
const stats = session.getSessionStats();
return [