@vauban-org/agent-sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRACT.md +6401 -813
- package/dist/adapters/llm/anthropic-direct.d.ts +1 -0
- package/dist/adapters/llm/anthropic-direct.d.ts.map +1 -1
- package/dist/adapters/llm/anthropic-direct.js +43 -0
- package/dist/adapters/llm/anthropic-direct.js.map +1 -1
- package/dist/adapters/llm/cascade.d.ts.map +1 -1
- package/dist/adapters/llm/cascade.js +57 -14
- package/dist/adapters/llm/cascade.js.map +1 -1
- package/dist/adapters/llm/litellm.d.ts +2 -0
- package/dist/adapters/llm/litellm.d.ts.map +1 -1
- package/dist/adapters/llm/litellm.js +44 -0
- package/dist/adapters/llm/litellm.js.map +1 -1
- package/dist/compute/difficulty-estimator.d.ts +53 -0
- package/dist/compute/difficulty-estimator.d.ts.map +1 -0
- package/dist/compute/difficulty-estimator.js +82 -0
- package/dist/compute/difficulty-estimator.js.map +1 -0
- package/dist/compute/strategies/mixture-of-agents.d.ts +40 -0
- package/dist/compute/strategies/mixture-of-agents.d.ts.map +1 -0
- package/dist/compute/strategies/mixture-of-agents.js +110 -0
- package/dist/compute/strategies/mixture-of-agents.js.map +1 -0
- package/dist/compute/strategies/tree-of-thoughts.d.ts +48 -0
- package/dist/compute/strategies/tree-of-thoughts.d.ts.map +1 -0
- package/dist/compute/strategies/tree-of-thoughts.js +242 -0
- package/dist/compute/strategies/tree-of-thoughts.js.map +1 -0
- package/dist/compute/strategies/two-phase-orient.d.ts +72 -0
- package/dist/compute/strategies/two-phase-orient.d.ts.map +1 -0
- package/dist/compute/strategies/two-phase-orient.js +85 -0
- package/dist/compute/strategies/two-phase-orient.js.map +1 -0
- package/dist/constitution/types.d.ts +10 -10
- package/dist/container/protocol.d.ts +134 -0
- package/dist/container/protocol.d.ts.map +1 -0
- package/dist/container/protocol.js +157 -0
- package/dist/container/protocol.js.map +1 -0
- package/dist/container/runtime.d.ts +140 -0
- package/dist/container/runtime.d.ts.map +1 -0
- package/dist/container/runtime.js +256 -0
- package/dist/container/runtime.js.map +1 -0
- package/dist/events/catalogue.d.ts +46 -46
- package/dist/events/schemas/agent.completed.v1.d.ts +4 -4
- package/dist/events/schemas/agent.failed.v1.d.ts +2 -2
- package/dist/events/schemas/agent.hitl_resolved.v1.d.ts +2 -2
- package/dist/events/schemas/agent.started.v1.d.ts +2 -2
- package/dist/events/schemas/brain.skill.extracted.v1.d.ts +4 -4
- package/dist/events/schemas/cc.cost.anomaly_detected.v1.d.ts +2 -2
- package/dist/events/schemas/cc.cost.recorded.v1.d.ts +4 -4
- package/dist/events/schemas/citadel.sprint.analyzed.v1.d.ts +6 -6
- package/dist/events/schemas/citadel.sprint.closed.v1.d.ts +2 -2
- package/dist/events/schemas/forge.inbox.reply_classified.v1.d.ts +6 -6
- package/dist/events/schemas/forge.lead.qualified.v1.d.ts +2 -2
- package/dist/events/schemas/forge.outreach.sent.v1.d.ts +4 -4
- package/dist/events/schemas/incident.detected.v1.d.ts +2 -2
- package/dist/events/schemas/vauban.goal.checked.v1.d.ts +2 -2
- package/dist/events/schemas/vauban.rebalancing.checked.v1.d.ts +2 -2
- package/dist/events/schemas/vauban.tax.checked.v1.d.ts +2 -2
- package/dist/events/schemas/vauban.vault.analyzed.v1.d.ts +6 -6
- package/dist/identity/agent-persona.d.ts +73 -0
- package/dist/identity/agent-persona.d.ts.map +1 -0
- package/dist/identity/agent-persona.js +165 -0
- package/dist/identity/agent-persona.js.map +1 -0
- package/dist/identity/persona-prompt.d.ts +25 -0
- package/dist/identity/persona-prompt.d.ts.map +1 -0
- package/dist/identity/persona-prompt.js +71 -0
- package/dist/identity/persona-prompt.js.map +1 -0
- package/dist/identity/persona-schema.d.ts +120 -0
- package/dist/identity/persona-schema.d.ts.map +1 -0
- package/dist/identity/persona-schema.js +103 -0
- package/dist/identity/persona-schema.js.map +1 -0
- package/dist/index.d.ts +37 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/loop/minimal-loop.js +293 -287
- package/dist/memory/episodic-rrf.d.ts +114 -0
- package/dist/memory/episodic-rrf.d.ts.map +1 -0
- package/dist/memory/episodic-rrf.js +148 -0
- package/dist/memory/episodic-rrf.js.map +1 -0
- package/dist/mesh/attenuation.d.ts +78 -0
- package/dist/mesh/attenuation.d.ts.map +1 -0
- package/dist/mesh/attenuation.js +141 -0
- package/dist/mesh/attenuation.js.map +1 -0
- package/dist/mesh/delegate.d.ts +96 -0
- package/dist/mesh/delegate.d.ts.map +1 -0
- package/dist/mesh/delegate.js +172 -0
- package/dist/mesh/delegate.js.map +1 -0
- package/dist/mesh/dispatcher.d.ts +119 -0
- package/dist/mesh/dispatcher.d.ts.map +1 -0
- package/dist/mesh/dispatcher.js +207 -0
- package/dist/mesh/dispatcher.js.map +1 -0
- package/dist/mesh/index.d.ts +12 -0
- package/dist/mesh/index.d.ts.map +1 -0
- package/dist/mesh/index.js +11 -0
- package/dist/mesh/index.js.map +1 -0
- package/dist/mesh/types.d.ts +30 -0
- package/dist/mesh/types.d.ts.map +1 -0
- package/dist/mesh/types.js +11 -0
- package/dist/mesh/types.js.map +1 -0
- package/dist/orchestration/ooda/skills.d.ts +104 -0
- package/dist/orchestration/ooda/skills.d.ts.map +1 -1
- package/dist/orchestration/ooda/skills.js +106 -0
- package/dist/orchestration/ooda/skills.js.map +1 -1
- package/dist/ports/bastion-action.contract.test.d.ts +11 -0
- package/dist/ports/bastion-action.contract.test.d.ts.map +1 -0
- package/dist/ports/bastion-action.contract.test.js +238 -0
- package/dist/ports/bastion-action.contract.test.js.map +1 -0
- package/dist/ports/bastion-action.d.ts +133 -0
- package/dist/ports/bastion-action.d.ts.map +1 -0
- package/dist/ports/bastion-action.js +73 -0
- package/dist/ports/bastion-action.js.map +1 -0
- package/dist/ports/brain.d.ts +31 -0
- package/dist/ports/brain.d.ts.map +1 -1
- package/dist/ports/brain.js +115 -1
- package/dist/ports/brain.js.map +1 -1
- package/dist/ports/citadel-action.contract.test.d.ts +11 -0
- package/dist/ports/citadel-action.contract.test.d.ts.map +1 -0
- package/dist/ports/citadel-action.contract.test.js +317 -0
- package/dist/ports/citadel-action.contract.test.js.map +1 -0
- package/dist/ports/citadel-action.d.ts +111 -0
- package/dist/ports/citadel-action.d.ts.map +1 -0
- package/dist/ports/citadel-action.js +62 -0
- package/dist/ports/citadel-action.js.map +1 -0
- package/dist/ports/compliance-contract.d.ts +123 -0
- package/dist/ports/compliance-contract.d.ts.map +1 -0
- package/dist/ports/compliance-contract.js +35 -0
- package/dist/ports/compliance-contract.js.map +1 -0
- package/dist/ports/db.d.ts +38 -0
- package/dist/ports/db.d.ts.map +1 -1
- package/dist/ports/db.js +88 -1
- package/dist/ports/db.js.map +1 -1
- package/dist/ports/delegation.contract.test.d.ts +9 -0
- package/dist/ports/delegation.contract.test.d.ts.map +1 -0
- package/dist/ports/delegation.contract.test.js +337 -0
- package/dist/ports/delegation.contract.test.js.map +1 -0
- package/dist/ports/delegation.d.ts +134 -0
- package/dist/ports/delegation.d.ts.map +1 -0
- package/dist/ports/delegation.js +105 -0
- package/dist/ports/delegation.js.map +1 -0
- package/dist/ports/event-bus.d.ts +29 -0
- package/dist/ports/event-bus.d.ts.map +1 -1
- package/dist/ports/event-bus.js +106 -1
- package/dist/ports/event-bus.js.map +1 -1
- package/dist/ports/federation.contract.test.d.ts +9 -0
- package/dist/ports/federation.contract.test.d.ts.map +1 -0
- package/dist/ports/federation.contract.test.js +279 -0
- package/dist/ports/federation.contract.test.js.map +1 -0
- package/dist/ports/federation.d.ts +140 -0
- package/dist/ports/federation.d.ts.map +1 -0
- package/dist/ports/federation.js +57 -0
- package/dist/ports/federation.js.map +1 -0
- package/dist/ports/index.d.ts +28 -2
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +17 -2
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/llm-provider.d.ts +37 -0
- package/dist/ports/llm-provider.d.ts.map +1 -1
- package/dist/ports/llm-provider.js +99 -1
- package/dist/ports/llm-provider.js.map +1 -1
- package/dist/ports/logger.d.ts +27 -0
- package/dist/ports/logger.d.ts.map +1 -1
- package/dist/ports/logger.js +87 -0
- package/dist/ports/logger.js.map +1 -1
- package/dist/ports/manifest-registry.contract.test.d.ts +9 -0
- package/dist/ports/manifest-registry.contract.test.d.ts.map +1 -0
- package/dist/ports/manifest-registry.contract.test.js +246 -0
- package/dist/ports/manifest-registry.contract.test.js.map +1 -0
- package/dist/ports/manifest-registry.d.ts +116 -0
- package/dist/ports/manifest-registry.d.ts.map +1 -0
- package/dist/ports/manifest-registry.js +79 -0
- package/dist/ports/manifest-registry.js.map +1 -0
- package/dist/ports/observability.contract.test.d.ts +12 -0
- package/dist/ports/observability.contract.test.d.ts.map +1 -0
- package/dist/ports/observability.contract.test.js +260 -0
- package/dist/ports/observability.contract.test.js.map +1 -0
- package/dist/ports/observability.d.ts +98 -0
- package/dist/ports/observability.d.ts.map +1 -0
- package/dist/ports/observability.js +59 -0
- package/dist/ports/observability.js.map +1 -0
- package/dist/ports/outcome.d.ts +26 -0
- package/dist/ports/outcome.d.ts.map +1 -1
- package/dist/ports/outcome.js +62 -1
- package/dist/ports/outcome.js.map +1 -1
- package/dist/ports/privacy.contract.test.d.ts +12 -0
- package/dist/ports/privacy.contract.test.d.ts.map +1 -0
- package/dist/ports/privacy.contract.test.js +325 -0
- package/dist/ports/privacy.contract.test.js.map +1 -0
- package/dist/ports/privacy.d.ts +132 -0
- package/dist/ports/privacy.d.ts.map +1 -0
- package/dist/ports/privacy.js +83 -0
- package/dist/ports/privacy.js.map +1 -0
- package/dist/ports/tenant-context.contract.test.d.ts +14 -0
- package/dist/ports/tenant-context.contract.test.d.ts.map +1 -0
- package/dist/ports/tenant-context.contract.test.js +352 -0
- package/dist/ports/tenant-context.contract.test.js.map +1 -0
- package/dist/ports/tenant-context.d.ts +103 -0
- package/dist/ports/tenant-context.d.ts.map +1 -0
- package/dist/ports/tenant-context.js +48 -0
- package/dist/ports/tenant-context.js.map +1 -0
- package/dist/ports/vauban-finance-action.contract.test.d.ts +11 -0
- package/dist/ports/vauban-finance-action.contract.test.d.ts.map +1 -0
- package/dist/ports/vauban-finance-action.contract.test.js +260 -0
- package/dist/ports/vauban-finance-action.contract.test.js.map +1 -0
- package/dist/ports/vauban-finance-action.d.ts +106 -0
- package/dist/ports/vauban-finance-action.d.ts.map +1 -0
- package/dist/ports/vauban-finance-action.js +60 -0
- package/dist/ports/vauban-finance-action.js.map +1 -0
- package/dist/ports/workflow-runtime.d.ts +204 -0
- package/dist/ports/workflow-runtime.d.ts.map +1 -0
- package/dist/ports/workflow-runtime.js +72 -0
- package/dist/ports/workflow-runtime.js.map +1 -0
- package/dist/proof/cert-verify.d.ts +80 -0
- package/dist/proof/cert-verify.d.ts.map +1 -0
- package/dist/proof/cert-verify.js +178 -0
- package/dist/proof/cert-verify.js.map +1 -0
- package/dist/replay/replay.d.ts.map +1 -1
- package/dist/replay/replay.js +5 -1
- package/dist/replay/replay.js.map +1 -1
- package/dist/retry/index.d.ts +129 -0
- package/dist/retry/index.d.ts.map +1 -0
- package/dist/retry/index.js +156 -0
- package/dist/retry/index.js.map +1 -0
- package/dist/retry/presets.d.ts +39 -0
- package/dist/retry/presets.d.ts.map +1 -0
- package/dist/retry/presets.js +69 -0
- package/dist/retry/presets.js.map +1 -0
- package/dist/skill-loop/ab-runner.d.ts +67 -0
- package/dist/skill-loop/ab-runner.d.ts.map +1 -0
- package/dist/skill-loop/ab-runner.js +160 -0
- package/dist/skill-loop/ab-runner.js.map +1 -0
- package/dist/skill-loop/adoption.d.ts +67 -0
- package/dist/skill-loop/adoption.d.ts.map +1 -0
- package/dist/skill-loop/adoption.js +126 -0
- package/dist/skill-loop/adoption.js.map +1 -0
- package/dist/skill-loop/candidate.d.ts +45 -0
- package/dist/skill-loop/candidate.d.ts.map +1 -0
- package/dist/skill-loop/candidate.js +43 -0
- package/dist/skill-loop/candidate.js.map +1 -0
- package/dist/skill-loop/evaluator.d.ts +42 -0
- package/dist/skill-loop/evaluator.d.ts.map +1 -0
- package/dist/skill-loop/evaluator.js +184 -0
- package/dist/skill-loop/evaluator.js.map +1 -0
- package/dist/skill-loop/index.d.ts +27 -0
- package/dist/skill-loop/index.d.ts.map +1 -0
- package/dist/skill-loop/index.js +27 -0
- package/dist/skill-loop/index.js.map +1 -0
- package/dist/skill-loop/reflexion-replay.d.ts +87 -0
- package/dist/skill-loop/reflexion-replay.d.ts.map +1 -0
- package/dist/skill-loop/reflexion-replay.js +110 -0
- package/dist/skill-loop/reflexion-replay.js.map +1 -0
- package/dist/skill-loop/sign-off.d.ts +88 -0
- package/dist/skill-loop/sign-off.d.ts.map +1 -0
- package/dist/skill-loop/sign-off.js +146 -0
- package/dist/skill-loop/sign-off.js.map +1 -0
- package/dist/skill-loop/value-metric.d.ts +55 -0
- package/dist/skill-loop/value-metric.d.ts.map +1 -0
- package/dist/skill-loop/value-metric.js +69 -0
- package/dist/skill-loop/value-metric.js.map +1 -0
- package/dist/skill-loop/versioning.d.ts +36 -0
- package/dist/skill-loop/versioning.d.ts.map +1 -0
- package/dist/skill-loop/versioning.js +47 -0
- package/dist/skill-loop/versioning.js.map +1 -0
- package/dist/skill-manifest/anchor.d.ts +91 -0
- package/dist/skill-manifest/anchor.d.ts.map +1 -0
- package/dist/skill-manifest/anchor.js +331 -0
- package/dist/skill-manifest/anchor.js.map +1 -0
- package/dist/skill-manifest/builder.d.ts +47 -0
- package/dist/skill-manifest/builder.d.ts.map +1 -0
- package/dist/skill-manifest/builder.js +93 -0
- package/dist/skill-manifest/builder.js.map +1 -0
- package/dist/skill-manifest/index.d.ts +13 -0
- package/dist/skill-manifest/index.d.ts.map +1 -0
- package/dist/skill-manifest/index.js +9 -0
- package/dist/skill-manifest/index.js.map +1 -0
- package/dist/skill-manifest/types.d.ts +67 -0
- package/dist/skill-manifest/types.d.ts.map +1 -0
- package/dist/skill-manifest/types.js +16 -0
- package/dist/skill-manifest/types.js.map +1 -0
- package/dist/skill-manifest/verifier.d.ts +42 -0
- package/dist/skill-manifest/verifier.d.ts.map +1 -0
- package/dist/skill-manifest/verifier.js +136 -0
- package/dist/skill-manifest/verifier.js.map +1 -0
- package/dist/skills/brain-query.d.ts +4 -4
- package/dist/skills/brain-store.d.ts +6 -6
- package/dist/skills/errors.d.ts +15 -0
- package/dist/skills/errors.d.ts.map +1 -1
- package/dist/skills/errors.js +21 -0
- package/dist/skills/errors.js.map +1 -1
- package/dist/skills/hitl-request.d.ts +2 -2
- package/dist/skills/index.d.ts +3 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +4 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/markdown/loader.d.ts +52 -0
- package/dist/skills/markdown/loader.d.ts.map +1 -0
- package/dist/skills/markdown/loader.js +93 -0
- package/dist/skills/markdown/loader.js.map +1 -0
- package/dist/skills/markdown/schema.d.ts +432 -0
- package/dist/skills/markdown/schema.d.ts.map +1 -0
- package/dist/skills/markdown/schema.js +121 -0
- package/dist/skills/markdown/schema.js.map +1 -0
- package/dist/skills/poc-md-loader/markdown-loader.d.ts +77 -0
- package/dist/skills/poc-md-loader/markdown-loader.d.ts.map +1 -0
- package/dist/skills/poc-md-loader/markdown-loader.js +125 -0
- package/dist/skills/poc-md-loader/markdown-loader.js.map +1 -0
- package/dist/skills/poc-md-loader/runner.d.ts +24 -0
- package/dist/skills/poc-md-loader/runner.d.ts.map +1 -0
- package/dist/skills/poc-md-loader/runner.js +57 -0
- package/dist/skills/poc-md-loader/runner.js.map +1 -0
- package/dist/skills/poc-md-loader/vitest.poc.config.d.ts +3 -0
- package/dist/skills/poc-md-loader/vitest.poc.config.d.ts.map +1 -0
- package/dist/skills/poc-md-loader/vitest.poc.config.js +13 -0
- package/dist/skills/poc-md-loader/vitest.poc.config.js.map +1 -0
- package/dist/skills/poc-md-loader/web-search/script.d.ts +33 -0
- package/dist/skills/poc-md-loader/web-search/script.d.ts.map +1 -0
- package/dist/skills/poc-md-loader/web-search/script.js +75 -0
- package/dist/skills/poc-md-loader/web-search/script.js.map +1 -0
- package/dist/skills/record-outcome.d.ts +4 -4
- package/dist/skills/send-email.d.ts.map +1 -1
- package/dist/skills/send-email.js +15 -3
- package/dist/skills/send-email.js.map +1 -1
- package/dist/skills/slack-notify.d.ts +4 -4
- package/dist/skills/starknet-balance.d.ts +1 -1
- package/dist/skills/telegram-notify.d.ts +4 -4
- package/dist/skills/web-search.d.ts +1 -1
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/test-brain-port.d.ts +4 -0
- package/dist/testing/test-brain-port.d.ts.map +1 -1
- package/dist/testing/test-brain-port.js +75 -20
- package/dist/testing/test-brain-port.js.map +1 -1
- package/dist/testing/test-event-bus.d.ts.map +1 -1
- package/dist/testing/test-event-bus.js +89 -36
- package/dist/testing/test-event-bus.js.map +1 -1
- package/dist/trace/schema.d.ts +1 -1
- package/dist/trace/schema.d.ts.map +1 -1
- package/dist/trace/schema.js +1 -1
- package/dist/trace/schema.js.map +1 -1
- package/dist/verify/formal/index.d.ts +44 -0
- package/dist/verify/formal/index.d.ts.map +1 -0
- package/dist/verify/formal/index.js +98 -0
- package/dist/verify/formal/index.js.map +1 -0
- package/dist/verify/formal/policy.d.ts +105 -0
- package/dist/verify/formal/policy.d.ts.map +1 -0
- package/dist/verify/formal/policy.js +159 -0
- package/dist/verify/formal/policy.js.map +1 -0
- package/dist/verify/formal/result.d.ts +50 -0
- package/dist/verify/formal/result.d.ts.map +1 -0
- package/dist/verify/formal/result.js +21 -0
- package/dist/verify/formal/result.js.map +1 -0
- package/dist/verify/formal/solver.d.ts +67 -0
- package/dist/verify/formal/solver.d.ts.map +1 -0
- package/dist/verify/formal/solver.js +184 -0
- package/dist/verify/formal/solver.js.map +1 -0
- package/dist/verify/formal/spec-language.d.ts +80 -0
- package/dist/verify/formal/spec-language.d.ts.map +1 -0
- package/dist/verify/formal/spec-language.js +219 -0
- package/dist/verify/formal/spec-language.js.map +1 -0
- package/docs/attestation.md +199 -0
- package/docs/identity.md +193 -0
- package/package.json +34 -17
- package/src/adapters/llm/anthropic-direct.ts +51 -0
- package/src/adapters/llm/cascade.ts +64 -19
- package/src/adapters/llm/litellm.ts +49 -0
- package/src/compute/difficulty-estimator.ts +111 -0
- package/src/compute/strategies/mixture-of-agents.ts +150 -0
- package/src/compute/strategies/tree-of-thoughts.ts +293 -0
- package/src/compute/strategies/two-phase-orient.ts +147 -0
- package/src/container/protocol.ts +243 -0
- package/src/container/runtime.ts +424 -0
- package/src/db/migrations/026_formal_verify_results.sql +30 -0
- package/src/identity/agent-persona.ts +203 -0
- package/src/identity/persona-prompt.ts +84 -0
- package/src/identity/persona-schema.ts +127 -0
- package/src/index.ts +338 -1
- package/src/memory/episodic-rrf.ts +224 -0
- package/src/mesh/attenuation.ts +190 -0
- package/src/mesh/delegate.ts +254 -0
- package/src/mesh/dispatcher.ts +301 -0
- package/src/mesh/index.ts +39 -0
- package/src/mesh/types.ts +31 -0
- package/src/orchestration/ooda/skills.ts +177 -0
- package/src/ports/bastion-action.contract.test.ts +355 -0
- package/src/ports/bastion-action.ts +198 -0
- package/src/ports/brain.ts +177 -15
- package/src/ports/citadel-action.contract.test.ts +430 -0
- package/src/ports/citadel-action.ts +174 -0
- package/src/ports/compliance-contract.ts +191 -0
- package/src/ports/db.ts +98 -0
- package/src/ports/delegation.contract.test.ts +428 -0
- package/src/ports/delegation.ts +211 -0
- package/src/ports/event-bus.ts +133 -0
- package/src/ports/federation.contract.test.ts +355 -0
- package/src/ports/federation.ts +190 -0
- package/src/ports/index.ts +186 -1
- package/src/ports/llm-provider.ts +123 -0
- package/src/ports/logger.ts +104 -0
- package/src/ports/manifest-registry.contract.test.ts +324 -0
- package/src/ports/manifest-registry.ts +188 -0
- package/src/ports/observability.contract.test.ts +315 -0
- package/src/ports/observability.ts +150 -0
- package/src/ports/outcome.ts +69 -0
- package/src/ports/privacy.contract.test.ts +413 -0
- package/src/ports/privacy.ts +207 -0
- package/src/ports/tenant-context.contract.test.ts +454 -0
- package/src/ports/tenant-context.ts +150 -0
- package/src/ports/vauban-finance-action.contract.test.ts +335 -0
- package/src/ports/vauban-finance-action.ts +166 -0
- package/src/ports/workflow-runtime.ts +327 -0
- package/src/proof/cert-verify.ts +249 -0
- package/src/replay/replay.ts +11 -8
- package/src/retry/index.ts +227 -0
- package/src/retry/presets.ts +75 -0
- package/src/skill-loop/ab-runner.ts +196 -0
- package/src/skill-loop/adoption.ts +188 -0
- package/src/skill-loop/candidate.ts +75 -0
- package/src/skill-loop/evaluator.ts +238 -0
- package/src/skill-loop/index.ts +51 -0
- package/src/skill-loop/reflexion-replay.ts +173 -0
- package/src/skill-loop/sign-off.ts +247 -0
- package/src/skill-loop/value-metric.ts +120 -0
- package/src/skill-loop/versioning.ts +75 -0
- package/src/skill-manifest/anchor.ts +401 -0
- package/src/skill-manifest/builder.ts +129 -0
- package/src/skill-manifest/index.ts +18 -0
- package/src/skill-manifest/types.ts +72 -0
- package/src/skill-manifest/verifier.ts +198 -0
- package/src/skills/errors.ts +30 -2
- package/src/skills/index.ts +19 -0
- package/src/skills/markdown/loader.ts +129 -0
- package/src/skills/markdown/schema.ts +144 -0
- package/src/skills/poc-md-loader/e2e-parity.test.ts +237 -0
- package/src/skills/poc-md-loader/markdown-loader.ts +161 -0
- package/src/skills/poc-md-loader/runner.ts +82 -0
- package/src/skills/poc-md-loader/vitest.poc.config.ts +13 -0
- package/src/skills/poc-md-loader/web-search/SKILL.md +42 -0
- package/src/skills/poc-md-loader/web-search/script.ts +109 -0
- package/src/skills/send-email.ts +15 -3
- package/src/testing/test-brain-port.ts +98 -24
- package/src/testing/test-event-bus.ts +104 -43
- package/src/trace/schema.ts +1 -1
- package/src/verify/formal/index.ts +154 -0
- package/src/verify/formal/policy.ts +253 -0
- package/src/verify/formal/result.ts +52 -0
- package/src/verify/formal/solver.ts +235 -0
- package/src/verify/formal/spec-language.ts +274 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/policy.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — Per-axiom policy + consumer mode resolution.
|
|
5
|
+
*
|
|
6
|
+
* The policy layer maps a 4-state {@link FormalVerifyResult} to an action
|
|
7
|
+
* (proceed / block / escalate / log), parameterised by :
|
|
8
|
+
* - the axiom (Robuste, Institutionnel, … — each has different sensitivity)
|
|
9
|
+
* - the consumer mode (strict / permissive / audit_only)
|
|
10
|
+
* - the calling context (runtime vs skill_ingestion — see Tension Sprint C)
|
|
11
|
+
*
|
|
12
|
+
* Tension Sprint C : skill-loop ingestion is ALWAYS strict on UNKNOWN.
|
|
13
|
+
* Even if the runtime policy says "proceed_with_log" on UNKNOWN for the
|
|
14
|
+
* Profitable axiom, the skill-ingestion path must refuse to ingest the
|
|
15
|
+
* skill until UNKNOWN becomes SAFE. This prevents UNKNOWN-tainted skills
|
|
16
|
+
* from accumulating in the skill library.
|
|
17
|
+
*
|
|
18
|
+
* @module verify/formal/policy
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Default per-axiom policies.
|
|
22
|
+
*
|
|
23
|
+
* Rationale :
|
|
24
|
+
* Robuste / Institutionnel : hard axioms — UNSAFE blocks, UNKNOWN escalates
|
|
25
|
+
* SOTA : UNKNOWN allowed with audit log (SOTA evolves)
|
|
26
|
+
* AntiFragile / Profitable : softer — UNSAFE escalates, UNKNOWN logs
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_POLICIES = {
|
|
29
|
+
Robuste: {
|
|
30
|
+
onSafe: "proceed",
|
|
31
|
+
onUnsafe: "block",
|
|
32
|
+
onUnknown: "escalate_human",
|
|
33
|
+
timeout_ms: 5000,
|
|
34
|
+
skillLoopStrict: true,
|
|
35
|
+
},
|
|
36
|
+
Institutionnel: {
|
|
37
|
+
onSafe: "proceed",
|
|
38
|
+
onUnsafe: "block",
|
|
39
|
+
onUnknown: "escalate_human",
|
|
40
|
+
timeout_ms: 10_000,
|
|
41
|
+
skillLoopStrict: true,
|
|
42
|
+
},
|
|
43
|
+
SOTA: {
|
|
44
|
+
onSafe: "proceed",
|
|
45
|
+
onUnsafe: "escalate_human",
|
|
46
|
+
onUnknown: "proceed_with_audit_log",
|
|
47
|
+
timeout_ms: 2000,
|
|
48
|
+
skillLoopStrict: true,
|
|
49
|
+
},
|
|
50
|
+
AntiFragile: {
|
|
51
|
+
onSafe: "proceed",
|
|
52
|
+
onUnsafe: "escalate_human",
|
|
53
|
+
onUnknown: "proceed_with_log",
|
|
54
|
+
timeout_ms: 1000,
|
|
55
|
+
skillLoopStrict: true,
|
|
56
|
+
},
|
|
57
|
+
Profitable: {
|
|
58
|
+
onSafe: "proceed",
|
|
59
|
+
onUnsafe: "escalate_human",
|
|
60
|
+
onUnknown: "proceed_with_log",
|
|
61
|
+
timeout_ms: 1000,
|
|
62
|
+
skillLoopStrict: true,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Whether an axiom is in the "hard" set (Robuste, Institutionnel) whose
|
|
67
|
+
* UNSAFE outcomes are non-negotiable.
|
|
68
|
+
*/
|
|
69
|
+
function isHardAxiom(axiom) {
|
|
70
|
+
return axiom === "Robuste" || axiom === "Institutionnel";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Apply the policy + mode + context to a single verification result.
|
|
74
|
+
*
|
|
75
|
+
* Decision order :
|
|
76
|
+
* 1. SKIPPED → log
|
|
77
|
+
* 2. skill_ingestion + UNKNOWN → block (Tension Sprint C)
|
|
78
|
+
* 3. mode = audit_only → log
|
|
79
|
+
* 4. mode = permissive + UNKNOWN → log (treated as SKIPPED)
|
|
80
|
+
* 5. mode = permissive + UNSAFE + non-hard axiom → log
|
|
81
|
+
* 6. otherwise → policy.on{Safe,Unsafe,Unknown}
|
|
82
|
+
*/
|
|
83
|
+
export function applyPolicy(result, policy, mode, context) {
|
|
84
|
+
// 1. SKIPPED → log
|
|
85
|
+
if (result.state === "SKIPPED") {
|
|
86
|
+
return {
|
|
87
|
+
action: "log",
|
|
88
|
+
rationale: `Axiom ${result.axiom} verification was skipped (${result.rationale})`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// 2. Tension Sprint C : skill_ingestion + UNKNOWN → block, always.
|
|
92
|
+
if (context === "skill_ingestion" && result.state === "UNKNOWN") {
|
|
93
|
+
return {
|
|
94
|
+
action: "block",
|
|
95
|
+
rationale: `Skill ingestion refuses UNKNOWN on axiom ${result.axiom} ` +
|
|
96
|
+
`(Tension Sprint C : skill-loop is always strict on UNKNOWN)`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// 3. audit_only never blocks.
|
|
100
|
+
if (mode === "audit_only") {
|
|
101
|
+
return {
|
|
102
|
+
action: "log",
|
|
103
|
+
rationale: `audit_only mode : axiom ${result.axiom} = ${result.state}`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// SAFE is always proceed.
|
|
107
|
+
if (result.state === "SAFE") {
|
|
108
|
+
return {
|
|
109
|
+
action: "proceed",
|
|
110
|
+
rationale: `Axiom ${result.axiom} proved SAFE in ${result.time_ms.toFixed(0)}ms`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// 4 + 5. Permissive softening.
|
|
114
|
+
if (mode === "permissive") {
|
|
115
|
+
if (result.state === "UNKNOWN") {
|
|
116
|
+
return {
|
|
117
|
+
action: "log",
|
|
118
|
+
rationale: `permissive mode : UNKNOWN on axiom ${result.axiom} treated as ` +
|
|
119
|
+
`non-blocking (${result.rationale})`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (result.state === "UNSAFE" && !isHardAxiom(result.axiom)) {
|
|
123
|
+
return {
|
|
124
|
+
action: "log",
|
|
125
|
+
rationale: `permissive mode : UNSAFE on soft axiom ${result.axiom} downgraded ` +
|
|
126
|
+
`to log (${result.rationale})`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// UNSAFE on hard axiom : fall through to strict policy.
|
|
130
|
+
}
|
|
131
|
+
// 6. Strict policy resolution.
|
|
132
|
+
if (result.state === "UNSAFE") {
|
|
133
|
+
return {
|
|
134
|
+
action: policy.onUnsafe,
|
|
135
|
+
rationale: `UNSAFE on axiom ${result.axiom} : ${policy.onUnsafe} ` +
|
|
136
|
+
`(counterexample : ${result.counterexample ?? "n/a"})`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// result.state === "UNKNOWN" (runtime context only)
|
|
140
|
+
switch (policy.onUnknown) {
|
|
141
|
+
case "escalate_human":
|
|
142
|
+
return {
|
|
143
|
+
action: "escalate_human",
|
|
144
|
+
rationale: `UNKNOWN on axiom ${result.axiom} : escalating (${result.rationale})`,
|
|
145
|
+
};
|
|
146
|
+
case "proceed_with_audit_log":
|
|
147
|
+
return {
|
|
148
|
+
action: "log",
|
|
149
|
+
rationale: `UNKNOWN on axiom ${result.axiom} : audit-log proceed (${result.rationale})`,
|
|
150
|
+
};
|
|
151
|
+
case "proceed_with_log":
|
|
152
|
+
default:
|
|
153
|
+
return {
|
|
154
|
+
action: "log",
|
|
155
|
+
rationale: `UNKNOWN on axiom ${result.axiom} : log-proceed (${result.rationale})`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../src/verify/formal/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAqDH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAgC;IAC3D,OAAO,EAAE;QACP,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,OAAO;QACjB,SAAS,EAAE,gBAAgB;QAC3B,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,IAAI;KACtB;IACD,cAAc,EAAE;QACd,MAAM,EAAE,SAAS;Q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MAAM,CAAC,SAAS,EAAE,CAAC;QACzB,KAAK,gBAAgB;YACnB,OAAO;gBACL,MAAM,EAAE,gBAAgB;gBACxB,SAAS,EAAE,oBAAoB,MAAM,CAAC,KAAK,kBAAkB,MAAM,CAAC,SAAS,GAAG;aACjF,CAAC;QACJ,KAAK,wBAAwB;YAC3B,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,oBAAoB,MAAM,CAAC,KAAK,yBAAyB,MAAM,CAAC,SAAS,GAAG;aACxF,CAAC;QACJ,KAAK,kBAAkB,CAAC;QACxB;YACE,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,oBAAoB,MAAM,CAAC,KAAK,mBAAmB,MAAM,CAAC,SAAS,GAAG;aAClF,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/result.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — Z3 formal verification result type.
|
|
5
|
+
*
|
|
6
|
+
* 4-state result discipline:
|
|
7
|
+
* - SAFE : Z3 proved the post-conditions hold under pre-conditions
|
|
8
|
+
* - UNSAFE : Z3 found a counterexample (state where pre-conditions hold
|
|
9
|
+
* but post-conditions are violated)
|
|
10
|
+
* - UNKNOWN : Z3 returned `unknown` (timeout, undecidable, or solver
|
|
11
|
+
* limitation). EXPLICIT — never silently treated as SAFE.
|
|
12
|
+
* - SKIPPED : Verification not run (consumer mode = permissive opt-out,
|
|
13
|
+
* or solver binary unavailable when caller chooses to skip)
|
|
14
|
+
*
|
|
15
|
+
* The distinction between UNKNOWN and SAFE is the core epistemic discipline
|
|
16
|
+
* of this module : we never assert proof when none was produced.
|
|
17
|
+
*
|
|
18
|
+
* @module verify/formal/result
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Discriminated state of a formal verification attempt.
|
|
22
|
+
*/
|
|
23
|
+
export type FormalVerifyState = "SAFE" | "UNSAFE" | "UNKNOWN" | "SKIPPED";
|
|
24
|
+
/**
|
|
25
|
+
* Solver backend identifier — currently only Z3 or `none` (no solver).
|
|
26
|
+
*/
|
|
27
|
+
export type FormalSolver = "z3" | "none";
|
|
28
|
+
/**
|
|
29
|
+
* Result of running a single axiom spec through the formal verifier.
|
|
30
|
+
*
|
|
31
|
+
* `state` : 4-state outcome (see {@link FormalVerifyState})
|
|
32
|
+
* `axiom` : human-readable axiom label (e.g. "Robuste")
|
|
33
|
+
* `rationale` : human-readable explanation of the outcome
|
|
34
|
+
* `witness` : when SAFE, optional UNSAT-core or proof witness string
|
|
35
|
+
* emitted by the solver (informational only)
|
|
36
|
+
* `counterexample` : when UNSAFE, SMT model (variable assignment) that
|
|
37
|
+
* violates the post-conditions
|
|
38
|
+
* `time_ms` : wall-clock time spent in the solver, in milliseconds
|
|
39
|
+
* `solver` : which backend produced the result
|
|
40
|
+
*/
|
|
41
|
+
export interface FormalVerifyResult {
|
|
42
|
+
state: FormalVerifyState;
|
|
43
|
+
axiom: string;
|
|
44
|
+
rationale: string;
|
|
45
|
+
witness?: string;
|
|
46
|
+
counterexample?: string;
|
|
47
|
+
time_ms: number;
|
|
48
|
+
solver: FormalSolver;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/verify/formal/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,iBAAiB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACtB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/result.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — Z3 formal verification result type.
|
|
5
|
+
*
|
|
6
|
+
* 4-state result discipline:
|
|
7
|
+
* - SAFE : Z3 proved the post-conditions hold under pre-conditions
|
|
8
|
+
* - UNSAFE : Z3 found a counterexample (state where pre-conditions hold
|
|
9
|
+
* but post-conditions are violated)
|
|
10
|
+
* - UNKNOWN : Z3 returned `unknown` (timeout, undecidable, or solver
|
|
11
|
+
* limitation). EXPLICIT — never silently treated as SAFE.
|
|
12
|
+
* - SKIPPED : Verification not run (consumer mode = permissive opt-out,
|
|
13
|
+
* or solver binary unavailable when caller chooses to skip)
|
|
14
|
+
*
|
|
15
|
+
* The distinction between UNKNOWN and SAFE is the core epistemic discipline
|
|
16
|
+
* of this module : we never assert proof when none was produced.
|
|
17
|
+
*
|
|
18
|
+
* @module verify/formal/result
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/verify/formal/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/solver.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — Z3 SMT solver wrapper.
|
|
5
|
+
*
|
|
6
|
+
* Strategy : avoid adding `z3-solver` as a hard npm dependency (heavy WASM
|
|
7
|
+
* package, ~5MB) by spawning the `z3` binary as a subprocess and piping
|
|
8
|
+
* SMT-LIB v2 source on stdin. If `z3` is not in PATH, the wrapper degrades
|
|
9
|
+
* gracefully by returning `{ sat: null }` so callers can map that to the
|
|
10
|
+
* UNKNOWN state.
|
|
11
|
+
*
|
|
12
|
+
* This keeps the SDK lean : consumers that want formal verification install
|
|
13
|
+
* `z3` system-wide (apt / brew / scoop). Consumers that do not, get UNKNOWN
|
|
14
|
+
* results and can route them according to their policy.
|
|
15
|
+
*
|
|
16
|
+
* @module verify/formal/solver
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Options accepted by {@link checkSmt}.
|
|
20
|
+
*/
|
|
21
|
+
export interface SolverOptions {
|
|
22
|
+
/** Wall-clock timeout in milliseconds. Defaults to 5000ms. */
|
|
23
|
+
timeout_ms?: number;
|
|
24
|
+
/** Optional path to the z3 binary (defaults to `z3` resolved via PATH). */
|
|
25
|
+
z3_path?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Outcome of a single SMT-LIB check-sat invocation.
|
|
29
|
+
*
|
|
30
|
+
* `sat` : `true` → solver returned `sat` (formula is satisfiable, i.e.
|
|
31
|
+
* a counterexample exists for a violation query)
|
|
32
|
+
* `false` → solver returned `unsat` (no counterexample, the
|
|
33
|
+
* property holds)
|
|
34
|
+
* `null` → solver returned `unknown`, timed out, was not
|
|
35
|
+
* installed, or failed to run
|
|
36
|
+
* `model` : when `sat === true`, the textual SMT-LIB model string emitted
|
|
37
|
+
* by `(get-model)` — useful as a counterexample witness
|
|
38
|
+
* `time_ms` : wall-clock time spent waiting on the solver subprocess
|
|
39
|
+
* `reason` : optional human-readable diagnostic for UNKNOWN / null outcomes
|
|
40
|
+
*/
|
|
41
|
+
export interface SmtCheckResult {
|
|
42
|
+
sat: boolean | null;
|
|
43
|
+
model?: string;
|
|
44
|
+
time_ms: number;
|
|
45
|
+
reason?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Run a single SMT-LIB v2 formula through Z3 and return the satisfiability
|
|
49
|
+
* outcome.
|
|
50
|
+
*
|
|
51
|
+
* Convention : the caller frames the property as a NEGATION (i.e. asserts the
|
|
52
|
+
* conjunction of preconditions AND the negation of the postcondition). Then :
|
|
53
|
+
* - `sat` → counterexample found → property VIOLATED → UNSAFE
|
|
54
|
+
* - `unsat` → no counterexample exists → property HOLDS → SAFE
|
|
55
|
+
* - `unknown` / timeout / missing binary → UNKNOWN
|
|
56
|
+
*
|
|
57
|
+
* The function never throws : transport errors and missing binaries are
|
|
58
|
+
* surfaced via `sat: null` with a `reason` string.
|
|
59
|
+
*/
|
|
60
|
+
export declare function checkSmt(smtFormula: string, options?: SolverOptions): Promise<SmtCheckResult>;
|
|
61
|
+
export declare function isZ3Available(z3Path?: string): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Test-only helper to reset the cached availability probe.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare function __resetZ3AvailabilityCache(): void;
|
|
67
|
+
//# sourceMappingURL=solver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solver.d.ts","sourceRoot":"","sources":["../../../src/verify/formal/solver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID;;;;;;;;;;;;GAYG;AACH,wBAAsB,QAAQ,CAC5B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAmHzB;AAWD,wBAAsB,aAAa,CAAC,MAAM,SAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA8BnE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/solver.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — Z3 SMT solver wrapper.
|
|
5
|
+
*
|
|
6
|
+
* Strategy : avoid adding `z3-solver` as a hard npm dependency (heavy WASM
|
|
7
|
+
* package, ~5MB) by spawning the `z3` binary as a subprocess and piping
|
|
8
|
+
* SMT-LIB v2 source on stdin. If `z3` is not in PATH, the wrapper degrades
|
|
9
|
+
* gracefully by returning `{ sat: null }` so callers can map that to the
|
|
10
|
+
* UNKNOWN state.
|
|
11
|
+
*
|
|
12
|
+
* This keeps the SDK lean : consumers that want formal verification install
|
|
13
|
+
* `z3` system-wide (apt / brew / scoop). Consumers that do not, get UNKNOWN
|
|
14
|
+
* results and can route them according to their policy.
|
|
15
|
+
*
|
|
16
|
+
* @module verify/formal/solver
|
|
17
|
+
*/
|
|
18
|
+
import { spawn } from "node:child_process";
|
|
19
|
+
import { performance } from "node:perf_hooks";
|
|
20
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
21
|
+
/**
|
|
22
|
+
* Run a single SMT-LIB v2 formula through Z3 and return the satisfiability
|
|
23
|
+
* outcome.
|
|
24
|
+
*
|
|
25
|
+
* Convention : the caller frames the property as a NEGATION (i.e. asserts the
|
|
26
|
+
* conjunction of preconditions AND the negation of the postcondition). Then :
|
|
27
|
+
* - `sat` → counterexample found → property VIOLATED → UNSAFE
|
|
28
|
+
* - `unsat` → no counterexample exists → property HOLDS → SAFE
|
|
29
|
+
* - `unknown` / timeout / missing binary → UNKNOWN
|
|
30
|
+
*
|
|
31
|
+
* The function never throws : transport errors and missing binaries are
|
|
32
|
+
* surfaced via `sat: null` with a `reason` string.
|
|
33
|
+
*/
|
|
34
|
+
export async function checkSmt(smtFormula, options = {}) {
|
|
35
|
+
const timeoutMs = options.timeout_ms ?? DEFAULT_TIMEOUT_MS;
|
|
36
|
+
const z3Path = options.z3_path ?? "z3";
|
|
37
|
+
const start = performance.now();
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
let child;
|
|
40
|
+
try {
|
|
41
|
+
child = spawn(z3Path, ["-in", `-T:${Math.ceil(timeoutMs / 1000)}`], {
|
|
42
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
resolve({
|
|
47
|
+
sat: null,
|
|
48
|
+
time_ms: performance.now() - start,
|
|
49
|
+
reason: `z3 spawn failed : ${err instanceof Error ? err.message : String(err)}`,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let stdout = "";
|
|
54
|
+
let stderr = "";
|
|
55
|
+
let settled = false;
|
|
56
|
+
const settle = (r) => {
|
|
57
|
+
if (settled)
|
|
58
|
+
return;
|
|
59
|
+
settled = true;
|
|
60
|
+
resolve(r);
|
|
61
|
+
};
|
|
62
|
+
const timer = setTimeout(() => {
|
|
63
|
+
try {
|
|
64
|
+
child.kill("SIGKILL");
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* ignored */
|
|
68
|
+
}
|
|
69
|
+
settle({
|
|
70
|
+
sat: null,
|
|
71
|
+
time_ms: performance.now() - start,
|
|
72
|
+
reason: `z3 timeout after ${timeoutMs}ms`,
|
|
73
|
+
});
|
|
74
|
+
}, timeoutMs);
|
|
75
|
+
child.stdout.on("data", (chunk) => {
|
|
76
|
+
stdout += chunk.toString();
|
|
77
|
+
});
|
|
78
|
+
child.stderr.on("data", (chunk) => {
|
|
79
|
+
stderr += chunk.toString();
|
|
80
|
+
});
|
|
81
|
+
child.on("error", (err) => {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
settle({
|
|
84
|
+
sat: null,
|
|
85
|
+
time_ms: performance.now() - start,
|
|
86
|
+
reason: `z3 not available : ${err.message}`,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
child.on("close", (code) => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
const time_ms = performance.now() - start;
|
|
92
|
+
// z3 exits 0 even on `unsat`; non-zero usually means parse error.
|
|
93
|
+
const out = stdout.trim();
|
|
94
|
+
const firstLine = out.split(/\r?\n/)[0]?.trim() ?? "";
|
|
95
|
+
if (firstLine === "sat") {
|
|
96
|
+
// Extract model block if present (everything after the first line).
|
|
97
|
+
const modelStart = out.indexOf("\n");
|
|
98
|
+
const model = modelStart >= 0 ? out.slice(modelStart + 1).trim() : undefined;
|
|
99
|
+
settle({ sat: true, model: model || undefined, time_ms });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (firstLine === "unsat") {
|
|
103
|
+
settle({ sat: false, time_ms });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (firstLine === "unknown") {
|
|
107
|
+
settle({
|
|
108
|
+
sat: null,
|
|
109
|
+
time_ms,
|
|
110
|
+
reason: "z3 returned unknown (likely timeout or undecidable fragment)",
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Parse error or other failure : surface stderr.
|
|
115
|
+
settle({
|
|
116
|
+
sat: null,
|
|
117
|
+
time_ms,
|
|
118
|
+
reason: `z3 unexpected output (exit ${code}) : ${(stderr || out).slice(0, 200)}`,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
child.stdin.write(smtFormula);
|
|
123
|
+
child.stdin.end();
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
settle({
|
|
128
|
+
sat: null,
|
|
129
|
+
time_ms: performance.now() - start,
|
|
130
|
+
reason: `z3 stdin write failed : ${err instanceof Error ? err.message : String(err)}`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Probe : check whether a usable `z3` binary is reachable.
|
|
137
|
+
* Returns `true` if `z3 --version` exits 0 within 1s.
|
|
138
|
+
*
|
|
139
|
+
* Cached for the lifetime of the process — the binary's presence does not
|
|
140
|
+
* change at runtime.
|
|
141
|
+
*/
|
|
142
|
+
let z3Available;
|
|
143
|
+
export async function isZ3Available(z3Path = "z3") {
|
|
144
|
+
if (z3Available !== undefined)
|
|
145
|
+
return z3Available;
|
|
146
|
+
z3Available = await new Promise((resolve) => {
|
|
147
|
+
let child;
|
|
148
|
+
try {
|
|
149
|
+
child = spawn(z3Path, ["--version"], {
|
|
150
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
resolve(false);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const t = setTimeout(() => {
|
|
158
|
+
try {
|
|
159
|
+
child.kill("SIGKILL");
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
/* ignored */
|
|
163
|
+
}
|
|
164
|
+
resolve(false);
|
|
165
|
+
}, 1000);
|
|
166
|
+
child.on("error", () => {
|
|
167
|
+
clearTimeout(t);
|
|
168
|
+
resolve(false);
|
|
169
|
+
});
|
|
170
|
+
child.on("close", (code) => {
|
|
171
|
+
clearTimeout(t);
|
|
172
|
+
resolve(code === 0);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
return z3Available;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Test-only helper to reset the cached availability probe.
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
181
|
+
export function __resetZ3AvailabilityCache() {
|
|
182
|
+
z3Available = undefined;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=solver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solver.js","sourceRoot":"","sources":["../../../src/verify/formal/solver.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CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,WAAW,GAAG,SAAS,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/formal/spec-language.ts
|
|
3
|
+
*
|
|
4
|
+
* Sprint-587 — DSL for axiom specifications, compiled to SMT-LIB v2.
|
|
5
|
+
*
|
|
6
|
+
* Design philosophy (inspired by FormalJudge, arXiv:2602.11136) : agent-cycle
|
|
7
|
+
* properties are expressed as small, typed pre/post-condition tuples. Each
|
|
8
|
+
* condition is mapped to an SMT-LIB fragment by {@link compileToSmt}, which
|
|
9
|
+
* frames the property as a NEGATION of the post-conditions under the
|
|
10
|
+
* pre-conditions. This way, Z3 returning `sat` means a counterexample exists
|
|
11
|
+
* (= UNSAFE) and `unsat` means the post-conditions hold (= SAFE).
|
|
12
|
+
*
|
|
13
|
+
* Bound types : Reals for budgets and ratios, Bools for binary properties,
|
|
14
|
+
* Sets-as-symbols for scope subset checks.
|
|
15
|
+
*
|
|
16
|
+
* @module verify/formal/spec-language
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* One verifiable axiom-level property.
|
|
20
|
+
*/
|
|
21
|
+
export interface AxiomSpec {
|
|
22
|
+
/** Human-readable axiom label (e.g. "Robuste", "Profitable"). */
|
|
23
|
+
axiom: string;
|
|
24
|
+
/** Conditions that must hold for the spec to be meaningful. */
|
|
25
|
+
preconditions: Condition[];
|
|
26
|
+
/** Conditions whose conjunction defines the post-state to verify. */
|
|
27
|
+
postconditions: Condition[];
|
|
28
|
+
/** Solver timeout in ms — see {@link DEFAULT_POLICIES}. */
|
|
29
|
+
timeout_ms?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tagged union of all supported condition kinds.
|
|
33
|
+
*
|
|
34
|
+
* `custom_smt` is the escape hatch : the consumer supplies a raw SMT-LIB
|
|
35
|
+
* fragment that will be inlined under an `(assert ...)`. Use sparingly —
|
|
36
|
+
* mistakes here are silent semantic bugs.
|
|
37
|
+
*/
|
|
38
|
+
export type Condition = {
|
|
39
|
+
type: "budget_constraint";
|
|
40
|
+
child_max_fraction: number;
|
|
41
|
+
} | {
|
|
42
|
+
type: "scope_subset";
|
|
43
|
+
parent_scope: string[];
|
|
44
|
+
child_scope: string[];
|
|
45
|
+
} | {
|
|
46
|
+
type: "no_pii_in_output";
|
|
47
|
+
pii_count_var?: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "cost_positive_roi";
|
|
50
|
+
min_roi_ratio: number;
|
|
51
|
+
} | {
|
|
52
|
+
type: "response_time";
|
|
53
|
+
max_ms: number;
|
|
54
|
+
} | {
|
|
55
|
+
type: "custom_smt";
|
|
56
|
+
smt_fragment: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Compile an {@link AxiomSpec} into an SMT-LIB v2 program string.
|
|
60
|
+
*
|
|
61
|
+
* Pattern : preconditions are asserted as-is ; postconditions are joined by
|
|
62
|
+
* conjunction and asserted NEGATED. A counterexample (z3 returns `sat`)
|
|
63
|
+
* therefore means : "pre-conditions hold AND at least one post-condition
|
|
64
|
+
* fails" — i.e. an UNSAFE outcome.
|
|
65
|
+
*
|
|
66
|
+
* Includes `(check-sat)` and `(get-model)` as terminating commands.
|
|
67
|
+
*/
|
|
68
|
+
export declare function compileToSmt(spec: AxiomSpec): string;
|
|
69
|
+
/**
|
|
70
|
+
* Default per-axiom AxiomSpec presets. Consumers can override the timeout
|
|
71
|
+
* or augment with additional conditions before passing to `formalVerify`.
|
|
72
|
+
*
|
|
73
|
+
* Robuste : 5s — engineering robustness, may need richer checks
|
|
74
|
+
* Institutionnel : 10s — strongest spec, PII + scope-subset + budget
|
|
75
|
+
* SOTA : 2s — lightweight (single ROI check on cost)
|
|
76
|
+
* AntiFragile : 1s — response-time bound only
|
|
77
|
+
* Profitable : 1s — cost-vs-value ROI check
|
|
78
|
+
*/
|
|
79
|
+
export declare const AXIOM_SPECS: Record<string, AxiomSpec>;
|
|
80
|
+
//# sourceMappingURL=spec-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec-language.d.ts","sourceRoot":"","sources":["../../../src/verify/formal/spec-language.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,qEAAqE;IACrE,cAAc,EAAE,SAAS,EAAE,CAAC;IAC5B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAiGjD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAoEpD;AAMD;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAqCjD,CAAC"}
|