labs-claude 0.6.0 → 0.7.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
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const axios = require('axios');
3
3
  const { spawn } = require('child_process');
4
4
  const { randomUUID } = require('crypto');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labs-claude",
3
- "version": "0.6.0",
3
+ "version": "0.7.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/dash.js CHANGED
@@ -1,16 +1,17 @@
1
- // Apple-clean Personal Command Center (`labs dash`):
2
- // Zero commands to memorize — see your live token stats, 7-day sparkline, switch effort/theme,
3
- // connect Playwright Chrome MCP, Brave Search, cute statusline, or jump straight into Claude Code.
1
+ // Apple-minimal centered Command Center (`labs dash`):
2
+ // Clean, calm, horizontally centered, zero mental load.
3
+ // Press Enter to code, [s] for settings (effort, theme, chrome, brave, statusline, key), [u] update, [a] admin (owner only).
4
4
  const axios = require('axios');
5
5
  const fs = require('fs');
6
6
  const os = require('os');
7
7
  const path = require('path');
8
- const { saveConfig } = require('./config');
8
+ const { LABS_DIR, saveConfig } = require('./config');
9
9
  const { storedConfig, saveGatewayKey } = require('./gateway-client');
10
- const { c, THEMES, activeTheme, sparkline, randomQuip, playMascotIntro, askMasked, withSpinner, printCard, runSelfUpdate } = require('./ui');
10
+ const { c, THEMES, activeTheme, gradient, visibleWidth, sparkline, randomQuip, askMasked, runSelfUpdate } = require('./ui');
11
11
  const { version } = require('../package.json');
12
12
 
13
13
  const DEFAULT_GATEWAY_URL = 'https://labs.instant.uz';
14
+ const IS_ADMIN = () => fs.existsSync(path.join(LABS_DIR, 'gateway-admin'));
14
15
 
