feat(httpapi): bridge worktree mutations (#24371)

This commit is contained in:
Kit Langton
2026-04-25 15:35:15 -04:00
committed by GitHub
parent 474024f9e6
commit a369130226
6 changed files with 164 additions and 45 deletions

View File

@@ -20,6 +20,8 @@ import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { BootstrapRuntime } from "@/effect/bootstrap-runtime"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
import { InstanceState } from "@/effect"
import { zod as effectZod } from "@/util/effect-zod"
import { withStatics } from "@/util/schema"
const log = Log.create({ service: "worktree" })
@@ -39,48 +41,38 @@ export const Event = {
),
}
export const Info = z
.object({
name: z.string(),
branch: z.string(),
directory: z.string(),
})
.meta({
ref: "Worktree",
})
export const Info = Schema.Struct({
name: Schema.String,
branch: Schema.String,
directory: Schema.String,
})
.annotate({ identifier: "Worktree" })
.pipe(withStatics((s) => ({ zod: effectZod(s) })))
export type Info = Schema.Schema.Type<typeof Info>
export type Info = z.infer<typeof Info>
export const CreateInput = Schema.Struct({
name: Schema.optional(Schema.String),
startCommand: Schema.optional(
Schema.String.annotate({ description: "Additional startup script to run after the project's start command" }),
),
})
.annotate({ identifier: "WorktreeCreateInput" })
.pipe(withStatics((s) => ({ zod: effectZod(s) })))
export type CreateInput = Schema.Schema.Type<typeof CreateInput>
export const CreateInput = z
.object({
name: z.string().optional(),
startCommand: z.string().optional().describe("Additional startup script to run after the project's start command"),
})
.meta({
ref: "WorktreeCreateInput",
})
export const RemoveInput = Schema.Struct({
directory: Schema.String,
})
.annotate({ identifier: "WorktreeRemoveInput" })
.pipe(withStatics((s) => ({ zod: effectZod(s) })))
export type RemoveInput = Schema.Schema.Type<typeof RemoveInput>
export type CreateInput = z.infer<typeof CreateInput>
export const RemoveInput = z
.object({
directory: z.string(),
})
.meta({
ref: "WorktreeRemoveInput",
})
export type RemoveInput = z.infer<typeof RemoveInput>
export const ResetInput = z
.object({
directory: z.string(),
})
.meta({
ref: "WorktreeResetInput",
})
export type ResetInput = z.infer<typeof ResetInput>
export const ResetInput = Schema.Struct({
directory: Schema.String,
})
.annotate({ identifier: "WorktreeResetInput" })
.pipe(withStatics((s) => ({ zod: effectZod(s) })))
export type ResetInput = Schema.Schema.Type<typeof ResetInput>
export const NotGitError = NamedError.create(
"WorktreeNotGitError",
@@ -210,7 +202,7 @@ export const layer: Layer.Layer<
const branchCheck = yield* git(["show-ref", "--verify", "--quiet", ref], { cwd: ctx.worktree })
if (branchCheck.code === 0) continue
return Info.parse({ name, branch, directory })
return { name, branch, directory }
}
throw new NameGenerationFailedError({ message: "Failed to generate a unique worktree name" })
})