kibi-cli 2.31.1 → 2.35.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/dist/cli-register-proof.d.ts.map +1 -1
- package/dist/cli-register-proof.js +19 -7
- package/dist/cli-register-reporting.d.ts.map +1 -1
- package/dist/cli-register-reporting.js +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -1
- package/dist/commands/check-generated.d.ts +5 -1
- package/dist/commands/check-generated.d.ts.map +1 -1
- package/dist/commands/check-generated.js +24 -35
- package/dist/commands/check.d.ts +1 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +14 -5
- package/dist/commands/discovery-table.d.ts.map +1 -1
- package/dist/commands/discovery-table.js +51 -4
- package/dist/commands/doctor.js +19 -4
- package/dist/commands/init-helpers.d.ts.map +1 -1
- package/dist/commands/init-helpers.js +8 -5
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +109 -5
- package/dist/commands/prove.d.ts +48 -1
- package/dist/commands/prove.d.ts.map +1 -1
- package/dist/commands/prove.js +293 -8
- package/dist/commands/report.d.ts +1 -0
- package/dist/commands/report.d.ts.map +1 -1
- package/dist/commands/report.js +70 -5
- package/dist/commands/signoff.d.ts.map +1 -1
- package/dist/commands/signoff.js +20 -1
- package/dist/commands/sync/manifest.d.ts +10 -1
- package/dist/commands/sync/manifest.d.ts.map +1 -1
- package/dist/commands/sync/manifest.js +106 -17
- package/dist/commands/sync/persistence.d.ts.map +1 -1
- package/dist/commands/sync/persistence.js +16 -5
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +19 -0
- package/dist/diagnostics.js +1 -1
- package/dist/engine.js +1 -1
- package/dist/extractors/markdown.d.ts +4 -2
- package/dist/extractors/markdown.d.ts.map +1 -1
- package/dist/extractors/markdown.js +17 -0
- package/dist/extractors/symbol-coordinates.js +2 -2
- package/dist/extractors/symbols-coordinator.d.ts +2 -4
- package/dist/extractors/symbols-coordinator.d.ts.map +1 -1
- package/dist/extractors/symbols-coordinator.js +1 -2
- package/dist/operations/bootstrap/candidate-helpers.d.ts +3 -0
- package/dist/operations/bootstrap/candidate-helpers.d.ts.map +1 -1
- package/dist/operations/bootstrap/candidate-helpers.js +4 -0
- package/dist/operations/migration/evidence-floor.d.ts +41 -0
- package/dist/operations/migration/evidence-floor.d.ts.map +1 -0
- package/dist/operations/migration/evidence-floor.js +230 -0
- package/dist/operations/migration/proof-contract-claims.d.ts +72 -0
- package/dist/operations/migration/proof-contract-claims.d.ts.map +1 -0
- package/dist/operations/migration/proof-contract-claims.js +215 -0
- package/dist/operations/migration/schema6.d.ts +6 -0
- package/dist/operations/migration/schema6.d.ts.map +1 -1
- package/dist/operations/migration/schema6.js +92 -0
- package/dist/operations/migration/symbol-coordinates-refresh.d.ts +3 -2
- package/dist/operations/migration/symbol-coordinates-refresh.d.ts.map +1 -1
- package/dist/operations/migration/symbol-coordinates-refresh.js +4 -3
- package/dist/operations/migration/untrack-symbol-coordinates.d.ts +23 -0
- package/dist/operations/migration/untrack-symbol-coordinates.d.ts.map +1 -0
- package/dist/operations/migration/untrack-symbol-coordinates.js +67 -0
- package/dist/operations/modeling/requirement-modeler.d.ts.map +1 -1
- package/dist/operations/modeling/requirement-modeler.js +48 -1
- package/dist/operations/modeling/requirement-types.d.ts +2 -1
- package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
- package/dist/operations/modeling/requirement-utils.d.ts +1 -1
- package/dist/operations/modeling/requirement-utils.d.ts.map +1 -1
- package/dist/operations/modeling/requirement-utils.js +8 -1
- package/dist/operations/mutation/omitted-properties.d.ts +11 -0
- package/dist/operations/mutation/omitted-properties.d.ts.map +1 -0
- package/dist/operations/mutation/omitted-properties.js +76 -0
- package/dist/operations/mutation/serialization.d.ts.map +1 -1
- package/dist/operations/mutation/serialization.js +1 -0
- package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
- package/dist/operations/mutation/source-authoring.js +39 -20
- package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
- package/dist/operations/mutation/strict-fact.js +6 -2
- package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -1
- package/dist/operations/mutation/symbol-granularity.js +5 -3
- package/dist/operations/mutation/upsert.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.js +7 -1
- package/dist/operations/mutation/validation.d.ts +2 -0
- package/dist/operations/mutation/validation.d.ts.map +1 -1
- package/dist/operations/mutation/validation.js +4 -0
- package/dist/operations/proof/claim-bindings.d.ts +41 -0
- package/dist/operations/proof/claim-bindings.d.ts.map +1 -0
- package/dist/operations/proof/claim-bindings.js +364 -0
- package/dist/operations/proof/code-certificates.d.ts +155 -0
- package/dist/operations/proof/code-certificates.d.ts.map +1 -0
- package/dist/operations/proof/code-certificates.js +894 -0
- package/dist/operations/proof/code-models.d.ts +96 -0
- package/dist/operations/proof/code-models.d.ts.map +1 -0
- package/dist/operations/proof/code-models.js +601 -0
- package/dist/operations/proof/code-runner.d.ts +40 -0
- package/dist/operations/proof/code-runner.d.ts.map +1 -0
- package/dist/operations/proof/code-runner.js +164 -0
- package/dist/operations/proof/code-scope.d.ts +14 -1
- package/dist/operations/proof/code-scope.d.ts.map +1 -1
- package/dist/operations/proof/code-scope.js +44 -2
- package/dist/operations/proof/compact-receipts.d.ts.map +1 -1
- package/dist/operations/proof/compact-receipts.js +4 -3
- package/dist/operations/proof/explain.d.ts +32 -0
- package/dist/operations/proof/explain.d.ts.map +1 -1
- package/dist/operations/proof/explain.js +91 -0
- package/dist/operations/proof/ingest-proof.d.ts +9 -1
- package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
- package/dist/operations/proof/ingest-proof.js +42 -2
- package/dist/operations/proof/receipt-compaction.d.ts +2 -0
- package/dist/operations/proof/receipt-compaction.d.ts.map +1 -1
- package/dist/operations/proof/receipt-compaction.js +6 -2
- package/dist/operations/proof/regular-language.d.ts +89 -0
- package/dist/operations/proof/regular-language.d.ts.map +1 -0
- package/dist/operations/proof/regular-language.js +943 -0
- package/dist/operations/proof/source-code-readers.d.ts +12 -0
- package/dist/operations/proof/source-code-readers.d.ts.map +1 -0
- package/dist/operations/proof/source-code-readers.js +699 -0
- package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/analyze-prose.js +2 -1
- package/dist/operations/semantic-advisor/shared.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/shared.js +4 -0
- package/dist/operations/semantic-advisor/strict-count-rules.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/strict-count-rules.js +8 -2
- package/dist/operations/semantic-advisor/strict-rules.d.ts +8 -0
- package/dist/operations/semantic-advisor/strict-rules.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/strict-rules.js +234 -4
- package/dist/operations/semantic-advisor/types.d.ts +3 -2
- package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
- package/dist/plugins/approved-source-analyzers.generated.d.ts +6 -6
- package/dist/plugins/approved-source-analyzers.generated.js +6 -6
- package/dist/prolog.d.ts.map +1 -1
- package/dist/prolog.js +13 -3
- package/dist/proof/command-test-report.d.ts +4 -3
- package/dist/proof/command-test-report.d.ts.map +1 -1
- package/dist/proof/command-test-report.js +4 -10
- package/dist/proof/evaluate.d.ts.map +1 -1
- package/dist/proof/evaluate.js +18 -2
- package/dist/proof/inspect.d.ts.map +1 -1
- package/dist/proof/inspect.js +58 -0
- package/dist/proof/producers/playwright-reporter.d.ts +3 -0
- package/dist/proof/producers/playwright-reporter.d.ts.map +1 -1
- package/dist/proof/producers/playwright-reporter.js +25 -2
- package/dist/proof/step-runner.d.ts +36 -0
- package/dist/proof/step-runner.d.ts.map +1 -0
- package/dist/proof/step-runner.js +234 -0
- package/dist/public/evidence-levels.d.ts +12 -0
- package/dist/public/evidence-levels.d.ts.map +1 -0
- package/dist/public/evidence-levels.js +19 -0
- package/dist/public/impact/coverage-depth-quality.d.ts +7 -0
- package/dist/public/impact/coverage-depth-quality.d.ts.map +1 -1
- package/dist/public/impact/coverage-depth-quality.js +59 -0
- package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
- package/dist/public/impact/full-kb-quality.js +3 -1
- package/dist/public/operations/catalog.d.ts +315 -11
- package/dist/public/operations/catalog.d.ts.map +1 -1
- package/dist/public/operations/check-executor.d.ts +2 -0
- package/dist/public/operations/check-executor.d.ts.map +1 -1
- package/dist/public/operations/check-executor.js +6 -0
- package/dist/public/operations/evidence-floor.d.ts +48 -0
- package/dist/public/operations/evidence-floor.d.ts.map +1 -0
- package/dist/public/operations/evidence-floor.js +143 -0
- package/dist/public/operations/migration-plan.d.ts +19 -5
- package/dist/public/operations/migration-plan.d.ts.map +1 -1
- package/dist/public/operations/migration-plan.js +22 -5
- package/dist/public/operations/node-ports.d.ts.map +1 -1
- package/dist/public/operations/node-ports.js +4 -1
- package/dist/public/operations/proof-contract-claims.d.ts +26 -0
- package/dist/public/operations/proof-contract-claims.d.ts.map +1 -0
- package/dist/public/operations/proof-contract-claims.js +71 -0
- package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
- package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
- package/dist/public/operations/specs/check-rules.generated.js +3 -1
- package/dist/public/operations/specs/check.d.ts +1 -1
- package/dist/public/operations/specs/composite.d.ts +16 -3
- package/dist/public/operations/specs/composite.d.ts.map +1 -1
- package/dist/public/operations/specs/modeling.d.ts +16 -3
- package/dist/public/operations/specs/modeling.d.ts.map +1 -1
- package/dist/public/operations/specs/modeling.js +22 -3
- package/dist/public/operations/specs/mutation-schemas.d.ts +289 -7
- package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
- package/dist/public/operations/specs/mutation-schemas.js +28 -4
- package/dist/public/operations/specs/proof.d.ts +9 -0
- package/dist/public/operations/specs/proof.d.ts.map +1 -1
- package/dist/public/operations/specs/reporting.d.ts.map +1 -1
- package/dist/public/operations/specs/reporting.js +19 -10
- package/dist/public/operations/specs/upsert.d.ts +289 -7
- package/dist/public/operations/specs/upsert.d.ts.map +1 -1
- package/dist/public/proof-certificates.d.ts +163 -0
- package/dist/public/proof-certificates.d.ts.map +1 -0
- package/dist/public/proof-certificates.js +419 -0
- package/dist/public/proof-protocol.d.ts +259 -3
- package/dist/public/proof-protocol.d.ts.map +1 -1
- package/dist/public/proof-protocol.js +524 -3
- package/dist/public/proof-receipt.d.ts +90 -6
- package/dist/public/proof-receipt.d.ts.map +1 -1
- package/dist/public/proof-receipt.js +88 -7
- package/dist/public/proof-sources.d.ts +102 -0
- package/dist/public/proof-sources.d.ts.map +1 -0
- package/dist/public/proof-sources.js +1292 -0
- package/dist/public/schemas/entity.d.ts.map +1 -1
- package/dist/public/schemas/entity.js +39 -2
- package/dist/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/dist/public/skills/kibi-commit-review/SKILL.md +8 -8
- package/dist/public/skills/kibi-commit-review/resources/staged-gate.md +12 -7
- package/dist/public/skills/kibi-decisions/SKILL.md +13 -2
- package/dist/public/skills/kibi-decisions/resources/decision-records.md +9 -1
- package/dist/public/skills/kibi-freshness/SKILL.md +5 -1
- package/dist/public/skills/kibi-traceability/SKILL.md +12 -1
- package/dist/public/skills/kibi-usage/SKILL.md +8 -4
- package/dist/public/skills/kibi-usage/resources/proof.md +221 -20
- package/dist/public/skills/kibi-usage/resources/workflows.md +4 -4
- package/dist/report/html-report.css +83 -11
- package/dist/report/html-report.d.ts +8 -0
- package/dist/report/html-report.d.ts.map +1 -1
- package/dist/report/html-report.js +214 -22
- package/dist/report/report-view.d.ts +2 -2
- package/dist/report/report-view.d.ts.map +1 -1
- package/dist/report/report-view.js +8 -0
- package/dist/schemas/entity.schema.json +404 -5
- package/dist/search-answer.d.ts.map +1 -1
- package/dist/search-answer.js +1 -0
- package/dist/signoff/html.d.ts.map +1 -1
- package/dist/signoff/html.js +3 -0
- package/dist/signoff/markdown.d.ts.map +1 -1
- package/dist/signoff/markdown.js +3 -0
- package/dist/signoff/model.d.ts +20 -0
- package/dist/signoff/model.d.ts.map +1 -1
- package/dist/signoff/model.js +20 -1
- package/dist/traceability/evidence-model.d.ts +13 -12
- package/dist/traceability/evidence-model.d.ts.map +1 -1
- package/dist/traceability/evidence-model.js +1 -1
- package/dist/traceability/impact-knowledge.d.ts.map +1 -1
- package/dist/traceability/impact-knowledge.js +1 -0
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-diagnostics.js +24 -20
- package/dist/traceability/staged-impact-contract.d.ts +4 -4
- package/dist/traceability/staged-impact-contract.js +9 -9
- package/dist/traceability/staged-symbols-manifest.d.ts +11 -3
- package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
- package/dist/traceability/staged-symbols-manifest.js +47 -140
- package/dist/traceability/temp-kb.d.ts.map +1 -1
- package/dist/traceability/temp-kb.js +1 -0
- package/dist/types/entities.d.ts +5 -2
- package/dist/types/entities.d.ts.map +1 -1
- package/dist/utils/merge-driver-setup.d.ts +8 -1
- package/dist/utils/merge-driver-setup.d.ts.map +1 -1
- package/dist/utils/merge-driver-setup.js +23 -2
- package/dist/utils/rule-registry.generated.d.ts +10 -0
- package/dist/utils/rule-registry.generated.d.ts.map +1 -1
- package/dist/utils/rule-registry.generated.js +12 -0
- package/dist/utils/schema-version.d.ts +1 -1
- package/dist/utils/schema-version.d.ts.map +1 -1
- package/dist/utils/schema-version.js +7 -1
- package/dist/utils/strict-modeling.d.ts +3 -2
- package/dist/utils/strict-modeling.d.ts.map +1 -1
- package/dist/utils/strict-modeling.js +37 -4
- package/dist/workspace-cwd.d.ts +15 -0
- package/dist/workspace-cwd.d.ts.map +1 -0
- package/dist/workspace-cwd.js +86 -0
- package/package.json +6 -2
- package/schema/entities.pl +6 -0
- package/schema/validation.pl +7 -2
- package/src/public/evidence-levels.ts +23 -0
- package/src/public/impact/coverage-depth-quality.ts +73 -0
- package/src/public/impact/full-kb-quality.ts +6 -1
- package/src/public/operations/check-executor.ts +13 -0
- package/src/public/operations/evidence-floor.ts +203 -0
- package/src/public/operations/migration-plan.ts +39 -6
- package/src/public/operations/node-ports.ts +3 -1
- package/src/public/operations/proof-contract-claims.ts +103 -0
- package/src/public/operations/specs/check-rules.generated.ts +3 -1
- package/src/public/operations/specs/modeling.ts +24 -5
- package/src/public/operations/specs/mutation-schemas.ts +30 -4
- package/src/public/operations/specs/reporting.ts +20 -10
- package/src/public/proof-certificates.ts +566 -0
- package/src/public/proof-protocol-types.d.ts +69 -1
- package/src/public/proof-protocol.ts +694 -3
- package/src/public/proof-receipt.ts +133 -7
- package/src/public/proof-sources.ts +1656 -0
- package/src/public/schemas/entity.ts +51 -3
- package/src/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/src/public/skills/kibi-commit-review/SKILL.md +8 -8
- package/src/public/skills/kibi-commit-review/resources/staged-gate.md +12 -7
- package/src/public/skills/kibi-decisions/SKILL.md +13 -2
- package/src/public/skills/kibi-decisions/resources/decision-records.md +9 -1
- package/src/public/skills/kibi-freshness/SKILL.md +5 -1
- package/src/public/skills/kibi-traceability/SKILL.md +12 -1
- package/src/public/skills/kibi-usage/SKILL.md +8 -4
- package/src/public/skills/kibi-usage/resources/proof.md +221 -20
- package/src/public/skills/kibi-usage/resources/workflows.md +4 -4
- package/src/schemas/entity.schema.json +404 -5
- package/dist/commands/proof-impact.d.ts +0 -7
- package/dist/commands/proof-impact.d.ts.map +0 -1
- package/dist/commands/proof-impact.js +0 -39
- package/dist/operations/proof/baseline-diff.d.ts +0 -41
- package/dist/operations/proof/baseline-diff.d.ts.map +0 -1
- package/dist/operations/proof/baseline-diff.js +0 -153
- package/dist/operations/proof/impact.d.ts +0 -51
- package/dist/operations/proof/impact.d.ts.map +0 -1
- package/dist/operations/proof/impact.js +0 -138
- package/dist/traceability/reviewed-coordinate-refresh.d.ts +0 -10
- package/dist/traceability/reviewed-coordinate-refresh.d.ts.map +0 -1
- package/dist/traceability/reviewed-coordinate-refresh.js +0 -49
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Kibi — repo-local, per-branch, queryable long-term memory for software projects
|
|
3
|
+
Copyright (C) 2026 Piotr Franczyk
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Builders for the kibi.code-certificate.v1 a certificate-kind proof contract
|
|
20
|
+
* leaves for `kibi prove`. A test builds its certificate and writes it with
|
|
21
|
+
* writeCodeCertificate; outside `kibi prove` the write is a no-op, so the same
|
|
22
|
+
* test runs unchanged in an ordinary test run. Kibi re-checks every
|
|
23
|
+
* certificate at ingest and again whenever it reports evidence, so a
|
|
24
|
+
* certificate only records what the test did; it never vouches for itself.
|
|
25
|
+
*/
|
|
26
|
+
import { createHash } from "node:crypto";
|
|
27
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
28
|
+
import path from "node:path";
|
|
29
|
+
import { evaluateSourceCode } from "../operations/proof/source-code-readers.js";
|
|
30
|
+
import { CODE_CERTIFICATE_VERSION } from "./proof-protocol.js";
|
|
31
|
+
import { describeSource, readSource, } from "./proof-sources.js";
|
|
32
|
+
/** Where `kibi prove` asks a run to leave its certificates. */
|
|
33
|
+
// implements REQ-kibi-code-proof-kinds
|
|
34
|
+
export const PROOF_CERTIFICATES_ENV = "KIBI_PROOF_CERTIFICATES";
|
|
35
|
+
function compareCodePoints(left, right) {
|
|
36
|
+
const a = Array.from(left, (char) => char.codePointAt(0) ?? 0);
|
|
37
|
+
const b = Array.from(right, (char) => char.codePointAt(0) ?? 0);
|
|
38
|
+
for (let index = 0; index < Math.min(a.length, b.length); index++) {
|
|
39
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
40
|
+
if (difference !== 0)
|
|
41
|
+
return difference;
|
|
42
|
+
}
|
|
43
|
+
return a.length - b.length;
|
|
44
|
+
}
|
|
45
|
+
const JSON_ESCAPES = {
|
|
46
|
+
'"': '\\"',
|
|
47
|
+
"\\": "\\\\",
|
|
48
|
+
"\b": "\\b",
|
|
49
|
+
"\f": "\\f",
|
|
50
|
+
"\n": "\\n",
|
|
51
|
+
"\r": "\\r",
|
|
52
|
+
"\t": "\\t",
|
|
53
|
+
};
|
|
54
|
+
function canonicalString(value) {
|
|
55
|
+
let out = '"';
|
|
56
|
+
for (let index = 0; index < value.length; index++) {
|
|
57
|
+
const char = value[index];
|
|
58
|
+
const unit = value.charCodeAt(index);
|
|
59
|
+
const escaped = JSON_ESCAPES[char];
|
|
60
|
+
if (escaped !== undefined)
|
|
61
|
+
out += escaped;
|
|
62
|
+
else if (unit >= 0x20 && unit <= 0x7e)
|
|
63
|
+
out += char;
|
|
64
|
+
else
|
|
65
|
+
out += `\\u${unit.toString(16).padStart(4, "0")}`;
|
|
66
|
+
}
|
|
67
|
+
return `${out}"`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The canonical JSON of a certificate, byte for byte what
|
|
71
|
+
* code_certificates.pl hashes: keys sorted by code point, no whitespace,
|
|
72
|
+
* non-ASCII and control characters as \u escapes of UTF-16 code units.
|
|
73
|
+
*/
|
|
74
|
+
// implements REQ-kibi-code-proof-kinds
|
|
75
|
+
export function canonicalCertificateJson(value) {
|
|
76
|
+
if (value === null || value === undefined)
|
|
77
|
+
return "null";
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
return `[${value.map(canonicalCertificateJson).join(",")}]`;
|
|
80
|
+
if (typeof value === "object")
|
|
81
|
+
return `{${Object.keys(value)
|
|
82
|
+
.sort(compareCodePoints)
|
|
83
|
+
.map((key) => `${canonicalString(key)}:${canonicalCertificateJson(value[key])}`)
|
|
84
|
+
.join(",")}}`;
|
|
85
|
+
if (typeof value === "string")
|
|
86
|
+
return canonicalString(value);
|
|
87
|
+
return JSON.stringify(value);
|
|
88
|
+
}
|
|
89
|
+
/** The sha256 a receipt records for its certificate. */
|
|
90
|
+
// implements REQ-kibi-code-proof-kinds
|
|
91
|
+
export function certificateDigest(certificate) {
|
|
92
|
+
return createHash("sha256")
|
|
93
|
+
.update(canonicalCertificateJson(certificate), "utf8")
|
|
94
|
+
.digest("hex");
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Run `check` on every member of a finite domain and record each outcome.
|
|
98
|
+
* `members` must be the domain as the code defines it (import it from its
|
|
99
|
+
* source, never restate it): Kibi rejects the certificate unless the proof
|
|
100
|
+
* file imports the contract's domain_source symbol.
|
|
101
|
+
*/
|
|
102
|
+
// implements REQ-kibi-code-proof-kinds
|
|
103
|
+
export async function exhaustiveCertificate(input) {
|
|
104
|
+
const key = input.key ?? ((member) => String(member));
|
|
105
|
+
const members = [...input.domain.members];
|
|
106
|
+
const results = [];
|
|
107
|
+
for (const member of members) {
|
|
108
|
+
try {
|
|
109
|
+
await input.check(member);
|
|
110
|
+
results.push({ member: key(member), outcome: "passed" });
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
results.push({
|
|
114
|
+
member: key(member),
|
|
115
|
+
outcome: "failed",
|
|
116
|
+
message: error instanceof Error ? error.message : String(error),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
122
|
+
kind: "exhaustive",
|
|
123
|
+
test_id: input.testId,
|
|
124
|
+
domain: {
|
|
125
|
+
symbol_id: input.domain.symbolId,
|
|
126
|
+
members: members.map(key),
|
|
127
|
+
},
|
|
128
|
+
results,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The members an exhaustive certificate records as failed. */
|
|
132
|
+
// implements REQ-kibi-code-proof-kinds
|
|
133
|
+
export function failedMembers(certificate) {
|
|
134
|
+
const results = Array.isArray(certificate.results)
|
|
135
|
+
? certificate.results
|
|
136
|
+
: [];
|
|
137
|
+
return results
|
|
138
|
+
.filter((result) => result.outcome !== "passed")
|
|
139
|
+
.map((result) => result.message ? `${result.member}: ${result.message}` : result.member);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A type checker accepted `witnessPath`, a file that fails to compile when a
|
|
143
|
+
* member of the domain goes unhandled (an exhaustive switch ending in a
|
|
144
|
+
* `never` assignment, or a mapped type over the domain).
|
|
145
|
+
*/
|
|
146
|
+
// implements REQ-kibi-code-proof-kinds
|
|
147
|
+
export function typecheckCertificate(input) {
|
|
148
|
+
const absolute = path.resolve(input.workspaceRoot ?? process.cwd(), input.witnessPath);
|
|
149
|
+
return {
|
|
150
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
151
|
+
kind: "typecheck",
|
|
152
|
+
test_id: input.testId,
|
|
153
|
+
domain: { symbol_id: input.domainSymbolId },
|
|
154
|
+
witness: {
|
|
155
|
+
path: input.witnessPath,
|
|
156
|
+
sha256: createHash("sha256")
|
|
157
|
+
.update(readFileSync(absolute, "utf8"))
|
|
158
|
+
.digest("hex"),
|
|
159
|
+
},
|
|
160
|
+
compiler: { ...input.compiler },
|
|
161
|
+
outcome: input.accepted ? "passed" : "failed",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A claim about one numeric variable that Kibi decides exactly: the
|
|
166
|
+
* assumptions must be satisfiable and must entail the claim for every value
|
|
167
|
+
* of the variable, not only the values a test happened to try.
|
|
168
|
+
*/
|
|
169
|
+
// implements REQ-kibi-code-proof-kinds
|
|
170
|
+
export function arithmeticCertificate(input) {
|
|
171
|
+
return {
|
|
172
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
173
|
+
kind: "arithmetic",
|
|
174
|
+
test_id: input.testId,
|
|
175
|
+
variable: input.variable,
|
|
176
|
+
value_type: input.valueType,
|
|
177
|
+
assumptions: input.assumptions.map((row) => ({ ...row })),
|
|
178
|
+
claim: { ...input.claim },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* An SMT-LIB query whose unsat answer proves the claim (the query asserts
|
|
183
|
+
* the claim's negation). Kibi re-runs the named solver on the query.
|
|
184
|
+
*/
|
|
185
|
+
// implements REQ-kibi-code-proof-kinds
|
|
186
|
+
export function smtCertificate(input) {
|
|
187
|
+
return {
|
|
188
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
189
|
+
kind: "smt",
|
|
190
|
+
test_id: input.testId,
|
|
191
|
+
solver: { ...input.solver },
|
|
192
|
+
query: input.query,
|
|
193
|
+
result: input.result,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const certificateText = (value) => typeof value === "string" ? value : String(value);
|
|
197
|
+
/**
|
|
198
|
+
* Call every predicate on every combination of its argument domains and
|
|
199
|
+
* record what the code decides. Import the domains and functions from their
|
|
200
|
+
* source (never restate them): Kibi evaluates the same exports at ingest and
|
|
201
|
+
* rejects a certificate whose tables differ, then model checks each claim's
|
|
202
|
+
* rule, predicate or set fact against the tables.
|
|
203
|
+
*/
|
|
204
|
+
// implements REQ-kibi-non-numeric-proof-kinds
|
|
205
|
+
export async function ruleCertificate(input) {
|
|
206
|
+
const values = {};
|
|
207
|
+
const domains = {};
|
|
208
|
+
for (const [type, domain] of Object.entries(input.domains)) {
|
|
209
|
+
values[type] = [...domain.members];
|
|
210
|
+
domains[type] = {
|
|
211
|
+
...(domain.symbolId !== undefined ? { symbol_id: domain.symbolId } : {}),
|
|
212
|
+
members: values[type].map(certificateText),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const predicates = {};
|
|
216
|
+
for (const [name, predicate] of Object.entries(input.predicates)) {
|
|
217
|
+
const lists = predicate.argTypes.map((type) => {
|
|
218
|
+
const list = values[type];
|
|
219
|
+
if (list === undefined)
|
|
220
|
+
throw new Error(`no domain for argument type ${type} of ${name}`);
|
|
221
|
+
return list;
|
|
222
|
+
});
|
|
223
|
+
const rows = [];
|
|
224
|
+
const count = lists.reduce((product, list) => product * list.length, 1);
|
|
225
|
+
for (let index = 0; index < count; index++) {
|
|
226
|
+
let rest = index;
|
|
227
|
+
const tuple = [];
|
|
228
|
+
for (let position = lists.length - 1; position >= 0; position--) {
|
|
229
|
+
const list = lists[position];
|
|
230
|
+
tuple[position] = list[rest % list.length];
|
|
231
|
+
rest = Math.floor(rest / list.length);
|
|
232
|
+
}
|
|
233
|
+
const args = tuple.map(certificateText);
|
|
234
|
+
try {
|
|
235
|
+
const value = await predicate.decide(...tuple);
|
|
236
|
+
rows.push(typeof value === "boolean"
|
|
237
|
+
? { args, value }
|
|
238
|
+
: { args, error: `returned ${typeof value}, not a boolean` });
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
rows.push({
|
|
242
|
+
args,
|
|
243
|
+
error: error instanceof Error ? error.message : String(error),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
predicates[name] = {
|
|
248
|
+
symbol_id: predicate.symbolId,
|
|
249
|
+
arg_types: [...predicate.argTypes],
|
|
250
|
+
rows,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
255
|
+
kind: "rule",
|
|
256
|
+
test_id: input.testId,
|
|
257
|
+
domains,
|
|
258
|
+
predicates,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** The calls of a rule certificate that threw or returned a non-boolean. */
|
|
262
|
+
// implements REQ-kibi-non-numeric-proof-kinds
|
|
263
|
+
export function failedCalls(certificate) {
|
|
264
|
+
const predicates = (certificate.predicates ?? {});
|
|
265
|
+
return Object.entries(predicates).flatMap(([name, table]) => (table.rows ?? [])
|
|
266
|
+
.filter((row) => row.error !== undefined)
|
|
267
|
+
.map((row) => `${name}(${row.args.join(", ")}): ${row.error}`));
|
|
268
|
+
}
|
|
269
|
+
function nextStates(next) {
|
|
270
|
+
if (next === null || next === undefined || next === false)
|
|
271
|
+
return [];
|
|
272
|
+
if (Array.isArray(next))
|
|
273
|
+
return next;
|
|
274
|
+
if (next instanceof Set)
|
|
275
|
+
return [...next];
|
|
276
|
+
if (next instanceof Map)
|
|
277
|
+
return [...next.values()];
|
|
278
|
+
if (typeof next === "object")
|
|
279
|
+
return Object.values(next);
|
|
280
|
+
return [next];
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Record a state machine as the code defines it: a transition table (an
|
|
284
|
+
* object or Map from each state to its next state, states, or event map; or
|
|
285
|
+
* a list of [from, to] pairs) or a next-state function called on every state
|
|
286
|
+
* and event (a throw, null or undefined means no transition). Kibi reads the
|
|
287
|
+
* same exports at ingest and checks each claim's transitions, reachability,
|
|
288
|
+
* initial and terminal states against the machine.
|
|
289
|
+
*/
|
|
290
|
+
// implements REQ-kibi-non-numeric-proof-kinds
|
|
291
|
+
export async function stateMachineCertificate(input) {
|
|
292
|
+
const states = new Set();
|
|
293
|
+
const edges = new Map();
|
|
294
|
+
const edge = (from, to) => {
|
|
295
|
+
const pair = [certificateText(from), certificateText(to)];
|
|
296
|
+
states.add(pair[0]);
|
|
297
|
+
states.add(pair[1]);
|
|
298
|
+
edges.set(pair.join("\u0000"), pair);
|
|
299
|
+
};
|
|
300
|
+
const table = input.transitions;
|
|
301
|
+
if (typeof table === "function") {
|
|
302
|
+
const events = [...(input.events ?? [])];
|
|
303
|
+
for (const state of input.states ?? []) {
|
|
304
|
+
states.add(certificateText(state));
|
|
305
|
+
for (const event of events) {
|
|
306
|
+
let next;
|
|
307
|
+
try {
|
|
308
|
+
next = await table(state, event);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
for (const target of nextStates(next))
|
|
314
|
+
edge(state, target);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else if (Array.isArray(table)) {
|
|
319
|
+
for (const entry of table) {
|
|
320
|
+
if (Array.isArray(entry) && entry.length === 2)
|
|
321
|
+
edge(entry[0], entry[1]);
|
|
322
|
+
else if (entry !== null && typeof entry === "object")
|
|
323
|
+
edge(entry.from, entry.to);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
const entries = table instanceof Map
|
|
328
|
+
? [...table.entries()]
|
|
329
|
+
: Object.entries(table);
|
|
330
|
+
for (const [from, next] of entries) {
|
|
331
|
+
states.add(certificateText(from));
|
|
332
|
+
for (const target of nextStates(next))
|
|
333
|
+
edge(from, target);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const initial = input.initial === undefined
|
|
337
|
+
? undefined
|
|
338
|
+
: (typeof input.initial === "object" && input.initial !== null
|
|
339
|
+
? [...input.initial]
|
|
340
|
+
: [input.initial])
|
|
341
|
+
.map(certificateText)
|
|
342
|
+
.sort();
|
|
343
|
+
return {
|
|
344
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
345
|
+
kind: "state_machine",
|
|
346
|
+
test_id: input.testId,
|
|
347
|
+
machine: {
|
|
348
|
+
symbol_id: input.symbolId,
|
|
349
|
+
states: [...states].sort(),
|
|
350
|
+
transitions: [...edges.values()].sort((a, b) => a.join("\u0000") < b.join("\u0000") ? -1 : 1),
|
|
351
|
+
...(initial !== undefined ? { initial } : {}),
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Record the pattern (a RegExp) or string constant a string claim is about.
|
|
357
|
+
* Kibi reads the same export at ingest and decides the claim exactly: a
|
|
358
|
+
* pattern's language against the fact's, or the string against the fact.
|
|
359
|
+
*/
|
|
360
|
+
// implements REQ-kibi-non-numeric-proof-kinds
|
|
361
|
+
export function regexCertificate(input) {
|
|
362
|
+
return {
|
|
363
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
364
|
+
kind: "regex",
|
|
365
|
+
test_id: input.testId,
|
|
366
|
+
pattern: typeof input.value === "string"
|
|
367
|
+
? { symbol_id: input.symbolId, type: "string", value: input.value }
|
|
368
|
+
: {
|
|
369
|
+
symbol_id: input.symbolId,
|
|
370
|
+
type: "regexp",
|
|
371
|
+
source: input.value.source,
|
|
372
|
+
flags: input.value.flags,
|
|
373
|
+
flavor: "js",
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* The certificate of a source proof. Kibi reads the contract's source
|
|
379
|
+
* itself at ingest and stores its own read, so the run only names the test
|
|
380
|
+
* and, optionally, the source (which must be the contract's). A run may also
|
|
381
|
+
* leave nothing: a passed source proof needs no certificate from the test.
|
|
382
|
+
*/
|
|
383
|
+
// implements REQ-kibi-source-proof-kinds
|
|
384
|
+
export function sourceCertificate(input) {
|
|
385
|
+
return {
|
|
386
|
+
version: CODE_CERTIFICATE_VERSION,
|
|
387
|
+
kind: "source",
|
|
388
|
+
test_id: input.testId,
|
|
389
|
+
...(input.source !== undefined ? { source: input.source } : {}),
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Read a project source the way Kibi does at ingest: the members (and the
|
|
394
|
+
* tables, objects or routes) of a JSON or YAML file, a glob, an OpenAPI
|
|
395
|
+
* document, the references the code makes, a data schema, a route table or
|
|
396
|
+
* a validator. A rule proof whose contract reads a domain from a source
|
|
397
|
+
* uses this to range its predicates over the same members.
|
|
398
|
+
*/
|
|
399
|
+
// implements REQ-kibi-source-proof-kinds
|
|
400
|
+
export async function readProjectSource(source, workspaceRoot = process.cwd()) {
|
|
401
|
+
const read = await readSource(workspaceRoot, source, evaluateSourceCode);
|
|
402
|
+
if (!read.ok)
|
|
403
|
+
throw new Error(`Kibi could not read ${describeSource(source)}: ${read.reason}`);
|
|
404
|
+
return read.model;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Leave the certificate where `kibi prove` reads it. Returns the file written,
|
|
408
|
+
* or null outside a `kibi prove` run.
|
|
409
|
+
*/
|
|
410
|
+
// implements REQ-kibi-code-proof-kinds
|
|
411
|
+
export function writeCodeCertificate(certificate, env = process.env) {
|
|
412
|
+
const directory = env[PROOF_CERTIFICATES_ENV];
|
|
413
|
+
if (directory === undefined || directory.trim() === "")
|
|
414
|
+
return null;
|
|
415
|
+
mkdirSync(directory, { recursive: true });
|
|
416
|
+
const file = path.join(directory, `${certificate.test_id.replace(/[^A-Za-z0-9._-]/g, "_")}.json`);
|
|
417
|
+
writeFileSync(file, `${JSON.stringify(certificate, null, 2)}\n`, "utf8");
|
|
418
|
+
return file;
|
|
419
|
+
}
|