Skip to content

Command-line workflows

The ExecKernel CLI works on graph definitions and their artifacts. You can use it while editing a graph, before accepting a change in CI, or when you need a portable definition or a diagram for review. A useful workflow checks the input first, gives you enough information to inspect it, and produces the required artifact only after those checks succeed.

The commands below run from an existing Composer project that provides vendor/bin/execkernel. See Installation and requirements if that executable is not available yet.

Task Command How your application or team uses the result
Check that a definition can be accepted under strict validation validate Stop a build or reject a proposed graph when the definition fails.
Find presentation and authoring issues lint Review warnings about missing text, labels or terminal outputs.
Read nodes, labels, connections and declared conditions explain Inspect what the definition describes in a selected language.
Summarize the graph’s structure graph stats Record counts and structural information alongside a review.
Produce another representation graph export Write JSON/YAML for tools or Mermaid for a diagram.

These commands load a definition. They do not start an application session or decide which choice is currently enabled for a person’s context. For example, explain shows a condition attached to an edge; the engine evaluates that condition when handling an actual session.

We reuse the learning-choice example from Anatomy of a graph. Node 10 offers a guide through edge 101, reaching terminal 20, and practice through edge 102, reaching terminal 30. Practice requires practiceEnabled: true.

For this workflow, the example has its own graph code, learning-path-review. The broken draft points edge 102 at node 99, which is absent from the definition. The corrected definition points it at 30.

Start with the failed draft:

Terminal window
vendor/bin/execkernel validate cli-learning-path-broken.json --json

The command exits with code 1. Its JSON report includes this error; the timestamp and other envelope fields are omitted here:

{
"ok": false,
"error": {
"ek_code": "EK-SEC-LOD-001",
"context": {
"edge_id": 102,
"from": 10,
"to": 99,
"validation_ek_code": "EK-GRAPH-010"
}
}
}

The outer code reports the blocked load. The validation code and context identify the concrete problem: edge 102 references a node that is not present. Correct its destination while preserving the choice:

{ "id": 102, "from": 10, "to": 30 }

Run the check on the corrected file:

Terminal window
vendor/bin/execkernel validate cli-learning-path.json --json

This time the exit code is 0, ok is true, and the summary is:

{
"nodes": 3,
"edges": 2,
"terminal_nodes": 2,
"warnings": 0
}

Use the command’s exit code to control the next automation step and keep its JSON report to explain a failure. The validation guide develops how graph validation and diagnostics relate.

Validation answers whether the definition passes its checks. Review also needs to answer what your application will present and which routes the graph describes:

Terminal window
vendor/bin/execkernel lint cli-learning-path.json --json
vendor/bin/execkernel explain cli-learning-path.json --lang=en --json
vendor/bin/execkernel graph stats cli-learning-path.json --json

explain returns the localized node titles and edge labels together with their connections and conditions. At node 10, you can inspect the routes to 20 and 30 and see the condition attached to practice. Changing --lang=en to --lang=es selects the Spanish presentation data; it does not change the graph’s numeric IDs.

Read data.warnings in the lint report as well as the exit code. A terminal without outputs is allowed, so such a graph can pass validate; lint can still emit lint.terminal_missing_outputs and exit successfully. Your team decides whether that warning is acceptable for the application. An empty terminal may be intentional, while another application needs a message or an action there.

For this complete example, both validation and lint report zero warnings. A successful review still leaves the runtime behavior of your application’s contexts and extensions to the relevant execution checks.

To give another tool a portable definition, export JSON:

Terminal window
vendor/bin/execkernel graph export cli-learning-path.json --format=json --out=cli-reviewed.json
vendor/bin/execkernel validate cli-reviewed.json --json

The exporter serializes the loaded graph into the schema representation. The second command checks the produced file as an input in its own right. The export can normalize the representation; it need not preserve the source file’s formatting or byte order.

For a review diagram, select Mermaid and the language used by its labels:

Terminal window
vendor/bin/execkernel graph export cli-learning-path.json --format=mermaid --lang=en --out=cli-reviewed.mmd

The .mmd file describes the three nodes, both connections and the rule marker on the practice choice. Open it in a Mermaid renderer to see the graph. Use --format=mermaid-rich when you need the richer supported representation, or --format=yaml for a YAML schema export. Import, export and Mermaid explains these representations.

With --out, the CLI creates a new file and refuses an existing output path. In this workflow, a second export to cli-reviewed.json exits with code 5 and leaves that file unchanged. Choose a new artifact name or deliberately manage the old file before exporting again.

Without --out, the artifact is written to standard output. Export warnings use standard error, keeping the artifact stream separate. Shell redirection such as > existing.json is handled by your shell and can overwrite an existing file before the CLI runs; use --out when you want the CLI’s existing-file check.

The complete cli-review.sh workflow takes an input file and a new output directory. It preserves the validation report when the input fails and stops before exporting. This is the part that carries the validation result into the shell:

Terminal window
if vendor/bin/execkernel validate "$graph" --json > "$out/validation.json"; then
:
else
code=$?
echo "Validation failed; read $out/validation.json" >&2
exit "$code"
fi

Capturing $? immediately preserves the CLI’s failure code. After a successful validation, the script collects lint and explanation reports, exports JSON, validates that export and creates the Mermaid file.

Place the downloaded script and graph in your existing project, then run:

Terminal window
sh cli-review.sh cli-learning-path.json review-output

The new directory contains:

File Purpose
validation.json Result of validating the source.
lint.json Authoring and presentation warnings for review.
explanation.json Nodes, labels and conditions in English.
graph.json Exported schema representation.
export-validation.json Result of validating the exported definition.
graph.mmd Diagram source for a Mermaid renderer.

The script exits with 0 for the corrected input. With the broken draft and another new directory, it exits with 1 and leaves only validation.json. Its lint step records warnings but does not impose a warning policy; add a deliberate check of that report if your CI must reject specific warnings.

Use templates and scaffolding when your starting point is a reusable template. Use graph migrations and rollback when a change must be represented as a plan tied to an existing definition. The scaffold and migrate command families support those separate tasks.

optimize analyzes a graph under its chosen checks and work limits. bench compares or formats supplied performance evidence; a report command needs measurements collected beforehand. See Performance and benchmarking for that workflow, and CLI commands, options and exit codes for the complete lookup reference.