kibi-cli 2.1.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 (246) hide show
  1. package/dist/cli-protocol.d.ts.map +1 -1
  2. package/dist/cli-protocol.js +3 -2
  3. package/dist/commands/aggregated-checks.d.ts +7 -0
  4. package/dist/commands/aggregated-checks.d.ts.map +1 -1
  5. package/dist/commands/aggregated-checks.js +25 -1
  6. package/dist/commands/check.d.ts.map +1 -1
  7. package/dist/commands/check.js +21 -13
  8. package/dist/commands/doctor.d.ts.map +1 -1
  9. package/dist/commands/doctor.js +105 -24
  10. package/dist/commands/github-init.d.ts +1 -1
  11. package/dist/commands/github-init.d.ts.map +1 -1
  12. package/dist/commands/github-init.js +1 -1
  13. package/dist/commands/init-helpers.d.ts +17 -2
  14. package/dist/commands/init-helpers.d.ts.map +1 -1
  15. package/dist/commands/init-helpers.js +123 -23
  16. package/dist/commands/init.d.ts.map +1 -1
  17. package/dist/commands/init.js +110 -15
  18. package/dist/commands/prove.d.ts.map +1 -1
  19. package/dist/commands/prove.js +10 -18
  20. package/dist/commands/sync/cache.d.ts +20 -1
  21. package/dist/commands/sync/cache.d.ts.map +1 -1
  22. package/dist/commands/sync/cache.js +51 -2
  23. package/dist/commands/sync/discovery.d.ts.map +1 -1
  24. package/dist/commands/sync/discovery.js +1 -1
  25. package/dist/commands/sync/persistence.d.ts.map +1 -1
  26. package/dist/commands/sync/persistence.js +8 -0
  27. package/dist/commands/sync.d.ts.map +1 -1
  28. package/dist/commands/sync.js +11 -3
  29. package/dist/engine.d.ts +26 -0
  30. package/dist/engine.d.ts.map +1 -1
  31. package/dist/engine.js +126 -29
  32. package/dist/extractors/manifest.d.ts.map +1 -1
  33. package/dist/extractors/manifest.js +66 -28
  34. package/dist/extractors/markdown.d.ts +2 -0
  35. package/dist/extractors/markdown.d.ts.map +1 -1
  36. package/dist/extractors/markdown.js +14 -3
  37. package/dist/extractors/relationships.d.ts.map +1 -1
  38. package/dist/extractors/relationships.js +1 -0
  39. package/dist/intent-search.d.ts.map +1 -1
  40. package/dist/intent-search.js +68 -29
  41. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  42. package/dist/operations/bootstrap/generate.js +4 -3
  43. package/dist/operations/modeling/model-requirement.d.ts +1 -1
  44. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  45. package/dist/operations/modeling/model-requirement.js +176 -10
  46. package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
  47. package/dist/operations/modeling/predicate-applyplan.js +14 -2
  48. package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
  49. package/dist/operations/modeling/predicate-loader.js +24 -0
  50. package/dist/operations/modeling/predicate-types.d.ts +4 -0
  51. package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
  52. package/dist/operations/modeling/predicate-vocabulary.d.ts +54 -0
  53. package/dist/operations/modeling/predicate-vocabulary.d.ts.map +1 -0
  54. package/dist/operations/modeling/predicate-vocabulary.js +169 -0
  55. package/dist/operations/modeling/requirement-types.d.ts +5 -0
  56. package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
  57. package/dist/operations/modeling/vocabulary-alignment.d.ts +60 -0
  58. package/dist/operations/modeling/vocabulary-alignment.d.ts.map +1 -0
  59. package/dist/operations/modeling/vocabulary-alignment.js +178 -0
  60. package/dist/operations/mutation/contradictions.d.ts +3 -0
  61. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  62. package/dist/operations/mutation/contradictions.js +29 -0
  63. package/dist/operations/mutation/delete.d.ts.map +1 -1
  64. package/dist/operations/mutation/delete.js +33 -1
  65. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +8 -0
  66. package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -0
  67. package/dist/operations/mutation/predicate-vocabulary-guard.js +64 -0
  68. package/dist/operations/mutation/relationships.d.ts +1 -1
  69. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  70. package/dist/operations/mutation/relationships.js +1 -0
  71. package/dist/operations/mutation/saga.d.ts +5 -0
  72. package/dist/operations/mutation/saga.d.ts.map +1 -1
  73. package/dist/operations/mutation/saga.js +10 -0
  74. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  75. package/dist/operations/mutation/serialization.js +2 -0
  76. package/dist/operations/mutation/source-authoring.d.ts +6 -0
  77. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  78. package/dist/operations/mutation/source-authoring.js +65 -26
  79. package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
  80. package/dist/operations/mutation/strict-fact.js +5 -0
  81. package/dist/operations/mutation/types.d.ts +17 -0
  82. package/dist/operations/mutation/types.d.ts.map +1 -1
  83. package/dist/operations/mutation/upsert.d.ts +6 -0
  84. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  85. package/dist/operations/mutation/upsert.js +72 -4
  86. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  87. package/dist/operations/mutation/validate-upsert.js +24 -1
  88. package/dist/operations/mutation/validation.d.ts.map +1 -1
  89. package/dist/operations/mutation/validation.js +16 -3
  90. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  91. package/dist/operations/planning/apply-plan.js +61 -17
  92. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  93. package/dist/operations/planning/compile-intent.js +3 -1
  94. package/dist/operations/proof/code-scope.d.ts +17 -0
  95. package/dist/operations/proof/code-scope.d.ts.map +1 -0
  96. package/dist/operations/proof/code-scope.js +60 -0
  97. package/dist/operations/proof/ingest-proof.d.ts +4 -2
  98. package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
  99. package/dist/operations/proof/ingest-proof.js +207 -74
  100. package/dist/operations/proof/migrate-legacy-receipts.d.ts.map +1 -1
  101. package/dist/operations/proof/migrate-legacy-receipts.js +7 -5
  102. package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
  103. package/dist/operations/proof/prune-receipts.js +7 -5
  104. package/dist/plugins/compose-semantic-classifier.d.ts +6 -1
  105. package/dist/plugins/compose-semantic-classifier.d.ts.map +1 -1
  106. package/dist/plugins/compose-semantic-classifier.js +8 -3
  107. package/dist/plugins/compose-vocabulary-alignment.d.ts +23 -0
  108. package/dist/plugins/compose-vocabulary-alignment.d.ts.map +1 -0
  109. package/dist/plugins/compose-vocabulary-alignment.js +141 -0
  110. package/dist/plugins/external-allowlist.d.ts +7 -0
  111. package/dist/plugins/external-allowlist.d.ts.map +1 -1
  112. package/dist/plugins/external-allowlist.js +13 -0
  113. package/dist/plugins/index.d.ts +2 -0
  114. package/dist/plugins/index.d.ts.map +1 -1
  115. package/dist/plugins/index.js +4 -0
  116. package/dist/plugins/registry.d.ts +2 -1
  117. package/dist/plugins/registry.d.ts.map +1 -1
  118. package/dist/plugins/registry.js +22 -1
  119. package/dist/prolog/codec.d.ts.map +1 -1
  120. package/dist/prolog/codec.js +2 -0
  121. package/dist/prolog.d.ts +36 -0
  122. package/dist/prolog.d.ts.map +1 -1
  123. package/dist/prolog.js +78 -9
  124. package/dist/public/diagnostic-usage.d.ts.map +1 -1
  125. package/dist/public/diagnostic-usage.js +7 -25
  126. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  127. package/dist/public/impact/full-kb-quality.js +4 -12
  128. package/dist/public/operations/catalog.d.ts +36 -7
  129. package/dist/public/operations/catalog.d.ts.map +1 -1
  130. package/dist/public/operations/check-executor.d.ts.map +1 -1
  131. package/dist/public/operations/check-executor.js +10 -2
  132. package/dist/public/operations/check-helpers.d.ts +6 -0
  133. package/dist/public/operations/check-helpers.d.ts.map +1 -1
  134. package/dist/public/operations/check-helpers.js +21 -1
  135. package/dist/public/operations/contracts.d.ts.map +1 -1
  136. package/dist/public/operations/contracts.js +16 -0
  137. package/dist/public/operations/discovery-entities.d.ts +42 -2
  138. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  139. package/dist/public/operations/discovery-entities.js +195 -22
  140. package/dist/public/operations/discovery-executors.d.ts +1 -0
  141. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  142. package/dist/public/operations/discovery-executors.js +75 -46
  143. package/dist/public/operations/migration-plan.d.ts +2 -0
  144. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  145. package/dist/public/operations/migration-plan.js +50 -0
  146. package/dist/public/operations/predicate-schema-conformance.d.ts +41 -0
  147. package/dist/public/operations/predicate-schema-conformance.d.ts.map +1 -0
  148. package/dist/public/operations/predicate-schema-conformance.js +242 -0
  149. package/dist/public/operations/prolog-json.d.ts.map +1 -1
  150. package/dist/public/operations/prolog-json.js +9 -3
  151. package/dist/public/operations/result-envelope.d.ts +34 -1
  152. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  153. package/dist/public/operations/result-envelope.js +78 -2
  154. package/dist/public/operations/runtime-types.d.ts +1 -1
  155. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  156. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  157. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  158. package/dist/public/operations/specs/check-rules.generated.js +8 -1
  159. package/dist/public/operations/specs/check.d.ts +1 -1
  160. package/dist/public/operations/specs/discovery.d.ts +7 -1
  161. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  162. package/dist/public/operations/specs/discovery.js +7 -1
  163. package/dist/public/operations/specs/mutation-schemas.d.ts +27 -4
  164. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  165. package/dist/public/operations/specs/mutation-schemas.js +21 -3
  166. package/dist/public/operations/specs/reporting.d.ts +8 -0
  167. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  168. package/dist/public/operations/specs/reporting.js +46 -15
  169. package/dist/public/operations/specs/upsert.d.ts +28 -5
  170. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  171. package/dist/public/operations/specs/upsert.js +1 -1
  172. package/dist/public/operations/symbol-repair-plan.d.ts.map +1 -1
  173. package/dist/public/operations/symbol-repair-plan.js +8 -3
  174. package/dist/public/schemas/entity.d.ts.map +1 -1
  175. package/dist/public/schemas/entity.js +22 -0
  176. package/dist/public/schemas/relationship.d.ts.map +1 -1
  177. package/dist/public/schemas/relationship.js +1 -0
  178. package/dist/public/skills/kibi-usage/SKILL.md +7 -3
  179. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
  180. package/dist/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
  181. package/dist/public/skills/kibi-usage/resources/source-authoring.md +36 -0
  182. package/dist/public/skills/kibi-usage/resources/workflows.md +52 -1
  183. package/dist/public/telemetry-acceptance.d.ts.map +1 -1
  184. package/dist/public/telemetry-acceptance.js +21 -5
  185. package/dist/relationships/shards.d.ts +6 -0
  186. package/dist/relationships/shards.d.ts.map +1 -1
  187. package/dist/relationships/shards.js +26 -19
  188. package/dist/schemas/entity.schema.json +32 -0
  189. package/dist/traceability/staged-diagnostics.d.ts +1 -1
  190. package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
  191. package/dist/traceability/staged-entity-id-style.d.ts +12 -0
  192. package/dist/traceability/staged-entity-id-style.d.ts.map +1 -0
  193. package/dist/traceability/staged-entity-id-style.js +68 -0
  194. package/dist/traceability/temp-kb.d.ts.map +1 -1
  195. package/dist/traceability/temp-kb.js +8 -0
  196. package/dist/traceability/validate.js +1 -1
  197. package/dist/types/entities.d.ts +2 -0
  198. package/dist/types/entities.d.ts.map +1 -1
  199. package/dist/types/relationships.d.ts +1 -1
  200. package/dist/types/relationships.d.ts.map +1 -1
  201. package/dist/utils/entity-id-style.d.ts +27 -0
  202. package/dist/utils/entity-id-style.d.ts.map +1 -0
  203. package/dist/utils/entity-id-style.js +81 -0
  204. package/dist/utils/git-repository-context.d.ts +50 -0
  205. package/dist/utils/git-repository-context.d.ts.map +1 -0
  206. package/dist/utils/git-repository-context.js +259 -0
  207. package/dist/utils/rule-registry.d.ts +5 -0
  208. package/dist/utils/rule-registry.d.ts.map +1 -1
  209. package/dist/utils/rule-registry.generated.d.ts +37 -0
  210. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  211. package/dist/utils/rule-registry.generated.js +44 -0
  212. package/dist/utils/strict-modeling.d.ts +7 -0
  213. package/dist/utils/strict-modeling.d.ts.map +1 -1
  214. package/dist/utils/strict-modeling.js +11 -0
  215. package/package.json +4 -4
  216. package/schema/entities.pl +60 -1
  217. package/schema/relationships.pl +17 -4
  218. package/schema/validation.pl +118 -20
  219. package/src/public/diagnostic-usage.ts +16 -24
  220. package/src/public/impact/full-kb-quality.ts +4 -16
  221. package/src/public/operations/check-executor.ts +12 -1
  222. package/src/public/operations/check-helpers.ts +27 -1
  223. package/src/public/operations/contracts.ts +19 -0
  224. package/src/public/operations/discovery-entities.ts +292 -23
  225. package/src/public/operations/discovery-executors.ts +91 -55
  226. package/src/public/operations/migration-plan.ts +57 -0
  227. package/src/public/operations/predicate-schema-conformance.ts +362 -0
  228. package/src/public/operations/prolog-json.ts +9 -3
  229. package/src/public/operations/result-envelope.ts +114 -2
  230. package/src/public/operations/runtime-types.ts +1 -1
  231. package/src/public/operations/specs/check-rules.generated.ts +8 -1
  232. package/src/public/operations/specs/discovery.ts +8 -1
  233. package/src/public/operations/specs/mutation-schemas.ts +23 -3
  234. package/src/public/operations/specs/reporting.ts +69 -22
  235. package/src/public/operations/specs/upsert.ts +1 -1
  236. package/src/public/operations/symbol-repair-plan.ts +13 -3
  237. package/src/public/schemas/entity.ts +22 -0
  238. package/src/public/schemas/relationship.ts +1 -0
  239. package/src/public/skills/kibi-usage/SKILL.md +7 -3
  240. package/src/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
  241. package/src/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
  242. package/src/public/skills/kibi-usage/resources/source-authoring.md +36 -0
  243. package/src/public/skills/kibi-usage/resources/workflows.md +52 -1
  244. package/src/public/telemetry-acceptance.ts +37 -6
  245. package/src/schemas/entity.schema.json +32 -0
  246. package/src/schemas/relationship.schema.json +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"discovery-entities.d.ts","sourceRoot":"","sources":["../../../src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AK,CAAC;AAG1C,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,CACT,KAAK,EAAE,sBAAsB,KAC1B,OAAO,CAAC,uBAAuB,CAAC,EACrC,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CAoBlC;AAED,8EAA8E;AAE9E,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EACjC,KAAK,EAAE,sBAAsB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAclC;AAED,gEAAgE;AAEhE,wBAAsB,aAAa,CACjC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB;AAED;;;;GAIG;AAEH,wBAAsB,kBAAkB,CACtC,MAAM,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EAE3D,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EACjC,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAcnB;AAGD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAC3C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAQ3B"}
