coderun

package
v0.1.4627 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 Result

func Result(text string, isErr bool) map[string]any

Result is a tool result of text.

func Run

func Run(ctx context.Context, exe, code string, names []string, lim Limits, run Call) any

Run runs code in a helper process, exe started as Command, with names the tools it may call, each 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.

Types

type Call

type Call func(ctx context.Context, name string, args json.RawMessage) (any, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL