@awebai/oats 0.68.0 → 0.69.1
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/bin/oats.mjs +102 -22
- package/docs/capabilities.md +49 -5
- package/docs/configuration.md +68 -2
- package/docs/desktop-cli-api.md +355 -12
- package/docs/desktop-instance-start.md +88 -3
- package/docs/desktop.md +147 -13
- package/docs/execution-targets.md +514 -62
- package/docs/harness-trust.md +3 -1
- package/docs/implementation.md +28 -11
- package/docs/integrations.md +1 -1
- package/docs/oats-local.schema.json +2 -2
- package/docs/official-catalog.md +4 -3
- package/docs/packages.md +7 -7
- package/docs/release-notes/v0.68.1.md +102 -0
- package/docs/release-notes/v0.69.0.md +658 -0
- package/docs/release-notes/v0.69.1.md +25 -0
- package/docs/servers.md +44 -5
- package/docs/souls-and-instances.md +11 -7
- package/docs/tui.md +114 -31
- package/docs/upgrading.md +14 -5
- package/docs/workspaces.md +1 -1
- package/lib/core.mjs +345 -89
- package/lib/file-pieces.mjs +49 -0
- package/lib/instance-events.mjs +25 -4
- package/lib/launch-prompt-fixtures/README.md +62 -0
- package/lib/launch-prompt-fixtures/resume-confirmation.json +32 -0
- package/lib/launch-prompt-fixtures.mjs +49 -0
- package/lib/launch-prompt-resume.mjs +55 -0
- package/lib/login-environment.mjs +27 -9
- package/lib/schedule.mjs +3 -3
- package/lib/servers.mjs +117 -23
- package/lib/session-end.mjs +82 -0
- package/lib/session-input.mjs +43 -9
- package/lib/session-resume-contract.mjs +32 -0
- package/lib/session-resume.mjs +310 -0
- package/lib/session-seen.mjs +163 -0
- package/lib/session-viewer.mjs +147 -44
- package/lib/soul-composition.mjs +2 -1
- package/lib/start-env.mjs +110 -0
- package/lib/tmux-server-scope.mjs +139 -14
- package/lib/workspace.mjs +38 -4
- package/package-catalog.json +10 -4
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +9 -0
- package/packages/client/cli-locator.mjs +3 -2
- package/packages/client/deployment-data.mjs +7 -0
- package/packages/client/deployment-panel.mjs +3 -0
- package/packages/client/file-output-exec.mjs +98 -0
- package/packages/client/instance-display-name.mjs +18 -0
- package/packages/client/launch-prompt-outcome.mjs +25 -13
- package/packages/client/own-codes.mjs +2 -0
- package/packages/client/session-attach.mjs +35 -5
- package/packages/client/session-resume-cli.mjs +64 -0
- package/packages/client/session-resume-trigger.mjs +167 -0
- package/packages/client/session-resume.mjs +332 -0
- package/packages/client/tmux-status.mjs +30 -7
- package/packages/client/waiting-on-you.mjs +11 -4
- package/packages/client/workspace-step.mjs +17 -5
- package/packages/record/lib/last-conversation.mjs +123 -0
- package/packages/record/lib/session-roots.mjs +10 -1
- package/packages/tui/README.md +1 -1
- package/packages/tui/lib/client.mjs +2 -1
- package/packages/tui/lib/main.mjs +5 -3
- package/packages/tui/lib/model.mjs +57 -15
- package/packages/tui/lib/store.mjs +8 -7
- package/packages/tui/lib/term/text.mjs +12 -9
- package/packages/tui/lib/views/capabilities.mjs +6 -6
- package/packages/tui/lib/views/frame.mjs +72 -7
- package/packages/tui/lib/views/help.mjs +9 -4
- package/packages/tui/lib/views/instances.mjs +46 -29
- package/packages/tui/lib/views/souls.mjs +9 -8
- package/skills/oats-getting-started/SKILL.md +117 -4
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
/** The workspace the leader's ↑ and ↓ move to (keymap.mjs `workspace-previous`, `workspace-next`): the
|
|
2
2
|
* next openable row of the sidebar's list of workspaces, as each client draws it, in one direction. Both
|
|
3
|
-
* clients read it; each draws its own list and opens what this answers.
|
|
3
|
+
* clients read it; each draws its own list and opens what this answers. Both clients' moves wrap.
|
|
4
4
|
*
|
|
5
5
|
* Pure: arguments in, a key out, nothing changed. A page loads this module: it imports nothing. */
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The key of the next row with `openable` true from the row `currentKey`, in the direction `step`
|
|
9
|
-
* (+1, down the list; −1, up it)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* (+1, down the list; −1, up it). Rows that are not openable are passed over. Without `wrap` (the TUI
|
|
10
|
+
* list's own cursor) the list does not wrap: null at an end. With `wrap` (both clients' moves) it goes
|
|
11
|
+
* on from the other end, and
|
|
12
|
+
* when no other row can be opened it answers `currentKey` itself (an openable current row: the only
|
|
13
|
+
* one), so a caller can tell "only this one" from "none". With `currentKey` not among the rows (null
|
|
14
|
+
* included: nothing is open, or what is open is not listed), the first openable row for +1 and the
|
|
15
|
+
* last for −1, or null when none is, wrapping or not.
|
|
12
16
|
* @param {{ key: string, openable: boolean }[]} rows the list as drawn, in its order
|
|
13
17
|
* @param {string | null} currentKey the row the client is on
|
|
14
18
|
* @param {1 | -1} step
|
|
19
|
+
* @param {{ wrap?: boolean }} [options]
|
|
15
20
|
* @returns {string | null}
|
|
16
21
|
*/
|
|
17
|
-
export function workspaceStep(rows, currentKey, step) {
|
|
22
|
+
export function workspaceStep(rows, currentKey, step, { wrap = false } = {}) {
|
|
18
23
|
const list = Array.isArray(rows) ? rows : [];
|
|
19
24
|
const at = currentKey === null || currentKey === undefined ? -1 : list.findIndex((row) => row?.key === currentKey);
|
|
20
25
|
const dir = step < 0 ? -1 : 1;
|
|
26
|
+
if (wrap && at !== -1) {
|
|
27
|
+
for (let n = 1; n < list.length; n++) {
|
|
28
|
+
const row = list[(((at + dir * n) % list.length) + list.length) % list.length];
|
|
29
|
+
if (row?.openable === true) return row.key;
|
|
30
|
+
}
|
|
31
|
+
return list[at]?.openable === true ? list[at].key : null;
|
|
32
|
+
}
|
|
21
33
|
for (let i = at === -1 ? (dir === 1 ? 0 : list.length - 1) : at + dir; i >= 0 && i < list.length; i += dir) {
|
|
22
34
|
if (list[i]?.openable === true) return list[i].key;
|
|
23
35
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// lastConversation — the conversation a restarted instance should reopen.
|
|
2
|
+
//
|
|
3
|
+
// The roots come from the home's own native-record receipts (what each managed
|
|
4
|
+
// start of this harness actually recorded), never from an observer's HOME. A
|
|
5
|
+
// transcript is the instance's conversation only when it was STARTED in the
|
|
6
|
+
// home itself: a session started in <home>/work is a helper's, not the
|
|
7
|
+
// instance's. `since` (the home's createdAt) drops an earlier incarnation of a
|
|
8
|
+
// reused name: its receipts started, and its transcripts last changed, before
|
|
9
|
+
// this home existed.
|
|
10
|
+
//
|
|
11
|
+
// Unlike capture, this is a best-effort lookup, so it never certifies complete
|
|
12
|
+
// history: a home made before the recorder has receipts only for later starts,
|
|
13
|
+
// and those are enough. Unexpected I/O failures throw.
|
|
14
|
+
|
|
15
|
+
import { closeSync, fstatSync, openSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
16
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
17
|
+
import { isUtf8 } from "node:buffer";
|
|
18
|
+
|
|
19
|
+
import { SESSION_FORMATS } from "./formats.mjs";
|
|
20
|
+
import { bufferLines, fileChunks } from "./file-lines.mjs";
|
|
21
|
+
import { nativeHistoryPath } from "./native-history.mjs";
|
|
22
|
+
import { CWD_SCAN_BOUND_BYTES, cwdOfLine } from "./sessions-for-home.mjs";
|
|
23
|
+
|
|
24
|
+
const SOURCE = { claude: "cc", pi: "pi", codex: "codex" };
|
|
25
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
26
|
+
const RECEIPT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.json$/;
|
|
27
|
+
// What pi's `--session` resolves as an id, not a path (pi treats `/`, `\` and
|
|
28
|
+
// a `.jsonl` suffix as a path). The recorder accepts the same bare form.
|
|
29
|
+
const PI_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
30
|
+
|
|
31
|
+
function canonical(p) {
|
|
32
|
+
try { return realpathSync(p); }
|
|
33
|
+
catch (err) { if (err.code !== "ENOENT") throw err; return resolve(p); }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sinceMs(since) {
|
|
37
|
+
const t = since instanceof Date ? since.getTime() : typeof since === "number" ? since : typeof since === "string" ? Date.parse(since) : NaN;
|
|
38
|
+
if (!Number.isFinite(t)) throw new TypeError("lastConversation needs a valid `since` (the home's createdAt)");
|
|
39
|
+
return t;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function readJson(path) { return JSON.parse(readFileSync(path, "utf8")); }
|
|
43
|
+
|
|
44
|
+
// The locations this harness's started launches (since `since`) recorded.
|
|
45
|
+
// null: there is no v1 receipt custody to trust for this harness.
|
|
46
|
+
function receiptRoots(home, runtime, since) {
|
|
47
|
+
const dir = nativeHistoryPath(home);
|
|
48
|
+
let names;
|
|
49
|
+
try { names = readdirSync(dir); }
|
|
50
|
+
catch (err) { if (err.code === "ENOENT") return null; throw err; }
|
|
51
|
+
let header;
|
|
52
|
+
try { header = readJson(join(dir, "history.json")); }
|
|
53
|
+
catch (err) { if (err.code === "ENOENT") return null; throw err; }
|
|
54
|
+
if (header?.version !== 1) return null; // a captured (v2) home keeps protected custody
|
|
55
|
+
const roots = [];
|
|
56
|
+
for (const name of names.sort()) {
|
|
57
|
+
if (!RECEIPT.test(name)) continue; // history.json, temp files, strays
|
|
58
|
+
const row = readJson(join(dir, name));
|
|
59
|
+
if (row?.version !== 1 || row.runtime !== runtime || row.state !== "started") continue;
|
|
60
|
+
if (!(Date.parse(row.startedAt) >= since)) continue;
|
|
61
|
+
if (row.id !== basename(name, ".json") || !Array.isArray(row.locations)) throw new Error(`invalid native record receipt: ${name}`);
|
|
62
|
+
for (const path of row.locations) {
|
|
63
|
+
if (typeof path !== "string" || !isAbsolute(path) || path.includes("\0") || resolve(path) !== path) throw new Error(`invalid native record location in ${name}`);
|
|
64
|
+
if (!roots.includes(path)) roots.push(path);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return roots.length ? roots : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The first native header in the file's complete lines (cwd, and pi's id).
|
|
71
|
+
// A tolerant read: other instances' transcripts in a shared root may be
|
|
72
|
+
// growing while we look, and only their already-terminated prefix is read.
|
|
73
|
+
function header(source, path) {
|
|
74
|
+
let fd;
|
|
75
|
+
try { fd = openSync(path, "r"); }
|
|
76
|
+
catch (err) { if (err.code === "ENOENT") return null; throw err; } // removed since listing
|
|
77
|
+
try {
|
|
78
|
+
const end = Math.min(CWD_SCAN_BOUND_BYTES, fstatSync(fd).size);
|
|
79
|
+
for (const bytes of bufferLines(fileChunks(fd, { end, size: 64 * 1024 }))) {
|
|
80
|
+
if (bytes[bytes.length - 1] !== 10) break; // an unterminated fragment is not a record
|
|
81
|
+
const line = isUtf8(bytes) ? bytes.toString("utf8") : null;
|
|
82
|
+
const cwd = cwdOfLine(source, line);
|
|
83
|
+
if (!cwd) continue;
|
|
84
|
+
return { cwd, id: source === "pi" ? JSON.parse(line).id : undefined };
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
} finally { closeSync(fd); }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The harness's last conversation started in `home` since `since`.
|
|
91
|
+
* `harness`: "claude" | "pi" | "codex"; `since`: ISO string, Date or ms.
|
|
92
|
+
* Returns { sessionId, path } (sessionId is what the harness's resume flag
|
|
93
|
+
* takes), or { none: "no-receipts" } / { none: "no-conversation" }. */
|
|
94
|
+
export function lastConversation(home, { harness, since } = {}) {
|
|
95
|
+
const source = SOURCE[harness];
|
|
96
|
+
if (!source) throw new Error(`unsupported harness for lastConversation: ${harness}`);
|
|
97
|
+
const after = sinceMs(since);
|
|
98
|
+
const roots = receiptRoots(home, harness, after);
|
|
99
|
+
if (!roots) return { none: "no-receipts" };
|
|
100
|
+
const format = SESSION_FORMATS[source], target = canonical(home);
|
|
101
|
+
let best = null;
|
|
102
|
+
// Non-strict: a recorded root nothing has written to yet is simply empty.
|
|
103
|
+
for (const path of new Set(format.listFiles(roots, { strict: false }))) {
|
|
104
|
+
let sessionId = format.sessionId(path);
|
|
105
|
+
// Claude: never a subagent or sidechain transcript; `claude --resume`
|
|
106
|
+
// takes the parent session's UUID, which is its file's name.
|
|
107
|
+
if (source === "cc" && (basename(dirname(path)) === "subagents" || !UUID.test(sessionId))) continue;
|
|
108
|
+
let mtimeMs;
|
|
109
|
+
try { mtimeMs = statSync(path).mtimeMs; }
|
|
110
|
+
catch (err) { if (err.code === "ENOENT") continue; throw err; }
|
|
111
|
+
// Cheap before any read: shared roots hold every other home's transcripts.
|
|
112
|
+
if (mtimeMs < after || (best && (mtimeMs < best.mtimeMs || (mtimeMs === best.mtimeMs && path > best.path)))) continue;
|
|
113
|
+
const found = header(source, path);
|
|
114
|
+
if (!found || canonical(found.cwd) !== target) continue;
|
|
115
|
+
if (source === "pi") {
|
|
116
|
+
// pi's --session matches the header id; the filename carries the same id.
|
|
117
|
+
if (typeof found.id === "string") sessionId = found.id;
|
|
118
|
+
if (!PI_ID.test(sessionId) || sessionId.endsWith(".jsonl")) continue;
|
|
119
|
+
}
|
|
120
|
+
best = { sessionId, path, mtimeMs };
|
|
121
|
+
}
|
|
122
|
+
return best ? { sessionId: best.sessionId, path: best.path } : { none: "no-conversation" };
|
|
123
|
+
}
|
|
@@ -81,7 +81,16 @@ export function nativeLaunchLocations(harness, { cwd, env = process.env, args =
|
|
|
81
81
|
let sessionDir = env.PI_CODING_AGENT_SESSION_DIR;
|
|
82
82
|
for (let i = 0; i < args.length; i++) {
|
|
83
83
|
const arg = args[i];
|
|
84
|
-
if (arg === "--session" || arg.startsWith("--session="))
|
|
84
|
+
if (arg === "--session" || arg.startsWith("--session=")) {
|
|
85
|
+
// A resumed launch names its session by bare id; pi looks an id up in the
|
|
86
|
+
// session directory below, so that directory is still where it writes.
|
|
87
|
+
// pi opens anything with `/`, `\` or a `.jsonl` suffix as a file path,
|
|
88
|
+
// which may live anywhere: that has no directory custody.
|
|
89
|
+
const id = arg === "--session" ? args[++i] : arg.slice("--session=".length);
|
|
90
|
+
if (!id || id.startsWith("-")) throw new Error("invalid native --session");
|
|
91
|
+
if (/[/\\\0]/.test(id) || /^[.~]/.test(id) || id.endsWith(".jsonl")) throw new Error("explicit Pi --session has no supported directory custody; capture explicit roots instead");
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
85
94
|
if (arg === "--session-dir" || arg.startsWith("--session-dir=")) {
|
|
86
95
|
sessionDir = arg === "--session-dir" ? args[++i] : arg.slice("--session-dir=".length);
|
|
87
96
|
if (!sessionDir || sessionDir.startsWith("--")) throw new Error("invalid native --session-dir");
|
package/packages/tui/README.md
CHANGED
|
@@ -27,7 +27,7 @@ never does.
|
|
|
27
27
|
| `lib/panel.mjs` | the open terminals, as tabs: the run's private tmux server (one control client, one window per tab, up to `MAX_TERMINALS`, each at the size its caller gives), the kernel's `oats session attach` in a pane of each, captures of the displayed tabs only (up to `MAX_SHOWN`, one per group of a split) when tmux says their pane changed, a hidden tab's output marking it, keys typed into the shown tab, and the sweep of what a dead run left; the only module that runs tmux (THE TABS in its header) |
|
|
28
28
|
| `lib/read.mjs` | the effects of reading: the deployment, the kernel record, the observer of every deployment opened in the run, the roster of other machines (`oats server roster --json`), the refresh loop, the liveness collector, ending every read, the identity reads of this computer's listed deployments the run has not opened (`createIdentityReads`: one at a time, under a budget, never on a timer), the changes (a stop or retire apply, a start or restart: never ended, their output in files of the run's private directory), the one look at the file system the switcher needs (whether a picked row is a deployment), and `startExec`, the exec of the list's read before the terminal is taken |
|
|
29
29
|
| `lib/store.mjs` | the state and `reduce(state, event)`: pure. It holds the tabs' order, their groups, the shown one of each and the rule for the neighbour after a close (`TAB_LIMIT`, held to the panel's `MAX_TERMINALS` by a test), and each workspace's memory for the run (THE MEMORY OF A WORKSPACE: its place, its palette recency, and its tabs as it was left, opened again one at a time when it is opened again); the list of workspaces' focus and cursor, and the leader's moves between workspaces (the shared `workspaceStep`) |
|
|
30
|
-
| `lib/model.mjs` | from the state to the rows and the detail to draw, and to the switcher's rows (a workspace and a line per deployment of it, matched by the shared `listedViews` over the served deployments and the identities the reads learned), and from those the list of workspaces (`workspaceList`: one row per workspace the switcher offers, by name, and its dot from what this run observes; `listWindow`: five rows at most), by calling the shared readers: pure, no cell position |
|
|
30
|
+
| `lib/model.mjs` | from the state to the rows and the detail to draw (an instance row's name as words, the shared `instanceDisplayName`, which the row alone shows: the views import nothing of the shared home), and to the switcher's rows (a workspace and a line per deployment of it, matched by the shared `listedViews` over the served deployments and the identities the reads learned), and from those the list of workspaces (`workspaceList`: one row per workspace the switcher offers, by name, and its dot from what this run observes; `listWindow`: five rows at most), by calling the shared readers: pure, no cell position |
|
|
31
31
|
| `lib/term/keys.mjs` | bytes to key events: a pure parser with an injected clock; under the kitty keyboard protocol it reads a `CSI … u` key as its legacy bytes read, a chord as its own id |
|
|
32
32
|
| `lib/term/kitty.mjs` | the kitty keyboard protocol: the flags asked for, a `CSI … u` key read, and the bytes the same key sends without the protocol (`legacyBytes`), which is what an agent is typed; and the chords a terminal sends the same way without it (`legacyChordText`: Alt with a letter or a digit, the Alt and Alt+Shift arrows), which the TUI takes in every terminal |
|
|
33
33
|
| `lib/term/width.mjs` | the cells a grapheme takes |
|
|
@@ -25,10 +25,11 @@ export { shortPath, deploymentLabel, machineLabels } from "../../client/deployme
|
|
|
25
25
|
export { instanceId, instanceVisibleInTree, waitingRollup, collapseKey, filterInstanceTree, hasInstanceChildren, heldHome, instanceSiblings } from "../../client/instance-tree.mjs";
|
|
26
26
|
export { rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment } from "../../client/roster-sections.mjs";
|
|
27
27
|
export { runtimeState, runtimeCounts, originLead, siblingText, instanceColor } from "../../client/instance-presentation.mjs";
|
|
28
|
+
export { instanceDisplayName } from "../../client/instance-display-name.mjs";
|
|
28
29
|
export { waitingClaim, waitingLabel, waitedText, waitingClock, waitingBelowText } from "../../client/waiting-on-you.mjs";
|
|
29
30
|
export { instanceActs, openAct } from "../../client/instance-acts.mjs";
|
|
30
31
|
export { rowReason } from "../../client/remote-address.mjs";
|
|
31
|
-
export { sessionAttachArgv, prepareRemoteTerm, detachKeySupported, hostDetachKeySupported, preflightFailure, DETACH_KEY_FEATURE } from "../../client/session-attach.mjs";
|
|
32
|
+
export { sessionAttachArgv, prepareRemoteTerm, detachKeySupported, hostDetachKeySupported, preflightFailure, DETACH_KEY_FEATURE, PREFIX_SCROLL_FEATURE, localScrollKeys, hostScrollKeys } from "../../client/session-attach.mjs";
|
|
32
33
|
export { attachExit } from "../../client/attach-exit.mjs";
|
|
33
34
|
export { kernelLines } from "../../client/kernel-lines.mjs";
|
|
34
35
|
export { createLifecycleBoundary } from "../../client/instance-lifecycle.mjs";
|
|
@@ -579,19 +579,21 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
579
579
|
* starts in the panel at once. On another, the shared preflight runs first over the reader's
|
|
580
580
|
* exec (a read like any other, ended on every way out), and what it prepared waits for the
|
|
581
581
|
* store's `panel`, which comes only if the open was not given up and the row is still there.
|
|
582
|
-
* The viewer is given no key of its own: the TUI takes the back key before the pane sees it.
|
|
582
|
+
* The viewer is given no key of its own: the TUI takes the back key before the pane sees it.
|
|
583
|
+
* Nor its status line, where the kernel can leave it out (--no-status-line): the cheat sheet
|
|
584
|
+
* names the scroll keys. */
|
|
583
585
|
function open(decision) {
|
|
584
586
|
if (!decision.routed) {
|
|
585
587
|
let args;
|
|
586
588
|
// A target the shared home refuses (no absolute home) starts nothing; the line after says
|
|
587
589
|
// the viewer ended without saying why.
|
|
588
|
-
try { args = sessionAttachArgv(probe.cli, decision.target); } catch { return void heard({ returned: { id: decision.id, status: null, stderr: "" } }); }
|
|
590
|
+
try { args = sessionAttachArgv(probe.cli, decision.target, { statusLine: false }); } catch { return void heard({ returned: { id: decision.id, status: null, stderr: "" } }); }
|
|
589
591
|
return view(decision.id, probe.cli.bin, args);
|
|
590
592
|
}
|
|
591
593
|
giveUpPreflight();
|
|
592
594
|
const mine = preflight = { id: decision.id, controller: new AbortController(), prepared: null };
|
|
593
595
|
Promise.resolve()
|
|
594
|
-
.then(() => effects.prepareRemoteTerm(probe.cli, decision.target, { exec: reader.exec, signal: mine.controller.signal }))
|
|
596
|
+
.then(() => effects.prepareRemoteTerm(probe.cli, decision.target, { exec: reader.exec, signal: mine.controller.signal, statusLine: false }))
|
|
595
597
|
.then((prepared) => { if (preflight === mine) { mine.prepared = prepared; heard({ prepared: { id: mine.id } }); } },
|
|
596
598
|
(error) => { if (preflight === mine) { preflight = null; heard({ prepared: { id: mine.id, error } }); } });
|
|
597
599
|
}
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
// in. What it adds is the TUI's: the window, the clock times, and which fact stands on which line.
|
|
8
8
|
import {
|
|
9
9
|
TERMS, panelData, displayLine, DETAIL_WITHHELD, originLead, instanceId, instanceVisibleInTree, waitingRollup, collapseKey, filterInstanceTree,
|
|
10
|
-
hasInstanceChildren, heldHome, instanceSiblings, siblingText, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts, instanceColor,
|
|
10
|
+
hasInstanceChildren, heldHome, instanceSiblings, siblingText, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts, instanceColor, instanceDisplayName,
|
|
11
11
|
waitingClaim, waitingLabel, waitedText, waitingClock, waitingBelowText, instanceActs, rowReason,
|
|
12
12
|
identityMemory, viewModel, listedViews, workspaceChoices, workspaceChoiceRows, choiceMatches, UNMATCHED_SECTION, shortPath, machineLabels,
|
|
13
|
-
openAct, deployments as heldDeployments, attachExit, preflightFailure, kernelLines,
|
|
13
|
+
openAct, deployments as heldDeployments, localScrollKeys, hostScrollKeys, attachExit, preflightFailure, kernelLines,
|
|
14
14
|
startGate, launchFlagIgnored, flagIgnoredNotice, retainedStartMessage, retiringRows, soulRows, soulFacts, spawnRefusal,
|
|
15
15
|
defaultSpawnChoices, spawnProblem, outcomeWords, previewFacts, deploymentLabel, subsequenceScore, soulMatches, soulCatalogFailure, catalogFailure,
|
|
16
16
|
memberNames, capabilitySource, groupCapabilities, hostKeyOf, capabilitySections, matchCapabilities, soulsComposition, rosterAgentName, layerLabel, capabilityUsers,
|
|
@@ -330,14 +330,23 @@ export function disclosure(state, r, item) {
|
|
|
330
330
|
return !r.filtering && state.collapsed.has(collapseKey(state.open, item.id)) ? "closed" : "open";
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
/** An instance's name as its row draws it: the shared `instanceDisplayName`, the Desktop's sidebar
|
|
334
|
+
* label (`oats-expert` is drawn "Oats expert"; a name of nothing but `-` as it is). The display
|
|
335
|
+
* filter is asked about the name first, as it came: a name it withholds is passed on unchanged, so
|
|
336
|
+
* shown() withholds it in the view, since the words could hide what made it unsafe (a `-` in a
|
|
337
|
+
* credential's URL becomes a space; a control character at an end is trimmed). */
|
|
338
|
+
const rowName = (name) => (displayLine(name) === DETAIL_WITHHELD ? name : instanceDisplayName(name) || name);
|
|
333
339
|
/** One row of the list: its mark, its name, the word its mark cannot say (or null), whether it
|
|
334
340
|
* waits, and on a folded row only, how many instances are folded away under it (`folded`) and how
|
|
335
341
|
* many of those wait (`below`). A row that is not folded says nothing of its children: they
|
|
336
|
-
* stand under it, indented. `selected` the selected row, `cursor` whether it carries `>`.
|
|
342
|
+
* stand under it, indented. `selected` the selected row, `cursor` whether it carries `>`.
|
|
343
|
+
* The name is drawn as words (rowName): it is what the row shows and nothing else. The filter, the
|
|
344
|
+
* palette, the detail, the tabs, a confirmation and every change sent to the kernel keep the
|
|
345
|
+
* instance's name. */
|
|
337
346
|
function listRow(state, r, item) {
|
|
338
347
|
const closed = disclosure(state, r, item) === "closed";
|
|
339
348
|
return {
|
|
340
|
-
id: item.id, name: item.row.instance, depth: item.depth, selected: item.id === state.selected,
|
|
349
|
+
id: item.id, name: rowName(item.row.instance), depth: item.depth, selected: item.id === state.selected,
|
|
341
350
|
// The selected row keeps its reverse video while the list of workspaces has the focus, but not the
|
|
342
351
|
// cursor: only the region with the focus draws `>`.
|
|
343
352
|
cursor: item.id === state.selected && state.focus !== "workspaces",
|
|
@@ -399,17 +408,50 @@ export const SPLIT_WORDS = Object.freeze({
|
|
|
399
408
|
twice: () => [{ own: "The panel has two groups already." }],
|
|
400
409
|
small: (dir, min) => [{ own: dir === "right" ? `No room to split side by side: each group needs ${min.cols} columns.` : `No room to split one above the other: each group needs ${min.rows} rows.` }],
|
|
401
410
|
});
|
|
411
|
+
/** The scroll keys the shown terminal's viewer takes, `{ shift, prefix }`, so the cheat sheet names
|
|
412
|
+
* them (docs/tui.md, "Tabs"): as the tab's host's kernel says, this machine's for a tab of this
|
|
413
|
+
* machine, the group's roster probe for another's (`rows`, the roster's instances, find the tab's
|
|
414
|
+
* row and so its group). Ctrl+B [ is not named with the leader Ctrl+B, which the TUI takes before
|
|
415
|
+
* the viewer reads it. No terminal shown, or a tab whose row is gone: neither. */
|
|
416
|
+
export function scrollKeys(state, rows, at) {
|
|
417
|
+
const t = state.terminal;
|
|
418
|
+
if (!t) return NO_SCROLL_KEYS;
|
|
419
|
+
let keys = localScrollKeys(state.cli);
|
|
420
|
+
if (t.routed) {
|
|
421
|
+
const row = rows.find((r) => instanceId(r) === t.id);
|
|
422
|
+
const group = row ? heldDeployments(heldOf(state, at)).find((d) => d.id === row.deployment?.id)?.group : undefined;
|
|
423
|
+
keys = group ? hostScrollKeys(state.cli, group) : NO_SCROLL_KEYS;
|
|
424
|
+
}
|
|
425
|
+
return keys.prefix && state.leaderKey === "ctrl+b" ? Object.freeze({ ...keys, prefix: false }) : keys;
|
|
426
|
+
}
|
|
427
|
+
const NO_SCROLL_KEYS = Object.freeze({ shift: false, prefix: false });
|
|
402
428
|
/** The groups of the panel as the frame draws them (docs/tui.md, "Splits"): one, or two with a
|
|
403
|
-
* split, each `{ tabs, shown }`: its tabs in the strip's order (`{ id, name, machine,
|
|
404
|
-
* shown, activity }`, `machine` only for another machine's)
|
|
405
|
-
* an empty group. */
|
|
406
|
-
function groupsOf(state) {
|
|
429
|
+
* split, each `{ tabs, shown, waiting }`: its tabs in the strip's order (`{ id, name, machine,
|
|
430
|
+
* routed, shown, activity }`, `machine` only for another machine's), its shown tab's id, or null
|
|
431
|
+
* for an empty group, and what its waiting row says (waitingOf). */
|
|
432
|
+
function groupsOf(state, r, now) {
|
|
407
433
|
return Array.from({ length: state.split === null ? 1 : 2 }, (_, g) => {
|
|
408
434
|
const shown = g === state.group ? state.terminal?.id ?? null : state.aside;
|
|
409
435
|
const tabs = state.tabs.filter((tab) => tab.group === g).map((tab) => ({ id: tab.id, name: tab.name, machine: tab.routed ? tab.machine : null, routed: tab.routed, shown: tab.id === shown, activity: tab.activity }));
|
|
410
|
-
return { tabs, shown };
|
|
436
|
+
return { tabs, shown, waiting: waitingOf(r, shown, now) };
|
|
411
437
|
});
|
|
412
438
|
}
|
|
439
|
+
/** What a claim with no message waits on, in the TUI's words, by its reason (docs/tui.md, "Tabs"). */
|
|
440
|
+
const WAITING_WORDS = Object.freeze({ permission: "waiting on a permission prompt", question: "asked you a question", attention: "asked for your attention" });
|
|
441
|
+
const WAITING_UNSAID = "waiting for your input";
|
|
442
|
+
/** The waiting row of a group whose shown agent is `id` (views/frame.mjs waitingRows): the
|
|
443
|
+
* agent's live claim, read through the shared gate as the list's `!` mark is, as `{ message, words,
|
|
444
|
+
* age }`: its message (agent text) or null, the TUI's words for a claim with none, and how long
|
|
445
|
+
* it has waited at `now`. A message the display filter leaves nothing of (only spaces) is none.
|
|
446
|
+
* Null for an empty group and an agent with no live claim. */
|
|
447
|
+
function waitingOf(r, id, now) {
|
|
448
|
+
const row = id === null ? null : r.instances.find((each) => instanceId(each) === id) ?? null;
|
|
449
|
+
const claim = row === null ? null : waitingClaim(row, { stale: r.stale(row) });
|
|
450
|
+
if (claim === null) return null;
|
|
451
|
+
const message = text(claim.message) && displayLine(claim.message) !== null ? claim.message : null;
|
|
452
|
+
const words = Object.hasOwn(WAITING_WORDS, claim.reason ?? "") ? WAITING_WORDS[claim.reason] : WAITING_UNSAID;
|
|
453
|
+
return Object.freeze({ message, words, age: waitedText(claim.since, now) });
|
|
454
|
+
}
|
|
413
455
|
/** A command in a line of the TUI's own: whole, never broken over two rows. */
|
|
414
456
|
const command = (text) => Object.freeze({ own: `\`${text}\``, whole: true });
|
|
415
457
|
/** A sentence from outside (a reason of the shared home's, the preflight table's), as a text
|
|
@@ -555,10 +597,10 @@ export const LIST_WORDS = Object.freeze({
|
|
|
555
597
|
});
|
|
556
598
|
|
|
557
599
|
/** The lines of the list of workspaces (docs/tui.md, "The list of workspaces"): the leader's Up or
|
|
558
|
-
* Down
|
|
600
|
+
* Down with no other row to open (the Desktop's words), and a row picked there that is not a
|
|
601
|
+
* deployment any more. */
|
|
559
602
|
export const WORKSPACE_WORDS = Object.freeze({
|
|
560
|
-
|
|
561
|
-
below: () => [{ own: "No workspace below this one." }],
|
|
603
|
+
noOther: () => [{ own: "No other workspace to show." }],
|
|
562
604
|
refused: (name) => [{ shown: name }, { own: ": not an OATS deployment any more." }],
|
|
563
605
|
});
|
|
564
606
|
/** The switcher's choices with no filter, in its order (workspaceList's rows are their keys). */
|
|
@@ -896,12 +938,12 @@ export function model(state, { page, body = page, now, at, cols, area = cols })
|
|
|
896
938
|
// The palette's own keys, `[key id, does]` (actions.mjs paletteKeys; none on macOS): its cheat
|
|
897
939
|
// sheet and the help name them.
|
|
898
940
|
paletteKeys: [...state.paletteKeys],
|
|
899
|
-
terminal: state.terminal, onTerminal: false,
|
|
941
|
+
terminal: state.terminal, onTerminal: false, scrollKeys: scrollKeys(state, r.instances, at),
|
|
900
942
|
// The panel's groups (views/frame.mjs), the split and the focused group; the panel stands while
|
|
901
943
|
// any tab is open. `tabs` is the focused group's strip: each tab in order, the shown one marked,
|
|
902
944
|
// a hidden one's activity. A strip is drawn with two tabs or more; one reads as a title row.
|
|
903
|
-
split: state.split, group: state.group, panelOpen: state.tabs.length > 0, groups: groupsOf(state),
|
|
904
|
-
tabs: groupsOf(state)[state.group].tabs,
|
|
945
|
+
split: state.split, group: state.group, panelOpen: state.tabs.length > 0, groups: groupsOf(state, r, now),
|
|
946
|
+
tabs: groupsOf(state, r, now)[state.group].tabs,
|
|
905
947
|
act: state.view === "act" && state.act ? actView(state) : null,
|
|
906
948
|
// The palette, while it is open.
|
|
907
949
|
palette: state.palette === null ? null : paletteView(state, body, at),
|
|
@@ -679,17 +679,18 @@ function toWorkspaces(state) {
|
|
|
679
679
|
}
|
|
680
680
|
/** The leader's Up and Down (`workspace-previous`, `workspace-next`): the workspace of the row before
|
|
681
681
|
* or after the open one's, as the list draws them (the shared workspaceStep: rows that do not open
|
|
682
|
-
* are passed over, and it
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
682
|
+
* are passed over, and it wraps, as the Desktop's do: past the last row, the first, and before the
|
|
683
|
+
* first, the last), opened as a pick of it opens it. From the terminal's focus it is kept for the
|
|
684
|
+
* workspace left (layoutOf); from anywhere else what is open is settled first, as for the leader's
|
|
685
|
+
* other keys (toList). With no other row to open, the line says so and nothing moves: with the list
|
|
686
|
+
* of workspaces' focus, the focus stays there, its cursor where it was. */
|
|
686
687
|
function workspaceMoved(state, step, inTerminal) {
|
|
687
688
|
const settled = inTerminal ? { state, effect: null } : toList(state), s = settled.state;
|
|
688
|
-
const list = workspaceList(s), key = workspaceStep(list.rows, list.current, step);
|
|
689
|
-
const item = key === null ? null : listChoice(s, key);
|
|
689
|
+
const list = workspaceList(s), key = workspaceStep(list.rows, list.current, step, { wrap: true });
|
|
690
|
+
const item = key === null || key === list.current ? null : listChoice(s, key);
|
|
690
691
|
if (item === null) {
|
|
691
692
|
const kept = state.view === "instances" && state.focus === "workspaces" ? { focus: "workspaces", workspaceCursor: state.workspaceCursor } : {};
|
|
692
|
-
return { state: next(s, { ...kept, outcome: Object.freeze({ said:
|
|
693
|
+
return { state: next(s, { ...kept, outcome: Object.freeze({ said: WORKSPACE_WORDS.noOther(), under: Object.freeze([]), once: true }) }), effect: settled.effect };
|
|
693
694
|
}
|
|
694
695
|
const moved = picked(s, item) ?? { state: s, effect: null };
|
|
695
696
|
return { state: moved.state, effect: both(settled.effect, moved.effect) };
|
|
@@ -76,17 +76,20 @@ export function shownEnd(value, width, { ascii = false } = {}) {
|
|
|
76
76
|
* broken at spaces where it can be and between graphemes where it cannot, the last row ending
|
|
77
77
|
* in the cut mark when more was left. For a sentence that must be read whole (a kernel's
|
|
78
78
|
* reason). Filtered first and cut after, as shownEnd is; nothing to show gives no row, and
|
|
79
|
-
* neither does a row too narrow for the first grapheme.
|
|
80
|
-
|
|
79
|
+
* neither does a row too narrow for the first grapheme. `first` is the first row's width, when
|
|
80
|
+
* something else stands before the text on that row; every other row is `width` cells. */
|
|
81
|
+
export function shownLines(value, width, max, { ascii = false, first = width } = {}) {
|
|
81
82
|
const line = displayLine(value);
|
|
82
|
-
if (line === null || width < 1 || max < 1) return [];
|
|
83
|
+
if (line === null || width < 1 || first < 1 || max < 1) return [];
|
|
83
84
|
if (line === DETAIL_WITHHELD) return [WITHHELD];
|
|
84
85
|
const rows = [];
|
|
86
|
+
const roomOf = (row) => (row === 0 ? first : width);
|
|
85
87
|
let rest = cells(line);
|
|
86
88
|
while (rest.length && rows.length < max) {
|
|
87
|
-
|
|
89
|
+
const room = roomOf(rows.length);
|
|
90
|
+
if (widthOf(rest) <= room) { rows.push(rest); rest = []; break; }
|
|
88
91
|
let end = 0;
|
|
89
|
-
for (let used = 0; end < rest.length && used + rest[end].width <=
|
|
92
|
+
for (let used = 0; end < rest.length && used + rest[end].width <= room; used += rest[end].width) end++;
|
|
90
93
|
// Back to the last space inside the row, when there is one: the row ends before it.
|
|
91
94
|
let cut = end;
|
|
92
95
|
while (cut > 0 && rest[cut]?.text !== " " && rest[cut - 1].text !== " ") cut--;
|
|
@@ -98,12 +101,12 @@ export function shownLines(value, width, max, { ascii = false } = {}) {
|
|
|
98
101
|
while (rest.length && rest[0].text === " ") rest.shift();
|
|
99
102
|
rows.push(row);
|
|
100
103
|
}
|
|
101
|
-
const mark = cutMark(ascii);
|
|
102
|
-
if (rest.length && rows.length && mark.length <=
|
|
104
|
+
const mark = cutMark(ascii), lastRoom = roomOf(rows.length - 1);
|
|
105
|
+
if (rest.length && rows.length && mark.length <= lastRoom) {
|
|
103
106
|
// More was left: the last row gives up its end to the mark. (A row too narrow for the mark
|
|
104
|
-
// keeps what it has: no row is ever wider than
|
|
107
|
+
// keeps what it has: no row is ever wider than its room.)
|
|
105
108
|
const last = rows[rows.length - 1];
|
|
106
|
-
while (last.length && widthOf(last) + mark.length >
|
|
109
|
+
while (last.length && widthOf(last) + mark.length > lastRoom) last.pop();
|
|
107
110
|
while (last.length && last[last.length - 1].text === " ") last.pop();
|
|
108
111
|
last.push(...cells(mark));
|
|
109
112
|
}
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// marked soul carry `>` as well as reverse video, a soul's colour is drawn on a mark that is there
|
|
9
9
|
// without it, and the souls on an older version are said so in words before their warning style.
|
|
10
10
|
import { lit, shown, shownLines } from "../term/text.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import { style } from "../term/style.mjs";
|
|
12
12
|
import { keyLabel } from "../actions.mjs";
|
|
13
|
-
import { cutNote, headingRow, marksOf, measured } from "./instances.mjs";
|
|
13
|
+
import { colourLook, cutNote, headingRow, marksOf, measured } from "./instances.mjs";
|
|
14
14
|
import { windowOf } from "./scroll.mjs";
|
|
15
15
|
import { COUNT_SIGN, SOUL_MARK, flowed, ownLines } from "./souls.mjs";
|
|
16
16
|
|
|
@@ -44,8 +44,9 @@ const PLAIN = style();
|
|
|
44
44
|
const BOLD = style({ bold: true });
|
|
45
45
|
const DIM = style({ dim: true });
|
|
46
46
|
const SELECTED = style({ reverse: true });
|
|
47
|
-
/** The warning style: what it marks says so in words too.
|
|
48
|
-
|
|
47
|
+
/** The warning style: what it marks says so in words too. Red, not yellow: yellow says needs input,
|
|
48
|
+
* and only that. */
|
|
49
|
+
const WARN = style({ bold: true, fg: "red" });
|
|
49
50
|
|
|
50
51
|
/** The mark between a group's name and its note, and before the instances on an older version. */
|
|
51
52
|
const dotOf = (ascii) => (ascii ? "-" : "·");
|
|
@@ -209,9 +210,8 @@ export function capabilityDetailRows(m, cols) {
|
|
|
209
210
|
const marked = i === m.capabilities.mark;
|
|
210
211
|
if (marked) mark = rows.length;
|
|
211
212
|
const look = (own) => (marked ? SELECTED : own);
|
|
212
|
-
const colour = typeof user.color === "string" && COLORS.includes(user.color) ? user.color : null;
|
|
213
213
|
const spans = marked ? [{ col: LEFT, width: Math.max(0, cols - LEFT), style: SELECTED }, { col: LEFT, text: lit(">"), style: SELECTED, width: 1 }] : [];
|
|
214
|
-
spans.push({ col: INNER, text: lit(soulMark), style: look(
|
|
214
|
+
spans.push({ col: INNER, text: lit(soulMark), style: look(colourLook(user.color) ?? PLAIN), width: 1 });
|
|
215
215
|
const counted = `${sign}${user.count}`;
|
|
216
216
|
const after = [{ text: lit(counted), width: counted.length, style: DIM }];
|
|
217
217
|
if (user.behind) { const behind = measured(user.behind); after.push({ text: lit(dotOf(ascii)), width: 1, style: DIM }, { text: behind.text, width: behind.width, style: WARN }); }
|
|
@@ -16,7 +16,7 @@ import { style } from "../term/style.mjs";
|
|
|
16
16
|
import { act } from "./act.mjs";
|
|
17
17
|
import { detail } from "./detail.mjs";
|
|
18
18
|
import { help, keyText, paletteGroupKeys } from "./help.mjs";
|
|
19
|
-
import { instances, measured } from "./instances.mjs";
|
|
19
|
+
import { NEEDS_INPUT, WAITS, instances, measured } from "./instances.mjs";
|
|
20
20
|
import { textWidth } from "../term/width.mjs";
|
|
21
21
|
import { palette } from "./palette.mjs";
|
|
22
22
|
import { soulDetail, soulsList, soulsListed } from "./souls.mjs";
|
|
@@ -252,6 +252,19 @@ function viewRow(m, view, cols, open) {
|
|
|
252
252
|
const made = (id, key, word) => ({ id, key, word: typeof word === "string" ? { spans: [{ col: 0, text: lit(word), width: word.length }], width: word.length } : word });
|
|
253
253
|
/** A hint of keys that are no action's (a key name the TUI writes, like `Enter`). */
|
|
254
254
|
const own = (id, keys, word) => made(id, { text: lit(keys), width: keys.length }, word);
|
|
255
|
+
/** The viewer's scroll keys (docs/tui.md, "Tabs"), the viewer's own and never the TUI's, as the
|
|
256
|
+
* model's `scrollKeys` says the shown tab's host takes them: Shift+PageUp, and Ctrl+B [ where its
|
|
257
|
+
* viewer takes that too; none for a host whose kernel does not say. Both keys where the row holds
|
|
258
|
+
* them; where it holds one, `short`: Ctrl+B [ (cheatRows, withKeys). A block of its own, so its
|
|
259
|
+
* long key does not move the other hints' column. */
|
|
260
|
+
const SCROLL_BOTH = "Shift+PageUp or Ctrl+B [", SCROLL_PREFIX = "Ctrl+B [", SCROLL_SHIFT = "Shift+PageUp";
|
|
261
|
+
function scrollHints(m) {
|
|
262
|
+
if (!m.scrollKeys?.shift) return [];
|
|
263
|
+
const hint = own("scroll", m.scrollKeys.prefix ? SCROLL_BOTH : SCROLL_SHIFT, "scroll back");
|
|
264
|
+
return [{ ...hint, block: "scroll", ...(m.scrollKeys.prefix ? { short: { text: lit(SCROLL_PREFIX), width: SCROLL_PREFIX.length } } : {}) }];
|
|
265
|
+
}
|
|
266
|
+
/** A hint with its `short` key where its own key and word do not fit `room` cells. */
|
|
267
|
+
const fitted = (h, room) => (h.short && h.key.width + GAP + h.word.width > room ? { ...h, key: h.short } : h);
|
|
255
268
|
/** `types <the leader>`: what the leader pressed twice does while a terminal has the focus. */
|
|
256
269
|
function types(m) {
|
|
257
270
|
const key = leaderText(m);
|
|
@@ -296,7 +309,7 @@ function cheatSheet(m) {
|
|
|
296
309
|
const listing = !["help", "switcher", "souls", "capabilities"].includes(m.view);
|
|
297
310
|
if (listing && m.terminal?.focus === "terminal" && !m.palette && !m.spawn) {
|
|
298
311
|
const label = backKeyLabel(m.detachKey), list = keyLabel(LEADER.find((entry) => entry.does === "list").keys[0]);
|
|
299
|
-
const leader = [made("list", keyText(`${label} ${list}`), "the list"), made("again", keyText(`${label} ${label}`), types(m))];
|
|
312
|
+
const leader = [made("list", keyText(`${label} ${list}`), "the list"), made("again", keyText(`${label} ${label}`), types(m)), ...scrollHints(m)];
|
|
300
313
|
return m.chordsLead ? [...chordHints(m), ...led(leader)] : [...led(leader), ...chordHints(m)];
|
|
301
314
|
}
|
|
302
315
|
if (m.palette) return led([own("run", "Enter", "run"), own("move", "Up/Down", "move"), own("close", "Esc", "close"), paletteGroups(m)]);
|
|
@@ -386,8 +399,9 @@ function givenUp(hints) {
|
|
|
386
399
|
* (the chords') have a column of their own, after their own widest key, and as far left as
|
|
387
400
|
* leaves their words whole: those words are the TUI's own and short, where their keys are long
|
|
388
401
|
* (`Alt+Shift+Left/Right` in the 30 cells beside a terminal). */
|
|
389
|
-
function cheatRows(
|
|
402
|
+
function cheatRows(given, cols) {
|
|
390
403
|
const edge = cols - MARGIN;
|
|
404
|
+
const hints = given.map((h) => fitted(h, edge - MARGIN));
|
|
391
405
|
const columns = new Map();
|
|
392
406
|
for (const h of hints) {
|
|
393
407
|
const c = columns.get(h.block) ?? { widest: 0, word: 6 };
|
|
@@ -412,13 +426,15 @@ const titleSheet = (m) => cheatSheet(m).filter((h) => m.chordsLead || h.block !=
|
|
|
412
426
|
* right, dim, as many as fit after what the row holds, given up from the end. With `first`, the
|
|
413
427
|
* first key always stands (a detail page's way back): what the row holds is cut to leave it room. */
|
|
414
428
|
function withKeys(given, hints, cols, { skip = ["leader", "palette", "help", "quit"], first = false } = {}) {
|
|
415
|
-
const keys = hints.filter((h) => !skip.includes(h.id));
|
|
416
429
|
const widthOf = (list) => list.reduce((sum, h) => sum + h.key.width + 1 + h.word.width, 0) + Math.max(0, list.length - 1) * GAP;
|
|
417
|
-
const
|
|
430
|
+
const whole = hints.filter((h) => !skip.includes(h.id));
|
|
431
|
+
const limit = first && whole.length ? cols - MARGIN - widthOf(whole.slice(0, 1)) - GAP : Infinity;
|
|
418
432
|
const row = limit === Infinity ? given : given.filter((span) => span.text === undefined || span.col < limit)
|
|
419
433
|
.map((span) => (span.text === undefined ? span : { ...span, width: Math.min(span.width ?? textWidth(textOf(span.text)), limit - span.col) }));
|
|
420
434
|
// What the row holds ends where its text does: a span may be given more cells than its text takes.
|
|
421
435
|
const end = row.reduce((most, span) => (span.text !== undefined ? Math.max(most, span.col + Math.min(span.width ?? Infinity, textWidth(textOf(span.text)))) : most), 0);
|
|
436
|
+
// A hint with a short key takes it when the row, after what it holds, cannot hold every key as it is.
|
|
437
|
+
const keys = end + GAP + widthOf(whole) <= cols - MARGIN ? whole : whole.map((h) => (h.short ? { ...h, key: h.short } : h));
|
|
422
438
|
let kept = keys;
|
|
423
439
|
// Given up from the end, the leader last (givenUp).
|
|
424
440
|
while (kept.length && end + GAP + widthOf(kept) > cols - MARGIN) kept = givenUp(kept);
|
|
@@ -690,10 +706,58 @@ function terminalAt(m, size, g) {
|
|
|
690
706
|
const both = Boolean(m.split) && !zoom && groups.length === 2 && splitFits(m.split, { cols: panel.cols, rows: panel.rows + 1 });
|
|
691
707
|
const [first, second, rule] = both ? splitRegions(panel, m.split) : [panel, null, null];
|
|
692
708
|
const regions = (both ? [{ ...first, group: 0 }, { ...second, group: 1 }] : [{ ...panel, group: focused }])
|
|
693
|
-
.map((r) => ({ ...r, id: groups[r.group]?.shown ?? null, focused: r.group === focused, whole }));
|
|
709
|
+
.map((r) => waited({ ...r, id: groups[r.group]?.shown ?? null, focused: r.group === focused, whole }, groups[r.group]?.waiting ?? null, m.ascii));
|
|
694
710
|
return { ...regions.find((r) => r.focused), panel, regions, rule };
|
|
695
711
|
}
|
|
696
712
|
|
|
713
|
+
/** THE WAITING ROW (docs/tui.md, "Tabs"; awebai/oats#1502), under a group's tab bar while its
|
|
714
|
+
* shown agent has a live claim: `Needs input` in the list's needs-input look (reverse video in the
|
|
715
|
+
* waiting colour, a cell of padding each side), then the claim's age dim after a dot (` · `,
|
|
716
|
+
* ` - ` in ASCII), then its message, the agent's text through the shared filter, or, with none,
|
|
717
|
+
* the TUI's words for its reason. The age stands before the message, so no cut removes it. The
|
|
718
|
+
* message wraps to at most WAITING_ROWS rows and to no more than a quarter of the region's
|
|
719
|
+
* height, the last row ending in the cut mark when more was left. */
|
|
720
|
+
const WAITING_ROWS = 3;
|
|
721
|
+
/** The cells before the age: the tag with its padding, a blank, the dot and a blank. */
|
|
722
|
+
const WAITING_LEAD = NEEDS_INPUT.length + 2 + 3;
|
|
723
|
+
/** The widest age the shared words give (packages/client/waiting-on-you.mjs waitedText). */
|
|
724
|
+
const WAITING_AGE_WIDEST = "under a minute".length;
|
|
725
|
+
/** The waiting row's text as rows: the first after the lead and the age (`age` cells of it), every
|
|
726
|
+
* other from the region's second cell, each with a cell of margin at the end. */
|
|
727
|
+
function waitingLines(waiting, cols, rows, age, ascii) {
|
|
728
|
+
const max = Math.max(1, Math.min(WAITING_ROWS, Math.floor(rows / 4)));
|
|
729
|
+
// The TUI's words are its own, and pass the shared filter as they are.
|
|
730
|
+
return shownLines(waiting.message ?? waiting.words, cols - 2, max, { ascii, first: cols - WAITING_LEAD - age - 2 });
|
|
731
|
+
}
|
|
732
|
+
/** A region with its waiting rows taken from the top of the agent's screen: `waiting` the rows
|
|
733
|
+
* waitingRows draws, or null. How many is counted with the widest age, so the agent's pane is
|
|
734
|
+
* resized when the claim starts, clears or changes its text, and never as its age grows. */
|
|
735
|
+
function waited(region, waiting, ascii) {
|
|
736
|
+
if (waiting === null || region.id === null) return { ...region, waiting: null };
|
|
737
|
+
const taken = waitingLines(waiting, region.cols, region.rows, WAITING_AGE_WIDEST, ascii).length;
|
|
738
|
+
if (taken === 0) return { ...region, waiting: null };
|
|
739
|
+
return { ...region, top: region.top + taken, rows: region.rows - taken, waiting: { ...waiting, taken } };
|
|
740
|
+
}
|
|
741
|
+
/** The waiting rows of a region that has them (waited): `taken` rows, the first holding the tag
|
|
742
|
+
* and the age. Drawn with the region's own age; a shorter one than the widest leaves the message
|
|
743
|
+
* more room, never fewer rows than were taken: the rest stay blank. */
|
|
744
|
+
function waitingRows(region, ascii) {
|
|
745
|
+
const { waiting } = region, col = region.col, end = col + region.cols;
|
|
746
|
+
const dot = ascii ? "-" : "\u00b7";
|
|
747
|
+
const lines = waitingLines(waiting, region.cols, region.rows + waiting.taken, waiting.age.length, ascii).slice(0, waiting.taken);
|
|
748
|
+
const first = [
|
|
749
|
+
{ col, width: NEEDS_INPUT.length + 2, style: WAITS }, { col: col + 1, text: lit(NEEDS_INPUT), style: WAITS, width: NEEDS_INPUT.length },
|
|
750
|
+
{ col: col + NEEDS_INPUT.length + 3, text: lit(dot), style: DIM, width: 1 },
|
|
751
|
+
{ col: col + NEEDS_INPUT.length + 5, text: lit(waiting.age), style: DIM, width: waiting.age.length },
|
|
752
|
+
];
|
|
753
|
+
const at = col + WAITING_LEAD + waiting.age.length + 1;
|
|
754
|
+
return Array.from({ length: waiting.taken }, (_, i) => {
|
|
755
|
+
const line = lines[i], start = i === 0 ? at : col + 1;
|
|
756
|
+
const spans = line ? [{ col: start, text: line, width: Math.max(0, Math.min(textWidth(textOf(line)), end - start)) }] : [];
|
|
757
|
+
return i === 0 ? [...first, ...spans] : spans;
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
|
|
697
761
|
/** A hidden tab's mark for output since it was last shown (docs/tui.md, "Tabs"). */
|
|
698
762
|
const ACTIVITY = "\u2022";
|
|
699
763
|
/** What stands between a tab's agent and its machine, another machine's: ` · ` (` - ` in ASCII). */
|
|
@@ -834,10 +898,11 @@ function regionRows(m, area) {
|
|
|
834
898
|
// A model made by hand may name its terminal and no tabs: its one tab is that terminal.
|
|
835
899
|
const tabs = group.tabs.length ? group.tabs : [{ name: m.terminal?.name, machine: m.terminal?.routed ? m.terminal.machine : null, shown: true, activity: false }];
|
|
836
900
|
const title = stripRow(tabs, area, { focused, ascii: m.ascii, numbers: m.tabNumbers !== false });
|
|
901
|
+
const waiting = area.waiting ? waitingRows(area, m.ascii) : [];
|
|
837
902
|
const screenOf = area.focused ? m.screen : m.screens?.get(group.shown) ?? null;
|
|
838
903
|
const lines = screenOf?.lines ?? [];
|
|
839
904
|
const body = Array.from({ length: area.rows }, (_, r) => (lines[r] ?? [])
|
|
840
905
|
.filter((span) => span.col < area.cols)
|
|
841
906
|
.map((span) => ({ ...span, col: area.col + span.col, width: Math.min(span.width ?? area.cols, area.cols - span.col) })));
|
|
842
|
-
return [title, ...body];
|
|
907
|
+
return [title, ...waiting, ...body];
|
|
843
908
|
}
|