@plures/praxis 1.1.3 → 1.2.10
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/FRAMEWORK.md +106 -15
- package/README.md +194 -119
- package/dist/browser/adapter-CIMBGDC7.js +14 -0
- package/dist/browser/chunk-K377RW4V.js +230 -0
- package/dist/browser/chunk-MBVHLOU2.js +152 -0
- package/dist/browser/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
- package/dist/browser/engine-YJZV4SLD.js +8 -0
- package/dist/browser/index.d.ts +161 -5
- package/dist/browser/index.js +156 -141
- package/dist/browser/integrations/svelte.d.ts +2 -2
- package/dist/browser/integrations/svelte.js +2 -1
- package/dist/browser/{reactive-engine.svelte-C9OpcTHf.d.ts → reactive-engine.svelte-9aS0kTa8.d.ts} +136 -1
- package/dist/node/adapter-75ISSMWD.js +15 -0
- package/dist/node/chunk-5RH7UAQC.js +486 -0
- package/dist/node/chunk-MBVHLOU2.js +152 -0
- package/dist/node/chunk-PRPQO6R5.js +85 -0
- package/dist/node/chunk-R2PSBPKQ.js +150 -0
- package/dist/node/chunk-S54337I5.js +446 -0
- package/dist/node/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
- package/dist/node/chunk-WZ6B3LZ6.js +638 -0
- package/dist/node/cli/index.cjs +2936 -897
- package/dist/node/cli/index.js +27 -0
- package/dist/node/components/index.d.cts +3 -2
- package/dist/node/components/index.d.ts +3 -2
- package/dist/node/docs-JFNYTOJA.js +102 -0
- package/dist/node/engine-2DQBKBJC.js +9 -0
- package/dist/node/index.cjs +1114 -354
- package/dist/node/index.d.cts +388 -5
- package/dist/node/index.d.ts +388 -5
- package/dist/node/index.js +201 -640
- package/dist/node/integrations/svelte.cjs +76 -0
- package/dist/node/integrations/svelte.d.cts +2 -2
- package/dist/node/integrations/svelte.d.ts +2 -2
- package/dist/node/integrations/svelte.js +3 -1
- package/dist/node/{reactive-engine.svelte-1M4m_C_v.d.cts → reactive-engine.svelte-BFIZfawz.d.cts} +199 -1
- package/dist/node/{reactive-engine.svelte-ChNFn4Hj.d.ts → reactive-engine.svelte-CRNqHlbv.d.ts} +199 -1
- package/dist/node/reverse-W7THPV45.js +193 -0
- package/dist/node/{terminal-adapter-CWka-yL8.d.ts → terminal-adapter-B-UK_Vdz.d.ts} +28 -3
- package/dist/node/{terminal-adapter-CDzxoLKR.d.cts → terminal-adapter-BQSIF5bf.d.cts} +28 -3
- package/dist/node/validate-CNHUULQE.js +180 -0
- package/docs/core/pluresdb-integration.md +15 -15
- package/docs/decision-ledger/BEHAVIOR_LEDGER.md +225 -0
- package/docs/decision-ledger/DecisionLedger.tla +180 -0
- package/docs/decision-ledger/IMPLEMENTATION_SUMMARY.md +217 -0
- package/docs/decision-ledger/LATEST.md +166 -0
- package/docs/guides/cicd-pipeline.md +142 -0
- package/package.json +2 -2
- package/src/__tests__/cli-validate.test.ts +197 -0
- package/src/__tests__/decision-ledger.test.ts +485 -0
- package/src/__tests__/reverse-generator.test.ts +189 -0
- package/src/__tests__/scanner.test.ts +215 -0
- package/src/cli/commands/docs.ts +147 -0
- package/src/cli/commands/reverse.ts +289 -0
- package/src/cli/commands/validate.ts +264 -0
- package/src/cli/index.ts +68 -0
- package/src/core/pluresdb/adapter.ts +46 -3
- package/src/core/reactive-engine.svelte.ts +6 -1
- package/src/core/reactive-engine.ts +1 -1
- package/src/core/rules.ts +133 -0
- package/src/decision-ledger/README.md +400 -0
- package/src/decision-ledger/REVERSE_ENGINEERING.md +484 -0
- package/src/decision-ledger/facts-events.ts +121 -0
- package/src/decision-ledger/index.ts +70 -0
- package/src/decision-ledger/ledger.ts +246 -0
- package/src/decision-ledger/logic-ledger.ts +158 -0
- package/src/decision-ledger/reverse-generator.ts +426 -0
- package/src/decision-ledger/scanner.ts +506 -0
- package/src/decision-ledger/types.ts +247 -0
- package/src/decision-ledger/validation.ts +336 -0
- package/src/dsl/index.ts +13 -2
- package/src/index.browser.ts +6 -0
- package/src/index.ts +40 -0
- package/src/integrations/pluresdb.ts +14 -2
- package/src/integrations/unified.ts +350 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
// src/integrations/state-docs.ts
|
|
2
|
+
var StateDocsGenerator = class {
|
|
3
|
+
config;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = {
|
|
6
|
+
target: "./docs",
|
|
7
|
+
globs: ["**/*.ts", "**/*.js"],
|
|
8
|
+
visualization: {
|
|
9
|
+
format: "mermaid",
|
|
10
|
+
exportPng: false,
|
|
11
|
+
theme: "default"
|
|
12
|
+
},
|
|
13
|
+
template: {
|
|
14
|
+
toc: true,
|
|
15
|
+
timestamp: true
|
|
16
|
+
},
|
|
17
|
+
...config
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate documentation from a Praxis schema
|
|
22
|
+
*/
|
|
23
|
+
generateFromSchema(schema) {
|
|
24
|
+
const docs = [];
|
|
25
|
+
docs.push(this.generateSchemaReadme(schema));
|
|
26
|
+
if (schema.models && schema.models.length > 0) {
|
|
27
|
+
docs.push(this.generateModelsDoc(schema));
|
|
28
|
+
}
|
|
29
|
+
if (schema.components && schema.components.length > 0) {
|
|
30
|
+
docs.push(this.generateComponentsDoc(schema));
|
|
31
|
+
}
|
|
32
|
+
if (schema.logic && schema.logic.length > 0) {
|
|
33
|
+
for (const logic of schema.logic) {
|
|
34
|
+
docs.push(this.generateLogicDoc(logic));
|
|
35
|
+
docs.push(this.generateLogicDiagram(logic));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return docs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generate documentation from a Praxis registry
|
|
42
|
+
*/
|
|
43
|
+
generateFromModule(module) {
|
|
44
|
+
const docs = [];
|
|
45
|
+
const rules = module.rules;
|
|
46
|
+
const constraints = module.constraints;
|
|
47
|
+
docs.push(this.generateRulesDoc(rules));
|
|
48
|
+
docs.push(this.generateConstraintsDoc(constraints));
|
|
49
|
+
docs.push(this.generateRegistryDiagram(rules, constraints));
|
|
50
|
+
return docs;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate the main schema README
|
|
54
|
+
*/
|
|
55
|
+
generateSchemaReadme(schema) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
if (this.config.template?.header) {
|
|
58
|
+
lines.push(this.config.template.header);
|
|
59
|
+
lines.push("");
|
|
60
|
+
}
|
|
61
|
+
lines.push(`# ${schema.name || this.config.projectTitle}`);
|
|
62
|
+
lines.push("");
|
|
63
|
+
if (schema.description) {
|
|
64
|
+
lines.push(schema.description);
|
|
65
|
+
lines.push("");
|
|
66
|
+
}
|
|
67
|
+
if (this.config.template?.toc) {
|
|
68
|
+
lines.push("## Table of Contents");
|
|
69
|
+
lines.push("");
|
|
70
|
+
lines.push("- [Overview](#overview)");
|
|
71
|
+
if (schema.models && schema.models.length > 0) {
|
|
72
|
+
lines.push("- [Models](#models)");
|
|
73
|
+
}
|
|
74
|
+
if (schema.components && schema.components.length > 0) {
|
|
75
|
+
lines.push("- [Components](#components)");
|
|
76
|
+
}
|
|
77
|
+
if (schema.logic && schema.logic.length > 0) {
|
|
78
|
+
lines.push("- [Logic](#logic)");
|
|
79
|
+
}
|
|
80
|
+
lines.push("");
|
|
81
|
+
}
|
|
82
|
+
lines.push("## Overview");
|
|
83
|
+
lines.push("");
|
|
84
|
+
lines.push(`**Version:** ${schema.version}`);
|
|
85
|
+
lines.push("");
|
|
86
|
+
lines.push("### Statistics");
|
|
87
|
+
lines.push("");
|
|
88
|
+
lines.push("| Category | Count |");
|
|
89
|
+
lines.push("|----------|-------|");
|
|
90
|
+
lines.push(`| Models | ${schema.models?.length || 0} |`);
|
|
91
|
+
lines.push(`| Components | ${schema.components?.length || 0} |`);
|
|
92
|
+
lines.push(`| Logic Modules | ${schema.logic?.length || 0} |`);
|
|
93
|
+
lines.push("");
|
|
94
|
+
if (schema.models && schema.models.length > 0) {
|
|
95
|
+
lines.push("## Models");
|
|
96
|
+
lines.push("");
|
|
97
|
+
for (const model of schema.models) {
|
|
98
|
+
lines.push(`### ${model.name}`);
|
|
99
|
+
lines.push("");
|
|
100
|
+
if (model.description) {
|
|
101
|
+
lines.push(model.description);
|
|
102
|
+
lines.push("");
|
|
103
|
+
}
|
|
104
|
+
lines.push("**Fields:**");
|
|
105
|
+
lines.push("");
|
|
106
|
+
lines.push("| Name | Type | Required |");
|
|
107
|
+
lines.push("|------|------|----------|");
|
|
108
|
+
for (const field of model.fields) {
|
|
109
|
+
const required = field.optional ? "No" : "Yes";
|
|
110
|
+
lines.push(`| ${field.name} | ${field.type} | ${required} |`);
|
|
111
|
+
}
|
|
112
|
+
lines.push("");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (schema.components && schema.components.length > 0) {
|
|
116
|
+
lines.push("## Components");
|
|
117
|
+
lines.push("");
|
|
118
|
+
for (const component of schema.components) {
|
|
119
|
+
lines.push(`### ${component.name}`);
|
|
120
|
+
lines.push("");
|
|
121
|
+
lines.push(`**Type:** ${component.type}`);
|
|
122
|
+
lines.push("");
|
|
123
|
+
if (component.description) {
|
|
124
|
+
lines.push(component.description);
|
|
125
|
+
lines.push("");
|
|
126
|
+
}
|
|
127
|
+
if (component.model) {
|
|
128
|
+
lines.push(`**Model:** ${component.model}`);
|
|
129
|
+
lines.push("");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (schema.logic && schema.logic.length > 0) {
|
|
134
|
+
lines.push("## Logic");
|
|
135
|
+
lines.push("");
|
|
136
|
+
for (const logic of schema.logic) {
|
|
137
|
+
lines.push(`### ${logic.id}`);
|
|
138
|
+
lines.push("");
|
|
139
|
+
if (logic.description) {
|
|
140
|
+
lines.push(logic.description);
|
|
141
|
+
lines.push("");
|
|
142
|
+
}
|
|
143
|
+
if (logic.events && logic.events.length > 0) {
|
|
144
|
+
lines.push("**Events:**");
|
|
145
|
+
lines.push("");
|
|
146
|
+
for (const event of logic.events) {
|
|
147
|
+
lines.push(`- \`${event.tag}\`: ${event.description || ""}`);
|
|
148
|
+
}
|
|
149
|
+
lines.push("");
|
|
150
|
+
}
|
|
151
|
+
if (logic.facts && logic.facts.length > 0) {
|
|
152
|
+
lines.push("**Facts:**");
|
|
153
|
+
lines.push("");
|
|
154
|
+
for (const fact of logic.facts) {
|
|
155
|
+
lines.push(`- \`${fact.tag}\`: ${fact.description || ""}`);
|
|
156
|
+
}
|
|
157
|
+
lines.push("");
|
|
158
|
+
}
|
|
159
|
+
if (logic.rules && logic.rules.length > 0) {
|
|
160
|
+
lines.push("**Rules:**");
|
|
161
|
+
lines.push("");
|
|
162
|
+
for (const rule of logic.rules) {
|
|
163
|
+
lines.push(`- \`${rule.id}\`: ${rule.description || ""}`);
|
|
164
|
+
}
|
|
165
|
+
lines.push("");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (this.config.template?.timestamp) {
|
|
170
|
+
lines.push("---");
|
|
171
|
+
lines.push("");
|
|
172
|
+
lines.push(`*Generated on ${(/* @__PURE__ */ new Date()).toISOString()} by State-Docs*`);
|
|
173
|
+
}
|
|
174
|
+
if (this.config.template?.footer) {
|
|
175
|
+
lines.push("");
|
|
176
|
+
lines.push(this.config.template.footer);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
path: `${this.config.target}/README.md`,
|
|
180
|
+
content: lines.join("\n"),
|
|
181
|
+
type: "markdown"
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Generate models documentation
|
|
186
|
+
*/
|
|
187
|
+
generateModelsDoc(schema) {
|
|
188
|
+
const lines = [
|
|
189
|
+
"# Models",
|
|
190
|
+
"",
|
|
191
|
+
"This document describes all data models defined in the schema.",
|
|
192
|
+
""
|
|
193
|
+
];
|
|
194
|
+
if (schema.models) {
|
|
195
|
+
for (const model of schema.models) {
|
|
196
|
+
lines.push(`## ${model.name}`);
|
|
197
|
+
lines.push("");
|
|
198
|
+
if (model.description) {
|
|
199
|
+
lines.push(model.description);
|
|
200
|
+
lines.push("");
|
|
201
|
+
}
|
|
202
|
+
lines.push("### Fields");
|
|
203
|
+
lines.push("");
|
|
204
|
+
lines.push("| Name | Type | Required | Description |");
|
|
205
|
+
lines.push("|------|------|----------|-------------|");
|
|
206
|
+
for (const field of model.fields) {
|
|
207
|
+
const required = field.optional ? "No" : "Yes";
|
|
208
|
+
const description = field.description || "-";
|
|
209
|
+
lines.push(`| ${field.name} | \`${field.type}\` | ${required} | ${description} |`);
|
|
210
|
+
}
|
|
211
|
+
lines.push("");
|
|
212
|
+
if (model.indexes && model.indexes.length > 0) {
|
|
213
|
+
lines.push("### Indexes");
|
|
214
|
+
lines.push("");
|
|
215
|
+
for (const index of model.indexes) {
|
|
216
|
+
lines.push(`- **${index.name}**: \`${index.fields.join(", ")}\``);
|
|
217
|
+
}
|
|
218
|
+
lines.push("");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
path: `${this.config.target}/models.md`,
|
|
224
|
+
content: lines.join("\n"),
|
|
225
|
+
type: "markdown"
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Generate components documentation
|
|
230
|
+
*/
|
|
231
|
+
generateComponentsDoc(schema) {
|
|
232
|
+
const lines = [
|
|
233
|
+
"# Components",
|
|
234
|
+
"",
|
|
235
|
+
"This document describes all UI components defined in the schema.",
|
|
236
|
+
""
|
|
237
|
+
];
|
|
238
|
+
if (schema.components) {
|
|
239
|
+
for (const component of schema.components) {
|
|
240
|
+
lines.push(`## ${component.name}`);
|
|
241
|
+
lines.push("");
|
|
242
|
+
lines.push(`**Type:** ${component.type}`);
|
|
243
|
+
lines.push("");
|
|
244
|
+
if (component.description) {
|
|
245
|
+
lines.push(component.description);
|
|
246
|
+
lines.push("");
|
|
247
|
+
}
|
|
248
|
+
if (component.model) {
|
|
249
|
+
lines.push(
|
|
250
|
+
`**Associated Model:** [${component.model}](./models.md#${component.model.toLowerCase()})`
|
|
251
|
+
);
|
|
252
|
+
lines.push("");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
path: `${this.config.target}/components.md`,
|
|
258
|
+
content: lines.join("\n"),
|
|
259
|
+
type: "markdown"
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Generate logic documentation
|
|
264
|
+
*/
|
|
265
|
+
generateLogicDoc(logic) {
|
|
266
|
+
const lines = [`# ${logic.id}`, ""];
|
|
267
|
+
if (logic.description) {
|
|
268
|
+
lines.push(logic.description);
|
|
269
|
+
lines.push("");
|
|
270
|
+
}
|
|
271
|
+
if (logic.events && logic.events.length > 0) {
|
|
272
|
+
lines.push("## Events");
|
|
273
|
+
lines.push("");
|
|
274
|
+
lines.push("| Event | Description | Payload |");
|
|
275
|
+
lines.push("|-------|-------------|---------|");
|
|
276
|
+
for (const event of logic.events) {
|
|
277
|
+
const payload = event.payload ? Object.entries(event.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
|
|
278
|
+
lines.push(`| \`${event.tag}\` | ${event.description || "-"} | ${payload} |`);
|
|
279
|
+
}
|
|
280
|
+
lines.push("");
|
|
281
|
+
}
|
|
282
|
+
if (logic.facts && logic.facts.length > 0) {
|
|
283
|
+
lines.push("## Facts");
|
|
284
|
+
lines.push("");
|
|
285
|
+
lines.push("| Fact | Description | Payload |");
|
|
286
|
+
lines.push("|------|-------------|---------|");
|
|
287
|
+
for (const fact of logic.facts) {
|
|
288
|
+
const payload = fact.payload ? Object.entries(fact.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
|
|
289
|
+
lines.push(`| \`${fact.tag}\` | ${fact.description || "-"} | ${payload} |`);
|
|
290
|
+
}
|
|
291
|
+
lines.push("");
|
|
292
|
+
}
|
|
293
|
+
if (logic.rules && logic.rules.length > 0) {
|
|
294
|
+
lines.push("## Rules");
|
|
295
|
+
lines.push("");
|
|
296
|
+
for (const rule of logic.rules) {
|
|
297
|
+
lines.push(`### ${rule.id}`);
|
|
298
|
+
lines.push("");
|
|
299
|
+
if (rule.description) {
|
|
300
|
+
lines.push(rule.description);
|
|
301
|
+
lines.push("");
|
|
302
|
+
}
|
|
303
|
+
if (rule.priority !== void 0) {
|
|
304
|
+
lines.push(`**Priority:** ${rule.priority}`);
|
|
305
|
+
lines.push("");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (logic.constraints && logic.constraints.length > 0) {
|
|
310
|
+
lines.push("## Constraints");
|
|
311
|
+
lines.push("");
|
|
312
|
+
for (const constraint of logic.constraints) {
|
|
313
|
+
lines.push(`### ${constraint.id}`);
|
|
314
|
+
lines.push("");
|
|
315
|
+
if (constraint.description) {
|
|
316
|
+
lines.push(constraint.description);
|
|
317
|
+
lines.push("");
|
|
318
|
+
}
|
|
319
|
+
if (constraint.message) {
|
|
320
|
+
lines.push(`**Error Message:** ${constraint.message}`);
|
|
321
|
+
lines.push("");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
path: `${this.config.target}/logic/${logic.id}.md`,
|
|
327
|
+
content: lines.join("\n"),
|
|
328
|
+
type: "markdown"
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Generate Mermaid diagram for logic
|
|
333
|
+
*/
|
|
334
|
+
generateLogicDiagram(logic) {
|
|
335
|
+
const lines = ["stateDiagram-v2"];
|
|
336
|
+
if (logic.events && logic.facts) {
|
|
337
|
+
lines.push(" [*] --> Processing");
|
|
338
|
+
for (const event of logic.events) {
|
|
339
|
+
lines.push(` Processing --> ${event.tag.replace(/[^a-zA-Z0-9]/g, "")}: ${event.tag}`);
|
|
340
|
+
}
|
|
341
|
+
for (const fact of logic.facts) {
|
|
342
|
+
lines.push(` ${fact.tag.replace(/[^a-zA-Z0-9]/g, "")} --> [*]`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
path: `${this.config.target}/logic/${logic.id}.mmd`,
|
|
347
|
+
content: lines.join("\n"),
|
|
348
|
+
type: "mermaid"
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Generate rules documentation
|
|
353
|
+
*/
|
|
354
|
+
generateRulesDoc(rules) {
|
|
355
|
+
const lines = [
|
|
356
|
+
"# Rules",
|
|
357
|
+
"",
|
|
358
|
+
"This document describes all rules registered in the Praxis engine.",
|
|
359
|
+
""
|
|
360
|
+
];
|
|
361
|
+
for (const rule of rules) {
|
|
362
|
+
lines.push(`## ${rule.id}`);
|
|
363
|
+
lines.push("");
|
|
364
|
+
if (rule.description) {
|
|
365
|
+
lines.push(rule.description);
|
|
366
|
+
lines.push("");
|
|
367
|
+
}
|
|
368
|
+
if (rule.meta?.eventType) {
|
|
369
|
+
lines.push(`**Triggers on:** \`${rule.meta.eventType}\``);
|
|
370
|
+
lines.push("");
|
|
371
|
+
}
|
|
372
|
+
if (rule.meta?.priority !== void 0) {
|
|
373
|
+
lines.push(`**Priority:** ${rule.meta.priority}`);
|
|
374
|
+
lines.push("");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
path: `${this.config.target}/rules.md`,
|
|
379
|
+
content: lines.join("\n"),
|
|
380
|
+
type: "markdown"
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Generate constraints documentation
|
|
385
|
+
*/
|
|
386
|
+
generateConstraintsDoc(constraints) {
|
|
387
|
+
const lines = [
|
|
388
|
+
"# Constraints",
|
|
389
|
+
"",
|
|
390
|
+
"This document describes all constraints (invariants) registered in the Praxis engine.",
|
|
391
|
+
""
|
|
392
|
+
];
|
|
393
|
+
for (const constraint of constraints) {
|
|
394
|
+
lines.push(`## ${constraint.id}`);
|
|
395
|
+
lines.push("");
|
|
396
|
+
if (constraint.description) {
|
|
397
|
+
lines.push(constraint.description);
|
|
398
|
+
lines.push("");
|
|
399
|
+
}
|
|
400
|
+
if (constraint.meta?.errorMessage) {
|
|
401
|
+
lines.push(`**Error Message:** ${constraint.meta.errorMessage}`);
|
|
402
|
+
lines.push("");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
path: `${this.config.target}/constraints.md`,
|
|
407
|
+
content: lines.join("\n"),
|
|
408
|
+
type: "markdown"
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Generate state diagram from registry
|
|
413
|
+
*/
|
|
414
|
+
generateRegistryDiagram(rules, constraints) {
|
|
415
|
+
const lines = ["graph TD", " subgraph Rules"];
|
|
416
|
+
for (const rule of rules) {
|
|
417
|
+
const id = rule.id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
418
|
+
lines.push(` ${id}["${rule.id}"]`);
|
|
419
|
+
}
|
|
420
|
+
lines.push(" end");
|
|
421
|
+
lines.push(" subgraph Constraints");
|
|
422
|
+
for (const constraint of constraints) {
|
|
423
|
+
const id = constraint.id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
424
|
+
lines.push(` ${id}["${constraint.id}"]`);
|
|
425
|
+
}
|
|
426
|
+
lines.push(" end");
|
|
427
|
+
return {
|
|
428
|
+
path: `${this.config.target}/state-diagram.mmd`,
|
|
429
|
+
content: lines.join("\n"),
|
|
430
|
+
type: "mermaid"
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
function createStateDocsGenerator(config) {
|
|
435
|
+
return new StateDocsGenerator(config);
|
|
436
|
+
}
|
|
437
|
+
function generateDocs(schema, config) {
|
|
438
|
+
const generator = createStateDocsGenerator(config);
|
|
439
|
+
return generator.generateFromSchema(schema);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export {
|
|
443
|
+
StateDocsGenerator,
|
|
444
|
+
createStateDocsGenerator,
|
|
445
|
+
generateDocs
|
|
446
|
+
};
|
|
@@ -1,77 +1,6 @@
|
|
|
1
1
|
// src/core/protocol.ts
|
|
2
2
|
var PRAXIS_PROTOCOL_VERSION = "1.0.0";
|
|
3
3
|
|
|
4
|
-
// src/core/rules.ts
|
|
5
|
-
var PraxisRegistry = class {
|
|
6
|
-
rules = /* @__PURE__ */ new Map();
|
|
7
|
-
constraints = /* @__PURE__ */ new Map();
|
|
8
|
-
/**
|
|
9
|
-
* Register a rule
|
|
10
|
-
*/
|
|
11
|
-
registerRule(descriptor) {
|
|
12
|
-
if (this.rules.has(descriptor.id)) {
|
|
13
|
-
throw new Error(`Rule with id "${descriptor.id}" already registered`);
|
|
14
|
-
}
|
|
15
|
-
this.rules.set(descriptor.id, descriptor);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Register a constraint
|
|
19
|
-
*/
|
|
20
|
-
registerConstraint(descriptor) {
|
|
21
|
-
if (this.constraints.has(descriptor.id)) {
|
|
22
|
-
throw new Error(`Constraint with id "${descriptor.id}" already registered`);
|
|
23
|
-
}
|
|
24
|
-
this.constraints.set(descriptor.id, descriptor);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Register a module (all its rules and constraints)
|
|
28
|
-
*/
|
|
29
|
-
registerModule(module) {
|
|
30
|
-
for (const rule of module.rules) {
|
|
31
|
-
this.registerRule(rule);
|
|
32
|
-
}
|
|
33
|
-
for (const constraint of module.constraints) {
|
|
34
|
-
this.registerConstraint(constraint);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get a rule by ID
|
|
39
|
-
*/
|
|
40
|
-
getRule(id) {
|
|
41
|
-
return this.rules.get(id);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get a constraint by ID
|
|
45
|
-
*/
|
|
46
|
-
getConstraint(id) {
|
|
47
|
-
return this.constraints.get(id);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get all registered rule IDs
|
|
51
|
-
*/
|
|
52
|
-
getRuleIds() {
|
|
53
|
-
return Array.from(this.rules.keys());
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get all registered constraint IDs
|
|
57
|
-
*/
|
|
58
|
-
getConstraintIds() {
|
|
59
|
-
return Array.from(this.constraints.keys());
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get all rules
|
|
63
|
-
*/
|
|
64
|
-
getAllRules() {
|
|
65
|
-
return Array.from(this.rules.values());
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Get all constraints
|
|
69
|
-
*/
|
|
70
|
-
getAllConstraints() {
|
|
71
|
-
return Array.from(this.constraints.values());
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
4
|
// src/core/engine.ts
|
|
76
5
|
function safeClone(value) {
|
|
77
6
|
if (value === null || typeof value !== "object") {
|
|
@@ -261,85 +190,8 @@ function createPraxisEngine(options) {
|
|
|
261
190
|
return new LogicEngine(options);
|
|
262
191
|
}
|
|
263
192
|
|
|
264
|
-
// src/core/reactive-engine.svelte.ts
|
|
265
|
-
import * as $ from "svelte/internal/client";
|
|
266
|
-
var ReactiveLogicEngine = class {
|
|
267
|
-
#state = (
|
|
268
|
-
// Use Svelte's $state rune for automatic reactivity
|
|
269
|
-
$.state($.proxy({ context: {}, facts: [], meta: {} }))
|
|
270
|
-
);
|
|
271
|
-
get state() {
|
|
272
|
-
return $.get(this.#state);
|
|
273
|
-
}
|
|
274
|
-
set state(value) {
|
|
275
|
-
$.set(this.#state, value, true);
|
|
276
|
-
}
|
|
277
|
-
_engine;
|
|
278
|
-
constructor(options) {
|
|
279
|
-
this.state.context = options.initialContext;
|
|
280
|
-
this.state.facts = options.initialFacts ?? [];
|
|
281
|
-
this.state.meta = options.initialMeta ?? {};
|
|
282
|
-
if (options.registry) {
|
|
283
|
-
this._engine = createPraxisEngine({
|
|
284
|
-
initialContext: options.initialContext,
|
|
285
|
-
registry: options.registry
|
|
286
|
-
});
|
|
287
|
-
} else {
|
|
288
|
-
this._engine = createPraxisEngine({
|
|
289
|
-
initialContext: options.initialContext,
|
|
290
|
-
registry: new PraxisRegistry()
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Access the reactive context.
|
|
296
|
-
* In Svelte 5 components, changes to this object will automatically trigger updates.
|
|
297
|
-
*/
|
|
298
|
-
get context() {
|
|
299
|
-
return this.state.context;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Access the reactive facts list.
|
|
303
|
-
*/
|
|
304
|
-
get facts() {
|
|
305
|
-
return this.state.facts;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Access the reactive metadata.
|
|
309
|
-
*/
|
|
310
|
-
get meta() {
|
|
311
|
-
return this.state.meta;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Apply a mutation to the state.
|
|
315
|
-
* Changes will automatically trigger Svelte reactivity.
|
|
316
|
-
*
|
|
317
|
-
* @param mutator A function that receives the state and modifies it.
|
|
318
|
-
*/
|
|
319
|
-
apply(mutator) {
|
|
320
|
-
mutator(this.state);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Process events through the logic engine and update reactive state.
|
|
324
|
-
*
|
|
325
|
-
* @param events Events to process
|
|
326
|
-
*/
|
|
327
|
-
step(events) {
|
|
328
|
-
const result = this._engine.step(events);
|
|
329
|
-
this.state.context = result.state.context;
|
|
330
|
-
this.state.facts = result.state.facts;
|
|
331
|
-
this.state.meta = result.state.meta ?? {};
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
function createReactiveEngine(options) {
|
|
335
|
-
return new ReactiveLogicEngine(options);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
193
|
export {
|
|
339
194
|
PRAXIS_PROTOCOL_VERSION,
|
|
340
|
-
PraxisRegistry,
|
|
341
195
|
LogicEngine,
|
|
342
|
-
createPraxisEngine
|
|
343
|
-
ReactiveLogicEngine,
|
|
344
|
-
createReactiveEngine
|
|
196
|
+
createPraxisEngine
|
|
345
197
|
};
|