agent-cli-sdk

Shared MoonBit process foundation for JSONL agent CLIs

agent
cli
jsonl
sdk
moonbit
moon add totto2727/agent-cli-sdk@0.2.1
Download zip
Author
Version
0.2.1
License
MIT
Last updated
10 days ago
Downloads
60

Dependencies

README

#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, defining provider-specific event types with FromJson, and aggregating turns. This package owns stdin delivery, ordered JSONL parsing and typed decoding, stderr capture, exit status reporting, callback-requested termination, and cancellation-safe child cleanup.

struct Event {
message : String
} derive(FromJson)

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

#
AgentCliError

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

Errors raised while reading or decoding 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.

#
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[T :
FromJson
] run(invocation : Invocation, on_event : async (T) -> Bool) -> RunResult

Run an agent CLI, write its stdin, and stream decoded 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 issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io