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
package/dist/prolog.js CHANGED
@@ -23,7 +23,7 @@ import { fileURLToPath } from "node:url";
23
23
  import { getKbPlPathOverride, isPrologDebugEnabled } from "./env.js";
24
24
  import { extractPrologErrorRecord, } from "./prolog/error-terms.js";
25
25
  const importMetaDir = path.dirname(fileURLToPath(import.meta.url));
26
- const PROLOG_OUTPUT_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
26
+ const DEFAULT_PROLOG_OUTPUT_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
27
27
  const PROLOG_OUTPUT_OVERFLOW_ERROR = "Query exceeded bounded Prolog output capacity (ENOBUFS); narrow the operation or reduce stored entity size";
28
28
  const INTERACTIVE_QUERY_FRAME_END = "__KIBI_QUERY_FRAME_END__";
29
29
  const require = createRequire(import.meta.url);
@@ -79,6 +79,22 @@ export function resolveKbPlPath() {
79
79
  throw new Error("Unable to resolve kb.pl. Expected kibi-core to be installed (node_modules) " +
80
80
  "or to be running inside the monorepo checkout.");
81
81
  }
82
+ /**
83
+ * Raised when a query reaches an interactive process that was started and
84
+ * later terminated (output overflow, timeout, crash, or explicit terminate).
85
+ * Such a port must be restarted by its owner (the engine daemon recycles it);
86
+ * it never degrades into isolated one-shot SWI processes, which would lose
87
+ * the attached KB and every module loaded into the interactive session.
88
+ */
89
+ export class PrologProcessTerminatedError extends Error {
90
+ code = "prolog_process_terminated";
91
+ reason;
92
+ constructor(reason) {
93
+ super(`Kibi Prolog process is no longer running (${reason}); the interactive session and its attached KB were lost. The owning engine must restart it before serving more queries — run 'kibi engine stop' and retry if this persists.`);
94
+ this.name = "PrologProcessTerminatedError";
95
+ this.reason = reason;
96
+ }
97
+ }
82
98
  // implements REQ-core-prolog-process-management
