kibi-cli 2.3.0 → 2.5.0

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 (380) hide show
  1. package/dist/cli-json-command.d.ts +6 -0
  2. package/dist/cli-json-command.d.ts.map +1 -1
  3. package/dist/cli-json-command.js +39 -11
  4. package/dist/cli-operation-loader.d.ts.map +1 -1
  5. package/dist/cli-operation-loader.js +7 -0
  6. package/dist/cli-operation-metadata.d.ts +13 -5
  7. package/dist/cli-operation-metadata.d.ts.map +1 -1
  8. package/dist/cli-operation-metadata.js +15 -5
  9. package/dist/cli-protocol.d.ts +14 -0
  10. package/dist/cli-protocol.d.ts.map +1 -1
  11. package/dist/cli-protocol.js +31 -2
  12. package/dist/cli-register-maintenance.d.ts.map +1 -1
  13. package/dist/cli-register-maintenance.js +7 -0
  14. package/dist/cli-register-proof.d.ts.map +1 -1
  15. package/dist/cli-register-proof.js +13 -0
  16. package/dist/commands/check.d.ts.map +1 -1
  17. package/dist/commands/check.js +11 -2
  18. package/dist/commands/discovery-shared.d.ts.map +1 -1
  19. package/dist/commands/discovery-shared.js +8 -2
  20. package/dist/commands/engine.d.ts.map +1 -1
  21. package/dist/commands/engine.js +4 -2
  22. package/dist/commands/gc.d.ts.map +1 -1
  23. package/dist/commands/gc.js +7 -0
  24. package/dist/commands/init-helpers.d.ts.map +1 -1
  25. package/dist/commands/init-helpers.js +0 -1
  26. package/dist/commands/merge-driver.d.ts +31 -0
  27. package/dist/commands/merge-driver.d.ts.map +1 -0
  28. package/dist/commands/merge-driver.js +268 -0
  29. package/dist/commands/migrate.d.ts.map +1 -1
  30. package/dist/commands/migrate.js +281 -14
  31. package/dist/commands/proof-compact.d.ts +9 -0
  32. package/dist/commands/proof-compact.d.ts.map +1 -0
  33. package/dist/commands/proof-compact.js +58 -0
  34. package/dist/commands/prove.d.ts +38 -0
  35. package/dist/commands/prove.d.ts.map +1 -1
  36. package/dist/commands/prove.js +222 -47
  37. package/dist/commands/sync/persistence.d.ts.map +1 -1
  38. package/dist/commands/sync/persistence.js +61 -16
  39. package/dist/commands/sync.d.ts +8 -0
  40. package/dist/commands/sync.d.ts.map +1 -1
  41. package/dist/commands/sync.js +42 -16
  42. package/dist/diagnostics.js +1 -1
  43. package/dist/engine-limits.d.ts +74 -0
  44. package/dist/engine-limits.d.ts.map +1 -0
  45. package/dist/engine-limits.js +201 -0
  46. package/dist/engine.d.ts +10 -0
  47. package/dist/engine.d.ts.map +1 -1
  48. package/dist/engine.js +57 -9
  49. package/dist/extractors/manifest.d.ts +8 -0
  50. package/dist/extractors/manifest.d.ts.map +1 -1
  51. package/dist/extractors/manifest.js +34 -5
  52. package/dist/extractors/markdown.d.ts +8 -0
  53. package/dist/extractors/markdown.d.ts.map +1 -1
  54. package/dist/extractors/markdown.js +57 -0
  55. package/dist/extractors/relationships.d.ts.map +1 -1
  56. package/dist/extractors/relationships.js +2 -0
  57. package/dist/intent-search.d.ts +4 -1
  58. package/dist/intent-search.d.ts.map +1 -1
  59. package/dist/intent-search.js +186 -33
  60. package/dist/operations/bootstrap/candidate-helpers.d.ts.map +1 -1
  61. package/dist/operations/bootstrap/candidate-helpers.js +8 -1
  62. package/dist/operations/bootstrap/candidates.d.ts.map +1 -1
  63. package/dist/operations/bootstrap/candidates.js +55 -39
  64. package/dist/operations/bootstrap/discovery.js +1 -1
  65. package/dist/operations/bootstrap/generate.d.ts +2 -0
  66. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  67. package/dist/operations/bootstrap/generate.js +107 -37
  68. package/dist/operations/bootstrap/guidance-actions.d.ts.map +1 -1
  69. package/dist/operations/bootstrap/guidance-actions.js +3 -0
  70. package/dist/operations/bootstrap/guidance.d.ts.map +1 -1
  71. package/dist/operations/bootstrap/guidance.js +7 -1
  72. package/dist/operations/bootstrap/intent-claims.d.ts +17 -0
  73. package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -0
  74. package/dist/operations/bootstrap/intent-claims.js +103 -0
  75. package/dist/operations/bootstrap/markdown-candidates.d.ts +2 -0
  76. package/dist/operations/bootstrap/markdown-candidates.d.ts.map +1 -1
  77. package/dist/operations/bootstrap/markdown-candidates.js +32 -10
  78. package/dist/operations/bootstrap/presentation.d.ts +2 -0
  79. package/dist/operations/bootstrap/presentation.d.ts.map +1 -1
  80. package/dist/operations/bootstrap/presentation.js +66 -3
  81. package/dist/operations/bootstrap/requirement-claims.d.ts +1 -0
  82. package/dist/operations/bootstrap/requirement-claims.d.ts.map +1 -1
  83. package/dist/operations/bootstrap/requirement-claims.js +13 -1
  84. package/dist/operations/bootstrap/types.d.ts +28 -0
  85. package/dist/operations/bootstrap/types.d.ts.map +1 -1
  86. package/dist/operations/bootstrap/types.js +16 -0
  87. package/dist/operations/bootstrap/validation.d.ts +4 -0
  88. package/dist/operations/bootstrap/validation.d.ts.map +1 -0
  89. package/dist/operations/bootstrap/validation.js +20 -0
  90. package/dist/operations/migration/inventory-rederive.d.ts +81 -0
  91. package/dist/operations/migration/inventory-rederive.d.ts.map +1 -0
  92. package/dist/operations/migration/inventory-rederive.js +484 -0
  93. package/dist/operations/migration/kb-sources.d.ts +53 -0
  94. package/dist/operations/migration/kb-sources.d.ts.map +1 -0
  95. package/dist/operations/migration/kb-sources.js +233 -0
  96. package/dist/operations/migration/origin-backfill.d.ts +39 -0
  97. package/dist/operations/migration/origin-backfill.d.ts.map +1 -0
  98. package/dist/operations/migration/origin-backfill.js +164 -0
  99. package/dist/operations/migration/polarity-values.d.ts +10 -0
  100. package/dist/operations/migration/polarity-values.d.ts.map +1 -0
  101. package/dist/operations/migration/polarity-values.js +60 -0
  102. package/dist/operations/migration/schema6.d.ts +59 -0
  103. package/dist/operations/migration/schema6.d.ts.map +1 -0
  104. package/dist/operations/migration/schema6.js +379 -0
  105. package/dist/operations/migration/source-paths.d.ts +131 -0
  106. package/dist/operations/migration/source-paths.d.ts.map +1 -0
  107. package/dist/operations/migration/source-paths.js +308 -0
  108. package/dist/operations/migration/superseded-closure.d.ts +54 -0
  109. package/dist/operations/migration/superseded-closure.d.ts.map +1 -0
  110. package/dist/operations/migration/superseded-closure.js +187 -0
  111. package/dist/operations/modeling/logic-modeling.d.ts.map +1 -1
  112. package/dist/operations/modeling/logic-modeling.js +3 -5
  113. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  114. package/dist/operations/modeling/model-requirement.js +225 -67
  115. package/dist/operations/mutation/contradictions.d.ts +16 -0
  116. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  117. package/dist/operations/mutation/contradictions.js +32 -0
  118. package/dist/operations/mutation/delete.d.ts.map +1 -1
  119. package/dist/operations/mutation/delete.js +15 -7
  120. package/dist/operations/mutation/origin.d.ts +21 -0
  121. package/dist/operations/mutation/origin.d.ts.map +1 -0
  122. package/dist/operations/mutation/origin.js +78 -0
  123. package/dist/operations/mutation/plan-apply-journal.d.ts +182 -0
  124. package/dist/operations/mutation/plan-apply-journal.d.ts.map +1 -0
  125. package/dist/operations/mutation/plan-apply-journal.js +613 -0
  126. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +3 -1
  127. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -1
  128. package/dist/operations/mutation/predicate-vocabulary-guard.js +13 -2
  129. package/dist/operations/mutation/relationships.d.ts +5 -5
  130. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  131. package/dist/operations/mutation/relationships.js +31 -11
  132. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  133. package/dist/operations/mutation/serialization.js +3 -1
  134. package/dist/operations/mutation/source-authoring.d.ts +6 -0
  135. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  136. package/dist/operations/mutation/source-authoring.js +7 -1
  137. package/dist/operations/mutation/symbol-refresh.d.ts.map +1 -1
  138. package/dist/operations/mutation/symbol-refresh.js +4 -1
  139. package/dist/operations/mutation/types.d.ts +14 -0
  140. package/dist/operations/mutation/types.d.ts.map +1 -1
  141. package/dist/operations/mutation/upsert.d.ts +30 -3
  142. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  143. package/dist/operations/mutation/upsert.js +105 -35
  144. package/dist/operations/mutation/validate-upsert.d.ts +6 -0
  145. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  146. package/dist/operations/mutation/validate-upsert.js +34 -30
  147. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  148. package/dist/operations/planning/apply-plan.js +751 -144
  149. package/dist/operations/planning/compile-intent.d.ts +34 -1
  150. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  151. package/dist/operations/planning/compile-intent.js +314 -98
  152. package/dist/operations/proof/code-scope.d.ts +28 -0
  153. package/dist/operations/proof/code-scope.d.ts.map +1 -1
  154. package/dist/operations/proof/code-scope.js +72 -0
  155. package/dist/operations/proof/compact-receipts.d.ts +49 -0
  156. package/dist/operations/proof/compact-receipts.d.ts.map +1 -0
  157. package/dist/operations/proof/compact-receipts.js +160 -0
  158. package/dist/operations/proof/ingest-proof.d.ts +2 -0
  159. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  160. package/dist/operations/proof/ingest-proof.js +44 -23
  161. package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
  162. package/dist/operations/proof/prune-receipts.js +5 -9
  163. package/dist/operations/proof/receipt-compaction.d.ts +48 -0
  164. package/dist/operations/proof/receipt-compaction.d.ts.map +1 -0
  165. package/dist/operations/proof/receipt-compaction.js +121 -0
  166. package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
  167. package/dist/operations/semantic-advisor/analysis-receipt.js +12 -1
  168. package/dist/operations/semantic-advisor/analyze-prose.d.ts +2 -1
  169. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  170. package/dist/operations/semantic-advisor/analyze-prose.js +51 -5
  171. package/dist/operations/semantic-advisor/clauses.d.ts +1 -0
  172. package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
  173. package/dist/operations/semantic-advisor/clauses.js +11 -1
  174. package/dist/operations/semantic-advisor/conditional-rules.d.ts +33 -0
  175. package/dist/operations/semantic-advisor/conditional-rules.d.ts.map +1 -0
  176. package/dist/operations/semantic-advisor/conditional-rules.js +262 -0
  177. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +3 -1
  178. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
  179. package/dist/operations/semantic-advisor/ingestion-boundary.js +14 -6
  180. package/dist/operations/semantic-advisor/plugin-orchestration.js +1 -1
  181. package/dist/prolog/codec.d.ts.map +1 -1
  182. package/dist/prolog/codec.js +2 -1
  183. package/dist/prolog.d.ts +9 -0
  184. package/dist/prolog.d.ts.map +1 -1
  185. package/dist/prolog.js +56 -10
  186. package/dist/proof/command-test-report.d.ts +74 -0
  187. package/dist/proof/command-test-report.d.ts.map +1 -0
  188. package/dist/proof/command-test-report.js +206 -0
  189. package/dist/public/branch-resolver.d.ts +1 -0
  190. package/dist/public/branch-resolver.d.ts.map +1 -1
  191. package/dist/public/branch-resolver.js +1 -0
  192. package/dist/public/diagnostic-usage.d.ts +14 -0
  193. package/dist/public/diagnostic-usage.d.ts.map +1 -1
  194. package/dist/public/diagnostic-usage.js +55 -1
  195. package/dist/public/entity-origin.d.ts +69 -0
  196. package/dist/public/entity-origin.d.ts.map +1 -0
  197. package/dist/public/entity-origin.js +142 -0
  198. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  199. package/dist/public/impact/full-kb-quality.js +1 -0
  200. package/dist/public/impact/requirement-quality.js +1 -1
  201. package/dist/public/operations/catalog.d.ts +203 -20
  202. package/dist/public/operations/catalog.d.ts.map +1 -1
  203. package/dist/public/operations/catalog.js +3 -0
  204. package/dist/public/operations/check-executor.d.ts.map +1 -1
  205. package/dist/public/operations/check-executor.js +8 -0
  206. package/dist/public/operations/contracts.d.ts +0 -5
  207. package/dist/public/operations/contracts.d.ts.map +1 -1
  208. package/dist/public/operations/contracts.js +63 -14
  209. package/dist/public/operations/discovery-entities.d.ts +15 -0
  210. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  211. package/dist/public/operations/discovery-entities.js +59 -0
  212. package/dist/public/operations/discovery-executors.d.ts +6 -1
  213. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  214. package/dist/public/operations/discovery-executors.js +65 -6
  215. package/dist/public/operations/index.d.ts +1 -0
  216. package/dist/public/operations/index.d.ts.map +1 -1
  217. package/dist/public/operations/index.js +1 -0
  218. package/dist/public/operations/migration-plan.d.ts +5 -0
  219. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  220. package/dist/public/operations/migration-plan.js +26 -1
  221. package/dist/public/operations/node-ports.d.ts.map +1 -1
  222. package/dist/public/operations/node-ports.js +24 -3
  223. package/dist/public/operations/origin-review.d.ts +51 -0
  224. package/dist/public/operations/origin-review.d.ts.map +1 -0
  225. package/dist/public/operations/origin-review.js +307 -0
  226. package/dist/public/operations/predicate-schema-conformance.js +1 -1
  227. package/dist/public/operations/repair-plan.d.ts.map +1 -1
  228. package/dist/public/operations/repair-plan.js +4 -0
  229. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  230. package/dist/public/operations/result-envelope.js +17 -5
  231. package/dist/public/operations/runtime-types.d.ts +9 -0
  232. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  233. package/dist/public/operations/schema6-check-actions.d.ts +127 -0
  234. package/dist/public/operations/schema6-check-actions.d.ts.map +1 -0
  235. package/dist/public/operations/schema6-check-actions.js +575 -0
  236. package/dist/public/operations/source-path-dangling.d.ts +17 -0
  237. package/dist/public/operations/source-path-dangling.d.ts.map +1 -0
  238. package/dist/public/operations/source-path-dangling.js +66 -0
  239. package/dist/public/operations/specs/bootstrap.d.ts +73 -1
  240. package/dist/public/operations/specs/bootstrap.d.ts.map +1 -1
  241. package/dist/public/operations/specs/bootstrap.js +66 -1
  242. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  243. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  244. package/dist/public/operations/specs/check-rules.generated.js +15 -1
  245. package/dist/public/operations/specs/check.d.ts +2 -2
  246. package/dist/public/operations/specs/check.js +1 -1
  247. package/dist/public/operations/specs/composite.d.ts +351 -0
  248. package/dist/public/operations/specs/composite.d.ts.map +1 -0
  249. package/dist/public/operations/specs/composite.js +96 -0
  250. package/dist/public/operations/specs/discovery.d.ts +8 -3
  251. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  252. package/dist/public/operations/specs/discovery.js +8 -3
  253. package/dist/public/operations/specs/modeling.d.ts +2 -2
  254. package/dist/public/operations/specs/modeling.js +2 -2
  255. package/dist/public/operations/specs/mutation-schemas.d.ts +73 -8
  256. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  257. package/dist/public/operations/specs/mutation-schemas.js +43 -7
  258. package/dist/public/operations/specs/mutation.d.ts +1 -1
  259. package/dist/public/operations/specs/mutation.js +1 -1
  260. package/dist/public/operations/specs/planning.d.ts +2 -2
  261. package/dist/public/operations/specs/planning.js +4 -4
  262. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  263. package/dist/public/operations/specs/reporting.js +13 -26
  264. package/dist/public/operations/specs/upsert.d.ts +79 -9
  265. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  266. package/dist/public/operations/specs/upsert.js +6 -1
  267. package/dist/public/operations/symbol-repair-plan.d.ts.map +1 -1
  268. package/dist/public/operations/symbol-repair-plan.js +3 -1
  269. package/dist/public/operations/types.d.ts +1 -1
  270. package/dist/public/operations/types.d.ts.map +1 -1
  271. package/dist/public/proof-receipt.d.ts +1 -0
  272. package/dist/public/proof-receipt.d.ts.map +1 -1
  273. package/dist/public/schemas/entity.d.ts.map +1 -1
  274. package/dist/public/schemas/entity.js +52 -0
  275. package/dist/public/schemas/relationship.d.ts.map +1 -1
  276. package/dist/public/schemas/relationship.js +2 -0
  277. package/dist/public/skills/kibi-bootstrap/SKILL.md +52 -11
  278. package/dist/public/skills/kibi-bootstrap/resources/bootstrap.md +12 -1
  279. package/dist/public/skills/kibi-usage/SKILL.md +82 -18
  280. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  281. package/dist/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  282. package/dist/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  283. package/dist/public/skills/kibi-usage/resources/operation-access.md +29 -1
  284. package/dist/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  285. package/dist/public/skills/kibi-usage/resources/workflows.md +42 -25
  286. package/dist/public/telemetry-acceptance.d.ts +64 -0
  287. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  288. package/dist/public/telemetry-acceptance.js +143 -7
  289. package/dist/public/telemetry-remediation.d.ts.map +1 -1
  290. package/dist/public/telemetry-remediation.js +26 -10
  291. package/dist/relationships/shards.d.ts +13 -0
  292. package/dist/relationships/shards.d.ts.map +1 -1
  293. package/dist/relationships/shards.js +54 -28
  294. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  295. package/dist/runtime/cli-runtime.js +44 -3
  296. package/dist/runtime/detached-snapshot.d.ts +38 -0
  297. package/dist/runtime/detached-snapshot.d.ts.map +1 -0
  298. package/dist/runtime/detached-snapshot.js +92 -0
  299. package/dist/schemas/entity.schema.json +122 -0
  300. package/dist/search-answer.d.ts +157 -0
  301. package/dist/search-answer.d.ts.map +1 -0
  302. package/dist/search-answer.js +846 -0
  303. package/dist/traceability/impact-knowledge.d.ts.map +1 -1
  304. package/dist/traceability/impact-knowledge.js +7 -0
  305. package/dist/traceability/symbol-extract.js +3 -3
  306. package/dist/traceability/temp-kb.d.ts.map +1 -1
  307. package/dist/traceability/temp-kb.js +12 -0
  308. package/dist/types/entities.d.ts +13 -0
  309. package/dist/types/entities.d.ts.map +1 -1
  310. package/dist/types/relationships.d.ts +1 -1
  311. package/dist/types/relationships.d.ts.map +1 -1
  312. package/dist/utils/branch-resolver.d.ts +37 -1
  313. package/dist/utils/branch-resolver.d.ts.map +1 -1
  314. package/dist/utils/branch-resolver.js +130 -3
  315. package/dist/utils/repo-relative-path.d.ts +18 -0
  316. package/dist/utils/repo-relative-path.d.ts.map +1 -0
  317. package/dist/utils/repo-relative-path.js +58 -0
  318. package/dist/utils/rule-registry.generated.d.ts +75 -3
  319. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  320. package/dist/utils/rule-registry.generated.js +89 -3
  321. package/dist/utils/schema-version.d.ts +1 -1
  322. package/dist/utils/schema-version.d.ts.map +1 -1
  323. package/dist/utils/schema-version.js +4 -3
  324. package/dist/utils/strict-modeling.d.ts +1 -1
  325. package/dist/utils/strict-modeling.d.ts.map +1 -1
  326. package/dist/utils/strict-modeling.js +23 -3
  327. package/package.json +3 -3
  328. package/schema/entities.pl +22 -0
  329. package/schema/relationships.pl +14 -0
  330. package/schema/validation.pl +45 -1
  331. package/src/public/branch-resolver.ts +1 -0
  332. package/src/public/diagnostic-usage.ts +59 -1
  333. package/src/public/entity-origin.ts +175 -0
  334. package/src/public/impact/full-kb-quality.ts +1 -0
  335. package/src/public/impact/requirement-quality.ts +1 -1
  336. package/src/public/operations/catalog.ts +3 -0
  337. package/src/public/operations/check-executor.ts +15 -0
  338. package/src/public/operations/contracts.ts +75 -15
  339. package/src/public/operations/discovery-entities.ts +74 -0
  340. package/src/public/operations/discovery-executors.ts +88 -10
  341. package/src/public/operations/index.ts +1 -0
  342. package/src/public/operations/migration-plan.ts +30 -1
  343. package/src/public/operations/node-ports.ts +24 -3
  344. package/src/public/operations/origin-review.ts +375 -0
  345. package/src/public/operations/predicate-schema-conformance.ts +1 -1
  346. package/src/public/operations/repair-plan.ts +4 -0
  347. package/src/public/operations/result-envelope.ts +18 -6
  348. package/src/public/operations/runtime-types.ts +9 -0
  349. package/src/public/operations/schema6-check-actions.ts +699 -0
  350. package/src/public/operations/source-path-dangling.ts +81 -0
  351. package/src/public/operations/specs/bootstrap.ts +78 -4
  352. package/src/public/operations/specs/check-rules.generated.ts +15 -1
  353. package/src/public/operations/specs/check.ts +1 -1
  354. package/src/public/operations/specs/composite.ts +141 -0
  355. package/src/public/operations/specs/discovery.ts +9 -3
  356. package/src/public/operations/specs/modeling.ts +2 -2
  357. package/src/public/operations/specs/mutation-schemas.ts +49 -7
  358. package/src/public/operations/specs/mutation.ts +1 -1
  359. package/src/public/operations/specs/planning.ts +4 -4
  360. package/src/public/operations/specs/reporting.ts +13 -38
  361. package/src/public/operations/specs/upsert.ts +7 -1
  362. package/src/public/operations/symbol-repair-plan.ts +3 -1
  363. package/src/public/operations/types.ts +2 -0
  364. package/src/public/proof-receipt.ts +1 -0
  365. package/src/public/schemas/entity.ts +57 -0
  366. package/src/public/schemas/relationship.ts +2 -0
  367. package/src/public/skills/kibi-bootstrap/SKILL.md +52 -11
  368. package/src/public/skills/kibi-bootstrap/resources/bootstrap.md +12 -1
  369. package/src/public/skills/kibi-usage/SKILL.md +82 -18
  370. package/src/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  371. package/src/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  372. package/src/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  373. package/src/public/skills/kibi-usage/resources/operation-access.md +29 -1
  374. package/src/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  375. package/src/public/skills/kibi-usage/resources/workflows.md +42 -25
  376. package/src/public/telemetry-acceptance-types.d.ts +4 -1
  377. package/src/public/telemetry-acceptance.ts +210 -7
  378. package/src/public/telemetry-remediation.ts +39 -10
  379. package/src/schemas/entity.schema.json +122 -0
  380. package/src/schemas/relationship.schema.json +2 -0
