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
@@ -0,0 +1,22 @@
1
+ import { type LogicRuleIR } from "../../logic/ir.js";
2
+ export interface LogicApplyPlanInput {
3
+ readonly text: string;
4
+ readonly logic: LogicRuleIR;
5
+ readonly source: string;
6
+ readonly requirementId?: string;
7
+ readonly existingLogicClaims?: readonly string[];
8
+ readonly claimKey?: string;
9
+ readonly claimText?: string;
10
+ }
11
+ export interface LogicApplyPlanResult {
12
+ readonly normalized: LogicRuleIR;
13
+ readonly ruleHash: string;
14
+ readonly semanticKey: string;
15
+ readonly claimKey: string;
16
+ readonly claimText: string;
17
+ readonly renderedProlog: string;
18
+ readonly applyPlan: Array<Record<string, unknown>>;
19
+ }
20
+ export declare function logicRuleFactId(semanticKey: string): string;
21
+ export declare function buildLogicApplyPlan(input: LogicApplyPlanInput): LogicApplyPlanResult;
22
+ //# sourceMappingURL=logic-modeling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic-modeling.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/logic-modeling.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAIjB,MAAM,mBAAmB,CAAC;AAO3B,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAUD,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,mBAAmB,GACzB,oBAAoB,CAsHtB"}
@@ -0,0 +1,120 @@
1
+ import { createHash } from "node:crypto";
2
+ import { logicSemanticKey, utf8Span, validateLogicIr, } from "../../logic/ir.js";
3
+ import { normalizeSemanticClause, semanticClaimKey, } from "../semantic-advisor/clauses.js";
4
+ import { semanticSourceHash } from "../semantic-advisor/shared.js";
5
+ function shortId(value) {
6
+ return createHash("sha256")
7
+ .update(value)
8
+ .digest("hex")
9
+ .slice(0, 16)
10
+ .toUpperCase();
11
+ }
12
+ export function logicRuleFactId(semanticKey) {
13
+ return `FACT-RULE-${shortId(semanticKey)}`;
14
+ }
15
+ export function buildLogicApplyPlan(input) {
16
+ const validation = validateLogicIr(input.logic);
17
+ if (!validation.valid ||
18
+ !validation.normalized ||
19
+ !validation.ruleHash ||
20
+ !validation.semanticKey ||
21
+ !validation.renderedProlog) {
22
+ throw new Error(`Logic IR validation failed: ${validation.errors.join("; ")}`);
23
+ }
24
+ const sourceText = input.claimText?.trim() || input.text.trim();
25
+ const claimText = normalizeSemanticClause(sourceText);
26
+ const claimKey = input.claimKey || semanticClaimKey(claimText);
27
+ const semanticKey = logicSemanticKey(validation.normalized);
28
+ const schemaId = validation.normalized.ruleSchemaId ?? "FACT-RULE-SCHEMA-LOGIC-V1";
29
+ const ruleId = logicRuleFactId(semanticKey);
30
+ const claimStart = input.text.indexOf(claimText);
31
+ const span = utf8Span(input.text, claimStart >= 0 ? claimStart : 0, claimStart >= 0 ? claimStart + claimText.length : claimText.length);
32
+ const logicClaims = Array.from(new Set([...(input.existingLogicClaims ?? []), claimKey]));
33
+ const schemaPlan = input.logic.ruleSchemaId
34
+ ? []
35
+ : [
36
+ {
37
+ type: "fact",
38
+ id: schemaId,
39
+ properties: {
40
+ title: "kibi.logic.v1 rule schema",
41
+ status: "active",
42
+ source: input.source,
43
+ fact_kind: "rule_schema",
44
+ rule_name: "kibi.logic.v1",
45
+ argument_names: ["rule_ir"],
46
+ argument_types: ["logic_ir"],
47
+ aliases: ["conditional rule", "constraint", "policy rule"],
48
+ examples: [validation.renderedProlog],
49
+ },
50
+ relationships: [],
51
+ },
52
+ ];
53
+ return {
54
+ normalized: validation.normalized,
55
+ ruleHash: validation.ruleHash,
56
+ semanticKey,
57
+ claimKey,
58
+ claimText,
59
+ renderedProlog: validation.renderedProlog,
60
+ applyPlan: [
61
+ ...schemaPlan,
62
+ {
63
+ type: "fact",
64
+ id: ruleId,
65
+ properties: {
66
+ title: `${validation.normalized.kind} rule ${semanticKey}`,
67
+ status: "active",
68
+ source: input.source,
69
+ fact_kind: "rule",
70
+ rule_ir: validation.normalized,
71
+ rule_hash: validation.ruleHash,
72
+ semantic_key: semanticKey,
73
+ rule_schema_id: schemaId,
74
+ rule_name: validation.normalized.ruleSchemaId ?? "kibi.logic.v1",
75
+ canonical_key: semanticKey,
76
+ claim_key: claimKey,
77
+ claim_text: claimText,
78
+ claim_span_start: span.start,
79
+ claim_span_end: span.end,
80
+ tags: ["lane:logic", "logic-ir-v1"],
81
+ },
82
+ relationships: [],
83
+ },
84
+ {
85
+ type: "req",
86
+ id: input.requirementId ?? `REQ-LOGIC-${shortId(claimText)}`,
87
+ properties: {
88
+ title: claimText.split(/[.!?]/, 1)[0] || "Typed logical requirement",
89
+ status: "open",
90
+ source: input.source,
91
+ semantic_text: input.text.trim(),
92
+ logic_claims: logicClaims,
93
+ semantic_clauses: [claimText],
94
+ semantic_inventory_version: "kibi.semantic-inventory.v1",
95
+ semantic_source_field: "semantic_text",
96
+ semantic_source_hash: semanticSourceHash(input.text.trim()),
97
+ semantic_inventory: [
98
+ {
99
+ claim_key: claimKey,
100
+ claim_text: claimText,
101
+ role: /\b(?:must|shall|should|required|requires?)\b/i.test(claimText)
102
+ ? "normative"
103
+ : "descriptive",
104
+ status: "modeled",
105
+ span,
106
+ semantic_key: semanticKey,
107
+ },
108
+ ],
109
+ },
110
+ relationships: [
111
+ {
112
+ type: "requires_rule",
113
+ from: input.requirementId ?? `REQ-LOGIC-${shortId(claimText)}`,
114
+ to: ruleId,
115
+ },
116
+ ],
117
+ },
118
+ ],
119
+ };
120
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"model-requirement.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/model-requirement.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAGjF,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAMhC,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,GACxB,CAAC;AAEF,wBAAsB,4BAA4B,CAChD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBxB;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,oBAAoB,EAC1B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,sBAAsB,CAAC,CAmFjC;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAEjC"}
1
+ {"version":3,"file":"model-requirement.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/model-requirement.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAQjF,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAMhC,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,GACxB,CAAC;AAEF,wBAAsB,4BAA4B,CAChD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBxB;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,oBAAoB,EAC1B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,sBAAsB,CAAC,CAsKjC;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAEjC"}
@@ -2,7 +2,9 @@ import { readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { buildStrictWriteSet } from "../../public/check-types.js";
4
4
  import { getSchemaVersionStatus } from "../../public/schema-version.js";
5
- import { semanticClaimKey } from "../semantic-advisor/clauses.js";
5
+ import { normalizeSemanticClause, semanticClaimKey, } from "../semantic-advisor/clauses.js";
6
+ import { semanticSourceHash } from "../semantic-advisor/shared.js";
7
+ import { buildLogicApplyPlan } from "./logic-modeling.js";
6
8
  import { strictWriteSetToApplyPlan, writeSetPrimaryEntityId, } from "./requirement-applyplan.js";
7
9
  import { estimateNormativeSignalConfidence, extractRequirementClaim, } from "./requirement-modeler.js";
8
10
  import { normalizeOptionalString, normalizeSourceFiles, } from "./requirement-utils.js";
@@ -31,6 +33,61 @@ export async function handleKbModelRequirement(_prolog, args, workspaceRoot) {
31
33
  normalizeSourceFiles(args.sourceFiles)[0] ??
32
34
  "mcp://kibi/model-requirement",
33
35
  });
