feat(server): package and apply a thread's git work #16734
Closedjuliusmarmingewants to merge 1 commit into
t3code/peer/thread-import fromt3code/peer/handoff-gitopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
- apps/server/src/peer/handoff/HandoffGit.ts line 98OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +78,21 @@78+79+const handoffRef = (handoffId: string, name: string) => `refs/t3code/handoff/${handoffId}/${name}`;80+81+const make = Effect.gen(function* () {82+ const processes = yield* VcsProcess.VcsProcess;83+ const fileSystem = yield* FileSystem.FileSystem;84+ const path = yield* Path.Path;85+86+ const git = (87+ cwd: string,88+ args: ReadonlyArray<string>,89+ options: { readonly env?: NodeJS.ProcessEnv; readonly allowNonZeroExit?: boolean } = {},90+ ) =>91+ processes92+ .run({93+ operation: "HandoffGit",94+ command: "git",95+ cwd,96+ args,97+ timeoutMs: 120_000,98+ ...(options.env === undefined ? {} : { env: { ...process.env, ...options.env } }),apps/server/src/peer/handoff/HandoffGit.ts lines 182 to 188Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +90,21 @@90+ ) =>91+ processes92+ .run({93+ operation: "HandoffGit",94+ command: "git",95+ cwd,96+ args,97+ timeoutMs: 120_000,98+ ...(options.env === undefined ? {} : { env: { ...process.env, ...options.env } }),99+ ...(options.allowNonZeroExit === undefined100+ ? {}101+ : { allowNonZeroExit: options.allowNonZeroExit }),102+ })103+ .pipe(104+ Effect.mapError(105+ (error) =>106+ new HandoffGitError({107+ reason: "git_failed",108+ message: `git ${args[0]} failed: ${error.message}`,109+ }),110+ ),apps/server/src/peer/handoff/HandoffGit.ts lines 356 to 357Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +266,21 @@266+ if (checkedOut) branch = null;267+ } else {268+ yield* git(input.repoRoot, ["update-ref", ref, input.tip, ""]);269+ undo.push(git(input.repoRoot, ["update-ref", "-d", ref]).pipe(Effect.ignore));270+ }271+ }272+ yield* git(273+ input.repoRoot,274+ branch === null275+ ? ["worktree", "add", "--detach", input.worktreePath, input.tip]276+ : ["worktree", "add", input.worktreePath, branch],277+ );278+ undo.push(279+ git(input.repoRoot, ["worktree", "remove", "--force", input.worktreePath]).pipe(280+ Effect.ignore,281+ ),282+ );283+ // The working tree as it was, untracked files included, then the284+ // index back on the tip so the changes show as uncommitted.285+ yield* git(input.worktreePath, ["checkout", "--no-overlay", input.snapshot, "--", "."]);286+ yield* git(input.worktreePath, ["reset", "--quiet", input.tip]);
- apps/server/src/peer/handoff/HandoffGit.ts lines 201 to 201OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +181,21 @@181+ const ok = (cwd: string, args: ReadonlyArray<string>) =>182+ git(cwd, args, { allowNonZeroExit: true }).pipe(Effect.map((result) => result.exitCode === 0));183+184+ const pack: HandoffGit["Service"]["pack"] = (input) =>185+ Effect.gen(function* () {186+ if (!(yield* ok(input.cwd, ["rev-parse", "--verify", "HEAD"]))) {187+ return yield* new HandoffNotARepositoryError({ cwd: input.cwd });188+ }189+ const tip = yield* out(input.cwd, ["rev-parse", "HEAD"]);190+ const branchName = yield* git(input.cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"], {191+ allowNonZeroExit: true,192+ });193+ const branch = branchName.exitCode === 0 ? branchName.stdout.trim() : null;194+ const gitDir = yield* out(input.cwd, ["rev-parse", "--path-format=absolute", "--git-dir"]);195+ const indexPath = path.join(gitDir, `t3-handoff-index-${input.handoffId}`);196+ // The working tree as a commit on top of the tip, in a private index so197+ // the user's staging is untouched. Ignored files stay behind.198+ const snapshot = yield* Effect.gen(function* () {199+ const env = { GIT_INDEX_FILE: indexPath, ...IDENTITY };200+ yield* git(input.cwd, ["read-tree", "HEAD"], { env });201+ yield* git(input.cwd, ["add", "--all", "--", "."], { env });apps/server/src/peer/handoff/HandoffGit.ts lines 319 to 319OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +299,21 @@299+ .split("\n")300+ .some((line) => line === `branch ${ref}`);301+ if (checkedOut && current !== input.tip) {302+ return yield* new HandoffBranchCheckedOutError({ branch });303+ }304+ if (current !== input.tip) {305+ if (306+ !(yield* ok(input.repoRoot, ["merge-base", "--is-ancestor", current, input.tip]))307+ ) {308+ return yield* new HandoffBranchDivergedError({ branch });309+ }310+ // Compare-and-swap: fails if the branch moved since it was read.311+ yield* git(input.repoRoot, ["update-ref", ref, input.tip, current]);312+ undo.push(313+ git(input.repoRoot, ["update-ref", ref, current, input.tip]).pipe(Effect.ignore),314+ );315+ }316+ if (checkedOut) branch = null;317+ } else {318+ yield* git(input.repoRoot, ["update-ref", ref, input.tip, ""]);319+ undo.push(git(input.repoRoot, ["update-ref", "-d", ref]).pipe(Effect.ignore));
juliusmarminge assignedjuliusmarminge
juliusmarminge closed this
juliusmarminge reopened this
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
tanstack-source added labelsfeature
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
f73f29d· Source CI: failureScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.