adapter

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package adapter resumes agent sessions via their CLIs (spec §6). Adapters are resume-based, never push-based.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildClaudeArgs

func BuildClaudeArgs(sessionID, prompt string) []string

BuildClaudeArgs builds the resume invocation. The prompt is a positional argument terminated by "--" so rendered prompts that start with a dash can never be eaten by claude's option parser (a "--help" prompt would otherwise exit 0 without resuming — a silent false success). --output-format must precede the terminator.

func BuildCodexArgs

func BuildCodexArgs(sessionID, prompt string) []string

BuildCodexArgs: prompt positional after "--" (dash-safe, stage-3 lesson); --skip-git-repo-check keeps non-git repoPaths working.

func BuildCursorArgs

func BuildCursorArgs(sessionID, prompt string) []string

BuildCursorArgs: the prompt is positional after "--" so dash-leading prompts can never be eaten by the option parser (stage-3 lesson).

func BuildOpenCodeArgs

func BuildOpenCodeArgs(sessionID, prompt string) []string

BuildOpenCodeArgs: prompt positional after "--" (dash-safe).

func ParseResultJSON

func ParseResultJSON(out []byte) (string, bool)

ParseResultJSON extracts the "result" field from the JSON object that both Claude (`--output-format json`) and Cursor (`--output-format json`) print; falls back to the raw text. The boolean reports whether structured output was recognized.

Types

type Adapter

type Adapter interface {
	Name() string
	Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)
	Validate() error
}

Adapter resumes a session with an injected prompt and reports the outcome. Resume returns an error only when the run could not even be attempted (binary missing, spawn failure); a nonzero agent exit is a Result, not an error.

type Claude

type Claude struct{}

Claude resumes Claude Code sessions headlessly:

claude --resume <session-id> -p "<prompt>" --output-format json

run in the session's repoPath (restores the original project config — see docs/reference/claude-code.md). v1 passes NO permission flags (owner decision): the agent runs with its project-configured permissions, and unapproved tool calls are denied in headless mode.

func (Claude) Name

func (Claude) Name() string

func (Claude) Resume

func (c Claude) Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)

func (Claude) Validate

func (Claude) Validate() error

type Codex

type Codex struct{}

Codex resumes Codex CLI sessions non-interactively:

codex exec resume <session-id> --skip-git-repo-check -- "<prompt>"

run in the session's repoPath. Default exec mode streams progress to stderr and prints only the final agent message to stdout (see docs/reference/codex-cli.md) — the shared runner keeps them apart. v1 passes NO sandbox/approval flags (owner decision); codex exec defaults to a read-only sandbox, a documented limitation.

func (Codex) Name

func (Codex) Name() string

func (Codex) Resume

func (c Codex) Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)

func (Codex) Validate

func (Codex) Validate() error

type Cursor

type Cursor struct{}

Cursor resumes Cursor CLI sessions headlessly:

agent -p --resume <chat-id> --output-format json -- "<prompt>"

run in the session's repoPath (the CLI treats cwd as the repository root — see docs/reference/cursor-cli.md). The -p+--resume combination is not shown combined in official docs; Validate() existing is why. v1 passes NO permission flags (no --force/--trust — owner decision): in print mode the agent proposes edits without applying them unless the workspace allows it.

func (Cursor) Name

func (Cursor) Name() string

func (Cursor) Resume

func (c Cursor) Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)

func (Cursor) Validate

func (Cursor) Validate() error

type Fake

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

Fake is a controllable in-memory adapter for dispatcher tests.

func NewFake

func NewFake() *Fake

func (*Fake) Calls

func (f *Fake) Calls() []FakeCall

func (*Fake) Name

func (f *Fake) Name() string

func (*Fake) Resume

func (f *Fake) Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)

func (*Fake) SetDelay

func (f *Fake) SetDelay(d time.Duration)

func (*Fake) SetOutcome

func (f *Fake) SetOutcome(exitCode int, err error)

func (*Fake) Validate

func (f *Fake) Validate() error

type FakeCall

type FakeCall struct {
	SessionID string
	RepoPath  string
	Prompt    string
}

type OpenCode

type OpenCode struct{}

OpenCode resumes OpenCode sessions non-interactively:

opencode run --session <ses_id> -- "<prompt>"

run in the session's repoPath (opencode stores sessions per-project keyed by directory — see docs/reference/opencode.md). Known caveat, documented there: opencode's CLI historically exits 0 on some errors; v1 trusts the exit code and records the output summary so failures are at least visible. The serve/HTTP path is a future improvement. v1 passes NO permission flags (owner decision).

func (OpenCode) Name

func (OpenCode) Name() string

func (OpenCode) Resume

func (o OpenCode) Resume(ctx context.Context, sess core.Session, prompt string) (Result, error)

func (OpenCode) Validate

func (OpenCode) Validate() error

type Registry

type Registry map[string]Adapter

Registry maps agent names (core.Session.Agent) to adapters.

type Result

type Result struct {
	Command       string // the command line that ran (for the continuation record)
	ExitCode      int
	OutputSummary string
	DurationMs    int64
}

Result is what supervision records about one resume run.

Jump to

Keyboard shortcuts

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