flypod 0.6.0 → 0.7.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.
@@ -1,52 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ atomicWriteFile,
4
+ clearSession,
3
5
  collectDist,
6
+ createClient,
4
7
  deploySite,
8
+ projectsFilePath,
9
+ resolveCredentials,
5
10
  resolveDeployDir,
11
+ saveSession,
6
12
  zipSync
7
- } from "../cli-ynzcc4xy.js";
13
+ } from "../cli-j9rxpfdv.js";
8
14
 
9
15
  // bin/deploy.ts
10
- import { readFile as readFile4 } from "node:fs/promises";
11
- import { homedir as homedir3 } from "node:os";
16
+ import { readFile as readFile3 } from "node:fs/promises";
17
+ import { homedir as homedir2 } from "node:os";
12
18
  import { relative } from "node:path";
13
19
  import { fileURLToPath } from "node:url";
14
20
 
15
21
  // src/cli/projects.ts
16
22
  import { readFile } from "node:fs/promises";
17
-
18
- // src/cli/paths.ts
19
- import { mkdir, rename, writeFile } from "node:fs/promises";
20
- import { homedir, platform } from "node:os";
21
- import { dirname, join } from "node:path";
22
- function configDir(env = process.env) {
23
- if (env.FLYPOD_CONFIG_DIR)
24
- return env.FLYPOD_CONFIG_DIR;
25
- const os = platform();
26
- if (os === "darwin") {
27
- return join(homedir(), "Library", "Application Support", "flypod");
28
- }
29
- if (os === "win32") {
30
- const appData = env.APPDATA ?? join(homedir(), "AppData", "Roaming");
31
- return join(appData, "flypod");
32
- }
33
- const xdg = env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
34
- return join(xdg, "flypod");
35
- }
36
- function sessionFilePath(env = process.env) {
37
- return join(configDir(env), "session.json");
38
- }
39
- function projectsFilePath(env = process.env) {
40
- return join(configDir(env), "projects.json");
41
- }
42
- async function atomicWriteFile(path, content) {
43
- await mkdir(dirname(path), { recursive: true });
44
- const tmp = `${path}.tmp`;
45
- await writeFile(tmp, content, { mode: 384 });
46
- await rename(tmp, path);
47
- }
48
-
49
- // src/cli/projects.ts
50
23
  var MAX_PROJECTS = 64;
