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 REPL has (cmd/golder/interactive.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 ¶
- func ContinueTarget(cwd string) (id, note string, err error)
- func ParseOutputMode(outputFmt string) (runtime.HeadlessMode, error)
- func PrintSessions(out io.Writer) error
- func Run(ctx context.Context, p RunParams, out, errOut io.Writer) int
- func RunSubAgentRPC(ctx context.Context, in io.Reader, out, errOut io.Writer) int
- func SessionStore() (*session.Store, error)
- type RunParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContinueTarget ¶ added in v1.2.16
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 ¶
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 ¶
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 ¶
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 ¶
SessionStore returns the session store rooted at ~/.golder/sessions (or under GOLDER_HOME when set), 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.