kibi-cli 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) 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 +37 -9
  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 +12 -4
  7. package/dist/cli-operation-metadata.d.ts.map +1 -1
  8. package/dist/cli-operation-metadata.js +14 -4
  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-proof.d.ts.map +1 -1
  13. package/dist/cli-register-proof.js +13 -0
  14. package/dist/commands/check.d.ts.map +1 -1
  15. package/dist/commands/check.js +11 -2
  16. package/dist/commands/discovery-shared.d.ts.map +1 -1
  17. package/dist/commands/discovery-shared.js +8 -2
  18. package/dist/commands/engine.d.ts.map +1 -1
  19. package/dist/commands/engine.js +4 -2
  20. package/dist/commands/gc.d.ts.map +1 -1
  21. package/dist/commands/gc.js +7 -0
  22. package/dist/commands/init-helpers.d.ts.map +1 -1
  23. package/dist/commands/init-helpers.js +38 -12
  24. package/dist/commands/init.d.ts.map +1 -1
  25. package/dist/commands/init.js +10 -15
  26. package/dist/commands/migrate.d.ts.map +1 -1
  27. package/dist/commands/migrate.js +281 -14
  28. package/dist/commands/proof-compact.d.ts +9 -0
  29. package/dist/commands/proof-compact.d.ts.map +1 -0
  30. package/dist/commands/proof-compact.js +58 -0
  31. package/dist/commands/prove.d.ts +38 -0
  32. package/dist/commands/prove.d.ts.map +1 -1
  33. package/dist/commands/prove.js +222 -47
  34. package/dist/commands/sync/persistence.d.ts.map +1 -1
  35. package/dist/commands/sync/persistence.js +61 -16
  36. package/dist/commands/sync.d.ts +8 -0
  37. package/dist/commands/sync.d.ts.map +1 -1
  38. package/dist/commands/sync.js +42 -16
  39. package/dist/diagnostics.js +1 -1
  40. package/dist/engine-limits.d.ts +74 -0
  41. package/dist/engine-limits.d.ts.map +1 -0
  42. package/dist/engine-limits.js +201 -0
  43. package/dist/engine.d.ts +10 -0
  44. package/dist/engine.d.ts.map +1 -1
  45. package/dist/engine.js +57 -9
  46. package/dist/extractors/manifest.d.ts +8 -0
  47. package/dist/extractors/manifest.d.ts.map +1 -1
  48. package/dist/extractors/manifest.js +34 -5
  49. package/dist/extractors/markdown.d.ts +8 -0
  50. package/dist/extractors/markdown.d.ts.map +1 -1
  51. package/dist/extractors/markdown.js +57 -0
  52. package/dist/extractors/relationships.d.ts.map +1 -1
  53. package/dist/extractors/relationships.js +2 -0
  54. package/dist/intent-search.d.ts +4 -1
  55. package/dist/intent-search.d.ts.map +1 -1
  56. package/dist/intent-search.js +186 -33
  57. package/dist/operations/bootstrap/candidate-helpers.d.ts.map +1 -1
  58. package/dist/operations/bootstrap/candidate-helpers.js +8 -1
  59. package/dist/operations/bootstrap/candidates.d.ts.map +1 -1
  60. package/dist/operations/bootstrap/candidates.js +54 -38
  61. package/dist/operations/bootstrap/generate.d.ts +2 -0
  62. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  63. package/dist/operations/bootstrap/generate.js +87 -33
  64. package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -1
  65. package/dist/operations/bootstrap/intent-claims.js +12 -4
  66. package/dist/operations/bootstrap/markdown-candidates.d.ts +2 -0
  67. package/dist/operations/bootstrap/markdown-candidates.d.ts.map +1 -1
  68. package/dist/operations/bootstrap/markdown-candidates.js +32 -10
  69. package/dist/operations/bootstrap/presentation.d.ts.map +1 -1
  70. package/dist/operations/bootstrap/presentation.js +6 -2
  71. package/dist/operations/bootstrap/requirement-claims.d.ts +1 -0
  72. package/dist/operations/bootstrap/requirement-claims.d.ts.map +1 -1
  73. package/dist/operations/bootstrap/requirement-claims.js +13 -1
  74. package/dist/operations/bootstrap/validation.d.ts +4 -0
  75. package/dist/operations/bootstrap/validation.d.ts.map +1 -0
  76. package/dist/operations/bootstrap/validation.js +20 -0
  77. package/dist/operations/migration/inventory-rederive.d.ts +81 -0
  78. package/dist/operations/migration/inventory-rederive.d.ts.map +1 -0
  79. package/dist/operations/migration/inventory-rederive.js +484 -0
  80. package/dist/operations/migration/kb-sources.d.ts +53 -0
  81. package/dist/operations/migration/kb-sources.d.ts.map +1 -0
  82. package/dist/operations/migration/kb-sources.js +233 -0
  83. package/dist/operations/migration/origin-backfill.d.ts +39 -0
  84. package/dist/operations/migration/origin-backfill.d.ts.map +1 -0
  85. package/dist/operations/migration/origin-backfill.js +164 -0
  86. package/dist/operations/migration/polarity-values.d.ts +10 -0
  87. package/dist/operations/migration/polarity-values.d.ts.map +1 -0
  88. package/dist/operations/migration/polarity-values.js +60 -0
  89. package/dist/operations/migration/schema6.d.ts +59 -0
  90. package/dist/operations/migration/schema6.d.ts.map +1 -0
  91. package/dist/operations/migration/schema6.js +379 -0
  92. package/dist/operations/migration/source-paths.d.ts +131 -0
  93. package/dist/operations/migration/source-paths.d.ts.map +1 -0
  94. package/dist/operations/migration/source-paths.js +308 -0
  95. package/dist/operations/migration/superseded-closure.d.ts +54 -0
  96. package/dist/operations/migration/superseded-closure.d.ts.map +1 -0
  97. package/dist/operations/migration/superseded-closure.js +187 -0
  98. package/dist/operations/modeling/logic-modeling.d.ts.map +1 -1
  99. package/dist/operations/modeling/logic-modeling.js +3 -5
  100. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  101. package/dist/operations/modeling/model-requirement.js +225 -67
  102. package/dist/operations/mutation/contradictions.d.ts +16 -0
  103. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  104. package/dist/operations/mutation/contradictions.js +32 -0
  105. package/dist/operations/mutation/delete.d.ts.map +1 -1
  106. package/dist/operations/mutation/delete.js +15 -7
  107. package/dist/operations/mutation/origin.d.ts +21 -0
  108. package/dist/operations/mutation/origin.d.ts.map +1 -0
  109. package/dist/operations/mutation/origin.js +78 -0
  110. package/dist/operations/mutation/plan-apply-journal.d.ts +182 -0
  111. package/dist/operations/mutation/plan-apply-journal.d.ts.map +1 -0
  112. package/dist/operations/mutation/plan-apply-journal.js +613 -0
  113. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +3 -1
  114. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -1
  115. package/dist/operations/mutation/predicate-vocabulary-guard.js +13 -2
  116. package/dist/operations/mutation/relationships.d.ts +5 -5
  117. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  118. package/dist/operations/mutation/relationships.js +31 -11
  119. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  120. package/dist/operations/mutation/serialization.js +3 -1
  121. package/dist/operations/mutation/source-authoring.d.ts +6 -0
  122. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  123. package/dist/operations/mutation/source-authoring.js +7 -1
  124. package/dist/operations/mutation/types.d.ts +14 -0
  125. package/dist/operations/mutation/types.d.ts.map +1 -1
  126. package/dist/operations/mutation/upsert.d.ts +30 -3
  127. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  128. package/dist/operations/mutation/upsert.js +105 -35
  129. package/dist/operations/mutation/validate-upsert.d.ts +6 -0
  130. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  131. package/dist/operations/mutation/validate-upsert.js +34 -30
  132. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  133. package/dist/operations/planning/apply-plan.js +753 -145
  134. package/dist/operations/planning/compile-intent.d.ts +34 -1
  135. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  136. package/dist/operations/planning/compile-intent.js +314 -98
  137. package/dist/operations/proof/code-scope.d.ts +28 -0
  138. package/dist/operations/proof/code-scope.d.ts.map +1 -1
  139. package/dist/operations/proof/code-scope.js +72 -0
  140. package/dist/operations/proof/compact-receipts.d.ts +49 -0
  141. package/dist/operations/proof/compact-receipts.d.ts.map +1 -0
  142. package/dist/operations/proof/compact-receipts.js +160 -0
  143. package/dist/operations/proof/ingest-proof.d.ts +2 -0
  144. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  145. package/dist/operations/proof/ingest-proof.js +44 -23
  146. package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
  147. package/dist/operations/proof/prune-receipts.js +5 -9
  148. package/dist/operations/proof/receipt-compaction.d.ts +48 -0
  149. package/dist/operations/proof/receipt-compaction.d.ts.map +1 -0
  150. package/dist/operations/proof/receipt-compaction.js +121 -0
  151. package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
  152. package/dist/operations/semantic-advisor/analysis-receipt.js +12 -1
  153. package/dist/operations/semantic-advisor/analyze-prose.d.ts +2 -1
  154. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  155. package/dist/operations/semantic-advisor/analyze-prose.js +51 -5
  156. package/dist/operations/semantic-advisor/clauses.d.ts +1 -0
  157. package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
  158. package/dist/operations/semantic-advisor/clauses.js +11 -1
  159. package/dist/operations/semantic-advisor/conditional-rules.d.ts +33 -0
  160. package/dist/operations/semantic-advisor/conditional-rules.d.ts.map +1 -0
  161. package/dist/operations/semantic-advisor/conditional-rules.js +262 -0
  162. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +3 -1
  163. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
  164. package/dist/operations/semantic-advisor/ingestion-boundary.js +14 -6
  165. package/dist/operations/semantic-advisor/plugin-orchestration.js +1 -1
  166. package/dist/prolog/codec.d.ts.map +1 -1
  167. package/dist/prolog/codec.js +2 -1
  168. package/dist/prolog.d.ts +9 -0
  169. package/dist/prolog.d.ts.map +1 -1
  170. package/dist/prolog.js +56 -10
  171. package/dist/proof/command-test-report.d.ts +74 -0
  172. package/dist/proof/command-test-report.d.ts.map +1 -0
  173. package/dist/proof/command-test-report.js +206 -0
  174. package/dist/public/branch-resolver.d.ts +1 -0
  175. package/dist/public/branch-resolver.d.ts.map +1 -1
  176. package/dist/public/branch-resolver.js +1 -0
  177. package/dist/public/entity-origin.d.ts +69 -0
  178. package/dist/public/entity-origin.d.ts.map +1 -0
  179. package/dist/public/entity-origin.js +142 -0
  180. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  181. package/dist/public/impact/full-kb-quality.js +1 -0
  182. package/dist/public/impact/requirement-quality.js +1 -1
  183. package/dist/public/operations/catalog.d.ts +130 -19
  184. package/dist/public/operations/catalog.d.ts.map +1 -1
  185. package/dist/public/operations/catalog.js +3 -0
  186. package/dist/public/operations/check-executor.d.ts.map +1 -1
  187. package/dist/public/operations/check-executor.js +8 -0
  188. package/dist/public/operations/contracts.d.ts +0 -5
  189. package/dist/public/operations/contracts.d.ts.map +1 -1
  190. package/dist/public/operations/contracts.js +63 -14
  191. package/dist/public/operations/discovery-entities.d.ts +15 -0
  192. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  193. package/dist/public/operations/discovery-entities.js +59 -0
  194. package/dist/public/operations/discovery-executors.d.ts +6 -1
  195. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  196. package/dist/public/operations/discovery-executors.js +65 -6
  197. package/dist/public/operations/index.d.ts +1 -0
  198. package/dist/public/operations/index.d.ts.map +1 -1
  199. package/dist/public/operations/index.js +1 -0
  200. package/dist/public/operations/migration-plan.d.ts +5 -0
  201. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  202. package/dist/public/operations/migration-plan.js +26 -1
  203. package/dist/public/operations/node-ports.d.ts.map +1 -1
  204. package/dist/public/operations/node-ports.js +24 -3
  205. package/dist/public/operations/origin-review.d.ts +51 -0
  206. package/dist/public/operations/origin-review.d.ts.map +1 -0
  207. package/dist/public/operations/origin-review.js +307 -0
  208. package/dist/public/operations/predicate-schema-conformance.js +1 -1
  209. package/dist/public/operations/repair-plan.d.ts.map +1 -1
  210. package/dist/public/operations/repair-plan.js +4 -0
  211. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  212. package/dist/public/operations/result-envelope.js +17 -5
  213. package/dist/public/operations/runtime-types.d.ts +9 -0
  214. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  215. package/dist/public/operations/schema6-check-actions.d.ts +127 -0
  216. package/dist/public/operations/schema6-check-actions.d.ts.map +1 -0
  217. package/dist/public/operations/schema6-check-actions.js +575 -0
  218. package/dist/public/operations/source-path-dangling.d.ts +17 -0
  219. package/dist/public/operations/source-path-dangling.d.ts.map +1 -0
  220. package/dist/public/operations/source-path-dangling.js +66 -0
  221. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  222. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  223. package/dist/public/operations/specs/check-rules.generated.js +15 -1
  224. package/dist/public/operations/specs/check.d.ts +2 -2
  225. package/dist/public/operations/specs/check.js +1 -1
  226. package/dist/public/operations/specs/composite.d.ts +351 -0
  227. package/dist/public/operations/specs/composite.d.ts.map +1 -0
  228. package/dist/public/operations/specs/composite.js +96 -0
  229. package/dist/public/operations/specs/discovery.d.ts +8 -3
  230. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  231. package/dist/public/operations/specs/discovery.js +8 -3
  232. package/dist/public/operations/specs/modeling.d.ts +2 -2
  233. package/dist/public/operations/specs/modeling.js +2 -2
  234. package/dist/public/operations/specs/mutation-schemas.d.ts +73 -8
  235. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  236. package/dist/public/operations/specs/mutation-schemas.js +43 -7
  237. package/dist/public/operations/specs/mutation.d.ts +1 -1
  238. package/dist/public/operations/specs/mutation.js +1 -1
  239. package/dist/public/operations/specs/planning.d.ts +2 -2
  240. package/dist/public/operations/specs/planning.js +4 -4
  241. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  242. package/dist/public/operations/specs/reporting.js +13 -26
  243. package/dist/public/operations/specs/upsert.d.ts +79 -9
  244. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  245. package/dist/public/operations/specs/upsert.js +6 -1
  246. package/dist/public/operations/types.d.ts +1 -1
  247. package/dist/public/operations/types.d.ts.map +1 -1
  248. package/dist/public/proof-receipt.d.ts +1 -0
  249. package/dist/public/proof-receipt.d.ts.map +1 -1
  250. package/dist/public/schemas/entity.d.ts.map +1 -1
  251. package/dist/public/schemas/entity.js +52 -0
  252. package/dist/public/schemas/relationship.d.ts.map +1 -1
  253. package/dist/public/schemas/relationship.js +2 -0
  254. package/dist/public/skills/kibi-bootstrap/SKILL.md +35 -67
  255. package/dist/public/skills/kibi-bootstrap/resources/bootstrap.md +6 -0
  256. package/dist/public/skills/kibi-usage/SKILL.md +68 -18
  257. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  258. package/dist/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  259. package/dist/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  260. package/dist/public/skills/kibi-usage/resources/operation-access.md +25 -1
  261. package/dist/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  262. package/dist/public/skills/kibi-usage/resources/workflows.md +42 -25
  263. package/dist/public/telemetry-acceptance.d.ts +58 -2
  264. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  265. package/dist/public/telemetry-acceptance.js +136 -10
  266. package/dist/public/telemetry-remediation.d.ts.map +1 -1
  267. package/dist/public/telemetry-remediation.js +26 -10
  268. package/dist/relationships/shards.d.ts +13 -0
  269. package/dist/relationships/shards.d.ts.map +1 -1
  270. package/dist/relationships/shards.js +54 -28
  271. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  272. package/dist/runtime/cli-runtime.js +44 -3
  273. package/dist/runtime/detached-snapshot.d.ts +38 -0
  274. package/dist/runtime/detached-snapshot.d.ts.map +1 -0
  275. package/dist/runtime/detached-snapshot.js +92 -0
  276. package/dist/schemas/entity.schema.json +122 -0
  277. package/dist/search-answer.d.ts +157 -0
  278. package/dist/search-answer.d.ts.map +1 -0
  279. package/dist/search-answer.js +846 -0
  280. package/dist/traceability/impact-knowledge.d.ts.map +1 -1
  281. package/dist/traceability/impact-knowledge.js +7 -0
  282. package/dist/traceability/symbol-extract.js +3 -3
  283. package/dist/traceability/temp-kb.d.ts.map +1 -1
  284. package/dist/traceability/temp-kb.js +12 -0
  285. package/dist/types/entities.d.ts +13 -0
  286. package/dist/types/entities.d.ts.map +1 -1
  287. package/dist/types/relationships.d.ts +1 -1
  288. package/dist/types/relationships.d.ts.map +1 -1
  289. package/dist/utils/branch-resolver.d.ts +37 -1
  290. package/dist/utils/branch-resolver.d.ts.map +1 -1
  291. package/dist/utils/branch-resolver.js +130 -3
  292. package/dist/utils/repo-relative-path.d.ts +18 -0
  293. package/dist/utils/repo-relative-path.d.ts.map +1 -0
  294. package/dist/utils/repo-relative-path.js +58 -0
  295. package/dist/utils/rule-registry.generated.d.ts +75 -3
  296. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  297. package/dist/utils/rule-registry.generated.js +89 -3
  298. package/dist/utils/schema-version.d.ts +1 -1
  299. package/dist/utils/schema-version.d.ts.map +1 -1
  300. package/dist/utils/schema-version.js +4 -3
  301. package/dist/utils/strict-modeling.d.ts +1 -1
  302. package/dist/utils/strict-modeling.d.ts.map +1 -1
  303. package/dist/utils/strict-modeling.js +23 -3
  304. package/package.json +3 -3
  305. package/schema/entities.pl +22 -0
  306. package/schema/relationships.pl +14 -0
  307. package/schema/validation.pl +45 -1
  308. package/src/public/branch-resolver.ts +1 -0
  309. package/src/public/entity-origin.ts +175 -0
  310. package/src/public/impact/full-kb-quality.ts +1 -0
  311. package/src/public/impact/requirement-quality.ts +1 -1
  312. package/src/public/operations/catalog.ts +3 -0
  313. package/src/public/operations/check-executor.ts +15 -0
  314. package/src/public/operations/contracts.ts +75 -15
  315. package/src/public/operations/discovery-entities.ts +74 -0
  316. package/src/public/operations/discovery-executors.ts +88 -10
  317. package/src/public/operations/index.ts +1 -0
  318. package/src/public/operations/migration-plan.ts +30 -1
  319. package/src/public/operations/node-ports.ts +24 -3
  320. package/src/public/operations/origin-review.ts +375 -0
  321. package/src/public/operations/predicate-schema-conformance.ts +1 -1
  322. package/src/public/operations/repair-plan.ts +4 -0
  323. package/src/public/operations/result-envelope.ts +18 -6
  324. package/src/public/operations/runtime-types.ts +9 -0
  325. package/src/public/operations/schema6-check-actions.ts +699 -0
  326. package/src/public/operations/source-path-dangling.ts +81 -0
  327. package/src/public/operations/specs/check-rules.generated.ts +15 -1
  328. package/src/public/operations/specs/check.ts +1 -1
  329. package/src/public/operations/specs/composite.ts +141 -0
  330. package/src/public/operations/specs/discovery.ts +9 -3
  331. package/src/public/operations/specs/modeling.ts +2 -2
  332. package/src/public/operations/specs/mutation-schemas.ts +49 -7
  333. package/src/public/operations/specs/mutation.ts +1 -1
  334. package/src/public/operations/specs/planning.ts +4 -4
  335. package/src/public/operations/specs/reporting.ts +13 -38
  336. package/src/public/operations/specs/upsert.ts +7 -1
  337. package/src/public/operations/types.ts +2 -0
  338. package/src/public/proof-receipt.ts +1 -0
  339. package/src/public/schemas/entity.ts +57 -0
  340. package/src/public/schemas/relationship.ts +2 -0
  341. package/src/public/skills/kibi-bootstrap/SKILL.md +35 -67
  342. package/src/public/skills/kibi-bootstrap/resources/bootstrap.md +6 -0
  343. package/src/public/skills/kibi-usage/SKILL.md +68 -18
  344. package/src/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  345. package/src/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  346. package/src/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  347. package/src/public/skills/kibi-usage/resources/operation-access.md +25 -1
  348. package/src/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  349. package/src/public/skills/kibi-usage/resources/workflows.md +42 -25
  350. package/src/public/telemetry-acceptance-types.d.ts +4 -1
  351. package/src/public/telemetry-acceptance.ts +204 -10
  352. package/src/public/telemetry-remediation.ts +39 -10
  353. package/src/schemas/entity.schema.json +122 -0
  354. package/src/schemas/relationship.schema.json +2 -0
@@ -1,6 +1,12 @@
1
1
  import type { Command } from "commander";
2
2
  import type { OperationName } from "./public/operations/types.js";
3
3
  export declare function writeOptionalStderr(stderr: string | undefined): void;
4
+ /**
5
+ * Runs `fn` with console.log and console.info sent to stderr. Commands that a
6
+ * JSON route reuses (sync, branch ensure, migrate) print progress; on stdout
7
+ * it would land ahead of the JSON document and make it unparseable.
8
+ */
9
+ export declare function withConsoleOnStderr<T>(fn: () => Promise<T>): Promise<T>;
4
10
  export type JsonInvocation = {
5
11
  readonly operationName: OperationName;
6
12
  readonly inputPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"cli-json-command.d.ts","sourceRoot":"","sources":["../src/cli-json-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAGlE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAIpE;AAGD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;KACpC,EAAE,CAAC;CACL,CAAC;AAkDF,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC,IAAI,CAAC,CAuGf"}
1
+ {"version":3,"file":"cli-json-command.d.ts","sourceRoot":"","sources":["../src/cli-json-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAazC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAGlE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAIpE;AAGD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAW7E;AAGD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;KACpC,EAAE,CAAC;CACL,CAAC;AAkDF,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Gf"}
@@ -2,7 +2,7 @@ import { once } from "node:events";
2
2
  import { InputError } from "./cli-errors.js";
3
3
  import { loadInput } from "./cli-input.js";
4
4
  import { loadOperationSpec } from "./cli-operation-loader.js";
5
- import { executeOperation as executeProtocolOperation } from "./cli-protocol.js";
5
+ import { executeOperation as executeProtocolOperation, openFailureResult, } from "./cli-protocol.js";
6
6
  import { prepareOperationInput } from "./cli-validate.js";
7
7
  import { appendCliDiagnosticUsage, diagnosticEnvOptIn, } from "./public/diagnostic-usage.js";
8
8
  import { createCliRuntime } from "./runtime/cli-runtime.js";
@@ -11,6 +11,25 @@ export function writeOptionalStderr(stderr) {
11
11
  process.stderr.write(stderr);
12
12
  }
13
13
  }
14
+ // implements REQ-kibi-operation-interface-parity
15
+ /**
16
+ * Runs `fn` with console.log and console.info sent to stderr. Commands that a
17
+ * JSON route reuses (sync, branch ensure, migrate) print progress; on stdout
18
+ * it would land ahead of the JSON document and make it unparseable.
19
+ */
20
+ export async function withConsoleOnStderr(fn) {
21
+ const { log, info } = console;
22
+ const toStderr = (...args) => console.error(...args);
23
+ console.log = toStderr;
24
+ console.info = toStderr;
25
+ try {
26
+ return await fn();
27
+ }
28
+ finally {
29
+ console.log = log;
30
+ console.info = info;
31
+ }
32
+ }
14
33
  function writeInputError(error) {
15
34
  process.stderr.write(`Error [${error.code}]: ${error.detail}\n`);
16
35
  process.exitCode = error.exitCode;
@@ -103,14 +122,23 @@ export async function runJsonInvocation(invocation) {
103
122
  const runtime = createCliRuntime({ workspaceRoot });
104
123
  let result;
105
124
  try {
106
- const context = await runtime.open(spec, { workspaceRoot });
107
- result = await executeProtocolOperation(invocation.operationName, input, context);
108
- if (result.exitCode === 0 && spec.effects.includes("kb-write")) {
109
- await runtime.afterSuccess(spec, context);
110
- }
111
- await runtime.close(context, {
112
- status: "success",
113
- result,
125
+ result = await withConsoleOnStderr(async () => {
126
+ let context;
127
+ try {
128
+ context = await runtime.open(spec, { workspaceRoot });
129
+ }
130
+ catch (error) {
131
+ return openFailureResult(invocation.operationName, spec, error);
132
+ }
133
+ const executed = await executeProtocolOperation(invocation.operationName, input, context);
134
+ if (executed.exitCode === 0 && spec.effects.includes("kb-write")) {
135
+ await runtime.afterSuccess(spec, context);
136
+ }
137
+ await runtime.close(context, {
138
+ status: "success",
139
+ result: executed,
140
+ });
141
+ return executed;
114
142
  });
115
143
  }
116
144
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"cli-operation-loader.d.ts","sourceRoot":"","sources":["../src/cli-operation-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACd,MAAM,8BAA8B,CAAC;AAOtC,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,aAAa,CAAC,CAyFxB"}
1
+ {"version":3,"file":"cli-operation-loader.d.ts","sourceRoot":"","sources":["../src/cli-operation-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACd,MAAM,8BAA8B,CAAC;AAOtC,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,aAAa,CAAC,CAgGxB"}
@@ -85,6 +85,13 @@ export async function loadOperationSpec(name) {
85
85
  spec = (await import("./public/operations/specs/planning.js"))
86
86
  .applyPlanSpec;
87
87
  break;
88
+ case "kb_skills":
89
+ spec = (await import("./public/operations/specs/composite.js"))
90
+ .skillsSpec;
91
+ break;
92
+ case "kb_model":
93
+ spec = (await import("./public/operations/specs/composite.js")).modelSpec;
94
+ break;
88
95
  case "kb_ingest_proof":
89
96
  spec = (await import("./public/operations/specs/proof.js"))
90
97
  .ingestProofSpec;
@@ -16,6 +16,10 @@ export declare const CLI_OPERATION_METADATA: readonly [{
16
16
  readonly name: "kb_skills_read";
17
17
  readonly cliName: "skills read";
18
18
  readonly description: "Read a declared resource from a bundled Kibi agent skill. Resource paths are restricted to the skill manifest; arbitrary file paths are not exposed. Read-only; does not require Prolog.";
19
+ }, {
20
+ readonly name: "kb_skills";
21
+ readonly cliName: "skill";
22
+ readonly description: "Read bundled Kibi agent skills (workflow guidance). action:list returns the catalog; action:load returns a skill's metadata, Markdown body, declared resources and content hash (start with id 'kibi-usage'); action:read returns one manifest-declared resource. Read-only; does not require Prolog.";
19
23
  }, {
20
24
  readonly name: "kb_query";
21
25
  readonly cliName: "query";
@@ -23,7 +27,7 @@ export declare const CLI_OPERATION_METADATA: readonly [{
23
27
  }, {
24
28
  readonly name: "kb_search";
25
29
  readonly cliName: "search";
26
- readonly description: "Search KB entities for discovery using legacy lexical ranking or deterministic intent-v1 ranking. Intent mode accepts host-agent semantic facets and source locations, returns evidence and abstains below its confidence threshold. Use for exploratory lookup before exact follow-up with kb_query. No mutation side effects.";
30
+ readonly description: "Ask the KB a question or search it. Default intent-v1 ranking accepts questions, host-agent semantic facets and changed-code source locations, returns evidence, abstains below its confidence threshold and adds an answer layer: the current requirements that govern the topic, what must stay true (linked facts), why (ADRs) and what verifies it (scenarios, tests). Use before changing behavior, then kb_query for exact follow-up. No mutation side effects.";
27
31
  }, {
28
32
  readonly name: "kb_status";
29
33
  readonly cliName: "status";
@@ -52,6 +56,10 @@ export declare const CLI_OPERATION_METADATA: readonly [{
52
56
  readonly name: "kb_suggest_predicates";
53
57
  readonly cliName: "suggest-predicates";
54
58
  readonly description: "Suggest ontology predicate schemas for prose requirements before agents write facts. Retrieval/ranking is followed by a semantic applicability gate and conservative binding review; complete-looking generic placeholders never trigger application. Read-only guidance returns additive candidate diagnostics, an applicable predicate-fact plan only for a semantically eligible candidate with reviewed bindings, or an explicit ontology-gap observation plus a deterministic review-only predicate schema draft when no schema fits.";
59
+ }, {
60
+ readonly name: "kb_model";
61
+ readonly cliName: "model";
62
+ readonly description: "Turn requirement prose into checkable structure without writing the KB. mode:analyze returns the semantic advisor receipt: the clause ledger, what is grounded, what is ambiguous and suggested modeling (pass clauses for compound prose and optional typed kibi.logic.v1 interpretations). mode:requirement converts one claim (subjectKey, propertyKey, operator, value, or typed logic) into a strict-lane write set and applyPlan. mode:predicates ranks ontology predicate schemas and returns an applicable predicate-fact plan only for reviewed bindings, otherwise an ontology-gap observation. Apply returned plans with kb_upsert.";
55
63
  }, {
56
64
  readonly name: "kb_plan_bootstrap";
57
65
  readonly cliName: "plan-bootstrap";
@@ -59,11 +67,11 @@ export declare const CLI_OPERATION_METADATA: readonly [{
59
67
  }, {
60
68
  readonly name: "kb_validate_upsert";
61
69
  readonly cliName: "validate-upsert";
62
- readonly description: "Validate a kb_upsert payload without mutating the KB. Use this read-only preflight before kb_upsert, especially for requirements, because it returns schema/modeling errors plus semantic advisor receipts that identify prose likely needing kb_model_requirement, kb_suggest_predicates, ambiguity review, or an ontology-gap observation.";
70
+ readonly description: "Validate a kb_upsert payload without mutating the KB. Use this read-only preflight before kb_upsert, especially for requirements, because it returns schema/modeling errors plus semantic advisor receipts that identify prose likely needing kb_model mode requirement or predicates, ambiguity review, or an ontology-gap observation.";
63
71
  }, {
64
72
  readonly name: "kb_upsert";
65
73
  readonly cliName: "upsert";
66
- readonly description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer kb_validate_upsert first because it returns semantic advisor receipts for prose-heavy requirements. Use kb_model_requirement before hand-writing strict property facts from prose, and kb_suggest_predicates before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request. Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates.";
74
+ readonly description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.";
67
75
  }, {
68
76
  readonly name: "kb_delete";
69
77
  readonly cliName: "delete";
@@ -87,7 +95,7 @@ export declare const CLI_OPERATION_METADATA: readonly [{
87
95
  }, {
88
96
  readonly name: "kb_apply_plan";
89
97
  readonly cliName: "apply-plan";
90
- readonly description: "Apply an explicitly approved kibi.bootstrap-plan.v1, kibi.compile-plan.v1, kibi.migration-plan.v2, or entity-deletion plan after revalidating its canonical hash and live snapshots. Bootstrap actions are dependency-ordered, sequential, source-first, and recoverable from a typed journal.";
98
+ readonly description: "Apply an explicitly approved kibi.bootstrap-plan.v1, kibi.compile-plan.v1, kibi.migration-plan.v2, or entity-deletion plan after revalidating its canonical hash and live snapshots. Compile plans apply all-or-nothing: a durable journal records every source write and store mutation before the first write, all steps commit in one store transaction, and an interrupted application is completed or rolled back by the next mutating call. Bootstrap actions are dependency-ordered, sequential, source-first, and recoverable from a typed journal.";
91
99
  }, {
92
100
  readonly name: "kb_ingest_proof";
93
101
  readonly cliName: "ingest-proof";
@@ -1 +1 @@
1
- {"version":3,"file":"cli-operation-metadata.d.ts","sourceRoot":"","sources":["../src/cli-operation-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAKF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqIiB,CAAC;AAMrD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,oBAAoB,GAAG,SAAS,EAC1C,IAAI,EAAE,aAAa,GAClB,oBAAoB,CAKtB;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,aAAa,GAClB,oBAAoB,CAEtB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,aAAa,CAEnE"}
1
+ {"version":3,"file":"cli-operation-metadata.d.ts","sourceRoot":"","sources":["../src/cli-operation-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAKF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiJiB,CAAC;AAMrD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,oBAAoB,GAAG,SAAS,EAC1C,IAAI,EAAE,aAAa,GAClB,oBAAoB,CAKtB;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,aAAa,GAClB,oBAAoB,CAEtB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,aAAa,CAEnE"}
@@ -17,6 +17,11 @@ export const CLI_OPERATION_METADATA = [
17
17
  cliName: "skills read",
18
18
  description: "Read a declared resource from a bundled Kibi agent skill. Resource paths are restricted to the skill manifest; arbitrary file paths are not exposed. Read-only; does not require Prolog.",
19
19
  },
20
+ {
21
+ name: "kb_skills",
22
+ cliName: "skill",
23
+ description: "Read bundled Kibi agent skills (workflow guidance). action:list returns the catalog; action:load returns a skill's metadata, Markdown body, declared resources and content hash (start with id 'kibi-usage'); action:read returns one manifest-declared resource. Read-only; does not require Prolog.",
24
+ },
20
25
  {
21
26
  name: "kb_query",
22
27
  cliName: "query",
@@ -25,7 +30,7 @@ export const CLI_OPERATION_METADATA = [
25
30
  {
26
31
  name: "kb_search",
27
32
  cliName: "search",
28
- description: "Search KB entities for discovery using legacy lexical ranking or deterministic intent-v1 ranking. Intent mode accepts host-agent semantic facets and source locations, returns evidence and abstains below its confidence threshold. Use for exploratory lookup before exact follow-up with kb_query. No mutation side effects.",
33
+ description: "Ask the KB a question or search it. Default intent-v1 ranking accepts questions, host-agent semantic facets and changed-code source locations, returns evidence, abstains below its confidence threshold and adds an answer layer: the current requirements that govern the topic, what must stay true (linked facts), why (ADRs) and what verifies it (scenarios, tests). Use before changing behavior, then kb_query for exact follow-up. No mutation side effects.",
29
34
  },
30
35
  {
31
36
  name: "kb_status",
@@ -62,6 +67,11 @@ export const CLI_OPERATION_METADATA = [
62
67
  cliName: "suggest-predicates",
63
68
  description: "Suggest ontology predicate schemas for prose requirements before agents write facts. Retrieval/ranking is followed by a semantic applicability gate and conservative binding review; complete-looking generic placeholders never trigger application. Read-only guidance returns additive candidate diagnostics, an applicable predicate-fact plan only for a semantically eligible candidate with reviewed bindings, or an explicit ontology-gap observation plus a deterministic review-only predicate schema draft when no schema fits.",
64
69
  },
70
+ {
71
+ name: "kb_model",
72
+ cliName: "model",
73
+ description: "Turn requirement prose into checkable structure without writing the KB. mode:analyze returns the semantic advisor receipt: the clause ledger, what is grounded, what is ambiguous and suggested modeling (pass clauses for compound prose and optional typed kibi.logic.v1 interpretations). mode:requirement converts one claim (subjectKey, propertyKey, operator, value, or typed logic) into a strict-lane write set and applyPlan. mode:predicates ranks ontology predicate schemas and returns an applicable predicate-fact plan only for reviewed bindings, otherwise an ontology-gap observation. Apply returned plans with kb_upsert.",
74
+ },
65
75
  {
66
76
  name: "kb_plan_bootstrap",
67
77
  cliName: "plan-bootstrap",
@@ -70,12 +80,12 @@ export const CLI_OPERATION_METADATA = [
70
80
  {
71
81
  name: "kb_validate_upsert",
72
82
  cliName: "validate-upsert",
73
- description: "Validate a kb_upsert payload without mutating the KB. Use this read-only preflight before kb_upsert, especially for requirements, because it returns schema/modeling errors plus semantic advisor receipts that identify prose likely needing kb_model_requirement, kb_suggest_predicates, ambiguity review, or an ontology-gap observation.",
83
+ description: "Validate a kb_upsert payload without mutating the KB. Use this read-only preflight before kb_upsert, especially for requirements, because it returns schema/modeling errors plus semantic advisor receipts that identify prose likely needing kb_model mode requirement or predicates, ambiguity review, or an ontology-gap observation.",
74
84
  },
75
85
  {
76
86
  name: "kb_upsert",
77
87
  cliName: "upsert",
78
- description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer kb_validate_upsert first because it returns semantic advisor receipts for prose-heavy requirements. Use kb_model_requirement before hand-writing strict property facts from prose, and kb_suggest_predicates before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request. Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates.",
88
+ description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.",
79
89
  },
80
90
  {
81
91
  name: "kb_delete",
@@ -105,7 +115,7 @@ export const CLI_OPERATION_METADATA = [
105
115
  {
106
116
  name: "kb_apply_plan",
107
117
  cliName: "apply-plan",
108
- description: "Apply an explicitly approved kibi.bootstrap-plan.v1, kibi.compile-plan.v1, kibi.migration-plan.v2, or entity-deletion plan after revalidating its canonical hash and live snapshots. Bootstrap actions are dependency-ordered, sequential, source-first, and recoverable from a typed journal.",
118
+ description: "Apply an explicitly approved kibi.bootstrap-plan.v1, kibi.compile-plan.v1, kibi.migration-plan.v2, or entity-deletion plan after revalidating its canonical hash and live snapshots. Compile plans apply all-or-nothing: a durable journal records every source write and store mutation before the first write, all steps commit in one store transaction, and an interrupted application is completed or rolled back by the next mutating call. Bootstrap actions are dependency-ordered, sequential, source-first, and recoverable from a typed journal.",
109
119
  },
110
120
  {
111
121
  name: "kb_ingest_proof",
@@ -1,5 +1,7 @@
1
+ import { InputError, OperationError } from "./cli-errors.js";
1
2
  import { type DiagnosticTelemetry } from "./cli-validate.js";
2
3
  import type { OperationContext } from "./public/operations/runtime-types.js";
4
+ import type { OperationEffect } from "./public/operations/types.js";
3
5
  export type CliContext = OperationContext & {
4
6
  readonly diagnosticTelemetry?: DiagnosticTelemetry;
5
7
  };
@@ -8,5 +10,17 @@ export type CliProtocolResult = {
8
10
  readonly stdout?: string;
9
11
  readonly stderr?: string;
10
12
  };
13
+ declare function errorResult(operation: string, error: InputError | OperationError, spec?: {
14
+ name: string;
15
+ effects: readonly OperationEffect[];
16
+ resultVersion?: string;
17
+ }, attempted?: boolean, details?: unknown): CliProtocolResult;
18
+ /**
19
+ * The error envelope for a route that never ran because its runtime could
20
+ * not open (no branch to attach, a detached HEAD refusing a write), so
21
+ * stdout still carries one JSON document.
22
+ */
23
+ export declare function openFailureResult(catalogName: string, spec: Parameters<typeof errorResult>[2], error: unknown): CliProtocolResult;
11
24
  export declare function executeOperation(catalogName: string, input: unknown, context: CliContext): Promise<CliProtocolResult>;
25
+ export {};
12
26
  //# sourceMappingURL=cli-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-protocol.d.ts","sourceRoot":"","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AAW,CAClB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,UAAU,GAAG,cAAc,EAClC,IAAI,CAAC,EAAE;IACL,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,EACD,SAAS,UAAO,EAChB,OAAO,CAAC,EAAE,OAAO,GAChB,iBAAiB,CAwBnB;AA4BD;;;;GAIG;AAEH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,EACvC,KAAK,EAAE,OAAO,GACb,iBAAiB,CAWnB;AAGD,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,iBAAiB,CAAC,CAwE5B"}
@@ -3,9 +3,11 @@ import { InputError, OperationError } from "./cli-errors.js";
3
3
  import { loadOperationSpec } from "./cli-operation-loader.js";
4
4
  import { isOperationName } from "./cli-operation-metadata.js";
5
5
  import { prepareOperationInput, } from "./cli-validate.js";
6
+ import { QUERY_LIMIT_EXCEEDED_CODE, queryLimitExceededOf, } from "./engine-limits.js";
6
7
  import { operationData, toKibiResult, } from "./public/operations/result-envelope.js";
8
+ import { detachedReadOnlyDiagnostic } from "./runtime/detached-snapshot.js";
7
9
  const outputValidator = new Ajv2020({ strict: false, allErrors: true });
8
- function errorResult(operation, error, spec, attempted = true) {
10
+ function errorResult(operation, error, spec, attempted = true, details) {
9
11
  const envelope = toKibiResult(spec ?? {
10
12
  name: operation,
11
13
  effects: [],
@@ -17,6 +19,7 @@ function errorResult(operation, error, spec, attempted = true) {
17
19
  code: error.code,
18
20
  message: error.detail,
19
21
  retryable: error.retryable,
22
+ ...(details !== undefined ? { details } : {}),
20
23
  },
21
24
  });
22
25
  return {
@@ -25,6 +28,17 @@ function errorResult(operation, error, spec, attempted = true) {
25
28
  stderr: `Error [${error.code}]: ${error.detail}\n`,
26
29
  };
27
30
  }
31
+ /**
32
+ * An answer from a detached HEAD's read-only snapshot says so in the
33
+ * envelope: which store was read and that writes are refused.
34
+ */
35
+ // implements REQ-branch-store-recovery-v4
36
+ function withDetachedReadOnlyNotice(envelope, context) {
37
+ const notice = detachedReadOnlyDiagnostic(context.branchAttachment);
38
+ return notice
39
+ ? { ...envelope, diagnostics: [...envelope.diagnostics, notice] }
40
+ : envelope;
41
+ }
28
42
  function protocolValid(spec, envelope) {
29
43
  if (!spec.outputSchema)
30
44
  return true;
@@ -35,6 +49,15 @@ function protocolValid(spec, envelope) {
35
49
  return false;
36
50
  }
37
51
  }
52
+ /**
53
+ * The error envelope for a route that never ran because its runtime could
54
+ * not open (no branch to attach, a detached HEAD refusing a write), so
55
+ * stdout still carries one JSON document.
56
+ */
57
+ // implements REQ-kibi-operation-interface-parity, REQ-branch-store-recovery-v4
58
+ export function openFailureResult(catalogName, spec, error) {
59
+ return errorResult(catalogName, new OperationError("OPERATION_FAILED", error instanceof Error ? error.message : String(error), false), spec, false);
60
+ }
38
61
  // implements REQ-kibi-operation-interface-parity
39
62
  export async function executeOperation(catalogName, input, context) {
40
63
  if (!isOperationName(catalogName)) {
@@ -51,7 +74,7 @@ export async function executeOperation(catalogName, input, context) {
51
74
  : context;
52
75
  const result = await spec.execute(prepared.businessInput, executionContext);
53
76
  const output = operationData(result);
54
- const envelope = toKibiResult(spec, output);
77
+ const envelope = withDetachedReadOnlyNotice(toKibiResult(spec, output), context);
55
78
  if (!protocolValid(spec, envelope)) {
56
79
  return errorResult(catalogName, new OperationError("PROTOCOL_VALIDATION_FAILED", "Operation produced a result that does not satisfy its generated output contract."), spec);
57
80
  }
@@ -61,6 +84,12 @@ export async function executeOperation(catalogName, input, context) {
61
84
  if (error instanceof InputError || error instanceof OperationError) {
62
85
  return errorResult(catalogName, error, spec);
63
86
  }
87
+ // A read stopped at its engine limit reports the limit, not a failure
88
+ // that could pass for a missing answer.
89
+ const limitExceeded = queryLimitExceededOf(error);
90
+ if (error instanceof Error && limitExceeded !== null) {
91
+ return errorResult(catalogName, new OperationError(QUERY_LIMIT_EXCEEDED_CODE, error.message, false), spec, true, { limitExceeded });
92
+ }
64
93
  if (error instanceof Error) {
65
94
  return errorResult(catalogName, new OperationError("OPERATION_FAILED", error.message), spec);
66
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cli-register-proof.d.ts","sourceRoot":"","sources":["../src/cli-register-proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6J3D"}
1
+ {"version":3,"file":"cli-register-proof.d.ts","sourceRoot":"","sources":["../src/cli-register-proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsL3D"}
@@ -85,6 +85,19 @@ export function registerProofCommand(program) {
85
85
  ...(options.keep === undefined ? {} : { keep: options.keep }),
86
86
  });
87
87
  }));
88
+ proof
89
+ .command("compact")
90
+ .description("Drop superseded proof receipts while keeping every receipt that decides current proof (newest per scope and contract for the live snapshot and current binding, plus the newest and newest passing receipt); coverage results are unchanged")
91
+ .option("--test <id>", "Compact a single test entity")
92
+ .option("--dry-run", "Report what would be removed without writing", false)
93
+ .option("--json", "Emit structured JSON", false)
94
+ .action(withExitCode(async (options) => {
95
+ return await (await import("./commands/proof-compact.js")).proofCompactCommand({
96
+ ...(options.test === undefined ? {} : { test: options.test }),
97
+ dryRun: options.dryRun === true,
98
+ json: options.json === true,
99
+ });
100
+ }));
88
101
  proof
89
102
  .command("migrate-legacy")
90
103
  .description("Remove legacy verification_receipts blocks from test documents that already carry a proof_contract")
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.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MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CA+BtB"}
@@ -25,6 +25,7 @@ import { PrologProcess } from "../prolog.js";
25
25
  import { escapeAtom, normalizeEntityId, parseTriples, parseViolationRows, } from "../prolog/codec.js";
26
26
  import { createSemanticReviewDiagnostics, createSymbolGranularityDiagnostics, createSymbolQualityDiagnostics, hasBlockingImpactDiagnostics, } from "../public/impact-diagnostics.js";
27
27
  import { executeCheck } from "../public/operations/check-executor.js";
28
+ import { refreshDetachedSnapshot } from "../runtime/detached-snapshot.js";
28
29
  import { KIBI_NO_IMPACT_DECLARATION, KIBI_SYMBOLS_MANIFEST_PATH, KIBI_SYMBOL_COORDINATES_PATH, } from "../traceability/evidence-model.js";
29
30
  import { captureStagedSnapshot } from "../traceability/git-change-snapshot.js";
30
31
  import { supportedStagedFiles, } from "../traceability/git-staged.js";
@@ -40,7 +41,7 @@ import { assessStagedSymbolsManifest, collectStagedAuthoredSymbolsManifestEviden
40
41
  import { createManifestLookupSentinelKey, extractSymbolsFromStagedFileAsync, } from "../traceability/symbol-extract.js";
41
42
  import { cleanupTempKb, consultOverlay, createOverlayFacts, createTempKb, projectStagedEntities, } from "../traceability/temp-kb.js";
42
43
  import { formatViolations as formatStagedViolations, validateStagedSymbols, } from "../traceability/validate.js";
43
- import { resolveBranchAttachment } from "../utils/branch-resolver.js";
44
+ import { resolveReadBranchAttachment } from "../utils/branch-resolver.js";
44
45
  import { CANONICAL_ENTITY_PATHS, isEntityLanePath } from "../utils/kb-paths.js";
45
46
  import { safeCleanupProlog } from "../utils/prolog-cleanup.js";
46
47
  function getMatchGroup(match, index = 1) {
@@ -438,10 +439,15 @@ export async function checkCommand(options) {
438
439
  resolvedKbPath = options.kbPath;
439
440
  }
440
441
  else {
441
- const attachment = resolveBranchAttachment(process.cwd());
442
+ const attachment = resolveReadBranchAttachment(process.cwd());
442
443
  if ("error" in attachment)
443
444
  throw new Error(attachment.error);
444
445
  resolvedBranch = attachment.kbBranch;
446
+ if (attachment.readOnly !== undefined) {
447
+ // Check reads only: a detached HEAD checks its read-only snapshot.
448
+ console.warn(`[KIBI] ${attachment.readOnly.notice}`);
449
+ await refreshDetachedSnapshot(process.cwd(), attachment);
450
+ }
445
451
  if (attachment.migrationRequired) {
446
452
  console.warn(`Warning: reading legacy KB attachment ${attachment.gitBranch} -> ${attachment.kbBranch}; migrate before writes or sync.`);
447
453
  }
@@ -983,6 +989,7 @@ export async function getAllEntityIds(prolog, type) {
983
989
  }
984
990
  return content.split(",").map((id) => id.trim().replace(/^'|'$/g, ""));
985
991
  }
992
+ // implements REQ-cli-check
986
993
  export async function checkNoDanglingRefs(prolog) {
987
994
  const violations = [];
988
995
  const allEntityIds = new Set(await getAllEntityIds(prolog));
@@ -995,6 +1002,8 @@ export async function checkNoDanglingRefs(prolog) {
995
1002
  "requires_property",
996
1003
  "supersedes",
997
1004
  "restates",
1005
+ "assumes",
1006
+ "exempts",
998
1007
  "relates_to",
999
1008
  ];
1000
1009
  const allRels = [];
@@ -1 +1 @@
1
- {"version":3,"file":"discovery-shared.d.ts","sourceRoot":"","sources":["../../src/commands/discovery-shared.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAMnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B;AAED,qDAAq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AE,MAAM,GAAG,OAAO,GAAG,SAAS,EACpC,UAAU,EAAE,OAAO,EACnB,YAAY,EAAE,MAAM,GACnB,IAAI,CAQN"}
@@ -4,7 +4,8 @@ import { PrologProcess, resolveKbPlPath } from "../prolog.js";
4
4
  import { escapeAtom } from "../prolog/codec.js";
5
5
  import { executeOperation, } from "../public/operations/runtime-types.js";
6
6
  import { createCliRuntime } from "../runtime/cli-runtime.js";
7
- import { resolveBranchAttachment } from "../utils/branch-resolver.js";
7
+ import { refreshDetachedSnapshot } from "../runtime/detached-snapshot.js";
8
+ import { resolveBranchAttachment, resolveReadBranchAttachment, } from "../utils/branch-resolver.js";
8
9
  import { safeCleanupProlog } from "../utils/prolog-cleanup.js";
9
10
  import { renderDiscoveryTable } from "./discovery-table.js";
10
11
  export { renderCoverageTable } from "./discovery-table.js";
@@ -21,10 +22,15 @@ export async function withAttachedBranchProlog(callback, deps) {
21
22
  let attached = false;
22
23
  let branchName;
23
24
  try {
24
- const attachment = resolveBranchAttachment(process.cwd());
25
+ // Callers only read: a detached HEAD reads its read-only snapshot.
26
+ const attachment = resolveReadBranchAttachment(process.cwd());
25
27
  if ("error" in attachment)
26
28
  throw new Error(attachment.error);
27
29
  branchName = attachment.kbBranch;
30
+ if (attachment.readOnly !== undefined) {
31
+ console.warn(`[KIBI] ${attachment.readOnly.notice}`);
32
+ await refreshDetachedSnapshot(process.cwd(), attachment);
33
+ }
28
34
  if (usesEngine) {
29
35
  engine = new EngineClient({
30
36
  workspaceRoot: process.cwd(),
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/commands/engine.ts"],"names":[],"mappings":"AAkCA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BzD;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWvD;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AAEH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA2Cf;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB3D;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhB"}
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/commands/engine.ts"],"names":[],"mappings":"AAuCA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BzD;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWvD;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AAEH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA2Cf;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB3D;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhB"}
@@ -1,8 +1,10 @@
1
1
  import path from "node:path";
2
2
  import { EngineClient } from "../engine.js";
3
- import { resolveBranchAttachment } from "../utils/branch-resolver.js";
3
+ import { resolveBranchAttachment, resolveReadBranchAttachment, } from "../utils/branch-resolver.js";
4
+ // Engine maintenance never writes the KB, so a detached HEAD addresses the
5
+ // daemon serving its read-only snapshot.
4
6
  function currentBranch(root) {
5
- const resolved = resolveBranchAttachment(root);
7
+ const resolved = resolveReadBranchAttachment(root);
6
8
  if ("error" in resolved) {
7
9
  throw new Error(resolved.error);
8
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gc.d.ts","sourceRoot":"","sources":["../../src/commands/gc.ts"],"names":[],"mappings":"AAWA,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA0GF,wBAAsB,SAAS,CAAC,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAgFtE;AAED,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"gc.d.ts","sourceRoot":"","sources":["../../src/commands/gc.ts"],"names":[],"mappings":"AAeA,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA0GF,wBAAsB,SAAS,CAAC,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAsFtE;AAED,eAAe,SAAS,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
+ import { DETACHED_SNAPSHOT_KB_BRANCH, resolveReadBranchAttachment, } from "../utils/branch-resolver.js";
4
5
  import { branchStoreKey, branchStoresRoot, readBranchStoreManifest, } from "../utils/branch-store-locator.js";
5
6
  const DEFAULT_RETENTION_DAYS = 30;
6
7
  function localBranches(workspaceRoot) {
@@ -101,6 +102,12 @@ export async function gcCommand(options = {}) {
101
102
  return;
102
103
  }
103
104
  const live = localBranches(workspaceRoot);
105
+ // The detached-HEAD snapshot is a regenerable read cache: live while this
106
+ // checkout is detached on it, stale (collectable) once a branch is out.
107
+ const readAttachment = resolveReadBranchAttachment(workspaceRoot);
108
+ if (!("error" in readAttachment) && readAttachment.readOnly !== undefined) {
109
+ live.add(DETACHED_SNAPSHOT_KB_BRANCH);
110
+ }
104
111
  const candidates = [];
105
112
  const visit = (dir, relativeBranch) => {
106
113
  const entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -1 +1 @@
1
- {"version":3,"file":"init-helpers.d.ts","sourceRoot":"","sources":["../../src/commands/init-helpers.ts"],"names":[],"mappings":"AAyIA,wBAAsB,gBAAgB,CACpC,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACpB,IAAI,CAUN;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA6BjD;AAkDD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAU3D;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAYf;AASD,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,iBAAiB,GACjB,qBAAqB,CAAC;AAoB1B,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,iBAAiB,CAyEnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,YAAY,GAAG,eAAe,GA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EAAE,iBAAiB,CAAC;CAC3B;AAiBD;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAU/D;AAED,wEAAwE;AAExE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQzD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GAChD,oBAAoB,EAAE,CA8CxB"}
@@ -15,11 +15,11 @@
15
15
  You should have received a copy of the GNU Affero General Public License
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
- import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
18
+ import { chmodSync, constants, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
19
19
  import * as path from "node:path";
20
20
  import fg from "fast-glob";
21
21
  import { getBranchDiagnostic, resolveActiveBranch, } from "../utils/branch-resolver.js";
22
- import { ensureBranchStoreManifest } from "../utils/branch-store-locator.js";
22
+ import { branchStorePath, ensureBranchStoreManifest, } from "../utils/branch-store-locator.js";
23
23
  import { defaultKbManifest, writeKbManifest } from "../utils/kb-manifest.js";
24
24
  import { ENTITY_LANES, KB_PATHS } from "../utils/kb-paths.js";
25
25
  import { SYMBOLS_MANIFEST_COMMENT_BLOCK } from "./sync/manifest.js";
@@ -125,15 +125,31 @@ export async function getCurrentBranch(cwd = process.cwd()) {
125
125
  return result.branch;
126
126
  }
127
127
  export function createKbDirectoryStructure(kbDir, currentBranch) {
128
- mkdirSync(kbDir, { recursive: true });
129
- mkdirSync(path.join(kbDir, "schema"), { recursive: true });
130
- // Canonical tracked knowledge lanes under .kb/.
131
- for (const lane of ENTITY_LANES) {
132
- mkdirSync(path.join(kbDir, lane), { recursive: true });
128
+ // Preflight all directories before writing; never follow a substituted lane
129
+ // into another location while completing a partial installation.
130
+ const directories = [
131
+ kbDir,
132
+ path.join(kbDir, "schema"),
133
+ ...ENTITY_LANES.map((lane) => path.join(kbDir, lane)),
134
+ path.join(kbDir, "branches"),
135
+ branchStorePath(path.dirname(kbDir), currentBranch),
136
+ ];
137
+ for (const directory of directories) {
138
+ try {
139
+ if (!lstatSync(directory).isDirectory()) {
140
+ throw new Error(`Refusing to initialize non-directory or symlink: ${directory}`);
141
+ }
142
+ }
143
+ catch (error) {
144
+ if (error.code !== "ENOENT")
145
+ throw error;
146
+ }
133
147
  }
148
+ for (const directory of directories)
149
+ mkdirSync(directory, { recursive: true });
134
150
  ensureBranchStoreManifest(path.dirname(kbDir), currentBranch);
135
- console.log("✓ Created .kb/ directory structure");
136
- console.log(`✓ Created hashed branch store for ${currentBranch}`);
151
+ console.log("✓ Ensured .kb/ directory structure");
152
+ console.log(`✓ Verified hashed branch store for ${currentBranch}`);
137
153
  }
138
154
  export function createManifestFile(kbDir) {
139
155
  writeKbManifest(path.dirname(kbDir), defaultKbManifest());
@@ -227,9 +243,20 @@ export async function copySchemaFiles(kbDir, schemaSourceDir) {
227
243
  for (const file of schemaFiles) {
228
244
  const sourcePath = path.join(schemaSourceDir, file);
229
245
  const destPath = path.join(kbDir, "schema", file);
230
- copyFileSync(sourcePath, destPath);
246
+ // Init completes missing schema files; existing files belong to the current
247
+ // installation and must not be overwritten by a repeated initialization.
248
+ try {
249
+ copyFileSync(sourcePath, destPath, constants.COPYFILE_EXCL);
250
+ }
251
+ catch (error) {
252
+ if (error.code !== "EEXIST")
253
+ throw error;
254
+ if (!lstatSync(destPath).isFile()) {
255
+ throw new Error(`Refusing non-file or symlink schema destination: ${destPath}`);
256
+ }
257
+ }
231
258
  }
232
- console.log(`✓ Copied ${schemaFiles.length} schema files`);
259
+ console.log(`✓ Ensured ${schemaFiles.length} schema files`);
233
260
  }
234
261
  const KIBI_HOOK_BEGIN = "# BEGIN kibi-managed";
235
262
  const KIBI_HOOK_END = "# END kibi-managed";
@@ -254,7 +281,6 @@ function hookIntegrationRecipe(hook) {
254
281
  }
255
282
  }
256
283
  export function installHook(hookPath, content) {
257
- // implements REQ-008
258
284
  // implements REQ-git-hook-effective-install
259
285
  const kibiSection = `${KIBI_HOOK_BEGIN}\n${content}\n${KIBI_HOOK_END}`;
260
286
  let hookStats;