feat(offload): update status command for container-aware job discovery

This commit is contained in:
mkorwel
2026-03-15 12:09:59 -07:00
parent e2ad7f4ecb
commit fb8ec967c1
+21 -25
View File
@@ -1,41 +1,38 @@
/** /**
* Offload Status Inspector (Remote) * Offload Status Inspector (Remote)
* *
* Scans tmux sessions and logs to provide a real-time status of offload jobs. * Scans tmux sessions (host) and logs (container) to provide job status.
*/ */
import { spawnSync } from 'child_process'; import { spawnSync } from 'child_process';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import os from 'os'; import os from 'os';
const WORKTREE_BASE = path.join(os.homedir(), 'dev/worktrees'); const WORKTREE_BASE = '/home/node/dev/worktrees';
function getStatus() { function getStatus() {
console.log('\n🛰️ Offload Mission Control Status:'); console.log('\n🛰️ Offload Mission Control Status (Container Mode):');
console.log(''.padEnd(80, '-')); console.log(''.padEnd(100, '-'));
console.log(`${'JOB ID'.padEnd(10)} | ${'ACTION'.padEnd(10)} | ${'STATE'.padEnd(12)} | ${'SESSION'.padEnd(25)}`); console.log(`${'JOB ID'.padEnd(10)} | ${'ACTION'.padEnd(10)} | ${'STATE'.padEnd(12)} | ${'SESSION'.padEnd(25)}`);
console.log(''.padEnd(80, '-')); console.log(''.padEnd(100, '-'));
// 1. Get active tmux sessions // 1. Get active tmux sessions on the HOST
const tmux = spawnSync('tmux', ['ls', '-F', '#{session_name}']); const tmux = spawnSync('tmux', ['ls', '-F', '#{session_name}']);
const activeSessions = tmux.stdout.toString().split('\n').filter(s => s.startsWith('offload-')); const activeSessions = tmux.stdout.toString().split('\n').filter(s => s.startsWith('offload-'));
// 2. Scan worktrees for job history // 2. Scan worktrees inside the CONTAINER
if (!fs.existsSync(WORKTREE_BASE)) { const findJobs = spawnSync('docker', ['exec', 'gemini-sandbox', 'ls', WORKTREE_BASE], { stdio: 'pipe' });
console.log(' No jobs found.'); const jobs = findJobs.stdout.toString().split('\n').filter(d => d.startsWith('offload-'));
return;
}
const jobs = fs.readdirSync(WORKTREE_BASE).filter(d => d.startsWith('offload-'));
if (jobs.length === 0 && activeSessions.length === 0) { if (jobs.length === 0 && activeSessions.length === 0) {
console.log(' No jobs found.'); console.log(' No jobs found.');
return; return;
} }
const allJobIds = new Set([...jobs, ...activeSessions.map(s => s)]); const allJobIds = Array.from(new Set([...jobs, ...activeSessions]));
allJobIds.forEach(id => { allJobIds.forEach(id => {
if (!id) return;
const parts = id.split('-'); // offload-123-review const parts = id.split('-'); // offload-123-review
const pr = parts[1] || '???'; const pr = parts[1] || '???';
const action = parts[2] || '???'; const action = parts[2] || '???';
@@ -44,16 +41,15 @@ function getStatus() {
if (activeSessions.includes(id)) { if (activeSessions.includes(id)) {
state = '🏃 RUNNING'; state = '🏃 RUNNING';
} else { } else {
// Check logs for final state // Check logs inside the container
const logDir = path.join(WORKTREE_BASE, id, '.gemini/logs'); const logCheck = spawnSync('docker', ['exec', 'gemini-sandbox', 'sh', '-c', `ls ${WORKTREE_BASE}/${id}/.gemini/logs/*.log 2>/dev/null | tail -n 1`], { stdio: 'pipe' });
if (fs.existsSync(logDir)) { const lastLogFile = logCheck.stdout.toString().trim();
const logFiles = fs.readdirSync(logDir).sort();
if (logFiles.length > 0) { if (lastLogFile) {
const lastLog = fs.readFileSync(path.join(logDir, logFiles[logFiles.length - 1]), 'utf8'); const logContent = spawnSync('docker', ['exec', 'gemini-sandbox', 'cat', lastLogFile], { stdio: 'pipe' }).stdout.toString();
if (lastLog.includes('SUCCESS')) state = '✅ SUCCESS'; if (logContent.includes('SUCCESS')) state = '✅ SUCCESS';
else if (lastLog.includes('FAILED')) state = '❌ FAILED'; else if (logContent.includes('FAILED')) state = '❌ FAILED';
else state = '🏁 FINISHED'; else state = '🏁 FINISHED';
}
} }
} }
@@ -63,7 +59,7 @@ function getStatus() {
console.log(` └─ Logs: npm run offload:logs ${pr} ${action}`); console.log(` └─ Logs: npm run offload:logs ${pr} ${action}`);
} }
}); });
console.log(''.padEnd(80, '-')); console.log(''.padEnd(100, '-'));
} }
getStatus(); getStatus();