agent-cli-sdk

    Shared MoonBit process foundation for JSONL agent CLIs

    agent
    cli
    jsonl
    sdk
    moonbit
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    3 months ago
    Downloads
    95

    #Agent CLI SDK

    agent-cli-sdk provides the shared native process lifecycle for MoonBit SDKs that run agent CLIs and consume JSONL events.

    Provider SDKs remain responsible for building CLI arguments and environment variables, decoding provider-specific events, and aggregating turns. This package owns stdin delivery, ordered JSONL parsing, stderr capture, exit status reporting, callback-requested termination, and cancellation-safe child cleanup.

    let result = @agent_cli.run(
    @agent_cli.Invocation::new(
    command="agent",
    arguments=["run", "--format", "json"],
    input="Hello",
    ),
    async fn(line) {
    println(line.value.stringify())
    true
    },
    )

    AgentCliError

    pub(all) suberror AgentCliError {
    InvalidJson(line~ : String, cause~ : String)
    } derive(Eq,
    Debug
    )

    Errors raised while reading the JSONL protocol.

    Invocation

    pub(all) struct Invocation {
    command : String
    arguments : Array[String]
    environment : Map[String, String]
    inherit_environment : Bool
    input : String
    }

    A complete invocation of a JSONL-emitting agent CLI.

    Invocation::new

    fn Invocation::new(command~ : String, arguments~ : Array[String], input~ : String, environment? : Map[String, String], inherit_environment? : Bool) -> Invocation

    Construct an agent CLI invocation.

    JsonLine

    pub(all) struct JsonLine {
    raw : String
    value : Json
    } derive(Eq,
    Debug
    )

    One JSONL record with both its original text and parsed JSON value.

    RunResult

    pub(all) enum RunResult {
    Completed
    Stopped
    Failed(code~ : Int, stderr~ : String)
    } derive(Eq,
    Debug
    )

    The process-level outcome of an agent CLI invocation.

    run

    async fn run(invocation : Invocation, on_event : async (JsonLine) -> Bool) -> RunResult

    Run an agent CLI, write its stdin, and stream parsed JSONL events in order.

    Returning false from on_event terminates the child and returns Stopped. A nonzero child exit is returned as Failed; process and callback errors are raised after all child resources have been cleaned up.

    Source Files

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io