15
16
  function compact(n) {
16
17
  const v = Number(n || 0);
@@ -40,108 +41,182 @@ function hasStatusline() {
40
41
 
41
42
  async function fetchMe(url, key) {
42
43
  try {
43
- const { data } = await axios.get(`${url}/v1/me`, { headers: { 'x-api-key': key }, timeout: 5000 });
44
+ const { data } = await axios.get(`${url}/v1/me`, { headers: { 'x-api-key': key }, timeout: 4000 });
44
45
  return data;
45
46
  } catch {
46
47
  return null;
47
48
  }
48
49
  }
49
50
 
50
- async function runDash(ask, askHidden, launchNow) {
51
- await playMascotIntro(version, 'personal command center · qwen4 1m');
51
+ function centerLine(text, cols) {
52
+ const w = visibleWidth(text);
53
+ const pad = Math.max(2, Math.floor((cols - w) / 2));
54
+ return ' '.repeat(pad) + text;
55
+ }
56
+
57
+ function renderCenteredCard(rows, cols, cardWidth = 58) {
58
+ const w = Math.min(cardWidth, Math.max(46, cols - 6));
59
+ const padLeft = ' '.repeat(Math.max(2, Math.floor((cols - (w + 2)) / 2)));
60
+ const out = [
61
+ `${padLeft}${c.dim('╭' + '─'.repeat(w) + '╮')}`,
62
+ ];
63
+ for (const row of rows) {
64
+ if (row === '---') {
65
+ out.push(`${padLeft}${c.dim('├' + '─'.repeat(w) + '┤')}`);
66
+ continue;
67
+ }
68
+ const rw = visibleWidth(row);
69
+ const rightPad = Math.max(0, w - rw - 4);
70
+ out.push(`${padLeft}${c.dim('│')} ${row}${' '.repeat(rightPad)} ${c.dim('│')}`);
71
+ }
72
+ out.push(`${padLeft}${c.dim('╰' + '─'.repeat(w) + '╯')}`);
73
+ return out.join('\n');
74
+ }
75
+
76
+ function renderHero(me, theme, cols) {
77
+ const logo1 = gradient('█░░ ▄▀█ █▄▄ █▀', theme.from, theme.to);
78
+ const logo2 = gradient('█▄▄ █▀█ █▄█ ▄█', theme.to, theme.from);
79
+ const name = me?.name ? `hey ${me.name}` : 'welcome to labs';
80
+ const boxDot = me ? (me.box_up ? c.mint('● online') : c.rose('● sleeping')) : c.dim('● offline');
81
+ const lines = [
82
+ '',
83
+ '',
84
+ centerLine(`${logo1} ${c.dim(`v${version}`)}`, cols),
85
+ centerLine(logo2, cols),
86
+ '',
87
+ centerLine(`${c.bold(c.white(name))} ${c.dim('·')} ${c.cyan('Qwen4-35B-A3B 1M')} ${c.dim('·')} ${boxDot}`, cols),
88
+ centerLine(c.dim(randomQuip()), cols),
89
+ '',
90
+ ];
91
+ return lines.join('\n');
92
+ }
93
+
94
+ async function runSettings(ask, askHidden) {
95
+ while (true) {
96
+ const cols = process.stdout.columns || 90;
97
+ const cfg = storedConfig();
98
+ const theme = activeTheme();
99
+ const chrome = hasChromeMcp() ? c.mint('on') : c.dim('off');
100
+ const brave = (cfg.braveKey || process.env.LABS_BRAVE_KEYS || process.env.LABS_BRAVE_KEY) ? c.mint('on') : c.dim('off');
101
+ const bar = hasStatusline() ? c.mint('on') : c.dim('off');
102
+
103
+ if (process.stdout.isTTY) process.stdout.write('\x1b[2J\x1b[H');
104
+ console.log('\n' + centerLine(c.bold(c.white('settings')), cols) + '\n');
105
+ console.log(renderCenteredCard([
106
+ `${c.cyan('1')} effort ${c.white(cfg.defaultEffort || 'high')} ${c.dim('(low / high / xhigh)')}`,
107
+ `${c.cyan('2')} theme ${c.violet(theme.name)} ${c.dim('(ocean / sunset / cyber / emerald / mono)')}`,
108
+ `${c.cyan('3')} chrome mcp ${chrome} ${c.dim('(real browser control)')}`,
109
+ `${c.cyan('4')} brave key ${brave} ${c.dim('(free 2k searches/mo)')}`,
110
+ `${c.cyan('5')} statusline ${bar} ${c.dim('(model · repo · git · ctx%)')}`,
111
+ `${c.cyan('6')} api key ${cfg.gatewayKey ? c.mint('saved') : c.rose('missing')} ${c.dim('(update or rotate)')}`,
112
+ '---',
113
+ `${c.dim('enter / b back to dash')}`,
114
+ ], cols, 60));
115
+
116
+ const pick = (await ask('\n' + centerLine(c.dim('choose: '), cols))).trim().toLowerCase();
117
+ if (!pick || pick === 'b' || pick === 'q') return;
118
+
119
+ if (pick === '1') {
120
+ const e = (await ask(centerLine(c.dim('effort [1=high, 2=xhigh, 3=low]: '), cols))).trim();
121
+ const next = e === '2' ? 'xhigh' : e === '3' ? 'low' : 'high';
122
+ saveConfig({ ...cfg, defaultEffort: next });
123
+ } else if (pick === '2') {
124
+ const names = Object.keys(THEMES);
125
+ if (process.stdout.isTTY) process.stdout.write('\x1b[2J\x1b[H');
126
+ console.log('\n' + centerLine(c.bold(c.white('pick a theme')), cols) + '\n');
127
+ const previewRows = names.map((n, i) => {
128
+ const th = THEMES[n];
129
+ const swatch = gradient('████████████', th.from, th.to);
130
+ const sample = gradient('LABS', th.from, th.to);
131
+ const active = n === theme.name ? c.mint(' ●') : ' ';
132
+ return `${c.cyan(String(i + 1))} ${c.bold(n.padEnd(8))} ${swatch} ${sample}${active}`;
133
+ });
134
+ previewRows.push('---', `${c.dim('enter number 1-5 to apply')}`);
135
+ console.log(renderCenteredCard(previewRows, cols, 52));
136
+ const t = Number(await ask('\n' + centerLine(c.dim('theme [1-5]: '), cols)));
137
+ if (t >= 1 && t <= names.length) {
138
+ saveConfig({ ...cfg, theme: names[t - 1] });
139
+ }
140
+ } else if (pick === '3') {
141
+ const { EXTENSION_URL, installBrowserServer } = require('./browser-setup');
142
+ console.log('\n' + centerLine(c.dim('extension: ') + c.cyan(EXTENSION_URL), cols));
143
+ const tok = (await askMasked(centerLine(c.dim('token (or enter to skip): '), cols))).replace(/^PLAYWRIGHT_MCP_EXTENSION_TOKEN=/, '');
144
+ try { installBrowserServer(tok); } catch { /* ignore */ }
145
+ } else if (pick === '4') {
146
+ console.log('\n' + centerLine(c.dim('free key: ') + c.cyan('https://api.search.brave.com/'), cols));
147
+ const bk = await askMasked(centerLine(c.dim('brave api key: '), cols));
148
+ if (bk) saveConfig({ ...storedConfig(), braveKey: bk });
149
+ } else if (pick === '5') {
150
+ try { require('./statusline').installStatusline(); } catch { /* ignore */ }
151
+ } else if (pick === '6') {
152
+ console.log('\n' + centerLine(c.dim('paste new lk_ key (or press Enter / Esc to go back)'), cols));
153
+ const newKey = await askMasked(centerLine(c.amber('key: '), cols));
154
+ if (newKey && /^lk_[A-Za-z0-9_-]{20,}$/.test(newKey)) {
155
+ saveConfig({ ...storedConfig(), gatewayKey: newKey });
156
+ }
157
+ }
158
+ }
159
+ }
52
160
 
161
+ async function runDash(ask, askHidden, launchNow) {
53
162
  while (true) {
163
+ const cols = process.stdout.columns || 90;
54
164
  const cfg = storedConfig();
55
165
  const url = (cfg.gatewayUrl || DEFAULT_GATEWAY_URL).replace(/\/+$/, '');
56
166
  const theme = activeTheme();
57
- const me = cfg.gatewayKey
58
- ? await withSpinner(randomQuip(), () => fetchMe(url, cfg.gatewayKey))
59
- : null;
60
-
61
- const keyBadge = cfg.gatewayKey
62
- ? c.mint(`connected (${cfg.gatewayKey.slice(0, 7)}…${cfg.gatewayKey.slice(-4)})`)
63
- : c.rose('not set');
64
- const boxBadge = me ? (me.box_up ? c.mint('ONLINE') : c.rose('SLEEPING')) : c.dim('unknown');
65
- const chromeBadge = hasChromeMcp() ? c.mint('✔ on') : c.dim('○ off');
66
- const braveBadge = (cfg.braveKey || process.env.LABS_BRAVE_KEYS || process.env.LABS_BRAVE_KEY) ? c.mint('✔ on') : c.dim('○ free key');
67
- const statusBadge = hasStatusline() ? c.mint('✔ on') : c.dim('○ off');
68
-
69
- const rows = [
70
- `${c.dim('user:')} ${c.bold(c.white(me?.name || 'guest'))} ${c.dim('key:')} ${keyBadge}`,
71
- `${c.dim('engine:')} ${c.cyan('Qwen4-35B-A3B')} ${c.dim('(1m · vision)')} ${c.dim('box:')} ${boxBadge}`,
72
- ];
167
+ const me = cfg.gatewayKey ? await fetchMe(url, cfg.gatewayKey) : null;
168
+
169
+ if (process.stdout.isTTY) process.stdout.write('\x1b[2J\x1b[H');
170
+ console.log(renderHero(me, theme, cols));
171
+
172
+ const chromeDot = hasChromeMcp() ? c.mint('chrome on') : c.dim('chrome off');
173
+ const braveDot = (cfg.braveKey || process.env.LABS_BRAVE_KEYS || process.env.LABS_BRAVE_KEY) ? c.mint('brave on') : c.dim('brave off');
174
+ const barDot = hasStatusline() ? c.mint('bar on') : c.dim('bar off');
175
+
176
+ const cardRows = [];
73
177
  if (me) {
74
- rows.push(
75
- `${c.dim('today:')} ${c.bold(c.mint(compact(me.today_tokens)))} tok ${c.dim('all-time:')} ${c.white(compact(me.total_tokens))} ${c.dim('cache:')} ${c.violet(`${me.cache_hit_pct}%`)}`,
76
- `${c.dim('7d trend:')} ${sparkline(me.last_7_days)} ${c.dim('calls today:')} ${c.cyan(String(me.today_calls))}`
178
+ cardRows.push(
179
+ `${c.bold(c.mint(compact(me.today_tokens)))} ${c.dim('today')} ${c.bold(c.white(compact(me.total_tokens)))} ${c.dim('total')} ${c.cyan(String(me.today_calls))} ${c.dim('calls')}`,
180
+ `${c.dim('7d')} ${sparkline(me.last_7_days)} ${c.dim('cache hit')} ${c.violet(`${me.cache_hit_pct}%`)}`,
181
+ '---'
182
+ );
183
+ } else if (!cfg.gatewayKey) {
184
+ cardRows.push(
185
+ `${c.amber('no api key yet')} ${c.dim('— press s to connect your lk_ key')}`,
186
+ '---'
77
187
  );
78
188
  }
79
- rows.push(
80
- `${c.dim('settings:')} effort ${c.cyan(cfg.defaultEffort || 'high')} · theme ${c.violet(theme.name)}`,
81
- `${c.dim('addons:')} chrome ${chromeBadge} · brave ${braveBadge} · statusline ${statusBadge}`
189
+ cardRows.push(
190
+ `${c.dim('effort')} ${c.cyan(cfg.defaultEffort || 'high')} ${c.dim('·')} ${c.dim('theme')} ${c.violet(theme.name)}`,
191
+ `${chromeDot} ${c.dim('·')} ${braveDot} ${c.dim('·')} ${barDot}`
82
192
  );
83
193
 
84
- printCard('LABS DASH', rows);
85
- console.log(` ${c.bold('what do you want to do?')}`);
86
- console.log(` ${c.cyan('1.')} start coding now (qwen4 1m) ${c.cyan('5.')} cute claude code statusline`);
87
- console.log(` ${c.cyan('2.')} change effort (low/high/xhigh) ${c.cyan('6.')} connect chrome mcp / brave key`);
88
- console.log(` ${c.cyan('3.')} change terminal theme color ${c.cyan('7.')} update / rotate api key`);
89
- console.log(` ${c.cyan('4.')} check & install labs update ${c.dim('q. quit')}\n`);
194
+ console.log(renderCenteredCard(cardRows, cols, 58));
90
195
 
91
- const pick = (await ask(` ${c.violet('labs>')} `)).trim().toLowerCase();
92
- if (!pick || pick === 'q' || pick === 'quit' || pick === 'exit') return;
196
+ const actions = [
197
+ `${c.mint('[enter]')} ${c.bold('code')}`,
198
+ `${c.cyan('[s]')} settings`,
199
+ `${c.cyan('[u]')} update`,
200
+ ...(IS_ADMIN() ? [`${c.violet('[a]')} admin`] : []),
201
+ `${c.dim('[q] quit')}`,
202
+ ].join(' ');
203
+ console.log('\n' + centerLine(actions, cols) + '\n');
93
204
 
94
- if (pick === '1') {
205
+ const pick = (await ask(centerLine(c.violet('› '), cols))).trim().toLowerCase();
206
+ if (pick === 'q' || pick === 'quit' || pick === 'exit') return;
207
+ if (pick === '' || pick === '1' || pick === 'code') {
95
208
  if (!cfg.gatewayKey) {
96
209
  await saveGatewayKey(askHidden, ask, undefined, true);
97
210
  }
98
211
  return launchNow();
99
212
  }
100
- if (pick === '2') {
101
- console.log(`\n ${c.cyan('1.')} high ${c.dim('(default)')} ${c.cyan('2.')} xhigh ${c.dim('(max)')} ${c.cyan('3.')} low ${c.dim('(fastest)')}`);
102
- const e = (await ask(' effort [1]: ')).trim();
103
- const next = e === '2' ? 'xhigh' : e === '3' ? 'low' : 'high';
104
- saveConfig({ ...cfg, defaultEffort: next });
105
- console.log(` ${c.mint('✔')} default effort set to ${c.cyan(next)}.\n`);
106
- } else if (pick === '3') {
107
- const names = Object.keys(THEMES);
108
- console.log('');
109
- names.forEach((n, i) => console.log(` ${c.cyan(`${i + 1}.`)} ${c.bold(n.padEnd(9))} ${c.dim(THEMES[n].label)}`));
110
- const t = Number(await ask(' theme [1]: ')) || 1;
111
- const chosen = names[Math.max(0, Math.min(names.length - 1, t - 1))];
112
- saveConfig({ ...cfg, theme: chosen });
113
- console.log(` ${c.mint('✔')} theme switched to ${c.violet(chosen)}!\n`);
114
- } else if (pick === '4') {
213
+ if (pick === 's' || pick === 'settings') {
214
+ await runSettings(ask, askHidden);
215
+ } else if (pick === 'u' || pick === 'update') {
115
216
  runSelfUpdate(version);
116
217
  return;
117
- } else if (pick === '5') {
118
- try {
119
- require('./statusline').installStatusline();
120
- console.log(` ${c.mint('✔')} cute statusline installed! reopen labs to see it.\n`);
121
- } catch (err) {
122
- console.log(` ${c.rose('✖')} failed: ${err.message}\n`);
123
- }
124
- } else if (pick === '6') {
125
- const { EXTENSION_URL, installBrowserServer } = require('./browser-setup');
126
- const doChrome = await ask(` ${c.cyan('🌐')} setup real chrome (playwright mcp)? ${c.dim('[y/N]:')} `);
127
- if (/^y/i.test(doChrome)) {
128
- console.log(` ${c.dim('install extension:')} ${c.cyan(EXTENSION_URL)}`);
129
- const tok = (await askMasked(` ${c.amber('🔑')} token ${c.dim('(or enter to skip):')} `)).replace(/^PLAYWRIGHT_MCP_EXTENSION_TOKEN=/, '');
130
- installBrowserServer(tok);
131
- console.log(` ${c.mint('✔')} chrome mcp connected!`);
132
- }
133
- const doBrave = await ask(` ${c.cyan('🔎')} add free brave search key? ${c.dim('[y/N]:')} `);
134
- if (/^y/i.test(doBrave)) {
135
- console.log(` ${c.dim('free key:')} ${c.cyan('https://api.search.brave.com/')}`);
136
- const bk = await askMasked(` ${c.amber('🔑')} brave api key: `);
137
- if (bk) {
138
- saveConfig({ ...storedConfig(), braveKey: bk });
139
- console.log(` ${c.mint('✔')} brave key saved!`);
140
- }
141
- }
142
- console.log('');
143
- } else if (pick === '7') {
144
- await saveGatewayKey(askHidden, ask, undefined, true);
218
+ } else if (pick === 'a' && IS_ADMIN()) {
219
+ await require('./admin-cli').runAdminCli([], ask);
145
220
  }
146
221
  }
147
222
  }
package/src/ui.js CHANGED
@@ -247,6 +247,11 @@ function askMasked(promptText) {
247
247
  process.stdout.write('\n');
248
248
  return resolve(value.trim());
249
249
  }
250
+ if (ch === '\u001b') {
251
+ cleanup();
252
+ process.stdout.write('\n');
253
+ return resolve('');
254
+ }
250
255
  if (ch === '\u0003') {
251
256
  cleanup();
252
257
  process.stdout.write('\n');