36
+ if (args.logic !== undefined) {
37
+ const logicPlan = buildLogicApplyPlan({
38
+ text: args.text,
39
+ logic: args.logic,
40
+ source: extracted.source,
41
+ ...(typeof args.requirementId === "string"
42
+ ? { requirementId: args.requirementId }
43
+ : {}),
44
+ ...(args.existingLogicClaims !== undefined
45
+ ? { existingLogicClaims: args.existingLogicClaims }
46
+ : {}),
47
+ ...(args.claimKey !== undefined ? { claimKey: args.claimKey } : {}),
48
+ ...(args.claimText !== undefined ? { claimText: args.claimText } : {}),
49
+ });
50
+ const fallbackWriteSet = buildStrictWriteSet({
51
+ claim: extracted.claim,
52
+ statement: extracted.statement,
53
+ });
54
+ const migrationWarning = await getWorkspaceMigrationWarning(workspaceRoot);
55
+ const structuredContent = {
56
+ statement: extracted.statement,
57
+ claimKey: logicPlan.claimKey,
58
+ logicClaims: Array.from(new Set([...(args.existingLogicClaims ?? []), logicPlan.claimKey])),
59
+ source: extracted.source,
60
+ sourceFiles: extracted.sourceFiles,
61
+ claim: extracted.claim,
62
+ writeSet: fallbackWriteSet,
63
+ applyPlan: logicPlan.applyPlan,
64
+ isStrict: false,
65
+ confidence: args.confidence ?? 1,
66
+ extractionMode: extracted.extractionMode,
67
+ extractionWarnings: extracted.extractionWarnings,
68
+ warnings: [],
69
+ migrationWarning,
70
+ logic: {
71
+ semanticKey: logicPlan.semanticKey,
72
+ claimKey: logicPlan.claimKey,
73
+ claimText: logicPlan.claimText,
74
+ renderedProlog: logicPlan.renderedProlog,
75
+ normalized: logicPlan.normalized,
76
+ },
77
+ };
78
+ return {
79
+ content: [
80
+ {
81
+ type: "text",
82
+ text: `Modeled typed kibi.logic.v1 rule ${logicPlan.semanticKey}; apply the returned schema, rule, and requirement steps sequentially.`,
83
+ },
84
+ ],
85
+ structuredContent,
86
+ applyPlan: logicPlan.applyPlan,
87
+ writeSet: fallbackWriteSet,
88
+ migrationWarning,
89
+ };
90
+ }
34
91
  const writeSet = buildStrictWriteSet({
35
92
  claim: extracted.claim,
36
93
  statement: extracted.statement,
@@ -52,9 +109,33 @@ export async function handleKbModelRequirement(_prolog, args, workspaceRoot) {
52
109
  };
53
110
  }
54
111
  if (step.type === "req") {
112
+ const claimText = extracted.statement.trim();
113
+ const normalizedClaimText = normalizeSemanticClause(claimText);
55
114
  return {
56
115
  ...step,
57
- properties: { ...properties, logic_claims: logicClaims },
116
+ properties: {
117
+ ...properties,
118
+ semantic_text: claimText,
119
+ logic_claims: logicClaims,
120
+ semantic_clauses: [claimText],
121
+ semantic_inventory_version: "kibi.semantic-inventory.v1",
122
+ semantic_source_field: "semantic_text",
123
+ semantic_source_hash: semanticSourceHash(claimText),
124
+ semantic_inventory: [
125
+ {
126
+ claim_key: claimKey,
127
+ claim_text: normalizedClaimText,
128
+ role: /\b(?:must|shall|should|required|requires?)\b/i.test(claimText)
129
+ ? "normative"
130
+ : "descriptive",
131
+ status: "modeled",
132
+ span: {
133
+ start: 0,
134
+ end: Buffer.byteLength(normalizedClaimText, "utf8"),
135
+ },
136
+ },
137
+ ],
138
+ },
58
139
  };
59
140
  }
60
141
  return step;
@@ -1,5 +1,5 @@
1
1
  import type { PredicateSchemaCandidate, PredicateSuggestion, SuggestPredicatesArgs } from "./predicate-types.js";
2
- export declare function buildSuggestion(schema: PredicateSchemaCandidate, text: string, subject: string, score: number): PredicateSuggestion;
2
+ export declare function buildSuggestion(schema: PredicateSchemaCandidate, text: string, subject: string, score: number, argumentBindings?: Readonly<Record<string, string>>, polarityHint?: "assert" | "deny"): PredicateSuggestion;
3
3
  export declare function buildPredicateApplyPlan(suggestion: PredicateSuggestion, args: SuggestPredicatesArgs): Array<Record<string, unknown>>;
4
4
  export declare function buildRelationshipPlan(factId: string | undefined, requirementId: string | undefined, claimText?: string, existingLogicClaims?: readonly string[]): Record<string, unknown> | null;
5
5
  export declare function buildGapApplyPlan(text: string, args: SuggestPredicatesArgs): Array<Record<string, unknown>>;
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-applyplan.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-applyplan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAI9B,wBAAgB,eAAe,CAC7B,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,mBAAmB,CAarB;AAGD,wBAAgB,uBAAuB,CACrC,UAAU,E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AAO,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAwBhC;AAGD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,qBAAqB,GAC1B,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+BhC"}
@@ -3,15 +3,32 @@ import { inferArgs } from "./predicate-inference.js";
3
3
  import { schemaForCandidate } from "./predicate-loader.js";
4
4
  import { hashId } from "./predicate-utils.js";
5
5
  // implements REQ-mcp-suggest-predicates
6
- export function buildSuggestion(schema, text, subject, score) {
7
- const predicateArgs = inferArgs(schema, text, subject);
6
+ export function buildSuggestion(schema, text, subject, score, argumentBindings = {}, polarityHint) {
7
+ const inferredArgs = inferArgs(schema, text, subject);
8
+ const predicateArgs = schema.argument_names.map((name, index) => {
9
+ const exactBinding = argumentBindings[name];
10
+ return typeof exactBinding === "string" && exactBinding.trim().length > 0
11
+ ? exactBinding.trim()
12
+ : (inferredArgs[index] ?? "unknown");
13
+ });
14
+ const unboundArguments = schema.argument_names.filter((_name, index) => predicateArgs[index] === "unknown");
8
15
  const canonicalKey = `${schema.predicate_name}(${predicateArgs.join(",")})`;
16
+ // Permission-style inference carries the deontic decision as its final
17
+ // argument. Preserve that polarity in the typed suggestion instead of
18
+ // silently turning a prohibition into an assertion.
19
+ const polarity = polarityHint ??
20
+ (predicateArgs.at(-1) === "deny" ||
21
+ /\b(?:must\s+not|shall\s+not|never|cannot|can't|forbidden|prohibited)\b/i.test(text)
22
+ ? "deny"
23
+ : "assert");
9
24
  return {
10
25
  id: hashId("SUGGEST", [schema.id, canonicalKey, text]),
11
26
  predicate_name: schema.predicate_name,
12
27
  predicate_args: predicateArgs,
13
28
  canonical_key: canonicalKey,
14
- polarity: "assert",
29
+ polarity,
30
+ binding_status: unboundArguments.length === 0 ? "complete" : "incomplete",
31
+ unbound_arguments: unboundArguments,
15
32
  score,
16
33
  rationale: `Matched ${schema.predicate_name} because the prose overlaps with ${schema.tags.join(", ")} cues.`,
17
34
  schema: schemaForCandidate(schema),
@@ -19,6 +36,8 @@ export function buildSuggestion(schema, text, subject, score) {
19
36
  }
20
37
  // implements REQ-mcp-suggest-predicates
21
38
  export function buildPredicateApplyPlan(suggestion, args) {
39
+ if (suggestion.binding_status !== "complete")
40
+ return [];
22
41
  const claimKey = semanticClaimKey(args.text);
23
42
  const factId = hashId("FACT-PRED", [
24
43
  args.requirementId ?? "",
@@ -98,7 +117,13 @@ export function buildGapApplyPlan(text, args) {
98
117
  claim_key: claimKey,
99
118
  claim_text: text,
100
119
  },
101
- relationships: [],
120
+ relationships: [
121
+ {
122
+ type: "relates_to",
123
+ from: factId,
124
+ to: "review:ontology-gap",
125
+ },
126
+ ],
102
127
  },
103
128
  ];
104
129
  }
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-inference.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-inference.ts"],"names":[],"mappings":"AAqDA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EASL,YAAY,EAIb,MAAM,sBAAsB,CAAC;AAG9B,wBAAgB,SAAS,CACvB,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CA8IV;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"predicate-inference.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-inference.ts"],"names":[],"mappings":"AAqDA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EASL,YAAY,EAIb,MAAM,sBAAsB,CAAC;AAG9B,wBAAgB,SAAS,CACvB,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CAiJV;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -141,6 +141,9 @@ export function inferArgs(schema, text, subject) {
141
141
  case "rate_limit":
142
142
  return inferRateLimitArgs(text);
143
143
  default:
144
+ // A schema argument name declares a role, not its ground value. Only
145
+ // the conventional subject slot has a separately reviewed hint;
146
+ // project-local non-subject arguments require exact argumentBindings.
144
147
  return schema.argument_names.map((name) => name === "subject" ? subject : "unknown");
145
148
  }
146
149
  }
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-loader.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAK3E,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAI9B,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CACxE,wBAAwB,EACxB,UAAU,CACX,GAAG;IACF,WAAW,EAAE,mBAAmB,CAAC;CAClC,CAeA;AAGD,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,sBAAsB,EAAE,OAAO,EAC/B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAwBrC;AAGD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,wBAAwB,EAAE,CA+B5B;AAGD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,mBAAmB,GAAG,SAAS,CAOjC;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAQpD"}
1
+ {"version":3,"file":"predicate-loader.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAK3E,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAI9B,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CACxE,wBAAwB,EACxB,UAAU,CACX,GAAG;IACF,WAAW,EAAE,mBAAmB,CAAC;CAClC,CAmBA;AAGD,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,sBAAsB,EAAE,OAAO,EAC/B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAwBrC;AAGD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,wBAAwB,EAAE,CAiC5B;AAGD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,mBAAmB,GAAG,SAAS,CAOjC;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAQpD"}
@@ -10,6 +10,10 @@ export function schemaForCandidate(schema) {
10
10
  description: schema.description,
11
11
  argument_names: schema.argument_names,
12
12
  argument_types: schema.argument_types,
13
+ ...(schema.aliases ? { aliases: schema.aliases } : {}),
14
+ ...(schema.paraphrase_templates
15
+ ? { paraphrase_templates: schema.paraphrase_templates }
16
+ : {}),
13
17
  examples: schema.examples,
14
18
  tags: schema.tags,
15
19
  usage_hints: schema.usage_hints ??
@@ -23,7 +27,7 @@ export async function loadExistingPredicateSchemas(prolog, includeExistingSchema
23
27
  return [];
24
28
  }
25
29
  try {
26
- const queryResult = await prolog.query("findall([Id,'fact',Props], (kb_entity(Id, 'fact', Props), member(fact_kind=predicate_schema, Props)), Results)");
30
+ const queryResult = await prolog.query("findall([Id,'fact',Props], (kb:predicate_schema(Id, _Namespace, _Name, _Arity, _ArgumentNames, _ArgumentTypes), kb_entity(Id, 'fact', Props)), Results)");
27
31
  if (!queryResult.success) {
28
32
  throw new Error(queryResult.error || "Query failed with unknown error");
29
33
  }
@@ -62,6 +66,8 @@ export function predicateSchemaFromEntity(entity) {
62
66
  ...stringArray(entity.aliases),
63
67
  ...stringArray(entity.tags),
64
68
  ],
69
+ aliases: stringArray(entity.aliases),
70
+ paraphrase_templates: stringArray(entity.paraphrase_templates),
65
71
  examples: stringArray(entity.examples),
66
72
  tags: stringArray(entity.tags),
67
73
  ...(usageHints ? { usage_hints: usageHints } : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-ranker.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-ranker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAUrE,wBAAgB,WAAW,CACzB,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,GACX,MAAM,CAcR"}
1
+ {"version":3,"file":"predicate-ranker.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-ranker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AA6BrE,wBAAgB,WAAW,CACzB,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,GACX,MAAM,CAuDR"}
@@ -2,6 +2,25 @@ import { scoreExactPredicates1 } from "./predicate-score-1.js";
2
2
  import { scoreExactPredicates2 } from "./predicate-score-2.js";
3
3
  import { scoreExactPredicates3 } from "./predicate-score-3.js";
4
4
  import { matchesKeyword } from "./predicate-utils.js";
5
+ function tokens(value) {
6
+ return value.toLowerCase().match(/[a-z0-9]+/g) ?? [];
7
+ }
8
+ function stem(value) {
9
+ if (value.length > 5 && value.endsWith("ies"))
10
+ return `${value.slice(0, -3)}y`;
11
+ if (value.length > 4 && value.endsWith("ing"))
12
+ return value.slice(0, -3);
13
+ if (value.length > 4 && value.endsWith("ed"))
14
+ return value.slice(0, -2);
15
+ if (value.length > 4 && value.endsWith("s"))
16
+ return value.slice(0, -1);
17
+ return value;
18
+ }
19
+ function overlap(left, right) {
20
+ const target = new Set(right.map(stem));
21
+ const matches = new Set(left.map(stem).filter((token) => target.has(token)));
22
+ return target.size === 0 ? 0 : matches.size / target.size;
23
+ }
5
24
  const EXACT_SCORERS = [
6
25
  scoreExactPredicates1,
7
26
  scoreExactPredicates2,
@@ -16,9 +35,28 @@ export function scoreSchema(schema, text) {
16
35
  }
17
36
  const lower = text.toLowerCase();
18
37
  const keywordHits = schema.keywords.filter((keyword) => matchesKeyword(text, lower, keyword)).length;
19
- if (keywordHits === 0)
38
+ const textTokens = tokens(text);
39
+ const descriptors = [
40
+ schema.predicate_name,
41
+ schema.title,
42
+ schema.description,
43
+ ...(schema.aliases ?? []),
44
+ ...(schema.paraphrase_templates ?? []),
45
+ ...schema.examples,
46
+ ];
47
+ const descriptorOverlap = Math.max(...descriptors.map((descriptor) => overlap(textTokens, tokens(descriptor))), 0);
48
+ const useWhenOverlap = Math.max(...(schema.usage_hints?.use_when ?? []).map((descriptor) => overlap(textTokens, tokens(descriptor))), 0);
49
+ const doNotUseWhenOverlap = Math.max(...(schema.usage_hints?.do_not_use_when ?? []).map((descriptor) => overlap(textTokens, tokens(descriptor))), 0);
50
+ const morphologyHits = schema.keywords.filter((keyword) => textTokens.map(stem).includes(stem(keyword.toLowerCase()))).length;
51
+ if (keywordHits === 0 && morphologyHits === 0 && descriptorOverlap < 0.25)
20
52
  return 0;
21
53
  const normalized = keywordHits / Math.max(3, schema.keywords.length / 2);
22
- const score = Math.min(0.98, 0.24 + normalized * 0.5 + keywordHits * 0.06);
54
+ const score = Math.min(0.98, Math.max(0, 0.2 +
55
+ normalized * 0.4 +
56
+ keywordHits * 0.05 +
57
+ morphologyHits * 0.04 +
58
+ descriptorOverlap * 0.3 +
59
+ useWhenOverlap * 0.08 -
60
+ doNotUseWhenOverlap * 0.18));
23
61
  return Math.round(score * 100) / 100;
24
62
  }
@@ -11,6 +11,9 @@ export interface PredicateSchemaCandidate {
11
11
  argument_names: string[];
12
12
  argument_types: string[];
13
13
  keywords: string[];
14
+ /** Human-language aliases and controlled paraphrase templates used for deterministic retrieval. */
15
+ aliases?: string[];
16
+ paraphrase_templates?: string[];
14
17
  examples: string[];
15
18
  tags: string[];
16
19
  usage_hints?: PredicateUsageHints;
@@ -23,6 +26,12 @@ export type SuggestPredicatesArgs = Readonly<Record<string, unknown>> & {
23
26
  readonly maxCandidates?: number;
24
27
  readonly minScore?: number;
25
28
  readonly includeExistingSchemas?: boolean;
29
+ /** Exact reviewed schema candidate ID to select instead of lexical ranking. */
30
+ readonly schemaId?: string;
31
+ /** Exact values keyed by the selected predicate schema's argument_names. */
32
+ readonly argumentBindings?: Readonly<Record<string, string>>;
33
+ /** Reviewed polarity override for negation-scope false positives. */
34
+ readonly polarityHint?: PredicatePolarity;
26
35
  /** Existing requirement claim manifest. Relationship guidance merges this list. */
27
36
  readonly existingLogicClaims?: readonly string[];
28
37
  };
@@ -32,6 +41,8 @@ export interface PredicateSuggestion {
32
41
  predicate_args: string[];
33
42
  canonical_key: string;
34
43
  polarity: PredicatePolarity;
44
+ binding_status: "complete" | "incomplete";
45
+ unbound_arguments: string[];
35
46
  score: number;
36
47
  rationale: string;
37
48
  schema: Omit<PredicateSchemaCandidate, "keywords"> & {
@@ -51,7 +62,7 @@ export interface SuggestPredicatesResult {
51
62
  requirementId: string | null;
52
63
  subject: string;
53
64
  candidates: PredicateSuggestion[];
54
- recommendedAction: "apply_requires_predicate" | "record_ontology_gap";
65
+ recommendedAction: "apply_requires_predicate" | "provide_argument_bindings" | "resolve_schema_reference" | "record_ontology_gap";
55
66
  applyPlan: Array<Record<string, unknown>>;
56
67
  relationshipPlan: Record<string, unknown> | null;
57
68
  warnings: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-types.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,MAAM,CAAC;A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-types.js";
2
3
  export type ModelRequirementArgs = Readonly<Record<string, unknown>> & {
3
4
  readonly text: string;
@@ -11,6 +12,10 @@ export type ModelRequirementArgs = Readonly<Record<string, unknown>> & {
11
12
  readonly provenance?: string;
12
13
  /** Existing requirement claim manifest. Returned req updates merge this list. */
13
14
  readonly existingLogicClaims?: readonly string[];
15
+ readonly logic?: LogicRuleIR;
16
+ readonly claimKey?: string;
17
+ readonly claimText?: string;
18
+ readonly requirementId?: string;
14
19
  };
15
20
  export interface ExtractedRequirementClaim {
16
21
  claim: SemanticClaim;
@@ -41,6 +46,13 @@ export interface ModelRequirementResult {
41
46
  nextAction: string;
42
47
  }>;
43
48
  migrationWarning: string | null;
49
+ logic?: {
50
+ readonly semanticKey: string;
51
+ readonly claimKey: string;
52
+ readonly claimText: string;
53
+ readonly renderedProlog: string;
54
+ readonly normalized: LogicRuleIR;
55
+ };
44
56
  };
45
57
  applyPlan: Array<Record<string, unknown>>;
46
58
  writeSet: StrictWriteSet;
@@ -1 +1 @@
1
- {"version":3,"file":"requirement-types.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/requirement-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACf,MAAM,6BAA6B,CAAC;AAGrC,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAA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AC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,QAAQ,EAAE,cAAc,CAAC;IACzB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"suggest-predicates.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/suggest-predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACX,MAAM,0CAA0C,CAAC;AAYlD,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EACV,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAK9B,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CA4ElC;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
1
+ {"version":3,"file":"suggest-predicates.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/suggest-predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACX,MAAM,0CAA0C,CAAC;AAYlD,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EACV,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAK9B,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CA+GlC;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
@@ -15,30 +15,54 @@ export async function handleKbSuggestPredicates(prolog, args) {
15
15
  const subject = inferSubject(text, args.subjectHint);
16
16
  const existingSchemas = await loadExistingPredicateSchemas(prolog, args.includeExistingSchemas ?? true, warnings);
17
17
  const schemas = [...existingSchemas, ...BUILT_IN_PREDICATE_SCHEMAS];
18
- const candidates = schemas
18
+ const selectedSchemas = args.schemaId
19
+ ? schemas.filter((schema) => schema.id === args.schemaId)
20
+ : schemas;
21
+ if (args.schemaId && selectedSchemas.length === 0) {
22
+ warnings.push(`Requested predicate schema ${args.schemaId} is not available. Refresh the KB or correct schemaId before retrying; no ontology-gap or predicate write plan was generated.`);
23
+ }
24
+ const candidates = selectedSchemas
19
25
  .map((schema) => ({ schema, score: scoreSchema(schema, text) }))
20
- .filter((scored) => scored.score >= minScore)
26
+ .filter((scored) => args.schemaId || scored.score >= minScore)
21
27
  .sort((left, right) => {
22
28
  if (right.score !== left.score)
23
29
  return right.score - left.score;
24
30
  return left.schema.predicate_name.localeCompare(right.schema.predicate_name);
25
31
  })
26
32
  .slice(0, maxCandidates)
27
- .map((scored) => buildSuggestion(scored.schema, text, subject, scored.score));
28
- if (candidates.length === 0) {
33
+ .map((scored) => buildSuggestion(scored.schema, text, subject, scored.score, args.argumentBindings, args.polarityHint));
34
+ if (candidates.length === 0 && !args.schemaId) {
29
35
  warnings.push("No predicate candidate met minScore. If this is recurring domain language, create a fact_kind=predicate_schema fact; otherwise keep the generated review:ontology-gap observation. Do not invent unsupported predicate names without a predicate_schema.");
30
36
  }
31
- const recommendedAction = candidates.length > 0 ? "apply_requires_predicate" : "record_ontology_gap";
32
37
  const firstCandidate = candidates[0];
33
- const applyPlan = firstCandidate
34
- ? buildPredicateApplyPlan(firstCandidate, args)
35
- : buildGapApplyPlan(text, args);
36
- const relationshipPlan = firstCandidate
38
+ const bindingsComplete = firstCandidate?.binding_status === "complete";
39
+ if (firstCandidate && !bindingsComplete) {
40
+ warnings.push(`Top predicate candidate ${firstCandidate.predicate_name} has unbound arguments: ${firstCandidate.unbound_arguments.join(", ")}. Supply exact argumentBindings keyed by the schema's argument_names before applying it.`);
41
+ }
42
+ const recommendedAction = !firstCandidate
43
+ ? args.schemaId
44
+ ? "resolve_schema_reference"
45
+ : "record_ontology_gap"
46
+ : bindingsComplete
47
+ ? "apply_requires_predicate"
48
+ : "provide_argument_bindings";
49
+ const applyPlan = !firstCandidate
50
+ ? args.schemaId
51
+ ? []
52
+ : buildGapApplyPlan(text, args)
53
+ : bindingsComplete
54
+ ? buildPredicateApplyPlan(firstCandidate, args)
55
+ : [];
56
+ const relationshipPlan = firstCandidate && bindingsComplete
37
57
  ? buildRelationshipPlan(String(applyPlan[0]?.id ?? ""), args.requirementId, text, args.existingLogicClaims)
38
58
  : null;
39
- const textSummary = candidates.length > 0
59
+ const textSummary = firstCandidate && bindingsComplete
40
60
  ? `Suggested ${candidates.length} predicate candidate(s). Top match: ${candidates[0]?.predicate_name}. Apply structured predicate facts before falling back to prose.`
41
- : "No predicate candidate met the confidence threshold; record an ontology gap instead of silently writing prose.";
61
+ : firstCandidate
62
+ ? `Matched ${firstCandidate.predicate_name}, but exact values are still required for: ${firstCandidate.unbound_arguments.join(", ")}. No apply plan was generated.`
63
+ : args.schemaId
64
+ ? `Requested predicate schema ${args.schemaId} is unavailable. No apply plan was generated.`
65
+ : "No predicate candidate met the confidence threshold; record an ontology gap instead of silently writing prose.";
42
66
  const claimKey = semanticClaimKey(text);
43
67
  const logicClaims = Array.from(new Set([...(args.existingLogicClaims ?? []), claimKey]));
44
68
  return {
@@ -17,6 +17,6 @@ export async function recordRelationshipAudits(prolog, relationships) {
17
17
  }
18
18
  }
19
19
  export function buildEntityDeleteAuditGoal(entity) {
20
- const auditEntity = Object.fromEntries(["id", "title", "source", "text_ref"].flatMap((key) => typeof entity[key] === "string" ? [[key, entity[key]]] : []));
20
+ const auditEntity = Object.fromEntries(["id", "title", "source", "text_ref", "semantic_text"].flatMap((key) => typeof entity[key] === "string" ? [[key, entity[key]]] : []));
21
21
  return `kb_retract_entity('${escapeAtom(String(entity.id))}', ${String(entity.type)}, ${buildPropertyList(auditEntity)})`;
22
22
  }