Captain / Documentation / Part 1. Getting started

What Captain is

Contents ↓

Machine-authored, human-read

Captain's main author is, more and more, a machine. Coding agents write Captain programs: in Mate, for example, an agent acts on a machine by writing a Captain program, and a person reads it, reviews the plan it produces and approves that plan by its digest. People mostly read Captain. They write it too, but saving them keystrokes is not the aim.

That one fact explains most of the language:

  • Explicit rules. There is no implicit conversion, no inference across an interface, no hidden default that changes what a program means. A reviewer should never need to know a rule the text does not show. An integer becomes a decimal only where the program writes n as: Decimal; a decimal loses digits only where the program writes a scale and a rounding mode.
  • Visible boundaries. Every effect a program can have is known before it runs. Where code runs, which secrets it may use, what authority it needs and what it will change are part of the program's checked interface and its plan, not facts discovered at run time.
  • One obvious way to write each thing. Text joins with append:, never with +. A value that may be absent is an Option, never a null. A choice is a statement and a value leaves a procedure with ret. When there is only one way to write something, a reader recognises it at a glance, and a machine writes it the same way every time.
  • A checker that catches what a reviewer would miss. A reviewer reading two hundred lines of generated code will not notice that a percentage was added to a duration, that a secret was passed where text was expected, or that a destructive step runs before the step that makes it safe. The checker does notice, and refuses the program with a stable diagnostic code and a suggested fix.

The rest of this book keeps pointing back to these four points. When a rule looks strict, it is usually strict so that a program is safe to approve without having written it.

Programs checked before they run

Captain is the platform's language for programs that are checked before they run. It has two strengths, and both are first-class.

Operations you can approve. An operation is a program that changes something: a file, a service, a machine. In Captain:

  • every effect is declared, and the checker computes which effects each procedure can have;
  • captain plan runs the program against a host that never acts, and renders every effect it would perform, with its arguments, as a plan;
  • the plan has a digest, and approving it mints the grants that destructive steps demand. Running under the approval refuses if anything has changed;
  • every run writes a run log, and captain replay re-executes the program against that log alone.

Calculations you can audit. A calculation is a program with no effects at all: a pure entry. In Captain:

  • numbers are exact. There is no floating point. A Decimal keeps every digit, / is exact or fails, and rounding happens only where the program names it;
  • the same inputs always give the same result, byte for byte, on every machine;
  • a run record proves later which program, which inputs and which result.

A pure entry is not a lesser kind of Captain. It is Captain with no effects, checked by the same checker and run by the same virtual machine.

Source in, artifact out

You write Captain source in .capt files. captain build compiles a module and the modules it imports into one artifact, a .capb file: bytecode plus a manifest that says what the program offers and what it needs. The artifact is what ships and what runs, never the source. Builds are deterministic: the same source gives the same bytes, so an artifact's SHA-256 identifies the program exactly.

  .capt source  --captain check-->  checked
                --captain build-->  .capb artifact (bytecode + manifest)
  .capb         --captain inspect-> what it needs and offers
                --captain plan----> every effect it would perform
                --captain run-----> the result, and a run log
  run log       --captain replay--> the same result, with no effects

Where Captain runs

The captain command line is one host. Captain programs also run inside the platform's own tools: Forge build recipes, Bosun project tasks, Mate commands, Fleet, apps and workers. Each of those hosts admits the effects it supports and runs Captain programs the same way: checked first, then run. Part 8 describes each one. Your own Rust software can run pure Captain entries through the Captain SDK (Part 7).

What Captain is not

  • Not a general-purpose systems language. There are no pointers, no threads, no foreign-function interface. Programs reach the world only through declared effects.
  • Not a shell. exec and shell exist, as an honest escape hatch, and a plan marks every call to them as weaker than a typed effect.
  • Not dynamic. There are no open records, no values that skip the checker, no eval. Data whose shape comes from elsewhere gets a declared Captain type.
  • Not floating point. Numbers are integers, exact decimals and quantities with units.
  • Not a configuration format. A Captain program is code: it has procedures, control flow and types. Declarations are checked against schemas, but the language is not a dialect per consumer.

What Captain leaves out, and why lists the deliberate absences, and Why Captain is the way it is explains the thinking behind them.

Where Captain came from

Captain is a dialect of Zing, an earlier Frogfish language design that was never built. Zing gave Captain its message-style syntax (keyword selectors, bracket blocks, symbols, tagged strings, shapes and protocols) and the principle that opens this chapter: programs are written by machines and read by people. Captain added quantities with units, effects, frontiers, plans, grants and secrets.