@@ -1,4 +1,5 @@
1
1
  import type { PrologPort } from "../../public/operations/runtime-types.js";
2
+ import type { ProofContract } from "../../public/proof-protocol.js";
2
3
  /**
3
4
  * Which symbols a proof receipt's per-contract binding covers. Receipt ingest
4
5
  * (which writes `binding_hash`) and coverage (which checks it) must derive
@@ -14,4 +15,31 @@ import type { PrologPort } from "../../public/operations/runtime-types.js";
14
15
  export declare function receiptCodeScopeSymbolIds(contract: unknown, bindings: unknown, coveredBySymbols: readonly string[]): string[];
15
16
  /** Map each test id to the symbols linked `covered_by` it, in one query. */
16
17
  export declare function loadCoveredBySymbolsByTest(prolog: Pick<PrologPort, "query">): Promise<ReadonlyMap<string, readonly string[]>>;
18
+ /**
19
+ * The proof-contract projection a receipt binding hashes. Ingest validates a
20
+ * contract and then hashes exactly this projection; coverage must hash the
21
+ * same projection, never the raw stored value, or a cosmetic extra key would
22
+ * make every receipt of that test silently fall back to snapshot matching.
23
+ */
24
+ export declare function receiptBindingContract(raw: unknown): ProofContract | null;
25
+ export type ReceiptBindingInput = Readonly<{
26
+ workspaceRoot: string;
27
+ readFile: (absolutePath: string) => Promise<string>;
28
+ /** The test entity: source, proof_contract and proof_bindings are read. */
29
+ test: Readonly<Record<string, unknown>>;
30
+ coveredBySymbols: readonly string[];
31
+ }>;
32
+ /**
33
+ * The current per-contract binding hash of one proof-bearing test, or
34
+ * undefined when the test has no markdown source the binding can hash.
35
+ *
36
+ * Ingest writes this value into `binding_hash` and coverage compares against
37
+ * it, so both call this one function. Every input is repository-relative and
38
+ * content-addressed: the test document is located by its normalized
39
+ * repo-relative `source`, the code scope by normalized manifest paths, and
40
+ * only file contents (never absolute locations) enter the hash. Receipts
41
+ * written on a CI runner and on a developer checkout of the same commit
42
+ * therefore carry the same binding.
43
+ */
44
+ export declare function currentReceiptBindingHash(input: ReceiptBindingInput): Promise<string | undefined>;
17
45
  //# sourceMappingURL=code-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-scope.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/code-scope.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E;;;;;;;;;;;GAWG;AAEH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,OAAO,EACjB,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAClC,MAAM,EAAE,CAoBV;AAED,4EAA4E;AAE5E,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAiBjD"}
