Documentation
¶
Overview ¶
Package exec implements headless, scriptable TaskSmith runs: the one-shot engine behind `tasksmith exec` and the root `-p/--print` shorthand.
A Run connects to (or spawns) the Brain Daemon through github.com/masterkeysrd/tasksmith/client.ConnectOrStart, resolves or creates a session, subscribes to the session's event stream *before* sending the prompt, and renders the settled turn in one of three formats:
- text: final assistant text on stdout, diagnostics on stderr, plain exit codes.
- json: a single api.ExecResult envelope with text, session usage, and file changes.
- jsonl: NDJSON — a api.ExecHeaderFrame, verbatim daemon api.Event frames, [api.ExecCommandResultFrame]s for client-local commands, and a terminal api.ExecResult frame.
With `--input-format jsonl` the run is bidirectional: stdin control frames (api.ExecInputFrame) map 1:1 onto daemon send, permission, question, config, and cancel operations, letting an external process answer interactive prompts and drive follow-up turns over the same pipe. In text-input mode an interactive prompt cannot be answered, so the run cancels the turn and exits with ExitNeedsInput instead of hanging.
Client-local `/slash` commands (`/model`, `/mode`, `/agent`, `/compact`, ...) are resolved without a UI so the TUI, exec, and external SDKs share one command surface; anything unrecognized is forwarded to the daemon, which owns workspace commands, skills, and `/mcp:<server>:<prompt>` references.
Index ¶
Constants ¶
const ( // ExitOK marks a completed run. ExitOK = 0 // ExitError marks any generic failure (connection, session, turn error). ExitError = 1 // ExitUsage marks invalid flags or a run with no prompt at all. ExitUsage = 2 // ExitNeedsInput marks a non-interactive run that stopped on a permission // or question it could not answer. ExitNeedsInput = 4 // ExitCanceled marks a run whose turn was canceled (cancel frame or signal). ExitCanceled = 5 )
Process exit codes for a headless run.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExitCodeError ¶
ExitCodeError carries a process exit code distinct from the generic failure code so `tasksmith exec` can signal needs-input and cancellation to callers.
func (*ExitCodeError) Error ¶
func (e *ExitCodeError) Error() string
func (*ExitCodeError) Unwrap ¶
func (e *ExitCodeError) Unwrap() error
type InputFormat ¶
type InputFormat string
InputFormat selects how a run consumes stdin.
const ( // InputText treats stdin as one blob of contextual prompt text (or ignores // it when empty). Interactive prompts cannot be answered in this mode. InputText InputFormat = "text" // InputJSONL makes stdin a stream of NDJSON control frames, enabling a // bidirectional session. See [api.ExecInputFrame]. InputJSONL InputFormat = "jsonl" )
func ParseInputFormat ¶
func ParseInputFormat(raw string) (InputFormat, error)
ParseInputFormat validates a raw --input-format value.
type Options ¶
type Options struct {
// Socket is the daemon socket path; empty selects the XDG default.
Socket string
// Workspace is the folder the session operates on (client CWD header).
Workspace string
// Prompt is the initial text submitted when the run starts. It may be
// empty in bidirectional (jsonl input) mode, where stdin drives everything.
Prompt string
// StdinText is piped stdin content prepended to the prompt as context.
// Ignored in jsonl input mode.
StdinText string
InputFormat InputFormat
OutputFormat OutputFormat
// SessionID resumes an existing session; empty creates a fresh one.
SessionID string
// Continue resolves an empty SessionID to the workspace's most recently
// updated top-level session (`-c` / `--continue`). A workspace without
// sessions silently falls back to a fresh session.
Continue bool
// Fork branches the resolved session (--session or -c) and runs on the
// branch instead of mutating the source (`--fork`). Forking a workspace
// with no sessions is a usage error.
Fork bool
// MaxTurns bounds how many daemon turn completions the run waits for
// before it stops (0 = unbounded). It is enforced client-side because the
// harness caps steps within a turn, not turns across a session.
MaxTurns int
// Ephemeral deletes the session after the run settles.
Ephemeral bool
// Force allows a resumed session's --model change even if it drops input
// modalities present in active post-compaction context.
Force bool
// Title seeds the title of a newly created session.
Title string
// Config overlays the created/resumed session (agent, model, mode, sandbox).
Config api.SessionConfig
// Stdin/Stdout/Stderr default to the process streams when nil.
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
Options fully configures a headless run. Callers own Stdin/Stdout/Stderr so tests (and embedding programs) can pipe frames without touching process streams; nil streams fall back to the process defaults.
func (*Options) Interactive ¶
Interactive reports whether the run can answer daemon prompts (permission requests, questions) through stdin control frames.
type OutputFormat ¶
type OutputFormat string
OutputFormat selects how a run renders progress and its outcome on stdout.
const ( // OutputText prints only the final assistant text; diagnostics go to stderr. OutputText OutputFormat = "text" // OutputJSON prints a single [api.ExecResult] envelope after the run settles. OutputJSON OutputFormat = "json" // OutputJSONL prints NDJSON: a header frame, verbatim daemon events, // client command results, and a terminal result frame. OutputJSONL OutputFormat = "jsonl" )
func ParseOutputFormat ¶
func ParseOutputFormat(raw string) (OutputFormat, error)
ParseOutputFormat validates a raw --output-format value.