@marktiderman/genesis-config 0.0.0-stage → 0.10.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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +461 -2
  3. package/dist/blocks.d.ts +473 -0
  4. package/dist/blocks.js +5 -0
  5. package/dist/blocks.js.map +1 -0
  6. package/dist/chunk-B6WRD3WF.js +6 -0
  7. package/dist/chunk-B6WRD3WF.js.map +1 -0
  8. package/dist/chunk-HIOKZIZP.js +218 -0
  9. package/dist/chunk-HIOKZIZP.js.map +1 -0
  10. package/dist/chunk-M7IY6LUN.js +123 -0
  11. package/dist/chunk-M7IY6LUN.js.map +1 -0
  12. package/dist/chunk-OW46SL2G.js +10 -0
  13. package/dist/chunk-OW46SL2G.js.map +1 -0
  14. package/dist/chunk-SEFG2QV6.js +413 -0
  15. package/dist/chunk-SEFG2QV6.js.map +1 -0
  16. package/dist/chunk-UD7SPYZH.js +354 -0
  17. package/dist/chunk-UD7SPYZH.js.map +1 -0
  18. package/dist/chunk-VYUX7VAX.js +52 -0
  19. package/dist/chunk-VYUX7VAX.js.map +1 -0
  20. package/dist/chunk-Y7NUBTWA.js +494 -0
  21. package/dist/chunk-Y7NUBTWA.js.map +1 -0
  22. package/dist/gate-CNTkn-Fv.d.ts +202 -0
  23. package/dist/gate-react.d.ts +48 -0
  24. package/dist/gate-react.js +37 -0
  25. package/dist/gate-react.js.map +1 -0
  26. package/dist/gate.d.ts +18 -0
  27. package/dist/gate.js +5 -0
  28. package/dist/gate.js.map +1 -0
  29. package/dist/index.d.ts +128 -0
  30. package/dist/index.js +9 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/model-uON71G4u.d.ts +437 -0
  33. package/dist/node.d.ts +159 -0
  34. package/dist/node.js +486 -0
  35. package/dist/node.js.map +1 -0
  36. package/dist/packages-CWhdXtzS.d.ts +203 -0
  37. package/dist/platforms-NR0liM8L.d.ts +10 -0
  38. package/dist/react.d.ts +60 -0
  39. package/dist/react.js +236 -0
  40. package/dist/react.js.map +1 -0
  41. package/dist/settings-protocol.d.ts +515 -0
  42. package/dist/settings-protocol.js +4 -0
  43. package/dist/settings-protocol.js.map +1 -0
  44. package/dist/settings-react.d.ts +143 -0
  45. package/dist/settings-react.js +943 -0
  46. package/dist/settings-react.js.map +1 -0
  47. package/dist/settings.d.ts +373 -0
  48. package/dist/settings.js +3 -0
  49. package/dist/settings.js.map +1 -0
  50. package/dist/types-D4hs16bJ.d.ts +39 -0
  51. package/package.json +141 -4