1
+ {"version":3,"file":"code-scope.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/code-scope.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAKpE;;;;;;;;;;;GAWG;AAEH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,OAAO,EACjB,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAClC,MAAM,EAAE,CAoBV;AAED,4EAA4E;AAE5E,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAiBjD;AAQD;;;;;GAKG;AAEH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAkBzE;AAGD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,2EAA2E;IAC3E,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AAEH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuB7B"}
@@ -7,7 +7,13 @@
7
7
  the Free Software Foundation, either version 3 of the License, or
8
8
  (at your option) any later version.
9
9
  */
10
+ import { join } from "node:path";
11
+ import { resolveBoundSymbolScope } from "../../extractors/manifest.js";
10
12
  import { normalizeEntityId, parseTriples } from "../../prolog/codec.js";
13
+ import { receiptBindingHash } from "../../public/proof-fingerprint.js";
14
+ import { normalizeRepoRelativePath } from "../../utils/repo-relative-path.js";
15
+ import { resolveContainedSourcePath } from "../mutation/source-authoring.js";
16
+ import { removeFrontmatterBlock } from "./receipt-document.js";
11
17
  /**
12
18
  * Which symbols a proof receipt's per-contract binding covers. Receipt ingest
13
19
  * (which writes `binding_hash`) and coverage (which checks it) must derive
@@ -58,3 +64,69 @@ export async function loadCoveredBySymbolsByTest(prolog) {
58
64
  }
59
65
  return byTest;
60
66
  }
67
+ function record(value) {
68
+ return value !== null && typeof value === "object" && !Array.isArray(value)
69
+ ? value
70
+ : null;
71
+ }
72
+ /**
73
+ * The proof-contract projection a receipt binding hashes. Ingest validates a
74
+ * contract and then hashes exactly this projection; coverage must hash the
75
+ * same projection, never the raw stored value, or a cosmetic extra key would
76
+ * make every receipt of that test silently fall back to snapshot matching.
77
+ */
78
+ // implements REQ-kibi-fresh-verification-receipts-v2
79
+ export function receiptBindingContract(raw) {
80
+ const contract = record(raw);
81
+ if (!contract)
82
+ return null;
83
+ const requiredProofs = Array.isArray(contract.required_proofs)
84
+ ? contract.required_proofs
85
+ : [];
86
+ return {
87
+ version: contract.version,
88
+ integration: String(contract.integration ?? ""),
89
+ required_proofs: requiredProofs.map((entry) => {
90
+ const row = record(entry);
91
+ return {
92
+ symbol_id: String(row?.symbol_id ?? ""),
93
+ target: String(row?.target ?? ""),
94
+ };
95
+ }),
96
+ success_policy: contract.success_policy,
97
+ };
98
+ }
99
+ /**
100
+ * The current per-contract binding hash of one proof-bearing test, or
101
+ * undefined when the test has no markdown source the binding can hash.
102
+ *
103
+ * Ingest writes this value into `binding_hash` and coverage compares against
104
+ * it, so both call this one function. Every input is repository-relative and
105
+ * content-addressed: the test document is located by its normalized
106
+ * repo-relative `source`, the code scope by normalized manifest paths, and
107
+ * only file contents (never absolute locations) enter the hash. Receipts
108
+ * written on a CI runner and on a developer checkout of the same commit
109
+ * therefore carry the same binding.
110
+ */
111
+ // implements REQ-kibi-fresh-verification-receipts-v2
112
+ export async function currentReceiptBindingHash(input) {
113
+ const contract = receiptBindingContract(input.test.proof_contract);
114
+ if (!contract)
115
+ return undefined;
116
+ const source = typeof input.test.source === "string" ? input.test.source : "";
117
+ if (!/\.(md|mdx)$/i.test(source.trim()))
118
+ return undefined;
119
+ const relative = normalizeRepoRelativePath(input.workspaceRoot, source);
120
+ if (relative === null)
121
+ return undefined;
122
+ try {
123
+ const absolute = resolveContainedSourcePath(input.workspaceRoot, relative);
124
+ const authored = await input.readFile(absolute);
125
+ const stripped = removeFrontmatterBlock(authored, "proof_receipts");
126
+ const codeScope = resolveBoundSymbolScope(join(input.workspaceRoot, ".kb", "symbols.yaml"), receiptCodeScopeSymbolIds(contract, input.test.proof_bindings, input.coveredBySymbols));
127
+ return receiptBindingHash(contract, stripped ?? authored, codeScope);
128
+ }
129
+ catch {
130
+ return undefined;
131
+ }
132
+ }
@@ -0,0 +1,49 @@
1
+ import type { OperationContext } from "../../public/operations/runtime-types.js";
2
+ import { PROOF_RECEIPT_COMPACTION_POLICY } from "./receipt-compaction.js";
3
+ export type CompactReceiptsArgs = Readonly<{
4
+ /** Compact a single test entity only. */
5
+ testId?: string;
6
+ /** Report what would be removed without writing anything. */
7
+ dryRun?: boolean;
8
+ }>;
9
+ export type CompactReceiptsTestResult = Readonly<{
10
+ testId: string;
11
+ before: number;
12
+ after: number;
13
+ removed: number;
14
+ }>;
15
+ export type CompactReceiptsResult = Readonly<{
16
+ policy: typeof PROOF_RECEIPT_COMPACTION_POLICY;
17
+ snapshot: string;
18
+ dryRun: boolean;
19
+ removed: number;
20
+ tests: readonly CompactReceiptsTestResult[];
21
+ skipped: readonly Readonly<{
22
+ testId: string;
23
+ reason: string;
24
+ }>[];
25
+ }>;
26
+ /**
27
+ * Replace one test's receipt history with a shorter, already-validated
28
+ * history. Only the `proof_receipts` frontmatter block of the authored
29
+ * document is rewritten: the rest of the document keeps its exact bytes, so
30
+ * the receipt-stripped document (an input of the per-contract binding) and
31
+ * therefore every receipt's freshness are unchanged by the rewrite.
32
+ */
33
+ export declare function rewriteReceiptHistory(test: Readonly<Record<string, unknown>>, nextReceipts: readonly Readonly<Record<string, unknown>>[], context: OperationContext): Promise<void>;
34
+ /**
35
+ * One-off migration for existing stores: apply the ingest-time compaction
36
+ * policy (kibi.proof-receipt-compaction.v1) to every test's receipt history
37
+ * against the live workspace snapshot and each test's current per-contract
38
+ * binding. Coverage decisions are unchanged by construction; histories that
39
+ * are not structurally valid are reported and left untouched, because an
40
+ * invalid history decides `invalid` and must stay visible.
41
+ */
42
+ export declare function executeCompactReceipts(args: CompactReceiptsArgs, context: OperationContext): Promise<{
43
+ content: Array<{
44
+ type: "text";
45
+ text: string;
46
+ }>;
47
+ structuredContent: CompactReceiptsResult;
48
+ }>;
49
+ //# sourceMappingURL=compact-receipts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact-receipts.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/compact-receipts.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAUjF,OAAO,EACL,+BAA+B,EAGhC,MAAM,yBAAyB,CAAC;AAIjC,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAGH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAGH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,MAAM,EAAE,OAAO,+BAA+B,CAAC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5C,OAAO,EAAE,SAAS,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;CAClE,CAAC,CAAC;AAWH;;;;;;GAMG;AAEH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACvC,YAAY,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,EAC1D,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CAiCf;AAED;;;;;;;GAOG;AAEH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IACT,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,qBAAqB,CAAC;CAC1C,CAAC,CA+FD"}
@@ -0,0 +1,160 @@
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
+ import { loadEntities, loadEntitiesPaged, } from "../../public/operations/discovery-entities.js";
19
+ import { readWorkspaceSnapshot } from "../../public/operations/workspace-snapshot.js";
20
+ import { proofReceiptHistoryErrors } from "../../public/proof-receipt.js";
21
+ import { projectEntityProperties } from "../mutation/entity-projection.js";
22
+ import { resolveContainedSourcePath } from "../mutation/source-authoring.js";
23
+ import { executeUpsert } from "../mutation/upsert.js";
24
+ import { currentReceiptBindingHash, loadCoveredBySymbolsByTest, } from "./code-scope.js";
25
+ import { PROOF_RECEIPT_COMPACTION_POLICY, compactProofReceipts, isOrderedReceiptSubsequence, } from "./receipt-compaction.js";
26
+ import { patchReceiptsIntoDocument } from "./receipt-document.js";
27
+ function receiptRecords(value) {
28
+ return Array.isArray(value)
29
+ ? value.filter((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry))
30
+ : [];
31
+ }
32
+ /**
33
+ * Replace one test's receipt history with a shorter, already-validated
34
+ * history. Only the `proof_receipts` frontmatter block of the authored
35
+ * document is rewritten: the rest of the document keeps its exact bytes, so
36
+ * the receipt-stripped document (an input of the per-contract binding) and
37
+ * therefore every receipt's freshness are unchanged by the rewrite.
38
+ */
39
+ // implements REQ-kibi-fresh-verification-receipts-v2
40
+ export async function rewriteReceiptHistory(test, nextReceipts, context) {
41
+ const testId = String(test.id);
42
+ let sourceDocumentOverride;
43
+ const source = typeof test.source === "string" ? test.source : "";
44
+ if (context.fs && /\.(md|mdx)$/i.test(source)) {
45
+ try {
46
+ const absolute = resolveContainedSourcePath(context.workspaceRoot, source);
47
+ const before = await context.fs.readFile(absolute);
48
+ sourceDocumentOverride =
49
+ patchReceiptsIntoDocument(before, nextReceipts) ?? undefined;
50
+ }
51
+ catch {
52
+ sourceDocumentOverride = undefined;
53
+ }
54
+ }
55
+ const properties = projectEntityProperties(test);
56
+ properties.proof_receipts = undefined;
57
+ await executeUpsert({
58
+ type: "test",
59
+ id: testId,
60
+ properties: { ...properties, proof_receipts: [...nextReceipts] },
61
+ }, context, {
62
+ allowReceiptsPrune: true,
63
+ ...(sourceDocumentOverride === undefined
64
+ ? {}
65
+ : { sourceDocumentOverride }),
66
+ });
67
+ }
68
+ /**
69
+ * One-off migration for existing stores: apply the ingest-time compaction
70
+ * policy (kibi.proof-receipt-compaction.v1) to every test's receipt history
71
+ * against the live workspace snapshot and each test's current per-contract
72
+ * binding. Coverage decisions are unchanged by construction; histories that
73
+ * are not structurally valid are reported and left untouched, because an
74
+ * invalid history decides `invalid` and must stay visible.
75
+ */
76
+ // implements REQ-kibi-fresh-verification-receipts-v2
77
+ export async function executeCompactReceipts(args, context) {
78
+ if (!context.prolog)
79
+ throw new Error("Proof compact requires a Prolog runtime");
80
+ const fs = context.fs;
81
+ if (fs === undefined)
82
+ throw new Error("Proof compact failed: this maintenance action rewrites authored test documents and requires a filesystem-capable runtime");
83
+ const workspace = await readWorkspaceSnapshot(context);
84
+ if (!workspace.available)
85
+ throw new Error(`Proof compact failed: ${workspace.error}`);
86
+ const snapshot = workspace.snapshot.hash;
87
+ const dryRun = args.dryRun === true;
88
+ // Receipt histories are exactly what this action reads; page them so a
89
+ // long-lived store never exceeds the bounded Prolog output capacity.
90
+ const tests = args.testId === undefined
91
+ ? await loadEntitiesPaged(context.prolog, "test")
92
+ : await loadEntities(context.prolog, { type: "test", id: args.testId });
93
+ if (args.testId !== undefined && tests.length === 0) {
94
+ throw new Error(`Proof compact failed: test ${args.testId} was not found`);
95
+ }
96
+ const coveredBy = await loadCoveredBySymbolsByTest(context.prolog);
97
+ const results = [];
98
+ const skipped = [];
99
+ for (const test of [...tests].sort((left, right) => String(left.id).localeCompare(String(right.id)))) {
100
+ const testId = String(test.id);
101
+ const receipts = receiptRecords(test.proof_receipts);
102
+ if (receipts.length <= 1)
103
+ continue;
104
+ const historyErrors = proofReceiptHistoryErrors(testId, test.verification_scope, receipts);
105
+ if (historyErrors.length > 0) {
106
+ skipped.push({
107
+ testId,
108
+ reason: `invalid receipt history left untouched: ${historyErrors[0]}`,
109
+ });
110
+ continue;
111
+ }
112
+ const bindingHash = await currentReceiptBindingHash({
113
+ workspaceRoot: context.workspaceRoot,
114
+ readFile: (absolute) => fs.readFile(absolute),
115
+ test,
116
+ coveredBySymbols: coveredBy.get(testId) ?? [],
117
+ });
118
+ const { kept, removed } = compactProofReceipts(receipts, {
119
+ codeSnapshot: snapshot,
120
+ ...(bindingHash === undefined ? {} : { bindingHash }),
121
+ });
122
+ if (removed === 0)
123
+ continue;
124
+ if (!isOrderedReceiptSubsequence(kept, receipts)) {
125
+ throw new Error(`Proof compact failed for ${testId}: compaction must only drop superseded receipts`);
126
+ }
127
+ if (!dryRun)
128
+ await rewriteReceiptHistory(test, kept, context);
129
+ results.push({
130
+ testId,
131
+ before: receipts.length,
132
+ after: kept.length,
133
+ removed,
134
+ });
135
+ }
136
+ const removed = results.reduce((sum, row) => sum + row.removed, 0);
137
+ const verb = dryRun ? "Would remove" : "Removed";
138
+ const summary = results.length === 0
139
+ ? "No test had superseded receipts."
140
+ : `${verb} ${removed} superseded receipt(s) across ${results.length} test(s).`;
141
+ const skippedText = skipped.length > 0
142
+ ? ` Skipped ${skipped.length} test(s) with invalid receipt history.`
143
+ : "";
144
+ return {
145
+ content: [
146
+ {
147
+ type: "text",
148
+ text: `Proof receipts compacted (${PROOF_RECEIPT_COMPACTION_POLICY}). ${summary}${skippedText}`,
149
+ },
150
+ ],
151
+ structuredContent: {
152
+ policy: PROOF_RECEIPT_COMPACTION_POLICY,
153
+ snapshot,
154
+ dryRun,
155
+ removed,
156
+ tests: results,
157
+ skipped,
158
+ },
159
+ };
160
+ }
@@ -13,6 +13,8 @@ export type IngestProofTestResult = Readonly<{
13
13
  applied: boolean;
14
14
  duplicate: boolean;
15
15
  receiptCount: number;
16
+ /** Superseded receipts the ingest compaction dropped from the history. */
17
+ compacted: number;
16
18
  gaps: readonly ProofGap[];
17
19
  }>;
