33 ScheduleJobSchema ,
44 ScheduleRunSchema ,
55 ScheduleSkillMetadataSchema ,
6- type ScheduleIsolationMode ,
76 type ScheduleJob ,
87 type ScheduleMode ,
98 type ScheduleRun ,
@@ -28,7 +27,6 @@ interface ScheduleJobRow {
2827 model : string | null
2928 skill_metadata : string | null
3029 branch : string | null
31- isolation_mode : string | null
3230 created_at : number
3331 updated_at : number
3432 last_run_at : number | null
@@ -84,7 +82,6 @@ function rowToScheduleJob(row: ScheduleJobRow): ScheduleJob {
8482 model : row . model ,
8583 skillMetadata : parseSkillMetadata ( row . skill_metadata ) ,
8684 branch : row . branch ,
87- isolationMode : ( row . isolation_mode as ScheduleIsolationMode ) ?? 'worktree' ,
8885 createdAt : row . created_at ,
8986 updatedAt : row . updated_at ,
9087 lastRunAt : row . last_run_at ,
@@ -150,10 +147,10 @@ export function createScheduleJob(db: Database, repoId: number, input: ScheduleJ
150147 const stmt = db . prepare ( `
151148 INSERT INTO schedule_jobs (
152149 repo_id, name, description, enabled, schedule_mode, interval_minutes, cron_expression, timezone, agent_slug, prompt, model, skill_metadata,
153- branch, isolation_mode,
150+ branch,
154151 created_at, updated_at, last_run_at, next_run_at
155152 )
156- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
153+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
157154 ` )
158155
159156 const result = stmt . run (
@@ -170,7 +167,6 @@ export function createScheduleJob(db: Database, repoId: number, input: ScheduleJ
170167 input . model ?? null ,
171168 serializeSkillMetadata ( input . skillMetadata ) ,
172169 input . branch ,
173- input . isolationMode ,
174170 now ,
175171 now ,
176172 null ,
@@ -195,7 +191,7 @@ export function updateScheduleJob(db: Database, repoId: number, jobId: number, i
195191 const stmt = db . prepare ( `
196192 UPDATE schedule_jobs
197193 SET name = ?, description = ?, enabled = ?, schedule_mode = ?, interval_minutes = ?, cron_expression = ?, timezone = ?,
198- agent_slug = ?, prompt = ?, model = ?, skill_metadata = ?, branch = ?, isolation_mode = ?, updated_at = ?, next_run_at = ?
194+ agent_slug = ?, prompt = ?, model = ?, skill_metadata = ?, branch = ?, updated_at = ?, next_run_at = ?
199195 WHERE repo_id = ? AND id = ?
200196 ` )
201197
@@ -212,7 +208,6 @@ export function updateScheduleJob(db: Database, repoId: number, jobId: number, i
212208 input . model ,
213209 serializeSkillMetadata ( input . skillMetadata ) ,
214210 input . branch ,
215- input . isolationMode ,
216211 now ,
217212 input . nextRunAt ,
218213 repoId ,
@@ -229,6 +224,41 @@ export function deleteScheduleJob(db: Database, repoId: number, jobId: number):
229224 return result . changes > 0
230225}
231226
227+ export interface ScheduleRunArtifact {
228+ id : number
229+ status : ScheduleRunStatus
230+ runBranch : string | null
231+ worktreePath : string | null
232+ }
233+
234+ export function listScheduleRunArtifactsByJob ( db : Database , repoId : number , jobId : number ) : ScheduleRunArtifact [ ] {
235+ const rows = db
236+ . prepare ( 'SELECT id, status, run_branch, worktree_path FROM schedule_runs WHERE repo_id = ? AND job_id = ? ORDER BY id DESC' )
237+ . all ( repoId , jobId ) as { id : number ; status : string ; run_branch : string | null ; worktree_path : string | null } [ ]
238+ return rows . map ( ( row ) => ( {
239+ id : row . id ,
240+ status : row . status as ScheduleRunStatus ,
241+ runBranch : row . run_branch ,
242+ worktreePath : row . worktree_path ,
243+ } ) )
244+ }
245+
246+ export function deleteScheduleRunById ( db : Database , repoId : number , jobId : number , runId : number ) : boolean {
247+ const result = db
248+ . prepare ( 'DELETE FROM schedule_runs WHERE repo_id = ? AND job_id = ? AND id = ?' )
249+ . run ( repoId , jobId , runId )
250+ return result . changes > 0
251+ }
252+
253+ export function deleteScheduleRunsByIds ( db : Database , repoId : number , jobId : number , runIds : number [ ] ) : number {
254+ if ( runIds . length === 0 ) return 0
255+ const placeholders = runIds . map ( ( ) => '?' ) . join ( ', ' )
256+ const result = db
257+ . prepare ( `DELETE FROM schedule_runs WHERE repo_id = ? AND job_id = ? AND id IN (${ placeholders } )` )
258+ . run ( repoId , jobId , ...runIds )
259+ return result . changes
260+ }
261+
232262export function cleanupOrphanedSchedules ( db : Database ) : { orphanedJobs : number ; orphanedRuns : number } {
233263 const runStmt = db . prepare ( `
234264 DELETE FROM schedule_runs
0 commit comments