@neuroverseos/governance 0.2.3 → 0.3.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.
Files changed (118) hide show
  1. package/package.json +4 -2
  2. package/policies/content-moderation-rules.txt +8 -0
  3. package/policies/marketing-rules.txt +8 -0
  4. package/policies/science-research-rules.txt +11 -0
  5. package/policies/social-media-rules.txt +7 -0
  6. package/policies/strict-rules.txt +8 -0
  7. package/policies/trading-rules.txt +8 -0
  8. package/simulate.html +1899 -0
  9. package/dist/adapters/autoresearch.cjs +0 -196
  10. package/dist/adapters/autoresearch.d.cts +0 -103
  11. package/dist/adapters/autoresearch.d.ts +0 -103
  12. package/dist/adapters/autoresearch.js +0 -7
  13. package/dist/adapters/deep-agents.cjs +0 -1472
  14. package/dist/adapters/deep-agents.d.cts +0 -181
  15. package/dist/adapters/deep-agents.d.ts +0 -181
  16. package/dist/adapters/deep-agents.js +0 -17
  17. package/dist/adapters/express.cjs +0 -1196
  18. package/dist/adapters/express.d.cts +0 -66
  19. package/dist/adapters/express.d.ts +0 -66
  20. package/dist/adapters/express.js +0 -12
  21. package/dist/adapters/index.cjs +0 -2038
  22. package/dist/adapters/index.d.cts +0 -8
  23. package/dist/adapters/index.d.ts +0 -8
  24. package/dist/adapters/index.js +0 -68
  25. package/dist/adapters/langchain.cjs +0 -1259
  26. package/dist/adapters/langchain.d.cts +0 -89
  27. package/dist/adapters/langchain.d.ts +0 -89
  28. package/dist/adapters/langchain.js +0 -17
  29. package/dist/adapters/openai.cjs +0 -1289
  30. package/dist/adapters/openai.d.cts +0 -99
  31. package/dist/adapters/openai.d.ts +0 -99
  32. package/dist/adapters/openai.js +0 -17
  33. package/dist/adapters/openclaw.cjs +0 -1281
  34. package/dist/adapters/openclaw.d.cts +0 -99
  35. package/dist/adapters/openclaw.d.ts +0 -99
  36. package/dist/adapters/openclaw.js +0 -17
  37. package/dist/bootstrap-GXVDZNF7.js +0 -114
  38. package/dist/build-X5MZY4IA.js +0 -339
  39. package/dist/chunk-4L6OPKMQ.js +0 -100
  40. package/dist/chunk-4NGDRRQH.js +0 -10
  41. package/dist/chunk-5U2MQO5P.js +0 -57
  42. package/dist/chunk-6BB55YJI.js +0 -113
  43. package/dist/chunk-6CZSKEY5.js +0 -164
  44. package/dist/chunk-7P3S7MAY.js +0 -1090
  45. package/dist/chunk-A5W4GNQO.js +0 -130
  46. package/dist/chunk-AF2VX4AL.js +0 -363
  47. package/dist/chunk-AKW5YVCE.js +0 -96
  48. package/dist/chunk-BMOXICAB.js +0 -340
  49. package/dist/chunk-BQZMOEML.js +0 -43
  50. package/dist/chunk-D2UCV5AK.js +0 -326
  51. package/dist/chunk-EVDJUSZ2.js +0 -91
  52. package/dist/chunk-FYS2CBUW.js +0 -304
  53. package/dist/chunk-I3RRAYK2.js +0 -11
  54. package/dist/chunk-IZSO75NZ.js +0 -792
  55. package/dist/chunk-JCKSW2PZ.js +0 -304
  56. package/dist/chunk-JZPQGIKR.js +0 -79
  57. package/dist/chunk-KTFTTLTP.js +0 -246
  58. package/dist/chunk-MH7BT4VH.js +0 -15
  59. package/dist/chunk-ORJ3NOE6.js +0 -622
  60. package/dist/chunk-OT6PXH54.js +0 -61
  61. package/dist/chunk-Q6O7ZLO2.js +0 -62
  62. package/dist/chunk-QLPTHTVB.js +0 -253
  63. package/dist/chunk-REXY4LUL.js +0 -226
  64. package/dist/chunk-T5EUJQE5.js +0 -172
  65. package/dist/chunk-TTBKTF3P.js +0 -608
  66. package/dist/chunk-XPDMYECO.js +0 -642
  67. package/dist/chunk-YZFATT7X.js +0 -9
  68. package/dist/chunk-ZIVQNSZU.js +0 -119
  69. package/dist/chunk-ZJTDUCC2.js +0 -194
  70. package/dist/cli/neuroverse.cjs +0 -12564
  71. package/dist/cli/neuroverse.d.cts +0 -1
  72. package/dist/cli/neuroverse.d.ts +0 -1
  73. package/dist/cli/neuroverse.js +0 -208
  74. package/dist/cli/plan.cjs +0 -1686
  75. package/dist/cli/plan.d.cts +0 -20
  76. package/dist/cli/plan.d.ts +0 -20
  77. package/dist/cli/plan.js +0 -353
  78. package/dist/cli/run.cjs +0 -1945
  79. package/dist/cli/run.d.cts +0 -20
  80. package/dist/cli/run.d.ts +0 -20
  81. package/dist/cli/run.js +0 -143
  82. package/dist/configure-ai-TK67ZWZL.js +0 -132
  83. package/dist/decision-flow-LETV5NWY.js +0 -61
  84. package/dist/derive-7365SUFU.js +0 -152
  85. package/dist/doctor-QYISMKEL.js +0 -173
  86. package/dist/equity-penalties-63FGB3I2.js +0 -244
  87. package/dist/explain-A2EWI2OL.js +0 -51
  88. package/dist/guard-3BWL3IGH.js +0 -92
  89. package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
  90. package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
  91. package/dist/guard-engine-QFMIBWJY.js +0 -10
  92. package/dist/impact-UB6DXKSX.js +0 -59
  93. package/dist/improve-XZA57GER.js +0 -66
  94. package/dist/index.cjs +0 -6821
  95. package/dist/index.d.cts +0 -1829
  96. package/dist/index.d.ts +0 -1829
  97. package/dist/index.js +0 -430
  98. package/dist/infer-world-7GVZWFX4.js +0 -543
  99. package/dist/init-PKPIYHYE.js +0 -144
  100. package/dist/init-world-VWMQZQC7.js +0 -223
  101. package/dist/mcp-server-XWQZXNW7.js +0 -13
  102. package/dist/model-adapter-BB7G4MFI.js +0 -11
  103. package/dist/playground-ADWZORNV.js +0 -550
  104. package/dist/redteam-JRQ7FD2F.js +0 -357
  105. package/dist/session-MMYX5YCF.js +0 -15
  106. package/dist/shared--Q8wPBVN.d.ts +0 -60
  107. package/dist/shared-HpAG90PX.d.cts +0 -60
  108. package/dist/shared-U2QFV7JH.js +0 -16
  109. package/dist/simulate-GMIFFXYV.js +0 -83
  110. package/dist/test-JBBZ65X4.js +0 -217
  111. package/dist/trace-3MYWIDEF.js +0 -166
  112. package/dist/validate-LLBWVPGV.js +0 -81
  113. package/dist/validate-engine-UIABSIHD.js +0 -7
  114. package/dist/world-BFJCIQSH.js +0 -378
  115. package/dist/world-loader-HMPTOEA2.js +0 -9
  116. package/dist/worlds/autoresearch.nv-world.md +0 -230
  117. package/dist/worlds/coding-agent.nv-world.md +0 -211
  118. package/dist/worlds/derivation-world.nv-world.md +0 -278
