workgraph-opencode-cli

    OpenCode CLI integration for workgraph

    agent
    graph
    moonbit
    opencode
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    3 hours ago
    Downloads
    72

    #moonbit: import: - path: moonbitlang/async@0.21.0 alias: async - path: moonbitlang/core/immut/hashmap alias: immut_hashmap - path: moonbitlang/x@0.5.1/path alias: path - path: totto2727/agent-sdk@0.2.1/cli alias: cli - path: totto2727/workgraph-agent-cli@0.2.1 alias: coding - path: totto2727/workgraph-opencode-cli@0.2.1 alias: opencode - path: totto2727/workgraph-core@0.1.4 alias: core backend: native

    #workgraph-opencode-cli

    workgraph-opencode-cli owns the OpenCode-native OpenCodeAgentOptions and opencode_agent composition root for the provider-neutral Workgraph coding-agent contract. For shared installation and graph construction, see the root Setup and Usage.

    #Usage

    Send a task through an OpenCode-backed graph node and return its final response from graph state:

    ///|
    pub async fn run_opencode_graph() -> String raise {
    let entry = @core.NodeId::NodeId("opencode")
    let agent = @opencode.opencode_agent(
    @coding.CodingAgentId::CodingAgentId("opencode-cli"),
    @opencode.OpenCodeAgentOptions::OpenCodeAgentOptions(),
    )
    let node = @coding.coding_agent_node(
    entry,
    @core.NodeMetadata::NodeMetadata(
    name="OpenCode",
    description=None,
    kind=@core.CodingAgent,
    tags=[],
    ),
    @coding.CodingAgentNodeSpec::CodingAgentNodeSpec(
    agent~,
    resource_key=@core.ResourceKey::ResourceKey("opencode-session"),
    resource_scope=@core.Run,
    open_context=fn(context, _state) {
    @coding.CodingAgentOpenContext::CodingAgentOpenContext(
    run_id=context.run_id,
    task_group=context.task_group,
    workspace=@coding.WorkspaceRef::WorkspaceRef(@path.Path("."), []),
    approval=@coding.Never,
    network=@coding.Disabled,
    environment=@immut_hashmap.new(),
    events=context.events,
    )
    },
    build_prompt=fn(_context, state : String) { @cli.Prompt::Prompt(state) },
    select_continuation=fn(_context, _state) { None },
    decode_response=fn(_state, response, _continuation) {
    @core.NodeOutput::NodeOutput(Some(response.text), None)
    },
    ),
    )
    let definition = @core.GraphDefinition::GraphDefinition(
    @core.Reducer::Reducer(fn(_state : String, patch : String) { patch }),
    )
    definition.add_node(node)
    definition.set_router(
    entry,
    @core.router([], fn(_state, _completion) { @core.End }),
    )
    definition.set_entry(entry)
    let result = @core.GraphRuntime::GraphRuntime(definition.compile()).invoke(
    "Reply with WORKGRAPH_OPENCODE_OK only. Do not modify files or use tools.",
    )
    result.final_state
    }

    Version 0.2.1 prefers Wasm/WASI and supports Wasm/WASI and native from the same production source; JavaScript is not supported. It resolves totto2727/agent-sdk@0.2.1 and totto2727/opencode-sdk@0.4.1 from the MoonBit registry.

    With an installed and configured OpenCode CLI, the expected result is WORKGRAPH_OPENCODE_OK. The literate function is type-checked without executing credentials; the runnable OpenCode example executes the same prompt-to-result flow.

    #API

    This README was generated from the share-artifact skill and README template.

    OpenCodeAgentOptions

    pub struct OpenCodeAgentOptions {
    opencode_path_override :
    Path
    ?
    config : Map[String,
    Json
    ]?
    resume_thread_id : String?
    model : String?
    agent : String?
    variant : String?
    title : String?
    thinking : Bool
    extra_env : Map[String, String]
    }

    Configuration shared by every OpenCode CLI session opened by this adapter.

    OpenCodeAgentOptions::OpenCodeAgentOptions

    fn OpenCodeAgentOptions::OpenCodeAgentOptions(opencode_path_override? :
    Path
    , config? : Map[String,
    Json
    ], resume_thread_id? : String, model? : String, agent? : String, variant? : String, title? : String, thinking? : Bool, extra_env? : Map[String, String]) -> OpenCodeAgentOptions

    Creates OpenCode adapter options with the CLI SDK's defaults.

    opencode_agent

    Creates a coding agent backed by the provider-neutral OpenCode CLI factory.

    Source Files