feat(schedules): support scheduling jobs for the Assistant workspace (#254)

* feat(schedules): support scheduling jobs for the Assistant workspace

* refactor(schedules): extract assistant repo constants, rename workspace to schedule-target

* feat(navigation): add schedules link to session drawer menu

* fix(schedules): document Assistant repoId=0 in generated schedule-management skill
This commit is contained in:
Chris Scott authored and GitHub committed 2026-06-05 11:16:31 -04:00
1 parent 9479e1f662
commit 70cb62b77b
18 files changed
+402 -115

No files matched your search

+19 -15
View File
@@ -9,6 +9,7 @@ import {
type ScheduleRunStatus,
type ScheduleRunTriggerSource,
} from '@opencode-manager/shared/schemas'
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_NAME, ASSISTANT_REPO_PATH } from '@opencode-manager/shared/utils'
import type { ScheduleJobPersistenceInput } from '../services/schedule-config'
interface ScheduleJobRow {
@@ -376,8 +377,8 @@ export interface ScheduleJobWithRepo extends ScheduleJob {
}
interface ScheduleJobWithRepoRow extends ScheduleJobRow {
repo_url: string
repo_path: string
repo_url: string | null
repo_path: string | null
}
function repoNameFromPath(repoPath: string): string {
@@ -385,13 +386,18 @@ function repoNameFromPath(repoPath: string): string {
return repoPath.split(/[\\/]/).pop() ?? repoPath
}
function resolveRepoDisplay(repoId: number, repoPath: string | null): { repoName: string; repoPath: string } {
if (repoId === ASSISTANT_REPO_ID) {
return { repoName: ASSISTANT_REPO_NAME, repoPath: ASSISTANT_REPO_PATH }
}
return { repoName: repoNameFromPath(repoPath ?? ''), repoPath: repoPath ?? '' }
}
function rowToScheduleJobWithRepo(row: ScheduleJobWithRepoRow): ScheduleJobWithRepo {
const job = rowToScheduleJob(row)
return {
...job,
repoName: repoNameFromPath(row.repo_path),
repoPath: row.repo_path,
repoUrl: row.repo_url,
...rowToScheduleJob(row),
...resolveRepoDisplay(row.repo_id, row.repo_path),
repoUrl: row.repo_url ?? '',
}
}
@@ -399,8 +405,8 @@ export function listAllScheduleJobsWithRepos(db: Database): ScheduleJobWithRepo[
const stmt = db.prepare(`
SELECT sj.*, r.repo_url, r.local_path as repo_path
FROM schedule_jobs sj
JOIN repos r ON sj.repo_id = r.id
ORDER BY r.local_path, sj.name
LEFT JOIN repos r ON sj.repo_id = r.id
ORDER BY COALESCE(r.local_path, ''), sj.name
`)
const rows = stmt.all() as ScheduleJobWithRepoRow[]
return rows.map(rowToScheduleJobWithRepo)
@@ -414,16 +420,14 @@ export interface ScheduleRunWithContext extends ScheduleRun {
interface ScheduleRunWithContextRow extends ScheduleRunRow {
job_name: string
repo_path: string
repo_path: string | null
}
function rowToScheduleRunWithContext(row: ScheduleRunWithContextRow): ScheduleRunWithContext {
const run = rowToScheduleRun(row)
return {
...run,
...rowToScheduleRun(row),
jobName: row.job_name,
repoName: repoNameFromPath(row.repo_path),
repoPath: row.repo_path,
...resolveRepoDisplay(row.repo_id, row.repo_path),
}
}
@@ -469,7 +473,7 @@ export function listAllScheduleRuns(db: Database, options: ListAllRunsOptions =
sj.name AS job_name, r.local_path AS repo_path
FROM schedule_runs sr
JOIN schedule_jobs sj ON sr.job_id = sj.id
JOIN repos r ON sr.repo_id = r.id
LEFT JOIN repos r ON sr.repo_id = r.id
${whereClause}
ORDER BY sr.started_at DESC
LIMIT ? OFFSET ?
+7 -2
View File
@@ -13,6 +13,7 @@ import {
ensureDirectoryExists,
} from './file-operations'
import { OpenCodeConfigSchema } from '@opencode-manager/shared/schemas'
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_PATH } from '@opencode-manager/shared/utils'
import { getReposPath, ENV } from '@opencode-manager/shared/config/env'
import type { Database } from 'bun:sqlite'
import { getOrCreateInternalToken } from './internal-token'
@@ -21,7 +22,7 @@ import { logger } from '../utils/logger'
const ASSISTANT_WARMUP_OPENCODE_TIMEOUT_MS = 90000
const ASSISTANT_MODE_DIR = 'assistant'
const ASSISTANT_MODE_DIR = ASSISTANT_REPO_PATH
const ASSISTANT_MODE_RELATIVE_PATH = 'repos/assistant'
const ASSISTANT_AGENTS_MD_FILENAME = 'AGENTS.md'
const ASSISTANT_OPENCODE_CONFIG_FILENAME = 'opencode.json'
@@ -52,7 +53,7 @@ export function getAssistantModeDirectory(): string {
export function buildAssistantRepo(): Repo {
return {
id: 0,
id: ASSISTANT_REPO_ID,
localPath: ASSISTANT_MODE_DIR,
fullPath: getAssistantModeDirectory(),
defaultBranch: 'main',
@@ -339,6 +340,10 @@ Authorization: Bearer <token>
\`${internalBaseUrl}\`
## Assistant Schedules
Use repo ID \`0\` for the built-in Assistant. For example, use \`/repos/0/schedules\` to list or create schedule jobs that run in the Assistant workspace.
## Endpoints
### GET /schedules/all
+2 -1
View File
@@ -39,6 +39,7 @@ import { sseAggregator, type SSEEvent } from './sse-aggregator'
import { getErrorMessage } from '../utils/error-utils'
import { logger } from '../utils/logger'
import { buildAssistantRepo } from './assistant-mode'
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
class ScheduleServiceError extends Error {
status: number
@@ -1056,7 +1057,7 @@ export class ScheduleService {
}
private assertRepo(repoId: number) {
if (repoId === 0) {
if (repoId === ASSISTANT_REPO_ID) {
return { ...buildAssistantRepo(), lastAccessedAt: Date.now(), isLocal: true, currentBranch: undefined }
}
const repo = getRepoById(this.db, repoId)