flypod 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin/deploy.js +622 -103
  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;
@@ -212,26 +212,55 @@ Flags:
212
212
  -h, --help Show this help.`,
213
213
  login: `flypod login [flags]
214
214
 
215
- Authenticate with flypod.
215
+ Authenticate with flypod via the browser (device authorization).
216
216
 
217
- flypod login Start the device-flow sign-in (open a browser).
218
- flypod login --key fk_... Save an API key directly (for agents/CI).
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
219
 
220
220
  Flags:
221
- --key fk_... Save this API key (minted at flypod.dev/account).
221
+ --token <t> Save this session token instead of opening a browser.
222
222
  -h, --help Show this help.`,
223
223
  logout: `flypod logout
224
224
 
225
- Forget the saved API key. Doesn't affect the server.`,
225
+ Forget the saved session token. Doesn't affect the server.`,
226
226
  list: `flypod list
227
227
 
228
- List sites you own (requires login or FLYPOD_API_KEY). Outputs JSON on stdout.`,
228
+ List sites you own (requires login or FLYPOD_TOKEN). Outputs JSON on stdout.`,
229
229
  claim: `flypod claim <site_id> <claim_token>
230
230
 
231
- Attach an anonymous deploy to your account (requires login or FLYPOD_API_KEY). Outputs JSON on stdout.`,
232
- keys: `flypod keys create
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>\`.
233
260
 
234
- Mint a new API key for agents / CI (requires login or FLYPOD_API_KEY). Outputs JSON on stdout.`,
261
+ Flags:
262
+ --json Emit JSON on stdout (one thread per line for \`list\`).
263
+ -h, --help Show this help.`,
235
264
  install: `flypod install skill [targets] [flags]
236
265
 
237
266
  Teach your coding agents (Claude Code, Codex, Cursor, …) how to deploy with flypod.
@@ -273,6 +302,8 @@ function failJson(error, io) {
273
302
  io.out(JSON.stringify({ ok: false, error }));
274
303
  return 1;
275
304
  }
305
+ var DEVICE_CLIENT_ID = "flypod-cli";
306
+ var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
276
307
  var POLL_MAX_ATTEMPTS = 120;
277
308
  async function login(args, io) {
278
309
  if (args.help) {
@@ -281,60 +312,112 @@ async function login(args, io) {
281
312
  }
282
313
  const env = io.env ?? process.env;
283
314
  const baseUrl = baseUrlFrom(env);
284
- if (args.key) {
285
- if (!args.key.startsWith("fk_") || args.key.length < 20) {
286
- io.err("Invalid key. Expected fk_ followed by at least 16 characters.");
287
- return 2;
288
- }
289
- await saveSession({ api_key: args.key, base_url: baseUrl, created_at: Date.now() }, env);
315
+ if (args.token) {
316
+ await saveSession({ session_token: args.token, base_url: baseUrl, created_at: Date.now() }, env);
290
317
  io.err("Logged in.");
318
+ await attachAnonymousSites(args.token, baseUrl, io, env);
291
319
  return 0;
292
320
  }
293
321
  const fetchImpl = io.fetch ?? fetch;
294
- 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
+ });
295
327
  if (!startRes.ok) {
296
328
  io.err(`flypod login: server returned ${startRes.status}. Is the server running?`);
297
329
  return 1;
298
330
  }
299
- const { device_code, user_code, verification_uri, interval } = await startRes.json();
300
- 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)}`;
301
333
  io.err("");
302
334
  io.err(` Open this URL in your browser to sign in:`);
303
- io.err(` ${confirmUrl}`);
335
+ io.err(` ${openUrl}`);
304
336
  io.err("");
305
- io.err(` Confirmation code: ${user_code}`);
337
+ io.err(` Confirmation code: ${start.user_code}`);
306
338
  io.err("");
307
- const pollMs = (interval ?? 5) * 1000;
339
+ let pollMs = (start.interval ?? 5) * 1000;
308
340
  for (let attempt = 0;attempt < POLL_MAX_ATTEMPTS; attempt++) {
309
341
  await new Promise((r) => setTimeout(r, pollMs));
310
- const pollRes = await fetchImpl(`${baseUrl}/auth/device/token`, {
342
+ const pollRes = await fetchImpl(`${baseUrl}/api/auth/device/token`, {
311
343
  method: "POST",
312
344
  headers: { "content-type": "application/json" },
313
- 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
+ })
314
350
  });
315
- 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")
316
360
  continue;
317
- if (!pollRes.ok) {
318
- const body = await pollRes.json().catch(() => ({}));
319
- if (body.error === "denied") {
320
- io.err("Authorization denied in browser.");
321
- return 1;
322
- }
323
- if (body.error === "expired") {
324
- io.err("Code expired. Run `flypod login` to try again.");
325
- return 1;
326
- }
327
- 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.");
328
367
  return 1;
329
368
  }
330
- const { api_key } = await pollRes.json();
331
- await saveSession({ api_key, base_url: baseUrl, created_at: Date.now() }, env);
332
- io.err("Logged in.");
333
- 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;
334
375
  }
335
376
  io.err("Timed out waiting for browser authorization. Run `flypod login` to try again.");
336
377
  return 1;
337
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
+ }
338
421
  async function logout(_args, io) {
339
422
  const env = io.env ?? process.env;
340
423
  const ok = await clearSession(env);
@@ -347,10 +430,10 @@ async function logout(_args, io) {
347
430
  async function list(_args, io) {
348
431
  const env = io.env ?? process.env;
349
432
  const session = await loadSession(env);
350
- const apiKey = session?.api_key ?? env.FLYPOD_API_KEY;
433
+ const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
351
434
  const baseUrl = session?.base_url ?? baseUrlFrom(env);
352
435
  if (!apiKey) {
353
- io.err("Not signed in. Run `flypod login` first or set FLYPOD_API_KEY.");
436
+ io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
354
437
  return 1;
355
438
  }
356
439
  const fetchImpl = io.fetch ?? fetch;
@@ -373,10 +456,10 @@ async function list(_args, io) {
373
456
  async function claim(args, io) {
374
457
  const env = io.env ?? process.env;
375
458
  const session = await loadSession(env);
376
- const apiKey = session?.api_key ?? env.FLYPOD_API_KEY;
459
+ const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
377
460
  const baseUrl = session?.base_url ?? baseUrlFrom(env);
378
461
  if (!apiKey) {
379
- io.err("Not signed in. Run `flypod login` first or set FLYPOD_API_KEY.");
462
+ io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
380
463
  return 1;
381
464
  }
382
465
  if (!args.site_id || !args.token) {
@@ -401,29 +484,6 @@ async function claim(args, io) {
401
484
  io.err(`Claimed. Owned by ${body.owner_account_id}.`);
402
485
  return 0;
403
486
  }
404
- async function keysCreate(_args, io) {
405
- const env = io.env ?? process.env;
406
- const session = await loadSession(env);
407
- const apiKey = session?.api_key ?? env.FLYPOD_API_KEY;
408
- const baseUrl = session?.base_url ?? baseUrlFrom(env);
409
- if (!apiKey) {
410
- io.err("Not signed in. Run `flypod login` first or set FLYPOD_API_KEY.");
411
- return 1;
412
- }
413
- const fetchImpl = io.fetch ?? fetch;
414
- const res = await fetchImpl(`${baseUrl}/account/api-keys`, {
415
- method: "POST",
416
- headers: { authorization: `Bearer ${apiKey}` }
417
- });
418
- if (!res.ok) {
419
- io.err(`flypod keys create: server returned ${res.status}.`);
420
- return 1;
421
- }
422
- const body = await res.json();
423
- io.out(JSON.stringify({ ok: true, api_key: body.api_key }));
424
- io.err("Save this now. You will not see it again.");
425
- return 0;
426
- }
427
487
  var NO_SITE = "No flypod site is linked to this folder. Run 'flypod' here to create one, or pass --site <id>.";
428
488
  async function resolveTarget(args, io) {
429
489
  const env = io.env ?? process.env;
@@ -436,7 +496,7 @@ async function resolveTarget(args, io) {
436
496
  async function requestContext(target, args, env) {
437
497
  const session = await loadSession(env);
438
498
  const baseUrl = target.rec?.base_url ?? session?.base_url ?? baseUrlFrom(env);
439
- const auth = args.token ?? target.rec?.manage_token ?? session?.api_key ?? env.FLYPOD_API_KEY;
499
+ const auth = args.token ?? target.rec?.manage_token ?? env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
440
500
  return { baseUrl, auth };
441
501
  }
442
502
  function authHeaders(auth, extra = {}) {
@@ -681,6 +741,411 @@ async function forget(args, io) {
681
741
  return 0;
682
742
  }
683
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
+
684
1149
  // src/cli/select.ts
685
1150
  var ESC = "\x1B[";
686
1151
  function canPrompt(input = process.stdin, output = process.stderr) {
@@ -848,29 +1313,25 @@ ${sub} Anonymous vs. signed in
848
1313
  - **Anonymous (default):** zero auth. The first deploy just works and the site
849
1314
  expires in ~14 days. Best for previews and throwaways.
850
1315
  - **Signed in:** deploys are attributed to an account, never expire, and show up
851
- in \`flypod list\`. Sign in once (no interactive prompt):
1316
+ in \`flypod list\`. Sign in once via the browser:
852
1317
 
853
1318
  \`\`\`sh
854
- flypod login --key fk_xxxxxxxxxxxxxxxxxxxx
1319
+ flypod login
855
1320
  \`\`\`
856
1321
 
857
- 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
858
1323
  environment and every deploy is attributed to the account:
859
1324
 
860
1325
  \`\`\`sh
861
- FLYPOD_API_KEY=fk_xxxxxxxxxxxxxxxxxxxx npx flypod ./dist --json
1326
+ FLYPOD_TOKEN=<session-token> npx flypod ./dist --json
862
1327
  \`\`\`
863
1328
 
864
- Mint a key at https://flypod.dev/account, or run \`flypod keys create\` when
865
- already signed in.
866
-
867
1329
  ${sub} Other commands
868
1330
 
869
1331
  \`\`\`sh
870
1332
  flypod list # sites you own (requires sign in)
871
1333
  flypod claim <site_id> <token> # attach an anonymous deploy to your account
872
- flypod keys create # mint an API key for agents / CI
873
- flypod logout # forget the saved key
1334
+ flypod logout # forget the saved session token
874
1335
  flypod --help # full usage
875
1336
  \`\`\`
876
1337
 
@@ -1250,8 +1711,8 @@ var SUBCOMMANDS = new Set([
1250
1711
  "logout",
1251
1712
  "list",
1252
1713
  "claim",
1253
- "keys",
1254
- "install"
1714
+ "install",
1715
+ "comments"
1255
1716
  ]);
1256
1717
  var TARGET_FLAGS = {
1257
1718
  "--agents": "agents",
@@ -1265,8 +1726,16 @@ var TARGET_FLAGS = {
1265
1726
  "--gemini": "gemini"
1266
1727
  };
1267
1728
  function parseArgs(argv) {
1268
- const out = { json: false, quiet: false, help: false, version: false };
1269
- 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];
1270
1739
  if (a === "--json")
1271
1740
  out.json = true;
1272
1741
  else if (a === "-q" || a === "--quiet")
@@ -1275,6 +1744,12 @@ function parseArgs(argv) {
1275
1744
  out.help = true;
1276
1745
  else if (a === "-v" || a === "--version")
1277
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);
1278
1753
  else if (a.startsWith("-")) {
1279
1754
  process.stderr.write(`flypod: unknown flag "${a}"
1280
1755
  Run \`flypod --help\` for usage.
@@ -1338,19 +1813,19 @@ async function runSubcommand(name, argv) {
1338
1813
  return forget({ site, help }, io);
1339
1814
  }
1340
1815
  case "login": {
1341
- let key;
1816
+ let token;
1342
1817
  let help = false;
1343
1818
  for (let i = 0;i < argv.length; i++) {
1344
- if (argv[i] === "--key" && i + 1 < argv.length) {
1345
- key = argv[i + 1];
1819
+ if (argv[i] === "--token" && i + 1 < argv.length) {
1820
+ token = argv[i + 1];
1346
1821
  i++;
1347
- } else if (argv[i]?.startsWith("--key=")) {
1348
- key = argv[i]?.slice("--key=".length);
1822
+ } else if (argv[i]?.startsWith("--token=")) {
1823
+ token = argv[i]?.slice("--token=".length);
1349
1824
  } else if (argv[i] === "-h" || argv[i] === "--help") {
1350
1825
  help = true;
1351
1826
  }
1352
1827
  }
1353
- return login({ key, help }, io);
1828
+ return login({ token, help }, io);
1354
1829
  }
1355
1830
  case "logout":
1356
1831
  return logout({}, io);
@@ -1360,15 +1835,10 @@ async function runSubcommand(name, argv) {
1360
1835
  const positional = argv.filter((a) => !a.startsWith("-"));
1361
1836
  return claim({ site_id: positional[0], token: positional[1] }, io);
1362
1837
  }
1363
- case "keys": {
1364
- const sub = argv.find((a) => !a.startsWith("-"));
1365
- if (sub === "create")
1366
- return keysCreate({}, io);
1367
- io.err("Usage: flypod keys create");
1368
- return 2;
1369
- }
1370
1838
  case "install":
1371
1839
  return runInstall(argv, io);
1840
+ case "comments":
1841
+ return commentsCommand(argv, io);
1372
1842
  default:
1373
1843
  io.err(`flypod: unknown subcommand "${name}"`);
1374
1844
  return 2;
@@ -1487,25 +1957,44 @@ Account (optional — lets deploys live forever and be listed/owned):
1487
1957
  your browser to confirm). Anonymous deploys
1488
1958
  keep working; logging in just makes future
1489
1959
  deploys land in your dashboard.
1490
- flypod login --key fk_... Save an API key directly (skip the browser).
1491
- Or set FLYPOD_API_KEY for agents/CI.
1492
- flypod logout Forget the saved API key.
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.
1493
1963
  flypod list List sites you own (JSON on stdout).
1494
1964
  flypod claim <id> <token> Attach an anonymous deploy to your account.
1495
- flypod keys create Mint a new API key for agents / CI (JSON on stdout).
1496
1965
  flypod forget [--site <id>] Drop this folder's remembered site link.
1497
1966
 
1498
1967
  Agents:
1499
1968
  flypod install skill Teach your coding agents (Claude Code, Codex,
1500
1969
  Cursor, …) how to deploy with flypod.
1501
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
+
1502
1991
  Output:
1503
1992
  --json Emit a stable JSON result on stdout (for agents/scripts).
1504
1993
  -q, --quiet Print only the URL.
1505
1994
  -h, --help Show this help. -v, --version Show the flypod version.
1506
1995
 
1507
1996
  Environment:
1508
- FLYPOD_API_KEY Deploy as your account without logging in (agents / CI)
1997
+ FLYPOD_TOKEN Deploy as your account without logging in (agents / CI)
1509
1998
  DEPLOY_URL Override the deploy server (default: https://flypod.dev)
1510
1999
  FLYPOD_CONFIG_DIR Override where the CLI keeps its session + folder memory
1511
2000
  NO_COLOR Disable ANSI colors
@@ -1551,7 +2040,7 @@ async function main() {
1551
2040
 
1552
2041
  `);
1553
2042
  if (!apiKey) {
1554
- process.stderr.write(` ${style.muted("account")} ${style.dim("anonymous · ")}${style.bold("flypod login")}${style.dim(" to attribute deploys to your account")}
2043
+ process.stderr.write(` ${style.muted("account")} ${style.dim("anonymous · ")}${style.bold("flypod login")}${style.dim(" claims this site to your account")}
1555
2044
 
1556
2045
  `);
1557
2046
  }
@@ -1637,6 +2126,35 @@ async function main() {
1637
2126
  version_id: result.version_id
1638
2127
  });
1639
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
+ }
1640
2158
  if (args.json) {
1641
2159
  process.stdout.write(`${JSON.stringify({
1642
2160
  ok: true,
@@ -1650,7 +2168,8 @@ async function main() {
1650
2168
  source: shortDir(dir),
1651
2169
  files: fileNames.length,
1652
2170
  bytes: totalBytes,
1653
- elapsed_ms: elapsed
2171
+ elapsed_ms: elapsed,
2172
+ ...args.comments ? { comments_enabled: commentsEnabled, comments_mode: args.commentsMode } : {}
1654
2173
  }, null, 2)}
1655
2174
  `);
1656
2175
  return;
@@ -1673,7 +2192,7 @@ async function main() {
1673
2192
  process.stderr.write(` ${rule}
1674
2193
 
1675
2194
  `);
1676
- const expiry = typeof result.expires_at === "number" ? `in ${Math.max(0, Math.round((result.expires_at - Date.now()) / 86400000))} days . anonymous deploy (run \`flypod login\` to attribute)` : result.owner_account_id ? "never . attributed to your account" : "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)";
1677
2196
  process.stderr.write(` ${style.muted("expires")} ${style.dim(expiry)}
1678
2197
 
1679
2198
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flypod",
3
- "version": "0.5.1",
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
  },