@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,152 @@
|
|
|
1
|
+
// src/core/pluresdb/adapter.ts
|
|
2
|
+
var InMemoryPraxisDB = class {
|
|
3
|
+
store = /* @__PURE__ */ new Map();
|
|
4
|
+
watchers = /* @__PURE__ */ new Map();
|
|
5
|
+
async get(key) {
|
|
6
|
+
return this.store.get(key);
|
|
7
|
+
}
|
|
8
|
+
async set(key, value) {
|
|
9
|
+
this.store.set(key, value);
|
|
10
|
+
const keyWatchers = this.watchers.get(key);
|
|
11
|
+
if (keyWatchers) {
|
|
12
|
+
for (const callback of keyWatchers) {
|
|
13
|
+
callback(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
watch(key, callback) {
|
|
18
|
+
if (!this.watchers.has(key)) {
|
|
19
|
+
this.watchers.set(key, /* @__PURE__ */ new Set());
|
|
20
|
+
}
|
|
21
|
+
const watchers = this.watchers.get(key);
|
|
22
|
+
const wrappedCallback = (val) => callback(val);
|
|
23
|
+
watchers.add(wrappedCallback);
|
|
24
|
+
return () => {
|
|
25
|
+
watchers.delete(wrappedCallback);
|
|
26
|
+
if (watchers.size === 0) {
|
|
27
|
+
this.watchers.delete(key);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get all keys (for testing/debugging)
|
|
33
|
+
*/
|
|
34
|
+
keys() {
|
|
35
|
+
return Array.from(this.store.keys());
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clear all data (for testing)
|
|
39
|
+
*/
|
|
40
|
+
clear() {
|
|
41
|
+
this.store.clear();
|
|
42
|
+
this.watchers.clear();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function createInMemoryDB() {
|
|
46
|
+
return new InMemoryPraxisDB();
|
|
47
|
+
}
|
|
48
|
+
var PluresDBPraxisAdapter = class {
|
|
49
|
+
db;
|
|
50
|
+
watchers = /* @__PURE__ */ new Map();
|
|
51
|
+
pollIntervals = /* @__PURE__ */ new Map();
|
|
52
|
+
lastValues = /* @__PURE__ */ new Map();
|
|
53
|
+
pollInterval;
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if ("get" in config && "put" in config) {
|
|
56
|
+
this.db = config;
|
|
57
|
+
this.pollInterval = 1e3;
|
|
58
|
+
} else {
|
|
59
|
+
this.db = config.db;
|
|
60
|
+
this.pollInterval = config.pollInterval ?? 1e3;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async get(key) {
|
|
64
|
+
try {
|
|
65
|
+
const value = await this.db.get(key);
|
|
66
|
+
return value;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async set(key, value) {
|
|
72
|
+
await this.db.put(key, value);
|
|
73
|
+
this.lastValues.set(key, value);
|
|
74
|
+
const keyWatchers = this.watchers.get(key);
|
|
75
|
+
if (keyWatchers) {
|
|
76
|
+
for (const callback of keyWatchers) {
|
|
77
|
+
callback(value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
watch(key, callback) {
|
|
82
|
+
if (!this.watchers.has(key)) {
|
|
83
|
+
this.watchers.set(key, /* @__PURE__ */ new Set());
|
|
84
|
+
}
|
|
85
|
+
const watchers = this.watchers.get(key);
|
|
86
|
+
const wrappedCallback = (val) => callback(val);
|
|
87
|
+
watchers.add(wrappedCallback);
|
|
88
|
+
if (!this.pollIntervals.has(key)) {
|
|
89
|
+
const interval = setInterval(async () => {
|
|
90
|
+
try {
|
|
91
|
+
const value = await this.db.get(key);
|
|
92
|
+
const lastValue = this.lastValues.get(key);
|
|
93
|
+
if (JSON.stringify(value) !== JSON.stringify(lastValue)) {
|
|
94
|
+
this.lastValues.set(key, value);
|
|
95
|
+
const currentWatchers = this.watchers.get(key);
|
|
96
|
+
if (currentWatchers) {
|
|
97
|
+
for (const cb of currentWatchers) {
|
|
98
|
+
cb(value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
}
|
|
104
|
+
}, this.pollInterval);
|
|
105
|
+
this.pollIntervals.set(key, interval);
|
|
106
|
+
}
|
|
107
|
+
return () => {
|
|
108
|
+
watchers.delete(wrappedCallback);
|
|
109
|
+
if (watchers.size === 0) {
|
|
110
|
+
this.watchers.delete(key);
|
|
111
|
+
const interval = this.pollIntervals.get(key);
|
|
112
|
+
if (interval) {
|
|
113
|
+
clearInterval(interval);
|
|
114
|
+
this.pollIntervals.delete(key);
|
|
115
|
+
}
|
|
116
|
+
this.lastValues.delete(key);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clean up all resources
|
|
122
|
+
*/
|
|
123
|
+
dispose() {
|
|
124
|
+
for (const interval of this.pollIntervals.values()) {
|
|
125
|
+
clearInterval(interval);
|
|
126
|
+
}
|
|
127
|
+
this.pollIntervals.clear();
|
|
128
|
+
this.watchers.clear();
|
|
129
|
+
this.lastValues.clear();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function createPluresDB(config) {
|
|
133
|
+
return new PluresDBPraxisAdapter(config);
|
|
134
|
+
}
|
|
135
|
+
async function createPraxisLocalFirst(options = {}) {
|
|
136
|
+
const { pollInterval, ...localOptions } = options;
|
|
137
|
+
const mod = await import("@plures/pluresdb/local-first");
|
|
138
|
+
const LocalFirstCtor = mod.PluresDBLocalFirst ?? mod.default;
|
|
139
|
+
if (!LocalFirstCtor) {
|
|
140
|
+
throw new Error("Failed to load PluresDBLocalFirst from @plures/pluresdb/local-first");
|
|
141
|
+
}
|
|
142
|
+
const db = new LocalFirstCtor(localOptions);
|
|
143
|
+
return new PluresDBPraxisAdapter({ db, pollInterval });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
InMemoryPraxisDB,
|
|
148
|
+
createInMemoryDB,
|
|
149
|
+
PluresDBPraxisAdapter,
|
|
150
|
+
createPluresDB,
|
|
151
|
+
createPraxisLocalFirst
|
|
152
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PraxisRegistry
|
|
3
|
+
} from "./chunk-R2PSBPKQ.js";
|
|
4
|
+
import {
|
|
5
|
+
createPraxisEngine
|
|
6
|
+
} from "./chunk-VOMLVI6V.js";
|
|
7
|
+
|
|
8
|
+
// src/core/reactive-engine.svelte.ts
|
|
9
|
+
import * as $ from "svelte/internal/client";
|
|
10
|
+
var ReactiveLogicEngine = class {
|
|
11
|
+
#state = (
|
|
12
|
+
// Use Svelte's $state rune for automatic reactivity
|
|
13
|
+
$.state($.proxy({ context: {}, facts: [], meta: {} }))
|
|
14
|
+
);
|
|
15
|
+
get state() {
|
|
16
|
+
return $.get(this.#state);
|
|
17
|
+
}
|
|
18
|
+
set state(value) {
|
|
19
|
+
$.set(this.#state, value, true);
|
|
20
|
+
}
|
|
21
|
+
_engine;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.state.context = options.initialContext;
|
|
24
|
+
this.state.facts = options.initialFacts ?? [];
|
|
25
|
+
this.state.meta = options.initialMeta ?? {};
|
|
26
|
+
if (options.registry) {
|
|
27
|
+
this._engine = createPraxisEngine({
|
|
28
|
+
initialContext: options.initialContext,
|
|
29
|
+
registry: options.registry
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
this._engine = createPraxisEngine({
|
|
33
|
+
initialContext: options.initialContext,
|
|
34
|
+
registry: new PraxisRegistry()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Access the reactive context.
|
|
40
|
+
* In Svelte 5 components, changes to this object will automatically trigger updates.
|
|
41
|
+
*/
|
|
42
|
+
get context() {
|
|
43
|
+
return this.state.context;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Access the reactive facts list.
|
|
47
|
+
*/
|
|
48
|
+
get facts() {
|
|
49
|
+
return this.state.facts;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Access the reactive metadata.
|
|
53
|
+
*/
|
|
54
|
+
get meta() {
|
|
55
|
+
return this.state.meta;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Apply a mutation to the state.
|
|
59
|
+
* Changes will automatically trigger Svelte reactivity.
|
|
60
|
+
*
|
|
61
|
+
* @param mutator A function that receives the state and modifies it.
|
|
62
|
+
*/
|
|
63
|
+
apply(mutator) {
|
|
64
|
+
mutator(this.state);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Process events through the logic engine and update reactive state.
|
|
68
|
+
*
|
|
69
|
+
* @param events Events to process
|
|
70
|
+
*/
|
|
71
|
+
step(events) {
|
|
72
|
+
const result = this._engine.step(events);
|
|
73
|
+
this.state.context = result.state.context;
|
|
74
|
+
this.state.facts = result.state.facts;
|
|
75
|
+
this.state.meta = result.state.meta ?? {};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function createReactiveEngine(options) {
|
|
79
|
+
return new ReactiveLogicEngine(options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
ReactiveLogicEngine,
|
|
84
|
+
createReactiveEngine
|
|
85
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/core/rules.ts
|
|
2
|
+
var PraxisRegistry = class {
|
|
3
|
+
rules = /* @__PURE__ */ new Map();
|
|
4
|
+
constraints = /* @__PURE__ */ new Map();
|
|
5
|
+
compliance;
|
|
6
|
+
contractGaps = [];
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
const defaultEnabled = typeof process !== "undefined" ? process.env?.NODE_ENV !== "production" : false;
|
|
9
|
+
this.compliance = {
|
|
10
|
+
enabled: defaultEnabled,
|
|
11
|
+
requiredFields: ["behavior", "examples", "invariants"],
|
|
12
|
+
missingSeverity: "warning",
|
|
13
|
+
...options.compliance
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Register a rule
|
|
18
|
+
*/
|
|
19
|
+
registerRule(descriptor) {
|
|
20
|
+
if (this.rules.has(descriptor.id)) {
|
|
21
|
+
throw new Error(`Rule with id "${descriptor.id}" already registered`);
|
|
22
|
+
}
|
|
23
|
+
this.rules.set(descriptor.id, descriptor);
|
|
24
|
+
this.trackContractCompliance(descriptor.id, descriptor);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register a constraint
|
|
28
|
+
*/
|
|
29
|
+
registerConstraint(descriptor) {
|
|
30
|
+
if (this.constraints.has(descriptor.id)) {
|
|
31
|
+
throw new Error(`Constraint with id "${descriptor.id}" already registered`);
|
|
32
|
+
}
|
|
33
|
+
this.constraints.set(descriptor.id, descriptor);
|
|
34
|
+
this.trackContractCompliance(descriptor.id, descriptor);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a module (all its rules and constraints)
|
|
38
|
+
*/
|
|
39
|
+
registerModule(module) {
|
|
40
|
+
for (const rule of module.rules) {
|
|
41
|
+
this.registerRule(rule);
|
|
42
|
+
}
|
|
43
|
+
for (const constraint of module.constraints) {
|
|
44
|
+
this.registerConstraint(constraint);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a rule by ID
|
|
49
|
+
*/
|
|
50
|
+
getRule(id) {
|
|
51
|
+
return this.rules.get(id);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get a constraint by ID
|
|
55
|
+
*/
|
|
56
|
+
getConstraint(id) {
|
|
57
|
+
return this.constraints.get(id);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get all registered rule IDs
|
|
61
|
+
*/
|
|
62
|
+
getRuleIds() {
|
|
63
|
+
return Array.from(this.rules.keys());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered constraint IDs
|
|
67
|
+
*/
|
|
68
|
+
getConstraintIds() {
|
|
69
|
+
return Array.from(this.constraints.keys());
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get all rules
|
|
73
|
+
*/
|
|
74
|
+
getAllRules() {
|
|
75
|
+
return Array.from(this.rules.values());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get all constraints
|
|
79
|
+
*/
|
|
80
|
+
getAllConstraints() {
|
|
81
|
+
return Array.from(this.constraints.values());
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get collected contract gaps from registration-time validation.
|
|
85
|
+
*/
|
|
86
|
+
getContractGaps() {
|
|
87
|
+
return [...this.contractGaps];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Clear collected contract gaps.
|
|
91
|
+
*/
|
|
92
|
+
clearContractGaps() {
|
|
93
|
+
this.contractGaps = [];
|
|
94
|
+
}
|
|
95
|
+
trackContractCompliance(id, descriptor) {
|
|
96
|
+
if (!this.compliance.enabled) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const gaps = this.validateDescriptorContract(id, descriptor);
|
|
100
|
+
for (const gap of gaps) {
|
|
101
|
+
this.contractGaps.push(gap);
|
|
102
|
+
if (this.compliance.onGap) {
|
|
103
|
+
this.compliance.onGap(gap);
|
|
104
|
+
} else {
|
|
105
|
+
const label = gap.severity === "error" ? "ERROR" : gap.severity === "warning" ? "WARN" : "INFO";
|
|
106
|
+
console.warn(`[Praxis][${label}] Contract gap for "${gap.ruleId}": missing ${gap.missing.join(", ")}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
validateDescriptorContract(id, descriptor) {
|
|
111
|
+
const requiredFields = this.compliance.requiredFields ?? ["behavior", "examples", "invariants"];
|
|
112
|
+
const missingSeverity = this.compliance.missingSeverity ?? "warning";
|
|
113
|
+
const contract = descriptor.contract ?? (descriptor.meta?.contract && typeof descriptor.meta.contract === "object" ? descriptor.meta.contract : void 0);
|
|
114
|
+
if (!contract) {
|
|
115
|
+
return [
|
|
116
|
+
{
|
|
117
|
+
ruleId: id,
|
|
118
|
+
missing: ["contract"],
|
|
119
|
+
severity: missingSeverity,
|
|
120
|
+
message: `Contract missing for "${id}"`
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
const missing = [];
|
|
125
|
+
if (requiredFields.includes("behavior") && (!contract.behavior || contract.behavior.trim() === "")) {
|
|
126
|
+
missing.push("behavior");
|
|
127
|
+
}
|
|
128
|
+
if (requiredFields.includes("examples") && (!contract.examples || contract.examples.length === 0)) {
|
|
129
|
+
missing.push("examples");
|
|
130
|
+
}
|
|
131
|
+
if (requiredFields.includes("invariants") && (!contract.invariants || contract.invariants.length === 0)) {
|
|
132
|
+
missing.push("invariants");
|
|
133
|
+
}
|
|
134
|
+
if (missing.length === 0) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
ruleId: id,
|
|
140
|
+
missing,
|
|
141
|
+
severity: "warning",
|
|
142
|
+
message: `Contract for "${id}" is incomplete: missing ${missing.join(", ")}`
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
PraxisRegistry
|
|
150
|
+
};
|