agy-family 0.2.6 → 0.2.8
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 +32 -9
- package/README.zh-CN.md +32 -9
- package/package.json +4 -1
- package/packages/cli/bin/agy-family.mjs +343 -54
- package/packages/cli/src/hook.mjs +1 -1
- package/packages/cli/src/host.mjs +442 -0
- package/packages/core/src/index.mjs +1 -0
- package/packages/core/src/pricing-node.mjs +140 -0
- package/packages/core/src/pricing.mjs +357 -14
- package/packages/core/src/sync.mjs +2 -2
- package/packages/server-core/src/index.mjs +31 -10
- package/packages/server-core/src/schema.mjs +2 -0
- package/packages/server-core/src/stats.mjs +122 -17
- package/packages/server-core/src/ui.mjs +53 -4
- package/packages/server-node/src/server.mjs +11 -1
- package/packages/worker/migrations/0001_init.sql +57 -0
- package/packages/worker/migrations/0002_integrity.sql +29 -0
- package/packages/worker/migrations/0003_family_roles.sql +2 -0
- package/packages/worker/migrations/0004_quota_pct.sql +2 -0
- package/packages/worker/migrations/0005_account_binding.sql +5 -0
- package/packages/worker/src/index.mjs +103 -0
- package/wrangler.jsonc +28 -0
package/README.md
CHANGED
|
@@ -40,21 +40,44 @@ packages/
|
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
43
|
-
## 1. One
|
|
43
|
+
## 1. One CLI for Both Joining & Hosting
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Install `agy-family` once — the same CLI handles **joining a family board** and **deploying/managing your own board** (zero `git clone` needed):
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm i -g agy-family
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- **Join someone's family board** (works for both Antigravity Desktop IDE & `agy` CLI):
|
|
52
|
+
```sh
|
|
53
|
+
agy-family join "agyfam://join?d=..." --daemon
|
|
54
|
+
```
|
|
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:
|
|
56
|
+
```sh
|
|
57
|
+
agy-family deploy --self --member "Owner" --email "you@gmail.com" --daemon
|
|
58
|
+
```
|
|
59
|
+
- **Invite members, inspect keys, or upgrade anytime**:
|
|
60
|
+
```sh
|
|
61
|
+
agy-family invite "Alice" --email "alice@gmail.com" --quota 20 # Prints ready-to-paste join command
|
|
62
|
+
agy-family host # Show board URL, Admin Key & member list
|
|
63
|
+
npm i -g agy-family@latest && agy-family deploy # Idempotent zero-downtime upgrade
|
|
64
|
+
```
|
|
65
|
+
- **Self-host locally or on any VPS (built-in Node SQLite)**:
|
|
66
|
+
```sh
|
|
67
|
+
agy-family serve --port 8787
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 2. Alternative Manager Deployment Options
|
|
73
|
+
|
|
74
|
+
### Option A: 1-Click Browser Deploy to Cloudflare Workers + D1 (Zero CLI)
|
|
46
75
|
|
|
47
76
|
Click the button below — Cloudflare automatically forks the template, provisions a brand-new free D1 database, prompts you for `AGY_FAMILY_ADMIN_KEY`, and deploys (tables auto-initialize on first request):
|
|
48
77
|
|
|
49
78
|
[](https://deploy.workers.cloudflare.com/?url=https://github.com/xy-tuoren/agy-family)
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
```sh
|
|
54
|
-
git clone https://github.com/xy-tuoren/agy-family.git
|
|
55
|
-
cd agy-family
|
|
56
|
-
npm run deploy:cf # Auto-creates D1, runs migrations, sets Admin Key, and deploys
|
|
57
|
-
```
|
|
80
|
+
Already deployed via the button? Link it to your local CLI with `agy-family host link --url https://your-board.workers.dev --admin-key adm_...` so you can run `agy-family invite` and `agy-family deploy` upgrades from your terminal.
|
|
58
81
|
|
|
59
82
|
### Option B: One-Line Docker Deploy (Prebuilt Multi-Arch GHCR Image · No `git clone`)
|
|
60
83
|
|
package/README.zh-CN.md
CHANGED
|
@@ -40,21 +40,44 @@ packages/
|
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## 一、一个 CLI:既能「上车」也能「自己开车」
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
只需全局安装一次 `agy-family`,**成员上车**和**车主部署/发邀请/自托管**全用同一个命令行完成(免 `git clone`):
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm i -g agy-family
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- **🚌 成员上车**(收到管理员发来的邀请码,桌面 IDE 和 `agy` CLI 通用):
|
|
52
|
+
```sh
|
|
53
|
+
agy-family join "agyfam://join?d=..." --daemon
|
|
54
|
+
```
|
|
55
|
+
- **🚗 车主免费云端开车**(Cloudflare Workers + D1 永久免费层,自动创建 D1、跑迁移、生成 Admin Key、同步 `models.dev` 三级定价,加 `--self` 顺便把自己也接上车):
|
|
56
|
+
```sh
|
|
57
|
+
agy-family deploy --self --member "你的名字" --email "你的家庭组@gmail.com" --daemon
|
|
58
|
+
```
|
|
59
|
+
- **🎟️ 车主发车票 / 查密钥 / 后续升级**:
|
|
60
|
+
```sh
|
|
61
|
+
agy-family invite "成员名" --email "member@gmail.com" --quota 20 # 生成一行上车命令
|
|
62
|
+
agy-family host # 随时查看看板地址与 Admin Key
|
|
63
|
+
npm i -g agy-family@latest && agy-family deploy # 一键平滑升级云端看板(保留数据与密钥)
|
|
64
|
+
```
|
|
65
|
+
- **🏠 本地 / VPS 自托管开车**(零依赖内置 SQLite):
|
|
66
|
+
```sh
|
|
67
|
+
agy-family serve --port 8787
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 二、家庭组管理员其他部署方式
|
|
73
|
+
|
|
74
|
+
### 方式 A:Cloudflare Workers + D1 一键网页部署(免命令行)
|
|
46
75
|
|
|
47
76
|
直接点击下方按钮,Cloudflare 会自动在你的账号里创建免费 D1 数据库、弹窗让你填写管理员密码 `AGY_FAMILY_ADMIN_KEY` 并完成上线(首次访问自动建表):
|
|
48
77
|
|
|
49
78
|
[](https://deploy.workers.cloudflare.com/?url=https://github.com/xy-tuoren/agy-family)
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
```sh
|
|
54
|
-
git clone https://github.com/xy-tuoren/agy-family.git
|
|
55
|
-
cd agy-family
|
|
56
|
-
npm run deploy:cf # 自动创建 D1、执行迁移、生成/写入 Admin Key 并部署
|
|
57
|
-
```
|
|
80
|
+
如果已通过网页按钮部署,也可以用 `agy-family host link --url https://你的看板.workers.dev --admin-key adm_...` 绑定到本地 CLI,之后就能直接 `agy-family invite` 和 `agy-family deploy` 一键升级。
|
|
58
81
|
|
|
59
82
|
### 方式 B:Docker 一行脚本部署(自动拉取 GHCR 多架构镜像,免 `git clone`)
|
|
60
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-family",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"packages/cli/src/",
|
|
14
14
|
"packages/server-core/src/",
|
|
15
15
|
"packages/server-node/src/",
|
|
16
|
+
"packages/worker/src/",
|
|
17
|
+
"packages/worker/migrations/",
|
|
18
|
+
"wrangler.jsonc",
|
|
16
19
|
"README.md",
|
|
17
20
|
"README.zh-CN.md",
|
|
18
21
|
"LICENSE"
|
|
@@ -10,8 +10,8 @@ process.emitWarning = function (warning, ...args) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
13
|
-
import { homedir } from 'node:os';
|
|
14
|
-
import { dirname, join } from 'node:path';
|
|
13
|
+
import { homedir, userInfo } from 'node:os';
|
|
14
|
+
import { dirname, join, resolve } from 'node:path';
|
|
15
15
|
import { fileURLToPath } from 'node:url';
|
|
16
16
|
import {
|
|
17
17
|
buildSyncPayload,
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
getOrCreateSharedDeviceId,
|
|
22
22
|
hashEmailSha256,
|
|
23
23
|
pushSyncPayload,
|
|
24
|
+
readLocalPricingSources,
|
|
25
|
+
syncLocalPricingCache,
|
|
24
26
|
writeActiveAccountCache,
|
|
25
27
|
} from '../../core/src/index.mjs';
|
|
26
28
|
import { startNodeServer } from '../../server-node/src/server.mjs';
|
|
@@ -34,9 +36,20 @@ import {
|
|
|
34
36
|
uninstallAntigravityIntegration,
|
|
35
37
|
uninstallBackgroundDaemon,
|
|
36
38
|
} from '../src/hook.mjs';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
import {
|
|
40
|
+
adminApiRequest,
|
|
41
|
+
createMemberInvite,
|
|
42
|
+
deployToCloudflare,
|
|
43
|
+
hostConfigPath,
|
|
44
|
+
readHostConfig,
|
|
45
|
+
removeHostConfig,
|
|
46
|
+
sanitizeWorkerName,
|
|
47
|
+
writeHostConfig,
|
|
48
|
+
} from '../src/host.mjs';
|
|
49
|
+
|
|
50
|
+
const CLI_VERSION = '0.2.8';
|
|
39
51
|
const THIS_CLI_PATH = fileURLToPath(import.meta.url);
|
|
52
|
+
const PACKAGE_ROOT = resolve(dirname(THIS_CLI_PATH), '..', '..', '..');
|
|
40
53
|
|
|
41
54
|
function configBaseDir(home = homedir()) {
|
|
42
55
|
return join(home, '.config', 'agy-family');
|
|
@@ -94,22 +107,46 @@ function getOrCreateClientConfig(home = homedir()) {
|
|
|
94
107
|
return { deviceId: sharedDeviceId };
|
|
95
108
|
}
|
|
96
109
|
|
|
110
|
+
function readFlag(args, name) {
|
|
111
|
+
for (let i = 0; i < args.length; i++) {
|
|
112
|
+
const a = args[i];
|
|
113
|
+
if (a === name) {
|
|
114
|
+
const next = args[i + 1];
|
|
115
|
+
return next !== undefined && !next.startsWith('--') ? next : '';
|
|
116
|
+
}
|
|
117
|
+
if (a.startsWith(`${name}=`)) {
|
|
118
|
+
return a.slice(name.length + 1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
|
|
97
124
|
function printHelp() {
|
|
98
125
|
console.log(`agy-family v${CLI_VERSION} — Google Family Group Transparent Usage Board & /family Hook CLI
|
|
126
|
+
One CLI for both joining a family group ("上车") and hosting your own board ("自己开车").
|
|
99
127
|
|
|
100
|
-
|
|
128
|
+
Join a Family Group (Member):
|
|
101
129
|
agy-family join <agyfam://join?...> [--no-hook] [--daemon]
|
|
102
130
|
Join a Google Family Group board & enable /family in IDE + CLI
|
|
103
131
|
agy-family sync [--dry-run] [--watch] [--full] [--quiet]
|
|
104
132
|
Sync local Desktop IDE + CLI numeric usage (delta by default)
|
|
105
133
|
agy-family status [--period today|7d|cycle|30d]
|
|
106
|
-
View your
|
|
134
|
+
View your quota progress and family leaderboard
|
|
107
135
|
agy-family audit Inspect the exact last transmitted JSON payload
|
|
136
|
+
agy-family pricing [sync] View or sync 3-tier model pricing cache (models.dev / litellm)
|
|
108
137
|
agy-family hook [on|off|status] Manage Antigravity IDE + CLI /family command & Stop auto-sync hook
|
|
109
138
|
agy-family daemon [install|uninstall|status] Manage background 5-minute OS heartbeat (macOS launchd / Linux cron)
|
|
110
139
|
agy-family leave Disconnect this device and delete local invite token
|
|
111
140
|
agy-family uninstall Remove hook, /family skill, OS daemon, and local credentials
|
|
112
|
-
|
|
141
|
+
|
|
142
|
+
Host Your Own Board (Family Manager):
|
|
143
|
+
agy-family deploy [--name agy-family] [--title "..."] [--admin-key <key>] [--self] [--member <name>] [--email <gmail>] [--daemon]
|
|
144
|
+
One-command deploy/upgrade on Cloudflare Workers + D1 (free tier, no git clone)
|
|
145
|
+
agy-family invite <name> [--email <gmail>] [--quota <pct>] [--role member|manager]
|
|
146
|
+
Create a member and print their ready-to-paste one-line join command
|
|
147
|
+
agy-family host [show|link|unlink] View or link your hosted board URL, Admin Key, and D1 metadata
|
|
148
|
+
agy-family serve [--port 8787] [--db path] [--admin-key <key>] [--title "..."]
|
|
149
|
+
Start a self-hosted Node.js + SQLite board server locally or on a VPS
|
|
113
150
|
|
|
114
151
|
Privacy guarantee:
|
|
115
152
|
Only read-only numeric SQLite metadata (hour bucket, model, token counts, est. USD) is scanned.
|
|
@@ -160,6 +197,7 @@ async function runSyncOnce({ cfg, dryRun = false, fullSync = false, quiet = fals
|
|
|
160
197
|
const res = await pushSyncPayload({ url: cfg.url, token: cfg.token, payload });
|
|
161
198
|
writePrivateJson(syncedHashesPath(home), nextSyncedHashes);
|
|
162
199
|
writePrivateJson(lastResultPath(home), res);
|
|
200
|
+
syncLocalPricingCache({ home, force: false }).catch(() => {});
|
|
163
201
|
|
|
164
202
|
if (res?.member) {
|
|
165
203
|
const serverExpected = res.member.expectedEmailHash || '';
|
|
@@ -242,6 +280,48 @@ async function runHookCommand(eventArg) {
|
|
|
242
280
|
}
|
|
243
281
|
}
|
|
244
282
|
|
|
283
|
+
async function performJoin({ rawInvite, noHook = false, withDaemon = false }) {
|
|
284
|
+
const parsed = decodeInviteInput(rawInvite);
|
|
285
|
+
const prev = getOrCreateClientConfig();
|
|
286
|
+
const next = {
|
|
287
|
+
deviceId: getOrCreateSharedDeviceId({ fallbackId: prev.deviceId }),
|
|
288
|
+
url: parsed.url,
|
|
289
|
+
token: parsed.token,
|
|
290
|
+
memberName: parsed.memberName || prev.memberName || '',
|
|
291
|
+
boardTitle: parsed.boardTitle || prev.boardTitle || '',
|
|
292
|
+
...(parsed.viewKey ? { viewKey: parsed.viewKey } : {}),
|
|
293
|
+
...(parsed.expectedEmailHash ? { expectedEmailHash: parsed.expectedEmailHash } : {}),
|
|
294
|
+
joinedAt: Date.now(),
|
|
295
|
+
};
|
|
296
|
+
writePrivateJson(clientConfigPath(), next);
|
|
297
|
+
rmSync(syncedHashesPath(), { force: true });
|
|
298
|
+
rmSync(accountLedgerPath(), { force: true });
|
|
299
|
+
console.log(`✓ Saved invite for "${next.memberName || 'member'}" -> ${next.url}`);
|
|
300
|
+
|
|
301
|
+
if (!noHook) {
|
|
302
|
+
const info = installAntigravityIntegration({
|
|
303
|
+
executable: process.execPath,
|
|
304
|
+
cliPath: THIS_CLI_PATH,
|
|
305
|
+
});
|
|
306
|
+
console.log(`✓ Installed /family zero-token command & auto-sync hook (${info.hooksFile})`);
|
|
307
|
+
}
|
|
308
|
+
if (withDaemon) {
|
|
309
|
+
const d = installBackgroundDaemon({
|
|
310
|
+
executable: process.execPath,
|
|
311
|
+
cliPath: THIS_CLI_PATH,
|
|
312
|
+
});
|
|
313
|
+
if (d.kind === 'launchd' || d.kind === 'cron') {
|
|
314
|
+
console.log(`✓ Installed background heartbeat (${d.kind}, every ${d.intervalSeconds}s)`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
await runSyncOnce({ cfg: next, dryRun: false, fullSync: true });
|
|
319
|
+
if (!noHook) {
|
|
320
|
+
console.log('Tip: Type "/family" inside Antigravity IDE or agy CLI anytime (0 tokens).');
|
|
321
|
+
}
|
|
322
|
+
return next;
|
|
323
|
+
}
|
|
324
|
+
|
|
245
325
|
async function main() {
|
|
246
326
|
const args = process.argv.slice(2);
|
|
247
327
|
const cmd = args[0] || 'help';
|
|
@@ -270,44 +350,7 @@ async function main() {
|
|
|
270
350
|
console.error('Usage: agy-family join <agyfam://join?...> [--no-hook] [--daemon]');
|
|
271
351
|
process.exit(1);
|
|
272
352
|
}
|
|
273
|
-
|
|
274
|
-
const prev = getOrCreateClientConfig();
|
|
275
|
-
const next = {
|
|
276
|
-
deviceId: getOrCreateSharedDeviceId({ fallbackId: prev.deviceId }),
|
|
277
|
-
url: parsed.url,
|
|
278
|
-
token: parsed.token,
|
|
279
|
-
memberName: parsed.memberName || prev.memberName || '',
|
|
280
|
-
boardTitle: parsed.boardTitle || prev.boardTitle || '',
|
|
281
|
-
...(parsed.viewKey ? { viewKey: parsed.viewKey } : {}),
|
|
282
|
-
...(parsed.expectedEmailHash ? { expectedEmailHash: parsed.expectedEmailHash } : {}),
|
|
283
|
-
joinedAt: Date.now(),
|
|
284
|
-
};
|
|
285
|
-
writePrivateJson(clientConfigPath(), next);
|
|
286
|
-
rmSync(syncedHashesPath(), { force: true });
|
|
287
|
-
rmSync(accountLedgerPath(), { force: true });
|
|
288
|
-
console.log(`✓ Saved invite for "${next.memberName || 'member'}" -> ${next.url}`);
|
|
289
|
-
|
|
290
|
-
if (!noHook) {
|
|
291
|
-
const info = installAntigravityIntegration({
|
|
292
|
-
executable: process.execPath,
|
|
293
|
-
cliPath: THIS_CLI_PATH,
|
|
294
|
-
});
|
|
295
|
-
console.log(`✓ Installed /family zero-token command & auto-sync hook (${info.hooksFile})`);
|
|
296
|
-
}
|
|
297
|
-
if (withDaemon) {
|
|
298
|
-
const d = installBackgroundDaemon({
|
|
299
|
-
executable: process.execPath,
|
|
300
|
-
cliPath: THIS_CLI_PATH,
|
|
301
|
-
});
|
|
302
|
-
if (d.kind === 'launchd' || d.kind === 'cron') {
|
|
303
|
-
console.log(`✓ Installed background heartbeat (${d.kind}, every ${d.intervalSeconds}s)`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
await runSyncOnce({ cfg: next, dryRun: false, fullSync: true });
|
|
308
|
-
if (!noHook) {
|
|
309
|
-
console.log('Tip: Type "/family" inside Antigravity IDE or agy CLI anytime (0 tokens).');
|
|
310
|
-
}
|
|
353
|
+
await performJoin({ rawInvite: raw, noHook, withDaemon });
|
|
311
354
|
return;
|
|
312
355
|
}
|
|
313
356
|
|
|
@@ -393,6 +436,31 @@ async function main() {
|
|
|
393
436
|
return;
|
|
394
437
|
}
|
|
395
438
|
|
|
439
|
+
if (cmd === 'pricing') {
|
|
440
|
+
const action = (args[1] || 'status').toLowerCase();
|
|
441
|
+
const srcIdx = args.indexOf('--source');
|
|
442
|
+
const source = srcIdx >= 0 ? args[srcIdx + 1] || 'auto' : 'auto';
|
|
443
|
+
if (action === 'sync') {
|
|
444
|
+
const res = await syncLocalPricingCache({ source, force: true });
|
|
445
|
+
if (!res.ok) {
|
|
446
|
+
console.error(`Pricing sync failed (${res.error || 'unknown error'}); falling back to ${res.source}.`);
|
|
447
|
+
process.exit(1);
|
|
448
|
+
}
|
|
449
|
+
console.log(`✓ Synced ${res.count} model rates from ${res.source} -> ${res.cachePath}`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const { customPricing, pricingCache } = readLocalPricingSources();
|
|
453
|
+
const customCount = customPricing ? Object.keys(customPricing).length : 0;
|
|
454
|
+
const cacheCount = pricingCache?.rates ? Object.keys(pricingCache.rates).length : 0;
|
|
455
|
+
console.log('3-Tier Pricing Engine Status:');
|
|
456
|
+
console.log(` Tier 1 (Custom overrides) : ${customCount > 0 ? `${customCount} model(s)` : 'none'}`);
|
|
457
|
+
console.log(
|
|
458
|
+
` Tier 2 (Live cache) : ${cacheCount > 0 ? `${cacheCount} models (${pricingCache.source || 'models.dev'}, updated ${new Date(pricingCache.fetchedAt || 0).toISOString()})` : 'not synced yet (run "agy-family pricing sync")'}`,
|
|
459
|
+
);
|
|
460
|
+
console.log(' Tier 3 (Built-in table) : active (calibrated from models.dev)');
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
396
464
|
if (cmd === 'status') {
|
|
397
465
|
const cfg = getOrCreateClientConfig();
|
|
398
466
|
if (!cfg.url) {
|
|
@@ -452,19 +520,240 @@ async function main() {
|
|
|
452
520
|
return;
|
|
453
521
|
}
|
|
454
522
|
|
|
523
|
+
if (cmd === 'deploy' || cmd === 'up') {
|
|
524
|
+
const workerName = readFlag(args, '--name');
|
|
525
|
+
const databaseName = readFlag(args, '--db-name');
|
|
526
|
+
const databaseId = readFlag(args, '--db-id');
|
|
527
|
+
const boardTitle = readFlag(args, '--title');
|
|
528
|
+
const adminKey = readFlag(args, '--admin-key');
|
|
529
|
+
const rotateKey = args.includes('--rotate-key');
|
|
530
|
+
const dryRun = args.includes('--dry-run');
|
|
531
|
+
const joinSelf = args.includes('--self') || args.includes('--join-self');
|
|
532
|
+
const noHook = args.includes('--no-hook');
|
|
533
|
+
const withDaemon = args.includes('--daemon');
|
|
534
|
+
const selfName = readFlag(args, '--member') || (() => {
|
|
535
|
+
try {
|
|
536
|
+
return userInfo().username || 'Owner';
|
|
537
|
+
} catch {
|
|
538
|
+
return 'Owner';
|
|
539
|
+
}
|
|
540
|
+
})();
|
|
541
|
+
const selfEmail = readFlag(args, '--email');
|
|
542
|
+
const selfQuota = readFlag(args, '--quota');
|
|
543
|
+
|
|
544
|
+
const res = await deployToCloudflare({
|
|
545
|
+
packageRoot: PACKAGE_ROOT,
|
|
546
|
+
workerName,
|
|
547
|
+
databaseName,
|
|
548
|
+
databaseId,
|
|
549
|
+
boardTitle,
|
|
550
|
+
adminKey,
|
|
551
|
+
rotateKey,
|
|
552
|
+
dryRun,
|
|
553
|
+
version: CLI_VERSION,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
if (dryRun) {
|
|
557
|
+
console.log(JSON.stringify(res, null, 2));
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
console.log(`\n✓ Deployed agy-family v${CLI_VERSION} to Cloudflare Workers + D1!`);
|
|
562
|
+
console.log(` Board URL : ${res.url}`);
|
|
563
|
+
console.log(` Admin Key : ${res.adminKey}`);
|
|
564
|
+
console.log(` D1 DB : ${res.databaseName} (${res.databaseId})`);
|
|
565
|
+
console.log(` Host Saved : ${res.hostConfigPath}`);
|
|
566
|
+
if (res.pricingSync?.ok) {
|
|
567
|
+
console.log(` Pricing : synced ${res.pricingSync.count} model rates from ${res.pricingSync.source}`);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (joinSelf) {
|
|
571
|
+
const existingClient = getOrCreateClientConfig();
|
|
572
|
+
const normExistingUrl = String(existingClient?.url || '').replace(/\/+$/, '');
|
|
573
|
+
if (existingClient?.token && normExistingUrl === res.url) {
|
|
574
|
+
console.log(`\n✓ This device is already joined to ${res.url} as "${existingClient.memberName || 'member'}".`);
|
|
575
|
+
await runSyncOnce({ cfg: existingClient, dryRun: false, fullSync: false });
|
|
576
|
+
} else {
|
|
577
|
+
const overview = await adminApiRequest({
|
|
578
|
+
url: res.url,
|
|
579
|
+
adminKey: res.adminKey,
|
|
580
|
+
path: '/api/admin/overview',
|
|
581
|
+
});
|
|
582
|
+
const existingMgr = (overview.members || []).find((m) => m.role === 'manager' && m.active);
|
|
583
|
+
if (existingMgr) {
|
|
584
|
+
console.log(
|
|
585
|
+
`\nℹ Family Manager "${existingMgr.name}" already exists on this board (skipped creating duplicate manager).`,
|
|
586
|
+
);
|
|
587
|
+
console.log(
|
|
588
|
+
` To invite another member, run: agy-family invite "<name>" --email "<gmail>"`,
|
|
589
|
+
);
|
|
590
|
+
} else {
|
|
591
|
+
const created = await createMemberInvite({
|
|
592
|
+
url: res.url,
|
|
593
|
+
adminKey: res.adminKey,
|
|
594
|
+
name: selfName,
|
|
595
|
+
role: 'manager',
|
|
596
|
+
email: selfEmail,
|
|
597
|
+
quotaPct: selfQuota ? Number(selfQuota) : null,
|
|
598
|
+
});
|
|
599
|
+
console.log(`\n✓ Created Family Manager "${created.member?.name || selfName}" — joining this device now...`);
|
|
600
|
+
await performJoin({ rawInvite: created.inviteUri, noHook, withDaemon });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
console.log('\nNext steps:');
|
|
606
|
+
console.log(` Open board : ${res.url}`);
|
|
607
|
+
console.log(' Invite member : agy-family invite "Alice" --email "alice@gmail.com"');
|
|
608
|
+
if (!joinSelf) {
|
|
609
|
+
console.log(' Join yourself : agy-family deploy --self --member "YourName" --daemon');
|
|
610
|
+
}
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (cmd === 'invite') {
|
|
615
|
+
const valueFlags = new Set(['--email', '--quota', '--role', '--color', '--url', '--admin-key']);
|
|
616
|
+
const pos = [];
|
|
617
|
+
for (let i = 1; i < args.length; i++) {
|
|
618
|
+
const a = args[i];
|
|
619
|
+
if (valueFlags.has(a)) {
|
|
620
|
+
i += 1;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (a.startsWith('--')) continue;
|
|
624
|
+
pos.push(a);
|
|
625
|
+
}
|
|
626
|
+
const memberName = pos.join(' ').trim();
|
|
627
|
+
if (!memberName) {
|
|
628
|
+
console.error('Usage: agy-family invite <name> [--email <gmail>] [--quota <pct>] [--role member|manager]');
|
|
629
|
+
process.exit(1);
|
|
630
|
+
}
|
|
631
|
+
const hostCfg = readHostConfig();
|
|
632
|
+
const url = readFlag(args, '--url') || hostCfg?.url || '';
|
|
633
|
+
const adminKey = readFlag(args, '--admin-key') || hostCfg?.adminKey || process.env.AGY_FAMILY_ADMIN_KEY || '';
|
|
634
|
+
if (!url || !adminKey) {
|
|
635
|
+
console.error(
|
|
636
|
+
'No hosted board configured locally. Run "agy-family deploy" first, or link an existing board with:\n agy-family host link --url <https://...> --admin-key <adm_...>',
|
|
637
|
+
);
|
|
638
|
+
process.exit(1);
|
|
639
|
+
}
|
|
640
|
+
const email = readFlag(args, '--email');
|
|
641
|
+
const quotaRaw = readFlag(args, '--quota');
|
|
642
|
+
const role = readFlag(args, '--role') || 'member';
|
|
643
|
+
const color = readFlag(args, '--color');
|
|
644
|
+
const asJson = args.includes('--json');
|
|
645
|
+
|
|
646
|
+
const res = await createMemberInvite({
|
|
647
|
+
url,
|
|
648
|
+
adminKey,
|
|
649
|
+
name: memberName,
|
|
650
|
+
role,
|
|
651
|
+
email,
|
|
652
|
+
quotaPct: quotaRaw ? Number(quotaRaw) : null,
|
|
653
|
+
color,
|
|
654
|
+
});
|
|
655
|
+
if (asJson) {
|
|
656
|
+
console.log(JSON.stringify(res, null, 2));
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const m = res.member || {};
|
|
660
|
+
console.log(`✓ Created ${m.role === 'manager' ? 'Family Manager' : 'member'} "${m.name || memberName}" on ${url}`);
|
|
661
|
+
if (m.emailHint) console.log(` Bound Google Email : ${m.emailHint} (SHA-256 only; non-family auto-excluded)`);
|
|
662
|
+
if (m.quotaPct != null) console.log(` Quota Share : ${m.quotaPct}%`);
|
|
663
|
+
console.log('\nSend this one-line join command (works for both Antigravity Desktop IDE & agy CLI):');
|
|
664
|
+
console.log(` ${res.joinCommand}`);
|
|
665
|
+
console.log('\nRaw invite code:');
|
|
666
|
+
console.log(` ${res.inviteUri}`);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (cmd === 'host') {
|
|
671
|
+
const action = (args[1] || 'show').toLowerCase();
|
|
672
|
+
if (action === 'link') {
|
|
673
|
+
const url = readFlag(args, '--url').replace(/\/+$/, '');
|
|
674
|
+
const adminKey = readFlag(args, '--admin-key');
|
|
675
|
+
if (!url || !adminKey) {
|
|
676
|
+
console.error(
|
|
677
|
+
'Usage: agy-family host link --url <https://...> --admin-key <adm_...> [--name <worker>] [--db-name <db>] [--db-id <uuid>] [--title <title>]',
|
|
678
|
+
);
|
|
679
|
+
process.exit(1);
|
|
680
|
+
}
|
|
681
|
+
const existing = readHostConfig() || {};
|
|
682
|
+
const workerName = sanitizeWorkerName(readFlag(args, '--name') || existing.workerName || 'agy-family');
|
|
683
|
+
const databaseName = readFlag(args, '--db-name') || existing.databaseName || `${workerName}-db`;
|
|
684
|
+
const databaseId = readFlag(args, '--db-id') || existing.databaseId || '';
|
|
685
|
+
const boardTitle = readFlag(args, '--title') || existing.boardTitle || 'Antigravity Family Board';
|
|
686
|
+
const saved = writeHostConfig({
|
|
687
|
+
provider: url.includes('.workers.dev') || databaseId ? 'cloudflare' : 'self-hosted',
|
|
688
|
+
workerName,
|
|
689
|
+
databaseName,
|
|
690
|
+
databaseId,
|
|
691
|
+
url,
|
|
692
|
+
adminKey,
|
|
693
|
+
boardTitle,
|
|
694
|
+
version: CLI_VERSION,
|
|
695
|
+
linkedAt: Date.now(),
|
|
696
|
+
});
|
|
697
|
+
console.log(`✓ Linked hosted board -> ${url}`);
|
|
698
|
+
console.log(` Saved to : ${saved} (chmod 600)`);
|
|
699
|
+
console.log(' You can now run "agy-family invite <name>" or "agy-family deploy" (to upgrade).');
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (action === 'unlink' || action === 'remove') {
|
|
703
|
+
const removed = removeHostConfig();
|
|
704
|
+
console.log(`✓ Local host config: ${removed ? 'removed' : 'not configured'}.`);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const cfg = readHostConfig();
|
|
708
|
+
if (!cfg) {
|
|
709
|
+
console.log('No hosted board configured on this machine yet.');
|
|
710
|
+
console.log(' Deploy a free Cloudflare board : agy-family deploy --self --daemon');
|
|
711
|
+
console.log(' Or link an existing board : agy-family host link --url <https://...> --admin-key <adm_...>');
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (args.includes('--json')) {
|
|
715
|
+
console.log(JSON.stringify(cfg, null, 2));
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
console.log('Hosted Family Board:');
|
|
719
|
+
console.log(` Provider : ${cfg.provider || 'cloudflare'}`);
|
|
720
|
+
console.log(` Board URL : ${cfg.url || '(unknown)'}`);
|
|
721
|
+
console.log(` Admin Key : ${cfg.adminKey || '(not saved)'}`);
|
|
722
|
+
if (cfg.workerName) console.log(` Worker : ${cfg.workerName}`);
|
|
723
|
+
if (cfg.databaseName) console.log(` D1 DB : ${cfg.databaseName}${cfg.databaseId ? ` (${cfg.databaseId})` : ''}`);
|
|
724
|
+
console.log(` Config : ${hostConfigPath()}`);
|
|
725
|
+
if (cfg.url && cfg.adminKey) {
|
|
726
|
+
try {
|
|
727
|
+
const ov = await adminApiRequest({ url: cfg.url, adminKey: cfg.adminKey, path: '/api/admin/overview', timeoutMs: 8_000 });
|
|
728
|
+
const activeMembers = (ov.members || []).filter((m) => m.active);
|
|
729
|
+
console.log(` Members : ${activeMembers.length}/6 (${activeMembers.map((m) => m.name).join(', ') || 'none'})`);
|
|
730
|
+
} catch {
|
|
731
|
+
// Offline or unreachable — skip live count quietly.
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
|
|
455
737
|
if (cmd === 'serve') {
|
|
456
|
-
const
|
|
457
|
-
const
|
|
458
|
-
const
|
|
738
|
+
const portStr = readFlag(args, '--port');
|
|
739
|
+
const hostStr = readFlag(args, '--host');
|
|
740
|
+
const dbStr = readFlag(args, '--db');
|
|
741
|
+
const keyStr = readFlag(args, '--admin-key');
|
|
742
|
+
const titleStr = readFlag(args, '--title');
|
|
743
|
+
const publicUrlStr = readFlag(args, '--public-url');
|
|
459
744
|
const inst = await startNodeServer({
|
|
460
|
-
...(
|
|
461
|
-
...(
|
|
462
|
-
...(
|
|
745
|
+
...(portStr ? { port: Number(portStr) } : {}),
|
|
746
|
+
...(hostStr ? { host: hostStr } : {}),
|
|
747
|
+
...(dbStr ? { dbPath: dbStr } : {}),
|
|
748
|
+
...(keyStr ? { adminKey: keyStr } : {}),
|
|
749
|
+
...(publicUrlStr ? { publicBaseUrl: publicUrlStr } : {}),
|
|
750
|
+
...(titleStr ? { envDefaults: { boardTitle: titleStr } } : {}),
|
|
463
751
|
});
|
|
752
|
+
const displayUrl = publicUrlStr || `http://${inst.host === '0.0.0.0' ? '127.0.0.1' : inst.host}:${inst.port}`;
|
|
464
753
|
console.log(`agy-family server listening on http://${inst.host}:${inst.port}`);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
754
|
+
console.log(`Board URL : ${displayUrl}`);
|
|
755
|
+
console.log(`Admin Key : ${inst.adminKey}${inst.generatedAdminKey ? ' (auto-generated)' : ''}`);
|
|
756
|
+
console.log(`Invite : agy-family invite "Alice" --url ${displayUrl} --admin-key ${inst.adminKey}`);
|
|
468
757
|
return;
|
|
469
758
|
}
|
|
470
759
|
|
|
@@ -716,7 +716,7 @@ export async function runHeadlessSync({ cfg, fullSync = false, home = homedir(),
|
|
|
716
716
|
const { payload, scan, nextSyncedHashes, nextAccountLedger } = await buildSyncPayload({
|
|
717
717
|
deviceId,
|
|
718
718
|
clientKind: 'cli',
|
|
719
|
-
clientVersion: '0.2.
|
|
719
|
+
clientVersion: '0.2.8',
|
|
720
720
|
home,
|
|
721
721
|
fileCache: cache,
|
|
722
722
|
syncedHashes: prevHashes,
|