kibi-cli 2.0.0 → 2.2.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 (377) hide show
  1. package/dist/cli-protocol.d.ts.map +1 -1
  2. package/dist/cli-protocol.js +3 -2
  3. package/dist/cli-register-proof.d.ts.map +1 -1
  4. package/dist/cli-register-proof.js +25 -1
  5. package/dist/cli-register-reporting.d.ts.map +1 -1
  6. package/dist/cli-register-reporting.js +6 -0
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +2 -0
  9. package/dist/commands/aggregated-checks.d.ts +7 -0
  10. package/dist/commands/aggregated-checks.d.ts.map +1 -1
  11. package/dist/commands/aggregated-checks.js +25 -1
  12. package/dist/commands/check-generated.d.ts +7 -0
  13. package/dist/commands/check-generated.d.ts.map +1 -0
  14. package/dist/commands/check-generated.js +192 -0
  15. package/dist/commands/check.d.ts.map +1 -1
  16. package/dist/commands/check.js +24 -15
  17. package/dist/commands/doctor.d.ts.map +1 -1
  18. package/dist/commands/doctor.js +227 -25
  19. package/dist/commands/engine.d.ts.map +1 -1
  20. package/dist/commands/engine.js +3 -1
  21. package/dist/commands/github-init.d.ts +1 -1
  22. package/dist/commands/github-init.d.ts.map +1 -1
  23. package/dist/commands/github-init.js +1 -1
  24. package/dist/commands/init-helpers.d.ts +17 -2
  25. package/dist/commands/init-helpers.d.ts.map +1 -1
  26. package/dist/commands/init-helpers.js +136 -30
  27. package/dist/commands/init.d.ts.map +1 -1
  28. package/dist/commands/init.js +110 -15
  29. package/dist/commands/proof-explain.d.ts +10 -0
  30. package/dist/commands/proof-explain.d.ts.map +1 -0
  31. package/dist/commands/proof-explain.js +45 -0
  32. package/dist/commands/proof-impact.d.ts +7 -0
  33. package/dist/commands/proof-impact.d.ts.map +1 -0
  34. package/dist/commands/proof-impact.js +39 -0
  35. package/dist/commands/proof-migrate-legacy.js +1 -1
  36. package/dist/commands/proof-prune.js +1 -1
  37. package/dist/commands/prove.d.ts.map +1 -1
  38. package/dist/commands/prove.js +14 -22
  39. package/dist/commands/report.d.ts.map +1 -1
  40. package/dist/commands/report.js +17 -2
  41. package/dist/commands/sync/cache.d.ts +20 -1
  42. package/dist/commands/sync/cache.d.ts.map +1 -1
  43. package/dist/commands/sync/cache.js +51 -2
  44. package/dist/commands/sync/discovery.d.ts.map +1 -1
  45. package/dist/commands/sync/discovery.js +1 -1
  46. package/dist/commands/sync/manifest.d.ts +1 -0
  47. package/dist/commands/sync/manifest.d.ts.map +1 -1
  48. package/dist/commands/sync/manifest.js +18 -16
  49. package/dist/commands/sync/persistence.d.ts.map +1 -1
  50. package/dist/commands/sync/persistence.js +14 -0
  51. package/dist/commands/sync.d.ts.map +1 -1
  52. package/dist/commands/sync.js +11 -3
  53. package/dist/engine.d.ts +29 -1
  54. package/dist/engine.d.ts.map +1 -1
  55. package/dist/engine.js +259 -89
  56. package/dist/env/bootstrap.d.ts +84 -0
  57. package/dist/env/bootstrap.d.ts.map +1 -0
  58. package/dist/env/bootstrap.js +310 -0
  59. package/dist/extractors/manifest.d.ts.map +1 -1
  60. package/dist/extractors/manifest.js +67 -29
  61. package/dist/extractors/markdown.d.ts +4 -0
  62. package/dist/extractors/markdown.d.ts.map +1 -1
  63. package/dist/extractors/markdown.js +33 -3
  64. package/dist/extractors/relationships.d.ts.map +1 -1
  65. package/dist/extractors/relationships.js +1 -0
  66. package/dist/extractors/symbols-coordinator.d.ts +8 -0
  67. package/dist/extractors/symbols-coordinator.d.ts.map +1 -1
  68. package/dist/extractors/symbols-coordinator.js +40 -0
  69. package/dist/extractors/symbols-ts.d.ts +8 -19
  70. package/dist/extractors/symbols-ts.d.ts.map +1 -1
  71. package/dist/extractors/symbols-ts.js +33 -503
  72. package/dist/intent-search.d.ts.map +1 -1
  73. package/dist/intent-search.js +68 -30
  74. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  75. package/dist/operations/bootstrap/generate.js +4 -3
  76. package/dist/operations/modeling/model-requirement.d.ts +1 -1
  77. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  78. package/dist/operations/modeling/model-requirement.js +179 -9
  79. package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
  80. package/dist/operations/modeling/predicate-applyplan.js +14 -2
  81. package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
  82. package/dist/operations/modeling/predicate-loader.js +24 -0
  83. package/dist/operations/modeling/predicate-types.d.ts +4 -0
  84. package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
  85. package/dist/operations/modeling/predicate-vocabulary.d.ts +54 -0
  86. package/dist/operations/modeling/predicate-vocabulary.d.ts.map +1 -0
  87. package/dist/operations/modeling/predicate-vocabulary.js +169 -0
  88. package/dist/operations/modeling/requirement-types.d.ts +5 -0
  89. package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
  90. package/dist/operations/modeling/suggest-predicates.d.ts +1 -1
  91. package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
  92. package/dist/operations/modeling/suggest-predicates.js +30 -3
  93. package/dist/operations/modeling/vocabulary-alignment.d.ts +60 -0
  94. package/dist/operations/modeling/vocabulary-alignment.d.ts.map +1 -0
  95. package/dist/operations/modeling/vocabulary-alignment.js +178 -0
  96. package/dist/operations/mutation/contradictions.d.ts +3 -0
  97. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  98. package/dist/operations/mutation/contradictions.js +29 -0
  99. package/dist/operations/mutation/delete.d.ts.map +1 -1
  100. package/dist/operations/mutation/delete.js +33 -1
  101. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +8 -0
  102. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -0
  103. package/dist/operations/mutation/predicate-vocabulary-guard.js +64 -0
  104. package/dist/operations/mutation/relationships.d.ts +1 -1
  105. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  106. package/dist/operations/mutation/relationships.js +1 -0
  107. package/dist/operations/mutation/saga.d.ts +5 -0
  108. package/dist/operations/mutation/saga.d.ts.map +1 -1
  109. package/dist/operations/mutation/saga.js +10 -0
  110. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  111. package/dist/operations/mutation/serialization.js +2 -0
  112. package/dist/operations/mutation/source-authoring.d.ts +6 -0
  113. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  114. package/dist/operations/mutation/source-authoring.js +65 -26
  115. package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
  116. package/dist/operations/mutation/strict-fact.js +5 -0
  117. package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -1
  118. package/dist/operations/mutation/symbol-granularity.js +9 -87
  119. package/dist/operations/mutation/types.d.ts +17 -0
  120. package/dist/operations/mutation/types.d.ts.map +1 -1
  121. package/dist/operations/mutation/upsert.d.ts +6 -0
  122. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  123. package/dist/operations/mutation/upsert.js +72 -4
  124. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  125. package/dist/operations/mutation/validate-upsert.js +24 -1
  126. package/dist/operations/mutation/validation.d.ts.map +1 -1
  127. package/dist/operations/mutation/validation.js +16 -3
  128. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  129. package/dist/operations/planning/apply-plan.js +61 -17
  130. package/dist/operations/planning/compile-intent.d.ts +49 -0
  131. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  132. package/dist/operations/planning/compile-intent.js +66 -4
  133. package/dist/operations/proof/baseline-diff.d.ts +41 -0
  134. package/dist/operations/proof/baseline-diff.d.ts.map +1 -0
  135. package/dist/operations/proof/baseline-diff.js +153 -0
  136. package/dist/operations/proof/code-scope.d.ts +17 -0
  137. package/dist/operations/proof/code-scope.d.ts.map +1 -0
  138. package/dist/operations/proof/code-scope.js +60 -0
  139. package/dist/operations/proof/explain.d.ts +75 -0
  140. package/dist/operations/proof/explain.d.ts.map +1 -0
  141. package/dist/operations/proof/explain.js +294 -0
  142. package/dist/operations/proof/impact.d.ts +45 -0
  143. package/dist/operations/proof/impact.d.ts.map +1 -0
  144. package/dist/operations/proof/impact.js +118 -0
  145. package/dist/operations/proof/ingest-proof.d.ts +4 -2
  146. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  147. package/dist/operations/proof/ingest-proof.js +251 -77
  148. package/dist/operations/proof/migrate-legacy-receipts.d.ts.map +1 -1
  149. package/dist/operations/proof/migrate-legacy-receipts.js +28 -22
  150. package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
  151. package/dist/operations/proof/prune-receipts.js +8 -6
  152. package/dist/operations/proof/receipt-document.js +2 -2
  153. package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
  154. package/dist/operations/semantic-advisor/analysis-receipt.js +3 -9
  155. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  156. package/dist/operations/semantic-advisor/analyze-prose.js +18 -67
  157. package/dist/operations/semantic-advisor/plugin-orchestration.d.ts +63 -0
  158. package/dist/operations/semantic-advisor/plugin-orchestration.d.ts.map +1 -0
  159. package/dist/operations/semantic-advisor/plugin-orchestration.js +489 -0
  160. package/dist/operations/semantic-advisor/predicate-rules-core.d.ts +15 -2
  161. package/dist/operations/semantic-advisor/predicate-rules-core.d.ts.map +1 -1
  162. package/dist/operations/semantic-advisor/predicate-rules-core.js +7 -140
  163. package/dist/operations/semantic-advisor/predicate-rules-launcher.d.ts +11 -12
  164. package/dist/operations/semantic-advisor/predicate-rules-launcher.d.ts.map +1 -1
  165. package/dist/operations/semantic-advisor/predicate-rules-launcher.js +6 -94
  166. package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts +16 -0
  167. package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts.map +1 -1
  168. package/dist/operations/semantic-advisor/predicate-rules-policy.js +7 -150
  169. package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts +9 -0
  170. package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts.map +1 -1
  171. package/dist/operations/semantic-advisor/predicate-rules-product-tail.js +7 -102
  172. package/dist/operations/semantic-advisor/predicate-rules-product.d.ts +13 -0
  173. package/dist/operations/semantic-advisor/predicate-rules-product.d.ts.map +1 -1
  174. package/dist/operations/semantic-advisor/predicate-rules-product.js +7 -133
  175. package/dist/operations/semantic-advisor/types.d.ts +1 -0
  176. package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
  177. package/dist/plugins/compose-ontology-packs.d.ts +51 -0
  178. package/dist/plugins/compose-ontology-packs.d.ts.map +1 -0
  179. package/dist/plugins/compose-ontology-packs.js +257 -0
  180. package/dist/plugins/compose-semantic-classifier.d.ts +47 -0
  181. package/dist/plugins/compose-semantic-classifier.d.ts.map +1 -0
  182. package/dist/plugins/compose-semantic-classifier.js +216 -0
  183. package/dist/plugins/compose-vocabulary-alignment.d.ts +23 -0
  184. package/dist/plugins/compose-vocabulary-alignment.d.ts.map +1 -0
  185. package/dist/plugins/compose-vocabulary-alignment.js +141 -0
  186. package/dist/plugins/external-allowlist.d.ts +17 -0
  187. package/dist/plugins/external-allowlist.d.ts.map +1 -0
  188. package/dist/plugins/external-allowlist.js +29 -0
  189. package/dist/plugins/index.d.ts +11 -0
  190. package/dist/plugins/index.d.ts.map +1 -0
  191. package/dist/plugins/index.js +37 -0
  192. package/dist/plugins/load-plugin.d.ts +19 -0
  193. package/dist/plugins/load-plugin.d.ts.map +1 -0
  194. package/dist/plugins/load-plugin.js +59 -0
  195. package/dist/plugins/project-config.d.ts +28 -0
  196. package/dist/plugins/project-config.d.ts.map +1 -0
  197. package/dist/plugins/project-config.js +90 -0
  198. package/dist/plugins/registry.d.ts +94 -0
  199. package/dist/plugins/registry.d.ts.map +1 -0
  200. package/dist/plugins/registry.js +359 -0
  201. package/dist/plugins/resolve-package.d.ts +47 -0
  202. package/dist/plugins/resolve-package.d.ts.map +1 -0
  203. package/dist/plugins/resolve-package.js +262 -0
  204. package/dist/plugins/source-analysis-service.d.ts +44 -0
  205. package/dist/plugins/source-analysis-service.d.ts.map +1 -0
  206. package/dist/plugins/source-analysis-service.js +232 -0
  207. package/dist/prolog/codec.d.ts.map +1 -1
  208. package/dist/prolog/codec.js +2 -0
  209. package/dist/prolog/janitor.d.ts.map +1 -1
  210. package/dist/prolog/janitor.js +1 -1
  211. package/dist/prolog/store-lock.d.ts +1 -1
  212. package/dist/prolog/store-lock.d.ts.map +1 -1
  213. package/dist/prolog.d.ts +36 -0
  214. package/dist/prolog.d.ts.map +1 -1
  215. package/dist/prolog.js +78 -9
  216. package/dist/proof/inspect.js +1 -1
  217. package/dist/proof/producers/playwright-case-id.js +2 -2
  218. package/dist/proof/producers/playwright-reporter.js +4 -4
  219. package/dist/public/diagnostic-usage.d.ts.map +1 -1
  220. package/dist/public/diagnostic-usage.js +7 -25
  221. package/dist/public/extractors/symbols-coordinator.d.ts +1 -1
  222. package/dist/public/extractors/symbols-coordinator.d.ts.map +1 -1
  223. package/dist/public/extractors/symbols-coordinator.js +1 -1
  224. package/dist/public/impact/analyzer.d.ts +1 -1
  225. package/dist/public/impact/analyzer.d.ts.map +1 -1
  226. package/dist/public/impact/analyzer.js +6 -4
  227. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  228. package/dist/public/impact/full-kb-quality.js +4 -12
  229. package/dist/public/operations/catalog.d.ts +39 -7
  230. package/dist/public/operations/catalog.d.ts.map +1 -1
  231. package/dist/public/operations/check-executor.d.ts.map +1 -1
  232. package/dist/public/operations/check-executor.js +11 -3
  233. package/dist/public/operations/check-helpers.d.ts +7 -1
  234. package/dist/public/operations/check-helpers.d.ts.map +1 -1
  235. package/dist/public/operations/check-helpers.js +22 -2
  236. package/dist/public/operations/contracts.d.ts.map +1 -1
  237. package/dist/public/operations/contracts.js +51 -12
  238. package/dist/public/operations/discovery-entities.d.ts +53 -1
  239. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  240. package/dist/public/operations/discovery-entities.js +219 -12
  241. package/dist/public/operations/discovery-executors.d.ts +1 -0
  242. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  243. package/dist/public/operations/discovery-executors.js +93 -59
  244. package/dist/public/operations/migration-plan.d.ts +2 -0
  245. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  246. package/dist/public/operations/migration-plan.js +50 -0
  247. package/dist/public/operations/predicate-schema-conformance.d.ts +41 -0
  248. package/dist/public/operations/predicate-schema-conformance.d.ts.map +1 -0
  249. package/dist/public/operations/predicate-schema-conformance.js +242 -0
  250. package/dist/public/operations/prolog-json.d.ts +1 -1
  251. package/dist/public/operations/prolog-json.d.ts.map +1 -1
  252. package/dist/public/operations/prolog-json.js +16 -10
  253. package/dist/public/operations/result-envelope.d.ts +34 -1
  254. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  255. package/dist/public/operations/result-envelope.js +78 -2
  256. package/dist/public/operations/runtime-types.d.ts +17 -2
  257. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  258. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  259. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  260. package/dist/public/operations/specs/check-rules.generated.js +9 -1
  261. package/dist/public/operations/specs/check.d.ts +1 -1
  262. package/dist/public/operations/specs/discovery.d.ts +10 -1
  263. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  264. package/dist/public/operations/specs/discovery.js +10 -1
  265. package/dist/public/operations/specs/mutation-schemas.d.ts +27 -4
  266. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  267. package/dist/public/operations/specs/mutation-schemas.js +21 -3
  268. package/dist/public/operations/specs/proof.js +1 -1
  269. package/dist/public/operations/specs/reporting.d.ts +9 -0
  270. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  271. package/dist/public/operations/specs/reporting.js +48 -17
  272. package/dist/public/operations/specs/semantic.d.ts +1 -1
  273. package/dist/public/operations/specs/semantic.d.ts.map +1 -1
  274. package/dist/public/operations/specs/semantic.js +54 -4
  275. package/dist/public/operations/specs/upsert.d.ts +28 -5
  276. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  277. package/dist/public/operations/specs/upsert.js +1 -1
  278. package/dist/public/operations/symbol-repair-plan.d.ts.map +1 -1
  279. package/dist/public/operations/symbol-repair-plan.js +11 -4
  280. package/dist/public/operations/types.d.ts +5 -0
  281. package/dist/public/operations/types.d.ts.map +1 -1
  282. package/dist/public/proof-protocol.js +4 -4
  283. package/dist/public/schemas/entity.d.ts.map +1 -1
  284. package/dist/public/schemas/entity.js +22 -0
  285. package/dist/public/schemas/relationship.d.ts.map +1 -1
  286. package/dist/public/schemas/relationship.js +1 -0
  287. package/dist/public/skills/kibi-usage/SKILL.md +10 -3
  288. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
  289. package/dist/public/skills/kibi-usage/resources/proof.md +45 -0
  290. package/dist/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
  291. package/dist/public/skills/kibi-usage/resources/source-authoring.md +36 -0
  292. package/dist/public/skills/kibi-usage/resources/workflows.md +52 -1
  293. package/dist/public/symbol-granularity.d.ts +1 -1
  294. package/dist/public/symbol-granularity.d.ts.map +1 -1
  295. package/dist/public/symbol-granularity.generated.d.ts.map +1 -1
  296. package/dist/public/symbol-granularity.generated.js +38 -5
  297. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  298. package/dist/public/telemetry-acceptance.js +21 -5
  299. package/dist/relationships/shards.d.ts +6 -0
  300. package/dist/relationships/shards.d.ts.map +1 -1
  301. package/dist/relationships/shards.js +26 -19
  302. package/dist/report/html-report.css +1239 -281
  303. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  304. package/dist/runtime/cli-runtime.js +18 -0
  305. package/dist/schemas/entity.schema.json +32 -0
  306. package/dist/traceability/staged-diagnostics.d.ts +1 -1
  307. package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
  308. package/dist/traceability/staged-entity-id-style.d.ts +12 -0
  309. package/dist/traceability/staged-entity-id-style.d.ts.map +1 -0
  310. package/dist/traceability/staged-entity-id-style.js +68 -0
  311. package/dist/traceability/symbol-extract.d.ts +24 -7
  312. package/dist/traceability/symbol-extract.d.ts.map +1 -1
  313. package/dist/traceability/symbol-extract.js +64 -208
  314. package/dist/traceability/temp-kb.d.ts.map +1 -1
  315. package/dist/traceability/temp-kb.js +8 -0
  316. package/dist/traceability/validate.js +1 -1
  317. package/dist/types/entities.d.ts +2 -0
  318. package/dist/types/entities.d.ts.map +1 -1
  319. package/dist/types/relationships.d.ts +1 -1
  320. package/dist/types/relationships.d.ts.map +1 -1
  321. package/dist/utils/entity-id-style.d.ts +27 -0
  322. package/dist/utils/entity-id-style.d.ts.map +1 -0
  323. package/dist/utils/entity-id-style.js +81 -0
  324. package/dist/utils/git-repository-context.d.ts +50 -0
  325. package/dist/utils/git-repository-context.d.ts.map +1 -0
  326. package/dist/utils/git-repository-context.js +259 -0
  327. package/dist/utils/rule-registry.d.ts +5 -0
  328. package/dist/utils/rule-registry.d.ts.map +1 -1
  329. package/dist/utils/rule-registry.generated.d.ts +42 -0
  330. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  331. package/dist/utils/rule-registry.generated.js +50 -0
  332. package/dist/utils/strict-modeling.d.ts +7 -0
  333. package/dist/utils/strict-modeling.d.ts.map +1 -1
  334. package/dist/utils/strict-modeling.js +11 -0
  335. package/package.json +14 -11
  336. package/schema/entities.pl +60 -1
  337. package/schema/relationships.pl +17 -4
  338. package/schema/validation.pl +118 -20
  339. package/src/public/diagnostic-usage.ts +16 -24
  340. package/src/public/extractors/symbols-coordinator.ts +1 -0
  341. package/src/public/impact/analyzer.ts +15 -12
  342. package/src/public/impact/full-kb-quality.ts +4 -16
  343. package/src/public/operations/check-executor.ts +13 -2
  344. package/src/public/operations/check-helpers.ts +29 -3
  345. package/src/public/operations/contracts.ts +59 -12
  346. package/src/public/operations/discovery-entities.ts +327 -12
  347. package/src/public/operations/discovery-executors.ts +110 -61
  348. package/src/public/operations/migration-plan.ts +57 -0
  349. package/src/public/operations/predicate-schema-conformance.ts +362 -0
  350. package/src/public/operations/prolog-json.ts +22 -8
  351. package/src/public/operations/result-envelope.ts +114 -2
  352. package/src/public/operations/runtime-types.ts +22 -3
  353. package/src/public/operations/specs/check-rules.generated.ts +9 -1
  354. package/src/public/operations/specs/discovery.ts +11 -1
  355. package/src/public/operations/specs/mutation-schemas.ts +23 -3
  356. package/src/public/operations/specs/proof.ts +1 -1
  357. package/src/public/operations/specs/reporting.ts +71 -24
  358. package/src/public/operations/specs/semantic.ts +79 -17
  359. package/src/public/operations/specs/upsert.ts +1 -1
  360. package/src/public/operations/symbol-repair-plan.ts +16 -7
  361. package/src/public/operations/types.ts +5 -0
  362. package/src/public/proof-fingerprint.ts +1 -1
  363. package/src/public/proof-protocol-types.d.ts +1 -1
  364. package/src/public/proof-protocol.ts +4 -4
  365. package/src/public/schemas/entity.ts +22 -0
  366. package/src/public/schemas/relationship.ts +1 -0
  367. package/src/public/skills/kibi-usage/SKILL.md +10 -3
  368. package/src/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
  369. package/src/public/skills/kibi-usage/resources/proof.md +45 -0
  370. package/src/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
  371. package/src/public/skills/kibi-usage/resources/source-authoring.md +36 -0
  372. package/src/public/skills/kibi-usage/resources/workflows.md +52 -1
  373. package/src/public/symbol-granularity.generated.ts +45 -12
  374. package/src/public/symbol-granularity.ts +3 -3
  375. package/src/public/telemetry-acceptance.ts +37 -6
  376. package/src/schemas/entity.schema.json +32 -0
  377. package/src/schemas/relationship.schema.json +1 -0
