Documentation
¶
Overview ¶
Package wrap is the commands Djinn puts first on a worker's path: docker, which binds the containers the worker starts to its task and bounds them, and, for the agents Claude's hook does not cover (Codex, Antigravity), the heavy heads (go, npm, make…), which wait for their admission by the gates. Each finds the real command by leaving the wrappers' folder out of the path.
Index ¶
- Constants
- Variables
- func Bytes(s string) (int64, error)
- func Docker(args []string, caps Caps, taskID, home string) (out []string, notes []string, err error)
- func DockerDir(root string) string
- func Env(root, home, path string, caps Caps, heads bool) []string
- func HeadsDir(root string) string
- func Main(root, head string, args []string, stderr io.Writer, admit Admit, exec Exec) int
- func Path(root, path string, heads bool) string
- func Pause(ctx context.Context, pause bool, labels ...string) int
- func Remove(ctx context.Context, labels ...string)
- func Root(home string) string
- func Size(b uint64) string
- func Slice(taskID string) string
- func Write(root, djinn string) error
- type Admit
- type Caps
- type Exec
Constants ¶
const ( TaskLabel = "djinn.task" HomeLabel = "djinn.home" )
TaskLabel names the label that binds a container to the task whose worker started it; HomeLabel the one that names the Djinn, by its data folder: a Djinn removes at its start the containers its workers left, never another Djinn's.
const ( // EnvMemory and EnvPIDs are the ceilings of the worker's containers (Caps); without them, docker runs as is. EnvMemory = "DJINN_CONTAINER_MEMORY" EnvPIDs = "DJINN_CONTAINER_PIDS" // EnvFile is the project's file they were read in (Caps.File); without it, the wrapper names ConfigFile. EnvFile = "DJINN_CONTAINER_FILE" // EnvHome is the data folder of the Djinn that runs the worker, its containers' HomeLabel. EnvHome = "DJINN_CONTAINER_HOME" // EnvAdmit, "1", has the wrapped commands wait for their admission by the gates: a worker whose agent has no // hook Djinn runs before each command (Codex, Antigravity). EnvAdmit = "DJINN_ADMIT_HEADS" // EnvAdmitted marks the processes of an admitted command: a wrapped command it runs (go test running go, npm // running npx) is part of its admission, and runs at once. EnvAdmitted = "DJINN_ADMITTED" )
What Djinn tells the wrappers through a worker's environment.
const ConfigFile = "djinn.yaml"
ConfigFile is the file a project raises its ceilings in when it has none yet.
Variables ¶
var ErrRefused = errors.New("refused by Djinn")
ErrRefused is why the wrapper refuses a docker command: it would lift a container's ceilings.
var Heads = []string{"go", "npm", "npx", "pnpm", "task", "make", "golangci-lint"}
Heads are the heavy commands wrapped for an agent without a hook (G1 of L04): builds, tests, package managers. docker is wrapped for every worker, in a folder of its own (DockerDir).
Functions ¶
func Bytes ¶
Bytes reads a size as docker does (units of 1024): "4g", "512m", "1GiB", "1048576". "-1" reads as -1, unlimited.
func Docker ¶
func Docker(args []string, caps Caps, taskID, home string) (out []string, notes []string, err error)
Docker rewrites the arguments of docker (args, the command name left out) for the worker of taskID in the Djinn of home: docker run and docker create (docker container run, create) get the task's label and slice, and the ceilings caps, a lower memory or pids limit the worker gave kept, a higher one or none brought down; the swap is set equal to the memory, so that a container never fills the swap. docker update that would lift a ceiling is refused (ErrRefused). Every other command is left as it is. The notes say what was brought down.
func DockerDir ¶
DockerDir and HeadsDir are the wrappers' folders, under root (Root): docker alone, for every worker; the heavy heads, for the agents without a hook.
func Env ¶
Env is what a worker's environment tells the wrappers: its path, its containers' ceilings and Djinn's data folder, and whether its heavy commands wait for their admission (heads). path is Djinn's own PATH.
func Main ¶
Main runs head with args as djinn gate wrap does, root being the wrappers' folder: it finds the real head on the path without the wrappers, binds and bounds docker's containers (Docker), has the command wait for its admission when the environment asks it (EnvAdmit), then runs it in its place (exec). It returns an exit code only when it does not run the command.
func Path ¶
Path is the PATH of a worker: the docker wrapper first, after the heavy heads' when heads, then path.
func Pause ¶
Pause freezes, with docker pause, the running containers that carry every label given (key=value), or, pause false, thaws the paused ones with docker unpause: a worker's (TaskLabel) as the memory brake freezes or thaws it. Docker's daemon owns their cgroups, which Djinn cannot write. Without docker, or with no such container, it does nothing; it gives up after half a minute. It says how many containers it froze or thawed.
func Remove ¶
Remove removes, with docker, the containers that carry every label given (key=value), running or not: a worker's once it ended (TaskLabel), a Djinn's at its start (HomeLabel), its workers then all ended. Without docker, or with no such container, it does nothing; it gives up after half a minute.
Types ¶
type Admit ¶
Admit has command, as the worker wrote it, wait for its admission by the gates, unless it only reads (gate.Plain): its cost is kept under it. Its process is found under the process agent by what it runs, run: docker's arguments once bound. It says why it waited, "" when it did not.
type Caps ¶
type Caps struct {
// Memory is a container's memory, swap included, in bytes.
Memory uint64
// PIDs is a container's processes and threads.
PIDs int64
// File is the project's file Djinn read them in, relative to the project: djinn.yaml or .agents/djinn.yaml;
// empty when the project sets none, and Djinn's defaults hold.
File string
}
Caps are the runaway ceilings of a worker's containers (djinn.v1.Containers, resolved).