feat(orchestration): import an existing Claude Code or Codex session by ID #4617
ClosedBil0000(GitHub profile, opens in a new tab)wants to merge 13 commits into
main fromrefs/pull/4617/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/ImportSessionDialog.tsx lines 140 to 143Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +121,21 @@121+ }122+123+ let projectId = session.projectId ?? projectRef.projectId;124+ if (session.projectId === null && session.workspaceRoot !== null) {125+ const createdProjectId = newProjectId();126+ const createResult = await createProject({127+ environmentId: projectRef.environmentId,128+ input: {129+ projectId: createdProjectId,130+ title: inferProjectTitleFromPath(session.workspaceRoot),131+ workspaceRoot: session.workspaceRoot,132+ defaultModelSelection: selectedOption.modelSelection,133+ },134+ });135+ if (createResult._tag === "Failure") {136+ return stopImporting(137+ failureMessage(createResult, `Could not add ${session.workspaceRoot} as a project.`),138+ );139+ }140+ projectId = createdProjectId;141+ }apps/server/src/orchestration/importThread.ts line 143OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +123,21 @@123+ const snapshot = yield* providerService124+ .readThread(input.threadId)125+ .pipe(126+ Effect.mapError(127+ importFailure(`Could not read the transcript for Codex thread '${input.externalId}'.`),128+ ),129+ );130+ const snapshotWorkspaceRoot = snapshot.workspaceRoot?.trim() ?? "";131+ if (snapshotWorkspaceRoot.length > 0 && snapshotWorkspaceRoot !== input.workspaceRoot) {132+ return yield* new OrchestrationImportThreadError({133+ message: `Codex thread '${input.externalId}' ran in ${snapshotWorkspaceRoot}, not in ${input.workspaceRoot}. Import it from a thread in that project.`,134+ });135+ }136+ return mapCodexThreadSnapshot({137+ threadId: input.threadId,138+ importedAt: transcriptTimestamp(snapshot.lastActivityAtMs) ?? input.importedAt,139+ snapshot,140+ });141+ });142+143+ const deletingCreatedThreadOnFailure = <A, E, R>(apps/web/src/components/CommandPalette.logic.ts line 403Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -368,0 +383,21 @@383+ readonly modelSelection: ModelSelection;384+}385+386+const IMPORT_SESSION_PROVIDERS = [387+ {388+ driverKind: "claudeAgent",389+ label: "Claude Code",390+ fieldLabel: "Session ID",391+ placeholder: "0de413a1-1796-43c7-9abf-967c5aedd890",392+ hint: "Run /status inside a Claude Code session to copy its id, or pick one from claude --resume.",393+ },394+ {395+ driverKind: "codex",396+ label: "Codex",397+ fieldLabel: "Thread ID",398+ placeholder: "019a2f8c-4e1b-7c3d-9f10-2b6a5d8e4c77",399+ hint: "Run codex resume to list thread ids.",400+ },401+] as const satisfies ReadonlyArray<Omit<ImportSessionProviderOption, "modelSelection">>;402+403+export function buildImportSessionProviderOptions(
- apps/server/src/orchestration/importThread.ts lines 36 to 37OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +17,21 @@17+import * as Effect from "effect/Effect";18+import * as Option from "effect/Option";19+20+import type { ProviderServiceShape } from "../provider/Services/ProviderService.ts";21+import { mapClaudeSessionMessages, mapCodexThreadSnapshot } from "./importedMessages.ts";22+import { mapProviderSessionStatusToOrchestrationStatus } from "./Layers/ProviderCommandReactor.ts";23+import type { OrchestrationEngineShape } from "./Services/OrchestrationEngine.ts";24+import type { ProjectionSnapshotQueryShape } from "./Services/ProjectionSnapshotQuery.ts";25+26+const IMPORTED_THREAD_TITLE_MAX_CHARS = 120;27+28+type ImportableDriver = "claudeAgent" | "codex";29+30+function isImportableDriver(driver: string): driver is ImportableDriver {31+ return driver === "claudeAgent" || driver === "codex";32+}33+34+const nowIso = Effect.map(DateTime.now, DateTime.formatIso);35+36+const importFailure = (message: string) => (cause: unknown) =>37+ new OrchestrationImportThreadError({ message, cause });
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
f31aa5e6-4472-4e7b-ae0f-82abb58d09dbYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share