Documentation
¶
Overview ¶
Package agentrunapi provides in-process Classify + AutoSendOrResume for agent-run session lifecycle (run | send | resume) without shelling out to the agent-run binary.
Index ¶
- func AutoSendOrResume(ctx context.Context, opts Opts) error
- func BuildFollowUpCommand(opts FollowUpOpts) (string, error)
- func IsSessionReadyFromStatus(stdout string) bool
- func OpenInNewTerminal(opts OpenInNewTerminalOpts) error
- func ParseTTYStatus(stdout string) (screen, sendable string)
- func WaitReady(opts WaitReadyOpts) error
- type FollowUpOpts
- type Mode
- type OpenInNewTerminalOpts
- type Opts
- type ProbeFunc
- type ProbeReport
- type WaitReadyOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoSendOrResume ¶
AutoSendOrResume validates, classifies, and dispatches run|send|resume.
func BuildFollowUpCommand ¶
func BuildFollowUpCommand(opts FollowUpOpts) (string, error)
BuildFollowUpCommand returns a single shell-quoted command line suitable for iterm2 FollowUpCommands. Never includes --new-terminal. Open/Detach mutual exclusion: if both true, return error. Empty SessionID → error.
func IsSessionReadyFromStatus ¶
IsSessionReadyFromStatus reports banner + sendable yes (parity with agentrunbridge.IsSessionReady).
func OpenInNewTerminal ¶
func OpenInNewTerminal(opts OpenInNewTerminalOpts) error
OpenInNewTerminal invokes OpenTerminal(dir, followUp). When OpenTerminal is nil, production uses iterm2 ModeForceNew.
func ParseTTYStatus ¶
ParseTTYStatus extracts screen status and sendable token from human `agent-run tty status` stdout (parity with agentrunbridge.ParseTTYStatus).
Lines:
- "screen status: <value>" → screen (trimmed value after colon)
- "sendable: <token> ..." → first whitespace-separated token of the value
func WaitReady ¶
func WaitReady(opts WaitReadyOpts) error
WaitReady polls StatusFn until IsSessionReadyFromStatus or timeout. Timeout error mentions ready and/or timeout. No agent-run binary LookPath.
Types ¶
type FollowUpOpts ¶
type FollowUpOpts struct {
// DriverBinary empty → "agent-run". Use os.Executable() for self re-exec.
DriverBinary string
// DriverArgsPrefix optional tokens after binary, before "run" (spl helper).
DriverArgsPrefix []string
SessionID string
Prompt string
AgentRunner string
WorkspaceDir string
NoSubmit bool
AllowRelocateResumeSessionDir bool
Open bool
Detach bool
// Env each "KEY=VALUE" → -e KEY=VALUE before -- / prompt (optional).
Env []string
}
FollowUpOpts builds a shell-quoted ForceNew child command (no --new-terminal).
type Mode ¶
type Mode string
Mode is the auto-send-or-resume branch: run | send | resume.
func Classify ¶
func Classify(store agentstorage.Store, sessionID string, probe ProbeFunc) (mode Mode, meta agentstorage.SessionMeta, found bool, err error)
Classify resolves session id and returns Mode using the same rules as cmd/agent-run runAutoSendOrResume. Missing session → ModeRun, found=false.
type OpenInNewTerminalOpts ¶
type OpenInNewTerminalOpts struct {
WorkspaceDir string
// FollowUp if non-empty is used as-is; else built from FollowUpOpts.
FollowUp string
FollowUpOpts FollowUpOpts
// OpenTerminal replaces production iTerm ForceNew when set (unit tests).
OpenTerminal func(dir string, followUp string) error
}
OpenInNewTerminalOpts opens a new terminal with a follow-up command.
type Opts ¶
type Opts struct {
SessionID string
Prompt string
WorkspaceDir string
AgentRunner string
AgentRunnerBinary string
RunnerConfigHome string
Model string
Open bool
Detach bool
NoSubmit bool
KeepTTY bool
JSON bool
AllowRelocateResumeSessionDir bool
// NewTerminal: P1 unit leaves keep false. When true, ForceNew may remain CLI-owned.
NewTerminal bool
Env []string
PrependPaths []string
Store agentstorage.Store
Stdout io.Writer
Stderr io.Writer
Probe ProbeFunc
// Optional dispatch overrides (nil = production path).
RunSession func(ctx context.Context, opts Opts, meta agentstorage.SessionMeta, found bool) error
SendLive func(ctx context.Context, opts Opts, meta agentstorage.SessionMeta) error
ResumeSession func(ctx context.Context, opts Opts, meta agentstorage.SessionMeta) error
}
Opts drives AutoSendOrResume. NewTerminal=false is the in-process P1 path. Dispatch hooks, when set, replace production send/run/resume for unit tests and prove no agent-run binary LookPath is required.
type ProbeFunc ¶
type ProbeFunc func(store agentstorage.Store, meta agentstorage.SessionMeta) (ProbeReport, error)
ProbeFunc injects lifecycle probing. nil → package default (empty report / unknown lifecycle; production callers should inject a real probe).
type ProbeReport ¶
type ProbeReport struct {
// ResumeReady is true when runner is bound and exited (resume path).
ResumeReady bool
// RunnerExited is nil when unknown; false when live; true when exited.
RunnerExited *bool
}
ProbeReport is the lifecycle subset Classify needs (from probeSessionStatus parity).
type WaitReadyOpts ¶
type WaitReadyOpts struct {
SessionID string // required (non-empty after trim)
StatusFn func() (stdout string, err error) // required
Timeout time.Duration // 0 → 60s
PollInterval time.Duration // 0 → 500ms
}
WaitReadyOpts polls an injectable status source until the session is ready.