reevesagents 2.1.0 → 2.2.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 +21 -0
- package/README.md +232 -318
- package/dist/chunk-CJKEBBUI.js +7663 -0
- package/dist/{chunk-UEYJAKAZ.js → chunk-DGLUP7Q7.js} +2 -2
- package/dist/{chunk-PWYG5IM5.js → chunk-HTCENB3Q.js} +2 -2
- package/dist/chunk-PKMTELW4.js +115 -0
- package/dist/chunk-PVYM35RS.js +1697 -0
- package/dist/{chunk-OQJNBACW.js → chunk-QWUBYDUV.js} +2 -2
- package/dist/chunk-XEOWHTRQ.js +1246 -0
- package/dist/{chunk-KROKGL2R.js → chunk-XHP63Y64.js} +879 -2
- package/dist/cli.js +1099 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/{router-AYNTF24M.js → router-S7KR2CIE.js} +146 -79
- package/dist/{server-TIFQ5JSM.js → server-4OILK2LL.js} +344 -6
- package/dist/{server-BNBSZZIP.js → server-5U4NNV43.js} +305 -14
- package/dist/{tui-launch-7DBX4JYA.js → tui-launch-7WKLVYEH.js} +2 -2
- package/dist/web/app.css +444 -11
- package/dist/web/app.js +672 -21
- package/dist/web/favicon.png +0 -0
- package/dist/web/index.html +75 -0
- package/dist/web/insights-core.js +92 -0
- package/dist/web/plan-controller.js +91 -0
- package/dist/web/plan-error.js +81 -0
- package/dist/web/tick-line.js +78 -0
- package/package.json +10 -8
- package/dist/chunk-DLWYZPW6.js +0 -3222
- package/dist/chunk-YWS3MILO.js +0 -266
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
runOnboarding,
|
|
5
5
|
suggestedAgentPrompt,
|
|
6
6
|
writeTuiOpenToken
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QWUBYDUV.js";
|
|
8
|
+
import {
|
|
9
|
+
startFlow
|
|
10
|
+
} from "./chunk-PKMTELW4.js";
|
|
8
11
|
import {
|
|
9
12
|
installSkills,
|
|
10
13
|
removeSkills,
|
|
@@ -12,55 +15,116 @@ import {
|
|
|
12
15
|
} from "./chunk-QIHT27ZG.js";
|
|
13
16
|
import {
|
|
14
17
|
MODEL_CATALOG
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-DGLUP7Q7.js";
|
|
19
|
+
import {
|
|
20
|
+
addFlowSpecs,
|
|
21
|
+
applyPlanMarks,
|
|
22
|
+
dropFlowSpec,
|
|
23
|
+
headIsDocsOnly,
|
|
24
|
+
isGitTreeClean,
|
|
25
|
+
pauseFlow,
|
|
26
|
+
readGitHead,
|
|
27
|
+
releaseRound,
|
|
28
|
+
resumeFlow,
|
|
29
|
+
roundIsLive,
|
|
30
|
+
stepFlow,
|
|
31
|
+
stopFlow
|
|
32
|
+
} from "./chunk-PVYM35RS.js";
|
|
16
33
|
import {
|
|
17
34
|
REEVESAGENTS_VERSION,
|
|
35
|
+
ackFlowIncident,
|
|
36
|
+
claimFlowIncident,
|
|
37
|
+
flowDispatchNote,
|
|
38
|
+
flowIncidentAgeMs,
|
|
39
|
+
flowStatusPayload,
|
|
40
|
+
listFlowIncidents,
|
|
18
41
|
listRunApprovals,
|
|
42
|
+
readTickStatus,
|
|
43
|
+
reconcileFlowIncidents,
|
|
44
|
+
resolveFlowIncident,
|
|
45
|
+
resolveFlowRunId,
|
|
19
46
|
resolveRunApproval,
|
|
20
47
|
sweepAgents,
|
|
21
|
-
sweepOrphanSessions
|
|
22
|
-
|
|
48
|
+
sweepOrphanSessions,
|
|
49
|
+
tickStateText,
|
|
50
|
+
writeTickStatus
|
|
51
|
+
} from "./chunk-XEOWHTRQ.js";
|
|
23
52
|
import {
|
|
24
53
|
ALLOWED_KEYS,
|
|
25
54
|
CONFIG_FIELDS,
|
|
55
|
+
NotificationError,
|
|
56
|
+
PLAN_STATUSES,
|
|
26
57
|
PROVIDERS,
|
|
58
|
+
PlanError,
|
|
59
|
+
appendLog,
|
|
27
60
|
archiveAndRemoveRun,
|
|
28
61
|
attach,
|
|
29
62
|
attachAll,
|
|
63
|
+
attachSpec,
|
|
30
64
|
autoCleanupRuns,
|
|
31
65
|
coerceExtraArgs,
|
|
32
66
|
computeRunStatus,
|
|
67
|
+
createPlan,
|
|
33
68
|
deleteAgent,
|
|
34
69
|
deletePreset,
|
|
35
70
|
deleteRunHistory,
|
|
36
71
|
detach,
|
|
37
72
|
detectAvailable,
|
|
38
73
|
detectToolStatuses,
|
|
74
|
+
displayPath,
|
|
75
|
+
ensurePlanSummary,
|
|
39
76
|
exactSession,
|
|
40
77
|
execTmux,
|
|
78
|
+
flowPath,
|
|
41
79
|
hostStatus,
|
|
80
|
+
importInto,
|
|
42
81
|
interrupt,
|
|
43
82
|
killAgent,
|
|
44
83
|
latestActiveRun,
|
|
45
84
|
listAgents,
|
|
85
|
+
listFlowFiles,
|
|
86
|
+
listNotesHeads,
|
|
46
87
|
listPresets,
|
|
47
88
|
listRunHistory,
|
|
48
89
|
listRuns,
|
|
49
90
|
loadConfig,
|
|
91
|
+
markNotificationsRead,
|
|
92
|
+
mutatePlan,
|
|
50
93
|
normalizeProvider,
|
|
94
|
+
notificationSummary,
|
|
51
95
|
parseConfigValue,
|
|
52
96
|
peekAgent,
|
|
97
|
+
planComplete,
|
|
98
|
+
planExists,
|
|
99
|
+
planIsComplete,
|
|
100
|
+
planItemView,
|
|
101
|
+
planNext,
|
|
102
|
+
planOpenItems,
|
|
103
|
+
planPath,
|
|
104
|
+
planProgress,
|
|
105
|
+
planTickView,
|
|
106
|
+
planWaitingForBrief,
|
|
53
107
|
providerColor,
|
|
54
108
|
providerDisplayName,
|
|
109
|
+
readFlow,
|
|
110
|
+
readNotesRound,
|
|
111
|
+
readNotifications,
|
|
112
|
+
readPlan,
|
|
55
113
|
readRun,
|
|
114
|
+
redactSecrets,
|
|
115
|
+
renderPlanItemPrompt,
|
|
116
|
+
resolveRepositoryPath,
|
|
56
117
|
runDoctor,
|
|
57
118
|
runHasLiveTmuxTarget,
|
|
119
|
+
saveFlow,
|
|
58
120
|
savePresetFromRun,
|
|
59
121
|
sendKey,
|
|
60
122
|
sendText,
|
|
61
123
|
sessionExists,
|
|
62
124
|
setConfigValues,
|
|
125
|
+
setItemStatus,
|
|
63
126
|
shellQuote,
|
|
127
|
+
shortHomePath,
|
|
64
128
|
spawnTmux,
|
|
65
129
|
spawnWorker,
|
|
66
130
|
startRun,
|
|
@@ -70,7 +134,7 @@ import {
|
|
|
70
134
|
verifyServerLaunch,
|
|
71
135
|
windowByName,
|
|
72
136
|
windowIds
|
|
73
|
-
} from "./chunk-
|
|
137
|
+
} from "./chunk-CJKEBBUI.js";
|
|
74
138
|
import "./chunk-Q3WWQP2R.js";
|
|
75
139
|
|
|
76
140
|
// src/surfaces/cli/index.ts
|
|
@@ -399,11 +463,11 @@ function registerRuns(program2) {
|
|
|
399
463
|
});
|
|
400
464
|
}
|
|
401
465
|
function registerReap(program2) {
|
|
402
|
-
program2.command("reap").description("reap zombie agents and orphan tmux sessions no live record owns").option("--json", "output JSON object: { reaped, killed_sessions }").action((opts) => {
|
|
466
|
+
program2.command("reap").description("reap zombie agents and orphan tmux sessions no live record owns").option("--json", "output JSON object: { reaped, killed_sessions, orphan_sweep_skipped }").action((opts) => {
|
|
403
467
|
const { reaped } = sweepAgents();
|
|
404
|
-
const { killed } = sweepOrphanSessions({ ignoreGrace: true });
|
|
468
|
+
const { killed, skipped } = sweepOrphanSessions({ ignoreGrace: true });
|
|
405
469
|
if (opts.json) {
|
|
406
|
-
console.log(JSON.stringify({ reaped, killed_sessions: killed }, null, 2));
|
|
470
|
+
console.log(JSON.stringify({ reaped, killed_sessions: killed, orphan_sweep_skipped: skipped ?? null }, null, 2));
|
|
407
471
|
return;
|
|
408
472
|
}
|
|
409
473
|
for (const r of reaped) {
|
|
@@ -412,7 +476,10 @@ function registerReap(program2) {
|
|
|
412
476
|
for (const name of killed) {
|
|
413
477
|
console.log(`killed orphan session ${name}`);
|
|
414
478
|
}
|
|
415
|
-
if (
|
|
479
|
+
if (skipped === "foreign-registry") {
|
|
480
|
+
console.log("orphan sweep skipped: this registry owns no runs, so the tmux server belongs to another state dir");
|
|
481
|
+
}
|
|
482
|
+
if (reaped.length === 0 && killed.length === 0 && skipped === void 0) {
|
|
416
483
|
console.log("no zombie agents or orphan sessions");
|
|
417
484
|
return;
|
|
418
485
|
}
|
|
@@ -833,7 +900,7 @@ function registerDetach(program2) {
|
|
|
833
900
|
function registerMcp(program2) {
|
|
834
901
|
program2.command("mcp").description("start the agent control MCP server over stdio (for CLIs that have it attached)").action(async () => {
|
|
835
902
|
try {
|
|
836
|
-
const { startAgentMcpServer } = await import("./server-
|
|
903
|
+
const { startAgentMcpServer } = await import("./server-4OILK2LL.js");
|
|
837
904
|
await startAgentMcpServer();
|
|
838
905
|
} catch (err) {
|
|
839
906
|
console.error(err instanceof Error ? err.message : String(err));
|
|
@@ -923,6 +990,966 @@ function registerStartPreset(program2) {
|
|
|
923
990
|
});
|
|
924
991
|
}
|
|
925
992
|
|
|
993
|
+
// src/core/flow-ticker.ts
|
|
994
|
+
var TICKABLE = ["idle", "fixing", "reviewing"];
|
|
995
|
+
function tickAllFlows(options = {}) {
|
|
996
|
+
const result = { advanced: [], held: [], skipped: [] };
|
|
997
|
+
let sendUsed = false;
|
|
998
|
+
for (const file of listFlowFiles(options.root)) {
|
|
999
|
+
let state;
|
|
1000
|
+
try {
|
|
1001
|
+
state = readFlow(file.run_id, { root: options.root });
|
|
1002
|
+
} catch {
|
|
1003
|
+
result.skipped.push({ run_id: file.run_id, why: "state unreadable" });
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
if (!TICKABLE.includes(state.state)) {
|
|
1007
|
+
if (options.dryRun !== true) {
|
|
1008
|
+
try {
|
|
1009
|
+
reconcileFlowIncidents(state, void 0, void 0, {
|
|
1010
|
+
root: options.root,
|
|
1011
|
+
...options.now === void 0 ? {} : { now: options.now },
|
|
1012
|
+
...options.at === void 0 ? {} : { at: options.at }
|
|
1013
|
+
});
|
|
1014
|
+
} catch {
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
result.skipped.push({ run_id: file.run_id, why: state.state });
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
let step;
|
|
1021
|
+
try {
|
|
1022
|
+
step = stepFlow(file.run_id, {
|
|
1023
|
+
root: options.root,
|
|
1024
|
+
dryRun: options.dryRun === true || sendUsed,
|
|
1025
|
+
...options.now === void 0 ? {} : { now: options.now },
|
|
1026
|
+
...options.at === void 0 ? {} : { at: options.at },
|
|
1027
|
+
...options.ports === void 0 ? {} : { ports: options.ports }
|
|
1028
|
+
});
|
|
1029
|
+
} catch (err) {
|
|
1030
|
+
result.skipped.push({ run_id: file.run_id, why: err instanceof Error ? err.message : String(err) });
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
if (step.send !== void 0) sendUsed = true;
|
|
1034
|
+
const entry = { run_id: file.run_id, status: step.status, reason: step.decision.reason };
|
|
1035
|
+
if (options.dryRun !== true && sendUsed && step.send === void 0 && result.advanced.length + result.held.length > 0) {
|
|
1036
|
+
result.held.push({ run_id: file.run_id, status: step.decision.next_state, reason: "pass_send_limit" });
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
if (step.status === "applied" || step.status === "unconfirmed") result.advanced.push(entry);
|
|
1040
|
+
else result.held.push(entry);
|
|
1041
|
+
}
|
|
1042
|
+
if (options.dryRun !== true) {
|
|
1043
|
+
writeTickStatus("all", {
|
|
1044
|
+
advanced: result.advanced.length,
|
|
1045
|
+
held: result.held.length,
|
|
1046
|
+
skipped: result.skipped.length
|
|
1047
|
+
}, {
|
|
1048
|
+
...options.root === void 0 ? {} : { root: options.root },
|
|
1049
|
+
...options.at === void 0 ? {} : { at: options.at }
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// src/surfaces/cli/plan.ts
|
|
1056
|
+
import { readFileSync } from "fs";
|
|
1057
|
+
function runOption(cmd) {
|
|
1058
|
+
const own = cmd.opts().run;
|
|
1059
|
+
const fromParent = cmd.parent?.opts()?.run;
|
|
1060
|
+
const value = own ?? fromParent;
|
|
1061
|
+
if (!value) throw new PlanError("--run <id> is required", "invalid");
|
|
1062
|
+
return value;
|
|
1063
|
+
}
|
|
1064
|
+
function jsonOption(cmd, opts) {
|
|
1065
|
+
return opts.json === true || cmd.parent?.opts()?.json === true;
|
|
1066
|
+
}
|
|
1067
|
+
function failPlan(err) {
|
|
1068
|
+
if (err instanceof PlanError) {
|
|
1069
|
+
console.error(err.message);
|
|
1070
|
+
process.exit(err.code === "not_found" ? 2 : err.code === "refused" || err.code === "conflict" ? 3 : 1);
|
|
1071
|
+
}
|
|
1072
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
1073
|
+
process.exit(1);
|
|
1074
|
+
}
|
|
1075
|
+
function statusCountsLine(plan) {
|
|
1076
|
+
const progress = planProgress(plan);
|
|
1077
|
+
const parts = [`${progress.done}/${progress.total} done`];
|
|
1078
|
+
if (progress.skipped > 0) parts.push(`${progress.skipped} skipped`);
|
|
1079
|
+
for (const status of ["pending", "needs_brief", "queued", "in_work", "reviewing", "blocked_owner"]) {
|
|
1080
|
+
const count = progress.by_status[status];
|
|
1081
|
+
if (count > 0) parts.push(`${count} ${status}`);
|
|
1082
|
+
}
|
|
1083
|
+
return parts.join(" \xB7 ");
|
|
1084
|
+
}
|
|
1085
|
+
function idsOf(plan, status) {
|
|
1086
|
+
return plan.items.filter((item) => item.status === status && item.missing_since === null).map((item) => item.id);
|
|
1087
|
+
}
|
|
1088
|
+
function nextItem(plan) {
|
|
1089
|
+
return plan.items.find((item) => item.missing_since === null && item.status !== "done" && item.status !== "skipped") ?? null;
|
|
1090
|
+
}
|
|
1091
|
+
function planPayload(plan, path) {
|
|
1092
|
+
const progress = planProgress(plan);
|
|
1093
|
+
const next = nextItem(plan);
|
|
1094
|
+
return {
|
|
1095
|
+
run_id: plan.run_id,
|
|
1096
|
+
source_path: plan.source_path,
|
|
1097
|
+
imported_at: plan.imported_at,
|
|
1098
|
+
source_hash: plan.source_hash,
|
|
1099
|
+
complete: planComplete(plan),
|
|
1100
|
+
progress: {
|
|
1101
|
+
done: progress.done,
|
|
1102
|
+
total: progress.total,
|
|
1103
|
+
skipped: progress.skipped,
|
|
1104
|
+
by_status: progress.by_status
|
|
1105
|
+
},
|
|
1106
|
+
waiting: {
|
|
1107
|
+
needs_brief: idsOf(plan, "needs_brief"),
|
|
1108
|
+
blocked_owner: idsOf(plan, "blocked_owner"),
|
|
1109
|
+
missing: plan.items.filter((item) => item.missing_since !== null).map((item) => item.id),
|
|
1110
|
+
conflicts: plan.conflicts.length
|
|
1111
|
+
},
|
|
1112
|
+
next: next ? {
|
|
1113
|
+
id: next.id,
|
|
1114
|
+
title: next.title,
|
|
1115
|
+
status: next.status,
|
|
1116
|
+
spec_path: next.spec_path,
|
|
1117
|
+
// Eligibility, not a dispatch: `plan next` is what queues it (§5 of the design).
|
|
1118
|
+
ready: next.status === "queued" && next.spec !== null
|
|
1119
|
+
} : null,
|
|
1120
|
+
items: plan.items.map(planItemView),
|
|
1121
|
+
conflicts: plan.conflicts,
|
|
1122
|
+
path
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
function registerPlanCommands(flow) {
|
|
1126
|
+
const plan = flow.command("plan").description("the plan imported from the project document: progress, items and the next thing to do").option("--run <id>", "run id (a unique prefix is accepted)").option("--json", "output JSON").action((opts) => {
|
|
1127
|
+
try {
|
|
1128
|
+
if (!opts.run) throw new PlanError("--run <id> is required (use `flow plan import --run <id> \u2026` for the other verbs)", "invalid");
|
|
1129
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1130
|
+
ensurePlanSummary(runId);
|
|
1131
|
+
const imported = readPlan(runId);
|
|
1132
|
+
if (opts.json) {
|
|
1133
|
+
console.log(JSON.stringify(planPayload(imported, displayPath(planPath(runId))), null, 2));
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
const flow2 = readFlow(runId);
|
|
1137
|
+
printPlan(imported, { perItem: flow2.max_rounds, total: flow2.max_total_rounds, paused: flow2.state === "paused" });
|
|
1138
|
+
if (imported.conflicts.length > 0) process.exitCode = 3;
|
|
1139
|
+
} catch (err) {
|
|
1140
|
+
failPlan(err);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
plan.command("import").description("import (or re-import) the project plan document into the flow").option("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--file <path>", "the plan document in the repository, e.g. docs/implementation-plan.md").option("--dry-run", "parse and report; write nothing").option("--json", "output JSON").action((opts, cmd) => {
|
|
1144
|
+
const json = jsonOption(cmd, opts);
|
|
1145
|
+
try {
|
|
1146
|
+
const runId = resolveFlowRunId(runOption(cmd));
|
|
1147
|
+
const target = projectPath(opts.file, projectRoot(runId));
|
|
1148
|
+
const text = readDocument(target.absolute);
|
|
1149
|
+
const sourcePath = target.relative;
|
|
1150
|
+
const dryRun = opts.dryRun === true;
|
|
1151
|
+
const result = dryRun ? parseOnly(runId, sourcePath, text) : mutatePlan(runId, (current) => {
|
|
1152
|
+
const imported = current ? importInto(current, { run_id: runId, source_path: sourcePath, text, now: Date.now() }) : createPlan({ run_id: runId, source_path: sourcePath, text, now: Date.now() });
|
|
1153
|
+
return { plan: imported.unchanged ? null : imported.plan, value: imported };
|
|
1154
|
+
});
|
|
1155
|
+
if (opts.dryRun !== true) anchorAfterDocumentChange(runId);
|
|
1156
|
+
if (json) {
|
|
1157
|
+
console.log(JSON.stringify({
|
|
1158
|
+
dry_run: opts.dryRun === true,
|
|
1159
|
+
unchanged: result.unchanged,
|
|
1160
|
+
added: result.added,
|
|
1161
|
+
missing: result.missing,
|
|
1162
|
+
conflicts: result.conflicts,
|
|
1163
|
+
source_hash: result.source_hash,
|
|
1164
|
+
source_path: sourcePath,
|
|
1165
|
+
progress: planProgress(result.plan)
|
|
1166
|
+
}, null, 2));
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (result.unchanged) {
|
|
1170
|
+
console.log(`unchanged ${sourcePath} (${result.source_hash.slice(0, 8)})`);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const parts = [`${result.plan.items.length} items`];
|
|
1174
|
+
if (result.added.length > 0) parts.push(`${result.added.length} new`);
|
|
1175
|
+
const ticked = result.plan.items.filter((item) => item.closed_by === "ticked_by_hand").length;
|
|
1176
|
+
if (result.added.length > 0 && ticked > 0) parts.push(`${ticked} ticked in the document`);
|
|
1177
|
+
if (result.missing.length > 0) parts.push(`${result.missing.length} missing`);
|
|
1178
|
+
if (result.conflicts.length > 0) parts.push(`${result.conflicts.length} conflict${result.conflicts.length === 1 ? "" : "s"}`);
|
|
1179
|
+
console.log(`${opts.dryRun === true ? "would import" : "imported"} ${sourcePath}: ${parts.join(", ")}`);
|
|
1180
|
+
for (const conflict of result.conflicts) console.log(` ${conflict.kind} ${conflict.detail}`);
|
|
1181
|
+
if (result.conflicts.length > 0) process.exitCode = 3;
|
|
1182
|
+
} catch (err) {
|
|
1183
|
+
failPlan(err);
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
plan.command("next").description("show the next plan item and why it is ready or blocked; never queues or sends").option("--run <id>", "run id (a unique prefix is accepted)").option("--dry-run", "accepted for compatibility; this command never writes").option("--json", "output JSON").action((opts, cmd) => {
|
|
1187
|
+
const json = jsonOption(cmd, opts);
|
|
1188
|
+
try {
|
|
1189
|
+
const runId = resolveFlowRunId(runOption(cmd));
|
|
1190
|
+
const flow2 = readFlow(runId);
|
|
1191
|
+
const imported = readPlan(runId);
|
|
1192
|
+
const view = planTickView(imported, { perItem: flow2.max_rounds, total: flow2.max_total_rounds });
|
|
1193
|
+
const next = planNext(view);
|
|
1194
|
+
const body = {
|
|
1195
|
+
run_id: runId,
|
|
1196
|
+
dry_run: opts.dryRun === true,
|
|
1197
|
+
kind: next.kind,
|
|
1198
|
+
item: next.kind === "none" ? null : { id: next.item.id, title: next.item.title, status: next.item.status, spec_path: next.item.spec_path ?? null, rounds: next.item.rounds },
|
|
1199
|
+
reason: next.kind === "item" ? null : next.kind === "none" ? planIsComplete(view) ? "plan_complete" : "nothing_open" : next.kind,
|
|
1200
|
+
progress: { done: imported.items.filter((item) => item.status === "done").length, total: imported.items.length },
|
|
1201
|
+
waiting_for_brief: planWaitingForBrief(view).map((item) => item.id)
|
|
1202
|
+
};
|
|
1203
|
+
const queued = false;
|
|
1204
|
+
if (json) {
|
|
1205
|
+
console.log(JSON.stringify({ ...body, queued }, null, 2));
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (next.kind === "item") {
|
|
1209
|
+
const brief = next.item.spec_path ? ` (brief ${next.item.spec_path})` : "";
|
|
1210
|
+
console.log(`next ${next.item.id} \u2014 "${next.item.title}"${brief} ready for dispatch`);
|
|
1211
|
+
console.log(" nothing was sent by this command; the tick dispatches it");
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
if (next.kind === "needs_brief") {
|
|
1215
|
+
const waiting = planWaitingForBrief(view).map((item) => item.id);
|
|
1216
|
+
console.log(`waiting ${next.item.id} has no brief: \`flow plan attach --run ${runId} --item ${next.item.id} --spec <file>\``);
|
|
1217
|
+
if (waiting.length > 1) console.log(`waiting ${waiting.length} items need a brief: ${waiting.join(", ")}`);
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
if (next.kind === "blocked_owner") {
|
|
1221
|
+
console.log(`waiting ${next.item.id} is blocked_owner: a human decides (\`flow plan set --status skipped|queued\`)`);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if (next.kind === "in_flight") {
|
|
1225
|
+
console.log(`waiting ${next.item.id} is ${next.item.status}: one task per flow`);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
const open = planOpenItems(view).length;
|
|
1229
|
+
console.log(planIsComplete(view) ? `nothing the plan is complete (${imported.items.length} items)` : `nothing ${open} item(s) open, none of them ready`);
|
|
1230
|
+
} catch (err) {
|
|
1231
|
+
failPlan(err);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
plan.command("status").description("one plan item: status, the commit that closed it, its rounds and its brief").requiredOption("--item <id>", "plan item id, e.g. P1.7.1").option("--run <id>", "run id, needed only when the item id exists in more than one flow").option("--json", "output JSON").action((opts, cmd) => {
|
|
1235
|
+
const json = jsonOption(cmd, opts);
|
|
1236
|
+
try {
|
|
1237
|
+
const own = opts.run ?? cmd.parent?.opts()?.run;
|
|
1238
|
+
const found = findItem(opts.item, own);
|
|
1239
|
+
if (json) {
|
|
1240
|
+
console.log(JSON.stringify({
|
|
1241
|
+
run_id: found.plan.run_id,
|
|
1242
|
+
item: planItemView(found.item),
|
|
1243
|
+
conflicts: found.plan.conflicts.filter((entry) => entry.item_id === found.item.id)
|
|
1244
|
+
}, null, 2));
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const item = found.item;
|
|
1248
|
+
console.log(`item ${item.id} ${item.status}${item.owner_action ? " (needs you)" : ""}`);
|
|
1249
|
+
console.log(`run ${found.plan.run_id}`);
|
|
1250
|
+
console.log(`title ${item.title}`);
|
|
1251
|
+
console.log(`brief ${item.spec_path ?? "(none)"}${item.spec_hash ? ` ${item.spec_hash.slice(0, 8)}` : ""}`);
|
|
1252
|
+
console.log(`head ${item.head ?? "(no accepted commit)"}`);
|
|
1253
|
+
console.log(`rounds ${item.rounds}${item.notes_ref ? ` notes ${item.notes_ref}` : ""}`);
|
|
1254
|
+
console.log(`updated ${item.updated_at}`);
|
|
1255
|
+
if (item.missing_since) console.log(`missing since ${item.missing_since} (the document no longer lists it)`);
|
|
1256
|
+
} catch (err) {
|
|
1257
|
+
failPlan(err);
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
plan.command("attach").description("attach a brief to a plan item: validates it and stores a snapshot").option("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--item <id>", "plan item id, e.g. P1.7.1").requiredOption("--spec <file>", "the brief: a JSON block spec, or markdown for an unstructured one").option("--queue", "also queue the block on the flow now, instead of waiting for `flow plan next`").option("--dry-run", "validate and report; write nothing").option("--json", "output JSON").action((opts, cmd) => {
|
|
1261
|
+
const json = jsonOption(cmd, opts);
|
|
1262
|
+
try {
|
|
1263
|
+
const runId = resolveFlowRunId(runOption(cmd));
|
|
1264
|
+
const target = projectPath(opts.spec, projectRoot(runId));
|
|
1265
|
+
const text = readDocument(target.absolute);
|
|
1266
|
+
const format = opts.spec.toLowerCase().endsWith(".json") ? "json" : "markdown";
|
|
1267
|
+
const specPath = target.relative;
|
|
1268
|
+
const attach2 = (plan2) => attachSpec(plan2, {
|
|
1269
|
+
id: opts.item,
|
|
1270
|
+
text,
|
|
1271
|
+
format,
|
|
1272
|
+
spec_path: specPath,
|
|
1273
|
+
now: Date.now()
|
|
1274
|
+
});
|
|
1275
|
+
const dryRun = opts.dryRun === true;
|
|
1276
|
+
const result = dryRun ? attach2(readPlan(runId)) : mutatePlan(runId, (current) => {
|
|
1277
|
+
if (!current) throw new PlanError(`no plan for run ${runId}`, "not_found");
|
|
1278
|
+
const attached = attach2(current);
|
|
1279
|
+
return { plan: attached.plan, value: attached };
|
|
1280
|
+
});
|
|
1281
|
+
let queued = false;
|
|
1282
|
+
if (!dryRun && opts.queue === true) {
|
|
1283
|
+
addFlowSpecs({ run_id: runId, files: format === "json" ? [target.absolute] : void 0, markdown: format === "markdown" ? [target.absolute] : void 0 });
|
|
1284
|
+
queued = true;
|
|
1285
|
+
}
|
|
1286
|
+
if (opts.dryRun !== true) anchorAfterDocumentChange(runId);
|
|
1287
|
+
if (json) {
|
|
1288
|
+
console.log(JSON.stringify({
|
|
1289
|
+
dry_run: opts.dryRun === true,
|
|
1290
|
+
item: { id: result.item.id, status: result.item.status, spec_path: result.item.spec_path, spec_hash: result.item.spec_hash },
|
|
1291
|
+
queued
|
|
1292
|
+
}, null, 2));
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const suffix = opts.dryRun === true ? "(dry run: nothing written)" : queued ? "(queued on the flow \u2014 the tick sends it)" : "(brief ready; the next `flow tick` dispatches it)";
|
|
1296
|
+
console.log(`attached ${result.item.id} \u2192 ${result.item.spec_path} ${suffix}`);
|
|
1297
|
+
} catch (err) {
|
|
1298
|
+
failPlan(err);
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
plan.command("set").description("move one plan item by hand; the only command that can set done without an ACCEPT").option("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--item <id>", "plan item id, e.g. P1.7.1").requiredOption("--status <status>", `one of: ${PLAN_STATUSES.join(", ")}`).option("--yes", "required for done and skipped").option("--note <text>", "why: required for a done without an accepted commit").option("--dry-run", "validate and report; write nothing").option("--json", "output JSON").action((opts, cmd) => {
|
|
1302
|
+
const json = jsonOption(cmd, opts);
|
|
1303
|
+
try {
|
|
1304
|
+
const runId = resolveFlowRunId(runOption(cmd));
|
|
1305
|
+
const parkedFlow = readFlow(runId);
|
|
1306
|
+
const flowIsParked = () => parkedFlow.state === "paused" || parkedFlow.state === "done";
|
|
1307
|
+
const flowHasLiveRound = () => parkedFlow.state !== "done" && roundIsLive(parkedFlow);
|
|
1308
|
+
const input = {
|
|
1309
|
+
id: opts.item,
|
|
1310
|
+
status: opts.status,
|
|
1311
|
+
note: opts.note,
|
|
1312
|
+
yes: opts.yes === true,
|
|
1313
|
+
now: Date.now(),
|
|
1314
|
+
// A paused (or stopped) flow is a human at the console, so the engine's hold on a busy row is lifted — unless a round is actually
|
|
1315
|
+
// live, which is the one thing a human may not close by hand (block 56).
|
|
1316
|
+
intervention: {
|
|
1317
|
+
paused: flowIsParked(),
|
|
1318
|
+
round_live: flowHasLiveRound()
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
const dryRun = opts.dryRun === true;
|
|
1322
|
+
const result = dryRun ? setItemStatus(readPlan(runId), input) : mutatePlan(runId, (current) => {
|
|
1323
|
+
if (!current) throw new PlanError(`no plan for run ${runId}`, "not_found");
|
|
1324
|
+
const applied = setItemStatus(current, input);
|
|
1325
|
+
return { plan: applied.plan === current ? null : applied.plan, value: applied };
|
|
1326
|
+
});
|
|
1327
|
+
const item = result.plan.items.find((entry) => entry.id === opts.item);
|
|
1328
|
+
const marks = dryRun || item.status !== "done" ? null : applyPlanMarks(runId, {
|
|
1329
|
+
repo: parkedFlow.repo,
|
|
1330
|
+
tree_clean: isGitTreeClean(parkedFlow.repo),
|
|
1331
|
+
ids: [item.id],
|
|
1332
|
+
attempt: "close"
|
|
1333
|
+
});
|
|
1334
|
+
if (json) {
|
|
1335
|
+
console.log(JSON.stringify({
|
|
1336
|
+
dry_run: opts.dryRun === true,
|
|
1337
|
+
item: { id: item.id, status: item.status, previous: result.previous, owner_action: item.owner_action, updated_at: item.updated_at },
|
|
1338
|
+
...marks ? {
|
|
1339
|
+
document: {
|
|
1340
|
+
marked: marks.marked.map((entry) => entry.id),
|
|
1341
|
+
already: marks.already,
|
|
1342
|
+
deferred: marks.deferred,
|
|
1343
|
+
failures: marks.failures,
|
|
1344
|
+
sha: marks.sha
|
|
1345
|
+
}
|
|
1346
|
+
} : {}
|
|
1347
|
+
}, null, 2));
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
const note = opts.note ? `, note: ${opts.note}` : "";
|
|
1351
|
+
console.log(`${item.id} ${result.previous} \u2192 ${item.status} (manual${note})${opts.dryRun === true ? " [dry run]" : ""}`);
|
|
1352
|
+
if (marks && marks.marked.length > 0) console.log(`marked ${marks.marked.map((entry) => entry.id).join(", ")} in the plan document (${marks.sha?.slice(0, 7)})`);
|
|
1353
|
+
if (marks && marks.already.length > 0) console.log(`marked ${marks.already.join(", ")} was already ticked`);
|
|
1354
|
+
if (marks && marks.deferred) console.log("marked deferred: the tree is dirty; the next clean tick writes it");
|
|
1355
|
+
for (const failure of marks?.failures ?? []) console.log(`marked ${failure.id}: ${failure.reason}`);
|
|
1356
|
+
} catch (err) {
|
|
1357
|
+
failPlan(err);
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
function finalizePlanCommands(flow) {
|
|
1362
|
+
const plan = flow.commands.find((command) => command.name() === "plan");
|
|
1363
|
+
plan?.enablePositionalOptions();
|
|
1364
|
+
}
|
|
1365
|
+
function findItem(itemId, run) {
|
|
1366
|
+
if (run) {
|
|
1367
|
+
const plan = readPlan(resolveFlowRunId(run));
|
|
1368
|
+
const item = plan.items.find((entry) => entry.id === itemId);
|
|
1369
|
+
if (!item) throw new PlanError(`no plan item ${itemId} in run ${plan.run_id}`, "not_found");
|
|
1370
|
+
return { plan, item };
|
|
1371
|
+
}
|
|
1372
|
+
const matches = [];
|
|
1373
|
+
for (const file of listFlowFiles()) {
|
|
1374
|
+
if (!planExists(file.run_id)) continue;
|
|
1375
|
+
const plan = readPlan(file.run_id);
|
|
1376
|
+
const item = plan.items.find((entry) => entry.id === itemId);
|
|
1377
|
+
if (item) matches.push({ plan, item });
|
|
1378
|
+
}
|
|
1379
|
+
if (matches.length === 0) throw new PlanError(`no plan item ${itemId} in any flow`, "not_found");
|
|
1380
|
+
if (matches.length > 1) {
|
|
1381
|
+
throw new PlanError(
|
|
1382
|
+
`${itemId} exists in more than one flow (${matches.map((match) => match.plan.run_id).join(", ")}); pass --run`,
|
|
1383
|
+
"ambiguous"
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
return matches[0];
|
|
1387
|
+
}
|
|
1388
|
+
function anchorAfterDocumentChange(runId) {
|
|
1389
|
+
let state;
|
|
1390
|
+
try {
|
|
1391
|
+
state = readFlow(runId);
|
|
1392
|
+
} catch {
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (state.state === "done") return;
|
|
1396
|
+
const head = readGitHead(state.repo) || state.claim.head;
|
|
1397
|
+
if (head === state.claim.head) return;
|
|
1398
|
+
if (headIsDocsOnly(state, head) !== true) return;
|
|
1399
|
+
saveFlow({
|
|
1400
|
+
...state,
|
|
1401
|
+
claim: { head, verdict: null, verdict_count: state.claim.verdict_count, verdict_applied: false, spec_id: null },
|
|
1402
|
+
verdict_handled_for: null,
|
|
1403
|
+
log: appendLog(state, {
|
|
1404
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1405
|
+
event: "plan_documents_anchored",
|
|
1406
|
+
detail: `${head.slice(0, 7)}: the plan is a document, not the dev's work`
|
|
1407
|
+
})
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
function projectRoot(runId) {
|
|
1411
|
+
try {
|
|
1412
|
+
return readRun(runId).working_dir;
|
|
1413
|
+
} catch {
|
|
1414
|
+
return process.cwd();
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
function projectPath(file, root) {
|
|
1418
|
+
return resolveRepositoryPath(file, root);
|
|
1419
|
+
}
|
|
1420
|
+
function parseOnly(runId, sourcePath, text) {
|
|
1421
|
+
const existing = planExists(runId) ? readPlan(runId) : null;
|
|
1422
|
+
return existing ? importInto(existing, { run_id: runId, source_path: sourcePath, text, now: Date.now() }) : createPlan({ run_id: runId, source_path: sourcePath, text, now: Date.now() });
|
|
1423
|
+
}
|
|
1424
|
+
function readDocument(path) {
|
|
1425
|
+
try {
|
|
1426
|
+
return readFileSync(path, "utf-8");
|
|
1427
|
+
} catch {
|
|
1428
|
+
throw new PlanError(`cannot read ${displayPath(path)}`, "invalid");
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function printPlan(plan, budgets) {
|
|
1432
|
+
console.log(`plan ${plan.source_path} (imported ${plan.imported_at}, hash ${plan.source_hash.slice(0, 8)})`);
|
|
1433
|
+
console.log(`progress ${statusCountsLine(plan)}`);
|
|
1434
|
+
if (budgets.paused === true) console.log("paused yes (flow pause; `flow resume` continues from here)");
|
|
1435
|
+
const waiting = [];
|
|
1436
|
+
const needsBrief = plan.items.filter((item) => item.spec === null && item.missing_since === null && item.status !== "done" && item.status !== "skipped").map((item) => item.id);
|
|
1437
|
+
const blocked = idsOf(plan, "blocked_owner");
|
|
1438
|
+
const missing = plan.items.filter((item) => item.missing_since !== null).map((item) => item.id);
|
|
1439
|
+
if (needsBrief.length > 0) waiting.push(`needs_brief: ${needsBrief.join(", ")}`);
|
|
1440
|
+
if (blocked.length > 0) waiting.push(`blocked_owner: ${blocked.join(", ")}`);
|
|
1441
|
+
if (missing.length > 0) waiting.push(`missing: ${missing.join(", ")}`);
|
|
1442
|
+
if (plan.conflicts.length > 0) waiting.push(`conflicts: ${plan.conflicts.length}`);
|
|
1443
|
+
if (waiting.length > 0) console.log(`waiting ${waiting.join(" \xB7 ")}`);
|
|
1444
|
+
const picked = planNext(planTickView(plan, budgets), {});
|
|
1445
|
+
const next = picked.kind === "none" ? null : picked.item;
|
|
1446
|
+
if (picked.kind === "needs_brief" || picked.kind === "blocked_owner" || picked.kind === "in_flight") {
|
|
1447
|
+
console.log(`next ${picked.item.id} \u2014 "${picked.item.title}" ${picked.kind.replace("_", " ")}`);
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
if (!next) {
|
|
1451
|
+
console.log(`next (nothing open)${planComplete(plan) ? " \u2014 the plan is complete" : ""}`);
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
const brief = next.spec_path ? ` (brief ${next.spec_path})` : " (no brief yet)";
|
|
1455
|
+
const ready = next.status === "queued" && next.spec ? " ready" : next.status === "pending" ? "" : ` ${next.status}`;
|
|
1456
|
+
console.log(`next ${next.id} \u2014 "${next.title}"${brief}${ready}`);
|
|
1457
|
+
if (next.spec && next.status === "queued") {
|
|
1458
|
+
const prompt = renderPlanItemPrompt(plan, next.id).split("\n")[0];
|
|
1459
|
+
console.log(`prompt ${prompt}`);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// src/surfaces/cli/flow.ts
|
|
1464
|
+
function roundText(state) {
|
|
1465
|
+
const total = state.max_total_rounds > 0 ? state.max_total_rounds : state.max_rounds;
|
|
1466
|
+
const flow = `${Math.min(state.rounds, total)}/${total} flow`;
|
|
1467
|
+
const item = planItemRound(state);
|
|
1468
|
+
return item === null ? flow : `${item} \xB7 ${flow}`;
|
|
1469
|
+
}
|
|
1470
|
+
function planItemRound(state) {
|
|
1471
|
+
const id = state.claim.spec_id ?? state.active_plan_item;
|
|
1472
|
+
if (!id) return null;
|
|
1473
|
+
try {
|
|
1474
|
+
const plan = readPlan(state.run_id);
|
|
1475
|
+
const item = plan.items.find((entry) => entry.id === id);
|
|
1476
|
+
if (!item) return null;
|
|
1477
|
+
const max = state.max_rounds > 0 ? state.max_rounds : item.rounds;
|
|
1478
|
+
return `${id} rounds ${Math.min(item.rounds, max)}/${max}`;
|
|
1479
|
+
} catch {
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
function pendingSpecs(state) {
|
|
1484
|
+
return state.specs.filter((spec) => !state.dispatched_specs.includes(spec.id));
|
|
1485
|
+
}
|
|
1486
|
+
function pendingCount(state) {
|
|
1487
|
+
return pendingSpecs(state).length;
|
|
1488
|
+
}
|
|
1489
|
+
function queueLine(state) {
|
|
1490
|
+
const pending = pendingSpecs(state);
|
|
1491
|
+
const ids = pending.slice(0, 3).map((spec) => spec.id);
|
|
1492
|
+
const more = pending.length > ids.length ? "\u2026" : "";
|
|
1493
|
+
return `${pending.length} pending, ${state.dispatched_specs.length} dispatched${ids.length > 0 ? ` \xB7 ${ids.join(", ")}${more}` : ""}`;
|
|
1494
|
+
}
|
|
1495
|
+
function tickPayload(result, dryRun) {
|
|
1496
|
+
const { decision } = result;
|
|
1497
|
+
return {
|
|
1498
|
+
dry_run: dryRun,
|
|
1499
|
+
status: result.status,
|
|
1500
|
+
decision: {
|
|
1501
|
+
kind: decision.kind,
|
|
1502
|
+
reason: decision.reason,
|
|
1503
|
+
next_state: decision.next_state,
|
|
1504
|
+
next_rounds: decision.next_rounds,
|
|
1505
|
+
target: decision.target ?? null,
|
|
1506
|
+
head: decision.head ?? null,
|
|
1507
|
+
spec_id: decision.spec_id ?? null,
|
|
1508
|
+
// The message is summarised, never dumped: it can embed a reviewer's remarks.
|
|
1509
|
+
message: decision.message ? { lines: decision.message.split("\n").length, chars: decision.message.length } : null
|
|
1510
|
+
},
|
|
1511
|
+
send: result.send ?? null,
|
|
1512
|
+
observations: {
|
|
1513
|
+
head: result.observations.head,
|
|
1514
|
+
tree_clean: result.observations.tree_clean,
|
|
1515
|
+
dev_pane: result.observations.dev_pane,
|
|
1516
|
+
review_pane: result.observations.review_pane,
|
|
1517
|
+
verdict: result.observations.verdict,
|
|
1518
|
+
verdict_count: result.observations.verdict_count,
|
|
1519
|
+
// Where the verdict came from, and which round file it was read from: without these two a tick that re-requests a review
|
|
1520
|
+
// nobody understands (blocks 41) looks exactly like a tick that had no answer at all.
|
|
1521
|
+
verdict_source: result.observations.verdict_source,
|
|
1522
|
+
notes_head: result.observations.notes_head ?? null,
|
|
1523
|
+
notes_invalid: result.observations.notes_invalid ?? null
|
|
1524
|
+
},
|
|
1525
|
+
state: result.path ? flowStatusPayload(result.state, result.path) : flowStatusPayload(result.state, flowPath(result.state.run_id))
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
function printStatus(state, path) {
|
|
1529
|
+
const head = state.claim.head ? state.claim.head.slice(0, 12) : "(none)";
|
|
1530
|
+
const verdict = state.claim.verdict ?? "none";
|
|
1531
|
+
const last = state.log.at(-1);
|
|
1532
|
+
console.log(`flow ${state.run_id}`);
|
|
1533
|
+
console.log(`state ${state.state} round ${roundText(state)}`);
|
|
1534
|
+
if (state.plan) {
|
|
1535
|
+
console.log(`plan ${state.plan.done}/${state.plan.total} done${state.plan.waiting > 0 ? ` \xB7 ${state.plan.waiting} waiting for you` : ""} (imported ${state.plan.imported_at})`);
|
|
1536
|
+
}
|
|
1537
|
+
if (state.active_plan_item) console.log(`plan item ${state.active_plan_item} in flight`);
|
|
1538
|
+
if (state.stalled_since !== null) {
|
|
1539
|
+
console.log(`dev idle since ${new Date(state.stalled_since).toISOString()} \xB7 retry ${state.dev_stall_attempts}/${state.dev_stall_max_attempts}`);
|
|
1540
|
+
}
|
|
1541
|
+
if (state.agent_question) {
|
|
1542
|
+
console.log(`agent question ${state.agent_question.agent}: ${state.agent_question.text}`);
|
|
1543
|
+
}
|
|
1544
|
+
if (state.hold) console.log(`hold ${state.hold.reason} since ${state.hold.since}`);
|
|
1545
|
+
const waiting = planWaitingLine(state);
|
|
1546
|
+
if (waiting) console.log(`waiting ${waiting}`);
|
|
1547
|
+
for (const incident of listFlowIncidents(state.run_id, { open_only: true })) {
|
|
1548
|
+
console.log(`incident ${incident.id.slice(0, 8)} ${incident.severity} ${incident.kind}${incident.spec_id ? ` ${incident.spec_id}` : ""} \xB7 ${incident.owner} \xB7 ${formatIncidentAge(flowIncidentAgeMs(incident))}`);
|
|
1549
|
+
}
|
|
1550
|
+
console.log(`tick ${tickStateText(readTickStatus())}`);
|
|
1551
|
+
console.log(`head ${head}`);
|
|
1552
|
+
console.log(`verdict ${verdict} (baseline ${state.claim.verdict_count} in the reviewer pane)`);
|
|
1553
|
+
if (state.pending) {
|
|
1554
|
+
console.log(`dispatch ${state.pending.kind} -> ${state.pending.target} claimed, unsettled (${state.pending.op_id})`);
|
|
1555
|
+
}
|
|
1556
|
+
const dispatchNote = flowDispatchNote(state);
|
|
1557
|
+
if (dispatchNote) console.log(`dispatch unconfirmed \u2014 ${dispatchNote.reason}`);
|
|
1558
|
+
if (state.state === "paused") {
|
|
1559
|
+
const since = state.paused_at ? ` since ${new Date(state.paused_at).toISOString()}` : "";
|
|
1560
|
+
console.log(`paused from ${state.paused_from ?? "idle"}${since} \u2014 \`flow resume\` puts it back`);
|
|
1561
|
+
}
|
|
1562
|
+
if (state.state === "orphaned") {
|
|
1563
|
+
console.log(`orphaned ${state.orphan_reason ?? "the run or its agents are gone"} \u2014 \`flow stop\` closes it`);
|
|
1564
|
+
}
|
|
1565
|
+
if (state.close_reason) console.log(`closed ${state.close_reason}`);
|
|
1566
|
+
const lastUnsubstantiated = [...state.log].reverse().find((entry) => entry.event === "review_unsubstantiated");
|
|
1567
|
+
if (lastUnsubstantiated) console.log(`evidence ${lastUnsubstantiated.detail}`);
|
|
1568
|
+
const review = state.review_started_at === null ? "not waiting" : `started ${new Date(state.review_started_at).toISOString()}, timeout ${state.review_timeout_sec}s`;
|
|
1569
|
+
console.log(`review ${review}`);
|
|
1570
|
+
console.log(`queue ${queueLine(state)}`);
|
|
1571
|
+
console.log(`repo ${shortHomePath(state.repo)}`);
|
|
1572
|
+
console.log(`updated ${state.updated_at}`);
|
|
1573
|
+
console.log(`last ${last ? `${last.event} ${redactSecrets(last.detail)}` : "(no events)"}`);
|
|
1574
|
+
console.log(`file ${shortHomePath(path)}`);
|
|
1575
|
+
}
|
|
1576
|
+
function formatIncidentAge(ageMs) {
|
|
1577
|
+
const seconds = Math.floor(ageMs / 1e3);
|
|
1578
|
+
if (seconds < 60) return `${seconds}s`;
|
|
1579
|
+
const minutes = Math.floor(seconds / 60);
|
|
1580
|
+
if (minutes < 60) return `${minutes}m`;
|
|
1581
|
+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
1582
|
+
}
|
|
1583
|
+
function printIncidents(runId) {
|
|
1584
|
+
const rows = listFlowIncidents(runId, { open_only: true });
|
|
1585
|
+
if (rows.length === 0) {
|
|
1586
|
+
console.log(`no open incidents for ${runId}`);
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
for (const row of rows) {
|
|
1590
|
+
console.log(`${row.id} ${row.severity} ${row.kind}${row.spec_id ? ` ${row.spec_id}` : ""} owner=${row.owner} status=${row.status} age=${formatIncidentAge(flowIncidentAgeMs(row))} count=${row.count}`);
|
|
1591
|
+
if (row.evidence.reason) console.log(` evidence ${redactSecrets(row.evidence.reason)}`);
|
|
1592
|
+
if (row.note) console.log(` note ${redactSecrets(row.note)}`);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
function registerFlowIncidentCommands(flow) {
|
|
1596
|
+
const incidents = flow.command("incidents").description("list and route durable flow incidents");
|
|
1597
|
+
incidents.command("list").requiredOption("--run <id>", "flow run id or unique prefix").action((options) => {
|
|
1598
|
+
printIncidents(resolveFlowRunId(options.run));
|
|
1599
|
+
});
|
|
1600
|
+
incidents.command("claim").requiredOption("--run <id>", "flow run id or unique prefix").requiredOption("--incident <id>", "incident id or unique prefix").action((options) => {
|
|
1601
|
+
const runId = resolveFlowRunId(options.run);
|
|
1602
|
+
const row = claimFlowIncident(runId, options.incident);
|
|
1603
|
+
console.log(`claimed ${row.id} for orchestrator`);
|
|
1604
|
+
});
|
|
1605
|
+
incidents.command("ack").requiredOption("--run <id>", "flow run id or unique prefix").requiredOption("--incident <id>", "incident id or unique prefix").action((options) => {
|
|
1606
|
+
const runId = resolveFlowRunId(options.run);
|
|
1607
|
+
const row = ackFlowIncident(runId, options.incident);
|
|
1608
|
+
console.log(`acknowledged ${row.id}; it remains open until resolved`);
|
|
1609
|
+
});
|
|
1610
|
+
incidents.command("resolve").requiredOption("--run <id>", "flow run id or unique prefix").requiredOption("--incident <id>", "incident id or unique prefix").requiredOption("--note <text>", "why the incident is resolved").action((options) => {
|
|
1611
|
+
const runId = resolveFlowRunId(options.run);
|
|
1612
|
+
const row = resolveFlowIncident(runId, options.incident, options.note);
|
|
1613
|
+
console.log(`resolved ${row.id}: ${row.note ?? ""}`);
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
function printTick(result, dryRun) {
|
|
1617
|
+
const { decision } = result;
|
|
1618
|
+
const target = decision.target ? ` -> ${decision.target}` : "";
|
|
1619
|
+
console.log(`decision ${decision.kind}${target}`);
|
|
1620
|
+
console.log(`reason ${decision.reason}`);
|
|
1621
|
+
if (decision.head) console.log(`head ${decision.head.slice(0, 12)}`);
|
|
1622
|
+
if (decision.spec_id) console.log(`block ${decision.spec_id}`);
|
|
1623
|
+
if (result.send) {
|
|
1624
|
+
console.log(`send ${result.send.sent ? "confirmed" : `refused (${result.send.reason})`}`);
|
|
1625
|
+
}
|
|
1626
|
+
if (dryRun) {
|
|
1627
|
+
console.log("dry run nothing sent, nothing written");
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
if (result.status === "locked") {
|
|
1631
|
+
console.log("result locked \u2014 another reevesagents process is writing the state directory; nothing was sent");
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
if (result.status === "cancelled") {
|
|
1635
|
+
console.log("result cancelled \u2014 the flow was paused or stopped while the dispatch was being prepared; nothing was sent");
|
|
1636
|
+
console.log(`state ${result.state.state} round ${roundText(result.state)}`);
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
console.log(`result ${result.status}`);
|
|
1640
|
+
console.log(`state ${result.state.state} round ${roundText(result.state)}`);
|
|
1641
|
+
if (result.path) console.log(`file ${shortHomePath(result.path)}`);
|
|
1642
|
+
}
|
|
1643
|
+
function countsSuffix(counts) {
|
|
1644
|
+
if (!counts) return "";
|
|
1645
|
+
const parts = [];
|
|
1646
|
+
if (counts.blocker > 0) parts.push(`${counts.blocker} BLOCKER`);
|
|
1647
|
+
if (counts.major > 0) parts.push(`${counts.major} MAJOR`);
|
|
1648
|
+
if (counts.minor > 0) parts.push(`${counts.minor} MINOR`);
|
|
1649
|
+
return parts.length > 0 ? ` \xB7 ${parts.join(", ")}` : "";
|
|
1650
|
+
}
|
|
1651
|
+
function tickHint() {
|
|
1652
|
+
return `tick ${tickStateText(readTickStatus())} \xB7 \`flow tick --run <id>\` moves one now`;
|
|
1653
|
+
}
|
|
1654
|
+
function planWaitingLine(state) {
|
|
1655
|
+
try {
|
|
1656
|
+
if (!planExists(state.run_id)) return null;
|
|
1657
|
+
const plan = readPlan(state.run_id);
|
|
1658
|
+
const needsBrief = plan.items.filter((item) => item.missing_since === null && item.spec === null && item.status !== "done" && item.status !== "skipped").map((item) => `${item.id} (needs a brief)`);
|
|
1659
|
+
const blocked = plan.items.filter((item) => item.status === "blocked_owner").map((item) => `${item.id} (blocked_owner${item.block_reason ? `: ${item.block_reason}` : ""})`);
|
|
1660
|
+
const parts = [...needsBrief, ...blocked];
|
|
1661
|
+
return parts.length > 0 ? parts.join(", ") : null;
|
|
1662
|
+
} catch {
|
|
1663
|
+
return null;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function fail(err) {
|
|
1667
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
1668
|
+
process.exit(1);
|
|
1669
|
+
}
|
|
1670
|
+
function registerFlow(program2) {
|
|
1671
|
+
const flow = program2.command("flow").description("dev -> review -> fix pipeline for a run (start, status, tick)");
|
|
1672
|
+
registerPlanCommands(flow);
|
|
1673
|
+
registerFlowIncidentCommands(flow);
|
|
1674
|
+
flow.command("start").description("attach a flow to an existing run: the dev agent, the review agent and the repo").requiredOption("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--dev <agent>", "dev agent id or nickname inside that run").requiredOption("--review <agent>", "review agent id or nickname inside that run").option("--repo <dir>", "project directory (defaults to the run working directory)").option("--spec <file...>", "block spec files to queue on the new flow").option("--max-rounds <n>", "fix rounds before the flow escalates", (value) => Number(value)).option("--review-timeout <sec>", "seconds a requested review may stay unanswered", (value) => Number(value)).option("--dev-timeout <sec>", "seconds an idle dev may hold a plan item before a retry", (value) => Number(value)).option("--dev-stall-attempts <n>", "re-nudges before a stalled plan item escalates", (value) => Number(value)).option("--replace", "start over on a run whose flow is escalated or done").option("--json", "output JSON").action((opts) => {
|
|
1675
|
+
try {
|
|
1676
|
+
const started = startFlow({
|
|
1677
|
+
run_id: opts.run,
|
|
1678
|
+
dev: opts.dev,
|
|
1679
|
+
review: opts.review,
|
|
1680
|
+
repo: opts.repo,
|
|
1681
|
+
specs: opts.spec,
|
|
1682
|
+
max_rounds: opts.maxRounds,
|
|
1683
|
+
review_timeout_sec: opts.reviewTimeout,
|
|
1684
|
+
dev_timeout_sec: opts.devTimeout,
|
|
1685
|
+
dev_stall_max_attempts: opts.devStallAttempts,
|
|
1686
|
+
replace: opts.replace === true
|
|
1687
|
+
});
|
|
1688
|
+
if (opts.json) {
|
|
1689
|
+
console.log(JSON.stringify(flowStatusPayload(started.state, started.path), null, 2));
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
console.log(`flow ${started.state.run_id}${started.replaced ? " (replaced the closed one)" : ""}`);
|
|
1693
|
+
console.log(`roles dev ${started.state.roles.dev} -> review ${started.state.roles.review}`);
|
|
1694
|
+
console.log(`head ${started.state.claim.head.slice(0, 12)} (a review is requested for the next commit)`);
|
|
1695
|
+
console.log(`queue ${pendingCount(started.state)} pending`);
|
|
1696
|
+
console.log(`repo ${shortHomePath(started.state.repo)}`);
|
|
1697
|
+
console.log(`file ${shortHomePath(started.path)}`);
|
|
1698
|
+
console.log(`next ${tickHint()}`);
|
|
1699
|
+
} catch (err) {
|
|
1700
|
+
fail(err);
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
flow.command("status").description("show the flow attached to a run").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--json", "output JSON").action((opts) => {
|
|
1704
|
+
try {
|
|
1705
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1706
|
+
const path = flowPath(runId);
|
|
1707
|
+
const state = readFlow(runId);
|
|
1708
|
+
if (opts.json) {
|
|
1709
|
+
console.log(JSON.stringify(flowStatusPayload(state, path), null, 2));
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
printStatus(state, path);
|
|
1713
|
+
} catch (err) {
|
|
1714
|
+
fail(err);
|
|
1715
|
+
}
|
|
1716
|
+
});
|
|
1717
|
+
flow.command("tick-all").description("alias of `flow tick --all`: advance every live flow once and exit").option("--dry-run", "print what each flow would do; send nothing and write nothing").option("--json", "output JSON").action((opts) => {
|
|
1718
|
+
try {
|
|
1719
|
+
const result = tickAllFlows({ dryRun: opts.dryRun === true });
|
|
1720
|
+
if (opts.json) {
|
|
1721
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
for (const entry of result.advanced) console.log(`${entry.run_id.padEnd(20)} ${entry.status.padEnd(11)} ${entry.reason}`);
|
|
1725
|
+
for (const entry of result.held) console.log(`${entry.run_id.padEnd(20)} ${entry.status.padEnd(11)} ${entry.reason}`);
|
|
1726
|
+
for (const entry of result.skipped) console.log(`${entry.run_id.padEnd(20)} skipped ${entry.why}`);
|
|
1727
|
+
console.log(`
|
|
1728
|
+
${result.advanced.length} advanced \xB7 ${result.held.length} held \xB7 ${result.skipped.length} skipped`);
|
|
1729
|
+
} catch (err) {
|
|
1730
|
+
fail(err);
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
flow.command("tick").description("run one engine step: observe, decide, claim, send and settle unless --dry-run; --all walks every live flow").option("--run <id>", "run id (a unique prefix is accepted)").option("--all", "advance every live flow once and exit: the cron path").option("--json", "output JSON").option("--dry-run", "print the decision; send nothing and write nothing").action((opts) => {
|
|
1734
|
+
try {
|
|
1735
|
+
if (opts.all === true) {
|
|
1736
|
+
const all = tickAllFlows({ dryRun: opts.dryRun === true });
|
|
1737
|
+
if (opts.json) {
|
|
1738
|
+
console.log(JSON.stringify(all, null, 2));
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
for (const entry of [...all.advanced, ...all.held]) {
|
|
1742
|
+
console.log(`${entry.run_id.padEnd(20)} ${entry.status.padEnd(11)} ${entry.reason}`);
|
|
1743
|
+
}
|
|
1744
|
+
for (const entry of all.skipped) console.log(`${entry.run_id.padEnd(20)} skipped ${entry.why}`);
|
|
1745
|
+
console.log(`
|
|
1746
|
+
${all.advanced.length} advanced \xB7 ${all.held.length} held \xB7 ${all.skipped.length} skipped`);
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
if (!opts.run) {
|
|
1750
|
+
console.error("either --run <id> or --all is required");
|
|
1751
|
+
process.exit(1);
|
|
1752
|
+
}
|
|
1753
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1754
|
+
const dryRun = opts.dryRun === true;
|
|
1755
|
+
const result = stepFlow(runId, { dryRun });
|
|
1756
|
+
if (!dryRun) {
|
|
1757
|
+
const moved = result.status === "applied" || result.status === "unconfirmed";
|
|
1758
|
+
writeTickStatus("run", { advanced: moved ? 1 : 0, held: moved ? 0 : 1, skipped: 0 });
|
|
1759
|
+
}
|
|
1760
|
+
if (opts.json) {
|
|
1761
|
+
console.log(JSON.stringify(tickPayload(result, dryRun), null, 2));
|
|
1762
|
+
} else {
|
|
1763
|
+
printTick(result, dryRun);
|
|
1764
|
+
}
|
|
1765
|
+
if (!dryRun && result.status === "unconfirmed") process.exitCode = 1;
|
|
1766
|
+
} catch (err) {
|
|
1767
|
+
fail(err);
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
flow.command("add-spec").description("queue a block on a flow that already exists: the dev receives it after the next ACCEPT").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--file <path...>", "structured JSON block spec (requirements and checks are mandatory)").option("--markdown <path...>", "ingest the file as an unstructured block: an explicit downgrade").option("--json", "output JSON").action((opts) => {
|
|
1771
|
+
try {
|
|
1772
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1773
|
+
const added = addFlowSpecs({ run_id: runId, files: opts.file, markdown: opts.markdown });
|
|
1774
|
+
if (opts.json) {
|
|
1775
|
+
console.log(JSON.stringify({
|
|
1776
|
+
run_id: runId,
|
|
1777
|
+
queued: added.queued.map((spec) => ({
|
|
1778
|
+
id: spec.id,
|
|
1779
|
+
title: redactSecrets(spec.title),
|
|
1780
|
+
unstructured: spec.unstructured === true
|
|
1781
|
+
})),
|
|
1782
|
+
state: flowStatusPayload(added.state, added.path)
|
|
1783
|
+
}, null, 2));
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
for (const spec of added.queued) {
|
|
1787
|
+
console.log(`queued ${spec.id} ${redactSecrets(spec.title)}${spec.unstructured ? " (unstructured)" : ""}`);
|
|
1788
|
+
}
|
|
1789
|
+
for (const spec of added.queued.filter((entry) => entry.unstructured)) {
|
|
1790
|
+
console.warn(`warning ${spec.id} has no requirements/checks; the reviewer has only the body to judge`);
|
|
1791
|
+
}
|
|
1792
|
+
console.log(`queue ${pendingCount(added.state)} pending`);
|
|
1793
|
+
console.log(`file ${shortHomePath(added.path)}`);
|
|
1794
|
+
} catch (err) {
|
|
1795
|
+
fail(err);
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
flow.command("drop-spec").description("drop a block the flow never sent: it leaves the queue and is never dispatched (needs --yes)").requiredOption("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--id <spec-id>", "the block to drop, as `flow status` prints it").option("--reason <text>", "why: journalled as `spec_dropped <id>: <reason>`").option("--yes", "confirm: a dropped block leaves the queue for good").option("--json", "output JSON").action((opts) => {
|
|
1799
|
+
try {
|
|
1800
|
+
requireDestructiveConfirmation(opts, "drop a block from the flow");
|
|
1801
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1802
|
+
const dropped = dropFlowSpec({ run_id: runId, id: opts.id, reason: opts.reason });
|
|
1803
|
+
if (opts.json) {
|
|
1804
|
+
console.log(JSON.stringify({
|
|
1805
|
+
run_id: runId,
|
|
1806
|
+
dropped: { id: dropped.spec.id, title: redactSecrets(dropped.spec.title) },
|
|
1807
|
+
state: flowStatusPayload(dropped.state, dropped.path)
|
|
1808
|
+
}, null, 2));
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
console.log(`dropped ${dropped.spec.id} ${redactSecrets(dropped.spec.title)}`);
|
|
1812
|
+
console.log(`queue ${pendingCount(dropped.state)} pending`);
|
|
1813
|
+
} catch (err) {
|
|
1814
|
+
fail(err);
|
|
1815
|
+
}
|
|
1816
|
+
});
|
|
1817
|
+
flow.command("pause").description("park a flow: a paused flow is never ticked and never sends anything").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--json", "output JSON").action((opts) => {
|
|
1818
|
+
try {
|
|
1819
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1820
|
+
const paused = pauseFlow(runId);
|
|
1821
|
+
if (opts.json) {
|
|
1822
|
+
console.log(JSON.stringify(flowStatusPayload(paused.state, paused.path), null, 2));
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
console.log(`flow ${runId} paused (was ${paused.state.paused_from ?? "unknown"})`);
|
|
1826
|
+
console.log("next nothing is sent while it is paused; `flow resume` puts it back to work");
|
|
1827
|
+
} catch (err) {
|
|
1828
|
+
fail(err);
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
flow.command("resume").description("put a paused flow back to work, or grant an escalated one a fresh round budget").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--json", "output JSON").action((opts) => {
|
|
1832
|
+
try {
|
|
1833
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1834
|
+
const resumed = resumeFlow(runId);
|
|
1835
|
+
if (opts.json) {
|
|
1836
|
+
console.log(JSON.stringify(flowStatusPayload(resumed.state, resumed.path), null, 2));
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
console.log(`flow ${runId} resumed into ${resumed.state.state}`);
|
|
1840
|
+
console.log(`rounds ${resumed.state.rounds}/${resumed.state.max_rounds}`);
|
|
1841
|
+
console.log("next `flow tick --run <id>` picks it up");
|
|
1842
|
+
} catch (err) {
|
|
1843
|
+
fail(err);
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
flow.command("release-round").description("free a round the engine lost: the item is in flight, but no review was requested and nothing is pending").option("--run <id>", "run id (a unique prefix is accepted)").requiredOption("--reason <text>", "why the round was lost: journaled as `round_released <item>: <reason>`").option("--json", "output JSON").action((opts) => {
|
|
1847
|
+
try {
|
|
1848
|
+
const result = releaseRound(resolveFlowRunId(opts.run ?? ""), { reason: opts.reason });
|
|
1849
|
+
if (opts.json === true) {
|
|
1850
|
+
console.log(JSON.stringify({ run_id: result.state.run_id, released: result.item, state: result.state.state }, null, 2));
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
console.log(`released ${result.item} \u2014 no review was requested for that round; the next tick dispatches it again`);
|
|
1854
|
+
console.log(`state ${result.state.state} round ${roundText(result.state)}`);
|
|
1855
|
+
} catch (err) {
|
|
1856
|
+
fail(err);
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1859
|
+
flow.command("stop").description("close a flow for good: nothing is sent after it (needs --yes)").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--yes", "confirm: a stopped flow cannot be resumed").option("--json", "output JSON").action((opts) => {
|
|
1860
|
+
try {
|
|
1861
|
+
requireDestructiveConfirmation(opts, "stop flow");
|
|
1862
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1863
|
+
const stopped = stopFlow(runId);
|
|
1864
|
+
if (opts.json) {
|
|
1865
|
+
console.log(JSON.stringify(flowStatusPayload(stopped.state, stopped.path), null, 2));
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
console.log(`flow ${runId} stopped (${stopped.state.close_reason ?? "done"})`);
|
|
1869
|
+
console.log(`file ${shortHomePath(stopped.path)} (kept: \`flow logs\` still reads it)`);
|
|
1870
|
+
} catch (err) {
|
|
1871
|
+
fail(err);
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1874
|
+
flow.command("notes").description("print the reviewer findings of one round: the durable notes file of that head").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("--head <sha>", "commit the review was requested for (defaults to the flow claim head)").option("-r, --round <n>", "review round (defaults to the newest round that has notes)", (value) => Number(value)).option("--json", "output JSON").action((opts) => {
|
|
1875
|
+
try {
|
|
1876
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1877
|
+
const state = readFlow(runId);
|
|
1878
|
+
const head = (opts.head ?? state.claim.head).trim();
|
|
1879
|
+
if (!head) throw new Error(`run ${runId} has no commit under review; pass --head <sha>`);
|
|
1880
|
+
const found = readNotesRound(runId, { head, round: opts.round });
|
|
1881
|
+
if (found.ok) {
|
|
1882
|
+
const { round } = found;
|
|
1883
|
+
if (opts.json) {
|
|
1884
|
+
console.log(JSON.stringify({
|
|
1885
|
+
run_id: runId,
|
|
1886
|
+
head: round.head,
|
|
1887
|
+
round: round.round,
|
|
1888
|
+
ref: round.ref,
|
|
1889
|
+
counts: round.counts,
|
|
1890
|
+
path: shortHomePath(round.path),
|
|
1891
|
+
notes: round.text
|
|
1892
|
+
}, null, 2));
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
console.log(`flow ${runId}`);
|
|
1896
|
+
console.log(`head ${round.head.slice(0, 12)} round ${round.round}${countsSuffix(round.counts)}`);
|
|
1897
|
+
console.log(`file ${shortHomePath(round.path)}`);
|
|
1898
|
+
console.log("");
|
|
1899
|
+
console.log(round.text.trimEnd());
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
if (found.reason === "missing" && (found.rounds?.length ?? 0) === 0) {
|
|
1903
|
+
if (opts.json) {
|
|
1904
|
+
console.log(JSON.stringify({ run_id: runId, head, notes: null, reason: "missing" }, null, 2));
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
console.log(`no notes for ${runId} (head ${head.slice(0, 12)}): no round published a notes file`);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
if (found.reason === "missing" && found.round !== void 0 && found.rounds) {
|
|
1911
|
+
console.error(`round ${found.round} does not exist for ${head.slice(0, 12)} (rounds: ${found.rounds.join(", ")})`);
|
|
1912
|
+
process.exit(1);
|
|
1913
|
+
return;
|
|
1914
|
+
}
|
|
1915
|
+
const heads = listNotesHeads(runId);
|
|
1916
|
+
console.error(heads.length > 0 ? `no notes for head ${head.slice(0, 12)} in ${runId} (heads with notes: ${heads.map((h) => h.slice(0, 12)).join(", ")})` : `no notes for ${runId} yet`);
|
|
1917
|
+
process.exit(1);
|
|
1918
|
+
} catch (err) {
|
|
1919
|
+
fail(err);
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
flow.command("logs").description("the tail of one flow journal: transitions, dispatches, verdicts, refusals").requiredOption("--run <id>", "run id (a unique prefix is accepted)").option("-n, --tail <n>", "how many entries to show", (value) => Number(value), 20).option("--json", "output JSON").action((opts) => {
|
|
1923
|
+
try {
|
|
1924
|
+
const runId = resolveFlowRunId(opts.run);
|
|
1925
|
+
const state = readFlow(runId);
|
|
1926
|
+
const limit = Number.isFinite(opts.tail) && opts.tail > 0 ? Math.floor(opts.tail) : 20;
|
|
1927
|
+
const entries = state.log.slice(-limit).map((entry) => ({
|
|
1928
|
+
at: entry.at,
|
|
1929
|
+
event: entry.event,
|
|
1930
|
+
detail: redactSecrets(entry.detail),
|
|
1931
|
+
notes_ref: entry.notes_ref ?? null,
|
|
1932
|
+
notes_counts: entry.notes_counts ?? null
|
|
1933
|
+
}));
|
|
1934
|
+
if (opts.json) {
|
|
1935
|
+
console.log(JSON.stringify(entries, null, 2));
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
if (entries.length === 0) {
|
|
1939
|
+
console.log("(no events)");
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
for (const entry of entries) {
|
|
1943
|
+
const notes = entry.notes_ref ? ` \u2192 ${entry.notes_ref}${countsSuffix(entry.notes_counts)}` : "";
|
|
1944
|
+
console.log(`${entry.at} ${entry.event.padEnd(20)} ${entry.detail}${notes}`);
|
|
1945
|
+
}
|
|
1946
|
+
} catch (err) {
|
|
1947
|
+
fail(err);
|
|
1948
|
+
}
|
|
1949
|
+
});
|
|
1950
|
+
finalizePlanCommands(flow);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
926
1953
|
// src/surfaces/cli/web.ts
|
|
927
1954
|
async function runWeb(opts) {
|
|
928
1955
|
const { checkWebExtras, webExtrasMessage } = await import("./extras-MWGWGEPB.js");
|
|
@@ -931,7 +1958,7 @@ async function runWeb(opts) {
|
|
|
931
1958
|
console.error(webExtrasMessage(extras.missing));
|
|
932
1959
|
process.exit(1);
|
|
933
1960
|
}
|
|
934
|
-
const { startWebServer } = await import("./server-
|
|
1961
|
+
const { startWebServer } = await import("./server-5U4NNV43.js");
|
|
935
1962
|
const parsed = opts.port ? Number.parseInt(opts.port, 10) : void 0;
|
|
936
1963
|
const handle = await startWebServer({
|
|
937
1964
|
port: parsed !== void 0 && Number.isFinite(parsed) ? parsed : void 0,
|
|
@@ -954,6 +1981,63 @@ function registerWeb(program2) {
|
|
|
954
1981
|
});
|
|
955
1982
|
}
|
|
956
1983
|
|
|
1984
|
+
// src/surfaces/cli/notifications.ts
|
|
1985
|
+
function fail2(err) {
|
|
1986
|
+
if (err instanceof NotificationError) {
|
|
1987
|
+
console.error(err.message);
|
|
1988
|
+
process.exit(err.code === "unavailable" ? 2 : 1);
|
|
1989
|
+
}
|
|
1990
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
function severityTag(severity) {
|
|
1994
|
+
return severity === "error" ? "ERR " : severity === "warn" ? "WARN" : "info";
|
|
1995
|
+
}
|
|
1996
|
+
function registerNotifications(program2) {
|
|
1997
|
+
const notifications = program2.command("notifications").description("the notification journal: what happened while you were away");
|
|
1998
|
+
notifications.command("list").description("recent events, newest first").option("--run <id>", "only events of this run").option("--unread", "only events newer than the read watermark").option("--limit <n>", "how many to print (default 20)").option("--json", "output JSON").action((opts) => {
|
|
1999
|
+
try {
|
|
2000
|
+
const limit = opts.limit ? Number.parseInt(opts.limit, 10) : 20;
|
|
2001
|
+
const result = readNotifications({
|
|
2002
|
+
run: opts.run,
|
|
2003
|
+
unread: opts.unread === true,
|
|
2004
|
+
limit: Number.isFinite(limit) && limit > 0 ? limit : 20
|
|
2005
|
+
});
|
|
2006
|
+
if (opts.json) {
|
|
2007
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
if (result.events.length === 0) {
|
|
2011
|
+
console.log("(no notifications)");
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
for (const event of result.events) {
|
|
2015
|
+
const where = event.run_name || event.run_id || "\u2014";
|
|
2016
|
+
const who = event.agent_nickname || event.agent_id;
|
|
2017
|
+
const unread = event.seq > result.read_seq ? "*" : " ";
|
|
2018
|
+
console.log(`${unread} ${String(event.seq).padStart(4)} ${event.received_at} ${severityTag(event.severity)} ${event.kind.padEnd(18)} ${where}${who ? ` / ${who}` : ""} ${event.title}`);
|
|
2019
|
+
}
|
|
2020
|
+
console.log(`
|
|
2021
|
+
${result.total} event${result.total === 1 ? "" : "s"} \xB7 unread ${result.events.filter((event) => event.seq > result.read_seq).length} \xB7 latest seq ${result.latest_seq}`);
|
|
2022
|
+
} catch (err) {
|
|
2023
|
+
fail2(err);
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
notifications.command("read").description("mark events read up to --seq (default: everything), monotonic").option("--seq <n>", "the highest seq to mark read").option("--json", "output JSON").action((opts) => {
|
|
2027
|
+
try {
|
|
2028
|
+
const seq = opts.seq ? Number.parseInt(opts.seq, 10) : void 0;
|
|
2029
|
+
const result = markNotificationsRead(Number.isFinite(seq) ? seq : void 0);
|
|
2030
|
+
if (opts.json) {
|
|
2031
|
+
console.log(JSON.stringify({ ...result, summary: notificationSummary() }, null, 2));
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
console.log(result.changed ? `read up to ${result.read_seq}` : `already read up to ${result.read_seq}`);
|
|
2035
|
+
} catch (err) {
|
|
2036
|
+
fail2(err);
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
|
|
957
2041
|
// src/surfaces/cli/index.ts
|
|
958
2042
|
var program = new Command();
|
|
959
2043
|
program.name("reevesagents").description("local tmux-first workspace manager for AI CLI agents").version(REEVESAGENTS_VERSION).addHelpText("after", `
|
|
@@ -996,6 +2080,8 @@ registerPresets(program);
|
|
|
996
2080
|
registerSavePreset(program);
|
|
997
2081
|
registerDeletePreset(program);
|
|
998
2082
|
registerStartPreset(program);
|
|
2083
|
+
registerFlow(program);
|
|
2084
|
+
registerNotifications(program);
|
|
999
2085
|
registerWeb(program);
|
|
1000
2086
|
registerMcp(program);
|
|
1001
2087
|
async function renderTui() {
|
|
@@ -1003,12 +2089,12 @@ async function renderTui() {
|
|
|
1003
2089
|
const [{ default: React }, { render }, { Router }] = await Promise.all([
|
|
1004
2090
|
import("react"),
|
|
1005
2091
|
import("ink"),
|
|
1006
|
-
import("./router-
|
|
2092
|
+
import("./router-S7KR2CIE.js")
|
|
1007
2093
|
]);
|
|
1008
2094
|
try {
|
|
1009
2095
|
await render(React.createElement(Router), { alternateScreen: false }).waitUntilExit();
|
|
1010
2096
|
} finally {
|
|
1011
|
-
const { closeTuiWebServer } = await import("./tui-launch-
|
|
2097
|
+
const { closeTuiWebServer } = await import("./tui-launch-7WKLVYEH.js");
|
|
1012
2098
|
await closeTuiWebServer();
|
|
1013
2099
|
}
|
|
1014
2100
|
process.exit(0);
|