Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"adlc-skills-cli": "bin/adlc-skills-cli.mjs"
},
"scripts": {
"test": "node --test && node tests/e2e-node-gate.mjs --skip-agent",
"test": "node --test && node tests/e2e-node-gate.mjs --skip-agent && node tests/e2e-cross-session.mjs",
"test:evals": "node --test evals/opencode-session-end/tests/test_check_session_end.mjs",
"test:all": "npm test && npm run test:evals",
"prepublishOnly": "npm test",
Expand Down
89 changes: 89 additions & 0 deletions src/commands/workflow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
stateShow,
} from "../workflow/state.mjs";
import { parkRun, restoreRun } from "../workflow/refs.mjs";
import { buildBoardIndex } from "../workflow/board.mjs";
import { printWorkflowHelp } from "../help.mjs";
import { classifyWorkflowStatus } from "../exit-codes.mjs";
import { StepStatus } from "../workflow/base.mjs";
Expand All @@ -36,6 +37,7 @@ import {
success,
failure,
note,
warn,
panel,
table,
keyValue,
Expand Down Expand Up @@ -69,6 +71,8 @@ export async function cmdWorkflow(args, flags, rawArgv) {
return cmdWorkflowPark(rest, rawArgv);
case "restore":
return cmdWorkflowRestore(rest, rawArgv);
case "board":
return cmdWorkflowBoard(rest, rawArgv);
case "search":
return cmdWorkflowSearch(rest, rawArgv);
case "add":
Expand Down Expand Up @@ -508,6 +512,91 @@ function valuedFlagValues(rawArgv) {
return values;
}

// ── board (ADR-476 pane of glass v1) ──────────────────────────────────────

// One view over every factory run: local run dirs + remote
// refs/factory-runs/* (ADR-475/490). The index is derived fresh every call
// and never persisted (ADR-325 stateless aggregation; ADR-490 disposable
// index). Degrades per source: an unreachable remote keeps the board
// local-only (warning, exit 0); unreadable refs are skipped and counted.
async function cmdWorkflowBoard(rest, rawArgv) {
const remote = extractFlagValue(rawArgv, "remote") ?? "origin";
let board;
try {
board = buildBoardIndex({ projectRoot: process.cwd(), remote });
} catch (exc) {
error(exc.message);
return 1;
}

// Machine contract for the future web dashboard (ADR-325 SPA): stdout is
// the JSON index and nothing else; remote errors ride inside the doc.
if (hasFlag(rawArgv, "format") && extractFlagValue(rawArgv, "format") === "json") {
out(
JSON.stringify(
{ runs: board.runs, remoteError: board.remoteError, skippedRemote: board.skippedRemote },
null,
2,
),
);
return 0;
}

if (board.remoteError !== null) {
warn(
combine(
style(sym.warn, "yellow"),
` remote "${remote}" unreachable — showing local runs only (`,
tint(board.remoteError, "gray"),
")",
),
);
}

if (board.runs.length === 0) {
out("");
note(`No factory runs found (local ${RUNS_DIR} + ${remote}:refs/factory-runs/*)`);
if (board.skippedRemote > 0) {
note(`Skipped ${board.skippedRemote} unreadable remote ref(s)`);
}
out("");
return 0;
}

out("");
out(
table({
title: `Factory board — ${board.runs.length} run${board.runs.length === 1 ? "" : "s"} (${remote})`,
columns: [
{ header: "Run ID", style: ACCENT },
{ header: "Source" },
{ header: "Status" },
{ header: "Current", optional: true },
{ header: "Outcome", optional: true },
{ header: "Retention", optional: true },
{ header: "Issue", optional: true },
{ header: "Updated", optional: true },
],
rows: board.runs.map((r) => [
r.run_id,
r.source,
statusCell(r.status ?? "unknown"),
r.current_step_id ?? "",
r.outcome ?? "",
r.retention_class ?? "",
r.issue_ref ?? "",
r.updated_at ?? "",
]),
}),
);
if (board.skippedRemote > 0) {
out("");
note(`Skipped ${board.skippedRemote} unreadable remote ref(s) — no parsable state.json`);
}
out("");
return 0;
}

// ── status ───────────────────────────────────────────────────────────────

async function cmdWorkflowStatus(rest) {
Expand Down
1 change: 1 addition & 0 deletions src/dispatch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ async function runNewTree({ command, args, flags }, argv) {
case "state":
case "park":
case "restore":
case "board":
case "search":
case "add":
case "list":
Expand Down
2 changes: 2 additions & 0 deletions src/help.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function printCliHelp() {
["workflow resume <run_id>", "Resume a paused/failed run (optionally with --input)"],
["workflow park <run_id>", "Save a gate-paused run + thread handle to the remote run ref"],
["workflow restore <run_id>", "Restore a parked run from the remote run ref"],
["workflow board [--remote <name>]", "Pane of glass: local runs + remote refs/factory-runs/* (--format json)"],
["workflow status [run_id]", "List runs / show one run's step states"],
["workflow validate <src>", "Validate a workflow definition (--headless checks gate verdicts)"],
["workflow search [query]", "Search available workflows in catalog"],
Expand Down Expand Up @@ -418,6 +419,7 @@ export function printWorkflowHelp() {
["resume <run_id>", "Resume a paused/failed run (gates re-prompt)"],
["park <run_id>", "Save a gate-paused run (+ --handle-file <json>) to refs/factory-runs/<run_id> on --remote (default origin)"],
["restore <run_id>", "Fetch refs/factory-runs/<run_id> from --remote into .adlc/workflows/runs/<run_id>/ (refuses an existing run dir or a different --issue-ref)"],
["board [--remote <name>]", "Pane of glass (ADR-476): all factory runs — local run dirs + remote refs/factory-runs/* fetched namespaced; --format json for machines; degrades to local-only on unreachable remote"],
["status [run_id]", "List all runs / show one run's step states"],
["validate <source>", "Validate a workflow definition"],
["search [query]", "Search available workflows in catalog"],
Expand Down
184 changes: 184 additions & 0 deletions src/workflow/board.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Factory board — pane of glass v1 (ADR-476) over local run dirs and remote
// refs/factory-runs/* (ADR-475/490). The index is derived and disposable:
// computed fresh on every invocation, nothing persisted (ADR-325 stateless
// aggregation; ADR-490 keeps refs authoritative and the index replaceable).
//
// Remote reads fetch into refs/remotes/<remote>/factory-runs/* — never the
// local refs/factory-runs/* a live machine may be pushing. Depth-1 + prune
// keeps the fetch light and drops refs deleted on the remote.

import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
import { checkRemote } from "./refs.mjs";

const RUNS_DIR = ".adlc/workflows/runs";
const RUN_REF_PREFIX = "refs/factory-runs/";
const REMOTE_REF_PREFIX = "refs/remotes/";

function git(projectRoot, args) {
return spawnSync("git", args, {
cwd: projectRoot,
encoding: "utf-8",
maxBuffer: 16 * 1024 * 1024,
});
}

function gitText(projectRoot, args) {
const r = git(projectRoot, args);
if (r.error || r.status !== 0) return null;
return String(r.stdout ?? "");
}

// ── local source ──────────────────────────────────────────────────────────

function readJsonIfPresent(path) {
if (!existsSync(path)) return null;
try {
return JSON.parse(readFileSync(path, "utf-8"));
} catch {
return null;
}
}

function localRuns(projectRoot) {
const runsDir = join(projectRoot, RUNS_DIR);
const rows = [];
if (!existsSync(runsDir)) return rows;
for (const entry of readdirSync(runsDir).sort()) {
const runDir = join(runsDir, entry);
try {
if (!statSync(runDir).isDirectory()) continue;
} catch {
continue;
}
const state = readJsonIfPresent(join(runDir, "state.json"));
if (!state || typeof state.run_id !== "string") continue;
const manifest = readJsonIfPresent(join(runDir, "trace", "manifest.json"));
rows.push({ state, manifest });
}
return rows;
}

// ── remote source ─────────────────────────────────────────────────────────

// Fetch every remote run ref into the namespaced remotes area. Returns
// { error } on failure — the board degrades to local-only (ADR-325).
function fetchRemoteRefs(projectRoot, remote) {
const refspec = `+${RUN_REF_PREFIX}*:${REMOTE_REF_PREFIX}${remote}/factory-runs/*`;
const r = git(projectRoot, ["fetch", "--quiet", "--prune", "--depth", "1", remote, refspec]);
if (r.error || r.status !== 0) {
const detail = r.error ? r.error.message : String(r.stderr ?? "").trim();
return { error: detail || "fetch failed" };
}
return { error: null };
}

function remoteRunIds(projectRoot, remote) {
const listing = gitText(projectRoot, [
"for-each-ref", "--format=%(refname)", `${REMOTE_REF_PREFIX}${remote}/factory-runs/`,
]);
if (listing === null) return [];
return listing
.split("\n")
.map((line) => line.trim())
.filter(Boolean)
.map((refname) => refname.slice(`${REMOTE_REF_PREFIX}${remote}/factory-runs/`.length))
.filter((id) => id.length > 0);
}

function remoteRunRow(projectRoot, remote, runId) {
const ref = `${REMOTE_REF_PREFIX}${remote}/factory-runs/${runId}`;
const sha = gitText(projectRoot, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
const stateText = gitText(projectRoot, ["show", `${ref}:state.json`]);
if (stateText === null) return null; // legacy/garbage ref — skipped, counted
let state;
try {
state = JSON.parse(stateText);
} catch {
return null;
}
if (!state || typeof state.run_id !== "string") return null;
const manifestText = gitText(projectRoot, ["show", `${ref}:trace/manifest.json`]);
let manifest = null;
if (manifestText !== null) {
try {
manifest = JSON.parse(manifestText);
} catch {}
}
return { state, manifest, remoteSha: sha ? sha.trim() : null };
}

// ── index ─────────────────────────────────────────────────────────────────

function rowFrom({ state, manifest, remoteSha, source }) {
return {
run_id: state.run_id,
source,
workflow_id: state.workflow_id ?? manifest?.workflow_id ?? null,
status: state.status ?? manifest?.outcome ?? null,
current_step_id: state.current_step_id ?? null,
outcome: manifest?.outcome ?? state.status ?? null,
retention_class: manifest?.retention_class ?? null,
issue_ref: manifest?.issue_ref ?? state.inputs?.issue_ref ?? null,
updated_at: manifest?.updated_at ?? state.updated_at ?? null,
remote_sha: remoteSha ?? null,
};
}

// Build the pane-of-glass index. Degrades per source: a failed remote fetch
// sets remoteError and the board shows local runs only; refs that do not
// parse are skipped and counted in skippedRemote.
export function buildBoardIndex({ projectRoot = process.cwd(), remote = "origin" } = {}) {
// A remote is a name or URL, never a git option (refs.mjs checkRemote —
// same guard park/restore use): a value like `--upload-pack=<cmd>` would
// be parsed by git fetch as an option and run <cmd>. Validated here, at
// the single entry point before any git call, so both flag forms
// (`--remote x`, `--remote=x`) are covered.
checkRemote(remote);
const local = new Map(localRuns(projectRoot).map((r) => [r.state.run_id, r]));

let remoteError = null;
let skippedRemote = 0;
const remoteMap = new Map();
const fetch = fetchRemoteRefs(projectRoot, remote);
if (fetch.error !== null) {
remoteError = fetch.error;
} else {
for (const runId of remoteRunIds(projectRoot, remote)) {
const row = remoteRunRow(projectRoot, remote, runId);
if (row === null) {
skippedRemote += 1;
continue;
}
remoteMap.set(runId, row);
}
}

const rows = [];
for (const [runId, entry] of local) {
const remoteEntry = remoteMap.get(runId);
rows.push(
rowFrom({
state: entry.state,
manifest: entry.manifest,
remoteSha: remoteEntry?.remoteSha ?? null,
source: remoteEntry ? "both" : "local",
}),
);
}
for (const [runId, entry] of remoteMap) {
if (local.has(runId)) continue;
rows.push(
rowFrom({
state: entry.state,
manifest: entry.manifest,
remoteSha: entry.remoteSha,
source: "remote",
}),
);
}

rows.sort((a, b) => String(b.updated_at ?? "").localeCompare(String(a.updated_at ?? "")));
return { runs: rows, remoteError, skippedRemote };
}
Loading
Loading