kibi-cli 0.16.1 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/cli-json-command.d.ts.map +1 -1
  2. package/dist/cli-json-command.js +87 -11
  3. package/dist/cli-register-maintenance.d.ts.map +1 -1
  4. package/dist/cli-register-maintenance.js +8 -0
  5. package/dist/cli-register-reporting.d.ts.map +1 -1
  6. package/dist/cli-register-reporting.js +5 -0
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +2 -1
  9. package/dist/commands/aggregated-checks.d.ts.map +1 -1
  10. package/dist/commands/aggregated-checks.js +1 -0
  11. package/dist/commands/check.d.ts.map +1 -1
  12. package/dist/commands/check.js +1 -1
  13. package/dist/commands/coverage.d.ts +5 -0
  14. package/dist/commands/coverage.d.ts.map +1 -1
  15. package/dist/commands/coverage.js +5 -0
  16. package/dist/commands/discovery-table.d.ts.map +1 -1
  17. package/dist/commands/discovery-table.js +96 -5
  18. package/dist/commands/sync/cache.d.ts +2 -0
  19. package/dist/commands/sync/cache.d.ts.map +1 -1
  20. package/dist/commands/sync/cache.js +8 -0
  21. package/dist/commands/sync/manifest.d.ts +12 -1
  22. package/dist/commands/sync/manifest.d.ts.map +1 -1
  23. package/dist/commands/sync/manifest.js +22 -5
  24. package/dist/commands/sync/persistence.d.ts.map +1 -1
  25. package/dist/commands/sync/persistence.js +76 -2
  26. package/dist/commands/sync.d.ts.map +1 -1
  27. package/dist/commands/sync.js +72 -15
  28. package/dist/commands/usage-metrics.d.ts +66 -2
  29. package/dist/commands/usage-metrics.d.ts.map +1 -1
  30. package/dist/commands/usage-metrics.js +34 -24
  31. package/dist/commands/usage-remediation.d.ts +9 -0
  32. package/dist/commands/usage-remediation.d.ts.map +1 -0
  33. package/dist/commands/usage-remediation.js +52 -0
  34. package/dist/extractors/markdown.d.ts +17 -1
  35. package/dist/extractors/markdown.d.ts.map +1 -1
  36. package/dist/extractors/markdown.js +81 -2
  37. package/dist/logic/ir.d.ts +112 -0
  38. package/dist/logic/ir.d.ts.map +1 -0
  39. package/dist/logic/ir.js +729 -0
  40. package/dist/operations/modeling/logic-modeling.d.ts +22 -0
  41. package/dist/operations/modeling/logic-modeling.d.ts.map +1 -0
  42. package/dist/operations/modeling/logic-modeling.js +120 -0
  43. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  44. package/dist/operations/modeling/model-requirement.js +83 -2
  45. package/dist/operations/modeling/predicate-applyplan.d.ts +1 -1
  46. package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
  47. package/dist/operations/modeling/predicate-applyplan.js +29 -4
  48. package/dist/operations/modeling/predicate-inference.d.ts.map +1 -1
  49. package/dist/operations/modeling/predicate-inference.js +3 -0
  50. package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
  51. package/dist/operations/modeling/predicate-loader.js +7 -1
  52. package/dist/operations/modeling/predicate-ranker.d.ts.map +1 -1
  53. package/dist/operations/modeling/predicate-ranker.js +40 -2
  54. package/dist/operations/modeling/predicate-types.d.ts +12 -1
  55. package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
  56. package/dist/operations/modeling/requirement-types.d.ts +12 -0
  57. package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
  58. package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
  59. package/dist/operations/modeling/suggest-predicates.js +35 -11
  60. package/dist/operations/mutation/audit.js +1 -1
  61. package/dist/operations/mutation/contradictions.d.ts +1 -1
  62. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  63. package/dist/operations/mutation/contradictions.js +23 -18
  64. package/dist/operations/mutation/relationships.d.ts.map +1 -1
  65. package/dist/operations/mutation/relationships.js +8 -0
  66. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  67. package/dist/operations/mutation/serialization.js +6 -0
  68. package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
  69. package/dist/operations/mutation/strict-fact.js +68 -3
  70. package/dist/operations/mutation/upsert.d.ts +3 -1
  71. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  72. package/dist/operations/mutation/upsert.js +51 -12
  73. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  74. package/dist/operations/mutation/validate-upsert.js +18 -2
  75. package/dist/operations/mutation/validation.d.ts.map +1 -1
  76. package/dist/operations/mutation/validation.js +8 -0
  77. package/dist/operations/semantic-advisor/analysis-receipt.d.ts +2 -2
  78. package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
  79. package/dist/operations/semantic-advisor/analysis-receipt.js +30 -16
  80. package/dist/operations/semantic-advisor/analyze-prose.d.ts +1 -1
  81. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  82. package/dist/operations/semantic-advisor/analyze-prose.js +464 -27
  83. package/dist/operations/semantic-advisor/clauses.d.ts +1 -0
  84. package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
  85. package/dist/operations/semantic-advisor/clauses.js +7 -7
  86. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +18 -0
  87. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -0
  88. package/dist/operations/semantic-advisor/ingestion-boundary.js +167 -0
  89. package/dist/operations/semantic-advisor/observation-plan.d.ts.map +1 -1
  90. package/dist/operations/semantic-advisor/observation-plan.js +15 -3
  91. package/dist/operations/semantic-advisor/shared.d.ts +9 -0
  92. package/dist/operations/semantic-advisor/shared.d.ts.map +1 -1
  93. package/dist/operations/semantic-advisor/shared.js +38 -4
  94. package/dist/operations/semantic-advisor/types.d.ts +66 -1
  95. package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
  96. package/dist/prolog/codec.d.ts.map +1 -1
  97. package/dist/prolog/codec.js +19 -2
  98. package/dist/prolog.d.ts +6 -0
  99. package/dist/prolog.d.ts.map +1 -1
  100. package/dist/prolog.js +247 -63
  101. package/dist/public/diagnostic-usage.d.ts +17 -0
  102. package/dist/public/diagnostic-usage.d.ts.map +1 -0
  103. package/dist/public/diagnostic-usage.js +152 -0
  104. package/dist/public/distribution-parity.d.ts +90 -0
  105. package/dist/public/distribution-parity.d.ts.map +1 -0
  106. package/dist/public/distribution-parity.js +367 -0
  107. package/dist/public/impact/full-kb-quality.d.ts +2 -0
  108. package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
  109. package/dist/public/impact/full-kb-quality.js +53 -1
  110. package/dist/public/impact-diagnostics.d.ts +2 -0
  111. package/dist/public/impact-diagnostics.d.ts.map +1 -1
  112. package/dist/public/impact-diagnostics.js +1 -0
  113. package/dist/public/operations/catalog.d.ts +235 -11
  114. package/dist/public/operations/catalog.d.ts.map +1 -1
  115. package/dist/public/operations/check-executor.d.ts.map +1 -1
  116. package/dist/public/operations/check-executor.js +4 -0
  117. package/dist/public/operations/discovery-executors.d.ts +6 -0
  118. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  119. package/dist/public/operations/discovery-executors.js +18 -2
  120. package/dist/public/operations/index.d.ts +5 -0
  121. package/dist/public/operations/index.d.ts.map +1 -1
  122. package/dist/public/operations/index.js +5 -0
  123. package/dist/public/operations/legacy-migration-plan.d.ts +113 -0
  124. package/dist/public/operations/legacy-migration-plan.d.ts.map +1 -0
  125. package/dist/public/operations/legacy-migration-plan.js +409 -0
  126. package/dist/public/operations/node-ports.d.ts.map +1 -1
  127. package/dist/public/operations/node-ports.js +90 -0
  128. package/dist/public/operations/repair-plan.d.ts +184 -0
  129. package/dist/public/operations/repair-plan.d.ts.map +1 -0
  130. package/dist/public/operations/repair-plan.js +397 -0
  131. package/dist/public/operations/runtime-types.d.ts +7 -0
  132. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  133. package/dist/public/operations/specs/check.d.ts +3 -3
  134. package/dist/public/operations/specs/check.d.ts.map +1 -1
  135. package/dist/public/operations/specs/check.js +5 -2
  136. package/dist/public/operations/specs/discovery.d.ts +1 -1
  137. package/dist/public/operations/specs/discovery.js +1 -1
  138. package/dist/public/operations/specs/modeling.d.ts +35 -1
  139. package/dist/public/operations/specs/modeling.d.ts.map +1 -1
  140. package/dist/public/operations/specs/modeling.js +32 -1
  141. package/dist/public/operations/specs/mutation-schemas.d.ts +133 -3
  142. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  143. package/dist/public/operations/specs/mutation-schemas.js +67 -1
  144. package/dist/public/operations/specs/reporting.d.ts +42 -1
  145. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  146. package/dist/public/operations/specs/reporting.js +70 -6
  147. package/dist/public/operations/specs/semantic.d.ts +30 -2
  148. package/dist/public/operations/specs/semantic.d.ts.map +1 -1
  149. package/dist/public/operations/specs/semantic.js +35 -3
  150. package/dist/public/operations/specs/upsert.d.ts +133 -3
  151. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  152. package/dist/public/operations/workspace-snapshot.d.ts +10 -0
  153. package/dist/public/operations/workspace-snapshot.d.ts.map +1 -0
  154. package/dist/public/operations/workspace-snapshot.js +20 -0
  155. package/dist/public/schemas/entity.d.ts.map +1 -1
  156. package/dist/public/schemas/entity.js +332 -0
  157. package/dist/public/schemas/relationship.d.ts.map +1 -1
  158. package/dist/public/schemas/relationship.js +1 -0
  159. package/dist/public/skills/kibi-traceability/SKILL.md +7 -1
  160. package/dist/public/skills/kibi-usage/SKILL.md +44 -12
  161. package/dist/public/skills/kibi-usage/resources/fact-lanes.md +12 -2
  162. package/dist/public/skills/kibi-usage/resources/logic-ir.md +43 -0
  163. package/dist/public/skills/kibi-usage/resources/operation-access.md +19 -19
  164. package/dist/public/skills/kibi-usage/resources/ui-requirements.md +96 -0
  165. package/dist/public/skills/kibi-usage/resources/workflows.md +40 -8
  166. package/dist/public/symbol-granularity.d.ts +9 -0
  167. package/dist/public/symbol-granularity.d.ts.map +1 -1
  168. package/dist/public/symbol-granularity.js +16 -0
  169. package/dist/public/telemetry-acceptance.d.ts +89 -0
  170. package/dist/public/telemetry-acceptance.d.ts.map +1 -0
  171. package/dist/public/telemetry-acceptance.js +597 -0
  172. package/dist/public/telemetry-remediation.d.ts +33 -0
  173. package/dist/public/telemetry-remediation.d.ts.map +1 -0
  174. package/dist/public/telemetry-remediation.js +257 -0
  175. package/dist/public/verification-receipt.d.ts +75 -0
  176. package/dist/public/verification-receipt.d.ts.map +1 -0
  177. package/dist/public/verification-receipt.js +129 -0
  178. package/dist/schemas/entity.schema.json +401 -4
  179. package/dist/traceability/staged-diagnostics.d.ts +1 -1
  180. package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
  181. package/dist/traceability/staged-diagnostics.js +17 -10
  182. package/dist/traceability/staged-impact-contract.js +1 -1
  183. package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
  184. package/dist/traceability/staged-symbols-manifest.js +28 -10
  185. package/dist/traceability/temp-kb.d.ts.map +1 -1
  186. package/dist/traceability/temp-kb.js +49 -3
  187. package/dist/types/entities.d.ts +1 -0
  188. package/dist/types/entities.d.ts.map +1 -1
  189. package/dist/types/relationships.d.ts +1 -1
  190. package/dist/types/relationships.d.ts.map +1 -1
  191. package/dist/utils/rule-registry.d.ts +2 -0
  192. package/dist/utils/rule-registry.d.ts.map +1 -1
  193. package/dist/utils/rule-registry.js +18 -0
  194. package/dist/utils/schema-version.d.ts +1 -1
  195. package/dist/utils/schema-version.js +1 -1
  196. package/package.json +34 -2
  197. package/src/public/diagnostic-usage.ts +206 -0
  198. package/src/public/distribution-parity.ts +580 -0
  199. package/src/public/impact/full-kb-quality.ts +74 -1
  200. package/src/public/impact-diagnostics.ts +16 -0
  201. package/src/public/operations/check-executor.ts +4 -0
  202. package/src/public/operations/discovery-executors.ts +24 -2
  203. package/src/public/operations/index.ts +5 -0
  204. package/src/public/operations/legacy-migration-plan.ts +688 -0
  205. package/src/public/operations/node-ports.ts +109 -0
  206. package/src/public/operations/repair-plan.ts +562 -0
  207. package/src/public/operations/runtime-types.ts +8 -0
  208. package/src/public/operations/specs/check.ts +5 -2
  209. package/src/public/operations/specs/discovery.ts +1 -1
  210. package/src/public/operations/specs/modeling.ts +39 -1
  211. package/src/public/operations/specs/mutation-schemas.ts +77 -1
  212. package/src/public/operations/specs/reporting.ts +91 -6
  213. package/src/public/operations/specs/semantic.ts +42 -3
  214. package/src/public/operations/workspace-snapshot.ts +28 -0
  215. package/src/public/schemas/entity.ts +340 -1
  216. package/src/public/schemas/relationship.ts +1 -0
  217. package/src/public/skills/kibi-traceability/SKILL.md +7 -1
  218. package/src/public/skills/kibi-usage/SKILL.md +44 -12
  219. package/src/public/skills/kibi-usage/resources/fact-lanes.md +12 -2
  220. package/src/public/skills/kibi-usage/resources/logic-ir.md +43 -0
  221. package/src/public/skills/kibi-usage/resources/operation-access.md +19 -19
  222. package/src/public/skills/kibi-usage/resources/ui-requirements.md +96 -0
  223. package/src/public/skills/kibi-usage/resources/workflows.md +40 -8
  224. package/src/public/symbol-granularity.ts +25 -0
  225. package/src/public/telemetry-acceptance.ts +859 -0
  226. package/src/public/telemetry-remediation.ts +462 -0
  227. package/src/public/verification-receipt.ts +170 -0
  228. package/src/schemas/entity.schema.json +401 -4
  229. package/src/schemas/relationship.schema.json +1 -0
