@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/plan.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec 089 §D — the resolvers shared by `publish --dry-run` and the real HTML
|
|
3
|
+
* publish path.
|
|
4
|
+
*
|
|
5
|
+
* Architecture outline: "A plan builder produces the `--dry-run` payload and
|
|
6
|
+
* shares name and existing-default resolution with a real run, so a plan
|
|
7
|
+
* cannot disagree with the apply." Before this module, `htmlPublishDryRun`
|
|
8
|
+
* derived a suggested name from the bundle directory only and never resolved
|
|
9
|
+
* title or visibility at all, so acceptance criterion L860 ("a plan's
|
|
10
|
+
* resolved name/title/visibility are byte-identical to those the same
|
|
11
|
+
* invocation without `--dry-run` would send") could not hold — there was no
|
|
12
|
+
* single implementation for either path to agree with.
|
|
13
|
+
*
|
|
14
|
+
* This module is deliberately dependency-free (no `CliDeps`, no network, no
|
|
15
|
+
* filesystem): callers pass in whatever local values they already have
|
|
16
|
+
* (parsed flags, scanned bundle bytes), which keeps it trivially unit
|
|
17
|
+
* testable and keeps the resolution logic itself single-sourced regardless of
|
|
18
|
+
* which caller (dry run or real create) invokes it.
|
|
19
|
+
*/
|
|
20
|
+
/** Mirrors `TITLE_MAX_SCALARS` in `infra/publish/src/api-worker/titles-slugs.ts`. */
|
|
21
|
+
export const TITLE_MAX_SCALARS = 120;
|
|
22
|
+
/** HTML artifact title fallback, mirroring `FALLBACK_TITLE` in the same file. */
|
|
23
|
+
export const FALLBACK_TITLE = "Untitled";
|
|
24
|
+
/**
|
|
25
|
+
* Sanitize a freeform filename/title into an ASCII vanity-name label
|
|
26
|
+
* candidate. Mirrors `sanitizeArtifactNameSource` in
|
|
27
|
+
* `apps/desktop/src/lib/publish-artifact-name.ts` — the CLI cannot import the
|
|
28
|
+
* desktop module (separate package, separate release train), so the rule is
|
|
29
|
+
* duplicated deliberately, as `validateArtifactName` already is in
|
|
30
|
+
* `index.ts`.
|
|
31
|
+
*/
|
|
32
|
+
export function sanitizeNameSource(raw, maxLength) {
|
|
33
|
+
let label = raw.trim().toLowerCase();
|
|
34
|
+
label = label.replace(/[^a-z0-9]+/g, "-");
|
|
35
|
+
label = label.replace(/^-+|-+$/g, "");
|
|
36
|
+
if (label.length > maxLength) {
|
|
37
|
+
label = label.slice(0, maxLength).replace(/-+$/g, "");
|
|
38
|
+
}
|
|
39
|
+
return label;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Best-effort `<title>` extraction from an HTML document string, mirroring
|
|
43
|
+
* the entry-file branch of `deriveHtmlTitle` in
|
|
44
|
+
* `infra/publish/src/api-worker/titles-slugs.ts` (the API never passes a
|
|
45
|
+
* `filename` fallback for an HTML create, so that branch is not mirrored
|
|
46
|
+
* here). This does not replicate that file's `safePublicText` /
|
|
47
|
+
* `containsSensitiveReference` redaction — those affect only pathological
|
|
48
|
+
* titles (secrets or absolute paths embedded in a page title) and pulling in
|
|
49
|
+
* `@foleo/renderer` to match them exactly would give the dependency-free CLI
|
|
50
|
+
* a server-side dependency. Whitespace collapse, trim, and the same
|
|
51
|
+
* `TITLE_MAX_SCALARS` truncation ceiling cover the common case, which is what
|
|
52
|
+
* a dry-run preview needs.
|
|
53
|
+
*/
|
|
54
|
+
export function extractHtmlDocumentTitle(html, maxScalars = TITLE_MAX_SCALARS) {
|
|
55
|
+
const match = /<title\b[^>]*>([^<]*)<\/title>/i.exec(html);
|
|
56
|
+
if (!match)
|
|
57
|
+
return null;
|
|
58
|
+
const collapsed = match[1].replace(/\s+/g, " ").trim();
|
|
59
|
+
if (collapsed.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
const scalars = [...collapsed];
|
|
62
|
+
if (scalars.length <= maxScalars)
|
|
63
|
+
return collapsed;
|
|
64
|
+
return scalars.slice(0, maxScalars).join("").trim();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Suggestion only — never auto-claimed (spec 089 §B: "Foleo never auto-claims
|
|
68
|
+
* a derived global name"). Prefers a label derived from the bundle's
|
|
69
|
+
* `<title>`, then the bundle directory name, matching §B's derive-and-confirm
|
|
70
|
+
* order. Always returns a non-empty candidate; when neither source sanitizes
|
|
71
|
+
* to a usable label, the caller still gets a directory-shaped fallback rather
|
|
72
|
+
* than an unusable empty string, because the label is only ever a suggestion
|
|
73
|
+
* the caller must pass back explicitly with `--name`.
|
|
74
|
+
*/
|
|
75
|
+
export function deriveArtifactName(root, entryHtml, bounds) {
|
|
76
|
+
const fromTitle = entryHtml ? extractHtmlDocumentTitle(entryHtml) : null;
|
|
77
|
+
const leaf = root.replace(/\/+$/, "").split(/[\\/]/).pop() ?? "site";
|
|
78
|
+
const candidates = [fromTitle, leaf]
|
|
79
|
+
.filter((value) => typeof value === "string" && value.length > 0)
|
|
80
|
+
.map((value) => sanitizeNameSource(value, bounds.maxLength));
|
|
81
|
+
for (const candidate of candidates) {
|
|
82
|
+
if (candidate.length >= bounds.minLength)
|
|
83
|
+
return candidate;
|
|
84
|
+
}
|
|
85
|
+
return "site";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The one title resolver for both the dry-run plan and the real HTML create.
|
|
89
|
+
* `--title` (when the real path forwards it, see `index.ts`) wins over a
|
|
90
|
+
* `--settings '{"title":…}'` value, which wins over deriving from the
|
|
91
|
+
* bundle's `<title>` tag, which falls back to the server's own
|
|
92
|
+
* `FALLBACK_TITLE`. Only the "flag" outcome is ever sent explicitly by a real
|
|
93
|
+
* create — "settings" is already present verbatim in the request's settings
|
|
94
|
+
* object, and "index.html <title>" / "fallback" are left for the server to
|
|
95
|
+
* derive itself so `titleUserSet` stays `false` for a title nobody chose.
|
|
96
|
+
*/
|
|
97
|
+
export function resolveHtmlTitle(input) {
|
|
98
|
+
if (input.titleFlag !== undefined) {
|
|
99
|
+
return { value: input.titleFlag, resolvedFrom: "flag" };
|
|
100
|
+
}
|
|
101
|
+
if (input.settingsTitle !== undefined) {
|
|
102
|
+
return { value: input.settingsTitle, resolvedFrom: "settings" };
|
|
103
|
+
}
|
|
104
|
+
const derived = input.entryHtml
|
|
105
|
+
? extractHtmlDocumentTitle(input.entryHtml)
|
|
106
|
+
: null;
|
|
107
|
+
if (derived !== null) {
|
|
108
|
+
return { value: derived, resolvedFrom: "index.html <title>" };
|
|
109
|
+
}
|
|
110
|
+
return { value: FALLBACK_TITLE, resolvedFrom: "fallback" };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Visibility resolver for both paths. Spec 089 §A: "current create hardcodes
|
|
114
|
+
* `unlisted`; override is not in this slice" as a CLI-dedicated flag — but
|
|
115
|
+
* `prepareHtmlCreateAccessSettings`
|
|
116
|
+
* (`infra/publish/src/api-worker/settings.ts`) already accepts
|
|
117
|
+
* `settings.visibility` at create time and defaults to `"unlisted"` exactly
|
|
118
|
+
* as this function does, so the CLI's existing generic `--settings` passthrough
|
|
119
|
+
* already agrees with this resolver without any real-path code change: this
|
|
120
|
+
* function exists to preview that outcome, not to add a new create-time
|
|
121
|
+
* mutation flag.
|
|
122
|
+
*/
|
|
123
|
+
export function resolveVisibility(input) {
|
|
124
|
+
if (typeof input.settingsVisibility === "string" &&
|
|
125
|
+
input.settingsVisibility.length > 0) {
|
|
126
|
+
return { value: input.settingsVisibility, resolvedFrom: "settings" };
|
|
127
|
+
}
|
|
128
|
+
return { value: "unlisted", resolvedFrom: "default" };
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=plan.js.map
|
package/dist/plan.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AAE,UAAU,EAAE,CAAC;IAClE,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS;QAC7B,CAAC,CAAC,wBAAwB,CAAC,KAAK,CAAC,SAAS,CAAC;QAC3C,CAAC,CAAC,IAAI,CAAC;IACT,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAC7D,CAAC;AAOD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAEjC;IACC,IACE,OAAO,KAAK,CAAC,kBAAkB,KAAK,QAAQ;QAC5C,KAAK,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EACnC,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;IACvE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AACxD,CAAC"}
|
package/package.json
CHANGED
package/skills/foleo/SKILL.md
CHANGED
|
@@ -197,6 +197,52 @@ Carry the opaque `etag` returned by `get`, `status`, delete, or
|
|
|
197
197
|
delete or purge returns `202`, poll `deletion-status` and describe the operation
|
|
198
198
|
as accepted/in progress until the server reports `complete`.
|
|
199
199
|
|
|
200
|
+
### Naming an HTML artifact
|
|
201
|
+
|
|
202
|
+
A hosted HTML artifact gets its own subdomain, and **`--name <label>` is
|
|
203
|
+
required** on every real HTML publish. The name is **permanent** — Foleo has no
|
|
204
|
+
rename, so changing the URL later means republishing under a new id and the old
|
|
205
|
+
link stops working. Choose it deliberately, with the human.
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
npx -y @foleo/cli name-check leadtube --json # free, no publish quota
|
|
209
|
+
npx -y @foleo/cli publish ./site --accept-hosting-risk --name leadtube --dry-run
|
|
210
|
+
npx -y @foleo/cli publish ./site --accept-hosting-risk --name leadtube
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Rules: 3-63 characters, `a-z`, `0-9` and hyphens, no leading, trailing, or
|
|
214
|
+
doubled hyphen. Invalid labels fail locally with `name_invalid` before any
|
|
215
|
+
network call. `name-check` exits 0 for `available`, 1 for `taken`/`reserved`/
|
|
216
|
+
`invalid`.
|
|
217
|
+
|
|
218
|
+
**Markdown never requires `--name`, and ignores it if passed** — it publishes under
|
|
219
|
+
the organization handle with a derived slug that can change safely. The
|
|
220
|
+
requirement follows the format inferred from the path, not the command.
|
|
221
|
+
|
|
222
|
+
Every artifact also keeps a permanent `a-<id>.foleo.site` address whether or not
|
|
223
|
+
a vanity name is claimed, so requiring a name costs no stable addressing.
|
|
224
|
+
|
|
225
|
+
`--dry-run` plans a publish without consuming any publish quota: it uploads
|
|
226
|
+
nothing and creates nothing. The plan reports the resolved `name` and its
|
|
227
|
+
availability, the final `url`, the `title` with the `resolvedFrom` source that
|
|
228
|
+
produced it, `visibility`, and a bundle manifest carrying `routes`,
|
|
229
|
+
`largestFiles`, and `skipped[]` — every dotfile, `node_modules` entry and
|
|
230
|
+
symlink left out, each with a reason — plus the quota the real run would spend.
|
|
231
|
+
Name, title and visibility come from the same resolver the real publish uses, so
|
|
232
|
+
the plan is not an approximation of the request; it is the request.
|
|
233
|
+
|
|
234
|
+
Exit 0 means local validation passed — read `plan.executable` to learn whether
|
|
235
|
+
the server currently admits it. A `taken` or `reserved` name is **not** returned
|
|
236
|
+
as a plan: it fails with `name_taken` / `name_reserved` in the failure object
|
|
237
|
+
above. Signed out, the plan degrades to `scope: "bundle-only"` with
|
|
238
|
+
`availability: "unknown"`; **never treat `unknown` as available.** Omitting
|
|
239
|
+
`--name` under `--dry-run` yields a _suggested_ label only — Foleo never
|
|
240
|
+
auto-claims a derived name.
|
|
241
|
+
|
|
242
|
+
`--dry-run` is HTML-only. On a Markdown publish or on `update` it refuses with
|
|
243
|
+
`dry_run_unsupported` rather than silently performing the real operation, so a
|
|
244
|
+
plan request can never mutate anything.
|
|
245
|
+
|
|
200
246
|
### Trusted active HTML alpha
|
|
201
247
|
|
|
202
248
|
HTML is executable content. Before any creation, a human must inspect and
|