@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,108 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import {} from "../types.js";
|
|
3
|
+
import { readText, sha256Hex, writeAtomic } from "./files.js";
|
|
4
|
+
const BEGIN = '# BEGIN hive setup (managed; put your own overrides above this block)';
|
|
5
|
+
const END = '# END hive setup';
|
|
6
|
+
const KEY = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=/;
|
|
7
|
+
const quote = (value) => (/^[\w@%+=:,./-]*$/.test(value) ? value : `"${value.replace(/(["\\$`])/g, '\\$1')}"`);
|
|
8
|
+
export function userKeys(text) {
|
|
9
|
+
const keys = new Map();
|
|
10
|
+
let inside = false;
|
|
11
|
+
for (const line of text.split('\n')) {
|
|
12
|
+
if (line === BEGIN)
|
|
13
|
+
inside = true;
|
|
14
|
+
else if (line === END)
|
|
15
|
+
inside = false;
|
|
16
|
+
else if (!inside) {
|
|
17
|
+
const match = KEY.exec(line);
|
|
18
|
+
if (match)
|
|
19
|
+
keys.set(match[1], line.slice(line.indexOf('=') + 1).trim().replace(/^"(.*)"$/s, '$1'));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return keys;
|
|
23
|
+
}
|
|
24
|
+
export function mergeEnv(existing, managed) {
|
|
25
|
+
const outside = [];
|
|
26
|
+
let inside = false;
|
|
27
|
+
for (const line of existing.split('\n')) {
|
|
28
|
+
if (line === BEGIN)
|
|
29
|
+
inside = true;
|
|
30
|
+
else if (line === END)
|
|
31
|
+
inside = false;
|
|
32
|
+
else if (!inside)
|
|
33
|
+
outside.push(line);
|
|
34
|
+
}
|
|
35
|
+
while (outside.length > 0 && outside[outside.length - 1] === '')
|
|
36
|
+
outside.pop();
|
|
37
|
+
const overridden = new Set(userKeys(existing).keys());
|
|
38
|
+
const block = Object.entries(managed)
|
|
39
|
+
.filter(([key]) => !overridden.has(key))
|
|
40
|
+
.map(([key, value]) => `${key}=${quote(value)}`);
|
|
41
|
+
const parts = [...outside];
|
|
42
|
+
if (block.length > 0) {
|
|
43
|
+
if (parts.length > 0)
|
|
44
|
+
parts.push('');
|
|
45
|
+
parts.push(BEGIN, ...block, END);
|
|
46
|
+
}
|
|
47
|
+
return `${parts.join('\n')}\n`;
|
|
48
|
+
}
|
|
49
|
+
function diffLines(before, after) {
|
|
50
|
+
const old = new Set(before.split('\n'));
|
|
51
|
+
const next = new Set(after.split('\n'));
|
|
52
|
+
const hide = (line) => line.replace(/^(\w*(?:KEY|TOKEN|SECRET)\w*)=.*$/, '$1=***');
|
|
53
|
+
return [...before.split('\n').filter((line) => line !== '' && !next.has(line)).map((line) => `- ${hide(line)}`), ...after.split('\n').filter((line) => line !== '' && !old.has(line)).map((line) => `+ ${hide(line)}`)];
|
|
54
|
+
}
|
|
55
|
+
export function managedEnv(run, existing) {
|
|
56
|
+
const managed = {
|
|
57
|
+
HIVE_ROLE: run.role ?? '',
|
|
58
|
+
HIVE_SERVER: run.desired.server,
|
|
59
|
+
HIVE_LANES_DIR: run.paths.lanesDir,
|
|
60
|
+
};
|
|
61
|
+
if (run.desired.toolchain !== null)
|
|
62
|
+
managed.HIVE_TOOLCHAIN = run.desired.toolchain;
|
|
63
|
+
if (run.laneSlots !== null && run.role !== 'proxy-only')
|
|
64
|
+
managed.HIVE_BOX_SLOTS = String(run.laneSlots);
|
|
65
|
+
const release = run.deps.pin.release;
|
|
66
|
+
if (release && run.role !== 'proxy-only')
|
|
67
|
+
managed.HIVE_RELEASE_DIR = run.paths.releaseDir(release.version);
|
|
68
|
+
if (run.local) {
|
|
69
|
+
managed.HIVE_LOCAL_PORT = String(run.local.port);
|
|
70
|
+
managed.HIVE_LOCAL_KEY = run.local.key;
|
|
71
|
+
managed.ANTHROPIC_BASE_URL = `http://127.0.0.1:${run.local.port}/anthropic`;
|
|
72
|
+
managed.ANTHROPIC_AUTH_TOKEN = run.local.key;
|
|
73
|
+
managed.HIVE_CODEX_HOME = join(run.paths.configDir, 'codex');
|
|
74
|
+
}
|
|
75
|
+
return managed;
|
|
76
|
+
}
|
|
77
|
+
export const observeEnv = async (run) => {
|
|
78
|
+
const existing = (await readText(run.paths.envFile)) ?? '';
|
|
79
|
+
const wanted = mergeEnv(existing, managedEnv(run, existing));
|
|
80
|
+
if (wanted === existing)
|
|
81
|
+
return { status: 'ok', detail: `${run.paths.envFile} is up to date`, fix: null };
|
|
82
|
+
const detail = existing === '' ? `${run.paths.envFile} is missing or empty` : `${run.paths.envFile} differs from the managed values in ${diffLines(existing, wanted).length} line(s)`;
|
|
83
|
+
return { status: 'stale', detail, fix: 'Run `hive setup`, which rewrites the managed block and keeps your own values.' };
|
|
84
|
+
};
|
|
85
|
+
export const envStep = async (run) => {
|
|
86
|
+
const existing = (await readText(run.paths.envFile)) ?? '';
|
|
87
|
+
const wanted = mergeEnv(existing, managedEnv(run, existing));
|
|
88
|
+
const hash = sha256Hex(wanted);
|
|
89
|
+
if (wanted === existing) {
|
|
90
|
+
run.saved.applied.env_hash = hash;
|
|
91
|
+
return { status: 'unchanged', detail: `${run.paths.envFile} is up to date` };
|
|
92
|
+
}
|
|
93
|
+
const changes = diffLines(existing, wanted);
|
|
94
|
+
if (run.opts.dryRun)
|
|
95
|
+
return { status: 'would', detail: `write ${run.paths.envFile}` };
|
|
96
|
+
if (run.deps.prompt.interactive && existing !== '') {
|
|
97
|
+
run.ctx.io.out(`Changes to ${run.paths.envFile}:`);
|
|
98
|
+
for (const line of changes)
|
|
99
|
+
run.ctx.io.out(` ${line}`);
|
|
100
|
+
if (!(await run.deps.prompt.confirm('Write these changes?')))
|
|
101
|
+
return { status: 'skipped', detail: 'you declined the changes' };
|
|
102
|
+
}
|
|
103
|
+
await writeAtomic(run.paths.envFile, wanted, 0o600);
|
|
104
|
+
const previous = run.saved.applied.env_hash;
|
|
105
|
+
run.saved.applied.env_hash = hash;
|
|
106
|
+
const edited = existing !== '' && previous !== undefined && sha256Hex(existing) !== previous;
|
|
107
|
+
return { status: edited ? 'repaired' : 'done', detail: `${existing === '' ? 'wrote' : 'updated'} ${run.paths.envFile} (${changes.length} line(s) changed, your own values kept)` };
|
|
108
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { writeAtomic } from '../../atomic.ts';
|
|
2
|
+
import type { ExecResult } from '../types.ts';
|
|
3
|
+
export { writeAtomic };
|
|
4
|
+
export declare const sha256Hex: (data: string | Uint8Array) => string;
|
|
5
|
+
export declare function readText(path: string): Promise<string | null>;
|
|
6
|
+
export declare function writeIfChanged(path: string, content: string, mode: number): Promise<boolean>;
|
|
7
|
+
export declare function tail(result: ExecResult): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { chmod, readFile } from 'node:fs/promises';
|
|
3
|
+
import { writeAtomic } from "../../atomic.js";
|
|
4
|
+
export { writeAtomic };
|
|
5
|
+
export const sha256Hex = (data) => createHash('sha256').update(data).digest('hex');
|
|
6
|
+
export async function readText(path) {
|
|
7
|
+
try {
|
|
8
|
+
return await readFile(path, 'utf8');
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code === 'ENOENT')
|
|
12
|
+
return null;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function writeIfChanged(path, content, mode) {
|
|
17
|
+
const current = await readText(path);
|
|
18
|
+
if (current === content) {
|
|
19
|
+
await chmod(path, mode);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
await writeAtomic(path, content, mode);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
export function tail(result) {
|
|
26
|
+
const text = `${result.stderr}\n${result.stdout}`.trim().split('\n').slice(-3).join(' | ');
|
|
27
|
+
return text === '' ? `exit ${result.code}` : text.slice(0, 300);
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AppliesFn, type ObserveFn, type Pin, type SetupRun, type StepFn } from '../types.ts';
|
|
2
|
+
type ReleasePin = NonNullable<Pin['release']>;
|
|
3
|
+
export declare function releaseDirReady(run: SetupRun, pin: ReleasePin): Promise<boolean>;
|
|
4
|
+
export declare function scriptEnv(run: SetupRun, pin: ReleasePin): Record<string, string>;
|
|
5
|
+
export declare function parseInstallResult(stdout: string): {
|
|
6
|
+
changed: number;
|
|
7
|
+
slots: number;
|
|
8
|
+
};
|
|
9
|
+
/** A proxy-only node has nothing to do here unless an earlier role left lane scripts behind. */
|
|
10
|
+
export declare const appliesLanes: AppliesFn;
|
|
11
|
+
/** Asks the release's own `install-local.sh --dry-run` what it would change, which writes nothing. */
|
|
12
|
+
export declare const observeLanes: ObserveFn;
|
|
13
|
+
export declare const lanesStep: StepFn;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { access, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { SetupError } from "../types.js";
|
|
4
|
+
import { verifyKitFiles } from "../kit.js";
|
|
5
|
+
import { readText, sha256Hex, tail } from "./files.js";
|
|
6
|
+
const MARKER = '.hive-release-sha256';
|
|
7
|
+
async function exists(path) {
|
|
8
|
+
return access(path).then(() => true, () => false);
|
|
9
|
+
}
|
|
10
|
+
async function listing(run, tarball) {
|
|
11
|
+
const names = await run.deps.exec('tar', ['-tzf', tarball]);
|
|
12
|
+
if (names.code !== 0)
|
|
13
|
+
throw new SetupError(`The release archive cannot be read: ${tail(names)}`);
|
|
14
|
+
for (const name of names.stdout.split('\n').filter(Boolean)) {
|
|
15
|
+
if (name.startsWith('/') || name.split('/').includes('..'))
|
|
16
|
+
throw new SetupError(`The release archive holds an unsafe path (${name}). Nothing was installed.`);
|
|
17
|
+
}
|
|
18
|
+
const types = await run.deps.exec('tar', ['-tvzf', tarball]);
|
|
19
|
+
if (types.stdout.split('\n').some((line) => line.startsWith('l') || line.startsWith('h'))) {
|
|
20
|
+
throw new SetupError('The release archive holds a link. Nothing was installed.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function fetchAndUnpack(run, pin, target) {
|
|
24
|
+
const bytes = await run.deps.fetchBytes(pin.url, run.signal);
|
|
25
|
+
const digest = sha256Hex(bytes);
|
|
26
|
+
if (digest !== pin.sha256.toLowerCase()) {
|
|
27
|
+
throw new SetupError(`The overcy-hive ${pin.version} download does not match its pinned sha256 (got ${digest.slice(0, 12)}, pinned ${pin.sha256.slice(0, 12)}). Nothing was installed.`);
|
|
28
|
+
}
|
|
29
|
+
await mkdir(run.paths.dataDir, { recursive: true });
|
|
30
|
+
const scratch = await mkdtemp(join(run.paths.dataDir, '.fetch-'));
|
|
31
|
+
try {
|
|
32
|
+
const tarball = join(scratch, 'release.tgz');
|
|
33
|
+
await writeFile(tarball, bytes);
|
|
34
|
+
await listing(run, tarball);
|
|
35
|
+
const staged = join(scratch, 'unpacked');
|
|
36
|
+
await mkdir(staged);
|
|
37
|
+
const unpacked = await run.deps.exec('tar', ['-xzf', tarball, '-C', staged, '--strip-components=1']);
|
|
38
|
+
if (unpacked.code !== 0)
|
|
39
|
+
throw new SetupError(`Unpacking the release failed: ${tail(unpacked)}`);
|
|
40
|
+
if (pin.files) {
|
|
41
|
+
await verifyKitFiles(pin.files, async (path) => readFile(join(staged, path)).catch(() => null), pin.version);
|
|
42
|
+
}
|
|
43
|
+
await writeFile(join(staged, MARKER), `${pin.sha256.toLowerCase()}\n`);
|
|
44
|
+
await rm(target, { recursive: true, force: true });
|
|
45
|
+
await rename(staged, target);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await rm(scratch, { recursive: true, force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function releaseDirReady(run, pin) {
|
|
52
|
+
const marker = await readText(join(run.paths.releaseDir(pin.version), MARKER));
|
|
53
|
+
return marker !== null && marker.trim() === pin.sha256.toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
export function scriptEnv(run, pin) {
|
|
56
|
+
return { HIVE_CONFIG: run.paths.envFile, HIVE_RELEASE_DIR: run.paths.releaseDir(pin.version) };
|
|
57
|
+
}
|
|
58
|
+
const isCount = (value) => typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
59
|
+
export function parseInstallResult(stdout) {
|
|
60
|
+
const lines = stdout.split('\n').map((line) => line.trim()).filter((line) => line !== '');
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = JSON.parse(lines.at(-1) ?? '');
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
throw new SetupError('The lane install did not print a JSON result on its last line.');
|
|
67
|
+
}
|
|
68
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
69
|
+
throw new SetupError('The lane install result is not a JSON object.');
|
|
70
|
+
if (!isCount(parsed.changed))
|
|
71
|
+
throw new SetupError('The lane install result has no valid "changed" count (a non-negative integer).');
|
|
72
|
+
if (!isCount(parsed.slots))
|
|
73
|
+
throw new SetupError('The lane install result has no valid "slots" count (a non-negative integer).');
|
|
74
|
+
return { changed: parsed.changed, slots: parsed.slots };
|
|
75
|
+
}
|
|
76
|
+
const NO_LANES = 'proxy-only machines run no lanes';
|
|
77
|
+
/** A proxy-only node has nothing to do here unless an earlier role left lane scripts behind. */
|
|
78
|
+
export const appliesLanes = (run) => (run.role === 'proxy-only' && !run.saved.applied.release ? { skip: NO_LANES } : true);
|
|
79
|
+
/** Asks the release's own `install-local.sh --dry-run` what it would change, which writes nothing. */
|
|
80
|
+
export const observeLanes = async (run) => {
|
|
81
|
+
if (run.role === 'proxy-only') {
|
|
82
|
+
const installed = run.saved.applied.release;
|
|
83
|
+
return { status: installed ? 'stale' : 'skipped', detail: installed ? `lane scripts from overcy-hive ${installed} are still installed on a proxy-only node` : NO_LANES, fix: installed ? 'Run `hive setup`, which removes them.' : null };
|
|
84
|
+
}
|
|
85
|
+
const pin = run.deps.pin.release;
|
|
86
|
+
if (!pin)
|
|
87
|
+
return { status: 'failing', detail: 'this CLI has no overcy-hive release pinned yet, so the lane scripts cannot be installed', fix: 'Update @overcy/hive, or pass --kit-release <tag> to `hive node bootstrap`.' };
|
|
88
|
+
const dir = run.paths.releaseDir(pin.version);
|
|
89
|
+
if (!(await releaseDirReady(run, pin)))
|
|
90
|
+
return { status: 'failing', detail: `overcy-hive ${pin.version} is not unpacked in ${dir}`, fix: 'Run `hive setup`, which downloads it, checks its sha256 and unpacks it.' };
|
|
91
|
+
const script = join(dir, 'install', 'install-local.sh');
|
|
92
|
+
if (!(await exists(script)))
|
|
93
|
+
return { status: 'failing', detail: `overcy-hive ${pin.version} has no install/install-local.sh`, fix: 'Pin a newer overcy-hive release.' };
|
|
94
|
+
const args = [script, '--role', run.role ?? 'worker', ...(run.desired.slots !== null ? ['--slots', String(run.desired.slots)] : []), '--json', '--dry-run'];
|
|
95
|
+
const result = await run.deps.exec('bash', args, { env: scriptEnv(run, pin) });
|
|
96
|
+
if (result.code !== 0)
|
|
97
|
+
return { status: 'failing', detail: `the lane install check failed: ${tail(result)}`, fix: 'Run `hive setup` and read its error.' };
|
|
98
|
+
const { changed, slots } = parseInstallResult(result.stdout);
|
|
99
|
+
run.laneSlots = slots;
|
|
100
|
+
if (changed > 0)
|
|
101
|
+
return { status: 'stale', detail: `${changed} lane file(s) differ from overcy-hive ${pin.version}`, fix: 'Run `hive setup`, which restores them from the release.' };
|
|
102
|
+
return { status: 'ok', detail: `overcy-hive ${pin.version} lane scripts match the release`, fix: null };
|
|
103
|
+
};
|
|
104
|
+
async function removeLanes(run) {
|
|
105
|
+
const installed = run.saved.applied.release;
|
|
106
|
+
if (!installed)
|
|
107
|
+
return { status: 'skipped', detail: NO_LANES };
|
|
108
|
+
const script = join(run.paths.releaseDir(installed), 'install', 'install-local.sh');
|
|
109
|
+
if (!(await exists(script)))
|
|
110
|
+
throw new SetupError(`This machine ran lanes from overcy-hive ${installed}, but ${script} is gone, so they cannot be removed. Delete ${run.paths.lanesDir} by hand.`);
|
|
111
|
+
if (run.opts.dryRun)
|
|
112
|
+
return { status: 'would', detail: `remove the lane scripts installed from overcy-hive ${installed}` };
|
|
113
|
+
const result = await run.deps.exec('bash', [script, '--uninstall', '--json'], { env: { HIVE_CONFIG: run.paths.envFile, HIVE_RELEASE_DIR: run.paths.releaseDir(installed) } });
|
|
114
|
+
if (result.code !== 0)
|
|
115
|
+
throw new SetupError(`Removing the lane scripts failed: ${tail(result)}`);
|
|
116
|
+
delete run.saved.applied.release;
|
|
117
|
+
delete run.saved.applied.drift;
|
|
118
|
+
return { status: 'done', detail: `removed the lane scripts installed from overcy-hive ${installed}` };
|
|
119
|
+
}
|
|
120
|
+
export const lanesStep = async (run) => {
|
|
121
|
+
if (run.role === 'proxy-only')
|
|
122
|
+
return removeLanes(run);
|
|
123
|
+
const pin = run.deps.pin.release;
|
|
124
|
+
if (!pin) {
|
|
125
|
+
if (run.opts.dryRun)
|
|
126
|
+
return { status: 'would', detail: 'fetch the pinned overcy-hive release and install its lane scripts (this CLI has no release pinned yet)' };
|
|
127
|
+
throw new SetupError('This CLI version has no overcy-hive release pinned yet, so the lane scripts cannot be installed. Update @overcy/hive and run it again.');
|
|
128
|
+
}
|
|
129
|
+
const dir = run.paths.releaseDir(pin.version);
|
|
130
|
+
const ready = await releaseDirReady(run, pin);
|
|
131
|
+
if (!ready) {
|
|
132
|
+
if (run.opts.dryRun)
|
|
133
|
+
return { status: 'would', detail: `fetch overcy-hive ${pin.version} (sha256 ${pin.sha256.slice(0, 12)}) into ${dir} and install the ${run.role ?? 'chosen'} lane scripts` };
|
|
134
|
+
await fetchAndUnpack(run, pin, dir);
|
|
135
|
+
}
|
|
136
|
+
const script = join(dir, 'install', 'install-local.sh');
|
|
137
|
+
if (!(await exists(script)))
|
|
138
|
+
throw new SetupError(`overcy-hive ${pin.version} has no install/install-local.sh, so it cannot be installed from this CLI.`);
|
|
139
|
+
const args = [script, '--role', run.role ?? 'worker', ...(run.desired.slots !== null ? ['--slots', String(run.desired.slots)] : []), '--json', ...(run.opts.dryRun ? ['--dry-run'] : [])];
|
|
140
|
+
const result = await run.deps.exec('bash', args, { env: scriptEnv(run, pin) });
|
|
141
|
+
if (result.code !== 0)
|
|
142
|
+
throw new SetupError(`The lane install failed: ${tail(result)}`);
|
|
143
|
+
const { changed: count, slots } = parseInstallResult(result.stdout);
|
|
144
|
+
run.laneSlots = slots;
|
|
145
|
+
const reinstall = run.saved.applied.release === pin.version;
|
|
146
|
+
if (!run.opts.dryRun) {
|
|
147
|
+
run.saved.applied.release = pin.version;
|
|
148
|
+
run.saved.applied.slots = slots;
|
|
149
|
+
}
|
|
150
|
+
if (!ready || count > 0)
|
|
151
|
+
return { status: run.opts.dryRun ? 'would' : reinstall ? 'repaired' : 'done', detail: `overcy-hive ${pin.version}: ${count} file(s) ${run.opts.dryRun ? 'to install or repair' : 'installed or repaired'}` };
|
|
152
|
+
return { status: 'unchanged', detail: `overcy-hive ${pin.version} lane scripts match the release` };
|
|
153
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ObserveFn, type SetupRun, type StepFn } from '../types.ts';
|
|
2
|
+
export declare const proxyArgs: (run: SetupRun, ...rest: string[]) => string[];
|
|
3
|
+
/**
|
|
4
|
+
* Asks Hive the same question the repair asks and compares the answer with what
|
|
5
|
+
* is stored, plus the lane-scoped Codex config. It sets `run.local` from the
|
|
6
|
+
* forwarder settings already in `hive.env`, in memory only, so the `env` step
|
|
7
|
+
* can tell what the file should hold. It never generates a port or a key.
|
|
8
|
+
*/
|
|
9
|
+
export declare const observeModelAccess: ObserveFn;
|
|
10
|
+
export declare const modelAccessStep: StepFn;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ApiError } from "../../api.js";
|
|
2
|
+
import { allValues, baseUrls, forwarderSettingsFrom, LOCAL_KEY_ENV, LOCAL_PORT_ENV, newLocalKey, newLocalPort } from "../forwarder.js";
|
|
3
|
+
import { ModelAccessContractError, sameAccess } from "../model-access.js";
|
|
4
|
+
import { SetupError } from "../types.js";
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { codexConfig, writeClaudeEnv, writeCodexConfig } from "./agents.js";
|
|
7
|
+
import { readText, tail } from "./files.js";
|
|
8
|
+
export const proxyArgs = (run, ...rest) => ['--yes', `@overcy/hive-proxy@${run.deps.pin.proxy.version}`, ...rest];
|
|
9
|
+
async function hostProxyHere(run) {
|
|
10
|
+
const { exec } = run.deps;
|
|
11
|
+
if ((await exec('npx', proxyArgs(run, 'status'))).code === 0)
|
|
12
|
+
return `hive-proxy ${run.deps.pin.proxy.version} is already installed here`;
|
|
13
|
+
const installed = await exec('npx', proxyArgs(run, 'install'));
|
|
14
|
+
if (installed.code !== 0)
|
|
15
|
+
throw new SetupError(`hive-proxy install failed: ${tail(installed)}`);
|
|
16
|
+
return `installed hive-proxy ${run.deps.pin.proxy.version} here`;
|
|
17
|
+
}
|
|
18
|
+
async function localSettings(run) {
|
|
19
|
+
const values = allValues((await readText(run.paths.envFile)) ?? '');
|
|
20
|
+
const existing = forwarderSettingsFrom((await readText(run.paths.envFile)) ?? '');
|
|
21
|
+
if (existing)
|
|
22
|
+
return { port: existing.port, key: existing.localKey };
|
|
23
|
+
const port = Number(values.get(LOCAL_PORT_ENV));
|
|
24
|
+
return { port: Number.isInteger(port) && port >= 1024 && port <= 65535 ? port : newLocalPort(), key: values.get(LOCAL_KEY_ENV) || newLocalKey() };
|
|
25
|
+
}
|
|
26
|
+
const describeAccess = (fresh) => (fresh.method === null ? 'no method chosen yet (lanes get a 503 until you pick one in Hive)' : `${fresh.method}, version ${fresh.version}`);
|
|
27
|
+
/**
|
|
28
|
+
* Asks Hive the same question the repair asks and compares the answer with what
|
|
29
|
+
* is stored, plus the lane-scoped Codex config. It sets `run.local` from the
|
|
30
|
+
* forwarder settings already in `hive.env`, in memory only, so the `env` step
|
|
31
|
+
* can tell what the file should hold. It never generates a port or a key.
|
|
32
|
+
*/
|
|
33
|
+
export const observeModelAccess = async (run) => {
|
|
34
|
+
let fresh;
|
|
35
|
+
try {
|
|
36
|
+
fresh = await run.deps.modelAccessSource.get(run.signal);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof ApiError || error instanceof ModelAccessContractError) {
|
|
40
|
+
return { status: 'failing', detail: error.message, fix: 'Check that Hive is up and serves model access, pick a method in team settings, then run `hive setup`.' };
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
const envText = (await readText(run.paths.envFile)) ?? '';
|
|
45
|
+
const existing = forwarderSettingsFrom(envText);
|
|
46
|
+
run.local = existing ? { port: existing.port, key: existing.localKey } : null;
|
|
47
|
+
const savedAny = await run.deps.modelAccessStore.read();
|
|
48
|
+
const saved = savedAny && savedAny.server === run.ctx.url ? savedAny : null;
|
|
49
|
+
const stale = [];
|
|
50
|
+
if (!sameAccess(saved, fresh, run.ctx.now()))
|
|
51
|
+
stale.push(`the ${run.deps.modelAccessStore.kind} holds ${saved ? `${saved.method ?? 'no method'}, version ${saved.version}` : 'no answer'}`);
|
|
52
|
+
if (existing) {
|
|
53
|
+
const path = join(run.paths.configDir, 'codex', 'config.toml');
|
|
54
|
+
const current = await readText(path);
|
|
55
|
+
const wanted = codexConfig(current ?? '', { baseUrl: baseUrls(existing).openai });
|
|
56
|
+
if (current !== wanted)
|
|
57
|
+
stale.push(`${path} does not point Codex at the local forwarder`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
stale.push(`${run.paths.envFile} has no local forwarder port and key yet`);
|
|
61
|
+
}
|
|
62
|
+
if (stale.length === 0)
|
|
63
|
+
return { status: 'ok', detail: `${describeAccess(fresh)}, stored in the ${run.deps.modelAccessStore.kind}`, fix: null };
|
|
64
|
+
return { status: 'stale', detail: `${describeAccess(fresh)}; ${stale.join('; ')}`, fix: 'Run `hive setup`.' };
|
|
65
|
+
};
|
|
66
|
+
export const modelAccessStep = async (run) => {
|
|
67
|
+
const { host, modelAccessSource, modelAccessStore } = run.deps;
|
|
68
|
+
const notes = [];
|
|
69
|
+
if (run.opts.hiveProxy === 'install') {
|
|
70
|
+
if (run.opts.dryRun)
|
|
71
|
+
notes.push('would run hive-proxy install on this machine');
|
|
72
|
+
else {
|
|
73
|
+
notes.push(await hostProxyHere(run));
|
|
74
|
+
run.ctx.io.err('Enter the proxy URL and key in Hive (team settings). Overcy hosts nothing.');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const enrolled = await run.ctx.store.read('node.json');
|
|
78
|
+
if (run.opts.dryRun && !enrolled) {
|
|
79
|
+
return { status: 'would', detail: `ask Hive where this team's models come from, point Claude Code and Codex at the local forwarder${notes.length ? `; ${notes.join('; ')}` : ''}` };
|
|
80
|
+
}
|
|
81
|
+
let fresh;
|
|
82
|
+
try {
|
|
83
|
+
fresh = await modelAccessSource.get(run.signal);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error instanceof ApiError || error instanceof ModelAccessContractError)
|
|
87
|
+
throw new SetupError(error.message);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
const local = await localSettings(run);
|
|
91
|
+
run.local = local;
|
|
92
|
+
const urls = baseUrls({ host: '127.0.0.1', port: local.port, localKey: local.key, anthropicPath: '/anthropic', openaiPath: '/openai/v1' });
|
|
93
|
+
const savedAny = await modelAccessStore.read();
|
|
94
|
+
const saved = savedAny && savedAny.server === run.ctx.url ? savedAny : null;
|
|
95
|
+
const accessSame = sameAccess(saved, fresh, run.ctx.now());
|
|
96
|
+
const describe = describeAccess(fresh);
|
|
97
|
+
if (run.opts.dryRun) {
|
|
98
|
+
const settingsChanged = !accessSame;
|
|
99
|
+
return { status: settingsChanged ? 'would' : 'unchanged', detail: [`model access: ${describe}`, ...notes].join('; ') };
|
|
100
|
+
}
|
|
101
|
+
let changed = false;
|
|
102
|
+
if (!accessSame) {
|
|
103
|
+
await modelAccessStore.write({ ...fresh, server: run.ctx.url });
|
|
104
|
+
changed = true;
|
|
105
|
+
}
|
|
106
|
+
changed = (await writeCodexConfig(join(run.paths.configDir, 'codex'), { baseUrl: urls.openai }, 'config.toml')) || changed;
|
|
107
|
+
run.saved.applied.model_access = `${fresh.method ?? 'none'}:${fresh.version}`;
|
|
108
|
+
run.saved.applied.model_access_store = modelAccessStore.kind;
|
|
109
|
+
if (run.opts.configureAgents) {
|
|
110
|
+
if (await run.deps.probeForwarder(local.port)) {
|
|
111
|
+
changed = (await writeClaudeEnv(host.home, { ANTHROPIC_BASE_URL: urls.anthropic, ANTHROPIC_AUTH_TOKEN: local.key })) || changed;
|
|
112
|
+
changed = (await writeCodexConfig(join(host.home, '.codex'), { baseUrl: urls.openai }, 'config.toml')) || changed;
|
|
113
|
+
notes.push('configured your global Claude Code and Codex');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
notes.push(`left your global Claude Code and Codex alone because the forwarder is not listening on 127.0.0.1:${local.port} yet`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const detail = [`${describe}, stored in the ${modelAccessStore.kind}; lanes use the forwarder at 127.0.0.1:${local.port} through hive.env`, ...notes].join('; ');
|
|
120
|
+
const previous = saved && saved.method !== fresh.method ? ` (was ${saved.method ?? 'none'})` : '';
|
|
121
|
+
return { status: changed ? 'done' : 'unchanged', detail: `${detail}${previous}` };
|
|
122
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ApiError, NetworkError } from "../../api.js";
|
|
2
|
+
import { SetupError } from "../types.js";
|
|
3
|
+
const MIN_DISK_GB = 5;
|
|
4
|
+
async function problemsOf(run) {
|
|
5
|
+
const { host, exec } = run.deps;
|
|
6
|
+
const problems = [];
|
|
7
|
+
if (host.os !== 'darwin' && host.os !== 'linux')
|
|
8
|
+
problems.push({ message: `${host.os} is not supported, use macOS or Linux`, fix: 'Use a macOS or Linux machine.' });
|
|
9
|
+
if (host.arch !== 'x64' && host.arch !== 'arm64')
|
|
10
|
+
problems.push({ message: `${host.arch} is not supported, use x64 or arm64`, fix: 'Use an x64 or arm64 machine.' });
|
|
11
|
+
if (Number(host.node.split('.')[0]) < 22)
|
|
12
|
+
problems.push({ message: `Node ${host.node} is too old, Node 22 or newer is required`, fix: 'Install Node 22 or newer.' });
|
|
13
|
+
if (host.freeDiskGb !== null && host.freeDiskGb < MIN_DISK_GB)
|
|
14
|
+
problems.push({ message: `${host.freeDiskGb} GB of disk is free, ${MIN_DISK_GB} GB is required`, fix: `Free at least ${MIN_DISK_GB} GB of disk.` });
|
|
15
|
+
for (const [command, args] of [['git', ['--version']], ['tar', ['--version']]]) {
|
|
16
|
+
const result = await exec(command, [...args]);
|
|
17
|
+
if (result.code !== 0)
|
|
18
|
+
problems.push({ message: `${command} is not installed or does not run`, fix: `Install ${command}.` });
|
|
19
|
+
}
|
|
20
|
+
const cron = await exec('crontab', ['-l']);
|
|
21
|
+
if (cron.code === 127)
|
|
22
|
+
problems.push({ message: 'crontab is not installed, and the lane jobs are scheduled with it', fix: 'Install cron. It is the cron package on Debian and Ubuntu and cronie on Fedora.' });
|
|
23
|
+
try {
|
|
24
|
+
await run.ctx.api.json('GET', '/api/v0/nodes/me', { signal: run.signal });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof NetworkError)
|
|
28
|
+
problems.push({ message: `${run.ctx.url} is not reachable (${error.message})`, fix: `Check the network and the server address. HIVE_URL sets it, and it is ${run.ctx.url} now.` });
|
|
29
|
+
else if (!(error instanceof ApiError))
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
return problems;
|
|
33
|
+
}
|
|
34
|
+
const healthy = (run) => {
|
|
35
|
+
const { host } = run.deps;
|
|
36
|
+
return `${host.os}-${host.arch}, node ${host.node}, ${host.cores} cores, ${host.ramGb} GB RAM, ${run.ctx.url} reachable`;
|
|
37
|
+
};
|
|
38
|
+
export const preflight = async (run) => {
|
|
39
|
+
const problems = await problemsOf(run);
|
|
40
|
+
if (problems.length > 0)
|
|
41
|
+
throw new SetupError(`This machine cannot be set up yet: ${problems.map((p) => p.message).join('; ')}.`);
|
|
42
|
+
return { status: 'unchanged', detail: healthy(run) };
|
|
43
|
+
};
|
|
44
|
+
export const observePreflight = async (run) => {
|
|
45
|
+
const problems = await problemsOf(run);
|
|
46
|
+
if (problems.length === 0)
|
|
47
|
+
return { status: 'ok', detail: healthy(run), fix: null };
|
|
48
|
+
return { status: 'failing', detail: problems.map((p) => p.message).join('; '), fix: [...new Set(problems.map((p) => p.fix))].join(' ') };
|
|
49
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InstallService } from '../manifest.ts';
|
|
2
|
+
import { type AppliesFn, type Host, type ObserveFn, type SetupRun, type StepFn } from '../types.ts';
|
|
3
|
+
/** On a node the supervisor reports, and a second loop (`hive connect`) would refuse to run beside it. */
|
|
4
|
+
export declare const appliesReporter: AppliesFn;
|
|
5
|
+
export declare function reporterService(host: Host): Omit<Exclude<InstallService, {
|
|
6
|
+
kind: 'none';
|
|
7
|
+
}>, 'status'>;
|
|
8
|
+
export declare function reporterCommand(run: SetupRun): string[];
|
|
9
|
+
export declare function launchdPlist(run: SetupRun, logPath: string): string;
|
|
10
|
+
export declare function systemdUnit(run: SetupRun): string;
|
|
11
|
+
export declare const observeReporter: ObserveFn;
|
|
12
|
+
export declare const reporterStep: StepFn;
|