Skip to content

Commit 0e0f832

Browse files
ctatevercel[bot]
andauthored
improves states, chat status, reliability (#166)
* remove vercel project * fixes * format * improves states, chat status, reliability * format * Fix missing ExternalLink import in task-details.tsx * Update app/api/tasks/[taskId]/sandbox-health/route.ts Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
1 parent 7217ec6 commit 0e0f832

File tree

30 files changed

+1211
-320
lines changed

30 files changed

+1211
-320
lines changed

app/api/tasks/[taskId]/create-file/route.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@/lib/db/client'
33
import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getServerSession } from '@/lib/session/get-server-session'
6+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
67

78
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
89
try {
@@ -65,7 +66,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
6566
const pathParts = filename.split('/')
6667
if (pathParts.length > 1) {
6768
const dirPath = pathParts.slice(0, -1).join('/')
68-
const mkdirResult = await sandbox.runCommand('mkdir', ['-p', dirPath])
69+
const mkdirResult = await sandbox.runCommand({
70+
cmd: 'mkdir',
71+
args: ['-p', dirPath],
72+
cwd: PROJECT_DIR,
73+
})
6974

7075
if (mkdirResult.exitCode !== 0) {
7176
const stderr = await mkdirResult.stderr()
@@ -75,7 +80,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
7580
}
7681

7782
// Create the file using touch
78-
const touchResult = await sandbox.runCommand('touch', [filename])
83+
const touchResult = await sandbox.runCommand({
84+
cmd: 'touch',
85+
args: [filename],
86+
cwd: PROJECT_DIR,
87+
})
7988

8089
if (touchResult.exitCode !== 0) {
8190
const stderr = await touchResult.stderr()

app/api/tasks/[taskId]/create-folder/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@/lib/db/client'
33
import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getServerSession } from '@/lib/session/get-server-session'
6+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
67

78
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
89
try {
@@ -61,7 +62,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
6162
}
6263

6364
// Create the folder using mkdir -p
64-
const mkdirResult = await sandbox.runCommand('mkdir', ['-p', foldername])
65+
const mkdirResult = await sandbox.runCommand({
66+
cmd: 'mkdir',
67+
args: ['-p', foldername],
68+
cwd: PROJECT_DIR,
69+
})
6570

6671
if (mkdirResult.exitCode !== 0) {
6772
const stderr = await mkdirResult.stderr()

app/api/tasks/[taskId]/delete-file/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@/lib/db/client'
33
import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getServerSession } from '@/lib/session/get-server-session'
6+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
67

78
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
89
try {
@@ -61,7 +62,11 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
6162
}
6263

6364
// Delete the file using rm
64-
const rmResult = await sandbox.runCommand('rm', [filename])
65+
const rmResult = await sandbox.runCommand({
66+
cmd: 'rm',
67+
args: [filename],
68+
cwd: PROJECT_DIR,
69+
})
6570

6671
if (rmResult.exitCode !== 0) {
6772
const stderr = await rmResult.stderr()

app/api/tasks/[taskId]/diff/route.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getOctokit } from '@/lib/github/client'
66
import { getServerSession } from '@/lib/session/get-server-session'
7+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
78
import type { Octokit } from '@octokit/rest'
89

910
function 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({

app/api/tasks/[taskId]/discard-file-changes/route.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@/lib/db/client'
33
import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getServerSession } from '@/lib/session/get-server-session'
6+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
67

78
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
89
try {
@@ -61,12 +62,20 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
6162
}
6263

6364
// Check if file is tracked in git
64-
const lsFilesResult = await sandbox.runCommand('git', ['ls-files', filename])
65+
const lsFilesResult = await sandbox.runCommand({
66+
cmd: 'git',
67+
args: ['ls-files', filename],
68+
cwd: PROJECT_DIR,
69+
})
6570
const isTracked = (await lsFilesResult.stdout()).trim().length > 0
6671

6772
if (isTracked) {
6873
// File is tracked, use git checkout to revert changes
69-
const checkoutResult = await sandbox.runCommand('git', ['checkout', 'HEAD', '--', filename])
74+
const checkoutResult = await sandbox.runCommand({
75+
cmd: 'git',
76+
args: ['checkout', 'HEAD', '--', filename],
77+
cwd: PROJECT_DIR,
78+
})
7079

7180
if (checkoutResult.exitCode !== 0) {
7281
const stderr = await checkoutResult.stderr()
@@ -75,7 +84,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
7584
}
7685
} else {
7786
// File is untracked (new file), delete it
78-
const rmResult = await sandbox.runCommand('rm', [filename])
87+
const rmResult = await sandbox.runCommand({
88+
cmd: 'rm',
89+
args: [filename],
90+
cwd: PROJECT_DIR,
91+
})
7992

8093
if (rmResult.exitCode !== 0) {
8194
const stderr = await rmResult.stderr()

app/api/tasks/[taskId]/file-content/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getOctokit } from '@/lib/github/client'
66
import { getServerSession } from '@/lib/session/get-server-session'
7+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
78
import type { Octokit } from '@octokit/rest'
89

910
function getLanguageFromFilename(filename: string): string {
@@ -255,7 +256,11 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
255256
if (sandbox) {
256257
// Read file from sandbox
257258
const normalizedPath = filename.startsWith('/') ? filename.substring(1) : filename
258-
const catResult = await sandbox.runCommand('cat', [normalizedPath])
259+
const catResult = await sandbox.runCommand({
260+
cmd: 'cat',
261+
args: [normalizedPath],
262+
cwd: PROJECT_DIR,
263+
})
259264

260265
if (catResult.exitCode === 0) {
261266
newContent = await catResult.stdout()

app/api/tasks/[taskId]/file-operation/route.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@/lib/db/client'
33
import { tasks } from '@/lib/db/schema'
44
import { eq, and, isNull } from 'drizzle-orm'
55
import { getServerSession } from '@/lib/session/get-server-session'
6+
import { PROJECT_DIR } from '@/lib/sandbox/commands'
67

78
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
89
try {
@@ -67,7 +68,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
6768

6869
if (operation === 'copy') {
6970
// Copy file
70-
const copyResult = await sandbox.runCommand('cp', ['-r', sourceFile, targetFile])
71+
const copyResult = await sandbox.runCommand({
72+
cmd: 'cp',
73+
args: ['-r', sourceFile, targetFile],
74+
cwd: PROJECT_DIR,
75+
})
7176

7277
if (copyResult.exitCode !== 0) {
7378
const stderr = await copyResult.stderr()
@@ -78,7 +83,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
7883
return NextResponse.json({ success: true, message: 'File copied successfully' })
7984
} else if (operation === 'cut') {
8085
// Move file
81-
const mvResult = await sandbox.runCommand('mv', [sourceFile, targetFile])
86+
const mvResult = await sandbox.runCommand({
87+
cmd: 'mv',
88+
args: [sourceFile, targetFile],
89+
cwd: PROJECT_DIR,
90+
})
8291

8392
if (mvResult.exitCode !== 0) {
8493
const stderr = await mvResult.stderr()

0 commit comments

Comments
 (0)