flypod 0.18.0 → 0.19.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.
@@ -13,7 +13,9 @@ import {
13
13
  classifyResponse,
14
14
  clearSession,
15
15
  collectFiles,
16
+ configDir,
16
17
  createClient,
18
+ detectCodingAgent,
17
19
  emitError,
18
20
  errorEnvelope,
19
21
  exitCodeFor,
@@ -45,10 +47,10 @@ import {
45
47
  unauthorizedFor,
46
48
  unexpectedError,
47
49
  uploadLimitsFor
48
- } from "../cli-4d5fkx95.js";
50
+ } from "../cli-qtqg73w5.js";
49
51
 
50
52
  // bin/deploy.ts
51
- import { readFile as readFile3, stat as stat4 } from "node:fs/promises";
53
+ import { readFile as readFile4, stat as stat4 } from "node:fs/promises";
52
54
  import { homedir } from "node:os";
53
55
  import { relative as relative3, resolve as resolve3 } from "node:path";
54
56
  import { fileURLToPath } from "node:url";
@@ -626,8 +628,33 @@ async function withFolderHint(err, cwd, deployed, opts = {}) {
626
628
  return { ...err, fix, telemetry };
627
629
  }
628
630
 
631
+ // src/cli/pending-login.ts
632
+ import { readFile as readFile2, rm } from "node:fs/promises";
633
+ import { join as join3 } from "node:path";
634
+ function pendingLoginPath(env = process.env) {
635
+ return join3(configDir(env), "pending-login.json");
636
+ }
637
+ async function savePendingLogin(pending, env = process.env) {
638
+ await atomicWriteFile(pendingLoginPath(env), `${JSON.stringify(pending)}
639
+ `);
640
+ }
641
+ async function loadPendingLogin(env = process.env, now = Date.now()) {
642
+ try {
643
+ const raw = JSON.parse(await readFile2(pendingLoginPath(env), "utf8"));
644
+ if (!raw || typeof raw.device_code !== "string" || typeof raw.base_url !== "string" || typeof raw.expires_at !== "number") {
645
+ return null;
646
+ }
647
+ return raw.expires_at > now ? raw : null;
648
+ } catch {
649
+ return null;
650
+ }
651
+ }
652
+ async function clearPendingLogin(env = process.env) {
653
+ await rm(pendingLoginPath(env), { force: true }).catch(() => {});
654
+ }
655
+
629
656
  // src/cli/projects.ts
630
- import { readFile as readFile2 } from "node:fs/promises";
657
+ import { readFile as readFile3 } from "node:fs/promises";
631
658
  import { sep } from "node:path";
632
659
  var MAX_PROJECTS = 64;
