Captain / Documentation / Part 8. Where Captain runs

Mate: commands on a machine

Contents ↓

Mate is a shell for people and for AI agents in which every action is checked, policed and logged. It reaches other machines through its own service, mated, instead of SSH and sudo, and agents act through it by writing Captain programs rather than shell commands.

Mate's commands are Captain effects. A line typed at Mate's prompt is a one-statement Captain program, and a Captain program is a Mate script.

Verb and noun

Every command is a verb, then a noun, declared as an effect in the built-in module Mate::Machine:

Command Does
show memory: #this, show disk: #all, show system: #this memory, disks, uptime and the operating system
show process: #all, stop process: P processes; a stop names a process the machine reported
show service: #all, restart service: "NAME" the services the machine allows to be restarted
show port: #all, show log: "SERVICE" listening ports, a service's latest log lines
show directory: "PATH", show file: "PATH" files
edit file: P replace: "old" with: "new" one passage of a file, written only if the file has not changed since it was read
create account:, create directory:owner:mode:, set file:owner:mode:, set file:text:, fetch file:from:digest:, set service:unit:, set service:boot:, delete service: what a server's software needs set up

That is a selection: the Mate guide lists them all, with the Unix command each replaces.

The rules behind the vocabulary:

  • Every show only reads. So "this caller may look but not touch" becomes "this caller may show". A command that changes the machine returns a Receipt, and Mate refuses a show that would.
  • A keyword that picks nothing in particular takes a symbol: #all for a list, #this for one thing. Captain has no calls without arguments, so show memory alone is not a program. At the prompt a person may type the short form; Mate shows the full form before running it, and history keeps the full form.
  • The results are opaque records, so only the machine makes them. stop process: takes a MateProcess, a process id together with its start time, which only show process: gives. A reused process id can never be stopped by mistake, because a bare number is a type error.
  • No on: keyword. A program runs on the machine it is sent to.

A program

look.capt
module Ops::Look.

use Mate::Machine.

;; How much memory is free, and which ports are listening.
export look -> Text [
  memory := show memory: #this.
  ports := show port: #all.
  ret "looked".
].

Because the commands are effects, Captain can show what the program will do before anything runs:

Terminal
$ captain build look.capt -o look.capb
built look.capb ([..])
$ captain plan look.capb look
captain plan v1
program sha256 [..]
entry `look`
args sha256 [..]

node 1: `show memory:` on LocalMachine
  memory: #this
  bounds: no timeout declared
node 2: `show port:` on LocalMachine
  port: #all
  bounds: no timeout declared

defaults in force: sequential execution, no automatic retries (v0.1)
result: "looked"
plan sha256 [..]
plan file: look.capp

And the checker refuses a stop by bare number:

Refused by the checker: CAP-TYPE-010
module Ops::Stop.

use Mate::Machine.

export stopIt -> Text [
  stopped := stop process: 4121.
  ret "stopped".
].

Where a program runs

On this machine. Mate's prompt runs a program with run program: "FILE", and an agent sends one through Mate's mate_run tool. Either way the program may look anywhere the user may, and may edit files only beneath the directory Mate started in. At the prompt, a change is shown first and made only once confirmed.

On another machine. After connect NAME, commands and programs run there, judged there:

  • The machine pins each caller by the fingerprint of its key, and gives each a policy: the commands it may run (may, by bundle, verb, or verb and noun, optionally narrowed to named services), and which paths it may list, read or write.
  • On Linux, two services split the work. mated faces the network and holds no authority; it answers only small looks itself. An executor, the only code running as root, acts only on requests a pinned caller signed, and runs nothing unsigned. Each program runs in a worker of its own, as an account that owns nothing, with no network; every effect the program makes, reads included, is a request back to the executor, judged against the signer's rights and written to an audit log.
  • On macOS, mated still uses an older helper run through sudo.

There is no command that runs an arbitrary program. That is the point: what a caller may do on a machine is exactly the commands its policy names, and a program can do no more than the commands it calls.