8000 GitHub - arminhammer/jackdaw-workflow-library · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

jackdaw-workflow-library

Reusable, composable workflows for the Jackdaw durable workflow engine.

Categories & Cargo Features

All workflow categories are opt-in (default = []) so your binary only compiles the dependencies it uses:

Feature Module Dependencies Description
fetch fetch gosh-dl, jackdaw-wf, tokio Multi-source, resumable HTTP(S) and file:///local download workflows (FetchFile, FetchBatch) with mirror fallback and SHA-256 verification.
duckdb data duckdb, jackdaw-wf, tokio, regex In-process DuckDB SQL step workflows (RunSqlStep, RunSqlPipeline, QueryJson), @NAME@ template rendering, Arrow batch streaming, and sql_steps!. Links prebuilt libduckdb by default.
duckdb-bundled — duckdb/bundled Compiles DuckDB from source into the binary (self-contained; ~3–15 minutes cold).
slicer slicer rmcp, zip, jackdaw-wf, tokio 3D print slicing through an OrcaSlicer MCP server (SliceModel), G-code guards, and the bundled orca-mcp server.
solidcraft solidcraft rmcp, jackdaw-wf, tokio CAD through the SolidCraft MCP server: build a part from a command script, export STEP/STL/3MF, measure and render.
full fetch, data, slicer, solidcraft — Enables all workflow categories without duckdb-bundled.

A download that stops (killed, timed out, network error) leaves its bytes beside the destination and the next call carries on from them. A partial that fails the checksum, or that the server cannot continue, is removed and downloaded afresh. Setting max_connections above 1 downloads large files in segments instead, which start over after an interruption.

Request headers (API keys)

A header's value is named by an environment variable and read when the request is made, so a FetchSpec, and the workflow journal that stores it, holds the variable's name only:

let spec = FetchSpec::new("https://api.wmata.com/gtfs/rail-gtfs-static.zip", dir.join("wmata.zip"))
    .with_env_header("api_key", "WMATA_API_KEY");

In serialized form: "headers": [{"name": "api_key", "env": "WMATA_API_KEY"}]. A variable that is not set fails the fetch without retries, naming the variable.

  • Headers go only to the origin (scheme, host and port) of the first source. A mirror or a redirect target anywhere else, including an http to https upgrade, is asked without them, and a redirect chain that has left that origin never gets them back.
  • A fetch with headers is one resumable stream: max_connections has no effect, and a failed source is followed by the next one without retries of its own.
  • An http:// source sends the value in clear text; use https://.

Quick Start

Add jackdaw-workflow-library to your Cargo.toml:

[dependencies]
jackdaw-wf = "0.3.0"
jackdaw-workflow-library = { version = "0.1.0", features = ["fetch", "duckdb", "slicer", "solidcraft"] }

Register the library's tasks and workflows on your Jackdaw EngineBuilder, then compose them inside your own #[workflow]:

use jackdaw::prelude::*;
use jackdaw_workflow_library::data::{RunSqlStep, SqlSource, SqlStep};
use jackdaw_workflow_library::fetch::{FetchFile, FetchSpec};
use std::collections::BTreeMap;
use std::path::PathBuf;

#[workflow(namespace = "example", name = "ingest", version = "1.0.0")]
struct IngestWorkflow;

#[workflow_methods]
impl IngestWorkflow {
    #[run]
    async fn run(ctx: &mut WorkflowContext<Self>, dir: PathBuf) -> WorkflowResult<u64> {
        // 1. Fetch a Parquet file with mirror fallback
        let spec = FetchSpec::new("https://example.com/data.parquet", dir.join("raw.parquet"))
            .with_mirrors(["https://mirror.example.com/data.parquet".into()]);
        let fetched = ctx.run(FetchFile::run, &spec).await?;

        // 2. Transform it idempotently with DuckDB
        let step = SqlStep {
            dir,
            name: "summarize".into(),
            sql: SqlSource::Inline(
                "COPY (SELECT count(*) AS n FROM read_parquet('raw.parquet')) TO 'summary.parquet' (FORMAT parquet)".into(),
            ),
            vars: BTreeMap::new(),
            env: BTreeMap::new(),
            outputs: vec!["summary.parquet".into()],
            memory: None,
            temp: None,
        };
        ctx.run(RunSqlStep::run, &step).await?;
        Ok(fetched.bytes)
    }
}