633
660
  function prune(projects, now) {
@@ -658,7 +685,7 @@ async function loadProjects(env) {
658
685
  }
659
686
  async function loadFile(env) {
660
687
  try {
661
- const text = await readFile2(projectsFilePath(env), "utf8");
688
+ const text = await readFile3(projectsFilePath(env), "utf8");
662
689
  const parsed = JSON.parse(text);
663
690
  if (!parsed || typeof parsed !== "object" || typeof parsed.projects !== "object")
664
691
  return null;
@@ -861,20 +888,20 @@ function versionsTable(opts) {
861
888
  function relinkNotice(prev, style) {
862
889
  const s = style ?? PLAIN;
863
890
  return [
864
- ` ${(s.warn ?? ((x) => x))("!")} ${s.bold("This folder already deploys to")}`,
891
+ ` ${s.dim("--new: a separate site. The earlier one stays live at")}`,
865
892
  ` ${s.accent(prev.url)}`,
866
- ` ${s.bold("flypod update")}${s.dim(" ships there. This run makes a second site.")}`
893
+ ` ${s.dim("and this folder now updates the new one.")}`
867
894
  ];
868
895
  }
869
896
  var RELINK_WARNING = "new-site-in-linked-folder";
870
897
  function relinkWarning(prev, newUrl) {
871
898
  return {
872
899
  code: RELINK_WARNING,
873
- fix_recipe: `This folder already deployed to ${prev.url}, so \`flypod\` made a second site (${newUrl}, live now; nothing to redo). ` + "To ship changes to a site you already have, run `flypod update`, never `flypod` again. " + `To put this build on the earlier URL instead: \`flypod update --site ${prev.site_id}\`.`
900
+ fix_recipe: `\`--new\` made a separate site (${newUrl}, live now; nothing to redo). The earlier site ${prev.url} stays live, ` + "and this folder now updates the new one: run `flypod` again to ship changes here. " + `To ship to the earlier URL instead: \`flypod update --site ${prev.site_id}\`.`
874
901
  };
875
902
  }
876
903
  function relinkHint(prev) {
877
- return `flypod: this folder already deploys to ${prev.url}; this run makes a second site. Use \`flypod update\` to ship there.`;
904
+ return `flypod: --new made a separate site; the earlier one stays live at ${prev.url}.`;
878
905
  }
879
906
  function skippedRows(skipped, style) {
880
907
  if (skipped.length === 0)
@@ -905,7 +932,7 @@ function agentNext(opts) {
905
932
  const target = linked ? "" : ` --site ${opts.siteId}`;
906
933
  const update = `flypod update${target}`;
907
934
  const linkNote = linked ? `This folder is linked to ${opts.siteId}.` : `The folder → site link could not be saved, so every command needs --site ${opts.siteId}.`;
908
- const expiryNote = expiring ? "The site stops serving on the date above unless `flypod login` claims it, which removes the expiry and changes nothing else." : "This site does not expire.";
935
+ const expiryNote = expiring ? "The site stops serving on the date above unless it is kept: run `flypod login --json` and give your user the URL it returns; once they confirm, the next flypod command finishes signing in and keeps every site on this machine (no expiry, nothing else changes)." : "This site does not expire.";
909
936
  return {
910
937
  expires_in_days: expiring ? daysUntil(opts.expiresAt, now) : null,
911
938
  expires_at_iso: expiring ? new Date(opts.expiresAt).toISOString() : null,
@@ -913,9 +940,9 @@ function agentNext(opts) {
913
940
  update,
914
941
  versions: `flypod versions${target}`,
915
942
  rollback: `flypod rollback${target}`,
916
- ...expiring ? { keep: "flypod login" } : {}
943
+ ...expiring ? { keep: "flypod login --json" } : {}
917
944
  },
918
- next_note: `${linkNote} Run \`${update}\` to publish changes to this same URL — running \`flypod\` again creates a different site at a different URL. ${expiryNote}`
945
+ next_note: `${linkNote} Run \`${update}\`${linked ? " (or plain `flypod` again: in a linked folder it updates)" : ""} to publish changes to this same URL; \`flypod --new\` makes a separate site. ${expiryNote}`
919
946
  };
920
947
  }
921
948
 
@@ -928,7 +955,8 @@ function siteUrlFrom(site_id, baseUrl) {
928
955
  var SUBCOMMAND_HELP = {
929
956
  update: `flypod update [path] [flags]
930
957
 
931
- Ship a new version of the site linked to this folder.
958
+ Ship a new version of the site linked to this folder. Plain \`flypod\` in a
959
+ linked folder does the same; \`flypod --new\` makes a separate site instead.
932
960
 
933
961
  flypod update Re-deploy this folder as a new version.
934
962
  flypod update ./dist Same, with an explicit path.
@@ -1016,13 +1044,15 @@ Authenticate with flypod via the browser (device authorization).
1016
1044
  code, then waits for the browser confirmation.
1017
1045
  flypod login --token <t> Save a session token directly (for agents/CI).
1018
1046
  flypod login --json Agents: print the URL, code, and device_code as
1019
- JSON and exit at once instead of waiting.
1047
+ JSON and exit at once instead of waiting. Once
1048
+ the user confirms, the next flypod command
1049
+ finishes signing in by itself.
1020
1050
  flypod login --device-code <c>
1021
- Finish a --json login once the user confirmed.
1051
+ Finish a --json login now (waits up to 25s).
1022
1052
 
1023
1053
  Flags:
1024
1054
  --token <t> Save this session token instead of opening a browser.
1025
- --device-code <c> Poll once for the approval of a sign-in started with --json.
1055
+ --device-code <c> Wait up to 25s for the approval of a sign-in started with --json.
1026
1056
  --json Emit JSON on stdout; never blocks waiting for a browser.
1027
1057
  -h, --help Show this help.`,
1028
1058
  logout: `flypod logout [--json]
@@ -1136,6 +1166,58 @@ async function finishLogin(accessToken, baseUrl, args, io, env) {
1136
1166
  io.out(JSON.stringify({ ok: true, logged_in: true, ...attached }));
1137
1167
  return 0;
1138
1168
  }
1169
+ var RESUME_WAIT_MS = 25000;
1170
+ var RESUME_POLL_MS = 5000;
1171
+ async function markPendingDone(deviceCode, env) {
1172
+ const pending = await loadPendingLogin(env);
1173
+ if (pending?.device_code !== deviceCode)
1174
+ return;
1175
+ await savePendingLogin({ ...pending, completed: true }, env).catch(() => {});
1176
+ }
1177
+ async function resumePendingLogin(io, opts) {
1178
+ const env = io.env ?? process.env;
1179
+ const pending = await loadPendingLogin(env);
1180
+ if (!pending || pending.completed)
1181
+ return;
1182
+ const session = await loadSession(env).catch(() => null);
1183
+ if (resolveCredentials(env, session).token)
1184
+ return;
1185
+ const client = await createClient({
1186
+ env,
1187
+ fetch: io.fetch,
1188
+ overrides: { baseUrl: pending.base_url }
1189
+ });
1190
+ let poll;
1191
+ try {
1192
+ poll = await withDeadline(pollDeviceToken(client, pending.device_code), RESUME_DEADLINE_MS);
1193
+ } catch {
1194
+ return;
1195
+ }
1196
+ if (poll.state === "approved") {
1197
+ await saveSession({ session_token: poll.access_token, base_url: pending.base_url, created_at: Date.now() }, env);
1198
+ await savePendingLogin({ ...pending, completed: true }, env).catch(() => {});
1199
+ const silent = { ...io, out: () => {}, err: () => {} };
1200
+ const kept = await attachAnonymousSites(poll.access_token, pending.base_url, { json: true }, silent, env).catch(() => ({ attached: [] }));
1201
+ if (!opts.quiet) {
1202
+ const n = kept.attached.length;
1203
+ io.err(headline("Signed in", n > 0 ? `${n} site${n === 1 ? "" : "s"} kept, no expiry` : undefined, io.style ?? PLAIN));
1204
+ }
1205
+ return;
1206
+ }
1207
+ if (poll.state === "denied" || poll.state === "expired" || poll.state === "invalid") {
1208
+ await clearPendingLogin(env);
1209
+ }
1210
+ }
1211
+ var RESUME_DEADLINE_MS = 2500;
1212
+ function withDeadline(p, ms) {
1213
+ let timer;
1214
+ return Promise.race([
1215
+ p,
1216
+ new Promise((_, reject) => {
1217
+ timer = setTimeout(() => reject(new Error("deadline")), ms);
1218
+ })
1219
+ ]).finally(() => clearTimeout(timer));
1220
+ }
1139
1221
  async function login(args, io) {
1140
1222
  if (args.help)
1141
1223
  return showSubHelp("login", io, args);
@@ -1149,13 +1231,39 @@ async function login(args, io) {
1149
1231
  }
1150
1232
  const client = await createClient({ env, fetch: io.fetch, overrides: { baseUrl } });
1151
1233
  if (args.deviceCode) {
1234
+ const remembered = await loadPendingLogin(env);
1235
+ if (remembered?.completed && remembered.device_code === args.deviceCode) {
1236
+ const session = await loadSession(env).catch(() => null);
1237
+ if (session?.session_token) {
1238
+ if (args.json)
1239
+ io.out(JSON.stringify({ ok: true, logged_in: true, attached: [], skipped: [] }));
1240
+ else
1241
+ io.err(headline("Logged in", undefined, io.style ?? PLAIN));
1242
+ return 0;
1243
+ }
1244
+ }
1245
+ let waited = 0;
1152
1246
  let poll;
1153
- try {
1154
- poll = await pollDeviceToken(client, args.deviceCode);
1155
- } catch (e) {
1156
- return emitError(networkError(e, baseUrl), args, io, { prefix: "flypod login" });
1247
+ for (;; ) {
1248
+ try {
1249
+ poll = await pollDeviceToken(client, args.deviceCode);
1250
+ } catch (e) {
1251
+ return emitError(networkError(e, baseUrl), args, io, { prefix: "flypod login" });
1252
+ }
1253
+ const waiting = poll.state === "pending" || poll.state === "slow_down";
1254
+ const pause = poll.state === "slow_down" ? RESUME_POLL_MS * 2 : RESUME_POLL_MS;
1255
+ if (!waiting || waited + pause > RESUME_WAIT_MS)
1256
+ break;
1257
+ await (io.sleep ?? delay)(pause);
1258
+ waited += pause;
1157
1259
  }
1158
- return poll.state === "approved" ? finishLogin(poll.access_token, baseUrl, args, io, env) : emitError(await loginPollError(poll, args.deviceCode, args), args, io, {
1260
+ if (poll.state === "approved") {
1261
+ await markPendingDone(args.deviceCode, env);
1262
+ return finishLogin(poll.access_token, baseUrl, args, io, env);
1263
+ }
1264
+ if (poll.state !== "pending" && poll.state !== "slow_down")
1265
+ await clearPendingLogin(env);
1266
+ return emitError(await loginPollError(poll, args.deviceCode, args), args, io, {
1159
1267
  prefix: "flypod login"
1160
1268
  });
1161
1269
  }
@@ -1171,11 +1279,17 @@ async function login(args, io) {
1171
1279
  }
1172
1280
  const start = await startRes.json();
1173
1281
  const openUrl = start.verification_uri_complete ?? `${start.verification_uri}?user_code=${encodeURIComponent(start.user_code)}`;
1174
- if (args.json) {
1282
+ const agentWithoutTerminal = !io.interactive && detectCodingAgent(env) !== "none";
1283
+ if (args.json || agentWithoutTerminal) {
1284
+ await savePendingLogin({
1285
+ device_code: start.device_code,
1286
+ base_url: baseUrl,
1287
+ expires_at: Date.now() + (start.expires_in ?? 600) * 1000
1288
+ }, env).catch(() => {});
1175
1289
  return emitError({
1176
1290
  code: "interactive_login_required",
1177
1291
  error: "Sign-in needs a browser. Ask the user to open the URL and confirm the code.",
1178
- fix: `Ask the user to open ${openUrl} and confirm code ${start.user_code}. Then run \`flypod login --device-code ${start.device_code} --json\`; while it answers authorization_pending, wait ${start.interval ?? 5}s and run it again.`,
1292
+ fix: `Ask the user to open ${openUrl} and confirm code ${start.user_code}. Once they have, your next flypod command (a deploy, \`flypod list\`, anything) finishes signing in by itself; to finish it now, run \`flypod login --device-code ${start.device_code} --json\`, which waits up to ${RESUME_WAIT_MS / 1000}s for the confirmation.`,
1179
1293
  extra: {
1180
1294
  verification_uri: start.verification_uri,
1181
1295
  verification_uri_complete: openUrl,
@@ -1313,6 +1427,7 @@ async function logout(args, io) {
1313
1427
  return showSubHelp("logout", io, args);
1314
1428
  const env = io.env ?? process.env;
1315
1429
  const ok = await clearSession(env);
1430
+ await clearPendingLogin(env);
1316
1431
  if (args.json) {
1317
1432
  io.out(JSON.stringify({ ok: true, signed_out: ok }));
1318
1433
  return 0;
@@ -1398,11 +1513,11 @@ async function resolveTarget(args, io) {
1398
1513
  const env = io.env ?? process.env;
1399
1514
  if (args.site) {
1400
1515
  const known = await projectForSite(args.site, env).catch(() => null);
1401
- return { site_id: args.site, rec: known, dir: null };
1516
+ return { site_id: args.site, rec: known, dir: null, named: "flag" };
1402
1517
  }
1403
1518
  const cwd = io.cwd ?? process.cwd();
1404
1519
  const rec = await projectForDir(cwd, env);
1405
- return rec ? { site_id: rec.site_id, rec, dir: cwd } : null;
1520
+ return rec ? { site_id: rec.site_id, rec, dir: cwd, named: "link" } : null;
1406
1521
  }
1407
1522
  async function withTarget(name, args, io) {
1408
1523
  if (args.help)
@@ -1450,9 +1565,12 @@ async function failSiteRequest(verb, res, target, args, io, env, opts = {}) {
1450
1565
  siteId: target.site_id,
1451
1566
  sent: credentialSent(target, args, opts.client),
1452
1567
  known: target.rec !== null,
1568
+ target: target.named,
1453
1569
  status: err.status
1454
1570
  });
1455
1571
  }
1572
+ if (opts.fixSuffix && err.fix)
1573
+ err = { ...err, fix: `${err.fix}${opts.fixSuffix}` };
1456
1574
  return emitError(err, args, io, { prefix: verb });
1457
1575
  }
1458
1576
  function credentialSent(target, args, client) {
@@ -1581,7 +1699,7 @@ function shortPath(path, cwd) {
1581
1699
  return path;
1582
1700
  return rel.startsWith("..") ? rel : `./${rel}`;
1583
1701
  }
1584
- async function update(args, io) {
1702
+ async function update(args, io, opts = {}) {
1585
1703
  const pre = await withTarget("update", args, io);
1586
1704
  if (typeof pre === "number")
1587
1705
  return pre;
@@ -1646,19 +1764,27 @@ async function update(args, io) {
1646
1764
  return emitError(sent.err, args, io, { prefix: "flypod update" });
1647
1765
  const { client } = sent;
1648
1766
  if (sent.kind === "refused") {
1767
+ if (sent.res.status === 404 && opts.whenGone && target.dir) {
1768
+ await sent.res.body?.cancel().catch(() => {});
1769
+ await forgetDir(target.dir, env, { gone: true });
1770
+ return opts.whenGone();
1771
+ }
1649
1772
  return failSiteRequest("flypod update", sent.res, target, args, io, env, {
1650
1773
  upload: () => uploadReport(files, skipped.length),
1651
- client
1774
+ client,
1775
+ fixSuffix: opts.fromDeploy ? " To make a separate new site from this folder instead, run `flypod --new`." : undefined
1652
1776
  });
1653
1777
  }
1654
1778
  const { body } = sent;
1655
1779
  await touchLink(target, body.version_id, env, resolve2(dir));
1656
1780
  const switched = args.timeline === undefined ? undefined : await switchTimeline(client, target.site_id, args.timeline);
1657
1781
  const timeline = switched?.timeline;
1782
+ const extra = opts.extra ? await opts.extra(target.site_id) : undefined;
1658
1783
  const expiresAt = body.expires_at !== undefined ? body.expires_at : target.rec?.expires_at ?? null;
1659
1784
  if (args.json) {
1660
1785
  io.out(JSON.stringify({
1661
1786
  ok: true,
1787
+ action: "updated",
1662
1788
  site_id: target.site_id,
1663
1789
  version_id: body.version_id,
1664
1790
  url: body.url,
@@ -1667,6 +1793,7 @@ async function update(args, io) {
1667
1793
  expires_at: expiresAt,
1668
1794
  ...skipped.length > 0 ? { skipped } : {},
1669
1795
  ...switched ?? {},
1796
+ ...extra?.json ?? {},
1670
1797
  ...(args.verbose ? agentNext : agentNextCommands)({
1671
1798
  siteId: target.site_id,
1672
1799
  expiresAt,
@@ -1691,6 +1818,8 @@ async function update(args, io) {
1691
1818
  })) {
1692
1819
  io.err(line);
1693
1820
  }
1821
+ for (const line of extra?.lines ?? [])
1822
+ io.err(line);
1694
1823
  if (timeline !== undefined) {
1695
1824
  for (const line of timelineRows(args.timeline, timeline, io.style ?? PLAIN, switched?.history_url)) {
1696
1825
  io.err(line);
@@ -2537,7 +2666,8 @@ var TOP_LEVEL_FLAG_SPEC = {
2537
2666
  "--timeline": "bool",
2538
2667
  "--no-timeline": "bool",
2539
2668
  "--history": "bool",
2540
- "--no-history": "bool"
2669
+ "--no-history": "bool",
2670
+ "--new": "bool"
2541
2671
  };
2542
2672
  var COMMENT_MODES = ["anonymous", "passcode", "approved", "open", "review", "members"];
2543
2673
  function exitUsage(err, argv) {
@@ -2590,7 +2720,8 @@ function parseArgs(argv) {
2590
2720
  comments: Boolean(flags["--comments"]),
2591
2721
  commentsMode: mode ?? "anonymous",
2592
2722
  verbose: Boolean(flags["--verbose"]),
2593
- timeline: timelineFlag(flags)
2723
+ timeline: timelineFlag(flags),
2724
+ newSite: Boolean(flags["--new"])
2594
2725
  };
2595
2726
  }
2596
2727
  var SUB_FLAG_SPEC = {
@@ -2766,7 +2897,7 @@ async function readVersion() {
2766
2897
  for (const rel of ["../../package.json", "../package.json"]) {
2767
2898
  try {
2768
2899
  const url = new URL(rel, `file://${here}`);
2769
- const text = await readFile3(url, "utf8");
2900
+ const text = await readFile4(url, "utf8");
2770
2901
  const version = JSON.parse(text).version;
2771
2902
  if (version)
2772
2903
  return version;
@@ -2779,13 +2910,15 @@ function helpText(version) {
2779
2910
  Drop files, get a live URL. Every deploy is versioned, so you can roll back.
2780
2911
 
2781
2912
  THE LOOP (this is all most agents need):
2782
- flypod [path] Deploy NEW content -> creates a new site, prints a URL.
2913
+ flypod [path] Deploy. The first time in a folder it creates a site
2914
+ and prints a URL; after that it updates that site.
2783
2915
  flypod update Ship CHANGES to that same site -> adds a new VERSION.
2784
2916
  flypod versions List every version, newest first (the live one is marked).
2785
2917
  flypod rollback Make the previous version live again.
2786
2918
 
2787
- A "version" is one deploy of a set of files. 'flypod' makes a brand-new site;
2788
- 'flypod update' adds a version to the site you already made. flypod remembers
2919
+ A "version" is one deploy of a set of files. 'flypod' makes a site the first
2920
+ time and adds a version every time after; 'flypod --new' makes a separate site
2921
+ even when the folder already has one. flypod remembers
2789
2922
  which site a folder belongs to (stored under your home config, never in your
2790
2923
  repo), so 'update'/'versions'/'rollback' just work from that folder. To target
2791
2924
  a site from anywhere, pass --site <id> (the id is printed on first deploy).
@@ -2850,6 +2983,9 @@ Agents:
2850
2983
  -y/--yes to write every target without asking.
2851
2984
 
2852
2985
  Deploy flags:
2986
+ --new Make a separate new site, even though this
2987
+ folder already has one. The earlier site stays
2988
+ live, and this folder then updates the new one.
2853
2989
  --timeline Turn on History: a chip on the site's pages
2854
2990
  that opens earlier versions, and a page that
2855
2991
  compares two side by side. Off by default: it
@@ -2959,6 +3095,54 @@ async function firstRunNotice(argv) {
2959
3095
 
2960
3096
  `);
2961
3097
  }
3098
+ var LINK_GONE = -1;
3099
+ async function deployAsUpdate(args, link, session, style, useUI) {
3100
+ if (useUI) {
3101
+ process.stderr.write(` ${style.dim("Updating this folder's site")} ${style.accent(link.url)}
3102
+ ` + ` ${style.dim("For a separate new site: flypod --new")}
3103
+
3104
+ `);
3105
+ }
3106
+ return update({
3107
+ path: args.path,
3108
+ json: args.json,
3109
+ quiet: args.quiet,
3110
+ verbose: args.verbose,
3111
+ timeline: args.timeline
3112
+ }, {
3113
+ out: (line) => process.stdout.write(`${line}
3114
+ `),
3115
+ err: (line) => process.stderr.write(`${line}
3116
+ `),
3117
+ interactive: Boolean(process.stdout.isTTY),
3118
+ style: makeStyle(colorsEnabled(process.stderr))
3119
+ }, {
3120
+ fromDeploy: true,
3121
+ whenGone: async () => LINK_GONE,
3122
+ extra: args.comments ? (siteId) => enableCommentsAfterUpdate(session, siteId, args) : undefined
3123
+ });
3124
+ }
3125
+ async function enableCommentsAfterUpdate(session, siteId, args) {
3126
+ const mode = args.commentsMode;
3127
+ if (!session.token) {
3128
+ return {
3129
+ json: {
3130
+ comments_enabled: false,
3131
+ comments_mode: mode,
3132
+ comments_skipped: "not_signed_in",
3133
+ comments_fix: "Run `flypod login`, then `flypod comments enable`."
3134
+ },
3135
+ lines: [" comments skipped — run `flypod login` to enable comments"]
3136
+ };
3137
+ }
3138
+ const ok = await session.setCommentsMode(siteId, { enabled: true, mode }).then((r) => r.ok).catch(() => false);
3139
+ return {
3140
+ json: { comments_enabled: ok, comments_mode: mode },
3141
+ lines: [
3142
+ ` comments ${ok ? `enabled (${mode})` : "failed — run `flypod comments enable`"}`
3143
+ ]
3144
+ };
3145
+ }
2962
3146
  async function main() {
2963
3147
  const rawArgv = process.argv.slice(2);
2964
3148
  const version = await readVersion();
@@ -2974,6 +3158,15 @@ async function main() {
2974
3158
  });
2975
3159
  if (!answersLocally)
2976
3160
  await firstRunNotice(rawArgv);
3161
+ const verb = isSubcommand ? firstPositional : "deploy";
3162
+ if (!answersLocally && verb !== "login" && verb !== "logout") {
3163
+ await resumePendingLogin({
3164
+ out: () => {},
3165
+ err: (line) => process.stderr.write(`${line}
3166
+ `),
3167
+ style: makeStyle(colorsEnabled(process.stderr))
3168
+ }, { quiet: rawArgv.some((a) => a === "--json" || a === "-q" || a === "--quiet") }).catch(() => {});
3169
+ }
2977
3170
  if (isSubcommand) {
2978
3171
  const code = await runSubcommand(firstPositional, withoutVerb);
2979
3172
  await flushFailureReports();
@@ -2995,11 +3188,11 @@ async function main() {
2995
3188
  const style = makeStyle(colorsEnabled(process.stderr) && useUI);
2996
3189
  if (args.path !== undefined && !await exists(args.path)) {
2997
3190
  const bareWord = /^[a-z]+$/i.test(args.path) && !BUILD_DIR_CANDIDATES.includes(args.path);
2998
- const verb = bareWord ? closest(args.path, [...SUBCOMMANDS]) : undefined;
2999
- fail2(verb ? {
3191
+ const verb2 = bareWord ? closest(args.path, [...SUBCOMMANDS]) : undefined;
3192
+ fail2(verb2 ? {
3000
3193
  code: "unknown_command",
3001
- error: `unknown command "${args.path}" — did you mean \`flypod ${verb}\`?`,
3002
- fix: `flypod ${verb}`
3194
+ error: `unknown command "${args.path}" — did you mean \`flypod ${verb2}\`?`,
3195
+ fix: `flypod ${verb2}`
3003
3196
  } : await withFolderHint({
3004
3197
  code: "no_build_dir",
3005
3198
  error: `Nothing to deploy at ${args.path}: no such file or folder.`,
@@ -3007,6 +3200,15 @@ async function main() {
3007
3200
  }, process.cwd()), args, style);
3008
3201
  }
3009
3202
  const priorLink = await projectForDir(process.cwd()).catch(() => null);
3203
+ let linked = priorLink;
3204
+ if (priorLink && !args.newSite) {
3205
+ const code = await deployAsUpdate(args, priorLink, client, style, useUI);
3206
+ if (code !== LINK_GONE) {
3207
+ await flushFailureReports();
3208
+ process.exit(code);
3209
+ }
3210
+ linked = null;
3211
+ }
3010
3212
  let dir;
3011
3213
  try {
3012
3214
  const remembered = args.path === undefined && priorLink?.deploy_dir && await exists(priorLink.deploy_dir) ? priorLink.deploy_dir : undefined;
@@ -3040,14 +3242,14 @@ async function main() {
3040
3242
  });
3041
3243
  if (tooLarge)
3042
3244
  fail2(tooLarge, args, style);
3043
- if (priorLink && useUI) {
3044
- for (const line of relinkNotice(priorLink, style))
3245
+ if (linked && useUI) {
3246
+ for (const line of relinkNotice(linked, style))
3045
3247
  process.stderr.write(`${line}
3046
3248
  `);
3047
3249
  process.stderr.write(`
3048
3250
  `);
3049
- } else if (priorLink && args.quiet) {
3050
- process.stderr.write(`${relinkHint(priorLink)}
3251
+ } else if (linked && args.quiet) {
3252
+ process.stderr.write(`${relinkHint(linked)}
3051
3253
  `);
3052
3254
  }
3053
3255
  if (useUI)
@@ -3059,7 +3261,7 @@ async function main() {
3059
3261
  const started = Date.now();
3060
3262
  let result;
3061
3263
  try {
3062
- const res = await client.createSite(packDeploy(files), { relink: Boolean(priorLink) });
3264
+ const res = await client.createSite(packDeploy(files), { relink: Boolean(linked) });
3063
3265
  if (!res.ok)
3064
3266
  throw await DeployError.fromResponse(res);
3065
3267
  result = await res.json();
@@ -3126,10 +3328,10 @@ async function main() {
3126
3328
  healed: result.healed ?? [],
3127
3329
  warnings: [
3128
3330
  ...result.warnings ?? [],
3129
- ...priorLink && priorLink.site_id !== result.site_id ? [relinkWarning(priorLink, result.url)] : []
3331
+ ...linked && linked.site_id !== result.site_id ? [relinkWarning(linked, result.url)] : []
3130
3332
  ],
3131
3333
  link_saved: linkSaved,
3132
- ...priorLink && priorLink.site_id !== result.site_id ? { replaced_link: { site_id: priorLink.site_id, url: priorLink.url } } : {},
3334
+ ...linked && linked.site_id !== result.site_id ? { replaced_link: { site_id: linked.site_id, url: linked.url } } : {},
3133
3335
  ...args.comments ? {
3134
3336
  comments_enabled: commentsEnabled,
3135
3337
  comments_mode: args.commentsMode,
@@ -3149,6 +3351,7 @@ async function main() {
3149
3351
  };
3150
3352
  const receipt = args.verbose ? {
3151
3353
  ok: true,
3354
+ action: "created",
3152
3355
  url: result.url,
3153
3356
  site_id: result.site_id,
3154
3357
  version_id: result.version_id,
@@ -3164,6 +3367,7 @@ async function main() {
3164
3367
  ...agentNext(nextOpts)
3165
3368
  } : {
3166
3369
  ok: true,
3370
+ action: "created",
3167
3371
  url: result.url,
3168
3372
  site_id: result.site_id,
3169
3373
  version_id: result.version_id,