diff --git a/.github/workflows/ci-gate.yml b/.github/workflows/ci-gate.yml index b760ec4..308088d 100644 --- a/.github/workflows/ci-gate.yml +++ b/.github/workflows/ci-gate.yml @@ -203,6 +203,9 @@ jobs: bash tests/ci_graph_layout_tests.sh bash scripts/prepare_graph_fixture_layout.sh + - name: Install pinned experimental operator host dependencies + run: bash scripts/install_operator_dependencies.sh + - name: Run Dispatch release gate # Full static graph, real-process crash and resource proofs run serially. timeout-minutes: 300 diff --git a/.gitignore b/.gitignore index eee75db..d63a847 100644 --- a/.gitignore +++ b/.gitignore @@ -198,3 +198,5 @@ tests/tmp/* # Reviewed, hash-inventoried proof evidence; ordinary runtime logs stay ignored. !docs/evidence/resource-accounting/*.log + +.operator-deps/ diff --git a/CHANGELOG.md b/CHANGELOG.md index abad761..0793161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ Version source: `kennel.toml`; CLI and `kujo.toml` must agree. Historical releas entries are retained below. Experimental contract versions are independent of Dispatch's version. +## Unreleased — experimental operator rehearsal + +- Add a bounded installed batch-summary operator host with separate inspect, + plan, apply, review and run commands over existing Dispatch control APIs. +- Provide human/JSON output and exact Workcell/Eval dependency setup for the + experimental graph path; retain source-runtime and trusted-host boundaries. +- Add installed-package failure, review, budget and real controller-crash proofs. + ## Unreleased — sourced resources and Eval budgets - Add opt-in graph/node Eval ceilings with locked reservations, durable dispatch diff --git a/README.md b/README.md index 9c03116..3a4d02f 100644 --- a/README.md +++ b/README.md @@ -765,3 +765,6 @@ Finalization does not schedule work, replay effects or change participant author Experimental sourced resource accounting and bounded Eval reservation planning are documented in [the resource contract](docs/contracts/resources/protocol.md). Existing runtime/provider artifacts remain observations; Dispatch owns budget authority. + +For the experimental typed-output, review, Eval and budget path, see the +[operator rehearsal](docs/operator-rehearsal.md). diff --git a/dispatch.kujo b/dispatch.kujo index e72a4e3..dd00056 100644 --- a/dispatch.kujo +++ b/dispatch.kujo @@ -41,6 +41,7 @@ func print_help() { "Usage:", " kujo run dispatch.kujo run \"Research topic\" [--workflow-file workflow.json] [--input-json '{...}'] [--output-root outputs]", " kujo run dispatch.kujo init [--dir dispatch-workflow] [--force]", + " kujo run dispatch.kujo operator --help (experimental local batch host)", " kujo run dispatch.kujo catalog --output model-catalog.json", " kujo run dispatch.kujo webhooks [--output-root outputs] [--url https-url] [--destination lifecycle] [--json]", " kujo run dispatch.kujo demo \"Research topic\" [--workflow research-report] [--policy-profile staging] [--tags prod,project-a] [--yes] [--non-interactive] [--output-root outputs]", @@ -2162,6 +2163,15 @@ while i < len(raw_args) { i := i + 1 } +if command == "operator" { + argv := ["bash", dispatch_root_path("scripts/operator.sh")] + for value in command_args {argv = push(argv, value)} + result := spawn_process(argv, {"inherit_env":true, "timeout_ms":300000, "max_output_bytes":4194304}) + if result.stdout != "" {print(trim(result.stdout))} + if result.stderr != "" {print(trim(result.stderr))} + if result.success == false {exit(1)} + return +} if command == "run"||command == "demo" { run_demo(command_args) return diff --git a/docs/OPERATOR_FIRST_HOUR.md b/docs/OPERATOR_FIRST_HOUR.md new file mode 100644 index 0000000..20a0796 --- /dev/null +++ b/docs/OPERATOR_FIRST_HOUR.md @@ -0,0 +1,78 @@ +# Operator rehearsal: first-hour findings + +Starting points: Dispatch `de66a668a6bceb0b27dd2d4ae97797c969c595c2` and Kujo +`fbaaf244708b9384fcb321e8e6772c6764e21425`. The unrelated primary Kujo checkout was +left untouched; work used isolated branches. This is a factual installation and +operator exercise, not a subjective usability score or a new architecture phase. + +| Category | Observed friction | Classification | Bounded response | +| --- | --- | --- | --- | +| Installation | Default Dispatch manifest names a Kujo source SHA; the installer attempted a nonexistent release for that SHA, then required Cargo in the clean environment. | Required prerequisite insufficiently explicit for binary-only use | Document exact binary manifest, release checksum verification and source-build distinction. Preserve canonical source pin. | +| Setup | The Dispatch package closure installs AI/Agents SDK but not the Workcell/Eval host used by graph proofs. | Required but undocumented | Install two exact experimental dependency archives; no fixture symlinks or inherited module path. | +| Public control | Stable installed `dispatch --help` has no graph operator path. The documented routed-review demo succeeds, but does not exercise graph terminal/resource authority. | Internal-only integration assumption | Add one closed experimental batch host behind `dispatch operator`; retain existing core APIs. | +| Status | An operator would need fixture functions/raw state to join output, review, branch, attempt and resource facts. | Missing explanation surface | Human and versioned JSON report with exact provenance, unknown usage and recovery assessment. | +| State terminology | Newly allocated child runs have a persisted `running` control status before any dispatch. Showing that as process liveness would be misleading. | Confusing terminology | Report control status separately from durable dispatch/result/finalization facts; make no process-liveness claim. | +| Continuation output | The host API returned a 21 KB raw state object for one paused `run`. | Implementation-centric output | Return a small versioned action summary; use `inspect` for the bounded facts/provenance view. | +| Review | Internal examples constructed subject/revision-bound decision JSON. | Command requiring source knowledge | `review` opens an exact request; `plan approve/deny` constructs the candidate; `apply` checks the current OS user and core authority. | +| Recovery | Rehearsal must identify surviving reservations before continuing after a killed controller. | Recovery ambiguity | Expose the existing retained-host plan/apply API; no implicit resume or refund. | +| Error text | Capacity/path/stale-candidate codes lacked a corrective operator action. | Implementation-centric diagnostic | Preserve the exact code and add a bounded next action. Never recommend raw state editing. | + +## Workflow and interfaces + +A bounded integer batch produces a typed summary and one SQLite publication +receipt. H reviews its exact output; E checks the configured expected total. The +existing Eval branch selects B (publication) or R (repair report). Each executable +node retains its own Workcell, effect admission, schema evaluation and parent +finalization. The graph terminal decision is separate. There is no live model. +Graph Eval budgets count explicit E dispatches; the local schema check within a +program's parent contract is not another graph evaluator node. + +Public entrypoints: `dispatch operator init`, `inspect [--json]`, `plan`, `apply`, +`review`, and `run`. Plans name one operation and preserve exact existing revision +and evidence preconditions. Planning a receipt operation is a requested command, +not a guarantee that admission will pass final revalidation. The wrapper's explicit +absolute workspace argument opts into the existing non-default output-root policy. + +The executable black-box proof is `tests/operator_rehearsal.mjs`. It copies only +package files into a new installation, supplies pinned real dependencies, clears +the inherited environment except documented prerequisites, uses a fresh HOME, +and invokes the public launcher from outside the installation. It imports no +internal fixture helpers and never edits control state. Its only low-level access +is read-only hashing and watching immutable record publication to time SIGKILL. +A separate archive installation rehearses the real GitHub installer path. + +## Proof boundaries + +- Happy path: independent program/receipt, human decision, Eval, selected consumer + and graph terminal authority. Exact A digest remains B's input; source input, + review and branch facts remain inspectable. +- Failure: an actual wrong expected total yields failed Eval and the declared R + branch. The failed verdict remains historical; B stays `not_selected`. +- Review: wrong subject and stale revision reject. Approval starts no evaluator + and grants no consumer effect admission. +- Budget: no Eval capacity blocks reservation; a graph already using its last + program/Eval units may still record evidence and finalize. +- Recovery: SIGKILL occurs after immutable reservation publication. A fresh + controller inventories/reconciles surviving facts, retains the reservation and + observes no program admission or output. Ordinary continuation follows. This + operator scenario does not newly claim every lost-reply crash case; the existing + canonical recovery/consumed-attempt suites cover those boundaries. +- Resources: real Eval runtime observation is retained. Process-time partial sums + are not graph elapsed time or CPU. Provider tokens, estimates and money remain + unknown where no source exists; unknown totals are null, not zero. + +## Remaining scope + +This is a supported experimental walkthrough for one installed host, not arbitrary +workflow authoring or a public graph SDK. Trusted local OS/filesystem authority, +static topology, exact installed implementation and surviving local storage are +required. Evidence/preservation expire; this walkthrough does not expose renewal, +unsafe retries, mutable ceilings, remote trust, machine migration or force recovery. +No pricing, dashboard, scheduler, participant wire changes or new language syntax +were added. Workcell and Eval sources were inspected/installed but not modified. + +Freeze the local Wave F architecture lane once canonical verification passes. +Return to product/release work and real user feedback. No additional graph or +resource architecture follows automatically from this rehearsal. Validation counts, +source pins, failures and artifact hashes belong in the accompanying evidence +record; a green happy path alone is not a release approval. diff --git a/docs/first-workflow.md b/docs/first-workflow.md index 240c544..6f82f79 100644 --- a/docs/first-workflow.md +++ b/docs/first-workflow.md @@ -64,3 +64,6 @@ Next: [author a workflow](../examples/quickstart-walkthrough.md), inspect [architecture and extension points](architecture-and-extension-diagrams.md), and read [enterprise deployment boundaries](enterprise-deployment.md) before enabling live providers. + +For the experimental typed-output, review, Eval and budget path, see the +[operator rehearsal](operator-rehearsal.md). diff --git a/docs/operator-rehearsal.md b/docs/operator-rehearsal.md new file mode 100644 index 0000000..df1a466 --- /dev/null +++ b/docs/operator-rehearsal.md @@ -0,0 +1,172 @@ +# Operate a local batch-summary graph (experimental) + +This walkthrough uses a trusted local host, a static five-node graph and retained +local storage. It is not a stable graph SDK or a claim of general production +readiness. The installed host runs this one workflow; it does not accept arbitrary +participant code or topology. + +## Install and configure + +Prerequisites: macOS or Linux, Bash, curl, tar, Git, and Kujo 1.6.0 with the +`sync_directory_beneath` runtime primitive. No provider account is needed. The +current release manifest pins a runtime **source commit**: its normal installer +path needs Cargo. To use a binary-only installation, use the verified 1.6.0 release +archive and its published SHA-256 file instead. Do not mistake an unavailable +release named after a source SHA for a verified binary installation. + +The following binary-install manifest was rehearsed without Cargo. The installer +verifies the runtime release checksum. Use a new prefix and run the commands from +a fresh directory (the source refs below are intentionally pinned): + +```bash +curl -fsSL https://raw.githubusercontent.com/kujolang/kujo/fc53093f35e4236682bbbf5ab1ccc8d2b4df990c/install.sh -o install.sh +cat > operator.refs <<'REFS' +kujo=v1.6.0 +ai-sdk=5184a122590dd5698770b50d99b69ed11c7ec84a +agents-sdk=5a9d5525e511a293b743b1c44d9ef270fd491f9f +dispatch=21aac0d35d8709ea3b8cb09844315c7b14fde5bd +REFS +bash install.sh --package dispatch --release-manifest "$PWD/operator.refs" \ + --prefix "$PWD/installed" --bin-dir "$PWD/bin" +export PATH="$PWD/bin:$PATH" +bash installed/sources/dispatch/scripts/install_operator_dependencies.sh +cp installed/sources/dispatch/examples/operator/batch.json batch.json +``` + +Source archives are the installed package format; an editable Git checkout is not +needed. This manifest installs the bounded host, not an unpublished participant +SDK or a new stable graph release. The package's default source-runtime manifest +remains unchanged for canonical source-build validation. + +The script downloads Workcell and Eval into `.operator-deps` without symlinks or +test-fixture preparation. It refuses to overwrite an existing dependency directory. +Set `DISPATCH_OPERATOR_DEPS` to a fresh absolute directory to install elsewhere. +Keep the installed code and dependencies unchanged for the lifetime of a run: +implementation/configuration changes invalidate its authority. + +Copy `examples/operator/batch.json` into your project. Its `amounts` are bounded +integer inputs; `expected_total` is the Eval criterion, not a claimed result. +`program_limit` and `eval_limit` are immutable ceilings for this run. Initializing +copies the exact source input, records its digest and the local OS user ID, creates +retained Git workspaces and negotiates each independent node run. + +```bash +dispatch operator init /absolute/batch-run /absolute/batch.json +dispatch operator inspect /absolute/batch-run --json +``` + +If you installed a source archive without a `dispatch` shim, use +`kujo run /installed/dispatch/dispatch.kujo operator ...` with `DISPATCH_ROOT` set +to that installed directory, or `bash /installed/dispatch/scripts/operator.sh ...`. +The latter resolves its installed files itself and works from any directory. +Only the initializing OS user is accepted by this trusted-host example. Filesystem +ownership and local executable permissions remain the host trust boundary. + +## Plan, apply, then separately continue + +A plan is an exact, reviewable candidate. It grants no authority and writes no run +state. Keep plans outside the retained workspace when comparing read-only snapshots. +For each operation below, use this pattern, inspect the resulting JSON, then apply: + +```bash +dispatch operator plan /absolute/batch-run reserve A > /absolute/plan.json +cat /absolute/plan.json +dispatch operator apply /absolute/batch-run /absolute/plan.json +dispatch operator run /absolute/batch-run +``` + +`run` uses Dispatch's existing DAG and one-use node admission. It may stop with +`node_requires_independent_finalization`; that is the expected control boundary, +not permission to replay. A program produces typed JSON and a proposed SQLite +receipt. Admit that receipt separately, and verify it by independent sink readback. +For A, plan/apply each operation in this order: + +```text +refresh A +select A +admit A +refresh A +parent-finalize A +``` + +`admit` explicitly authorizes the one selected SQLite mutation. `refresh` reads the +sink and retains evidence. `parent-finalize` accepts the exact output, its local +schema evaluation, preservation and effect evidence. No operation runs B or R. +Then call `run` again so the DAG observes A's independent finalization. + +## Human review, Eval and branch + +```bash +dispatch operator review /absolute/batch-run +``` + +This creates H's durable review request for the exact A output. Inspect it before +planning `approve H` (or `deny H`), then apply that plan. Approval binds the subject, +input digest, request, revision and OS-user actor. A stale plan must be regenerated; +a wrong subject or actor is rejected. Approval does not execute Eval or consumers. + +Plan/apply each operation: + +```text +reserve E +eval-dispatch E +observe E +node-finalize E +branch graph +``` + +Eval runs in a fresh process against the exact bound A output. `observe E` records +its actual runtime measurement artifact; it does not invent model usage. Eval +finalization and branch activation remain separate from executing the selected +consumer. On pass, reserve B and call `run`. On fail, reserve R and call `run`. +The other branch is `not_selected`, consuming no program capacity. + +Finish the selected consumer with the same five receipt/finalization operations +used for A. Call `run` again, then plan/apply `graph-finalize graph`. + +## Inspect failure, budget and provenance + +```bash +dispatch operator inspect /absolute/batch-run --json +``` + +The report references exact input bindings, output digests, node terminals, +attempt history, review evidence, branch decisions, graph outcome and retained +recovery assessment. Resource totals preserve observed/provider-reported/estimated +classes and explicit unknowns. A known partial sum is not a complete total. +No model was invoked in this workflow; monetary cost and model usage have no +sourced measurement and are not reported as measured zero. + +To exercise a real failed quality check, initialize a **new** workspace from a +config with `expected_total: 99`. Eval fails and the explicitly configured repair +branch R publishes the summary receipt. A failed quality check remains in history; +routing it does not rewrite the verdict as pass. + +To exercise exhaustion, initialize another workspace with `eval_limit: 0`. +After A and H complete, `plan ... reserve E` rejects for lack of Eval capacity. +Do not edit the anchored ceiling or restore old state. Consumed work can still +record evidence and finalize when the remaining available capacity is zero. + +## Controller failure and retained recovery + +After a controller dies, begin with `inspect`, then `plan ... recover graph`. +The plan comes from the existing retained-host recovery engine. Apply only a +permitted mechanical repair, then inspect again. A consistent run needs no repair; +continue with ordinary plans/admission. For a child, use its node ID instead of +`graph`. Recovery never runs a node or chooses a branch. + +A consumed attempt remains consumed even if its reply was lost. An unresolved +Eval may be resolved only from the installed adapter's exact retained response +(`eval-resolve E`); absence of that response remains uncertainty. Never refund or +rerun it based on budget availability. This example deliberately provides no +force-recover command, ceiling extension, evidence renewal, or unsafe retry. + +The preservation/effect evidence window is bounded to roughly one hour. Expiry +may prevent further execution/finalization even though history remains readable. +Do not reset the workspace to evade expiry. The deeper renewal APIs are outside +this first-hour workflow. + +See [resource accounting](contracts/resources/protocol.md), +[graph attempts](contracts/graph-attempts/operator.md), and +[retained recovery](contracts/recovery/retained-host.md) for the authority +contracts. The rehearsal evidence and remaining friction are recorded separately. diff --git a/examples/operator/batch.json b/examples/operator/batch.json new file mode 100644 index 0000000..1d49c5e --- /dev/null +++ b/examples/operator/batch.json @@ -0,0 +1 @@ +{"schema":"dispatch.batch-summary/v1alpha1","amounts":[12,18,20],"expected_total":50,"program_limit":2,"eval_limit":1} diff --git a/scripts/install_operator_dependencies.sh b/scripts/install_operator_dependencies.sh new file mode 100755 index 0000000..df7fb29 --- /dev/null +++ b/scripts/install_operator_dependencies.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +operator_root="$(cd "$(dirname "$0")/.." && pwd)" +operator_deps="${DISPATCH_OPERATOR_DEPS:-$operator_root/.operator-deps}" +mkdir -p "$operator_deps" +while read -r repository revision; do + destination="$operator_deps/$repository" + [[ ! -e "$destination" ]] || { echo "Refusing to replace $destination; use a fresh DISPATCH_OPERATOR_DEPS directory." >&2; exit 1; } + archive="$(mktemp)" + curl -fsSL --retry 3 "https://api.github.com/repos/kujolang/$repository/tarball/$revision" -o "$archive" + mkdir "$destination" + tar -xzf "$archive" --strip-components=1 -C "$destination" + rm "$archive" + printf '%s\n' "$revision" > "$destination/.operator-source-ref" +done <<'PINS' +workcell 0f9595b79872d2500f0bb35a8cf6227171fd7eeb +eval 6a5ab09e5c24cc1a842b374afccb64da40db2874 +PINS +printf 'Installed pinned operator dependencies in %s\n' "$operator_deps" diff --git a/scripts/operator.sh b/scripts/operator.sh new file mode 100755 index 0000000..81fb7b3 --- /dev/null +++ b/scripts/operator.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail +operator_root="$(cd "$(dirname "$0")/.." && pwd)" +if [[ $# -lt 2 || $1 == --help ]]; then + cat <<'HELP' +Experimental local batch-summary operator host + dispatch operator init /absolute/workspace /absolute/batch.json + dispatch operator inspect /absolute/workspace [--json] + dispatch operator plan /absolute/workspace ACTION [NODE] > plan.json + dispatch operator apply /absolute/workspace /absolute/plan.json + dispatch operator review /absolute/workspace + dispatch operator run /absolute/workspace +Actions: reserve, refresh, select, admit, parent-finalize, approve, deny, + eval-dispatch, eval-release, eval-resolve, observe, node-finalize, + branch, graph-finalize, recover. +Plans and inspection grant no authority. Apply affects only the named operation. +See docs/operator-rehearsal.md. This host runs only the shipped batch workflow. +HELP + exit 0 +fi +operator_deps="${DISPATCH_OPERATOR_DEPS:-$operator_root/.operator-deps}" +for dependency in workcell eval; do + if [[ ! -d "$operator_deps/$dependency/src" ]]; then + echo "Missing installed $dependency. Run bash $operator_root/scripts/install_operator_dependencies.sh before using the experimental operator host." >&2 + exit 1 + fi +done +# The explicit absolute workspace argument opts into a user-selected output root. +export DISPATCH_ALLOW_ANY_OUTPUT_ROOT=true +export DISPATCH_ROOT="$operator_root" +export DISPATCH_OPERATOR_DEPS="$operator_deps" +export KUJO_BIN="${KUJO_BIN:-$(command -v kujo)}" +export KUJO_MODULE_PATH="$operator_root:$operator_deps:$operator_deps/workcell:$operator_deps/eval" +exec "$KUJO_BIN" run "$operator_root/src/operator/main.kujo" "$@" diff --git a/scripts/run_release_gate.sh b/scripts/run_release_gate.sh index 65d9d53..100cf94 100755 --- a/scripts/run_release_gate.sh +++ b/scripts/run_release_gate.sh @@ -119,6 +119,7 @@ run_suite node_policy env KUJO_BIN="$KUJO_BIN" node tests/node_composition_polic run_suite node_recovery env KUJO_BIN="$KUJO_BIN" node tests/node_composition_recovery.mjs run_suite node_vectors "$KUJO_BIN" run tests/portable_commitments.kujo tests/vectors/node-composition.json run_suite parent_vectors "$KUJO_BIN" run tests/portable_commitments.kujo tests/vectors/parent-finalization.json +run_suite operator_rehearsal env KUJO_BIN="$KUJO_BIN" node tests/operator_rehearsal.mjs run_suite retained_recovery env KUJO_BIN="$KUJO_BIN" node tests/retained_recovery_integration.mjs run_suite effect_set env KUJO_BIN="$KUJO_BIN" node tests/effect_set_integration.mjs run_suite effect_continuation env KUJO_BIN="$KUJO_BIN" node tests/effect_continuation_integration.mjs diff --git a/src/operator/evaluate.kujo b/src/operator/evaluate.kujo new file mode 100644 index 0000000..42256fd --- /dev/null +++ b/src/operator/evaluate.kujo @@ -0,0 +1,16 @@ +from src.core.state import load_run_state +from src.core.resource_ledger import claim_evaluation +from src.core.node_transition import node_raw +from src.core.utils import dict_get_or +from eval.src.control_contracts import build_evaluation_result +arguments := args();base := arguments[0];id := arguments[1];attempt := arguments[2] +pointer := parse_json(read_file(base + "/pointer.json"));loaded := load_run_state(base + "/runs", pointer["run_id"]) +if loaded["ok"] == false {throw("eval_graph_missing")};graph := loaded["run_state"] +for step in graph["workflow_definition"]["steps"] {if step["id"] == id {if step["config"]["evaluator"]["configuration_sha256"] != sha256(read_file_beneath(base + "/" + id, "eval-config.json", 65536)) {throw("eval_configuration_stale")}}} +claim_evaluation(graph, id, attempt) +binding := graph["graph_node_bindings"][id];input := binding["inputs"][0];root := base + "/" + id +host := parse_json(read_file(root + "/eval-config.json"));append_file(root + "/eval-executions.log", attempt + "\n") +value := parse_json(node_raw(graph, input["content_ref"]));failed := 0;if value["value"] != dict_get_or(host, "expected_value", 1) {failed = 1} +stamp := current_timestamp() +result := build_evaluation_result({"passed":1 - failed, "failed":failed}, root + "/eval-config.json", {"subject":input["producer_subject"], "input_evidence_ids":[input["result_ref"], input["content_ref"]]}, stamp, current_timestamp(), []) +print(to_json(result)) diff --git a/src/operator/main.kujo b/src/operator/main.kujo new file mode 100644 index 0000000..ea78725 --- /dev/null +++ b/src/operator/main.kujo @@ -0,0 +1,285 @@ +from src.operator.presentation import print_operator_report, corrective_action +# Experimental installed batch-summary host. Control authority remains in core APIs. +from src.core.resource_operation import resource_operation +from src.core.graph_policy_operation import graph_policy_operation +from src.core.graph_outcome import graph_terminal_operation +from src.core.node_transition import node_raw +from src.core.node_composition import assess_node_inputs, bind_node_inputs, validate_bound_node_inputs, read_bound_node_input +from src.core.node_execution import run_bound_node +from src.core.runner import run_workflow +from src.core.state import load_run_state +from src.core.assurance_admission import create_negotiated_run +from src.core.assurance_configuration import implementation_digest, configuration_revision +from src.core.sequential_effects import sequential_effect_operation +from src.core.parent_finalization import assess_parent_finalization, finalize_parent +from src.core.retained_recovery import plan_retained_reconciliation, apply_retained_reconciliation +from src.core.step import create_step +from src.workflows.workflow import create_workflow +from src.tools.tool import create_tool_registry, create_tool, register_tool +from src.core.portable_commitments import portable_json +from src.core.utils import ensure_dir, dict_get_or +from src.adapters.sqlite_effect import sqlite_effect_init, sqlite_effect_observe +from src.adapters.sqlite_continuation import sqlite_continuation_adapter +from workcell.src.workspace.workspace import create_workspace +from workcell.src.evidence.preservation import write_preservation_outcome +from workcell.src.evidence.retained_workspace import observe_retained_workspace +from eval.src.control_contracts import build_evaluation_result +arguments := args();mode := arguments[0];base := arguments[1];node_id := "graph";if len(arguments) > 2 {node_id = arguments[2]};root := base + "/" + node_id +installation := env("DISPATCH_ROOT") +func need(ok) {if ok != true {throw("operator_host_fact_unavailable")}} +func cfg(path) {return parse_json(read_file_beneath(path, "host.json", 1048576))} +func pointer(path) {return parse_json(read_file(path + "/pointer.json"))} +func state(path) {p := pointer(path);loaded := load_run_state(path + "/runs", p["run_id"]);need(loaded["ok"]);return loaded["run_state"]} +func inventory() { + files := [] + for path in ["src/core/runtime_resource_schema.kujo", "src/core/resource_ledger.kujo", "src/core/resource_facts.kujo", "src/core/resource_operation.kujo", "src/operator/evaluate.kujo", "src/core/graph_attempts.kujo", "src/core/graph_outcome.kujo", "src/core/graph_transition.kujo", "src/core/node_transition.kujo", "src/core/node_composition.kujo", "src/core/node_execution.kujo", "src/core/runner.kujo", "src/core/assurance_state.kujo", "src/core/retained_recovery.kujo", "src/core/control_journal.kujo", "src/core/graph_policy.kujo", "src/core/graph_policy_operation.kujo", "src/core/assurance_configuration.kujo", "src/adapters/sqlite_continuation.kujo", "src/operator/main.kujo"] {files = push(files, {"root":installation, "path":path})} + files = push(files, {"root":env("DISPATCH_OPERATOR_DEPS") + "/workcell", "path":"src/evidence/retained_workspace.kujo"});return files +} +func descriptor(path) {return {"schema":"dispatch.assurance-configuration/v1beta1", "mode":"required", "fallback":"deny", "profile":"dispatch.sqlite-unique", "profile_version":"1beta1", "issuer":"sqlite-local", "mechanism":"sqlite_unique_transaction", "verifier_id":"node-host", "verifier_version":"1", "verifier_sha256":implementation_digest(inventory()), "authority_sha256":sha256(read_file(base + "/configuration.json"))}} +func graph_options() {return {"assurance_host":graph_host}} +func operator_actor(authorization) { + identity := spawn_process(["/usr/bin/id", "-u"], {"timeout_ms":5000, "max_output_bytes":1024}) + need(identity.success);uid := trim(identity.stdout) + need(uid == parse_json(read_file_beneath(base, "configuration.json", 65536))["operator_uid"]) + return {"id":"uid:" + uid, "type":"human", "authenticated_by":"local-os-user", "authorization":authorization} +} +func authorized(actor, authorization) {return to_json(actor) == to_json(operator_actor(authorization))} +func graph_host(revision, current) { + config := cfg(base) + host := {"authorize_graph":func(actor, graph, intent) {return authorized(actor, "graph-finalization")}, "authorize_decision":func(decision, graph, binding) {return authorized(decision["actor"], "graph-review")}, "read_evaluation":func(id, binding) {return read_file_beneath(base + "/" + id, "evaluation.json", 1048576)}, "resolve":func(id) {path := base + "/" + id;return {"root":path + "/runs", "run_id":pointer(path)["run_id"], "options":node_options(path)}}, "start":func(id, binding) { + selected := id;if pointer(base + "/" + id)["run_id"] != binding["consumer"]["run_id"] {selected = id + "-retry"} + command := spawn_process([env("KUJO_BIN"), "run", "src/operator/main.kujo", "start", base, selected], {"cwd":installation, "inherit_env":true, "timeout_ms":120000, "max_output_bytes":1048576}) + need(command.success);write_file(base + "/" + id + "/start-response.json", command.stdout, true);return parse_json(command.stdout) + }} + host["evaluation_identity"] := func(id) {return {"name":"eval", "version":"2.0.0", "configuration_sha256":sha256(read_file_beneath(base + "/" + id, "eval-config.json", 65536))}} + host["start_evaluation"] := func(id, binding, attempt) { + path := base + "/" + id + result := spawn_process([env("KUJO_BIN"), "run", "--measurements", path + "/resource-" + attempt + "-runtime.json", "src/operator/evaluate.kujo", base, id, attempt], {"cwd":installation, "inherit_env":true, "timeout_ms":120000, "max_output_bytes":1048576}) + response := {"attempt_id":attempt, "binding_ref":"sha256:" + sha256(portable_json(binding)), "status":"completed", "evaluation_raw":result.stdout} + if result.timed_out||result.cancelled||result.stdout_truncated||result.stderr_truncated {throw("eval_termination_uncertain")} + if result.success == false {response = {"attempt_id":attempt, "binding_ref":"sha256:" + sha256(portable_json(binding)), "status":"infrastructure_failed", "reason":"installed evaluator worker terminated with an infrastructure error"}} + + write_file_atomic_beneath(path, "response-" + attempt + ".json", to_json(response), false);return response + } + host["read_evaluation_attempt"] := func(id, binding, attempt) {return parse_json(read_file_beneath(base + "/" + id, "response-" + attempt + ".json", 1048576))} + host["read_resource_source"] := func(subject, kind) {path := base + "/" + subject["node_id"];relative := "resource-" + subject["attempt_id"] + "-" + kind + ".json";if file_exists(path + "/" + relative) == false {return null};return {"subject":subject, "source_kind":kind, "raw":read_file_beneath(path, relative, 65536)}} + host["resolve_attempt"] := func(id, run_id) {for suffix in [id, id + "-retry"] {path := base + "/" + suffix;if file_exists(path + "/pointer.json")&&pointer(path)["run_id"] == run_id {return {"root":path + "/runs", "run_id":run_id, "options":node_options(path)}}};throw("attempt_run_unavailable")} + return {"status":"active", "descriptor":config["descriptor"], "authority_sha256":sha256(read_file(base + "/configuration.json")), "implementation":inventory(), "verify":func(subject) {return null}, "node_host":host} +} +func preserved(path, selector) { + config := cfg(path) + for entry in config["preservation_sources"] { + if entry["selector"] == selector { + content := "" + if entry["kind"] == "workspace" {observed := observe_retained_workspace(config["workspace"]);need(observed["ok"]);content = to_json(observed["observation"])} + else {content = read_file_beneath(path, "workcell/" + selector, 1048576)} + return {"metadata_raw":entry["metadata_raw"], "content_raw":content, "environment_ref":"sha256:" + sha256(path)} + } + } + throw("unknown_preservation_reference") +} +func node_host(path, revision, current) { + config := cfg(path);effect := dict_get_or(config, "effect_set", {}) + effect["read_artifact"] := func(reference) {return read_file_beneath(path, "artifacts/" + substring(reference, 7, 71) + ".json", 65536)} + if has_key(config, "preservation_sources") {effect["preservation_binding"] := {"document_raw":read_file_beneath(path, "workcell/preservation.json", 65536), "environment_ref":"sha256:" + sha256(path), "resolve":func(selector) {return preserved(path, selector)}}} + parent := {"evaluation_raw":dict_get_or(config, "evaluation_raw", ""), "authorize_decision":func(decision, current) {return authorized(decision["actor"], "parent-finalization")}, "read_output":func(reference) {need(reference == cfg(path)["output_ref"]);return {"metadata_raw":read_file_beneath(path, "output-evidence.json", 16384), "content_raw":read_file_beneath(path, "output.json", 1048576)}}} + return {"status":"active", "descriptor":config["descriptor"], "authority_sha256":sha256(read_file(base + "/configuration.json")), "implementation":inventory(), "verify":func(subject) {return null}, "node_preflight":func(current) {return {"status":"available"}}, "effect_set":effect, "continuation_adapter":sqlite_continuation_adapter, "parent_finalization":parent, "validate_node_inputs":func(current) {return validate_bound_node_inputs(current, state(base), graph_options())}} +} +func node_options(path) {return {"assurance_host":func(revision, current) {return node_host(path, revision, current)}, "tool_authorization_policy":func(input) {return {"allow":true, "message":"Installed batch-summary tool only"}}}} +func schema() {return {"$id":"kujo.example/batch-summary/v1", "type":"object", "required":["schema", "node", "value", "sources", "source_ref"], "additionalProperties":false, "properties":{"schema":{"const":"kujo.example/batch-summary/v1"}, "source_ref":{"type":"string"}, "node":{"type":"string"}, "value":{"type":"integer"}, "sources":{"type":"array", "items":{"type":"string"}}}}} +func outputs() {return [{"name":"report", "type_id":"kujo.example/batch-summary/v1", "json_schema":schema()}]} +func workflow(path) { + return create_workflow({"id":"composed-execution", "metadata":{"node_input_required":"dispatch.node-input/v1alpha1"}, "name":"Independent node", "description":"One protected execution", "input_schema":{"type":"dict"}, "output_schema":{"type":"dict"}, "agents":{}, "tools":["action"], "steps":[create_step("action", "Node action", "tool", {"tool_name":"action", "input_from":["input"], "effect_class":"external_non_idempotent", "node_outputs":outputs(), "parent_finalization":{"schema":"dispatch.parent-finalization-policy/v1alpha1", "required_outputs":["report"], "evaluation":{"name":"eval", "version":"2.0.0", "configuration_sha256":sha256(read_file(path + "/eval-config.json"))}}})], "routing":{"enabled":false}, "control":{"policy_id":"node", "policy_version":"1", "policies":[{"when":{"result":"execution", "status":"indeterminate"}, "decide":{"disposition":"require_intervention", "reason":"Resolve node effect", "allowed_actions":["retry_step", "approve_override", "abort"]}}]}, "default_retry_policy":{"max_attempts":1}, "approval_config":{"auto_approve":false}, "memory_config":{}, "budgets":{}, "max_parallel_steps":1}) +} +func graph_workflow() { + definition := parse_json(read_file(base + "/graph.json"));steps := [] + heterogeneous := false + for node in definition["nodes"] { + node_config := {"tool_name":"installed_node", "depends_on":node["depends_on"], "optional":dict_get_or(node, "optional", false), "kind":dict_get_or(node, "kind", "program")} + contract := dict_get_or(node, "terminal_contract", "parent-finalization/v1alpha1") + if has_key(node, "terminal_contract") {heterogeneous = true;node_config["terminal_contract"] := contract} + if contains(["parent-finalization/v1alpha1", "program-attempt/v1alpha1"], contract) {node_config["node_execution"] := {"schema":"dispatch.run-backed-node/v1alpha1", "run_id":pointer(base + "/" + node["id"])["run_id"], "step_id":"action", "inputs":node["inputs"], "outputs":outputs()}} + else {node_config["inputs"] := node["inputs"];if contract == "evaluation-result/v1" {node_config["evaluator"] := {"name":"eval", "version":"2.0.0", "configuration_sha256":sha256(read_file(base + "/" + node["id"] + "/eval-config.json"))}}} + if has_key(node, "max_attempts") {execution := node_config["node_execution"];execution["max_attempts"] := node["max_attempts"];if node["max_attempts"] == 2 {execution["retry_run_id"] := pointer(base + "/" + node["id"] + "-retry")["run_id"]};node_config["node_execution"] := execution} + for key in ["max_eval_attempts", "accept_terminal", "after_subgraphs", "on_unsuccessful"] {if has_key(node, key) {node_config[key] := node[key]}} + steps = push(steps, create_step(node["id"], node["id"], "tool", node_config)) + } + metadata := {"node_composition":"dispatch.node-composition/v1alpha1"};if heterogeneous {metadata["graph_outcome"] := "dispatch.graph-outcome/v1alpha1"} + if has_key(definition, "graph_resources") {metadata["graph_resources"] := definition["graph_resources"]} + if has_key(definition, "graph_accounting") {metadata["graph_accounting"] := definition["graph_accounting"]} + if has_key(definition, "graph_policy") {metadata["graph_policy"] := definition["graph_policy"]} + return create_workflow({"id":"static-composition", "metadata":metadata, "name":"Static node DAG", "description":"Separate data and scheduling", "input_schema":{"type":"dict"}, "output_schema":{"type":"dict"}, "agents":{}, "tools":[], "steps":steps, "routing":{"enabled":false}, "control":dict_get_or(definition, "control", {"policy_id":"graph", "policy_version":"1", "policies":[]}), "default_retry_policy":{"max_attempts":1}, "approval_config":{"auto_approve":false}, "memory_config":{}, "budgets":{}, "max_parallel_steps":1}) +} +func action(input, context) { + config := cfg(root);current := state(root);sources := [];source_raw := read_file_beneath(base, "input.json", 65536);need(sha256(source_raw) == parse_json(read_file(base + "/configuration.json"))["source_sha256"]);value := 0;if node_id == "A" {for amount in parse_json(source_raw)["amounts"] {value = value + amount}} + for item in current["node_input_binding"]["inputs"] {consumed := read_bound_node_input(current, item["name"]);value = value + consumed["value"];sources = push(sources, item["content_ref"])} + append_file(root + "/executions.log", "executed\n") + + ensure_dir(root + "/workcell") + workspace := create_workspace(root + "/source", "git-worktree", "wc-" + replace(uuid_v4(), "-", ""));need(workspace["ok"]);config["workspace"] := workspace + write_file(root + "/workcell/receipt.json", to_json({"workspace":workspace}), true) + subject := {"run_id":context["run_id"], "step_id":"action", "attempt_id":"1"};stamp := format_date(now(), "YYYY-MM-DDTHH:mm:ssZ") + preserved_result := write_preservation_outcome({"run_id":subject["run_id"], "step_id":"action", "attempt_id":"1", "requested_mode":"filesystem", "cleanup_status":"preserved", "output_dir":root + "/workcell", "workspace_path":workspace["workspace_path"], "provider":"local", "retain_until":format_date(now() + 3600, "YYYY-MM-DDTHH:mm:ssZ"), "source_root":workspace["source_root"], "workspace_strategy":workspace["strategy"]});need(preserved_result["ok"]) + content := to_json({"schema":"kujo.example/batch-summary/v1", "node":node_id, "value":value, "sources":sources, "source_ref":"sha256:" + sha256(source_raw)});write_file(root + "/output.json", content, true) + metadata := {"schema":"kujo.evidence-ref/v1", "id":"report", "producer":{"name":"local-node", "version":"1"}, "subject":subject, "kind":"artifact", "uri":"file:output.json", "media_type":"application/json", "artifact_schema":schema(), "created_at":stamp, "integrity":{"status":"sha256", "sha256":sha256(content)}} + metadata_raw := to_json(metadata);write_file(root + "/output-evidence.json", metadata_raw, true);config["output_ref"] := "sha256:" + sha256(metadata_raw) + preservation_sources := [] + for entry in preserved_result["outcome"]["evidence"] { + selector := entry["$ref"];kind := "file";bytes := "" + if selector == workspace["workspace_path"] {kind = "workspace";bytes = to_json(observe_retained_workspace(workspace)["observation"])} else {bytes = read_file_beneath(root, "workcell/" + selector, 1048576)} + evidence := {"schema":"kujo.evidence-ref/v1", "subject":subject, "integrity":{"status":"sha256", "sha256":sha256(bytes)}} + preservation_sources = push(preservation_sources, {"selector":selector, "kind":kind, "metadata_raw":to_json(evidence)}) + } + config["preservation_sources"] := preservation_sources;write_file(root + "/host.json", to_json(config), true) + return {"ok":true, "data":{"schema":"kujo.execution-result/v1", "result_id":context["run_id"] + ":result", "subject":subject, "producer":{"name":"local-node", "version":"1"}, "status":"indeterminate", "classification":"unknown", "started_at":stamp, "finished_at":stamp, "attempt":1, "effects":[{"effect_id":"C", "class":"external_idempotent", "state":"not_started"}], "evidence":[], "output":{"report":config["output_ref"]}, "preservation_outcome":preserved_result["outcome"]}} +} +func put(value) {raw := portable_json(value);path := "artifacts/" + sha256(raw) + ".json";if file_exists(root + "/" + path) == false {write_file_atomic_beneath(root, path, raw, false)};return "sha256:" + sha256(raw)} +func publish_facts() { + config := cfg(root);current := state(root);result := current["steps"][0]["execution_result"];raw := to_json(result);intent := config["intent"];stamp := parse_int(to_string(floor(now_utc_seconds()))) + registration := {"adapter":"local-sqlite", "revision":"1", "participant":"node-host"} + plan := {"schema":"dispatch.effect-plan/v1alpha1", "subject":result["subject"], "config_ref":"sha256:" + configuration_revision(config["descriptor"]), "registration_ref":"sha256:" + sha256(portable_json(registration)), "preserve_until":stamp + 3000, "effects":[{"effect_id":"C", "operation":"create", "target_ref":"sha256:" + intent["target_sha256"], "scope_ref":"sha256:" + intent["scope_sha256"], "key_ref":"sha256:" + intent["key_sha256"], "request_ref":"sha256:" + intent["request_sha256"], "profile":"dispatch.sqlite-unique", "profile_revision":"1beta1", "authority":"sqlite-local"}]} + live := sqlite_effect_observe(root + "/sink.db", intent);need(live["ok"]) + observation := put({"schema":"dispatch.effect-observation/v1alpha1", "plan_ref":"sha256:" + sha256(portable_json(plan)), "result_ref":"sha256:" + sha256(raw), "effect_id":"C", "state":live["observation"]["observed_state"], "observed_at":stamp - 1, "valid_until":stamp + 1800, "evidence_ref":live["observation"]["evidence_ref"]}) + sidecar := {"schema":"dispatch.effect-set/v1alpha1", "result_ref":"sha256:" + sha256(raw), "plan_ref":"sha256:" + sha256(portable_json(plan)), "observations":[observation]} + config["effect_set"] := {"plan":plan, "result_raw":raw, "set_raw":portable_json(sidecar), "registration":registration, "intents":[intent], "sink_path":root + "/sink.db", "environment_ref":"sha256:" + sha256(root), "environment_valid":true} + need(json_schema_validate(parse_json(read_file(root + "/output.json")), schema())["valid"]) + config["evaluation_raw"] := to_json(build_evaluation_result({"passed":1, "failed":0}, root + "/eval-config.json", {"subject":result["subject"], "input_evidence_ids":["sha256:" + sha256(raw), "sha256:" + sha256(read_file(root + "/output.json"))]}, stamp * 1000, stamp * 1000, [])) + write_file(root + "/host.json", to_json(config), true) +} + +func save(path, value) {need(write_file_atomic_beneath(base, path, to_json(value), false))} +func edge() {return {"name":"input", "source_node":"A", "source_output":"report", "type_id":"kujo.example/batch-summary/v1"}} +func program(id, dependencies) {return {"id":id, "depends_on":dependencies, "inputs":[edge()], "terminal_contract":"parent-finalization/v1alpha1"}} +func initialize(configuration_path) { + need(file_exists(base) == false) + configuration := parse_json(read_file(configuration_path));need(json_schema_validate(configuration, {"type":"object", "required":["schema", "amounts", "expected_total", "program_limit", "eval_limit"], "additionalProperties":false, "properties":{"schema":{"const":"dispatch.batch-summary/v1alpha1"}, "amounts":{"type":"array", "items":{"type":"integer"}}, "expected_total":{"type":"integer"}, "program_limit":{"type":"integer"}, "eval_limit":{"type":"integer"}}})["valid"]) + need(type(configuration["amounts"]) == "array"&&len(configuration["amounts"]) > 0&&len(configuration["amounts"]) <= 100) + for amount in configuration["amounts"] {need(type(amount) == "int"&&amount >= 0&&amount <= 1000000)} + for key in ["program_limit", "eval_limit", "expected_total"] {need(type(configuration[key]) == "int"&&configuration[key] >= 0&&configuration[key] <= 100000000)} + need(configuration["program_limit"] <= 3&&configuration["eval_limit"] <= 4) + ensure_dir(base) + source := to_json({"amounts":configuration["amounts"]});write_file_atomic_beneath(base, "input.json", source, false) + identity := spawn_process(["/usr/bin/id", "-u"], {"timeout_ms":5000});need(identity.success) + configuration["operator_uid"] := trim(identity.stdout);configuration["source_sha256"] := sha256(source);save("configuration.json", configuration) + a := program("A", []);a["inputs"] := [] + e := {"id":"E", "depends_on":["A", "H"], "inputs":[edge()], "kind":"evaluator", "terminal_contract":"evaluation-result/v1", "on_unsuccessful":{"action":"route", "branch":"quality"}} + h := {"id":"H", "depends_on":["A"], "inputs":[edge()], "kind":"human_review", "terminal_contract":"intervention-decision/v2"} + repair := program("R", ["E"]);repair["accept_terminal"] := {"E":["failed"]} + definition := {"nodes":[a, h, e, program("B", ["E"]), repair], "graph_accounting":"dispatch.graph-attempt-accounting/v1alpha1", "graph_resources":{"schema":"dispatch.graph-resources/v1alpha1", "max_eval_attempts":configuration["eval_limit"], "require_provider_usage":false}, "graph_policy":{"schema":"dispatch.static-graph-policy/v1alpha1", "branches":[{"id":"quality", "source":"E", "predicate":"evaluation_verdict", "cases":[{"value":"pass", "nodes":["B"]}, {"value":"fail", "nodes":["R"]}]}], "subgraphs":[], "budget":{"max_program_dispatches":configuration["program_limit"], "on_exhaustion":"block"}}} + save("graph.json", definition) + for item in definition["nodes"] { + id := item["id"];path := base + "/" + id;ensure_dir(path);save(id + "/eval-config.json", {"suite":"batch-" + id, "expected_value":configuration["expected_total"]}) + if contains(["A", "B", "R"], id) { + ensure_dir(path + "/source");write_file(path + "/source/input.json", source, true) + for argv in [["git", "-C", path + "/source", "init", "-q"], ["git", "-C", path + "/source", "add", "input.json"], ["git", "-C", path + "/source", "-c", "user.name=Dispatch Operator", "-c", "user.email=operator@localhost", "commit", "-qm", "Retained batch input"]] {command_result := spawn_process(argv, {"timeout_ms":10000});need(command_result.success)} + stamp := parse_int(to_string(floor(now_utc_seconds()))) + save(id + "/host.json", {"intent":{"operation":"create", "target_sha256":sha256(path + "/sink.db"), "scope_sha256":sha256(base), "key_sha256":sha256(id), "request_sha256":sha256(source + ":" + id), "precondition_sha256":sha256("empty"), "valid_from":stamp - 1, "valid_until":stamp + 3500}}) + ensure_dir(path + "/artifacts");sqlite_effect_init(path + "/sink.db") + config := cfg(path);config["descriptor"] := descriptor(path);write_file(path + "/host.json", to_json(config), true) + created := create_negotiated_run(workflow(path), {}, path + "/runs", {}, config["descriptor"], node_options(path)["assurance_host"]);need(created["ok"]) + save(id + "/pointer.json", {"run_id":created["run_state"]["run_id"]}) + } else {save(id + "/host.json", {})} + } + save("host.json", {"descriptor":descriptor(base)}) + created := create_negotiated_run(graph_workflow(), {}, base + "/runs", {}, cfg(base)["descriptor"], graph_host);need(created["ok"]) + save("pointer.json", {"run_id":created["run_state"]["run_id"]}) + return {"ok":true, "run_id":pointer(base)["run_id"], "next":"plan reserve A; apply the plan; run"} +} +func graph_call(request) {return graph_terminal_operation(base + "/runs", pointer(base)["run_id"], request, graph_options())} +func resource_call(request) {return resource_operation(base + "/runs", pointer(base)["run_id"], request, graph_options())} +func policy_call(request) {return graph_policy_operation(base + "/runs", pointer(base)["run_id"], request, graph_options())} +func effect_call(id, request) {path := base + "/" + id;return sequential_effect_operation(path + "/runs", pointer(path)["run_id"], request, node_options(path))} +func parent_decision(id) { + s := state(base + "/" + id) + return {"schema":"kujo.intervention-decision/v2", "decision_id":"parent-" + uuid_v4(), "request_id":s["human_intervention"]["request_id"], "boundary_id":s["current_control_boundary"]["boundary_id"], "expected_state_revision":s["revision"], "action":"approve_override", "reason":"Operator accepts independently verified batch receipt and typed output", "decided_at":format_date(now(), "YYYY-MM-DDTHH:mm:ssZ"), "actor":operator_actor("parent-finalization")} +} +func human_decision(action) { + graph := state(base);review := graph["graph_reviews"]["H"] + return {"schema":"kujo.intervention-decision/v2", "decision_id":"review-" + uuid_v4(), "request_id":review["request"]["request_id"], "boundary_id":review["boundary"]["boundary_id"], "expected_state_revision":graph["revision"], "subject":{"run_id":graph["run_id"], "step_id":"H", "decision_instance":"1"}, "input_binding_ref":review["binding_ref"], "action":action, "reason":"Operator reviews exact batch input and producer output", "decided_at":format_date(now(), "YYYY-MM-DDTHH:mm:ssZ"), "actor":operator_actor("graph-review")} +} +func make_plan(action, id) { + need(contains(["A", "B", "R", "E", "H", "graph"], id)) + if action == "recover" { + target := base;if id != "graph" {target = base + "/" + id} + checked := plan_retained_reconciliation(target + "/runs", pointer(target)["run_id"]);if checked["ok"] == false {return checked} + return {"ok":true, "schema":"dispatch.operator-plan/v1alpha1", "run_id":pointer(base)["run_id"], "node_id":id, "action":action, "family":"recovery", "request":checked, "authority":"informational", "scope":"mechanical repair only; no continuation"} + } + graph := state(base);request := {};family := "";checked := {} + if contains(["reserve", "eval-dispatch", "eval-release", "eval-resolve", "observe"], action) { + family = "resource";op := action;if action == "eval-dispatch" {op = "dispatch"};if action == "eval-release" {op = "release"};if action == "eval-resolve" {op = "resolve"} + request = {"operation":"assess", "action":op, "node_id":id} + if action == "reserve" {request["nodes"] := [id]} + if action == "observe" {rows := graph["eval_attempts"][id];request["subject"] := {"kind":"eval", "node_id":id, "attempt_id":rows[len(rows) - 1]["attempt_id"]};request["source_kind"] := "runtime"} + checked = resource_call(request);if checked["ok"] {request["operation"] := "apply";request["candidate"] := checked["candidate"];request["actor"] := operator_actor("graph-finalization")} + } else if action == "branch" { + family = "policy";request = {"operation":"assess", "kind":"branch", "id":"quality"};checked = policy_call(request) + if checked["ok"] {request["operation"] := "apply";request["candidate"] := checked["candidate"];request["actor"] := operator_actor("graph-finalization")} + } else if contains(["refresh", "select", "admit"], action) { + family = "effect";checked = effect_call(id, {"operation":"inspect"}) + if checked["ok"] {request = {"operation":action, "effect_id":"C", "expected":checked["cursor"]};if action == "admit" {request = {"operation":"admit", "expected":checked["cursor"], "attempt_id":checked["lifecycle"]["active"]}}} + } else if action == "parent-finalize" { + family = "parent";decision := parent_decision(id);path := base + "/" + id + checked = assess_parent_finalization(path + "/runs", pointer(path)["run_id"], decision, node_options(path));if checked["ok"] {request = {"candidate":checked["candidate"], "decision":decision}} + } else if contains(["approve", "deny", "node-finalize", "graph-finalize"], action) { + family = "graph";request = {"operation":"node-assess", "node_id":id} + if action == "graph-finalize" {request = {"operation":"graph-assess"}} + if action == "approve" {request["decision"] := human_decision("approve_override")} + if action == "deny" {request["decision"] := human_decision("abort")} + checked = graph_call(request) + if checked["ok"] {request["candidate"] := checked["candidate"];request["operation"] := "node-finalize";if action == "graph-finalize" {request["operation"] := "graph-finalize";request["actor"] := operator_actor("graph-finalization")}} + } else if action == "recover" { + family = "recovery";path := base;if id != "graph" {path = base + "/" + id};checked = plan_retained_reconciliation(path + "/runs", pointer(path)["run_id"]);request = checked + } else {throw("unknown_operator_action")} + if checked["ok"] == false {return checked} + return {"ok":true, "schema":"dispatch.operator-plan/v1alpha1", "run_id":graph["run_id"], "node_id":id, "action":action, "family":family, "request":request, "authority":"informational", "scope":"one explicit operation; no downstream execution"} +} +func apply_plan(plan) { + need(plan["schema"] == "dispatch.operator-plan/v1alpha1"&&plan["run_id"] == pointer(base)["run_id"]) + id := plan["node_id"];need(contains(["A", "B", "R", "H", "E", "graph"], id));operator_actor("graph-finalization") + request := plan["request"];family := plan["family"] + if family == "resource" {need(request["operation"] == "apply");return resource_call(request)} + if family == "policy" {need(request["operation"] == "apply");return policy_call(request)} + if family == "effect" {need(contains(["refresh", "select", "admit"], request["operation"]));return effect_call(id, request)} + if family == "parent" {path := base + "/" + id;return finalize_parent(path + "/runs", pointer(path)["run_id"], request["candidate"], request["decision"], node_options(path))} + if family == "graph" {need(contains(["node-finalize", "graph-finalize"], request["operation"]));return graph_call(request)} + if family == "recovery" {path := base;if id != "graph" {path = base + "/" + id};return apply_retained_reconciliation(path + "/runs", pointer(path)["run_id"], request["plan"], operator_actor("graph-finalization")["id"])} + throw("operator_plan_family_invalid") +} +func explain() { + graph := state(base);nodes := [] + for step in graph["workflow_definition"]["steps"] { + id := step["id"];item := {"node_id":id, "depends_on":step["depends_on"], "kind":step["config"]["kind"], "terminal":dict_get_or(dict_get_or(graph, "node_completions", {}), id, null), "binding":dict_get_or(dict_get_or(graph, "graph_node_bindings", {}), id, null)} + if contains(["A", "B", "R"], id) { + child := state(base + "/" + id);item["control_status"] := child["status"];item["execution_state"] := "never_dispatched" + if has_key(dict_get_or(graph, "node_dispatches", {}), id) {item["execution_state"] := "dispatch_consumed_completion_unknown"} + if dict_get_or(child["steps"][0], "execution_result", null) != null {item["execution_state"] := "result_recorded"} + if has_key(child, "parent_finalization") {item["execution_state"] := "independently_finalized"} + item["input_binding"] := dict_get_or(child, "node_input_binding", null);item["finalization"] := dict_get_or(child, "parent_finalization", null) + if has_key(cfg(base + "/" + id), "effect_set") {item["effect"] := effect_call(id, {"operation":"inspect"})} + if file_exists(base + "/" + id + "/output.json") {item["output"] := parse_json(read_file_beneath(base + "/" + id, "output.json", 65536));item["output_sha256"] := sha256(read_file_beneath(base + "/" + id, "output.json", 65536))} + } + nodes = push(nodes, item) + } + return {"ok":true, "schema":"dispatch.operator-report/v1alpha1", "run_id":graph["run_id"], "revision":graph["revision"], "status":graph["status"], "nodes":nodes, "outcome":graph_call({"operation":"graph-assess"}), "resources":resource_call({"operation":"report"}), "attempts":policy_call({"operation":"assess", "kind":"accounting"}), "branches":dict_get_or(graph, "branch_activations", {}), "reviews":dict_get_or(graph, "graph_reviews", {}), "recovery":plan_retained_reconciliation(base + "/runs", pointer(base)["run_id"]), "source_ref":"sha256:" + parse_json(read_file(base + "/configuration.json"))["source_sha256"], "authority":"informational", "continuation":"separate explicit run/admission; consumed work must not replay"} +} +answer := {"ok":false} +try { + need(starts_with(base, "/")&&len(base) < 1024) + if mode == "init" {answer = initialize(node_id)} + else if mode == "inspect" {answer = explain()} + else if mode == "plan" {id := "graph";if len(arguments) > 3 {id = arguments[3]};answer = make_plan(node_id, id)} + else if mode == "apply" {answer = apply_plan(parse_json(read_file(node_id)))} + else if mode == "review" {operator_actor("graph-review");answer = graph_call({"operation":"review-open", "node_id":"H"})} + else if mode == "run" {operator_actor("graph-finalization");answer = run_workflow(graph_workflow(), state(base), create_tool_registry(), graph_options())} + else if mode == "start" { + current := state(root);registry := register_tool(create_tool_registry(), create_tool("action", "Batch summary", {"type":"dict"}, {"type":"dict"}, action, null)) + answer = run_bound_node(workflow(root), current, registry, node_options(root), current["node_input_binding"]) + if answer["ok"]&&dict_get_or(answer, "paused", false) {publish_facts()} + } else {throw("operator_command_invalid")} +} except err {answer = {"ok":false, "reason":to_string(err)}} +if mode == "run"&&has_key(answer, "run_state") { + current := answer["run_state"] + answer = {"schema":"dispatch.operator-action/v1alpha1", "ok":answer["ok"], "run_id":current["run_id"], "revision":current["revision"], "control_status":current["status"], "paused":dict_get_or(answer, "paused", false), "reason":dict_get_or(answer, "reason", ""), "next":"inspect the workspace; use separate plans for effects, review and finalization"} +} +if answer["ok"] == false {answer["next"] := corrective_action(answer)} +if mode == "inspect"&&answer["ok"]&&contains(arguments, "--json") == false {print_operator_report(answer)} else {print(to_json(answer))};if answer["ok"] == false {exit(1)} diff --git a/src/operator/presentation.kujo b/src/operator/presentation.kujo new file mode 100644 index 0000000..d758ad5 --- /dev/null +++ b/src/operator/presentation.kujo @@ -0,0 +1,40 @@ +from src.core.utils import dict_get_or +func value_or_unknown(value) {if value == null {return "unknown"};return to_string(value)} +export func print_operator_report(report) { + print("Run: " + report["run_id"] + " (revision " + to_string(report["revision"]) + ")") + print("Control status: " + report["status"]) + outcome := report["outcome"] + if outcome["ok"] { + facts := dict_get_or(outcome, "candidate", {}) + if has_key(outcome, "receipt") {facts = outcome["receipt"]["candidate"];print("Graph terminal decision: " + facts["outcome"])} + else {print("Graph assessment: " + facts["outcome"] + " (informational)")} + for node in facts["nodes"] { + terminal := "not terminal";if node["terminal"] != null {terminal = node["terminal"]["outcome"]} + print(" " + node["node_id"] + ": " + terminal + "; " + node["reason"]) + } + } else {print("Graph facts unavailable: " + to_json(outcome))} + for node in report["nodes"] { + if has_key(node, "execution_state") {print("Execution " + node["node_id"] + ": " + node["execution_state"] + " (durable facts, not process liveness)")} + if has_key(node, "output_sha256") {print("Output " + node["node_id"] + ": sha256:" + node["output_sha256"]);print(" Sources: " + to_json(node["output"]["sources"]));print(" Source input: " + node["output"]["source_ref"])} + } + resource := report["resources"] + if resource["ok"] { + data := resource["report"] + for field in ["programs", "evaluations"] {budget := data[field];print(field + ": " + to_string(budget["consumed"]) + " consumed, " + to_string(budget["reserved"]) + " reserved, " + to_string(budget["available"]) + " available");if budget["available"] == 0 {print(" No new " + field + " capacity. Already consumed work may still resolve/finalize.")}} + for field in keys(data["totals"]) {fact := data["totals"][field];print(field + " [" + fact["class"] + "]: " + value_or_unknown(fact["total"]) + "; known partial sum " + to_string(fact["known_sum"]) + "; unknown attempts " + to_string(fact["unknown_attempts"]))} + print("Monetary cost [unknown]: unknown") + } else {print("Resource facts unavailable: " + to_json(resource))} + for id in keys(report["reviews"]) {review := report["reviews"][id];print("Retained review " + id + ": " + review["request"]["request_id"] + "; input " + review["binding_ref"])} + for id in keys(report["branches"]) {branch := report["branches"][id]["candidate"];print("Branch " + id + ": " + branch["selected"] + "; active " + to_json(branch["active_nodes"]) + "; not selected " + to_json(branch["inactive_nodes"]));print(" Decision evidence: " + branch["source_fact_ref"])} + recovery := report["recovery"] + if recovery["ok"] {assessment := recovery["assessment"];print("Recovery: " + assessment["classification"] + "; safe repairs " + to_string(len(assessment["safe_repairs"])));print("Unresolved: " + to_json(assessment["unresolved"]))} else {print("Recovery unavailable: " + to_json(recovery))} + print("Inspection grants no admission. Consumed attempts cannot replay. Use --json for exact bindings and attempt history.") +} +export func corrective_action(answer) { + description := to_json(answer) + if contains(description, "eval_plan_capacity")||contains(description, "eval_attempt_limit") {return "Eval capacity is exhausted. Do not edit the ceiling. Resolve already-consumed Eval attempts if evidence exists; a new run needs a separately chosen policy."} + if contains(description, "program_plan_capacity")||contains(description, "attempt_budget_exhausted") {return "Program capacity is exhausted or reserved. Inspect reservations; release only a proven never-dispatched reservation. Consumed attempts cannot be refunded."} + if contains(description, "stale") {return "The plan/decision no longer matches current authority. Inspect and generate a new plan; do not reuse or edit the old decision."} + if contains(description, "reservation_path_not_ready") {return "This node is not on an eligible active path. Inspect upstream finalization, review and branch selection; budget alone grants no eligibility."} + return "Inspect the retained workspace. Re-plan after resolving the named condition; never edit state, refund consumed work, or replay an uncertain effect." +} diff --git a/tests/dispatch_tests.kujo b/tests/dispatch_tests.kujo index 2996b6e..d870f7a 100644 --- a/tests/dispatch_tests.kujo +++ b/tests/dispatch_tests.kujo @@ -2532,6 +2532,7 @@ test "dispatch help usage snapshot remains compatible" { usage_snapshot := [ "kujo run dispatch.kujo run \"Research topic\" [--workflow-file workflow.json] [--input-json '{...}'] [--output-root outputs]", "kujo run dispatch.kujo init [--dir dispatch-workflow] [--force]", + "kujo run dispatch.kujo operator --help (experimental local batch host)", "kujo run dispatch.kujo catalog --output model-catalog.json", "kujo run dispatch.kujo webhooks [--output-root outputs] [--url https-url] [--destination lifecycle] [--json]", "kujo run dispatch.kujo demo \"Research topic\" [--workflow research-report] [--policy-profile staging] [--tags prod,project-a] [--yes] [--non-interactive] [--output-root outputs]", diff --git a/tests/operator_rehearsal.mjs b/tests/operator_rehearsal.mjs new file mode 100644 index 0000000..6f5748c --- /dev/null +++ b/tests/operator_rehearsal.mjs @@ -0,0 +1,55 @@ +// Black-box installed-package rehearsal. No fixture imports or state mutations. +import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; +import {spawn, spawnSync} from 'node:child_process'; +import {createHash} from 'node:crypto'; +import assert from 'node:assert/strict'; +const source=process.cwd(),root=fs.mkdtempSync(path.join(os.tmpdir(),'dispatch-operator-')); +const installation=path.join(root,'installed'),home=path.join(root,'home'),evidence=path.join(root,'evidence'); +for(const p of [installation,home,evidence])fs.mkdirSync(p,{recursive:true}); +const files=spawnSync('git',['ls-files','--cached','--others','--exclude-standard','-z'],{encoding:'utf8'}).stdout.split('\0').filter(Boolean); +for(const file of files){if(!fs.statSync(path.join(source,file)).isFile())continue;const p=path.join(installation,file);fs.mkdirSync(path.dirname(p),{recursive:true});fs.copyFileSync(path.join(source,file),p)} +const deps=process.env.DISPATCH_OPERATOR_DEPS||path.join(source,'.operator-deps'); +for(const name of ['workcell','eval']){const from=path.join(deps,name);assert.ok(fs.existsSync(from),'Install pinned operator dependencies first: bash scripts/install_operator_dependencies.sh');fs.cpSync(from,path.join(installation,'.operator-deps',name),{recursive:true})} +const runtime=path.resolve(process.env.KUJO_BIN||'../kujo/target/release/kujo'); +const env={HOME:home,PATH:process.env.PATH,KUJO_BIN:runtime,TMPDIR:root,LANG:'C',DISPATCH_ROOT:installation}; +const entry=path.join(installation,'scripts/operator.sh');let sequence=0; +function command(args,{allowFailure=false,json=true}={}){const serial=sequence++;return new Promise((done,reject)=>{const p=spawn('bash',[entry,...args],{env,cwd:home});let out='',err='';const timer=setTimeout(()=>p.kill('SIGKILL'),240000);p.stdout.on('data',b=>out+=b);p.stderr.on('data',b=>err+=b);p.on('close',(status,signal)=>{clearTimeout(timer);fs.writeFileSync(path.join(evidence,`${serial}.json`),JSON.stringify({argv:args,status,signal,stdout:out,stderr:err}));try{assert.equal(err,'',err);assert.equal(signal,null,out);if(!allowFailure)assert.equal(status,0,out);let value=json?JSON.parse(out):out;if(json)assert.equal(value.ok,status===0,JSON.stringify(value));done(value)}catch(e){reject(e)}})})} +const publicHelp=spawnSync(runtime,['run',path.join(installation,'dispatch.kujo'),'operator','--help'],{env,cwd:home,encoding:'utf8'});assert.equal(publicHelp.status,0,publicHelp.stderr);assert.match(publicHelp.stdout,/Experimental local batch-summary/); +const check=(v)=>{assert.equal(v.ok,true,JSON.stringify(v));return v}; +async function initialize(name,settings={}){const d=path.join(root,name),config=path.join(root,name+'.json');fs.writeFileSync(config,JSON.stringify({schema:'dispatch.batch-summary/v1alpha1',amounts:[12,18,20],expected_total:50,program_limit:2,eval_limit:1,...settings}));check(await command(['init',d,config]));return d} +async function plan(d,action,id='graph'){return check(await command(['plan',d,action,id]))} +async function apply(d,p,allowFailure=false){const file=path.join(evidence,`plan-${sequence}.json`);fs.writeFileSync(file,JSON.stringify(p));return command(['apply',d,file],{allowFailure})} +async function operation(d,action,id='graph'){return check(await apply(d,await plan(d,action,id)))} +async function run(d){const r=check(await command(['run',d]));assert.equal(r.schema,'dispatch.operator-action/v1alpha1');assert.equal(r.run_state,undefined);return r} +async function inspect(d){return check(await command(['inspect',d,'--json']))} +async function finish(d,id){for(const action of ['refresh','select','admit','refresh','parent-finalize'])await operation(d,action,id);await run(d)} +function snapshot(directory){const entries=[];function walk(d){for(const e of fs.readdirSync(d,{withFileTypes:true})){const p=path.join(d,e.name);if(e.isDirectory())walk(p);else if(e.isFile()&&!e.name.endsWith('.lock'))entries.push([path.relative(directory,p),createHash('sha256').update(fs.readFileSync(p)).digest('hex')])}}walk(directory);return entries.sort((a,b)=>a[0].localeCompare(b[0]))} +const proofs=[];function pass(s){proofs.push(s);console.log('PASS '+s)} +async function prefix(d){await operation(d,'reserve','A');await run(d);await finish(d,'A');await command(['review',d])} +async function crashReservation(d){ + const reservation=await plan(d,'reserve','A'),requestFile=path.join(evidence,'crash-reservation.json');fs.writeFileSync(requestFile,JSON.stringify(reservation)); + const records=path.join(d,'runs',reservation.run_id,'control-records'),known=new Set(fs.readdirSync(records)); + await new Promise((done,reject)=>{let killed=false,out='',err='';const child=spawn('bash',[entry,'apply',d,requestFile],{env,cwd:home}); + const scan=()=>{for(const name of fs.readdirSync(records)){if(known.has(name)||!name.endsWith('.json'))continue;try{const record=JSON.parse(fs.readFileSync(path.join(records,name),'utf8'));if(record.kind==='graph_resources_reserved'&&!killed){killed=true;child.kill('SIGKILL')}}catch{}}}; + const watcher=fs.watch(records,scan),interval=setInterval(scan,5),timeout=setTimeout(()=>child.kill('SIGKILL'),120000); + child.stdout.on('data',x=>out+=x);child.stderr.on('data',x=>err+=x);child.on('close',(code,signal)=>{watcher.close();clearInterval(interval);clearTimeout(timeout);fs.writeFileSync(path.join(evidence,'crash.json'),JSON.stringify({code,signal,killed,out,err}));try{assert.ok(killed,'did not reach durable reservation');assert.equal(signal,'SIGKILL');done()}catch(e){reject(e)}}) + }); + const recovery=await plan(d,'recover');if(recovery.request.plan.repairs.length)check(await apply(d,recovery)); + const report=await inspect(d);assert.equal(report.resources.report.programs.consumed,0);assert.equal(report.resources.report.programs.reserved,1);assert.equal(report.nodes.find(n=>n.node_id==='A').output,undefined); + pass('real SIGKILL after immutable reservation; fresh recovery retains capacity without execution or replay'); +} +async function happy(){const d=await initialize('happy');const initial=await inspect(d);assert.ok(initial.nodes.filter(n=>n.kind==='program').every(n=>n.execution_state==='never_dispatched'));await crashReservation(d);await run(d);await finish(d,'A');await command(['review',d]); + const before=snapshot(d),approval=await plan(d,'approve','H');await inspect(d);assert.deepEqual(snapshot(d),before);pass('inspection and candidate planning leave durable contents unchanged'); + const wrong=structuredClone(approval);wrong.request.decision.subject.run_id='wrong';assert.equal((await apply(d,wrong,true)).ok,false);await command(['review',d]);assert.equal((await apply(d,approval,true)).ok,false);await operation(d,'approve','H');const reviewed=await inspect(d);assert.equal(reviewed.resources.report.evaluations.consumed,0);pass('wrong/stale human decisions rejected; authorized approval does not dispatch Eval'); + await operation(d,'reserve','E');await operation(d,'eval-dispatch','E');await operation(d,'observe','E');await operation(d,'node-finalize','E');await operation(d,'branch');await operation(d,'reserve','B');await run(d);await finish(d,'B');await operation(d,'graph-finalize'); + const result=await inspect(d);assert.equal(result.outcome.receipt.candidate.outcome,'completed');assert.equal(result.resources.report.programs.consumed,2);assert.equal(result.resources.report.evaluations.consumed,1);assert.equal(result.resources.report.evaluations.available,0);assert.equal(result.resources.report.monetary_cost.value,null);assert.equal(result.resources.report.totals.reported_input_tokens.total,null);assert.ok(result.resources.report.totals.process_wall_ns.known_sum>0); + const a=result.nodes.find(n=>n.node_id==='A'),b=result.nodes.find(n=>n.node_id==='B');assert.equal(b.output.value,50);assert.ok(b.output.sources.includes('sha256:'+a.output_sha256));assert.equal(b.output.source_ref,result.source_ref);assert.equal(result.outcome.receipt.candidate.nodes.find(n=>n.node_id==='R').reason,'not_selected'); + const human=await command(['inspect',d],{json:false});assert.match(human,/Graph terminal decision: completed/);assert.match(human,/Monetary cost \[unknown\]: unknown/);fs.writeFileSync(path.join(evidence,'happy-human.txt'),human); + fs.writeFileSync(path.join(evidence,'happy-report.json'),JSON.stringify(result,null,2));pass('installed happy path finalizes with exact provenance and exhausted budgets; unknown usage remains null'); +} +async function qualityFailure(){const d=await initialize('quality-failure',{expected_total:99});await prefix(d);await operation(d,'approve','H');await operation(d,'reserve','E');await operation(d,'eval-dispatch','E');await operation(d,'node-finalize','E');await operation(d,'branch');assert.equal((await command(['plan',d,'reserve','B'],{allowFailure:true})).ok,false);await operation(d,'reserve','R');await run(d);await finish(d,'R');await operation(d,'graph-finalize');const report=await inspect(d);assert.equal(report.outcome.receipt.candidate.outcome,'completed');assert.equal(report.outcome.receipt.candidate.nodes.find(n=>n.node_id==='B').reason,'not_selected');assert.equal(report.nodes.find(n=>n.node_id==='E').terminal.terminal.outcome,'failed');fs.writeFileSync(path.join(evidence,'failure-report.json'),JSON.stringify(report,null,2));pass('real Eval failure routes repair; failed verdict survives and inactive consumer consumes nothing')} +async function exhaustion(){const d=await initialize('exhausted',{eval_limit:0});await prefix(d);await operation(d,'approve','H');const denied=await command(['plan',d,'reserve','E'],{allowFailure:true});assert.equal(denied.ok,false);assert.match(JSON.stringify(denied),/eval_plan_capacity/);const report=await inspect(d);assert.equal(report.resources.report.evaluations.available,0);assert.notEqual(report.outcome.candidate.outcome,'completed');pass('exhaustion names Eval capacity and blocks new work without rewriting completed producer')} +await happy();await qualityFailure();await exhaustion(); +console.log(JSON.stringify({ok:true,proofs,root,evidence,installation,runtime}));