@awebai/oats 0.64.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/bin/oats.mjs +109 -11
- package/docs/desktop-cli-api.md +88 -5
- package/docs/desktop.md +14 -5
- package/docs/implementation.md +26 -3
- package/docs/integrations.md +1 -1
- package/docs/official-catalog.md +2 -2
- package/docs/packages.md +7 -7
- package/docs/release-notes/v0.65.0.md +187 -0
- package/docs/release-notes/v0.66.0.md +183 -0
- package/docs/servers.md +2 -2
- package/docs/tui.md +548 -249
- package/docs/upgrading.md +1 -1
- package/docs/workspaces.md +132 -1
- package/lib/core.mjs +14 -4
- package/lib/deployments.mjs +341 -0
- package/lib/resolved-deployment.mjs +37 -0
- package/lib/workspace.mjs +2 -0
- package/package-catalog.json +2 -2
- 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 +133 -0
- package/packages/client/machine-contract.mjs +1 -5
- 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/record/bin/setup.mjs +10 -2
- package/packages/record/docs/capture-service.md +45 -6
- package/packages/record/lib/capture-service-install.mjs +6 -95
- package/packages/record/lib/capture-setup-write.mjs +233 -0
- package/packages/tui/README.md +10 -9
- package/packages/tui/lib/actions.mjs +89 -64
- package/packages/tui/lib/client.mjs +4 -1
- package/packages/tui/lib/config.mjs +184 -36
- package/packages/tui/lib/main.mjs +161 -40
- package/packages/tui/lib/model.mjs +73 -41
- package/packages/tui/lib/read.mjs +15 -45
- package/packages/tui/lib/store.mjs +174 -40
- package/packages/tui/lib/term/keys.mjs +135 -33
- package/packages/tui/lib/term/kitty.mjs +198 -0
- package/packages/tui/lib/term/through.mjs +160 -24
- package/packages/tui/lib/term/tty.mjs +43 -12
- 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 +90 -29
- 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 +102 -32
|
@@ -23,7 +23,7 @@ export function shortPath(path, { home = null } = {}) {
|
|
|
23
23
|
return parts.length > 2 ? `…/${parts.slice(-2).join('/')}` : shown;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/** The two halves of a deployment's label: `{ machine, path }` ("This Mac", "~/
|
|
26
|
+
/** The two halves of a deployment's label: `{ machine, path }` ("This Mac", "~/acme"; path ''
|
|
27
27
|
* when none). Headings style them apart: a machine label may be uppercased, a path never. */
|
|
28
28
|
export function deploymentLabelParts(deployment, terms) {
|
|
29
29
|
requireTerms(terms, 'deploymentLabelParts');
|
|
@@ -32,7 +32,7 @@ export function deploymentLabelParts(deployment, terms) {
|
|
|
32
32
|
return { machine, path };
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** `This Mac · ~/
|
|
35
|
+
/** `This Mac · ~/acme`, `altair · ~/northwind`. */
|
|
36
36
|
export function deploymentLabel(deployment, terms) {
|
|
37
37
|
requireTerms(terms, 'deploymentLabel');
|
|
38
38
|
const { machine, path } = deploymentLabelParts(deployment, terms);
|
|
@@ -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,133 @@
|
|
|
1
|
+
/** The keys both clients share: the leader, the table read after it, the plain keys of the list
|
|
2
|
+
* of instances, and the chords. Written down once, here; the Desktop and the TUI read their defaults
|
|
3
|
+
* from it (packages/tui/lib/actions.mjs LEADER is LEADER_TABLE, and the TUI's test
|
|
4
|
+
* packages/tui/test/keymap.test.mjs fails on a `does` the TUI does not handle).
|
|
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+` / `shift+`
|
|
11
|
+
* prefixes, in that order. A chord adds two: `shift+` with Ctrl and a letter (`ctrl+shift+k`, which
|
|
12
|
+
* the TUI reads only under the kitty keyboard protocol), and `cmd+`, first, for macOS's Command
|
|
13
|
+
* (`cmd+k`, the Desktop's ⌘K), which a terminal never passes to a program.
|
|
14
|
+
*
|
|
15
|
+
* leaderKey(isMac) -> the leader's key id on that platform "ctrl+\\" / "alt+o"
|
|
16
|
+
* leaderDoes(key) -> what the leader then does for a key id, or null
|
|
17
|
+
* plainKeys(does) -> the plain key ids of an action (empty when it has none)
|
|
18
|
+
* leaderRows() -> LEADER_TABLE
|
|
19
|
+
* chordKey(does, isMac) -> the chord's key id on that platform, or null
|
|
20
|
+
*
|
|
21
|
+
* `does` names an action, not a client's code: each client maps it to its own. */
|
|
22
|
+
|
|
23
|
+
/** The leader per platform: Ctrl+\ on macOS, Alt+O elsewhere. */
|
|
24
|
+
export const LEADER = Object.freeze({ mac: "ctrl+\\", other: "alt+o" });
|
|
25
|
+
|
|
26
|
+
/** The keys read after the leader, in the TUI's order, and what each does. `terminal`: named in
|
|
27
|
+
* the hint only while a terminal is open. The leader pressed twice is not here: it is the user's
|
|
28
|
+
* key, and each client says what it does. */
|
|
29
|
+
export const LEADER_TABLE = Object.freeze([
|
|
30
|
+
{ keys: ["k", "space"], does: "palette", label: "palette" },
|
|
31
|
+
{ keys: ["1"], does: "instances", label: "instances" },
|
|
32
|
+
{ keys: ["2"], does: "souls", label: "souls" },
|
|
33
|
+
{ keys: ["3"], does: "capabilities", label: "capabilities" },
|
|
34
|
+
{ keys: ["up"], does: "previous", label: "previous instance" },
|
|
35
|
+
{ keys: ["down"], does: "next", label: "next instance" },
|
|
36
|
+
{ keys: ["z"], does: "zoom", label: "zoom", terminal: true },
|
|
37
|
+
{ keys: ["w"], does: "close-terminal", label: "close terminal", terminal: true },
|
|
38
|
+
{ keys: ["left"], does: "tab-previous", label: "previous tab", terminal: true },
|
|
39
|
+
{ keys: ["right"], does: "tab-next", label: "next tab", terminal: true },
|
|
40
|
+
{ keys: ["|"], does: "split-right", label: "split right", terminal: true },
|
|
41
|
+
{ keys: ["-"], does: "split-down", label: "split down", terminal: true },
|
|
42
|
+
{ keys: ["tab"], does: "group-next", label: "next group", terminal: true },
|
|
43
|
+
{ keys: ["m"], does: "tab-move", label: "move tab", terminal: true },
|
|
44
|
+
{ keys: ["x"], does: "group-close", label: "close group", terminal: true },
|
|
45
|
+
{ keys: ["X"], does: "stop", label: "stop" },
|
|
46
|
+
{ keys: ["R"], does: "restart", label: "restart" },
|
|
47
|
+
{ keys: ["S"], does: "start", label: "start" },
|
|
48
|
+
{ keys: ["D"], does: "retire", label: "retire" },
|
|
49
|
+
{ keys: ["n"], does: "spawn", label: "spawn" },
|
|
50
|
+
{ keys: ["N"], does: "spawn-another", label: "spawn another" },
|
|
51
|
+
{ keys: ["/"], does: "filter", label: "filter" },
|
|
52
|
+
{ keys: ["o"], does: "workspaces", label: "workspaces" },
|
|
53
|
+
{ keys: ["?"], does: "help", label: "help" },
|
|
54
|
+
{ keys: ["escape"], does: "list", label: "the list" },
|
|
55
|
+
].map((row) => Object.freeze({ ...row, keys: Object.freeze([...row.keys]) })));
|
|
56
|
+
|
|
57
|
+
/** The plain keys both clients read in the list of instances (the TUI's ACTIONS), one entry per action. */
|
|
58
|
+
export const PLAIN_KEYS = Object.freeze([
|
|
59
|
+
{ does: "up", keys: ["up", "k"] },
|
|
60
|
+
{ does: "down", keys: ["down", "j"] },
|
|
61
|
+
{ does: "top", keys: ["g", "home"] },
|
|
62
|
+
{ does: "bottom", keys: ["G", "end"] },
|
|
63
|
+
{ does: "page-up", keys: ["pageup"] },
|
|
64
|
+
{ does: "page-down", keys: ["pagedown"] },
|
|
65
|
+
{ does: "collapse", keys: ["left", "h"] },
|
|
66
|
+
{ does: "expand", keys: ["right", "l"] },
|
|
67
|
+
{ does: "filter", keys: ["/"] },
|
|
68
|
+
{ does: "refresh", keys: ["r"] },
|
|
69
|
+
{ does: "instances", keys: ["1"] },
|
|
70
|
+
{ does: "souls", keys: ["2"] },
|
|
71
|
+
{ does: "capabilities", keys: ["3"] },
|
|
72
|
+
{ does: "workspaces", keys: ["w"] },
|
|
73
|
+
{ does: "open", keys: ["enter"] },
|
|
74
|
+
{ does: "zoom", keys: ["z"] },
|
|
75
|
+
{ does: "close-terminal", keys: ["c"] },
|
|
76
|
+
{ does: "tab-previous", keys: ["["] },
|
|
77
|
+
{ does: "tab-next", keys: ["]"] },
|
|
78
|
+
{ does: "split-right", keys: ["|"] },
|
|
79
|
+
{ does: "split-down", keys: ["-"] },
|
|
80
|
+
{ does: "stop", keys: ["X"] },
|
|
81
|
+
{ does: "retire", keys: ["D"] },
|
|
82
|
+
{ does: "start", keys: ["S"] },
|
|
83
|
+
{ does: "restart", keys: ["R"] },
|
|
84
|
+
{ does: "spawn", keys: ["n"] },
|
|
85
|
+
{ does: "spawn-another", keys: ["N"] },
|
|
86
|
+
{ does: "help", keys: ["?"] },
|
|
87
|
+
].map((entry) => Object.freeze({ ...entry, keys: Object.freeze([...entry.keys]) })));
|
|
88
|
+
|
|
89
|
+
/** The chords: one key that does what the leader then a key does, the Desktop's direct chords whose
|
|
90
|
+
* action the TUI has too, per platform (`mac`, `other`). The Desktop's DEFAULT_KEYMAP reads these
|
|
91
|
+
* entries from here (docs/desktop-keyboard.md). The TUI takes the `other` ones, and the `mac` ones
|
|
92
|
+
* without `cmd+`, while the terminal confirms the kitty keyboard protocol (docs/tui.md, "Chords"),
|
|
93
|
+
* as extras: the leader stays the key that always works. The Desktop's Ctrl+1/2/3 (the stages) are
|
|
94
|
+
* the Desktop's own and are not here. */
|
|
95
|
+
export const CHORDS = Object.freeze([
|
|
96
|
+
{ does: "palette", mac: "cmd+k", other: "ctrl+shift+k" },
|
|
97
|
+
{ does: "spawn", mac: "cmd+p", other: "ctrl+shift+p" },
|
|
98
|
+
{ does: "tab-next", mac: "ctrl+tab", other: "ctrl+tab" },
|
|
99
|
+
{ does: "tab-previous", mac: "ctrl+shift+tab", other: "ctrl+shift+tab" },
|
|
100
|
+
{ does: "close-terminal", mac: "cmd+w", other: "ctrl+shift+w" },
|
|
101
|
+
{ does: "filter", mac: "cmd+f", other: "ctrl+shift+f" },
|
|
102
|
+
{ does: "split-right", mac: "cmd+\\", other: "ctrl+shift+e" },
|
|
103
|
+
{ does: "split-down", mac: "cmd+shift+\\", other: "ctrl+shift+o" },
|
|
104
|
+
].map((entry) => Object.freeze({ ...entry })));
|
|
105
|
+
|
|
106
|
+
const NONE = Object.freeze([]);
|
|
107
|
+
|
|
108
|
+
/** The leader's key id on macOS (`true`) or elsewhere. */
|
|
109
|
+
export function leaderKey(isMac) {
|
|
110
|
+
return isMac ? LEADER.mac : LEADER.other;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What the leader then does for `keyId`, or null when the table has no such key. */
|
|
114
|
+
export function leaderDoes(keyId) {
|
|
115
|
+
for (const row of LEADER_TABLE) if (row.keys.includes(keyId)) return row.does;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The plain key ids of the action `does`, frozen; empty when it has none. */
|
|
120
|
+
export function plainKeys(does) {
|
|
121
|
+
return PLAIN_KEYS.find((entry) => entry.does === does)?.keys ?? NONE;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The leader's table, LEADER_TABLE itself. */
|
|
125
|
+
export function leaderRows() {
|
|
126
|
+
return LEADER_TABLE;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The key id of the chord that does `does` on macOS (`true`) or elsewhere, or null when none does. */
|
|
130
|
+
export function chordKey(does, isMac) {
|
|
131
|
+
const entry = CHORDS.find((each) => each.does === does);
|
|
132
|
+
return entry === undefined ? null : isMac ? entry.mac : entry.other;
|
|
133
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* oats desktop — a workspace's own machines (#517): the gates, the Add a machine
|
|
1
|
+
/* oats desktop — a workspace's own machines (#517): the gates, the Add a machine Name default and field
|
|
2
2
|
rules, and the step rows of `oats server connect --json` and `oats aweb connect --json` as the CLI
|
|
3
3
|
sends them (docs/desktop-cli-api.md; interface §2 and §4).
|
|
4
4
|
|
|
@@ -37,10 +37,6 @@ export function machineName(host, deploymentDir) {
|
|
|
37
37
|
return `${host}-${basename(deploymentDir)}`.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/-{2,}/g, '-')
|
|
38
38
|
.replace(/^-+/, '').slice(0, 64).replace(/-+$/, '');
|
|
39
39
|
}
|
|
40
|
-
/** The default Folder on that machine: `~/Agents/<this deployment dir basename>`. */
|
|
41
|
-
export function machineFolder(deploymentDir) {
|
|
42
|
-
return `~/Agents/${basename(deploymentDir)}`;
|
|
43
|
-
}
|
|
44
40
|
|
|
45
41
|
/** The first field that the kernel would refuse, as `{ field, text }`, or null. */
|
|
46
42
|
export function machineFieldProblem({ id, host, folder }) {
|
|
@@ -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
|
|
@@ -31,7 +31,8 @@ import { captureDefaultRootPlan } from "../lib/capture-default-roots.mjs";
|
|
|
31
31
|
import { captureCommandPass } from "../lib/capture-command-output.mjs";
|
|
32
32
|
import { captureCommandEntry } from "../lib/capture-command.mjs";
|
|
33
33
|
import { IgnoreError, loadIgnore } from "../lib/ignore.mjs";
|
|
34
|
-
import { preflightCaptureService, applyCaptureService
|
|
34
|
+
import { preflightCaptureService, applyCaptureService } from "../lib/capture-service-install.mjs";
|
|
35
|
+
import { captureSetupSnapshot, recheckCaptureSetup, writeCaptureSetup } from "../lib/capture-setup-write.mjs";
|
|
35
36
|
import { captureRemedyCommand } from "../lib/capture-health.mjs";
|
|
36
37
|
|
|
37
38
|
// The node written into what outlives this process: the hooks and the
|
|
@@ -243,7 +244,14 @@ try {
|
|
|
243
244
|
for (const { snapshot, contents } of hooks) {
|
|
244
245
|
if (!contents) console.log(`hooks: ${snapshot.path} already installed`);
|
|
245
246
|
else if (dry) console.log(`hooks: would install Stop+SessionEnd capture in ${snapshot.path}`);
|
|
246
|
-
else {
|
|
247
|
+
else {
|
|
248
|
+
try { writeCaptureSetup(snapshot, contents, createdParents); }
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error.published) summary.hooks.push(`${snapshot.path} (publication may have occurred at ${oneLine(error.stage)}; durability was not established)`);
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
summary.hooks.push(snapshot.path); console.log(`hooks: installed Stop+SessionEnd capture in ${snapshot.path}`);
|
|
254
|
+
}
|
|
247
255
|
}
|
|
248
256
|
if (dry) console.log("dry run: no first capture pass");
|
|
249
257
|
else {
|
|
@@ -1533,8 +1533,11 @@ the first pass still uses the running Node. These are user-manager definitions,
|
|
|
1533
1533
|
not deployment automation timers. No external wrapper is removed.
|
|
1534
1534
|
|
|
1535
1535
|
The setup coordinator prepares hook edits in memory, then
|
|
1536
|
-
`capture-service-install.mjs`
|
|
1537
|
-
applicable manager state before any
|
|
1536
|
+
`capture-service-install.mjs` uses `capture-setup-write.mjs` to snapshot every
|
|
1537
|
+
named service target and inspects applicable manager state before any
|
|
1538
|
+
service/file/hook/capture mutation. The shared module owns checked setup
|
|
1539
|
+
publication independently of manager policy; the service module retains its
|
|
1540
|
+
snapshot/recheck/write exports for existing callers.
|
|
1538
1541
|
Snapshots retain regular-file bytes and identity or the symlink's own identity
|
|
1539
1542
|
and target, plus ancestor identities and explicit missing-ancestor records. Reads are limited to 1 MiB per target;
|
|
1540
1543
|
unknown reads, nonregular targets and unsupported manager output refuse.
|
|
@@ -1574,6 +1577,11 @@ Apply rechecks file/ancestor identities and manager ownership/enablement.
|
|
|
1574
1577
|
Replaced bytes or symlinks are saved nonoverwriting in a reported datable
|
|
1575
1578
|
`<root>/service-backups/<date>-<unique-id>/` directory. Symlink backups
|
|
1576
1579
|
preserve the link instead of reading or removing an external wrapper target.
|
|
1580
|
+
Backup bytes and directory/symlink entries are not fsynced and cannot be relied
|
|
1581
|
+
on as power-loss-safe recovery. Durability of a replacement does not establish
|
|
1582
|
+
backup durability; this is tracked separately in
|
|
1583
|
+
[backup durability follow-up #1410](https://github.com/awebai/oats/issues/1410).
|
|
1584
|
+
|
|
1577
1585
|
An ancestor absent at preflight must remain absent until this apply creates it.
|
|
1578
1586
|
Creation proceeds one directory at a time without recursive adoption of an
|
|
1579
1587
|
existing path; each created non-link directory's identity is retained in a
|
|
@@ -1581,9 +1589,35 @@ per-apply map shared by subsequent service and hook writes. Newly introduced
|
|
|
1581
1589
|
directories or links are not accepted as extra ancestry. Existing ancestor
|
|
1582
1590
|
identities and observed symlink targets remain binding. The extra metadata
|
|
1583
1591
|
checks and directory creation do not establish an atomic filesystem operation.
|
|
1584
|
-
Each
|
|
1585
|
-
|
|
1586
|
-
|
|
1592
|
+
Each setup hook, service definition and pending-marker write uses the same
|
|
1593
|
+
checked publisher. It creates an exclusive 0600 temporary file, checks its
|
|
1594
|
+
open descriptor against the pathname, writes the complete contents and fsyncs
|
|
1595
|
+
the file before rename. After rechecking the saved target, temporary file and
|
|
1596
|
+
ancestors, it renames and fsyncs the containing directory through a checked
|
|
1597
|
+
directory descriptor. Newly created ancestor entries are synced in their
|
|
1598
|
+
containing directories, from the first missing parent toward the target,
|
|
1599
|
+
before creating the next child. A directory whose entry sync/open/close failed
|
|
1600
|
+
is not authorized for reuse by a subsequent write through the per-apply map.
|
|
1601
|
+
Required directory fsync failures, including an unsupported operation, refuse;
|
|
1602
|
+
there is no fallback that reports durability without the required sync.
|
|
1603
|
+
|
|
1604
|
+
A failure reports the target and stage, retains the primary cause and any
|
|
1605
|
+
scratch/descriptor cleanup failure, and exits nonzero. Before publication,
|
|
1606
|
+
the writer preserves the old target and removes only scratch whose saved
|
|
1607
|
+
identity and unchanged ancestry still prove ownership. Changed ancestry or a
|
|
1608
|
+
substituted temporary file revokes pathname cleanup; an interrupted/refused
|
|
1609
|
+
write can leave its original temporary file. After rename, a failed sync,
|
|
1610
|
+
close or identity recheck reports that publication may have occurred and
|
|
1611
|
+
durability was not established. It neither unlinks the new target nor claims
|
|
1612
|
+
rollback. A refused rename whose original target cannot be re-established is
|
|
1613
|
+
reported with the same uncertainty.
|
|
1614
|
+
|
|
1615
|
+
These are ordered filesystem durability operations, subject to the filesystem
|
|
1616
|
+
and storage device honoring fsync. Recording and injected I/O-fault fixtures
|
|
1617
|
+
check process-visible bytes, identities, permissions, failures and ordering;
|
|
1618
|
+
they do not reproduce or prove survival of a physical power loss. This setup
|
|
1619
|
+
publisher does not change ordinary capture transaction sync policy or the
|
|
1620
|
+
pending marker's activation/removal lifecycle.
|
|
1587
1621
|
An expected manager unmask can remove only the saved named `/dev/null` link;
|
|
1588
1622
|
other observed replacements refuse. These checks detect observed races, not
|
|
1589
1623
|
an OS-wide atomic transaction over files and managers.
|
|
@@ -1654,7 +1688,12 @@ never as "nothing happened". After a service failure, `service changed` lines
|
|
|
1654
1688
|
name, in order, what the failed apply had already changed: the replacement
|
|
1655
1689
|
backup directory, each manager action completed (units stopped, disabled or
|
|
1656
1690
|
unmasked, a job booted out), each definition written, and the pending-activation
|
|
1657
|
-
marker written or a stale one removed.
|
|
1691
|
+
marker written or a stale one removed. A failed publication also retains any
|
|
1692
|
+
created-parent evidence and names a possibly published target and its failed
|
|
1693
|
+
stage in these lines. A hook published before a later durability failure is
|
|
1694
|
+
listed under `hooks written` with the same uncertainty and stage, rather than
|
|
1695
|
+
reported as `none`. These annotations describe possible changes, not successful
|
|
1696
|
+
durability or rollback. Setup has no `--json` mode.
|
|
1658
1697
|
|
|
1659
1698
|
Fake-manager and isolated CLI fixtures exercise this ordering and refusal
|
|
1660
1699
|
contract. Real-manager cases live in `test/capture-service-real-darwin.test.mjs`
|
|
@@ -8,99 +8,10 @@ import { basename, dirname, isAbsolute, join } from "node:path";
|
|
|
8
8
|
import { CAPTURE_POLICY } from "./capture-budget.mjs";
|
|
9
9
|
import { capturePendingActivationName, captureServiceDefinition, captureServiceLabel, captureServiceUnit, captureServiceTimer } from "./capture-service-definition.mjs";
|
|
10
10
|
import { captureServiceOwnership, captureServiceArgvOwnership } from "./capture-service-ownership.mjs";
|
|
11
|
+
import { captureSetupSnapshot, recheckCaptureSetup, recheckCaptureSetupParents, writeCaptureSetup } from "./capture-setup-write.mjs";
|
|
12
|
+
export { captureSetupSnapshot, recheckCaptureSetup, writeCaptureSetup } from "./capture-setup-write.mjs";
|
|
11
13
|
|
|
12
14
|
export const serviceShellWord = value => /^[A-Za-z0-9_./:@%+,-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
|
|
13
|
-
const identity = stat => [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
|
|
14
|
-
function parents(path) {
|
|
15
|
-
const records = [];
|
|
16
|
-
for (let directory = dirname(path); ; directory = dirname(directory)) {
|
|
17
|
-
let stat;
|
|
18
|
-
try { stat = fs.lstatSync(directory); }
|
|
19
|
-
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
20
|
-
if (stat) {
|
|
21
|
-
let target = null;
|
|
22
|
-
if (stat.isSymbolicLink()) {
|
|
23
|
-
try { target = fs.statSync(directory); }
|
|
24
|
-
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
25
|
-
}
|
|
26
|
-
// Even a dangling ancestor link has an identity to retain. Its missing
|
|
27
|
-
// target must not turn a later retargeting into ordinary directory creation.
|
|
28
|
-
records.push([directory, `${stat.dev}:${stat.ino}:${stat.mode}`, stat.isSymbolicLink() ? fs.readlinkSync(directory) : null,
|
|
29
|
-
target ? `${target.dev}:${target.ino}:${target.mode}` : null]);
|
|
30
|
-
} else records.push([directory, null, null, null]);
|
|
31
|
-
if (dirname(directory) === directory) return records;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function captureSetupSnapshot(path) {
|
|
36
|
-
const ancestry = parents(path);
|
|
37
|
-
let stat;
|
|
38
|
-
try { stat = fs.lstatSync(path); }
|
|
39
|
-
catch (error) { if (error.code === "ENOENT") return { path, kind: "absent", parents: ancestry }; throw error; }
|
|
40
|
-
const before = identity(stat);
|
|
41
|
-
let bytes, link;
|
|
42
|
-
if (stat.isSymbolicLink()) link = fs.readlinkSync(path);
|
|
43
|
-
else {
|
|
44
|
-
if (!stat.isFile() || stat.size > 1024 * 1024) throw new Error(`refusing nonregular or oversized setup target ${path}`);
|
|
45
|
-
const fd = fs.openSync(path, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
46
|
-
try {
|
|
47
|
-
if (identity(fs.fstatSync(fd)) !== before) throw new Error(`setup target changed while opening ${path}`);
|
|
48
|
-
bytes = fs.readFileSync(fd);
|
|
49
|
-
if (identity(fs.fstatSync(fd)) !== before) throw new Error(`setup target changed while reading ${path}`);
|
|
50
|
-
} finally { fs.closeSync(fd); }
|
|
51
|
-
}
|
|
52
|
-
if (identity(fs.lstatSync(path)) !== before) throw new Error(`setup target changed while reading ${path}`);
|
|
53
|
-
return { path, kind: link === undefined ? "file" : "link", identity: before, bytes, link, parents: ancestry };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function recheckParents(snapshot, current, createdParents = new Map()) {
|
|
57
|
-
if (snapshot.parents.some(record => {
|
|
58
|
-
const expected = record[1] === null ? createdParents.get(record[0]) ?? record : record;
|
|
59
|
-
return !current.parents.some(now => JSON.stringify(now) === JSON.stringify(expected));
|
|
60
|
-
}))
|
|
61
|
-
throw new Error(`setup target parent changed since preflight: ${snapshot.path}; re-run setup`);
|
|
62
|
-
}
|
|
63
|
-
export function recheckCaptureSetup(snapshot, createdParents = new Map()) {
|
|
64
|
-
recheckParents(snapshot, { parents: parents(snapshot.path) }, createdParents);
|
|
65
|
-
const current = captureSetupSnapshot(snapshot.path);
|
|
66
|
-
recheckParents(snapshot, current, createdParents);
|
|
67
|
-
if (current.kind !== snapshot.kind || current.identity !== snapshot.identity || current.link !== snapshot.link ||
|
|
68
|
-
(snapshot.bytes && !snapshot.bytes.equals(current.bytes))) throw new Error(`setup target changed since preflight: ${snapshot.path}; re-run setup`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function writeCaptureSetup(snapshot, contents, createdParents = new Map()) {
|
|
72
|
-
recheckCaptureSetup(snapshot, createdParents);
|
|
73
|
-
// A missing ancestor is evidence, not permission to follow whatever appears
|
|
74
|
-
// there later. Create one level at a time, refusing EEXIST, and share only
|
|
75
|
-
// this apply's observed non-link directory identities with subsequent writes.
|
|
76
|
-
for (const record of [...snapshot.parents].reverse()) {
|
|
77
|
-
if (record[1] !== null || createdParents.has(record[0])) continue;
|
|
78
|
-
recheckCaptureSetup(snapshot, createdParents);
|
|
79
|
-
fs.mkdirSync(record[0]);
|
|
80
|
-
const stat = fs.lstatSync(record[0]);
|
|
81
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`setup created parent changed: ${record[0]}; re-run setup`);
|
|
82
|
-
createdParents.set(record[0], [record[0], `${stat.dev}:${stat.ino}:${stat.mode}`, null, null]);
|
|
83
|
-
}
|
|
84
|
-
recheckCaptureSetup(snapshot, createdParents);
|
|
85
|
-
const temporary = `${snapshot.path}.tmp-${randomUUID()}`;
|
|
86
|
-
let temporaryIdentity;
|
|
87
|
-
try {
|
|
88
|
-
fs.writeFileSync(temporary, contents, { flag: "wx", mode: 0o600 });
|
|
89
|
-
temporaryIdentity = identity(fs.lstatSync(temporary));
|
|
90
|
-
recheckCaptureSetup(snapshot, createdParents);
|
|
91
|
-
fs.renameSync(temporary, snapshot.path);
|
|
92
|
-
} finally {
|
|
93
|
-
// A refused ancestor replacement also revokes cleanup through that path.
|
|
94
|
-
// Leave the original scratch file rather than unlink an unrelated target.
|
|
95
|
-
let safe = false;
|
|
96
|
-
try {
|
|
97
|
-
recheckParents(snapshot, { parents: parents(snapshot.path) }, createdParents);
|
|
98
|
-
safe = temporaryIdentity !== undefined && identity(fs.lstatSync(temporary)) === temporaryIdentity;
|
|
99
|
-
} catch { /* absent scratch or changed ancestry: no pathname cleanup */ }
|
|
100
|
-
if (safe) fs.unlinkSync(temporary);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
15
|
const detail = result => [result.error?.message, result.signal && `signal ${result.signal}`, result.stderr?.trim(),
|
|
105
16
|
result.status !== null && result.status !== undefined && `exit ${result.status}`].filter(Boolean).join("; ") || "no exit status returned";
|
|
106
17
|
const manager = (command, argv) => spawnSync(command, argv, { encoding: "utf8", timeout: 10000, maxBuffer: 1024 * 1024 });
|
|
@@ -249,7 +160,7 @@ export function preflightCaptureService({ platform, node, request, setupCommand,
|
|
|
249
160
|
export function applyCaptureService(plan, createdParents = new Map()) {
|
|
250
161
|
const applied = [];
|
|
251
162
|
try { return applyCaptureServiceSteps(plan, createdParents, applied); }
|
|
252
|
-
catch (error) { if (applied.length) error.applied = [...applied]; throw error; }
|
|
163
|
+
catch (error) { if (applied.length) error.applied = [...applied, ...(error.applied ?? [])]; throw error; }
|
|
253
164
|
}
|
|
254
165
|
|
|
255
166
|
function applyCaptureServiceSteps(plan, createdParents, applied) {
|
|
@@ -309,7 +220,7 @@ function applyCaptureServiceSteps(plan, createdParents, applied) {
|
|
|
309
220
|
if (plan.platform === "darwin") {
|
|
310
221
|
if (plan.changed && current.registered) command("launchctl", ["bootout", plan.target]);
|
|
311
222
|
for (const file of files) if (file.changed) writeDefinition(file);
|
|
312
|
-
|
|
223
|
+
recheckCaptureSetupParents(files[0].snapshot, createdParents);
|
|
313
224
|
fs.mkdirSync(join(plan.request.plan.home, "Library", "Logs"), { recursive: true });
|
|
314
225
|
if (plan.disabled) command("launchctl", ["enable", plan.target]);
|
|
315
226
|
if (plan.changed || !current.registered) command("launchctl", ["bootstrap", plan.domain, files[0].path]);
|
|
@@ -334,7 +245,7 @@ function applyCaptureServiceSteps(plan, createdParents, applied) {
|
|
|
334
245
|
for (const file of files) {
|
|
335
246
|
if (plan.disabled && file.snapshot.kind === "link" && file.snapshot.link === "/dev/null") {
|
|
336
247
|
const now = captureSetupSnapshot(file.path);
|
|
337
|
-
|
|
248
|
+
recheckCaptureSetupParents(file.snapshot, createdParents, now);
|
|
338
249
|
if (now.kind === "absent") file.snapshot = now;
|
|
339
250
|
}
|
|
340
251
|
if (file.changed) writeDefinition(file);
|
|
@@ -351,7 +262,7 @@ function applyCaptureServiceSteps(plan, createdParents, applied) {
|
|
|
351
262
|
}
|
|
352
263
|
for (const file of files) {
|
|
353
264
|
const final = captureSetupSnapshot(file.path);
|
|
354
|
-
|
|
265
|
+
recheckCaptureSetupParents(file.snapshot, createdParents, final);
|
|
355
266
|
if (final.kind !== "file" || !final.bytes.equals(Buffer.from(file.contents))) throw new Error(`capture definition changed during activation: ${file.path}; re-run setup`);
|
|
356
267
|
}
|
|
357
268
|
if (marked || plan.pending && !plan.pending.stale) {
|