fix: preserve HWLAB G14 monitor state pointer

This commit is contained in:
Codex
2026-05-27 07:00:01 +00:00
parent 6802fad158
commit fc7902f709
3 changed files with 59 additions and 3 deletions
+26 -2
View File
@@ -58,6 +58,20 @@ interface OpenPullRequest {
draft?: boolean;
}
export function hwlabG14MonitorStateFileName(options: Pick<G14MonitorOptions, "once" | "dryRun">): string {
if (options.once && options.dryRun) return "latest-once-dry-run-job.json";
if (options.once) return "latest-once-job.json";
if (options.dryRun) return "latest-dry-run-job.json";
return "latest-monitor-job.json";
}
function hwlabG14MonitorStateRole(options: Pick<G14MonitorOptions, "once" | "dryRun">): string {
if (options.once && options.dryRun) return "once-dry-run";
if (options.once) return "once";
if (options.dryRun) return "dry-run-monitor";
return "monitor";
}
function parseOptions(args: string[]): G14MonitorOptions {
return {
intervalSeconds: positiveIntegerOption(args, "--interval-seconds", DEFAULT_INTERVAL_SECONDS, 86400),
@@ -648,6 +662,12 @@ export function hwlabG14Help(): Record<string, unknown> {
devApplication: DEV_APP,
briefIndexIssue: G14_BRIEF_INDEX_ISSUE,
},
stateFiles: {
monitor: ".state/hwlab-g14/latest-monitor-job.json",
once: ".state/hwlab-g14/latest-once-job.json",
dryRun: ".state/hwlab-g14/latest-dry-run-job.json",
onceDryRun: ".state/hwlab-g14/latest-once-dry-run-job.json",
},
};
}
@@ -668,9 +688,11 @@ export async function runHwlabG14Command(_config: Config, args: string[]): Promi
const statusCommand = `bun scripts/cli.ts job status ${job.id} --tail-bytes 30000`;
const stateDir = rootPath(".state", "hwlab-g14");
mkdirSync(stateDir, { recursive: true });
const latestPath = join(stateDir, "latest-monitor-job.json");
const stateFileName = hwlabG14MonitorStateFileName(options);
const stateFileRole = hwlabG14MonitorStateRole(options);
const latestPath = join(stateDir, stateFileName);
const previousLatest = existsSync(latestPath) ? readFileSync(latestPath, "utf8") : null;
writeFileSync(latestPath, `${JSON.stringify({ jobId: job.id, createdAt: job.createdAt, statusCommand }, null, 2)}\n`, "utf8");
writeFileSync(latestPath, `${JSON.stringify({ jobId: job.id, createdAt: job.createdAt, statusCommand, role: stateFileRole }, null, 2)}\n`, "utf8");
return {
ok: true,
command: "hwlab g14 monitor-prs",
@@ -678,6 +700,8 @@ export async function runHwlabG14Command(_config: Config, args: string[]): Promi
job,
statusCommand,
latestPath,
stateFileName,
stateFileRole,
previousLatest,
next: {
status: statusCommand,