@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,738 +0,0 @@
1
- import { mkdtemp, readFile, rm } from 'node:fs/promises';
2
- import { homedir, tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { currentPlatform } from '../platform';
5
- import { agentRoot, render } from './render';
6
- import { select } from './registry';
7
- import type { Check, Runner } from '../types';
8
- import { pinnedPath } from './toolchain';
9
- import { registry } from './registry';
10
- import type { Account } from './accounts';
11
- import { accountSlug } from './accounts';
12
- import {
13
- accountSessionChecks,
14
- namesCondition,
15
- printedClears,
16
- sessionResult,
17
- type Instance,
18
- type SessionOutcome,
19
- type SessionResult,
20
- } from '../accounts/sessions';
21
- import {
22
- cacheKey,
23
- cachedCheck,
24
- lastFailure,
25
- sourceKey,
26
- type VerifyCache,
27
- } from './verify-cache';
28
-
29
- const PROMPT = 'Reply with exactly: OK';
30
-
31
- /** Every agent T3 offers on every node, launched exactly as T3 launches it:
32
- * through the tracked wrapper that injects the shared credential. `pin` names
33
- * the mise.toml tool whose locked version the installed binary must report.
34
- */
35
- export const NATIVE_AGENTS = [
36
- {
37
- name: 'claude',
38
- binary: 'claude',
39
- pin: 'claude',
40
- wrapper: 'claude-proxy.ts',
41
- // T3's binaryPath: the Claude Agent SDK runs a `.ts` path with node.
42
- launcher: 'claude-proxy',
43
- args: ['-p', PROMPT],
44
- },
45
- {
46
- name: 'codex',
47
- binary: 'codex',
48
- pin: 'codex',
49
- wrapper: 'codex-proxy.ts',
50
- launcher: 'codex-proxy.ts',
51
- args: ['exec', '--skip-git-repo-check', PROMPT],
52
- },
53
- {
54
- name: 'grok',
55
- binary: 'grok',
56
- pin: 'http:grok',
57
- wrapper: 'grok-proxy.ts',
58
- launcher: 'grok-proxy.ts',
59
- args: ['-p', PROMPT],
60
- },
61
- {
62
- name: 'antigravity',
63
- binary: 'antigravity',
64
- pin: 'http:antigravity',
65
- wrapper: 'antigravity-proxy.ts',
66
- launcher: 'bin/agy',
67
- args: [
68
- '-p',
69
- PROMPT,
70
- '--model',
71
- 'Gemini 3.8 Flash (High)',
72
- '--print-timeout',
73
- '90s',
74
- ],
75
- },
76
- {
77
- name: 'muse',
78
- binary: 'opencode',
79
- pin: 'aqua:anomalyco/opencode',
80
- wrapper: 'opencode-proxy.ts',
81
- launcher: 'opencode-proxy.ts',
82
- args: ['run', '--model', 'personal_proxy/devin/muse-wonder-1-0', PROMPT],
83
- },
84
- ] as const;
85
-
86
- type Agent = (typeof NATIVE_AGENTS)[number];
87
-
88
- export const ADDITIONAL_PROVIDER_CLIS = ['gemini', 'copilot'] as const;
89
-
90
- /** The user service T3 runs as on a worker, and so the environment every
91
- * agent it starts inherits.
92
- */
93
- export const T3_SERVICE = 't3code-desktop.service';
94
-
95
- /** How a session is launched: by the sync, through Bun on the pinned PATH,
96
- * or exactly as the T3 service starts it, with that service's environment
97
- * and nothing of the sync's.
98
- */
99
- type Launch =
100
- | { kind: 'sync'; env: Record<string, string> }
101
- | { kind: 'service'; env: Record<string, string> }
102
- | { kind: 'incomplete' };
103
-
104
- /** Variables an agent session or a launcher sets for the tool it starts:
105
- * the account and node it is pinned to, the proxy key and base URL, the
106
- * tool's own home and configuration. A sync started inside an agent session
107
- * inherits them; none of them may reach a launch, or every session would be
108
- * pinned to the calling session's account and tool.
109
- */
110
- const LAUNCHER_PREFIXES = [
111
- 'WS_AGENT_',
112
- 'CLIPROXY_',
113
- 'ANTHROPIC_',
114
- 'CLAUDE_CODE_',
115
- 'CODEX_',
116
- 'OPENCODE_',
117
- 'GROK_',
118
- 'GEMINI_',
119
- 'GOOGLE_GEMINI_',
120
- 'GOOGLE_GENAI_',
121
- 'AGY_',
122
- 'OPENAI_',
123
- 'XAI_',
124
- ];
125
- const LAUNCHER_NAMES = new Set(['CLAUDECODE', 'DISABLE_AUTOUPDATER']);
126
-
127
- /** What the sync launches an agent tool with, wherever the sync was started:
128
- * the environment it inherited without any launcher variable, and the pinned
129
- * tools first on PATH. Launched with this alone (`isolatedEnv`), never on top
130
- * of the sync's own environment.
131
- */
132
- export function syncLaunchEnvironment(
133
- inherited: NodeJS.ProcessEnv = process.env
134
- ): Record<string, string> {
135
- const env: Record<string, string> = {};
136
- for (const [name, value] of Object.entries(inherited))
137
- if (
138
- value !== undefined &&
139
- !LAUNCHER_NAMES.has(name) &&
140
- !LAUNCHER_PREFIXES.some((prefix) => name.startsWith(prefix))
141
- )
142
- env[name] = value;
143
- env['PATH'] = pinnedPath(inherited);
144
- return env;
145
- }
146
-
147
- /** Same versions everywhere (from the shared mise.lock) and a working signed-in
148
- * session through each T3 launcher. Agents run concurrently and are bounded.
149
- * With `t3Service` (a Linux worker), sessions run in the environment of the
150
- * T3 user service, where T3 itself starts them, not in the sync's.
151
- */
152
- export async function verifyNativeAgents(
153
- node: string,
154
- workspace: string,
155
- run: Runner,
156
- options: {
157
- /** Proxy routes already found out of quota; their sessions are not run. */
158
- outOfQuota?: Set<string>;
159
- cache?: VerifyCache;
160
- t3Service?: boolean;
161
- /** The proxy's accounts and what this node offers. Every cached result
162
- * is keyed on the roster version and the client key's version, so any
163
- * account change or key rotation re-verifies at once.
164
- */
165
- accounts?: AccountContext;
166
- /** Where the agent profiles are rendered; this user's by default. */
167
- profiles?: string;
168
- /** The environment the sync was started in; its own by default. */
169
- inherited?: NodeJS.ProcessEnv;
170
- } = {}
171
- ): Promise<Check[]> {
172
- const { outOfQuota = new Set<string>(), cache = {} } = options;
173
- const profiles =
174
- options.profiles ?? agentRoot(homedir(), currentPlatform().name);
175
- const pins = parsePins(await readFile(join(workspace, 'mise.toml'), 'utf8'));
176
- const sync = syncLaunchEnvironment(options.inherited);
177
- const environment = options.t3Service
178
- ? await serviceLaunch(run, sync)
179
- : { launch: { kind: 'sync', env: sync } as Launch, checks: [] };
180
- const { launch } = environment;
181
- const cwd = await mkdtemp(join(tmpdir(), 'fleet-agents-'));
182
- try {
183
- const keys = new Map<string, string>();
184
- const results = await Promise.all(
185
- NATIVE_AGENTS.map(async (agent) => {
186
- const key = cacheKey(
187
- node,
188
- agent,
189
- pins[agent.pin] ?? '',
190
- registry,
191
- launch.kind,
192
- await sourceKey(workspace, launcherSources(workspace, agent)),
193
- options.accounts?.rosterVersion ?? '',
194
- options.accounts?.keyVersion ?? '',
195
- await configurationKey(profiles, node, agent.binary)
196
- );
197
- keys.set(agent.binary, key);
198
- return [
199
- await versionCheck(agent, pins[agent.pin], run, sync),
200
- outOfQuota.has(agent.name)
201
- ? quotaPass(agent)
202
- : launch.kind === 'incomplete'
203
- ? incompleteSession(agent)
204
- : await cachedCheck(
205
- `agent-${node}-${agent.name}`,
206
- key,
207
- () =>
208
- sessionCheck(agent, { node, workspace, cwd, launch }, run),
209
- cache
210
- ),
211
- ];
212
- })
213
- );
214
- const accounts =
215
- options.accounts && launch.kind !== 'incomplete'
216
- ? await accountSessionChecks(
217
- options.accounts.live,
218
- options.accounts.exposed,
219
- (instance) =>
220
- accountSession(instance, options.accounts!, {
221
- node,
222
- workspace,
223
- cwd,
224
- launch,
225
- cache,
226
- run,
227
- launcherKey: keys.get(instance.tool)!,
228
- })
229
- )
230
- : [];
231
- const extraVersions = await Promise.all(
232
- ADDITIONAL_PROVIDER_CLIS.map((binary) =>
233
- versionCheck(
234
- { name: binary, binary, pin: binary },
235
- pins[binary],
236
- run,
237
- sync
238
- )
239
- )
240
- );
241
- return [
242
- ...environment.checks,
243
- ...results.flat(),
244
- ...extraVersions,
245
- ...accounts,
246
- ];
247
- } finally {
248
- await rm(cwd, { recursive: true, force: true });
249
- }
250
- }
251
-
252
- export interface AccountContext {
253
- live: Account[];
254
- exposed: Instance[];
255
- rosterVersion: string;
256
- keyVersion: string;
257
- /** Asks the proxy what holds one account back, after its session timed
258
- * out (`proxyVerdict`). Without it a timed-out session stays `timed-out`.
259
- */
260
- consult?: (account: Account) => Promise<SessionOutcome>;
261
- /** The clock a cooldown a session printed is read against. */
262
- now?: () => number;
263
- }
264
-
265
- /** How a per-account instance is launched: its tool's launcher, pinned to
266
- * the account as T3 pins it. The proxy is asked when a session ran into the
267
- * deadline without a word.
268
- */
269
- export const ACCOUNT_LAUNCH: Record<
270
- string,
271
- { wrapper: string; launcher: string; args: string[] }
272
- > = {
273
- claude: {
274
- wrapper: 'claude-proxy.ts',
275
- launcher: 'claude-proxy',
276
- args: ['-p', PROMPT],
277
- },
278
- codex: {
279
- wrapper: 'codex-proxy.ts',
280
- launcher: 'codex-proxy.ts',
281
- args: ['exec', '--skip-git-repo-check', PROMPT],
282
- },
283
- antigravity: {
284
- wrapper: 'antigravity-proxy.ts',
285
- launcher: 'bin/agy',
286
- args: [
287
- '-p',
288
- PROMPT,
289
- '--model',
290
- 'Gemini 3.8 Flash (High)',
291
- '--print-timeout',
292
- '90s',
293
- ],
294
- },
295
- };
296
-
297
- /** How long a session that did not pass is taken as found, before it is
298
- * run again: back-to-back syncs do not pay for the same dead session twice.
299
- * Any change to the roster, the client key or the profile runs it at once.
300
- */
301
- export const SESSION_FAILURE_REUSE_MS = 10 * 60 * 1000;
302
-
303
- /** A session's deadline, and the one of a session that ran into it or found
304
- * its account cooling down the last time: long enough to answer, short
305
- * enough not to hold a sync up again.
306
- */
307
- export const SESSION_DEADLINE_MS = 150_000;
308
- export const SESSION_RETRY_DEADLINE_MS = 30_000;
309
-
310
- interface SessionContext {
311
- node: string;
312
- workspace: string;
313
- cwd: string;
314
- launch: Exclude<Launch, { kind: 'incomplete' }>;
315
- cache: VerifyCache;
316
- run: Runner;
317
- launcherKey: string;
318
- }
319
-
320
- /** An outcome as the cache keeps it: `cooling-down 2027-01-15T09:30:00Z`. */
321
- const kept = ({ result, clears }: SessionOutcome): string =>
322
- clears ? `${result} ${clears}` : result;
323
-
324
- function outcomeOf(summary: string): SessionOutcome {
325
- const [result, clears] = summary.split(' ');
326
- return { result: result as SessionResult, ...(clears ? { clears } : {}) };
327
- }
328
-
329
- /** One account's session, at the least cost that still proves it.
330
- *
331
- * - A pass is reused for six hours.
332
- * - What a session found when it did not pass is taken as found for ten
333
- * minutes, and says so.
334
- * - Before a session is launched the proxy is asked for the account's model:
335
- * an account it holds back, wants verified or refuses is reported at once,
336
- * with no session. OpenCode would retry such an account quietly until the
337
- * deadline.
338
- * - A session ends as soon as what it printed names a condition of its
339
- * account: OpenCode prints a refused request within a second, then retries
340
- * it quietly until the deadline.
341
- * - A session that ran into its deadline or found its account cooling down
342
- * the last time gets a short one.
343
- */
344
- function accountLaunch(instance: Instance, live: Account[]) {
345
- const spec = ACCOUNT_LAUNCH[instance.tool];
346
- const neon =
347
- instance.tool === 'antigravity' &&
348
- live.some(
349
- (account) =>
350
- account.tool === instance.tool &&
351
- account.email === instance.account &&
352
- account.models.includes('gemini-4-neon')
353
- );
354
- return neon && spec
355
- ? {
356
- ...spec,
357
- args: spec.args.map((arg) =>
358
- arg === 'Gemini 3.8 Flash (High)' ? 'Gemini 4 Neon (High)' : arg
359
- ),
360
- }
361
- : spec;
362
- }
363
-
364
- async function accountSession(
365
- instance: Instance,
366
- accounts: AccountContext,
367
- context: SessionContext
368
- ): Promise<SessionOutcome> {
369
- const spec = accountLaunch(instance, accounts.live);
370
- if (!spec) return { result: 'failed' };
371
- const name = `account-${context.node}-${instance.tool}-${accountSlug(instance.account)}`;
372
- const key = cacheKey(
373
- context.node,
374
- instance,
375
- spec,
376
- accounts.rosterVersion,
377
- accounts.keyVersion,
378
- context.launcherKey
379
- );
380
- const last = await lastFailure(name, key, context.cache);
381
- if (last && last.ageMs < SESSION_FAILURE_REUSE_MS)
382
- return {
383
- ...outcomeOf(last.check.summary),
384
- foundMinutesAgo: Math.round(last.ageMs / 60_000),
385
- };
386
- const hung =
387
- last !== null &&
388
- ['timed-out', 'cooling-down'].includes(
389
- outcomeOf(last.check.summary).result
390
- );
391
- let found: SessionOutcome | undefined;
392
- const check = await cachedCheck(
393
- name,
394
- key,
395
- async () => {
396
- found = await runSession(instance, spec, accounts, {
397
- ...context,
398
- timeoutMs: hung ? SESSION_RETRY_DEADLINE_MS : SESSION_DEADLINE_MS,
399
- });
400
- // A pass is read back as one; anything else as what was found.
401
- return {
402
- id: 'account-session',
403
- status: found.result === 'ok' ? 'pass' : 'fail',
404
- summary: kept(found),
405
- };
406
- },
407
- { ...context.cache, keepFailure: true }
408
- );
409
- if (check.status === 'pass') return { result: 'ok' };
410
- return found ?? outcomeOf(check.summary);
411
- }
412
-
413
- /** Asks the proxy, then launches the session unless the proxy already said
414
- * what holds the account back. `timed-out` from the proxy means it named
415
- * nothing: the account answered, or nothing said why it does not.
416
- */
417
- async function runSession(
418
- instance: Instance,
419
- spec: (typeof ACCOUNT_LAUNCH)[string],
420
- accounts: AccountContext,
421
- context: SessionContext & { timeoutMs: number }
422
- ): Promise<SessionOutcome> {
423
- const live = accounts.live.find(
424
- (account) =>
425
- account.tool === instance.tool && account.email === instance.account
426
- );
427
- const consult = async (): Promise<SessionOutcome> =>
428
- live && accounts.consult ? accounts.consult(live) : { result: 'timed-out' };
429
- const before = await consult();
430
- if (before.result !== 'timed-out') return before;
431
- const agents = join(context.workspace, 'agents');
432
- const service = context.launch.kind === 'service';
433
- const result = await context.run(
434
- service
435
- ? [join(agents, spec.launcher), ...spec.args]
436
- : ['bun', join(agents, spec.wrapper), ...spec.args],
437
- {
438
- cwd: context.cwd,
439
- env: {
440
- ...context.launch.env,
441
- WS_AGENT_NODE: context.node,
442
- WS_AGENT_ACCOUNT: instance.account,
443
- },
444
- isolatedEnv: true,
445
- input: '',
446
- timeoutMs: context.timeoutMs,
447
- // A refusal, a limit or a demand to verify is printed long before the
448
- // session would end; nothing after it changes what it says.
449
- stopWhen: namesCondition,
450
- }
451
- );
452
- const output = result.stdout + result.stderr;
453
- const said = sessionResult(result.ok, output, result.reason === 'timeout');
454
- // A session that ran into its deadline printed nothing telling. The
455
- // proxy is asked again: the session may have used another model of the
456
- // account than the one asked for before, and found that one held back.
457
- if (said === 'timed-out') return consult();
458
- const clears =
459
- said === 'cooling-down'
460
- ? printedClears(output, (accounts.now ?? Date.now)())
461
- : undefined;
462
- return { result: said, ...(clears ? { clears } : {}) };
463
- }
464
-
465
- /** Reads `tool = "x"` and `"tool" = { version = "x", ... }` pins. */
466
- export function parsePins(source: string): Record<string, string> {
467
- const pins: Record<string, string> = {};
468
- const pattern =
469
- /^"?([A-Za-z0-9:@/._-]+)"?\s*=\s*(?:"([^"]+)"|\{[^\n]*?\bversion\s*=\s*"([^"]+)")/gm;
470
- for (const match of source.matchAll(pattern))
471
- pins[match[1]!] = (match[2] ?? match[3])!;
472
- return pins;
473
- }
474
-
475
- /** Self-healing: a binary that drifted from the lock (a vendor self-updater
476
- * rewrote it) is reinstalled from the locked artifact, then checked again.
477
- */
478
- async function versionCheck(
479
- agent: { name: string; binary: string; pin: string },
480
- pin: string | undefined,
481
- run: Runner,
482
- env: Record<string, string>
483
- ): Promise<Check> {
484
- const observe = async () => {
485
- const result = await run([agent.binary, '--version'], {
486
- env,
487
- isolatedEnv: true,
488
- timeoutMs: 30_000,
489
- });
490
- return result.ok
491
- ? /(?:^|[\s/])v?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)(?=\.?(?:[\s)]|$))/m.exec(
492
- result.stdout
493
- )?.[1]
494
- : undefined;
495
- };
496
- let observed = await observe();
497
- if (observed !== pin && pin) {
498
- await run(
499
- ['mise', 'install', '--locked', '--force', `${agent.pin}@${pin}`],
500
- {
501
- timeoutMs: 600_000,
502
- }
503
- );
504
- observed = await observe();
505
- }
506
- const ok = Boolean(pin) && observed === pin;
507
- return {
508
- id: `agent:${agent.name}:version`,
509
- status: ok ? 'pass' : 'fail',
510
- summary: ok
511
- ? `${agent.binary} ${pin} matches the shared toolchain lock.`
512
- : 'AGENT_VERSION_MISMATCH',
513
- ...(ok
514
- ? {}
515
- : {
516
- remedy: {
517
- action: `Expected ${pin ?? 'unknown'}, observed ${observed ?? 'unavailable'}. Every node runs the ${agent.binary} pinned in mise.toml/mise.lock; reinstalling it from the lock failed. Inspect mise install --locked ${agent.pin} on this node; never install it with a vendor self-updater.`,
518
- },
519
- }),
520
- };
521
- }
522
-
523
- /** Quota is the account's, not the node's: no warning (as for providers). */
524
- function quotaPass(agent: Agent): Check {
525
- return {
526
- id: `agent:${agent.name}:session`,
527
- status: 'pass',
528
- summary: `The shared ${agent.name} account is rate limited or out of quota; its session is checked again once it recovers.`,
529
- };
530
- }
531
-
532
- async function sessionCheck(
533
- agent: Agent,
534
- context: {
535
- node: string;
536
- workspace: string;
537
- cwd: string;
538
- launch: Exclude<Launch, { kind: 'incomplete' }>;
539
- },
540
- run: Runner
541
- ): Promise<Check> {
542
- const agents = join(context.workspace, 'agents');
543
- const command =
544
- context.launch.kind === 'service'
545
- ? [join(agents, agent.launcher), ...agent.args]
546
- : ['bun', join(agents, agent.wrapper), ...agent.args];
547
- const env = { ...context.launch.env, WS_AGENT_NODE: context.node };
548
- const launch = () =>
549
- run(command, {
550
- cwd: context.cwd,
551
- env,
552
- isolatedEnv: true,
553
- input: '',
554
- timeoutMs: 150_000,
555
- });
556
- const expected = /\bOK\b/;
557
- let result = await launch();
558
- // One retry: a CLI's first launch on a node may still be initializing.
559
- if (!(result.ok && expected.test(result.stdout))) result = await launch();
560
- const ok = result.ok && expected.test(result.stdout);
561
- return {
562
- id: `agent:${agent.name}:session`,
563
- status: ok ? 'pass' : 'fail',
564
- summary: ok
565
- ? `${agent.name} runs signed in through its T3 launcher with the shared account.`
566
- : sessionFailure(result.stderr + result.stdout),
567
- ...(ok ? {} : { remedy: { action: sessionRemedy(agent) } }),
568
- };
569
- }
570
-
571
- /** The environment of the T3 user service: what its user manager holds
572
- * (PATH included) and what the unit adds. Every launcher starts with
573
- * `#!/usr/bin/env bun` or runs `bun`, so that PATH must find Bun.
574
- */
575
- async function serviceLaunch(
576
- run: Runner,
577
- sync: Record<string, string>
578
- ): Promise<{ launch: Launch; checks: Check[] }> {
579
- const manager = await run(['systemctl', '--user', 'show-environment'], {
580
- timeoutMs: 15_000,
581
- });
582
- const unit = await run(
583
- [
584
- 'systemctl',
585
- '--user',
586
- 'show',
587
- T3_SERVICE,
588
- '--property=Environment',
589
- '--value',
590
- ],
591
- { timeoutMs: 15_000 }
592
- );
593
- if (!manager.ok || !unit.ok)
594
- return {
595
- launch: { kind: 'sync', env: sync },
596
- checks: [
597
- environmentCheck(
598
- 'warn',
599
- 'AGENT_SERVICE_ENVIRONMENT_UNVERIFIED',
600
- 'The environment of the T3 service could not be read, so sessions were launched from the sync instead. Inspect the user service manager of this worker: systemctl --user show-environment.'
601
- ),
602
- ],
603
- };
604
- const env = {
605
- ...parseAssignments(manager.stdout.split('\n')),
606
- ...parseAssignments(words(unit.stdout)),
607
- };
608
- const bun = await run(['/bin/sh', '-c', 'command -v bun'], {
609
- env,
610
- isolatedEnv: true,
611
- timeoutMs: 15_000,
612
- });
613
- if (!bun.ok)
614
- return {
615
- launch: { kind: 'incomplete' },
616
- checks: [
617
- environmentCheck(
618
- 'fail',
619
- 'AGENT_SERVICE_ENVIRONMENT_INCOMPLETE',
620
- INCOMPLETE_REMEDY
621
- ),
622
- ],
623
- };
624
- return {
625
- launch: { kind: 'service', env },
626
- checks: [
627
- environmentCheck(
628
- 'pass',
629
- 'The T3 service environment finds Bun; every session was launched with it alone.'
630
- ),
631
- ],
632
- };
633
- }
634
-
635
- const INCOMPLETE_REMEDY = `The PATH of ${T3_SERVICE} does not find Bun, so T3 cannot start any agent launcher even though they work from a shell. Put the pinned shims on the PATH of the user service manager through the baseline (never by hand), then run converge.`;
636
-
637
- function environmentCheck(
638
- status: Check['status'],
639
- summary: string,
640
- remedy?: string
641
- ): Check {
642
- return {
643
- id: 'agent:service-environment',
644
- status,
645
- summary,
646
- ...(remedy ? { remedy: { action: remedy } } : {}),
647
- };
648
- }
649
-
650
- function incompleteSession(agent: Agent): Check {
651
- return {
652
- id: `agent:${agent.name}:session`,
653
- status: 'fail',
654
- summary: 'AGENT_SERVICE_ENVIRONMENT_INCOMPLETE',
655
- remedy: { action: INCOMPLETE_REMEDY },
656
- };
657
- }
658
-
659
- /** `KEY=value` lines or words; a value systemd quoted loses its quotes. */
660
- function parseAssignments(entries: string[]): Record<string, string> {
661
- const env: Record<string, string> = {};
662
- for (const entry of entries) {
663
- const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s.exec(entry.trim());
664
- if (match) env[match[1]!] = unquote(match[2]!);
665
- }
666
- return env;
667
- }
668
-
669
- /** `systemctl show -p Environment` separates assignments with spaces and
670
- * double-quotes one that holds a space.
671
- */
672
- function words(line: string): string[] {
673
- return line.trim().match(/(?:[^\s"]+|"[^"]*")+/g) ?? [];
674
- }
675
-
676
- function unquote(value: string): string {
677
- return value.replace(/"([^"]*)"/g, '$1').replace(/^\$'(.*)'$/s, '$1');
678
- }
679
-
680
- /** A stable code only; raw CLI output is never reported. */
681
- function sessionFailure(output: string): string {
682
- if (/missing or out of date/.test(output)) return 'AGENT_PROFILE_STALE';
683
- if (/Required secret unavailable/.test(output))
684
- return 'AGENT_VAULT_UNAVAILABLE';
685
- if (/model_not_found|unknown provider for model/.test(output))
686
- return 'AGENT_MODEL_UNSERVED';
687
- return 'AGENT_SESSION_UNVERIFIED';
688
- }
689
-
690
- function sessionRemedy(agent: Agent): string {
691
- if (agent.name === 'antigravity')
692
- return 'Antigravity sends its own catalog model ids; the proxy serves them through declared aliases that converge applies on the manager (see proxy:config-pending). Pick Gemini 3.8 Flash in T3: the default Pro model is not served by the shared accounts.';
693
- return `Run the ${agent.name} launcher on this node to inspect it: WS_AGENT_NODE=<node> bun agents/${agent.wrapper}. Check this node's Vault session and the shared proxy.`;
694
- }
695
-
696
- /** The launcher and profile code a session depends on. */
697
- /** Digest of the agent's proxy profile as it is on this machine: the files
698
- * its session reads. A profile rendered again, edited or removed changes it,
699
- * so the session is proven again at once. Empty for a tool with no profile.
700
- */
701
- export async function configurationKey(
702
- profiles: string,
703
- node: string,
704
- tool: string
705
- ): Promise<string> {
706
- try {
707
- const selection = select(node, tool, 'proxy');
708
- const directory = join(profiles, node, tool, 'proxy');
709
- return await sourceKey(
710
- directory,
711
- Object.keys(render(selection)).map((name) => join(directory, name))
712
- );
713
- } catch {
714
- return '';
715
- }
716
- }
717
-
718
- function launcherSources(workspace: string, agent: Agent): string[] {
719
- const agents = join(workspace, 'agents');
720
- const lib = join(workspace, 'src/agents');
721
- return [
722
- ...new Set([join(agents, agent.wrapper), join(agents, agent.launcher)]),
723
- join(agents, 'managed-proxy.ts'),
724
- ...[
725
- 'native-verify.ts',
726
- 'admission.ts',
727
- 'account-relay.ts',
728
- 'accounts.ts',
729
- 'commands.ts',
730
- 'converge.ts',
731
- 'registry.ts',
732
- 'launch.ts',
733
- 'render.ts',
734
- 'secrets.ts',
735
- 'toolchain.ts',
736
- ].map((name) => join(lib, name)),
737
- ];
738
- }