@h-rig/run-worker 0.0.6-alpha.155 → 0.0.6-alpha.156
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/dist/src/autohost.js +10 -10
- package/dist/src/extension.js +10 -10
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +108 -33
- package/dist/src/notifications.js +1 -1
- package/dist/src/panel-plugin.d.ts +4 -5
- package/dist/src/panel-plugin.js +2 -2
- package/dist/src/plugin.d.ts +14 -0
- package/dist/src/plugin.js +851 -0
- package/dist/src/runs/control.d.ts +24 -0
- package/dist/src/runs/control.js +398 -0
- package/dist/src/runs/diagnostics.d.ts +10 -0
- package/dist/src/runs/diagnostics.js +53 -0
- package/dist/src/runs/guard.d.ts +4 -0
- package/dist/src/runs/guard.js +26 -0
- package/dist/src/runs/inbox.d.ts +44 -0
- package/dist/src/runs/inbox.js +499 -0
- package/dist/src/runs/index.d.ts +9 -0
- package/dist/src/runs/index.js +990 -0
- package/dist/src/runs/inspect.d.ts +27 -0
- package/dist/src/runs/inspect.js +459 -0
- package/dist/src/runs/projection.d.ts +24 -0
- package/dist/src/runs/projection.js +356 -0
- package/dist/src/runs/run-status.d.ts +20 -0
- package/dist/src/runs/run-status.js +181 -0
- package/dist/src/runs/stats.d.ts +13 -0
- package/dist/src/runs/stats.js +485 -0
- package/package.json +13 -8
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// packages/run-worker/src/runs/diagnostics.ts
|
|
19
|
+
function normalizeString(value) {
|
|
20
|
+
if (typeof value !== "string")
|
|
21
|
+
return null;
|
|
22
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
23
|
+
return normalized.length > 0 ? normalized : null;
|
|
24
|
+
}
|
|
25
|
+
function isGenericRunFailure(value) {
|
|
26
|
+
const text = normalizeString(value);
|
|
27
|
+
return Boolean(text && /^Task run failed \([^)]*\)$/i.test(text));
|
|
28
|
+
}
|
|
29
|
+
function appendCandidate(candidates, value) {
|
|
30
|
+
const text = normalizeString(value);
|
|
31
|
+
if (text && !candidates.includes(text))
|
|
32
|
+
candidates.push(text);
|
|
33
|
+
}
|
|
34
|
+
function categorizeUsefulRunError(lines) {
|
|
35
|
+
const taskSourceFailure = lines.find((line) => /failed to update task source/i.test(line));
|
|
36
|
+
if (taskSourceFailure)
|
|
37
|
+
return `Task source update failed: ${taskSourceFailure}`;
|
|
38
|
+
const moduleFailure = lines.find((line) => /cannot find module/i.test(line));
|
|
39
|
+
if (moduleFailure)
|
|
40
|
+
return `Runtime module resolution failed: ${moduleFailure}`;
|
|
41
|
+
const providerFailure = lines.find((line) => /no api key found|unauthorized|authentication failed|invalid api key/i.test(line));
|
|
42
|
+
if (providerFailure)
|
|
43
|
+
return `Provider authentication failed: ${providerFailure}`;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function summarizeRunError(projection) {
|
|
47
|
+
if (projection.status !== "failed")
|
|
48
|
+
return null;
|
|
49
|
+
const candidates = [];
|
|
50
|
+
for (const anomaly of projection.anomalies) {
|
|
51
|
+
appendCandidate(candidates, `Journal anomaly (${anomaly.kind}): ${anomaly.detail}`);
|
|
52
|
+
}
|
|
53
|
+
for (const phase of projection.closeoutPhases) {
|
|
54
|
+
if (phase.outcome === "failed")
|
|
55
|
+
appendCandidate(candidates, phase.detail);
|
|
56
|
+
}
|
|
57
|
+
for (const entry of projection.statusHistory) {
|
|
58
|
+
appendCandidate(candidates, entry.reason);
|
|
59
|
+
}
|
|
60
|
+
appendCandidate(candidates, projection.record.statusDetail);
|
|
61
|
+
appendCandidate(candidates, projection.record.errorText);
|
|
62
|
+
const nonGeneric = candidates.filter((candidate) => !isGenericRunFailure(candidate));
|
|
63
|
+
return categorizeUsefulRunError(nonGeneric) ?? nonGeneric.at(-1) ?? normalizeString(projection.record.errorText);
|
|
64
|
+
}
|
|
65
|
+
var init_diagnostics = () => {};
|
|
66
|
+
|
|
67
|
+
// packages/run-worker/src/runs/projection.ts
|
|
68
|
+
var exports_projection = {};
|
|
69
|
+
__export(exports_projection, {
|
|
70
|
+
selectRunProjection: () => selectRunProjection,
|
|
71
|
+
runRecordsFromRegistrySnapshot: () => runRecordsFromRegistrySnapshot,
|
|
72
|
+
runRecordFromRegistryEntry: () => runRecordFromRegistryEntry,
|
|
73
|
+
resolveRunJoinTarget: () => resolveRunJoinTarget,
|
|
74
|
+
resolveJoinTarget: () => resolveJoinTarget,
|
|
75
|
+
readSessionRunEntries: () => readSessionRunEntries,
|
|
76
|
+
listRuns: () => listRuns,
|
|
77
|
+
listRunProjections: () => listRunProjections,
|
|
78
|
+
getRunProjection: () => getRunProjection,
|
|
79
|
+
getRun: () => getRun,
|
|
80
|
+
discoveryDiagnosticRunRecord: () => discoveryDiagnosticRunRecord
|
|
81
|
+
});
|
|
82
|
+
import { existsSync, readFileSync } from "fs";
|
|
83
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
84
|
+
import { Duration, Effect, Option, Stream } from "effect";
|
|
85
|
+
import {
|
|
86
|
+
foldRunSessionEntries,
|
|
87
|
+
isTerminalRunStatus as isTerminalRunStatus2,
|
|
88
|
+
timelineEntriesFromCustomEntries
|
|
89
|
+
} from "@rig/contracts";
|
|
90
|
+
import { registrySnapshotStream } from "@rig/runtime/control-plane/discovery";
|
|
91
|
+
function readSessionRunEntries(sessionPath) {
|
|
92
|
+
if (!sessionPath || !existsSync(sessionPath))
|
|
93
|
+
return [];
|
|
94
|
+
try {
|
|
95
|
+
return parseSessionRunEntries(readFileSync(sessionPath, "utf8"));
|
|
96
|
+
} catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function parseSessionRunEntries(raw) {
|
|
101
|
+
const entries = [];
|
|
102
|
+
for (const line of raw.split(`
|
|
103
|
+
`)) {
|
|
104
|
+
if (!line.trim())
|
|
105
|
+
continue;
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(line);
|
|
108
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
109
|
+
continue;
|
|
110
|
+
entries.push({
|
|
111
|
+
type: "type" in parsed && typeof parsed.type === "string" ? parsed.type : "",
|
|
112
|
+
..."customType" in parsed && typeof parsed.customType === "string" ? { customType: parsed.customType } : {},
|
|
113
|
+
..."data" in parsed ? { data: parsed.data } : {}
|
|
114
|
+
});
|
|
115
|
+
} catch {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return entries;
|
|
120
|
+
}
|
|
121
|
+
function stringOrNull(value) {
|
|
122
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
123
|
+
}
|
|
124
|
+
function numberOrNull(value) {
|
|
125
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
126
|
+
}
|
|
127
|
+
function objectRecord(value) {
|
|
128
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
129
|
+
}
|
|
130
|
+
function registryStatusAsRunStatus(status) {
|
|
131
|
+
if (status === "waiting-input")
|
|
132
|
+
return "waiting-user-input";
|
|
133
|
+
if (status === "starting")
|
|
134
|
+
return "preparing";
|
|
135
|
+
return typeof status === "string" && [
|
|
136
|
+
"created",
|
|
137
|
+
"queued",
|
|
138
|
+
"preparing",
|
|
139
|
+
"running",
|
|
140
|
+
"waiting-approval",
|
|
141
|
+
"waiting-user-input",
|
|
142
|
+
"paused",
|
|
143
|
+
"validating",
|
|
144
|
+
"reviewing",
|
|
145
|
+
"closing-out",
|
|
146
|
+
"needs-attention",
|
|
147
|
+
"completed",
|
|
148
|
+
"failed",
|
|
149
|
+
"stopped"
|
|
150
|
+
].includes(status) ? status : null;
|
|
151
|
+
}
|
|
152
|
+
function payloadString(payload, keys) {
|
|
153
|
+
if (!payload || typeof payload !== "object")
|
|
154
|
+
return null;
|
|
155
|
+
const record = payload;
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
const value = record[key];
|
|
158
|
+
if (typeof value === "string" && value.trim())
|
|
159
|
+
return value.trim();
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
function payloadOptions(payload) {
|
|
164
|
+
if (!payload || typeof payload !== "object")
|
|
165
|
+
return;
|
|
166
|
+
const record = payload;
|
|
167
|
+
const options = Array.isArray(record.options) ? record.options : Array.isArray(record.choices) ? record.choices : null;
|
|
168
|
+
const values = options?.filter((value) => typeof value === "string" && value.trim().length > 0) ?? [];
|
|
169
|
+
return values.length > 0 ? values : undefined;
|
|
170
|
+
}
|
|
171
|
+
function inboxRequest(request, kind) {
|
|
172
|
+
const fallback = kind === "approval" ? "Approval requested" : "Input requested";
|
|
173
|
+
return {
|
|
174
|
+
requestId: request.requestId,
|
|
175
|
+
kind,
|
|
176
|
+
title: payloadString(request.payload, ["title", "message", "reason", "prompt", "summary"]) ?? fallback,
|
|
177
|
+
body: payloadString(request.payload, ["body", "description", "detail", "details"]),
|
|
178
|
+
...payloadOptions(request.payload) ? { options: payloadOptions(request.payload) } : {},
|
|
179
|
+
requestedAt: request.requestedAt ?? null,
|
|
180
|
+
source: "run"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function inboxFromProjection(projection) {
|
|
184
|
+
return [
|
|
185
|
+
...projection.pendingApprovals.map((request) => inboxRequest(request, "approval")),
|
|
186
|
+
...projection.pendingUserInputs.map((request) => inboxRequest(request, "input"))
|
|
187
|
+
].sort((a, b) => (Date.parse(a.requestedAt ?? "") || 0) - (Date.parse(b.requestedAt ?? "") || 0));
|
|
188
|
+
}
|
|
189
|
+
function isProjectPath(projectRoot, cwd) {
|
|
190
|
+
const root = resolve(projectRoot);
|
|
191
|
+
const candidate = resolve(cwd);
|
|
192
|
+
const pathFromRoot = relative(root, candidate);
|
|
193
|
+
return pathFromRoot === "" || !pathFromRoot.startsWith("../") && pathFromRoot !== ".." && !isAbsolute(pathFromRoot);
|
|
194
|
+
}
|
|
195
|
+
function sourceFromEntry(projectRoot, projection, entry) {
|
|
196
|
+
const candidates = [
|
|
197
|
+
stringOrNull(projection.collabCwd),
|
|
198
|
+
stringOrNull(projection.cwd),
|
|
199
|
+
stringOrNull(entry.cwd),
|
|
200
|
+
stringOrNull(projection.worktreePath)
|
|
201
|
+
].filter((cwd) => cwd !== null);
|
|
202
|
+
return candidates.some((cwd) => isProjectPath(projectRoot, cwd)) ? "local" : "remote";
|
|
203
|
+
}
|
|
204
|
+
function pendingRequests(value, fallbackKind) {
|
|
205
|
+
if (!Array.isArray(value))
|
|
206
|
+
return [];
|
|
207
|
+
return value.flatMap((item) => {
|
|
208
|
+
const record = objectRecord(item);
|
|
209
|
+
const requestId = stringOrNull(record?.requestId) ?? stringOrNull(record?.id);
|
|
210
|
+
if (!record || !requestId)
|
|
211
|
+
return [];
|
|
212
|
+
return [{
|
|
213
|
+
requestId,
|
|
214
|
+
requestKind: stringOrNull(record.requestKind) ?? stringOrNull(record.kind) ?? fallbackKind,
|
|
215
|
+
actionId: stringOrNull(record.actionId),
|
|
216
|
+
payload: "payload" in record ? record.payload : record,
|
|
217
|
+
requestedAt: stringOrNull(record.requestedAt) ?? stringOrNull(record.at) ?? ""
|
|
218
|
+
}];
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function emptyFoldedProjection(runId, projection) {
|
|
222
|
+
const projectionRecord = projection;
|
|
223
|
+
const nestedProjection = objectRecord(projectionRecord.projection);
|
|
224
|
+
const pendingApprovals = pendingRequests(nestedProjection?.pendingApprovals ?? projectionRecord.pendingApprovals, "approval");
|
|
225
|
+
const pendingUserInputs = pendingRequests(nestedProjection?.pendingUserInputs ?? nestedProjection?.pendingInputs ?? projectionRecord.pendingUserInputs ?? (Array.isArray(projectionRecord.pendingInputs) ? projectionRecord.pendingInputs : undefined), "user-input");
|
|
226
|
+
const nestedRecord = objectRecord(nestedProjection?.record);
|
|
227
|
+
const nestedFolded = nestedProjection;
|
|
228
|
+
return {
|
|
229
|
+
...EMPTY_PROJECTION,
|
|
230
|
+
...nestedFolded ?? {},
|
|
231
|
+
record: {
|
|
232
|
+
...nestedRecord ?? {},
|
|
233
|
+
runId,
|
|
234
|
+
...projection.taskId ? { taskId: projection.taskId } : {},
|
|
235
|
+
...projection.title ? { title: projection.title } : {},
|
|
236
|
+
...projection.startedAt ? { startedAt: projection.startedAt } : {},
|
|
237
|
+
...projection.updatedAt ? { updatedAt: projection.updatedAt } : {},
|
|
238
|
+
...projection.completedAt ? { completedAt: projection.completedAt } : {},
|
|
239
|
+
...projection.sessionPath ? { sessionPath: projection.sessionPath } : {},
|
|
240
|
+
...projection.worktreePath ? { worktreePath: projection.worktreePath } : {},
|
|
241
|
+
...projection.prUrl ? { prUrl: projection.prUrl } : {}
|
|
242
|
+
},
|
|
243
|
+
status: registryStatusAsRunStatus(projection.status) ?? registryStatusAsRunStatus(nestedProjection?.status),
|
|
244
|
+
pendingApprovals,
|
|
245
|
+
pendingUserInputs,
|
|
246
|
+
steeringCount: projection.steeringCount ?? numberOrNull(nestedProjection?.steeringCount) ?? 0,
|
|
247
|
+
stallCount: projection.stallCount ?? numberOrNull(nestedProjection?.stallCount) ?? 0,
|
|
248
|
+
lastEventAt: projection.updatedAt ?? stringOrNull(nestedProjection?.lastEventAt)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function runRecordFromRegistryEntry(projectRoot, entry) {
|
|
252
|
+
const projection = entry.projection && typeof entry.projection === "object" ? entry.projection : {};
|
|
253
|
+
const runId = stringOrNull(projection.runId) ?? entry.roomId;
|
|
254
|
+
const folded = emptyFoldedProjection(runId, projection);
|
|
255
|
+
const pushedStatus = registryStatusAsRunStatus(projection.status) ?? folded.status ?? registryStatusAsRunStatus(entry.status);
|
|
256
|
+
const status = entry.stale ? pushedStatus && isTerminalRunStatus2(pushedStatus) ? pushedStatus : "stale" : pushedStatus ?? "running";
|
|
257
|
+
const sessionPath = stringOrNull(projection.sessionPath) ?? stringOrNull(entry.sessionPath) ?? null;
|
|
258
|
+
const collabCwd = stringOrNull(projection.collabCwd) ?? stringOrNull(projection.cwd) ?? stringOrNull(entry.cwd) ?? stringOrNull(projection.worktreePath);
|
|
259
|
+
return {
|
|
260
|
+
runId,
|
|
261
|
+
taskId: stringOrNull(projection.taskId),
|
|
262
|
+
title: stringOrNull(projection.title) ?? entry.title,
|
|
263
|
+
status,
|
|
264
|
+
source: sourceFromEntry(projectRoot, projection, entry),
|
|
265
|
+
live: !entry.stale,
|
|
266
|
+
stale: entry.stale,
|
|
267
|
+
startedAt: stringOrNull(projection.startedAt) ?? entry.startedAt ?? null,
|
|
268
|
+
updatedAt: stringOrNull(projection.updatedAt) ?? entry.heartbeatAt ?? null,
|
|
269
|
+
completedAt: stringOrNull(projection.completedAt),
|
|
270
|
+
joinLink: stringOrNull(projection.joinLink) ?? entry.joinLink ?? null,
|
|
271
|
+
webLink: stringOrNull(projection.webLink) ?? entry.webLink ?? null,
|
|
272
|
+
relayUrl: stringOrNull(projection.relayUrl) ?? entry.relayUrl ?? null,
|
|
273
|
+
sessionPath,
|
|
274
|
+
prUrl: stringOrNull(projection.prUrl),
|
|
275
|
+
worktreePath: stringOrNull(projection.worktreePath) ?? collabCwd,
|
|
276
|
+
pendingApprovals: numberOrNull(projection.pendingApprovals) ?? folded.pendingApprovals.length,
|
|
277
|
+
pendingInputs: numberOrNull(projection.pendingInputs) ?? folded.pendingUserInputs.length,
|
|
278
|
+
steeringCount: projection.steeringCount ?? 0,
|
|
279
|
+
stallCount: projection.stallCount ?? 0,
|
|
280
|
+
errorSummary: stringOrNull(projection.errorSummary) ?? summarizeRunError(folded),
|
|
281
|
+
timeline: Array.isArray(projection.timeline) ? [...projection.timeline] : [...timelineEntriesFromCustomEntries([])],
|
|
282
|
+
inbox: inboxFromProjection(folded),
|
|
283
|
+
collabCwd: collabCwd ?? null,
|
|
284
|
+
projection: folded
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function runRecordsFromRegistrySnapshot(projectRoot, snapshot) {
|
|
288
|
+
return sortByRecency(snapshot.entries.map((entry) => runRecordFromRegistryEntry(projectRoot, entry)).filter((record) => record !== null));
|
|
289
|
+
}
|
|
290
|
+
function sortByRecency(records) {
|
|
291
|
+
return [...records].sort((a, b) => {
|
|
292
|
+
const at = Date.parse(b.updatedAt ?? b.startedAt ?? "") || 0;
|
|
293
|
+
const bt = Date.parse(a.updatedAt ?? a.startedAt ?? "") || 0;
|
|
294
|
+
return at - bt;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function discoveryDiagnosticRunRecord(projectRoot, error) {
|
|
298
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
299
|
+
const runId = DISCOVERY_DIAGNOSTIC_RUN_ID;
|
|
300
|
+
const projection = {
|
|
301
|
+
...EMPTY_PROJECTION,
|
|
302
|
+
record: { runId, title: "Registry discovery unavailable" },
|
|
303
|
+
status: "needs-attention",
|
|
304
|
+
stallCount: 1
|
|
305
|
+
};
|
|
306
|
+
return {
|
|
307
|
+
runId,
|
|
308
|
+
taskId: null,
|
|
309
|
+
title: "Registry discovery unavailable",
|
|
310
|
+
status: "needs-attention",
|
|
311
|
+
source: "remote",
|
|
312
|
+
live: false,
|
|
313
|
+
stale: true,
|
|
314
|
+
startedAt: null,
|
|
315
|
+
updatedAt: null,
|
|
316
|
+
completedAt: null,
|
|
317
|
+
joinLink: null,
|
|
318
|
+
webLink: null,
|
|
319
|
+
relayUrl: null,
|
|
320
|
+
sessionPath: null,
|
|
321
|
+
prUrl: null,
|
|
322
|
+
worktreePath: null,
|
|
323
|
+
pendingApprovals: 0,
|
|
324
|
+
pendingInputs: 0,
|
|
325
|
+
steeringCount: 0,
|
|
326
|
+
stallCount: 1,
|
|
327
|
+
errorSummary: `registry discovery unavailable: ${detail}`,
|
|
328
|
+
timeline: [],
|
|
329
|
+
inbox: [],
|
|
330
|
+
collabCwd: null,
|
|
331
|
+
projection
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
async function listRunProjections(projectRoot, filter = {}) {
|
|
335
|
+
try {
|
|
336
|
+
const snapshot = await Effect.runPromise(registrySnapshotStream(projectRoot, filter).pipe(Stream.runHead, Effect.timeout(Duration.seconds(15)), Effect.map(Option.getOrNull)));
|
|
337
|
+
return snapshot ? runRecordsFromRegistrySnapshot(projectRoot, snapshot) : [discoveryDiagnosticRunRecord(projectRoot, "registry discovery stream ended without a snapshot")];
|
|
338
|
+
} catch (error) {
|
|
339
|
+
return [discoveryDiagnosticRunRecord(projectRoot, error)];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function selectRunProjection(runs, runId) {
|
|
343
|
+
const exactRun = runs.find((run) => run.runId === runId);
|
|
344
|
+
if (exactRun)
|
|
345
|
+
return exactRun;
|
|
346
|
+
const exactTask = runs.find((run) => run.taskId === runId);
|
|
347
|
+
if (exactTask)
|
|
348
|
+
return exactTask;
|
|
349
|
+
const prefixMatches = runs.filter((run) => run.runId.startsWith(runId));
|
|
350
|
+
if (prefixMatches.length === 1)
|
|
351
|
+
return prefixMatches[0] ?? null;
|
|
352
|
+
if (prefixMatches.length > 1) {
|
|
353
|
+
const matches = prefixMatches.map((run) => run.runId).join(", ");
|
|
354
|
+
throw new Error(`Ambiguous run id prefix "${runId}" matched ${prefixMatches.length} runs: ${matches}`);
|
|
355
|
+
}
|
|
356
|
+
return runs.find((run) => run.runId === DISCOVERY_DIAGNOSTIC_RUN_ID) ?? null;
|
|
357
|
+
}
|
|
358
|
+
async function getRunProjection(projectRoot, runId, filter = {}) {
|
|
359
|
+
const runs = await listRunProjections(projectRoot, filter);
|
|
360
|
+
return selectRunProjection(runs, runId);
|
|
361
|
+
}
|
|
362
|
+
async function resolveRunJoinTarget(projectRoot, runId, filter = {}) {
|
|
363
|
+
const run = await getRunProjection(projectRoot, runId, filter);
|
|
364
|
+
if (!run || !run.joinLink)
|
|
365
|
+
return null;
|
|
366
|
+
return { runId: run.runId, taskId: run.taskId, joinLink: run.joinLink, cwd: run.collabCwd ?? run.sessionPath, stale: run.stale };
|
|
367
|
+
}
|
|
368
|
+
var EMPTY_PROJECTION, DISCOVERY_DIAGNOSTIC_RUN_ID = "__registry_discovery_error__", listRuns, getRun, resolveJoinTarget;
|
|
369
|
+
var init_projection = __esm(() => {
|
|
370
|
+
init_diagnostics();
|
|
371
|
+
EMPTY_PROJECTION = foldRunSessionEntries([], "");
|
|
372
|
+
listRuns = listRunProjections;
|
|
373
|
+
getRun = getRunProjection;
|
|
374
|
+
resolveJoinTarget = resolveRunJoinTarget;
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// packages/run-worker/src/runs/run-status.ts
|
|
378
|
+
import {
|
|
379
|
+
ACTIVE_RUN_STATUSES,
|
|
380
|
+
TERMINAL_RUN_STATUSES,
|
|
381
|
+
isActiveRunStatus,
|
|
382
|
+
isTerminalRunStatus,
|
|
383
|
+
normalizeRunStatusToken
|
|
384
|
+
} from "@rig/contracts";
|
|
385
|
+
var KNOWN_RUN_STATUS = Object.fromEntries([...ACTIVE_RUN_STATUSES, ...TERMINAL_RUN_STATUSES].map((status) => [status, true]));
|
|
386
|
+
function canonicalStatusToken(status) {
|
|
387
|
+
const normalized = normalizeRunStatusToken(status);
|
|
388
|
+
if (normalized === "waiting-input")
|
|
389
|
+
return "waiting-user-input";
|
|
390
|
+
return normalized;
|
|
391
|
+
}
|
|
392
|
+
function isNeedsAttention(run) {
|
|
393
|
+
return canonicalStatusToken(run.status) === "needs-attention" || run.pendingApprovals + run.pendingInputs > 0 || run.stallCount > 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// packages/run-worker/src/runs/stats.ts
|
|
397
|
+
function parseTimestamp(value) {
|
|
398
|
+
if (!value)
|
|
399
|
+
return null;
|
|
400
|
+
const parsed = Date.parse(value);
|
|
401
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
402
|
+
}
|
|
403
|
+
function median(values) {
|
|
404
|
+
if (values.length === 0)
|
|
405
|
+
return null;
|
|
406
|
+
const sorted = [...values].sort((left, right) => left - right);
|
|
407
|
+
const middle = Math.floor(sorted.length / 2);
|
|
408
|
+
return sorted.length % 2 === 1 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
|
|
409
|
+
}
|
|
410
|
+
function rate(part, total) {
|
|
411
|
+
return total === 0 ? null : part / total;
|
|
412
|
+
}
|
|
413
|
+
function completedDuration(run) {
|
|
414
|
+
if (run.status !== "completed")
|
|
415
|
+
return null;
|
|
416
|
+
const startedAt = parseTimestamp(run.startedAt);
|
|
417
|
+
const completedAt = parseTimestamp(run.completedAt);
|
|
418
|
+
if (startedAt === null || completedAt === null || completedAt < startedAt)
|
|
419
|
+
return null;
|
|
420
|
+
return completedAt - startedAt;
|
|
421
|
+
}
|
|
422
|
+
async function computeStats(projectRootOrRuns, options = {}) {
|
|
423
|
+
const sinceMs = options.since ? options.since.getTime() : null;
|
|
424
|
+
const allRuns = typeof projectRootOrRuns === "string" ? await (options.listRuns ?? (await Promise.resolve().then(() => (init_projection(), exports_projection))).listRuns)(projectRootOrRuns) : projectRootOrRuns;
|
|
425
|
+
const runs = allRuns.filter((run) => {
|
|
426
|
+
if (sinceMs === null)
|
|
427
|
+
return true;
|
|
428
|
+
const startedAt = parseTimestamp(run.startedAt);
|
|
429
|
+
return startedAt !== null && startedAt >= sinceMs;
|
|
430
|
+
});
|
|
431
|
+
const statusCounts = {};
|
|
432
|
+
const completionDurations = [];
|
|
433
|
+
let completedRuns = 0;
|
|
434
|
+
let failedRuns = 0;
|
|
435
|
+
let needsAttentionRuns = 0;
|
|
436
|
+
let steeringTotal = 0;
|
|
437
|
+
let stallTotal = 0;
|
|
438
|
+
let approvalsPending = 0;
|
|
439
|
+
for (const run of runs) {
|
|
440
|
+
const status = run.status || "unknown";
|
|
441
|
+
statusCounts[status] = (statusCounts[status] ?? 0) + 1;
|
|
442
|
+
if (status === "completed")
|
|
443
|
+
completedRuns += 1;
|
|
444
|
+
if (status === "failed")
|
|
445
|
+
failedRuns += 1;
|
|
446
|
+
if (isNeedsAttention(run))
|
|
447
|
+
needsAttentionRuns += 1;
|
|
448
|
+
const duration = completedDuration(run);
|
|
449
|
+
if (duration !== null)
|
|
450
|
+
completionDurations.push(duration);
|
|
451
|
+
steeringTotal += run.steeringCount;
|
|
452
|
+
stallTotal += run.stallCount;
|
|
453
|
+
approvalsPending += run.pendingApprovals;
|
|
454
|
+
}
|
|
455
|
+
const totalRuns = runs.length;
|
|
456
|
+
return {
|
|
457
|
+
since: options.since ? options.since.toISOString() : null,
|
|
458
|
+
totalRuns,
|
|
459
|
+
statusCounts,
|
|
460
|
+
completedRuns,
|
|
461
|
+
failedRuns,
|
|
462
|
+
needsAttentionRuns,
|
|
463
|
+
completionRate: rate(completedRuns, totalRuns),
|
|
464
|
+
failureRate: rate(failedRuns, totalRuns),
|
|
465
|
+
needsAttentionRate: rate(needsAttentionRuns, totalRuns),
|
|
466
|
+
medianCompletionMs: median(completionDurations),
|
|
467
|
+
steeringTotal,
|
|
468
|
+
steeringPerRun: totalRuns === 0 ? null : steeringTotal / totalRuns,
|
|
469
|
+
stallTotal,
|
|
470
|
+
approvalsRequested: approvalsPending,
|
|
471
|
+
approvalsApproved: 0,
|
|
472
|
+
approvalsRejected: 0,
|
|
473
|
+
approvalsPending
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
var computeRigStats = computeStats;
|
|
477
|
+
export {
|
|
478
|
+
rate,
|
|
479
|
+
parseTimestamp,
|
|
480
|
+
median,
|
|
481
|
+
isNeedsAttention,
|
|
482
|
+
computeStats,
|
|
483
|
+
computeRigStats,
|
|
484
|
+
completedDuration
|
|
485
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/run-worker",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.156",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rig package",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/src/index.d.ts",
|
|
14
14
|
"import": "./dist/src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./runs": {
|
|
17
|
+
"types": "./dist/src/runs/index.d.ts",
|
|
18
|
+
"import": "./dist/src/runs/index.js"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"engines": {
|
|
@@ -27,13 +31,14 @@
|
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"@oh-my-pi/pi-coding-agent": "16.0.4",
|
|
30
|
-
"@rig/
|
|
31
|
-
"@rig/
|
|
32
|
-
"@rig/
|
|
33
|
-
"@rig/
|
|
34
|
-
"@rig/kernel": "npm:@h-rig/kernel@0.0.6-alpha.
|
|
35
|
-
"@rig/
|
|
36
|
-
"@rig/
|
|
34
|
+
"@rig/bundle-default-lifecycle": "npm:@h-rig/bundle-default-lifecycle@0.0.6-alpha.156",
|
|
35
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.156",
|
|
36
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.156",
|
|
37
|
+
"@rig/github-provider-plugin": "npm:@h-rig/github-provider-plugin@0.0.6-alpha.156",
|
|
38
|
+
"@rig/kernel": "npm:@h-rig/kernel@0.0.6-alpha.156",
|
|
39
|
+
"@rig/notifications-plugin": "npm:@h-rig/notifications-plugin@0.0.6-alpha.156",
|
|
40
|
+
"@rig/relay-registry": "npm:@h-rig/relay-registry@0.0.6-alpha.156",
|
|
41
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.156",
|
|
37
42
|
"effect": "4.0.0-beta.90"
|
|
38
43
|
}
|
|
39
44
|
}
|