@foleo/cli 0.1.18 → 0.1.21
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.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +357 -8
- package/dist/index.js.map +1 -1
- package/dist/plan.d.ts +97 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +130 -0
- package/dist/plan.js.map +1 -0
- package/package.json +1 -1
- package/skills/foleo/SKILL.md +46 -0
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,24 @@ type HtmlFile = {
|
|
|
55
55
|
mediaType: string;
|
|
56
56
|
bytes: Uint8Array;
|
|
57
57
|
};
|
|
58
|
-
export
|
|
58
|
+
export type SkippedBundleEntryReason = "dotfile_excluded" | "node_modules_excluded" | "symlink_excluded";
|
|
59
|
+
export interface SkippedBundleEntry {
|
|
60
|
+
path: string;
|
|
61
|
+
reason: SkippedBundleEntryReason;
|
|
62
|
+
}
|
|
63
|
+
export interface ScanBundleResult {
|
|
64
|
+
files: HtmlFile[];
|
|
65
|
+
/**
|
|
66
|
+
* Spec 089 §K.3 / acceptance L914: `scanBundle` silently dropped dotfile,
|
|
67
|
+
* `node_modules`, and symlink entries before this field existed, so a
|
|
68
|
+
* dropped `.well-known/` never appeared anywhere. Every excluded entry is
|
|
69
|
+
* reported here instead of only being skipped.
|
|
70
|
+
*/
|
|
71
|
+
skipped: SkippedBundleEntry[];
|
|
72
|
+
/** Sorted HTML routes, matching each entry's clean-route resolution. */
|
|
73
|
+
routes: string[];
|
|
74
|
+
}
|
|
75
|
+
export declare function scanBundle(root: string, deps: CliDeps): Promise<ScanBundleResult>;
|
|
59
76
|
type LiveDocAssetFile = {
|
|
60
77
|
path: string;
|
|
61
78
|
sha256: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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vB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,wBAAwB,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,gBAAgB,CAAC,CAgP3B;AAwQD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsF7B;AAsuBD,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,MAAM,EACb,SAAS,SAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CA+E1B"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ 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
11
|
import { FoleoError, LocalError, renderFailure, UsageError } from "./errors.js";
|
|
12
|
+
import { deriveArtifactName, resolveHtmlTitle, resolveVisibility, } from "./plan.js";
|
|
12
13
|
const KEYCHAIN_SERVICE = "com.contraverse.foleo.cli";
|
|
13
14
|
const CLI_KEY_SCOPES = [
|
|
14
15
|
"artifacts:read",
|
|
@@ -124,6 +125,8 @@ export async function runCli(argv, deps = {
|
|
|
124
125
|
warnDeprecatedAlias(commandDeps, "html-unpublish", "unpublish <id>");
|
|
125
126
|
return await htmlUnpublish(rest, commandDeps);
|
|
126
127
|
}
|
|
128
|
+
if (command === "name-check")
|
|
129
|
+
return await nameCheck(rest, commandDeps);
|
|
127
130
|
if (command === "settings")
|
|
128
131
|
return await settingsCommand(rest, commandDeps);
|
|
129
132
|
if (command === "limits")
|
|
@@ -195,6 +198,68 @@ function describeArgvToken(raw) {
|
|
|
195
198
|
? `${dashes}${name}`
|
|
196
199
|
: `${dashes}<redacted>`;
|
|
197
200
|
}
|
|
201
|
+
const ARTIFACT_NAME_MIN_LENGTH = 3;
|
|
202
|
+
const ARTIFACT_NAME_MAX_LENGTH = 63;
|
|
203
|
+
const ARTIFACT_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
204
|
+
/**
|
|
205
|
+
* Local DNS-label validation, mirroring the rules the desktop app and the API
|
|
206
|
+
* already enforce (`apps/desktop/src/lib/publish-artifact-name.ts`). It runs
|
|
207
|
+
* before any network call so an invalid label costs nothing: the create-attempt
|
|
208
|
+
* budget is ten per day and is charged even on failure, so trial-and-error
|
|
209
|
+
* naming against the server can lock an account out of publishing for the day.
|
|
210
|
+
*
|
|
211
|
+
* The CLI cannot import the desktop module (separate package, separate release
|
|
212
|
+
* train), so these rules are duplicated deliberately and pinned by a test.
|
|
213
|
+
*/
|
|
214
|
+
function validateArtifactName(raw) {
|
|
215
|
+
const label = raw.trim().toLowerCase();
|
|
216
|
+
if (label.length === 0)
|
|
217
|
+
return { ok: false, reason: "empty" };
|
|
218
|
+
if (label.length < ARTIFACT_NAME_MIN_LENGTH)
|
|
219
|
+
return { ok: false, reason: "too_short" };
|
|
220
|
+
if (label.length > ARTIFACT_NAME_MAX_LENGTH)
|
|
221
|
+
return { ok: false, reason: "too_long" };
|
|
222
|
+
if (label.includes("--"))
|
|
223
|
+
return { ok: false, reason: "consecutive_hyphens" };
|
|
224
|
+
if (!ARTIFACT_NAME_PATTERN.test(label))
|
|
225
|
+
return { ok: false, reason: "invalid_charset" };
|
|
226
|
+
return { ok: true, label };
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The whole naming model in one screen, because an agent that hits this has no
|
|
230
|
+
* other way to learn it: the rules, the permanence, the free way to check, and
|
|
231
|
+
* the fact that a permanent address exists either way.
|
|
232
|
+
*/
|
|
233
|
+
const NAME_MISSING_MESSAGE = [
|
|
234
|
+
"Missing --name.",
|
|
235
|
+
"",
|
|
236
|
+
"HTML artifacts get their own subdomain, and the name is permanent — Foleo has",
|
|
237
|
+
"no rename. Choose it now, or changing the URL later means republishing under a",
|
|
238
|
+
"new id and the old link stops working.",
|
|
239
|
+
"",
|
|
240
|
+
" foleo name-check leadtube --json # free, no quota cost",
|
|
241
|
+
" foleo publish ./site --accept-hosting-risk --name leadtube --dry-run",
|
|
242
|
+
"",
|
|
243
|
+
`Rules: ${ARTIFACT_NAME_MIN_LENGTH}-${ARTIFACT_NAME_MAX_LENGTH} characters, a-z 0-9 and hyphens, no leading, trailing, or doubled hyphen.`,
|
|
244
|
+
"Every artifact also keeps a permanent a-<id>.foleo.site address for stable linking.",
|
|
245
|
+
].join("\n");
|
|
246
|
+
/**
|
|
247
|
+
* Resolve the vanity name for a real (non-dry-run) HTML publish.
|
|
248
|
+
*
|
|
249
|
+
* Required only here. A Markdown publish keeps its derived, reversible slug and
|
|
250
|
+
* must never be asked for a name (spec 089 D4) — the requirement follows the
|
|
251
|
+
* inferred source format, never the command spelling.
|
|
252
|
+
*/
|
|
253
|
+
function requireArtifactName(raw) {
|
|
254
|
+
if (raw === undefined) {
|
|
255
|
+
throw new UsageError(NAME_MISSING_MESSAGE, "name_missing");
|
|
256
|
+
}
|
|
257
|
+
const validated = validateArtifactName(raw);
|
|
258
|
+
if (!validated.ok) {
|
|
259
|
+
throw new UsageError(`Invalid --name "${raw}": ${validated.reason.replace(/_/g, " ")}. Rules: ${ARTIFACT_NAME_MIN_LENGTH}-${ARTIFACT_NAME_MAX_LENGTH} characters, a-z 0-9 and hyphens, no leading, trailing, or doubled hyphen.`, "name_invalid", { value: raw, reason: validated.reason });
|
|
260
|
+
}
|
|
261
|
+
return validated.label;
|
|
262
|
+
}
|
|
198
263
|
function warnDeprecatedAlias(deps, alias, canonical) {
|
|
199
264
|
deps.stderr(`warning: \`foleo ${alias}\` is a deprecated alias; use \`foleo ${canonical}\`.\n`);
|
|
200
265
|
}
|
|
@@ -541,13 +606,191 @@ async function login(args, deps) {
|
|
|
541
606
|
deps.stdout(`Signed in to ${loginResult.org}. Credential saved in macOS Keychain.\n`);
|
|
542
607
|
return 0;
|
|
543
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* `name-check <label>` — free availability probe.
|
|
611
|
+
*
|
|
612
|
+
* Consumes no product quota: it is a read against `GET /v1/subdomains/{label}`,
|
|
613
|
+
* separately fenced at 30/minute. A locally invalid label never reaches the
|
|
614
|
+
* network, so an agent cannot burn the read fence learning the character rules.
|
|
615
|
+
*/
|
|
616
|
+
async function nameCheck(args, deps) {
|
|
617
|
+
const parsed = parseFlags(args);
|
|
618
|
+
const raw = parsed.positionals[0];
|
|
619
|
+
if (!raw || parsed.positionals.length !== 1)
|
|
620
|
+
throw new Error("Usage: foleo name-check <label> [--json]");
|
|
621
|
+
const validated = validateArtifactName(raw);
|
|
622
|
+
if (!validated.ok) {
|
|
623
|
+
const payload = {
|
|
624
|
+
label: raw.trim().toLowerCase(),
|
|
625
|
+
status: "invalid",
|
|
626
|
+
reason: validated.reason,
|
|
627
|
+
};
|
|
628
|
+
if (parsed.json)
|
|
629
|
+
deps.stdout(`${JSON.stringify(payload, null, 2)}\n`);
|
|
630
|
+
else
|
|
631
|
+
deps.stdout(`invalid ${payload.label} (${validated.reason.replace(/_/g, " ")})\n`);
|
|
632
|
+
return 1;
|
|
633
|
+
}
|
|
634
|
+
const result = await requestJson(deps, `/subdomains/${encodeURIComponent(validated.label)}`, { method: "GET", body: undefined });
|
|
635
|
+
const payload = { label: validated.label, status: result.status };
|
|
636
|
+
if (parsed.json)
|
|
637
|
+
deps.stdout(`${JSON.stringify(payload, null, 2)}\n`);
|
|
638
|
+
else
|
|
639
|
+
deps.stdout(`${payload.status} ${payload.label}\n`);
|
|
640
|
+
return payload.status === "available" ? 0 : 1;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* `publish --dry-run` — plan without consuming product quota.
|
|
644
|
+
*
|
|
645
|
+
* Issues no `POST /v1/uploads`, no file PUT and no create. It scans the bundle
|
|
646
|
+
* locally, checks the name when one is in play, and reads `/v1/usage`. Exit 0
|
|
647
|
+
* means the local plan is valid; `executable` reports whether the server state
|
|
648
|
+
* currently admits it, because an unauthenticated or degraded plan must never
|
|
649
|
+
* read as permission to publish (spec 089 D2).
|
|
650
|
+
*/
|
|
651
|
+
/** The largest bundle files by size, so a dry run can flag a heavy upload before it starts. */
|
|
652
|
+
const DRY_RUN_LARGEST_FILES_SHOWN = 5;
|
|
653
|
+
async function htmlPublishDryRun(root, name, parsed, deps) {
|
|
654
|
+
const { files, skipped, routes } = await scanBundle(root, deps);
|
|
655
|
+
const htmlFiles = files.filter((file) => file.mediaType === "text/html; charset=utf-8");
|
|
656
|
+
const entryFile = files.find((file) => file.path === "/index.html");
|
|
657
|
+
const entryHtml = entryFile
|
|
658
|
+
? new TextDecoder("utf-8").decode(entryFile.bytes)
|
|
659
|
+
: undefined;
|
|
660
|
+
const derived = name ??
|
|
661
|
+
deriveArtifactName(root, entryHtml, {
|
|
662
|
+
minLength: ARTIFACT_NAME_MIN_LENGTH,
|
|
663
|
+
maxLength: ARTIFACT_NAME_MAX_LENGTH,
|
|
664
|
+
});
|
|
665
|
+
// Same resolvers the real (non-dry-run) path uses in `htmlPublish` below, so
|
|
666
|
+
// this plan cannot disagree with the apply it previews (spec 089 L860).
|
|
667
|
+
const resolvedTitle = resolveHtmlTitle({
|
|
668
|
+
titleFlag: parsed.title,
|
|
669
|
+
settingsTitle: typeof parsed.settings?.title === "string"
|
|
670
|
+
? parsed.settings.title
|
|
671
|
+
: undefined,
|
|
672
|
+
entryHtml,
|
|
673
|
+
});
|
|
674
|
+
const resolvedVisibility = resolveVisibility({
|
|
675
|
+
settingsVisibility: parsed.settings?.visibility,
|
|
676
|
+
});
|
|
677
|
+
const largestFiles = [...files]
|
|
678
|
+
.sort((a, b) => b.byteSize - a.byteSize || a.path.localeCompare(b.path))
|
|
679
|
+
.slice(0, DRY_RUN_LARGEST_FILES_SHOWN)
|
|
680
|
+
.map((file) => ({ path: file.path, bytes: file.byteSize }));
|
|
681
|
+
let availability = "unknown";
|
|
682
|
+
let checkedAt = null;
|
|
683
|
+
let cost = null;
|
|
684
|
+
let executable = false;
|
|
685
|
+
try {
|
|
686
|
+
const result = await requestJson(deps, `/subdomains/${encodeURIComponent(derived)}`, { method: "GET", body: undefined });
|
|
687
|
+
availability = result.status;
|
|
688
|
+
checkedAt = new Date((deps.now ?? Date.now)()).toISOString();
|
|
689
|
+
if (availability === "taken" || availability === "reserved") {
|
|
690
|
+
// Spec 089 L859: an unavailable name is a failure, not a plan — it gets
|
|
691
|
+
// the same stable error object a real create would fail with, not a
|
|
692
|
+
// buried `plan.name.availability` field an agent has to know to check.
|
|
693
|
+
throw new FoleoError({
|
|
694
|
+
code: availability === "taken" ? "name_taken" : "name_reserved",
|
|
695
|
+
message: `The name "${derived}" is ${availability}.`,
|
|
696
|
+
source: "api",
|
|
697
|
+
retryable: false,
|
|
698
|
+
next: "Choose a different --name and check it first: foleo name-check <label> --json",
|
|
699
|
+
context: { name: derived, availability },
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
cost = await requestJson(deps, "/usage", {
|
|
703
|
+
method: "GET",
|
|
704
|
+
body: undefined,
|
|
705
|
+
});
|
|
706
|
+
executable = availability === "available";
|
|
707
|
+
}
|
|
708
|
+
catch (error) {
|
|
709
|
+
// Only a missing credential may degrade to a bundle-only plan (D2). An
|
|
710
|
+
// expired key, a 500, or a throttle is a real failure: swallowing it into a
|
|
711
|
+
// benign exit-0 "unknown" plan is how an agent concludes a name is free and
|
|
712
|
+
// publishes over the top of something. A `name_taken` / `name_reserved`
|
|
713
|
+
// thrown just above is a `FoleoError` with neither code, so it also falls
|
|
714
|
+
// through to the rethrow below rather than being swallowed.
|
|
715
|
+
if (!(error instanceof FoleoError) || error.code !== "credential_missing") {
|
|
716
|
+
throw error;
|
|
717
|
+
}
|
|
718
|
+
availability = "unknown";
|
|
719
|
+
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");
|
|
720
|
+
}
|
|
721
|
+
const plan = {
|
|
722
|
+
ok: true,
|
|
723
|
+
plan: {
|
|
724
|
+
action: "create",
|
|
725
|
+
scope: cost === null ? "bundle-only" : "full",
|
|
726
|
+
executable,
|
|
727
|
+
name: {
|
|
728
|
+
requested: name ?? null,
|
|
729
|
+
resolved: derived,
|
|
730
|
+
resolvedFrom: name ? "flag" : "derived",
|
|
731
|
+
availability,
|
|
732
|
+
checkedAt,
|
|
733
|
+
},
|
|
734
|
+
url: artifactPreviewUrl(derived, deps),
|
|
735
|
+
title: resolvedTitle,
|
|
736
|
+
visibility: resolvedVisibility.value,
|
|
737
|
+
bundle: {
|
|
738
|
+
fileCount: files.length,
|
|
739
|
+
htmlFileCount: htmlFiles.length,
|
|
740
|
+
totalBytes: files.reduce((n, file) => n + file.byteSize, 0),
|
|
741
|
+
entry: "/index.html",
|
|
742
|
+
routes,
|
|
743
|
+
notFoundPage: files.some((file) => file.path === "/404.html")
|
|
744
|
+
? "/404.html"
|
|
745
|
+
: null,
|
|
746
|
+
skipped,
|
|
747
|
+
largestFiles,
|
|
748
|
+
},
|
|
749
|
+
cost,
|
|
750
|
+
},
|
|
751
|
+
};
|
|
752
|
+
if (parsed.json)
|
|
753
|
+
deps.stdout(`${JSON.stringify(plan, null, 2)}\n`);
|
|
754
|
+
else {
|
|
755
|
+
deps.stdout(`plan: create ${derived} (${availability})\n` +
|
|
756
|
+
`files: ${files.length} (${htmlFiles.length} html)\n` +
|
|
757
|
+
`executable: ${executable}\n`);
|
|
758
|
+
}
|
|
759
|
+
if (name === undefined) {
|
|
760
|
+
deps.stderr("No --name given; the label above is only a suggestion. Pass it explicitly to publish.\n");
|
|
761
|
+
}
|
|
762
|
+
return 0;
|
|
763
|
+
}
|
|
544
764
|
async function htmlPublish(args, deps) {
|
|
545
765
|
resolveUploadRate(deps);
|
|
546
766
|
const parsed = parseFlags(args);
|
|
547
767
|
const root = parsed.positionals[0];
|
|
548
768
|
if (!root || parsed.positionals.length !== 1 || !parsed.acceptHostingRisk)
|
|
549
|
-
throw new Error("Usage: foleo html-publish <bundle-root> --accept-hosting-risk [--settings <json>] [--password-stdin] [--publish-separately] [--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.");
|
|
769
|
+
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.");
|
|
550
770
|
const settings = { ...(parsed.settings ?? {}) };
|
|
771
|
+
// A dry run may omit --name to obtain a derived suggestion; a real create
|
|
772
|
+
// may not (spec 089 §B).
|
|
773
|
+
const name = parsed.dryRun
|
|
774
|
+
? parsed.name === undefined
|
|
775
|
+
? undefined
|
|
776
|
+
: requireArtifactName(parsed.name)
|
|
777
|
+
: requireArtifactName(parsed.name);
|
|
778
|
+
if (parsed.dryRun) {
|
|
779
|
+
return htmlPublishDryRun(root, name, parsed, deps);
|
|
780
|
+
}
|
|
781
|
+
settings.name = name;
|
|
782
|
+
// Same resolver `htmlPublishDryRun` previews with (spec 089 L860): a real
|
|
783
|
+
// create only ever sends an explicit title when `--title` chose one. A
|
|
784
|
+
// `--settings '{"title":…}'` value is already in `settings` verbatim, and a
|
|
785
|
+
// derived-or-fallback title is left unsent so the server derives it itself
|
|
786
|
+
// and `titleUserSet` stays `false` for a title nobody chose.
|
|
787
|
+
const resolvedTitle = resolveHtmlTitle({
|
|
788
|
+
titleFlag: parsed.title,
|
|
789
|
+
settingsTitle: typeof settings.title === "string" ? settings.title : undefined,
|
|
790
|
+
});
|
|
791
|
+
if (resolvedTitle.resolvedFrom === "flag") {
|
|
792
|
+
settings.title = resolvedTitle.value;
|
|
793
|
+
}
|
|
551
794
|
if (parsed.passwordStdin) {
|
|
552
795
|
const password = stripTrailingNewline(await readStdinText(deps));
|
|
553
796
|
if (password.length < 12 || password.length > 256) {
|
|
@@ -779,7 +1022,18 @@ async function htmlUnpublish(args, deps) {
|
|
|
779
1022
|
return 0;
|
|
780
1023
|
}
|
|
781
1024
|
async function publishBundle(root, deps, update, hostingRiskAcknowledged = false, publishSeparately = false, settings) {
|
|
782
|
-
const files = await scanBundle(root, deps);
|
|
1025
|
+
const { files, skipped } = await scanBundle(root, deps);
|
|
1026
|
+
if (skipped.length > 0) {
|
|
1027
|
+
// Spec 089 §K.3 / L914: a dropped `.well-known/` must never be silent on
|
|
1028
|
+
// a real run either, not only in a `--dry-run` plan. stderr, unconditionally
|
|
1029
|
+
// of `--json`, matching the existing progress-line convention.
|
|
1030
|
+
const shown = skipped
|
|
1031
|
+
.slice(0, 10)
|
|
1032
|
+
.map((entry) => `${entry.path} (${entry.reason})`)
|
|
1033
|
+
.join(", ");
|
|
1034
|
+
const rest = skipped.length > 10 ? ` (+${skipped.length - 10} more)` : "";
|
|
1035
|
+
deps.stderr(`Skipped ${skipped.length} bundle ${skipped.length === 1 ? "entry" : "entries"} not uploaded: ${shown}${rest}\n`);
|
|
1036
|
+
}
|
|
783
1037
|
const manifest = files.map(({ bytes: _bytes, ...file }) => file);
|
|
784
1038
|
// One pacer for every /v1/ call in this publish: the zone rate-limit fence
|
|
785
1039
|
// counts the session create and complete calls against the same budget as the
|
|
@@ -1131,18 +1385,39 @@ export async function scanBundle(root, deps) {
|
|
|
1131
1385
|
((path) => boundedReadFileBytes(path, HTML_BUNDLE_MAX_FILE_BYTES, realBase));
|
|
1132
1386
|
const files = [];
|
|
1133
1387
|
const unsupported = [];
|
|
1388
|
+
const skipped = [];
|
|
1134
1389
|
let fileCount = 0;
|
|
1135
1390
|
let totalBytes = 0;
|
|
1391
|
+
function relPosix(absolute) {
|
|
1392
|
+
return relative(base, absolute).split(sep).join("/");
|
|
1393
|
+
}
|
|
1136
1394
|
async function walk(dir) {
|
|
1137
1395
|
for (const name of await list(dir)) {
|
|
1396
|
+
const absolute = join(dir, name);
|
|
1138
1397
|
if (name.startsWith(".") ||
|
|
1139
1398
|
name === "node_modules" ||
|
|
1140
|
-
name.startsWith(".env"))
|
|
1399
|
+
name.startsWith(".env")) {
|
|
1400
|
+
// Still worth knowing whether the excluded entry was a directory (for
|
|
1401
|
+
// the trailing-slash convention below) — best-effort only, since an
|
|
1402
|
+
// entry that cannot be statted is still reported with what we know
|
|
1403
|
+
// rather than dropped silently.
|
|
1404
|
+
const isDirectory = await stat(absolute)
|
|
1405
|
+
.then((info) => info.isDirectory())
|
|
1406
|
+
.catch(() => false);
|
|
1407
|
+
const relative_ = relPosix(absolute);
|
|
1408
|
+
skipped.push({
|
|
1409
|
+
path: isDirectory ? `${relative_}/` : relative_,
|
|
1410
|
+
reason: name === "node_modules"
|
|
1411
|
+
? "node_modules_excluded"
|
|
1412
|
+
: "dotfile_excluded",
|
|
1413
|
+
});
|
|
1141
1414
|
continue;
|
|
1142
|
-
|
|
1415
|
+
}
|
|
1143
1416
|
const info = await stat(absolute);
|
|
1144
|
-
if (info.isSymbolicLink())
|
|
1417
|
+
if (info.isSymbolicLink()) {
|
|
1418
|
+
skipped.push({ path: relPosix(absolute), reason: "symlink_excluded" });
|
|
1145
1419
|
continue;
|
|
1420
|
+
}
|
|
1146
1421
|
if (info.isDirectory()) {
|
|
1147
1422
|
await walk(absolute);
|
|
1148
1423
|
continue;
|
|
@@ -1270,7 +1545,11 @@ export async function scanBundle(root, deps) {
|
|
|
1270
1545
|
throw new LocalError("bundle_ambiguous_route", `Ambiguous HTML route: ${route}`, { context: { route, path: file.path } });
|
|
1271
1546
|
routes.add(route);
|
|
1272
1547
|
}
|
|
1273
|
-
return
|
|
1548
|
+
return {
|
|
1549
|
+
files: files.sort((a, b) => a.path.localeCompare(b.path)),
|
|
1550
|
+
skipped,
|
|
1551
|
+
routes: [...routes].sort((a, b) => a.localeCompare(b)),
|
|
1552
|
+
};
|
|
1274
1553
|
}
|
|
1275
1554
|
function isValidUtf8(bytes) {
|
|
1276
1555
|
try {
|
|
@@ -1364,8 +1643,11 @@ async function publish(args, deps) {
|
|
|
1364
1643
|
const parsed = parseFlags(args);
|
|
1365
1644
|
const file = parsed.positionals[0];
|
|
1366
1645
|
if (!file || parsed.positionals.length !== 1)
|
|
1367
|
-
throw new Error("Usage: foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--accept-hosting-risk] [--json]");
|
|
1646
|
+
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.");
|
|
1368
1647
|
const isDirectory = await pathIsDirectory(file, deps);
|
|
1648
|
+
if (!isDirectory && parsed.dryRun) {
|
|
1649
|
+
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" });
|
|
1650
|
+
}
|
|
1369
1651
|
if (isDirectory) {
|
|
1370
1652
|
if (!parsed.acceptHostingRisk) {
|
|
1371
1653
|
throw new UsageError("foleo publish <path> --accept-hosting-risk is required for an HTML site bundle. The deprecated alias is: foleo html-publish <bundle-root> --accept-hosting-risk", "hosting_risk_unacknowledged");
|
|
@@ -1399,6 +1681,11 @@ async function publish(args, deps) {
|
|
|
1399
1681
|
async function update(args, deps) {
|
|
1400
1682
|
resolveUploadRate(deps);
|
|
1401
1683
|
const parsed = parseFlags(args);
|
|
1684
|
+
// Asking for a plan must never mutate. Until an update plan exists, refuse
|
|
1685
|
+
// the flag rather than silently performing the real update.
|
|
1686
|
+
if (parsed.dryRun) {
|
|
1687
|
+
throw new UsageError("--dry-run is not implemented for update. Run the update without it.", "dry_run_unsupported", { operation: "update" });
|
|
1688
|
+
}
|
|
1402
1689
|
const [id, file] = parsed.positionals;
|
|
1403
1690
|
if (!id || !file || parsed.positionals.length !== 2) {
|
|
1404
1691
|
throw new Error("Usage: foleo update <id> <path> --revision <etag> [--json] (or Markdown compatibility --version <version>)");
|
|
@@ -2004,6 +2291,27 @@ function environmentInfo(deps) {
|
|
|
2004
2291
|
: "production";
|
|
2005
2292
|
return { name, apiBase: base };
|
|
2006
2293
|
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Explicit table, never derived by rewriting the API host (docs/23
|
|
2296
|
+
* "Mappings are explicit tables, never `api.foleo.app` → string-replace →
|
|
2297
|
+
* `foleo.site`"). `local` and `custom` environments have no known tenant
|
|
2298
|
+
* host, matching the Mac app's "loopback / anything else → none" row in the
|
|
2299
|
+
* same doc — a dry-run plan reports `url: null` rather than guessing.
|
|
2300
|
+
*/
|
|
2301
|
+
const TENANT_DOMAIN_BY_ENVIRONMENT = {
|
|
2302
|
+
production: "foleo.site",
|
|
2303
|
+
staging: "foleo-staging.site",
|
|
2304
|
+
};
|
|
2305
|
+
function tenantDomain(deps) {
|
|
2306
|
+
const { name } = environmentInfo(deps);
|
|
2307
|
+
return name === "production" || name === "staging"
|
|
2308
|
+
? TENANT_DOMAIN_BY_ENVIRONMENT[name]
|
|
2309
|
+
: null;
|
|
2310
|
+
}
|
|
2311
|
+
function artifactPreviewUrl(name, deps) {
|
|
2312
|
+
const domain = tenantDomain(deps);
|
|
2313
|
+
return domain ? `https://${name}.${domain}/` : null;
|
|
2314
|
+
}
|
|
2007
2315
|
function announceApi(deps, json) {
|
|
2008
2316
|
if (!json)
|
|
2009
2317
|
deps.stderr(`API: ${apiBase(deps)}\n`);
|
|
@@ -2354,6 +2662,8 @@ function parseFlags(args, options = {}) {
|
|
|
2354
2662
|
let publishSeparately = false;
|
|
2355
2663
|
let allowDelete = false;
|
|
2356
2664
|
let allowPurge = false;
|
|
2665
|
+
let name;
|
|
2666
|
+
let dryRun = false;
|
|
2357
2667
|
for (let i = 0; i < args.length; i++) {
|
|
2358
2668
|
const arg = args[i];
|
|
2359
2669
|
if (arg === "--json") {
|
|
@@ -2366,6 +2676,16 @@ function parseFlags(args, options = {}) {
|
|
|
2366
2676
|
throw new Error("--title requires a value");
|
|
2367
2677
|
continue;
|
|
2368
2678
|
}
|
|
2679
|
+
if (arg === "--name") {
|
|
2680
|
+
name = args[++i];
|
|
2681
|
+
if (!name)
|
|
2682
|
+
throw new UsageError("--name requires a value", "name_missing");
|
|
2683
|
+
continue;
|
|
2684
|
+
}
|
|
2685
|
+
if (arg === "--dry-run") {
|
|
2686
|
+
dryRun = true;
|
|
2687
|
+
continue;
|
|
2688
|
+
}
|
|
2369
2689
|
if (arg === "--version") {
|
|
2370
2690
|
const raw = args[++i];
|
|
2371
2691
|
const parsed = raw === undefined ? Number.NaN : Number(raw);
|
|
@@ -2477,6 +2797,8 @@ function parseFlags(args, options = {}) {
|
|
|
2477
2797
|
publishSeparately,
|
|
2478
2798
|
allowDelete,
|
|
2479
2799
|
allowPurge,
|
|
2800
|
+
...(name === undefined ? {} : { name }),
|
|
2801
|
+
dryRun,
|
|
2480
2802
|
};
|
|
2481
2803
|
}
|
|
2482
2804
|
function parseGlobalFlags(argv) {
|
|
@@ -2492,6 +2814,7 @@ function parseGlobalFlags(argv) {
|
|
|
2492
2814
|
function help() {
|
|
2493
2815
|
return [
|
|
2494
2816
|
"Usage:",
|
|
2817
|
+
" foleo --help",
|
|
2495
2818
|
" foleo login [--allow-delete] [--allow-purge] [--json]",
|
|
2496
2819
|
" foleo whoami [--json]",
|
|
2497
2820
|
" foleo doctor [--json]",
|
|
@@ -2500,9 +2823,11 @@ function help() {
|
|
|
2500
2823
|
" foleo environment [--json]",
|
|
2501
2824
|
" foleo list [--kind <kind>] [--format <format>] [--runtime <class>] [--limit <n>] [--json]",
|
|
2502
2825
|
" foleo get <id> [--json]",
|
|
2503
|
-
" foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--
|
|
2826
|
+
" foleo publish <path> [--title <title>] [--settings <json>] [--password-stdin] [--publish-separately] [--json]",
|
|
2827
|
+
" foleo publish <dir> --accept-hosting-risk --name <label> [--dry-run] [--json]",
|
|
2504
2828
|
" foleo update <id> <path> --revision <etag> [--json]",
|
|
2505
2829
|
" foleo update <id> <file.md> --version <version> [--json] (compatibility)",
|
|
2830
|
+
" foleo name-check <label> [--json]",
|
|
2506
2831
|
" foleo status <id> [--json]",
|
|
2507
2832
|
" foleo settings <id> [--json]",
|
|
2508
2833
|
" foleo settings <id> --set k=v [--set k=v ...] [--password-stdin] --revision <etag> [--json]",
|
|
@@ -2519,11 +2844,35 @@ function help() {
|
|
|
2519
2844
|
" foleo html-password <id> --password-stdin --revision <stateRevision> (deprecated alias of settings)",
|
|
2520
2845
|
" foleo html-unpublish <id> --revision <stateRevision> (deprecated alias of unpublish)",
|
|
2521
2846
|
"",
|
|
2847
|
+
"Naming (HTML only):",
|
|
2848
|
+
" --name <label> is REQUIRED on every real HTML publish, and is PERMANENT:",
|
|
2849
|
+
" there is no rename, so a new URL means republishing under a new id and",
|
|
2850
|
+
" the old link breaks. Choose it with the human.",
|
|
2851
|
+
" Labels are 3-63 chars, a-z 0-9 and hyphens, with no leading, trailing or",
|
|
2852
|
+
" doubled hyphen. Invalid labels fail locally, before any network call.",
|
|
2853
|
+
" Markdown never requires --name and ignores it; the requirement follows",
|
|
2854
|
+
" the format inferred from the path, not the command you typed.",
|
|
2855
|
+
" Every artifact also keeps a permanent a-<id>.foleo.site address.",
|
|
2856
|
+
"",
|
|
2857
|
+
" --dry-run plans an HTML publish without uploading, creating, or spending",
|
|
2858
|
+
" quota. It reports the resolved name and availability, url, title with its",
|
|
2859
|
+
" resolvedFrom source, visibility, routes, largestFiles and skipped[].",
|
|
2860
|
+
" A taken or reserved name fails with name_taken / name_reserved.",
|
|
2861
|
+
" On Markdown or on update it refuses with dry_run_unsupported.",
|
|
2862
|
+
" name-check <label> is free and checks availability without publishing.",
|
|
2863
|
+
"",
|
|
2864
|
+
"Secrets:",
|
|
2865
|
+
" --password <value> is REFUSED (password_flag_unsupported). Secrets never",
|
|
2866
|
+
" travel on argv, where they land in shell history and process listings.",
|
|
2867
|
+
" Use --password-stdin, and never place a secret inside --set or --settings.",
|
|
2868
|
+
"",
|
|
2522
2869
|
"Environment:",
|
|
2523
2870
|
" --production (default), --staging, or --local selects a known API.",
|
|
2524
2871
|
" FOLEO_ENV=production|staging|local provides the same selection.",
|
|
2525
2872
|
" FOLEO_API_BASE explicitly overrides the selected API.",
|
|
2526
2873
|
" FOLEO_TOKEN uses an explicit API token.",
|
|
2874
|
+
" FOLEO_UPLOAD_RATE=1-60 caps concurrent file uploads (default 7).",
|
|
2875
|
+
" FOLEO_SKIP_UPDATE_CHECK=1 skips the npm version check.",
|
|
2527
2876
|
"",
|
|
2528
2877
|
"Agent guidance: https://foleo.app/agents.md",
|
|
2529
2878
|
"Foleo MCP is not available during this beta.",
|