@@ -4,6 +4,7 @@ import { tasks } from '@/lib/db/schema'
44import { eq , and , isNull } from 'drizzle-orm'
55import { getOctokit } from '@/lib/github/client'
66import { getServerSession } from '@/lib/session/get-server-session'
7+ import { PROJECT_DIR } from '@/lib/sandbox/commands'
78import type { Octokit } from '@octokit/rest'
89
910function getLanguageFromFilename ( filename : string ) : string {
@@ -204,26 +205,42 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
204205 }
205206
206207 // Fetch latest from remote to ensure we have up-to-date remote refs
207- const fetchResult = await sandbox . runCommand ( 'git' , [ 'fetch' , 'origin' , task . branchName ] )
208+ const fetchResult = await sandbox . runCommand ( {
209+ cmd : 'git' ,
210+ args : [ 'fetch' , 'origin' , task . branchName ] ,
211+ cwd : PROJECT_DIR ,
212+ } )
208213
209214 // Check if remote branch actually exists (even if fetch succeeds, the branch might not exist)
210215 const remoteBranchRef = `origin/${ task . branchName } `
211- const checkRemoteResult = await sandbox . runCommand ( 'git' , [ 'rev-parse' , '--verify' , remoteBranchRef ] )
216+ const checkRemoteResult = await sandbox . runCommand ( {
217+ cmd : 'git' ,
218+ args : [ 'rev-parse' , '--verify' , remoteBranchRef ] ,
219+ cwd : PROJECT_DIR ,
220+ } )
212221 const remoteBranchExists = checkRemoteResult . exitCode === 0
213222
214223 if ( ! remoteBranchExists ) {
215224 // Remote branch doesn't exist yet, compare against HEAD (local changes only)
216225
217226 // Get old content (HEAD version)
218- const oldContentResult = await sandbox . runCommand ( 'git' , [ 'show' , `HEAD:${ filename } ` ] )
227+ const oldContentResult = await sandbox . runCommand ( {
228+ cmd : 'git' ,
229+ args : [ 'show' , `HEAD:${ filename } ` ] ,
230+ cwd : PROJECT_DIR ,
231+ } )
219232 let oldContent = ''
220233 if ( oldContentResult . exitCode === 0 ) {
221234 oldContent = await oldContentResult . stdout ( )
222235 }
223236 // File might not exist in HEAD (new file)
224237
225238 // Get new content (working directory version)
226- const newContentResult = await sandbox . runCommand ( 'cat' , [ filename ] )
239+ const newContentResult = await sandbox . runCommand ( {
240+ cmd : 'cat' ,
241+ args : [ filename ] ,
242+ cwd : PROJECT_DIR ,
243+ } )
227244 const newContent = newContentResult . exitCode === 0 ? await newContentResult . stdout ( ) : ''
228245
229246 return NextResponse . json ( {
@@ -241,7 +258,11 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
241258
242259 // Compare working directory against remote branch
243260 // This shows all uncommitted AND unpushed changes
244- const diffResult = await sandbox . runCommand ( 'git' , [ 'diff' , remoteBranchRef , filename ] )
261+ const diffResult = await sandbox . runCommand ( {
262+ cmd : 'git' ,
263+ args : [ 'diff' , remoteBranchRef , filename ] ,
264+ cwd : PROJECT_DIR ,
265+ } )
245266
246267 if ( diffResult . exitCode !== 0 ) {
247268 const diffError = await diffResult . stderr ( )
@@ -252,15 +273,23 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
252273 const diffOutput = await diffResult . stdout ( )
253274
254275 // Get old content (remote branch version)
255- const oldContentResult = await sandbox . runCommand ( 'git' , [ 'show' , `${ remoteBranchRef } :${ filename } ` ] )
276+ const oldContentResult = await sandbox . runCommand ( {
277+ cmd : 'git' ,
278+ args : [ 'show' , `${ remoteBranchRef } :${ filename } ` ] ,
279+ cwd : PROJECT_DIR ,
280+ } )
256281 let oldContent = ''
257282 if ( oldContentResult . exitCode === 0 ) {
258283 oldContent = await oldContentResult . stdout ( )
259284 }
260285 // File might not exist on remote (new file)
261286
262287 // Get new content (working directory version)
263- const newContentResult = await sandbox . runCommand ( 'cat' , [ filename ] )
288+ const newContentResult = await sandbox . runCommand ( {
289+ cmd : 'cat' ,
290+ args : [ filename ] ,
291+ cwd : PROJECT_DIR ,
292+ } )
264293 const newContent = newContentResult . exitCode === 0 ? await newContentResult . stdout ( ) : ''
265294
266295 return NextResponse . json ( {
0 commit comments