limen-ai 1.0.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/CHANGELOG.md +47 -0
- package/LICENSE +190 -0
- package/README.md +546 -0
- package/dist/api/agents/agent_api.d.ts +126 -0
- package/dist/api/agents/agent_api.d.ts.map +1 -0
- package/dist/api/agents/agent_api.js +467 -0
- package/dist/api/agents/agent_api.js.map +1 -0
- package/dist/api/agents/trust_progression.d.ts +78 -0
- package/dist/api/agents/trust_progression.d.ts.map +1 -0
- package/dist/api/agents/trust_progression.js +124 -0
- package/dist/api/agents/trust_progression.js.map +1 -0
- package/dist/api/chat/chat_pipeline.d.ts +91 -0
- package/dist/api/chat/chat_pipeline.d.ts.map +1 -0
- package/dist/api/chat/chat_pipeline.js +630 -0
- package/dist/api/chat/chat_pipeline.js.map +1 -0
- package/dist/api/chat/technique_injector.d.ts +86 -0
- package/dist/api/chat/technique_injector.d.ts.map +1 -0
- package/dist/api/chat/technique_injector.js +125 -0
- package/dist/api/chat/technique_injector.js.map +1 -0
- package/dist/api/data/data_api.d.ts +91 -0
- package/dist/api/data/data_api.d.ts.map +1 -0
- package/dist/api/data/data_api.js +306 -0
- package/dist/api/data/data_api.js.map +1 -0
- package/dist/api/enforcement/cost_tracker.d.ts +105 -0
- package/dist/api/enforcement/cost_tracker.d.ts.map +1 -0
- package/dist/api/enforcement/cost_tracker.js +227 -0
- package/dist/api/enforcement/cost_tracker.js.map +1 -0
- package/dist/api/enforcement/latency_harness.d.ts +94 -0
- package/dist/api/enforcement/latency_harness.d.ts.map +1 -0
- package/dist/api/enforcement/latency_harness.js +120 -0
- package/dist/api/enforcement/latency_harness.js.map +1 -0
- package/dist/api/enforcement/rate_guard.d.ts +52 -0
- package/dist/api/enforcement/rate_guard.d.ts.map +1 -0
- package/dist/api/enforcement/rate_guard.js +79 -0
- package/dist/api/enforcement/rate_guard.js.map +1 -0
- package/dist/api/enforcement/rbac_guard.d.ts +55 -0
- package/dist/api/enforcement/rbac_guard.d.ts.map +1 -0
- package/dist/api/enforcement/rbac_guard.js +77 -0
- package/dist/api/enforcement/rbac_guard.js.map +1 -0
- package/dist/api/errors/limen_error.d.ts +81 -0
- package/dist/api/errors/limen_error.d.ts.map +1 -0
- package/dist/api/errors/limen_error.js +324 -0
- package/dist/api/errors/limen_error.js.map +1 -0
- package/dist/api/facades/claim_facade.d.ts +47 -0
- package/dist/api/facades/claim_facade.d.ts.map +1 -0
- package/dist/api/facades/claim_facade.js +67 -0
- package/dist/api/facades/claim_facade.js.map +1 -0
- package/dist/api/facades/working_memory_facade.d.ts +47 -0
- package/dist/api/facades/working_memory_facade.d.ts.map +1 -0
- package/dist/api/facades/working_memory_facade.js +74 -0
- package/dist/api/facades/working_memory_facade.js.map +1 -0
- package/dist/api/governance/governed_orchestration.d.ts +76 -0
- package/dist/api/governance/governed_orchestration.d.ts.map +1 -0
- package/dist/api/governance/governed_orchestration.js +413 -0
- package/dist/api/governance/governed_orchestration.js.map +1 -0
- package/dist/api/index.d.ts +84 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +847 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/infer/infer_pipeline.d.ts +51 -0
- package/dist/api/infer/infer_pipeline.d.ts.map +1 -0
- package/dist/api/infer/infer_pipeline.js +291 -0
- package/dist/api/infer/infer_pipeline.js.map +1 -0
- package/dist/api/interfaces/api.d.ts +940 -0
- package/dist/api/interfaces/api.d.ts.map +1 -0
- package/dist/api/interfaces/api.js +21 -0
- package/dist/api/interfaces/api.js.map +1 -0
- package/dist/api/knowledge/knowledge_api.d.ts +55 -0
- package/dist/api/knowledge/knowledge_api.d.ts.map +1 -0
- package/dist/api/knowledge/knowledge_api.js +89 -0
- package/dist/api/knowledge/knowledge_api.js.map +1 -0
- package/dist/api/migration/023_agent_persistence.d.ts +32 -0
- package/dist/api/migration/023_agent_persistence.d.ts.map +1 -0
- package/dist/api/migration/023_agent_persistence.js +158 -0
- package/dist/api/migration/023_agent_persistence.js.map +1 -0
- package/dist/api/migration/024_trust_learning.d.ts +36 -0
- package/dist/api/migration/024_trust_learning.d.ts.map +1 -0
- package/dist/api/migration/024_trust_learning.js +194 -0
- package/dist/api/migration/024_trust_learning.js.map +1 -0
- package/dist/api/migration/025_knowledge_graph.d.ts +29 -0
- package/dist/api/migration/025_knowledge_graph.d.ts.map +1 -0
- package/dist/api/migration/025_knowledge_graph.js +97 -0
- package/dist/api/migration/025_knowledge_graph.js.map +1 -0
- package/dist/api/migration/026_replay_pipeline.d.ts +30 -0
- package/dist/api/migration/026_replay_pipeline.d.ts.map +1 -0
- package/dist/api/migration/026_replay_pipeline.js +118 -0
- package/dist/api/migration/026_replay_pipeline.js.map +1 -0
- package/dist/api/missions/mission_api.d.ts +74 -0
- package/dist/api/missions/mission_api.d.ts.map +1 -0
- package/dist/api/missions/mission_api.js +408 -0
- package/dist/api/missions/mission_api.js.map +1 -0
- package/dist/api/observability/health.d.ts +36 -0
- package/dist/api/observability/health.d.ts.map +1 -0
- package/dist/api/observability/health.js +92 -0
- package/dist/api/observability/health.js.map +1 -0
- package/dist/api/observability/metrics.d.ts +95 -0
- package/dist/api/observability/metrics.d.ts.map +1 -0
- package/dist/api/observability/metrics.js +260 -0
- package/dist/api/observability/metrics.js.map +1 -0
- package/dist/api/roles/roles_api.d.ts +45 -0
- package/dist/api/roles/roles_api.d.ts.map +1 -0
- package/dist/api/roles/roles_api.js +77 -0
- package/dist/api/roles/roles_api.js.map +1 -0
- package/dist/api/sessions/session_manager.d.ts +110 -0
- package/dist/api/sessions/session_manager.d.ts.map +1 -0
- package/dist/api/sessions/session_manager.js +278 -0
- package/dist/api/sessions/session_manager.js.map +1 -0
- package/dist/budget/harness/dba_harness.d.ts +36 -0
- package/dist/budget/harness/dba_harness.d.ts.map +1 -0
- package/dist/budget/harness/dba_harness.js +58 -0
- package/dist/budget/harness/dba_harness.js.map +1 -0
- package/dist/budget/impl/dba_impl.d.ts +47 -0
- package/dist/budget/impl/dba_impl.d.ts.map +1 -0
- package/dist/budget/impl/dba_impl.js +402 -0
- package/dist/budget/impl/dba_impl.js.map +1 -0
- package/dist/budget/interfaces/dba_types.d.ts +708 -0
- package/dist/budget/interfaces/dba_types.d.ts.map +1 -0
- package/dist/budget/interfaces/dba_types.js +124 -0
- package/dist/budget/interfaces/dba_types.js.map +1 -0
- package/dist/claims/evidence/capability_scope_validator.d.ts +32 -0
- package/dist/claims/evidence/capability_scope_validator.d.ts.map +1 -0
- package/dist/claims/evidence/capability_scope_validator.js +72 -0
- package/dist/claims/evidence/capability_scope_validator.js.map +1 -0
- package/dist/claims/evidence/evidence_validator.d.ts +35 -0
- package/dist/claims/evidence/evidence_validator.d.ts.map +1 -0
- package/dist/claims/evidence/evidence_validator.js +118 -0
- package/dist/claims/evidence/evidence_validator.js.map +1 -0
- package/dist/claims/harness/claim_harness.d.ts +22 -0
- package/dist/claims/harness/claim_harness.d.ts.map +1 -0
- package/dist/claims/harness/claim_harness.js +26 -0
- package/dist/claims/harness/claim_harness.js.map +1 -0
- package/dist/claims/interfaces/claim_types.d.ts +858 -0
- package/dist/claims/interfaces/claim_types.d.ts.map +1 -0
- package/dist/claims/interfaces/claim_types.js +201 -0
- package/dist/claims/interfaces/claim_types.js.map +1 -0
- package/dist/claims/migration/019_ccp_claims.d.ts +23 -0
- package/dist/claims/migration/019_ccp_claims.d.ts.map +1 -0
- package/dist/claims/migration/019_ccp_claims.js +196 -0
- package/dist/claims/migration/019_ccp_claims.js.map +1 -0
- package/dist/claims/store/claim_stores.d.ts +27 -0
- package/dist/claims/store/claim_stores.d.ts.map +1 -0
- package/dist/claims/store/claim_stores.js +1352 -0
- package/dist/claims/store/claim_stores.js.map +1 -0
- package/dist/context/harness/cgp_harness.d.ts +32 -0
- package/dist/context/harness/cgp_harness.d.ts.map +1 -0
- package/dist/context/harness/cgp_harness.js +295 -0
- package/dist/context/harness/cgp_harness.js.map +1 -0
- package/dist/context/interfaces/cgp_types.d.ts +905 -0
- package/dist/context/interfaces/cgp_types.d.ts.map +1 -0
- package/dist/context/interfaces/cgp_types.js +112 -0
- package/dist/context/interfaces/cgp_types.js.map +1 -0
- package/dist/context/stores/cgp_stores.d.ts +42 -0
- package/dist/context/stores/cgp_stores.d.ts.map +1 -0
- package/dist/context/stores/cgp_stores.js +856 -0
- package/dist/context/stores/cgp_stores.js.map +1 -0
- package/dist/execution/harness/egp_harness.d.ts +43 -0
- package/dist/execution/harness/egp_harness.d.ts.map +1 -0
- package/dist/execution/harness/egp_harness.js +54 -0
- package/dist/execution/harness/egp_harness.js.map +1 -0
- package/dist/execution/interfaces/egp_types.d.ts +1042 -0
- package/dist/execution/interfaces/egp_types.d.ts.map +1 -0
- package/dist/execution/interfaces/egp_types.js +195 -0
- package/dist/execution/interfaces/egp_types.js.map +1 -0
- package/dist/execution/stores/egp_stores.d.ts +29 -0
- package/dist/execution/stores/egp_stores.d.ts.map +1 -0
- package/dist/execution/stores/egp_stores.js +1250 -0
- package/dist/execution/stores/egp_stores.js.map +1 -0
- package/dist/execution/wiring/execution_gate.d.ts +56 -0
- package/dist/execution/wiring/execution_gate.d.ts.map +1 -0
- package/dist/execution/wiring/execution_gate.js +77 -0
- package/dist/execution/wiring/execution_gate.js.map +1 -0
- package/dist/execution/wiring/floor_enforcer.d.ts +68 -0
- package/dist/execution/wiring/floor_enforcer.d.ts.map +1 -0
- package/dist/execution/wiring/floor_enforcer.js +96 -0
- package/dist/execution/wiring/floor_enforcer.js.map +1 -0
- package/dist/execution/wiring/invocation_gate.d.ts +58 -0
- package/dist/execution/wiring/invocation_gate.d.ts.map +1 -0
- package/dist/execution/wiring/invocation_gate.js +69 -0
- package/dist/execution/wiring/invocation_gate.js.map +1 -0
- package/dist/execution/wiring/terminal_release.d.ts +56 -0
- package/dist/execution/wiring/terminal_release.d.ts.map +1 -0
- package/dist/execution/wiring/terminal_release.js +85 -0
- package/dist/execution/wiring/terminal_release.js.map +1 -0
- package/dist/governance/harness/governance_harness.d.ts +54 -0
- package/dist/governance/harness/governance_harness.d.ts.map +1 -0
- package/dist/governance/harness/governance_harness.js +60 -0
- package/dist/governance/harness/governance_harness.js.map +1 -0
- package/dist/governance/migration/012_governance_runs_traces.d.ts +21 -0
- package/dist/governance/migration/012_governance_runs_traces.d.ts.map +1 -0
- package/dist/governance/migration/012_governance_runs_traces.js +115 -0
- package/dist/governance/migration/012_governance_runs_traces.js.map +1 -0
- package/dist/governance/migration/013_governance_contracts.d.ts +18 -0
- package/dist/governance/migration/013_governance_contracts.d.ts.map +1 -0
- package/dist/governance/migration/013_governance_contracts.js +59 -0
- package/dist/governance/migration/013_governance_contracts.js.map +1 -0
- package/dist/governance/migration/014_governance_supervisor.d.ts +16 -0
- package/dist/governance/migration/014_governance_supervisor.d.ts.map +1 -0
- package/dist/governance/migration/014_governance_supervisor.js +75 -0
- package/dist/governance/migration/014_governance_supervisor.js.map +1 -0
- package/dist/governance/migration/015_governance_eval.d.ts +18 -0
- package/dist/governance/migration/015_governance_eval.d.ts.map +1 -0
- package/dist/governance/migration/015_governance_eval.js +65 -0
- package/dist/governance/migration/015_governance_eval.js.map +1 -0
- package/dist/governance/migration/016_governance_capabilities.d.ts +16 -0
- package/dist/governance/migration/016_governance_capabilities.d.ts.map +1 -0
- package/dist/governance/migration/016_governance_capabilities.js +60 -0
- package/dist/governance/migration/016_governance_capabilities.js.map +1 -0
- package/dist/governance/migration/017_governance_handoffs_idempotency.d.ts +20 -0
- package/dist/governance/migration/017_governance_handoffs_idempotency.d.ts.map +1 -0
- package/dist/governance/migration/017_governance_handoffs_idempotency.js +103 -0
- package/dist/governance/migration/017_governance_handoffs_idempotency.js.map +1 -0
- package/dist/governance/migration/018_supervisor_decision_delete_trigger.d.ts +17 -0
- package/dist/governance/migration/018_supervisor_decision_delete_trigger.d.ts.map +1 -0
- package/dist/governance/migration/018_supervisor_decision_delete_trigger.js +37 -0
- package/dist/governance/migration/018_supervisor_decision_delete_trigger.js.map +1 -0
- package/dist/governance/stores/governance_stores.d.ts +78 -0
- package/dist/governance/stores/governance_stores.d.ts.map +1 -0
- package/dist/governance/stores/governance_stores.js +1117 -0
- package/dist/governance/stores/governance_stores.js.map +1 -0
- package/dist/kernel/audit/audit_trail.d.ts +24 -0
- package/dist/kernel/audit/audit_trail.d.ts.map +1 -0
- package/dist/kernel/audit/audit_trail.js +569 -0
- package/dist/kernel/audit/audit_trail.js.map +1 -0
- package/dist/kernel/crypto/crypto_engine.d.ts +49 -0
- package/dist/kernel/crypto/crypto_engine.d.ts.map +1 -0
- package/dist/kernel/crypto/crypto_engine.js +350 -0
- package/dist/kernel/crypto/crypto_engine.js.map +1 -0
- package/dist/kernel/database/database_lifecycle.d.ts +24 -0
- package/dist/kernel/database/database_lifecycle.d.ts.map +1 -0
- package/dist/kernel/database/database_lifecycle.js +404 -0
- package/dist/kernel/database/database_lifecycle.js.map +1 -0
- package/dist/kernel/database/migrations.d.ts +21 -0
- package/dist/kernel/database/migrations.d.ts.map +1 -0
- package/dist/kernel/database/migrations.js +407 -0
- package/dist/kernel/database/migrations.js.map +1 -0
- package/dist/kernel/events/event_bus.d.ts +25 -0
- package/dist/kernel/events/event_bus.d.ts.map +1 -0
- package/dist/kernel/events/event_bus.js +302 -0
- package/dist/kernel/events/event_bus.js.map +1 -0
- package/dist/kernel/events/webhook_delivery.d.ts +90 -0
- package/dist/kernel/events/webhook_delivery.d.ts.map +1 -0
- package/dist/kernel/events/webhook_delivery.js +324 -0
- package/dist/kernel/events/webhook_delivery.js.map +1 -0
- package/dist/kernel/index.d.ts +39 -0
- package/dist/kernel/index.d.ts.map +1 -0
- package/dist/kernel/index.js +263 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/kernel/interfaces/audit.d.ts +146 -0
- package/dist/kernel/interfaces/audit.d.ts.map +1 -0
- package/dist/kernel/interfaces/audit.js +15 -0
- package/dist/kernel/interfaces/audit.js.map +1 -0
- package/dist/kernel/interfaces/capability_manifest.d.ts +104 -0
- package/dist/kernel/interfaces/capability_manifest.d.ts.map +1 -0
- package/dist/kernel/interfaces/capability_manifest.js +44 -0
- package/dist/kernel/interfaces/capability_manifest.js.map +1 -0
- package/dist/kernel/interfaces/common.d.ts +91 -0
- package/dist/kernel/interfaces/common.d.ts.map +1 -0
- package/dist/kernel/interfaces/common.js +10 -0
- package/dist/kernel/interfaces/common.js.map +1 -0
- package/dist/kernel/interfaces/crypto.d.ts +95 -0
- package/dist/kernel/interfaces/crypto.d.ts.map +1 -0
- package/dist/kernel/interfaces/crypto.js +14 -0
- package/dist/kernel/interfaces/crypto.js.map +1 -0
- package/dist/kernel/interfaces/database.d.ts +157 -0
- package/dist/kernel/interfaces/database.d.ts.map +1 -0
- package/dist/kernel/interfaces/database.js +10 -0
- package/dist/kernel/interfaces/database.js.map +1 -0
- package/dist/kernel/interfaces/eval.d.ts +93 -0
- package/dist/kernel/interfaces/eval.d.ts.map +1 -0
- package/dist/kernel/interfaces/eval.js +17 -0
- package/dist/kernel/interfaces/eval.js.map +1 -0
- package/dist/kernel/interfaces/events.d.ts +73 -0
- package/dist/kernel/interfaces/events.d.ts.map +1 -0
- package/dist/kernel/interfaces/events.js +13 -0
- package/dist/kernel/interfaces/events.js.map +1 -0
- package/dist/kernel/interfaces/governance_ids.d.ts +93 -0
- package/dist/kernel/interfaces/governance_ids.d.ts.map +1 -0
- package/dist/kernel/interfaces/governance_ids.js +18 -0
- package/dist/kernel/interfaces/governance_ids.js.map +1 -0
- package/dist/kernel/interfaces/idempotency.d.ts +143 -0
- package/dist/kernel/interfaces/idempotency.d.ts.map +1 -0
- package/dist/kernel/interfaces/idempotency.js +22 -0
- package/dist/kernel/interfaces/idempotency.js.map +1 -0
- package/dist/kernel/interfaces/index.d.ts +29 -0
- package/dist/kernel/interfaces/index.d.ts.map +1 -0
- package/dist/kernel/interfaces/index.js +9 -0
- package/dist/kernel/interfaces/index.js.map +1 -0
- package/dist/kernel/interfaces/kernel.d.ts +79 -0
- package/dist/kernel/interfaces/kernel.d.ts.map +1 -0
- package/dist/kernel/interfaces/kernel.js +13 -0
- package/dist/kernel/interfaces/kernel.js.map +1 -0
- package/dist/kernel/interfaces/lifecycle.d.ts +115 -0
- package/dist/kernel/interfaces/lifecycle.d.ts.map +1 -0
- package/dist/kernel/interfaces/lifecycle.js +53 -0
- package/dist/kernel/interfaces/lifecycle.js.map +1 -0
- package/dist/kernel/interfaces/mission_contract.d.ts +106 -0
- package/dist/kernel/interfaces/mission_contract.d.ts.map +1 -0
- package/dist/kernel/interfaces/mission_contract.js +20 -0
- package/dist/kernel/interfaces/mission_contract.js.map +1 -0
- package/dist/kernel/interfaces/namespace.d.ts +30 -0
- package/dist/kernel/interfaces/namespace.d.ts.map +1 -0
- package/dist/kernel/interfaces/namespace.js +12 -0
- package/dist/kernel/interfaces/namespace.js.map +1 -0
- package/dist/kernel/interfaces/rate_limiter.d.ts +42 -0
- package/dist/kernel/interfaces/rate_limiter.d.ts.map +1 -0
- package/dist/kernel/interfaces/rate_limiter.js +12 -0
- package/dist/kernel/interfaces/rate_limiter.js.map +1 -0
- package/dist/kernel/interfaces/rbac.d.ts +58 -0
- package/dist/kernel/interfaces/rbac.d.ts.map +1 -0
- package/dist/kernel/interfaces/rbac.js +13 -0
- package/dist/kernel/interfaces/rbac.js.map +1 -0
- package/dist/kernel/interfaces/retention.d.ts +58 -0
- package/dist/kernel/interfaces/retention.d.ts.map +1 -0
- package/dist/kernel/interfaces/retention.js +13 -0
- package/dist/kernel/interfaces/retention.js.map +1 -0
- package/dist/kernel/interfaces/run_identity.d.ts +132 -0
- package/dist/kernel/interfaces/run_identity.d.ts.map +1 -0
- package/dist/kernel/interfaces/run_identity.js +16 -0
- package/dist/kernel/interfaces/run_identity.js.map +1 -0
- package/dist/kernel/interfaces/supervisor.d.ts +175 -0
- package/dist/kernel/interfaces/supervisor.d.ts.map +1 -0
- package/dist/kernel/interfaces/supervisor.js +25 -0
- package/dist/kernel/interfaces/supervisor.js.map +1 -0
- package/dist/kernel/interfaces/tenant.d.ts +34 -0
- package/dist/kernel/interfaces/tenant.d.ts.map +1 -0
- package/dist/kernel/interfaces/tenant.js +12 -0
- package/dist/kernel/interfaces/tenant.js.map +1 -0
- package/dist/kernel/interfaces/time.d.ts +29 -0
- package/dist/kernel/interfaces/time.d.ts.map +1 -0
- package/dist/kernel/interfaces/time.js +13 -0
- package/dist/kernel/interfaces/time.js.map +1 -0
- package/dist/kernel/interfaces/trace.d.ts +264 -0
- package/dist/kernel/interfaces/trace.d.ts.map +1 -0
- package/dist/kernel/interfaces/trace.js +17 -0
- package/dist/kernel/interfaces/trace.js.map +1 -0
- package/dist/kernel/namespace/namespace_enforcer.d.ts +20 -0
- package/dist/kernel/namespace/namespace_enforcer.d.ts.map +1 -0
- package/dist/kernel/namespace/namespace_enforcer.js +91 -0
- package/dist/kernel/namespace/namespace_enforcer.js.map +1 -0
- package/dist/kernel/rate_limiter/rate_limiter.d.ts +23 -0
- package/dist/kernel/rate_limiter/rate_limiter.d.ts.map +1 -0
- package/dist/kernel/rate_limiter/rate_limiter.js +146 -0
- package/dist/kernel/rate_limiter/rate_limiter.js.map +1 -0
- package/dist/kernel/rbac/rbac_engine.d.ts +20 -0
- package/dist/kernel/rbac/rbac_engine.d.ts.map +1 -0
- package/dist/kernel/rbac/rbac_engine.js +257 -0
- package/dist/kernel/rbac/rbac_engine.js.map +1 -0
- package/dist/kernel/retention/retention_scheduler.d.ts +41 -0
- package/dist/kernel/retention/retention_scheduler.d.ts.map +1 -0
- package/dist/kernel/retention/retention_scheduler.js +218 -0
- package/dist/kernel/retention/retention_scheduler.js.map +1 -0
- package/dist/kernel/tenant/tenant_context.d.ts +22 -0
- package/dist/kernel/tenant/tenant_context.d.ts.map +1 -0
- package/dist/kernel/tenant/tenant_context.js +107 -0
- package/dist/kernel/tenant/tenant_context.js.map +1 -0
- package/dist/kernel/tenant/tenant_scope.d.ts +81 -0
- package/dist/kernel/tenant/tenant_scope.d.ts.map +1 -0
- package/dist/kernel/tenant/tenant_scope.js +168 -0
- package/dist/kernel/tenant/tenant_scope.js.map +1 -0
- package/dist/kernel/time/time_provider.d.ts +39 -0
- package/dist/kernel/time/time_provider.d.ts.map +1 -0
- package/dist/kernel/time/time_provider.js +58 -0
- package/dist/kernel/time/time_provider.js.map +1 -0
- package/dist/learning/applicator/technique_applicator.d.ts +41 -0
- package/dist/learning/applicator/technique_applicator.d.ts.map +1 -0
- package/dist/learning/applicator/technique_applicator.js +200 -0
- package/dist/learning/applicator/technique_applicator.js.map +1 -0
- package/dist/learning/cold_start/cold_start_manager.d.ts +35 -0
- package/dist/learning/cold_start/cold_start_manager.d.ts.map +1 -0
- package/dist/learning/cold_start/cold_start_manager.js +146 -0
- package/dist/learning/cold_start/cold_start_manager.js.map +1 -0
- package/dist/learning/cycle/learning_cycle_orchestrator.d.ts +45 -0
- package/dist/learning/cycle/learning_cycle_orchestrator.d.ts.map +1 -0
- package/dist/learning/cycle/learning_cycle_orchestrator.js +165 -0
- package/dist/learning/cycle/learning_cycle_orchestrator.js.map +1 -0
- package/dist/learning/extractor/technique_extractor.d.ts +48 -0
- package/dist/learning/extractor/technique_extractor.d.ts.map +1 -0
- package/dist/learning/extractor/technique_extractor.js +357 -0
- package/dist/learning/extractor/technique_extractor.js.map +1 -0
- package/dist/learning/harness/learning_harness.d.ts +26 -0
- package/dist/learning/harness/learning_harness.d.ts.map +1 -0
- package/dist/learning/harness/learning_harness.js +58 -0
- package/dist/learning/harness/learning_harness.js.map +1 -0
- package/dist/learning/interfaces/index.d.ts +7 -0
- package/dist/learning/interfaces/index.d.ts.map +1 -0
- package/dist/learning/interfaces/index.js +10 -0
- package/dist/learning/interfaces/index.js.map +1 -0
- package/dist/learning/interfaces/learning_types.d.ts +398 -0
- package/dist/learning/interfaces/learning_types.d.ts.map +1 -0
- package/dist/learning/interfaces/learning_types.js +69 -0
- package/dist/learning/interfaces/learning_types.js.map +1 -0
- package/dist/learning/migration/007_learning_techniques.d.ts +23 -0
- package/dist/learning/migration/007_learning_techniques.d.ts.map +1 -0
- package/dist/learning/migration/007_learning_techniques.js +86 -0
- package/dist/learning/migration/007_learning_techniques.js.map +1 -0
- package/dist/learning/migration/008_learning_outcomes.d.ts +23 -0
- package/dist/learning/migration/008_learning_outcomes.d.ts.map +1 -0
- package/dist/learning/migration/008_learning_outcomes.js +79 -0
- package/dist/learning/migration/008_learning_outcomes.js.map +1 -0
- package/dist/learning/migration/009_learning_applications.d.ts +25 -0
- package/dist/learning/migration/009_learning_applications.d.ts.map +1 -0
- package/dist/learning/migration/009_learning_applications.js +82 -0
- package/dist/learning/migration/009_learning_applications.js.map +1 -0
- package/dist/learning/migration/010_learning_quarantine.d.ts +22 -0
- package/dist/learning/migration/010_learning_quarantine.d.ts.map +1 -0
- package/dist/learning/migration/010_learning_quarantine.js +78 -0
- package/dist/learning/migration/010_learning_quarantine.js.map +1 -0
- package/dist/learning/migration/011_learning_transfers.d.ts +22 -0
- package/dist/learning/migration/011_learning_transfers.d.ts.map +1 -0
- package/dist/learning/migration/011_learning_transfers.js +77 -0
- package/dist/learning/migration/011_learning_transfers.js.map +1 -0
- package/dist/learning/quarantine/quarantine_manager.d.ts +34 -0
- package/dist/learning/quarantine/quarantine_manager.d.ts.map +1 -0
- package/dist/learning/quarantine/quarantine_manager.js +200 -0
- package/dist/learning/quarantine/quarantine_manager.js.map +1 -0
- package/dist/learning/retirement/retirement_evaluator.d.ts +35 -0
- package/dist/learning/retirement/retirement_evaluator.d.ts.map +1 -0
- package/dist/learning/retirement/retirement_evaluator.js +131 -0
- package/dist/learning/retirement/retirement_evaluator.js.map +1 -0
- package/dist/learning/specialization/over_specialization_detector.d.ts +32 -0
- package/dist/learning/specialization/over_specialization_detector.d.ts.map +1 -0
- package/dist/learning/specialization/over_specialization_detector.js +105 -0
- package/dist/learning/specialization/over_specialization_detector.js.map +1 -0
- package/dist/learning/store/technique_store.d.ts +22 -0
- package/dist/learning/store/technique_store.d.ts.map +1 -0
- package/dist/learning/store/technique_store.js +369 -0
- package/dist/learning/store/technique_store.js.map +1 -0
- package/dist/learning/tracker/effectiveness_tracker.d.ts +26 -0
- package/dist/learning/tracker/effectiveness_tracker.d.ts.map +1 -0
- package/dist/learning/tracker/effectiveness_tracker.js +158 -0
- package/dist/learning/tracker/effectiveness_tracker.js.map +1 -0
- package/dist/learning/transfer/cross_agent_transfer.d.ts +35 -0
- package/dist/learning/transfer/cross_agent_transfer.d.ts.map +1 -0
- package/dist/learning/transfer/cross_agent_transfer.js +245 -0
- package/dist/learning/transfer/cross_agent_transfer.js.map +1 -0
- package/dist/orchestration/artifacts/artifact_store.d.ts +19 -0
- package/dist/orchestration/artifacts/artifact_store.d.ts.map +1 -0
- package/dist/orchestration/artifacts/artifact_store.js +213 -0
- package/dist/orchestration/artifacts/artifact_store.js.map +1 -0
- package/dist/orchestration/artifacts/cascade_walker.d.ts +39 -0
- package/dist/orchestration/artifacts/cascade_walker.d.ts.map +1 -0
- package/dist/orchestration/artifacts/cascade_walker.js +107 -0
- package/dist/orchestration/artifacts/cascade_walker.js.map +1 -0
- package/dist/orchestration/budget/budget_governance.d.ts +20 -0
- package/dist/orchestration/budget/budget_governance.d.ts.map +1 -0
- package/dist/orchestration/budget/budget_governance.js +182 -0
- package/dist/orchestration/budget/budget_governance.js.map +1 -0
- package/dist/orchestration/checkpoints/checkpoint_coordinator.d.ts +22 -0
- package/dist/orchestration/checkpoints/checkpoint_coordinator.d.ts.map +1 -0
- package/dist/orchestration/checkpoints/checkpoint_coordinator.js +252 -0
- package/dist/orchestration/checkpoints/checkpoint_coordinator.js.map +1 -0
- package/dist/orchestration/checkpoints/drift_engine.d.ts +52 -0
- package/dist/orchestration/checkpoints/drift_engine.d.ts.map +1 -0
- package/dist/orchestration/checkpoints/drift_engine.js +126 -0
- package/dist/orchestration/checkpoints/drift_engine.js.map +1 -0
- package/dist/orchestration/compaction/bounded_cognition.d.ts +22 -0
- package/dist/orchestration/compaction/bounded_cognition.d.ts.map +1 -0
- package/dist/orchestration/compaction/bounded_cognition.js +124 -0
- package/dist/orchestration/compaction/bounded_cognition.js.map +1 -0
- package/dist/orchestration/conversation/conversation_manager.d.ts +25 -0
- package/dist/orchestration/conversation/conversation_manager.d.ts.map +1 -0
- package/dist/orchestration/conversation/conversation_manager.js +260 -0
- package/dist/orchestration/conversation/conversation_manager.js.map +1 -0
- package/dist/orchestration/events/event_propagation.d.ts +20 -0
- package/dist/orchestration/events/event_propagation.d.ts.map +1 -0
- package/dist/orchestration/events/event_propagation.js +160 -0
- package/dist/orchestration/events/event_propagation.js.map +1 -0
- package/dist/orchestration/index.d.ts +28 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +147 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/interfaces/orchestration.d.ts +494 -0
- package/dist/orchestration/interfaces/orchestration.d.ts.map +1 -0
- package/dist/orchestration/interfaces/orchestration.js +64 -0
- package/dist/orchestration/interfaces/orchestration.js.map +1 -0
- package/dist/orchestration/migration/003_orchestration.d.ts +27 -0
- package/dist/orchestration/migration/003_orchestration.d.ts.map +1 -0
- package/dist/orchestration/migration/003_orchestration.js +336 -0
- package/dist/orchestration/migration/003_orchestration.js.map +1 -0
- package/dist/orchestration/migration/004_tenant_isolation.d.ts +22 -0
- package/dist/orchestration/migration/004_tenant_isolation.d.ts.map +1 -0
- package/dist/orchestration/migration/004_tenant_isolation.js +179 -0
- package/dist/orchestration/migration/004_tenant_isolation.js.map +1 -0
- package/dist/orchestration/migration/005_immutability_triggers.d.ts +30 -0
- package/dist/orchestration/migration/005_immutability_triggers.d.ts.map +1 -0
- package/dist/orchestration/migration/005_immutability_triggers.js +93 -0
- package/dist/orchestration/migration/005_immutability_triggers.js.map +1 -0
- package/dist/orchestration/migration/006_audit_tombstone.d.ts +26 -0
- package/dist/orchestration/migration/006_audit_tombstone.d.ts.map +1 -0
- package/dist/orchestration/migration/006_audit_tombstone.js +71 -0
- package/dist/orchestration/migration/006_audit_tombstone.js.map +1 -0
- package/dist/orchestration/missions/mission_recovery.d.ts +60 -0
- package/dist/orchestration/missions/mission_recovery.d.ts.map +1 -0
- package/dist/orchestration/missions/mission_recovery.js +251 -0
- package/dist/orchestration/missions/mission_recovery.js.map +1 -0
- package/dist/orchestration/missions/mission_store.d.ts +16 -0
- package/dist/orchestration/missions/mission_store.d.ts.map +1 -0
- package/dist/orchestration/missions/mission_store.js +280 -0
- package/dist/orchestration/missions/mission_store.js.map +1 -0
- package/dist/orchestration/syscalls/create_artifact.d.ts +13 -0
- package/dist/orchestration/syscalls/create_artifact.d.ts.map +1 -0
- package/dist/orchestration/syscalls/create_artifact.js +23 -0
- package/dist/orchestration/syscalls/create_artifact.js.map +1 -0
- package/dist/orchestration/syscalls/emit_event.d.ts +13 -0
- package/dist/orchestration/syscalls/emit_event.d.ts.map +1 -0
- package/dist/orchestration/syscalls/emit_event.js +13 -0
- package/dist/orchestration/syscalls/emit_event.js.map +1 -0
- package/dist/orchestration/syscalls/propose_mission.d.ts +14 -0
- package/dist/orchestration/syscalls/propose_mission.d.ts.map +1 -0
- package/dist/orchestration/syscalls/propose_mission.js +27 -0
- package/dist/orchestration/syscalls/propose_mission.js.map +1 -0
- package/dist/orchestration/syscalls/propose_task_execution.d.ts +13 -0
- package/dist/orchestration/syscalls/propose_task_execution.d.ts.map +1 -0
- package/dist/orchestration/syscalls/propose_task_execution.js +84 -0
- package/dist/orchestration/syscalls/propose_task_execution.js.map +1 -0
- package/dist/orchestration/syscalls/propose_task_graph.d.ts +13 -0
- package/dist/orchestration/syscalls/propose_task_graph.d.ts.map +1 -0
- package/dist/orchestration/syscalls/propose_task_graph.js +22 -0
- package/dist/orchestration/syscalls/propose_task_graph.js.map +1 -0
- package/dist/orchestration/syscalls/read_artifact.d.ts +14 -0
- package/dist/orchestration/syscalls/read_artifact.d.ts.map +1 -0
- package/dist/orchestration/syscalls/read_artifact.js +31 -0
- package/dist/orchestration/syscalls/read_artifact.js.map +1 -0
- package/dist/orchestration/syscalls/request_budget.d.ts +14 -0
- package/dist/orchestration/syscalls/request_budget.d.ts.map +1 -0
- package/dist/orchestration/syscalls/request_budget.js +46 -0
- package/dist/orchestration/syscalls/request_budget.js.map +1 -0
- package/dist/orchestration/syscalls/request_capability.d.ts +13 -0
- package/dist/orchestration/syscalls/request_capability.d.ts.map +1 -0
- package/dist/orchestration/syscalls/request_capability.js +136 -0
- package/dist/orchestration/syscalls/request_capability.js.map +1 -0
- package/dist/orchestration/syscalls/respond_checkpoint.d.ts +12 -0
- package/dist/orchestration/syscalls/respond_checkpoint.d.ts.map +1 -0
- package/dist/orchestration/syscalls/respond_checkpoint.js +12 -0
- package/dist/orchestration/syscalls/respond_checkpoint.js.map +1 -0
- package/dist/orchestration/syscalls/submit_result.d.ts +15 -0
- package/dist/orchestration/syscalls/submit_result.d.ts.map +1 -0
- package/dist/orchestration/syscalls/submit_result.js +97 -0
- package/dist/orchestration/syscalls/submit_result.js.map +1 -0
- package/dist/orchestration/tasks/task_graph.d.ts +26 -0
- package/dist/orchestration/tasks/task_graph.d.ts.map +1 -0
- package/dist/orchestration/tasks/task_graph.js +204 -0
- package/dist/orchestration/tasks/task_graph.js.map +1 -0
- package/dist/orchestration/tasks/task_store.d.ts +18 -0
- package/dist/orchestration/tasks/task_store.d.ts.map +1 -0
- package/dist/orchestration/tasks/task_store.js +99 -0
- package/dist/orchestration/tasks/task_store.js.map +1 -0
- package/dist/reference-agent/artifact_manager.d.ts +119 -0
- package/dist/reference-agent/artifact_manager.d.ts.map +1 -0
- package/dist/reference-agent/artifact_manager.js +149 -0
- package/dist/reference-agent/artifact_manager.js.map +1 -0
- package/dist/reference-agent/checkpoint_handler.d.ts +186 -0
- package/dist/reference-agent/checkpoint_handler.d.ts.map +1 -0
- package/dist/reference-agent/checkpoint_handler.js +423 -0
- package/dist/reference-agent/checkpoint_handler.js.map +1 -0
- package/dist/reference-agent/index.d.ts +43 -0
- package/dist/reference-agent/index.d.ts.map +1 -0
- package/dist/reference-agent/index.js +53 -0
- package/dist/reference-agent/index.js.map +1 -0
- package/dist/reference-agent/mission_planner.d.ts +163 -0
- package/dist/reference-agent/mission_planner.d.ts.map +1 -0
- package/dist/reference-agent/mission_planner.js +375 -0
- package/dist/reference-agent/mission_planner.js.map +1 -0
- package/dist/reference-agent/reference_agent.d.ts +130 -0
- package/dist/reference-agent/reference_agent.d.ts.map +1 -0
- package/dist/reference-agent/reference_agent.js +360 -0
- package/dist/reference-agent/reference_agent.js.map +1 -0
- package/dist/reference-agent/reference_agent.types.d.ts +199 -0
- package/dist/reference-agent/reference_agent.types.d.ts.map +1 -0
- package/dist/reference-agent/reference_agent.types.js +59 -0
- package/dist/reference-agent/reference_agent.types.js.map +1 -0
- package/dist/reference-agent/result_aggregator.d.ts +107 -0
- package/dist/reference-agent/result_aggregator.d.ts.map +1 -0
- package/dist/reference-agent/result_aggregator.js +219 -0
- package/dist/reference-agent/result_aggregator.js.map +1 -0
- package/dist/reference-agent/system_call_client.d.ts +106 -0
- package/dist/reference-agent/system_call_client.d.ts.map +1 -0
- package/dist/reference-agent/system_call_client.js +231 -0
- package/dist/reference-agent/system_call_client.js.map +1 -0
- package/dist/reference-agent/task_executor.d.ts +108 -0
- package/dist/reference-agent/task_executor.d.ts.map +1 -0
- package/dist/reference-agent/task_executor.js +249 -0
- package/dist/reference-agent/task_executor.js.map +1 -0
- package/dist/substrate/accounting/resource_accounting.d.ts +52 -0
- package/dist/substrate/accounting/resource_accounting.d.ts.map +1 -0
- package/dist/substrate/accounting/resource_accounting.js +200 -0
- package/dist/substrate/accounting/resource_accounting.js.map +1 -0
- package/dist/substrate/adapters/capability_registry.d.ts +28 -0
- package/dist/substrate/adapters/capability_registry.d.ts.map +1 -0
- package/dist/substrate/adapters/capability_registry.js +196 -0
- package/dist/substrate/adapters/capability_registry.js.map +1 -0
- package/dist/substrate/gateway/llm_gateway.d.ts +68 -0
- package/dist/substrate/gateway/llm_gateway.d.ts.map +1 -0
- package/dist/substrate/gateway/llm_gateway.js +442 -0
- package/dist/substrate/gateway/llm_gateway.js.map +1 -0
- package/dist/substrate/heartbeat/heartbeat_monitor.d.ts +40 -0
- package/dist/substrate/heartbeat/heartbeat_monitor.d.ts.map +1 -0
- package/dist/substrate/heartbeat/heartbeat_monitor.js +170 -0
- package/dist/substrate/heartbeat/heartbeat_monitor.js.map +1 -0
- package/dist/substrate/index.d.ts +59 -0
- package/dist/substrate/index.d.ts.map +1 -0
- package/dist/substrate/index.js +143 -0
- package/dist/substrate/index.js.map +1 -0
- package/dist/substrate/interfaces/substrate.d.ts +486 -0
- package/dist/substrate/interfaces/substrate.d.ts.map +1 -0
- package/dist/substrate/interfaces/substrate.js +14 -0
- package/dist/substrate/interfaces/substrate.js.map +1 -0
- package/dist/substrate/migration/002_substrate.d.ts +24 -0
- package/dist/substrate/migration/002_substrate.d.ts.map +1 -0
- package/dist/substrate/migration/002_substrate.js +188 -0
- package/dist/substrate/migration/002_substrate.js.map +1 -0
- package/dist/substrate/migration/022_transport_deliberation.d.ts +31 -0
- package/dist/substrate/migration/022_transport_deliberation.d.ts.map +1 -0
- package/dist/substrate/migration/022_transport_deliberation.js +77 -0
- package/dist/substrate/migration/022_transport_deliberation.js.map +1 -0
- package/dist/substrate/replay/replay_engine.d.ts +65 -0
- package/dist/substrate/replay/replay_engine.d.ts.map +1 -0
- package/dist/substrate/replay/replay_engine.js +316 -0
- package/dist/substrate/replay/replay_engine.js.map +1 -0
- package/dist/substrate/scheduler/task_scheduler.d.ts +38 -0
- package/dist/substrate/scheduler/task_scheduler.d.ts.map +1 -0
- package/dist/substrate/scheduler/task_scheduler.js +486 -0
- package/dist/substrate/scheduler/task_scheduler.js.map +1 -0
- package/dist/substrate/transport/adapters/anthropic_adapter.d.ts +57 -0
- package/dist/substrate/transport/adapters/anthropic_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/anthropic_adapter.js +455 -0
- package/dist/substrate/transport/adapters/anthropic_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/gemini_adapter.d.ts +86 -0
- package/dist/substrate/transport/adapters/gemini_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/gemini_adapter.js +456 -0
- package/dist/substrate/transport/adapters/gemini_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/groq_adapter.d.ts +50 -0
- package/dist/substrate/transport/adapters/groq_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/groq_adapter.js +179 -0
- package/dist/substrate/transport/adapters/groq_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/mistral_adapter.d.ts +50 -0
- package/dist/substrate/transport/adapters/mistral_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/mistral_adapter.js +179 -0
- package/dist/substrate/transport/adapters/mistral_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/ollama_adapter.d.ts +66 -0
- package/dist/substrate/transport/adapters/ollama_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/ollama_adapter.js +347 -0
- package/dist/substrate/transport/adapters/ollama_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/openai_adapter.d.ts +68 -0
- package/dist/substrate/transport/adapters/openai_adapter.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/openai_adapter.js +439 -0
- package/dist/substrate/transport/adapters/openai_adapter.js.map +1 -0
- package/dist/substrate/transport/adapters/openai_compat.d.ts +64 -0
- package/dist/substrate/transport/adapters/openai_compat.d.ts.map +1 -0
- package/dist/substrate/transport/adapters/openai_compat.js +326 -0
- package/dist/substrate/transport/adapters/openai_compat.js.map +1 -0
- package/dist/substrate/transport/index.d.ts +17 -0
- package/dist/substrate/transport/index.d.ts.map +1 -0
- package/dist/substrate/transport/index.js +25 -0
- package/dist/substrate/transport/index.js.map +1 -0
- package/dist/substrate/transport/stream_parser.d.ts +69 -0
- package/dist/substrate/transport/stream_parser.d.ts.map +1 -0
- package/dist/substrate/transport/stream_parser.js +280 -0
- package/dist/substrate/transport/stream_parser.js.map +1 -0
- package/dist/substrate/transport/transport_engine.d.ts +53 -0
- package/dist/substrate/transport/transport_engine.d.ts.map +1 -0
- package/dist/substrate/transport/transport_engine.js +444 -0
- package/dist/substrate/transport/transport_engine.js.map +1 -0
- package/dist/substrate/transport/transport_types.d.ts +207 -0
- package/dist/substrate/transport/transport_types.d.ts.map +1 -0
- package/dist/substrate/transport/transport_types.js +13 -0
- package/dist/substrate/transport/transport_types.js.map +1 -0
- package/dist/substrate/workers/worker_runtime.d.ts +40 -0
- package/dist/substrate/workers/worker_runtime.d.ts.map +1 -0
- package/dist/substrate/workers/worker_runtime.js +294 -0
- package/dist/substrate/workers/worker_runtime.js.map +1 -0
- package/dist/techniques/harness/tgp_harness.d.ts +39 -0
- package/dist/techniques/harness/tgp_harness.d.ts.map +1 -0
- package/dist/techniques/harness/tgp_harness.js +49 -0
- package/dist/techniques/harness/tgp_harness.js.map +1 -0
- package/dist/techniques/interfaces/tgp_types.d.ts +646 -0
- package/dist/techniques/interfaces/tgp_types.d.ts.map +1 -0
- package/dist/techniques/interfaces/tgp_types.js +160 -0
- package/dist/techniques/interfaces/tgp_types.js.map +1 -0
- package/dist/techniques/migration/020_tgp_governance.d.ts +36 -0
- package/dist/techniques/migration/020_tgp_governance.d.ts.map +1 -0
- package/dist/techniques/migration/020_tgp_governance.js +249 -0
- package/dist/techniques/migration/020_tgp_governance.js.map +1 -0
- package/dist/techniques/store/tgp_stores.d.ts +36 -0
- package/dist/techniques/store/tgp_stores.d.ts.map +1 -0
- package/dist/techniques/store/tgp_stores.js +854 -0
- package/dist/techniques/store/tgp_stores.js.map +1 -0
- package/dist/working-memory/harness/wmp_harness.d.ts +43 -0
- package/dist/working-memory/harness/wmp_harness.d.ts.map +1 -0
- package/dist/working-memory/harness/wmp_harness.js +81 -0
- package/dist/working-memory/harness/wmp_harness.js.map +1 -0
- package/dist/working-memory/interfaces/wmp_types.d.ts +635 -0
- package/dist/working-memory/interfaces/wmp_types.d.ts.map +1 -0
- package/dist/working-memory/interfaces/wmp_types.js +144 -0
- package/dist/working-memory/interfaces/wmp_types.js.map +1 -0
- package/dist/working-memory/migration/021_wmp.d.ts +21 -0
- package/dist/working-memory/migration/021_wmp.d.ts.map +1 -0
- package/dist/working-memory/migration/021_wmp.js +139 -0
- package/dist/working-memory/migration/021_wmp.js.map +1 -0
- package/dist/working-memory/stores/wmp_stores.d.ts +28 -0
- package/dist/working-memory/stores/wmp_stores.d.ts.map +1 -0
- package/dist/working-memory/stores/wmp_stores.js +754 -0
- package/dist/working-memory/stores/wmp_stores.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,1352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CCP (Claim Protocol) Store Implementations — SQLite-backed.
|
|
3
|
+
* Replaces NotImplementedError stubs in claim_harness.ts.
|
|
4
|
+
*
|
|
5
|
+
* Phase: 1 (CCP)
|
|
6
|
+
* Implements: ClaimStore, ClaimEvidenceStore, ClaimRelationshipStore,
|
|
7
|
+
* ClaimArtifactRefStore, AssertClaimHandler, RetractClaimHandler,
|
|
8
|
+
* RelateClaimsHandler, QueryClaimsHandler, GroundingValidator,
|
|
9
|
+
* ClaimLifecycleProjection.
|
|
10
|
+
*
|
|
11
|
+
* Pattern: Follows src/governance/stores/governance_stores.ts exactly.
|
|
12
|
+
*
|
|
13
|
+
* Truth model obligations:
|
|
14
|
+
* CCP-I1: Content immutability (trigger-enforced)
|
|
15
|
+
* CCP-I2: Forward-only lifecycle (trigger-enforced)
|
|
16
|
+
* CCP-I5: Evidence provenance chain
|
|
17
|
+
* CCP-I6: Relationship integrity (append-only, trigger-enforced)
|
|
18
|
+
* CCP-I9: Audit sufficiency (every mutation audited in same transaction)
|
|
19
|
+
* CCP-I10: Tombstone identity preservation
|
|
20
|
+
* CCP-I12: No kernel lifecycle consequence from relationships
|
|
21
|
+
* CCP-I13: Grounding cycle safety (visited-set traversal)
|
|
22
|
+
* CCP-I14: Retraction notification boundary (one-edge-deep)
|
|
23
|
+
* Binding 14: Trace event per lifecycle transition (same transaction)
|
|
24
|
+
*/
|
|
25
|
+
import { randomUUID, createHash } from 'node:crypto';
|
|
26
|
+
import { CCP_TRACE_EVENTS, CCP_EVENTS, CLAIM_GROUNDING_MAX_HOPS, CLAIM_PER_MISSION_LIMIT, CLAIM_PER_ARTIFACT_LIMIT, CLAIM_MAX_EVIDENCE_REFS, CLAIM_MAX_OUTGOING_RELATIONSHIPS, CLAIM_QUERY_MAX_LIMIT, CLAIM_QUERY_DEFAULT_LIMIT, CLAIM_JSON_MAX_BYTES, CLAIM_RATE_LIMIT, } from '../interfaces/claim_types.js';
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Helpers
|
|
29
|
+
// ============================================================================
|
|
30
|
+
function ok(value) {
|
|
31
|
+
return { ok: true, value };
|
|
32
|
+
}
|
|
33
|
+
function err(code, message, spec) {
|
|
34
|
+
return { ok: false, error: { code, message, spec } };
|
|
35
|
+
}
|
|
36
|
+
// nowISO() removed — Hard Stop #7: use deps.time.nowISO() instead
|
|
37
|
+
function newId() {
|
|
38
|
+
return randomUUID();
|
|
39
|
+
}
|
|
40
|
+
/** DC-CCP-307: Compute idempotency hash from claim input payload */
|
|
41
|
+
function computeIdempotencyHash(input) {
|
|
42
|
+
const payload = JSON.stringify({
|
|
43
|
+
subject: input.subject,
|
|
44
|
+
predicate: input.predicate,
|
|
45
|
+
object: input.object,
|
|
46
|
+
confidence: input.confidence,
|
|
47
|
+
validAt: input.validAt,
|
|
48
|
+
groundingMode: input.groundingMode,
|
|
49
|
+
evidenceRefs: input.evidenceRefs,
|
|
50
|
+
});
|
|
51
|
+
return createHash('sha256').update(payload).digest('hex');
|
|
52
|
+
}
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Validation Helpers
|
|
55
|
+
// ============================================================================
|
|
56
|
+
/** Strict 3-segment URN: lowercase-alpha-prefix : type : identifier */
|
|
57
|
+
function isValidSubjectURN(subject) {
|
|
58
|
+
if (!subject || typeof subject !== 'string')
|
|
59
|
+
return false;
|
|
60
|
+
const parts = subject.split(':');
|
|
61
|
+
if (parts.length !== 3)
|
|
62
|
+
return false;
|
|
63
|
+
const [seg0, seg1, seg2] = parts;
|
|
64
|
+
// First segment must be lowercase alpha (entity, metric, etc.)
|
|
65
|
+
if (!seg0 || !/^[a-z][a-z0-9_]*$/.test(seg0))
|
|
66
|
+
return false;
|
|
67
|
+
// Second and third segments must be non-empty
|
|
68
|
+
if (!seg1 || !seg2)
|
|
69
|
+
return false;
|
|
70
|
+
// No whitespace in any segment (CCP Design Source §6, BPB-002)
|
|
71
|
+
if (/\s/.test(seg1) || /\s/.test(seg2))
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/** Strict 2-segment predicate: domain.property */
|
|
76
|
+
function isValidPredicate(predicate) {
|
|
77
|
+
if (!predicate || typeof predicate !== 'string')
|
|
78
|
+
return false;
|
|
79
|
+
const parts = predicate.split('.');
|
|
80
|
+
if (parts.length !== 2)
|
|
81
|
+
return false;
|
|
82
|
+
if (!parts[0] || !parts[1])
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/** Check reserved predicate namespaces: system.*, lifecycle.* */
|
|
87
|
+
function isReservedPredicate(predicate) {
|
|
88
|
+
const domain = predicate.split('.')[0];
|
|
89
|
+
return domain === 'system' || domain === 'lifecycle';
|
|
90
|
+
}
|
|
91
|
+
/** Validate object value matches declared type */
|
|
92
|
+
function isValidObjectType(objectType, value) {
|
|
93
|
+
switch (objectType) {
|
|
94
|
+
case 'string':
|
|
95
|
+
return typeof value === 'string';
|
|
96
|
+
case 'number':
|
|
97
|
+
return typeof value === 'number' && !Number.isNaN(value) && Number.isFinite(value);
|
|
98
|
+
case 'boolean':
|
|
99
|
+
return typeof value === 'boolean';
|
|
100
|
+
case 'date':
|
|
101
|
+
return typeof value === 'string' && !Number.isNaN(Date.parse(value));
|
|
102
|
+
case 'json': {
|
|
103
|
+
if (value === null || value === undefined)
|
|
104
|
+
return false;
|
|
105
|
+
const serialized = JSON.stringify(value);
|
|
106
|
+
return Buffer.byteLength(serialized, 'utf8') <= CLAIM_JSON_MAX_BYTES;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Validate ISO 8601 date string */
|
|
113
|
+
function isValidISO8601(dateStr) {
|
|
114
|
+
if (!dateStr || typeof dateStr !== 'string')
|
|
115
|
+
return false;
|
|
116
|
+
const d = new Date(dateStr);
|
|
117
|
+
return !Number.isNaN(d.getTime());
|
|
118
|
+
}
|
|
119
|
+
/** Check authorization — agent must have create_mission permission (or be non-empty permissions set) */
|
|
120
|
+
function isAuthorized(ctx) {
|
|
121
|
+
return ctx.permissions.size > 0;
|
|
122
|
+
}
|
|
123
|
+
/** Check if subject filter is valid — exact or trailing wildcard */
|
|
124
|
+
function isValidSubjectFilter(subject) {
|
|
125
|
+
if (!subject || subject.length === 0)
|
|
126
|
+
return false;
|
|
127
|
+
// Reject wildcard in non-trailing position (AMB-14)
|
|
128
|
+
const wildcardIdx = subject.indexOf('*');
|
|
129
|
+
if (wildcardIdx >= 0 && wildcardIdx !== subject.length - 1)
|
|
130
|
+
return false;
|
|
131
|
+
// Trailing wildcard
|
|
132
|
+
if (subject.endsWith('*')) {
|
|
133
|
+
const prefix = subject.slice(0, -1);
|
|
134
|
+
// Must have at least one colon-separated segment before wildcard
|
|
135
|
+
if (!prefix || !prefix.includes(':'))
|
|
136
|
+
return false;
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
// Exact match — must be valid URN
|
|
140
|
+
return isValidSubjectURN(subject);
|
|
141
|
+
}
|
|
142
|
+
/** Check if predicate filter is valid — exact or trailing wildcard */
|
|
143
|
+
function isValidPredicateFilter(predicate) {
|
|
144
|
+
if (!predicate || predicate.length === 0)
|
|
145
|
+
return false;
|
|
146
|
+
if (predicate.endsWith('*')) {
|
|
147
|
+
const prefix = predicate.slice(0, -1);
|
|
148
|
+
if (!prefix || !prefix.includes('.'))
|
|
149
|
+
return false;
|
|
150
|
+
if (prefix.includes('*'))
|
|
151
|
+
return false;
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return isValidPredicate(predicate);
|
|
155
|
+
}
|
|
156
|
+
// Simple in-memory rate limiter per agent
|
|
157
|
+
const rateLimitCounters = new Map();
|
|
158
|
+
function checkRateLimit(agentId, time) {
|
|
159
|
+
if (!agentId)
|
|
160
|
+
return true;
|
|
161
|
+
const now = time.nowMs();
|
|
162
|
+
const key = agentId;
|
|
163
|
+
const entry = rateLimitCounters.get(key);
|
|
164
|
+
if (!entry || now - entry.windowStart > 60_000) {
|
|
165
|
+
rateLimitCounters.set(key, { count: 1, windowStart: now });
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
entry.count++;
|
|
169
|
+
if (entry.count > CLAIM_RATE_LIMIT) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
function resetRateLimits() {
|
|
175
|
+
rateLimitCounters.clear();
|
|
176
|
+
}
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// Row Mapping Helpers
|
|
179
|
+
// ============================================================================
|
|
180
|
+
function rowToClaim(row) {
|
|
181
|
+
// CCP-I10: tombstoned claims have NULL content fields — preserve as null
|
|
182
|
+
const isTombstoned = row['purged_at'] !== null && row['purged_at'] !== undefined;
|
|
183
|
+
return {
|
|
184
|
+
id: row['id'],
|
|
185
|
+
tenantId: (row['tenant_id'] ?? null),
|
|
186
|
+
subject: (isTombstoned ? null : row['subject']),
|
|
187
|
+
predicate: (isTombstoned ? null : row['predicate']),
|
|
188
|
+
// CCP-I10: tombstoned claims return null for content fields at runtime.
|
|
189
|
+
// The Claim interface declares this non-nullable, but the contract (test #54) requires null.
|
|
190
|
+
// Cast through unknown to satisfy tsc while preserving runtime behavior.
|
|
191
|
+
object: (isTombstoned ? null : (row['object_type'] != null ? {
|
|
192
|
+
type: row['object_type'],
|
|
193
|
+
value: row['object_value'] ? JSON.parse(row['object_value']) : null,
|
|
194
|
+
} : null)),
|
|
195
|
+
confidence: (isTombstoned ? null : row['confidence']),
|
|
196
|
+
validAt: (isTombstoned ? null : row['valid_at']),
|
|
197
|
+
sourceAgentId: (isTombstoned ? null : row['source_agent_id']),
|
|
198
|
+
sourceMissionId: (isTombstoned || row['source_mission_id'] == null ? null : row['source_mission_id']),
|
|
199
|
+
sourceTaskId: (isTombstoned || row['source_task_id'] == null ? null : row['source_task_id']),
|
|
200
|
+
groundingMode: row['grounding_mode'],
|
|
201
|
+
runtimeWitness: row['runtime_witness'] ? JSON.parse(row['runtime_witness']) : null,
|
|
202
|
+
status: row['status'],
|
|
203
|
+
archived: Boolean(row['archived']),
|
|
204
|
+
createdAt: row['created_at'],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function rowToEvidence(row) {
|
|
208
|
+
return {
|
|
209
|
+
claimId: row['claim_id'],
|
|
210
|
+
evidenceType: row['evidence_type'],
|
|
211
|
+
evidenceId: row['evidence_id'],
|
|
212
|
+
sourceState: row['source_state'],
|
|
213
|
+
createdAt: row['created_at'],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function rowToRelationship(row) {
|
|
217
|
+
return {
|
|
218
|
+
id: row['id'],
|
|
219
|
+
tenantId: (row['tenant_id'] ?? null),
|
|
220
|
+
fromClaimId: row['from_claim_id'],
|
|
221
|
+
toClaimId: row['to_claim_id'],
|
|
222
|
+
type: row['type'],
|
|
223
|
+
declaredByAgentId: row['declared_by_agent_id'],
|
|
224
|
+
missionId: row['mission_id'],
|
|
225
|
+
createdAt: row['created_at'],
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// ============================================================================
|
|
229
|
+
// ClaimStore Implementation
|
|
230
|
+
// ============================================================================
|
|
231
|
+
function createClaimStoreImpl(deps) {
|
|
232
|
+
return {
|
|
233
|
+
create(conn, ctx, input) {
|
|
234
|
+
const id = newId();
|
|
235
|
+
const now = deps.time.nowISO();
|
|
236
|
+
try {
|
|
237
|
+
conn.run(`INSERT INTO claim_assertions (id, tenant_id, subject, predicate, object_type, object_value, confidence, valid_at, source_agent_id, source_mission_id, source_task_id, grounding_mode, runtime_witness, status, archived, idempotency_key, idempotency_hash, created_at)
|
|
238
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', 0, ?, ?, ?)`, [
|
|
239
|
+
id, ctx.tenantId, input.subject, input.predicate,
|
|
240
|
+
input.object.type, JSON.stringify(input.object.value),
|
|
241
|
+
input.confidence, input.validAt,
|
|
242
|
+
ctx.agentId, input.missionId, input.taskId ?? null,
|
|
243
|
+
input.groundingMode,
|
|
244
|
+
input.runtimeWitness ? JSON.stringify(input.runtimeWitness) : null,
|
|
245
|
+
input.idempotencyKey?.key ?? null,
|
|
246
|
+
input.idempotencyKey?.key ? computeIdempotencyHash(input) : null,
|
|
247
|
+
now,
|
|
248
|
+
]);
|
|
249
|
+
const claim = {
|
|
250
|
+
id,
|
|
251
|
+
tenantId: ctx.tenantId,
|
|
252
|
+
subject: input.subject,
|
|
253
|
+
predicate: input.predicate,
|
|
254
|
+
object: input.object,
|
|
255
|
+
confidence: input.confidence,
|
|
256
|
+
validAt: input.validAt,
|
|
257
|
+
sourceAgentId: ctx.agentId,
|
|
258
|
+
sourceMissionId: input.missionId,
|
|
259
|
+
sourceTaskId: input.taskId ?? null,
|
|
260
|
+
groundingMode: input.groundingMode,
|
|
261
|
+
runtimeWitness: input.runtimeWitness ?? null,
|
|
262
|
+
status: 'active',
|
|
263
|
+
archived: false,
|
|
264
|
+
createdAt: now,
|
|
265
|
+
};
|
|
266
|
+
return ok(claim);
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
270
|
+
return err('CLAIM_CREATE_FAILED', msg, 'SC-11');
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
get(conn, claimId, tenantId) {
|
|
274
|
+
const sql = tenantId !== null
|
|
275
|
+
? 'SELECT * FROM claim_assertions WHERE id = ? AND tenant_id = ?'
|
|
276
|
+
: 'SELECT * FROM claim_assertions WHERE id = ?';
|
|
277
|
+
const params = tenantId !== null ? [claimId, tenantId] : [claimId];
|
|
278
|
+
const row = conn.get(sql, params);
|
|
279
|
+
if (!row)
|
|
280
|
+
return err('CLAIM_NOT_FOUND', `Claim ${claimId} not found`, 'SC-13');
|
|
281
|
+
return ok(rowToClaim(row));
|
|
282
|
+
},
|
|
283
|
+
retract(conn, ctx, claimId, _reason) {
|
|
284
|
+
try {
|
|
285
|
+
conn.run(`UPDATE claim_assertions SET status = 'retracted' WHERE id = ? AND tenant_id = ?`, [claimId, ctx.tenantId]);
|
|
286
|
+
return ok(undefined);
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
290
|
+
if (msg.includes('CCP-I2')) {
|
|
291
|
+
return err('CLAIM_ALREADY_RETRACTED', 'Claim already retracted', 'CCP-I2');
|
|
292
|
+
}
|
|
293
|
+
return err('RETRACT_FAILED', msg, 'SC-11');
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
archive(conn, claimId, tenantId) {
|
|
297
|
+
const sql = tenantId !== null
|
|
298
|
+
? 'UPDATE claim_assertions SET archived = 1 WHERE id = ? AND tenant_id = ?'
|
|
299
|
+
: 'UPDATE claim_assertions SET archived = 1 WHERE id = ?';
|
|
300
|
+
const params = tenantId !== null ? [claimId, tenantId] : [claimId];
|
|
301
|
+
conn.run(sql, params);
|
|
302
|
+
return ok(undefined);
|
|
303
|
+
},
|
|
304
|
+
tombstone(conn, claimId, tenantId, reason) {
|
|
305
|
+
const now = deps.time.nowISO();
|
|
306
|
+
const sql = tenantId !== null
|
|
307
|
+
? `UPDATE claim_assertions SET subject = NULL, predicate = NULL, object_type = NULL, object_value = NULL, confidence = NULL, valid_at = NULL, source_agent_id = NULL, source_mission_id = NULL, source_task_id = NULL, runtime_witness = NULL, purged_at = ?, purge_reason = ? WHERE id = ? AND tenant_id = ?`
|
|
308
|
+
: `UPDATE claim_assertions SET subject = NULL, predicate = NULL, object_type = NULL, object_value = NULL, confidence = NULL, valid_at = NULL, source_agent_id = NULL, source_mission_id = NULL, source_task_id = NULL, runtime_witness = NULL, purged_at = ?, purge_reason = ? WHERE id = ?`;
|
|
309
|
+
const params = tenantId !== null ? [now, reason, claimId, tenantId] : [now, reason, claimId];
|
|
310
|
+
conn.run(sql, params);
|
|
311
|
+
return ok(undefined);
|
|
312
|
+
},
|
|
313
|
+
query(conn, tenantId, filters) {
|
|
314
|
+
const conditions = [];
|
|
315
|
+
const params = [];
|
|
316
|
+
// Tenant isolation
|
|
317
|
+
if (tenantId !== null) {
|
|
318
|
+
conditions.push('c.tenant_id = ?');
|
|
319
|
+
params.push(tenantId);
|
|
320
|
+
}
|
|
321
|
+
// Exclude tombstoned claims from ALL queries
|
|
322
|
+
conditions.push('c.purged_at IS NULL');
|
|
323
|
+
// Subject filter
|
|
324
|
+
if (filters.subject !== undefined && filters.subject !== null) {
|
|
325
|
+
if (filters.subject.endsWith('*')) {
|
|
326
|
+
conditions.push('c.subject LIKE ?');
|
|
327
|
+
params.push(filters.subject.slice(0, -1) + '%');
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
conditions.push('c.subject = ?');
|
|
331
|
+
params.push(filters.subject);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// Predicate filter
|
|
335
|
+
if (filters.predicate !== undefined && filters.predicate !== null) {
|
|
336
|
+
if (filters.predicate.endsWith('*')) {
|
|
337
|
+
conditions.push('c.predicate LIKE ?');
|
|
338
|
+
params.push(filters.predicate.slice(0, -1) + '%');
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
conditions.push('c.predicate = ?');
|
|
342
|
+
params.push(filters.predicate);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Status filter — null means unfiltered, undefined defaults to 'active' (AMB-10, BPB-008)
|
|
346
|
+
const effectiveStatus = filters.status === undefined ? 'active' : filters.status;
|
|
347
|
+
if (effectiveStatus !== null) {
|
|
348
|
+
conditions.push('c.status = ?');
|
|
349
|
+
params.push(effectiveStatus);
|
|
350
|
+
}
|
|
351
|
+
// Confidence filter
|
|
352
|
+
if (filters.minConfidence !== undefined && filters.minConfidence !== null) {
|
|
353
|
+
conditions.push('c.confidence >= ?');
|
|
354
|
+
params.push(filters.minConfidence);
|
|
355
|
+
}
|
|
356
|
+
// Agent filter
|
|
357
|
+
if (filters.sourceAgentId !== undefined && filters.sourceAgentId !== null) {
|
|
358
|
+
conditions.push('c.source_agent_id = ?');
|
|
359
|
+
params.push(filters.sourceAgentId);
|
|
360
|
+
}
|
|
361
|
+
// Mission filter
|
|
362
|
+
if (filters.sourceMissionId !== undefined && filters.sourceMissionId !== null) {
|
|
363
|
+
conditions.push('c.source_mission_id = ?');
|
|
364
|
+
params.push(filters.sourceMissionId);
|
|
365
|
+
}
|
|
366
|
+
// Temporal range
|
|
367
|
+
if (filters.validAtFrom !== undefined && filters.validAtFrom !== null) {
|
|
368
|
+
conditions.push('c.valid_at >= ?');
|
|
369
|
+
params.push(filters.validAtFrom);
|
|
370
|
+
}
|
|
371
|
+
if (filters.validAtTo !== undefined && filters.validAtTo !== null) {
|
|
372
|
+
conditions.push('c.valid_at <= ?');
|
|
373
|
+
params.push(filters.validAtTo);
|
|
374
|
+
}
|
|
375
|
+
// Archive mode
|
|
376
|
+
const archiveMode = filters.archiveMode ?? 'exclude';
|
|
377
|
+
if (archiveMode === 'exclude') {
|
|
378
|
+
conditions.push('c.archived = 0');
|
|
379
|
+
}
|
|
380
|
+
else if (archiveMode === 'only') {
|
|
381
|
+
conditions.push('c.archived = 1');
|
|
382
|
+
}
|
|
383
|
+
// 'include' — no archive filter
|
|
384
|
+
// MissionId filter (for queries that use it)
|
|
385
|
+
if ('missionId' in filters && filters['missionId'] !== undefined) {
|
|
386
|
+
conditions.push('c.source_mission_id = ?');
|
|
387
|
+
params.push(filters['missionId']);
|
|
388
|
+
}
|
|
389
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
390
|
+
const limit = Math.min(filters.limit ?? CLAIM_QUERY_DEFAULT_LIMIT, CLAIM_QUERY_MAX_LIMIT);
|
|
391
|
+
const offset = filters.offset ?? 0;
|
|
392
|
+
// Count query
|
|
393
|
+
const countRow = conn.get(`SELECT COUNT(*) as total FROM claim_assertions c ${whereClause}`, params);
|
|
394
|
+
const total = countRow?.total ?? 0;
|
|
395
|
+
// Data query
|
|
396
|
+
const dataRows = conn.query(`SELECT c.* FROM claim_assertions c ${whereClause} ORDER BY c.created_at DESC LIMIT ? OFFSET ?`, [...params, limit, offset]);
|
|
397
|
+
const claims = dataRows.map(row => {
|
|
398
|
+
const claim = rowToClaim(row);
|
|
399
|
+
const claimIdVal = claim.id;
|
|
400
|
+
// Computed properties — check relationship graph
|
|
401
|
+
const supersededRow = conn.get(`SELECT COUNT(*) as cnt FROM claim_relationships WHERE to_claim_id = ? AND type = 'supersedes'`, [claimIdVal]);
|
|
402
|
+
const disputedRow = conn.get(`SELECT COUNT(*) as cnt FROM claim_relationships WHERE to_claim_id = ? AND type = 'contradicts'`, [claimIdVal]);
|
|
403
|
+
const item = {
|
|
404
|
+
claim,
|
|
405
|
+
superseded: (supersededRow?.cnt ?? 0) > 0,
|
|
406
|
+
disputed: (disputedRow?.cnt ?? 0) > 0,
|
|
407
|
+
};
|
|
408
|
+
// Include evidence if requested
|
|
409
|
+
if (filters.includeEvidence) {
|
|
410
|
+
const evidenceRows = conn.query('SELECT * FROM claim_evidence WHERE claim_id = ?', [claimIdVal]);
|
|
411
|
+
item.evidence = evidenceRows.map(rowToEvidence);
|
|
412
|
+
}
|
|
413
|
+
// Include relationships if requested
|
|
414
|
+
if (filters.includeRelationships) {
|
|
415
|
+
const relRows = conn.query('SELECT * FROM claim_relationships WHERE from_claim_id = ? OR to_claim_id = ?', [claimIdVal, claimIdVal]);
|
|
416
|
+
item.relationships = relRows.map(rowToRelationship);
|
|
417
|
+
}
|
|
418
|
+
return item;
|
|
419
|
+
});
|
|
420
|
+
return ok({
|
|
421
|
+
claims,
|
|
422
|
+
total,
|
|
423
|
+
hasMore: total > offset + limit,
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
getAsTombstone(conn, claimId, tenantId) {
|
|
427
|
+
const sql = tenantId !== null
|
|
428
|
+
? 'SELECT id, tenant_id, status, archived, purged_at, purge_reason FROM claim_assertions WHERE id = ? AND tenant_id = ? AND purged_at IS NOT NULL'
|
|
429
|
+
: 'SELECT id, tenant_id, status, archived, purged_at, purge_reason FROM claim_assertions WHERE id = ? AND purged_at IS NOT NULL';
|
|
430
|
+
const params = tenantId !== null ? [claimId, tenantId] : [claimId];
|
|
431
|
+
const row = conn.get(sql, params);
|
|
432
|
+
if (!row)
|
|
433
|
+
return ok(null);
|
|
434
|
+
return ok({
|
|
435
|
+
id: row['id'],
|
|
436
|
+
tenantId: (row['tenant_id'] ?? null),
|
|
437
|
+
status: row['status'],
|
|
438
|
+
archived: Boolean(row['archived']),
|
|
439
|
+
purgedAt: row['purged_at'],
|
|
440
|
+
purgeReason: row['purge_reason'],
|
|
441
|
+
});
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
// ============================================================================
|
|
446
|
+
// ClaimEvidenceStore Implementation
|
|
447
|
+
// ============================================================================
|
|
448
|
+
function createClaimEvidenceStoreImpl(deps) {
|
|
449
|
+
return {
|
|
450
|
+
createBatch(conn, claimId, evidenceRefs) {
|
|
451
|
+
for (const ref of evidenceRefs) {
|
|
452
|
+
const id = newId();
|
|
453
|
+
conn.run(`INSERT INTO claim_evidence (id, claim_id, evidence_type, evidence_id, source_state, created_at)
|
|
454
|
+
VALUES (?, ?, ?, ?, 'live', ?)`, [id, claimId, ref.type, ref.id, deps.time.nowISO()]);
|
|
455
|
+
}
|
|
456
|
+
return ok(undefined);
|
|
457
|
+
},
|
|
458
|
+
getByClaimId(conn, claimId) {
|
|
459
|
+
const rows = conn.query('SELECT * FROM claim_evidence WHERE claim_id = ?', [claimId]);
|
|
460
|
+
return ok(rows.map(rowToEvidence));
|
|
461
|
+
},
|
|
462
|
+
markSourceTombstoned(conn, evidenceType, evidenceId) {
|
|
463
|
+
const result = conn.run(`UPDATE claim_evidence SET source_state = 'tombstoned' WHERE evidence_type = ? AND evidence_id = ?`, [evidenceType, evidenceId]);
|
|
464
|
+
return ok(result.changes);
|
|
465
|
+
},
|
|
466
|
+
getBySourceId(conn, evidenceType, evidenceId) {
|
|
467
|
+
const rows = conn.query('SELECT * FROM claim_evidence WHERE evidence_type = ? AND evidence_id = ?', [evidenceType, evidenceId]);
|
|
468
|
+
return ok(rows.map(rowToEvidence));
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
// ============================================================================
|
|
473
|
+
// ClaimRelationshipStore Implementation
|
|
474
|
+
// ============================================================================
|
|
475
|
+
function createClaimRelationshipStoreImpl(deps) {
|
|
476
|
+
return {
|
|
477
|
+
create(conn, ctx, input) {
|
|
478
|
+
const id = newId();
|
|
479
|
+
const now = deps.time.nowISO();
|
|
480
|
+
conn.run(`INSERT INTO claim_relationships (id, tenant_id, from_claim_id, to_claim_id, type, declared_by_agent_id, mission_id, created_at)
|
|
481
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [id, ctx.tenantId, input.fromClaimId, input.toClaimId, input.type, ctx.agentId, input.missionId, now]);
|
|
482
|
+
return ok({
|
|
483
|
+
id,
|
|
484
|
+
tenantId: ctx.tenantId,
|
|
485
|
+
fromClaimId: input.fromClaimId,
|
|
486
|
+
toClaimId: input.toClaimId,
|
|
487
|
+
type: input.type,
|
|
488
|
+
declaredByAgentId: ctx.agentId,
|
|
489
|
+
missionId: input.missionId,
|
|
490
|
+
createdAt: now,
|
|
491
|
+
});
|
|
492
|
+
},
|
|
493
|
+
getByClaimId(conn, claimId, direction) {
|
|
494
|
+
const col = direction === 'from' ? 'from_claim_id' : 'to_claim_id';
|
|
495
|
+
const rows = conn.query(`SELECT * FROM claim_relationships WHERE ${col} = ?`, [claimId]);
|
|
496
|
+
return ok(rows.map(rowToRelationship));
|
|
497
|
+
},
|
|
498
|
+
getByType(conn, claimId, type, direction) {
|
|
499
|
+
const col = direction === 'from' ? 'from_claim_id' : 'to_claim_id';
|
|
500
|
+
const rows = conn.query(`SELECT * FROM claim_relationships WHERE ${col} = ? AND type = ?`, [claimId, type]);
|
|
501
|
+
return ok(rows.map(rowToRelationship));
|
|
502
|
+
},
|
|
503
|
+
countOutgoing(conn, claimId) {
|
|
504
|
+
const row = conn.get('SELECT COUNT(*) as cnt FROM claim_relationships WHERE from_claim_id = ?', [claimId]);
|
|
505
|
+
return ok(row?.cnt ?? 0);
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
// ============================================================================
|
|
510
|
+
// ClaimArtifactRefStore Implementation
|
|
511
|
+
// ============================================================================
|
|
512
|
+
function createClaimArtifactRefStoreImpl(deps) {
|
|
513
|
+
return {
|
|
514
|
+
createBatch(conn, artifactId, claimIds) {
|
|
515
|
+
const now = deps.time.nowISO();
|
|
516
|
+
for (const claimId of claimIds) {
|
|
517
|
+
conn.run(`INSERT OR IGNORE INTO claim_artifact_refs (artifact_id, claim_id, created_at) VALUES (?, ?, ?)`, [artifactId, claimId, now]);
|
|
518
|
+
}
|
|
519
|
+
return ok(undefined);
|
|
520
|
+
},
|
|
521
|
+
getByArtifactId(conn, artifactId) {
|
|
522
|
+
const rows = conn.query('SELECT claim_id FROM claim_artifact_refs WHERE artifact_id = ?', [artifactId]);
|
|
523
|
+
return ok(rows.map(r => r.claim_id));
|
|
524
|
+
},
|
|
525
|
+
getByClaimId(conn, claimId) {
|
|
526
|
+
const rows = conn.query('SELECT artifact_id FROM claim_artifact_refs WHERE claim_id = ?', [claimId]);
|
|
527
|
+
return ok(rows.map(r => r.artifact_id));
|
|
528
|
+
},
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
// ============================================================================
|
|
532
|
+
// GroundingValidator Implementation — CF-05, CCP-I13, DC-CCP-117
|
|
533
|
+
// ============================================================================
|
|
534
|
+
function createGroundingValidatorImpl(_deps, stores) {
|
|
535
|
+
function traverseEvidencePath(conn, evidenceRefs, maxHops, checkRetracted, visited = new Set(), depth = 0) {
|
|
536
|
+
// For each evidence ref, check if any leads to a non-claim anchor within maxHops
|
|
537
|
+
for (const ref of evidenceRefs) {
|
|
538
|
+
if (ref.type !== 'claim') {
|
|
539
|
+
// Non-claim evidence = terminal anchor. Grounding succeeds.
|
|
540
|
+
const steps = [{
|
|
541
|
+
claimId: '', // placeholder — filled by caller
|
|
542
|
+
evidenceType: ref.type,
|
|
543
|
+
evidenceId: ref.id,
|
|
544
|
+
}];
|
|
545
|
+
return {
|
|
546
|
+
grounded: true,
|
|
547
|
+
mode: 'evidence_path',
|
|
548
|
+
traversalPath: {
|
|
549
|
+
hops: depth + 1,
|
|
550
|
+
maxHops,
|
|
551
|
+
steps,
|
|
552
|
+
anchor: { type: ref.type, id: ref.id },
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
// Claim evidence — need to traverse deeper
|
|
557
|
+
// At max depth with a claim ref: no more hops available to reach an anchor.
|
|
558
|
+
if (depth + 1 >= maxHops) {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (visited.has(ref.id))
|
|
562
|
+
continue; // Cycle detection
|
|
563
|
+
visited.add(ref.id);
|
|
564
|
+
// Retrieve the referenced claim
|
|
565
|
+
const targetClaim = stores.store.get(conn, ref.id, null);
|
|
566
|
+
if (!targetClaim.ok)
|
|
567
|
+
continue;
|
|
568
|
+
if (checkRetracted && targetClaim.value.status === 'retracted') {
|
|
569
|
+
return {
|
|
570
|
+
grounded: false,
|
|
571
|
+
mode: 'evidence_path',
|
|
572
|
+
failureReason: `Evidence chain traverses retracted intermediate claim ${ref.id}`,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
// Get evidence of the referenced claim and recurse
|
|
576
|
+
const subEvidence = stores.evidence.getByClaimId(conn, ref.id);
|
|
577
|
+
if (!subEvidence.ok)
|
|
578
|
+
continue;
|
|
579
|
+
const subRefs = subEvidence.value.map(e => ({
|
|
580
|
+
type: e.evidenceType,
|
|
581
|
+
id: e.evidenceId,
|
|
582
|
+
}));
|
|
583
|
+
const subResult = traverseEvidencePath(conn, subRefs, maxHops, checkRetracted, visited, depth + 1);
|
|
584
|
+
if (subResult.grounded) {
|
|
585
|
+
// Update hops to account for this level
|
|
586
|
+
const result = {
|
|
587
|
+
grounded: true,
|
|
588
|
+
mode: 'evidence_path',
|
|
589
|
+
};
|
|
590
|
+
if (subResult.traversalPath) {
|
|
591
|
+
result.traversalPath = {
|
|
592
|
+
...subResult.traversalPath,
|
|
593
|
+
hops: depth + 1 + (subResult.traversalPath.hops - depth - 1),
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
return result;
|
|
597
|
+
}
|
|
598
|
+
// If sub-result has retraction contamination, propagate it
|
|
599
|
+
if (subResult.failureReason?.includes('retracted')) {
|
|
600
|
+
return subResult;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
// No path found to non-claim anchor
|
|
604
|
+
return {
|
|
605
|
+
grounded: false,
|
|
606
|
+
mode: 'evidence_path',
|
|
607
|
+
failureReason: 'No evidence path terminates at non-claim anchor within max hops',
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
return Object.freeze({
|
|
611
|
+
validate(conn, _claimId, evidenceRefs, mode, maxHops, runtimeWitness) {
|
|
612
|
+
if (mode === 'runtime_witness') {
|
|
613
|
+
const result = { grounded: true, mode: 'runtime_witness' };
|
|
614
|
+
if (runtimeWitness) {
|
|
615
|
+
result.witnessBinding = runtimeWitness;
|
|
616
|
+
}
|
|
617
|
+
return ok(result);
|
|
618
|
+
}
|
|
619
|
+
// evidence_path mode
|
|
620
|
+
const result = traverseEvidencePath(conn, evidenceRefs, maxHops, false);
|
|
621
|
+
return ok(result);
|
|
622
|
+
},
|
|
623
|
+
validateWithRetractedCheck(conn, _claimId, evidenceRefs, mode, maxHops, runtimeWitness) {
|
|
624
|
+
if (mode === 'runtime_witness') {
|
|
625
|
+
const result = { grounded: true, mode: 'runtime_witness' };
|
|
626
|
+
if (runtimeWitness) {
|
|
627
|
+
result.witnessBinding = runtimeWitness;
|
|
628
|
+
}
|
|
629
|
+
return ok(result);
|
|
630
|
+
}
|
|
631
|
+
// evidence_path with retraction check
|
|
632
|
+
const result = traverseEvidencePath(conn, evidenceRefs, maxHops, true);
|
|
633
|
+
return ok(result);
|
|
634
|
+
},
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
// ============================================================================
|
|
638
|
+
// ClaimLifecycleProjection Implementation — Binding 3, DC-CCP-205
|
|
639
|
+
// ============================================================================
|
|
640
|
+
function createClaimLifecycleProjectionImpl() {
|
|
641
|
+
return Object.freeze({
|
|
642
|
+
project(status, grounded, hasContradicts, hasSupersedes) {
|
|
643
|
+
// Ordering by severity: retracted > superseded > disputed > grounded > asserted
|
|
644
|
+
if (status === 'retracted')
|
|
645
|
+
return 'retracted';
|
|
646
|
+
if (hasSupersedes)
|
|
647
|
+
return 'superseded';
|
|
648
|
+
if (hasContradicts)
|
|
649
|
+
return 'disputed';
|
|
650
|
+
if (grounded)
|
|
651
|
+
return 'grounded';
|
|
652
|
+
return 'asserted';
|
|
653
|
+
},
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
// ============================================================================
|
|
657
|
+
// AssertClaimHandler Implementation — SC-11
|
|
658
|
+
// ============================================================================
|
|
659
|
+
function createAssertClaimHandlerImpl(deps, stores) {
|
|
660
|
+
return Object.freeze({
|
|
661
|
+
execute(conn, ctx, input) {
|
|
662
|
+
// F-S1-005: TOCTOU invariant — evidence validation (steps 10, 10b) and claim
|
|
663
|
+
// INSERT (step 15) execute within the SAME transaction boundary. SQLite with
|
|
664
|
+
// better-sqlite3 uses synchronous, serialized writes. This transaction ensures
|
|
665
|
+
// no evidence can be deleted/modified between validation and claim creation.
|
|
666
|
+
return conn.transaction(() => {
|
|
667
|
+
// Generate a CorrelationId for this operation
|
|
668
|
+
const correlationId = newId();
|
|
669
|
+
// 0. Authorization
|
|
670
|
+
if (!isAuthorized(ctx)) {
|
|
671
|
+
return err('UNAUTHORIZED', 'Agent not authorized to assert claims', 'SC-11');
|
|
672
|
+
}
|
|
673
|
+
// 0a. Rate limit
|
|
674
|
+
if (!checkRateLimit(ctx.agentId, deps.time)) {
|
|
675
|
+
return err('RATE_LIMITED', 'Rate limit exceeded', 'SC-11');
|
|
676
|
+
}
|
|
677
|
+
// 0b. Idempotency key check (DC-CCP-307)
|
|
678
|
+
if (input.idempotencyKey?.key) {
|
|
679
|
+
const existing = conn.get('SELECT id, idempotency_hash FROM claim_assertions WHERE idempotency_key = ?', [input.idempotencyKey.key]);
|
|
680
|
+
if (existing) {
|
|
681
|
+
// Key exists — check if payload matches (hash comparison)
|
|
682
|
+
const inputHash = computeIdempotencyHash(input);
|
|
683
|
+
if (existing['idempotency_hash'] !== inputHash) {
|
|
684
|
+
return err('IDEMPOTENT_DUPLICATE', 'Idempotency key already used with different payload', 'DC-CCP-307');
|
|
685
|
+
}
|
|
686
|
+
// Same key, same payload → return cached claim
|
|
687
|
+
const cachedClaim = stores.store.get(conn, existing['id'], ctx.tenantId);
|
|
688
|
+
if (cachedClaim.ok) {
|
|
689
|
+
const cachedEvidence = stores.evidence.getByClaimId(conn, cachedClaim.value.id);
|
|
690
|
+
return ok({
|
|
691
|
+
claim: cachedClaim.value,
|
|
692
|
+
grounding: { grounded: true, mode: cachedClaim.value.groundingMode },
|
|
693
|
+
evidenceRecords: cachedEvidence.ok ? cachedEvidence.value : [],
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
// 1. Validate grounding mode
|
|
699
|
+
if (!input.groundingMode) {
|
|
700
|
+
return err('GROUNDING_MODE_MISSING', 'groundingMode field is required', 'CF-05');
|
|
701
|
+
}
|
|
702
|
+
// 2. Validate subject URN
|
|
703
|
+
if (!input.subject || !isValidSubjectURN(input.subject)) {
|
|
704
|
+
return err('INVALID_SUBJECT', `Invalid subject URN: ${input.subject}`, 'SC-11');
|
|
705
|
+
}
|
|
706
|
+
// 3. Validate predicate
|
|
707
|
+
if (!input.predicate || !isValidPredicate(input.predicate)) {
|
|
708
|
+
return err('INVALID_PREDICATE', `Invalid predicate format: ${input.predicate}`, 'SC-11');
|
|
709
|
+
}
|
|
710
|
+
if (isReservedPredicate(input.predicate)) {
|
|
711
|
+
return err('INVALID_PREDICATE', `Reserved predicate namespace: ${input.predicate}`, 'SC-11');
|
|
712
|
+
}
|
|
713
|
+
// 4. Validate object type
|
|
714
|
+
if (!isValidObjectType(input.object.type, input.object.value)) {
|
|
715
|
+
return err('INVALID_OBJECT_TYPE', `Object value does not match declared type ${input.object.type}`, 'SC-11');
|
|
716
|
+
}
|
|
717
|
+
// 5. Validate confidence
|
|
718
|
+
if (typeof input.confidence !== 'number' || input.confidence < 0 || input.confidence > 1) {
|
|
719
|
+
return err('CONFIDENCE_OUT_OF_RANGE', 'Confidence must be in [0.0, 1.0]', 'SC-11');
|
|
720
|
+
}
|
|
721
|
+
// 6. Validate validAt
|
|
722
|
+
if (!isValidISO8601(input.validAt)) {
|
|
723
|
+
return err('INVALID_VALID_AT', 'validAt must be valid ISO 8601', 'SC-11');
|
|
724
|
+
}
|
|
725
|
+
// 7. Runtime witness validation
|
|
726
|
+
if (input.groundingMode === 'runtime_witness') {
|
|
727
|
+
if (!input.runtimeWitness) {
|
|
728
|
+
return err('RUNTIME_WITNESS_MISSING', 'runtimeWitness required for runtime_witness mode', 'CF-05');
|
|
729
|
+
}
|
|
730
|
+
if (!input.runtimeWitness.witnessType || !isValidISO8601(input.runtimeWitness.witnessTimestamp)) {
|
|
731
|
+
return err('RUNTIME_WITNESS_INVALID', 'runtimeWitness structure is invalid', 'CF-05');
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
// 8. Evidence validation (evidence_path requires ≥1, runtime_witness allows 0)
|
|
735
|
+
if (input.groundingMode === 'evidence_path' && input.evidenceRefs.length === 0) {
|
|
736
|
+
return err('NO_EVIDENCE', 'Evidence-path mode requires at least one evidence reference', 'CCP-I5');
|
|
737
|
+
}
|
|
738
|
+
// 9. Evidence count limit
|
|
739
|
+
if (input.evidenceRefs.length > CLAIM_MAX_EVIDENCE_REFS) {
|
|
740
|
+
return err('EVIDENCE_LIMIT_EXCEEDED', `Evidence references exceed limit of ${CLAIM_MAX_EVIDENCE_REFS}`, 'SC-11');
|
|
741
|
+
}
|
|
742
|
+
// 10. Evidence FK validation
|
|
743
|
+
// Claim-type evidence: validated via DB (ClaimStore owns claim existence).
|
|
744
|
+
// External types: validated via injected EvidenceSourceValidator.
|
|
745
|
+
// DC-CCP-023: type mismatch detected by cross-checking alternative sources.
|
|
746
|
+
for (const ref of input.evidenceRefs) {
|
|
747
|
+
if (ref.type === 'claim') {
|
|
748
|
+
// Self-referential: check claim_assertions directly
|
|
749
|
+
const claimRef = conn.get('SELECT id, tenant_id FROM claim_assertions WHERE id = ?', [ref.id]);
|
|
750
|
+
if (!claimRef) {
|
|
751
|
+
// Check if this ID exists under a non-claim type (type mismatch)
|
|
752
|
+
const nonClaimTypes = ['memory', 'artifact', 'capability_result'];
|
|
753
|
+
let typeMismatch = false;
|
|
754
|
+
for (const altType of nonClaimTypes) {
|
|
755
|
+
const altResult = deps.evidenceValidator.exists(conn, altType, ref.id, ctx.tenantId, input.taskId);
|
|
756
|
+
if (altResult.ok) {
|
|
757
|
+
typeMismatch = true;
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (typeMismatch) {
|
|
762
|
+
return err('EVIDENCE_TYPE_MISMATCH', `Evidence id ${ref.id} exists but not as type 'claim'`, 'DC-CCP-023');
|
|
763
|
+
}
|
|
764
|
+
return err('EVIDENCE_NOT_FOUND', `Claim evidence ${ref.id} not found`, 'I-30');
|
|
765
|
+
}
|
|
766
|
+
// Cross-tenant check for claim evidence
|
|
767
|
+
if (ctx.tenantId !== null && claimRef['tenant_id'] !== null && claimRef['tenant_id'] !== ctx.tenantId) {
|
|
768
|
+
return err('EVIDENCE_CROSS_TENANT', `Claim evidence ${ref.id} belongs to different tenant`, 'CCP-LI-06');
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
// External evidence: use injected validator
|
|
773
|
+
// Sprint 1: Pass taskId for memory evidence scoping (CCP-01)
|
|
774
|
+
const validResult = deps.evidenceValidator.exists(conn, ref.type, ref.id, ctx.tenantId, input.taskId);
|
|
775
|
+
if (!validResult.ok) {
|
|
776
|
+
// Check if it exists under a different type (type mismatch)
|
|
777
|
+
if (validResult.error.code === 'EVIDENCE_NOT_FOUND') {
|
|
778
|
+
const allTypes = ['memory', 'artifact', 'capability_result', 'claim'];
|
|
779
|
+
const otherTypes = allTypes.filter(t => t !== ref.type);
|
|
780
|
+
for (const altType of otherTypes) {
|
|
781
|
+
if (altType === 'claim') {
|
|
782
|
+
// Check DB for claim
|
|
783
|
+
const claimCheck = conn.get('SELECT id FROM claim_assertions WHERE id = ?', [ref.id]);
|
|
784
|
+
if (claimCheck) {
|
|
785
|
+
return err('EVIDENCE_TYPE_MISMATCH', `Evidence id ${ref.id} exists as claim not ${ref.type}`, 'DC-CCP-023');
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
const altResult = deps.evidenceValidator.exists(conn, altType, ref.id, ctx.tenantId, input.taskId);
|
|
790
|
+
if (altResult.ok) {
|
|
791
|
+
return err('EVIDENCE_TYPE_MISMATCH', `Evidence id ${ref.id} exists as ${altType} not ${ref.type}`, 'DC-CCP-023');
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return err(validResult.error.code, validResult.error.message, validResult.error.spec);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
// 10b. Capability result scope validation (DC-CCP-118)
|
|
801
|
+
if (deps.capabilityResultScopeValidator) {
|
|
802
|
+
for (const ref of input.evidenceRefs) {
|
|
803
|
+
if (ref.type === 'capability_result') {
|
|
804
|
+
const scopeResult = deps.capabilityResultScopeValidator.validateScope(conn, ref.id, input.missionId, ctx.tenantId);
|
|
805
|
+
if (!scopeResult.ok) {
|
|
806
|
+
return err(scopeResult.error.code, scopeResult.error.message, scopeResult.error.spec);
|
|
807
|
+
}
|
|
808
|
+
if (!scopeResult.value) {
|
|
809
|
+
return err('EVIDENCE_SCOPE_VIOLATION', `capability_result ${ref.id} is outside mission ancestor chain`, 'DC-CCP-118');
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
// 11. Mission state validation
|
|
815
|
+
// If mission exists in DB with a terminal state, reject.
|
|
816
|
+
// If mission doesn't exist in DB, allow (may be managed externally).
|
|
817
|
+
if (input.missionId) {
|
|
818
|
+
// F-007: Include tenant_id in mission state query to prevent cross-tenant information leak.
|
|
819
|
+
// Matches SC-12 (line 1305) and SC-13 (line 1462) which both scope by tenant_id.
|
|
820
|
+
const missionRow = conn.get('SELECT state FROM core_missions WHERE id = ? AND tenant_id = ?', [input.missionId, ctx.tenantId]);
|
|
821
|
+
if (missionRow) {
|
|
822
|
+
const state = missionRow['state'];
|
|
823
|
+
if (state === 'COMPLETED' || state === 'FAILED' || state === 'REVOKED') {
|
|
824
|
+
return err('MISSION_NOT_ACTIVE', 'Mission is not in active state', 'SC-11');
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
// 12. Per-mission claim limit
|
|
829
|
+
const countRow = conn.get('SELECT COUNT(*) as cnt FROM claim_assertions WHERE tenant_id = ? AND source_mission_id = ?', [ctx.tenantId, input.missionId]);
|
|
830
|
+
if ((countRow?.cnt ?? 0) >= CLAIM_PER_MISSION_LIMIT) {
|
|
831
|
+
return err('CLAIM_LIMIT_EXCEEDED', `Per-mission claim limit (${CLAIM_PER_MISSION_LIMIT}) exceeded`, 'SC-11');
|
|
832
|
+
}
|
|
833
|
+
// 12b. Per-artifact claim limit (SC-4 amendment)
|
|
834
|
+
const artifactRefs = input.evidenceRefs.filter(r => r.type === 'artifact');
|
|
835
|
+
for (const artRef of artifactRefs) {
|
|
836
|
+
const artCount = conn.get('SELECT COUNT(*) as cnt FROM claim_artifact_refs WHERE artifact_id = ?', [artRef.id]);
|
|
837
|
+
if ((artCount?.cnt ?? 0) >= CLAIM_PER_ARTIFACT_LIMIT) {
|
|
838
|
+
return err('ARTIFACT_CLAIM_LIMIT', `Per-artifact claim limit (${CLAIM_PER_ARTIFACT_LIMIT}) exceeded`, 'SC-4');
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
// 13. Grounding validation
|
|
842
|
+
let groundingResult;
|
|
843
|
+
if (input.groundingMode === 'evidence_path') {
|
|
844
|
+
const gResult = stores.grounding.validateWithRetractedCheck(conn, '', input.evidenceRefs, input.groundingMode, CLAIM_GROUNDING_MAX_HOPS);
|
|
845
|
+
if (!gResult.ok)
|
|
846
|
+
return gResult;
|
|
847
|
+
groundingResult = gResult.value;
|
|
848
|
+
if (!groundingResult.grounded) {
|
|
849
|
+
// DC-SC11-111, F-004/F-010: Distinguish retraction-contaminated grounding from generic depth exceeded.
|
|
850
|
+
// If failureReason indicates a retracted intermediate claim, return GROUNDING_RETRACTED_INTERMEDIATE.
|
|
851
|
+
const isRetractionContaminated = groundingResult.failureReason?.includes('retracted') ?? false;
|
|
852
|
+
const errorCode = isRetractionContaminated ? 'GROUNDING_RETRACTED_INTERMEDIATE' : 'GROUNDING_DEPTH_EXCEEDED';
|
|
853
|
+
return err(errorCode, groundingResult.failureReason ?? 'Grounding failed', 'CF-05');
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
const rw = { grounded: true, mode: 'runtime_witness' };
|
|
858
|
+
if (input.runtimeWitness) {
|
|
859
|
+
rw.witnessBinding = input.runtimeWitness;
|
|
860
|
+
}
|
|
861
|
+
groundingResult = rw;
|
|
862
|
+
}
|
|
863
|
+
// 14. WMP pre-emission capture (optional)
|
|
864
|
+
let wmpCaptureId;
|
|
865
|
+
let wmpSourcingStatus;
|
|
866
|
+
if (deps.wmpCapture && input.taskId) {
|
|
867
|
+
const captureResult = deps.wmpCapture.capture(conn, input.taskId);
|
|
868
|
+
if (!captureResult.ok)
|
|
869
|
+
return captureResult;
|
|
870
|
+
wmpCaptureId = captureResult.value.captureId;
|
|
871
|
+
wmpSourcingStatus = captureResult.value.sourcingStatus;
|
|
872
|
+
}
|
|
873
|
+
// 15. Create claim
|
|
874
|
+
const createResult = stores.store.create(conn, ctx, input);
|
|
875
|
+
if (!createResult.ok)
|
|
876
|
+
return createResult;
|
|
877
|
+
const claim = createResult.value;
|
|
878
|
+
// 16. Create evidence rows
|
|
879
|
+
if (input.evidenceRefs.length > 0) {
|
|
880
|
+
const evResult = stores.evidence.createBatch(conn, claim.id, input.evidenceRefs);
|
|
881
|
+
if (!evResult.ok)
|
|
882
|
+
return evResult;
|
|
883
|
+
}
|
|
884
|
+
// 17. Create artifact junction rows for artifact evidence
|
|
885
|
+
for (const ref of input.evidenceRefs) {
|
|
886
|
+
if (ref.type === 'artifact') {
|
|
887
|
+
stores.artifactRefs.createBatch(conn, ref.id, [claim.id]);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
// 18. Audit entry (I-03: same transaction)
|
|
891
|
+
deps.audit.append(conn, {
|
|
892
|
+
tenantId: ctx.tenantId,
|
|
893
|
+
actorType: ctx.agentId ? 'agent' : 'system',
|
|
894
|
+
actorId: ctx.agentId ?? 'system',
|
|
895
|
+
operation: 'claim_asserted',
|
|
896
|
+
resourceType: 'claim',
|
|
897
|
+
resourceId: claim.id,
|
|
898
|
+
detail: {
|
|
899
|
+
groundingMode: input.groundingMode,
|
|
900
|
+
evidenceCount: input.evidenceRefs.length,
|
|
901
|
+
confidence: input.confidence,
|
|
902
|
+
traversalPath: groundingResult.traversalPath,
|
|
903
|
+
...(wmpCaptureId ? { preEmissionWmpCaptureId: wmpCaptureId, wmpSourcingStatus } : {}),
|
|
904
|
+
},
|
|
905
|
+
});
|
|
906
|
+
// 19. Domain event emission (EventBus)
|
|
907
|
+
deps.eventBus.emit(conn, ctx, {
|
|
908
|
+
type: CCP_EVENTS.CLAIM_ASSERTED.type,
|
|
909
|
+
scope: CCP_EVENTS.CLAIM_ASSERTED.scope,
|
|
910
|
+
propagation: CCP_EVENTS.CLAIM_ASSERTED.propagation,
|
|
911
|
+
missionId: input.missionId,
|
|
912
|
+
payload: {
|
|
913
|
+
claimId: claim.id,
|
|
914
|
+
subject: claim.subject,
|
|
915
|
+
predicate: claim.predicate,
|
|
916
|
+
groundingMode: claim.groundingMode,
|
|
917
|
+
confidence: claim.confidence,
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
// 20. Trace emission (Binding 14: same transaction)
|
|
921
|
+
if (deps.traceEmitter) {
|
|
922
|
+
// claim.asserted trace
|
|
923
|
+
deps.traceEmitter.emit(conn, ctx, {
|
|
924
|
+
runId: 'run-ccp',
|
|
925
|
+
correlationId,
|
|
926
|
+
type: CCP_TRACE_EVENTS.CLAIM_ASSERTED,
|
|
927
|
+
payload: {
|
|
928
|
+
type: CCP_TRACE_EVENTS.CLAIM_ASSERTED,
|
|
929
|
+
claimId: claim.id,
|
|
930
|
+
agentId: ctx.agentId,
|
|
931
|
+
},
|
|
932
|
+
});
|
|
933
|
+
// claim.grounded trace (only on grounding success)
|
|
934
|
+
if (groundingResult.grounded) {
|
|
935
|
+
deps.traceEmitter.emit(conn, ctx, {
|
|
936
|
+
runId: 'run-ccp',
|
|
937
|
+
correlationId,
|
|
938
|
+
type: CCP_TRACE_EVENTS.CLAIM_GROUNDED,
|
|
939
|
+
payload: {
|
|
940
|
+
type: CCP_TRACE_EVENTS.CLAIM_GROUNDED,
|
|
941
|
+
claimId: claim.id,
|
|
942
|
+
evidenceCount: input.evidenceRefs.length,
|
|
943
|
+
},
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return ok({
|
|
948
|
+
claim,
|
|
949
|
+
grounding: groundingResult,
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
},
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
// ============================================================================
|
|
956
|
+
// RetractClaimHandler Implementation — §14.4
|
|
957
|
+
// ============================================================================
|
|
958
|
+
function createRetractClaimHandlerImpl(deps, stores) {
|
|
959
|
+
return Object.freeze({
|
|
960
|
+
execute(conn, ctx, input) {
|
|
961
|
+
return conn.transaction(() => {
|
|
962
|
+
const correlationId = newId();
|
|
963
|
+
// 0. Authorization
|
|
964
|
+
if (!isAuthorized(ctx)) {
|
|
965
|
+
return err('UNAUTHORIZED', 'Agent not authorized to retract claims', 'SC-11');
|
|
966
|
+
}
|
|
967
|
+
// 1. Validate reason
|
|
968
|
+
if (!input.reason || input.reason.trim().length === 0) {
|
|
969
|
+
return err('INVALID_REASON', 'Retraction reason is required', '§10.4');
|
|
970
|
+
}
|
|
971
|
+
// 2. Get claim (tenant-scoped)
|
|
972
|
+
const getResult = stores.store.get(conn, input.claimId, ctx.tenantId);
|
|
973
|
+
if (!getResult.ok) {
|
|
974
|
+
return err('CLAIM_NOT_FOUND', `Claim ${input.claimId} not found`, '§10.4');
|
|
975
|
+
}
|
|
976
|
+
const claim = getResult.value;
|
|
977
|
+
// 3. Authorization: source agent or admin
|
|
978
|
+
if (claim.sourceAgentId !== ctx.agentId) {
|
|
979
|
+
const hasAdmin = ctx.permissions.has('manage_roles') || ctx.permissions.has('purge_data');
|
|
980
|
+
if (!hasAdmin) {
|
|
981
|
+
return err('UNAUTHORIZED', 'Only source agent or admin can retract', '§10.4');
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
// 4. Check if already retracted
|
|
985
|
+
if (claim.status === 'retracted') {
|
|
986
|
+
return err('CLAIM_ALREADY_RETRACTED', 'Claim is already retracted', 'CCP-I2');
|
|
987
|
+
}
|
|
988
|
+
// 5. Retract (trigger enforces forward-only)
|
|
989
|
+
const retractResult = stores.store.retract(conn, ctx, input.claimId, input.reason);
|
|
990
|
+
if (!retractResult.ok)
|
|
991
|
+
return retractResult;
|
|
992
|
+
// 6. Audit (I-03)
|
|
993
|
+
deps.audit.append(conn, {
|
|
994
|
+
tenantId: ctx.tenantId,
|
|
995
|
+
actorType: ctx.agentId ? 'agent' : 'system',
|
|
996
|
+
actorId: ctx.agentId ?? 'system',
|
|
997
|
+
operation: 'claim_retracted',
|
|
998
|
+
resourceType: 'claim',
|
|
999
|
+
resourceId: input.claimId,
|
|
1000
|
+
detail: {
|
|
1001
|
+
claimId: input.claimId,
|
|
1002
|
+
oldStatus: 'active',
|
|
1003
|
+
newStatus: 'retracted',
|
|
1004
|
+
reason: input.reason,
|
|
1005
|
+
actor: ctx.agentId,
|
|
1006
|
+
timestamp: deps.time.nowISO(),
|
|
1007
|
+
},
|
|
1008
|
+
});
|
|
1009
|
+
// 7. Domain event: claim.retracted
|
|
1010
|
+
deps.eventBus.emit(conn, ctx, {
|
|
1011
|
+
type: CCP_EVENTS.CLAIM_RETRACTED.type,
|
|
1012
|
+
scope: CCP_EVENTS.CLAIM_RETRACTED.scope,
|
|
1013
|
+
propagation: CCP_EVENTS.CLAIM_RETRACTED.propagation,
|
|
1014
|
+
payload: {
|
|
1015
|
+
claimId: input.claimId,
|
|
1016
|
+
reason: input.reason,
|
|
1017
|
+
actor: ctx.agentId,
|
|
1018
|
+
},
|
|
1019
|
+
});
|
|
1020
|
+
// 8. Notification cascade: one-edge-deep (CCP-I14)
|
|
1021
|
+
// Find direct dependents (claims that reference this claim as evidence)
|
|
1022
|
+
const dependentEvidence = stores.evidence.getBySourceId(conn, 'claim', input.claimId);
|
|
1023
|
+
if (dependentEvidence.ok) {
|
|
1024
|
+
for (const ev of dependentEvidence.value) {
|
|
1025
|
+
deps.eventBus.emit(conn, ctx, {
|
|
1026
|
+
type: CCP_EVENTS.CLAIM_EVIDENCE_RETRACTED.type,
|
|
1027
|
+
scope: CCP_EVENTS.CLAIM_EVIDENCE_RETRACTED.scope,
|
|
1028
|
+
propagation: CCP_EVENTS.CLAIM_EVIDENCE_RETRACTED.propagation,
|
|
1029
|
+
payload: {
|
|
1030
|
+
dependentClaimId: ev.claimId,
|
|
1031
|
+
retractedClaimId: input.claimId,
|
|
1032
|
+
sourceClaimId: input.claimId,
|
|
1033
|
+
claimId: ev.claimId,
|
|
1034
|
+
},
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
// 9. Trace: claim.retracted (Binding 14)
|
|
1039
|
+
if (deps.traceEmitter) {
|
|
1040
|
+
deps.traceEmitter.emit(conn, ctx, {
|
|
1041
|
+
runId: 'run-ccp',
|
|
1042
|
+
correlationId,
|
|
1043
|
+
type: CCP_TRACE_EVENTS.CLAIM_RETRACTED,
|
|
1044
|
+
payload: {
|
|
1045
|
+
type: CCP_TRACE_EVENTS.CLAIM_RETRACTED,
|
|
1046
|
+
claimId: input.claimId,
|
|
1047
|
+
reason: input.reason,
|
|
1048
|
+
},
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
return ok(undefined);
|
|
1052
|
+
});
|
|
1053
|
+
},
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
// ============================================================================
|
|
1057
|
+
// RelateClaimsHandler Implementation — SC-12
|
|
1058
|
+
// ============================================================================
|
|
1059
|
+
function createRelateClaimsHandlerImpl(deps, stores) {
|
|
1060
|
+
return Object.freeze({
|
|
1061
|
+
execute(conn, ctx, input) {
|
|
1062
|
+
return conn.transaction(() => {
|
|
1063
|
+
const correlationId = newId();
|
|
1064
|
+
// 0. Authorization
|
|
1065
|
+
if (!isAuthorized(ctx)) {
|
|
1066
|
+
return err('UNAUTHORIZED', 'Agent not authorized to create relationships', 'SC-12');
|
|
1067
|
+
}
|
|
1068
|
+
// 0a. Rate limit
|
|
1069
|
+
if (!checkRateLimit(ctx.agentId, deps.time)) {
|
|
1070
|
+
return err('RATE_LIMITED', 'Rate limit exceeded', 'SC-12');
|
|
1071
|
+
}
|
|
1072
|
+
// 1. Validate relationship type
|
|
1073
|
+
const validTypes = ['supports', 'contradicts', 'supersedes', 'derived_from'];
|
|
1074
|
+
if (!validTypes.includes(input.type)) {
|
|
1075
|
+
return err('INVALID_RELATIONSHIP_TYPE', `Invalid type: ${input.type}`, 'I-31');
|
|
1076
|
+
}
|
|
1077
|
+
// 2. Self-reference check
|
|
1078
|
+
if (input.fromClaimId === input.toClaimId) {
|
|
1079
|
+
return err('SELF_REFERENCE', 'Cannot create self-referencing relationship', 'I-31');
|
|
1080
|
+
}
|
|
1081
|
+
// 3. Mission state validation
|
|
1082
|
+
if (input.missionId) {
|
|
1083
|
+
const missionRow = conn.get('SELECT state FROM core_missions WHERE id = ? AND tenant_id = ?', [input.missionId, ctx.tenantId]);
|
|
1084
|
+
if (missionRow) {
|
|
1085
|
+
const state = missionRow['state'];
|
|
1086
|
+
if (state === 'COMPLETED' || state === 'FAILED' || state === 'REVOKED') {
|
|
1087
|
+
return err('MISSION_NOT_ACTIVE', 'Mission is not in active state', 'SC-12');
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
// 4. Get from claim (must exist)
|
|
1092
|
+
const fromResult = stores.store.get(conn, input.fromClaimId, null);
|
|
1093
|
+
if (!fromResult.ok) {
|
|
1094
|
+
return err('CLAIM_NOT_FOUND', `Source claim ${input.fromClaimId} not found`, 'I-31');
|
|
1095
|
+
}
|
|
1096
|
+
// 5. Cross-tenant check
|
|
1097
|
+
const fromClaim = fromResult.value;
|
|
1098
|
+
if (ctx.tenantId !== null && fromClaim.tenantId !== ctx.tenantId) {
|
|
1099
|
+
return err('CROSS_TENANT', 'Source claim belongs to different tenant', 'CCP-LI-06');
|
|
1100
|
+
}
|
|
1101
|
+
// 6. From claim must be active
|
|
1102
|
+
if (fromClaim.status !== 'active') {
|
|
1103
|
+
return err('CLAIM_NOT_ACTIVE', 'Source claim must be active', 'I-31');
|
|
1104
|
+
}
|
|
1105
|
+
// 7. Get to claim (must exist)
|
|
1106
|
+
const toResult = stores.store.get(conn, input.toClaimId, null);
|
|
1107
|
+
if (!toResult.ok) {
|
|
1108
|
+
return err('CLAIM_NOT_FOUND', `Target claim ${input.toClaimId} not found`, 'I-31');
|
|
1109
|
+
}
|
|
1110
|
+
// 8. Cross-tenant on target
|
|
1111
|
+
const toClaim = toResult.value;
|
|
1112
|
+
if (ctx.tenantId !== null && fromClaim.tenantId !== toClaim.tenantId) {
|
|
1113
|
+
return err('CROSS_TENANT', 'Claims belong to different tenants', 'CCP-LI-06');
|
|
1114
|
+
}
|
|
1115
|
+
// 9. Outgoing relationship limit
|
|
1116
|
+
const countResult = stores.relationships.countOutgoing(conn, input.fromClaimId);
|
|
1117
|
+
if (countResult.ok && countResult.value >= CLAIM_MAX_OUTGOING_RELATIONSHIPS) {
|
|
1118
|
+
return err('RELATIONSHIP_LIMIT_EXCEEDED', `Outgoing relationship limit (${CLAIM_MAX_OUTGOING_RELATIONSHIPS}) exceeded`, 'I-31');
|
|
1119
|
+
}
|
|
1120
|
+
// 10. Create relationship
|
|
1121
|
+
const createResult = stores.relationships.create(conn, ctx, input);
|
|
1122
|
+
if (!createResult.ok)
|
|
1123
|
+
return createResult;
|
|
1124
|
+
// 11. Audit (I-03)
|
|
1125
|
+
deps.audit.append(conn, {
|
|
1126
|
+
tenantId: ctx.tenantId,
|
|
1127
|
+
actorType: ctx.agentId ? 'agent' : 'system',
|
|
1128
|
+
actorId: ctx.agentId ?? 'system',
|
|
1129
|
+
operation: 'claim_relationship_declared',
|
|
1130
|
+
resourceType: 'claim_relationship',
|
|
1131
|
+
resourceId: createResult.value.id,
|
|
1132
|
+
detail: {
|
|
1133
|
+
fromClaimId: input.fromClaimId,
|
|
1134
|
+
toClaimId: input.toClaimId,
|
|
1135
|
+
type: input.type,
|
|
1136
|
+
},
|
|
1137
|
+
});
|
|
1138
|
+
// 12. Domain event: claim.relationship.declared
|
|
1139
|
+
deps.eventBus.emit(conn, ctx, {
|
|
1140
|
+
type: CCP_EVENTS.CLAIM_RELATIONSHIP_DECLARED.type,
|
|
1141
|
+
scope: CCP_EVENTS.CLAIM_RELATIONSHIP_DECLARED.scope,
|
|
1142
|
+
propagation: CCP_EVENTS.CLAIM_RELATIONSHIP_DECLARED.propagation,
|
|
1143
|
+
missionId: input.missionId,
|
|
1144
|
+
payload: {
|
|
1145
|
+
fromClaimId: input.fromClaimId,
|
|
1146
|
+
toClaimId: input.toClaimId,
|
|
1147
|
+
type: input.type,
|
|
1148
|
+
relationshipId: createResult.value.id,
|
|
1149
|
+
},
|
|
1150
|
+
});
|
|
1151
|
+
// 13. Trace: claim.challenged on contradicts (DC-CCP-512)
|
|
1152
|
+
if (input.type === 'contradicts' && deps.traceEmitter) {
|
|
1153
|
+
deps.traceEmitter.emit(conn, ctx, {
|
|
1154
|
+
runId: 'run-ccp',
|
|
1155
|
+
correlationId,
|
|
1156
|
+
type: CCP_TRACE_EVENTS.CLAIM_CHALLENGED,
|
|
1157
|
+
payload: {
|
|
1158
|
+
type: CCP_TRACE_EVENTS.CLAIM_CHALLENGED,
|
|
1159
|
+
claimId: input.toClaimId,
|
|
1160
|
+
challengerId: ctx.agentId,
|
|
1161
|
+
},
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
return ok({ relationship: createResult.value });
|
|
1165
|
+
});
|
|
1166
|
+
},
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
// ============================================================================
|
|
1170
|
+
// QueryClaimsHandler Implementation — SC-13
|
|
1171
|
+
// ============================================================================
|
|
1172
|
+
function createQueryClaimsHandlerImpl(deps, stores) {
|
|
1173
|
+
return Object.freeze({
|
|
1174
|
+
execute(conn, ctx, input) {
|
|
1175
|
+
// 0. Authorization
|
|
1176
|
+
if (!isAuthorized(ctx)) {
|
|
1177
|
+
return err('UNAUTHORIZED', 'Agent not authorized to query claims', 'SC-13');
|
|
1178
|
+
}
|
|
1179
|
+
// 0a. Rate limit
|
|
1180
|
+
if (!checkRateLimit(ctx.agentId, deps.time)) {
|
|
1181
|
+
return err('RATE_LIMITED', 'Rate limit exceeded', 'SC-13');
|
|
1182
|
+
}
|
|
1183
|
+
// 1. Validate limit
|
|
1184
|
+
if (input.limit !== undefined && input.limit !== null && input.limit > CLAIM_QUERY_MAX_LIMIT) {
|
|
1185
|
+
return err('LIMIT_EXCEEDED', `Limit exceeds maximum of ${CLAIM_QUERY_MAX_LIMIT}`, 'SC-13');
|
|
1186
|
+
}
|
|
1187
|
+
// 2. Validate at least one filter provided
|
|
1188
|
+
const hasFilter = ((input.subject !== undefined && input.subject !== null) ||
|
|
1189
|
+
(input.predicate !== undefined && input.predicate !== null) ||
|
|
1190
|
+
(input.status !== undefined && input.status !== null) ||
|
|
1191
|
+
(input.minConfidence !== undefined && input.minConfidence !== null) ||
|
|
1192
|
+
(input.sourceAgentId !== undefined && input.sourceAgentId !== null) ||
|
|
1193
|
+
(input.sourceMissionId !== undefined && input.sourceMissionId !== null) ||
|
|
1194
|
+
(input.validAtFrom !== undefined && input.validAtFrom !== null) ||
|
|
1195
|
+
(input.validAtTo !== undefined && input.validAtTo !== null) ||
|
|
1196
|
+
('missionId' in input && input['missionId'] !== undefined));
|
|
1197
|
+
if (!hasFilter) {
|
|
1198
|
+
return err('NO_FILTERS', 'At least one filter must be provided', 'SC-13');
|
|
1199
|
+
}
|
|
1200
|
+
// 3. Validate subject filter format
|
|
1201
|
+
if (input.subject !== undefined && input.subject !== null) {
|
|
1202
|
+
if (!isValidSubjectFilter(input.subject)) {
|
|
1203
|
+
return err('INVALID_SUBJECT_FILTER', `Invalid subject filter: ${input.subject}`, 'AMB-14');
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
// 4. Validate predicate filter format
|
|
1207
|
+
if (input.predicate !== undefined && input.predicate !== null) {
|
|
1208
|
+
if (!isValidPredicateFilter(input.predicate)) {
|
|
1209
|
+
return err('INVALID_PREDICATE_FILTER', `Invalid predicate filter: ${input.predicate}`, 'AMB-14');
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
// 5. Mission state validation for sourceMissionId filter
|
|
1213
|
+
if (input.sourceMissionId) {
|
|
1214
|
+
const missionRow = conn.get('SELECT state FROM core_missions WHERE id = ? AND tenant_id = ?', [input.sourceMissionId, ctx.tenantId]);
|
|
1215
|
+
if (missionRow) {
|
|
1216
|
+
const state = missionRow['state'];
|
|
1217
|
+
if (state === 'COMPLETED' || state === 'FAILED' || state === 'REVOKED') {
|
|
1218
|
+
return err('MISSION_NOT_ACTIVE', 'Mission is not in active state', 'SC-13');
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
// 6. Delegate to store
|
|
1223
|
+
return stores.store.query(conn, ctx.tenantId, input);
|
|
1224
|
+
},
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
// ============================================================================
|
|
1228
|
+
// ClaimSystem Factory — wires everything together
|
|
1229
|
+
// ============================================================================
|
|
1230
|
+
export function createClaimSystem(deps) {
|
|
1231
|
+
// Reset rate limits per test run
|
|
1232
|
+
resetRateLimits();
|
|
1233
|
+
// Create stores
|
|
1234
|
+
const store = createClaimStoreImpl(deps);
|
|
1235
|
+
const evidence = createClaimEvidenceStoreImpl(deps);
|
|
1236
|
+
const relationships = createClaimRelationshipStoreImpl(deps);
|
|
1237
|
+
const artifactRefs = createClaimArtifactRefStoreImpl(deps);
|
|
1238
|
+
// Create grounding validator
|
|
1239
|
+
const grounding = createGroundingValidatorImpl(deps, { store, evidence });
|
|
1240
|
+
// Create lifecycle projection
|
|
1241
|
+
const lifecycleProjection = createClaimLifecycleProjectionImpl();
|
|
1242
|
+
// Create handlers
|
|
1243
|
+
const assertClaim = createAssertClaimHandlerImpl(deps, { store, evidence, artifactRefs, grounding });
|
|
1244
|
+
const retractClaim = createRetractClaimHandlerImpl(deps, { store, evidence });
|
|
1245
|
+
const relateClaims = createRelateClaimsHandlerImpl(deps, { store, relationships });
|
|
1246
|
+
const queryClaims = createQueryClaimsHandlerImpl(deps, { store, evidence, relationships });
|
|
1247
|
+
// Wire tombstone event and evidence cascade to the store operations
|
|
1248
|
+
const storeWithEvents = {
|
|
1249
|
+
...store,
|
|
1250
|
+
tombstone(conn, claimId, tenantId, reason) {
|
|
1251
|
+
return conn.transaction(() => {
|
|
1252
|
+
// Tombstone the claim
|
|
1253
|
+
const result = store.tombstone(conn, claimId, tenantId, reason);
|
|
1254
|
+
if (!result.ok)
|
|
1255
|
+
return result;
|
|
1256
|
+
// Update evidence rows pointing to this claim (sourceState → tombstoned)
|
|
1257
|
+
evidence.markSourceTombstoned(conn, 'claim', claimId);
|
|
1258
|
+
// Emit claim.tombstoned event
|
|
1259
|
+
const dummyCtx = {
|
|
1260
|
+
tenantId: tenantId,
|
|
1261
|
+
userId: null,
|
|
1262
|
+
agentId: null,
|
|
1263
|
+
permissions: new Set(),
|
|
1264
|
+
};
|
|
1265
|
+
deps.eventBus.emit(conn, dummyCtx, {
|
|
1266
|
+
type: CCP_EVENTS.CLAIM_TOMBSTONED.type,
|
|
1267
|
+
scope: CCP_EVENTS.CLAIM_TOMBSTONED.scope,
|
|
1268
|
+
propagation: CCP_EVENTS.CLAIM_TOMBSTONED.propagation,
|
|
1269
|
+
payload: { claimId, purgeReason: reason },
|
|
1270
|
+
});
|
|
1271
|
+
// Audit
|
|
1272
|
+
deps.audit.append(conn, {
|
|
1273
|
+
tenantId,
|
|
1274
|
+
actorType: 'system',
|
|
1275
|
+
actorId: 'system',
|
|
1276
|
+
operation: 'claim_tombstoned',
|
|
1277
|
+
resourceType: 'claim',
|
|
1278
|
+
resourceId: claimId,
|
|
1279
|
+
detail: { reason },
|
|
1280
|
+
});
|
|
1281
|
+
return ok(undefined);
|
|
1282
|
+
});
|
|
1283
|
+
},
|
|
1284
|
+
archive(conn, claimId, tenantId) {
|
|
1285
|
+
return conn.transaction(() => {
|
|
1286
|
+
const result = store.archive(conn, claimId, tenantId);
|
|
1287
|
+
if (!result.ok)
|
|
1288
|
+
return result;
|
|
1289
|
+
// Audit
|
|
1290
|
+
deps.audit.append(conn, {
|
|
1291
|
+
tenantId,
|
|
1292
|
+
actorType: 'system',
|
|
1293
|
+
actorId: 'system',
|
|
1294
|
+
operation: 'claim_archived',
|
|
1295
|
+
resourceType: 'claim',
|
|
1296
|
+
resourceId: claimId,
|
|
1297
|
+
});
|
|
1298
|
+
return ok(undefined);
|
|
1299
|
+
});
|
|
1300
|
+
},
|
|
1301
|
+
};
|
|
1302
|
+
// Wire evidence store with event emission for markSourceTombstoned
|
|
1303
|
+
const evidenceWithEvents = {
|
|
1304
|
+
...evidence,
|
|
1305
|
+
markSourceTombstoned(conn, evidenceType, evidenceId) {
|
|
1306
|
+
const result = evidence.markSourceTombstoned(conn, evidenceType, evidenceId);
|
|
1307
|
+
if (!result.ok)
|
|
1308
|
+
return result;
|
|
1309
|
+
// Emit claim.evidence.orphaned for non-claim sources
|
|
1310
|
+
if (evidenceType !== 'claim') {
|
|
1311
|
+
// Get affected evidence rows to know which claims are affected
|
|
1312
|
+
const affected = evidence.getBySourceId(conn, evidenceType, evidenceId);
|
|
1313
|
+
if (affected.ok) {
|
|
1314
|
+
const dummyCtx = {
|
|
1315
|
+
tenantId: null,
|
|
1316
|
+
userId: null,
|
|
1317
|
+
agentId: null,
|
|
1318
|
+
permissions: new Set(),
|
|
1319
|
+
};
|
|
1320
|
+
for (const ev of affected.value) {
|
|
1321
|
+
deps.eventBus.emit(conn, dummyCtx, {
|
|
1322
|
+
type: CCP_EVENTS.CLAIM_EVIDENCE_ORPHANED.type,
|
|
1323
|
+
scope: CCP_EVENTS.CLAIM_EVIDENCE_ORPHANED.scope,
|
|
1324
|
+
propagation: CCP_EVENTS.CLAIM_EVIDENCE_ORPHANED.propagation,
|
|
1325
|
+
payload: {
|
|
1326
|
+
claimId: ev.claimId,
|
|
1327
|
+
evidenceType,
|
|
1328
|
+
evidenceId,
|
|
1329
|
+
sourceType: evidenceType,
|
|
1330
|
+
sourceId: evidenceId,
|
|
1331
|
+
},
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
return result;
|
|
1337
|
+
},
|
|
1338
|
+
};
|
|
1339
|
+
return Object.freeze({
|
|
1340
|
+
store: storeWithEvents,
|
|
1341
|
+
evidence: evidenceWithEvents,
|
|
1342
|
+
relationships,
|
|
1343
|
+
artifactRefs,
|
|
1344
|
+
assertClaim,
|
|
1345
|
+
retractClaim,
|
|
1346
|
+
relateClaims,
|
|
1347
|
+
queryClaims,
|
|
1348
|
+
grounding,
|
|
1349
|
+
lifecycleProjection,
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
//# sourceMappingURL=claim_stores.js.map
|