Slicing

SliceModel (jwl/slice-model) turns a model (.stl, .3mf, .step, .stp), machine/process/filament preset names and an AMS slot (1 to 4) into a checked .gcode.3mf with a print time and filament estimate. It starts a slicer MCP server over stdio and calls its slice tool.

OrcaSlicer output is unverified. Everything is tested against fake servers and a fake CLI; no real OrcaSlicer run and no print of its output has happened. The server's command line and preset layering follow the OrcaSlicer 2.5.3 sources. The G-code guards were also run against a real A1 mini file sliced by Bambu Studio.

use jackdaw::prelude::*;
use jackdaw_workflow_library::slicer::{ServerCommand, SliceModel, SliceSpec};

# async fn example(ctx: &mut WorkflowContext<SliceModel>) -> WorkflowResult<()> {
let mut server = ServerCommand::new("orca-mcp");
server.args = vec![
    "--slicer".into(),
    "/opt/OrcaSlicer/orca-slicer".into(),
    "--profiles".into(),
    "/opt/OrcaSlicer/resources/profiles/BBL".into(),
];
let spec = SliceSpec {
    server,
    model: "part.stl".into(),
    output: "out/part.gcode.3mf".into(),
    machine: "Bambu Lab A1 mini 0.4 nozzle".into(),
    process: "0.20mm Standard @BBL A1M".into(),
    filament: "Bambu PLA Basic @BBL A1M".into(),
    ams_slot: 1,
    filament_type: Some("PLA".into()),
    bed_type: None, // A1 mini: "Textured PEI Plate"
    timeout_s: 600,
};
let sliced = ctx.run(SliceModel::run, &spec).await?;
println!("{} s, {} g", sliced.estimate.print_time_s, sliced.estimate.filament_g);
# Ok(())
# }

The orca-mcp server

Install it with cargo install jackdaw-workflow-library --features slicer --bin orca-mcp (or cargo build --features slicer --bin orca-mcp).

Option Environment Meaning
--profiles DIR (repeatable) ORCA_PROFILES (path list) Preset directories holding machine/, process/, filament/, searched in order. Required.
--slicer PROGRAM ORCA_SLICER OrcaSlicer program (default orca-slicer).
--slicer-arg ARG (repeatable) Fixed arguments before the slicer's own, for wrappers.

It resolves each preset's inherits and include chain (and Bambu's <machine> template <key> G-code presets), runs the CLI, writes the AMS slot, filament id and printer model id into slice_info.config, and applies the guards. It has one tool and no printer access; tool arguments never choose what is executed.

Guards

A slice that fails is 8000 an error, and the destination file is left as it was.

Printer Required
Bambu Lab A1 mini A1 mini start header, M190, M109, G28, M620 S0A then M621 S0A in the start G-code; layer notifications (M991); "turn off hotend" end G-code; extrusion moves.
Other Bambu Lab M190, M109, G28, M991, end G-code, extrusion moves.
Any other A layer change marker and extrusion moves after it.

