feat(flight-finder): implement milestone M2 - report workflow and delivery gates
This commit is contained in:
59
skills/flight-finder/src/run-state.ts
Normal file
59
skills/flight-finder/src/run-state.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import type { FlightRunState } from "./types.js";
|
||||
|
||||
const DEFAULT_STATE_DIR = path.join(
|
||||
os.homedir(),
|
||||
".openclaw",
|
||||
"workspace",
|
||||
"state",
|
||||
"flight-finder"
|
||||
);
|
||||
|
||||
export function getFlightFinderStatePath(
|
||||
baseDir = DEFAULT_STATE_DIR
|
||||
): string {
|
||||
return path.join(baseDir, "flight-finder-run.json");
|
||||
}
|
||||
|
||||
export async function saveFlightFinderRunState(
|
||||
state: FlightRunState,
|
||||
baseDir = DEFAULT_STATE_DIR
|
||||
): Promise<string> {
|
||||
await fs.mkdir(baseDir, { recursive: true });
|
||||
const statePath = getFlightFinderStatePath(baseDir);
|
||||
await fs.writeFile(statePath, JSON.stringify(state, null, 2));
|
||||
return statePath;
|
||||
}
|
||||
|
||||
export async function loadFlightFinderRunState(
|
||||
baseDir = DEFAULT_STATE_DIR
|
||||
): Promise<FlightRunState | null> {
|
||||
const statePath = getFlightFinderStatePath(baseDir);
|
||||
try {
|
||||
const raw = await fs.readFile(statePath, "utf8");
|
||||
return JSON.parse(raw) as FlightRunState;
|
||||
} catch (error) {
|
||||
const maybeNodeError = error as NodeJS.ErrnoException;
|
||||
if (maybeNodeError.code === "ENOENT") {
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearFlightFinderRunState(
|
||||
baseDir = DEFAULT_STATE_DIR
|
||||
): Promise<void> {
|
||||
const statePath = getFlightFinderStatePath(baseDir);
|
||||
try {
|
||||
await fs.unlink(statePath);
|
||||
} catch (error) {
|
||||
const maybeNodeError = error as NodeJS.ErrnoException;
|
||||
if (maybeNodeError.code !== "ENOENT") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user