privateer-agent 0.15.4 → 0.15.6
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 +11 -0
- package/bin/boot-bundle.d.mts +2 -0
- package/bin/boot-bundle.mjs +44 -0
- package/bin/fresh-supervisor.d.mts +5 -1
- package/bin/fresh-supervisor.mjs +47 -10
- package/bin/privateer-launch.mjs +27 -3
- package/bin/privateer-subagent.mjs +5 -2
- package/bin/privateer-verify.mjs +12 -0
- package/bin/session-recovery.d.mts +53 -0
- package/bin/session-recovery.mjs +240 -0
- package/bin/session-seal-preload.mjs +17 -0
- package/bin/session-seal.d.mts +25 -0
- package/bin/session-seal.mjs +242 -0
- package/dist-boot/boot.mjs +3 -0
- package/dist-boot/c-27JKSMWL.mjs +1460 -0
- package/dist-boot/c-2BMRFV24.mjs +269 -0
- package/dist-boot/c-2CTF6JA3.mjs +166 -0
- package/dist-boot/c-2G3BBHRJ.mjs +84 -0
- package/dist-boot/c-2IDLKXX6.mjs +250 -0
- package/dist-boot/c-2NJD5VYM.mjs +8 -0
- package/dist-boot/c-2S5EEQPW.mjs +1602 -0
- package/dist-boot/c-2WRDCUVI.mjs +25 -0
- package/dist-boot/c-2YN3M256.mjs +14 -0
- package/dist-boot/c-37GM3GMU.mjs +187 -0
- package/dist-boot/c-3STKRSVO.mjs +2480 -0
- package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
- package/dist-boot/c-3UVHLQDJ.mjs +225 -0
- package/dist-boot/c-42PUUZYC.mjs +697 -0
- package/dist-boot/c-4D5UMWVW.mjs +683 -0
- package/dist-boot/c-4ETZRMTA.mjs +46 -0
- package/dist-boot/c-4QT25BD5.mjs +1482 -0
- package/dist-boot/c-4WVR32AP.mjs +2579 -0
- package/dist-boot/c-5EMM567G.mjs +152 -0
- package/dist-boot/c-5FA4CV63.mjs +145 -0
- package/dist-boot/c-5GV3X3RB.mjs +14 -0
- package/dist-boot/c-5JCEPRIY.mjs +52 -0
- package/dist-boot/c-5NDKIIWT.mjs +16 -0
- package/dist-boot/c-5QL3AR26.mjs +4665 -0
- package/dist-boot/c-5XY6MFKN.mjs +5142 -0
- package/dist-boot/c-65UZIZC7.mjs +2897 -0
- package/dist-boot/c-6FUXKHOK.mjs +1969 -0
- package/dist-boot/c-6JHWQE4V.mjs +18242 -0
- package/dist-boot/c-6LOBR4I6.mjs +5280 -0
- package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
- package/dist-boot/c-6ZO2SADQ.mjs +178 -0
- package/dist-boot/c-6ZORVVZP.mjs +1449 -0
- package/dist-boot/c-76QH4UCP.mjs +2441 -0
- package/dist-boot/c-77GO5L5Y.mjs +20982 -0
- package/dist-boot/c-7M23XFTN.mjs +5052 -0
- package/dist-boot/c-7TC367E2.mjs +32 -0
- package/dist-boot/c-7UOG7POX.mjs +1524 -0
- package/dist-boot/c-7VHP3FLN.mjs +376 -0
- package/dist-boot/c-A73JHZP2.mjs +13207 -0
- package/dist-boot/c-ABXULAFL.mjs +71 -0
- package/dist-boot/c-ANDD2AQO.mjs +74 -0
- package/dist-boot/c-AOY77AZL.mjs +1430 -0
- package/dist-boot/c-AXEPZ22I.mjs +108 -0
- package/dist-boot/c-B2Y7VNHU.mjs +427 -0
- package/dist-boot/c-B7VJUH73.mjs +77 -0
- package/dist-boot/c-BFW6CDVL.mjs +24 -0
- package/dist-boot/c-BHNIF2AR.mjs +188 -0
- package/dist-boot/c-BKF2O6BL.mjs +23 -0
- package/dist-boot/c-BOZXFTZN.mjs +8 -0
- package/dist-boot/c-BRNYJWZL.mjs +28 -0
- package/dist-boot/c-C3N4Z2HO.mjs +93 -0
- package/dist-boot/c-C4IV7ZFG.mjs +717 -0
- package/dist-boot/c-C5NK6UYV.mjs +793 -0
- package/dist-boot/c-C67644MB.mjs +1659 -0
- package/dist-boot/c-C6S2YB53.mjs +620 -0
- package/dist-boot/c-CDBEJSBF.mjs +37 -0
- package/dist-boot/c-CG47HBKU.mjs +435 -0
- package/dist-boot/c-CKCTWCT5.mjs +51 -0
- package/dist-boot/c-CN77DCGF.mjs +60 -0
- package/dist-boot/c-CRBXNKFO.mjs +1795 -0
- package/dist-boot/c-CRIHASQ6.mjs +973 -0
- package/dist-boot/c-CU4NGAUO.mjs +3786 -0
- package/dist-boot/c-CWRFLGQU.mjs +1883 -0
- package/dist-boot/c-CYQB2USO.mjs +32 -0
- package/dist-boot/c-DEE67DJO.mjs +379 -0
- package/dist-boot/c-DIFDBYOP.mjs +1258 -0
- package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
- package/dist-boot/c-DR7XQI32.mjs +381 -0
- package/dist-boot/c-DTGPSB46.mjs +14666 -0
- package/dist-boot/c-DTHDNA4P.mjs +320 -0
- package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
- package/dist-boot/c-E66Z2TI7.mjs +203 -0
- package/dist-boot/c-EBU6RLRV.mjs +1527 -0
- package/dist-boot/c-EBZZNGSF.mjs +432 -0
- package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
- package/dist-boot/c-EQBKXWNX.mjs +15829 -0
- package/dist-boot/c-EUEPIW4S.mjs +574 -0
- package/dist-boot/c-EX4YVWAT.mjs +378 -0
- package/dist-boot/c-EYZGSAJU.mjs +98 -0
- package/dist-boot/c-F75VRKY4.mjs +172 -0
- package/dist-boot/c-FH4NXKHV.mjs +177 -0
- package/dist-boot/c-FHNUCTEM.mjs +140 -0
- package/dist-boot/c-FJ5T42DS.mjs +5349 -0
- package/dist-boot/c-FPCNRL7G.mjs +1728 -0
- package/dist-boot/c-G4DLN7Q4.mjs +8 -0
- package/dist-boot/c-G56GYQFZ.mjs +2507 -0
- package/dist-boot/c-GLIOERDQ.mjs +1200 -0
- package/dist-boot/c-GMJ5HUBM.mjs +14 -0
- package/dist-boot/c-H3HSGMAQ.mjs +461 -0
- package/dist-boot/c-HIKTO6P7.mjs +275 -0
- package/dist-boot/c-I2MCJ34O.mjs +464 -0
- package/dist-boot/c-I3C6LBW4.mjs +765 -0
- package/dist-boot/c-I54OKQHW.mjs +387 -0
- package/dist-boot/c-IFSP3R4D.mjs +80 -0
- package/dist-boot/c-IZK77VB7.mjs +171 -0
- package/dist-boot/c-J3Y25UGE.mjs +54 -0
- package/dist-boot/c-J5IESS7W.mjs +27750 -0
- package/dist-boot/c-JJWZBY7L.mjs +254 -0
- package/dist-boot/c-JKTFXTGF.mjs +463 -0
- package/dist-boot/c-JN57AXQ4.mjs +77 -0
- package/dist-boot/c-KFIO6LUW.mjs +1096 -0
- package/dist-boot/c-KIEMEFWW.mjs +478 -0
- package/dist-boot/c-KIVXWBYD.mjs +28 -0
- package/dist-boot/c-KP6CRIP4.mjs +580 -0
- package/dist-boot/c-L26VOJX4.mjs +11558 -0
- package/dist-boot/c-L5GHWG5G.mjs +5988 -0
- package/dist-boot/c-M7NSQAKK.mjs +353 -0
- package/dist-boot/c-MCEWOPBW.mjs +56 -0
- package/dist-boot/c-MGPIEG7I.mjs +20 -0
- package/dist-boot/c-NREXJV3M.mjs +393 -0
- package/dist-boot/c-O5PP6CTX.mjs +162 -0
- package/dist-boot/c-OBQDHSXM.mjs +1774 -0
- package/dist-boot/c-OLQHHDD4.mjs +21 -0
- package/dist-boot/c-OXW4JQQH.mjs +319 -0
- package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
- package/dist-boot/c-P4PQZVV5.mjs +948 -0
- package/dist-boot/c-P63T3XL2.mjs +26373 -0
- package/dist-boot/c-P6N5DQGZ.mjs +194 -0
- package/dist-boot/c-P7MLKQFC.mjs +58 -0
- package/dist-boot/c-PB3PZJL5.mjs +1276 -0
- package/dist-boot/c-PTN4S6G2.mjs +1259 -0
- package/dist-boot/c-PYCE5J7U.mjs +1083 -0
- package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
- package/dist-boot/c-QUXMETGG.mjs +68 -0
- package/dist-boot/c-RDMJZCOX.mjs +356 -0
- package/dist-boot/c-ROGJK76M.mjs +17 -0
- package/dist-boot/c-RQJJ26T4.mjs +708 -0
- package/dist-boot/c-RSKCUPJF.mjs +7559 -0
- package/dist-boot/c-RVJU4O6P.mjs +37 -0
- package/dist-boot/c-S2RVHR3M.mjs +165 -0
- package/dist-boot/c-SKMK3PEE.mjs +91120 -0
- package/dist-boot/c-TI7SM4EG.mjs +20 -0
- package/dist-boot/c-TILJ6GXD.mjs +1235 -0
- package/dist-boot/c-TT6BCUJD.mjs +114 -0
- package/dist-boot/c-U4ITOXAN.mjs +2107 -0
- package/dist-boot/c-UGERXVO2.mjs +7120 -0
- package/dist-boot/c-UPBH5AXY.mjs +1363 -0
- package/dist-boot/c-US2PUNZL.mjs +597 -0
- package/dist-boot/c-UU4WZPPE.mjs +20 -0
- package/dist-boot/c-UWVIYPQS.mjs +39 -0
- package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
- package/dist-boot/c-V5MRVK47.mjs +351 -0
- package/dist-boot/c-V6CL266R.mjs +1755 -0
- package/dist-boot/c-VJTMFKYE.mjs +14975 -0
- package/dist-boot/c-VJTRUKIB.mjs +773 -0
- package/dist-boot/c-W4IFSHPW.mjs +43 -0
- package/dist-boot/c-WETGB2CF.mjs +113 -0
- package/dist-boot/c-WO3QSZUU.mjs +1337 -0
- package/dist-boot/c-WQLH73TY.mjs +242 -0
- package/dist-boot/c-XL735JW5.mjs +500 -0
- package/dist-boot/c-Y7HADL5B.mjs +1107 -0
- package/dist-boot/c-YGQHSVSK.mjs +41 -0
- package/dist-boot/c-YMP2AMEB.mjs +10350 -0
- package/dist-boot/c-YRDO2WEF.mjs +12012 -0
- package/dist-boot/c-YUSTRATJ.mjs +8 -0
- package/dist-boot/c-Z2262R22.mjs +2697 -0
- package/dist-boot/c-Z4ALQMJC.mjs +709 -0
- package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
- package/dist-boot/c-ZDZUKXF7.mjs +874 -0
- package/dist-boot/c-ZJYLGIC3.mjs +32 -0
- package/dist-boot/c-ZNA5CDMI.mjs +77 -0
- package/dist-boot/c-ZSO6DI3M.mjs +204 -0
- package/dist-boot/c-ZWUVHKMK.mjs +100 -0
- package/dist-boot/c-ZY4MESEW.mjs +832 -0
- package/dist-boot/c-ZZ5REI4L.mjs +329 -0
- package/dist-boot/cli.mjs +51 -0
- package/dist-boot/ext-anthropic-attribution.mjs +207 -0
- package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
- package/dist-boot/ext-pi-subagents.mjs +37 -0
- package/dist-boot/ext-privateer-account.mjs +4426 -0
- package/dist-boot/ext-privateer-brand.mjs +5274 -0
- package/dist-boot/ext-privateer-codemode.mjs +37 -0
- package/dist-boot/ext-privateer-computer.mjs +626 -0
- package/dist-boot/ext-privateer-connect.mjs +1862 -0
- package/dist-boot/ext-privateer-context.mjs +323 -0
- package/dist-boot/ext-privateer-desktop.mjs +92 -0
- package/dist-boot/ext-privateer-final-audit.mjs +48 -0
- package/dist-boot/ext-privateer-fresh.mjs +81 -0
- package/dist-boot/ext-privateer-gate.mjs +5959 -0
- package/dist-boot/ext-privateer-hints.mjs +236 -0
- package/dist-boot/ext-privateer-media.mjs +2626 -0
- package/dist-boot/ext-privateer-models.mjs +3397 -0
- package/dist-boot/ext-privateer-posture.mjs +3006 -0
- package/dist-boot/ext-privateer-privacy.mjs +4578 -0
- package/dist-boot/ext-privateer-recovery.mjs +287 -0
- package/dist-boot/ext-privateer-speak.mjs +4754 -0
- package/dist-boot/ext-privateer-terminals.mjs +725 -0
- package/dist-boot/ext-privateer-tools.mjs +528 -0
- package/dist-boot/ext-privateer-truncation.mjs +74 -0
- package/dist-boot/ext-privateer-update.mjs +210 -0
- package/dist-boot/ext-privateer-vision.mjs +148 -0
- package/dist-boot/ext-privateer-web.mjs +543 -0
- package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
- package/dist-boot/manifest.json +9 -0
- package/extensions/privateer-brand.ts +3 -1
- package/extensions/privateer-context.ts +4 -2
- package/extensions/privateer-final-audit.ts +17 -0
- package/extensions/privateer-gate.ts +55 -9
- package/extensions/privateer-recovery.ts +175 -0
- package/extensions/privateer-web.ts +4 -4
- package/package.json +3 -1
- package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
- package/patches/pi-background-tasks+2.6.10.patch +91 -7
- package/src/cli/chat.ts +7 -1
- package/src/config/moatManifest.json +2 -0
- package/src/config/whatsNew.json +4 -4
- package/src/context.ts +33 -5
- package/src/engine/finalAudit.ts +38 -0
- package/src/engine/stallWatchdog.ts +8 -1
- package/src/providers/account.ts +34 -3
- package/src/remote/attentionPush.ts +40 -0
- package/src/remote/liveTaskSession.ts +7 -1
- package/src/remote/relayClient.ts +38 -4
- package/src/remote/remoteBridge.ts +17 -0
- package/src/remote/transcriptSnapshot.ts +104 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
boundedRead,
|
|
4
|
+
compactWhitespace,
|
|
5
|
+
formatCompactNumber,
|
|
6
|
+
formatDuration,
|
|
7
|
+
taskDisplayName,
|
|
8
|
+
truncateChars
|
|
9
|
+
} from "./c-I3C6LBW4.mjs";
|
|
10
|
+
import "./c-B2Y7VNHU.mjs";
|
|
11
|
+
import "./c-SKMK3PEE.mjs";
|
|
12
|
+
import "./c-I54OKQHW.mjs";
|
|
13
|
+
import "./c-UPBH5AXY.mjs";
|
|
14
|
+
import {
|
|
15
|
+
formatSize
|
|
16
|
+
} from "./c-7UOG7POX.mjs";
|
|
17
|
+
import "./c-E4Z3Y5B5.mjs";
|
|
18
|
+
import "./c-6ZO2SADQ.mjs";
|
|
19
|
+
import "./c-JKTFXTGF.mjs";
|
|
20
|
+
import "./c-CRBXNKFO.mjs";
|
|
21
|
+
import "./c-KP6CRIP4.mjs";
|
|
22
|
+
import "./c-RSKCUPJF.mjs";
|
|
23
|
+
import "./c-PTN4S6G2.mjs";
|
|
24
|
+
import "./c-P6N5DQGZ.mjs";
|
|
25
|
+
import "./c-6LOBR4I6.mjs";
|
|
26
|
+
import "./c-3STKRSVO.mjs";
|
|
27
|
+
import "./c-YRDO2WEF.mjs";
|
|
28
|
+
import "./c-BHNIF2AR.mjs";
|
|
29
|
+
import "./c-ABXULAFL.mjs";
|
|
30
|
+
import "./c-2G3BBHRJ.mjs";
|
|
31
|
+
import "./c-O5PP6CTX.mjs";
|
|
32
|
+
import "./c-CDBEJSBF.mjs";
|
|
33
|
+
import "./c-DEE67DJO.mjs";
|
|
34
|
+
import "./c-WO3QSZUU.mjs";
|
|
35
|
+
import "./c-S2RVHR3M.mjs";
|
|
36
|
+
import {
|
|
37
|
+
matchesKey,
|
|
38
|
+
truncateToWidth,
|
|
39
|
+
visibleWidth
|
|
40
|
+
} from "./c-EQBKXWNX.mjs";
|
|
41
|
+
import "./c-RQJJ26T4.mjs";
|
|
42
|
+
import "./c-L5GHWG5G.mjs";
|
|
43
|
+
import {
|
|
44
|
+
__name
|
|
45
|
+
} from "./c-CN77DCGF.mjs";
|
|
46
|
+
|
|
47
|
+
// node_modules/pi-background-tasks/src/ui/background-tasks-manager.ts?ext=pi-background-tasks
|
|
48
|
+
import { existsSync } from "node:fs";
|
|
49
|
+
var STATUS_INTERVAL_MS = 1e3;
|
|
50
|
+
var DETAIL_TAIL_BYTES = 128 * 1024;
|
|
51
|
+
var LIST_VISIBLE_ROWS = 14;
|
|
52
|
+
var DETAIL_VISIBLE_OUTPUT_LINES = 12;
|
|
53
|
+
var LIGHT_BLUE_BG = "\x1B[48;2;183;223;255m";
|
|
54
|
+
var LIGHT_BLUE_FG = "\x1B[38;2;11;70;110m";
|
|
55
|
+
var LIGHT_BLUE_BORDER = "\x1B[38;2;83;160;215m";
|
|
56
|
+
var ANSI_RESET = "\x1B[0m";
|
|
57
|
+
function formatTime(timestamp) {
|
|
58
|
+
return new Date(timestamp).toLocaleTimeString();
|
|
59
|
+
}
|
|
60
|
+
__name(formatTime, "formatTime");
|
|
61
|
+
function formatCount(value) {
|
|
62
|
+
return value.toString();
|
|
63
|
+
}
|
|
64
|
+
__name(formatCount, "formatCount");
|
|
65
|
+
function pluralSuffix(count) {
|
|
66
|
+
return count === 1 ? "" : "s";
|
|
67
|
+
}
|
|
68
|
+
__name(pluralSuffix, "pluralSuffix");
|
|
69
|
+
function formatExitCodeText(exitCode) {
|
|
70
|
+
return typeof exitCode === "number" ? ` exit=${formatCount(exitCode)}` : "";
|
|
71
|
+
}
|
|
72
|
+
__name(formatExitCodeText, "formatExitCodeText");
|
|
73
|
+
function formatPidText(pid) {
|
|
74
|
+
return typeof pid === "number" ? ` \xB7 pid ${formatCount(pid)}` : "";
|
|
75
|
+
}
|
|
76
|
+
__name(formatPidText, "formatPidText");
|
|
77
|
+
function toOutputLines(content) {
|
|
78
|
+
return content.replace(/\r/g, "").split("\n").filter((line, index, array) => line.length > 0 || index < array.length - 1);
|
|
79
|
+
}
|
|
80
|
+
__name(toOutputLines, "toOutputLines");
|
|
81
|
+
function padAnsi(value, width) {
|
|
82
|
+
return value + " ".repeat(Math.max(0, width - visibleWidth(value)));
|
|
83
|
+
}
|
|
84
|
+
__name(padAnsi, "padAnsi");
|
|
85
|
+
function lightBlue(value) {
|
|
86
|
+
return `${LIGHT_BLUE_BG}${LIGHT_BLUE_FG}${value}${ANSI_RESET}`;
|
|
87
|
+
}
|
|
88
|
+
__name(lightBlue, "lightBlue");
|
|
89
|
+
function blueBorder(value) {
|
|
90
|
+
return `${LIGHT_BLUE_BORDER}${value}${ANSI_RESET}`;
|
|
91
|
+
}
|
|
92
|
+
__name(blueBorder, "blueBorder");
|
|
93
|
+
function statusLabel(status) {
|
|
94
|
+
if (status === "completed") return "done";
|
|
95
|
+
if (status === "failed") return "error";
|
|
96
|
+
if (status === "killed") return "stopped";
|
|
97
|
+
return "running";
|
|
98
|
+
}
|
|
99
|
+
__name(statusLabel, "statusLabel");
|
|
100
|
+
function statusColor(theme, status, text = statusLabel(status)) {
|
|
101
|
+
if (status === "completed") return theme.fg("success", text);
|
|
102
|
+
if (status === "failed") return theme.fg("error", text);
|
|
103
|
+
if (status === "killed") return theme.fg("warning", text);
|
|
104
|
+
return theme.fg("accent", text);
|
|
105
|
+
}
|
|
106
|
+
__name(statusColor, "statusColor");
|
|
107
|
+
function taskAge(task, now = Date.now()) {
|
|
108
|
+
return formatDuration((task.endTime ?? now) - task.startTime);
|
|
109
|
+
}
|
|
110
|
+
__name(taskAge, "taskAge");
|
|
111
|
+
function formatContextUsage(task) {
|
|
112
|
+
const usage = task.contextUsage;
|
|
113
|
+
if (!usage?.contextWindow) return "\u2014";
|
|
114
|
+
const window = formatCompactNumber(usage.contextWindow);
|
|
115
|
+
if (usage.percent === null || usage.tokens === null) return `?/${window}`;
|
|
116
|
+
return `${usage.percent.toFixed(1)}%/${window}`;
|
|
117
|
+
}
|
|
118
|
+
__name(formatContextUsage, "formatContextUsage");
|
|
119
|
+
function formatContextDetail(task) {
|
|
120
|
+
const usage = task.contextUsage;
|
|
121
|
+
if (!usage?.contextWindow) return "not reported by this background task";
|
|
122
|
+
const window = formatCompactNumber(usage.contextWindow);
|
|
123
|
+
if (usage.percent === null || usage.tokens === null) return `unknown tokens / ${window} window`;
|
|
124
|
+
return `${usage.percent.toFixed(1)}% of ${window} window (${formatCompactNumber(usage.tokens)} tokens)`;
|
|
125
|
+
}
|
|
126
|
+
__name(formatContextDetail, "formatContextDetail");
|
|
127
|
+
function formatTokenUsage(task) {
|
|
128
|
+
const usage = task.tokenUsage;
|
|
129
|
+
if (!usage || usage.totalTokens <= 0) return "";
|
|
130
|
+
return `tok ${formatCompactNumber(usage.totalTokens)}`;
|
|
131
|
+
}
|
|
132
|
+
__name(formatTokenUsage, "formatTokenUsage");
|
|
133
|
+
function formatTokenDetail(task) {
|
|
134
|
+
const usage = task.tokenUsage;
|
|
135
|
+
if (!usage || usage.totalTokens <= 0) return "not reported by this background task";
|
|
136
|
+
const parts = [
|
|
137
|
+
`input ${formatCompactNumber(usage.input)}`,
|
|
138
|
+
`output ${formatCompactNumber(usage.output)}`,
|
|
139
|
+
`cache read ${formatCompactNumber(usage.cacheRead)}`,
|
|
140
|
+
`cache write ${formatCompactNumber(usage.cacheWrite)}`,
|
|
141
|
+
`total ${formatCompactNumber(usage.totalTokens)}`
|
|
142
|
+
];
|
|
143
|
+
return parts.join(" \xB7 ");
|
|
144
|
+
}
|
|
145
|
+
__name(formatTokenDetail, "formatTokenDetail");
|
|
146
|
+
function formatToolUsage(task) {
|
|
147
|
+
const usage = task.toolUsage;
|
|
148
|
+
if (!usage || usage.total <= 0 && usage.failed <= 0) return "";
|
|
149
|
+
const total = formatCount(usage.total);
|
|
150
|
+
const failed = formatCount(usage.failed);
|
|
151
|
+
return usage.failed > 0 ? `tools ${total}/${failed} failed` : `tools ${total}`;
|
|
152
|
+
}
|
|
153
|
+
__name(formatToolUsage, "formatToolUsage");
|
|
154
|
+
function formatToolDetail(task) {
|
|
155
|
+
const usage = task.toolUsage;
|
|
156
|
+
if (!usage || usage.total <= 0 && usage.failed <= 0)
|
|
157
|
+
return "not reported by this background task";
|
|
158
|
+
const byName = Object.entries(usage.byName).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 6).map(([name, count]) => `${name} ${formatCount(count)}`);
|
|
159
|
+
const parts = [`${formatCount(usage.total)} total`];
|
|
160
|
+
if (usage.failed > 0) parts.push(`${formatCount(usage.failed)} failed`);
|
|
161
|
+
parts.push(...byName);
|
|
162
|
+
return parts.join(" \xB7 ");
|
|
163
|
+
}
|
|
164
|
+
__name(formatToolDetail, "formatToolDetail");
|
|
165
|
+
function shortModelName(model) {
|
|
166
|
+
const slash = model.lastIndexOf("/");
|
|
167
|
+
return slash >= 0 ? model.slice(slash + 1) : model;
|
|
168
|
+
}
|
|
169
|
+
__name(shortModelName, "shortModelName");
|
|
170
|
+
function formatModel(task) {
|
|
171
|
+
if (!task.model) return "";
|
|
172
|
+
return `model ${shortModelName(task.model)}`;
|
|
173
|
+
}
|
|
174
|
+
__name(formatModel, "formatModel");
|
|
175
|
+
function formatModelDetail(task) {
|
|
176
|
+
if (!task.model) return "not reported by this background task";
|
|
177
|
+
return task.model;
|
|
178
|
+
}
|
|
179
|
+
__name(formatModelDetail, "formatModelDetail");
|
|
180
|
+
function contextColor(theme, task, text) {
|
|
181
|
+
const percent = task.contextUsage?.percent ?? 0;
|
|
182
|
+
if (percent > 90) return theme.fg("error", text);
|
|
183
|
+
if (percent > 70) return theme.fg("warning", text);
|
|
184
|
+
return theme.fg("dim", text);
|
|
185
|
+
}
|
|
186
|
+
__name(contextColor, "contextColor");
|
|
187
|
+
function sortTasksForUi(tasks) {
|
|
188
|
+
const rank = /* @__PURE__ */ __name((task) => task.status === "running" ? 0 : task.status === "failed" ? 1 : task.status === "killed" ? 2 : 3, "rank");
|
|
189
|
+
return [...tasks].sort((a, b) => {
|
|
190
|
+
const rankDiff = rank(a) - rank(b);
|
|
191
|
+
if (rankDiff !== 0) return rankDiff;
|
|
192
|
+
return (b.endTime ?? b.startTime) - (a.endTime ?? a.startTime);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
__name(sortTasksForUi, "sortTasksForUi");
|
|
196
|
+
var BackgroundTasksManager = class {
|
|
197
|
+
constructor(tui, theme, done, options) {
|
|
198
|
+
this.tui = tui;
|
|
199
|
+
this.theme = theme;
|
|
200
|
+
this.done = done;
|
|
201
|
+
this.options = options;
|
|
202
|
+
if (options.initialTaskId) {
|
|
203
|
+
this.detailTaskId = options.initialTaskId;
|
|
204
|
+
this.mode = "detail";
|
|
205
|
+
this.options.markSeen(options.initialTaskId);
|
|
206
|
+
void this.refreshTail();
|
|
207
|
+
} else {
|
|
208
|
+
const allTasks = options.getTasks();
|
|
209
|
+
const hasRunning = allTasks.some((task) => task.status === "running");
|
|
210
|
+
const hasFinished = allTasks.some((task) => task.status !== "running");
|
|
211
|
+
if (!hasRunning && hasFinished) this.showHistory = true;
|
|
212
|
+
}
|
|
213
|
+
this.refreshTimer = setInterval(() => {
|
|
214
|
+
if (this.mode === "detail") void this.refreshTail();
|
|
215
|
+
this.tui.requestRender();
|
|
216
|
+
}, STATUS_INTERVAL_MS);
|
|
217
|
+
}
|
|
218
|
+
tui;
|
|
219
|
+
theme;
|
|
220
|
+
done;
|
|
221
|
+
options;
|
|
222
|
+
static {
|
|
223
|
+
__name(this, "BackgroundTasksManager");
|
|
224
|
+
}
|
|
225
|
+
mode = "list";
|
|
226
|
+
selectedIndex = 0;
|
|
227
|
+
listScroll = 0;
|
|
228
|
+
detailTaskId;
|
|
229
|
+
showHistory = false;
|
|
230
|
+
detailLines = [];
|
|
231
|
+
detailFollow = true;
|
|
232
|
+
detailScrollTop = 0;
|
|
233
|
+
tailBytesRead = 0;
|
|
234
|
+
tailTotalBytes = 0;
|
|
235
|
+
tailTruncated = false;
|
|
236
|
+
tailError;
|
|
237
|
+
actionMessage;
|
|
238
|
+
confirmStopAllArmed = false;
|
|
239
|
+
lastBytesByTask = /* @__PURE__ */ new Map();
|
|
240
|
+
recentActivityByTask = /* @__PURE__ */ new Map();
|
|
241
|
+
refreshTimer;
|
|
242
|
+
dispose() {
|
|
243
|
+
clearInterval(this.refreshTimer);
|
|
244
|
+
}
|
|
245
|
+
invalidate() {
|
|
246
|
+
this.tui.requestRender();
|
|
247
|
+
}
|
|
248
|
+
handleInput(data) {
|
|
249
|
+
const stopAllKey = data === "a" || data === "A" || data === "K";
|
|
250
|
+
if (!stopAllKey) this.confirmStopAllArmed = false;
|
|
251
|
+
this.actionMessage = void 0;
|
|
252
|
+
if (matchesKey(data, "escape") || data === "q" || data === "Q" || data === "x" || data === "X") {
|
|
253
|
+
this.close();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (this.mode === "detail") {
|
|
257
|
+
this.handleDetailInput(data);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.handleListInput(data);
|
|
261
|
+
}
|
|
262
|
+
render(width) {
|
|
263
|
+
const boxWidth = Math.max(2, Math.min(width, 118));
|
|
264
|
+
return this.mode === "detail" ? this.renderDetail(boxWidth) : this.renderList(boxWidth);
|
|
265
|
+
}
|
|
266
|
+
close() {
|
|
267
|
+
this.done("closed");
|
|
268
|
+
}
|
|
269
|
+
handleListInput(data) {
|
|
270
|
+
const tasks = this.currentTasks();
|
|
271
|
+
if (tasks.length === 0) {
|
|
272
|
+
if (matchesKey(data, "return")) this.close();
|
|
273
|
+
if (data === "h" || data === "H") {
|
|
274
|
+
this.showHistory = !this.showHistory;
|
|
275
|
+
this.tui.requestRender();
|
|
276
|
+
}
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (matchesKey(data, "up")) {
|
|
280
|
+
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
|
281
|
+
this.ensureSelectionVisible();
|
|
282
|
+
this.tui.requestRender();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (matchesKey(data, "down")) {
|
|
286
|
+
this.selectedIndex = Math.min(tasks.length - 1, this.selectedIndex + 1);
|
|
287
|
+
this.ensureSelectionVisible();
|
|
288
|
+
this.tui.requestRender();
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (matchesKey(data, "pageUp")) {
|
|
292
|
+
this.selectedIndex = Math.max(0, this.selectedIndex - LIST_VISIBLE_ROWS);
|
|
293
|
+
this.ensureSelectionVisible();
|
|
294
|
+
this.tui.requestRender();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (matchesKey(data, "pageDown")) {
|
|
298
|
+
this.selectedIndex = Math.min(tasks.length - 1, this.selectedIndex + LIST_VISIBLE_ROWS);
|
|
299
|
+
this.ensureSelectionVisible();
|
|
300
|
+
this.tui.requestRender();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (matchesKey(data, "return") || matchesKey(data, "right")) {
|
|
304
|
+
const task = tasks[this.selectedIndex];
|
|
305
|
+
if (!task) return;
|
|
306
|
+
this.openDetail(task.id);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (data === "k") {
|
|
310
|
+
const task = tasks[this.selectedIndex];
|
|
311
|
+
if (task) void this.stopTaskFromUi(task);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (data === "K" || data === "a" || data === "A") {
|
|
315
|
+
void this.stopAllFromUi();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (data === "R") {
|
|
319
|
+
const task = tasks[this.selectedIndex];
|
|
320
|
+
if (task) void this.rerunTaskFromUi(task);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (data === "c" || data === "C") {
|
|
324
|
+
const task = tasks[this.selectedIndex];
|
|
325
|
+
if (task) this.showOutputPathFromUi(task);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (data === "h" || data === "H") {
|
|
329
|
+
this.showHistory = !this.showHistory;
|
|
330
|
+
this.selectedIndex = 0;
|
|
331
|
+
this.listScroll = 0;
|
|
332
|
+
this.tui.requestRender();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
handleDetailInput(data) {
|
|
336
|
+
const task = this.detailTask();
|
|
337
|
+
if (matchesKey(data, "left")) {
|
|
338
|
+
this.mode = "list";
|
|
339
|
+
this.detailTaskId = void 0;
|
|
340
|
+
this.tui.requestRender();
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (matchesKey(data, "up")) {
|
|
344
|
+
this.scrollDetail(-1);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (matchesKey(data, "down")) {
|
|
348
|
+
this.scrollDetail(1);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (matchesKey(data, "pageUp")) {
|
|
352
|
+
this.scrollDetail(-DETAIL_VISIBLE_OUTPUT_LINES);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (matchesKey(data, "pageDown")) {
|
|
356
|
+
this.scrollDetail(DETAIL_VISIBLE_OUTPUT_LINES);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (data === "r") {
|
|
360
|
+
this.detailFollow = true;
|
|
361
|
+
this.detailScrollTop = 0;
|
|
362
|
+
void this.refreshTail();
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (data === "R" && task) {
|
|
366
|
+
void this.rerunTaskFromUi(task);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (data === "k" && task) {
|
|
370
|
+
void this.stopTaskFromUi(task);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if ((data === "c" || data === "C") && task) {
|
|
374
|
+
this.showOutputPathFromUi(task);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
currentTasks() {
|
|
378
|
+
const allTasks = this.options.getTasks();
|
|
379
|
+
let visible = this.showHistory ? allTasks : allTasks.filter((task) => task.status === "running");
|
|
380
|
+
if (!this.showHistory && visible.length === 0 && allTasks.some((task) => task.status !== "running")) {
|
|
381
|
+
this.showHistory = true;
|
|
382
|
+
visible = allTasks;
|
|
383
|
+
}
|
|
384
|
+
return sortTasksForUi(visible);
|
|
385
|
+
}
|
|
386
|
+
detailTask() {
|
|
387
|
+
return this.options.getTasks().find((task) => task.id === this.detailTaskId);
|
|
388
|
+
}
|
|
389
|
+
openDetail(taskId) {
|
|
390
|
+
this.detailTaskId = taskId;
|
|
391
|
+
this.mode = "detail";
|
|
392
|
+
this.detailLines = [];
|
|
393
|
+
this.detailFollow = true;
|
|
394
|
+
this.detailScrollTop = 0;
|
|
395
|
+
this.tailError = void 0;
|
|
396
|
+
this.options.markSeen(taskId);
|
|
397
|
+
void this.refreshTail();
|
|
398
|
+
this.tui.requestRender();
|
|
399
|
+
}
|
|
400
|
+
ensureSelectionVisible() {
|
|
401
|
+
if (this.selectedIndex < this.listScroll) this.listScroll = this.selectedIndex;
|
|
402
|
+
if (this.selectedIndex >= this.listScroll + LIST_VISIBLE_ROWS)
|
|
403
|
+
this.listScroll = this.selectedIndex - LIST_VISIBLE_ROWS + 1;
|
|
404
|
+
}
|
|
405
|
+
async stopTaskFromUi(task) {
|
|
406
|
+
if (task.status !== "running") {
|
|
407
|
+
this.actionMessage = `${taskDisplayName(task)} is ${task.status}; nothing to stop.`;
|
|
408
|
+
this.tui.requestRender();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
this.actionMessage = `Stopping ${taskDisplayName(task)}\u2026`;
|
|
412
|
+
this.tui.requestRender();
|
|
413
|
+
try {
|
|
414
|
+
await this.options.stopTask(task);
|
|
415
|
+
this.actionMessage = `Stopped ${taskDisplayName(task)}.`;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
this.actionMessage = `Stop failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
418
|
+
}
|
|
419
|
+
this.tui.requestRender();
|
|
420
|
+
}
|
|
421
|
+
async stopAllFromUi() {
|
|
422
|
+
const running = this.options.getTasks().filter((task) => task.status === "running");
|
|
423
|
+
if (running.length === 0) {
|
|
424
|
+
this.actionMessage = "No running background tasks to stop.";
|
|
425
|
+
this.tui.requestRender();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (!this.confirmStopAllArmed) {
|
|
429
|
+
this.confirmStopAllArmed = true;
|
|
430
|
+
this.actionMessage = `Press a/K again to stop all ${formatCount(running.length)} running task${pluralSuffix(running.length)}.`;
|
|
431
|
+
this.tui.requestRender();
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
this.confirmStopAllArmed = false;
|
|
435
|
+
this.actionMessage = `Stopping ${formatCount(running.length)} running task${pluralSuffix(running.length)}\u2026`;
|
|
436
|
+
this.tui.requestRender();
|
|
437
|
+
try {
|
|
438
|
+
const result = await this.options.stopAllRunning();
|
|
439
|
+
this.actionMessage = result.failures.length > 0 ? `Stopped ${formatCount(result.stopped)}; ${formatCount(result.failures.length)} failed: ${result.failures.join("; ")}` : `Stopped ${formatCount(result.stopped)} running task${pluralSuffix(result.stopped)}.`;
|
|
440
|
+
} catch (error) {
|
|
441
|
+
this.actionMessage = `Stop-all failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
442
|
+
}
|
|
443
|
+
this.tui.requestRender();
|
|
444
|
+
}
|
|
445
|
+
async rerunTaskFromUi(task) {
|
|
446
|
+
this.actionMessage = `Rerunning ${taskDisplayName(task)}\u2026`;
|
|
447
|
+
this.tui.requestRender();
|
|
448
|
+
try {
|
|
449
|
+
const rerun = await this.options.rerunTask(task);
|
|
450
|
+
this.showHistory = false;
|
|
451
|
+
const tasks = this.currentTasks();
|
|
452
|
+
const index = tasks.findIndex((candidate) => candidate.id === rerun.id);
|
|
453
|
+
if (index >= 0) {
|
|
454
|
+
this.selectedIndex = index;
|
|
455
|
+
this.ensureSelectionVisible();
|
|
456
|
+
}
|
|
457
|
+
this.actionMessage = `Reran as ${taskDisplayName(rerun)} (${rerun.id}).`;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
this.actionMessage = `Rerun failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
460
|
+
}
|
|
461
|
+
this.tui.requestRender();
|
|
462
|
+
}
|
|
463
|
+
showOutputPathFromUi(task) {
|
|
464
|
+
this.options.showOutputPath(task);
|
|
465
|
+
this.actionMessage = `Output path shown for ${taskDisplayName(task)}.`;
|
|
466
|
+
this.tui.requestRender();
|
|
467
|
+
}
|
|
468
|
+
/** Scroll the detail output window. Scrolling up pauses the live tail; reaching the bottom resumes it. */
|
|
469
|
+
scrollDetail(delta) {
|
|
470
|
+
const maxTop = Math.max(0, this.detailLines.length - DETAIL_VISIBLE_OUTPUT_LINES);
|
|
471
|
+
if (maxTop === 0) return;
|
|
472
|
+
if (this.detailFollow) {
|
|
473
|
+
this.detailFollow = false;
|
|
474
|
+
this.detailScrollTop = maxTop;
|
|
475
|
+
}
|
|
476
|
+
this.detailScrollTop = Math.min(maxTop, Math.max(0, this.detailScrollTop + delta));
|
|
477
|
+
if (this.detailScrollTop >= maxTop) {
|
|
478
|
+
this.detailFollow = true;
|
|
479
|
+
this.detailScrollTop = 0;
|
|
480
|
+
void this.refreshTail();
|
|
481
|
+
}
|
|
482
|
+
this.tui.requestRender();
|
|
483
|
+
}
|
|
484
|
+
async refreshTail() {
|
|
485
|
+
const task = this.detailTask();
|
|
486
|
+
if (!task) return;
|
|
487
|
+
if (!this.detailFollow) return;
|
|
488
|
+
try {
|
|
489
|
+
if (!existsSync(task.outputAbsPath)) {
|
|
490
|
+
this.detailLines = [];
|
|
491
|
+
this.tailBytesRead = 0;
|
|
492
|
+
this.tailTotalBytes = 0;
|
|
493
|
+
this.tailTruncated = false;
|
|
494
|
+
this.tailError = `Output file not found: ${task.outputPath}`;
|
|
495
|
+
this.tui.requestRender();
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const read = await boundedRead(task.outputAbsPath, DETAIL_TAIL_BYTES, true);
|
|
499
|
+
this.detailLines = toOutputLines(read.content);
|
|
500
|
+
this.tailBytesRead = read.bytesRead;
|
|
501
|
+
this.tailTotalBytes = read.totalBytes;
|
|
502
|
+
this.tailTruncated = read.truncated;
|
|
503
|
+
this.tailError = void 0;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
this.tailError = `Output read failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
506
|
+
}
|
|
507
|
+
this.tui.requestRender();
|
|
508
|
+
}
|
|
509
|
+
activityLabel(task) {
|
|
510
|
+
if (task.status !== "running") return "";
|
|
511
|
+
const now = Date.now();
|
|
512
|
+
const previous = this.lastBytesByTask.get(task.id);
|
|
513
|
+
this.lastBytesByTask.set(task.id, task.bytesWritten);
|
|
514
|
+
if (previous !== void 0 && task.bytesWritten > previous) {
|
|
515
|
+
const delta = task.bytesWritten - previous;
|
|
516
|
+
this.recentActivityByTask.set(task.id, { delta, timestamp: now });
|
|
517
|
+
return `+${formatSize(delta)} \u2191`;
|
|
518
|
+
}
|
|
519
|
+
const recent = this.recentActivityByTask.get(task.id);
|
|
520
|
+
if (recent && now - recent.timestamp < 3e3) return `+${formatSize(recent.delta)} \u2191`;
|
|
521
|
+
return "";
|
|
522
|
+
}
|
|
523
|
+
frame(title, subtitle, body, footer, width) {
|
|
524
|
+
const inner = Math.max(1, width - 2);
|
|
525
|
+
const top = blueBorder(`\u256D${"\u2500".repeat(inner)}\u256E`);
|
|
526
|
+
const bottom = blueBorder(`\u2570${"\u2500".repeat(inner)}\u256F`);
|
|
527
|
+
const row = /* @__PURE__ */ __name((content = "") => `${blueBorder("\u2502")}${padAnsi(truncateToWidth(content, inner), inner)}${blueBorder("\u2502")}`, "row");
|
|
528
|
+
const header = lightBlue(padAnsi(` ${title}`, inner));
|
|
529
|
+
const subtitleLine = subtitle ? lightBlue(padAnsi(` ${subtitle}`, inner)) : lightBlue(" ".repeat(inner));
|
|
530
|
+
const lines = [top, row(header), row(subtitleLine), row()];
|
|
531
|
+
for (const line of body) lines.push(row(line));
|
|
532
|
+
lines.push(row());
|
|
533
|
+
lines.push(row(footer));
|
|
534
|
+
lines.push(bottom);
|
|
535
|
+
return lines;
|
|
536
|
+
}
|
|
537
|
+
renderList(width) {
|
|
538
|
+
const tasks = this.currentTasks();
|
|
539
|
+
if (this.selectedIndex >= tasks.length) this.selectedIndex = Math.max(0, tasks.length - 1);
|
|
540
|
+
this.ensureSelectionVisible();
|
|
541
|
+
const allTasks = this.options.getTasks();
|
|
542
|
+
const allRunning = allTasks.filter((task) => task.status === "running").length;
|
|
543
|
+
const historyCount = allTasks.length - allRunning;
|
|
544
|
+
const unseenFailed = allTasks.filter(
|
|
545
|
+
(task) => task.status === "failed" && !this.options.isSeen(task.id)
|
|
546
|
+
).length;
|
|
547
|
+
const unseenStopped = allTasks.filter(
|
|
548
|
+
(task) => task.status === "killed" && !this.options.isSeen(task.id)
|
|
549
|
+
).length;
|
|
550
|
+
const unseenDone = allTasks.filter(
|
|
551
|
+
(task) => task.status === "completed" && !this.options.isSeen(task.id)
|
|
552
|
+
).length;
|
|
553
|
+
const unread = unseenFailed + unseenStopped + unseenDone;
|
|
554
|
+
const subtitleParts = this.showHistory ? [`${formatCount(allRunning)} active`, `${formatCount(historyCount)} history`] : allRunning > 0 ? [`${formatCount(allRunning)} active shell${pluralSuffix(allRunning)}`] : ["No active shells"];
|
|
555
|
+
if (unseenFailed) subtitleParts.push(`${formatCount(unseenFailed)} failed`);
|
|
556
|
+
if (unseenStopped) subtitleParts.push(`${formatCount(unseenStopped)} stopped`);
|
|
557
|
+
if (unseenDone) subtitleParts.push(`${formatCount(unseenDone)} done`);
|
|
558
|
+
if (unread) subtitleParts.push(`${formatCount(unread)} unread`);
|
|
559
|
+
const subtitle = subtitleParts.join(" \xB7 ");
|
|
560
|
+
const body = [];
|
|
561
|
+
if (tasks.length === 0) {
|
|
562
|
+
const message = allTasks.length === 0 ? " No background tasks in this session." : this.showHistory ? " No background tasks in this view." : " No running background tasks. Press h to show recent history.";
|
|
563
|
+
body.push(this.theme.fg("dim", message));
|
|
564
|
+
} else {
|
|
565
|
+
const maxNameWidth = Math.max(12, width - 78);
|
|
566
|
+
const visible = tasks.slice(this.listScroll, this.listScroll + LIST_VISIBLE_ROWS);
|
|
567
|
+
for (let i = 0; i < visible.length; i++) {
|
|
568
|
+
const task = visible[i];
|
|
569
|
+
if (!task) continue;
|
|
570
|
+
const index = this.listScroll + i;
|
|
571
|
+
const selected = index === this.selectedIndex;
|
|
572
|
+
const pointer = selected ? "\u203A" : " ";
|
|
573
|
+
const unseen = task.status !== "running" && !this.options.isSeen(task.id);
|
|
574
|
+
const unreadMark = unseen ? this.theme.fg("warning", "\u25CF") : " ";
|
|
575
|
+
const rawName = truncateChars(taskDisplayName(task), maxNameWidth);
|
|
576
|
+
const name = task.status === "failed" ? this.theme.fg("error", rawName) : task.status === "killed" ? this.theme.fg("warning", rawName) : task.status === "completed" ? this.theme.fg("success", rawName) : this.theme.fg("text", rawName);
|
|
577
|
+
const status = statusColor(this.theme, task.status, statusLabel(task.status));
|
|
578
|
+
const runtime = taskAge(task);
|
|
579
|
+
const size = formatSize(task.bytesWritten);
|
|
580
|
+
const context = formatContextUsage(task);
|
|
581
|
+
const contextText = ` ${contextColor(this.theme, task, `ctx ${context}`)}`;
|
|
582
|
+
const model = formatModel(task);
|
|
583
|
+
const modelText = model ? ` ${this.theme.fg("dim", model)}` : "";
|
|
584
|
+
const tokenUsage = formatTokenUsage(task);
|
|
585
|
+
const tokenText = tokenUsage ? ` ${this.theme.fg("dim", tokenUsage)}` : "";
|
|
586
|
+
const toolUsage = formatToolUsage(task);
|
|
587
|
+
const toolText = toolUsage ? ` ${this.theme.fg("dim", toolUsage)}` : "";
|
|
588
|
+
const activity = this.activityLabel(task);
|
|
589
|
+
const activityText = activity ? ` ${this.theme.fg("warning", activity)}` : "";
|
|
590
|
+
const exit = task.status !== "running" ? this.theme.fg("dim", formatExitCodeText(task.exitCode)) : "";
|
|
591
|
+
let row = ` ${pointer} ${unreadMark} ${name} ${this.theme.fg("dim", task.id)} ${this.theme.fg("dim", "\xB7")} ${status}${exit} ${this.theme.fg("dim", `${runtime} ${size}`)}${contextText}${modelText}${tokenText}${toolText}${activityText}`;
|
|
592
|
+
if (selected) row = lightBlue(padAnsi(truncateToWidth(row, width - 4), width - 4));
|
|
593
|
+
body.push(row);
|
|
594
|
+
}
|
|
595
|
+
if (tasks.length > LIST_VISIBLE_ROWS) {
|
|
596
|
+
const firstVisible = formatCount(this.listScroll + 1);
|
|
597
|
+
const lastVisible = formatCount(
|
|
598
|
+
Math.min(tasks.length, this.listScroll + LIST_VISIBLE_ROWS)
|
|
599
|
+
);
|
|
600
|
+
const totalVisible = formatCount(tasks.length);
|
|
601
|
+
body.push(
|
|
602
|
+
this.theme.fg("dim", ` Showing ${firstVisible}-${lastVisible} of ${totalVisible}`)
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (this.actionMessage) body.push(this.theme.fg("warning", ` ${this.actionMessage}`));
|
|
607
|
+
return this.frame(
|
|
608
|
+
"bg tasks focused",
|
|
609
|
+
subtitle,
|
|
610
|
+
body,
|
|
611
|
+
` ${this.theme.fg("dim", `\u2191/\u2193 select \xB7 Enter logs \xB7 k stop \xB7 a stop all \xB7 h ${this.showHistory ? "hide" : "show"} history \xB7 R rerun \xB7 c path \xB7 x close`)}`,
|
|
612
|
+
width
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
renderDetail(width) {
|
|
616
|
+
const task = this.detailTask();
|
|
617
|
+
if (!task) {
|
|
618
|
+
this.mode = "list";
|
|
619
|
+
return this.renderList(width);
|
|
620
|
+
}
|
|
621
|
+
const name = taskDisplayName(task);
|
|
622
|
+
const status = statusColor(this.theme, task.status);
|
|
623
|
+
const exit = formatExitCodeText(task.exitCode);
|
|
624
|
+
const body = [
|
|
625
|
+
` ${this.theme.fg("toolTitle", "Name:")} ${this.theme.fg("accent", name)}`,
|
|
626
|
+
` ${this.theme.fg("toolTitle", "ID:")} ${this.theme.fg("accent", task.id)}`,
|
|
627
|
+
` ${this.theme.fg("toolTitle", "Status:")} ${status}${this.theme.fg("dim", exit)}`,
|
|
628
|
+
` ${this.theme.fg("toolTitle", "Runtime:")} ${taskAge(task)}${this.theme.fg("dim", formatPidText(task.pid))}`,
|
|
629
|
+
` ${this.theme.fg("toolTitle", "Started:")} ${formatTime(task.startTime)}${task.endTime ? this.theme.fg("dim", ` \xB7 ended ${formatTime(task.endTime)}`) : ""}`,
|
|
630
|
+
` ${this.theme.fg("toolTitle", "Output:")} ${this.theme.fg("accent", task.outputPath)}`
|
|
631
|
+
];
|
|
632
|
+
if (task.description && compactWhitespace(task.description) !== compactWhitespace(name)) {
|
|
633
|
+
body.push(
|
|
634
|
+
` ${this.theme.fg("toolTitle", "Description:")} ${truncateToWidth(task.description, width - 16)}`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
const modelDetail = formatModelDetail(task);
|
|
638
|
+
body.push(
|
|
639
|
+
` ${this.theme.fg("toolTitle", "Model:")} ${task.model ? this.theme.fg("accent", modelDetail) : this.theme.fg("dim", modelDetail)}`
|
|
640
|
+
);
|
|
641
|
+
const context = formatContextDetail(task);
|
|
642
|
+
body.push(
|
|
643
|
+
` ${this.theme.fg("toolTitle", "Context:")} ${contextColor(this.theme, task, context)}`
|
|
644
|
+
);
|
|
645
|
+
body.push(
|
|
646
|
+
` ${this.theme.fg("toolTitle", "Tokens:")} ${this.theme.fg("dim", formatTokenDetail(task))}`
|
|
647
|
+
);
|
|
648
|
+
body.push(
|
|
649
|
+
` ${this.theme.fg("toolTitle", "Tools:")} ${this.theme.fg("dim", formatToolDetail(task))}`
|
|
650
|
+
);
|
|
651
|
+
body.push(
|
|
652
|
+
` ${this.theme.fg("toolTitle", "Command:")} ${truncateToWidth(task.command, width - 13)}`
|
|
653
|
+
);
|
|
654
|
+
if (task.error) body.push(` ${this.theme.fg("error", `Error: ${task.error}`)}`);
|
|
655
|
+
body.push("", ` ${this.theme.fg("toolTitle", "Output tail:")}`);
|
|
656
|
+
body.push(...this.renderOutputBox(width - 4));
|
|
657
|
+
if (this.actionMessage) body.push(this.theme.fg("warning", ` ${this.actionMessage}`));
|
|
658
|
+
const subtitle = `${task.id} \xB7 ${task.status === "running" ? "live tail refreshes every second" : "final output"}`;
|
|
659
|
+
const footer = ` ${this.theme.fg("dim", "\u2191/\u2193 scroll \xB7 \u2190 list \xB7 r refresh \xB7 k stop \xB7 R rerun \xB7 c path \xB7 x close")}`;
|
|
660
|
+
return this.frame(`bg: ${truncateChars(name, 64)}`, subtitle, body, footer, width);
|
|
661
|
+
}
|
|
662
|
+
renderOutputBox(width) {
|
|
663
|
+
const inner = Math.max(1, width - 2);
|
|
664
|
+
const top = ` ${blueBorder(`\u256D${"\u2500".repeat(inner)}\u256E`)}`;
|
|
665
|
+
const bottom = ` ${blueBorder(`\u2570${"\u2500".repeat(inner)}\u256F`)}`;
|
|
666
|
+
const row = /* @__PURE__ */ __name((content = "") => ` ${blueBorder("\u2502")}${padAnsi(truncateToWidth(content, inner), inner)}${blueBorder("\u2502")}`, "row");
|
|
667
|
+
const lines = [top];
|
|
668
|
+
if (this.tailError) {
|
|
669
|
+
lines.push(row(this.theme.fg("error", this.tailError)));
|
|
670
|
+
} else if (this.detailLines.length === 0) {
|
|
671
|
+
lines.push(row(this.theme.fg("dim", "No output yet")));
|
|
672
|
+
} else {
|
|
673
|
+
const maxTop = Math.max(0, this.detailLines.length - DETAIL_VISIBLE_OUTPUT_LINES);
|
|
674
|
+
const start = this.detailFollow ? maxTop : Math.min(this.detailScrollTop, maxTop);
|
|
675
|
+
const windowLines = this.detailLines.slice(start, start + DETAIL_VISIBLE_OUTPUT_LINES);
|
|
676
|
+
for (const line of windowLines) lines.push(row(this.theme.fg("toolOutput", line)));
|
|
677
|
+
}
|
|
678
|
+
while (lines.length < DETAIL_VISIBLE_OUTPUT_LINES + 1) lines.push(row());
|
|
679
|
+
lines.push(bottom);
|
|
680
|
+
lines.push(` ${this.theme.fg("dim", this.outputStatusLine())}`);
|
|
681
|
+
return lines;
|
|
682
|
+
}
|
|
683
|
+
outputStatusLine() {
|
|
684
|
+
const total = this.detailLines.length;
|
|
685
|
+
if (!this.detailFollow && total > 0) {
|
|
686
|
+
const maxTop = Math.max(0, total - DETAIL_VISIBLE_OUTPUT_LINES);
|
|
687
|
+
const start = Math.min(this.detailScrollTop, maxTop);
|
|
688
|
+
const end = Math.min(total, start + DETAIL_VISIBLE_OUTPUT_LINES);
|
|
689
|
+
return `lines ${formatCount(start + 1)}\u2013${formatCount(end)} of ${formatCount(total)} \xB7 \u2191/\u2193 PgUp/PgDn scroll \xB7 \u2193 at bottom follows`;
|
|
690
|
+
}
|
|
691
|
+
const suffix = this.tailTruncated ? ` of ${formatSize(this.tailTotalBytes)}` : "";
|
|
692
|
+
return `following tail ${formatSize(this.tailBytesRead)}${suffix} \xB7 \u2191 scroll`;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
export {
|
|
696
|
+
BackgroundTasksManager
|
|
697
|
+
};
|