mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-26 14:01:14 -07:00
feat(offload): update status command for container-aware job discovery
This commit is contained in:
@@ -1,41 +1,38 @@
|
||||
/**
|
||||
* 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 fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
|
||||
const WORKTREE_BASE = path.join(os.homedir(), 'dev/worktrees');
|
||||
const WORKTREE_BASE = '/home/node/dev/worktrees';
|
||||
|
||||
function getStatus() {
|
||||
console.log('\n🛰️ Offload Mission Control Status:');
|
||||
console.log(''.padEnd(80, '-'));
|
||||
console.log('\n🛰️ Offload Mission Control Status (Container Mode):');
|
||||
console.log(''.padEnd(100, '-'));
|
||||
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 activeSessions = tmux.stdout.toString().split('\n').filter(s => s.startsWith('offload-'));
|
||||
|
||||
// 2. Scan worktrees for job history
|
||||
if (!fs.existsSync(WORKTREE_BASE)) {
|
||||
console.log(' No jobs found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const jobs = fs.readdirSync(WORKTREE_BASE).filter(d => d.startsWith('offload-'));
|
||||
// 2. Scan worktrees inside the CONTAINER
|
||||
const findJobs = spawnSync('docker', ['exec', 'gemini-sandbox', 'ls', WORKTREE_BASE], { stdio: 'pipe' });
|
||||
const jobs = findJobs.stdout.toString().split('\n').filter(d => d.startsWith('offload-'));
|
||||
|
||||
if (jobs.length === 0 && activeSessions.length === 0) {
|
||||
console.log(' No jobs found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const allJobIds = new Set([...jobs, ...activeSessions.map(s => s)]);
|
||||
const allJobIds = Array.from(new Set([...jobs, ...activeSessions]));
|
||||
|
||||
allJobIds.forEach(id => {
|
||||
if (!id) return;
|
||||
const parts = id.split('-'); // offload-123-review
|
||||
const pr = parts[1] || '???';
|
||||
const action = parts[2] || '???';
|
||||
@@ -44,16 +41,15 @@ function getStatus() {
|
||||
if (activeSessions.includes(id)) {
|
||||
state = '🏃 RUNNING';
|
||||
} else {
|
||||
// Check logs for final state
|
||||
const logDir = path.join(WORKTREE_BASE, id, '.gemini/logs');
|
||||
if (fs.existsSync(logDir)) {
|
||||
const logFiles = fs.readdirSync(logDir).sort();
|
||||
if (logFiles.length > 0) {
|
||||
const lastLog = fs.readFileSync(path.join(logDir, logFiles[logFiles.length - 1]), 'utf8');
|
||||
if (lastLog.includes('SUCCESS')) state = '✅ SUCCESS';
|
||||
else if (lastLog.includes('FAILED')) state = '❌ FAILED';
|
||||
else state = '🏁 FINISHED';
|
||||
}
|
||||
// Check logs inside the container
|
||||
const logCheck = spawnSync('docker', ['exec', 'gemini-sandbox', 'sh', '-c', `ls ${WORKTREE_BASE}/${id}/.gemini/logs/*.log 2>/dev/null | tail -n 1`], { stdio: 'pipe' });
|
||||
const lastLogFile = logCheck.stdout.toString().trim();
|
||||
|
||||
if (lastLogFile) {
|
||||
const logContent = spawnSync('docker', ['exec', 'gemini-sandbox', 'cat', lastLogFile], { stdio: 'pipe' }).stdout.toString();
|
||||
if (logContent.includes('SUCCESS')) state = '✅ SUCCESS';
|
||||
else if (logContent.includes('FAILED')) state = '❌ FAILED';
|
||||
else state = '🏁 FINISHED';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +59,7 @@ function getStatus() {
|
||||
console.log(` └─ Logs: npm run offload:logs ${pr} ${action}`);
|
||||
}
|
||||
});
|
||||
console.log(''.padEnd(80, '-'));
|
||||
console.log(''.padEnd(100, '-'));
|
||||
}
|
||||
|
||||
getStatus();
|
||||
|
||||
Reference in New Issue
Block a user