kibi-cli 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/dist/cli-json-command.d.ts +6 -0
  2. package/dist/cli-json-command.d.ts.map +1 -1
  3. package/dist/cli-json-command.js +37 -9
  4. package/dist/cli-operation-loader.d.ts.map +1 -1
  5. package/dist/cli-operation-loader.js +7 -0
  6. package/dist/cli-operation-metadata.d.ts +12 -4
  7. package/dist/cli-operation-metadata.d.ts.map +1 -1
  8. package/dist/cli-operation-metadata.js +14 -4
  9. package/dist/cli-protocol.d.ts +14 -0
  10. package/dist/cli-protocol.d.ts.map +1 -1
  11. package/dist/cli-protocol.js +31 -2
  12. package/dist/cli-register-proof.d.ts.map +1 -1
  13. package/dist/cli-register-proof.js +13 -0
  14. package/dist/commands/check.d.ts.map +1 -1
  15. package/dist/commands/check.js +11 -2
  16. package/dist/commands/discovery-shared.d.ts.map +1 -1
  17. package/dist/commands/discovery-shared.js +8 -2
  18. package/dist/commands/engine.d.ts.map +1 -1
  19. package/dist/commands/engine.js +4 -2
  20. package/dist/commands/gc.d.ts.map +1 -1
  21. package/dist/commands/gc.js +7 -0
  22. package/dist/commands/init-helpers.d.ts.map +1 -1
  23. package/dist/commands/init-helpers.js +38 -12
  24. package/dist/commands/init.d.ts.map +1 -1
  25. package/dist/commands/init.js +10 -15
  26. package/dist/commands/migrate.d.ts.map +1 -1
  27. package/dist/commands/migrate.js +281 -14
  28. package/dist/commands/proof-compact.d.ts +9 -0
  29. package/dist/commands/proof-compact.d.ts.map +1 -0
  30. package/dist/commands/proof-compact.js +58 -0
  31. package/dist/commands/prove.d.ts +38 -0
  32. package/dist/commands/prove.d.ts.map +1 -1
  33. package/dist/commands/prove.js +222 -47
  34. package/dist/commands/sync/persistence.d.ts.map +1 -1
  35. package/dist/commands/sync/persistence.js +61 -16
  36. package/dist/commands/sync.d.ts +8 -0
  37. package/dist/commands/sync.d.ts.map +1 -1
  38. package/dist/commands/sync.js +42 -16
  39. package/dist/diagnostics.js +1 -1
  40. package/dist/engine-limits.d.ts +74 -0
  41. package/dist/engine-limits.d.ts.map +1 -0
  42. package/dist/engine-limits.js +201 -0
  43. package/dist/engine.d.ts +10 -0
  44. package/dist/engine.d.ts.map +1 -1
  45. package/dist/engine.js +57 -9
  46. package/dist/extractors/manifest.d.ts +8 -0
  47. package/dist/extractors/manifest.d.ts.map +1 -1
  48. package/dist/extractors/manifest.js +34 -5
  49. package/dist/extractors/markdown.d.ts +8 -0
  50. package/dist/extractors/markdown.d.ts.map +1 -1
  51. package/dist/extractors/markdown.js +57 -0
  52. package/dist/extractors/relationships.d.ts.map +1 -1
  53. package/dist/extractors/relationships.js +2 -0
  54. package/dist/intent-search.d.ts +4 -1
  55. package/dist/intent-search.d.ts.map +1 -1
  56. package/dist/intent-search.js +186 -33
  57. package/dist/operations/bootstrap/candidate-helpers.d.ts.map +1 -1
  58. package/dist/operations/bootstrap/candidate-helpers.js +8 -1
  59. package/dist/operations/bootstrap/candidates.d.ts.map +1 -1
  60. package/dist/operations/bootstrap/candidates.js +54 -38
  61. package/dist/operations/bootstrap/generate.d.ts +2 -0
  62. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  63. package/dist/operations/bootstrap/generate.js +87 -33
  64. package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -1
  65. package/dist/operations/bootstrap/intent-claims.js +12 -4
  66. package/dist/operations/bootstrap/markdown-candidates.d.ts +2 -0
  67. package/dist/operations/bootstrap/markdown-candidates.d.ts.map +1 -1
  68. package/dist/operations/bootstrap/markdown-candidates.js +32 -10
  69. package/dist/operations/bootstrap/presentation.d.ts.map +1 -1
  70. package/dist/operations/bootstrap/presentation.js +6 -2
  71. package/dist/operations/bootstrap/requirement-claims.d.ts +1 -0
  72. package/dist/operations/bootstrap/requirement-claims.d.ts.map +1 -1
  73. package/dist/operations/bootstrap/requirement-claims.js +13 -1
  74. package/dist/operations/bootstrap/validation.d.ts +4 -0
  75. package/dist/operations/bootstrap/validation.d.ts.map +1 -0
  76. package/dist/operations/bootstrap/validation.js +20 -0
  77. package/dist/operations/migration/inventory-rederive.d.ts +81 -0
  78. package/dist/operations/migration/inventory-rederive.d.ts.map +1 -0
  79. package/dist/operations/migration/inventory-rederive.js +484 -0
  80. package/dist/operations/migration/kb-sources.d.ts +53 -0
  81. package/dist/operations/migration/kb-sources.d.ts.map +1 -0
  82. package/dist/operations/migration/kb-sources.js +233 -0
  83. package/dist/operations/migration/origin-backfill.d.ts +39 -0
  84. package/dist/operations/migration/origin-backfill.d.ts.map +1 -0
  85. package/dist/operations/migration/origin-backfill.js +164 -0
  86. package/dist/operations/migration/polarity-values.d.ts +10 -0
  87. package/dist/operations/migration/polarity-values.d.ts.map +1 -0
  88. package/dist/operations/migration/polarity-values.js +60 -0
  89. package/dist/operations/migration/schema6.d.ts +59 -0
  90. package/dist/operations/migration/schema6.d.ts.map +1 -0
  91. package/dist/operations/migration/schema6.js +379 -0
  92. package/dist/operations/migration/source-paths.d.ts +131 -0
  93. package/dist/operations/migration/source-paths.d.ts.map +1 -0
  94. package/dist/operations/migration/source-paths.js +308 -0
  95. package/dist/operations/migration/superseded-closure.d.ts +54 -0
  96. package/dist/operations/migration/superseded-closure.d.ts.map +1 -0
  97. package/dist/operations/migration/superseded-closure.js +187 -0
  98. package/dist/operations/modeling/logic-modeling.d.ts.map +1 -1
  99. package/dist/operations/modeling/logic-modeling.js +3 -5
  100. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  101. package/dist/operations/modeling/model-requirement.js +225 -67
  102. package/dist/operations/mutation/contradictions.d.ts +16 -0
  103. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  104. package/dist/operations/mutation/contradictions.js +32 -0
  105. package/dist/operations/mutation/delete.d.ts.map +1 -1
  106. package/dist/operations/mutation/delete.js +15 -7
  107. package/dist/operations/mutation/origin.d.ts +21 -0
  108. package/dist/operations/mutation/origin.d.ts.map +1 -0
  109. package/dist/operations/mutation/origin.js +78 -0
  110. package/dist/operations/mutation/plan-apply-journal.d.ts +182 -0
  111. package/dist/operations/mutation/plan-apply-journal.d.ts.map +1 -0
  112. package/dist/operations/mutation/plan-apply-journal.js +613 -0
  113. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +3 -1
  114. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -1
  115. package/dist/operations/mutation/predicate-vocabulary-guard.js +13 -2
  116. package/dist/operations/mutation/relationships.d.ts +5 -5
  117. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  118. package/dist/operations/mutation/relationships.js +31 -11
  119. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  120. package/dist/operations/mutation/serialization.js +3 -1
  121. package/dist/operations/mutation/source-authoring.d.ts +6 -0
  122. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  123. package/dist/operations/mutation/source-authoring.js +7 -1
  124. package/dist/operations/mutation/types.d.ts +14 -0
  125. package/dist/operations/mutation/types.d.ts.map +1 -1
  126. package/dist/operations/mutation/upsert.d.ts +30 -3
  127. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  128. package/dist/operations/mutation/upsert.js +105 -35
  129. package/dist/operations/mutation/validate-upsert.d.ts +6 -0
  130. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  131. package/dist/operations/mutation/validate-upsert.js +34 -30
  132. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  133. package/dist/operations/planning/apply-plan.js +753 -145
  134. package/dist/operations/planning/compile-intent.d.ts +34 -1
  135. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  136. package/dist/operations/planning/compile-intent.js +314 -98
  137. package/dist/operations/proof/code-scope.d.ts +28 -0
  138. package/dist/operations/proof/code-scope.d.ts.map +1 -1
  139. package/dist/operations/proof/code-scope.js +72 -0
  140. package/dist/operations/proof/compact-receipts.d.ts +49 -0
  141. package/dist/operations/proof/compact-receipts.d.ts.map +1 -0
  142. package/dist/operations/proof/compact-receipts.js +160 -0
  143. package/dist/operations/proof/ingest-proof.d.ts +2 -0
  144. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  145. package/dist/operations/proof/ingest-proof.js +44 -23
  146. package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
  147. package/dist/operations/proof/prune-receipts.js +5 -9
  148. package/dist/operations/proof/receipt-compaction.d.ts +48 -0
  149. package/dist/operations/proof/receipt-compaction.d.ts.map +1 -0
  150. package/dist/operations/proof/receipt-compaction.js +121 -0
  151. package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
  152. package/dist/operations/semantic-advisor/analysis-receipt.js +12 -1
  153. package/dist/operations/semantic-advisor/analyze-prose.d.ts +2 -1
  154. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  155. package/dist/operations/semantic-advisor/analyze-prose.js +51 -5
  156. package/dist/operations/semantic-advisor/clauses.d.ts +1 -0
  157. package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
  158. package/dist/operations/semantic-advisor/clauses.js +11 -1
  159. package/dist/operations/semantic-advisor/conditional-rules.d.ts +33 -0
  160. package/dist/operations/semantic-advisor/conditional-rules.d.ts.map +1 -0
  161. package/dist/operations/semantic-advisor/conditional-rules.js +262 -0
  162. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +3 -1
  163. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
  164. package/dist/operations/semantic-advisor/ingestion-boundary.js +14 -6
  165. package/dist/operations/semantic-advisor/plugin-orchestration.js +1 -1
  166. package/dist/prolog/codec.d.ts.map +1 -1
  167. package/dist/prolog/codec.js +2 -1
  168. package/dist/prolog.d.ts +9 -0
  169. package/dist/prolog.d.ts.map +1 -1
  170. package/dist/prolog.js +56 -10
  171. package/dist/proof/command-test-report.d.ts +74 -0
  172. package/dist/proof/command-test-report.d.ts.map +1 -0
  173. package/dist/proof/command-test-report.js +206 -0
  174. package/dist/public/branch-resolver.d.ts +1 -0
  175. package/dist/public/branch-resolver.d.ts.map +1 -1
  176. package/dist/public/branch-resolver.js +1 -0
  177. package/dist/public/entity-origin.d.ts +69 -0
  178. package/dist/public/entity-origin.d.ts.map +1 -0
  179. package/dist/public/entity-origin.js +142 -0
  180. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  181. package/dist/public/impact/full-kb-quality.js +1 -0
  182. package/dist/public/impact/requirement-quality.js +1 -1
  183. package/dist/public/operations/catalog.d.ts +130 -19
  184. package/dist/public/operations/catalog.d.ts.map +1 -1
  185. package/dist/public/operations/catalog.js +3 -0
  186. package/dist/public/operations/check-executor.d.ts.map +1 -1
  187. package/dist/public/operations/check-executor.js +8 -0
  188. package/dist/public/operations/contracts.d.ts +0 -5
  189. package/dist/public/operations/contracts.d.ts.map +1 -1
  190. package/dist/public/operations/contracts.js +63 -14
  191. package/dist/public/operations/discovery-entities.d.ts +15 -0
  192. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  193. package/dist/public/operations/discovery-entities.js +59 -0
  194. package/dist/public/operations/discovery-executors.d.ts +6 -1
  195. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  196. package/dist/public/operations/discovery-executors.js +65 -6
  197. package/dist/public/operations/index.d.ts +1 -0
  198. package/dist/public/operations/index.d.ts.map +1 -1
  199. package/dist/public/operations/index.js +1 -0
  200. package/dist/public/operations/migration-plan.d.ts +5 -0
  201. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  202. package/dist/public/operations/migration-plan.js +26 -1
  203. package/dist/public/operations/node-ports.d.ts.map +1 -1
  204. package/dist/public/operations/node-ports.js +24 -3
  205. package/dist/public/operations/origin-review.d.ts +51 -0
  206. package/dist/public/operations/origin-review.d.ts.map +1 -0
  207. package/dist/public/operations/origin-review.js +307 -0
  208. package/dist/public/operations/predicate-schema-conformance.js +1 -1
  209. package/dist/public/operations/repair-plan.d.ts.map +1 -1
  210. package/dist/public/operations/repair-plan.js +4 -0
  211. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  212. package/dist/public/operations/result-envelope.js +17 -5
  213. package/dist/public/operations/runtime-types.d.ts +9 -0
  214. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  215. package/dist/public/operations/schema6-check-actions.d.ts +127 -0
  216. package/dist/public/operations/schema6-check-actions.d.ts.map +1 -0
  217. package/dist/public/operations/schema6-check-actions.js +575 -0
  218. package/dist/public/operations/source-path-dangling.d.ts +17 -0
  219. package/dist/public/operations/source-path-dangling.d.ts.map +1 -0
  220. package/dist/public/operations/source-path-dangling.js +66 -0
  221. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  222. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  223. package/dist/public/operations/specs/check-rules.generated.js +15 -1
  224. package/dist/public/operations/specs/check.d.ts +2 -2
  225. package/dist/public/operations/specs/check.js +1 -1
  226. package/dist/public/operations/specs/composite.d.ts +351 -0
  227. package/dist/public/operations/specs/composite.d.ts.map +1 -0
  228. package/dist/public/operations/specs/composite.js +96 -0
  229. package/dist/public/operations/specs/discovery.d.ts +8 -3
  230. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  231. package/dist/public/operations/specs/discovery.js +8 -3
  232. package/dist/public/operations/specs/modeling.d.ts +2 -2
  233. package/dist/public/operations/specs/modeling.js +2 -2
  234. package/dist/public/operations/specs/mutation-schemas.d.ts +73 -8
  235. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  236. package/dist/public/operations/specs/mutation-schemas.js +43 -7
  237. package/dist/public/operations/specs/mutation.d.ts +1 -1
  238. package/dist/public/operations/specs/mutation.js +1 -1
  239. package/dist/public/operations/specs/planning.d.ts +2 -2
  240. package/dist/public/operations/specs/planning.js +4 -4
  241. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  242. package/dist/public/operations/specs/reporting.js +13 -26
  243. package/dist/public/operations/specs/upsert.d.ts +79 -9
  244. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  245. package/dist/public/operations/specs/upsert.js +6 -1
  246. package/dist/public/operations/types.d.ts +1 -1
  247. package/dist/public/operations/types.d.ts.map +1 -1
  248. package/dist/public/proof-receipt.d.ts +1 -0
  249. package/dist/public/proof-receipt.d.ts.map +1 -1
  250. package/dist/public/schemas/entity.d.ts.map +1 -1
  251. package/dist/public/schemas/entity.js +52 -0
  252. package/dist/public/schemas/relationship.d.ts.map +1 -1
  253. package/dist/public/schemas/relationship.js +2 -0
  254. package/dist/public/skills/kibi-bootstrap/SKILL.md +35 -67
  255. package/dist/public/skills/kibi-bootstrap/resources/bootstrap.md +6 -0
  256. package/dist/public/skills/kibi-usage/SKILL.md +68 -18
  257. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  258. package/dist/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  259. package/dist/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  260. package/dist/public/skills/kibi-usage/resources/operation-access.md +25 -1
  261. package/dist/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  262. package/dist/public/skills/kibi-usage/resources/workflows.md +42 -25
  263. package/dist/public/telemetry-acceptance.d.ts +58 -2
  264. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  265. package/dist/public/telemetry-acceptance.js +136 -10
  266. package/dist/public/telemetry-remediation.d.ts.map +1 -1
  267. package/dist/public/telemetry-remediation.js +26 -10
  268. package/dist/relationships/shards.d.ts +13 -0
  269. package/dist/relationships/shards.d.ts.map +1 -1
  270. package/dist/relationships/shards.js +54 -28
  271. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  272. package/dist/runtime/cli-runtime.js +44 -3
  273. package/dist/runtime/detached-snapshot.d.ts +38 -0
  274. package/dist/runtime/detached-snapshot.d.ts.map +1 -0
  275. package/dist/runtime/detached-snapshot.js +92 -0
  276. package/dist/schemas/entity.schema.json +122 -0
  277. package/dist/search-answer.d.ts +157 -0
  278. package/dist/search-answer.d.ts.map +1 -0
  279. package/dist/search-answer.js +846 -0
  280. package/dist/traceability/impact-knowledge.d.ts.map +1 -1
  281. package/dist/traceability/impact-knowledge.js +7 -0
  282. package/dist/traceability/symbol-extract.js +3 -3
  283. package/dist/traceability/temp-kb.d.ts.map +1 -1
  284. package/dist/traceability/temp-kb.js +12 -0
  285. package/dist/types/entities.d.ts +13 -0
  286. package/dist/types/entities.d.ts.map +1 -1
  287. package/dist/types/relationships.d.ts +1 -1
  288. package/dist/types/relationships.d.ts.map +1 -1
  289. package/dist/utils/branch-resolver.d.ts +37 -1
  290. package/dist/utils/branch-resolver.d.ts.map +1 -1
  291. package/dist/utils/branch-resolver.js +130 -3
  292. package/dist/utils/repo-relative-path.d.ts +18 -0
  293. package/dist/utils/repo-relative-path.d.ts.map +1 -0
  294. package/dist/utils/repo-relative-path.js +58 -0
  295. package/dist/utils/rule-registry.generated.d.ts +75 -3
  296. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  297. package/dist/utils/rule-registry.generated.js +89 -3
  298. package/dist/utils/schema-version.d.ts +1 -1
  299. package/dist/utils/schema-version.d.ts.map +1 -1
  300. package/dist/utils/schema-version.js +4 -3
  301. package/dist/utils/strict-modeling.d.ts +1 -1
  302. package/dist/utils/strict-modeling.d.ts.map +1 -1
  303. package/dist/utils/strict-modeling.js +23 -3
  304. package/package.json +3 -3
  305. package/schema/entities.pl +22 -0
  306. package/schema/relationships.pl +14 -0
  307. package/schema/validation.pl +45 -1
  308. package/src/public/branch-resolver.ts +1 -0
  309. package/src/public/entity-origin.ts +175 -0
  310. package/src/public/impact/full-kb-quality.ts +1 -0
  311. package/src/public/impact/requirement-quality.ts +1 -1
  312. package/src/public/operations/catalog.ts +3 -0
  313. package/src/public/operations/check-executor.ts +15 -0
  314. package/src/public/operations/contracts.ts +75 -15
  315. package/src/public/operations/discovery-entities.ts +74 -0
  316. package/src/public/operations/discovery-executors.ts +88 -10
  317. package/src/public/operations/index.ts +1 -0
  318. package/src/public/operations/migration-plan.ts +30 -1
  319. package/src/public/operations/node-ports.ts +24 -3
  320. package/src/public/operations/origin-review.ts +375 -0
  321. package/src/public/operations/predicate-schema-conformance.ts +1 -1
  322. package/src/public/operations/repair-plan.ts +4 -0
  323. package/src/public/operations/result-envelope.ts +18 -6
  324. package/src/public/operations/runtime-types.ts +9 -0
  325. package/src/public/operations/schema6-check-actions.ts +699 -0
  326. package/src/public/operations/source-path-dangling.ts +81 -0
  327. package/src/public/operations/specs/check-rules.generated.ts +15 -1
  328. package/src/public/operations/specs/check.ts +1 -1
  329. package/src/public/operations/specs/composite.ts +141 -0
  330. package/src/public/operations/specs/discovery.ts +9 -3
  331. package/src/public/operations/specs/modeling.ts +2 -2
  332. package/src/public/operations/specs/mutation-schemas.ts +49 -7
  333. package/src/public/operations/specs/mutation.ts +1 -1
  334. package/src/public/operations/specs/planning.ts +4 -4
  335. package/src/public/operations/specs/reporting.ts +13 -38
  336. package/src/public/operations/specs/upsert.ts +7 -1
  337. package/src/public/operations/types.ts +2 -0
  338. package/src/public/proof-receipt.ts +1 -0
  339. package/src/public/schemas/entity.ts +57 -0
  340. package/src/public/schemas/relationship.ts +2 -0
  341. package/src/public/skills/kibi-bootstrap/SKILL.md +35 -67
  342. package/src/public/skills/kibi-bootstrap/resources/bootstrap.md +6 -0
  343. package/src/public/skills/kibi-usage/SKILL.md +68 -18
  344. package/src/public/skills/kibi-usage/resources/fact-lanes.md +5 -5
  345. package/src/public/skills/kibi-usage/resources/kb-improvement.md +1 -1
  346. package/src/public/skills/kibi-usage/resources/logic-ir.md +2 -2
  347. package/src/public/skills/kibi-usage/resources/operation-access.md +25 -1
  348. package/src/public/skills/kibi-usage/resources/ui-requirements.md +4 -4
  349. package/src/public/skills/kibi-usage/resources/workflows.md +42 -25
  350. package/src/public/telemetry-acceptance-types.d.ts +4 -1
  351. package/src/public/telemetry-acceptance.ts +204 -10
  352. package/src/public/telemetry-remediation.ts +39 -10
  353. package/src/schemas/entity.schema.json +122 -0
  354. package/src/schemas/relationship.schema.json +2 -0
