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

Spell contract

A spell answers magus through exported mgs_ functions. magus calls each one once, with no arguments, when it loads the spell, before any target runs. Each function must declare exactly the return type below; a different one, > any, or an mgs_ name this page does not list is MGS1051.

Only mgs_getName is required. Leaving any other function out declares nothing for it.

mgs_getName

export fun mgs_getName() > str

Required. The spell's name, the one a magusfile imports it by.

mgs_listRequiredGlobs

export fun mgs_listRequiredGlobs() > [Path]

The files every op of the spell reads. They key its cache and pull its project into the affected set.

mgs_listProvidedGlobs

export fun mgs_listProvidedGlobs() > [Path]

The files the spell's ops write.

mgs_listIgnoreDirs

export fun mgs_listIgnoreDirs() > [Path]

Directories the spell's ecosystem generates (vendor, node_modules, target), which the input-hashing walk prunes. Each Path sets isDir = true.

mgs_listManifests

export fun mgs_listManifests() > [Manifest]

The candidate manifests of the spell's ecosystem, in order: the first one present in a project directory is its manifest. Each names the lockfiles it may carry.

mgs_listScriptRunners

export fun mgs_listScriptRunners() > [Command]

The argv prefixes that run a script a manifest defines, which doctor reports as MGS1049.

mgs_getTools

export fun mgs_getTools() > {str: Tool}

Every binary the spell's ops run, keyed by the bin name a Command names, each with the probe that reads its version into the cache key.

mgs_getLanguage

export fun mgs_getLanguage() > Language

The source language the spell adapts: its name, its file extensions and, when the spell can declare it honestly, its comment and string syntax.

mgs_getSymbolIndexer

export fun mgs_getSymbolIndexer() > SymbolIndexer

The command that writes the spell's SCIP symbol index. magus runs it as the reserved index op.

mgs_getSandbox

export fun mgs_getSandbox() > Sandbox

What the spell's tools need from the host beyond the sandbox's own grants.

mgs_isOpaque

export fun mgs_isOpaque() > bool

Whether the spell delegates to a foreign process that manages its own dependency graph, so magus treats the project as a black box.

mgs_getModeArgs

export fun mgs_getModeArgs() > {str: [str]}

The args that tell an op apart from other uses of a program with no subcommand, keyed by op name: node runs scripts too, and only --test is node-test.

mgs_listTargets

export fun mgs_listTargets() > {str: fun(Target) Command}

The spell's ops, keyed by op name. magus calls each handler once at load, with a null Target, to read the Command it declares, so a handler must not read its Target.

mgs_listServices

export fun mgs_listServices() > {str: fun(Target) Service}

The spell's long-running ops, keyed by op name, each read the way a target handler is.

generatedinternal/spell/contract.gospellscontractmgs_referenceMGS1051
Last updated (aba0c4fa)
Glossary

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.

Manifest

The file that declares what a package is: its name, dependencies, entry points and tool config (go.mod, package.json, pyproject.toml, Cargo.toml). How the workspace builds, tests and lints the package belongs in the magusfile, not in the manifest's scripts. See spells.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

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.

Sandbox

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

Service

A long-running or shared process magus manages across runs, distinct from a one-shot target. See services.

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.

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.