Documentation
¶
Overview ¶
Package agentrun owns ResolveWorkdir, the filesystem-path canonicaliser used by internal/agentrun/trust to key into ~/.claude.json's projects map. JSONL-path encoding (the dashed ~/.claude/projects/<encoded>/ name) lives in tuidriver, not here.
MUST NOT log file contents. Callers that consume the resolved paths must uphold the same constraint at their layer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExitErrIsBenign ¶ added in v0.14.0
ExitErrIsBenign reports whether err is the OS-level "process already gone" or "self-signalled exit" shape that surfaces during expected teardown of an agent-run child. Returns false for nil and for any other error. Wrapped errors are unwrapped via errors.Is / errors.As.
Benign classes:
- syscall.ESRCH (no such process — kill/signal raced child exit)
- syscall.EPIPE (broken pipe — fd write after child exit)
- os.ErrClosed (write/close after fd already closed)
- *exec.ExitError where ExitCode() == 143 (SIGTERM) or 137 (SIGKILL)
- *exec.ExitError where the child was signal-killed by SIGTERM or SIGKILL (Signaled() with the matching signal — covers the case where the child has no signal handler and ExitCode() returns -1).
func IsNewLogicalTurn ¶ added in v0.14.0
IsNewLogicalTurn reports whether an assistant entry with message id currentID begins a new logical turn, given lastID (the previous assistant entry's id; "" before any assistant entry has been seen).
claude serialises one logical reply as multiple consecutive assistant JSONL entries sharing a message.id (2.1.158 emits a thinking line, a tool_use line, and a text line for a single reply). A new turn begins only when the message.id changes, so a logical-turn count matches claude's native num_turns regardless of how a reply is chunked. An empty currentID is ungroupable (synthetic/malformed entries) → its own turn (the empty-id floor), preserving the pre-fix per-entry behaviour for id-less entries.
This is the single source of truth shared by streamjson's num_turns reporting and budget's --max-turns enforcement, so the reported and enforced turn counts cannot drift on what a turn is. Transition-counting (comparing against the immediately-previous id) equals distinct-id-counting because claude completes one assistant message before starting the next — no A,B,A interleaving has been observed; if it ever is, this is the one place a seen-set would land.
func ReapDescendantGroups ¶ added in v0.16.0
ReapDescendantGroups SIGKILLs every process group that contains a descendant of rootPid, except the caller's own group, rootPid's own group, and the init/invalid group (pgid <= 1). It is the deterministic half of the operator-SIGTERM teardown contract: claude isolates every Bash command into its own detached process group two levels below pyry and does NOT kill that group even when given a graceful SIGTERM, so pyry must reap it here (#565).
Best-effort and content-blind: it reads pid/ppid/pgid triples only — never process command lines — and logs enumeration or signal failures at Warn (pids/pgids only) without propagating them; claude still receives its SIGTERM regardless. Safe to call on the os/exec watcher goroutine: it reads only its arguments, shells out to ps, and issues kills — no shared state.
The caller wires this into cmd.Cancel, which fires only once, at the single teardown moment when rootPid and its whole descendant tree are guaranteed alive and not-yet-signalled — so the ps snapshot sees the live tree and the walk is race-free, not a hopeful defer-time scan.
func ResolveWorkdir ¶
ResolveWorkdir returns the resolved absolute path of workdir, canonicalised the way claude canonicalises its own cwd before reading ~/.claude.json's projects map. It:
- resolves relative paths against the current directory (filepath.Abs),
- resolves symlinks (filepath.EvalSymlinks; on macOS /var → /private/var), and
- rewrites each path component to its on-disk spelling, so a workdir on a case-insensitive filesystem whose configured case differs from disk (e.g. .../WorkSpace configured, .../Workspace on disk) resolves to the spelling claude derives — the key claude reads from the projects map and the key internal/agentrun/trust pre-marks as trusted.
Wraps fs.ErrNotExist when the path does not exist.
Sole remaining caller after #508: internal/agentrun/trust. A follow-up issue tracks eventual removal alongside a tuidriver-exposes-canonicalise change or a local filepath.EvalSymlinks inside trust.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package budget enforces the pyry-side --max-turns cap for agent-run by counting assistant JSONL entries and signalling the claude child when the budget is reached.
|
Package budget enforces the pyry-side --max-turns cap for agent-run by counting assistant JSONL entries and signalling the claude child when the budget is reached. |
|
Package jsonl parses claude session JSONL output into structured events, surfacing every line (assistant, user, tool_use, tool_result, system, attachment, or unrecognised) with its verbatim bytes, alongside a deterministic end-of-turn signal on assistant entries.
|
Package jsonl parses claude session JSONL output into structured events, surfacing every line (assistant, user, tool_use, tool_result, system, attachment, or unrecognised) with its verbatim bytes, alongside a deterministic end-of-turn signal on assistant entries. |
|
Package selfcheck implements the verification that the per-agent tool-allowlist enforcement contract still refuses tools NOT in permissions.allow when claude is spawned headlessly on the stream-json surface with a per-spawn deny-default settings file.
|
Package selfcheck implements the verification that the per-agent tool-allowlist enforcement contract still refuses tools NOT in permissions.allow when claude is spawned headlessly on the stream-json surface with a per-spawn deny-default settings file. |
|
Package settings writes per-spawn deny-default permission JSON files for interactive claude spawned via PTY drive.
|
Package settings writes per-spawn deny-default permission JSON files for interactive claude spawned via PTY drive. |
|
Package streamjson re-emits the parsed claude session-JSONL entry stream onto a writer (typically pyry's stdout) and composes a single `type:"result"` trailer line when the run terminates.
|
Package streamjson re-emits the parsed claude session-JSONL entry stream onto a writer (typically pyry's stdout) and composes a single `type:"result"` trailer line when the run terminates. |
|
Package streamrunner spawns claude with the stream-json input/output formats as a plain subprocess (no PTY), writes one user-turn JSON envelope to its stdin, forwards stdout/stderr to caller-supplied writers, and waits for the child to exit.
|
Package streamrunner spawns claude with the stream-json input/output formats as a plain subprocess (no PTY), writes one user-turn JSON envelope to its stdin, forwards stdout/stderr to caller-supplied writers, and waits for the child to exit. |
|
Package trust pre-answers, in ~/.claude.json, the startup gates a headless claude child cannot answer for itself: the workspace-trust modal that interactive claude (spawned via PTY drive) would render, and the approval that lets a CLAUDE.md `@` import resolving outside the session's working directory expand.
|
Package trust pre-answers, in ~/.claude.json, the startup gates a headless claude child cannot answer for itself: the workspace-trust modal that interactive claude (spawned via PTY drive) would render, and the approval that lets a CLAUDE.md `@` import resolving outside the session's working directory expand. |