@tothemax/tasking 0.0.0-stage → 0.6.15
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 +119 -2
- package/README.zh-CN.md +120 -0
- package/assets/skills/install-glab/SKILL.md +70 -0
- package/assets/skills/land/SKILL.md +63 -0
- package/assets/skills/land/land_watch.py +312 -0
- package/assets/skills/openspec-archive-change/SKILL.md +114 -0
- package/assets/skills/opsx-grill-with-docs/SKILL.md +193 -0
- package/assets/skills/opsx-implement/SKILL.md +258 -0
- package/assets/skills/opsx-propose-with-tdd/SKILL.md +271 -0
- package/assets/workflows/WORKFLOW.code-mr.en.md.example +345 -0
- package/assets/workflows/WORKFLOW.code-mr.md.example +339 -0
- package/assets/workflows/WORKFLOW.feishu-direct.en.md.example +267 -0
- package/assets/workflows/WORKFLOW.feishu-direct.md.example +258 -0
- package/assets/workflows/WORKFLOW.grill-openspec.en.md.example +362 -0
- package/assets/workflows/WORKFLOW.grill-openspec.md.example +356 -0
- package/assets/workflows/WORKFLOW.minimal.en.md.example +296 -0
- package/assets/workflows/WORKFLOW.minimal.md.example +289 -0
- package/dist/adapters/feishu/events.d.ts +55 -0
- package/dist/adapters/feishu/events.d.ts.map +1 -0
- package/dist/adapters/feishu/events.js +184 -0
- package/dist/adapters/feishu/events.js.map +1 -0
- package/dist/adapters/feishu/index.d.ts +2 -0
- package/dist/adapters/feishu/index.d.ts.map +1 -0
- package/dist/adapters/feishu/index.js +2 -0
- package/dist/adapters/feishu/index.js.map +1 -0
- package/dist/adapters/feishu/probe.d.ts +31 -0
- package/dist/adapters/feishu/probe.d.ts.map +1 -0
- package/dist/adapters/feishu/probe.js +179 -0
- package/dist/adapters/feishu/probe.js.map +1 -0
- package/dist/adapters/feishu/source.d.ts +124 -0
- package/dist/adapters/feishu/source.d.ts.map +1 -0
- package/dist/adapters/feishu/source.js +715 -0
- package/dist/adapters/feishu/source.js.map +1 -0
- package/dist/adapters/jira/index.d.ts +2 -0
- package/dist/adapters/jira/index.d.ts.map +1 -0
- package/dist/adapters/jira/index.js +2 -0
- package/dist/adapters/jira/index.js.map +1 -0
- package/dist/adapters/jira/tracker.d.ts +63 -0
- package/dist/adapters/jira/tracker.d.ts.map +1 -0
- package/dist/adapters/jira/tracker.js +402 -0
- package/dist/adapters/jira/tracker.js.map +1 -0
- package/dist/bridge/binding-store.d.ts +93 -0
- package/dist/bridge/binding-store.d.ts.map +1 -0
- package/dist/bridge/binding-store.js +365 -0
- package/dist/bridge/binding-store.js.map +1 -0
- package/dist/bridge/commands.d.ts +45 -0
- package/dist/bridge/commands.d.ts.map +1 -0
- package/dist/bridge/commands.js +197 -0
- package/dist/bridge/commands.js.map +1 -0
- package/dist/bridge/comment-bridge.d.ts +116 -0
- package/dist/bridge/comment-bridge.d.ts.map +1 -0
- package/dist/bridge/comment-bridge.js +1473 -0
- package/dist/bridge/comment-bridge.js.map +1 -0
- package/dist/cli/daemon-info.d.ts +17 -0
- package/dist/cli/daemon-info.d.ts.map +1 -0
- package/dist/cli/daemon-info.js +64 -0
- package/dist/cli/daemon-info.js.map +1 -0
- package/dist/cli/daemon.d.ts +27 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +77 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/doctor.d.ts +7 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +156 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/event-channel.d.ts +16 -0
- package/dist/cli/event-channel.d.ts.map +1 -0
- package/dist/cli/event-channel.js +51 -0
- package/dist/cli/event-channel.js.map +1 -0
- package/dist/cli/help.d.ts +3 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +155 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +774 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +64 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +1296 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/instance-lock.d.ts +13 -0
- package/dist/cli/instance-lock.d.ts.map +1 -0
- package/dist/cli/instance-lock.js +53 -0
- package/dist/cli/instance-lock.js.map +1 -0
- package/dist/cli/prompts.d.ts +13 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +26 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/cli/style.d.ts +26 -0
- package/dist/cli/style.d.ts.map +1 -0
- package/dist/cli/style.js +58 -0
- package/dist/cli/style.js.map +1 -0
- package/dist/cli/tui-helpers.d.ts +5 -0
- package/dist/cli/tui-helpers.d.ts.map +1 -0
- package/dist/cli/tui-helpers.js +124 -0
- package/dist/cli/tui-helpers.js.map +1 -0
- package/dist/cli/workflow-path.d.ts +12 -0
- package/dist/cli/workflow-path.d.ts.map +1 -0
- package/dist/cli/workflow-path.js +37 -0
- package/dist/cli/workflow-path.js.map +1 -0
- package/dist/config/config-types.d.ts +180 -0
- package/dist/config/config-types.d.ts.map +1 -0
- package/dist/config/config-types.js +71 -0
- package/dist/config/config-types.js.map +1 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.d.ts.map +1 -0
- package/dist/config/dotenv.js +10 -0
- package/dist/config/dotenv.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +304 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/manager.d.ts +31 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +110 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/resolver.d.ts +6 -0
- package/dist/config/resolver.d.ts.map +1 -0
- package/dist/config/resolver.js +267 -0
- package/dist/config/resolver.js.map +1 -0
- package/dist/config/validator.d.ts +9 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +70 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/direct/card.d.ts +49 -0
- package/dist/direct/card.d.ts.map +1 -0
- package/dist/direct/card.js +274 -0
- package/dist/direct/card.js.map +1 -0
- package/dist/direct/command.d.ts +12 -0
- package/dist/direct/command.d.ts.map +1 -0
- package/dist/direct/command.js +23 -0
- package/dist/direct/command.js.map +1 -0
- package/dist/direct/manager.d.ts +159 -0
- package/dist/direct/manager.d.ts.map +1 -0
- package/dist/direct/manager.js +1862 -0
- package/dist/direct/manager.js.map +1 -0
- package/dist/mcp/inject.d.ts +5 -0
- package/dist/mcp/inject.d.ts.map +1 -0
- package/dist/mcp/inject.js +51 -0
- package/dist/mcp/inject.js.map +1 -0
- package/dist/mcp/jira-server.d.ts +29 -0
- package/dist/mcp/jira-server.d.ts.map +1 -0
- package/dist/mcp/jira-server.js +288 -0
- package/dist/mcp/jira-server.js.map +1 -0
- package/dist/observability/activity-store.d.ts +29 -0
- package/dist/observability/activity-store.d.ts.map +1 -0
- package/dist/observability/activity-store.js +32 -0
- package/dist/observability/activity-store.js.map +1 -0
- package/dist/observability/config-view.d.ts +19 -0
- package/dist/observability/config-view.d.ts.map +1 -0
- package/dist/observability/config-view.js +61 -0
- package/dist/observability/config-view.js.map +1 -0
- package/dist/observability/http-dashboard.d.ts +36 -0
- package/dist/observability/http-dashboard.d.ts.map +1 -0
- package/dist/observability/http-dashboard.js +297 -0
- package/dist/observability/http-dashboard.js.map +1 -0
- package/dist/observability/log-buffer.d.ts +21 -0
- package/dist/observability/log-buffer.d.ts.map +1 -0
- package/dist/observability/log-buffer.js +69 -0
- package/dist/observability/log-buffer.js.map +1 -0
- package/dist/observability/logger.d.ts +37 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +114 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/snapshot.d.ts +11 -0
- package/dist/observability/snapshot.d.ts.map +1 -0
- package/dist/observability/snapshot.js +59 -0
- package/dist/observability/snapshot.js.map +1 -0
- package/dist/observability/terminal-dashboard.d.ts +155 -0
- package/dist/observability/terminal-dashboard.d.ts.map +1 -0
- package/dist/observability/terminal-dashboard.js +1598 -0
- package/dist/observability/terminal-dashboard.js.map +1 -0
- package/dist/observability/wrap.d.ts +4 -0
- package/dist/observability/wrap.d.ts.map +1 -0
- package/dist/observability/wrap.js +80 -0
- package/dist/observability/wrap.js.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +52 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/scheduler.js +535 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/shared/agent-resolver.d.ts +11 -0
- package/dist/shared/agent-resolver.d.ts.map +1 -0
- package/dist/shared/agent-resolver.js +20 -0
- package/dist/shared/agent-resolver.js.map +1 -0
- package/dist/shared/errors.d.ts +14 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +24 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/info-card.d.ts +24 -0
- package/dist/shared/info-card.d.ts.map +1 -0
- package/dist/shared/info-card.js +46 -0
- package/dist/shared/info-card.js.map +1 -0
- package/dist/shared/types.d.ts +148 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +15 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/translate/card.d.ts +2 -0
- package/dist/translate/card.d.ts.map +1 -0
- package/dist/translate/card.js +17 -0
- package/dist/translate/card.js.map +1 -0
- package/dist/translate/dict.d.ts +7 -0
- package/dist/translate/dict.d.ts.map +1 -0
- package/dist/translate/dict.js +895 -0
- package/dist/translate/dict.js.map +1 -0
- package/dist/translate/locale.d.ts +8 -0
- package/dist/translate/locale.d.ts.map +1 -0
- package/dist/translate/locale.js +75 -0
- package/dist/translate/locale.js.map +1 -0
- package/dist/translate/normalize.d.ts +4 -0
- package/dist/translate/normalize.d.ts.map +1 -0
- package/dist/translate/normalize.js +38 -0
- package/dist/translate/normalize.js.map +1 -0
- package/dist/translate/output.d.ts +3 -0
- package/dist/translate/output.d.ts.map +1 -0
- package/dist/translate/output.js +16 -0
- package/dist/translate/output.js.map +1 -0
- package/dist/worker/prompt.d.ts +11 -0
- package/dist/worker/prompt.d.ts.map +1 -0
- package/dist/worker/prompt.js +153 -0
- package/dist/worker/prompt.js.map +1 -0
- package/dist/worker/runner.d.ts +101 -0
- package/dist/worker/runner.d.ts.map +1 -0
- package/dist/worker/runner.js +448 -0
- package/dist/worker/runner.js.map +1 -0
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/manager.d.ts +37 -0
- package/dist/workspace/manager.d.ts.map +1 -0
- package/dist/workspace/manager.js +157 -0
- package/dist/workspace/manager.js.map +1 -0
- package/package.json +65 -4
|
@@ -0,0 +1,1598 @@
|
|
|
1
|
+
import { setLocale, translate } from "../translate/locale.js";
|
|
2
|
+
import { CONFIG_SECTIONS } from "./config-view.js";
|
|
3
|
+
import { buildSnapshot } from "./snapshot.js";
|
|
4
|
+
import { truncateToWidth, wrapToWidth } from "./wrap.js";
|
|
5
|
+
function syncLocaleFromConfig(view) {
|
|
6
|
+
setLocale(view.config.interface_language === "en" ? "en" : "zh");
|
|
7
|
+
}
|
|
8
|
+
const SPARKLINE_BLOCKS = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
|
|
9
|
+
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
10
|
+
const GRAPH_COLUMNS = 24;
|
|
11
|
+
const GRAPH_WINDOW_MS = 10 * 60 * 1000;
|
|
12
|
+
const BAR_WIDTH = 10;
|
|
13
|
+
const DETAIL_OUTPUT_MAX_LINES = 100;
|
|
14
|
+
const DESCRIPTION_FOLD_LINES = 6;
|
|
15
|
+
function capTailLines(text, max) {
|
|
16
|
+
const parts = text.split("\n");
|
|
17
|
+
if (parts.length > 1 && parts[parts.length - 1] === "")
|
|
18
|
+
parts.pop();
|
|
19
|
+
if (parts.length <= max)
|
|
20
|
+
return { lines: parts, dropped: 0 };
|
|
21
|
+
return { lines: parts.slice(-max), dropped: parts.length - max };
|
|
22
|
+
}
|
|
23
|
+
function logFieldText(value) {
|
|
24
|
+
if (typeof value === "string")
|
|
25
|
+
return value;
|
|
26
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") {
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return JSON.stringify(value);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function logFieldPriority(key, value) {
|
|
37
|
+
if (key === "auto_approve")
|
|
38
|
+
return 2;
|
|
39
|
+
return typeof value === "string" && value.length > 20 ? 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
function formatDuration(ms) {
|
|
42
|
+
if (ms < 1000)
|
|
43
|
+
return `${ms}ms`;
|
|
44
|
+
if (ms < 60000)
|
|
45
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
46
|
+
return `${Math.floor(ms / 60000)}m ${Math.round((ms % 60000) / 1000)}s`;
|
|
47
|
+
}
|
|
48
|
+
const ENTER_ALT = "\x1b[?1049h";
|
|
49
|
+
const EXIT_ALT = "\x1b[?1049l";
|
|
50
|
+
const CLEAR_SCREEN = "\x1b[2J\x1b[H";
|
|
51
|
+
const CURSOR_HOME = "\x1b[H";
|
|
52
|
+
const CLEAR_LINE = "\x1b[K";
|
|
53
|
+
const CLEAR_BELOW = "\x1b[J";
|
|
54
|
+
const HIDE_CURSOR = "\x1b[?25l";
|
|
55
|
+
const SHOW_CURSOR = "\x1b[?25h";
|
|
56
|
+
const RESET = "\x1b[0m";
|
|
57
|
+
const BOLD = "\x1b[1m";
|
|
58
|
+
const DIM = "\x1b[2m";
|
|
59
|
+
const CYAN = "\x1b[36m";
|
|
60
|
+
const GREEN = "\x1b[32m";
|
|
61
|
+
const YELLOW = "\x1b[33m";
|
|
62
|
+
const RED = "\x1b[31m";
|
|
63
|
+
const GRAY = "\x1b[90m";
|
|
64
|
+
const MAGENTA = "\x1b[35m";
|
|
65
|
+
export class TerminalDashboard {
|
|
66
|
+
opts;
|
|
67
|
+
timer = null;
|
|
68
|
+
tokenSamples = [];
|
|
69
|
+
lastRenderedContent = null;
|
|
70
|
+
lastRenderedAt = 0;
|
|
71
|
+
intervalMs;
|
|
72
|
+
renderFn;
|
|
73
|
+
altScreenActive = false;
|
|
74
|
+
stdinActive = false;
|
|
75
|
+
mode = "overview";
|
|
76
|
+
focus = "running";
|
|
77
|
+
selectedIndex = 0;
|
|
78
|
+
selectedId = null;
|
|
79
|
+
detailId = null;
|
|
80
|
+
descExpanded = false;
|
|
81
|
+
escBuffer = "";
|
|
82
|
+
escTimer = null;
|
|
83
|
+
lastSnapshot = null;
|
|
84
|
+
lastConfigView = null;
|
|
85
|
+
configScrollOffset = 0;
|
|
86
|
+
logFollow = true;
|
|
87
|
+
logPinnedTop = null;
|
|
88
|
+
logLevelFilter = "info";
|
|
89
|
+
searchActive = false;
|
|
90
|
+
searchQuery = "";
|
|
91
|
+
searchFilterOnly = false;
|
|
92
|
+
spinnerFrame = 0;
|
|
93
|
+
activityFollow = true;
|
|
94
|
+
activityAnchoredStart = null;
|
|
95
|
+
activityCursor = 0;
|
|
96
|
+
activityDetailScroll = 0;
|
|
97
|
+
activityReturnMode = "detail-running";
|
|
98
|
+
lastActivityEvents = [];
|
|
99
|
+
lastActivityForId = null;
|
|
100
|
+
terminalWidthFn;
|
|
101
|
+
renderInFlight = false;
|
|
102
|
+
renderQueued = false;
|
|
103
|
+
static MIN_RERENDER_MS = 200;
|
|
104
|
+
static ESC_TIMEOUT_MS = 50;
|
|
105
|
+
static LOG_VIEWPORT = 30;
|
|
106
|
+
static CONFIG_VIEWPORT = 30;
|
|
107
|
+
static ACTIVITY_VIEWPORT = 30;
|
|
108
|
+
static ACTIVITY_EVENT_WIDTH_PAD = 13;
|
|
109
|
+
static ACTIVITY_DETAIL_WIDTH_PAD = 4;
|
|
110
|
+
constructor(opts) {
|
|
111
|
+
this.opts = opts;
|
|
112
|
+
this.intervalMs = opts.intervalMs ?? 1000;
|
|
113
|
+
this.renderFn = opts.renderFn ?? ((content) => process.stderr.write(content));
|
|
114
|
+
this.terminalWidthFn = opts.terminalWidth ?? (() => process.stdout.columns ?? 80);
|
|
115
|
+
}
|
|
116
|
+
start(intervalMs) {
|
|
117
|
+
const ms = intervalMs ?? this.intervalMs;
|
|
118
|
+
this.renderFn(`${ENTER_ALT}${CLEAR_SCREEN}${HIDE_CURSOR}`);
|
|
119
|
+
this.altScreenActive = true;
|
|
120
|
+
this.setupStdin();
|
|
121
|
+
this.doRender();
|
|
122
|
+
this.timer = setInterval(() => this.doRender(), ms);
|
|
123
|
+
}
|
|
124
|
+
stop() {
|
|
125
|
+
if (this.timer) {
|
|
126
|
+
clearInterval(this.timer);
|
|
127
|
+
this.timer = null;
|
|
128
|
+
}
|
|
129
|
+
this.teardownStdin();
|
|
130
|
+
if (this.altScreenActive) {
|
|
131
|
+
this.renderFn(`${SHOW_CURSOR}${EXIT_ALT}`);
|
|
132
|
+
this.altScreenActive = false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
forceRender() {
|
|
136
|
+
this.doRender();
|
|
137
|
+
}
|
|
138
|
+
handleKey(key) {
|
|
139
|
+
if (key === "\x1b") {
|
|
140
|
+
this.escBuffer = "\x1b";
|
|
141
|
+
if (this.escTimer)
|
|
142
|
+
clearTimeout(this.escTimer);
|
|
143
|
+
this.escTimer = setTimeout(() => {
|
|
144
|
+
this.processKey(this.escBuffer);
|
|
145
|
+
this.escBuffer = "";
|
|
146
|
+
this.escTimer = null;
|
|
147
|
+
}, TerminalDashboard.ESC_TIMEOUT_MS);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (this.escBuffer) {
|
|
151
|
+
this.escBuffer += key;
|
|
152
|
+
if (this.escBuffer.length >= 3) {
|
|
153
|
+
if (this.escTimer) {
|
|
154
|
+
clearTimeout(this.escTimer);
|
|
155
|
+
this.escTimer = null;
|
|
156
|
+
}
|
|
157
|
+
this.processKey(this.escBuffer);
|
|
158
|
+
this.escBuffer = "";
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.processKey(key);
|
|
164
|
+
}
|
|
165
|
+
processKey(key) {
|
|
166
|
+
if (this.searchActive) {
|
|
167
|
+
this.handleSearchInput(key);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
switch (key) {
|
|
171
|
+
case "\x03":
|
|
172
|
+
process.kill(process.pid, "SIGINT");
|
|
173
|
+
return;
|
|
174
|
+
case "\x1b[A":
|
|
175
|
+
case "\x1bOA":
|
|
176
|
+
case "k":
|
|
177
|
+
if (this.mode === "overview")
|
|
178
|
+
this.moveSelection(-1);
|
|
179
|
+
else if (this.mode === "logs")
|
|
180
|
+
this.scrollLogs(-1);
|
|
181
|
+
else if (this.mode === "config")
|
|
182
|
+
this.scrollConfig(-1);
|
|
183
|
+
else if (this.mode === "activity")
|
|
184
|
+
this.moveActivityCursor(-1);
|
|
185
|
+
else if (this.mode === "activity-detail")
|
|
186
|
+
this.scrollActivityDetail(-1);
|
|
187
|
+
break;
|
|
188
|
+
case "\x1b[B":
|
|
189
|
+
case "\x1bOB":
|
|
190
|
+
case "j":
|
|
191
|
+
if (this.mode === "overview")
|
|
192
|
+
this.moveSelection(1);
|
|
193
|
+
else if (this.mode === "logs")
|
|
194
|
+
this.scrollLogs(1);
|
|
195
|
+
else if (this.mode === "config")
|
|
196
|
+
this.scrollConfig(1);
|
|
197
|
+
else if (this.mode === "activity")
|
|
198
|
+
this.moveActivityCursor(1);
|
|
199
|
+
else if (this.mode === "activity-detail")
|
|
200
|
+
this.scrollActivityDetail(1);
|
|
201
|
+
break;
|
|
202
|
+
case "\t":
|
|
203
|
+
case "\x1b[D":
|
|
204
|
+
case "\x1bOD":
|
|
205
|
+
case "\x1b[C":
|
|
206
|
+
case "\x1bOC":
|
|
207
|
+
case "h":
|
|
208
|
+
case "l":
|
|
209
|
+
if (this.mode === "overview")
|
|
210
|
+
this.toggleFocus();
|
|
211
|
+
break;
|
|
212
|
+
case "\r":
|
|
213
|
+
case "\n":
|
|
214
|
+
if (this.mode === "overview")
|
|
215
|
+
this.enterDetail();
|
|
216
|
+
else if (this.mode === "activity")
|
|
217
|
+
this.enterActivityDetail();
|
|
218
|
+
break;
|
|
219
|
+
case "a":
|
|
220
|
+
if (this.mode === "detail-running" || this.mode === "detail-direct")
|
|
221
|
+
this.enterActivity();
|
|
222
|
+
break;
|
|
223
|
+
case "e":
|
|
224
|
+
if (this.mode === "detail-running") {
|
|
225
|
+
this.descExpanded = !this.descExpanded;
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
case "L":
|
|
229
|
+
if (this.mode === "overview" && this.opts.logBuffer)
|
|
230
|
+
this.enterLogs();
|
|
231
|
+
break;
|
|
232
|
+
case "c":
|
|
233
|
+
if (this.mode === "overview" && this.hasConfigSource())
|
|
234
|
+
this.enterConfig();
|
|
235
|
+
break;
|
|
236
|
+
case "f":
|
|
237
|
+
case " ":
|
|
238
|
+
if (this.mode === "logs") {
|
|
239
|
+
this.toggleLogFollow();
|
|
240
|
+
}
|
|
241
|
+
else if (this.mode === "activity") {
|
|
242
|
+
this.toggleActivityFollow();
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
case "1":
|
|
246
|
+
if (this.mode === "logs") {
|
|
247
|
+
this.logLevelFilter = "debug";
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
case "2":
|
|
251
|
+
if (this.mode === "logs") {
|
|
252
|
+
this.logLevelFilter = "info";
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "3":
|
|
256
|
+
if (this.mode === "logs") {
|
|
257
|
+
this.logLevelFilter = "warn";
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
case "4":
|
|
261
|
+
if (this.mode === "logs") {
|
|
262
|
+
this.logLevelFilter = "error";
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
case "F":
|
|
266
|
+
if (this.mode === "logs" && this.searchQuery) {
|
|
267
|
+
this.searchFilterOnly = !this.searchFilterOnly;
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
case "n":
|
|
271
|
+
if (this.mode === "logs" && this.searchQuery)
|
|
272
|
+
this.jumpMatch(1);
|
|
273
|
+
break;
|
|
274
|
+
case "N":
|
|
275
|
+
if (this.mode === "logs" && this.searchQuery)
|
|
276
|
+
this.jumpMatch(-1);
|
|
277
|
+
break;
|
|
278
|
+
case "/":
|
|
279
|
+
if (this.mode === "logs") {
|
|
280
|
+
this.searchActive = true;
|
|
281
|
+
this.searchQuery = "";
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
case "\x1b":
|
|
285
|
+
case "q":
|
|
286
|
+
if (this.mode === "activity-detail")
|
|
287
|
+
this.exitActivityDetail();
|
|
288
|
+
else if (this.mode === "logs")
|
|
289
|
+
this.exitLogs();
|
|
290
|
+
else if (this.mode === "config")
|
|
291
|
+
this.exitConfig();
|
|
292
|
+
else if (this.mode === "activity")
|
|
293
|
+
this.exitActivity();
|
|
294
|
+
else if (this.mode !== "overview")
|
|
295
|
+
this.exitDetail();
|
|
296
|
+
else
|
|
297
|
+
this.opts.onQuit?.();
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
this.lastRenderedContent = null;
|
|
303
|
+
this.doRender();
|
|
304
|
+
}
|
|
305
|
+
handleSearchInput(key) {
|
|
306
|
+
if (key === "\x1b") {
|
|
307
|
+
this.searchActive = false;
|
|
308
|
+
this.searchQuery = "";
|
|
309
|
+
}
|
|
310
|
+
else if (key === "\r" || key === "\n") {
|
|
311
|
+
this.searchActive = false;
|
|
312
|
+
if (this.searchQuery)
|
|
313
|
+
this.jumpMatch(1);
|
|
314
|
+
}
|
|
315
|
+
else if (key === "\x7f" || key === "\b") {
|
|
316
|
+
this.searchQuery = this.searchQuery.slice(0, -1);
|
|
317
|
+
if (!this.searchQuery)
|
|
318
|
+
this.searchActive = false;
|
|
319
|
+
}
|
|
320
|
+
else if (key.length === 1 && key >= " " && key <= "~") {
|
|
321
|
+
this.searchQuery += key;
|
|
322
|
+
}
|
|
323
|
+
this.lastRenderedContent = null;
|
|
324
|
+
this.doRender();
|
|
325
|
+
}
|
|
326
|
+
moveSelection(dir) {
|
|
327
|
+
const items = this.getFocusedItems();
|
|
328
|
+
if (items.length === 0)
|
|
329
|
+
return;
|
|
330
|
+
const current = this.indexOfSelected(items);
|
|
331
|
+
const next = Math.max(0, Math.min(items.length - 1, current + dir));
|
|
332
|
+
this.selectedIndex = next;
|
|
333
|
+
this.selectedId = items[next]?.id ?? null;
|
|
334
|
+
}
|
|
335
|
+
indexOfSelected(items) {
|
|
336
|
+
if (this.selectedId !== null) {
|
|
337
|
+
const idx = items.findIndex((item) => item.id === this.selectedId);
|
|
338
|
+
if (idx !== -1)
|
|
339
|
+
return idx;
|
|
340
|
+
}
|
|
341
|
+
return Math.min(this.selectedIndex, Math.max(items.length - 1, 0));
|
|
342
|
+
}
|
|
343
|
+
directItems() {
|
|
344
|
+
return this.lastSnapshot?.direct ?? [];
|
|
345
|
+
}
|
|
346
|
+
availableFocuses() {
|
|
347
|
+
return this.directItems().length > 0
|
|
348
|
+
? ["running", "backoff", "direct"]
|
|
349
|
+
: ["running", "backoff"];
|
|
350
|
+
}
|
|
351
|
+
toggleFocus() {
|
|
352
|
+
const order = this.availableFocuses();
|
|
353
|
+
const idx = order.indexOf(this.focus);
|
|
354
|
+
this.focus = order[(idx + 1) % order.length] ?? "running";
|
|
355
|
+
this.selectedIndex = 0;
|
|
356
|
+
this.selectedId = null;
|
|
357
|
+
}
|
|
358
|
+
enterDetail() {
|
|
359
|
+
const items = this.getFocusedItems();
|
|
360
|
+
if (items.length === 0)
|
|
361
|
+
return;
|
|
362
|
+
const idx = this.indexOfSelected(items);
|
|
363
|
+
const item = items[idx];
|
|
364
|
+
if (!item)
|
|
365
|
+
return;
|
|
366
|
+
this.detailId = item.id;
|
|
367
|
+
this.mode =
|
|
368
|
+
this.focus === "running"
|
|
369
|
+
? "detail-running"
|
|
370
|
+
: this.focus === "direct"
|
|
371
|
+
? "detail-direct"
|
|
372
|
+
: "detail-retry";
|
|
373
|
+
this.descExpanded = false;
|
|
374
|
+
}
|
|
375
|
+
exitDetail() {
|
|
376
|
+
this.mode = "overview";
|
|
377
|
+
this.detailId = null;
|
|
378
|
+
}
|
|
379
|
+
enterLogs() {
|
|
380
|
+
this.mode = "logs";
|
|
381
|
+
this.logFollow = true;
|
|
382
|
+
this.logPinnedTop = null;
|
|
383
|
+
this.searchQuery = "";
|
|
384
|
+
this.searchActive = false;
|
|
385
|
+
this.searchFilterOnly = false;
|
|
386
|
+
}
|
|
387
|
+
exitLogs() {
|
|
388
|
+
this.mode = "overview";
|
|
389
|
+
this.searchQuery = "";
|
|
390
|
+
this.searchActive = false;
|
|
391
|
+
this.searchFilterOnly = false;
|
|
392
|
+
}
|
|
393
|
+
hasConfigSource() {
|
|
394
|
+
return Boolean(this.opts.configView || this.opts.fetchConfig);
|
|
395
|
+
}
|
|
396
|
+
enterConfig() {
|
|
397
|
+
this.mode = "config";
|
|
398
|
+
this.configScrollOffset = 0;
|
|
399
|
+
}
|
|
400
|
+
exitConfig() {
|
|
401
|
+
this.mode = "overview";
|
|
402
|
+
this.configScrollOffset = 0;
|
|
403
|
+
}
|
|
404
|
+
enterActivity() {
|
|
405
|
+
this.activityReturnMode = this.mode === "detail-direct" ? "detail-direct" : "detail-running";
|
|
406
|
+
this.mode = "activity";
|
|
407
|
+
this.activityFollow = true;
|
|
408
|
+
this.activityAnchoredStart = null;
|
|
409
|
+
}
|
|
410
|
+
exitActivity() {
|
|
411
|
+
this.mode = this.activityReturnMode;
|
|
412
|
+
this.activityAnchoredStart = null;
|
|
413
|
+
}
|
|
414
|
+
enterActivityDetail() {
|
|
415
|
+
const entries = this.getActivityEntries();
|
|
416
|
+
if (entries.length === 0)
|
|
417
|
+
return;
|
|
418
|
+
this.mode = "activity-detail";
|
|
419
|
+
this.activityDetailScroll = 0;
|
|
420
|
+
}
|
|
421
|
+
exitActivityDetail() {
|
|
422
|
+
this.mode = "activity";
|
|
423
|
+
this.activityDetailScroll = 0;
|
|
424
|
+
}
|
|
425
|
+
moveActivityCursor(dir) {
|
|
426
|
+
const total = this.getActivityEntries().length;
|
|
427
|
+
if (total === 0)
|
|
428
|
+
return;
|
|
429
|
+
const wasFollowing = this.activityFollow;
|
|
430
|
+
this.activityFollow = false;
|
|
431
|
+
const current = wasFollowing || this.activityCursor < 0
|
|
432
|
+
? total - 1
|
|
433
|
+
: Math.max(0, Math.min(this.activityCursor, total - 1));
|
|
434
|
+
const next = Math.max(0, Math.min(total - 1, current + dir));
|
|
435
|
+
this.activityCursor = next;
|
|
436
|
+
this.ensureActivityCursorVisible();
|
|
437
|
+
}
|
|
438
|
+
ensureActivityCursorVisible() {
|
|
439
|
+
const total = this.getActivityEntries().length;
|
|
440
|
+
const viewport = TerminalDashboard.ACTIVITY_VIEWPORT;
|
|
441
|
+
const maxStart = Math.max(0, total - viewport);
|
|
442
|
+
let start = this.activityAnchoredStart ?? 0;
|
|
443
|
+
if (this.activityCursor < start)
|
|
444
|
+
start = this.activityCursor;
|
|
445
|
+
if (this.activityCursor > start + viewport - 1)
|
|
446
|
+
start = this.activityCursor - viewport + 1;
|
|
447
|
+
this.activityAnchoredStart = Math.max(0, Math.min(maxStart, start));
|
|
448
|
+
}
|
|
449
|
+
scrollActivityDetail(dir) {
|
|
450
|
+
const body = this.getActivityDetailBody();
|
|
451
|
+
const maxScroll = Math.max(0, body.length - TerminalDashboard.ACTIVITY_VIEWPORT);
|
|
452
|
+
this.activityDetailScroll = Math.max(0, Math.min(maxScroll, this.activityDetailScroll + dir));
|
|
453
|
+
}
|
|
454
|
+
getActivityEntries() {
|
|
455
|
+
if (this.opts.fetchActivity) {
|
|
456
|
+
return this.lastActivityForId === this.detailId ? this.lastActivityEvents : [];
|
|
457
|
+
}
|
|
458
|
+
if (this.opts.activityStore && this.detailId) {
|
|
459
|
+
return this.opts.activityStore.recent(this.detailId, 500);
|
|
460
|
+
}
|
|
461
|
+
return [];
|
|
462
|
+
}
|
|
463
|
+
getActivityMeta() {
|
|
464
|
+
if (this.opts.state && this.detailId) {
|
|
465
|
+
const entry = this.opts.state().running.get(this.detailId);
|
|
466
|
+
if (entry) {
|
|
467
|
+
return {
|
|
468
|
+
identifier: entry.task_identifier,
|
|
469
|
+
agent: entry.agent,
|
|
470
|
+
model: entry.model,
|
|
471
|
+
variant: entry.variant,
|
|
472
|
+
turn: entry.turn_count,
|
|
473
|
+
tokens: entry.total_tokens,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const snap = this.lastSnapshot;
|
|
478
|
+
if (snap && this.detailId) {
|
|
479
|
+
const row = snap.running.find((e) => e.task_id === this.detailId);
|
|
480
|
+
if (row) {
|
|
481
|
+
return {
|
|
482
|
+
identifier: row.task_identifier,
|
|
483
|
+
agent: row.agent,
|
|
484
|
+
model: row.model,
|
|
485
|
+
variant: row.variant,
|
|
486
|
+
turn: row.turn_count,
|
|
487
|
+
tokens: row.tokens.total_tokens,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
const direct = (snap.direct ?? []).find((d) => d.id === this.detailId);
|
|
491
|
+
if (direct) {
|
|
492
|
+
return {
|
|
493
|
+
identifier: direct.name ?? direct.project ?? direct.path,
|
|
494
|
+
agent: direct.agent,
|
|
495
|
+
model: direct.model,
|
|
496
|
+
variant: direct.variant,
|
|
497
|
+
turn: direct.turns,
|
|
498
|
+
tokens: direct.total_tokens,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
scrollConfig(dir) {
|
|
505
|
+
const view = this.lastConfigView;
|
|
506
|
+
if (!view)
|
|
507
|
+
return;
|
|
508
|
+
const viewport = TerminalDashboard.CONFIG_VIEWPORT;
|
|
509
|
+
const maxStart = Math.max(0, this.configLineCount() - viewport);
|
|
510
|
+
this.configScrollOffset = Math.max(0, Math.min(maxStart, this.configScrollOffset + dir));
|
|
511
|
+
}
|
|
512
|
+
configLineCount() {
|
|
513
|
+
const view = this.lastConfigView;
|
|
514
|
+
return view ? this.buildConfigLines(view).length : 0;
|
|
515
|
+
}
|
|
516
|
+
scrollLogs(dir) {
|
|
517
|
+
const wasFollowing = this.logFollow;
|
|
518
|
+
this.logFollow = false;
|
|
519
|
+
const entries = this.getLogEntries();
|
|
520
|
+
const total = entries.length;
|
|
521
|
+
const maxStart = this.logMaxStart(total);
|
|
522
|
+
const currentStart = wasFollowing ? maxStart : this.logPinnedStart(entries, maxStart);
|
|
523
|
+
const next = Math.max(0, Math.min(maxStart, currentStart + dir));
|
|
524
|
+
this.logPinnedTop = entries[next] ?? null;
|
|
525
|
+
}
|
|
526
|
+
toggleLogFollow() {
|
|
527
|
+
if (this.logFollow) {
|
|
528
|
+
const entries = this.getLogEntries();
|
|
529
|
+
if (entries.length === 0)
|
|
530
|
+
return;
|
|
531
|
+
this.logPinnedTop = entries[this.logMaxStart(entries.length)] ?? null;
|
|
532
|
+
this.logFollow = false;
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
this.logFollow = true;
|
|
536
|
+
this.logPinnedTop = null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
toggleActivityFollow() {
|
|
540
|
+
if (this.activityFollow) {
|
|
541
|
+
const entries = this.getActivityEntries();
|
|
542
|
+
if (entries.length === 0)
|
|
543
|
+
return;
|
|
544
|
+
this.activityAnchoredStart = Math.max(0, entries.length - TerminalDashboard.ACTIVITY_VIEWPORT);
|
|
545
|
+
this.activityFollow = false;
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
this.activityFollow = true;
|
|
549
|
+
this.activityAnchoredStart = null;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
logMaxStart(total) {
|
|
553
|
+
return Math.max(0, total - TerminalDashboard.LOG_VIEWPORT);
|
|
554
|
+
}
|
|
555
|
+
logPinnedStart(entries, maxStart) {
|
|
556
|
+
const pinned = this.logPinnedTop;
|
|
557
|
+
if (pinned) {
|
|
558
|
+
const idx = entries.indexOf(pinned);
|
|
559
|
+
if (idx !== -1)
|
|
560
|
+
return Math.min(idx, maxStart);
|
|
561
|
+
}
|
|
562
|
+
this.logPinnedTop = entries[0] ?? null;
|
|
563
|
+
return 0;
|
|
564
|
+
}
|
|
565
|
+
jumpMatch(dir) {
|
|
566
|
+
const entries = this.getLogEntries();
|
|
567
|
+
if (entries.length === 0 || !this.searchQuery)
|
|
568
|
+
return;
|
|
569
|
+
const query = this.searchQuery.toLowerCase();
|
|
570
|
+
const matches = [];
|
|
571
|
+
for (let i = 0; i < entries.length; i++) {
|
|
572
|
+
if (entries[i]?.msg.toLowerCase().includes(query))
|
|
573
|
+
matches.push(i);
|
|
574
|
+
}
|
|
575
|
+
if (matches.length === 0)
|
|
576
|
+
return;
|
|
577
|
+
const maxStart = this.logMaxStart(entries.length);
|
|
578
|
+
const currentTop = this.logFollow ? maxStart : this.logPinnedStart(entries, maxStart);
|
|
579
|
+
let next;
|
|
580
|
+
if (dir > 0) {
|
|
581
|
+
next = matches.find((m) => m > currentTop);
|
|
582
|
+
if (next === undefined)
|
|
583
|
+
next = matches[0];
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
587
|
+
const m = matches[i];
|
|
588
|
+
if (m !== undefined && m < currentTop) {
|
|
589
|
+
next = m;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (next === undefined)
|
|
594
|
+
next = matches[matches.length - 1];
|
|
595
|
+
}
|
|
596
|
+
if (next !== undefined) {
|
|
597
|
+
this.logFollow = false;
|
|
598
|
+
this.logPinnedTop = entries[Math.max(0, Math.min(maxStart, next))] ?? null;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
getLogEntries() {
|
|
602
|
+
if (!this.opts.logBuffer)
|
|
603
|
+
return [];
|
|
604
|
+
const all = this.opts.logBuffer.recent(200);
|
|
605
|
+
const levelPriority = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
606
|
+
const minPriority = levelPriority[this.logLevelFilter];
|
|
607
|
+
const filtered = all.filter((e) => levelPriority[e.level] >= minPriority);
|
|
608
|
+
if (this.searchFilterOnly && this.searchQuery) {
|
|
609
|
+
const q = this.searchQuery.toLowerCase();
|
|
610
|
+
return filtered.filter((e) => e.msg.toLowerCase().includes(q));
|
|
611
|
+
}
|
|
612
|
+
return filtered;
|
|
613
|
+
}
|
|
614
|
+
getFocusedItems() {
|
|
615
|
+
const snap = this.lastSnapshot;
|
|
616
|
+
if (!snap)
|
|
617
|
+
return [];
|
|
618
|
+
if (this.focus === "running") {
|
|
619
|
+
return snap.running.map((e) => ({ id: e.task_id }));
|
|
620
|
+
}
|
|
621
|
+
if (this.focus === "direct") {
|
|
622
|
+
return (snap.direct ?? []).map((d) => ({ id: d.id }));
|
|
623
|
+
}
|
|
624
|
+
return snap.retrying.map((e) => ({ id: e.task_id }));
|
|
625
|
+
}
|
|
626
|
+
setupStdin() {
|
|
627
|
+
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
628
|
+
process.stdin.setRawMode(true);
|
|
629
|
+
process.stdin.resume();
|
|
630
|
+
process.stdin.on("data", this.onStdinData);
|
|
631
|
+
this.stdinActive = true;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
teardownStdin() {
|
|
635
|
+
if (this.stdinActive) {
|
|
636
|
+
process.stdin.removeListener("data", this.onStdinData);
|
|
637
|
+
process.stdin.setRawMode(false);
|
|
638
|
+
process.stdin.pause();
|
|
639
|
+
this.stdinActive = false;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
onStdinData = (data) => {
|
|
643
|
+
this.handleKey(data.toString());
|
|
644
|
+
};
|
|
645
|
+
doRender() {
|
|
646
|
+
if (this.opts.fetchSnapshot) {
|
|
647
|
+
if (this.renderInFlight) {
|
|
648
|
+
this.renderQueued = true;
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
this.renderInFlight = true;
|
|
652
|
+
void this.renderAsync().finally(() => {
|
|
653
|
+
this.renderInFlight = false;
|
|
654
|
+
if (this.renderQueued) {
|
|
655
|
+
this.renderQueued = false;
|
|
656
|
+
this.doRender();
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
this.renderSync();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
snapshotExtras() {
|
|
665
|
+
return {
|
|
666
|
+
direct: this.opts.directSessions?.() ?? [],
|
|
667
|
+
directTotals: this.opts.directTotals?.(),
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
renderSync() {
|
|
671
|
+
if (!this.opts.state)
|
|
672
|
+
return;
|
|
673
|
+
try {
|
|
674
|
+
const snap = buildSnapshot(this.opts.state(), this.snapshotExtras());
|
|
675
|
+
if (this.mode === "config") {
|
|
676
|
+
const configView = this.opts.configView ? this.opts.configView() : null;
|
|
677
|
+
if (configView) {
|
|
678
|
+
syncLocaleFromConfig(configView);
|
|
679
|
+
this.lastConfigView = configView;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
this.renderSnapshot(snap);
|
|
683
|
+
}
|
|
684
|
+
catch (e) {
|
|
685
|
+
this.opts.logger.warn("tui render failed", { error: String(e) });
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
async getSnapshot() {
|
|
689
|
+
if (this.opts.fetchSnapshot) {
|
|
690
|
+
return await this.opts.fetchSnapshot();
|
|
691
|
+
}
|
|
692
|
+
if (this.opts.state) {
|
|
693
|
+
return buildSnapshot(this.opts.state(), this.snapshotExtras());
|
|
694
|
+
}
|
|
695
|
+
return this.emptySnapshot();
|
|
696
|
+
}
|
|
697
|
+
async getConfigView() {
|
|
698
|
+
if (this.opts.fetchConfig) {
|
|
699
|
+
const view = await this.opts.fetchConfig();
|
|
700
|
+
if (view)
|
|
701
|
+
syncLocaleFromConfig(view);
|
|
702
|
+
return view;
|
|
703
|
+
}
|
|
704
|
+
if (this.opts.configView) {
|
|
705
|
+
const view = this.opts.configView();
|
|
706
|
+
syncLocaleFromConfig(view);
|
|
707
|
+
return view;
|
|
708
|
+
}
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
async renderAsync() {
|
|
712
|
+
try {
|
|
713
|
+
const snap = await this.getSnapshot();
|
|
714
|
+
const configView = this.mode === "config" ? await this.getConfigView() : null;
|
|
715
|
+
if (configView)
|
|
716
|
+
this.lastConfigView = configView;
|
|
717
|
+
if ((this.mode === "activity" || this.mode === "activity-detail") &&
|
|
718
|
+
this.detailId &&
|
|
719
|
+
this.opts.fetchActivity) {
|
|
720
|
+
try {
|
|
721
|
+
this.lastActivityEvents = await this.opts.fetchActivity(this.detailId);
|
|
722
|
+
this.lastActivityForId = this.detailId;
|
|
723
|
+
}
|
|
724
|
+
catch (e) {
|
|
725
|
+
this.opts.logger.warn("tui activity fetch failed", { error: String(e) });
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
this.renderSnapshot(snap);
|
|
729
|
+
}
|
|
730
|
+
catch (e) {
|
|
731
|
+
this.opts.logger.warn("tui render failed", { error: String(e) });
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
renderSnapshot(snap) {
|
|
735
|
+
this.lastSnapshot = snap;
|
|
736
|
+
this.spinnerFrame = (this.spinnerFrame + 1) % SPINNER_FRAMES.length;
|
|
737
|
+
const now = Date.now();
|
|
738
|
+
const currentTotal = snap.totals.total_tokens;
|
|
739
|
+
this.tokenSamples = this.updateSamples(this.tokenSamples, now, currentTotal);
|
|
740
|
+
const tps = this.computeTps(this.tokenSamples, now, currentTotal);
|
|
741
|
+
if (this.mode === "overview") {
|
|
742
|
+
if (this.focus === "direct" && this.directItems().length === 0) {
|
|
743
|
+
this.focus = "running";
|
|
744
|
+
this.selectedIndex = 0;
|
|
745
|
+
this.selectedId = null;
|
|
746
|
+
}
|
|
747
|
+
const items = this.getFocusedItems();
|
|
748
|
+
if (items.length === 0) {
|
|
749
|
+
this.selectedIndex = 0;
|
|
750
|
+
this.selectedId = null;
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
const idx = this.indexOfSelected(items);
|
|
754
|
+
this.selectedIndex = idx;
|
|
755
|
+
this.selectedId = items[idx]?.id ?? null;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const content = this.mode === "overview"
|
|
759
|
+
? this.formatOverview(snap, tps, now)
|
|
760
|
+
: this.mode === "logs"
|
|
761
|
+
? this.formatLogs()
|
|
762
|
+
: this.mode === "config"
|
|
763
|
+
? this.formatConfig()
|
|
764
|
+
: this.mode === "activity"
|
|
765
|
+
? this.formatActivity()
|
|
766
|
+
: this.mode === "activity-detail"
|
|
767
|
+
? this.formatActivityDetail()
|
|
768
|
+
: this.formatDetail(now);
|
|
769
|
+
if (content === this.lastRenderedContent &&
|
|
770
|
+
now - this.lastRenderedAt < TerminalDashboard.MIN_RERENDER_MS) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
this.renderFn(content);
|
|
774
|
+
this.lastRenderedContent = content;
|
|
775
|
+
this.lastRenderedAt = now;
|
|
776
|
+
}
|
|
777
|
+
formatOverview(snap, tps, now) {
|
|
778
|
+
const lines = [];
|
|
779
|
+
const agentCount = snap.counts.running;
|
|
780
|
+
const maxAgents = snap.max_concurrent_agents;
|
|
781
|
+
const runtime = this.formatRuntime(snap.totals.seconds_running);
|
|
782
|
+
const tokens = snap.totals;
|
|
783
|
+
const url = this.opts.dashboardUrl ?? null;
|
|
784
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}·${RESET} ${DIM}${runtime}${RESET}`);
|
|
785
|
+
if (url) {
|
|
786
|
+
lines.push(`${GRAY}│ ${DIM}Dashboard: ${url}${RESET}`);
|
|
787
|
+
}
|
|
788
|
+
lines.push(`│ Agents: ${this.progressBar(agentCount, maxAgents)}`);
|
|
789
|
+
lines.push(`│ ${DIM}Tokens: ${RESET}in ${this.formatCount(tokens.input_tokens)} ${GRAY}|${RESET} out ${this.formatCount(tokens.output_tokens)} ${GRAY}|${RESET} total ${this.formatCount(tokens.total_tokens)} ${GRAY}·${RESET} Throughput: ${this.formatTps(tps)} tps`);
|
|
790
|
+
const runningFocused = this.focus === "running";
|
|
791
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
792
|
+
const runHeader = runningFocused
|
|
793
|
+
? `${CYAN}├─ ${GREEN}●${RESET} Running ${BOLD}◄${RESET}`
|
|
794
|
+
: `${CYAN}├─ ${GREEN}●${RESET} Running${RESET}`;
|
|
795
|
+
lines.push(runHeader);
|
|
796
|
+
if (snap.running.length === 0) {
|
|
797
|
+
lines.push(`${GRAY}│ ${DIM}No active agents${RESET}`);
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
lines.push(`${GRAY}│ ${DIM}ID STATE AGE/TURN TOKENS SESSION EVENT${RESET}`);
|
|
801
|
+
let i = 0;
|
|
802
|
+
for (const entry of snap.running) {
|
|
803
|
+
const ageSeconds = (now - entry.started_at) / 1000;
|
|
804
|
+
const age = this.formatRuntime(ageSeconds);
|
|
805
|
+
const ageColor = ageSeconds < 300 ? GREEN : ageSeconds < 1800 ? YELLOW : RED;
|
|
806
|
+
const session = this.compactSession(entry.session_id);
|
|
807
|
+
const event = entry.last_event ?? "none";
|
|
808
|
+
const spinner = SPINNER_FRAMES[this.spinnerFrame % SPINNER_FRAMES.length] ?? "⠋";
|
|
809
|
+
const cursor = runningFocused && i === this.selectedIndex
|
|
810
|
+
? `${CYAN}${spinner}${RESET} `
|
|
811
|
+
: `${GRAY} ${RESET} `;
|
|
812
|
+
lines.push(`${GRAY}│${RESET} ${cursor}${this.pad(entry.task_identifier, 11)} ${this.pad(entry.state, 15)} ${ageColor}${this.pad(`${age}/${entry.turn_count}`, 11)}${RESET} ${this.pad(String(this.formatCount(entry.tokens.total_tokens)), 10)} ${this.pad(session, 11)} ${event}`);
|
|
813
|
+
i++;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
const backoffFocused = this.focus === "backoff";
|
|
817
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
818
|
+
const backoffHeader = backoffFocused
|
|
819
|
+
? `${CYAN}├─ ${GRAY}●${RESET} Backoff queue ${BOLD}◄${RESET}`
|
|
820
|
+
: `${CYAN}├─ ${GRAY}●${RESET} Backoff queue${RESET}`;
|
|
821
|
+
lines.push(backoffHeader);
|
|
822
|
+
if (snap.retrying.length === 0) {
|
|
823
|
+
lines.push(`${GRAY}│ ${DIM}No queued retries${RESET}`);
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
let i = 0;
|
|
827
|
+
for (const entry of snap.retrying) {
|
|
828
|
+
const dueIn = Math.max(0, (entry.due_at - now) / 1000);
|
|
829
|
+
const err = entry.error ? ` ${RED}error=${entry.error.slice(0, 50)}${RESET}` : "";
|
|
830
|
+
const cursor = backoffFocused && i === this.selectedIndex ? `${YELLOW}↻${RESET} ` : `${GRAY} ${RESET} `;
|
|
831
|
+
lines.push(`${GRAY}│${RESET} ${cursor}${entry.task_identifier} attempt=${entry.attempt} in ${dueIn.toFixed(1)}s${err}`);
|
|
832
|
+
i++;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const direct = snap.direct ?? [];
|
|
836
|
+
if (direct.length > 0) {
|
|
837
|
+
const directFocused = this.focus === "direct";
|
|
838
|
+
const runningCount = direct.filter((d) => d.status === "running").length;
|
|
839
|
+
const countTag = runningCount > 0 ? `(${direct.length} · ${runningCount} running)` : `(${direct.length})`;
|
|
840
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
841
|
+
const directHeader = directFocused
|
|
842
|
+
? `${CYAN}├─ ${MAGENTA}●${RESET} Direct sessions ${countTag} ${BOLD}◄${RESET}`
|
|
843
|
+
: `${CYAN}├─ ${MAGENTA}●${RESET} Direct sessions ${countTag}${RESET}`;
|
|
844
|
+
lines.push(directHeader);
|
|
845
|
+
lines.push(`${GRAY}│ ${DIM}NAME STATUS AGE TOKENS QUEUE${RESET}`);
|
|
846
|
+
let i = 0;
|
|
847
|
+
for (const entry of direct) {
|
|
848
|
+
const age = entry.updated_at > 0 ? this.formatRuntime((now - entry.updated_at) / 1000) : "n/a";
|
|
849
|
+
const status = entry.status === "running" ? "running" : "idle";
|
|
850
|
+
const statusColored = entry.status === "running"
|
|
851
|
+
? `${GREEN}${status.padEnd(9)}${RESET}`
|
|
852
|
+
: `${YELLOW}${status.padEnd(9)}${RESET}`;
|
|
853
|
+
const label = entry.name ?? entry.project ?? entry.path;
|
|
854
|
+
const spinner = SPINNER_FRAMES[this.spinnerFrame % SPINNER_FRAMES.length] ?? "⠋";
|
|
855
|
+
const cursor = directFocused && i === this.selectedIndex
|
|
856
|
+
? `${CYAN}${spinner}${RESET} `
|
|
857
|
+
: `${GRAY} ${RESET} `;
|
|
858
|
+
lines.push(`${GRAY}│${RESET} ${cursor}${this.pad(label, 16)} ${statusColored} ${this.pad(age, 10)} ${this.pad(this.formatCount(entry.total_tokens), 10)} ${entry.queued}`);
|
|
859
|
+
i++;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
863
|
+
lines.push(`${CYAN}├─ Throughput (10min)${RESET}`);
|
|
864
|
+
lines.push(`│ ${this.sparkline(this.tokenSamples, now, snap.totals.total_tokens)}`);
|
|
865
|
+
if (this.opts.logBuffer) {
|
|
866
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
867
|
+
const levelTag = this.logLevelFilter === "debug" ? "Logs" : `Logs [${this.logLevelFilter}]`;
|
|
868
|
+
lines.push(`${CYAN}├─ ${levelTag}${RESET}`);
|
|
869
|
+
const entries = this.getLogEntries().slice(-10);
|
|
870
|
+
if (entries.length === 0) {
|
|
871
|
+
lines.push(`${GRAY}│ ${DIM}No recent logs${RESET}`);
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
for (const entry of entries) {
|
|
875
|
+
const time = entry.ts.slice(11, 19);
|
|
876
|
+
const color = entry.level === "error"
|
|
877
|
+
? RED
|
|
878
|
+
: entry.level === "warn"
|
|
879
|
+
? YELLOW
|
|
880
|
+
: entry.level === "debug"
|
|
881
|
+
? GRAY
|
|
882
|
+
: "";
|
|
883
|
+
const reset = color ? RESET : "";
|
|
884
|
+
const msg = this.logLineText(entry, Math.max(60, this.terminalWidthFn() - 26));
|
|
885
|
+
lines.push(`${GRAY}│${RESET} ${GRAY}${time}${RESET} ${color}${entry.level.toUpperCase().padEnd(5)}${reset} ${msg}`);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
890
|
+
const logHint = this.opts.logBuffer ? " · L logs" : "";
|
|
891
|
+
const configHint = this.hasConfigSource() ? " · C config" : "";
|
|
892
|
+
lines.push(`${GRAY}│ ${DIM}↑↓ navigate · ←/→ or Tab switch · Enter details${logHint}${configHint} · Esc/q back · Ctrl-C exit${RESET}`);
|
|
893
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
894
|
+
return this.compose(lines);
|
|
895
|
+
}
|
|
896
|
+
compose(lines) {
|
|
897
|
+
const prefix = this.altScreenActive ? CURSOR_HOME : "";
|
|
898
|
+
const body = lines.map((l) => `${l}${CLEAR_LINE}`).join("\n");
|
|
899
|
+
return `${prefix}${body}\n${CLEAR_BELOW}`;
|
|
900
|
+
}
|
|
901
|
+
formatDetail(now) {
|
|
902
|
+
if (this.mode === "detail-running") {
|
|
903
|
+
return this.formatRunningDetail(now);
|
|
904
|
+
}
|
|
905
|
+
if (this.mode === "detail-direct") {
|
|
906
|
+
return this.formatDirectDetail(now);
|
|
907
|
+
}
|
|
908
|
+
return this.formatRetryDetail(now);
|
|
909
|
+
}
|
|
910
|
+
formatRunningDetail(now) {
|
|
911
|
+
if (this.opts.state) {
|
|
912
|
+
return this.formatRunningDetailFromState(now);
|
|
913
|
+
}
|
|
914
|
+
return this.formatRunningDetailFromSnapshot(now);
|
|
915
|
+
}
|
|
916
|
+
fieldLines(label, value) {
|
|
917
|
+
const labelColon = `${label}:`;
|
|
918
|
+
const head = `│ ${DIM}${labelColon}${RESET}${" ".repeat(Math.max(0, 14 - labelColon.length))}`;
|
|
919
|
+
const cont = `│${" ".repeat(16)}`;
|
|
920
|
+
const wrapped = wrapToWidth(value, 34);
|
|
921
|
+
if (wrapped.length === 0)
|
|
922
|
+
return [head];
|
|
923
|
+
return wrapped.map((line, i) => (i === 0 ? `${head}${line}` : `${cont}${line}`));
|
|
924
|
+
}
|
|
925
|
+
logLineText(entry, maxChars) {
|
|
926
|
+
const fields = Object.entries(entry.fields ?? {});
|
|
927
|
+
if (fields.length === 0) {
|
|
928
|
+
return entry.msg.length > maxChars ? `${entry.msg.slice(0, maxChars)}…` : entry.msg;
|
|
929
|
+
}
|
|
930
|
+
const ordered = fields.sort((a, b) => logFieldPriority(b[0], b[1]) - logFieldPriority(a[0], a[1]));
|
|
931
|
+
const suffix = ordered.map(([key, value]) => `${key}=${logFieldText(value)}`).join(" ");
|
|
932
|
+
const text = `${entry.msg} ${suffix}`;
|
|
933
|
+
return text.length > maxChars ? `${text.slice(0, maxChars)}…` : text;
|
|
934
|
+
}
|
|
935
|
+
pushDetailFields(lines, fields) {
|
|
936
|
+
for (const [label, value] of fields) {
|
|
937
|
+
for (const line of this.fieldLines(label, value)) {
|
|
938
|
+
lines.push(line);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
formatRunningDetailFromState(now) {
|
|
943
|
+
const state = this.opts.state?.();
|
|
944
|
+
if (!state) {
|
|
945
|
+
this.exitDetail();
|
|
946
|
+
return this.formatOverview(this.emptySnapshot(), 0, now);
|
|
947
|
+
}
|
|
948
|
+
const entry = this.detailId ? state.running.get(this.detailId) : null;
|
|
949
|
+
if (!entry) {
|
|
950
|
+
this.exitDetail();
|
|
951
|
+
return this.formatOverview(buildSnapshot(state), 0, now);
|
|
952
|
+
}
|
|
953
|
+
const task = entry.task;
|
|
954
|
+
const age = this.formatRuntime((now - entry.started_at) / 1000);
|
|
955
|
+
const lines = [];
|
|
956
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}${task.identifier}${RESET}`);
|
|
957
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
958
|
+
this.pushDetailFields(lines, [
|
|
959
|
+
["Title", task.title],
|
|
960
|
+
["State", task.state],
|
|
961
|
+
["Assignee", task.assignee ?? "n/a"],
|
|
962
|
+
["Priority", String(task.priority ?? "n/a")],
|
|
963
|
+
["Source", task.source],
|
|
964
|
+
...(task.url ? [["URL", task.url]] : []),
|
|
965
|
+
...(task.branch_name ? [["Branch", task.branch_name]] : []),
|
|
966
|
+
]);
|
|
967
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
968
|
+
this.pushDetailFields(lines, [
|
|
969
|
+
["Workspace", entry.workspace_path],
|
|
970
|
+
["Session", entry.session_id ?? "n/a"],
|
|
971
|
+
["Agent", entry.agent ?? "n/a"],
|
|
972
|
+
["Model", entry.model ?? "n/a"],
|
|
973
|
+
...(entry.variant != null ? [["Variant", entry.variant]] : []),
|
|
974
|
+
["Started", `${age} ago`],
|
|
975
|
+
["Turn", String(entry.turn_count)],
|
|
976
|
+
["Last event", entry.last_event ?? "none"],
|
|
977
|
+
]);
|
|
978
|
+
if (entry.last_message) {
|
|
979
|
+
this.pushDetailFields(lines, [["Last message", entry.last_message]]);
|
|
980
|
+
}
|
|
981
|
+
if (entry.retry_attempt !== null) {
|
|
982
|
+
this.pushDetailFields(lines, [["Retry", `attempt ${entry.retry_attempt}`]]);
|
|
983
|
+
}
|
|
984
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
985
|
+
lines.push(`│ ${DIM}Tokens:${RESET} in ${this.formatCount(entry.input_tokens)} ${GRAY}|${RESET} out ${this.formatCount(entry.output_tokens)} ${GRAY}|${RESET} total ${this.formatCount(entry.total_tokens)}`);
|
|
986
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
987
|
+
if (task.labels.length > 0) {
|
|
988
|
+
this.pushDetailFields(lines, [["Labels", task.labels.join(", ")]]);
|
|
989
|
+
}
|
|
990
|
+
if (task.blocked_by.length > 0) {
|
|
991
|
+
const blockers = task.blocked_by.map((b) => b.identifier ?? b.id ?? "?").join(", ");
|
|
992
|
+
this.pushDetailFields(lines, [["Blocked by", blockers]]);
|
|
993
|
+
}
|
|
994
|
+
let descTruncated = false;
|
|
995
|
+
if (task.description) {
|
|
996
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
997
|
+
lines.push(`│ ${DIM}Description:${RESET}`);
|
|
998
|
+
const descLines = task.description.split("\n");
|
|
999
|
+
while (descLines[descLines.length - 1] === "") {
|
|
1000
|
+
descLines.pop();
|
|
1001
|
+
}
|
|
1002
|
+
const descWrapped = [];
|
|
1003
|
+
for (const line of descLines) {
|
|
1004
|
+
for (const w of wrapToWidth(line, 48)) {
|
|
1005
|
+
descWrapped.push(w);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
descTruncated = descWrapped.length > DESCRIPTION_FOLD_LINES;
|
|
1009
|
+
const collapsed = descTruncated && !this.descExpanded;
|
|
1010
|
+
const shown = collapsed ? descWrapped.slice(0, DESCRIPTION_FOLD_LINES) : descWrapped;
|
|
1011
|
+
for (const line of shown) {
|
|
1012
|
+
lines.push(`${GRAY}│${RESET} ${line}`);
|
|
1013
|
+
}
|
|
1014
|
+
if (collapsed) {
|
|
1015
|
+
lines.push(`${GRAY}│${RESET} ${DIM}… (${descWrapped.length - DESCRIPTION_FOLD_LINES} more lines)${RESET}`);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1019
|
+
const detailHints = ["Esc/q back", "a activity"];
|
|
1020
|
+
if (descTruncated) {
|
|
1021
|
+
detailHints.push(this.descExpanded ? "e collapse" : "e expand");
|
|
1022
|
+
}
|
|
1023
|
+
lines.push(`${GRAY}│ ${DIM}${detailHints.join(" · ")}${RESET}`);
|
|
1024
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1025
|
+
return this.compose(lines);
|
|
1026
|
+
}
|
|
1027
|
+
formatRunningDetailFromSnapshot(now) {
|
|
1028
|
+
const snap = this.lastSnapshot;
|
|
1029
|
+
if (!snap) {
|
|
1030
|
+
this.exitDetail();
|
|
1031
|
+
return this.formatOverview(this.emptySnapshot(), 0, now);
|
|
1032
|
+
}
|
|
1033
|
+
const entry = snap.running.find((e) => e.task_id === this.detailId);
|
|
1034
|
+
if (!entry) {
|
|
1035
|
+
this.exitDetail();
|
|
1036
|
+
return this.formatOverview(snap, 0, now);
|
|
1037
|
+
}
|
|
1038
|
+
const age = this.formatRuntime((now - entry.started_at) / 1000);
|
|
1039
|
+
const lines = [];
|
|
1040
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}${entry.task_identifier}${RESET}`);
|
|
1041
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1042
|
+
this.pushDetailFields(lines, [
|
|
1043
|
+
["State", entry.state],
|
|
1044
|
+
["Workspace", entry.workspace_path],
|
|
1045
|
+
["Session", entry.session_id ?? "n/a"],
|
|
1046
|
+
["Agent", entry.agent ?? "n/a"],
|
|
1047
|
+
["Model", entry.model ?? "n/a"],
|
|
1048
|
+
...(entry.variant != null ? [["Variant", entry.variant]] : []),
|
|
1049
|
+
["Started", `${age} ago`],
|
|
1050
|
+
["Turn", String(entry.turn_count)],
|
|
1051
|
+
["Last event", entry.last_event ?? "none"],
|
|
1052
|
+
]);
|
|
1053
|
+
if (entry.last_message) {
|
|
1054
|
+
this.pushDetailFields(lines, [["Last message", entry.last_message]]);
|
|
1055
|
+
}
|
|
1056
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1057
|
+
lines.push(`│ ${DIM}Tokens:${RESET} in ${this.formatCount(entry.tokens.input_tokens)} ${GRAY}|${RESET} out ${this.formatCount(entry.tokens.output_tokens)} ${GRAY}|${RESET} total ${this.formatCount(entry.tokens.total_tokens)}`);
|
|
1058
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1059
|
+
lines.push(`${GRAY}│ ${DIM}Esc/q back · a activity${RESET}`);
|
|
1060
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1061
|
+
return this.compose(lines);
|
|
1062
|
+
}
|
|
1063
|
+
formatDirectDetail(now) {
|
|
1064
|
+
const snap = this.lastSnapshot;
|
|
1065
|
+
const entry = snap?.direct?.find((d) => d.id === this.detailId);
|
|
1066
|
+
if (!snap || !entry) {
|
|
1067
|
+
this.exitDetail();
|
|
1068
|
+
return this.formatOverview(snap ?? this.emptySnapshot(), 0, now);
|
|
1069
|
+
}
|
|
1070
|
+
const age = entry.updated_at > 0 ? `${this.formatRuntime((now - entry.updated_at) / 1000)} ago` : "n/a";
|
|
1071
|
+
const lines = [];
|
|
1072
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}${entry.name ?? entry.project ?? entry.path}${RESET} ${GRAY}(feishu direct)${RESET}`);
|
|
1073
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1074
|
+
this.pushDetailFields(lines, [
|
|
1075
|
+
["Status", entry.status],
|
|
1076
|
+
["Session", entry.session_id ?? "n/a"],
|
|
1077
|
+
["Directory", entry.path],
|
|
1078
|
+
["Agent", entry.agent ?? "n/a"],
|
|
1079
|
+
["Model", entry.model ?? "n/a"],
|
|
1080
|
+
...(entry.variant != null ? [["Variant", entry.variant]] : []),
|
|
1081
|
+
["Turns", String(entry.turns)],
|
|
1082
|
+
["Queued", String(entry.queued)],
|
|
1083
|
+
["Updated", age],
|
|
1084
|
+
]);
|
|
1085
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1086
|
+
lines.push(`│ ${DIM}Tokens:${RESET} in ${this.formatCount(entry.input_tokens)} ${GRAY}|${RESET} out ${this.formatCount(entry.output_tokens)} ${GRAY}|${RESET} total ${this.formatCount(entry.total_tokens)}`);
|
|
1087
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1088
|
+
lines.push(`${GRAY}│ ${DIM}Esc/q back · a activity${RESET}`);
|
|
1089
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1090
|
+
return this.compose(lines);
|
|
1091
|
+
}
|
|
1092
|
+
formatRetryDetail(now) {
|
|
1093
|
+
if (this.opts.state) {
|
|
1094
|
+
return this.formatRetryDetailFromState(now);
|
|
1095
|
+
}
|
|
1096
|
+
return this.formatRetryDetailFromSnapshot(now);
|
|
1097
|
+
}
|
|
1098
|
+
formatRetryDetailFromState(now) {
|
|
1099
|
+
const state = this.opts.state?.();
|
|
1100
|
+
if (!state) {
|
|
1101
|
+
this.exitDetail();
|
|
1102
|
+
return this.formatOverview(this.emptySnapshot(), 0, now);
|
|
1103
|
+
}
|
|
1104
|
+
const entry = this.detailId ? state.retry_attempts.get(this.detailId) : null;
|
|
1105
|
+
if (!entry) {
|
|
1106
|
+
this.exitDetail();
|
|
1107
|
+
return this.formatOverview(buildSnapshot(state), 0, now);
|
|
1108
|
+
}
|
|
1109
|
+
const dueIn = Math.max(0, (entry.due_at_ms - now) / 1000);
|
|
1110
|
+
const lines = [];
|
|
1111
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${YELLOW}retry${RESET}: ${BOLD}${entry.identifier}${RESET}`);
|
|
1112
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1113
|
+
this.pushDetailFields(lines, [
|
|
1114
|
+
["Identifier", entry.identifier],
|
|
1115
|
+
["Attempt", String(entry.attempt)],
|
|
1116
|
+
["Due in", `${dueIn.toFixed(1)}s`],
|
|
1117
|
+
["Continuation", entry.continuation ? "yes" : "no"],
|
|
1118
|
+
["Session", entry.session_id ?? "n/a"],
|
|
1119
|
+
]);
|
|
1120
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1121
|
+
if (entry.error) {
|
|
1122
|
+
lines.push(`│ ${RED}${DIM}Error:${RESET}`);
|
|
1123
|
+
const errLines = entry.error.split("\n").slice(0, 8);
|
|
1124
|
+
for (const el of errLines) {
|
|
1125
|
+
for (const wrapped of wrapToWidth(el, 48)) {
|
|
1126
|
+
lines.push(`${GRAY}│${RESET} ${RED}${wrapped}${RESET}`);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
lines.push(`│ ${DIM}No error recorded${RESET}`);
|
|
1132
|
+
}
|
|
1133
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1134
|
+
lines.push(`${GRAY}│ ${DIM}Esc/q back${RESET}`);
|
|
1135
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1136
|
+
return this.compose(lines);
|
|
1137
|
+
}
|
|
1138
|
+
formatRetryDetailFromSnapshot(now) {
|
|
1139
|
+
const snap = this.lastSnapshot;
|
|
1140
|
+
if (!snap) {
|
|
1141
|
+
this.exitDetail();
|
|
1142
|
+
return this.formatOverview(this.emptySnapshot(), 0, now);
|
|
1143
|
+
}
|
|
1144
|
+
const entry = snap.retrying.find((e) => e.task_id === this.detailId);
|
|
1145
|
+
if (!entry) {
|
|
1146
|
+
this.exitDetail();
|
|
1147
|
+
return this.formatOverview(snap, 0, now);
|
|
1148
|
+
}
|
|
1149
|
+
const dueIn = Math.max(0, (entry.due_at - now) / 1000);
|
|
1150
|
+
const lines = [];
|
|
1151
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${YELLOW}retry${RESET}: ${BOLD}${entry.task_identifier}${RESET}`);
|
|
1152
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1153
|
+
this.pushDetailFields(lines, [
|
|
1154
|
+
["Identifier", entry.task_identifier],
|
|
1155
|
+
["Attempt", String(entry.attempt)],
|
|
1156
|
+
["Due in", `${dueIn.toFixed(1)}s`],
|
|
1157
|
+
]);
|
|
1158
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1159
|
+
if (entry.error) {
|
|
1160
|
+
lines.push(`│ ${RED}${DIM}Error:${RESET}`);
|
|
1161
|
+
const errLines = entry.error.split("\n").slice(0, 8);
|
|
1162
|
+
for (const el of errLines) {
|
|
1163
|
+
for (const wrapped of wrapToWidth(el, 48)) {
|
|
1164
|
+
lines.push(`${GRAY}│${RESET} ${RED}${wrapped}${RESET}`);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
lines.push(`│ ${DIM}No error recorded${RESET}`);
|
|
1170
|
+
}
|
|
1171
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1172
|
+
lines.push(`${GRAY}│ ${DIM}Esc/q back${RESET}`);
|
|
1173
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1174
|
+
return this.compose(lines);
|
|
1175
|
+
}
|
|
1176
|
+
formatLogs() {
|
|
1177
|
+
const entries = this.getLogEntries();
|
|
1178
|
+
const total = entries.length;
|
|
1179
|
+
const viewport = TerminalDashboard.LOG_VIEWPORT;
|
|
1180
|
+
const maxStart = this.logMaxStart(total);
|
|
1181
|
+
let start;
|
|
1182
|
+
if (this.logFollow) {
|
|
1183
|
+
start = maxStart;
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
start = this.logPinnedStart(entries, maxStart);
|
|
1187
|
+
}
|
|
1188
|
+
const visible = entries.slice(start, start + viewport);
|
|
1189
|
+
const query = this.searchQuery.toLowerCase();
|
|
1190
|
+
const lines = [];
|
|
1191
|
+
const followTag = this.logFollow ? ` ${GREEN}[follow]${RESET}` : ` ${YELLOW}[paused]${RESET}`;
|
|
1192
|
+
const levelTag = ` ${CYAN}[${this.logLevelFilter}]${RESET}`;
|
|
1193
|
+
const searchTag = this.searchQuery
|
|
1194
|
+
? ` ${CYAN}/${this.searchQuery}${RESET}${this.searchFilterOnly ? `${GRAY}(only)${RESET}` : ""}`
|
|
1195
|
+
: "";
|
|
1196
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}Logs${RESET} ${GRAY}(${total} entries)${RESET}${followTag}${levelTag}${searchTag}`);
|
|
1197
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1198
|
+
if (visible.length === 0) {
|
|
1199
|
+
lines.push(`${GRAY}│ ${DIM}No log entries${RESET}`);
|
|
1200
|
+
}
|
|
1201
|
+
else {
|
|
1202
|
+
for (const entry of visible) {
|
|
1203
|
+
const time = entry.ts.slice(11, 19);
|
|
1204
|
+
const color = entry.level === "error"
|
|
1205
|
+
? RED
|
|
1206
|
+
: entry.level === "warn"
|
|
1207
|
+
? YELLOW
|
|
1208
|
+
: entry.level === "debug"
|
|
1209
|
+
? GRAY
|
|
1210
|
+
: "";
|
|
1211
|
+
const reset = color ? RESET : "";
|
|
1212
|
+
let msg = this.logLineText(entry, Math.max(60, this.terminalWidthFn() - 20));
|
|
1213
|
+
if (query && msg.toLowerCase().includes(query)) {
|
|
1214
|
+
msg = `${BOLD}${msg}${RESET}`;
|
|
1215
|
+
}
|
|
1216
|
+
lines.push(`${GRAY}│${RESET} ${GRAY}${time}${RESET} ${color}${entry.level.toUpperCase().padEnd(5)}${reset} ${msg}`);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1220
|
+
if (this.searchActive) {
|
|
1221
|
+
lines.push(`${CYAN}│ /${this.searchQuery}█${RESET}`);
|
|
1222
|
+
}
|
|
1223
|
+
const scrollInfo = this.logFollow
|
|
1224
|
+
? ""
|
|
1225
|
+
: ` ${GRAY}[${start}/${Math.max(0, total - viewport)}]${RESET}`;
|
|
1226
|
+
lines.push(`${GRAY}│ ${DIM}↑↓ scroll · Space/f pause · 1-4 level · / search · F filter-only · n/N match · Esc/q back${RESET}${scrollInfo}`);
|
|
1227
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1228
|
+
return this.compose(lines);
|
|
1229
|
+
}
|
|
1230
|
+
formatActivity() {
|
|
1231
|
+
const meta = this.getActivityMeta();
|
|
1232
|
+
const entries = this.getActivityEntries();
|
|
1233
|
+
const total = entries.length;
|
|
1234
|
+
const viewport = TerminalDashboard.ACTIVITY_VIEWPORT;
|
|
1235
|
+
let start;
|
|
1236
|
+
if (this.activityFollow) {
|
|
1237
|
+
start = Math.max(0, total - viewport);
|
|
1238
|
+
if (total > 0)
|
|
1239
|
+
this.activityCursor = total - 1;
|
|
1240
|
+
}
|
|
1241
|
+
else {
|
|
1242
|
+
const anchored = this.activityAnchoredStart ?? 0;
|
|
1243
|
+
start = Math.max(0, Math.min(anchored, Math.max(0, total - viewport)));
|
|
1244
|
+
}
|
|
1245
|
+
const visible = entries.slice(start, start + viewport);
|
|
1246
|
+
const lines = [];
|
|
1247
|
+
const ident = meta?.identifier ?? this.detailId ?? "?";
|
|
1248
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}Activity${RESET} ${GRAY}·${RESET} ${BOLD}${ident}${RESET}`);
|
|
1249
|
+
if (meta) {
|
|
1250
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1251
|
+
this.pushDetailFields(lines, [
|
|
1252
|
+
["Agent", meta.agent ?? "n/a"],
|
|
1253
|
+
["Model", meta.model ?? "n/a"],
|
|
1254
|
+
...(meta.variant != null ? [["Variant", meta.variant]] : []),
|
|
1255
|
+
["Turn", String(meta.turn)],
|
|
1256
|
+
["Tokens", this.formatCount(meta.tokens)],
|
|
1257
|
+
]);
|
|
1258
|
+
}
|
|
1259
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1260
|
+
if (visible.length === 0) {
|
|
1261
|
+
lines.push(`${GRAY}│ ${DIM}No activity events${RESET}`);
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
for (let i = 0; i < visible.length; i++) {
|
|
1265
|
+
const entry = visible[i];
|
|
1266
|
+
if (!entry)
|
|
1267
|
+
continue;
|
|
1268
|
+
const idx = start + i;
|
|
1269
|
+
const time = new Date(entry.ts).toISOString().slice(11, 19);
|
|
1270
|
+
const cursor = idx === this.activityCursor ? `${CYAN}❯${RESET} ` : `${GRAY} ${RESET} `;
|
|
1271
|
+
const prefix = `${GRAY}│${RESET} ${cursor}${GRAY}${time}${RESET} `;
|
|
1272
|
+
if (entry.type === "text" && entry.text !== undefined) {
|
|
1273
|
+
for (const wrapped of this.renderActivityText(entry.text)) {
|
|
1274
|
+
lines.push(`${prefix}${DIM}${wrapped}${RESET}`);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
else if (entry.type === "tool_use" && entry.tool !== undefined) {
|
|
1278
|
+
const failed = entry.exit !== undefined && entry.exit !== 0;
|
|
1279
|
+
const icon = failed ? "✗" : "🔧";
|
|
1280
|
+
const color = failed ? YELLOW : CYAN;
|
|
1281
|
+
const summary = truncateToWidth(this.toolCallSummary(entry), 35);
|
|
1282
|
+
lines.push(`${prefix}${color}${icon} ${summary}${RESET}`);
|
|
1283
|
+
}
|
|
1284
|
+
else if (entry.type === "step_finish" && entry.tokens) {
|
|
1285
|
+
lines.push(`${prefix}${GRAY}◷ tokens +${this.formatCount(entry.tokens.total)}${RESET}`);
|
|
1286
|
+
}
|
|
1287
|
+
else if (entry.type === "step_start") {
|
|
1288
|
+
lines.push(`${prefix}${GRAY}▶ step${RESET}`);
|
|
1289
|
+
}
|
|
1290
|
+
else {
|
|
1291
|
+
lines.push(`${prefix}${GRAY}${entry.type}${RESET}`);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1296
|
+
const followTag = this.activityFollow ? "" : ` ${YELLOW}[paused]${RESET}`;
|
|
1297
|
+
const scrollInfo = this.activityFollow
|
|
1298
|
+
? ""
|
|
1299
|
+
: ` ${GRAY}[${start}/${Math.max(0, total - viewport)}]${RESET}`;
|
|
1300
|
+
lines.push(`${GRAY}│ ${DIM}↑↓ select · Space/f pause · Enter expand · Esc/q back${RESET}${followTag}${scrollInfo}`);
|
|
1301
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1302
|
+
return this.compose(lines);
|
|
1303
|
+
}
|
|
1304
|
+
formatActivityDetail() {
|
|
1305
|
+
const entries = this.getActivityEntries();
|
|
1306
|
+
const evt = entries[this.activityCursor];
|
|
1307
|
+
if (!evt) {
|
|
1308
|
+
this.exitActivityDetail();
|
|
1309
|
+
return this.formatActivity();
|
|
1310
|
+
}
|
|
1311
|
+
const ident = this.getActivityMeta()?.identifier ?? this.detailId ?? "?";
|
|
1312
|
+
const time = new Date(evt.ts).toISOString().slice(11, 19);
|
|
1313
|
+
const lines = [];
|
|
1314
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}Activity${RESET} ${GRAY}·${RESET} ${BOLD}${ident}${RESET} ${GRAY}·${RESET} ${BOLD}full text${RESET}`);
|
|
1315
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1316
|
+
this.pushDetailFields(lines, [
|
|
1317
|
+
["Time", time],
|
|
1318
|
+
["Type", evt.type],
|
|
1319
|
+
...(evt.tool !== undefined ? [["Tool", evt.tool]] : []),
|
|
1320
|
+
...(evt.tokens
|
|
1321
|
+
? [
|
|
1322
|
+
[
|
|
1323
|
+
"Tokens",
|
|
1324
|
+
`in ${this.formatCount(evt.tokens.input)} | out ${this.formatCount(evt.tokens.output)} | total ${this.formatCount(evt.tokens.total)}`,
|
|
1325
|
+
],
|
|
1326
|
+
]
|
|
1327
|
+
: []),
|
|
1328
|
+
]);
|
|
1329
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1330
|
+
const body = this.getActivityDetailBody();
|
|
1331
|
+
const viewport = TerminalDashboard.ACTIVITY_VIEWPORT;
|
|
1332
|
+
const maxScroll = Math.max(0, body.length - viewport);
|
|
1333
|
+
this.activityDetailScroll = Math.max(0, Math.min(maxScroll, this.activityDetailScroll));
|
|
1334
|
+
const visible = body.slice(this.activityDetailScroll, this.activityDetailScroll + viewport);
|
|
1335
|
+
if (visible.length === 0)
|
|
1336
|
+
visible.push("");
|
|
1337
|
+
for (const line of visible) {
|
|
1338
|
+
lines.push(`${GRAY}│${RESET} ${line}`);
|
|
1339
|
+
}
|
|
1340
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1341
|
+
const scrollInfo = body.length > viewport ? ` ${GRAY}[${this.activityDetailScroll}/${maxScroll}]${RESET}` : "";
|
|
1342
|
+
lines.push(`${GRAY}│ ${DIM}↑↓ scroll · Esc/q back${RESET}${scrollInfo}`);
|
|
1343
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1344
|
+
return this.compose(lines);
|
|
1345
|
+
}
|
|
1346
|
+
getActivityDetailBody() {
|
|
1347
|
+
const entries = this.getActivityEntries();
|
|
1348
|
+
const evt = entries[this.activityCursor];
|
|
1349
|
+
if (!evt)
|
|
1350
|
+
return [""];
|
|
1351
|
+
if (evt.type === "tool_use" &&
|
|
1352
|
+
(evt.tool !== undefined ||
|
|
1353
|
+
evt.input !== undefined ||
|
|
1354
|
+
evt.output !== undefined ||
|
|
1355
|
+
evt.exit !== undefined)) {
|
|
1356
|
+
return this.buildToolDetailBody(evt);
|
|
1357
|
+
}
|
|
1358
|
+
if (evt.text === undefined)
|
|
1359
|
+
return [""];
|
|
1360
|
+
const width = Math.max(20, this.terminalWidthFn() - TerminalDashboard.ACTIVITY_DETAIL_WIDTH_PAD);
|
|
1361
|
+
return wrapToWidth(evt.text, width);
|
|
1362
|
+
}
|
|
1363
|
+
buildToolDetailBody(evt) {
|
|
1364
|
+
const width = Math.max(20, this.terminalWidthFn() - TerminalDashboard.ACTIVITY_DETAIL_WIDTH_PAD);
|
|
1365
|
+
const lines = [];
|
|
1366
|
+
const failed = evt.exit !== undefined && evt.exit !== 0;
|
|
1367
|
+
const statusLabel = evt.status ?? "completed";
|
|
1368
|
+
const exitLabel = evt.exit !== undefined ? ` (exit ${evt.exit})` : "";
|
|
1369
|
+
const statusLine = `${failed ? "Status: ✗" : "Status:"} ${statusLabel}${exitLabel}`;
|
|
1370
|
+
lines.push(failed ? `${YELLOW}${statusLine}${RESET}` : statusLine);
|
|
1371
|
+
if (evt.durationMs !== undefined)
|
|
1372
|
+
lines.push(`Duration: ${formatDuration(evt.durationMs)}`);
|
|
1373
|
+
if (evt.tool !== undefined)
|
|
1374
|
+
lines.push(`Tool: ${evt.tool}`);
|
|
1375
|
+
if (evt.input !== undefined) {
|
|
1376
|
+
lines.push("");
|
|
1377
|
+
const input = evt.input;
|
|
1378
|
+
if (typeof input.command === "string") {
|
|
1379
|
+
lines.push("Command:");
|
|
1380
|
+
for (const l of wrapToWidth(input.command, width))
|
|
1381
|
+
lines.push(` ${l}`);
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
lines.push("Args:");
|
|
1385
|
+
for (const l of wrapToWidth(JSON.stringify(input, null, 2), width))
|
|
1386
|
+
lines.push(` ${l}`);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (evt.output !== undefined) {
|
|
1390
|
+
lines.push("");
|
|
1391
|
+
lines.push("Output:");
|
|
1392
|
+
const capped = capTailLines(evt.output, DETAIL_OUTPUT_MAX_LINES);
|
|
1393
|
+
if (capped.dropped > 0)
|
|
1394
|
+
lines.push(`… (${capped.dropped} more lines)`);
|
|
1395
|
+
if (evt.output.trim() === "") {
|
|
1396
|
+
lines.push(" (no output)");
|
|
1397
|
+
}
|
|
1398
|
+
else {
|
|
1399
|
+
for (const l of capped.lines) {
|
|
1400
|
+
for (const w of wrapToWidth(l, width))
|
|
1401
|
+
lines.push(` ${w}`);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if (evt.truncated)
|
|
1405
|
+
lines.push("… (opencode truncated)");
|
|
1406
|
+
}
|
|
1407
|
+
return lines;
|
|
1408
|
+
}
|
|
1409
|
+
renderActivityText(text) {
|
|
1410
|
+
const width = Math.max(20, this.terminalWidthFn() - TerminalDashboard.ACTIVITY_EVENT_WIDTH_PAD);
|
|
1411
|
+
const wrapped = wrapToWidth(text, width);
|
|
1412
|
+
if (wrapped.length <= 3)
|
|
1413
|
+
return wrapped;
|
|
1414
|
+
const shown = wrapped.slice(0, 3);
|
|
1415
|
+
const last = shown[2] ?? "";
|
|
1416
|
+
shown[2] = truncateToWidth(`${last}…`, width);
|
|
1417
|
+
return shown;
|
|
1418
|
+
}
|
|
1419
|
+
toolCallSummary(entry) {
|
|
1420
|
+
const tool = entry.tool ?? "";
|
|
1421
|
+
if (entry.title)
|
|
1422
|
+
return `${tool} · ${entry.title}`;
|
|
1423
|
+
if (entry.input) {
|
|
1424
|
+
if (typeof entry.input.command === "string")
|
|
1425
|
+
return `${tool} · ${entry.input.command}`;
|
|
1426
|
+
if (typeof entry.input.filePath === "string")
|
|
1427
|
+
return `${tool} · ${entry.input.filePath}`;
|
|
1428
|
+
}
|
|
1429
|
+
return tool;
|
|
1430
|
+
}
|
|
1431
|
+
formatConfig() {
|
|
1432
|
+
const viewport = TerminalDashboard.CONFIG_VIEWPORT;
|
|
1433
|
+
const allLines = this.lastConfigView
|
|
1434
|
+
? this.buildConfigLines(this.lastConfigView)
|
|
1435
|
+
: [`${GRAY}│ ${DIM}No config available${RESET}`];
|
|
1436
|
+
const total = allLines.length;
|
|
1437
|
+
const maxStart = Math.max(0, total - viewport);
|
|
1438
|
+
this.configScrollOffset = Math.max(0, Math.min(this.configScrollOffset, maxStart));
|
|
1439
|
+
const start = this.configScrollOffset;
|
|
1440
|
+
const visible = allLines.slice(start, start + viewport);
|
|
1441
|
+
const lines = [...visible];
|
|
1442
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1443
|
+
lines.push(`${GRAY}│ ${DIM}↑↓ scroll · Esc/q back${RESET} ${GRAY}[${start}/${maxStart}]${RESET}`);
|
|
1444
|
+
lines.push(`${CYAN}╰──────────────────────────────────────────────────${RESET}`);
|
|
1445
|
+
return this.compose(lines);
|
|
1446
|
+
}
|
|
1447
|
+
buildConfigLines(view) {
|
|
1448
|
+
const lines = [];
|
|
1449
|
+
const r = view.runtime;
|
|
1450
|
+
lines.push(`${CYAN}${BOLD}╭─ tasking${RESET} ${GRAY}—${RESET} ${BOLD}Config${RESET}`);
|
|
1451
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1452
|
+
lines.push(`│ ${DIM}Workflow:${RESET} ${r.workflow_path ?? "n/a"}`);
|
|
1453
|
+
lines.push(`│ ${DIM}Daemon pid:${RESET} ${r.pid ?? "n/a"}`);
|
|
1454
|
+
if (r.started_at !== null) {
|
|
1455
|
+
const uptime = this.formatRuntime((Date.now() - r.started_at) / 1000);
|
|
1456
|
+
lines.push(`│ ${DIM}Started:${RESET} ${this.formatDateTime(r.started_at)} (${uptime} ago)`);
|
|
1457
|
+
}
|
|
1458
|
+
lines.push(`│ ${DIM}Workspace root:${RESET} ${r.workspace_root ?? "n/a"}`);
|
|
1459
|
+
lines.push(`│ ${DIM}Log file:${RESET} ${r.log_path ?? "n/a"}`);
|
|
1460
|
+
lines.push(`│ ${DIM}Dashboard:${RESET} ${r.host ?? "n/a"}:${r.port ?? "n/a"}`);
|
|
1461
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1462
|
+
for (const group of CONFIG_SECTIONS) {
|
|
1463
|
+
const groupData = view.config[group];
|
|
1464
|
+
if (groupData === undefined)
|
|
1465
|
+
continue;
|
|
1466
|
+
lines.push(`${CYAN}├─ ${BOLD}${group}${RESET}`);
|
|
1467
|
+
for (const [key, value] of Object.entries(groupData)) {
|
|
1468
|
+
lines.push(`│ ${GRAY}${this.pad(`${key}:`, 26)}${RESET} ${this.formatValue(value)}`);
|
|
1469
|
+
}
|
|
1470
|
+
lines.push(`${GRAY}│${RESET}`);
|
|
1471
|
+
}
|
|
1472
|
+
return lines;
|
|
1473
|
+
}
|
|
1474
|
+
formatValue(value) {
|
|
1475
|
+
if (value === null || value === undefined)
|
|
1476
|
+
return translate("未配置");
|
|
1477
|
+
if (Array.isArray(value)) {
|
|
1478
|
+
if (value.length === 0)
|
|
1479
|
+
return "[]";
|
|
1480
|
+
return value.map((v) => this.formatValue(v)).join(", ");
|
|
1481
|
+
}
|
|
1482
|
+
if (typeof value === "object") {
|
|
1483
|
+
const entries = Object.entries(value);
|
|
1484
|
+
if (entries.length === 0)
|
|
1485
|
+
return "{}";
|
|
1486
|
+
return entries.map(([k, v]) => `${k}=${this.formatValue(v)}`).join(" ");
|
|
1487
|
+
}
|
|
1488
|
+
if (typeof value === "boolean")
|
|
1489
|
+
return value ? "true" : "false";
|
|
1490
|
+
return String(value);
|
|
1491
|
+
}
|
|
1492
|
+
formatDateTime(ms) {
|
|
1493
|
+
return new Date(ms).toISOString().replace("T", " ").slice(0, 19);
|
|
1494
|
+
}
|
|
1495
|
+
emptySnapshot() {
|
|
1496
|
+
return {
|
|
1497
|
+
generated_at: Date.now(),
|
|
1498
|
+
max_concurrent_agents: 0,
|
|
1499
|
+
counts: { running: 0, retrying: 0 },
|
|
1500
|
+
running: [],
|
|
1501
|
+
retrying: [],
|
|
1502
|
+
direct: [],
|
|
1503
|
+
totals: { input_tokens: 0, output_tokens: 0, total_tokens: 0, seconds_running: 0 },
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
updateSamples(samples, now, total) {
|
|
1507
|
+
const updated = [{ timestamp: now, total }, ...samples];
|
|
1508
|
+
const minTs = now - GRAPH_WINDOW_MS;
|
|
1509
|
+
return updated.filter((s) => s.timestamp >= minTs).slice(0, 1000);
|
|
1510
|
+
}
|
|
1511
|
+
computeTps(samples, now, currentTotal) {
|
|
1512
|
+
if (samples.length < 2)
|
|
1513
|
+
return 0;
|
|
1514
|
+
const first = samples[samples.length - 1];
|
|
1515
|
+
if (!first)
|
|
1516
|
+
return 0;
|
|
1517
|
+
const elapsedMs = now - first.timestamp;
|
|
1518
|
+
if (elapsedMs <= 0)
|
|
1519
|
+
return 0;
|
|
1520
|
+
const delta = Math.max(0, currentTotal - first.total);
|
|
1521
|
+
return delta / (elapsedMs / 1000);
|
|
1522
|
+
}
|
|
1523
|
+
sparkline(samples, now, currentTotal) {
|
|
1524
|
+
if (samples.length < 2)
|
|
1525
|
+
return `${GRAY}${DIM}collecting data...${RESET}`;
|
|
1526
|
+
const bucketMs = Math.floor(GRAPH_WINDOW_MS / GRAPH_COLUMNS);
|
|
1527
|
+
const activeBucket = Math.floor(now / bucketMs) * bucketMs;
|
|
1528
|
+
const windowStart = activeBucket - (GRAPH_COLUMNS - 1) * bucketMs;
|
|
1529
|
+
const rates = [];
|
|
1530
|
+
for (let i = 0; i < GRAPH_COLUMNS; i++) {
|
|
1531
|
+
const bucketStart = windowStart + i * bucketMs;
|
|
1532
|
+
const bucketEnd = bucketStart + bucketMs;
|
|
1533
|
+
const bucketSamples = [{ timestamp: now, total: currentTotal }, ...samples].filter((s) => s.timestamp >= bucketStart && s.timestamp < bucketEnd);
|
|
1534
|
+
if (bucketSamples.length < 2) {
|
|
1535
|
+
rates.push(0);
|
|
1536
|
+
}
|
|
1537
|
+
else {
|
|
1538
|
+
const first = bucketSamples[bucketSamples.length - 1];
|
|
1539
|
+
const last = bucketSamples[0];
|
|
1540
|
+
if (!first || !last) {
|
|
1541
|
+
rates.push(0);
|
|
1542
|
+
continue;
|
|
1543
|
+
}
|
|
1544
|
+
const elapsed = last.timestamp - first.timestamp;
|
|
1545
|
+
const delta = Math.max(0, last.total - first.total);
|
|
1546
|
+
rates.push(elapsed > 0 ? delta / (elapsed / 1000) : 0);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
const maxRate = Math.max(...rates, 1);
|
|
1550
|
+
const allZero = rates.every((r) => r === 0);
|
|
1551
|
+
if (allZero)
|
|
1552
|
+
return `${GRAY}${DIM}idle (no tokens consumed)${RESET}`;
|
|
1553
|
+
const blocks = rates
|
|
1554
|
+
.map((r) => {
|
|
1555
|
+
const idx = maxRate <= 0 ? 0 : Math.round((r / maxRate) * (SPARKLINE_BLOCKS.length - 1));
|
|
1556
|
+
const block = SPARKLINE_BLOCKS[Math.min(idx, SPARKLINE_BLOCKS.length - 1)] ?? "▁";
|
|
1557
|
+
const intensity = idx / (SPARKLINE_BLOCKS.length - 1);
|
|
1558
|
+
const color = intensity > 0.6 ? GREEN : intensity > 0.3 ? CYAN : GRAY;
|
|
1559
|
+
return `${color}${block}`;
|
|
1560
|
+
})
|
|
1561
|
+
.join("");
|
|
1562
|
+
return `${blocks}${RESET}`;
|
|
1563
|
+
}
|
|
1564
|
+
formatRuntime(seconds) {
|
|
1565
|
+
const s = Math.max(0, Math.floor(seconds));
|
|
1566
|
+
const m = Math.floor(s / 60);
|
|
1567
|
+
const sec = s % 60;
|
|
1568
|
+
return `${m}m ${sec}s`;
|
|
1569
|
+
}
|
|
1570
|
+
formatCount(value) {
|
|
1571
|
+
return value.toLocaleString("en-US");
|
|
1572
|
+
}
|
|
1573
|
+
formatTps(value) {
|
|
1574
|
+
return Math.trunc(value).toLocaleString("en-US");
|
|
1575
|
+
}
|
|
1576
|
+
compactSession(sessionId) {
|
|
1577
|
+
if (!sessionId)
|
|
1578
|
+
return "n/a";
|
|
1579
|
+
if (sessionId.length > 10) {
|
|
1580
|
+
return `${sessionId.slice(0, 4)}...${sessionId.slice(-6)}`;
|
|
1581
|
+
}
|
|
1582
|
+
return sessionId;
|
|
1583
|
+
}
|
|
1584
|
+
pad(value, width) {
|
|
1585
|
+
const v = value.replace(/\n/g, " ").trim();
|
|
1586
|
+
if (v.length <= width)
|
|
1587
|
+
return v.padEnd(width);
|
|
1588
|
+
return `${v.slice(0, width - 1)}…`;
|
|
1589
|
+
}
|
|
1590
|
+
progressBar(current, max) {
|
|
1591
|
+
const ratio = max > 0 ? current / max : 0;
|
|
1592
|
+
const filled = Math.round(ratio * BAR_WIDTH);
|
|
1593
|
+
const empty = BAR_WIDTH - filled;
|
|
1594
|
+
const color = ratio >= 0.9 ? RED : ratio >= 0.6 ? YELLOW : GREEN;
|
|
1595
|
+
return `${color}${"█".repeat(filled)}${GRAY}${"░".repeat(empty)}${RESET} ${current}/${max}`;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
//# sourceMappingURL=terminal-dashboard.js.map
|