kibi-cli 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-protocol.d.ts.map +1 -1
- package/dist/cli-protocol.js +3 -2
- package/dist/cli-register-proof.d.ts.map +1 -1
- package/dist/cli-register-proof.js +25 -1
- package/dist/cli-register-reporting.d.ts.map +1 -1
- package/dist/cli-register-reporting.js +6 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/commands/aggregated-checks.d.ts +7 -0
- package/dist/commands/aggregated-checks.d.ts.map +1 -1
- package/dist/commands/aggregated-checks.js +25 -1
- package/dist/commands/check-generated.d.ts +7 -0
- package/dist/commands/check-generated.d.ts.map +1 -0
- package/dist/commands/check-generated.js +192 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +24 -15
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +227 -25
- package/dist/commands/engine.d.ts.map +1 -1
- package/dist/commands/engine.js +3 -1
- package/dist/commands/github-init.d.ts +1 -1
- package/dist/commands/github-init.d.ts.map +1 -1
- package/dist/commands/github-init.js +1 -1
- package/dist/commands/init-helpers.d.ts +17 -2
- package/dist/commands/init-helpers.d.ts.map +1 -1
- package/dist/commands/init-helpers.js +136 -30
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +110 -15
- package/dist/commands/proof-explain.d.ts +10 -0
- package/dist/commands/proof-explain.d.ts.map +1 -0
- package/dist/commands/proof-explain.js +45 -0
- package/dist/commands/proof-impact.d.ts +7 -0
- package/dist/commands/proof-impact.d.ts.map +1 -0
- package/dist/commands/proof-impact.js +39 -0
- package/dist/commands/proof-migrate-legacy.js +1 -1
- package/dist/commands/proof-prune.js +1 -1
- package/dist/commands/prove.d.ts.map +1 -1
- package/dist/commands/prove.js +14 -22
- package/dist/commands/report.d.ts.map +1 -1
- package/dist/commands/report.js +17 -2
- package/dist/commands/sync/cache.d.ts +20 -1
- package/dist/commands/sync/cache.d.ts.map +1 -1
- package/dist/commands/sync/cache.js +51 -2
- package/dist/commands/sync/discovery.d.ts.map +1 -1
- package/dist/commands/sync/discovery.js +1 -1
- package/dist/commands/sync/manifest.d.ts +1 -0
- package/dist/commands/sync/manifest.d.ts.map +1 -1
- package/dist/commands/sync/manifest.js +18 -16
- package/dist/commands/sync/persistence.d.ts.map +1 -1
- package/dist/commands/sync/persistence.js +14 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +11 -3
- package/dist/engine.d.ts +29 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +259 -89
- package/dist/env/bootstrap.d.ts +84 -0
- package/dist/env/bootstrap.d.ts.map +1 -0
- package/dist/env/bootstrap.js +310 -0
- package/dist/extractors/manifest.d.ts.map +1 -1
- package/dist/extractors/manifest.js +67 -29
- package/dist/extractors/markdown.d.ts +4 -0
- package/dist/extractors/markdown.d.ts.map +1 -1
- package/dist/extractors/markdown.js +33 -3
- package/dist/extractors/relationships.d.ts.map +1 -1
- package/dist/extractors/relationships.js +1 -0
- package/dist/extractors/symbols-coordinator.d.ts +8 -0
- package/dist/extractors/symbols-coordinator.d.ts.map +1 -1
- package/dist/extractors/symbols-coordinator.js +40 -0
- package/dist/extractors/symbols-ts.d.ts +8 -19
- package/dist/extractors/symbols-ts.d.ts.map +1 -1
- package/dist/extractors/symbols-ts.js +33 -503
- package/dist/intent-search.d.ts.map +1 -1
- package/dist/intent-search.js +68 -30
- package/dist/operations/bootstrap/generate.d.ts.map +1 -1
- package/dist/operations/bootstrap/generate.js +4 -3
- package/dist/operations/modeling/model-requirement.d.ts +1 -1
- package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
- package/dist/operations/modeling/model-requirement.js +179 -9
- package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-applyplan.js +14 -2
- package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-loader.js +24 -0
- package/dist/operations/modeling/predicate-types.d.ts +4 -0
- package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-vocabulary.d.ts +54 -0
- package/dist/operations/modeling/predicate-vocabulary.d.ts.map +1 -0
- package/dist/operations/modeling/predicate-vocabulary.js +169 -0
- package/dist/operations/modeling/requirement-types.d.ts +5 -0
- package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
- package/dist/operations/modeling/suggest-predicates.d.ts +1 -1
- package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
- package/dist/operations/modeling/suggest-predicates.js +30 -3
- package/dist/operations/modeling/vocabulary-alignment.d.ts +60 -0
- package/dist/operations/modeling/vocabulary-alignment.d.ts.map +1 -0
- package/dist/operations/modeling/vocabulary-alignment.js +178 -0
- package/dist/operations/mutation/contradictions.d.ts +3 -0
- package/dist/operations/mutation/contradictions.d.ts.map +1 -1
- package/dist/operations/mutation/contradictions.js +29 -0
- package/dist/operations/mutation/delete.d.ts.map +1 -1
- package/dist/operations/mutation/delete.js +33 -1
- package/dist/operations/mutation/predicate-vocabulary-guard.d.ts +8 -0
- package/dist/operations/mutation/predicate-vocabulary-guard.d.ts.map +1 -0
- package/dist/operations/mutation/predicate-vocabulary-guard.js +64 -0
- package/dist/operations/mutation/relationships.d.ts +1 -1
- package/dist/operations/mutation/relationships.d.ts.map +1 -1
- package/dist/operations/mutation/relationships.js +1 -0
- package/dist/operations/mutation/saga.d.ts +5 -0
- package/dist/operations/mutation/saga.d.ts.map +1 -1
- package/dist/operations/mutation/saga.js +10 -0
- package/dist/operations/mutation/serialization.d.ts.map +1 -1
- package/dist/operations/mutation/serialization.js +2 -0
- package/dist/operations/mutation/source-authoring.d.ts +6 -0
- package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
- package/dist/operations/mutation/source-authoring.js +65 -26
- package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
- package/dist/operations/mutation/strict-fact.js +5 -0
- package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -1
- package/dist/operations/mutation/symbol-granularity.js +9 -87
- package/dist/operations/mutation/types.d.ts +17 -0
- package/dist/operations/mutation/types.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.d.ts +6 -0
- package/dist/operations/mutation/upsert.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.js +72 -4
- package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
- package/dist/operations/mutation/validate-upsert.js +24 -1
- package/dist/operations/mutation/validation.d.ts.map +1 -1
- package/dist/operations/mutation/validation.js +16 -3
- package/dist/operations/planning/apply-plan.d.ts.map +1 -1
- package/dist/operations/planning/apply-plan.js +61 -17
- package/dist/operations/planning/compile-intent.d.ts +49 -0
- package/dist/operations/planning/compile-intent.d.ts.map +1 -1
- package/dist/operations/planning/compile-intent.js +66 -4
- package/dist/operations/proof/baseline-diff.d.ts +41 -0
- package/dist/operations/proof/baseline-diff.d.ts.map +1 -0
- package/dist/operations/proof/baseline-diff.js +153 -0
- package/dist/operations/proof/code-scope.d.ts +17 -0
- package/dist/operations/proof/code-scope.d.ts.map +1 -0
- package/dist/operations/proof/code-scope.js +60 -0
- package/dist/operations/proof/explain.d.ts +75 -0
- package/dist/operations/proof/explain.d.ts.map +1 -0
- package/dist/operations/proof/explain.js +294 -0
- package/dist/operations/proof/impact.d.ts +45 -0
- package/dist/operations/proof/impact.d.ts.map +1 -0
- package/dist/operations/proof/impact.js +118 -0
- package/dist/operations/proof/ingest-proof.d.ts +4 -2
- package/dist/operations/proof/ingest-proof.d.ts.map +1 -1
- package/dist/operations/proof/ingest-proof.js +251 -77
- package/dist/operations/proof/migrate-legacy-receipts.d.ts.map +1 -1
- package/dist/operations/proof/migrate-legacy-receipts.js +28 -22
- package/dist/operations/proof/prune-receipts.d.ts.map +1 -1
- package/dist/operations/proof/prune-receipts.js +8 -6
- package/dist/operations/proof/receipt-document.js +2 -2
- package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/analysis-receipt.js +3 -9
- package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/analyze-prose.js +18 -67
- package/dist/operations/semantic-advisor/plugin-orchestration.d.ts +63 -0
- package/dist/operations/semantic-advisor/plugin-orchestration.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/plugin-orchestration.js +489 -0
- package/dist/operations/semantic-advisor/predicate-rules-core.d.ts +15 -2
- package/dist/operations/semantic-advisor/predicate-rules-core.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/predicate-rules-core.js +7 -140
- package/dist/operations/semantic-advisor/predicate-rules-launcher.d.ts +11 -12
- package/dist/operations/semantic-advisor/predicate-rules-launcher.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/predicate-rules-launcher.js +6 -94
- package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts +16 -0
- package/dist/operations/semantic-advisor/predicate-rules-policy.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/predicate-rules-policy.js +7 -150
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts +9 -0
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/predicate-rules-product-tail.js +7 -102
- package/dist/operations/semantic-advisor/predicate-rules-product.d.ts +13 -0
- package/dist/operations/semantic-advisor/predicate-rules-product.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/predicate-rules-product.js +7 -133
- package/dist/operations/semantic-advisor/types.d.ts +1 -0
- package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
- package/dist/plugins/compose-ontology-packs.d.ts +51 -0
- package/dist/plugins/compose-ontology-packs.d.ts.map +1 -0
- package/dist/plugins/compose-ontology-packs.js +257 -0
- package/dist/plugins/compose-semantic-classifier.d.ts +47 -0
- package/dist/plugins/compose-semantic-classifier.d.ts.map +1 -0
- package/dist/plugins/compose-semantic-classifier.js +216 -0
- package/dist/plugins/compose-vocabulary-alignment.d.ts +23 -0
- package/dist/plugins/compose-vocabulary-alignment.d.ts.map +1 -0
- package/dist/plugins/compose-vocabulary-alignment.js +141 -0
- package/dist/plugins/external-allowlist.d.ts +17 -0
- package/dist/plugins/external-allowlist.d.ts.map +1 -0
- package/dist/plugins/external-allowlist.js +29 -0
- package/dist/plugins/index.d.ts +11 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +37 -0
- package/dist/plugins/load-plugin.d.ts +19 -0
- package/dist/plugins/load-plugin.d.ts.map +1 -0
- package/dist/plugins/load-plugin.js +59 -0
- package/dist/plugins/project-config.d.ts +28 -0
- package/dist/plugins/project-config.d.ts.map +1 -0
- package/dist/plugins/project-config.js +90 -0
- package/dist/plugins/registry.d.ts +94 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +359 -0
- package/dist/plugins/resolve-package.d.ts +47 -0
- package/dist/plugins/resolve-package.d.ts.map +1 -0
- package/dist/plugins/resolve-package.js +262 -0
- package/dist/plugins/source-analysis-service.d.ts +44 -0
- package/dist/plugins/source-analysis-service.d.ts.map +1 -0
- package/dist/plugins/source-analysis-service.js +232 -0
- package/dist/prolog/codec.d.ts.map +1 -1
- package/dist/prolog/codec.js +2 -0
- package/dist/prolog/janitor.d.ts.map +1 -1
- package/dist/prolog/janitor.js +1 -1
- package/dist/prolog/store-lock.d.ts +1 -1
- package/dist/prolog/store-lock.d.ts.map +1 -1
- package/dist/prolog.d.ts +36 -0
- package/dist/prolog.d.ts.map +1 -1
- package/dist/prolog.js +78 -9
- package/dist/proof/inspect.js +1 -1
- package/dist/proof/producers/playwright-case-id.js +2 -2
- package/dist/proof/producers/playwright-reporter.js +4 -4
- package/dist/public/diagnostic-usage.d.ts.map +1 -1
- package/dist/public/diagnostic-usage.js +7 -25
- package/dist/public/extractors/symbols-coordinator.d.ts +1 -1
- package/dist/public/extractors/symbols-coordinator.d.ts.map +1 -1
- package/dist/public/extractors/symbols-coordinator.js +1 -1
- package/dist/public/impact/analyzer.d.ts +1 -1
- package/dist/public/impact/analyzer.d.ts.map +1 -1
- package/dist/public/impact/analyzer.js +6 -4
- package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
- package/dist/public/impact/full-kb-quality.js +4 -12
- package/dist/public/operations/catalog.d.ts +39 -7
- package/dist/public/operations/catalog.d.ts.map +1 -1
- package/dist/public/operations/check-executor.d.ts.map +1 -1
- package/dist/public/operations/check-executor.js +11 -3
- package/dist/public/operations/check-helpers.d.ts +7 -1
- package/dist/public/operations/check-helpers.d.ts.map +1 -1
- package/dist/public/operations/check-helpers.js +22 -2
- package/dist/public/operations/contracts.d.ts.map +1 -1
- package/dist/public/operations/contracts.js +51 -12
- package/dist/public/operations/discovery-entities.d.ts +53 -1
- package/dist/public/operations/discovery-entities.d.ts.map +1 -1
- package/dist/public/operations/discovery-entities.js +219 -12
- package/dist/public/operations/discovery-executors.d.ts +1 -0
- package/dist/public/operations/discovery-executors.d.ts.map +1 -1
- package/dist/public/operations/discovery-executors.js +93 -59
- package/dist/public/operations/migration-plan.d.ts +2 -0
- package/dist/public/operations/migration-plan.d.ts.map +1 -1
- package/dist/public/operations/migration-plan.js +50 -0
- package/dist/public/operations/predicate-schema-conformance.d.ts +41 -0
- package/dist/public/operations/predicate-schema-conformance.d.ts.map +1 -0
- package/dist/public/operations/predicate-schema-conformance.js +242 -0
- package/dist/public/operations/prolog-json.d.ts +1 -1
- package/dist/public/operations/prolog-json.d.ts.map +1 -1
- package/dist/public/operations/prolog-json.js +16 -10
- package/dist/public/operations/result-envelope.d.ts +34 -1
- package/dist/public/operations/result-envelope.d.ts.map +1 -1
- package/dist/public/operations/result-envelope.js +78 -2
- package/dist/public/operations/runtime-types.d.ts +17 -2
- package/dist/public/operations/runtime-types.d.ts.map +1 -1
- package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
- package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
- package/dist/public/operations/specs/check-rules.generated.js +9 -1
- package/dist/public/operations/specs/check.d.ts +1 -1
- package/dist/public/operations/specs/discovery.d.ts +10 -1
- package/dist/public/operations/specs/discovery.d.ts.map +1 -1
- package/dist/public/operations/specs/discovery.js +10 -1
- package/dist/public/operations/specs/mutation-schemas.d.ts +27 -4
- package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
- package/dist/public/operations/specs/mutation-schemas.js +21 -3
- package/dist/public/operations/specs/proof.js +1 -1
- package/dist/public/operations/specs/reporting.d.ts +9 -0
- package/dist/public/operations/specs/reporting.d.ts.map +1 -1
- package/dist/public/operations/specs/reporting.js +48 -17
- package/dist/public/operations/specs/semantic.d.ts +1 -1
- package/dist/public/operations/specs/semantic.d.ts.map +1 -1
- package/dist/public/operations/specs/semantic.js +54 -4
- package/dist/public/operations/specs/upsert.d.ts +28 -5
- package/dist/public/operations/specs/upsert.d.ts.map +1 -1
- package/dist/public/operations/specs/upsert.js +1 -1
- package/dist/public/operations/symbol-repair-plan.d.ts.map +1 -1
- package/dist/public/operations/symbol-repair-plan.js +11 -4
- package/dist/public/operations/types.d.ts +5 -0
- package/dist/public/operations/types.d.ts.map +1 -1
- package/dist/public/proof-protocol.js +4 -4
- package/dist/public/schemas/entity.d.ts.map +1 -1
- package/dist/public/schemas/entity.js +22 -0
- package/dist/public/schemas/relationship.d.ts.map +1 -1
- package/dist/public/schemas/relationship.js +1 -0
- package/dist/public/skills/kibi-usage/SKILL.md +10 -3
- package/dist/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
- package/dist/public/skills/kibi-usage/resources/proof.md +45 -0
- package/dist/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
- package/dist/public/skills/kibi-usage/resources/source-authoring.md +36 -0
- package/dist/public/skills/kibi-usage/resources/workflows.md +52 -1
- package/dist/public/symbol-granularity.d.ts +1 -1
- package/dist/public/symbol-granularity.d.ts.map +1 -1
- package/dist/public/symbol-granularity.generated.d.ts.map +1 -1
- package/dist/public/symbol-granularity.generated.js +38 -5
- package/dist/public/telemetry-acceptance.d.ts.map +1 -1
- package/dist/public/telemetry-acceptance.js +21 -5
- package/dist/relationships/shards.d.ts +6 -0
- package/dist/relationships/shards.d.ts.map +1 -1
- package/dist/relationships/shards.js +26 -19
- package/dist/report/html-report.css +1239 -281
- package/dist/runtime/cli-runtime.d.ts.map +1 -1
- package/dist/runtime/cli-runtime.js +18 -0
- package/dist/schemas/entity.schema.json +32 -0
- package/dist/traceability/staged-diagnostics.d.ts +1 -1
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-entity-id-style.d.ts +12 -0
- package/dist/traceability/staged-entity-id-style.d.ts.map +1 -0
- package/dist/traceability/staged-entity-id-style.js +68 -0
- package/dist/traceability/symbol-extract.d.ts +24 -7
- package/dist/traceability/symbol-extract.d.ts.map +1 -1
- package/dist/traceability/symbol-extract.js +64 -208
- package/dist/traceability/temp-kb.d.ts.map +1 -1
- package/dist/traceability/temp-kb.js +8 -0
- package/dist/traceability/validate.js +1 -1
- package/dist/types/entities.d.ts +2 -0
- package/dist/types/entities.d.ts.map +1 -1
- package/dist/types/relationships.d.ts +1 -1
- package/dist/types/relationships.d.ts.map +1 -1
- package/dist/utils/entity-id-style.d.ts +27 -0
- package/dist/utils/entity-id-style.d.ts.map +1 -0
- package/dist/utils/entity-id-style.js +81 -0
- package/dist/utils/git-repository-context.d.ts +50 -0
- package/dist/utils/git-repository-context.d.ts.map +1 -0
- package/dist/utils/git-repository-context.js +259 -0
- package/dist/utils/rule-registry.d.ts +5 -0
- package/dist/utils/rule-registry.d.ts.map +1 -1
- package/dist/utils/rule-registry.generated.d.ts +42 -0
- package/dist/utils/rule-registry.generated.d.ts.map +1 -1
- package/dist/utils/rule-registry.generated.js +50 -0
- package/dist/utils/strict-modeling.d.ts +7 -0
- package/dist/utils/strict-modeling.d.ts.map +1 -1
- package/dist/utils/strict-modeling.js +11 -0
- package/package.json +14 -11
- package/schema/entities.pl +60 -1
- package/schema/relationships.pl +17 -4
- package/schema/validation.pl +118 -20
- package/src/public/diagnostic-usage.ts +16 -24
- package/src/public/extractors/symbols-coordinator.ts +1 -0
- package/src/public/impact/analyzer.ts +15 -12
- package/src/public/impact/full-kb-quality.ts +4 -16
- package/src/public/operations/check-executor.ts +13 -2
- package/src/public/operations/check-helpers.ts +29 -3
- package/src/public/operations/contracts.ts +59 -12
- package/src/public/operations/discovery-entities.ts +327 -12
- package/src/public/operations/discovery-executors.ts +110 -61
- package/src/public/operations/migration-plan.ts +57 -0
- package/src/public/operations/predicate-schema-conformance.ts +362 -0
- package/src/public/operations/prolog-json.ts +22 -8
- package/src/public/operations/result-envelope.ts +114 -2
- package/src/public/operations/runtime-types.ts +22 -3
- package/src/public/operations/specs/check-rules.generated.ts +9 -1
- package/src/public/operations/specs/discovery.ts +11 -1
- package/src/public/operations/specs/mutation-schemas.ts +23 -3
- package/src/public/operations/specs/proof.ts +1 -1
- package/src/public/operations/specs/reporting.ts +71 -24
- package/src/public/operations/specs/semantic.ts +79 -17
- package/src/public/operations/specs/upsert.ts +1 -1
- package/src/public/operations/symbol-repair-plan.ts +16 -7
- package/src/public/operations/types.ts +5 -0
- package/src/public/proof-fingerprint.ts +1 -1
- package/src/public/proof-protocol-types.d.ts +1 -1
- package/src/public/proof-protocol.ts +4 -4
- package/src/public/schemas/entity.ts +22 -0
- package/src/public/schemas/relationship.ts +1 -0
- package/src/public/skills/kibi-usage/SKILL.md +10 -3
- package/src/public/skills/kibi-usage/resources/fact-lanes.md +4 -0
- package/src/public/skills/kibi-usage/resources/proof.md +45 -0
- package/src/public/skills/kibi-usage/resources/relationship-directions.md +35 -17
- package/src/public/skills/kibi-usage/resources/source-authoring.md +36 -0
- package/src/public/skills/kibi-usage/resources/workflows.md +52 -1
- package/src/public/symbol-granularity.generated.ts +45 -12
- package/src/public/symbol-granularity.ts +3 -3
- package/src/public/telemetry-acceptance.ts +37 -6
- package/src/schemas/entity.schema.json +32 -0
- package/src/schemas/relationship.schema.json +1 -0
package/dist/engine.js
CHANGED
|
@@ -15,6 +15,7 @@ import { fileURLToPath } from "node:url";
|
|
|
15
15
|
import { PrologProcess, resolveKbPlPath } from "./prolog.js";
|
|
16
16
|
import { parseEntityFromList, parseListOfLists } from "./prolog/codec.js";
|
|
17
17
|
import { retryAttachAfterBreakingStaleLock } from "./prolog/store-lock.js";
|
|
18
|
+
import { queryEntityChunks } from "./public/operations/discovery-entities.js";
|
|
18
19
|
import { isValidBranchName } from "./utils/branch-resolver.js";
|
|
19
20
|
import { branchStorePath, ensureBranchStoreManifest, } from "./utils/branch-store-locator.js";
|
|
20
21
|
export const ENGINE_PROTOCOL_VERSION = 1;
|
|
@@ -219,11 +220,19 @@ function frame(value) {
|
|
|
219
220
|
header.writeUInt32BE(payload.byteLength, 0);
|
|
220
221
|
return Buffer.concat([header, payload]);
|
|
221
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Swallow a write failure for a peer that is already gone.
|
|
225
|
+
*
|
|
226
|
+
* A socket write reports EPIPE/ECONNRESET asynchronously, so a surrounding
|
|
227
|
+
* try/catch cannot see it and Node raises it as an unhandled error. Passing a
|
|
228
|
+
* callback keeps the failure local to this write.
|
|
229
|
+
*/
|
|
230
|
+
function ignoreWriteFailure() { }
|
|
222
231
|
function writeSocketFrame(socket, value) {
|
|
223
232
|
if (socket.destroyed || !socket.writable)
|
|
224
233
|
return;
|
|
225
234
|
try {
|
|
226
|
-
socket.write(frame(value));
|
|
235
|
+
socket.write(frame(value), ignoreWriteFailure);
|
|
227
236
|
}
|
|
228
237
|
catch {
|
|
229
238
|
// A client may disconnect while a queued request is finishing. The
|
|
@@ -783,16 +792,26 @@ export class EngineClient {
|
|
|
783
792
|
socket.on("close", () => {
|
|
784
793
|
this.socket = null;
|
|
785
794
|
const error = new Error("Kibi engine connection closed");
|
|
786
|
-
for (const pending of this.pending.values())
|
|
787
|
-
pending.reject(error);
|
|
795
|
+
for (const pending of this.pending.values()) {
|
|
796
|
+
this.settlePending(pending, () => pending.reject(error));
|
|
797
|
+
}
|
|
788
798
|
this.pending.clear();
|
|
789
799
|
});
|
|
790
800
|
socket.on("error", (error) => {
|
|
791
|
-
for (const pending of this.pending.values())
|
|
792
|
-
pending.reject(error);
|
|
801
|
+
for (const pending of this.pending.values()) {
|
|
802
|
+
this.settlePending(pending, () => pending.reject(error));
|
|
803
|
+
}
|
|
793
804
|
this.pending.clear();
|
|
794
805
|
});
|
|
795
806
|
}
|
|
807
|
+
/** Settle a pending RPC at most once (abort vs response race-safe). */
|
|
808
|
+
settlePending(pending, settle) {
|
|
809
|
+
if (pending.settled)
|
|
810
|
+
return false;
|
|
811
|
+
pending.settled = true;
|
|
812
|
+
settle();
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
796
815
|
handleResponse(value) {
|
|
797
816
|
if (value === null || typeof value !== "object")
|
|
798
817
|
return;
|
|
@@ -803,55 +822,20 @@ export class EngineClient {
|
|
|
803
822
|
if (!pending)
|
|
804
823
|
return;
|
|
805
824
|
this.pending.delete(response.id);
|
|
806
|
-
if (response.ok)
|
|
807
|
-
pending.resolve(response.result);
|
|
808
|
-
|
|
809
|
-
|
|
825
|
+
if (response.ok) {
|
|
826
|
+
this.settlePending(pending, () => pending.resolve(response.result));
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
this.settlePending(pending, () => pending.reject(new Error(response.error ?? "Kibi engine request failed")));
|
|
830
|
+
}
|
|
810
831
|
}
|
|
811
832
|
async request(request, signal) {
|
|
833
|
+
// Connect/reconcile before taking the client queue. Holding requestTail
|
|
834
|
+
// across start()→reconcileAttachment()→queryStatusJson() deadlocks because
|
|
835
|
+
// that nested status RPC needs the same queue (see command-first clients).
|
|
812
836
|
await this.start();
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
throw new Error("Kibi engine is not connected");
|
|
816
|
-
const id = ++this.requestId;
|
|
817
|
-
const result = new Promise((resolve, reject) => {
|
|
818
|
-
this.pending.set(id, {
|
|
819
|
-
resolve: resolve,
|
|
820
|
-
reject,
|
|
821
|
-
});
|
|
822
|
-
try {
|
|
823
|
-
socket.write(frame({
|
|
824
|
-
...request,
|
|
825
|
-
id,
|
|
826
|
-
protocolVersion: ENGINE_PROTOCOL_VERSION,
|
|
827
|
-
packageVersions: ENGINE_PACKAGE_VERSIONS,
|
|
828
|
-
workspaceRoot: this.workspaceRoot,
|
|
829
|
-
branch: this.branch,
|
|
830
|
-
}));
|
|
831
|
-
}
|
|
832
|
-
catch (error) {
|
|
833
|
-
this.pending.delete(id);
|
|
834
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
|
-
if (signal !== undefined) {
|
|
838
|
-
const abort = () => {
|
|
839
|
-
if (!this.pending.has(id))
|
|
840
|
-
return;
|
|
841
|
-
this.pending.delete(id);
|
|
842
|
-
this.cancel(id);
|
|
843
|
-
reject(new Error("Kibi engine request cancelled"));
|
|
844
|
-
};
|
|
845
|
-
if (signal.aborted)
|
|
846
|
-
abort();
|
|
847
|
-
else
|
|
848
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
849
|
-
}
|
|
850
|
-
});
|
|
851
|
-
return result;
|
|
852
|
-
}
|
|
853
|
-
async query(goal, signal) {
|
|
854
|
-
let result;
|
|
837
|
+
// Serialize query and command frames on one socket so concurrent MCP
|
|
838
|
+
// traffic cannot interleave length-prefixed writes/responses.
|
|
855
839
|
const previous = this.requestTail;
|
|
856
840
|
let release;
|
|
857
841
|
this.requestTail = new Promise((resolve) => {
|
|
@@ -859,14 +843,59 @@ export class EngineClient {
|
|
|
859
843
|
});
|
|
860
844
|
await previous;
|
|
861
845
|
try {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
846
|
+
const socket = this.socket;
|
|
847
|
+
if (socket === null || socket.destroyed)
|
|
848
|
+
throw new Error("Kibi engine is not connected");
|
|
849
|
+
const id = ++this.requestId;
|
|
850
|
+
return await new Promise((resolve, reject) => {
|
|
851
|
+
this.pending.set(id, {
|
|
852
|
+
resolve: resolve,
|
|
853
|
+
reject,
|
|
854
|
+
settled: false,
|
|
855
|
+
});
|
|
856
|
+
try {
|
|
857
|
+
socket.write(frame({
|
|
858
|
+
...request,
|
|
859
|
+
id,
|
|
860
|
+
protocolVersion: ENGINE_PROTOCOL_VERSION,
|
|
861
|
+
packageVersions: ENGINE_PACKAGE_VERSIONS,
|
|
862
|
+
workspaceRoot: this.workspaceRoot,
|
|
863
|
+
branch: this.branch,
|
|
864
|
+
}), ignoreWriteFailure);
|
|
865
|
+
}
|
|
866
|
+
catch (error) {
|
|
867
|
+
const pending = this.pending.get(id);
|
|
868
|
+
this.pending.delete(id);
|
|
869
|
+
if (pending) {
|
|
870
|
+
this.settlePending(pending, () => reject(error instanceof Error ? error : new Error(String(error))));
|
|
871
|
+
}
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
if (signal !== undefined) {
|
|
875
|
+
const abort = () => {
|
|
876
|
+
const pending = this.pending.get(id);
|
|
877
|
+
if (!pending || pending.settled)
|
|
878
|
+
return;
|
|
879
|
+
this.pending.delete(id);
|
|
880
|
+
this.cancel(id);
|
|
881
|
+
this.settlePending(pending, () => reject(new Error("Kibi engine request cancelled")));
|
|
882
|
+
};
|
|
883
|
+
if (signal.aborted)
|
|
884
|
+
abort();
|
|
885
|
+
else
|
|
886
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
887
|
+
}
|
|
888
|
+
});
|
|
865
889
|
}
|
|
866
890
|
finally {
|
|
867
891
|
release();
|
|
868
892
|
}
|
|
869
893
|
}
|
|
894
|
+
async query(goal, signal) {
|
|
895
|
+
const result = await this.request({ method: "query", goal }, signal);
|
|
896
|
+
this.lastResult = result;
|
|
897
|
+
return result;
|
|
898
|
+
}
|
|
870
899
|
/** Execute a versioned, goal-free engine command. Raw query remains private
|
|
871
900
|
* compatibility traffic for the in-process Prolog adapter only. */
|
|
872
901
|
async command(command, signal) {
|
|
@@ -877,6 +906,11 @@ export class EngineClient {
|
|
|
877
906
|
return this.query(`rdf_transaction((${normalized.join(", ")}))`);
|
|
878
907
|
}
|
|
879
908
|
async queryEntities(input, signal) {
|
|
909
|
+
// Full entities carry receipt histories; a caller-sized page (up to 100k
|
|
910
|
+
// rows) is split into bounded engine requests.
|
|
911
|
+
return queryEntityChunks((chunk) => this.queryEntityChunk(chunk, signal), input);
|
|
912
|
+
}
|
|
913
|
+
async queryEntityChunk(input, signal) {
|
|
880
914
|
const result = await this.command({
|
|
881
915
|
version: 1,
|
|
882
916
|
kind: "entities",
|
|
@@ -936,7 +970,7 @@ export class EngineClient {
|
|
|
936
970
|
packageVersions: ENGINE_PACKAGE_VERSIONS,
|
|
937
971
|
workspaceRoot: this.workspaceRoot,
|
|
938
972
|
branch: this.branch,
|
|
939
|
-
}));
|
|
973
|
+
}), ignoreWriteFailure);
|
|
940
974
|
}
|
|
941
975
|
async nextSolution() {
|
|
942
976
|
const result = this.lastResult;
|
|
@@ -952,8 +986,8 @@ export class EngineClient {
|
|
|
952
986
|
async checkpoint() {
|
|
953
987
|
return this.command({ version: 1, kind: "checkpoint" });
|
|
954
988
|
}
|
|
955
|
-
async queryStatusJson() {
|
|
956
|
-
return this.command({ version: 1, kind: "status" });
|
|
989
|
+
async queryStatusJson(signal) {
|
|
990
|
+
return this.command({ version: 1, kind: "status" }, signal);
|
|
957
991
|
}
|
|
958
992
|
async compact() {
|
|
959
993
|
return this.command({ version: 1, kind: "compact" });
|
|
@@ -1266,6 +1300,92 @@ function recoverInterruptedGeneration(branchPath) {
|
|
|
1266
1300
|
}
|
|
1267
1301
|
}
|
|
1268
1302
|
}
|
|
1303
|
+
function isEngineLifecycleRequest(request) {
|
|
1304
|
+
if (request.method === "stop" || request.method === "cancel")
|
|
1305
|
+
return true;
|
|
1306
|
+
const kind = request.command?.kind;
|
|
1307
|
+
return (request.method === "command" &&
|
|
1308
|
+
(kind === "stop" || kind === "cancel" || kind === "lifecycle"));
|
|
1309
|
+
}
|
|
1310
|
+
const ENGINE_PRELOADED_MODULES = [
|
|
1311
|
+
["status.pl", "status"],
|
|
1312
|
+
["discovery.pl", "discovery"],
|
|
1313
|
+
];
|
|
1314
|
+
const USE_MODULE_GOAL = /^use_module\('(?:[^']|'')*'\)$/u;
|
|
1315
|
+
/**
|
|
1316
|
+
* Owns the daemon's interactive SWI session: the attached branch store plus
|
|
1317
|
+
* every module loaded into it. An overflow or timeout terminates the SWI
|
|
1318
|
+
* child; the next request recycles the session (restart, reattach, reload
|
|
1319
|
+
* modules) instead of letting the port degrade into isolated one-shot
|
|
1320
|
+
* processes that have lost the attachment and module state.
|
|
1321
|
+
*/
|
|
1322
|
+
// implements REQ-core-journaled-engine-persistence
|
|
1323
|
+
export class EngineSession {
|
|
1324
|
+
prolog;
|
|
1325
|
+
branchPath;
|
|
1326
|
+
modules = [];
|
|
1327
|
+
constructor(prolog, branchPath) {
|
|
1328
|
+
this.prolog = prolog;
|
|
1329
|
+
this.branchPath = branchPath;
|
|
1330
|
+
const coreModuleDir = path.dirname(resolveKbPlPath());
|
|
1331
|
+
for (const [fileName, label] of ENGINE_PRELOADED_MODULES) {
|
|
1332
|
+
const modulePath = path.join(coreModuleDir, fileName);
|
|
1333
|
+
this.modules.push({
|
|
1334
|
+
goal: `use_module('${quoteProlog(modulePath.replaceAll("\\", "/"))}')`,
|
|
1335
|
+
label,
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
async boot() {
|
|
1340
|
+
await this.prolog.start();
|
|
1341
|
+
const attached = await this.prolog.query(`kb_attach('${quoteProlog(this.branchPath)}')`);
|
|
1342
|
+
if (!attached.success) {
|
|
1343
|
+
// The daemon hosts the branch store for every later request, so a
|
|
1344
|
+
// store-locked startup with a provably dead holder is auto-healed here
|
|
1345
|
+
// exactly like the CLI runtime path; live holders abort the startup
|
|
1346
|
+
// with the holder identity surfaced.
|
|
1347
|
+
const recovered = await retryAttachAfterBreakingStaleLock(this.prolog, this.branchPath, attached);
|
|
1348
|
+
if (!recovered.success)
|
|
1349
|
+
throw new Error(recovered.error ?? "Failed to attach branch KB");
|
|
1350
|
+
}
|
|
1351
|
+
for (const { goal, label } of this.modules) {
|
|
1352
|
+
const loaded = await this.prolog.query(goal);
|
|
1353
|
+
if (!loaded.success) {
|
|
1354
|
+
throw new Error(loaded.error ?? `Failed to load Kibi ${label} module`);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
/** Remember a successful client module load so a recycle restores it. */
|
|
1359
|
+
recordModuleLoad(goal, result) {
|
|
1360
|
+
const normalized = goal.trim().replace(/\.+\s*$/u, "");
|
|
1361
|
+
if (result.success &&
|
|
1362
|
+
USE_MODULE_GOAL.test(normalized) &&
|
|
1363
|
+
!this.modules.some((module) => module.goal === normalized)) {
|
|
1364
|
+
this.modules.push({ goal: normalized, label: "client-loaded" });
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
needsRecycle() {
|
|
1368
|
+
return this.prolog.needsRestart();
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Restart a lost interactive session. Returns true when a recycle ran. A
|
|
1372
|
+
* failed recycle leaves the process stopped so the next request retries.
|
|
1373
|
+
*/
|
|
1374
|
+
async ensureLive() {
|
|
1375
|
+
if (!this.prolog.needsRestart())
|
|
1376
|
+
return false;
|
|
1377
|
+
console.error("[KIBI] engine Prolog session was lost (output overflow, timeout, or crash); restarting and reattaching the branch store");
|
|
1378
|
+
try {
|
|
1379
|
+
await this.boot();
|
|
1380
|
+
}
|
|
1381
|
+
catch (error) {
|
|
1382
|
+
await this.prolog.terminate().catch(() => undefined);
|
|
1383
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1384
|
+
throw new Error(`Kibi engine failed to recycle its Prolog session: ${message}`);
|
|
1385
|
+
}
|
|
1386
|
+
return true;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1269
1389
|
// implements REQ-core-journaled-engine-lifecycle
|
|
1270
1390
|
export async function runEngineDaemon(options) {
|
|
1271
1391
|
if (!isValidBranchName(options.branch)) {
|
|
@@ -1273,42 +1393,67 @@ export async function runEngineDaemon(options) {
|
|
|
1273
1393
|
}
|
|
1274
1394
|
const branchPath = ensureBranchStoreManifest(options.workspaceRoot, options.branch);
|
|
1275
1395
|
await ensureJournaledBranchStoreAsync(branchPath);
|
|
1276
|
-
const prolog = new PrologProcess({
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
throw new Error(recovered.error ?? "Failed to attach branch KB");
|
|
1287
|
-
}
|
|
1288
|
-
const attachedIdentity = readEngineAttachmentIdentity(branchPath);
|
|
1289
|
-
const coreModuleDir = path.dirname(resolveKbPlPath());
|
|
1290
|
-
for (const [fileName, label] of [
|
|
1291
|
-
["status.pl", "status"],
|
|
1292
|
-
["discovery.pl", "discovery"],
|
|
1293
|
-
]) {
|
|
1294
|
-
const modulePath = path.join(coreModuleDir, fileName);
|
|
1295
|
-
const loaded = await prolog.query(`use_module('${quoteProlog(modulePath.replaceAll("\\", "/"))}')`);
|
|
1296
|
-
if (!loaded.success) {
|
|
1297
|
-
throw new Error(loaded.error ?? `Failed to load Kibi ${label} module`);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1396
|
+
const prolog = new PrologProcess({
|
|
1397
|
+
timeout: 120_000,
|
|
1398
|
+
oneShot: false,
|
|
1399
|
+
...(options.maxOutputBytes === undefined
|
|
1400
|
+
? {}
|
|
1401
|
+
: { maxOutputBytes: options.maxOutputBytes }),
|
|
1402
|
+
});
|
|
1403
|
+
const session = new EngineSession(prolog, branchPath);
|
|
1404
|
+
await session.boot();
|
|
1405
|
+
let attachedIdentity = readEngineAttachmentIdentity(branchPath);
|
|
1300
1406
|
mkdirSync(path.dirname(options.socketPath), { recursive: true, mode: 0o700 });
|
|
1301
1407
|
if (existsSync(options.socketPath)) {
|
|
1408
|
+
const isLivePeerSignal = (error) => {
|
|
1409
|
+
if (error && typeof error === "object") {
|
|
1410
|
+
const code = "code" in error ? String(error.code) : "";
|
|
1411
|
+
if (code === "EPIPE" || code === "ECONNRESET")
|
|
1412
|
+
return true;
|
|
1413
|
+
const errno = "errno" in error
|
|
1414
|
+
? Number(error.errno)
|
|
1415
|
+
: Number.NaN;
|
|
1416
|
+
// POSIX EPIPE
|
|
1417
|
+
if (errno === -32)
|
|
1418
|
+
return true;
|
|
1419
|
+
}
|
|
1420
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1421
|
+
return /\bEPIPE\b|\bECONNRESET\b|broken pipe/i.test(message);
|
|
1422
|
+
};
|
|
1302
1423
|
let live = false;
|
|
1303
1424
|
try {
|
|
1304
1425
|
const existing = await connectSocket(options.socketPath, 100);
|
|
1305
|
-
|
|
1426
|
+
// Keep a permanent error sink. Bun 1.4 can surface write EPIPE from
|
|
1427
|
+
// teardown into the caller promise on some CI runners, replacing the
|
|
1428
|
+
// intended live-listener error.
|
|
1429
|
+
existing.on("error", () => undefined);
|
|
1306
1430
|
live = true;
|
|
1431
|
+
try {
|
|
1432
|
+
existing.destroy();
|
|
1433
|
+
}
|
|
1434
|
+
catch {
|
|
1435
|
+
// Ignore destroy races; live detection already succeeded.
|
|
1436
|
+
}
|
|
1437
|
+
existing.unref?.();
|
|
1307
1438
|
}
|
|
1308
|
-
catch {
|
|
1309
|
-
//
|
|
1439
|
+
catch (error) {
|
|
1440
|
+
// Bun 1.4 can reject the probe with EPIPE/ECONNRESET against a live
|
|
1441
|
+
// unix listener instead of resolving connect.
|
|
1442
|
+
if (isLivePeerSignal(error)) {
|
|
1443
|
+
live = true;
|
|
1444
|
+
}
|
|
1445
|
+
// Otherwise a refused connection means a stale filesystem socket.
|
|
1310
1446
|
}
|
|
1311
1447
|
if (live) {
|
|
1448
|
+
try {
|
|
1449
|
+
await prolog.terminate();
|
|
1450
|
+
}
|
|
1451
|
+
catch (error) {
|
|
1452
|
+
// Best-effort cleanup; Bun may surface late EPIPE here too.
|
|
1453
|
+
if (!isLivePeerSignal(error)) {
|
|
1454
|
+
// Ignore non-EPIPE terminate failures.
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1312
1457
|
throw new Error(`A Kibi engine is already listening at ${options.socketPath}`);
|
|
1313
1458
|
}
|
|
1314
1459
|
try {
|
|
@@ -1326,7 +1471,6 @@ export async function runEngineDaemon(options) {
|
|
|
1326
1471
|
let idleCompactionQueued = false;
|
|
1327
1472
|
const queryCache = new Map();
|
|
1328
1473
|
let freshnessCache = null;
|
|
1329
|
-
const cancelledRequests = new Set();
|
|
1330
1474
|
const clients = new Set();
|
|
1331
1475
|
let shuttingDown = false;
|
|
1332
1476
|
const exactBranchStatus = (result) => {
|
|
@@ -1382,7 +1526,8 @@ export async function runEngineDaemon(options) {
|
|
|
1382
1526
|
idleCompactionQueued = true;
|
|
1383
1527
|
queue = queue
|
|
1384
1528
|
.then(async () => {
|
|
1385
|
-
|
|
1529
|
+
// A lost session is recycled by the next request, not by idle work.
|
|
1530
|
+
if (activeClients === 0 && !session.needsRecycle()) {
|
|
1386
1531
|
await prolog.query("kb_storage_compact_if_needed");
|
|
1387
1532
|
}
|
|
1388
1533
|
})
|
|
@@ -1398,7 +1543,7 @@ export async function runEngineDaemon(options) {
|
|
|
1398
1543
|
void shutdown();
|
|
1399
1544
|
}, engineIdleTimeoutMs());
|
|
1400
1545
|
};
|
|
1401
|
-
const handle = async (request) => {
|
|
1546
|
+
const handle = async (request, cancelledRequests) => {
|
|
1402
1547
|
if (request.protocolVersion !== ENGINE_PROTOCOL_VERSION) {
|
|
1403
1548
|
throw new Error(`Kibi engine protocol mismatch: client=${request.protocolVersion ?? "missing"}, server=${ENGINE_PROTOCOL_VERSION}`);
|
|
1404
1549
|
}
|
|
@@ -1412,6 +1557,13 @@ export async function runEngineDaemon(options) {
|
|
|
1412
1557
|
request.branch !== options.branch) {
|
|
1413
1558
|
throw new Error("Kibi engine workspace identity mismatch");
|
|
1414
1559
|
}
|
|
1560
|
+
if (!isEngineLifecycleRequest(request) && (await session.ensureLive())) {
|
|
1561
|
+
// A recycled session re-read the store; nothing cached from the lost
|
|
1562
|
+
// session may be served, and the attachment identity may have moved.
|
|
1563
|
+
queryCache.clear();
|
|
1564
|
+
freshnessCache = null;
|
|
1565
|
+
attachedIdentity = readEngineAttachmentIdentity(branchPath);
|
|
1566
|
+
}
|
|
1415
1567
|
switch (request.method) {
|
|
1416
1568
|
case "entities": {
|
|
1417
1569
|
const limit = request.limit ?? 100;
|
|
@@ -1621,6 +1773,7 @@ export async function runEngineDaemon(options) {
|
|
|
1621
1773
|
return cached;
|
|
1622
1774
|
}
|
|
1623
1775
|
const result = await prolog.query(request.goal);
|
|
1776
|
+
session.recordModuleLoad(request.goal, result);
|
|
1624
1777
|
if (result.success && mutatingEngineGoal(request.goal)) {
|
|
1625
1778
|
fsyncJournaledBranchStore(branchPath);
|
|
1626
1779
|
}
|
|
@@ -1661,6 +1814,13 @@ export async function runEngineDaemon(options) {
|
|
|
1661
1814
|
setImmediate(() => void shutdown());
|
|
1662
1815
|
return { stopped: true };
|
|
1663
1816
|
case "cancel":
|
|
1817
|
+
// Best-effort: marks the id so a *queued* request on this connection
|
|
1818
|
+
// is skipped before handle(). A request already inside
|
|
1819
|
+
// `await prolog.query(...)` cannot be interrupted without redesigning
|
|
1820
|
+
// SWI interactive cancellation; the client still rejects locally on
|
|
1821
|
+
// AbortSignal, but the daemon queue remains occupied until that Prolog
|
|
1822
|
+
// call returns. Cancel marks are per-connection. See
|
|
1823
|
+
// docs/mcp-reference.md ("Engine cancellation limits").
|
|
1664
1824
|
if (typeof request.cancelOf === "number") {
|
|
1665
1825
|
cancelledRequests.add(request.cancelOf);
|
|
1666
1826
|
}
|
|
@@ -1676,7 +1836,9 @@ export async function runEngineDaemon(options) {
|
|
|
1676
1836
|
if (idleTimer)
|
|
1677
1837
|
clearTimeout(idleTimer);
|
|
1678
1838
|
clearInterval(workspaceWatchdog);
|
|
1679
|
-
const saved =
|
|
1839
|
+
const saved = session.needsRecycle()
|
|
1840
|
+
? null
|
|
1841
|
+
: await prolog.query("kb_save").catch(() => null);
|
|
1680
1842
|
if (saved?.success) {
|
|
1681
1843
|
try {
|
|
1682
1844
|
fsyncJournaledBranchStore(branchPath);
|
|
@@ -1720,6 +1882,9 @@ export async function runEngineDaemon(options) {
|
|
|
1720
1882
|
server.on("connection", (socket) => {
|
|
1721
1883
|
clients.add(socket);
|
|
1722
1884
|
activeClients += 1;
|
|
1885
|
+
// Request ids are per-connection. Cancel marks must not be daemon-global
|
|
1886
|
+
// or Client B's id=1 is poisoned by Client A's cancelOf=1.
|
|
1887
|
+
const cancelledRequests = new Set();
|
|
1723
1888
|
let buffer = Buffer.alloc(0);
|
|
1724
1889
|
socket.on("data", (chunk) => {
|
|
1725
1890
|
try {
|
|
@@ -1742,7 +1907,7 @@ export async function runEngineDaemon(options) {
|
|
|
1742
1907
|
return;
|
|
1743
1908
|
}
|
|
1744
1909
|
try {
|
|
1745
|
-
const result = await handle(request);
|
|
1910
|
+
const result = await handle(request, cancelledRequests);
|
|
1746
1911
|
writeSocketFrame(socket, {
|
|
1747
1912
|
id: request.id,
|
|
1748
1913
|
ok: true,
|
|
@@ -1758,6 +1923,11 @@ export async function runEngineDaemon(options) {
|
|
|
1758
1923
|
serverPackageVersions: ENGINE_PACKAGE_VERSIONS,
|
|
1759
1924
|
});
|
|
1760
1925
|
}
|
|
1926
|
+
finally {
|
|
1927
|
+
// Drop stale cancel marks for in-flight goals that still ran
|
|
1928
|
+
// to completion after cancelOf (SWI cannot interrupt them).
|
|
1929
|
+
cancelledRequests.delete(request.id);
|
|
1930
|
+
}
|
|
1761
1931
|
})
|
|
1762
1932
|
.catch(() => undefined);
|
|
1763
1933
|
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Preferred project-local Kibi env file (harness-independent). */
|
|
2
|
+
export declare const KIBI_PROJECT_ENV_FILE = ".env.kibi";
|
|
3
|
+
/** Legacy generic dotenv still loaded for compatibility only. */
|
|
4
|
+
export declare const KIBI_LEGACY_ENV_FILE = ".env";
|
|
5
|
+
export type EnvValueSource = "process" | "project_env" | "user_env" | "legacy_env" | "missing";
|
|
6
|
+
export type BootstrapKibiEnvironmentResult = Readonly<{
|
|
7
|
+
workspaceRoot: string;
|
|
8
|
+
userEnvPath: string;
|
|
9
|
+
projectEnvPath: string;
|
|
10
|
+
legacyEnvPath: string;
|
|
11
|
+
/** Attribution for keys present after bootstrap (never includes secret values). */
|
|
12
|
+
sources: Readonly<Record<string, EnvValueSource>>;
|
|
13
|
+
keysLoadedFromUser: readonly string[];
|
|
14
|
+
keysLoadedFromProject: readonly string[];
|
|
15
|
+
keysLoadedFromLegacy: readonly string[];
|
|
16
|
+
}>;
|
|
17
|
+
export type BootstrapKibiEnvironmentOptions = Readonly<{
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
startDir?: string;
|
|
20
|
+
homedir?: string;
|
|
21
|
+
/** Override XDG config home (defaults to env.XDG_CONFIG_HOME). */
|
|
22
|
+
xdgConfigHome?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Keys that were non-empty on the real process before any Kibi file load.
|
|
25
|
+
* Callers normally omit this; the first default-env bootstrap remembers it.
|
|
26
|
+
*/
|
|
27
|
+
initialNonEmptyProcessKeys?: ReadonlySet<string>;
|
|
28
|
+
}>;
|
|
29
|
+
type EnvEntry = Readonly<{
|
|
30
|
+
key: string;
|
|
31
|
+
value: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Test-only: clear remembered process-key snapshot and last bootstrap result.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resetKibiEnvironmentBootstrapStateForTests(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Last bootstrap against the real `process.env`, if any.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getLastBootstrapResult(): BootstrapKibiEnvironmentResult | null;
|
|
41
|
+
/**
|
|
42
|
+
* Canonical workspace root for Kibi env files and KB attachment.
|
|
43
|
+
* Uses KIBI_WORKSPACE / KIBI_PROJECT_ROOT / KIBI_ROOT, then .kb / .git discovery.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveKibiWorkspaceRoot(startDir?: string, env?: NodeJS.ProcessEnv): string;
|
|
46
|
+
export declare function resolveEnvFilePath(envFileName: string, workspaceRoot: string): string;
|
|
47
|
+
/** User-wide Kibi env file: $XDG_CONFIG_HOME/kibi/env or ~/.config/kibi/env. */
|
|
48
|
+
export declare function resolveKibiUserEnvPath(options?: Readonly<{
|
|
49
|
+
homedir?: string;
|
|
50
|
+
xdgConfigHome?: string;
|
|
51
|
+
env?: NodeJS.ProcessEnv;
|
|
52
|
+
}>): string;
|
|
53
|
+
export declare function resolveKibiProjectEnvPath(workspaceRoot: string, env?: NodeJS.ProcessEnv): string;
|
|
54
|
+
export declare function parseEnvContent(content: string): EnvEntry[];
|
|
55
|
+
/**
|
|
56
|
+
* Load Kibi-owned env files into `process.env` (or an injectable env object).
|
|
57
|
+
* Blank values are treated as unset (never applied, never overwrite).
|
|
58
|
+
* Existing non-empty process keys are never overwritten. Project overrides user.
|
|
59
|
+
* Legacy `.env` only gap-fills and is attributed as `legacy_env`.
|
|
60
|
+
* Call only from CLI/MCP entrypoints — not on library import.
|
|
61
|
+
*/
|
|
62
|
+
export declare function bootstrapKibiEnvironment(options?: BootstrapKibiEnvironmentOptions): BootstrapKibiEnvironmentResult;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve a secret source label from an actual bootstrap result.
|
|
65
|
+
* Never reconstructs attribution by re-reading files alone.
|
|
66
|
+
*/
|
|
67
|
+
export declare function secretSourceFromBootstrap(key: string, bootstrap: BootstrapKibiEnvironmentResult, env?: NodeJS.ProcessEnv): EnvValueSource;
|
|
68
|
+
export type InspectSecretSourceOptions = BootstrapKibiEnvironmentOptions & Readonly<{
|
|
69
|
+
/** @deprecated Prefer bootstrap result sources; kept for targeted tests. */
|
|
70
|
+
initialProcessKeys?: ReadonlySet<string>;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Read-only secret attribution via a dry bootstrap on an env snapshot.
|
|
74
|
+
* Prefer `secretSourceFromBootstrap` with the real entrypoint bootstrap result.
|
|
75
|
+
* Never returns secret values.
|
|
76
|
+
*/
|
|
77
|
+
export declare function inspectSecretSource(key: string, options?: InspectSecretSourceOptions): EnvValueSource;
|
|
78
|
+
/**
|
|
79
|
+
* Whether a secret is available for provider use (non-empty after resolution).
|
|
80
|
+
* Blank values are unset.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isSecretAvailable(key: string, options?: InspectSecretSourceOptions): boolean;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/env/bootstrap.ts"],"names":[],"mappings":"AA4BA,mEAAmE;AAEnE,eAAO,MAAM,qBAAqB,cAAc,CAAC;AAEjD,iEAAiE;AAEjE,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAG3C,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,aAAa,GACb,UAAU,GACV,YAAY,GACZ,SAAS,CAAC;AAGd,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CAAC;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAClD,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC,CAAC;AAGH,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC;IACrD,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,0BAA0B,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAClD,CAAC,CAAC;AAEH,KAAK,QAAQ,GAAG,QAAQ,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAOzD;;GAEG;AAEH,wBAAgB,0CAA0C,IAAI,IAAI,CAGjE;AAED;;GAEG;AAEH,wBAAgB,sBAAsB,IAAI,8BAA8B,GAAG,IAAI,CAE9E;AA6BD;;;GAGG;AAEH,wBAAgB,wBAAwB,CACtC,QAAQ,GAAE,MAAsB,EAChC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,CAWR;AAGD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GACpB,MAAM,CAGR;AAED,gFAAgF;AAEhF,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB,CAAM,GACN,MAAM,CAOR;AAGD,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,EACrB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,CAIR;AAGD,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,CAmB3D;AAkDD;;;;;;GAMG;AAEH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,+BAAoC,GAC5C,8BAA8B,CAkGhC;AAED;;;GAGG;AAEH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,8BAA8B,EACzC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,cAAc,CAMhB;AAGD,MAAM,MAAM,0BAA0B,GAAG,+BAA+B,GACtE,QAAQ,CAAC;IACP,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC1C,CAAC,CAAC;AAEL;;;;GAIG;AAEH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,0BAA+B,GACvC,cAAc,CA+BhB;AAED;;;GAGG;AAEH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAET"}
|