@awebai/oats 0.51.0 → 0.53.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 +3 -1
- package/bin/oats.mjs +407 -123
- package/docs/capabilities.md +75 -6
- package/docs/configuration.md +200 -91
- package/docs/desktop-cli-api.md +1563 -113
- package/docs/desktop-instance-start.md +69 -0
- package/docs/desktop.md +10 -7
- package/docs/execution-targets.md +145 -58
- package/docs/first-team.md +3 -1
- package/docs/harness-trust.md +50 -2
- package/docs/implementation.md +238 -17
- package/docs/integrations.md +13 -9
- package/docs/knowledge-reference/acceptance.md +1 -0
- package/docs/knowledge-reference/harvester.md +5 -3
- package/docs/knowledge-reference/model.md +5 -3
- package/docs/knowledge-theory.md +1 -1
- package/docs/knowledge.md +25 -2
- package/docs/launch-prompt-completion.md +50 -48
- package/docs/macos-test-runs.md +246 -0
- package/docs/oats-local.schema.json +4 -3
- package/docs/official-catalog.md +5 -5
- package/docs/packages.md +14 -14
- package/docs/release-lane.md +225 -11
- package/docs/release-notes/v0.44.0.md +1 -1
- package/docs/release-notes/v0.52.0.md +933 -0
- package/docs/release-notes/v0.53.0.md +1274 -0
- package/docs/schedules.md +97 -4
- package/docs/souls-and-instances.md +332 -40
- package/docs/tui.md +584 -0
- package/docs/upgrading.md +298 -0
- package/docs/workspaces.md +3 -3
- package/lib/automations.mjs +22 -22
- package/lib/claim.mjs +278 -49
- package/lib/config-data.mjs +4 -1
- package/lib/core.mjs +1282 -289
- package/lib/errors.mjs +170 -0
- package/lib/harness-trust-write.mjs +68 -27
- package/lib/harness-trust.mjs +34 -16
- package/lib/instance-events.mjs +19 -1
- package/lib/instance-git.mjs +39 -3
- package/lib/instance-inspect.mjs +45 -17
- package/lib/instance-lifecycle.mjs +306 -57
- package/lib/instance-resolution.mjs +59 -6
- package/lib/launch-preference.mjs +236 -9
- package/lib/launch-prompt-completion.mjs +7 -43
- package/lib/launch-prompt-evidence.mjs +14 -7
- package/lib/launch-prompt-fixtures/README.md +86 -152
- package/lib/launch-prompt-fixtures/dev-channel-confirmation.json +50 -0
- package/lib/launch-prompt-fixtures.mjs +122 -109
- package/lib/launch-prompt-transport.mjs +2 -56
- package/lib/launch-prompts.mjs +102 -100
- package/lib/local-edit.mjs +118 -0
- package/lib/packages.mjs +13 -4
- package/lib/pi-bridge.mjs +308 -0
- package/lib/refused-text.mjs +11 -0
- package/lib/remote.mjs +190 -25
- package/lib/resolve.mjs +2 -1
- package/lib/retained-after-retire.mjs +2 -2
- package/lib/retire-output.mjs +12 -1
- package/lib/schedule-host.mjs +125 -22
- package/lib/schedule.mjs +73 -24
- package/lib/shell-word.mjs +13 -0
- package/lib/soul-launch-verbs.mjs +153 -0
- package/lib/stable-node.mjs +62 -0
- package/lib/system-tools.mjs +39 -0
- package/lib/teams-verbs.mjs +18 -46
- package/lib/tmux-server-scope.mjs +62 -0
- package/lib/triggers.mjs +4 -4
- package/lib/workspace.mjs +54 -30
- package/lib/worktree-hooks.mjs +98 -20
- package/lib/worktree.mjs +83 -24
- package/package-catalog.json +4 -4
- package/package.json +8 -2
- package/packages/client/attach-exit.mjs +25 -0
- package/packages/client/capability-show-contract.mjs +230 -0
- package/packages/client/capability-warnings-contract.mjs +57 -0
- package/packages/client/cli-adapter.mjs +561 -0
- package/packages/client/cli-environment.mjs +53 -0
- package/packages/client/cli-locator.mjs +253 -0
- package/packages/client/cli-probe-contract.mjs +47 -0
- package/packages/client/client-terms.mjs +60 -0
- package/packages/client/deployment-contract.mjs +72 -0
- package/packages/client/deployment-data.mjs +483 -0
- package/packages/client/deployment-facts.mjs +95 -0
- package/packages/client/deployment-label.mjs +76 -0
- package/packages/client/deployment-observer.mjs +89 -0
- package/packages/client/deployment-panel.mjs +180 -0
- package/packages/client/deployment-read-cli.mjs +57 -0
- package/packages/client/display-text.mjs +50 -0
- package/packages/client/harness-names.mjs +30 -0
- package/packages/client/inspect-contract.mjs +62 -0
- package/packages/client/instance-acts.mjs +90 -0
- package/packages/client/instance-admission.mjs +45 -0
- package/packages/client/instance-events-contract.mjs +76 -0
- package/packages/client/instance-git-contract.mjs +80 -0
- package/packages/client/instance-presentation.mjs +86 -0
- package/packages/client/instance-tree.mjs +462 -0
- package/packages/client/kernel-environment.mjs +11 -0
- package/packages/client/kernel-lines.mjs +31 -0
- package/packages/client/kernel-made.mjs +23 -0
- package/packages/client/launch-contract.mjs +51 -0
- package/packages/client/launch-prompt-outcome.mjs +200 -0
- package/packages/client/lifecycle-cli.mjs +61 -0
- package/packages/client/lifecycle-contract.mjs +413 -0
- package/packages/client/liveness-main.mjs +10 -0
- package/packages/client/liveness.mjs +48 -0
- package/packages/client/machine-contract.mjs +123 -0
- package/packages/client/own-codes.mjs +31 -0
- package/packages/client/own-environment.mjs +22 -0
- package/packages/client/panel-views.mjs +293 -0
- package/packages/client/readiness-contract.mjs +174 -0
- package/packages/client/refresh-loop.mjs +52 -0
- package/packages/client/remote-address.mjs +151 -0
- package/packages/client/remote-identity-memory.mjs +94 -0
- package/packages/client/remote-roster.mjs +153 -0
- package/packages/client/roster-sections.mjs +80 -0
- package/packages/client/session-attach.mjs +175 -0
- package/packages/client/spawn-apply-cli.mjs +104 -0
- package/packages/client/spawn-apply-contract.mjs +195 -0
- package/packages/client/spawn-decision.mjs +46 -0
- package/packages/client/spawn-messages.mjs +142 -0
- package/packages/client/spawn-preview-cli.mjs +38 -0
- package/packages/client/spawn-preview-contract.mjs +318 -0
- package/packages/client/team-members.mjs +41 -0
- package/packages/client/team-rows.mjs +45 -0
- package/packages/client/terminal-contract.mjs +57 -0
- package/packages/client/terminal-exec.mjs +21 -0
- package/packages/client/tmux-status.mjs +66 -0
- package/packages/client/waiting-on-you.mjs +88 -0
- package/packages/client/workspace-admission.mjs +45 -0
- package/packages/client/workspace-choices.mjs +95 -0
- package/packages/client/workspace-cli.mjs +142 -0
- package/packages/client/workspace-views.mjs +183 -0
- package/packages/record/README.md +21 -0
- package/packages/record/bin/setup.mjs +108 -15
- package/packages/tui/README.md +64 -0
- package/packages/tui/bin/tui.mjs +7 -0
- package/packages/tui/lib/actions.mjs +44 -0
- package/packages/tui/lib/client.mjs +35 -0
- package/packages/tui/lib/config.mjs +151 -0
- package/packages/tui/lib/main.mjs +176 -0
- package/packages/tui/lib/model.mjs +392 -0
- package/packages/tui/lib/read.mjs +473 -0
- package/packages/tui/lib/store.mjs +364 -0
- package/packages/tui/lib/term/keys.mjs +367 -0
- package/packages/tui/lib/term/screen.mjs +134 -0
- package/packages/tui/lib/term/style.mjs +43 -0
- package/packages/tui/lib/term/text.mjs +109 -0
- package/packages/tui/lib/term/tty.mjs +178 -0
- package/packages/tui/lib/term/width.mjs +124 -0
- package/packages/tui/lib/views/detail.mjs +46 -0
- package/packages/tui/lib/views/frame.mjs +256 -0
- package/packages/tui/lib/views/help.mjs +140 -0
- package/packages/tui/lib/views/instances.mjs +137 -0
- package/packages/tui/lib/views/scroll.mjs +19 -0
- package/packages/tui/lib/views/switcher.mjs +97 -0
- package/packages/tui/package.json +8 -0
- package/skills/oats-getting-started/SKILL.md +30 -23
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-05-channel-seeded.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-06-first-after-channel.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-07-after-channel-200ms.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-08-installed-after-channel-200ms.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/manifest.json +0 -77
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/max-bypass-source.json +0 -88
- package/lib/launch-prompt-fixtures/structural-completion.json +0 -205
- package/lib/launch-prompt-policy.mjs +0 -87
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** How a deployment is named on screen: its machine and a short path (#482). Shared by the server,
|
|
2
|
+
* which labels every deployment of a workspace view, and the renderer, which shows the labels.
|
|
3
|
+
* A deployment that names no machine is on the machine the client runs on, and takes that machine's
|
|
4
|
+
* label from the client's terms (client-terms.mjs `thisMachine`: "This Mac"). */
|
|
5
|
+
import { requireTerms } from './client-terms.mjs';
|
|
6
|
+
|
|
7
|
+
const MAX_PATH = 40;
|
|
8
|
+
|
|
9
|
+
/** A path for display only: the home directory as `~` (this computer's own home for a local
|
|
10
|
+
* deployment; a remote host's `/Users/<name>` or `/home/<name>` prefix, which is only a display
|
|
11
|
+
* guess, since the host's home is never asked), and its last two segments when it is still long. */
|
|
12
|
+
export function shortPath(path, { home = null } = {}) {
|
|
13
|
+
if (typeof path !== 'string' || !path) return '';
|
|
14
|
+
let shown = path;
|
|
15
|
+
if (typeof home === 'string' && home.length > 1 && (path === home || path.startsWith(home.endsWith('/') ? home : `${home}/`))) {
|
|
16
|
+
shown = `~${path.slice(home.replace(/\/$/, '').length)}`;
|
|
17
|
+
} else if (home === null) {
|
|
18
|
+
const m = path.match(/^\/(?:Users|home)\/[^/]+(\/.*)?$/);
|
|
19
|
+
if (m) shown = `~${m[1] || ''}`;
|
|
20
|
+
}
|
|
21
|
+
if (shown.length <= MAX_PATH) return shown;
|
|
22
|
+
const parts = shown.split('/').filter(Boolean);
|
|
23
|
+
return parts.length > 2 ? `…/${parts.slice(-2).join('/')}` : shown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The two halves of a deployment's label: `{ machine, path }` ("This Mac", "~/Agents/oats"; path ''
|
|
27
|
+
* when none). Headings style them apart: a machine label may be uppercased, a path never. */
|
|
28
|
+
export function deploymentLabelParts(deployment, terms) {
|
|
29
|
+
requireTerms(terms, 'deploymentLabelParts');
|
|
30
|
+
const machine = typeof deployment?.machine === 'string' && deployment.machine ? deployment.machine : terms.thisMachine;
|
|
31
|
+
const path = typeof deployment?.label === 'string' && deployment.label ? deployment.label : '';
|
|
32
|
+
return { machine, path };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `This Mac · ~/Agents/oats`, `altair · ~/Agents/tsm`. */
|
|
36
|
+
export function deploymentLabel(deployment, terms) {
|
|
37
|
+
requireTerms(terms, 'deploymentLabel');
|
|
38
|
+
const { machine, path } = deploymentLabelParts(deployment, terms);
|
|
39
|
+
return path ? `${machine} · ${path}` : machine;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The last segment of a path ("/Users/juan/awebai/oats-v2" → "oats-v2"), or the last `n`. */
|
|
43
|
+
export function pathTail(path, n = 1) {
|
|
44
|
+
if (typeof path !== 'string' || !path) return '';
|
|
45
|
+
return path.split('/').filter(Boolean).slice(-n).join('/');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Each deployment's short name on screen (UI spec, #482): its machine ("This Mac", "altair"); when one
|
|
49
|
+
* machine holds two or more of the deployments, the machine and its path tail ("This Mac · oats-v2"),
|
|
50
|
+
* the last two segments when the tails collide. Never an id. Returns Map<deployment id, label>. */
|
|
51
|
+
export function machineLabels(deployments, terms) {
|
|
52
|
+
requireTerms(terms, 'machineLabels');
|
|
53
|
+
const out = new Map();
|
|
54
|
+
for (const [id, { machine, tail }] of machineLabelParts(deployments, terms)) out.set(id, tail ? `${machine} · ${tail}` : machine);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** machineLabels in two halves: Map<deployment id, { machine, tail }> (`tail` '' when the machine is
|
|
59
|
+
* enough). A heading uppercases the machine only; a path tail keeps its case. */
|
|
60
|
+
export function machineLabelParts(deployments, terms) {
|
|
61
|
+
requireTerms(terms, 'machineLabelParts');
|
|
62
|
+
const list = Array.isArray(deployments) ? deployments.filter(d => d && typeof d.id === 'string') : [];
|
|
63
|
+
const machineOf = d => (typeof d.machine === 'string' && d.machine) ? d.machine : terms.thisMachine;
|
|
64
|
+
const byMachine = new Map();
|
|
65
|
+
for (const d of list) byMachine.set(machineOf(d), [...(byMachine.get(machineOf(d)) || []), d]);
|
|
66
|
+
const out = new Map();
|
|
67
|
+
for (const [machine, same] of byMachine) {
|
|
68
|
+
if (same.length === 1) { out.set(same[0].id, { machine, tail: '' }); continue; }
|
|
69
|
+
const tails = same.map(d => pathTail(d.path));
|
|
70
|
+
same.forEach((d, i) => {
|
|
71
|
+
const tail = tails.filter(t => t === tails[i]).length > 1 ? pathTail(d.path, 2) : tails[i];
|
|
72
|
+
out.set(d.id, { machine, tail: tail || '' });
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Native deployment observations with bounded admission and both-outcome
|
|
2
|
+
* ownership. No cache, queued work, reader fallback or generation conversion. */
|
|
3
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
4
|
+
import { cliDeploymentRead } from './deployment-read-cli.mjs';
|
|
5
|
+
import { deploymentStatusData, workspaceStatusData, observationData } from './deployment-data.mjs';
|
|
6
|
+
import { deploymentReadGate, deploymentFailure, validMaxAge } from './deployment-contract.mjs';
|
|
7
|
+
export const MAX_DEPLOYMENT_OBSERVATIONS = 2; // each owns at most two CLI reads
|
|
8
|
+
|
|
9
|
+
/** Run `fn` over `items` with at most `limit` calls in flight, first come first served; results keep
|
|
10
|
+
* the input order. The observation cycle reads every registered deployment through this, bounded by
|
|
11
|
+
* the observer's own admission: starting them all in one tick left the third and later deployments
|
|
12
|
+
* E_DEPLOYMENT_BUSY on every cycle, never read and shown as "pending" forever (#461). A slow
|
|
13
|
+
* deployment holds one slot while the others go through the rest. */
|
|
14
|
+
export async function mapBounded(items, limit, fn) {
|
|
15
|
+
const results = new Array(items.length);
|
|
16
|
+
let next = 0;
|
|
17
|
+
const worker = async () => { while (next < items.length) { const index = next++; results[index] = await fn(items[index], index); } };
|
|
18
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker));
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
const absolute = value => typeof value === 'string' && !value.includes('\0') && isAbsolute(value) && resolve(value) === value;
|
|
22
|
+
|
|
23
|
+
/** getContext(id) is the owner's registry lookup, not renderer data. revision
|
|
24
|
+
* must change on CLI/registry invalidation. Pending revoked reads retain their
|
|
25
|
+
* slots until settlement; a new epoch cannot bypass the resource bound.
|
|
26
|
+
* `read` is a reader with `cliDeploymentRead`'s signature, `(cli, options)`, and its answer. A client
|
|
27
|
+
* that runs the kernel through its own `exec` passes one that closes over it:
|
|
28
|
+
* `read: (cli, options) => cliDeploymentRead(cli, options, { exec })`. Both reads of an observation
|
|
29
|
+
* go through it, and nothing else of the observer starts a process. */
|
|
30
|
+
export function createDeploymentObserver({ getContext, read = cliDeploymentRead }) {
|
|
31
|
+
const pending = new Map(); let active = 0, alive = true;
|
|
32
|
+
function admit(id) {
|
|
33
|
+
if (!alive) return deploymentFailure('E_DEPLOYMENT_STALE');
|
|
34
|
+
let value;
|
|
35
|
+
try { value = getContext(id); } catch { return deploymentFailure('E_BAD_ARGS'); }
|
|
36
|
+
if (!value || value.deployment !== id || !absolute(id) || !Number.isSafeInteger(value.revision) || value.revision < 0) return deploymentFailure('E_BAD_ARGS');
|
|
37
|
+
const gate = deploymentReadGate(value.cli, 'status');
|
|
38
|
+
if (gate) return gate;
|
|
39
|
+
const cli = { ok: value.cli.ok, bin: value.cli.bin, version: value.cli.version,
|
|
40
|
+
workspaceApi: value.cli.workspaceApi, features: [...value.cli.features] };
|
|
41
|
+
const stamp = JSON.stringify([id, value.revision, cli]);
|
|
42
|
+
return { ok: true, deployment: id, cli, stamp };
|
|
43
|
+
}
|
|
44
|
+
const current = captured => { const next = admit(captured.deployment); return next.ok && next.stamp === captured.stamp; };
|
|
45
|
+
/** `maxAge` (feature observe-max-age) rides on both reads; the adapter drops it for a kernel
|
|
46
|
+
* that does not declare the feature. Waiters coalesce on the stamp alone: a live (0) request
|
|
47
|
+
* that joins a background flight accepts that flight's observation rather than doubling it. */
|
|
48
|
+
function observe(id, { maxAge } = {}) {
|
|
49
|
+
const captured = admit(id);
|
|
50
|
+
if (!captured.ok) return Promise.resolve(captured);
|
|
51
|
+
if (!validMaxAge(maxAge)) return Promise.resolve(deploymentFailure('E_BAD_ARGS'));
|
|
52
|
+
let work = pending.get(captured.stamp);
|
|
53
|
+
if (!work) {
|
|
54
|
+
if (active >= MAX_DEPLOYMENT_OBSERVATIONS) return Promise.resolve(deploymentFailure('E_DEPLOYMENT_BUSY'));
|
|
55
|
+
active++; // reserve synchronously, before any dispatch/await
|
|
56
|
+
work = Promise.resolve().then(async () => {
|
|
57
|
+
if (!current(captured)) return deploymentFailure('E_DEPLOYMENT_STALE');
|
|
58
|
+
try {
|
|
59
|
+
const settled = await Promise.allSettled(['status', 'workspace-status'].map(action => Promise.resolve().then(() => {
|
|
60
|
+
if (!current(captured)) return deploymentFailure('E_DEPLOYMENT_STALE');
|
|
61
|
+
return read(captured.cli, { action, context: captured.deployment, ...(maxAge !== undefined ? { maxAge } : {}) });
|
|
62
|
+
})));
|
|
63
|
+
// Even a rejecting invoker keeps this reservation until its sibling
|
|
64
|
+
// read settles. Promise.all would release resources prematurely.
|
|
65
|
+
if (!current(captured)) return deploymentFailure('E_DEPLOYMENT_STALE');
|
|
66
|
+
if (settled.some(result => result.status === 'rejected')) return deploymentFailure('E_CLI_PROTOCOL');
|
|
67
|
+
const [status, header] = settled.map(result => result.value);
|
|
68
|
+
if (!status?.ok) return status || deploymentFailure('E_CLI_PROTOCOL');
|
|
69
|
+
if (!header?.ok) return header || deploymentFailure('E_CLI_PROTOCOL');
|
|
70
|
+
const workspaceStatus = workspaceStatusData(header.document, captured.deployment);
|
|
71
|
+
const roster = deploymentStatusData(status.document, captured.deployment);
|
|
72
|
+
// The observation's age is its OLDEST remote-head observation across both reads; a
|
|
73
|
+
// kernel that reports none observed live, so the completion time is the truth.
|
|
74
|
+
const stamps = [status, header].map(r => observationData(r.document).observedAt).filter(s => typeof s === 'string');
|
|
75
|
+
const observedAt = stamps.length ? stamps.sort()[0] : new Date().toISOString();
|
|
76
|
+
return { ok: true, deployment: captured.deployment, workspaceStatus, roster, observedAt };
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (!current(captured)) return deploymentFailure('E_DEPLOYMENT_STALE');
|
|
79
|
+
return deploymentFailure(error?.code === 'E_DEPLOYMENT_SCOPE' ? 'E_DEPLOYMENT_SCOPE' : 'E_CLI_PROTOCOL');
|
|
80
|
+
}
|
|
81
|
+
}).finally(() => { pending.delete(captured.stamp); active--; });
|
|
82
|
+
pending.set(captured.stamp, work);
|
|
83
|
+
}
|
|
84
|
+
// Each waiter owns its copy; a renderer/request cannot mutate another's
|
|
85
|
+
// observation or the retained private producer bytes.
|
|
86
|
+
return work.then(result => current(captured) ? structuredClone(result) : deploymentFailure('E_DEPLOYMENT_STALE'));
|
|
87
|
+
}
|
|
88
|
+
return { observe, dispose() { alive = false; } };
|
|
89
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/** What one deployment's observation becomes for a client's panel (#855, 1d): the kernel's roster as
|
|
2
|
+
* rows, the liveness collector's input and its answers, each row as the panel serves it, and the
|
|
3
|
+
* deployment's entry: before the first probe, after a failed read, and observed.
|
|
4
|
+
*
|
|
5
|
+
* Every function takes what it needs and returns a value. Nothing is kept between calls, and nothing
|
|
6
|
+
* here reads a clock, a file or a process: a client runs the collector itself (liveness-main.mjs, as a
|
|
7
|
+
* child, with its own environment and limits) and gives what it printed to `livenessAnswers`, and it
|
|
8
|
+
* passes the time of its call as `at`, an ISO string. Each client keeps its own store of entries.
|
|
9
|
+
*
|
|
10
|
+
* Not for a page: this module imports `node:path`. What a page shows of a deployment that is not
|
|
11
|
+
* observed is in deployment-facts.mjs (`deploymentUnavailableText`), and the Desktop's
|
|
12
|
+
* test/inventory.test.mjs holds that its page reaches no module that imports a Node builtin. */
|
|
13
|
+
import { dirname } from 'node:path';
|
|
14
|
+
import { livenessOrigin } from './liveness.mjs';
|
|
15
|
+
import { knownOrigin, hasRuntimeError } from './instance-presentation.mjs';
|
|
16
|
+
|
|
17
|
+
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
+
|
|
19
|
+
/** One row per instance of a roster (deployment-data.mjs `deploymentStatusData`): the kernel's row,
|
|
20
|
+
* with `agent`, `description` and `team` from its soul and `agentsRoot` from the roster.
|
|
21
|
+
* Needs input: a row keeps the kernel's `waitingOnYou` only when this CLI advertises waiting-on-you.
|
|
22
|
+
* Gate on the feature, never the version: a pre-feature kernel emitting the field is dropped. A row
|
|
23
|
+
* without the key stays without it. */
|
|
24
|
+
export function rosterRows(roster, cli) {
|
|
25
|
+
const waitingFeature = Array.isArray(cli?.features) && cli.features.includes("waiting-on-you");
|
|
26
|
+
return roster.agents.flatMap((agent) => agent.instances.map(({ waitingOnYou, ...instance }) => ({
|
|
27
|
+
...instance, ...(waitingFeature && waitingOnYou !== undefined ? { waitingOnYou } : {}),
|
|
28
|
+
agent: instance.agent || agent.name, description: agent.description || "",
|
|
29
|
+
team: agent.team || null, agentsRoot: roster.root,
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The liveness collector's input (liveness.mjs `observeLiveness`), one per row, in the rows' order.
|
|
34
|
+
* `running` is the kernel's answer: the collector leaves a row it answered `null` as the kernel has it. */
|
|
35
|
+
export function livenessInput(rows) {
|
|
36
|
+
return rows.map((i) => ({ instance: i.instance, running: i.running, tmux: i.tmux, sessionTarget: i.sessionTarget,
|
|
37
|
+
runtimeState: i.runtimeState, runtimeError: i.runtimeError }));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The collector's answers, one per row. `stdout` is what the collector printed, or `null` when it
|
|
41
|
+
* failed, timed out or could not start. Anything that is not JSON for an array of exactly
|
|
42
|
+
* `rows.length` answers gives every row the unknown answer; no rows give `[]`, whatever was printed.
|
|
43
|
+
*
|
|
44
|
+
* An answer with a `runtimeError` says who made it, in `runtimeErrorOrigin` (instance-presentation.mjs
|
|
45
|
+
* names the speakers). The speaker is decided here, in this process, and never read from what the
|
|
46
|
+
* collector printed: a `runtimeErrorOrigin` in its output is dropped, and the key is set from the row
|
|
47
|
+
* that was sent (liveness.mjs `livenessOrigin`: which answer `observeLiveness` gives is a function of
|
|
48
|
+
* the row alone). So `rows` are the rows whose `livenessInput` the collector was given. The unknown
|
|
49
|
+
* answer written here is the terminal check's own. */
|
|
50
|
+
export function livenessAnswers(rows, stdout) {
|
|
51
|
+
if (!rows.length) return [];
|
|
52
|
+
const unknown = () => rows.map(() => ({ running: null, runtimeState: "unreachable", runtimeError: "Terminal status is unavailable", runtimeErrorOrigin: "terminal-probe" }));
|
|
53
|
+
if (typeof stdout !== "string") return unknown();
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(stdout);
|
|
56
|
+
if (!Array.isArray(parsed) || parsed.length !== rows.length) return unknown();
|
|
57
|
+
return parsed.map((printed, index) => {
|
|
58
|
+
if (!record(printed)) return printed;
|
|
59
|
+
const { runtimeErrorOrigin: _printed, ...answer } = printed;
|
|
60
|
+
const origin = hasRuntimeError(answer) ? livenessOrigin(rows[index]) : null;
|
|
61
|
+
return origin ? { ...answer, runtimeErrorOrigin: origin } : answer;
|
|
62
|
+
});
|
|
63
|
+
} catch { return unknown(); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A row as the panel serves it: the per-instance contract a client's grouping and overview read.
|
|
67
|
+
* A dropped or misspelt field here is a field no view receives. */
|
|
68
|
+
export function panelInstance(i) {
|
|
69
|
+
return {
|
|
70
|
+
instance: i.instance, agent: i.agent, description: i.description,
|
|
71
|
+
// The reported harness only (harness-names.mjs reads a released kernel's runtime); never a guessed default.
|
|
72
|
+
repo: i.repo, work: i.work, branch: i.branch || null, harness: i.harness || null,
|
|
73
|
+
model: i.model || null, running: i.running, createdAt: i.createdAt,
|
|
74
|
+
home: i.home, agentsRoot: i.agentsRoot,
|
|
75
|
+
workspace: dirname(i.agentsRoot), repoName: (i.repo || dirname(i.agentsRoot)).split("/").pop(),
|
|
76
|
+
parentInstance: i.parentInstance || null,
|
|
77
|
+
// Agent relations (kernel contract, final): siblingInstance links a
|
|
78
|
+
// declared sibling to a ROOT anchor; relation/relativeTo record what
|
|
79
|
+
// was declared at spawn. Forwarded for cluster grouping and the
|
|
80
|
+
// cluster-first overview.
|
|
81
|
+
siblingInstance: i.siblingInstance || null,
|
|
82
|
+
relation: i.relation || null,
|
|
83
|
+
relativeTo: i.relativeTo || null,
|
|
84
|
+
...(i.sessionTarget ? { sessionTarget: i.sessionTarget } : {}),
|
|
85
|
+
runtimeState: i.runtimeState, runtimeError: i.runtimeError,
|
|
86
|
+
// Who made that text: only beside a `runtimeError`, and only one of the three speakers.
|
|
87
|
+
...(hasRuntimeError(i) && knownOrigin(i.runtimeErrorOrigin) ? { runtimeErrorOrigin: i.runtimeErrorOrigin } : {}),
|
|
88
|
+
tmux: i.tmux, git: null,
|
|
89
|
+
// Workspace-model v2 facts exactly as `oats status --json` reported them:
|
|
90
|
+
// module drift rows (or the recorded map when the workspace is
|
|
91
|
+
// unreachable), the soul source and the served identity. Identity is
|
|
92
|
+
// present only when a provider reported one — never synthesized.
|
|
93
|
+
...(i.modules !== undefined ? { modules: i.modules } : {}),
|
|
94
|
+
...(i.soul !== undefined ? { soul: i.soul } : {}),
|
|
95
|
+
...(i.identity !== undefined ? { identity: i.identity } : {}),
|
|
96
|
+
// desktop-facts: the last session start, where the model came from, the messaging identity's address.
|
|
97
|
+
...(i.startedAt !== undefined ? { startedAt: i.startedAt } : {}),
|
|
98
|
+
...(i.modelFrom !== undefined ? { modelFrom: i.modelFrom } : {}),
|
|
99
|
+
...(i.identityAddress !== undefined ? { identityAddress: i.identityAddress } : {}),
|
|
100
|
+
...(i.retirePending ? { retirePending: true } : {}),
|
|
101
|
+
...(i.rollbackIncomplete ? { rollbackIncomplete: true } : {}),
|
|
102
|
+
// #802: a spawn setting up its worktree (deployment-data.mjs keeps it as true only).
|
|
103
|
+
...(i.spawnInProgress === true ? { spawnInProgress: true } : {}),
|
|
104
|
+
...(i.captured ? { captured: true } : {}),
|
|
105
|
+
// Needs input (PR K): the validated claim (or null, unknown) as status reported it; absent stays absent.
|
|
106
|
+
// The client's liveness is merged before projection, so running/runtimeState beside it are the probe's.
|
|
107
|
+
...(i.waitingOnYou !== undefined ? { waitingOnYou: i.waitingOnYou } : {}),
|
|
108
|
+
team: i.team || null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The panel's rows: each row merged with its liveness answer and projected, running first, then by name.
|
|
113
|
+
* `answers` are `livenessAnswers`'.
|
|
114
|
+
*
|
|
115
|
+
* The merged row's `runtimeErrorOrigin` is set here or removed, whatever the row carried: when the
|
|
116
|
+
* answer holds the `runtimeError`, the answer's speaker; when the answer has none and the kernel's row
|
|
117
|
+
* had one (a probed row the kernel reported with a text), the text is the kernel's, so "kernel". */
|
|
118
|
+
export function panelInstances(rows, answers) {
|
|
119
|
+
return rows.map((row, index) => {
|
|
120
|
+
const answer = answers[index], { runtimeErrorOrigin: _carried, ...merged } = { ...row, ...answer };
|
|
121
|
+
const origin = record(answer) && Object.hasOwn(answer, "runtimeError") ? answer.runtimeErrorOrigin : "kernel";
|
|
122
|
+
return panelInstance(hasRuntimeError(merged) ? { ...merged, runtimeErrorOrigin: origin } : merged);
|
|
123
|
+
}).sort((a, b) => (a.running === b.running ? String(a.instance).localeCompare(b.instance) : a.running ? -1 : 1));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A deployment's entry before the first CLI probe has settled, when there is no verdict to report:
|
|
127
|
+
* the entry already held, or a pending one. */
|
|
128
|
+
export function pendingEntry(previous, at) {
|
|
129
|
+
return previous || { deployment: { status: "pending" }, instances: [], generatedAt: at };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A deployment's entry after a read that failed with `reason` (deployment-contract.mjs).
|
|
133
|
+
* A transient busy or stale read keeps the entry held, as it is. A remote the kernel could not read
|
|
134
|
+
* (a cache problem, the network, a timeout) does not erase what was observed: the last observation
|
|
135
|
+
* stays, marked with the failure, the kernel's message and its bounded cause (Spec D); an `error`, an
|
|
136
|
+
* `errorOrigin` and an `errorCause` it already carried are replaced, the origin and the cause removed
|
|
137
|
+
* when this reason has none.
|
|
138
|
+
* Every other failure, and each of those without an entry to keep, is shown as unavailable with the
|
|
139
|
+
* reason, never as an empty roster.
|
|
140
|
+
*
|
|
141
|
+
* The kept entry's `error` is always a string: the reason's message, or "" when it carries none. That
|
|
142
|
+
* `error` is a string is the fact "a failure is kept" (deployment-facts.mjs `keptFailure`, the one place
|
|
143
|
+
* that reads it); what the string holds decides nothing.
|
|
144
|
+
* `errorOrigin: "kernel"` stands beside it when the reason is one the installed CLI printed (the reader's
|
|
145
|
+
* `origin: 'kernel'`, deployment-read-cli.mjs), and is absent for any other reason: who shows `error`
|
|
146
|
+
* names its speaker from this key (instance-presentation.mjs `originLead`), and shows a message with no
|
|
147
|
+
* origin as its own, never under the kernel's name. The key is written here only, from the reason given:
|
|
148
|
+
* one the entry already carried never survives. */
|
|
149
|
+
export function failedEntry(previous, reason, at) {
|
|
150
|
+
if (previous && ["E_DEPLOYMENT_BUSY", "E_DEPLOYMENT_STALE"].includes(reason?.code)) return previous;
|
|
151
|
+
if (previous?.deployment?.status === "observed" && reason?.code === "E_REMOTE_UNREADABLE") {
|
|
152
|
+
const { error: _error, errorCause: _cause, errorOrigin: _origin, ...kept } = previous;
|
|
153
|
+
const cause = reason.cause;
|
|
154
|
+
return { ...kept, error: typeof reason.message === "string" ? reason.message : "", ...(reason.origin === "kernel" ? { errorOrigin: "kernel" } : {}),
|
|
155
|
+
...(cause ? { errorCause: { code: reason.code, ...cause } } : {}) };
|
|
156
|
+
}
|
|
157
|
+
return { deployment: { status: "unavailable", reason }, instances: [], generatedAt: at };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** An observed deployment's entry: the observer's answer (deployment-observer.mjs: `roster`,
|
|
161
|
+
* `workspaceStatus`, `observedAt`) and the panel's rows (`panelInstances`). `souls` are the roster's
|
|
162
|
+
* souls without their instances. A client adds its own facts to `deployment` after the call. */
|
|
163
|
+
export function observedEntry({ roster, workspaceStatus, observedAt }, instances, at) {
|
|
164
|
+
return {
|
|
165
|
+
deployment: { status: "observed", root: roster.root, workspace: workspaceStatus.workspace, workspaceStatus,
|
|
166
|
+
reachable: roster.workspace ?? null, withheld: roster.withheld,
|
|
167
|
+
souls: roster.agents.map(({ instances: _instances, ...soul }) => soul) },
|
|
168
|
+
instances, generatedAt: at, observedAt,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The deployment facts a view may show: the header observation, reachability and any unavailable
|
|
173
|
+
* reason. Pending when there is none; as it is when not observed; without the private soul rows
|
|
174
|
+
* (`souls`) and the catalog's key when observed. */
|
|
175
|
+
export function publicDeployment(deployment) {
|
|
176
|
+
if (!deployment) return { status: "pending" };
|
|
177
|
+
if (deployment.status !== "observed") return deployment;
|
|
178
|
+
const { souls: _souls, catalogKey: _catalogKey, ...rest } = deployment;
|
|
179
|
+
return rest;
|
|
180
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Bounded fixed-argv native deployment reads. Private producer documents are
|
|
2
|
+
* projected by the owning observer, never forwarded wholesale to a renderer. */
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
5
|
+
import { deploymentReadGate, deploymentFailure, deploymentRecord, deploymentErrorCode, validMaxAge, maxAgeArgv, remoteFailureCause } from './deployment-contract.mjs';
|
|
6
|
+
import { withoutInstanceVariables } from './kernel-environment.mjs';
|
|
7
|
+
|
|
8
|
+
export const DEPLOYMENT_READ_TIMEOUT = 30_000;
|
|
9
|
+
export const DEPLOYMENT_READ_MAX_BUFFER = 4 * 1024 * 1024;
|
|
10
|
+
const absolute = path => typeof path === 'string' && !path.includes('\0') && isAbsolute(path) && resolve(path) === path;
|
|
11
|
+
|
|
12
|
+
/** `status` is a raw object; `workspace status` is a schemaVersion:1 envelope.
|
|
13
|
+
* Those are distinct native command contracts, not interchangeable generations.
|
|
14
|
+
* `io.exec` is a client's own `execFile` (the rule is at cli-adapter.mjs `runJson`); `io.env` its environment. */
|
|
15
|
+
export function cliDeploymentRead(cli, options, io = {}) {
|
|
16
|
+
const action = options?.action;
|
|
17
|
+
const gate = deploymentReadGate(cli, action);
|
|
18
|
+
if (gate) return Promise.resolve(gate);
|
|
19
|
+
if (!absolute(cli.bin) || !deploymentRecord(options) || Object.keys(options).some(k => !['action', 'context', 'maxAge'].includes(k))
|
|
20
|
+
|| !absolute(options.context) || !validMaxAge(options.maxAge)) return Promise.resolve(deploymentFailure('E_BAD_ARGS'));
|
|
21
|
+
const context = options.context, bin = cli.bin;
|
|
22
|
+
// --max-age only when the probe declares observe-max-age; otherwise the argv is the flagless one.
|
|
23
|
+
const argv = [...(action === 'status' ? ['status'] : ['workspace', 'status']), '--dir', context, ...maxAgeArgv(cli.features, options.maxAge), '--json'];
|
|
24
|
+
const env = withoutInstanceVariables(io.env ?? process.env);
|
|
25
|
+
return new Promise(done => {
|
|
26
|
+
const fail = code => done(deploymentFailure(code));
|
|
27
|
+
try {
|
|
28
|
+
(io.exec ?? execFile)(bin, argv, { cwd: context, env, shell: false, encoding: 'utf8', timeout: DEPLOYMENT_READ_TIMEOUT, maxBuffer: DEPLOYMENT_READ_MAX_BUFFER }, (error, stdout) => {
|
|
29
|
+
if (error?.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') return fail('E_CLI_OUTPUT_LIMIT');
|
|
30
|
+
if (error?.killed) return fail('E_CLI_TIMEOUT');
|
|
31
|
+
if (typeof stdout !== 'string') return fail(error ? 'E_CLI_FAILED' : 'E_CLI_PROTOCOL');
|
|
32
|
+
if (Buffer.byteLength(stdout, 'utf8') > DEPLOYMENT_READ_MAX_BUFFER) return fail('E_CLI_OUTPUT_LIMIT');
|
|
33
|
+
let document;
|
|
34
|
+
try { document = JSON.parse(stdout); } catch { return fail(error ? 'E_CLI_FAILED' : 'E_CLI_PROTOCOL'); }
|
|
35
|
+
if (!deploymentRecord(document)) return fail('E_CLI_PROTOCOL');
|
|
36
|
+
if (document.schemaVersion === 1 && document.ok === false) {
|
|
37
|
+
const reason = document.error;
|
|
38
|
+
if (!deploymentRecord(reason) || !deploymentErrorCode(reason.code)
|
|
39
|
+
|| typeof reason.message !== 'string' || reason.message.length > 8192) return fail('E_CLI_PROTOCOL');
|
|
40
|
+
// Only the bounded kernel error envelope, never stderr, argv, stacks or an exec error's message;
|
|
41
|
+
// of `details`, only an unreadable remote's bounded cause (Spec D). A refusal cannot become success.
|
|
42
|
+
// `origin: 'kernel'`: this reason is the one the installed CLI printed in its envelope, so the
|
|
43
|
+
// kernel answered, in its own words. The reader's own failures (`deploymentFailure`: the gate, a
|
|
44
|
+
// timeout, the output limit, a protocol failure, a failed run) carry no origin, and unmarked
|
|
45
|
+
// reads as not the kernel's: who shows a reason decides by where it came from, never by its shape.
|
|
46
|
+
const cause = reason.code === 'E_REMOTE_UNREADABLE' ? remoteFailureCause(reason.details) : null;
|
|
47
|
+
return done({ ok: false, reason: { code: reason.code, message: reason.message, origin: 'kernel', ...(cause ? { cause } : {}) } });
|
|
48
|
+
}
|
|
49
|
+
if (error) return fail('E_CLI_FAILED');
|
|
50
|
+
if (action === 'status') {
|
|
51
|
+
if (Object.hasOwn(document, 'schemaVersion') || !absolute(document.root) || !Array.isArray(document.agents)) return fail('E_CLI_PROTOCOL');
|
|
52
|
+
} else if (document.schemaVersion !== 1 || document.ok !== true || document.result?.workspaceStatusApi !== 1) return fail('E_CLI_PROTOCOL');
|
|
53
|
+
done({ ok: true, document });
|
|
54
|
+
});
|
|
55
|
+
} catch { fail('E_CLI_FAILED'); }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** The one display filter for free text the kernel or a host supplies and Desktop shows: a detail, or a
|
|
2
|
+
* label inside one of Desktop's sentences. The result is lossy and for display only: it is never evidence
|
|
3
|
+
* of identity and never authority for an action, and it is not fit for a name that identifies something.
|
|
4
|
+
* Pure: no DOM, no IO, never throws. A contract module: the server imports it too, so it imports nothing. */
|
|
5
|
+
|
|
6
|
+
/** Not text a one-line note may hold, an exact set (the maintainer's decision for the kernel's
|
|
7
|
+
* validWaitingMessage): control characters (Cc: C0, DEL, C1), the line and paragraph separators, the bidi
|
|
8
|
+
* embeddings and overrides (U+202A–202E) and isolates (U+2066–2069), the zero-width space, the word
|
|
9
|
+
* joiner, the BOM and the tag characters (U+E0000–E007F). Every other format character is text: ZWJ
|
|
10
|
+
* (emoji sequences), ZWNJ (Persian, Urdu), LRM, RLM and ALM (Hebrew, Arabic), the soft hyphen. */
|
|
11
|
+
export const NOT_NOTE_TEXT = /[\p{Cc}\u2028\u2029\u202A-\u202E\u2066-\u2069\u200B\u2060\uFEFF\u{E0000}-\u{E007F}]/u;
|
|
12
|
+
const EVERY_NOT_NOTE_TEXT = new RegExp(NOT_NOTE_TEXT.source, 'gu');
|
|
13
|
+
|
|
14
|
+
/** Text withheld whole: secrets, credentialed URLs, C0 controls other than tab and line feed, DEL.
|
|
15
|
+
* Its time grows with the length of the text, which is tested as given and may be long (#976). So the URL
|
|
16
|
+
* alternative finds `://` first and looks behind it for the scheme: written scheme first, it read a run of
|
|
17
|
+
* letters to its end from each letter of the run, and its time grew with the square of the run. The
|
|
18
|
+
* look-behind reads only scheme characters and `://` holds none, so each `://` reads its own run once;
|
|
19
|
+
* what follows stops at the next `/`, and every `://` holds one. Asked only whether it matches: this form
|
|
20
|
+
* and the scheme-first one match the same texts, not the same part of them. */
|
|
21
|
+
export const UNSAFE = /[\x00-\x08\x0b-\x1f\x7f]|:\/\/(?<=[a-z][a-z0-9+.-]*:\/\/)[^\s/]*@|(?:token|authorization|password|secret|api[_ -]?key)\s*[:=]\s*\S+|(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]{16,}/i;
|
|
22
|
+
export const DETAIL_WITHHELD = '[Detail withheld]';
|
|
23
|
+
export const MAX_DISPLAY_LINE = 2048;
|
|
24
|
+
|
|
25
|
+
/** One line: tab, line feed and the line and paragraph separators each become a space, runs of spaces
|
|
26
|
+
* collapse (also a run the text already had: acceptable for free text, not for an identifier) and the
|
|
27
|
+
* ends are trimmed. Every character of NOT_NOTE_TEXT still present becomes U+FFFD:
|
|
28
|
+
* replaced, never dropped, so the reader sees something was withheld. Two different texts can become the
|
|
29
|
+
* same line: the result is for display only, never for comparing, selecting or addressing anything.
|
|
30
|
+
* Bounded to MAX_DISPLAY_LINE UTF-16 units, without splitting a surrogate pair or ending on a space. */
|
|
31
|
+
function oneLine(text) {
|
|
32
|
+
const line = text.replace(/[\t\n\u2028\u2029]/g, ' ').replace(/ {2,}/g, ' ').replace(/^ | $/g, '').replace(EVERY_NOT_NOTE_TEXT, '\uFFFD');
|
|
33
|
+
if (line.length <= MAX_DISPLAY_LINE) return line;
|
|
34
|
+
const last = line.charCodeAt(MAX_DISPLAY_LINE - 1);
|
|
35
|
+
return line.slice(0, last >= 0xD800 && last <= 0xDBFF ? MAX_DISPLAY_LINE - 1 : MAX_DISPLAY_LINE).replace(/ $/, '');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Kernel or host text as one display line, DETAIL_WITHHELD when it is UNSAFE, or null when there is
|
|
39
|
+
* nothing to show (not a string, empty, or only line breaks and spaces). UNSAFE is tested on the text as
|
|
40
|
+
* given, before any folding, replacement or truncation: what is withheld is withheld whole. The line is
|
|
41
|
+
* what is shown, so it is held to UNSAFE as well; filtering twice therefore equals filtering once. */
|
|
42
|
+
export function displayLine(text) {
|
|
43
|
+
if (typeof text !== 'string' || !text) return null;
|
|
44
|
+
if (UNSAFE.test(text)) return DETAIL_WITHHELD;
|
|
45
|
+
const line = oneLine(text);
|
|
46
|
+
return !line ? null : UNSAFE.test(line) ? DETAIL_WITHHELD : line;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Already a display line: what a relayed text must be before it is shown again. */
|
|
50
|
+
export const cleanLine = v => typeof v === 'string' && displayLine(v) === v;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The harness rename (kernel 0.27.0, feature `harness`; docs/desktop-cli-api.md
|
|
2
|
+
* "The harness rename"). The Desktop speaks `harness`. A released kernel without
|
|
3
|
+
* the feature still speaks `runtime`: its payloads are READ in either spelling
|
|
4
|
+
* (a payload carries one; the new name wins), and what the Desktop WRITES to a
|
|
5
|
+
* kernel (flags, definition keys) follows the feature. Drop the old spellings
|
|
6
|
+
* when the accepted range no longer includes a kernel without `harness`. */
|
|
7
|
+
export const HARNESSES = Object.freeze(['pi', 'claude', 'codex']);
|
|
8
|
+
/** Each harness as people read it. */
|
|
9
|
+
export const HARNESS_NAMES = Object.freeze({ pi: 'Pi', claude: 'Claude Code', codex: 'Codex' });
|
|
10
|
+
|
|
11
|
+
export const harnessFeature = cli => Array.isArray(cli?.features) && cli.features.includes('harness');
|
|
12
|
+
/** The spawn/session/launch-config flag for this kernel. */
|
|
13
|
+
export const harnessFlag = cli => harnessFeature(cli) ? '--harness' : '--runtime';
|
|
14
|
+
/** The key a definition written to this kernel uses (launch-config set, schedule spec). */
|
|
15
|
+
export const harnessKey = cli => harnessFeature(cli) ? 'harness' : 'runtime';
|
|
16
|
+
|
|
17
|
+
/** A kernel row's harness: `harness`, else a released kernel's `runtime`. */
|
|
18
|
+
export function harnessOf(row) {
|
|
19
|
+
if (!row || typeof row !== 'object') return undefined;
|
|
20
|
+
if (Object.hasOwn(row, 'harness')) return row.harness;
|
|
21
|
+
if (Object.hasOwn(row, 'runtime')) return row.runtime;
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The probe's harness list: `harnesses` with the feature, a released kernel's `runtimes` without. */
|
|
26
|
+
export function harnessList(probe) {
|
|
27
|
+
const value = harnessFeature(probe) ? probe?.harnesses : probe?.runtimes;
|
|
28
|
+
return Array.isArray(value) ? value : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** `oats inspect --json` on the workspace model (`operationsApi: 2`; each soul
|
|
2
|
+
* row `soulsApi: 2`). The subject is an instance (`--home`) or a soul
|
|
3
|
+
* (`--soul`), never a scope. Everything shown is the kernel's record: a
|
|
4
|
+
* capability's origin is its module's `from`, its settings the merged payload.
|
|
5
|
+
* Presentation-only; no classic field (scope chain, activation, trust,
|
|
6
|
+
* snapshot drift, sources provenance) is read. */
|
|
7
|
+
import { harnessOf } from './harness-names.mjs';
|
|
8
|
+
import { launchOf, REPORT_FROM, RECORD_FROM } from './launch-contract.mjs';
|
|
9
|
+
import { memberLabel } from './deployment-facts.mjs';
|
|
10
|
+
|
|
11
|
+
export const OPERATIONS_API = 2;
|
|
12
|
+
export const SOULS_API = 2;
|
|
13
|
+
const record = v => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
14
|
+
const str = v => typeof v === 'string';
|
|
15
|
+
const short = v => str(v) && /^[0-9a-f]{7,64}$/.test(v) ? v.slice(0, 7) : null;
|
|
16
|
+
|
|
17
|
+
/** The probe integer is the gate (no feature string). */
|
|
18
|
+
export const inspectSupported = cli => cli?.ok === true && cli.operationsApi === OPERATIONS_API;
|
|
19
|
+
|
|
20
|
+
/** The inspection for this selection, or null when it is not the operationsApi 2
|
|
21
|
+
* document for exactly this subject. */
|
|
22
|
+
export function inspectData(v, selection) {
|
|
23
|
+
if (!record(v) || v.operationsApi !== OPERATIONS_API || !record(v.subject) || !Array.isArray(v.souls) || v.souls.length > 1
|
|
24
|
+
|| !Array.isArray(v.capabilities) || !record(v.layers) || !Array.isArray(v.problems)) return null;
|
|
25
|
+
const s = v.subject;
|
|
26
|
+
if (selection?.instance) {
|
|
27
|
+
if (s.kind !== 'instance' || s.home !== selection.selector?.home || !record(v.instance)) return null;
|
|
28
|
+
} else if (selection?.agent) {
|
|
29
|
+
if (s.kind !== 'soul' || s.soul !== selection.agent.name || v.instance !== null) return null;
|
|
30
|
+
} else return null;
|
|
31
|
+
if (v.souls.some(row => !record(row) || row.soulsApi !== SOULS_API)) return null;
|
|
32
|
+
if (v.capabilities.some(cap => !record(cap) || !str(cap.id) || !Array.isArray(cap.operations ?? []))) return null;
|
|
33
|
+
// Launch preferences (0.30, feature launch-preference): a soul's is what a spawn with no flags would
|
|
34
|
+
// decide; a home's is its record (a pre-0.30 home reads `recorded`), with `launchCurrent` (what
|
|
35
|
+
// --reselect-launch would choose now, or null).
|
|
36
|
+
const home = s.kind === 'instance', ok = (x, from) => launchOf(x, from) !== undefined;
|
|
37
|
+
if (Object.hasOwn(v, 'launch') && !ok(v.launch, home ? RECORD_FROM : REPORT_FROM)) return null;
|
|
38
|
+
if (Object.hasOwn(v, 'launchCurrent') && !(home && (v.launchCurrent === null || ok(v.launchCurrent, REPORT_FROM)))) return null;
|
|
39
|
+
if (v.souls.some(row => Object.hasOwn(row, 'launch') && !ok(row.launch, REPORT_FROM))) return null;
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const text = (v, fallback = '—') => v === undefined || v === null || v === '' ? fallback : String(v);
|
|
44
|
+
/** A module's `from`: member commit, or package version + commit. */
|
|
45
|
+
export function originText(from) {
|
|
46
|
+
if (!record(from)) return 'Not reported';
|
|
47
|
+
if (from.kind === 'package') return `package ${text(from.package, '?')} ${text(from.version, '')}`.trimEnd() + (short(from.commit) ? ` @ ${short(from.commit)}` : '');
|
|
48
|
+
if (from.kind === 'member') return `member ${memberLabel(from.repoKey)}${short(from.commit) ? ` @ ${short(from.commit)}` : ''}`;
|
|
49
|
+
return text(from.kind);
|
|
50
|
+
}
|
|
51
|
+
export const inspectFacts = {
|
|
52
|
+
instance: i => [
|
|
53
|
+
['Harness', text(harnessOf(i))], ['Model', text(i.model, 'Harness default')],
|
|
54
|
+
['Permissions', i.yolo === true ? 'Unrestricted (yolo)' : i.yolo === false ? 'Restricted' : 'Harness default'],
|
|
55
|
+
['Launched', i.launched === true ? 'Yes' : i.launched === false ? 'No' : '—'], ['Created', text(i.createdAt)],
|
|
56
|
+
['Resolution', str(i.resolution) ? i.resolution.slice(0, 12) : '—'],
|
|
57
|
+
],
|
|
58
|
+
capability: cap => [
|
|
59
|
+
['Version', text(cap.version)], ['Layer', text(cap.layer, 'None')], ['Origin', originText(cap.from)],
|
|
60
|
+
['Missing requirements', Array.isArray(cap.missingRequires) && cap.missingRequires.length ? cap.missingRequires.join(', ') : 'None'],
|
|
61
|
+
],
|
|
62
|
+
};
|