83
99
  export function registerProcessExitOnce(current, handler, on = (event, listener) => process.on(event, listener)) {
84
100
  if (current)
@@ -108,9 +124,23 @@ export class PrologProcess {
108
124
  useOneShotMode;
109
125
  attachedKbPath = null;
110
126
  onProcessExit = null;
127
+ maxOutputBytes;
128
+ /**
129
+ * Set once start() spawned an interactive process. From then on the
130
+ * isolated one-shot fallback is unreachable: a lost interactive process
131
+ * must fail loudly instead of silently changing execution semantics.
132
+ */
133
+ interactiveStarted = false;
134
+ terminationReason = null;
111
135
  constructor(options = {}) {
112
136
  this.swiplPath = options.swiplPath || "swipl";
113
137
  this.timeout = options.timeout || 30000;
138
+ this.maxOutputBytes =
139
+ options.maxOutputBytes !== undefined &&
140
+ Number.isInteger(options.maxOutputBytes) &&
141
+ options.maxOutputBytes > 0
142
+ ? options.maxOutputBytes
143
+ : DEFAULT_PROLOG_OUTPUT_MAX_BUFFER_BYTES;
114
144
  this.useOneShotMode =
115
145
  options.oneShot ??
116
146
  (process.env.NODE_ENV === "test" &&
@@ -120,11 +150,28 @@ export class PrologProcess {
120
150
  attachProcessExitHandler(on = (event, listener) => process.on(event, listener)) {
121
151
  this.onProcessExit = bindProcessExitHandler(this.onProcessExit, () => this.terminate(), on);
122
152
  }
153
+ /**
154
+ * True when every query runs in its own isolated SWI process, so callers
155
+ * must not rely on state (loaded modules) carried between queries.
156
+ */
157
+ get oneShotMode() {
158
+ return this.useOneShotMode || !this.interactiveStarted;
159
+ }
160
+ /**
161
+ * True once a started interactive process has been lost. The owner must
162
+ * restart it (and re-establish its session state) before querying again.
163
+ */
164
+ needsRestart() {
165
+ return this.interactiveStarted && !this.isProcessUsable();
166
+ }
123
167
  async start() {
124
168
  if (!existsSync(this.swiplPath) && this.swiplPath !== "swipl") {
125
169
  throw new Error(`SWI-Prolog not found at ${this.swiplPath}. Please install SWI-Prolog or check your PATH.`);
126
170
  }
127
171
  const kbPath = resolveKbPlPath();
172
+ this.interactiveStarted = true;
173
+ this.terminationReason = null;
174
+ this.invalidateCache();
128
175
  this.process = spawn(this.swiplPath, [
129
176
  "-g",
130
177
  `use_module('${kbPath}'), use_module(library(semweb/rdf_db)), set_prolog_flag(answer_write_options, [max_depth(0), quoted(true)])`,
@@ -148,6 +195,16 @@ export class PrologProcess {
148
195
  this.process.stderr.on("data", (chunk) => {
149
196
  this.appendErrorChunk(chunk);
150
197
  });
198
+ // A write racing the child's death (native crash, external kill) fails
199
+ // asynchronously with EPIPE. Unhandled, that error event crashes the
200
+ // whole host (the engine daemon); record the loss instead so the owner
201
+ // sees needsRestart() and the in-flight query reports the termination.
202
+ const child = this.process;
203
+ child.stdin?.on("error", (error) => {
204
+ if (this.process === child) {
205
+ this.terminationReason ??= `stdin ${error.code ?? "error"}`;
206
+ }
207
+ });
151
208
  this.process.stdin.write("true.\n");
152
209
  this.attachProcessExitHandler();
153
210
  await this.waitForReady();
@@ -223,10 +280,10 @@ export class PrologProcess {
223
280
  // runtimes provide an EngineClient, while explicitly attached callers
224
281
  // call start() and stay interactive; this fallback never participates
225
282
  // in the engine-backed workflow.
226
- if (this.process === null) {
283
+ if (this.process === null && !this.interactiveStarted) {
227
284
  return this.execOneShot(goal, this.attachedKbPath);
228
285
  }
229
- throw new Error("Prolog process not started");
286
+ throw this.lostProcessError();
230
287
  }
231
288
  const runInteractiveQuery = async () => {
232
289
  this.clearQueryBuffers();
@@ -264,6 +321,7 @@ export class PrologProcess {
264
321
  console.error(`[prolog debug] runtime=${runtime ?? "unknown"} packages=${process.env.KIBI_PACKAGE_VERSIONS ?? KIBI_PACKAGE_VERSIONS}`);
265
322
  }
266
323
  settled = true;
324
+ this.terminationReason = `query timeout: ${goalLabel}`;
267
325
  void this.terminate().finally(() => {
268
326
  reject(new Error(msg));
269
327
  });
@@ -275,6 +333,7 @@ export class PrologProcess {
275
333
  if (this.outputOverflowed) {
276
334
  clearTimeout(timeoutId);
277
335
  settled = true;
336
+ this.terminationReason = `output overflow (ENOBUFS): ${goalLabel}`;
278
337
  void this.terminate().finally(() => {
279
338
  resolve({
280
339
  success: false,
@@ -287,6 +346,7 @@ export class PrologProcess {
287
346
  if (!this.isProcessUsable()) {
288
347
  clearTimeout(timeoutId);
289
348
  settled = true;
349
+ this.terminationReason ??= `process exited during query: ${goalLabel}`;
290
350
  resolve({
291
351
  success: false,
292
352
  bindings: {},
@@ -358,7 +418,7 @@ export class PrologProcess {
358
418
  await previousQuery;
359
419
  try {
360
420
  if (!this.isProcessUsable()) {
361
- throw new Error("Prolog process not started");
421
+ throw this.lostProcessError();
362
422
  }
363
423
  return await runInteractiveQuery();
364
424
  }
@@ -508,7 +568,7 @@ export class PrologProcess {
508
568
  if (outputOverflowed)
509
569
  return;
510
570
  const bytes = target === "stdout" ? outputBytes : errorBytes;
511
- const remaining = PROLOG_OUTPUT_MAX_BUFFER_BYTES - bytes;
571
+ const remaining = this.maxOutputBytes - bytes;
512
572
  if (chunk.byteLength > remaining) {
513
573
  const clipped = chunk.subarray(0, Math.max(0, remaining)).toString();
514
574
  if (target === "stdout")
@@ -624,10 +684,10 @@ export class PrologProcess {
624
684
  appendOutputChunk(chunk) {
625
685
  if (this.outputOverflowed)
626
686
  return;
627
- const remaining = PROLOG_OUTPUT_MAX_BUFFER_BYTES - this.outputBufferBytes;
687
+ const remaining = this.maxOutputBytes - this.outputBufferBytes;
628
688
  if (chunk.byteLength > remaining) {
629
689
  this.outputBuffer += chunk.subarray(0, remaining).toString();
630
- this.outputBufferBytes = PROLOG_OUTPUT_MAX_BUFFER_BYTES;
690
+ this.outputBufferBytes = this.maxOutputBytes;
631
691
  this.outputOverflowed = true;
632
692
  return;
633
693
  }
@@ -637,10 +697,10 @@ export class PrologProcess {
637
697
  appendErrorChunk(chunk) {
638
698
  if (this.outputOverflowed)
639
699
  return;
640
- const remaining = PROLOG_OUTPUT_MAX_BUFFER_BYTES - this.errorBufferBytes;
700
+ const remaining = this.maxOutputBytes - this.errorBufferBytes;
641
701
  if (chunk.byteLength > remaining) {
642
702
  this.errorBuffer += chunk.subarray(0, remaining).toString();
643
- this.errorBufferBytes = PROLOG_OUTPUT_MAX_BUFFER_BYTES;
703
+ this.errorBufferBytes = this.maxOutputBytes;
644
704
  this.outputOverflowed = true;
645
705
  return;
646
706
  }
@@ -827,7 +887,16 @@ export class PrologProcess {
827
887
  getPid() {
828
888
  return this.process?.pid || 0;
829
889
  }
890
+ lostProcessError() {
891
+ if (!this.interactiveStarted) {
892
+ return new Error("Prolog process not started");
893
+ }
894
+ return new PrologProcessTerminatedError(this.terminationReason ?? "process exited");
895
+ }
830
896
  async terminate() {
897
+ if (this.interactiveStarted) {
898
+ this.terminationReason ??= "terminated";
899
+ }
831
900
  if (this.terminationPromise) {
832
901
  await this.terminationPromise;
833
902
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostic-usage.d.ts","sourceRoot":"","sources":["../../src/public/diagnostic-usage.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAiCD,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACtC,MAAM,CAIR;AAkHD,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACvC,SAAS,EAAE,QAAQ,CAAC,MAA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AM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,EACnD,MAAM,EAAE,OAAO,GACd,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwEzB;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAgC1E"}
@@ -1,21 +1,10 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { appendFileSync, mkdirSync } from "node:fs";
3
3
  import path from "node:path";
4
+ import { appendPayloadCountField, normalizeResultPayload, } from "./operations/result-envelope.js";
4
5
  function isRecord(value) {
5
6
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6
7
  }
7
- function resultRecord(result) {
8
- if (!isRecord(result))
9
- return undefined;
10
- if (isRecord(result.structuredContent))
11
- return result.structuredContent;
12
- // CLI JSON operations return the same versioned KibiResult envelope as MCP
13
- // structuredContent. Unwrap its data before deriving operation-specific
14
- // telemetry fields (coverage/proof fields in particular).
15
- if (result.kibiProtocol === 1 && isRecord(result.data))
16
- return result.data;
17
- return result;
18
- }
19
8
  function stringArray(value) {
20
9
  return Array.isArray(value)
21
10
  ? value.filter((item) => typeof item === "string")
@@ -141,10 +130,7 @@ export function deriveDiagnosticUsageFields(tool, args, telemetry, result) {
141
130
  fields.actor_id = telemetry.actor_id;
142
131
  }
143
132
  }
144
- const structured = resultRecord(result);
145
- const envelope = isRecord(structured) && structured.kibiProtocol === 1
146
- ? structured
147
- : undefined;
133
+ const { envelope, data: structured } = normalizeResultPayload(result);
148
134
  if (envelope) {
149
135
  fields.protocol_version = envelope.kibiProtocol;
150
136
  fields.result_version =
@@ -162,18 +148,14 @@ export function deriveDiagnosticUsageFields(tool, args, telemetry, result) {
162
148
  fields.unsafe_original_retry = telemetry?.unsafe_original_retry === true;
163
149
  }
164
150
  if (tool === "kb_query" || tool === "kb_search") {
165
- const resultCount = Number(structured?.count ?? 0);
166
- fields.result_count = resultCount;
167
- fields.zero_results = resultCount === 0;
168
- fields.result_summary =
169
- resultCount === 0 ? "0 results" : `${resultCount} results`;
151
+ appendPayloadCountField(fields, "result_count", "results", structured);
152
+ if (typeof fields.result_count === "number") {
153
+ fields.zero_results = fields.result_count === 0;
154
+ }
170
155
  }
171
156
  if (tool === "kb_check") {
172
- const count = Number(structured?.count ?? 0);
173
- fields.violation_count = count;
157
+ appendPayloadCountField(fields, "violation_count", "violations", structured);
174
158
  fields.requested_rules = Array.isArray(args.rules) ? args.rules : [];
175
- fields.result_summary =
176
- count === 0 ? "0 violations" : `${count} violations`;
177
159
  }
178
160
  if (tool === "kb_coverage" && structured) {
179
161
  appendCoverageFields(fields, args, structured);
@@ -1 +1 @@
1
- {"version":3,"file":"full-kb-quality.d.ts","sourceRoot":"","sources":["../../../src/public/impact/full-kb-quality.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAatC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAWjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AASpD,KAAK,+BAA+B,GAAG;IACrC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,eAAe,CAAC,CAAC;IAC7D,QAAQ,CAAC,sBAAsB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAmgBF,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,eAAe,CAAC,GAClD,OAAO,CAAC,gBAAgB,EAAE,CAAC,C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ACnD,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAkCvC"}
@@ -404,18 +404,10 @@ export async function loadKbExtractionResults(prolog) {
404
404
  entities = await loadIndexedEntityProjection(prolog.queryEntities.bind(prolog));
405
405
  }
406
406
  else {
407
- const entityResult = await prolog.query("findall([Id,Type,Props], kb_entity(Id, Type, Props), Results)");
408
- if (entityResult.success) {
409
- entities = entityResult.bindings.Results
410
- ? parseListOfLists(entityResult.bindings.Results).map(parseEntityFromList)
411
- : [];
412
- }
413
- else if (isOutputCapacityError(entityResult.error)) {
414
- entities = await loadBoundedEntityProjection(prolog);
415
- }
416
- else {
417
- throw new Error(`Full KB entity projection query failed: ${entityResult.error ?? "Unknown error"}`);
418
- }
407
+ // Never probe with an unbounded all-entities findall: receipt histories
408
+ // make that answer grow without limit, and an overflow terminates the
409
+ // interactive Prolog process that serves every later query.
410
+ entities = await loadBoundedEntityProjection(prolog);
419
411
  }
420
412
  const relationships = new Map();
421
413
  for (const relationshipType of RELATIONSHIP_TYPES) {
@@ -72,7 +72,7 @@ export declare const OPERATION_CATALOG: readonly [{
72
72
  };
73
73
  readonly id: {
74
74
  readonly type: "string";
75
- readonly description: "Optional exact entity ID. Example: 'REQ-001'. If omitted, returns matching entities by other filters.";
75
+ readonly description: "Optional exact entity ID. Example: 'REQ-cli-gc'. If omitted, returns matching entities by other filters.";
76
76
  };
77
77
  readonly tags: {
78
78
  readonly type: "array";
@@ -216,6 +216,12 @@ export declare const OPERATION_CATALOG: readonly [{
216
216
  readonly default: 0.18;
217
217
  readonly description: "Intent-v1 acceptance threshold between 0 and 1. Low-confidence queries abstain instead of returning misleading matches.";
218
218
  };
219
+ readonly fields: {
220
+ readonly type: "string";
221
+ readonly enum: readonly ["summary", "full"];
222
+ readonly default: "summary";
223
+ readonly description: "Optional result detail. 'summary' returns identifying metadata plus the match snippet for discovery. Use 'full' to include complete entity bodies, or follow up with kb_query for the exact entities you need.";
224
+ };
219
225
  };
220
226
  };
221
227
  readonly requiresProlog: true;
@@ -759,7 +765,7 @@ export declare const OPERATION_CATALOG: readonly [{
759
765
  };
760
766
  readonly id: {
761
767
  readonly type: "string";
762
- readonly description: "Unique entity ID (string). Example: 'REQ-123'. Existing ID updates the entity; new ID creates it.";
768
+ readonly description: "Unique entity ID (string). Example: 'REQ-cli-gc'. Name entities by the behavior they govern (<TYPE>-<area>-<behavior>), never by the next free number. Existing ID updates the entity; new ID creates it.";
763
769
  };
764
770
  readonly properties: {
765
771
  readonly type: "object";
@@ -775,7 +781,7 @@ export declare const OPERATION_CATALOG: readonly [{
775
781
  };
776
782
  readonly source: {
777
783
  readonly type: "string";
778
- readonly description: "Optional provenance string. Example: 'docs/requirements/REQ-123.md'. Defaults to 'mcp://kibi/upsert'.";
784
+ readonly description: "Optional provenance string. Example: '.kb/requirements/REQ-cli-gc.md'. Defaults to 'mcp://kibi/upsert'.";
779
785
  };
780
786
  readonly tags: {
781
787
  readonly type: "array";
@@ -801,7 +807,7 @@ export declare const OPERATION_CATALOG: readonly [{
801
807
  readonly items: {
802
808
  readonly type: "string";
803
809
  };
804
- readonly description: "Optional references. Example: ['REQ-010','https://example.com/spec'].";
810
+ readonly description: "Optional references. Example: ['REQ-cli-gc','https://example.com/spec'].";
805
811
  };
806
812
  readonly text_ref: {
807
813
  readonly type: "string";
@@ -1276,6 +1282,29 @@ export declare const OPERATION_CATALOG: readonly [{
1276
1282
  };
1277
1283
  readonly description: "Optional ordered argument explanations.";
1278
1284
  };
1285
+ readonly argument_constants: {
1286
+ readonly type: "object";
1287
+ readonly additionalProperties: {
1288
+ readonly type: "array";
1289
+ readonly items: {
1290
+ readonly type: "string";
1291
+ readonly minLength: 1;
1292
+ };
1293
+ readonly minItems: 1;
1294
+ };
1295
+ readonly description: "predicate_schema only: allowed constants keyed by argument name, e.g. {\"severity\": [\"warning\", \"info\"]}. Predicate facts must use a listed constant for those arguments; unlisted arguments stay open.";
1296
+ };
1297
+ readonly argument_aliases: {
1298
+ readonly type: "object";
1299
+ readonly additionalProperties: {
1300
+ readonly type: "object";
1301
+ readonly additionalProperties: {
1302
+ readonly type: "string";
1303
+ readonly minLength: 1;
1304
+ };
1305
+ };
1306
+ readonly description: "predicate_schema only: legacy spellings keyed by argument name, each mapped to a declared constant, e.g. {\"severity\": {\"warn\": \"warning\"}}. kibi migrate rewrites facts that still use an alias.";
1307
+ };
1279
1308
  readonly aliases: {
1280
1309
  readonly type: "array";
1281
1310
  readonly items: {
@@ -1345,7 +1374,7 @@ export declare const OPERATION_CATALOG: readonly [{
1345
1374
  readonly properties: {
1346
1375
  readonly type: {
1347
1376
  readonly type: "string";
1348
- readonly enum: readonly ["depends_on", "specified_by", "verified_by", "validates", "implements", "covered_by", "executable_for", "constrained_by", "constrains", "requires_property", "requires_predicate", "requires_rule", "guards", "publishes", "consumes", "supersedes", "relates_to"];
1377
+ readonly enum: readonly ["depends_on", "specified_by", "verified_by", "validates", "implements", "covered_by", "executable_for", "constrained_by", "constrains", "requires_property", "requires_predicate", "requires_rule", "guards", "publishes", "consumes", "supersedes", "restates", "relates_to"];
1349
1378
  readonly description: "Relationship type enum. Use only supported values. Direction semantics follow KB model (e.g., implements symbol->req, verified_by req/scenario->test, executable_for symbol->test).";
1350
1379
  };
1351
1380
  readonly from: {
@@ -1354,7 +1383,7 @@ export declare const OPERATION_CATALOG: readonly [{
1354
1383
  };
1355
1384
  readonly to: {
1356
1385
  readonly type: "string";
1357
- readonly description: "Target entity ID (must exist). Example: 'REQ-001'.";
1386
+ readonly description: "Target entity ID (must exist). Example: 'REQ-cli-gc'.";
1358
1387
  };
1359
1388
  };
1360
1389
  };
@@ -1451,7 +1480,7 @@ export declare const OPERATION_CATALOG: readonly [{
1451
1480
  readonly type: "string";
1452
1481
  readonly enum: readonly string[];
1453
1482
  };
1454
- readonly description: "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, source-relationship-parity, no-cycles, required-fields, deprecated-adr-no-successor, domain-contradictions, logic-coverage, rule-safety, rule-verifiability, query-plan-safety, req-status-vocabulary, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, strict-readiness, semantic-completeness, proof-contract-symbols. If omitted, server runs canonical and advisory rules plus the full-KB qualityDiagnostics audit scan, including usage telemetry acceptance when evidence exists; migration rules run only when explicitly selected. Advisory and migration findings are non-blocking qualityDiagnostics. If supplied, server preserves scoped validation and skips the full-KB advisory scan.";
1483
+ readonly description: "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, source-relationship-parity, no-cycles, required-fields, deprecated-adr-no-successor, domain-contradictions, logic-coverage, rule-safety, rule-verifiability, query-plan-safety, req-status-vocabulary, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, strict-readiness, semantic-completeness, proof-contract-symbols, entity-id-style, domain-redundancy, domain-implication, subject-key-identity, subject-key-shape, ontology-quality, predicate-schema-conformance. If omitted, server runs canonical and advisory rules plus the full-KB qualityDiagnostics audit scan, including usage telemetry acceptance when evidence exists; migration rules run only when explicitly selected. Advisory and migration findings are non-blocking qualityDiagnostics. If supplied, server preserves scoped validation and skips the full-KB advisory scan.";
1455
1484
  };
1456
1485
  readonly sourceFiles: {
1457
1486
  readonly type: "array";
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/public/operations/catalog.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AClC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAClD,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,GAClB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,6CAA6C,CAAC,EAAE,OAAO,CAAC;CAClE,CAAC;AAqDF,wBAAsB,YAAY,CAChC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CA4JxC"}
@@ -1,9 +1,10 @@
1
1
  import { runAggregatedChecks } from "../../commands/aggregated-checks.js";
2
2
  import { collectFullKbQualityDiagnostics } from "../impact-diagnostics.js";
3
3
  import { buildStructuredContent, buildSummary, } from "./check-format-shared.js";
4
- import { analyzeKbCheckImpact, collectQueryPlanSafetyViolations, getEffectiveRules, partitionCheckFindings, qualityDiagnosticsFromImpact, resolveCheckRules, } from "./check-helpers.js";
4
+ import { analyzeKbCheckImpact, collectQueryPlanSafetyViolations, getEffectiveRules, partitionCheckFindings, qualityDiagnosticsFromImpact, resolveCheckRules, stagedEntityIdStyleDiagnostics, } from "./check-helpers.js";
5
5
  import { executeStatus } from "./discovery-executors.js";
6
6
  import { buildActionsFromCheck, buildMigrationPlan, mergeMigrationPlans, } from "./migration-plan.js";
7
+ import { collectPredicateSchemaConformanceViolations } from "./predicate-schema-conformance.js";
7
8
  import { collectSourceRelationshipParityViolations } from "./source-relationship-parity.js";
8
9
  import { readWorkspaceSnapshot } from "./workspace-snapshot.js";
9
10
  export { buildStructuredContent, buildSummary, getEffectiveRules, resolveCheckRules, };
@@ -61,7 +62,10 @@ export async function executeCheck(args, context, options = {}) {
61
62
  const rulesAllowlist = resolveCheckRules(args);
62
63
  const hasExplicitRules = args.rules !== undefined;
63
64
  const impactResult = await analyzeKbCheckImpact(workspaceRoot, args);
64
- const impactQualityDiagnostics = qualityDiagnosticsFromImpact(impactResult);
65
+ const impactQualityDiagnostics = [
66
+ ...qualityDiagnosticsFromImpact(impactResult),
67
+ ...stagedEntityIdStyleDiagnostics(workspaceRoot, args),
68
+ ];
65
69
  const maxDiagnosticsOption = args.maxDiagnostics !== undefined
66
70
  ? { maxDiagnostics: args.maxDiagnostics }
67
71
  : {};
@@ -109,10 +113,14 @@ export async function executeCheck(args, context, options = {}) {
109
113
  const sourceRelationshipParityViolations = rulesAllowlist.has("source-relationship-parity")
110
114
  ? await collectSourceRelationshipParityViolations(workspaceRoot, prolog)
111
115
  : [];
116
+ const predicateConformanceFindings = rulesAllowlist.has("predicate-schema-conformance")
117
+ ? await collectPredicateSchemaConformanceViolations(prolog)
118
+ : [];
112
119
  const partitioned = partitionCheckFindings([
113
120
  ...aggregatedFindings,
114
121
  ...queryPlanViolations,
115
122
  ...sourceRelationshipParityViolations,
123
+ ...predicateConformanceFindings,
116
124
  ]);
117
125
  const violations = partitioned.violations;
118
126
  const diagnostics = violations.map((v) => ({
@@ -31,5 +31,11 @@ export declare function resolveCheckRules(args: Pick<CheckInput, "rules">): Set<
31
31
  export declare function readLegacyChecksHint(workspaceRoot: string): Promise<string | null>;
32
32
  export declare function hasImpactOptions(args: CheckInput): boolean;
33
33
  export declare function analyzeKbCheckImpact(workspaceRoot: string, args: CheckInput): Promise<ChangedFileImpactResult | undefined>;
34
+ /**
35
+ * Advisory naming-style review for entity Markdown staged as new. Runs only
36
+ * for `staged: true`, the creation boundary where a purely numeric ID can
37
+ * still be renamed cheaply; committed legacy entities are never evaluated.
38
+ */
39
+ export declare function stagedEntityIdStyleDiagnostics(workspaceRoot: string, args: Pick<CheckInput, "staged">): readonly QualityDiagnostic[];
34
40
  export declare function qualityDiagnosticsFromImpact(impactResult: ChangedFileImpactResult | undefined): readonly QualityDiagnostic[];
35
41
  //# sourceMappingURL=check-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-helpers.d.ts","sourceRoot":"","sources":["../../../src/public/operations/check-helpers.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,UAAU,EACV,KAAK,SAAS,EACd,iBAAiB,EAGlB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAEzC;;;;;;;GAOG;AAEH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG;IACtE,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC,CA0BA;AAQD,wBAAgB,gCAAgC,IAAI,SAAS,EAAE,CAU9D;AAED;;;;;;GAMG;AAEH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAC9B,GAAG,CAAC,MAAM,CAAC,CAQb;AAED;;;;GAIG;AAEH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAO1D;AAGD,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAoB9C;AAGD,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,uBAAuB,GAAG,SAAS,GAChD,SAAS,iBAAiB,EAAE,CAK9B"}
1
+ {"version":3,"file":"check-helpers.d.ts","sourceRoot":"","sources":["../../../src/public/operations/check-helpers.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,UAAU,EACV,KAAK,SA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ises";
3
4
  import path from "node:path";
@@ -20,6 +21,8 @@ import path from "node:path";
20
21
  */
21
22
  import { getKbPlPathOverride } from "../../env.js";
22
23
  import { resolveKbPlPath } from "../../prolog.js";
24
+ import { getStagedFiles } from "../../traceability/git-staged.js";
25
+ import { createStagedEntityIdStyleDiagnostics } from "../../traceability/staged-entity-id-style.js";
23
26
  import { analyzePrologQueryPlanSafety } from "../../utils/prolog-query-plan-safety.js";
24
27
  import { RULE_NAMES, getEffectiveRules, getRuleDefinition, getRuleEnforcementClass, } from "../../utils/rule-registry.js";
25
28
  import { analyzeChangedFileImpact, } from "../impact-diagnostics.js";
@@ -45,7 +48,7 @@ export function partitionCheckFindings(findings) {
45
48
  const definition = getRuleDefinition(finding.rule);
46
49
  qualityDiagnostics.push({
47
50
  id: `rule.${finding.rule}`,
48
- severity: "warning",
51
+ severity: definition?.diagnosticSeverity ?? "warning",
49
52
  blocking: false,
50
53
  category: definition?.category ?? "integrity",
51
54
  ...(finding.entityId !== undefined ? { entityId: finding.entityId } : {}),
@@ -135,6 +138,23 @@ export async function analyzeKbCheckImpact(workspaceRoot, args) {
135
138
  : {}),
136
139
  });
137
140
  }
141
+ /**
142
+ * Advisory naming-style review for entity Markdown staged as new. Runs only
143
+ * for `staged: true`, the creation boundary where a purely numeric ID can
144
+ * still be renamed cheaply; committed legacy entities are never evaluated.
145
+ */
146
+ // implements REQ-kibi-entity-id-style
147
+ export function stagedEntityIdStyleDiagnostics(workspaceRoot, args) {
148
+ if (args.staged !== true)
149
+ return [];
150
+ try {
151
+ return createStagedEntityIdStyleDiagnostics(getStagedFiles((command, options) => execSync(command, { ...options, cwd: workspaceRoot })));
152
+ }
153
+ catch {
154
+ // Outside a Git work tree there is no staged creation boundary.
155
+ return [];
156
+ }
157
+ }
138
158
  // implements REQ-mcp-tool-check
139
159
  export function qualityDiagnosticsFromImpact(impactResult) {
140
160
  if (impactResult === undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/public/operations/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAwDpE;;uEAEuE;AACvE,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,mBAAmB,GAC1B,mBAAmB,CAMrB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAsP3C,CAAC;AAgDF,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAClD,YAAY,EAAE,MAAM,GACnB,IAAI,CAIN;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,SAAS,eAAe,EAAE,GAClC,SAAS,0BAA0B,EAAE,CAoBvC"}
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/public/operations/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAwDpE;;uEAEuE;AACvE,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,mBAAmB,GAC1B,mBAAmB,CAMrB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAyQ3C,CAAC;AAgDF,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAClD,YAAY,EAAE,MAAM,GACnB,IAAI,CAIN;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,SAAS,eAAe,EAAE,GAClC,SAAS,0BAA0B,EAAE,CAoBvC"}
@@ -145,6 +145,21 @@ export const OPERATION_DATA_SCHEMAS = {
145
145
  warnings: recordArray,
146
146
  migrationWarning: { type: ["string", "null"] },
147
147
  logic: recordValue,
148
+ vocabularyAlignment: objectData({
149
+ subject: recordValue,
150
+ redundancyCandidates: recordArray,
151
+ reviewPlan: recordArray,
152
+ stamps: recordArray,
153
+ fallbackUsed: booleanValue,
154
+ diagnostics: recordArray,
155
+ }, [
156
+ "subject",
157
+ "redundancyCandidates",
158
+ "reviewPlan",
159
+ "stamps",
160
+ "fallbackUsed",
161
+ "diagnostics",
162
+ ]),
148
163
  }),
149
164
  kb_suggest_predicates: objectData({
150
165
  text: stringValue,
@@ -226,6 +241,7 @@ export const OPERATION_DATA_SCHEMAS = {
226
241
  sourceWrites: recordArray,
227
242
  deletionPlan: recordValue,
228
243
  supersessionPlan: recordValue,
244
+ skippedEffects: stringArray,
229
245
  status: stringValue,
230
246
  effectFailures: recordArray,
231
247
  nextActions: recordArray,
@@ -1,4 +1,4 @@
1
- import type { PrologPort } from "./runtime-types.js";
1
+ import type { PrologEntityQueryInput, PrologEntityQueryResult, PrologPort } from "./runtime-types.js";
2
2
  export type EntityQueryInput = {
3
3
  readonly type?: string;
4
4
  readonly id?: string;
@@ -7,10 +7,22 @@ export type EntityQueryInput = {
7
7
  /** Page size for index-backed queries; bounds each query's output. */
8
8
  readonly limit?: number;
9
9
  readonly offset?: number;
10
+ /**
11
+ * Proof selection only needs the contract. Omit receipt histories so a
12
+ * campaign does not page every full test entity.
13
+ */
14
+ readonly projection?: "proof_contract";
10
15
  };
11
16
  export declare const VALID_ENTITY_TYPES: readonly ["req", "scenario", "test", "adr", "flag", "event", "symbol", "fact"];
12
17
  export declare function validateEntityType(type?: string): void;
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 declare const PROOF_CONTRACT_PAGE_SIZE = 100;
13
24
  export declare function buildEntityGoal(input: EntityQueryInput): string;
25
+ export declare function loadEntitiesPaged(prolog: Pick<PrologPort, "query">, type: (typeof VALID_ENTITY_TYPES)[number], pageSize?: number): Promise<Record<string, unknown>[]>;
14
26
  export declare function loadEntities(prolog: Pick<PrologPort, "query">, input: EntityQueryInput): Promise<Record<string, unknown>[]>;
15
27
  export declare function paginateResults<T>(results: readonly T[], limit?: number, offset?: number): T[];
16
28
  /**
@@ -20,10 +32,38 @@ export declare function paginateResults<T>(results: readonly T[], limit?: number
20
32
  * a byte-size guarantee for arbitrarily large individual entity payloads.
21
33
  */
22
34
  export declare const SEARCH_CANDIDATE_PAGE_SIZE = 500;
23
- export declare function loadSearchCandidates(prolog: Pick<PrologPort, "searchEntities">, input: {
35
+ export declare function loadSearchCandidates(prolog: Pick<PrologPort, "searchEntities"> & Partial<Pick<PrologPort, "query">>, input: {
24
36
  readonly query: string;
25
37
  readonly type?: string;
26
38
  readonly maxCandidates?: number;
27
39
  }, signal?: AbortSignal): Promise<Record<string, unknown>[]>;
40
+ /**
41
+ * Projected candidate rows for every entity (optionally of one type), in id
42
+ * order, bounded by `maxCandidates`. For semantic discovery that has no
43
+ * lexical token to pre-filter candidates.
44
+ */
45
+ export declare function listSearchCandidates(prolog: Pick<PrologPort, "query">, input: {
46
+ readonly type?: string;
47
+ readonly maxCandidates: number;
48
+ }, signal?: AbortSignal): Promise<Record<string, unknown>[]>;
49
+ /**
50
+ * Rows per `kb_query_entities` request. Full entities carry receipt
51
+ * histories, so a caller-sized page (up to 100k rows) is split into bounded
52
+ * requests and concatenated; the reported count is the total match count.
53
+ */
54
+ export declare const ENTITY_QUERY_CHUNK_SIZE = 25;
55
+ export declare function queryEntityChunks(readChunk: (input: PrologEntityQueryInput) => Promise<PrologEntityQueryResult>, input: PrologEntityQueryInput): Promise<PrologEntityQueryResult>;
56
+ /** Bounded `kb_query_entities` paging for ports without the engine method. */
57
+ export declare function queryEntitiesViaQuery(prolog: Pick<PrologPort, "query">, input: PrologEntityQueryInput, signal?: AbortSignal): Promise<PrologEntityQueryResult>;
58
+ /** Every entity id, without materializing entity properties. */
59
+ export declare function loadEntityIds(prolog: Pick<PrologPort, "query">): Promise<string[]>;
60
+ /**
61
+ * Replace projected search candidates with complete entities, one bounded
62
+ * query per entity. Used only for the final result page when a caller asks
63
+ * for full entity bodies.
64
+ */
65
+ export declare function reloadFullEntities<TMatch extends {
66
+ readonly entity: Record<string, unknown>;
67
+ }>(prolog: Pick<PrologPort, "query">, matches: readonly TMatch[]): Promise<TMatch[]>;
28
68
  export declare function dedupeEntities(entities: readonly Record<string, unknown>[]): Record<string, unknown>[];
29
69
  //# sourceMappingURL=discovery-entities.d.ts.map