@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.
- package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/aube-lock.yaml +73 -297
- package/.mise/locks/npm-vercel/{68.0.0 → 68.2.0}/package.json +1 -1
- package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/aube-lock.yaml +42 -42
- package/.mise/locks/npm-wrangler/{4.169.0 → 4.170.0}/package.json +1 -1
- package/README.md +54 -76
- package/ansible/ubuntu/agent-tool.py +106 -1
- package/ansible/ubuntu/heavy.py +142 -0
- package/ansible/ubuntu/idle-reboot.py +125 -0
- package/ansible/ubuntu/policy.json +58 -3
- package/ansible/ubuntu/t3-desktop.yml +7 -0
- package/ansible/ubuntu/t3-hang-snapshot.sh +75 -0
- package/ansible/ubuntu/t3-headless.yml +7 -0
- package/ansible/ubuntu/t3-health.sh +71 -3
- package/ansible/ubuntu/t3-policy.yml +14 -5
- package/ansible/ubuntu/tasks/packages.yml +2 -0
- package/ansible/ubuntu/tasks/recovery.yml +16 -2
- package/ansible/ubuntu/tasks/resources.yml +25 -2
- package/ansible/ubuntu/tasks/unattended-upgrades.yml +24 -6
- package/ansible/ubuntu/tasks/updates.yml +59 -0
- package/ansible/ubuntu/wip-guard.py +141 -14
- package/bootstrap/doctor.ts +0 -4
- package/bootstrap/project-action.sh +4 -5
- package/bootstrap/shell-path.ts +17 -19
- package/cliproxy/README.md +5 -6
- package/cliproxy/config.template.yaml +1 -15
- package/cliproxy/docs/health-workflow.example.yml +6 -6
- package/cliproxy/docs/model-health.md +8 -8
- package/cliproxy/scripts/accounts.py +3 -4
- package/cliproxy/scripts/fleet_sync.py +2 -13
- package/cliproxy/scripts/ops +3 -21
- package/docs/authentication.md +21 -26
- package/docs/convergence.md +28 -32
- package/docs/declared.md +30 -31
- package/docs/durability.md +9 -0
- package/docs/github.md +0 -9
- package/docs/machine-setup.md +16 -17
- package/docs/manager-recovery.md +0 -2
- package/docs/operations.md +12 -11
- package/docs/releasing.md +18 -21
- package/docs/runbooks.md +22 -78
- package/docs/support-matrix.md +1 -1
- package/docs/ubuntu-sync.md +71 -65
- package/docs/worker-contract.md +112 -15
- package/examples/fleet.json +0 -1
- package/llms.txt +0 -2
- package/mise.lock +206 -780
- package/mise.toml +12 -27
- package/package.json +5 -6
- package/schema/check-ids.json +41 -482
- package/schema/fleet.schema.json +6 -57
- package/schema/roster.schema.json +0 -2
- package/src/agent-session-limit.ts +2 -7
- package/src/auth-checks.ts +1 -3
- package/src/check-owners.ts +0 -13
- package/src/check-registry.ts +13 -72
- package/src/cli/agent-guide.ts +3 -16
- package/src/cli/command-index.ts +0 -12
- package/src/cli/fleet-sync-manager.ts +4 -146
- package/src/cli/fleet-sync-output.ts +1 -4
- package/src/cli/fleet-sync-plan.ts +1 -24
- package/src/cli/fleet-sync-remote.ts +2 -1
- package/src/cli/fleet-sync-vault.ts +1 -2
- package/src/cli/fleet-sync.ts +8 -44
- package/src/cli/fleet.ts +1 -2
- package/src/cli/program.ts +3 -14
- package/src/cli/register-fleet.ts +1 -55
- package/src/cli/registry.ts +1 -43
- package/src/config.ts +0 -2
- package/src/definition.ts +8 -83
- package/src/fleet-config.ts +1 -1
- package/src/ide/definition.ts +2 -29
- package/src/ide/super.ts +4 -35
- package/src/ide/t3.ts +9 -38
- package/src/manager-sync.ts +1 -1
- package/src/node-converge-linux.ts +4 -47
- package/src/node-converge-shared.ts +1 -22
- package/src/{agents/toolchain.ts → pinned-path.ts} +0 -17
- package/src/platform/agent-oom-check.ts +104 -0
- package/src/platform/t3-policy.ts +23 -36
- package/src/platform/t3-service.ts +117 -0
- package/src/platform/wip-guard-check.ts +65 -0
- package/src/remote-entry.ts +2 -41
- package/src/repair-catalog.ts +0 -30
- package/src/schedule-check.ts +17 -4
- package/src/service-auth.ts +0 -50
- package/src/state/litestream.ts +1 -1
- package/src/t3/retire-providers.ts +79 -0
- package/src/t3/version.ts +1 -1
- package/src/transport.ts +2 -6
- package/src/types.ts +0 -2
- package/src/version-parity.ts +0 -8
- package/src/worker-access-checks.ts +0 -75
- package/src/worker-host-checks.ts +78 -1
- package/src/worker-policy.ts +0 -2
- package/src/worker-readiness.ts +2 -0
- package/src/worker-sizing.ts +25 -0
- package/.mise/locks/azure-cli/2.93.0~a837e014/pyproject.toml +0 -5
- package/.mise/locks/azure-cli/2.93.0~a837e014/uv.lock +0 -2841
- package/.mise/locks/gemini/0.71.1~84aac8e6/aube-lock.yaml +0 -124
- package/.mise/locks/gemini/0.71.1~84aac8e6/package.json +0 -12
- package/agents/antigravity-proxy.ts +0 -3
- package/agents/audit.md +0 -88
- package/agents/bin/agy +0 -10
- package/agents/bin/antigravity +0 -10
- package/agents/bin/claude +0 -10
- package/agents/bin/codex +0 -10
- package/agents/bin/grok +0 -10
- package/agents/bin/opencode +0 -10
- package/agents/claude-proxy +0 -5
- package/agents/claude-proxy.ts +0 -3
- package/agents/codex-proxy.ts +0 -3
- package/agents/grok-proxy.ts +0 -3
- package/agents/managed-proxy.ts +0 -109
- package/agents/opencode-proxy.ts +0 -3
- package/agents/registry.json +0 -209
- package/agents/registry.schema.json +0 -149
- package/agents/setup.md +0 -158
- package/agents/t3.json +0 -40
- package/ansible/agents/agents.yml +0 -135
- package/ansible/agents/commands.yml +0 -32
- package/ansible/agents/receipts.yml +0 -19
- package/ansible/agents/templates/antigravity.settings.json.j2 +0 -3
- package/ansible/agents/templates/claude.settings.json.j2 +0 -3
- package/ansible/agents/templates/codex.config.toml.j2 +0 -11
- package/ansible/agents/templates/gemini.settings.json.j2 +0 -14
- package/ansible/agents/templates/grok.config.toml.j2 +0 -25
- package/ansible/agents/templates/opencode.json.j2 +0 -24
- package/ansible/agents/templates/receipt.json.j2 +0 -10
- package/ansible/t3/provider-keys.yml +0 -24
- package/docs/accounts.md +0 -256
- package/src/accounts/checks.ts +0 -226
- package/src/accounts/context.ts +0 -77
- package/src/accounts/propagate.ts +0 -62
- package/src/accounts/roster.ts +0 -112
- package/src/accounts/selection.ts +0 -67
- package/src/accounts/sessions.ts +0 -354
- package/src/agents/account-relay.ts +0 -279
- package/src/agents/accounts.ts +0 -94
- package/src/agents/admission.ts +0 -65
- package/src/agents/audit.ts +0 -77
- package/src/agents/cli.ts +0 -13
- package/src/agents/command.ts +0 -257
- package/src/agents/commands.ts +0 -127
- package/src/agents/converge.ts +0 -339
- package/src/agents/doctor.ts +0 -107
- package/src/agents/errors.ts +0 -2
- package/src/agents/files.ts +0 -43
- package/src/agents/fleet-verify.ts +0 -195
- package/src/agents/launch.ts +0 -361
- package/src/agents/native-verify.ts +0 -738
- package/src/agents/provider-errors.ts +0 -57
- package/src/agents/registry.ts +0 -61
- package/src/agents/render.ts +0 -121
- package/src/agents/round-trip.ts +0 -192
- package/src/agents/secrets.ts +0 -48
- package/src/agents/verify-cache.ts +0 -164
- package/src/agents/verify.ts +0 -129
- package/src/cli/fleet-accounts.ts +0 -294
- package/src/cli/fleet-sync-accounts.ts +0 -62
- package/src/cli/node-deployment.ts +0 -34
- package/src/cli/node-sync.ts +0 -121
- package/src/cli/node-t3.ts +0 -35
- package/src/cli/t3/command.ts +0 -91
- package/src/cli/t3/register.ts +0 -56
- package/src/configure.ts +0 -271
- package/src/github/copilot.ts +0 -54
- package/src/t3/accounts.ts +0 -90
- package/src/t3/antigravity.ts +0 -93
- package/src/t3/desired.ts +0 -174
- package/src/t3/diagnostics.ts +0 -42
- package/src/t3/models.ts +0 -354
- package/src/t3/names-check.ts +0 -53
- package/src/t3/names.ts +0 -155
- package/src/t3/plan.ts +0 -106
- package/src/t3/provider-keys.ts +0 -49
- package/src/t3/providers.ts +0 -102
- package/src/t3/reconcile.ts +0 -133
package/src/agents/launch.ts
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { mkdirSync } from 'node:fs';
|
|
4
|
-
import { AgentConfigurationError } from './errors';
|
|
5
|
-
import { registry, type Selection } from './registry';
|
|
6
|
-
import { accountPrefix, accountSlug, discoverAccounts } from './accounts';
|
|
7
|
-
import { startAccountRelay } from './account-relay';
|
|
8
|
-
import { proxyKey } from './secrets';
|
|
9
|
-
import { pinnedBinary, pinnedPath } from './toolchain';
|
|
10
|
-
import { AccountSelector } from '../accounts/selection';
|
|
11
|
-
import { fleet } from '../fleet-config';
|
|
12
|
-
import type { AccountSelection } from '../definition';
|
|
13
|
-
|
|
14
|
-
/** `account` (its email) pins a proxy launch to one signed-in proxy account. */
|
|
15
|
-
export async function launchProfile(
|
|
16
|
-
root: string,
|
|
17
|
-
selection: Selection,
|
|
18
|
-
args: string[],
|
|
19
|
-
account?: string
|
|
20
|
-
): Promise<number> {
|
|
21
|
-
const directory = join(
|
|
22
|
-
root,
|
|
23
|
-
selection.node,
|
|
24
|
-
selection.tool,
|
|
25
|
-
selection.profile
|
|
26
|
-
);
|
|
27
|
-
const env = { ...process.env };
|
|
28
|
-
env['PATH'] = pinnedPath(env);
|
|
29
|
-
// Do not allow an ambient gateway to silently change the selected route.
|
|
30
|
-
for (const name of [
|
|
31
|
-
'OPENAI_BASE_URL',
|
|
32
|
-
'ANTHROPIC_BASE_URL',
|
|
33
|
-
'ANTHROPIC_AUTH_TOKEN',
|
|
34
|
-
'CLAUDE_CODE_USE_BEDROCK',
|
|
35
|
-
'CLAUDE_CODE_USE_VERTEX',
|
|
36
|
-
'CLAUDE_CODE_USE_FOUNDRY',
|
|
37
|
-
'CLIPROXY_API_KEY',
|
|
38
|
-
'GOOGLE_GEMINI_BASE_URL',
|
|
39
|
-
'GROK_MODELS_BASE_URL',
|
|
40
|
-
'GROK_CODE_XAI_API_KEY',
|
|
41
|
-
'XAI_API_KEY',
|
|
42
|
-
])
|
|
43
|
-
delete env[name];
|
|
44
|
-
if (selection.profile === 'proxy') {
|
|
45
|
-
env['CLIPROXY_API_KEY'] = await proxyKey();
|
|
46
|
-
configureGatewayEnvironment(env, selection);
|
|
47
|
-
}
|
|
48
|
-
toolEnvironment(env, selection, directory);
|
|
49
|
-
const pinned =
|
|
50
|
-
selection.profile !== 'proxy'
|
|
51
|
-
? null
|
|
52
|
-
: account
|
|
53
|
-
? await pinAccount(env, selection, { account, directory })
|
|
54
|
-
: await routeThroughRelay(env, selection);
|
|
55
|
-
try {
|
|
56
|
-
return await spawnAgent(selection, directory, env, [
|
|
57
|
-
pinned?.args ?? [],
|
|
58
|
-
args,
|
|
59
|
-
]);
|
|
60
|
-
} finally {
|
|
61
|
-
pinned?.stop();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function spawnAgent(
|
|
66
|
-
selection: Selection,
|
|
67
|
-
directory: string,
|
|
68
|
-
env: NodeJS.ProcessEnv,
|
|
69
|
-
[pinned, args]: [string[], string[]]
|
|
70
|
-
): Promise<number> {
|
|
71
|
-
// Resolve the executable before launchArgs may point HOME at the profile.
|
|
72
|
-
const executable =
|
|
73
|
-
selection.tool === 'antigravity' && args[0] !== 'acp'
|
|
74
|
-
? pinnedBinary(selection.tool, env)
|
|
75
|
-
: selection.tool;
|
|
76
|
-
const command = [
|
|
77
|
-
executable,
|
|
78
|
-
...codexToolIsolation(selection.tool),
|
|
79
|
-
...pinned,
|
|
80
|
-
...launchArgs(selection, directory, args, env),
|
|
81
|
-
];
|
|
82
|
-
if (selection.tool === 'antigravity' && args[0] === 'acp')
|
|
83
|
-
return relayAcp(command, env);
|
|
84
|
-
const child = Bun.spawn(command, {
|
|
85
|
-
env,
|
|
86
|
-
stdin: 'inherit',
|
|
87
|
-
stdout: 'inherit',
|
|
88
|
-
stderr: 'inherit',
|
|
89
|
-
});
|
|
90
|
-
return child.exited;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Routes every request of this launch to one account's proxy credential.
|
|
94
|
-
* Claude and Codex send whichever model was picked, so they talk to a loopback
|
|
95
|
-
* relay that adds the account's model prefix. Antigravity names its model in
|
|
96
|
-
* the request path, which the relay prefixes the same way.
|
|
97
|
-
*/
|
|
98
|
-
export async function pinAccount(
|
|
99
|
-
env: NodeJS.ProcessEnv,
|
|
100
|
-
selection: Selection,
|
|
101
|
-
{ account, directory }: { account: string; directory: string },
|
|
102
|
-
{ relay = startAccountRelay, discover = discoverAccounts } = {}
|
|
103
|
-
): Promise<{ args: string[]; stop: () => void }> {
|
|
104
|
-
const prefix = accountPrefix(selection.tool, account);
|
|
105
|
-
// What the account serves right now, preferred default first.
|
|
106
|
-
const roster = await discover(env['CLIPROXY_API_KEY'] ?? '');
|
|
107
|
-
const served = roster.find(
|
|
108
|
-
(entry) => entry.tool === selection.tool && entry.email === account
|
|
109
|
-
);
|
|
110
|
-
// Named in this account's "cooling down" error, so the person can switch.
|
|
111
|
-
const alternatives = roster
|
|
112
|
-
.filter((entry) => entry.tool === selection.tool && entry.email !== account)
|
|
113
|
-
.map((entry) => entry.email);
|
|
114
|
-
if (!served)
|
|
115
|
-
throw new AgentConfigurationError(
|
|
116
|
-
'This account is not signed in on the CLI proxy.'
|
|
117
|
-
);
|
|
118
|
-
const { url, stop } = relay(registry.proxy.endpoint, prefix, {
|
|
119
|
-
alternatives,
|
|
120
|
-
});
|
|
121
|
-
if (selection.tool === 'antigravity') {
|
|
122
|
-
env['GOOGLE_GEMINI_BASE_URL'] = url;
|
|
123
|
-
return { args: [], stop };
|
|
124
|
-
}
|
|
125
|
-
if (selection.tool === 'claude') {
|
|
126
|
-
env['ANTHROPIC_BASE_URL'] = url;
|
|
127
|
-
// Aliases and the default must name models a Claude account serves.
|
|
128
|
-
const [opus, sonnet, haiku] = (
|
|
129
|
-
registry.proxy.accounts as Record<string, { models: string[] }>
|
|
130
|
-
)['claude']!.models;
|
|
131
|
-
env['ANTHROPIC_DEFAULT_OPUS_MODEL'] = opus;
|
|
132
|
-
env['ANTHROPIC_DEFAULT_SONNET_MODEL'] = sonnet;
|
|
133
|
-
env['ANTHROPIC_DEFAULT_HAIKU_MODEL'] = haiku;
|
|
134
|
-
env['ANTHROPIC_MODEL'] = sonnet;
|
|
135
|
-
return { args: [], stop };
|
|
136
|
-
}
|
|
137
|
-
// Each account keeps its own Codex sessions; the provider is declared on
|
|
138
|
-
// the command line because that home has no rendered config.
|
|
139
|
-
env['CODEX_HOME'] = join(directory, '..', `account-${accountSlug(account)}`);
|
|
140
|
-
mkdirSync(env['CODEX_HOME'], { recursive: true, mode: 0o700 });
|
|
141
|
-
const provider = {
|
|
142
|
-
name: 'Personal CLI Proxy',
|
|
143
|
-
base_url: `${url}/v1`,
|
|
144
|
-
env_key: 'CLIPROXY_API_KEY',
|
|
145
|
-
wire_api: 'responses',
|
|
146
|
-
requires_openai_auth: false,
|
|
147
|
-
supports_websockets: false,
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
args: [
|
|
151
|
-
['model', served.models[0]],
|
|
152
|
-
['model_provider', 'personal_proxy'],
|
|
153
|
-
...Object.entries(provider).map(
|
|
154
|
-
([key, value]) =>
|
|
155
|
-
[`model_providers.personal_proxy.${key}`, value] as const
|
|
156
|
-
),
|
|
157
|
-
].flatMap(([key, value]) => ['-c', `${key}=${JSON.stringify(value)}`]),
|
|
158
|
-
stop,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Which tools reach the proxy through an address this wrapper sets, and so
|
|
163
|
-
* can be sent through a relay. OpenCode and Grok read theirs from rendered
|
|
164
|
-
* configuration and still go to the proxy directly.
|
|
165
|
-
*/
|
|
166
|
-
const RELAYED = new Set(['claude', 'codex', 'gemini', 'antigravity']);
|
|
167
|
-
|
|
168
|
-
/** An unpinned launch goes through a relay as well: it retries a proxy that
|
|
169
|
-
* is restarting exactly as a pinned one does, reports "proxy unreachable"
|
|
170
|
-
* when it stays down, and picks each request's account by the fleet's
|
|
171
|
-
* selection policy when it declares one for the provider.
|
|
172
|
-
*/
|
|
173
|
-
export async function routeThroughRelay(
|
|
174
|
-
env: NodeJS.ProcessEnv,
|
|
175
|
-
selection: Selection,
|
|
176
|
-
{
|
|
177
|
-
relay = startAccountRelay,
|
|
178
|
-
discover = discoverAccounts,
|
|
179
|
-
policy = selectionPolicy,
|
|
180
|
-
} = {}
|
|
181
|
-
): Promise<{ args: string[]; stop: () => void } | null> {
|
|
182
|
-
if (!RELAYED.has(selection.tool)) return null;
|
|
183
|
-
const selector = await policySelector(env, selection, discover, policy);
|
|
184
|
-
const { url, stop } = relay(
|
|
185
|
-
registry.proxy.endpoint,
|
|
186
|
-
'',
|
|
187
|
-
selector ? { selector } : {}
|
|
188
|
-
);
|
|
189
|
-
if (selection.tool === 'claude') env['ANTHROPIC_BASE_URL'] = url;
|
|
190
|
-
if (selection.tool === 'gemini' || selection.tool === 'antigravity')
|
|
191
|
-
env['GOOGLE_GEMINI_BASE_URL'] = url;
|
|
192
|
-
const args =
|
|
193
|
-
selection.tool === 'codex'
|
|
194
|
-
? [
|
|
195
|
-
'-c',
|
|
196
|
-
`model_providers.personal_proxy.base_url=${JSON.stringify(`${url}/v1`)}`,
|
|
197
|
-
]
|
|
198
|
-
: [];
|
|
199
|
-
return { args, stop };
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** The fleet's selection policy for the tool's provider, over the accounts
|
|
203
|
-
* the proxy lists. The list is read only when a policy needs it; an
|
|
204
|
-
* unreadable list leaves the choice to the proxy's own pool.
|
|
205
|
-
*/
|
|
206
|
-
async function policySelector(
|
|
207
|
-
env: NodeJS.ProcessEnv,
|
|
208
|
-
selection: Selection,
|
|
209
|
-
discover: typeof discoverAccounts,
|
|
210
|
-
policy: (provider: string) => AccountSelection | undefined
|
|
211
|
-
): Promise<AccountSelector | undefined> {
|
|
212
|
-
const route = (
|
|
213
|
-
registry.proxy.accounts as Record<string, { provider: string }>
|
|
214
|
-
)[selection.tool];
|
|
215
|
-
const declared = route ? policy(route.provider) : undefined;
|
|
216
|
-
if (!declared) return undefined;
|
|
217
|
-
const accounts = await discover(env['CLIPROXY_API_KEY'] ?? '').catch(
|
|
218
|
-
() => []
|
|
219
|
-
);
|
|
220
|
-
const prefixes = accounts
|
|
221
|
-
.filter((account) => account.tool === selection.tool)
|
|
222
|
-
.map((account) => account.prefix);
|
|
223
|
-
return prefixes.length ? new AccountSelector(prefixes, declared) : undefined;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const selectionPolicy = (provider: string): AccountSelection | undefined =>
|
|
227
|
-
fleet.services.proxy.accounts?.selection?.[provider];
|
|
228
|
-
|
|
229
|
-
/** Per-tool profile selection and self-updater switches. */
|
|
230
|
-
function toolEnvironment(
|
|
231
|
-
env: NodeJS.ProcessEnv,
|
|
232
|
-
selection: Selection,
|
|
233
|
-
directory: string
|
|
234
|
-
): void {
|
|
235
|
-
if (selection.tool === 'claude') env['DISABLE_AUTOUPDATER'] = '1';
|
|
236
|
-
if (selection.tool === 'codex') env['CODEX_HOME'] = directory;
|
|
237
|
-
if (selection.tool === 'opencode')
|
|
238
|
-
env['OPENCODE_CONFIG'] = join(directory, 'opencode.json');
|
|
239
|
-
if (selection.tool === 'gemini') env['GEMINI_CLI_HOME'] = directory;
|
|
240
|
-
if (selection.tool === 'grok') {
|
|
241
|
-
env['GROK_HOME'] = directory;
|
|
242
|
-
env['GROK_DISABLE_AUTOUPDATER'] = '1';
|
|
243
|
-
}
|
|
244
|
-
// Only "true" disables Antigravity's in-place self-updater ("1" is ignored).
|
|
245
|
-
if (selection.tool === 'antigravity')
|
|
246
|
-
env['AGY_CLI_DISABLE_AUTO_UPDATE'] = 'true';
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** T3's managed policy may not carry a credential, so its Antigravity
|
|
250
|
-
* instance keeps the default Google sign-in method. The proxy key is the
|
|
251
|
-
* credential here: the one ACP `authenticate` request is switched to the
|
|
252
|
-
* Gemini API-key method on its way in; every other message passes unchanged.
|
|
253
|
-
*/
|
|
254
|
-
async function relayAcp(
|
|
255
|
-
command: string[],
|
|
256
|
-
env: NodeJS.ProcessEnv
|
|
257
|
-
): Promise<number> {
|
|
258
|
-
const child = Bun.spawn(command, {
|
|
259
|
-
env,
|
|
260
|
-
stdin: 'pipe',
|
|
261
|
-
stdout: 'inherit',
|
|
262
|
-
stderr: 'inherit',
|
|
263
|
-
});
|
|
264
|
-
void (async () => {
|
|
265
|
-
let pending = '';
|
|
266
|
-
for await (const chunk of process.stdin) {
|
|
267
|
-
pending += String(chunk);
|
|
268
|
-
let end = pending.indexOf('\n');
|
|
269
|
-
while (end >= 0) {
|
|
270
|
-
void child.stdin.write(
|
|
271
|
-
rewriteAuthenticate(pending.slice(0, end)) + '\n'
|
|
272
|
-
);
|
|
273
|
-
pending = pending.slice(end + 1);
|
|
274
|
-
end = pending.indexOf('\n');
|
|
275
|
-
}
|
|
276
|
-
void child.stdin.flush();
|
|
277
|
-
}
|
|
278
|
-
if (pending) void child.stdin.write(rewriteAuthenticate(pending));
|
|
279
|
-
void child.stdin.end();
|
|
280
|
-
})();
|
|
281
|
-
return child.exited;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const BROWSER_SIGN_IN = new Set(['oauth-personal', 'oauth-business']);
|
|
285
|
-
|
|
286
|
-
/** Rewrites only an ACP `authenticate` request for a browser sign-in method. */
|
|
287
|
-
export function rewriteAuthenticate(line: string): string {
|
|
288
|
-
if (!line.includes('"authenticate"')) return line;
|
|
289
|
-
try {
|
|
290
|
-
const message = JSON.parse(line) as {
|
|
291
|
-
method?: unknown;
|
|
292
|
-
params?: { methodId?: unknown };
|
|
293
|
-
};
|
|
294
|
-
if (
|
|
295
|
-
message.method !== 'authenticate' ||
|
|
296
|
-
!BROWSER_SIGN_IN.has(String(message.params?.methodId))
|
|
297
|
-
)
|
|
298
|
-
return line;
|
|
299
|
-
return JSON.stringify({
|
|
300
|
-
...message,
|
|
301
|
-
params: { ...message.params, methodId: 'gemini-api-key' },
|
|
302
|
-
});
|
|
303
|
-
} catch {
|
|
304
|
-
return line;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/** Tool-specific arguments that select the rendered profile. */
|
|
309
|
-
export function launchArgs(
|
|
310
|
-
selection: Selection,
|
|
311
|
-
directory: string,
|
|
312
|
-
args: string[],
|
|
313
|
-
env: NodeJS.ProcessEnv
|
|
314
|
-
): string[] {
|
|
315
|
-
if (selection.tool === 'claude')
|
|
316
|
-
return ['--settings', join(directory, 'settings.json'), ...args];
|
|
317
|
-
if (selection.tool === 'antigravity') {
|
|
318
|
-
// Over ACP (how T3 runs it) T3 owns a private GEMINI_HOME and selects the
|
|
319
|
-
// Gemini API key method; the proxy key and endpoint come from this wrapper.
|
|
320
|
-
// Run directly, the fleet profile is the home; one-shot print mode only
|
|
321
|
-
// reads ~/.gemini, so it also runs with HOME set to the profile.
|
|
322
|
-
if (args[0] === 'acp') {
|
|
323
|
-
env['GEMINI_HOME'] ??= join(directory, '.gemini');
|
|
324
|
-
return ['acp', '--disable-telemetry', ...args.slice(1)];
|
|
325
|
-
}
|
|
326
|
-
env['HOME'] = directory;
|
|
327
|
-
}
|
|
328
|
-
return args;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function configureGatewayEnvironment(
|
|
332
|
-
env: NodeJS.ProcessEnv,
|
|
333
|
-
selection: Selection
|
|
334
|
-
): void {
|
|
335
|
-
if (selection.tool === 'gemini' || selection.tool === 'antigravity') {
|
|
336
|
-
delete env['GOOGLE_GENAI_USE_VERTEXAI'];
|
|
337
|
-
delete env['GOOGLE_GENAI_USE_GCA'];
|
|
338
|
-
env['GOOGLE_GEMINI_BASE_URL'] = registry.proxy.endpoint;
|
|
339
|
-
env['GEMINI_API_KEY'] = env['CLIPROXY_API_KEY'];
|
|
340
|
-
}
|
|
341
|
-
if (selection.tool === 'claude') {
|
|
342
|
-
delete env['ANTHROPIC_API_KEY'];
|
|
343
|
-
env['ANTHROPIC_BASE_URL'] = registry.proxy.endpoint;
|
|
344
|
-
env['ANTHROPIC_AUTH_TOKEN'] = env['CLIPROXY_API_KEY'];
|
|
345
|
-
for (const family of ['OPUS', 'SONNET', 'HAIKU'])
|
|
346
|
-
env[`ANTHROPIC_DEFAULT_${family}_MODEL`] = selection.model;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/** Bash commands from a Linux Codex provider enter worker-wide admitted scopes.
|
|
351
|
-
* Install policy before enabling it; other platforms retain their native shell. */
|
|
352
|
-
export function codexToolIsolation(
|
|
353
|
-
tool: string,
|
|
354
|
-
platform: string = process.platform,
|
|
355
|
-
installed: (path: string) => boolean = existsSync
|
|
356
|
-
): string[] {
|
|
357
|
-
const hook = '/usr/local/lib/personal-fleet-agent-tool/agent-tool.bash';
|
|
358
|
-
return tool === 'codex' && platform === 'linux' && installed(hook)
|
|
359
|
-
? ['-c', `shell_environment_policy.set.BASH_ENV=${JSON.stringify(hook)}`]
|
|
360
|
-
: [];
|
|
361
|
-
}
|