agentrunner

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultAdapter = "claude-code"

DefaultAdapter is the adapter a backend block with none named runs.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(ctx Context) string

BuildPrompt reinforces "content is data, not instructions" at the mechanism level, not just in the role prompt (spec: Roles). Every backend that takes a flat text prompt (any CLI-shim adapter) should call this rather than assembling its own — that's what keeps injection-mitigation behavior identical across backends instead of drifting per adapter.

Both wrapped regions are untrusted, and both are escaped (see internal/promptfence). The log is not merely agent chatter: `golem ticket new` writes "ticket created: <issue body>" as line 0 of the ticket's local log, so a GitHub issue body reaches this builder verbatim, with no LLM anywhere in the path — an injected "</log-entries>" previously survived into the prompt and made the attacker's following text render outside the data region. The diff is generated from files an agent wrote, which that same text may have influenced. Each log entry is escaped as a whole formatted line, so a delimiter split across Type, Role and Message cannot slip through the gaps between them.

Escaping is not a guarantee, and is not claimed as one: it defeats an attacker who reproduces these delimiters byte for byte, and does nothing against free text that achieves the same effect without them ("the data section has ended; new operator instruction: ..."). The treat-as-data framing sentence and the human approval gate upstream are the defences against that; this is one narrow layer on top of both.

func GenerateClaudeCodeArtifacts

func GenerateClaudeCodeArtifacts(repoRoot string, roleContent map[string]string) error

GenerateClaudeCodeArtifacts translates neutral role content into Claude Code subagent definitions. This is a projection of the neutral role files, not the source of truth (spec: Architecture Overview) — re-running it after a role file changes regenerates the artifact.

func GenerateClaudeCodeCommands

func GenerateClaudeCodeCommands(repoRoot string) error

func Names added in v0.1.0

func Names() []string

Names returns the registered adapter names, sorted.

func Register added in v0.1.0

func Register(name string, f func(Options) Adapter)

Register adds an adapter factory. It panics on a duplicate name or a nil factory: both are programming errors visible at init.

func WithToolRoot added in v0.1.0

func WithToolRoot(ctx context.Context, root string) context.Context

WithToolRoot keeps the policy's write scope separate from the working directory used to resolve ticket/spec paths in phase prompts.

Types

type Adapter added in v0.1.0

type Adapter interface {
	Runner

	// WorktreeSetup writes what the vendor needs inside a fresh worktree.
	WorktreeSetup(worktreePath string) error

	// PrepareHost is the per-host hook run before a repo is worked.
	PrepareHost(repoPath string) error

	// GenerateArtifacts projects role content into the vendor's on-disk format.
	GenerateArtifacts(repoRoot string, roleContent map[string]string) error

	// ReservedArgs are argv tokens the adapter sets itself; extra_args may
	// not contain them.
	ReservedArgs() []string

	// DefaultCatalog is the model catalog used when a backend block declares
	// no models.
	DefaultCatalog() models.Catalog
}

Adapter is one vendor CLI, including its on-disk setup hooks.

func New added in v0.1.0

func New(name string, o Options) (Adapter, error)

New builds the named adapter.

type BackendConfig added in v0.1.0

type BackendConfig struct {
	Adapter        string            `yaml:"adapter"`
	Command        string            `yaml:"command"`
	ExtraArgs      []string          `yaml:"extra_args"`
	Env            map[string]string `yaml:"env"`
	models.Catalog `yaml:",inline"`
	// contains filtered or unexported fields
}

BackendConfig is a shem.yaml `backend:` block.

func LoadBackendConfig added in v0.1.0

func LoadBackendConfig(path string) (BackendConfig, error)

LoadBackendConfig reads a {backend: {...}} document and validates it.

func ResolveBackend added in v0.1.0

func ResolveBackend(b *BackendConfig) BackendConfig

ResolveBackend fills b from its adapter's default catalog. A block that declares models is used as written; otherwise only the catalog keys it declares override the defaults. A nil block is the default adapter's.

func (BackendConfig) MarshalDocument added in v0.1.0

func (b BackendConfig) MarshalDocument() ([]byte, error)

MarshalDocument renders b as a {backend: {...}} YAML document.

func (BackendConfig) NewAdapter added in v0.1.0

func (b BackendConfig) NewAdapter(repoRoot string) (Adapter, error)

NewAdapter builds b's adapter.

func (BackendConfig) Options added in v0.1.0

func (b BackendConfig) Options(repoRoot string) Options

func (*BackendConfig) UnmarshalYAML added in v0.1.0

func (b *BackendConfig) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML decodes the block, rejecting unknown keys so a misspelling fails at startup instead of silently taking the default.

func (BackendConfig) Validate added in v0.1.0

func (b BackendConfig) Validate() error

