Documentation
¶
Overview ¶
Package coderun runs the MCP router's code mode scripts (run_code) in a process of their own: magpie started again as `magpie run-code-helper`, which the gateway gives the script and serves its tool calls to.
The script runs in goja, a JavaScript interpreter with nothing of the computer's. goja stops a script that is interrupted only between its own steps: a builtin is Go, and runs to its end however long it takes or however much it allocates. "x".repeat(1e10) asks for 10 GB at once, a regular expression with a backreference can backtrack for ever, and [].join or fill over an array of length 4e9 loops 4e9 times. Run in magpie's own process, such a script took magpie's memory or a core with it, and the request waited on it past its time. A process of its own is ended whatever it is doing: at its time, by the gateway, and past its memory, by itself.
Index ¶
Constants ¶
const Command = "run-code-helper"
Command is the hidden subcommand that runs a script: magpie's own binary, started again by Run.
Variables ¶
This section is empty.
Functions ¶
func Helping ¶
func Helping() bool
Helping is whether this process was started as the helper: before anything else runs, `if coderun.Helping() { os.Exit(coderun.Main()) }`.
func Main ¶
func Main() int
Main is the helper: it runs the script the gateway gives it on stdin, asking the gateway for each tool call, and ends itself when its heap grows past the script's Heap. Its exit code is 0 once it has answered.
Types ¶
type Call ¶
Call runs one tool by name for a script: its result as the tool gave it, or an error when no tool has that name.
type Limits ¶
type Limits struct {
// Calls is how many tool calls it makes at most, AtOnce how many run
// at the same time.
Calls int `json:"calls"`
AtOnce int `json:"atOnce"`
// Max is how many characters of what it returns and logs go back.
Max int `json:"max"`
// Heap is how far its process's heap may grow before it is ended.
Heap uint64 `json:"heap"`
// Wait is how long it runs in all, its calls included.
Wait time.Duration `json:"wait"`
}
Limits are what one script may do.