@@ -14,6 +14,7 @@ import type { OpenCodeClient } from '../services/opencode/client'
1414import { logger } from '../utils/logger'
1515import { getErrorMessage , getStatusCode } from '../utils/error-utils'
1616import { getOpenCodeConfigFilePath } from '@opencode-manager/shared/config/env'
17+ import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
1718import { createRepoGitRoutes } from './repo-git'
1819import { createScheduleRoutes } from './schedules'
1920import type { GitAuthService } from '../services/git-auth'
@@ -31,6 +32,10 @@ async function restartOpenCode(openCodeSupervisor?: OpenCodeSupervisor): Promise
3132 await opencodeServerManager . restart ( )
3233}
3334
35+ function resolveRepo ( database : Database , id : number ) : Repo | null {
36+ return getRepoById ( database , id ) ?? ( id === ASSISTANT_REPO_ID ? buildAssistantRepo ( ) : null )
37+ }
38+
3439export function createRepoRoutes (
3540 database : Database ,
3641 gitAuthService : GitAuthService ,
@@ -122,7 +127,7 @@ app.get('/', async (c) => {
122127 const reposWithCurrentBranch = await Promise . all (
123128 repos . map ( async ( repo ) => {
124129 const env = gitAuthService . getGitEnvironment ( )
125- const currentBranch = await repoService . getCurrentBranch ( repo , env )
130+ const currentBranch = repo . id === ASSISTANT_REPO_ID ? undefined : await repoService . getCurrentBranch ( repo , env )
126131 return { ...repo , currentBranch }
127132 } )
128133 )
@@ -157,14 +162,13 @@ app.get('/', async (c) => {
157162 try {
158163 const id = parseInt ( c . req . param ( 'id' ) )
159164
160- const isAssistant = id === 0
161- const repo : Repo | null = isAssistant ? buildAssistantRepo ( ) : getRepoById ( database , id )
165+ const repo : Repo | null = resolveRepo ( database , id )
162166
163167 if ( ! repo ) {
164168 return c . json ( { error : 'Repo not found' } , 404 )
165169 }
166170
167- const currentBranch = isAssistant ? undefined : await repoService . getCurrentBranch ( repo , gitAuthService . getGitEnvironment ( ) )
171+ const currentBranch = id === ASSISTANT_REPO_ID ? undefined : await repoService . getCurrentBranch ( repo , gitAuthService . getGitEnvironment ( ) )
168172
169173 return c . json ( { ...repo , currentBranch } )
170174 } catch ( error : unknown ) {
@@ -267,6 +271,11 @@ app.get('/', async (c) => {
267271 app . delete ( '/:id' , async ( c ) => {
268272 try {
269273 const id = parseInt ( c . req . param ( 'id' ) )
274+
275+ if ( id === ASSISTANT_REPO_ID ) {
276+ return c . json ( { error : 'Cannot delete the assistant repository' } , 403 )
277+ }
278+
270279 const repo = getRepoById ( database , id )
271280
272281 if ( ! repo ) {
@@ -480,7 +489,7 @@ app.get('/', async (c) => {
480489 try {
481490 const id = parseInt ( c . req . param ( 'id' ) )
482491
483- const repo : Repo | null = id === 0 ? buildAssistantRepo ( ) : getRepoById ( database , id )
492+ const repo : Repo | null = resolveRepo ( database , id )
484493
485494 if ( ! repo ) {
486495 return c . json ( { error : 'Repo not found' } , 404 )
@@ -498,7 +507,7 @@ app.get('/', async (c) => {
498507 try {
499508 const id = parseInt ( c . req . param ( 'id' ) )
500509
501- const repo : Repo | null = id === 0 ? buildAssistantRepo ( ) : getRepoById ( database , id )
510+ const repo : Repo | null = resolveRepo ( database , id )
502511
503512 if ( ! repo ) {
504513 return c . json ( { error : 'Repo not found' } , 404 )
0 commit comments