kibi-cli 1.0.1 → 2.0.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 (450) hide show
  1. package/dist/cli-errors.d.ts +3 -1
  2. package/dist/cli-errors.d.ts.map +1 -1
  3. package/dist/cli-errors.js +4 -1
  4. package/dist/cli-json-command.d.ts +1 -0
  5. package/dist/cli-json-command.d.ts.map +1 -1
  6. package/dist/cli-json-command.js +13 -4
  7. package/dist/cli-operation-loader.js +3 -3
  8. package/dist/cli-operation-metadata.d.ts +4 -3
  9. package/dist/cli-operation-metadata.d.ts.map +1 -1
  10. package/dist/cli-operation-metadata.js +7 -5
  11. package/dist/cli-protocol.js +1 -1
  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 +3 -0
  15. package/dist/cli-register-proof.d.ts.map +1 -0
  16. package/dist/cli-register-proof.js +103 -0
  17. package/dist/cli-register-reporting.d.ts.map +1 -1
  18. package/dist/cli-register-reporting.js +1 -0
  19. package/dist/cli.d.ts +4 -0
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +17 -10
  22. package/dist/commands/branch.d.ts +1 -0
  23. package/dist/commands/branch.d.ts.map +1 -1
  24. package/dist/commands/branch.js +8 -4
  25. package/dist/commands/check.d.ts +14 -0
  26. package/dist/commands/check.d.ts.map +1 -1
  27. package/dist/commands/check.js +190 -44
  28. package/dist/commands/coverage.d.ts +1 -0
  29. package/dist/commands/coverage.d.ts.map +1 -1
  30. package/dist/commands/coverage.js +6 -0
  31. package/dist/commands/doctor.d.ts +22 -0
  32. package/dist/commands/doctor.d.ts.map +1 -1
  33. package/dist/commands/doctor.js +48 -22
  34. package/dist/commands/engine.d.ts +12 -0
  35. package/dist/commands/engine.d.ts.map +1 -1
  36. package/dist/commands/engine.js +40 -0
  37. package/dist/commands/github-init.d.ts +1 -0
  38. package/dist/commands/github-init.d.ts.map +1 -1
  39. package/dist/commands/github-init.js +9 -5
  40. package/dist/commands/init-helpers.d.ts.map +1 -1
  41. package/dist/commands/init-helpers.js +38 -5
  42. package/dist/commands/migrate.d.ts +4 -0
  43. package/dist/commands/migrate.d.ts.map +1 -1
  44. package/dist/commands/migrate.js +7 -7
  45. package/dist/commands/proof-migrate-legacy.d.ts +7 -0
  46. package/dist/commands/proof-migrate-legacy.d.ts.map +1 -0
  47. package/dist/commands/proof-migrate-legacy.js +45 -0
  48. package/dist/commands/proof-prune.d.ts +8 -0
  49. package/dist/commands/proof-prune.d.ts.map +1 -0
  50. package/dist/commands/proof-prune.js +53 -0
  51. package/dist/commands/prove.d.ts +37 -0
  52. package/dist/commands/prove.d.ts.map +1 -0
  53. package/dist/commands/prove.js +470 -0
  54. package/dist/commands/report.js +1 -1
  55. package/dist/commands/sync/discovery.d.ts +3 -0
  56. package/dist/commands/sync/discovery.d.ts.map +1 -1
  57. package/dist/commands/sync/discovery.js +36 -28
  58. package/dist/commands/sync/manifest.d.ts +1 -1
  59. package/dist/commands/sync/manifest.d.ts.map +1 -1
  60. package/dist/commands/sync/manifest.js +53 -21
  61. package/dist/commands/sync/persistence.d.ts +4 -1
  62. package/dist/commands/sync/persistence.d.ts.map +1 -1
  63. package/dist/commands/sync/persistence.js +25 -14
  64. package/dist/commands/sync/staging.d.ts +1 -0
  65. package/dist/commands/sync/staging.d.ts.map +1 -1
  66. package/dist/commands/sync/staging.js +5 -2
  67. package/dist/commands/sync/untracked-targets.d.ts +24 -0
  68. package/dist/commands/sync/untracked-targets.d.ts.map +1 -0
  69. package/dist/commands/sync/untracked-targets.js +108 -0
  70. package/dist/commands/sync.d.ts +11 -1
  71. package/dist/commands/sync.d.ts.map +1 -1
  72. package/dist/commands/sync.js +74 -30
  73. package/dist/engine-daemon.d.ts +3 -1
  74. package/dist/engine-daemon.d.ts.map +1 -1
  75. package/dist/engine-daemon.js +49 -20
  76. package/dist/engine.d.ts +14 -76
  77. package/dist/engine.d.ts.map +1 -1
  78. package/dist/engine.js +197 -30
  79. package/dist/extractors/manifest.d.ts +5 -0
  80. package/dist/extractors/manifest.d.ts.map +1 -1
  81. package/dist/extractors/manifest.js +46 -1
  82. package/dist/extractors/markdown.d.ts +5 -3
  83. package/dist/extractors/markdown.d.ts.map +1 -1
  84. package/dist/extractors/markdown.js +41 -24
  85. package/dist/extractors/playwright-cases.js +1 -1
  86. package/dist/extractors/relationships.d.ts +6 -0
  87. package/dist/extractors/relationships.d.ts.map +1 -1
  88. package/dist/extractors/relationships.js +1 -1
  89. package/dist/extractors/symbol-coordinates.d.ts.map +1 -1
  90. package/dist/extractors/symbols-ts.d.ts +1 -0
  91. package/dist/extractors/symbols-ts.d.ts.map +1 -1
  92. package/dist/extractors/symbols-ts.js +142 -67
  93. package/dist/intent-search.d.ts +1 -0
  94. package/dist/intent-search.d.ts.map +1 -1
  95. package/dist/intent-search.js +7 -3
  96. package/dist/logic/ir.d.ts +1 -0
  97. package/dist/logic/ir.d.ts.map +1 -1
  98. package/dist/logic/ir.js +1 -1
  99. package/dist/operations/bootstrap/activation.d.ts +2 -1
  100. package/dist/operations/bootstrap/activation.d.ts.map +1 -1
  101. package/dist/operations/bootstrap/activation.js +11 -3
  102. package/dist/operations/bootstrap/generate.d.ts +2 -1
  103. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  104. package/dist/operations/bootstrap/generate.js +6 -3
  105. package/dist/operations/bootstrap/guidance.d.ts +1 -0
  106. package/dist/operations/bootstrap/guidance.d.ts.map +1 -1
  107. package/dist/operations/bootstrap/guidance.js +1 -1
  108. package/dist/operations/modeling/model-requirement.d.ts +5 -0
  109. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  110. package/dist/operations/modeling/model-requirement.js +53 -46
  111. package/dist/operations/modeling/predicate-applicability.d.ts.map +1 -1
  112. package/dist/operations/modeling/predicate-applicability.js +103 -4
  113. package/dist/operations/modeling/predicate-catalog-2.d.ts.map +1 -1
  114. package/dist/operations/modeling/predicate-catalog-2.js +18 -2
  115. package/dist/operations/modeling/predicate-catalog-3.d.ts.map +1 -1
  116. package/dist/operations/modeling/predicate-catalog-3.js +17 -1
  117. package/dist/operations/modeling/predicate-catalog-5.d.ts +10 -0
  118. package/dist/operations/modeling/predicate-catalog-5.d.ts.map +1 -0
  119. package/dist/operations/modeling/predicate-catalog-5.js +291 -0
  120. package/dist/operations/modeling/predicate-catalog.d.ts.map +1 -1
  121. package/dist/operations/modeling/predicate-catalog.js +4 -0
  122. package/dist/operations/modeling/predicate-loader.d.ts +1 -0
  123. package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
  124. package/dist/operations/modeling/predicate-loader.js +4 -3
  125. package/dist/operations/modeling/predicate-ranker.d.ts.map +1 -1
  126. package/dist/operations/modeling/predicate-ranker.js +4 -1
  127. package/dist/operations/modeling/predicate-types.d.ts +1 -1
  128. package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
  129. package/dist/operations/modeling/predicate-usage-hints-4.d.ts +3 -0
  130. package/dist/operations/modeling/predicate-usage-hints-4.d.ts.map +1 -0
  131. package/dist/operations/modeling/predicate-usage-hints-4.js +84 -0
  132. package/dist/operations/modeling/suggest-predicates.d.ts +3 -1
  133. package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
  134. package/dist/operations/modeling/suggest-predicates.js +52 -19
  135. package/dist/operations/mutation/contradictions.d.ts +2 -1
  136. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  137. package/dist/operations/mutation/contradictions.js +26 -5
  138. package/dist/operations/mutation/delete.d.ts +3 -0
  139. package/dist/operations/mutation/delete.d.ts.map +1 -1
  140. package/dist/operations/mutation/delete.js +100 -32
  141. package/dist/operations/mutation/relationships.d.ts +1 -0
  142. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  143. package/dist/operations/mutation/relationships.js +6 -4
  144. package/dist/operations/mutation/saga.d.ts +51 -0
  145. package/dist/operations/mutation/saga.d.ts.map +1 -0
  146. package/dist/operations/mutation/saga.js +67 -0
  147. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  148. package/dist/operations/mutation/serialization.js +3 -2
  149. package/dist/operations/mutation/source-authoring.d.ts +5 -1
  150. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  151. package/dist/operations/mutation/source-authoring.js +79 -46
  152. package/dist/operations/mutation/strict-fact.d.ts +1 -0
  153. package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
  154. package/dist/operations/mutation/strict-fact.js +8 -5
  155. package/dist/operations/mutation/symbol-compiler-lock.d.ts +5 -2
  156. package/dist/operations/mutation/symbol-compiler-lock.d.ts.map +1 -1
  157. package/dist/operations/mutation/symbol-compiler-lock.js +65 -2
  158. package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -1
  159. package/dist/operations/mutation/symbol-granularity.js +2 -2
  160. package/dist/operations/mutation/symbol-refresh.d.ts +1 -0
  161. package/dist/operations/mutation/symbol-refresh.d.ts.map +1 -1
  162. package/dist/operations/mutation/symbol-refresh.js +10 -8
  163. package/dist/operations/mutation/upsert.d.ts +18 -2
  164. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  165. package/dist/operations/mutation/upsert.js +86 -54
  166. package/dist/operations/mutation/validate-upsert.js +2 -2
  167. package/dist/operations/mutation/validation.d.ts.map +1 -1
  168. package/dist/operations/mutation/validation.js +46 -4
  169. package/dist/operations/mutation/warnings.d.ts +1 -0
  170. package/dist/operations/mutation/warnings.d.ts.map +1 -1
  171. package/dist/operations/mutation/warnings.js +7 -5
  172. package/dist/operations/mutation/workspace-mutation-lock.d.ts +60 -0
  173. package/dist/operations/mutation/workspace-mutation-lock.d.ts.map +1 -0
  174. package/dist/operations/mutation/workspace-mutation-lock.js +362 -0
  175. package/dist/operations/planning/apply-plan.d.ts +8 -106
  176. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  177. package/dist/operations/planning/apply-plan.js +113 -36
  178. package/dist/operations/planning/compile-intent.d.ts +2 -0
  179. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  180. package/dist/operations/planning/compile-intent.js +70 -14
  181. package/dist/operations/proof/ingest-proof.d.ts +34 -0
  182. package/dist/operations/proof/ingest-proof.d.ts.map +1 -0
  183. package/dist/operations/proof/ingest-proof.js +307 -0
  184. package/dist/operations/proof/migrate-legacy-receipts.d.ts +30 -0
  185. package/dist/operations/proof/migrate-legacy-receipts.d.ts.map +1 -0
  186. package/dist/operations/proof/migrate-legacy-receipts.js +88 -0
  187. package/dist/operations/proof/prune-receipts.d.ts +35 -0
  188. package/dist/operations/proof/prune-receipts.d.ts.map +1 -0
  189. package/dist/operations/proof/prune-receipts.js +91 -0
  190. package/dist/operations/proof/receipt-document.d.ts +29 -0
  191. package/dist/operations/proof/receipt-document.d.ts.map +1 -0
  192. package/dist/operations/proof/receipt-document.js +117 -0
  193. package/dist/operations/semantic-advisor/analyze-prose.d.ts +1 -0
  194. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  195. package/dist/operations/semantic-advisor/analyze-prose.js +46 -26
  196. package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
  197. package/dist/operations/semantic-advisor/clauses.js +20 -7
  198. package/dist/operations/semantic-advisor/strict-count-rules.d.ts +2 -0
  199. package/dist/operations/semantic-advisor/strict-count-rules.d.ts.map +1 -1
  200. package/dist/operations/semantic-advisor/strict-count-rules.js +40 -25
  201. package/dist/prolog/codec.d.ts +13 -1
  202. package/dist/prolog/codec.d.ts.map +1 -1
  203. package/dist/prolog/codec.js +269 -154
  204. package/dist/prolog/error-terms.d.ts +47 -0
  205. package/dist/prolog/error-terms.d.ts.map +1 -0
  206. package/dist/prolog/error-terms.js +334 -0
  207. package/dist/prolog/janitor.d.ts +50 -0
  208. package/dist/prolog/janitor.d.ts.map +1 -0
  209. package/dist/prolog/janitor.js +154 -0
  210. package/dist/prolog/store-lock.d.ts +45 -0
  211. package/dist/prolog/store-lock.d.ts.map +1 -0
  212. package/dist/prolog/store-lock.js +195 -0
  213. package/dist/prolog.d.ts +7 -0
  214. package/dist/prolog.d.ts.map +1 -1
  215. package/dist/prolog.js +55 -17
  216. package/dist/proof/evaluate.d.ts +27 -0
  217. package/dist/proof/evaluate.d.ts.map +1 -0
  218. package/dist/proof/evaluate.js +151 -0
  219. package/dist/proof/inspect.d.ts +12 -0
  220. package/dist/proof/inspect.d.ts.map +1 -0
  221. package/dist/proof/inspect.js +236 -0
  222. package/dist/proof/integrations.d.ts +35 -0
  223. package/dist/proof/integrations.d.ts.map +1 -0
  224. package/dist/proof/integrations.js +123 -0
  225. package/dist/proof/producers/junit-adapter.d.ts +26 -0
  226. package/dist/proof/producers/junit-adapter.d.ts.map +1 -0
  227. package/dist/proof/producers/junit-adapter.js +186 -0
  228. package/dist/{public → proof/producers}/playwright-case-id.d.ts +1 -1
  229. package/dist/proof/producers/playwright-case-id.d.ts.map +1 -0
  230. package/dist/{public → proof/producers}/playwright-case-id.js +3 -3
  231. package/dist/proof/producers/playwright-reporter.d.ts +27 -0
  232. package/dist/proof/producers/playwright-reporter.d.ts.map +1 -0
  233. package/dist/proof/producers/playwright-reporter.js +138 -0
  234. package/dist/proof/producers/tap-adapter.d.ts +10 -0
  235. package/dist/proof/producers/tap-adapter.d.ts.map +1 -0
  236. package/dist/proof/producers/tap-adapter.js +200 -0
  237. package/dist/proof/receipt-outcome.d.ts +2 -0
  238. package/dist/proof/receipt-outcome.d.ts.map +1 -0
  239. package/dist/proof/receipt-outcome.js +1 -0
  240. package/dist/public/diagnostic-usage.js +6 -6
  241. package/dist/public/distribution-parity.d.ts +7 -1
  242. package/dist/public/distribution-parity.d.ts.map +1 -1
  243. package/dist/public/distribution-parity.js +15 -10
  244. package/dist/public/impact/coverage-depth-quality.d.ts +1 -0
  245. package/dist/public/impact/coverage-depth-quality.d.ts.map +1 -1
  246. package/dist/public/impact/coverage-depth-quality.js +1 -1
  247. package/dist/public/impact/diagnostics.d.ts.map +1 -1
  248. package/dist/public/impact/diagnostics.js +2 -2
  249. package/dist/public/impact/diff-meaning.d.ts +1 -0
  250. package/dist/public/impact/diff-meaning.d.ts.map +1 -1
  251. package/dist/public/impact/diff-meaning.js +5 -2
  252. package/dist/public/impact/full-kb-quality.d.ts +5 -2
  253. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  254. package/dist/public/impact/full-kb-quality.js +329 -64
  255. package/dist/public/operations/catalog.d.ts +447 -196
  256. package/dist/public/operations/catalog.d.ts.map +1 -1
  257. package/dist/public/operations/catalog.js +6 -4
  258. package/dist/public/operations/check-executor.d.ts.map +1 -1
  259. package/dist/public/operations/check-executor.js +3 -7
  260. package/dist/public/operations/contracts.d.ts +7 -0
  261. package/dist/public/operations/contracts.d.ts.map +1 -1
  262. package/dist/public/operations/contracts.js +31 -22
  263. package/dist/public/operations/discovery-entities.d.ts +3 -0
  264. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  265. package/dist/public/operations/discovery-entities.js +4 -0
  266. package/dist/public/operations/discovery-executors.d.ts +9 -9
  267. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  268. package/dist/public/operations/discovery-executors.js +17 -14
  269. package/dist/public/operations/index.d.ts +1 -1
  270. package/dist/public/operations/index.d.ts.map +1 -1
  271. package/dist/public/operations/index.js +1 -1
  272. package/dist/public/operations/migration-plan.d.ts +4 -3
  273. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  274. package/dist/public/operations/migration-plan.js +23 -21
  275. package/dist/public/operations/node-ports.js +6 -6
  276. package/dist/public/operations/repair-plan.d.ts +3 -3
  277. package/dist/public/operations/repair-plan.d.ts.map +1 -1
  278. package/dist/public/operations/repair-plan.js +49 -19
  279. package/dist/public/operations/result-envelope.d.ts +1 -0
  280. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  281. package/dist/public/operations/result-envelope.js +12 -10
  282. package/dist/public/operations/runtime-types.d.ts +5 -0
  283. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  284. package/dist/public/operations/specs/check-rules.generated.d.ts +5 -0
  285. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -0
  286. package/dist/public/operations/specs/check-rules.generated.js +34 -0
  287. package/dist/public/operations/specs/check.d.ts +7 -2
  288. package/dist/public/operations/specs/check.d.ts.map +1 -1
  289. package/dist/public/operations/specs/check.js +8 -20
  290. package/dist/public/operations/specs/mutation-schemas.d.ts +257 -163
  291. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  292. package/dist/public/operations/specs/mutation-schemas.js +15 -7
  293. package/dist/public/operations/specs/planning.d.ts +9 -0
  294. package/dist/public/operations/specs/planning.d.ts.map +1 -1
  295. package/dist/public/operations/specs/planning.js +6 -0
  296. package/dist/public/operations/specs/proof.d.ts +212 -0
  297. package/dist/public/operations/specs/proof.d.ts.map +1 -0
  298. package/dist/public/operations/specs/proof.js +30 -0
  299. package/dist/public/operations/specs/reporting.d.ts +19 -0
  300. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  301. package/dist/public/operations/specs/reporting.js +112 -12
  302. package/dist/public/operations/specs/upsert.d.ts +257 -163
  303. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  304. package/dist/public/operations/symbol-repair-plan.d.ts +11 -0
  305. package/dist/public/operations/symbol-repair-plan.d.ts.map +1 -1
  306. package/dist/public/operations/symbol-repair-plan.js +118 -3
  307. package/dist/public/operations/types.d.ts +1 -1
  308. package/dist/public/operations/types.d.ts.map +1 -1
  309. package/dist/public/proof-fingerprint.d.ts +54 -0
  310. package/dist/public/proof-fingerprint.d.ts.map +1 -0
  311. package/dist/public/proof-fingerprint.js +141 -0
  312. package/dist/public/proof-protocol.d.ts +354 -0
  313. package/dist/public/proof-protocol.d.ts.map +1 -0
  314. package/dist/public/proof-protocol.js +454 -0
  315. package/dist/public/proof-receipt.d.ts +279 -0
  316. package/dist/public/proof-receipt.d.ts.map +1 -0
  317. package/dist/public/proof-receipt.js +377 -0
  318. package/dist/public/schemas/entity.d.ts.map +1 -1
  319. package/dist/public/schemas/entity.js +21 -7
  320. package/dist/public/skills/kibi-freshness/SKILL.md +1 -1
  321. package/dist/public/skills/kibi-usage/SKILL.md +41 -12
  322. package/dist/public/skills/kibi-usage/resources/operation-access.md +1 -1
  323. package/dist/public/skills/kibi-usage/resources/proof.md +105 -0
  324. package/dist/public/skills/kibi-usage/resources/workflows.md +6 -6
  325. package/dist/public/symbol-granularity.d.ts +3 -14
  326. package/dist/public/symbol-granularity.d.ts.map +1 -1
  327. package/dist/public/symbol-granularity.generated.d.ts +16 -0
  328. package/dist/public/symbol-granularity.generated.d.ts.map +1 -0
  329. package/dist/public/symbol-granularity.generated.js +20 -0
  330. package/dist/public/symbol-granularity.js +6 -47
  331. package/dist/public/telemetry-acceptance.d.ts +3 -77
  332. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  333. package/dist/public/telemetry-acceptance.js +4 -2
  334. package/dist/public/telemetry-remediation.js +1 -1
  335. package/dist/report/html-report.css +282 -0
  336. package/dist/report/html-report.d.ts +4 -2
  337. package/dist/report/html-report.d.ts.map +1 -1
  338. package/dist/report/html-report.js +37 -300
  339. package/dist/runtime/cli-runtime.d.ts +2 -0
  340. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  341. package/dist/runtime/cli-runtime.js +14 -7
  342. package/dist/schemas/entity.schema.json +355 -215
  343. package/dist/search-ranking.d.ts +1 -0
  344. package/dist/search-ranking.d.ts.map +1 -1
  345. package/dist/search-ranking.js +3 -0
  346. package/dist/traceability/evidence-model.d.ts +28 -0
  347. package/dist/traceability/evidence-model.d.ts.map +1 -1
  348. package/dist/traceability/git-staged.d.ts +20 -0
  349. package/dist/traceability/git-staged.d.ts.map +1 -1
  350. package/dist/traceability/git-staged.js +145 -1
  351. package/dist/traceability/staged-diagnostics.d.ts +7 -0
  352. package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
  353. package/dist/traceability/staged-diagnostics.js +78 -7
  354. package/dist/traceability/staged-file-coverage.d.ts +33 -0
  355. package/dist/traceability/staged-file-coverage.d.ts.map +1 -0
  356. package/dist/traceability/staged-file-coverage.js +284 -0
  357. package/dist/traceability/staged-impact-contract.js +4 -4
  358. package/dist/traceability/staged-symbols-manifest.d.ts +13 -0
  359. package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
  360. package/dist/traceability/staged-symbols-manifest.js +138 -27
  361. package/dist/traceability/symbol-extract.d.ts +5 -0
  362. package/dist/traceability/symbol-extract.d.ts.map +1 -1
  363. package/dist/traceability/symbol-extract.js +1 -1
  364. package/dist/traceability/temp-kb.d.ts +2 -0
  365. package/dist/traceability/temp-kb.d.ts.map +1 -1
  366. package/dist/traceability/temp-kb.js +13 -4
  367. package/dist/types/entities.d.ts +5 -3
  368. package/dist/types/entities.d.ts.map +1 -1
  369. package/dist/utils/branch-resolver.d.ts +1 -0
  370. package/dist/utils/branch-resolver.d.ts.map +1 -1
  371. package/dist/utils/branch-resolver.js +7 -4
  372. package/dist/utils/branch-store.d.ts +6 -0
  373. package/dist/utils/branch-store.d.ts.map +1 -1
  374. package/dist/utils/branch-store.js +27 -0
  375. package/dist/utils/kb-paths.d.ts +1 -1
  376. package/dist/utils/kb-paths.d.ts.map +1 -1
  377. package/dist/utils/kb-paths.js +1 -1
  378. package/dist/utils/rule-registry.d.ts +1 -11
  379. package/dist/utils/rule-registry.d.ts.map +1 -1
  380. package/dist/utils/rule-registry.generated.d.ts +97 -0
  381. package/dist/utils/rule-registry.generated.d.ts.map +1 -0
  382. package/dist/utils/rule-registry.generated.js +125 -0
  383. package/dist/utils/rule-registry.js +12 -113
  384. package/dist/utils/strict-modeling.d.ts +1 -0
  385. package/dist/utils/strict-modeling.d.ts.map +1 -1
  386. package/dist/utils/strict-modeling.js +1 -1
  387. package/package.json +8 -11
  388. package/src/public/diagnostic-usage.ts +6 -6
  389. package/src/public/distribution-parity.ts +17 -10
  390. package/src/public/impact/coverage-depth-quality.ts +1 -1
  391. package/src/public/impact/diagnostics.ts +2 -1
  392. package/src/public/impact/diff-meaning.ts +11 -4
  393. package/src/public/impact/full-kb-quality.ts +463 -72
  394. package/src/public/operations/catalog.ts +10 -4
  395. package/src/public/operations/check-executor.ts +3 -7
  396. package/src/public/operations/contracts.ts +38 -22
  397. package/src/public/operations/discovery-entities.ts +7 -0
  398. package/src/public/operations/discovery-executors.ts +26 -23
  399. package/src/public/operations/index.ts +1 -1
  400. package/src/public/operations/migration-plan.ts +32 -25
  401. package/src/public/operations/node-ports.ts +6 -6
  402. package/src/public/operations/repair-plan.ts +60 -23
  403. package/src/public/operations/result-envelope.ts +15 -10
  404. package/src/public/operations/runtime-types.ts +5 -0
  405. package/src/public/operations/specs/check-rules.generated.ts +37 -0
  406. package/src/public/operations/specs/check.ts +12 -21
  407. package/src/public/operations/specs/mutation-schemas.ts +22 -9
  408. package/src/public/operations/specs/planning.ts +7 -0
  409. package/src/public/operations/specs/proof.ts +43 -0
  410. package/src/public/operations/specs/reporting.ts +140 -13
  411. package/src/public/operations/symbol-repair-plan.ts +163 -3
  412. package/src/public/operations/types.ts +1 -1
  413. package/src/public/proof-fingerprint.ts +216 -0
  414. package/src/public/proof-protocol-types.d.ts +96 -0
  415. package/src/public/proof-protocol.ts +589 -0
  416. package/src/public/proof-receipt.ts +499 -0
  417. package/src/public/schemas/entity.ts +26 -10
  418. package/src/public/skills/kibi-freshness/SKILL.md +1 -1
  419. package/src/public/skills/kibi-usage/SKILL.md +41 -12
  420. package/src/public/skills/kibi-usage/resources/operation-access.md +1 -1
  421. package/src/public/skills/kibi-usage/resources/proof.md +105 -0
  422. package/src/public/skills/kibi-usage/resources/workflows.md +6 -6
  423. package/src/public/symbol-granularity.generated.ts +41 -0
  424. package/src/public/symbol-granularity.ts +35 -60
  425. package/src/public/telemetry-acceptance-types.d.ts +98 -0
  426. package/src/public/telemetry-acceptance.ts +22 -100
  427. package/src/public/telemetry-remediation.ts +1 -1
  428. package/src/schemas/entity.schema.json +355 -215
  429. package/dist/cli-register-verification.d.ts +0 -3
  430. package/dist/cli-register-verification.d.ts.map +0 -1
  431. package/dist/cli-register-verification.js +0 -16
  432. package/dist/commands/verify.d.ts +0 -10
  433. package/dist/commands/verify.d.ts.map +0 -1
  434. package/dist/commands/verify.js +0 -126
  435. package/dist/operations/verification/ingest-verification.d.ts +0 -29
  436. package/dist/operations/verification/ingest-verification.d.ts.map +0 -1
  437. package/dist/operations/verification/ingest-verification.js +0 -192
  438. package/dist/public/operations/specs/verification.d.ts +0 -78
  439. package/dist/public/operations/specs/verification.d.ts.map +0 -1
  440. package/dist/public/operations/specs/verification.js +0 -62
  441. package/dist/public/playwright-case-id.d.ts.map +0 -1
  442. package/dist/public/verification-receipt.d.ts +0 -242
  443. package/dist/public/verification-receipt.d.ts.map +0 -1
  444. package/dist/public/verification-receipt.js +0 -296
  445. package/dist/verification/playwright-reporter.d.ts +0 -21
  446. package/dist/verification/playwright-reporter.d.ts.map +0 -1
  447. package/dist/verification/playwright-reporter.js +0 -114
  448. package/src/public/operations/specs/verification.ts +0 -78
  449. package/src/public/playwright-case-id.ts +0 -35
  450. package/src/public/verification-receipt.ts +0 -412
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function isEngineDaemonEntrypoint(argv?: readonly string[], moduleUrl?: string, isMain?: boolean | undefined): boolean;
3
+ export declare function runEngineDaemonCli(args?: readonly string[]): Promise<void>;
4
+ export declare function runEngineDaemonIfEntrypoint(isEntrypoint?: boolean): Promise<void>;
3
5
  //# sourceMappingURL=engine-daemon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine-daemon.d.ts","sourceRoot":"","sources":["../src/engine-daemon.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"engine-daemon.d.ts","sourceRoot":"","sources":["../src/engine-daemon.ts"],"names":[],"mappings":";AAWA,wBAAgB,wBAAwB,CACtC,IAAI,GAAE,SAAS,MAAM,EAAiB,EACtC,SAAS,GAAE,MAAwB,EACnC,MAAM,GAAE,OAAO,GAAG,SACX,GACN,OAAO,CAWT;AAYD,wBAAsB,kBAAkB,CACtC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAC9C,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED,wBAAsB,2BAA2B,CAC/C,YAAY,UAA6B,GACxC,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -1,6 +1,27 @@
