@crvouga/homelab 0.23.13 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/aube-lock.yaml +73 -297
  2. package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/package.json +1 -1
  3. package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/aube-lock.yaml +42 -42
  4. package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/package.json +1 -1
  5. package/README.md +54 -76
  6. package/ansible/ubuntu/agent-tool.py +106 -1
  7. package/ansible/ubuntu/heavy.py +142 -0
  8. package/ansible/ubuntu/idle-reboot.py +125 -0
  9. package/ansible/ubuntu/policy.json +58 -3
  10. package/ansible/ubuntu/t3-desktop.yml +7 -0
  11. package/ansible/ubuntu/t3-hang-snapshot.sh +75 -0
  12. package/ansible/ubuntu/t3-headless.yml +7 -0
  13. package/ansible/ubuntu/t3-health.sh +71 -3
  14. package/ansible/ubuntu/t3-policy.yml +14 -5
  15. package/ansible/ubuntu/tasks/packages.yml +2 -0
  16. package/ansible/ubuntu/tasks/recovery.yml +16 -2
  17. package/ansible/ubuntu/tasks/resources.yml +25 -2
  18. package/ansible/ubuntu/tasks/unattended-upgrades.yml +24 -6
  19. package/ansible/ubuntu/tasks/updates.yml +59 -0
  20. package/ansible/ubuntu/wip-guard.py +141 -14
  21. package/bootstrap/doctor.ts +0 -4
  22. package/bootstrap/project-action.sh +4 -5
  23. package/bootstrap/shell-path.ts +17 -19
  24. package/cliproxy/README.md +5 -6
  25. package/cliproxy/config.template.yaml +1 -15
  26. package/cliproxy/docs/health-workflow.example.yml +6 -6
  27. package/cliproxy/docs/model-health.md +8 -8
  28. package/cliproxy/scripts/accounts.py +3 -4
  29. package/cliproxy/scripts/fleet_sync.py +2 -13
  30. package/cliproxy/scripts/ops +3 -21
  31. package/docs/authentication.md +21 -26
  32. package/docs/convergence.md +28 -32
  33. package/docs/declared.md +30 -31
  34. package/docs/durability.md +9 -0
  35. package/docs/github.md +0 -9
  36. package/docs/machine-setup.md +16 -17
  37. package/docs/manager-recovery.md +0 -2
  38. package/docs/operations.md +12 -11
  39. package/docs/releasing.md +18 -21
  40. package/docs/runbooks.md +22 -78
  41. package/docs/support-matrix.md +1 -1
  42. package/docs/ubuntu-sync.md +71 -65
  43. package/docs/worker-contract.md +112 -15
  44. package/examples/fleet.json +0 -1
  45. package/llms.txt +0 -2
  46. package/mise.lock +206 -780
  47. package/mise.toml +12 -27
  48. package/package.json +5 -6
  49. package/schema/check-ids.json +41 -482
  50. package/schema/fleet.schema.json +6 -57
  51. package/schema/roster.schema.json +0 -2
  52. package/src/agent-session-limit.ts +2 -7
  53. package/src/auth-checks.ts +1 -3
  54. package/src/check-owners.ts +0 -13
  55. package/src/check-registry.ts +13 -72
  56. package/src/cli/agent-guide.ts +3 -16
  57. package/src/cli/command-index.ts +0 -12
  58. package/src/cli/fleet-sync-manager.ts +4 -146
  59. package/src/cli/fleet-sync-output.ts +1 -4
  60. package/src/cli/fleet-sync-plan.ts +1 -24
  61. package/src/cli/fleet-sync-remote.ts +2 -1
  62. package/src/cli/fleet-sync-vault.ts +1 -2
  63. package/src/cli/fleet-sync.ts +8 -44
  64. package/src/cli/fleet.ts +1 -2
  65. package/src/cli/program.ts +3 -14
  66. package/src/cli/register-fleet.ts +1 -55
  67. package/src/cli/registry.ts +1 -43
  68. package/src/config.ts +0 -2
  69. package/src/definition.ts +8 -83
  70. package/src/fleet-config.ts +1 -1
  71. package/src/ide/definition.ts +2 -29
  72. package/src/ide/super.ts +4 -35
  73. package/src/ide/t3.ts +9 -38
  74. package/src/manager-sync.ts +1 -1
  75. package/src/node-converge-linux.ts +4 -47
  76. package/src/node-converge-shared.ts +1 -22
  77. package/src/{agents/toolchain.ts → pinned-path.ts} +0 -17
  78. package/src/platform/agent-oom-check.ts +104 -0
  79. package/src/platform/t3-policy.ts +23 -36
  80. package/src/platform/t3-service.ts +117 -0
  81. package/src/platform/wip-guard-check.ts +65 -0
  82. package/src/remote-entry.ts +2 -41
  83. package/src/repair-catalog.ts +0 -30
  84. package/src/schedule-check.ts +17 -4
  85. package/src/service-auth.ts +0 -50
  86. package/src/state/litestream.ts +1 -1
  87. package/src/t3/retire-providers.ts +79 -0
  88. package/src/t3/version.ts +1 -1
  89. package/src/transport.ts +2 -6
  90. package/src/types.ts +0 -2
  91. package/src/version-parity.ts +0 -8
  92. package/src/worker-access-checks.ts +0 -75
  93. package/src/worker-host-checks.ts +78 -1
  94. package/src/worker-policy.ts +0 -2
  95. package/src/worker-readiness.ts +2 -0
  96. package/src/worker-sizing.ts +25 -0
  97. package/.mise/locks/azure-cli/2.93.0~a837e014/pyproject.toml +0 -5
  98. package/.mise/locks/azure-cli/2.93.0~a837e014/uv.lock +0 -2841
  99. package/.mise/locks/gemini/0.71.1~84aac8e6/aube-lock.yaml +0 -124
  100. package/.mise/locks/gemini/0.71.1~84aac8e6/package.json +0 -12
  101. package/agents/antigravity-proxy.ts +0 -3
  102. package/agents/audit.md +0 -88
  103. package/agents/bin/agy +0 -10
  104. package/agents/bin/antigravity +0 -10
  105. package/agents/bin/claude +0 -10
  106. package/agents/bin/codex +0 -10
  107. package/agents/bin/grok +0 -10
  108. package/agents/bin/opencode +0 -10
  109. package/agents/claude-proxy +0 -5
  110. package/agents/claude-proxy.ts +0 -3
  111. package/agents/codex-proxy.ts +0 -3
  112. package/agents/grok-proxy.ts +0 -3
  113. package/agents/managed-proxy.ts +0 -109
  114. package/agents/opencode-proxy.ts +0 -3
  115. package/agents/registry.json +0 -209
  116. package/agents/registry.schema.json +0 -149
  117. package/agents/setup.md +0 -158
  118. package/agents/t3.json +0 -40
  119. package/ansible/agents/agents.yml +0 -135
  120. package/ansible/agents/commands.yml +0 -32
  121. package/ansible/agents/receipts.yml +0 -19
  122. package/ansible/agents/templates/antigravity.settings.json.j2 +0 -3
  123. package/ansible/agents/templates/claude.settings.json.j2 +0 -3
  124. package/ansible/agents/templates/codex.config.toml.j2 +0 -11
  125. package/ansible/agents/templates/gemini.settings.json.j2 +0 -14
  126. package/ansible/agents/templates/grok.config.toml.j2 +0 -25
  127. package/ansible/agents/templates/opencode.json.j2 +0 -24
  128. package/ansible/agents/templates/receipt.json.j2 +0 -10
  129. package/ansible/t3/provider-keys.yml +0 -24
  130. package/docs/accounts.md +0 -256
  131. package/src/accounts/checks.ts +0 -226
  132. package/src/accounts/context.ts +0 -77
  133. package/src/accounts/propagate.ts +0 -62
  134. package/src/accounts/roster.ts +0 -112
  135. package/src/accounts/selection.ts +0 -67
  136. package/src/accounts/sessions.ts +0 -354
  137. package/src/agents/account-relay.ts +0 -279
  138. package/src/agents/accounts.ts +0 -94
  139. package/src/agents/admission.ts +0 -65
  140. package/src/agents/audit.ts +0 -77
  141. package/src/agents/cli.ts +0 -13
  142. package/src/agents/command.ts +0 -257
  143. package/src/agents/commands.ts +0 -127
  144. package/src/agents/converge.ts +0 -339
  145. package/src/agents/doctor.ts +0 -107
  146. package/src/agents/errors.ts +0 -2
  147. package/src/agents/files.ts +0 -43
  148. package/src/agents/fleet-verify.ts +0 -195
  149. package/src/agents/launch.ts +0 -361
  150. package/src/agents/native-verify.ts +0 -738
  151. package/src/agents/provider-errors.ts +0 -57
  152. package/src/agents/registry.ts +0 -61
  153. package/src/agents/render.ts +0 -121
  154. package/src/agents/round-trip.ts +0 -192
  155. package/src/agents/secrets.ts +0 -48
  156. package/src/agents/verify-cache.ts +0 -164
  157. package/src/agents/verify.ts +0 -129
  158. package/src/cli/fleet-accounts.ts +0 -294
  159. package/src/cli/fleet-sync-accounts.ts +0 -62
  160. package/src/cli/node-deployment.ts +0 -34
  161. package/src/cli/node-sync.ts +0 -121
  162. package/src/cli/node-t3.ts +0 -35
  163. package/src/cli/t3/command.ts +0 -91
  164. package/src/cli/t3/register.ts +0 -56
  165. package/src/configure.ts +0 -271
  166. package/src/github/copilot.ts +0 -54
  167. package/src/t3/accounts.ts +0 -90
  168. package/src/t3/antigravity.ts +0 -93
  169. package/src/t3/desired.ts +0 -174
  170. package/src/t3/diagnostics.ts +0 -42
  171. package/src/t3/models.ts +0 -354
  172. package/src/t3/names-check.ts +0 -53
  173. package/src/t3/names.ts +0 -155
  174. package/src/t3/plan.ts +0 -106
  175. package/src/t3/provider-keys.ts +0 -49
  176. package/src/t3/providers.ts +0 -102
  177. package/src/t3/reconcile.ts +0 -133
