wrap

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 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 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

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

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

View Source
const ConfigFile = "djinn.yaml"

ConfigFile is the file a project raises its ceilings in when it has none yet.

Variables

View Source
var ErrRefused = errors.New("refused by Djinn")

ErrRefused is why the wrapper refuses a docker command: it would lift a container's ceilings.

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

func Bytes(s string) (int64, error)

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

func DockerDir(root string) string

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

func Env(root, home, path string, caps Caps, heads bool) []string

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 HeadsDir

func HeadsDir(root string) string

HeadsDir is the folder of the heavy heads' wrappers, under root.

func Main

func Main(root, head string, args []string, stderr io.Writer, admit Admit, exec Exec) int

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

func Path(root, path string, heads bool) string

Path is the PATH of a worker: the docker wrapper first, after the heavy heads' when heads, then path.

func Pause

func Pause(ctx context.Context, pause bool, labels ...string) int

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

func Remove(ctx context.Context, labels ...string)

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.

func Root

func Root(home string) string

Root is where Djinn writes the wrappers, under its data folder home.

func Size

func Size(b uint64) string

Size writes bytes as a person reads it: 4 GiB, 512 MiB.

func Slice

func Slice(taskID string) string

Slice is the systemd slice a task's containers run under (docker's --cgroup-parent): djinn-<task id, its hyphens dropped>.slice, which systemd places under djinn.slice, a dash marking a level.

func Write

func Write(root, djinn string) error

Write writes the wrappers under root, each run by djinn, when they differ from what is there: workers starting together each write their own and rename it.

Types

type Admit

type Admit func(command, run string, agent int) (string, error)

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).

func (Caps) Setting

func (c Caps) Setting() string

Setting names where the project raises its ceilings, as the wrapper's messages say it: the file Djinn read them in, else ConfigFile.

type Exec

type Exec func(path string, args, env []string) error

Exec replaces the current process with the real command: Unix's exec.

Jump to

Keyboard shortcuts

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