moonflow

    Generic durable orchestration engine for Moon Suite

    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    39

    #MoonFlow

    Platform · local alpha orchestration engine. Read the product contract for the non-agent boundary, adapter requirements, recovery model and release gates.

    MoonFlow is Moon Suite's generic durable orchestration capability and engine.

    The governed reinforcement and capability-activation loop is documented in docs/REINFORCEMENT_CAPABILITY_LOOP.md. The executable ownership boundaries and pure test seams are documented in docs/RESPONSIBILITY_AND_TESTABILITY.md. MoonClaw is the suite's single agent runtime: it owns the model loop, personas, reasoning lifecycle, and agent execution, and may call MoonFlow to durably advance declared work. MoonBook owns source intent; MoonFlow imports a versioned Work graph, preserves its source linkage, evaluates dependencies, records attempts and evidence, and projects recoverable orchestration state.

    MoonFlow is not an agent and does not have a model loop, persona, autonomous reasoning lifecycle, or self-scheduling behavior. Its library and command-line surfaces perform explicit orchestration operations when invoked by MoonClaw or an operator/developer.

    #Constitutional boundary

    • MoonFlow advances durable orchestration for declared intent when invoked; it does not author MoonBook goals or independently decide to run work.
    • MoonFlow owns run events, attempts, policy decisions, and recovery state.
    • Product adapters own their domain effects and return typed receipts.
    • MoonTown may propose work but cannot mark MoonFlow items complete.
    • Physical effects always require separately granted physical authority.

    #Event stream v3

    moonflow.event-stream.v3 adds governed checkpoint reuse without weakening the fresh execution contract. A Work graph must provide:

    • book_id, declaration_revision, and source_digest;
    • a unique declaration_id for every Work item;
    • canonical requested_authority values;
    • non-empty acceptance_criteria;
    • known, acyclic dependencies.

    The importer fails closed instead of creating permanently waiting work when a dependency is unknown or cyclic. Every event carries the immutable source context, so replay rejects events from a different book revision or digest.

    Canonical authority classes are observe, cognitive-maintenance, sandbox-execution, workspace-mutation, external-effect, and physical-effect.

    #Adapter contract

    The adapter boundary records capability, request, attempt, idempotency key, input digest, requested authority, external job identity, terminal status, output digest, artifacts, error classification, and compensability. Production adapters must support reconciliation. Result import fails closed when request, attempt, idempotency, or product identity differs.

    Capability records also declare health, operations, authority classes, input/output contracts, and a claim ceiling. The director selects an adapter only when all dimensions match. Unknown outcomes reconcile before any retry; quality rejection revises the input or procedure instead of repeating it.

    For cross-product execution, capability truth is compiled instead of hand-authored. A moonflow.capability-source-bundle.v1 combines the product-owned pack.json, a version-bound adapter declaration, and expiring health evidence. It produces canonical operation identities such as moonmold/spatial.operation.execute@0.2.0 and versioned schema identities. The existing director consumes that catalog directly. Graph compilation fails closed on phantom products, invented/unversioned operations, schema or authority drift, unhealthy adapters, and claims above the declared ceiling. Dispatch and unattended execution re-evaluate the health validity window at their recorded execution time. See docs/CAPABILITY_TRUTH.md.

    Ready Work items that require a pack-owned operator surface use the generic, digest-bound receiver loop documented in docs/OPERATOR_RECEIVER_LOOP.md. It carries run, attempt, operation, input, evidence, authority, and review identity into a configured manifest entrypoint and accepts only a correlated durable receipt. An accepted receipt advances the existing event stream and unlocks declared dependencies; it does not create another runtime.

    prepare-next removes hand-authored dispatch requests. It derives each ready item's requirement from its MoonBook execution binding, selects a healthy compatible adapter, verifies and hashes the declared input artifacts, writes a durable decision/request pair, and submits the attempt event. A rejected selection is retained as a decision receipt and does not start work. complete-artifacts performs the symmetric return path for local adapters: it verifies workspace-relative output artifacts, derives their aggregate digest, materializes the typed result receipt, and reconciles it into review state.

    #Native revision and evidence lineage

    revise-run creates a child run and never rewrites its parent. It reuses an accepted checkpoint only when declaration identity, owner, authority, acceptance criteria, evidence identity, and every dependency revalidate. Changed checkpoints are explicitly marked invalidated in a moonflow.run-migration.v1 receipt. Reuse is represented by a durable checkpoint-reused event and remains distinct from new execution.

    bundle-evidence reads a workspace-relative descriptor, verifies every source before mutation, hashes and stores immutable content-addressed objects, writes a manifest, and verifies workspace containment again after mutation. The command removes manual copying and hash transcription while retaining producer, contract, claim, and result provenance.

    #CLI

    The CLI is an operator/developer surface for inspecting, driving, and diagnosing the engine. It is not a separate agent process or agent runtime.

    moonflow import-graph <workspace> <graph.json> moonflow status <workspace> <run-id> moonflow transition <workspace> <run-id> <work-item-id> <action> <recorded-at> [detail] moonflow advance <workspace> <run-id> <recorded-at> moonflow submit-attempt <workspace> <run-id> <request.json> moonflow reconcile-attempt <workspace> <run-id> <result.json> moonflow review-outcome <workspace> <run-id> <workspace-relative-review-receipt> moonflow revise-run <workspace> <parent-run-id> <child-graph-artifact> <proposal-artifact> <migration-id> <recorded-at> moonflow select-adapter <workspace> <capabilities-artifact> <requirement-artifact> moonflow prepare-next <workspace> <run-id> <capabilities-artifact> <recorded-at> moonflow complete-artifacts <workspace> <run-id> <work-item-id> <recorded-at> <artifact>... moonflow bundle-evidence <workspace> <bundle-spec-artifact> <recorded-at> moonflow run-unattended <workspace> <graph-artifact> <capabilities-artifact> <manifest-artifact> <envelope-artifact> <usage-artifact> <recorded-at> moonflow validate-capability <capability.json> moonflow compile-capability-catalog <source-bundle.json> moonflow validate-work-graph-capabilities <graph.json> <catalog.json> <evaluated-at> moonflow import-conformant-graph <workspace> <graph.json> <catalog.json> <evaluated-at> moonflow receive-operator-receipt <workspace> <run-id> <handoff-token> <submission-artifact> moonflow recover-operator-receipts <workspace> <run-id> moonflow operator-receiver-status <workspace> <run-id> <handoff-token>

    run-unattended requires a v3 manifest. Every attempt is authorized by MoonGate before execution, its declared artifacts are digest-verified, a distinct product attestor must turn the isolated agent draft into a separately declared final artifact, and an independent reviewer must decide the immutable criteria against that product-owned final path. Durable request, draft result, attestation, and review receipts are recovery checkpoints: restarting after any one of them does not repeat completed work or create a second attempt.

    Install the cross-product unattended runtime reproducibly instead of copying development build paths into a manifest:

    scripts/install_moonsuite_runtime.sh ~/moonsuite

    The installer builds the owning products, installs only runtime executables under ~/moonsuite/bin, and writes a content-addressed source/binary manifest at ~/moonsuite/.moonsuite/runtime/installed-runtime.json. Set MOON_SUITE_SOURCE_ROOT only when the source repositories are not sibling directories under ~/Workspace.

    The restart invariant is fault-injected at all three post-action boundaries:

    python3 scripts/unattended_recovery_smoke.py harness \ _build/native/debug/build/cmd/main/main.exe

    The first three launches are deliberately killed after result, product attestation, and review persistence. The fourth resumes to accepted state and the fifth proves terminal duplicate delivery is a no-op. The smoke test also requires an unattended-qualified intervention scorecard and exactly one attempt identity.

    #Ordered HTTP JSON transport

    The operator/developer CLI includes one domain-neutral transport utility for transferring selected top-level fields from a fetched JSON object in a declared order. The utility performs no reasoning and does not create an agent loop:

    moon run cmd/main -- ordered-http-json \ fixtures/ordered-http-json.config.json \ /path/to/new-receipt.json

    The configuration contract is moonflow.ordered_http_json.v2:

    { "contract_version": "moonflow.ordered_http_json.v2", "transfer_id": "example-ordered-transfer-v1", "source_url": "http://127.0.0.1:4100/api/bundles/example", "expected_source_digest": "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "max_response_bytes": 1048576, "max_attempts": 3, "retry_delay_ms": 250, "steps": [ {"field": "record", "destination_url": "http://127.0.0.1:4200/api/ingress/records"}, {"field": "envelope", "destination_url": "http://127.0.0.1:4200/api/ingress/envelopes"} ] }

    The transport performs exactly one GET, requires its raw response digest to match expected_source_digest, requires a top-level JSON object, and then serializes and POSTs each configured field in array order. It accepts no header, token, secret, cookie, username, password, query, or fragment configuration. Every response is streamed under max_response_bytes, must be UTF-8 JSON with a 2xx status, and must not carry a generic error signal (error, non-empty errors, or false ok, success, or accepted).

    Each POST is retried at most max_attempts times with retry_delay_ms between failures. Every attempt for one step carries the same Idempotency-Key, derived only from the transfer ID, step ordinal, selected field, destination, and exact request digest. Re-running the same immutable transfer therefore uses the same keys; changing the source bytes, payload, destination, or order changes them.

    On complete success the command refuses to overwrite the receipt path, writes one compact canonical receipt with mode 0600, and prints the same value. The receipt binds the source response digest and every ordered request body, destination, idempotency key, attempt count, status, and exact raw response digest; receipt_digest hashes the canonical receipt core. A failed step stops later steps and emits no success receipt. Because later steps cannot start until the prior step returns a successful JSON receipt, record followed by envelope in the configuration is a strict delivery boundary. See fixtures/ordered-http-json.config.schema.json for the strict schema.

    Adapter success moves Work to review; it never implies acceptance. The only CLI acceptance path is review-outcome, whose typed receipt must match the persisted run, declaration, result, attempt, and output digest, review every original criterion in order, and cite evidence already attached to the Work item.

    If execution reveals that a criterion belongs to the wrong product, MoonBook compiles a new declaration revision and revise-run performs checkpoint migration. The old event history remains unchanged; invalid evidence is never reinterpreted in place.

    All durable orchestration state is stored under <workspace>/.moonsuite/products/moonflow/runs/<run-id>. Artifact transitions accept only existing workspace-relative paths and reject canonical path escape.

    #Verification

    moon check --target native --deny-warn moon test --target native --deny-warn moon info moon fmt

    AcceptanceReviewError

    pub(all) suberror AcceptanceReviewError {
    InvalidAcceptanceReview(Array[String])
    AcceptanceReviewItemUnavailable(String)
    AcceptanceReviewIdentityMismatch(field~ : String, expected~ : String, actual~ : String)
    AcceptanceReviewConflict(String)
    } derive(Eq, ToJson,
    Debug
    )

    AdapterContractError

    pub(all) suberror AdapterContractError {
    InvalidAdapterRequest(Array[String])
    InvalidAdapterResult(Array[String])
    AdapterIdentityMismatch(field~ : String, expected~ : String, actual~ : String)
    AdapterRuntimeItemUnavailable(String)
    AdapterRuntimeItemNotReady(item_id~ : String, status~ : String)
    AdapterAttemptUnavailable(String)
    AdapterReceiptConflict(String)
    } derive(Eq, ToJson,
    Debug
    )

    FlowError

    pub(all) suberror FlowError {
    EmptyEventId
    EmptyRunId
    InvalidSequence(expected~ : Int, actual~ : Int)
    ConflictingDuplicateEvent(String)
    RunIdMismatch(expected~ : String, actual~ : String)
    MissingWorkItem(String)
    DuplicateWorkItem(String)
    InvalidTransition(item_id~ : String, from~ : String, event~ : String)
    DependencyNotAccepted(item_id~ : String, dependency_id~ : String)
    MissingArtifactId(String)
    MissingAuthorityId(String)
    MissingRunSource(String)
    MissingDeclarationId(String)
    MissingAcceptanceCriteria(String)
    InvalidAuthority(item_id~ : String, authority~ : String)
    SourceContextMismatch(field~ : String, expected~ : String, actual~ : String)
    MissingAttemptField(item_id~ : String, field~ : String)
    AttemptIdentityMismatch(item_id~ : String, expected~ : String, actual~ : String)
    UnsupportedAttemptStatus(item_id~ : String, status~ : String)
    MissingAcceptanceReview(String)
    MissingAcceptanceReviewField(item_id~ : String, field~ : String)
    } derive(Eq, ToJson,
    Debug
    )

    AcceptanceCriterionReview

    pub(all) struct AcceptanceCriterionReview {
    criterion : String
    satisfied : Bool
    evidence_refs : Array[String]
    note : String
    } derive(Eq, ToJson,
    Debug
    )

    AcceptanceReviewReceipt

    pub(all) struct AcceptanceReviewReceipt {
    contract_id : String
    review_id : String
    run_id : String
    work_item_id : String
    declaration_id : String
    result_id : String
    attempt_id : String
    output_digest : String
    decision : String
    criteria : Array[AcceptanceCriterionReview]
    reviewer_id : String
    review_authority_id : String
    receipt_artifact : String
    recorded_at : String
    } derive(Eq, ToJson,
    Debug
    )

    AcceptanceReviewReceipt::quality_issues

    fn AcceptanceReviewReceipt::quality_issues(self : AcceptanceReviewReceipt) -> Array[String]

    AdapterAttemptStatus

    pub(all) enum AdapterAttemptStatus {
    Submitted
    Running
    Succeeded
    Failed
    Cancelled
    Unknown
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    AdapterAttemptStatus::id

    AdapterAttemptStatus::is_terminal

    fn AdapterAttemptStatus::is_terminal(self : AdapterAttemptStatus) -> Bool

    AdapterCapability

    pub(all) struct AdapterCapability {
    adapter_id : String
    product_id : String
    protocol : String
    operations : Array[String]
    authority_classes : Array[String]
    input_contracts : Array[String]
    output_contracts : Array[String]
    claim_ceiling : String
    healthy : Bool
    supports_cancel : Bool
    supports_reconcile : Bool
    } derive(Eq, ToJson,
    Debug
    )

    AdapterCapability::quality_issues

    fn AdapterCapability::quality_issues(self : AdapterCapability) -> Array[String]

    AdapterDeclarationV1

    pub(all) struct AdapterDeclarationV1 {
    contract_id : String
    adapter_id : String
    product_id : String
    pack_id : String
    pack_version : String
    protocol : String
    operations : Array[AdapterOperationDeclarationV1]
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    AdapterHealthAttestationV1

    pub(all) struct AdapterHealthAttestationV1 {
    contract_id : String
    adapter_id : String
    product_id : String
    pack_id : String
    pack_version : String
    protocol : String
    status : String
    checked_at : String
    valid_until : String
    operation_refs : Array[String]
    evidence_ref : String
    evidence_digest : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    AdapterOperationDeclarationV1

    pub(all) struct AdapterOperationDeclarationV1 {
    operation_id : String
    claim_ceiling : String
    supports_cancel : Bool
    supports_reconcile : Bool
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    AdapterRequest

    pub(all) struct AdapterRequest {
    request_id : String
    run_id : String
    book_id : String
    work_item_id : String
    declaration_id : String
    attempt_id : String
    idempotency_key : String
    product_id : String
    operation : String
    requested_authority : String
    acceptance_criteria : Array[String]
    input_contracts : Array[String]
    output_contracts : Array[String]
    required_claim : String
    input_digest : String
    input_artifacts : Array[String]
    timeout_ms : Int
    created_at : String
    } derive(Eq, ToJson,
    Debug
    )

    AdapterRequest::quality_issues

    fn AdapterRequest::quality_issues(self : AdapterRequest) -> Array[String]

    AdapterResult

    pub(all) struct AdapterResult {
    result_id : String
    request_id : String
    attempt_id : String
    idempotency_key : String
    product_id : String
    external_job_id : String
    status : AdapterAttemptStatus
    output_digest : String
    output_artifacts : Array[String]
    error_kind : String
    compensable : Bool
    recorded_at : String
    } derive(Eq, ToJson,
    Debug
    )

    AdapterResult::quality_issues

    fn AdapterResult::quality_issues(self : AdapterResult) -> Array[String]

    CapabilityActivationProjectionV1

    pub(all) struct CapabilityActivationProjectionV1 {
    contract_version : String
    activation_id : String
    request : CapabilityRecordRefV1
    receipt : CapabilityRecordRefV1
    scope_id : String
    rollout_mode : String
    status : String
    challenger_participant_ids : Array[String]
    max_observations : Int
    experiment : CapabilityRecordRefV1
    old_capability : CapabilityRecordRefV1
    new_capability : CapabilityRecordRefV1
    rollback : CapabilityRecordRefV1
    activation_review : CapabilityRecordRefV1
    activation_reviewer_id : String
    activation_reviewer_authority_ref : String
    activated_at : Int64
    observations : Array[CapabilityObservationV1]
    settlement : CapabilitySettlementRequestV1?
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityActivationProjectionV1::record_observation

    CapabilityActivationRequestV1

    pub(all) struct CapabilityActivationRequestV1 {
    contract_version : String
    request : CapabilityRecordRefV1
    receipt : CapabilityRecordRefV1
    scope_id : String
    rollout_mode : String
    challenger_participant_ids : Array[String]
    max_observations : Int
    experiment : CapabilityRecordRefV1
    old_capability : CapabilityRecordRefV1
    new_capability : CapabilityRecordRefV1
    rollback : CapabilityRecordRefV1
    activation_review : CapabilityRecordRefV1
    activation_reviewer_id : String
    activation_reviewer_authority_ref : String
    requested_at : Int64
    adoption_authorized : Bool
    source_side_effects_applied : Bool
    activation_side_effects_applied : Bool
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityCatalogV1

    pub(all) struct CapabilityCatalogV1 {
    contract_id : String
    catalog_id : String
    compiled_at : String
    conformant : Bool
    products : Array[CapabilityProductV1]
    operations : Array[CapabilityOperationV1]
    issues : Array[CapabilityConformanceIssueV1]
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityCatalogV1::adapter_capabilities

    fn CapabilityCatalogV1::adapter_capabilities(self : CapabilityCatalogV1) -> Array[AdapterCapability]

    CapabilityCatalogV1::adapter_capabilities_at

    fn CapabilityCatalogV1::adapter_capabilities_at(self : CapabilityCatalogV1, evaluated_at : String) -> Array[AdapterCapability] raise

    CapabilityConformanceIssueV1

    pub(all) struct CapabilityConformanceIssueV1 {
    code : String
    subject : String
    detail : String
    suggestions : Array[String]
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityObservationV1

    pub(all) struct CapabilityObservationV1 {
    observation_id : String
    scope_id : String
    participant_id : String
    assignment : String
    capability : CapabilityRecordRefV1
    outcome : CapabilityRecordRefV1
    reward_evidence : CapabilityRecordRefV1
    accepted : Bool
    recorded_at : Int64
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityOperationV1

    pub(all) struct CapabilityOperationV1 {
    operation_ref : String
    product_id : String
    pack_id : String
    pack_version : String
    tool_id : String
    adapter_id : String
    protocol : String
    authority : String
    input_schema_ref : String
    output_schema_ref : String
    claim_ceiling : String
    idempotent : Bool
    review_required : Bool
    supports_cancel : Bool
    supports_reconcile : Bool
    health_checked_at : String
    health_valid_until : String
    health_evidence_ref : String
    health_evidence_digest : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityProductV1

    pub(all) struct CapabilityProductV1 {
    product_id : String
    pack_id : String
    pack_version : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityRecordRefV1

    pub(all) struct CapabilityRecordRefV1 {
    record_id : String
    record_version : String
    record_digest : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilityResolutionV1

    pub(all) struct CapabilityResolutionV1 {
    contract_version : String
    scope_id : String
    participant_id : String
    assignment : String
    selected_capability : CapabilityRecordRefV1
    shadow_capability : CapabilityRecordRefV1?
    activation_id : String
    experiment : CapabilityRecordRefV1
    status : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CapabilitySettlementRequestV1

    pub(all) struct CapabilitySettlementRequestV1 {
    contract_version : String
    settlement_id : String
    scope_id : String
    decision : String
    experiment_outcome : CapabilityRecordRefV1
    reviewer_id : String
    reviewer_authority_ref : String
    review_evidence : CapabilityRecordRefV1
    settled_at : Int64
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    CheckpointMigrationDecision

    pub(all) struct CheckpointMigrationDecision {
    child_work_item_id : String
    source_work_item_id : String
    declaration_id : String
    decision : String
    reason : String
    evidence_refs : Array[String]
    } derive(Eq, ToJson,
    Debug
    )

    DirectorCandidateReview

    pub(all) struct DirectorCandidateReview {
    adapter_id : String
    accepted : Bool
    reasons : Array[String]
    } derive(Eq, ToJson,
    Debug
    )

    DirectorDecision

    pub(all) struct DirectorDecision {
    contract_id : String
    requirement_id : String
    selected_adapter_id : String
    accepted : Bool
    reviews : Array[DirectorCandidateReview]
    } derive(Eq, ToJson,
    Debug
    )

    DirectorFailureClass

    pub(all) enum DirectorFailureClass {
    TransientFailure
    QualityRejection
    AuthorityDenial
    PermanentIncompatibility
    UnknownOutcome
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    DirectorFailureClass::id

    DirectorRequirement

    pub(all) struct DirectorRequirement {
    requirement_id : String
    product_id : String
    operation : String
    requested_authority : String
    input_contracts : Array[String]
    output_contracts : Array[String]
    required_claim : String
    } derive(Eq, ToJson,
    Debug
    )

    DirectorRetryDecision

    pub(all) struct DirectorRetryDecision {
    failure_class : DirectorFailureClass
    action : String
    preserves_attempt_evidence : Bool
    reuses_idempotency_lineage : Bool
    requires_reconciliation : Bool
    } derive(Eq, ToJson,
    Debug
    )

    EventKind

    pub(all) enum EventKind {
    RunCreated
    ItemRegistered
    ItemReady
    ItemStarted
    ItemWaiting
    ItemBlocked
    ItemReviewRequested
    ItemAccepted
    ItemFailed
    ItemCancelled
    ItemSuperseded
    ArtifactAttached
    ApprovalGranted
    AttemptSubmitted
    AttemptReconciled
    CheckpointReused
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    EventKind::id

    fn EventKind::id(self : EventKind) -> String

    EvidenceBundleEntry

    pub(all) struct EvidenceBundleEntry {
    artifact_ref : String
    object_ref : String
    producer_product_id : String
    contract_id : String
    claim_class : String
    result_id : String
    sha256 : String
    size_bytes : Int
    } derive(Eq, ToJson,
    Debug
    )

    EvidenceBundleManifest

    pub(all) struct EvidenceBundleManifest {
    contract_id : String
    bundle_id : String
    content_digest : String
    entries : Array[EvidenceBundleEntry]
    recorded_at : String
    } derive(Eq, ToJson,
    Debug
    )

    EvidenceBundleManifest::quality_issues

    fn EvidenceBundleManifest::quality_issues(self : EvidenceBundleManifest) -> Array[String]

    EvidenceBundleSpec

    pub(all) struct EvidenceBundleSpec {
    contract_id : String
    bundle_id : String
    sources : Array[EvidenceSourceSpec]
    } derive(Eq, ToJson,
    Debug
    )

    EvidenceSourceSpec

    pub(all) struct EvidenceSourceSpec {
    artifact_ref : String
    producer_product_id : String
    contract_id : String
    claim_class : String
    result_id : String
    } derive(Eq, ToJson,
    Debug
    )

    GraphCapabilityBindingV1

    pub(all) struct GraphCapabilityBindingV1 {
    work_item_id : String
    operation_ref : String
    adapter_id : String
    input_schema_ref : String
    output_schema_ref : String
    authority : String
    claim_ceiling : String
    review_required : Bool
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    GraphCapabilityReportV1

    pub(all) struct GraphCapabilityReportV1 {
    contract_id : String
    catalog_id : String
    graph_id : String
    accepted : Bool
    bindings : Array[GraphCapabilityBindingV1]
    issues : Array[CapabilityConformanceIssueV1]
    catalog_issues : Array[CapabilityConformanceIssueV1]
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    PackCapabilityManifestV1

    pub(all) struct PackCapabilityManifestV1 {
    pack_id : String
    product_id : String
    pack_version : String
    schemas : Array[PackSchemaDescriptorV1]
    tools : Array[PackToolDescriptorV1]
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    PackSchemaDescriptorV1

    pub(all) struct PackSchemaDescriptorV1 {
    id : String
    version : String
    path : String
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    PackToolDescriptorV1

    pub(all) struct PackToolDescriptorV1 {
    id : String
    owner_product : String
    input_schema_id : String
    output_schema_id : String
    authority : String
    idempotent : Bool
    review_required : Bool
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    ReconciliationDecision

    pub(all) enum ReconciliationDecision {
    Pending
    ImportSuccess
    ImportFailure
    ImportCancellation
    InvestigateUnknown
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    RunMigrationReceipt

    pub(all) struct RunMigrationReceipt {
    contract_id : String
    migration_id : String
    parent_run_id : String
    child_run_id : String
    parent_revision : String
    child_revision : String
    parent_source_digest : String
    child_source_digest : String
    revision_proposal_ref : String
    decisions : Array[CheckpointMigrationDecision]
    reused_count : Int
    invalidated_count : Int
    new_count : Int
    recorded_at : String
    } derive(Eq, ToJson,
    Debug
    )

    RunMigrationReceipt::quality_issues

    fn RunMigrationReceipt::quality_issues(self : RunMigrationReceipt) -> Array[String]

    RunProjection

    pub(all) struct RunProjection {
    run_id : String
    book_id : String
    declaration_revision : String
    source_digest : String
    last_sequence : Int
    items : Array[RuntimeItem]
    applied_event_ids : Array[String]
    applied_events : Array[RuntimeEvent]
    outcome : String
    } derive(Eq, ToJson,
    Debug
    )

    RunProjection::apply

    fn RunProjection::apply(self : RunProjection, event : RuntimeEvent) -> Unit raise FlowError

    RunProjection::find_item

    fn RunProjection::find_item(self : RunProjection, item_id : String) -> RuntimeItem?

    RunProjection::runnable_item_ids

    fn RunProjection::runnable_item_ids(self : RunProjection) -> Array[String]

    RunRevisionResult

    pub(all) struct RunRevisionResult {
    events : Array[RuntimeEvent]
    receipt : RunMigrationReceipt
    } derive(Eq, ToJson,
    Debug
    )

    RuntimeEvent

    pub(all) struct RuntimeEvent {
    sequence : Int
    event_id : String
    run_id : String
    work_item_id : String
    kind : EventKind
    product_id : String
    declaration_id : String
    book_id : String
    declaration_revision : String
    source_digest : String
    requested_authority : String
    acceptance_criteria : Array[String]
    operation : String
    input_contracts : Array[String]
    output_contracts : Array[String]
    required_claim : String
    input_artifacts : Array[String]
    timeout_ms : Int
    request_id : String
    result_id : String
    attempt_id : String
    idempotency_key : String
    external_job_id : String
    attempt_status : String
    input_digest : String
    output_digest : String
    output_artifacts : Array[String]
    error_kind : String
    compensable : Bool
    depends_on : Array[String]
    detail : String
    artifact_id : String
    authority_id : String
    recorded_at : String
    } derive(Eq, ToJson,
    Debug
    )

    RuntimeItem

    pub(all) struct RuntimeItem {
    work_item_id : String
    declaration_id : String
    product_id : String
    requested_authority : String
    acceptance_criteria : Array[String]
    operation : String
    input_contracts : Array[String]
    output_contracts : Array[String]
    required_claim : String
    input_artifacts : Array[String]
    timeout_ms : Int
    depends_on : Array[String]
    status : RuntimeStatus
    attempt_count : Int
    request_id : String
    result_id : String
    active_attempt_id : String
    idempotency_key : String
    external_job_id : String
    attempt_status : String
    input_digest : String
    output_digest : String
    error_kind : String
    compensable : Bool
    blocker : String
    acceptance_review_id : String
    acceptance_review_artifact : String
    acceptance_reviewer_id : String
    artifacts : Array[String]
    approvals : Array[String]
    } derive(Eq, ToJson,
    Debug
    )

    RuntimeStatus

    pub(all) enum RuntimeStatus {
    Proposed
    Ready
    Active
    Waiting
    Blocked
    Review
    Accepted
    Failed
    Cancelled
    Superseded
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    RuntimeStatus::id

    fn RuntimeStatus::id(self : RuntimeStatus) -> String

    RuntimeStatus::is_terminal

    fn RuntimeStatus::is_terminal(self : RuntimeStatus) -> Bool

    UnattendedDriver

    pub(all) struct UnattendedDriver {
    adapter_id : String
    executable : String
    arguments : Array[String]
    draft_output_artifacts : Array[String]
    expected_output_artifacts : Array[String]
    attestor_id : String
    attestor_executable : String
    attestor_arguments : Array[String]
    reviewer_id : String
    reviewer_executable : String
    reviewer_arguments : Array[String]
    review_authority_id : String
    budget_request :
    AutonomyBudgetUsage

    } derive(Eq,
    Debug
    )

    UnattendedManifest

    pub(all) struct UnattendedManifest {
    contract_id : String
    gate_executable : String
    gate_arguments : Array[String]
    max_cycles : Int
    drivers : Array[UnattendedDriver]
    observer_executable : String
    observer_arguments : Array[String]
    } derive(Eq,
    Debug
    )

    UnattendedManifest::find_driver

    fn UnattendedManifest::find_driver(self : UnattendedManifest, adapter_id : String) -> UnattendedDriver?

    UnattendedManifest::quality_issues

    fn UnattendedManifest::quality_issues(self : UnattendedManifest) -> Array[String]

    acceptance_review_event

    fn acceptance_review_event(projection : RunProjection, receipt : AcceptanceReviewReceipt) -> RuntimeEvent raise AcceptanceReviewError

    activate_capability_v1

    fn activate_capability_v1(request : CapabilityActivationRequestV1, activation_id~ : String, activated_at~ : Int64) -> CapabilityActivationProjectionV1 raise

    adapter_attempt_status_from_id

    fn adapter_attempt_status_from_id(id : String) -> AdapterAttemptStatus raise

    adapter_declaration_contract_v1

    fn adapter_declaration_contract_v1() -> String

    adapter_health_contract_v1

    fn adapter_health_contract_v1() -> String

    adapter_reconciliation_event

    fn adapter_reconciliation_event(projection : RunProjection, result : AdapterResult) -> RuntimeEvent raise AdapterContractError

    adapter_submission_event

    fn adapter_submission_event(projection : RunProjection, request : AdapterRequest) -> RuntimeEvent raise AdapterContractError

    artifact_ref_is_workspace_relative

    fn artifact_ref_is_workspace_relative(artifact_ref : String) -> Bool

    authority_class_is_canonical

    fn authority_class_is_canonical(authority : String) -> Bool

    canonical_authority_classes

    fn canonical_authority_classes() -> Array[String]

    capability_catalog_contract_v1

    fn capability_catalog_contract_v1() -> String

    capability_guarded_events_from_work_graph_v1

    fn capability_guarded_events_from_work_graph_v1(graph : Json, capabilities : Json, evaluated_at : String) -> Array[RuntimeEvent] raise

    capability_loop_contract_version

    fn capability_loop_contract_version() -> String

    Generic activation contract consumed from MoonBook. Domain reward meaning remains opaque to MoonFlow and is carried only through evidence references.

    capability_source_bundle_contract_v1

    fn capability_source_bundle_contract_v1() -> String

    claim_class_rank

    fn claim_class_rank(claim : String) -> Int?

    compile_capability_catalog_v1

    fn compile_capability_catalog_v1(value : Json) -> CapabilityCatalogV1 raise

    compile_work_graph_capabilities_at_v1

    fn compile_work_graph_capabilities_at_v1(graph : Json, catalog : CapabilityCatalogV1, evaluated_at : String) -> GraphCapabilityReportV1 raise

    compile_work_graph_capabilities_v1

    fn compile_work_graph_capabilities_v1(graph : Json, catalog : CapabilityCatalogV1) -> GraphCapabilityReportV1 raise

    conformant_events_from_work_graph_at_v1

    fn conformant_events_from_work_graph_at_v1(graph : Json, catalog : CapabilityCatalogV1, evaluated_at : String) -> Array[RuntimeEvent] raise

    conformant_events_from_work_graph_v1

    fn conformant_events_from_work_graph_v1(graph : Json, catalog : CapabilityCatalogV1) -> Array[RuntimeEvent] raise

    decode_acceptance_review_receipt

    fn decode_acceptance_review_receipt(value : Json) -> AcceptanceReviewReceipt raise

    decode_adapter_capabilities

    fn decode_adapter_capabilities(value : Json) -> Array[AdapterCapability] raise

    decode_adapter_capabilities_at_v1

    fn decode_adapter_capabilities_at_v1(value : Json, evaluated_at : String) -> Array[AdapterCapability] raise

    decode_adapter_capability

    fn decode_adapter_capability(value : Json) -> AdapterCapability raise

    decode_adapter_declaration_v1

    fn decode_adapter_declaration_v1(value : Json) -> AdapterDeclarationV1 raise

    decode_adapter_health_attestation_v1

    fn decode_adapter_health_attestation_v1(value : Json) -> AdapterHealthAttestationV1 raise

    decode_adapter_request

    fn decode_adapter_request(value : Json) -> AdapterRequest raise

    decode_adapter_result

    fn decode_adapter_result(value : Json) -> AdapterResult raise

    decode_capability_activation_projection_v1

    fn decode_capability_activation_projection_v1(value : Json) -> CapabilityActivationProjectionV1 raise

    decode_capability_activation_request_v1

    fn decode_capability_activation_request_v1(value : Json) -> CapabilityActivationRequestV1 raise

    decode_capability_catalog_v1

    fn decode_capability_catalog_v1(value : Json) -> CapabilityCatalogV1 raise

    decode_capability_observation_v1

    fn decode_capability_observation_v1(value : Json) -> CapabilityObservationV1 raise

    decode_capability_settlement_request_v1

    fn decode_capability_settlement_request_v1(value : Json) -> CapabilitySettlementRequestV1 raise

    decode_director_requirement

    fn decode_director_requirement(value : Json) -> DirectorRequirement raise

    decode_event_array

    fn decode_event_array(value : Json) -> Array[RuntimeEvent] raise

    decode_evidence_bundle_spec

    fn decode_evidence_bundle_spec(value : Json) -> EvidenceBundleSpec raise

    decode_pack_capability_manifest_v1

    fn decode_pack_capability_manifest_v1(value : Json) -> PackCapabilityManifestV1 raise

    decode_runtime_event

    fn decode_runtime_event(value : Json) -> RuntimeEvent raise

    decode_unattended_manifest

    fn decode_unattended_manifest(value : Json) -> UnattendedManifest raise

    director_input_artifacts

    fn director_input_artifacts(projection : RunProjection, item : RuntimeItem) -> Array[String]

    director_request_for_item

    fn director_request_for_item(projection : RunProjection, item : RuntimeItem, input_digest : String, recorded_at : String) -> AdapterRequest

    director_requirement_for_item

    fn director_requirement_for_item(item : RuntimeItem) -> DirectorRequirement

    director_retry_decision

    fn director_retry_decision(failure_class : DirectorFailureClass) -> DirectorRetryDecision

    director_success_result_for_item

    fn director_success_result_for_item(item : RuntimeItem, output_digest : String, output_artifacts : Array[String], recorded_at : String) -> AdapterResult

    empty_projection

    fn empty_projection(run_id : String) -> RunProjection

    event_array_json

    fn event_array_json(events : Array[RuntimeEvent]) -> Json

    event_kind_from_id

    fn event_kind_from_id(id : String) -> EventKind raise

    events_from_work_graph

    fn events_from_work_graph(value : Json) -> Array[RuntimeEvent] raise

    evidence_bundle_manifest

    fn evidence_bundle_manifest(spec : EvidenceBundleSpec, entries : Array[EvidenceBundleEntry], content_digest : String, recorded_at : String) -> EvidenceBundleManifest raise

    graph_capability_report_contract_v1

    fn graph_capability_report_contract_v1() -> String

    normalize_workspace_path

    fn normalize_workspace_path(path : String) -> String

    path_is_within_workspace

    fn path_is_within_workspace(workspace_root : String, candidate : String) -> Bool

    product_attestation_issues

    fn product_attestation_issues(value : Json, driver : UnattendedDriver, request : AdapterRequest, result : AdapterResult) -> Array[String]

    product_id

    fn product_id() -> String

    projection_json

    fn projection_json(projection : RunProjection) -> Json

    protocol_id

    fn protocol_id() -> String

    ready_events

    fn ready_events(projection : RunProjection, recorded_at : String) -> Array[RuntimeEvent]

    reconcile_adapter_result

    fn reconcile_adapter_result(request : AdapterRequest, result : AdapterResult) -> ReconciliationDecision raise AdapterContractError

    render_unattended_arguments

    fn render_unattended_arguments(arguments : Array[String], workspace : String, request_artifact : String, result_artifact : String, receipt_artifact : String, review_artifact : String) -> Array[String]

    render_unattended_attestor_arguments

    fn render_unattended_attestor_arguments(arguments : Array[String], workspace : String, request_artifact : String, result_artifact : String, attestation_artifact : String, draft_artifact : String, final_artifact : String) -> Array[String]

    render_unattended_observer_arguments

    fn render_unattended_observer_arguments(arguments : Array[String], workspace : String, run_id : String, book_id : String, projection_path : String, recorded_at : String) -> Array[String]

    replay

    fn replay(run_id : String, events : Array[RuntimeEvent]) -> RunProjection raise FlowError

    resolve_capability_v1

    fn resolve_capability_v1(projection : CapabilityActivationProjectionV1, scope_id~ : String, participant_id~ : String) -> CapabilityResolutionV1 raise

    revise_run

    fn revise_run(parent : RunProjection, child_graph : Json, migration_id : String, revision_proposal_ref : String, recorded_at : String) -> RunRevisionResult raise

    runtime_event_json

    fn runtime_event_json(event : RuntimeEvent) -> Json

    runtime_protocol_id

    fn runtime_protocol_id() -> String

    select_adapter

    fn select_adapter(capabilities : Array[AdapterCapability], requirement : DirectorRequirement) -> DirectorDecision

    validate_adapter_capability

    fn validate_adapter_capability(value : Json) -> AdapterCapability raise AdapterContractError

    versioned_operation_ref

    fn versioned_operation_ref(product_id : String, tool_id : String, pack_version : String) -> String

    versioned_schema_ref

    fn versioned_schema_ref(product_id : String, schema_id : String, schema_version : String) -> String