labs-claude 0.11.0 → 0.12.1

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/bin/labs.js CHANGED
@@ -196,13 +196,14 @@ async function prepareLabsLaunch(config, args) {
196
196
  const effort = readEffortFlag(claudeArgs, config.defaultEffort || 'high');
197
197
 
198
198
  const CAPS = 'effort,xhigh_effort,max_effort,thinking,interleaved_thinking';
199
- // For Google Gemini / Gateway Gemini-4, present claude-opus-4-6; for Antigravity (agy), present the real agy model id
200
- // (like gemini-4-hydrogen) so Claude Code displays and routes the actual model name rather than Opus/Sonnet/Haiku.
199
+ // Present a native Claude Opus id for BOTH gateway Gemini-4 and Antigravity (agy) so Claude Code enables
200
+ // full thinking/effort/1M UX with zero unrecognized_model warnings (v1 acceptance style). X-Labs-Model in the
201
+ // custom header routes every call to the real target model (gemini-4-hydrogen for agy).
201
202
  const isOpusUx = onGemini || onGatewayGemini4;
202
203
  const launchArgs = [];
203
204
  for (let i = 0; i < claudeArgs.length; i += 1) {
204
- if (onAgy && claudeArgs[i] === '--model') { launchArgs.push('--model', agyId); i += 1; continue; }
205
- if (onAgy && claudeArgs[i].startsWith('--model=')) { launchArgs.push(`--model=${agyId}`); continue; }
205
+ if (onAgy && claudeArgs[i] === '--model') { launchArgs.push('--model', 'claude-opus-4-6'); i += 1; continue; }
206
+ if (onAgy && claudeArgs[i].startsWith('--model=')) { launchArgs.push('--model=claude-opus-4-6'); continue; }
206
207
  if (isOpusUx && claudeArgs[i] === '--model') { launchArgs.push('--model', 'claude-opus-4-6'); i += 1; continue; }
207
208
  if (isOpusUx && claudeArgs[i].startsWith('--model=')) { launchArgs.push('--model=claude-opus-4-6'); continue; }
208
209
  launchArgs.push(claudeArgs[i]);
@@ -217,16 +218,19 @@ async function prepareLabsLaunch(config, args) {
217
218
  ANTHROPIC_AUTH_TOKEN: loadProxyKey(LABS_DIR),
218
219
  ANTHROPIC_CUSTOM_HEADERS: withLabsHeaders(process.env.ANTHROPIC_CUSTOM_HEADERS, randomUUID(), modelName, effort, process.cwd()),
219
220
  ...(onAgy ? {
220
- ANTHROPIC_MODEL: agyId,
221
- ANTHROPIC_CUSTOM_MODEL_OPTION: agyId,
221
+ // v1 acceptance style: present native Claude ids (zero unrecognized_model warnings). The display name
222
+ // still shows "Gemini 4 Hydrogen (agy)" and X-Labs-Model routes every call to the real agy target.
223
+ ANTHROPIC_MODEL: 'claude-opus-4-6',
224
+ ANTHROPIC_CUSTOM_MODEL_OPTION: 'claude-opus-4-6',
222
225
  ANTHROPIC_CUSTOM_MODEL_OPTION_NAME: agyDisplayName,
223
226
  ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION: `Antigravity (agy) · ${Math.round(llmInfo.max_context_limit / 1000)}k context`,
224
- ANTHROPIC_DEFAULT_OPUS_MODEL: agyId,
225
- ANTHROPIC_DEFAULT_SONNET_MODEL: agyId,
226
- ANTHROPIC_DEFAULT_HAIKU_MODEL: 'gemini-3.8-flash',
227
+ ANTHROPIC_DEFAULT_OPUS_MODEL: 'claude-opus-4-6',
228
+ ANTHROPIC_DEFAULT_SONNET_MODEL: 'claude-sonnet-4-6',
229
+ ANTHROPIC_DEFAULT_HAIKU_MODEL: 'claude-haiku-4-5',
227
230
  ANTHROPIC_DEFAULT_OPUS_MODEL_SUPPORTED_CAPABILITIES: CAPS,
228
231
  ANTHROPIC_DEFAULT_SONNET_MODEL_SUPPORTED_CAPABILITIES: CAPS,
229
- ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES: CAPS
232
+ ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES: CAPS,
233
+ CLAUDE_CODE_MAX_OUTPUT_TOKENS: '262144'
230
234
  } : isOpusUx ? {
231
235
  // Present a native Claude Opus id so Claude Code enables full thinking/effort/1M UX with zero
232
236
  // unrecognized_model warnings; X-Labs-Model in the custom header routes every call to the target model.
@@ -239,7 +243,7 @@ async function prepareLabsLaunch(config, args) {
239
243
  ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES: CAPS
240
244
  } : {}),
241
245
  // Subagents run on the chosen model too; the proxy answers overload with 529 so Claude Code retries, never switches.
242
- CLAUDE_CODE_SUBAGENT_MODEL: onAgy ? agyId : isOpusUx ? 'claude-opus-4-6' : modelName
246
+ CLAUDE_CODE_SUBAGENT_MODEL: (onAgy || isOpusUx) ? 'claude-opus-4-6' : modelName
243
247
  };
244
248
  // A leftover key (e.g. from an Ollama setup) would take precedence over the proxy's auth token.
245
249
  delete env.ANTHROPIC_API_KEY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labs-claude",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "description": "Run the real Claude Code CLI on Qwen4 1M (Vision + Web), Gemini 4, Bedrock, or ElevenLabs — with colorful setup and admin token tracking.",
5
5
  "bin": {
6
6
  "labs": "bin/labs.js"
package/src/admin-cli.js CHANGED
@@ -1,15 +1,20 @@
1
1
  // Cracked-engineer terminal-native Admin Control Room (`labs admin`).
2
2
  // Zero browser needed: mint friend keys, pause/resume/revoke, and inspect live per-friend token bars in your terminal.
3
3
  const axios = require('axios');
4
+ const https = require('https');
4
5
  const fs = require('fs');
5
6
  const path = require('path');
6
- const { spawn } = require('child_process');
7
+ const { spawn, execFile } = require('child_process');
8
+ const { promisify } = require('util');
9
+ const execFileAsync = promisify(execFile);
7
10
  const { LABS_DIR } = require('./config');
8
11
  const { storedConfig } = require('./gateway-client');
9
12
  const { c, sparkline, randomQuip, playMascotIntro, withSpinner, printCard } = require('./ui');
10
13
  const { version } = require('../package.json');
11
14
 
12
15
  const DEFAULT_GATEWAY_URL = 'https://labs.instant.uz';
16
+ const DEFAULT_BOX_INSTANCE = 'i-024bdf750d64da0f8';
17
+ const DEFAULT_BOX_REGION = 'us-east-2';
13
18
  const ADMIN_TOKEN_FILE = path.join(LABS_DIR, 'gateway-admin');
14
19
 
15
20
  function compactTokens(n) {
@@ -56,10 +61,30 @@ function readAdminToken() {
56
61
  }
57
62
 
58
63
  function createAdminApi(url, token) {
59
- const headers = { authorization: `Bearer ${token}` };
64
+ const httpsAgent = new https.Agent({ keepAlive: true, maxSockets: 2, family: 4 });
65
+ const client = axios.create({
66
+ baseURL: `${url}/admin/api`,
67
+ headers: { authorization: `Bearer ${token}` },
68
+ timeout: 8000,
69
+ httpsAgent,
70
+ });
71
+ async function callWithRetry(fn, retries = 2) {
72
+ let lastErr;
73
+ for (let i = 0; i <= retries; i += 1) {
74
+ try {
75
+ return (await fn()).data;
76
+ } catch (err) {
77
+ lastErr = err;
78
+ const status = err?.response?.status;
79
+ if (status && status < 500) throw err;
80
+ if (i < retries) await new Promise(r => setTimeout(r, 400 * (i + 1)));
81
+ }
82
+ }
83
+ throw lastErr;
84
+ }
60
85
  return {
61
- get: p => axios.get(`${url}/admin/api${p}`, { headers, timeout: 10000 }).then(r => r.data),
62
- post: (p, body) => axios.post(`${url}/admin/api${p}`, body, { headers, timeout: 10000 }).then(r => r.data),
86
+ get: p => callWithRetry(() => client.get(p)),
87
+ post: (p, body) => callWithRetry(() => client.post(p, body)),
63
88
  };
64
89
  }
65
90
 
@@ -69,7 +94,20 @@ function resolveKeyTarget(keys, target) {
69
94
  return keys.find(k => String(k.id) === raw || k.name.toLowerCase() === raw.toLowerCase()) || null;
70
95
  }
71
96
 
72
- function renderDashboard(keys, usageRows, box) {
97
+ function formatBoxStatus(box, ec2State) {
98
+ const st = ec2State ? String(ec2State).toLowerCase() : null;
99
+ if (st === 'stopped') return c.rose('SLEEPING ($0/hr)');
100
+ if (st === 'stopping' || st === 'shutting-down') return c.amber('STOPPING...');
101
+ if (st === 'pending') return c.amber('BOOTING (ec2 pending)');
102
+ if (st === 'running' && !box?.up) return c.amber('BOOTING (loading Qwen4...)');
103
+ if (box?.up) {
104
+ const models = (box.models || []).join(', ');
105
+ return `${c.mint('ONLINE')}${models ? ` ${c.dim(`(${models})`)}` : ''}`;
106
+ }
107
+ return c.rose('SLEEPING');
108
+ }
109
+
110
+ function renderDashboard(keys, usageRows, box, ec2State = null) {
73
111
  const todayStr = new Date(Date.now() + 5 * 3600e3).toISOString().slice(0, 10);
74
112
  const todayRows = usageRows.filter(r => r.day === todayStr);
75
113
  const todayIn = todayRows.reduce((s, r) => s + r.input, 0);
@@ -91,9 +129,7 @@ function renderDashboard(keys, usageRows, box) {
91
129
  last7.push(byDay[d] || 0);
92
130
  }
93
131
 
94
- const boxPill = box.up
95
- ? `${c.mint('ONLINE')} ${c.dim(`(${box.models.join(', ')})`)}`
96
- : `${c.rose('SLEEPING')}`;
132
+ const boxPill = formatBoxStatus(box, ec2State);
97
133
 
98
134
  printCard('LABS ADMIN CONTROL ROOM', [
99
135
  `${c.dim('gpu box:')} ${boxPill} ${c.dim('7d trend:')} ${sparkline(last7)}`,
@@ -169,6 +205,129 @@ async function changeStatus(api, keys, target, status) {
169
205
  console.log(` ${c.mint('✔')} Key ${c.bold(found.name)} is now ${status === 'active' ? c.mint('active') : c.amber(status)}.\n`);
170
206
  }
171
207
 
208
+ function awsBoxArgs(cfg) {
209
+ return {
210
+ instanceId: cfg.boxInstanceId || process.env.LABS_BOX_INSTANCE || DEFAULT_BOX_INSTANCE,
211
+ region: cfg.boxRegion || process.env.LABS_BOX_REGION || DEFAULT_BOX_REGION,
212
+ };
213
+ }
214
+
215
+ async function runAws(args, timeout = 15000) {
216
+ try {
217
+ const { stdout } = await execFileAsync('aws', args, { encoding: 'utf8', timeout, windowsHide: true });
218
+ return (stdout || '').trim();
219
+ } catch (err) {
220
+ const msg = (err.stderr || err.stdout || err.message || 'aws command failed').trim();
221
+ throw new Error(msg);
222
+ }
223
+ }
224
+
225
+ async function getEc2State(cfg, runAwsFn = runAws) {
226
+ const { instanceId, region } = awsBoxArgs(cfg);
227
+ try {
228
+ const out = await runAwsFn([
229
+ 'ec2', 'describe-instances',
230
+ '--region', region,
231
+ '--instance-ids', instanceId,
232
+ '--query', 'Reservations[0].Instances[0].State.Name',
233
+ '--output', 'text',
234
+ ], 6000);
235
+ return out && out !== 'None' ? out.trim().toLowerCase() : null;
236
+ } catch {
237
+ return null;
238
+ }
239
+ }
240
+
241
+ function fmtElapsed(ms) {
242
+ const elapsed = Math.max(0, Math.floor(ms / 1000));
243
+ const mm = String(Math.floor(elapsed / 60)).padStart(2, '0');
244
+ const ss = String(elapsed % 60).padStart(2, '0');
245
+ return `${mm}:${ss}`;
246
+ }
247
+
248
+ async function wakeGpuBox(api, cfg, deps = {}) {
249
+ const runAwsFn = deps.runAws || runAws;
250
+ const sleepFn = deps.sleep || (ms => new Promise(r => setTimeout(r, ms)));
251
+ const pollMs = deps.pollMs ?? 5000;
252
+ const maxMs = deps.maxMs ?? (6 * 60 * 1000);
253
+ const { instanceId, region } = awsBoxArgs(cfg);
254
+
255
+ const preState = await getEc2State(cfg, runAwsFn);
256
+ if (preState === 'running') {
257
+ try {
258
+ const box = await api.get('/box');
259
+ if (box?.up) {
260
+ console.log(` ${c.mint('● ONLINE')} ${c.bold(instanceId)} is already up — ${c.cyan((box.models || []).join(', '))}\n`);
261
+ return true;
262
+ }
263
+ } catch { /* still booting */ }
264
+ }
265
+
266
+ await withSpinner(`Starting GPU box ${c.cyan(instanceId)} (${region})...`, async () => {
267
+ await runAwsFn(['ec2', 'start-instances', '--region', region, '--instance-ids', instanceId]);
268
+ });
269
+ console.log(` ${c.mint('✔')} EC2 start sent. Waiting for Qwen4-35B-A3B 1M + DFlash2 auto-boot (~3–4 min)...`);
270
+ const t0 = Date.now();
271
+ while (Date.now() - t0 < maxMs) {
272
+ const elapsedStr = fmtElapsed(Date.now() - t0);
273
+ const ec2State = await getEc2State(cfg, runAwsFn);
274
+ try {
275
+ const box = await api.get('/box');
276
+ if (box?.up && (!ec2State || ec2State === 'running')) {
277
+ process.stdout.write(`\r ${c.mint('● ONLINE')} in ${c.bold(elapsedStr)} — ${c.cyan((box.models || []).join(', '))}${' '.repeat(24)}\n\n`);
278
+ return true;
279
+ }
280
+ } catch { /* gateway still waiting on tunnel */ }
281
+ if (process.stdout.isTTY) {
282
+ const phase = ec2State === 'pending'
283
+ ? 'EC2 booting (pending)...'
284
+ : 'loading Qwen4 weights & warming CUDA graphs...';
285
+ process.stdout.write(`\r ${c.cyan('⏳')} ${elapsedStr} · ${phase}${' '.repeat(12)}`);
286
+ }
287
+ await sleepFn(pollMs);
288
+ }
289
+ console.log(`\n ${c.amber('!')} Still booting after 6m — check ${c.cyan('labs admin stats')} in a minute.\n`);
290
+ return false;
291
+ }
292
+
293
+ async function sleepGpuBox(api, cfg, ask, deps = {}) {
294
+ const runAwsFn = deps.runAws || runAws;
295
+ const sleepFn = deps.sleep || (ms => new Promise(r => setTimeout(r, ms)));
296
+ const pollMs = deps.pollMs ?? 3000;
297
+ const maxMs = deps.maxMs ?? (3 * 60 * 1000);
298
+ const { instanceId, region } = awsBoxArgs(cfg);
299
+
300
+ const preState = await getEc2State(cfg, runAwsFn);
301
+ if (preState === 'stopped') {
302
+ console.log(` ${c.mint('✔')} ${c.bold(instanceId)} is already ${c.rose('STOPPED')} ($0/hr compute).\n`);
303
+ return true;
304
+ }
305
+
306
+ const confirm = (await ask(` ${c.amber('!')} Stop GPU box ${c.bold(instanceId)} (${region}) to stop hourly billing? Type YES: `)).trim();
307
+ if (confirm !== 'YES') {
308
+ console.log(` ${c.dim('Cancelled.')}\n`);
309
+ return false;
310
+ }
311
+ await withSpinner(`Sending stop signal to ${c.cyan(instanceId)}...`, async () => {
312
+ await runAwsFn(['ec2', 'stop-instances', '--region', region, '--instance-ids', instanceId]);
313
+ });
314
+ const t0 = Date.now();
315
+ while (Date.now() - t0 < maxMs) {
316
+ const elapsedStr = fmtElapsed(Date.now() - t0);
317
+ const ec2State = await getEc2State(cfg, runAwsFn);
318
+ if (ec2State === 'stopped') {
319
+ process.stdout.write(`\r ${c.rose('● STOPPED')} in ${c.bold(elapsedStr)} — ${c.bold(instanceId)} is at $0/hr compute. Wake anytime with ${c.cyan('labs admin wake')}.${' '.repeat(10)}\n\n`);
320
+ return true;
321
+ }
322
+ if (process.stdout.isTTY) {
323
+ process.stdout.write(`\r ${c.amber('⏳')} ${elapsedStr} · EC2 state: ${ec2State || 'stopping'} (waiting for full shutdown)...`);
324
+ }
325
+ await sleepFn(pollMs);
326
+ }
327
+ console.log(`\n ${c.amber('!')} Stop signal was accepted, still shutting down after 3m — press ${c.cyan('6')} to refresh.\n`);
328
+ return true;
329
+ }
330
+
172
331
  async function runAdminCli(args, ask) {
173
332
  const cfg = storedConfig();
174
333
  const url = (cfg.gatewayUrl || DEFAULT_GATEWAY_URL).replace(/\/+$/, '');
@@ -179,7 +338,10 @@ async function runAdminCli(args, ask) {
179
338
  if (sub === 'help' || sub === '--help') {
180
339
  printCard('LABS ADMIN COMMANDS', [
181
340
  `${c.cyan('labs admin')} ${c.dim('Interactive terminal control room')}`,
341
+ `${c.cyan('labs admin wake')} ${c.dim('Start GPU box + wait until Qwen4 1M is ONLINE (~3-4m)')}`,
342
+ `${c.cyan('labs admin sleep')} ${c.dim('Stop GPU box immediately ($0/hr compute)')}`,
182
343
  `${c.cyan('labs admin stats')} ${c.dim('Live box status + per-friend token leaderboard')}`,
344
+ `${c.cyan('labs admin watch')} ${c.dim('Live 3s auto-refreshing btop-style monitor')}`,
183
345
  `${c.cyan('labs admin create <name>')} ${c.dim('Mint new lk_... key + auto-copy friend 1-liner')}`,
184
346
  `${c.cyan('labs admin pause <name>')} ${c.dim('Pause a friend key immediately')}`,
185
347
  `${c.cyan('labs admin resume <name>')} ${c.dim('Re-enable a paused friend key')}`,
@@ -189,16 +351,32 @@ async function runAdminCli(args, ask) {
189
351
  return;
190
352
  }
191
353
 
354
+ if (sub === 'wake' || sub === 'on' || sub === 'start') {
355
+ await playMascotIntro(version, 'Admin · GPU Box Wake');
356
+ await wakeGpuBox(api, cfg);
357
+ return;
358
+ }
359
+ if (sub === 'sleep' || sub === 'off' || sub === 'stop') {
360
+ await playMascotIntro(version, 'Admin · GPU Box Sleep');
361
+ await sleepGpuBox(api, cfg, ask);
362
+ return;
363
+ }
364
+
192
365
  await playMascotIntro(version, `Admin Control Room · ${url}`);
193
366
 
194
367
  const loadAll = async (days = 14) => withSpinner(randomQuip(), async () => {
195
- const [k, u, b] = await Promise.all([api.get('/keys'), api.get(`/usage?days=${days}`), api.get('/box')]);
196
- return { keys: k.keys || [], rows: u.rows || [], box: b || { up: false, models: [] } };
368
+ const [k, u, b, ec2State] = await Promise.all([
369
+ api.get('/keys'),
370
+ api.get(`/usage?days=${days}`),
371
+ api.get('/box').catch(() => ({ up: false, models: [] })),
372
+ getEc2State(cfg),
373
+ ]);
374
+ return { keys: k.keys || [], rows: u.rows || [], box: b || { up: false, models: [] }, ec2State };
197
375
  });
198
376
 
199
377
  if (sub === 'stats' || sub === 'ls' || sub === 'list') {
200
- const { keys, rows, box } = await loadAll(14);
201
- renderDashboard(keys, rows, box);
378
+ const { keys, rows, box, ec2State } = await loadAll(14);
379
+ renderDashboard(keys, rows, box, ec2State);
202
380
  return;
203
381
  }
204
382
  if (sub === 'usage') {
@@ -223,13 +401,18 @@ async function runAdminCli(args, ask) {
223
401
 
224
402
  if (sub === 'watch' || sub === 'live') {
225
403
  const fetchState = async () => {
226
- const [k, u, b] = await Promise.all([api.get('/keys'), api.get('/usage?days=14'), api.get('/box')]);
227
- return { keys: k.keys || [], rows: u.rows || [], box: b || { up: false, models: [] } };
404
+ const [k, u, b, ec2State] = await Promise.all([
405
+ api.get('/keys'),
406
+ api.get('/usage?days=14'),
407
+ api.get('/box'),
408
+ getEc2State(cfg),
409
+ ]);
410
+ return { keys: k.keys || [], rows: u.rows || [], box: b || { up: false, models: [] }, ec2State };
228
411
  };
229
412
  const renderLive = async () => {
230
413
  const st = await fetchState();
231
414
  process.stdout.write('\x1b[2J\x1b[H');
232
- renderDashboard(st.keys, st.rows, st.box);
415
+ renderDashboard(st.keys, st.rows, st.box, st.ec2State);
233
416
  console.log(` ${c.dim('live watch mode (refreshing every 3s) · press Ctrl+C to exit')}\n`);
234
417
  };
235
418
  await renderLive();
@@ -241,16 +424,26 @@ async function runAdminCli(args, ask) {
241
424
  // Interactive menu loop
242
425
  let state = await loadAll(14);
243
426
  while (true) {
244
- renderDashboard(state.keys, state.rows, state.box);
427
+ renderDashboard(state.keys, state.rows, state.box, state.ec2State);
245
428
  console.log(` ${c.bold('actions:')}`);
246
- console.log(` ${c.cyan('1.')} mint new friend api key ${c.cyan('4.')} revoke (delete) a key`);
247
- console.log(` ${c.cyan('2.')} pause a key ${c.cyan('5.')} daily token table (14d)`);
429
+ console.log(` ${c.cyan('1.')} mint new friend api key ${c.cyan('4.')} revoke (delete) a key ${c.mint('7.')} wake gpu box (on)`);
430
+ console.log(` ${c.cyan('2.')} pause a key ${c.cyan('5.')} daily token table (14d) ${c.rose('8.')} stop gpu box (off)`);
248
431
  console.log(` ${c.cyan('3.')} resume a key ${c.cyan('6.')} refresh stats ${c.cyan('w.')} live watch (3s) ${c.dim('q. quit')}\n`);
249
432
  const choice = (await ask(` ${c.violet('admin>')} `)).trim().toLowerCase();
250
433
  if (!choice || choice === 'q' || choice === 'quit' || choice === 'exit') break;
251
434
  if (choice === 'w') {
252
435
  return runAdminCli(['watch'], ask);
253
436
  }
437
+ if (choice === '7') {
438
+ await wakeGpuBox(api, cfg);
439
+ state = await loadAll(14);
440
+ continue;
441
+ }
442
+ if (choice === '8') {
443
+ await sleepGpuBox(api, cfg, ask);
444
+ state = await loadAll(14);
445
+ continue;
446
+ }
254
447
  if (choice === '1') {
255
448
  const name = (await ask(` ${c.cyan('?')} Friend name: `)).trim();
256
449
  if (name) {
@@ -282,4 +475,4 @@ async function runAdminCli(args, ask) {
282
475
  }
283
476
  }
284
477
 
285
- module.exports = { compactTokens, barChart, resolveKeyTarget, runAdminCli };
478
+ module.exports = { compactTokens, barChart, resolveKeyTarget, formatBoxStatus, getEc2State, sleepGpuBox, wakeGpuBox, runAdminCli };