@overcy/hive 0.0.0-stage → 0.2.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 +213 -2
- package/dist/api.d.ts +31 -0
- package/dist/api.js +83 -0
- package/dist/atomic.d.ts +1 -0
- package/dist/atomic.js +24 -0
- package/dist/binding.d.ts +5 -0
- package/dist/binding.js +16 -0
- package/dist/bootstrap/deps.d.ts +3 -0
- package/dist/bootstrap/deps.js +35 -0
- package/dist/bootstrap/doctor.d.ts +29 -0
- package/dist/bootstrap/doctor.js +80 -0
- package/dist/bootstrap/engine.d.ts +29 -0
- package/dist/bootstrap/engine.js +160 -0
- package/dist/bootstrap/forwarder.d.ts +11 -0
- package/dist/bootstrap/forwarder.js +30 -0
- package/dist/bootstrap/identity.d.ts +7 -0
- package/dist/bootstrap/identity.js +52 -0
- package/dist/bootstrap/index.d.ts +36 -0
- package/dist/bootstrap/index.js +40 -0
- package/dist/bootstrap/kit.d.ts +9 -0
- package/dist/bootstrap/kit.js +56 -0
- package/dist/bootstrap/manifest.d.ts +73 -0
- package/dist/bootstrap/manifest.js +309 -0
- package/dist/bootstrap/model-access.d.ts +43 -0
- package/dist/bootstrap/model-access.js +74 -0
- package/dist/bootstrap/pin.d.ts +2 -0
- package/dist/bootstrap/pin.js +16 -0
- package/dist/bootstrap/plan.d.ts +49 -0
- package/dist/bootstrap/plan.js +69 -0
- package/dist/bootstrap/prompt.d.ts +3 -0
- package/dist/bootstrap/prompt.js +35 -0
- package/dist/bootstrap/registry.d.ts +85 -0
- package/dist/bootstrap/registry.js +38 -0
- package/dist/bootstrap/secrets.d.ts +11 -0
- package/dist/bootstrap/secrets.js +105 -0
- package/dist/bootstrap/steps/agents.d.ts +9 -0
- package/dist/bootstrap/steps/agents.js +75 -0
- package/dist/bootstrap/steps/auth.d.ts +8 -0
- package/dist/bootstrap/steps/auth.js +138 -0
- package/dist/bootstrap/steps/cron.d.ts +7 -0
- package/dist/bootstrap/steps/cron.js +74 -0
- package/dist/bootstrap/steps/drift.d.ts +5 -0
- package/dist/bootstrap/steps/drift.js +67 -0
- package/dist/bootstrap/steps/env.d.ts +6 -0
- package/dist/bootstrap/steps/env.js +108 -0
- package/dist/bootstrap/steps/files.d.ts +7 -0
- package/dist/bootstrap/steps/files.js +28 -0
- package/dist/bootstrap/steps/lanes.d.ts +14 -0
- package/dist/bootstrap/steps/lanes.js +153 -0
- package/dist/bootstrap/steps/model-access.d.ts +10 -0
- package/dist/bootstrap/steps/model-access.js +122 -0
- package/dist/bootstrap/steps/preflight.d.ts +3 -0
- package/dist/bootstrap/steps/preflight.js +49 -0
- package/dist/bootstrap/steps/reporter.d.ts +12 -0
- package/dist/bootstrap/steps/reporter.js +155 -0
- package/dist/bootstrap/system.d.ts +5 -0
- package/dist/bootstrap/system.js +69 -0
- package/dist/bootstrap/types.d.ts +157 -0
- package/dist/bootstrap/types.js +14 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +23 -0
- package/dist/collect.d.ts +28 -0
- package/dist/collect.js +63 -0
- package/dist/commands/connect.d.ts +33 -0
- package/dist/commands/connect.js +306 -0
- package/dist/commands/doctor.d.ts +7 -0
- package/dist/commands/doctor.js +13 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +118 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +37 -0
- package/dist/commands/node-add.d.ts +7 -0
- package/dist/commands/node-add.js +56 -0
- package/dist/commands/node.d.ts +19 -0
- package/dist/commands/node.js +43 -0
- package/dist/commands/prEvents.d.ts +7 -0
- package/dist/commands/prEvents.js +32 -0
- package/dist/commands/setup.d.ts +15 -0
- package/dist/commands/setup.js +35 -0
- package/dist/commands/status.d.ts +18 -0
- package/dist/commands/status.js +71 -0
- package/dist/commands/threads.d.ts +6 -0
- package/dist/commands/threads.js +36 -0
- package/dist/config.d.ts +71 -0
- package/dist/config.js +121 -0
- package/dist/context.d.ts +26 -0
- package/dist/context.js +31 -0
- package/dist/crypto.d.ts +7 -0
- package/dist/crypto.js +50 -0
- package/dist/machine.d.ts +66 -0
- package/dist/machine.js +103 -0
- package/dist/node/cli.d.ts +25 -0
- package/dist/node/cli.js +130 -0
- package/dist/node/engine.d.ts +47 -0
- package/dist/node/engine.js +463 -0
- package/dist/node/ingress.d.ts +102 -0
- package/dist/node/ingress.js +473 -0
- package/dist/node/layout.d.ts +56 -0
- package/dist/node/layout.js +55 -0
- package/dist/node/leave.d.ts +8 -0
- package/dist/node/leave.js +32 -0
- package/dist/node/lock.d.ts +19 -0
- package/dist/node/lock.js +99 -0
- package/dist/node/modelAccess.d.ts +2 -0
- package/dist/node/modelAccess.js +44 -0
- package/dist/node/repair.d.ts +28 -0
- package/dist/node/repair.js +78 -0
- package/dist/node/services.d.ts +58 -0
- package/dist/node/services.js +171 -0
- package/dist/node/state.d.ts +127 -0
- package/dist/node/state.js +95 -0
- package/dist/node/steps.d.ts +74 -0
- package/dist/node/steps.js +158 -0
- package/dist/node/supervisor.d.ts +22 -0
- package/dist/node/supervisor.js +95 -0
- package/dist/node/tick.d.ts +47 -0
- package/dist/node/tick.js +278 -0
- package/dist/node/toolchain.d.ts +50 -0
- package/dist/node/toolchain.js +230 -0
- package/dist/nodeContract.d.ts +101 -0
- package/dist/nodeContract.js +192 -0
- package/dist/package.d.ts +3 -0
- package/dist/package.js +5 -0
- package/dist/prEvents.d.ts +109 -0
- package/dist/prEvents.js +374 -0
- package/dist/run.d.ts +19 -0
- package/dist/run.js +487 -0
- package/dist/specs/device-client.json +920 -0
- package/dist/threads.d.ts +88 -0
- package/dist/threads.js +268 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +35 -4
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { appendFileSync } from 'node:fs';
|
|
3
|
+
import { mkdir, readFile, rm } from 'node:fs/promises';
|
|
4
|
+
import { loadavg } from 'node:os';
|
|
5
|
+
import { ApiError } from "../api.js";
|
|
6
|
+
import { writeAtomic } from "../atomic.js";
|
|
7
|
+
import { diskUsedPercent } from "../collect.js";
|
|
8
|
+
import { planTick } from "../bootstrap/plan.js";
|
|
9
|
+
import { postOnce } from "../commands/connect.js";
|
|
10
|
+
import { parseReport, REPORT_SCHEMA } from "../nodeContract.js";
|
|
11
|
+
import { prEventsEnabled, pullPrEvents } from "../prEvents.js";
|
|
12
|
+
import { VERSION } from "../version.js";
|
|
13
|
+
import { settleCliSwap } from "./cli.js";
|
|
14
|
+
import { dropIngressSecrets } from "./ingress.js";
|
|
15
|
+
import { linkTarget } from "./services.js";
|
|
16
|
+
import { hostFacts, NODE_STEPS, nodeStep } from "./steps.js";
|
|
17
|
+
import { MAX_TRANSITIONS, readDesired, stateFor, writeRevoked, writeState } from "./state.js";
|
|
18
|
+
/** A report is posted when it changed, and at least this often. */
|
|
19
|
+
export const REPORT_REFRESH_MS = 10 * 60_000;
|
|
20
|
+
export async function readRequest(layout) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(await readFile(layout.repairRequest, 'utf8'));
|
|
23
|
+
return typeof parsed.id === 'string' ? { id: parsed.id, at: String(parsed.at ?? ''), by: String(parsed.by ?? '') } : { id: '', at: '', by: '' };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return null;
|
|
28
|
+
// An unreadable request still means someone asked. It is dropped after the tick like any other.
|
|
29
|
+
return { id: '', at: '', by: '' };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Removes the request this tick read. A request that arrived during the tick has another id and stays for the next. */
|
|
33
|
+
async function settleRequest(layout, handled) {
|
|
34
|
+
if (handled === null)
|
|
35
|
+
return;
|
|
36
|
+
const now = await readRequest(layout);
|
|
37
|
+
if (now !== null && now.id === handled.id)
|
|
38
|
+
await rm(layout.repairRequest, { force: true });
|
|
39
|
+
}
|
|
40
|
+
function wireTimestamp(date) {
|
|
41
|
+
return date.toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
42
|
+
}
|
|
43
|
+
function reportStatus(health, repaired, blocked) {
|
|
44
|
+
if (blocked)
|
|
45
|
+
return 'blocked';
|
|
46
|
+
switch (health) {
|
|
47
|
+
case 'ok':
|
|
48
|
+
return repaired ? 'repaired' : 'ok';
|
|
49
|
+
case 'skipped':
|
|
50
|
+
return null;
|
|
51
|
+
case 'stale':
|
|
52
|
+
case 'failing':
|
|
53
|
+
return 'failed';
|
|
54
|
+
case 'needs_action':
|
|
55
|
+
return 'needs';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function observeSafely(run, id) {
|
|
59
|
+
try {
|
|
60
|
+
return await nodeStep(id).observe(run);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (run.signal.aborted)
|
|
64
|
+
throw error;
|
|
65
|
+
return { status: 'failing', detail: `the check itself failed: ${error instanceof Error ? error.message : String(error)}`, fix: 'rerun_install' };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function repairSafely(run, id) {
|
|
69
|
+
const step = nodeStep(id);
|
|
70
|
+
if (step.repair === undefined)
|
|
71
|
+
return null;
|
|
72
|
+
try {
|
|
73
|
+
await step.repair(run);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (run.signal.aborted)
|
|
78
|
+
throw error;
|
|
79
|
+
return error instanceof ApiError ? `${error.message} (${error.code})` : error instanceof Error ? error.message : String(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function hashOf(report) {
|
|
83
|
+
// The send time and the vitals change on every tick. Neither makes a report worth posting by itself.
|
|
84
|
+
const { sent_at: _sent, vitals: _vitals, ...rest } = report;
|
|
85
|
+
return createHash('sha256').update(JSON.stringify(rest)).digest('hex');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One tick of the supervisor. The caller holds the state lock. Order:
|
|
89
|
+
*
|
|
90
|
+
* 1. heartbeat. A revoking answer ends the tick.
|
|
91
|
+
* 2. observe every step, then repair in order what `planTick` queues.
|
|
92
|
+
* 3. if the repairs changed the slots Hive asked for, heartbeat again, so the change shows within this tick.
|
|
93
|
+
* 4. run a full pass when Hive raised the `rerun_setup` counter, then save the counter.
|
|
94
|
+
* 5. write `report/report.json`, post it when it changed or is ten minutes old, and settle the repair request.
|
|
95
|
+
*/
|
|
96
|
+
export async function runTick(deps) {
|
|
97
|
+
const { ctx, layout, node, key, signal } = deps;
|
|
98
|
+
const state = await stateFor(layout, node.node_id);
|
|
99
|
+
const request = await readRequest(layout);
|
|
100
|
+
await holdForTest(ctx.env);
|
|
101
|
+
const desired = await readDesired(layout);
|
|
102
|
+
const running = await linkTarget(layout.cliCurrent);
|
|
103
|
+
settleCliSwap(state, running, desired, ctx.now());
|
|
104
|
+
const lanesDir = ctx.env.HIVE_LANES_DIR && ctx.env.HIVE_LANES_DIR !== '' ? ctx.env.HIVE_LANES_DIR : null;
|
|
105
|
+
// A heartbeat every minute is not news. The tick prints what it changes, and `postOnce` prints what a loop wants.
|
|
106
|
+
const quietCtx = { ...ctx, io: { out: () => undefined, err: ctx.io.err } };
|
|
107
|
+
const beat = (laneMax) => {
|
|
108
|
+
const floor = state.heartbeat_at === null ? 0 : Date.parse(state.heartbeat_at) + 1000;
|
|
109
|
+
const stamp = new Date(Math.max(ctx.now().getTime(), floor));
|
|
110
|
+
state.heartbeat_at = stamp.toISOString();
|
|
111
|
+
return postOnce(quietCtx, node, key, lanesDir, signal, laneMax, stamp);
|
|
112
|
+
};
|
|
113
|
+
const slotsSent = desired?.slots ?? null;
|
|
114
|
+
const first = await beat(desired?.slots);
|
|
115
|
+
if (first.state === 'revoked')
|
|
116
|
+
return revoke(deps, 'Hive revoked this node');
|
|
117
|
+
const run = { ctx, layout, node, key, signal, exec: deps.exec, state, heartbeat: first, desired, slotsSent, removed: false, probes: deps.probes, versions: {}, relay: null, cache: {} };
|
|
118
|
+
// PR events run beside the steps, so a slow T3 Code never delays them. Both finish before the tick does.
|
|
119
|
+
const events = prEventsEnabled(ctx.env) ? pullPrEvents(ctx, node, key, { signal }).catch((error) => ctx.io.err(`PR events failed: ${error instanceof Error ? error.message : String(error)}`)) : null;
|
|
120
|
+
const observations = new Map();
|
|
121
|
+
const observeAll = async () => {
|
|
122
|
+
for (const step of NODE_STEPS)
|
|
123
|
+
observations.set(step.id, await observeSafely(run, step.id));
|
|
124
|
+
};
|
|
125
|
+
const planNow = () => planTick(NODE_STEPS.map((step) => ({ id: step.id, status: observations.get(step.id).status })), NODE_STEPS);
|
|
126
|
+
await observeAll();
|
|
127
|
+
const initial = new Map(NODE_STEPS.map((step) => [step.id, observations.get(step.id).status]));
|
|
128
|
+
// Repairs run in step order. The plan is made again before each one, because an earlier repair that failed blocks
|
|
129
|
+
// the steps after it, and one that worked can change what they see.
|
|
130
|
+
const repaired = new Set();
|
|
131
|
+
for (const step of NODE_STEPS) {
|
|
132
|
+
const plan = planNow();
|
|
133
|
+
if (step.repair === undefined || plan.blocked.some((held) => held.id === step.id) || !plan.repairs.includes(step.id))
|
|
134
|
+
continue;
|
|
135
|
+
const failure = await repairSafely(run, step.id);
|
|
136
|
+
if (run.removed)
|
|
137
|
+
return revoke(deps, 'Hive removed this node');
|
|
138
|
+
if (failure !== null) {
|
|
139
|
+
observations.set(step.id, { status: 'failing', detail: failure, fix: observations.get(step.id)?.fix ?? 'rerun_install' });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
await observeAll();
|
|
143
|
+
if (observations.get(step.id)?.status === 'ok')
|
|
144
|
+
repaired.add(step.id);
|
|
145
|
+
}
|
|
146
|
+
const wantedGeneration = run.desired?.actions?.rerun_setup ?? 0;
|
|
147
|
+
if (wantedGeneration > run.state.generations.rerun_setup) {
|
|
148
|
+
// A full pass runs every repair, even for a step that looks healthy. The counter moves after it, never before.
|
|
149
|
+
// It also lifts a rollback, so a version the node went back from is tried once more.
|
|
150
|
+
run.state.cli.rejected = null;
|
|
151
|
+
run.state.engine.rejected = null;
|
|
152
|
+
run.state.toolchain.rejected = null;
|
|
153
|
+
run.state.toolchain.failed = null;
|
|
154
|
+
for (const step of NODE_STEPS) {
|
|
155
|
+
if (step.repair === undefined || planNow().blocked.some((held) => held.id === step.id))
|
|
156
|
+
continue;
|
|
157
|
+
const failure = await repairSafely(run, step.id);
|
|
158
|
+
if (run.removed)
|
|
159
|
+
return revoke(deps, 'Hive removed this node');
|
|
160
|
+
if (failure !== null) {
|
|
161
|
+
observations.set(step.id, { status: 'failing', detail: failure, fix: 'rerun_install' });
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
await observeAll();
|
|
165
|
+
if (observations.get(step.id)?.status === 'ok')
|
|
166
|
+
repaired.add(step.id);
|
|
167
|
+
}
|
|
168
|
+
run.state.generations.rerun_setup = wantedGeneration;
|
|
169
|
+
}
|
|
170
|
+
const blockedBy = new Map(planNow().blocked.map((held) => [held.id, held.by]));
|
|
171
|
+
let heartbeat = first;
|
|
172
|
+
const slotsNow = run.desired?.slots ?? null;
|
|
173
|
+
if (slotsNow !== null && slotsNow !== slotsSent && run.heartbeat.state === 'connected') {
|
|
174
|
+
heartbeat = await beat(slotsNow);
|
|
175
|
+
run.slotsSent = slotsNow;
|
|
176
|
+
if (heartbeat.state === 'revoked')
|
|
177
|
+
return revoke(deps, 'Hive revoked this node');
|
|
178
|
+
}
|
|
179
|
+
const now = ctx.now();
|
|
180
|
+
const steps = [];
|
|
181
|
+
for (const step of NODE_STEPS) {
|
|
182
|
+
const observation = observations.get(step.id);
|
|
183
|
+
const blocked = blockedBy.has(step.id);
|
|
184
|
+
// A repair counts as one when it fixed something that was broken. A routine refresh of a stale step does not.
|
|
185
|
+
const before = run.state.steps[step.id];
|
|
186
|
+
const wasBroken = initial.get(step.id) === 'failing' || before?.status === 'failed' || before?.status === 'needs' || before?.status === 'blocked';
|
|
187
|
+
const status = reportStatus(observation.status, repaired.has(step.id) && wasBroken, blocked);
|
|
188
|
+
if (status === null)
|
|
189
|
+
continue;
|
|
190
|
+
const detail = (blocked ? `waiting on ${blockedBy.get(step.id).join(', ')}` : observation.detail).slice(0, 500);
|
|
191
|
+
let since = before?.since ?? now.toISOString();
|
|
192
|
+
if (before === undefined || before.status !== status) {
|
|
193
|
+
since = now.toISOString();
|
|
194
|
+
run.state.transitions.push({ step: step.id, from: before?.status ?? null, to: status, detail, at: wireTimestamp(now) });
|
|
195
|
+
run.state.transitions = run.state.transitions.slice(-MAX_TRANSITIONS);
|
|
196
|
+
}
|
|
197
|
+
run.state.steps[step.id] = { status, since, detail };
|
|
198
|
+
const row = { id: step.id, status, detail, at: wireTimestamp(new Date(since)) };
|
|
199
|
+
if (status === 'failed' || status === 'needs')
|
|
200
|
+
row.fix = observation.fix ?? 'rerun_install';
|
|
201
|
+
steps.push(row);
|
|
202
|
+
}
|
|
203
|
+
// The release name is what desired state pins. Two dev builds share one package version.
|
|
204
|
+
const versions = { cli: running !== null && RELEASE_NAME.test(running) ? running : VERSION, node: process.versions.node };
|
|
205
|
+
for (const tool of Object.keys(run.versions))
|
|
206
|
+
versions[tool] = run.versions[tool];
|
|
207
|
+
if (run.state.engine.version !== null)
|
|
208
|
+
versions.engine = run.state.engine.version;
|
|
209
|
+
const [one = 0, five = 0, fifteen = 0] = loadavg();
|
|
210
|
+
const vitals = { load: [round2(one), round2(five), round2(fifteen)], disk_used_percent: await diskUsedPercent().catch(() => 0) };
|
|
211
|
+
if (run.relay !== null)
|
|
212
|
+
vitals.threads_relayed = run.relay.threads;
|
|
213
|
+
const document = parseReport({
|
|
214
|
+
schema: REPORT_SCHEMA,
|
|
215
|
+
sent_at: wireTimestamp(now),
|
|
216
|
+
applied_revision: run.state.applied_revision,
|
|
217
|
+
generations: run.state.generations,
|
|
218
|
+
host: await hostFacts(layout),
|
|
219
|
+
versions,
|
|
220
|
+
steps,
|
|
221
|
+
vitals,
|
|
222
|
+
transitions: run.state.transitions,
|
|
223
|
+
...(run.desired?.model_access ? { model_access: { method: run.desired.model_access.method } } : {}),
|
|
224
|
+
});
|
|
225
|
+
// The state is saved before the report goes out, so a counter is never echoed that a crash could still lose.
|
|
226
|
+
await writeState(layout, run.state);
|
|
227
|
+
await mkdir(layout.reportDir, { recursive: true, mode: 0o750 });
|
|
228
|
+
await writeAtomic(layout.reportFile, `${JSON.stringify(document, null, 2)}\n`, 0o640);
|
|
229
|
+
const hash = hashOf(document);
|
|
230
|
+
const due = run.state.posted === null || run.state.posted.hash !== hash || now.getTime() - Date.parse(run.state.posted.at) >= REPORT_REFRESH_MS;
|
|
231
|
+
let posted = false;
|
|
232
|
+
if (due && heartbeat.state === 'connected') {
|
|
233
|
+
try {
|
|
234
|
+
await ctx.api.json('POST', '/api/v0/nodes/me/report', { token: node.token, key, body: (skewMs) => ({ ...document, sent_at: wireTimestamp(new Date(now.getTime() + skewMs)) }), signal });
|
|
235
|
+
run.state.posted = { hash, at: now.toISOString() };
|
|
236
|
+
posted = true;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (signal.aborted)
|
|
240
|
+
throw error;
|
|
241
|
+
ctx.io.err(`Report not accepted, will retry: ${error instanceof ApiError ? `${error.message} (${error.code})` : error instanceof Error ? error.message : String(error)}`);
|
|
242
|
+
}
|
|
243
|
+
await writeState(layout, run.state);
|
|
244
|
+
}
|
|
245
|
+
await events;
|
|
246
|
+
await settleRequest(layout, request);
|
|
247
|
+
return { heartbeat, revoked: null, report: document, posted };
|
|
248
|
+
}
|
|
249
|
+
const RELEASE_NAME = /^[0-9A-Za-z][0-9A-Za-z._+-]{0,63}$/;
|
|
250
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
251
|
+
async function revoke(deps, reason) {
|
|
252
|
+
await writeRevoked(deps.layout, reason, deps.ctx.now());
|
|
253
|
+
await dropIngressSecrets(deps.layout);
|
|
254
|
+
deps.ctx.io.err(`${reason}. The node is stopped. Enroll again with a new registration token to bring it back.`);
|
|
255
|
+
return { heartbeat: { state: 'revoked', desiredRevision: null, error: reason }, revoked: reason, report: null, posted: false };
|
|
256
|
+
}
|
|
257
|
+
/** Test hook: `HIVE_NODE_TRACE_HOLD_MS` keeps a tick open that long, after it has read the repair request. */
|
|
258
|
+
async function holdForTest(env) {
|
|
259
|
+
const hold = Number(env.HIVE_NODE_TRACE_HOLD_MS ?? 0);
|
|
260
|
+
if (env.HIVE_NODE_TRACE && hold > 0)
|
|
261
|
+
await new Promise((resolve) => setTimeout(resolve, hold));
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Test hook. When `HIVE_NODE_TRACE` names a file, each tick appends `start <pid>` and `end <pid>`, so a test can
|
|
265
|
+
* prove that two processes never tick at the same time.
|
|
266
|
+
*/
|
|
267
|
+
export async function tracedTick(deps) {
|
|
268
|
+
const file = deps.ctx.env.HIVE_NODE_TRACE;
|
|
269
|
+
if (!file)
|
|
270
|
+
return runTick(deps);
|
|
271
|
+
appendFileSync(file, `start ${process.pid}\n`);
|
|
272
|
+
try {
|
|
273
|
+
return await runTick(deps);
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
appendFileSync(file, `end ${process.pid}\n`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Rejected } from './state.ts';
|
|
2
|
+
import type { NodeStep, TickRun } from './steps.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The `toolchain` step: the agent tools the engine runs. v1 installs Claude Code only, because the headline path is a
|
|
5
|
+
* BYOK Claude turn and the BYOK key is an Anthropic key. gh is for the lane kit's pull requests, and the lane kit is
|
|
6
|
+
* not on customer nodes in v1. Codex has no model access in v1. Both stay observed on PATH.
|
|
7
|
+
*
|
|
8
|
+
* Claude Code comes from npm as its per-arch package, `@anthropic-ai/claude-code-linux-<arch>`. Its tarball holds
|
|
9
|
+
* one self-contained `claude` binary and no install script, so no npm and no package script runs on the node. The
|
|
10
|
+
* tarball's sha512 is checked against the pin below before tar sees it.
|
|
11
|
+
*/
|
|
12
|
+
/** The one pin. `integrity` is npm's `dist.integrity` for each per-arch package, from registry.npmjs.org. */
|
|
13
|
+
export declare const CLAUDE_CODE: {
|
|
14
|
+
readonly version: "2.1.326";
|
|
15
|
+
readonly integrity: {
|
|
16
|
+
readonly arm64: "sha512-lZCCWXarB/1IeHkotI937eEdN4BCbVdWDdmejtlkbUO9M29rHjITtXW9BWCDFlxvo0GXsFogN0SFIJWgMelKLw==";
|
|
17
|
+
readonly x64: "sha512-RvNuaeMGfPGUyUGttVvhHgVUZ3B2L+Pgf336ImZLsPP2UQHYblewi47CPFLObqz+K6D++PLP1eAsDBLYko3w+g==";
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** The artifact name on Hive's dev channel, served from `claude-code-<arch>.tar.gz`. */
|
|
21
|
+
export declare const CLAUDE_ARTIFACT = "claude-code";
|
|
22
|
+
export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
23
|
+
/** The tools the step only looks for on PATH. */
|
|
24
|
+
export declare const OBSERVED_TOOLS: readonly ["gh", "codex"];
|
|
25
|
+
/** A version probe is kept this long, since a `--version` is not free. */
|
|
26
|
+
export declare const PROBE_TTL_MS: number;
|
|
27
|
+
/** After a failed download the step waits this long before it tries again, since the tarball is about 170 MB. */
|
|
28
|
+
export declare const RETRY_PACE_MS: number;
|
|
29
|
+
/** A tarball download that takes longer is cut off, so a stalled connection never holds up the tick and the engine step after it. */
|
|
30
|
+
export declare const DOWNLOAD_TIMEOUT_MS: number;
|
|
31
|
+
export type InstalledTool = {
|
|
32
|
+
version: string;
|
|
33
|
+
integrity: string;
|
|
34
|
+
};
|
|
35
|
+
export type ToolchainMemory = {
|
|
36
|
+
/** The Claude Code release `bin/tools/claude` points at, and the sha512 its tarball had. */
|
|
37
|
+
claude: InstalledTool | null;
|
|
38
|
+
/** A version whose tarball failed its sha512 or named another version. Not fetched again until the pin moves or Hive asks for a rerun of setup. */
|
|
39
|
+
rejected: Rejected | null;
|
|
40
|
+
/** The last failed attempt for any other reason, such as the network, so the next one waits `RETRY_PACE_MS`. */
|
|
41
|
+
failed: {
|
|
42
|
+
version: string;
|
|
43
|
+
at: string;
|
|
44
|
+
detail: string;
|
|
45
|
+
} | null;
|
|
46
|
+
};
|
|
47
|
+
export declare function initialToolchain(): ToolchainMemory;
|
|
48
|
+
/** The Claude Code version this node should run: Hive's `versions.toolchain.claude`, or the pin. Nothing before Hive pins an engine. */
|
|
49
|
+
export declare function wantedClaude(run: TickRun): string | null;
|
|
50
|
+
export declare const toolchainStep: NodeStep;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { chmod, mkdir, readdir, rename, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { download, isExecutable, linkTarget, nodeArch, requestArtifact, switchLink, unpack } from "./services.js";
|
|
4
|
+
/**
|
|
5
|
+
* The `toolchain` step: the agent tools the engine runs. v1 installs Claude Code only, because the headline path is a
|
|
6
|
+
* BYOK Claude turn and the BYOK key is an Anthropic key. gh is for the lane kit's pull requests, and the lane kit is
|
|
7
|
+
* not on customer nodes in v1. Codex has no model access in v1. Both stay observed on PATH.
|
|
8
|
+
*
|
|
9
|
+
* Claude Code comes from npm as its per-arch package, `@anthropic-ai/claude-code-linux-<arch>`. Its tarball holds
|
|
10
|
+
* one self-contained `claude` binary and no install script, so no npm and no package script runs on the node. The
|
|
11
|
+
* tarball's sha512 is checked against the pin below before tar sees it.
|
|
12
|
+
*/
|
|
13
|
+
/** The one pin. `integrity` is npm's `dist.integrity` for each per-arch package, from registry.npmjs.org. */
|
|
14
|
+
export const CLAUDE_CODE = {
|
|
15
|
+
version: '2.1.326',
|
|
16
|
+
integrity: {
|
|
17
|
+
arm64: 'sha512-lZCCWXarB/1IeHkotI937eEdN4BCbVdWDdmejtlkbUO9M29rHjITtXW9BWCDFlxvo0GXsFogN0SFIJWgMelKLw==',
|
|
18
|
+
x64: 'sha512-RvNuaeMGfPGUyUGttVvhHgVUZ3B2L+Pgf336ImZLsPP2UQHYblewi47CPFLObqz+K6D++PLP1eAsDBLYko3w+g==',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/** The artifact name on Hive's dev channel, served from `claude-code-<arch>.tar.gz`. */
|
|
22
|
+
export const CLAUDE_ARTIFACT = 'claude-code';
|
|
23
|
+
export const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
|
|
24
|
+
/** The tools the step only looks for on PATH. */
|
|
25
|
+
export const OBSERVED_TOOLS = ['gh', 'codex'];
|
|
26
|
+
/** A version probe is kept this long, since a `--version` is not free. */
|
|
27
|
+
export const PROBE_TTL_MS = 10 * 60_000;
|
|
28
|
+
/** After a failed download the step waits this long before it tries again, since the tarball is about 170 MB. */
|
|
29
|
+
export const RETRY_PACE_MS = 3 * 60_000;
|
|
30
|
+
/** A tarball download that takes longer is cut off, so a stalled connection never holds up the tick and the engine step after it. */
|
|
31
|
+
export const DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
|
|
32
|
+
const VERSION_PATTERN = /\d+\.\d+\.\d+[0-9A-Za-z.+-]*/;
|
|
33
|
+
export function initialToolchain() {
|
|
34
|
+
return { claude: null, rejected: null, failed: null };
|
|
35
|
+
}
|
|
36
|
+
const packageName = () => `@anthropic-ai/claude-code-linux-${nodeArch()}`;
|
|
37
|
+
const releases = (run) => join(run.layout.binDir, 'releases', CLAUDE_ARTIFACT);
|
|
38
|
+
const linkFor = (version) => join('..', 'releases', CLAUDE_ARTIFACT, version, 'claude');
|
|
39
|
+
const claudeLink = (run) => join(run.layout.toolsDir, 'claude');
|
|
40
|
+
/** The Claude Code version this node should run: Hive's `versions.toolchain.claude`, or the pin. Nothing before Hive pins an engine. */
|
|
41
|
+
export function wantedClaude(run) {
|
|
42
|
+
if (run.desired?.versions?.engine === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
return run.desired.versions.toolchain?.claude ?? CLAUDE_CODE.version;
|
|
45
|
+
}
|
|
46
|
+
function registry(run) {
|
|
47
|
+
const url = run.ctx.env.HIVE_NPM_REGISTRY;
|
|
48
|
+
return (url !== undefined && url !== '' ? url : DEFAULT_NPM_REGISTRY).replace(/\/+$/, '');
|
|
49
|
+
}
|
|
50
|
+
const since = (run, at) => run.ctx.now().getTime() - Date.parse(at);
|
|
51
|
+
async function linkIsGood(run, version) {
|
|
52
|
+
return (await linkTarget(claudeLink(run))) === linkFor(version) && (await isExecutable(claudeLink(run)));
|
|
53
|
+
}
|
|
54
|
+
async function observeClaude(run) {
|
|
55
|
+
const wanted = wantedClaude(run);
|
|
56
|
+
const memory = run.state.toolchain;
|
|
57
|
+
if (wanted === null)
|
|
58
|
+
return { status: 'ok', detail: 'claude is installed once Hive pins an engine' };
|
|
59
|
+
if (memory.rejected !== null && memory.rejected.version === wanted)
|
|
60
|
+
return { status: 'needs_action', detail: memory.rejected.detail, fix: 'hive_button' };
|
|
61
|
+
const installed = memory.claude;
|
|
62
|
+
if (installed !== null && installed.version === wanted) {
|
|
63
|
+
if (await linkIsGood(run, wanted)) {
|
|
64
|
+
run.versions.claude = wanted;
|
|
65
|
+
return { status: 'ok', detail: `claude ${wanted}` };
|
|
66
|
+
}
|
|
67
|
+
return { status: 'failing', detail: `${claudeLink(run)} does not run Claude Code ${wanted}`, fix: 'rerun_install' };
|
|
68
|
+
}
|
|
69
|
+
if (memory.failed !== null && memory.failed.version === wanted)
|
|
70
|
+
return { status: 'failing', detail: memory.failed.detail, fix: 'rerun_install' };
|
|
71
|
+
return { status: 'stale', detail: installed === null ? `Claude Code ${wanted} is not installed` : `Claude Code ${installed.version} is installed, Hive wants ${wanted}` };
|
|
72
|
+
}
|
|
73
|
+
async function probe(run, tool) {
|
|
74
|
+
const now = run.ctx.now().getTime();
|
|
75
|
+
const cached = run.probes.get(tool);
|
|
76
|
+
if (cached !== undefined && now - cached.at < PROBE_TTL_MS)
|
|
77
|
+
return cached.version;
|
|
78
|
+
const result = await run.exec(tool, ['--version']);
|
|
79
|
+
const version = result.code === 0 ? (VERSION_PATTERN.exec(result.stdout)?.[0] ?? null) : null;
|
|
80
|
+
run.probes.set(tool, { at: now, version });
|
|
81
|
+
return version;
|
|
82
|
+
}
|
|
83
|
+
/** gh and codex: found on PATH or not. A version Hive asks for that is missing is a person's job, since v1 does not install them. */
|
|
84
|
+
async function observePath(run) {
|
|
85
|
+
const wanted = run.desired?.versions?.toolchain ?? {};
|
|
86
|
+
const found = [];
|
|
87
|
+
const problems = [];
|
|
88
|
+
for (const tool of OBSERVED_TOOLS) {
|
|
89
|
+
const version = await probe(run, tool);
|
|
90
|
+
if (version !== null) {
|
|
91
|
+
run.versions[tool] = version;
|
|
92
|
+
found.push(`${tool} ${version}`);
|
|
93
|
+
}
|
|
94
|
+
const pin = wanted[tool];
|
|
95
|
+
if (pin === undefined)
|
|
96
|
+
continue;
|
|
97
|
+
if (version === null)
|
|
98
|
+
problems.push(`${tool} ${pin} is wanted and is not installed, and the node does not install ${tool}`);
|
|
99
|
+
else if (version !== pin)
|
|
100
|
+
problems.push(`${tool} ${version} is installed, Hive wants ${pin}, and the node does not install ${tool}`);
|
|
101
|
+
}
|
|
102
|
+
return { found, problems };
|
|
103
|
+
}
|
|
104
|
+
async function observeToolchain(run) {
|
|
105
|
+
const claude = await observeClaude(run);
|
|
106
|
+
const path = await observePath(run);
|
|
107
|
+
// A claude repair must still run while gh or codex needs a person, so its status comes first.
|
|
108
|
+
if (claude.status !== 'ok')
|
|
109
|
+
return { ...claude, detail: [claude.detail, ...path.problems].join('; ') };
|
|
110
|
+
if (path.problems.length > 0)
|
|
111
|
+
return { status: 'needs_action', detail: path.problems.join('; '), fix: 'human' };
|
|
112
|
+
return { status: 'ok', detail: [claude.detail, ...path.found].join(', ') };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The sha512 the tarball must have. The pinned version's comes from `CLAUDE_CODE`, whatever the registry or the dev
|
|
116
|
+
* channel says. Another version Hive asks for takes `dist.integrity` from the registry over https, as npm does.
|
|
117
|
+
*/
|
|
118
|
+
async function integrityFor(run, version) {
|
|
119
|
+
if (version === CLAUDE_CODE.version)
|
|
120
|
+
return CLAUDE_CODE.integrity[nodeArch()];
|
|
121
|
+
const response = await fetch(`${registry(run)}/${packageName()}/${encodeURIComponent(version)}`, { signal: AbortSignal.any([run.signal, AbortSignal.timeout(30_000)]), headers: { accept: 'application/json' } });
|
|
122
|
+
if (!response.ok)
|
|
123
|
+
throw new Error(`the npm registry answered ${response.status} for ${packageName()} ${version}`);
|
|
124
|
+
const meta = (await response.json());
|
|
125
|
+
const integrity = meta.dist?.integrity;
|
|
126
|
+
if (meta.name !== packageName() || meta.version !== version || typeof integrity !== 'string' || !integrity.startsWith('sha512-')) {
|
|
127
|
+
throw new Error(`the npm registry has no sha512 for ${packageName()} ${version}`);
|
|
128
|
+
}
|
|
129
|
+
return integrity;
|
|
130
|
+
}
|
|
131
|
+
/** Stable comes straight from npm. The dev channel comes from Hive, which serves the tarball the harness put there. */
|
|
132
|
+
async function fetchTarball(run, version) {
|
|
133
|
+
const root = releases(run);
|
|
134
|
+
await mkdir(root, { recursive: true });
|
|
135
|
+
if (run.desired?.versions?.channel === 'dev') {
|
|
136
|
+
const answer = await requestArtifact(run, CLAUDE_ARTIFACT, 'dev');
|
|
137
|
+
return download(run, answer.url, CLAUDE_ARTIFACT, root, DOWNLOAD_TIMEOUT_MS);
|
|
138
|
+
}
|
|
139
|
+
const file = `claude-code-linux-${nodeArch()}-${version}.tgz`;
|
|
140
|
+
return download(run, `${registry(run)}/${packageName()}/-/${file}`, CLAUDE_ARTIFACT, root, DOWNLOAD_TIMEOUT_MS);
|
|
141
|
+
}
|
|
142
|
+
class Refused extends Error {
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Lays Claude Code into `bin/releases/claude-code/<version>/` and points `bin/tools/claude` at it. `bin/` is
|
|
146
|
+
* `hive-node`'s and 0755, so the engine's user can run the binary and cannot change it. A binary still on disk is
|
|
147
|
+
* linked again with no download.
|
|
148
|
+
*/
|
|
149
|
+
async function installClaude(run, version) {
|
|
150
|
+
const dir = join(releases(run), version);
|
|
151
|
+
if (await isExecutable(join(dir, 'claude'))) {
|
|
152
|
+
const installed = run.state.toolchain.claude;
|
|
153
|
+
if (installed !== null && installed.version === version) {
|
|
154
|
+
await link(run, version);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const integrity = await integrityFor(run, version);
|
|
159
|
+
const tarball = await fetchTarball(run, version);
|
|
160
|
+
const stage = join(releases(run), `.stage-${process.pid}`);
|
|
161
|
+
try {
|
|
162
|
+
if (`sha512-${tarball.sha512}` !== integrity)
|
|
163
|
+
throw new Refused(`the Claude Code ${version} tarball has sha512 ${tarball.sha512}, not the pinned ${integrity.slice('sha512-'.length)}, so the node refused it`);
|
|
164
|
+
const unpacked = await unpack(run, tarball.file, stage, 'claude');
|
|
165
|
+
// A scratch home, so the check writes nothing into the supervisor's home, and no updater runs.
|
|
166
|
+
const home = join(stage, '.home');
|
|
167
|
+
await mkdir(home, { recursive: true });
|
|
168
|
+
const result = await run.exec(join(unpacked, 'claude'), ['--version'], { env: { HOME: home, CLAUDE_CONFIG_DIR: home, DISABLE_AUTOUPDATER: '1' } });
|
|
169
|
+
if (result.code !== 0)
|
|
170
|
+
throw new Error(`the downloaded claude does not run: ${(result.stderr || result.stdout).trim().slice(-300)}`);
|
|
171
|
+
const reported = VERSION_PATTERN.exec(result.stdout)?.[0] ?? null;
|
|
172
|
+
if (reported !== version)
|
|
173
|
+
throw new Refused(`the downloaded claude is ${reported ?? 'an unknown version'}, Hive wants ${version}`);
|
|
174
|
+
await rm(home, { recursive: true, force: true });
|
|
175
|
+
await rm(dir, { recursive: true, force: true });
|
|
176
|
+
await rename(unpacked, dir);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
await rm(stage, { recursive: true, force: true });
|
|
180
|
+
await rm(tarball.file, { force: true });
|
|
181
|
+
}
|
|
182
|
+
run.state.toolchain.claude = { version, integrity };
|
|
183
|
+
await link(run, version);
|
|
184
|
+
// One release stays. An agent still running the old binary keeps its open file.
|
|
185
|
+
for (const name of await readdir(releases(run))) {
|
|
186
|
+
if (!name.startsWith('.') && name !== version)
|
|
187
|
+
await rm(join(releases(run), name), { recursive: true, force: true });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function link(run, version) {
|
|
191
|
+
// mkdir applies the supervisor's umask 0007, which would leave the directory closed to the engine's user.
|
|
192
|
+
await mkdir(run.layout.toolsDir, { recursive: true });
|
|
193
|
+
await chmod(run.layout.toolsDir, 0o755);
|
|
194
|
+
await switchLink(claudeLink(run), linkFor(version));
|
|
195
|
+
}
|
|
196
|
+
async function repairToolchain(run) {
|
|
197
|
+
const version = wantedClaude(run);
|
|
198
|
+
if (version === null)
|
|
199
|
+
return;
|
|
200
|
+
const memory = run.state.toolchain;
|
|
201
|
+
if (memory.rejected !== null) {
|
|
202
|
+
if (memory.rejected.version === version)
|
|
203
|
+
return;
|
|
204
|
+
memory.rejected = null;
|
|
205
|
+
}
|
|
206
|
+
if (memory.failed !== null && memory.failed.version === version && since(run, memory.failed.at) < RETRY_PACE_MS) {
|
|
207
|
+
throw new Error(`${memory.failed.detail}. The step tries again ${Math.ceil((RETRY_PACE_MS - since(run, memory.failed.at)) / 1000)} s from now`);
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
await installClaude(run, version);
|
|
211
|
+
memory.failed = null;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (run.signal.aborted)
|
|
215
|
+
throw error;
|
|
216
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
217
|
+
const at = run.ctx.now().toISOString();
|
|
218
|
+
if (error instanceof Refused)
|
|
219
|
+
memory.rejected = { version, at, detail: `${detail}. Pin another version in Hive, or re-run setup to try it again.` };
|
|
220
|
+
else
|
|
221
|
+
memory.failed = { version, at, detail };
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export const toolchainStep = {
|
|
226
|
+
id: 'toolchain',
|
|
227
|
+
needs: ['host', 'desired'],
|
|
228
|
+
observe: observeToolchain,
|
|
229
|
+
repair: repairToolchain,
|
|
230
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export declare const MODEL_METHODS: readonly ["direct", "byok", "own_proxy", "hive_credits", "overcy_pool"];
|
|
2
|
+
export type ModelMethod = (typeof MODEL_METHODS)[number];
|
|
3
|
+
export declare const STEP_IDS: readonly ["host", "identity", "desired", "cli", "toolchain", "engine", "ingress", "model-access", "relay"];
|
|
4
|
+
export type StepId = (typeof STEP_IDS)[number];
|
|
5
|
+
export declare const STEP_STATUSES: readonly ["ok", "repaired", "needs", "failed", "blocked", "running"];
|
|
6
|
+
export type StepStatus = (typeof STEP_STATUSES)[number];
|
|
7
|
+
export declare const INGRESS_KINDS: readonly ["none", "dev_tls", "cloudflare_tunnel"];
|
|
8
|
+
export type IngressKind = (typeof INGRESS_KINDS)[number];
|
|
9
|
+
export declare const DESIRED_SCHEMA = "hive-node-desired/v1";
|
|
10
|
+
export declare const REPORT_SCHEMA = "hive-node-report/v1";
|
|
11
|
+
export interface SecretRef {
|
|
12
|
+
name: string;
|
|
13
|
+
version: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Desired {
|
|
16
|
+
schema: typeof DESIRED_SCHEMA;
|
|
17
|
+
revision: number;
|
|
18
|
+
paused?: boolean;
|
|
19
|
+
removed?: boolean;
|
|
20
|
+
role?: string;
|
|
21
|
+
slots?: number;
|
|
22
|
+
versions?: {
|
|
23
|
+
cli?: string;
|
|
24
|
+
engine?: string;
|
|
25
|
+
channel?: 'stable' | 'dev';
|
|
26
|
+
toolchain?: {
|
|
27
|
+
gh?: string;
|
|
28
|
+
claude?: string;
|
|
29
|
+
codex?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
model_access?: {
|
|
33
|
+
method: ModelMethod;
|
|
34
|
+
secret?: SecretRef;
|
|
35
|
+
};
|
|
36
|
+
ingress?: {
|
|
37
|
+
kind: IngressKind;
|
|
38
|
+
stream_origin?: string;
|
|
39
|
+
secret?: SecretRef;
|
|
40
|
+
};
|
|
41
|
+
actions?: {
|
|
42
|
+
rerun_setup?: number;
|
|
43
|
+
restart_engine?: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface ReportStep {
|
|
47
|
+
id: StepId;
|
|
48
|
+
status: StepStatus;
|
|
49
|
+
detail?: string;
|
|
50
|
+
fix?: 'hive_button' | 'rerun_install' | 'human';
|
|
51
|
+
at: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ReportTransition {
|
|
54
|
+
step: StepId;
|
|
55
|
+
from?: StepStatus | null;
|
|
56
|
+
to: StepStatus;
|
|
57
|
+
detail?: string;
|
|
58
|
+
at: string;
|
|
59
|
+
}
|
|
60
|
+
export interface Report {
|
|
61
|
+
schema: typeof REPORT_SCHEMA;
|
|
62
|
+
sent_at: string;
|
|
63
|
+
applied_revision: number;
|
|
64
|
+
generations: {
|
|
65
|
+
rerun_setup: number;
|
|
66
|
+
restart_engine: number;
|
|
67
|
+
};
|
|
68
|
+
host?: {
|
|
69
|
+
os?: string;
|
|
70
|
+
arch?: 'x64' | 'arm64';
|
|
71
|
+
init?: 'systemd' | 'foreground';
|
|
72
|
+
cpus?: number;
|
|
73
|
+
ram_gb?: number;
|
|
74
|
+
disk_free_gb?: number;
|
|
75
|
+
clock_skew_seconds?: number;
|
|
76
|
+
};
|
|
77
|
+
versions?: {
|
|
78
|
+
cli?: string;
|
|
79
|
+
engine?: string;
|
|
80
|
+
node?: string;
|
|
81
|
+
gh?: string;
|
|
82
|
+
claude?: string;
|
|
83
|
+
codex?: string;
|
|
84
|
+
};
|
|
85
|
+
model_access?: {
|
|
86
|
+
method: ModelMethod;
|
|
87
|
+
};
|
|
88
|
+
steps: ReportStep[];
|
|
89
|
+
vitals?: {
|
|
90
|
+
load?: [number, number, number];
|
|
91
|
+
disk_used_percent?: number;
|
|
92
|
+
engine_uptime_seconds?: number;
|
|
93
|
+
threads_relayed?: number;
|
|
94
|
+
};
|
|
95
|
+
transitions?: ReportTransition[];
|
|
96
|
+
}
|
|
97
|
+
export declare class ContractError extends Error {
|
|
98
|
+
constructor(path: string, message: string);
|
|
99
|
+
}
|
|
100
|
+
export declare function parseDesired(input: unknown): Desired;
|
|
101
|
+
export declare function parseReport(input: unknown): Report;
|