agent-whisker 0.1.0 → 0.2.0
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 +12 -3
- package/README.zh-CN.md +12 -3
- package/package.json +3 -2
- package/packages/antigravity-plugin/package.json +1 -1
- package/packages/antigravity-plugin/plugin.json +1 -1
- package/packages/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/packages/claude-plugin/.codex-plugin/plugin.json +1 -1
- package/packages/claude-plugin/README.md +11 -1
- package/packages/claude-plugin/README.zh-CN.md +4 -1
- package/packages/claude-plugin/bin/taskstate +145 -4
- package/packages/claude-plugin/hooks/codex.json +8 -8
- package/packages/claude-plugin/package.json +1 -1
- package/packages/cli/README.md +76 -3
- package/packages/cli/README.zh-CN.md +76 -3
- package/packages/cli/package.json +1 -1
- package/packages/cli/src/command.js +20 -3
- package/packages/cli/src/commands/catalog.js +26 -7
- package/packages/cli/src/commands/doctor.js +31 -27
- package/packages/cli/src/commands/exclude.js +156 -0
- package/packages/cli/src/commands/extract.js +4 -2
- package/packages/cli/src/commands/index-command.js +1 -1
- package/packages/cli/src/commands/index.js +4 -0
- package/packages/cli/src/commands/install.js +12 -1
- package/packages/cli/src/commands/nudge.js +39 -37
- package/packages/cli/src/commands/read.js +2 -1
- package/packages/cli/src/commands/search.js +33 -3
- package/packages/cli/src/commands/sessions.js +20 -12
- package/packages/cli/src/commands/status.js +6 -3
- package/packages/cli/src/commands/tui.js +62 -0
- package/packages/cli/src/commands/version.js +4 -4
- package/packages/cli/src/exclusion.js +88 -0
- package/packages/cli/src/install/codex-plugin.js +6 -5
- package/packages/cli/src/install/external.js +48 -37
- package/packages/cli/src/install/handlers.js +4 -3
- package/packages/cli/src/install/mcp.js +3 -3
- package/packages/cli/src/install/steps.js +43 -15
- package/packages/cli/src/install/wrapper.js +28 -5
- package/packages/cli/src/main.js +9 -12
- package/packages/cli/src/node-version.js +25 -0
- package/packages/cli/src/run.js +25 -5
- package/packages/cli/src/tui/app.js +1430 -0
- package/packages/cli/src/tui/data/call.js +83 -0
- package/packages/cli/src/tui/data/poll.js +24 -0
- package/packages/cli/src/tui/glyphs.js +93 -0
- package/packages/cli/src/tui/i18n.js +342 -0
- package/packages/cli/src/tui/model.js +251 -0
- package/packages/cli/src/tui/pages/common.js +71 -0
- package/packages/cli/src/tui/pages/library.js +154 -0
- package/packages/cli/src/tui/pages/sessions.js +96 -0
- package/packages/cli/src/tui/pages/system.js +124 -0
- package/packages/cli/src/tui/pages/tasks.js +297 -0
- package/packages/cli/src/tui/run.js +216 -0
- package/packages/cli/src/tui/term/keys.js +152 -0
- package/packages/cli/src/tui/term/screen.js +88 -0
- package/packages/cli/src/tui/term/term.js +157 -0
- package/packages/cli/src/tui/term/width.js +290 -0
- package/packages/cli/src/tui/ui/widgets.js +247 -0
- package/packages/core/README.md +1 -1
- package/packages/core/README.zh-CN.md +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/src/catalog.js +13 -1
- package/packages/core/src/clairic.js +1 -1
- package/packages/core/src/convert.js +1 -1
- package/packages/core/src/db.js +6 -1
- package/packages/core/src/host.js +104 -0
- package/packages/core/src/index.js +2 -2
- package/packages/core/src/library-read.js +12 -8
- package/packages/core/src/nudge.js +34 -1
- package/packages/core/src/schema.js +17 -0
- package/packages/core/src/sessions-read.js +23 -11
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/herdr-plugin/herdr-plugin.toml +1 -1
- package/packages/herdr-plugin/package.json +1 -1
- package/packages/mcp/README.md +5 -5
- package/packages/mcp/README.zh-CN.md +5 -5
- package/packages/mcp/package.json +1 -1
- package/packages/pi-extension/README.md +1 -1
- package/packages/pi-extension/README.zh-CN.md +1 -1
- package/packages/pi-extension/package.json +1 -1
- package/packages/pi-extension/src/extension.ts +3 -3
- package/packages/service/package.json +1 -1
- package/packages/service/src/index.js +1 -1
- package/packages/service/src/runtime.js +4 -0
|
@@ -0,0 +1,1430 @@
|
|
|
1
|
+
// The interface's state machine: keys and answers come in, the model changes, and view draws it. view is a pure
|
|
2
|
+
// function of the model (and the clock), so a test can press keys and read the screen without a terminal. Writes
|
|
3
|
+
// never run on a key alone: each opens the confirmation bar, whose `$ …` line is shellQuote of the very argv that y
|
|
4
|
+
// runs (confirmArgv), and each run is kept for the audit printed on exit.
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
import { glyphsFor } from "./glyphs.js";
|
|
9
|
+
import { langFor, translator } from "./i18n.js";
|
|
10
|
+
import {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
confirmArgv,
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PAGES,
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
sanitizeDeep,
|
|
22
|
+
|
|
23
|
+
} from "./model.js";
|
|
24
|
+
import { documentParentDir, tilde } from "./pages/common.js";
|
|
25
|
+
import { facetDocs, libraryDetailRows, libraryListRows } from "./pages/library.js";
|
|
26
|
+
import { HARNESS_FILTERS, RANGES, readerRows, sessionItems, sessionListRows } from "./pages/sessions.js";
|
|
27
|
+
import { agentsRows, doctorRows } from "./pages/system.js";
|
|
28
|
+
import { expectationRows, latestRun, taskDetailRows, taskItems, taskListRows } from "./pages/tasks.js";
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
import { displayWidth, sanitize, wrap } from "./term/width.js";
|
|
33
|
+
import {
|
|
34
|
+
besideRows,
|
|
35
|
+
clampSelection,
|
|
36
|
+
editInput,
|
|
37
|
+
fitRow,
|
|
38
|
+
|
|
39
|
+
hintBar,
|
|
40
|
+
inputRow,
|
|
41
|
+
line,
|
|
42
|
+
moveSelection,
|
|
43
|
+
rule,
|
|
44
|
+
shellQuote,
|
|
45
|
+
wrapped,
|
|
46
|
+
} from "./ui/widgets.js";
|
|
47
|
+
|
|
48
|
+
/** Below this size only a notice is drawn: 40 columns, 12 rows. */
|
|
49
|
+
const MIN_COLS = 40;
|
|
50
|
+
const MIN_ROWS = 12;
|
|
51
|
+
/** From this width the pages show a list and its detail side by side. */
|
|
52
|
+
const WIDE_COLS = 100;
|
|
53
|
+
/** How long the search waits after the last key before it runs: 250 ms. */
|
|
54
|
+
const SEARCH_DEBOUNCE_MS = 250;
|
|
55
|
+
/** How long a call waits for the busy frame to be drawn first: one frame and a millisecond. */
|
|
56
|
+
const BUSY_FRAME_MS = 17;
|
|
57
|
+
/** How many lines of a run's log the expectation view shows. */
|
|
58
|
+
const LOG_LINES = 6;
|
|
59
|
+
/** The taskstate verbs this interface runs: reads and handoffs only (tests/architecture.test.ts holds it to these). */
|
|
60
|
+
const TASKSTATE_VERBS = ["list", "show", "facts", "where", "hold", "park", "unpark", "close"] ;
|
|
61
|
+
|
|
62
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: colour codes in a log are removed before sanitizing.
|
|
63
|
+
const SGR_CODES = /\x1b\[[0-9;?]*[ -/]*[@-~]/gu;
|
|
64
|
+
|
|
65
|
+
/** A taskstate argv: one of TASKSTATE_VERBS and its arguments. The only way this interface builds one. */
|
|
66
|
+
export function taskstateArgv(verb , ...args ) {
|
|
67
|
+
return [verb, ...args];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/** The read-time model paths as the environment sets them: the endpoint's host only, never a key. */
|
|
85
|
+
function modelPaths(env ) {
|
|
86
|
+
const hostOf = (url , enabled ) => {
|
|
87
|
+
if (!url?.trim() || /^(off|0|false|no)$/iu.test(enabled?.trim() ?? "")) return null;
|
|
88
|
+
try {
|
|
89
|
+
return sanitize(new URL(url.trim()).host);
|
|
90
|
+
} catch {
|
|
91
|
+
return "?";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
decide: hostOf(env.AGENT_WHISKER_RERANK_URL, env.AGENT_WHISKER_RERANK),
|
|
96
|
+
extract: hostOf(env.AGENT_WHISKER_EXTRACT_URL, env.AGENT_WHISKER_EXTRACT),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class App {
|
|
101
|
+
model ;
|
|
102
|
+
/** Called whenever the model changed and the screen should be drawn again. */
|
|
103
|
+
onChange = () => {};
|
|
104
|
+
/** Called on Ctrl+Z. */
|
|
105
|
+
onSuspend = () => {};
|
|
106
|
+
pending = 0;
|
|
107
|
+
searchTimer = null;
|
|
108
|
+
runner ;
|
|
109
|
+
timers ;
|
|
110
|
+
now ;
|
|
111
|
+
readFile ;
|
|
112
|
+
/** taskstate's session ids resolved to agent-whisker's (null: not found). */
|
|
113
|
+
resolved = new Map ();
|
|
114
|
+
projectRoot = null;
|
|
115
|
+
|
|
116
|
+
constructor(options ) {
|
|
117
|
+
this.runner = options.runner;
|
|
118
|
+
this.timers = options.timers;
|
|
119
|
+
this.now = options.now;
|
|
120
|
+
this.readFile = options.readFile ?? ((path) => readFileSync(path, "utf8"));
|
|
121
|
+
const lang = langFor(options.env);
|
|
122
|
+
const view = () => ({ top: 0 });
|
|
123
|
+
this.model = {
|
|
124
|
+
page: options.page,
|
|
125
|
+
cols: options.cols,
|
|
126
|
+
rows: options.rows,
|
|
127
|
+
lang,
|
|
128
|
+
t: translator(lang),
|
|
129
|
+
glyphs: glyphsFor(options.env),
|
|
130
|
+
paint: { ambiguous: options.ambiguous, colour: !options.env.NO_COLOR },
|
|
131
|
+
homeDir: options.homeDir,
|
|
132
|
+
status: null,
|
|
133
|
+
confirm: null,
|
|
134
|
+
prompt: null,
|
|
135
|
+
help: false,
|
|
136
|
+
search: null,
|
|
137
|
+
right: false,
|
|
138
|
+
stale: new Set(),
|
|
139
|
+
store: null,
|
|
140
|
+
taskstateState: null,
|
|
141
|
+
taskstateRuns: null,
|
|
142
|
+
audit: [],
|
|
143
|
+
quit: false,
|
|
144
|
+
tasks: {
|
|
145
|
+
list: null,
|
|
146
|
+
error: null,
|
|
147
|
+
sel: 0,
|
|
148
|
+
view: view(),
|
|
149
|
+
layer: "list",
|
|
150
|
+
detail: null,
|
|
151
|
+
detailSel: 0,
|
|
152
|
+
detailView: view(),
|
|
153
|
+
log: null,
|
|
154
|
+
},
|
|
155
|
+
library: {
|
|
156
|
+
docs: null,
|
|
157
|
+
hidden: null,
|
|
158
|
+
error: null,
|
|
159
|
+
facet: 0,
|
|
160
|
+
sel: 0,
|
|
161
|
+
view: view(),
|
|
162
|
+
layer: "list",
|
|
163
|
+
last: null,
|
|
164
|
+
project: null,
|
|
165
|
+
},
|
|
166
|
+
sessions: {
|
|
167
|
+
list: null,
|
|
168
|
+
error: null,
|
|
169
|
+
harness: null,
|
|
170
|
+
range: 0,
|
|
171
|
+
query: "",
|
|
172
|
+
sel: 0,
|
|
173
|
+
view: view(),
|
|
174
|
+
layer: "list",
|
|
175
|
+
reader: null,
|
|
176
|
+
links: {},
|
|
177
|
+
},
|
|
178
|
+
agents: { steps: null, error: null, sel: 0, view: view() },
|
|
179
|
+
doctor: { checks: null, error: null, running: false, sel: 0, view: view() },
|
|
180
|
+
models: modelPaths(options.env),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Ends the session's own timers (a search waiting on its debounce), so nothing runs after the terminal is restored. */
|
|
185
|
+
dispose() {
|
|
186
|
+
this.disposed = true;
|
|
187
|
+
if (this.searchTimer !== null) this.timers.clearTimeout(this.searchTimer);
|
|
188
|
+
this.searchTimer = null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
disposed = false;
|
|
192
|
+
/** Whether the last frame showed the whole confirmation bar; a bar that did not fit cannot be confirmed. */
|
|
193
|
+
confirmShown = true;
|
|
194
|
+
|
|
195
|
+
/** Whether no call is running and no search is waiting: what tests wait for. */
|
|
196
|
+
get idle() {
|
|
197
|
+
return this.pending === 0 && this.searchTimer === null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// Calls
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
async call(kind , argv , json = true) {
|
|
205
|
+
if (this.disposed) return { ok: false, code: "Closed", message: "the interface has ended", exit: 1 };
|
|
206
|
+
this.pending++;
|
|
207
|
+
// Let the busy mark be drawn before the call: most calls run synchronously and would hold the frame back.
|
|
208
|
+
this.onChange();
|
|
209
|
+
try {
|
|
210
|
+
await new Promise((resolve) => this.timers.setTimeout(() => resolve(null), BUSY_FRAME_MS));
|
|
211
|
+
if (this.disposed) return { ok: false, code: "Closed", message: "the interface has ended", exit: 1 };
|
|
212
|
+
const result = kind === "cli" ? await this.runner.cli(argv) : await this.runner.taskstate(argv, json);
|
|
213
|
+
if (!result.ok && (result.code === "MaintenanceInProgress" || result.code === "Busy"))
|
|
214
|
+
this.model.status = { text: this.model.t("paused"), kind: "paused" };
|
|
215
|
+
return result.ok ? { ...result, json: sanitizeDeep(result.json) } : sanitizeDeep(result);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
ok: false,
|
|
219
|
+
code: "Internal",
|
|
220
|
+
message: sanitize(error instanceof Error ? error.message : String(error)),
|
|
221
|
+
exit: 1,
|
|
222
|
+
};
|
|
223
|
+
} finally {
|
|
224
|
+
this.pending--;
|
|
225
|
+
this.onChange();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** The first reads: the store's status, where taskstate keeps its state, then the current page. */
|
|
230
|
+
async start() {
|
|
231
|
+
await this.loadStatus();
|
|
232
|
+
const where = await this.call("taskstate", taskstateArgv("where"));
|
|
233
|
+
if (where.ok) {
|
|
234
|
+
const json = where.json ;
|
|
235
|
+
this.model.taskstateState = typeof json.state === "string" ? json.state : null;
|
|
236
|
+
this.model.taskstateRuns = typeof json.runs === "string" ? json.runs : null;
|
|
237
|
+
}
|
|
238
|
+
await this.load(this.model.page);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async loadStatus() {
|
|
242
|
+
const status = await this.call("cli", ["status"]);
|
|
243
|
+
if (!status.ok) return;
|
|
244
|
+
const json = status.json ;
|
|
245
|
+
const initialised = json.initialised === true;
|
|
246
|
+
let documents = 0;
|
|
247
|
+
if (initialised) {
|
|
248
|
+
const visible = await this.call("cli", ["catalog", "--limit", "1"]);
|
|
249
|
+
const hidden = await this.call("cli", ["catalog", "--removed", "--limit", "1"]);
|
|
250
|
+
for (const answer of [visible, hidden])
|
|
251
|
+
if (answer.ok) documents += Number((answer.json ).total ?? 0);
|
|
252
|
+
}
|
|
253
|
+
this.model.store = { initialised, project: json.project?.name ?? null, documents };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Reads a page's data again. */
|
|
257
|
+
async load(page ) {
|
|
258
|
+
this.model.stale.delete(page);
|
|
259
|
+
if (page === "tasks") return this.loadTasks();
|
|
260
|
+
if (page === "library") return this.loadLibrary();
|
|
261
|
+
if (page === "sessions") return this.loadSessions();
|
|
262
|
+
if (page === "agents") return this.loadAgents();
|
|
263
|
+
return this.loadDoctor(false);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async loadTasks() {
|
|
267
|
+
const page = this.model.tasks;
|
|
268
|
+
const list = await this.call("taskstate", taskstateArgv("list"));
|
|
269
|
+
if (!list.ok) {
|
|
270
|
+
page.error = list.message;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
page.error = null;
|
|
274
|
+
page.list = ((list.json ).tasks ?? []).filter((task) => typeof task?.id === "string");
|
|
275
|
+
const items = taskItems(this.model, this.model.cols, this.now());
|
|
276
|
+
page.sel = clampSelection(items, page.sel);
|
|
277
|
+
await this.loadTaskDetail();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
selectedTask() {
|
|
281
|
+
const items = taskItems(this.model, this.model.cols, this.now());
|
|
282
|
+
return items[this.model.tasks.sel]?.key ?? null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async loadTaskDetail() {
|
|
286
|
+
const page = this.model.tasks;
|
|
287
|
+
const id = this.selectedTask();
|
|
288
|
+
if (id === null) {
|
|
289
|
+
page.detail = null;
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const show = await this.call("taskstate", taskstateArgv("show", id));
|
|
293
|
+
// An answer for a task the cursor has left is dropped; the cursor's own read is on its way.
|
|
294
|
+
if (this.selectedTask() !== id) return;
|
|
295
|
+
if (show.ok) {
|
|
296
|
+
page.detail = show.json ;
|
|
297
|
+
page.detailSel = Math.min(page.detailSel, Math.max(0, page.detail.expectations.length - 1));
|
|
298
|
+
} else {
|
|
299
|
+
page.detail = null;
|
|
300
|
+
this.model.status = { text: this.model.t("failed", show.message), kind: "fail" };
|
|
301
|
+
}
|
|
302
|
+
this.loadLog();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The latest run's log of the selected expectation, its last lines without colour codes. */
|
|
306
|
+
loadLog() {
|
|
307
|
+
const page = this.model.tasks;
|
|
308
|
+
const run = latestRun(this.model);
|
|
309
|
+
if (run === null || this.model.taskstateRuns === null || !/^R[1-9][0-9]*$/u.test(run)) {
|
|
310
|
+
page.log = null;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
const text = this.readFile(join(this.model.taskstateRuns, `${run}.log`)).replace(SGR_CODES, "");
|
|
315
|
+
const lines = text.split("\n").filter((l, i, all) => l !== "" || i < all.length - 1);
|
|
316
|
+
page.log = { run, lines: lines.slice(-LOG_LINES).map(sanitize) };
|
|
317
|
+
} catch {
|
|
318
|
+
page.log = { run, lines: [] };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async loadLibrary() {
|
|
323
|
+
const page = this.model.library;
|
|
324
|
+
if (this.projectRoot === null) {
|
|
325
|
+
const project = await this.call("cli", ["project", "show"]);
|
|
326
|
+
if (project.ok) {
|
|
327
|
+
const found = (project.json ).project;
|
|
328
|
+
this.projectRoot = found?.root ?? null;
|
|
329
|
+
page.project = found?.name ?? null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const visible = await this.call("cli", ["catalog", "--limit", "5000"]);
|
|
333
|
+
if (!visible.ok) {
|
|
334
|
+
page.error = visible.code === "NotAStore" ? this.model.t("libNotInit") : visible.message;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const hidden = await this.call("cli", ["catalog", "--removed", "--limit", "5000"]);
|
|
338
|
+
page.error = null;
|
|
339
|
+
page.docs = (visible.json ).documents;
|
|
340
|
+
page.hidden = hidden.ok ? (hidden.json ).documents : [];
|
|
341
|
+
if (this.model.store) this.model.store.documents = page.docs.length + page.hidden.length;
|
|
342
|
+
page.sel = Math.max(0, Math.min(page.sel, facetDocs(this.model).length - 1));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async loadSessions() {
|
|
346
|
+
const page = this.model.sessions;
|
|
347
|
+
const range = RANGES[page.range] ?? 0;
|
|
348
|
+
const since = range === 0 ? [] : ["--since", new Date(this.now() - range * 86_400_000).toISOString().slice(0, 10)];
|
|
349
|
+
const words = page.query.trim() === "" ? [] : [page.query.trim()];
|
|
350
|
+
const answer = await this.call("cli", [
|
|
351
|
+
"sessions",
|
|
352
|
+
"search",
|
|
353
|
+
...words,
|
|
354
|
+
"--group",
|
|
355
|
+
"session",
|
|
356
|
+
"--limit",
|
|
357
|
+
"100",
|
|
358
|
+
...(page.harness === null ? [] : ["--harness", page.harness]),
|
|
359
|
+
...since,
|
|
360
|
+
]);
|
|
361
|
+
if (!answer.ok) {
|
|
362
|
+
page.error = answer.code === "NotAStore" ? this.model.t("libNotInit") : answer.message;
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
page.error = null;
|
|
366
|
+
page.list = (answer.json ).sessions ?? [];
|
|
367
|
+
page.sel = Math.max(0, Math.min(page.sel, page.list.length - 1));
|
|
368
|
+
await this.resolveLinks();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Links agent-whisker's sessions to tasks: each task's session ids (taskstate's) resolved through `--session`. */
|
|
372
|
+
async resolveLinks() {
|
|
373
|
+
if (this.model.tasks.list === null) {
|
|
374
|
+
const list = await this.call("taskstate", taskstateArgv("list"));
|
|
375
|
+
if (list.ok) this.model.tasks.list = (list.json ).tasks ?? [];
|
|
376
|
+
}
|
|
377
|
+
const links = {};
|
|
378
|
+
// A session linked to several tasks shows the one most recently written to, an open one before a closed one.
|
|
379
|
+
const rank = (task ) => `${task.state === "closed" ? 0 : 1}${task.last ?? ""}`;
|
|
380
|
+
const tasks = [...(this.model.tasks.list ?? [])].sort((x, y) =>
|
|
381
|
+
rank(x) < rank(y) ? -1 : rank(x) > rank(y) ? 1 : 0,
|
|
382
|
+
);
|
|
383
|
+
for (const task of tasks.slice(-40)) {
|
|
384
|
+
for (const native of task.sessions.slice(0, 5)) {
|
|
385
|
+
if (!this.resolved.has(native)) {
|
|
386
|
+
const found = await this.call("cli", [
|
|
387
|
+
"sessions",
|
|
388
|
+
"search",
|
|
389
|
+
"--session",
|
|
390
|
+
native,
|
|
391
|
+
"--group",
|
|
392
|
+
"session",
|
|
393
|
+
"--limit",
|
|
394
|
+
"1",
|
|
395
|
+
]);
|
|
396
|
+
const id = found.ok ? ((found.json ).sessions?.[0]?.session ?? null) : null;
|
|
397
|
+
this.resolved.set(native, id);
|
|
398
|
+
}
|
|
399
|
+
const id = this.resolved.get(native);
|
|
400
|
+
if (id) links[id] = task.id;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
this.model.sessions.links = links;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async loadAgents() {
|
|
407
|
+
const page = this.model.agents;
|
|
408
|
+
const answer = await this.call("cli", ["install", "--dry-run"]);
|
|
409
|
+
if (!answer.ok) {
|
|
410
|
+
page.error = answer.message;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
page.error = null;
|
|
414
|
+
page.steps = (answer.json ).steps ?? [];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async loadDoctor(run ) {
|
|
418
|
+
if (!run) return;
|
|
419
|
+
const page = this.model.doctor;
|
|
420
|
+
page.running = true;
|
|
421
|
+
this.model.status = { text: this.model.t("running", "doctor"), kind: "busy" };
|
|
422
|
+
this.onChange();
|
|
423
|
+
// doctor exits 1 when a check fails and still answers JSON on stdout, which the runner returns as the answer.
|
|
424
|
+
const answer = await this.call("cli", ["doctor"]);
|
|
425
|
+
page.running = false;
|
|
426
|
+
if (!answer.ok) {
|
|
427
|
+
page.error = `${answer.code}: ${answer.message}`;
|
|
428
|
+
this.model.status = { text: this.model.t("failed", "doctor"), kind: "fail" };
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
page.error = null;
|
|
432
|
+
page.checks = (answer.json ).checks ?? [];
|
|
433
|
+
const failed = page.checks.some((check) => check.status === "fail");
|
|
434
|
+
this.model.status = failed
|
|
435
|
+
? { text: this.model.t("failed", "doctor"), kind: "fail" }
|
|
436
|
+
: { text: this.model.t("refreshed"), kind: "ok" };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async openReader(session ) {
|
|
440
|
+
const answer = await this.call("cli", ["sessions", "read", session.session, "--tail", "200"]);
|
|
441
|
+
if (!answer.ok) {
|
|
442
|
+
this.model.status = { text: this.model.t("failed", answer.message), kind: "fail" };
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const json = answer.json ;
|
|
446
|
+
this.model.sessions.reader = { session, items: json.items ?? [], top: 0, next: json.next ?? null };
|
|
447
|
+
this.model.sessions.layer = "reader";
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** Shows a task's session in the reader: Sessions page, reader open on it. */
|
|
451
|
+
async jumpToSession(native ) {
|
|
452
|
+
const found = await this.call("cli", [
|
|
453
|
+
"sessions",
|
|
454
|
+
"search",
|
|
455
|
+
"--session",
|
|
456
|
+
native,
|
|
457
|
+
"--group",
|
|
458
|
+
"session",
|
|
459
|
+
"--limit",
|
|
460
|
+
"1",
|
|
461
|
+
]);
|
|
462
|
+
const session = found.ok ? (found.json ).sessions?.[0] : undefined;
|
|
463
|
+
if (session === undefined) {
|
|
464
|
+
this.model.status = { text: this.model.t("failed", native), kind: "fail" };
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
this.model.page = "sessions";
|
|
468
|
+
if (this.model.sessions.list === null) await this.loadSessions();
|
|
469
|
+
await this.openReader(session);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Shows the task a session is linked to: Tasks page, its detail open. */
|
|
473
|
+
async jumpToTask(taskId ) {
|
|
474
|
+
this.model.page = "tasks";
|
|
475
|
+
if (this.model.tasks.list === null) await this.loadTasks();
|
|
476
|
+
const items = taskItems(this.model, this.model.cols, this.now());
|
|
477
|
+
const index = items.findIndex((item) => item.key === taskId);
|
|
478
|
+
if (index >= 0) this.model.tasks.sel = index;
|
|
479
|
+
this.model.tasks.layer = "detail";
|
|
480
|
+
await this.loadTaskDetail();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Every page is stale; the current one is read again. The poller calls it when the stamp changed. */
|
|
484
|
+
async refresh(asked = false) {
|
|
485
|
+
for (const page of PAGES) this.model.stale.add(page);
|
|
486
|
+
if (this.model.status?.kind === "paused") this.model.status = null;
|
|
487
|
+
await this.load(this.model.page);
|
|
488
|
+
// The poller's refresh keeps what the status line says (the result of a write stays readable); r announces itself.
|
|
489
|
+
if (this.model.status === null || (asked && this.model.status.kind !== "paused"))
|
|
490
|
+
this.model.status = { text: this.model.t("refreshed"), kind: "ok" };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// ---------------------------------------------------------------------------
|
|
494
|
+
// Keys
|
|
495
|
+
// ---------------------------------------------------------------------------
|
|
496
|
+
|
|
497
|
+
/** Handles one key. */
|
|
498
|
+
key(key ) {
|
|
499
|
+
const m = this.model;
|
|
500
|
+
if (key.ctrl && key.name === "c") {
|
|
501
|
+
m.quit = true;
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (key.ctrl && key.name === "z") {
|
|
505
|
+
this.onSuspend();
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (m.confirm !== null) {
|
|
509
|
+
this.confirmKey(key);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (m.prompt !== null) {
|
|
513
|
+
this.promptKey(key);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (m.search !== null) {
|
|
517
|
+
this.searchKey(key);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (m.help) {
|
|
521
|
+
if (key.name === "escape" || key.name === "?" || key.name === "q" || key.name === "enter") m.help = false;
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (key.ctrl && key.name === "k") {
|
|
525
|
+
this.openSearch();
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (key.ctrl && key.name === "d") {
|
|
529
|
+
this.move(this.halfPage());
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (key.ctrl && key.name === "u") {
|
|
533
|
+
this.move(-this.halfPage());
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (key.ctrl) return;
|
|
537
|
+
const page = PAGES.indexOf(key.name === "1" ? "tasks" : (PAGES[Number(key.name) - 1] ?? ("" )));
|
|
538
|
+
if (/^[1-5]$/u.test(key.name) && page >= 0) {
|
|
539
|
+
const next = PAGES[Number(key.name) - 1] ;
|
|
540
|
+
if (next !== m.page || m.stale.has(next) || this.empty(next)) {
|
|
541
|
+
m.page = next;
|
|
542
|
+
void this.load(next);
|
|
543
|
+
}
|
|
544
|
+
m.page = next;
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
switch (key.name) {
|
|
548
|
+
case "/":
|
|
549
|
+
this.openSearch();
|
|
550
|
+
return;
|
|
551
|
+
case "?":
|
|
552
|
+
m.help = true;
|
|
553
|
+
return;
|
|
554
|
+
case "q":
|
|
555
|
+
if (this.layer() === "list") m.quit = true;
|
|
556
|
+
else this.back();
|
|
557
|
+
return;
|
|
558
|
+
case "escape":
|
|
559
|
+
this.back();
|
|
560
|
+
return;
|
|
561
|
+
case "r":
|
|
562
|
+
void this.refresh(true);
|
|
563
|
+
return;
|
|
564
|
+
case "tab":
|
|
565
|
+
case "backtab":
|
|
566
|
+
if (m.cols >= WIDE_COLS) m.right = !m.right;
|
|
567
|
+
return;
|
|
568
|
+
case "j":
|
|
569
|
+
case "down":
|
|
570
|
+
this.move(1);
|
|
571
|
+
return;
|
|
572
|
+
case "k":
|
|
573
|
+
case "up":
|
|
574
|
+
this.move(-1);
|
|
575
|
+
return;
|
|
576
|
+
case "pagedown":
|
|
577
|
+
this.move(this.halfPage() * 2);
|
|
578
|
+
return;
|
|
579
|
+
case "pageup":
|
|
580
|
+
this.move(-this.halfPage() * 2);
|
|
581
|
+
return;
|
|
582
|
+
case "g":
|
|
583
|
+
case "home":
|
|
584
|
+
this.move(-1e6);
|
|
585
|
+
return;
|
|
586
|
+
case "G":
|
|
587
|
+
case "end":
|
|
588
|
+
this.move(1e6);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (m.page === "tasks") {
|
|
592
|
+
this.tasksKey(key);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (m.page === "library") {
|
|
596
|
+
this.libraryKey(key);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (m.page === "sessions") {
|
|
600
|
+
this.sessionsKey(key);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (m.page === "doctor" && key.name === "D") void this.loadDoctor(true);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
empty(page ) {
|
|
607
|
+
const m = this.model;
|
|
608
|
+
if (page === "tasks") return m.tasks.list === null;
|
|
609
|
+
if (page === "library") return m.library.docs === null;
|
|
610
|
+
if (page === "sessions") return m.sessions.list === null;
|
|
611
|
+
if (page === "agents") return m.agents.steps === null && m.agents.error === null;
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** The width of the pane a detail or reader is drawn in: the right pane on a wide screen, else the screen. */
|
|
616
|
+
paneWidth() {
|
|
617
|
+
const cols = this.model.cols;
|
|
618
|
+
if (cols < WIDE_COLS) return cols;
|
|
619
|
+
const ambiguous = this.model.paint.ambiguous;
|
|
620
|
+
return cols - Math.floor(cols * 0.44) - displayWidth(this.model.glyphs.vline, ambiguous);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** A scroll position kept within the rows there are, so scrolling back up moves at once after G. */
|
|
624
|
+
clampTop(top , rows ) {
|
|
625
|
+
const height = Math.max(1, this.model.rows - 5);
|
|
626
|
+
return Math.max(0, Math.min(top, rows - height));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
halfPage() {
|
|
630
|
+
return Math.max(1, Math.floor((this.model.rows - 6) / 2));
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** The current page's innermost layer: list, detail, expectation or reader. */
|
|
634
|
+
layer() {
|
|
635
|
+
const m = this.model;
|
|
636
|
+
if (m.page === "tasks") return m.tasks.layer;
|
|
637
|
+
if (m.page === "library") return m.library.layer;
|
|
638
|
+
if (m.page === "sessions") return m.sessions.layer;
|
|
639
|
+
return "list";
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
back() {
|
|
643
|
+
const m = this.model;
|
|
644
|
+
if (m.page === "tasks") {
|
|
645
|
+
if (m.tasks.layer === "expectation") m.tasks.layer = "detail";
|
|
646
|
+
else m.tasks.layer = "list";
|
|
647
|
+
} else if (m.page === "library") m.library.layer = "list";
|
|
648
|
+
else if (m.page === "sessions") {
|
|
649
|
+
m.sessions.layer = "list";
|
|
650
|
+
if (m.cols < WIDE_COLS) m.sessions.reader = null;
|
|
651
|
+
}
|
|
652
|
+
m.right = false;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
move(delta ) {
|
|
656
|
+
const m = this.model;
|
|
657
|
+
const now = this.now();
|
|
658
|
+
if (m.page === "tasks") {
|
|
659
|
+
const page = m.tasks;
|
|
660
|
+
if (page.layer === "expectation") {
|
|
661
|
+
page.detailView.top = this.clampTop(page.detailView.top + delta, expectationRows(m, this.paneWidth()).length);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (page.layer === "detail" || (m.right && m.cols >= WIDE_COLS)) {
|
|
665
|
+
const count = page.detail?.expectations.length ?? 0;
|
|
666
|
+
page.detailSel = Math.max(0, Math.min(count - 1, page.detailSel + delta));
|
|
667
|
+
if (page.layer === "list") page.layer = "detail";
|
|
668
|
+
this.loadLog();
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const before = page.sel;
|
|
672
|
+
page.sel = moveSelection(taskItems(m, m.cols, now), page.sel, delta);
|
|
673
|
+
if (page.sel !== before) {
|
|
674
|
+
page.detailSel = 0;
|
|
675
|
+
void this.loadTaskDetail();
|
|
676
|
+
}
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (m.page === "library") {
|
|
680
|
+
const count = facetDocs(m).length;
|
|
681
|
+
m.library.sel = Math.max(0, Math.min(count - 1, m.library.sel + delta));
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (m.page === "sessions") {
|
|
685
|
+
const page = m.sessions;
|
|
686
|
+
if (page.layer === "reader" && page.reader) {
|
|
687
|
+
page.reader.top = this.clampTop(page.reader.top + delta, readerRows(m, this.paneWidth(), false).length);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
page.sel = moveSelection(sessionItems(m, m.cols, now), page.sel, delta);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const page = m.page === "agents" ? m.agents : m.doctor;
|
|
694
|
+
const count = (m.page === "agents" ? m.agents.steps?.length : m.doctor.checks?.length) ?? 0;
|
|
695
|
+
page.sel = Math.max(0, Math.min(count - 1, page.sel + delta));
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
tasksKey(key ) {
|
|
699
|
+
const m = this.model;
|
|
700
|
+
const page = m.tasks;
|
|
701
|
+
const show = page.detail;
|
|
702
|
+
if (key.name === "enter") {
|
|
703
|
+
if (page.layer === "list") page.layer = m.cols >= WIDE_COLS && !m.right ? "detail" : "detail";
|
|
704
|
+
else if (page.layer === "detail" && (show?.expectations.length ?? 0) > 0) {
|
|
705
|
+
page.layer = "expectation";
|
|
706
|
+
page.detailView.top = 0;
|
|
707
|
+
this.loadLog();
|
|
708
|
+
}
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if ((key.name === "[" || key.name === "]") && show) {
|
|
712
|
+
page.detailSel = Math.max(
|
|
713
|
+
0,
|
|
714
|
+
Math.min(show.expectations.length - 1, page.detailSel + (key.name === "]" ? 1 : -1)),
|
|
715
|
+
);
|
|
716
|
+
page.detailView.top = 0;
|
|
717
|
+
this.loadLog();
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (key.name === "s" && show) {
|
|
721
|
+
const e = show.expectations[page.detailSel];
|
|
722
|
+
const native = (page.layer === "expectation" ? e?.runs.at(-1)?.session : null) ?? show.task.sessions[0];
|
|
723
|
+
if (native) void this.jumpToSession(native);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
// A write acts on the task under the cursor only: while its detail is still being read, H, P and C do nothing.
|
|
727
|
+
const task = show?.task ?? null;
|
|
728
|
+
if (task === null || task.id !== this.selectedTask() || task.state === "closed") return;
|
|
729
|
+
const t = m.t;
|
|
730
|
+
if (key.name === "H")
|
|
731
|
+
this.ask({
|
|
732
|
+
title: t("wHold", task.id),
|
|
733
|
+
runner: "taskstate",
|
|
734
|
+
argv: taskstateArgv("hold", task.id),
|
|
735
|
+
yOnly: false,
|
|
736
|
+
page: "tasks",
|
|
737
|
+
doneText: t("wHold", task.id),
|
|
738
|
+
});
|
|
739
|
+
else if (key.name === "P") {
|
|
740
|
+
const parked = task.state === "parked";
|
|
741
|
+
const argv = parked ? taskstateArgv("unpark", task.id) : taskstateArgv("park", task.id);
|
|
742
|
+
const title = parked ? t("wUnpark", task.id) : t("wPark", task.id);
|
|
743
|
+
this.ask({ title, runner: "taskstate", argv, yOnly: false, page: "tasks", doneText: title });
|
|
744
|
+
} else if (key.name === "C")
|
|
745
|
+
this.ask({
|
|
746
|
+
title: t("wClose", task.id),
|
|
747
|
+
runner: "taskstate",
|
|
748
|
+
argv: taskstateArgv("close", task.id),
|
|
749
|
+
yOnly: true,
|
|
750
|
+
page: "tasks",
|
|
751
|
+
doneText: t("wClose", task.id),
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
libraryKey(key ) {
|
|
756
|
+
const m = this.model;
|
|
757
|
+
const page = m.library;
|
|
758
|
+
const t = m.t;
|
|
759
|
+
if (key.name === "left" || key.name === "h" || key.name === "f" || key.name === "right" || key.name === "l") {
|
|
760
|
+
const step = key.name === "left" || key.name === "h" ? 3 : 1;
|
|
761
|
+
page.facet = ((page.facet + step) % 4) ;
|
|
762
|
+
page.sel = 0;
|
|
763
|
+
page.view.top = 0;
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (key.name === "enter") {
|
|
767
|
+
page.layer = "detail";
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (key.name === "u") {
|
|
771
|
+
this.undo();
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (key.name === "A") {
|
|
775
|
+
m.prompt = { label: t("wAddPath"), input: { text: "", cursor: 0 }, purpose: "add" };
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const doc = facetDocs(m)[page.sel];
|
|
779
|
+
if (doc === undefined) return;
|
|
780
|
+
const scope = doc.scope === "user" ? "user" : "project";
|
|
781
|
+
if (key.name === "x") {
|
|
782
|
+
const hidden = page.facet === 3;
|
|
783
|
+
const argv = ["document", hidden ? "restore" : "remove", doc.docId, "--scope", scope];
|
|
784
|
+
const undo = ["document", hidden ? "remove" : "restore", doc.docId, "--scope", scope];
|
|
785
|
+
const title = hidden ? t("wRestore", doc.title) : t("wHide", doc.title);
|
|
786
|
+
this.ask({ title, runner: "cli", argv, undo, yOnly: false, page: "library", doneText: title });
|
|
787
|
+
} else if (key.name === "E") {
|
|
788
|
+
const dir = this.directoryOf(doc);
|
|
789
|
+
if (dir === null) return;
|
|
790
|
+
this.ask({
|
|
791
|
+
title: t("wExclude", tilde(m, dir)),
|
|
792
|
+
runner: "cli",
|
|
793
|
+
argv: ["exclude", "add", dir],
|
|
794
|
+
toggle: { label: t("wHideIngested"), flag: "--hide-ingested", on: true },
|
|
795
|
+
yOnly: false,
|
|
796
|
+
page: "library",
|
|
797
|
+
doneText: t("wExclude", tilde(m, dir)),
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/** The directory a document's file lies in, from its label: under home for user, under the project root. */
|
|
803
|
+
directoryOf(doc ) {
|
|
804
|
+
const dir = documentParentDir(doc, this.model.homeDir, this.projectRoot);
|
|
805
|
+
if (dir === null) {
|
|
806
|
+
this.model.status = { text: this.model.t("failed", this.model.t("kExclude")), kind: "fail" };
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
return dir;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
sessionsKey(key ) {
|
|
813
|
+
const m = this.model;
|
|
814
|
+
const page = m.sessions;
|
|
815
|
+
const session = page.list?.[page.sel];
|
|
816
|
+
if (key.name === "enter" && session && page.layer === "list") {
|
|
817
|
+
void this.openReader(session);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (key.name === "t") {
|
|
821
|
+
const id = page.layer === "reader" ? page.reader?.session.session : session?.session;
|
|
822
|
+
const task = id ? page.links[id] : undefined;
|
|
823
|
+
if (task) void this.jumpToTask(task);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (page.layer === "reader") return;
|
|
827
|
+
if (key.name === "h") {
|
|
828
|
+
const at = HARNESS_FILTERS.indexOf(page.harness );
|
|
829
|
+
page.harness = HARNESS_FILTERS[(at + 1) % HARNESS_FILTERS.length] ?? null;
|
|
830
|
+
} else if (key.name === "left" || key.name === "right") {
|
|
831
|
+
page.range = (page.range + (key.name === "right" ? 1 : RANGES.length - 1)) % RANGES.length;
|
|
832
|
+
} else if (key.name === "s") {
|
|
833
|
+
m.prompt = {
|
|
834
|
+
label: `${m.glyphs.prompt} `,
|
|
835
|
+
input: { text: page.query, cursor: page.query.length },
|
|
836
|
+
purpose: "query",
|
|
837
|
+
};
|
|
838
|
+
return;
|
|
839
|
+
} else return;
|
|
840
|
+
page.sel = 0;
|
|
841
|
+
page.view.top = 0;
|
|
842
|
+
void this.loadSessions();
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
promptKey(key ) {
|
|
846
|
+
const m = this.model;
|
|
847
|
+
const prompt = m.prompt;
|
|
848
|
+
if (prompt === null) return;
|
|
849
|
+
if (key.name === "escape") {
|
|
850
|
+
if (prompt.input.text !== "" && prompt.purpose === "add") prompt.input = { text: "", cursor: 0 };
|
|
851
|
+
else m.prompt = null;
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
if (key.name === "enter") {
|
|
855
|
+
const text = prompt.input.text.trim();
|
|
856
|
+
m.prompt = null;
|
|
857
|
+
if (prompt.purpose === "query") {
|
|
858
|
+
m.sessions.query = text;
|
|
859
|
+
m.sessions.sel = 0;
|
|
860
|
+
void this.loadSessions();
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
if (text === "") return;
|
|
864
|
+
const dir = text.startsWith("~/") || text.startsWith("~\\") ? join(m.homeDir, text.slice(2)) : text;
|
|
865
|
+
this.ask({
|
|
866
|
+
title: m.t("wAdd", text),
|
|
867
|
+
runner: "cli",
|
|
868
|
+
argv: ["ingest", dir],
|
|
869
|
+
tier: { chosen: null },
|
|
870
|
+
yOnly: false,
|
|
871
|
+
page: "library",
|
|
872
|
+
doneText: m.t("wAdd", text),
|
|
873
|
+
});
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
prompt.input = editInput(prompt.input, key);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// ---------------------------------------------------------------------------
|
|
880
|
+
// Confirmation and writes
|
|
881
|
+
// ---------------------------------------------------------------------------
|
|
882
|
+
|
|
883
|
+
ask(confirm ) {
|
|
884
|
+
this.model.confirm = confirm;
|
|
885
|
+
// Not confirmable until a frame has shown it: a y typed in the same burst as the key that opened it does nothing.
|
|
886
|
+
this.confirmShown = false;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** The command line the bar shows for a confirmation: the same argv confirmKey runs. */
|
|
890
|
+
static commandLine(confirm ) {
|
|
891
|
+
return `${confirm.runner === "cli" ? "agent-whisker" : "taskstate"} ${shellQuote(confirmArgv(confirm))}`;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
confirmKey(key ) {
|
|
895
|
+
const m = this.model;
|
|
896
|
+
const confirm = m.confirm;
|
|
897
|
+
if (confirm === null) return;
|
|
898
|
+
if (key.name === "n" || key.name === "escape") {
|
|
899
|
+
m.confirm = null;
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (key.name === "space" && confirm.toggle) {
|
|
903
|
+
confirm.toggle.on = !confirm.toggle.on;
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (confirm.tier && (key.name === "o" || key.name === "p")) {
|
|
907
|
+
confirm.tier.chosen = key.name === "o" ? "open" : "personal";
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
const yes = key.name === "y" || (key.name === "enter" && !confirm.yOnly);
|
|
911
|
+
if (!yes) return;
|
|
912
|
+
if (confirm.tier && confirm.tier.chosen === null) return;
|
|
913
|
+
if (!this.confirmShown) return;
|
|
914
|
+
m.confirm = null;
|
|
915
|
+
void this.write(confirm);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
async write(confirm ) {
|
|
919
|
+
const m = this.model;
|
|
920
|
+
const argv = confirmArgv(confirm);
|
|
921
|
+
const command = App.commandLine(confirm);
|
|
922
|
+
m.status = { text: m.t("running", command), kind: "busy" };
|
|
923
|
+
this.onChange();
|
|
924
|
+
const result = confirm.runner === "cli" ? await this.call("cli", argv) : await this.call("taskstate", argv, false);
|
|
925
|
+
m.audit.push({ command, ok: result.ok });
|
|
926
|
+
if (!result.ok) {
|
|
927
|
+
m.status = { text: m.t("failed", `${result.code}: ${result.message}`), kind: "fail" };
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
if (confirm.page === "library")
|
|
931
|
+
m.library.last = confirm.undo ? { argv, undo: confirm.undo, title: confirm.doneText } : null;
|
|
932
|
+
await this.load(confirm.page);
|
|
933
|
+
if (confirm.page === "library") await this.loadStatus();
|
|
934
|
+
m.status = { text: `${confirm.undo ? `u ${m.t("kUndo")} · ` : ""}${m.t("done", confirm.doneText)}`, kind: "ok" };
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
undo() {
|
|
938
|
+
const m = this.model;
|
|
939
|
+
const last = m.library.last;
|
|
940
|
+
if (last === null) {
|
|
941
|
+
m.status = { text: m.t("nothingToUndo"), kind: "info" };
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
m.library.last = null;
|
|
945
|
+
const command = `agent-whisker ${shellQuote(last.undo)}`;
|
|
946
|
+
void (async () => {
|
|
947
|
+
const result = await this.call("cli", last.undo);
|
|
948
|
+
m.audit.push({ command, ok: result.ok });
|
|
949
|
+
m.status = result.ok
|
|
950
|
+
? { text: m.t("undone", last.title), kind: "ok" }
|
|
951
|
+
: { text: m.t("failed", result.ok ? "" : result.message), kind: "fail" };
|
|
952
|
+
await this.load("library");
|
|
953
|
+
})();
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// ---------------------------------------------------------------------------
|
|
957
|
+
// The search overlay
|
|
958
|
+
// ---------------------------------------------------------------------------
|
|
959
|
+
|
|
960
|
+
openSearch() {
|
|
961
|
+
this.model.search = {
|
|
962
|
+
input: { text: "", cursor: 0 },
|
|
963
|
+
mode: "library",
|
|
964
|
+
real: false,
|
|
965
|
+
hits: null,
|
|
966
|
+
avoided: null,
|
|
967
|
+
sel: 0,
|
|
968
|
+
error: null,
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
searchKey(key ) {
|
|
973
|
+
const m = this.model;
|
|
974
|
+
const search = m.search;
|
|
975
|
+
if (search === null) return;
|
|
976
|
+
if (key.name === "escape") {
|
|
977
|
+
if (search.input.text !== "") {
|
|
978
|
+
search.input = { text: "", cursor: 0 };
|
|
979
|
+
search.hits = null;
|
|
980
|
+
} else m.search = null;
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (key.ctrl && key.name === "k") {
|
|
984
|
+
m.search = null;
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (key.name === "tab") {
|
|
988
|
+
search.mode = search.mode === "library" ? "sessions" : "library";
|
|
989
|
+
this.scheduleSearch(0, false);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (key.name === "down" || key.name === "up") {
|
|
993
|
+
search.sel = Math.max(0, Math.min((search.hits?.length ?? 1) - 1, search.sel + (key.name === "down" ? 1 : -1)));
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (key.name === "enter") {
|
|
997
|
+
this.scheduleSearch(0, true);
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const before = search.input.text;
|
|
1001
|
+
search.input = editInput(search.input, key);
|
|
1002
|
+
if (search.input.text !== before) this.scheduleSearch(SEARCH_DEBOUNCE_MS, false);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
scheduleSearch(ms , real ) {
|
|
1006
|
+
if (this.searchTimer !== null) this.timers.clearTimeout(this.searchTimer);
|
|
1007
|
+
this.searchTimer = this.timers.setTimeout(() => {
|
|
1008
|
+
this.searchTimer = null;
|
|
1009
|
+
void this.runSearch(real);
|
|
1010
|
+
}, ms);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
async runSearch(real ) {
|
|
1014
|
+
const search = this.model.search;
|
|
1015
|
+
if (search === null) return;
|
|
1016
|
+
const text = search.input.text.trim();
|
|
1017
|
+
if (text === "") {
|
|
1018
|
+
search.hits = null;
|
|
1019
|
+
this.onChange();
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
search.real = real;
|
|
1023
|
+
if (search.mode === "library") {
|
|
1024
|
+
const answer = await this.call("cli", ["search", text, "--limit", "10", ...(real ? [] : ["--no-rerank"])]);
|
|
1025
|
+
if (this.model.search !== search) return;
|
|
1026
|
+
if (!answer.ok) {
|
|
1027
|
+
search.error = answer.message;
|
|
1028
|
+
search.hits = [];
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const json = answer.json
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
;
|
|
1035
|
+
search.error = null;
|
|
1036
|
+
search.hits = (json.hits ?? []).map((hit) => ({
|
|
1037
|
+
title: hit.title,
|
|
1038
|
+
tier: hit.tier,
|
|
1039
|
+
text: hit.text,
|
|
1040
|
+
source: hit.source,
|
|
1041
|
+
}));
|
|
1042
|
+
search.avoided = json.avoided ?? null;
|
|
1043
|
+
} else {
|
|
1044
|
+
const answer = await this.call("cli", ["sessions", "search", text, "--limit", "10"]);
|
|
1045
|
+
if (this.model.search !== search) return;
|
|
1046
|
+
if (!answer.ok) {
|
|
1047
|
+
search.error = answer.message;
|
|
1048
|
+
search.hits = [];
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const hits = (answer.json ).hits ?? [];
|
|
1052
|
+
search.error = null;
|
|
1053
|
+
search.avoided = null;
|
|
1054
|
+
search.hits = hits.map((hit) => ({
|
|
1055
|
+
title: hit.title,
|
|
1056
|
+
tier: hit.harness,
|
|
1057
|
+
text: hit.excerpt ?? "",
|
|
1058
|
+
source: hit.session,
|
|
1059
|
+
}));
|
|
1060
|
+
}
|
|
1061
|
+
search.sel = Math.min(search.sel, Math.max(0, search.hits.length - 1));
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// ---------------------------------------------------------------------------
|
|
1065
|
+
// View
|
|
1066
|
+
// ---------------------------------------------------------------------------
|
|
1067
|
+
|
|
1068
|
+
/** Changes the size; the next view lays everything out again. */
|
|
1069
|
+
resize(cols , rows ) {
|
|
1070
|
+
this.model.cols = cols;
|
|
1071
|
+
this.model.rows = rows;
|
|
1072
|
+
if (cols < WIDE_COLS) this.model.right = false;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/** The whole screen as rows, exactly model.rows of them. */
|
|
1076
|
+
view() {
|
|
1077
|
+
const m = this.model;
|
|
1078
|
+
const { cols, rows } = m;
|
|
1079
|
+
const a = m.paint.ambiguous;
|
|
1080
|
+
if (cols < MIN_COLS || rows < MIN_ROWS) {
|
|
1081
|
+
const out = [];
|
|
1082
|
+
for (let r = 0; r < rows; r++)
|
|
1083
|
+
out.push(r === Math.floor(rows / 2) ? fitRow(centered(m.t("tooSmall"), cols, a), cols, a) : []);
|
|
1084
|
+
return out.map((row) => fitRow(row, cols, a));
|
|
1085
|
+
}
|
|
1086
|
+
const nowMs = this.now();
|
|
1087
|
+
const wide = cols >= WIDE_COLS;
|
|
1088
|
+
const leftWidth = Math.floor(cols * 0.44);
|
|
1089
|
+
const rightWidth = cols - leftWidth - displayWidth(m.glyphs.vline, a);
|
|
1090
|
+
const split =
|
|
1091
|
+
wide && (m.page === "tasks" || m.page === "library" || m.page === "sessions") && m.search === null && !m.help;
|
|
1092
|
+
const bottom = this.bottomRows(cols);
|
|
1093
|
+
const bodyHeight = Math.max(0, rows - 2 - bottom.length);
|
|
1094
|
+
const hline = m.glyphs.hline;
|
|
1095
|
+
const sepRow = (cross ) => [
|
|
1096
|
+
{
|
|
1097
|
+
text: split ? `${rule(hline, leftWidth, a)}${cross}${rule(hline, rightWidth, a)}` : rule(hline, cols, a),
|
|
1098
|
+
style: { dim: true },
|
|
1099
|
+
},
|
|
1100
|
+
];
|
|
1101
|
+
let body ;
|
|
1102
|
+
if (m.help) body = this.helpRows(cols);
|
|
1103
|
+
else if (m.search !== null) body = this.searchRows(cols, bodyHeight);
|
|
1104
|
+
else if (split) {
|
|
1105
|
+
const [left, right] = this.splitPanes(leftWidth, rightWidth, bodyHeight, nowMs);
|
|
1106
|
+
body = besideRows(left, right, leftWidth, rightWidth, bodyHeight, m.glyphs.vline, a);
|
|
1107
|
+
} else body = this.singleRows(cols, bodyHeight, nowMs);
|
|
1108
|
+
const out = [this.tabsRow(cols), sepRow(m.glyphs.cross)];
|
|
1109
|
+
for (let r = 0; r < bodyHeight; r++) out.push(body[r] ?? []);
|
|
1110
|
+
out.push(...bottom);
|
|
1111
|
+
return out.map((row) => fitRow(row, cols, a));
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
tabsRow(cols ) {
|
|
1115
|
+
const m = this.model;
|
|
1116
|
+
const a = m.paint.ambiguous;
|
|
1117
|
+
const narrow = cols < 72;
|
|
1118
|
+
const labels = [
|
|
1119
|
+
m.t("tabTasks"),
|
|
1120
|
+
m.t("tabLibrary"),
|
|
1121
|
+
m.t("tabSessions"),
|
|
1122
|
+
m.t("tabAgents"),
|
|
1123
|
+
narrow ? m.t("tabDoctorShort") : m.t("tabDoctor"),
|
|
1124
|
+
];
|
|
1125
|
+
const spans = narrow ? [] : [{ text: ` ${m.t("appName")} `, style: { bold: true } }];
|
|
1126
|
+
labels.forEach((label, index) => {
|
|
1127
|
+
const current = PAGES[index] === m.page;
|
|
1128
|
+
const text = narrow ? `${index + 1}${label}` : `${index + 1} ${label}`;
|
|
1129
|
+
spans.push({ text: current ? `[${text}]` : ` ${text} `, style: current ? { bold: true, inverse: true } : {} });
|
|
1130
|
+
if (!narrow) spans.push({ text: " " });
|
|
1131
|
+
});
|
|
1132
|
+
const used = displayWidth(spans.map((s) => s.text).join(""), a);
|
|
1133
|
+
const right = narrow ? "^K" : `^K ${m.t("trySearch")}${m.store?.project ? ` ${m.store.project}` : ""}`;
|
|
1134
|
+
const gap = cols - used - displayWidth(right, a) - 1;
|
|
1135
|
+
if (gap > 0) spans.push({ text: " ".repeat(gap) }, { text: right, style: { dim: true } });
|
|
1136
|
+
return spans;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
splitPanes(leftWidth , rightWidth , height , nowMs ) {
|
|
1140
|
+
const m = this.model;
|
|
1141
|
+
if (m.page === "tasks") {
|
|
1142
|
+
const right =
|
|
1143
|
+
m.tasks.layer === "expectation"
|
|
1144
|
+
? scroll(expectationRows(m, rightWidth), m.tasks.detailView.top, height)
|
|
1145
|
+
: taskDetailRows(m, rightWidth, height, m.right || m.tasks.layer !== "list");
|
|
1146
|
+
return [taskListRows(m, leftWidth, height, nowMs), right];
|
|
1147
|
+
}
|
|
1148
|
+
if (m.page === "library")
|
|
1149
|
+
return [
|
|
1150
|
+
libraryListRows(m, leftWidth, height),
|
|
1151
|
+
libraryDetailRows(m, rightWidth, m.right || m.library.layer === "detail"),
|
|
1152
|
+
];
|
|
1153
|
+
const reader = m.sessions.reader;
|
|
1154
|
+
return [
|
|
1155
|
+
sessionListRows(m, leftWidth, height, nowMs),
|
|
1156
|
+
reader === null ? [] : scroll(readerRows(m, rightWidth, m.sessions.layer === "reader"), reader.top, height),
|
|
1157
|
+
];
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
singleRows(cols , height , nowMs ) {
|
|
1161
|
+
const m = this.model;
|
|
1162
|
+
if (m.page === "tasks") {
|
|
1163
|
+
if (m.tasks.layer === "expectation") return scroll(expectationRows(m, cols), m.tasks.detailView.top, height);
|
|
1164
|
+
if (m.tasks.layer === "detail") return taskDetailRows(m, cols, height, false);
|
|
1165
|
+
return taskListRows(m, cols, height, nowMs);
|
|
1166
|
+
}
|
|
1167
|
+
if (m.page === "library")
|
|
1168
|
+
return m.library.layer === "detail" ? libraryDetailRows(m, cols, false) : libraryListRows(m, cols, height);
|
|
1169
|
+
if (m.page === "sessions") {
|
|
1170
|
+
const reader = m.sessions.reader;
|
|
1171
|
+
if (m.sessions.layer === "reader" && reader !== null)
|
|
1172
|
+
return scroll(readerRows(m, cols, false), reader.top, height);
|
|
1173
|
+
return sessionListRows(m, cols, height, nowMs);
|
|
1174
|
+
}
|
|
1175
|
+
if (m.page === "agents") return agentsRows(m, cols, height);
|
|
1176
|
+
return doctorRows(m, cols, height);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
searchRows(cols , height ) {
|
|
1180
|
+
const m = this.model;
|
|
1181
|
+
const search = m.search;
|
|
1182
|
+
if (search === null) return [];
|
|
1183
|
+
const a = m.paint.ambiguous;
|
|
1184
|
+
const view = m.store?.project ? `${m.store.project}+${m.t("viewUser")}` : m.t("viewUser");
|
|
1185
|
+
const rows = [
|
|
1186
|
+
fitRow(
|
|
1187
|
+
[
|
|
1188
|
+
{ text: ` ${m.t("searchTitle", `${m.glyphs.personal} personal`, view)}`, style: { bold: true } },
|
|
1189
|
+
{
|
|
1190
|
+
text: ` [${search.mode === "library" ? m.t("searchLibrary") : m.t("searchSessions")}]`,
|
|
1191
|
+
style: { dim: true },
|
|
1192
|
+
},
|
|
1193
|
+
],
|
|
1194
|
+
cols,
|
|
1195
|
+
a,
|
|
1196
|
+
),
|
|
1197
|
+
inputRow(` ${m.glyphs.prompt} `, search.input, cols, a),
|
|
1198
|
+
[{ text: rule(m.glyphs.hline, cols, a), style: { dim: true } }],
|
|
1199
|
+
];
|
|
1200
|
+
const foot = [];
|
|
1201
|
+
if (search.avoided && search.mode === "library")
|
|
1202
|
+
foot.push(line(` ${m.t("searchAvoided", search.avoided.removed, search.avoided.excluded)}`, { dim: true }));
|
|
1203
|
+
foot.push(line(` ${search.real ? m.t("searchReal") : m.t("searchTyping")}`, { dim: true }));
|
|
1204
|
+
const room = height - rows.length - foot.length;
|
|
1205
|
+
const hits = [];
|
|
1206
|
+
if (search.error !== null) hits.push(line(` ${m.t("failed", search.error)}`, { fg: "red" }));
|
|
1207
|
+
else if (search.hits !== null && search.hits.length === 0) hits.push(line(` ${m.t("searchNone")}`, { dim: true }));
|
|
1208
|
+
for (const [index, hit] of (search.hits ?? []).entries()) {
|
|
1209
|
+
const selected = index === search.sel;
|
|
1210
|
+
const glyph = search.mode === "library" ? (hit.tier === "open" ? m.glyphs.open : m.glyphs.personal) : hit.tier;
|
|
1211
|
+
const head = fitRow(
|
|
1212
|
+
[
|
|
1213
|
+
{ text: `${selected ? m.glyphs.cursor : " "}${index + 1} ${glyph} ` },
|
|
1214
|
+
{ text: hit.title || hit.source, style: { bold: true } },
|
|
1215
|
+
],
|
|
1216
|
+
cols,
|
|
1217
|
+
a,
|
|
1218
|
+
);
|
|
1219
|
+
hits.push(selected ? head.map((span) => ({ text: span.text, style: { ...span.style, inverse: true } })) : head);
|
|
1220
|
+
const excerpt = hit.text.replace(/\s+/gu, " ").trim();
|
|
1221
|
+
if (excerpt) hits.push(...wrapped(`${m.glyphs.more}${excerpt}`, cols, a, { dim: true }, 3).slice(0, 1));
|
|
1222
|
+
}
|
|
1223
|
+
return [
|
|
1224
|
+
...rows,
|
|
1225
|
+
...hits.slice(0, Math.max(0, room)),
|
|
1226
|
+
...Array.from({ length: Math.max(0, room - hits.length) }, () => [] ),
|
|
1227
|
+
...foot,
|
|
1228
|
+
];
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
helpRows(cols ) {
|
|
1232
|
+
const m = this.model;
|
|
1233
|
+
const rows = [line(` ${m.t("helpTitle")} · ${m.t("helpClose")}`, { bold: true })];
|
|
1234
|
+
for (const hint of this.hints())
|
|
1235
|
+
rows.push(
|
|
1236
|
+
fitRow(
|
|
1237
|
+
[{ text: ` ${hint.key.padEnd(8)}`, style: { bold: true } }, { text: hint.label }],
|
|
1238
|
+
cols,
|
|
1239
|
+
m.paint.ambiguous,
|
|
1240
|
+
),
|
|
1241
|
+
);
|
|
1242
|
+
rows.push(line(" ^C quit · ^Z suspend · Esc back", { dim: true }));
|
|
1243
|
+
return rows;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
/** The hints of the current layer, by priority. */
|
|
1247
|
+
hints() {
|
|
1248
|
+
const m = this.model;
|
|
1249
|
+
const t = m.t;
|
|
1250
|
+
const layer = this.layer();
|
|
1251
|
+
const common = [
|
|
1252
|
+
{ key: "j/k", label: t("kMove"), prio: 5 },
|
|
1253
|
+
{ key: "^K", label: t("kSearch"), prio: 6 },
|
|
1254
|
+
{ key: "1-5", label: t("kPages"), prio: 3 },
|
|
1255
|
+
{ key: "r", label: t("kRefresh"), prio: 1 },
|
|
1256
|
+
{ key: "q", label: t("kQuit"), prio: 2 },
|
|
1257
|
+
];
|
|
1258
|
+
const back = { key: "Esc", label: t("kBack"), prio: 8 };
|
|
1259
|
+
if (m.page === "tasks") {
|
|
1260
|
+
const writes = [
|
|
1261
|
+
{ key: "H", label: t("kHold"), prio: 7 },
|
|
1262
|
+
{ key: "P", label: t("kPark"), prio: 7 },
|
|
1263
|
+
{ key: "C", label: t("kClose"), prio: 7 },
|
|
1264
|
+
];
|
|
1265
|
+
if (layer === "list")
|
|
1266
|
+
return [
|
|
1267
|
+
{ key: "↵", label: t("kOpen"), prio: 9 },
|
|
1268
|
+
...writes,
|
|
1269
|
+
...common,
|
|
1270
|
+
...(m.cols >= WIDE_COLS ? [{ key: "Tab", label: t("kPane"), prio: 4 }] : []),
|
|
1271
|
+
];
|
|
1272
|
+
if (layer === "detail")
|
|
1273
|
+
return [
|
|
1274
|
+
{ key: "↵", label: t("kLog"), prio: 9 },
|
|
1275
|
+
...writes,
|
|
1276
|
+
back,
|
|
1277
|
+
{ key: "s", label: t("kJumpSession"), prio: 4 },
|
|
1278
|
+
...common,
|
|
1279
|
+
];
|
|
1280
|
+
return [
|
|
1281
|
+
{ key: "[/]", label: t("kMove"), prio: 9 },
|
|
1282
|
+
{ key: "s", label: t("kJumpSession"), prio: 6 },
|
|
1283
|
+
back,
|
|
1284
|
+
...common,
|
|
1285
|
+
];
|
|
1286
|
+
}
|
|
1287
|
+
if (m.page === "library")
|
|
1288
|
+
return [
|
|
1289
|
+
{ key: "x", label: t("kHide"), prio: 9 },
|
|
1290
|
+
{ key: "u", label: t("kUndo"), prio: 8 },
|
|
1291
|
+
{ key: "E", label: t("kExclude"), prio: 8 },
|
|
1292
|
+
{ key: "A", label: t("kAdd"), prio: 6 },
|
|
1293
|
+
{ key: "←→", label: t("kFacet"), prio: 7 },
|
|
1294
|
+
...(layer === "detail" ? [back] : [{ key: "↵", label: t("kOpen"), prio: 5 }]),
|
|
1295
|
+
...common,
|
|
1296
|
+
];
|
|
1297
|
+
if (m.page === "sessions") {
|
|
1298
|
+
if (layer === "reader")
|
|
1299
|
+
return [
|
|
1300
|
+
{ key: "j/k", label: t("kScroll"), prio: 9 },
|
|
1301
|
+
{ key: "t", label: t("kJumpTask"), prio: 8 },
|
|
1302
|
+
back,
|
|
1303
|
+
...common.slice(1),
|
|
1304
|
+
];
|
|
1305
|
+
return [
|
|
1306
|
+
{ key: "↵", label: t("kRead"), prio: 9 },
|
|
1307
|
+
{ key: "t", label: t("kJumpTask"), prio: 8 },
|
|
1308
|
+
{ key: "h", label: t("kHarness"), prio: 7 },
|
|
1309
|
+
{ key: "←→", label: t("kRange"), prio: 7 },
|
|
1310
|
+
{ key: "s", label: t("kFilter"), prio: 6 },
|
|
1311
|
+
...common,
|
|
1312
|
+
];
|
|
1313
|
+
}
|
|
1314
|
+
if (m.page === "doctor") return [{ key: "D", label: t("kDoctor"), prio: 9 }, ...common];
|
|
1315
|
+
return common;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
bottomRows(cols ) {
|
|
1319
|
+
const m = this.model;
|
|
1320
|
+
const a = m.paint.ambiguous;
|
|
1321
|
+
const hline = [{ text: rule(m.glyphs.hline, cols, a), style: { dim: true } }];
|
|
1322
|
+
if (m.confirm !== null) {
|
|
1323
|
+
const confirm = m.confirm;
|
|
1324
|
+
const rows = [hline, fitRow(line(` ${confirm.title}`, { bold: true }), cols, a)];
|
|
1325
|
+
if (confirm.toggle)
|
|
1326
|
+
rows.push(
|
|
1327
|
+
fitRow(
|
|
1328
|
+
[
|
|
1329
|
+
{ text: ` [${confirm.toggle.on ? "x" : " "}] ${confirm.toggle.label} ` },
|
|
1330
|
+
{ text: m.t("confirmToggle"), style: { dim: true } },
|
|
1331
|
+
],
|
|
1332
|
+
cols,
|
|
1333
|
+
a,
|
|
1334
|
+
),
|
|
1335
|
+
);
|
|
1336
|
+
if (confirm.tier) {
|
|
1337
|
+
const chosen = confirm.tier.chosen;
|
|
1338
|
+
rows.push(
|
|
1339
|
+
fitRow(
|
|
1340
|
+
[
|
|
1341
|
+
{ text: ` ${m.t("confirmChoose")} ` },
|
|
1342
|
+
{ text: `${m.glyphs.open} open`, style: chosen === "open" ? { inverse: true } : { dim: true } },
|
|
1343
|
+
{ text: " " },
|
|
1344
|
+
{
|
|
1345
|
+
text: `${m.glyphs.personal} personal`,
|
|
1346
|
+
style: chosen === "personal" ? { inverse: true } : { dim: true },
|
|
1347
|
+
},
|
|
1348
|
+
],
|
|
1349
|
+
cols,
|
|
1350
|
+
a,
|
|
1351
|
+
),
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
// The command is wrapped, never cut: what is confirmed is the whole command.
|
|
1355
|
+
for (const piece of wrap(`$ ${App.commandLine(confirm)}`, cols - 1, a))
|
|
1356
|
+
rows.push(line(` ${piece}`, { bold: true }));
|
|
1357
|
+
rows.push(
|
|
1358
|
+
fitRow(
|
|
1359
|
+
[
|
|
1360
|
+
{ text: ` ${confirm.yOnly ? m.t("confirmYesOnly") : m.t("confirmYes")} `, style: { bold: true } },
|
|
1361
|
+
{ text: m.t("confirmNo"), style: { dim: true } },
|
|
1362
|
+
],
|
|
1363
|
+
cols,
|
|
1364
|
+
a,
|
|
1365
|
+
),
|
|
1366
|
+
);
|
|
1367
|
+
// A command too long for this screen cannot be confirmed here: the bar says so and y does nothing.
|
|
1368
|
+
this.confirmShown = rows.length <= m.rows - 2;
|
|
1369
|
+
if (!this.confirmShown)
|
|
1370
|
+
return [
|
|
1371
|
+
hline,
|
|
1372
|
+
fitRow(line(` ${m.t("confirmTooLong")}`, { fg: "yellow" }), cols, a),
|
|
1373
|
+
fitRow(line(` ${m.t("confirmNo")}`, { dim: true }), cols, a),
|
|
1374
|
+
];
|
|
1375
|
+
return rows;
|
|
1376
|
+
}
|
|
1377
|
+
if (m.prompt !== null)
|
|
1378
|
+
return [
|
|
1379
|
+
hline,
|
|
1380
|
+
inputRow(` ${m.prompt.label}`, m.prompt.input, cols, a),
|
|
1381
|
+
fitRow(line(` ↵ Esc ${m.t("kBack")}`, { dim: true }), cols, a),
|
|
1382
|
+
];
|
|
1383
|
+
const status = m.status;
|
|
1384
|
+
const busy = this.pending > 0 && status?.kind !== "paused";
|
|
1385
|
+
const statusRow = busy
|
|
1386
|
+
? line(` ${m.glyphs.busy} ${status?.kind === "busy" ? status.text : m.t("loading")}`, { dim: true })
|
|
1387
|
+
: status === null
|
|
1388
|
+
? []
|
|
1389
|
+
: [
|
|
1390
|
+
{
|
|
1391
|
+
text: ` ${status.kind === "ok" ? m.glyphs.ok : status.kind === "fail" ? m.glyphs.fail : status.kind === "paused" ? m.glyphs.paused : " "} `,
|
|
1392
|
+
style:
|
|
1393
|
+
status.kind === "fail"
|
|
1394
|
+
? { fg: "red" }
|
|
1395
|
+
: status.kind === "ok"
|
|
1396
|
+
? { fg: "green" }
|
|
1397
|
+
: status.kind === "paused"
|
|
1398
|
+
? { fg: "yellow" }
|
|
1399
|
+
: { dim: true },
|
|
1400
|
+
},
|
|
1401
|
+
{ text: status.text, style: { dim: true } },
|
|
1402
|
+
];
|
|
1403
|
+
return [
|
|
1404
|
+
hline,
|
|
1405
|
+
fitRow(statusRow, cols, a),
|
|
1406
|
+
hintBar(m.search ? this.searchHints() : this.hints(), cols, a, m.t("more")),
|
|
1407
|
+
];
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
searchHints() {
|
|
1411
|
+
const t = this.model.t;
|
|
1412
|
+
return [
|
|
1413
|
+
{ key: "↵", label: t("searchReal").split(":")[0] ?? "", prio: 9 },
|
|
1414
|
+
{ key: "Tab", label: `${t("searchLibrary")}/${t("searchSessions")}`, prio: 7 },
|
|
1415
|
+
{ key: "↑↓", label: t("kMove"), prio: 6 },
|
|
1416
|
+
{ key: "Esc", label: t("kBack"), prio: 8 },
|
|
1417
|
+
];
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/** rows from top, height of them (top clamped so the last screenful stays full). */
|
|
1422
|
+
function scroll(rows , top , height ) {
|
|
1423
|
+
const start = Math.max(0, Math.min(top, rows.length - height));
|
|
1424
|
+
return rows.slice(start, start + height);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
function centered(text , cols , ambiguous ) {
|
|
1428
|
+
const w = displayWidth(text, ambiguous);
|
|
1429
|
+
return [{ text: " ".repeat(Math.max(0, Math.floor((cols - w) / 2))) + text, style: { bold: true } }];
|
|
1430
|
+
}
|