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 moejs, the JavaScript interpreter magpie's middleware and agent plugins run in, with nothing of the computer's. It is interrupted at its time and stopped past its memory limit inside a builtin too, but a builtin is Go: one that misses a check runs to its end however long it takes or however much it allocates, and 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.
func Run ¶
Run runs sc in a helper process, exe started as Command, each tool call it makes run here by run. It ends the helper when the script is past lim.Wait (and grace), and whatever has gone wrong it gives back a result that says so: never an error.
func SkillSource ¶
SkillSource is code, a skill's code.js, as an expression whose value is its default export: the file run as a function's body, with its `export default` made that function's return. It is an error when the file has no `export default`, or another import or export.
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.
type Script ¶
type Script struct {
Code string `json:"code"`
Args json.RawMessage `json:"args,omitempty"`
Tools []string `json:"tools"`
Skills []Skill `json:"skills,omitempty"`
}
Script is one script to run: code, the body of an async function, with Args as its `args`, Tools the names on `tools` and Skills the functions on `skills`.