@@ -1,642 +0,0 @@
1
- // src/engine/bootstrap-parser.ts
2
- function splitSections(markdown) {
3
- const lines = markdown.split("\n");
4
- let frontmatter = "";
5
- let bodyStart = 0;
6
- if (lines[0]?.trim() === "---") {
7
- const endIdx = lines.indexOf("---", 1);
8
- if (endIdx > 0) {
9
- frontmatter = lines.slice(1, endIdx).join("\n");
10
- bodyStart = endIdx + 1;
11
- }
12
- }
13
- const sections = [];
14
- let currentSection = null;
15
- const contentLines = [];
16
- for (let i = bodyStart; i < lines.length; i++) {
17
- const line = lines[i];
18
- if (line.startsWith("# ")) {
19
- if (currentSection) {
20
- currentSection.content = contentLines.join("\n").trim();
21
- sections.push(currentSection);
22
- contentLines.length = 0;
23
- }
24
- currentSection = {
25
- name: line.replace(/^#\s+/, "").trim(),
26
- content: "",
27
- startLine: i + 1
28
- // 1-based
29
- };
30
- } else if (currentSection) {
31
- contentLines.push(line);
32
- }
33
- }
34
- if (currentSection) {
35
- currentSection.content = contentLines.join("\n").trim();
36
- sections.push(currentSection);
37
- }
38
- return { frontmatter, sections };
39
- }
40
- function parseFrontmatter(yaml, issues) {
41
- const result = {};
42
- for (const line of yaml.split("\n")) {
43
- const trimmed = line.trim();
44
- if (!trimmed || trimmed.startsWith("#")) continue;
45
- const colonIdx = trimmed.indexOf(":");
46
- if (colonIdx === -1) continue;
47
- const key = trimmed.slice(0, colonIdx).trim();
48
- const value = trimmed.slice(colonIdx + 1).trim();
49
- result[key] = value;
50
- }
51
- if (!result.world_id) {
52
- issues.push({ line: 1, section: "frontmatter", message: "Missing world_id in frontmatter", severity: "error" });
53
- }
54
- if (!result.name) {
55
- issues.push({ line: 1, section: "frontmatter", message: "Missing name in frontmatter", severity: "error" });
56
- }
57
- return {
58
- world_id: result.world_id ?? "",
59
- name: result.name ?? "",
60
- version: result.version,
61
- runtime_mode: result.runtime_mode,
62
- default_profile: result.default_profile,
63
- alternative_profile: result.alternative_profile
64
- };
65
- }
66
- function parseThesis(content, startLine, issues) {
67
- const thesis = content.trim();
68
- if (!thesis) {
69
- issues.push({ line: startLine, section: "Thesis", message: "Thesis section is empty", severity: "error" });
70
- }
71
- return thesis;
72
- }
73
- function parseInvariants(content, startLine, issues) {
74
- const invariants = [];
75
- const lines = content.split("\n");
76
- for (let i = 0; i < lines.length; i++) {
77
- const line = lines[i].trim();
78
- if (!line.startsWith("- ")) continue;
79
- const lineNum = startLine + i + 1;
80
- const match = line.match(
81
- /^-\s+`([^`]+)`\s*[—–-]\s*(.+?)(?:\s*\(([^)]+)\))?\s*$/
82
- );
83
- if (match) {
84
- const id = match[1];
85
- const label = match[2].trim();
86
- const parens = match[3] ?? "structural, immutable";
87
- const enforcement = parens.includes("prompt") ? "prompt" : parens.includes("operational") ? "operational" : "structural";
88
- const mutable = parens.includes("mutable") && !parens.includes("immutable");
89
- invariants.push({ id, label, enforcement, mutable, line: lineNum });
90
- } else {
91
- const fallback = line.match(/^-\s+\*\*([^*]+)\*\*\s*[—–-]\s*(.+)/);
92
- if (fallback) {
93
- const id = fallback[1].toLowerCase().replace(/\s+/g, "_");
94
- const label = fallback[2].trim();
95
- invariants.push({ id, label, enforcement: "structural", mutable: false, line: lineNum });
96
- } else {
97
- issues.push({ line: lineNum, section: "Invariants", message: `Could not parse invariant: "${line}"`, severity: "warning" });
98
- }
99
- }
100
- }
101
- if (invariants.length === 0) {
102
- issues.push({ line: startLine, section: "Invariants", message: "No invariants found", severity: "error" });
103
- }
104
- return invariants;
105
- }
106
- function parseStateVariables(content, startLine, issues) {
107
- const variables = [];
108
- const subSections = splitH2Sections(content, startLine);
109
- for (const sub of subSections) {
110
- const props = parseKeyValueBullets(sub.content);
111
- const lineNum = sub.startLine;
112
- const type = props.type;
113
- if (!type) {
114
- issues.push({ line: lineNum, section: "State", message: `Variable "${sub.name}" missing type`, severity: "error" });
115
- continue;
116
- }
117
- let defaultVal = props.default ?? "";
118
- if (type === "number") {
119
- defaultVal = parseFloat(String(defaultVal)) || 0;
120
- } else if (type === "boolean") {
121
- defaultVal = String(defaultVal).toLowerCase() === "true";
122
- }
123
- const variable = {
124
- id: sub.name,
125
- type,
126
- default: defaultVal,
127
- label: props.label ?? sub.name,
128
- description: props.description ?? "",
129
- line: lineNum
130
- };
131
- if (type === "number") {
132
- if (props.min !== void 0) variable.min = parseFloat(props.min);
133
- if (props.max !== void 0) variable.max = parseFloat(props.max);
134
- if (props.step !== void 0) variable.step = parseFloat(props.step);
135
- }
136
- if (type === "enum" && props.options) {
137
- variable.options = props.options.split(",").map((s) => s.trim());
138
- }
139
- variables.push(variable);
140
- }
141
- return variables;
142
- }
143
- function parseAssumptions(content, startLine, issues) {
144
- const profiles = [];
145
- const subSections = splitH2Sections(content, startLine);
146
- for (const sub of subSections) {
147
- const props = parseKeyValueBullets(sub.content);
148
- const name = props.name ?? sub.name;
149
- const description = props.description ?? "";
150
- const parameters = {};
151
- for (const [key, val] of Object.entries(props)) {
152
- if (key === "name" || key === "description") continue;
153
- if (val === "true") parameters[key] = true;
154
- else if (val === "false") parameters[key] = false;
155
- else if (!isNaN(Number(val)) && val.trim() !== "") parameters[key] = Number(val);
156
- else parameters[key] = val;
157
- }
158
- profiles.push({
159
- id: sub.name,
160
- name,
161
- description,
162
- parameters,
163
- line: sub.startLine
164
- });
165
- }
166
- return profiles;
167
- }
168
- function parseRules(content, startLine, issues) {
169
- const rules = [];
170
- const subSections = splitH2Sections(content, startLine);
171
- for (let ruleIdx = 0; ruleIdx < subSections.length; ruleIdx++) {
172
- const sub = subSections[ruleIdx];
173
- const lineNum = sub.startLine;
174
- const headingMatch = sub.name.match(/^([^:]+):\s*(.+?)(?:\s*\(([^)]+)\))?\s*$/);
175
- const id = headingMatch ? headingMatch[1].trim() : `rule-${String(ruleIdx + 1).padStart(3, "0")}`;
176
- const label = headingMatch ? headingMatch[2].trim() : sub.name;
177
- const severity = headingMatch?.[3]?.trim() ?? "degradation";
178
- const lines = sub.content.split("\n");
179
- let description = "";
180
- const triggers = [];
181
- const effects = [];
182
- let collapseCheck;
183
- const causalParts = {};
184
- for (let i = 0; i < lines.length; i++) {
185
- const line = lines[i].trim();
186
- if (line.startsWith("When ")) {
187
- const triggerStr = line.slice(5);
188
- const parts = triggerStr.split(/\s+AND\s+/i);
189
- for (const part of parts) {
190
- const trigger = parseTriggerExpression(part.trim());
191
- if (trigger) triggers.push(trigger);
192
- else issues.push({ line: lineNum + i, section: "Rules", message: `Could not parse trigger: "${part}"`, severity: "warning" });
193
- }
194
- } else if (line.startsWith("Then ")) {
195
- const effectStr = line.slice(5);
196
- const parts = effectStr.split(",");
197
- for (const part of parts) {
198
- const effect = parseEffectExpression(part.trim());
199
- if (effect) effects.push(effect);
200
- else issues.push({ line: lineNum + i, section: "Rules", message: `Could not parse effect: "${part}"`, severity: "warning" });
201
- }
202
- } else if (line.startsWith("Collapse:")) {
203
- const collapseStr = line.slice(9).trim();
204
- const collapse = parseCollapseExpression(collapseStr);
205
- if (collapse) collapseCheck = collapse;
206
- else issues.push({ line: lineNum + i, section: "Rules", message: `Could not parse collapse: "${collapseStr}"`, severity: "warning" });
207
- } else if (line.startsWith("> ")) {
208
- const causalMatch = line.match(/^>\s*(trigger|rule|shift|effect):\s*(.+)/i);
209
- if (causalMatch) {
210
- causalParts[causalMatch[1].toLowerCase()] = causalMatch[2].trim();
211
- }
212
- } else if (line && !line.startsWith("-") && !line.startsWith("#")) {
213
- if (!description) description = line;
214
- else description += " " + line;
215
- }
216
- }
217
- if (triggers.length === 0) {
218
- issues.push({ line: lineNum, section: "Rules", message: `Rule "${id}" has no triggers (missing "When" line)`, severity: "warning" });
219
- }
220
- if (effects.length === 0) {
221
- issues.push({ line: lineNum, section: "Rules", message: `Rule "${id}" has no effects (missing "Then" line)`, severity: "warning" });
222
- }
223
- const causal_translation = Object.keys(causalParts).length > 0 ? {
224
- trigger_text: causalParts.trigger ?? "",
225
- rule_text: causalParts.rule ?? "",
226
- shift_text: causalParts.shift ?? "",
227
- effect_text: causalParts.effect ?? ""
228
- } : void 0;
229
- rules.push({
230
- id,
231
- label,
232
- severity,
233
- description: description || void 0,
234
- order: ruleIdx + 1,
235
- triggers,
236
- effects,
237
- collapse_check: collapseCheck,
238
- causal_translation,
239
- line: lineNum
240
- });
241
- }
242
- return rules;
243
- }
244
- function parseTriggerExpression(expr) {
245
- const match = expr.match(
246
- /^(\w+)\s*(==|!=|>=|<=|>|<|in)\s*(.+?)\s*\[(state|assumption)\]\s*$/
247
- );
248
- if (!match) return null;
249
- const field = match[1];
250
- const operator = match[2];
251
- let value = match[3].trim();
252
- const source = match[4];
253
- value = parseValueLiteral(value);
254
- return { field, operator, value, source };
255
- }
256
- function parseEffectExpression(expr) {
257
- const compound = expr.match(/^(\w+)\s*(\*=|\+=|-=)\s*(.+)$/);
258
- if (compound) {
259
- const target = compound[1];
260
- const op = compound[2];
261
- const value = parseValueLiteral(compound[3].trim());
262
- const operationMap = {
263
- "*=": "multiply",
264
- "+=": "add",
265
- "-=": "subtract"
266
- };
267
- return { target, operation: operationMap[op], value };
268
- }
269
- const assignment = expr.match(/^(\w+)\s*=\s*(.+)$/);
270
- if (assignment) {
271
- const target = assignment[1];
272
- const value = parseValueLiteral(assignment[2].trim());
273
- const operation = typeof value === "boolean" ? "set_boolean" : "set";
274
- return { target, operation, value };
275
- }
276
- return null;
277
- }
278
- function parseCollapseExpression(expr) {
279
- const cleaned = expr.replace(/\s*→.*$/, "").trim();
280
- const match = cleaned.match(/^(\w+)\s*(==|!=|>=|<=|>|<)\s*([\d.]+)$/);
281
- if (!match) return null;
282
- return {
283
- field: match[1],
284
- operator: match[2],
285
- value: parseFloat(match[3])
286
- };
287
- }
288
- function parseGates(content, startLine, issues) {
289
- const gates = [];
290
- const lines = content.split("\n");
291
- for (let i = 0; i < lines.length; i++) {
292
- const line = lines[i].trim();
293
- if (!line.startsWith("- ")) continue;
294
- const lineNum = startLine + i + 1;
295
- const match = line.match(/^-\s+(\w+):\s*(\w+)\s*(==|!=|>=|<=|>|<)\s*([\d.]+)/);
296
- if (match) {
297
- gates.push({
298
- status: match[1],
299
- field: match[2],
300
- operator: match[3],
301
- value: parseFloat(match[4]),
302
- line: lineNum
303
- });
304
- } else {
305
- issues.push({ line: lineNum, section: "Gates", message: `Could not parse gate: "${line}"`, severity: "warning" });
306
- }
307
- }
308
- if (gates.length === 0) {
309
- issues.push({ line: startLine, section: "Gates", message: "No gates found", severity: "error" });
310
- }
311
- return gates;
312
- }
313
- function parseOutcomes(content, startLine, issues) {
314
- const outcomes = [];
315
- const subSections = splitH2Sections(content, startLine);
316
- for (const sub of subSections) {
317
- const props = parseKeyValueBullets(sub.content);
318
- const outcome = {
319
- id: sub.name,
320
- type: props.type ?? "number",
321
- label: props.label ?? sub.name,
322
- line: sub.startLine
323
- };
324
- if (props.range) {
325
- const rangeParts = props.range.split("-").map(Number);
326
- if (rangeParts.length === 2 && !isNaN(rangeParts[0]) && !isNaN(rangeParts[1])) {
327
- outcome.range = [rangeParts[0], rangeParts[1]];
328
- }
329
- }
330
- if (props.display) outcome.display = props.display;
331
- if (props.primary) outcome.primary = props.primary === "true";
332
- if (props.assignment) outcome.assignment = props.assignment;
333
- outcomes.push(outcome);
334
- }
335
- return outcomes;
336
- }
337
- function splitH2Sections(content, baseStartLine) {
338
- const lines = content.split("\n");
339
- const sections = [];
340
- let current = null;
341
- const contentLines = [];
342
- for (let i = 0; i < lines.length; i++) {
343
- const line = lines[i];
344
- if (line.startsWith("## ")) {
345
- if (current) {
346
- current.content = contentLines.join("\n").trim();
347
- sections.push(current);
348
- contentLines.length = 0;
349
- }
350
- current = {
351
- name: line.replace(/^##\s+/, "").trim(),
352
- content: "",
353
- startLine: baseStartLine + i + 1
354
- };
355
- } else if (current) {
356
- contentLines.push(line);
357
- }
358
- }
359
- if (current) {
360
- current.content = contentLines.join("\n").trim();
361
- sections.push(current);
362
- }
363
- return sections;
364
- }
365
- function parseKeyValueBullets(content) {
366
- const result = {};
367
- for (const line of content.split("\n")) {
368
- const trimmed = line.trim();
369
- const match = trimmed.match(/^-\s+(\w[\w\s]*?):\s*(.+)$/);
370
- if (match) {
371
- result[match[1].trim().toLowerCase().replace(/\s+/g, "_")] = match[2].trim();
372
- }
373
- }
374
- return result;
375
- }
376
- function parseValueLiteral(raw) {
377
- if (raw === "true") return true;
378
- if (raw === "false") return false;
379
- if (raw.startsWith('"') && raw.endsWith('"') || raw.startsWith("'") && raw.endsWith("'")) {
380
- return raw.slice(1, -1);
381
- }
382
- const num = Number(raw);
383
- if (!isNaN(num) && raw.trim() !== "") return num;
384
- return raw;
385
- }
386
- function parseWorldMarkdown(markdown) {
387
- const issues = [];
388
- const { frontmatter: fmRaw, sections } = splitSections(markdown);
389
- const frontmatter = parseFrontmatter(fmRaw, issues);
390
- const findSection = (name) => sections.find((s) => s.name.toLowerCase() === name.toLowerCase());
391
- const thesisSection = findSection("Thesis");
392
- const thesis = thesisSection ? parseThesis(thesisSection.content, thesisSection.startLine, issues) : "";
393
- if (!thesisSection) {
394
- issues.push({ line: 0, section: "Thesis", message: "Missing # Thesis section", severity: "error" });
395
- }
396
- const invariantsSection = findSection("Invariants");
397
- const invariants = invariantsSection ? parseInvariants(invariantsSection.content, invariantsSection.startLine, issues) : [];
398
- if (!invariantsSection) {
399
- issues.push({ line: 0, section: "Invariants", message: "Missing # Invariants section", severity: "error" });
400
- }
401
- const stateSection = findSection("State");
402
- const stateVariables = stateSection ? parseStateVariables(stateSection.content, stateSection.startLine, issues) : [];
403
- if (!stateSection) {
404
- issues.push({ line: 0, section: "State", message: "Missing # State section", severity: "warning" });
405
- }
406
- const assumptionsSection = findSection("Assumptions");
407
- const assumptions = assumptionsSection ? parseAssumptions(assumptionsSection.content, assumptionsSection.startLine, issues) : [];
408
- if (!assumptionsSection) {
409
- issues.push({ line: 0, section: "Assumptions", message: "Missing # Assumptions section", severity: "warning" });
410
- }
411
- const rulesSection = findSection("Rules");
412
- const rules = rulesSection ? parseRules(rulesSection.content, rulesSection.startLine, issues) : [];
413
- if (!rulesSection) {
414
- issues.push({ line: 0, section: "Rules", message: "Missing # Rules section", severity: "warning" });
415
- }
416
- const gatesSection = findSection("Gates");
417
- const gates = gatesSection ? parseGates(gatesSection.content, gatesSection.startLine, issues) : [];
418
- if (!gatesSection) {
419
- issues.push({ line: 0, section: "Gates", message: "Missing # Gates section", severity: "warning" });
420
- }
421
- const outcomesSection = findSection("Outcomes");
422
- const outcomes = outcomesSection ? parseOutcomes(outcomesSection.content, outcomesSection.startLine, issues) : [];
423
- const parsedSections = sections.map((s) => s.name);
424
- const knownSections = /* @__PURE__ */ new Set(["thesis", "invariants", "state", "assumptions", "rules", "gates", "outcomes"]);
425
- for (const section of sections) {
426
- if (!knownSections.has(section.name.toLowerCase())) {
427
- issues.push({
428
- line: section.startLine,
429
- section: section.name,
430
- message: `Unrecognized section "${section.name}" \u2014 will be ignored`,
431
- severity: "info"
432
- });
433
- }
434
- }
435
- const hasErrors = issues.some((i) => i.severity === "error");
436
- if (!frontmatter.world_id || !thesis) {
437
- if (hasErrors) {
438
- return { world: null, issues };
439
- }
440
- }
441
- return {
442
- world: {
443
- frontmatter,
444
- thesis,
445
- invariants,
446
- stateVariables,
447
- assumptions,
448
- rules,
449
- gates,
450
- outcomes
451
- },
452
- issues
453
- };
454
- }
455
-
456
- // src/engine/bootstrap-emitter.ts
457
- var GATE_DEFAULTS = {
458
- THRIVING: { color: "#0f6b3a", icon: "\u2726" },
459
- STABLE: { color: "#1856b8", icon: "\u25CF" },
460
- COMPRESSED: { color: "#a16207", icon: "\u25B2" },
461
- CRITICAL: { color: "#b91c1c", icon: "\u26A0" },
462
- MODEL_COLLAPSES: { color: "#7f1d1d", icon: "\u2715" }
463
- };
464
- function emitWorldDefinition(parsed) {
465
- const issues = [];
466
- const fm = parsed.frontmatter;
467
- const defaultProfile = fm.default_profile ?? parsed.assumptions[0]?.id ?? "baseline";
468
- const altProfile = fm.alternative_profile ?? parsed.assumptions[1]?.id ?? "alternative";
469
- const world = {
470
- world_id: fm.world_id,
471
- name: fm.name,
472
- thesis: parsed.thesis,
473
- version: fm.version ?? "1.0.0",
474
- runtime_mode: fm.runtime_mode ?? "SIMULATION",
475
- default_assumption_profile: defaultProfile,
476
- default_alternative_profile: altProfile,
477
- modules: parsed.rules.map((r) => r.id),
478
- players: {
479
- thinking_space: true,
480
- experience_space: true,
481
- action_space: true
482
- }
483
- };
484
- const invariants = parsed.invariants.map((inv) => ({
485
- id: inv.id,
486
- label: inv.label,
487
- enforcement: inv.enforcement === "prompt" ? "prompt" : "structural",
488
- mutable: false
489
- }));
490
- const profiles = {};
491
- const parameterDefinitions = {};
492
- for (let i = 0; i < parsed.assumptions.length; i++) {
493
- const profile = parsed.assumptions[i];
494
- const params = {};
495
- for (const [key, val] of Object.entries(profile.parameters)) {
496
- params[key] = String(val);
497
- if (!parameterDefinitions[key]) {
498
- parameterDefinitions[key] = {
499
- type: typeof val === "boolean" ? "boolean" : typeof val === "number" ? "number" : "enum",
500
- label: key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()),
501
- description: `Parameter: ${key}`
502
- };
503
- }
504
- }
505
- profiles[profile.id] = {
506
- name: profile.name,
507
- description: profile.description,
508
- is_default_baseline: i === 0 || profile.id === defaultProfile,
509
- is_default_alternative: i === 1 || profile.id === altProfile,
510
- parameters: params
511
- };
512
- }
513
- const assumptions = { profiles, parameter_definitions: parameterDefinitions };
514
- const variables = {};
515
- for (const v of parsed.stateVariables) {
516
- const stateVar = {
517
- type: v.type,
518
- default: v.default,
519
- mutable: true,
520
- label: v.label,
521
- description: v.description
522
- };
523
- if (v.type === "number") {
524
- if (v.min !== void 0) stateVar.min = v.min;
525
- if (v.max !== void 0) stateVar.max = v.max;
526
- if (v.step !== void 0) stateVar.step = v.step;
527
- }
528
- if (v.type === "enum" && v.options) {
529
- stateVar.options = v.options;
530
- }
531
- variables[v.id] = stateVar;
532
- }
533
- const stateSchema = { variables, presets: {} };
534
- const rules = parsed.rules.map((r) => {
535
- const triggers = r.triggers.map((t) => ({
536
- field: t.field,
537
- operator: t.operator,
538
- value: t.value,
539
- source: t.source
540
- }));
541
- const effects = r.effects.map((e) => ({
542
- target: e.target,
543
- operation: e.operation,
544
- value: e.value
545
- }));
546
- let collapse_check;
547
- if (r.collapse_check) {
548
- collapse_check = {
549
- field: r.collapse_check.field,
550
- operator: r.collapse_check.operator,
551
- value: r.collapse_check.value,
552
- result: "MODEL_COLLAPSES"
553
- };
554
- }
555
- const causal_translation = r.causal_translation ?? {
556
- trigger_text: "",
557
- rule_text: "",
558
- shift_text: "",
559
- effect_text: ""
560
- };
561
- const rule = {
562
- id: r.id,
563
- severity: r.severity,
564
- label: r.label,
565
- description: r.description ?? r.label,
566
- order: r.order,
567
- triggers,
568
- effects: effects.length > 0 ? effects : void 0,
569
- collapse_check,
570
- causal_translation
571
- };
572
- return rule;
573
- });
574
- const viabilityClassification = parsed.gates.map((g) => {
575
- const defaults = GATE_DEFAULTS[g.status] ?? { color: "#5c5a52", icon: "\u25CF" };
576
- return {
577
- status: g.status,
578
- field: g.field,
579
- operator: g.operator,
580
- value: g.value,
581
- color: defaults.color,
582
- icon: defaults.icon
583
- };
584
- });
585
- const gates = {
586
- viability_classification: viabilityClassification,
587
- structural_override: {
588
- description: "Rules with severity=structural and triggered collapse_check force MODEL_COLLAPSES regardless of final margin.",
589
- enforcement: "mandatory"
590
- },
591
- sustainability_threshold: 0.1,
592
- collapse_visual: {
593
- background: "#1c1917",
594
- text: "#fef2f2",
595
- border: "#b91c1c",
596
- label: "Structural Failure"
597
- }
598
- };
599
- const computedOutcomes = parsed.outcomes.map((o) => {
600
- const outcome = {
601
- id: o.id,
602
- type: o.type,
603
- label: o.label,
604
- show_in_comparison: true
605
- };
606
- if (o.range) outcome.range = o.range;
607
- if (o.display) outcome.display_as = o.display;
608
- if (o.primary) outcome.primary = o.primary;
609
- if (o.assignment) outcome.assignment = o.assignment;
610
- return outcome;
611
- });
612
- const outcomes = {
613
- computed_outcomes: computedOutcomes,
614
- comparison_layout: {
615
- primary_card: computedOutcomes.find((o) => o.primary)?.id ?? computedOutcomes[0]?.id ?? "",
616
- status_badge: "viability_status",
617
- structural_indicators: rules.filter((r) => r.severity === "structural").map((r) => r.id)
618
- }
619
- };
620
- const metadata = {
621
- format_version: "1.0.0",
622
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
623
- last_modified: (/* @__PURE__ */ new Date()).toISOString(),
624
- authoring_method: "manual-authoring"
625
- };
626
- const worldDefinition = {
627
- world,
628
- invariants,
629
- assumptions,
630
- stateSchema,
631
- rules,
632
- gates,
633
- outcomes,
634
- metadata
635
- };
636
- return { world: worldDefinition, issues };
637
- }
638
-
639
- export {
640
- parseWorldMarkdown,
641
- emitWorldDefinition
642
- };
@@ -1,9 +0,0 @@
1
- var __glob = (map) => (path) => {
2
- var fn = map[path];
3
- if (fn) return fn();
4
- throw new Error("Module not found in bundle: " + path);
5
- };
6
-
7
- export {
8
- __glob
9
- };