Help us shape the future of Go! Take the 2026 Go Developer Survey

subagent

package
v0.0.204 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TraceHeaderRule separates trace/session status header blocks.
	TraceHeaderRule = "==================================================================="
	// TraceFooterRule separates trace footer messages.
	TraceFooterRule = "-------------------------------------------------------------------"
	// EmptyDisplay is shown when a trace/status field has no value.
	EmptyDisplay = "-"
)

Variables

View Source
var TestProcessNameFunc func(pid int) string

TestProcessNameFunc is a test hook that, when non-nil, overrides the PID → process-name lookup used by autoDetectAgentRunner during Priority 4 (parent-process) detection. Tests set this to inject a fake process tree. The production getProcessName delegates to this hook before falling back to OS calls (ps on darwin, /proc on linux).

Functions

func AutoDetectAgentRunner added in v0.0.30

func AutoDetectAgentRunner(c Config) (runner string, detected bool)

AutoDetectAgentRunner detects the parent agent runner for subagent execution. Explicit Config.AgentRunnerEnv wins, then well-known runner environment variables, then parent-process inspection.

Implementation lives in the lean agentrunner package; this is a thin wrapper so existing callers and doctests keep working.

func FprintTraceFooterFrame added in v0.0.36

func FprintTraceFooterFrame(w io.Writer)

FprintTraceFooterFrame writes the footer rule line before and after a message.

func FprintTraceHeader added in v0.0.36

func FprintTraceHeader(w io.Writer, sessionID string, eventCount int)

FprintTraceHeader writes the standard session/events trace header to w.

func FprintlnTraceFooterRule added in v0.0.36

func FprintlnTraceFooterRule(w io.Writer)

FprintlnTraceFooterRule closes a trace footer block.

func HandleReportProgress

func HandleReportProgress(args []string) error

func HandleYieldPendingQuestions

func HandleYieldPendingQuestions(args []string) error

func Logf

func Logf(fmtStr string, args ...interface{})

func ParseTimeoutDuration added in v0.0.23

func ParseTimeoutDuration(s string) (time.Duration, error)

ParseTimeoutDuration parses a duration string for the --timeout flag.

  • Empty input defaults to 1 hour.
  • Bare numbers (no suffix) are treated as seconds.
  • Otherwise, parsed with time.ParseDuration.
  • Whitespace is trimmed before parsing.
  • Duration < 1 minute returns an error.
  • 1m ≤ duration < 10m prints a warning to stderr.

func PromptContent

func PromptContent(c Config) string

func Run

func Run(ctx context.Context, c Config, opts Options) error

func TestExported_NewSessionLogWriter added in v0.0.20

func TestExported_NewSessionLogWriter() *sessionLogWriter

TestExported_NewSessionLogWriter creates a sessionLogWriter for testing.

func TestExported_autoDetectAgentRunner added in v0.0.21

func TestExported_autoDetectAgentRunner(c Config) (string, bool)

TestExported_autoDetectAgentRunner wraps the unexported autoDetectAgentRunner for doctest access.

func TestExported_formatEventLine added in v0.0.22

func TestExported_formatEventLine(line string) string

TestExported_formatEventLine wraps the unexported formatEventLine for doctest access.

func TestExported_parseTimeoutDuration added in v0.0.23

func TestExported_parseTimeoutDuration(s string) (time.Duration, error)

TestExported_parseTimeoutDuration wraps ParseTimeoutDuration for doctest access.

func TestExported_runAgent added in v0.0.20

func TestExported_runAgent(ctx context.Context, agentRunner, model, prompt, sessionID string, rawLog *sessionLogWriter) (string, error)

TestExported_runAgent wraps the unexported runAgent for doctest access.

func TestExported_showStatus added in v0.0.22

func TestExported_showStatus(c Config, opts Options) error

TestExported_showStatus wraps the unexported showStatus for doctest access.

func TestExported_traceSession added in v0.0.22

func TestExported_traceSession(c Config, opts Options) error

TestExported_traceSession wraps the unexported traceSession for doctest access.

Types

type AgentRunInfo added in v0.0.36

type AgentRunInfo struct {
	InnerSessionID string
	AgentRunner    string
}

type Config

type Config struct {
	RoleName         string
	Cmd              string
	PromptContent    string
	SessionEnvVar    string
	SessionMetaField string
	DebugSessionEnv  string
	AgentRunnerEnv   string
	ModelEnv         string
	// SessionRetryHint formats the suggested retry CLI when session id cannot be
	// auto-detected. Receives sessionID and prompt. When nil, defaults to
	// `doctest agent <Cmd> --session-id <id> <prompt>`.
	SessionRetryHint func(sessionID, prompt string) string
	// AutoGenerateSessionID when true generates a session ID when flag, env var,
	// and CODEX_THREAD_ID are all unset. Default false returns an error with retry hint.
	AutoGenerateSessionID bool
	// HomeDir overrides os.UserHomeDir when resolving the default sessions base
	// (SessionBase and debug-session env empty). Prefer Options.SessionBase in
	// production; HomeDir is mainly for parallel-safe tests.
	HomeDir string
	// EnvLookup, when non-nil, is consulted before os.Getenv for library env
	// reads (session ID, debug session home, model, detection). Return
	// (value, true) to force a value (empty string = treat as unset); ( "", false)
	// falls through to the process environment. Request-scoped and parallel-safe.
	EnvLookup func(key string) (string, bool)
}

type Options

type Options struct {
	Prompt        string
	AgentRunner   string
	MockConfig    string
	SessionID     string
	Requirement   string
	CatchUp       bool
	Status        bool
	ListSessions  bool
	SessionBase   string
	SessionLayout SessionLayout
	Timeout       time.Duration
	// StdoutWriter receives streamed agent output instead of os.Stdout when set.
	StdoutWriter io.Writer

	// When true, subagent must not read or write meta.json. Session match/resume
	// uses SessionID and ResumeInnerSessionID; host persists via OnAgentComplete.
	HostOwnsMeta bool
	// Inner runner session for resume (from host meta.opencode_session_id).
	ResumeInnerSessionID string
	// Called after successful agent run; host persists to its meta.
	OnAgentComplete func(AgentRunInfo) error
}

type SessionLayout added in v0.0.36

type SessionLayout struct {
	// Dir is the session root. When set, use this directory directly
	// (no date nesting, no sess_* auto-create). Required for task-hub integration.
	Dir string

	// Per-file overrides. Empty = filepath.Join(Dir, <default-name>).
	MetaPath     string
	MessagesPath string // empty = skip messages.jsonl writes
	EventsPath   string
	PIDPath      string
	QuestionsDir string // custom path when questions enabled
	ProgressDir  string // custom path when progress enabled

	// Optional features — default ON in legacy mode (Dir unset).
	// When Dir is set, caller must set these explicitly.
	QuestionsEnabled bool
	ProgressEnabled  bool
}

SessionLayout overrides where subagent reads/writes session files. Zero value = default layout under ~/.agent-pro/subagent/<role>/sessions/.

Jump to

Keyboard shortcuts

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