fix(cli): bound diagnostics and add swap management
This commit is contained in:
+67
-3
@@ -1,5 +1,5 @@
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { repoRoot, rootPath } from "./config";
|
||||
import { runCommandToFiles, tailFile } from "./command";
|
||||
@@ -141,6 +141,70 @@ export async function runJob(id: string): Promise<JobRecord> {
|
||||
return job;
|
||||
}
|
||||
|
||||
export function jobWithTail(job: JobRecord, maxBytes = 12000): JobRecord & { stdoutTail: string; stderrTail: string } {
|
||||
return { ...job, stdoutTail: tailFile(job.stdoutFile, maxBytes), stderrTail: tailFile(job.stderrFile, maxBytes) };
|
||||
export function jobWithTail(job: JobRecord, maxBytes = 12000): JobRecord & {
|
||||
tailPolicy: {
|
||||
requestedTailBytes: number;
|
||||
stdoutBytes: number;
|
||||
stderrBytes: number;
|
||||
stdoutTruncated: boolean;
|
||||
stderrTruncated: boolean;
|
||||
fullLogPaths: { stdoutFile: string; stderrFile: string };
|
||||
};
|
||||
stdoutTail: string;
|
||||
stderrTail: string;
|
||||
} {
|
||||
const stdoutBytes = existsSync(job.stdoutFile) ? statSync(job.stdoutFile).size : 0;
|
||||
const stderrBytes = existsSync(job.stderrFile) ? statSync(job.stderrFile).size : 0;
|
||||
return {
|
||||
...job,
|
||||
tailPolicy: {
|
||||
requestedTailBytes: maxBytes,
|
||||
stdoutBytes,
|
||||
stderrBytes,
|
||||
stdoutTruncated: stdoutBytes > maxBytes,
|
||||
stderrTruncated: stderrBytes > maxBytes,
|
||||
fullLogPaths: { stdoutFile: job.stdoutFile, stderrFile: job.stderrFile },
|
||||
},
|
||||
stdoutTail: tailFile(job.stdoutFile, maxBytes),
|
||||
stderrTail: tailFile(job.stderrFile, maxBytes),
|
||||
};
|
||||
}
|
||||
|
||||
export interface JobListOptions {
|
||||
limit?: number;
|
||||
includeCommand?: boolean;
|
||||
}
|
||||
|
||||
export function listJobsSummary(options: JobListOptions = {}): unknown {
|
||||
const limit = Math.max(1, Math.floor(options.limit ?? 50));
|
||||
const jobs = listJobs();
|
||||
const returned = jobs.slice(0, limit).map((job) => ({
|
||||
id: job.id,
|
||||
name: job.name,
|
||||
status: job.status,
|
||||
runner: job.runner,
|
||||
runnerPid: job.runnerPid ?? null,
|
||||
runnerContainer: job.runnerContainer ?? null,
|
||||
createdAt: job.createdAt,
|
||||
startedAt: job.startedAt,
|
||||
finishedAt: job.finishedAt,
|
||||
exitCode: job.exitCode,
|
||||
note: job.note,
|
||||
stdoutFile: job.stdoutFile,
|
||||
stderrFile: job.stderrFile,
|
||||
...(options.includeCommand === true ? { command: job.command, cwd: job.cwd } : {}),
|
||||
}));
|
||||
return {
|
||||
jobs: returned,
|
||||
total: jobs.length,
|
||||
returned: returned.length,
|
||||
limit,
|
||||
truncated: jobs.length > returned.length,
|
||||
disclosure: {
|
||||
defaultLimit: 50,
|
||||
nextCommand: jobs.length > returned.length ? `bun scripts/cli.ts job list --limit ${Math.min(jobs.length, limit * 2)}` : null,
|
||||
includeCommandCommand: "bun scripts/cli.ts job list --include-command",
|
||||
statusCommand: "bun scripts/cli.ts job status <jobId> --tail-bytes 12000",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user