@@ -31,8 +31,16 @@ export interface FilesystemPort {
31
31
  export interface GitPort {
32
32
  revParse(...args: readonly string[]): Promise<string>;
33
33
  showToplevel(): Promise<string>;
34
+ workspaceSnapshot?(workspaceRoot: string): Promise<WorkspaceSnapshot>;
34
35
  }
35
36
 
37
+ export type WorkspaceSnapshot = Readonly<{
38
+ version: "kibi.workspace-snapshot.v1";
39
+ hash: string;
40
+ dirty: boolean;
41
+ fileCount: number;
42
+ }>;
43
+
36
44
  export interface NetworkPort {
37
45
  fetch(input: string | URL, init?: RequestInit): Promise<Response>;
38
46
  }
@@ -5,7 +5,7 @@ export const checkSpec = {
5
5
  name: "kb_check",
6
6
  cliName: "check",
7
7
  description:
8
- "Run KB validation rules and return violations. Use before or after mutations, and after meaningful source edits with impact options to surface symbol granularity and semantic-review diagnostics. Do not use for point lookups. No write side effects. Prefer explicit rules for faster iteration; omit rules for final full validation plus full-KB qualityDiagnostics review.",
8
+ "Run KB validation rules and return violations. Use before or after mutations, and after meaningful source edits with impact options to surface symbol granularity and semantic-review diagnostics. Do not use for point lookups. No write side effects. Prefer explicit rules for faster iteration; omit rules for final full validation plus full-KB qualityDiagnostics review, including telemetry acceptance when .kb/usage.log exists.",
9
9
  businessInputSchema: {
10
10
  type: "object",
11
11
  properties: {
@@ -26,11 +26,14 @@ export const checkSpec = {
26
26
  "strict-req-fact-pairing",
27
27
  "predicate-verifiability",
28
28
  "logic-coverage",
29
+ "rule-safety",
30
+ "rule-verifiability",
31
+ "semantic-completeness",
29
32
  "query-plan-safety",
30
33
  ],
31
34
  },
32
35
  description:
33
- "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, no-cycles, required-fields, deprecated-adr-no-successor, domain-contradictions, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, logic-coverage, query-plan-safety. If omitted, server runs all rules plus the full-KB qualityDiagnostics audit scan; if supplied, server preserves scoped validation and skips the full-KB advisory scan.",
36
+ "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, no-cycles, required-fields, deprecated-adr-no-successor, domain-contradictions, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, logic-coverage, rule-safety, rule-verifiability, semantic-completeness, query-plan-safety. If omitted, server runs all rules plus the full-KB qualityDiagnostics audit scan, including usage telemetry acceptance when evidence exists; if supplied, server preserves scoped validation and skips the full-KB advisory scan.",
34
37
  },
35
38
  sourceFiles: {
36
39
  type: "array",
@@ -118,7 +118,7 @@ export const statusSpec = {
118
118
  name: "kb_status",
119
119
  cliName: "status",
120
120
  description:
121
- "Report current branch, snapshot, and freshness metadata for the attached KB. Read-only status inspection with no mutation side effects.",
121
+ "Report current branch, KB snapshot and freshness metadata, plus the deterministic workspace snapshot used to validate execution receipts. Read-only status inspection with no mutation side effects.",
122
122
  businessInputSchema: { type: "object", properties: {} },
123
123
  requiresProlog: true,
124
124
  effects: ["kb-read", "workspace-read"],
@@ -75,6 +75,26 @@ export const modelRequirementSpec = {
75
75
  description:
76
76
  "Existing requirement logic_claims values. The returned requirement update merges the new atomic claim key into this manifest instead of replacing prior claims.",
77
77
  },
78
+ requirementId: {
79
+ type: "string",
80
+ description:
81
+ "Optional existing requirement ID to receive the requires_rule relationship.",
82
+ },
83
+ claimKey: {
84
+ type: "string",
85
+ description:
86
+ "Optional advisor-issued claim key for the exact proposition represented by logic.",
87
+ },
88
+ claimText: {
89
+ type: "string",
90
+ description:
91
+ "Optional exact proposition text represented by logic; defaults to text.",
92
+ },
93
+ logic: {
94
+ type: "object",
95
+ description:
96
+ "Optional typed kibi.logic.v1 IR. Kibi validates and canonicalizes it into a rule fact; raw Prolog is rejected.",
97
+ },
78
98
  },
79
99
  },
80
100
  requiresProlog: true,
@@ -89,7 +109,7 @@ export const suggestPredicatesSpec = {
89
109
  name: "kb_suggest_predicates",
90
110
  cliName: "suggest-predicates",
91
111
  description:
92
- "Suggest ontology predicate schemas for prose requirements before agents write facts. Read-only guidance returns ranked candidates, a safe predicate-fact applyPlan, a separate requires_predicate relationshipPlan when a requirement ID is supplied, or an explicit ontology-gap observation when no predicate fits.",
112
+ "Suggest ontology predicate schemas for prose requirements before agents write facts. Read-only guidance returns ranked candidates, an applicable predicate-fact plan only when every ordered argument is bound, a separate requires_predicate relationship plan when a requirement ID is supplied, or an explicit ontology-gap observation when no predicate fits.",
93
113
  businessInputSchema: {
94
114
  type: "object",
95
115
  required: ["text"],
@@ -136,6 +156,24 @@ export const suggestPredicatesSpec = {
136
156
  description:
137
157
  "Whether to include existing KB fact_kind=predicate_schema facts alongside Kibi's built-in predicate catalog. Default: true.",
138
158
  },
159
+ schemaId: {
160
+ type: "string",
161
+ minLength: 1,
162
+ description:
163
+ "Optional exact reviewed predicate schema ID. When supplied, Kibi selects that schema instead of lexical rank order and fails closed if it is unavailable.",
164
+ },
165
+ argumentBindings: {
166
+ type: "object",
167
+ additionalProperties: { type: "string", minLength: 1 },
168
+ description:
169
+ "Optional exact predicate argument values keyed by a candidate schema's argument_names. Required before applying a candidate whose binding_status is incomplete; Kibi never substitutes guessed values for unbound arguments.",
170
+ },
171
+ polarityHint: {
172
+ type: "string",
173
+ enum: ["assert", "deny"],
174
+ description:
175
+ "Optional reviewed polarity override for claims whose surface negation does not express predicate denial. Use only after reviewing the selected schema and full claim scope.",
176
+ },
139
177
  existingLogicClaims: {
140
178
  type: "array",
141
179
  items: { type: "string", pattern: "^CLAIM-[A-F0-9]{16}$" },
@@ -1,3 +1,5 @@
1
+ import { VERIFICATION_RECEIPT_SCHEMA } from "../../verification-receipt.js";
2
+
1
3
  export const ENTITY_TYPES = [
2
4
  "req",
3
5
  "scenario",
@@ -67,6 +69,11 @@ export const ENTITY_PROPERTIES_SCHEMA = {
67
69
  description:
68
70
  "Optional text anchor/reference. Example: 'requirements.md#L40'.",
69
71
  },
72
+ semantic_text: {
73
+ type: "string",
74
+ description:
75
+ "Requirement-only authored prose used for semantic inventory hashes and UTF-8 spans. Keep text_ref available for independent document or code evidence.",
76
+ },
70
77
  logic_claims: {
71
78
  type: "array",
72
79
  minItems: 1,
@@ -75,6 +82,31 @@ export const ENTITY_PROPERTIES_SCHEMA = {
75
82
  description:
76
83
  "Requirement-only manifest of every atomic normative claim key returned by kb_semantic_advisor. A requirement is logic-complete only when every key is grounded by a linked property_value or predicate fact with the same claim_key.",
77
84
  },
85
+ semantic_clauses: {
86
+ type: "array",
87
+ minItems: 1,
88
+ items: { type: "string", minLength: 1 },
89
+ description:
90
+ "Optional complete atomic decomposition used by kb_semantic_advisor and proposition-complete ingestion. Preserve it when automatic sentence splitting needs a reviewed override.",
91
+ },
92
+ semantic_inventory_version: {
93
+ type: "string",
94
+ const: "kibi.semantic-inventory.v1",
95
+ description:
96
+ "Requirement-only proposition ledger contract version returned by kb_semantic_advisor.",
97
+ },
98
+ semantic_source_field: {
99
+ type: "string",
100
+ enum: ["semantic_text", "text_ref", "title"],
101
+ description:
102
+ "Requirement field whose exact UTF-8 bytes anchor semantic_inventory spans.",
103
+ },
104
+ semantic_source_hash: {
105
+ type: "string",
106
+ pattern: "^[a-f0-9]{64}$",
107
+ description:
108
+ "SHA-256 of the exact semantic source text returned in the advisor inventory contract.",
109
+ },
78
110
  sourceFile: {
79
111
  type: "string",
80
112
  description:
@@ -116,6 +148,13 @@ export const ENTITY_PROPERTIES_SCHEMA = {
116
148
  description:
117
149
  "Optional typed verification perspective for test entities. Example: 'consumer'.",
118
150
  },
151
+ verification_receipts: {
152
+ type: "array",
153
+ maxItems: 50,
154
+ items: VERIFICATION_RECEIPT_SCHEMA,
155
+ description:
156
+ "Append-only test execution evidence. Proof accepts only the newest valid passed receipt bound to the current code snapshot and within the seven-day freshness window.",
157
+ },
119
158
  fact_kind: {
120
159
  type: "string",
121
160
  enum: [
@@ -125,6 +164,8 @@ export const ENTITY_PROPERTIES_SCHEMA = {
125
164
  "meta",
126
165
  "predicate_schema",
127
166
  "predicate",
167
+ "rule_schema",
168
+ "rule",
128
169
  ],
129
170
  description:
130
171
  "Optional fact lane kind for fact entities. Strict lane uses 'subject' and 'property_value'; context lane uses 'observation' or 'meta'; ontology lane uses 'predicate_schema' or 'predicate'. Use kb_model_requirement or kb_suggest_predicates when starting from prose.",
@@ -246,8 +287,42 @@ export const ENTITY_PROPERTIES_SCHEMA = {
246
287
  items: { type: "string" },
247
288
  description: "Optional ground-term examples for a predicate schema.",
248
289
  },
290
+ semantic_inventory: {
291
+ type: "array",
292
+ description:
293
+ "Requirement proposition ledger returned by kb_semantic_advisor; preserve entries while modeling each assertive span.",
294
+ items: { type: "object" },
295
+ },
296
+ rule_ir: {
297
+ type: "object",
298
+ description:
299
+ "Schema-validated kibi.logic.v1 rule IR. It is persisted as data and never executed as caller-supplied Prolog.",
300
+ },
301
+ rule_hash: {
302
+ type: "string",
303
+ description: "Deterministic hash of canonical rule_ir.",
304
+ },
305
+ rule_schema_id: {
306
+ type: "string",
307
+ description: "Rule schema fact ID used to validate this rule.",
308
+ },
309
+ rule_name: { type: "string", description: "Stable rule schema name." },
310
+ semantic_key: {
311
+ type: "string",
312
+ description:
313
+ "Canonical semantic identity of the normalized logical model.",
314
+ },
315
+ claim_span_start: { type: "integer", minimum: 0 },
316
+ claim_span_end: { type: "integer", minimum: 0 },
249
317
  },
250
- allOf: [CLAIM_PROVENANCE_CONDITIONAL],
318
+ allOf: [
319
+ CLAIM_PROVENANCE_CONDITIONAL,
320
+ {
321
+ if: { required: ["verification_receipts"] },
322
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema conditional keyword.
323
+ then: { required: ["verification_scope"] },
324
+ },
325
+ ],
251
326
  required: ["title", "status"],
252
327
  } as const;
253
328
 
@@ -273,6 +348,7 @@ export const RELATIONSHIPS_SCHEMA = {
273
348
  "constrains",
274
349
  "requires_property",
275
350
  "requires_predicate",
351
+ "requires_rule",
276
352
  "guards",
277
353
  "publishes",
278
354
  "consumes",
@@ -1,10 +1,17 @@
1
+ import { VERIFICATION_RECEIPT_MAX_AGE_SECONDS } from "../../verification-receipt.js";
2
+ import {
3
+ type LegacyMigrationPlan,
4
+ buildLegacyMigrationPlanFromContext,
5
+ } from "../legacy-migration-plan.js";
1
6
  import {
2
7
  runOperationJsonQuery,
3
8
  toPrologAtom,
4
9
  toPrologList,
5
10
  } from "../prolog-json.js";
11
+ import { type RepairPlan, buildRepairPlan } from "../repair-plan.js";
6
12
  import type { OperationContext } from "../runtime-types.js";
7
13
  import type { OperationResult, OperationSpec } from "../types.js";
14
+ import { readWorkspaceSnapshot } from "../workspace-snapshot.js";
8
15
 
9
16
  const ENTITY_TYPES = [
10
17
  "req",
@@ -41,11 +48,18 @@ export type CoverageInput = {
41
48
  readonly includeTransitive?: boolean;
42
49
  readonly limit?: number;
43
50
  readonly offset?: number;
51
+ readonly includeMigrationPreview?: boolean;
52
+ readonly migrationLimit?: number;
53
+ readonly migrationOffset?: number;
54
+ readonly migrationPredicateLimit?: number;
55
+ readonly migrationPredicateMinScore?: number;
44
56
  };
45
57
 
46
58
  export type CoveragePayload = {
47
59
  readonly summary: Readonly<Record<string, number>>;
48
60
  readonly rows: readonly Readonly<Record<string, unknown>>[];
61
+ readonly repairPlan?: RepairPlan;
62
+ readonly legacyMigrationPlan?: LegacyMigrationPlan;
49
63
  readonly meta?: Readonly<Record<string, unknown>>;
50
64
  };
51
65
 
@@ -142,22 +156,57 @@ export async function executeCoverage(
142
156
  context: OperationContext,
143
157
  ): Promise<OperationResult<CoveragePayload>> {
144
158
  try {
159
+ const snapshotEvidence = await readWorkspaceSnapshot(context);
160
+ const codeSnapshot = snapshotEvidence.available
161
+ ? snapshotEvidence.snapshot.hash
162
+ : "unknown";
163
+ const checkedAt = context.clock().toISOString();
145
164
  const payload = await runOperationJsonQuery<CoveragePayload>(
146
165
  requireProlog(context),
147
166
  "discovery.pl",
148
- `discovery:coverage_report_json('${input.by ?? "req"}', ${toPrologList(input.tags)}, ${input.includePassing ?? false}, ${input.includeTransitive ?? true}, ${input.limit ?? 100}, ${input.offset ?? 0}, JsonString)`,
167
+ `discovery:coverage_report_json('${input.by ?? "req"}', ${toPrologList(input.tags)}, ${input.includePassing ?? false}, ${input.includeTransitive ?? true}, ${input.limit ?? 100}, ${input.offset ?? 0}, ${toPrologAtom(codeSnapshot)}, ${toPrologAtom(checkedAt)}, ${VERIFICATION_RECEIPT_MAX_AGE_SECONDS}, JsonString)`,
149
168
  "Coverage execution",
150
169
  );
151
- const fullyCovered = Number(payload.summary?.fullyCovered ?? 0);
152
- const total = Number(payload.summary?.total ?? 0);
170
+ const repairPlan = buildRepairPlan(payload, input, codeSnapshot);
171
+ const legacyMigrationPlan =
172
+ input.includeMigrationPreview === true && repairPlan !== undefined
173
+ ? await buildLegacyMigrationPlanFromContext(
174
+ repairPlan,
175
+ input,
176
+ codeSnapshot,
177
+ context,
178
+ )
179
+ : undefined;
180
+ const enrichedPayload = {
181
+ ...payload,
182
+ ...(repairPlan !== undefined ? { repairPlan } : {}),
183
+ ...(legacyMigrationPlan !== undefined ? { legacyMigrationPlan } : {}),
184
+ meta: {
185
+ ...(payload.meta ?? {}),
186
+ verificationReceiptMaxAgeSeconds: VERIFICATION_RECEIPT_MAX_AGE_SECONDS,
187
+ verificationSnapshot: codeSnapshot,
188
+ verificationSnapshotAvailable: snapshotEvidence.available,
189
+ ...(snapshotEvidence.available
190
+ ? {
191
+ verificationSnapshotDirty: snapshotEvidence.snapshot.dirty,
192
+ verificationSnapshotFileCount:
193
+ snapshotEvidence.snapshot.fileCount,
194
+ verificationSnapshotVersion: snapshotEvidence.snapshot.version,
195
+ }
196
+ : { verificationSnapshotError: snapshotEvidence.error }),
197
+ },
198
+ };
199
+ const fullyCovered = Number(enrichedPayload.summary?.fullyCovered ?? 0);
200
+ const proofProven = Number(enrichedPayload.summary?.proofProven ?? 0);
201
+ const total = Number(enrichedPayload.summary?.total ?? 0);
153
202
  return {
154
203
  content: [
155
204
  {
156
205
  type: "text",
157
- text: `Coverage summary: ${fullyCovered} fully covered out of ${total}.`,
206
+ text: `Coverage summary: ${fullyCovered} structurally covered and ${proofProven} proven out of ${total}.`,
158
207
  },
159
208
  ],
160
- structuredContent: payload,
209
+ structuredContent: enrichedPayload,
161
210
  };
162
211
  } catch (error) {
163
212
  const message = error instanceof Error ? error.message : String(error);
@@ -169,7 +218,7 @@ export const coverageSpec = {
169
218
  name: "kb_coverage",
170
219
  cliName: "coverage",
171
220
  description:
172
- "Generate curated coverage reports for requirements, symbols, or grouped types. Read-only reporting with no mutation side effects.",
221
+ "Generate curated structural coverage and conservative end-to-end requirement proof reports for requirements, symbols, or grouped types. Requirement reports include a deterministic, dependency-ordered, read-only repair plan; optional legacy migration previews reconstruct authored proposition inventories and rank exact schema candidates without producing executable writes. Paginated plans identify incomplete scope. Requirement rows keep coverageStatus separate from proofStatus and require fresh snapshot-bound E2E receipts before proof. No mutation side effects.",
173
222
  businessInputSchema: {
174
223
  type: "object",
175
224
  properties: {
@@ -179,6 +228,42 @@ export const coverageSpec = {
179
228
  includeTransitive: { type: "boolean", default: true },
180
229
  limit: { type: "integer", default: 100 },
181
230
  offset: { type: "integer", default: 0 },
231
+ includeMigrationPreview: {
232
+ type: "boolean",
233
+ default: false,
234
+ description:
235
+ "Opt in to a deterministic, read-only kibi.legacy-migration-plan.v1 preview for ready semantic-inventory repair batches.",
236
+ },
237
+ migrationLimit: {
238
+ type: "integer",
239
+ minimum: 1,
240
+ maximum: 10,
241
+ default: 1,
242
+ description:
243
+ "Maximum requirement migration batches to preview. Defaults to one review batch.",
244
+ },
245
+ migrationOffset: {
246
+ type: "integer",
247
+ minimum: 0,
248
+ default: 0,
249
+ description: "Zero-based offset into ready semantic-inventory batches.",
250
+ },
251
+ migrationPredicateLimit: {
252
+ type: "integer",
253
+ minimum: 1,
254
+ maximum: 20,
255
+ default: 5,
256
+ description:
257
+ "Maximum exact predicate-schema candidates retained per assertive proposition.",
258
+ },
259
+ migrationPredicateMinScore: {
260
+ type: "number",
261
+ minimum: 0,
262
+ maximum: 1,
263
+ default: 0.35,
264
+ description:
265
+ "Minimum deterministic predicate-schema rank score retained in migration previews.",
266
+ },
182
267
  },
183
268
  },
184
269
  requiresProlog: true,
@@ -39,10 +39,13 @@ export async function executeSemanticAdvisor(
39
39
  title,
40
40
  status: optionalString(args.status) ?? "open",
41
41
  source,
42
- text_ref: text,
42
+ semantic_text: text,
43
43
  },
44
44
  },
45
45
  ...(args.clauses !== undefined ? { clauses: args.clauses } : {}),
46
+ ...(args.interpretations !== undefined
47
+ ? { interpretations: args.interpretations }
48
+ : {}),
46
49
  });
47
50
  return {
48
51
  content: [
@@ -69,6 +72,15 @@ async function executeSemanticAdvisorInput(
69
72
  (value): value is string => typeof value === "string",
70
73
  )
71
74
  : undefined;
75
+ const interpretations = Array.isArray(input.interpretations)
76
+ ? input.interpretations.filter(
77
+ (
78
+ value,
79
+ ): value is NonNullable<
80
+ SemanticAdvisorArgs["interpretations"]
81
+ >[number] => typeof value === "object" && value !== null,
82
+ )
83
+ : undefined;
72
84
  return executeSemanticAdvisor(
73
85
  {
74
86
  text: requiredText(input.text),
@@ -78,6 +90,7 @@ async function executeSemanticAdvisorInput(
78
90
  ...(source ? { source } : {}),
79
91
  ...(status ? { status } : {}),
80
92
  ...(clauses !== undefined ? { clauses } : {}),
93
+ ...(interpretations !== undefined ? { interpretations } : {}),
81
94
  },
82
95
  context,
83
96
  );
@@ -103,12 +116,38 @@ export const semanticAdvisorSpec = {
103
116
  description:
104
117
  "Optional complete list of atomic requirement clauses supplied by the caller. Use this for compound prose so every normative clause receives a stable claim key and independent grounding review.",
105
118
  },
119
+ interpretations: {
120
+ type: "array",
121
+ maxItems: 3,
122
+ description:
123
+ "Optional host-LLM typed kibi.logic.v1 interpretations. Kibi validates and canonicalizes them; raw Prolog is not accepted.",
124
+ items: {
125
+ type: "object",
126
+ required: ["claim_key", "claim_text", "ir"],
127
+ properties: {
128
+ claim_key: { type: "string" },
129
+ claim_text: { type: "string" },
130
+ confidence: { type: "number", minimum: 0, maximum: 1 },
131
+ span: { type: "object" },
132
+ ir: { type: "object" },
133
+ },
134
+ },
135
+ },
106
136
  type: {
107
137
  type: "string",
108
- enum: ["req"],
138
+ enum: [
139
+ "req",
140
+ "scenario",
141
+ "test",
142
+ "adr",
143
+ "flag",
144
+ "event",
145
+ "symbol",
146
+ "fact",
147
+ ],
109
148
  default: "req",
110
149
  description:
111
- "Entity type context for analysis. Currently requirement prose is supported.",
150
+ "Entity type context for analysis. Requirement, domain-fact, and supporting prose all receive a proposition ledger; only requirements receive deterministic modeling suggestions.",
112
151
  },
113
152
  id: {
114
153
  type: "string",
@@ -0,0 +1,28 @@
1
+ import type { OperationContext, WorkspaceSnapshot } from "./runtime-types.js";
2
+
3
+ export type WorkspaceSnapshotEvidence =
4
+ | Readonly<{ available: true; snapshot: WorkspaceSnapshot }>
5
+ | Readonly<{ available: false; error: string }>;
6
+
7
+ export async function readWorkspaceSnapshot(
8
+ context: OperationContext,
9
+ ): Promise<WorkspaceSnapshotEvidence> {
10
+ if (!context.git?.workspaceSnapshot) {
11
+ return {
12
+ available: false,
13
+ error:
14
+ "The active operation runtime does not expose workspace snapshots.",
15
+ };
16
+ }
17
+ try {
18
+ return {
19
+ available: true,
20
+ snapshot: await context.git.workspaceSnapshot(context.workspaceRoot),
21
+ };
22
+ } catch (error) {
23
+ return {
24
+ available: false,
25
+ error: error instanceof Error ? error.message : String(error),
26
+ };
27
+ }
28
+ }