pi-better-background-tasks 0.2.14 → 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 +92 -56
package/package.json
CHANGED
package/src/shared-navigator.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { truncateToWidth as piTruncateToWidth, visibleWidth as piVisibleWidth } from "@earendil-works/pi-tui";
|
|
2
3
|
import type { Component } from "@earendil-works/pi-tui";
|
|
3
4
|
import { createRenderScheduler, type RenderScheduler } from "./shared-render-scheduler.ts";
|
|
4
5
|
|
|
@@ -280,10 +281,10 @@ function refreshMainListWidget(): void {
|
|
|
280
281
|
}) : undefined;
|
|
281
282
|
const changed = nextSignature !== s.lastMainListSignature;
|
|
282
283
|
s.lastMainListSignature = nextSignature;
|
|
283
|
-
s.lastMainListLines = rows.length ? buildMainListLines(rows, MAIN_LIST_FALLBACK_WIDTH, deps.truncate, themeFg(ctx), {
|
|
284
|
+
s.lastMainListLines = rows.length ? ["", ...buildMainListLines(rows, MAIN_LIST_FALLBACK_WIDTH, deps.truncate, themeFg(ctx), {
|
|
284
285
|
selectedId: s.mainListFocused ? s.mainListSelectedId : undefined,
|
|
285
286
|
focused: s.mainListFocused === true,
|
|
286
|
-
}) : undefined;
|
|
287
|
+
})] : undefined;
|
|
287
288
|
if (!rows.length) {
|
|
288
289
|
if (!s.mainListWidgetInstalled) return;
|
|
289
290
|
try { (ctx.ui as any).setWidget?.(MAIN_LIST_WIDGET_KEY, undefined); } catch { /* ignore */ }
|
|
@@ -323,10 +324,10 @@ function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, d
|
|
|
323
324
|
state().lastMainListLines = undefined;
|
|
324
325
|
return [];
|
|
325
326
|
}
|
|
326
|
-
const lines = buildMainListLines(rows, renderWidth(width), deps.truncate, themeFgFromTheme(theme), {
|
|
327
|
+
const lines = ["", ...buildMainListLines(rows, renderWidth(width), deps.truncate, themeFgFromTheme(theme), {
|
|
327
328
|
selectedId: state().mainListFocused ? state().mainListSelectedId : undefined,
|
|
328
329
|
focused: state().mainListFocused === true,
|
|
329
|
-
});
|
|
330
|
+
})];
|
|
330
331
|
state().lastMainListLines = lines;
|
|
331
332
|
return lines;
|
|
332
333
|
},
|
|
@@ -1269,7 +1270,8 @@ export function wrapLogText(text: string, width: number): string[] {
|
|
|
1269
1270
|
continue;
|
|
1270
1271
|
}
|
|
1271
1272
|
const sourceIndent = source.match(/^[ \t]*/)?.[0] ?? "";
|
|
1272
|
-
|
|
1273
|
+
// Leave room for a full-width grapheme even on deeply indented log lines.
|
|
1274
|
+
const indent = sourceIndent.replace(/\t/g, " ").slice(0, max - 2);
|
|
1273
1275
|
let remaining = source.slice(sourceIndent.length);
|
|
1274
1276
|
const contentWidth = Math.max(1, max - visibleWidth(indent));
|
|
1275
1277
|
if (!remaining) {
|
|
@@ -1302,33 +1304,25 @@ function lastDelimiterBreak(value: string): number {
|
|
|
1302
1304
|
return last;
|
|
1303
1305
|
}
|
|
1304
1306
|
|
|
1307
|
+
const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
1308
|
+
|
|
1305
1309
|
function splitVisiblePrefix(value: string, width: number): [string, string] {
|
|
1306
1310
|
const max = Math.max(0, Math.floor(width));
|
|
1307
1311
|
let visible = 0;
|
|
1308
|
-
let
|
|
1309
|
-
|
|
1310
|
-
if (
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
if (value[index] === "<") {
|
|
1318
|
-
const close = value.indexOf(">", index);
|
|
1319
|
-
if (close !== -1) {
|
|
1320
|
-
const tag = value.slice(index, close + 1);
|
|
1321
|
-
if (/^<\/?[a-zA-Z][\w-]*>$/.test(tag) || tag === "</>") {
|
|
1322
|
-
index = close + 1;
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1312
|
+
let end = 0;
|
|
1313
|
+
for (const { segment, index } of GRAPHEME_SEGMENTER.segment(value)) {
|
|
1314
|
+
if (index < end) continue;
|
|
1315
|
+
const formatting = value.slice(index).match(FORMATTING_PREFIX_RE);
|
|
1316
|
+
if (formatting) {
|
|
1317
|
+
end = index + formatting[0].length;
|
|
1318
|
+
continue;
|
|
1326
1319
|
}
|
|
1327
|
-
const
|
|
1328
|
-
|
|
1329
|
-
visible +=
|
|
1320
|
+
const cells = piVisibleWidth(segment);
|
|
1321
|
+
if (visible + cells > max) break;
|
|
1322
|
+
visible += cells;
|
|
1323
|
+
end = index + segment.length;
|
|
1330
1324
|
}
|
|
1331
|
-
return [value.slice(0,
|
|
1325
|
+
return [value.slice(0, end), value.slice(end)];
|
|
1332
1326
|
}
|
|
1333
1327
|
|
|
1334
1328
|
function cycleLogTailRows(current: number): number {
|
|
@@ -1387,44 +1381,86 @@ function safeTruncate(line: string, width: number, truncate: (s: string, width:
|
|
|
1387
1381
|
|
|
1388
1382
|
const ANSI_RE = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
|
1389
1383
|
|
|
1384
|
+
const FORMATTING_PREFIX_RE = new RegExp(`^(?:${ANSI_RE.source}|<\\/?[a-zA-Z][\\w-]*>|</>)`);
|
|
1385
|
+
|
|
1390
1386
|
function visibleWidth(value: string): number {
|
|
1391
|
-
|
|
1387
|
+
const cleaned = String(value ?? "")
|
|
1392
1388
|
.replace(ANSI_RE, "")
|
|
1393
1389
|
.replace(/<\/?[a-zA-Z][\w-]*>/g, "")
|
|
1394
|
-
.replace(/<\/>/g, "")
|
|
1395
|
-
|
|
1390
|
+
.replace(/<\/>/g, "");
|
|
1391
|
+
return piVisibleWidth(cleaned);
|
|
1396
1392
|
}
|
|
1397
1393
|
|
|
1398
1394
|
function truncateVisible(value: string, width: number): string {
|
|
1399
1395
|
const str = String(value ?? "");
|
|
1400
1396
|
const max = Math.max(0, Math.floor(width || 0));
|
|
1401
1397
|
if (visibleWidth(str) <= max) return str;
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1398
|
+
return piTruncateToWidth(str, max);
|
|
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 });
|
|
1424
1437
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
i += 1;
|
|
1438
|
+
} catch {
|
|
1439
|
+
lines = buildDetailLines(detail, width, truncate, fg, { logTailRows: 12 });
|
|
1428
1440
|
}
|
|
1429
|
-
|
|
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
|
+
};
|
|
1430
1466
|
}
|