kibi-cli 2.32.0 → 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.
Files changed (164) hide show
  1. package/dist/cli.d.ts.map +1 -1
  2. package/dist/cli.js +5 -1
  3. package/dist/commands/check-generated.d.ts +5 -1
  4. package/dist/commands/check-generated.d.ts.map +1 -1
  5. package/dist/commands/check-generated.js +24 -35
  6. package/dist/commands/init-helpers.d.ts.map +1 -1
  7. package/dist/commands/init-helpers.js +8 -5
  8. package/dist/commands/migrate.d.ts.map +1 -1
  9. package/dist/commands/migrate.js +23 -5
  10. package/dist/commands/sync/manifest.d.ts +10 -1
  11. package/dist/commands/sync/manifest.d.ts.map +1 -1
  12. package/dist/commands/sync/manifest.js +87 -14
  13. package/dist/commands/sync.d.ts.map +1 -1
  14. package/dist/commands/sync.js +19 -0
  15. package/dist/extractors/markdown.d.ts +1 -1
  16. package/dist/extractors/markdown.d.ts.map +1 -1
  17. package/dist/extractors/symbol-coordinates.js +2 -2
  18. package/dist/extractors/symbols-coordinator.d.ts +2 -4
  19. package/dist/extractors/symbols-coordinator.d.ts.map +1 -1
  20. package/dist/extractors/symbols-coordinator.js +1 -2
  21. package/dist/operations/migration/proof-contract-claims.d.ts +23 -10
  22. package/dist/operations/migration/proof-contract-claims.d.ts.map +1 -1
  23. package/dist/operations/migration/proof-contract-claims.js +35 -2
  24. package/dist/operations/migration/schema6.d.ts.map +1 -1
  25. package/dist/operations/migration/schema6.js +2 -4
  26. package/dist/operations/migration/symbol-coordinates-refresh.d.ts +3 -2
  27. package/dist/operations/migration/symbol-coordinates-refresh.d.ts.map +1 -1
  28. package/dist/operations/migration/symbol-coordinates-refresh.js +4 -3
  29. package/dist/operations/migration/untrack-symbol-coordinates.d.ts +23 -0
  30. package/dist/operations/migration/untrack-symbol-coordinates.d.ts.map +1 -0
  31. package/dist/operations/migration/untrack-symbol-coordinates.js +67 -0
  32. package/dist/operations/modeling/requirement-modeler.d.ts.map +1 -1
  33. package/dist/operations/modeling/requirement-modeler.js +48 -1
  34. package/dist/operations/modeling/requirement-types.d.ts +2 -1
  35. package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
  36. package/dist/operations/modeling/requirement-utils.d.ts +1 -1
  37. package/dist/operations/modeling/requirement-utils.d.ts.map +1 -1
  38. package/dist/operations/modeling/requirement-utils.js +8 -1
  39. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  40. package/dist/operations/mutation/source-authoring.js +39 -20
  41. package/dist/operations/proof/claim-bindings.d.ts +18 -0
  42. package/dist/operations/proof/claim-bindings.d.ts.map +1 -1
  43. package/dist/operations/proof/claim-bindings.js +157 -4
  44. package/dist/operations/proof/code-certificates.d.ts +34 -14
  45. package/dist/operations/proof/code-certificates.d.ts.map +1 -1
  46. package/dist/operations/proof/code-certificates.js +266 -157
  47. package/dist/operations/proof/code-models.d.ts +96 -0
  48. package/dist/operations/proof/code-models.d.ts.map +1 -0
  49. package/dist/operations/proof/code-models.js +601 -0
  50. package/dist/operations/proof/code-runner.d.ts +40 -0
  51. package/dist/operations/proof/code-runner.d.ts.map +1 -0
  52. package/dist/operations/proof/code-runner.js +164 -0
  53. package/dist/operations/proof/code-scope.d.ts +3 -0
  54. package/dist/operations/proof/code-scope.d.ts.map +1 -1
  55. package/dist/operations/proof/code-scope.js +26 -2
  56. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  57. package/dist/operations/proof/ingest-proof.js +2 -1
  58. package/dist/operations/proof/regular-language.d.ts +89 -0
  59. package/dist/operations/proof/regular-language.d.ts.map +1 -0
  60. package/dist/operations/proof/regular-language.js +943 -0
  61. package/dist/operations/proof/source-code-readers.d.ts +12 -0
  62. package/dist/operations/proof/source-code-readers.d.ts.map +1 -0
  63. package/dist/operations/proof/source-code-readers.js +699 -0
  64. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  65. package/dist/operations/semantic-advisor/analyze-prose.js +2 -1
  66. package/dist/operations/semantic-advisor/strict-count-rules.d.ts.map +1 -1
  67. package/dist/operations/semantic-advisor/strict-count-rules.js +8 -2
  68. package/dist/operations/semantic-advisor/strict-rules.d.ts +8 -0
  69. package/dist/operations/semantic-advisor/strict-rules.d.ts.map +1 -1
  70. package/dist/operations/semantic-advisor/strict-rules.js +231 -1
  71. package/dist/operations/semantic-advisor/types.d.ts +1 -1
  72. package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
  73. package/dist/prolog.d.ts.map +1 -1
  74. package/dist/prolog.js +13 -3
  75. package/dist/public/operations/catalog.d.ts +156 -13
  76. package/dist/public/operations/catalog.d.ts.map +1 -1
  77. package/dist/public/operations/evidence-floor.js +1 -1
  78. package/dist/public/operations/proof-contract-claims.js +1 -1
  79. package/dist/public/operations/specs/composite.d.ts +16 -3
  80. package/dist/public/operations/specs/composite.d.ts.map +1 -1
  81. package/dist/public/operations/specs/modeling.d.ts +16 -3
  82. package/dist/public/operations/specs/modeling.d.ts.map +1 -1
  83. package/dist/public/operations/specs/modeling.js +22 -3
  84. package/dist/public/operations/specs/mutation-schemas.d.ts +140 -10
  85. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  86. package/dist/public/operations/specs/mutation-schemas.js +14 -3
  87. package/dist/public/operations/specs/upsert.d.ts +140 -10
  88. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  89. package/dist/public/proof-certificates.d.ts +75 -1
  90. package/dist/public/proof-certificates.d.ts.map +1 -1
  91. package/dist/public/proof-certificates.js +212 -0
  92. package/dist/public/proof-protocol.d.ts +143 -10
  93. package/dist/public/proof-protocol.d.ts.map +1 -1
  94. package/dist/public/proof-protocol.js +301 -16
  95. package/dist/public/proof-receipt.d.ts +4 -3
  96. package/dist/public/proof-receipt.d.ts.map +1 -1
  97. package/dist/public/proof-receipt.js +6 -1
  98. package/dist/public/proof-sources.d.ts +102 -0
  99. package/dist/public/proof-sources.d.ts.map +1 -0
  100. package/dist/public/proof-sources.js +1292 -0
  101. package/dist/public/schemas/entity.d.ts.map +1 -1
  102. package/dist/public/schemas/entity.js +21 -1
  103. package/dist/public/skills/kibi-commit-review/SKILL.md +8 -8
  104. package/dist/public/skills/kibi-commit-review/resources/staged-gate.md +6 -6
  105. package/dist/public/skills/kibi-decisions/SKILL.md +5 -2
  106. package/dist/public/skills/kibi-decisions/resources/decision-records.md +4 -1
  107. package/dist/public/skills/kibi-freshness/SKILL.md +2 -2
  108. package/dist/public/skills/kibi-traceability/SKILL.md +3 -2
  109. package/dist/public/skills/kibi-usage/SKILL.md +5 -3
  110. package/dist/public/skills/kibi-usage/resources/proof.md +105 -9
  111. package/dist/report/html-report.css +45 -10
  112. package/dist/report/html-report.d.ts.map +1 -1
  113. package/dist/report/html-report.js +74 -17
  114. package/dist/report/report-view.d.ts +1 -1
  115. package/dist/report/report-view.d.ts.map +1 -1
  116. package/dist/report/report-view.js +1 -0
  117. package/dist/schemas/entity.schema.json +199 -8
  118. package/dist/traceability/evidence-model.d.ts +13 -12
  119. package/dist/traceability/evidence-model.d.ts.map +1 -1
  120. package/dist/traceability/evidence-model.js +1 -1
  121. package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
  122. package/dist/traceability/staged-diagnostics.js +24 -20
  123. package/dist/traceability/staged-impact-contract.d.ts +4 -4
  124. package/dist/traceability/staged-impact-contract.js +9 -9
  125. package/dist/traceability/staged-symbols-manifest.d.ts +11 -3
  126. package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
  127. package/dist/traceability/staged-symbols-manifest.js +47 -140
  128. package/dist/types/entities.d.ts +1 -1
  129. package/dist/types/entities.d.ts.map +1 -1
  130. package/dist/utils/rule-registry.generated.d.ts +1 -1
  131. package/dist/utils/rule-registry.generated.js +1 -1
  132. package/dist/utils/schema-version.d.ts +1 -1
  133. package/dist/utils/schema-version.d.ts.map +1 -1
  134. package/dist/utils/schema-version.js +3 -1
  135. package/dist/utils/strict-modeling.d.ts +3 -2
  136. package/dist/utils/strict-modeling.d.ts.map +1 -1
  137. package/dist/utils/strict-modeling.js +37 -4
  138. package/dist/workspace-cwd.d.ts +15 -0
  139. package/dist/workspace-cwd.d.ts.map +1 -0
  140. package/dist/workspace-cwd.js +86 -0
  141. package/package.json +2 -2
  142. package/schema/validation.pl +3 -1
  143. package/src/public/operations/evidence-floor.ts +1 -1
  144. package/src/public/operations/proof-contract-claims.ts +1 -1
  145. package/src/public/operations/specs/modeling.ts +24 -5
  146. package/src/public/operations/specs/mutation-schemas.ts +14 -3
  147. package/src/public/proof-certificates.ts +296 -1
  148. package/src/public/proof-protocol-types.d.ts +54 -2
  149. package/src/public/proof-protocol.ts +396 -20
  150. package/src/public/proof-receipt.ts +8 -2
  151. package/src/public/proof-sources.ts +1656 -0
  152. package/src/public/schemas/entity.ts +32 -2
  153. package/src/public/skills/kibi-commit-review/SKILL.md +8 -8
  154. package/src/public/skills/kibi-commit-review/resources/staged-gate.md +6 -6
  155. package/src/public/skills/kibi-decisions/SKILL.md +5 -2
  156. package/src/public/skills/kibi-decisions/resources/decision-records.md +4 -1
  157. package/src/public/skills/kibi-freshness/SKILL.md +2 -2
  158. package/src/public/skills/kibi-traceability/SKILL.md +3 -2
  159. package/src/public/skills/kibi-usage/SKILL.md +5 -3
  160. package/src/public/skills/kibi-usage/resources/proof.md +105 -9
  161. package/src/schemas/entity.schema.json +199 -8
  162. package/dist/traceability/reviewed-coordinate-refresh.d.ts +0 -10
  163. package/dist/traceability/reviewed-coordinate-refresh.d.ts.map +0 -1
  164. package/dist/traceability/reviewed-coordinate-refresh.js +0 -49
