@neuroverseos/governance 0.3.0 → 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.
- package/README.md +20 -0
- package/package.json +16 -3
- package/policies/content-moderation-rules.txt +8 -0
- package/policies/marketing-rules.txt +8 -0
- package/policies/science-research-rules.txt +11 -0
- package/policies/social-media-rules.txt +7 -0
- package/policies/strict-rules.txt +8 -0
- package/policies/trading-rules.txt +8 -0
- package/simulate.html +1899 -0
- package/dist/adapters/autoresearch.cjs +0 -196
- package/dist/adapters/autoresearch.d.cts +0 -103
- package/dist/adapters/autoresearch.d.ts +0 -103
- package/dist/adapters/autoresearch.js +0 -7
- package/dist/adapters/express.cjs +0 -1114
- package/dist/adapters/express.d.cts +0 -66
- package/dist/adapters/express.d.ts +0 -66
- package/dist/adapters/express.js +0 -12
- package/dist/adapters/index.cjs +0 -1669
- package/dist/adapters/index.d.cts +0 -6
- package/dist/adapters/index.d.ts +0 -6
- package/dist/adapters/index.js +0 -46
- package/dist/adapters/langchain.cjs +0 -1155
- package/dist/adapters/langchain.d.cts +0 -89
- package/dist/adapters/langchain.d.ts +0 -89
- package/dist/adapters/langchain.js +0 -16
- package/dist/adapters/openai.cjs +0 -1185
- package/dist/adapters/openai.d.cts +0 -99
- package/dist/adapters/openai.d.ts +0 -99
- package/dist/adapters/openai.js +0 -16
- package/dist/adapters/openclaw.cjs +0 -1177
- package/dist/adapters/openclaw.d.cts +0 -99
- package/dist/adapters/openclaw.d.ts +0 -99
- package/dist/adapters/openclaw.js +0 -16
- package/dist/bootstrap-GXVDZNF7.js +0 -114
- package/dist/build-P42YFKQV.js +0 -339
- package/dist/chunk-2NICNKOM.js +0 -100
- package/dist/chunk-2PQU3VAN.js +0 -131
- package/dist/chunk-4A7LISES.js +0 -324
- package/dist/chunk-4JRYGIO7.js +0 -727
- package/dist/chunk-4NGDRRQH.js +0 -10
- package/dist/chunk-4QXB6PEO.js +0 -232
- package/dist/chunk-6CZSKEY5.js +0 -164
- package/dist/chunk-7P3S7MAY.js +0 -1090
- package/dist/chunk-A5W4GNQO.js +0 -130
- package/dist/chunk-AKW5YVCE.js +0 -96
- package/dist/chunk-BUWWN2NX.js +0 -192
- package/dist/chunk-COT5XS4V.js +0 -109
- package/dist/chunk-ER62HNGF.js +0 -139
- package/dist/chunk-FYS2CBUW.js +0 -304
- package/dist/chunk-GR6DGCZ2.js +0 -340
- package/dist/chunk-I3RRAYK2.js +0 -11
- package/dist/chunk-JZPQGIKR.js +0 -79
- package/dist/chunk-MWDQ4MJB.js +0 -11
- package/dist/chunk-NF5POFCI.js +0 -622
- package/dist/chunk-OGL7QXZS.js +0 -608
- package/dist/chunk-OT6PXH54.js +0 -61
- package/dist/chunk-PDOZHZWL.js +0 -225
- package/dist/chunk-Q6O7ZLO2.js +0 -62
- package/dist/chunk-QPASI2BR.js +0 -187
- package/dist/chunk-T5EUJQE5.js +0 -172
- package/dist/chunk-XPDMYECO.js +0 -642
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/cli/neuroverse.cjs +0 -11448
- package/dist/cli/neuroverse.d.cts +0 -1
- package/dist/cli/neuroverse.d.ts +0 -1
- package/dist/cli/neuroverse.js +0 -196
- package/dist/cli/plan.cjs +0 -1599
- package/dist/cli/plan.d.cts +0 -20
- package/dist/cli/plan.d.ts +0 -20
- package/dist/cli/plan.js +0 -361
- package/dist/cli/run.cjs +0 -1746
- package/dist/cli/run.d.cts +0 -20
- package/dist/cli/run.d.ts +0 -20
- package/dist/cli/run.js +0 -143
- package/dist/configure-ai-TK67ZWZL.js +0 -132
- package/dist/derive-TLIV4OOU.js +0 -152
- package/dist/doctor-XPDLEYXN.js +0 -171
- package/dist/explain-IDCRWMPX.js +0 -70
- package/dist/guard-RV65TT4L.js +0 -96
- package/dist/guard-contract-WZx__PmU.d.cts +0 -709
- package/dist/guard-contract-WZx__PmU.d.ts +0 -709
- package/dist/guard-engine-JLTUARGU.js +0 -10
- package/dist/impact-XPECYRLH.js +0 -59
- package/dist/improve-GPUBKTEA.js +0 -85
- package/dist/index.cjs +0 -6273
- package/dist/index.d.cts +0 -1616
- package/dist/index.d.ts +0 -1616
- package/dist/index.js +0 -379
- package/dist/infer-world-7GVZWFX4.js +0 -543
- package/dist/init-PKPIYHYE.js +0 -144
- package/dist/init-world-VWMQZQC7.js +0 -223
- package/dist/mcp-server-FPVSU32Z.js +0 -13
- package/dist/model-adapter-BB7G4MFI.js +0 -11
- package/dist/playground-E664U4T6.js +0 -550
- package/dist/redteam-Z7WREJ44.js +0 -357
- package/dist/session-EKTRSR7C.js +0 -14
- package/dist/simulate-VDOYQFRO.js +0 -108
- package/dist/test-OGXJK4QU.js +0 -217
- package/dist/trace-JVF67VR3.js +0 -166
- package/dist/validate-LLBWVPGV.js +0 -81
- package/dist/validate-engine-UIABSIHD.js +0 -7
- package/dist/world-LAXO6DOX.js +0 -378
- package/dist/world-loader-HMPTOEA2.js +0 -9
- package/dist/worlds/autoresearch.nv-world.md +0 -230
- package/dist/worlds/derivation-world.nv-world.md +0 -278
package/dist/chunk-XPDMYECO.js
DELETED
|
@@ -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
|
-
};
|