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

+11 -4
View File
@@ -11,13 +11,20 @@ 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.
* removed when the run ends, `kept-worktree` keeps each run's worktree afterwards, and
* `shared-worktree` reuses one worktree and branch for every run of the schedule.
*/
export const ScheduleWorkspaceModeSchema = z.enum(['worktree', 'kept-worktree', 'shared-worktree', 'repo'])
export const ScheduleWorkspaceModeSchema = z.enum(['worktree', 'kept-worktree', 'shared-worktree'])
export type ScheduleWorkspaceMode = z.infer<typeof ScheduleWorkspaceModeSchema>
/**
* What clearing run history does with the run worktrees that still exist on disk.
* `commit` commits their pending changes to their branches and keeps those branches;
* `discard` force-removes the worktrees and deletes their branches.
*/
export const ScheduleRunWorktreesModeSchema = z.enum(['commit', 'discard']).default('commit')
export type ScheduleRunWorktreesMode = z.infer<typeof ScheduleRunWorktreesModeSchema>
/**
* 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.
+1
View File
@@ -155,6 +155,7 @@ export type {
export type {
ScheduleMode,
ScheduleWorkspaceMode,
ScheduleRunWorktreesMode,
ScheduleWorktree,
RemoveScheduleWorktreesRequest,
SchedulePermissionConfig,
+14 -1
View File
@@ -1,3 +1,5 @@
import type { Repo } from '../types'
export const ASSISTANT_REPO_ID = 0
export const ASSISTANT_REPO_NAME = 'Assistant'
export const ASSISTANT_REPO_PATH = 'assistant'
@@ -94,13 +96,24 @@ 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.
* `inUse` is true while a running run works in it, and `name` is the schedule's display name.
*/
export interface RepoWorktreeSchedule {
repoId: number
jobId: number
runId: number | null
inUse: boolean
name: string
}
/**
* A repository visible from another repository in the same project: the repo itself, a plain
* git or OpenCode worktree, or a schedule worktree.
*/
export type RepoSibling = Repo & {
currentBranch?: string
worktreeSource?: RepoWorktreeSource
schedule?: RepoWorktreeSchedule
}
export function isWorktreeSibling(sibling: { worktreeSource?: RepoWorktreeSource }): boolean {