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

magus-run

Run a target for selected projects

Synopsis

magus run <target> [flags] [project...] | magus run [<target>] --stdin [--shard <id>] < plan.json

Description

Run a named target for the selected projects. With no project arguments, selects the project containing the current directory, or all projects if the current directory is not inside a project. Explicit project paths on the command line select exactly those projects.

--skip subtracts from whatever that selection resolved to, so a CI step can gate every project except a named few without any shell filtering. It takes the same project reference a positional does, and refuses a reference no project matches rather than skipping nothing quietly.

--preflight names targets to run first, as a separate pass across every selected project, before the invoked target starts anywhere. Each must be a target the invoked target already reaches through ctx.needs (the chain magus describe target prints); one it never reaches is refused before anything runs (MGS3021). If a preflight target fails, no further preflight step starts, the ones in flight are cancelled, nothing of the invoked target starts, and the run exits 3 (MGS3020) with a first line naming the target, the failing projects and the command that fixes them. When the pass is green the run proceeds and treats those targets as done, so nothing runs twice and no cache key changes.

The target ci is an ordinary magusfile-defined target - magus does not hardcode its steps; your magusfile composes them with magus.needs. magus keeps ci as the anchor that the affected set keys off, and always runs it read-only; apply the rw charm (e.g. 'magus run format:rw') to mutate files.

--stdin runs a saved shard plan instead of a selection: the document magus affected <target> --plan printed, piped in or redirected from a file (< plan.json). The plan names the target and each shard's projects, so the target positional is optional (give it to add charms, as in ci:gha) and project positionals are refused. --shard <id> runs that one shard; without it every shard runs here. A malformed plan, a shard id the plan does not have, a target other than the plan's, or an --n-shards other than its count is refused before anything runs (MGS3029). Under the global --dry-run nothing runs: the plan is checked and printed, and -o json, yaml or template renders the document as read, so a saved plan renders more than once without being computed again.

Options

