feat: add tabular Work summaries and CSV exports

This commit is contained in:
2026-11-16 15:59:26 +00:00
parent 1e440c12ee
commit 3c75ce70f6
21 changed files with 642 additions and 5 deletions
@@ -164,10 +164,26 @@ public final class EngineeringCli implements Runnable {
}
@Command(name = "status", mixinStandardHelpOptions = true, description = "Inspect Works, validation and suggested next actions.")
int status(@Option(names = "--all", description = "Include archived Works.") boolean all,
@Option(names = "--format", defaultValue = "markdown") Format format) { return emit(verification.status(root(), all), format); }
@Option(names = "--format", defaultValue = "markdown", description = "Output: ${COMPLETION-CANDIDATES}.") Listing.Format format) {
Path root = root();
if (format == Listing.Format.json) return emit(verification.status(root, all), Format.json);
var state = new CompatibilityService().inspect(root).summary();
var selected = works.list(root).stream().filter(w -> all || !w.archived()).toList();
if (format != Listing.Format.csv) {
String name = projects.load(root).project().name();
String details = (format == Listing.Format.markdown ? Listing.markdown(name) : Listing.singleLine(name)) + " | Onboarded: " + ProtocolGuide.installed(root)
+ " | Compatibility: " + state.state();
output.println(format == Listing.Format.markdown ? "# Project status\n\n" + details + "\n" : details + "\n");
}
output.print(Listing.works(verification.overview(root, selected), format)); return 0;
}
@Command(name = "next-actions", mixinStandardHelpOptions = true, description = "Suggest deterministic next actions; does not execute them.")
int nextActions(@Parameters(index = "0", arity = "0..1") String id,
@Option(names = "--format", defaultValue = "markdown") Format format) { return emit(verification.nextActions(root(), id), format); }
@Option(names = "--format", defaultValue = "markdown", description = "Output: ${COMPLETION-CANDIDATES}.") Listing.Format format) {
var actions = verification.nextActions(root(), id);
if (format == Listing.Format.json) return emit(actions, Format.json);
output.print(Listing.actions(actions, format)); return 0;
}
@Command(name = "project", mixinStandardHelpOptions = true, description = "Inspect and validate the engineering project.")
public class ProjectCommands {
@Command(name = "compatibility", mixinStandardHelpOptions = true,
@@ -216,7 +232,13 @@ public final class EngineeringCli implements Runnable {
return emit(works.create(root(), title, description, goal, motivation, safe(constraints), safe(criteria), safe(repositories), author), Format.markdown);
}
@Command(name = "list", mixinStandardHelpOptions = true)
int list(@Option(names = "--format", defaultValue = "markdown") Format format) { return emit(works.list(root()), format); }
int list(@Option(names = "--open", description = "Only nonterminal, unarchived Works (OPEN, ACTIVE, BLOCKED).") boolean open,
@Option(names = "--format", defaultValue = "markdown", description = "Output: ${COMPLETION-CANDIDATES}.") Listing.Format format) {
Path root = root();
var selected = works.list(root).stream().filter(w -> !open || (!w.terminal() && !w.archived())).toList();
if (format == Listing.Format.json) return emit(selected, Format.json);
output.print(Listing.works(verification.overview(root, selected), format)); return 0;
}
@Command(name = "show", mixinStandardHelpOptions = true)
int show(@Parameters(index = "0") String id, @Option(names = "--format", defaultValue = "markdown") Format format) { return emit(works.load(root(), id), format); }
@Command(name = "update", mixinStandardHelpOptions = true, description = "Update specified Work fields, preserving history and references.")
@@ -0,0 +1,68 @@
package net.intrepid.aiengineering.cli;
import net.intrepid.aiengineering.verification.VerificationService;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/** Presentation only: no file access, transitions, or model calls. */
final class Listing {
enum Format { markdown, json, table, csv }
static String works(List<VerificationService.Overview> works, Format format) {
var rows = works.stream().map(view -> List.of(view.work().id(), view.work().title(),
view.work().status().name(), Boolean.toString(view.work().archived()), view.steps(),
Integer.toString(view.nextActions().size()), view.validation().valid() ? "valid" : "INVALID",
view.nextActions().isEmpty() ? "" : view.nextActions().getFirst().command())).toList();
return render(List.of("id", "title", "status", "archived", "steps", "pending_actions", "validation", "next_action"),
List.of("ID", "Title", "Status", "Archived", "Steps", "Pending actions", "Validation", "Next action"), rows, format);
}
static String actions(List<VerificationService.Action> actions, Format format) {
var rows = actions.stream().map(action -> List.of(action.workId() == null ? "" : action.workId(),
action.code(), action.message(), action.command())).toList();
return render(List.of("work_id", "code", "message", "command"),
List.of("Work", "Action", "Pending", "Command"), rows, format);
}
private static String render(List<String> csvHeaders, List<String> headers, List<List<String>> rows, Format format) {
if (format == Format.csv) return line(csvHeaders, Listing::csv, ",", "", "\r\n")
+ String.join("", rows.stream().map(row -> line(row, Listing::csv, ",", "", "\r\n")).toList());
if (format == Format.markdown) return line(headers, Listing::markdown, " | ", "| ", " |\n")
+ line(headers.stream().map(_ -> "---").toList(), Function.identity(), " | ", "| ", " |\n")
+ String.join("", rows.stream().map(row -> line(row, Listing::markdown, " | ", "| ", " |\n")).toList());
if (format != Format.table) throw new IllegalArgumentException("JSON listings use the full data contract");
var cells = new ArrayList<List<String>>(); cells.add(headers);
cells.addAll(rows.stream().map(row -> row.stream().map(Listing::singleLine).toList()).toList());
int[] widths = new int[headers.size()];
for (var row : cells) for (int i = 0; i < widths.length; i++) widths[i] = Math.max(widths[i], width(row.get(i)));
var result = new StringBuilder();
for (int r = 0; r < cells.size(); r++) {
var row = cells.get(r);
for (int i = 0; i < widths.length; i++) {
if (i > 0) result.append(" ");
result.append(row.get(i));
if (i < widths.length - 1) result.append(" ".repeat(widths[i] - width(row.get(i))));
}
result.append('\n');
if (r == 0) result.append(String.join(" ", java.util.Arrays.stream(widths).mapToObj(w -> "-".repeat(w)).toList())).append('\n');
}
return result.toString();
}
private static int width(String value) { return value.codePointCount(0, value.length()); }
private static String line(List<String> row, Function<String, String> escape, String separator, String prefix, String suffix) {
return prefix + String.join(separator, row.stream().map(escape).toList()) + suffix;
}
private static String csv(String value) {
return value.contains(",") || value.contains("\"") || value.contains("\r") || value.contains("\n")
? "\"" + value.replace("\"", "\"\"") + "\"" : value;
}
static String singleLine(String value) { return value.replaceAll("[\\p{Cntrl}\\p{Zl}\\p{Zp}]", " "); }
static String markdown(String value) {
return value.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
.replace("\\", "&#92;").replace("|", "&#124;").replace("`", "&#96;")
.replace("*", "&#42;").replace("_", "&#95;").replace("[", "&#91;").replace("]", "&#93;")
.replace("\r\n", "\n").replace("\r", "\n").replace("\n", "<br>").replaceAll("[\\p{Cntrl}\\p{Zl}\\p{Zp}]", " ");
}
}
@@ -270,6 +270,22 @@ public final class VerificationService {
public record WorkSummary(String id, String title, Work.Status status, boolean archived, ValidationReport validation, List<Action> nextActions) {}
public record ProjectStatus(int schemaVersion, ProjectConfig.Identity project, boolean onboarded, List<WorkSummary> works,
CompatibilityService.Summary compatibility) {}
/** Read-only projection for human listings; the full JSON contracts remain unchanged. */
public record Overview(Work work, String steps, ValidationReport validation, List<Action> nextActions) {}
public List<Overview> overview(Path root, List<Work> selected) {
return selected.stream().map(w -> {
var validation = work(root, w.id());
String progress = "unavailable";
try {
var steps = plans.list(root, w.id()).stream().flatMap(p -> p.steps().stream()).toList();
progress = steps.stream().filter(s -> s.status() == Plan.Status.COMPLETED).count() + "/" + steps.size();
} catch (ProtocolException failure) {
if (validation.valid()) throw failure;
// Keep repairable Works visible without claiming a zero-step plan.
}
return new Overview(w, progress, validation, actions(root, w, validation));
}).toList();
}
public ProjectStatus status(Path root, boolean all) {
return new ProjectStatus(1, projects.load(root).project(), ProtocolGuide.installed(root), works.list(root).stream()
.filter(w -> all || !w.archived()).map(w -> new WorkSummary(w.id(), w.title(), w.status(), w.archived(), work(root, w.id()), actions(root, w))).toList(),
@@ -282,8 +298,10 @@ public final class VerificationService {
selected.forEach(w -> result.addAll(actions(root, w))); return List.copyOf(result);
}
private List<Action> actions(Path root, Work work) {
return actions(root, work, work(root, work.id()));
}
private List<Action> actions(Path root, Work work, ValidationReport validation) {
String id = work.id(); var actions = new ArrayList<Action>();
var validation = work(root, id);
if (!validation.valid()) return List.of(new Action(work.epic() ? "RECONCILE_EPIC" : "REPAIR_PROTOCOL", id,
String.join("; ", validation.issues()), work.epic() ? "aie epic reconcile " + id : "aie work validate " + id));
if (work.archived()) return List.of(new Action("REOPEN", id, "Reopen only when new work is needed", "aie work reopen " + id + " --help"));