agy-family 0.4.1 → 0.6.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/README.md CHANGED
@@ -40,28 +40,38 @@ packages/
40
40
 
41
41
  ---
42
42
 
43
- ## 1. One CLI for Both Joining & Hosting
43
+ ## 1. One Standalone CLI for Hosting, Master Quota & Joining (Zero External Dependencies)
44
44
 
45
- Install `agy-family` once — the same CLI handles **joining a family board** and **deploying/managing your own board** (zero `git clone` needed):
45
+ Install `agy-family` once — the same self-contained CLI handles **hosting**, **live master subscription quota sync**, **passwordless browser access**, and **joining a family board** (zero `git clone`, zero external tools required):
46
46
 
47
47
  ```sh
48
48
  npm i -g agy-family
49
49
  ```
50
50
 
51
- - **Join someone's family board** (works for both Antigravity Desktop IDE & `agy` CLI):
51
+ - **Host your own board on Cloudflare Workers + D1 (free tier, 1 command)** — auto-provisions D1, applies migrations, enables `cli-only` private mode by default, generates `AGY_FAMILY_ADMIN_KEY`, syncs live `models.dev` 3-tier pricing, and with `--self` joins you automatically:
52
52
  ```sh
53
- agy-family join "agyfam://join?d=..." --daemon
53
+ agy-family deploy --self --member "Owner" --email "master@gmail.com" --daemon
54
+ ```
55
+ - **Bind the Master Account for live 5h / weekly subscription quota sync** (built-in official `statusLine` passive tap — zero external tools, zero OAuth secrets, transparently chains any existing status line):
56
+ ```sh
57
+ agy-family master bind --daemon
54
58
  ```
55
- - **Host your own board on Cloudflare Workers + D1 (free tier, 1 command)** — auto-provisions D1, applies migrations, generates `AGY_FAMILY_ADMIN_KEY`, syncs live `models.dev` 3-tier pricing, and with `--self` joins you automatically:
59
+ - **Open the web board passwordlessly** (60s one-time ticket -> 7-day `HttpOnly` cookie; manager machines auto-unlock Admin Console):
56
60
  ```sh
57
- agy-family deploy --self --member "Owner" --email "you@gmail.com" --daemon
61
+ agy-family open # Open directly in your default browser
62
+ agy-family open --link # Print a 5-minute single-use link for mobile
58
63
  ```
59
- - **Invite members, inspect keys, or upgrade anytime**:
64
+ - **Invite members, inspect host, or upgrade anytime**:
60
65
  ```sh
61
66
  agy-family invite "Alice" --email "alice@gmail.com" --quota 20 # Prints ready-to-paste join command
62
67
  agy-family host # Show board URL, Admin Key & member list
63
68
  npm i -g agy-family@latest && agy-family deploy # Idempotent zero-downtime upgrade
64
69
  ```
70
+ - **Join someone's family board & view dashboard** (works for both Antigravity Desktop IDE & `agy` CLI):
71
+ ```sh
72
+ agy-family join "agyfam://join?d=..." --daemon
73
+ agy-family open
74
+ ```
65
75
  - **Self-host locally or on any VPS (built-in Node SQLite)**:
66
76
  ```sh
67
77
  agy-family serve --port 8787
package/README.zh-CN.md CHANGED
@@ -40,28 +40,38 @@ packages/
40
40
 
41
41
  ---
42
42
 
43
- ## 一、一个 CLI:既能「上车」也能「自己开车」
43
+ ## 一、一个 CLI:既能「上车」也能「自己开车」(零外部依赖、零密码)
44
44
 
45
- 只需全局安装一次 `agy-family`,**成员上车**和**车主部署/发邀请/自托管**全用同一个命令行完成(免 `git clone`):
45
+ 只需全局安装一次 `agy-family`,**成员上车**、**主号订阅余量同步**、**免密打开网页看板**和**车主部署/发邀请/自托管**全部由这一个包独立完成(免 `git clone`、不依赖任何其他工具):
46
46
 
47
47
  ```sh
48
48
  npm i -g agy-family
49
49
  ```
50
50
 
51
- - **🚌 成员上车**(收到管理员发来的邀请码,桌面 IDE 和 `agy` CLI 通用):
51
+ - **🚗 车主免费云端开车**(Cloudflare Workers + D1 永久免费层,自动创建 D1、跑迁移、默认开启 `cli-only` 隐私保护、生成 Admin Key、同步 `models.dev` 三级定价,加 `--self` 顺便把自己也接上车):
52
52
  ```sh
53
- agy-family join "agyfam://join?d=..." --daemon
53
+ agy-family deploy --self --member "你的名字" --email "主号@gmail.com" --daemon
54
54
  ```
55
- - **🚗 车主免费云端开车**(Cloudflare Workers + D1 永久免费层,自动创建 D1、跑迁移、生成 Admin Key、同步 `models.dev` 三级定价,加 `--self` 顺便把自己也接上车):
55
+ - **⚡ 绑定主号实时订阅额度**(内置 `statusLine` 官方被动采集钩子,零外部工具依赖、零 Google 凭据、自动透明串联保留你原有的终端状态栏):
56
56
  ```sh
57
- agy-family deploy --self --member "你的名字" --email "你的家庭组@gmail.com" --daemon
57
+ agy-family master bind --daemon # 绑定主号并自动捕获同步 5h / 周订阅余量
58
58
  ```
59
- - **🎟️ 车主发车票 / 查密钥 / 后续升级**:
59
+ - **🔐 零密码打开网页看板**(一次性 60s 票据换取 7 天 `HttpOnly` 会话,主号电脑自动免密解锁「家庭组管理」后台):
60
+ ```sh
61
+ agy-family open # 自动打开浏览器
62
+ agy-family open --link # 生成 5 分钟单次有效链接(方便手机临时看)
63
+ ```
64
+ - **🎟️ 车主发车票 / 查状态 / 后续升级**:
60
65
  ```sh
61
66
  agy-family invite "成员名" --email "member@gmail.com" --quota 20 # 生成一行上车命令
62
- agy-family host # 随时查看看板地址与 Admin Key
67
+ agy-family host # 查看看板地址与 Admin Key
63
68
  npm i -g agy-family@latest && agy-family deploy # 一键平滑升级云端看板(保留数据与密钥)
64
69
  ```
70
+ - **🚌 成员上车 & 查看面板**(桌面 IDE 和 `agy` CLI 通用):
71
+ ```sh
72
+ agy-family join "agyfam://join?d=..." --daemon # 加入家庭组并开启后台同步
73
+ agy-family open # 零密码打开网页看板
74
+ ```
65
75
  - **🏠 本地 / VPS 自托管开车**(零依赖内置 SQLite):
66
76
  ```sh
67
77
  agy-family serve --port 8787
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-family",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "Zero-privacy-leak transparent usage dashboard, /family slash command, and fair-use budget guardrail for Google One / Antigravity family groups.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,6 +9,7 @@ process.emitWarning = function (warning, ...args) {
9
9
  return _origEmitWarning.call(this, warning, ...args);
10
10
  };
11
11
 
12
+ import { execSync, spawn } from 'node:child_process';
12
13
  import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
13
14
  import { homedir, userInfo } from 'node:os';
14
15
  import { dirname, join, resolve } from 'node:path';
@@ -19,21 +20,27 @@ import {
19
20
  extractEmailFromHookPayload,
20
21
  extractLocalSubscriptionQuota,
21
22
  fetchBoardSummary,
23
+ formatCompactStatusLineOutput,
22
24
  formatResetCountdown,
23
25
  getOrCreateSharedDeviceId,
24
26
  hashEmailSha256,
27
+ ingestStatusLineQuotaPayload,
28
+ inspectStatusLineTap,
29
+ installStatusLineTap,
30
+ isManagedStatusLineCommand,
31
+ maskEmailHint,
25
32
  masterConfigPath,
26
33
  normalizePlanTier,
27
34
  pushMasterQuotaToServer,
28
35
  pushSyncPayload,
29
- readAgyBarAccounts,
30
- readAgyBarQuotaCache,
36
+ readLocalActiveEmailHint,
31
37
  readLocalPricingSources,
32
38
  readMasterConfig,
33
- refreshAgyBarAliasQuota,
34
39
  removeMasterConfig,
35
- shouldAutoRefreshMasterQuota,
40
+ requestWebLoginTicket,
41
+ statusLineChainPath,
36
42
  syncLocalPricingCache,
43
+ uninstallStatusLineTap,
37
44
  writeActiveAccountCache,
38
45
  writeMasterConfig,
39
46
  } from '../../core/src/index.mjs';
@@ -59,7 +66,7 @@ import {
59
66
  writeHostConfig,
60
67
  } from '../src/host.mjs';
61
68
 
62
- const CLI_VERSION = '0.4.1';
69
+ const CLI_VERSION = '0.6.0';
63
70
  const THIS_CLI_PATH = fileURLToPath(import.meta.url);
64
71
  const PACKAGE_ROOT = resolve(dirname(THIS_CLI_PATH), '..', '..', '..');
65
72
 
@@ -140,6 +147,8 @@ One CLI for both joining a family group ("上车") and hosting your own board ("
140
147
  Join a Family Group (Member):
141
148
  agy-family join <agyfam://join?...> [--no-hook] [--daemon]
142
149
  Join a Google Family Group board & enable /family in IDE + CLI
150
+ agy-family open [--link] [--readonly] [--ttl 60]
151
+ Open the family board in your browser passwordlessly via a one-time CLI ticket
143
152
  agy-family sync [--dry-run] [--watch] [--full] [--quiet]
144
153
  Sync local Desktop IDE + CLI numeric usage (delta by default)
145
154
  agy-family status [--period today|7d|cycle|30d]
@@ -154,8 +163,8 @@ Join a Family Group (Member):
154
163
  Host Your Own Board (Family Manager):
155
164
  agy-family deploy [--name agy-family] [--title "..."] [--admin-key <key>] [--self] [--member <name>] [--email <gmail>] [--daemon]
156
165
  One-command deploy/upgrade on Cloudflare Workers + D1 (free tier, no git clone)
157
- agy-family master [bind [alias]|sync|set|status|unlink] [--refresh] [--daemon]
158
- Bind & sync the master account's live subscription quota (5h / weekly) to the board
166
+ agy-family master [bind|sync|set|status|unlink] [--email <gmail>] [--daemon]
167
+ Bind master account & auto-capture live 5h / weekly subscription quota (100% standalone, zero secrets)
159
168
  agy-family invite <name> [--email <gmail>] [--quota <pct>] [--role member|manager]
160
169
  Create a member and print their ready-to-paste one-line join command
161
170
  agy-family host [show|link|unlink] View or link your hosted board URL, Admin Key, and D1 metadata
@@ -167,6 +176,22 @@ Privacy guarantee:
167
176
  Prompts, replies, code, file paths, and Google credentials are NEVER read or uploaded.`);
168
177
  }
169
178
 
179
+ function openUrlInSystemBrowser(targetUrl, platform = process.platform) {
180
+ if (platform === 'darwin') {
181
+ const child = spawn('open', [targetUrl], { detached: true, stdio: 'ignore' });
182
+ child.unref();
183
+ return true;
184
+ }
185
+ if (platform === 'win32') {
186
+ const child = spawn('cmd', ['/c', 'start', '', targetUrl], { detached: true, stdio: 'ignore', windowsHide: true });
187
+ child.unref();
188
+ return true;
189
+ }
190
+ const child = spawn('xdg-open', [targetUrl], { detached: true, stdio: 'ignore' });
191
+ child.unref();
192
+ return true;
193
+ }
194
+
170
195
  function formatMasterQuotaLine(mq) {
171
196
  if (!mq || !mq.configured) return '';
172
197
  const fmtSlot = (pct, resetAt) => {
@@ -182,7 +207,6 @@ function formatMasterQuotaLine(mq) {
182
207
 
183
208
  async function runMasterQuotaSync({
184
209
  home = homedir(),
185
- forceRefresh = false,
186
210
  quiet = false,
187
211
  urlOverride = '',
188
212
  adminKeyOverride = '',
@@ -193,20 +217,11 @@ async function runMasterQuotaSync({
193
217
  const targetKey = adminKeyOverride || host?.adminKey || '';
194
218
  if (!mCfg || !targetUrl || !targetKey) return null;
195
219
 
196
- let quota = extractLocalSubscriptionQuota({ home, masterConfig: mCfg });
197
- if (mCfg.alias && (forceRefresh || shouldAutoRefreshMasterQuota(mCfg, quota))) {
198
- const ref = refreshAgyBarAliasQuota(mCfg.alias);
199
- if (ref.ok) {
200
- quota = extractLocalSubscriptionQuota({ home, masterConfig: mCfg });
201
- if (quota) quota = { ...quota, source: 'agy-bar-refresh' };
202
- } else if (!quiet && forceRefresh) {
203
- console.warn(`! Live agy-bar refresh failed (${ref.error}); falling back to cached quota.`);
204
- }
205
- }
220
+ const quota = extractLocalSubscriptionQuota({ home, masterConfig: mCfg });
206
221
  if (!quota) {
207
222
  if (!quiet) {
208
223
  console.warn(
209
- `! No cached subscription quota found for master "${mCfg.alias || mCfg.quotaKey}". Run "agy-bar account refresh ${mCfg.alias || ''}" or use "agy-family master set".`,
224
+ '! No captured master subscription quota yet. Send any turn in `agy` CLI while signed into the master account, or calibrate manually with "agy-family master set".',
210
225
  );
211
226
  }
212
227
  return null;
@@ -322,13 +337,66 @@ async function runHookCommand(eventArg) {
322
337
  raw += chunk;
323
338
  }
324
339
  const trimmed = raw.trim();
325
- const payload = trimmed ? JSON.parse(trimmed) : {};
340
+ let payload = {};
341
+ if (trimmed) {
342
+ try {
343
+ payload = JSON.parse(trimmed);
344
+ } catch {
345
+ payload = {};
346
+ }
347
+ }
326
348
 
327
349
  if (eventArg === 'pre-invocation') {
328
350
  const response = await handlePreInvocation(payload, { home: homedir() });
329
351
  process.stdout.write(JSON.stringify(response || {}));
330
352
  return;
331
353
  }
354
+ if (eventArg === 'statusline') {
355
+ const home = homedir();
356
+ let capturedRes = { captured: false, matchedMaster: false, quota: null };
357
+ try {
358
+ capturedRes = ingestStatusLineQuotaPayload(payload, { home });
359
+ } catch {}
360
+
361
+ if (capturedRes.matchedMaster) {
362
+ try {
363
+ const throttlePath = join(configBaseDir(home), 'last-master-push.json');
364
+ const prev = readJsonSafe(throttlePath);
365
+ const now = Date.now();
366
+ if (!prev?.ts || now - Number(prev.ts) >= 60_000) {
367
+ writePrivateJson(throttlePath, { ts: now });
368
+ const child = spawn(process.execPath, [THIS_CLI_PATH, 'master', 'sync', '--quiet'], {
369
+ detached: true,
370
+ stdio: 'ignore',
371
+ windowsHide: true,
372
+ });
373
+ child.unref();
374
+ }
375
+ } catch {}
376
+ }
377
+
378
+ const chain = readJsonSafe(statusLineChainPath(home));
379
+ if (chain?.command && !isManagedStatusLineCommand(chain.command)) {
380
+ try {
381
+ const out = execSync(chain.command, {
382
+ input: raw,
383
+ encoding: 'utf8',
384
+ timeout: 8_000,
385
+ stdio: ['pipe', 'pipe', 'ignore'],
386
+ });
387
+ if (out) process.stdout.write(out);
388
+ return;
389
+ } catch {
390
+ return;
391
+ }
392
+ }
393
+
394
+ if (capturedRes.quota) {
395
+ const compact = formatCompactStatusLineOutput(capturedRes.quota);
396
+ if (compact) process.stdout.write(compact);
397
+ }
398
+ return;
399
+ }
332
400
  if (eventArg === 'stop') {
333
401
  const hookEmail = extractEmailFromHookPayload(payload);
334
402
  if (hookEmail) {
@@ -346,7 +414,7 @@ async function runHookCommand(eventArg) {
346
414
  process.stdout.write('{}');
347
415
  } catch {
348
416
  // Always fail open so hook glitches never block Antigravity IDE or CLI turns.
349
- process.stdout.write('{}');
417
+ if (eventArg !== 'statusline') process.stdout.write('{}');
350
418
  }
351
419
  }
352
420
 
@@ -429,7 +497,6 @@ async function main() {
429
497
  const watch = args.includes('--watch');
430
498
  const fullSync = args.includes('--full');
431
499
  const quiet = args.includes('--quiet');
432
- const forceRefresh = args.includes('--refresh-quota') || args.includes('--refresh');
433
500
  const daysIdx = args.indexOf('--days');
434
501
  const lookbackDays = daysIdx >= 0 ? Number(args[daysIdx + 1]) || 31 : 31;
435
502
  const intervalIdx = args.indexOf('--interval');
@@ -442,7 +509,7 @@ async function main() {
442
509
  const runTick = async (isFirst) => {
443
510
  if (!dryRun && hasMasterHost) {
444
511
  try {
445
- await runMasterQuotaSync({ forceRefresh: isFirst && forceRefresh, quiet });
512
+ await runMasterQuotaSync({ quiet });
446
513
  } catch (err) {
447
514
  if (!quiet) console.error(`Master quota sync error: ${err.message}`);
448
515
  }
@@ -554,9 +621,55 @@ async function main() {
554
621
  return;
555
622
  }
556
623
 
624
+ if (cmd === 'open') {
625
+ const printLinkOnly = args.includes('--link') || args.includes('--print-link') || args.includes('--url-only');
626
+ const readonly = args.includes('--readonly') || args.includes('--member');
627
+ const ttlFlag = readFlag(args, '--ttl');
628
+ const ttlSec = ttlFlag ? Number(ttlFlag) || 60 : printLinkOnly ? 300 : 60;
629
+ const urlOverride = readFlag(args, '--url');
630
+ const adminKeyOverride = readFlag(args, '--admin-key');
631
+
632
+ const host = readHostConfig();
633
+ const cfg = getOrCreateClientConfig();
634
+ const targetUrl = (urlOverride || host?.url || cfg?.url || '').replace(/\/+$/, '');
635
+ if (!targetUrl) {
636
+ console.error('Not joined or linked to any family board yet. Run "agy-family join <invite>" or "agy-family deploy".');
637
+ process.exit(1);
638
+ }
639
+
640
+ const hostMatches = Boolean(host?.url && host.url.replace(/\/+$/, '') === targetUrl && host.adminKey);
641
+ const clientMatches = Boolean(cfg?.url && cfg.url.replace(/\/+$/, '') === targetUrl && cfg.token);
642
+ const useAdminKey = readonly ? '' : (adminKeyOverride || (hostMatches ? host.adminKey : ''));
643
+ const useToken = clientMatches ? cfg.token : (!useAdminKey && cfg?.token ? cfg.token : '');
644
+
645
+ const res = await requestWebLoginTicket({
646
+ url: targetUrl,
647
+ token: useToken,
648
+ adminKey: useAdminKey,
649
+ readonly,
650
+ ttlSec,
651
+ });
652
+
653
+ const roleLabel = res.scope === 'admin'
654
+ ? `admin${res.memberName ? ` + ${res.memberName}` : ''}`
655
+ : (res.memberName || 'member');
656
+ if (printLinkOnly) {
657
+ console.log(`One-time login link (${roleLabel}, valid ${res.expiresInSec}s, single use):`);
658
+ console.log(res.enterUrl);
659
+ return;
660
+ }
661
+
662
+ openUrlInSystemBrowser(res.enterUrl);
663
+ console.log(`✓ Opened family board in browser (${roleLabel}, one-time ticket valid ${res.expiresInSec}s)`);
664
+ console.log(` Board URL : ${targetUrl}`);
665
+ return;
666
+ }
667
+
557
668
  if (cmd === 'status') {
558
669
  const cfg = getOrCreateClientConfig();
559
- if (!cfg.url) {
670
+ const host = readHostConfig();
671
+ const targetUrl = cfg.url || host?.url || '';
672
+ if (!targetUrl) {
560
673
  console.error('Not joined to any family group yet. Run: agy-family join <agyfam://join?...>');
561
674
  process.exit(1);
562
675
  }
@@ -564,7 +677,14 @@ async function main() {
564
677
  const period = pIdx >= 0 ? args[pIdx + 1] || 'today' : 'today';
565
678
  const kIdx = args.indexOf('--view-key');
566
679
  const viewKey = kIdx >= 0 ? args[kIdx + 1] || '' : cfg.viewKey || '';
567
- const board = await fetchBoardSummary({ url: cfg.url, viewKey, period });
680
+ const hostMatches = Boolean(host?.url && host.url.replace(/\/+$/, '') === targetUrl.replace(/\/+$/, '') && host.adminKey);
681
+ const board = await fetchBoardSummary({
682
+ url: targetUrl,
683
+ viewKey,
684
+ token: cfg.token || '',
685
+ adminKey: hostMatches ? host.adminKey : '',
686
+ period,
687
+ });
568
688
  const s = board.summary || {};
569
689
  const headerExtra =
570
690
  s.quotaMode === 'pool'
@@ -605,7 +725,9 @@ async function main() {
605
725
 
606
726
  if (cmd === 'uninstall') {
607
727
  uninstallAntigravityIntegration();
728
+ uninstallStatusLineTap();
608
729
  uninstallBackgroundDaemon();
730
+ removeMasterConfig();
609
731
  rmSync(clientConfigPath(), { force: true });
610
732
  rmSync(syncedHashesPath(), { force: true });
611
733
  rmSync(accountLedgerPath(), { force: true });
@@ -698,7 +820,8 @@ async function main() {
698
820
  }
699
821
 
700
822
  console.log('\nNext steps:');
701
- console.log(` Open board : ${res.url}`);
823
+ console.log(' Open board : agy-family open');
824
+ console.log(' Master quota : agy-family master bind --daemon');
702
825
  console.log(' Invite member : agy-family invite "Alice" --email "alice@gmail.com"');
703
826
  if (!joinSelf) {
704
827
  console.log(' Join yourself : agy-family deploy --self --member "YourName" --daemon');
@@ -757,6 +880,7 @@ async function main() {
757
880
  if (m.quotaPct != null) console.log(` Quota Share : ${m.quotaPct}%`);
758
881
  console.log('\nSend this one-line join command (works for both Antigravity Desktop IDE & agy CLI):');
759
882
  console.log(` ${res.joinCommand}`);
883
+ console.log('Then open the web board anytime with: agy-family open');
760
884
  console.log('\nRaw invite code:');
761
885
  console.log(` ${res.inviteUri}`);
762
886
  return;
@@ -771,8 +895,12 @@ async function main() {
771
895
  const targetKey = adminKeyOverride || host?.adminKey || '';
772
896
 
773
897
  if (action === 'unlink' || action === 'remove' || action === 'clear') {
898
+ const sl = uninstallStatusLineTap();
774
899
  const removed = removeMasterConfig();
775
900
  console.log(`✓ Local master subscription binding: ${removed ? 'removed' : 'not configured'}.`);
901
+ if (sl.restored) {
902
+ console.log(`✓ Antigravity statusLine: ${sl.hadChained ? 'restored previous statusLine command' : 'removed capture hook'}.`);
903
+ }
776
904
  return;
777
905
  }
778
906
 
@@ -809,11 +937,10 @@ async function main() {
809
937
  }
810
938
  const mCfg = readMasterConfig();
811
939
  if (!mCfg) {
812
- console.error('No master account bound yet. Run "agy-family master bind" to pick your master account.');
940
+ console.error('No master account bound yet. Run "agy-family master bind --daemon".');
813
941
  process.exit(1);
814
942
  }
815
943
  const res = await runMasterQuotaSync({
816
- forceRefresh: args.includes('--refresh'),
817
944
  quiet: args.includes('--quiet'),
818
945
  urlOverride: targetUrl,
819
946
  adminKeyOverride: targetKey,
@@ -823,81 +950,36 @@ async function main() {
823
950
  }
824
951
 
825
952
  if (action === 'bind') {
826
- const valueFlags = new Set(['--url', '--admin-key', '--tier', '--label']);
827
- const positional = [];
828
- for (let i = 2; i < args.length; i++) {
829
- const a = args[i];
830
- if (valueFlags.has(a)) {
831
- i++;
832
- continue;
833
- }
834
- if (a.startsWith('--')) continue;
835
- positional.push(a);
836
- }
837
- const query = positional[0] || '';
838
- const barAccounts = readAgyBarAccounts();
839
- const barCache = readAgyBarQuotaCache();
840
- const sortedAccounts = [...barAccounts].sort((a, b) => {
841
- const rank = (t) => (t.includes('Ultra') ? 3 : t.includes('Pro') ? 2 : 1);
842
- return rank(b.tier) - rank(a.tier);
843
- });
844
-
845
- if (!query) {
846
- if (sortedAccounts.length === 0) {
847
- console.log('No agy-bar accounts found on this machine.');
848
- console.log('You can either:');
849
- console.log(' 1. Save your master account in agy-bar ("agy-bar account save"), then run "agy-family master bind <alias> --refresh --daemon"');
850
- console.log(' 2. Or push manually: agy-family master set --tier "Google AI Ultra" --gemini-5h 80 --gemini-weekly 40 --3p-5h 100 --3p-weekly 100');
851
- return;
852
- }
853
- console.log('Detected local agy-bar accounts (choose your Google Family Master account):');
854
- sortedAccounts.forEach((a, idx) => {
855
- const entry = barCache?.accounts?.[a.quotaKey];
856
- const g5 = entry?.buckets?.['gemini-5h']?.remaining_fraction;
857
- const gw = entry?.buckets?.['gemini-weekly']?.remaining_fraction;
858
- const qSummary =
859
- g5 !== undefined || gw !== undefined
860
- ? `Gemini 5h ${g5 !== undefined ? `${Math.round(g5 * 100)}%` : '—'} · wk ${gw !== undefined ? `${Math.round(gw * 100)}%` : '—'}`
861
- : 'no cached quota yet';
862
- console.log(
863
- ` #${idx + 1} ${a.alias.padEnd(16)} ${(a.tier || 'Unknown').padEnd(16)} ${(a.maskedEmail || '').padEnd(22)} ${qSummary}`,
864
- );
865
- });
866
- const suggested = sortedAccounts[0].alias;
867
- console.log(`\nBind master & enable background quota sync:\n agy-family master bind ${suggested} --refresh --daemon`);
868
- return;
869
- }
870
-
871
- let matched = null;
872
- const numMatch = /^#?([1-9]\d*)$/.exec(query);
873
- if (numMatch) {
874
- matched = sortedAccounts[Number(numMatch[1]) - 1] || null;
953
+ const explicitEmail = readFlag(args, '--email').trim().toLowerCase();
954
+ let emailHash = '';
955
+ let maskedEmail = '';
956
+ if (explicitEmail) {
957
+ emailHash = hashEmailSha256(explicitEmail);
958
+ maskedEmail = maskEmailHint(explicitEmail);
875
959
  } else {
876
- const ql = query.toLowerCase();
877
- matched =
878
- sortedAccounts.find((a) => a.alias.toLowerCase() === ql) ||
879
- sortedAccounts.find((a) => a.quotaKey.toLowerCase() === ql) ||
880
- sortedAccounts.find((a) => a.alias.toLowerCase().startsWith(ql)) ||
881
- null;
882
- }
883
- if (!matched) {
884
- console.error(`Account "${query}" not found in agy-bar. Run "agy-family master bind" with no arguments to list available accounts.`);
885
- process.exit(1);
960
+ const detected = readLocalActiveEmailHint();
961
+ if (detected) {
962
+ emailHash = detected.emailHash;
963
+ maskedEmail = detected.maskedEmail;
964
+ }
886
965
  }
887
966
 
888
- const autoRefresh = !args.includes('--no-auto-refresh');
889
967
  const saved = {
890
- alias: matched.alias,
891
- quotaKey: matched.quotaKey,
892
- maskedEmail: matched.maskedEmail,
893
- planTier: matched.tier || '',
894
- autoRefresh,
968
+ emailHash,
969
+ maskedEmail,
895
970
  boundAt: Date.now(),
896
971
  };
897
- const fp = writeMasterConfig(saved);
898
- console.log(`✓ Bound Master Subscription Account: ${matched.alias} (${matched.tier || 'Unknown'}${matched.maskedEmail ? ` · ${matched.maskedEmail}` : ''})`);
899
- console.log(` Saved to : ${fp} (chmod 600)`);
900
- console.log(` Auto-refresh : ${autoRefresh ? 'enabled (via local agy-bar when cache > 10m)' : 'passive cache only'}`);
972
+ const cfgFile = writeMasterConfig(saved);
973
+ const tap = installStatusLineTap({
974
+ executable: process.execPath,
975
+ cliPath: THIS_CLI_PATH,
976
+ });
977
+
978
+ console.log(`✓ Bound Master Subscription Account${maskedEmail ? `: ${maskedEmail}` : ' (will lock onto active agy account)'}`);
979
+ console.log(` Master Config : ${cfgFile} (SHA-256 fingerprint only; zero Google tokens stored)`);
980
+ console.log(
981
+ ` Quota Capture : installed built-in statusLine tap (${tap.chained ? 'chained seamlessly with your existing statusLine' : 'standalone'})`,
982
+ );
901
983
 
902
984
  if (args.includes('--daemon')) {
903
985
  const d = installBackgroundDaemon({ executable: process.execPath, cliPath: THIS_CLI_PATH });
@@ -906,25 +988,26 @@ async function main() {
906
988
  }
907
989
  }
908
990
 
909
- if (targetUrl && targetKey) {
910
- await runMasterQuotaSync({
911
- forceRefresh: args.includes('--refresh'),
912
- quiet: false,
913
- urlOverride: targetUrl,
914
- adminKeyOverride: targetKey,
915
- });
991
+ const existingQ = extractLocalSubscriptionQuota({ masterConfig: saved });
992
+ if (existingQ && targetUrl && targetKey) {
993
+ await runMasterQuotaSync({ quiet: false, urlOverride: targetUrl, adminKeyOverride: targetKey });
994
+ } else if (targetUrl && targetKey) {
995
+ console.log('ℹ Quota auto-captures on your next `agy` turn (0 secrets, 100% standalone), or calibrate immediately with `agy-family master set`.');
916
996
  } else {
917
- console.log('ℹ No hosted board linked yet — run "agy-family host link --url <...> --admin-key <...>" or "agy-family deploy", then "agy-family master sync".');
997
+ console.log('ℹ No hosted board linked yet — run "agy-family deploy" or "agy-family host link".');
918
998
  }
919
999
  return;
920
1000
  }
921
1001
 
922
1002
  // Default: `agy-family master status`
923
1003
  const mCfg = readMasterConfig();
924
- console.log('Master Subscription Quota Status:');
1004
+ const tapStatus = inspectStatusLineTap();
1005
+ console.log('Master Subscription Quota Status (100% Standalone · Zero Secrets):');
925
1006
  if (mCfg) {
926
- console.log(` Bound Account : ${mCfg.alias || mCfg.quotaKey}${mCfg.planTier ? ` (${mCfg.planTier})` : ''}${mCfg.maskedEmail ? ` · ${mCfg.maskedEmail}` : ''}`);
927
- console.log(` Auto-refresh : ${mCfg.autoRefresh ? 'on (local agy-bar)' : 'passive cache only'}`);
1007
+ console.log(` Bound Account : ${mCfg.maskedEmail || '(any active agy account)'}`);
1008
+ console.log(
1009
+ ` Quota Capture : ${tapStatus.installed ? `active (${tapStatus.chained ? 'chained with existing statusLine' : 'standalone'})` : 'not installed (run "agy-family master bind --daemon")'}`,
1010
+ );
928
1011
  console.log(` Config File : ${masterConfigPath()}`);
929
1012
  const localQ = extractLocalSubscriptionQuota({ masterConfig: mCfg });
930
1013
  if (localQ) {
@@ -933,17 +1016,20 @@ async function main() {
933
1016
  const c5 = localQ.buckets['3p-5h']?.remainingFraction;
934
1017
  const cw = localQ.buckets['3p-weekly']?.remainingFraction;
935
1018
  console.log(
936
- ` Local Cache : Gemini 5h ${g5 !== undefined ? `${Math.round(g5 * 100)}%` : '—'} · wk ${gw !== undefined ? `${Math.round(gw * 100)}%` : '—'} | 3P 5h ${c5 !== undefined ? `${Math.round(c5 * 100)}%` : '—'} · wk ${cw !== undefined ? `${Math.round(cw * 100)}%` : '—'}`,
1019
+ ` Local Cache : ${localQ.planTier ? `${localQ.planTier} · ` : ''}Gemini 5h ${g5 !== undefined ? `${Math.round(g5 * 100)}%` : '—'} · wk ${gw !== undefined ? `${Math.round(gw * 100)}%` : '—'} | 3P 5h ${c5 !== undefined ? `${Math.round(c5 * 100)}%` : '—'} · wk ${cw !== undefined ? `${Math.round(cw * 100)}%` : '—'}`,
937
1020
  );
1021
+ } else {
1022
+ console.log(' Local Cache : waiting for next `agy` turn (or run `agy-family master set ...`)');
938
1023
  }
939
1024
  } else {
940
- console.log(' Bound Account : none (run "agy-family master bind" to pick your master account)');
1025
+ console.log(' Bound Account : none');
1026
+ console.log(' Quick setup : agy-family master bind --daemon [--email master@gmail.com]');
941
1027
  }
942
1028
  if (targetUrl && targetKey) {
943
1029
  try {
944
1030
  const ov = await adminApiRequest({ url: targetUrl, adminKey: targetKey, path: '/api/admin/overview', timeoutMs: 8_000 });
945
1031
  const line = formatMasterQuotaLine(ov.masterSubscriptionQuota);
946
- console.log(` Live Board : ${line || 'not synced yet (run "agy-family master sync --refresh")'}`);
1032
+ console.log(` Live Board : ${line || 'not synced yet'}`);
947
1033
  } catch (err) {
948
1034
  console.log(` Live Board : unreachable (${err.message})`);
949
1035
  }
@@ -1048,7 +1134,7 @@ async function main() {
1048
1134
 
1049
1135
  main().catch((err) => {
1050
1136
  if (process.argv[2] === 'hook-run') {
1051
- process.stdout.write('{}');
1137
+ if (process.argv[3] !== 'statusline') process.stdout.write('{}');
1052
1138
  return;
1053
1139
  }
1054
1140
  console.error(`Error: ${err?.message || err}`);