@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.
Files changed (74) hide show
  1. package/FRAMEWORK.md +106 -15
  2. package/README.md +194 -119
  3. package/dist/browser/adapter-CIMBGDC7.js +14 -0
  4. package/dist/browser/chunk-K377RW4V.js +230 -0
  5. package/dist/browser/chunk-MBVHLOU2.js +152 -0
  6. package/dist/browser/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
  7. package/dist/browser/engine-YJZV4SLD.js +8 -0
  8. package/dist/browser/index.d.ts +161 -5
  9. package/dist/browser/index.js +156 -141
  10. package/dist/browser/integrations/svelte.d.ts +2 -2
  11. package/dist/browser/integrations/svelte.js +2 -1
  12. package/dist/browser/{reactive-engine.svelte-C9OpcTHf.d.ts → reactive-engine.svelte-9aS0kTa8.d.ts} +136 -1
  13. package/dist/node/adapter-75ISSMWD.js +15 -0
  14. package/dist/node/chunk-5RH7UAQC.js +486 -0
  15. package/dist/node/chunk-MBVHLOU2.js +152 -0
  16. package/dist/node/chunk-PRPQO6R5.js +85 -0
  17. package/dist/node/chunk-R2PSBPKQ.js +150 -0
  18. package/dist/node/chunk-S54337I5.js +446 -0
  19. package/dist/node/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
  20. package/dist/node/chunk-WZ6B3LZ6.js +638 -0
  21. package/dist/node/cli/index.cjs +2936 -897
  22. package/dist/node/cli/index.js +27 -0
  23. package/dist/node/components/index.d.cts +3 -2
  24. package/dist/node/components/index.d.ts +3 -2
  25. package/dist/node/docs-JFNYTOJA.js +102 -0
  26. package/dist/node/engine-2DQBKBJC.js +9 -0
  27. package/dist/node/index.cjs +1114 -354
  28. package/dist/node/index.d.cts +388 -5
  29. package/dist/node/index.d.ts +388 -5
  30. package/dist/node/index.js +201 -640
  31. package/dist/node/integrations/svelte.cjs +76 -0
  32. package/dist/node/integrations/svelte.d.cts +2 -2
  33. package/dist/node/integrations/svelte.d.ts +2 -2
  34. package/dist/node/integrations/svelte.js +3 -1
  35. package/dist/node/{reactive-engine.svelte-1M4m_C_v.d.cts → reactive-engine.svelte-BFIZfawz.d.cts} +199 -1
  36. package/dist/node/{reactive-engine.svelte-ChNFn4Hj.d.ts → reactive-engine.svelte-CRNqHlbv.d.ts} +199 -1
  37. package/dist/node/reverse-W7THPV45.js +193 -0
  38. package/dist/node/{terminal-adapter-CWka-yL8.d.ts → terminal-adapter-B-UK_Vdz.d.ts} +28 -3
  39. package/dist/node/{terminal-adapter-CDzxoLKR.d.cts → terminal-adapter-BQSIF5bf.d.cts} +28 -3
  40. package/dist/node/validate-CNHUULQE.js +180 -0
  41. package/docs/core/pluresdb-integration.md +15 -15
  42. package/docs/decision-ledger/BEHAVIOR_LEDGER.md +225 -0
  43. package/docs/decision-ledger/DecisionLedger.tla +180 -0
  44. package/docs/decision-ledger/IMPLEMENTATION_SUMMARY.md +217 -0
  45. package/docs/decision-ledger/LATEST.md +166 -0
  46. package/docs/guides/cicd-pipeline.md +142 -0
  47. package/package.json +2 -2
  48. package/src/__tests__/cli-validate.test.ts +197 -0
  49. package/src/__tests__/decision-ledger.test.ts +485 -0
  50. package/src/__tests__/reverse-generator.test.ts +189 -0
  51. package/src/__tests__/scanner.test.ts +215 -0
  52. package/src/cli/commands/docs.ts +147 -0
  53. package/src/cli/commands/reverse.ts +289 -0
  54. package/src/cli/commands/validate.ts +264 -0
  55. package/src/cli/index.ts +68 -0
  56. package/src/core/pluresdb/adapter.ts +46 -3
  57. package/src/core/reactive-engine.svelte.ts +6 -1
  58. package/src/core/reactive-engine.ts +1 -1
  59. package/src/core/rules.ts +133 -0
  60. package/src/decision-ledger/README.md +400 -0
  61. package/src/decision-ledger/REVERSE_ENGINEERING.md +484 -0
  62. package/src/decision-ledger/facts-events.ts +121 -0
  63. package/src/decision-ledger/index.ts +70 -0
  64. package/src/decision-ledger/ledger.ts +246 -0
  65. package/src/decision-ledger/logic-ledger.ts +158 -0
  66. package/src/decision-ledger/reverse-generator.ts +426 -0
  67. package/src/decision-ledger/scanner.ts +506 -0
  68. package/src/decision-ledger/types.ts +247 -0
  69. package/src/decision-ledger/validation.ts +336 -0
  70. package/src/dsl/index.ts +13 -2
  71. package/src/index.browser.ts +6 -0
  72. package/src/index.ts +40 -0
  73. package/src/integrations/pluresdb.ts +14 -2
  74. package/src/integrations/unified.ts +350 -0
