@foleo/cli 0.1.32 → 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
@@ -59,6 +59,40 @@ export const SETTINGS_SURFACE_FIELD_IDS = [
59
59
  "password",
60
60
  "customDomain",
61
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
+ }
62
96
  const LIVE_DOC_ASSET_MEDIA_TYPES = {
63
97
  ".png": "image/png",
64
98
  ".jpg": "image/jpeg",
@@ -105,6 +139,14 @@ export async function runCli(argv, deps = {
105
139
  if (rest.includes("--dry-run") && !DRY_RUN_AWARE_COMMANDS.has(command)) {
106
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 });
107
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
+ }
108
150
  if (command === "publish")
109
151
  return await publish(rest, commandDeps);
110
152
  if (command === "update")
@@ -922,6 +964,7 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
922
964
  availability = "unknown";
923
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");
924
966
  }
967
+ const previewUrl = artifactPreviewUrl(derived, deps);
925
968
  const plan = {
926
969
  ok: true,
927
970
  plan: {
@@ -935,9 +978,38 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
935
978
  availability,
936
979
  checkedAt,
937
980
  },
938
- 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
+ },
939
992
  title: resolvedTitle,
940
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
+ },
941
1013
  bundle: {
942
1014
  fileCount: files.length,
943
1015
  htmlFileCount: htmlFiles.length,
@@ -958,6 +1030,8 @@ async function htmlPublishDryRun(root, name, parsed, deps) {
958
1030
  else {
959
1031
  deps.stdout(`plan: create ${derived} (${availability})\n` +
960
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` +
961
1035
  `executable: ${executable}\n`);
962
1036
  }
963
1037
  if (name === undefined) {
@@ -970,7 +1044,7 @@ async function htmlPublish(args, deps) {
970
1044
  const parsed = parseFlags(args);
971
1045
  const root = parsed.positionals[0];
972
1046
  if (!root || parsed.positionals.length !== 1 || !parsed.acceptHostingRisk)
973
- 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.");
974
1048
  const settings = { ...(parsed.settings ?? {}) };
975
1049
  // A dry run may omit --name to obtain a derived suggestion; a real create
976
1050
  // may not (spec 089 §B).
@@ -1014,10 +1088,18 @@ async function htmlPublish(args, deps) {
1014
1088
  settings.password = password;
1015
1089
  }
1016
1090
  announceApi(deps, parsed.json);
1017
- 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));
1018
1092
  writeResult(deps, result, parsed.json);
1019
1093
  return 0;
1020
1094
  }
1095
+ function htmlWireOptions(parsed) {
1096
+ return {
1097
+ ...(parsed.runtimeProfile === undefined
1098
+ ? {}
1099
+ : { runtimeProfile: parsed.runtimeProfile }),
1100
+ acknowledgeAccessWidening: parsed.acknowledgeAccessWidening,
1101
+ };
1102
+ }
1021
1103
  async function htmlUpdate(args, deps) {
1022
1104
  resolveUploadRate(deps);
1023
1105
  const parsed = parseFlags(args);
@@ -1030,12 +1112,8 @@ async function htmlUpdate(args, deps) {
1030
1112
  const [id, root] = parsed.positionals;
1031
1113
  const revision = legacyRevision(parsed.revision);
1032
1114
  if (!id || !root || parsed.positionals.length !== 2 || revision === null)
1033
- throw new Error("Usage: foleo html-update <id> <bundle-root> --revision <stateRevision> [--json]");
1034
- const result = await publishBundle(root, deps, {
1035
- family: "compatibility",
1036
- id,
1037
- revision,
1038
- });
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));
1039
1117
  writeResult(deps, result, parsed.json);
1040
1118
  return 0;
1041
1119
  }
@@ -1055,11 +1133,14 @@ async function htmlVisibility(args, deps) {
1055
1133
  revision === null ||
1056
1134
  !parsed.set ||
1057
1135
  !["unlisted", "password", "private"].includes(parsed.set))
1058
- 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]");
1059
1137
  announceApi(deps, parsed.json);
1060
1138
  const result = await requestJson(deps, `/artifacts/html/${encodeURIComponent(id)}/visibility`, {
1061
1139
  method: "PATCH",
1062
- body: { visibility: parsed.set },
1140
+ body: {
1141
+ visibility: parsed.set,
1142
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1143
+ },
1063
1144
  headers: revisionHeaders(revision),
1064
1145
  });
1065
1146
  writeResult(deps, result, parsed.json);
@@ -1070,10 +1151,10 @@ async function htmlPassword(args, deps) {
1070
1151
  const id = parsed.positionals[0];
1071
1152
  const revision = legacyRevision(parsed.revision);
1072
1153
  if (!id || parsed.positionals.length !== 1 || revision === null) {
1073
- 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]");
1074
1155
  }
1075
1156
  if (!parsed.passwordStdin) {
1076
- 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]");
1077
1158
  }
1078
1159
  const password = stripTrailingNewline(await readStdinText(deps));
1079
1160
  if (password.length < 12 || password.length > 256) {
@@ -1082,7 +1163,12 @@ async function htmlPassword(args, deps) {
1082
1163
  announceApi(deps, parsed.json);
1083
1164
  const result = await requestJson(deps, `/artifacts/html/${encodeURIComponent(id)}/password`, {
1084
1165
  method: "PATCH",
1085
- 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
+ },
1086
1172
  headers: revisionHeaders(revision),
1087
1173
  });
1088
1174
  writeResult(deps, result, parsed.json);
@@ -1092,7 +1178,7 @@ async function settingsCommand(args, deps) {
1092
1178
  const parsed = parseFlags(args);
1093
1179
  const id = parsed.positionals[0];
1094
1180
  if (!id || parsed.positionals.length !== 1) {
1095
- 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]");
1096
1182
  }
1097
1183
  const patch = parseSettingsSets(parsed.sets);
1098
1184
  if (parsed.passwordStdin) {
@@ -1112,11 +1198,14 @@ async function settingsCommand(args, deps) {
1112
1198
  }
1113
1199
  const revision = artifactRevision(parsed.revision);
1114
1200
  if (revision === null) {
1115
- 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]");
1116
1202
  }
1117
1203
  writeResult(deps, await requestJson(deps, `/artifacts/${encodeURIComponent(id)}/settings`, {
1118
1204
  method: "PATCH",
1119
- body: { settings: patch },
1205
+ body: {
1206
+ settings: patch,
1207
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1208
+ },
1120
1209
  headers: {
1121
1210
  ...artifactMutationHeaders(revision, randomUUID()),
1122
1211
  "content-type": "application/merge-patch+json",
@@ -1242,7 +1331,16 @@ async function htmlUnpublish(args, deps) {
1242
1331
  writeResult(deps, result, parsed.json);
1243
1332
  return 0;
1244
1333
  }
1245
- 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
+ };
1246
1344
  const { files, skipped } = await scanBundle(root, deps);
1247
1345
  if (skipped.length > 0) {
1248
1346
  // Spec 089 §K.3 / L914: a dropped `.well-known/` must never be silent on
@@ -1323,6 +1421,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1323
1421
  uploadId: upload.uploadId,
1324
1422
  manifestHash: upload.manifestHash,
1325
1423
  source,
1424
+ ...wireFields,
1326
1425
  },
1327
1426
  headers: {
1328
1427
  "if-match": `"r${update.revision}"`,
@@ -1338,6 +1437,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1338
1437
  uploadId: upload.uploadId,
1339
1438
  manifestHash: upload.manifestHash,
1340
1439
  source,
1440
+ ...wireFields,
1341
1441
  },
1342
1442
  headers: artifactMutationHeaders(update.etag, createKey),
1343
1443
  });
@@ -1352,6 +1452,7 @@ async function publishBundle(root, deps, update, hostingRiskAcknowledged = false
1352
1452
  source,
1353
1453
  ...(publishSeparately ? { allowDuplicate: true } : {}),
1354
1454
  ...(settings && Object.keys(settings).length > 0 ? { settings } : {}),
1455
+ ...wireFields,
1355
1456
  },
1356
1457
  headers: { "idempotency-key": createKey },
1357
1458
  });
@@ -1864,7 +1965,7 @@ async function publish(args, deps) {
1864
1965
  const parsed = parseFlags(args);
1865
1966
  const file = parsed.positionals[0];
1866
1967
  if (!file || parsed.positionals.length !== 1)
1867
- 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.");
1868
1969
  const isDirectory = await pathIsDirectory(file, deps);
1869
1970
  if (!isDirectory && parsed.dryRun) {
1870
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" });
@@ -1878,6 +1979,9 @@ async function publish(args, deps) {
1878
1979
  if (!file.toLowerCase().endsWith(".md")) {
1879
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 } });
1880
1981
  }
1982
+ if (parsed.runtimeProfile !== undefined) {
1983
+ throw runtimeProfileNotApplicable({ sourceFormat: "markdown" });
1984
+ }
1881
1985
  const markdown = await deps.readFile(file, "utf8");
1882
1986
  const assets = await uploadMarkdownAssets(file, markdown, deps);
1883
1987
  const result = await requestJson(deps, "/artifacts", {
@@ -1894,6 +1998,7 @@ async function publish(args, deps) {
1894
1998
  ...(assets
1895
1999
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1896
2000
  : {}),
2001
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1897
2002
  },
1898
2003
  });
1899
2004
  writeResult(deps, result, parsed.json);
@@ -1909,27 +2014,26 @@ async function update(args, deps) {
1909
2014
  }
1910
2015
  const [id, file] = parsed.positionals;
1911
2016
  if (!id || !file || parsed.positionals.length !== 2) {
1912
- 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>)");
1913
2018
  }
1914
2019
  const isDirectory = await pathIsDirectory(file, deps);
1915
2020
  if (isDirectory) {
1916
2021
  const revision = artifactRevision(parsed.revision);
1917
2022
  if (revision === null) {
1918
- 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]");
1919
2024
  }
1920
- const result = await publishBundle(file, deps, {
1921
- family: "generic",
1922
- id,
1923
- etag: revision,
1924
- });
2025
+ const result = await publishBundle(file, deps, { family: "generic", id, etag: revision }, false, false, undefined, htmlWireOptions(parsed));
1925
2026
  writeResult(deps, result, parsed.json);
1926
2027
  return 0;
1927
2028
  }
1928
2029
  if (!file.toLowerCase().endsWith(".md")) {
1929
2030
  throw new Error("Unsupported update input. Use a .md file or an HTML site directory.");
1930
2031
  }
2032
+ if (parsed.runtimeProfile !== undefined) {
2033
+ throw runtimeProfileNotApplicable({ sourceFormat: "markdown" });
2034
+ }
1931
2035
  if (parsed.version === undefined && parsed.revision === undefined) {
1932
- 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>)");
1933
2037
  }
1934
2038
  const opaqueRevision = parsed.revision === undefined ? null : artifactRevision(parsed.revision);
1935
2039
  if (parsed.revision !== undefined && opaqueRevision === null) {
@@ -1949,6 +2053,7 @@ async function update(args, deps) {
1949
2053
  ...(assets
1950
2054
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1951
2055
  : {}),
2056
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1952
2057
  },
1953
2058
  headers: artifactMutationHeaders(opaqueRevision, randomUUID()),
1954
2059
  })
@@ -1961,6 +2066,7 @@ async function update(args, deps) {
1961
2066
  ...(assets
1962
2067
  ? { uploadId: assets.uploadId, manifestHash: assets.manifestHash }
1963
2068
  : {}),
2069
+ ...accessWideningField(parsed.acknowledgeAccessWidening),
1964
2070
  },
1965
2071
  });
1966
2072
  writeResult(deps, result, parsed.json);
@@ -2176,8 +2282,8 @@ async function unpublish(args, deps) {
2176
2282
  */
2177
2283
  const NAME_USAGE = [
2178
2284
  "Usage:",
2179
- " foleo name attach <id> <label> [--revision <etag>] [--dry-run] [--json]",
2180
- " 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]",
2181
2287
  " foleo name release <id> <label> --acknowledge-link-breakage [--revision <etag>] [--dry-run] [--json]",
2182
2288
  ].join("\n");
2183
2289
  /**
@@ -2217,12 +2323,16 @@ async function nameCommand(args, deps) {
2217
2323
  // re-issuing the mutation under a fresh identity.
2218
2324
  const idempotencyKey = randomUUID();
2219
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);
2220
2330
  const request = sub === "attach"
2221
2331
  ? {
2222
2332
  activity: "attaching the name",
2223
2333
  path: `/artifacts/${encodedId}/name`,
2224
2334
  method: "POST",
2225
- body: { name: label },
2335
+ body: { name: label, ...widening },
2226
2336
  }
2227
2337
  : sub === "set"
2228
2338
  ? {
@@ -2237,6 +2347,7 @@ async function nameCommand(args, deps) {
2237
2347
  name: label,
2238
2348
  previousLabel: parsed.previous,
2239
2349
  expectedPreviousLabel: snapshot.name,
2350
+ ...widening,
2240
2351
  },
2241
2352
  }
2242
2353
  : {
@@ -2467,6 +2578,11 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2467
2578
  .filter((hostname) => hostname !== resultHostname &&
2468
2579
  !addressesThatStopWorking.includes(hostname))
2469
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);
2470
2586
  const plan = {
2471
2587
  ok: true,
2472
2588
  plan: {
@@ -2484,6 +2600,14 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2484
2600
  [NAME_QUOTA_DIMENSIONS.activeNames]: activeDelta,
2485
2601
  current: quota,
2486
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
+ },
2487
2611
  executable: true,
2488
2612
  },
2489
2613
  };
@@ -2495,6 +2619,7 @@ async function nameDryRun(sub, id, label, parsed, deps) {
2495
2619
  ` (${plan.plan.result.primaryUrl ?? "unknown"})\n` +
2496
2620
  `stops working: ${addressesThatStopWorking.join(", ") || "none"}\n` +
2497
2621
  `keeps working: ${addressesThatKeepWorking.join(", ") || "none"}\n` +
2622
+ `access widening: ${mayWiden ? "yes" : "no"}; --acknowledge-access-widening ${plan.plan.accessWidening.acknowledged ? "present" : "absent"}\n` +
2498
2623
  `executable: true\n`);
2499
2624
  }
2500
2625
  return 0;
@@ -2588,12 +2713,18 @@ async function restoreArtifact(args, deps) {
2588
2713
  const id = parsed.positionals[0];
2589
2714
  const revision = artifactRevision(parsed.revision);
2590
2715
  if (!id || parsed.positionals.length !== 1 || revision === null) {
2591
- throw new Error("Usage: foleo restore <id> --revision <etag> [--json]");
2716
+ throw new Error("Usage: foleo restore <id> --revision <etag> [--acknowledge-access-widening] [--json]");
2592
2717
  }
2593
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;
2594
2725
  const result = await withRateLimitRetry(deps, "restoring the artifact", () => requestJson(deps, `/artifacts/${encodeURIComponent(id)}/restore`, {
2595
2726
  method: "POST",
2596
- body: undefined,
2727
+ body,
2597
2728
  headers: artifactMutationHeaders(revision, idempotencyKey),
2598
2729
  }));
2599
2730
  writeDeletionResult(deps, result, parsed.json);
@@ -2782,14 +2913,29 @@ class ApiRequestError extends FoleoError {
2782
2913
  body;
2783
2914
  constructor(status, code, body) {
2784
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;
2785
2924
  super({
2786
2925
  code,
2787
2926
  message: code === "matching_source_exists"
2788
2927
  ? matchingSourceExistsMessage(body)
2789
- : `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}`,
2790
2934
  httpStatus: status,
2791
2935
  source: "api",
2936
+ retryable,
2792
2937
  ...(next === null ? {} : { next }),
2938
+ ...(references === null ? {} : { context: { references } }),
2793
2939
  });
2794
2940
  this.name = "ApiRequestError";
2795
2941
  this.status = status;
@@ -2813,6 +2959,20 @@ function apiErrorNext(body) {
2813
2959
  const envelope = isRecord(body) && isRecord(body.error) ? body.error : null;
2814
2960
  return envelope && typeof envelope.next === "string" ? envelope.next : null;
2815
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
+ }
2816
2976
  function matchingSourceExistsMessage(body) {
2817
2977
  const errorBody = isRecord(body) && isRecord(body.error) ? body.error : null;
2818
2978
  const matches = errorBody && Array.isArray(errorBody.matches)
@@ -3205,6 +3365,13 @@ function writeResult(deps, result, json) {
3205
3365
  }
3206
3366
  if (result !== null && typeof result === "object" && "url" in result) {
3207
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
+ }
3208
3375
  return;
3209
3376
  }
3210
3377
  deps.stdout(`${JSON.stringify(result)}\n`);
@@ -3290,6 +3457,8 @@ function parseFlags(args, options = {}) {
3290
3457
  let dryRun = false;
3291
3458
  let previous;
3292
3459
  let acknowledgeLinkBreakage = false;
3460
+ let acknowledgeAccessWidening = false;
3461
+ let runtimeProfile;
3293
3462
  let artifact;
3294
3463
  let cursor;
3295
3464
  for (let i = 0; i < args.length; i++) {
@@ -3400,6 +3569,19 @@ function parseFlags(args, options = {}) {
3400
3569
  acknowledgeLinkBreakage = true;
3401
3570
  continue;
3402
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
+ }
3403
3585
  if (arg === "--artifact") {
3404
3586
  artifact = args[++i];
3405
3587
  if (!artifact)
@@ -3451,6 +3633,8 @@ function parseFlags(args, options = {}) {
3451
3633
  dryRun,
3452
3634
  ...(previous === undefined ? {} : { previous }),
3453
3635
  acknowledgeLinkBreakage,
3636
+ acknowledgeAccessWidening,
3637
+ ...(runtimeProfile === undefined ? {} : { runtimeProfile }),
3454
3638
  ...(artifact === undefined ? {} : { artifact }),
3455
3639
  ...(cursor === undefined ? {} : { cursor }),
3456
3640
  };
@@ -3478,29 +3662,29 @@ function help() {
3478
3662
  " foleo environment [--json]",
3479
3663
  " foleo list [--kind <kind>] [--format <format>] [--runtime <class>] [--limit <n>] [--json]",
3480
3664
  " foleo get <id> [--json]",
3481
- " foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--json]",
3482
- " foleo publish <dir> --accept-hosting-risk --name <label> [--dry-run] [--json]",
3483
- " foleo update <id> <path> --revision <etag> [--json]",
3484
- " 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)",
3485
3669
  " foleo name-check <label> [--json]",
3486
3670
  " foleo names [--artifact <id>] [--limit <n>] [--cursor <cursor>] [--json]",
3487
- " foleo name attach <id> <label> [--revision <etag>] [--dry-run] [--json]",
3488
- " 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]",
3489
3673
  " foleo name release <id> <label> --acknowledge-link-breakage [--revision <etag>] [--dry-run] [--json]",
3490
3674
  " foleo status <id> [--json]",
3491
3675
  " foleo settings <id> [--json]",
3492
- " 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]",
3493
3677
  " foleo limits [--json]",
3494
3678
  " foleo unpublish <id> --revision <etag> [--json]",
3495
3679
  " foleo delete <id> --revision <etag> [--json]",
3496
- " foleo restore <id> --revision <etag> [--json]",
3680
+ " foleo restore <id> --revision <etag> [--acknowledge-access-widening] [--json]",
3497
3681
  " foleo purge <id> --revision <etag> --confirm <id> [--json]",
3498
3682
  " foleo deletion-status <id> [--json]",
3499
- " foleo html-publish <bundle-root> --accept-hosting-risk (deprecated alias of publish)",
3500
- " 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)",
3501
3685
  " foleo html-status <id> (deprecated alias of status)",
3502
- " foleo html-visibility <id> --set unlisted|password|private --revision <stateRevision> (deprecated alias of settings)",
3503
- " 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)",
3504
3688
  " foleo html-unpublish <id> --revision <stateRevision> (deprecated alias of unpublish)",
3505
3689
  "",
3506
3690
  "Naming (HTML only):",
@@ -3519,7 +3703,12 @@ function help() {
3519
3703
  "",
3520
3704
  " --dry-run plans an HTML publish without uploading, creating, or spending",
3521
3705
  " quota. It reports the resolved name and availability, url, title with its",
3522
- " 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.",
3523
3712
  " A taken or reserved name fails with name_taken / name_reserved.",
3524
3713
  "",
3525
3714
  " name attach|set|release --dry-run plans a name-lifecycle change with GET",
@@ -3528,7 +3717,9 @@ function help() {
3528
3717
  " D3 promotedAlias (release of the primary) or D4 claimsExistingAlias",
3529
3718
  " (renaming to a name already held as an alias claims nothing), and the",
3530
3719
  " publish.subdomain_claims / publish.subdomain_names.active quota deltas",
3531
- " 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,",
3532
3723
  " name_unchanged, name_not_found, last_name_release_refused, quota_exceeded,",
3533
3724
  " ...) fails with the same stable error object the real command would.",
3534
3725
  "",
@@ -3543,6 +3734,29 @@ function help() {
3543
3734
  " reports that. Do not republish, unpublish or rename to simulate privacy —",
3544
3735
  " none of those makes a document private. Passwords are HTML-only.",
3545
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
+ "",
3546
3760
  "Secrets:",
3547
3761
  " --password <value> is REFUSED (password_flag_unsupported). Secrets never",
3548
3762
  " travel on argv, where they land in shell history and process listings.",