History

Move worktree branch auto-rename into provider turn reactor

- Generate and rename temporary `t3code/*` worktree branches on first user turn in `ProviderCommandReactor` - Remove websocket/client branch-generation RPCs and related contract/API surface - Update Codex text-generation prompt to include attachment metadata only when attachments exist, with expanded tests

Julius Marminge committed 8 months ago

Commit 5e55aa31 parent a21095b12 files · +405 −264Browse files

Showing the changes to apps/server/src/wsServer.ts (1 of 12 files). Show all

Unified · Split

apps/server/src/wsServer.ts+0−54
@@ -54,7 +54,6 @@ import { clamp } from "effect/Number"; · 53 unmodified lines
54import { Open } from "./open";54import { Open } from "./open";
55import { ServerConfig } from "./config";55import { ServerConfig } from "./config";
56import { GitCore } from "./git/Services/GitCore.ts";56import { GitCore } from "./git/Services/GitCore.ts";
57import { TextGeneration } from "./git/Services/TextGeneration.ts";
58import { ATTACHMENTS_ROUTE_PREFIX, tryHandleProjectFaviconRequest } from "./projectFaviconRoute";57import { ATTACHMENTS_ROUTE_PREFIX, tryHandleProjectFaviconRequest } from "./projectFaviconRoute";
59 58
60/**59/**
@@ -136,31 +135,6 @@ function stripRequestTag<T extends { _tag: string }>(body: T) { · 75 unmodified lines
136 return Struct.omit(body, ["_tag"]);135 return Struct.omit(body, ["_tag"]);
137}136}
138 137
139const WORKTREE_BRANCH_PREFIX = "t3code";
140
141function buildGeneratedWorktreeBranchName(raw: string): string {
142 const normalized = raw
143 .trim()
144 .toLowerCase()
145 .replace(/^refs\/heads\//, "")
146 .replace(/['"`]/g, "");
147
148 const withoutPrefix = normalized.startsWith(`${WORKTREE_BRANCH_PREFIX}/`)
149 ? normalized.slice(`${WORKTREE_BRANCH_PREFIX}/`.length)
150 : normalized;
151
152 const branchFragment = withoutPrefix
153 .replace(/[^a-z0-9/_-]+/g, "-")
154 .replace(/\/+/g, "/")
155 .replace(/-+/g, "-")
156 .replace(/^[./_-]+|[./_-]+$/g, "")
157 .slice(0, 64)
158 .replace(/[./_-]+$/g, "");
159
160 const safeFragment = branchFragment.length > 0 ? branchFragment : "update";
161 return `${WORKTREE_BRANCH_PREFIX}/${safeFragment}`;
162}
163
164export type ServerCoreRuntimeServices =138export type ServerCoreRuntimeServices =
165 | OrchestrationEngineService139 | OrchestrationEngineService
166 | ProjectionSnapshotQuery140 | ProjectionSnapshotQuery
@@ -172,7 +146,6 @@ export type ServerRuntimeServices = · 5 unmodified lines
172 | ServerCoreRuntimeServices146 | ServerCoreRuntimeServices
173 | GitManager147 | GitManager
174 | GitCore148 | GitCore
175 | TextGeneration
176 | TerminalManager149 | TerminalManager
177 | Keybindings150 | Keybindings
178 | Open;151 | Open;
@@ -211,7 +184,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< · 32 unmodified lines
211 const terminalManager = yield* TerminalManager;184 const terminalManager = yield* TerminalManager;
212 const keybindingsManager = yield* Keybindings;185 const keybindingsManager = yield* Keybindings;
213 const git = yield* GitCore;186 const git = yield* GitCore;
214 const textGeneration = yield* TextGeneration;
215 const fileSystem = yield* FileSystem.FileSystem;187 const fileSystem = yield* FileSystem.FileSystem;
216 const path = yield* Path.Path;188 const path = yield* Path.Path;
217 189
@@ -600,32 +572,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< · 382 unmodified lines
600 return yield* git.createWorktree(body);572 return yield* git.createWorktree(body);
601 }573 }
602 574
603 case WS_METHODS.gitGenerateBranchName: {
604 const body = stripRequestTag(request.body);
605 return yield* textGeneration.generateBranchName(body);
606 }
607
608 case WS_METHODS.gitGenerateAndRenameBranch: {
609 const body = stripRequestTag(request.body);
610 const generated = yield* textGeneration.generateBranchName({
611 cwd: body.cwd,
612 message: body.message,
613 ...(body.attachments !== undefined ? { attachments: body.attachments } : {}),
614 });
615 if (!generated.branch) {
616 return { branch: null };
617 }
618 const targetBranch = buildGeneratedWorktreeBranchName(generated.branch);
619 if (targetBranch === body.oldBranch) {
620 return { branch: body.oldBranch };
621 }
622 return yield* git.renameBranch({
623 cwd: body.cwd,
624 oldBranch: body.oldBranch,
625 newBranch: targetBranch,
626 });
627 }
628
629 case WS_METHODS.gitRenameBranch: {575 case WS_METHODS.gitRenameBranch: {
630 const body = stripRequestTag(request.body);576 const body = stripRequestTag(request.body);
631 return yield* git.renameBranch(body);577 return yield* git.renameBranch(body);