@awebai/oats 0.43.3 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/oats.mjs +98 -27
- package/docs/capabilities.md +7 -1
- package/docs/configuration.md +65 -0
- package/docs/desktop-cli-api.md +149 -4
- package/docs/execution-targets.md +75 -0
- package/docs/implementation.md +14 -1
- package/docs/oats-local.schema.json +19 -1
- package/docs/oats-workspace.schema.json +1 -1
- package/docs/release-notes/v0.44.0.md +161 -0
- package/docs/schedules.md +27 -9
- package/docs/souls-and-instances.md +7 -0
- package/lib/core.mjs +253 -87
- package/lib/instance-events.mjs +1 -1
- package/lib/instance-inspect.mjs +39 -6
- package/lib/launch-prompt-fixtures/README.md +49 -0
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-05-channel-seeded.txt +35 -0
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-06-first-after-channel.txt +35 -0
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-07-after-channel-200ms.txt +35 -0
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-08-installed-after-channel-200ms.txt +35 -0
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/manifest.json +77 -0
- package/lib/launch-prompt-fixtures.mjs +114 -0
- package/lib/launch-prompt-policy.mjs +73 -0
- package/lib/launch-prompt-transport.mjs +102 -0
- package/lib/launch-prompts.mjs +216 -0
- package/lib/operator-coverage.mjs +134 -0
- package/lib/remote.mjs +15 -9
- package/lib/schedule.mjs +57 -10
- package/lib/teams-verbs.mjs +3 -3
- package/lib/triggers.mjs +2 -2
- package/lib/workspace.mjs +20 -2
- package/package.json +1 -1
- package/skills/oats-getting-started/SKILL.md +15 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Launch-only tmux observations. Exact visible bytes, never scrollback or
|
|
2
|
+
* joined wrapped lines; both identity/geometry reads must agree. */
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { isAbsolute } from 'node:path';
|
|
5
|
+
import { performance } from 'node:perf_hooks';
|
|
6
|
+
|
|
7
|
+
function budget(timeout) {
|
|
8
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new Error('invalid launch timeout');
|
|
9
|
+
const deadline = performance.now() + timeout;
|
|
10
|
+
return () => {
|
|
11
|
+
const left = deadline - performance.now();
|
|
12
|
+
if (left <= 0) throw new Error('launch geometry timeout');
|
|
13
|
+
return left;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const LAUNCH_PANE_FORMAT = '#{window_id}\t#{pane_id}\t#{pane_pid}';
|
|
18
|
+
const SNAPSHOT_FORMAT = `${LAUNCH_PANE_FORMAT}\t#{pane_width}\t#{pane_height}\t#{window_panes}`;
|
|
19
|
+
export function launchPaneTarget(socket, output) {
|
|
20
|
+
const fields = String(output).trim().split('\t');
|
|
21
|
+
if (!isAbsolute(socket || '') || fields.length !== 3 || !/^@\d+$/.test(fields[0]) || !/^%\d+$/.test(fields[1]) || !/^[1-9]\d*$/.test(fields[2])) throw new Error('invalid launch pane identity');
|
|
22
|
+
return { socket, windowId: fields[0], paneId: fields[1], pid: fields[2] };
|
|
23
|
+
}
|
|
24
|
+
export function launchPromptTransport(io) {
|
|
25
|
+
const run = (target, args, timeout) => {
|
|
26
|
+
if (!isAbsolute(target.socket || '') || !/^%\d+$/.test(target.paneId || '') || !Number.isFinite(timeout) || !(timeout > 0)) throw new Error('invalid launch target');
|
|
27
|
+
return String((io?.exec || execFileSync)('tmux', ['-u', '-S', target.socket, ...args], {
|
|
28
|
+
encoding: 'utf8', timeout: Math.max(1, Math.floor(timeout)), killSignal: 'SIGKILL', maxBuffer: 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'],
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
const pins = new WeakMap();
|
|
32
|
+
const transport = {
|
|
33
|
+
// Called only before this invocation respawns an already-owned exact pane.
|
|
34
|
+
identity(socket, paneId) {
|
|
35
|
+
return launchPaneTarget(socket, run({socket, paneId}, ['display-message', '-p', '-t', paneId, LAUNCH_PANE_FORMAT], 1000));
|
|
36
|
+
},
|
|
37
|
+
snapshot(target, timeout) {
|
|
38
|
+
const out = run(target, ['display-message', '-p', '-t', target.paneId, SNAPSHOT_FORMAT, ';',
|
|
39
|
+
'capture-pane', '-p', '-t', target.paneId, ';',
|
|
40
|
+
'display-message', '-p', '-t', target.paneId, SNAPSHOT_FORMAT], timeout);
|
|
41
|
+
const lines = out.split('\n');
|
|
42
|
+
if (lines.at(-1) === '') lines.pop();
|
|
43
|
+
const first = lines.shift(), last = lines.pop();
|
|
44
|
+
if (first !== last) throw new Error('launch pane identity or geometry changed');
|
|
45
|
+
const fields = first?.split('\t') || [];
|
|
46
|
+
if (fields.length !== 6 || fields[5] !== '1' || !/^[1-9]\d*$/.test(fields[3]) || !/^[1-9]\d*$/.test(fields[4])) throw new Error('launch pane is not exclusively owned');
|
|
47
|
+
const actual = launchPaneTarget(target.socket, fields.slice(0, 3).join('\t'));
|
|
48
|
+
if (actual.windowId !== target.windowId || actual.paneId !== target.paneId || actual.pid !== String(target.pid)) throw new Error('launch pane replaced');
|
|
49
|
+
if (lines.length !== Number(fields[4])) throw new Error('incomplete visible capture');
|
|
50
|
+
return { ...actual, width: Number(fields[3]), height: Number(fields[4]), text: lines.join('\n') + '\n' };
|
|
51
|
+
},
|
|
52
|
+
// Pin only an exclusively owned window. Tokens are invocation-local and
|
|
53
|
+
// cannot be reconstructed from an event receipt or another transport.
|
|
54
|
+
pin(target, geometry, timeout) {
|
|
55
|
+
if (!Number.isSafeInteger(geometry?.width) || geometry.width < 1 || !Number.isSafeInteger(geometry?.height) || geometry.height < 1) throw new Error('invalid launch geometry');
|
|
56
|
+
const remaining = budget(timeout);
|
|
57
|
+
const before = transport.snapshot(target, remaining());
|
|
58
|
+
const windowSize = run(target, ['show-options', '-w', '-q', '-v', '-t', target.windowId, 'window-size'], remaining()).trim();
|
|
59
|
+
if (!['', 'largest', 'smallest', 'manual', 'latest'].includes(windowSize)) throw new Error('invalid window-size policy');
|
|
60
|
+
// An empty option is inherited; restoration must unset our local override.
|
|
61
|
+
const token = Object.freeze({ previous: Object.freeze({ width: before.width, height: before.height, windowSize }) });
|
|
62
|
+
pins.set(token, { target: { ...target }, previous: token.previous });
|
|
63
|
+
try {
|
|
64
|
+
transport.snapshot(target, remaining());
|
|
65
|
+
run(target, ['set-option', '-w', '-t', target.windowId, 'window-size', 'manual', ';',
|
|
66
|
+
'resize-window', '-t', target.windowId, '-x', String(geometry.width), '-y', String(geometry.height)], remaining());
|
|
67
|
+
const after = transport.snapshot(target, remaining());
|
|
68
|
+
if (after.width !== geometry.width || after.height !== geometry.height) throw new Error('launch geometry pin failed');
|
|
69
|
+
return token;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
// A failed command may already have changed the option/dimensions.
|
|
72
|
+
try { transport.restore(target, token, 3000); error.geometryRestored = true; }
|
|
73
|
+
catch { error.geometryRestoreFailed = true; }
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
restore(target, token, timeout) {
|
|
78
|
+
const remaining = budget(timeout);
|
|
79
|
+
const saved = pins.get(token);
|
|
80
|
+
if (!saved || ['socket', 'windowId', 'paneId', 'pid'].some(key => String(saved.target[key]) !== String(target[key]))) throw new Error('invalid launch geometry token');
|
|
81
|
+
// Consume even on failure: no retries can resize a replacement process.
|
|
82
|
+
pins.delete(token);
|
|
83
|
+
transport.snapshot(target, remaining());
|
|
84
|
+
const { width, height, windowSize } = saved.previous;
|
|
85
|
+
const reset = windowSize === ''
|
|
86
|
+
? ['set-option', '-w', '-u', '-t', target.windowId, 'window-size']
|
|
87
|
+
: ['set-option', '-w', '-t', target.windowId, 'window-size', windowSize];
|
|
88
|
+
run(target, ['set-option', '-w', '-t', target.windowId, 'window-size', 'manual', ';',
|
|
89
|
+
'resize-window', '-t', target.windowId, '-x', String(width), '-y', String(height), ';', ...reset], remaining());
|
|
90
|
+
const after = transport.snapshot(target, remaining());
|
|
91
|
+
const restoredPolicy = run(target, ['show-options', '-w', '-q', '-v', '-t', target.windowId, 'window-size'], remaining()).trim();
|
|
92
|
+
if (after.width !== width || after.height !== height || restoredPolicy !== windowSize) throw new Error('launch geometry restoration failed');
|
|
93
|
+
return { status: 'restored' };
|
|
94
|
+
},
|
|
95
|
+
send(target, key, timeout) {
|
|
96
|
+
if (key !== 'Enter') throw new Error('invalid launch action');
|
|
97
|
+
run(target, ['send-keys', '-t', target.paneId, key], timeout);
|
|
98
|
+
return { status: 'submitted' };
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return transport;
|
|
102
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { performance } from "node:perf_hooks";
|
|
4
|
+
|
|
5
|
+
const LIMIT = 30000;
|
|
6
|
+
const INTERVAL = 100;
|
|
7
|
+
const digest = (text) => createHash("sha256").update(text).digest("hex");
|
|
8
|
+
const sameTarget = (a, b, pid = true) => a && b && ["socket", "windowId", "paneId", ...(pid ? ["pid"] : [])].every(k => String(a[k]) === String(b[k]));
|
|
9
|
+
const validTarget = t => t && typeof t.socket === "string" && t.socket.length > 0 && /^@\d+$/.test(t.windowId) && /^%\d+$/.test(t.paneId) && /^[1-9]\d*$/.test(String(t.pid));
|
|
10
|
+
const wait = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
11
|
+
|
|
12
|
+
/** Private, single-invocation authority. Production fixtures must pass the separate qualification adapter.
|
|
13
|
+
* Transport captures visible bytes only and independently verifies ownership and
|
|
14
|
+
* stable geometry around capture. Every call receives the remaining deadline.
|
|
15
|
+
* Synthetic fixtures are injectable for tests; accepting a real version/platform
|
|
16
|
+
* fixture is a separate review gate. A fixture binds an exact home and complete
|
|
17
|
+
* frames (text, width, height), never a substring or whitespace normalization.
|
|
18
|
+
* audit receives launch-prompt event data and returns appendEvent's checked result.
|
|
19
|
+
*/
|
|
20
|
+
export function createLaunchPromptController({ home, startId, harness, policy = {}, transport, audit,
|
|
21
|
+
now = () => performance.now(), sleep = wait, fixtures = [], geometry, validateExecutable, expectedHomeIdentity }) {
|
|
22
|
+
const selectedHarness = typeof harness === "string" ? { name: harness } : { ...harness };
|
|
23
|
+
const consent = { ...policy };
|
|
24
|
+
// Copy fixture data so a caller cannot change signatures during an answer.
|
|
25
|
+
const accepted = structuredClone(fixtures);
|
|
26
|
+
let identity;
|
|
27
|
+
try {
|
|
28
|
+
const st = lstatSync(home);
|
|
29
|
+
if (!st.isDirectory() || realpathSync(home) !== home
|
|
30
|
+
|| (expectedHomeIdentity && (st.dev !== expectedHomeIdentity.dev || st.ino !== expectedHomeIdentity.ino))) throw new Error("home identity");
|
|
31
|
+
identity = { dev: st.dev, ino: st.ino };
|
|
32
|
+
} catch { /* Observation reports a retained blocked result, not a launch throw. */ }
|
|
33
|
+
const tokens = new WeakMap();
|
|
34
|
+
const deadline = now() + LIMIT;
|
|
35
|
+
let used = false, terminal, target, lastText = "", auditFailed = false;
|
|
36
|
+
const answers = [], receipts = [];
|
|
37
|
+
function checkHome() {
|
|
38
|
+
if (!identity || !startId) throw new Error("home identity changed");
|
|
39
|
+
const st = lstatSync(home);
|
|
40
|
+
if (!st.isDirectory() || st.dev !== identity.dev || st.ino !== identity.ino || realpathSync(home) !== home) throw new Error("home identity changed");
|
|
41
|
+
}
|
|
42
|
+
function checkAuthority() {
|
|
43
|
+
checkHome();
|
|
44
|
+
if (validateExecutable && validateExecutable() !== true) throw new Error("launch executable changed");
|
|
45
|
+
}
|
|
46
|
+
function remaining() {
|
|
47
|
+
const left = deadline - now();
|
|
48
|
+
if (!(left > 0)) throw new Error("observation timeout");
|
|
49
|
+
return Math.max(1, Math.ceil(left));
|
|
50
|
+
}
|
|
51
|
+
function capture(t) {
|
|
52
|
+
checkAuthority();
|
|
53
|
+
if (!validTarget(t)) throw new Error("invalid target");
|
|
54
|
+
const screen = transport.snapshot(t, remaining());
|
|
55
|
+
remaining();
|
|
56
|
+
checkAuthority();
|
|
57
|
+
if (!sameTarget(t, screen) || !Number.isInteger(screen.width) || screen.width < 1 || !Number.isInteger(screen.height) || screen.height < 1 || typeof screen.text !== "string") throw new Error("target or geometry changed");
|
|
58
|
+
lastText = screen.text;
|
|
59
|
+
return { ...screen };
|
|
60
|
+
}
|
|
61
|
+
function record(data) {
|
|
62
|
+
let result;
|
|
63
|
+
try {
|
|
64
|
+
checkHome();
|
|
65
|
+
result = audit({ home, startId, socket: target?.socket, windowId: target?.windowId,
|
|
66
|
+
paneId: target?.paneId, pid: target?.pid, consentSource: consent.consentSource ?? null, ...data });
|
|
67
|
+
} catch { auditFailed = true; return false; }
|
|
68
|
+
// Preserve actual appendEvent paths, including partial-log availability.
|
|
69
|
+
if (result && Array.isArray(result.results)) receipts.push({ ok: result.ok === true, ...(result.row ? { row: structuredClone(result.row) } : {}), results: result.results.map(r => ({ ...r })) });
|
|
70
|
+
if (result?.ok !== true) auditFailed = true;
|
|
71
|
+
return result?.ok === true;
|
|
72
|
+
}
|
|
73
|
+
function finish(status, reason, extra = {}) {
|
|
74
|
+
if (terminal) return terminal;
|
|
75
|
+
if (auditFailed) {
|
|
76
|
+
status = "incomplete";
|
|
77
|
+
reason = "launch prompt audit failed";
|
|
78
|
+
}
|
|
79
|
+
const recorded = record({ status, reason, signatureDigest: digest(lastText), ...extra });
|
|
80
|
+
if (!recorded || auditFailed) {
|
|
81
|
+
status = "incomplete";
|
|
82
|
+
reason = "launch prompt audit failed";
|
|
83
|
+
}
|
|
84
|
+
terminal = { status, answers: answers.map(a => ({ ...a })), reason, receipt: receipts };
|
|
85
|
+
return terminal;
|
|
86
|
+
}
|
|
87
|
+
function matching(screen) {
|
|
88
|
+
const candidates = [];
|
|
89
|
+
for (const fixture of accepted) {
|
|
90
|
+
if (!fixture.id || fixture.home !== home || fixture.harness !== selectedHarness.name || !fixture.version || fixture.version !== selectedHarness.version || !fixture.platform || fixture.platform !== selectedHarness.platform) continue;
|
|
91
|
+
for (const frame of fixture.frames ?? []) {
|
|
92
|
+
if (frame.text === screen.text && frame.width === screen.width && frame.height === screen.height
|
|
93
|
+
&& JSON.stringify(frame.after) === JSON.stringify(answers.map(a => a.class))) candidates.push({ fixture, frame });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
97
|
+
}
|
|
98
|
+
const exact = (a, b) => sameTarget(a, b) && a.width === b.width && a.height === b.height && a.text === b.text;
|
|
99
|
+
function observe(t, before) {
|
|
100
|
+
if (used) return terminal ?? { status: "blocked", answers: [], reason: "blocked: launch authority already used", receipt: [] };
|
|
101
|
+
used = true;
|
|
102
|
+
target = { ...t };
|
|
103
|
+
let fresh = before === undefined, resizeToken;
|
|
104
|
+
const wantsGeometry = geometry && Number.isInteger(geometry.width) && geometry.width > 0 && Number.isInteger(geometry.height) && geometry.height > 0
|
|
105
|
+
&& consent.awebDevelopmentChannel === true
|
|
106
|
+
&& accepted.some(f => f.home === home && f.harness === selectedHarness.name && f.version === selectedHarness.version && f.platform === selectedHarness.platform
|
|
107
|
+
&& f.frames?.some(frame => frame.width === geometry.width && frame.height === geometry.height));
|
|
108
|
+
let geometryHandled = !wantsGeometry;
|
|
109
|
+
function incompleteCleanup() {
|
|
110
|
+
if (!terminal) terminal = { answers: answers.map(a => ({ ...a })), receipt: receipts };
|
|
111
|
+
terminal.status = "incomplete";
|
|
112
|
+
terminal.reason = "launch prompt geometry restoration incomplete";
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
checkHome();
|
|
116
|
+
if (!validTarget(target)) return finish("blocked", "blocked: invalid target");
|
|
117
|
+
if (before !== undefined && (!before || !sameTarget(target, before, false) || String(target.pid) === String(before.pid))) return finish("blocked", "blocked: respawn ownership not proven");
|
|
118
|
+
// Hard iteration bound also protects against a broken injected clock.
|
|
119
|
+
for (let observations = 0; observations <= LIMIT / INTERVAL; observations++) {
|
|
120
|
+
let screen = capture(target);
|
|
121
|
+
if (!fresh) {
|
|
122
|
+
// A resize can reflow the *old* prompt into different bytes. Require
|
|
123
|
+
// a fresh process screen at the original geometry before pinning.
|
|
124
|
+
if (screen.width !== before.width || screen.height !== before.height) return finish("blocked", "blocked: respawn geometry changed before fresh screen");
|
|
125
|
+
if (screen.text !== before.text) fresh = true;
|
|
126
|
+
}
|
|
127
|
+
if (fresh && !geometryHandled) {
|
|
128
|
+
geometryHandled = true;
|
|
129
|
+
const fields = { action: "pin-geometry", width: geometry.width, height: geometry.height, signatureDigest: digest(screen.text) };
|
|
130
|
+
if (!record({ ...fields, status: "attempted" })) return finish("incomplete", "launch prompt audit failed before geometry pin");
|
|
131
|
+
checkAuthority();
|
|
132
|
+
resizeToken = transport.pin(target, { ...geometry }, remaining());
|
|
133
|
+
if (!resizeToken) return finish("incomplete", "launch prompt geometry pin failed");
|
|
134
|
+
if (!record({ ...fields, status: "submitted" })) return finish("incomplete", "launch prompt audit failed after geometry pin");
|
|
135
|
+
sleep(Math.min(INTERVAL, remaining()));
|
|
136
|
+
screen = capture(target);
|
|
137
|
+
if (screen.width !== geometry.width || screen.height !== geometry.height) return finish("blocked", "blocked: launch geometry not pinned");
|
|
138
|
+
}
|
|
139
|
+
if (!fresh || screen.text.trim() === "") {
|
|
140
|
+
sleep(Math.min(INTERVAL, remaining()));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const match = matching(screen);
|
|
144
|
+
if (!match) return finish("blocked", "blocked: unexpected prompt");
|
|
145
|
+
const { fixture, frame } = match;
|
|
146
|
+
const prior = answers.map(a => a.class);
|
|
147
|
+
if (frame.kind === "completed") return finish("completed", "recognized launch boundary");
|
|
148
|
+
if (frame.kind === "startup") {
|
|
149
|
+
sleep(Math.min(INTERVAL, remaining()));
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const klass = frame.class;
|
|
153
|
+
if (frame.kind !== "prompt" || klass !== "awebDevelopmentChannel" || prior.length !== 0) return finish("blocked", "blocked: repeated or unsupported prompt");
|
|
154
|
+
if (consent.awebDevelopmentChannel !== true || selectedHarness.name !== "claude" || selectedHarness.developmentChannelEligible !== true) return finish("blocked", "blocked: prompt consent absent");
|
|
155
|
+
const expected = screen;
|
|
156
|
+
if (!exact(capture(target), expected)) return finish("blocked", "blocked: prompt changed before input");
|
|
157
|
+
const fields = { signatureId: fixture.id, version: fixture.version, platform: fixture.platform,
|
|
158
|
+
signatureDigest: digest(expected.text), class: klass, key: "Enter" };
|
|
159
|
+
if (!record({ ...fields, status: "attempted" })) {
|
|
160
|
+
terminal = { status: "incomplete", answers: answers.map(a => ({ ...a })), reason: "launch prompt audit failed", receipt: receipts };
|
|
161
|
+
return terminal;
|
|
162
|
+
}
|
|
163
|
+
// Durable intent may take time or run hooks. Revalidate the visible
|
|
164
|
+
// signature, PID and home again after it and immediately before input.
|
|
165
|
+
if (!exact(capture(target), expected)) return finish("blocked", "blocked: prompt changed before input", fields);
|
|
166
|
+
let outcome = "uncertain";
|
|
167
|
+
try {
|
|
168
|
+
checkAuthority();
|
|
169
|
+
const sent = transport.send(target, "Enter", remaining());
|
|
170
|
+
outcome = sent?.status === "submitted" ? "submitted" : sent?.status === "failed" ? "failed" : "uncertain";
|
|
171
|
+
} catch { /* A thrown send might already have delivered the key. */ }
|
|
172
|
+
if (!record({ ...fields, status: outcome })) {
|
|
173
|
+
terminal = { status: "incomplete", answers: answers.map(a => ({ ...a })), reason: "launch prompt audit failed after possible input", receipt: receipts };
|
|
174
|
+
return terminal;
|
|
175
|
+
}
|
|
176
|
+
if (outcome !== "submitted") return finish("incomplete", `launch prompt input ${outcome}`, fields);
|
|
177
|
+
answers.push({ class: klass, signatureId: fixture.id, status: "submitted" });
|
|
178
|
+
sleep(Math.min(INTERVAL, remaining()));
|
|
179
|
+
}
|
|
180
|
+
return finish("blocked", "blocked: observation timeout");
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (error?.geometryRestored || error?.geometryRestoreFailed) record({ action: "restore-geometry", status: error.geometryRestored ? "submitted" : "failed", reason: "partial pin rollback", signatureDigest: digest(lastText) });
|
|
183
|
+
if (error?.geometryRestoreFailed) return finish("incomplete", "launch prompt geometry restoration incomplete");
|
|
184
|
+
return finish("blocked", error?.message === "observation timeout" ? "blocked: observation timeout" : "blocked: launch observation failed");
|
|
185
|
+
} finally {
|
|
186
|
+
if (resizeToken) {
|
|
187
|
+
// Restoration is cleanup of our own bounded mutation. Attempt it even
|
|
188
|
+
// when auditing failed or the observation deadline expired; the adapter
|
|
189
|
+
// independently refuses a replaced process/window before touching it.
|
|
190
|
+
const fields = { action: "restore-geometry", previous: resizeToken.previous, signatureDigest: digest(lastText) };
|
|
191
|
+
let audited = record({ ...fields, status: "attempted" });
|
|
192
|
+
let restored = false;
|
|
193
|
+
try { restored = transport.restore(target, resizeToken, 3000)?.status === "restored"; } catch { /* retained incomplete below */ }
|
|
194
|
+
audited = record({ ...fields, status: restored ? "submitted" : "failed" }) && audited;
|
|
195
|
+
if (!restored || !audited) incompleteCleanup();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
captureBeforeRespawn(t) {
|
|
201
|
+
if (used) return Object.freeze({ ok: false, reason: "launch authority already used" });
|
|
202
|
+
try {
|
|
203
|
+
const snapshot = capture({ ...t });
|
|
204
|
+
const token = Object.freeze({ ok: true });
|
|
205
|
+
tokens.set(token, snapshot);
|
|
206
|
+
return token;
|
|
207
|
+
} catch { return Object.freeze({ ok: false, reason: "prior pane capture failed" }); }
|
|
208
|
+
},
|
|
209
|
+
observeNew(t) { return observe(t); },
|
|
210
|
+
observeRespawn(t, token) {
|
|
211
|
+
const before = tokens.get(token);
|
|
212
|
+
tokens.delete(token);
|
|
213
|
+
return observe(t, before ?? null);
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Operator coverage (awebai/oats#671, #709): does a soul this workspace offers compose the operator
|
|
2
|
+
// capability, oats.setup, for the workspace and for each team? Detected by composition, never by a
|
|
3
|
+
// soul's name and never by a role marker (maintainer decision on #671). A warning only: readiness and
|
|
4
|
+
// doctor report it; nothing refuses, spawns or writes. An eligible soul is not a launched seat.
|
|
5
|
+
import * as remoteModule from "./remote.mjs";
|
|
6
|
+
import { disabledEntry, qualifiedSoulName, soulCandidates } from "./instance-resolution.mjs";
|
|
7
|
+
import { resolveSoul } from "./resolve.mjs";
|
|
8
|
+
|
|
9
|
+
export const OPERATOR_CAPABILITY = "oats.setup";
|
|
10
|
+
const SEAT = "an eligible soul is not a launched seat";
|
|
11
|
+
|
|
12
|
+
/** The Desktop refuses a whole readiness answer whose item `reason` or `remedy` is over 1024 characters
|
|
13
|
+
* (packages/desktop/renderer/readiness-contract.mjs): each detail is clipped, lists show three and a count,
|
|
14
|
+
* and every message and remedy stays under MAX_TEXT. */
|
|
15
|
+
export const MAX_TEXT = 900;
|
|
16
|
+
const DETAIL = 160;
|
|
17
|
+
export const clip = (text, max = DETAIL) => { const t = String(text ?? ""); return t.length > max ? `${t.slice(0, max - 1)}…` : t; };
|
|
18
|
+
const some = (list) => `${list.slice(0, 3).join("; ")}${list.length > 3 ? `; and ${list.length - 3} more` : ""}`;
|
|
19
|
+
|
|
20
|
+
const obj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
21
|
+
/** A source this machine could not read (an access, network or cache miss), as opposed to one the kernel refuses. */
|
|
22
|
+
const unreadable = (e) => e?.code === "E_REMOTE_UNREADABLE";
|
|
23
|
+
/** Does the soul's own declaration name the operator capability (for the remedy only, never for coverage)? */
|
|
24
|
+
const declaresOperator = (entry) => obj(entry?.definition?.capabilities) && Object.hasOwn(entry.definition.capabilities, OPERATOR_CAPABILITY);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The coverage of the workspace and of `teams` (labels), from one discovery. A soul covers when it is
|
|
28
|
+
* offered (soulCandidates), not disabled here (souls.disabled), resolves as a spawn would (resolveSoul),
|
|
29
|
+
* composes oats.setup, and empties no layer slot the workspace selects (no `slot-none` in turnedOff:
|
|
30
|
+
* the operator keeps the workspace's chosen core, messaging and knowledge). It covers a team when the
|
|
31
|
+
* team is among its resolved teams. Souls are resolved in turn until every question is answered.
|
|
32
|
+
*
|
|
33
|
+
* → { known: true, workspace: { covered, by }, teams: [{ label, covered, by }], excluded: [{ soul, code, slots? }] }
|
|
34
|
+
* | { known: false, reason }
|
|
35
|
+
* A covering soul found is reported whatever else could not be read. Absence is reported only when every
|
|
36
|
+
* source was read: unknown when there is no discovery, when it is the member-only view of an unreadable
|
|
37
|
+
* host, or when a question stays open and a source could not be read (a member discovery dropped as
|
|
38
|
+
* cannot-read, a soul file or listing it could not read, a resolution that hit E_REMOTE_UNREADABLE).
|
|
39
|
+
* Any other refusal is the soul's (a spawn would meet it too): not covering. Never throws.
|
|
40
|
+
*/
|
|
41
|
+
export async function operatorCoverage({ discovery, local = null, lock = null, teams = [], remoteOptions, remote } = {}) {
|
|
42
|
+
try {
|
|
43
|
+
if (!discovery) return { known: false, reason: "the workspace was not read" };
|
|
44
|
+
if (discovery.standalone === true && discovery.standaloneReason !== "explicit") {
|
|
45
|
+
return { known: false, reason: "only this member was read: its workspace host is not readable here, so the souls it offers are not known" };
|
|
46
|
+
}
|
|
47
|
+
const wanted = [...new Set(teams.filter((l) => typeof l === "string"))];
|
|
48
|
+
const by = { workspace: null, teams: new Map() };
|
|
49
|
+
const excluded = [];
|
|
50
|
+
// What discovery could not read: it drops such a member or soul and carries on.
|
|
51
|
+
const missed = [
|
|
52
|
+
...(discovery.members || []).filter((m) => m.confirmed === false && m.reason === "cannot-read").map((m) => clip(m.detail || `member ${m.key}`)),
|
|
53
|
+
...(discovery.problems || []).filter(unreadable).map((p) => clip(p.message || p.path)),
|
|
54
|
+
];
|
|
55
|
+
const done = () => by.workspace !== null && wanted.every((l) => by.teams.has(l));
|
|
56
|
+
for (const { entry } of soulCandidates(discovery)) {
|
|
57
|
+
if (done()) break;
|
|
58
|
+
const soul = qualifiedSoulName(entry);
|
|
59
|
+
const refuse = (code) => { if (declaresOperator(entry)) excluded.push({ soul, code }); };
|
|
60
|
+
if (disabledEntry(local, entry) !== null) { refuse("E_SOUL_DISABLED"); continue; }
|
|
61
|
+
if (Array.isArray(entry.collides)) { refuse("E_SOUL_AMBIGUOUS"); continue; }
|
|
62
|
+
let res;
|
|
63
|
+
try { res = await resolveSoul(discovery, entry, { local, lock, spawn: {}, remoteOptions, remote }); }
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (unreadable(e)) { missed.push(clip(`${soul}: ${e.message}`)); continue; }
|
|
66
|
+
if (typeof e?.code === "string" && e.code.startsWith("E_")) { refuse(e.code); continue; }
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
if (!(res.modules || []).some((m) => m.name === OPERATOR_CAPABILITY)) continue;
|
|
70
|
+
const emptied = (res.turnedOff || []).filter((o) => o.reason === "slot-none");
|
|
71
|
+
if (emptied.length) { excluded.push({ soul, code: "slot-none", slots: emptied.map((o) => o.slot) }); continue; }
|
|
72
|
+
by.workspace ??= soul;
|
|
73
|
+
for (const t of res.teams || []) if (wanted.includes(t.label) && !by.teams.has(t.label)) by.teams.set(t.label, soul);
|
|
74
|
+
}
|
|
75
|
+
if (!done() && missed.length) {
|
|
76
|
+
return { known: false, reason: `not every source could be read (${some(missed)})` };
|
|
77
|
+
}
|
|
78
|
+
return { known: true, workspace: { covered: by.workspace !== null, by: by.workspace },
|
|
79
|
+
teams: wanted.map((label) => ({ label, covered: by.teams.has(label), by: by.teams.get(label) ?? null })), excluded };
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return { known: false, reason: `operator coverage could not be computed: ${clip(e?.message ?? e)}` };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The warnings a coverage answer carries, as `{ code, label?, message, remedy, excluded? }` (`excluded`, the
|
|
86
|
+
* workspace-wide list, on the workspace warning only); one `operator-coverage-unknown` (its remedy
|
|
87
|
+
* `unknownRemedy`) when it is not known, never an absence; none when everything is covered. */
|
|
88
|
+
export function operatorProblems(coverage, { workspace = null, unknownRemedy = "oats sync, then oats souls" } = {}) {
|
|
89
|
+
if (!coverage?.known) return [{ code: "operator-coverage-unknown", message: clip(`operator coverage unknown: ${clip(coverage?.reason ?? "not computed", 700)}; this says nothing about whether an operator soul exists`, MAX_TEXT), remedy: clip(unknownRemedy, MAX_TEXT) }];
|
|
90
|
+
const named = workspace ? `workspace ${workspace}` : "this workspace";
|
|
91
|
+
const why = coverage.excluded.length ? ` (not usable here: ${some(coverage.excluded.map((x) => clip(`${x.soul} ${x.code}${x.slots ? ` ${x.slots.join(",")}` : ""}`)))})` : "";
|
|
92
|
+
const remedy = `give a soul the ${OPERATOR_CAPABILITY} capability in its soul.yaml (reviewed source), keeping the workspace's core, messaging and knowledge, then \`oats spawn <soul> --preview\``;
|
|
93
|
+
const out = [];
|
|
94
|
+
if (!coverage.workspace.covered) {
|
|
95
|
+
out.push({ code: "operator-soul-missing", message: clip(`no soul ${clip(named)} offers composes ${OPERATOR_CAPABILITY}, so it has no operator soul${why}; ${SEAT}`, MAX_TEXT), remedy, excluded: coverage.excluded });
|
|
96
|
+
}
|
|
97
|
+
for (const t of coverage.teams) {
|
|
98
|
+
if (t.covered) continue;
|
|
99
|
+
out.push({ code: "operator-team-uncovered", label: t.label, message: clip(`no soul composing ${OPERATOR_CAPABILITY} is eligible for team ${clip(t.label)}; ${SEAT}`, MAX_TEXT),
|
|
100
|
+
remedy: clip(`${remedy}, and let it join ${clip(t.label)} (the workspace's souls:)`, MAX_TEXT) });
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The remote contract answered from this machine's cache only (offline doctor): the head a repository was
|
|
107
|
+
* last observed at (lastObservedCommit) and the parsed values kept at that commit (peekAtCommit). Never a
|
|
108
|
+
* git process, never the network: any read the cache cannot answer is E_REMOTE_UNREADABLE, which
|
|
109
|
+
* operatorCoverage reports as unknown. The miss carries no access reason, so it is never taken for an
|
|
110
|
+
* unreadable host (no standalone fallback).
|
|
111
|
+
*/
|
|
112
|
+
export function cacheOnlyRemote() {
|
|
113
|
+
const miss = (what) => Object.assign(new Error(`not in this machine's cache: ${what} (run oats sync)`), { code: "E_REMOTE_UNREADABLE" });
|
|
114
|
+
return {
|
|
115
|
+
parseRepoRef: remoteModule.parseRepoRef,
|
|
116
|
+
observeRemote: async (ref, { at, ...options } = {}) => {
|
|
117
|
+
const commit = remoteModule.lastObservedCommit(ref, { at, ...options });
|
|
118
|
+
if (!commit) throw miss(`the last observed head of ${ref}`);
|
|
119
|
+
const p = remoteModule.parseRepoRef(ref, options);
|
|
120
|
+
return { key: p.key, url: p.url, commit, ref: null, observedAt: null };
|
|
121
|
+
},
|
|
122
|
+
memoAtCommit: async (ref, commit, item, _compute, options = {}) => {
|
|
123
|
+
const value = remoteModule.peekAtCommit(ref, commit, item, options);
|
|
124
|
+
if (value === undefined) throw miss(`${String(item).split("\0")[0]} of ${ref}`);
|
|
125
|
+
return value;
|
|
126
|
+
},
|
|
127
|
+
lastObservedCommit: remoteModule.lastObservedCommit,
|
|
128
|
+
peekAtCommit: remoteModule.peekAtCommit,
|
|
129
|
+
readRemoteFile: async (ref, _commit, path) => { throw miss(`${path} of ${ref}`); },
|
|
130
|
+
listRemoteTree: async (ref, _commit, dir) => { throw miss(`${dir} of ${ref}`); },
|
|
131
|
+
listRemoteFiles: async (ref, _commit, dir) => { throw miss(`${dir} of ${ref}`); },
|
|
132
|
+
fetchRemoteTree: async (ref, _commit, dir) => { throw miss(`${dir} of ${ref}`); },
|
|
133
|
+
};
|
|
134
|
+
}
|
package/lib/remote.mjs
CHANGED
|
@@ -1158,16 +1158,20 @@ function writeObservation(root, ref, atArgs, obs) {
|
|
|
1158
1158
|
|
|
1159
1159
|
/** The COMMIT <oid> peels to, when <oid> is present in the cache and is a commit or an
|
|
1160
1160
|
* annotated tag chain ending in one; null on a missing object, a pruned store, or a
|
|
1161
|
-
* tag/tree/blob that does not peel to a commit. (`rev-parse <oid>^{commit}` peels.)
|
|
1161
|
+
* tag/tree/blob that does not peel to a commit. (`rev-parse <oid>^{commit}` peels.)
|
|
1162
|
+
* A peel git did not finish in time (`timedOut`: its timer, which a deadline cuts, or no time
|
|
1163
|
+
* left to start it) answered nothing: that is thrown, never taken for a missing commit (#728). */
|
|
1162
1164
|
async function peelCommit(repo, oid) {
|
|
1163
1165
|
try {
|
|
1164
1166
|
const out = (await repo.local(["rev-parse", "--verify", "-q", `${oid}^{commit}`])).stdout.toString("utf8").trim();
|
|
1165
1167
|
return OID_RE.test(out) ? out : null;
|
|
1166
|
-
} catch { return null; }
|
|
1168
|
+
} catch (error) { if (error?.timedOut) throw error; return null; }
|
|
1167
1169
|
}
|
|
1168
1170
|
|
|
1171
|
+
/** The type of <oid> in the cache, null when it is absent; a timed-out read is thrown (as peelCommit's). */
|
|
1169
1172
|
async function objectType(repo, oid) {
|
|
1170
|
-
try { return (await repo.local(["cat-file", "-t", oid])).stdout.toString("utf8").trim(); }
|
|
1173
|
+
try { return (await repo.local(["cat-file", "-t", oid])).stdout.toString("utf8").trim(); }
|
|
1174
|
+
catch (error) { if (error?.timedOut) throw error; return null; }
|
|
1171
1175
|
}
|
|
1172
1176
|
|
|
1173
1177
|
/**
|
|
@@ -1185,6 +1189,9 @@ async function ensureCommit(ref, oid, options) {
|
|
|
1185
1189
|
const known = session?.peels.get(`${dir}\0${oid}`);
|
|
1186
1190
|
if (known) return { repo: repoHandle(dir, options.exec ?? runGit, session), commit: known };
|
|
1187
1191
|
const remember = (commit) => { if (session) { session.peels.set(`${dir}\0${oid}`, commit); session.peels.set(`${dir}\0${commit}`, commit); } return commit; };
|
|
1192
|
+
// A cache read the clock ended is the read's timeout, judged by git's own result (`timedOut`), never by the wall
|
|
1193
|
+
// clock: git's timer can fire a moment before Date.now() reaches the deadline (#728).
|
|
1194
|
+
const asReadTimeout = (repo, read) => read.catch((error) => { throw unreadable(ref, error, { commit: oid, cacheDir: repo.dir, stage: "fetch" }); });
|
|
1188
1195
|
return withCacheLock(dir, async () => {
|
|
1189
1196
|
// Already present (the common case): a read, so no write lock.
|
|
1190
1197
|
let peeled = false; // the object store was asked already, and said no
|
|
@@ -1192,7 +1199,7 @@ async function ensureCommit(ref, oid, options) {
|
|
|
1192
1199
|
if (!existsSync(join(dir, "HEAD")) || toRebuild(dir, session)) return null;
|
|
1193
1200
|
if (!keepsPartialCache(await readVersion(repo, ref)) && await fetchMode(repo) === "partial") return null;
|
|
1194
1201
|
peeled = true;
|
|
1195
|
-
return peelCommit(repo, oid);
|
|
1202
|
+
return asReadTimeout(repo, peelCommit(repo, oid));
|
|
1196
1203
|
};
|
|
1197
1204
|
const present = await usable(repoHandle(dir, options.exec ?? runGit, session));
|
|
1198
1205
|
if (present) return { repo: repoHandle(dir, options.exec ?? runGit, session), commit: remember(present) };
|
|
@@ -1204,7 +1211,7 @@ async function ensureCommit(ref, oid, options) {
|
|
|
1204
1211
|
// A partial cache is only safe where git cannot fetch a missing blob on its own: an older git rebuilds it whole.
|
|
1205
1212
|
if (!keepsPartialCache(version) && await fetchMode(repo) === "partial") repo = await rebuildWhole(repo, ref, options, version);
|
|
1206
1213
|
if (toRebuild(repo.dir, session)) repo = await freshCache(repo, ref, options);
|
|
1207
|
-
const cached = peeled && !waited ? null : await peelCommit(repo, oid);
|
|
1214
|
+
const cached = peeled && !waited ? null : await asReadTimeout(repo, peelCommit(repo, oid));
|
|
1208
1215
|
if (cached) return { repo, commit: remember(cached) }; // pinned AND present AND (peels to) a commit
|
|
1209
1216
|
const mode = await fetchMode(repo)
|
|
1210
1217
|
?? (keepsPartialCache(version) ? await startPartialFetches(repo, ref) : await recordFullFetches(repo, ref, olderGitNotice(version, ref)));
|
|
@@ -1212,11 +1219,10 @@ async function ensureCommit(ref, oid, options) {
|
|
|
1212
1219
|
const { stderr } = await fetchInto(repo, ref, ["fetch", "-q", "--depth", "1", "--no-tags", "--no-recurse-submodules", ...filter, "origin", oid], { what: oid, commit: oid });
|
|
1213
1220
|
// A server without filters says so and sends the whole tree: nothing is lost, the cache remembers.
|
|
1214
1221
|
if (mode === "partial" && /filtering not recognized by server/i.test(stderr.toString("utf8"))) await recordFullFetches(repo, ref);
|
|
1215
|
-
const commit = await peelCommit(repo, oid);
|
|
1222
|
+
const commit = await asReadTimeout(repo, peelCommit(repo, oid));
|
|
1216
1223
|
if (!commit) {
|
|
1217
|
-
//
|
|
1218
|
-
|
|
1219
|
-
const type = await objectType(repo, oid);
|
|
1224
|
+
// The peel answered: the object is missing or not a commit (a peel the deadline ended was thrown above).
|
|
1225
|
+
const type = await asReadTimeout(repo, objectType(repo, oid));
|
|
1220
1226
|
throw fail("E_REMOTE_UNREADABLE", `${oid} in ${ref.url} is ${type ? `a ${type}` : "missing"}, not a commit`, { url: ref.url, key: ref.key, reason: "not-found", commit: oid, type });
|
|
1221
1227
|
}
|
|
1222
1228
|
await writePin(repo, ref, pinRef(commit), commit, commit);
|
package/lib/schedule.mjs
CHANGED
|
@@ -34,7 +34,7 @@ import { herdrSettingRemoved } from "./errors.mjs";
|
|
|
34
34
|
import { withDirLock as withSharedDirLock } from "./dir-lock.mjs";
|
|
35
35
|
import { tickTriggers } from "./triggers.mjs";
|
|
36
36
|
import { resolveMemberClone } from "./instance-resolution.mjs";
|
|
37
|
-
import { SCHEDULE_NAME_RE, readSnapshot, MODEL_RE, automationContext, automationError, baseRow, localEntry, localId, soulOriginOf, splitId, validateDescription } from "./automations.mjs";
|
|
37
|
+
import { SCHEDULE_NAME_RE, HOST_NAME_RE, readSnapshot, hostOf, trusted, parseOwner, MODEL_RE, automationContext, automationError, baseRow, localEntry, localId, soulOriginOf, splitId, validateDescription } from "./automations.mjs";
|
|
38
38
|
import { RESERVED_LAUNCH_ENV, MAX_INSTANCE_NAME, shq, findAgent, findInstanceHomes, inspectInstanceSession, inputInstanceSession, startInstanceSession, retirePendingMarkerPath } from "./core.mjs";
|
|
39
39
|
|
|
40
40
|
export const SCHEDULE_FILE = "oats-schedules.json";
|
|
@@ -1037,11 +1037,35 @@ function namedHomes(ws, js) {
|
|
|
1037
1037
|
return instance ? findHomesInScope(ws, instance).map((home) => ({ instance, home })) : [];
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
|
-
/**
|
|
1041
|
-
*
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1040
|
+
/** Offline guidance only: saved placement can prove an exclusion, never current
|
|
1041
|
+
* authorization. In particular, do not call placementOf here: it probes gh. */
|
|
1042
|
+
function workspaceReconcileRemedy(id, snapshot, local, localError) {
|
|
1043
|
+
const preserve = "Preserve the retained state and inspect its effects with the deployment owner; this diagnostic does not clear attempts or slots.";
|
|
1044
|
+
let unknown, excluded;
|
|
1045
|
+
const entries = snapshot?.schedules;
|
|
1046
|
+
const matches = entries?.filter((entry) => entry?.id === id) || [];
|
|
1047
|
+
const entry = matches[0];
|
|
1048
|
+
if (localError) unknown = `local configuration is invalid or unreadable (${localError.code || "read error"})`;
|
|
1049
|
+
else if (!snapshot) unknown = "the saved automation snapshot is missing, invalid or unreadable";
|
|
1050
|
+
else if (entries.some((e) => !e || typeof e.id !== "string") || matches.length > 1) unknown = "the saved automation snapshot is invalid";
|
|
1051
|
+
else if (!entry) excluded = "the definition is missing from the saved snapshot (this is not proof of remote deletion)";
|
|
1052
|
+
else if (entry.invalid || shapeError(entry.definition) || typeof entry.runsOn !== "string" || !HOST_NAME_RE.test(entry.runsOn)
|
|
1053
|
+
|| (entry.enabled !== undefined && typeof entry.enabled !== "boolean") || !parseOwner(entry.owner)) unknown = "the saved schedule definition is invalid or incomplete";
|
|
1054
|
+
else {
|
|
1055
|
+
const host = hostOf(local);
|
|
1056
|
+
if (entry.enabled === false || host.disabled.schedule.has(id)) excluded = "the schedule is disabled in the saved definition or local schedules.disabled";
|
|
1057
|
+
else if (!host.name) excluded = "local host.name is not configured";
|
|
1058
|
+
else if (entry.runsOn !== host.name) excluded = `the saved schedule is assigned elsewhere (${entry.runsOn}); this host is ${host.name}`;
|
|
1059
|
+
else if (!trusted(host, id)) excluded = "the schedule is untrusted by local automations.trust";
|
|
1060
|
+
}
|
|
1061
|
+
if (excluded) return `Retained-state reconciliation is currently unavailable under this placement: ${excluded}. ${preserve}`;
|
|
1062
|
+
if (unknown) return `Workspace authorization cannot be verified offline: ${unknown}. ${preserve}`;
|
|
1063
|
+
return `Current workspace authorization is unverified offline; reconciliation requires current host, owner and trust authorization. ${preserve}`;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/** `oats doctor`: retained launch attempts and unknown last observations, in this
|
|
1067
|
+
* deployment and the other scopes sharing its slots. Reads saved state only;
|
|
1068
|
+
* workspace guidance cannot promise authorization or an executable recovery. */
|
|
1045
1069
|
export function unresolvedScheduleAttempts(dep, { now = new Date() } = {}) {
|
|
1046
1070
|
const problems = [], information = [];
|
|
1047
1071
|
const here = resolve(dep);
|
|
@@ -1054,7 +1078,14 @@ export function unresolvedScheduleAttempts(dep, { now = new Date() } = {}) {
|
|
|
1054
1078
|
catch (e) { information.push(`the schedules of ${ws} could not be read: ${e.message}`); continue; }
|
|
1055
1079
|
// Read the last discovery snapshot directly: placement and refresh would
|
|
1056
1080
|
// require credentials/network, and unresolved work matters even when offline.
|
|
1057
|
-
const
|
|
1081
|
+
const snapshot = readSnapshot(ws);
|
|
1082
|
+
const workspaceKinds = new Map((snapshot?.schedules || []).filter((entry) => entry && typeof entry.id === "string").map((entry) => [entry.id, entry.definition?.kind]));
|
|
1083
|
+
let local, localError;
|
|
1084
|
+
try {
|
|
1085
|
+
const found = loadLocal(ws);
|
|
1086
|
+
if (resolve(dirname(found.path)) !== resolve(ws)) throw scheduleError("E_LOCAL_MISSING", "this scope has no local configuration");
|
|
1087
|
+
local = found.local;
|
|
1088
|
+
} catch (e) { localError = e; }
|
|
1058
1089
|
for (const [key, js] of Object.entries(st.jobs)) {
|
|
1059
1090
|
if (!js?.attempt && js?.lastRun?.outcome !== "unknown") continue;
|
|
1060
1091
|
// A workspace schedule's state key is <member>~<id> (scheduleStateKey); a local one is its id.
|
|
@@ -1066,12 +1097,28 @@ export function unresolvedScheduleAttempts(dep, { now = new Date() } = {}) {
|
|
|
1066
1097
|
const startedAt = js.attempt?.startedAt ?? js.lastRun?.startedAt ?? null;
|
|
1067
1098
|
const started = Date.parse(startedAt);
|
|
1068
1099
|
const ageSeconds = Number.isNaN(started) ? null : Math.max(0, Math.floor((now.getTime() - started) / 1000));
|
|
1069
|
-
const
|
|
1100
|
+
const lock = jobLockInfo(ws, key);
|
|
1101
|
+
const holdsSlot = !!lock;
|
|
1070
1102
|
const error = js.attempt?.error ?? js.lastRun?.error ?? null;
|
|
1071
1103
|
const unproven = (kind === "command" || kind === "operation") && namedHomes(ws, js).length !== 1;
|
|
1072
1104
|
const dir = ws === here ? "" : ` --dir ${/^[\w./@%+=:,-]+$/.test(ws) ? ws : shq(ws)}`;
|
|
1073
|
-
|
|
1074
|
-
|
|
1105
|
+
let unavailable = localError ? `local configuration is invalid or unreadable (${localError.code || "read error"})` : null;
|
|
1106
|
+
if (!workspace && !unavailable) {
|
|
1107
|
+
unavailable = !SCHEDULE_ID_RE.test(id) ? "the stored schedule ID is invalid" : shapeError(defs.jobs[key]);
|
|
1108
|
+
if (!unavailable && defs.jobs[key].id !== undefined && defs.jobs[key].id !== key) unavailable = "the stored definition has a different ID";
|
|
1109
|
+
try { validateAttemptExecution(js.attempt || { execution: js.lastRun?.execution }, lock); }
|
|
1110
|
+
catch { unavailable ||= "the retained attempt or lock uses unsupported captured execution state"; }
|
|
1111
|
+
if (lock?.unreadable) unavailable ||= "job lock custody is unreadable";
|
|
1112
|
+
}
|
|
1113
|
+
const remedy = workspace ? workspaceReconcileRemedy(id, snapshot, local, localError)
|
|
1114
|
+
: unavailable ? `Doctor does not recommend reconciling this job because ${unavailable}; preserve the retained state and inspect its effects with the deployment owner.`
|
|
1115
|
+
: `oats schedule reconcile ${id}${unproven ? " --clear" : ""}${dir}`;
|
|
1116
|
+
const subject = js.attempt ? `${kind ? `a ${kind}` : "a"} launch attempt for ${scheduledFor} has no recorded result`
|
|
1117
|
+
: `the last ${kind || "schedule"} run for ${scheduledFor} has an unknown observation`;
|
|
1118
|
+
const blocking = js.attempt ? "This persisted attempt blocks another run until it is reconciled"
|
|
1119
|
+
: "There is no persisted launch attempt blocking execution; an eligible tick may re-observe the last run, without a guarantee of clearance";
|
|
1120
|
+
const guidance = workspace || unavailable ? remedy : unproven ? `Its effects can't be proven: check the roster and the host by hand, then run ${remedy}` : `Run ${remedy}`;
|
|
1121
|
+
const message = `schedule ${id}${ws === here ? "" : ` (in ${ws})`}: ${subject} (started ${startedAt}${ageSeconds === null ? "" : `, ${formatAge(ageSeconds)} ago`})${error ? `: ${error}` : ""}. ${blocking}, and ${holdsSlot ? "it holds a host slot (counted against maxConcurrent)" : "it holds no host slot"}. ${guidance}`;
|
|
1075
1122
|
problems.push({ code: "schedule-unresolved", severity: "warning", scope: ws, id, kind, scheduledFor, startedAt, ageSeconds, holdsSlot, exited: js.attempt?.exited === true, error, remedy, message });
|
|
1076
1123
|
}
|
|
1077
1124
|
}
|