@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
package/README.md
CHANGED
|
@@ -1,3 +1,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @overcy/hive
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect a machine to Hive and see it report.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npx @overcy/hive # one command: sign in, enroll, install proxy, lanes, env, cron and drift-check
|
|
7
|
+
npx @overcy/hive login # prints a code, you approve it at https://hive.overcy.ai/device
|
|
8
|
+
npx @overcy/hive connect # registers this machine, then reports status every 60 seconds
|
|
9
|
+
npx @overcy/hive status # your team, plan usage and nodes with their state
|
|
10
|
+
npx @overcy/hive doctor # check every setup step, read-only, one row each with its fix
|
|
11
|
+
npx @overcy/hive threads --once # relay this machine's T3 Code threads to Hive one time
|
|
12
|
+
npx @overcy/hive logout
|
|
13
|
+
npx @overcy/hive connect --token hvr_... # a machine with nobody at the keyboard, no sign-in
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The commands `hive` and `overcy-hive` are the same program. It needs Node 22.
|
|
17
|
+
|
|
18
|
+
## One-line commands
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npx @overcy/hive login
|
|
22
|
+
npx @overcy/hive connect
|
|
23
|
+
npx @overcy/hive node bootstrap --token hvr_... --role worker
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`node bootstrap` is `hive setup` without prompts. It runs the same ordered, idempotent steps (`preflight`, `login`, `role`, `enroll`, `model-access`, `lanes`, `env`, `cron`, `drift`, `reporter`), reports each as `done`, `unchanged`, `repaired`, `skipped` or `failed`, stops at the first failure and exits non-zero. A rerun repairs. `--json` prints one report. `--dry-run` writes nothing. `--toolchain <profile>` is written to `hive.env` as `HIVE_TOOLCHAIN` and shown in the report. `--slots <n>` and `--kit-release <tag>` pass through to the kit.
|
|
27
|
+
|
|
28
|
+
### EC2 user data
|
|
29
|
+
|
|
30
|
+
User data must hold no secret. The instance proves who it is with its signed IMDSv2 identity, and Hive hands back a one-time registration token:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
npx -y @overcy/hive@<pinned version> node bootstrap --token-from-imds --node-id <id> --role <role> --toolchain <profile>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Always pin the version. An unpinned `npx` runs whatever is newest at boot. `--node-id` is not a secret. The command reads the identity document and its signature with IMDSv2, posts them to `/api/v0/nodes/aws-identity` and never prints or logs them or the token. A 402, 404, 409 or 422 fails at once with the code and message. A 5xx is retried three times, then fails. If IMDS is unreachable it fails closed.
|
|
37
|
+
|
|
38
|
+
### The install manifest
|
|
39
|
+
|
|
40
|
+
Bootstrap records every path, worktree root, service and crontab block it creates, ahead of creating it, in `$HIVE_HOME/install-manifest.json`. The format, the sibling journal and the crontab baseline rule are in [docs/install-manifest.md](docs/install-manifest.md).
|
|
41
|
+
|
|
42
|
+
### Use from code
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { bootstrapNode, createBootstrapDeps } from '@overcy/hive/bootstrap';
|
|
46
|
+
|
|
47
|
+
const deps = await createBootstrapDeps({ apiUrl: 'https://hive.example' });
|
|
48
|
+
const report = await bootstrapNode({ apiUrl: 'https://hive.example', role: 'worker', hiveProxy: 'skip', registrationToken }, deps);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`createBootstrapDeps` builds the context and every dependency from public options (`env`, `io`, `signal`, `fetch`, `interactive`, and `overrides` for any `SetupDeps` member). `--slots`, `--toolchain` and `--kit-release` are saved and reused on later runs that omit them.
|
|
52
|
+
|
|
53
|
+
The setup command, `node bootstrap` and other commands share this module. The kit comes from a release manifest on the public OvercyAI/hive-kit repo (`hive-kit.manifest.json`: version, https url, sha256, optional per-file sha256). A hash mismatch installs nothing.
|
|
54
|
+
|
|
55
|
+
## What it does
|
|
56
|
+
|
|
57
|
+
- `login` uses the OAuth device flow (RFC 8628). It polls no faster than the server asks and slows down when told. A code lasts 30 minutes, and `login` prints when it expires as a local time (`Code expires at 2:34 PM.`). If nobody approves a code in time, `login` asks for a new one, prints it with its new expiry and keeps waiting. After 5 codes it exits 1.
|
|
58
|
+
- `connect` creates an Ed25519 key in `~/.config/hive/` (mode 0600), registers the machine as a node and posts status v0 with load, CPU count, disk use and lanes. Every post is signed with the key. The private key never leaves the machine. `--once` posts one time and exits. Ctrl-C stops it cleanly.
|
|
59
|
+
- `status` shows the connection state (`unconfigured`, `logged_in`, `connecting`, `connected`, `degraded`, `paused`, `revoked`), the plan's plan slots and each node.
|
|
60
|
+
- `logout` revokes the sign-in. The machine keeps its node identity, so the next `login` and `connect` reuse its slot.
|
|
61
|
+
|
|
62
|
+
`--rebind` and `--reconnect` are declared and not built yet.
|
|
63
|
+
|
|
64
|
+
## T3 Code threads
|
|
65
|
+
|
|
66
|
+
A connected machine that runs T3 Code also relays its threads to the Threads page. After each successful status post, `hive connect` reads the T3 Code server's thread projection and posts the summaries to `POST /api/v0/hivecode/threads`, signed with the same node key as the status post ([ADR 0010](../../docs/adr/0010-hivecode-threads.md)).
|
|
67
|
+
|
|
68
|
+
- It reads `$HIVE_T3_HOME/userdata/statev2.sqlite`, with `HIVE_T3_HOME` defaulting to `~/.t3`. It opens the file read-only and never writes T3 Code state. If the file is missing, the relay does nothing. Set `HIVE_THREADS=off` to turn it off.
|
|
69
|
+
- It sends up to 200 threads that are not archived, deleted, subagents or side chats, in four groups, newest first within each: threads that are unsettled or running and have a project (lanes), then the other unsettled or running threads, then settled threads with an open pull request, then the rest.
|
|
70
|
+
- Before reading, it checks the T3 Code tables and columns it uses. When an upgrade changed them, it relays nothing and logs `Thread relay failed: T3 Code's state database changed shape (missing ...)`, and status posts go on.
|
|
71
|
+
- Each one carries the project id and title, thread id, title, status, `waiting_on_user`, the linked pull request and `last_activity_at`. An id that is already `[A-Za-z0-9_-]` and fits is sent as is. Any other id keeps a cleaned prefix and gets a hash suffix, so `mcp:abc` becomes `mcp-abc-<16 hex>` and two ids never merge. A batch stays within 256KB. A pull request is sent only when its URL is https, at most 500 bytes and has no credentials, and its number fits the server's column.
|
|
72
|
+
- Status comes from the thread's latest run. A settled thread is `completed` unless a run is active. Otherwise a pending approval or question gives `waiting` with `waiting_on_user`. As in T3 Code, a subagent's pending approval or user-only question counts for its parent while one of the subagent's runs is still live (preparing, starting, running or waiting), and any question from a side chat counts for the thread it came from. An `auth_refresh` request never counts. `queued` stays `queued`. `preparing`, `starting` and `running` give `running`, and `waiting` stays `waiting`. `failed` gives `error`. A settled thread gives `completed`, a thread with an open pull request gives `review`, and any other thread gives `idle`.
|
|
73
|
+
- `~/.config/hive/threads.json` keeps the ids sent last time. An id that leaves the set is sent in `removed`. The file changes only after Hive accepts the post, so a refused post repeats the removal next time.
|
|
74
|
+
- Live streaming is opt-in. Set `HIVE_T3_STREAM_ORIGIN` to the HTTPS origin of an approved Cloudflare Tunnel pointing at the HiveCode-enabled OvercyCode server. See [live thread setup](docs/hivecode-live.md). With no setting, the reporter leaves the saved address alone. Use `HIVE_T3_STREAM_ORIGIN=off hive threads --once` to withdraw it.
|
|
75
|
+
- A failed relay prints `Thread relay failed: ...` and never changes the connection state or the status report.
|
|
76
|
+
|
|
77
|
+
Use `hive threads --once` to relay one time on a connected machine, and `hive threads --dry-run` to print the batch without sending it. The relay uses `node:sqlite`, so it needs Node 22.13 or later.
|
|
78
|
+
|
|
79
|
+
## PR events into T3 Code threads
|
|
80
|
+
|
|
81
|
+
Hive turns GitHub webhooks into PR events (`ready_to_merge`, `lost_ready`, `checks_failed`, `conflict`, `merged`, `closed`, `enqueued`, `dequeued`) and lists, for each one, the relayed threads on this node that own the pull request. With `HIVE_PR_EVENTS=on` (it is off by default), `hive connect` pulls them once a minute and sends each thread one message:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
[hive pr-event] #<N> <kind> at <sha8>[ (reason)] - act per your chain rules.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- It calls `GET /api/v0/hivecode/pr-events?after=<cursor>&limit=50`, signed with the node key like the thread relay.
|
|
88
|
+
- It runs as its own task beside the status loop. A pass has a 45 second deadline and each `t3` call at most 30 seconds, so a slow or hung T3 Code never delays a status post or the thread relay. It only runs while the machine is connected, and it never changes the connection state. A failure prints `PR events failed: ...` or a per-thread line.
|
|
89
|
+
- Hive lists threads by the relay's wire id. Each one is mapped back to its T3 Code id by reading `statev2.sqlite` read-only under `HIVE_T3_HOME` (default `~/.t3`) and applying the relay's `wireId`, so `mcp-launch-<hex>-<hash>` becomes `mcp:launch:<hex>`. A thread with no match is not on this machine, so it is skipped and does not hold the cursor. Without T3 Code state the pass does nothing. Only a native id matching `[A-Za-z0-9][A-Za-z0-9:._-]{0,199}` is handed to `t3`, so the id can never be read as a flag.
|
|
90
|
+
- It sends through `t3 thread send`, the CLI that ships with T3 Code. That command signs in to the running T3 Code server with the server's own local auth for the one call and revokes the session afterwards, so no T3 token passes through Hive. When the installed `t3` has `--mode`, it sends `--mode queue`: a busy thread gets the message as its next turn and is never steered or interrupted. A `t3` without `--mode` is used only when its help says it queues, as T3 Code 0.1.9 does (it sends `mode: "queue"` itself). Any other `t3` is refused and the send stays a retry. `HIVE_T3_BIN` picks the `t3` command, and `HIVE_T3_HOME`, when set, is passed as `--base-dir`.
|
|
91
|
+
- `~/.config/hive/pr-events.json` holds the cursor, the threads already handled for each event above it, and a retry list. Before each send, the send is saved as a pending retry. It is removed once `t3` succeeds. A pass holds `~/.config/hive/pr-events.lock`, so `hive pr-events --once` and `hive connect` never run a pass at the same time. The lock is written whole. It is taken over when its process is gone, when it names this process, or when it is older than a pass can run. A send in flight at shutdown is allowed to finish.
|
|
92
|
+
- A send that fails, times out or was cut off by a crash may still have been queued, so it stays a retry and is never resent blindly. The cursor moves on, so one bad thread does not hold up the others. Repeated events such as `enqueued` can have identical text, so matching is done by T3 message id. Each confirmed send records the message id that `t3 thread send --json` returns. A retry is done only when it finds a user message with its exact text, from 60 seconds before its first attempt, that no confirmed send and no older retry already accounts for. T3 Code records a queued message with its queued run, so a queued message counts too. Otherwise the retry waits while the thread has a run in progress, and for two minutes after its last attempt, so a send that landed late is seen first. Only then is it sent again. A retry is dropped after 10 failures spanning at least 24 hours, or when more than 200 retries are waiting.
|
|
93
|
+
- A send that T3 Code reports as `steered` or `restarted` rather than queued is logged as an error.
|
|
94
|
+
- Each pass makes at most 20 `t3` calls and stops after 3 failures in a row. It then holds the cursor before the event it stopped in. On the first pull on a machine, events from more than an hour before that pull are skipped.
|
|
95
|
+
|
|
96
|
+
Use `HIVE_PR_EVENTS=on hive pr-events --once` to deliver one time, and `hive pr-events --dry-run` to print the messages without sending them or moving the cursor. The dry run works with delivery off.
|
|
97
|
+
|
|
98
|
+
## Setup
|
|
99
|
+
|
|
100
|
+
`npx @overcy/hive` (the same as `hive setup`) turns a new machine into a Hive node. It runs ten steps in order, stops at the first one that fails, and keeps the desired config and what it applied in `~/.config/hive/setup.json` (mode 0600). It keeps no place to resume from. The next run starts at the first step again.
|
|
101
|
+
|
|
102
|
+
| Step | What it does |
|
|
103
|
+
|---|---|
|
|
104
|
+
| preflight | Checks the OS, CPU, Node 22, git, tar, npx, 5 GB of disk and that the server answers. Names every problem at once. |
|
|
105
|
+
| login | Reuses `hive login`. Skipped when a valid sign-in exists. |
|
|
106
|
+
| role | `--role`, else the role saved last time, else the team default, else a prompt. |
|
|
107
|
+
| enroll | Reuses `hive connect` registration and sends cores, RAM and role. |
|
|
108
|
+
| model-access | Asks Hive where this team's models come from (`GET /api/v0/nodes/me/model-access`) and stores the answer in the OS keychain (proved by a real write and read, else `~/.config/hive/model-access.json`, 0600). Generates a local port and key and writes the lane env to `hive.env`: `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `HIVE_LOCAL_KEY`, `HIVE_LOCAL_PORT` and `HIVE_CODEX_HOME`. Your own `~/.claude` and `~/.codex` are never touched unless you pass `--configure-agents`. |
|
|
109
|
+
| lanes | Downloads the pinned overcy-hive release, checks its sha256, unpacks it to `~/.local/share/hive/<version>` and runs its `install/install-local.sh --role <role> --json`. The `slots` it prints is the lane cap. The CLI computes no slot count. It writes the number to `hive.env` as `HIVE_BOX_SLOTS` and reports it to Hive as `box.limits.lane_max`, in the drift event and in every reporter post. |
|
|
110
|
+
| env | Writes `~/.config/hive/hive.env` (mode 0600). |
|
|
111
|
+
| cron | Runs the release's `install/apply-cron.sh <role>`. |
|
|
112
|
+
| drift | Runs `drift-check.sh --local` and reports the result to Hive as a status event. |
|
|
113
|
+
| reporter | Installs `hive connect` as a launchd agent (macOS) or a systemd user unit (Linux) and starts it, with absolute paths for node and the CLI. |
|
|
114
|
+
|
|
115
|
+
Roles: `primary`, `worker`, `lite` and `proxy-only`. A `proxy-only` machine skips lanes, cron and drift-check.
|
|
116
|
+
|
|
117
|
+
Flags:
|
|
118
|
+
|
|
119
|
+
| Flag | Meaning |
|
|
120
|
+
|---|---|
|
|
121
|
+
| `--role <role>` | Choose the role. Needed on the first run with `--yes`. |
|
|
122
|
+
| `--yes` | Never prompt. Uses flags, saved answers and defaults. |
|
|
123
|
+
| `--server <url>` | Hive server. Default `https://hive.overcy.ai`. |
|
|
124
|
+
| `--name <name>`, `--team <slug>` | Device name and team, as for `connect`. |
|
|
125
|
+
| `--configure-agents` | For dedicated nodes: also point your global Claude Code and Codex at the local forwarder, only after it answers on 127.0.0.1. Keeps every key you have. |
|
|
126
|
+
| `--install-proxy` | Also run `hive-proxy install` here, to host your own proxy. Only when you ask. |
|
|
127
|
+
| `--dry-run` | Print the plan and change nothing. |
|
|
128
|
+
| `--json` | Print one JSON result on stdout. Progress goes to stderr. |
|
|
129
|
+
|
|
130
|
+
An unknown option or a stray word prints the usage and exits 1 without running anything. `--help` prints it and exits 0.
|
|
131
|
+
|
|
132
|
+
Every run starts at the first step and each step checks the machine against the desired config, then repairs what differs, so a failed run is fixed by running the same command again. The steps live in one ordered list, `STEPS` in `src/bootstrap/registry.ts`. Each entry has an `id`, the ids it `needs`, `applies` (is the step part of this node's checklist), `observe` (read-only) and `repair`. Setup runs `repair`, `hive doctor` runs `observe`, and the step names in the report come from the same list. A `setup.json` written by an older CLI still loads. Its `state` and `since` fields are ignored and dropped on the next write. The desired config (role, server, slots) is saved in `setup.json`, so `--role` and `--server` stick. A saved server is refused if you pass a different one on an enrolled machine. Moving to `proxy-only` removes the old lane scripts and crontab through the release's `install-local.sh --uninstall` and `apply-cron.sh <role> --remove`.
|
|
133
|
+
|
|
134
|
+
Idempotency: run it again any time. With nothing changed it prints `Already up to date. Nothing changed.` and writes nothing. A newer pin installs into a new `~/.local/share/hive/<version>` directory and upgrades. A hand-edited lane script is restored from the release. A new `--role` re-renders the crontab. The env file keeps every value you set yourself: the installer writes only inside its own `BEGIN hive setup` block and leaves out any key you set above it.
|
|
135
|
+
|
|
136
|
+
Model access: the team picks one method in Hive (its own proxy, bring your own keys, or Hive credits). Overcy hosts no proxy and ships none. Lanes get the forwarder's address from `hive.env`. The lane launcher must export `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and `HIVE_LOCAL_KEY` into each lane process and set `CODEX_HOME=$HIVE_CODEX_HOME`. Lanes talk only to a forwarder on `127.0.0.1`, so a changed method or a rotated token never restarts a lane. The forwarder is part of the long-running reporter and is built in a follow-up, so until then the lanes' local endpoint has nothing listening (`src/setup/forwarder.ts` and `src/setup/model-access.ts` hold the typed seam). If you run your own proxy, `--install-proxy` installs hive-proxy on this machine and tells you to enter its URL and key in Hive.
|
|
137
|
+
|
|
138
|
+
Uninstall notes: `hive logout` revokes the sign-in. Then remove the service (`launchctl bootout gui/$UID/ai.overcy.hive.connect` and delete `~/Library/LaunchAgents/ai.overcy.hive.connect.plist`, or `systemctl --user disable --now hive-connect.service`), delete the `BEGIN hive <role>` block from `crontab -e`, remove the `hive` provider and the `ANTHROPIC_*` entries from `~/.claude/settings.json` and `~/.codex/config.toml`, delete the `hive` `model-access` entry from your keychain, and delete `~/.config/hive`, `~/.local/share/hive` and `~/lanes`. Remove the node in the app to free its plan slot.
|
|
139
|
+
|
|
140
|
+
## Doctor
|
|
141
|
+
|
|
142
|
+
`hive doctor` checks every setup step and prints one row for each: status, detail and the fix. It is read-only. It never writes the config directory, the install manifest or the journal, never prompts, never signs in and never enrolls, so it works on a machine that is not set up. It exits 0 only when every row is `ok` or `skipped`. `--json` prints one document on stdout.
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
$ HIVE_URL=http://127.0.0.1:1 hive doctor
|
|
146
|
+
failing preflight http://127.0.0.1:1 is not reachable (fetch failed (bad port))
|
|
147
|
+
fix: Check the network and the server address. HIVE_URL sets it, and it is http://127.0.0.1:1 now.
|
|
148
|
+
blocked login waiting on preflight
|
|
149
|
+
blocked role waiting on preflight
|
|
150
|
+
...
|
|
151
|
+
1 failing, 9 blocked. `hive setup` repairs what it can, and a needs_action row needs you.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
| Status | Meaning |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `ok` | Nothing to do. |
|
|
157
|
+
| `skipped` | The step does not apply to this node, for example lanes on a `proxy-only` node. |
|
|
158
|
+
| `stale` | Out of date. `hive setup` repairs it, and the steps after it still work. |
|
|
159
|
+
| `failing` | The step does not work. `hive setup` tries to repair it, and every step after it is `blocked`. |
|
|
160
|
+
| `needs_action` | Only a person can fix it, for example `sudo loginctl enable-linger`. The row says how. |
|
|
161
|
+
| `blocked` | Not checked, because a step it needs is broken. The row names that step. |
|
|
162
|
+
|
|
163
|
+
Each step needs the one before it, as setup always ran them, so the first broken step hides the rest until it is fixed. The check for each step asks the same questions the repair asks. Lanes and cron ask the release's own scripts with `--dry-run`, and drift runs `drift-check.sh --local`. Known limit: a step is checked as `setup` would repair it with its saved desired config. Flags such as `--configure-agents` are not known to `doctor`, so it does not look at your global Claude Code and Codex files.
|
|
164
|
+
|
|
165
|
+
## Connect without signing in
|
|
166
|
+
|
|
167
|
+
An owner or admin creates a registration token in the app, under team settings, Connect a node. It works once, expires after 1 hour and is shown once. Give it to the machine in one of three ways:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
npx @overcy/hive connect --token hvr_...
|
|
171
|
+
npx @overcy/hive connect hvr_...
|
|
172
|
+
HIVE_REGISTRATION_TOKEN=hvr_... npx @overcy/hive connect
|
|
173
|
+
npx @overcy/hive connect --token-file /path/to/box.token
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The flag wins over the bare argument, and the bare argument wins over the variable. The CLI sends the token and the key it just generated, and gets back a node token. It never prints or saves the registration token. A machine that is already connected ignores it, so a cloud-init script can run on every boot. A reply lost on the way is retried with the same key and connects the machine once. An expired, used or revoked token is refused with `registration_token_expired`, `registration_token_used` or `registration_token_revoked`. `hive setup --token` does the same through the installer, and skips its sign-in step. `--token-file` reads the token from a file instead, so it never appears in the process list, and deletes the file once the exchange succeeds. A refused or lost exchange keeps the file for the retry. On a machine that is already enrolled a missing file is not an error, so the same command can run on every boot. If the file cannot be deleted, for example a read-only credential mount, the machine still connects and the CLI warns you to delete it. Pass either `--token` or `--token-file`, not both.
|
|
177
|
+
|
|
178
|
+
### Add a node from a script
|
|
179
|
+
|
|
180
|
+
An owner or admin who is signed in with `hive login` can create the node and its registration token without the browser:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
npx @overcy/hive node add overcy-box-1 --team <slug> --token-file /path/to/box.token
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
It posts to `/api/v0/registration-tokens` with your sign-in, writes the token to a new file with mode 0600 and prints only the node name, id and when the token expires. It refuses a path that already exists and never overwrites one. Nothing is minted when the file cannot be created, and a refused request removes the empty file. If the reply is lost, Hive may already have added the node, and its token cannot be shown again. A retry then gets `node_exists`. Remove the node in the app under team settings and run `hive node add` again; the CLI says so when this happens. The plan limit and the 1 hour, works once rules are the same as in the app. Copy the file to the new machine and run `hive connect --token-file` there.
|
|
187
|
+
|
|
188
|
+
## Install manifest
|
|
189
|
+
|
|
190
|
+
Bootstrap records what it created in `$HIVE_HOME/install-manifest.json` (version 2, mode 0600, written atomically), so a later `hive node uninstall` removes only that. It lists paths, the lane worktree root, the reporter service, the crontab block, the key path and the token path, never a token or key value. The file is written ahead of every side effect: before a step creates something, bootstrap confirms it does not exist yet, writes the entry with `"status": "pending"`, creates it, and then rewrites the entry as `"done"`. A kill at any point therefore leaves what bootstrap may have created in the file. A path, service, crontab block or file that existed before bootstrap is never recorded, and a dangling symlink counts as existing. A rerun marks a pending entry done when the thing exists and creates it again under the same entry when it is missing, merges without duplicates, and leaves the file byte-identical, `written_at` included, when nothing changed. A step that finishes without creating something drops its pending entry. The crontab is a list of `{marker, user, status}` entries, `[]` when none. On a role change the new block's entry is added as `pending` while the old one stays `done`, then the cron update runs, the new entry is marked `done`, and only then is the old entry removed, so a kill at any point leaves every block that may exist listed. Removal and uninstall touch only the listed blocks, never every `# BEGIN hive` block, because another install on the same machine may own one. When `$HIVE_HOME` does not exist yet, the first manifest goes to `<parent>/.<name>.install-manifest.json` (`~/..hive.install-manifest.json` for the default `~/.hive`, `/opt/.hive.install-manifest.json` for `HIVE_HOME=/opt/hive`; the full name is kept, leading dot included, so `~/hive` and `~/.hive` never share a journal) with `$HIVE_HOME` listed as pending, then `$HIVE_HOME` is created and the file is renamed into it. The parent must already exist and is never created. `readInstallManifest` checks that sibling first and the in-home file wins when both exist. A version 1 file is read with every entry as done, and a version 2 file with a single crontab object is read as a one-item list. The format stays version 2 because a reader tells the list from the object, and an older reader refuses the list instead of misreading it. `@overcy/hive/bootstrap` exports the `InstallManifest` type and `readInstallManifest`.
|
|
191
|
+
|
|
192
|
+
## Environment
|
|
193
|
+
|
|
194
|
+
| Variable | Meaning |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `HIVE_HOME` | Where `install-manifest.json` is written. Default `~/.hive`. |
|
|
197
|
+
| `HIVE_URL` | Server. Overrides the one saved in `~/.config/hive/config.json` by `setup --server`. Default `https://hive.overcy.ai`. |
|
|
198
|
+
| `HIVE_CONFIG_DIR` | Config directory. Default `~/.config/hive`. |
|
|
199
|
+
| `HIVE_REGISTRATION_TOKEN` | A registration token for `hive connect`, for machines set up by a script. |
|
|
200
|
+
| `HIVE_LANES_DIR` | A directory whose subdirectories are lanes. Each lane reports the minutes since its newest `.log` file changed. |
|
|
201
|
+
| `HIVE_T3_STREAM_ORIGIN` | HTTPS origin of a preconfigured HiveCode tunnel; `off` withdraws it. |
|
|
202
|
+
|
|
203
|
+
## Develop
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
npm ci
|
|
207
|
+
npm run types:check
|
|
208
|
+
npm test
|
|
209
|
+
npm run build
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`e2e/run.sh` runs the whole journey against a local server, with a Playwright browser approving the login. See `.claude/skills/verify/features/cli-login.md`.
|
|
213
|
+
|
|
214
|
+
The connection machine is `src/machine.ts`. Its model and the server's two machines are in `docs/statecharts`.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { KeyFile } from './config.ts';
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly body: Record<string, unknown>;
|
|
6
|
+
readonly serverDate: number | null;
|
|
7
|
+
constructor(status: number, code: string, message: string, body?: Record<string, unknown>, serverDate?: number | null);
|
|
8
|
+
}
|
|
9
|
+
export declare class NetworkError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export declare const AWS_IDENTITY_EXCHANGE_PATH = "/api/v0/nodes/aws-identity";
|
|
13
|
+
export type Fetch = typeof fetch;
|
|
14
|
+
/** `query` is appended to the URL but not signed: the server verifies the path alone. */
|
|
15
|
+
export type CallOptions = {
|
|
16
|
+
query?: Record<string, string>;
|
|
17
|
+
token?: string;
|
|
18
|
+
body?: unknown | ((skewMs: number) => unknown);
|
|
19
|
+
key?: KeyFile;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare class Api {
|
|
24
|
+
readonly baseUrl: string;
|
|
25
|
+
private readonly doFetch;
|
|
26
|
+
private readonly timeoutMs;
|
|
27
|
+
constructor(baseUrl: string, doFetch?: Fetch, timeoutMs?: number);
|
|
28
|
+
private skewMs;
|
|
29
|
+
json<T>(method: string, path: string, options?: CallOptions): Promise<T>;
|
|
30
|
+
private attempt;
|
|
31
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { signRequest } from "./crypto.js";
|
|
2
|
+
export class ApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
body;
|
|
6
|
+
serverDate;
|
|
7
|
+
constructor(status, code, message, body = {}, serverDate = null) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'ApiError';
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.body = body;
|
|
13
|
+
this.serverDate = serverDate;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class NetworkError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'NetworkError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const REQUEST_TIMEOUT_MS = 30_000;
|
|
23
|
+
export const AWS_IDENTITY_EXCHANGE_PATH = '/api/v0/nodes/aws-identity';
|
|
24
|
+
export class Api {
|
|
25
|
+
baseUrl;
|
|
26
|
+
doFetch;
|
|
27
|
+
timeoutMs;
|
|
28
|
+
constructor(baseUrl, doFetch = fetch, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
29
|
+
this.baseUrl = baseUrl;
|
|
30
|
+
this.doFetch = doFetch;
|
|
31
|
+
this.timeoutMs = timeoutMs;
|
|
32
|
+
}
|
|
33
|
+
skewMs = 0;
|
|
34
|
+
async json(method, path, options = {}) {
|
|
35
|
+
try {
|
|
36
|
+
return await this.attempt(method, path, options);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!(error instanceof ApiError) || error.code !== 'timestamp_skew' || options.key === undefined || error.serverDate === null)
|
|
40
|
+
throw error;
|
|
41
|
+
this.skewMs = error.serverDate - Date.now();
|
|
42
|
+
return this.attempt(method, path, options);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async attempt(method, path, options) {
|
|
46
|
+
const payload = typeof options.body === 'function' ? options.body(this.skewMs) : options.body;
|
|
47
|
+
const body = payload === undefined ? '' : JSON.stringify(payload);
|
|
48
|
+
const headers = { accept: 'application/json', 'user-agent': 'overcy-hive-cli/0.2.0' };
|
|
49
|
+
if (body !== '')
|
|
50
|
+
headers['content-type'] = 'application/json';
|
|
51
|
+
if (options.token)
|
|
52
|
+
headers.authorization = `Bearer ${options.token}`;
|
|
53
|
+
if (options.key)
|
|
54
|
+
Object.assign(headers, signRequest(options.key, method, path, body, new Date(Date.now() + this.skewMs)));
|
|
55
|
+
let response;
|
|
56
|
+
try {
|
|
57
|
+
const timeout = AbortSignal.timeout(options.timeoutMs ?? this.timeoutMs);
|
|
58
|
+
const init = { method, headers, signal: options.signal ? AbortSignal.any([options.signal, timeout]) : timeout };
|
|
59
|
+
if (body !== '')
|
|
60
|
+
init.body = body;
|
|
61
|
+
const search = options.query ? `?${new URLSearchParams(options.query).toString()}` : '';
|
|
62
|
+
response = await this.doFetch(`${this.baseUrl}${path}${search}`, init);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new NetworkError(error instanceof Error ? `${error.message}${error.cause instanceof Error ? ` (${error.cause.message})` : ''}` : String(error));
|
|
66
|
+
}
|
|
67
|
+
const text = await response.text();
|
|
68
|
+
let parsed = {};
|
|
69
|
+
try {
|
|
70
|
+
parsed = text === '' ? {} : JSON.parse(text);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
parsed = {};
|
|
74
|
+
}
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const code = typeof parsed.error === 'string' ? parsed.error : `http_${response.status}`;
|
|
77
|
+
const message = typeof parsed.message === 'string' ? parsed.message : `The server answered ${response.status}.`;
|
|
78
|
+
const date = Date.parse(response.headers.get('date') ?? '');
|
|
79
|
+
throw new ApiError(response.status, code, message, parsed, Number.isNaN(date) ? null : date);
|
|
80
|
+
}
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/dist/atomic.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeAtomic(path: string, content: string, mode: number): Promise<void>;
|
package/dist/atomic.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { chmod, mkdir, readlink, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
async function resolveLink(path) {
|
|
4
|
+
let current = path;
|
|
5
|
+
for (let hops = 0; hops < 16; hops++) {
|
|
6
|
+
let link;
|
|
7
|
+
try {
|
|
8
|
+
link = await readlink(current);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return current;
|
|
12
|
+
}
|
|
13
|
+
current = resolve(dirname(current), link);
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Too many symbolic links at ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
export async function writeAtomic(path, content, mode) {
|
|
18
|
+
const target = await resolveLink(path);
|
|
19
|
+
await mkdir(dirname(target), { recursive: true });
|
|
20
|
+
const temp = `${target}.${process.pid}.tmp`;
|
|
21
|
+
await writeFile(temp, content, { mode });
|
|
22
|
+
await chmod(temp, mode);
|
|
23
|
+
await rename(temp, target);
|
|
24
|
+
}
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function sameServer(a, b) {
|
|
2
|
+
try {
|
|
3
|
+
const left = new URL(a);
|
|
4
|
+
const right = new URL(b);
|
|
5
|
+
return left.origin === right.origin && left.pathname.replace(/\/+$/, '') === right.pathname.replace(/\/+$/, '');
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function boundToServer(ctx, saved, what) {
|
|
12
|
+
if (saved === null || sameServer(saved.url, ctx.url))
|
|
13
|
+
return saved;
|
|
14
|
+
ctx.io.err(`The saved ${what} belongs to ${saved.url}, not ${ctx.url}. It is never sent to this server. Set HIVE_URL=${saved.url} to use it.`);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { connect } from 'node:net';
|
|
2
|
+
import { OVERCY_HIVE_KIT } from "./kit.js";
|
|
3
|
+
import { PIN } from "./pin.js";
|
|
4
|
+
import { httpModelAccessSource } from "./model-access.js";
|
|
5
|
+
import { makePrompter } from "./prompt.js";
|
|
6
|
+
import { makeModelAccessStore } from "./secrets.js";
|
|
7
|
+
import { fetchBytes, hostInfo, makeExec } from "./system.js";
|
|
8
|
+
function probeForwarder(port) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const socket = connect({ host: '127.0.0.1', port });
|
|
11
|
+
socket.setTimeout(1000);
|
|
12
|
+
socket.once('connect', () => (socket.destroy(), resolve(true)));
|
|
13
|
+
socket.once('timeout', () => (socket.destroy(), resolve(false)));
|
|
14
|
+
socket.once('error', () => resolve(false));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function timed(exec) {
|
|
18
|
+
return (command, args, options) => Promise.race([exec(command, args, options), new Promise((resolve) => setTimeout(() => resolve({ code: 124, stdout: '', stderr: 'timed out' }), 8000).unref())]);
|
|
19
|
+
}
|
|
20
|
+
export async function makeSetupDeps(ctx, interactive, overrides = {}) {
|
|
21
|
+
const exec = makeExec(ctx.env);
|
|
22
|
+
const host = await hostInfo(ctx.env);
|
|
23
|
+
return {
|
|
24
|
+
exec,
|
|
25
|
+
host,
|
|
26
|
+
kit: OVERCY_HIVE_KIT,
|
|
27
|
+
modelAccessSource: httpModelAccessSource(ctx),
|
|
28
|
+
modelAccessStore: overrides.modelAccessStore ?? (await makeModelAccessStore(timed(exec), host, ctx.store.dir)),
|
|
29
|
+
pin: PIN,
|
|
30
|
+
fetchBytes,
|
|
31
|
+
probeForwarder,
|
|
32
|
+
prompt: makePrompter(interactive),
|
|
33
|
+
...overrides,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Context } from '../context.ts';
|
|
2
|
+
import { type Health } from './plan.ts';
|
|
3
|
+
import { type StepId } from './registry.ts';
|
|
4
|
+
import { type SetupDeps } from './types.ts';
|
|
5
|
+
export type DoctorStatus = Health | 'blocked';
|
|
6
|
+
export type DoctorRow = {
|
|
7
|
+
id: StepId;
|
|
8
|
+
status: DoctorStatus;
|
|
9
|
+
detail: string;
|
|
10
|
+
fix: string | null;
|
|
11
|
+
/** The failing steps this one waits on. Empty unless `status` is `blocked`. */
|
|
12
|
+
blocked_by: StepId[];
|
|
13
|
+
};
|
|
14
|
+
export type DoctorReport = {
|
|
15
|
+
/** True only when every row is `ok` or `skipped`. */
|
|
16
|
+
ok: boolean;
|
|
17
|
+
server: string;
|
|
18
|
+
role: string | null;
|
|
19
|
+
steps: DoctorRow[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Observes every step and changes nothing. It never writes the config
|
|
23
|
+
* directory, the manifest or the journal, and it never prompts. Steps run in
|
|
24
|
+
* STEPS order. A step whose needs are broken is not observed. It is reported as
|
|
25
|
+
* blocked, with the failing steps that hold it, so a machine that is not set up
|
|
26
|
+
* shows the first thing to fix and not ten errors that follow from it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runDoctor(ctx: Context, baseDeps: SetupDeps, signal: AbortSignal): Promise<DoctorReport>;
|
|
29
|
+
export declare function renderDoctor(report: DoctorReport): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { initialSetupFile, prepareRun, readSetupFile } from "./engine.js";
|
|
2
|
+
import { planTick } from "./plan.js";
|
|
3
|
+
import { STEPS } from "./registry.js";
|
|
4
|
+
import { SetupError } from "./types.js";
|
|
5
|
+
const GENERIC_FIX = 'Run `hive setup` and read its error.';
|
|
6
|
+
/**
|
|
7
|
+
* Observes every step and changes nothing. It never writes the config
|
|
8
|
+
* directory, the manifest or the journal, and it never prompts. Steps run in
|
|
9
|
+
* STEPS order. A step whose needs are broken is not observed. It is reported as
|
|
10
|
+
* blocked, with the failing steps that hold it, so a machine that is not set up
|
|
11
|
+
* shows the first thing to fix and not ten errors that follow from it.
|
|
12
|
+
*/
|
|
13
|
+
export async function runDoctor(ctx, baseDeps, signal) {
|
|
14
|
+
const opts = { apiUrl: ctx.url, hiveProxy: 'skip', dryRun: true };
|
|
15
|
+
const preset = new Map();
|
|
16
|
+
let saved = initialSetupFile();
|
|
17
|
+
try {
|
|
18
|
+
saved = await readSetupFile(ctx);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!(error instanceof SetupError))
|
|
22
|
+
throw error;
|
|
23
|
+
preset.set('preflight', { status: 'failing', detail: error.message, fix: 'Fix or delete that file, then run `hive setup`.' });
|
|
24
|
+
}
|
|
25
|
+
let run;
|
|
26
|
+
try {
|
|
27
|
+
run = await prepareRun(ctx, opts, baseDeps, signal, saved);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!(error instanceof SetupError))
|
|
31
|
+
throw error;
|
|
32
|
+
preset.set('lanes', { status: 'failing', detail: error.message, fix: 'Check the --kit-release tag and the network, then run `hive setup`.' });
|
|
33
|
+
run = await prepareRun(ctx, opts, baseDeps, signal, saved, false);
|
|
34
|
+
}
|
|
35
|
+
const rows = [];
|
|
36
|
+
const observed = [];
|
|
37
|
+
for (const [index, step] of STEPS.entries()) {
|
|
38
|
+
// Ask the planner whether anything this step needs is broken. The step's own
|
|
39
|
+
// status does not matter for that, so a placeholder stands in for it.
|
|
40
|
+
const held = planTick([...observed, { id: step.id, status: 'ok' }], STEPS.slice(0, index + 1)).blocked.find((b) => b.id === step.id);
|
|
41
|
+
if (held) {
|
|
42
|
+
const by = held.by;
|
|
43
|
+
rows.push({ id: step.id, status: 'blocked', detail: `waiting on ${by.join(', ')}`, fix: null, blocked_by: by });
|
|
44
|
+
observed.push({ id: step.id, status: 'stale' });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const gate = step.applies(run);
|
|
48
|
+
let seen;
|
|
49
|
+
if (gate !== true)
|
|
50
|
+
seen = { status: 'skipped', detail: gate.skip, fix: null };
|
|
51
|
+
else {
|
|
52
|
+
try {
|
|
53
|
+
seen = preset.get(step.id) ?? (await step.observe(run));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (signal.aborted)
|
|
57
|
+
throw error;
|
|
58
|
+
seen = { status: 'failing', detail: `the check itself failed: ${error instanceof Error ? error.message : String(error)}`, fix: GENERIC_FIX };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
rows.push({ id: step.id, status: seen.status, detail: seen.detail, fix: seen.fix, blocked_by: [] });
|
|
62
|
+
observed.push({ id: step.id, status: seen.status });
|
|
63
|
+
}
|
|
64
|
+
return { ok: rows.every((row) => row.status === 'ok' || row.status === 'skipped'), server: ctx.url, role: run.role, steps: rows };
|
|
65
|
+
}
|
|
66
|
+
export function renderDoctor(report) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
for (const row of report.steps) {
|
|
69
|
+
lines.push(`${row.status.padEnd(13)}${row.id.padEnd(14)}${row.detail}`);
|
|
70
|
+
if (row.fix)
|
|
71
|
+
lines.push(`${' '.repeat(27)}fix: ${row.fix}`);
|
|
72
|
+
}
|
|
73
|
+
const counts = new Map();
|
|
74
|
+
for (const row of report.steps)
|
|
75
|
+
if (row.status !== 'ok' && row.status !== 'skipped')
|
|
76
|
+
counts.set(row.status, (counts.get(row.status) ?? 0) + 1);
|
|
77
|
+
const tally = [...counts].map(([status, count]) => `${count} ${status}`).join(', ');
|
|
78
|
+
lines.push(report.ok ? 'Every step checks out.' : `${tally}. \`hive setup\` repairs what it can, and a needs_action row needs you.`);
|
|
79
|
+
return lines;
|
|
80
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Context } from '../context.ts';
|
|
2
|
+
import { type StepId } from './registry.ts';
|
|
3
|
+
import type { Paths, SetupDeps, SetupFile, ResolvedOptions, SetupRun, StepResult } from './types.ts';
|
|
4
|
+
export type BootstrapReport = {
|
|
5
|
+
ok: boolean;
|
|
6
|
+
dry_run: boolean;
|
|
7
|
+
up_to_date: boolean;
|
|
8
|
+
needs_action: boolean;
|
|
9
|
+
role: string | null;
|
|
10
|
+
toolchain: string | null;
|
|
11
|
+
server: string;
|
|
12
|
+
steps: StepResult[];
|
|
13
|
+
error: {
|
|
14
|
+
step: StepId;
|
|
15
|
+
message: string;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
|
18
|
+
export declare function initialSetupFile(): SetupFile;
|
|
19
|
+
export declare function makePaths(ctx: Context, home: string): Paths;
|
|
20
|
+
/**
|
|
21
|
+
* Reads `setup.json`. Only `desired`, `applied` and `last_error` are taken, so a
|
|
22
|
+
* file written before the resume cursor was removed loads cleanly and loses its
|
|
23
|
+
* `state` and `since` on the next write.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readSetupFile(ctx: Context): Promise<SetupFile>;
|
|
26
|
+
/** Builds the run that setup and `hive doctor` both hand to every step. Writes nothing. */
|
|
27
|
+
export declare function prepareRun(ctx: Context, opts: ResolvedOptions, baseDeps: SetupDeps, signal: AbortSignal, saved: SetupFile, resolvePinnedKit?: boolean): Promise<SetupRun>;
|
|
28
|
+
export declare function runSteps(ctx: Context, opts: ResolvedOptions, baseDeps: SetupDeps, signal: AbortSignal): Promise<BootstrapReport>;
|
|
29
|
+
export declare function renderReport(report: BootstrapReport, url: string): string[];
|