@plures/praxis 1.3.0 → 1.4.4
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/dist/browser/{chunk-N63K4KWS.js → chunk-4IRUGWR3.js} +1 -1
- package/dist/browser/chunk-6SJ44Q64.js +473 -0
- package/dist/browser/chunk-BQOYZBWA.js +282 -0
- package/dist/browser/chunk-IG5BJ2MT.js +91 -0
- package/dist/browser/{chunk-MJK3IYTJ.js → chunk-JZDJU2DO.js} +4 -84
- package/dist/browser/chunk-ZEW4LJAJ.js +353 -0
- package/dist/browser/{engine-YIEGSX7U.js → engine-3B5WJPGT.js} +2 -1
- package/dist/browser/expectations/index.d.ts +180 -0
- package/dist/browser/expectations/index.js +14 -0
- package/dist/browser/factory/index.d.ts +149 -0
- package/dist/browser/factory/index.js +15 -0
- package/dist/browser/index.d.ts +274 -3
- package/dist/browser/index.js +407 -54
- package/dist/browser/integrations/svelte.d.ts +3 -2
- package/dist/browser/integrations/svelte.js +3 -2
- package/dist/browser/project/index.d.ts +176 -0
- package/dist/browser/project/index.js +19 -0
- package/dist/browser/reactive-engine.svelte-DgVTqHLc.d.ts +223 -0
- package/dist/browser/{reactive-engine.svelte-DjynI82A.d.ts → rules-i1LHpnGd.d.ts} +13 -221
- package/dist/node/chunk-2IUFZBH3.js +87 -0
- package/dist/node/{chunk-WZ6B3LZ6.js → chunk-7CSWBDFL.js} +3 -56
- package/dist/node/chunk-AZLNISFI.js +1690 -0
- package/dist/node/chunk-IG5BJ2MT.js +91 -0
- package/dist/node/{chunk-KMJWAFZV.js → chunk-JZDJU2DO.js} +4 -89
- package/dist/node/chunk-PGVSB6NR.js +59 -0
- package/dist/node/{chunk-5JQJZADT.js → chunk-ZO2LU4G4.js} +4 -4
- package/dist/node/cli/index.cjs +1126 -211
- package/dist/node/cli/index.js +21 -2
- package/dist/node/{engine-FEN5IYZ5.js → engine-VFHCIEM4.js} +2 -1
- package/dist/node/index.cjs +5623 -2765
- package/dist/node/index.d.cts +1181 -1
- package/dist/node/index.d.ts +1181 -1
- package/dist/node/index.js +1646 -79
- package/dist/node/integrations/svelte.js +4 -3
- package/dist/node/{reverse-W7THPV45.js → reverse-YD3CWIGM.js} +3 -2
- package/dist/node/rules-4DAJ4Z4N.js +7 -0
- package/dist/node/server-FKLVY57V.js +363 -0
- package/dist/node/{validate-EN3M4FUR.js → validate-5PSWJTIC.js} +5 -3
- package/package.json +50 -3
- package/src/__tests__/chronos-project.test.ts +799 -0
- package/src/__tests__/decision-ledger.test.ts +857 -402
- package/src/__tests__/expectations.test.ts +364 -0
- package/src/__tests__/factory.test.ts +426 -0
- package/src/__tests__/mcp-server.test.ts +310 -0
- package/src/__tests__/project.test.ts +396 -0
- package/src/chronos/diff.ts +336 -0
- package/src/chronos/hooks.ts +227 -0
- package/src/chronos/index.ts +83 -0
- package/src/chronos/project-chronicle.ts +198 -0
- package/src/chronos/timeline.ts +152 -0
- package/src/cli/index.ts +28 -0
- package/src/decision-ledger/analyzer-types.ts +280 -0
- package/src/decision-ledger/analyzer.ts +518 -0
- package/src/decision-ledger/contract-verification.ts +456 -0
- package/src/decision-ledger/derivation.ts +158 -0
- package/src/decision-ledger/index.ts +59 -0
- package/src/decision-ledger/report.ts +378 -0
- package/src/decision-ledger/suggestions.ts +287 -0
- package/src/expectations/expectations.ts +471 -0
- package/src/expectations/index.ts +29 -0
- package/src/expectations/types.ts +95 -0
- package/src/factory/factory.ts +634 -0
- package/src/factory/index.ts +27 -0
- package/src/factory/types.ts +64 -0
- package/src/index.browser.ts +83 -0
- package/src/index.ts +134 -0
- package/src/mcp/index.ts +33 -0
- package/src/mcp/server.ts +485 -0
- package/src/mcp/types.ts +161 -0
- package/src/project/index.ts +31 -0
- package/src/project/project.ts +423 -0
- package/src/project/types.ts +87 -0
- package/dist/node/chunk-PTH6MD6P.js +0 -487
- /package/dist/node/{chunk-R2PSBPKQ.js → chunk-TEMFJOIH.js} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/core/completeness.ts
|
|
2
|
+
function auditCompleteness(manifest, registryRuleIds, registryConstraintIds, rulesWithContracts, config) {
|
|
3
|
+
const threshold = config?.threshold ?? 90;
|
|
4
|
+
const domainBranches = manifest.branches.filter((b) => b.kind === "domain");
|
|
5
|
+
const coveredDomain = domainBranches.filter((b) => b.coveredBy && registryRuleIds.includes(b.coveredBy));
|
|
6
|
+
const uncoveredDomain = domainBranches.filter((b) => !b.coveredBy || !registryRuleIds.includes(b.coveredBy));
|
|
7
|
+
const invariantBranches = manifest.branches.filter((b) => b.kind === "invariant");
|
|
8
|
+
const coveredInvariants = invariantBranches.filter((b) => b.coveredBy && registryConstraintIds.includes(b.coveredBy));
|
|
9
|
+
const uncoveredInvariants = invariantBranches.filter((b) => !b.coveredBy || !registryConstraintIds.includes(b.coveredBy));
|
|
10
|
+
const needContracts = manifest.rulesNeedingContracts;
|
|
11
|
+
const haveContracts = needContracts.filter((id) => rulesWithContracts.includes(id));
|
|
12
|
+
const missingContracts = needContracts.filter((id) => !rulesWithContracts.includes(id));
|
|
13
|
+
const neededFields = manifest.stateFields.filter((f) => f.usedByRule);
|
|
14
|
+
const coveredFields = neededFields.filter((f) => f.inContext);
|
|
15
|
+
const missingFields = neededFields.filter((f) => !f.inContext);
|
|
16
|
+
const coveredTransitions = manifest.transitions.filter((t) => t.eventTag);
|
|
17
|
+
const missingTransitions = manifest.transitions.filter((t) => !t.eventTag);
|
|
18
|
+
const ruleScore = domainBranches.length > 0 ? coveredDomain.length / domainBranches.length * 40 : 40;
|
|
19
|
+
const constraintScore = invariantBranches.length > 0 ? coveredInvariants.length / invariantBranches.length * 20 : 20;
|
|
20
|
+
const contractScore = needContracts.length > 0 ? haveContracts.length / needContracts.length * 15 : 15;
|
|
21
|
+
const contextScore = neededFields.length > 0 ? coveredFields.length / neededFields.length * 15 : 15;
|
|
22
|
+
const eventScore = manifest.transitions.length > 0 ? coveredTransitions.length / manifest.transitions.length * 10 : 10;
|
|
23
|
+
const score = Math.round(ruleScore + constraintScore + contractScore + contextScore + eventScore);
|
|
24
|
+
const rating = score >= 90 ? "complete" : score >= 70 ? "good" : score >= 50 ? "partial" : "incomplete";
|
|
25
|
+
const report = {
|
|
26
|
+
score,
|
|
27
|
+
rating,
|
|
28
|
+
rules: { total: domainBranches.length, covered: coveredDomain.length, uncovered: uncoveredDomain },
|
|
29
|
+
constraints: { total: invariantBranches.length, covered: coveredInvariants.length, uncovered: uncoveredInvariants },
|
|
30
|
+
contracts: { total: needContracts.length, withContracts: haveContracts.length, missing: missingContracts },
|
|
31
|
+
context: { total: neededFields.length, covered: coveredFields.length, missing: missingFields },
|
|
32
|
+
events: { total: manifest.transitions.length, covered: coveredTransitions.length, missing: missingTransitions }
|
|
33
|
+
};
|
|
34
|
+
if (config?.strict && score < threshold) {
|
|
35
|
+
throw new Error(`Praxis completeness ${score}/100 (${rating}) \u2014 below threshold ${threshold}. ${uncoveredDomain.length} uncovered rules, ${uncoveredInvariants.length} uncovered invariants, ${missingContracts.length} missing contracts.`);
|
|
36
|
+
}
|
|
37
|
+
return report;
|
|
38
|
+
}
|
|
39
|
+
function formatReport(report) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
const icon = report.rating === "complete" ? "\u2705" : report.rating === "good" ? "\u{1F7E2}" : report.rating === "partial" ? "\u{1F7E1}" : "\u{1F534}";
|
|
42
|
+
lines.push(`${icon} Praxis Completeness: ${report.score}/100 (${report.rating})`);
|
|
43
|
+
lines.push("");
|
|
44
|
+
lines.push(`Rules: ${report.rules.covered}/${report.rules.total} domain branches covered (${pct(report.rules.covered, report.rules.total)})`);
|
|
45
|
+
lines.push(`Constraints: ${report.constraints.covered}/${report.constraints.total} invariants covered (${pct(report.constraints.covered, report.constraints.total)})`);
|
|
46
|
+
lines.push(`Contracts: ${report.contracts.withContracts}/${report.contracts.total} rules have contracts (${pct(report.contracts.withContracts, report.contracts.total)})`);
|
|
47
|
+
lines.push(`Context: ${report.context.covered}/${report.context.total} state fields in context (${pct(report.context.covered, report.context.total)})`);
|
|
48
|
+
lines.push(`Events: ${report.events.covered}/${report.events.total} transitions have events (${pct(report.events.covered, report.events.total)})`);
|
|
49
|
+
if (report.rules.uncovered.length > 0) {
|
|
50
|
+
lines.push("");
|
|
51
|
+
lines.push("Uncovered domain logic:");
|
|
52
|
+
for (const b of report.rules.uncovered) {
|
|
53
|
+
lines.push(` \u274C ${b.location}: ${b.condition}${b.note ? ` \u2014 ${b.note}` : ""}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (report.constraints.uncovered.length > 0) {
|
|
57
|
+
lines.push("");
|
|
58
|
+
lines.push("Uncovered invariants:");
|
|
59
|
+
for (const b of report.constraints.uncovered) {
|
|
60
|
+
lines.push(` \u274C ${b.location}: ${b.condition}${b.note ? ` \u2014 ${b.note}` : ""}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (report.contracts.missing.length > 0) {
|
|
64
|
+
lines.push("");
|
|
65
|
+
lines.push("Rules missing contracts:");
|
|
66
|
+
for (const id of report.contracts.missing) {
|
|
67
|
+
lines.push(` \u{1F4DD} ${id}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (report.events.missing.length > 0) {
|
|
71
|
+
lines.push("");
|
|
72
|
+
lines.push("State transitions without events:");
|
|
73
|
+
for (const t of report.events.missing) {
|
|
74
|
+
lines.push(` \u26A1 ${t.location}: ${t.description}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return lines.join("\n");
|
|
78
|
+
}
|
|
79
|
+
function pct(a, b) {
|
|
80
|
+
if (b === 0) return "100%";
|
|
81
|
+
return Math.round(a / b * 100) + "%";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
auditCompleteness,
|
|
86
|
+
formatReport
|
|
87
|
+
};
|
|
@@ -1,55 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
const contract = obj;
|
|
7
|
-
return typeof contract.ruleId === "string" && typeof contract.behavior === "string" && Array.isArray(contract.examples) && contract.examples.length > 0 && contract.examples.every(
|
|
8
|
-
(ex) => typeof ex === "object" && ex !== null && typeof ex.given === "string" && typeof ex.when === "string" && typeof ex.then === "string"
|
|
9
|
-
) && Array.isArray(contract.invariants) && contract.invariants.every((inv) => typeof inv === "string");
|
|
10
|
-
}
|
|
11
|
-
function defineContract(options) {
|
|
12
|
-
if (options.examples.length === 0) {
|
|
13
|
-
throw new Error("Contract must have at least one example");
|
|
14
|
-
}
|
|
15
|
-
if (options.assumptions) {
|
|
16
|
-
for (const assumption of options.assumptions) {
|
|
17
|
-
if (assumption.confidence < 0 || assumption.confidence > 1) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`Assumption '${assumption.id}' has invalid confidence value ${assumption.confidence}. Must be between 0.0 and 1.0`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
ruleId: options.ruleId,
|
|
26
|
-
behavior: options.behavior,
|
|
27
|
-
examples: options.examples,
|
|
28
|
-
invariants: options.invariants,
|
|
29
|
-
assumptions: options.assumptions,
|
|
30
|
-
references: options.references,
|
|
31
|
-
version: options.version || "1.0.0",
|
|
32
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function getContract(meta) {
|
|
36
|
-
if (!meta || !meta.contract) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
if (isContract(meta.contract)) {
|
|
40
|
-
return meta.contract;
|
|
41
|
-
}
|
|
42
|
-
return void 0;
|
|
43
|
-
}
|
|
44
|
-
function getContractFromDescriptor(descriptor) {
|
|
45
|
-
if (!descriptor) {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
if (descriptor.contract && isContract(descriptor.contract)) {
|
|
49
|
-
return descriptor.contract;
|
|
50
|
-
}
|
|
51
|
-
return getContract(descriptor.meta);
|
|
52
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
defineContract
|
|
3
|
+
} from "./chunk-PGVSB6NR.js";
|
|
53
4
|
|
|
54
5
|
// src/decision-ledger/logic-ledger.ts
|
|
55
6
|
import { createHash } from "crypto";
|
|
@@ -628,10 +579,6 @@ function generateDefaultAssumptions(descriptor) {
|
|
|
628
579
|
}
|
|
629
580
|
|
|
630
581
|
export {
|
|
631
|
-
isContract,
|
|
632
|
-
defineContract,
|
|
633
|
-
getContract,
|
|
634
|
-
getContractFromDescriptor,
|
|
635
582
|
writeLogicLedgerEntry,
|
|
636
583
|
scanRepository,
|
|
637
584
|
generateContractFromRule
|