magus v0.4.3 is out. See what's new
¶ View generated markdown
6 min read

Magusfile Module Reference

These are the runtime utility modules. Import each under its bare name (import "fs", then fs\glob(...)) with camelCase methods. magus layers these host methods onto Buzz's own stdlib, so a single import "fs" (or os, crypto) carries both sets of methods, and the magus forms are sandbox-aware where Buzz's bare stdlib is not. Methods that are also in Buzz's own standard library are marked with an asterisk (*) and a footnote on their page; either form works.

Files and paths

Module Description
fs Filesystem and path primitives.
path Pure path-string math: abs, rel, clean, is_abs, expand_user, and glob matching.
archive Archive creation and extraction with automatic format detection. Supports tar, zip, tar.gz, tar.bz2, tar.xz, and tar.zst. Symlinks and non-regular entries are skipped.

Process and environment

Module Description
os The machine and this process: platform triple, CPU count, hostname, the running magus binary, and the two members that shadow Buzz's own (exit, sleep). Running OTHER processes lives in the proc module.
env Process environment variable access.
platform Normalize OS/architecture identifiers across naming conventions (aarch64<->arm64, Darwin<->darwin).

Text and formatting

Module Description
strings String helpers Buzz's builtins lack: case conversion, comparison, affix trimming, padding, and splitting into lines or fields.
fmt String formatting (printf-style).
markdown GitHub-Flavored Markdown to semantic HTML.

Serialization and encoding

Module Description
json JSON encode/decode.
yaml YAML parse and stringify (YAML 1.2 via gopkg.in/yaml.v3).

Cryptography

Module Description
crypto Content digests (SHA-256/512; SHA-1 and MD5 for legacy-checksum interop) and Ed25519 signing.

Networking

Module Description
http HTTP client. Requests run ONCE unless given a retry policy.

Time

Module Description
time Timestamp formatting/parsing and duration parsing (Go time, UTC).

Versioning and version control

Module Description
semver Semantic version parsing and comparison (SemVer 2.0.0).
vcs Version-control queries for the current working tree.

Magus internals

Module Description
magus Magus core primitives.

Provider namespaces are wired by the runtime rather than declared here, so they do not appear in the method list below: magus\cache.remote(<spell>) selects a remote cache provider, magus\ci.provider(<spell>) a CI provider, magus\secret.provider(<spell>) / magus\secret.read(<ref>) a secret provider and the credentials read through it, magus\harness.provider(<spell>) an agent-host harness (many hosts; like workspace.provider, unlike cache.remote's one), and magus\guard.shell(<rule>) an additive shell-guard rule (strengthen-only), and magus\guard.spawn(<fun>) the one function the agent guard calls on every spawn and continuation (see magus\guard.spawn), and magus\guard.command(<fun>) the one function it calls on every agent shell command (see magus\guard.command), and magus\guard.write(<fun>) the one function it calls on every agent file write. Each provider takes an imported spell handle. magus\secret.endpoint(<grant>) serves the case read cannot: it returns a loopback base URL a CHILD PROCESS is pointed at instead of the real API, so magus attaches the credential on the way upstream and the child never holds it. It takes an object with ref/host/header/prefix fields, declared in your own magusfile. For your own code, read is the ordinary choice. See Secrets, Remote cache and CI integration.

import "magus" is how you reach any of this. The namespace is an ordinary host module, like fs or vcs: without the import line magus is undefined, and the import is what attaches these signatures to your call sites. It resolves in a magus buzz script as well as in a magusfile, and a script run inside a workspace reads that workspace: describe.project, affected, projectGraph, where, insight, the knowledge-graph reads (query, explain, path, refs, stats, importGraph, dir, dirs, layer, neighborhood) and output all answer in-process, and so does magus\job (list, put, register, exit, wait, clear): the job store an orchestrating agent declares about work it handed out (see types.Job). The magus job CLI subcommand is a third write door onto the same rows: ls and describe read, fork declares a row, exec records a worker's landed base, and wait blocks on a dependency. Only the members that DECLARE into the workspace being loaded (magus\project, the provider selections above) raise MGS1022 in a script: there is nothing for them to declare into. Run a script outside any workspace and the reading members raise it too, since there is no workspace to read. The nested-command methods (cmd, run, doctor, and the magus\describe methods that fork) work there either way and discover the workspace themselves. | | charm | Constructors for charm values: RFC 6902 JSON Patches over a target's argv (see docs/charms.md). |

Other

Module Description
base64 Base64 text codec (standard and URL-safe, both padded).
csv Delimiter-separated tabular text (CSV, TSV) parsing and rendering.
diff Unified line diffs, for reporting what drifted rather than only that something did.
figure Architecture figures drawn from graph records: boxes and groups over Dir records, coverage by scope, edges derived from imports and declared calls.
flags Parse a script's argv against the flags it declares.
hex Hex text codec.
ini INI/properties config parsing and rendering (.npmrc, .gitconfig, .editorconfig).
lcov LCOV coverage reports: the percentage a badge or a floor gate shows, and the line-level merge that keeps it true across multiple test processes.
log Emit a message at a level through magus's own logger, so it honors -q/-v/-vv, renders in the run's format, is redacted, and is captured in the run log. Unlike std\print, which is an uncontrolled bare line.
math Rounding to a decimal place, clamping, and aggregation over a list of numbers.
merge Combine two values. shallow replaces one level of an object; deep recurses into objects.
modeltiers The default model-tier declaration: the ModelTier enum, cheapest first, its default, and the bounds and skill variant of each tier.
net TCP readiness and port allocation: wait for a service to accept connections, and find a free port.
pipe Read the records a magus stage upstream in a pipe writes, and write records for the stage downstream.
proc Run other processes. proc.exec is the one verb that runs anything: it streams output live, captures it, honors the sandbox, and raises on failure instead of handing back a code to check. Needing a shell is not a second verb - proc.shell builds the {bin, args} to hand it, so which shell ran stays visible at the call site instead of hidden inside it. Distinct from Buzz's own os.execute, which returns an exit code and stays silent when you do not read it.
sort Ordering for string lists: lexicographic, natural (digit-aware), and semver.
template Logic-less Mustache templating (Mustache spec, via github.com/cbroglie/mustache).
term Terminal interaction: capability probes, an interactive picker, and styled output. Renders to stderr; pick raises rather than hanging when there is no terminal.
toml TOML parse and stringify (TOML 1.0 via pelletier/go-toml/v2).
url URL percent-encoding, parsing, and building.
uuid Unique identifiers and random tokens (v4 random, v7 time-ordered, plus raw random hex/tokens).
xml Build, serialize, and parse XML/SVG.

See also

  • Targets: the runnable units whose magusfiles call these modules.
  • Spells: language and toolchain adapters that compose these modules into ops.
  • Charms: the execution modifiers the charm module constructs.
  • Playground: exercise these modules live in the browser.
generatedstd/**/*.gostdlibmodulesmagusfilereferencefsoshttpjson
Last updated (29d8b3de)
Earlier changes on this page (7)

Full history ↗ · Blame source ↗

Glossary

Workspace

The magus root directory that owns a set of projects and shared config; the unit magus operates over. Workspace in full.

Project

A directory magus recognizes as a unit of work (it has a magusfile); the unit of caching, scheduling, and dependency tracking. Project in full.

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. Magusfile in full.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. Target in full.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). Op in full.

