flypod 0.5.0 → 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.
Files changed (2) hide show
  1. package/dist/bin/deploy.js +848 -119
  2. package/package.json +7 -2
@@ -118,7 +118,7 @@ async function forgetSite(site_id, env) {
118
118
  import { readFile as readFile2, unlink } from "node:fs/promises";
119
119
  async function resolveAuth(env = process.env) {
120
120
  const session = await loadSession(env);
121
- const apiKey = session?.api_key ?? env.FLYPOD_API_KEY;
121
+ const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
122
122
  const baseUrl = session?.base_url ?? env.DEPLOY_URL ?? "https://flypod.dev";
123
123
  return { apiKey, baseUrl };
124
124
  }
@@ -127,7 +127,7 @@ async function loadSession(env) {
127
127
  const path = sessionFilePath(env);
128
128
  const text = await readFile2(path, "utf8");
129
129
  const parsed = JSON.parse(text);
130
- if (typeof parsed?.api_key === "string" && typeof parsed?.base_url === "string" && typeof parsed?.created_at === "number") {
130
+ if (typeof parsed?.session_token === "string" && typeof parsed?.base_url === "string" && typeof parsed?.created_at === "number") {
131
131
  return parsed;
132
132
  }
133
133
  return null;
@@ -154,62 +154,270 @@ async function clearSession(env) {
154
154
  function baseUrlFrom(env = process.env) {
155
155
  return env.DEPLOY_URL ?? "https://flypod.dev";
156
156
  }
157
- async function openBrowser(url) {
158
- const platform2 = process.platform;
159
- const cmd = platform2 === "darwin" ? "open" : platform2 === "win32" ? "start" : "xdg-open";
160
- await Bun.$`${cmd} ${url}`.quiet().nothrow();
157
+ function siteUrlFrom(site_id, baseUrl) {
158
+ const host = new URL(baseUrl).host;
159
+ const scheme = new URL(baseUrl).protocol.replace(":", "");
160
+ return `${scheme}://${site_id}.${host}`;
161
161
  }
162
+ var SUBCOMMAND_HELP = {
163
+ update: `flypod update [path] [flags]
164
+
165
+ Ship a new version of the site linked to this folder.
166
+
167
+ flypod update Re-deploy this folder as a new version.
168
+ flypod update ./dist Same, with an explicit path.
169
+ flypod update --site <id> Update any site by id (no folder memory needed).
170
+ flypod update --token <tok> Use a manage_token (anonymous sites).
171
+
172
+ Flags:
173
+ --site <id> Target a site by id instead of the linked folder.
174
+ --token <tok> Authorize with a manage_token.
175
+ --json Emit JSON on stdout (for agents/scripts).
176
+ -q, --quiet Minimal output.
177
+ -h, --help Show this help.`,
178
+ versions: `flypod versions [flags]
179
+
180
+ List every version of the site linked to this folder.
181
+
182
+ flypod versions Show version history for the linked site.
183
+ flypod versions --site <id> Show versions for a specific site.
184
+
185
+ Flags:
186
+ --site <id> Target a site by id.
187
+ --token <tok> Authorize with a manage_token.
188
+ --json Emit JSON on stdout.
189
+ -h, --help Show this help.`,
190
+ rollback: `flypod rollback [version] [flags]
191
+
192
+ Roll the site back to a previous version.
193
+
194
+ flypod rollback Roll back to the immediately previous version.
195
+ flypod rollback <version> Roll back to a specific version id (or prefix).
196
+ flypod rollback --site <id> Roll back a site by id.
197
+
198
+ Flags:
199
+ --site <id> Target a site by id.
200
+ --token <tok> Authorize with a manage_token.
201
+ --json Emit JSON on stdout.
202
+ -h, --help Show this help.`,
203
+ forget: `flypod forget [flags]
204
+
205
+ Drop this folder's remembered site link.
206
+
207
+ flypod forget Forget this folder's link.
208
+ flypod forget --site <id> Forget all folders linked to a site id.
209
+
210
+ Flags:
211
+ --site <id> Forget all links to this site.
212
+ -h, --help Show this help.`,
213
+ login: `flypod login [flags]
214
+
215
+ Authenticate with flypod via the browser (device authorization).
216
+
217
+ flypod login Start the device sign-in (open a browser).
218
+ flypod login --token <t> Save a session token directly (for agents/CI).
219
+
220
+ Flags:
221
+ --token <t> Save this session token instead of opening a browser.
222
+ -h, --help Show this help.`,
223
+ logout: `flypod logout
224
+
225
+ Forget the saved session token. Doesn't affect the server.`,
226
+ list: `flypod list
227
+
228
+ List sites you own (requires login or FLYPOD_TOKEN). Outputs JSON on stdout.`,
229
+ claim: `flypod claim <site_id> <claim_token>
230
+
231
+ Attach an anonymous deploy to your account (requires login or FLYPOD_TOKEN). Outputs JSON on stdout.`,
232
+ comments: `flypod comments <verb> [args]
233
+
234
+ Manage v0.1 comments on a flypod site. All ops talk to the site's host
235
+ (\`DEPLOY_URL\` or the default \`https://flypod.dev\`) over HTTPS.
236
+
237
+ flypod comments mode <anonymous|passcode|approved> --site <id> [--passcode <s>]
238
+ Enable comments and set the access mode.
239
+ flypod comments off --site <id>
240
+ Disable comments (data is preserved).
241
+ flypod comments list <site> [--page <p>] [--open|--resolved|--all] [--limit N] [--json]
242
+ List threads. With --json, prints one thread per line.
243
+ flypod comments show <site> <thread_id> [--json]
244
+ Print a thread with its full comment tree.
245
+ flypod comments post <site> --page <path> --target <json> --body <text> [--json]
246
+ Create a comment. REQUIRES an fau_ token.
247
+ flypod comments resolve <site> <thread_id>
248
+ Mark a thread resolved.
249
+ flypod comments reopen <site> <thread_id>
250
+ Re-open a resolved thread.
251
+ flypod comments webhook set <site> --url <https://...> --secret <s>
252
+ Configure outbound webhooks.
253
+ flypod comments webhook remove <site>
254
+ Stop sending webhooks.
255
+
256
+ Auth:
257
+ Reads FLYPOD_TOKEN (preferred) or your \`flypod login\` session. Write ops
258
+ reject deploy keys (\`fk_\`) with "comments operations require an fau_ token".
259
+ Mint an fau_ token via \`flypod keys create --agent <agent_id>\`.
260
+
261
+ Flags:
262
+ --json Emit JSON on stdout (one thread per line for \`list\`).
263
+ -h, --help Show this help.`,
264
+ install: `flypod install skill [targets] [flags]
265
+
266
+ Teach your coding agents (Claude Code, Codex, Cursor, …) how to deploy with flypod.
267
+
268
+ flypod install skill Interactive picker (TTY).
269
+ flypod install skill --claude Write Claude Code skill.
270
+ flypod install skill --all Write every supported target.
271
+ flypod install skill --global Write to home directory (for AGENTS.md, Claude, Gemini).
272
+ flypod install skill --list Print detected targets without writing.
273
+ flypod install skill --dry-run Show what would be written.
274
+ flypod install skill --yes Skip interactive confirmation.
275
+
276
+ Targets:
277
+ --agents AGENTS.md (Codex, Cursor, Copilot, Gemini, Windsurf, +more)
278
+ --claude Claude Code (.claude/skills/flypod/SKILL.md)
279
+ --cursor Cursor (.cursor/rules/flypod.mdc)
280
+ --copilot GitHub Copilot (.github/copilot-instructions.md)
281
+ --windsurf Windsurf (.windsurf/rules/flypod.md)
282
+ --cline Cline (.clinerules/flypod.md)
283
+ --roo Roo Code (.roo/rules/flypod.md)
284
+ --gemini Gemini CLI (GEMINI.md)
285
+
286
+ Flags:
287
+ --all Write every supported target.
288
+ --global Write to home directory instead of project root.
289
+ --list Print detected targets without writing.
290
+ --dry-run Show what would be written (alias: --print).
291
+ --yes, -y Skip the interactive picker.
292
+ -h, --help Show this help.`
293
+ };
294
+ function showSubHelp(name, io) {
295
+ const help = SUBCOMMAND_HELP[name];
296
+ if (help)
297
+ io.err(help);
298
+ else
299
+ io.err(`No help available for "${name}". Run \`flypod --help\` for usage.`);
300
+ }
301
+ function failJson(error, io) {
302
+ io.out(JSON.stringify({ ok: false, error }));
303
+ return 1;
304
+ }
305
+ var DEVICE_CLIENT_ID = "flypod-cli";
306
+ var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
162
307
  var POLL_MAX_ATTEMPTS = 120;
163
- async function login(_args, io) {
308
+ async function login(args, io) {
309
+ if (args.help) {
310
+ showSubHelp("login", io);
311
+ return 0;
312
+ }
164
313
  const env = io.env ?? process.env;
165
314
  const baseUrl = baseUrlFrom(env);
315
+ if (args.token) {
316
+ await saveSession({ session_token: args.token, base_url: baseUrl, created_at: Date.now() }, env);
317
+ io.err("Logged in.");
318
+ await attachAnonymousSites(args.token, baseUrl, io, env);
319
+ return 0;
320
+ }
166
321
  const fetchImpl = io.fetch ?? fetch;
167
- const openUrl = io.openUrl ?? openBrowser;
168
- const startRes = await fetchImpl(`${baseUrl}/auth/device`, { method: "POST" });
322
+ const startRes = await fetchImpl(`${baseUrl}/api/auth/device/code`, {
323
+ method: "POST",
324
+ headers: { "content-type": "application/json" },
325
+ body: JSON.stringify({ client_id: DEVICE_CLIENT_ID })
326
+ });
169
327
  if (!startRes.ok) {
170
328
  io.err(`flypod login: server returned ${startRes.status}. Is the server running?`);
171
329
  return 1;
172
330
  }
173
- const { device_code, user_code, verification_uri, interval } = await startRes.json();
174
- const confirmUrl = `${verification_uri}?code=${user_code}`;
331
+ const start = await startRes.json();
332
+ const openUrl = start.verification_uri_complete ?? `${start.verification_uri}?user_code=${encodeURIComponent(start.user_code)}`;
175
333
  io.err("");
176
- io.err(` Opening browser to complete sign-in...`);
177
- io.err(` ${confirmUrl}`);
334
+ io.err(` Open this URL in your browser to sign in:`);
335
+ io.err(` ${openUrl}`);
178
336
  io.err("");
179
- io.err(` Confirmation code: ${user_code}`);
337
+ io.err(` Confirmation code: ${start.user_code}`);
180
338
  io.err("");
181
- await openUrl(confirmUrl);
182
- const pollMs = (interval ?? 5) * 1000;
339
+ let pollMs = (start.interval ?? 5) * 1000;
183
340
  for (let attempt = 0;attempt < POLL_MAX_ATTEMPTS; attempt++) {
184
- await new Promise((r) => setTimeout(r, attempt === 0 ? pollMs : pollMs));
185
- const pollRes = await fetchImpl(`${baseUrl}/auth/device/token`, {
341
+ await new Promise((r) => setTimeout(r, pollMs));
342
+ const pollRes = await fetchImpl(`${baseUrl}/api/auth/device/token`, {
186
343
  method: "POST",
187
344
  headers: { "content-type": "application/json" },
188
- body: JSON.stringify({ device_code })
345
+ body: JSON.stringify({
346
+ grant_type: DEVICE_GRANT_TYPE,
347
+ device_code: start.device_code,
348
+ client_id: DEVICE_CLIENT_ID
349
+ })
189
350
  });
190
- if (pollRes.status === 202)
351
+ if (pollRes.ok) {
352
+ const { access_token } = await pollRes.json();
353
+ await saveSession({ session_token: access_token, base_url: baseUrl, created_at: Date.now() }, env);
354
+ io.err("Logged in.");
355
+ await attachAnonymousSites(access_token, baseUrl, io, env);
356
+ return 0;
357
+ }
358
+ const body = await pollRes.json().catch(() => ({}));
359
+ if (body.error === "authorization_pending")
191
360
  continue;
192
- if (!pollRes.ok) {
193
- const body = await pollRes.json().catch(() => ({}));
194
- if (body.error === "denied") {
195
- io.err("Authorization denied in browser.");
196
- return 1;
197
- }
198
- if (body.error === "expired") {
199
- io.err("Code expired. Run `flypod login` to try again.");
200
- return 1;
201
- }
202
- io.err(`flypod login: unexpected error ${pollRes.status}.`);
361
+ if (body.error === "slow_down") {
362
+ pollMs += 5000;
363
+ continue;
364
+ }
365
+ if (body.error === "access_denied") {
366
+ io.err("Authorization denied in browser.");
203
367
  return 1;
204
368
  }
205
- const { api_key } = await pollRes.json();
206
- const path = await saveSession({ api_key, base_url: baseUrl, created_at: Date.now() }, env);
207
- io.err(`Logged in. Session saved to ${path}`);
208
- return 0;
369
+ if (body.error === "expired_token") {
370
+ io.err("Code expired. Run `flypod login` to try again.");
371
+ return 1;
372
+ }
373
+ io.err(`flypod login: unexpected error ${pollRes.status}.`);
374
+ return 1;
209
375
  }
210
376
  io.err("Timed out waiting for browser authorization. Run `flypod login` to try again.");
211
377
  return 1;
212
378
  }
379
+ async function attachAnonymousSites(apiKey, baseUrl, io, env) {
380
+ const projects = await loadProjects(env);
381
+ const candidates = Object.entries(projects).filter(([, rec]) => rec.base_url === baseUrl && rec.expires_at !== null && typeof rec.manage_token === "string");
382
+ if (candidates.length === 0)
383
+ return;
384
+ const noun = candidates.length === 1 ? "site" : "sites";
385
+ io.err(`Found ${candidates.length} anonymous ${noun} on this machine.`);
386
+ io.err(` Attaching to your account…`);
387
+ const fetchImpl = io.fetch ?? fetch;
388
+ const res = await fetchImpl(`${baseUrl}/account/bulk-attach`, {
389
+ method: "POST",
390
+ headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
391
+ body: JSON.stringify({
392
+ sites: candidates.map(([, rec]) => ({
393
+ site_id: rec.site_id,
394
+ manage_token: rec.manage_token
395
+ }))
396
+ })
397
+ });
398
+ if (!res.ok) {
399
+ io.err(` Could not attach (${res.status}). Try again later.`);
400
+ return;
401
+ }
402
+ const body = await res.json().catch(() => ({}));
403
+ const attached = new Set(body.attached ?? []);
404
+ const skipped = body.skipped ?? [];
405
+ if (attached.size > 0) {
406
+ for (const [dir, rec] of candidates) {
407
+ if (attached.has(rec.site_id)) {
408
+ projects[dir] = { ...rec, expires_at: null };
409
+ }
410
+ }
411
+ await saveProjects(projects, env);
412
+ }
413
+ if (attached.size > 0) {
414
+ const word = attached.size === 1 ? "site" : "sites";
415
+ io.err(` Attached ${attached.size} ${word}.`);
416
+ }
417
+ if (skipped.length > 0) {
418
+ io.err(` Skipped ${skipped.length} (already owned or expired).`);
419
+ }
420
+ }
213
421
  async function logout(_args, io) {
214
422
  const env = io.env ?? process.env;
215
423
  const ok = await clearSession(env);
@@ -222,13 +430,15 @@ async function logout(_args, io) {
222
430
  async function list(_args, io) {
223
431
  const env = io.env ?? process.env;
224
432
  const session = await loadSession(env);
225
- if (!session) {
226
- io.err("Not signed in. Run `flypod login` first.");
433
+ const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
434
+ const baseUrl = session?.base_url ?? baseUrlFrom(env);
435
+ if (!apiKey) {
436
+ io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
227
437
  return 1;
228
438
  }
229
439
  const fetchImpl = io.fetch ?? fetch;
230
- const res = await fetchImpl(`${session.base_url}/account/sites`, {
231
- headers: { authorization: `Bearer ${session.api_key}` }
440
+ const res = await fetchImpl(`${baseUrl}/account/sites`, {
441
+ headers: { authorization: `Bearer ${apiKey}` }
232
442
  });
233
443
  if (!res.ok) {
234
444
  io.err(`flypod list: server returned ${res.status}.`);
@@ -240,15 +450,16 @@ async function list(_args, io) {
240
450
  io.err("No sites yet. Run `flypod` in a folder to deploy one.");
241
451
  return 0;
242
452
  }
243
- for (const site of sites)
244
- io.out(`${site.site_id} ${site.url}`);
453
+ io.out(JSON.stringify({ ok: true, sites }));
245
454
  return 0;
246
455
  }
247
456
  async function claim(args, io) {
248
457
  const env = io.env ?? process.env;
249
458
  const session = await loadSession(env);
250
- if (!session) {
251
- io.err("Not signed in. Run `flypod login` first.");
459
+ const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
460
+ const baseUrl = session?.base_url ?? baseUrlFrom(env);
461
+ if (!apiKey) {
462
+ io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
252
463
  return 1;
253
464
  }
254
465
  if (!args.site_id || !args.token) {
@@ -256,11 +467,11 @@ async function claim(args, io) {
256
467
  return 2;
257
468
  }
258
469
  const fetchImpl = io.fetch ?? fetch;
259
- const res = await fetchImpl(`${session.base_url}/sites/${args.site_id}/claim`, {
470
+ const res = await fetchImpl(`${baseUrl}/sites/${args.site_id}/claim`, {
260
471
  method: "POST",
261
472
  headers: {
262
473
  "content-type": "application/json",
263
- authorization: `Bearer ${session.api_key}`
474
+ authorization: `Bearer ${apiKey}`
264
475
  },
265
476
  body: JSON.stringify({ claim_token: args.token })
266
477
  });
@@ -269,31 +480,10 @@ async function claim(args, io) {
269
480
  return 1;
270
481
  }
271
482
  const body = await res.json();
272
- io.out(body.site_id);
483
+ io.out(JSON.stringify({ ok: true, site_id: body.site_id, owner_account_id: body.owner_account_id }));
273
484
  io.err(`Claimed. Owned by ${body.owner_account_id}.`);
274
485
  return 0;
275
486
  }
276
- async function keysCreate(_args, io) {
277
- const env = io.env ?? process.env;
278
- const session = await loadSession(env);
279
- if (!session) {
280
- io.err("Not signed in. Run `flypod login` first.");
281
- return 1;
282
- }
283
- const fetchImpl = io.fetch ?? fetch;
284
- const res = await fetchImpl(`${session.base_url}/account/api-keys`, {
285
- method: "POST",
286
- headers: { authorization: `Bearer ${session.api_key}` }
287
- });
288
- if (!res.ok) {
289
- io.err(`flypod keys create: server returned ${res.status}.`);
290
- return 1;
291
- }
292
- const body = await res.json();
293
- io.out(body.api_key);
294
- io.err("Save this now. You will not see it again.");
295
- return 0;
296
- }
297
487
  var NO_SITE = "No flypod site is linked to this folder. Run 'flypod' here to create one, or pass --site <id>.";
298
488
  async function resolveTarget(args, io) {
299
489
  const env = io.env ?? process.env;
@@ -306,7 +496,7 @@ async function resolveTarget(args, io) {
306
496
  async function requestContext(target, args, env) {
307
497
  const session = await loadSession(env);
308
498
  const baseUrl = target.rec?.base_url ?? session?.base_url ?? baseUrlFrom(env);
309
- const auth = args.token ?? target.rec?.manage_token ?? session?.api_key;
499
+ const auth = args.token ?? target.rec?.manage_token ?? env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
310
500
  return { baseUrl, auth };
311
501
  }
312
502
  function authHeaders(auth, extra = {}) {
@@ -344,10 +534,16 @@ async function touchLink(target, version_id, env) {
344
534
  }
345
535
  }
346
536
  async function update(args, io) {
537
+ if (args.help) {
538
+ showSubHelp("update", io);
539
+ return 0;
540
+ }
347
541
  const env = io.env ?? process.env;
348
542
  const cwd = io.cwd ?? process.cwd();
349
543
  const target = await resolveTarget(args, io);
350
544
  if (!target) {
545
+ if (args.json)
546
+ return failJson(NO_SITE, io);
351
547
  io.err(NO_SITE);
352
548
  return 1;
353
549
  }
@@ -355,14 +551,20 @@ async function update(args, io) {
355
551
  try {
356
552
  dir = await resolveDeployDir({ cwd, explicit: args.path });
357
553
  } catch (e) {
358
- io.err(e.message);
554
+ const msg = e.message;
555
+ if (args.json)
556
+ return failJson(msg, io);
557
+ io.err(msg);
359
558
  return 1;
360
559
  }
361
560
  let files;
362
561
  try {
363
562
  files = await collectDist(dir);
364
563
  } catch (e) {
365
- io.err(`Could not read ${dir}: ${e.message}`);
564
+ const msg = `Could not read ${dir}: ${e.message}`;
565
+ if (args.json)
566
+ return failJson(msg, io);
567
+ io.err(msg);
366
568
  return 1;
367
569
  }
368
570
  const { baseUrl, auth } = await requestContext(target, args, env);
@@ -395,14 +597,24 @@ async function update(args, io) {
395
597
  }));
396
598
  return 0;
397
599
  }
600
+ if (args.quiet) {
601
+ io.out(body.url);
602
+ return 0;
603
+ }
398
604
  io.err(`→ version ${body.version_id} is now live`);
399
605
  io.out(body.url);
400
606
  return 0;
401
607
  }
402
608
  async function versions(args, io) {
609
+ if (args.help) {
610
+ showSubHelp("versions", io);
611
+ return 0;
612
+ }
403
613
  const env = io.env ?? process.env;
404
614
  const target = await resolveTarget(args, io);
405
615
  if (!target) {
616
+ if (args.json)
617
+ return failJson(NO_SITE, io);
406
618
  io.err(NO_SITE);
407
619
  return 1;
408
620
  }
@@ -420,9 +632,15 @@ async function versions(args, io) {
420
632
  return 0;
421
633
  }
422
634
  async function rollback(args, io) {
635
+ if (args.help) {
636
+ showSubHelp("rollback", io);
637
+ return 0;
638
+ }
423
639
  const env = io.env ?? process.env;
424
640
  const target = await resolveTarget(args, io);
425
641
  if (!target) {
642
+ if (args.json)
643
+ return failJson(NO_SITE, io);
426
644
  io.err(NO_SITE);
427
645
  return 1;
428
646
  }
@@ -439,20 +657,32 @@ async function rollback(args, io) {
439
657
  else if (prefixed.length === 1)
440
658
  chosen = prefixed[0]?.version_id;
441
659
  else if (prefixed.length === 0) {
442
- io.err(`No version matches '${args.version}'.`);
660
+ const msg = `No version matches '${args.version}'.`;
661
+ if (args.json)
662
+ return failJson(msg, io);
663
+ io.err(msg);
443
664
  return 1;
444
665
  } else {
445
- io.err(`'${args.version}' is ambiguous — it matches ${prefixed.length} versions.`);
666
+ const msg = `'${args.version}' is ambiguous — it matches ${prefixed.length} versions.`;
667
+ if (args.json)
668
+ return failJson(msg, io);
669
+ io.err(msg);
446
670
  return 1;
447
671
  }
448
672
  } else {
449
673
  if (vers.length < 2) {
450
- io.err("Only one version exists — nothing to roll back to.");
674
+ const msg = "Only one version exists — nothing to roll back to.";
675
+ if (args.json)
676
+ return failJson(msg, io);
677
+ io.err(msg);
451
678
  return 1;
452
679
  }
453
680
  const liveIdx = vers.findIndex((v) => v.version_id === live_version_id);
454
681
  if (liveIdx <= 0) {
455
- io.err("Already at the oldest version.");
682
+ const msg = "Already at the oldest version.";
683
+ if (args.json)
684
+ return failJson(msg, io);
685
+ io.err(msg);
456
686
  return 1;
457
687
  }
458
688
  chosen = vers[liveIdx - 1]?.version_id;
@@ -466,23 +696,38 @@ async function rollback(args, io) {
466
696
  });
467
697
  if (res.status === 404) {
468
698
  await healGone(target, io, env);
699
+ if (args.json)
700
+ return failJson(`Site ${target.site_id} not found.`, io);
469
701
  return 1;
470
702
  }
471
703
  if (!res.ok) {
472
- io.err(`flypod rollback: server returned ${res.status}.`);
704
+ const msg = `flypod rollback: server returned ${res.status}.`;
705
+ if (args.json)
706
+ return failJson(msg, io);
707
+ io.err(msg);
473
708
  return 1;
474
709
  }
475
710
  const body = await res.json();
476
711
  await touchLink(target, body.live_version_id, env);
712
+ const url = target.rec?.url ?? siteUrlFrom(target.site_id, baseUrl);
477
713
  if (args.json) {
478
- io.out(JSON.stringify({ ok: true, site_id: target.site_id, live_version_id: body.live_version_id }));
714
+ io.out(JSON.stringify({
715
+ ok: true,
716
+ site_id: target.site_id,
717
+ live_version_id: body.live_version_id,
718
+ url
719
+ }));
479
720
  return 0;
480
721
  }
481
722
  io.err(`→ rolled back to ${body.live_version_id}`);
482
- io.out(body.live_version_id);
723
+ io.out(url);
483
724
  return 0;
484
725
  }
485
726
  async function forget(args, io) {
727
+ if (args.help) {
728
+ showSubHelp("forget", io);
729
+ return 0;
730
+ }
486
731
  const env = io.env ?? process.env;
487
732
  if (args.site) {
488
733
  const n = await forgetSite(args.site, env);
@@ -496,6 +741,411 @@ async function forget(args, io) {
496
741
  return 0;
497
742
  }
498
743
 
744
+ // src/cli/comments.ts
745
+ function baseUrlFrom2(env = process.env) {
746
+ return env.DEPLOY_URL ?? "https://flypod.dev";
747
+ }
748
+ async function resolveCommentToken(env) {
749
+ const session = await loadSession(env);
750
+ const baseUrl = session?.base_url ?? baseUrlFrom2(env);
751
+ const token = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
752
+ return { token, baseUrl };
753
+ }
754
+ function requireFauToken(token, io) {
755
+ if (!token) {
756
+ io.err("Not signed in. Set FLYPOD_TOKEN to an fau_ token, or run `flypod login`.");
757
+ return 3;
758
+ }
759
+ if (token.startsWith("fk_")) {
760
+ io.err("comments operations require an fau_ token");
761
+ return 3;
762
+ }
763
+ return null;
764
+ }
765
+ function authHeaders2(token) {
766
+ return token ? { authorization: `Bearer ${token}` } : {};
767
+ }
768
+ function jsonHeaders(token) {
769
+ return { "content-type": "application/json", ...authHeaders2(token) };
770
+ }
771
+ async function readErrorBody(res) {
772
+ try {
773
+ const body = await res.json();
774
+ if (body?.code)
775
+ return body.code;
776
+ if (body?.error)
777
+ return body.error;
778
+ } catch {}
779
+ return `HTTP ${res.status}`;
780
+ }
781
+ async function commentsMode(args, io) {
782
+ if (!args.mode) {
783
+ io.err("Usage: flypod comments mode <anonymous|passcode|approved> [--site <id>] [--passcode <s>]");
784
+ return 2;
785
+ }
786
+ const allowed = new Set(["anonymous", "passcode", "approved", "open", "review", "members"]);
787
+ if (!allowed.has(args.mode)) {
788
+ io.err(`Unknown mode "${args.mode}". Expected anonymous|passcode|approved.`);
789
+ return 2;
790
+ }
791
+ if (!args.site) {
792
+ io.err("Missing --site <id>.");
793
+ return 2;
794
+ }
795
+ const env = io.env ?? process.env;
796
+ const { token, baseUrl } = await resolveCommentToken(env);
797
+ if (!token) {
798
+ io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
799
+ return 3;
800
+ }
801
+ const fetchImpl = io.fetch ?? fetch;
802
+ const body = { enabled: true, mode: args.mode };
803
+ if (args.passcode)
804
+ body.passcode = args.passcode;
805
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/config`, {
806
+ method: "PUT",
807
+ headers: jsonHeaders(token),
808
+ body: JSON.stringify(body)
809
+ });
810
+ if (!res.ok) {
811
+ io.err(`flypod comments mode: ${await readErrorBody(res)}`);
812
+ return res.status >= 500 ? 4 : 1;
813
+ }
814
+ if (args.json)
815
+ io.out(JSON.stringify({ ok: true, site_id: args.site, mode: args.mode }));
816
+ else
817
+ io.err(`Comments mode set to ${args.mode} on ${args.site}.`);
818
+ return 0;
819
+ }
820
+ async function commentsOff(args, io) {
821
+ if (!args.site) {
822
+ io.err("Missing --site <id>.");
823
+ return 2;
824
+ }
825
+ const env = io.env ?? process.env;
826
+ const { token, baseUrl } = await resolveCommentToken(env);
827
+ if (!token) {
828
+ io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
829
+ return 3;
830
+ }
831
+ const fetchImpl = io.fetch ?? fetch;
832
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/config`, {
833
+ method: "PUT",
834
+ headers: jsonHeaders(token),
835
+ body: JSON.stringify({ enabled: false })
836
+ });
837
+ if (!res.ok) {
838
+ io.err(`flypod comments off: ${await readErrorBody(res)}`);
839
+ return res.status >= 500 ? 4 : 1;
840
+ }
841
+ if (args.json)
842
+ io.out(JSON.stringify({ ok: true, site_id: args.site, enabled: false }));
843
+ else
844
+ io.err(`Comments disabled on ${args.site}.`);
845
+ return 0;
846
+ }
847
+ async function commentsList(args, io) {
848
+ if (!args.site) {
849
+ io.err("Usage: flypod comments list <site> [--page <p>] [--open|--resolved|--all] [--limit N]");
850
+ return 2;
851
+ }
852
+ const env = io.env ?? process.env;
853
+ const { token, baseUrl } = await resolveCommentToken(env);
854
+ const fetchImpl = io.fetch ?? fetch;
855
+ const params = new URLSearchParams;
856
+ if (args.page)
857
+ params.set("page", args.page);
858
+ if (args.status)
859
+ params.set("status", args.status);
860
+ if (args.limit)
861
+ params.set("limit", String(args.limit));
862
+ const qs = params.toString();
863
+ const url = `${baseUrl}/api/comments/${args.site}${qs ? `?${qs}` : ""}`;
864
+ const res = await fetchImpl(url, { headers: authHeaders2(token) });
865
+ if (!res.ok) {
866
+ io.err(`flypod comments list: ${await readErrorBody(res)}`);
867
+ return res.status >= 500 ? 4 : 1;
868
+ }
869
+ const body = await res.json();
870
+ const threads = Array.isArray(body.threads) ? body.threads : [];
871
+ if (args.json) {
872
+ for (const t of threads)
873
+ io.out(JSON.stringify(t));
874
+ } else {
875
+ io.err(`${threads.length} thread${threads.length === 1 ? "" : "s"}.`);
876
+ for (const t of threads)
877
+ io.out(JSON.stringify(t));
878
+ }
879
+ return 0;
880
+ }
881
+ async function commentsShow(args, io) {
882
+ if (!args.site || !args.thread_id) {
883
+ io.err("Usage: flypod comments show <site> <thread_id>");
884
+ return 2;
885
+ }
886
+ const env = io.env ?? process.env;
887
+ const { token, baseUrl } = await resolveCommentToken(env);
888
+ const fetchImpl = io.fetch ?? fetch;
889
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/threads/${args.thread_id}`, {
890
+ headers: authHeaders2(token)
891
+ });
892
+ if (!res.ok) {
893
+ io.err(`flypod comments show: ${await readErrorBody(res)}`);
894
+ return res.status >= 500 ? 4 : 1;
895
+ }
896
+ const body = await res.json();
897
+ io.out(JSON.stringify(body));
898
+ return 0;
899
+ }
900
+ async function commentsPost(args, io) {
901
+ if (!args.site || !args.page || !args.target || !args.body) {
902
+ io.err("Usage: flypod comments post <site> --page <path> --target <json> --body <text>");
903
+ return 2;
904
+ }
905
+ const env = io.env ?? process.env;
906
+ const { token, baseUrl } = await resolveCommentToken(env);
907
+ const reject = requireFauToken(token, io);
908
+ if (reject !== null)
909
+ return reject;
910
+ let target;
911
+ try {
912
+ target = JSON.parse(args.target);
913
+ } catch {
914
+ io.err("Invalid --target JSON.");
915
+ return 2;
916
+ }
917
+ const fetchImpl = io.fetch ?? fetch;
918
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}`, {
919
+ method: "POST",
920
+ headers: jsonHeaders(token),
921
+ body: JSON.stringify({ page_path: args.page, anchor: target, body: args.body })
922
+ });
923
+ if (!res.ok) {
924
+ io.err(`flypod comments post: ${await readErrorBody(res)}`);
925
+ return res.status >= 500 ? 4 : res.status === 401 || res.status === 403 ? 3 : 1;
926
+ }
927
+ const body = await res.json();
928
+ io.out(JSON.stringify(body));
929
+ return 0;
930
+ }
931
+ async function setThreadStatus(endpoint, args, io) {
932
+ if (!args.site || !args.thread_id) {
933
+ io.err(`Usage: flypod comments ${endpoint} <site> <thread_id>`);
934
+ return 2;
935
+ }
936
+ const env = io.env ?? process.env;
937
+ const { token, baseUrl } = await resolveCommentToken(env);
938
+ const reject = requireFauToken(token, io);
939
+ if (reject !== null)
940
+ return reject;
941
+ const fetchImpl = io.fetch ?? fetch;
942
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/threads/${args.thread_id}/${endpoint}`, { method: "POST", headers: jsonHeaders(token) });
943
+ if (!res.ok) {
944
+ io.err(`flypod comments ${endpoint}: ${await readErrorBody(res)}`);
945
+ return res.status >= 500 ? 4 : res.status === 401 || res.status === 403 ? 3 : 1;
946
+ }
947
+ const body = await res.json().catch(() => ({}));
948
+ if (args.json)
949
+ io.out(JSON.stringify({ ok: true, ...body }));
950
+ else
951
+ io.err(`Thread ${args.thread_id} ${endpoint === "resolve" ? "resolved" : "reopened"}.`);
952
+ return 0;
953
+ }
954
+ function commentsResolve(args, io) {
955
+ return setThreadStatus("resolve", args, io);
956
+ }
957
+ function commentsReopen(args, io) {
958
+ return setThreadStatus("reopen", args, io);
959
+ }
960
+ async function commentsWebhookSet(args, io) {
961
+ if (!args.site || !args.url || !args.secret) {
962
+ io.err("Usage: flypod comments webhook set <site> --url <https://...> --secret <s>");
963
+ return 2;
964
+ }
965
+ const env = io.env ?? process.env;
966
+ const { token, baseUrl } = await resolveCommentToken(env);
967
+ if (!token) {
968
+ io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
969
+ return 3;
970
+ }
971
+ const fetchImpl = io.fetch ?? fetch;
972
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/config`, {
973
+ method: "PUT",
974
+ headers: jsonHeaders(token),
975
+ body: JSON.stringify({ webhook_url: args.url, webhook_secret: args.secret })
976
+ });
977
+ if (!res.ok) {
978
+ io.err(`flypod comments webhook set: ${await readErrorBody(res)}`);
979
+ return res.status >= 500 ? 4 : 1;
980
+ }
981
+ if (args.json)
982
+ io.out(JSON.stringify({ ok: true, site_id: args.site, webhook_url: args.url }));
983
+ else
984
+ io.err(`Webhook set for ${args.site}.`);
985
+ return 0;
986
+ }
987
+ async function commentsWebhookRemove(args, io) {
988
+ if (!args.site) {
989
+ io.err("Usage: flypod comments webhook remove <site>");
990
+ return 2;
991
+ }
992
+ const env = io.env ?? process.env;
993
+ const { token, baseUrl } = await resolveCommentToken(env);
994
+ if (!token) {
995
+ io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
996
+ return 3;
997
+ }
998
+ const fetchImpl = io.fetch ?? fetch;
999
+ const res = await fetchImpl(`${baseUrl}/api/comments/${args.site}/config`, {
1000
+ method: "PUT",
1001
+ headers: jsonHeaders(token),
1002
+ body: JSON.stringify({ webhook_url: null, webhook_secret: null })
1003
+ });
1004
+ if (!res.ok) {
1005
+ io.err(`flypod comments webhook remove: ${await readErrorBody(res)}`);
1006
+ return res.status >= 500 ? 4 : 1;
1007
+ }
1008
+ if (args.json)
1009
+ io.out(JSON.stringify({ ok: true, site_id: args.site, webhook_url: null }));
1010
+ else
1011
+ io.err(`Webhook removed for ${args.site}.`);
1012
+ return 0;
1013
+ }
1014
+ async function commentsEnable(args, io) {
1015
+ if (!args.site) {
1016
+ io.err("Usage: flypod comments enable --site <id> [--mode anonymous|passcode|approved] [--passcode <s>]");
1017
+ return 2;
1018
+ }
1019
+ return commentsMode({ mode: args.mode ?? "anonymous", site: args.site, passcode: args.passcode, json: args.json }, io);
1020
+ }
1021
+ async function commentsCommand(argv, io) {
1022
+ if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
1023
+ io.err("Usage: flypod comments <enable|mode|off|list|show|post|resolve|reopen|webhook> [args]");
1024
+ return argv[0] === "-h" || argv[0] === "--help" ? 0 : 2;
1025
+ }
1026
+ const verb = argv[0];
1027
+ const rest = argv.slice(1);
1028
+ function parseFlags(tail) {
1029
+ const out = { positionals: [], json: false };
1030
+ for (let i = 0;i < tail.length; i++) {
1031
+ const a = tail[i];
1032
+ const eat = () => tail[++i];
1033
+ if (a === "--site")
1034
+ out.site = eat();
1035
+ else if (a.startsWith("--site="))
1036
+ out.site = a.slice("--site=".length);
1037
+ else if (a === "--mode")
1038
+ out.mode = eat();
1039
+ else if (a.startsWith("--mode="))
1040
+ out.mode = a.slice("--mode=".length);
1041
+ else if (a === "--page")
1042
+ out.page = eat();
1043
+ else if (a.startsWith("--page="))
1044
+ out.page = a.slice("--page=".length);
1045
+ else if (a === "--target")
1046
+ out.target = eat();
1047
+ else if (a.startsWith("--target="))
1048
+ out.target = a.slice("--target=".length);
1049
+ else if (a === "--body")
1050
+ out.body = eat();
1051
+ else if (a.startsWith("--body="))
1052
+ out.body = a.slice("--body=".length);
1053
+ else if (a === "--url")
1054
+ out.url = eat();
1055
+ else if (a.startsWith("--url="))
1056
+ out.url = a.slice("--url=".length);
1057
+ else if (a === "--secret")
1058
+ out.secret = eat();
1059
+ else if (a.startsWith("--secret="))
1060
+ out.secret = a.slice("--secret=".length);
1061
+ else if (a === "--passcode")
1062
+ out.passcode = eat();
1063
+ else if (a.startsWith("--passcode="))
1064
+ out.passcode = a.slice("--passcode=".length);
1065
+ else if (a === "--limit") {
1066
+ const v = eat();
1067
+ if (v)
1068
+ out.limit = Number(v);
1069
+ } else if (a.startsWith("--limit=")) {
1070
+ out.limit = Number(a.slice("--limit=".length));
1071
+ } else if (a === "--open")
1072
+ out.status = "open";
1073
+ else if (a === "--resolved")
1074
+ out.status = "resolved";
1075
+ else if (a === "--all")
1076
+ out.status = "all";
1077
+ else if (a === "--json")
1078
+ out.json = true;
1079
+ else if (!a.startsWith("-"))
1080
+ out.positionals.push(a);
1081
+ }
1082
+ return out;
1083
+ }
1084
+ switch (verb) {
1085
+ case "enable": {
1086
+ const f = parseFlags(rest);
1087
+ const site = f.site ?? f.positionals[0];
1088
+ return commentsEnable({ site, mode: f.mode, passcode: f.passcode, json: f.json }, io);
1089
+ }
1090
+ case "mode": {
1091
+ const f = parseFlags(rest);
1092
+ const mode = f.positionals[0];
1093
+ const site = f.site ?? f.positionals[1];
1094
+ return commentsMode({ mode, site, passcode: f.passcode, json: f.json }, io);
1095
+ }
1096
+ case "off": {
1097
+ const f = parseFlags(rest);
1098
+ const site = f.site ?? f.positionals[0];
1099
+ return commentsOff({ site, json: f.json }, io);
1100
+ }
1101
+ case "list": {
1102
+ const f = parseFlags(rest);
1103
+ const site = f.positionals[0] ?? f.site;
1104
+ return commentsList({ site, page: f.page, status: f.status, limit: f.limit, json: f.json }, io);
1105
+ }
1106
+ case "show": {
1107
+ const f = parseFlags(rest);
1108
+ const site = f.positionals[0];
1109
+ const thread_id = f.positionals[1];
1110
+ return commentsShow({ site, thread_id, json: f.json }, io);
1111
+ }
1112
+ case "post": {
1113
+ const f = parseFlags(rest);
1114
+ const site = f.positionals[0] ?? f.site;
1115
+ return commentsPost({ site, page: f.page, target: f.target, body: f.body, json: f.json }, io);
1116
+ }
1117
+ case "resolve": {
1118
+ const f = parseFlags(rest);
1119
+ const site = f.positionals[0];
1120
+ const thread_id = f.positionals[1];
1121
+ return commentsResolve({ site, thread_id, json: f.json }, io);
1122
+ }
1123
+ case "reopen": {
1124
+ const f = parseFlags(rest);
1125
+ const site = f.positionals[0];
1126
+ const thread_id = f.positionals[1];
1127
+ return commentsReopen({ site, thread_id, json: f.json }, io);
1128
+ }
1129
+ case "webhook": {
1130
+ const sub = rest[0];
1131
+ const tail = rest.slice(1);
1132
+ const f = parseFlags(tail);
1133
+ const site = f.positionals[0] ?? f.site;
1134
+ if (sub === "set") {
1135
+ return commentsWebhookSet({ site, url: f.url, secret: f.secret, json: f.json }, io);
1136
+ }
1137
+ if (sub === "remove") {
1138
+ return commentsWebhookRemove({ site, json: f.json }, io);
1139
+ }
1140
+ io.err("Usage: flypod comments webhook <set|remove> <site> [flags]");
1141
+ return 2;
1142
+ }
1143
+ default:
1144
+ io.err(`flypod comments: unknown verb "${verb}"`);
1145
+ return 2;
1146
+ }
1147
+ }
1148
+
499
1149
  // src/cli/select.ts
500
1150
  var ESC = "\x1B[";
501
1151
  function canPrompt(input = process.stdin, output = process.stderr) {
@@ -663,29 +1313,25 @@ ${sub} Anonymous vs. signed in
663
1313
  - **Anonymous (default):** zero auth. The first deploy just works and the site
664
1314
  expires in ~14 days. Best for previews and throwaways.
665
1315
  - **Signed in:** deploys are attributed to an account, never expire, and show up
666
- in \`flypod list\`. Sign in once (no interactive prompt):
1316
+ in \`flypod list\`. Sign in once via the browser:
667
1317
 
668
1318
  \`\`\`sh
669
- flypod login --key fk_xxxxxxxxxxxxxxxxxxxx
1319
+ flypod login
670
1320
  \`\`\`
671
1321
 
672
- For agents and CI, skip the session file entirely — set the key in the
1322
+ For agents and CI, skip the session file entirely — set a session token in the
673
1323
  environment and every deploy is attributed to the account:
674
1324
 
675
1325
  \`\`\`sh
676
- FLYPOD_API_KEY=fk_xxxxxxxxxxxxxxxxxxxx npx flypod ./dist --json
1326
+ FLYPOD_TOKEN=<session-token> npx flypod ./dist --json
677
1327
  \`\`\`
678
1328
 
679
- Mint a key at https://flypod.dev/account, or run \`flypod keys create\` when
680
- already signed in.
681
-
682
1329
  ${sub} Other commands
683
1330
 
684
1331
  \`\`\`sh
685
1332
  flypod list # sites you own (requires sign in)
686
1333
  flypod claim <site_id> <token> # attach an anonymous deploy to your account
687
- flypod keys create # mint an API key for agents / CI
688
- flypod logout # forget the saved key
1334
+ flypod logout # forget the saved session token
689
1335
  flypod --help # full usage
690
1336
  \`\`\`
691
1337
 
@@ -1065,8 +1711,8 @@ var SUBCOMMANDS = new Set([
1065
1711
  "logout",
1066
1712
  "list",
1067
1713
  "claim",
1068
- "keys",
1069
- "install"
1714
+ "install",
1715
+ "comments"
1070
1716
  ]);
1071
1717
  var TARGET_FLAGS = {
1072
1718
  "--agents": "agents",
@@ -1080,8 +1726,16 @@ var TARGET_FLAGS = {
1080
1726
  "--gemini": "gemini"
1081
1727
  };
1082
1728
  function parseArgs(argv) {
1083
- const out = { json: false, quiet: false, help: false, version: false };
1084
- for (const a of argv) {
1729
+ const out = {
1730
+ json: false,
1731
+ quiet: false,
1732
+ help: false,
1733
+ version: false,
1734
+ comments: false,
1735
+ commentsMode: "anonymous"
1736
+ };
1737
+ for (let i = 0;i < argv.length; i++) {
1738
+ const a = argv[i];
1085
1739
  if (a === "--json")
1086
1740
  out.json = true;
1087
1741
  else if (a === "-q" || a === "--quiet")
@@ -1090,6 +1744,12 @@ function parseArgs(argv) {
1090
1744
  out.help = true;
1091
1745
  else if (a === "-v" || a === "--version")
1092
1746
  out.version = true;
1747
+ else if (a === "--comments")
1748
+ out.comments = true;
1749
+ else if (a === "--mode" && i + 1 < argv.length)
1750
+ out.commentsMode = argv[++i];
1751
+ else if (a.startsWith("--mode="))
1752
+ out.commentsMode = a.slice("--mode=".length);
1093
1753
  else if (a.startsWith("-")) {
1094
1754
  process.stderr.write(`flypod: unknown flag "${a}"
1095
1755
  Run \`flypod --help\` for usage.
@@ -1106,13 +1766,14 @@ function parseSub(argv) {
1106
1766
  let token;
1107
1767
  let json = false;
1108
1768
  let quiet = false;
1769
+ let help = false;
1109
1770
  for (let i = 0;i < argv.length; i++) {
1110
1771
  const a = argv[i];
1111
- if (a === "--site")
1772
+ if (a === "--site" && i + 1 < argv.length)
1112
1773
  site = argv[++i];
1113
1774
  else if (a.startsWith("--site="))
1114
1775
  site = a.slice("--site=".length);
1115
- else if (a === "--token")
1776
+ else if (a === "--token" && i + 1 < argv.length)
1116
1777
  token = argv[++i];
1117
1778
  else if (a.startsWith("--token="))
1118
1779
  token = a.slice("--token=".length);
@@ -1120,10 +1781,12 @@ function parseSub(argv) {
1120
1781
  json = true;
1121
1782
  else if (a === "-q" || a === "--quiet")
1122
1783
  quiet = true;
1784
+ else if (a === "-h" || a === "--help")
1785
+ help = true;
1123
1786
  else if (!a.startsWith("-"))
1124
1787
  positionals.push(a);
1125
1788
  }
1126
- return { positionals, site, token, json, quiet };
1789
+ return { positionals, site, token, json, quiet, help };
1127
1790
  }
1128
1791
  async function runSubcommand(name, argv) {
1129
1792
  const io = {
@@ -1134,23 +1797,36 @@ async function runSubcommand(name, argv) {
1134
1797
  };
1135
1798
  switch (name) {
1136
1799
  case "update": {
1137
- const { positionals, site, token, json, quiet } = parseSub(argv);
1138
- return update({ path: positionals[0], site, token, json, quiet }, io);
1800
+ const { positionals, site, token, json, quiet, help } = parseSub(argv);
1801
+ return update({ path: positionals[0], site, token, json, quiet, help }, io);
1139
1802
  }
1140
1803
  case "versions": {
1141
- const { site, token, json } = parseSub(argv);
1142
- return versions({ site, token, json }, io);
1804
+ const { site, token, json, help } = parseSub(argv);
1805
+ return versions({ site, token, json, help }, io);
1143
1806
  }
1144
1807
  case "rollback": {
1145
- const { positionals, site, token, json } = parseSub(argv);
1146
- return rollback({ version: positionals[0], site, token, json }, io);
1808
+ const { positionals, site, token, json, help } = parseSub(argv);
1809
+ return rollback({ version: positionals[0], site, token, json, help }, io);
1147
1810
  }
1148
1811
  case "forget": {
1149
- const { site } = parseSub(argv);
1150
- return forget({ site }, io);
1812
+ const { site, help } = parseSub(argv);
1813
+ return forget({ site, help }, io);
1814
+ }
1815
+ case "login": {
1816
+ let token;
1817
+ let help = false;
1818
+ for (let i = 0;i < argv.length; i++) {
1819
+ if (argv[i] === "--token" && i + 1 < argv.length) {
1820
+ token = argv[i + 1];
1821
+ i++;
1822
+ } else if (argv[i]?.startsWith("--token=")) {
1823
+ token = argv[i]?.slice("--token=".length);
1824
+ } else if (argv[i] === "-h" || argv[i] === "--help") {
1825
+ help = true;
1826
+ }
1827
+ }
1828
+ return login({ token, help }, io);
1151
1829
  }
1152
- case "login":
1153
- return login({}, io);
1154
1830
  case "logout":
1155
1831
  return logout({}, io);
1156
1832
  case "list":
@@ -1159,15 +1835,10 @@ async function runSubcommand(name, argv) {
1159
1835
  const positional = argv.filter((a) => !a.startsWith("-"));
1160
1836
  return claim({ site_id: positional[0], token: positional[1] }, io);
1161
1837
  }
1162
- case "keys": {
1163
- const sub = argv.find((a) => !a.startsWith("-"));
1164
- if (sub === "create")
1165
- return keysCreate({}, io);
1166
- io.err("Usage: flypod keys create");
1167
- return 2;
1168
- }
1169
1838
  case "install":
1170
1839
  return runInstall(argv, io);
1840
+ case "comments":
1841
+ return commentsCommand(argv, io);
1171
1842
  default:
1172
1843
  io.err(`flypod: unknown subcommand "${name}"`);
1173
1844
  return 2;
@@ -1282,24 +1953,48 @@ Targeting (update / versions / rollback):
1282
1953
  machine that doesn't remember it. Owned sites use your login.
1283
1954
 
1284
1955
  Account (optional — lets deploys live forever and be listed/owned):
1285
- flypod login --key fk_... Save an API key; deploys are then yours forever.
1286
- flypod logout Forget the saved API key.
1287
- flypod list List sites you own.
1288
- flypod claim <id> <token> Attach an earlier anonymous deploy to your account.
1289
- flypod keys create Mint a new API key (for agents / CI).
1956
+ flypod login Link this CLI to your flypod account (opens
1957
+ your browser to confirm). Anonymous deploys
1958
+ keep working; logging in just makes future
1959
+ deploys land in your dashboard.
1960
+ flypod login --token <t> Save a session token directly (skip the browser).
1961
+ Or set FLYPOD_TOKEN for agents/CI.
1962
+ flypod logout Forget the saved session token.
1963
+ flypod list List sites you own (JSON on stdout).
1964
+ flypod claim <id> <token> Attach an anonymous deploy to your account.
1290
1965
  flypod forget [--site <id>] Drop this folder's remembered site link.
1291
1966
 
1292
1967
  Agents:
1293
1968
  flypod install skill Teach your coding agents (Claude Code, Codex,
1294
1969
  Cursor, …) how to deploy with flypod.
1295
1970
 
1971
+ Deploy flags:
1972
+ --comments Enable comments on the new site (mode: anonymous).
1973
+ --comments --mode <mode> Same, but choose the mode: anonymous|passcode|
1974
+ approved.
1975
+
1976
+ Comments (v0.1):
1977
+ flypod comments enable --site <id> [--mode anonymous|passcode|approved]
1978
+ Enable comments on an existing site.
1979
+ flypod comments mode <anonymous|passcode|approved> --site <id> [--passcode <s>]
1980
+ Enable comments and set the access mode.
1981
+ flypod comments off --site <id> Disable comments (data preserved).
1982
+ flypod comments list <site> List threads (--json for ND-JSON).
1983
+ flypod comments show <site> <thread_id> Print a thread with replies.
1984
+ flypod comments post <site> --page <p> --target <json> --body <text>
1985
+ Post a comment. Requires fau_ token.
1986
+ flypod comments resolve <site> <thread_id> Mark a thread resolved.
1987
+ flypod comments reopen <site> <thread_id> Re-open a thread.
1988
+ flypod comments webhook set <site> --url <https://...> --secret <s>
1989
+ flypod comments webhook remove <site>
1990
+
1296
1991
  Output:
1297
1992
  --json Emit a stable JSON result on stdout (for agents/scripts).
1298
1993
  -q, --quiet Print only the URL.
1299
1994
  -h, --help Show this help. -v, --version Show the flypod version.
1300
1995
 
1301
1996
  Environment:
1302
- FLYPOD_API_KEY Deploy as your account without logging in (agents / CI)
1997
+ FLYPOD_TOKEN Deploy as your account without logging in (agents / CI)
1303
1998
  DEPLOY_URL Override the deploy server (default: https://flypod.dev)
1304
1999
  FLYPOD_CONFIG_DIR Override where the CLI keeps its session + folder memory
1305
2000
  NO_COLOR Disable ANSI colors
@@ -1310,7 +2005,6 @@ When no path is given, flypod looks for a build folder in the current directory:
1310
2005
  (each must contain an index.html)
1311
2006
 
1312
2007
  Docs: https://flypod.dev
1313
- Source: https://github.com/sdserranog/flypod
1314
2008
  `;
1315
2009
  process.stdout.write(usage);
1316
2010
  }
@@ -1345,6 +2039,11 @@ async function main() {
1345
2039
  ${style.bold(style.accent("flypod"))} ${style.dim(`v${version}`)}
1346
2040
 
1347
2041
  `);
2042
+ if (!apiKey) {
2043
+ process.stderr.write(` ${style.muted("account")} ${style.dim("anonymous · ")}${style.bold("flypod login")}${style.dim(" claims this site to your account")}
2044
+
2045
+ `);
2046
+ }
1348
2047
  }
1349
2048
  let dir;
1350
2049
  try {
@@ -1427,6 +2126,35 @@ async function main() {
1427
2126
  version_id: result.version_id
1428
2127
  });
1429
2128
  } catch {}
2129
+ let commentsEnabled = false;
2130
+ if (args.comments) {
2131
+ if (!apiKey) {
2132
+ if (useUI) {
2133
+ process.stderr.write(` ${style.muted("comments")} ${style.dim("skipped — run `flypod login` to enable comments")}
2134
+ `);
2135
+ }
2136
+ } else {
2137
+ try {
2138
+ const allowed = new Set(["anonymous", "passcode", "approved", "open", "review", "members"]);
2139
+ const mode = allowed.has(args.commentsMode) ? args.commentsMode : "anonymous";
2140
+ const cr = await fetch(`${baseUrl}/api/comments/${result.site_id}/config`, {
2141
+ method: "PUT",
2142
+ headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
2143
+ body: JSON.stringify({ enabled: true, mode })
2144
+ });
2145
+ commentsEnabled = cr.ok;
2146
+ if (useUI) {
2147
+ if (cr.ok) {
2148
+ process.stderr.write(` ${style.muted("comments")} ${style.dim(`enabled (${mode})`)}
2149
+ `);
2150
+ } else {
2151
+ process.stderr.write(` ${style.muted("comments")} ${style.dim("failed to enable — run `flypod comments enable --site " + result.site_id + "`")}
2152
+ `);
2153
+ }
2154
+ }
2155
+ } catch {}
2156
+ }
2157
+ }
1430
2158
  if (args.json) {
1431
2159
  process.stdout.write(`${JSON.stringify({
1432
2160
  ok: true,
@@ -1440,7 +2168,8 @@ async function main() {
1440
2168
  source: shortDir(dir),
1441
2169
  files: fileNames.length,
1442
2170
  bytes: totalBytes,
1443
- elapsed_ms: elapsed
2171
+ elapsed_ms: elapsed,
2172
+ ...args.comments ? { comments_enabled: commentsEnabled, comments_mode: args.commentsMode } : {}
1444
2173
  }, null, 2)}
1445
2174
  `);
1446
2175
  return;
@@ -1463,7 +2192,7 @@ async function main() {
1463
2192
  process.stderr.write(` ${rule}
1464
2193
 
1465
2194
  `);
1466
- const expiry = typeof result.expires_at === "number" ? `in ${Math.max(0, Math.round((result.expires_at - Date.now()) / 86400000))} days . ephemeral by default` : result.owner_account_id ? `never . owned by you (${result.owner_account_id})` : "never (claimed)";
2195
+ const expiry = typeof result.expires_at === "number" ? `in ${Math.max(0, Math.round((result.expires_at - Date.now()) / 86400000))} days . run \`flypod login\` to claim this site to your account` : result.owner_account_id ? "never . attributed to your account" : "never (claimed)";
1467
2196
  process.stderr.write(` ${style.muted("expires")} ${style.dim(expiry)}
1468
2197
 
1469
2198
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flypod",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Zero-auth deploy primitive. Turns any folder into a live URL in one command. For AI agents and humans.",
5
5
  "module": "src/cli.ts",
6
6
  "type": "module",
@@ -34,12 +34,16 @@
34
34
  "scripts": {
35
35
  "build": "rm -rf dist && bun build src/cli.ts bin/deploy.ts --outdir dist --target node --splitting",
36
36
  "prepublishOnly": "bun run build",
37
- "test": "bun test",
37
+ "test": "bun run test:unit && bun run test:bdd",
38
+ "test:unit": "bun test --test-name-pattern='^(?!.*BDD).*' $(find test -name '*.test.ts' ! -path 'test/comments/bdd.test.ts')",
39
+ "test:bdd": "bun test test/comments/bdd.test.ts",
38
40
  "typecheck": "tsc --noEmit",
39
41
  "deploy": "wrangler deploy",
40
42
  "dev": "bun --hot index.ts"
41
43
  },
42
44
  "dependencies": {
45
+ "@flypod/comments": "workspace:*",
46
+ "@modelcontextprotocol/sdk": "^1.20.2",
43
47
  "fflate": "^0.8.3"
44
48
  },
45
49
  "devDependencies": {
@@ -50,6 +54,7 @@
50
54
  "hono": "^4.12.25",
51
55
  "marked": "^18.0.5",
52
56
  "playwright": "^1.60.0",
57
+ "quickpickle": "^1.7.0",
53
58
  "typescript": "^6.0.3",
54
59
  "wrangler": "^4.0.0"
55
60
  },