@devries-cameron20 / t3code Mirror · read-only / commits / 57ca5ccbd9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 04:30 UTC

chore(repos): sync reference repos from shallow clones (#30472)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 3, 2026 at 16:03 UTC 57ca5ccbd9096887a891ef38d47cbeffb2b8d288
2 files changed +114 -63
scripts/sync-reference-repos.test.ts
+10 -12
@@ -31,7 +31,7 @@ it.layer(NodeServices.layer)("sync-reference-repos", (it) => {
31 }),
32 );
33
34 - it.effect("plans an add for a missing subtree and a pull for an existing subtree", () =>
34 + it.effect("plans a shallow, tagless clone of the resolved ref", () =>
35 Effect.gen(function* () {
36 const fs = yield* FileSystem.FileSystem;
37 const path = yield* Path.Path;
@@ -43,19 +43,17 @@ it.layer(NodeServices.layer)("sync-reference-repos", (it) => {
43 "catalog:\n effect: 4.0.0-beta.73\n",
44 );
45
46 - const addPlan = yield* planReferenceRepoSync(effectSmol, rootDir, false);
47 - assert.equal(addPlan.action, "add");
48 - assert.deepStrictEqual(addPlan.args, [
49 - "subtree",
50 - "add",
51 - "--prefix=.repos/effect-smol",
46 + const plan = yield* planReferenceRepoSync(effectSmol, rootDir, false);
47 + assert.equal(plan.ref, "effect@4.0.0-beta.73");
48 + assert.deepStrictEqual(plan.cloneArgs, [
49 + "clone",
50 + "--quiet",
51 + "--depth=1",
52 + "--no-tags",
53 + "--single-branch",
54 + "--branch=effect@4.0.0-beta.73",
55 "https://github.com/Effect-TS/effect.git",
53 - "effect@4.0.0-beta.73",
54 - "--squash",
56 ]);
56 -
57 - yield* fs.makeDirectory(path.join(rootDir, effectSmol.prefix), { recursive: true });
58 - assert.equal((yield* planReferenceRepoSync(effectSmol, rootDir, false)).action, "pull");
57 }),
58 );
59 });
scripts/sync-reference-repos.ts
+104 -51
@@ -15,8 +15,6 @@ import { fromYaml } from "@t3tools/shared/schemaYaml";
15
16 import { referenceRepos, type ReferenceRepo } from "./lib/reference-repos.ts";
17
18 -export type ReferenceRepoSyncAction = "add" | "pull";
19 -
18 export interface ReferenceRepoSyncOptions {
19 readonly rootDir?: string | undefined;
20 readonly repoId?: string | undefined;
@@ -26,9 +24,9 @@ export interface ReferenceRepoSyncOptions {
24
25 export interface ReferenceRepoSyncPlan {
26 readonly repo: ReferenceRepo;
29 - readonly action: ReferenceRepoSyncAction;
27 readonly ref: string;
31 - readonly args: ReadonlyArray<string>;
28 + /** `git clone` arguments, without the destination directory. */
29 + readonly cloneArgs: ReadonlyArray<string>;
30 }
31
32 export class ReferenceRepoSelectionError extends Schema.TaggedError<ReferenceRepoSelectionError>()(
@@ -70,24 +68,35 @@ export class ReferenceRepoVersionResolutionError extends Schema.TaggedError<Refe
68 }
69 }
70
73 -export class ReferenceRepoGitSubtreeError extends Schema.TaggedError<ReferenceRepoGitSubtreeError>()(
74 - "ReferenceRepoGitSubtreeError",
71 +export class ReferenceRepoGitError extends Schema.TaggedError<ReferenceRepoGitError>()(
72 + "ReferenceRepoGitError",
73 {
74 operation: Schema.Literals(["spawn", "communicate", "exit"]),
75 repoId: Schema.String,
78 - action: Schema.Literals(["add", "pull"]),
79 - repository: Schema.String,
76 + command: Schema.String,
77 ref: Schema.String,
81 - rootDir: Schema.String,
82 - argumentCount: Schema.Number,
78 + cwd: Schema.String,
79 exitCode: Schema.optional(Schema.Number),
84 - stdoutLength: Schema.optional(Schema.Number),
85 - stderrLength: Schema.optional(Schema.Number),
80 + stderr: Schema.optional(Schema.String),
81 cause: Schema.optional(Schema.Defect()),
82 },
83 ) {
84 override get message(): string {
90 - return `Git subtree ${this.action} for reference repo "${this.repoId}" failed during "${this.operation}".`;
85 + const detail = this.stderr ? `: ${this.stderr.trim()}` : "";
86 + return `git ${this.command} for reference repo "${this.repoId}" at ${this.ref} failed during "${this.operation}"${detail}`;
87 + }
88 +}
89 +
90 +export class ReferenceRepoFileSystemError extends Schema.TaggedError<ReferenceRepoFileSystemError>()(
91 + "ReferenceRepoFileSystemError",
92 + {
93 + repoId: Schema.String,
94 + prefix: Schema.String,
95 + cause: Schema.Defect(),
96 + },
97 +) {
98 + override get message(): string {
99 + return `Replacing ${this.prefix} for reference repo "${this.repoId}" failed.`;
100 }
101 }
102
@@ -95,7 +104,8 @@ export type ReferenceRepoSyncError =
104 | ReferenceRepoSelectionError
105 | ReferenceRepoVersionSourceError
106 | ReferenceRepoVersionResolutionError
98 - | ReferenceRepoGitSubtreeError;
107 + | ReferenceRepoGitError
108 + | ReferenceRepoFileSystemError;
109
110 const decodeJsonSource = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
111 const decodeYamlSource = Schema.decodeEffect(fromYaml(Schema.Unknown));
@@ -197,46 +207,51 @@ export const resolveReferenceRepoRef = Effect.fn("resolveReferenceRepoRef")(func
207 return `${repo.versionTagPrefix}${version}`;
208 });
209
210 +/**
211 + * Shallow-clone the upstream ref into a temp dir and copy its files into `.repos/<id>`.
212 + * Never fetch upstream into this repo: its tags and shallow boundaries break `git fetch`.
213 + */
214 export const planReferenceRepoSync = Effect.fn("planReferenceRepoSync")(function* (
215 repo: ReferenceRepo,
216 rootDir: string,
217 latest: boolean,
218 ) {
205 - const fs = yield* FileSystem.FileSystem;
206 - const path = yield* Path.Path;
207 - const action: ReferenceRepoSyncAction = (yield* fs.exists(path.join(rootDir, repo.prefix)))
208 - ? "pull"
209 - : "add";
219 const ref = yield* resolveReferenceRepoRef(repo, rootDir, latest);
220
221 return {
222 repo,
214 - action,
223 ref,
216 - args: ["subtree", action, `--prefix=${repo.prefix}`, repo.repository, ref, "--squash"],
224 + cloneArgs: [
225 + "clone",
226 + "--quiet",
227 + "--depth=1",
228 + "--no-tags",
229 + "--single-branch",
230 + `--branch=${ref}`,
231 + repo.repository,
232 + ],
233 } satisfies ReferenceRepoSyncPlan;
234 });
235
220 -const runGit = Effect.fn("runGit")(function* (rootDir: string, plan: ReferenceRepoSyncPlan) {
236 +const runGit = Effect.fn("runGit")(function* (
237 + plan: ReferenceRepoSyncPlan,
238 + cwd: string,
239 + args: ReadonlyArray<string>,
240 +) {
241 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
242 const errorContext = {
243 repoId: plan.repo.id,
224 - action: plan.action,
225 - repository: plan.repo.repository,
244 + command: args[0] ?? "",
245 ref: plan.ref,
227 - rootDir,
228 - argumentCount: plan.args.length,
246 + cwd,
247 } as const;
230 - const child = yield* spawner.spawn(ChildProcess.make("git", plan.args, { cwd: rootDir })).pipe(
231 - Effect.mapError(
232 - (cause) =>
233 - new ReferenceRepoGitSubtreeError({
234 - ...errorContext,
235 - operation: "spawn",
236 - cause,
237 - }),
238 - ),
239 - );
248 + const child = yield* spawner
249 + .spawn(ChildProcess.make("git", [...args], { cwd }))
250 + .pipe(
251 + Effect.mapError(
252 + (cause) => new ReferenceRepoGitError({ ...errorContext, operation: "spawn", cause }),
253 + ),
254 + );
255 const [stdout, stderr, exitCode] = yield* Effect.all(
256 [
257 collectStreamAsString(child.stdout),
@@ -246,28 +261,66 @@ const runGit = Effect.fn("runGit")(function* (rootDir: string, plan: ReferenceRe
261 { concurrency: "unbounded" },
262 ).pipe(
263 Effect.mapError(
249 - (cause) =>
250 - new ReferenceRepoGitSubtreeError({
251 - ...errorContext,
252 - operation: "communicate",
253 - cause,
254 - }),
264 + (cause) => new ReferenceRepoGitError({ ...errorContext, operation: "communicate", cause }),
265 ),
266 );
267
268 if (exitCode !== 0) {
259 - return yield* new ReferenceRepoGitSubtreeError({
269 + return yield* new ReferenceRepoGitError({
270 ...errorContext,
271 operation: "exit",
272 exitCode,
263 - stdoutLength: stdout.length,
264 - stderrLength: stderr.length,
273 + stderr,
274 });
275 }
276
268 - if (stdout.trim().length > 0) {
269 - yield* Console.log(stdout.trim());
277 + return stdout;
278 +});
279 +
280 +const applyReferenceRepoSync = Effect.fn("applyReferenceRepoSync")(function* (
281 + rootDir: string,
282 + plan: ReferenceRepoSyncPlan,
283 +) {
284 + const fs = yield* FileSystem.FileSystem;
285 + const path = yield* Path.Path;
286 + const { repo } = plan;
287 + const target = path.join(rootDir, repo.prefix);
288 + const mapFsError = Effect.mapError(
289 + (cause: unknown) =>
290 + new ReferenceRepoFileSystemError({ repoId: repo.id, prefix: repo.prefix, cause }),
291 + );
292 +
293 + // Clone next to the target so a rename moves it into place: same filesystem, and
294 + // relative symlinks stay relative (`fs.copy` rewrites them to absolute temp paths).
295 + yield* fs.makeDirectory(path.dirname(target), { recursive: true }).pipe(mapFsError);
296 + const tempDir = yield* fs
297 + .makeTempDirectoryScoped({ directory: path.dirname(target), prefix: `.sync-${repo.id}-` })
298 + .pipe(mapFsError);
299 + const checkout = path.join(tempDir, "checkout");
300 + yield* runGit(plan, rootDir, [...plan.cloneArgs, checkout]);
301 + const commit = (yield* runGit(plan, checkout, ["rev-parse", "HEAD"])).trim();
302 +
303 + yield* Effect.gen(function* () {
304 + yield* fs.remove(path.join(checkout, ".git"), { recursive: true });
305 + yield* fs.remove(target, { recursive: true, force: true });
306 + yield* fs.rename(checkout, target);
307 + }).pipe(mapFsError);
308 +
309 + yield* runGit(plan, rootDir, ["add", "--all", "--", repo.prefix]);
310 + const status = yield* runGit(plan, rootDir, ["status", "--porcelain", "--", repo.prefix]);
311 + if (status.trim().length === 0) {
312 + yield* Console.log(`${repo.id} is already at ${plan.ref}.`);
313 + return;
314 }
315 + yield* runGit(plan, rootDir, [
316 + "commit",
317 + "--quiet",
318 + "--message",
319 + `chore(repos): sync ${repo.id} to ${plan.ref}\n\nUpstream: ${repo.repository} ${commit}`,
320 + "--",
321 + repo.prefix,
322 + ]);
323 + yield* Console.log(`Committed ${repo.prefix} at ${plan.ref} (${commit.slice(0, 12)}).`);
324 });
325
326 export const syncReferenceRepos = Effect.fn("syncReferenceRepos")(function* (
@@ -281,9 +334,9 @@ export const syncReferenceRepos = Effect.fn("syncReferenceRepos")(function* (
334 for (const repo of repos) {
335 const plan = yield* planReferenceRepoSync(repo, rootDir, options.latest ?? false);
336 plans.push(plan);
284 - yield* Console.log(`Syncing ${repo.id} from ${plan.ref} with git subtree ${plan.action}.`);
337 + yield* Console.log(`Syncing ${repo.id} from ${plan.ref} (shallow clone, no history).`);
338 if (!(options.dryRun ?? false)) {
286 - yield* runGit(rootDir, plan).pipe(Effect.scoped);
339 + yield* applyReferenceRepoSync(rootDir, plan).pipe(Effect.scoped);
340 }
341 }
342
@@ -304,11 +357,11 @@ export const syncReferenceReposCommand = Command.make(
357 Flag.withDefault(false),
358 ),
359 root: Flag.String("root").pipe(
307 - Flag.withDescription("Workspace root used to resolve versions and subtree prefixes."),
360 + Flag.withDescription("Workspace root used to resolve versions and .repos/ prefixes."),
361 Flag.optional,
362 ),
363 dryRun: Flag.Boolean("dry-run").pipe(
311 - Flag.withDescription("Print planned subtree operations without running git."),
364 + Flag.withDescription("Print the planned syncs without cloning or committing."),
365 Flag.withDefault(false),
366 ),
367 },