@dougbots/avenor-pi 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +43 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -469,22 +469,44 @@ var RunInspectorOverlay = class {
|
|
|
469
469
|
return lines.map((line) => truncateToWidth(line, innerWidth));
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
|
+
function matchingWatchRuns(runs, selector) {
|
|
473
|
+
const query = selector.trim().toLowerCase();
|
|
474
|
+
if (!query) return [];
|
|
475
|
+
const byId = runs.find((run) => run.runId.toLowerCase() === query);
|
|
476
|
+
if (byId) return [byId];
|
|
477
|
+
return runs.filter((run) => run.label?.toLowerCase() === query || run.agent?.toLowerCase() === query);
|
|
478
|
+
}
|
|
479
|
+
function watchRunChoice(run) {
|
|
480
|
+
return `${sanitizeText(run.label ?? run.runId)}${run.agent ? ` · ${sanitizeText(run.agent)}` : ""} · ${sanitizeText(run.runId).slice(0, 8)}`;
|
|
481
|
+
}
|
|
482
|
+
async function selectWatchRun(ctx, runs) {
|
|
483
|
+
const choices = runs.map(watchRunChoice);
|
|
484
|
+
const selected = await ctx.ui.select("Watch run:", choices);
|
|
485
|
+
if (!selected) return void 0;
|
|
486
|
+
return runs.find((_run, index) => choices[index] === selected);
|
|
487
|
+
}
|
|
472
488
|
async function openRunInspector(ctx, options) {
|
|
473
489
|
if (!ctx.hasUI) {
|
|
474
490
|
ctx.ui.notify("avenor-watch requires TUI mode", "warning");
|
|
475
491
|
return;
|
|
476
492
|
}
|
|
477
|
-
|
|
478
|
-
|
|
493
|
+
const selector = options.initialRunId?.trim();
|
|
494
|
+
let tracked;
|
|
495
|
+
let runId;
|
|
496
|
+
if (selector) {
|
|
497
|
+
const matches = matchingWatchRuns(options.trackedRuns, selector);
|
|
498
|
+
tracked = matches.length === 1 ? matches[0] : matches.length > 1 ? await selectWatchRun(ctx, matches) : void 0;
|
|
499
|
+
if (matches.length > 1 && !tracked) return;
|
|
500
|
+
runId = tracked?.runId ?? selector;
|
|
501
|
+
} else {
|
|
479
502
|
if (options.trackedRuns.length === 0) {
|
|
480
503
|
ctx.ui.notify("No tracked runs", "warning");
|
|
481
504
|
return;
|
|
482
505
|
}
|
|
483
|
-
|
|
484
|
-
if (!
|
|
485
|
-
runId =
|
|
506
|
+
tracked = await selectWatchRun(ctx, options.trackedRuns);
|
|
507
|
+
if (!tracked) return;
|
|
508
|
+
runId = tracked.runId;
|
|
486
509
|
}
|
|
487
|
-
const tracked = options.trackedRuns.find((run) => run.runId === runId);
|
|
488
510
|
await ctx.ui.custom((tui, theme, keybindings, done) => new RunInspectorOverlay(tui, theme, keybindings, options.deps, tracked ?? { runId }, () => done(), options.onTrackRun), {
|
|
489
511
|
overlay: true,
|
|
490
512
|
overlayOptions: {
|
|
@@ -497,6 +519,15 @@ async function openRunInspector(ctx, options) {
|
|
|
497
519
|
}
|
|
498
520
|
//#endregion
|
|
499
521
|
//#region src/types.ts
|
|
522
|
+
function findLiveStatusForTrackedRun(run, liveStatuses) {
|
|
523
|
+
const knownRunIds = new Set([run.runId, run.lastStatus?.run_id].filter((id) => !!id));
|
|
524
|
+
let runtimeMatch;
|
|
525
|
+
for (const status of liveStatuses) {
|
|
526
|
+
if (knownRunIds.has(status.run_id)) return status;
|
|
527
|
+
if (!run.supervisorId && run.runtimeId === status.runtime_id) runtimeMatch = status;
|
|
528
|
+
}
|
|
529
|
+
return runtimeMatch;
|
|
530
|
+
}
|
|
500
531
|
const TERMINAL_STATUSES = new Set([
|
|
501
532
|
"done",
|
|
502
533
|
"failed",
|
|
@@ -699,7 +730,7 @@ function createExtension(deps = defaultDeps) {
|
|
|
699
730
|
}
|
|
700
731
|
const entries = [];
|
|
701
732
|
for (const run of trackedRuns.values()) {
|
|
702
|
-
const live = liveMap.
|
|
733
|
+
const live = findLiveStatusForTrackedRun(run, liveMap.values());
|
|
703
734
|
if (live) {
|
|
704
735
|
liveMap.delete(live.run_id);
|
|
705
736
|
run.lastStatus = live;
|
|
@@ -1422,11 +1453,11 @@ function createExtension(deps = defaultDeps) {
|
|
|
1422
1453
|
}
|
|
1423
1454
|
});
|
|
1424
1455
|
pi.registerCommand("avenor-watch", {
|
|
1425
|
-
description: "Open a live run inspector
|
|
1456
|
+
description: "Open a live run inspector by run ID, label, or agent name",
|
|
1426
1457
|
getArgumentCompletions: (prefix) => {
|
|
1427
|
-
const items = Array.from(trackedRuns.values()).filter((run) => run.label.startsWith(prefix) || run.runId.startsWith(prefix)).map((run) => ({
|
|
1458
|
+
const items = Array.from(trackedRuns.values()).filter((run) => run.label.startsWith(prefix) || run.agent.startsWith(prefix) || run.runId.startsWith(prefix)).map((run) => ({
|
|
1428
1459
|
value: run.runId,
|
|
1429
|
-
label: `${run.label} (${run.runId.slice(0, 8)})`
|
|
1460
|
+
label: `${sanitizeText(run.label)} (${sanitizeText(run.agent)}, ${sanitizeText(run.runId).slice(0, 8)})`
|
|
1430
1461
|
}));
|
|
1431
1462
|
return items.length > 0 ? items : null;
|
|
1432
1463
|
},
|
|
@@ -1448,9 +1479,9 @@ function createExtension(deps = defaultDeps) {
|
|
|
1448
1479
|
pi.registerCommand("avenor-cancel", {
|
|
1449
1480
|
description: "Cancel a running avenor sub-agent",
|
|
1450
1481
|
getArgumentCompletions: (prefix) => {
|
|
1451
|
-
const items = Array.from(trackedRuns.values()).filter((run) => run.label.startsWith(prefix) || run.runId.startsWith(prefix)).map((run) => ({
|
|
1482
|
+
const items = Array.from(trackedRuns.values()).filter((run) => run.label.startsWith(prefix) || run.agent.startsWith(prefix) || run.runId.startsWith(prefix)).map((run) => ({
|
|
1452
1483
|
value: run.runId,
|
|
1453
|
-
label: `${run.label} (${run.runId.slice(0, 8)})`
|
|
1484
|
+
label: `${sanitizeText(run.label)} (${sanitizeText(run.agent)}, ${sanitizeText(run.runId).slice(0, 8)})`
|
|
1454
1485
|
}));
|
|
1455
1486
|
return items.length > 0 ? items : null;
|
|
1456
1487
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dougbots/avenor-pi",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dev": "tsdown --watch"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@dougbots/avenor-core": "^0.4.
|
|
38
|
+
"@dougbots/avenor-core": "^0.4.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@earendil-works/pi-coding-agent": "*",
|