@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
@@ -1,339 +0,0 @@
1
- import { AgentConfigurationError } from './errors';
2
- import { lstat, mkdir, rm } from 'node:fs/promises';
3
- import { dirname, join, resolve } from 'node:path';
4
- import { randomUUID } from 'node:crypto';
5
- import { digest, registry, type Selection } from './registry';
6
- import { render } from './render';
7
- import { readOwned, fileState, safeParents } from './files';
8
- import { runAnsible } from '../platform/ansible';
9
- import { PACKAGE_ROOT } from '../package-info';
10
- import { runCommand } from '../runner';
11
- import type { CommandResult, Runner } from '../types';
12
-
13
- export type Receipt = {
14
- version: 1;
15
- revision: string;
16
- fingerprint: string;
17
- files: Record<string, string>;
18
- };
19
- export type Context = { root: string; revision: string; selection: Selection };
20
-
21
- /** What `ansible/agents/agents.yml` is given to write one profile. TypeScript
22
- * decides here, beforehand, what is backed up and what each file must hash
23
- * to; the play renders the files from its templates and asserts them.
24
- */
25
- export interface ProfileVariables {
26
- agent_root: string;
27
- agent_node: string;
28
- agent_tool: string;
29
- agent_profile: string;
30
- agent_model: string;
31
- /** Empty for a direct profile: it never names the proxy. */
32
- agent_proxy_endpoint: string;
33
- /** The model of every proxy route, in the registry's order. */
34
- agent_proxy_models: string[];
35
- /** The SHA-256 of each file as src/agents/render.ts specifies it. */
36
- agent_files: Record<string, string>;
37
- /** What the receipt records beside those digests. */
38
- agent_revision: string;
39
- agent_fingerprint: string;
40
- /** Files to copy into ROOT/backups before they are replaced. */
41
- agent_backups: { source: string; dest: string }[];
42
- }
43
-
44
- /** Runs the agents play with these variables. */
45
- export type ProfilePlay = (
46
- variables: ProfileVariables,
47
- receiptOnly?: boolean
48
- ) => Promise<CommandResult>;
49
-
50
- /** The package's agents play, with the Ansible this machine runs. `scratch`
51
- * is where its variables file is kept while it runs (the fleet's private
52
- * run directory by default).
53
- */
54
- export function agentsPlay(
55
- run: Runner = runCommand,
56
- options: { check?: boolean; scratch?: string } = {}
57
- ): ProfilePlay {
58
- const directory = join(PACKAGE_ROOT, 'ansible', 'agents');
59
- return (variables, receiptOnly) =>
60
- runAnsible(
61
- run,
62
- join(directory, 'agents.yml'),
63
- {
64
- cwd: directory,
65
- ...(receiptOnly ? { tags: 'receipt' } : {}),
66
- input: JSON.stringify(variables),
67
- // Inside the two minutes the sync gives `agents apply`.
68
- timeoutMs: 90_000,
69
- ...(options.check ? { check: true } : {}),
70
- },
71
- options.scratch
72
- );
73
- }
74
-
75
- export async function plan(context: Context) {
76
- const { root, selection } = context;
77
- const directory = join(
78
- root,
79
- selection.node,
80
- selection.tool,
81
- selection.profile
82
- );
83
- const receiptPath = join(directory, 'receipt.json');
84
- const raw = await readOwned(receiptPath);
85
- const previous = raw ? parseReceipt(raw) : null;
86
- const outputs = render(selection);
87
- const files = [];
88
- for (const [name, content] of Object.entries(outputs)) {
89
- const path = join(directory, name);
90
- const current = await readOwned(path);
91
- files.push({
92
- name,
93
- path,
94
- content,
95
- state: fileState(current, content, previous?.files[name]),
96
- });
97
- }
98
- const fingerprint = digest(JSON.stringify({ registry, selection, outputs }));
99
- return { directory, receiptPath, raw, previous, files, fingerprint };
100
- }
101
-
102
- /** The full play also enforces private modes. Reapply to repair drift, and
103
- * refuse a profile owned by another account before advancing its evidence. */
104
- async function privateProfile(
105
- context: Context,
106
- result: Awaited<ReturnType<typeof plan>>
107
- ): Promise<boolean> {
108
- if (process.platform === 'win32') return true;
109
- const root = resolve(context.root);
110
- const paths = new Map<string, number>();
111
- for (const file of [
112
- result.receiptPath,
113
- ...result.files.map((entry) => entry.path),
114
- ]) {
115
- paths.set(file, 0o600);
116
- for (let dir = dirname(resolve(file)); dir !== root; dir = dirname(dir))
117
- paths.set(dir, 0o700);
118
- }
119
- const modes = await Promise.all(
120
- [...paths].map(async ([path, mode]) => {
121
- const entry = await lstat(path);
122
- if (entry.uid !== process.getuid!() || entry.isSymbolicLink())
123
- throw new AgentConfigurationError(
124
- 'Profile ownership changed. Inspect the managed paths before applying.'
125
- );
126
- return (entry.mode & 0o777) === mode;
127
- })
128
- );
129
- return modes.every(Boolean);
130
- }
131
-
132
- /** Applies one profile. A file someone edited is refused unless `adopt`;
133
- * then the agents play writes the profile, and what it wrote is measured
134
- * against the specification before this reports success. With nothing to
135
- * change, the play is not run.
136
- */
137
- export async function convergeAgents(
138
- context: Context,
139
- adopt = false,
140
- play: ProfilePlay = agentsPlay()
141
- ) {
142
- return withProfileLock(context.root, async () => {
143
- const result = await plan(context);
144
- if (!adopt && result.files.some((file) => file.state === 'conflict'))
145
- throw new AgentConfigurationError(
146
- 'Unmanaged or modified configuration. Review locally, then use --adopt to back up and replace only this profile.'
147
- );
148
- const { receipt, encoded } = receiptFor(result, context.revision);
149
- const changing = result.files.filter((file) => file.state !== 'unchanged');
150
- const sameProfile =
151
- changing.length === 0 &&
152
- result.previous !== null &&
153
- receiptFor(result, result.previous.revision).encoded === result.raw &&
154
- (await privateProfile(context, result));
155
- if (!sameProfile || result.raw !== encoded) {
156
- const applied = await play(
157
- profileVariables(context, receipt, {
158
- backups: changing
159
- .filter((file) => file.state !== 'create')
160
- .map((file) => ({
161
- source: file.path,
162
- dest: join(context.root, 'backups', randomUUID()),
163
- })),
164
- }),
165
- sameProfile
166
- );
167
- if (!applied.ok)
168
- throw new AgentConfigurationError(
169
- 'The agents play (ansible/agents/agents.yml) failed for this profile; no receipt was advanced and its output is not reported. Inspect the profile with agents preview, then apply again.'
170
- );
171
- await measure(context, encoded);
172
- }
173
- return {
174
- ...publicPlan(result, context.revision),
175
- appliedRevision: context.revision,
176
- receiptMatches: true,
177
- };
178
- });
179
- }
180
-
181
- /** All files and their prior receipts must still match. On a mixed batch
182
- * the caller uses individual applies, which name the first failed tool. */
183
- export async function refreshProfileBatch(
184
- contexts: Context[],
185
- run: Runner = runCommand,
186
- scratch?: string
187
- ) {
188
- return withProfileLock(contexts[0]!.root, async () => {
189
- const plans = await Promise.all(contexts.map(plan));
190
- const updates = [];
191
- for (const [i, result] of plans.entries()) {
192
- if (
193
- !result.previous ||
194
- result.files.some((file) => file.state !== 'unchanged') ||
195
- receiptFor(result, result.previous.revision).encoded !== result.raw ||
196
- !(await privateProfile(contexts[i]!, result))
197
- )
198
- return null;
199
- const context = contexts[i]!;
200
- if (context.revision !== result.previous.revision) {
201
- const { receipt, encoded } = receiptFor(result, context.revision);
202
- updates.push({
203
- context,
204
- encoded,
205
- variables: { dest: result.receiptPath, ...receipt },
206
- });
207
- }
208
- }
209
- if (updates.length) {
210
- const applied = await runAnsible(
211
- run,
212
- join(PACKAGE_ROOT, 'ansible/agents/receipts.yml'),
213
- {
214
- input: JSON.stringify({
215
- receipts: updates.map((update) => update.variables),
216
- }),
217
- timeoutMs: 90_000,
218
- },
219
- scratch
220
- );
221
- if (!applied.ok) return null;
222
- await Promise.all(
223
- updates.map((update) => measure(update.context, update.encoded))
224
- );
225
- }
226
- return plans.map((result, i) => ({
227
- ...publicPlan(result, contexts[i]!.revision),
228
- appliedRevision: contexts[i]!.revision,
229
- receiptMatches: true,
230
- }));
231
- });
232
- }
233
-
234
- async function withProfileLock<T>(
235
- root: string,
236
- apply: () => Promise<T>
237
- ): Promise<T> {
238
- await safeParents(root);
239
- await mkdir(root, { recursive: true, mode: 0o700 });
240
- const lock = join(root, '.apply-lock');
241
- try {
242
- await mkdir(lock);
243
- } catch {
244
- throw new AgentConfigurationError(
245
- 'Another apply is active; inspect .apply-lock before retrying.'
246
- );
247
- }
248
- try {
249
- return await apply();
250
- } finally {
251
- await rm(lock, { recursive: true, force: true });
252
- }
253
- }
254
-
255
- /** The receipt an apply of this plan records, and its exact text. */
256
- export function receiptFor(
257
- result: Awaited<ReturnType<typeof plan>>,
258
- revision: string
259
- ): { receipt: Receipt; encoded: string } {
260
- const receipt: Receipt = {
261
- version: 1,
262
- revision,
263
- fingerprint: result.fingerprint,
264
- files: Object.fromEntries(
265
- result.files.map((file) => [file.name, digest(file.content)])
266
- ),
267
- };
268
- return { receipt, encoded: JSON.stringify(receipt, null, 2) + '\n' };
269
- }
270
-
271
- export function profileVariables(
272
- context: Context,
273
- receipt: Receipt,
274
- options: { backups: { source: string; dest: string }[] } = { backups: [] }
275
- ): ProfileVariables {
276
- const { selection } = context;
277
- return {
278
- agent_root: context.root,
279
- agent_node: selection.node,
280
- agent_tool: selection.tool,
281
- agent_profile: selection.profile,
282
- agent_model: selection.model,
283
- agent_proxy_endpoint:
284
- selection.profile === 'proxy' ? registry.proxy.endpoint : '',
285
- agent_proxy_models: Object.values(registry.proxy.routes).map(
286
- (route) => route.model
287
- ),
288
- agent_files: receipt.files,
289
- agent_revision: receipt.revision,
290
- agent_fingerprint: receipt.fingerprint,
291
- agent_backups: options.backups,
292
- };
293
- }
294
-
295
- /** After the play: every file is what was specified, byte for byte, and the
296
- * receipt is the one this apply decided on.
297
- */
298
- async function measure(context: Context, encoded: string): Promise<void> {
299
- const after = await plan(context);
300
- if (
301
- after.files.some((file) => file.state !== 'unchanged') ||
302
- (await readOwned(after.receiptPath)) !== encoded
303
- )
304
- throw new AgentConfigurationError(
305
- 'After the agents play, the profile on disk is not what homelab specifies. Inspect it with agents preview before applying again.'
306
- );
307
- }
308
-
309
- export function publicPlan(
310
- result: Awaited<ReturnType<typeof plan>>,
311
- revision: string
312
- ) {
313
- return {
314
- revision,
315
- appliedRevision: result.previous?.revision ?? null,
316
- fingerprint: result.fingerprint,
317
- receiptMatches: result.previous?.fingerprint === result.fingerprint,
318
- files: result.files.map(({ name, state }) => ({ name, state })),
319
- t3EndToEnd: 'unverified',
320
- authenticatedInference: 'unverified',
321
- };
322
- }
323
-
324
- function parseReceipt(raw: string): Receipt {
325
- const value = JSON.parse(raw) as Receipt;
326
- if (
327
- value.version !== 1 ||
328
- !/^[a-f0-9]{40}$/.test(value.revision) ||
329
- !/^[a-f0-9]{64}$/.test(value.fingerprint) ||
330
- !value.files ||
331
- !Object.values(value.files).every(
332
- (hash) => typeof hash === 'string' && /^[a-f0-9]{64}$/.test(hash)
333
- )
334
- )
335
- throw new AgentConfigurationError(
336
- 'Invalid configuration receipt. Inspect it locally and restore a known receipt before applying.'
337
- );
338
- return value;
339
- }
@@ -1,107 +0,0 @@
1
- import { lstat, readdir } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { homedir } from 'node:os';
4
- import { agentRoot } from './render';
5
- import { registry, select } from './registry';
6
- import { plan } from './converge';
7
- import type { Platform } from '../platform/types';
8
- import type { DoctorCheck } from '../doctor-check';
9
-
10
- export async function agentChecks(platform: Platform): Promise<DoctorCheck[]> {
11
- const checks: DoctorCheck[] = [];
12
- for (const [tool, definition] of Object.entries(registry.tools)) {
13
- const binary = Bun.which(definition.binary);
14
- checks.push({
15
- id: `agent:${tool}`,
16
- label: `${tool} installed`,
17
- severity: binary ? 'pass' : 'warn',
18
- detail: binary
19
- ? await version(definition.binary)
20
- : 'Not on PATH. Use shared mise for managed CLIs; desktop apps remain OS prerequisites.',
21
- });
22
- }
23
- const root = agentRoot(homedir(), platform.name);
24
- const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
25
- let profiles = 0;
26
- for (const node of entries
27
- .filter(
28
- (entry) =>
29
- entry.isDirectory() && /^[a-z0-9][a-z0-9-]{0,62}$/.test(entry.name)
30
- )
31
- .slice(0, 64)) {
32
- for (const tool of Object.keys(registry.defaults)) {
33
- for (const profile of ['direct', 'proxy']) {
34
- const check = await profileCheck(root, node.name, tool, profile);
35
- if (check) {
36
- checks.push(check);
37
- profiles++;
38
- }
39
- }
40
- }
41
- }
42
- if (profiles === 0)
43
- checks.push({
44
- id: 'agent:profiles',
45
- label: 'Managed profiles',
46
- severity: 'warn',
47
- detail:
48
- 'No applied profiles. Run bun src/agents/cli.ts agents preview --node ID, then bun src/agents/cli.ts --yes agents apply --node ID.',
49
- });
50
- return checks;
51
- }
52
-
53
- async function profileCheck(
54
- root: string,
55
- node: string,
56
- tool: string,
57
- profile: string
58
- ): Promise<DoctorCheck | null> {
59
- const receiptPath = join(root, node, tool, profile, 'receipt.json');
60
- if (!(await lstat(receiptPath).catch(() => null))) return null;
61
- try {
62
- const result = await plan({
63
- root,
64
- selection: select(node, tool, profile),
65
- revision: 'unverified',
66
- });
67
- if (!result.previous) return null;
68
- const clean =
69
- result.files.every((file) => file.state === 'unchanged') &&
70
- result.previous.fingerprint === result.fingerprint;
71
- return {
72
- id: `agent:${node}:${tool}:${profile}`,
73
- label: 'Managed profile drift',
74
- severity: clean ? 'pass' : 'fail',
75
- detail: `Applied revision ${result.previous.revision}; static configuration ${clean ? 'matches' : 'drifted'}. Secret availability, endpoint, inference and T3 end-to-end require bun src/agents/cli.ts agents verify/operator tests.`,
76
- };
77
- } catch {
78
- return {
79
- id: `agent:${node}:${tool}:${profile}`,
80
- label: 'Managed profile drift',
81
- severity: 'fail',
82
- detail:
83
- 'Profile or receipt cannot be validated. Inspect locally and preview before applying; raw contents withheld.',
84
- };
85
- }
86
- }
87
-
88
- async function version(binary: string): Promise<string> {
89
- try {
90
- const child = Bun.spawn([binary, '--version'], {
91
- stdout: 'pipe',
92
- stderr: 'ignore',
93
- });
94
- const timer = setTimeout(() => child.kill(), 5000);
95
- try {
96
- const text = await new Response(child.stdout).text();
97
- const match = text.match(/\b\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?\b/);
98
- return (await child.exited) === 0 && match
99
- ? `Version ${match[0]}; installation pins remain owned by mise.`
100
- : 'Version unverified.';
101
- } finally {
102
- clearTimeout(timer);
103
- }
104
- } catch {
105
- return 'Version unverified.';
106
- }
107
- }
@@ -1,2 +0,0 @@
1
- /** Only explicitly authored messages may cross the agent CLI error boundary. */
2
- export class AgentConfigurationError extends Error {}
@@ -1,43 +0,0 @@
1
- import { AgentConfigurationError } from './errors';
2
- import { lstat, readFile } from 'node:fs/promises';
3
- import { dirname, parse } from 'node:path';
4
- import { digest } from './registry';
5
-
6
- export async function safeParents(path: string): Promise<void> {
7
- let current = path;
8
- while (current !== parse(current).root) {
9
- try {
10
- if ((await lstat(current)).isSymbolicLink())
11
- throw new AgentConfigurationError(
12
- 'Symlink conflict; move the managed destination before applying.'
13
- );
14
- } catch (error) {
15
- if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
16
- }
17
- current = dirname(current);
18
- }
19
- }
20
-
21
- export async function readOwned(path: string): Promise<string | null> {
22
- await safeParents(path);
23
- try {
24
- if (!(await lstat(path)).isFile())
25
- throw new AgentConfigurationError(
26
- 'Managed destination is not a regular file.'
27
- );
28
- return await readFile(path, 'utf8');
29
- } catch (error) {
30
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;
31
- throw error;
32
- }
33
- }
34
-
35
- export function fileState(
36
- current: string | null,
37
- desired: string,
38
- previous?: string
39
- ): string {
40
- if (current === desired) return 'unchanged';
41
- if (current === null) return 'create';
42
- return previous === digest(current) ? 'update' : 'conflict';
43
- }
@@ -1,195 +0,0 @@
1
- import { providerFailureCode } from './provider-errors';
2
- import { verifyRoundTrip } from './round-trip';
3
- import { proxyKey } from './secrets';
4
- import type { Check } from '../types';
5
- import { fleet, secret } from '../fleet-config';
6
- import type { SecretsProvider } from '../secrets';
7
- import {
8
- blockedBySecretsLogin,
9
- secretsFault,
10
- secretsLoginOwner,
11
- } from '../secrets-blocked';
12
- import { registry, type Selection } from './registry';
13
- import { verifyProvider } from './verify';
14
- import { fileURLToPath } from 'node:url';
15
- import {
16
- cacheKey,
17
- cachedCheck,
18
- sourceKey,
19
- type VerifyCache,
20
- } from './verify-cache';
21
-
22
- /** The verifier's own code: changing how providers are checked re-verifies.
23
- * Resolved from the module URL: the published CLI loads this on Node, which has
24
- * no `import.meta.dir`.
25
- */
26
- const VERIFIER_SOURCES = [
27
- 'fleet-verify.ts',
28
- 'verify.ts',
29
- 'round-trip.ts',
30
- 'provider-errors.ts',
31
- ].map((name) => fileURLToPath(new URL(name, import.meta.url)));
32
-
33
- /** Uses the selected gateway credential in this node's noninteractive environment.
34
- * Authentication/inference evidence does not certify native clients or paired T3.
35
- */
36
- export async function verifyFleetProviders(
37
- node: string,
38
- cache: VerifyCache = {},
39
- /** The node's secrets and where it keeps the last key they gave. */
40
- from: { secrets?: SecretsProvider; lastKey?: string } = {}
41
- ): Promise<Check[]> {
42
- const secrets = from.secrets ?? secret;
43
- let key: string;
44
- try {
45
- key = await proxyKey({
46
- read: () => secrets('proxy-client-key'),
47
- ...(from.lastKey ? { path: from.lastKey } : {}),
48
- });
49
- } catch {
50
- // Neither the provider nor the last key it gave (src/agents/secrets.ts).
51
- const absent = Object.keys(registry.proxy.routes).map((provider) => ({
52
- id: `provider:${provider}:authentication`,
53
- status: 'fail' as const,
54
- summary: 'PROVIDER_UNATTENDED_CREDENTIAL_REQUIRED',
55
- remedy: {
56
- action:
57
- 'Restore this node’s existing Vault authorization and renewal. No model requests or native OAuth login were attempted.',
58
- },
59
- }));
60
- // One fault of the login of the machine this ran on, not one a provider.
61
- const fault = await secretsFault(secrets);
62
- const owner = secretsLoginOwner(
63
- node === fleet.manager.id ? 'manager' : 'worker'
64
- );
65
- return fault
66
- ? absent.map(({ id, status }) =>
67
- blockedBySecretsLogin(id, status, fault, owner)
68
- )
69
- : absent;
70
- }
71
-
72
- // Warm runs reuse recent passes, but always prove this node's key still
73
- // authenticates to the live gateway; if it does not, verify everything.
74
- const live = await gatewayAuthenticates(key);
75
- const code = await sourceKey(
76
- fileURLToPath(new URL('.', import.meta.url)),
77
- VERIFIER_SOURCES
78
- );
79
- // Providers are independent upstream accounts: verify them concurrently so
80
- // the slowest one, not their sum, bounds the step. Order stays stable.
81
- return Promise.all(
82
- Object.entries(registry.proxy.routes).map(([provider, route]) =>
83
- cachedCheck(
84
- `provider-${node}-${provider}`,
85
- cacheKey(node, registry.proxy.endpoint, route, code),
86
- () => verifyRoute(node, provider, route, key),
87
- {
88
- ...cache,
89
- bypass: Boolean(cache.bypass) || !live,
90
- reuse: (check) => check.summary !== QUOTA_SUMMARY,
91
- }
92
- )
93
- )
94
- );
95
- }
96
-
97
- /** One cheap authenticated model listing: Vault key, proxy and route are live. */
98
- async function gatewayAuthenticates(key: string): Promise<boolean> {
99
- try {
100
- const response = await fetch(registry.proxy.endpoint + '/v1/models', {
101
- headers: { Authorization: `Bearer ${key}` },
102
- redirect: 'error',
103
- signal: AbortSignal.timeout(15_000),
104
- });
105
- return response.ok;
106
- } catch {
107
- return false;
108
- }
109
- }
110
-
111
- async function verifyRoute(
112
- node: string,
113
- provider: string,
114
- route: { model: string; native: string | null; harness: string },
115
- key: string
116
- ): Promise<Check> {
117
- const selection: Selection = {
118
- node,
119
- profile: 'proxy',
120
- tool: (route.native ?? route.harness) as Selection['tool'],
121
- model: route.model,
122
- };
123
- try {
124
- const evidence = await verifyProvider(selection, true, key);
125
- await verifyRoundTrip(route.model, key);
126
- return {
127
- id: `provider:${provider}:inference`,
128
- status: evidence.inference === 'pass' ? 'pass' : 'fail',
129
- summary:
130
- 'Gateway authentication, bounded inference, completed streaming and safe echo tool round trip verified from node environment. Native CLI/T3 execution is separate.',
131
- };
132
- } catch (error) {
133
- return inferenceFailure(provider, providerFailureCode(error));
134
- }
135
- }
136
-
137
- /** Rate limits and exhausted quota are expected on shared subscription
138
- * accounts: the gateway authenticated and routed the request, and the account
139
- * recovers on its own. They are not reported at all (a quiet pass).
140
- */
141
- const QUOTA = new Set(['PROVIDER_RATE_LIMITED']);
142
- /** Summary of the quiet pass; native session checks skip these accounts. */
143
- export const QUOTA_SUMMARY =
144
- 'Gateway authenticated and routed the request; the provider account is rate limited or out of quota and recovers on its own.';
145
-
146
- /** Proxy routes whose provider account is out of quota in these checks. */
147
- export function quotaLimited(checks: Check[]): Set<string> {
148
- return new Set(
149
- checks
150
- .filter((check) => check.summary === QUOTA_SUMMARY)
151
- .map((check) => check.id.split(':')[1]!)
152
- );
153
- }
154
-
155
- /** Other conditions owned by the upstream provider account (outage, billing)
156
- * do not mean this node is misconfigured: the gateway answered and routed the
157
- * request. They are warnings, so a provider outage never fails converge.
158
- */
159
- const UPSTREAM: Record<string, string> = {
160
- PROVIDER_UPSTREAM_UNAVAILABLE:
161
- 'The provider returned a server error through the gateway. Retry later; no fleet change is needed.',
162
- PROVIDER_MODEL_UNAVAILABLE:
163
- 'The provider refused the declared model (often billing or account access). Fix the provider account, or change the model in agents/registry.json.',
164
- PROVIDER_TIMEOUT:
165
- 'The provider did not answer within the bounded verification deadline. Retry later.',
166
- };
167
-
168
- /** The declared route cannot work as it is: it fails, and stays failed,
169
- * until the route is changed. Retrying or signing in again changes nothing.
170
- */
171
- const INCOMPATIBLE: Record<string, string> = {
172
- PROVIDER_PROTOCOL_INCOMPATIBLE:
173
- 'The gateway does not serve the protocol this route uses (no such endpoint, method or media type). Nothing on this machine can fix it: change the route in agents/registry.json to one listed under "Supported alternatives" in agents/setup.md, then run converge.',
174
- };
175
-
176
- export function inferenceFailure(provider: string, code: string): Check {
177
- if (QUOTA.has(code))
178
- return {
179
- id: `provider:${provider}:inference`,
180
- status: 'pass',
181
- summary: QUOTA_SUMMARY,
182
- };
183
- const upstream = UPSTREAM[code];
184
- return {
185
- id: `provider:${provider}:inference`,
186
- status: upstream ? 'warn' : 'fail',
187
- summary: code,
188
- remedy: {
189
- action:
190
- upstream ??
191
- INCOMPATIBLE[code] ??
192
- `Verify unattended Vault access and the declared ${provider} model on the singleton gateway. Preserve OAuth state; do not log native auth on proxy clients.`,
193
- },
194
- };
195
- }