@h-rig/run-plugin 0.0.6-alpha.186
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/README.md +1 -0
- package/dist/src/plugin.d.ts +4 -0
- package/dist/src/plugin.js +4319 -0
- package/dist/src/read-model/inspect-command.d.ts +19 -0
- package/dist/src/read-model/inspect-command.js +341 -0
- package/dist/src/read-model/plugin.d.ts +4 -0
- package/dist/src/read-model/plugin.js +2550 -0
- package/dist/src/read-model/read-model-backend/diagnostics.d.ts +9 -0
- package/dist/src/read-model/read-model-backend/diagnostics.js +51 -0
- package/dist/src/read-model/read-model-backend/guard.d.ts +4 -0
- package/dist/src/read-model/read-model-backend/guard.js +25 -0
- package/dist/src/read-model/read-model-backend/inbox.d.ts +23 -0
- package/dist/src/read-model/read-model-backend/inbox.js +669 -0
- package/dist/src/read-model/read-model-backend/index.d.ts +8 -0
- package/dist/src/read-model/read-model-backend/index.js +1163 -0
- package/dist/src/read-model/read-model-backend/inspect.d.ts +26 -0
- package/dist/src/read-model/read-model-backend/inspect.js +770 -0
- package/dist/src/read-model/read-model-backend/projection.d.ts +39 -0
- package/dist/src/read-model/read-model-backend/projection.js +669 -0
- package/dist/src/read-model/read-model-backend/run-status.d.ts +27 -0
- package/dist/src/read-model/read-model-backend/run-status.js +237 -0
- package/dist/src/read-model/read-model-backend/stats.d.ts +12 -0
- package/dist/src/read-model/read-model-backend/stats.js +800 -0
- package/dist/src/read-model/read-model-service.d.ts +2 -0
- package/dist/src/read-model/read-model-service.js +1725 -0
- package/dist/src/read-model/reconcile.d.ts +23 -0
- package/dist/src/read-model/reconcile.js +306 -0
- package/dist/src/read-model/run-format.d.ts +23 -0
- package/dist/src/read-model/run-format.js +202 -0
- package/dist/src/read-model/runs-screen.d.ts +14 -0
- package/dist/src/read-model/runs-screen.js +217 -0
- package/dist/src/read-model/session-journal.d.ts +26 -0
- package/dist/src/read-model/session-journal.js +355 -0
- package/dist/src/read-model/stats-command.d.ts +16 -0
- package/dist/src/read-model/stats-command.js +88 -0
- package/dist/src/read-model/stats-format.d.ts +1 -0
- package/dist/src/read-model/stats-format.js +8 -0
- package/dist/src/worker/autohost.d.ts +11 -0
- package/dist/src/worker/autohost.js +858 -0
- package/dist/src/worker/constants.d.ts +3 -0
- package/dist/src/worker/constants.js +10 -0
- package/dist/src/worker/extension.d.ts +14 -0
- package/dist/src/worker/extension.js +881 -0
- package/dist/src/worker/host.d.ts +1 -0
- package/dist/src/worker/host.js +1 -0
- package/dist/src/worker/inbox-command.d.ts +23 -0
- package/dist/src/worker/inbox-command.js +163 -0
- package/dist/src/worker/index.d.ts +2 -0
- package/dist/src/worker/index.js +1767 -0
- package/dist/src/worker/local-run-changes.d.ts +3 -0
- package/dist/src/worker/local-run-changes.js +65 -0
- package/dist/src/worker/notifications.d.ts +1 -0
- package/dist/src/worker/notifications.js +27 -0
- package/dist/src/worker/notify-cap.d.ts +11 -0
- package/dist/src/worker/notify-cap.js +13 -0
- package/dist/src/worker/panel-plugin.d.ts +11 -0
- package/dist/src/worker/panel-plugin.js +37 -0
- package/dist/src/worker/plugin.d.ts +3 -0
- package/dist/src/worker/plugin.js +1761 -0
- package/dist/src/worker/run-control-service.d.ts +2 -0
- package/dist/src/worker/run-control-service.js +210 -0
- package/dist/src/worker/session-journal-writer.d.ts +4 -0
- package/dist/src/worker/session-journal-writer.js +184 -0
- package/dist/src/worker/stall.d.ts +21 -0
- package/dist/src/worker/stall.js +55 -0
- package/dist/src/worker/utils.d.ts +21 -0
- package/dist/src/worker/utils.js +29 -0
- package/dist/src/worker/workflow-journal-writer.d.ts +7 -0
- package/dist/src/worker/workflow-journal-writer.js +76 -0
- package/package.json +47 -0
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-plugin/src/read-model/read-model-backend/inspect.ts
|
|
3
|
+
import { RIG_RUN_LOG_ENTRY } from "@rig/contracts";
|
|
4
|
+
|
|
5
|
+
// packages/run-plugin/src/read-model/read-model-backend/projection.ts
|
|
6
|
+
import { existsSync, readFileSync } from "fs";
|
|
7
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
8
|
+
import { RUN_DISCOVERY, RUN_REGISTRY_BACKBONE } from "@rig/contracts";
|
|
9
|
+
|
|
10
|
+
// packages/run-plugin/src/read-model/session-journal.ts
|
|
11
|
+
import { Schema } from "effect";
|
|
12
|
+
import {
|
|
13
|
+
CUSTOM_TYPE_FOR,
|
|
14
|
+
RIG_CONTROL_SENTINEL_END,
|
|
15
|
+
RIG_INBOX_RESOLUTION_SENTINEL,
|
|
16
|
+
RIG_PAUSE_SENTINEL,
|
|
17
|
+
RIG_RESUME_SENTINEL,
|
|
18
|
+
RIG_STOP_SENTINEL,
|
|
19
|
+
RIG_STOP_SENTINEL_END,
|
|
20
|
+
RunJournalEvent,
|
|
21
|
+
TYPE_FOR_CUSTOM
|
|
22
|
+
} from "@rig/contracts";
|
|
23
|
+
var decodeRunJournalEvent = (value) => Schema.decodeUnknownSync(RunJournalEvent)(value);
|
|
24
|
+
var RUN_STATUS_TRANSITIONS = {
|
|
25
|
+
created: ["queued", "preparing", "running", "failed", "stopped"],
|
|
26
|
+
queued: ["preparing", "running", "failed", "stopped"],
|
|
27
|
+
preparing: ["queued", "running", "needs-attention", "failed", "stopped"],
|
|
28
|
+
running: [
|
|
29
|
+
"queued",
|
|
30
|
+
"waiting-approval",
|
|
31
|
+
"waiting-user-input",
|
|
32
|
+
"paused",
|
|
33
|
+
"validating",
|
|
34
|
+
"reviewing",
|
|
35
|
+
"closing-out",
|
|
36
|
+
"needs-attention",
|
|
37
|
+
"completed",
|
|
38
|
+
"failed",
|
|
39
|
+
"stopped"
|
|
40
|
+
],
|
|
41
|
+
"waiting-approval": ["running", "needs-attention", "failed", "stopped"],
|
|
42
|
+
"waiting-user-input": ["running", "needs-attention", "failed", "stopped"],
|
|
43
|
+
paused: ["running", "failed", "stopped"],
|
|
44
|
+
validating: ["running", "reviewing", "closing-out", "needs-attention", "completed", "failed", "stopped"],
|
|
45
|
+
reviewing: ["running", "validating", "closing-out", "needs-attention", "completed", "failed", "stopped"],
|
|
46
|
+
"closing-out": ["running", "needs-attention", "completed", "failed", "stopped"],
|
|
47
|
+
"needs-attention": ["queued", "preparing", "running", "closing-out", "completed", "failed", "stopped"],
|
|
48
|
+
completed: [],
|
|
49
|
+
failed: ["queued", "preparing", "running", "closing-out"],
|
|
50
|
+
stopped: ["queued", "preparing", "running", "closing-out"]
|
|
51
|
+
};
|
|
52
|
+
var TERMINAL_RUN_STATUSES = ["completed", "failed", "stopped"];
|
|
53
|
+
function isTerminalRunStatus(status) {
|
|
54
|
+
return TERMINAL_RUN_STATUSES.includes(status);
|
|
55
|
+
}
|
|
56
|
+
function canTransitionRunStatus(from, to) {
|
|
57
|
+
if (from === null)
|
|
58
|
+
return true;
|
|
59
|
+
if (from === to)
|
|
60
|
+
return true;
|
|
61
|
+
return RUN_STATUS_TRANSITIONS[from].includes(to);
|
|
62
|
+
}
|
|
63
|
+
function reduceRunJournal(events, runId = null) {
|
|
64
|
+
let record = {};
|
|
65
|
+
let status = null;
|
|
66
|
+
const statusHistory = [];
|
|
67
|
+
const pendingApprovals = new Map;
|
|
68
|
+
const resolvedApprovals = [];
|
|
69
|
+
const pendingUserInputs = new Map;
|
|
70
|
+
const resolvedUserInputs = [];
|
|
71
|
+
const closeoutPhases = [];
|
|
72
|
+
let resolvedPipeline = null;
|
|
73
|
+
const stageOutcomes = [];
|
|
74
|
+
const anomalies = [];
|
|
75
|
+
let steeringCount = 0;
|
|
76
|
+
let stallCount = 0;
|
|
77
|
+
let lastSeq = 0;
|
|
78
|
+
let lastEventAt = null;
|
|
79
|
+
const projectedRunId = runId ?? events[0]?.runId ?? null;
|
|
80
|
+
for (const event of events) {
|
|
81
|
+
lastSeq = event.seq;
|
|
82
|
+
lastEventAt = event.at;
|
|
83
|
+
switch (event.type) {
|
|
84
|
+
case "status-changed": {
|
|
85
|
+
if (!canTransitionRunStatus(status, event.to)) {
|
|
86
|
+
anomalies.push({ seq: event.seq, kind: "illegal-transition", detail: `${status ?? "(none)"} -> ${event.to}` });
|
|
87
|
+
}
|
|
88
|
+
statusHistory.push({ seq: event.seq, at: event.at, from: status, to: event.to, reason: event.reason ?? null });
|
|
89
|
+
const wasTerminal = status !== null && isTerminalRunStatus(status);
|
|
90
|
+
status = event.to;
|
|
91
|
+
record = { ...record, updatedAt: event.at };
|
|
92
|
+
if (isTerminalRunStatus(event.to) && !record.completedAt)
|
|
93
|
+
record = { ...record, completedAt: event.at };
|
|
94
|
+
if (!isTerminalRunStatus(event.to) && wasTerminal)
|
|
95
|
+
record = { ...record, completedAt: null };
|
|
96
|
+
if (event.to === "running" && !record.startedAt)
|
|
97
|
+
record = { ...record, startedAt: event.at };
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "record-patch": {
|
|
101
|
+
const next = { ...record };
|
|
102
|
+
for (const [key, value] of Object.entries(event.patch)) {
|
|
103
|
+
if (value !== undefined)
|
|
104
|
+
next[key] = value;
|
|
105
|
+
}
|
|
106
|
+
next.updatedAt = event.patch.updatedAt ?? event.at;
|
|
107
|
+
record = next;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "approval-requested": {
|
|
111
|
+
pendingApprovals.set(event.requestId, {
|
|
112
|
+
requestId: event.requestId,
|
|
113
|
+
requestKind: event.requestKind,
|
|
114
|
+
actionId: event.actionId ?? null,
|
|
115
|
+
payload: event.payload,
|
|
116
|
+
requestedAt: event.at
|
|
117
|
+
});
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "approval-resolved": {
|
|
121
|
+
const pending = pendingApprovals.get(event.requestId);
|
|
122
|
+
if (!pending) {
|
|
123
|
+
const alreadyResolved = resolvedApprovals.some((entry) => entry.requestId === event.requestId);
|
|
124
|
+
anomalies.push({ seq: event.seq, kind: alreadyResolved ? "duplicate-resolution" : "unknown-request", detail: `approval ${event.requestId}` });
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
pendingApprovals.delete(event.requestId);
|
|
128
|
+
resolvedApprovals.push({ ...pending, decision: event.decision, note: event.note ?? null, actor: event.actor, resolvedAt: event.at });
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "input-requested": {
|
|
132
|
+
pendingUserInputs.set(event.requestId, {
|
|
133
|
+
requestId: event.requestId,
|
|
134
|
+
requestKind: "user-input",
|
|
135
|
+
actionId: null,
|
|
136
|
+
payload: event.payload,
|
|
137
|
+
requestedAt: event.at
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case "input-resolved": {
|
|
142
|
+
const pending = pendingUserInputs.get(event.requestId);
|
|
143
|
+
if (!pending) {
|
|
144
|
+
const alreadyResolved = resolvedUserInputs.some((entry) => entry.requestId === event.requestId);
|
|
145
|
+
anomalies.push({ seq: event.seq, kind: alreadyResolved ? "duplicate-resolution" : "unknown-request", detail: `user-input ${event.requestId}` });
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
pendingUserInputs.delete(event.requestId);
|
|
149
|
+
resolvedUserInputs.push({ ...pending, answers: event.answers, actor: event.actor, resolvedAt: event.at });
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "steering":
|
|
153
|
+
steeringCount += 1;
|
|
154
|
+
break;
|
|
155
|
+
case "adopted":
|
|
156
|
+
record = { ...record, pid: event.pid, updatedAt: event.at };
|
|
157
|
+
break;
|
|
158
|
+
case "stall-detected":
|
|
159
|
+
stallCount += 1;
|
|
160
|
+
break;
|
|
161
|
+
case "closeout-phase":
|
|
162
|
+
closeoutPhases.push({ seq: event.seq, at: event.at, phase: event.phase, outcome: event.outcome, detail: event.detail ?? null });
|
|
163
|
+
break;
|
|
164
|
+
case "pipeline-resolved":
|
|
165
|
+
resolvedPipeline = event.pipeline;
|
|
166
|
+
break;
|
|
167
|
+
case "stage-outcome":
|
|
168
|
+
stageOutcomes.push({ seq: event.seq, at: event.at, outcome: event.outcome });
|
|
169
|
+
break;
|
|
170
|
+
case "timeline-entry":
|
|
171
|
+
case "log-entry":
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
runId: projectedRunId,
|
|
177
|
+
record,
|
|
178
|
+
status,
|
|
179
|
+
statusHistory,
|
|
180
|
+
pendingApprovals: [...pendingApprovals.values()],
|
|
181
|
+
resolvedApprovals,
|
|
182
|
+
pendingUserInputs: [...pendingUserInputs.values()],
|
|
183
|
+
resolvedUserInputs,
|
|
184
|
+
steeringCount,
|
|
185
|
+
stallCount,
|
|
186
|
+
closeoutPhases,
|
|
187
|
+
resolvedPipeline,
|
|
188
|
+
stageOutcomes,
|
|
189
|
+
lastSeq,
|
|
190
|
+
lastEventAt,
|
|
191
|
+
anomalies
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function isRunSessionCustomType(customType) {
|
|
195
|
+
return customType !== undefined && Object.hasOwn(TYPE_FOR_CUSTOM, customType);
|
|
196
|
+
}
|
|
197
|
+
function foldRunSessionEntries(entries, runId) {
|
|
198
|
+
const events = [];
|
|
199
|
+
entries.forEach((entry, index) => {
|
|
200
|
+
if (entry.type !== "custom" || !isRunSessionCustomType(entry.customType))
|
|
201
|
+
return;
|
|
202
|
+
const data = entry.data !== null && typeof entry.data === "object" ? entry.data : {};
|
|
203
|
+
const stamped = {
|
|
204
|
+
v: 1,
|
|
205
|
+
seq: index + 1,
|
|
206
|
+
at: typeof data.at === "string" ? data.at : new Date(0).toISOString(),
|
|
207
|
+
runId,
|
|
208
|
+
...data,
|
|
209
|
+
type: TYPE_FOR_CUSTOM[entry.customType]
|
|
210
|
+
};
|
|
211
|
+
try {
|
|
212
|
+
events.push(decodeRunJournalEvent(stamped));
|
|
213
|
+
} catch {}
|
|
214
|
+
});
|
|
215
|
+
return reduceRunJournal(events, runId);
|
|
216
|
+
}
|
|
217
|
+
function isRecord(value) {
|
|
218
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
219
|
+
}
|
|
220
|
+
function timelineEntryFromCustomEntry(entry) {
|
|
221
|
+
if (entry.customType !== CUSTOM_TYPE_FOR["timeline-entry"] || !isRecord(entry.data))
|
|
222
|
+
return null;
|
|
223
|
+
const payload = isRecord(entry.data.payload) ? entry.data.payload : entry.data;
|
|
224
|
+
const type = typeof payload.type === "string" ? payload.type : "timeline";
|
|
225
|
+
const stage = typeof payload.stage === "string" ? payload.stage : typeof payload.name === "string" ? payload.name : null;
|
|
226
|
+
const status = typeof payload.status === "string" ? payload.status : typeof payload.outcome === "string" ? payload.outcome : null;
|
|
227
|
+
const detail = typeof payload.detail === "string" ? payload.detail : typeof payload.message === "string" ? payload.message : null;
|
|
228
|
+
const at = typeof entry.data.at === "string" ? entry.data.at : typeof payload.at === "string" ? payload.at : null;
|
|
229
|
+
return { at, type, stage, status, detail };
|
|
230
|
+
}
|
|
231
|
+
function timelineEntriesFromCustomEntries(entries) {
|
|
232
|
+
return entries.flatMap((entry) => {
|
|
233
|
+
const timelineEntry = timelineEntryFromCustomEntry(entry);
|
|
234
|
+
return timelineEntry ? [timelineEntry] : [];
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// packages/run-plugin/src/read-model/read-model-backend/projection.ts
|
|
239
|
+
import { loadCapabilityForRoot } from "@rig/core/capability-loaders";
|
|
240
|
+
import { defineCapability } from "@rig/core/capability";
|
|
241
|
+
|
|
242
|
+
// packages/run-plugin/src/read-model/read-model-backend/run-status.ts
|
|
243
|
+
var OPERATOR_INACTIVE_RUN_STATUSES = new Set([
|
|
244
|
+
"completed",
|
|
245
|
+
"complete",
|
|
246
|
+
"done",
|
|
247
|
+
"success",
|
|
248
|
+
"succeeded",
|
|
249
|
+
"passed",
|
|
250
|
+
"failed",
|
|
251
|
+
"failure",
|
|
252
|
+
"error",
|
|
253
|
+
"errored",
|
|
254
|
+
"stopped",
|
|
255
|
+
"cancelled",
|
|
256
|
+
"canceled",
|
|
257
|
+
"aborted",
|
|
258
|
+
"abort",
|
|
259
|
+
"merged",
|
|
260
|
+
"closed",
|
|
261
|
+
"skipped",
|
|
262
|
+
"needs-attention",
|
|
263
|
+
"needs_attention"
|
|
264
|
+
]);
|
|
265
|
+
var TERMINAL_RUN_STATUSES2 = ["completed", "failed", "stopped"];
|
|
266
|
+
var RUNTIME_ACTIVE_STATUSES = new Set([
|
|
267
|
+
"created",
|
|
268
|
+
"preparing",
|
|
269
|
+
"running",
|
|
270
|
+
"validating",
|
|
271
|
+
"reviewing",
|
|
272
|
+
"closing-out"
|
|
273
|
+
]);
|
|
274
|
+
var ACTIVE_RUN_STATUSES = [
|
|
275
|
+
"created",
|
|
276
|
+
"queued",
|
|
277
|
+
"preparing",
|
|
278
|
+
"running",
|
|
279
|
+
"waiting-approval",
|
|
280
|
+
"waiting-user-input",
|
|
281
|
+
"paused",
|
|
282
|
+
"validating",
|
|
283
|
+
"reviewing",
|
|
284
|
+
"closing-out",
|
|
285
|
+
"needs-attention"
|
|
286
|
+
];
|
|
287
|
+
var KNOWN_RUN_STATUS = Object.fromEntries([...ACTIVE_RUN_STATUSES, ...TERMINAL_RUN_STATUSES2].map((status) => [status, true]));
|
|
288
|
+
function isRuntimeActiveStatus(status) {
|
|
289
|
+
return RUNTIME_ACTIVE_STATUSES.has(normalizeRunStatusToken(status));
|
|
290
|
+
}
|
|
291
|
+
function normalizeRunStatusToken(status) {
|
|
292
|
+
return String(status ?? "").trim().toLowerCase().replace(/[\s_]+/g, "-");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// packages/run-plugin/src/read-model/read-model-backend/diagnostics.ts
|
|
296
|
+
function normalizeString(value) {
|
|
297
|
+
if (typeof value !== "string")
|
|
298
|
+
return null;
|
|
299
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
300
|
+
return normalized.length > 0 ? normalized : null;
|
|
301
|
+
}
|
|
302
|
+
function isGenericRunFailure(value) {
|
|
303
|
+
const text = normalizeString(value);
|
|
304
|
+
return Boolean(text && /^Task run failed \([^)]*\)$/i.test(text));
|
|
305
|
+
}
|
|
306
|
+
function appendCandidate(candidates, value) {
|
|
307
|
+
const text = normalizeString(value);
|
|
308
|
+
if (text && !candidates.includes(text))
|
|
309
|
+
candidates.push(text);
|
|
310
|
+
}
|
|
311
|
+
function categorizeUsefulRunError(lines) {
|
|
312
|
+
const taskSourceFailure = lines.find((line) => /failed to update task source/i.test(line));
|
|
313
|
+
if (taskSourceFailure)
|
|
314
|
+
return `Task source update failed: ${taskSourceFailure}`;
|
|
315
|
+
const moduleFailure = lines.find((line) => /cannot find module/i.test(line));
|
|
316
|
+
if (moduleFailure)
|
|
317
|
+
return `Runtime module resolution failed: ${moduleFailure}`;
|
|
318
|
+
const providerFailure = lines.find((line) => /no api key found|unauthorized|authentication failed|invalid api key/i.test(line));
|
|
319
|
+
if (providerFailure)
|
|
320
|
+
return `Provider authentication failed: ${providerFailure}`;
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
function summarizeRunError(projection) {
|
|
324
|
+
if (projection.status !== "failed")
|
|
325
|
+
return null;
|
|
326
|
+
const candidates = [];
|
|
327
|
+
for (const anomaly of projection.anomalies) {
|
|
328
|
+
appendCandidate(candidates, `Journal anomaly (${anomaly.kind}): ${anomaly.detail}`);
|
|
329
|
+
}
|
|
330
|
+
for (const phase of projection.closeoutPhases) {
|
|
331
|
+
if (phase.outcome === "failed")
|
|
332
|
+
appendCandidate(candidates, phase.detail);
|
|
333
|
+
}
|
|
334
|
+
for (const entry of projection.statusHistory) {
|
|
335
|
+
appendCandidate(candidates, entry.reason);
|
|
336
|
+
}
|
|
337
|
+
appendCandidate(candidates, projection.record.statusDetail);
|
|
338
|
+
appendCandidate(candidates, projection.record.errorText);
|
|
339
|
+
const nonGeneric = candidates.filter((candidate) => !isGenericRunFailure(candidate));
|
|
340
|
+
return categorizeUsefulRunError(nonGeneric) ?? nonGeneric.at(-1) ?? normalizeString(projection.record.errorText);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// packages/run-plugin/src/read-model/read-model-backend/projection.ts
|
|
344
|
+
var RunDiscoveryCap = defineCapability(RUN_DISCOVERY);
|
|
345
|
+
var RunRegistryBackboneCap = defineCapability(RUN_REGISTRY_BACKBONE);
|
|
346
|
+
function registryEntryFromCollab(collab) {
|
|
347
|
+
const record = collab;
|
|
348
|
+
return {
|
|
349
|
+
roomId: collab.sessionId,
|
|
350
|
+
title: collab.title,
|
|
351
|
+
status: record.registryStatus ?? (collab.stale ? "stale" : "running"),
|
|
352
|
+
startedAt: collab.startedAt ?? null,
|
|
353
|
+
heartbeatAt: collab.updatedAt ?? null,
|
|
354
|
+
sessionPath: collab.sessionPath ?? null,
|
|
355
|
+
cwd: collab.cwd ?? null,
|
|
356
|
+
joinLink: collab.joinLink ?? null,
|
|
357
|
+
webLink: collab.webLink ?? null,
|
|
358
|
+
relayUrl: collab.relayUrl ?? null,
|
|
359
|
+
stale: collab.stale,
|
|
360
|
+
repo: collab.selectedRepo ?? null,
|
|
361
|
+
...collab.pid === undefined ? {} : { pid: collab.pid },
|
|
362
|
+
projection: record.registryProjection ?? null
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
var EMPTY_PROJECTION = foldRunSessionEntries([], "");
|
|
366
|
+
var DISCOVERY_DIAGNOSTIC_RUN_ID = "__registry_discovery_error__";
|
|
367
|
+
function readSessionRunEntries(sessionPath) {
|
|
368
|
+
if (!sessionPath || !existsSync(sessionPath))
|
|
369
|
+
return [];
|
|
370
|
+
try {
|
|
371
|
+
return parseSessionRunEntries(readFileSync(sessionPath, "utf8"));
|
|
372
|
+
} catch {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function parseSessionRunEntries(raw) {
|
|
377
|
+
const entries = [];
|
|
378
|
+
for (const line of raw.split(`
|
|
379
|
+
`)) {
|
|
380
|
+
if (!line.trim())
|
|
381
|
+
continue;
|
|
382
|
+
try {
|
|
383
|
+
const parsed = JSON.parse(line);
|
|
384
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
385
|
+
continue;
|
|
386
|
+
entries.push({
|
|
387
|
+
type: "type" in parsed && typeof parsed.type === "string" ? parsed.type : "",
|
|
388
|
+
..."customType" in parsed && typeof parsed.customType === "string" ? { customType: parsed.customType } : {},
|
|
389
|
+
..."data" in parsed ? { data: parsed.data } : {}
|
|
390
|
+
});
|
|
391
|
+
} catch {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return entries;
|
|
396
|
+
}
|
|
397
|
+
function stringOrNull(value) {
|
|
398
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
399
|
+
}
|
|
400
|
+
function numberOrNull(value) {
|
|
401
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
402
|
+
}
|
|
403
|
+
function objectRecord(value) {
|
|
404
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
405
|
+
}
|
|
406
|
+
function payloadString(payload, keys) {
|
|
407
|
+
if (!payload || typeof payload !== "object")
|
|
408
|
+
return null;
|
|
409
|
+
const record = payload;
|
|
410
|
+
for (const key of keys) {
|
|
411
|
+
const value = record[key];
|
|
412
|
+
if (typeof value === "string" && value.trim())
|
|
413
|
+
return value.trim();
|
|
414
|
+
}
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
function payloadOptions(payload) {
|
|
418
|
+
if (!payload || typeof payload !== "object")
|
|
419
|
+
return;
|
|
420
|
+
const record = payload;
|
|
421
|
+
const options = Array.isArray(record.options) ? record.options : Array.isArray(record.choices) ? record.choices : null;
|
|
422
|
+
const values = options?.filter((value) => typeof value === "string" && value.trim().length > 0) ?? [];
|
|
423
|
+
return values.length > 0 ? values : undefined;
|
|
424
|
+
}
|
|
425
|
+
function inboxRequest(request, kind) {
|
|
426
|
+
const fallback = kind === "approval" ? "Approval requested" : "Input requested";
|
|
427
|
+
const body = payloadString(request.payload, ["body", "description", "detail", "details"]);
|
|
428
|
+
const options = payloadOptions(request.payload);
|
|
429
|
+
return {
|
|
430
|
+
requestId: request.requestId,
|
|
431
|
+
kind,
|
|
432
|
+
title: payloadString(request.payload, ["title", "message", "reason", "prompt", "summary"]) ?? fallback,
|
|
433
|
+
...body !== undefined ? { body } : {},
|
|
434
|
+
...options ? { options } : {},
|
|
435
|
+
requestedAt: request.requestedAt ?? null,
|
|
436
|
+
source: "run"
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function inboxFromProjection(projection) {
|
|
440
|
+
return [
|
|
441
|
+
...projection.pendingApprovals.map((request) => inboxRequest(request, "approval")),
|
|
442
|
+
...projection.pendingUserInputs.map((request) => inboxRequest(request, "input"))
|
|
443
|
+
].sort((a, b) => (Date.parse(a.requestedAt ?? "") || 0) - (Date.parse(b.requestedAt ?? "") || 0));
|
|
444
|
+
}
|
|
445
|
+
function isProjectPath(projectRoot, cwd) {
|
|
446
|
+
const root = resolve(projectRoot);
|
|
447
|
+
const candidate = resolve(cwd);
|
|
448
|
+
const pathFromRoot = relative(root, candidate);
|
|
449
|
+
return pathFromRoot === "" || !pathFromRoot.startsWith("../") && pathFromRoot !== ".." && !isAbsolute(pathFromRoot);
|
|
450
|
+
}
|
|
451
|
+
function sourceFromEntry(projectRoot, projection, entry) {
|
|
452
|
+
const candidates = [
|
|
453
|
+
stringOrNull(projection.collabCwd),
|
|
454
|
+
stringOrNull(projection.cwd),
|
|
455
|
+
stringOrNull(entry.cwd),
|
|
456
|
+
stringOrNull(projection.worktreePath)
|
|
457
|
+
].filter((cwd) => cwd !== null);
|
|
458
|
+
return candidates.some((cwd) => isProjectPath(projectRoot, cwd)) ? "local" : "remote";
|
|
459
|
+
}
|
|
460
|
+
function pendingRequests(value, fallbackKind) {
|
|
461
|
+
if (!Array.isArray(value))
|
|
462
|
+
return [];
|
|
463
|
+
return value.flatMap((item) => {
|
|
464
|
+
const record = objectRecord(item);
|
|
465
|
+
const requestId = stringOrNull(record?.requestId) ?? stringOrNull(record?.id);
|
|
466
|
+
if (!record || !requestId)
|
|
467
|
+
return [];
|
|
468
|
+
return [{
|
|
469
|
+
requestId,
|
|
470
|
+
requestKind: stringOrNull(record.requestKind) ?? stringOrNull(record.kind) ?? fallbackKind,
|
|
471
|
+
actionId: stringOrNull(record.actionId),
|
|
472
|
+
payload: "payload" in record ? record.payload : record,
|
|
473
|
+
requestedAt: stringOrNull(record.requestedAt) ?? stringOrNull(record.at) ?? ""
|
|
474
|
+
}];
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function emptyFoldedProjection(runId, projection, toRunStatus) {
|
|
478
|
+
const projectionRecord = projection;
|
|
479
|
+
const nestedProjection = objectRecord(projectionRecord.projection);
|
|
480
|
+
const pendingApprovals = pendingRequests(nestedProjection?.pendingApprovals ?? projectionRecord.pendingApprovals, "approval");
|
|
481
|
+
const pendingUserInputs = pendingRequests(nestedProjection?.pendingUserInputs ?? nestedProjection?.pendingInputs ?? projectionRecord.pendingUserInputs ?? (Array.isArray(projectionRecord.pendingInputs) ? projectionRecord.pendingInputs : undefined), "user-input");
|
|
482
|
+
const nestedRecord = objectRecord(nestedProjection?.record);
|
|
483
|
+
const nestedFolded = nestedProjection;
|
|
484
|
+
return {
|
|
485
|
+
...EMPTY_PROJECTION,
|
|
486
|
+
...nestedFolded ?? {},
|
|
487
|
+
record: {
|
|
488
|
+
...nestedRecord ?? {},
|
|
489
|
+
runId,
|
|
490
|
+
...projection.taskId ? { taskId: projection.taskId } : {},
|
|
491
|
+
...projection.title ? { title: projection.title } : {},
|
|
492
|
+
...projection.startedAt ? { startedAt: projection.startedAt } : {},
|
|
493
|
+
...projection.updatedAt ? { updatedAt: projection.updatedAt } : {},
|
|
494
|
+
...projection.completedAt ? { completedAt: projection.completedAt } : {},
|
|
495
|
+
...projection.sessionPath ? { sessionPath: projection.sessionPath } : {},
|
|
496
|
+
...projection.worktreePath ? { worktreePath: projection.worktreePath } : {},
|
|
497
|
+
...projection.prUrl ? { prUrl: projection.prUrl } : {}
|
|
498
|
+
},
|
|
499
|
+
status: toRunStatus(projection.status) ?? toRunStatus(nestedProjection?.status),
|
|
500
|
+
pendingApprovals,
|
|
501
|
+
pendingUserInputs,
|
|
502
|
+
steeringCount: projection.steeringCount ?? numberOrNull(nestedProjection?.steeringCount) ?? 0,
|
|
503
|
+
stallCount: projection.stallCount ?? numberOrNull(nestedProjection?.stallCount) ?? 0,
|
|
504
|
+
lastEventAt: projection.updatedAt ?? stringOrNull(nestedProjection?.lastEventAt)
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function foldedProjectionForRun(runId, projection, sessionPath, toRunStatus) {
|
|
508
|
+
const registryFolded = emptyFoldedProjection(runId, projection, toRunStatus);
|
|
509
|
+
const sessionEntries = readSessionRunEntries(sessionPath);
|
|
510
|
+
if (sessionEntries.length === 0)
|
|
511
|
+
return { projection: registryFolded, hasSessionEntries: false };
|
|
512
|
+
const sessionFolded = foldRunSessionEntries(sessionEntries, runId);
|
|
513
|
+
if (sessionFolded.lastSeq === 0)
|
|
514
|
+
return { projection: registryFolded, hasSessionEntries: false };
|
|
515
|
+
return {
|
|
516
|
+
projection: {
|
|
517
|
+
...registryFolded,
|
|
518
|
+
...sessionFolded,
|
|
519
|
+
record: {
|
|
520
|
+
...registryFolded.record,
|
|
521
|
+
...sessionFolded.record,
|
|
522
|
+
runId
|
|
523
|
+
},
|
|
524
|
+
status: sessionFolded.status ?? registryFolded.status,
|
|
525
|
+
lastEventAt: sessionFolded.lastEventAt ?? registryFolded.lastEventAt
|
|
526
|
+
},
|
|
527
|
+
hasSessionEntries: true
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function runRecordFromRegistryEntry(projectRoot, entry, toRunStatus) {
|
|
531
|
+
const projection = entry.projection && typeof entry.projection === "object" ? entry.projection : {};
|
|
532
|
+
const projectionRecord = projection;
|
|
533
|
+
const runId = stringOrNull(projection.runId) ?? entry.roomId;
|
|
534
|
+
const sessionPath = stringOrNull(projection.sessionPath) ?? stringOrNull(entry.sessionPath) ?? null;
|
|
535
|
+
const foldedResult = foldedProjectionForRun(runId, projection, sessionPath, toRunStatus);
|
|
536
|
+
const folded = foldedResult.projection;
|
|
537
|
+
const pushedStatus = folded.status ?? toRunStatus(projection.status) ?? toRunStatus(entry.status);
|
|
538
|
+
const status = entry.stale ? pushedStatus && isTerminalRunStatus(pushedStatus) ? pushedStatus : "stale" : pushedStatus ?? "running";
|
|
539
|
+
const collabCwd = stringOrNull(projection.collabCwd) ?? stringOrNull(projection.cwd) ?? stringOrNull(entry.cwd) ?? stringOrNull(projection.worktreePath);
|
|
540
|
+
const pendingApprovals = foldedResult.hasSessionEntries ? folded.pendingApprovals.length : numberOrNull(projectionRecord.pendingApprovals) ?? folded.pendingApprovals.length;
|
|
541
|
+
const pendingInputs = foldedResult.hasSessionEntries ? folded.pendingUserInputs.length : numberOrNull(projectionRecord.pendingInputs) ?? folded.pendingUserInputs.length;
|
|
542
|
+
return {
|
|
543
|
+
runId,
|
|
544
|
+
taskId: stringOrNull(projection.taskId),
|
|
545
|
+
title: stringOrNull(projection.title) ?? entry.title,
|
|
546
|
+
status,
|
|
547
|
+
source: sourceFromEntry(projectRoot, projection, entry),
|
|
548
|
+
live: !entry.stale,
|
|
549
|
+
stale: entry.stale,
|
|
550
|
+
startedAt: stringOrNull(projection.startedAt) ?? entry.startedAt ?? null,
|
|
551
|
+
updatedAt: stringOrNull(projection.updatedAt) ?? entry.heartbeatAt ?? null,
|
|
552
|
+
completedAt: stringOrNull(projection.completedAt),
|
|
553
|
+
joinLink: stringOrNull(projection.joinLink) ?? entry.joinLink ?? null,
|
|
554
|
+
webLink: stringOrNull(projection.webLink) ?? entry.webLink ?? null,
|
|
555
|
+
relayUrl: stringOrNull(projection.relayUrl) ?? entry.relayUrl ?? null,
|
|
556
|
+
sessionPath,
|
|
557
|
+
prUrl: stringOrNull(projection.prUrl),
|
|
558
|
+
worktreePath: stringOrNull(projection.worktreePath) ?? collabCwd,
|
|
559
|
+
pendingApprovals,
|
|
560
|
+
pendingInputs,
|
|
561
|
+
steeringCount: projection.steeringCount ?? folded.steeringCount ?? 0,
|
|
562
|
+
stallCount: projection.stallCount ?? folded.stallCount ?? 0,
|
|
563
|
+
errorSummary: stringOrNull(projection.errorSummary) ?? summarizeRunError(folded),
|
|
564
|
+
timeline: Array.isArray(projection.timeline) ? [...projection.timeline] : [...timelineEntriesFromCustomEntries([])],
|
|
565
|
+
inbox: inboxFromProjection(folded),
|
|
566
|
+
collabCwd: collabCwd ?? null,
|
|
567
|
+
projection: folded
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function runRecordsFromCollab(projectRoot, collabs, toRunStatus) {
|
|
571
|
+
return sortByRecency(collabs.map((collab) => runRecordFromRegistryEntry(projectRoot, registryEntryFromCollab(collab), toRunStatus)).filter((record) => record !== null));
|
|
572
|
+
}
|
|
573
|
+
function sortByRecency(records) {
|
|
574
|
+
return [...records].sort((a, b) => {
|
|
575
|
+
const at = Date.parse(b.updatedAt ?? b.startedAt ?? "") || 0;
|
|
576
|
+
const bt = Date.parse(a.updatedAt ?? a.startedAt ?? "") || 0;
|
|
577
|
+
return at - bt;
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
function discoveryDiagnosticRunRecord(projectRoot, error) {
|
|
581
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
582
|
+
const runId = DISCOVERY_DIAGNOSTIC_RUN_ID;
|
|
583
|
+
const projection = {
|
|
584
|
+
...EMPTY_PROJECTION,
|
|
585
|
+
record: { runId, title: "Registry discovery unavailable" },
|
|
586
|
+
status: "needs-attention",
|
|
587
|
+
stallCount: 1
|
|
588
|
+
};
|
|
589
|
+
return {
|
|
590
|
+
runId,
|
|
591
|
+
taskId: null,
|
|
592
|
+
title: "Registry discovery unavailable",
|
|
593
|
+
status: "needs-attention",
|
|
594
|
+
source: "remote",
|
|
595
|
+
live: false,
|
|
596
|
+
stale: true,
|
|
597
|
+
startedAt: null,
|
|
598
|
+
updatedAt: null,
|
|
599
|
+
completedAt: null,
|
|
600
|
+
joinLink: null,
|
|
601
|
+
webLink: null,
|
|
602
|
+
relayUrl: null,
|
|
603
|
+
sessionPath: null,
|
|
604
|
+
prUrl: null,
|
|
605
|
+
worktreePath: null,
|
|
606
|
+
pendingApprovals: 0,
|
|
607
|
+
pendingInputs: 0,
|
|
608
|
+
steeringCount: 0,
|
|
609
|
+
stallCount: 1,
|
|
610
|
+
errorSummary: `registry discovery unavailable: ${detail}`,
|
|
611
|
+
timeline: [],
|
|
612
|
+
inbox: [],
|
|
613
|
+
collabCwd: null,
|
|
614
|
+
projection
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
async function listRunProjections(projectRoot, filter = {}) {
|
|
618
|
+
try {
|
|
619
|
+
const discovery = await loadCapabilityForRoot(projectRoot, RunDiscoveryCap);
|
|
620
|
+
if (!discovery)
|
|
621
|
+
return [discoveryDiagnosticRunRecord(projectRoot, "run discovery capability unavailable")];
|
|
622
|
+
const backbone = await loadCapabilityForRoot(projectRoot, RunRegistryBackboneCap);
|
|
623
|
+
if (!backbone)
|
|
624
|
+
return [discoveryDiagnosticRunRecord(projectRoot, "run registry backbone capability unavailable")];
|
|
625
|
+
const collabs = await discovery.listActiveRunCollab(projectRoot, filter, { isRuntimeActiveStatus });
|
|
626
|
+
return runRecordsFromCollab(projectRoot, collabs, backbone.registryStatusToRunStatus);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
return [discoveryDiagnosticRunRecord(projectRoot, error)];
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function selectRunProjection(runs, runId) {
|
|
632
|
+
const exactRun = runs.find((run) => run.runId === runId);
|
|
633
|
+
if (exactRun)
|
|
634
|
+
return exactRun;
|
|
635
|
+
const exactTask = runs.find((run) => run.taskId === runId);
|
|
636
|
+
if (exactTask)
|
|
637
|
+
return exactTask;
|
|
638
|
+
const prefixMatches = runs.filter((run) => run.runId.startsWith(runId));
|
|
639
|
+
if (prefixMatches.length === 1)
|
|
640
|
+
return prefixMatches[0] ?? null;
|
|
641
|
+
if (prefixMatches.length > 1) {
|
|
642
|
+
const matches = prefixMatches.map((run) => run.runId).join(", ");
|
|
643
|
+
throw new Error(`Ambiguous run id prefix "${runId}" matched ${prefixMatches.length} runs: ${matches}`);
|
|
644
|
+
}
|
|
645
|
+
return runs.find((run) => run.runId === DISCOVERY_DIAGNOSTIC_RUN_ID) ?? null;
|
|
646
|
+
}
|
|
647
|
+
async function getRunProjection(projectRoot, runId, filter = {}) {
|
|
648
|
+
const runs = await listRunProjections(projectRoot, filter);
|
|
649
|
+
return selectRunProjection(runs, runId);
|
|
650
|
+
}
|
|
651
|
+
var listRuns = listRunProjections;
|
|
652
|
+
var getRun = getRunProjection;
|
|
653
|
+
|
|
654
|
+
// packages/run-plugin/src/read-model/read-model-backend/inspect.ts
|
|
655
|
+
function asRecord(value) {
|
|
656
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
657
|
+
}
|
|
658
|
+
function firstString(record, keys) {
|
|
659
|
+
for (const key of keys) {
|
|
660
|
+
const value = record[key];
|
|
661
|
+
if (typeof value === "string" && value.trim().length > 0)
|
|
662
|
+
return value;
|
|
663
|
+
}
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
function stringifyLogPayload(value) {
|
|
667
|
+
if (typeof value === "string")
|
|
668
|
+
return value;
|
|
669
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
670
|
+
return String(value);
|
|
671
|
+
const record = asRecord(value);
|
|
672
|
+
if (!record)
|
|
673
|
+
return null;
|
|
674
|
+
const direct = firstString(record, ["line", "message", "text", "content", "output", "summary", "detail"]);
|
|
675
|
+
if (direct)
|
|
676
|
+
return direct;
|
|
677
|
+
try {
|
|
678
|
+
return JSON.stringify(record);
|
|
679
|
+
} catch {
|
|
680
|
+
return String(record);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function logLineFromValue(value) {
|
|
684
|
+
const record = asRecord(value);
|
|
685
|
+
if (!record)
|
|
686
|
+
return stringifyLogPayload(value);
|
|
687
|
+
const direct = firstString(record, ["line", "message", "text", "content", "output", "summary", "detail"]);
|
|
688
|
+
if (direct)
|
|
689
|
+
return direct;
|
|
690
|
+
if ("payload" in record)
|
|
691
|
+
return stringifyLogPayload(record.payload);
|
|
692
|
+
if ("data" in record)
|
|
693
|
+
return stringifyLogPayload(record.data);
|
|
694
|
+
return stringifyLogPayload(record);
|
|
695
|
+
}
|
|
696
|
+
function logLineFromSessionEntry(entry) {
|
|
697
|
+
if (entry.type !== "custom" || entry.customType !== RIG_RUN_LOG_ENTRY)
|
|
698
|
+
return null;
|
|
699
|
+
return logLineFromValue(entry.data);
|
|
700
|
+
}
|
|
701
|
+
function logLinesFromProjection(projection) {
|
|
702
|
+
const projected = projection;
|
|
703
|
+
const lines = [];
|
|
704
|
+
for (const key of ["logs", "logEntries", "journalLogs", "runLogs"]) {
|
|
705
|
+
const entries = projected[key];
|
|
706
|
+
if (!Array.isArray(entries))
|
|
707
|
+
continue;
|
|
708
|
+
for (const entry of entries) {
|
|
709
|
+
const line = logLineFromValue(entry);
|
|
710
|
+
if (line !== null)
|
|
711
|
+
lines.push(line);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return lines;
|
|
715
|
+
}
|
|
716
|
+
function extractRunLogs(run, deps = {}) {
|
|
717
|
+
const projectedLines = logLinesFromProjection(run.projection);
|
|
718
|
+
if (projectedLines.length > 0)
|
|
719
|
+
return projectedLines;
|
|
720
|
+
return (deps.readSessionRunEntries ?? readSessionRunEntries)(run.sessionPath).map(logLineFromSessionEntry).filter((line) => line !== null);
|
|
721
|
+
}
|
|
722
|
+
function summarizeRunFailures(run) {
|
|
723
|
+
const failures = [];
|
|
724
|
+
const useful = summarizeRunError(run.projection);
|
|
725
|
+
if (useful)
|
|
726
|
+
failures.push(`${run.runId}: ${useful}`);
|
|
727
|
+
if (run.status === "failed" || run.projection.status === "failed")
|
|
728
|
+
failures.push(`${run.runId}: run status failed`);
|
|
729
|
+
for (const phase of run.projection.closeoutPhases) {
|
|
730
|
+
if (phase.outcome === "failed")
|
|
731
|
+
failures.push(`${run.runId}: closeout ${phase.phase} failed${phase.detail ? ` \u2014 ${phase.detail}` : ""}`);
|
|
732
|
+
}
|
|
733
|
+
for (const anomaly of run.projection.anomalies) {
|
|
734
|
+
failures.push(`${run.runId}: anomaly ${anomaly.kind}${anomaly.detail ? ` \u2014 ${anomaly.detail}` : ""}`);
|
|
735
|
+
}
|
|
736
|
+
return failures;
|
|
737
|
+
}
|
|
738
|
+
async function runsForTask(projectRoot, taskId, deps = {}) {
|
|
739
|
+
const list = deps.listRuns ?? listRuns;
|
|
740
|
+
try {
|
|
741
|
+
const runs = await list(projectRoot);
|
|
742
|
+
const filtered = runs.filter((run2) => run2.taskId === taskId || run2.runId === taskId);
|
|
743
|
+
if (filtered.length > 0)
|
|
744
|
+
return [...filtered];
|
|
745
|
+
} catch {}
|
|
746
|
+
const run = await (deps.getRun ?? getRun)(projectRoot, taskId);
|
|
747
|
+
return run ? [run] : [];
|
|
748
|
+
}
|
|
749
|
+
function runInspectSummaryRows(runs, options = {}) {
|
|
750
|
+
const attachable = runs.filter((run) => Boolean(run.joinLink && !run.stale)).length;
|
|
751
|
+
const pendingInbox = options.pendingInbox ?? runs.reduce((total, run) => total + run.pendingApprovals + run.pendingInputs, 0);
|
|
752
|
+
return [
|
|
753
|
+
{ id: "title", label: "Inspect", currentValue: "runtime", heading: true, description: "session/runtime inspection rows from @rig/client" },
|
|
754
|
+
{ id: "inspect:sessions", label: "RUNS", currentValue: String(runs.length), heading: true, description: `${attachable} attachable OMP collab links` },
|
|
755
|
+
{ id: "inspect:cwd", label: "PROJECT ROOT", currentValue: options.projectRoot ?? "", heading: true, description: "selected target/project root used by Rig chrome" },
|
|
756
|
+
{ id: "inspect:inbox", label: "INBOX", currentValue: String(pendingInbox), values: ["open"], description: "pending run gates; open Inbox to resolve" },
|
|
757
|
+
{ id: "inspect:runs", label: "RUNS", currentValue: String(runs.length), values: ["open"], description: "open Runs to inspect individual run detail, logs, and attach controls" },
|
|
758
|
+
{ id: "inspect:audit", label: "AUDIT", currentValue: "unavailable", heading: true, description: "CLI inspect audit has no cockpit equivalent; use rig inspect audit" }
|
|
759
|
+
];
|
|
760
|
+
}
|
|
761
|
+
export {
|
|
762
|
+
summarizeRunFailures,
|
|
763
|
+
stringifyLogPayload,
|
|
764
|
+
runsForTask,
|
|
765
|
+
runInspectSummaryRows,
|
|
766
|
+
logLinesFromProjection,
|
|
767
|
+
logLineFromValue,
|
|
768
|
+
logLineFromSessionEntry,
|
|
769
|
+
extractRunLogs
|
|
770
|
+
};
|