@foleo/cli 0.1.28 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,14 +8,25 @@ import { lstat, readdir } from "node:fs/promises";
8
8
  import { createServer } from "node:http";
9
9
  import { dirname, join, relative, resolve, sep } from "node:path";
10
10
  import { fileURLToPath, pathToFileURL } from "node:url";
11
- import { FoleoError, LocalError, renderFailure, UsageError } from "./errors.js";
11
+ import { FoleoError, LocalError, renderFailure, toFoleoError, UsageError, } from "./errors.js";
12
12
  import { deriveArtifactName, resolveHtmlTitle, resolveVisibility, } from "./plan.js";
13
13
  const KEYCHAIN_SERVICE = "com.contraverse.foleo.cli";
14
+ /**
15
+ * Scopes a normal `foleo login` asks for.
16
+ *
17
+ * `artifacts:delete` is here, not behind an opt-in, because delete is
18
+ * REVERSIBLE: it stops serving immediately and holds the bytes for a 30-day
19
+ * restore window (spec 082). Gating it like purge taught people that the two
20
+ * are equally dangerous, and made the ordinary "remove this" job fail with a
21
+ * scope error until you knew to re-run login with a flag you had not heard of.
22
+ * `artifacts:purge` stays opt-in — that one is irreversible.
23
+ */
14
24
  const CLI_KEY_SCOPES = [
15
25
  "artifacts:read",
16
26
  "artifacts:publish",
17
27
  "artifacts:settings",
18
28
  "artifacts:unpublish",
29
+ "artifacts:delete",
19
30
  "docs:write",
20
31
  "docs:unpublish",
21
32
  "html:write",
@@ -43,10 +54,45 @@ export const SETTINGS_SURFACE_FIELD_IDS = [
43
54
  "titleUserSet",
44
55
  "slug",
45
56
  "slugUserSet",
57
+ "frontmatterDisplay",
46
58
  "visibility",
47
59
  "password",
48
60
  "customDomain",
49
61
  ];
62
+ /**
63
+ * Spec 103 CLI slice: the HTML runtime profile a publish or update asks for.
64
+ * `auto` is the server's default and is never sent unless the caller names it,
65
+ * so a publish without the flag stays byte-identical on the wire.
66
+ */
67
+ const RUNTIME_PROFILES = ["auto", "open", "contained"];
68
+ /** The only commands that can carry `runtimeProfile`, and only for HTML. */
69
+ const RUNTIME_PROFILE_COMMANDS = new Set([
70
+ "publish",
71
+ "update",
72
+ "html-publish",
73
+ "html-update",
74
+ ]);
75
+ const RUNTIME_PROFILE_NOT_APPLICABLE_NEXT = "Use --runtime-profile only for an HTML publish or update.";
76
+ function runtimeProfileNotApplicable(context) {
77
+ return new FoleoError({
78
+ code: "runtime_profile_not_applicable",
79
+ message: "--runtime-profile applies only to an HTML publish or update; Markdown has no author-script runtime.",
80
+ next: RUNTIME_PROFILE_NOT_APPLICABLE_NEXT,
81
+ retryable: false,
82
+ source: "local",
83
+ usage: true,
84
+ context,
85
+ });
86
+ }
87
+ /**
88
+ * Spec 103 / ADR 0048: the top-level REST field an API key sends to confirm
89
+ * that the human approved exposing an artifact to more readers or giving it
90
+ * another working address. Sent only when `--acknowledge-access-widening` is
91
+ * present — never inferred from `--accept-hosting-risk` or any other flag.
92
+ */
93
+ function accessWideningField(acknowledged) {
94
+ return acknowledged ? { accessWideningAcknowledged: true } : {};
95
+ }
50
96
  const LIVE_DOC_ASSET_MEDIA_TYPES = {
51
97
  ".png": "image/png",
52
98
  ".jpg": "image/jpeg",
@@ -93,6 +139,14 @@ export async function runCli(argv, deps = {
93
139
  if (rest.includes("--dry-run") && !DRY_RUN_AWARE_COMMANDS.has(command)) {
94
140
  throw new UsageError(`--dry-run is not supported by \`foleo ${command}\`. Only \`publish\` on an HTML bundle can plan.`, "dry_run_unsupported", { operation: command });
95
141
  }
142
+ // Same shape as the --dry-run guard: a runtime profile on a command that
143
+ // cannot send one must fail rather than be silently ignored.
144
+ if (rest.includes("--runtime-profile") &&
145
+ !RUNTIME_PROFILE_COMMANDS.has(command)) {
146
+ throw runtimeProfileNotApplicable({
147
+ operation: describeArgvToken(command),
148
+ });
149
+ }
96
150
  if (command === "publish")
97
151
  return await publish(rest, commandDeps);
98
152
  if (command === "update")
@@ -147,6 +201,8 @@ export async function runCli(argv, deps = {
147
201
  return await limitsCommand(rest, commandDeps);
148
202
  if (command === "login")
149
203
  return await login(rest, commandDeps);
204
+ if (command === "logout")
205
+ return await logout(rest, commandDeps);
150
206
  if (command === "list")
151
207
  return await list(rest, commandDeps);
152
208
  if (command === "whoami")
@@ -555,7 +611,7 @@ function stringArray(value) {
555
611
  async function login(args, deps) {
556
612
  const parsed = parseFlags(args, { allowLoginScopeFlags: true });
557
613
  if (parsed.positionals.length > 0)
558
- throw new Error("Usage: foleo login [--allow-delete] [--allow-purge] [--json]");
614
+ throw new Error("Usage: foleo login [--allow-purge] [--json]");
559
615
  const base = apiBase(deps);
560
616
  announceApi(deps, parsed.json);
561
617
  const verifyStore = deps.verifyCredentialStore ?? verifyKeychainWritable;
@@ -564,6 +620,10 @@ async function login(args, deps) {
564
620
  const createCallback = deps.createBrowserCallback ?? createLoopbackCallback;
565
621
  const openUrl = deps.openUrl ?? openBrowser;
566
622
  await verifyStore(base);
623
+ // The Keychain entry this login overwrites holds the only copy of the
624
+ // previous key's token. Keep it, so a failed login can put it back and a
625
+ // successful one can revoke that key instead of stranding it (ADR 0044).
626
+ const previousToken = await (deps.loadCredential ?? loadKeychainCredential)(base);
567
627
  const nonce = createHash("sha256").update(randomUUID()).digest("hex");
568
628
  const callback = await createCallback(nonce);
569
629
  let appSessionToken = null;
@@ -590,9 +650,10 @@ async function login(args, deps) {
590
650
  method: "POST",
591
651
  body: {
592
652
  name: "Foleo CLI",
653
+ // `--allow-delete` is now redundant and accepted silently, so existing
654
+ // scripts and docs keep working.
593
655
  scopes: [
594
656
  ...CLI_KEY_SCOPES,
595
- ...(parsed.allowDelete ? ["artifacts:delete"] : []),
596
657
  ...(parsed.allowPurge ? ["artifacts:purge"] : []),
597
658
  ],
598
659
  deferredActivation: true,
@@ -603,7 +664,16 @@ async function login(args, deps) {
603
664
  await requestJsonWithToken(deps, `/keys/${encodeURIComponent(key.id)}/activate`, appSessionToken, { method: "POST", body: {} });
604
665
  }
605
666
  catch (error) {
606
- await deleteCredential(base).catch(() => undefined);
667
+ const restored = previousToken !== null &&
668
+ (await saveCredential(base, previousToken).then(() => true, () => false));
669
+ if (!restored) {
670
+ await deleteCredential(base).catch(() => undefined);
671
+ // The previous token is now gone from the Keychain for good. Retire its
672
+ // key while this process still holds the token, or it stays live with
673
+ // no one able to use or revoke it.
674
+ if (previousToken !== null)
675
+ await revokeOwnCredential(deps, previousToken);
676
+ }
607
677
  const revoked = await requestJsonWithToken(deps, `/keys/${encodeURIComponent(key.id)}/revoke`, appSessionToken, { method: "POST", body: {} }).then(() => true, () => false);
608
678
  if (!revoked)
609
679
  throw new Error(`Foleo login failed and pending key cleanup must be retried from the dashboard (key ${key.id}).`);
@@ -614,6 +684,9 @@ async function login(args, deps) {
614
684
  org: exchanged.org.handle,
615
685
  keyId: key.id,
616
686
  scopes: key.scopes,
687
+ replacedCredential: previousToken === null
688
+ ? "none"
689
+ : (await revokeOwnCredential(deps, previousToken)).outcome,
617
690
  };
618
691
  }
619
692
  catch (error) {
@@ -642,6 +715,93 @@ async function login(args, deps) {
642
715
  deps.stdout(`${JSON.stringify(loginResult, null, 2)}\n`);
643
716
  else
644
717
  deps.stdout(`Signed in to ${loginResult.org}. Credential saved in macOS Keychain.\n`);
718
+ if (loginResult.replacedCredential === "revoke_failed" && !parsed.json)
719
+ deps.stderr("Warning: the CLI key this login replaced could not be revoked and may still be active on the server.\n");
720
+ return 0;
721
+ }
722
+ /**
723
+ * Spend a stored token on `POST /v1/keys/self/revoke`, which retires exactly
724
+ * the key it authenticates as (ADR 0044). A 401 means the server already
725
+ * refuses the token, so nothing is left to revoke.
726
+ */
727
+ async function revokeOwnCredential(deps, token) {
728
+ try {
729
+ await requestJsonWithToken(deps, "/keys/self/revoke", token, {
730
+ method: "POST",
731
+ body: {},
732
+ });
733
+ return { outcome: "revoked" };
734
+ }
735
+ catch (error) {
736
+ if (error instanceof ApiRequestError && error.status === 401)
737
+ return { outcome: "already_invalid" };
738
+ return { outcome: "revoke_failed", error: toFoleoError(error) };
739
+ }
740
+ }
741
+ /**
742
+ * `logout` — sign this machine's CLI out of the selected API (spec 061 §6).
743
+ *
744
+ * Revoking server-side is the default, not an opt-in: a logout that leaves the
745
+ * key live is how keys were stranded. `--no-revoke` skips the server call for
746
+ * the offline case; it cannot be `--local`, which already selects the local
747
+ * API. The Keychain entry is cleared either way, and a failed revoke still
748
+ * exits 1 so it is never silent. FOLEO_TOKEN is the caller's and is untouched.
749
+ */
750
+ async function logout(args, deps) {
751
+ const noRevoke = args.includes("--no-revoke");
752
+ const parsed = parseFlags(args.filter((arg) => arg !== "--no-revoke"));
753
+ if (parsed.positionals.length > 0)
754
+ throw new Error("Usage: foleo logout [--no-revoke] [--json]");
755
+ const base = apiBase(deps);
756
+ announceApi(deps, parsed.json);
757
+ const token = await (deps.loadCredential ?? loadKeychainCredential)(base);
758
+ const revocation = token === null
759
+ ? null
760
+ : noRevoke
761
+ ? { outcome: "skipped" }
762
+ : await revokeOwnCredential(deps, token);
763
+ if (token !== null) {
764
+ try {
765
+ await (deps.deleteCredential ?? deleteKeychainCredential)(base);
766
+ }
767
+ catch (error) {
768
+ throw new LocalError("keychain_delete_failed", `Unable to remove the CLI credential from macOS Keychain: ${errorMessage(error)}`, {
769
+ context: {
770
+ revocation: revocation?.outcome ?? "none",
771
+ },
772
+ });
773
+ }
774
+ }
775
+ if (revocation?.outcome === "revoke_failed")
776
+ throw new FoleoError({
777
+ code: "logout_revoke_failed",
778
+ message: `Removed the CLI credential from this machine, but the server did not confirm revoking its key (${revocation.error.code}).`,
779
+ next: "The key may still be active server-side. Its token is no longer stored here.",
780
+ source: revocation.error.source,
781
+ ...(revocation.error.httpStatus === undefined
782
+ ? {}
783
+ : { httpStatus: revocation.error.httpStatus }),
784
+ context: { signedOut: true, revocation: "revoke_failed" },
785
+ });
786
+ const envTokenActive = Boolean(deps.env.FOLEO_TOKEN);
787
+ const result = {
788
+ ok: true,
789
+ apiOrigin: new URL(base).origin,
790
+ signedOut: token !== null,
791
+ revocation: revocation?.outcome ?? "none",
792
+ envTokenActive,
793
+ };
794
+ if (parsed.json) {
795
+ deps.stdout(`${JSON.stringify(result, null, 2)}\n`);
796
+ return 0;
797
+ }
798
+ deps.stdout(revocation === null
799
+ ? "No CLI credential is stored for this API.\n"
800
+ : revocation.outcome === "skipped"
801
+ ? "Signed out on this machine. The key was not revoked and stays active on the server.\n"
802
+ : "Signed out. The CLI key is revoked and removed from macOS Keychain.\n");
803
+ if (envTokenActive)
804
+ deps.stdout("FOLEO_TOKEN is still set in your environment; logout does not change it.\n");
645
805
  return 0;
646
806
  }
647
807
  /**
@@ -804,6 +964,7 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
804
964
  availability = "unknown";
805
965
  deps.stderr("Not signed in: this plan is bundle-only and cannot tell you whether the name is free. Run `foleo login` and plan again before publishing.\n");
806
966
  }
967
+ const previewUrl = artifactPreviewUrl(derived, deps);
807
968
  const plan = {
808
969
  ok: true,
809
970
  plan: {
@@ -817,9 +978,38 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
817
978
  availability,
818
979
  checkedAt,
819
980
  },
820
- url: artifactPreviewUrl(derived, deps),
981
+ url: previewUrl,
982
+ // Spec 103: HTML names are vanity labels today; handle-scoped agent
983
+ // addresses (ADR 0049) are a separate, later class.
984
+ address: {
985
+ class: "vanity",
986
+ hostname: previewUrl === null ? null : new URL(previewUrl).hostname,
987
+ },
988
+ nameQuota: {
989
+ [NAME_QUOTA_DIMENSIONS.claimsPerDay]: 1,
990
+ [NAME_QUOTA_DIMENSIONS.activeNames]: 1,
991
+ },
821
992
  title: resolvedTitle,
822
993
  visibility: resolvedVisibility.value,
994
+ runtimeProfile: {
995
+ requested: parsed.runtimeProfile ?? "auto",
996
+ resolvedFrom: parsed.runtimeProfile === undefined ? "default" : "flag",
997
+ // The server chooses (auto) or checks (contained) the profile from the
998
+ // uploaded bytes. A plan uploads nothing, so it cannot know either.
999
+ applied: null,
1000
+ containedFit: "unknown",
1001
+ blockedContainedReferences: null,
1002
+ note: parsed.runtimeProfile === "contained"
1003
+ ? "A plan uploads nothing, so it cannot check the contained fit. If the page does not fit, the real publish fails with contained_profile_unavailable, lists the blocked references, and never falls back to open."
1004
+ : "The server applies the runtime profile from the uploaded bytes and reports it as runtimeProfile with a profileNote.",
1005
+ },
1006
+ accessWidening: {
1007
+ // A create makes a new artifact; widening is a change to an existing
1008
+ // one's readers or addresses (ADR 0048 §4), so a create never needs it.
1009
+ mayWiden: false,
1010
+ acknowledged: parsed.acknowledgeAccessWidening,
1011
+ note: "A new artifact does not widen an existing artifact's readers or addresses. This plan does not approve any connection or access policy.",
1012
+ },
823
1013
  bundle: {
824
1014
  fileCount: files.length,
825
1015
  htmlFileCount: htmlFiles.length,
@@ -840,6 +1030,8 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
840
1030
  else {
841
1031
  deps.stdout(`plan: create ${derived} (${availability})\n` +
842
1032
  `files: ${files.length} (${htmlFiles.length} html)\n` +
1033
+ `runtime profile: ${plan.plan.runtimeProfile.requested} (applied by the server; fit unknown)\n` +
1034
+ `access widening: no (new artifact); --acknowledge-access-widening ${parsed.acknowledgeAccessWidening ? "present" : "absent"}\n` +
843
1035
  `executable: ${executable}\n`);
844
1036
  }
845
1037
  if (name === undefined) {
@@ -852,7 +1044,7 @@ async function htmlPublish(args, deps) {
852
1044
  const parsed = parseFlags(args);
853
1045
  const root = parsed.positionals[0];
854
1046
  if (!root || parsed.positionals.length !== 1 || !parsed.acceptHostingRisk)
855
- throw new Error("Usage: foleo html-publish <bundle-root> --accept-hosting-risk --name <label> [--settings <json>] [--password-stdin] [--publish-separately] [--dry-run] [--json]\nHosted HTML is executable and may run JavaScript, show forms, or initiate downloads. A human must inspect the source and explicitly approve this risk; an agent must not infer approval.");
1047
+ throw new Error("Usage: foleo html-publish <bundle-root> --accept-hosting-risk --name <label> [--settings <json>] [--password-stdin] [--publish-separately] [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--dry-run] [--json]\nHosted HTML is executable and may run JavaScript, show forms, or initiate downloads. A human must inspect the source and explicitly approve this risk; an agent must not infer approval.");
856
1048
  const settings = { ...(parsed.settings ?? {}) };
857
1049
  // A dry run may omit --name to obtain a derived suggestion; a real create
858
1050
  // may not (spec 089 §B).
@@ -896,10 +1088,18 @@ async function htmlPublish(args, deps) {
896
1088
  settings.password = password;
897
1089
  }
898
1090
  announceApi(deps, parsed.json);
899
- const result = await publishBundle(root, deps, null, true, parsed.publishSeparately, settings);
1091
+ const result = await publishBundle(root, deps, null, true, parsed.publishSeparately, settings, htmlWireOptions(parsed));
900
1092
  writeResult(deps, result, parsed.json);
901
1093
  return 0;
902
1094
  }
1095
+ function htmlWireOptions(parsed) {
1096
+ return {
1097
+ ...(parsed.runtimeProfile === undefined
1098
+ ? {}
1099
+ : { runtimeProfile: parsed.runtimeProfile }),
1100
+ acknowledgeAccessWidening: parsed.acknowledgeAccessWidening,
1101
+ };
1102
+ }
903
1103
  async function htmlUpdate(args, deps) {
904
1104
  resolveUploadRate(deps);
905
1105
  const parsed = parseFlags(args);
@@ -912,12 +1112,8 @@ async function htmlUpdate(args, deps) {
912
1112
  const [id, root] = parsed.positionals;
913
1113
  const revision = legacyRevision(parsed.revision);
914
1114
  if (!id || !root || parsed.positionals.length !== 2 || revision === null)
915
- throw new Error("Usage: foleo html-update <id> <bundle-root> --revision <stateRevision> [--json]");
916
- const result = await publishBundle(root, deps, {
917
- family: "compatibility",
918
- id,
919
- revision,
920
- });
1115
+ throw new Error("Usage: foleo html-update <id> <bundle-root> --revision <stateRevision> [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--json]");
1116
+ const result = await publishBundle(root, deps, { family: "compatibility", id, revision }, false, false, undefined, htmlWireOptions(parsed));
921
1117
  writeResult(deps, result, parsed.json);
922
1118
  return 0;
923
1119
  }
@@ -937,11 +1133,14 @@ async function htmlVisibility(args, deps) {
937
1133
  revision === null ||
938
1134
  !parsed.set ||
939
1135
  !["unlisted", "password", "private"].includes(parsed.set))
940
- throw new Error("Usage: foleo html-visibility <id> --set unlisted|password|private --revision <stateRevision> [--json]");
1136
+ throw new Error("Usage: foleo html-visibility <id> --set unlisted|password|private --revision <stateRevision> [--acknowledge-access-widening] [--json]");
941
1137
  announceApi(deps, parsed.json);
942
1138
  const result = await requestJson(deps, `/artifacts/html/${encodeURIComponent(id)}/visibility`, {
943
1139
  method: "PATCH",
944
- body: { visibility: parsed.set },
1140
+ body: {
1141
+ visibility: parsed.set,
1142
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1143
+ },
945
1144
  headers: revisionHeaders(revision),
946
1145
  });
947
1146
  writeResult(deps, result, parsed.json);
@@ -952,10 +1151,10 @@ async function htmlPassword(args, deps) {
952
1151
  const id = parsed.positionals[0];
953
1152
  const revision = legacyRevision(parsed.revision);
954
1153
  if (!id || parsed.positionals.length !== 1 || revision === null) {
955
- throw new Error("Usage: foleo html-password <id> --password-stdin --revision <stateRevision> [--json]");
1154
+ throw new Error("Usage: foleo html-password <id> --password-stdin --revision <stateRevision> [--acknowledge-access-widening] [--json]");
956
1155
  }
957
1156
  if (!parsed.passwordStdin) {
958
- throw new Error("Usage: foleo html-password <id> --password-stdin --revision <stateRevision> [--json]");
1157
+ throw new Error("Usage: foleo html-password <id> --password-stdin --revision <stateRevision> [--acknowledge-access-widening] [--json]");
959
1158
  }
960
1159
  const password = stripTrailingNewline(await readStdinText(deps));
961
1160
  if (password.length < 12 || password.length > 256) {
@@ -964,7 +1163,12 @@ async function htmlPassword(args, deps) {
964
1163
  announceApi(deps, parsed.json);
965
1164
  const result = await requestJson(deps, `/artifacts/html/${encodeURIComponent(id)}/password`, {
966
1165
  method: "PATCH",
967
- body: { password },
1166
+ // A password change is an access change the API guards like the
1167
+ // visibility route, so the deprecated alias carries the same field.
1168
+ body: {
1169
+ password,
1170
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1171
+ },
968
1172
  headers: revisionHeaders(revision),
969
1173
  });
970
1174
  writeResult(deps, result, parsed.json);
@@ -974,7 +1178,7 @@ async function settingsCommand(args, deps) {
974
1178
  const parsed = parseFlags(args);
975
1179
  const id = parsed.positionals[0];
976
1180
  if (!id || parsed.positionals.length !== 1) {
977
- throw new Error("Usage: foleo settings <id> [--set k=v ...] [--password-stdin] [--revision <etag>] [--json]");
1181
+ throw new Error("Usage: foleo settings <id> [--set k=v ...] [--password-stdin] [--revision <etag>] [--acknowledge-access-widening] [--json]");
978
1182
  }
979
1183
  const patch = parseSettingsSets(parsed.sets);
980
1184
  if (parsed.passwordStdin) {
@@ -994,11 +1198,14 @@ async function settingsCommand(args, deps) {
994
1198
  }
995
1199
  const revision = artifactRevision(parsed.revision);
996
1200
  if (revision === null) {
997
- throw new Error("Usage: foleo settings <id> --set k=v ... --revision <etag> [--json]");
1201
+ throw new Error("Usage: foleo settings <id> --set k=v ... --revision <etag> [--acknowledge-access-widening] [--json]");
998
1202
  }
999
1203
  writeResult(deps, await requestJson(deps, `/artifacts/${encodeURIComponent(id)}/settings`, {
1000
1204
  method: "PATCH",
1001
- body: { settings: patch },
1205
+ body: {
1206
+ settings: patch,
1207
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1208
+ },
1002
1209
  headers: {
1003
1210
  ...artifactMutationHeaders(revision, randomUUID()),
1004
1211
  "content-type": "application/merge-patch+json",
@@ -1124,7 +1331,16 @@ async function htmlUnpublish(args, deps) {
1124
1331
  writeResult(deps, result, parsed.json);
1125
1332
  return 0;
1126
1333
  }
1127
- async function publishBundle(root, deps, update, hostingRiskAcknowledged = false, publishSeparately = false, settings) {
1334
+ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false, publishSeparately = false, settings, wire = {}) {
1335
+ // Top-level fields every HTML create/update body carries (spec 103): the
1336
+ // runtime profile only when the caller chose one, and the widening
1337
+ // acknowledgement only when its flag is present.
1338
+ const wireFields = {
1339
+ ...(wire.runtimeProfile === undefined
1340
+ ? {}
1341
+ : { runtimeProfile: wire.runtimeProfile }),
1342
+ ...accessWideningField(wire.acknowledgeAccessWidening === true),
1343
+ };
1128
1344
  const { files, skipped } = await scanBundle(root, deps);
1129
1345
  if (skipped.length > 0) {
1130
1346
  // Spec 089 §K.3 / L914: a dropped `.well-known/` must never be silent on
@@ -1205,6 +1421,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1205
1421
  uploadId: upload.uploadId,
1206
1422
  manifestHash: upload.manifestHash,
1207
1423
  source,
1424
+ ...wireFields,
1208
1425
  },
1209
1426
  headers: {
1210
1427
  "if-match": `"r${update.revision}"`,
@@ -1220,6 +1437,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1220
1437
  uploadId: upload.uploadId,
1221
1438
  manifestHash: upload.manifestHash,
1222
1439
  source,
1440
+ ...wireFields,
1223
1441
  },
1224
1442
  headers: artifactMutationHeaders(update.etag, createKey),
1225
1443
  });
@@ -1234,6 +1452,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1234
1452
  source,
1235
1453
  ...(publishSeparately ? { allowDuplicate: true } : {}),
1236
1454
  ...(settings && Object.keys(settings).length > 0 ? { settings } : {}),
1455
+ ...wireFields,
1237
1456
  },
1238
1457
  headers: { "idempotency-key": createKey },
1239
1458
  });
@@ -1746,7 +1965,7 @@ async function publish(args, deps) {
1746
1965
  const parsed = parseFlags(args);
1747
1966
  const file = parsed.positionals[0];
1748
1967
  if (!file || parsed.positionals.length !== 1)
1749
- throw new Error("Usage: foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--accept-hosting-risk] [--name <label>] [--dry-run] [--json]\nAn HTML site bundle also requires --name <label>; Markdown does not.");
1968
+ throw new Error("Usage: foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--accept-hosting-risk] [--name <label>] [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--dry-run] [--json]\nAn HTML site bundle also requires --name <label>; Markdown does not.");
1750
1969
  const isDirectory = await pathIsDirectory(file, deps);
1751
1970
  if (!isDirectory && parsed.dryRun) {
1752
1971
  throw new UsageError("--dry-run is only implemented for HTML site bundles (a directory with --accept-hosting-risk). A Markdown publish is not previewable yet; run it without --dry-run, or use `foleo publish <dir> --accept-hosting-risk --name <label> --dry-run`.", "dry_run_unsupported", { sourceFormat: "markdown" });
@@ -1760,6 +1979,9 @@ async function publish(args, deps) {
1760
1979
  if (!file.toLowerCase().endsWith(".md")) {
1761
1980
  throw new LocalError("publish_input_unsupported", "Unsupported publish input. Use a .md file for Markdown or an HTML site directory with --accept-hosting-risk.", { context: { path: file } });
1762
1981
  }
1982
+ if (parsed.runtimeProfile !== undefined) {
1983
+ throw runtimeProfileNotApplicable({ sourceFormat: "markdown" });
1984
+ }
1763
1985
  const markdown = await deps.readFile(file, "utf8");
1764
1986
  const assets = await uploadMarkdownAssets(file, markdown, deps);
1765
1987
  const result = await requestJson(deps, "/artifacts", {
@@ -1776,6 +1998,7 @@ async function publish(args, deps) {
1776
1998
  ...(assets
1777
1999
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1778
2000
  : {}),
2001
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1779
2002
  },
1780
2003
  });
1781
2004
  writeResult(deps, result, parsed.json);
@@ -1791,27 +2014,26 @@ async function update(args, deps) {
1791
2014
  }
1792
2015
  const [id, file] = parsed.positionals;
1793
2016
  if (!id || !file || parsed.positionals.length !== 2) {
1794
- throw new Error("Usage: foleo update <id> <path> --revision <etag> [--json] (or Markdown compatibility --version <version>)");
2017
+ throw new Error("Usage: foleo update <id> <path> --revision <etag> [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--json] (or Markdown compatibility --version <version>)");
1795
2018
  }
1796
2019
  const isDirectory = await pathIsDirectory(file, deps);
1797
2020
  if (isDirectory) {
1798
2021
  const revision = artifactRevision(parsed.revision);
1799
2022
  if (revision === null) {
1800
- throw new Error("Usage: foleo update <id> <bundle-root> --revision <etag> [--json]");
2023
+ throw new Error("Usage: foleo update <id> <bundle-root> --revision <etag> [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--json]");
1801
2024
  }
1802
- const result = await publishBundle(file, deps, {
1803
- family: "generic",
1804
- id,
1805
- etag: revision,
1806
- });
2025
+ const result = await publishBundle(file, deps, { family: "generic", id, etag: revision }, false, false, undefined, htmlWireOptions(parsed));
1807
2026
  writeResult(deps, result, parsed.json);
1808
2027
  return 0;
1809
2028
  }
1810
2029
  if (!file.toLowerCase().endsWith(".md")) {
1811
2030
  throw new Error("Unsupported update input. Use a .md file or an HTML site directory.");
1812
2031
  }
2032
+ if (parsed.runtimeProfile !== undefined) {
2033
+ throw runtimeProfileNotApplicable({ sourceFormat: "markdown" });
2034
+ }
1813
2035
  if (parsed.version === undefined && parsed.revision === undefined) {
1814
- throw new Error("Usage: foleo update <id> <file> --revision <etag> [--json] (or compatibility --version <version>)");
2036
+ throw new Error("Usage: foleo update <id> <file> --revision <etag> [--acknowledge-access-widening] [--json] (or compatibility --version <version>)");
1815
2037
  }
1816
2038
  const opaqueRevision = parsed.revision === undefined ? null : artifactRevision(parsed.revision);
1817
2039
  if (parsed.revision !== undefined && opaqueRevision === null) {
@@ -1831,6 +2053,7 @@ async function update(args, deps) {
1831
2053
  ...(assets
1832
2054
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1833
2055
  : {}),
2056
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1834
2057
  },
1835
2058
  headers: artifactMutationHeaders(opaqueRevision, randomUUID()),
1836
2059
  })
@@ -1843,6 +2066,7 @@ async function update(args, deps) {
1843
2066
  ...(assets
1844
2067
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1845
2068
  : {}),
2069
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1846
2070
  },
1847
2071
  });
1848
2072
  writeResult(deps, result, parsed.json);
@@ -2058,8 +2282,8 @@ async function unpublish(args, deps) {
2058
2282
  */
2059
2283
  const NAME_USAGE = [
2060
2284
  "Usage:",
2061
- " foleo name attach <id> <label> [--revision <etag>] [--dry-run] [--json]",
2062
- " foleo name set <id> <label> --previous keep-as-alias|release [--revision <etag>] [--dry-run] [--json]",
2285
+ " foleo name attach <id> <label> [--revision <etag>] [--acknowledge-access-widening] [--dry-run] [--json]",
2286
+ " foleo name set <id> <label> --previous keep-as-alias|release [--revision <etag>] [--acknowledge-access-widening] [--dry-run] [--json]",
2063
2287
  " foleo name release <id> <label> --acknowledge-link-breakage [--revision <etag>] [--dry-run] [--json]",
2064
2288
  ].join("\n");
2065
2289
  /**
@@ -2099,12 +2323,16 @@ async function nameCommand(args, deps) {
2099
2323
  // re-issuing the mutation under a fresh identity.
2100
2324
  const idempotencyKey = randomUUID();
2101
2325
  const encodedId = encodeURIComponent(id);
2326
+ // Attach and rename add a working address, which the API treats as
2327
+ // widening (spec 103). Release only removes one, so it never sends the
2328
+ // acknowledgement even when the flag is present.
2329
+ const widening = accessWideningField(parsed.acknowledgeAccessWidening);
2102
2330
  const request = sub === "attach"
2103
2331
  ? {
2104
2332
  activity: "attaching the name",
2105
2333
  path: `/artifacts/${encodedId}/name`,
2106
2334
  method: "POST",
2107
- body: { name: label },
2335
+ body: { name: label, ...widening },
2108
2336
  }
2109
2337
  : sub === "set"
2110
2338
  ? {
@@ -2119,6 +2347,7 @@ async function nameCommand(args, deps) {
2119
2347
  name: label,
2120
2348
  previousLabel: parsed.previous,
2121
2349
  expectedPreviousLabel: snapshot.name,
2350
+ ...widening,
2122
2351
  },
2123
2352
  }
2124
2353
  : {
@@ -2349,6 +2578,11 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2349
2578
  .filter((hostname) => hostname !== resultHostname &&
2350
2579
  !addressesThatStopWorking.includes(hostname))
2351
2580
  .sort();
2581
+ // Spec 103: a change that leaves the artifact with more working addresses
2582
+ // widens access. Attach and a keep-as-alias rename to a new label add one;
2583
+ // promoting an alias it already holds, a release rename and a release do not.
2584
+ const mayWiden = sub === "attach" ||
2585
+ (sub === "set" && parsed.previous !== "release" && !claimsExistingAlias);
2352
2586
  const plan = {
2353
2587
  ok: true,
2354
2588
  plan: {
@@ -2366,6 +2600,14 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2366
2600
  [NAME_QUOTA_DIMENSIONS.activeNames]: activeDelta,
2367
2601
  current: quota,
2368
2602
  },
2603
+ accessWidening: {
2604
+ mayWiden,
2605
+ // Release never sends the acknowledgement, so it never reports one.
2606
+ acknowledged: sub !== "release" && parsed.acknowledgeAccessWidening,
2607
+ note: mayWiden
2608
+ ? "This adds a working address. An API key needs --acknowledge-access-widening once the human approves; without it the API may answer acknowledgement_required. This plan approves nothing."
2609
+ : "This does not add a working address, so it needs no access-widening acknowledgement.",
2610
+ },
2369
2611
  executable: true,
2370
2612
  },
2371
2613
  };
@@ -2377,6 +2619,7 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2377
2619
  ` (${plan.plan.result.primaryUrl ?? "unknown"})\n` +
2378
2620
  `stops working: ${addressesThatStopWorking.join(", ") || "none"}\n` +
2379
2621
  `keeps working: ${addressesThatKeepWorking.join(", ") || "none"}\n` +
2622
+ `access widening: ${mayWiden ? "yes" : "no"}; --acknowledge-access-widening ${plan.plan.accessWidening.acknowledged ? "present" : "absent"}\n` +
2380
2623
  `executable: true\n`);
2381
2624
  }
2382
2625
  return 0;
@@ -2470,12 +2713,18 @@ async function restoreArtifact(args, deps) {
2470
2713
  const id = parsed.positionals[0];
2471
2714
  const revision = artifactRevision(parsed.revision);
2472
2715
  if (!id || parsed.positionals.length !== 1 || revision === null) {
2473
- throw new Error("Usage: foleo restore <id> --revision <etag> [--json]");
2716
+ throw new Error("Usage: foleo restore <id> --revision <etag> [--acknowledge-access-widening] [--json]");
2474
2717
  }
2475
2718
  const idempotencyKey = randomUUID();
2719
+ // A restore returns the artifact unpublished, but it reactivates the row
2720
+ // and its names, so the API treats it as widening (ADR 0048). The body stays
2721
+ // absent without the flag, exactly as before.
2722
+ const body = parsed.acknowledgeAccessWidening
2723
+ ? accessWideningField(true)
2724
+ : undefined;
2476
2725
  const result = await withRateLimitRetry(deps, "restoring the artifact", () => requestJson(deps, `/artifacts/${encodeURIComponent(id)}/restore`, {
2477
2726
  method: "POST",
2478
- body: undefined,
2727
+ body,
2479
2728
  headers: artifactMutationHeaders(revision, idempotencyKey),
2480
2729
  }));
2481
2730
  writeDeletionResult(deps, result, parsed.json);
@@ -2664,14 +2913,29 @@ class ApiRequestError extends FoleoError {
2664
2913
  body;
2665
2914
  constructor(status, code, body) {
2666
2915
  const next = apiErrorNext(body);
2916
+ const envelope = isRecord(body) && isRecord(body.error) ? body.error : null;
2917
+ // Spec 103: preserve the server's `retryable` verbatim, and carry the
2918
+ // blocked references of `contained_profile_unavailable` so an agent can
2919
+ // act on them without re-running anything.
2920
+ const retryable = typeof envelope?.retryable === "boolean" ? envelope.retryable : false;
2921
+ const references = Array.isArray(envelope?.references)
2922
+ ? envelope.references
2923
+ : null;
2667
2924
  super({
2668
2925
  code,
2669
2926
  message: code === "matching_source_exists"
2670
2927
  ? matchingSourceExistsMessage(body)
2671
- : `Foleo API error: ${code}`,
2928
+ : code === "acknowledgement_required" &&
2929
+ envelope?.field !== "acknowledgeLinkBreakage"
2930
+ ? "Foleo API error: acknowledgement_required. This change would expose the artifact to more readers or add a working address. Only after the human approves it, re-run the same command with --acknowledge-access-widening."
2931
+ : code === "contained_profile_unavailable"
2932
+ ? containedProfileUnavailableMessage(references ?? [])
2933
+ : `Foleo API error: ${code}`,
2672
2934
  httpStatus: status,
2673
2935
  source: "api",
2936
+ retryable,
2674
2937
  ...(next === null ? {} : { next }),
2938
+ ...(references === null ? {} : { context: { references } }),
2675
2939
  });
2676
2940
  this.name = "ApiRequestError";
2677
2941
  this.status = status;
@@ -2695,6 +2959,20 @@ function apiErrorNext(body) {
2695
2959
  const envelope = isRecord(body) && isRecord(body.error) ? body.error : null;
2696
2960
  return envelope && typeof envelope.next === "string" ? envelope.next : null;
2697
2961
  }
2962
+ /** Prose for a human; `--json` callers read `error.context.references`. */
2963
+ function containedProfileUnavailableMessage(references) {
2964
+ const shown = references
2965
+ .filter(isRecord)
2966
+ .slice(0, 10)
2967
+ .map((item) => ` ${String(item.kind ?? "reference")}: ${String(item.reference ?? "")}`);
2968
+ return [
2969
+ "Foleo API error: contained_profile_unavailable. The page does not fit the contained runtime profile, so nothing was published (the CLI never retries as open).",
2970
+ ...shown,
2971
+ ...(references.length > shown.length
2972
+ ? [` (+${references.length - shown.length} more)`]
2973
+ : []),
2974
+ ].join("\n");
2975
+ }
2698
2976
  function matchingSourceExistsMessage(body) {
2699
2977
  const errorBody = isRecord(body) && isRecord(body.error) ? body.error : null;
2700
2978
  const matches = errorBody && Array.isArray(errorBody.matches)
@@ -3087,6 +3365,13 @@ function writeResult(deps, result, json) {
3087
3365
  }
3088
3366
  if (result !== null && typeof result === "object" && "url" in result) {
3089
3367
  deps.stdout(`${String(result.url)}\n`);
3368
+ // The applied HTML runtime profile is chosen by the server; say which one
3369
+ // a human got. stderr, so stdout stays the bare URL it always was.
3370
+ const profile = stringField(result, "runtimeProfile");
3371
+ if (profile !== null) {
3372
+ const note = stringField(result, "profileNote");
3373
+ deps.stderr(`Runtime profile: ${profile}.${note ? ` ${note}` : ""}\n`);
3374
+ }
3090
3375
  return;
3091
3376
  }
3092
3377
  deps.stdout(`${JSON.stringify(result)}\n`);
@@ -3172,6 +3457,8 @@ function parseFlags(args, options = {}) {
3172
3457
  let dryRun = false;
3173
3458
  let previous;
3174
3459
  let acknowledgeLinkBreakage = false;
3460
+ let acknowledgeAccessWidening = false;
3461
+ let runtimeProfile;
3175
3462
  let artifact;
3176
3463
  let cursor;
3177
3464
  for (let i = 0; i < args.length; i++) {
@@ -3282,6 +3569,19 @@ function parseFlags(args, options = {}) {
3282
3569
  acknowledgeLinkBreakage = true;
3283
3570
  continue;
3284
3571
  }
3572
+ if (arg === "--acknowledge-access-widening") {
3573
+ acknowledgeAccessWidening = true;
3574
+ continue;
3575
+ }
3576
+ if (arg === "--runtime-profile") {
3577
+ const raw = args[++i];
3578
+ if (!RUNTIME_PROFILES.includes(raw ?? "")) {
3579
+ const shown = raw === undefined ? "(missing)" : describeArgvToken(raw);
3580
+ throw new UsageError(`Invalid --runtime-profile ${shown}; expected auto, open or contained.`, "runtime_profile_invalid", { value: shown, allowed: [...RUNTIME_PROFILES] });
3581
+ }
3582
+ runtimeProfile = raw;
3583
+ continue;
3584
+ }
3285
3585
  if (arg === "--artifact") {
3286
3586
  artifact = args[++i];
3287
3587
  if (!artifact)
@@ -3333,6 +3633,8 @@ function parseFlags(args, options = {}) {
3333
3633
  dryRun,
3334
3634
  ...(previous === undefined ? {} : { previous }),
3335
3635
  acknowledgeLinkBreakage,
3636
+ acknowledgeAccessWidening,
3637
+ ...(runtimeProfile === undefined ? {} : { runtimeProfile }),
3336
3638
  ...(artifact === undefined ? {} : { artifact }),
3337
3639
  ...(cursor === undefined ? {} : { cursor }),
3338
3640
  };
@@ -3351,7 +3653,8 @@ function help() {
3351
3653
  return [
3352
3654
  "Usage:",
3353
3655
  " foleo --help",
3354
- " foleo login [--allow-delete] [--allow-purge] [--json]",
3656
+ " foleo login [--allow-purge] [--json]",
3657
+ " foleo logout [--no-revoke] [--json]",
3355
3658
  " foleo whoami [--json]",
3356
3659
  " foleo doctor [--json]",
3357
3660
  " foleo skill get|path",
@@ -3359,29 +3662,29 @@ function help() {
3359
3662
  " foleo environment [--json]",
3360
3663
  " foleo list [--kind <kind>] [--format <format>] [--runtime <class>] [--limit <n>] [--json]",
3361
3664
  " foleo get <id> [--json]",
3362
- " foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--json]",
3363
- " foleo publish <dir> --accept-hosting-risk --name <label> [--dry-run] [--json]",
3364
- " foleo update <id> <path> --revision <etag> [--json]",
3365
- " foleo update <id> <file.md> --version <version> [--json] (compatibility)",
3665
+ " foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--acknowledge-access-widening] [--json]",
3666
+ " foleo publish <dir> --accept-hosting-risk --name <label> [--runtime-profile auto|open|contained] [--dry-run] [--json]",
3667
+ " foleo update <id> <path> --revision <etag> [--runtime-profile auto|open|contained] [--acknowledge-access-widening] [--json]",
3668
+ " foleo update <id> <file.md> --version <version> [--acknowledge-access-widening] [--json] (compatibility)",
3366
3669
  " foleo name-check <label> [--json]",
3367
3670
  " foleo names [--artifact <id>] [--limit <n>] [--cursor <cursor>] [--json]",
3368
- " foleo name attach <id> <label> [--revision <etag>] [--dry-run] [--json]",
3369
- " foleo name set <id> <label> --previous keep-as-alias|release [--revision <etag>] [--dry-run] [--json]",
3671
+ " foleo name attach <id> <label> [--revision <etag>] [--acknowledge-access-widening] [--dry-run] [--json]",
3672
+ " foleo name set <id> <label> --previous keep-as-alias|release [--revision <etag>] [--acknowledge-access-widening] [--dry-run] [--json]",
3370
3673
  " foleo name release <id> <label> --acknowledge-link-breakage [--revision <etag>] [--dry-run] [--json]",
3371
3674
  " foleo status <id> [--json]",
3372
3675
  " foleo settings <id> [--json]",
3373
- " foleo settings <id> --set k=v [--set k=v ...] [--password-stdin] --revision <etag> [--json]",
3676
+ " foleo settings <id> --set k=v [--set k=v ...] [--password-stdin] --revision <etag> [--acknowledge-access-widening] [--json]",
3374
3677
  " foleo limits [--json]",
3375
3678
  " foleo unpublish <id> --revision <etag> [--json]",
3376
3679
  " foleo delete <id> --revision <etag> [--json]",
3377
- " foleo restore <id> --revision <etag> [--json]",
3680
+ " foleo restore <id> --revision <etag> [--acknowledge-access-widening] [--json]",
3378
3681
  " foleo purge <id> --revision <etag> --confirm <id> [--json]",
3379
3682
  " foleo deletion-status <id> [--json]",
3380
- " foleo html-publish <bundle-root> --accept-hosting-risk (deprecated alias of publish)",
3381
- " foleo html-update <id> <bundle-root> --revision <stateRevision> (deprecated alias of update)",
3683
+ " foleo html-publish <bundle-root> --accept-hosting-risk [--runtime-profile <p>] (deprecated alias of publish)",
3684
+ " foleo html-update <id> <bundle-root> --revision <stateRevision> [--runtime-profile <p>] [--acknowledge-access-widening] (deprecated alias of update)",
3382
3685
  " foleo html-status <id> (deprecated alias of status)",
3383
- " foleo html-visibility <id> --set unlisted|password|private --revision <stateRevision> (deprecated alias of settings)",
3384
- " foleo html-password <id> --password-stdin --revision <stateRevision> (deprecated alias of settings)",
3686
+ " foleo html-visibility <id> --set unlisted|password|private --revision <stateRevision> [--acknowledge-access-widening] (deprecated alias of settings)",
3687
+ " foleo html-password <id> --password-stdin --revision <stateRevision> [--acknowledge-access-widening] (deprecated alias of settings)",
3385
3688
  " foleo html-unpublish <id> --revision <stateRevision> (deprecated alias of unpublish)",
3386
3689
  "",
3387
3690
  "Naming (HTML only):",
@@ -3400,7 +3703,12 @@ function help() {
3400
3703
  "",
3401
3704
  " --dry-run plans an HTML publish without uploading, creating, or spending",
3402
3705
  " quota. It reports the resolved name and availability, url, title with its",
3403
- " resolvedFrom source, visibility, routes, largestFiles and skipped[].",
3706
+ " resolvedFrom source, visibility, routes, largestFiles and skipped[], the",
3707
+ " address class and candidate hostname, the name quota cost, the requested",
3708
+ " runtimeProfile (the applied profile and any blocked contained references",
3709
+ " are decided by the server from uploaded bytes, so a plan reports them as",
3710
+ " unknown), and accessWidening (a create never widens; whether the",
3711
+ " acknowledgement flag is present). A plan approves nothing.",
3404
3712
  " A taken or reserved name fails with name_taken / name_reserved.",
3405
3713
  "",
3406
3714
  " name attach|set|release --dry-run plans a name-lifecycle change with GET",
@@ -3409,7 +3717,9 @@ function help() {
3409
3717
  " D3 promotedAlias (release of the primary) or D4 claimsExistingAlias",
3410
3718
  " (renaming to a name already held as an alias claims nothing), and the",
3411
3719
  " publish.subdomain_claims / publish.subdomain_names.active quota deltas",
3412
- " next to the current quota. A predicted refusal (name_taken, name_reserved,",
3720
+ " next to the current quota, plus accessWidening (whether the change adds a",
3721
+ " working address and whether the acknowledgement flag is present).",
3722
+ " A predicted refusal (name_taken, name_reserved,",
3413
3723
  " name_unchanged, name_not_found, last_name_release_refused, quota_exceeded,",
3414
3724
  " ...) fails with the same stable error object the real command would.",
3415
3725
  "",
@@ -3424,11 +3734,39 @@ function help() {
3424
3734
  " reports that. Do not republish, unpublish or rename to simulate privacy —",
3425
3735
  " none of those makes a document private. Passwords are HTML-only.",
3426
3736
  "",
3737
+ "Access widening (an explicit human decision, never a blanket consent):",
3738
+ " --acknowledge-access-widening tells the API that the human approved THIS",
3739
+ " change exposing an existing artifact to more readers (private or password",
3740
+ " to unlisted, removing a password) or adding a working address (name",
3741
+ " attach, a keep-as-alias rename, restore, republishing unpublished work).",
3742
+ " settings, restore, name attach, name set, publish, update, html-publish,",
3743
+ " html-update, html-visibility and html-password send",
3744
+ " accessWideningAcknowledged: true only when the flag is present. It is never",
3745
+ " inferred from --accept-hosting-risk, and narrowing (private, unpublish,",
3746
+ " delete, name release, a release rename) never needs it. Without it, an API",
3747
+ " key widening fails with acknowledgement_required (HTTP 409, retryable",
3748
+ " false): ask the human, then re-run the same command with the flag.",
3749
+ "",
3750
+ "Runtime profile (HTML publish/update only):",
3751
+ " --runtime-profile auto|open|contained (auto when omitted). auto lets the",
3752
+ " server pick contained only when every static reference fits; contained",
3753
+ " blocks external fetch/XHR/WebSocket, forms, frames and remote media but",
3754
+ " not top-level navigation. An explicit contained that does not fit fails",
3755
+ " with contained_profile_unavailable, lists error.context.references, and is",
3756
+ " never retried as open. On Markdown or any other command it fails with",
3757
+ " runtime_profile_not_applicable. Results report runtimeProfile and",
3758
+ " profileNote.",
3759
+ "",
3427
3760
  "Secrets:",
3428
3761
  " --password <value> is REFUSED (password_flag_unsupported). Secrets never",
3429
3762
  " travel on argv, where they land in shell history and process listings.",
3430
3763
  " Use --password-stdin, and never place a secret inside --set or --settings.",
3431
3764
  "",
3765
+ "Sign-in:",
3766
+ " login keeps one API key per API in macOS Keychain and revokes the key it",
3767
+ " replaces. logout revokes that key and removes it; --no-revoke only removes",
3768
+ " it from this machine. Neither changes FOLEO_TOKEN.",
3769
+ "",
3432
3770
  "Environment:",
3433
3771
  " --production (default), --staging, or --local selects a known API.",
3434
3772
  " FOLEO_ENV=production|staging|local provides the same selection.",
@@ -3438,7 +3776,7 @@ function help() {
3438
3776
  " FOLEO_SKIP_UPDATE_CHECK=1 skips the npm version check.",
3439
3777
  "",
3440
3778
  "Agent guidance: https://foleo.app/agents.md",
3441
- "Foleo MCP is not available during this beta.",
3779
+ "Remote MCP: https://mcp.foleo.app/mcp",
3442
3780
  "",
3443
3781
  ].join("\n");
3444
3782
  }