pi-better-background-tasks 0.2.15 → 0.2.16
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/package.json +1 -1
- package/src/shared-navigator.ts +67 -0
package/package.json
CHANGED
package/src/shared-navigator.ts
CHANGED
|
@@ -1397,3 +1397,70 @@ function truncateVisible(value: string, width: number): string {
|
|
|
1397
1397
|
if (visibleWidth(str) <= max) return str;
|
|
1398
1398
|
return piTruncateToWidth(str, max);
|
|
1399
1399
|
}
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Render one provider detail with the overlay line builder and the main-list
|
|
1403
|
+
* row formatter. Callers must already be inside the process that registered
|
|
1404
|
+
* the provider. `listedIds` is the live list; `rowLine` uses the same
|
|
1405
|
+
* formatter on the detail payload when the live list has filtered the run.
|
|
1406
|
+
*/
|
|
1407
|
+
export function renderRegisteredWorkDetail(providerId: string, id: string, width = 100): {
|
|
1408
|
+
detail: BackgroundWorkDetail | null;
|
|
1409
|
+
lines: string[];
|
|
1410
|
+
rowLine: string | null;
|
|
1411
|
+
listLines: string[] | null;
|
|
1412
|
+
listedIds: string[];
|
|
1413
|
+
} {
|
|
1414
|
+
const s = state();
|
|
1415
|
+
const deps = s.deps;
|
|
1416
|
+
const ctx = s.uiCtx;
|
|
1417
|
+
const truncate = deps?.truncate ?? ((value: string, limit: number) => {
|
|
1418
|
+
const text = String(value ?? "");
|
|
1419
|
+
return text.length > limit ? text.slice(0, Math.max(0, limit)) : text;
|
|
1420
|
+
});
|
|
1421
|
+
const fg = ctx ? themeFg(ctx) : (_color: string, value: string) => value;
|
|
1422
|
+
const provider = s.providers.get(providerId);
|
|
1423
|
+
let listed: BackgroundWorkRow[] = [];
|
|
1424
|
+
try { listed = provider?.listRows(Date.now()) ?? []; } catch { listed = []; }
|
|
1425
|
+
const detail = detailFor(rowKey(providerId, id), Date.now(), { logTailLines: 40 });
|
|
1426
|
+
const listLines = s.lastMainListLines ?? null;
|
|
1427
|
+
const listedIds = listed.map((row) => row.id);
|
|
1428
|
+
if (!detail) return { detail: null, lines: [], rowLine: null, listLines, listedIds };
|
|
1429
|
+
const theme = (ctx?.ui as { theme?: unknown } | undefined)?.theme;
|
|
1430
|
+
let lines: string[];
|
|
1431
|
+
try {
|
|
1432
|
+
if (detail.transcript && deps?.createTranscriptComponent) {
|
|
1433
|
+
const transcriptLines = deps.createTranscriptComponent(detail, theme).render(width) ?? [];
|
|
1434
|
+
lines = buildTranscriptDetailLines(detail, transcriptLines, width, truncate, fg, { logTailRows: 12 });
|
|
1435
|
+
} else {
|
|
1436
|
+
lines = buildDetailLines(detail, width, truncate, fg, { logTailRows: 12 });
|
|
1437
|
+
}
|
|
1438
|
+
} catch {
|
|
1439
|
+
lines = buildDetailLines(detail, width, truncate, fg, { logTailRows: 12 });
|
|
1440
|
+
}
|
|
1441
|
+
const modelLine = detail.metadata.find((item) => item.label === "model")?.value ?? "";
|
|
1442
|
+
const effortMatch = modelLine.match(/ · effort (.+)$/);
|
|
1443
|
+
const elapsed = detail.metadata.find((item) => item.label === "elapsed")?.value ?? "-";
|
|
1444
|
+
const row: InternalRow = {
|
|
1445
|
+
providerId,
|
|
1446
|
+
id: detail.id,
|
|
1447
|
+
name: detail.title,
|
|
1448
|
+
model: effortMatch ? modelLine.slice(0, effortMatch.index) : modelLine,
|
|
1449
|
+
...(effortMatch ? { effort: effortMatch[1] } : {}),
|
|
1450
|
+
status: detail.status,
|
|
1451
|
+
statusTone: detail.statusTone,
|
|
1452
|
+
kind: "subagent",
|
|
1453
|
+
elapsed,
|
|
1454
|
+
primary: "",
|
|
1455
|
+
sortStartedAt: 0,
|
|
1456
|
+
navigatorId: rowKey(providerId, detail.id),
|
|
1457
|
+
providerLabel: provider?.label ?? providerId,
|
|
1458
|
+
};
|
|
1459
|
+
return {
|
|
1460
|
+
detail,
|
|
1461
|
+
lines,
|
|
1462
|
+
rowLine: formatMainListRow(row, true, fg, width),
|
|
1463
|
+
listLines,
|
|
1464
|
+
listedIds,
|
|
1465
|
+
};
|
|
1466
|
+
}
|