@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,279 +0,0 @@
1
- import {
2
- AccountSelector,
3
- accountRefused,
4
- retryAfter,
5
- } from '../accounts/selection';
6
-
7
- /** Pins one agent process to one provider account. The proxy routes a model
8
- * named `<prefix>/<model>` only to the credential that owns the prefix, but
9
- * agents send whichever model the user picked. This loopback relay lives only
10
- * as long as the agent it was started for: it adds the prefix to each request
11
- * and forwards everything else (credentials, streaming) unchanged.
12
- *
13
- * With an empty prefix it pins nothing: every launch goes through a relay, so
14
- * every launch rides out a proxy restart the same way. `selector` then picks
15
- * the account of each request by the fleet's selection policy.
16
- */
17
- export function startAccountRelay(
18
- endpoint: string,
19
- prefix: string,
20
- options: Pick<RelayOptions, 'selector' | 'alternatives'> = {}
21
- ): { url: string; stop: () => void } {
22
- const pinned =
23
- prefix && !options.selector
24
- ? new AccountSelector([prefix], { strategy: 'fill-first' })
25
- : options.selector;
26
- const server = Bun.serve({
27
- hostname: '127.0.0.1',
28
- port: 0,
29
- // Model streams are idle for as long as a model thinks.
30
- idleTimeout: 0,
31
- fetch: (request) =>
32
- forward(request, endpoint, prefix, {
33
- ...options,
34
- ...(pinned ? { selector: pinned } : {}),
35
- }),
36
- });
37
- return {
38
- url: `http://127.0.0.1:${server.port}`,
39
- stop: () => void server.stop(true),
40
- };
41
- }
42
-
43
- type RelayOptions = {
44
- send?: typeof fetch;
45
- pause?: (seconds: number) => Promise<void>;
46
- /** Unpinned: the accounts to try in turn. Pinned: remembers cooldowns. */
47
- selector?: AccountSelector;
48
- /** Pinned: the other instances of the provider, named in its error. */
49
- alternatives?: string[];
50
- now?: () => number;
51
- };
52
- const sleep = (seconds: number) =>
53
- new Promise<void>((done) => setTimeout(done, seconds * 1000));
54
-
55
- export async function forward(
56
- request: Request,
57
- endpoint: string,
58
- prefix: string,
59
- options: RelayOptions = {}
60
- ): Promise<Response> {
61
- const url = new URL(request.url);
62
- const headers = new Headers(request.headers);
63
- // fetch sets these for the upstream request and decodes its response.
64
- for (const name of ['host', 'content-length', 'accept-encoding'])
65
- headers.delete(name);
66
- // An unreadable body could not be pinned; never forward it to the pool.
67
- if (request.body && headers.has('content-encoding'))
68
- return new Response('The account relay needs an uncompressed request.', {
69
- status: 415,
70
- });
71
- const raw = request.body ? await request.text() : undefined;
72
- const reach = reacher(request, headers, { endpoint, url, raw }, options);
73
- const { selector } = options;
74
- const reached =
75
- !prefix && selector && raw !== undefined
76
- ? await failOver(selector, reach)
77
- : await pinnedReach(prefix, reach, options);
78
- if (reached instanceof Response) return reached;
79
- return answer(reached);
80
- }
81
-
82
- /** Routed to one account, or to the proxy's pool without one. */
83
- type Reach = (account: string | undefined) => Promise<Reached>;
84
-
85
- /** Sends the request to the proxy, its model routed to the account, retrying
86
- * while the route is down.
87
- */
88
- function reacher(
89
- request: Request,
90
- headers: Headers,
91
- {
92
- endpoint,
93
- url,
94
- raw,
95
- }: { endpoint: string; url: URL; raw: string | undefined },
96
- { send = fetch, pause = sleep, now = Date.now }: RelayOptions
97
- ): Reach {
98
- return (account) => {
99
- const path = account ? pinPath(url.pathname, account) : url.pathname;
100
- const body = raw !== undefined && account ? pinModel(raw, account) : raw;
101
- return reachProxy(
102
- () =>
103
- send(
104
- endpoint + path + url.search,
105
- upstreamInit(request, headers, body)
106
- ),
107
- request.signal,
108
- pause,
109
- now
110
- );
111
- };
112
- }
113
-
114
- /** The proxy's answer, decoded, or the distinct "unreachable" error. */
115
- function answer(reached: Reached): Response {
116
- const upstream = reached.response;
117
- if (!upstream) return unreachable(reached.since);
118
- const answered = new Headers(upstream.headers);
119
- answered.delete('content-encoding');
120
- answered.delete('content-length');
121
- return new Response(upstream.body, {
122
- status: upstream.status,
123
- headers: answered,
124
- });
125
- }
126
-
127
- /** A pinned account (or no pinning at all). A pinned account the provider
128
- * limited answers at once, until its cooldown clears, with the time and the
129
- * other instances of its provider.
130
- */
131
- async function pinnedReach(
132
- prefix: string,
133
- reach: Reach,
134
- { selector, alternatives = [] }: RelayOptions
135
- ): Promise<Reached | Response> {
136
- const cooling = prefix && selector ? selector.coolingUntil(prefix) : null;
137
- if (cooling !== null) return coolingDown(cooling, alternatives);
138
- const reached = await reach(prefix || undefined);
139
- if (!prefix || !selector || reached.response?.status !== 429) return reached;
140
- selector.limited(prefix, retryAfter(reached.response.headers));
141
- await reached.response.body?.cancel().catch(() => undefined);
142
- return coolingDown(selector.coolingUntil(prefix)!, alternatives);
143
- }
144
-
145
- type Reached = { response: Response | null; since: number };
146
-
147
- function upstreamInit(
148
- request: Request,
149
- headers: Headers,
150
- body: string | undefined
151
- ): RequestInit {
152
- return {
153
- method: request.method,
154
- headers,
155
- ...(body === undefined ? {} : { body }),
156
- redirect: 'error',
157
- signal: request.signal,
158
- };
159
- }
160
-
161
- /** An unpinned request goes to the first usable account by the fleet's
162
- * policy; a quota or authentication refusal sends it on to the next. With
163
- * every account cooling down, the proxy's own pool serves it.
164
- */
165
- async function failOver(
166
- selector: AccountSelector,
167
- reach: Reach
168
- ): Promise<Reached> {
169
- const candidates = selector.candidates();
170
- if (candidates.length === 0) return reach(undefined);
171
- let reached!: Reached;
172
- for (const [position, candidate] of candidates.entries()) {
173
- reached = await reach(candidate);
174
- const status = reached.response?.status;
175
- if (status === undefined || !accountRefused(status)) return reached;
176
- selector.limited(candidate, retryAfter(reached.response!.headers));
177
- if (position < candidates.length - 1)
178
- await reached.response!.body?.cancel().catch(() => undefined);
179
- }
180
- return reached;
181
- }
182
-
183
- /** One error both Anthropic and OpenAI clients show as a message. */
184
- function agentError(
185
- status: number,
186
- type: string,
187
- message: string,
188
- retry: number
189
- ) {
190
- return new Response(
191
- JSON.stringify({ type: 'error', error: { type, message } }),
192
- {
193
- status,
194
- headers: {
195
- 'content-type': 'application/json',
196
- 'retry-after': String(Math.max(1, Math.ceil(retry))),
197
- },
198
- }
199
- );
200
- }
201
-
202
- function coolingDown(until: number, alternatives: string[]): Response {
203
- const others = alternatives.length
204
- ? ` Pick another instance of this provider in T3: ${alternatives.join(', ')}.`
205
- : '';
206
- return agentError(
207
- 429,
208
- 'rate_limit_error',
209
- `This account is cooling down until ${new Date(until).toISOString()}.${others}`,
210
- (until - Date.now()) / 1000
211
- );
212
- }
213
-
214
- /** The proxy did not answer within the retry window: a distinct, retryable
215
- * error that says since when, never a provider's error.
216
- */
217
- function unreachable(since: number): Response {
218
- return agentError(
219
- 503,
220
- 'proxy_unreachable',
221
- `The CLI proxy has been unreachable since ${new Date(since).toISOString()}. This is retryable; nothing is wrong with the account.`,
222
- 30
223
- );
224
- }
225
-
226
- /** Seconds to wait before each further attempt (about a minute in total). */
227
- export const RETRY_DELAYS = [1, 2, 4, 8, 15, 30];
228
- /** The route to the proxy answered instead of the proxy: its connector or the
229
- * proxy itself is restarting. 502-504 from a gateway, 520-530 from Cloudflare.
230
- */
231
- const routeDown = (status: number) =>
232
- (status >= 502 && status <= 504) || (status >= 520 && status <= 530);
233
-
234
- /** A brief outage of the route must not end an agent's turn: nothing has been
235
- * sent to the agent yet, so the same request is simply tried again until the
236
- * proxy answers or the delays run out. The last answer is returned as it is.
237
- */
238
- async function reachProxy(
239
- attempt: () => Promise<Response>,
240
- signal: AbortSignal,
241
- pause: (seconds: number) => Promise<void>,
242
- now: () => number
243
- ): Promise<Reached> {
244
- const since = now();
245
- for (let tries = 0; ; tries++) {
246
- const delay = RETRY_DELAYS[tries];
247
- const response = await attempt().catch(() => null);
248
- if (response && !routeDown(response.status)) return { response, since };
249
- if (delay === undefined || signal.aborted) return { response, since };
250
- await response?.body?.cancel().catch(() => undefined);
251
- await pause(delay);
252
- }
253
- }
254
-
255
- /** A Gemini request names its model in the path (`/models/<model>:<method>`);
256
- * that model is routed to the account the same way. Other paths are as-is.
257
- */
258
- export function pinPath(path: string, prefix: string): string {
259
- const match = /^(.*\/models\/)([^/:]+)(:[A-Za-z]+)$/.exec(path);
260
- if (!match) return path;
261
- const model = decodeURIComponent(match[2]!);
262
- if (model.startsWith(`${prefix}/`)) return path;
263
- return match[1] + encodeURIComponent(`${prefix}/${model}`) + match[3];
264
- }
265
-
266
- /** The JSON request with its model routed to the account; other bodies as-is. */
267
- export function pinModel(text: string, prefix: string): string {
268
- try {
269
- const payload: unknown = JSON.parse(text);
270
- if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
271
- const model = (payload as { model?: unknown }).model;
272
- if (typeof model === 'string' && !model.startsWith(`${prefix}/`))
273
- return JSON.stringify({ ...payload, model: `${prefix}/${model}` });
274
- }
275
- } catch {
276
- /* Not JSON: nothing to route. */
277
- }
278
- return text;
279
- }
@@ -1,94 +0,0 @@
1
- import { AgentConfigurationError } from './errors';
2
- import { registry } from './registry';
3
-
4
- /** One signed-in provider account on the proxy, offered through one tool. */
5
- export type Account = {
6
- tool: string;
7
- email: string;
8
- /** Models named `<prefix>/<model>` are served only by this account. */
9
- prefix: string;
10
- /** Every model the account serves. Its default comes first: the first of
11
- * the tool's preferred defaults it serves, else its first model by name.
12
- */
13
- models: string[];
14
- };
15
-
16
- type Route = { provider: string; models: string[] };
17
- const ROUTES = registry.proxy.accounts as Record<string, Route>;
18
- const EMAIL = /^[^\s@/]{1,64}@[^\s@/]{1,255}$/;
19
-
20
- /** The models an account of the tool should default to, best first. Accounts
21
- * of one tool are not entitled to the same models, so the list is an order
22
- * and not one model.
23
- */
24
- export const preferredModels = (tool: string): string[] =>
25
- ROUTES[tool]?.models ?? [];
26
-
27
- /** Stable file and instance name for an account. */
28
- export const accountSlug = (value: string): string =>
29
- value.toLowerCase().replace(/[^a-z0-9]+/g, '_');
30
-
31
- /** The proxy gives each account credential the prefix `<type>-<email>`. */
32
- export function accountPrefix(tool: string, email: string): string {
33
- const route = ROUTES[tool];
34
- if (!route || !EMAIL.test(email))
35
- throw new AgentConfigurationError(
36
- 'Unknown provider account; T3 offers only accounts signed in on the CLI proxy.'
37
- );
38
- return `${route.provider}-${email}`;
39
- }
40
-
41
- /** Accounts are never declared in source: the proxy lists a prefixed copy of
42
- * each model for every signed-in credential, and that list is the roster.
43
- */
44
- export function accountsFrom(modelIds: string[]): Account[] {
45
- const accounts: Account[] = [];
46
- for (const [tool, route] of Object.entries(ROUTES)) {
47
- const served = new Map<string, string[]>();
48
- for (const id of modelIds) {
49
- const slash = id.indexOf('/');
50
- const owner = id.slice(0, slash);
51
- if (slash < 0 || !owner.startsWith(`${route.provider}-`)) continue;
52
- const email = owner.slice(route.provider.length + 1);
53
- if (!EMAIL.test(email)) continue;
54
- served.set(email, [...(served.get(email) ?? []), id.slice(slash + 1)]);
55
- }
56
- for (const email of [...served.keys()].sort())
57
- accounts.push({
58
- tool,
59
- email,
60
- prefix: `${route.provider}-${email}`,
61
- models: preferred(served.get(email)!.sort(), route.models),
62
- });
63
- }
64
- return accounts;
65
- }
66
-
67
- const preferred = (models: string[], first: string[]) => [
68
- ...first.filter((model) => models.includes(model)),
69
- ...models.filter((model) => !first.includes(model)),
70
- ];
71
-
72
- /** Reads the roster with this node's own proxy key. Throws when the proxy does
73
- * not answer: an unknown roster must never read as "no accounts".
74
- */
75
- export async function discoverAccounts(
76
- key: string,
77
- send: typeof fetch = fetch
78
- ): Promise<Account[]> {
79
- const response = await send(registry.proxy.endpoint + '/v1/models', {
80
- headers: { Authorization: `Bearer ${key}` },
81
- redirect: 'error',
82
- signal: AbortSignal.timeout(15_000),
83
- });
84
- if (!response.ok)
85
- throw new AgentConfigurationError('The CLI proxy did not list its models.');
86
- const body = (await response.json()) as { data?: { id?: unknown }[] };
87
- if (!Array.isArray(body.data))
88
- throw new AgentConfigurationError('The CLI proxy did not list its models.');
89
- return accountsFrom(
90
- body.data.flatMap((model) =>
91
- typeof model.id === 'string' ? [model.id] : []
92
- )
93
- );
94
- }
@@ -1,65 +0,0 @@
1
- import { readFileSync, readdirSync } from 'node:fs';
2
- import { basename, dirname, join } from 'node:path';
3
- import policy from '../../ansible/ubuntu/policy.json';
4
- import { declaredFromKernel } from '../agent-session-limit';
5
-
6
- /** The scope T3 starts an agent in, and the slice it owns for them. */
7
- const SCOPE = /^t3code-[\w-]+\.scope$/;
8
- const OWNED_SLICE = /^app-t3code-agents-[0-9a-f]+\.slice$/;
9
-
10
- export const REFUSED_EXIT_CODE =
11
- policy.resourceSafety.agentSessionLimit.refusedExitCode;
12
-
13
- export interface Admission {
14
- /** Agent scopes in the slice, this launcher's own included. */
15
- running: number;
16
- limit: number;
17
- }
18
-
19
- /** Whether this launcher was started above the worker's limit on agent
20
- * sessions: it reads the limit the kernel holds on the slice it was started
21
- * in and counts the scopes there. Undefined wherever no limit applies: off
22
- * Linux, outside a scope T3 started (its version and capability probes run
23
- * in T3's own unit), or with no limit held.
24
- *
25
- * T3 starts an agent with `systemd-run --user --scope` and reports only how
26
- * it ended, so the launcher is the one place a refusal can say why.
27
- */
28
- export function admission(
29
- read: {
30
- file: (path: string) => string;
31
- directory: (path: string) => string[];
32
- } = {
33
- file: (path) => readFileSync(path, 'utf8'),
34
- directory: (path) => readdirSync(path),
35
- },
36
- mount = '/sys/fs/cgroup'
37
- ): Admission | undefined {
38
- try {
39
- const own = /^0::(\/.*)$/m.exec(read.file('/proc/self/cgroup'))?.[1];
40
- if (own === undefined || !SCOPE.test(basename(own))) return undefined;
41
- const slice = dirname(own);
42
- if (!OWNED_SLICE.test(basename(slice))) return undefined;
43
- const limit = declaredFromKernel(
44
- read.file(join(mount, slice, 'cgroup.max.descendants'))
45
- );
46
- if (limit === undefined) return undefined;
47
- return {
48
- limit,
49
- running: read
50
- .directory(join(mount, slice))
51
- .filter((name) => SCOPE.test(name)).length,
52
- };
53
- } catch {
54
- // An unreadable cgroup tree is no reason to refuse an agent.
55
- return undefined;
56
- }
57
- }
58
-
59
- const REFUSED = 'AGENT_SESSION_REFUSED';
60
-
61
- /** What a refused launcher prints: the limit, and both ways out. */
62
- export function refusal({ running, limit }: Admission): string | undefined {
63
- if (running <= limit) return undefined;
64
- return `${REFUSED}: this worker already runs ${running - 1} agent sessions and its limit is ${limit} (agentSessionLimit in the fleet configuration), so this one was not started. End a session that is no longer needed and send the message again, or raise agentSessionLimit in fleet.json and run homelab converge.`;
65
- }
@@ -1,77 +0,0 @@
1
- import { join } from 'node:path';
2
- import { homedir } from 'node:os';
3
- import { readFile, readdir } from 'node:fs/promises';
4
- import type { Platform } from '../platform/types';
5
-
6
- /** Content values never leave this module; the audit inventories ownership boundaries. */
7
- export async function auditMachine(platform: Platform) {
8
- const home = homedir();
9
- const paths = [
10
- join(home, '.codex', 'config.toml'),
11
- join(home, '.claude', 'settings.json'),
12
- join(home, '.claude.json'),
13
- join(home, '.gemini', 'settings.json'),
14
- join(platform.opencodeDir(), 'opencode.json'),
15
- join(home, '.cursor', 'mcp.json'),
16
- join(home, '.t3', 'userdata', 'settings.json'),
17
- join(home, '.config', 'cliproxy-fleet', 'settings.json'),
18
- ];
19
- const files = [];
20
- for (const path of paths) files.push(await inspect(path));
21
- const directories = [];
22
- for (const tool of ['.codex', '.claude', '.gemini', '.cursor']) {
23
- for (const kind of ['skills', 'plugins']) {
24
- const path = join(home, tool, kind);
25
- const entries = await readdir(path).catch(() => []);
26
- directories.push({
27
- tool,
28
- kind,
29
- entries: entries.length,
30
- ownership: 'native/unmanaged; review sources before migration',
31
- });
32
- }
33
- }
34
- return {
35
- version: 1,
36
- files,
37
- directories,
38
- environment: Object.keys(process.env).filter((key) =>
39
- /^(CODEX_|CLAUDE_|ANTHROPIC_|OPENAI_|GEMINI_|GOOGLE_|OPENCODE_|T3CODE_|CLIPROXY_|CURSOR_)/.test(
40
- key
41
- )
42
- ),
43
- warning:
44
- 'Metadata only; values, credentials and runtime state are withheld. This machine is not proof of fleet-wide coverage. Native/project/organization settings may add configuration.',
45
- };
46
- }
47
-
48
- async function inspect(path: string) {
49
- try {
50
- const text = await readFile(path, 'utf8');
51
- const value: unknown = path.endsWith('.toml')
52
- ? Bun.TOML.parse(text)
53
- : JSON.parse(text);
54
- return {
55
- path,
56
- present: true,
57
- fields: fieldNames(value),
58
- ownership:
59
- 'native/unmanaged; dedicated homelab profiles do not overwrite this file',
60
- };
61
- } catch (error) {
62
- return {
63
- path,
64
- present: (error as NodeJS.ErrnoException).code !== 'ENOENT',
65
- fields: [],
66
- ownership:
67
- 'missing or unparseable; inspect locally, no raw error retained',
68
- };
69
- }
70
- }
71
-
72
- export function fieldNames(value: unknown): string[] {
73
- if (!value || typeof value !== 'object' || Array.isArray(value)) return [];
74
- return Object.keys(value)
75
- .filter((key) => /^[a-zA-Z_$][a-zA-Z0-9_$-]{0,63}$/.test(key))
76
- .sort();
77
- }
package/src/agents/cli.ts DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env bun
2
- /** Internal entry converge runs on each node for agent profile commands
3
- * (`agents apply|status|verify|run`). People use `homelab workstation agents`.
4
- */
5
- import { Command } from 'commander';
6
- import { registerAgents } from './command';
7
-
8
- const program = new Command('fleet-agents')
9
- .option('--json', 'Machine-readable output')
10
- .option('--yes', 'Apply without confirmation')
11
- .option('--non-interactive', 'Fail instead of prompting');
12
- registerAgents(program, () => program.opts());
13
- await program.parseAsync(process.argv);