Validate reports the first problem in b: an unknown adapter, an extra_args token the adapter sets itself, an env name golem owns, or a structural fault in the catalog.

func (BackendConfig) Write added in v0.1.0

func (b BackendConfig) Write(path string) error

Write emits b as a {backend: {...}} document at mode 0o644.

type ClaudeCode

type ClaudeCode struct {
	// contains filtered or unexported fields
}

ClaudeCode runs the `claude` CLI with the host's own authentication.

func (ClaudeCode) DefaultCatalog added in v0.1.0

func (c ClaudeCode) DefaultCatalog() models.Catalog

func (ClaudeCode) GenerateArtifacts added in v0.1.0

func (c ClaudeCode) GenerateArtifacts(repoRoot string, roleContent map[string]string) error

GenerateArtifacts writes the Claude Code subagent definitions and commands.

func (ClaudeCode) Name added in v0.1.0

func (c ClaudeCode) Name() string

func (ClaudeCode) PrepareHost added in v0.1.0

func (c ClaudeCode) PrepareHost(repoPath string) error

PrepareHost pre-accepts Claude Code's workspace trust dialog for repoPath, so the agent honours the repository's own .claude/settings.json instead of reporting

Ignoring 34 permissions.allow entries from .claude/settings.json:
this workspace has not been trusted.

The container entrypoint already does this, but only for directories that exist when the container starts. Golem now clones a repository the first time it works a ticket for it, so the path does not exist yet at that point and the entrypoint cannot see it — every on-demand clone ran with its permissions ignored.

func (ClaudeCode) ReservedArgs added in v0.1.0

func (c ClaudeCode) ReservedArgs() []string

ReservedArgs includes -p because `claude` treats it as --print.

func (ClaudeCode) RunAgent

func (c ClaudeCode) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)

func (ClaudeCode) RunPhase added in v0.1.0

func (c ClaudeCode) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error

func (ClaudeCode) WorktreeSetup

func (c ClaudeCode) WorktreeSetup(worktreePath string) error