@@ -0,0 +1,494 @@
1
+ import { requirementProblem, cycleProblems, dependencyOrder } from './chunk-VYUX7VAX.js';
2
+ import { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
3
+
4
+ // src/blocks.ts
5
+ var BlockError = class extends Error {
6
+ constructor(problems) {
7
+ super(`Invalid blocks:
8
+ ${problems.map((p) => ` - ${p}`).join("\n")}`);
9
+ this.problems = problems;
10
+ this.name = "BlockError";
11
+ }
12
+ problems;
13
+ };
14
+ var ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
15
+ var CONTRIBUTION_KEYS = ["nav", "settings", "routes", "slots", "migrations", "skills", "privacy", "contentSection"];
16
+ function duplicates(values) {
17
+ const seen = /* @__PURE__ */ new Set();
18
+ const dup = /* @__PURE__ */ new Set();
19
+ for (const v of values) (seen.has(v) ? dup : seen).add(v);
20
+ return [...dup];
21
+ }
22
+ function blockProblems(block) {
23
+ const { id } = block;
24
+ const problems = [];
25
+ if (typeof id !== "string" || !ID.test(id)) problems.push(`${String(id)}: a block id is a feature id: lowercase letters and digits, joined by -, _ or .`);
26
+ for (const req of block.requires ?? []) {
27
+ if (req === id) problems.push(`${id}.requires: a block can't require itself`);
28
+ else if (!ID.test(req)) problems.push(`${id}.requires: "${req}" is not a feature id`);
29
+ }
30
+ for (const p of block.platforms ?? []) {
31
+ if (!FEATURE_PLATFORMS.includes(p)) problems.push(`${id}.platforms: "${p}" is not one of ${FEATURE_PLATFORMS.join(", ")}`);
32
+ }
33
+ if (block.platforms && block.platforms.length === 0) problems.push(`${id}.platforms: an empty list runs nowhere; leave it out for every platform`);
34
+ const c = block.contributes ?? {};
35
+ for (const key of Object.keys(c)) {
36
+ if (!CONTRIBUTION_KEYS.includes(key)) problems.push(`${id}.contributes.${key}: not a contribution (${CONTRIBUTION_KEYS.join(", ")})`);
37
+ }
38
+ for (const d of duplicates((c.nav ?? []).map((n) => n.id))) problems.push(`${id}.contributes.nav: "${d}" appears twice`);
39
+ for (const d of duplicates((c.settings ?? []).map((r) => r.id))) problems.push(`${id}.contributes.settings: "${d}" appears twice`);
40
+ for (const d of duplicates((c.routes ?? []).map((r) => r.path))) problems.push(`${id}.contributes.routes: "${d}" appears twice`);
41
+ for (const n of c.nav ?? []) if (!n.id || !n.label || !n.path) problems.push(`${id}.contributes.nav: every entry needs an id, a label and a path`);
42
+ for (const n of c.nav ?? []) if (n.zone !== void 0 && (typeof n.zone !== "string" || !n.zone.trim())) problems.push(`${id}.contributes.nav: "${n.id}" zone must be a non-empty string`);
43
+ for (const r of c.settings ?? []) if (!r.id || !r.section || !r.title) problems.push(`${id}.contributes.settings: every row needs an id, a section and a title`);
44
+ for (const m of c.migrations ?? []) if (!m.package || !m.file) problems.push(`${id}.contributes.migrations: every migration needs a package and a file`);
45
+ return problems;
46
+ }
47
+ function defineBlock(block) {
48
+ const problems = blockProblems(block);
49
+ if (problems.length) throw new BlockError(problems);
50
+ return Object.freeze(block);
51
+ }
52
+ function enabledPredicate(enabled) {
53
+ if (enabled === void 0) return void 0;
54
+ if (typeof enabled === "function") return enabled;
55
+ const set = new Set(enabled);
56
+ return (id) => set.has(id);
57
+ }
58
+ var byOrder = (items) => items.sort((a, b) => (a.item.order ?? 0) - (b.item.order ?? 0) || a.at - b.at).map((x) => x.item);
59
+ function resolveBlocks(blocks, enabled, options = {}) {
60
+ const { platform, features, missing = "throw", slots: slotNames } = options;
61
+ const problems = [];
62
+ const byId = /* @__PURE__ */ new Map();
63
+ for (const block of blocks) {
64
+ problems.push(...blockProblems(block));
65
+ if (byId.has(block.id)) problems.push(`${block.id}: two blocks have this id`);
66
+ else byId.set(block.id, block);
67
+ }
68
+ const isFeature = features ? (id) => Object.hasOwn(features, id) : void 0;
69
+ if (isFeature) {
70
+ for (const id of byId.keys()) if (!isFeature(id)) problems.push(`${id}: not a feature in the registry`);
71
+ }
72
+ const graph = Object.fromEntries([...byId].map(([id, b]) => [id, { requires: b.requires }]));
73
+ const known = { noun: "block", isKnown: (req) => byId.has(req) || !isFeature || isFeature(req) };
74
+ for (const [id, node] of Object.entries(graph)) {
75
+ for (const req of node.requires ?? []) {
76
+ if (req !== id && requirementProblem(graph, id, req, known)) problems.push(`${id}.requires: "${req}" is neither a block nor a feature in the registry`);
77
+ }
78
+ }
79
+ problems.push(...cycleProblems(graph));
80
+ if (problems.length) throw new BlockError(problems);
81
+ const isOn = enabledPredicate(enabled);
82
+ const runsHere = (b) => !platform || !b.platforms || b.platforms.includes(platform);
83
+ const active = /* @__PURE__ */ new Set();
84
+ for (const [id, b] of byId) if ((!isOn || isOn(id)) && runsHere(b)) active.add(id);
85
+ const order = dependencyOrder(graph);
86
+ const dropped = [];
87
+ for (const id of order) {
88
+ if (!active.has(id)) continue;
89
+ const off = (byId.get(id).requires ?? []).filter((req) => {
90
+ if (byId.has(req)) return !active.has(req);
91
+ return !isOn || !isOn(req);
92
+ });
93
+ if (!off.length) continue;
94
+ if (missing === "drop") {
95
+ active.delete(id);
96
+ dropped.push({ id, missing: off });
97
+ continue;
98
+ }
99
+ for (const req of off) {
100
+ const why = !byId.has(req) ? isOn ? "is not enabled" : "is not one of the blocks given (pass it, or list the app feature in enabled)" : !runsHere(byId.get(req)) ? `doesn't run on ${platform}` : "is off";
101
+ problems.push(`${id}.requires: "${req}" ${why}; turn it on or turn ${id} off`);
102
+ }
103
+ }
104
+ if (problems.length) throw new BlockError(problems);
105
+ const on = order.filter((id) => active.has(id)).map((id) => byId.get(id));
106
+ const nav = [];
107
+ const settings = [];
108
+ const routes = [];
109
+ const migrations = [];
110
+ const skills = [];
111
+ const privacy = [];
112
+ const slots = {};
113
+ const owner = { nav: /* @__PURE__ */ new Map(), settings: /* @__PURE__ */ new Map(), routes: /* @__PURE__ */ new Map(), slots: /* @__PURE__ */ new Map() };
114
+ const claim = (kind, key, id, what) => {
115
+ const first = owner[kind].get(key);
116
+ if (first !== void 0) problems.push(`${id}.contributes.${kind}: ${what} "${key}" is already contributed by ${first}`);
117
+ else owner[kind].set(key, id);
118
+ return first === void 0;
119
+ };
120
+ on.forEach((block, at) => {
121
+ const feature = block.id;
122
+ const c = block.contributes ?? {};
123
+ for (const n of c.nav ?? []) if (claim("nav", n.id, feature, "the nav entry")) nav.push({ item: { ...n, feature }, at });
124
+ for (const r of c.settings ?? []) if (claim("settings", r.id, feature, "the settings row")) settings.push({ item: { ...r, feature }, at });
125
+ for (const r of c.routes ?? []) if (claim("routes", r.path, feature, "the route")) routes.push({ ...r, feature });
126
+ for (const [name, fill] of Object.entries(c.slots ?? {})) {
127
+ if (slotNames && !slotNames.includes(name)) {
128
+ problems.push(`${feature}.contributes.slots: "${name}" is not a slot here (${slotNames.join(", ")})`);
129
+ continue;
130
+ }
131
+ if (claim("slots", name, feature, "the slot")) slots[name] = fill;
132
+ }
133
+ for (const m of c.migrations ?? []) migrations.push({ ...m, feature });
134
+ for (const path of c.skills ?? []) skills.push({ path, feature });
135
+ if (c.privacy) privacy.push({ ...c.privacy, feature });
136
+ });
137
+ if (problems.length) throw new BlockError(problems);
138
+ const ids = new Set(on.map((b) => b.id));
139
+ return Object.freeze({
140
+ blocks: Object.freeze(on),
141
+ ids,
142
+ has: (id) => ids.has(id),
143
+ contributionsOf: (id) => ids.has(id) ? byId.get(id).contributes ?? {} : void 0,
144
+ nav: Object.freeze(byOrder(nav)),
145
+ settings: Object.freeze(byOrder(settings)),
146
+ routes: Object.freeze(routes),
147
+ slots: Object.freeze(slots),
148
+ migrations: Object.freeze(migrations),
149
+ skills: Object.freeze(skills),
150
+ privacy: Object.freeze(privacy),
151
+ dropped: Object.freeze(dropped)
152
+ });
153
+ }
154
+
155
+ // src/content-packs-legacy.ts
156
+ var CONTENT_PACK_FIELD_TARGETS = {
157
+ pursuits: "pursuits",
158
+ work_items: "pursuits",
159
+ metrics: "metrics",
160
+ sessions: "sessions"
161
+ };
162
+ var SECTION_BLOCK = { sessionTypes: "sessions", metricTemplates: "metrics", forms: "forms", roadmapTemplates: "roadmap" };
163
+ function legacyContentPackBlocks(pack) {
164
+ const needed = [];
165
+ for (const [section, block] of Object.entries(SECTION_BLOCK)) {
166
+ const items = pack[section];
167
+ if (items && items.length) needed.push(block);
168
+ }
169
+ for (const f of pack.fieldDefinitions ?? []) {
170
+ const block = CONTENT_PACK_FIELD_TARGETS[f.target];
171
+ if (block) needed.push(block);
172
+ }
173
+ return needed;
174
+ }
175
+ function legacyContentPackProblems(pack, at, keyProblems2) {
176
+ const problems = [
177
+ ...keyProblems2(`${at}.sessionTypes`, pack.sessionTypes),
178
+ ...keyProblems2(`${at}.metricTemplates`, pack.metricTemplates),
179
+ ...keyProblems2(`${at}.fieldDefinitions`, pack.fieldDefinitions),
180
+ ...keyProblems2(`${at}.forms`, pack.forms),
181
+ ...keyProblems2(`${at}.roadmapTemplates`, pack.roadmapTemplates)
182
+ ];
183
+ for (const s of pack.sessionTypes ?? []) {
184
+ problems.push(...keyProblems2(`${at}.sessionTypes.${s.key}.agenda`, s.agenda));
185
+ for (const item of s.agenda ?? []) {
186
+ if (!(typeof item.minutes === "number" && item.minutes > 0)) problems.push(`${at}.sessionTypes.${s.key}.agenda.${item.key}: minutes must be more than 0`);
187
+ }
188
+ }
189
+ for (const f of pack.fieldDefinitions ?? []) {
190
+ if (!Object.hasOwn(CONTENT_PACK_FIELD_TARGETS, f.target)) problems.push(`${at}.fieldDefinitions.${f.key}: target "${String(f.target)}" isn't one of ${Object.keys(CONTENT_PACK_FIELD_TARGETS).join(", ")}`);
191
+ if (typeof f.field?.type !== "string") problems.push(`${at}.fieldDefinitions.${f.key}: field needs a genesis-forms type`);
192
+ if (!["tenant", "app", "private"].includes(f.visibility)) problems.push(`${at}.fieldDefinitions.${f.key}: visibility must be tenant, app or private`);
193
+ }
194
+ for (const r of pack.roadmapTemplates ?? []) {
195
+ problems.push(...keyProblems2(`${at}.roadmapTemplates.${r.key}.items`, r.items));
196
+ const keys = new Set((r.items ?? []).map((i) => i.key));
197
+ for (const item of r.items ?? []) {
198
+ if (item.ref !== void 0 && (!keys.has(item.ref) || item.ref === item.key)) {
199
+ problems.push(`${at}.roadmapTemplates.${r.key}.items.${item.key}: ref "${item.ref}" isn't another item in this template`);
200
+ }
201
+ }
202
+ }
203
+ return problems;
204
+ }
205
+
206
+ // src/content-packs.ts
207
+ var ContentPackError = class extends Error {
208
+ constructor(problems) {
209
+ super(`Invalid content pack:
210
+ ${problems.map((p) => ` - ${p}`).join("\n")}`);
211
+ this.problems = problems;
212
+ this.name = "ContentPackError";
213
+ }
214
+ problems;
215
+ };
216
+ var KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
217
+ var KEY = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
218
+ var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
219
+ function keyProblems(where, items) {
220
+ const problems = [];
221
+ const seen = /* @__PURE__ */ new Set();
222
+ for (const [i, item] of (items ?? []).entries()) {
223
+ const key = item?.key;
224
+ if (typeof key !== "string" || !KEY.test(key)) problems.push(`${where}[${i}].key: "${String(key)}" is not a key (lowercase, dots, dashes or underscores)`);
225
+ else if (seen.has(key)) problems.push(`${where}: the key "${key}" is used twice`);
226
+ else seen.add(key);
227
+ }
228
+ return problems;
229
+ }
230
+ function contentPackBlocks(pack) {
231
+ const needed = new Set(legacyContentPackBlocks(pack));
232
+ const sections = pack.sections;
233
+ const entries = sections && typeof sections === "object" && !Array.isArray(sections) ? Object.entries(sections) : [];
234
+ for (const [block, items] of entries) {
235
+ if (Array.isArray(items) && items.length) needed.add(block);
236
+ }
237
+ return [...needed].sort();
238
+ }
239
+ function test(blocks) {
240
+ if (typeof blocks === "function") return blocks;
241
+ const set = new Set(blocks);
242
+ return (id) => set.has(id);
243
+ }
244
+ function checkOptions(value) {
245
+ if (value === void 0) return {};
246
+ if (typeof value === "function") return { installed: value };
247
+ if (typeof value === "object" && value !== null) {
248
+ if (Symbol.iterator in value) return { installed: value };
249
+ return value;
250
+ }
251
+ throw new TypeError(`contentPackProblems: the second argument is the installed block ids (a list or a predicate) or options, not ${value === null ? "null" : typeof value}`);
252
+ }
253
+ function contentPackProblems(pack, installedOrOptions) {
254
+ const options = checkOptions(installedOrOptions);
255
+ const at = `content pack ${typeof pack?.id === "string" ? pack.id : "?"}`;
256
+ const problems = [];
257
+ if (typeof pack?.id !== "string" || !KEBAB.test(pack.id)) problems.push(`${at}: id must be kebab-case`);
258
+ if (typeof pack?.name !== "string" || !pack.name.trim()) problems.push(`${at}: needs a name`);
259
+ if (typeof pack?.version !== "string" || !SEMVER.test(pack.version)) problems.push(`${at}: version "${String(pack?.version)}" isn't semver`);
260
+ if (typeof pack?.publisher !== "string" || !pack.publisher.trim()) problems.push(`${at}: needs a publisher (its package name)`);
261
+ if (!Array.isArray(pack?.requires)) {
262
+ problems.push(`${at}: requires must list the blocks it fills`);
263
+ return problems;
264
+ }
265
+ for (const [label, text] of Object.entries(pack.labels ?? {})) {
266
+ if (!KEY.test(label)) problems.push(`${at}: label key "${label}" is not a key`);
267
+ if (typeof text !== "string" || !text.trim()) problems.push(`${at}: label "${label}" needs display text`);
268
+ }
269
+ const validators = /* @__PURE__ */ Object.create(null);
270
+ for (const block of options.blocks ?? []) {
271
+ const validate = block.contributes?.contentSection;
272
+ if (typeof validate === "function") validators[block.id] = validate;
273
+ }
274
+ for (const [block, validate] of Object.entries(options.validators ?? {})) if (typeof validate === "function") validators[block] = validate;
275
+ const sections = pack.sections;
276
+ const sectionsOk = sections === void 0 || typeof sections === "object" && sections !== null && !Array.isArray(sections);
277
+ if (!sectionsOk) problems.push(`${at}: sections must be an object keyed by block id`);
278
+ for (const [block, items] of sectionsOk ? Object.entries(sections ?? {}) : []) {
279
+ const where = `${at}.sections.${block}`;
280
+ if (!KEY.test(block)) problems.push(`${where}: "${block}" is not a block id`);
281
+ if (!Array.isArray(items)) {
282
+ problems.push(`${where}: must be a list of items`);
283
+ continue;
284
+ }
285
+ problems.push(...keyProblems(where, items));
286
+ const validate = validators[block];
287
+ if (!validate) continue;
288
+ let found;
289
+ try {
290
+ found = validate(items);
291
+ } catch (error) {
292
+ problems.push(`${where}: the block's validator failed: ${error instanceof Error ? error.message : String(error)}`);
293
+ continue;
294
+ }
295
+ for (const problem of Array.isArray(found) ? found : []) problems.push(`${where}: ${problem}`);
296
+ }
297
+ problems.push(...legacyContentPackProblems(pack, at, keyProblems));
298
+ const declared = new Set(pack.requires);
299
+ for (const block of contentPackBlocks(pack)) {
300
+ if (!declared.has(block)) problems.push(`${at}: fills the ${block} block but doesn't list it in requires`);
301
+ }
302
+ if (options.installed !== void 0) {
303
+ const has = test(options.installed);
304
+ for (const block of pack.requires) if (!has(block)) problems.push(`${at}: needs the ${block} block, which isn't installed`);
305
+ }
306
+ return problems;
307
+ }
308
+ function defineContentPack(pack, options) {
309
+ const problems = contentPackProblems(pack, { blocks: options?.blocks, validators: options?.validators });
310
+ if (problems.length) throw new ContentPackError(problems);
311
+ return pack;
312
+ }
313
+
314
+ // src/overlay.ts
315
+ var OVERLAY_KEYS = /* @__PURE__ */ new Set(["upstream", "since", "owner", "reason", "$comment"]);
316
+ var UPSTREAM = /^(@marktiderman\/genesis(?:-[a-z0-9-]+)?)@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
317
+ var LOCAL_TAG = /(?:^|[.-])local(?:[.-]|$)/;
318
+ var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
319
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
320
+ var isText = (v) => typeof v === "string" && v.trim().length > 0;
321
+ function isIsoDate(v) {
322
+ if (typeof v !== "string") return false;
323
+ const m = ISO_DATE.exec(v);
324
+ if (!m) return false;
325
+ const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
326
+ return d.getUTCFullYear() === Number(m[1]) && d.getUTCMonth() === Number(m[2]) - 1 && d.getUTCDate() === Number(m[3]);
327
+ }
328
+ function readOverlayMarker(name, raw, problems = []) {
329
+ const at = `${name} genesis.overlay`;
330
+ if (!isObject(raw)) {
331
+ problems.push(`${at}: must be an object { "upstream", "since", "owner", "reason" }`);
332
+ return null;
333
+ }
334
+ const before = problems.length;
335
+ for (const key of Object.keys(raw)) {
336
+ if (!OVERLAY_KEYS.has(key)) problems.push(`${at}: unknown key "${key}" (known: upstream, since, owner, reason)`);
337
+ }
338
+ const m = typeof raw.upstream === "string" ? UPSTREAM.exec(raw.upstream) : null;
339
+ if (!m) problems.push(`${at}.upstream: must be "@marktiderman/genesis-<name>@<version>", the package and release it was copied from, not ${JSON.stringify(raw.upstream)}`);
340
+ else if (m[1] !== name) problems.push(`${at}.upstream: names ${m[1]}, but the package is ${name}; an overlay keeps the name it shadows`);
341
+ else if (m[2].includes("-") && LOCAL_TAG.test(m[2].slice(m[2].indexOf("-") + 1))) problems.push(`${at}.upstream: ${m[2]} is a local build; name the release it was copied from`);
342
+ if (!isIsoDate(raw.since)) problems.push(`${at}.since: must be the day it was made, as YYYY-MM-DD, not ${JSON.stringify(raw.since)}`);
343
+ if (!isText(raw.owner)) problems.push(`${at}.owner: say who answers for the overlay`);
344
+ if (!isText(raw.reason)) problems.push(`${at}.reason: say why the overlay exists`);
345
+ return problems.length === before ? { upstream: raw.upstream, since: raw.since, owner: raw.owner, reason: raw.reason } : null;
346
+ }
347
+ function overlayUpstream(marker) {
348
+ const at = marker.upstream.lastIndexOf("@");
349
+ return { name: marker.upstream.slice(0, at), version: marker.upstream.slice(at + 1) };
350
+ }
351
+
352
+ // src/packages.ts
353
+ var PACKAGE_LAYERS = ["foundation", "primitive", "module", "tooling"];
354
+ var PACKAGE_GROUPS = ["core", "data", "ai", "forms", "collaboration", "shells", "modules"];
355
+ var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
356
+ var isText2 = (v) => typeof v === "string" && v.trim().length > 0;
357
+ var isTextList = (v) => Array.isArray(v) && v.every(isText2);
358
+ var PG_NAME = /^[a-z_][a-z0-9_]*$/;
359
+ var MODULE_KEYS = /* @__PURE__ */ new Set(["name", "summary", "blocks", "requiresModules", "schema", "install", "docs", "skill"]);
360
+ function readPackageMeta(name, genesis, problems = [], exportsKeys) {
361
+ const at = `${name} genesis`;
362
+ if (!isObject2(genesis)) {
363
+ problems.push(`${at}: missing; every package declares "genesis": { "layer", "group" }`);
364
+ return null;
365
+ }
366
+ const before = problems.length;
367
+ const { layer, group, essential, module, toolingEntries, owner, overlay, optional } = genesis;
368
+ if (overlay !== void 0) readOverlayMarker(name, overlay, problems);
369
+ if (owner !== void 0 && (typeof owner !== "string" || !/^@[A-Za-z0-9-]+(\/[A-Za-z0-9._-]+)?$/.test(owner))) {
370
+ problems.push(`${at}.owner: must be a GitHub handle or team, like "@octocat" or "@acme/web"`);
371
+ }
372
+ if (!PACKAGE_LAYERS.includes(layer)) problems.push(`${at}.layer: must be one of ${PACKAGE_LAYERS.join(", ")}, not ${JSON.stringify(layer)}`);
373
+ if (!PACKAGE_GROUPS.includes(group)) problems.push(`${at}.group: must be one of ${PACKAGE_GROUPS.join(", ")}, not ${JSON.stringify(group)}`);
374
+ if (essential !== void 0 && typeof essential !== "boolean") problems.push(`${at}.essential: must be true or false`);
375
+ if (essential === true && layer !== "foundation" && layer !== "tooling") problems.push(`${at}.essential: only a foundation or tooling package is essential, not a ${String(layer)}`);
376
+ if (optional !== void 0 && typeof optional !== "boolean") problems.push(`${at}.optional: must be true or false`);
377
+ if (optional === true && (layer === "foundation" || layer === "tooling")) problems.push(`${at}.optional: a ${String(layer)} package can't be optional; only a primitive or module is an upgrade apps opt into`);
378
+ if (optional === true && essential === true) problems.push(`${at}.optional: an essential package can't be optional`);
379
+ if (layer === "module" !== (group === "modules")) problems.push(`${at}.group: a module is in the "modules" group, and only a module is`);
380
+ if (layer === "module" && module === void 0) problems.push(`${at}.module: a module declares its card and install (name, summary, blocks, install, docs, skill)`);
381
+ if (layer !== "module" && module !== void 0) problems.push(`${at}.module: only a package with layer "module" has one`);
382
+ if (module !== void 0) moduleProblems(at, genesis, module, problems);
383
+ if (toolingEntries !== void 0) {
384
+ if (!isTextList(toolingEntries) || toolingEntries.some((e) => !e.startsWith("./"))) problems.push(`${at}.toolingEntries: must be a list of entry points like "./node"`);
385
+ else if (exportsKeys) {
386
+ for (const e of toolingEntries) if (!exportsKeys.includes(e)) problems.push(`${at}.toolingEntries: "${e}" is not in the package's exports`);
387
+ }
388
+ }
389
+ return problems.length === before ? genesis : null;
390
+ }
391
+ function moduleProblems(at, genesis, module, problems) {
392
+ const where = `${at}.module`;
393
+ if (!isObject2(module)) {
394
+ problems.push(`${where}: must be an object`);
395
+ return;
396
+ }
397
+ for (const key of Object.keys(module)) if (!MODULE_KEYS.has(key)) problems.push(`${where}.${key}: unknown key (one of ${[...MODULE_KEYS].join(", ")})`);
398
+ for (const key of ["name", "summary", "install", "docs", "skill"]) if (!isText2(module[key])) problems.push(`${where}.${key}: required text`);
399
+ const declared = isObject2(genesis["blocks"]) ? Object.keys(genesis["blocks"]) : [];
400
+ const blocks = module["blocks"];
401
+ if (!isTextList(blocks) || blocks.length === 0) problems.push(`${where}.blocks: list at least one id from genesis.blocks`);
402
+ else for (const id of blocks) if (!declared.includes(id)) problems.push(`${where}.blocks: "${id}" is not in genesis.blocks`);
403
+ const requiresModules = module["requiresModules"];
404
+ if (requiresModules !== void 0 && !isTextList(requiresModules)) problems.push(`${where}.requiresModules: must be a list of package names`);
405
+ const schema = module["schema"];
406
+ if (schema !== void 0 && !(typeof schema === "string" && PG_NAME.test(schema))) problems.push(`${where}.schema: must be a Postgres schema name`);
407
+ const install = module["install"];
408
+ if (isText2(install)) {
409
+ const words = install.trim().split(/\s+/);
410
+ if (words.length !== 3 || words[0] !== "genesis" || words[1] !== "add") problems.push(`${where}.install: must be "genesis add <block>", not ${JSON.stringify(install)}`);
411
+ else if (isTextList(blocks) && !blocks.includes(words[2])) problems.push(`${where}.install: "${words[2]}" is not one of the module's blocks`);
412
+ }
413
+ const docs = module["docs"];
414
+ if (isText2(docs) && !docs.startsWith("https://") && !isPackagePath(docs)) problems.push(`${where}.docs: a path in the package or an https URL, not ${JSON.stringify(docs)}`);
415
+ const skill = module["skill"];
416
+ if (isText2(skill) && !(isPackagePath(skill) && skill.endsWith("SKILL.md"))) problems.push(`${where}.skill: a SKILL.md path in the package, not ${JSON.stringify(skill)}`);
417
+ }
418
+ function isPackagePath(value) {
419
+ if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return false;
420
+ return value.split("/").every((s) => s !== "" && s !== "." && s !== "..");
421
+ }
422
+ function packageOf(specifier) {
423
+ const parts = specifier.split("/");
424
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
425
+ }
426
+ function packageLayerProblems(packages) {
427
+ const problems = [];
428
+ const metas = /* @__PURE__ */ new Map();
429
+ for (const pkg of packages) {
430
+ const meta = readPackageMeta(pkg.name, pkg.genesis, problems, pkg.exports);
431
+ if (isObject2(pkg.genesis) && pkg.genesis["overlay"] !== void 0) problems.push(`${pkg.name} genesis.overlay: only an app's local copy of a Genesis package carries one, never the package itself`);
432
+ if (meta) metas.set(pkg.name, meta);
433
+ }
434
+ for (const [name, meta] of metas) {
435
+ for (const req of meta.module?.requiresModules ?? []) {
436
+ if (req === name) problems.push(`${name} genesis.module.requiresModules: a module can't require itself`);
437
+ else if (metas.get(req)?.layer !== "module") problems.push(`${name} genesis.module.requiresModules: "${req}" is not a module`);
438
+ }
439
+ }
440
+ const graph = {};
441
+ for (const pkg of packages) {
442
+ const meta = metas.get(pkg.name);
443
+ if (!meta) continue;
444
+ const edges = /* @__PURE__ */ new Set();
445
+ const optionalPeers = new Set(pkg.optionalPeers ?? []);
446
+ const valueImported = new Set((pkg.valueImports ?? []).map(packageOf));
447
+ for (const spec of new Set(pkg.uses)) {
448
+ const target = packageOf(spec);
449
+ if (target === pkg.name) continue;
450
+ const to = metas.get(target);
451
+ if (!to || meta.layer === "tooling") continue;
452
+ const sub = spec.length > target.length ? `.${spec.slice(target.length)}` : ".";
453
+ if (to.layer === "tooling") problems.push(`${pkg.name} (${meta.layer}) uses ${target}, which is tooling: no runtime package depends on tooling`);
454
+ else if (to.toolingEntries?.includes(sub)) problems.push(`${pkg.name} (${meta.layer}) imports ${spec}, a tooling entry point of ${target}`);
455
+ else if (!allowed(meta, to, target)) problems.push(`${pkg.name} (${meta.layer}) uses ${target} (${to.layer}): ${rule(meta)}`);
456
+ else if (to.optional === true && (meta.layer === "foundation" || meta.layer === "primitive") && !optionalPeers.has(target)) {
457
+ problems.push(`${pkg.name} (${meta.layer}) uses ${target}, which is optional: define a port in ${pkg.name} and let ${target} ship the adapter (or list it as an optional peer dependency)`);
458
+ } else if (to.optional === true && (meta.layer === "foundation" || meta.layer === "primitive") && valueImported.has(target)) {
459
+ problems.push(`${pkg.name} (${meta.layer}) imports ${target} statically, but it is an optional peer: import it for types only or with import(), so ${pkg.name} still loads without it`);
460
+ } else if (!optionalPeers.has(target)) edges.add(target);
461
+ }
462
+ if (meta.layer !== "tooling") graph[pkg.name] = { requires: [...edges].sort() };
463
+ }
464
+ for (const cycle of cycleProblems(graph)) problems.push(`dependency cycle:${cycle.slice(cycle.indexOf(": a cycle:") + ": a cycle:".length)}`);
465
+ return problems;
466
+ }
467
+ function allowed(from, to, target) {
468
+ switch (from.layer) {
469
+ case "foundation":
470
+ return to.layer === "foundation";
471
+ case "primitive":
472
+ return to.layer === "foundation" || to.layer === "primitive";
473
+ case "module":
474
+ return to.layer !== "module" || (from.module?.requiresModules ?? []).includes(target);
475
+ case "tooling":
476
+ return true;
477
+ }
478
+ }
479
+ function rule(from) {
480
+ switch (from.layer) {
481
+ case "foundation":
482
+ return "a foundation package depends only on foundation packages";
483
+ case "primitive":
484
+ return "a primitive depends only on foundation packages and other primitives (never a module)";
485
+ case "module":
486
+ return "a module depends on another module only when genesis.module.requiresModules lists it";
487
+ default:
488
+ return "";
489
+ }
490
+ }
491
+
492
+ export { BlockError, CONTENT_PACK_FIELD_TARGETS, ContentPackError, PACKAGE_GROUPS, PACKAGE_LAYERS, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, overlayUpstream, packageLayerProblems, readOverlayMarker, readPackageMeta, resolveBlocks };
493
+ //# sourceMappingURL=chunk-Y7NUBTWA.js.map
494
+ //# sourceMappingURL=chunk-Y7NUBTWA.js.map