headless

package
v1.5.20 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 25 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

This file is the headless run driver: the print / stream-json run path (US-020) extracted from the CLI dispatch seam (#363). dispatch resolves the output mode and the run environment, then hands off to Run, which wires the session, prompt, thinking level, and provider credentials into a runtime.HeadlessConfig and executes one run. Plugin slash commands and output mode parsing live here because they are specific to the headless path.

Package headless drives golder's non-interactive run paths: the print / stream-json headless run, the session listing/resume helpers, and the process-isolated sub-agent JSON-RPC server (--subagent-rpc).

This file gives headless / stream-json runs the same session persistence and resume the interactive front-ends have, through the shared persist path (internal/cli/persist.go). Before this, a headless run built an in-memory AgentContext and threw it away on exit, so `--output-format stream-json` emitted no session id and `--resume`/`--continue` only worked in the REPL.

Now a headless run is backed by a session file: resuming seeds the context from a prior session (and re-anchors the branch leaf), a fresh run creates a new session, and in both cases the run's newly produced messages are appended after it completes. The session id is threaded into the run so it appears in the first stream-json event (mirrors pi/Claude Code) and can be passed back via --resume to continue the run.

This file implements the subprocess side of process-isolated sub-agents (US-019, #135). Invoked as `golder --subagent-rpc`, golder speaks JSON-RPC 2.0 over stdio: for each "subagent/run" request on stdin it runs a child agent loop and writes the result (or an error) to stdout, exiting when stdin closes. The parent (SubAgentTool in process mode, internal/runtime) drives it via internal/jsonrpc.

It reuses internal/jsonrpc's message types (Request/Response/ID/Version) for (de)serialization so the wire format matches the client exactly; the agent execution itself is runtime.RunSubAgentOnce.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContinueTarget added in v1.2.16

func ContinueTarget(cwd string) (id, note string, err error)

ContinueTarget resolves --continue for a launch directory: the most recently updated session of the current project. When this project has no sessions the newest session of any project is returned together with a note naming its directory, so continuing across projects is possible but never silent — the caller prints the note. An empty id means the store holds nothing at all.

func ParseOutputMode

func ParseOutputMode(outputFmt string) (runtime.HeadlessMode, error)

ParseOutputMode maps the --output-format flag onto a HeadlessMode, erroring on an unknown value.

func PrintSessions

func PrintSessions(out io.Writer) error

PrintSessions prints the stored sessions, most-recent first, to out. Every project's sessions are listed (this is the explicit "show me everything" command, so it is not filtered) and each row carries the directory the session ran in, which is what makes the rows attributable.

func Run

func Run(ctx context.Context, p RunParams, out, errOut io.Writer) int

Run executes one headless run over p.Prompt, writing agent output to out and diagnostics to errOut, and returns a process exit code (0 = success). The run is backed by a session so its id appears in the first stream-json event and it can be resumed with --resume/--continue; a resumed session seeds its prior messages ahead of the new prompt.

func RunSubAgentRPC

func RunSubAgentRPC(ctx context.Context, in io.Reader, out, errOut io.Writer) int

RunSubAgentRPC is the `golder --subagent-rpc` entry point. It reads newline-delimited JSON-RPC requests from in, runs each sub-agent request, and writes one response per request to out. It returns 0 (success) when stdin closes; a per-request failure is an RPC error response, not a non-zero exit, so the parent can distinguish "the child answered with an error" from "the child crashed" (the latter is detected by the parent's transport when stdout closes without a response).

func SessionStore

func SessionStore() (*session.Store, error)

SessionStore returns the session store rooted at ~/.golder/sessions (or under the state root), creating the directory on first use. It is shared by the headless run path and the interactive REPL.

Types

type RunParams

type RunParams struct {
	Mode          runtime.HeadlessMode
	Env           run.Env
	Prompt        string
	Model         string
	APIKey        string
	ThinkingLevel string
	ResumeID      string
	// MaxContext is the resolved [compaction] max_context value, applied to
	// the run's auto-compaction trigger. The zero value leaves the defaults.
	MaxContext config.MaxContext
}

RunParams carries the resolved inputs for one headless run. Mode and Env are resolved by the caller (dispatch) — Mode via ParseOutputMode, Env via run.SetupEnv — so their distinct exit codes stay at the call site; Run owns the rest of the run lifecycle.

Jump to

Keyboard shortcuts

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