@awebai/oats 0.64.0 → 0.65.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/bin/oats.mjs +101 -4
- package/docs/desktop-cli-api.md +84 -2
- package/docs/desktop.md +14 -5
- package/docs/implementation.md +17 -3
- package/docs/release-notes/v0.65.0.md +187 -0
- package/docs/tui.md +416 -238
- package/docs/upgrading.md +1 -1
- package/docs/workspaces.md +124 -0
- package/lib/core.mjs +14 -4
- package/lib/deployments.mjs +325 -0
- package/lib/resolved-deployment.mjs +37 -0
- package/lib/workspace.mjs +2 -0
- package/package.json +1 -1
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-label.mjs +2 -2
- package/packages/client/deployment-list-cli.mjs +98 -0
- package/packages/client/deployment-list.mjs +91 -0
- package/packages/client/keymap.mjs +106 -0
- package/packages/client/own-codes.mjs +2 -0
- package/packages/client/panel-views.mjs +1 -1
- package/packages/client/workspace-admission.mjs +2 -1
- package/packages/tui/README.md +4 -4
- package/packages/tui/lib/actions.mjs +29 -5
- package/packages/tui/lib/client.mjs +3 -1
- package/packages/tui/lib/config.mjs +21 -14
- package/packages/tui/lib/main.mjs +108 -31
- package/packages/tui/lib/model.mjs +71 -41
- package/packages/tui/lib/read.mjs +15 -45
- package/packages/tui/lib/store.mjs +158 -39
- package/packages/tui/lib/term/through.mjs +40 -18
- package/packages/tui/lib/views/act.mjs +17 -13
- package/packages/tui/lib/views/frame.mjs +418 -421
- package/packages/tui/lib/views/help.mjs +41 -19
- package/packages/tui/lib/views/instances.mjs +38 -9
- package/packages/tui/lib/views/switcher.mjs +65 -21
- package/skills/oats-getting-started/SKILL.md +6 -4
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** This computer's deployments list, through the kernel (awebai/oats#1390): the four `oats deployments`
|
|
2
|
+
* verbs a client runs, fixed argv, bounded output, the instance environment scrubbed. The answers are
|
|
3
|
+
* read by deployment-list.mjs; only the kernel's JSON crosses back, and a refusal is its code and message.
|
|
4
|
+
* list → `oats deployments --json` (cwd /)
|
|
5
|
+
* add → `oats deployments add <path> --via <client> --json` (cwd <path>)
|
|
6
|
+
* remove → `oats deployments remove <path> --json` (cwd /)
|
|
7
|
+
* import → `oats deployments import --from <client> <path>… --json` (cwd /; no path is a valid call;
|
|
8
|
+
* each path absolute as the client saved it, which the kernel canonicalizes)
|
|
9
|
+
* Each needs the probe's `deployments-list` feature: without it nothing runs, and nothing falls back to
|
|
10
|
+
* looking at the disk. `/` is the working directory of the verbs that name no deployment, so a client
|
|
11
|
+
* started inside one never has it resolved by the kernel on the way. */
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { cliEnvironment } from './cli-environment.mjs';
|
|
14
|
+
import { withoutInstanceVariables } from './kernel-environment.mjs';
|
|
15
|
+
import { absolutePath, deploymentsListSupported, listedPath, readDeploymentAdd, readDeploymentImport, readDeploymentList, readDeploymentRemove } from './deployment-list.mjs';
|
|
16
|
+
|
|
17
|
+
/** The kernel waits up to 3 s for the list's lock; the rest is a node start and a small file. */
|
|
18
|
+
export const DEPLOYMENT_LIST_TIMEOUT = 15_000;
|
|
19
|
+
/** The list file is at most 1 MiB; its answer adds a name and a state per row. */
|
|
20
|
+
export const DEPLOYMENT_LIST_MAX_BUFFER = 4 * 1024 * 1024;
|
|
21
|
+
/** The most paths one import names: an argv bound, far above any saved set. A longer import is refused
|
|
22
|
+
* whole, never cut: the caller keeps what it would import. */
|
|
23
|
+
export const DEPLOYMENT_IMPORT_MAX = 2000;
|
|
24
|
+
/** The clients the kernel takes in `--via` and `--from`. */
|
|
25
|
+
const CLIENTS = ['desktop', 'tui'];
|
|
26
|
+
|
|
27
|
+
const messages = Object.freeze({
|
|
28
|
+
E_CLI_UNAVAILABLE: 'Choose a compatible installed OATS CLI first.',
|
|
29
|
+
E_DEPLOYMENTS_FEATURE: "This oats can't list this computer's deployments. Update oats.",
|
|
30
|
+
E_BAD_ARGS: "The request to this computer's deployments list was not valid.",
|
|
31
|
+
E_CLI_FAILED: "The installed OATS CLI could not change or read this computer's deployments list.",
|
|
32
|
+
E_CLI_PROTOCOL: "The installed OATS CLI returned an invalid answer about this computer's deployments.",
|
|
33
|
+
E_CLI_TIMEOUT: "The installed OATS CLI did not answer about this computer's deployments in time.",
|
|
34
|
+
E_CLI_OUTPUT_LIMIT: "The installed OATS CLI's answer about this computer's deployments was too large.",
|
|
35
|
+
});
|
|
36
|
+
export const DEPLOYMENT_LIST_FAILURE_CODES = Object.freeze(Object.keys(messages));
|
|
37
|
+
const failure = (code) => ({ ok: false, reason: { code, message: messages[code] } });
|
|
38
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
|
|
40
|
+
/** The argv and working directory of one verb, or null for a request that could not be one. */
|
|
41
|
+
export function deploymentListArgv(options) {
|
|
42
|
+
if (!record(options)) return null;
|
|
43
|
+
const keys = Object.keys(options), only = (...allowed) => keys.every((key) => allowed.includes(key));
|
|
44
|
+
switch (options.action) {
|
|
45
|
+
case 'list': return only('action') ? { argv: ['deployments', '--json'], cwd: '/' } : null;
|
|
46
|
+
case 'add':
|
|
47
|
+
if (!only('action', 'path', 'via') || !listedPath(options.path) || !CLIENTS.includes(options.via)) return null;
|
|
48
|
+
return { argv: ['deployments', 'add', options.path, '--via', options.via, '--json'], cwd: options.path };
|
|
49
|
+
case 'remove':
|
|
50
|
+
if (!only('action', 'path') || !listedPath(options.path)) return null;
|
|
51
|
+
return { argv: ['deployments', 'remove', options.path, '--json'], cwd: '/' };
|
|
52
|
+
case 'import':
|
|
53
|
+
if (!only('action', 'from', 'paths') || !CLIENTS.includes(options.from) || !Array.isArray(options.paths)
|
|
54
|
+
|| options.paths.length > DEPLOYMENT_IMPORT_MAX || !options.paths.every(absolutePath)) return null;
|
|
55
|
+
return { argv: ['deployments', 'import', '--from', options.from, ...options.paths, '--json'], cwd: '/' };
|
|
56
|
+
default: return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const READERS = { list: readDeploymentList, add: readDeploymentAdd, remove: readDeploymentRemove, import: readDeploymentImport };
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Run one verb. `cli` is the client's accepted probe (`{ ok, bin, features }`); `io.exec` its own `execFile`
|
|
64
|
+
* (cli-adapter.mjs `runJson` says what it must keep).
|
|
65
|
+
* @returns {Promise<{ ok: true, value: object } | { ok: false, reason: { code: string, message: string } }>}
|
|
66
|
+
* `value` is what deployment-list.mjs reads from the answer (the list's `{ ok: true, rows }`, the add's `{ path, added }`, …).
|
|
67
|
+
*/
|
|
68
|
+
export function cliDeploymentList(cli, options, io = {}) {
|
|
69
|
+
if (cli?.ok !== true || typeof cli.bin !== 'string' || !cli.bin.startsWith('/')) return Promise.resolve(failure('E_CLI_UNAVAILABLE'));
|
|
70
|
+
if (!deploymentsListSupported(cli)) return Promise.resolve(failure('E_DEPLOYMENTS_FEATURE'));
|
|
71
|
+
const plan = deploymentListArgv(options);
|
|
72
|
+
if (!plan) return Promise.resolve(failure('E_BAD_ARGS'));
|
|
73
|
+
const env = withoutInstanceVariables(cliEnvironment(io.env ?? process.env));
|
|
74
|
+
return new Promise((done) => {
|
|
75
|
+
const fail = (code) => done(failure(code));
|
|
76
|
+
try {
|
|
77
|
+
(io.exec ?? execFile)(cli.bin, plan.argv, { cwd: plan.cwd, env, shell: false, encoding: 'utf8', timeout: DEPLOYMENT_LIST_TIMEOUT, maxBuffer: DEPLOYMENT_LIST_MAX_BUFFER }, (error, stdout) => {
|
|
78
|
+
if (error?.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') return fail('E_CLI_OUTPUT_LIMIT');
|
|
79
|
+
if (error?.killed) return fail('E_CLI_TIMEOUT');
|
|
80
|
+
if (typeof stdout !== 'string') return fail(error ? 'E_CLI_FAILED' : 'E_CLI_PROTOCOL');
|
|
81
|
+
let document;
|
|
82
|
+
try { document = JSON.parse(stdout); } catch { return fail(error ? 'E_CLI_FAILED' : 'E_CLI_PROTOCOL'); }
|
|
83
|
+
if (!record(document) || document.schemaVersion !== 1 || typeof document.ok !== 'boolean') return fail('E_CLI_PROTOCOL');
|
|
84
|
+
if (document.ok === false) {
|
|
85
|
+
const reason = document.error;
|
|
86
|
+
if (!record(reason) || typeof reason.code !== 'string' || !/^E_[A-Z0-9_]{1,62}$/.test(reason.code)
|
|
87
|
+
|| typeof reason.message !== 'string' || !reason.message || reason.message.length > 8192) return fail('E_CLI_PROTOCOL');
|
|
88
|
+
// A refusal is a nonzero exit; a success exit cannot carry one.
|
|
89
|
+
return error ? done({ ok: false, reason: { code: reason.code, message: reason.message } }) : fail('E_CLI_PROTOCOL');
|
|
90
|
+
}
|
|
91
|
+
if (error) return fail('E_CLI_FAILED'); // success is exit 0 only
|
|
92
|
+
const value = READERS[options.action](document.result);
|
|
93
|
+
if (!value || value.ok === false) return fail('E_CLI_PROTOCOL');
|
|
94
|
+
done({ ok: true, value });
|
|
95
|
+
});
|
|
96
|
+
} catch { fail('E_CLI_FAILED'); }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** This computer's deployments, as the kernel lists them (awebai/oats#1390): the `result` of
|
|
2
|
+
* `oats deployments --json` (feature `deployments-list`, `deploymentsApi: 1`) read into rows of
|
|
3
|
+
* `{ path, name, state }`. The list is the kernel's, kept in `~/.oats/config/deployments.json`; a client
|
|
4
|
+
* reads it, never the file, and changes it only through `oats deployments add|remove|import`.
|
|
5
|
+
*
|
|
6
|
+
* A row's `state` comes from the kernel's existence check (nothing of the deployment is read): one of
|
|
7
|
+
* DEPLOYMENT_STATES. Each client puts the four states into its own words. A row is a suggestion: a
|
|
8
|
+
* client that opens one validates it again first (workspace-admission.mjs).
|
|
9
|
+
*
|
|
10
|
+
* The document's shape is closed (docs/desktop-cli-api.md): a key, a state or a `via` this reader does
|
|
11
|
+
* not know, a duplicate path or a path that is not absolute refuses the whole document. It is never
|
|
12
|
+
* guessed at, and never read in part. The answers of the writes are read here too. Nothing here keeps
|
|
13
|
+
* state between calls. */
|
|
14
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
15
|
+
|
|
16
|
+
/** The probe feature that makes `oats deployments` exist. */
|
|
17
|
+
export const DEPLOYMENTS_LIST_FEATURE = 'deployments-list';
|
|
18
|
+
/** The integer the list document carries. */
|
|
19
|
+
export const DEPLOYMENTS_API = 1;
|
|
20
|
+
/** Every state a row can have: `ok` (a deployment), `missing` (the path is gone, or on a volume not
|
|
21
|
+
* mounted), `not-a-deployment` (the folder has no oats-local.yaml), `unreadable` (the check failed). */
|
|
22
|
+
export const DEPLOYMENT_STATES = Object.freeze(['ok', 'missing', 'not-a-deployment', 'unreadable']);
|
|
23
|
+
/** How a row joined the list: information only, never acted on. */
|
|
24
|
+
export const DEPLOYMENT_VIAS = Object.freeze(['onboard', 'tui', 'desktop', 'cli', 'import:agents-dir', 'import:desktop']);
|
|
25
|
+
|
|
26
|
+
const DOCUMENT_KEYS = ['deploymentsApi', 'file', 'deployments', 'imports'];
|
|
27
|
+
const ROW_KEYS = ['path', 'name', 'state', 'addedAt', 'via'];
|
|
28
|
+
|
|
29
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
30
|
+
const exactKeys = (value, keys) => Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
31
|
+
const text = (value) => typeof value === 'string' && value.length > 0 && !value.includes('\0');
|
|
32
|
+
/** An absolute path as the kernel stores it: canonical in form (no `.`, `..`, `//` or trailing `/`). */
|
|
33
|
+
export const listedPath = (value) => text(value) && isAbsolute(value) && resolve(value) === value;
|
|
34
|
+
/** An absolute path in any form: what an import names, as a client saved it (the kernel canonicalizes it). */
|
|
35
|
+
export const absolutePath = (value) => text(value) && isAbsolute(value);
|
|
36
|
+
|
|
37
|
+
/** Whether a probe (`oats version --json`, accepted) declares the list. */
|
|
38
|
+
export const deploymentsListSupported = (cli) => Array.isArray(cli?.features) && cli.features.includes(DEPLOYMENTS_LIST_FEATURE);
|
|
39
|
+
|
|
40
|
+
const refused = (reason) => ({ ok: false, rows: [], reason });
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {unknown} result the envelope's `result` of `oats deployments --json`
|
|
44
|
+
* @returns {{ ok: true, rows: Array<{ path: string, name: string, state: string }> } | { ok: false, rows: [], reason: string }}
|
|
45
|
+
* rows in the kernel's order; `reason` says, for a log, why the document was refused.
|
|
46
|
+
*/
|
|
47
|
+
export function readDeploymentList(result) {
|
|
48
|
+
if (!record(result)) return refused('the list is not an object');
|
|
49
|
+
if (result.deploymentsApi !== DEPLOYMENTS_API) return refused(`deploymentsApi is not ${DEPLOYMENTS_API}`);
|
|
50
|
+
if (!exactKeys(result, DOCUMENT_KEYS)) return refused('the list has keys this client does not read');
|
|
51
|
+
if (!listedPath(result.file)) return refused('file is not an absolute path');
|
|
52
|
+
if (!record(result.imports) || !Object.values(result.imports).every(text)) return refused('imports is not a set of markers');
|
|
53
|
+
if (!Array.isArray(result.deployments)) return refused('deployments is not a list');
|
|
54
|
+
const rows = [], seen = new Set();
|
|
55
|
+
for (const row of result.deployments) {
|
|
56
|
+
if (!record(row) || !exactKeys(row, ROW_KEYS)) return refused('a row has keys this client does not read');
|
|
57
|
+
if (!listedPath(row.path)) return refused('a row path is not an absolute path');
|
|
58
|
+
if (seen.has(row.path)) return refused(`${row.path} is listed twice`);
|
|
59
|
+
if (!text(row.name)) return refused(`${row.path} has no name`);
|
|
60
|
+
if (!DEPLOYMENT_STATES.includes(row.state)) return refused(`${row.path} has a state this client does not know`);
|
|
61
|
+
if (!text(row.addedAt)) return refused(`${row.path} has no addedAt`);
|
|
62
|
+
if (!DEPLOYMENT_VIAS.includes(row.via)) return refused(`${row.path} has a via this client does not know`);
|
|
63
|
+
seen.add(row.path);
|
|
64
|
+
rows.push({ path: row.path, name: row.name, state: row.state });
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, rows };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* The answers of the three writes, each a closed `result` like the list's. Each reader answers its
|
|
70
|
+
* fields, or null for a document it cannot read. */
|
|
71
|
+
|
|
72
|
+
/** `oats deployments add <dir> --json`: `{ path, added }`; `added` is false when the path was listed already. */
|
|
73
|
+
export function readDeploymentAdd(result) {
|
|
74
|
+
return record(result) && exactKeys(result, ['path', 'added']) && listedPath(result.path) && typeof result.added === 'boolean'
|
|
75
|
+
? { path: result.path, added: result.added } : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `oats deployments remove <path> --json`: `{ path, removed }`; `removed` is false when the path was not listed. */
|
|
79
|
+
export function readDeploymentRemove(result) {
|
|
80
|
+
return record(result) && exactKeys(result, ['path', 'removed']) && listedPath(result.path) && typeof result.removed === 'boolean'
|
|
81
|
+
? { path: result.path, removed: result.removed } : null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `oats deployments import --from <client> <path>… --json`: `{ imported: true, at, added: [path…] }` the first
|
|
85
|
+
* time, `{ imported: false, at }` after it (`at` is the import's marker). Either answer means the import is done. */
|
|
86
|
+
export function readDeploymentImport(result) {
|
|
87
|
+
if (!record(result) || !text(result.at)) return null;
|
|
88
|
+
if (result.imported === false) return exactKeys(result, ['imported', 'at']) ? { imported: false, at: result.at, added: [] } : null;
|
|
89
|
+
if (result.imported !== true || !exactKeys(result, ['imported', 'at', 'added']) || !Array.isArray(result.added) || !result.added.every(absolutePath)) return null;
|
|
90
|
+
return { imported: true, at: result.at, added: [...result.added] };
|
|
91
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** The keys both clients share: the leader, the table read after it, and the plain keys of the list
|
|
2
|
+
* of instances. Written down once, here; the Desktop reads its defaults from it, and the TUI's own
|
|
3
|
+
* table (packages/tui/lib/actions.mjs LEADER) is held equal to LEADER_TABLE by the root test
|
|
4
|
+
* test/keymap-parity.test.mjs until the TUI imports this module.
|
|
5
|
+
*
|
|
6
|
+
* Pure data and readers: no state, no DOM, no imports. Every value is frozen.
|
|
7
|
+
*
|
|
8
|
+
* Key ids are the TUI's spelling (packages/tui/lib/term/keys.mjs keyId): one character as itself,
|
|
9
|
+
* case kept (`n`, `N`, `|`, `?`, `/`, `-`); named keys `up` `down` `left` `right` `tab` `escape`
|
|
10
|
+
* `space` `enter` `home` `end` `pageup` `pagedown`; modifiers as `ctrl+` / `alt+` prefixes.
|
|
11
|
+
*
|
|
12
|
+
* leaderKey(isMac) -> the leader's key id on that platform "ctrl+\\" / "alt+o"
|
|
13
|
+
* leaderDoes(key) -> what the leader then does for a key id, or null
|
|
14
|
+
* plainKeys(does) -> the plain key ids of an action (empty when it has none)
|
|
15
|
+
* leaderRows() -> LEADER_TABLE
|
|
16
|
+
*
|
|
17
|
+
* `does` names an action, not a client's code: each client maps it to its own. */
|
|
18
|
+
|
|
19
|
+
/** The leader per platform: Ctrl+\ on macOS, Alt+O elsewhere. */
|
|
20
|
+
export const LEADER = Object.freeze({ mac: "ctrl+\\", other: "alt+o" });
|
|
21
|
+
|
|
22
|
+
/** The keys read after the leader, in the TUI's order, and what each does. `terminal`: named in
|
|
23
|
+
* the hint only while a terminal is open. The leader pressed twice is not here: it is the user's
|
|
24
|
+
* key, and each client says what it does. */
|
|
25
|
+
export const LEADER_TABLE = Object.freeze([
|
|
26
|
+
{ keys: ["k", "space"], does: "palette", label: "palette" },
|
|
27
|
+
{ keys: ["1"], does: "instances", label: "instances" },
|
|
28
|
+
{ keys: ["2"], does: "souls", label: "souls" },
|
|
29
|
+
{ keys: ["3"], does: "capabilities", label: "capabilities" },
|
|
30
|
+
{ keys: ["up"], does: "previous", label: "previous instance" },
|
|
31
|
+
{ keys: ["down"], does: "next", label: "next instance" },
|
|
32
|
+
{ keys: ["z"], does: "zoom", label: "zoom", terminal: true },
|
|
33
|
+
{ keys: ["w"], does: "close-terminal", label: "close terminal", terminal: true },
|
|
34
|
+
{ keys: ["left"], does: "tab-previous", label: "previous tab", terminal: true },
|
|
35
|
+
{ keys: ["right"], does: "tab-next", label: "next tab", terminal: true },
|
|
36
|
+
{ keys: ["|"], does: "split-right", label: "split right", terminal: true },
|
|
37
|
+
{ keys: ["-"], does: "split-down", label: "split down", terminal: true },
|
|
38
|
+
{ keys: ["tab"], does: "group-next", label: "next group", terminal: true },
|
|
39
|
+
{ keys: ["m"], does: "tab-move", label: "move tab", terminal: true },
|
|
40
|
+
{ keys: ["x"], does: "group-close", label: "close group", terminal: true },
|
|
41
|
+
{ keys: ["X"], does: "stop", label: "stop" },
|
|
42
|
+
{ keys: ["R"], does: "restart", label: "restart" },
|
|
43
|
+
{ keys: ["S"], does: "start", label: "start" },
|
|
44
|
+
{ keys: ["D"], does: "retire", label: "retire" },
|
|
45
|
+
{ keys: ["n"], does: "spawn", label: "spawn" },
|
|
46
|
+
{ keys: ["N"], does: "spawn-another", label: "spawn another" },
|
|
47
|
+
{ keys: ["/"], does: "filter", label: "filter" },
|
|
48
|
+
{ keys: ["o"], does: "workspaces", label: "workspaces" },
|
|
49
|
+
{ keys: ["?"], does: "help", label: "help" },
|
|
50
|
+
{ keys: ["escape"], does: "list", label: "the list" },
|
|
51
|
+
].map((row) => Object.freeze({ ...row, keys: Object.freeze([...row.keys]) })));
|
|
52
|
+
|
|
53
|
+
/** The plain keys both clients read in the list of instances (the TUI's ACTIONS), one entry per action. */
|
|
54
|
+
export const PLAIN_KEYS = Object.freeze([
|
|
55
|
+
{ does: "up", keys: ["up", "k"] },
|
|
56
|
+
{ does: "down", keys: ["down", "j"] },
|
|
57
|
+
{ does: "top", keys: ["g", "home"] },
|
|
58
|
+
{ does: "bottom", keys: ["G", "end"] },
|
|
59
|
+
{ does: "page-up", keys: ["pageup"] },
|
|
60
|
+
{ does: "page-down", keys: ["pagedown"] },
|
|
61
|
+
{ does: "collapse", keys: ["left", "h"] },
|
|
62
|
+
{ does: "expand", keys: ["right", "l"] },
|
|
63
|
+
{ does: "filter", keys: ["/"] },
|
|
64
|
+
{ does: "refresh", keys: ["r"] },
|
|
65
|
+
{ does: "instances", keys: ["1"] },
|
|
66
|
+
{ does: "souls", keys: ["2"] },
|
|
67
|
+
{ does: "capabilities", keys: ["3"] },
|
|
68
|
+
{ does: "workspaces", keys: ["w"] },
|
|
69
|
+
{ does: "open", keys: ["enter"] },
|
|
70
|
+
{ does: "zoom", keys: ["z"] },
|
|
71
|
+
{ does: "close-terminal", keys: ["c"] },
|
|
72
|
+
{ does: "tab-previous", keys: ["["] },
|
|
73
|
+
{ does: "tab-next", keys: ["]"] },
|
|
74
|
+
{ does: "split-right", keys: ["|"] },
|
|
75
|
+
{ does: "split-down", keys: ["-"] },
|
|
76
|
+
{ does: "stop", keys: ["X"] },
|
|
77
|
+
{ does: "retire", keys: ["D"] },
|
|
78
|
+
{ does: "start", keys: ["S"] },
|
|
79
|
+
{ does: "restart", keys: ["R"] },
|
|
80
|
+
{ does: "spawn", keys: ["n"] },
|
|
81
|
+
{ does: "spawn-another", keys: ["N"] },
|
|
82
|
+
{ does: "help", keys: ["?"] },
|
|
83
|
+
].map((entry) => Object.freeze({ ...entry, keys: Object.freeze([...entry.keys]) })));
|
|
84
|
+
|
|
85
|
+
const NONE = Object.freeze([]);
|
|
86
|
+
|
|
87
|
+
/** The leader's key id on macOS (`true`) or elsewhere. */
|
|
88
|
+
export function leaderKey(isMac) {
|
|
89
|
+
return isMac ? LEADER.mac : LEADER.other;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** What the leader then does for `keyId`, or null when the table has no such key. */
|
|
93
|
+
export function leaderDoes(keyId) {
|
|
94
|
+
for (const row of LEADER_TABLE) if (row.keys.includes(keyId)) return row.does;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The plain key ids of the action `does`, frozen; empty when it has none. */
|
|
99
|
+
export function plainKeys(does) {
|
|
100
|
+
return PLAIN_KEYS.find((entry) => entry.does === does)?.keys ?? NONE;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The leader's table, LEADER_TABLE itself. */
|
|
104
|
+
export function leaderRows() {
|
|
105
|
+
return LEADER_TABLE;
|
|
106
|
+
}
|
|
@@ -14,6 +14,8 @@ export const CLIENT_OWN_CODES = Object.freeze([
|
|
|
14
14
|
// Reading a deployment, a workspace and another machine's roster.
|
|
15
15
|
'E_CAPABILITY_SHOW_FEATURE', 'E_DEPLOYMENT_BUSY', 'E_DEPLOYMENT_FEATURE', 'E_DEPLOYMENT_SCOPE', 'E_DEPLOYMENT_STALE',
|
|
16
16
|
'E_REMOTE_ROSTER', 'E_WORKSPACE_FEATURE', 'E_WORKSPACE_UNKNOWN',
|
|
17
|
+
// This computer's deployments list (#1390): a CLI without it.
|
|
18
|
+
'E_DEPLOYMENTS_FEATURE',
|
|
17
19
|
// A spawn: its preview, its apply and the wake saved with it.
|
|
18
20
|
'E_APPLY_UNAVAILABLE', 'E_BACKEND_UNAVAILABLE', 'E_BUSY', 'E_FORBIDDEN_FRAME', 'E_INPUT_PREPARATION', 'E_INSTANCE_GONE',
|
|
19
21
|
'E_INTENT_EXPIRED', 'E_OUTCOME_UNKNOWN', 'E_PREFLIGHT_INCOMPLETE', 'E_PREVIEW_UNAVAILABLE', 'E_TARGET_CHANGED',
|
|
@@ -319,7 +319,7 @@ export function workspaceChoices(held, terms, model) {
|
|
|
319
319
|
// before views, not as "not matched" (each deployment's own reason still says why).
|
|
320
320
|
const unmatched = v.unattached && identityFeature(held);
|
|
321
321
|
return { id: v.id, name: v.name, team: null, deployments: [...v.deployments],
|
|
322
|
-
// The deployments' labels, in the same order, for a view that is not on screen ("This Mac · ~/
|
|
322
|
+
// The deployments' labels, in the same order, for a view that is not on screen ("This Mac · ~/acme").
|
|
323
323
|
deploymentLabels: v.deployments.map((id) => deploymentLabel(model.infos.get(id), terms)),
|
|
324
324
|
// The switcher's one-liner (UI spec, #482): the machines, in order and once each, and how many deployments aren't live.
|
|
325
325
|
machines: [...new Set(v.deployments.map((id) => model.infos.get(id)?.machine).filter(Boolean))],
|
|
@@ -12,7 +12,8 @@ export const deploymentCheck = (io) => (p) => { try { return io.isDeployment(p)
|
|
|
12
12
|
|
|
13
13
|
/** The deployments directly inside `dir`, sorted by name: at most PICK_SCAN_LIMIT entries read, a
|
|
14
14
|
* link never followed, nothing parsed. An unreadable or missing `dir` holds none. Used for a picked
|
|
15
|
-
* parent folder
|
|
15
|
+
* parent folder. The deployments the Desktop offers unasked come from this computer's deployments
|
|
16
|
+
* list, which the kernel keeps (deployment-list.mjs, #1390), not from a look inside a folder.
|
|
16
17
|
* @param {string} dir
|
|
17
18
|
* @param {object} io
|
|
18
19
|
* @param {(dir: string, limit: number) => { entries: Array<{ name: string, isDirectory: boolean }>, limited: boolean }} io.list
|
package/packages/tui/README.md
CHANGED
|
@@ -20,12 +20,12 @@ never does.
|
|
|
20
20
|
| path | contents |
|
|
21
21
|
|---|---|
|
|
22
22
|
| `bin/tui.mjs` | the entry `bin/oats.mjs` loads: it imports the whole module graph, then runs `main()` |
|
|
23
|
-
| `lib/main.mjs` | the start (arguments, environment, terminal, `tui.json`, deployment, kernel) and the loop: events through `reduce`, effects out, the frame drawn |
|
|
24
|
-
| `lib/actions.mjs` | the action table and its default keys: the reducer, the
|
|
23
|
+
| `lib/main.mjs` | the start (arguments, environment, terminal, `tui.json`, deployment, kernel, and outside every deployment this computer's list of deployments) and the loop: events through `reduce`, effects out, the frame drawn; the list's reads, the add of the deployment the run starts in and the switcher's Remove, through the shared `cliDeploymentList` |
|
|
24
|
+
| `lib/actions.mjs` | the action table and its default keys: the reducer, the cheat sheet and the help read the effective one |
|
|
25
25
|
| `lib/config.mjs` | `tui.json`: read once, checked, and the effective action table |
|
|
26
26
|
| `lib/client.mjs` | the one module that imports the shared readers (`packages/client/`), and the client's terms |
|
|
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
|
-
| `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 changes (a stop or retire apply, a start or restart: never ended, their output in files of the run's private directory),
|
|
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 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) |
|
|
30
30
|
| `lib/model.mjs` | from the state to the rows and the detail to draw, and to the switcher's rows, 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 |
|
|
@@ -36,7 +36,7 @@ never does.
|
|
|
36
36
|
| `lib/term/through.mjs` | the bytes typed while a terminal has the focus: the back key's grammar and bytes, and the scanner that takes the back key and a bracketed paste out of them |
|
|
37
37
|
| `lib/term/screen.mjs` | the cell buffer and the bytes of a frame |
|
|
38
38
|
| `lib/term/tty.mjs` | the guard: enter, leave, signals, suspend, resize, one write per frame |
|
|
39
|
-
| `lib/views/` | pure functions from the model and a size to rows of spans: the frame, the list, the detail, the Capabilities view (`capabilities.mjs`), the switcher, the help, the confirmation of an act (`act.mjs`), the spawn prompt (`spawn.mjs`), the split's geometry (`split.mjs`) |
|
|
39
|
+
| `lib/views/` | pure functions from the model and a size to rows of spans: the frame (the sidebar: its title, the accordion of the three views and the cheat sheet; the main area beside it), the list, the detail, the Capabilities view (`capabilities.mjs`), the switcher, the help, the confirmation of an act (`act.mjs`), the spawn prompt (`spawn.mjs`), the split's geometry (`split.mjs`) |
|
|
40
40
|
|
|
41
41
|
Rules the tests pin (`test/tui-boundary.test.mjs` reads the files):
|
|
42
42
|
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// An action that does one thing in the list of instances and another in the switcher (`open`)
|
|
6
6
|
// says so in `views`: what it does in each, in the order the help lists them. An action of one
|
|
7
7
|
// view only (the four acts) names that view, so the help says where it acts.
|
|
8
|
+
import { isBackKey } from "./term/through.mjs";
|
|
9
|
+
|
|
8
10
|
export const ACTIONS = Object.freeze([
|
|
9
11
|
{ id: "up", keys: ["up", "k"], label: "up" },
|
|
10
12
|
{ id: "down", keys: ["down", "j"], label: "down" },
|
|
@@ -17,8 +19,8 @@ export const ACTIONS = Object.freeze([
|
|
|
17
19
|
{ id: "detail", keys: ["tab"], label: "detail" },
|
|
18
20
|
{ id: "filter", keys: ["/"], label: "filter" },
|
|
19
21
|
{ id: "refresh", keys: ["r"], label: "refresh" },
|
|
20
|
-
// The views by their number. The
|
|
21
|
-
// (docs/tui.md, "
|
|
22
|
+
// The views by their number. The sidebar names the views, each with its key at the right of its row
|
|
23
|
+
// (docs/tui.md, "What it shows"): the digits are named here, so in the help and the sidebar.
|
|
22
24
|
{ id: "instances", keys: ["1"], label: "instances" },
|
|
23
25
|
{ id: "souls", keys: ["2"], label: "souls" },
|
|
24
26
|
{ id: "capabilities", keys: ["3"], label: "capabilities" },
|
|
@@ -26,13 +28,19 @@ export const ACTIONS = Object.freeze([
|
|
|
26
28
|
// The palette (docs/tui.md, "The palette"): from every focus it is the leader and then `k`.
|
|
27
29
|
{ id: "palette", keys: ["ctrl+k"], label: "palette" },
|
|
28
30
|
{ id: "open", keys: ["enter"], label: "open", views: [["instances", "open the selected agent's terminal as a tab beside the list, or show its tab when it has one, in the list of instances"], ["switcher", "open the selected workspace, in the switcher"], ["souls", "show the selected soul's detail, and from the detail its instances, in the Souls view"], ["capabilities", "show the selected capability's detail, and from the detail the marked soul that uses it, in the Capabilities view"]] },
|
|
31
|
+
// The switcher's Remove (docs/tui.md, "The switcher"; awebai/oats#1390): a row of this computer's
|
|
32
|
+
// deployments list, after a confirmation; nothing on disk is touched. Delete, and no letter: a new
|
|
33
|
+
// default key that a user's tui.json already gives to another action would make that file refused
|
|
34
|
+
// at the start (config.mjs claims every default first), and the free letters are the ones a
|
|
35
|
+
// tui.json is likeliest to use (`x` and `m` among them, see the split below).
|
|
36
|
+
{ id: "remove", keys: ["delete"], label: "remove", views: [["switcher", "remove the selected row of this computer's list of deployments, after a confirmation; its folder stays"]] },
|
|
29
37
|
// The Souls view (docs/tui.md, "The Souls view"): the selected soul's instances, in the
|
|
30
38
|
// Instances view, filtered by that soul.
|
|
31
39
|
{ id: "soul-instances", keys: ["i"], label: "instances", views: [["souls", "the selected soul's instances, in the Instances view"]] },
|
|
32
40
|
// The open terminal, from the list (docs/tui.md, "Open an agent's terminal"). While the terminal
|
|
33
41
|
// has the focus the TUI takes no key but the leader (tui.json's open.detachKey), so neither of
|
|
34
42
|
// these is ever read there: the leader's table has its own (LEADER).
|
|
35
|
-
{ id: "zoom", keys: ["z"], label: "zoom", views: [["instances", "go to the shown terminal with the whole screen; the leader
|
|
43
|
+
{ id: "zoom", keys: ["z"], label: "zoom", views: [["instances", "go to the shown terminal with the whole screen; the leader then Esc brings the list back"]] },
|
|
36
44
|
{ id: "close-terminal", keys: ["c"], label: "close terminal", views: [["instances", "close the shown terminal and show its neighbour; the agent keeps running"]] },
|
|
37
45
|
{ id: "tab-previous", keys: ["["], label: "previous tab", views: [["instances", "show the terminal of the tab before the shown one"]] },
|
|
38
46
|
{ id: "tab-next", keys: ["]"], label: "next tab", views: [["instances", "show the terminal of the tab after the shown one"]] },
|
|
@@ -67,8 +75,10 @@ export const ACTIONS = Object.freeze([
|
|
|
67
75
|
* open.detachKey) and what each does, from every focus. Fixed: tui.json's `keys` rebinds the plain
|
|
68
76
|
* keys of ACTIONS only. `does` is an action id of ACTIONS, or one of the leader's own: `previous`
|
|
69
77
|
* and `next` (the instance before or after the shown terminal's, or the selection's: its tab
|
|
70
|
-
* shown, or opened as a new one, with the focus in it) and `list` (the list's focus
|
|
71
|
-
*
|
|
78
|
+
* shown, or opened as a new one, with the focus in it) and `list` (the list's focus, which
|
|
79
|
+
* Esc gives). The leader pressed again is not in this table either, as it is the user's key: from
|
|
80
|
+
* the open terminal's focus it types the leader's own bytes into the agent, the focus staying
|
|
81
|
+
* there, and from any other focus it only closes the hint (lib/store.mjs `twice`). `terminal`: named in the hint only while a terminal
|
|
72
82
|
* is open, and nothing without one (the hint names the tab keys only with two tabs or more). */
|
|
73
83
|
export const LEADER = Object.freeze([
|
|
74
84
|
{ keys: ["k", "space"], does: "palette", label: "palette" },
|
|
@@ -118,3 +128,17 @@ export function keyLabel(key) {
|
|
|
118
128
|
const name = NAMES[last] ?? (/^f\d+$/.test(last) ? last.toUpperCase() : parts.length && last.length === 1 ? last.toUpperCase() : last);
|
|
119
129
|
return [...parts.map((part) => NAMES[part] ?? part), name].join("+");
|
|
120
130
|
}
|
|
131
|
+
|
|
132
|
+
/** The modifiers of the back key's grammar (term/through.mjs BACK_KEY) as a person reads them. */
|
|
133
|
+
const BACK_MODIFIERS = Object.freeze({ C: "Ctrl", M: "Alt", S: "Shift" });
|
|
134
|
+
/** A back key (tui.json's open.detachKey, the leader) as the cheat sheet and the help name it, spelt
|
|
135
|
+
* for people as keyLabel spells a key id: `C-\\` is `Ctrl+\\`, `C-x` is `Ctrl+X`, `M-o` is `Alt+O`,
|
|
136
|
+
* `M-5` is `Alt+5`, `F12` is `F12`, `S-F5` is `Shift+F5`. A letter is written as a capital, which
|
|
137
|
+
* never means Shift (the grammar has lowercase Meta letters only). Pure. A value outside the
|
|
138
|
+
* grammar is answered as it was given (tui.json refuses it; a view draws it as text from outside). */
|
|
139
|
+
export function backKeyLabel(key) {
|
|
140
|
+
if (!isBackKey(key)) return key;
|
|
141
|
+
const [, mod, rest] = /^(?:([CMS])-)?(.+)$/.exec(key);
|
|
142
|
+
const name = rest.length === 1 ? rest.toUpperCase() : rest;
|
|
143
|
+
return mod ? `${BACK_MODIFIERS[mod]}+${name}` : name;
|
|
144
|
+
}
|
|
@@ -9,6 +9,8 @@ import { clientTerms } from "../../client/client-terms.mjs";
|
|
|
9
9
|
export { displayLine, DETAIL_WITHHELD } from "../../client/display-text.mjs";
|
|
10
10
|
export { parseProbeStdout, acceptProbe, cliRecord } from "../../client/cli-locator.mjs";
|
|
11
11
|
export { cliDeploymentRead } from "../../client/deployment-read-cli.mjs";
|
|
12
|
+
export { cliDeploymentList } from "../../client/deployment-list-cli.mjs";
|
|
13
|
+
export { deploymentsListSupported } from "../../client/deployment-list.mjs";
|
|
12
14
|
export { cliRemoteRoster } from "../../client/cli-adapter.mjs";
|
|
13
15
|
export { createDeploymentObserver, mapBounded, MAX_DEPLOYMENT_OBSERVATIONS } from "../../client/deployment-observer.mjs";
|
|
14
16
|
export { createRefreshLoop } from "../../client/refresh-loop.mjs";
|
|
@@ -33,7 +35,7 @@ export { createRetiresInFlight, retiringRows } from "../../client/retire-in-flig
|
|
|
33
35
|
export { startGate, startInstance } from "../../client/session-start.mjs";
|
|
34
36
|
export { retainedStartMessage, launchFlagIgnored, flagIgnoredNotice } from "../../client/launch-prompt-outcome.mjs";
|
|
35
37
|
export { INSTANCE_VARIABLES } from "../../client/kernel-environment.mjs";
|
|
36
|
-
export { validateWorkspace
|
|
38
|
+
export { validateWorkspace } from "../../client/workspace-admission.mjs";
|
|
37
39
|
export { createSoulCatalog, soulCatalogKey } from "../../client/soul-catalog.mjs";
|
|
38
40
|
export { soulRows } from "../../client/soul-rows.mjs";
|
|
39
41
|
export { soulFacts, spawnRefusal, soulMatches } from "../../client/soul-facts.mjs";
|
|
@@ -19,9 +19,12 @@ export const CONFIG_LIMIT = 64 * 1024;
|
|
|
19
19
|
const TOO_LARGE = `it is larger than ${CONFIG_LIMIT / 1024} KiB`;
|
|
20
20
|
const NOT_AN_OBJECT = 'it is not one JSON object, like {"keys": {"quit": ["q"]}}';
|
|
21
21
|
const SETTINGS = "the settings are keys, ascii and open";
|
|
22
|
-
/** The back key when tui.json names none
|
|
23
|
-
* back to the list (the setting keeps its
|
|
24
|
-
|
|
22
|
+
/** The back key when tui.json names none, on `platform` (a `process.platform` value): the key that
|
|
23
|
+
* takes the focus from an agent's terminal back to the list, the leader (the setting keeps its
|
|
24
|
+
* name, `open.detachKey`, from when it left a viewer). `C-\\` on macOS, whose terminals send
|
|
25
|
+
* Option as Meta only when told to; `M-o` (Alt+O) elsewhere. Both are read as keys no action of
|
|
26
|
+
* ACTIONS holds (`ctrl+\\`, `alt+o`), which the check of the leader below keeps true. */
|
|
27
|
+
export const defaultDetachKey = (platform = process.platform) => (platform === "darwin" ? "C-\\" : "M-o");
|
|
25
28
|
/** An action id this program had and has no more, with what it is called now. */
|
|
26
29
|
const RENAMED = Object.freeze({ "open-workspace": "open" });
|
|
27
30
|
const KEY_IDS = "key ids look like q, ctrl+c, shift+tab, f5, space";
|
|
@@ -33,7 +36,7 @@ const ERROR_CODE = /^[A-Z][A-Z0-9_]{0,30}$/;
|
|
|
33
36
|
export const MAX_PROBLEMS = 20;
|
|
34
37
|
|
|
35
38
|
const plain = (name) => typeof name === "string" && PLAIN_NAME.test(name);
|
|
36
|
-
/** Whether the
|
|
39
|
+
/** Whether the cheat sheet and the help can name a key: its label is drawn as text from outside (the
|
|
37
40
|
* shared display filter), and a label that filter would change would name another key, or none.
|
|
38
41
|
* Such a key (a bidi override, a combining mark on a space) is refused here, with the file named,
|
|
39
42
|
* where a key the views cannot draw would otherwise be bound and never said. */
|
|
@@ -49,9 +52,10 @@ export function configPath(env, home) {
|
|
|
49
52
|
return join(typeof xdg === "string" && xdg !== "" && isAbsolute(xdg) ? xdg : join(home, ".config"), "oats", "tui.json");
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
/** What tui.json says, checked: `value` is the file already parsed, `defaults` the action table
|
|
53
|
-
*
|
|
54
|
-
* `detachKey`
|
|
55
|
+
/** What tui.json says, checked: `value` is the file already parsed, `defaults` the action table,
|
|
56
|
+
* `platform` the one the TUI runs on (a `process.platform` value). Pure. Answers
|
|
57
|
+
* `{ ok: true, actions, ascii, detachKey }` or `{ ok: false, problems }`: `detachKey` is
|
|
58
|
+
* `open.detachKey`, or defaultDetachKey(platform) when the file names none.
|
|
55
59
|
*
|
|
56
60
|
* `actions` is a frozen table shaped exactly like `defaults` (same order, ids and labels, frozen
|
|
57
61
|
* rows with frozen `keys`) in which the list of each action the file names REPLACES that action's
|
|
@@ -63,7 +67,7 @@ export function configPath(env, home) {
|
|
|
63
67
|
* order. A key given to two actions is judged with the kept defaults included and names both. An
|
|
64
68
|
* action whose list is refused takes no part in that judgement: what it was meant to hold is not
|
|
65
69
|
* known. The ids of `defaults` are the program's own; one that is not plain is still never echoed. */
|
|
66
|
-
export function effectiveConfig(value, defaults = ACTIONS) {
|
|
70
|
+
export function effectiveConfig(value, defaults = ACTIONS, platform = process.platform) {
|
|
67
71
|
if (!isObject(value)) return { ok: false, problems: [NOT_AN_OBJECT] };
|
|
68
72
|
for (const [setting, given] of Object.entries(value)) {
|
|
69
73
|
if (setting === "keys") { if (!isObject(given)) return { ok: false, problems: ['keys must be an object, like {"quit": ["q"]}'] }; }
|
|
@@ -106,9 +110,11 @@ export function effectiveConfig(value, defaults = ACTIONS) {
|
|
|
106
110
|
}
|
|
107
111
|
// The leader is read as a key wherever the TUI reads keys (docs/tui.md, "The leader"), so no
|
|
108
112
|
// action may hold the key it reads as: `C-l` would be redraw's Ctrl+L, `C-j` open's Enter.
|
|
109
|
-
const detachKey = value.open?.detachKey ??
|
|
113
|
+
const detachKey = value.open?.detachKey ?? defaultDetachKey(platform), leader = backKeyId(detachKey);
|
|
110
114
|
const taken = defaults.find((action) => (named.get(action.id) ?? action.keys).includes(leader));
|
|
111
|
-
|
|
115
|
+
// A file that names no leader is told it is the default, which it did not write.
|
|
116
|
+
const which = value.open?.detachKey === undefined ? `the default leader ${detachKey}` : `open.detachKey ${detachKey}`;
|
|
117
|
+
if (taken) problems.push(`${which} is read as ${keyLabel(leader)}, the key of ${say(taken.id)}; give the leader a key no action has, or give ${say(taken.id)} another`);
|
|
112
118
|
if (problems.length > 0) return { ok: false, problems };
|
|
113
119
|
|
|
114
120
|
const actions = Object.freeze(defaults.map((action) => Object.freeze({ ...action, keys: Object.freeze([...(named.get(action.id) ?? action.keys)]) })));
|
|
@@ -158,24 +164,25 @@ const NODE_IO = Object.freeze({
|
|
|
158
164
|
/** Read tui.json, once. Answers `{ ok: true, actions, ascii, detachKey, path }`, or
|
|
159
165
|
* `{ ok: false, lines }`: the complete lines to print (no trailing newline), after which the TUI
|
|
160
166
|
* must not start. No file is the defaults: `actions` is ACTIONS itself, `ascii` is false and
|
|
161
|
-
* `detachKey` is
|
|
167
|
+
* `detachKey` is defaultDetachKey(platform); `platform` is the one the TUI runs on (a
|
|
168
|
+
* `process.platform` value, given so the answer is known for each).
|
|
162
169
|
*
|
|
163
170
|
* `io` is the file system (node:fs when omitted): `io.stat(path)` answers `{ file, size }` after
|
|
164
171
|
* following symbolic links, or null when the path does not exist, and throws for anything else;
|
|
165
172
|
* `io.read(path)` answers the text. The size is checked before `read` is called, so a file over
|
|
166
173
|
* CONFIG_LIMIT, a directory or a FIFO is never opened. A line holds the path only when it is
|
|
167
174
|
* printable ASCII, and never the text of an error: only its code, when it is a plain one. */
|
|
168
|
-
export function loadConfig({ env = process.env, home = homedir(), io = NODE_IO } = {}) {
|
|
175
|
+
export function loadConfig({ env = process.env, home = homedir(), io = NODE_IO, platform = process.platform } = {}) {
|
|
169
176
|
const path = configPath(env, home);
|
|
170
177
|
const listed = (problems) => (problems.length > MAX_PROBLEMS ? [...problems.slice(0, MAX_PROBLEMS), problems.length - MAX_PROBLEMS === 1 ? "1 more problem is not listed" : `${problems.length - MAX_PROBLEMS} more problems are not listed`] : problems);
|
|
171
178
|
const refused = (problems) => ({ ok: false, lines: listed(problems).map((problem) => `oats: \`oats tui\` cannot use ${PLAIN_PATH.test(path) ? path : "its configuration file"}: ${problem} (E_TUI_CONFIG)`) });
|
|
172
179
|
let found, text, value;
|
|
173
180
|
try { found = io.stat(path); } catch (error) { return refused([unreadable(error)]); }
|
|
174
|
-
if (found === null) return { ok: true, actions: ACTIONS, ascii: false, detachKey:
|
|
181
|
+
if (found === null) return { ok: true, actions: ACTIONS, ascii: false, detachKey: defaultDetachKey(platform), path };
|
|
175
182
|
if (found.file !== true) return refused(["it is not a regular file"]);
|
|
176
183
|
if (!(typeof found.size === "number" && found.size <= CONFIG_LIMIT)) return refused([TOO_LARGE]); // read only what is known to fit
|
|
177
184
|
try { text = io.read(path); } catch (error) { return refused([error?.code === "EFBIG" ? TOO_LARGE : unreadable(error)]); }
|
|
178
185
|
try { value = JSON.parse(text); } catch { return refused(["it is not valid JSON"]); }
|
|
179
|
-
const checked = effectiveConfig(value);
|
|
186
|
+
const checked = effectiveConfig(value, ACTIONS, platform);
|
|
180
187
|
return checked.ok ? { ...checked, path } : refused(checked.problems);
|
|
181
188
|
}
|