--depth int
With --graph: cap displayed depth (0 = unlimited)
--detach
Hand the run to the server and return immediately; follow it with magus status --watch
--graph
Render the dependency graph for the selected scope instead of executing
--n-shards int
Without --stdin: the shard count the --shard label belongs to. With it the count is the saved plan's, and a different value is refused
--no-cache
Force a fresh run even on a cache hit; still refreshes the entry
--no-default-charms
Ignore magus.yaml default_charms for this run
--no-redundancy-check
Run the ci gate even when an identical-or-equivalent gate already passed for this branch on this machine (MGS3010); ci target only
--no-volatility-retry
Disable volatility auto-retry for this run
--open
Open this run in the browser log viewer and stream to it as it goes (loopback; never leaves your machine)
--preflight string
Comma-separated targets to run first across every selected project; each must be in the invoked target's ctx.needs closure (MGS3021), and a failure stops the run before it starts (exit 3, MGS3020)
--race string
Race-condition diagnostics (watch|replay, comma-combinable); omit to disable. watch: attribution-gated fsnotify detection (MGS4001/4002/4004), emitting only when >=2 projects' output snapshots confirm a shared write. replay: re-runs cacheable output-declaring projects sequentially to content-hash outputs for non-determinism (MGS4003); roughly doubles wall-clock.
--shard string
With --stdin: run only the saved plan's shard with this id. Without it: a label naming this run's shard in a CI matrix, paired with --n-shards; it selects nothing
--skip string
Exclude projects from the selection; repeatable or comma-separated. Takes project references like positionals, or a doublestar glob over project paths (libs/*); a value matching nothing is an error
--stdin
Run the shards of a saved shard plan, the document affected --plan prints, read from stdin; the plan names the target and the projects
--step
Pause before each subprocess for interactive stepping (needs a TTY; implies --concurrency=1)
--timeout duration
Abort if the run has not finished within this duration (e.g. 5m, 1h30m)
--upstream
With --graph: show dependents instead of dependencies
--wait
With --detach, block until the run finishes and exit with its status

Targets

ls
Print selected projects without executing anything
build
Build selected projects
test
Test selected projects
lint
Lint selected projects (read-only)
format
Format source files in selected projects
clean
Remove declared outputs from selected projects
generate
Run code generation for selected projects
ci
Run the magusfile's ci target read-only (affected-set anchor)

Exit status

0
Every selected project's target succeeded, whether it ran or replayed from cache.
1
At least one target failed. The failure was already reported with the path to its captured log, so there is no second error line here. This is the default failure status, not the only one: a magusfile calling os.exit(code) has that code honored verbatim, so a target may exit with a status this list does not name.
2
Misuse: an unknown target, no project matched the filters, a flag that does not apply to this invocation, a --preflight target the invoked target never reaches (MGS3021), or a saved plan that cannot be run as asked (MGS3029).
3
A --preflight target failed, so nothing of the invoked target ran (MGS3020). The first line names the target, the failing projects and the command that fixes them.
75
Nothing ran, and trying again later would succeed; 75 is EX_TEMPFAIL, the transient-failure convention. A selected project's workspace lock or the machine's build budget was held by another magus invocation (magus never queues behind one; the error names the holder's pid, command and directory), or a ci gate was deferred as redundant under load (MGS3010; the error names the green gate it found and --no-redundancy-check overrides).

Examples

Build everything

magus run build

Check for drift everywhere before any project runs ci

magus run ci --preflight generate

Test one project

magus run test api/gateway

Build two specific projects

magus run build api/gateway web/studio

Every project that declares generate except two

magus run generate --skip docs --skip console

Dry-run: show what would run

magus run build --dry-run

Force a fresh rebuild past a cache hit

magus run build --no-cache

Full CI pipeline

magus run ci

Show dependency graph for build target

magus run build --graph

Graph in Mermaid format

magus run build --graph -o mermaid

Graph dependents of api/gateway

magus run build api/gateway --graph --upstream

Stream JSONL target events to a file

magus run build -o jsonl --tee build.jsonl

Run every shard of the affected ci plan here

magus affected ci --plan | magus run --stdin

Run one shard of a saved plan

magus run ci:gha --stdin --shard 2 < plan.json

Render a saved plan's summary without computing it again

magus run --stdin --dry-run -o 'template={{.summary}}' < plan.json

See Also

magus(1), magus-ls(1), magus-describe(1), magus-x(1), magus-where(1), magus-affected(1), magus-graph(1), magus-query(1), magus-explain(1), magus-path(1), magus-refs(1), magus-watch(1), magus-events(1), magus-status(1), magus-clean(1), magus-shell(1), magus-vcs(1), magus-queue(1), magus-doctor(1), magus-config(1), magus-session(1), magus-memory(1), magus-job(1), magus-notes(1), magus-diff(1), magus-server(1), magus-broker(1), magus-mcp(1), magus-buzz(1), magus-completion(1), magus-man(1), magus-init(1), magus-spell(1), magus-agent(1), magus-self(1), magus-version(1)

generatedinternal/cli/registry.goclimagus runruntargetbuildtestci
Last updated (c5971189)
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. See workspace.

Project

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

Magusfile

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

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. See targets.

Op

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

Spell

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

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. See charms.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. See cache.

Affected

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

Broker

The per-user background process that holds this host's capacity: the machine budget every run claims slots from, and the shared services runs keep warm. A run starts it on demand; broker: off in magus.yaml runs without one. See server.

Server

The background process a person starts with magus server start. It serves MCP, the console, background jobs and the warm knowledge graph, and adopts nested magus calls into one pool. See server.

CI

An ordinary magusfile-defined target you compose yourself with magus\needs - magus does not hardcode its stages. Magus.RunCI treats it specially only in that it strips the rw charm, it is the anchor magus affected ci keys off, and a selected scope with no project declaring it is a load error rather than a silent no-op. See targets.

Concurrency

How many targets run at once. It is bounded by the pool's capacity and set with --concurrency, MAGUS_CONCURRENCY, or the concurrency config key. See server.

Snapshot

A point-in-time view of live state - the pool's occupancy or a tick of exported metrics - as opposed to accumulated history. See server.

Volatility

A target that fails once and passes on rerun is volatile, as opposed to a regression that started failing and stays failing. magus keeps per-target pass/fail history and a Wilson-score volatility rate to tell them apart and auto-retry the noise. See volatility.

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. See knowledge.

Session

An agent host's conversation, by the id the host delivers to its hooks. magus never mints one: a record with no session is unattributed, and the OS user it carries says whose account ran it.

Invocation

One magus process's recorded facts - the targets it finished, their outcomes, the lease it acted as, and the session it ran in when a host delivered one - kept in a repo-scoped store every worktree shares. magus session lists them; the store prunes itself by last-fact age.

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 server, for its own maintenance. The store records; the agent guard is what reads those facts back when grading a write. See doctrine.

A job is not a run. magus run build web is a run, and no job exists for it. A job causes runs: its check executes as one, and a server job records the invocation of its last one. Jobs are listed with magus ls jobs and in the console's Jobs view; runs are listed in the Runs view.

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.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.