sequenceDiagram
participant P as Parent runner
participant S as Your shim
participant C as Agent CLI
P->>S: One request line
Note over P,S: Keep stdin open<br/>as the cancellation channel
S->>C: Prompt in argv
Note over S,C: CLI stdin is already closed
C-->>S: CLI-specific stdout lines
alt Normal completion
S-->>P: Result file: completed, usage, steps
else Parent cancels
P->>S: Close stdin
S->>C: SIGINT, then kill after grace
S-->>P: Result file: interrupted
end///|
async fn main {
@shim.serve(default_command="my-agent", run=(options, request) => {
let exit = @shim.run_cli(
command=options.command,
args=["--prompt", request.prompt],
observe=_ => @shim.Continue,
)
match exit {
Exited(0) => @shim.ShimResult(NoReport, steps=0)
Exited(code) => @shim.ShimResult(Failed("exited \{code}"))
Stopped => @shim.ShimResult(MaxStepsExhausted)
Cancelled => @shim.ShimResult(Interrupted("the parent closed stdin"))
Failed(reason) => @shim.ShimResult(Failed(reason))
}
})
}{"version":1,"request_id":"probe-1","kind":"explore","limits":{"max_steps":8},"input":{"query":"Find the entry point","hints":"Look in src/"}}| Option | Parsed value |
|---|---|
| --result-file PATH | Required. Where the result file goes; a launch passes {result_file}. |
| --command EXE | CLI executable; defaults to the dialect's command name. |
| --model NAME | Model name forwarded by the dialect. |
| --cwd DIR | Child working directory. |
| --writable | Request a write-capable run; default false. |
| --schema FILE | Default schema file when the request supplies no schema. |
| -- ARGS... | Remaining arguments passed through unchanged, in options.extra. |
| Status | Result status | Meaning |
|---|---|---|
| Completed(report) | completed | The CLI finished; report is the result's output. |
| NoReport | no_report | The CLI exited cleanly without an answer. |
| MaxStepsExhausted | max_steps_exhausted | The step ceiling stopped the run. |
| Interrupted(reason) | interrupted | The parent closed stdin. |
| Failed(reason) | failed | The run could not finish. |
///|
test "a completed result document" {
let usage = @shim.Usage(
prompt_tokens=10,
completion_tokens=4,
cache_hit_tokens=6,
cache_miss_tokens=4,
)
assert_eq(
@shim.ShimResult(Completed({ "answer": "ok" }), usage~, steps=1).to_json(
request_id="probe-1",
),
{
"version": 1,
"request_id": "probe-1",
"status": "completed",
"output": { "answer": "ok" },
"usage": {
"prompt_tokens": 10,
"completion_tokens": 4,
"total_tokens": 14,
"prompt_cache_hit_tokens": 6,
"prompt_cache_miss_tokens": 4,
},
"steps": 1,
},
)
}| CliExit | Adapter action |
|---|---|
| Exited(code) | Inspect dialect state for a report or failure; a nonzero exit without a report is Failed. |
| Stopped | The observer requested a stop, usually a step ceiling: MaxStepsExhausted. |
| Cancelled | Parent stdin reached EOF: Interrupted. |
| Failed(reason) | Launch or stream handling failed: Failed. |
moon test shim --target native
moon test shim --target wasmpub struct Options {
result_file : String
command : String
model : String?
cwd : String?
writable : Bool
schema : String?
extra : Array[String]
}fn integral(value : Double) -> Int?