@cabn/cli 0.1.0

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.
Files changed (222) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/dist/assets/originals/cabin_256.webp +0 -0
  4. package/dist/assets/originals/cabinet_256.webp +0 -0
  5. package/dist/assets/originals/file_256.webp +0 -0
  6. package/dist/assets/originals/key_256.webp +0 -0
  7. package/dist/assets/originals/letter_opener_256.webp +0 -0
  8. package/dist/assets/placeholders/bonfire_frame0_soft.png +0 -0
  9. package/dist/assets/placeholders/bonfire_frame1_soft.png +0 -0
  10. package/dist/assets/placeholders/bonfire_frame2_soft.png +0 -0
  11. package/dist/assets/placeholders/bonfire_frame3_soft.png +0 -0
  12. package/dist/assets/placeholders/bramble_defeat0_soft.png +0 -0
  13. package/dist/assets/placeholders/bramble_defeat1_soft.png +0 -0
  14. package/dist/assets/placeholders/bramble_defeat2_soft.png +0 -0
  15. package/dist/assets/placeholders/bramble_hit_soft.png +0 -0
  16. package/dist/assets/placeholders/bramble_idle0_soft.png +0 -0
  17. package/dist/assets/placeholders/bramble_idle1_soft.png +0 -0
  18. package/dist/assets/placeholders/character_idle_back_soft.png +0 -0
  19. package/dist/assets/placeholders/character_idle_soft.png +0 -0
  20. package/dist/assets/placeholders/decals_soft.png +0 -0
  21. package/dist/assets/placeholders/fx_spark.png +0 -0
  22. package/dist/assets/placeholders/ghost_defeat0_soft.png +0 -0
  23. package/dist/assets/placeholders/ghost_defeat1_soft.png +0 -0
  24. package/dist/assets/placeholders/ghost_defeat2_soft.png +0 -0
  25. package/dist/assets/placeholders/ghost_hit_soft.png +0 -0
  26. package/dist/assets/placeholders/ghost_soft.png +0 -0
  27. package/dist/assets/placeholders/glade_tiles_soft.png +0 -0
  28. package/dist/assets/placeholders/gremlin_defeat0_soft.png +0 -0
  29. package/dist/assets/placeholders/gremlin_defeat1_soft.png +0 -0
  30. package/dist/assets/placeholders/gremlin_defeat2_soft.png +0 -0
  31. package/dist/assets/placeholders/gremlin_hit_soft.png +0 -0
  32. package/dist/assets/placeholders/gremlin_idle0_soft.png +0 -0
  33. package/dist/assets/placeholders/gremlin_idle1_soft.png +0 -0
  34. package/dist/assets/placeholders/grove_tiles_soft.png +0 -0
  35. package/dist/assets/placeholders/imp_defeat0_soft.png +0 -0
  36. package/dist/assets/placeholders/imp_defeat1_soft.png +0 -0
  37. package/dist/assets/placeholders/imp_defeat2_soft.png +0 -0
  38. package/dist/assets/placeholders/imp_hit_soft.png +0 -0
  39. package/dist/assets/placeholders/imp_idle0_soft.png +0 -0
  40. package/dist/assets/placeholders/imp_idle1_soft.png +0 -0
  41. package/dist/assets/placeholders/magpie_defeat0_soft.png +0 -0
  42. package/dist/assets/placeholders/magpie_defeat1_soft.png +0 -0
  43. package/dist/assets/placeholders/magpie_defeat2_soft.png +0 -0
  44. package/dist/assets/placeholders/magpie_hit_soft.png +0 -0
  45. package/dist/assets/placeholders/magpie_idle0_soft.png +0 -0
  46. package/dist/assets/placeholders/magpie_idle1_soft.png +0 -0
  47. package/dist/assets/placeholders/meadow_tiles_soft.png +0 -0
  48. package/dist/assets/placeholders/npc_guide_bubble_soft.png +0 -0
  49. package/dist/assets/placeholders/npc_guide_portrait_soft.png +0 -0
  50. package/dist/assets/placeholders/npc_guide_strip_soft.png +0 -0
  51. package/dist/assets/placeholders/ouroboros_defeat0_soft.png +0 -0
  52. package/dist/assets/placeholders/ouroboros_defeat1_soft.png +0 -0
  53. package/dist/assets/placeholders/ouroboros_defeat2_soft.png +0 -0
  54. package/dist/assets/placeholders/ouroboros_hit_soft.png +0 -0
  55. package/dist/assets/placeholders/ouroboros_idle0_soft.png +0 -0
  56. package/dist/assets/placeholders/ouroboros_idle1_soft.png +0 -0
  57. package/dist/assets/placeholders/path_bed_disc_soft.png +0 -0
  58. package/dist/assets/placeholders/path_cobble_0_soft.png +0 -0
  59. package/dist/assets/placeholders/path_cobble_1_soft.png +0 -0
  60. package/dist/assets/placeholders/path_cobble_2_soft.png +0 -0
  61. package/dist/assets/placeholders/path_cobble_3_soft.png +0 -0
  62. package/dist/assets/placeholders/path_edge_disc_soft.png +0 -0
  63. package/dist/assets/placeholders/path_stamp_0_soft.png +0 -0
  64. package/dist/assets/placeholders/path_stamp_1_soft.png +0 -0
  65. package/dist/assets/placeholders/path_stamp_2_soft.png +0 -0
  66. package/dist/assets/placeholders/pet_bird_portrait_soft.png +0 -0
  67. package/dist/assets/placeholders/pet_bird_strip_soft.png +0 -0
  68. package/dist/assets/placeholders/pet_cat_portrait_soft.png +0 -0
  69. package/dist/assets/placeholders/pet_cat_strip_soft.png +0 -0
  70. package/dist/assets/placeholders/pet_ferret_portrait_soft.png +0 -0
  71. package/dist/assets/placeholders/pet_ferret_strip_soft.png +0 -0
  72. package/dist/assets/placeholders/pet_llama_portrait_soft.png +0 -0
  73. package/dist/assets/placeholders/pet_llama_strip_soft.png +0 -0
  74. package/dist/assets/placeholders/pet_owl_portrait_soft.png +0 -0
  75. package/dist/assets/placeholders/pet_owl_strip_soft.png +0 -0
  76. package/dist/assets/placeholders/pet_whale_portrait_soft.png +0 -0
  77. package/dist/assets/placeholders/pet_whale_strip_soft.png +0 -0
  78. package/dist/assets/placeholders/portal_arch_soft.png +0 -0
  79. package/dist/assets/placeholders/portal_arch_strip_soft.png +0 -0
  80. package/dist/assets/placeholders/portal_arch_variants_soft.png +0 -0
  81. package/dist/assets/placeholders/prop_bench_soft.png +0 -0
  82. package/dist/assets/placeholders/prop_bush_soft.png +0 -0
  83. package/dist/assets/placeholders/prop_castle_keep_soft.png +0 -0
  84. package/dist/assets/placeholders/prop_cottage_soft.png +0 -0
  85. package/dist/assets/placeholders/prop_fence_soft.png +0 -0
  86. package/dist/assets/placeholders/prop_flower_bed_soft.png +0 -0
  87. package/dist/assets/placeholders/prop_flower_pot_soft.png +0 -0
  88. package/dist/assets/placeholders/prop_hedge_soft.png +0 -0
  89. package/dist/assets/placeholders/prop_lamp_post_soft.png +0 -0
  90. package/dist/assets/placeholders/prop_seyn_sign_soft.png +0 -0
  91. package/dist/assets/placeholders/prop_shelf_cabin_soft.png +0 -0
  92. package/dist/assets/placeholders/prop_signpost_soft.png +0 -0
  93. package/dist/assets/placeholders/prop_stone_wall_soft.png +0 -0
  94. package/dist/assets/placeholders/prop_tree_large_soft.png +0 -0
  95. package/dist/assets/placeholders/prop_tree_small_soft.png +0 -0
  96. package/dist/assets/placeholders/prop_well_soft.png +0 -0
  97. package/dist/assets/placeholders/prop_world_fountain_gem_soft.png +0 -0
  98. package/dist/assets/placeholders/prop_world_fountain_strip_soft.png +0 -0
  99. package/dist/assets/placeholders/rot_sprite_defeat0_soft.png +0 -0
  100. package/dist/assets/placeholders/rot_sprite_defeat1_soft.png +0 -0
  101. package/dist/assets/placeholders/rot_sprite_defeat2_soft.png +0 -0
  102. package/dist/assets/placeholders/rot_sprite_hit_soft.png +0 -0
  103. package/dist/assets/placeholders/rot_sprite_idle0_soft.png +0 -0
  104. package/dist/assets/placeholders/rot_sprite_idle1_soft.png +0 -0
  105. package/dist/assets/placeholders/scenery_berry_shrub_soft.png +0 -0
  106. package/dist/assets/placeholders/scenery_blossom_oak_soft.png +0 -0
  107. package/dist/assets/placeholders/scenery_boulder_soft.png +0 -0
  108. package/dist/assets/placeholders/scenery_fallen_log_soft.png +0 -0
  109. package/dist/assets/placeholders/scenery_flower_patch_soft.png +0 -0
  110. package/dist/assets/placeholders/scenery_mushroom_soft.png +0 -0
  111. package/dist/assets/placeholders/scenery_oak_soft.png +0 -0
  112. package/dist/assets/placeholders/scenery_pine_soft.png +0 -0
  113. package/dist/assets/placeholders/scenery_pond_soft.png +0 -0
  114. package/dist/assets/placeholders/scenery_reeds_soft.png +0 -0
  115. package/dist/assets/placeholders/scenery_rock_small_soft.png +0 -0
  116. package/dist/assets/placeholders/scenery_ruin_soft.png +0 -0
  117. package/dist/assets/placeholders/scenery_shrub_soft.png +0 -0
  118. package/dist/assets/placeholders/scenery_stump_soft.png +0 -0
  119. package/dist/assets/placeholders/scenery_waymarker_soft.png +0 -0
  120. package/dist/assets/placeholders/scenery_windmill_sails_soft.png +0 -0
  121. package/dist/assets/placeholders/scenery_windmill_soft.png +0 -0
  122. package/dist/assets/placeholders/shade_defeat0_soft.png +0 -0
  123. package/dist/assets/placeholders/shade_defeat1_soft.png +0 -0
  124. package/dist/assets/placeholders/shade_defeat2_soft.png +0 -0
  125. package/dist/assets/placeholders/shade_hit_soft.png +0 -0
  126. package/dist/assets/placeholders/shade_idle0_soft.png +0 -0
  127. package/dist/assets/placeholders/shade_idle1_soft.png +0 -0
  128. package/dist/assets/placeholders/skeleton_defeat0_soft.png +0 -0
  129. package/dist/assets/placeholders/skeleton_defeat1_soft.png +0 -0
  130. package/dist/assets/placeholders/skeleton_defeat2_soft.png +0 -0
  131. package/dist/assets/placeholders/skeleton_hit_soft.png +0 -0
  132. package/dist/assets/placeholders/skeleton_idle0_soft.png +0 -0
  133. package/dist/assets/placeholders/skeleton_idle1_soft.png +0 -0
  134. package/dist/assets/placeholders/sky_day.png +0 -0
  135. package/dist/assets/placeholders/sky_moon_soft.png +0 -0
  136. package/dist/assets/placeholders/sky_night.png +0 -0
  137. package/dist/assets/placeholders/sky_star_soft.png +0 -0
  138. package/dist/assets/placeholders/skyline_castle_day_soft.png +0 -0
  139. package/dist/assets/placeholders/skyline_castle_night_soft.png +0 -0
  140. package/dist/assets/placeholders/skyline_hill_day_soft.png +0 -0
  141. package/dist/assets/placeholders/skyline_hill_night_soft.png +0 -0
  142. package/dist/assets/placeholders/skyline_treeline_day_soft.png +0 -0
  143. package/dist/assets/placeholders/skyline_treeline_night_soft.png +0 -0
  144. package/dist/assets/placeholders/skyline_village_day_soft.png +0 -0
  145. package/dist/assets/placeholders/skyline_village_night_soft.png +0 -0
  146. package/dist/assets/placeholders/skyline_watchtower_day_soft.png +0 -0
  147. package/dist/assets/placeholders/skyline_watchtower_night_soft.png +0 -0
  148. package/dist/assets/placeholders/ui_icon_bag_soft.png +0 -0
  149. package/dist/assets/placeholders/ui_icon_key_soft.png +0 -0
  150. package/dist/assets/placeholders/ui_icon_orb_soft.png +0 -0
  151. package/dist/assets/placeholders/ui_icon_owner_soft.png +0 -0
  152. package/dist/assets/placeholders/ui_icon_quill_soft.png +0 -0
  153. package/dist/assets/placeholders/ui_icon_sign_soft.png +0 -0
  154. package/dist/assets/placeholders/ui_icon_spyglass_soft.png +0 -0
  155. package/dist/assets/placeholders/ui_icon_wand_soft.png +0 -0
  156. package/dist/assets/placeholders/ui_screen_orb_soft.png +0 -0
  157. package/dist/assets/placeholders/ui_screen_satchel_flap_soft.png +0 -0
  158. package/dist/assets/placeholders/ui_screen_satchel_soft.png +0 -0
  159. package/dist/assets/placeholders/ui_screen_spyglass_soft.png +0 -0
  160. package/dist/assets/placeholders/ui_sparkle_cyan@8x.png +0 -0
  161. package/dist/assets/placeholders/ui_sparkle_gold@8x.png +0 -0
  162. package/dist/assets/placeholders/ui_sparkle_violet@8x.png +0 -0
  163. package/dist/assets/placeholders/ui_tool_comment_soft.png +0 -0
  164. package/dist/assets/placeholders/ui_tool_find_soft.png +0 -0
  165. package/dist/assets/placeholders/ui_tool_fold_soft.png +0 -0
  166. package/dist/assets/placeholders/ui_tool_format_soft.png +0 -0
  167. package/dist/assets/placeholders/ui_tool_goto_soft.png +0 -0
  168. package/dist/assets/placeholders/ui_tool_rename_soft.png +0 -0
  169. package/dist/assets/placeholders/ui_tool_replace_soft.png +0 -0
  170. package/dist/assets/placeholders/ui_tool_save_soft.png +0 -0
  171. package/dist/assets/placeholders/ui_tool_symbol_soft.png +0 -0
  172. package/dist/assets/placeholders/ui_tool_unfold_soft.png +0 -0
  173. package/dist/assets/placeholders/warded_mimic_defeat0_soft.png +0 -0
  174. package/dist/assets/placeholders/warded_mimic_defeat1_soft.png +0 -0
  175. package/dist/assets/placeholders/warded_mimic_defeat2_soft.png +0 -0
  176. package/dist/assets/placeholders/warded_mimic_hit_soft.png +0 -0
  177. package/dist/assets/placeholders/warded_mimic_idle0_soft.png +0 -0
  178. package/dist/assets/placeholders/warded_mimic_idle1_soft.png +0 -0
  179. package/dist/assets/placeholders/will_o_wisp_defeat0_soft.png +0 -0
  180. package/dist/assets/placeholders/will_o_wisp_defeat1_soft.png +0 -0
  181. package/dist/assets/placeholders/will_o_wisp_defeat2_soft.png +0 -0
  182. package/dist/assets/placeholders/will_o_wisp_hit_soft.png +0 -0
  183. package/dist/assets/placeholders/will_o_wisp_idle0_soft.png +0 -0
  184. package/dist/assets/placeholders/will_o_wisp_idle1_soft.png +0 -0
  185. package/dist/assets/placeholders/wizard_tower_soft.png +0 -0
  186. package/dist/build.d.ts +84 -0
  187. package/dist/build.js +185 -0
  188. package/dist/cli.d.ts +1 -0
  189. package/dist/cli.js +163 -0
  190. package/dist/help.d.ts +2 -0
  191. package/dist/help.js +35 -0
  192. package/dist/index.d.ts +6 -0
  193. package/dist/index.js +6 -0
  194. package/dist/inspect.d.ts +3 -0
  195. package/dist/inspect.js +35 -0
  196. package/dist/main.d.ts +2 -0
  197. package/dist/main.js +3 -0
  198. package/dist/serve/execRunner.d.ts +43 -0
  199. package/dist/serve/execRunner.js +113 -0
  200. package/dist/serve/hostPage.d.ts +15 -0
  201. package/dist/serve/hostPage.js +100 -0
  202. package/dist/serve/ownerAuth.d.ts +80 -0
  203. package/dist/serve/ownerAuth.js +241 -0
  204. package/dist/serve/ownerGit.d.ts +40 -0
  205. package/dist/serve/ownerGit.js +265 -0
  206. package/dist/serve/ownerShadow.d.ts +52 -0
  207. package/dist/serve/ownerShadow.js +250 -0
  208. package/dist/serve/ownerSigns.d.ts +30 -0
  209. package/dist/serve/ownerSigns.js +224 -0
  210. package/dist/serve/pyTracer.d.ts +33 -0
  211. package/dist/serve/pyTracer.js +76 -0
  212. package/dist/serve/runtime.d.ts +8 -0
  213. package/dist/serve/runtime.js +35 -0
  214. package/dist/serve/security.d.ts +47 -0
  215. package/dist/serve/security.js +106 -0
  216. package/dist/serve/server.d.ts +52 -0
  217. package/dist/serve/server.js +490 -0
  218. package/dist/serve/shadowArt.d.ts +10 -0
  219. package/dist/serve/shadowArt.js +29 -0
  220. package/dist/shelf.d.ts +10 -0
  221. package/dist/shelf.js +23 -0
  222. package/package.json +60 -0