package/src/t3/desired.ts DELETED
@@ -1,174 +0,0 @@
1
- import { join, resolve } from 'node:path';
2
- import { homedir, hostname } from 'node:os';
3
- import { FleetUsageError } from '../errors';
4
- import { object, read } from './files';
5
- import { T3DiagnosticError } from './diagnostics';
6
- import { proxyName } from './names';
7
- import { accountInstances, proxyAccounts, type Roster } from './accounts';
8
-
9
- export interface T3Options {
10
- id?: string;
11
- t3Home?: string;
12
- definition?: string;
13
- planHash?: string;
14
- dryRun?: boolean;
15
- import?: string;
16
- /** Internal: the proxy account roster (read live when omitted). */
17
- roster?: Roster;
18
- }
19
-
20
- export function nodeId(value?: string): string {
21
- const id =
22
- value ??
23
- hostname()
24
- .toLowerCase()
25
- .replace(/[^a-z0-9-]/g, '-')
26
- .slice(0, 63);
27
- if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(id))
28
- throw new FleetUsageError('Invalid node ID. Use --id NAME.');
29
- return id;
30
- }
31
-
32
- export function paths(options: T3Options, workspace: string) {
33
- const base = resolve(
34
- options.t3Home ?? process.env['T3CODE_HOME'] ?? join(homedir(), '.t3')
35
- );
36
- return {
37
- settings: join(base, 'userdata/settings.json'),
38
- state: join(base, 'userdata/personal-managed.json'),
39
- definition: resolve(
40
- options.definition ?? join(workspace, 'agents/t3.json')
41
- ),
42
- };
43
- }
44
-
45
- /** The managed instances: the fixed ones in the definition plus one per
46
- * provider account signed in on the CLI proxy (`roster`, read live).
47
- */
48
- export async function desired(
49
- path: string,
50
- workspace: string,
51
- id: string,
52
- roster: Roster = proxyAccounts
53
- ) {
54
- const raw = await read(path);
55
- if (raw === null)
56
- throw new FleetUsageError('T3 definition is missing in this checkout.');
57
- const doc = object(raw);
58
- if (
59
- doc['version'] !== 1 ||
60
- Object.keys(doc).some((key) => !['version', 'instances'].includes(key))
61
- )
62
- throw new FleetUsageError(
63
- 'Unsupported T3 definition. Expected version 1 and instances.'
64
- );
65
- const instances = object(JSON.stringify(doc['instances'] ?? null));
66
- for (const [key, value] of Object.entries(instances))
67
- validateInstance(key, value);
68
- const agents =
69
- process.platform === 'win32'
70
- ? join(homedir(), 'AppData/Local/personal/agents')
71
- : join(homedir(), '.config/personal/agents');
72
- const variables: Record<string, string> = {
73
- workspace: resolve(workspace),
74
- agents,
75
- node: id,
76
- };
77
- // Substitute individual strings, not serialized JSON: paths may contain quotes/backslashes.
78
- return {
79
- ...(expand(instances, variables) as Record<string, unknown>),
80
- ...accountInstances(await readRoster(roster), variables),
81
- };
82
- }
83
-
84
- function expand(value: unknown, variables: Record<string, string>): unknown {
85
- if (typeof value === 'string')
86
- return value.replace(/\$\{([^}]+)\}/g, (_, key: string) => {
87
- if (!(key in variables))
88
- throw new FleetUsageError('Unknown variable in T3 definition.');
89
- return variables[key]!;
90
- });
91
- if (Array.isArray(value)) return value.map((item) => expand(item, variables));
92
- if (value && typeof value === 'object')
93
- return Object.fromEntries(
94
- Object.entries(value).map(([key, item]) => [key, expand(item, variables)])
95
- );
96
- return value;
97
- }
98
-
99
- /** Each fixed driver accepts only the adapter fields fleet sets, under its
100
- * conventional `<Provider> CLI Proxy` name. Credentials never appear here (T3
101
- * refuses a managed policy that holds one): wrappers read them from Vault at
102
- * launch.
103
- */
104
- const DRIVERS: Record<
105
- string,
106
- { required: string[]; env?: Record<string, string> }
107
- > = {
108
- opencode: { required: ['binaryPath'] },
109
- grok: { required: ['binaryPath'], env: { XAI_API_KEY: 'fleet-cli-proxy' } },
110
- };
111
-
112
- function validateInstance(id: string, value: unknown): void {
113
- const instance = object(JSON.stringify(value));
114
- const config = object(JSON.stringify(instance['config']));
115
- const driver = DRIVERS[String(instance['driver'])];
116
- if (
117
- !/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(id) ||
118
- !driver ||
119
- instance['displayName'] !== proxyName(String(instance['driver'])) ||
120
- typeof instance['enabled'] !== 'boolean' ||
121
- Object.keys(instance).some(
122
- (key) =>
123
- !['driver', 'displayName', 'enabled', 'config', 'environment'].includes(
124
- key
125
- )
126
- ) ||
127
- !validConfig(config, driver) ||
128
- !validEnvironment(instance['environment'], driver.env ?? {})
129
- )
130
- throw new FleetUsageError(
131
- 'Invalid T3 instance definition; only the supported managed adapter fields are accepted.'
132
- );
133
- }
134
-
135
- function validConfig(
136
- config: Record<string, unknown>,
137
- driver: { required: string[] }
138
- ): boolean {
139
- return (
140
- Object.keys(config).every((key) => driver.required.includes(key)) &&
141
- driver.required.every((key) => typeof config[key] === 'string')
142
- );
143
- }
144
-
145
- /** WS_AGENT_NODE first, then exactly the driver's fixed non-secret values. */
146
- function validEnvironment(
147
- env: unknown,
148
- fixed: Record<string, string>
149
- ): boolean {
150
- const extra = Object.entries(fixed);
151
- if (!Array.isArray(env) || env.length !== 1 + extra.length) return false;
152
- const [node, ...rest] = env.map((item) => object(JSON.stringify(item)));
153
- return (
154
- node!['name'] === 'WS_AGENT_NODE' &&
155
- node!['value'] === '${node}' &&
156
- node!['sensitive'] === false &&
157
- Object.keys(node!).length === 3 &&
158
- rest.every(
159
- (variable, index) =>
160
- variable['name'] === extra[index]![0] &&
161
- variable['value'] === extra[index]![1] &&
162
- variable['sensitive'] === false &&
163
- Object.keys(variable).length === 3
164
- )
165
- );
166
- }
167
-
168
- async function readRoster(roster: Roster) {
169
- try {
170
- return await roster();
171
- } catch {
172
- throw new T3DiagnosticError();
173
- }
174
- }
@@ -1,42 +0,0 @@
1
- import type { Check } from '../types';
2
-
3
- /** Fixed diagnostic only: upstream errors can contain credentials. */
4
- export class T3DiagnosticError extends Error {
5
- readonly check: Check = {
6
- id: 't3:account-roster',
7
- status: 'fail',
8
- summary: 'T3_ACCOUNT_ROSTER_UNAVAILABLE',
9
- remedy: {
10
- action:
11
- 'Run homelab accounts on this machine to verify proxy access and the proxy-client-key secret, then retry homelab t3-reconcile --dry-run. Existing providers were preserved.',
12
- },
13
- };
14
-
15
- constructor() {
16
- super('T3_ACCOUNT_ROSTER_UNAVAILABLE');
17
- }
18
- }
19
-
20
- export async function diagnoseT3<T>(
21
- stage: 'deployment' | 'definition' | 'reconciliation',
22
- action: () => Promise<T>
23
- ): Promise<T> {
24
- try {
25
- return await action();
26
- } catch (error) {
27
- if (error instanceof T3DiagnosticError) throw error;
28
- const failure = new T3DiagnosticError();
29
- Object.assign(failure.check, { id: 't3:reconciliation' });
30
- failure.check.summary = 'T3_RECONCILIATION_UNAVAILABLE';
31
- failure.check.remedy = {
32
- action:
33
- stage === 'deployment'
34
- ? 'Inspect the local node receipt and its file permissions; restore the receipt before retrying homelab t3.'
35
- : stage === 'definition'
36
- ? 'Verify the installed release contains agents/t3.json and can read it. Reinstall the pinned package and retry homelab t3.'
37
- : 'Inspect T3 settings and personal-managed.json locally for invalid JSON, symlinks or file permissions. Restore a valid backup, check for another T3 operation, then retry homelab t3-reconcile --dry-run. Do not share file contents.',
38
- };
39
- failure.message = failure.check.summary;
40
- throw failure;
41
- }
42
- }
package/src/t3/models.ts DELETED
@@ -1,354 +0,0 @@
1
- import { homedir } from 'node:os';
2
- import proxyTemplate from '../../cliproxy/config.template.yaml';
3
- import { join, resolve } from 'node:path';
4
- import type { Check } from '../types';
5
- import { fleet, fleetJson } from '../fleet-config';
6
- import {
7
- accountDriver,
8
- accountInstanceId,
9
- proxyAccounts,
10
- type Roster,
11
- } from './accounts';
12
- import { preferredModels, type Account } from '../agents/accounts';
13
- import { canonical, object, read, write } from './files';
14
-
15
- /** T3's own setting for what an instance's model picker shows: models it
16
- * hides and the order of the rest. T3 opens an instance on its catalogue's
17
- * default model, or on the first model shown when that one is hidden.
18
- */
19
- const PREFERENCES = 'providerModelPreferences';
20
- type Preference = { hiddenModels: string[]; modelOrder: string[] };
21
-
22
- const strings = (value: unknown): string[] =>
23
- Array.isArray(value)
24
- ? value.filter((item): item is string => typeof item === 'string')
25
- : [];
26
- const record = (value: unknown): Record<string, unknown> =>
27
- value && typeof value === 'object' && !Array.isArray(value)
28
- ? (value as Record<string, unknown>)
29
- : {};
30
- const preference = (value: unknown): Preference => ({
31
- hiddenModels: strings(record(value)['hiddenModels']),
32
- modelOrder: strings(record(value)['modelOrder']),
33
- });
34
-
35
- /** The models T3 keeps for a driver (userdata/model-manifest.json). Null when
36
- * it has no list for the driver: it asks the tool itself.
37
- */
38
- function catalogueOf(
39
- manifest: Record<string, unknown>,
40
- driver: string
41
- ): string[] | null {
42
- const models = record(record(manifest['manifest'])['currentModels'])[driver];
43
- return Array.isArray(models) ? strings(models) : null;
44
- }
45
-
46
- /** Antigravity also discovers models from its live ACP session. Its native
47
- * IDs can appear in the picker before T3 adds them to the static manifest.
48
- * The proxy template names the native IDs that homelab routes as aliases.
49
- */
50
- const antigravityAliases = (
51
- proxyTemplate as {
52
- oauth: { 'model-alias': { antigravity: { alias: string }[] } };
53
- }
54
- ).oauth['model-alias'].antigravity.map(({ alias }) => alias);
55
-
56
- function preferenceCatalogue(
57
- manifest: Record<string, unknown>,
58
- driver: string
59
- ) {
60
- const catalogue = catalogueOf(manifest, driver);
61
- return driver === 'antigravity'
62
- ? [...new Set([...(catalogue ?? []), ...antigravityAliases])]
63
- : catalogue;
64
- }
65
-
66
- /** The custom models an instance adds. T3 always shows them. */
67
- function customOf(instance: unknown): string[] {
68
- const models = record(record(instance)['config'])['customModels'];
69
- return Array.isArray(models)
70
- ? models.flatMap((model: unknown) =>
71
- typeof model === 'string'
72
- ? [model]
73
- : typeof record(model)['slug'] === 'string'
74
- ? [record(model)['slug'] as string]
75
- : []
76
- )
77
- : [];
78
- }
79
-
80
- /** The managed instance of each account that T3 holds on this machine. */
81
- function managed(accounts: Account[], settings: Record<string, unknown>) {
82
- const instances = record(settings['providerInstances']);
83
- return accounts.flatMap((account) => {
84
- const driver = accountDriver(account.tool);
85
- const id = accountInstanceId(account);
86
- return driver && Object.hasOwn(instances, id)
87
- ? [{ account, driver, id, instance: instances[id] }]
88
- : [];
89
- });
90
- }
91
-
92
- /** What each account's instance should show: a catalogue model is hidden
93
- * exactly when the account does not serve it, and an instance that hides one
94
- * lists the preferred defaults its account serves first, so T3 opens it on
95
- * the first of them when its own default is hidden. Everything else (other
96
- * instances, hidden models outside the catalogue, the order of the rest) is
97
- * the machine's own and is kept.
98
- */
99
- function planPreferences(
100
- accounts: Account[],
101
- settings: Record<string, unknown>,
102
- manifest: Record<string, unknown>
103
- ) {
104
- const next = { ...record(settings[PREFERENCES]) };
105
- const changes = new Set<string>();
106
- for (const { account, driver, id } of managed(accounts, settings)) {
107
- const catalogue = preferenceCatalogue(manifest, driver);
108
- if (!catalogue) continue;
109
- const current = preference(next[id]);
110
- const unserved = catalogue.filter(
111
- (model) => !account.models.includes(model)
112
- );
113
- const hide = unserved.filter(
114
- (model) => !current.hiddenModels.includes(model)
115
- );
116
- const show = current.hiddenModels.filter(
117
- (model) => catalogue.includes(model) && account.models.includes(model)
118
- );
119
- const first = unserved.length
120
- ? preferredModels(account.tool).filter((model) =>
121
- account.models.includes(model)
122
- )
123
- : [];
124
- const modelOrder = [
125
- ...first,
126
- ...current.modelOrder.filter((model) => !first.includes(model)),
127
- ];
128
- const reordered = canonical(modelOrder) !== canonical(current.modelOrder);
129
- for (const model of hide) changes.add(`${account.tool}: hide ${model}`);
130
- for (const model of show) changes.add(`${account.tool}: show ${model}`);
131
- if (reordered)
132
- changes.add(`${account.tool}: list ${first.join(', ')} first`);
133
- if (hide.length || show.length || reordered)
134
- next[id] = {
135
- ...record(next[id]),
136
- hiddenModels: [
137
- ...current.hiddenModels.filter((model) => !show.includes(model)),
138
- ...hide,
139
- ],
140
- modelOrder,
141
- };
142
- }
143
- return { preferences: next, changes };
144
- }
145
-
146
- export interface ModelsOptions {
147
- t3Home: string;
148
- roster: Roster;
149
- required?: Record<string, string[]>;
150
- /** Write what each account's instance shows (converge); without it the
151
- * check only measures, and says what a sync would change.
152
- */
153
- apply?: boolean;
154
- /** Tries before a settings file T3 keeps rewriting is reported busy. */
155
- attempts?: number;
156
- pause?: () => Promise<void>;
157
- /** Runs between the read and the write: where T3 may write too. */
158
- beforeWrite?: () => Promise<void>;
159
- }
160
-
161
- /** Reads what the check needs and, with `apply`, writes what each account's
162
- * instance shows. T3 writes the same file and offers no compare-and-swap, so
163
- * a write happens only when the file is still what was read; otherwise the
164
- * plan is made again, a bounded number of times. Null when T3 kept writing.
165
- */
166
- async function reconcile(options: ModelsOptions) {
167
- const path = join(options.t3Home, 'userdata/settings.json');
168
- const pause =
169
- options.pause ?? (() => new Promise((done) => setTimeout(done, 500)));
170
- const accounts = await options.roster();
171
- const manifest = object(
172
- await read(join(options.t3Home, 'userdata/model-manifest.json'))
173
- );
174
- for (let attempt = 1; ; attempt++) {
175
- const raw = await read(path);
176
- const settings = object(raw);
177
- const plan = planPreferences(accounts, settings, manifest);
178
- // Measured as a sync leaves it: what a sync would hide is pending, not
179
- // a model T3 wrongly shows.
180
- const result = {
181
- accounts,
182
- manifest,
183
- changes: plan.changes,
184
- settings: { ...settings, [PREFERENCES]: plan.preferences },
185
- };
186
- if (!options.apply || !plan.changes.size) return result;
187
- await options.beforeWrite?.();
188
- if ((await read(path)) === raw) {
189
- await write(path, JSON.stringify(result.settings, null, 2) + '\n');
190
- return result;
191
- }
192
- if (attempt >= (options.attempts ?? 3)) return null;
193
- await pause();
194
- }
195
- }
196
-
197
- /** `t3:models`: every account instance the fleet manages shows only models
198
- * the proxy serves for its account, opens on one of them, and every required
199
- * model is both served and shown. Accounts of one tool may be entitled to
200
- * different models: that is settled by hiding, per instance, what its account
201
- * does not serve, and is no fault. A report names tools and models, never an
202
- * account.
203
- */
204
- export async function modelsCheck(options: ModelsOptions): Promise<Check> {
205
- const warn = (summary: string, action: string): Check => ({
206
- id: 't3:models',
207
- status: 'warn',
208
- summary,
209
- remedy: { action },
210
- });
211
- let result;
212
- try {
213
- result = await reconcile(options);
214
- } catch {
215
- return warn(
216
- 'T3_MODELS_UNVERIFIED',
217
- 'The proxy’s model list or T3’s settings could not be read on this machine. Check that the CLI proxy answers and T3 has started once, then run converge.'
218
- );
219
- }
220
- if (!result)
221
- return warn(
222
- 'T3_SETTINGS_BUSY',
223
- 'T3 kept rewriting its settings while homelab hid the models an account does not serve. Run converge again; nothing was overwritten.'
224
- );
225
- const problems = mismatches(result, options.required ?? {});
226
- if (problems.size)
227
- return warn(
228
- 'T3_MODELS_MISMATCH',
229
- `${[...problems].sort().join('; ')}. Serve the model on the CLI proxy, or stop asking for it: remove it from t3.requiredModels in ${fleetJson()}, choose another default in T3, or remove the custom model. A model the proxy does not serve for an account fails when it is chosen in T3.`
230
- );
231
- if (result.changes.size && !options.apply)
232
- return warn(
233
- 'T3_MODELS_PENDING',
234
- `converge would change what T3 shows for an account’s instance, so that it shows only the models the proxy serves for that account: ${[...result.changes].sort().join('; ')}.`
235
- );
236
- return {
237
- id: 't3:models',
238
- status: 'pass',
239
- summary:
240
- 'Every model T3 shows for a managed account is one the proxy serves for it, and every required model is shown.',
241
- };
242
- }
243
-
244
- /** What `converge --only accounts` applies beside the instances: an
245
- * account that was just added shows only what it serves at once.
246
- */
247
- export const accountModels = (): Promise<Check> => {
248
- const required = fleet.t3?.requiredModels;
249
- return modelsCheck({
250
- t3Home: resolve(process.env['T3CODE_HOME'] ?? join(homedir(), '.t3')),
251
- roster: proxyAccounts,
252
- ...(required ? { required } : {}),
253
- apply: true,
254
- });
255
- };
256
-
257
- /** T3's own choices of a model to start with. */
258
- const SELECTIONS = {
259
- defaultModelSelection: 'default',
260
- fallbackModelSelection: 'fallback',
261
- };
262
-
263
- /** What is wrong with the models of each managed account instance. */
264
- function mismatches(
265
- {
266
- accounts,
267
- settings,
268
- manifest,
269
- }: {
270
- accounts: Account[];
271
- settings: Record<string, unknown>;
272
- manifest: Record<string, unknown>;
273
- },
274
- required: Record<string, string[]>
275
- ): Set<string> {
276
- const problems: string[] = [];
277
- const preferences = record(settings[PREFERENCES]);
278
- for (const { account, driver, id, instance } of managed(accounts, settings)) {
279
- const catalogue = catalogueOf(manifest, driver);
280
- const custom = customOf(instance);
281
- const hidden = preference(preferences[id]).hiddenModels;
282
- // Null when T3 has no list for the driver: it asks the tool itself.
283
- const shown =
284
- catalogue || custom.length
285
- ? [
286
- ...(catalogue ?? []).filter((model) => !hidden.includes(model)),
287
- ...custom,
288
- ]
289
- : null;
290
- problems.push(
291
- ...[
292
- ...shownProblems(account, shown),
293
- ...defaultProblems(account, id, settings),
294
- ...requiredProblems(account, shown, required[account.tool] ?? []),
295
- ].map((problem) => `${account.tool}: ${problem}`)
296
- );
297
- }
298
- return new Set(problems);
299
- }
300
-
301
- /** A model the instance shows that its account does not serve. */
302
- function shownProblems(account: Account, shown: string[] | null): string[] {
303
- if (!shown) return [];
304
- const problems = shown
305
- .filter((model) => !account.models.includes(model))
306
- .map((model) => `T3 offers ${model}, which the proxy does not serve`);
307
- if (problems.length === shown.length)
308
- problems.push(
309
- 'T3 offers no model the proxy serves for an account, so its instance has no default that works'
310
- );
311
- return problems;
312
- }
313
-
314
- /** A model the instance starts on that its account does not serve, and an
315
- * account whose default is not one of the preferred ones.
316
- */
317
- function defaultProblems(
318
- account: Account,
319
- id: string,
320
- settings: Record<string, unknown>
321
- ): string[] {
322
- const preferred = preferredModels(account.tool);
323
- const problems = preferred.some((model) => account.models.includes(model))
324
- ? []
325
- : [
326
- `an account serves none of the preferred defaults (${preferred.join(', ')}) and defaults to ${account.models[0]}; ask for a model it serves to be added to them, with an issue in homelab’s tracker (homelab --help names it)`,
327
- ];
328
- for (const [key, name] of Object.entries(SELECTIONS)) {
329
- const selection = record(settings[key]);
330
- const model = selection['model'];
331
- if (
332
- selection['instanceId'] === id &&
333
- typeof model === 'string' &&
334
- !account.models.includes(model)
335
- )
336
- problems.push(`T3’s ${name} model ${model} is not served by the proxy`);
337
- }
338
- return problems;
339
- }
340
-
341
- /** A required model the proxy does not serve, or T3 does not show. */
342
- function requiredProblems(
343
- account: Account,
344
- shown: string[] | null,
345
- required: string[]
346
- ): string[] {
347
- return required.flatMap((model) =>
348
- !account.models.includes(model)
349
- ? [`the proxy does not serve the required ${model}`]
350
- : shown && !shown.includes(model)
351
- ? [`T3 does not offer the required ${model}`]
352
- : []
353
- );
354
- }
@@ -1,53 +0,0 @@
1
- import { desired, nodeId, paths } from './desired';
2
- import { conformT3Names } from './names';
3
- import type { Roster } from './accounts';
4
- import type { Check } from '../types';
5
-
6
- /** Fleet check: this machine's T3 lists every provider under the convention. */
7
- export async function providerNames(
8
- id: string,
9
- workspace: string,
10
- apply: boolean,
11
- { t3Home, roster }: { t3Home?: string; roster?: Roster } = {}
12
- ): Promise<Check> {
13
- try {
14
- const target = paths(t3Home ? { t3Home } : {}, workspace);
15
- const managed = Object.fromEntries(
16
- Object.entries(
17
- await desired(target.definition, workspace, nodeId(id), roster)
18
- ).map(([instance, value]) => [
19
- instance,
20
- String((value as { displayName?: unknown }).displayName),
21
- ])
22
- );
23
- const { changed } = await conformT3Names(target.settings, managed, {
24
- apply,
25
- });
26
- return changed && !apply
27
- ? {
28
- id: 't3:provider-names',
29
- status: 'warn',
30
- summary: 'T3_PROVIDER_NAMES_PENDING',
31
- remedy: {
32
- action:
33
- 'converge renames these providers to the convention when applied.',
34
- },
35
- }
36
- : {
37
- id: 't3:provider-names',
38
- status: 'pass',
39
- summary:
40
- 'Every T3 provider is named "<Provider> CLI Proxy" or "<Provider> <account email>".',
41
- };
42
- } catch {
43
- return {
44
- id: 't3:provider-names',
45
- status: 'fail',
46
- summary: 'T3_PROVIDER_NAMES_UNVERIFIED',
47
- remedy: {
48
- action:
49
- 'T3 settings were unreadable or changed during the rename. Rerun converge; only provider display names are written.',
50
- },
51
- };
52
- }
53
- }