@@ -1,3 +1,4 @@
1
+ import { type EntityOrigin } from "../public/entity-origin.js";
1
2
  import { type ProofBinding, type ProofContract } from "../public/proof-protocol.js";
2
3
  import { type ProofReceipt } from "../public/proof-receipt.js";
3
4
  export interface ExtractedEntity {
@@ -13,6 +14,7 @@ export interface ExtractedEntity {
13
14
  priority?: string;
14
15
  severity?: string;
15
16
  text_ref?: string;
17
+ origin?: EntityOrigin;
16
18
  semantic_text?: string;
17
19
  logic_claims?: string[];
18
20
  semantic_clauses?: string[];
@@ -30,6 +32,11 @@ export interface ExtractedEntity {
30
32
  verification_perspective?: "internal" | "consumer";
31
33
  proof_exempt?: boolean;
32
34
  proof_exempt_reason?: string;
35
+ approved_by?: string;
36
+ approval_ref?: string;
37
+ rationale?: string;
38
+ exempts_claims?: string[];
39
+ expects?: "success" | "rejection" | "error";
33
40
  proof_contract?: ProofContract;
34
41
  proof_bindings?: readonly ProofBinding[];
35
42
  proof_receipts?: readonly ProofReceipt[];
@@ -57,6 +64,7 @@ export interface ExtractedEntity {
57
64
  argument_names?: string[];
58
65
  argument_types?: string[];
59
66
  argument_descriptions?: string[];
67
+ key_arguments?: string[];
60
68
  aliases?: string[];
61
69
  examples?: string[];
62
70
  predicate_args?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/extractors/markdown.ts"],"names":[],"mappings":"AAuBA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,4BAA4B,CAAC;AAsEpC,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,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AG,SAAS,CAQpE"}
@@ -20,6 +20,7 @@ import { readFileSync } from "node:fs";
20
20
  import Ajv from "ajv";
21
21
  import { load as yamlLoad } from "js-yaml";
22
22
  import { semanticClaimKey } from "../operations/semantic-advisor/clauses.js";
23
+ import { normalizeEntityOrigin, } from "../public/entity-origin.js";
23
24
  import { PROOF_BINDINGS_SCHEMA, PROOF_CONTRACT_SCHEMA, } from "../public/proof-protocol.js";
24
25
  import { proofReceiptHistoryErrors, } from "../public/proof-receipt.js";
25
26
  import entitySchema from "../schemas/entity.schema.json" with { type: "json" };
@@ -61,6 +62,7 @@ const FACT_STRING_ARRAY_FIELDS = [
61
62
  "argument_names",
62
63
  "argument_types",
63
64
  "argument_descriptions",
65
+ "key_arguments",
64
66
  "aliases",
65
67
  "examples",
66
68
  "predicate_args",
@@ -114,6 +116,8 @@ const VALID_RELATIONSHIP_TYPES = new Set([
114
116
  "consumes",
115
117
  "supersedes",
116
118
  "restates",
119
+ "assumes",
120
+ "exempts",
117
121
  "relates_to",
118
122
  ]);
119
123
  const VALID_RELATIONSHIP_DIRECTIONS = [
@@ -139,6 +143,8 @@ const VALID_RELATIONSHIP_DIRECTIONS = [
139
143
  { type: "supersedes", from: "adr", to: "adr" },
140
144
  { type: "supersedes", from: "req", to: "req" },
141
145
  { type: "restates", from: "req", to: "req" },
146
+ { type: "assumes", from: "scenario", to: "fact" },
147
+ { type: "exempts", from: "req", to: "req" },
142
148
  ];
143
149
  const RELATIONSHIP_TYPE_DISPLAY_LIST = Array.from(VALID_RELATIONSHIP_TYPES)
144
150
  .sort()
@@ -398,6 +404,17 @@ function extractFromMarkdownContent(content, filePath) {
398
404
  if (data.text_ref !== undefined) {
399
405
  entity.text_ref = data.text_ref;
400
406
  }
407
+ // implements REQ-004
408
+ if (data.origin !== undefined) {
409
+ const normalized = normalizeEntityOrigin(data.origin);
410
+ if ("error" in normalized) {
411
+ throw new FrontmatterError(`Invalid origin: ${normalized.error}`, filePath, {
412
+ classification: "Invalid Entity Origin",
413
+ hint: "Use origin: {kind: human|agent|migration|import, ref, approved_by, recorded_at}; only kind is required.",
414
+ });
415
+ }
416
+ entity.origin = normalized.origin;
417
+ }
401
418
  if (type === "req" && data.semantic_text !== undefined) {
402
419
  entity.semantic_text = data.semantic_text;
403
420
  }
@@ -421,6 +438,18 @@ function extractFromMarkdownContent(content, filePath) {
421
438
  if (type === "req" && data.semantic_source_hash !== undefined) {
422
439
  entity.semantic_source_hash = data.semantic_source_hash;
423
440
  }
441
+ // implements REQ-kibi-scenario-feasibility-v2
442
+ if (type === "scenario" && data.expects !== undefined) {
443
+ if (data.expects !== "success" &&
444
+ data.expects !== "rejection" &&
445
+ data.expects !== "error") {
446
+ throw new FrontmatterError("Invalid expects; expected success, rejection or error", filePath, {
447
+ classification: "Invalid Scenario Outcome",
448
+ hint: "Set expects: success, expects: rejection or expects: error on the scenario.",
449
+ });
450
+ }
451
+ entity.expects = data.expects;
452
+ }
424
453
  if (type === "req" && data.proof_exempt !== undefined) {
425
454
  if (typeof data.proof_exempt !== "boolean") {
426
455
  throw new FrontmatterError("Invalid proof_exempt; expected true or false", filePath, {
@@ -440,6 +469,34 @@ function extractFromMarkdownContent(content, filePath) {
440
469
  }
441
470
  entity.proof_exempt_reason = data.proof_exempt_reason;
442
471
  }
472
+ // implements REQ-kibi-scenario-feasibility-v2
473
+ // Human approval of an exception requirement; only an approved exception
474
+ // makes a success scenario feasible.
475
+ for (const field of ["approved_by", "approval_ref"]) {
476
+ if (type !== "req" || data[field] === undefined)
477
+ continue;
478
+ if (typeof data[field] !== "string" || data[field].trim() === "") {
479
+ throw new FrontmatterError(`Invalid ${field}; expected a non-empty string`, filePath, {
480
+ classification: "Invalid Exception Approval",
481
+ hint: "Set approved_by to the approving person or role (and optionally approval_ref to the decision record) on the exception requirement.",
482
+ });
483
+ }
484
+ entity[field] = data[field];
485
+ }
486
+ // implements REQ-core-validation-rules
487
+ // Why the requirement exists; requirement-rationale-missing reads it.
488
+ if (type === "req" && data.rationale !== undefined) {
489
+ if (typeof data.rationale !== "string" || data.rationale.trim() === "") {
490
+ throw new FrontmatterError("Invalid rationale; expected a non-empty string", filePath, {
491
+ classification: "Invalid Rationale",
492
+ hint: "Set rationale to one or two sentences saying why the requirement exists, or remove the field.",
493
+ });
494
+ }
495
+ entity.rationale = data.rationale;
496
+ }
497
+ if (type === "req" && Array.isArray(data.exempts_claims)) {
498
+ entity.exempts_claims = data.exempts_claims.filter((value) => typeof value === "string");
499
+ }
443
500
  if (type !== "fact") {
444
501
  const invalidFactField = FACT_ONLY_FIELDS.find((field) => data[field] !== undefined);
445
502
  if (invalidFactField) {
@@ -1 +1 @@
1
- {"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../src/extractors/relationships.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,4BAA4B,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,qBAAqB,EAAE,CAAC;CACxC;AA0BD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,MAAM,GACvB,qBAAqB,EAAE,CAmBzB;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,GAChB,qBAAqB,CAiBvB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,kBAAkB,GACzB,qBAAqB,GAAG,IAAI,CAyC9B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAAE,GAC/B,qBAAqB,EAAE,CAEzB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,qBAAqB,EAAE,EACtC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,KAAK,CAAC;IACP,YAAY,EAAE,qBAAqB,CAAC;IACpC,KAAK,EAAE,cAAc,GAAG,YAAY,CAAC;CACtC,CAAC,CAgBD"}
1
+ {"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../src/extractors/relationships.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,4BAA4B,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,qBAAqB,EAAE,CAAC;CACxC;AA4BD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,MAAM,GACvB,qBAAqB,EAAE,CAmBzB;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,GAChB,qBAAqB,CAiBvB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,kBAAkB,GACzB,qBAAqB,GAAG,IAAI,CAyC9B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAAE,GAC/B,qBAAqB,EAAE,CAEzB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,qBAAqB,EAAE,EACtC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,KAAK,CAAC;IACP,YAAY,EAAE,qBAAqB,CAAC;IACpC,KAAK,EAAE,cAAc,GAAG,YAAY,CAAC;CACtC,CAAC,CAgBD"}
@@ -39,6 +39,8 @@ const VALID_RELATIONSHIP_TYPES = new Set([
39
39
  "consumes",
40
40
  "supersedes",
41
41
  "restates",
42
+ "assumes",
43
+ "exempts",
42
44
  "relates_to",
43
45
  ]);
44
46
  /**
@@ -43,6 +43,7 @@ export type IntentSearchAnalysis = Readonly<{
43
43
  topScore: number | null;
44
44
  topTwoMargin: number | null;
45
45
  abstained: boolean;
46
+ ambiguous: boolean;
46
47
  }>;
47
48
  export type IntentSearchResult = Readonly<{
48
49
  matches: readonly IntentSearchMatch[];
@@ -53,7 +54,9 @@ type GraphEdge = Readonly<{
53
54
  from: string;
54
55
  to: string;
55
56
  }>;
56
- export declare function rankIntentEntities(entities: readonly Record<string, unknown>[], options: IntentSearchOptions, workspaceRoot: string, graphEdges?: readonly GraphEdge[]): Promise<IntentSearchResult>;
57
+ /** Markdown bodies already read in this search, keyed by entity source. */
58
+ export type MarkdownBodyCache = Map<string, string | null>;
59
+ export declare function rankIntentEntities(entities: readonly Record<string, unknown>[], options: IntentSearchOptions, workspaceRoot: string, graphEdges?: readonly GraphEdge[], bodyCache?: MarkdownBodyCache): Promise<IntentSearchResult>;
57
60
  export declare function graphGoal(seedIds: readonly string[], depth: 1 | 2): string;
58
61
  export declare function executeIntentSearch(options: IntentSearchOptions, prolog: PrologPort, workspaceRoot: string): Promise<IntentSearchResult>;
59
62
  export declare function validateIntentSearchInput(input: IntentSearchOptions): void;
@@ -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,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC,CAAC;AAobH,2EAA2E;AAE3E,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;AA8B3D,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC5C,OAAO,EAAE,mBAAmB,EAC5B,aAAa,EAAE,MAAM,EACrB,UAAU,GAAE,SAAS,SAAS,EAAO,EACrC,SAAS,GAAE,iBAA6B,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAsG7B;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,MAAM,CAO1E;AAkHD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,kBAAkB,CAAC,CAoD7B;AAGD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CA0C1E"}
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { escapeAtom, normalizeEntityId, parseTriples } from "./prolog/codec.js";
3
- import { SEARCH_CANDIDATE_PAGE_SIZE, listSearchCandidates, loadEntities, loadSearchCandidates, } from "./public/operations/discovery-entities.js";
3
+ import { SEARCH_CANDIDATE_PAGE_SIZE, listSearchCandidates, loadEntities, loadEntityRows, loadSearchCandidates, } from "./public/operations/discovery-entities.js";
4
4
  import { loadMarkdownBody } from "./search-ranking.js";
5
5
  const GRAPH_RELATIONSHIPS = [
6
6
  "implements",
@@ -13,6 +13,7 @@ const GRAPH_RELATIONSHIPS = [
13
13
  "requires_property",
14
14
  "requires_predicate",
15
15
  "requires_rule",
16
+ "supersedes",
16
17
  ];
17
18
  const FACET_NAMES = [
18
19
  "actors",
@@ -21,23 +22,92 @@ const FACET_NAMES = [
21
22
  "constraints",
22
23
  "aliases",
23
24
  ];
25
+ // Function words and question scaffolding carry no domain signal. Without
26
+ // them, "how should kibi handle a detached HEAD?" scores on "detached" and
27
+ // "head" rather than on how many entities mention "should". The frame of the
28
+ // questions kb_search invites ("what governs X?", "what must stay true when
29
+ // X?") is scaffolding too: entries are stemmed forms, so "govern" also drops
30
+ // "governs", "governing" and "governed".
24
31
  const STOP_WORDS = new Set([
25
32
  "a",
33
+ "about",
26
34
  "an",
27
35
  "and",
36
+ "any",
28
37
  "are",
38
+ "as",
39
+ "at",
29
40
  "be",
30
41
  "by",
42
+ "can",
43
+ "could",
44
+ "did",
45
+ "do",
46
+ "does",
31
47
  "for",
48
+ "from",
49
+ "govern",
50
+ "happen",
51
+ "happens",
52
+ "how",
53
+ "i",
54
+ "if",
32
55
  "in",
56
+ "into",
33
57
  "is",
58
+ "it",
59
+ "its",
60
+ "me",
61
+ "must",
62
+ "my",
34
63
  "of",
35
64
  "on",
36
65
  "or",
66
+ "our",
67
+ "should",
68
+ "so",
69
+ "stay",
70
+ "tell",
71
+ "than",
72
+ "that",
37
73
  "the",
74
+ "their",
75
+ "them",
76
+ "then",
77
+ "there",
78
+ "these",
79
+ "they",
80
+ "this",
81
+ "those",
38
82
  "to",
83
+ "true",
84
+ "us",
85
+ "was",
86
+ "we",
87
+ "what",
88
+ "when",
89
+ "where",
90
+ "which",
91
+ "who",
92
+ "why",
93
+ "will",
39
94
  "with",
95
+ "would",
96
+ "you",
97
+ "your",
40
98
  ]);
99
+ // Statuses whose entities no longer govern. They stay findable but rank
100
+ // below current entities and are labelled in the match reasons.
101
+ const NON_GOVERNING_STATUSES = new Set([
102
+ "superseded",
103
+ "deprecated",
104
+ "rejected",
105
+ "retired",
106
+ "obsolete",
107
+ "archived",
108
+ ]);
109
+ const NON_GOVERNING_FACTOR = 0.5;
110
+ const AMBIGUOUS_MARGIN = 0.05;
41
111
  const MAX_CANDIDATES = 10_000;
42
112
  const MAX_GRAPH_SEEDS = 5;
43
113
  const MAX_GRAPH_EDGES = 2_000;
@@ -52,8 +122,27 @@ function normalize(value) {
52
122
  .map((token) => token.length > 4 && token.endsWith("s") && !token.endsWith("ss")
53
123
  ? token.slice(0, -1)
54
124
  : token)
125
+ .map(stem)
55
126
  .join(" ");
56
127
  }
128
+ // A deliberately small suffix stripper so a question's verb meets the
129
+ // entity's noun ("contradict" / "contradiction" / "contradictory",
130
+ // "detached" / "detach"). Short tokens are left alone.
131
+ const STEM_SUFFIXES = ["ation", "ion", "ing", "ory", "ed"];
132
+ function stem(token) {
133
+ if (token.length < 6 || /\d/.test(token))
134
+ return token;
135
+ let stemmed = token;
136
+ for (const suffix of STEM_SUFFIXES) {
137
+ if (stemmed.endsWith(suffix) && stemmed.length - suffix.length >= 4) {
138
+ stemmed = stemmed.slice(0, -suffix.length);
139
+ break;
140
+ }
141
+ }
142
+ return stemmed.length > 4 && stemmed.endsWith("e")
143
+ ? stemmed.slice(0, -1)
144
+ : stemmed;
145
+ }
57
146
  function tokens(value) {
58
147
  return Array.from(new Set(normalize(value)
59
148
  .split(" ")
@@ -158,7 +247,16 @@ function facetValues(facets) {
158
247
  }
159
248
  return result;
160
249
  }
161
- function scoreEntity(entity, queryTokens, facets, sourceEvidence, graphEvidence, documentFrequency, documentCount, body) {
250
+ // Both ranking passes of a search score the same candidate objects, and
251
+ // tokenizing them is most of the ranking cost on a large KB, so each entity is
252
+ // tokenized once. Keyed weakly by the entity object, so nothing outlives the
253
+ // search that loaded it.
254
+ const ENTITY_TOKENS = new WeakMap();
255
+ // implements REQ-kibi-intent-aware-source-discovery
256
+ function entityTokens(entity, body) {
257
+ const cached = ENTITY_TOKENS.get(entity);
258
+ if (cached !== undefined && cached.body === body)
259
+ return cached;
162
260
  const title = normalize(String(entity.title ?? ""));
163
261
  const metadata = normalize([
164
262
  entity.id,
@@ -171,25 +269,47 @@ function scoreEntity(entity, queryTokens, facets, sourceEvidence, graphEvidence,
171
269
  ]
172
270
  .filter((value) => typeof value === "string")
173
271
  .join(" "));
174
- const bodyText = normalize(body ?? "");
175
- const titleTokens = new Set(tokens(title));
176
- const metadataTokens = new Set(tokens(metadata));
177
- const bodyTokens = new Set(tokens(bodyText));
272
+ const computed = {
273
+ body,
274
+ title: new Set(tokens(title)),
275
+ metadata: new Set(tokens(metadata)),
276
+ bodyTokens: new Set(tokens(normalize(body ?? ""))),
277
+ document: tokens(`${entityText(entity)} ${body ?? ""}`),
278
+ };
279
+ ENTITY_TOKENS.set(entity, computed);
280
+ return computed;
281
+ }
282
+ function scoreEntity(entity, queryTokens, facets, sourceEvidence, graphEvidence, documentFrequency, documentCount, body, superseded = false) {
283
+ const { title: titleTokens, metadata: metadataTokens, bodyTokens, } = entityTokens(entity, body);
178
284
  const allSignalTokens = Array.from(new Set(queryTokens));
179
- const lexical = allSignalTokens.reduce((sum, token) => {
285
+ // BM25-style inverse document frequency over title, metadata and body:
286
+ // a token most entities contain (a project name, "requirement") adds
287
+ // almost nothing, and the score is the share of the query's total
288
+ // discriminating weight this entity matches.
289
+ // Half of the lexical score is where the matched weight sits (title over
290
+ // metadata over body); the other half is how much of the query's
291
+ // discriminating weight the entity covers at all, so an entity matching
292
+ // the rare terms in its body outranks one matching a common term in its
293
+ // title.
294
+ let placed = 0;
295
+ let covered = 0;
296
+ let total = 0;
297
+ for (const token of allSignalTokens) {
180
298
  const frequency = documentFrequency.get(token) ?? 0;
181
- const idf = Math.log(1 + (documentCount + 1) / (frequency + 1));
299
+ const idf = Math.log(1 + (documentCount - frequency + 0.5) / (frequency + 0.5));
182
300
  const fieldWeight = titleTokens.has(token)
183
- ? 3
301
+ ? 1
184
302
  : metadataTokens.has(token)
185
- ? 1.5
303
+ ? 0.65
186
304
  : bodyTokens.has(token)
187
- ? 0.75
305
+ ? 0.5
188
306
  : 0;
189
- return sum + idf * fieldWeight;
190
- }, 0);
191
- const lexicalMax = Math.max(1, allSignalTokens.length * 4);
192
- const lexicalScore = Math.min(1, lexical / lexicalMax);
307
+ placed += idf * fieldWeight;
308
+ if (fieldWeight > 0)
309
+ covered += idf;
310
+ total += idf;
311
+ }
312
+ const lexicalScore = total > 0 ? Math.min(1, (placed / total + covered / total) / 2) : 0;
193
313
  const matchedFacets = [];
194
314
  let facetScore = 0;
195
315
  for (const facet of facets) {
@@ -207,11 +327,17 @@ function scoreEntity(entity, queryTokens, facets, sourceEvidence, graphEvidence,
207
327
  facetScore = Math.min(1, facetScore / Math.max(1, facets.length));
208
328
  const sourceScore = sourceEvidence.length > 0 ? 1 : 0;
209
329
  const graphScore = graphEvidence.length > 0 ? Math.min(1, graphEvidence.length / 2) : 0;
330
+ const status = String(entity.status ?? "")
331
+ .trim()
332
+ .toLowerCase();
333
+ const nonGoverning = NON_GOVERNING_STATUSES.has(status) || superseded;
210
334
  const score = Math.min(1, lexicalScore * 0.58 +
211
335
  facetScore * 0.17 +
212
336
  sourceScore * 0.2 +
213
- graphScore * 0.05);
337
+ graphScore * 0.05) * (nonGoverning ? NON_GOVERNING_FACTOR : 1);
214
338
  const reasons = [];
339
+ if (nonGoverning)
340
+ reasons.push(superseded ? "demoted: superseded" : `demoted: ${status}`);
215
341
  if (lexicalScore > 0)
216
342
  reasons.push("intent token match");
217
343
  if (matchedFacets.length > 0)
@@ -227,24 +353,45 @@ function scoreEntity(entity, queryTokens, facets, sourceEvidence, graphEvidence,
227
353
  }
228
354
  return { score, reasons, matchedFacets };
229
355
  }
230
- function buildDocumentFrequency(entities) {
356
+ function buildDocumentFrequency(entities, bodies) {
231
357
  const frequency = new Map();
232
358
  for (const entity of entities) {
233
- const seen = new Set(tokens(entityText(entity)));
359
+ const seen = entityTokens(entity, bodies.get(entity) ?? null).document;
234
360
  for (const token of seen)
235
361
  frequency.set(token, (frequency.get(token) ?? 0) + 1);
236
362
  }
237
363
  return frequency;
238
364
  }
365
+ /** Files read at once, well under common open-file limits. */
366
+ const BODY_READ_CONCURRENCY = 32;
367
+ // implements REQ-kibi-intent-aware-source-discovery
368
+ async function readBodies(entities, workspaceRoot, cache) {
369
+ const missing = [
370
+ ...new Set(entities.map((entity) => String(entity.source ?? ""))),
371
+ ].filter((source) => !cache.has(source));
372
+ for (let start = 0; start < missing.length; start += BODY_READ_CONCURRENCY) {
373
+ const batch = missing.slice(start, start + BODY_READ_CONCURRENCY);
374
+ const loaded = await Promise.all(batch.map((source) => loadMarkdownBody(source, workspaceRoot)));
375
+ batch.forEach((source, index) => cache.set(source, loaded[index] ?? null));
376
+ }
377
+ return new Map(entities.map((entity) => [
378
+ entity,
379
+ cache.get(String(entity.source ?? "")) ?? null,
380
+ ]));
381
+ }
239
382
  // implements REQ-kibi-intent-aware-source-discovery
240
- export async function rankIntentEntities(entities, options, workspaceRoot, graphEdges = []) {
383
+ export async function rankIntentEntities(entities, options, workspaceRoot, graphEdges = [], bodyCache = new Map()) {
241
384
  const queryTokens = tokens(options.query);
242
385
  const facets = facetValues(options.semanticFacets);
243
386
  const allTokens = Array.from(new Set([
244
387
  ...queryTokens,
245
388
  ...facets.flatMap((facet) => tokens(facet.value)),
246
389
  ]));
247
- const documentFrequency = buildDocumentFrequency(entities);
390
+ const bodies = await readBodies(entities, workspaceRoot, bodyCache);
391
+ const documentFrequency = buildDocumentFrequency(entities, bodies);
392
+ const supersededIds = new Set(graphEdges
393
+ .filter((edge) => edge.relationship === "supersedes")
394
+ .map((edge) => edge.to));
248
395
  const ranked = [];
249
396
  const minScore = options.minScore ?? 0.18;
250
397
  const graphByEntity = new Map();
@@ -267,8 +414,8 @@ export async function rankIntentEntities(entities, options, workspaceRoot, graph
267
414
  // Keep evidence useful for agents and bounded for transport. The score is
268
415
  // already capped; unbounded parallel paths only add noise to receipts.
269
416
  const graphEvidence = (graphByEntity.get(entityId) ?? []).slice(0, 8);
270
- const body = await loadMarkdownBody(String(entity.source ?? ""), workspaceRoot);
271
- const scored = scoreEntity(entity, allTokens, facets, sourceEvidence, graphEvidence, documentFrequency, entities.length, body);
417
+ const body = bodies.get(entity) ?? null;
418
+ const scored = scoreEntity(entity, allTokens, facets, sourceEvidence, graphEvidence, documentFrequency, entities.length, body, supersededIds.has(entityId));
272
419
  if (scored.score < minScore)
273
420
  continue;
274
421
  const snippet = body
@@ -285,7 +432,9 @@ export async function rankIntentEntities(entities, options, workspaceRoot, graph
285
432
  matchedFacets: scored.matchedFacets,
286
433
  sourceMatches: sourceEvidence,
287
434
  graphPaths: graphEvidence,
288
- abstentionEligible: scored.score < minScore,
435
+ // Accepted, but within 0.05 of the threshold: a weak match the
436
+ // caller should confirm before relying on it.
437
+ abstentionEligible: scored.score < minScore + AMBIGUOUS_MARGIN,
289
438
  },
290
439
  });
291
440
  }
@@ -312,6 +461,8 @@ export async function rankIntentEntities(entities, options, workspaceRoot, graph
312
461
  topScore,
313
462
  topTwoMargin,
314
463
  abstained: ranked.length === 0,
464
+ // Two leading matches this close are not a confident single answer.
465
+ ambiguous: topTwoMargin !== null && topTwoMargin < AMBIGUOUS_MARGIN,
315
466
  },
316
467
  };
317
468
  }
@@ -421,7 +572,9 @@ async function loadIntentCandidates(prolog, options) {
421
572
  // implements REQ-kibi-intent-aware-source-discovery
422
573
  export async function executeIntentSearch(options, prolog, workspaceRoot) {
423
574
  const candidates = await loadIntentCandidates(prolog, options);
424
- const firstPass = await rankIntentEntities(candidates, options, workspaceRoot);
575
+ // Both ranking passes read the same Markdown bodies; read each file once.
576
+ const bodies = new Map();
577
+ const firstPass = await rankIntentEntities(candidates, options, workspaceRoot, [], bodies);
425
578
  const sourceSeeds = firstPass.matches
426
579
  .filter((match) => match.evidence.sourceMatches.length > 0)
427
580
  .map((match) => String(match.entity.id ?? ""));
@@ -435,17 +588,17 @@ export async function executeIntentSearch(options, prolog, workspaceRoot) {
435
588
  const graphEdges = await queryGraphEdges(prolog, seeds);
436
589
  const knownIds = new Set(candidates.map((entity) => `${String(entity.type ?? "")}::${String(entity.id ?? "")}`));
437
590
  const relatedIds = Array.from(new Set(graphEdges.flatMap((edge) => [edge.from, edge.to]))).filter((id) => !seeds.includes(id));
438
- for (const id of relatedIds.slice(0, MAX_GRAPH_SEEDS * 4)) {
439
- const related = await loadEntities(prolog, { id });
440
- for (const entity of related) {
441
- const key = `${String(entity.type ?? "")}::${String(entity.id ?? "")}`;
442
- if (!knownIds.has(key)) {
443
- knownIds.add(key);
444
- candidates.push(entity);
445
- }
591
+ // One batched query of projected rows for the graph neighbours, rather
592
+ // than one engine round trip per neighbour.
593
+ const related = await loadEntityRows(prolog, relatedIds.slice(0, MAX_GRAPH_SEEDS * 4));
594
+ for (const entity of related) {
595
+ const key = `${String(entity.type ?? "")}::${String(entity.id ?? "")}`;
596
+ if (!knownIds.has(key)) {
597
+ knownIds.add(key);
598
+ candidates.push(entity);
446
599
  }
447
600
  }
448
- return rankIntentEntities(candidates, options, workspaceRoot, graphEdges);
601
+ return rankIntentEntities(candidates, options, workspaceRoot, graphEdges, bodies);
449
602
  }
450
603
  // implements REQ-kibi-intent-aware-source-discovery
451
604
  export function validateIntentSearchInput(input) {
@@ -1 +1 @@
1
- {"version":3,"file":"candidate-helpers.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/candidate-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAMtD;AAED,wBAAgB,MAAM,CACpB,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,CAAA;CAAE,EAE5D,MAAM,EAAE,CAAC,EACT,aAAa,GAAE,SAAS;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,EAAO,GACP,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAQnC;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,cAAc,GACvB,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAmC9C"}
1
+ {"version":3,"file":"candidate-helpers.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/candidate-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIrE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAMtD;AAED,wBAAgB,MAAM,CACpB,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,CAAA;CAAE,EAE5D,MAAM,EAAE,CAAC,EACT,aAAa,GAAE,SAAS;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,EAAO,GACP,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAQnC;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,cAAc,GACvB,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CA0C9C"}
@@ -1,3 +1,5 @@
1
+ import { annotateModelRequirementStep } from "../modeling/model-requirement.js";
2
+ import { semanticClaimKey } from "../semantic-advisor/clauses.js";
1
3
  export function confidenceBand(value) {
2
4
  return value >= 0.9 ? "high" : value >= 0.8 ? "medium" : "low";
3
5
  }
@@ -28,6 +30,7 @@ export function strictPlan(writeSet) {
28
30
  },
29
31
  ];
30
32
  }
33
+ const claimKey = semanticClaimKey(writeSet.req.properties.title);
31
34
  return [
32
35
  {
33
36
  type: "fact",
@@ -51,5 +54,9 @@ export function strictPlan(writeSet) {
51
54
  to,
52
55
  })),
53
56
  },
54
- ];
57
+ ].map((step) => annotateModelRequirementStep(step, {
58
+ claimKey,
59
+ statement: writeSet.req.properties.title,
60
+ logicClaims: [claimKey],
61
+ }));
55
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/candidates.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAmHpB,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,aAAa,EAAE,MAAM,EACrB,sBAAsB,EAAE,OAAO,GAC9B,oBAAoB,CAsCtB"}
1
+ {"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/candidates.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AA+GpB,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,aAAa,EAAE,MAAM,EACrB,sBAAsB,EAAE,OAAO,GAC9B,oBAAoB,CA4DtB"}