cli

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Own = "djinn"

Own is the name of the group of djinn's own commands, those that are no service.

Variables

View Source
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.

Builtins are the commands written by hand, in the order the help lists them.

View Source
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.

View Source
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.

View Source
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 "--".

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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 folders, and hold the push checks until space comes back; 0 never; " +
				"default $DJINN_DISK_FULL_GB.",
		},
		{
			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.

View Source
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.

View Source
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

func Alive(addr string) bool

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.

func Dial

func Dial(addr string) (connect.HTTPClient, string, error)

Dial returns the HTTP client and the base URL that reach the server at addr, for a typed Connect client.

func Run

func Run(ctx context.Context, args []string, cfg Config) int

Run runs one command line, without the program name, and returns the exit code: 0 on success, 1 when the call fails, 2 when the command line is wrong.

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

func Builtin(args []string) (Command, []string, bool)

Builtin returns the command written by hand whose words args start with, the longest, and the arguments after them.

func (Command) FlagSet

func (c Command) FlagSet(vars map[string]any) *goflag.FlagSet

FlagSet is the flag set of c, each flag stored in its variable of vars, by name without its dashes: a *bool, an *int or a *string, set to the flag's default. Its usage is c's help. It panics when a flag has no variable or a variable no flag: the documentation would lie.

func (Command) WriteHelp

func (c Command) WriteHelp(w io.Writer)

WriteHelp writes what --help prints for c.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL