agy-family 0.3.1 → 0.4.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/package.json +1 -1
- package/packages/cli/bin/agy-family.mjs +288 -4
- package/packages/cli/src/hook.mjs +26 -6
- package/packages/core/src/account.mjs +7 -5
- package/packages/core/src/index.mjs +1 -0
- package/packages/core/src/quota.mjs +319 -0
- package/packages/core/src/sync.mjs +9 -2
- package/packages/server-core/src/index.mjs +139 -1
- package/packages/server-core/src/schema.mjs +18 -0
- package/packages/server-core/src/stats.mjs +193 -2
- package/packages/server-core/src/ui.mjs +402 -160
- package/packages/worker/migrations/0007_master_quota.sql +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-family",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
@@ -17,13 +17,25 @@ import {
|
|
|
17
17
|
buildSyncPayload,
|
|
18
18
|
decodeInviteInput,
|
|
19
19
|
extractEmailFromHookPayload,
|
|
20
|
+
extractLocalSubscriptionQuota,
|
|
20
21
|
fetchBoardSummary,
|
|
22
|
+
formatResetCountdown,
|
|
21
23
|
getOrCreateSharedDeviceId,
|
|
22
24
|
hashEmailSha256,
|
|
25
|
+
masterConfigPath,
|
|
26
|
+
normalizePlanTier,
|
|
27
|
+
pushMasterQuotaToServer,
|
|
23
28
|
pushSyncPayload,
|
|
29
|
+
readAgyBarAccounts,
|
|
30
|
+
readAgyBarQuotaCache,
|
|
24
31
|
readLocalPricingSources,
|
|
32
|
+
readMasterConfig,
|
|
33
|
+
refreshAgyBarAliasQuota,
|
|
34
|
+
removeMasterConfig,
|
|
35
|
+
shouldAutoRefreshMasterQuota,
|
|
25
36
|
syncLocalPricingCache,
|
|
26
37
|
writeActiveAccountCache,
|
|
38
|
+
writeMasterConfig,
|
|
27
39
|
} from '../../core/src/index.mjs';
|
|
28
40
|
import { startNodeServer } from '../../server-node/src/server.mjs';
|
|
29
41
|
import {
|
|
@@ -47,7 +59,7 @@ import {
|
|
|
47
59
|
writeHostConfig,
|
|
48
60
|
} from '../src/host.mjs';
|
|
49
61
|
|
|
50
|
-
const CLI_VERSION = '0.
|
|
62
|
+
const CLI_VERSION = '0.4.1';
|
|
51
63
|
const THIS_CLI_PATH = fileURLToPath(import.meta.url);
|
|
52
64
|
const PACKAGE_ROOT = resolve(dirname(THIS_CLI_PATH), '..', '..', '..');
|
|
53
65
|
|
|
@@ -142,6 +154,8 @@ Join a Family Group (Member):
|
|
|
142
154
|
Host Your Own Board (Family Manager):
|
|
143
155
|
agy-family deploy [--name agy-family] [--title "..."] [--admin-key <key>] [--self] [--member <name>] [--email <gmail>] [--daemon]
|
|
144
156
|
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
|
|
145
159
|
agy-family invite <name> [--email <gmail>] [--quota <pct>] [--role member|manager]
|
|
146
160
|
Create a member and print their ready-to-paste one-line join command
|
|
147
161
|
agy-family host [show|link|unlink] View or link your hosted board URL, Admin Key, and D1 metadata
|
|
@@ -153,6 +167,62 @@ Privacy guarantee:
|
|
|
153
167
|
Prompts, replies, code, file paths, and Google credentials are NEVER read or uploaded.`);
|
|
154
168
|
}
|
|
155
169
|
|
|
170
|
+
function formatMasterQuotaLine(mq) {
|
|
171
|
+
if (!mq || !mq.configured) return '';
|
|
172
|
+
const fmtSlot = (pct, resetAt) => {
|
|
173
|
+
if (pct === null || pct === undefined) return '—';
|
|
174
|
+
const cd = formatResetCountdown(resetAt);
|
|
175
|
+
return `${pct}%${cd ? ` (${cd})` : ''}`;
|
|
176
|
+
};
|
|
177
|
+
const tier = mq.planTier ? ` (${mq.planTier})` : '';
|
|
178
|
+
const g = mq.gemini || {};
|
|
179
|
+
const tp = mq.thirdParty || {};
|
|
180
|
+
return `Master${tier}: Gemini 5h ${fmtSlot(g.fiveHourPct, g.fiveHourResetAt)} · wk ${fmtSlot(g.weeklyPct, g.weeklyResetAt)} | 3P 5h ${fmtSlot(tp.fiveHourPct, tp.fiveHourResetAt)} · wk ${fmtSlot(tp.weeklyPct, tp.weeklyResetAt)}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function runMasterQuotaSync({
|
|
184
|
+
home = homedir(),
|
|
185
|
+
forceRefresh = false,
|
|
186
|
+
quiet = false,
|
|
187
|
+
urlOverride = '',
|
|
188
|
+
adminKeyOverride = '',
|
|
189
|
+
} = {}) {
|
|
190
|
+
const mCfg = readMasterConfig({ home });
|
|
191
|
+
const host = readHostConfig({ home });
|
|
192
|
+
const targetUrl = urlOverride || host?.url || '';
|
|
193
|
+
const targetKey = adminKeyOverride || host?.adminKey || '';
|
|
194
|
+
if (!mCfg || !targetUrl || !targetKey) return null;
|
|
195
|
+
|
|
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
|
+
}
|
|
206
|
+
if (!quota) {
|
|
207
|
+
if (!quiet) {
|
|
208
|
+
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".`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const res = await pushMasterQuotaToServer({
|
|
216
|
+
url: targetUrl,
|
|
217
|
+
adminKey: targetKey,
|
|
218
|
+
quota,
|
|
219
|
+
});
|
|
220
|
+
if (!quiet && res?.masterSubscriptionQuota) {
|
|
221
|
+
console.log(`✓ Synced master subscription quota -> ${formatMasterQuotaLine(res.masterSubscriptionQuota)}`);
|
|
222
|
+
}
|
|
223
|
+
return res;
|
|
224
|
+
}
|
|
225
|
+
|
|
156
226
|
async function runSyncOnce({ cfg, dryRun = false, fullSync = false, quiet = false, lookbackDays = 31, home = homedir() }) {
|
|
157
227
|
const cache = fullSync ? null : readJsonSafe(scanCachePath(home));
|
|
158
228
|
const prevHashes = dryRun || fullSync ? null : readJsonSafe(syncedHashesPath(home));
|
|
@@ -359,17 +429,40 @@ async function main() {
|
|
|
359
429
|
const watch = args.includes('--watch');
|
|
360
430
|
const fullSync = args.includes('--full');
|
|
361
431
|
const quiet = args.includes('--quiet');
|
|
432
|
+
const forceRefresh = args.includes('--refresh-quota') || args.includes('--refresh');
|
|
362
433
|
const daysIdx = args.indexOf('--days');
|
|
363
434
|
const lookbackDays = daysIdx >= 0 ? Number(args[daysIdx + 1]) || 31 : 31;
|
|
364
435
|
const intervalIdx = args.indexOf('--interval');
|
|
365
436
|
const intervalSec = Math.max(30, intervalIdx >= 0 ? Number(args[intervalIdx + 1]) || 180 : 180);
|
|
366
437
|
|
|
367
438
|
const cfg = getOrCreateClientConfig();
|
|
368
|
-
|
|
439
|
+
const hasMasterHost = Boolean(readMasterConfig() && readHostConfig()?.url && readHostConfig()?.adminKey);
|
|
440
|
+
const hasMemberClient = Boolean(cfg.url && cfg.token);
|
|
441
|
+
|
|
442
|
+
const runTick = async (isFirst) => {
|
|
443
|
+
if (!dryRun && hasMasterHost) {
|
|
444
|
+
try {
|
|
445
|
+
await runMasterQuotaSync({ forceRefresh: isFirst && forceRefresh, quiet });
|
|
446
|
+
} catch (err) {
|
|
447
|
+
if (!quiet) console.error(`Master quota sync error: ${err.message}`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (dryRun || hasMemberClient || !hasMasterHost) {
|
|
451
|
+
try {
|
|
452
|
+
await runSyncOnce({ cfg, dryRun, fullSync: isFirst && fullSync, quiet, lookbackDays });
|
|
453
|
+
} catch (err) {
|
|
454
|
+
// If this machine is also syncing master quota via daemon, don't fail the whole tick on a revoked member token.
|
|
455
|
+
if (hasMasterHost && quiet) return;
|
|
456
|
+
throw err;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
await runTick(true);
|
|
369
462
|
if (watch && !dryRun) {
|
|
370
463
|
if (!quiet) console.log(`Watching local usage every ${intervalSec}s with delta sync (Ctrl+C to stop)...`);
|
|
371
464
|
setInterval(() => {
|
|
372
|
-
|
|
465
|
+
runTick(false).catch((err) => {
|
|
373
466
|
if (!quiet) console.error(`Sync error: ${err.message}`);
|
|
374
467
|
});
|
|
375
468
|
}, intervalSec * 1000);
|
|
@@ -480,8 +573,10 @@ async function main() {
|
|
|
480
573
|
console.log(
|
|
481
574
|
`${board.boardTitle} (${board.period}) — Online ${s.onlineCount}/${s.memberCount} (limit ${s.maxMembers || 6}) · ${headerExtra}`,
|
|
482
575
|
);
|
|
576
|
+
const mqLine = formatMasterQuotaLine(board.masterSubscriptionQuota);
|
|
577
|
+
if (mqLine) console.log(` ${mqLine}`);
|
|
483
578
|
for (const m of board.members || []) {
|
|
484
|
-
const role = m.role === 'manager' ? ' [
|
|
579
|
+
const role = m.role === 'manager' ? ' [Master]' : '';
|
|
485
580
|
const qStatus = m.quotaStatus || 'ok';
|
|
486
581
|
const flag = qStatus === 'over' ? ' [OVER SHARE]' : qStatus === 'warn' ? ' [ABOVE SHARE]' : '';
|
|
487
582
|
const acctFlag =
|
|
@@ -667,6 +762,195 @@ async function main() {
|
|
|
667
762
|
return;
|
|
668
763
|
}
|
|
669
764
|
|
|
765
|
+
if (cmd === 'master') {
|
|
766
|
+
const action = (args[1] || 'status').toLowerCase();
|
|
767
|
+
const urlOverride = readFlag(args, '--url');
|
|
768
|
+
const adminKeyOverride = readFlag(args, '--admin-key');
|
|
769
|
+
const host = readHostConfig();
|
|
770
|
+
const targetUrl = urlOverride || host?.url || '';
|
|
771
|
+
const targetKey = adminKeyOverride || host?.adminKey || '';
|
|
772
|
+
|
|
773
|
+
if (action === 'unlink' || action === 'remove' || action === 'clear') {
|
|
774
|
+
const removed = removeMasterConfig();
|
|
775
|
+
console.log(`✓ Local master subscription binding: ${removed ? 'removed' : 'not configured'}.`);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (action === 'set') {
|
|
780
|
+
if (!targetUrl || !targetKey) {
|
|
781
|
+
console.error('No hosted board configured. Run "agy-family host link --url <...> --admin-key <...>" or pass --url and --admin-key.');
|
|
782
|
+
process.exit(1);
|
|
783
|
+
}
|
|
784
|
+
const g5 = readFlag(args, '--gemini-5h');
|
|
785
|
+
const gw = readFlag(args, '--gemini-weekly');
|
|
786
|
+
const tp5 = readFlag(args, '--3p-5h') || readFlag(args, '--claude-5h');
|
|
787
|
+
const tpw = readFlag(args, '--3p-weekly') || readFlag(args, '--claude-weekly');
|
|
788
|
+
const tier = readFlag(args, '--tier') || 'Google AI Ultra';
|
|
789
|
+
const label = readFlag(args, '--label') || '';
|
|
790
|
+
const payload = {
|
|
791
|
+
planTier: normalizePlanTier(tier),
|
|
792
|
+
accountLabel: label,
|
|
793
|
+
source: 'manual',
|
|
794
|
+
observedAt: Date.now(),
|
|
795
|
+
...(g5 !== '' ? { gemini5hPct: Number(g5) } : {}),
|
|
796
|
+
...(gw !== '' ? { geminiWeeklyPct: Number(gw) } : {}),
|
|
797
|
+
...(tp5 !== '' ? { thirdParty5hPct: Number(tp5) } : {}),
|
|
798
|
+
...(tpw !== '' ? { thirdPartyWeeklyPct: Number(tpw) } : {}),
|
|
799
|
+
};
|
|
800
|
+
const res = await pushMasterQuotaToServer({ url: targetUrl, adminKey: targetKey, quota: payload });
|
|
801
|
+
console.log(`✓ Updated master subscription quota -> ${formatMasterQuotaLine(res.masterSubscriptionQuota)}`);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (action === 'sync') {
|
|
806
|
+
if (!targetUrl || !targetKey) {
|
|
807
|
+
console.error('No hosted board configured. Run "agy-family deploy" or "agy-family host link --url <...> --admin-key <...>".');
|
|
808
|
+
process.exit(1);
|
|
809
|
+
}
|
|
810
|
+
const mCfg = readMasterConfig();
|
|
811
|
+
if (!mCfg) {
|
|
812
|
+
console.error('No master account bound yet. Run "agy-family master bind" to pick your master account.');
|
|
813
|
+
process.exit(1);
|
|
814
|
+
}
|
|
815
|
+
const res = await runMasterQuotaSync({
|
|
816
|
+
forceRefresh: args.includes('--refresh'),
|
|
817
|
+
quiet: args.includes('--quiet'),
|
|
818
|
+
urlOverride: targetUrl,
|
|
819
|
+
adminKeyOverride: targetKey,
|
|
820
|
+
});
|
|
821
|
+
if (!res) process.exit(1);
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
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;
|
|
875
|
+
} 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);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const autoRefresh = !args.includes('--no-auto-refresh');
|
|
889
|
+
const saved = {
|
|
890
|
+
alias: matched.alias,
|
|
891
|
+
quotaKey: matched.quotaKey,
|
|
892
|
+
maskedEmail: matched.maskedEmail,
|
|
893
|
+
planTier: matched.tier || '',
|
|
894
|
+
autoRefresh,
|
|
895
|
+
boundAt: Date.now(),
|
|
896
|
+
};
|
|
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'}`);
|
|
901
|
+
|
|
902
|
+
if (args.includes('--daemon')) {
|
|
903
|
+
const d = installBackgroundDaemon({ executable: process.execPath, cliPath: THIS_CLI_PATH });
|
|
904
|
+
if (d.kind === 'launchd' || d.kind === 'cron') {
|
|
905
|
+
console.log(`✓ Background sync daemon active (${d.kind}, every ${d.intervalSeconds}s)`);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
if (targetUrl && targetKey) {
|
|
910
|
+
await runMasterQuotaSync({
|
|
911
|
+
forceRefresh: args.includes('--refresh'),
|
|
912
|
+
quiet: false,
|
|
913
|
+
urlOverride: targetUrl,
|
|
914
|
+
adminKeyOverride: targetKey,
|
|
915
|
+
});
|
|
916
|
+
} 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".');
|
|
918
|
+
}
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// Default: `agy-family master status`
|
|
923
|
+
const mCfg = readMasterConfig();
|
|
924
|
+
console.log('Master Subscription Quota Status:');
|
|
925
|
+
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'}`);
|
|
928
|
+
console.log(` Config File : ${masterConfigPath()}`);
|
|
929
|
+
const localQ = extractLocalSubscriptionQuota({ masterConfig: mCfg });
|
|
930
|
+
if (localQ) {
|
|
931
|
+
const g5 = localQ.buckets['gemini-5h']?.remainingFraction;
|
|
932
|
+
const gw = localQ.buckets['gemini-weekly']?.remainingFraction;
|
|
933
|
+
const c5 = localQ.buckets['3p-5h']?.remainingFraction;
|
|
934
|
+
const cw = localQ.buckets['3p-weekly']?.remainingFraction;
|
|
935
|
+
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)}%` : '—'}`,
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
} else {
|
|
940
|
+
console.log(' Bound Account : none (run "agy-family master bind" to pick your master account)');
|
|
941
|
+
}
|
|
942
|
+
if (targetUrl && targetKey) {
|
|
943
|
+
try {
|
|
944
|
+
const ov = await adminApiRequest({ url: targetUrl, adminKey: targetKey, path: '/api/admin/overview', timeoutMs: 8_000 });
|
|
945
|
+
const line = formatMasterQuotaLine(ov.masterSubscriptionQuota);
|
|
946
|
+
console.log(` Live Board : ${line || 'not synced yet (run "agy-family master sync --refresh")'}`);
|
|
947
|
+
} catch (err) {
|
|
948
|
+
console.log(` Live Board : unreachable (${err.message})`);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
|
|
670
954
|
if (cmd === 'host') {
|
|
671
955
|
const action = (args[1] || 'show').toLowerCase();
|
|
672
956
|
if (action === 'link') {
|
|
@@ -475,17 +475,37 @@ function boardLinkFromConfig(cfg) {
|
|
|
475
475
|
return target;
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
+
function fmtResetCdShort(ms) {
|
|
479
|
+
if (!ms || !Number.isFinite(Number(ms)) || Number(ms) <= 0) return '';
|
|
480
|
+
const mins = Math.ceil(Number(ms) / 60_000);
|
|
481
|
+
if (mins < 60) return `${mins}m`;
|
|
482
|
+
const h = Math.floor(mins / 60);
|
|
483
|
+
const remM = mins % 60;
|
|
484
|
+
if (h < 24) return remM > 0 ? `${h}h${remM}m` : `${h}h`;
|
|
485
|
+
const d = Math.floor(h / 24);
|
|
486
|
+
const remH = h % 24;
|
|
487
|
+
return remH > 0 ? `${d}d${remH}h` : `${d}d`;
|
|
488
|
+
}
|
|
489
|
+
|
|
478
490
|
function formatStatusMarkdown(board, cfg) {
|
|
479
491
|
const periodLabel = { today: '今日', '7d': '近 7 天', cycle: '本周期', '30d': '近 30 天' }[board.period] || board.period;
|
|
480
492
|
const s = board.summary || {};
|
|
481
|
-
const
|
|
482
|
-
const
|
|
483
|
-
?
|
|
484
|
-
|
|
493
|
+
const mq = board.masterSubscriptionQuota;
|
|
494
|
+
const masterLine = mq && mq.configured
|
|
495
|
+
? (() => {
|
|
496
|
+
const g = mq.gemini || {};
|
|
497
|
+
const tp = mq.thirdParty || {};
|
|
498
|
+
const fmtP = (pct, ms) => (pct !== null && pct !== undefined ? `\`${pct}%\`${ms ? ` (${fmtResetCdShort(ms)})` : ''}` : '`—`');
|
|
499
|
+
const tier = mq.planTier ? ` (${mq.planTier})` : '';
|
|
500
|
+
return `**主号订阅额度${tier}**:Gemini 5h ${fmtP(g.fiveHourPct, g.fiveHourResetInMs)} · 周 ${fmtP(g.weeklyPct, g.weeklyResetInMs)} | 3P 5h ${fmtP(tp.fiveHourPct, tp.fiveHourResetInMs)} · 周 ${fmtP(tp.weeklyPct, tp.weeklyResetInMs)}`;
|
|
501
|
+
})()
|
|
502
|
+
: '';
|
|
503
|
+
const summaryLine = `**家庭组总览**:在线 \`${s.onlineCount}/${s.memberCount}\`(上限 ${s.maxMembers || 6} 人) · 按百分比份额核算(折算参考 \`${fmtUsd(s.totalUsd)}\`)`;
|
|
485
504
|
|
|
486
505
|
const lines = [
|
|
487
506
|
`### ${board.boardTitle || 'Google 家庭组透明看板'} · ${periodLabel} *(0 tokens)*`,
|
|
488
507
|
'',
|
|
508
|
+
...(masterLine ? [masterLine, ''] : []),
|
|
489
509
|
summaryLine,
|
|
490
510
|
'',
|
|
491
511
|
'| 家庭成员 | 状态 | 分配份额与进度 | 使用占比 | 参考金额 |',
|
|
@@ -494,7 +514,7 @@ function formatStatusMarkdown(board, cfg) {
|
|
|
494
514
|
|
|
495
515
|
for (const m of board.members || []) {
|
|
496
516
|
const badges = [];
|
|
497
|
-
if (m.role === 'manager') badges.push('
|
|
517
|
+
if (m.role === 'manager') badges.push('主号');
|
|
498
518
|
if (cfg?.memberId && m.id === cfg.memberId) badges.push('我');
|
|
499
519
|
const nameStr = badges.length ? `**${m.name}** (${badges.join('·')})` : m.name;
|
|
500
520
|
const qPct = m.quotaPct ?? (s.memberCount > 0 ? Math.round((100 / s.memberCount) * 10) / 10 : 100);
|
|
@@ -716,7 +736,7 @@ export async function runHeadlessSync({ cfg, fullSync = false, home = homedir(),
|
|
|
716
736
|
const { payload, scan, nextSyncedHashes, nextAccountLedger } = await buildSyncPayload({
|
|
717
737
|
deviceId,
|
|
718
738
|
clientKind: 'cli',
|
|
719
|
-
clientVersion: '0.
|
|
739
|
+
clientVersion: '0.4.1',
|
|
720
740
|
home,
|
|
721
741
|
fileCache: cache,
|
|
722
742
|
syncedHashes: prevHashes,
|
|
@@ -138,30 +138,32 @@ export function defaultDesktopAppStoragePaths({
|
|
|
138
138
|
platform = process.platform,
|
|
139
139
|
env = process.env,
|
|
140
140
|
} = {}) {
|
|
141
|
+
const useEnvDirs = home === homedir() || env !== process.env;
|
|
141
142
|
if (platform === 'darwin') {
|
|
142
143
|
return [join(home, 'Library', 'Application Support', 'Antigravity', 'app_storage.json')];
|
|
143
144
|
}
|
|
144
145
|
if (platform === 'win32') {
|
|
145
|
-
const appData = env.APPDATA || join(home, 'AppData', 'Roaming');
|
|
146
|
-
const localAppData = env.LOCALAPPDATA || join(home, 'AppData', 'Local');
|
|
146
|
+
const appData = (useEnvDirs && env.APPDATA) || join(home, 'AppData', 'Roaming');
|
|
147
|
+
const localAppData = (useEnvDirs && env.LOCALAPPDATA) || join(home, 'AppData', 'Local');
|
|
147
148
|
return [
|
|
148
149
|
join(appData, 'Antigravity', 'app_storage.json'),
|
|
149
150
|
join(localAppData, 'Antigravity', 'app_storage.json'),
|
|
150
151
|
];
|
|
151
152
|
}
|
|
152
|
-
const xdg = env.XDG_CONFIG_HOME || join(home, '.config');
|
|
153
|
+
const xdg = (useEnvDirs && env.XDG_CONFIG_HOME) || join(home, '.config');
|
|
153
154
|
return [join(xdg, 'Antigravity', 'app_storage.json')];
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
export function defaultIdeStateDbPaths({ home = homedir(), platform = process.platform, env = process.env } = {}) {
|
|
158
|
+
const useEnvDirs = home === homedir() || env !== process.env;
|
|
157
159
|
if (platform === 'darwin') {
|
|
158
160
|
return [join(home, 'Library', 'Application Support', 'Antigravity', 'User', 'globalStorage', 'state.vscdb')];
|
|
159
161
|
}
|
|
160
162
|
if (platform === 'win32') {
|
|
161
|
-
const appData = env.APPDATA || join(home, 'AppData', 'Roaming');
|
|
163
|
+
const appData = (useEnvDirs && env.APPDATA) || join(home, 'AppData', 'Roaming');
|
|
162
164
|
return [join(appData, 'Antigravity', 'User', 'globalStorage', 'state.vscdb')];
|
|
163
165
|
}
|
|
164
|
-
const xdg = env.XDG_CONFIG_HOME || join(home, '.config');
|
|
166
|
+
const xdg = (useEnvDirs && env.XDG_CONFIG_HOME) || join(home, '.config');
|
|
165
167
|
return [join(xdg, 'Antigravity', 'User', 'globalStorage', 'state.vscdb')];
|
|
166
168
|
}
|
|
167
169
|
|