From fcfd47602b6e0b53b881904066c26a3c5ea2d927 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Tue, 2 Jun 2026 13:42:23 +0000 Subject: [PATCH] chore: generate --- packages/core/src/git.ts | 36 +++++++-- packages/core/src/repository-cache.ts | 86 ++++++++++++++------- packages/core/src/repository.ts | 3 +- packages/core/test/repository-cache.test.ts | 7 +- packages/core/test/repository.test.ts | 4 +- 5 files changed, 98 insertions(+), 38 deletions(-) diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 3852dce91..b656fbdfb 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -34,7 +34,12 @@ export interface Interface { readonly head: (directory: string) => Effect.Effect readonly branch: (directory: string) => Effect.Effect readonly remoteHead: (directory: string) => Effect.Effect - readonly clone: (input: { remote: string; target: string; branch?: string; depth?: number }) => Effect.Effect + readonly clone: (input: { + remote: string + target: string + branch?: string + depth?: number + }) => Effect.Effect readonly fetch: (directory: string) => Effect.Effect readonly fetchBranch: (directory: string, branch: string) => Effect.Effect readonly checkout: (directory: string, branch: string) => Effect.Effect @@ -109,7 +114,10 @@ export const layer = Layer.effect( }) const clone = Effect.fn("Git.clone")((input: { remote: string; target: string; branch?: string; depth?: number }) => - execute(path.dirname(input.target), proc)([ + execute( + path.dirname(input.target), + proc, + )([ "clone", "--depth", String(input.depth ?? 100), @@ -134,7 +142,20 @@ export const layer = Layer.effect( execute(directory, proc)(["reset", "--hard", target]), ) - return Service.of({ find, remote, roots, origin, head, branch, remoteHead, clone, fetch, fetchBranch, checkout, reset }) + return Service.of({ + find, + remote, + roots, + origin, + head, + branch, + remoteHead, + clone, + fetch, + fetchBranch, + checkout, + reset, + }) }), ) @@ -150,7 +171,8 @@ export interface Result { } function run(cwd: string, proc: AppProcess.Interface) { - return (args: string[]) => execute(cwd, proc)(args).pipe(Effect.catch(() => Effect.succeed({ exitCode: 1, text: "", stderr: "" }))) + return (args: string[]) => + execute(cwd, proc)(args).pipe(Effect.catch(() => Effect.succeed({ exitCode: 1, text: "", stderr: "" }))) } function execute(cwd: string, proc: AppProcess.Interface) { @@ -166,7 +188,11 @@ function execute(cwd: string, proc: AppProcess.Interface) { .pipe( Effect.map( (result) => - ({ exitCode: result.exitCode, text: result.stdout.toString("utf8"), stderr: result.stderr.toString("utf8") }) satisfies Result, + ({ + exitCode: result.exitCode, + text: result.stdout.toString("utf8"), + stderr: result.stderr.toString("utf8"), + }) satisfies Result, ), ) } diff --git a/packages/core/src/repository-cache.ts b/packages/core/src/repository-cache.ts index 6670ce3c7..8fd0f81ac 100644 --- a/packages/core/src/repository-cache.ts +++ b/packages/core/src/repository-cache.ts @@ -30,10 +30,13 @@ export class InvalidRepositoryError extends Schema.TaggedErrorClass()("RepositoryCacheInvalidBranchError", { - branch: Schema.String, - message: Schema.String, -}) {} +export class InvalidBranchError extends Schema.TaggedErrorClass()( + "RepositoryCacheInvalidBranchError", + { + branch: Schema.String, + message: Schema.String, + }, +) {} export class CloneFailedError extends Schema.TaggedErrorClass()("RepositoryCacheCloneFailedError", { repository: Schema.String, @@ -64,11 +67,14 @@ export class LockFailedError extends Schema.TaggedErrorClass()( message: Schema.String, }) {} -export class CacheOperationError extends Schema.TaggedErrorClass()("RepositoryCacheOperationError", { - operation: Schema.String, - path: Schema.String, - message: Schema.String, -}) {} +export class CacheOperationError extends Schema.TaggedErrorClass()( + "RepositoryCacheOperationError", + { + operation: Schema.String, + path: Schema.String, + message: Schema.String, + }, +) {} export type Error = | InvalidRepositoryError @@ -155,27 +161,35 @@ export const layer: Layer.Layer< }) if (status === "cloned") { - const result = yield* git.clone({ remote: input.reference.remote, target: localPath, branch: input.branch }).pipe( - Effect.mapError((error) => new CloneFailedError({ repository, message: errorMessage(error) })), - ) + const result = yield* git + .clone({ remote: input.reference.remote, target: localPath, branch: input.branch }) + .pipe(Effect.mapError((error) => new CloneFailedError({ repository, message: errorMessage(error) }))) if (result.exitCode !== 0) { - return yield* new CloneFailedError({ repository, message: resultMessage(result, `Failed to clone ${repository}`) }) + return yield* new CloneFailedError({ + repository, + message: resultMessage(result, `Failed to clone ${repository}`), + }) } } if (status === "refreshed") { - const fetch = yield* git.fetch(localPath).pipe( - Effect.mapError((error) => new FetchFailedError({ repository, message: errorMessage(error) })), - ) + const fetch = yield* git + .fetch(localPath) + .pipe(Effect.mapError((error) => new FetchFailedError({ repository, message: errorMessage(error) }))) if (fetch.exitCode !== 0) { - return yield* new FetchFailedError({ repository, message: resultMessage(fetch, `Failed to refresh ${repository}`) }) + return yield* new FetchFailedError({ + repository, + message: resultMessage(fetch, `Failed to refresh ${repository}`), + }) } if (input.branch) { const requestedBranch = input.branch - const fetchBranch = yield* git.fetchBranch(localPath, requestedBranch).pipe( - Effect.mapError((error) => new FetchFailedError({ repository, message: errorMessage(error) })), - ) + const fetchBranch = yield* git + .fetchBranch(localPath, requestedBranch) + .pipe( + Effect.mapError((error) => new FetchFailedError({ repository, message: errorMessage(error) })), + ) if (fetchBranch.exitCode !== 0) { return yield* new FetchFailedError({ repository, @@ -183,11 +197,18 @@ export const layer: Layer.Layer< }) } - const checkout = yield* git.checkout(localPath, requestedBranch).pipe( - Effect.mapError((error) => - new CheckoutFailedError({ repository, branch: requestedBranch, message: errorMessage(error) }), - ), - ) + const checkout = yield* git + .checkout(localPath, requestedBranch) + .pipe( + Effect.mapError( + (error) => + new CheckoutFailedError({ + repository, + branch: requestedBranch, + message: errorMessage(error), + }), + ), + ) if (checkout.exitCode !== 0) { return yield* new CheckoutFailedError({ repository, @@ -197,11 +218,14 @@ export const layer: Layer.Layer< } } - const reset = yield* git.reset(localPath, yield* resetTarget(git, localPath, input.branch)).pipe( - Effect.mapError((error) => new ResetFailedError({ repository, message: errorMessage(error) })), - ) + const reset = yield* git + .reset(localPath, yield* resetTarget(git, localPath, input.branch)) + .pipe(Effect.mapError((error) => new ResetFailedError({ repository, message: errorMessage(error) }))) if (reset.exitCode !== 0) { - return yield* new ResetFailedError({ repository, message: resultMessage(reset, `Failed to reset ${repository}`) }) + return yield* new ResetFailedError({ + repository, + message: resultMessage(reset, `Failed to reset ${repository}`), + }) } } @@ -245,7 +269,9 @@ function errorMessage(error: unknown) { } function cacheOperation(effect: Effect.Effect, operation: string, target: string) { - return effect.pipe(Effect.mapError((error) => new CacheOperationError({ operation, path: target, message: errorMessage(error) }))) + return effect.pipe( + Effect.mapError((error) => new CacheOperationError({ operation, path: target, message: errorMessage(error) })), + ) } const resetTarget = Effect.fnUntraced(function* (git: Git.Interface, cwd: string, requestedBranch?: string) { diff --git a/packages/core/src/repository.ts b/packages/core/src/repository.ts index 9ed760191..dbc6a8fbc 100644 --- a/packages/core/src/repository.ts +++ b/packages/core/src/repository.ts @@ -182,7 +182,8 @@ function buildRemote(input: { host: string; segments: string[]; remote?: string; segments, owner: segments.length === 2 ? segments[0] : undefined, repo: segments[segments.length - 1], - remote: input.remote ?? (host === "github.com" ? githubRemote(repositoryPath) : `https://${host}/${repositoryPath}.git`), + remote: + input.remote ?? (host === "github.com" ? githubRemote(repositoryPath) : `https://${host}/${repositoryPath}.git`), label: host === "github.com" && segments.length === 2 ? repositoryPath : `${host}/${repositoryPath}`, protocol: input.protocol, } satisfies RemoteReference diff --git a/packages/core/test/repository-cache.test.ts b/packages/core/test/repository-cache.test.ts index d562db0e6..17ae79d53 100644 --- a/packages/core/test/repository-cache.test.ts +++ b/packages/core/test/repository-cache.test.ts @@ -116,5 +116,10 @@ function read(file: string) { } function exists(file: string) { - return Effect.promise(() => fs.stat(file).then(() => true, () => false)) + return Effect.promise(() => + fs.stat(file).then( + () => true, + () => false, + ), + ) } diff --git a/packages/core/test/repository.test.ts b/packages/core/test/repository.test.ts index 35136a6db..5b18f8b1d 100644 --- a/packages/core/test/repository.test.ts +++ b/packages/core/test/repository.test.ts @@ -42,7 +42,9 @@ describe("Repository", () => { expect(reference).toMatchObject({ host: "file", protocol: "file:", label: localPath }) expect(reference && Repository.isFile(reference)).toBe(true) expect(reference && Repository.isRemote(reference)).toBe(false) - expect(() => Repository.parseRemote(pathToFileURL(localPath).href)).toThrow(Repository.UnsupportedLocalRepositoryError) + expect(() => Repository.parseRemote(pathToFileURL(localPath).href)).toThrow( + Repository.UnsupportedLocalRepositoryError, + ) }) test("rejects unsafe remote references and branches with typed errors", () => {