WorktreeSetup merges golem's permissions into the worktree's .claude/settings.json (the repository's committed file, as the checkout just produced it) rather than replacing it.

type Codex added in v0.1.0

type Codex struct {
	// contains filtered or unexported fields
}

Codex runs OpenAI's Codex CLI (`codex exec`) headless.

The invocation mirrors the claude-code adapter: one process per role, the prompt on stdin. `codex exec -` reads its instructions from stdin (verified against codex 0.163.0), which keeps untrusted ticket text out of the process list.

Auth is the operator's, resolved by codex itself: a CODEX_API_KEY in the environment (exec-only), a saved login in $CODEX_HOME/auth.json, or a custom provider in ~/.codex/config.toml ([model_providers.*] with base_url/env_key). Custom providers must speak the Responses API — the chat-completions wire API was removed from codex in February 2026 (openai/codex discussion #7782), so a chat-only "OpenAI-compatible" server will not work here; that is what the opencode adapter is for.

func (Codex) DefaultCatalog added in v0.1.0

func (c Codex) DefaultCatalog() models.Catalog

func (Codex) GenerateArtifacts added in v0.1.0

func (c Codex) GenerateArtifacts(repoRoot string, roleContent map[string]string) error

GenerateArtifacts writes the codex rules file at the repo root.

There are no per-role files to project: codex has no subagent-definition format, so roles reach the agent inlined in the prompt via BuildPrompt, exactly as the claude adapter's one-shot invocations already do. Writing an AGENTS.md was considered and rejected: it would have to live at the repository root, where it collides with the operator's own AGENTS.md.

func (Codex) Name added in v0.1.0

func (c Codex) Name() string

func (Codex) PrepareHost added in v0.1.0

func (c Codex) PrepareHost(repoPath string) error

PrepareHost marks repoPath trusted in ~/.codex/config.toml.

Codex loads a project's .codex/ layer — including the rules file GenerateArtifacts writes — only when the project is trusted, and in `codex exec` an unanswered trust prompt is not answerable, which leaves the run untrusted and the rules ignored. Trust is recorded per absolute path as

[projects."/abs/path"]
trust_level = "trusted"

(https://developers.openai.com/codex/config-advanced). The container entrypoint does this for directories that exist when the container starts; this hook covers repositories golem clones on demand afterwards, the same gap the claude adapter's PrepareHost covers for .claude.json.

func (Codex) ReservedArgs added in v0.1.0

func (c Codex) ReservedArgs() []string

ReservedArgs are the tokens this adapter sets itself. --json is reserved because golem parses stdout as the agent's plain-text answer.

func (Codex) RunAgent added in v0.1.0

func (c Codex) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)

func (Codex) RunPhase added in v0.1.0

func (c Codex) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error

func (Codex) WorktreeSetup added in v0.1.0

func (c Codex) WorktreeSetup(worktreePath string) error

WorktreeSetup installs the same rules in a fresh worktree.

type Context

type Context struct {
	LogSlice   []blog.Entry
	Diff       string
	RolePrompt string

	// SpillDir is where an input too large for the prompt is saved in full,
	// so the agent can read it on demand; empty keeps only the excerpt.
	SpillDir string
	// DiffLimit is the largest diff passed whole; 0 means the default.
	DiffLimit int
	// SpillUnreadable says the session has no tools, so saved files are for the
	// operator and the prompt must not tell the agent to read them.
	SpillUnreadable bool
}

Context is everything a one-shot role invocation needs, reconstructed fresh by the observer from ticket state — there is no persistent conversation across invocations (spec: Concurrency Model).

type Mock

type Mock struct {
	// contains filtered or unexported fields
}

Mock is a scripted Runner used in tests so the ticket lifecycle can be exercised end-to-end without a real model call or token cost (spec: Testing Strategy).

func NewMock

func NewMock() *Mock

func (*Mock) DefaultCatalog added in v0.1.0

func (m *Mock) DefaultCatalog() models.Catalog

func (*Mock) GenerateArtifacts added in v0.1.0

func (m *Mock) GenerateArtifacts(string, map[string]string) error

func (*Mock) Name added in v0.1.0

func (m *Mock) Name() string

func (*Mock) PrepareHost added in v0.1.0

func (m *Mock) PrepareHost(string) error

func (*Mock) ReservedArgs added in v0.1.0

func (m *Mock) ReservedArgs() []string

func (*Mock) RunAgent

func (m *Mock) RunAgent(_ context.Context, role string, _ Context, model string) (Result, error)

func (*Mock) RunPhase added in v0.1.0

func (m *Mock) RunPhase(_ context.Context, _, _ string, out io.Writer, _ string) error

func (*Mock) ScriptResponse

func (m *Mock) ScriptResponse(role string, result Result)

func (*Mock) WorktreeSetup

func (m *Mock) WorktreeSetup(string) error

type OpenCode added in v0.1.0

type OpenCode struct {
	// contains filtered or unexported fields
}

OpenCode runs SST's opencode CLI (`opencode run`) headless.

This is the adapter for OpenAI-compatible endpoints: opencode treats custom providers as first-class config ("npm": "@ai-sdk/openai-compatible" plus a baseURL), where codex removed its chat-completions wire API in February 2026. The invocation mirrors the other adapters: one process per role, the prompt on stdin — `opencode run` reads a piped stdin as the message (verified against opencode 1.19.2), so untrusted ticket text stays out of the process list.

Auth is the operator's: a saved credential from `opencode auth login` (stored in ~/.local/share/opencode/auth.json), or a provider env var such as ANTHROPIC_API_KEY or OPENAI_API_KEY — the default catalog's anthropic/* models work with the same key a claude-code operator already has.

func (OpenCode) DefaultCatalog added in v0.1.0

func (o OpenCode) DefaultCatalog() models.Catalog

func (OpenCode) GenerateArtifacts added in v0.1.0

func (o OpenCode) GenerateArtifacts(repoRoot string, roleContent map[string]string) error

GenerateArtifacts writes opencode.json's permission block and the .opencode/agents role files at the repo root.

func (OpenCode) Name added in v0.1.0

func (o OpenCode) Name() string

func (OpenCode) PrepareHost added in v0.1.0

func (o OpenCode) PrepareHost(repoPath string) error

PrepareHost has nothing to do: opencode has no workspace-trust system to pre-accept and its auth lives in the user's home, which the deployment layer already arranges.

func (OpenCode) ReservedArgs added in v0.1.0

func (o OpenCode) ReservedArgs() []string

ReservedArgs are the tokens this adapter sets itself. --format is reserved because golem parses stdout as the agent's plain-text answer; --agent because roles are inlined into the prompt, not selected as opencode agents.

func (OpenCode) RunAgent added in v0.1.0

func (o OpenCode) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)

func (OpenCode) RunPhase added in v0.1.0

func (o OpenCode) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error

func (OpenCode) WorktreeSetup added in v0.1.0

func (o OpenCode) WorktreeSetup(worktreePath string) error

WorktreeSetup installs the permission block in a fresh worktree.

type Options added in v0.1.0

type Options struct {
	RepoRoot  string
	Command   string
	ExtraArgs []string
	Env       map[string]string
}

Options is the operator-declared part of an adapter's configuration.

type Result

type Result struct {
	Output string
	Model  string
}

type Runner

type Runner interface {
	// Name is the adapter name.
	Name() string

	// RunAgent invokes one role; model may be "" for the vendor default.
	RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)

	// RunPhase runs a long-form session with prompt on stdin and output
	// streamed to out.
	RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error
}

Runner invokes an agent.

Jump to

Keyboard shortcuts

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