Comments (including the slicer's CONFIG_BLOCK copy of the preset G-code) never satisfy a check. Every file must also hold exactly one plate, a time and filament estimate, and the requested AMS slot. Multi-filament and multi-plate jobs are not supported.

The AMS slot is metadata for the sender: the G-code is slot independent.

Using another MCP server

The server must offer a tool (name set by ServerCommand::tool) accepting the arguments of slicer::server::SliceArgs, write the .gcode.3mf to output_path, and report failures with isError: true. The file is verified whatever the server claims. No existing OrcaSlicer MCP server met this when orca-mcp was written.

CAD with SolidCraft

SolidCraft is a CAD application whose solidcraft-cli mcp serves MCP over stdio. A part is a JSON list of commands, so nothing is compiled and the script is data, not code. Tested against SolidCraft 0.48.1; its 0.x command set may change.

scripts/install-solidcraft.sh   # pinned 0.48.1, linux x86_64, sha256 checked, into tools/ (git-ignored)
Workflow Name Does
ListCadTools jwl/solidcraft-list-tools The server's tools and their argument schemas.
BuildPart jwl/solidcraft-build-part Runs a command script on an empty design, then measures it, saves <name>.sc, exports STEP/STL/3MF and renders <name>.png.
ExportModel jwl/solidcraft-export Exports a .sc, .step, .stp, .stl or .3mf file of the run folder.
MeasureModel jwl/solidcraft-measure Volume, area, bounding box, centre of mass and face and edge counts.
RenderPreview jwl/solidcraft-render A PNG from a standard or saved view.
use jackdaw::prelude::*;
use jackdaw_workflow_library::solidcraft::{
    BuildPart, BuildPartSpec, ScriptSource, SolidcraftError, SolidcraftServer,
};

# async fn example(ctx: &mut WorkflowContext<BuildPart>) -> WorkflowResult<()> {
let spec = BuildPartSpec::new(
    SolidcraftServer::new("tools/solidcraft/solidcraft-0.48.1-linux-x86_64/bin/solidcraft-cli"),
    "runs/bracket",
    ScriptSource::File("bracket.json".into()), // {"commands": [{"command": ..., "params": ...}]}
    "bracket",
);
match ctx.run(BuildPart::run, &spec).await {
    Ok(part) => println!("{:?} mm", part.measurement.bbox.size()),
    Err(WorkflowError::Fault(fault)) => match SolidcraftError::from_fault(&fault) {
        Some(SolidcraftError::Step { step, command, message, .. }) => {
            println!("fix step {step} ({command}): {message}");
        }
        _ => return Err(fault.into()),
    },
    Err(other) => return Err(other),
}
# Ok(())
# }

Typed failures

Every failure is a SolidcraftError. In a workflow it arrives as a Fault titled solidcraft.<code> whose detail is the error as JSON; SolidcraftError::from_fault decodes it.

Code Meaning Retryable
step A script command failed (step, command, message, completed, rolled_back). no
tool Another tool answered isError: true, or a model opened with failed features. no
protocol The server refused the request (JSON-RPC error). no
invalid_input Bad name, script or model path; the server was not started. no
empty_design No bodies to measure or export. no
output The server claimed success but its answer or file is unusable. no
start The configured binary cannot be started. no
timeout, connection, io Too slow (the server is stopped), lost, or a local file error. yes

File access

The server runs in the run folder, started with mcp --headless --require-allow-path --allow-path <run folder> --param-check strict, and no request can widen that. SolidCraft also always allows its own crash-recovery folder (~/.local/share/solidcraft/recovery) and a per-process temporary folder. Models for export, measure and render must lie inside the run folder. Script files are read by the library and may be anywhere, so do not let untrusted callers choose them, the binary or the run folder.

Outputs are written to a staging folder and moved into place only when every one of them passed; a failure leaves earlier files as they were. Files that the script itself writes (file.export) are not staged.

Each workflow starts its own server (the design lives in the server process); SolidcraftServer::timeout_s (default 120) limits the whole run.

DuckDB Builds

By default (duckdb feature), duckdb-rs links a prebuilt libduckdb v2.0.0 (DUCKDB_LIB_DIR / DUCKDB_INCLUDE_DIR) for fast incremental builds and CI. Enable duckdb-bundled in release builds when you want DuckDB compiled statically into the binary.

Development & Testing

# Format & Clippy (pedantic + panic-free)
cargo fmt --all -- --check
cargo clippy --all-targets --features full -- -D warnings

# Run BDD scenarios, unit tests, and doc tests
cargo test --features full --lib
cargo test --features full --doc
cargo test --features full --test bdd

# Opt-in: check a real A1 mini file, or slice with a real OrcaSlicer
JWL_SLICED_FILE=part.gcode.3mf cargo test --features full --test bdd
JWL_ORCA=1 ORCA_SLICER=orca-slicer ORCA_PROFILES=/path/to/profiles/BBL JWL_ORCA_MODEL=/path/to/part.stl \
  cargo test --features full --test bdd

# Opt-in: run the real solidcraft-cli (install it with scripts/install-solidcraft.sh)
JWL_SOLIDCRAFT=1 SOLIDCRAFT_CLI=$PWD/tools/solidcraft/solidcraft-0.48.1-linux-x86_64/bin/solidcraft-cli \
  cargo test --features full --test bdd

# Verify docs.rs build
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps

License

Licensed under the Apache License, Version 2.0.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0