51
24
  function prune(projects, now) {
52
25
  const out = {};
@@ -114,46 +87,7 @@ async function forgetSite(site_id, env) {
114
87
  return removed;
115
88
  }
116
89
 
117
- // src/cli/session.ts
118
- import { readFile as readFile2, unlink } from "node:fs/promises";
119
- async function resolveAuth(env = process.env) {
120
- const session = await loadSession(env);
121
- const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
122
- const baseUrl = session?.base_url ?? env.DEPLOY_URL ?? "https://flypod.dev";
123
- return { apiKey, baseUrl };
124
- }
125
- async function loadSession(env) {
126
- try {
127
- const path = sessionFilePath(env);
128
- const text = await readFile2(path, "utf8");
129
- const parsed = JSON.parse(text);
130
- if (typeof parsed?.session_token === "string" && typeof parsed?.base_url === "string" && typeof parsed?.created_at === "number") {
131
- return parsed;
132
- }
133
- return null;
134
- } catch {
135
- return null;
136
- }
137
- }
138
- async function saveSession(session, env) {
139
- const path = sessionFilePath(env);
140
- await atomicWriteFile(path, `${JSON.stringify(session, null, 2)}
141
- `);
142
- return path;
143
- }
144
- async function clearSession(env) {
145
- try {
146
- await unlink(sessionFilePath(env));
147
- return true;
148
- } catch {
149
- return false;
150
- }
151
- }
152
-
153
90
  // src/cli/commands.ts
154
- function baseUrlFrom(env = process.env) {
155
- return env.DEPLOY_URL ?? "https://flypod.dev";
156
- }
157
91
  function siteUrlFrom(site_id, baseUrl) {
158
92
  const host = new URL(baseUrl).host;
159
93
  const scheme = new URL(baseUrl).protocol.replace(":", "");
@@ -228,68 +162,7 @@ Forget the saved session token. Doesn't affect the server.`,
228
162
  List sites you own (requires login or FLYPOD_TOKEN). Outputs JSON on stdout.`,
229
163
  claim: `flypod claim <site_id> <claim_token>
230
164
 
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.`
165
+ Attach an anonymous deploy to your account (requires login or FLYPOD_TOKEN). Outputs JSON on stdout.`
293
166
  };
294
167
  function showSubHelp(name, io) {
295
168
  const help = SUBCOMMAND_HELP[name];
@@ -302,8 +175,13 @@ function failJson(error, io) {
302
175
  io.out(JSON.stringify({ ok: false, error }));
303
176
  return 1;
304
177
  }
305
- var DEVICE_CLIENT_ID = "flypod-cli";
306
- var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
178
+ function fail(msg, args, io, opts = {}) {
179
+ if (args.json)
180
+ return failJson(msg, io);
181
+ if (!opts.silent)
182
+ io.err(msg);
183
+ return 1;
184
+ }
307
185
  var POLL_MAX_ATTEMPTS = 120;
308
186
  async function login(args, io) {
309
187
  if (args.help) {
@@ -311,19 +189,15 @@ async function login(args, io) {
311
189
  return 0;
312
190
  }
313
191
  const env = io.env ?? process.env;
314
- const baseUrl = baseUrlFrom(env);
192
+ const baseUrl = resolveCredentials(env, null).baseUrl;
315
193
  if (args.token) {
316
194
  await saveSession({ session_token: args.token, base_url: baseUrl, created_at: Date.now() }, env);
317
195
  io.err("Logged in.");
318
196
  await attachAnonymousSites(args.token, baseUrl, io, env);
319
197
  return 0;
320
198
  }
321
- const fetchImpl = io.fetch ?? fetch;
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
- });
199
+ const client = await createClient({ env, fetch: io.fetch, overrides: { baseUrl } });
200
+ const startRes = await client.deviceCode();
327
201
  if (!startRes.ok) {
328
202
  io.err(`flypod login: server returned ${startRes.status}. Is the server running?`);
329
203
  return 1;
@@ -339,15 +213,7 @@ async function login(args, io) {
339
213
  let pollMs = (start.interval ?? 5) * 1000;
340
214
  for (let attempt = 0;attempt < POLL_MAX_ATTEMPTS; attempt++) {
341
215
  await new Promise((r) => setTimeout(r, pollMs));
342
- const pollRes = await fetchImpl(`${baseUrl}/api/auth/device/token`, {
343
- method: "POST",
344
- headers: { "content-type": "application/json" },
345
- body: JSON.stringify({
346
- grant_type: DEVICE_GRANT_TYPE,
347
- device_code: start.device_code,
348
- client_id: DEVICE_CLIENT_ID
349
- })
350
- });
216
+ const pollRes = await client.deviceToken(start.device_code);
351
217
  if (pollRes.ok) {
352
218
  const { access_token } = await pollRes.json();
353
219
  await saveSession({ session_token: access_token, base_url: baseUrl, created_at: Date.now() }, env);
@@ -384,17 +250,15 @@ async function attachAnonymousSites(apiKey, baseUrl, io, env) {
384
250
  const noun = candidates.length === 1 ? "site" : "sites";
385
251
  io.err(`Found ${candidates.length} anonymous ${noun} on this machine.`);
386
252
  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
- })
253
+ const client = await createClient({
254
+ env,
255
+ fetch: io.fetch,
256
+ overrides: { token: apiKey, baseUrl }
397
257
  });
258
+ const res = await client.bulkAttach(candidates.map(([, rec]) => ({
259
+ site_id: rec.site_id,
260
+ manage_token: rec.manage_token
261
+ })));
398
262
  if (!res.ok) {
399
263
  io.err(` Could not attach (${res.status}). Try again later.`);
400
264
  return;
@@ -429,17 +293,12 @@ async function logout(_args, io) {
429
293
  }
430
294
  async function list(_args, io) {
431
295
  const env = io.env ?? process.env;
432
- const session = await loadSession(env);
433
- const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
434
- const baseUrl = session?.base_url ?? baseUrlFrom(env);
435
- if (!apiKey) {
296
+ const client = await createClient({ env, fetch: io.fetch });
297
+ if (!client.token) {
436
298
  io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
437
299
  return 1;
438
300
  }
439
- const fetchImpl = io.fetch ?? fetch;
440
- const res = await fetchImpl(`${baseUrl}/account/sites`, {
441
- headers: { authorization: `Bearer ${apiKey}` }
442
- });
301
+ const res = await client.listSites();
443
302
  if (!res.ok) {
444
303
  io.err(`flypod list: server returned ${res.status}.`);
445
304
  return 1;
@@ -455,10 +314,8 @@ async function list(_args, io) {
455
314
  }
456
315
  async function claim(args, io) {
457
316
  const env = io.env ?? process.env;
458
- const session = await loadSession(env);
459
- const apiKey = env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
460
- const baseUrl = session?.base_url ?? baseUrlFrom(env);
461
- if (!apiKey) {
317
+ const client = await createClient({ env, fetch: io.fetch });
318
+ if (!client.token) {
462
319
  io.err("Not signed in. Run `flypod login` first or set FLYPOD_TOKEN.");
463
320
  return 1;
464
321
  }
@@ -466,15 +323,7 @@ async function claim(args, io) {
466
323
  io.err("Usage: flypod claim <site_id> <claim_token>");
467
324
  return 2;
468
325
  }
469
- const fetchImpl = io.fetch ?? fetch;
470
- const res = await fetchImpl(`${baseUrl}/sites/${args.site_id}/claim`, {
471
- method: "POST",
472
- headers: {
473
- "content-type": "application/json",
474
- authorization: `Bearer ${apiKey}`
475
- },
476
- body: JSON.stringify({ claim_token: args.token })
477
- });
326
+ const res = await client.claimSite(args.site_id, args.token);
478
327
  if (!res.ok) {
479
328
  io.err(`flypod claim: server returned ${res.status}.`);
480
329
  return 1;
@@ -493,14 +342,27 @@ async function resolveTarget(args, io) {
493
342
  const rec = await projectForDir(cwd, env);
494
343
  return rec ? { site_id: rec.site_id, rec, dir: cwd } : null;
495
344
  }
496
- async function requestContext(target, args, env) {
497
- const session = await loadSession(env);
498
- const baseUrl = target.rec?.base_url ?? session?.base_url ?? baseUrlFrom(env);
499
- const auth = args.token ?? target.rec?.manage_token ?? env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
500
- return { baseUrl, auth };
501
- }
502
- function authHeaders(auth, extra = {}) {
503
- return auth ? { ...extra, authorization: `Bearer ${auth}` } : { ...extra };
345
+ async function withTarget(name, args, io) {
346
+ if (args.help) {
347
+ showSubHelp(name, io);
348
+ return 0;
349
+ }
350
+ const env = io.env ?? process.env;
351
+ const target = await resolveTarget(args, io);
352
+ if (!target)
353
+ return fail(NO_SITE, args, io);
354
+ return { env, target };
355
+ }
356
+ function clientForTarget(target, args, io) {
357
+ return createClient({
358
+ env: io.env ?? process.env,
359
+ fetch: io.fetch,
360
+ overrides: {
361
+ token: args.token,
362
+ manageToken: target.rec?.manage_token,
363
+ baseUrl: target.rec?.base_url
364
+ }
365
+ });
504
366
  }
505
367
  async function healGone(target, io, env) {
506
368
  if (target.dir)
@@ -511,9 +373,8 @@ function unauthorized(target, io) {
511
373
  io.err(`Unauthorized for ${target.site_id}. Run \`flypod login\` or pass --token <manage_token>.`);
512
374
  }
513
375
  async function fetchSite(target, args, io, env) {
514
- const { baseUrl, auth } = await requestContext(target, args, env);
515
- const fetchImpl = io.fetch ?? fetch;
516
- const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}`, { headers: authHeaders(auth) });
376
+ const client = await clientForTarget(target, args, io);
377
+ const res = await client.getSite(target.site_id);
517
378
  if (res.status === 401 || res.status === 403) {
518
379
  unauthorized(target, io);
519
380
  return { error: 1 };
@@ -534,46 +395,25 @@ async function touchLink(target, version_id, env) {
534
395
  }
535
396
  }
536
397
  async function update(args, io) {
537
- if (args.help) {
538
- showSubHelp("update", io);
539
- return 0;
540
- }
541
- const env = io.env ?? process.env;
398
+ const pre = await withTarget("update", args, io);
399
+ if (typeof pre === "number")
400
+ return pre;
401
+ const { env, target } = pre;
542
402
  const cwd = io.cwd ?? process.cwd();
543
- const target = await resolveTarget(args, io);
544
- if (!target) {
545
- if (args.json)
546
- return failJson(NO_SITE, io);
547
- io.err(NO_SITE);
548
- return 1;
549
- }
550
403
  let dir;
551
404
  try {
552
405
  dir = await resolveDeployDir({ cwd, explicit: args.path });
553
406
  } catch (e) {
554
- const msg = e.message;
555
- if (args.json)
556
- return failJson(msg, io);
557
- io.err(msg);
558
- return 1;
407
+ return fail(e.message, args, io);
559
408
  }
560
409
  let files;
561
410
  try {
562
411
  files = await collectDist(dir);
563
412
  } catch (e) {
564
- const msg = `Could not read ${dir}: ${e.message}`;
565
- if (args.json)
566
- return failJson(msg, io);
567
- io.err(msg);
568
- return 1;
413
+ return fail(`Could not read ${dir}: ${e.message}`, args, io);
569
414
  }
570
- const { baseUrl, auth } = await requestContext(target, args, env);
571
- const fetchImpl = io.fetch ?? fetch;
572
- const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}/deploys`, {
573
- method: "POST",
574
- headers: authHeaders(auth, { "content-type": "application/zip" }),
575
- body: zipSync(files)
576
- });
415
+ const client = await clientForTarget(target, args, io);
416
+ const res = await client.redeploy(target.site_id, zipSync(files));
577
417
  if (res.status === 401 || res.status === 403) {
578
418
  unauthorized(target, io);
579
419
  return 1;
@@ -606,18 +446,10 @@ async function update(args, io) {
606
446
  return 0;
607
447
  }
608
448
  async function versions(args, io) {
609
- if (args.help) {
610
- showSubHelp("versions", io);
611
- return 0;
612
- }
613
- const env = io.env ?? process.env;
614
- const target = await resolveTarget(args, io);
615
- if (!target) {
616
- if (args.json)
617
- return failJson(NO_SITE, io);
618
- io.err(NO_SITE);
619
- return 1;
620
- }
449
+ const pre = await withTarget("versions", args, io);
450
+ if (typeof pre === "number")
451
+ return pre;
452
+ const { env, target } = pre;
621
453
  const site = await fetchSite(target, args, io, env);
622
454
  if ("error" in site)
623
455
  return site.error;
@@ -632,18 +464,10 @@ async function versions(args, io) {
632
464
  return 0;
633
465
  }
634
466
  async function rollback(args, io) {
635
- if (args.help) {
636
- showSubHelp("rollback", io);
637
- return 0;
638
- }
639
- const env = io.env ?? process.env;
640
- const target = await resolveTarget(args, io);
641
- if (!target) {
642
- if (args.json)
643
- return failJson(NO_SITE, io);
644
- io.err(NO_SITE);
645
- return 1;
646
- }
467
+ const pre = await withTarget("rollback", args, io);
468
+ if (typeof pre === "number")
469
+ return pre;
470
+ const { env, target } = pre;
647
471
  const site = await fetchSite(target, args, io, env);
648
472
  if ("error" in site)
649
473
  return site.error;
@@ -657,59 +481,32 @@ async function rollback(args, io) {
657
481
  else if (prefixed.length === 1)
658
482
  chosen = prefixed[0]?.version_id;
659
483
  else if (prefixed.length === 0) {
660
- const msg = `No version matches '${args.version}'.`;
661
- if (args.json)
662
- return failJson(msg, io);
663
- io.err(msg);
664
- return 1;
484
+ return fail(`No version matches '${args.version}'.`, args, io);
665
485
  } else {
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);
670
- return 1;
486
+ return fail(`'${args.version}' is ambiguous — it matches ${prefixed.length} versions.`, args, io);
671
487
  }
672
488
  } else {
673
489
  if (vers.length < 2) {
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);
678
- return 1;
490
+ return fail("Only one version exists — nothing to roll back to.", args, io);
679
491
  }
680
492
  const liveIdx = vers.findIndex((v) => v.version_id === live_version_id);
681
493
  if (liveIdx <= 0) {
682
- const msg = "Already at the oldest version.";
683
- if (args.json)
684
- return failJson(msg, io);
685
- io.err(msg);
686
- return 1;
494
+ return fail("Already at the oldest version.", args, io);
687
495
  }
688
496
  chosen = vers[liveIdx - 1]?.version_id;
689
497
  }
690
- const { baseUrl, auth } = await requestContext(target, args, env);
691
- const fetchImpl = io.fetch ?? fetch;
692
- const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}/rollback`, {
693
- method: "POST",
694
- headers: authHeaders(auth, { "content-type": "application/json" }),
695
- body: JSON.stringify({ version_id: chosen })
696
- });
498
+ const client = await clientForTarget(target, args, io);
499
+ const res = await client.rollback(target.site_id, chosen);
697
500
  if (res.status === 404) {
698
501
  await healGone(target, io, env);
699
- if (args.json)
700
- return failJson(`Site ${target.site_id} not found.`, io);
701
- return 1;
502
+ return fail(`Site ${target.site_id} not found.`, args, io, { silent: true });
702
503
  }
703
504
  if (!res.ok) {
704
- const msg = `flypod rollback: server returned ${res.status}.`;
705
- if (args.json)
706
- return failJson(msg, io);
707
- io.err(msg);
708
- return 1;
505
+ return fail(`flypod rollback: server returned ${res.status}.`, args, io);
709
506
  }
710
507
  const body = await res.json();
711
508
  await touchLink(target, body.live_version_id, env);
712
- const url = target.rec?.url ?? siteUrlFrom(target.site_id, baseUrl);
509
+ const url = target.rec?.url ?? siteUrlFrom(target.site_id, client.baseUrl);
713
510
  if (args.json) {
714
511
  io.out(JSON.stringify({
715
512
  ok: true,
@@ -741,33 +538,89 @@ async function forget(args, io) {
741
538
  return 0;
742
539
  }
743
540
 
541
+ // src/cli/flags.ts
542
+ function parseFlags(argv, spec) {
543
+ const flags = {};
544
+ const positionals = [];
545
+ const unknown = [];
546
+ let terminated = false;
547
+ for (let i = 0;i < argv.length; i++) {
548
+ const a = argv[i];
549
+ if (terminated) {
550
+ positionals.push(a);
551
+ continue;
552
+ }
553
+ if (a === "--") {
554
+ terminated = true;
555
+ continue;
556
+ }
557
+ const eq = a.startsWith("--") ? a.indexOf("=") : -1;
558
+ if (eq !== -1) {
559
+ const name = a.slice(0, eq);
560
+ if (spec[name] === "value")
561
+ flags[name] = a.slice(eq + 1);
562
+ else
563
+ unknown.push(a);
564
+ continue;
565
+ }
566
+ const kind = spec[a];
567
+ if (kind === "value") {
568
+ if (i + 1 < argv.length)
569
+ flags[a] = argv[++i];
570
+ else
571
+ unknown.push(a);
572
+ continue;
573
+ }
574
+ if (kind === "bool") {
575
+ flags[a] = true;
576
+ continue;
577
+ }
578
+ if (a.startsWith("-"))
579
+ unknown.push(a);
580
+ else
581
+ positionals.push(a);
582
+ }
583
+ return { flags, positionals, unknown };
584
+ }
585
+
744
586
  // src/cli/comments.ts
745
- function baseUrlFrom2(env = process.env) {
746
- return env.DEPLOY_URL ?? "https://flypod.dev";
587
+ var NO_SITE2 = "No site given, and no flypod site is linked to this folder. " + "Pass --site <id>, or run this from a folder you have deployed from.";
588
+ async function resolveCommentsSite(explicit, io) {
589
+ if (explicit)
590
+ return explicit;
591
+ const rec = await projectForDir(io.cwd ?? process.cwd(), io.env ?? process.env);
592
+ return rec?.site_id;
593
+ }
594
+ function failNoSite(json, io) {
595
+ if (json) {
596
+ io.out(JSON.stringify({ ok: false, error: "no_site" }));
597
+ return 1;
598
+ }
599
+ io.err(NO_SITE2);
600
+ return 2;
747
601
  }
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 };
602
+ async function resolveSiteAndThread(f, io) {
603
+ if (f.site)
604
+ return { site: f.site, thread_id: f.positionals[0] };
605
+ if (f.positionals.length >= 2) {
606
+ return { site: f.positionals[0], thread_id: f.positionals[1] };
607
+ }
608
+ return {
609
+ site: await resolveCommentsSite(undefined, io),
610
+ thread_id: f.positionals[0]
611
+ };
753
612
  }
754
- function requireFauToken(token, io) {
613
+ function requireCommentWriteToken(token, io) {
755
614
  if (!token) {
756
- io.err("Not signed in. Set FLYPOD_TOKEN to an fau_ token, or run `flypod login`.");
615
+ io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
757
616
  return 3;
758
617
  }
759
618
  if (token.startsWith("fk_")) {
760
- io.err("comments operations require an fau_ token");
619
+ io.err("comments operations require an account session or agent token");
761
620
  return 3;
762
621
  }
763
622
  return null;
764
623
  }
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
624
  async function readErrorBody(res) {
772
625
  try {
773
626
  const body = await res.json();
@@ -780,7 +633,8 @@ async function readErrorBody(res) {
780
633
  }
781
634
  async function commentsMode(args, io) {
782
635
  if (!args.mode) {
783
- io.err("Usage: flypod comments mode <anonymous|passcode|approved> [--site <id>] [--passcode <s>]");
636
+ io.err(`Usage: flypod comments mode <anonymous|passcode|approved> [--site <id>] [--passcode <s>]
637
+ ` + " --site defaults to the site linked to this folder.");
784
638
  return 2;
785
639
  }
786
640
  const allowed = new Set(["anonymous", "passcode", "approved", "open", "review", "members"]);
@@ -793,20 +647,15 @@ async function commentsMode(args, io) {
793
647
  return 2;
794
648
  }
795
649
  const env = io.env ?? process.env;
796
- const { token, baseUrl } = await resolveCommentToken(env);
797
- if (!token) {
650
+ const client = await createClient({ env, fetch: io.fetch });
651
+ if (!client.token) {
798
652
  io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
799
653
  return 3;
800
654
  }
801
- const fetchImpl = io.fetch ?? fetch;
802
655
  const body = { enabled: true, mode: args.mode };
803
656
  if (args.passcode)
804
657
  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
- });
658
+ const res = await client.setCommentsMode(args.site, body);
810
659
  if (!res.ok) {
811
660
  io.err(`flypod comments mode: ${await readErrorBody(res)}`);
812
661
  return res.status >= 500 ? 4 : 1;
@@ -823,17 +672,12 @@ async function commentsOff(args, io) {
823
672
  return 2;
824
673
  }
825
674
  const env = io.env ?? process.env;
826
- const { token, baseUrl } = await resolveCommentToken(env);
827
- if (!token) {
675
+ const client = await createClient({ env, fetch: io.fetch });
676
+ if (!client.token) {
828
677
  io.err("Not signed in. Run `flypod login` or set FLYPOD_TOKEN.");
829
678
  return 3;
830
679
  }
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
- });
680
+ const res = await client.setCommentsMode(args.site, { enabled: false });
837
681
  if (!res.ok) {
838
682
  io.err(`flypod comments off: ${await readErrorBody(res)}`);
839
683
  return res.status >= 500 ? 4 : 1;
@@ -850,18 +694,12 @@ async function commentsList(args, io) {
850
694
  return 2;
851
695
  }
852
696
  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) });
697
+ const client = await createClient({ env, fetch: io.fetch });
698
+ const res = await client.listComments(args.site, {
699
+ page: args.page,
700
+ status: args.status,
701
+ limit: args.limit !== undefined ? String(args.limit) : undefined
702
+ });
865
703
  if (!res.ok) {
866
704
  io.err(`flypod comments list: ${await readErrorBody(res)}`);
867
705
  return res.status >= 500 ? 4 : 1;
@@ -884,11 +722,8 @@ async function commentsShow(args, io) {
884
722
  return 2;
885
723
  }
886
724
  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
- });
725
+ const client = await createClient({ env, fetch: io.fetch });
726
+ const res = await client.getThread(args.site, args.thread_id);
892
727
  if (!res.ok) {
893
728
  io.err(`flypod comments show: ${await readErrorBody(res)}`);
894
729
  return res.status >= 500 ? 4 : 1;
@@ -903,8 +738,8 @@ async function commentsPost(args, io) {
903
738
  return 2;
904
739
  }
905
740
  const env = io.env ?? process.env;
906
- const { token, baseUrl } = await resolveCommentToken(env);
907
- const reject = requireFauToken(token, io);
741
+ const client = await createClient({ env, fetch: io.fetch });
742
+ const reject = requireCommentWriteToken(client.token, io);
908
743
  if (reject !== null)
909
744
  return reject;
910
745
  let target;
@@ -914,11 +749,10 @@ async function commentsPost(args, io) {
914
749
  io.err("Invalid --target JSON.");
915
750
  return 2;
916
751
  }
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 })
752
+ const res = await client.postComment(args.site, {
753
+ page_path: args.page,
754
+ anchor: target,
755
+ body: args.body
922
756
  });
923
757
  if (!res.ok) {
924
758
  io.err(`flypod comments post: ${await readErrorBody(res)}`);
@@ -930,16 +764,16 @@ async function commentsPost(args, io) {
930
764
  }
931
765
  async function setThreadStatus(endpoint, args, io) {
932
766
  if (!args.site || !args.thread_id) {
933
- io.err(`Usage: flypod comments ${endpoint} <site> <thread_id>`);
767
+ io.err(`Usage: flypod comments ${endpoint} [<site>] <thread_id>
768
+ ` + " The site defaults to the one linked to this folder.");
934
769
  return 2;
935
770
  }
936
771
  const env = io.env ?? process.env;
937
- const { token, baseUrl } = await resolveCommentToken(env);
938
- const reject = requireFauToken(token, io);
772
+ const client = await createClient({ env, fetch: io.fetch });
773
+ const reject = requireCommentWriteToken(client.token, io);
939
774
  if (reject !== null)
940
775
  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) });
776
+ const res = await client.setThreadStatus(args.site, args.thread_id, endpoint);
943
777
  if (!res.ok) {
944
778
  io.err(`flypod comments ${endpoint}: ${await readErrorBody(res)}`);
945
779
  return res.status >= 500 ? 4 : res.status === 401 || res.status === 403 ? 3 : 1;
@@ -957,189 +791,113 @@ function commentsResolve(args, io) {
957
791
  function commentsReopen(args, io) {
958
792
  return setThreadStatus("reopen", args, io);
959
793
  }
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
794
  async function commentsEnable(args, io) {
1015
795
  if (!args.site) {
1016
- io.err("Usage: flypod comments enable --site <id> [--mode anonymous|passcode|approved] [--passcode <s>]");
796
+ io.err(`Usage: flypod comments enable [--site <id>] [--mode anonymous|passcode|approved] [--passcode <s>]
797
+ ` + " --site defaults to the site linked to this folder.");
1017
798
  return 2;
1018
799
  }
1019
800
  return commentsMode({ mode: args.mode ?? "anonymous", site: args.site, passcode: args.passcode, json: args.json }, io);
1020
801
  }
802
+ var COMMENTS_FLAG_SPEC = {
803
+ "--site": "value",
804
+ "--mode": "value",
805
+ "--page": "value",
806
+ "--target": "value",
807
+ "--body": "value",
808
+ "--url": "value",
809
+ "--secret": "value",
810
+ "--passcode": "value",
811
+ "--limit": "value",
812
+ "--open": "bool",
813
+ "--resolved": "bool",
814
+ "--all": "bool",
815
+ "--json": "bool"
816
+ };
817
+ function parseCommentFlags(tail) {
818
+ const { flags, positionals } = parseFlags(tail, COMMENTS_FLAG_SPEC);
819
+ const limitRaw = flags["--limit"];
820
+ const status = flags["--all"] ? "all" : flags["--resolved"] ? "resolved" : flags["--open"] ? "open" : undefined;
821
+ return {
822
+ positionals,
823
+ site: flags["--site"],
824
+ mode: flags["--mode"],
825
+ page: flags["--page"],
826
+ target: flags["--target"],
827
+ body: flags["--body"],
828
+ url: flags["--url"],
829
+ secret: flags["--secret"],
830
+ passcode: flags["--passcode"],
831
+ limit: limitRaw ? Number(limitRaw) : undefined,
832
+ status,
833
+ json: Boolean(flags["--json"])
834
+ };
835
+ }
1021
836
  async function commentsCommand(argv, io) {
1022
837
  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]");
838
+ io.err("Usage: flypod comments <enable|mode|off|list|show|post|resolve|reopen> [args]");
1024
839
  return argv[0] === "-h" || argv[0] === "--help" ? 0 : 2;
1025
840
  }
1026
841
  const verb = argv[0];
1027
842
  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
843
  switch (verb) {
1085
844
  case "enable": {
1086
- const f = parseFlags(rest);
1087
- const site = f.site ?? f.positionals[0];
845
+ const f = parseCommentFlags(rest);
846
+ const site = await resolveCommentsSite(f.site ?? f.positionals[0], io);
847
+ if (!site)
848
+ return failNoSite(f.json, io);
1088
849
  return commentsEnable({ site, mode: f.mode, passcode: f.passcode, json: f.json }, io);
1089
850
  }
1090
851
  case "mode": {
1091
- const f = parseFlags(rest);
852
+ const f = parseCommentFlags(rest);
1092
853
  const mode = f.positionals[0];
1093
- const site = f.site ?? f.positionals[1];
854
+ const site = await resolveCommentsSite(f.site ?? f.positionals[1], io);
855
+ if (!site)
856
+ return failNoSite(f.json, io);
1094
857
  return commentsMode({ mode, site, passcode: f.passcode, json: f.json }, io);
1095
858
  }
1096
859
  case "off": {
1097
- const f = parseFlags(rest);
1098
- const site = f.site ?? f.positionals[0];
860
+ const f = parseCommentFlags(rest);
861
+ const site = await resolveCommentsSite(f.site ?? f.positionals[0], io);
862
+ if (!site)
863
+ return failNoSite(f.json, io);
1099
864
  return commentsOff({ site, json: f.json }, io);
1100
865
  }
1101
866
  case "list": {
1102
- const f = parseFlags(rest);
1103
- const site = f.positionals[0] ?? f.site;
867
+ const f = parseCommentFlags(rest);
868
+ const site = await resolveCommentsSite(f.positionals[0] ?? f.site, io);
869
+ if (!site)
870
+ return failNoSite(f.json, io);
1104
871
  return commentsList({ site, page: f.page, status: f.status, limit: f.limit, json: f.json }, io);
1105
872
  }
1106
873
  case "show": {
1107
- const f = parseFlags(rest);
1108
- const site = f.positionals[0];
1109
- const thread_id = f.positionals[1];
874
+ const f = parseCommentFlags(rest);
875
+ const { site, thread_id } = await resolveSiteAndThread(f, io);
876
+ if (!site)
877
+ return failNoSite(f.json, io);
1110
878
  return commentsShow({ site, thread_id, json: f.json }, io);
1111
879
  }
1112
880
  case "post": {
1113
- const f = parseFlags(rest);
1114
- const site = f.positionals[0] ?? f.site;
881
+ const f = parseCommentFlags(rest);
882
+ const site = await resolveCommentsSite(f.positionals[0] ?? f.site, io);
883
+ if (!site)
884
+ return failNoSite(f.json, io);
1115
885
  return commentsPost({ site, page: f.page, target: f.target, body: f.body, json: f.json }, io);
1116
886
  }
1117
887
  case "resolve": {
1118
- const f = parseFlags(rest);
1119
- const site = f.positionals[0];
1120
- const thread_id = f.positionals[1];
888
+ const f = parseCommentFlags(rest);
889
+ const { site, thread_id } = await resolveSiteAndThread(f, io);
890
+ if (!site)
891
+ return failNoSite(f.json, io);
1121
892
  return commentsResolve({ site, thread_id, json: f.json }, io);
1122
893
  }
1123
894
  case "reopen": {
1124
- const f = parseFlags(rest);
1125
- const site = f.positionals[0];
1126
- const thread_id = f.positionals[1];
895
+ const f = parseCommentFlags(rest);
896
+ const { site, thread_id } = await resolveSiteAndThread(f, io);
897
+ if (!site)
898
+ return failNoSite(f.json, io);
1127
899
  return commentsReopen({ site, thread_id, json: f.json }, io);
1128
900
  }
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
901
  default:
1144
902
  io.err(`flypod comments: unknown verb "${verb}"`);
1145
903
  return 2;
@@ -1244,9 +1002,9 @@ function multiselect(opts) {
1244
1002
  }
1245
1003
 
1246
1004
  // src/cli/skill.ts
1247
- import { mkdir as mkdir2, readFile as readFile3, stat, writeFile as writeFile2 } from "node:fs/promises";
1248
- import { homedir as homedir2 } from "node:os";
1249
- import { dirname as dirname2, join as join2 } from "node:path";
1005
+ import { mkdir, readFile as readFile2, stat, writeFile } from "node:fs/promises";
1006
+ import { homedir } from "node:os";
1007
+ import { dirname, join } from "node:path";
1250
1008
  var SKILL_NAME = "flypod";
1251
1009
  var SKILL_DESCRIPTION = "Deploy any folder of static files to a live public URL with flypod (flypod.dev) — no account, config, or build pipeline needed. " + "Use when the user wants to deploy, publish, ship, share, or host a static site, build output, preview, or demo, or asks to put a finished build online or get a URL for it.";
1252
1010
  var MARK_BEGIN = `<!-- ${SKILL_NAME}:begin -->`;
@@ -1382,7 +1140,7 @@ async function exists(path) {
1382
1140
  }
1383
1141
  async function anyExists(root, rels) {
1384
1142
  for (const rel of rels) {
1385
- if (await exists(join2(root, rel)))
1143
+ if (await exists(join(root, rel)))
1386
1144
  return true;
1387
1145
  }
1388
1146
  return false;
@@ -1394,8 +1152,8 @@ var TARGETS = [
1394
1152
  detail: "universal — Codex, Cursor, Copilot, Gemini, Zed, Jules, +more",
1395
1153
  kind: "embed",
1396
1154
  alwaysDefault: true,
1397
- projectPath: (root) => join2(root, "AGENTS.md"),
1398
- globalPath: () => join2(homedir2(), ".codex", "AGENTS.md"),
1155
+ projectPath: (root) => join(root, "AGENTS.md"),
1156
+ globalPath: () => join(homedir(), ".codex", "AGENTS.md"),
1399
1157
  detect: () => Promise.resolve(true),
1400
1158
  render: embedSection
1401
1159
  },
@@ -1405,8 +1163,8 @@ var TARGETS = [
1405
1163
  detail: ".claude/skills/flypod/SKILL.md — loaded on demand",
1406
1164
  kind: "skill",
1407
1165
  alwaysDefault: true,
1408
- projectPath: (root) => join2(root, ".claude", "skills", SKILL_NAME, "SKILL.md"),
1409
- globalPath: () => join2(homedir2(), ".claude", "skills", SKILL_NAME, "SKILL.md"),
1166
+ projectPath: (root) => join(root, ".claude", "skills", SKILL_NAME, "SKILL.md"),
1167
+ globalPath: () => join(homedir(), ".claude", "skills", SKILL_NAME, "SKILL.md"),
1410
1168
  detect: (root) => anyExists(root, [".claude", "CLAUDE.md"]),
1411
1169
  render: claudeSkillFile
1412
1170
  },
@@ -1416,7 +1174,7 @@ var TARGETS = [
1416
1174
  detail: ".cursor/rules/flypod.mdc",
1417
1175
  kind: "rules",
1418
1176
  alwaysDefault: false,
1419
- projectPath: (root) => join2(root, ".cursor", "rules", `${SKILL_NAME}.mdc`),
1177
+ projectPath: (root) => join(root, ".cursor", "rules", `${SKILL_NAME}.mdc`),
1420
1178
  globalPath: () => null,
1421
1179
  detect: (root) => anyExists(root, [".cursor", ".cursorrules"]),
1422
1180
  render: cursorRuleFile
@@ -1427,7 +1185,7 @@ var TARGETS = [
1427
1185
  detail: ".github/copilot-instructions.md",
1428
1186
  kind: "embed",
1429
1187
  alwaysDefault: false,
1430
- projectPath: (root) => join2(root, ".github", "copilot-instructions.md"),
1188
+ projectPath: (root) => join(root, ".github", "copilot-instructions.md"),
1431
1189
  globalPath: () => null,
1432
1190
  detect: (root) => anyExists(root, [".github"]),
1433
1191
  render: embedSection
@@ -1438,7 +1196,7 @@ var TARGETS = [
1438
1196
  detail: ".windsurf/rules/flypod.md",
1439
1197
  kind: "rules",
1440
1198
  alwaysDefault: false,
1441
- projectPath: (root) => join2(root, ".windsurf", "rules", `${SKILL_NAME}.md`),
1199
+ projectPath: (root) => join(root, ".windsurf", "rules", `${SKILL_NAME}.md`),
1442
1200
  globalPath: () => null,
1443
1201
  detect: (root) => anyExists(root, [".windsurf", ".windsurfrules"]),
1444
1202
  render: standaloneMarkdown
@@ -1449,7 +1207,7 @@ var TARGETS = [
1449
1207
  detail: ".clinerules/flypod.md",
1450
1208
  kind: "rules",
1451
1209
  alwaysDefault: false,
1452
- projectPath: (root) => join2(root, ".clinerules", `${SKILL_NAME}.md`),
1210
+ projectPath: (root) => join(root, ".clinerules", `${SKILL_NAME}.md`),
1453
1211
  globalPath: () => null,
1454
1212
  detect: (root) => anyExists(root, [".clinerules"]),
1455
1213
  render: standaloneMarkdown
@@ -1460,7 +1218,7 @@ var TARGETS = [
1460
1218
  detail: ".roo/rules/flypod.md",
1461
1219
  kind: "rules",
1462
1220
  alwaysDefault: false,
1463
- projectPath: (root) => join2(root, ".roo", "rules", `${SKILL_NAME}.md`),
1221
+ projectPath: (root) => join(root, ".roo", "rules", `${SKILL_NAME}.md`),
1464
1222
  globalPath: () => null,
1465
1223
  detect: (root) => anyExists(root, [".roo", ".roorules"]),
1466
1224
  render: standaloneMarkdown
@@ -1471,8 +1229,8 @@ var TARGETS = [
1471
1229
  detail: "GEMINI.md",
1472
1230
  kind: "embed",
1473
1231
  alwaysDefault: false,
1474
- projectPath: (root) => join2(root, "GEMINI.md"),
1475
- globalPath: () => join2(homedir2(), ".gemini", "GEMINI.md"),
1232
+ projectPath: (root) => join(root, "GEMINI.md"),
1233
+ globalPath: () => join(homedir(), ".gemini", "GEMINI.md"),
1476
1234
  detect: (root) => anyExists(root, ["GEMINI.md", ".gemini"]),
1477
1235
  render: embedSection
1478
1236
  }
@@ -1494,7 +1252,7 @@ ${section}
1494
1252
  }
1495
1253
  async function writeTarget(target, path) {
1496
1254
  const had = await exists(path);
1497
- const current = had ? await readFile3(path, "utf8") : "";
1255
+ const current = had ? await readFile2(path, "utf8") : "";
1498
1256
  let next;
1499
1257
  if (target.kind === "embed") {
1500
1258
  next = spliceBlock(current, target.render());
@@ -1503,8 +1261,8 @@ async function writeTarget(target, path) {
1503
1261
  }
1504
1262
  if (had && current === next)
1505
1263
  return { target, path, status: "unchanged" };
1506
- await mkdir2(dirname2(path), { recursive: true });
1507
- await writeFile2(path, next, "utf8");
1264
+ await mkdir(dirname(path), { recursive: true });
1265
+ await writeFile(path, next, "utf8");
1508
1266
  return { target, path, status: had ? "updated" : "created" };
1509
1267
  }
1510
1268
  async function buildPlan(root, env, global) {
@@ -1725,68 +1483,69 @@ var TARGET_FLAGS = {
1725
1483
  "--roo": "roo",
1726
1484
  "--gemini": "gemini"
1727
1485
  };
1486
+ var INSTALL_FLAG_SPEC = {
1487
+ "--all": "bool",
1488
+ "--global": "bool",
1489
+ "--list": "bool",
1490
+ "--dry-run": "bool",
1491
+ "--print": "bool",
1492
+ "--yes": "bool",
1493
+ "-y": "bool",
1494
+ ...Object.fromEntries(Object.keys(TARGET_FLAGS).map((f) => [f, "bool"]))
1495
+ };
1496
+ var TOP_LEVEL_FLAG_SPEC = {
1497
+ "--json": "bool",
1498
+ "-q": "bool",
1499
+ "--quiet": "bool",
1500
+ "-h": "bool",
1501
+ "--help": "bool",
1502
+ "-v": "bool",
1503
+ "--version": "bool",
1504
+ "--comments": "bool",
1505
+ "--mode": "value"
1506
+ };
1728
1507
  function parseArgs(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];
1739
- if (a === "--json")
1740
- out.json = true;
1741
- else if (a === "-q" || a === "--quiet")
1742
- out.quiet = true;
1743
- else if (a === "-h" || a === "--help")
1744
- out.help = true;
1745
- else if (a === "-v" || a === "--version")
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);
1753
- else if (a.startsWith("-")) {
1754
- process.stderr.write(`flypod: unknown flag "${a}"
1508
+ const { flags, positionals, unknown } = parseFlags(argv, TOP_LEVEL_FLAG_SPEC);
1509
+ if (unknown.length > 0) {
1510
+ process.stderr.write(`flypod: unknown flag "${unknown[0]}"
1755
1511
  Run \`flypod --help\` for usage.
1756
1512
  `);
1757
- process.exit(2);
1758
- } else if (!out.path)
1759
- out.path = a;
1513
+ process.exit(2);
1760
1514
  }
1761
- return out;
1515
+ return {
1516
+ path: positionals[0],
1517
+ json: Boolean(flags["--json"]),
1518
+ quiet: Boolean(flags["-q"] || flags["--quiet"]),
1519
+ help: Boolean(flags["-h"] || flags["--help"]),
1520
+ version: Boolean(flags["-v"] || flags["--version"]),
1521
+ comments: Boolean(flags["--comments"]),
1522
+ commentsMode: flags["--mode"] ?? "anonymous"
1523
+ };
1762
1524
  }
1525
+ var SUB_FLAG_SPEC = {
1526
+ "--site": "value",
1527
+ "--token": "value",
1528
+ "--json": "bool",
1529
+ "-q": "bool",
1530
+ "--quiet": "bool",
1531
+ "-h": "bool",
1532
+ "--help": "bool"
1533
+ };
1534
+ var LOGIN_FLAG_SPEC = {
1535
+ "--token": "value",
1536
+ "-h": "bool",
1537
+ "--help": "bool"
1538
+ };
1763
1539
  function parseSub(argv) {
1764
- const positionals = [];
1765
- let site;
1766
- let token;
1767
- let json = false;
1768
- let quiet = false;
1769
- let help = false;
1770
- for (let i = 0;i < argv.length; i++) {
1771
- const a = argv[i];
1772
- if (a === "--site" && i + 1 < argv.length)
1773
- site = argv[++i];
1774
- else if (a.startsWith("--site="))
1775
- site = a.slice("--site=".length);
1776
- else if (a === "--token" && i + 1 < argv.length)
1777
- token = argv[++i];
1778
- else if (a.startsWith("--token="))
1779
- token = a.slice("--token=".length);
1780
- else if (a === "--json")
1781
- json = true;
1782
- else if (a === "-q" || a === "--quiet")
1783
- quiet = true;
1784
- else if (a === "-h" || a === "--help")
1785
- help = true;
1786
- else if (!a.startsWith("-"))
1787
- positionals.push(a);
1788
- }
1789
- return { positionals, site, token, json, quiet, help };
1540
+ const { flags, positionals } = parseFlags(argv, SUB_FLAG_SPEC);
1541
+ return {
1542
+ positionals,
1543
+ site: flags["--site"],
1544
+ token: flags["--token"],
1545
+ json: Boolean(flags["--json"]),
1546
+ quiet: Boolean(flags["-q"] || flags["--quiet"]),
1547
+ help: Boolean(flags["-h"] || flags["--help"])
1548
+ };
1790
1549
  }
1791
1550
  async function runSubcommand(name, argv) {
1792
1551
  const io = {
@@ -1813,27 +1572,19 @@ async function runSubcommand(name, argv) {
1813
1572
  return forget({ site, help }, io);
1814
1573
  }
1815
1574
  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);
1575
+ const { flags } = parseFlags(argv, LOGIN_FLAG_SPEC);
1576
+ return login({
1577
+ token: flags["--token"],
1578
+ help: Boolean(flags["-h"] || flags["--help"])
1579
+ }, io);
1829
1580
  }
1830
1581
  case "logout":
1831
1582
  return logout({}, io);
1832
1583
  case "list":
1833
1584
  return list({}, io);
1834
1585
  case "claim": {
1835
- const positional = argv.filter((a) => !a.startsWith("-"));
1836
- return claim({ site_id: positional[0], token: positional[1] }, io);
1586
+ const { positionals } = parseFlags(argv, {});
1587
+ return claim({ site_id: positionals[0], token: positionals[1] }, io);
1837
1588
  }
1838
1589
  case "install":
1839
1590
  return runInstall(argv, io);
@@ -1845,7 +1596,7 @@ async function runSubcommand(name, argv) {
1845
1596
  }
1846
1597
  }
1847
1598
  function shortHome(path) {
1848
- const home = homedir3();
1599
+ const home = homedir2();
1849
1600
  return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
1850
1601
  }
1851
1602
  async function runInstall(argv, io) {
@@ -1857,33 +1608,23 @@ async function runInstall(argv, io) {
1857
1608
  io.err("with flypod by writing a small instruction file they read automatically.");
1858
1609
  return 2;
1859
1610
  }
1860
- const KNOWN_FLAGS = new Set([
1861
- "--all",
1862
- "--global",
1863
- "--list",
1864
- "--dry-run",
1865
- "--print",
1866
- "--yes",
1867
- "-y",
1868
- ...Object.keys(TARGET_FLAGS)
1869
- ]);
1870
- const unknownFlag = argv.find((a) => a.startsWith("-") && !KNOWN_FLAGS.has(a));
1611
+ const { flags, unknown } = parseFlags(argv, INSTALL_FLAG_SPEC);
1612
+ const unknownFlag = unknown[0];
1871
1613
  if (unknownFlag) {
1872
1614
  io.err(`flypod: unknown flag "${unknownFlag}"`);
1873
1615
  io.err("Run `flypod install skill --list` to see available targets and flags.");
1874
1616
  return 2;
1875
1617
  }
1876
- const has = (flag) => argv.includes(flag);
1877
1618
  const targets = [];
1878
1619
  for (const [flag, id] of Object.entries(TARGET_FLAGS)) {
1879
- if (has(flag) && !targets.includes(id))
1620
+ if (flags[flag] && !targets.includes(id))
1880
1621
  targets.push(id);
1881
1622
  }
1882
- const all = has("--all");
1883
- const global = has("--global");
1884
- const list2 = has("--list");
1885
- const dryRun = has("--dry-run") || has("--print");
1886
- const yes = has("--yes") || has("-y");
1623
+ const all = Boolean(flags["--all"]);
1624
+ const global = Boolean(flags["--global"]);
1625
+ const list2 = Boolean(flags["--list"]);
1626
+ const dryRun = Boolean(flags["--dry-run"] || flags["--print"]);
1627
+ const yes = Boolean(flags["--yes"] || flags["-y"]);
1887
1628
  const interactive = !list2 && !dryRun && !all && !yes && targets.length === 0 && canPrompt(process.stdin);
1888
1629
  const picker = interactive ? async (plan) => {
1889
1630
  const style = makeStyle(colorsEnabled(process.stderr));
@@ -1911,7 +1652,7 @@ async function readVersion() {
1911
1652
  for (const rel of ["../../package.json", "../package.json"]) {
1912
1653
  try {
1913
1654
  const url = new URL(rel, `file://${here}`);
1914
- const text = await readFile4(url, "utf8");
1655
+ const text = await readFile3(url, "utf8");
1915
1656
  const version = JSON.parse(text).version;
1916
1657
  if (version)
1917
1658
  return version;
@@ -1973,20 +1714,21 @@ Deploy flags:
1973
1714
  --comments --mode <mode> Same, but choose the mode: anonymous|passcode|
1974
1715
  approved.
1975
1716
 
1976
- Comments (v0.1):
1977
- flypod comments enable --site <id> [--mode anonymous|passcode|approved]
1717
+ Comments (off by default — enabling is one command):
1718
+ Every verb below takes the site from --site, or from the folder->site link
1719
+ recorded on your first deploy, so --site is optional inside a linked folder.
1720
+
1721
+ flypod comments enable [--site <id>] [--mode anonymous|passcode|approved]
1978
1722
  Enable comments on an existing site.
1979
- flypod comments mode <anonymous|passcode|approved> --site <id> [--passcode <s>]
1723
+ flypod comments mode <anonymous|passcode|approved> [--site <id>] [--passcode <s>]
1980
1724
  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>
1725
+ flypod comments off [--site <id>] Disable comments (data preserved).
1726
+ flypod comments list [<site>] List threads (--json for ND-JSON).
1727
+ flypod comments show [<site>] <thread_id> Print a thread with replies.
1728
+ flypod comments post [<site>] --page <p> --target <json> --body <text>
1729
+ Post a comment using your account session.
1730
+ flypod comments resolve [<site>] <thread_id> Mark a thread resolved.
1731
+ flypod comments reopen [<site>] <thread_id> Re-open a thread.
1990
1732
 
1991
1733
  Output:
1992
1734
  --json Emit a stable JSON result on stdout (for agents/scripts).
@@ -2012,6 +1754,21 @@ function shortDir(dir) {
2012
1754
  const rel = relative(process.cwd(), dir);
2013
1755
  return rel === "" || rel.startsWith("..") ? dir : rel || ".";
2014
1756
  }
1757
+ function fail2(msg, args, style, opts = {}) {
1758
+ if (args.json) {
1759
+ process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
1760
+ `);
1761
+ } else if (opts.dimOnly) {
1762
+ process.stderr.write(` ${style.dim(msg)}
1763
+
1764
+ `);
1765
+ } else {
1766
+ process.stderr.write(` ${style.err("✗")} ${msg}
1767
+
1768
+ `);
1769
+ }
1770
+ process.exit(1);
1771
+ }
2015
1772
  async function main() {
2016
1773
  const rawArgv = process.argv.slice(2);
2017
1774
  const version = await readVersion();
@@ -2031,7 +1788,8 @@ async function main() {
2031
1788
  `);
2032
1789
  return;
2033
1790
  }
2034
- const { apiKey, baseUrl } = await resolveAuth();
1791
+ const client = await createClient({});
1792
+ const { token: apiKey, baseUrl } = client;
2035
1793
  const useUI = !args.json && !args.quiet;
2036
1794
  const style = makeStyle(colorsEnabled(process.stderr) && useUI);
2037
1795
  if (useUI) {
@@ -2049,45 +1807,18 @@ async function main() {
2049
1807
  try {
2050
1808
  dir = await resolveDeployDir({ explicit: args.path });
2051
1809
  } catch (error) {
2052
- const msg = error.message;
2053
- if (args.json) {
2054
- process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
2055
- `);
2056
- } else {
2057
- process.stderr.write(` ${style.err("✗")} ${msg}
2058
-
2059
- `);
2060
- }
2061
- process.exit(1);
1810
+ fail2(error.message, args, style);
2062
1811
  }
2063
1812
  let files;
2064
1813
  try {
2065
1814
  files = await collectDist(dir);
2066
1815
  } catch (error) {
2067
- const msg = `Could not read ${shortDir(dir)}: ${error.message}`;
2068
- if (args.json) {
2069
- process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
2070
- `);
2071
- } else {
2072
- process.stderr.write(` ${style.err("✗")} ${msg}
2073
-
2074
- `);
2075
- }
2076
- process.exit(1);
1816
+ fail2(`Could not read ${shortDir(dir)}: ${error.message}`, args, style);
2077
1817
  }
2078
1818
  const fileNames = Object.keys(files);
2079
1819
  const totalBytes = fileNames.reduce((sum, name) => sum + (files[name]?.byteLength ?? 0), 0);
2080
1820
  if (fileNames.length === 0) {
2081
- const msg = `No files found in ${shortDir(dir)}.`;
2082
- if (args.json) {
2083
- process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
2084
- `);
2085
- } else {
2086
- process.stderr.write(` ${style.err("✗")} ${msg}
2087
-
2088
- `);
2089
- }
2090
- process.exit(1);
1821
+ fail2(`No files found in ${shortDir(dir)}.`, args, style);
2091
1822
  }
2092
1823
  if (useUI) {
2093
1824
  process.stderr.write(` ${style.muted("source")} ${style.bold(shortDir(dir))} ${style.dim(`${fmtCount(fileNames.length, "file")} · ${fmtBytes(totalBytes)}`)}
@@ -2101,16 +1832,7 @@ async function main() {
2101
1832
  result = await deploySite({ baseUrl, files, apiKey });
2102
1833
  } catch (error) {
2103
1834
  spinner.fail("Deploy failed.");
2104
- const msg = error.message;
2105
- if (args.json) {
2106
- process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
2107
- `);
2108
- } else {
2109
- process.stderr.write(` ${style.dim(msg)}
2110
-
2111
- `);
2112
- }
2113
- process.exit(1);
1835
+ fail2(error.message, args, style, { dimOnly: true });
2114
1836
  }
2115
1837
  const elapsed = Date.now() - started;
2116
1838
  spinner.success(`Deployed in ${fmtSeconds(elapsed)}`);
@@ -2137,18 +1859,14 @@ async function main() {
2137
1859
  try {
2138
1860
  const allowed = new Set(["anonymous", "passcode", "approved", "open", "review", "members"]);
2139
1861
  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
- });
1862
+ const cr = await client.setCommentsMode(result.site_id, { enabled: true, mode });
2145
1863
  commentsEnabled = cr.ok;
2146
1864
  if (useUI) {
2147
1865
  if (cr.ok) {
2148
1866
  process.stderr.write(` ${style.muted("comments")} ${style.dim(`enabled (${mode})`)}
2149
1867
  `);
2150
1868
  } else {
2151
- process.stderr.write(` ${style.muted("comments")} ${style.dim("failed to enable — run `flypod comments enable --site " + result.site_id + "`")}
1869
+ process.stderr.write(` ${style.muted("comments")} ${style.dim(`failed to enable — run \`flypod comments enable --site ${result.site_id}\``)}
2152
1870
  `);
2153
1871
  }
2154
1872
  }