@@ -1,3 +1,44 @@
1
+ import {
2
+ AcknowledgeContractGap,
3
+ BehaviorLedger,
4
+ ContractAdded,
5
+ ContractGapAcknowledged,
6
+ ContractMissing,
7
+ ContractUpdated,
8
+ ContractValidated,
9
+ ValidateContracts,
10
+ createBehaviorLedger,
11
+ defineConstraint,
12
+ defineEvent,
13
+ defineFact,
14
+ defineModule,
15
+ defineRule,
16
+ filterEvents,
17
+ filterFacts,
18
+ findEvent,
19
+ findFact,
20
+ formatValidationReport,
21
+ formatValidationReportJSON,
22
+ formatValidationReportSARIF,
23
+ validateContracts
24
+ } from "./chunk-5RH7UAQC.js";
25
+ import {
26
+ defineContract,
27
+ getContract,
28
+ isContract
29
+ } from "./chunk-WZ6B3LZ6.js";
30
+ import {
31
+ InMemoryPraxisDB,
32
+ PluresDBPraxisAdapter,
33
+ createInMemoryDB,
34
+ createPluresDB,
35
+ createPraxisLocalFirst
36
+ } from "./chunk-MBVHLOU2.js";
37
+ import {
38
+ StateDocsGenerator,
39
+ createStateDocsGenerator,
40
+ generateDocs
41
+ } from "./chunk-S54337I5.js";
1
42
  import {
2
43
  canvasToMermaid,
3
44
  canvasToSchema,
@@ -7,13 +48,12 @@ import {
7
48
  validateWithGuardian
8
49
  } from "./chunk-SRM3OPPM.js";
9
50
  import {
10
- LogicEngine,
11
- PRAXIS_PROTOCOL_VERSION,
12
- PraxisRegistry,
13
51
  ReactiveLogicEngine,
14
- createPraxisEngine,
15
52
  createReactiveEngine
16
- } from "./chunk-R45WXWKH.js";
53
+ } from "./chunk-PRPQO6R5.js";
54
+ import {
55
+ PraxisRegistry
56
+ } from "./chunk-R2PSBPKQ.js";
17
57
  import {
18
58
  TerminalAdapter,
19
59
  createMockExecutor,
@@ -35,6 +75,11 @@ import {
35
75
  createSchemaTemplate,
36
76
  validateSchema
37
77
  } from "./chunk-UATVJBNV.js";
78
+ import {
79
+ LogicEngine,
80
+ PRAXIS_PROTOCOL_VERSION,
81
+ createPraxisEngine
82
+ } from "./chunk-VOMLVI6V.js";
38
83
  import "./chunk-QGM4M3NI.js";
39
84
 
40
85
  // src/core/reactive-engine.ts
@@ -577,65 +622,6 @@ function createIntrospector(registry) {
577
622
  return new RegistryIntrospector(registry);
578
623
  }
579
624
 
580
- // src/dsl/index.ts
581
- function defineFact(tag) {
582
- return {
583
- tag,
584
- create(payload) {
585
- return { tag, payload };
586
- },
587
- is(fact) {
588
- return fact.tag === tag;
589
- }
590
- };
591
- }
592
- function defineEvent(tag) {
593
- return {
594
- tag,
595
- create(payload) {
596
- return { tag, payload };
597
- },
598
- is(event) {
599
- return event.tag === tag;
600
- }
601
- };
602
- }
603
- function defineRule(options) {
604
- return {
605
- id: options.id,
606
- description: options.description,
607
- impl: options.impl,
608
- meta: options.meta
609
- };
610
- }
611
- function defineConstraint(options) {
612
- return {
613
- id: options.id,
614
- description: options.description,
615
- impl: options.impl,
616
- meta: options.meta
617
- };
618
- }
619
- function defineModule(options) {
620
- return {
621
- rules: options.rules ?? [],
622
- constraints: options.constraints ?? [],
623
- meta: options.meta
624
- };
625
- }
626
- function filterEvents(events, definition) {
627
- return events.filter(definition.is);
628
- }
629
- function filterFacts(facts, definition) {
630
- return facts.filter(definition.is);
631
- }
632
- function findEvent(events, definition) {
633
- return events.find(definition.is);
634
- }
635
- function findFact(facts, definition) {
636
- return facts.find(definition.is);
637
- }
638
-
639
625
  // src/core/pluresdb/store.ts
640
626
  var PRAXIS_PATHS = {
641
627
  /** Base path for all Praxis data */
@@ -915,141 +901,6 @@ function createPraxisDBStore(db, registry, initialContext, onRuleError) {
915
901
  return new PraxisDBStore({ db, registry, initialContext, onRuleError });
916
902
  }
917
903
 
918
- // src/core/pluresdb/adapter.ts
919
- var InMemoryPraxisDB = class {
920
- store = /* @__PURE__ */ new Map();
921
- watchers = /* @__PURE__ */ new Map();
922
- async get(key) {
923
- return this.store.get(key);
924
- }
925
- async set(key, value) {
926
- this.store.set(key, value);
927
- const keyWatchers = this.watchers.get(key);
928
- if (keyWatchers) {
929
- for (const callback of keyWatchers) {
930
- callback(value);
931
- }
932
- }
933
- }
934
- watch(key, callback) {
935
- if (!this.watchers.has(key)) {
936
- this.watchers.set(key, /* @__PURE__ */ new Set());
937
- }
938
- const watchers = this.watchers.get(key);
939
- const wrappedCallback = (val) => callback(val);
940
- watchers.add(wrappedCallback);
941
- return () => {
942
- watchers.delete(wrappedCallback);
943
- if (watchers.size === 0) {
944
- this.watchers.delete(key);
945
- }
946
- };
947
- }
948
- /**
949
- * Get all keys (for testing/debugging)
950
- */
951
- keys() {
952
- return Array.from(this.store.keys());
953
- }
954
- /**
955
- * Clear all data (for testing)
956
- */
957
- clear() {
958
- this.store.clear();
959
- this.watchers.clear();
960
- }
961
- };
962
- function createInMemoryDB() {
963
- return new InMemoryPraxisDB();
964
- }
965
- var PluresDBPraxisAdapter = class {
966
- db;
967
- watchers = /* @__PURE__ */ new Map();
968
- pollIntervals = /* @__PURE__ */ new Map();
969
- lastValues = /* @__PURE__ */ new Map();
970
- pollInterval;
971
- constructor(config) {
972
- if ("get" in config && "put" in config) {
973
- this.db = config;
974
- this.pollInterval = 1e3;
975
- } else {
976
- this.db = config.db;
977
- this.pollInterval = config.pollInterval ?? 1e3;
978
- }
979
- }
980
- async get(key) {
981
- try {
982
- const value = await this.db.get(key);
983
- return value;
984
- } catch (error) {
985
- return void 0;
986
- }
987
- }
988
- async set(key, value) {
989
- await this.db.put(key, value);
990
- this.lastValues.set(key, value);
991
- const keyWatchers = this.watchers.get(key);
992
- if (keyWatchers) {
993
- for (const callback of keyWatchers) {
994
- callback(value);
995
- }
996
- }
997
- }
998
- watch(key, callback) {
999
- if (!this.watchers.has(key)) {
1000
- this.watchers.set(key, /* @__PURE__ */ new Set());
1001
- }
1002
- const watchers = this.watchers.get(key);
1003
- const wrappedCallback = (val) => callback(val);
1004
- watchers.add(wrappedCallback);
1005
- if (!this.pollIntervals.has(key)) {
1006
- const interval = setInterval(async () => {
1007
- try {
1008
- const value = await this.db.get(key);
1009
- const lastValue = this.lastValues.get(key);
1010
- if (JSON.stringify(value) !== JSON.stringify(lastValue)) {
1011
- this.lastValues.set(key, value);
1012
- const currentWatchers = this.watchers.get(key);
1013
- if (currentWatchers) {
1014
- for (const cb of currentWatchers) {
1015
- cb(value);
1016
- }
1017
- }
1018
- }
1019
- } catch (error) {
1020
- }
1021
- }, this.pollInterval);
1022
- this.pollIntervals.set(key, interval);
1023
- }
1024
- return () => {
1025
- watchers.delete(wrappedCallback);
1026
- if (watchers.size === 0) {
1027
- this.watchers.delete(key);
1028
- const interval = this.pollIntervals.get(key);
1029
- if (interval) {
1030
- clearInterval(interval);
1031
- this.pollIntervals.delete(key);
1032
- }
1033
- this.lastValues.delete(key);
1034
- }
1035
- };
1036
- }
1037
- /**
1038
- * Clean up all resources
1039
- */
1040
- dispose() {
1041
- for (const interval of this.pollIntervals.values()) {
1042
- clearInterval(interval);
1043
- }
1044
- this.pollIntervals.clear();
1045
- this.watchers.clear();
1046
- this.lastValues.clear();
1047
- }
1048
- };
1049
- function createPluresDB(config) {
1050
- return new PluresDBPraxisAdapter(config);
1051
- }
1052
-
1053
904
  // src/core/pluresdb/schema-registry.ts
1054
905
  function getSchemaPath(schemaName) {
1055
906
  return `${PRAXIS_PATHS.SCHEMAS}/${schemaName}`;
@@ -1370,447 +1221,6 @@ function attachUnumToEngine(_engine, _adapter, _channelId) {
1370
1221
  };
1371
1222
  }
1372
1223
 
1373
- // src/integrations/state-docs.ts
1374
- var StateDocsGenerator = class {
1375
- config;
1376
- constructor(config) {
1377
- this.config = {
1378
- target: "./docs",
1379
- globs: ["**/*.ts", "**/*.js"],
1380
- visualization: {
1381
- format: "mermaid",
1382
- exportPng: false,
1383
- theme: "default"
1384
- },
1385
- template: {
1386
- toc: true,
1387
- timestamp: true
1388
- },
1389
- ...config
1390
- };
1391
- }
1392
- /**
1393
- * Generate documentation from a Praxis schema
1394
- */
1395
- generateFromSchema(schema) {
1396
- const docs = [];
1397
- docs.push(this.generateSchemaReadme(schema));
1398
- if (schema.models && schema.models.length > 0) {
1399
- docs.push(this.generateModelsDoc(schema));
1400
- }
1401
- if (schema.components && schema.components.length > 0) {
1402
- docs.push(this.generateComponentsDoc(schema));
1403
- }
1404
- if (schema.logic && schema.logic.length > 0) {
1405
- for (const logic of schema.logic) {
1406
- docs.push(this.generateLogicDoc(logic));
1407
- docs.push(this.generateLogicDiagram(logic));
1408
- }
1409
- }
1410
- return docs;
1411
- }
1412
- /**
1413
- * Generate documentation from a Praxis registry
1414
- */
1415
- generateFromModule(module) {
1416
- const docs = [];
1417
- const rules = module.rules;
1418
- const constraints = module.constraints;
1419
- docs.push(this.generateRulesDoc(rules));
1420
- docs.push(this.generateConstraintsDoc(constraints));
1421
- docs.push(this.generateRegistryDiagram(rules, constraints));
1422
- return docs;
1423
- }
1424
- /**
1425
- * Generate the main schema README
1426
- */
1427
- generateSchemaReadme(schema) {
1428
- const lines = [];
1429
- if (this.config.template?.header) {
1430
- lines.push(this.config.template.header);
1431
- lines.push("");
1432
- }
1433
- lines.push(`# ${schema.name || this.config.projectTitle}`);
1434
- lines.push("");
1435
- if (schema.description) {
1436
- lines.push(schema.description);
1437
- lines.push("");
1438
- }
1439
- if (this.config.template?.toc) {
1440
- lines.push("## Table of Contents");
1441
- lines.push("");
1442
- lines.push("- [Overview](#overview)");
1443
- if (schema.models && schema.models.length > 0) {
1444
- lines.push("- [Models](#models)");
1445
- }
1446
- if (schema.components && schema.components.length > 0) {
1447
- lines.push("- [Components](#components)");
1448
- }
1449
- if (schema.logic && schema.logic.length > 0) {
1450
- lines.push("- [Logic](#logic)");
1451
- }
1452
- lines.push("");
1453
- }
1454
- lines.push("## Overview");
1455
- lines.push("");
1456
- lines.push(`**Version:** ${schema.version}`);
1457
- lines.push("");
1458
- lines.push("### Statistics");
1459
- lines.push("");
1460
- lines.push("| Category | Count |");
1461
- lines.push("|----------|-------|");
1462
- lines.push(`| Models | ${schema.models?.length || 0} |`);
1463
- lines.push(`| Components | ${schema.components?.length || 0} |`);
1464
- lines.push(`| Logic Modules | ${schema.logic?.length || 0} |`);
1465
- lines.push("");
1466
- if (schema.models && schema.models.length > 0) {
1467
- lines.push("## Models");
1468
- lines.push("");
1469
- for (const model of schema.models) {
1470
- lines.push(`### ${model.name}`);
1471
- lines.push("");
1472
- if (model.description) {
1473
- lines.push(model.description);
1474
- lines.push("");
1475
- }
1476
- lines.push("**Fields:**");
1477
- lines.push("");
1478
- lines.push("| Name | Type | Required |");
1479
- lines.push("|------|------|----------|");
1480
- for (const field of model.fields) {
1481
- const required = field.optional ? "No" : "Yes";
1482
- lines.push(`| ${field.name} | ${field.type} | ${required} |`);
1483
- }
1484
- lines.push("");
1485
- }
1486
- }
1487
- if (schema.components && schema.components.length > 0) {
1488
- lines.push("## Components");
1489
- lines.push("");
1490
- for (const component of schema.components) {
1491
- lines.push(`### ${component.name}`);
1492
- lines.push("");
1493
- lines.push(`**Type:** ${component.type}`);
1494
- lines.push("");
1495
- if (component.description) {
1496
- lines.push(component.description);
1497
- lines.push("");
1498
- }
1499
- if (component.model) {
1500
- lines.push(`**Model:** ${component.model}`);
1501
- lines.push("");
1502
- }
1503
- }
1504
- }
1505
- if (schema.logic && schema.logic.length > 0) {
1506
- lines.push("## Logic");
1507
- lines.push("");
1508
- for (const logic of schema.logic) {
1509
- lines.push(`### ${logic.id}`);
1510
- lines.push("");
1511
- if (logic.description) {
1512
- lines.push(logic.description);
1513
- lines.push("");
1514
- }
1515
- if (logic.events && logic.events.length > 0) {
1516
- lines.push("**Events:**");
1517
- lines.push("");
1518
- for (const event of logic.events) {
1519
- lines.push(`- \`${event.tag}\`: ${event.description || ""}`);
1520
- }
1521
- lines.push("");
1522
- }
1523
- if (logic.facts && logic.facts.length > 0) {
1524
- lines.push("**Facts:**");
1525
- lines.push("");
1526
- for (const fact of logic.facts) {
1527
- lines.push(`- \`${fact.tag}\`: ${fact.description || ""}`);
1528
- }
1529
- lines.push("");
1530
- }
1531
- if (logic.rules && logic.rules.length > 0) {
1532
- lines.push("**Rules:**");
1533
- lines.push("");
1534
- for (const rule of logic.rules) {
1535
- lines.push(`- \`${rule.id}\`: ${rule.description || ""}`);
1536
- }
1537
- lines.push("");
1538
- }
1539
- }
1540
- }
1541
- if (this.config.template?.timestamp) {
1542
- lines.push("---");
1543
- lines.push("");
1544
- lines.push(`*Generated on ${(/* @__PURE__ */ new Date()).toISOString()} by State-Docs*`);
1545
- }
1546
- if (this.config.template?.footer) {
1547
- lines.push("");
1548
- lines.push(this.config.template.footer);
1549
- }
1550
- return {
1551
- path: `${this.config.target}/README.md`,
1552
- content: lines.join("\n"),
1553
- type: "markdown"
1554
- };
1555
- }
1556
- /**
1557
- * Generate models documentation
1558
- */
1559
- generateModelsDoc(schema) {
1560
- const lines = [
1561
- "# Models",
1562
- "",
1563
- "This document describes all data models defined in the schema.",
1564
- ""
1565
- ];
1566
- if (schema.models) {
1567
- for (const model of schema.models) {
1568
- lines.push(`## ${model.name}`);
1569
- lines.push("");
1570
- if (model.description) {
1571
- lines.push(model.description);
1572
- lines.push("");
1573
- }
1574
- lines.push("### Fields");
1575
- lines.push("");
1576
- lines.push("| Name | Type | Required | Description |");
1577
- lines.push("|------|------|----------|-------------|");
1578
- for (const field of model.fields) {
1579
- const required = field.optional ? "No" : "Yes";
1580
- const description = field.description || "-";
1581
- lines.push(`| ${field.name} | \`${field.type}\` | ${required} | ${description} |`);
1582
- }
1583
- lines.push("");
1584
- if (model.indexes && model.indexes.length > 0) {
1585
- lines.push("### Indexes");
1586
- lines.push("");
1587
- for (const index of model.indexes) {
1588
- lines.push(`- **${index.name}**: \`${index.fields.join(", ")}\``);
1589
- }
1590
- lines.push("");
1591
- }
1592
- }
1593
- }
1594
- return {
1595
- path: `${this.config.target}/models.md`,
1596
- content: lines.join("\n"),
1597
- type: "markdown"
1598
- };
1599
- }
1600
- /**
1601
- * Generate components documentation
1602
- */
1603
- generateComponentsDoc(schema) {
1604
- const lines = [
1605
- "# Components",
1606
- "",
1607
- "This document describes all UI components defined in the schema.",
1608
- ""
1609
- ];
1610
- if (schema.components) {
1611
- for (const component of schema.components) {
1612
- lines.push(`## ${component.name}`);
1613
- lines.push("");
1614
- lines.push(`**Type:** ${component.type}`);
1615
- lines.push("");
1616
- if (component.description) {
1617
- lines.push(component.description);
1618
- lines.push("");
1619
- }
1620
- if (component.model) {
1621
- lines.push(
1622
- `**Associated Model:** [${component.model}](./models.md#${component.model.toLowerCase()})`
1623
- );
1624
- lines.push("");
1625
- }
1626
- }
1627
- }
1628
- return {
1629
- path: `${this.config.target}/components.md`,
1630
- content: lines.join("\n"),
1631
- type: "markdown"
1632
- };
1633
- }
1634
- /**
1635
- * Generate logic documentation
1636
- */
1637
- generateLogicDoc(logic) {
1638
- const lines = [`# ${logic.id}`, ""];
1639
- if (logic.description) {
1640
- lines.push(logic.description);
1641
- lines.push("");
1642
- }
1643
- if (logic.events && logic.events.length > 0) {
1644
- lines.push("## Events");
1645
- lines.push("");
1646
- lines.push("| Event | Description | Payload |");
1647
- lines.push("|-------|-------------|---------|");
1648
- for (const event of logic.events) {
1649
- const payload = event.payload ? Object.entries(event.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
1650
- lines.push(`| \`${event.tag}\` | ${event.description || "-"} | ${payload} |`);
1651
- }
1652
- lines.push("");
1653
- }
1654
- if (logic.facts && logic.facts.length > 0) {
1655
- lines.push("## Facts");
1656
- lines.push("");
1657
- lines.push("| Fact | Description | Payload |");
1658
- lines.push("|------|-------------|---------|");
1659
- for (const fact of logic.facts) {
1660
- const payload = fact.payload ? Object.entries(fact.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
1661
- lines.push(`| \`${fact.tag}\` | ${fact.description || "-"} | ${payload} |`);
1662
- }
1663
- lines.push("");
1664
- }
1665
- if (logic.rules && logic.rules.length > 0) {
1666
- lines.push("## Rules");
1667
- lines.push("");
1668
- for (const rule of logic.rules) {
1669
- lines.push(`### ${rule.id}`);
1670
- lines.push("");
1671
- if (rule.description) {
1672
- lines.push(rule.description);
1673
- lines.push("");
1674
- }
1675
- if (rule.priority !== void 0) {
1676
- lines.push(`**Priority:** ${rule.priority}`);
1677
- lines.push("");
1678
- }
1679
- }
1680
- }
1681
- if (logic.constraints && logic.constraints.length > 0) {
1682
- lines.push("## Constraints");
1683
- lines.push("");
1684
- for (const constraint of logic.constraints) {
1685
- lines.push(`### ${constraint.id}`);
1686
- lines.push("");
1687
- if (constraint.description) {
1688
- lines.push(constraint.description);
1689
- lines.push("");
1690
- }
1691
- if (constraint.message) {
1692
- lines.push(`**Error Message:** ${constraint.message}`);
1693
- lines.push("");
1694
- }
1695
- }
1696
- }
1697
- return {
1698
- path: `${this.config.target}/logic/${logic.id}.md`,
1699
- content: lines.join("\n"),
1700
- type: "markdown"
1701
- };
1702
- }
1703
- /**
1704
- * Generate Mermaid diagram for logic
1705
- */
1706
- generateLogicDiagram(logic) {
1707
- const lines = ["stateDiagram-v2"];
1708
- if (logic.events && logic.facts) {
1709
- lines.push(" [*] --> Processing");
1710
- for (const event of logic.events) {
1711
- lines.push(` Processing --> ${event.tag.replace(/[^a-zA-Z0-9]/g, "")}: ${event.tag}`);
1712
- }
1713
- for (const fact of logic.facts) {
1714
- lines.push(` ${fact.tag.replace(/[^a-zA-Z0-9]/g, "")} --> [*]`);
1715
- }
1716
- }
1717
- return {
1718
- path: `${this.config.target}/logic/${logic.id}.mmd`,
1719
- content: lines.join("\n"),
1720
- type: "mermaid"
1721
- };
1722
- }
1723
- /**
1724
- * Generate rules documentation
1725
- */
1726
- generateRulesDoc(rules) {
1727
- const lines = [
1728
- "# Rules",
1729
- "",
1730
- "This document describes all rules registered in the Praxis engine.",
1731
- ""
1732
- ];
1733
- for (const rule of rules) {
1734
- lines.push(`## ${rule.id}`);
1735
- lines.push("");
1736
- if (rule.description) {
1737
- lines.push(rule.description);
1738
- lines.push("");
1739
- }
1740
- if (rule.meta?.eventType) {
1741
- lines.push(`**Triggers on:** \`${rule.meta.eventType}\``);
1742
- lines.push("");
1743
- }
1744
- if (rule.meta?.priority !== void 0) {
1745
- lines.push(`**Priority:** ${rule.meta.priority}`);
1746
- lines.push("");
1747
- }
1748
- }
1749
- return {
1750
- path: `${this.config.target}/rules.md`,
1751
- content: lines.join("\n"),
1752
- type: "markdown"
1753
- };
1754
- }
1755
- /**
1756
- * Generate constraints documentation
1757
- */
1758
- generateConstraintsDoc(constraints) {
1759
- const lines = [
1760
- "# Constraints",
1761
- "",
1762
- "This document describes all constraints (invariants) registered in the Praxis engine.",
1763
- ""
1764
- ];
1765
- for (const constraint of constraints) {
1766
- lines.push(`## ${constraint.id}`);
1767
- lines.push("");
1768
- if (constraint.description) {
1769
- lines.push(constraint.description);
1770
- lines.push("");
1771
- }
1772
- if (constraint.meta?.errorMessage) {
1773
- lines.push(`**Error Message:** ${constraint.meta.errorMessage}`);
1774
- lines.push("");
1775
- }
1776
- }
1777
- return {
1778
- path: `${this.config.target}/constraints.md`,
1779
- content: lines.join("\n"),
1780
- type: "markdown"
1781
- };
1782
- }
1783
- /**
1784
- * Generate state diagram from registry
1785
- */
1786
- generateRegistryDiagram(rules, constraints) {
1787
- const lines = ["graph TD", " subgraph Rules"];
1788
- for (const rule of rules) {
1789
- const id = rule.id.replace(/[^a-zA-Z0-9]/g, "_");
1790
- lines.push(` ${id}["${rule.id}"]`);
1791
- }
1792
- lines.push(" end");
1793
- lines.push(" subgraph Constraints");
1794
- for (const constraint of constraints) {
1795
- const id = constraint.id.replace(/[^a-zA-Z0-9]/g, "_");
1796
- lines.push(` ${id}["${constraint.id}"]`);
1797
- }
1798
- lines.push(" end");
1799
- return {
1800
- path: `${this.config.target}/state-diagram.mmd`,
1801
- content: lines.join("\n"),
1802
- type: "mermaid"
1803
- };
1804
- }
1805
- };
1806
- function createStateDocsGenerator(config) {
1807
- return new StateDocsGenerator(config);
1808
- }
1809
- function generateDocs(schema, config) {
1810
- const generator = createStateDocsGenerator(config);
1811
- return generator.generateFromSchema(schema);
1812
- }
1813
-
1814
1224
  // src/integrations/tauri.ts
1815
1225
  function createMockTauriBridge() {
1816
1226
  const eventHandlers = /* @__PURE__ */ new Map();
@@ -2030,8 +1440,147 @@ function generateTauriConfig(config) {
2030
1440
  plugins: Object.fromEntries((config.plugins || []).map((p) => [p.name, p.config || {}]))
2031
1441
  };
2032
1442
  }
1443
+
1444
+ // src/integrations/unified.ts
1445
+ async function createUnifiedApp(config) {
1446
+ const { createPraxisEngine: createPraxisEngine2 } = await import("./engine-2DQBKBJC.js");
1447
+ const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-75ISSMWD.js");
1448
+ const db = config.db || createInMemoryDB2();
1449
+ const pluresdb = createPluresDBAdapter({
1450
+ db,
1451
+ registry: config.registry,
1452
+ initialContext: config.initialContext
1453
+ });
1454
+ const engine = createPraxisEngine2({
1455
+ initialContext: config.initialContext,
1456
+ registry: config.registry
1457
+ });
1458
+ pluresdb.attachEngine(engine);
1459
+ const disposers = [];
1460
+ let unum;
1461
+ let channel;
1462
+ if (config.enableUnum) {
1463
+ const fullIdentity = config.unumIdentity ? {
1464
+ ...config.unumIdentity,
1465
+ id: generateId(),
1466
+ createdAt: Date.now()
1467
+ } : void 0;
1468
+ unum = await createUnumAdapter({
1469
+ db,
1470
+ identity: fullIdentity,
1471
+ realtime: true
1472
+ });
1473
+ channel = await unum.createChannel(
1474
+ config.unumIdentity?.name || "praxis-app",
1475
+ []
1476
+ );
1477
+ const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
1478
+ disposers.push(unumDisposer);
1479
+ }
1480
+ let docs;
1481
+ let generateDocs2;
1482
+ if (config.enableDocs && config.docsConfig) {
1483
+ docs = createStateDocsGenerator({
1484
+ projectTitle: config.docsConfig.projectTitle,
1485
+ target: config.docsConfig.target || "./docs"
1486
+ });
1487
+ generateDocs2 = () => {
1488
+ const module = {
1489
+ rules: config.registry.getAllRules(),
1490
+ constraints: config.registry.getAllConstraints()
1491
+ };
1492
+ return docs.generateFromModule(module);
1493
+ };
1494
+ }
1495
+ let canvas;
1496
+ if (config.schema) {
1497
+ canvas = schemaToCanvas(config.schema, { layout: "hierarchical" });
1498
+ }
1499
+ return {
1500
+ engine,
1501
+ pluresdb,
1502
+ unum,
1503
+ channel,
1504
+ docs,
1505
+ canvas,
1506
+ generateDocs: generateDocs2,
1507
+ dispose: () => {
1508
+ pluresdb.dispose();
1509
+ if (unum) {
1510
+ unum.disconnect().catch((err) => {
1511
+ console.warn("Warning: Error during Unum disconnect:", err);
1512
+ });
1513
+ }
1514
+ for (const disposer of disposers) {
1515
+ disposer();
1516
+ }
1517
+ }
1518
+ };
1519
+ }
1520
+ async function attachAllIntegrations(engine, registry, options = {}) {
1521
+ const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-75ISSMWD.js");
1522
+ const db = options.db || createInMemoryDB2();
1523
+ const pluresdb = createPluresDBAdapter({
1524
+ db,
1525
+ registry,
1526
+ initialContext: engine.getContext()
1527
+ });
1528
+ pluresdb.attachEngine(engine);
1529
+ const disposers = [];
1530
+ let unum;
1531
+ let channel;
1532
+ if (options.enableUnum) {
1533
+ const fullIdentity = options.unumIdentity ? {
1534
+ ...options.unumIdentity,
1535
+ id: generateId(),
1536
+ createdAt: Date.now()
1537
+ } : void 0;
1538
+ unum = await createUnumAdapter({
1539
+ db,
1540
+ identity: fullIdentity,
1541
+ realtime: true
1542
+ });
1543
+ channel = await unum.createChannel(
1544
+ options.unumIdentity?.name || "praxis-app",
1545
+ []
1546
+ );
1547
+ const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
1548
+ disposers.push(unumDisposer);
1549
+ }
1550
+ let docs;
1551
+ if (options.enableDocs && options.docsConfig) {
1552
+ docs = createStateDocsGenerator({
1553
+ projectTitle: options.docsConfig.projectTitle,
1554
+ target: options.docsConfig.target || "./docs"
1555
+ });
1556
+ }
1557
+ return {
1558
+ pluresdb,
1559
+ unum,
1560
+ channel,
1561
+ docs,
1562
+ dispose: () => {
1563
+ pluresdb.dispose();
1564
+ if (unum) {
1565
+ unum.disconnect().catch((err) => {
1566
+ console.warn("Warning: Error during Unum disconnect:", err);
1567
+ });
1568
+ }
1569
+ for (const disposer of disposers) {
1570
+ disposer();
1571
+ }
1572
+ }
1573
+ };
1574
+ }
2033
1575
  export {
1576
+ AcknowledgeContractGap,
2034
1577
  ActorManager,
1578
+ BehaviorLedger,
1579
+ ContractAdded,
1580
+ ContractGapAcknowledged,
1581
+ ContractMissing,
1582
+ ContractUpdated,
1583
+ ContractValidated,
2035
1584
  ReactiveLogicEngine2 as FrameworkAgnosticReactiveEngine,
2036
1585
  InMemoryPraxisDB,
2037
1586
  LogicEngine,
@@ -2046,12 +1595,15 @@ export {
2046
1595
  RegistryIntrospector,
2047
1596
  StateDocsGenerator,
2048
1597
  TerminalAdapter,
1598
+ ValidateContracts,
1599
+ attachAllIntegrations,
2049
1600
  attachTauriToEngine,
2050
1601
  attachToEngine,
2051
1602
  attachUnumToEngine,
2052
1603
  canvasToMermaid,
2053
1604
  canvasToSchema,
2054
1605
  canvasToYaml,
1606
+ createBehaviorLedger,
2055
1607
  createCanvasEditor,
2056
1608
  createReactiveEngine2 as createFrameworkAgnosticReactiveEngine,
2057
1609
  createInMemoryDB,
@@ -2063,6 +1615,7 @@ export {
2063
1615
  createPluresDBGenerator,
2064
1616
  createPraxisDBStore,
2065
1617
  createPraxisEngine,
1618
+ createPraxisLocalFirst,
2066
1619
  createReactiveEngine,
2067
1620
  createSchemaRegistry,
2068
1621
  createSchemaTemplate,
@@ -2070,8 +1623,10 @@ export {
2070
1623
  createTauriPraxisAdapter,
2071
1624
  createTerminalAdapter,
2072
1625
  createTimerActor,
1626
+ createUnifiedApp,
2073
1627
  createUnumAdapter,
2074
1628
  defineConstraint,
1629
+ defineContract,
2075
1630
  defineEvent,
2076
1631
  defineFact,
2077
1632
  defineModule,
@@ -2080,12 +1635,17 @@ export {
2080
1635
  filterFacts,
2081
1636
  findEvent,
2082
1637
  findFact,
1638
+ formatValidationReport,
1639
+ formatValidationReportJSON,
1640
+ formatValidationReportSARIF,
2083
1641
  generateDocs,
2084
1642
  generateId,
2085
1643
  generateTauriConfig,
1644
+ getContract,
2086
1645
  getEventPath,
2087
1646
  getFactPath,
2088
1647
  getSchemaPath,
1648
+ isContract,
2089
1649
  loadSchema,
2090
1650
  loadSchemaFromFile,
2091
1651
  loadSchemaFromJson,
@@ -2093,6 +1653,7 @@ export {
2093
1653
  registerSchema,
2094
1654
  runTerminalCommand,
2095
1655
  schemaToCanvas,
1656
+ validateContracts,
2096
1657
  validateForGeneration,
2097
1658
  validateSchema,
2098
1659
  validateWithGuardian