Documentation
¶
Index ¶
- Constants
- func BuildPrompt(ctx Context) string
- func GenerateClaudeCodeArtifacts(repoRoot string, roleContent map[string]string) error
- func GenerateClaudeCodeCommands(repoRoot string) error
- func Names() []string
- func Register(name string, f func(Options) Adapter)
- func WithToolRoot(ctx context.Context, root string) context.Context
- type Adapter
- type BackendConfig
- func (b BackendConfig) MarshalDocument() ([]byte, error)
- func (b BackendConfig) NewAdapter(repoRoot string) (Adapter, error)
- func (b BackendConfig) Options(repoRoot string) Options
- func (b *BackendConfig) UnmarshalYAML(n *yaml.Node) error
- func (b BackendConfig) Validate() error
- func (b BackendConfig) Write(path string) error
- type ClaudeCode
- func (c ClaudeCode) DefaultCatalog() models.Catalog
- func (c ClaudeCode) GenerateArtifacts(repoRoot string, roleContent map[string]string) error
- func (c ClaudeCode) Name() string
- func (c ClaudeCode) PrepareHost(repoPath string) error
- func (c ClaudeCode) ReservedArgs() []string
- func (c ClaudeCode) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)
- func (c ClaudeCode) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error
- func (c ClaudeCode) WorktreeSetup(worktreePath string) error
- type Codex
- func (c Codex) DefaultCatalog() models.Catalog
- func (c Codex) GenerateArtifacts(repoRoot string, roleContent map[string]string) error
- func (c Codex) Name() string
- func (c Codex) PrepareHost(repoPath string) error
- func (c Codex) ReservedArgs() []string
- func (c Codex) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)
- func (c Codex) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error
- func (c Codex) WorktreeSetup(worktreePath string) error
- type Context
- type Mock
- func (m *Mock) DefaultCatalog() models.Catalog
- func (m *Mock) GenerateArtifacts(string, map[string]string) error
- func (m *Mock) Name() string
- func (m *Mock) PrepareHost(string) error
- func (m *Mock) ReservedArgs() []string
- func (m *Mock) RunAgent(_ context.Context, role string, _ Context, model string) (Result, error)
- func (m *Mock) RunPhase(_ context.Context, _, _ string, out io.Writer, _ string) error
- func (m *Mock) ScriptResponse(role string, result Result)
- func (m *Mock) WorktreeSetup(string) error
- type OpenCode
- func (o OpenCode) DefaultCatalog() models.Catalog
- func (o OpenCode) GenerateArtifacts(repoRoot string, roleContent map[string]string) error
- func (o OpenCode) Name() string
- func (o OpenCode) PrepareHost(repoPath string) error
- func (o OpenCode) ReservedArgs() []string
- func (o OpenCode) RunAgent(ctx context.Context, role string, in Context, model string) (Result, error)
- func (o OpenCode) RunPhase(ctx context.Context, dir, prompt string, out io.Writer, model string) error
- func (o OpenCode) WorktreeSetup(worktreePath string) error
- type Options
- type Result
- type Runner
Constants ¶
const DefaultAdapter = "claude-code"
DefaultAdapter is the adapter a backend block with none named runs.
Variables ¶
This section is empty.
Functions ¶
func BuildPrompt ¶
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 ¶
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 Names ¶ added in v0.1.0
func Names() []string
Names returns the registered adapter names, sorted.
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.
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) 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 (Codex) GenerateArtifacts ¶ added in v0.1.0
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) PrepareHost ¶ added in v0.1.0
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
ReservedArgs are the tokens this adapter sets itself. --json is reserved because golem parses stdout as the agent's plain-text answer.
func (Codex) WorktreeSetup ¶ added in v0.1.0
WorktreeSetup installs the same rules in a fresh worktree.
type Context ¶
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 (*Mock) DefaultCatalog ¶ added in v0.1.0
func (*Mock) GenerateArtifacts ¶ added in v0.1.0
func (*Mock) PrepareHost ¶ added in v0.1.0
func (*Mock) ReservedArgs ¶ added in v0.1.0
func (*Mock) ScriptResponse ¶
func (*Mock) WorktreeSetup ¶
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 (OpenCode) GenerateArtifacts ¶ added in v0.1.0
GenerateArtifacts writes opencode.json's permission block and the .opencode/agents role files at the repo root.
func (OpenCode) PrepareHost ¶ added in v0.1.0
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
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) WorktreeSetup ¶ added in v0.1.0
WorktreeSetup installs the permission block in a fresh worktree.
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.