@@ -0,0 +1,84 @@
1
+ import { type EmbedCheckNetwork, type ExternalFinding, type GitHistoryInput, type GithubFetch, type GithubNetwork } from "@cabn/converter";
2
+ import { type FindingsSummary } from "@cabn/world-schema";
3
+ export interface BuildSummary {
4
+ outDir: string;
5
+ clusters: number;
6
+ portals: number;
7
+ bytes: number;
8
+ elapsedMs: number;
9
+ truncated: boolean;
10
+ skippedFiles: number;
11
+ /** world.json monsters plus monsters.json monsters. */
12
+ monsters: number;
13
+ /** Present only when --findings files were given. */
14
+ findings?: FindingsSummary;
15
+ /** Url previews whose site refuses to be framed (build-time check); empty when offline. */
16
+ embedBlocked: {
17
+ portalId: string;
18
+ url: string;
19
+ detail?: string;
20
+ }[];
21
+ embedCheck: "network" | "offline";
22
+ /** Present when the source was a git repository root and history was written. */
23
+ history?: HistorySummary;
24
+ /** Non-fatal notes from the converter (e.g. why history was skipped). */
25
+ warnings: string[];
26
+ }
27
+ export interface HistorySummary {
28
+ /** Commits in the shipped pack (all branches, deduplicated by the pack itself). */
29
+ packBytes: number;
30
+ objects: number;
31
+ branches: number;
32
+ tags: number;
33
+ commitsPerBranch: number;
34
+ halvings: number;
35
+ notShipped: number;
36
+ releases: string;
37
+ releaseCount: number;
38
+ }
39
+ export interface BuildOptions {
40
+ outDir?: string;
41
+ /** Read secret-pattern files (.env, *.pem, id_rsa*, ...) normally instead of metadata-only. Default false. */
42
+ includeSecrets?: boolean;
43
+ /** ESLint JSON or SARIF results files to turn into monsters (`--findings`, repeatable). */
44
+ findingsPaths?: string[];
45
+ /** Skip the build-time framability check for url previews and the GitHub releases request (no network requests at all). */
46
+ offline?: boolean;
47
+ /** false: no `git/` pack directory or releases.json even for a repository root, and no releases request (`--no-history`). */
48
+ history?: boolean;
49
+ /** Read history from this git directory instead of `<dir>/.git` (`--git-dir`). */
50
+ gitDir?: string;
51
+ /** 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
+ githubFetch?: GithubFetch;
53
+ }
54
+ /**
55
+ * Reads and validates each results file at the boundary: unreadable,
56
+ * oversized, non-JSON, or schema-invalid input fails the build with the
57
+ * file's name rather than silently producing a world without its monsters.
58
+ */
59
+ export declare function loadFindings(paths: readonly string[]): Promise<ExternalFinding[]>;
60
+ /**
61
+ * The CLI's opt-in to convert()'s network check: Node's own fetch, cast to
62
+ * the structural shape the converter asks for. Only the CLI (a user running
63
+ * cabn on their own project) does this — never apps/backend.
64
+ */
65
+ export declare function cliEmbedNetwork(offline: boolean | undefined): EmbedCheckNetwork | undefined;
66
+ /**
67
+ * The CLI's opt-in to the build-time GitHub releases request: Node's fetch,
68
+ * plus `Authorization: Bearer $GITHUB_TOKEN` when that env var is set. The
69
+ * token lives only in this closure's request headers — convert() never sees
70
+ * it, and nothing it returns is written into the bundle except the
71
+ * zod-filtered release fields.
72
+ */
73
+ export declare function cliGithubNetwork(offline: boolean | undefined, override?: GithubFetch): GithubNetwork | undefined;
74
+ /** The `git` option for convert(): only for a directory source, never a zip. */
75
+ export declare function cliGitInput(dir: string, opts: Pick<BuildOptions, "history" | "gitDir" | "offline" | "githubFetch">): (GitHistoryInput & {
76
+ github?: GithubNetwork;
77
+ }) | undefined;
78
+ export declare function historySummary(bundle: Map<string, Uint8Array | string>): HistorySummary | undefined;
79
+ /** Pulls blocked url previews out of a bundle's embeds.json for the CLI's summary line. */
80
+ export declare function embedSummary(bundle: Map<string, Uint8Array | string>): {
81
+ mode: "network" | "offline";
82
+ blocked: BuildSummary["embedBlocked"];
83
+ };
84
+ export declare function runBuild(inputPath: string, opts?: BuildOptions): Promise<BuildSummary>;
package/dist/build.js ADDED
@@ -0,0 +1,185 @@
1
+ import * as nodeFs from "node:fs";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { basename, dirname, extname, join, resolve } from "node:path";
4
+ import { convert, DirSource, FindingsValidationError, parseFindingsFile, ZipSource, } from "@cabn/converter";
5
+ import { EMBED_INDEX_FILENAME, GIT_META_FILENAME, MONSTER_INDEX_FILENAME, parseEmbedIndex, parseGitMeta, parseMonsterIndex, parseReleasesFile, RELEASES_FILENAME, } from "@cabn/world-schema";
6
+ // 50 MB: comfortably above a large monorepo's SARIF, well below anything that
7
+ // would make JSON.parse the slowest part of a build.
8
+ const MAX_FINDINGS_FILE_BYTES = 50 * 1024 * 1024;
9
+ /**
10
+ * Reads and validates each results file at the boundary: unreadable,
11
+ * oversized, non-JSON, or schema-invalid input fails the build with the
12
+ * file's name rather than silently producing a world without its monsters.
13
+ */
14
+ export async function loadFindings(paths) {
15
+ const all = [];
16
+ for (const path of paths) {
17
+ const raw = await readFile(resolve(path));
18
+ if (raw.byteLength > MAX_FINDINGS_FILE_BYTES) {
19
+ throw new Error(`findings file ${path} is over ${MAX_FINDINGS_FILE_BYTES} bytes`);
20
+ }
21
+ let json;
22
+ try {
23
+ json = JSON.parse(raw.toString("utf8"));
24
+ }
25
+ catch (err) {
26
+ throw new Error(`findings file ${path} is not valid JSON: ${err.message}`);
27
+ }
28
+ try {
29
+ all.push(...parseFindingsFile(json));
30
+ }
31
+ catch (err) {
32
+ if (err instanceof FindingsValidationError) {
33
+ throw new Error(`findings file ${path}: ${err.message}`);
34
+ }
35
+ throw err;
36
+ }
37
+ }
38
+ return all;
39
+ }
40
+ /**
41
+ * The CLI's opt-in to convert()'s network check: Node's own fetch, cast to
42
+ * the structural shape the converter asks for. Only the CLI (a user running
43
+ * cabn on their own project) does this — never apps/backend.
44
+ */
45
+ export function cliEmbedNetwork(offline) {
46
+ if (offline)
47
+ return undefined;
48
+ return { fetch: globalThis.fetch };
49
+ }
50
+ /**
51
+ * The CLI's opt-in to the build-time GitHub releases request: Node's fetch,
52
+ * plus `Authorization: Bearer $GITHUB_TOKEN` when that env var is set. The
53
+ * token lives only in this closure's request headers — convert() never sees
54
+ * it, and nothing it returns is written into the bundle except the
55
+ * zod-filtered release fields.
56
+ */
57
+ export function cliGithubNetwork(offline, override) {
58
+ if (offline)
59
+ return undefined;
60
+ if (override)
61
+ return { fetch: override };
62
+ const token = process.env.GITHUB_TOKEN?.trim();
63
+ const fetch = async (url, init) => {
64
+ const headers = { ...init.headers };
65
+ if (token)
66
+ headers.authorization = `Bearer ${token}`;
67
+ const res = await globalThis.fetch(url, {
68
+ headers,
69
+ signal: init.signal,
70
+ redirect: "error",
71
+ });
72
+ return res;
73
+ };
74
+ return { fetch, authenticated: Boolean(token) };
75
+ }
76
+ /** The `git` option for convert(): only for a directory source, never a zip. */
77
+ export function cliGitInput(dir, opts) {
78
+ if (opts.history === false)
79
+ return undefined;
80
+ return {
81
+ fs: nodeFs,
82
+ dir,
83
+ ...(opts.gitDir ? { gitdir: resolve(opts.gitDir) } : {}),
84
+ github: cliGithubNetwork(opts.offline, opts.githubFetch),
85
+ };
86
+ }
87
+ export function historySummary(bundle) {
88
+ const raw = bundle.get(GIT_META_FILENAME);
89
+ if (typeof raw !== "string")
90
+ return undefined;
91
+ const meta = parseGitMeta(JSON.parse(raw));
92
+ if (!meta)
93
+ return undefined;
94
+ const rawReleases = bundle.get(RELEASES_FILENAME);
95
+ const releases = typeof rawReleases === "string"
96
+ ? parseReleasesFile(JSON.parse(rawReleases))
97
+ : null;
98
+ return {
99
+ packBytes: meta.pack.bytes,
100
+ objects: meta.pack.objects,
101
+ branches: meta.branches.length,
102
+ tags: meta.tags.length,
103
+ commitsPerBranch: meta.pack.commitsPerBranch,
104
+ halvings: meta.pack.halvings,
105
+ notShipped: Object.keys(meta.omitted).length,
106
+ releases: releases?.source ?? "none",
107
+ releaseCount: releases?.items.length ?? 0,
108
+ };
109
+ }
110
+ /** Pulls blocked url previews out of a bundle's embeds.json for the CLI's summary line. */
111
+ export function embedSummary(bundle) {
112
+ const raw = bundle.get(EMBED_INDEX_FILENAME);
113
+ if (typeof raw !== "string")
114
+ return { mode: "offline", blocked: [] };
115
+ const json = JSON.parse(raw);
116
+ const blocked = [];
117
+ for (const [portalId, v] of parseEmbedIndex(json)) {
118
+ if (!v.framable)
119
+ blocked.push({
120
+ portalId,
121
+ url: v.url,
122
+ ...(v.detail !== undefined ? { detail: v.detail } : {}),
123
+ });
124
+ }
125
+ return { mode: json.mode === "network" ? "network" : "offline", blocked };
126
+ }
127
+ export async function runBuild(inputPath, opts = {}) {
128
+ const start = performance.now();
129
+ const resolvedInput = resolve(inputPath);
130
+ const isZip = extname(resolvedInput).toLowerCase() === ".zip";
131
+ const name = isZip
132
+ ? basename(resolvedInput, extname(resolvedInput))
133
+ : basename(resolvedInput);
134
+ const outDir = resolve(opts.outDir ?? `./${name}-world`);
135
+ const source = isZip
136
+ ? new ZipSource(await readFile(resolvedInput))
137
+ : new DirSource(resolvedInput);
138
+ const findings = opts.findingsPaths?.length
139
+ ? await loadFindings(opts.findingsPaths)
140
+ : undefined;
141
+ const warnings = [];
142
+ const bundle = await convert(source, {
143
+ name,
144
+ source: resolvedInput,
145
+ includeSecrets: opts.includeSecrets,
146
+ findings,
147
+ // Tools report paths relative to (or absolute under) the directory they
148
+ // ran in, which for `cabn build <dir>` is that dir.
149
+ findingsRoot: isZip ? undefined : resolvedInput,
150
+ embedNetwork: cliEmbedNetwork(opts.offline),
151
+ git: isZip ? undefined : cliGitInput(resolvedInput, opts),
152
+ onWarning: (message) => warnings.push(message),
153
+ });
154
+ for (const [relPath, content] of bundle) {
155
+ const dest = join(outDir, relPath);
156
+ await mkdir(dirname(dest), { recursive: true });
157
+ await writeFile(dest, content);
158
+ }
159
+ const manifestRaw = bundle.get("world.json");
160
+ if (typeof manifestRaw !== "string") {
161
+ throw new Error("convert() did not produce a world.json entry");
162
+ }
163
+ const manifest = JSON.parse(manifestRaw);
164
+ const indexRaw = bundle.get(MONSTER_INDEX_FILENAME);
165
+ const indexJson = typeof indexRaw === "string" ? JSON.parse(indexRaw) : undefined;
166
+ const extraMonsters = parseMonsterIndex(indexJson).length;
167
+ const findingsSummary = indexJson?.findings;
168
+ const embeds = embedSummary(bundle);
169
+ const history = historySummary(bundle);
170
+ return {
171
+ outDir,
172
+ clusters: manifest.clusters.length,
173
+ portals: manifest.portals.length,
174
+ bytes: manifest.meta.totalBytes,
175
+ elapsedMs: Math.round(performance.now() - start),
176
+ truncated: manifest.meta.truncated,
177
+ skippedFiles: manifest.meta.skippedFiles,
178
+ monsters: manifest.monsters.length + extraMonsters,
179
+ ...(findingsSummary ? { findings: findingsSummary } : {}),
180
+ embedBlocked: embeds.blocked,
181
+ embedCheck: embeds.mode,
182
+ ...(history ? { history } : {}),
183
+ warnings,
184
+ };
185
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function run(argv: string[]): Promise<number>;
package/dist/cli.js ADDED
@@ -0,0 +1,163 @@
1
+ import { parseArgs } from "node:util";
2
+ import { runBuild } from "./build.js";
3
+ import { CLI_VERSION, helpText } from "./help.js";
4
+ import { formatSummary, runInspect } from "./inspect.js";
5
+ import { DEFAULT_SERVE_PORT, startServe } from "./serve/server.js";
6
+ import { runShelf } from "./shelf.js";
7
+ async function build(rest) {
8
+ try {
9
+ const { values, positionals } = parseArgs({
10
+ args: rest,
11
+ options: {
12
+ out: { type: "string", short: "o" },
13
+ "include-secrets": { type: "boolean" },
14
+ findings: { type: "string", multiple: true },
15
+ offline: { type: "boolean" },
16
+ "no-history": { type: "boolean" },
17
+ "git-dir": { type: "string" },
18
+ },
19
+ allowPositionals: true,
20
+ });
21
+ const input = positionals[0];
22
+ if (!input) {
23
+ console.error("cabn build: missing <dir|zipfile>");
24
+ return 1;
25
+ }
26
+ const summary = await runBuild(input, {
27
+ outDir: values.out,
28
+ includeSecrets: values["include-secrets"],
29
+ findingsPaths: values.findings,
30
+ offline: values.offline,
31
+ history: !values["no-history"],
32
+ gitDir: values["git-dir"],
33
+ });
34
+ console.log(`Built world at ${summary.outDir}`);
35
+ console.log(`${summary.clusters} clusters, ${summary.portals} portals, ${summary.monsters} monsters, ${summary.bytes} bytes in ${summary.elapsedMs}ms`);
36
+ if (summary.findings) {
37
+ const { ingested, attached, dropped } = summary.findings;
38
+ console.log(`Findings: ${attached} of ${ingested} became monsters (${dropped} dropped: path not in this world, duplicate of a built-in monster, or over a cap)`);
39
+ }
40
+ for (const b of summary.embedBlocked) {
41
+ console.log(`Note: ${b.portalId} -> ${b.url} refuses to be framed${b.detail ? ` (${b.detail})` : ""}; the world shows its title card and an "Open in browser" button instead.`);
42
+ }
43
+ if (summary.history) {
44
+ const h = summary.history;
45
+ console.log(`History: ${h.branches} branch(es), ${h.tags} tag(s), up to ${h.commitsPerBranch} commits per branch${h.halvings ? ` (halved ${h.halvings}x to fit the pack cap)` : ""}; pack ${Math.round(h.packBytes / 1024)} KB, ${h.objects} objects, ${h.notShipped} blob(s) not shipped; releases: ${h.releases}${h.releaseCount ? ` (${h.releaseCount})` : ""}. Publishing this world publishes its git history, author emails included.`);
46
+ }
47
+ for (const warning of summary.warnings)
48
+ console.warn(`Note: ${warning}`);
49
+ if (values.offline) {
50
+ console.log("Embed check and GitHub releases skipped (--offline): url previews are assumed framable.");
51
+ }
52
+ if (summary.truncated) {
53
+ console.warn(`Warning: partial world — ${summary.skippedFiles} file(s) were dropped by the converter's caps (maxFiles/archive limits).`);
54
+ }
55
+ return 0;
56
+ }
57
+ catch (err) {
58
+ console.error(`cabn build failed: ${err.message}`);
59
+ return 1;
60
+ }
61
+ }
62
+ async function inspect(rest) {
63
+ try {
64
+ const { positionals } = parseArgs({ args: rest, allowPositionals: true });
65
+ const bundleDir = positionals[0];
66
+ if (!bundleDir) {
67
+ console.error("cabn inspect: missing <bundleDir>");
68
+ return 1;
69
+ }
70
+ const manifest = await runInspect(bundleDir);
71
+ console.log(formatSummary(manifest));
72
+ return 0;
73
+ }
74
+ catch (err) {
75
+ console.error(`cabn inspect failed: ${err.message}`);
76
+ return 1;
77
+ }
78
+ }
79
+ async function shelf(rest) {
80
+ try {
81
+ const { values, positionals } = parseArgs({
82
+ args: rest,
83
+ options: { out: { type: "string", short: "o" } },
84
+ allowPositionals: true,
85
+ });
86
+ if (positionals.length === 0) {
87
+ console.error("cabn shelf: missing <bundleDir...>");
88
+ return 1;
89
+ }
90
+ const summary = await runShelf(positionals, { outDir: values.out });
91
+ console.log(`Wrote shelf at ${summary.outDir} (${summary.worlds} worlds)`);
92
+ return 0;
93
+ }
94
+ catch (err) {
95
+ console.error(`cabn shelf failed: ${err.message}`);
96
+ return 1;
97
+ }
98
+ }
99
+ async function serve(rest) {
100
+ try {
101
+ const { values, positionals } = parseArgs({
102
+ args: rest,
103
+ options: {
104
+ port: { type: "string" },
105
+ "allow-exec": { type: "boolean" },
106
+ timeout: { type: "string" },
107
+ offline: { type: "boolean" },
108
+ owner: { type: "boolean" },
109
+ "no-history": { type: "boolean" },
110
+ "git-dir": { type: "string" },
111
+ },
112
+ allowPositionals: true,
113
+ });
114
+ const dir = positionals[0];
115
+ if (!dir) {
116
+ console.error("cabn serve: missing <dir>");
117
+ return 1;
118
+ }
119
+ const handle = await startServe(dir, {
120
+ port: values.port ? Number(values.port) : DEFAULT_SERVE_PORT,
121
+ allowExec: values["allow-exec"] ?? false,
122
+ timeoutMs: values.timeout ? Number(values.timeout) : undefined,
123
+ offline: values.offline ?? false,
124
+ owner: values.owner ?? false,
125
+ history: !values["no-history"],
126
+ gitDir: values["git-dir"],
127
+ });
128
+ // Never resolves on its own — `cabn serve` is a long-running command,
129
+ // stopped by the user (Ctrl-C) rather than exiting once "done".
130
+ await new Promise((resolveForever) => {
131
+ process.once("SIGINT", () => {
132
+ handle.close().then(() => resolveForever());
133
+ });
134
+ });
135
+ return 0;
136
+ }
137
+ catch (err) {
138
+ console.error(`cabn serve failed: ${err.message}`);
139
+ return 1;
140
+ }
141
+ }
142
+ export async function run(argv) {
143
+ const [command, ...rest] = argv;
144
+ if (!command || command === "--help" || command === "-h") {
145
+ console.log(helpText());
146
+ return 0;
147
+ }
148
+ if (command === "--version" || command === "-v") {
149
+ console.log(CLI_VERSION);
150
+ return 0;
151
+ }
152
+ if (command === "build")
153
+ return build(rest);
154
+ if (command === "inspect")
155
+ return inspect(rest);
156
+ if (command === "shelf")
157
+ return shelf(rest);
158
+ if (command === "serve")
159
+ return serve(rest);
160
+ console.error(`cabn: unknown command "${command}"`);
161
+ console.log(helpText());
162
+ return 1;
163
+ }
package/dist/help.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const CLI_VERSION: string;
2
+ export declare function helpText(): string;
package/dist/help.js ADDED
@@ -0,0 +1,35 @@
1
+ import { readFileSync } from "node:fs";
2
+ // Read at runtime rather than inlined: tsc emits dist/help.js one level
3
+ // below package.json, the same relative spot as src/help.ts, and the
4
+ // published package always ships package.json.
5
+ export const CLI_VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
6
+ export function helpText() {
7
+ return [
8
+ `cabn ${CLI_VERSION}`,
9
+ "",
10
+ "Turn a directory or zipfile into an explorable cottagecore game world.",
11
+ "",
12
+ "Usage:",
13
+ " cabn build <dir|zipfile> [-o outDir] [--include-secrets] [--offline] [--findings file]... [--no-history] [--git-dir path]",
14
+ " Convert a source into a world bundle",
15
+ " (a git repository root also ships its recent git history, author emails included, and",
16
+ " GitHub releases; --no-history skips that, --git-dir reads another git directory,",
17
+ " the opt-in for a .git symlink or a worktree/submodule .git pointer file;",
18
+ " (--include-secrets reads .env/*.pem/etc content instead of leaving them metadata-only;",
19
+ " --findings turns an ESLint JSON or SARIF results file into monsters, repeatable;",
20
+ " --offline skips the one-request-per-url check of whether url previews can be framed",
21
+ " and the GitHub releases request)",
22
+ " cabn inspect <bundleDir> Validate and summarize a world bundle",
23
+ " cabn shelf <bundleDir...> [-o outDir] Build a shelf.json listing multiple converted worlds",
24
+ " cabn serve <dir> [--port 5178] [--allow-exec] [--timeout ms] [--offline] [--owner] [--no-history] [--git-dir path]",
25
+ " Convert <dir> in memory and serve it as a walkable game, bound to",
26
+ " 127.0.0.1 only. --allow-exec enables REAL code execution of files",
27
+ " you run with the wand tool — only pass it for code you trust.",
28
+ " --owner turns on owner mode: the page can write .seyn signs into <dir>,",
29
+ " commit your in-game edits and create/switch branches in the real",
30
+ " repository (local only; never push/fetch), and show hidden files.",
31
+ " In the game, O opens the owner's toolkit for all of these. Off by default.",
32
+ " cabn --version Print the CLI version",
33
+ " cabn --help Show this help text",
34
+ ].join("\n");
35
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./build.js";
2
+ export * from "./cli.js";
3
+ export * from "./help.js";
4
+ export * from "./inspect.js";
5
+ export * from "./serve/server.js";
6
+ export * from "./shelf.js";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./build.js";
2
+ export * from "./cli.js";
3
+ export * from "./help.js";
4
+ export * from "./inspect.js";
5
+ export * from "./serve/server.js";
6
+ export * from "./shelf.js";
@@ -0,0 +1,3 @@
1
+ import { type WorldManifest } from "@cabn/world-schema";
2
+ export declare function formatSummary(manifest: WorldManifest): string;
3
+ export declare function runInspect(bundleDir: string): Promise<WorldManifest>;
@@ -0,0 +1,35 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { validateManifest } from "@cabn/world-schema";
4
+ export function formatSummary(manifest) {
5
+ const kindCounts = new Map();
6
+ for (const portal of manifest.portals) {
7
+ kindCounts.set(portal.file.kind, (kindCounts.get(portal.file.kind) ?? 0) + 1);
8
+ }
9
+ const topKinds = [...kindCounts.entries()]
10
+ .sort((a, b) => b[1] - a[1])
11
+ .map(([kind, count]) => `${kind}:${count}`)
12
+ .join(", ");
13
+ const clusterLines = manifest.clusters.map((cluster) => {
14
+ const depth = cluster.path === "." ? 0 : cluster.path.split("/").length;
15
+ const annex = cluster.annexOf ? ` (annex of ${cluster.annexOf})` : "";
16
+ return `${" ".repeat(depth)}- ${cluster.label} [${cluster.biome}] (${cluster.portalIds.length} portals)${annex}`;
17
+ });
18
+ const truncatedLine = manifest.meta.truncated
19
+ ? [
20
+ `Warning: partial world — ${manifest.meta.skippedFiles} file(s) were dropped by the converter's caps.`,
21
+ ]
22
+ : [];
23
+ return [
24
+ `${manifest.meta.name} (cabn v${manifest.cabnVersion})`,
25
+ `${manifest.clusters.length} clusters, ${manifest.portals.length} portals, ${manifest.meta.totalBytes} bytes`,
26
+ `Top file kinds: ${topKinds || "none"}`,
27
+ ...truncatedLine,
28
+ "",
29
+ ...clusterLines,
30
+ ].join("\n");
31
+ }
32
+ export async function runInspect(bundleDir) {
33
+ const raw = await readFile(join(bundleDir, "world.json"), "utf8");
34
+ return validateManifest(JSON.parse(raw));
35
+ }
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "./cli.js";
3
+ process.exitCode = await run(process.argv.slice(2));
@@ -0,0 +1,43 @@
1
+ export type ExecEvent = {
2
+ type: "stdout";
3
+ text: string;
4
+ } | {
5
+ type: "stderr";
6
+ text: string;
7
+ } | {
8
+ type: "line";
9
+ line: number;
10
+ } | {
11
+ type: "exit";
12
+ code: number | null;
13
+ } | {
14
+ type: "timeout";
15
+ } | {
16
+ type: "error";
17
+ message: string;
18
+ };
19
+ export interface RunScriptOptions {
20
+ cwd: string;
21
+ /** True only for the python tracer wrapper — its stderr is `parseTraceChunk`d for `\x1eLINE n` markers; every other runtime's stderr is forwarded untouched (see runtime.ts's "JS/TS: no real line tracing" note). */
22
+ traced: boolean;
23
+ timeoutMs?: number;
24
+ outputCapBytes?: number;
25
+ onEvent: (event: ExecEvent) => void;
26
+ }
27
+ export interface RunningScript {
28
+ done: Promise<void>;
29
+ /** Kills the whole process group (or just the process on Windows) — used for both the timeout and an early client disconnect. */
30
+ kill(signal?: NodeJS.Signals): void;
31
+ }
32
+ export declare const DEFAULT_TIMEOUT_MS = 10000;
33
+ export declare const DEFAULT_OUTPUT_CAP_BYTES: number;
34
+ /**
35
+ * Spawns exactly `command`/`args` with `child_process.spawn` (never a shell —
36
+ * no string ever gets shell-interpreted, so there's no injection surface
37
+ * beyond the allowlisted interpreter itself) in a detached process group on
38
+ * POSIX so a runaway child's own children die with it, a minimal env (PATH +
39
+ * HOME only — no inherited secrets from this server's own process env), and
40
+ * hard per-stream output caps that stop accumulating (and kill the process,
41
+ * see below) once reached.
42
+ */
43
+ export declare function runScript(command: string, args: string[], opts: RunScriptOptions): RunningScript;