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
@@ -0,0 +1,233 @@
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 { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync, } from "node:fs";
19
+ import path from "node:path";
20
+ import { isDeepStrictEqual } from "node:util";
21
+ import { load as loadYaml } from "js-yaml";
22
+ import { ENTITY_LANES, KB_PATHS, } from "../../utils/kb-paths.js";
23
+ function walkMarkdown(directory, files) {
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(directory, { withFileTypes: true, encoding: "utf8" });
27
+ }
28
+ catch {
29
+ return;
30
+ }
31
+ for (const entry of entries) {
32
+ const absolute = path.join(directory, entry.name);
33
+ if (entry.isDirectory()) {
34
+ walkMarkdown(absolute, files);
35
+ }
36
+ else if (entry.isFile() &&
37
+ entry.name.endsWith(".md") &&
38
+ entry.name !== "README.md") {
39
+ files.push(absolute);
40
+ }
41
+ }
42
+ }
43
+ /** Every authored Markdown entity file in the canonical lanes, sorted. */
44
+ // implements REQ-cli-schema-migration
45
+ export function listLaneMarkdownFiles(workspaceRoot, lanes = ENTITY_LANES) {
46
+ const result = [];
47
+ for (const lane of lanes) {
48
+ const files = [];
49
+ const laneRoot = path.join(workspaceRoot, KB_PATHS.lanes[lane]);
50
+ if (!existsSync(laneRoot))
51
+ continue;
52
+ walkMarkdown(laneRoot, files);
53
+ for (const absolutePath of files.sort()) {
54
+ result.push({
55
+ lane,
56
+ absolutePath,
57
+ relativePath: path
58
+ .relative(workspaceRoot, absolutePath)
59
+ .replaceAll(path.sep, "/"),
60
+ });
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+ /**
66
+ * Split a document the way the Markdown extractor reads it: the frontmatter
67
+ * ends at the next `---` after the opening delimiter. Returns null when that
68
+ * `---` is not at the start of a line, because an edit there could not be
69
+ * read back.
70
+ */
71
+ // implements REQ-cli-schema-migration
72
+ export function sliceFrontmatter(content) {
73
+ const leading = content.length - content.trimStart().length;
74
+ if (!content.startsWith("---", leading))
75
+ return null;
76
+ const openEnd = content.indexOf("\n", leading + 3);
77
+ if (openEnd < 0)
78
+ return null;
79
+ const close = content.indexOf("---", leading + 3);
80
+ if (close <= openEnd || content[close - 1] !== "\n")
81
+ return null;
82
+ const text = content.slice(openEnd + 1, close);
83
+ return {
84
+ prefix: content.slice(0, openEnd + 1),
85
+ text,
86
+ suffix: content.slice(close),
87
+ eol: text.includes("\r\n") || content[openEnd - 1] === "\r" ? "\r\n" : "\n",
88
+ };
89
+ }
90
+ function isRecord(value) {
91
+ return value !== null && typeof value === "object" && !Array.isArray(value);
92
+ }
93
+ function topLevelFieldPattern(key) {
94
+ return new RegExp(`^${key}[ \\t]*:[^\\r\\n]*`, "m");
95
+ }
96
+ /**
97
+ * The value of one top-level frontmatter key, read from its own line without
98
+ * parsing the whole document (test files carry large receipt histories).
99
+ * Falls back to a full parse when the value spans several lines. Returns
100
+ * `undefined` when the key is absent or the frontmatter does not parse.
101
+ */
102
+ // implements REQ-cli-schema-migration
103
+ export function readTopLevelField(frontmatter, key) {
104
+ const match = topLevelFieldPattern(key).exec(frontmatter);
105
+ if (match === null)
106
+ return undefined;
107
+ const after = frontmatter.slice(match.index + match[0].length);
108
+ const continues = /^\r?\n[ \t]+\S/.test(after);
109
+ try {
110
+ if (!continues) {
111
+ const parsed = loadYaml(match[0]);
112
+ if (isRecord(parsed))
113
+ return parsed[key];
114
+ }
115
+ const parsed = loadYaml(frontmatter);
116
+ return isRecord(parsed) ? parsed[key] : undefined;
117
+ }
118
+ catch {
119
+ return undefined;
120
+ }
121
+ }
122
+ function scalarLine(key, value, previous) {
123
+ const raw = previous.slice(previous.indexOf(":") + 1).trim();
124
+ if (raw.startsWith('"'))
125
+ return `${key}: ${JSON.stringify(value)}`;
126
+ if (raw.startsWith("'"))
127
+ return `${key}: '${value.replaceAll("'", "''")}'`;
128
+ try {
129
+ const plain = loadYaml(`${key}: ${value}`);
130
+ if (isRecord(plain) && plain[key] === value)
131
+ return `${key}: ${value}`;
132
+ }
133
+ catch {
134
+ // Fall through to a quoted scalar.
135
+ }
136
+ return `${key}: ${JSON.stringify(value)}`;
137
+ }
138
+ /**
139
+ * Set one top-level scalar frontmatter key, leaving every other byte of the
140
+ * document unchanged: the key's line is replaced in place, or appended as the
141
+ * last frontmatter key when absent. Returns null when the key spans several
142
+ * lines or the edit would not read back as exactly that change.
143
+ */
144
+ // implements REQ-cli-schema-migration
145
+ export function withTopLevelField(content, key, value) {
146
+ const slice = sliceFrontmatter(content);
147
+ if (slice === null)
148
+ return null;
149
+ const match = topLevelFieldPattern(key).exec(slice.text);
150
+ let text;
151
+ if (match === null) {
152
+ text = `${slice.text}${scalarLine(key, value, "")}${slice.eol}`;
153
+ }
154
+ else {
155
+ const after = slice.text.slice(match.index + match[0].length);
156
+ if (/^\r?\n[ \t]+\S/.test(after))
157
+ return null;
158
+ text = `${slice.text.slice(0, match.index)}${scalarLine(key, value, match[0])}${after}`;
159
+ }
160
+ try {
161
+ const before = loadYaml(slice.text);
162
+ const next = loadYaml(text);
163
+ if (!isRecord(before) || !isRecord(next) || next[key] !== value) {
164
+ return null;
165
+ }
166
+ const { [key]: _beforeValue, ...beforeRest } = before;
167
+ const { [key]: _nextValue, ...nextRest } = next;
168
+ if (!isDeepStrictEqual(beforeRest, nextRest))
169
+ return null;
170
+ }
171
+ catch {
172
+ return null;
173
+ }
174
+ return `${slice.prefix}${text}${slice.suffix}`;
175
+ }
176
+ function frontmatterRecord(text) {
177
+ const parsed = loadYaml(text);
178
+ if (parsed === undefined || parsed === null)
179
+ return {};
180
+ return isRecord(parsed) ? parsed : null;
181
+ }
182
+ /**
183
+ * Remove one top-level scalar frontmatter key, leaving every other byte of
184
+ * the document unchanged: only the key's line and its line break go. Returns
185
+ * the content unchanged when the key is absent. Returns null when the key
186
+ * spans several lines or the edit would not read back as exactly that
187
+ * change (the key gone, every other key parsing identically).
188
+ */
189
+ // implements REQ-kibi-schema6-migration
190
+ export function withoutTopLevelField(content, key) {
191
+ const slice = sliceFrontmatter(content);
192
+ if (slice === null)
193
+ return null;
194
+ const match = topLevelFieldPattern(key).exec(slice.text);
195
+ let text = slice.text;
196
+ if (match !== null) {
197
+ const after = slice.text.slice(match.index + match[0].length);
198
+ if (/^\r?\n[ \t]+\S/.test(after))
199
+ return null;
200
+ text = `${slice.text.slice(0, match.index)}${after.replace(/^\r?\n/, "")}`;
201
+ }
202
+ try {
203
+ const before = frontmatterRecord(slice.text);
204
+ const next = frontmatterRecord(text);
205
+ if (before === null || next === null || Object.hasOwn(next, key)) {
206
+ return null;
207
+ }
208
+ const { [key]: _beforeValue, ...beforeRest } = before;
209
+ if (!isDeepStrictEqual(beforeRest, next))
210
+ return null;
211
+ }
212
+ catch {
213
+ return null;
214
+ }
215
+ return match === null ? content : `${slice.prefix}${text}${slice.suffix}`;
216
+ }
217
+ /** Replace a file's bytes atomically. */
218
+ // implements REQ-cli-schema-migration
219
+ export function writeFileAtomically(filePath, content) {
220
+ mkdirSync(path.dirname(filePath), { recursive: true });
221
+ const tempPath = `${filePath}.kibi-migrate-${process.pid}-${Date.now()}`;
222
+ writeFileSync(tempPath, content, "utf8");
223
+ renameSync(tempPath, filePath);
224
+ }
225
+ // implements REQ-cli-schema-migration
226
+ export function readText(filePath) {
227
+ try {
228
+ return readFileSync(filePath, "utf8");
229
+ }
230
+ catch {
231
+ return null;
232
+ }
233
+ }
@@ -0,0 +1,39 @@
1
+ import { type EntityOrigin } from "../../public/entity-origin.js";
2
+ /** One authored entity the v5 -> v6 migration stamps with an origin. */
3
+ export type OriginBackfillTarget = Readonly<{
4
+ id: string;
5
+ type: string;
6
+ path: string;
7
+ }>;
8
+ export type OriginBackfillSkip = Readonly<{
9
+ path: string;
10
+ reason: string;
11
+ }>;
12
+ export type OriginBackfillPlan = Readonly<{
13
+ targets: readonly OriginBackfillTarget[];
14
+ /** Files Kibi cannot stamp safely; sync reports most of them anyway. */
15
+ skipped: readonly OriginBackfillSkip[];
16
+ }>;
17
+ /** Authored Markdown entities that carry no origin yet. Read-only. */
18
+ export declare function planOriginBackfill(workspaceRoot: string): OriginBackfillPlan;
19
+ /** The origin recorded on entities the v5 -> v6 migration backfills. */
20
+ export declare function migrationOrigin(recordedAt: string): EntityOrigin;
21
+ /**
22
+ * Append `origin` as the last frontmatter key of one document, leaving every
23
+ * other byte unchanged, and confirm the frontmatter reads back with the same
24
+ * fields plus that origin. Returns null when the edit would not read back.
25
+ */
26
+ export declare function withBackfilledOrigin(content: string, origin: EntityOrigin): string | null;
27
+ export type OriginBackfillResult = Readonly<{
28
+ written: readonly OriginBackfillTarget[];
29
+ skipped: readonly OriginBackfillSkip[];
30
+ /** Entities an earlier run (or plan action) already stamped. */
31
+ previouslyStamped: number;
32
+ }>;
33
+ /**
34
+ * Stamp `origin: {kind: migration, ref, recorded_at}` on every authored
35
+ * Markdown entity without an origin. Idempotent: entities that already carry
36
+ * an origin, including ones stamped by an earlier run, are left alone.
37
+ */
38
+ export declare function applyOriginBackfill(workspaceRoot: string, recordedAt: string): OriginBackfillResult;
39
+ //# sourceMappingURL=origin-backfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin-backfill.d.ts","sourceRoot":"","sources":["../../../src/operations/migration/origin-backfill.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,KAAK,YAAY,EAGlB,MAAM,+BAA+B,CAAC;AAQvC,wEAAwE;AAExE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAGH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAG5E,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,OAAO,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACzC,wEAAwE;IACxE,OAAO,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACxC,CAAC,CAAC;AAkEH,sEAAsE;AAEtE,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,kBAAkB,CAa5E;AAED,wEAAwE;AAExE,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY,CAMhE;AAED;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,GAAG,IAAI,CAwBf;AAGD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,OAAO,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACzC,OAAO,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACvC,gEAAgE;IAChE,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CAAC;AAEH;;;;GAIG;AAEH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GACjB,oBAAoB,CA+BtB"}
@@ -0,0 +1,164 @@
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 path from "node:path";
19
+ import { isDeepStrictEqual } from "node:util";
20
+ import { dump as dumpYaml, load as loadYaml } from "js-yaml";
21
+ import { inferTypeFromPath } from "../../extractors/markdown.js";
22
+ import { SCHEMA6_MIGRATION_ORIGIN_REF, normalizeEntityOrigin, } from "../../public/entity-origin.js";
23
+ import { listLaneMarkdownFiles, readText, sliceFrontmatter, writeFileAtomically, } from "./kb-sources.js";
24
+ function isRecord(value) {
25
+ return value !== null && typeof value === "object" && !Array.isArray(value);
26
+ }
27
+ function inspect(workspaceRoot, absolutePath, relativePath) {
28
+ const content = readText(absolutePath);
29
+ if (content === null) {
30
+ return { kind: "skip", skip: { path: relativePath, reason: "unreadable" } };
31
+ }
32
+ const slice = sliceFrontmatter(content);
33
+ if (slice === null) {
34
+ return {
35
+ kind: "skip",
36
+ skip: { path: relativePath, reason: "no closed YAML frontmatter" },
37
+ };
38
+ }
39
+ let data;
40
+ try {
41
+ data = loadYaml(slice.text);
42
+ }
43
+ catch (error) {
44
+ return {
45
+ kind: "skip",
46
+ skip: {
47
+ path: relativePath,
48
+ reason: `frontmatter does not parse: ${error instanceof Error ? error.message : String(error)}`,
49
+ },
50
+ };
51
+ }
52
+ if (!isRecord(data) || typeof data.title !== "string") {
53
+ return {
54
+ kind: "skip",
55
+ skip: { path: relativePath, reason: "frontmatter has no title" },
56
+ };
57
+ }
58
+ if (data.origin !== undefined) {
59
+ const origin = normalizeEntityOrigin(data.origin);
60
+ return {
61
+ kind: "has_origin",
62
+ migrated: "origin" in origin &&
63
+ origin.origin.kind === "migration" &&
64
+ origin.origin.ref === SCHEMA6_MIGRATION_ORIGIN_REF,
65
+ };
66
+ }
67
+ const id = typeof data.id === "string" && data.id.trim() !== ""
68
+ ? data.id.trim()
69
+ : path.basename(relativePath, ".md");
70
+ const type = typeof data.type === "string"
71
+ ? data.type
72
+ : (inferTypeFromPath(path.join(workspaceRoot, relativePath)) ?? "");
73
+ return { kind: "target", target: { id, type, path: relativePath }, content };
74
+ }
75
+ /** Authored Markdown entities that carry no origin yet. Read-only. */
76
+ // implements REQ-cli-schema-migration, REQ-004
77
+ export function planOriginBackfill(workspaceRoot) {
78
+ const targets = [];
79
+ const skipped = [];
80
+ for (const file of listLaneMarkdownFiles(workspaceRoot)) {
81
+ const candidate = inspect(workspaceRoot, file.absolutePath, file.relativePath);
82
+ if (candidate.kind === "target")
83
+ targets.push(candidate.target);
84
+ else if (candidate.kind === "skip")
85
+ skipped.push(candidate.skip);
86
+ }
87
+ return { targets, skipped };
88
+ }
89
+ /** The origin recorded on entities the v5 -> v6 migration backfills. */
90
+ // implements REQ-kibi-entity-origin, REQ-cli-schema-migration
91
+ export function migrationOrigin(recordedAt) {
92
+ return {
93
+ kind: "migration",
94
+ ref: SCHEMA6_MIGRATION_ORIGIN_REF,
95
+ recorded_at: recordedAt,
96
+ };
97
+ }
98
+ /**
99
+ * Append `origin` as the last frontmatter key of one document, leaving every
100
+ * other byte unchanged, and confirm the frontmatter reads back with the same
101
+ * fields plus that origin. Returns null when the edit would not read back.
102
+ */
103
+ // implements REQ-cli-schema-migration
104
+ export function withBackfilledOrigin(content, origin) {
105
+ const slice = sliceFrontmatter(content);
106
+ if (slice === null)
107
+ return null;
108
+ const block = dumpYaml({ origin }, { lineWidth: -1, noRefs: true })
109
+ .split("\n")
110
+ .join(slice.eol);
111
+ const text = `${slice.text}${block}`;
112
+ try {
113
+ const before = loadYaml(slice.text);
114
+ const after = loadYaml(text);
115
+ if (!isRecord(before) || !isRecord(after))
116
+ return null;
117
+ const { origin: readBack, ...rest } = after;
118
+ const normalized = normalizeEntityOrigin(readBack);
119
+ if (!("origin" in normalized) ||
120
+ !isDeepStrictEqual(normalized.origin, origin) ||
121
+ !isDeepStrictEqual(rest, before)) {
122
+ return null;
123
+ }
124
+ }
125
+ catch {
126
+ return null;
127
+ }
128
+ return `${slice.prefix}${text}${slice.suffix}`;
129
+ }
130
+ /**
131
+ * Stamp `origin: {kind: migration, ref, recorded_at}` on every authored
132
+ * Markdown entity without an origin. Idempotent: entities that already carry
133
+ * an origin, including ones stamped by an earlier run, are left alone.
134
+ */
135
+ // implements REQ-cli-schema-migration, REQ-004
136
+ export function applyOriginBackfill(workspaceRoot, recordedAt) {
137
+ const origin = migrationOrigin(recordedAt);
138
+ const written = [];
139
+ const skipped = [];
140
+ let previouslyStamped = 0;
141
+ for (const file of listLaneMarkdownFiles(workspaceRoot)) {
142
+ const candidate = inspect(workspaceRoot, file.absolutePath, file.relativePath);
143
+ if (candidate.kind === "has_origin") {
144
+ if (candidate.migrated)
145
+ previouslyStamped += 1;
146
+ continue;
147
+ }
148
+ if (candidate.kind === "skip") {
149
+ skipped.push(candidate.skip);
150
+ continue;
151
+ }
152
+ const next = withBackfilledOrigin(candidate.content, origin);
153
+ if (next === null) {
154
+ skipped.push({
155
+ path: file.relativePath,
156
+ reason: "origin could not be appended without changing other fields",
157
+ });
158
+ continue;
159
+ }
160
+ writeFileAtomically(file.absolutePath, next);
161
+ written.push(candidate.target);
162
+ }
163
+ return { written, skipped, previouslyStamped };
164
+ }
@@ -0,0 +1,10 @@
1
+ export declare const POLARITY_VALUE_BACKFILL_CODE = "polarity_value_backfill";
2
+ /** Only polarity-only legacy claims have an unambiguous boolean encoding. */
3
+ export declare function planPolarityValueBackfill(workspaceRoot: string): readonly {
4
+ id: string;
5
+ path: string;
6
+ before: string;
7
+ after: string;
8
+ }[];
9
+ export declare function applyPolarityValueBackfill(workspaceRoot: string): number;
10
+ //# sourceMappingURL=polarity-values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polarity-values.d.ts","sourceRoot":"","sources":["../../../src/operations/migration/polarity-values.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAEtE,6EAA6E;AAE7E,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,GACpB,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CA+DxE;AAGD,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAKxE"}
@@ -0,0 +1,60 @@
1
+ import { load as loadYaml } from "js-yaml";
2
+ import { listLaneMarkdownFiles, readText, sliceFrontmatter, writeFileAtomically, } from "./kb-sources.js";
3
+ // implements REQ-cli-schema-migration, REQ-kibi-truthful-consistency
4
+ export const POLARITY_VALUE_BACKFILL_CODE = "polarity_value_backfill";
5
+ /** Only polarity-only legacy claims have an unambiguous boolean encoding. */
6
+ // implements REQ-cli-schema-migration, REQ-kibi-truthful-consistency
7
+ export function planPolarityValueBackfill(workspaceRoot) {
8
+ const targets = [];
9
+ for (const file of listLaneMarkdownFiles(workspaceRoot, ["facts"])) {
10
+ const before = readText(file.absolutePath);
11
+ const slice = before === null ? null : sliceFrontmatter(before);
12
+ if (!slice || before === null)
13
+ continue;
14
+ let data;
15
+ try {
16
+ data = loadYaml(slice.text);
17
+ }
18
+ catch (error) {
19
+ throw new Error(`Cannot migrate fact ${file.relativePath}: ${error instanceof Error ? error.message : String(error)}`);
20
+ }
21
+ if (!data ||
22
+ data.fact_kind !== "property_value" ||
23
+ !["require", "forbid"].includes(String(data.polarity)))
24
+ continue;
25
+ if ([
26
+ "operator",
27
+ "value_type",
28
+ "value_bool",
29
+ "value_int",
30
+ "value_number",
31
+ "value_string",
32
+ ].some((key) => Object.hasOwn(data, key)))
33
+ continue;
34
+ if (typeof data.subject_key !== "string" ||
35
+ typeof data.property_key !== "string")
36
+ throw new Error(`Cannot migrate polarity fact ${file.relativePath}: subject_key and property_key are required`);
37
+ const after = `${slice.prefix}${slice.text}operator: eq${slice.eol}value_type: bool${slice.eol}value_bool: true${slice.eol}${slice.suffix}`;
38
+ const parsed = loadYaml(sliceFrontmatter(after).text);
39
+ if (parsed.operator !== "eq" ||
40
+ parsed.value_type !== "bool" ||
41
+ parsed.value_bool !== true)
42
+ throw new Error(`Polarity migration could not verify ${file.relativePath}`);
43
+ targets.push({
44
+ id: typeof data.id === "string"
45
+ ? data.id
46
+ : file.relativePath.split("/").at(-1).slice(0, -3),
47
+ path: file.relativePath,
48
+ before,
49
+ after,
50
+ });
51
+ }
52
+ return targets;
53
+ }
54
+ // implements REQ-cli-schema-migration, REQ-kibi-truthful-consistency
55
+ export function applyPolarityValueBackfill(workspaceRoot) {
56
+ const targets = planPolarityValueBackfill(workspaceRoot);
57
+ for (const target of targets)
58
+ writeFileAtomically(`${workspaceRoot}/${target.path}`, target.after);
59
+ return targets.length;
60
+ }
@@ -0,0 +1,59 @@
1
+ import { type MigrationAction } from "../../public/operations/migration-plan.js";
2
+ import { CLOSE_SUPERSEDED_REQUIREMENTS_CODE, MIGRATION_SYNC_ACTION_ID, MIGRATION_SYNC_CODE, SOURCE_PATH_REWRITE_CODE } from "../../public/operations/schema6-check-actions.js";
3
+ /** The KB schema generation that introduced entity `origin`. */
4
+ export declare const ORIGIN_SCHEMA_VERSION = 6;
5
+ /** Automatic: re-derive a drifted inventory with the current advisor. */
6
+ export declare const SEMANTIC_INVENTORY_REDERIVE_CODE = "semantic_inventory_rederive";
7
+ /** Review: a drifted inventory Kibi cannot re-derive safely. */
8
+ export declare const SEMANTIC_INVENTORY_REVIEW_CODE = "semantic_inventory_review";
9
+ /** Automatic: stamp `origin: {kind: migration}` on authored entities. */
10
+ export declare const ENTITY_ORIGIN_BACKFILL_CODE = "entity_origin_backfill";
11
+ export declare const ENTITY_ORIGIN_BACKFILL_ACTION_ID = "entity-origin-backfill";
12
+ export { CLOSE_SUPERSEDED_REQUIREMENTS_CODE, MIGRATION_SYNC_ACTION_ID, MIGRATION_SYNC_CODE, SOURCE_PATH_REWRITE_CODE, };
13
+ /**
14
+ * Exceptions without approved_by, read from authored sources so the list is
15
+ * available before the KB compiles.
16
+ */
17
+ export declare function unapprovedExceptionsFromSources(workspaceRoot: string): Array<{
18
+ exceptionId: string;
19
+ exempts: string[];
20
+ source: string;
21
+ }>;
22
+ export type Schema6MigrationFragment = Readonly<{
23
+ actions: readonly MigrationAction[];
24
+ /** Automatic actions that rewrite authored sources. */
25
+ sourceRewriteActionIds: readonly string[];
26
+ diagnostics: readonly string[];
27
+ }>;
28
+ /**
29
+ * Source-derived migration actions: inventory re-derivation whenever an
30
+ * advisor change makes stored inventories drift and the lifecycle repairs
31
+ * (superseded requirements to close, dangling source paths) at any schema
32
+ * version, and, for a KB older than schema 6, the origin backfill plus the
33
+ * exceptions that stop exempting anything. Read-only.
34
+ */
35
+ export declare function buildSchema6MigrationFragment(input: {
36
+ workspaceRoot: string;
37
+ currentSchemaVersion: number | null;
38
+ }): Schema6MigrationFragment;
39
+ /**
40
+ * Actions for the superseded-requirement-open and source-path-dangling
41
+ * findings in authored sources: close superseded requirements, and rewrite
42
+ * moved or remove redundant and dead source values, automatically; one
43
+ * review per supersession cycle and per source value Kibi cannot edit
44
+ * safely. Read-only.
45
+ */
46
+ export declare function buildLifecycleRepairActions(workspaceRoot: string): {
47
+ actions: MigrationAction[];
48
+ sourceRewriteActionIds: string[];
49
+ };
50
+ /** The sync that recompiles sources rewritten by earlier actions. */
51
+ export declare function migrationSyncAction(dependsOn: readonly string[]): MigrationAction;
52
+ type ApplyContext = Readonly<{
53
+ workspaceRoot: string;
54
+ clock: () => Date;
55
+ }>;
56
+ /** Execute one automatic action produced by this module. */
57
+ export declare function applySchema6MigrationAction(action: MigrationAction, context: ApplyContext): Promise<void>;
58
+ export declare const SCHEMA6_AUTOMATIC_CODES: ReadonlySet<string>;
59
+ //# sourceMappingURL=schema6.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema6.d.ts","sourceRoot":"","sources":["../../../src/operations/migration/schema6.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEL,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EAEnB,wBAAwB,EAOzB,MAAM,kDAAkD,CAAC;AA2B1D,gEAAgE;AAEhE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,yEAAyE;AAEzE,eAAO,MAAM,gCAAgC,gCAAgC,CAAC;AAC9E,gEAAgE;AAEhE,eAAO,MAAM,8BAA8B,8BAA8B,CAAC;AAC1E,yEAAyE;AAEzE,eAAO,MAAM,2BAA2B,2BAA2B,CAAC;AAEpE,eAAO,MAAM,gCAAgC,2BAA2B,CAAC;AACzE,OAAO,EACL,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,GACzB,CAAC;AAsEF;;;GAGG;AAEH,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,GACpB,KAAK,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsDnE;AAGD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IACpC,uDAAuD;IACvD,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,CAAC,CAAC;AAEH;;;;;;GAMG;AAEH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC,GAAG,wBAAwB,CA8F3B;AAED;;;;;;GAMG;AAEH,wBAAgB,2BAA2B,CAAC,aAAa,EAAE,MAAM,GAAG;IAClE,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,sBAAsB,EAAE,MAAM,EAAE,CAAC;CAClC,CAoCA;AAED,qEAAqE;AAErE,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,eAAe,CAEjB;AA0CD,KAAK,YAAY,GAAG,QAAQ,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC,CAAC;AAEH,4DAA4D;AAE5D,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CA8Df;AAGD,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAOtD,CAAC"}