@crvouga/homelab 0.23.13 → 0.24.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.
Files changed (177) hide show
  1. package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/aube-lock.yaml +73 -297
  2. package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/package.json +1 -1
  3. package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/aube-lock.yaml +42 -42
  4. package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/package.json +1 -1
  5. package/README.md +54 -76
  6. package/ansible/ubuntu/agent-tool.py +106 -1
  7. package/ansible/ubuntu/heavy.py +142 -0
  8. package/ansible/ubuntu/idle-reboot.py +125 -0
  9. package/ansible/ubuntu/policy.json +58 -3
  10. package/ansible/ubuntu/t3-desktop.yml +7 -0
  11. package/ansible/ubuntu/t3-hang-snapshot.sh +75 -0
  12. package/ansible/ubuntu/t3-headless.yml +7 -0
  13. package/ansible/ubuntu/t3-health.sh +71 -3
  14. package/ansible/ubuntu/t3-policy.yml +14 -5
  15. package/ansible/ubuntu/tasks/packages.yml +2 -0
  16. package/ansible/ubuntu/tasks/recovery.yml +16 -2
  17. package/ansible/ubuntu/tasks/resources.yml +25 -2
  18. package/ansible/ubuntu/tasks/unattended-upgrades.yml +24 -6
  19. package/ansible/ubuntu/tasks/updates.yml +59 -0
  20. package/ansible/ubuntu/wip-guard.py +141 -14
  21. package/bootstrap/doctor.ts +0 -4
  22. package/bootstrap/project-action.sh +4 -5
  23. package/bootstrap/shell-path.ts +17 -19
  24. package/cliproxy/README.md +5 -6
  25. package/cliproxy/config.template.yaml +1 -15
  26. package/cliproxy/docs/health-workflow.example.yml +6 -6
  27. package/cliproxy/docs/model-health.md +8 -8
  28. package/cliproxy/scripts/accounts.py +3 -4
  29. package/cliproxy/scripts/fleet_sync.py +2 -13
  30. package/cliproxy/scripts/ops +3 -21
  31. package/docs/authentication.md +21 -26
  32. package/docs/convergence.md +28 -32
  33. package/docs/declared.md +30 -31
  34. package/docs/durability.md +9 -0
  35. package/docs/github.md +0 -9
  36. package/docs/machine-setup.md +16 -17
  37. package/docs/manager-recovery.md +0 -2
  38. package/docs/operations.md +12 -11
  39. package/docs/releasing.md +18 -21
  40. package/docs/runbooks.md +22 -78
  41. package/docs/support-matrix.md +1 -1
  42. package/docs/ubuntu-sync.md +71 -65
  43. package/docs/worker-contract.md +112 -15
  44. package/examples/fleet.json +0 -1
  45. package/llms.txt +0 -2
  46. package/mise.lock +206 -780
  47. package/mise.toml +12 -27
  48. package/package.json +5 -6
  49. package/schema/check-ids.json +41 -482
  50. package/schema/fleet.schema.json +6 -57
  51. package/schema/roster.schema.json +0 -2
  52. package/src/agent-session-limit.ts +2 -7
  53. package/src/auth-checks.ts +1 -3
  54. package/src/check-owners.ts +0 -13
  55. package/src/check-registry.ts +13 -72
  56. package/src/cli/agent-guide.ts +3 -16
  57. package/src/cli/command-index.ts +0 -12
  58. package/src/cli/fleet-sync-manager.ts +4 -146
  59. package/src/cli/fleet-sync-output.ts +1 -4
  60. package/src/cli/fleet-sync-plan.ts +1 -24
  61. package/src/cli/fleet-sync-remote.ts +2 -1
  62. package/src/cli/fleet-sync-vault.ts +1 -2
  63. package/src/cli/fleet-sync.ts +8 -44
  64. package/src/cli/fleet.ts +1 -2
  65. package/src/cli/program.ts +3 -14
  66. package/src/cli/register-fleet.ts +1 -55
  67. package/src/cli/registry.ts +1 -43
  68. package/src/config.ts +0 -2
  69. package/src/definition.ts +8 -83
  70. package/src/fleet-config.ts +1 -1
  71. package/src/ide/definition.ts +2 -29
  72. package/src/ide/super.ts +4 -35
  73. package/src/ide/t3.ts +9 -38
  74. package/src/manager-sync.ts +1 -1
  75. package/src/node-converge-linux.ts +4 -47
  76. package/src/node-converge-shared.ts +1 -22
  77. package/src/{agents/toolchain.ts → pinned-path.ts} +0 -17
  78. package/src/platform/agent-oom-check.ts +104 -0
  79. package/src/platform/t3-policy.ts +23 -36
  80. package/src/platform/t3-service.ts +117 -0
  81. package/src/platform/wip-guard-check.ts +65 -0
  82. package/src/remote-entry.ts +2 -41
  83. package/src/repair-catalog.ts +0 -30
  84. package/src/schedule-check.ts +17 -4
  85. package/src/service-auth.ts +0 -50
  86. package/src/state/litestream.ts +1 -1
  87. package/src/t3/retire-providers.ts +79 -0
  88. package/src/t3/version.ts +1 -1
  89. package/src/transport.ts +2 -6
  90. package/src/types.ts +0 -2
  91. package/src/version-parity.ts +0 -8
  92. package/src/worker-access-checks.ts +0 -75
  93. package/src/worker-host-checks.ts +78 -1
  94. package/src/worker-policy.ts +0 -2
  95. package/src/worker-readiness.ts +2 -0
  96. package/src/worker-sizing.ts +25 -0
  97. package/.mise/locks/azure-cli/2.93.0~a837e014/pyproject.toml +0 -5
  98. package/.mise/locks/azure-cli/2.93.0~a837e014/uv.lock +0 -2841
  99. package/.mise/locks/gemini/0.71.1~84aac8e6/aube-lock.yaml +0 -124
  100. package/.mise/locks/gemini/0.71.1~84aac8e6/package.json +0 -12
  101. package/agents/antigravity-proxy.ts +0 -3
  102. package/agents/audit.md +0 -88
  103. package/agents/bin/agy +0 -10
  104. package/agents/bin/antigravity +0 -10
  105. package/agents/bin/claude +0 -10
  106. package/agents/bin/codex +0 -10
  107. package/agents/bin/grok +0 -10
  108. package/agents/bin/opencode +0 -10
  109. package/agents/claude-proxy +0 -5
  110. package/agents/claude-proxy.ts +0 -3
  111. package/agents/codex-proxy.ts +0 -3
  112. package/agents/grok-proxy.ts +0 -3
  113. package/agents/managed-proxy.ts +0 -109
  114. package/agents/opencode-proxy.ts +0 -3
  115. package/agents/registry.json +0 -209
  116. package/agents/registry.schema.json +0 -149
  117. package/agents/setup.md +0 -158
  118. package/agents/t3.json +0 -40
  119. package/ansible/agents/agents.yml +0 -135
  120. package/ansible/agents/commands.yml +0 -32
  121. package/ansible/agents/receipts.yml +0 -19
  122. package/ansible/agents/templates/antigravity.settings.json.j2 +0 -3
  123. package/ansible/agents/templates/claude.settings.json.j2 +0 -3
  124. package/ansible/agents/templates/codex.config.toml.j2 +0 -11
  125. package/ansible/agents/templates/gemini.settings.json.j2 +0 -14
  126. package/ansible/agents/templates/grok.config.toml.j2 +0 -25
  127. package/ansible/agents/templates/opencode.json.j2 +0 -24
  128. package/ansible/agents/templates/receipt.json.j2 +0 -10
  129. package/ansible/t3/provider-keys.yml +0 -24
  130. package/docs/accounts.md +0 -256
  131. package/src/accounts/checks.ts +0 -226
  132. package/src/accounts/context.ts +0 -77
  133. package/src/accounts/propagate.ts +0 -62
  134. package/src/accounts/roster.ts +0 -112
  135. package/src/accounts/selection.ts +0 -67
  136. package/src/accounts/sessions.ts +0 -354
  137. package/src/agents/account-relay.ts +0 -279
  138. package/src/agents/accounts.ts +0 -94
  139. package/src/agents/admission.ts +0 -65
  140. package/src/agents/audit.ts +0 -77
  141. package/src/agents/cli.ts +0 -13
  142. package/src/agents/command.ts +0 -257
  143. package/src/agents/commands.ts +0 -127
  144. package/src/agents/converge.ts +0 -339
  145. package/src/agents/doctor.ts +0 -107
  146. package/src/agents/errors.ts +0 -2
  147. package/src/agents/files.ts +0 -43
  148. package/src/agents/fleet-verify.ts +0 -195
  149. package/src/agents/launch.ts +0 -361
  150. package/src/agents/native-verify.ts +0 -738
  151. package/src/agents/provider-errors.ts +0 -57
  152. package/src/agents/registry.ts +0 -61
  153. package/src/agents/render.ts +0 -121
  154. package/src/agents/round-trip.ts +0 -192
  155. package/src/agents/secrets.ts +0 -48
  156. package/src/agents/verify-cache.ts +0 -164
  157. package/src/agents/verify.ts +0 -129
  158. package/src/cli/fleet-accounts.ts +0 -294
  159. package/src/cli/fleet-sync-accounts.ts +0 -62
  160. package/src/cli/node-deployment.ts +0 -34
  161. package/src/cli/node-sync.ts +0 -121
  162. package/src/cli/node-t3.ts +0 -35
  163. package/src/cli/t3/command.ts +0 -91
  164. package/src/cli/t3/register.ts +0 -56
  165. package/src/configure.ts +0 -271
  166. package/src/github/copilot.ts +0 -54
  167. package/src/t3/accounts.ts +0 -90
  168. package/src/t3/antigravity.ts +0 -93
  169. package/src/t3/desired.ts +0 -174
  170. package/src/t3/diagnostics.ts +0 -42
  171. package/src/t3/models.ts +0 -354
  172. package/src/t3/names-check.ts +0 -53
  173. package/src/t3/names.ts +0 -155
  174. package/src/t3/plan.ts +0 -106
  175. package/src/t3/provider-keys.ts +0 -49
  176. package/src/t3/providers.ts +0 -102
  177. package/src/t3/reconcile.ts +0 -133
