kibi-cli 0.14.0 → 0.16.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.
- package/bin/kibi +3 -1
- package/dist/cli-command.d.ts +5 -0
- package/dist/cli-command.d.ts.map +1 -0
- package/dist/cli-command.js +9 -0
- package/dist/cli-errors.d.ts +13 -0
- package/dist/cli-errors.d.ts.map +1 -0
- package/dist/cli-errors.js +26 -0
- package/dist/cli-input.d.ts +6 -0
- package/dist/cli-input.d.ts.map +1 -0
- package/dist/cli-input.js +54 -0
- package/dist/cli-json-command.d.ts +14 -0
- package/dist/cli-json-command.d.ts.map +1 -0
- package/dist/cli-json-command.js +96 -0
- package/dist/cli-protocol.d.ts +12 -0
- package/dist/cli-protocol.d.ts.map +1 -0
- package/dist/cli-protocol.js +37 -0
- package/dist/cli-register-foundation.d.ts +3 -0
- package/dist/cli-register-foundation.d.ts.map +1 -0
- package/dist/cli-register-foundation.js +90 -0
- package/dist/cli-register-maintenance.d.ts +3 -0
- package/dist/cli-register-maintenance.d.ts.map +1 -0
- package/dist/cli-register-maintenance.js +36 -0
- package/dist/cli-register-reporting.d.ts +3 -0
- package/dist/cli-register-reporting.d.ts.map +1 -0
- package/dist/cli-register-reporting.js +101 -0
- package/dist/cli-register-skills.d.ts +3 -0
- package/dist/cli-register-skills.d.ts.map +1 -0
- package/dist/cli-register-skills.js +71 -0
- package/dist/cli-validate.d.ts +18 -0
- package/dist/cli-validate.d.ts.map +1 -0
- package/dist/cli-validate.js +45 -0
- package/dist/cli.d.ts +4 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +48 -211
- package/dist/commands/aggregated-checks.d.ts +1 -1
- package/dist/commands/aggregated-checks.d.ts.map +1 -1
- package/dist/commands/aggregated-checks.js +28 -34
- package/dist/commands/check.d.ts +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +52 -94
- package/dist/commands/coverage.d.ts.map +1 -1
- package/dist/commands/coverage.js +12 -17
- package/dist/commands/discovery-shared.d.ts +2 -1
- package/dist/commands/discovery-shared.d.ts.map +1 -1
- package/dist/commands/discovery-shared.js +6 -18
- package/dist/commands/gaps.d.ts.map +1 -1
- package/dist/commands/gaps.js +15 -19
- package/dist/commands/graph.d.ts.map +1 -1
- package/dist/commands/graph.js +15 -21
- package/dist/commands/query.d.ts +7 -7
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/commands/query.js +98 -204
- package/dist/commands/search.d.ts +4 -4
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +14 -27
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +6 -7
- package/dist/commands/sync/manifest.d.ts +1 -1
- package/dist/commands/sync/manifest.d.ts.map +1 -1
- package/dist/commands/sync/manifest.js +9 -17
- package/dist/commands/sync/persistence.d.ts.map +1 -1
- package/dist/commands/sync/persistence.js +22 -1
- package/dist/extractors/markdown.d.ts +14 -2
- package/dist/extractors/markdown.d.ts.map +1 -1
- package/dist/extractors/markdown.js +38 -1
- package/dist/extractors/symbols-ts.d.ts.map +1 -1
- package/dist/extractors/symbols-ts.js +11 -1
- package/dist/operations/autopilot/activation.d.ts +4 -0
- package/dist/operations/autopilot/activation.d.ts.map +1 -0
- package/dist/operations/autopilot/activation.js +130 -0
- package/dist/operations/autopilot/candidate-helpers.d.ts +13 -0
- package/dist/operations/autopilot/candidate-helpers.d.ts.map +1 -0
- package/dist/operations/autopilot/candidate-helpers.js +55 -0
- package/dist/operations/autopilot/candidates.d.ts +4 -0
- package/dist/operations/autopilot/candidates.d.ts.map +1 -0
- package/dist/operations/autopilot/candidates.js +114 -0
- package/dist/operations/autopilot/discovery-evidence.d.ts +10 -0
- package/dist/operations/autopilot/discovery-evidence.d.ts.map +1 -0
- package/dist/operations/autopilot/discovery-evidence.js +158 -0
- package/dist/operations/autopilot/discovery.d.ts +4 -0
- package/dist/operations/autopilot/discovery.d.ts.map +1 -0
- package/dist/operations/autopilot/discovery.js +100 -0
- package/dist/operations/autopilot/generate.d.ts +8 -0
- package/dist/operations/autopilot/generate.d.ts.map +1 -0
- package/dist/operations/autopilot/generate.js +112 -0
- package/dist/operations/autopilot/guidance-actions.d.ts +3 -0
- package/dist/operations/autopilot/guidance-actions.d.ts.map +1 -0
- package/dist/operations/autopilot/guidance-actions.js +79 -0
- package/dist/operations/autopilot/guidance.d.ts +14 -0
- package/dist/operations/autopilot/guidance.d.ts.map +1 -0
- package/dist/operations/autopilot/guidance.js +124 -0
- package/dist/operations/autopilot/markdown-candidates.d.ts +7 -0
- package/dist/operations/autopilot/markdown-candidates.d.ts.map +1 -0
- package/dist/operations/autopilot/markdown-candidates.js +134 -0
- package/dist/operations/autopilot/presentation.d.ts +13 -0
- package/dist/operations/autopilot/presentation.d.ts.map +1 -0
- package/dist/operations/autopilot/presentation.js +91 -0
- package/dist/operations/autopilot/requirement-claims.d.ts +3 -0
- package/dist/operations/autopilot/requirement-claims.d.ts.map +1 -0
- package/dist/operations/autopilot/requirement-claims.js +48 -0
- package/dist/operations/autopilot/types.d.ts +117 -0
- package/dist/operations/autopilot/types.d.ts.map +1 -0
- package/dist/operations/autopilot/types.js +8 -0
- package/dist/operations/modeling/model-requirement.d.ts +10 -0
- package/dist/operations/modeling/model-requirement.d.ts.map +1 -0
- package/dist/operations/modeling/model-requirement.js +108 -0
- package/dist/operations/modeling/predicate-applyplan.d.ts +6 -0
- package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-applyplan.js +104 -0
- package/dist/operations/modeling/predicate-catalog-1.d.ts +3 -0
- package/dist/operations/modeling/predicate-catalog-1.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-catalog-1.js +200 -0
- package/dist/operations/modeling/predicate-catalog-2.d.ts +3 -0
- package/dist/operations/modeling/predicate-catalog-2.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-catalog-2.js +197 -0
- package/dist/operations/modeling/predicate-catalog-3.d.ts +3 -0
- package/dist/operations/modeling/predicate-catalog-3.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-catalog-3.js +193 -0
- package/dist/operations/modeling/predicate-catalog-4.d.ts +3 -0
- package/dist/operations/modeling/predicate-catalog-4.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-catalog-4.js +149 -0
- package/dist/operations/modeling/predicate-catalog.d.ts +5 -0
- package/dist/operations/modeling/predicate-catalog.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-catalog.js +29 -0
- package/dist/operations/modeling/predicate-inference-1.d.ts +16 -0
- package/dist/operations/modeling/predicate-inference-1.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-inference-1.js +161 -0
- package/dist/operations/modeling/predicate-inference-2.d.ts +19 -0
- package/dist/operations/modeling/predicate-inference-2.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-inference-2.js +169 -0
- package/dist/operations/modeling/predicate-inference-3.d.ts +15 -0
- package/dist/operations/modeling/predicate-inference-3.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-inference-3.js +163 -0
- package/dist/operations/modeling/predicate-inference.d.ts +5 -0
- package/dist/operations/modeling/predicate-inference.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-inference.js +148 -0
- package/dist/operations/modeling/predicate-loader.d.ts +10 -0
- package/dist/operations/modeling/predicate-loader.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-loader.js +88 -0
- package/dist/operations/modeling/predicate-ranker.d.ts +3 -0
- package/dist/operations/modeling/predicate-ranker.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-ranker.js +24 -0
- package/dist/operations/modeling/predicate-score-1.d.ts +3 -0
- package/dist/operations/modeling/predicate-score-1.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-score-1.js +121 -0
- package/dist/operations/modeling/predicate-score-2.d.ts +3 -0
- package/dist/operations/modeling/predicate-score-2.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-score-2.js +122 -0
- package/dist/operations/modeling/predicate-score-3.d.ts +3 -0
- package/dist/operations/modeling/predicate-score-3.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-score-3.js +54 -0
- package/dist/operations/modeling/predicate-types.d.ts +61 -0
- package/dist/operations/modeling/predicate-types.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-types.js +1 -0
- package/dist/operations/modeling/predicate-usage-hints-1.d.ts +3 -0
- package/dist/operations/modeling/predicate-usage-hints-1.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-usage-hints-1.js +211 -0
- package/dist/operations/modeling/predicate-usage-hints-2.d.ts +3 -0
- package/dist/operations/modeling/predicate-usage-hints-2.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-usage-hints-2.js +209 -0
- package/dist/operations/modeling/predicate-usage-hints-3.d.ts +3 -0
- package/dist/operations/modeling/predicate-usage-hints-3.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-usage-hints-3.js +45 -0
- package/dist/operations/modeling/predicate-utils.d.ts +23 -0
- package/dist/operations/modeling/predicate-utils.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-utils.js +187 -0
- package/dist/operations/modeling/requirement-applyplan.d.ts +4 -0
- package/dist/operations/modeling/requirement-applyplan.d.ts.map +1 -0
- package/dist/operations/modeling/requirement-applyplan.js +44 -0
- package/dist/operations/modeling/requirement-heuristics.d.ts +4 -0
- package/dist/operations/modeling/requirement-heuristics.d.ts.map +1 -0
- package/dist/operations/modeling/requirement-heuristics.js +114 -0
- package/dist/operations/modeling/requirement-modeler.d.ts +8 -0
- package/dist/operations/modeling/requirement-modeler.d.ts.map +1 -0
- package/dist/operations/modeling/requirement-modeler.js +70 -0
- package/dist/operations/modeling/requirement-types.d.ts +49 -0
- package/dist/operations/modeling/requirement-types.d.ts.map +1 -0
- package/dist/operations/modeling/requirement-types.js +1 -0
- package/dist/operations/modeling/requirement-utils.d.ts +10 -0
- package/dist/operations/modeling/requirement-utils.d.ts.map +1 -0
- package/dist/operations/modeling/requirement-utils.js +65 -0
- package/dist/operations/modeling/suggest-predicates.d.ts +6 -0
- package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -0
- package/dist/operations/modeling/suggest-predicates.js +64 -0
- package/dist/operations/mutation/audit.d.ts +6 -0
- package/dist/operations/mutation/audit.d.ts.map +1 -0
- package/dist/operations/mutation/audit.js +22 -0
- package/dist/operations/mutation/contradictions.d.ts +10 -0
- package/dist/operations/mutation/contradictions.d.ts.map +1 -0
- package/dist/operations/mutation/contradictions.js +40 -0
- package/dist/operations/mutation/delete.d.ts +5 -0
- package/dist/operations/mutation/delete.d.ts.map +1 -0
- package/dist/operations/mutation/delete.js +67 -0
- package/dist/operations/mutation/relationships.d.ts +17 -0
- package/dist/operations/mutation/relationships.d.ts.map +1 -0
- package/dist/operations/mutation/relationships.js +134 -0
- package/dist/operations/mutation/save.d.ts +4 -0
- package/dist/operations/mutation/save.d.ts.map +1 -0
- package/dist/operations/mutation/save.js +14 -0
- package/dist/operations/mutation/serialization.d.ts +5 -0
- package/dist/operations/mutation/serialization.d.ts.map +1 -0
- package/dist/operations/mutation/serialization.js +85 -0
- package/dist/operations/mutation/strict-fact.d.ts +4 -0
- package/dist/operations/mutation/strict-fact.d.ts.map +1 -0
- package/dist/operations/mutation/strict-fact.js +67 -0
- package/dist/operations/mutation/symbol-granularity.d.ts +4 -0
- package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -0
- package/dist/operations/mutation/symbol-granularity.js +109 -0
- package/dist/operations/mutation/symbol-refresh.d.ts +10 -0
- package/dist/operations/mutation/symbol-refresh.d.ts.map +1 -0
- package/dist/operations/mutation/symbol-refresh.js +105 -0
- package/dist/operations/mutation/types.d.ts +43 -0
- package/dist/operations/mutation/types.d.ts.map +1 -0
- package/dist/operations/mutation/types.js +1 -0
- package/dist/operations/mutation/upsert.d.ts +5 -0
- package/dist/operations/mutation/upsert.d.ts.map +1 -0
- package/dist/operations/mutation/upsert.js +103 -0
- package/dist/operations/mutation/validate-upsert.d.ts +5 -0
- package/dist/operations/mutation/validate-upsert.d.ts.map +1 -0
- package/dist/operations/mutation/validate-upsert.js +50 -0
- package/dist/operations/mutation/validation.d.ts +5 -0
- package/dist/operations/mutation/validation.d.ts.map +1 -0
- package/dist/operations/mutation/validation.js +107 -0
- package/dist/operations/mutation/warnings.d.ts +4 -0
- package/dist/operations/mutation/warnings.d.ts.map +1 -0
- package/dist/operations/mutation/warnings.js +17 -0
- package/dist/operations/semantic-advisor/analysis-receipt.d.ts +5 -0
- package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/analysis-receipt.js +112 -0
- package/dist/operations/semantic-advisor/analyze-prose.d.ts +5 -0
- package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/analyze-prose.js +271 -0
- package/dist/operations/semantic-advisor/clauses.d.ts +10 -0
- package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/clauses.js +43 -0
- package/dist/operations/semantic-advisor/observation-plan.d.ts +3 -0
- package/dist/operations/semantic-advisor/observation-plan.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/observation-plan.js +19 -0
- package/dist/operations/semantic-advisor/predicate-rule.d.ts +14 -0
- package/dist/operations/semantic-advisor/predicate-rule.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/predicate-rule.js +22 -0
- package/dist/operations/semantic-advisor/predicate-rules-core.d.ts +79 -0
- package/dist/operations/semantic-advisor/predicate-rules-core.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/predicate-rules-core.js +140 -0
- package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts +83 -0
- package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/predicate-rules-policy.js +150 -0
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts +48 -0
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.js +102 -0
- package/dist/operations/semantic-advisor/predicate-rules-product.d.ts +71 -0
- package/dist/operations/semantic-advisor/predicate-rules-product.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/predicate-rules-product.js +133 -0
- package/dist/operations/semantic-advisor/prose-coverage-evaluator.d.ts +29 -0
- package/dist/operations/semantic-advisor/prose-coverage-evaluator.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/prose-coverage-evaluator.js +54 -0
- package/dist/operations/semantic-advisor/shared.d.ts +18 -0
- package/dist/operations/semantic-advisor/shared.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/shared.js +209 -0
- package/dist/operations/semantic-advisor/strict-count-rules.d.ts +4 -0
- package/dist/operations/semantic-advisor/strict-count-rules.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/strict-count-rules.js +62 -0
- package/dist/operations/semantic-advisor/strict-rules.d.ts +4 -0
- package/dist/operations/semantic-advisor/strict-rules.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/strict-rules.js +106 -0
- package/dist/operations/semantic-advisor/types.d.ts +135 -0
- package/dist/operations/semantic-advisor/types.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/types.js +1 -0
- package/dist/prolog/codec.d.ts.map +1 -1
- package/dist/prolog/codec.js +9 -2
- package/dist/prolog.d.ts +5 -0
- package/dist/prolog.d.ts.map +1 -1
- package/dist/prolog.js +82 -30
- package/dist/public/impact/diagnostics.d.ts.map +1 -1
- package/dist/public/impact/diagnostics.js +8 -4
- package/dist/public/impact/full-kb-quality.d.ts +1 -1
- package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
- package/dist/public/impact/full-kb-quality.js +34 -1
- package/dist/public/impact/requirement-quality.d.ts.map +1 -1
- package/dist/public/impact/requirement-quality.js +6 -23
- package/dist/public/operations/catalog.d.ts +907 -0
- package/dist/public/operations/catalog.d.ts.map +1 -0
- package/dist/public/operations/catalog.js +42 -0
- package/dist/public/operations/check-executor.d.ts +21 -0
- package/dist/public/operations/check-executor.d.ts.map +1 -0
- package/dist/public/operations/check-executor.js +111 -0
- package/dist/public/operations/check-format-shared.d.ts +36 -0
- package/dist/public/operations/check-format-shared.d.ts.map +1 -0
- package/dist/public/operations/check-format-shared.js +107 -0
- package/dist/public/operations/check-helpers.d.ts +10 -0
- package/dist/public/operations/check-helpers.d.ts.map +1 -0
- package/dist/public/operations/check-helpers.js +107 -0
- package/dist/public/operations/discovery-entities.d.ts +14 -0
- package/dist/public/operations/discovery-entities.d.ts.map +1 -0
- package/dist/public/operations/discovery-entities.js +91 -0
- package/dist/public/operations/discovery-executors.d.ts +39 -0
- package/dist/public/operations/discovery-executors.d.ts.map +1 -0
- package/dist/public/operations/discovery-executors.js +101 -0
- package/dist/public/operations/index.d.ts +20 -0
- package/dist/public/operations/index.d.ts.map +1 -0
- package/dist/public/operations/index.js +18 -0
- package/dist/public/operations/node-ports.d.ts +15 -0
- package/dist/public/operations/node-ports.d.ts.map +1 -0
- package/dist/public/operations/node-ports.js +57 -0
- package/dist/public/operations/prolog-json.d.ts +5 -0
- package/dist/public/operations/prolog-json.d.ts.map +1 -0
- package/dist/public/operations/prolog-json.js +44 -0
- package/dist/public/operations/runtime-types.d.ts +69 -0
- package/dist/public/operations/runtime-types.d.ts.map +1 -0
- package/dist/public/operations/runtime-types.js +17 -0
- package/dist/public/operations/specs/autopilot.d.ts +82 -0
- package/dist/public/operations/specs/autopilot.d.ts.map +1 -0
- package/dist/public/operations/specs/autopilot.js +72 -0
- package/dist/public/operations/specs/check.d.ts +51 -0
- package/dist/public/operations/specs/check.d.ts.map +1 -0
- package/dist/public/operations/specs/check.js +62 -0
- package/dist/public/operations/specs/discovery.d.ts +94 -0
- package/dist/public/operations/specs/discovery.d.ts.map +1 -0
- package/dist/public/operations/specs/discovery.js +98 -0
- package/dist/public/operations/specs/modeling.d.ts +126 -0
- package/dist/public/operations/specs/modeling.d.ts.map +1 -0
- package/dist/public/operations/specs/modeling.js +117 -0
- package/dist/public/operations/specs/mutation-schemas.d.ts +233 -0
- package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -0
- package/dist/public/operations/specs/mutation-schemas.js +267 -0
- package/dist/public/operations/specs/mutation.d.ts +56 -0
- package/dist/public/operations/specs/mutation.d.ts.map +1 -0
- package/dist/public/operations/specs/mutation.js +44 -0
- package/dist/public/operations/specs/reporting.d.ts +185 -0
- package/dist/public/operations/specs/reporting.d.ts.map +1 -0
- package/dist/public/operations/specs/reporting.js +158 -0
- package/dist/public/operations/specs/semantic.d.ts +53 -0
- package/dist/public/operations/specs/semantic.d.ts.map +1 -0
- package/dist/public/operations/specs/semantic.js +105 -0
- package/dist/public/operations/specs/skills.d.ts +70 -0
- package/dist/public/operations/specs/skills.d.ts.map +1 -0
- package/dist/public/operations/specs/skills.js +107 -0
- package/dist/public/operations/specs/sparql.d.ts +39 -0
- package/dist/public/operations/specs/sparql.d.ts.map +1 -0
- package/dist/public/operations/specs/sparql.js +121 -0
- package/dist/public/operations/specs/upsert.d.ts +256 -0
- package/dist/public/operations/specs/upsert.d.ts.map +1 -0
- package/dist/public/operations/specs/upsert.js +27 -0
- package/dist/public/operations/types.d.ts +24 -0
- package/dist/public/operations/types.d.ts.map +1 -0
- package/dist/public/operations/types.js +1 -0
- package/dist/public/schemas/entity.d.ts.map +1 -1
- package/dist/public/schemas/entity.js +27 -0
- package/dist/public/skill-system/errors.d.ts +19 -0
- package/dist/public/skill-system/errors.d.ts.map +1 -0
- package/dist/public/skill-system/errors.js +36 -0
- package/dist/public/skill-system/loader.d.ts +9 -0
- package/dist/public/skill-system/loader.d.ts.map +1 -0
- package/dist/public/skill-system/loader.js +76 -0
- package/dist/public/skill-system/paths.d.ts +6 -0
- package/dist/public/skill-system/paths.d.ts.map +1 -0
- package/dist/public/skill-system/paths.js +25 -0
- package/dist/public/skill-system/types.d.ts +15 -0
- package/dist/public/skill-system/types.d.ts.map +1 -0
- package/dist/public/skill-system/types.js +1 -0
- package/dist/public/skill-system/validation.d.ts +10 -0
- package/dist/public/skill-system/validation.d.ts.map +1 -0
- package/dist/public/skill-system/validation.js +119 -0
- package/dist/public/skills/init-kibi/SKILL.md +62 -0
- package/dist/public/skills/kibi-freshness/SKILL.md +44 -0
- package/dist/public/skills/kibi-traceability/SKILL.md +54 -0
- package/dist/public/skills/kibi-usage/SKILL.md +119 -99
- package/dist/public/skills/kibi-usage/resources/fact-lanes.md +102 -0
- package/dist/public/skills/kibi-usage/resources/operation-access.md +44 -0
- package/dist/public/skills/kibi-usage/resources/workflows.md +26 -3
- package/dist/public/skills.d.ts +4 -41
- package/dist/public/skills.d.ts.map +1 -1
- package/dist/public/skills.js +3 -270
- package/dist/runtime/cli-runtime.d.ts +3 -0
- package/dist/runtime/cli-runtime.d.ts.map +1 -0
- package/dist/runtime/cli-runtime.js +96 -0
- package/dist/schemas/entity.schema.json +23 -0
- package/dist/traceability/staged-diagnostics.d.ts +1 -1
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-symbols-manifest.d.ts +1 -0
- package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
- package/dist/traceability/staged-symbols-manifest.js +38 -27
- package/dist/traceability/symbol-extract.d.ts.map +1 -1
- package/dist/traceability/symbol-extract.js +17 -1
- package/dist/traceability/temp-kb.d.ts.map +1 -1
- package/dist/traceability/temp-kb.js +34 -1
- package/dist/types/entities.d.ts +3 -0
- package/dist/types/entities.d.ts.map +1 -1
- package/dist/utils/rule-registry.d.ts.map +1 -1
- package/dist/utils/rule-registry.js +6 -0
- package/package.json +56 -2
- package/src/public/impact/diagnostics.ts +18 -11
- package/src/public/impact/full-kb-quality.ts +30 -3
- package/src/public/impact/requirement-quality.ts +6 -26
- package/src/public/operations/catalog.ts +60 -0
- package/src/public/operations/check-executor.ts +185 -0
- package/src/public/operations/check-format-shared.ts +178 -0
- package/src/public/operations/check-helpers.ts +141 -0
- package/src/public/operations/discovery-entities.ts +122 -0
- package/src/public/operations/discovery-executors.ts +176 -0
- package/src/public/operations/index.ts +19 -0
- package/src/public/operations/node-ports.ts +78 -0
- package/src/public/operations/prolog-json.ts +71 -0
- package/src/public/operations/runtime-types.ts +106 -0
- package/src/public/operations/specs/autopilot.ts +98 -0
- package/src/public/operations/specs/check.ts +72 -0
- package/src/public/operations/specs/discovery.ts +126 -0
- package/src/public/operations/specs/modeling.ts +154 -0
- package/src/public/operations/specs/mutation-schemas.ts +296 -0
- package/src/public/operations/specs/mutation.ts +58 -0
- package/src/public/operations/specs/reporting.ts +249 -0
- package/src/public/operations/specs/semantic.ts +135 -0
- package/src/public/operations/specs/skills.ts +142 -0
- package/src/public/operations/specs/sparql.ts +149 -0
- package/src/public/operations/specs/upsert.ts +40 -0
- package/src/public/operations/types.ts +57 -0
- package/src/public/schemas/entity.ts +27 -0
- package/src/public/skill-system/errors.ts +38 -0
- package/src/public/skill-system/loader.ts +108 -0
- package/src/public/skill-system/paths.ts +27 -0
- package/src/public/skill-system/types.ts +14 -0
- package/src/public/skill-system/validation.ts +175 -0
- package/src/public/skills/init-kibi/SKILL.md +62 -0
- package/src/public/skills/kibi-freshness/SKILL.md +44 -0
- package/src/public/skills/kibi-traceability/SKILL.md +54 -0
- package/src/public/skills/kibi-usage/SKILL.md +119 -99
- package/src/public/skills/kibi-usage/resources/fact-lanes.md +102 -0
- package/src/public/skills/kibi-usage/resources/operation-access.md +44 -0
- package/src/public/skills/kibi-usage/resources/workflows.md +26 -3
- package/src/public/skills.ts +18 -427
- package/src/schemas/entity.schema.json +23 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { buildFallbackClaim, extractHeuristicClaim, } from "./requirement-heuristics.js";
|
|
2
|
+
import { clampConfidence, normalizeClaimValue, normalizeOptionalString, normalizeSourceFiles, normalizeText, stripListPrefix, } from "./requirement-utils.js";
|
|
3
|
+
const NORMATIVE_SECTION_PATTERN = /\b(requirements?|polic(?:y|ies)|rules?)\b/i;
|
|
4
|
+
function hasExplicitClaimFields(args) {
|
|
5
|
+
return (args.subjectKey !== undefined ||
|
|
6
|
+
args.propertyKey !== undefined ||
|
|
7
|
+
args.operator !== undefined ||
|
|
8
|
+
args.value !== undefined);
|
|
9
|
+
}
|
|
10
|
+
// implements REQ-002
|
|
11
|
+
export function estimateNormativeSignalConfidence(statement, heading) {
|
|
12
|
+
const normalizedStatement = stripListPrefix(statement).toLowerCase();
|
|
13
|
+
if (!/\b(must|shall|should)\b/.test(normalizedStatement))
|
|
14
|
+
return 0;
|
|
15
|
+
let confidence = normalizedStatement.includes(" shall ")
|
|
16
|
+
? 0.86
|
|
17
|
+
: normalizedStatement.includes(" must ")
|
|
18
|
+
? 0.84
|
|
19
|
+
: 0.78;
|
|
20
|
+
if (heading && NORMATIVE_SECTION_PATTERN.test(heading))
|
|
21
|
+
confidence += 0.08;
|
|
22
|
+
return Math.round(Math.min(0.95, confidence) * 100) / 100;
|
|
23
|
+
}
|
|
24
|
+
// implements REQ-002
|
|
25
|
+
export function extractRequirementClaim(args) {
|
|
26
|
+
const statement = normalizeText(args.text);
|
|
27
|
+
const sourceFiles = normalizeSourceFiles(args.sourceFiles);
|
|
28
|
+
const source = normalizeOptionalString(args.source) ?? sourceFiles[0];
|
|
29
|
+
if (!source) {
|
|
30
|
+
throw new Error("Requirement modeling failed: provide source or at least one sourceFiles entry");
|
|
31
|
+
}
|
|
32
|
+
const provenance = normalizeOptionalString(args.provenance);
|
|
33
|
+
const confidence = clampConfidence(args.confidence);
|
|
34
|
+
if (hasExplicitClaimFields(args)) {
|
|
35
|
+
const subjectKey = normalizeOptionalString(args.subjectKey);
|
|
36
|
+
const propertyKey = normalizeOptionalString(args.propertyKey);
|
|
37
|
+
if (!subjectKey ||
|
|
38
|
+
!propertyKey ||
|
|
39
|
+
args.operator === undefined ||
|
|
40
|
+
args.value === undefined) {
|
|
41
|
+
throw new Error("Requirement modeling failed: subjectKey, propertyKey, operator, and value must all be provided when any extracted claim field is supplied");
|
|
42
|
+
}
|
|
43
|
+
const claim = {
|
|
44
|
+
source,
|
|
45
|
+
subjectKey,
|
|
46
|
+
propertyKey,
|
|
47
|
+
operator: args.operator,
|
|
48
|
+
value: normalizeClaimValue(args.value),
|
|
49
|
+
confidence,
|
|
50
|
+
...(provenance ? { provenance } : {}),
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
statement,
|
|
54
|
+
source,
|
|
55
|
+
sourceFiles,
|
|
56
|
+
claim,
|
|
57
|
+
extractionMode: "provided",
|
|
58
|
+
extractionWarnings: [],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const heuristic = extractHeuristicClaim(statement, source, confidence, provenance);
|
|
62
|
+
if (heuristic)
|
|
63
|
+
return { statement, source, sourceFiles, ...heuristic };
|
|
64
|
+
return {
|
|
65
|
+
statement,
|
|
66
|
+
source,
|
|
67
|
+
sourceFiles,
|
|
68
|
+
...buildFallbackClaim(statement, source, confidence, provenance),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SemanticClaim, StrictWriteSet } from "../../public/check-types.js";
|
|
2
|
+
export type ModelRequirementArgs = Readonly<Record<string, unknown>> & {
|
|
3
|
+
readonly text: string;
|
|
4
|
+
readonly source?: string;
|
|
5
|
+
readonly sourceFiles?: string[];
|
|
6
|
+
readonly confidence?: number;
|
|
7
|
+
readonly subjectKey?: string;
|
|
8
|
+
readonly propertyKey?: string;
|
|
9
|
+
readonly operator?: SemanticClaim["operator"];
|
|
10
|
+
readonly value?: string | number | boolean;
|
|
11
|
+
readonly provenance?: string;
|
|
12
|
+
/** Existing requirement claim manifest. Returned req updates merge this list. */
|
|
13
|
+
readonly existingLogicClaims?: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export interface ExtractedRequirementClaim {
|
|
16
|
+
claim: SemanticClaim;
|
|
17
|
+
extractionMode: "provided" | "heuristic" | "fallback";
|
|
18
|
+
extractionWarnings: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface ModelRequirementResult {
|
|
21
|
+
content: Array<{
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
}>;
|
|
25
|
+
structuredContent: {
|
|
26
|
+
statement: string;
|
|
27
|
+
claimKey: string;
|
|
28
|
+
logicClaims: string[];
|
|
29
|
+
source: string;
|
|
30
|
+
sourceFiles: string[];
|
|
31
|
+
claim: SemanticClaim;
|
|
32
|
+
writeSet: StrictWriteSet;
|
|
33
|
+
applyPlan: Array<Record<string, unknown>>;
|
|
34
|
+
isStrict: boolean;
|
|
35
|
+
confidence: number;
|
|
36
|
+
extractionMode: "provided" | "heuristic" | "fallback";
|
|
37
|
+
extractionWarnings: string[];
|
|
38
|
+
warnings: Array<{
|
|
39
|
+
kind: string;
|
|
40
|
+
message: string;
|
|
41
|
+
nextAction: string;
|
|
42
|
+
}>;
|
|
43
|
+
migrationWarning: string | null;
|
|
44
|
+
};
|
|
45
|
+
applyPlan: Array<Record<string, unknown>>;
|
|
46
|
+
writeSet: StrictWriteSet;
|
|
47
|
+
migrationWarning: string | null;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=requirement-types.d.ts.map
|
|
@@ -0,0 +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,CAAC,CAAC;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,iFAAiF;IACjF,QAAQ,CAAC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClD,CAAC;AAGF,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;IACtD,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAGD,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,KAAK,EAAE,aAAa,CAAC;QACrB,QAAQ,EAAE,cAAc,CAAC;QACzB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1C,QAAQ,EAAE,OAAO,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;QACtD,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC,CAAC;QACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,CAAC;IACF,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,QAAQ,EAAE,cAAc,CAAC;IACzB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function normalizeText(text: string): string;
|
|
2
|
+
export declare function normalizeOptionalString(value: string | undefined): string | undefined;
|
|
3
|
+
export declare function normalizeSourceFiles(sourceFiles: string[] | undefined): string[];
|
|
4
|
+
export declare function clampConfidence(confidence: number | undefined): number;
|
|
5
|
+
export declare function normalizeClaimValue(value: unknown): string | number | boolean;
|
|
6
|
+
export declare function stripListPrefix(value: string): string;
|
|
7
|
+
export declare function trimSentenceTail(value: string): string;
|
|
8
|
+
export declare function cleanSubject(value: string): string;
|
|
9
|
+
export declare function cleanPredicate(value: string): string;
|
|
10
|
+
//# sourceMappingURL=requirement-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirement-utils.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/requirement-utils.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlD;AAGD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,MAAM,GAAG,SAAS,CAGpB;AAGD,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EAAE,GAAG,SAAS,GAChC,MAAM,EAAE,CAUV;AAGD,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMtE;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAgB7E;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrD;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGlD;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// implements REQ-002
|
|
2
|
+
export function normalizeText(text) {
|
|
3
|
+
const normalized = String(text ?? "").trim();
|
|
4
|
+
if (!normalized) {
|
|
5
|
+
throw new Error("Requirement modeling failed: text must be a non-empty string");
|
|
6
|
+
}
|
|
7
|
+
return normalized;
|
|
8
|
+
}
|
|
9
|
+
// implements REQ-002
|
|
10
|
+
export function normalizeOptionalString(value) {
|
|
11
|
+
const normalized = String(value ?? "").trim();
|
|
12
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
13
|
+
}
|
|
14
|
+
// implements REQ-002
|
|
15
|
+
export function normalizeSourceFiles(sourceFiles) {
|
|
16
|
+
const seen = new Set();
|
|
17
|
+
const normalized = [];
|
|
18
|
+
for (const sourceFile of sourceFiles ?? []) {
|
|
19
|
+
const trimmed = String(sourceFile ?? "").trim();
|
|
20
|
+
if (!trimmed || seen.has(trimmed))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(trimmed);
|
|
23
|
+
normalized.push(trimmed);
|
|
24
|
+
}
|
|
25
|
+
return normalized;
|
|
26
|
+
}
|
|
27
|
+
// implements REQ-002
|
|
28
|
+
export function clampConfidence(confidence) {
|
|
29
|
+
const numeric = typeof confidence === "number" && Number.isFinite(confidence)
|
|
30
|
+
? confidence
|
|
31
|
+
: 0.8;
|
|
32
|
+
return Math.round(Math.min(1, Math.max(0, numeric)) * 100) / 100;
|
|
33
|
+
}
|
|
34
|
+
// implements REQ-002
|
|
35
|
+
export function normalizeClaimValue(value) {
|
|
36
|
+
if (typeof value === "string" ||
|
|
37
|
+
typeof value === "number" ||
|
|
38
|
+
typeof value === "boolean") {
|
|
39
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
40
|
+
throw new Error("Requirement modeling failed: value must be a finite number");
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
throw new Error("Requirement modeling failed: value must be a string, number, or boolean");
|
|
45
|
+
}
|
|
46
|
+
// implements REQ-002
|
|
47
|
+
export function stripListPrefix(value) {
|
|
48
|
+
return value
|
|
49
|
+
.replace(/^\s*[-*+]\s+/, "")
|
|
50
|
+
.replace(/^\s*\d+[.)]\s+/, "")
|
|
51
|
+
.trim();
|
|
52
|
+
}
|
|
53
|
+
// implements REQ-002
|
|
54
|
+
export function trimSentenceTail(value) {
|
|
55
|
+
return value.replace(/[\s.?!:;]+$/g, "").trim();
|
|
56
|
+
}
|
|
57
|
+
// implements REQ-002
|
|
58
|
+
export function cleanSubject(value) {
|
|
59
|
+
const cleaned = trimSentenceTail(stripListPrefix(value));
|
|
60
|
+
return cleaned.replace(/^(?:the|a|an)\s+/i, "").trim() || cleaned;
|
|
61
|
+
}
|
|
62
|
+
// implements REQ-002
|
|
63
|
+
export function cleanPredicate(value) {
|
|
64
|
+
return trimSentenceTail(stripListPrefix(value)) || "statement";
|
|
65
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OperationContext, PrologPort } from "../../public/operations/runtime-types.js";
|
|
2
|
+
import type { SuggestPredicatesArgs, SuggestPredicatesResult } from "./predicate-types.js";
|
|
3
|
+
export type { SuggestPredicatesArgs, SuggestPredicatesResult, } from "./predicate-types.js";
|
|
4
|
+
export declare function handleKbSuggestPredicates(prolog: PrologPort | null, args: SuggestPredicatesArgs): Promise<SuggestPredicatesResult>;
|
|
5
|
+
export declare function executeSuggestPredicates(args: SuggestPredicatesArgs, context: OperationContext): Promise<SuggestPredicatesResult>;
|
|
6
|
+
//# sourceMappingURL=suggest-predicates.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { semanticClaimKey } from "../semantic-advisor/clauses.js";
|
|
2
|
+
import { buildGapApplyPlan, buildPredicateApplyPlan, buildRelationshipPlan, buildSuggestion, } from "./predicate-applyplan.js";
|
|
3
|
+
import { BUILT_IN_PREDICATE_SCHEMAS } from "./predicate-catalog.js";
|
|
4
|
+
import { inferSubject } from "./predicate-inference.js";
|
|
5
|
+
import { loadExistingPredicateSchemas } from "./predicate-loader.js";
|
|
6
|
+
import { scoreSchema } from "./predicate-ranker.js";
|
|
7
|
+
import { clampInteger, clampScore, normalizeText } from "./predicate-utils.js";
|
|
8
|
+
const DEFAULT_MAX_CANDIDATES = 5;
|
|
9
|
+
// implements REQ-mcp-suggest-predicates
|
|
10
|
+
export async function handleKbSuggestPredicates(prolog, args) {
|
|
11
|
+
const text = normalizeText(args.text);
|
|
12
|
+
const maxCandidates = clampInteger(args.maxCandidates, DEFAULT_MAX_CANDIDATES, 1, 20);
|
|
13
|
+
const minScore = clampScore(args.minScore);
|
|
14
|
+
const warnings = [];
|
|
15
|
+
const subject = inferSubject(text, args.subjectHint);
|
|
16
|
+
const existingSchemas = await loadExistingPredicateSchemas(prolog, args.includeExistingSchemas ?? true, warnings);
|
|
17
|
+
const schemas = [...existingSchemas, ...BUILT_IN_PREDICATE_SCHEMAS];
|
|
18
|
+
const candidates = schemas
|
|
19
|
+
.map((schema) => ({ schema, score: scoreSchema(schema, text) }))
|
|
20
|
+
.filter((scored) => scored.score >= minScore)
|
|
21
|
+
.sort((left, right) => {
|
|
22
|
+
if (right.score !== left.score)
|
|
23
|
+
return right.score - left.score;
|
|
24
|
+
return left.schema.predicate_name.localeCompare(right.schema.predicate_name);
|
|
25
|
+
})
|
|
26
|
+
.slice(0, maxCandidates)
|
|
27
|
+
.map((scored) => buildSuggestion(scored.schema, text, subject, scored.score));
|
|
28
|
+
if (candidates.length === 0) {
|
|
29
|
+
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
|
+
}
|
|
31
|
+
const recommendedAction = candidates.length > 0 ? "apply_requires_predicate" : "record_ontology_gap";
|
|
32
|
+
const firstCandidate = candidates[0];
|
|
33
|
+
const applyPlan = firstCandidate
|
|
34
|
+
? buildPredicateApplyPlan(firstCandidate, args)
|
|
35
|
+
: buildGapApplyPlan(text, args);
|
|
36
|
+
const relationshipPlan = firstCandidate
|
|
37
|
+
? buildRelationshipPlan(String(applyPlan[0]?.id ?? ""), args.requirementId, text, args.existingLogicClaims)
|
|
38
|
+
: null;
|
|
39
|
+
const textSummary = candidates.length > 0
|
|
40
|
+
? `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.";
|
|
42
|
+
const claimKey = semanticClaimKey(text);
|
|
43
|
+
const logicClaims = Array.from(new Set([...(args.existingLogicClaims ?? []), claimKey]));
|
|
44
|
+
return {
|
|
45
|
+
content: [{ type: "text", text: textSummary }],
|
|
46
|
+
structuredContent: {
|
|
47
|
+
text,
|
|
48
|
+
claimKey,
|
|
49
|
+
logicClaims,
|
|
50
|
+
source: args.source ?? null,
|
|
51
|
+
requirementId: args.requirementId ?? null,
|
|
52
|
+
subject,
|
|
53
|
+
candidates,
|
|
54
|
+
recommendedAction,
|
|
55
|
+
applyPlan,
|
|
56
|
+
relationshipPlan,
|
|
57
|
+
warnings,
|
|
58
|
+
},
|
|
59
|
+
applyPlan,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function executeSuggestPredicates(args, context) {
|
|
63
|
+
return handleKbSuggestPredicates(context.prolog ?? null, args);
|
|
64
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PrologPort } from "../../public/operations/runtime-types.js";
|
|
2
|
+
import type { RelationshipInput } from "./types.js";
|
|
3
|
+
export declare function recordEntityAudit(prolog: PrologPort, change: "created" | "updated", entity: Readonly<Record<string, unknown>>): Promise<void>;
|
|
4
|
+
export declare function recordRelationshipAudits(prolog: PrologPort, relationships: readonly RelationshipInput[]): Promise<void>;
|
|
5
|
+
export declare function buildEntityDeleteAuditGoal(entity: Readonly<Record<string, unknown>>): string;
|
|
6
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/audit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAK3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC,CASf;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,SAAS,iBAAiB,EAAE,GAC1C,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,MAAM,CAOR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { escapeAtom } from "../../prolog/codec.js";
|
|
2
|
+
import { buildPropertyList, buildRelationshipMetadata, } from "./serialization.js";
|
|
3
|
+
export async function recordEntityAudit(prolog, change, entity) {
|
|
4
|
+
const result = await prolog.query(`kb_log_entity_upsert(${change}, ${String(entity.type)}, ${buildPropertyList(entity)})`);
|
|
5
|
+
if (!result.success) {
|
|
6
|
+
throw new Error(`Failed to record audit entry for ${String(entity.id)}: ${result.error ?? "Unknown error"}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export async function recordRelationshipAudits(prolog, relationships) {
|
|
10
|
+
for (const relationship of relationships) {
|
|
11
|
+
const from = String(relationship.from);
|
|
12
|
+
const to = String(relationship.to);
|
|
13
|
+
const result = await prolog.query(`kb_log_relationship_upsert(${String(relationship.type)}, '${escapeAtom(from)}', '${escapeAtom(to)}', ${buildRelationshipMetadata(relationship)})`);
|
|
14
|
+
if (!result.success) {
|
|
15
|
+
throw new Error(`Failed to record relationship audit entry ${from}->${to}: ${result.error ?? "Unknown error"}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function buildEntityDeleteAuditGoal(entity) {
|
|
20
|
+
const auditEntity = Object.fromEntries(["id", "title", "source", "text_ref"].flatMap((key) => typeof entity[key] === "string" ? [[key, entity[key]]] : []));
|
|
21
|
+
return `kb_retract_entity('${escapeAtom(String(entity.id))}', ${String(entity.type)}, ${buildPropertyList(auditEntity)})`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RelationshipInput } from "./types.js";
|
|
2
|
+
type TransactionInput = {
|
|
3
|
+
readonly entity: Readonly<Record<string, unknown>>;
|
|
4
|
+
readonly relationships: readonly RelationshipInput[];
|
|
5
|
+
readonly skipContradictionCheck: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function buildUpsertTransaction(input: TransactionInput): string;
|
|
8
|
+
export declare function formatUpsertError(entityId: string, raw?: string): string;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=contradictions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contradictions.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/contradictions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,KAAK,gBAAgB,GAAG;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;CAC1C,CAAC;AAGF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CActE;AAGD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CA0BxE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { escapeAtom } from "../../prolog/codec.js";
|
|
2
|
+
import { formatInvalidRelationshipError } from "./relationships.js";
|
|
3
|
+
import { buildPropertyList, buildRelationshipMetadata, } from "./serialization.js";
|
|
4
|
+
// implements REQ-kibi-operation-interface-parity
|
|
5
|
+
export function buildUpsertTransaction(input) {
|
|
6
|
+
const id = String(input.entity.id);
|
|
7
|
+
const type = String(input.entity.type);
|
|
8
|
+
const goals = [
|
|
9
|
+
`kb_assert_entity_no_audit(${type}, ${buildPropertyList(input.entity)})`,
|
|
10
|
+
...input.relationships.map((relationship) => `kb_assert_relationship_no_audit(${String(relationship.type)}, '${escapeAtom(String(relationship.from))}', '${escapeAtom(String(relationship.to))}', ${buildRelationshipMetadata(relationship)})`),
|
|
11
|
+
];
|
|
12
|
+
if (type === "req" && !input.skipContradictionCheck) {
|
|
13
|
+
goals.push(`check_req_contradiction('${escapeAtom(id)}')`);
|
|
14
|
+
}
|
|
15
|
+
return `rdf_transaction((${goals.join(", ")}))`;
|
|
16
|
+
}
|
|
17
|
+
// implements REQ-kibi-operation-interface-parity
|
|
18
|
+
export function formatUpsertError(entityId, raw) {
|
|
19
|
+
if (!raw)
|
|
20
|
+
return `Failed to upsert entity ${entityId}: Unknown error`;
|
|
21
|
+
const invalidRelationship = formatInvalidRelationshipError(raw);
|
|
22
|
+
if (invalidRelationship !== null) {
|
|
23
|
+
return `Failed to upsert entity ${entityId}: ${invalidRelationship}`;
|
|
24
|
+
}
|
|
25
|
+
const contradiction = raw.match(/kb_contradiction\(\s*\[([^\]]+)\]\s*\)/);
|
|
26
|
+
if (contradiction) {
|
|
27
|
+
const details = contradiction[1] ?? "";
|
|
28
|
+
const conflicts = [
|
|
29
|
+
...details.matchAll(/(?:'([^']+)'|"([^"\\]*(?:\\.[^"\\]*)*)")-'([^']+)'/g),
|
|
30
|
+
].map((match) => ` - Conflicts with ${String(match[3])}: ${String(match[1] ?? match[2])}`);
|
|
31
|
+
if (conflicts.length > 0) {
|
|
32
|
+
return `Contradiction detected for requirement ${entityId}:\n${[...new Set(conflicts)].join("\n")}\n\nTo resolve:\n 1. Add a supersedes relationship from the new requirement to the conflicting one, OR\n 2. Deprecate the conflicting requirement before creating the new one.`;
|
|
33
|
+
}
|
|
34
|
+
return `Contradiction detected for entity ${entityId}: This requirement conflicts with existing requirements. Add a supersedes relationship to the conflicting requirement, or deprecate the old requirement before creating the new one.`;
|
|
35
|
+
}
|
|
36
|
+
if (raw.includes("rdf_transaction")) {
|
|
37
|
+
return `Failed to upsert entity ${entityId}: Transaction failed`;
|
|
38
|
+
}
|
|
39
|
+
return `Failed to upsert entity ${entityId}: ${raw}`;
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OperationContext } from "../../public/operations/runtime-types.js";
|
|
2
|
+
import type { OperationResult } from "../../public/operations/types.js";
|
|
3
|
+
import type { DeleteInput, DeletePayload } from "./types.js";
|
|
4
|
+
export declare function executeDelete(input: DeleteInput, context: OperationContext): Promise<OperationResult<DeletePayload>>;
|
|
5
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/delete.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAIxE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+B7D,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CA6CzC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseEntityFromList, parseListOfLists } from "../../prolog/codec.js";
|
|
2
|
+
import { buildEntityDeleteAuditGoal } from "./audit.js";
|
|
3
|
+
import { dependentRelationshipsGoal } from "./relationships.js";
|
|
4
|
+
import { saveAtomicMutation, saveMutation } from "./save.js";
|
|
5
|
+
function requireProlog(context) {
|
|
6
|
+
if (context.prolog === undefined) {
|
|
7
|
+
throw new Error("Delete operation requires a Prolog runtime");
|
|
8
|
+
}
|
|
9
|
+
return context.prolog;
|
|
10
|
+
}
|
|
11
|
+
async function loadEntity(prolog, id) {
|
|
12
|
+
const safeId = id.replaceAll("'", "''");
|
|
13
|
+
const result = await prolog.query(`findall(['${safeId}',Type,Props], kb_entity('${safeId}', Type, Props), Results)`);
|
|
14
|
+
if (!result.success) {
|
|
15
|
+
throw new Error(`Failed to load metadata for entity ${id}: ${result.error ?? "Unknown error"}`);
|
|
16
|
+
}
|
|
17
|
+
const rows = parseListOfLists(result.bindings.Results ?? "[]");
|
|
18
|
+
if (rows.length === 0) {
|
|
19
|
+
throw new Error(`Failed to load metadata for entity ${id}: Entity not found`);
|
|
20
|
+
}
|
|
21
|
+
return { ...parseEntityFromList(rows[0] ?? []), id };
|
|
22
|
+
}
|
|
23
|
+
export async function executeDelete(input, context) {
|
|
24
|
+
const prolog = requireProlog(context);
|
|
25
|
+
if (input.ids.length === 0)
|
|
26
|
+
throw new Error("At least one ID required for delete");
|
|
27
|
+
try {
|
|
28
|
+
const errors = [];
|
|
29
|
+
const goals = [];
|
|
30
|
+
for (const id of input.ids) {
|
|
31
|
+
const safeId = id.replaceAll("'", "''");
|
|
32
|
+
const exists = await prolog.query(`once(kb_entity('${safeId}', _, _))`);
|
|
33
|
+
if (!exists.success) {
|
|
34
|
+
errors.push(`Entity ${id} does not exist`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const dependents = await prolog.query(dependentRelationshipsGoal(id));
|
|
38
|
+
if (!dependents.success) {
|
|
39
|
+
errors.push(`Failed to inspect dependents for entity ${id}: ${dependents.error ?? "Query failed"}`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if ((dependents.bindings.Dependents ?? "[]") !== "[]") {
|
|
43
|
+
errors.push(`Cannot delete entity ${id}: has dependents (other entities reference it)`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
goals.push(buildEntityDeleteAuditGoal(await loadEntity(prolog, id)));
|
|
47
|
+
}
|
|
48
|
+
if (goals.length > 0)
|
|
49
|
+
await saveAtomicMutation(prolog, goals, "delete");
|
|
50
|
+
else
|
|
51
|
+
await saveMutation(prolog, "delete");
|
|
52
|
+
const payload = { deleted: goals.length, skipped: errors.length, errors };
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: "text",
|
|
57
|
+
text: `Deleted ${payload.deleted} entities. Skipped ${payload.skipped}.${errors.length > 0 ? ` Errors: ${errors.join("; ")}` : ""}`,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
structuredContent: payload,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
65
|
+
throw new Error(`Delete execution failed: ${message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PrologPort } from "../../public/operations/runtime-types.js";
|
|
2
|
+
import type { RelationshipInput } from "./types.js";
|
|
3
|
+
export declare function dependentRelationshipsGoal(entityId: string): string;
|
|
4
|
+
type RelationshipTuple = {
|
|
5
|
+
readonly relType: string;
|
|
6
|
+
readonly fromType: string;
|
|
7
|
+
readonly toType: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function formatInvalidRelationshipTuple(tuple: RelationshipTuple): string;
|
|
10
|
+
export declare function formatInvalidRelationshipError(raw: string): string | null;
|
|
11
|
+
export declare function validateRelationshipSources(entityId: string, relationships: readonly RelationshipInput[]): void;
|
|
12
|
+
export declare function formatRelationshipSourceMismatch(entityId: string, relationship: RelationshipInput): string;
|
|
13
|
+
export declare function validateLiveRelationshipTargets(prolog: PrologPort, entity: Readonly<Record<string, unknown>>, relationships: readonly RelationshipInput[]): Promise<void>;
|
|
14
|
+
export declare function validateStrictLanePairing(prolog: PrologPort, relationships: readonly RelationshipInput[]): Promise<void>;
|
|
15
|
+
export declare function existingRelationships(prolog: PrologPort, entityId: string): Promise<readonly RelationshipInput[]>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=relationships.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/relationships.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAqBpD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAgCF,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,iBAAiB,GACvB,MAAM,CAER;AAED,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAczE;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,SAAS,iBAAiB,EAAE,GAC1C,IAAI,CAMN;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,iBAAiB,GAC9B,MAAM,CAIR;AAuBD,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,aAAa,EAAE,SAAS,iBAAiB,EAAE,GAC1C,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,SAAS,iBAAiB,EAAE,GAC1C,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAevC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { escapeAtom, toPrologAtom } from "../../prolog/codec.js";
|
|
2
|
+
import { parsePrologList } from "./serialization.js";
|
|
3
|
+
const RELATIONSHIP_TYPES = [
|
|
4
|
+
"depends_on",
|
|
5
|
+
"specified_by",
|
|
6
|
+
"verified_by",
|
|
7
|
+
"validates",
|
|
8
|
+
"implements",
|
|
9
|
+
"covered_by",
|
|
10
|
+
"executable_for",
|
|
11
|
+
"constrained_by",
|
|
12
|
+
"constrains",
|
|
13
|
+
"requires_property",
|
|
14
|
+
"requires_predicate",
|
|
15
|
+
"guards",
|
|
16
|
+
"publishes",
|
|
17
|
+
"consumes",
|
|
18
|
+
"supersedes",
|
|
19
|
+
"relates_to",
|
|
20
|
+
];
|
|
21
|
+
export function dependentRelationshipsGoal(entityId) {
|
|
22
|
+
return `findall([RelType,From], (member(RelType, [${RELATIONSHIP_TYPES.join(", ")}]), kb_relationship(RelType, From, '${escapeAtom(entityId)}')), Dependents)`;
|
|
23
|
+
}
|
|
24
|
+
function stringField(record, field) {
|
|
25
|
+
const value = record[field];
|
|
26
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
27
|
+
throw new Error(`Relationship ${field} must be a non-empty string`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function recipe(tuple) {
|
|
32
|
+
if (tuple.relType === "verified_by" &&
|
|
33
|
+
tuple.fromType === "fact" &&
|
|
34
|
+
tuple.toType === "test") {
|
|
35
|
+
return "Facts are not directly verified by tests. Create or update a requirement and link REQ -> TEST with verified_by. Link the requirement to the fact with constrains or requires_property.";
|
|
36
|
+
}
|
|
37
|
+
if (tuple.relType === "validates" &&
|
|
38
|
+
tuple.fromType === "test" &&
|
|
39
|
+
tuple.toType === "fact") {
|
|
40
|
+
return "Tests validate requirements or scenarios, not facts directly. Create or update a requirement and link TEST -> REQ with validates. Link the requirement to the fact with constrains or requires_property.";
|
|
41
|
+
}
|
|
42
|
+
if (tuple.relType === "verified_by")
|
|
43
|
+
return "verified_by is only valid as req/scenario -> test.";
|
|
44
|
+
if (tuple.relType === "validates")
|
|
45
|
+
return "validates is only valid as test -> req/scenario.";
|
|
46
|
+
return "Use a typed relationship from docs/entity-schema.md, or relates_to only as a reviewed escape hatch.";
|
|
47
|
+
}
|
|
48
|
+
export function formatInvalidRelationshipTuple(tuple) {
|
|
49
|
+
return `Invalid relationship: ${tuple.relType} from ${tuple.fromType} to ${tuple.toType}. ${recipe(tuple)}`;
|
|
50
|
+
}
|
|
51
|
+
export function formatInvalidRelationshipError(raw) {
|
|
52
|
+
const match = raw.match(/Invalid relationship:\s*([^\s~]+) from ([^\s~]+) to ([^\s.\-]+)/) ??
|
|
53
|
+
raw.match(/Invalid relationship:\s*~w from ~w to ~w-\[([^,\]]+),([^,\]]+),([^\]]+)\]/);
|
|
54
|
+
const relType = match?.[1];
|
|
55
|
+
const fromType = match?.[2];
|
|
56
|
+
const toType = match?.[3];
|
|
57
|
+
return relType && fromType && toType
|
|
58
|
+
? formatInvalidRelationshipTuple({ relType, fromType, toType })
|
|
59
|
+
: null;
|
|
60
|
+
}
|
|
61
|
+
export function validateRelationshipSources(entityId, relationships) {
|
|
62
|
+
for (const relationship of relationships) {
|
|
63
|
+
if (relationship.from !== entityId) {
|
|
64
|
+
throw new Error(formatRelationshipSourceMismatch(entityId, relationship));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function formatRelationshipSourceMismatch(entityId, relationship) {
|
|
69
|
+
const from = stringField(relationship, "from");
|
|
70
|
+
const to = stringField(relationship, "to");
|
|
71
|
+
return `Relationship source must match the upserted entity ${entityId}; received from=${from}. To add ${from} -> ${to}, upsert ${from} instead and include the relationship in that call.`;
|
|
72
|
+
}
|
|
73
|
+
async function endpointType(prolog, entity, endpointId) {
|
|
74
|
+
if (endpointId === entity.id && typeof entity.type === "string")
|
|
75
|
+
return entity.type;
|
|
76
|
+
let result;
|
|
77
|
+
try {
|
|
78
|
+
result = await prolog.query(`kb_entity('${escapeAtom(endpointId)}', Type, _)`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof Error)
|
|
82
|
+
return null;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (!result.success)
|
|
86
|
+
return null;
|
|
87
|
+
const type = result.bindings.Type;
|
|
88
|
+
return type ? type.replace(/^['"]|['"]$/g, "") : null;
|
|
89
|
+
}
|
|
90
|
+
export async function validateLiveRelationshipTargets(prolog, entity, relationships) {
|
|
91
|
+
for (const relationship of relationships) {
|
|
92
|
+
const fromType = await endpointType(prolog, entity, stringField(relationship, "from"));
|
|
93
|
+
const toType = await endpointType(prolog, entity, stringField(relationship, "to"));
|
|
94
|
+
if (fromType === null || toType === null)
|
|
95
|
+
continue;
|
|
96
|
+
const tuple = {
|
|
97
|
+
relType: stringField(relationship, "type"),
|
|
98
|
+
fromType,
|
|
99
|
+
toType,
|
|
100
|
+
};
|
|
101
|
+
const result = await prolog.query(`once(kb:validate_relationship(${toPrologAtom(tuple.relType)}, ${toPrologAtom(tuple.fromType)}, ${toPrologAtom(tuple.toType)}))`);
|
|
102
|
+
if (!result.success)
|
|
103
|
+
throw new Error(formatInvalidRelationshipTuple(tuple));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export async function validateStrictLanePairing(prolog, relationships) {
|
|
107
|
+
for (const relationship of relationships) {
|
|
108
|
+
const target = stringField(relationship, "to");
|
|
109
|
+
const wrongKind = relationship.type === "constrains"
|
|
110
|
+
? "property_value"
|
|
111
|
+
: relationship.type === "requires_property"
|
|
112
|
+
? "subject"
|
|
113
|
+
: null;
|
|
114
|
+
if (wrongKind === null)
|
|
115
|
+
continue;
|
|
116
|
+
const result = await prolog.query(`once((kb_entity('${escapeAtom(target)}', fact, _SlpProps), memberchk(fact_kind=_SlpFK, _SlpProps), normalize_term_atom(_SlpFK, ${wrongKind})))`);
|
|
117
|
+
if (result.success) {
|
|
118
|
+
const expected = relationship.type === "constrains" ? "subject" : "property_value";
|
|
119
|
+
throw new Error(`Relationship '${String(relationship.type)}' requires target '${target}' to be a ${expected}, observation, or meta fact. ${wrongKind[0]?.toUpperCase()}${wrongKind.slice(1)} facts cannot be direct targets of ${String(relationship.type)} relationships.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export async function existingRelationships(prolog, entityId) {
|
|
124
|
+
const existing = [];
|
|
125
|
+
for (const type of RELATIONSHIP_TYPES) {
|
|
126
|
+
const forward = await prolog.query(`findall(To, kb_relationship(${type}, '${escapeAtom(entityId)}', To), Targets)`);
|
|
127
|
+
for (const to of parsePrologList(forward.bindings.Targets ?? "[]"))
|
|
128
|
+
existing.push({ type, from: entityId, to });
|
|
129
|
+
const reverse = await prolog.query(`findall(From, kb_relationship(${type}, From, '${escapeAtom(entityId)}'), Sources)`);
|
|
130
|
+
for (const from of parsePrologList(reverse.bindings.Sources ?? "[]"))
|
|
131
|
+
existing.push({ type, from, to: entityId });
|
|
132
|
+
}
|
|
133
|
+
return existing;
|
|
134
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PrologPort } from "../../public/operations/runtime-types.js";
|
|
2
|
+
export declare function saveMutation(prolog: PrologPort, operation?: "upsert" | "delete"): Promise<void>;
|
|
3
|
+
export declare function saveAtomicMutation(prolog: PrologPort, goals: readonly string[], operation: "delete"): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=save.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/save.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,wBAAsB,YAAY,CAChC,MAAM,EAAE,UAAU,EAClB,SAAS,GAAE,QAAQ,GAAG,QAAmB,GACxC,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,SAAS,EAAE,QAAQ,GAClB,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function saveMutation(prolog, operation = "upsert") {
|
|
2
|
+
prolog.invalidateCache?.();
|
|
3
|
+
const result = await prolog.save();
|
|
4
|
+
if (!result.success) {
|
|
5
|
+
throw new Error(`Failed to save KB after ${operation}: ${result.error ?? "Unknown error"}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export async function saveAtomicMutation(prolog, goals, operation) {
|
|
9
|
+
const result = await prolog.query(`rdf_transaction((${[...goals, "kb_save"].join(", ")}))`);
|
|
10
|
+
if (!result.success) {
|
|
11
|
+
throw new Error(`Failed to save KB after ${operation}: ${result.error ?? "Unknown error"}`);
|
|
12
|
+
}
|
|
13
|
+
prolog.invalidateCache?.();
|
|
14
|
+
}
|