@staix/agent-research 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +84 -19
- package/package.json +4 -1
- package/src/cli-output.ts +446 -0
- package/src/cli.ts +208 -66
- package/src/commands-table.ts +213 -93
- package/src/commands.ts +75 -13
- package/src/exp/attempts.ts +13 -1
- package/src/exp/calibrate.ts +125 -0
- package/src/exp/executor.ts +98 -13
- package/src/exp/final.ts +12 -3
- package/src/exp/idea-report.ts +97 -0
- package/src/exp/ideas.ts +90 -6
- package/src/exp/investigate.ts +25 -22
- package/src/exp/protocol.ts +26 -1
- package/src/exp/screen.ts +83 -0
- package/src/exp/selection.ts +110 -4
- package/src/exp/stages.ts +3 -1
- package/src/harness/transitions.ts +37 -5
- package/src/manifest.ts +13 -5
- package/src/mcp-tools.ts +67 -14
- package/src/memory/archive.ts +8 -3
- package/src/paper/build.ts +39 -25
- package/src/paper/check.ts +46 -15
- package/src/paper/dependencies.ts +47 -0
- package/src/paper/document.ts +19 -0
- package/src/paper/figures.ts +152 -0
- package/src/paper/hygiene.ts +16 -5
- package/src/paper/plan.ts +71 -29
- package/src/paper/point-evidence.ts +27 -12
- package/src/paper/render.ts +113 -0
- package/src/paper/renderer.ts +128 -0
- package/src/paper/review.ts +41 -5
- package/src/plan/definition.ts +6 -1
- package/src/playbook.ts +20 -10
- package/src/provenance.ts +4 -3
- package/src/study-export.ts +7 -4
- package/src/study.ts +9 -4
- package/src/ui/plugin.ts +3 -1
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { cellWidth, wrap, asciiMarkers, errorLine, errorSpans, paint, Report, resolveColor, streamEnv, streamWidth, terminalText, MARKERS, markerCell, type MarkerName } from "@staix/cli-output";
|
|
2
|
+
|
|
3
|
+
import { COMMANDS, GLOBAL_HELP_FLAGS, flagDescription, helpFlagLabel, helpUsage, type CommandSpec } from "./commands-table.ts";
|
|
4
|
+
|
|
5
|
+
import { shellQuote } from "./exp/executor.ts";
|
|
6
|
+
|
|
7
|
+
export interface OutputOptions {
|
|
8
|
+
color?: string;
|
|
9
|
+
ascii?: boolean;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function colorFor(options: OutputOptions, isTTY: boolean, env = process.env): boolean | Error {
|
|
14
|
+
const color = resolveColor(options.color, streamEnv(isTTY, env), "ares");
|
|
15
|
+
return options.json && !(color instanceof Error) ? false : color;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function label(key: string): string {
|
|
19
|
+
return key.replace(/([a-z])([A-Z])/g, "$1 $2").replaceAll("_", " ").replace(/\s+/g, " ").replace(/^./, character => character.toUpperCase());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function rows(report: Report, value: unknown, indent = 2): void {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
if (!value.length) report.note("None");
|
|
25
|
+
for (const item of value) {
|
|
26
|
+
if (item !== null && typeof item === "object") {
|
|
27
|
+
rows(report, item, indent + 2);
|
|
28
|
+
} else {
|
|
29
|
+
report.note(String(item), "value");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (value === null || typeof value !== "object") {
|
|
35
|
+
report.kv([["Result", value]], indent);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const fields = Object.entries(value).filter(([, field]) => field !== undefined);
|
|
39
|
+
report.kv(fields.filter(([, field]) => field === null || typeof field !== "object").map(([key, field]) => [label(key), field]), indent);
|
|
40
|
+
for (const [key, field] of fields) {
|
|
41
|
+
if (field === null || typeof field !== "object") continue;
|
|
42
|
+
if (indent === 2) report.section(label(key), Array.isArray(field) ? String(field.length) : undefined);
|
|
43
|
+
else report.kv([[label(key), ""]], indent);
|
|
44
|
+
rows(report, field, indent + (indent === 2 ? 0 : 2));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Row = Record<string, unknown>;
|
|
49
|
+
const record = (value: unknown): Row => value && typeof value === "object" && !Array.isArray(value) ? value as Row : {};
|
|
50
|
+
const array = (value: unknown): unknown[] => Array.isArray(value) ? value : [];
|
|
51
|
+
const text = (value: unknown): string => typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
52
|
+
const commandLine = (args: string[]) => ["ares", ...args.map(shellQuote)].join(" ");
|
|
53
|
+
const statusMarker = (value: string): MarkerName =>
|
|
54
|
+
["approved", "succeeded", "done", "qualified", "verified", "included", "ok"].includes(value) ? "ok"
|
|
55
|
+
: ["failed", "rejected", "lost", "not_qualified"].includes(value) ? "fail"
|
|
56
|
+
: ["unknown", "skipped"].includes(value) ? "unknown"
|
|
57
|
+
: ["pending", "running", "new", "paused"].includes(value) ? "pending" : "absent";
|
|
58
|
+
|
|
59
|
+
function stateCell(report: Report, state: string) {
|
|
60
|
+
const marker = statusMarker(state);
|
|
61
|
+
return { text: `${markerCell(marker, report.ascii)} ${state}`, role: MARKERS[marker].role };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface OutputContext {
|
|
65
|
+
args: string[];
|
|
66
|
+
values: Readonly<Record<string, string>>;
|
|
67
|
+
now: number;
|
|
68
|
+
previewCount?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function fillMessage(message: string, values: Readonly<Record<string, string>>): string {
|
|
72
|
+
const quoted = (key: string, original: string) => Object.hasOwn(values, key) ? shellQuote(values[key]!) : original;
|
|
73
|
+
return message.replace(/<([a-z][a-z0-9-]*)>/g, (match, key: string) => quoted(key, match))
|
|
74
|
+
.replace(/(--[a-z][a-z-]*) (PATH|DIR|ID|RUN|ALIAS|SHA|TEXT|N)(?![A-Za-z0-9_])(?:\|-)?/g, (match, flag: string, metavar: string) =>
|
|
75
|
+
Object.hasOwn(values, flag) ? `${flag} ${shellQuote(values[flag]!)}` : Object.hasOwn(values, metavar) ? `${flag} ${shellQuote(values[metavar]!)}` : match);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function relativeTime(value: unknown, now: number): string {
|
|
79
|
+
if (typeof value !== "string") return "";
|
|
80
|
+
const seconds = Math.floor((now - Date.parse(value)) / 1000);
|
|
81
|
+
if (!Number.isFinite(seconds)) return "";
|
|
82
|
+
const absolute = Math.abs(seconds);
|
|
83
|
+
for (const [unit, duration] of [["d", 86_400], ["h", 3600], ["m", 60], ["s", 1]] as const) {
|
|
84
|
+
if (absolute >= duration) return seconds >= 0 ? `${Math.floor(absolute / duration)}${unit} ago` : `in ${Math.floor(absolute / duration)}${unit}`;
|
|
85
|
+
}
|
|
86
|
+
return "now";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function gates(report: Report, values: unknown[], context: OutputContext, includeAttention = true): void {
|
|
90
|
+
const entries = values.map(record);
|
|
91
|
+
const needsAction = entries.filter(row => row.state === "pending" || row.state === "rejected");
|
|
92
|
+
if (includeAttention && needsAction.length) report.section("Attention");
|
|
93
|
+
for (const gate of includeAttention ? needsAction : []) {
|
|
94
|
+
report.bullet("warn", `${text(gate.gate)} gate is ${text(gate.state)}`);
|
|
95
|
+
if (context.values.dir) report.next(commandLine(["gate", "approve", context.values.dir, text(gate.gate)]));
|
|
96
|
+
}
|
|
97
|
+
report.section("Gates", String(entries.length));
|
|
98
|
+
report.table(["Gate", "State", "Actor", "When"], entries.map(gate => {
|
|
99
|
+
const decision = record(gate.decided), actor = record(decision.actor);
|
|
100
|
+
return [text(gate.gate), stateCell(report, text(gate.state)), text(actor.id ?? actor.kind), relativeTime(decision.at, context.now)];
|
|
101
|
+
}), 2, { dropEmptyColumns: false });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const HIDDEN = /(?:sha256|hash|binding|^events$|manifestbytes|^rendered$|^abstract$)/i;
|
|
105
|
+
function readable(value: unknown, now: number): unknown {
|
|
106
|
+
if (Array.isArray(value)) return value.map(item => readable(item, now));
|
|
107
|
+
if (value && typeof value === "object") {
|
|
108
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, field]) => {
|
|
109
|
+
if (HIDDEN.test(key) || (typeof field === "string" && field.startsWith("/") && /path|dir|root|study/i.test(key))) return [];
|
|
110
|
+
const when = /^(?:at|createdAt|startedAt|endedAt|updatedAt|decidedAt)$/.test(key) ? relativeTime(field, now) : "";
|
|
111
|
+
return [[key, when || readable(field, now)]];
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface Finding { state: "failed" | "warning" | "skipped" | "ok"; message: string }
|
|
118
|
+
function checks(command: string, value: Row): Finding[] {
|
|
119
|
+
if (Array.isArray(value.checks)) return value.checks.map(entry => {
|
|
120
|
+
const row = record(entry);
|
|
121
|
+
return { state: row.state === "failed" || row.state === "skipped" || row.state === "warning" ? row.state : "ok",
|
|
122
|
+
message: [row.name, row.detail].map(text).filter(Boolean).join(": ") };
|
|
123
|
+
});
|
|
124
|
+
if (command === "paper check") return array(value.findings).map(entry => {
|
|
125
|
+
const row = record(entry);
|
|
126
|
+
return { state: row.severity === "blocking" ? "failed" : "warning", message: `${text(row.line)}:${text(row.column)} ${text(row.code)}: ${text(row.message)}` };
|
|
127
|
+
});
|
|
128
|
+
if (command === "cite check") return [
|
|
129
|
+
...array(value.unknown).map(key => ({ state: "failed" as const, message: `Unknown citation ${text(key)}` })),
|
|
130
|
+
...array(value.notVerified).map(key => ({ state: "failed" as const, message: `Unverified citation ${text(key)}` })),
|
|
131
|
+
];
|
|
132
|
+
if (command === "watch run") return array(value.queries).map(entry => {
|
|
133
|
+
const row = record(entry);
|
|
134
|
+
const failed = array(row.errors).length;
|
|
135
|
+
const passed = array(row.sources).some(source => record(source).ok === true);
|
|
136
|
+
return { state: failed ? passed ? "warning" : "failed" : "ok", message: [row.id, failed ? `${failed} source errors` : "", row.added === undefined ? "" : `${text(row.added)} added`].map(text).filter(Boolean).join(": ") };
|
|
137
|
+
});
|
|
138
|
+
if (Array.isArray(value.findings)) return value.findings.map(entry => {
|
|
139
|
+
const row = record(entry);
|
|
140
|
+
return { state: row.severity === "blocking" || row.level === "error" ? "failed" : "warning",
|
|
141
|
+
message: text(row.message ?? row.reason ?? row.code ?? entry) };
|
|
142
|
+
});
|
|
143
|
+
const state = text(value.state ?? value.status ?? record(value.readiness).state);
|
|
144
|
+
const available = ["ok", "ready", "passed", "pass", "accepted", "available", "verified", "screened"];
|
|
145
|
+
const findings: Finding[] = [{ state: value.ok === false ? "failed" : state && !available.includes(state) ? "warning" : "ok",
|
|
146
|
+
message: [state || "Check completed", value.reason ?? value.nextStep].map(text).filter(Boolean).join(": ") }];
|
|
147
|
+
for (const observation of [...array(value.inspections), ...array(value.observations)]) {
|
|
148
|
+
const row = record(observation), status = text(row.state);
|
|
149
|
+
findings.push({ state: available.includes(status) ? "ok" : "warning",
|
|
150
|
+
message: [row.id ?? record(row.ref).id, status, row.reason ?? row.nextStep].map(text).filter(Boolean).join(": ") });
|
|
151
|
+
}
|
|
152
|
+
return findings;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function checkReport(report: Report, command: string, value: Row, context: OutputContext) {
|
|
156
|
+
const findings = checks(command, value);
|
|
157
|
+
const counts = { failed: 0, warnings: 0, unknown: 0, ok: 0 };
|
|
158
|
+
for (const [state, name, marker, count] of [
|
|
159
|
+
["failed", "Failures", "fail", "failed"], ["warning", "Warnings", "warn", "warnings"],
|
|
160
|
+
["skipped", "Skipped", "unknown", "unknown"], ["ok", "Passed", "ok", "ok"],
|
|
161
|
+
] as const) {
|
|
162
|
+
const group = findings.filter(row => row.state === state);
|
|
163
|
+
counts[count] = group.length;
|
|
164
|
+
if (group.length) report.section(name, String(group.length));
|
|
165
|
+
for (const row of group) report.bullet(marker, fillMessage(row.message, context.values) || name);
|
|
166
|
+
}
|
|
167
|
+
if (!findings.length) {
|
|
168
|
+
counts[value.ok === false ? "failed" : "ok"] = 1;
|
|
169
|
+
report.section(value.ok === false ? "Failures" : "Passed").bullet(value.ok === false ? "fail" : "ok", value.ok === false ? "Check failed" : "No findings");
|
|
170
|
+
}
|
|
171
|
+
report.summary(counts);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const CHECKS = new Set(["paper check", "cite check", "executor check", "renderer check", "lesson check", "skill check", "experience check", "watch run"]);
|
|
175
|
+
const VIEW_NAMES = new Set(["idea report", "lessons", "lit flow", "lit queries", "retention inspect", "review checklist", "manifest", "lineage compare", "executor inputs hash"]);
|
|
176
|
+
const PREVIEWS = new Set(["archive", "retention prune", "lit card export", "harness close", "harness adopt"]);
|
|
177
|
+
const COMPLETED: Readonly<Record<string, string>> = {
|
|
178
|
+
init: "Created the study", scope: "Saved the study scope", protocol: "Saved the experiment protocol",
|
|
179
|
+
selection: "Saved the selection rule", "selection calibrate": "Recorded the calibration recommendation", "idea categories": "Saved the idea categories",
|
|
180
|
+
"autonomy set": "Saved the autonomy policy", "executor set": "Saved the executor",
|
|
181
|
+
"gate approve": "Approved the gate", "gate reject": "Rejected the gate",
|
|
182
|
+
"lit search": "Recorded the literature search", "lit screen": "Recorded the screening decision",
|
|
183
|
+
"lit verify": "Checked the selected identifiers", "lit card": "Saved the extraction card", "lit bib": "Built the verified bibliography",
|
|
184
|
+
"plan set": "Saved the study plan", "watch set": "Saved the watch configuration", "paper build": "Built the checked manuscript", "renderer set": "Saved the renderer for this machine", "paper render record": "Recorded the render",
|
|
185
|
+
"paper plan set": "Saved the paper plan", "review add": "Recorded the review", "review resolve": "Resolved the review finding",
|
|
186
|
+
"attempt run": "Recorded the attempt", "attempt cancel": "Cancelled the attempt", "attempt reconcile": "Reconciled the attempts",
|
|
187
|
+
"console add": "Registered the study", "console remove": "Removed the study registration",
|
|
188
|
+
archive: "Published the selected notes", "retention prune": "Pruned the retained references", "lit card export": "Exported the selected cards",
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const NEXT: Readonly<Record<string, string[]>> = {
|
|
192
|
+
init: ["status"], scope: ["gate", "list"], protocol: ["executor", "check"], "protocol set": ["executor", "check"],
|
|
193
|
+
"executor set": ["executor", "check"], "lit search": ["lit", "list"], "lit screen": ["lit", "list"], "lit verify": ["lit", "list"],
|
|
194
|
+
"plan set": ["plan", "show"], "watch set": ["watch", "show"], "paper plan set": ["paper", "plan", "show"],
|
|
195
|
+
"paper build": ["review", "show"], "renderer set": ["renderer", "check"], "paper render record": ["paper", "render", "show"], "review add": ["review", "show"], selection: ["investigate", "show"], "idea categories": ["idea", "report"],
|
|
196
|
+
"investigate close": ["investigate", "show"], "attempt reconcile": ["attempt", "list"], "gate approve": ["gate", "list"],
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function renderView(report: Report, command: string, result: unknown, context: OutputContext) {
|
|
200
|
+
const value = record(result);
|
|
201
|
+
if (command === "status") {
|
|
202
|
+
const literature = record(value.literature), active = array(value.gates).map(record).filter(row => ["pending", "rejected"].includes(text(row.state)));
|
|
203
|
+
if (active.length || Number(literature.unverified) > 0) report.section("Attention");
|
|
204
|
+
for (const gate of active) {
|
|
205
|
+
report.bullet("warn", `${text(gate.gate)} gate is ${text(gate.state)}`);
|
|
206
|
+
if (context.values.dir) report.next(commandLine(["gate", "approve", context.values.dir, text(gate.gate)]));
|
|
207
|
+
}
|
|
208
|
+
if (Number(literature.unverified) > 0) {
|
|
209
|
+
report.bullet("warn", `${text(literature.unverified)} included references need verification`);
|
|
210
|
+
if (context.values.dir) report.next(commandLine(["lit", "verify", context.values.dir]));
|
|
211
|
+
}
|
|
212
|
+
report.section("Study").kv([["Question", value.question], ["Mode", value.mode], ["Scope", record(value.scope).set ? "Set" : "Unset"]]);
|
|
213
|
+
gates(report, array(value.gates), context, false);
|
|
214
|
+
report.section("Literature").kv(Object.entries(literature).map(([key, field]) => [label(key), field]));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (command === "gate list") { gates(report, array(result), context); return; }
|
|
218
|
+
if (command === "lit list") {
|
|
219
|
+
const candidates = array(value.candidates).map(record);
|
|
220
|
+
const unverified = candidates.filter(row => row.status === "included" && row.verified !== true);
|
|
221
|
+
if (unverified.length) {
|
|
222
|
+
report.section("Attention").bullet("warn", `${unverified.length} listed references need verification`);
|
|
223
|
+
if (context.values.dir) report.next(commandLine(["lit", "verify", context.values.dir]));
|
|
224
|
+
}
|
|
225
|
+
report.section("Candidates", `${candidates.length} of ${text(value.total)}`).table(
|
|
226
|
+
["ID", "Year", "Status", "Verified", "Title"],
|
|
227
|
+
candidates.map(candidate => [text(candidate.id), text(candidate.year), stateCell(report, text(candidate.status)), candidate.verified === true ? "yes" : "no", text(candidate.title)]),
|
|
228
|
+
4, { columnCaps: [22, 4, 12, 8, null], dropEmptyColumns: false, clip: true },
|
|
229
|
+
);
|
|
230
|
+
if (!candidates.length) report.note("No candidates");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (command === "attempt list" || command === "attempt show") {
|
|
234
|
+
const attempts = command === "attempt list" ? array(value.attempts).map(record) : [value];
|
|
235
|
+
const problems = attempts.filter(row => ["unknown", "failed"].includes(text(row.status)));
|
|
236
|
+
if (problems.length) {
|
|
237
|
+
report.section("Attention");
|
|
238
|
+
for (const row of problems) report.bullet(statusMarker(text(row.status)), `${text(row.id)} ${text(row.status)} ${text(row.reason)}`.trimEnd());
|
|
239
|
+
if (context.values.dir) report.next(commandLine(["attempt", "reconcile", context.values.dir]));
|
|
240
|
+
}
|
|
241
|
+
if (command === "attempt list") {
|
|
242
|
+
report.section("Attempts", String(attempts.length)).table(["ID", "Run", "Seed", "State", "Started"], attempts.map(row =>
|
|
243
|
+
[text(row.id), text(row.run), text(row.seed), stateCell(report, text(row.status)), relativeTime(row.startedAt, context.now)]), 1);
|
|
244
|
+
} else {
|
|
245
|
+
report.section("Attempt").kv([["ID", value.id], ["Run", value.run], ["Seed", value.seed], ["State", value.status], ["Started", relativeTime(value.startedAt, context.now)]]);
|
|
246
|
+
const metrics = array(value.metrics).map(record);
|
|
247
|
+
if (metrics.length) report.section("Metrics").kv(metrics.map(metric => [text(metric.name), `${text(metric.value)} ${text(metric.unit)}`.trimEnd()]));
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (command === "plan show" && Array.isArray(value.nodes)) {
|
|
252
|
+
const nodes = array(value.nodes).map(record);
|
|
253
|
+
const actionable = nodes.filter(node => ["failed", "unknown"].includes(text(node.status)));
|
|
254
|
+
if (actionable.length) {
|
|
255
|
+
report.section("Attention");
|
|
256
|
+
for (const node of actionable) report.bullet(statusMarker(text(node.status)), [node.id, node.reason ?? node.status].map(text).join(": "));
|
|
257
|
+
if (context.values.dir) report.next(commandLine(["run", context.values.dir]));
|
|
258
|
+
}
|
|
259
|
+
report.section("Plan").kv([["State", value.state], ["Revision", value.revision]]);
|
|
260
|
+
report.section("Nodes", String(nodes.length)).table(["ID", "Kind", "State", "Details"], nodes.map(node =>
|
|
261
|
+
[text(node.id), text(node.kind), stateCell(report, text(node.status)), text(node.reason)]), 3);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (command === "review show") {
|
|
265
|
+
const unmet = array(value.unmet), findings = array(value.openBlocking).map(record);
|
|
266
|
+
if (unmet.length || findings.length) report.section("Attention");
|
|
267
|
+
for (const item of unmet) report.bullet("warn", fillMessage(text(record(item).message), context.values));
|
|
268
|
+
for (const row of findings) {
|
|
269
|
+
report.bullet("fail", [row.location, row.text].map(text).filter(Boolean).join(": "));
|
|
270
|
+
report.note(`Resolve ${text(row.reviewId)}/${text(row.findingId)} with the reason for the repair`);
|
|
271
|
+
}
|
|
272
|
+
report.section("Reviews").kv([["Ready", value.ready], ["Reviews", array(value.reviews).length], ["Model families", array(value.families).join(", ")]]);
|
|
273
|
+
// Shown side by side for a person to compare; ares matches and marks nothing.
|
|
274
|
+
const readbacks = array(value.readbacks).map(record).flatMap(row => array(row.claims).map(claim => [`${text(row.reviewer)} (${text(row.modelFamily)})`, text(claim)]));
|
|
275
|
+
if (readbacks.length) report.section("Read-backs", String(readbacks.length)).table(["Reviewer", "Claim"], readbacks, 1, { columnCaps: [24, null], clip: true });
|
|
276
|
+
const planClaims = array(value.planClaims).map(record);
|
|
277
|
+
if (planClaims.length) report.section("Plan claims", String(planClaims.length)).table(["Point", "Claim"], planClaims.map(row => [text(row.point), text(row.claim)]), 1, { columnCaps: [24, null], clip: true });
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (command === "idea report") {
|
|
281
|
+
const search = record(value.search), ideas = array(value.ideas).map(record), untried = array(search.untried).map(text);
|
|
282
|
+
if (search.stalled === true || untried.length) {
|
|
283
|
+
report.section("Attention");
|
|
284
|
+
if (search.stalled === true) report.bullet("warn", `No primary gain over the last ${text(value.window)} measured ideas`);
|
|
285
|
+
if (untried.length) report.bullet("warn", `Untried categories: ${untried.join(", ")}`);
|
|
286
|
+
}
|
|
287
|
+
report.section("Search").kv([["Run", value.run], ["Metric", record(value.metric).name], ["Measured ideas", search.measured], ["Best delta", search.bestDelta ?? "none"], ["Advisory", "yes"]]);
|
|
288
|
+
report.section("Ideas", String(ideas.length)).table(["ID", "Category", "Timing", "Delta", "Predictions"], ideas.map(row => [
|
|
289
|
+
text(row.id), row.confounded === true ? "confounded" : text(row.category ?? "-"), text(row.timing), text(row.primaryDelta ?? "-"),
|
|
290
|
+
array(row.predictions).map(record).map(p => `${text(p.metric)} ${text(p.outcome ?? "post-hoc")}`).join(", ") || "-",
|
|
291
|
+
]), 1);
|
|
292
|
+
const categories = array(value.categories).map(record);
|
|
293
|
+
if (categories.length) report.section("Categories", String(categories.length)).table(["Name", "Ideas", "Measured", "Hits", "Recent gain"], categories.map(row => [
|
|
294
|
+
text(row.name), text(row.ideas), text(row.measured), text(row.hits), row.noRecentGain === true ? "none" : text(row.bestRecentDelta ?? "-"),
|
|
295
|
+
]), 1);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (command === "executor inputs hash") {
|
|
299
|
+
report.section("Input manifest").kv([["SHA-256", value.sha256], ["Files", value.files], ["Bytes", value.bytes]]);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const calibration = record(value.calibration);
|
|
303
|
+
if (calibration.belowNoise === true) report.section("Attention").bullet("warn", "The sealed minimum delta is below the calibration recommendation");
|
|
304
|
+
rows(report, readable(result, context.now));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function renderResult(command: string, result: unknown, code: number, color: boolean, ascii: boolean, columns?: number,
|
|
308
|
+
context: OutputContext = { args: [], values: {}, now: Date.now() },
|
|
309
|
+
): string {
|
|
310
|
+
const report = new Report(columns, ascii).header("ares", label(command)), value = record(result);
|
|
311
|
+
if (command === "attempt logs") {
|
|
312
|
+
for (const entry of array(value.logs)) {
|
|
313
|
+
const log = record(entry);
|
|
314
|
+
const stage = text(log.candidateStage ? `candidate:${text(log.candidateStage)}` : log.stage);
|
|
315
|
+
report.section(`${stage} ${text(log.stream)}${log.truncated ? ", truncated copy" : ""}`);
|
|
316
|
+
const body = terminalText(log.text).trimEnd();
|
|
317
|
+
if (body) report.line(body);
|
|
318
|
+
}
|
|
319
|
+
} else if (command === "setup" && Array.isArray(value.actions)) {
|
|
320
|
+
const actions = array(value.actions).map(record);
|
|
321
|
+
if (code) report.section("Attention").bullet("fail", "One or more integration changes were refused");
|
|
322
|
+
report.section(value.applied === true ? "Changes" : "Preview").table(["Target", "Change", "Reason"], actions.map(action =>
|
|
323
|
+
[text(action.target), text(action.change), text(action.reason)]), 2);
|
|
324
|
+
for (const note of array(value.notes)) report.note(text(note));
|
|
325
|
+
} else if (command === "study export" && value.wouldWrite === true) {
|
|
326
|
+
report.section("Preview").kv([["Bundle", value.bundle]]);
|
|
327
|
+
for (const name of array(value.files)) report.note(text(name), "value");
|
|
328
|
+
if (context.args.length) report.next(commandLine(context.args.filter(argument => argument !== "--list")));
|
|
329
|
+
} else if (CHECKS.has(command)) {
|
|
330
|
+
checkReport(report, command, value, context);
|
|
331
|
+
} else if (VIEW_NAMES.has(command) || command === "status" || / (?:list|show)$/.test(command)) {
|
|
332
|
+
renderView(report, command, result, context);
|
|
333
|
+
} else if (PREVIEWS.has(command) && typeof value.fingerprint === "string" && !Object.hasOwn(context.values, "--confirm")) {
|
|
334
|
+
report.section("Preview");
|
|
335
|
+
for (const item of array(value.preview)) report.note(text(item), "value");
|
|
336
|
+
if (command === "archive") {
|
|
337
|
+
const notes = array(value.notes).map(record);
|
|
338
|
+
report.note(`Publish ${notes.length} notes`, "value");
|
|
339
|
+
for (const note of notes) report.note(text(record(note.note).title), "value");
|
|
340
|
+
}
|
|
341
|
+
if (command === "lit card export") {
|
|
342
|
+
const cards = array(value.cards).map(record);
|
|
343
|
+
report.note(`Export ${cards.length} cards`, "value");
|
|
344
|
+
for (const card of cards) report.note(text(card.id), "value");
|
|
345
|
+
}
|
|
346
|
+
if (command === "retention prune") report.note(`Remove ${context.previewCount ?? "the"} retained references from ${context.values["--file"] ?? "the supplied input"}`, "value");
|
|
347
|
+
if (value.recovery) report.note(text(value.recovery));
|
|
348
|
+
if (context.args.length) report.next(commandLine([...context.args, "--confirm", value.fingerprint]));
|
|
349
|
+
} else if (code !== 0) {
|
|
350
|
+
report.section("Attention").bullet(code === 75 ? "warn" : "fail", text(value.reason ?? value.state ?? value.status) || (code === 75 ? "Temporarily deferred" : "Command reported a failure"));
|
|
351
|
+
rows(report, readable(result, context.now));
|
|
352
|
+
} else {
|
|
353
|
+
if (command === "investigate close" && record(value.calibration).belowNoise === true) {
|
|
354
|
+
report.section("Attention").bullet("warn", "The sealed minimum delta is below the calibration recommendation");
|
|
355
|
+
}
|
|
356
|
+
const identifier = text(value.id ?? value.name ?? value.gate ?? record(value.study).id ?? record(value.record).id ?? record(value.attempt).id ?? record(value.winner).commit);
|
|
357
|
+
const state = text(value.state ?? value.status);
|
|
358
|
+
const slides = context.values["--doc"] === "slides";
|
|
359
|
+
const description = slides && command === "paper build" ? "Built the checked slides" : COMPLETED[command] ?? `${label(command)} completed`;
|
|
360
|
+
const receipt = [value.changed === false ? "Already current" : description, identifier, state].filter(Boolean).join(" · ");
|
|
361
|
+
report.bullet("ok", receipt);
|
|
362
|
+
if (command === "selection calibrate") report.section("Recommendation").kv([
|
|
363
|
+
["Method", value.method], ["Minimum delta", value.recommendedMinDelta], ["Receipt SHA-256", value.sha256],
|
|
364
|
+
]);
|
|
365
|
+
if (context.values.dir && NEXT[command] && !(slides && command === "paper build")) report.next(commandLine([...NEXT[command], context.values.dir]));
|
|
366
|
+
const warnings = array(value.warnings);
|
|
367
|
+
if (warnings.length) {
|
|
368
|
+
report.section("Attention");
|
|
369
|
+
for (const warning of warnings.map(record)) report.bullet("warn", [warning.cause ?? warning.code, warning.nextStep].map(text).filter(Boolean).join(": "));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return report.render(color).join("\n");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function renderError(message: string, tty: boolean, color: boolean, ascii: boolean, columns?: number): string {
|
|
376
|
+
const advice = /; ((?:use|pass|run|rerun|retry|choose|restore|explain|select)\b[\s\S]*)$/.exec(message)
|
|
377
|
+
?? /; ([^;]*\b(?:run|rerun|retry) ares [\s\S]*)$/.exec(message)
|
|
378
|
+
?? / \((run ares [^()]*)\)$/.exec(message);
|
|
379
|
+
const text = advice ? message.slice(0, advice.index) : message;
|
|
380
|
+
const separator = text.indexOf(": ");
|
|
381
|
+
const what = separator < 0 ? text : text.slice(0, separator);
|
|
382
|
+
const why = separator < 0 ? "" : text.slice(separator + 2);
|
|
383
|
+
const next = advice?.[1]?.replace(/^(?:run|rerun|retry) (?=(?:cd |ares ))/, "");
|
|
384
|
+
const options = { tty, ascii, ...(next === undefined ? {} : { next }) };
|
|
385
|
+
const lines = color
|
|
386
|
+
? errorSpans("ares", what, why, options, columns).map(line => paint(line, true))
|
|
387
|
+
: errorLine("ares", what, why, options, columns);
|
|
388
|
+
return lines.join("\n");
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export { streamWidth };
|
|
392
|
+
|
|
393
|
+
export function outputAscii(options: OutputOptions, env: NodeJS.ProcessEnv): boolean {
|
|
394
|
+
return asciiMarkers(env, options.ascii);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const HELP_GROUPS = [
|
|
398
|
+
["Study", "init", "status", "study", "scope", "playbook"],
|
|
399
|
+
["Literature", "lit", "watch"],
|
|
400
|
+
["Gates", "gate", "autonomy"],
|
|
401
|
+
["Plan", "plan", "run"],
|
|
402
|
+
["Experiments", "protocol", "executor", "attempt", "idea", "investigate", "ablate", "posthoc", "final", "selection", "retention", "lineage"],
|
|
403
|
+
["Harness and experience", "harness", "experience"],
|
|
404
|
+
["Memory", "archive", "lesson", "lessons", "skill"],
|
|
405
|
+
["Paper and review", "paper", "renderer", "review", "cite"],
|
|
406
|
+
["Integration", "setup", "console", "manifest", "mcp"],
|
|
407
|
+
] as const;
|
|
408
|
+
|
|
409
|
+
export function renderHelp(spec: CommandSpec | undefined, color: boolean, ascii: boolean): string {
|
|
410
|
+
const report = new Report(80, ascii);
|
|
411
|
+
if (!spec) {
|
|
412
|
+
report.header("ares", "Help").section("Usage")
|
|
413
|
+
.line(" ares <command> [options]")
|
|
414
|
+
.line(" ares help <command> | ares <command> --help")
|
|
415
|
+
.line(" ares --version");
|
|
416
|
+
for (const [title, ...prefixes] of HELP_GROUPS) {
|
|
417
|
+
const commands = COMMANDS.filter(command => prefixes.some(prefix => command.name.split(" ")[0] === prefix))
|
|
418
|
+
.toSorted((left, right) => left.name.localeCompare(right.name, "en"));
|
|
419
|
+
report.section(title).kv(commands.map(command => [command.name, command.summary]), 2, { colon: false });
|
|
420
|
+
}
|
|
421
|
+
report.section("Global flags").kv(Object.entries(GLOBAL_HELP_FLAGS), 2, { colon: false });
|
|
422
|
+
} else {
|
|
423
|
+
const usage = helpUsage(spec);
|
|
424
|
+
report.header("ares", spec.name).section("Usage").line(` ares ${usage}`)
|
|
425
|
+
.section("Description").note(spec.summary, "value");
|
|
426
|
+
if (usage.includes("<gate>")) {
|
|
427
|
+
report.note("Gate names: scope, screen, design, final, review, plan:node-id,", "value")
|
|
428
|
+
.note("accept:artifact or harness:round-id", "value");
|
|
429
|
+
}
|
|
430
|
+
const flags = Object.keys(spec.options).filter(flag => flag !== "--json")
|
|
431
|
+
.map(flag => [helpFlagLabel(spec, flag), flagDescription(spec, flag)] as const);
|
|
432
|
+
if (spec.options["--json"]) flags.push(["--json", GLOBAL_HELP_FLAGS["--json"]]);
|
|
433
|
+
flags.push(["--color=auto|always|never", GLOBAL_HELP_FLAGS["--color"]], ["--ascii", GLOBAL_HELP_FLAGS["--ascii"]], ["--help", GLOBAL_HELP_FLAGS["--help"]]);
|
|
434
|
+
report.section("Flags", String(flags.length)).kv(flags, 2, { colon: false });
|
|
435
|
+
if (spec.example) report.section("Examples").next(`ares ${spec.name} ${spec.example}`);
|
|
436
|
+
}
|
|
437
|
+
return report.render(color).join("\n");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export function usageHint(spec: CommandSpec | undefined, columns = 80): string {
|
|
441
|
+
const usage = spec ? helpUsage(spec) : "<command> [options]";
|
|
442
|
+
const help = spec ? `ares help ${spec.name}` : "ares --help";
|
|
443
|
+
return [...wrap(`Usage: ares ${usage}`, Math.min(columns, 80)), `Run '${help}' for details.`].join("\n");
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export { cellWidth };
|