@@ -0,0 +1,359 @@
1
+ /*
2
+ Kibi — repo-local, per-branch, queryable long-term memory for software projects
3
+ Copyright (C) 2026 Piotr Franczyk
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ import { KIBI_PLUGIN_API_VERSION, ONTOLOGY_PACK_CAPABILITY_ID, SEMANTIC_CLASSIFIER_CAPABILITY_ID, SYMBOL_EXTRACTOR_CAPABILITY_ID, VOCABULARY_ALIGNMENT_CAPABILITY_ID, defineKibiPlugin, validateKibiPlugin, } from "kibi-plugin-sdk";
19
+ import { loadPluginPackage } from "./load-plugin.js";
20
+ import { readProjectKibiConfig } from "./project-config.js";
21
+ import { PluginResolutionError } from "./resolve-package.js";
22
+ const CAPABILITY_SLOT = {
23
+ [SEMANTIC_CLASSIFIER_CAPABILITY_ID]: "semanticClassifier",
24
+ [ONTOLOGY_PACK_CAPABILITY_ID]: "ontologyPack",
25
+ [SYMBOL_EXTRACTOR_CAPABILITY_ID]: "symbolExtractor",
26
+ [VOCABULARY_ALIGNMENT_CAPABILITY_ID]: "vocabularyAlignment",
27
+ };
28
+ /**
29
+ * Minimal builtin used when no factory is injected and the builtin package is
30
+ * not yet wired. Satisfies kibi.plugin.v1 validation.
31
+ */
32
+ // implements REQ-capability-plugin-activation-disclosure-v1
33
+ export function createStubBuiltinPlugin() {
34
+ return validateKibiPlugin(defineKibiPlugin({
35
+ apiVersion: KIBI_PLUGIN_API_VERSION,
36
+ id: "kibi-plugin-builtin-stub",
37
+ version: "0.0.0-stub",
38
+ permissions: {
39
+ network: false,
40
+ metered: false,
41
+ secrets: [],
42
+ },
43
+ capabilities: {
44
+ semanticClassifier: {
45
+ id: "kibi-plugin-builtin-stub.classifier",
46
+ classify: () => ({ decisions: [] }),
47
+ },
48
+ ontologyPack: {
49
+ id: "kibi-plugin-builtin-stub.ontology",
50
+ schemas: () => [],
51
+ match: () => [],
52
+ },
53
+ symbolExtractor: {
54
+ id: "kibi-plugin-builtin-stub.symbols",
55
+ supports: () => false,
56
+ analyze: (input) => ({
57
+ sourceFile: input.path,
58
+ language: "unknown",
59
+ module: {
60
+ title: "stub",
61
+ language: "unknown",
62
+ analysisMode: "fallback",
63
+ fallbackReason: "builtin_stub",
64
+ },
65
+ symbols: [],
66
+ }),
67
+ },
68
+ vocabularyAlignment: {
69
+ id: "kibi-plugin-builtin-stub.vocabulary",
70
+ rankSubjects: (input) => ({
71
+ decisions: input.clauses.map((clause) => ({
72
+ claimKey: clause.claimKey,
73
+ choice: "new_subject",
74
+ confidence: 0,
75
+ })),
76
+ }),
77
+ compareClaims: (input) => ({
78
+ judgments: input.pairs.map((pair) => ({
79
+ pairKey: pair.pairKey,
80
+ sameObligation: false,
81
+ confidence: 0,
82
+ })),
83
+ }),
84
+ },
85
+ },
86
+ }));
87
+ }
88
+ /** Default host builtin from the published kibi-plugin-builtin package. */
89
+ async function defaultBuiltinFactory() {
90
+ const mod = (await import("kibi-plugin-builtin"));
91
+ const plugin = mod.kibiPlugin;
92
+ if (!plugin) {
93
+ throw new Error("kibi-plugin-builtin did not export kibiPlugin");
94
+ }
95
+ const validated = validateKibiPlugin(plugin);
96
+ let packageVersion = validated.version;
97
+ try {
98
+ const { createRequire } = await import("node:module");
99
+ const require = createRequire(import.meta.url);
100
+ const builtinPackageJson = require("kibi-plugin-builtin/package.json");
101
+ if (typeof builtinPackageJson.version === "string" &&
102
+ builtinPackageJson.version.trim()) {
103
+ packageVersion = builtinPackageJson.version.trim();
104
+ }
105
+ }
106
+ catch {
107
+ // Fall back to the export version when package.json is not resolvable.
108
+ }
109
+ if (validated.version !== packageVersion) {
110
+ throw new Error(`kibi-plugin-builtin export version '${validated.version}' does not match package.json version '${packageVersion}'`);
111
+ }
112
+ return { ...validated, version: packageVersion };
113
+ }
114
+ // implements REQ-capability-plugin-activation-disclosure-v1
115
+ function stampFor(plugin, capability, mode, external, model) {
116
+ return {
117
+ pluginId: plugin.id,
118
+ pluginVersion: plugin.version,
119
+ capability,
120
+ mode: mode === "builtin" ? "augment" : mode,
121
+ external,
122
+ network: plugin.permissions.network,
123
+ metered: plugin.permissions.metered,
124
+ ...(model !== undefined ? { model } : {}),
125
+ };
126
+ }
127
+ // implements REQ-capability-plugin-activation-disclosure-v1
128
+ function disclosedModel(capability) {
129
+ if (typeof capability !== "object" || capability === null)
130
+ return undefined;
131
+ if (!("model" in capability))
132
+ return undefined;
133
+ const model = capability.model;
134
+ return typeof model === "string" && model.trim() !== ""
135
+ ? model.trim()
136
+ : undefined;
137
+ }
138
+ function bindingFor(plugin, packageName, mode, capabilityId, capability) {
139
+ const external = packageName !== null;
140
+ return {
141
+ pluginId: plugin.id,
142
+ pluginVersion: plugin.version,
143
+ packageName,
144
+ mode,
145
+ permissions: plugin.permissions,
146
+ external,
147
+ capability,
148
+ stamp: stampFor(plugin, capabilityId, mode, external, disclosedModel(capability)),
149
+ };
150
+ }
151
+ function capabilityFromPlugin(plugin, capabilityId) {
152
+ const slot = CAPABILITY_SLOT[capabilityId];
153
+ return plugin.capabilities[slot];
154
+ }
155
+ /**
156
+ * Per-workspace capability registry. Builtin providers are always present;
157
+ * configured packages load lazily the first time a capability is resolved.
158
+ * Not a process-wide singleton — inject or construct per test/runtime.
159
+ */
160
+ // implements REQ-capability-plugin-activation-disclosure-v1, REQ-capability-plugin-observable-behavior-v1
161
+ export class CapabilityRegistry {
162
+ workspaceRoot;
163
+ builtinFactory;
164
+ readConfig;
165
+ loadPlugin;
166
+ loadPluginOptions;
167
+ injectedConfig;
168
+ builtinPluginPromise;
169
+ configPromise;
170
+ loadedPackages = new Map();
171
+ capabilityCache = new Map();
172
+ constructor(options) {
173
+ this.workspaceRoot = options.workspaceRoot;
174
+ this.builtinFactory = options.builtinFactory ?? defaultBuiltinFactory;
175
+ this.readConfig = options.readConfig ?? readProjectKibiConfig;
176
+ this.loadPlugin = options.loadPlugin ?? loadPluginPackage;
177
+ this.loadPluginOptions = options.loadPluginOptions;
178
+ this.injectedConfig = options.projectConfig;
179
+ }
180
+ async getBuiltinPlugin() {
181
+ this.builtinPluginPromise ??= Promise.resolve(this.builtinFactory()).then((plugin) => validateKibiPlugin(plugin));
182
+ return this.builtinPluginPromise;
183
+ }
184
+ async getProjectConfig() {
185
+ if (this.injectedConfig !== undefined) {
186
+ return this.injectedConfig;
187
+ }
188
+ this.configPromise ??= Promise.resolve(this.readConfig(this.workspaceRoot));
189
+ return this.configPromise;
190
+ }
191
+ async resolveSemanticClassifiers() {
192
+ return this.resolveCapability(SEMANTIC_CLASSIFIER_CAPABILITY_ID);
193
+ }
194
+ async resolveOntologyPacks() {
195
+ return this.resolveCapability(ONTOLOGY_PACK_CAPABILITY_ID);
196
+ }
197
+ async resolveSymbolExtractors() {
198
+ return this.resolveCapability(SYMBOL_EXTRACTOR_CAPABILITY_ID);
199
+ }
200
+ async resolveVocabularyAlignment() {
201
+ return this.resolveCapability(VOCABULARY_ALIGNMENT_CAPABILITY_ID);
202
+ }
203
+ async resolveCapability(capabilityId) {
204
+ const cached = this.capabilityCache.get(capabilityId);
205
+ if (cached)
206
+ return cached;
207
+ const promise = this.buildCapabilityResolution(capabilityId);
208
+ this.capabilityCache.set(capabilityId, promise);
209
+ try {
210
+ return await promise;
211
+ }
212
+ catch (error) {
213
+ this.capabilityCache.delete(capabilityId);
214
+ throw error;
215
+ }
216
+ }
217
+ /**
218
+ * Canonical providers only (builtin + optional replace + augment).
219
+ * Shadow bindings are excluded.
220
+ */
221
+ canonicalProviders(resolution) {
222
+ if (resolution.replace) {
223
+ return [resolution.replace, ...resolution.augment];
224
+ }
225
+ return [resolution.builtin, ...resolution.augment];
226
+ }
227
+ async buildCapabilityResolution(capabilityId) {
228
+ const builtinPlugin = await this.getBuiltinPlugin();
229
+ const builtinCapability = capabilityFromPlugin(builtinPlugin, capabilityId);
230
+ if (!builtinCapability) {
231
+ throw new PluginResolutionError("BUILTIN_MISSING_CAPABILITY", `Builtin plugin '${builtinPlugin.id}' does not provide ${capabilityId}`);
232
+ }
233
+ const builtin = bindingFor(builtinPlugin, null, "builtin", capabilityId, builtinCapability);
234
+ const config = await this.getProjectConfig();
235
+ const entries = config.plugins ?? [];
236
+ const relevant = entries.filter((entry) => entry.capabilities[capabilityId] !== undefined);
237
+ let replace = null;
238
+ const augment = [];
239
+ const shadow = [];
240
+ const pluginIds = new Map([
241
+ [builtinPlugin.id, "kibi-plugin-builtin"],
242
+ ]);
243
+ const providerIds = new Set([
244
+ capabilityFromPlugin(builtinPlugin, capabilityId)?.id ?? builtinPlugin.id,
245
+ ]);
246
+ for (const entry of relevant) {
247
+ const modeConfig = entry.capabilities[capabilityId];
248
+ if (!modeConfig)
249
+ continue;
250
+ const loaded = await this.ensurePackageLoaded(entry);
251
+ const owner = pluginIds.get(loaded.plugin.id);
252
+ if (owner !== undefined && owner !== entry.package) {
253
+ throw new PluginResolutionError("DUPLICATE_PLUGIN_ID", `Plugin id '${loaded.plugin.id}' is claimed by both '${owner}' and '${entry.package}'`);
254
+ }
255
+ pluginIds.set(loaded.plugin.id, entry.package);
256
+ const capability = capabilityFromPlugin(loaded.plugin, capabilityId);
257
+ if (!capability) {
258
+ throw new PluginResolutionError("PLUGIN_MISSING_CAPABILITY", `Plugin package '${entry.package}' is activated for ${capabilityId} but does not export that capability`);
259
+ }
260
+ if ("id" in capability && typeof capability.id === "string") {
261
+ if (providerIds.has(capability.id)) {
262
+ throw new PluginResolutionError("DUPLICATE_PROVIDER_ID", `Provider id '${capability.id}' for ${capabilityId} is not unique`);
263
+ }
264
+ providerIds.add(capability.id);
265
+ }
266
+ const binding = bindingFor(loaded.plugin, entry.package, modeConfig.mode, capabilityId, capability);
267
+ if (modeConfig.mode === "replace") {
268
+ if (replace !== null) {
269
+ throw new PluginResolutionError("MULTIPLE_REPLACE_PROVIDERS", `At most one replace provider is allowed for ${capabilityId}; both '${replace.packageName}' and '${entry.package}' requested replace`);
270
+ }
271
+ replace = binding;
272
+ }
273
+ else if (modeConfig.mode === "augment") {
274
+ augment.push(binding);
275
+ }
276
+ else {
277
+ shadow.push(binding);
278
+ }
279
+ }
280
+ return { builtin, replace, augment, shadow };
281
+ }
282
+ async ensurePackageLoaded(entry) {
283
+ const existing = this.loadedPackages.get(entry.package);
284
+ if (existing)
285
+ return existing;
286
+ const loadOptions = this.loadPluginOptions;
287
+ const promise = this.loadPlugin(this.workspaceRoot, entry.package, loadOptions);
288
+ this.loadedPackages.set(entry.package, promise);
289
+ try {
290
+ return await promise;
291
+ }
292
+ catch (error) {
293
+ if (this.loadedPackages.get(entry.package) === promise) {
294
+ this.loadedPackages.delete(entry.package);
295
+ }
296
+ throw error;
297
+ }
298
+ }
299
+ }
300
+ /**
301
+ * Explicit cache keyed by workspace root. Injectable — not a hidden global.
302
+ */
303
+ // implements REQ-capability-plugin-activation-disclosure-v1
304
+ export class CapabilityRegistryCache {
305
+ registries = new Map();
306
+ get(workspaceRoot) {
307
+ return this.registries.get(workspaceRoot);
308
+ }
309
+ getOrCreate(workspaceRoot, options) {
310
+ const existing = this.registries.get(workspaceRoot);
311
+ if (existing)
312
+ return existing;
313
+ const registry = new CapabilityRegistry({
314
+ workspaceRoot,
315
+ ...options,
316
+ });
317
+ this.registries.set(workspaceRoot, registry);
318
+ return registry;
319
+ }
320
+ set(workspaceRoot, registry) {
321
+ this.registries.set(workspaceRoot, registry);
322
+ }
323
+ clear() {
324
+ this.registries.clear();
325
+ }
326
+ }
327
+ // implements REQ-capability-plugin-activation-disclosure-v1
328
+ export function createCapabilityRegistry(options) {
329
+ return new CapabilityRegistry(options);
330
+ }
331
+ // implements REQ-capability-plugin-activation-disclosure-v1
332
+ export function createCapabilityRegistryCache() {
333
+ return new CapabilityRegistryCache();
334
+ }
335
+ /**
336
+ * Lazily construct and cache a registry per workspace root.
337
+ * Callers should supply a cache instance — there is no process-global store.
338
+ */
339
+ // implements REQ-capability-plugin-activation-disclosure-v1
340
+ export function ensureCapabilityRegistry(workspaceRootOrOptions, options) {
341
+ if (typeof workspaceRootOrOptions === "string") {
342
+ const { cache, ...registryOptions } = options ?? {};
343
+ if (cache) {
344
+ return cache.getOrCreate(workspaceRootOrOptions, registryOptions);
345
+ }
346
+ return new CapabilityRegistry({
347
+ workspaceRoot: workspaceRootOrOptions,
348
+ ...registryOptions,
349
+ });
350
+ }
351
+ const { workspaceRoot, cache, ...registryOptions } = workspaceRootOrOptions;
352
+ if (cache) {
353
+ return cache.getOrCreate(workspaceRoot, registryOptions);
354
+ }
355
+ return new CapabilityRegistry({
356
+ workspaceRoot,
357
+ ...registryOptions,
358
+ });
359
+ }
@@ -0,0 +1,47 @@
1
+ import { PluginValidationError } from "kibi-plugin-sdk";
2
+ import { type ProjectPackageManifest } from "./project-config.js";
3
+ export declare class PluginResolutionError extends Error {
4
+ readonly code: string;
5
+ constructor(code: string, message: string);
6
+ }
7
+ export type ResolvedProjectPackage = Readonly<{
8
+ packageName: string;
9
+ packageRoot: string;
10
+ packageJsonPath: string;
11
+ packageJson: ProjectPackageManifest & Readonly<Record<string, unknown>>;
12
+ /** Absolute filesystem path of the package entry used for dynamic import. */
13
+ entryPath: string;
14
+ /** file:// URL for dynamic import. */
15
+ entryUrl: string;
16
+ }>;
17
+ /**
18
+ * Bare npm package names only. Paths, URLs, subpaths, and aliases are rejected.
19
+ */
20
+ export declare function isBarePackageName(packageName: string): boolean;
21
+ export declare function assertBarePackageName(packageName: string): void;
22
+ export declare function hasDeclaredProjectDependency(workspaceRoot: string, packageName: string, manifest?: ProjectPackageManifest): boolean;
23
+ export declare function hasConsumerNodeModulesLink(workspaceRoot: string, packageName: string, packageRoot: string): boolean;
24
+ /**
25
+ * Same project-scope policy as packages/cursor/bin/launch-kibi-mcp.mjs:
26
+ * within workspace OR node_modules symlink OR Yarn PnP active resolver.
27
+ * Rejects NODE_PATH / global / ambient packages.
28
+ */
29
+ export declare function isProjectScopedPackage(workspaceRoot: string, packageName: string, packageRoot: string): boolean;
30
+ export declare function packageJsonForResolvedFile(startPath: string, expectedPackageName: string): {
31
+ packageJsonPath: string;
32
+ packageRoot: string;
33
+ packageJson: ProjectPackageManifest & Readonly<Record<string, unknown>>;
34
+ } | null;
35
+ /**
36
+ * Confine a resolved entry to the realpath'd package root. Rejects
37
+ * `exports`/`main` traversal and symlink escapes.
38
+ */
39
+ export declare function assertResolvedEntryInsidePackageRoot(packageRoot: string, entryPath: string): string;
40
+ /**
41
+ * Resolve a declared project-local plugin package through the workspace
42
+ * package.json require graph. NODE_PATH / global / path / URL references fail.
43
+ */
44
+ export declare function resolveProjectLocalPackage(workspaceRoot: string, packageName: string): ResolvedProjectPackage;
45
+ /** Re-export for callers that catch SDK validation failures as resolution errors. */
46
+ export { PluginValidationError };
47
+ //# sourceMappingURL=resolve-package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-package.d.ts","sourceRoot":"","sources":["../../src/plugins/resolve-package.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,qBAAqB,CAAC;AAG7B,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAGD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAmBH;;GAEG;AAEH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAoB9D;AAGD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAO/D;AAGD,wBAAgB,4BAA4B,CAC1C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,OAAO,CAaT;AAGD,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAeT;AAED;;;;GAIG;AAEH,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAMT;AAGD,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,mBAAmB,EAAE,MAAM,GAC1B;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzE,GAAG,IAAI,CA0BP;AAED;;;GAGG;AAEH,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,MAAM,CAoCR;AA0DD;;;GAGG;AAEH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,sBAAsB,CAgExB;AAED,qFAAqF;AACrF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,262 @@
1
+ /*
2
+ Kibi — repo-local, per-branch, queryable long-term memory for software projects
3
+ Copyright (C) 2026 Piotr Franczyk
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ import * as fs from "node:fs";
19
+ import { createRequire } from "node:module";
20
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
21
+ import { pathToFileURL } from "node:url";
22
+ import { PluginValidationError } from "kibi-plugin-sdk";
23
+ import { readProjectPackageJson, } from "./project-config.js";
24
+ // implements REQ-capability-plugin-activation-disclosure-v1
25
+ export class PluginResolutionError extends Error {
26
+ code;
27
+ constructor(code, message) {
28
+ super(message);
29
+ this.name = "PluginResolutionError";
30
+ this.code = code;
31
+ }
32
+ }
33
+ function readJson(path) {
34
+ return JSON.parse(fs.readFileSync(path, "utf8"));
35
+ }
36
+ function nextAncestorDirectory(current) {
37
+ const parent = dirname(current);
38
+ return parent === current ? undefined : parent;
39
+ }
40
+ function isWithinRoot(rootPath, candidatePath) {
41
+ const relativePath = relative(resolve(rootPath), resolve(candidatePath));
42
+ return (relativePath === "" ||
43
+ (!relativePath.startsWith("..") && !isAbsolute(relativePath)));
44
+ }
45
+ /**
46
+ * Bare npm package names only. Paths, URLs, subpaths, and aliases are rejected.
47
+ */
48
+ // implements REQ-capability-plugin-activation-disclosure-v1
49
+ export function isBarePackageName(packageName) {
50
+ const trimmed = packageName.trim();
51
+ if (!trimmed || trimmed !== packageName)
52
+ return false;
53
+ if (trimmed.startsWith(".") ||
54
+ trimmed.startsWith("/") ||
55
+ trimmed.includes(":") ||
56
+ trimmed.includes("\\") ||
57
+ trimmed.includes("..")) {
58
+ return false;
59
+ }
60
+ // Reject subpath imports (`pkg/sub`) and Windows drive paths.
61
+ if (trimmed.includes("/") && !trimmed.startsWith("@"))
62
+ return false;
63
+ if (trimmed.startsWith("@")) {
64
+ const parts = trimmed.split("/");
65
+ if (parts.length !== 2 || !parts[0] || !parts[1])
66
+ return false;
67
+ if (parts[1].includes("/"))
68
+ return false;
69
+ }
70
+ return true;
71
+ }
72
+ // implements REQ-capability-plugin-activation-disclosure-v1, REQ-capability-plugin-observable-behavior-v1
73
+ export function assertBarePackageName(packageName) {
74
+ if (!isBarePackageName(packageName)) {
75
+ throw new PluginResolutionError("INVALID_PACKAGE_REFERENCE", `Plugin package '${packageName}' must be a bare package name; paths, URLs, and subpaths are rejected`);
76
+ }
77
+ }
78
+ // implements REQ-capability-plugin-activation-disclosure-v1, REQ-capability-plugin-observable-behavior-v1
79
+ export function hasDeclaredProjectDependency(workspaceRoot, packageName, manifest) {
80
+ const packageJson = manifest ?? readProjectPackageJson(workspaceRoot);
81
+ return [
82
+ packageJson.dependencies,
83
+ packageJson.devDependencies,
84
+ packageJson.optionalDependencies,
85
+ ].some((dependencies) => Boolean(dependencies &&
86
+ typeof dependencies === "object" &&
87
+ dependencies[packageName]));
88
+ }
89
+ // implements REQ-capability-plugin-activation-disclosure-v1
90
+ export function hasConsumerNodeModulesLink(workspaceRoot, packageName, packageRoot) {
91
+ try {
92
+ const linkPath = join(workspaceRoot, "node_modules", ...packageName.split("/"));
93
+ const linkedRoot = fs.realpathSync(linkPath);
94
+ return (isWithinRoot(linkedRoot, packageRoot) ||
95
+ isWithinRoot(packageRoot, linkedRoot));
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ }
101
+ /**
102
+ * Same project-scope policy as packages/cursor/bin/launch-kibi-mcp.mjs:
103
+ * within workspace OR node_modules symlink OR Yarn PnP active resolver.
104
+ * Rejects NODE_PATH / global / ambient packages.
105
+ */
106
+ // implements REQ-capability-plugin-activation-disclosure-v1, REQ-capability-plugin-observable-behavior-v1
107
+ export function isProjectScopedPackage(workspaceRoot, packageName, packageRoot) {
108
+ if (isWithinRoot(workspaceRoot, packageRoot))
109
+ return true;
110
+ return (hasConsumerNodeModulesLink(workspaceRoot, packageName, packageRoot) ||
111
+ Boolean(process.versions.pnp));
112
+ }
113
+ // implements REQ-capability-plugin-activation-disclosure-v1
114
+ export function packageJsonForResolvedFile(startPath, expectedPackageName) {
115
+ let current = resolve(startPath);
116
+ try {
117
+ if (!fs.statSync(current).isDirectory())
118
+ current = dirname(current);
119
+ }
120
+ catch {
121
+ current = dirname(current);
122
+ }
123
+ let cursor = current;
124
+ while (cursor !== undefined) {
125
+ const packageJsonPath = join(cursor, "package.json");
126
+ if (fs.existsSync(packageJsonPath)) {
127
+ try {
128
+ const packageJson = readJson(packageJsonPath);
129
+ if (packageJson.name === expectedPackageName) {
130
+ return { packageJsonPath, packageRoot: cursor, packageJson };
131
+ }
132
+ }
133
+ catch {
134
+ // Keep walking if a parent package manifest is malformed.
135
+ }
136
+ }
137
+ cursor = nextAncestorDirectory(cursor);
138
+ }
139
+ return null;
140
+ }
141
+ /**
142
+ * Confine a resolved entry to the realpath'd package root. Rejects
143
+ * `exports`/`main` traversal and symlink escapes.
144
+ */
145
+ // implements REQ-capability-plugin-activation-disclosure-v1
146
+ export function assertResolvedEntryInsidePackageRoot(packageRoot, entryPath) {
147
+ let realRoot;
148
+ try {
149
+ realRoot = fs.realpathSync(packageRoot);
150
+ }
151
+ catch {
152
+ throw new PluginResolutionError("PACKAGE_NOT_FOUND", `Plugin package root '${packageRoot}' is not readable`);
153
+ }
154
+ let realEntry;
155
+ try {
156
+ const stats = fs.statSync(entryPath);
157
+ if (!stats.isFile()) {
158
+ throw new PluginResolutionError("PACKAGE_ENTRY_NOT_FILE", `Plugin package entry '${entryPath}' is not a regular file`);
159
+ }
160
+ realEntry = fs.realpathSync(entryPath);
161
+ }
162
+ catch (error) {
163
+ if (error instanceof PluginResolutionError)
164
+ throw error;
165
+ throw new PluginResolutionError("PACKAGE_ENTRY_NOT_FOUND", `Plugin package entry '${entryPath}' does not exist`);
166
+ }
167
+ if (!isWithinRoot(realRoot, realEntry)) {
168
+ throw new PluginResolutionError("PACKAGE_ENTRY_OUTSIDE_ROOT", `Resolved plugin entry '${realEntry}' is outside package root '${realRoot}'`);
169
+ }
170
+ return realEntry;
171
+ }
172
+ function candidateFromManifest(packageJson) {
173
+ const exportsField = packageJson.exports;
174
+ if (typeof exportsField === "string")
175
+ return exportsField;
176
+ if (exportsField &&
177
+ typeof exportsField === "object" &&
178
+ !Array.isArray(exportsField)) {
179
+ const rootExport = exportsField["."];
180
+ if (typeof rootExport === "string")
181
+ return rootExport;
182
+ if (rootExport &&
183
+ typeof rootExport === "object" &&
184
+ !Array.isArray(rootExport)) {
185
+ const conditional = rootExport;
186
+ if (typeof conditional.import === "string")
187
+ return conditional.import;
188
+ if (typeof conditional.default === "string")
189
+ return conditional.default;
190
+ if (typeof conditional.require === "string")
191
+ return conditional.require;
192
+ }
193
+ }
194
+ if (typeof packageJson.module === "string")
195
+ return packageJson.module;
196
+ if (typeof packageJson.main === "string")
197
+ return packageJson.main;
198
+ return undefined;
199
+ }
200
+ function resolvePackageEntryWithNode(packageRoot, packageJson, packageName, consumerRequire) {
201
+ let resolved;
202
+ try {
203
+ resolved = consumerRequire.resolve(packageName);
204
+ }
205
+ catch {
206
+ resolved = undefined;
207
+ }
208
+ if (resolved === undefined) {
209
+ const candidate = candidateFromManifest(packageJson);
210
+ if (candidate) {
211
+ resolved = resolve(packageRoot, candidate);
212
+ }
213
+ }
214
+ if (resolved === undefined) {
215
+ throw new PluginResolutionError("PACKAGE_ENTRY_NOT_FOUND", `Node could not resolve the root export of '${packageName}' from ${packageRoot}`);
216
+ }
217
+ const entryPath = assertResolvedEntryInsidePackageRoot(packageRoot, resolved);
218
+ return { entryPath, entryUrl: pathToFileURL(entryPath).href };
219
+ }
220
+ /**
221
+ * Resolve a declared project-local plugin package through the workspace
222
+ * package.json require graph. NODE_PATH / global / path / URL references fail.
223
+ */
224
+ // implements REQ-capability-plugin-activation-disclosure-v1
225
+ export function resolveProjectLocalPackage(workspaceRoot, packageName) {
226
+ assertBarePackageName(packageName);
227
+ const root = resolve(workspaceRoot);
228
+ const manifest = readProjectPackageJson(root);
229
+ if (!hasDeclaredProjectDependency(root, packageName, manifest)) {
230
+ throw new PluginResolutionError("UNDECLARED_DEPENDENCY", `Plugin package '${packageName}' must be listed in dependencies, devDependencies, or optionalDependencies of ${join(root, "package.json")}`);
231
+ }
232
+ const consumerRequire = createRequire(join(root, "package.json"));
233
+ let packageInfo = null;
234
+ try {
235
+ packageInfo = packageJsonForResolvedFile(consumerRequire.resolve(`${packageName}/package.json`), packageName);
236
+ }
237
+ catch {
238
+ try {
239
+ packageInfo = packageJsonForResolvedFile(consumerRequire.resolve(packageName), packageName);
240
+ }
241
+ catch {
242
+ packageInfo = null;
243
+ }
244
+ }
245
+ if (!packageInfo) {
246
+ throw new PluginResolutionError("PACKAGE_NOT_FOUND", `No project-local package '${packageName}' was found for ${root}. Install it in that workspace and retry.`);
247
+ }
248
+ if (!isProjectScopedPackage(root, packageName, packageInfo.packageRoot)) {
249
+ throw new PluginResolutionError("PACKAGE_OUTSIDE_WORKSPACE", `Resolved '${packageName}' outside the consumer workspace: ${packageInfo.packageRoot}. Install it in ${root}; global, NODE_PATH, and ambient packages are not supported.`);
250
+ }
251
+ const { entryPath, entryUrl } = resolvePackageEntryWithNode(packageInfo.packageRoot, packageInfo.packageJson, packageName, consumerRequire);
252
+ return {
253
+ packageName,
254
+ packageRoot: packageInfo.packageRoot,
255
+ packageJsonPath: packageInfo.packageJsonPath,
256
+ packageJson: packageInfo.packageJson,
257
+ entryPath,
258
+ entryUrl,
259
+ };
260
+ }
261
+ /** Re-export for callers that catch SDK validation failures as resolution errors. */
262
+ export { PluginValidationError };