api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api serves a small newline-delimited JSON protocol over a unix socket, so an agent harness can drive the environment programmatically (run commands, branch, roll back) and get structured results — including the snapshot node id produced by each command, which it can later checkout or branch from.

One JSON request per line; one JSON response per line. Example:

{"op":"exec","cmd":"apt-get install -y jq"}
-> {"ok":true,"exit":0,"stdout":"...","node":"ab12cd34ef56","head":"ab12cd34ef56"}

Index

Constants

View Source
const HTTPVersion = "0.3.0"

HTTPVersion is reported in the OpenAPI spec's info block. Bumped manually alongside backwards-incompatible HTTP-layer changes (independent of the agentenv release tag, which can grow without changing this surface).

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, r *repo.Repo, c *repo.Capturer, sockPath string) error

Serve listens on sockPath and serves requests until ctx is cancelled.

Security: the socket is created with default fs perms (~0755 after umask), which lets ANY local user connect and invoke `exec` — i.e. run arbitrary commands as whoever runs agentenv (often root). We immediately tighten it to 0600 so only the owning uid can talk to the daemon. Callers that need to share the socket across UIDs should chmod/chown it themselves AFTER Serve has started (with full awareness of the implications).

func ServeHTTP added in v0.3.0

func ServeHTTP(ctx context.Context, r *repo.Repo, _ *repo.Capturer, addr, token string) error

ServeHTTP runs the HTTP API on addr (e.g. "127.0.0.1:8911"). Blocks until ctx is cancelled. When token != "", every request must carry `Authorization: Bearer <token>` — non-loopback addresses without a token are rejected at startup as a safety guard. Compatible with the socket dispatch: both paths call the same r.* and the same repo handles the locking.

Types

This section is empty.

Jump to

Keyboard shortcuts

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