Spell

A language/runtime adapter (e.g. go, md) that maps generic targets onto a toolchain's real commands. Spell in full.

Charm

An execution modifier attached with : (lint:rw) that changes how a target runs, not which one; the built-in rw flips a check-only target to mutate in place, and ci always strips it. Charm in full.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. Module in full.

Buzz

The language magusfiles are written in (the .buzz engine). Buzz in full.

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. Cache in full.

Affected

The set of projects touched by a change; magus affected <target> runs a target only over them. Affected in full.

Sandbox

The restricted filesystem and environment a target runs in, so builds stay reproducible and side-effect-free. Sandbox in full.

Service

A long-running or shared process magus manages across runs, distinct from a one-shot target. Service in full.

CI

An ordinary target you compose yourself with ctx.needs; magus does not hardcode its stages. It is the anchor magus affected ci keys off, and ci strips the rw charm. CI in full.

Remote cache

A CI-only backend that shares content-addressed artifacts across runners: a cold machine replays a build another runner already did instead of rebuilding. Every remote artifact must be signed by a trusted key. Remote cache in full.

MAGUS.md

The committed routing index at a workspace root, regenerated from the knowledge graph: it lists every node and points at the exact query for a given question, so it is the entry point an agent reads first. MAGUS.md in full.

Insight

The reports magus derives over the graph and history (hotspots, affinity, ownership, trend, volatility, unreferenced). Insight in full.

Agent

A model working through an agent host such as Claude Code, Codex, Cursor or OpenCode. magus treats an agent as one more caller of its CLI, MCP tools and console, held to the same checks as a person. Agent in full.

Tool

An action a model can call through its host: a name, a description, a typed input and a result. magus serves its tools over MCP, each a read of the workspace model or a run of the CLI it already has. Tool in full.

Harness

The deterministic scaffolding around the work on a change, for a person or an agent: compiler errors, formatters, linters, checks, gates, leases and hooks, placed at points a person chose. Around an agent's loop, magus supplies one and keeps it outside. Harness in full.

Skill

A packaged set of instructions an agent host loads when a task matches its description: a directory holding a SKILL.md. magus ships its magus-* skills in the binary and writes them with magus agent install. Skill in full.

Job

The unit of delegated work, and one row of the job store: what an orchestrating agent handed out, with its goal, the checkpoint it was cut against, the paths it may write or must not touch, and the one check it runs. A job's holder is either a session, for work an orchestrator handed out, or the daemon, for its own maintenance. The store records; the agent guard is what reads those facts back when grading a write. Job in full.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate. Run in full.

Conventions

Placeholders

Angle brackets mark a value you replace with your own; never type the brackets:

magus run <target>
magus completion <shell>    # e.g. bash, zsh, fish

<target>, <path>, <shell>, <name> and the like are stand-ins, not literal text.