1
1
  #!/usr/bin/env node
2
2
  import { writeFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { pathToFileURL } from "node:url";
3
5
  import { runEngineDaemon } from "./engine.js";
6
+ // Node 22.14 and earlier do not set `import.meta.main`. The journaled engine
7
+ // client always hosts this file with `node`, so the entry check must work
8
+ // without Bun-only metadata.
9
+ // implements REQ-core-journaled-engine-persistence
10
+ export function isEngineDaemonEntrypoint(argv = process.argv, moduleUrl = import.meta.url, isMain = import.meta
11
+ .main) {
12
+ if (isMain === true) {
13
+ return moduleUrl === import.meta.url;
14
+ }
15
+ const entry = argv[1];
16
+ if (typeof entry !== "string" || entry.length === 0)
17
+ return false;
18
+ try {
19
+ return moduleUrl === pathToFileURL(path.resolve(entry)).href;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
4
25
  function requiredArg(args, name) {
5
26
  const index = args.indexOf(name);
6
27
  const value = index >= 0 ? args[index + 1] : undefined;
@@ -9,26 +30,34 @@ function requiredArg(args, name) {
9
30
  }
10
31
  return value;
11
32
  }
12
- const args = process.argv.slice(2);
13
- try {
14
- await runEngineDaemon({
15
- workspaceRoot: requiredArg(args, "--workspace"),
16
- branch: requiredArg(args, "--branch"),
17
- socketPath: requiredArg(args, "--socket"),
18
- });
19
- }
20
- catch (error) {
21
- const message = error instanceof Error ? error.message : String(error);
22
- console.error(message);
23
- const socketIndex = args.indexOf("--socket");
24
- const socketPath = socketIndex >= 0 ? args[socketIndex + 1] : undefined;
25
- if (socketPath) {
26
- try {
27
- writeFileSync(`${socketPath}.error`, `${message}\n`, { mode: 0o600 });
28
- }
29
- catch {
30
- // Preserve the process exit code even if the diagnostic path is gone.
33
+ // implements REQ-core-journaled-engine-persistence
34
+ export async function runEngineDaemonCli(args = process.argv.slice(2)) {
35
+ try {
36
+ await runEngineDaemon({
37
+ workspaceRoot: requiredArg(args, "--workspace"),
38
+ branch: requiredArg(args, "--branch"),
39
+ socketPath: requiredArg(args, "--socket"),
40
+ });
41
+ }
42
+ catch (error) {
43
+ const message = error instanceof Error ? error.message : String(error);
44
+ console.error(message);
45
+ const socketIndex = args.indexOf("--socket");
46
+ const socketPath = socketIndex >= 0 ? args[socketIndex + 1] : undefined;
47
+ if (socketPath) {
48
+ try {
49
+ writeFileSync(`${socketPath}.error`, `${message}\n`, { mode: 0o600 });
50
+ }
51
+ catch {
52
+ // Preserve the process exit code even if the diagnostic path is gone.
53
+ }
31
54
  }
55
+ process.exitCode = 1;
32
56
  }
33
- process.exitCode = 1;
34
57
  }
58
+ export async function runEngineDaemonIfEntrypoint(isEntrypoint = isEngineDaemonEntrypoint()) {
59
+ if (!isEntrypoint)
60
+ return;
61
+ await runEngineDaemonCli();
62
+ }
63
+ await runEngineDaemonIfEntrypoint();
package/dist/engine.d.ts CHANGED
@@ -1,84 +1,17 @@
1
+ import type { EngineAttachmentIdentity, EngineCommandV1 } from "./engine-types.js";
1
2
  import type { PrologQueryResult } from "./public/operations/runtime-types.js";
2
3
  import type { PrologEntityQueryInput, PrologEntityQueryResult, PrologSearchQueryInput, PrologSearchQueryResult } from "./public/operations/runtime-types.js";
4
+ export type { EngineAttachmentIdentity, EngineCommandV1, EngineRequest, } from "./engine-types.js";
3
5
  export declare const ENGINE_PROTOCOL_VERSION = 1;
4
6
  export declare const ENGINE_IDLE_TIMEOUT_MS: number;
5
7
  export declare const ENGINE_PACKAGE_VERSIONS: string;
6
- export type EngineCommandV1 = Readonly<{
7
- version: 1;
8
- kind: "status";
9
- }> | Readonly<{
10
- version: 1;
11
- kind: "entities";
12
- type?: string;
13
- id?: string;
14
- tags?: readonly string[];
15
- sourceFile?: string;
16
- limit: number;
17
- offset: number;
18
- }> | Readonly<{
19
- version: 1;
20
- kind: "search";
21
- query: string;
22
- type?: string;
23
- limit: number;
24
- offset: number;
25
- }> | Readonly<{
26
- version: 1;
27
- kind: "checkpoint";
28
- }> | Readonly<{
29
- version: 1;
30
- kind: "compact";
31
- }> | Readonly<{
32
- version: 1;
33
- kind: "save";
34
- }> | Readonly<{
35
- version: 1;
36
- kind: "check";
37
- rule?: string;
38
- }> | Readonly<{
39
- version: 1;
40
- kind: "relationship";
41
- action: "assert" | "retract";
42
- type: string;
43
- from: string;
44
- to: string;
45
- }> | Readonly<{
46
- version: 1;
47
- kind: "persistence";
48
- action: "checkpoint" | "compact" | "save" | "export";
49
- targetDirectory?: string;
50
- }> | Readonly<{
51
- version: 1;
52
- kind: "lifecycle";
53
- action: "stop" | "cancel";
54
- requestId?: number;
55
- }> | Readonly<{
56
- version: 1;
57
- kind: "stop";
58
- }> | Readonly<{
59
- version: 1;
60
- kind: "cancel";
61
- requestId: number;
62
- }>;
63
- export type EngineRequest = {
64
- readonly id: number;
65
- readonly method: "query" | "command" | "entities" | "search" | "kbStatus" | "status" | "checkpoint" | "compact" | "export" | "stop" | "cancel";
66
- readonly protocolVersion?: number;
67
- readonly packageVersions?: string;
68
- readonly workspaceRoot?: string;
69
- readonly branch?: string;
70
- readonly goal?: string;
71
- readonly type?: string;
72
- readonly entityId?: string;
73
- readonly searchQuery?: string;
74
- readonly tags?: readonly string[];
75
- readonly sourceFile?: string;
76
- readonly limit?: number;
77
- readonly offset?: number;
78
- readonly targetDirectory?: string;
79
- readonly cancelOf?: number;
80
- readonly command?: EngineCommandV1;
81
- };
8
+ export declare function requestEngineSignalShutdown(shutdown: () => unknown): () => void;
9
+ export declare function readJournalGeneration(branchPath: string): string;
10
+ export declare function readEngineAttachmentIdentity(branchPath: string): EngineAttachmentIdentity | null;
11
+ export declare function parseEngineAttachmentIdentity(statusJson: string | undefined): EngineAttachmentIdentity | null;
12
+ export declare function engineAttachmentsMatch(expected: EngineAttachmentIdentity | null, attached: EngineAttachmentIdentity | null): boolean;
13
+ export declare function formatEngineAttachmentMismatch(operation: string, expected: EngineAttachmentIdentity | null, attached: EngineAttachmentIdentity | null): string;
14
+ export declare function runtimeDirectory(): string;
82
15
  /**
83
16
  * Cross the kernel durability boundary before a journaled mutation is
84
17
  * acknowledged. SWI flushes completed RDF transaction records to its journal
@@ -120,8 +53,10 @@ export declare class EngineClient {
120
53
  private pending;
121
54
  private requestTail;
122
55
  private lastResult;
56
+ private replacingStaleDaemon;
123
57
  constructor(options: EngineClientOptions);
124
58
  start(allowSpawn?: boolean): Promise<void>;
59
+ private connect;
125
60
  private attachSocket;
126
61
  private handleResponse;
127
62
  private request;
@@ -143,6 +78,9 @@ export declare class EngineClient {
143
78
  exportStorage(targetDirectory: string): Promise<PrologQueryResult>;
144
79
  invalidateCache(): void;
145
80
  isRunning(): boolean;
81
+ private readAttachedIdentity;
82
+ private reconcileAttachment;
83
+ private shutdownConnectedDaemon;
146
84
  getPid(): number;
147
85
  stop(startIfMissing?: boolean): Promise<void>;
148
86
  terminate(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,sCAAsC,CAAC;AAI9C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,sBAAsB,QAAiB,CAAC;AACrD,eAAO,MAAM,uBAAuB,QACY,CAAC;AAgBjD,MAAM,MAAM,eAAe,GACvB,QAAQ,CAAC;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GACxC,QAAQ,CAAC;IACP,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IA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  import { fileURLToPath } from "node:url";
15
15
  import { PrologProcess, resolveKbPlPath } from "./prolog.js";
16
16
  import { parseEntityFromList, parseListOfLists } from "./prolog/codec.js";
17
+ import { retryAttachAfterBreakingStaleLock } from "./prolog/store-lock.js";
17
18
  import { isValidBranchName } from "./utils/branch-resolver.js";
18
- import { ensureBranchStoreManifest } from "./utils/branch-store-locator.js";
19
+ import { branchStorePath, ensureBranchStoreManifest, } from "./utils/branch-store-locator.js";
19
20
  export const ENGINE_PROTOCOL_VERSION = 1;
20
21
  export const ENGINE_IDLE_TIMEOUT_MS = 10 * 60 * 1000;
21
22
  export const ENGINE_PACKAGE_VERSIONS = process.env.KIBI_PACKAGE_VERSIONS ?? "unknown";
@@ -23,12 +24,95 @@ const ENGINE_QUERY_CACHE_MAX_ENTRIES = 128;
23
24
  const ENGINE_QUERY_CACHE_MAX_RESULT_BYTES = 8 * 1024 * 1024;
24
25
  const ENGINE_FRESHNESS_CACHE_MS = 100;
25
26
  const ENGINE_PUBLICATION_LOCK_STALE_MS = 5_000;
27
+ const ENGINE_WORKSPACE_WATCHDOG_MS = 30_000;
28
+ export function requestEngineSignalShutdown(shutdown) {
29
+ return () => {
30
+ void shutdown();
31
+ };
32
+ }
33
+ export function readJournalGeneration(branchPath) {
34
+ // implements REQ-core-journaled-engine-persistence
35
+ const currentPath = path.join(branchPath, "CURRENT");
36
+ if (!existsSync(currentPath))
37
+ return "";
38
+ return readFileSync(currentPath, "utf8").trim();
39
+ }
40
+ export function readEngineAttachmentIdentity(branchPath) {
41
+ // implements REQ-core-journaled-engine-persistence
42
+ if (!existsSync(branchPath))
43
+ return null;
44
+ const stats = statSync(branchPath);
45
+ let resolved = path.resolve(branchPath);
46
+ try {
47
+ resolved = realpathSync(branchPath);
48
+ }
49
+ catch {
50
+ // The live path may be replaced between stat and realpath.
51
+ }
52
+ return {
53
+ path: resolved,
54
+ generation: readJournalGeneration(branchPath),
55
+ dev: stats.dev,
56
+ ino: stats.ino,
57
+ };
58
+ }
59
+ export function parseEngineAttachmentIdentity(statusJson) {
60
+ // implements REQ-core-journaled-engine-persistence
61
+ if (statusJson === undefined)
62
+ return null;
63
+ try {
64
+ const decoded = JSON.parse(JSON.parse(statusJson));
65
+ if (typeof decoded.attachedPath !== "string" ||
66
+ typeof decoded.attachedGeneration !== "string" ||
67
+ typeof decoded.attachedDev !== "number" ||
68
+ typeof decoded.attachedIno !== "number") {
69
+ return null;
70
+ }
71
+ return {
72
+ path: decoded.attachedPath,
73
+ generation: decoded.attachedGeneration,
74
+ dev: decoded.attachedDev,
75
+ ino: decoded.attachedIno,
76
+ };
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ }
82
+ export function engineAttachmentsMatch(expected, attached) {
83
+ // implements REQ-core-journaled-engine-persistence
84
+ if (expected === null || attached === null)
85
+ return false;
86
+ if (expected.path !== attached.path)
87
+ return false;
88
+ if (expected.ino !== 0 && attached.ino !== 0) {
89
+ return expected.dev === attached.dev && expected.ino === attached.ino;
90
+ }
91
+ return (expected.generation.length > 0 &&
92
+ expected.generation === attached.generation);
93
+ }
94
+ export function formatEngineAttachmentMismatch(operation, expected, attached) {
95
+ // implements REQ-core-journaled-engine-persistence
96
+ return [
97
+ `operation=${operation}`,
98
+ `branchStore=${expected?.path ?? "missing"}`,
99
+ `expectedGeneration=${expected?.generation || "missing"}`,
100
+ `attachedPath=${attached?.path ?? "missing"}`,
101
+ `attachedGeneration=${attached?.generation || "missing"}`,
102
+ ].join(" ");
103
+ }
26
104
  function engineIdleTimeoutMs() {
27
105
  const configured = Number.parseInt(process.env.KIBI_ENGINE_IDLE_TIMEOUT_MS ?? "", 10);
28
106
  return Number.isFinite(configured) && configured >= 100
29
107
  ? configured
30
108
  : ENGINE_IDLE_TIMEOUT_MS;
31
109
  }
110
+ function engineWorkspaceWatchdogMs() {
111
+ const configured = Number.parseInt(process.env.KIBI_ENGINE_WORKSPACE_WATCHDOG_MS ?? "", 10);
112
+ return Number.isFinite(configured) && configured >= 100
113
+ ? configured
114
+ : ENGINE_WORKSPACE_WATCHDOG_MS;
115
+ }
32
116
  function quoteProlog(value) {
33
117
  return value.replaceAll("'", "''");
34
118
  }
@@ -162,7 +246,7 @@ function parseFrames(buffer, onFrame) {
162
246
  }
163
247
  return buffer.subarray(cursor);
164
248
  }
165
- function runtimeDirectory() {
249
+ export function runtimeDirectory() {
166
250
  const configured = process.env.KIBI_RUNTIME_DIR ??
167
251
  process.env.XDG_RUNTIME_DIR ??
168
252
  path.join(os.tmpdir(), "kibi-runtime");
@@ -577,6 +661,7 @@ export class EngineClient {
577
661
  pending = new Map();
578
662
  requestTail = Promise.resolve();
579
663
  lastResult = null;
664
+ replacingStaleDaemon = false;
580
665
  constructor(options) {
581
666
  if (!isValidBranchName(options.branch)) {
582
667
  throw new Error(`Invalid Kibi engine branch name: ${options.branch}`);
@@ -593,6 +678,13 @@ export class EngineClient {
593
678
  this.allowPublicationLock = options.allowPublicationLock ?? false;
594
679
  }
595
680
  async start(allowSpawn = true) {
681
+ const wasConnected = this.socket !== null && !this.socket.destroyed;
682
+ await this.connect(allowSpawn);
683
+ if (!wasConnected && this.socket !== null) {
684
+ await this.reconcileAttachment();
685
+ }
686
+ }
687
+ async connect(allowSpawn = true) {
596
688
  if (this.socket !== null && !this.socket.destroyed)
597
689
  return;
598
690
  const socketPath = engineSocketPath(this.workspaceRoot, this.branch);
@@ -878,27 +970,36 @@ export class EngineClient {
878
970
  isRunning() {
879
971
  return this.socket !== null && !this.socket.destroyed;
880
972
  }
881
- getPid() {
882
- const pidPath = enginePidPath(this.workspaceRoot, this.branch);
973
+ async readAttachedIdentity() {
974
+ const status = await this.queryStatusJson();
975
+ if (!status.success)
976
+ return null;
977
+ return parseEngineAttachmentIdentity(status.bindings.JsonString);
978
+ }
979
+ async reconcileAttachment() {
980
+ if (this.replacingStaleDaemon || this.socket === null)
981
+ return;
982
+ const livePath = branchStorePath(this.workspaceRoot, this.branch);
983
+ const expected = readEngineAttachmentIdentity(livePath);
984
+ const attached = await this.readAttachedIdentity();
985
+ if (engineAttachmentsMatch(expected, attached))
986
+ return;
987
+ this.replacingStaleDaemon = true;
883
988
  try {
884
- return Number.parseInt(readFileSync(pidPath, "utf8").trim(), 10) || 0;
989
+ await this.shutdownConnectedDaemon();
990
+ await this.connect(true);
991
+ const live = readEngineAttachmentIdentity(livePath);
992
+ const retried = await this.readAttachedIdentity();
993
+ if (!engineAttachmentsMatch(live, retried)) {
994
+ throw new Error(`Kibi engine is attached to a stale branch generation: ${formatEngineAttachmentMismatch("attachment-handshake", live, retried)}`);
995
+ }
885
996
  }
886
- catch {
887
- return 0;
997
+ finally {
998
+ this.replacingStaleDaemon = false;
888
999
  }
889
1000
  }
890
- async stop(startIfMissing = true) {
1001
+ async shutdownConnectedDaemon() {
891
1002
  const socketPath = engineSocketPath(this.workspaceRoot, this.branch);
892
- if (!this.isRunning()) {
893
- try {
894
- await this.start(startIfMissing);
895
- }
896
- catch {
897
- if (!startIfMissing)
898
- return;
899
- throw new Error("Unable to start Kibi engine for stop request");
900
- }
901
- }
902
1003
  if (!this.isRunning()) {
903
1004
  if (existsSync(socketPath)) {
904
1005
  throw new Error(`Kibi engine socket remains present but is not reachable: ${socketPath}`);
@@ -914,9 +1015,6 @@ export class EngineClient {
914
1015
  }
915
1016
  this.socket?.destroy();
916
1017
  this.socket = null;
917
- // The daemon acknowledges stop before its SWI child has flushed and the
918
- // listening socket has closed. Do not let a following auto-start attach to
919
- // that half-shutdown process.
920
1018
  const deadline = Date.now() + 5_000;
921
1019
  while (existsSync(socketPath) && Date.now() < deadline) {
922
1020
  await new Promise((resolve) => setTimeout(resolve, 25));
@@ -926,6 +1024,35 @@ export class EngineClient {
926
1024
  throw new Error(`Kibi engine did not stop within 5 seconds${detail}`);
927
1025
  }
928
1026
  }
1027
+ getPid() {
1028
+ const pidPath = enginePidPath(this.workspaceRoot, this.branch);
1029
+ try {
1030
+ return Number.parseInt(readFileSync(pidPath, "utf8").trim(), 10) || 0;
1031
+ }
1032
+ catch {
1033
+ return 0;
1034
+ }
1035
+ }
1036
+ async stop(startIfMissing = true) {
1037
+ const socketPath = engineSocketPath(this.workspaceRoot, this.branch);
1038
+ if (!this.isRunning()) {
1039
+ try {
1040
+ await this.connect(startIfMissing);
1041
+ }
1042
+ catch {
1043
+ if (!startIfMissing)
1044
+ return;
1045
+ throw new Error("Unable to start Kibi engine for stop request");
1046
+ }
1047
+ }
1048
+ if (!this.isRunning()) {
1049
+ if (existsSync(socketPath)) {
1050
+ throw new Error(`Kibi engine socket remains present but is not reachable: ${socketPath}`);
1051
+ }
1052
+ return;
1053
+ }
1054
+ await this.shutdownConnectedDaemon();
1055
+ }
929
1056
  async terminate() {
930
1057
  // Closing a client connection releases the engine; the daemon remains
931
1058
  // available for other operations until its idle timeout expires.
@@ -1149,12 +1276,26 @@ export async function runEngineDaemon(options) {
1149
1276
  const prolog = new PrologProcess({ timeout: 120_000, oneShot: false });
1150
1277
  await prolog.start();
1151
1278
  const attached = await prolog.query(`kb_attach('${quoteProlog(branchPath)}')`);
1152
- if (!attached.success)
1153
- throw new Error(attached.error ?? "Failed to attach branch KB");
1154
- const statusModulePath = path.join(path.dirname(resolveKbPlPath()), "status.pl");
1155
- const statusLoaded = await prolog.query(`use_module('${quoteProlog(statusModulePath.replaceAll("\\", "/"))}')`);
1156
- if (!statusLoaded.success) {
1157
- throw new Error(statusLoaded.error ?? "Failed to load Kibi status module");
1279
+ if (!attached.success) {
1280
+ // The daemon hosts the branch store for every later request, so a
1281
+ // store-locked startup with a provably dead holder is auto-healed here
1282
+ // exactly like the CLI runtime path; live holders abort the startup
1283
+ // with the holder identity surfaced.
1284
+ const recovered = await retryAttachAfterBreakingStaleLock(prolog, branchPath, attached);
1285
+ if (!recovered.success)
1286
+ throw new Error(recovered.error ?? "Failed to attach branch KB");
1287
+ }
1288
+ const attachedIdentity = readEngineAttachmentIdentity(branchPath);
1289
+ const coreModuleDir = path.dirname(resolveKbPlPath());
1290
+ for (const [fileName, label] of [
1291
+ ["status.pl", "status"],
1292
+ ["discovery.pl", "discovery"],
1293
+ ]) {
1294
+ const modulePath = path.join(coreModuleDir, fileName);
1295
+ const loaded = await prolog.query(`use_module('${quoteProlog(modulePath.replaceAll("\\", "/"))}')`);
1296
+ if (!loaded.success) {
1297
+ throw new Error(loaded.error ?? `Failed to load Kibi ${label} module`);
1298
+ }
1158
1299
  }
1159
1300
  mkdirSync(path.dirname(options.socketPath), { recursive: true, mode: 0o700 });
1160
1301
  if (existsSync(options.socketPath)) {
@@ -1195,6 +1336,12 @@ export async function runEngineDaemon(options) {
1195
1336
  try {
1196
1337
  const decoded = JSON.parse(JSON.parse(result.bindings.JsonString));
1197
1338
  decoded.branch = options.branch;
1339
+ if (attachedIdentity !== null) {
1340
+ decoded.attachedPath = attachedIdentity.path;
1341
+ decoded.attachedGeneration = attachedIdentity.generation;
1342
+ decoded.attachedDev = attachedIdentity.dev;
1343
+ decoded.attachedIno = attachedIdentity.ino;
1344
+ }
1198
1345
  return {
1199
1346
  ...result,
1200
1347
  bindings: {
@@ -1207,6 +1354,27 @@ export async function runEngineDaemon(options) {
1207
1354
  return result;
1208
1355
  }
1209
1356
  };
1357
+ // A daemon whose workspace vanished (git worktree remove --force, deleted
1358
+ // checkout) can never serve a request again, but it would keep holding the
1359
+ // branch-store lock and wedge every later operation behind an opaque
1360
+ // "KB locked". Detect the loss and shut down cleanly instead.
1361
+ let workspaceMissingStreak = 0;
1362
+ const workspaceWatchdog = setInterval(() => {
1363
+ if (shuttingDown)
1364
+ return;
1365
+ // Two consecutive misses before giving up: a transient blip (slow
1366
+ // rename, network mount hiccup) must not stop a healthy daemon.
1367
+ if (!existsSync(options.workspaceRoot)) {
1368
+ workspaceMissingStreak += 1;
1369
+ if (workspaceMissingStreak < 2)
1370
+ return;
1371
+ console.error(`[KIBI] workspace ${options.workspaceRoot} no longer exists; stopping engine`);
1372
+ void shutdown();
1373
+ return;
1374
+ }
1375
+ workspaceMissingStreak = 0;
1376
+ }, engineWorkspaceWatchdogMs());
1377
+ workspaceWatchdog.unref();
1210
1378
  const scheduleIdleExit = () => {
1211
1379
  if (activeClients > 0)
1212
1380
  return;
@@ -1507,6 +1675,7 @@ export async function runEngineDaemon(options) {
1507
1675
  process.off("SIGINT", requestSignalShutdown);
1508
1676
  if (idleTimer)
1509
1677
  clearTimeout(idleTimer);
1678
+ clearInterval(workspaceWatchdog);
1510
1679
  const saved = await prolog.query("kb_save").catch(() => null);
1511
1680
  if (saved?.success) {
1512
1681
  try {
@@ -1545,9 +1714,7 @@ export async function runEngineDaemon(options) {
1545
1714
  // Detached engines must cross the same durability boundary when a service
1546
1715
  // manager or a test harness terminates them as they do for an RPC stop.
1547
1716
  // implements REQ-test-journaled-engine-harness
1548
- const requestSignalShutdown = () => {
1549
- void shutdown();
1550
- };
1717
+ const requestSignalShutdown = requestEngineSignalShutdown(shutdown);
1551
1718
  process.once("SIGTERM", requestSignalShutdown);
1552
1719
  process.once("SIGINT", requestSignalShutdown);
1553
1720
  server.on("connection", (socket) => {
@@ -67,4 +67,9 @@ export declare function extractFromManifestString(content: string, filePath: str
67
67
  export declare function extractManifestSymbolRecordsString(content: string, filePath: string): ManifestSymbolRecord[];
68
68
  export declare function extractFromManifest(filePath: string): ExtractionResult[];
69
69
  export declare function readManifestWithCoordinateOverlay(manifestPath: string, coordinatesPath?: string): ManifestSymbolRecord[];
70
+ export interface ReceiptCodeScopeEntry {
71
+ readonly symbolId: string;
72
+ readonly sourceHash: string;
73
+ }
74
+ export declare function resolveBoundSymbolScope(manifestPath: string, symbolIds: readonly string[]): ReceiptCodeScopeEntry[];
70
75
  //# sourceMappingURL=manifest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/extractors/manifest.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EA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,SAAS,MAAM,EAAE,GAC3B,qBAAqB,EAAE,CAgBzB"}
@@ -16,7 +16,7 @@
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
18
  import { createHash } from "node:crypto";
19
- import { existsSync, readFileSync } from "node:fs";
19
+ import { existsSync, readFileSync, statSync } from "node:fs";
20
20
  import * as path from "node:path";
21
21
  import { load as parseYAML } from "js-yaml";
22
22
  import { DEFAULT_COORDINATES_PATH } from "../utils/manifest-paths.js";
@@ -324,6 +324,51 @@ export function readManifestWithCoordinateOverlay(manifestPath, coordinatesPath)
324
324
  resolveSourceText: sourceTextResolver(manifestPath),
325
325
  });
326
326
  }
327
+ /**
328
+ * Resolve the code scope of a receipt binding: for each proof-bound symbol,
329
+ * its coordinate-recorded source hash. A receipt's binding covers these, so
330
+ * editing the production code behind a test stales only that test's receipts
331
+ * (per-contract binding mode).
332
+ */
333
+ // implements REQ-kibi-proof-evidence-protocol
334
+ // Receipt-binding scope reads run once per proof-bearing test; a campaign
335
+ // touches dozens-to-hundreds of tests, so the parsed overlay is memoized per
336
+ // manifest state (path + mtime + size) and invalidated when the file changes.
337
+ const boundSymbolScopeCache = new Map();
338
+ function boundSymbolScopeRecords(manifestPath) {
339
+ let stamp = "";
340
+ try {
341
+ const stats = statSync(manifestPath);
342
+ stamp = `${stats.mtimeMs}:${stats.size}`;
343
+ }
344
+ catch {
345
+ stamp = "missing";
346
+ }
347
+ const hit = boundSymbolScopeCache.get(manifestPath);
348
+ if (hit && hit.stamp === stamp)
349
+ return hit.records;
350
+ const records = readManifestWithCoordinateOverlay(manifestPath);
351
+ boundSymbolScopeCache.set(manifestPath, { stamp, records });
352
+ return records;
353
+ }
354
+ export function resolveBoundSymbolScope(manifestPath, symbolIds) {
355
+ const wanted = new Set(symbolIds);
356
+ if (wanted.size === 0)
357
+ return [];
358
+ const records = boundSymbolScopeRecords(manifestPath);
359
+ const scope = [];
360
+ for (const record of records) {
361
+ const symbolId = typeof record.id === "string" ? record.id : undefined;
362
+ if (symbolId === undefined || !wanted.has(symbolId))
363
+ continue;
364
+ const sourceHash = record.sourceHash;
365
+ if (typeof sourceHash === "string" && sourceHash !== "") {
366
+ scope.push({ symbolId, sourceHash });
367
+ }
368
+ }
369
+ scope.sort((left, right) => left.symbolId.localeCompare(right.symbolId));
370
+ return scope;
371
+ }
327
372
  function generateId(filePath, title) {
328
373
  const hash = createHash("sha256");
329
374
  hash.update(`${filePath}:${title}`);