mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(schedules): add workspace modes and worktree management
This commit is contained in:
1 parent
c06075651d
commit
6ec3f3bd91
90 files changed
+2084
-801
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import { getRepoDirectoryNameError } from '../utils/repo'
|
||||
|
||||
export const RepoStatusSchema = z.enum(['cloning', 'ready', 'error'])
|
||||
|
||||
@@ -54,6 +55,13 @@ export const UpdateRepoRequestSchema = z.object({
|
||||
name: z.string().trim().max(100).nullable(),
|
||||
})
|
||||
|
||||
export const CreateRepoWorkspaceRequestSchema = z.object({
|
||||
name: z.string().trim().optional().superRefine((name, ctx) => {
|
||||
const error = name ? getRepoDirectoryNameError(name) : null
|
||||
if (error) ctx.addIssue({ code: 'custom', message: error })
|
||||
}),
|
||||
})
|
||||
|
||||
export const DeleteRepoRequestSchema = z.object({
|
||||
deleteBranch: z.enum(['none', 'local', 'local-and-remote']).default('none'),
|
||||
})
|
||||
|
||||
@@ -9,6 +9,32 @@ export type ScheduleRunStatus = z.infer<typeof ScheduleRunStatusSchema>
|
||||
export const ScheduleModeSchema = z.enum(['interval', 'cron'])
|
||||
export type ScheduleMode = z.infer<typeof ScheduleModeSchema>
|
||||
|
||||
/**
|
||||
* Where a scheduled run executes. `worktree` gives every run a fresh worktree that is
|
||||
* removed when the run ends, `kept-worktree` keeps each run's worktree afterwards,
|
||||
* `shared-worktree` reuses one worktree and branch for every run of the schedule, and
|
||||
* `repo` runs directly in the repository checkout without isolation.
|
||||
*/
|
||||
export const ScheduleWorkspaceModeSchema = z.enum(['worktree', 'kept-worktree', 'shared-worktree', 'repo'])
|
||||
export type ScheduleWorkspaceMode = z.infer<typeof ScheduleWorkspaceModeSchema>
|
||||
|
||||
/**
|
||||
* A schedule worktree that still exists on disk. `runId` is null for the schedule's
|
||||
* shared worktree, and `inUse` is true while a running run is working in it.
|
||||
*/
|
||||
export const ScheduleWorktreeSchema = z.object({
|
||||
worktreePath: z.string(),
|
||||
branch: z.string(),
|
||||
runId: z.number().nullable(),
|
||||
inUse: z.boolean(),
|
||||
})
|
||||
export type ScheduleWorktree = z.infer<typeof ScheduleWorktreeSchema>
|
||||
|
||||
export const RemoveScheduleWorktreesRequestSchema = z.object({
|
||||
worktreePath: z.string().min(1).optional(),
|
||||
})
|
||||
export type RemoveScheduleWorktreesRequest = z.infer<typeof RemoveScheduleWorktreesRequestSchema>
|
||||
|
||||
export const ScheduleSkillMetadataSchema = z.object({
|
||||
skillSlugs: z.array(z.string().min(1).max(100)).default([]),
|
||||
notes: z.string().max(2000).optional(),
|
||||
@@ -153,6 +179,7 @@ export const ScheduleJobSchema = z.object({
|
||||
permissionConfig: SchedulePermissionConfigSchema.nullable(),
|
||||
mcpServers: ScheduleMcpServersSchema,
|
||||
branch: z.string().nullable(),
|
||||
workspaceMode: ScheduleWorkspaceModeSchema,
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
lastRunAt: z.number().nullable(),
|
||||
@@ -192,6 +219,7 @@ const ScheduleJobBaseRequestSchema = z.object({
|
||||
permissionConfig: SchedulePermissionConfigSchema.nullable().optional(),
|
||||
mcpServers: ScheduleMcpServersSchema.optional(),
|
||||
branch: z.string().min(1).max(200).nullable().optional(),
|
||||
workspaceMode: ScheduleWorkspaceModeSchema.optional(),
|
||||
})
|
||||
|
||||
export const CreateScheduleJobRequestSchema = z.discriminatedUnion('scheduleMode', [
|
||||
@@ -222,6 +250,7 @@ export const UpdateScheduleJobRequestSchema = z.object({
|
||||
permissionConfig: SchedulePermissionConfigSchema.nullable().optional(),
|
||||
mcpServers: ScheduleMcpServersSchema.optional(),
|
||||
branch: z.string().min(1).max(200).nullable().optional(),
|
||||
workspaceMode: ScheduleWorkspaceModeSchema.optional(),
|
||||
})
|
||||
export type UpdateScheduleJobRequest = z.infer<typeof UpdateScheduleJobRequestSchema>
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
DiscoverReposRequestSchema,
|
||||
DiscoverReposResponseSchema,
|
||||
UpdateRepoRequestSchema,
|
||||
CreateRepoWorkspaceRequestSchema,
|
||||
DeleteRepoRequestSchema,
|
||||
DeleteRepoResultSchema,
|
||||
RepoStatusSchema,
|
||||
@@ -89,6 +90,7 @@ export type DiscoverReposRequest = z.infer<typeof DiscoverReposRequestSchema>
|
||||
export type DiscoverReposResponse = z.infer<typeof DiscoverReposResponseSchema>
|
||||
export type RepoStatus = z.infer<typeof RepoStatusSchema>
|
||||
export type UpdateRepoRequest = z.infer<typeof UpdateRepoRequestSchema>
|
||||
export type CreateRepoWorkspaceRequest = z.infer<typeof CreateRepoWorkspaceRequestSchema>
|
||||
export type DeleteRepoRequest = z.infer<typeof DeleteRepoRequestSchema>
|
||||
export type DeleteRepoResult = z.infer<typeof DeleteRepoResultSchema>
|
||||
export type AssistantModeStatus = z.infer<typeof AssistantModeStatusSchema>
|
||||
@@ -152,6 +154,9 @@ export type {
|
||||
|
||||
export type {
|
||||
ScheduleMode,
|
||||
ScheduleWorkspaceMode,
|
||||
ScheduleWorktree,
|
||||
RemoveScheduleWorktreesRequest,
|
||||
SchedulePermissionConfig,
|
||||
ScheduleRunTriggerSource,
|
||||
ScheduleRunStatus,
|
||||
|
||||
@@ -87,8 +87,24 @@ export function getBranchNameError(name: string): string | null {
|
||||
return null
|
||||
}
|
||||
|
||||
export function isWorktreeSibling(sibling: { worktreeStrategy?: string }): boolean {
|
||||
return sibling.worktreeStrategy !== undefined
|
||||
/**
|
||||
* Who owns a repo worktree: OpenCode, a schedule, or nobody (a plain git worktree).
|
||||
*/
|
||||
export type RepoWorktreeSource = 'opencode' | 'schedule' | 'git'
|
||||
|
||||
/**
|
||||
* The schedule a worktree belongs to. `runId` is null for the schedule's shared worktree,
|
||||
* and `inUse` is true while a running run works in it.
|
||||
*/
|
||||
export interface RepoWorktreeSchedule {
|
||||
repoId: number
|
||||
jobId: number
|
||||
runId: number | null
|
||||
inUse: boolean
|
||||
}
|
||||
|
||||
export function isWorktreeSibling(sibling: { worktreeSource?: RepoWorktreeSource }): boolean {
|
||||
return sibling.worktreeSource !== undefined
|
||||
}
|
||||
|
||||
export function getRepoBaseDirectoryName(repo: { localPath: string; branch?: string; isWorktree?: boolean }): string {
|
||||
|
||||
Reference in new issue
Block a user