package/docs/accounts.md DELETED
@@ -1,256 +0,0 @@
1
- # Provider accounts
2
-
3
- **The rule.** Provider accounts exist only as the CLI proxy's credential files
4
- on the manager. Every node and IDE gets a view derived from them, and nothing
5
- on a node holds a provider login of its own. T3 offers one instance per
6
- account, named `<Provider> <account email>`, and every launcher reaches the
7
- provider through the proxy.
8
-
9
- ## The roster
10
-
11
- ```sh
12
- npx @crvouga/homelab accounts # provider, index, label, state, cooldowns and when they clear
13
- npx @crvouga/homelab accounts --diff # and what this machine offers against it
14
- ```
15
-
16
- Each account has one state, derived from its credential file and the proxy's
17
- management API:
18
-
19
- | State | Meaning |
20
- | ----------------- | -------------------------------------------------------------------------- |
21
- | `usable` | Serves requests |
22
- | `cooling-down` | The provider limited it; `until` says when it clears, when the proxy knows |
23
- | `refresh-failing` | Its token refresh fails for now, and its access token is still valid |
24
- | `needs-login` | The provider refused its refresh token: only signing in again helps |
25
- | `removed` | Disabled on the proxy |
26
-
27
- The proxy also holds back single models: an account out of quota for one
28
- model still serves its others. Such an account stays `usable`, and its
29
- `cooldowns` name each model held back, the proxy's reason (`quota`,
30
- `payment_required`, …) and `until`. `proxy:account:<provider>` says so in its
31
- summary: "account 1 cooling-down on MODEL until …".
32
-
33
- The index of an account is its position among its provider's accounts, sorted
34
- by sign-in email. Checks name accounts by provider and index only.
35
-
36
- The **roster version** is a digest of the routing prefixes of the accounts.
37
- The manager computes it from the credential files and every node from the
38
- proxy's model list, so the two agree exactly when a node offers what the
39
- proxy holds.
40
-
41
- ## Checks
42
-
43
- | Check | Fails when |
44
- | ---------------------------------- | ------------------------------------------------------------------------------------------------------ |
45
- | `proxy:account:<provider>` | The provider has no usable account; it warns below `services.proxy.accounts.minimumUsable` (default 2) |
46
- | `accounts:roster-current` | The node offers another roster version than the proxy's |
47
- | `accounts:native-login` | (warns) An agent CLI on the node keeps a provider login of its own |
48
- | `proxy:reachable-from` | The node gets no answer from the proxy; it warns above two seconds |
49
- | `agent:<tool>:account-<n>:session` | That account's instance does not run a session (see below); it warns while the account is cooling down |
50
- | `agent:<tool>:removed-<n>:session` | The node still offers an instance for an account the proxy no longer holds |
51
- | `t3:models` | (warns) An account's instance shows or starts on a model its account does not serve |
52
-
53
- A session check that does not pass says which of these it found:
54
-
55
- | Summary starts with | Status | Meaning |
56
- | ------------------------------------- | ------ | ---------------------------------------------------------------------------------------------- |
57
- | `AGENT_ACCOUNT_COOLING_DOWN` | warn | The provider limited the account. It clears on its own |
58
- | `AGENT_ACCOUNT_VERIFICATION_REQUIRED` | fail | The provider answers "Verify your account": a person completes it with the provider |
59
- | `AGENT_ACCOUNT_AUTH_REJECTED` | fail | The account's credentials were refused; `accounts` says whether it needs a login |
60
- | `AGENT_ACCOUNT_SESSION_TIMED_OUT` | fail | The session never ended, and the proxy named no cooldown and no refusal. Not a sign-in failure |
61
- | `AGENT_ACCOUNT_SESSION_FAILED` | fail | Anything else |
62
-
63
- OpenCode retries a request the proxy refuses until the session's deadline and
64
- prints nothing, so a limited account ends as a timeout. A node then asks the
65
- proxy for that account's model directly, with its own client key: a model the
66
- proxy holds back for a limit answers 429 at once, without a request to the
67
- provider, and the session is `AGENT_ACCOUNT_COOLING_DOWN`. An account the
68
- proxy holds back because its provider refused it answers 503 with the
69
- provider's last words, read for a verification ("Verify your account", or the
70
- reason `VALIDATION_REQUIRED`) or refused credentials. A model it does not hold
71
- back is asked of the provider once, with one bounded request, and its answer
72
- is read the same way. A report never repeats what the provider said.
73
-
74
- A cooling-down session names when the cooldown clears, when the proxy says
75
- so: "… is rate limited until 2027-01-15T09:30:00Z". The instant is read from
76
- the `Retry-After` of the proxy's 429 (else the `reset_seconds` of its
77
- `model_cooldown` error), or from the instant the fleet's relay prints when it
78
- refuses a request for an account it holds back. An answer that names no time
79
- adds none to the summary; `accounts` still lists `until` per model. The
80
- proxy names a time when the provider did: a limit the provider gave no time
81
- for is held for a moment and asked again.
82
-
83
- `features/accounts/proxy-box.feature` runs the pinned proxy in a container
84
- against a stand-in provider, on every pull request, so these answers are the
85
- proxy's own and not an assumption: the 429 and its `Retry-After`, the
86
- `model_cooldown` error of the OpenAI protocols, and the 503 that carries a
87
- provider's demand for verification.
88
-
89
- Session results are cached under a key that holds the roster version and the
90
- version of the client key, so any account change or key rotation re-verifies
91
- at once. A pass is reused for six hours.
92
-
93
- A session that cannot pass must not hold every sync up for its 150 second
94
- deadline on every node:
95
-
96
- - The proxy is asked for the account's model **before** the session is
97
- launched. An account it holds back, wants verified or refuses is reported
98
- at once and no session is started.
99
- - What a session found when it did not pass is taken as found for ten
100
- minutes. Its check says so: "(found 4m ago; a session that does not pass is
101
- run again after 10m or on any change)".
102
- - A session that ran into its deadline is given 30 seconds the next time,
103
- until it passes or six hours have gone by.
104
-
105
- ## Models per account
106
-
107
- Accounts of one provider are not entitled to the same models. Each tool has
108
- preferred defaults, in order (`proxy.accounts` in `agents/registry.json`): an
109
- account's launcher and its T3 instance start on the first one the account
110
- serves. In T3, an account's instance hides the models of T3's catalogue that
111
- its account does not serve (`providerModelPreferences` in T3's settings), so
112
- it shows only what works; `sync` writes that, and shows a model again
113
- when the account serves it. T3 opens an instance on its own catalogue's
114
- default when the account serves it, and on the first preferred default
115
- otherwise.
116
-
117
- `t3:models` warns with `T3_MODELS_MISMATCH` when an account serves none of
118
- its tool's preferred defaults (it then starts on its first model by name) or
119
- nothing of T3's catalogue.
120
-
121
- ## When T3 asks for sign-in on several machines
122
-
123
- Start on the manager, in the project that pins homelab. To list the sign-ins
124
- that need attention across providers, run:
125
-
126
- ```sh
127
- npx @crvouga/homelab accounts --auth-plan --json
128
- ```
129
-
130
- If the command reports an error or the roster is unavailable, resolve that
131
- before interpreting an empty list. For each result, check the current account
132
- label with `homelab accounts` before renewing it. Use the provider's documented
133
- sign-in method for the client, account plan and intended use. Where the
134
- provider permits proxy access, renew the account once on the manager using
135
- the command below. Complete consent and any MFA yourself. Homelab then
136
- propagates the instance configuration to the workers. Where the provider
137
- requires its own client, complete its sign-in there. A successful proxy login
138
- alone does not establish permission to use a subscription through a proxy.
139
-
140
- If T3 displays “Sign in with Google to see Antigravity limits” or asks
141
- for a turn to renew limits, update the consumer project's homelab pin to
142
- the release containing the T3 quota fix and run `homelab converge` on the
143
- manager. Check the T3 version on the manager and each worker. An offline
144
- worker needs to converge when it reconnects.
145
-
146
- Google supports ACP for external Antigravity clients. The T3 release pinned
147
- by homelab removes the native and proxy quota readers that called Google's
148
- internal APIs. Antigravity subscription windows are unavailable in T3 until
149
- Google exposes them over a supported interface. Use the official Antigravity
150
- client for limits. [Upstream change](https://github.com/pingdotgg/t3code/pull/43026)
151
-
152
- ## Adding, signing in again, removing
153
-
154
- ```sh
155
- npx @crvouga/homelab accounts --add claude
156
- npx @crvouga/homelab accounts --relogin codex 2
157
- npx @crvouga/homelab accounts --remove codex 2
158
- ```
159
-
160
- A sign-in writes into a staging directory beside the credentials; only a
161
- complete credential is moved in, with one rename, so an interrupted sign-in
162
- leaves nothing behind. Routing prefixes are applied in the same command. Every
163
- change is then propagated to every node.
164
-
165
- ## Propagation without a full sync
166
-
167
- ```sh
168
- npx @crvouga/homelab converge --only accounts
169
- ```
170
-
171
- On the manager and every worker at once, each node re-reads the proxy's
172
- roster and rewrites only its per-account T3 instances and the models each
173
- shows. T3 watches its settings, so nothing restarts and no running turn ends. Instance ids derive
174
- from the account's routing prefix and stay the same. A node that cannot be
175
- reached catches up on the next propagation or sync; until then
176
- `accounts:roster-current` reports the version it has.
177
-
178
- ## Choosing an account
179
-
180
- Unpinned requests go through a loopback relay on every node. When the fleet
181
- declares a policy for a provider, the relay picks the account of each request:
182
-
183
- ```json
184
- "services": {
185
- "proxy": {
186
- "endpoint": "https://cli-proxy.example.com",
187
- "accounts": {
188
- "minimumUsable": 2,
189
- "selection": {
190
- "codex": { "strategy": "fill-first", "order": ["a@example.com"] }
191
- }
192
- }
193
- }
194
- }
195
- ```
196
-
197
- | Strategy | Order |
198
- | ------------------------ | ------------------------------------------------ |
199
- | `fill-first` | The same order for every request |
200
- | `round-robin` | Each request starts one account further along |
201
- | `least-recently-limited` | The account limited longest ago (or never) first |
202
-
203
- The order is the accounts `order` names, in that order, then the others in
204
- the order of their routing prefix. A quota or authentication refusal sends
205
- the request on to the next account, and the refused one cools down for its
206
- `Retry-After` (a minute without one). Without a policy the proxy's own
207
- fill-first pool chooses. An instance pinned to one account answers "This
208
- account is cooling down until …" and names the other instances of its
209
- provider.
210
-
211
- ## Proxy outages
212
-
213
- Every relayed launch (Claude, Codex, Gemini and Antigravity, pinned or not)
214
- retries a proxy that does not answer for about a minute. If it stays down,
215
- the agent gets one distinct, retryable error: "The CLI proxy has been
216
- unreachable since …".
217
-
218
- ## Checkpoints and the proxy state
219
-
220
- Each checkpoint records a short digest of every credential's refresh token,
221
- never the token. After restoring an older checkpoint, `restore-verify
222
- RESTORED --newest NEWEST` names exactly the accounts whose refresh token the
223
- provider has since replaced (`needs-login: <provider> <index>`).
224
-
225
- `cliproxy/scripts/lease.py` is a fencing lease on the proxy state: a second
226
- proxy cannot take it while the first holds it, and taking over an expired
227
- lease fences the old holder.
228
-
229
- ## Client keys
230
-
231
- `homelab proxy issue-key|rotate-key|retire-key|revoke-key NODE` keep one
232
- proxy client key per node in the manager's key ring. A rotation keeps the old
233
- key accepted until `retire-key`, so no running agent fails while nodes move
234
- over. Revoking one node's key leaves the others working.
235
- `homelab proxy client-keys` reports each node's key by fingerprint only.
236
-
237
- ## Not yet done
238
-
239
- - The proxy does not notify anyone when an account turns `needs-login`, and
240
- no watcher on the manager triggers propagation or a checkpoint when a
241
- credential file changes. Run `converge --only accounts` or
242
- `accounts` instead.
243
- - Nothing forces a refresh of every account after a restore. The digest
244
- comparison above is offline.
245
- - The lease is not yet taken by the proxy service at start, and its
246
- production store (the checkpoint bucket) is not wired.
247
- - Per-node client keys are not yet distributed to nodes through the secrets
248
- provider, so nodes still present the shared key. No
249
- `proxy:client-key-current` check exists yet.
250
- - OpenCode and Grok read the proxy's address from rendered configuration and
251
- are not relayed yet. There is no warm standby proxy.
252
- - The selection policy is applied by the client relay; the proxy itself stays
253
- fill-first.
254
- - A sign-in uses the provider's device code where the proxy offers one.
255
- Other providers print a callback URL, and no loopback forward is managed
256
- for them.
@@ -1,226 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { homedir } from 'node:os';
3
- import { join } from 'node:path';
4
- import type { Check } from '../types';
5
- import type { ProxyRoster, RosterAccount } from './roster';
6
-
7
- /** Fewer usable accounts than this warns unless the fleet says otherwise. */
8
- export const MINIMUM_USABLE = 2;
9
-
10
- /** `proxy:account:<provider>`: fails when a provider has no usable account,
11
- * warns below the fleet's minimum. Accounts are named by their opaque index
12
- * and counts only, never by an identifier.
13
- */
14
- export function providerAccountChecks(
15
- roster: ProxyRoster,
16
- minimumUsable = MINIMUM_USABLE
17
- ): Check[] {
18
- const providers = new Map<string, RosterAccount[]>();
19
- for (const account of roster.accounts)
20
- if (account.state !== 'removed')
21
- providers.set(account.provider, [
22
- ...(providers.get(account.provider) ?? []),
23
- account,
24
- ]);
25
- return [...providers.entries()]
26
- .sort(([a], [b]) => a.localeCompare(b))
27
- .map(([provider, accounts]) =>
28
- providerCheck(provider, accounts, minimumUsable)
29
- );
30
- }
31
-
32
- /** "account 2 needs-login, account 3 cooling-down until …"; a usable account
33
- * with a model held back says which: "account 1 cooling-down on m until …".
34
- */
35
- const describe = (accounts: RosterAccount[]): string[] =>
36
- accounts.flatMap((account) =>
37
- account.state === 'usable'
38
- ? account.cooldowns.map(
39
- (cooldown) =>
40
- `account ${account.index} cooling-down on ${cooldown.model} until ${cooldown.until}`
41
- )
42
- : [
43
- `account ${account.index} ${account.state}${account.until ? ` until ${account.until}` : ''}`,
44
- ]
45
- );
46
-
47
- function reloginRemedy(provider: string, accounts: RosterAccount[]) {
48
- const login = accounts.find((account) => account.state === 'needs-login');
49
- return login
50
- ? {
51
- action: `Sign ${provider} account ${login.index} in again. Signing in is the only manual step.`,
52
- command: `homelab accounts --relogin ${provider} ${login.index}`,
53
- }
54
- : undefined;
55
- }
56
-
57
- function providerCheck(
58
- provider: string,
59
- accounts: RosterAccount[],
60
- minimumUsable: number
61
- ): Check {
62
- const usable = accounts.filter((account) => account.state === 'usable');
63
- const id = `proxy:account:${provider}`;
64
- const detail = describe(accounts);
65
- const counted = `${usable.length} of ${accounts.length} ${provider} accounts usable${detail.length ? ` (${detail.join(', ')})` : ''}`;
66
- const remedy = reloginRemedy(provider, accounts);
67
- if (usable.length === 0) return noneUsable(provider, accounts);
68
- if (usable.length < minimumUsable)
69
- return {
70
- id,
71
- status: 'warn',
72
- summary: `${counted}; one limit or expired login away from none.`,
73
- remedy: remedy ?? {
74
- action: `Add a ${provider} account: homelab accounts --add ${provider}.`,
75
- },
76
- };
77
- return {
78
- id,
79
- status: 'pass',
80
- summary: `${counted}.`,
81
- ...(remedy ? { remedy } : {}),
82
- };
83
- }
84
-
85
- /** No usable account: say why, and when the first cooldown clears. */
86
- function noneUsable(provider: string, accounts: RosterAccount[]): Check {
87
- const clears = accounts
88
- .map((account) => account.until)
89
- .filter((until): until is string => until !== null)
90
- .sort()[0];
91
- const cooling = accounts.every((account) => account.state === 'cooling-down');
92
- const wait = `Wait until ${clears ?? 'the provider lifts the limit'}, or add an account: homelab accounts --add ${provider}.`;
93
- return {
94
- id: `proxy:account:${provider}`,
95
- status: 'fail',
96
- summary: cooling
97
- ? `No usable ${provider} account: every one is cooling down${clears ? `; the first clears at ${clears}` : ''}.`
98
- : `No usable ${provider} account (${describe(accounts).join(', ')}).`,
99
- remedy: reloginRemedy(provider, accounts) ?? {
100
- action: cooling
101
- ? wait
102
- : `Inspect the ${provider} accounts with homelab accounts.`,
103
- },
104
- };
105
- }
106
-
107
- /** `accounts:roster-current`: this node offers exactly the accounts the
108
- * proxy holds. `proxy` is the proxy's roster version (null: unreadable),
109
- * `node` the version of the account instances the node exposes.
110
- */
111
- export function rosterCurrentCheck(proxy: string | null, node: string): Check {
112
- if (proxy === null)
113
- return {
114
- id: 'accounts:roster-current',
115
- status: 'warn',
116
- summary: `The proxy's account roster could not be read; this node offers roster version ${node}.`,
117
- remedy: {
118
- action: 'Check proxy:reachable-from, then run check again.',
119
- },
120
- };
121
- return proxy === node
122
- ? {
123
- id: 'accounts:roster-current',
124
- status: 'pass',
125
- summary: `This node offers the proxy's account roster (version ${node}).`,
126
- }
127
- : {
128
- id: 'accounts:roster-current',
129
- status: 'fail',
130
- summary: `This node offers account roster version ${node}; the proxy holds ${proxy}.`,
131
- remedy: {
132
- action: 'Propagate the accounts to every node without a full sync.',
133
- command: 'homelab converge --only accounts',
134
- },
135
- };
136
- }
137
-
138
- /** Where agent CLIs keep a provider login of their own, relative to home. */
139
- export const NATIVE_LOGINS: Record<string, string[]> = {
140
- claude: ['.claude/.credentials.json'],
141
- codex: ['.codex/auth.json'],
142
- gemini: ['.gemini/oauth_creds.json'],
143
- opencode: ['.local/share/opencode/auth.json'],
144
- grok: ['.grok/auth.json'],
145
- };
146
-
147
- /** The provider logins found on this node outside the proxy path. */
148
- export function nativeLogins(
149
- home = homedir(),
150
- exists: (path: string) => boolean = existsSync
151
- ): { cli: string; path: string }[] {
152
- return Object.entries(NATIVE_LOGINS).flatMap(([cli, paths]) =>
153
- paths
154
- .map((path) => join(home, path))
155
- .filter((path) => exists(path))
156
- .map((path) => ({ cli, path }))
157
- );
158
- }
159
-
160
- /** `accounts:native-login`: a node holds no provider login of its own, so it
161
- * can use no account the proxy does not know. Names the CLIs only.
162
- */
163
- export function nativeLoginCheck(found: { cli: string }[]): Check {
164
- const clis = [...new Set(found.map((login) => login.cli))].sort();
165
- return clis.length === 0
166
- ? {
167
- id: 'accounts:native-login',
168
- status: 'pass',
169
- summary:
170
- 'No agent CLI on this node holds a provider login of its own; every account comes from the proxy.',
171
- }
172
- : {
173
- id: 'accounts:native-login',
174
- status: 'warn',
175
- summary: `Provider logins outside the proxy path: ${clis.join(', ')}.`,
176
- remedy: {
177
- action:
178
- 'Provider accounts belong on the proxy. Remove these logins (opt-in), and sign the account in on the proxy if it is needed.',
179
- command: 'homelab accounts --remove-native-logins --yes',
180
- },
181
- };
182
- }
183
-
184
- /** `proxy:reachable-from`: this node reaches the proxy, and how fast. */
185
- export async function proxyReachableCheck(
186
- endpoint: string,
187
- send: typeof fetch = fetch,
188
- clock: () => number = () => performance.now()
189
- ): Promise<Check> {
190
- const started = clock();
191
- try {
192
- // Unauthenticated: the proxy refuses it, which proves it answered.
193
- const response = await send(endpoint + '/v1/models', {
194
- redirect: 'error',
195
- signal: AbortSignal.timeout(10_000),
196
- });
197
- await response.body?.cancel().catch(() => undefined);
198
- const latency = Math.round(clock() - started);
199
- const answered = response.status < 500;
200
- return {
201
- id: 'proxy:reachable-from',
202
- status: !answered ? 'fail' : latency > 2000 ? 'warn' : 'pass',
203
- summary: answered
204
- ? `The proxy answered in ${latency} ms.`
205
- : 'PROXY_UNREACHABLE: the route to the proxy answered, the proxy did not.',
206
- ...(answered
207
- ? {}
208
- : {
209
- remedy: {
210
- action:
211
- 'Agents retry for about a minute and then report "proxy unreachable". Check the proxy on the manager: homelab proxy status.',
212
- },
213
- }),
214
- };
215
- } catch {
216
- return {
217
- id: 'proxy:reachable-from',
218
- status: 'fail',
219
- summary: 'PROXY_UNREACHABLE: no answer from the proxy.',
220
- remedy: {
221
- action:
222
- 'Agents retry for about a minute and then report "proxy unreachable". Check this node’s tailnet and the proxy on the manager: homelab proxy status.',
223
- },
224
- };
225
- }
226
- }
@@ -1,77 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { homedir } from 'node:os';
3
- import { join, resolve } from 'node:path';
4
- import { accountPrefix, discoverAccounts } from '../agents/accounts';
5
- import { proxyKey } from '../agents/secrets';
6
- import { registry } from '../agents/registry';
7
- import type { AccountContext } from '../agents/native-verify';
8
- import type { Check } from '../types';
9
- import {
10
- nativeLoginCheck,
11
- nativeLogins,
12
- proxyReachableCheck,
13
- rosterCurrentCheck,
14
- } from './checks';
15
- import { liveVersion, rosterVersion } from './roster';
16
- import { exposedInstances, proxyVerdict, type Instance } from './sessions';
17
-
18
- /** This machine's T3 settings, where its account instances are written. */
19
- export const t3Settings = (): string =>
20
- join(
21
- resolve(process.env['T3CODE_HOME'] ?? join(homedir(), '.t3')),
22
- 'userdata/settings.json'
23
- );
24
-
25
- /** A short digest of the client key: its version, never its value. */
26
- export const keyVersion = (key: string): string =>
27
- createHash('sha256').update(key).digest('hex').slice(0, 12);
28
-
29
- /** The roster version of the instances a node offers. */
30
- export function exposedVersion(instances: Instance[]): string {
31
- return rosterVersion(
32
- instances.flatMap((instance) => {
33
- try {
34
- return [accountPrefix(instance.tool, instance.account)];
35
- } catch {
36
- return [];
37
- }
38
- })
39
- );
40
- }
41
-
42
- /** The proxy's accounts and what this node offers, read with this node's
43
- * own key; undefined when the proxy or the key is unavailable (the provider
44
- * checks report that).
45
- */
46
- export async function accountContext(
47
- settings = t3Settings()
48
- ): Promise<AccountContext | undefined> {
49
- try {
50
- const key = await proxyKey();
51
- const live = await discoverAccounts(key);
52
- return {
53
- live,
54
- exposed: await exposedInstances(settings),
55
- rosterVersion: liveVersion(live),
56
- keyVersion: keyVersion(key),
57
- consult: (account) => proxyVerdict(account, key),
58
- };
59
- } catch {
60
- return undefined;
61
- }
62
- }
63
-
64
- /** What a node measures about accounts: it reaches the proxy, it offers
65
- * the proxy's roster, and it holds no provider login of its own.
66
- */
67
- export async function nodeAccountChecks(
68
- context: AccountContext | undefined,
69
- settings = t3Settings()
70
- ): Promise<Check[]> {
71
- const exposed = context?.exposed ?? (await exposedInstances(settings));
72
- return [
73
- await proxyReachableCheck(registry.proxy.endpoint),
74
- rosterCurrentCheck(context?.rosterVersion ?? null, exposedVersion(exposed)),
75
- nativeLoginCheck(nativeLogins()),
76
- ];
77
- }
@@ -1,62 +0,0 @@
1
- import { blocking, type Check, type FleetNode, type Runner } from '../types';
2
- import { inspectRemote } from '../transport';
3
- import type { CommandOutcome } from '../cli/contracts';
4
-
5
- export interface Propagation {
6
- /** The enrolled workers. */
7
- nodes: FleetNode[];
8
- /** The approved revision every worker runs. */
9
- revision: string;
10
- /** The bundled remote entry sent to each worker. */
11
- source: string;
12
- /** The manager's own account instances, applied locally. */
13
- manager: () => Promise<Check[]>;
14
- run: Runner;
15
- }
16
-
17
- /** `converge --only accounts`: the account-derived configuration and
18
- * nothing else, on the manager and on every worker at once. Each node
19
- * re-reads the proxy's roster and rewrites only its per-account T3
20
- * instances; T3 watches its settings, so nothing restarts and no running
21
- * turn ends. Instance ids derive from the account's routing prefix, so they
22
- * stay the same and existing threads keep working. A node that cannot be
23
- * reached is reported; it catches up on the next propagation or sync, and
24
- * reports the roster version it has (`accounts:roster-current`) until then.
25
- */
26
- export async function propagateAccounts(
27
- input: Propagation
28
- ): Promise<CommandOutcome> {
29
- const started = Date.now();
30
- const [manager, ...workers] = await Promise.all([
31
- input.manager().then((checks) => ({ node: 'manager', checks })),
32
- ...input.nodes.map((node) =>
33
- inspectRemote(
34
- node,
35
- {
36
- source: input.source,
37
- timeoutMs: 180_000,
38
- action: 'accounts',
39
- expected: { head: input.revision, files: {} },
40
- },
41
- input.run
42
- )
43
- ),
44
- ]);
45
- const nodes = [manager!, ...workers].map((report) => ({
46
- node: report.node,
47
- checks: report.checks,
48
- }));
49
- const ok = nodes.every((node) => !node.checks.some(blocking));
50
- return {
51
- exitCode: ok ? 0 : 1,
52
- data: {
53
- version: 1,
54
- command: 'converge',
55
- only: 'accounts',
56
- ok,
57
- revision: input.revision,
58
- durationMs: Date.now() - started,
59
- nodes,
60
- },
61
- };
62
- }