@@ -63,8 +63,11 @@ export const SUCCESS_POLICIES = [
63
63
  /**
64
64
  * What a proof contract's checker establishes. Runner kinds (e2e, example,
65
65
  * property) sample cases and support tested evidence; certificate kinds
66
- * (exhaustive, typecheck, arithmetic, smt) cover every case and support
67
- * proved evidence once Kibi re-checks the certificate the run left.
66
+ * (exhaustive, typecheck, arithmetic, smt, rule, state_machine, regex,
67
+ * source) cover every case and support proved evidence once Kibi re-checks
68
+ * the certificate the run left. A source certificate is Kibi's own read of a
69
+ * project source (a JSON or YAML file, a glob, an OpenAPI document, the
70
+ * references the code makes, a data schema, a route table, a validator).
68
71
  */
69
72
  // implements REQ-kibi-code-proof-kinds
70
73
  export const PROOF_KINDS = [
@@ -75,18 +78,27 @@ export const PROOF_KINDS = [
75
78
  "typecheck",
76
79
  "arithmetic",
77
80
  "smt",
81
+ "rule",
82
+ "state_machine",
83
+ "regex",
84
+ "source",
78
85
  ];
79
- // implements REQ-kibi-code-proof-kinds
86
+ // implements REQ-kibi-code-proof-kinds, REQ-kibi-non-numeric-proof-kinds, REQ-kibi-source-proof-kinds
80
87
  export const CERTIFICATE_PROOF_KINDS = [
81
88
  "exhaustive",
82
89
  "typecheck",
83
90
  "arithmetic",
84
91
  "smt",
92
+ "rule",
93
+ "state_machine",
94
+ "regex",
95
+ "source",
85
96
  ];
86
97
  // implements REQ-kibi-code-proof-kinds
87
98
  export function isCertificateProofKind(kind) {
88
99
  return CERTIFICATE_PROOF_KINDS.includes(kind);
89
100
  }
101
+ import { SOURCE_READERS, normalizeSourceSpec, sourceSpecErrors, } from "./proof-sources.js";
90
102
  export const PROOF_RESULT_SCHEMA = {
91
103
  type: "object",
92
104
  description: "One observed proof result. binding distinguishes native-case observations from aggregate-run bindings; attempts must report facts only.",
@@ -215,6 +227,50 @@ export const PROOF_RUN_ARTIFACT_SCHEMA = {
215
227
  },
216
228
  additionalProperties: false,
217
229
  };
230
+ const SOURCE_REFERENCE_SCHEMA = {
231
+ type: "object",
232
+ required: ["symbol_id"],
233
+ properties: {
234
+ symbol_id: { type: "string", minLength: 1 },
235
+ export: { type: "string", minLength: 1 },
236
+ },
237
+ additionalProperties: false,
238
+ };
239
+ // implements REQ-kibi-source-proof-kinds
240
+ const SOURCE_SPEC_SCHEMA = {
241
+ type: "object",
242
+ description: "A project source Kibi reads by itself. reader json or yaml: {file, path?, select?: keys|values|items}. glob: {pattern, capture?, ignore?} (capture true reads what each * matched). openapi: {file, select?: operations|unsecured_operations|security_schemes|responses}. references: {files, extract: env|imports|calls|string_args|thrown|property, callee?, key?, ignore?}. schema: {format: drizzle|prisma|sql, file (drizzle, prisma) or files (sql migrations), exports?, table?, select?: tables|columns|required_columns|nullable_columns|foreign_keys}. routes: {file, export, framework?: hono|express, path_prefix?, names_from?, select?: routes|middleware}. validator: {file, export, select?: fields|required_fields|optional_fields}. Paths are repository-relative. A member Kibi cannot read statically fails the read with its location.",
243
+ required: ["reader"],
244
+ properties: {
245
+ reader: { type: "string", enum: [...SOURCE_READERS] },
246
+ },
247
+ additionalProperties: true,
248
+ };
249
+ const SOURCE_DOMAIN_SCHEMA = {
250
+ type: "object",
251
+ required: ["source"],
252
+ properties: { source: SOURCE_SPEC_SCHEMA },
253
+ additionalProperties: false,
254
+ };
255
+ const PREDICATE_SOURCE_SCHEMA = {
256
+ type: "object",
257
+ required: ["symbol_id"],
258
+ properties: {
259
+ symbol_id: { type: "string", minLength: 1 },
260
+ export: {
261
+ type: "string",
262
+ minLength: 1,
263
+ description: "The exported function's name in the symbol's source file. Without it Kibi reads the export named by the symbol's title.",
264
+ },
265
+ harness_for: {
266
+ type: "array",
267
+ minItems: 1,
268
+ items: { type: "string", minLength: 1 },
269
+ description: "The predicate is a test harness that decides the predicate by driving these code symbols (for example by calling the handler with each role). The symbols must be covered_by the test; a claim the harness proves is bound with scope harness.",
270
+ },
271
+ },
272
+ additionalProperties: false,
273
+ };
218
274
  export const PROOF_CONTRACT_SCHEMA = {
219
275
  type: "object",
220
276
  description: "Semantic proof contract binding a test to explicit proof obligations executed by a configured integration.",
@@ -240,11 +296,15 @@ export const PROOF_CONTRACT_SCHEMA = {
240
296
  kind: {
241
297
  type: "string",
242
298
  enum: [...PROOF_KINDS],
243
- description: "What the checker establishes; absent means e2e. exhaustive, typecheck, arithmetic and smt must leave a kibi.code-certificate.v1 that Kibi re-checks before the receipt counts as proved.",
299
+ description: "What the checker establishes; absent means e2e. exhaustive, typecheck, arithmetic, smt, rule, state_machine and regex must leave a kibi.code-certificate.v1 that Kibi re-checks before the receipt counts as proved. source reads the contract's source itself: the run may leave {version, kind: source, test_id, source} or nothing, and Kibi stores its own read as the certificate.",
300
+ },
301
+ source: {
302
+ ...SOURCE_SPEC_SCHEMA,
303
+ description: `source: the project source a source proof reads. ${SOURCE_SPEC_SCHEMA.description}`,
244
304
  },
245
305
  domain_source: {
246
306
  type: "object",
247
- description: "exhaustive and typecheck: the symbol that defines the finite domain. The proof must import it from its source file; a hand-listed domain downgrades the receipt to example. Kibi reads the export named `export`, or the symbol's title when `export` is absent.",
307
+ description: "exhaustive and typecheck: the symbol that defines the finite domain (typecheck: also the type whose fields a required_fields fact names). state_machine: the transition table or next-state function. The proof must import it from its source file; a hand-listed domain downgrades the receipt to example. Kibi reads the export named `export`, or the symbol's title when `export` is absent.",
248
308
  required: ["symbol_id"],
249
309
  properties: {
250
310
  symbol_id: { type: "string", minLength: 1 },
@@ -265,25 +325,52 @@ export const PROOF_CONTRACT_SCHEMA = {
265
325
  },
266
326
  proves: {
267
327
  type: "array",
268
- description: "Certificate kinds: the requirement claim keys (CLAIM-...) this certificate proves. Each must be a modeled claim of a current requirement the test reaches through its scenarios. Kibi derives what the certificate must establish from the claim's grounding fact (a set fact for exhaustive or typecheck, a numeric fact for arithmetic or smt); a claim with no such derivation is only attested and never counts as proved.",
328
+ description: "Certificate kinds: the requirement claim keys (CLAIM-...) this certificate proves. Each must be a modeled claim of a current requirement the test reaches through its scenarios. Kibi derives what the certificate must establish from the claim's grounding fact (a set fact for exhaustive or typecheck, a numeric fact for arithmetic or smt, a rule, predicate or set fact for rule and state_machine, a string fact for regex); a claim with no such derivation is only attested and never counts as proved.",
269
329
  minItems: 1,
270
330
  items: { type: "string", pattern: "^CLAIM-" },
271
331
  uniqueItems: true,
272
332
  },
273
333
  value_source: {
274
334
  type: "array",
275
- description: "arithmetic and smt: code constants the assumptions read. Kibi evaluates each export at ingest and requires the certificate to assume the variable equals that value, so the proof is about the code and not only the knowledge base.",
335
+ description: "arithmetic and smt: code constants the assumptions read. Kibi evaluates each export at ingest and requires the certificate to assume the variable equals that value, so the proof is about the code and not only the knowledge base. With measure count the value is the size of a list, set, map or object export, so a count claim reads the collection itself. An entry {source, measure: count} counts the members Kibi reads from a project source (routes, tables, environment variables).",
276
336
  minItems: 1,
277
337
  items: {
278
338
  type: "object",
279
- required: ["symbol_id"],
280
339
  properties: {
281
340
  symbol_id: { type: "string", minLength: 1 },
282
341
  export: { type: "string", minLength: 1 },
342
+ source: SOURCE_SPEC_SCHEMA,
343
+ measure: {
344
+ type: "string",
345
+ enum: ["value", "count"],
346
+ description: "value (default for an export): the export is a number. count (the only measure of a source): the number of members of a list, set, map or object export, or of a source.",
347
+ },
283
348
  },
284
349
  additionalProperties: false,
285
350
  },
286
351
  },
352
+ predicate_source: {
353
+ type: "object",
354
+ description: "rule: the code function behind each predicate a claim's rule, predicate or set fact names, keyed by predicate name. Each export takes the predicate's arguments in order and returns a boolean; Kibi calls it on every combination of its argument domains.",
355
+ minProperties: 1,
356
+ additionalProperties: PREDICATE_SOURCE_SCHEMA,
357
+ },
358
+ domains: {
359
+ type: "object",
360
+ description: "rule: the finite domain of each argument type, keyed by type name (an array, Set, Map or object export, or a Python list, set, dict or Enum), or {source} for the members Kibi reads from a project source (every route, every table, every environment variable). state_machine with a next-state function: the `state` and `event` domains it is called on.",
361
+ minProperties: 1,
362
+ additionalProperties: {
363
+ anyOf: [SOURCE_REFERENCE_SCHEMA, SOURCE_DOMAIN_SCHEMA],
364
+ },
365
+ },
366
+ initial_source: {
367
+ ...SOURCE_REFERENCE_SCHEMA,
368
+ description: "state_machine: the export holding the initial state (or states), needed for initial_states and reachable_states facts.",
369
+ },
370
+ pattern_source: {
371
+ ...SOURCE_REFERENCE_SCHEMA,
372
+ description: "regex: the export holding the code's pattern (a RegExp, or a Python re.Pattern) or string constant that a string fact is about.",
373
+ },
287
374
  constraint_source: {
288
375
  type: "object",
289
376
  description: "arithmetic and smt: the typed numeric property_value facts the certificate's assumptions come from. Kibi checks the assumptions (or the query's assertions) are exactly these facts' constraints, so the proof is about the knowledge base, not numbers the test chose.",
@@ -591,19 +678,37 @@ function proofContractKindErrors(contract) {
591
678
  errors.push(`proof_contract.constraint_source or value_source is required for kind ${String(kind)}: name the typed facts or code constants its assumptions come from`);
592
679
  const valueSource = contract.value_source;
593
680
  if (valueSource !== undefined) {
681
+ if (Array.isArray(valueSource))
682
+ valueSource.forEach((entry, index) => {
683
+ const row = record(entry);
684
+ if (row === null || row.source === undefined)
685
+ return;
686
+ errors.push(...sourceSpecErrors(row.source, `proof_contract.value_source[${index}].source`));
687
+ if (row.symbol_id !== undefined || row.export !== undefined)
688
+ errors.push(`proof_contract.value_source[${index}] names a source, so it takes no symbol_id or export`);
689
+ if (row.measure !== undefined && row.measure !== "count")
690
+ errors.push(`proof_contract.value_source[${index}].measure must be count for a source: Kibi counts the members it reads`);
691
+ });
594
692
  if (!Array.isArray(valueSource) ||
595
693
  valueSource.length === 0 ||
596
694
  !valueSource.every((entry) => {
597
695
  const row = record(entry);
696
+ if (row !== null && row.source !== undefined)
697
+ return true;
598
698
  return (row !== null &&
599
699
  nonEmptyString(row.symbol_id) &&
600
700
  (row.export === undefined || nonEmptyString(row.export)) &&
601
- Object.keys(row).every((key) => key === "symbol_id" || key === "export"));
701
+ (row.measure === undefined ||
702
+ row.measure === "value" ||
703
+ row.measure === "count") &&
704
+ Object.keys(row).every((key) => key === "symbol_id" || key === "export" || key === "measure"));
602
705
  }))
603
- errors.push("proof_contract.value_source must be [{symbol_id, export?}] naming the code constants the assumptions read");
706
+ errors.push("proof_contract.value_source must be [{symbol_id, export?, measure?: value|count} or {source, measure?: count}] naming the code constants or project sources the assumptions read");
604
707
  else if (kind !== "arithmetic" && kind !== "smt")
605
708
  errors.push(`proof_contract.value_source applies only to kind arithmetic or smt, not ${String(kind ?? "e2e")}`);
606
709
  }
710
+ errors.push(...nonNumericContractErrors(contract));
711
+ errors.push(...sourceContractErrors(contract));
607
712
  const proves = contract.proves;
608
713
  if (proves !== undefined) {
609
714
  if (!Array.isArray(proves) ||
@@ -612,8 +717,104 @@ function proofContractKindErrors(contract) {
612
717
  new Set(proves).size !== proves.length)
613
718
  errors.push("proof_contract.proves must be a non-empty list of distinct claim keys (CLAIM-...) the certificate proves");
614
719
  else if (!isCertificateProofKind(kind))
615
- errors.push(`proof_contract.proves applies only to certificate kinds (exhaustive, typecheck, arithmetic, smt), not ${String(kind ?? "e2e")}`);
720
+ errors.push(`proof_contract.proves applies only to certificate kinds (${CERTIFICATE_PROOF_KINDS.join(", ")}), not ${String(kind ?? "e2e")}`);
721
+ }
722
+ return errors;
723
+ }
724
+ function isSourceReference(value) {
725
+ const row = record(value);
726
+ return (row !== null &&
727
+ nonEmptyString(row.symbol_id) &&
728
+ (row.export === undefined || nonEmptyString(row.export)) &&
729
+ Object.keys(row).every((key) => key === "symbol_id" || key === "export"));
730
+ }
731
+ function isSourceMap(value, accepts = isSourceReference) {
732
+ const row = record(value);
733
+ return (row !== null &&
734
+ Object.keys(row).length > 0 &&
735
+ Object.entries(row).every(([key, entry]) => key.trim() !== "" && accepts(entry)));
736
+ }
737
+ function isPredicateReference(value) {
738
+ const row = record(value);
739
+ if (row === null || row.harness_for === undefined)
740
+ return isSourceReference(value);
741
+ const { harness_for: harness, ...reference } = row;
742
+ return (isSourceReference(reference) &&
743
+ Array.isArray(harness) &&
744
+ harness.length > 0 &&
745
+ harness.every(nonEmptyString));
746
+ }
747
+ function isSourceDomain(value) {
748
+ const row = record(value);
749
+ return (row !== null && Object.keys(row).length === 1 && row.source !== undefined);
750
+ }
751
+ /**
752
+ * The source kind and the source-backed rule domains: a well-formed source
753
+ * spec, required for kind source and only there.
754
+ */
755
+ // implements REQ-kibi-source-proof-kinds
756
+ function sourceContractErrors(contract) {
757
+ const errors = [];
758
+ const kind = contract.kind;
759
+ if (contract.source !== undefined) {
760
+ errors.push(...sourceSpecErrors(contract.source, "proof_contract.source"));
761
+ if (kind !== "source")
762
+ errors.push(`proof_contract.source applies only to kind source, not ${String(kind ?? "e2e")}`);
763
+ }
764
+ else if (kind === "source")
765
+ errors.push("proof_contract.source is required for kind source: name the project source Kibi reads (reader json, yaml, glob, openapi, references, schema, routes or validator)");
766
+ const domains = record(contract.domains);
767
+ for (const [type, entry] of Object.entries(domains ?? {}))
768
+ if (isSourceDomain(entry)) {
769
+ errors.push(...sourceSpecErrors(record(entry)?.source, `proof_contract.domains.${type}.source`));
770
+ if (kind !== "rule")
771
+ errors.push(`proof_contract.domains.${type}.source applies only to kind rule: a state machine's domains are the code's`);
772
+ }
773
+ return errors;
774
+ }
775
+ /**
776
+ * The contract fields of the rule, state_machine and regex kinds: where the
777
+ * code Kibi evaluates lives, and only on the kinds that read it.
778
+ */
779
+ // implements REQ-kibi-non-numeric-proof-kinds
780
+ function nonNumericContractErrors(contract) {
781
+ const errors = [];
782
+ const kind = contract.kind;
783
+ const only = (field, kinds) => {
784
+ if (contract[field] !== undefined && !kinds.includes(String(kind)))
785
+ errors.push(`proof_contract.${field} applies only to kind ${kinds.join(" or ")}, not ${String(kind ?? "e2e")}`);
786
+ };
787
+ if (contract.predicate_source !== undefined &&
788
+ !isSourceMap(contract.predicate_source, isPredicateReference))
789
+ errors.push("proof_contract.predicate_source must map each predicate name to {symbol_id, export?, harness_for?} naming the function that decides it");
790
+ if (contract.domains !== undefined &&
791
+ !isSourceMap(contract.domains, (entry) => isSourceReference(entry) || isSourceDomain(entry)))
792
+ errors.push("proof_contract.domains must map each argument type to {symbol_id, export?} naming the export that lists its values, or {source} naming the project source Kibi reads them from");
793
+ for (const field of ["initial_source", "pattern_source"])
794
+ if (contract[field] !== undefined && !isSourceReference(contract[field]))
795
+ errors.push(`proof_contract.${field} must be {symbol_id, export?} naming the export Kibi reads`);
796
+ only("predicate_source", ["rule"]);
797
+ only("domains", ["rule", "state_machine"]);
798
+ only("initial_source", ["state_machine"]);
799
+ only("pattern_source", ["regex"]);
800
+ if (kind === "rule") {
801
+ if (contract.predicate_source === undefined)
802
+ errors.push("proof_contract.predicate_source is required for kind rule: name the function behind each predicate the claims use");
803
+ if (contract.domains === undefined)
804
+ errors.push("proof_contract.domains is required for kind rule: name the export listing each argument type's values");
805
+ }
806
+ if (kind === "state_machine") {
807
+ if (contract.domain_source === undefined)
808
+ errors.push("proof_contract.domain_source is required for kind state_machine: name the transition table or next-state function");
809
+ const domains = record(contract.domains);
810
+ if (domains !== null &&
811
+ (Object.keys(domains).length !== 2 ||
812
+ domains.state === undefined ||
813
+ domains.event === undefined))
814
+ errors.push("proof_contract.domains for kind state_machine must name exactly the state and event domains a next-state function is called on");
616
815
  }
816
+ if (kind === "regex" && contract.pattern_source === undefined)
817
+ errors.push("proof_contract.pattern_source is required for kind regex: name the export holding the pattern or string");
617
818
  return errors;
618
819
  }
619
820
  /**
@@ -642,15 +843,99 @@ export function optionalProofContractFields(contract) {
642
843
  if (Array.isArray(contract.value_source))
643
844
  fields.value_source = contract.value_source
644
845
  .map((entry) => record(entry))
645
- .filter((row) => row !== null && typeof row.symbol_id === "string")
646
- .map((row) => ({
647
- symbol_id: String(row.symbol_id),
648
- ...(typeof row.export === "string" ? { export: row.export } : {}),
649
- }));
846
+ .map((row) => {
847
+ if (row === null)
848
+ return null;
849
+ const spec = normalizeSourceSpec(row.source);
850
+ if (spec !== undefined)
851
+ return { source: spec, measure: "count" };
852
+ if (typeof row.symbol_id !== "string")
853
+ return null;
854
+ return {
855
+ symbol_id: row.symbol_id,
856
+ ...(typeof row.export === "string" ? { export: row.export } : {}),
857
+ ...(row.measure === "value" || row.measure === "count"
858
+ ? { measure: row.measure }
859
+ : {}),
860
+ };
861
+ })
862
+ .filter((row) => row !== null);
650
863
  if (Array.isArray(contract.proves))
651
864
  fields.proves = contract.proves.filter((key) => typeof key === "string");
865
+ const predicates = predicateMap(contract.predicate_source);
866
+ if (predicates !== undefined)
867
+ fields.predicate_source = predicates;
868
+ const domains = domainMap(contract.domains);
869
+ if (domains !== undefined)
870
+ fields.domains = domains;
871
+ const spec = normalizeSourceSpec(contract.source);
872
+ if (spec !== undefined)
873
+ fields.source = spec;
874
+ const initial = sourceReference(contract.initial_source);
875
+ if (initial !== undefined)
876
+ fields.initial_source = initial;
877
+ const pattern = sourceReference(contract.pattern_source);
878
+ if (pattern !== undefined)
879
+ fields.pattern_source = pattern;
652
880
  return fields;
653
881
  }
882
+ function predicateMap(value) {
883
+ const row = record(value);
884
+ if (!row)
885
+ return undefined;
886
+ const out = {};
887
+ for (const [key, entry] of Object.entries(row)) {
888
+ const reference = sourceReference(entry);
889
+ if (reference === undefined)
890
+ continue;
891
+ const harness = record(entry)?.harness_for;
892
+ out[key] = Array.isArray(harness)
893
+ ? {
894
+ ...reference,
895
+ harness_for: harness.filter((id) => typeof id === "string"),
896
+ }
897
+ : reference;
898
+ }
899
+ return Object.keys(out).length > 0 ? out : undefined;
900
+ }
901
+ function domainMap(value) {
902
+ const row = record(value);
903
+ if (!row)
904
+ return undefined;
905
+ const out = {};
906
+ for (const [key, entry] of Object.entries(row)) {
907
+ const spec = normalizeSourceSpec(record(entry)?.source);
908
+ if (spec !== undefined) {
909
+ out[key] = { source: spec };
910
+ continue;
911
+ }
912
+ const reference = sourceReference(entry);
913
+ if (reference !== undefined)
914
+ out[key] = reference;
915
+ }
916
+ return Object.keys(out).length > 0 ? out : undefined;
917
+ }
918
+ function sourceReference(value) {
919
+ const row = record(value);
920
+ if (!row || typeof row.symbol_id !== "string")
921
+ return undefined;
922
+ return {
923
+ symbol_id: row.symbol_id,
924
+ ...(typeof row.export === "string" ? { export: row.export } : {}),
925
+ };
926
+ }
927
+ function sourceMap(value) {
928
+ const row = record(value);
929
+ if (!row)
930
+ return undefined;
931
+ const out = {};
932
+ for (const [key, entry] of Object.entries(row)) {
933
+ const reference = sourceReference(entry);
934
+ if (reference !== undefined)
935
+ out[key] = reference;
936
+ }
937
+ return Object.keys(out).length > 0 ? out : undefined;
938
+ }
654
939
  export function proofBindingsErrors(value) {
655
940
  if (!Array.isArray(value))
656
941
  return ["proof_bindings must be an array of binding objects"];
@@ -200,7 +200,7 @@ export declare const PROOF_RECEIPT_SCHEMA: {
200
200
  };
201
201
  readonly kind: {
202
202
  readonly type: "string";
203
- readonly enum: readonly ["e2e", "example", "property", "exhaustive", "typecheck", "arithmetic", "smt"];
203
+ readonly enum: readonly ["e2e", "example", "property", "exhaustive", "typecheck", "arithmetic", "smt", "rule", "state_machine", "regex", "source"];
204
204
  };
205
205
  readonly evidence_level: {
206
206
  readonly type: "string";
@@ -242,7 +242,7 @@ export declare const PROOF_RECEIPT_SCHEMA: {
242
242
  };
243
243
  readonly scope: {
244
244
  readonly type: "string";
245
- readonly enum: readonly ["code", "intent"];
245
+ readonly enum: readonly ["code", "source", "harness", "intent"];
246
246
  };
247
247
  readonly obligation: {
248
248
  readonly type: "object";
@@ -339,7 +339,8 @@ export type ClaimBinding = Readonly<{
339
339
  requirement_id?: string;
340
340
  fact_id?: string;
341
341
  binding: ClaimBindingVerdict;
342
- scope?: "code" | "intent";
342
+ /** What the proof rests on: evaluated code, project files Kibi read (source), a test harness, or the knowledge base alone (intent). */
343
+ scope?: "code" | "source" | "harness" | "intent";
343
344
  obligation?: Readonly<Record<string, unknown>>;
344
345
  reason?: string;
345
346
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"proof-receipt.d.ts","sourceRoot":"","sources":["../../src/public/proof-receipt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAGhC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EAEf,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,6BAA6B,QAAmB,CAAC;AAE9D;;;;GAIG;AAEH,eAAO,MAAM,sBAAsB,8CAIzB,CAAC;AAGX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1E,eAAO,MAAM,s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AE,GACrD,SAAS,MAAM,EAAE,CAuCnB;AAED,qFAAqF;AACrF,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,OAAO,EAC1B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC1C,QAAQ,CAAC,EAAE,aAAa,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,SAAS,MAAM,EAAE,CAgCnB;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAoBrC,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,EACtD,IAAI,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,GAC7D,SAAS,MAAM,EAAE,CAqBnB"}
@@ -161,7 +161,10 @@ export const PROOF_RECEIPT_SCHEMA = {
161
161
  type: "string",
162
162
  enum: [...CLAIM_BINDING_VERDICTS],
163
163
  },
164
- scope: { type: "string", enum: ["code", "intent"] },
164
+ scope: {
165
+ type: "string",
166
+ enum: ["code", "source", "harness", "intent"],
167
+ },
165
168
  obligation: { type: "object" },
166
169
  reason: { type: "string", minLength: 1 },
167
170
  },
@@ -340,6 +343,8 @@ function validClaimBindings(value) {
340
343
  CLAIM_BINDING_VERDICTS.includes(entry.binding) &&
341
344
  (entry.scope === undefined ||
342
345
  entry.scope === "code" ||
346
+ entry.scope === "source" ||
347
+ entry.scope === "harness" ||
343
348
  entry.scope === "intent") &&
344
349
  (entry.obligation === undefined || isRecord(entry.obligation)) &&
345
350
  (entry.reason === undefined || nonEmptyString(entry.reason))));
@@ -0,0 +1,102 @@
1
+ export declare const SOURCE_READERS: readonly ["json", "yaml", "glob", "openapi", "references", "schema", "routes", "validator"];
2
+ export type SourceReader = (typeof SOURCE_READERS)[number];
3
+ /** A source spec as a proof contract states it; see sourceSpecErrors. */
4
+ export type SourceSpec = Readonly<Record<string, unknown>> & Readonly<{
5
+ reader: SourceReader;
6
+ }>;
7
+ /** A column of a table, or a field of a validator object. */
8
+ export type SourceColumn = {
9
+ name: string;
10
+ nullable: boolean;
11
+ optional: boolean;
12
+ };
13
+ /** A table (schema reader) or object (validator reader). */
14
+ export type SourceEntity = {
15
+ name: string;
16
+ columns: SourceColumn[];
17
+ foreign_keys: string[];
18
+ };
19
+ /** One endpoint of a route table and the middleware that runs before it. */
20
+ export type SourceRoute = {
21
+ method: string;
22
+ path: string;
23
+ middleware: string[];
24
+ };
25
+ /**
26
+ * What Kibi read: the selected members (sorted, unique), and for schema,
27
+ * validator and routes readers the structure the field and middleware
28
+ * obligations are decided on.
29
+ */
30
+ export type SourceModel = {
31
+ members: string[];
32
+ entities?: SourceEntity[];
33
+ routes?: SourceRoute[];
34
+ };
35
+ export type SourceRead = {
36
+ ok: true;
37
+ model: SourceModel;
38
+ } | {
39
+ ok: false;
40
+ reason: string;
41
+ };
42
+ /** A place in a file Kibi could not read statically. */
43
+ export type UnresolvedReference = Readonly<{
44
+ file: string;
45
+ line: number;
46
+ text: string;
47
+ }>;
48
+ export declare const REFERENCE_EXTRACTS: readonly ["env", "imports", "calls", "string_args", "thrown", "property"];
49
+ /**
50
+ * Why a source spec is not one Kibi can read, or [] when it is. `label`
51
+ * names the field in the messages (proof_contract.source, ...).
52
+ */
53
+ export declare function sourceSpecErrors(value: unknown, label: string): string[];
54
+ /** The spec with only the keys its reader takes, for contract hashing. */
55
+ export declare function normalizeSourceSpec(value: unknown): SourceSpec | undefined;
56
+ /** Workspace-relative files a glob list matches, sorted. */
57
+ export declare function matchWorkspaceFiles(workspaceRoot: string, patterns: readonly string[], ignore?: readonly string[]): string[];
58
+ export type SourceDependency = Readonly<{
59
+ id: string;
60
+ hash: string;
61
+ }>;
62
+ /**
63
+ * What a read of `spec` depends on, so a receipt goes stale when any of it
64
+ * changes: each file the reader parses (its contents), the set of files a
65
+ * glob matches (their paths), and for the readers that evaluate a module
66
+ * (drizzle schemas, route tables, validators) every workspace module that
67
+ * module imports through relative or tsconfig path imports.
68
+ */
69
+ export declare function sourceDependencies(workspaceRoot: string, spec: SourceSpec): SourceDependency[];
70
+ /**
71
+ * The workspace modules `file` imports, directly or not, through relative
72
+ * imports, the nearest tsconfig's `paths` aliases (following `extends`) and
73
+ * workspace packages linked into node_modules (packages installed from a
74
+ * registry are left out: a lockfile change stales nothing here).
75
+ */
76
+ export declare function importClosure(workspaceRoot: string, file: string): string[];
77
+ /** The entities (tables or validator objects) a spec's table filter selects. */
78
+ export declare function selectedEntities(spec: SourceSpec, model: SourceModel): SourceEntity[];
79
+ /** The routes a spec's path_prefix selects. */
80
+ export declare function selectedRoutes(spec: SourceSpec, routes: SourceRoute[]): SourceRoute[];
81
+ /**
82
+ * Read `spec` from the workspace. Readers that evaluate code (drizzle
83
+ * schemas, route tables, validators) and the references reader go through
84
+ * `evaluate`, which the CLI supplies; a read without it refuses those.
85
+ */
86
+ export declare function readSource(workspaceRoot: string, spec: SourceSpec, evaluate?: SourceCodeEvaluator): Promise<SourceRead>;
87
+ /** What the CLI's code evaluator returns for a reader that runs code. */
88
+ export type SourceCodeEvaluation = {
89
+ ok: true;
90
+ members?: string[];
91
+ entities?: SourceEntity[];
92
+ routes?: SourceRoute[];
93
+ } | {
94
+ ok: false;
95
+ reason: string;
96
+ };
97
+ export type SourceCodeEvaluator = (workspaceRoot: string, spec: SourceSpec) => Promise<SourceCodeEvaluation>;
98
+ /** A short description of a spec, for messages. */
99
+ export declare function describeSource(spec: SourceSpec): string;
100
+ /** Unresolved references, as one rejection reason naming the first few. */
101
+ export declare function unresolvedReason(what: string, unresolved: readonly UnresolvedReference[]): string;
102
+ //# sourceMappingURL=proof-sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-sources.d.ts","sourceRoot":"","sources":["../../src/public/proof-sources.ts"],"names":[],"mappings":"AAwCA,eAAO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