Documentation
¶
Overview ¶
Package cli turns the public methods of the protos into commands, by convention and at runtime: the command is the service then the method, the arguments are the fields of the request, and the help is the proto comments. See docs/cli-convention.md.
Index ¶
Constants ¶
const Own = "djinn"
Own is the name of the group of djinn's own commands, those that are no service.
Variables ¶
var Backup = Command{ Name: "backup", Usage: "djinn backup [--file <archive>]", Summary: "Write the data folder into one archive, while Djinn runs or not.", Help: `Write the data folder into one archive: a consistent copy of the database, taken while Djinn runs, and the files beside it. Worktrees (Git holds them), the socket, the server's address, the logs and environment files stay out. Sending the archive elsewhere is left to a tool that does it well: see docs/backup.md. djinn backup restore puts it back.`, Flags: []Param{{ Name: "--file", Type: "file", Help: "Archive to write, ending in .tar.gz, .tgz or .zip; replaced if it exists. Default: a new file in the " + "Downloads folder.", }}, }
Backup is djinn backup.
var Builtins = []Command{Up, Open, Update, Backup, Restore, Version, MCP, GateRun, MachineCommands, DebugDump}
Builtins are the commands written by hand, in the order the help lists them.
var DebugDump = Command{ Name: "debug dump", Usage: "djinn debug dump [flags]", Summary: "Make a running djinn up write where each of its goroutines waits, without stopping it.", Help: `Make a running djinn up write the stacks of all its goroutines to a file of its log folder (logs/ in the data folder), and print the file's path: what a frozen djinn up, or one that does not quit, is waiting for. It asks the server first; when the server does not answer, it leaves a request file the djinn up looks for every second. Send the dump with logs/djinn.log when you report a freeze. On Linux and macOS, kill -USR2 <pid> does the same.`, Flags: []Param{ {Name: "--addr", Type: "string", Env: "DJINN_ADDR", Help: "Address of the djinn server (default $DJINN_ADDR, then the one djinn up writes)."}, }, }
DebugDump is djinn debug dump.
var GateHook = Command{
Name: "gate hook",
Usage: "djinn gate hook",
Summary: "Claude's PreToolUse hook on a worker's Bash and Monitor: wait until Djinn admits a command that neither reads nor edits.",
Help: `Read a PreToolUse call of Claude on its standard input. A command that only reads or edits (ls, rg, cat, sed,
git status, djinn…) goes on at once; any other waits until Djinn admits it, then runs as the worker wrote it: the hook
changes nothing in the call, and tells the worker why its command waited when it did. Djinn passes it to its Claude
workers in the settings it gives them.`,
}
GateHook is djinn gate hook, which no one types.
var GateRun = Command{ Name: "gate run", Usage: "djinn gate run <name> [--task-id <task>] -- <command> [arguments]", Summary: "Run a command under a gate: one holder at a time, while the machine is not under pressure.", Help: `Take the gate <name>, run the command once it is granted, and give the gate back when the command ends, fails or is interrupted. Djinn grants a gate to one holder at a time, and only while the machine is not under pressure; meanwhile it says why it waits. The exit code is the command's. Djinn records what the command cost in its project (CPU time, peak memory, duration): djinn command list. Outside a running worker, the gate takes a worker's slot. Djinn takes it back after an hour, the command going on. A command measured heavy (past 2 GiB of peak memory or a minute of CPU time) also waits while another task's heavy command runs, whatever its gate.`, Args: []Param{ {Name: "<name>", Type: "string", Help: "The gate: codegen, stack, e2e, paid, or any other."}, {Name: "<command>", Type: "string", Help: "The command to run, after --, then its arguments."}, }, Flags: []Param{ {Name: "--task-id", Type: "string", Env: "DJINN_TASK_ID", Help: "Task the gate is taken for (default $DJINN_TASK_ID): its events show the gate."}, {Name: "--addr", Type: "string", Env: "DJINN_ADDR", Help: "Address of the djinn server (default $DJINN_ADDR, then the one djinn up writes)."}, }, }
GateRun is djinn gate run.
var GateWrap = Command{
Name: "gate wrap",
Usage: "djinn gate wrap <wrappers folder> <command> [arguments...]",
Summary: "Run docker or a heavy command of a worker in its place: its containers bounded, its admission awaited.",
Help: `Djinn writes, in its data folder, a docker first on every worker's path, and for the agents without a hook
(Codex, Antigravity) go, npm, npx, pnpm, task, make and golangci-lint: each runs this command. It finds the real
command on the path without the wrappers. docker run and docker create get the task's label and slice and the
project's runaway ceilings (containers in its djinn.yaml); a docker update that would lift them is refused. For an agent
without a hook, a command that neither reads nor edits waits for its admission by the gates, as Claude's hook has
it wait. Then the command runs in its place, the same process.`,
}
GateWrap is djinn gate wrap, which no one types.
var GlobalFlags = []Param{
{Name: "--json", Type: "bool", Help: "Print the result as JSON."},
{
Name: "--addr", Type: "string", Env: "DJINN_ADDR",
Help: "Address of the djinn server: unix:///path/to/djinn.sock, or http://127.0.0.1:PORT/?token=… " +
"(default $DJINN_ADDR, then the address djinn up writes in the data directory).",
},
{Name: "-h, --help", Type: "bool", Help: "Show help."},
}
GlobalFlags are the flags every generated command takes, anywhere before "--".
var Hidden = []Command{GateHook, GateWrap}
Hidden are the commands written by hand that Djinn runs, never a person nor an agent: no help lists them.
var MCP = Command{
Name: "mcp",
Usage: "djinn mcp [--addr URL]",
Summary: "Serve these commands as MCP tools on stdin and stdout, for an agent that speaks MCP.",
Help: `Serve the commands of djinn as MCP tools, on stdin and stdout (the stdio transport of the Model Context
Protocol). Each public method that answers once is a tool: djinn lead set is lead_set. Its arguments
are the fields of the request, by their proto names, read and checked as the command line does. A relative path
starts from the folder djinn mcp runs in. The streaming methods (watch, gate hold) stay on the command line.
Add it to an agent, for example: claude mcp add djinn -- djinn mcp`,
}
MCP is djinn mcp.
var MachineCommands = Command{ Name: "machine commands", Usage: "djinn machine commands [flags]", Summary: "Print what the commands run under the gates cost in each project.", Help: `Print what the commands run under the gates cost in each project: their runs, p50, p95 and last of their held time and wait, mean CPU time, peak memory, last exit code, and a sparkline of held time over recent runs, the slowest first.`, Flags: []Param{ {Name: "--project", Type: "string", Help: "Show only commands of this project (name or ID)."}, {Name: "--addr", Type: "string", Env: "DJINN_ADDR", Help: "Address of the djinn server (default $DJINN_ADDR, then the one djinn up writes)."}, }, }
MachineCommands is djinn machine commands.
var Open = Command{ Name: "open", Usage: "djinn open <link>", Summary: "Open a djinn:// link in Djinn, starting it when it does not run: what the system runs for one.", Help: `Open a djinn:// link in Djinn: djinn://tilasm/<id> shows the wish's Tilasms tab on that tilasm, djinn://wish/<id> the wish. The system runs it for a link clicked anywhere (a browser, a chat, a Markdown file). It hands the link to the running Djinn, starting it in the background when none runs. A link Djinn does not know is refused, and the window says so. Without a link, djinn open is djinn up.`, Args: []Param{{Name: "<link>", Type: "string", Expect: "a djinn:// link", Help: "The link to open."}}, }
Open is djinn open.
var Restore = Command{ Name: "backup restore", Usage: "djinn backup restore <archive>", Summary: "Put an archive of djinn backup back as the data folder, while Djinn is stopped.", Help: `Put an archive back as the data folder, while Djinn is stopped. The previous folder is kept aside, next to it. A project whose folder is not on this machine is detached: djinn project add attaches it again.`, Args: []Param{{Name: "<archive>", Type: "file", Help: "Archive written by djinn backup."}}, }
Restore is djinn backup restore.
var Up = Command{ Name: "up", Usage: "djinn up [flags]", Summary: "Open Djinn: its window, its local server, and the lead's terminal.", Help: `Open Djinn: serve the interface and the server the command line talks to, then open the native window on them, or with --browser print the URL to open. One djinn runs per data folder: a second djinn up brings the first one's window to the front. On macOS and Linux the command line reaches it through a Unix socket and no port is open; on Windows, and with --browser, through a loopback HTTP server guarded by a token. Either way djinn up writes its address in the data folder, for the other commands.`, Flags: []Param{ {Name: "--browser", Type: "bool", Help: "Print the URL to open in a browser instead of opening a window."}, {Name: "--port", Type: "int", Help: "Port of the loopback HTTP server (with --browser, and on Windows); 0 picks a free one."}, { Name: "--terminal", Type: "string", Help: `Command the terminal of the window runs, through the user's shell, e.g. "claude --resume <session>"; empty ` + `runs the shell itself.`, }, { Name: "--terminal-dir", Type: "folder", Help: "Working directory of the terminal; empty is the folder of the first project, as the window lists them " + "(never the home folder: with no project, the window asks to create one).", }, { Name: "--workers", Type: "int", Env: "DJINN_WORKERS", Help: "Most workers at once, 1 to 16; 0 decides from the machine (one per 2 cores and per 2 GiB of memory); " + "default $DJINN_WORKERS.", }, { Name: "--worker-cpu", Type: "int", Env: "DJINN_WORKER_CPU", Help: "Cap each worker's CPU at this percent of one core (150 is a core and a half), in a systemd user scope of " + "its own; Linux with systemd only, and only where systemd gives your user the cpu controller, else workers " + "run uncapped and djinn says why; 0 caps nothing; default $DJINN_WORKER_CPU.", }, { Name: "--worker-memory", Type: "int", Env: "DJINN_WORKER_MEMORY", Help: "Cap each worker's memory at this many MiB, in its systemd user scope: past it the kernel reclaims, then " + "kills a process of the worker; Linux with systemd only, and only where systemd gives your user the memory " + "controller; 0 caps nothing; default $DJINN_WORKER_MEMORY.", }, { Name: "--worker-memory-guard", Type: "float", Env: "DJINN_WORKER_MEMORY_GUARD", Help: "Cap each worker's memory dynamically at this multiple of its provider's observed peak (median of latest " + "10 finished workers) and at least the forecast; typical values are 2 to 3; 0 turns the guardrail off; " + "Linux with systemd only, and only where systemd gives your user the memory controller; without measurements, " + "no ceiling applies; default $DJINN_WORKER_MEMORY_GUARD.", }, { Name: "--enlighten-workers", Type: "bool", Default: "true", Env: "DJINN_ENLIGHTEN_WORKERS", Help: `Start a worker to investigate and revise a question after "Enlighten me"; default ` + "$DJINN_ENLIGHTEN_WORKERS (on or off), else on.", }, { Name: "--ifrit-idle", Type: "duration", Help: "How long you may leave Djinn alone before it puts an ifrit out, from 5m to 4h, like 30m; an ifrit " + "spawned with --idle-minutes keeps its own; default the window's settings, else 30m.", }, { Name: "--disk-trim-gb", Type: "int", Default: "30", Env: "DJINN_DISK_TRIM_GB", Help: "Under this many GB free where the Go build cache is, delete its entries unused for a day, before a " + "worker starts and before push checks; read only when go is on the PATH (go env GOCACHE); 0 never trims; " + "default $DJINN_DISK_TRIM_GB.", }, { Name: "--disk-full-gb", Type: "int", Default: "10", Env: "DJINN_DISK_FULL_GB", Help: "Under this many GB free where Djinn's data folder or the Go build cache is, tell the lead the disk is " + "almost full, naming the biggest sources on the disk, and hold the push checks until space comes back; 0 never; " + "default $DJINN_DISK_FULL_GB.", }, { Name: "--paused", Type: "bool", Help: "Start without resuming any worker the last djinn up left interrupted, nor replaying a task an " + "environment failure stopped: they stay interrupted, and the lead and the window hear it; djinn task " + "continue resumes each. Djinn starts so by itself after a stop that was not clean, and after one whose " + "last Hourglass reading had the memory past --paused-memory.", }, { Name: "--paused-memory", Type: "int", Default: "90", Env: "DJINN_PAUSED_MEMORY", Help: "Start as with --paused when the Hourglass's last reading of the last djinn up had the machine's " + "memory at or above this percent; a reading past it is written at once, so that a crash keeps it; 0 " + "never; default $DJINN_PAUSED_MEMORY.", }, { Name: "--brake-memory", Type: "int", Default: "5", Env: "DJINN_BRAKE_MEMORY", Help: "Under this percent of the machine's memory available, or a PSI full of 20, the memory brake freezes the " + "worker that grows most outside the gates, its containers too, and interrupts it 30 s later if the memory " + "stays short; a worker the gates admitted is never interrupted, and only frozen when it alone grows; calm a " + "minute above this percent plus 5, it thaws; the lead hears each; 0 turns the brake off; default " + "$DJINN_BRAKE_MEMORY, else the percent chosen in the Summoning Circle, else 5. Given here or by " + "$DJINN_BRAKE_MEMORY, it holds for the run: the Summoning Circle cannot change it.", }, { Name: "--pprof", Type: "bool", Env: "DJINN_PPROF", Help: "Serve Go's profiles of djinn up at /debug/pprof/, on its own address only (the Unix socket, or the " + "loopback server and its token), to measure what it spends its CPU and memory on; default " + "$DJINN_PPROF (on or off), else off.", }, { Name: "--update-check", Type: "bool", Default: "true", Env: "DJINN_UPDATE_CHECK", Help: "Look for a newer release of Djinn: at start, then every 6 hours, a release binary asks GitHub's API, " + "one installed with go install the Go module proxy; nothing downloads before you click Update. Off, " + "Djinn sends nothing on its own, and only a newer binary installed at its path is offered; default " + "$DJINN_UPDATE_CHECK (on or off), else on.", }, }, }
Up is djinn up.
var Update = Command{ Name: "update", Usage: "djinn update [--yes]", Summary: "Restart the running djinn on the newer one installed at its path, or on a newer release.", Help: `Restart the running djinn on the newer one installed at its path (go tool task install), or, for a djinn installed from a release, on the newer release it offers, first downloaded and verified. Djinn notes its open terminals, stops as when it quits (workers interrupted, nothing lost), and starts the new binary, which runs those terminals again on the same sessions. The window's update button does the same.`, Flags: []Param{{Name: "--yes", Type: "bool", Help: "Restart without a terminal to run from, as a script does."}}, }
Update is djinn update.
var Version = Command{
Name: "version",
Usage: "djinn version",
Summary: "Print the version of djinn.",
Help: "Print the version of djinn.",
}
Version is djinn version.
Functions ¶
func Alive ¶
Alive tells whether a server listens at addr: its socket, or its loopback port, takes a connection. A server that crashed leaves its address behind, and nothing answers it.
Types ¶
type Command ¶
type Command struct {
Name string // the words after djinn: "wish make", "gate run", "up"
Usage string // the usage line, after "Usage: "
Summary string // one sentence, for the lists of commands
Help string // what it does: paragraphs apart by a blank line
Args []Param // the positional arguments, in order
Flags []Param // the flags
Tags []string // short facts: "reads only", "streams", "MCP tool wish_make"…
}
Command is one command of djinn, as its --help and the documentation's Command line tab show it: a public method of the protos, read by the convention, or a command written by hand in cmd/djinn (Builtins).
func Builtin ¶
Builtin returns the command written by hand whose words args start with, the longest, and the arguments after them.
type Config ¶
type Config struct {
Version string
// Addr is the server: unix:///path/to/djinn.sock, or an http URL whose token parameter, if any, is sent as a
// bearer token. When empty, the address djinn up wrote in Home.
Addr string
Home string // data directory
HTTP connect.HTTPClient // built from Addr when nil
// Start starts djinn up in the background and returns its address once it answers, for the methods marked
// autostart when no server answers. Nil leaves them failing as the others do.
Start func(ctx context.Context) (addr string, err error)
// Getenv reads the variables some fields default to, such as $DJINN_TASK_ID ((djinn.v1.env)); os.Getenv when nil.
Getenv func(string) string
Stdin io.Reader // djinn mcp reads its requests here
Stdout io.Writer
Stderr io.Writer
}
Config is what Run needs from its caller.
type Group ¶
type Group struct {
Name string // the command word: "wish"; "djinn" for djinn's own commands
Aliases []string // other words for it: talisman
Help string
Commands []Command
}
Group is a command and its subcommands: a service, or djinn's own commands.
func Reference ¶
func Reference() []Group
Reference is the whole command line, for its documentation: djinn's own commands first, then one group per service, by name, each with its methods then the commands written by hand in it (djinn gate run). It reads the same command tree as Run, and the same Builtins as the --help of the commands written by hand.
type Param ¶
type Param struct {
Name string // <question> when positional, --kind when a flag
Type string // string, bool, int32, enum, time, folder, file, path, pair…
Values []string // the values an enum takes
Expect string // what it accepts beyond its type: "a UUID", "a match of ^Q[0-9]{2,3}$"
Default string // the value it takes when not given, when that is worth saying
Env string // the environment variable it defaults to
Repeated bool // a flag given once per value
Help string
}
Param is an argument or a flag of a command.