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 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.`, 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 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 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: "--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.", }, }, }
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.