@@ -1,4 +1,4 @@
1
- import { escapeAtomContent, parseEntityFromBinding, parseEntityFromList, parseListOfLists, } from "../../prolog/codec.js";
1
+ import { escapeAtomContent, normalizeEntityId, parseAtomList, parseEntityFromBinding, parseEntityFromList, parseListOfLists, } from "../../prolog/codec.js";
2
2
  export const VALID_ENTITY_TYPES = [
3
3
  "req",
4
4
  "scenario",
@@ -15,9 +15,21 @@ export function validateEntityType(type) {
15
15
  throw new Error(`Invalid type '${type}'. Valid types: ${VALID_ENTITY_TYPES.join(", ")}. Use a single type value, or omit this parameter to query all entities.`);
16
16
  }
17
17
  }
18
+ /**
19
+ * Proof campaign selection must not materialize every contracted test in a
20
+ * single Prolog result. The specialized projection excludes receipt histories
21
+ * and returns one bounded page at a time.
22
+ */
23
+ export const PROOF_CONTRACT_PAGE_SIZE = 100;
18
24
  // implements REQ-002, REQ-013
19
25
  export function buildEntityGoal(input) {
20
26
  const { type, id, tags, sourceFile } = input;
27
+ if (type === "test" && input.projection === "proof_contract") {
28
+ const idTerm = id ? `some('${escapeAtomContent(id)}')` : "none";
29
+ const limit = input.limit ?? PROOF_CONTRACT_PAGE_SIZE;
30
+ const offset = input.offset ?? 0;
31
+ return `kb_query_proof_contracts(${idTerm},${limit},${offset},Results)`;
32
+ }
21
33
  if (sourceFile) {
22
34
  const safeSource = escapeAtomContent(sourceFile);
23
35
  if (type) {
@@ -53,21 +65,61 @@ export function buildEntityGoal(input) {
53
65
  }
54
66
  return "findall([Id,Type,Props], kb_entity(Id, Type, Props), Results)";
55
67
  }
68
+ /**
69
+ * Full test entities carry their receipt histories, which only grow. Callers
70
+ * that must see every full entity of a type page through the indexed query so
71
+ * no single Prolog answer can approach the bounded output capacity.
72
+ */
73
+ const FULL_ENTITY_PAGE_SIZE = 25;
74
+ // implements REQ-002, REQ-013
75
+ export async function loadEntitiesPaged(prolog, type, pageSize = FULL_ENTITY_PAGE_SIZE) {
76
+ if (!Number.isInteger(pageSize) || pageSize <= 0) {
77
+ throw new Error("loadEntitiesPaged pageSize must be a positive integer");
78
+ }
79
+ const entities = [];
80
+ for (let offset = 0;; offset += pageSize) {
81
+ const page = await loadEntities(prolog, { type, limit: pageSize, offset });
82
+ entities.push(...page);
83
+ if (page.length < pageSize)
84
+ break;
85
+ }
86
+ return dedupeEntities(entities);
87
+ }
56
88
  // implements REQ-002, REQ-013
57
89
  export async function loadEntities(prolog, input) {
58
90
  validateEntityType(input.type);
59
- const queryResult = await prolog.query(buildEntityGoal(input));
60
- if (!queryResult.success) {
61
- throw new Error(queryResult.error || "Query failed with unknown error");
62
- }
63
- let entities = [];
64
- const resultsBinding = queryResult.bindings.Results;
65
- const resultBinding = queryResult.bindings.Result;
66
- if (resultsBinding) {
67
- entities = parseListOfLists(resultsBinding).map(parseEntityFromList);
91
+ const readPage = async (pageInput) => {
92
+ const queryResult = await prolog.query(buildEntityGoal(pageInput));
93
+ if (!queryResult.success) {
94
+ throw new Error(queryResult.error || "Query failed with unknown error");
95
+ }
96
+ const resultsBinding = queryResult.bindings.Results;
97
+ const resultBinding = queryResult.bindings.Result;
98
+ if (resultsBinding) {
99
+ return parseListOfLists(resultsBinding).map(parseEntityFromList);
100
+ }
101
+ return resultBinding ? [parseEntityFromBinding(resultBinding)] : [];
102
+ };
103
+ let entities;
104
+ if (input.type === "test" &&
105
+ input.projection === "proof_contract" &&
106
+ input.id === undefined &&
107
+ input.limit === undefined &&
108
+ input.offset === undefined) {
109
+ entities = [];
110
+ for (let offset = 0;; offset += PROOF_CONTRACT_PAGE_SIZE) {
111
+ const page = await readPage({
112
+ ...input,
113
+ limit: PROOF_CONTRACT_PAGE_SIZE,
114
+ offset,
115
+ });
116
+ entities.push(...page);
117
+ if (page.length < PROOF_CONTRACT_PAGE_SIZE)
118
+ break;
119
+ }
68
120
  }
69
- else if (resultBinding) {
70
- entities = [parseEntityFromBinding(resultBinding)];
121
+ else {
122
+ entities = await readPage(input);
71
123
  }
72
124
  if (input.tags && input.tags.length > 0) {
73
125
  const requested = new Set(input.tags.map((tag) => tag.trim()));
@@ -91,23 +143,63 @@ export function paginateResults(results, limit = 100, offset = 0) {
91
143
  */
92
144
  // implements REQ-kibi-operation-interface-parity, REQ-mcp-search-discovery
93
145
  export const SEARCH_CANDIDATE_PAGE_SIZE = 500;
146
+ function isPrologOutputOverflow(error) {
147
+ return error instanceof Error && error.message.includes("ENOBUFS");
148
+ }
94
149
  // implements REQ-kibi-operation-interface-parity, REQ-mcp-search-discovery
95
150
  export async function loadSearchCandidates(prolog, input, signal) {
151
+ // Call through the port property, never via a detached local: EngineClient
152
+ // searchEntities depends on `this` (this.command), and the PrologPort
153
+ // contract does not promise a pre-bound method. Ports without the indexed
154
+ // engine method run the same bounded Prolog search through `query`.
155
+ const readPage = (page) => {
156
+ if (prolog.searchEntities)
157
+ return prolog.searchEntities(page, signal);
158
+ const query = prolog.query;
159
+ if (query === undefined)
160
+ return Promise.resolve({ entities: [], count: 0 });
161
+ return searchEntitiesViaQuery({ query: (goal, querySignal) => query.call(prolog, goal, querySignal) }, page, signal);
162
+ };
163
+ return readCandidatePages(readPage, input);
164
+ }
165
+ /**
166
+ * Projected candidate rows for every entity (optionally of one type), in id
167
+ * order, bounded by `maxCandidates`. For semantic discovery that has no
168
+ * lexical token to pre-filter candidates.
169
+ */
170
+ // implements REQ-kibi-operation-interface-parity, REQ-mcp-search-discovery
171
+ export async function listSearchCandidates(prolog, input, signal) {
172
+ const type = input.type ? `'${escapeAtomContent(input.type)}'` : "none";
173
+ return readCandidatePages((page) => readRowsAndCount(prolog, `kb_list_search_candidates(${type}, ${page.limit}, ${page.offset}, Rows, Count)`, "Search candidate listing failed", signal), { query: "", maxCandidates: input.maxCandidates });
174
+ }
175
+ async function readCandidatePages(readPage, input) {
96
176
  const maxCandidates = input.maxCandidates ?? Number.POSITIVE_INFINITY;
97
177
  const candidates = [];
98
178
  let offset = 0;
99
179
  let total = Number.POSITIVE_INFINITY;
180
+ let pageSize = SEARCH_CANDIDATE_PAGE_SIZE;
100
181
  while (offset < total && candidates.length < maxCandidates) {
101
- // Call through the port property, never via a detached local: EngineClient
102
- // searchEntities depends on `this` (this.command), and the PrologPort
103
- // contract does not promise a pre-bound method.
104
- const page = await prolog.searchEntities?.({
105
- query: input.query,
106
- ...(input.type !== undefined ? { type: input.type } : {}),
107
- limit: SEARCH_CANDIDATE_PAGE_SIZE,
108
- offset,
109
- }, signal);
110
- if (!page || page.entities.length === 0)
182
+ let page;
183
+ try {
184
+ page = await readPage({
185
+ query: input.query,
186
+ ...(input.type !== undefined ? { type: input.type } : {}),
187
+ limit: pageSize,
188
+ offset,
189
+ });
190
+ }
191
+ catch (error) {
192
+ // A page of unusually large rows can still exceed the bounded Prolog
193
+ // output. Halve the page and retry the same offset; the smaller size is
194
+ // kept for the rest of the scan. Only a single row that overflows on its
195
+ // own is a real failure.
196
+ if (pageSize > 1 && isPrologOutputOverflow(error)) {
197
+ pageSize = Math.max(1, Math.floor(pageSize / 2));
198
+ continue;
199
+ }
200
+ throw error;
201
+ }
202
+ if (page.entities.length === 0)
111
203
  break;
112
204
  candidates.push(...page.entities);
113
205
  total = page.count;
@@ -117,6 +209,87 @@ export async function loadSearchCandidates(prolog, input, signal) {
117
209
  ? candidates.slice(0, maxCandidates)
118
210
  : candidates;
119
211
  }
212
+ function searchEntitiesViaQuery(prolog, input, signal) {
213
+ const type = input.type ? `'${escapeAtomContent(input.type)}'` : "none";
214
+ return readRowsAndCount(prolog, `kb_search_entities(${type}, '${escapeAtomContent(input.query)}', ${input.limit}, ${input.offset}, Rows, Count)`, "Indexed search candidate query failed", signal);
215
+ }
216
+ async function readRowsAndCount(prolog, goal, errorLabel, signal) {
217
+ const result = await prolog.query(goal, signal);
218
+ if (!result.success) {
219
+ // Same message as the engine client's indexed methods, so both surfaces
220
+ // report a failure identically.
221
+ throw new Error(result.error ?? errorLabel);
222
+ }
223
+ const entities = result.bindings.Rows
224
+ ? parseListOfLists(result.bindings.Rows).map(parseEntityFromList)
225
+ : [];
226
+ const count = Number.parseInt(result.bindings.Count ?? "0", 10);
227
+ return { entities, count: Number.isFinite(count) ? count : entities.length };
228
+ }
229
+ /**
230
+ * Rows per `kb_query_entities` request. Full entities carry receipt
231
+ * histories, so a caller-sized page (up to 100k rows) is split into bounded
232
+ * requests and concatenated; the reported count is the total match count.
233
+ */
234
+ export const ENTITY_QUERY_CHUNK_SIZE = 25;
235
+ // implements REQ-kibi-operation-interface-parity
236
+ export async function queryEntityChunks(readChunk, input) {
237
+ const entities = [];
238
+ let count = 0;
239
+ let first = true;
240
+ while (first || entities.length < input.limit) {
241
+ const chunkLimit = Math.min(ENTITY_QUERY_CHUNK_SIZE, input.limit - entities.length);
242
+ const chunk = await readChunk({
243
+ ...input,
244
+ limit: chunkLimit,
245
+ offset: input.offset + entities.length,
246
+ });
247
+ if (first)
248
+ count = chunk.count;
249
+ first = false;
250
+ entities.push(...chunk.entities);
251
+ if (chunk.entities.length < chunkLimit || chunkLimit === 0)
252
+ break;
253
+ }
254
+ return { entities, count };
255
+ }
256
+ /** Bounded `kb_query_entities` paging for ports without the engine method. */
257
+ // implements REQ-kibi-operation-interface-parity
258
+ export function queryEntitiesViaQuery(prolog, input, signal) {
259
+ const atom = (value) => value === undefined ? "none" : `'${escapeAtomContent(value)}'`;
260
+ const tags = `[${(input.tags ?? []).map((tag) => `'${escapeAtomContent(tag)}'`).join(",")}]`;
261
+ return queryEntityChunks((chunk) => readRowsAndCount(prolog, `kb_query_entities(${atom(chunk.type)}, ${atom(chunk.id)}, ${tags}, ${atom(chunk.sourceFile)}, ${chunk.limit}, ${chunk.offset}, Rows, Count)`, "Indexed entity query failed", signal), input);
262
+ }
263
+ /** Every entity id, without materializing entity properties. */
264
+ // implements REQ-002
265
+ export async function loadEntityIds(prolog) {
266
+ const result = await prolog.query("kb_entity_ids(Ids)");
267
+ if (!result.success) {
268
+ throw new Error(`Entity id enumeration failed: ${result.error ?? "Unknown error"}`);
269
+ }
270
+ return parseAtomList(result.bindings.Ids ?? "[]").map(normalizeEntityId);
271
+ }
272
+ /**
273
+ * Replace projected search candidates with complete entities, one bounded
274
+ * query per entity. Used only for the final result page when a caller asks
275
+ * for full entity bodies.
276
+ */
277
+ // implements REQ-mcp-search-discovery
278
+ export async function reloadFullEntities(prolog, matches) {
279
+ const reloaded = [];
280
+ for (const match of matches) {
281
+ const id = String(match.entity.id ?? "");
282
+ const type = match.entity.type;
283
+ const [full] = id
284
+ ? await loadEntities(prolog, {
285
+ id,
286
+ ...(typeof type === "string" ? { type } : {}),
287
+ })
288
+ : [];
289
+ reloaded.push(full ? { ...match, entity: full } : match);
290
+ }
291
+ return reloaded;
292
+ }
120
293
  // implements REQ-002
121
294
  export function dedupeEntities(entities) {
122
295
  const seen = new Set();
@@ -25,6 +25,7 @@ export type SearchInput = {
25
25
  readonly semanticFacets?: IntentSearchFacets;
26
26
  readonly sourceLocations?: readonly SourceLocation[];
27
27
  readonly minScore?: number;
28
+ readonly fields?: "summary" | "full";
28
29
  };
29
30
  export type SearchPayload = {
30
31
  readonly results: readonly (SearchMatch | IntentSearchMatch)[];
@@ -1 +1 @@
1
- {"version":3,"file":"discovery-executors.d.ts","sourceRoot":"","sources":["../../../src/public/operations/discovery-executors.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EACL,KAAK,qBAAqB,EAI3B,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAGnB,MAAM,qBAAqB,CAAC;AAK7B,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM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AQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;KACpC,CAAC;IACF,QAAQ,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC;IAC9C,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;QACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;QAChC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;QAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACzD,CAAC;CACH,CAAC;AAqBF,wBAAsB,YAAY,CAChC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAiExC;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAiGzC;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAuOzC"}
1
+ {"version":3,"file":"discovery-executors.d.ts","sourceRoot":"","sources":["../../../src/public/operations/discovery-executors.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EACL,KAAK,qBAAqB,EAI3B,MAAM,6BAA6B,C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B,GACxB,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CA2CxC;AAmDD,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAiGzC;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CA4OzC"}
@@ -1,10 +1,11 @@
1
+ import { compilerFingerprintReason } from "../../commands/sync/cache.js";
1
2
  import { EngineClient } from "../../engine.js";
2
3
  import { executeIntentSearch, validateIntentSearchInput, } from "../../intent-search.js";
3
4
  import { classifyActivation } from "../../operations/bootstrap/activation.js";
4
5
  import { rankEntities } from "../../search-ranking.js";
5
6
  import { resolveBranchAttachment } from "../../utils/branch-resolver.js";
6
7
  import { branchStoreReason, inspectBranchStore, storeLockJournalReason, } from "../../utils/branch-store.js";
7
- import { loadEntities, loadSearchCandidates, paginateResults, validateEntityType, } from "./discovery-entities.js";
8
+ import { loadSearchCandidates, paginateResults, queryEntitiesViaQuery, reloadFullEntities, validateEntityType, } from "./discovery-entities.js";
8
9
  import { buildActionsFromStatus, readMigrationConfigStatus, } from "./migration-plan.js";
9
10
  import { OperationJsonDecodeError, runOperationJsonQuery, } from "./prolog-json.js";
10
11
  import { readWorkspaceSnapshot } from "./workspace-snapshot.js";
@@ -28,43 +29,28 @@ export async function executeQuery(input, context) {
28
29
  // implements REQ-kibi-operation-interface-parity
29
30
  const { type, id, tags, sourceFile, limit = 100, offset = 0 } = input;
30
31
  try {
32
+ validateEntityType(type);
31
33
  const prolog = requireProlog(context);
32
34
  const signal = context.signal;
33
- const indexedPage = prolog.queryEntities
34
- ? await prolog.queryEntities({
35
- ...(type !== undefined ? { type } : {}),
36
- ...(id !== undefined ? { id } : {}),
37
- ...(tags !== undefined ? { tags } : {}),
38
- ...(sourceFile !== undefined ? { sourceFile } : {}),
39
- limit,
40
- offset,
41
- }, signal)
42
- : null;
43
- if (indexedPage !== null) {
44
- const paginated = indexedPage.entities;
45
- const text = indexedPage.count === 0
46
- ? `No entities found${type ? ` of type '${type}'` : ""}.`
47
- : `Found ${indexedPage.count} entities${type ? ` of type '${type}'` : ""}. Showing ${paginated.length} (offset ${offset}, limit ${limit}): ${paginated
48
- .map((entity) => {
49
- const entityId = String(entity.id ?? "").replace(/^file:\/\/.*\//, "");
50
- return `${entityId} (${String(entity.title ?? "")}, status=${String(entity.status ?? "")})`;
51
- })
52
- .join(", ")}`;
53
- return {
54
- content: [{ type: "text", text }],
55
- structuredContent: { entities: paginated, count: indexedPage.count },
56
- };
57
- }
58
- const entities = await loadEntities(requireProlog(context), {
35
+ const pageInput = {
59
36
  ...(type !== undefined ? { type } : {}),
60
37
  ...(id !== undefined ? { id } : {}),
61
38
  ...(tags !== undefined ? { tags } : {}),
62
39
  ...(sourceFile !== undefined ? { sourceFile } : {}),
63
- });
64
- const paginated = paginateResults(entities, limit, offset);
65
- const text = entities.length === 0
40
+ limit,
41
+ offset,
42
+ };
43
+ // Both paths return one bounded page plus the total count. Ports without
44
+ // the engine method page kb_query_entities through `query` instead of
45
+ // materializing every matching entity (receipt histories make an
46
+ // all-tests answer exceed the bounded engine output).
47
+ const indexedPage = prolog.queryEntities
48
+ ? await prolog.queryEntities(pageInput, signal)
49
+ : await queryEntitiesViaQuery(prolog, pageInput, signal);
50
+ const paginated = indexedPage.entities;
51
+ const text = indexedPage.count === 0
66
52
  ? `No entities found${type ? ` of type '${type}'` : ""}.`
67
- : `Found ${entities.length} entities${type ? ` of type '${type}'` : ""}. Showing ${paginated.length} (offset ${offset}, limit ${limit}): ${paginated
53
+ : `Found ${indexedPage.count} entities${type ? ` of type '${type}'` : ""}. Showing ${paginated.length} (offset ${offset}, limit ${limit}): ${paginated
68
54
  .map((entity) => {
69
55
  const entityId = String(entity.id ?? "").replace(/^file:\/\/.*\//, "");
70
56
  return `${entityId} (${String(entity.title ?? "")}, status=${String(entity.status ?? "")})`;
@@ -72,7 +58,7 @@ export async function executeQuery(input, context) {
72
58
  .join(", ")}`;
73
59
  return {
74
60
  content: [{ type: "text", text }],
75
- structuredContent: { entities: paginated, count: entities.length },
61
+ structuredContent: { entities: paginated, count: indexedPage.count },
76
62
  };
77
63
  }
78
64
  catch (error) {
@@ -80,9 +66,48 @@ export async function executeQuery(input, context) {
80
66
  throw new Error(`Query execution failed: ${message}`);
81
67
  }
82
68
  }
69
+ /**
70
+ * Identifying metadata a caller needs to decide which hits to open.
71
+ *
72
+ * Search is a discovery step, so returning complete entity bodies for every
73
+ * hit spends a large share of an agent's context before it has chosen
74
+ * anything. Full bodies stay available through `fields: "full"` or a follow-up
75
+ * kb_query for the exact ids.
76
+ */
77
+ const SUMMARY_ENTITY_FIELDS = [
78
+ "id",
79
+ "type",
80
+ "title",
81
+ "status",
82
+ "priority",
83
+ "tags",
84
+ "source",
85
+ "sourceFile",
86
+ "updated_at",
87
+ ];
88
+ function summarizeMatch(match) {
89
+ const entity = match.entity;
90
+ if (entity === null || typeof entity !== "object" || Array.isArray(entity)) {
91
+ return match;
92
+ }
93
+ const row = entity;
94
+ const summary = {};
95
+ for (const field of SUMMARY_ENTITY_FIELDS) {
96
+ if (row[field] !== undefined)
97
+ summary[field] = row[field];
98
+ }
99
+ return { ...match, entity: summary };
100
+ }
101
+ // Candidates are projected rows, so `fields: "full"` reloads the final page's
102
+ // complete entities by id (one bounded query each).
103
+ async function projectMatches(prolog, matches, fields) {
104
+ return fields === "full"
105
+ ? reloadFullEntities(prolog, matches)
106
+ : matches.map(summarizeMatch);
107
+ }
83
108
  export async function executeSearch(input, context) {
84
109
  // implements REQ-kibi-operation-interface-parity, REQ-mcp-search-discovery
85
- const { query, type, limit = 20, offset = 0, rankingMode = "legacy", semanticFacets, sourceLocations, minScore, } = input;
110
+ const { query, type, limit = 20, offset = 0, rankingMode = "legacy", semanticFacets, sourceLocations, minScore, fields = "summary", } = input;
86
111
  const trimmedQuery = query.trim();
87
112
  if (!trimmedQuery) {
88
113
  throw new Error("Search execution failed: query must be a non-empty string");
@@ -112,23 +137,19 @@ export async function executeSearch(input, context) {
112
137
  return {
113
138
  content: [{ type: "text", text }],
114
139
  structuredContent: {
115
- results: paginated,
140
+ results: await projectMatches(prolog, paginated, fields),
116
141
  count: intentResult.matches.length,
117
142
  queryAnalysis: intentResult.analysis,
118
143
  },
119
144
  };
120
145
  }
121
- const indexedCandidates = prolog.searchEntities
122
- ? await loadSearchCandidates(prolog, {
123
- query: trimmedQuery,
124
- ...(type !== undefined ? { type } : {}),
125
- }, context.signal)
126
- : null;
127
- const entities = indexedCandidates
128
- ? [...indexedCandidates]
129
- : await loadEntities(prolog, {
130
- ...(type !== undefined ? { type } : {}),
131
- });
146
+ // Candidates are projected rows (no receipt histories or other large
147
+ // structured properties); ports without the engine method run the same
148
+ // bounded Prolog search through `query`.
149
+ const entities = await loadSearchCandidates(prolog, {
150
+ query: trimmedQuery,
151
+ ...(type !== undefined ? { type } : {}),
152
+ }, context.signal);
132
153
  const matches = await rankEntities(entities, trimmedQuery, context.workspaceRoot);
133
154
  const paginated = paginateResults(matches, limit, offset);
134
155
  const text = matches.length === 0
@@ -138,7 +159,10 @@ export async function executeSearch(input, context) {
138
159
  .join(", ")}`;
139
160
  return {
140
161
  content: [{ type: "text", text }],
141
- structuredContent: { results: paginated, count: matches.length },
162
+ structuredContent: {
163
+ results: await projectMatches(prolog, paginated, fields),
164
+ count: matches.length,
165
+ },
142
166
  };
143
167
  }
144
168
  catch (error) {
@@ -232,6 +256,7 @@ export async function executeStatus(_input, context) {
232
256
  const existingReasons = payload.staleReasons ?? [];
233
257
  const storeReason = branchStoreReason(store);
234
258
  const lockReason = storeLockJournalReason(store.path);
259
+ const compilerReason = compilerFingerprintReason(store.path);
235
260
  const engineReason = engineStatus
236
261
  ? {
237
262
  code: engineStatus.errorCode ?? "engine_status_unavailable",
@@ -249,10 +274,14 @@ export async function executeStatus(_input, context) {
249
274
  ...existingReasons,
250
275
  ...(storeReason ? [storeReason] : []),
251
276
  ...(lockReason ? [lockReason] : []),
277
+ ...(compilerReason ? [compilerReason] : []),
252
278
  ...(engineReason ? [engineReason] : []),
253
279
  ].sort((left, right) => String(left.path ?? "").localeCompare(String(right.path ?? "")));
254
280
  const enrichedPayload = {
255
281
  ...payload,
282
+ // Source hashes can all match while the compilation itself is lossy, so
283
+ // a compiler contract change alone makes the store stale.
284
+ ...(compilerReason ? { syncState: "stale", dirty: true } : {}),
256
285
  branchAttachment: attachment,
257
286
  branchStore: store,
258
287
  ...(engineStatus ? { engineStatus } : {}),
@@ -70,6 +70,8 @@ export declare function compareReadyActionIds(left: string, right: string, byId:
70
70
  export declare function buildMigrationPlan(input?: PlanInput): MigrationPlan;
71
71
  export declare function mergeMigrationPlans(plans: readonly MigrationPlan[]): MigrationPlan;
72
72
  export declare function migrationAction(input: Partial<MigrationAction> & Pick<MigrationAction, "id" | "code">): MigrationAction;
73
+ /** Migration code for mechanical predicate namespace/alias repairs. */
74
+ export declare const PREDICATE_SCHEMA_ALIGNMENT_CODE = "predicate_schema_alignment";
73
75
  export declare function buildActionsFromCheck(input: {
74
76
  violations?: readonly Readonly<Record<string, unknown>>[];
75
77
  qualityDiagnostics?: readonly Readonly<Record<string, unknown>>[];
@@ -1 +1 @@
1
- {"version":3,"file":"migration-plan.d.ts","sourceRoot":"","sources":["../../../src/public/operations/migration-plan.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,sBAAsB,EAAG,wBAAiC,CAAC;AAExE,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,SAAS,CAAC;AACvD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;AAChF,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;AAErE,MAAM,MAAM,mBAAmB,GAC3B,QAAQ,CAAC;IACP,IAAI,EAAE,WA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AAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC,CAAC;AAEH,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,GACpB,qBAAqB,CA8BvB;AAwBD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACrD,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAChD,YAAY,CAAC,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAC5D,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC,GAAG,aAAa,CA6MhB"}
@@ -197,6 +197,51 @@ function actionDefaults(input) {
197
197
  export function migrationAction(input) {
198
198
  return actionDefaults(input);
199
199
  }
200
+ /**
201
+ * A predicate-schema-conformance finding whose repair is mechanical (move to
202
+ * the only matching schema namespace, rewrite declared aliases) becomes an
203
+ * automatic action carrying the exact kb_upsert input, so it is reviewable in
204
+ * the plan and replayable through either surface.
205
+ */
206
+ // implements REQ-kibi-predicate-vocabulary-migration
207
+ function predicateSchemaAlignmentAction(diagnostic) {
208
+ if (diagnostic.id !== "rule.predicate-schema-conformance")
209
+ return null;
210
+ const evidence = isRecord(diagnostic.evidence) ? diagnostic.evidence : null;
211
+ const repair = evidence !== null && isRecord(evidence.repair) ? evidence.repair : null;
212
+ if (repair === null ||
213
+ repair.type !== "fact" ||
214
+ typeof repair.id !== "string" ||
215
+ !isRecord(repair.properties)) {
216
+ return null;
217
+ }
218
+ return migrationAction({
219
+ id: `predicate-schema-alignment-${repair.id}`,
220
+ code: PREDICATE_SCHEMA_ALIGNMENT_CODE,
221
+ category: "semantic",
222
+ safety: "automatic",
223
+ autoApplicable: true,
224
+ invocation: { kind: "operation", name: "kb_upsert", input: repair },
225
+ affectedEntityIds: [repair.id],
226
+ affectedFiles: typeof diagnostic.source === "string" ? [diagnostic.source] : [],
227
+ postconditions: [
228
+ {
229
+ rule: "predicate-schema-conformance",
230
+ entityId: repair.id,
231
+ findings: 0,
232
+ },
233
+ ],
234
+ evidence: {
235
+ issue: evidence?.issue,
236
+ namespace: evidence?.namespace,
237
+ alignment: evidence?.alignment,
238
+ rewrites: evidence?.rewrites,
239
+ },
240
+ });
241
+ }
242
+ /** Migration code for mechanical predicate namespace/alias repairs. */
243
+ export const PREDICATE_SCHEMA_ALIGNMENT_CODE = "predicate_schema_alignment";
244
+ // implements REQ-agent-guided-migration-orchestration, REQ-kibi-predicate-vocabulary-migration
200
245
  export function buildActionsFromCheck(input) {
201
246
  const actions = [];
202
247
  for (const [index, violation] of (input.violations ?? []).entries()) {
@@ -225,6 +270,11 @@ export function buildActionsFromCheck(input) {
225
270
  ? diagnostic.suggestion
226
271
  : "Review this quality diagnostic.";
227
272
  const blocking = diagnostic.blocking === true;
273
+ const predicateRepair = predicateSchemaAlignmentAction(diagnostic);
274
+ if (predicateRepair !== null) {
275
+ actions.push(predicateRepair);
276
+ continue;
277
+ }
228
278
  actions.push(migrationAction({
229
279
  id: `diagnostic-${id}-${entityId || "workspace"}-${index + 1}`,
230
280
  code: `quality_${id}`,
@@ -0,0 +1,41 @@
1
+ import { type ArgumentRewrite, type UndeclaredArgument } from "../../operations/modeling/predicate-vocabulary.js";
2
+ import type { Violation } from "../../utils/rule-registry.js";
3
+ import type { PrologPort } from "./runtime-types.js";
4
+ type Entity = Readonly<Record<string, unknown>>;
5
+ /**
6
+ * Exact kb_upsert input that repairs one predicate fact mechanically: move it
7
+ * to the only namespace whose schema matches, and/or replace alias spellings
8
+ * with their declared constants. Present only when nothing is left for review.
9
+ */
10
+ export type PredicateFactRepair = Readonly<{
11
+ type: "fact";
12
+ id: string;
13
+ properties: Readonly<Record<string, unknown>>;
14
+ }>;
15
+ export type PredicateConformanceEvidence = Readonly<{
16
+ factId: string;
17
+ predicateName: string;
18
+ namespace: string;
19
+ arity: number;
20
+ issue: "missing_schema" | "undeclared_constant" | "alias_in_use";
21
+ schemaId: string | null;
22
+ alignment: Readonly<{
23
+ namespace: string;
24
+ schemaId: string;
25
+ origin: "project_local" | "built_in";
26
+ }> | null;
27
+ candidateNamespaces: readonly string[];
28
+ rewrites: readonly ArgumentRewrite[];
29
+ undeclared: readonly UndeclaredArgument[];
30
+ repair: PredicateFactRepair | null;
31
+ }>;
32
+ /**
33
+ * Predicate facts must match a schema (project-local, or the built-in catalog
34
+ * in the default namespace) with the same namespace, name, and arity, and
35
+ * must use declared constants where the schema closes an argument.
36
+ */
37
+ export declare function evaluatePredicateSchemaConformance(facts: readonly Entity[]): Violation[];
38
+ /** Load every fact once and evaluate predicate conformance. */
39
+ export declare function collectPredicateSchemaConformanceViolations(prolog: Pick<PrologPort, "query">): Promise<Violation[]>;
40
+ export {};
41
+ //# sourceMappingURL=predicate-schema-conformance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate-schema-conformance.d.ts","sourceRoot":"","sources":["../../../src/public/operations/predicate-schema-conformance.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAMxB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM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