@cabn/cli 0.1.0 → 0.2.1
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/README.md +7 -0
- package/dist/build.d.ts +12 -1
- package/dist/build.js +27 -4
- package/dist/cli.js +12 -2
- package/dist/help.js +7 -2
- package/dist/serve/server.d.ts +2 -0
- package/dist/serve/server.js +12 -2
- package/dist/shelf.d.ts +9 -0
- package/dist/shelf.js +26 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -19,6 +19,13 @@ cabn shelf <bundleDir...> [-o dir] # build a shelf.json listing several worlds
|
|
|
19
19
|
cabn serve <dir> [--allow-exec] [--owner] # convert in memory, serve as a walkable game on 127.0.0.1
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
`cabn build` also takes:
|
|
23
|
+
|
|
24
|
+
- `--name <name>`: the world's display name. It beats any `cabn.json` `world.title`. Without it, the title (the injected config's when `--config` is given) names the world, else the input's basename. It also names the default output dir and becomes `meta.source`, which never holds an absolute path.
|
|
25
|
+
- `--config <file>`: a `cabn.json` kept outside the source. The injected config owns the embed allowlist and the showcase: the repo's `allowedEmbedOrigins`, `world` and `sites` are not used (see `@cabn/converter`'s `ConvertOptions.config`). Its other keys merge over the repo's.
|
|
26
|
+
|
|
27
|
+
`cabn shelf --name <name>` names the shelf. `runBuild(input, { name, config })` and `runShelf(dirs, { name })` take the same options, and `config` may be a path or a parsed object. `cabn shelf` reads each bundle's `showcase.json` for the entry's description, links, hero url and sort order. `collectWorldEmbedOrigins(bundleDirs, { excludeOrigin })` returns the sorted union of every built world's `allowedEmbedOrigins`, which a host serving those worlds needs in its CSP `frame-src`. Build it from the built worlds, not the `cabn.json` inputs, because injection changes the list. It throws on any entry that isn't an exact https origin. The pure `collectEmbedOrigins` is re-exported too.
|
|
28
|
+
|
|
22
29
|
A git repository root also gets its recent history (branch universes, tags, GitHub releases, file history); `--no-history` skips it and `--git-dir <path>` reads another git directory. `--offline` skips every network request (the url-preview framing check and the GitHub releases request).
|
|
23
30
|
|
|
24
31
|
`cabn serve` binds to `127.0.0.1` only. `--allow-exec` turns on **real code execution** of whatever file you run with the wand tool — only use it on code you trust. `--owner` lets the page commit in-game edits and create/switch branches in the real repository (never push or fetch). See the [monorepo README](https://github.com/SebastianFrazier26/cabn#cabn-serve--running-a-file-for-real-locally-only) for the full safety model.
|
package/dist/build.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EmbedCheckNetwork, type ExternalFinding, type GitHistoryInput, type GithubFetch, type GithubNetwork } from "@cabn/converter";
|
|
2
|
-
import { type FindingsSummary } from "@cabn/world-schema";
|
|
2
|
+
import { type CabnConfigInput, type FindingsSummary } from "@cabn/world-schema";
|
|
3
3
|
export interface BuildSummary {
|
|
4
4
|
outDir: string;
|
|
5
5
|
clusters: number;
|
|
@@ -38,6 +38,15 @@ export interface HistorySummary {
|
|
|
38
38
|
}
|
|
39
39
|
export interface BuildOptions {
|
|
40
40
|
outDir?: string;
|
|
41
|
+
/** World display name (meta.name, and the default output dir's prefix). Beats any cabn.json `world.title`; without it the title, else the input's basename, names the world. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/**
|
|
44
|
+
* A cabn.json kept outside the source (`--config <path>`): either the
|
|
45
|
+
* path to that JSON file or the parsed object itself. Merged over the
|
|
46
|
+
* source's own cabn.json, the injected keys winning (see
|
|
47
|
+
* ConvertOptions.config).
|
|
48
|
+
*/
|
|
49
|
+
config?: string | CabnConfigInput;
|
|
41
50
|
/** Read secret-pattern files (.env, *.pem, id_rsa*, ...) normally instead of metadata-only. Default false. */
|
|
42
51
|
includeSecrets?: boolean;
|
|
43
52
|
/** ESLint JSON or SARIF results files to turn into monsters (`--findings`, repeatable). */
|
|
@@ -51,6 +60,8 @@ export interface BuildOptions {
|
|
|
51
60
|
/** Replaces the network fetch for GitHub releases — the demo's canned releases and tests use it; GITHUB_TOKEN is still only ever added by cliGithubNetwork. */
|
|
52
61
|
githubFetch?: GithubFetch;
|
|
53
62
|
}
|
|
63
|
+
/** Reads `--config`: unreadable, oversized or non-JSON input fails the build naming the file; shape is checked by convert() after the merge. */
|
|
64
|
+
export declare function loadConfigFile(path: string): Promise<CabnConfigInput>;
|
|
54
65
|
/**
|
|
55
66
|
* Reads and validates each results file at the boundary: unreadable,
|
|
56
67
|
* oversized, non-JSON, or schema-invalid input fails the build with the
|
package/dist/build.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import * as nodeFs from "node:fs";
|
|
2
2
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
4
|
-
import { convert, DirSource, FindingsValidationError, parseFindingsFile, ZipSource, } from "@cabn/converter";
|
|
4
|
+
import { CabnConfigError, convert, DirSource, FindingsValidationError, parseFindingsFile, ZipSource, } from "@cabn/converter";
|
|
5
5
|
import { EMBED_INDEX_FILENAME, GIT_META_FILENAME, MONSTER_INDEX_FILENAME, parseEmbedIndex, parseGitMeta, parseMonsterIndex, parseReleasesFile, RELEASES_FILENAME, } from "@cabn/world-schema";
|
|
6
|
+
// cabn.json itself is never close to this; anything larger is the wrong file.
|
|
7
|
+
const MAX_CONFIG_FILE_BYTES = 1024 * 1024;
|
|
8
|
+
/** Reads `--config`: unreadable, oversized or non-JSON input fails the build naming the file; shape is checked by convert() after the merge. */
|
|
9
|
+
export async function loadConfigFile(path) {
|
|
10
|
+
const raw = await readFile(resolve(path));
|
|
11
|
+
if (raw.byteLength > MAX_CONFIG_FILE_BYTES) {
|
|
12
|
+
throw new CabnConfigError(`--config ${path} is over ${MAX_CONFIG_FILE_BYTES} bytes`);
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(raw.toString("utf8"));
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
throw new CabnConfigError(`--config ${path} is not valid JSON: ${err.message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
// 50 MB: comfortably above a large monorepo's SARIF, well below anything that
|
|
7
22
|
// would make JSON.parse the slowest part of a build.
|
|
8
23
|
const MAX_FINDINGS_FILE_BYTES = 50 * 1024 * 1024;
|
|
@@ -128,10 +143,14 @@ export async function runBuild(inputPath, opts = {}) {
|
|
|
128
143
|
const start = performance.now();
|
|
129
144
|
const resolvedInput = resolve(inputPath);
|
|
130
145
|
const isZip = extname(resolvedInput).toLowerCase() === ".zip";
|
|
131
|
-
const
|
|
146
|
+
const inputName = isZip
|
|
132
147
|
? basename(resolvedInput, extname(resolvedInput))
|
|
133
148
|
: basename(resolvedInput);
|
|
149
|
+
const name = opts.name ?? inputName;
|
|
134
150
|
const outDir = resolve(opts.outDir ?? `./${name}-world`);
|
|
151
|
+
const config = typeof opts.config === "string"
|
|
152
|
+
? await loadConfigFile(opts.config)
|
|
153
|
+
: opts.config;
|
|
135
154
|
const source = isZip
|
|
136
155
|
? new ZipSource(await readFile(resolvedInput))
|
|
137
156
|
: new DirSource(resolvedInput);
|
|
@@ -140,8 +159,12 @@ export async function runBuild(inputPath, opts = {}) {
|
|
|
140
159
|
: undefined;
|
|
141
160
|
const warnings = [];
|
|
142
161
|
const bundle = await convert(source, {
|
|
143
|
-
name,
|
|
144
|
-
|
|
162
|
+
name: inputName,
|
|
163
|
+
...(opts.name !== undefined ? { nameOverride: opts.name } : {}),
|
|
164
|
+
// world.json is published; an absolute path would leak the builder's
|
|
165
|
+
// directory layout (home directory, user name) to every visitor.
|
|
166
|
+
source: name,
|
|
167
|
+
...(config ? { config } : {}),
|
|
145
168
|
includeSecrets: opts.includeSecrets,
|
|
146
169
|
findings,
|
|
147
170
|
// Tools report paths relative to (or absolute under) the directory they
|
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,8 @@ async function build(rest) {
|
|
|
15
15
|
offline: { type: "boolean" },
|
|
16
16
|
"no-history": { type: "boolean" },
|
|
17
17
|
"git-dir": { type: "string" },
|
|
18
|
+
name: { type: "string" },
|
|
19
|
+
config: { type: "string" },
|
|
18
20
|
},
|
|
19
21
|
allowPositionals: true,
|
|
20
22
|
});
|
|
@@ -25,6 +27,8 @@ async function build(rest) {
|
|
|
25
27
|
}
|
|
26
28
|
const summary = await runBuild(input, {
|
|
27
29
|
outDir: values.out,
|
|
30
|
+
name: values.name,
|
|
31
|
+
config: values.config,
|
|
28
32
|
includeSecrets: values["include-secrets"],
|
|
29
33
|
findingsPaths: values.findings,
|
|
30
34
|
offline: values.offline,
|
|
@@ -80,14 +84,20 @@ async function shelf(rest) {
|
|
|
80
84
|
try {
|
|
81
85
|
const { values, positionals } = parseArgs({
|
|
82
86
|
args: rest,
|
|
83
|
-
options: {
|
|
87
|
+
options: {
|
|
88
|
+
out: { type: "string", short: "o" },
|
|
89
|
+
name: { type: "string" },
|
|
90
|
+
},
|
|
84
91
|
allowPositionals: true,
|
|
85
92
|
});
|
|
86
93
|
if (positionals.length === 0) {
|
|
87
94
|
console.error("cabn shelf: missing <bundleDir...>");
|
|
88
95
|
return 1;
|
|
89
96
|
}
|
|
90
|
-
const summary = await runShelf(positionals, {
|
|
97
|
+
const summary = await runShelf(positionals, {
|
|
98
|
+
outDir: values.out,
|
|
99
|
+
name: values.name,
|
|
100
|
+
});
|
|
91
101
|
console.log(`Wrote shelf at ${summary.outDir} (${summary.worlds} worlds)`);
|
|
92
102
|
return 0;
|
|
93
103
|
}
|
package/dist/help.js
CHANGED
|
@@ -10,8 +10,12 @@ export function helpText() {
|
|
|
10
10
|
"Turn a directory or zipfile into an explorable cottagecore game world.",
|
|
11
11
|
"",
|
|
12
12
|
"Usage:",
|
|
13
|
-
" cabn build <dir|zipfile> [-o outDir] [--
|
|
13
|
+
" cabn build <dir|zipfile> [-o outDir] [--name name] [--config file] [--include-secrets] [--offline] [--findings file]...",
|
|
14
|
+
" [--no-history] [--git-dir path]",
|
|
14
15
|
" Convert a source into a world bundle",
|
|
16
|
+
" (--name sets the world's display name, beating any cabn.json world.title;",
|
|
17
|
+
" --config injects a cabn.json kept outside the source: it owns the embed allowlist",
|
|
18
|
+
" and the showcase (world, sites), and its other keys merge over the source's own)",
|
|
15
19
|
" (a git repository root also ships its recent git history, author emails included, and",
|
|
16
20
|
" GitHub releases; --no-history skips that, --git-dir reads another git directory,",
|
|
17
21
|
" the opt-in for a .git symlink or a worktree/submodule .git pointer file;",
|
|
@@ -20,7 +24,8 @@ export function helpText() {
|
|
|
20
24
|
" --offline skips the one-request-per-url check of whether url previews can be framed",
|
|
21
25
|
" and the GitHub releases request)",
|
|
22
26
|
" cabn inspect <bundleDir> Validate and summarize a world bundle",
|
|
23
|
-
" cabn shelf <bundleDir...> [-o outDir]
|
|
27
|
+
" cabn shelf <bundleDir...> [-o outDir] [--name name]",
|
|
28
|
+
" Build a shelf.json listing multiple converted worlds (--name: the shelf's name)",
|
|
24
29
|
" cabn serve <dir> [--port 5178] [--allow-exec] [--timeout ms] [--offline] [--owner] [--no-history] [--git-dir path]",
|
|
25
30
|
" Convert <dir> in memory and serve it as a walkable game, bound to",
|
|
26
31
|
" 127.0.0.1 only. --allow-exec enables REAL code execution of files",
|
package/dist/serve/server.d.ts
CHANGED
|
@@ -50,3 +50,5 @@ export declare function worldTextFromBundle(bundle: WorldBundle): Map<string, st
|
|
|
50
50
|
* this monorepo.
|
|
51
51
|
*/
|
|
52
52
|
export declare function startServe(dir: string, opts?: ServeOptions): Promise<ServeHandle>;
|
|
53
|
+
/** meta.source for a served world: stable per directory, never the path itself. */
|
|
54
|
+
export declare function serveSource(resolvedDir: string): string;
|
package/dist/serve/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomBytes } from "node:crypto";
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { createServer, } from "node:http";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
@@ -391,7 +391,12 @@ export async function startServe(dir, opts = {}) {
|
|
|
391
391
|
const token = randomBytes(32).toString("hex");
|
|
392
392
|
const convertWorld = () => convert(new DirSource(resolvedDir), {
|
|
393
393
|
name: basename(resolvedDir),
|
|
394
|
-
|
|
394
|
+
// Not the absolute path (convert() would cut it to the basename
|
|
395
|
+
// anyway): the basename plus a hash of the path, so two projects
|
|
396
|
+
// with the same folder name served on the same port keep separate
|
|
397
|
+
// in-browser universe stashes (keyed on meta.source), and a restart
|
|
398
|
+
// keeps the same key.
|
|
399
|
+
source: serveSource(resolvedDir),
|
|
395
400
|
embedNetwork: cliEmbedNetwork(opts.offline),
|
|
396
401
|
git: cliGitInput(resolvedDir, opts),
|
|
397
402
|
onWarning: (message) => console.warn(`cabn serve: ${message}`),
|
|
@@ -488,3 +493,8 @@ export async function startServe(dir, opts = {}) {
|
|
|
488
493
|
}),
|
|
489
494
|
};
|
|
490
495
|
}
|
|
496
|
+
/** meta.source for a served world: stable per directory, never the path itself. */
|
|
497
|
+
export function serveSource(resolvedDir) {
|
|
498
|
+
const hash = createHash("sha256").update(resolvedDir).digest("hex");
|
|
499
|
+
return `${basename(resolvedDir)}~${hash.slice(0, 8)}`;
|
|
500
|
+
}
|
package/dist/shelf.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CollectEmbedOriginsOptions, collectEmbedOrigins } from "@cabn/world-schema";
|
|
1
2
|
export interface ShelfSummary {
|
|
2
3
|
outDir: string;
|
|
3
4
|
worlds: number;
|
|
@@ -7,4 +8,12 @@ export interface ShelfOptions {
|
|
|
7
8
|
/** Shelf display name (meta.name). Defaults to "My Worlds". */
|
|
8
9
|
name?: string;
|
|
9
10
|
}
|
|
11
|
+
/** Re-exported so a host that only depends on @cabn/cli can union cabn.json configs too. */
|
|
12
|
+
export { collectEmbedOrigins };
|
|
13
|
+
/**
|
|
14
|
+
* Every origin any of these built worlds may embed (their world.json
|
|
15
|
+
* allowedEmbedOrigins, cabn.json sites included), sorted and deduplicated:
|
|
16
|
+
* the `frame-src` list for a host page serving them.
|
|
17
|
+
*/
|
|
18
|
+
export declare function collectWorldEmbedOrigins(bundleDirs: readonly string[], opts?: CollectEmbedOriginsOptions): Promise<string[]>;
|
|
10
19
|
export declare function runShelf(bundleDirs: string[], opts?: ShelfOptions): Promise<ShelfSummary>;
|
package/dist/shelf.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { buildShelf } from "@cabn/converter";
|
|
4
|
-
import { validateManifest } from "@cabn/world-schema";
|
|
4
|
+
import { collectEmbedOrigins, EMPTY_SHOWCASE, parseShowcase, SHOWCASE_FILENAME, validateManifest, } from "@cabn/world-schema";
|
|
5
5
|
// Windows path separators would otherwise leak into a URL the browser has to
|
|
6
6
|
// fetch relative to shelf.json's own location.
|
|
7
7
|
function toUrlPath(path) {
|
|
8
8
|
return sep === "/" ? path : path.split(sep).join("/");
|
|
9
9
|
}
|
|
10
|
+
/** A bundle from before showcase.json (or with an unreadable one) is a world with no showcase info, never a failed shelf. */
|
|
11
|
+
async function readShowcase(bundleDir) {
|
|
12
|
+
try {
|
|
13
|
+
return parseShowcase(JSON.parse(await readFile(join(bundleDir, SHOWCASE_FILENAME), "utf8")));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return EMPTY_SHOWCASE;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Re-exported so a host that only depends on @cabn/cli can union cabn.json configs too. */
|
|
20
|
+
export { collectEmbedOrigins };
|
|
21
|
+
async function readManifest(bundleDir) {
|
|
22
|
+
const raw = await readFile(join(resolve(bundleDir), "world.json"), "utf8");
|
|
23
|
+
return validateManifest(JSON.parse(raw));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every origin any of these built worlds may embed (their world.json
|
|
27
|
+
* allowedEmbedOrigins, cabn.json sites included), sorted and deduplicated:
|
|
28
|
+
* the `frame-src` list for a host page serving them.
|
|
29
|
+
*/
|
|
30
|
+
export async function collectWorldEmbedOrigins(bundleDirs, opts = {}) {
|
|
31
|
+
return collectEmbedOrigins(await Promise.all(bundleDirs.map(readManifest)), opts);
|
|
32
|
+
}
|
|
10
33
|
export async function runShelf(bundleDirs, opts = {}) {
|
|
11
34
|
const outDir = resolve(opts.outDir ?? "./shelf");
|
|
12
35
|
await mkdir(outDir, { recursive: true });
|
|
@@ -15,7 +38,8 @@ export async function runShelf(bundleDirs, opts = {}) {
|
|
|
15
38
|
const raw = await readFile(join(resolvedBundleDir, "world.json"), "utf8");
|
|
16
39
|
const manifest = validateManifest(JSON.parse(raw));
|
|
17
40
|
const worldUrl = `${toUrlPath(relative(outDir, resolvedBundleDir))}/world.json`;
|
|
18
|
-
|
|
41
|
+
const showcase = await readShowcase(resolvedBundleDir);
|
|
42
|
+
return { name: manifest.meta.name, worldUrl, manifest, showcase };
|
|
19
43
|
}));
|
|
20
44
|
const shelf = buildShelf(worlds, { name: opts.name });
|
|
21
45
|
await writeFile(join(outDir, "shelf.json"), `${JSON.stringify(shelf, null, 2)}\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cabn/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The cabn CLI: build/inspect a world bundle, build a shelf of worlds, and cabn serve for a local walkable game with optional real code execution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cabn",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"LICENSE"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cabn/converter": "0.
|
|
36
|
-
"@cabn/engine": "0.
|
|
37
|
-
"@cabn/world-schema": "0.
|
|
35
|
+
"@cabn/converter": "0.3.0",
|
|
36
|
+
"@cabn/engine": "0.3.0",
|
|
37
|
+
"@cabn/world-schema": "0.2.0",
|
|
38
38
|
"esbuild": "^0.27.0",
|
|
39
39
|
"isomorphic-git": "1.42.2",
|
|
40
40
|
"react": "^19.3.0",
|
|
41
41
|
"react-dom": "^19.3.0",
|
|
42
|
-
"zod": "^4.6.
|
|
42
|
+
"zod": "^4.6.7"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@cabn/shadow-art": "^0.1
|
|
45
|
+
"@cabn/shadow-art": "^0.2.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@cabn/shadow-art": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@cabn/shadow-art": "0.1
|
|
53
|
+
"@cabn/shadow-art": "0.2.1",
|
|
54
54
|
"@types/node": "^22.20.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|