feat(schedules): require worktrees and choose commit or discard on removal

Drop the repo workspace mode so every scheduled run executes in a
worktree. Clearing run history or deleting a run now asks whether to
commit pending changes and keep the run branches, or force-remove the
worktrees and delete the branches.

Sibling repo listings carry the schedule name, and the repo detail
workspace view subscribes to schedule worktree sessions only while
expanded. Also unify schedule worktree path/branch helpers, refuse a run
branch already checked out elsewhere, and clean up terminals when a
worktree is removed.
This commit is contained in:
Chris Scott committed 2026-10-06 11:02:29 -04:00
1 parent 6ec3f3bd91
commit 26ff08d891
46 files changed
+1171 -375

No files matched your search

+5 -9
View File
@@ -3,7 +3,10 @@ import { FetchError, fetchWrapper, fetchWrapperVoid, fetchWrapperBlob } from './
import { API_BASE_URL } from '@/config'
import { saveFile } from '@/lib/download'
import type { CreateRepoWorkspaceRequest, DiscoverReposResponse, AssistantModeStatus, AssistantModeInitRequest, DeleteRepoRequest, DeleteRepoResult, RepoGitIdentity, WorktreeSetupResult } from '@opencode-manager/shared/types'
import type { RepoWorktreeSchedule, RepoWorktreeSource } from '@opencode-manager/shared/utils'
import type { RepoSibling } from '@opencode-manager/shared/utils'
import { formatScheduleWorktreeLabel } from '@/lib/schedules/schedule-worktree'
export type { RepoSibling } from '@opencode-manager/shared/utils'
export interface CreateRepoOptions {
repoUrl?: string
@@ -39,20 +42,13 @@ export async function getRepo(id: number): Promise<Repo> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}`)
}
export type RepoSibling = Repo & {
currentBranch?: string
worktreeSource?: RepoWorktreeSource
worktreeStrategy?: string
schedule?: RepoWorktreeSchedule
}
export function workspaceLabel(workspace: RepoSibling): string {
return workspace.currentBranch || workspace.branch || workspace.localPath || 'worktree'
}
export function worktreeSourceLabel(worktree: RepoSibling): string | null {
if (worktree.schedule) {
return worktree.schedule.runId === null ? 'Schedule · shared' : `Schedule · run #${worktree.schedule.runId}`
return `Schedule · ${formatScheduleWorktreeLabel(worktree.schedule.runId)}`
}
if (worktree.worktreeSource === 'git') return 'Git'
return worktree.worktreeSource === 'opencode' ? 'OpenCode' : null
+10 -6
View File
@@ -2,9 +2,11 @@ import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
import { API_BASE_URL } from '@/config'
import type {
CreateScheduleJobRequest,
RemoveScheduleWorktreesRequest,
ScheduleJob,
ScheduleRun,
ScheduleRunStatus,
ScheduleRunWorktreesMode,
ScheduleWorktree,
UpdateScheduleJobRequest,
} from '@opencode-manager/shared/types'
@@ -158,8 +160,9 @@ export async function cancelRepoScheduleRun(repoId: number, jobId: number, runId
})
}
export async function clearRepoScheduleRuns(repoId: number, jobId: number): Promise<{ cleared: number }> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs`, {
export async function clearRepoScheduleRuns(repoId: number, jobId: number, worktrees?: ScheduleRunWorktreesMode): Promise<{ cleared: number }> {
const qs = worktrees ? `?worktrees=${worktrees}` : ''
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs${qs}`, {
method: 'DELETE',
})
}
@@ -168,16 +171,17 @@ export async function listScheduleWorktrees(repoId: number, jobId: number): Prom
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/worktrees`)
}
export async function removeScheduleWorktrees(repoId: number, jobId: number, worktreePath?: string): Promise<{ removed: number }> {
export async function removeScheduleWorktrees(repoId: number, jobId: number, request: RemoveScheduleWorktreesRequest = {}): Promise<{ removed: number }> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/worktrees`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(worktreePath ? { worktreePath } : {}),
body: JSON.stringify(request),
})
}
export async function deleteRepoScheduleRun(repoId: number, jobId: number, runId: number): Promise<void> {
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs/${runId}`, {
export async function deleteRepoScheduleRun(repoId: number, jobId: number, runId: number, worktrees?: ScheduleRunWorktreesMode): Promise<void> {
const qs = worktrees ? `?worktrees=${worktrees}` : ''
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs/${runId}${qs}`, {
method: 'DELETE',
})
}