18
20
  export type IngestProofResult = Readonly<{
@@ -1 +1 @@
1
- {"version":3,"file":"ingest-proof.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/ingest-proof.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,yBAAyB,CAAC;AAOjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAkBjF,OAAO,EAEL,KAAK,YAAY,EAGlB,MAAM,+BAA+B,CAAC;AAqBvC,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC3B,CAAC,CAAC;AAGH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC3C,CAAC,CAAC;AAEH,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,CAAC;AAqkBF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAuC5B"}
1
+ {"version":3,"file":"ingest-proof.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/ingest-proof.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,yBAAyB,CAAC;AAOjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAiBjF,OAAO,EAEL,KAAK,YAAY,EAGlB,MAAM,+BAA+B,CAAC;AAkBvC,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC3B,CAAC,CAAC;AAGH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC3C,CAAC,CAAC;AAEH,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,CAAC;AAolBF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAuC5B"}
@@ -1,11 +1,10 @@
1
- import { join } from "node:path";
2
- import { resolveBoundSymbolScope } from "../../extractors/manifest.js";
3
- import { loadCoveredBySymbolsByTest, receiptCodeScopeSymbolIds, } from "./code-scope.js";
1
+ import { currentReceiptBindingHash, loadCoveredBySymbolsByTest, } from "./code-scope.js";
2
+ import { compactProofReceipts, isOrderedReceiptSubsequence, } from "./receipt-compaction.js";
4
3
  import { evaluateContractAgainstRun, } from "../../proof/evaluate.js";
5
4
  import { loadProofIntegrations, resolveIntegration, toExecution, } from "../../proof/integrations.js";
6
5
  import { loadEntities } from "../../public/operations/discovery-entities.js";
7
6
  import { readWorkspaceSnapshot } from "../../public/operations/workspace-snapshot.js";
8
- import { environmentHash as canonicalEnvironmentHash, effectiveProofFingerprint, jsonDigest, proofContractHash, receiptBindingHash, } from "../../public/proof-fingerprint.js";
7
+ import { environmentHash as canonicalEnvironmentHash, effectiveProofFingerprint, jsonDigest, proofContractHash, } from "../../public/proof-fingerprint.js";
9
8
  import { PROOF_CONTRACT_VERSION, PROOF_RECEIPT_VERSION, proofBindingsErrors, proofRunArtifactErrors, } from "../../public/proof-protocol.js";
10
9
  import { MAX_PROOF_RECEIPTS, proofReceiptCurrentBindingErrors, proofReceiptHistoryErrors, } from "../../public/proof-receipt.js";
11
10
  import { projectEntityProperties } from "../mutation/entity-projection.js";
@@ -14,7 +13,7 @@ import { buildUpsertBatchCommitGoal, parseUpsertChangeKinds, } from "../mutation
14
13
  import { executeUpsert } from "../mutation/upsert.js";
15
14
  import { acquireWorkspaceMutationLock, releaseWorkspaceMutationLock, } from "../mutation/workspace-mutation-lock.js";
16
15
  import { MutationRollbackFailureError } from "../mutation/saga.js";
17
- import { patchReceiptsIntoDocument, removeFrontmatterBlock, } from "./receipt-document.js";
16
+ import { patchReceiptsIntoDocument } from "./receipt-document.js";
18
17
  async function rollbackUncommittedReceipts(pending, originalError, lifecycle) {
19
18
  const failures = [];
20
19
  for (const entry of pending) {
@@ -243,21 +242,17 @@ async function executeIngestProofUnlocked(args, context, lifecycle) {
243
242
  // Per-contract receipt binding (W2): hash the receipt-stripped authored
244
243
  // document, the contract, and the bound symbols' source hashes so the
245
244
  // receipt survives unrelated workspace changes and stales only when its
246
- // own inputs (contract, document, production code scope) change.
247
- let bindingHash;
248
- const source = typeof test.source === "string" ? test.source : "";
249
- if (context.fs && source !== "" && /\.(md|mdx)$/i.test(source)) {
250
- try {
251
- const absolute = resolveContainedSourcePath(context.workspaceRoot, source);
252
- const authored = await context.fs.readFile(absolute);
253
- const stripped = removeFrontmatterBlock(authored, "proof_receipts");
254
- const codeScope = resolveBoundSymbolScope(join(context.workspaceRoot, ".kb", "symbols.yaml"), receiptCodeScopeSymbolIds(contract, bindings, coveredBy.get(testId) ?? []));
255
- bindingHash = receiptBindingHash(contract, stripped ?? authored, codeScope);
256
- }
257
- catch {
258
- bindingHash = undefined;
259
- }
260
- }
245
+ // own inputs (contract, document, production code scope) change. The
246
+ // same function computes the binding coverage compares against.
247
+ const fs = context.fs;
248
+ const bindingHash = fs === undefined
249
+ ? undefined
250
+ : await currentReceiptBindingHash({
251
+ workspaceRoot: context.workspaceRoot,
252
+ readFile: (absolute) => fs.readFile(absolute),
253
+ test,
254
+ coveredBySymbols: coveredBy.get(testId) ?? [],
255
+ });
261
256
  const receipt = {
262
257
  version: PROOF_RECEIPT_VERSION,
263
258
  receipt_id: `PR-${jsonDigest({
@@ -319,19 +314,38 @@ async function executeIngestProofUnlocked(args, context, lifecycle) {
319
314
  applied: false,
320
315
  duplicate: true,
321
316
  receiptCount: existing.length,
317
+ compacted: 0,
322
318
  gaps: evaluation.gaps,
323
319
  });
324
320
  continue;
325
321
  }
326
- const nextReceipts = [
322
+ const appended = [
327
323
  ...existing,
328
324
  receipt,
329
- ].slice(-MAX_PROOF_RECEIPTS);
330
- const historyErrors = proofReceiptHistoryErrors(testId, test.verification_scope, nextReceipts);
325
+ ];
326
+ const appendedWindow = appended.slice(-MAX_PROOF_RECEIPTS);
327
+ const historyErrors = proofReceiptHistoryErrors(testId, test.verification_scope, appendedWindow);
331
328
  const bindingErrors = proofReceiptCurrentBindingErrors(testId, test.verification_scope, receipt, contract, receipt.fingerprint);
332
329
  const receiptErrors = [...historyErrors, ...bindingErrors];
333
330
  if (receiptErrors.length > 0)
334
331
  throw new Error(`Proof ingest failed for ${testId}: ${receiptErrors.join("; ")}`);
332
+ // Compact only the validated history: superseded receipts that can no
333
+ // longer decide this test's proof for the snapshot and binding the new
334
+ // receipt was produced on are dropped, so histories stay a handful of
335
+ // entries instead of growing to the rotation cap. The new receipt is
336
+ // always the newest entry and is always kept.
337
+ const nextReceipts = [
338
+ ...compactProofReceipts(appendedWindow, {
339
+ codeSnapshot: snapshot,
340
+ ...(receipt.binding_hash === undefined
341
+ ? {}
342
+ : { bindingHash: receipt.binding_hash }),
343
+ }).kept,
344
+ ];
345
+ if (nextReceipts.at(-1)?.receipt_id !== receipt.receipt_id ||
346
+ !isOrderedReceiptSubsequence(nextReceipts, appended)) {
347
+ throw new Error(`Proof ingest failed for ${testId}: receipt compaction must only drop superseded receipts`);
348
+ }
335
349
  const properties = projectEntityProperties(test);
336
350
  properties.proof_receipts = undefined;
337
351
  // Surgical receipt append: splice only the proof_receipts block into the
@@ -355,8 +369,13 @@ async function executeIngestProofUnlocked(args, context, lifecycle) {
355
369
  }
356
370
  }
357
371
  // exactOptionalPropertyTypes: only pass the override when one exists.
372
+ // The compacted history was checked above to be the existing history plus
373
+ // the new receipt with superseded entries removed, so the generic
374
+ // append-only revalidation (which would reject any removal) is replaced
375
+ // by that stricter subsequence check.
358
376
  const upsertOptions = {
359
377
  deferCompiledCommit: true,
378
+ allowReceiptsPrune: true,
360
379
  ...(sourceDocumentOverride === undefined
361
380
  ? {}
362
381
  : { sourceDocumentOverride }),
@@ -375,6 +394,7 @@ async function executeIngestProofUnlocked(args, context, lifecycle) {
375
394
  outcome: receipt.outcome,
376
395
  receiptId: receipt.receipt_id,
377
396
  receiptCount: nextReceipts.length,
397
+ compacted: appended.length - nextReceipts.length,
378
398
  gaps: evaluation.gaps,
379
399
  deferred,
380
400
  });
@@ -426,6 +446,7 @@ async function executeIngestProofUnlocked(args, context, lifecycle) {
426
446
  applied: true,
427
447
  duplicate: false,
428
448
  receiptCount: entry.receiptCount,
449
+ compacted: entry.compacted,
429
450
  gaps: entry.gaps,
430
451
  });
431
452
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prune-receipts.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/prune-receipts.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AASjF,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,uDAAuD;IAEvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAGH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAE7C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IAEzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,uBAAuB,EAAE,CAAC;CAC3C,CAAC,CAAC;AAYH;;;;;;;;;GASG;AAEH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IACT,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,mBAAmB,CAAC;CACxC,CAAC,CAuED"}
1
+ {"version":3,"file":"prune-receipts.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/prune-receipts.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAQjF,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,uDAAuD;IAEvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAGH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAE7C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IAEzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,uBAAuB,EAAE,CAAC;CAC3C,CAAC,CAAC;AAYH;;;;;;;;;GASG;AAEH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IACT,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,mBAAmB,CAAC;CACxC,CAAC,CAgED"}
@@ -17,8 +17,7 @@
17
17
  */
18
18
  import { loadEntities, loadEntitiesPaged, } from "../../public/operations/discovery-entities.js";
19
19
  import { proofReceiptHistoryErrors, } from "../../public/proof-receipt.js";
20
- import { projectEntityProperties } from "../mutation/entity-projection.js";
21
- import { executeUpsert } from "../mutation/upsert.js";
20
+ import { rewriteReceiptHistory } from "./compact-receipts.js";
22
21
  function parseKeep(value) {
23
22
  if (value === undefined)
24
23
  return 1;
@@ -68,13 +67,10 @@ export async function executePruneReceipts(args, context) {
68
67
  if (historyErrors.length > 0) {
69
68
  throw new Error(`Proof prune failed for ${testId}: pruned history is invalid: ${historyErrors.join("; ")}`);
70
69
  }
71
- const properties = projectEntityProperties(test);
72
- properties.proof_receipts = undefined;
73
- await executeUpsert({
74
- type: "test",
75
- id: testId,
76
- properties: { ...properties, proof_receipts: nextReceipts },
77
- }, context, { allowReceiptsPrune: true });
70
+ // Patch only the receipts block: a canonical re-render of the authored
71
+ // document would change the receipt-stripped bytes the per-contract
72
+ // binding hashes and stale every receipt the prune keeps.
73
+ await rewriteReceiptHistory(test, nextReceipts, context);
78
74
  results.push({
79
75
  testId,
80
76
  before: receipts.length,
@@ -0,0 +1,48 @@
1
+ export declare const PROOF_RECEIPT_COMPACTION_POLICY: "kibi.proof-receipt-compaction.v1";
2
+ /**
3
+ * What "current" means when a history is compacted: the live workspace
4
+ * snapshot and the test's current per-contract binding hash. Coverage selects
5
+ * a test's deciding receipts with exactly these two keys.
6
+ */
7
+ export type ReceiptCompactionAnchor = Readonly<{
8
+ codeSnapshot?: string;
9
+ bindingHash?: string;
10
+ }>;
11
+ export type ReceiptCompaction = Readonly<{
12
+ kept: readonly Readonly<Record<string, unknown>>[];
13
+ removed: number;
14
+ }>;
15
+ type Receipt = Readonly<Record<string, unknown>>;
16
+ /**
17
+ * Deterministic, decision-preserving compaction of one test's proof-receipt
18
+ * history (policy kibi.proof-receipt-compaction.v1).
19
+ *
20
+ * Coverage decides a test from one selector group: receipts whose
21
+ * `binding_hash` equals the test's current binding, or, when there are none,
22
+ * receipts whose `code_snapshot` equals the live snapshot. Within that group
23
+ * it reads the newest receipt per (scope, contract_hash) and the set of
24
+ * contract hashes present. Compaction keeps exactly what those reads can
25
+ * observe, plus two history anchors:
26
+ *
27
+ * - per selector group, the newest receipt for each (scope, contract_hash);
28
+ * - the newest receipt overall (what the last run reported);
29
+ * - the newest passing receipt (last known good, so reverting a change
30
+ * finds its proof again without a re-run).
31
+ *
32
+ * Everything else is superseded evidence: it can never be the deciding
33
+ * receipt again for the current snapshot or binding. The result is an
34
+ * ordered subsequence of the input, so it stays a valid history, and the
35
+ * function is idempotent for a fixed anchor. Inputs that are not structurally
36
+ * valid histories must not be compacted (callers validate first): an invalid
37
+ * history decides `invalid`, and dropping the offending entry would change
38
+ * that decision.
39
+ */
40
+ export declare function compactProofReceipts(receipts: readonly Receipt[], anchor: ReceiptCompactionAnchor): ReceiptCompaction;
41
+ /**
42
+ * True when `subset` is `superset` with entries removed and nothing changed or
43
+ * reordered. Compaction may only drop receipts; this guard keeps every other
44
+ * rewrite of a receipt history fail-closed.
45
+ */
46
+ export declare function isOrderedReceiptSubsequence(subset: readonly Receipt[], superset: readonly Receipt[]): boolean;
47
+ export {};
48
+ //# sourceMappingURL=receipt-compaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt-compaction.d.ts","sourceRoot":"","sources":["../../../src/operations/proof/receipt-compaction.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,+BAA+B,EAC1C,kCAA2C,CAAC;AAE9C;;;;GAIG;AAEH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC,CAAC;AAGH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,IAAI,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,KAAK,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAuBjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,MAAM,EAAE,uBAAuB,GAC9B,iBAAiB,CA0CnB;AAED;;;;GAIG;AAEH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,OAAO,EAAE,EAC1B,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,OAAO,CAcT"}