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,297 @@
|
|
|
1
|
+
// The Tasks page: taskstate's tasks, and for each expectation three columns read off taskstate's own facts
|
|
2
|
+
// (baseline: a red run of the same command; evidence: a usable passing run; conclusion: the latest verdict). Shapes
|
|
3
|
+
// carry the meaning: ◆ met or passed, ◇ needs review or no red baseline, ⊘ void, ✕ not met, · nothing yet. A claim is
|
|
4
|
+
// shown only as the agent's own words, never as evidence; a gap's proposed check is shown as text and never offered
|
|
5
|
+
// to run. Nothing here decides a verdict: every mark comes from `taskstate show --json` and `list --json`.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { displayWidth, fit } from "../term/width.js";
|
|
9
|
+
import { fitRow, line, listRows, wrapped } from "../ui/widgets.js";
|
|
10
|
+
import { ago, noteRow, tilde, titleRow } from "./common.js";
|
|
11
|
+
|
|
12
|
+
/** A mark for the list: one glyph per expectation, from its latest conclusion. */
|
|
13
|
+
function markOf(model , e ) {
|
|
14
|
+
const g = model.glyphs;
|
|
15
|
+
if (e.verdict === null) return { text: g.none, style: { dim: true } };
|
|
16
|
+
if (e.stale) return { text: g.review, style: { fg: "yellow" } };
|
|
17
|
+
if (e.verdict === "met") return { text: g.met, style: { fg: "green" } };
|
|
18
|
+
if (e.verdict === "not-met") return { text: g.notMet, style: { fg: "red" } };
|
|
19
|
+
return { text: g.review, style: { fg: "yellow" } };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The tasks as list items: open and held first, then a parked heading and the parked, then closed. */
|
|
23
|
+
export function taskItems(model , width , nowMs ) {
|
|
24
|
+
const list = model.tasks.list ?? [];
|
|
25
|
+
const a = model.paint.ambiguous;
|
|
26
|
+
const groups = [
|
|
27
|
+
[null, list.filter((task) => task.state === "open" || task.state === "held").reverse()],
|
|
28
|
+
[model.t("groupParked"), list.filter((task) => task.state === "parked").reverse()],
|
|
29
|
+
[model.t("groupClosed"), list.filter((task) => task.state === "closed").reverse()],
|
|
30
|
+
];
|
|
31
|
+
const items = [];
|
|
32
|
+
for (const [heading, tasks] of groups) {
|
|
33
|
+
if (tasks.length === 0) continue;
|
|
34
|
+
if (heading !== null)
|
|
35
|
+
items.push({
|
|
36
|
+
rows: [
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
text: `${model.glyphs.hline}${model.glyphs.hline} ${heading} ${model.glyphs.hline}${model.glyphs.hline}`,
|
|
40
|
+
style: { dim: true },
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
],
|
|
44
|
+
selectable: false,
|
|
45
|
+
});
|
|
46
|
+
for (const task of tasks) {
|
|
47
|
+
const marks = task.expectations.slice(0, 8).map((e) => markOf(model, e));
|
|
48
|
+
const age = ago(model, task.last, nowMs);
|
|
49
|
+
const id = `${task.id}${task.state === "held" ? "*" : ""}`;
|
|
50
|
+
const room = Math.max(4, width - 1 - displayWidth(id, a) - 2 - 9 - 7);
|
|
51
|
+
items.push({
|
|
52
|
+
key: task.id,
|
|
53
|
+
selectable: true,
|
|
54
|
+
rows: [
|
|
55
|
+
[
|
|
56
|
+
{ text: id, style: { bold: true } },
|
|
57
|
+
{ text: ` ${fit(task.goal, room, a)} ` },
|
|
58
|
+
...marks,
|
|
59
|
+
{ text: " ".repeat(Math.max(1, 9 - marks.reduce((sum, mark) => sum + displayWidth(mark.text, a), 0))) },
|
|
60
|
+
{ text: fit(age, 6, a), style: { dim: true } },
|
|
61
|
+
],
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return items;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The task list with its summary line above. */
|
|
70
|
+
export function taskListRows(model , width , height , nowMs ) {
|
|
71
|
+
const page = model.tasks;
|
|
72
|
+
if (page.error !== null) return [noteRow(model.t("tasksNoTaskstate", page.error))];
|
|
73
|
+
if (page.list === null) return [noteRow(model.t("loading"))];
|
|
74
|
+
if (page.list.length === 0) return [noteRow(model.t("tasksNone"))];
|
|
75
|
+
const count = (state ) => page.list?.filter((task) => task.state === state).length ?? 0;
|
|
76
|
+
const head = line(` ${model.t("tasksSummary", count("open") + count("held"), count("parked"), count("closed"))}`, {
|
|
77
|
+
dim: true,
|
|
78
|
+
});
|
|
79
|
+
const items = taskItems(model, width, nowMs);
|
|
80
|
+
return [
|
|
81
|
+
head,
|
|
82
|
+
...listRows(items, page.sel, height - 1, width, page.view, model.glyphs, model.paint, (k, n) => model.t(k, n)),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A cell as spans in width columns: its glyph (the first character) in the cell's colour, the words after it plain,
|
|
90
|
+
* so colour stays a small share of the screen and only repeats what the shape says.
|
|
91
|
+
*/
|
|
92
|
+
function cellSpans(cell , width , model ) {
|
|
93
|
+
const text = fit(cell.text, width, model.paint.ambiguous);
|
|
94
|
+
const glyph = [...text][0] ?? "";
|
|
95
|
+
const rest = text.slice(glyph.length);
|
|
96
|
+
const words = cell.style?.dim ? { dim: true } : undefined;
|
|
97
|
+
return [
|
|
98
|
+
{ text: glyph, ...(cell.style ? { style: cell.style } : {}) },
|
|
99
|
+
{ text: rest, ...(words ? { style: words } : {}) },
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The three columns of an expectation, from its facts and conclusion. */
|
|
104
|
+
function columnsOf(model , e ) {
|
|
105
|
+
const g = model.glyphs;
|
|
106
|
+
const t = model.t;
|
|
107
|
+
const red = e.seenRed.at(-1);
|
|
108
|
+
const baseline = red
|
|
109
|
+
? { text: `${g.met} ${t("redSeen", red)}`, style: { fg: "green" } }
|
|
110
|
+
: e.core
|
|
111
|
+
? { text: `${g.review} ${t("noRedBaseline")}`, style: { fg: "yellow" } }
|
|
112
|
+
: { text: "—", style: { dim: true } };
|
|
113
|
+
const usable = e.usable.at(-1);
|
|
114
|
+
const voidRun = e.passing.filter((id) => !e.usable.includes(id)).at(-1);
|
|
115
|
+
let evidence ;
|
|
116
|
+
if (usable) evidence = { text: `${g.met} ${t("passed", usable)}`, style: { fg: "green" } };
|
|
117
|
+
else if (voidRun) {
|
|
118
|
+
const why = e.changed[voidRun]?.map((path) => path.split("/").at(-1) ?? path).join(", ");
|
|
119
|
+
const again = e.failed[voidRun]?.join(", ");
|
|
120
|
+
const note = why ? t("changedNote", why) : again ? t("failedAgainNote", again) : null;
|
|
121
|
+
evidence = { text: `${g.void} ${t("voided", voidRun)}`, style: { fg: "red" }, ...(note === null ? {} : { note }) };
|
|
122
|
+
} else {
|
|
123
|
+
const last = e.runs.filter((run) => !run.expectFail).at(-1);
|
|
124
|
+
evidence = last
|
|
125
|
+
? { text: `${g.notMet} ${t("failedRun", last.id)}`, style: { fg: "red" } }
|
|
126
|
+
: { text: g.none, style: { dim: true } };
|
|
127
|
+
}
|
|
128
|
+
const v = e.conclusion;
|
|
129
|
+
let conclusion ;
|
|
130
|
+
if (v === null) conclusion = { text: g.none, style: { dim: true } };
|
|
131
|
+
else {
|
|
132
|
+
const word = v.verdict === "met" ? t("met") : v.verdict === "not-met" ? t("notMet") : t("notVerified");
|
|
133
|
+
const glyph = v.verdict === "met" ? g.met : v.verdict === "not-met" ? g.notMet : g.review;
|
|
134
|
+
const extra = [v.stale ? `→ ${t("stale")}` : "", v.selfReview ? t("selfReview") : ""].filter(Boolean).join(" · ");
|
|
135
|
+
conclusion = {
|
|
136
|
+
text: `${glyph} ${word}${extra ? ` ${extra}` : ""}`,
|
|
137
|
+
style: {
|
|
138
|
+
fg:
|
|
139
|
+
v.stale || v.selfReview
|
|
140
|
+
? "yellow"
|
|
141
|
+
: v.verdict === "met"
|
|
142
|
+
? "green"
|
|
143
|
+
: v.verdict === "not-met"
|
|
144
|
+
? "red"
|
|
145
|
+
: "yellow",
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return { baseline, evidence, conclusion };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The selected task's detail: its head, the three-column table, the gaps. */
|
|
153
|
+
export function taskDetailRows(model , width , height , focused ) {
|
|
154
|
+
const page = model.tasks;
|
|
155
|
+
const show = page.detail;
|
|
156
|
+
const a = model.paint.ambiguous;
|
|
157
|
+
if (show === null) return [noteRow(page.list === null ? model.t("loading") : "")];
|
|
158
|
+
const task = show.task;
|
|
159
|
+
const rows = [];
|
|
160
|
+
rows.push(fitRow([...titleRow(task.id, focused), { text: ` ${task.goal}`, style: { bold: true } }], width, a));
|
|
161
|
+
const where = [
|
|
162
|
+
task.cwd ? tilde(model, task.cwd) : "",
|
|
163
|
+
model.t("sessionsOfTask", task.sessions.length),
|
|
164
|
+
stateWord(model, task.state),
|
|
165
|
+
]
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.join(" · ");
|
|
168
|
+
rows.push(line(` ${where}`, { dim: true }));
|
|
169
|
+
const exps = show.expectations;
|
|
170
|
+
const withEvidence = exps.filter((e) => e.usable.length > 0).length;
|
|
171
|
+
const met = exps.filter((e) => e.conclusion?.verdict === "met" && !e.conclusion.stale).length;
|
|
172
|
+
rows.push(line(` ${model.t("expSummary", exps.length, withEvidence, met, show.gaps.length)}`));
|
|
173
|
+
const label = Math.max(9, Math.min(24, Math.floor(width * 0.24)));
|
|
174
|
+
const col = Math.max(8, Math.floor((width - label - 1) / 3));
|
|
175
|
+
const last = Math.max(8, width - label - 1 - col * 2);
|
|
176
|
+
rows.push([
|
|
177
|
+
{ text: " ".repeat(label + 1) },
|
|
178
|
+
{ text: fit(model.t("colBaseline"), col, a), style: { dim: true } },
|
|
179
|
+
{ text: fit(model.t("colEvidence"), col, a), style: { dim: true } },
|
|
180
|
+
{ text: fit(model.t("colConclusion"), last, a), style: { dim: true } },
|
|
181
|
+
]);
|
|
182
|
+
exps.forEach((e, index) => {
|
|
183
|
+
const { baseline, evidence, conclusion } = columnsOf(model, e);
|
|
184
|
+
const selected = page.layer !== "list" && index === page.detailSel;
|
|
185
|
+
const name = `${selected ? model.glyphs.cursor : " "}${e.id}${e.core ? ` ${model.t("core")}` : ""}`;
|
|
186
|
+
const cells = [
|
|
187
|
+
{ text: fit(name, label + 1, a), style: selected ? { inverse: true, bold: true } : { bold: true } },
|
|
188
|
+
...cellSpans(baseline, col, model),
|
|
189
|
+
...cellSpans(evidence, col, model),
|
|
190
|
+
...cellSpans(conclusion, last, model),
|
|
191
|
+
];
|
|
192
|
+
rows.push(cells);
|
|
193
|
+
// A reason that does not fit its column goes on the next line, never cut away.
|
|
194
|
+
for (const note of [evidence.note].filter((n) => n !== undefined))
|
|
195
|
+
rows.push(...wrapped(`${model.glyphs.branch} ${note}`, width, a, { dim: true }, 3));
|
|
196
|
+
if (width >= 72) rows.push(...wrapped(e.text, width, a, { dim: true }, 3).slice(0, 1));
|
|
197
|
+
});
|
|
198
|
+
if (show.gaps.length > 0) {
|
|
199
|
+
rows.push([]);
|
|
200
|
+
rows.push(line(` ${model.t("gapsTitle", show.gaps.length)}`, { dim: true }));
|
|
201
|
+
for (const gap of show.gaps) {
|
|
202
|
+
rows.push(...wrapped(`${model.glyphs.quote} ${gap.id} ${gap.text}`, width, a, { dim: true }, 2));
|
|
203
|
+
if (gap.check)
|
|
204
|
+
rows.push(...wrapped(`${model.glyphs.quote} ${model.t("gapCheck", gap.check)}`, width, a, { dim: true }, 2));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return rows.slice(0, height);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function stateWord(model , state ) {
|
|
211
|
+
return state === "parked"
|
|
212
|
+
? model.t("stateParked")
|
|
213
|
+
: state === "held"
|
|
214
|
+
? model.t("stateHeld")
|
|
215
|
+
: state === "closed"
|
|
216
|
+
? model.t("stateClosed")
|
|
217
|
+
: model.t("stateOpen");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** One expectation in full: its runs with their notes, the conclusion, the reasons, the claims, the latest run's log. */
|
|
221
|
+
export function expectationRows(model , width ) {
|
|
222
|
+
const show = model.tasks.detail;
|
|
223
|
+
const e = show?.expectations[model.tasks.detailSel];
|
|
224
|
+
if (!show || !e) return [];
|
|
225
|
+
const a = model.paint.ambiguous;
|
|
226
|
+
const g = model.glyphs;
|
|
227
|
+
const t = model.t;
|
|
228
|
+
const rows = [];
|
|
229
|
+
rows.push(
|
|
230
|
+
...wrapped(`${show.task.id} › ${e.id}${e.core ? ` ${t("core")}` : ""} ${e.text}`, width, a, { bold: true }, 1),
|
|
231
|
+
);
|
|
232
|
+
const { baseline, evidence, conclusion } = columnsOf(model, e);
|
|
233
|
+
const names = [t("colBaseline"), t("colEvidence"), t("colConclusion")];
|
|
234
|
+
const nameWidth = Math.max(...names.map((name) => displayWidth(name, a)));
|
|
235
|
+
for (const [index, cell] of [baseline, evidence, conclusion].entries()) {
|
|
236
|
+
rows.push([
|
|
237
|
+
{ text: ` ${fit(names[index] ?? "", nameWidth, a)} `, style: { dim: true } },
|
|
238
|
+
...cellSpans(cell, width - nameWidth - 3, model),
|
|
239
|
+
]);
|
|
240
|
+
if (cell.note) rows.push(...wrapped(`${g.branch} ${cell.note}`, width, a, { dim: true }, nameWidth + 3));
|
|
241
|
+
}
|
|
242
|
+
rows.push(line(` ${t("runsTitle")}`, { bold: true }));
|
|
243
|
+
for (const run of e.runs) {
|
|
244
|
+
const ok = run.ok;
|
|
245
|
+
const mark = run.expectFail ? g.met : e.usable.includes(run.id) ? g.met : ok ? g.void : g.notMet;
|
|
246
|
+
const style = { fg: run.expectFail || e.usable.includes(run.id) ? "green" : ok ? "red" : "red" };
|
|
247
|
+
rows.push(
|
|
248
|
+
fitRow(
|
|
249
|
+
[
|
|
250
|
+
{ text: ` ${mark} `, style },
|
|
251
|
+
{ text: `${run.id} exit ${run.exit}${run.expectFail ? " (expect-fail)" : ""}`, style: { bold: true } },
|
|
252
|
+
{ text: ` ${run.commit ?? ""} ${run.command}`, style: { dim: true } },
|
|
253
|
+
],
|
|
254
|
+
width,
|
|
255
|
+
a,
|
|
256
|
+
),
|
|
257
|
+
);
|
|
258
|
+
if (run.dirty) rows.push(...wrapped(t("dirtyNote"), width, a, { dim: true }, 5));
|
|
259
|
+
const changed = e.changed[run.id];
|
|
260
|
+
if (changed)
|
|
261
|
+
rows.push(...wrapped(`${g.branch} ${t("changedNote", changed.join(", "))}`, width, a, { dim: true }, 3));
|
|
262
|
+
const again = e.failed[run.id];
|
|
263
|
+
if (again)
|
|
264
|
+
rows.push(...wrapped(`${g.branch} ${t("failedAgainNote", again.join(", "))}`, width, a, { dim: true }, 3));
|
|
265
|
+
}
|
|
266
|
+
const v = e.conclusion;
|
|
267
|
+
rows.push(
|
|
268
|
+
v === null
|
|
269
|
+
? line(` ${t("noConclusion")}`, { dim: true })
|
|
270
|
+
: line(` ${v.id} ${t("conclusionBy", v.verdict, v.basis.join(","), v.agent ?? v.session ?? "?")}`, { dim: true }),
|
|
271
|
+
);
|
|
272
|
+
if (v?.notCovered) rows.push(...wrapped(`${g.quote} ${v.notCovered}`, width, a, { dim: true }, 2));
|
|
273
|
+
if (e.reasons.length > 0) {
|
|
274
|
+
rows.push(line(` ${t("reasonsTitle")}`, { bold: true }));
|
|
275
|
+
for (const why of e.reasons) rows.push(...wrapped(`- ${why}`, width, a, undefined, 2));
|
|
276
|
+
}
|
|
277
|
+
const claims = show.claims.filter((claim) => claim.for === e.id || claim.for === null).slice(-3);
|
|
278
|
+
if (claims.length > 0) {
|
|
279
|
+
rows.push(line(` ${t("claimsTitle")}`, { dim: true }));
|
|
280
|
+
for (const claim of claims)
|
|
281
|
+
rows.push(...wrapped(`${g.quote} "${claim.text}" ${claim.id}`, width, a, { dim: true }, 2));
|
|
282
|
+
}
|
|
283
|
+
const log = model.tasks.log;
|
|
284
|
+
if (log !== null) {
|
|
285
|
+
rows.push(line(` ${t("logTitle", log.run, log.lines.length)}`, { bold: true }));
|
|
286
|
+
if (log.lines.length === 0) rows.push(line(` ${t("logMissing", log.run)}`, { dim: true }));
|
|
287
|
+
for (const text of log.lines)
|
|
288
|
+
rows.push(fitRow([{ text: ` ${g.quote} `, style: { dim: true } }, { text }], width, a));
|
|
289
|
+
}
|
|
290
|
+
return rows;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** The latest run of the selected expectation, whose log the expectation view shows. */
|
|
294
|
+
export function latestRun(model ) {
|
|
295
|
+
const e = model.tasks.detail?.expectations[model.tasks.detailSel];
|
|
296
|
+
return e?.runs.at(-1)?.id ?? null;
|
|
297
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// The loop: a terminal session around an App. Keys are decoded and handed to the app; a change asks for a frame,
|
|
2
|
+
// drawn at most once per FRAME_MS (holding j down draws only the last state); a resize or a resume draws everything
|
|
3
|
+
// again; the probe compares store stamps every 2 s (10 s when idle) and reads the page again only when they changed.
|
|
4
|
+
// Every way out restores the terminal before anything is printed, then the writes this session ran are printed to
|
|
5
|
+
// stderr as an audit, so they stay in the scrollback after the alternate screen is gone.
|
|
6
|
+
import { App, } from "./app.js";
|
|
7
|
+
import { IDLE_AFTER_MS, POLL_ACTIVE_MS, POLL_IDLE_MS, probeStamp } from "./data/poll.js";
|
|
8
|
+
|
|
9
|
+
import { ESC_WAIT_MS, KeyDecoder } from "./term/keys.js";
|
|
10
|
+
import { encodeRow, flush } from "./term/screen.js";
|
|
11
|
+
import { AMBIGUOUS_PROBE, ambiguousFromReport, Terminal, } from "./term/term.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/** At most one frame per 16 ms. */
|
|
15
|
+
const FRAME_MS = 16;
|
|
16
|
+
/** How long the ambiguous-width probe waits for the terminal's answer: 200 ms, then one column is assumed. */
|
|
17
|
+
const PROBE_MS = 200;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/** Runs the interface until q, Ctrl+C or a signal; resolves to the exit code. */
|
|
35
|
+
export async function runTui(options ) {
|
|
36
|
+
const { tty, timers, now } = options;
|
|
37
|
+
const term = new Terminal(tty, timers, now);
|
|
38
|
+
const decoder = new KeyDecoder();
|
|
39
|
+
let finish = () => {};
|
|
40
|
+
const done = new Promise ((resolve) => {
|
|
41
|
+
finish = resolve;
|
|
42
|
+
});
|
|
43
|
+
let ended = false;
|
|
44
|
+
let failure = null;
|
|
45
|
+
let app = null;
|
|
46
|
+
let prev = null;
|
|
47
|
+
let frameTimer = null;
|
|
48
|
+
let escTimer = null;
|
|
49
|
+
let pollTimer = null;
|
|
50
|
+
let lastKey = now();
|
|
51
|
+
let stamp = "";
|
|
52
|
+
let reportWaiter = null;
|
|
53
|
+
decoder.onReport = (report) => reportWaiter?.(report.col);
|
|
54
|
+
|
|
55
|
+
const end = (code , error ) => {
|
|
56
|
+
if (ended) return;
|
|
57
|
+
ended = true;
|
|
58
|
+
if (error !== undefined && error !== null) failure = error;
|
|
59
|
+
if (frameTimer !== null) timers.clearTimeout(frameTimer);
|
|
60
|
+
if (escTimer !== null) timers.clearTimeout(escTimer);
|
|
61
|
+
if (pollTimer !== null) timers.clearInterval(pollTimer);
|
|
62
|
+
app?.dispose();
|
|
63
|
+
term.close();
|
|
64
|
+
finish(code);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const draw = () => {
|
|
68
|
+
frameTimer = null;
|
|
69
|
+
if (ended || app === null || !term.active) return;
|
|
70
|
+
try {
|
|
71
|
+
const { cols } = app.model;
|
|
72
|
+
const frame = app.view().map((row) => encodeRow(row, cols, app?.model.paint ?? { ambiguous: 1, colour: false }));
|
|
73
|
+
const bytes = flush(frame, prev);
|
|
74
|
+
prev = frame;
|
|
75
|
+
term.write(bytes);
|
|
76
|
+
options.onFrame?.(frame, bytes);
|
|
77
|
+
if (app.model.quit) end(0);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
end(1, error);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const request = () => {
|
|
83
|
+
if (frameTimer === null && !ended) frameTimer = timers.setTimeout(draw, FRAME_MS);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const keys = (list ) => {
|
|
87
|
+
for (const key of list) {
|
|
88
|
+
if (ended || app === null) return;
|
|
89
|
+
try {
|
|
90
|
+
app.key(key);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
end(1, error);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
request();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
term.enter({
|
|
100
|
+
input: (chunk) => {
|
|
101
|
+
lastKey = now();
|
|
102
|
+
keys(decoder.feed(chunk, now()));
|
|
103
|
+
if (decoder.waiting) {
|
|
104
|
+
if (escTimer !== null) timers.clearTimeout(escTimer);
|
|
105
|
+
escTimer = timers.setTimeout(() => {
|
|
106
|
+
escTimer = null;
|
|
107
|
+
keys(decoder.flush(now(), true));
|
|
108
|
+
}, ESC_WAIT_MS);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
resize: () => {
|
|
112
|
+
if (app === null) return;
|
|
113
|
+
const size = tty.size();
|
|
114
|
+
app.resize(size.cols, size.rows);
|
|
115
|
+
prev = null;
|
|
116
|
+
request();
|
|
117
|
+
},
|
|
118
|
+
resume: () => {
|
|
119
|
+
prev = null;
|
|
120
|
+
if (app !== null) {
|
|
121
|
+
const size = tty.size();
|
|
122
|
+
app.resize(size.cols, size.rows);
|
|
123
|
+
}
|
|
124
|
+
request();
|
|
125
|
+
},
|
|
126
|
+
exit: (why, error) => {
|
|
127
|
+
if (why === "SIGTERM") end(143);
|
|
128
|
+
else if (why === "SIGHUP") end(129);
|
|
129
|
+
else if (why === "SIGINT") end(130);
|
|
130
|
+
else if (why === "fatal") end(1, error);
|
|
131
|
+
else end(0);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const ambiguous = await measureAmbiguous(options.env, tty, timers, (fn) => {
|
|
136
|
+
reportWaiter = fn;
|
|
137
|
+
});
|
|
138
|
+
reportWaiter = null;
|
|
139
|
+
if (ended) return report(options, await done, null, failure);
|
|
140
|
+
const size = tty.size();
|
|
141
|
+
app = new App({ ...options, cols: size.cols, rows: size.rows, ambiguous, timers, now });
|
|
142
|
+
app.onChange = request;
|
|
143
|
+
app.onSuspend = () => {
|
|
144
|
+
prev = null;
|
|
145
|
+
term.suspend();
|
|
146
|
+
};
|
|
147
|
+
options.onApp?.(app);
|
|
148
|
+
request();
|
|
149
|
+
// The probe's first stamp is taken once the first reads are done (taskstate's state file is known by then), so the
|
|
150
|
+
// poller compares against what the screen shows.
|
|
151
|
+
void app.start().then(
|
|
152
|
+
() => {
|
|
153
|
+
if (app !== null) stamp = JSON.stringify(probeStamp(options.home, app.model.taskstateState));
|
|
154
|
+
request();
|
|
155
|
+
},
|
|
156
|
+
(error) => end(1, error),
|
|
157
|
+
);
|
|
158
|
+
let lastPoll = now();
|
|
159
|
+
pollTimer = timers.setInterval(() => {
|
|
160
|
+
if (ended || app === null || !term.active || stamp === "") return;
|
|
161
|
+
const idle = now() - lastKey > IDLE_AFTER_MS;
|
|
162
|
+
const paused = app.model.status?.kind === "paused";
|
|
163
|
+
if ((idle || paused) && now() - lastPoll < POLL_IDLE_MS) return;
|
|
164
|
+
lastPoll = now();
|
|
165
|
+
// While a call runs the stamp is left as it was, so a change that lands meanwhile is still seen on the next tick.
|
|
166
|
+
if (!app.idle) return;
|
|
167
|
+
const next = JSON.stringify(probeStamp(options.home, app.model.taskstateState));
|
|
168
|
+
if (next === stamp && !paused) return;
|
|
169
|
+
stamp = next;
|
|
170
|
+
void app.refresh();
|
|
171
|
+
}, POLL_ACTIVE_MS);
|
|
172
|
+
|
|
173
|
+
const code = await done;
|
|
174
|
+
return report(options, code, app, failure);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** After the terminal is restored: the audit of writes, and the error that ended the session, on stderr. */
|
|
178
|
+
function report(options , code , app , failure ) {
|
|
179
|
+
if (failure !== null) {
|
|
180
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
181
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: the message goes to a terminal.
|
|
182
|
+
options.err(`error: Internal: ${message.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?")}\n`);
|
|
183
|
+
}
|
|
184
|
+
const audit = app?.model.audit ?? [];
|
|
185
|
+
if (audit.length > 0) {
|
|
186
|
+
const lines = [
|
|
187
|
+
app?.model.t("auditTitle") ?? "",
|
|
188
|
+
...audit.map((entry) => ` ${entry.ok ? "ok " : "failed"} $ ${entry.command}`),
|
|
189
|
+
];
|
|
190
|
+
options.err(`${lines.join("\n")}\n`);
|
|
191
|
+
}
|
|
192
|
+
return code;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The terminal's ambiguous width: AGENT_WHISKER_TUI_AMBIGUOUS (wide or narrow) when set; otherwise the probe, waiting
|
|
197
|
+
* PROBE_MS for the cursor position report (one column when none comes).
|
|
198
|
+
*/
|
|
199
|
+
async function measureAmbiguous(
|
|
200
|
+
env ,
|
|
201
|
+
tty ,
|
|
202
|
+
timers ,
|
|
203
|
+
wait ,
|
|
204
|
+
) {
|
|
205
|
+
const given = env.AGENT_WHISKER_TUI_AMBIGUOUS;
|
|
206
|
+
if (given === "wide") return 2;
|
|
207
|
+
if (given === "narrow") return 1;
|
|
208
|
+
return new Promise ((resolve) => {
|
|
209
|
+
const timer = timers.setTimeout(() => resolve(1), PROBE_MS);
|
|
210
|
+
wait((col) => {
|
|
211
|
+
timers.clearTimeout(timer);
|
|
212
|
+
resolve(ambiguousFromReport(col));
|
|
213
|
+
});
|
|
214
|
+
tty.write(AMBIGUOUS_PROBE);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Bytes from a terminal in raw mode, decoded into key events. A pure decoder with an injected clock: an escape
|
|
2
|
+
// sequence split across reads is kept until it completes, a lone Esc is told from the start of a sequence by waiting
|
|
3
|
+
// ESC_WAIT_MS for more, and a bracketed paste (`\x1b[200~ … \x1b[201~`) arrives as one paste event whose text is never
|
|
4
|
+
// taken as keys.
|
|
5
|
+
|
|
6
|
+
/** One key: name is a printable character (`a`, `中`), or one of the named keys below; ctrl and alt as pressed. */
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/** How long a lone Esc waits for the rest of a sequence: 30 ms. */
|
|
10
|
+
export const ESC_WAIT_MS = 30;
|
|
11
|
+
|
|
12
|
+
const CSI_NAMES = {
|
|
13
|
+
A: "up",
|
|
14
|
+
B: "down",
|
|
15
|
+
C: "right",
|
|
16
|
+
D: "left",
|
|
17
|
+
H: "home",
|
|
18
|
+
F: "end",
|
|
19
|
+
Z: "backtab",
|
|
20
|
+
};
|
|
21
|
+
const TILDE_NAMES = {
|
|
22
|
+
"1": "home",
|
|
23
|
+
"2": "insert",
|
|
24
|
+
"3": "delete",
|
|
25
|
+
"4": "end",
|
|
26
|
+
"5": "pageup",
|
|
27
|
+
"6": "pagedown",
|
|
28
|
+
"7": "home",
|
|
29
|
+
"8": "end",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: an escape sequence starts with ESC.
|
|
33
|
+
const CSI = /^\x1b[[O]([0-?]*)([ -/]*)([@-~])/u;
|
|
34
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: as above, a sequence still arriving.
|
|
35
|
+
const CSI_PART = /^\x1b[[O][0-?]*[ -/]*$/u;
|
|
36
|
+
|
|
37
|
+
/** A terminal's answer to a cursor position report (`\x1b[<row>;<col>R`), which term.ts asks for itself. */
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/** The decoder: feed(chunk, now) gives the keys complete so far; flush(now) gives a lone Esc once its wait is over. */
|
|
41
|
+
export class KeyDecoder {
|
|
42
|
+
buffer = "";
|
|
43
|
+
since = 0;
|
|
44
|
+
pasting = null;
|
|
45
|
+
/** Called with each cursor position report instead of a key. */
|
|
46
|
+
onReport = null;
|
|
47
|
+
|
|
48
|
+
feed(chunk , now ) {
|
|
49
|
+
if (this.buffer === "") this.since = now;
|
|
50
|
+
this.buffer += chunk;
|
|
51
|
+
return this.drain(now, false);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The keys a waiting lone Esc (or an unfinished sequence) gives once ESC_WAIT_MS has passed; [] before that. force
|
|
56
|
+
* gives them at once: the caller's own ESC_WAIT_MS timer fired (a timer may fire a millisecond before the clock says).
|
|
57
|
+
*/
|
|
58
|
+
flush(now , force = false) {
|
|
59
|
+
if (this.buffer === "" || (!force && now - this.since < ESC_WAIT_MS)) return [];
|
|
60
|
+
return this.drain(now, true);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Whether a partial sequence waits for more bytes (the caller then calls flush after ESC_WAIT_MS). */
|
|
64
|
+
get waiting() {
|
|
65
|
+
return this.buffer !== "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
drain(now , timedOut ) {
|
|
69
|
+
const keys = [];
|
|
70
|
+
for (;;) {
|
|
71
|
+
if (this.pasting !== null) {
|
|
72
|
+
const end = this.buffer.indexOf("\x1b[201~");
|
|
73
|
+
if (end < 0) {
|
|
74
|
+
this.pasting += this.buffer;
|
|
75
|
+
this.buffer = "";
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
keys.push({ name: "paste", paste: this.pasting + this.buffer.slice(0, end) });
|
|
79
|
+
this.pasting = null;
|
|
80
|
+
this.buffer = this.buffer.slice(end + 6);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (this.buffer === "") break;
|
|
84
|
+
const step = this.next(timedOut);
|
|
85
|
+
if (step === null) break;
|
|
86
|
+
this.buffer = this.buffer.slice(step.used);
|
|
87
|
+
if (step.key) keys.push(step.key);
|
|
88
|
+
}
|
|
89
|
+
if (this.buffer !== "") this.since = now;
|
|
90
|
+
return keys;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The first key of the buffer and how many characters it used; null when it needs more bytes. */
|
|
94
|
+
next(timedOut ) {
|
|
95
|
+
const s = this.buffer;
|
|
96
|
+
const first = s.codePointAt(0) ?? 0;
|
|
97
|
+
const char = String.fromCodePoint(first);
|
|
98
|
+
if (first !== 0x1b) return { key: plain(char), used: char.length };
|
|
99
|
+
if (s.length === 1) return timedOut ? { key: { name: "escape" }, used: 1 } : null;
|
|
100
|
+
const second = s[1] ?? "";
|
|
101
|
+
if (second === "[" || second === "O") {
|
|
102
|
+
// CSI: parameters 0x30–0x3f, intermediates 0x20–0x2f, one final byte 0x40–0x7e.
|
|
103
|
+
const match = CSI.exec(s);
|
|
104
|
+
if (match === null) {
|
|
105
|
+
if (CSI_PART.test(s) && !timedOut) return null;
|
|
106
|
+
return { key: { name: "escape" }, used: 1 };
|
|
107
|
+
}
|
|
108
|
+
const [whole, params = "", , final = ""] = match;
|
|
109
|
+
if (final === "~" && params === "200") {
|
|
110
|
+
this.pasting = "";
|
|
111
|
+
return { key: null, used: whole.length };
|
|
112
|
+
}
|
|
113
|
+
if (final === "R" && second === "[" && /^\d+;\d+$/u.test(params)) {
|
|
114
|
+
const [row, col] = params.split(";").map(Number);
|
|
115
|
+
this.onReport?.({ row: row ?? 0, col: col ?? 0 });
|
|
116
|
+
return { key: null, used: whole.length };
|
|
117
|
+
}
|
|
118
|
+
const parts = params.split(";");
|
|
119
|
+
const mod = Number(parts[1] ?? "1") - 1;
|
|
120
|
+
const mods = mod > 0 ? { shift: (mod & 1) !== 0, alt: (mod & 2) !== 0, ctrl: (mod & 4) !== 0 } : {};
|
|
121
|
+
const name = final === "~" ? TILDE_NAMES[parts[0] ?? ""] : CSI_NAMES[final];
|
|
122
|
+
if (name === undefined) return { key: { name: "unknown" }, used: whole.length };
|
|
123
|
+
return { key: clean({ name, ...mods }), used: whole.length };
|
|
124
|
+
}
|
|
125
|
+
// Alt plus a key: Esc then the key.
|
|
126
|
+
const rest = String.fromCodePoint(s.codePointAt(1) ?? 0);
|
|
127
|
+
if (rest === "\x1b") return { key: { name: "escape" }, used: 1 };
|
|
128
|
+
const key = plain(rest);
|
|
129
|
+
return { key: { ...key, alt: true }, used: 1 + rest.length };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A key without its false modifier flags, so tests compare keys as written. */
|
|
134
|
+
function clean(key ) {
|
|
135
|
+
const out = { name: key.name };
|
|
136
|
+
if (key.ctrl) out.ctrl = true;
|
|
137
|
+
if (key.alt) out.alt = true;
|
|
138
|
+
if (key.shift) out.shift = true;
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A key that is not part of an escape sequence: Enter, Tab, Backspace, Ctrl+letter, or a character. */
|
|
143
|
+
function plain(char ) {
|
|
144
|
+
const code = char.codePointAt(0) ?? 0;
|
|
145
|
+
if (char === "\r" || char === "\n") return { name: "enter" };
|
|
146
|
+
if (char === "\t") return { name: "tab" };
|
|
147
|
+
if (code === 0x7f || code === 0x08) return { name: "backspace" };
|
|
148
|
+
if (code === 0) return { name: "space", ctrl: true };
|
|
149
|
+
if (code < 0x20) return { name: String.fromCharCode(code + 0x60), ctrl: true };
|
|
150
|
+
if (char === " ") return { name: "space" };
|
|
151
|
+
return { name: char };
|
|
152
|
+
}
|