feat(handoff): let an agent hand its thread off to a fresh one #8492
Closedmfattakhov(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/8492/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
- @@ -0,0 +87,21 @@87+ const name = flags.name.trim();88+ if (name.length === 0) {89+ return yield* new HandoffCliError({ message: "--name must not be empty." });90+ }91+92+ const httpClient = yield* HttpClient.HttpClient;93+ const response = yield* httpClient94+ .post(`${origin}${HANDOFF_HTTP_PATH}`, {95+ headers: {96+ authorization: `Bearer ${token}`,97+ },98+ body: HttpBody.jsonUnsafe({ name, summary }),99+ })100+ .pipe(101+ Effect.mapError(102+ (cause) =>103+ new HandoffCliError({104+ message: `Could not reach the d server at ${origin}: ${String(cause)}`,105+ }),106+ ),107+ );@@ -0,0 +70,21 @@70+ readonly parentThreadId: ThreadId;71+ readonly request: HandoffRequest;72+}) {73+ const orchestrationEngine = yield* OrchestrationEngineService;74+ const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;75+ const crypto = yield* Crypto.Crypto;76+77+ const randomUUID = crypto.randomUUIDv4.pipe(Effect.orDie);78+ const commandId = (tag: string) =>79+ randomUUID.pipe(Effect.map((uuid) => CommandId.make(`server:handoff-${tag}:${uuid}`)));80+81+ const parent = yield* projectionSnapshotQuery.getThreadShellById(input.parentThreadId).pipe(82+ Effect.mapError(83+ (cause) =>84+ new HandoffDispatchError({85+ parentThreadId: input.parentThreadId,86+ stage: "create",87+ cause,88+ }),89+ ),90+ );@@ -0,0 +15,21 @@15+ *16+ * @module cli/handoff17+ */18+import * as Config from "effect/Config";19+import * as Console from "effect/Console";20+import * as Effect from "effect/Effect";21+import * as Option from "effect/Option";22+import * as Schema from "effect/Schema";23+import { Command, Flag } from "effect/unstable/cli";24+import { FetchHttpClient, HttpBody, HttpClient } from "effect/unstable/http";25+26+import {27+ T3_SERVER_ORIGIN_ENV,28+ T3_SERVER_TOKEN_ENV,29+ HANDOFF_HTTP_PATH,30+ HandoffResponse,31+} from "../handoff/protocol.ts";32+33+export class HandoffCliError extends Schema.TaggedErrorClass<HandoffCliError>()("HandoffCliError", {34+ message: Schema.String,35+}) {}
- @@ -1541,3 +1550,21 @@15411550 return "hammer";15421551 }15431552 }1553+/**1554+ * Lineage row for `handoff.created` / `handoff.received` activities: the1555+ * summary plus a link into the other side of the handoff.1556+ */1557+const HandoffWorkEntryRow = memo(function HandoffWorkEntryRow({1558+ workEntry,1559+}: {1560+ workEntry: TimelineWorkEntry;1561+}) {1562+ const ctx = use(TimelineRowCtx);1563+ const linkedThreadId = workEntry.linkedThreadId;1564+1565+ return (1566+ <div className="flex items-center gap-1.5 rounded-md px-0.5 py-0.5 text-[12px] leading-5">1567+ <span className="flex size-5 shrink-0 items-center justify-center text-muted-foreground/65">1568+ <ArrowRightLeftIcon className="size-3.5" aria-hidden />1569+ </span>1570+ <span className="min-w-0 truncate font-medium text-foreground/82">{workEntry.label}</span>
- @@ -0,0 +117,21 @@117+118+ if (response.status < 200 || response.status >= 300) {119+ return yield* new HandoffCliError({120+ message: readErrorMessage(body) ?? `Handoff failed (HTTP ${response.status}).`,121+ });122+ }123+124+ const result = yield* decodeHandoffResponse(body).pipe(125+ Effect.mapError(126+ () =>127+ new HandoffCliError({128+ message: "The d server returned an unexpected handoff response.",129+ }),130+ ),131+ );132+133+ yield* Console.log(134+ [135+ `Handed off to "${result.title}"`,136+ `Thread: ${result.threadId}`,137+ `URL: ${origin}/${result.environmentId}/${result.threadId}`,@@ -412,3 +431,6 @@412431 ),413432 }));414433434+// The baseline only pins read state if it survives a reload, so a client that435+// just minted one writes it out now instead of waiting for the first change.436+persistState(useUiStateStore.getState());@@ -0,0 +118,21 @@118+ title: input.request.name,119+ modelSelection: parentThread.modelSelection,120+ runtimeMode: parentThread.runtimeMode,121+ interactionMode: parentThread.interactionMode,122+ branch: null,123+ worktreePath: null,124+ createdAt,125+ });126+127+ const deleteChildThread = Effect.suspend(() =>128+ dispatchStage("create", {129+ type: "thread.delete",130+ commandId: CommandId.make(`server:handoff-compensate:${childThreadId}`),131+ threadId: childThreadId,132+ }),133+ ).pipe(Effect.ignoreCause({ log: true }));134+135+ // No titleSeed on the seed turn: the model-chosen name IS the title, and136+ // canReplaceThreadTitle never overwrites a non-default title without a137+ // matching seed — so the auto-titler leaves it alone.138+ yield* dispatchStage("turn-start", {@@ -2087,7 +2097,8 @@20872097 directories: {20882098 buildResources: "apps/desktop/resources",20892099 },2090- // All platforms keep app.asar fully packed; electron-builder's default2091- // smart unpack extracts native libraries, which loaders find in2100+ // Beyond the Claude plugin, app.asar stays packed; electron-builder's2101+ // default smart unpack extracts native libraries, which loaders find in20922102 // app.asar.unpacked. Windows additionally ships the server tree as the20932103 // hand-packed server.asar sidecar (see WINDOWS_SERVER_ASAR_RESOURCE).2104+ asarUnpack: [...DESKTOP_ASAR_UNPACK],
- @@ -801,3 +801,8 @@801801 "!**/node_modules/node-pty/prebuilds/win32-*/**/*",802802 "!**/node_modules/node-pty/third_party/conpty/**/*",803803 ] as const;804+// The t3 Claude plugin (skills plus the `bin/t3` shim) is loaded by the805+// `claude` subprocess, which is a plain process and cannot read an asar806+// archive: packed, the plugin exists for the server but for nothing else, so807+// t3:handoff would show up in the picker and load nowhere.808+export const DESKTOP_ASAR_UNPACK = ["apps/server/dist/claude-plugin/**/*"] as const;
mfattakhov(GitHub profile, opens in a new tab) 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:
56bad244-9409-400b-a409-3a2752644107You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.