Documentation
¶
Overview ¶
Package claudecode is the Claude Code harness adapter (design §7, ADR-0001).
Each delivered message runs one unattended `claude -p` process:
claude -p --output-format stream-json --verbose [--bare]
[--resume <session_id>] --mcp-config <runner>/claude/mcp.json --strict-mcp-config
--settings <runner>/claude/settings.json --append-system-prompt <bootstrap>
--permission-mode bypassPermissions --permission-prompts none [--model <m>]
with the prompt (envelope + body) on stdin, HOME=/seat/home and cwd=/seat/workspace. Platform tools arrive through `steadmesh-tools mcp`. The model is reached only through the seat runner's local forwarder (ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/model/<connection>), which adds the seat's current token to every request for the platform model proxy; ANTHROPIC_API_KEY is a placeholder. No model credential enters the sandbox. Every model role (background, subagent) is pinned to the profile's model, the only one the proxy accepts for the seat.
Checkpoint = session id + claude version (application_checkpoint). When a session cannot be resumed, the adapter starts a new session seeded with the portable handoff and reports a recovery note; it never claims byte-for-byte continuation (§6.4).
Index ¶
- Constants
- type Adapter
- func (a *Adapter) Args(sessionID, systemPrompt string) []string
- func (a *Adapter) Checkpoint(ctx context.Context) (runtimeapi.Checkpoint, error)
- func (a *Adapter) Deliver(ctx context.Context, d harnesses.Delivery) (harnesses.TurnResult, error)
- func (a *Adapter) DescribeCapabilities() harnesses.Capabilities
- func (a *Adapter) Events() <-chan harnesses.Event
- func (a *Adapter) Prepare(ctx context.Context, env harnesses.Environment) error
- func (a *Adapter) Quiesce(ctx context.Context) (harnesses.QuiesceResult, error)
- func (a *Adapter) StartOrResume(ctx context.Context, rec harnesses.RecoveryDescriptor) (harnesses.ResumeResult, error)
- func (a *Adapter) Stop(ctx context.Context) error
- type Init
- type ParsedEvent
- type Result
- type SessionState
- type StreamParser
Constants ¶
const ( // AdapterName is the harness profile adapter value. AdapterName = "claude-code" // PinnedVersion is the Claude Code version the seat image installs and the // feasibility spike verified (docs/decisions.html#harness). PinnedVersion = "2.1.289" // SessionFormatPrefix prefixes Checkpoint.FormatVersion. SessionFormatPrefix = "claude-code-session/" // MCPServerName is the server key in mcp.json; tools appear to the model // as mcp__steadmesh__<tool>. MCPServerName = "steadmesh" )
const ( ConfigBinary = "claude_bin" // default "claude" ConfigVersion = "version" // when set, Prepare requires exactly this version ConfigPermissionMode = "permission_mode" // default bypassPermissions ConfigBare = "bare" // default "true" ConfigAllowedTools = "allowed_tools" // optional --allowedTools value ConfigPromptSnapshot = "system_prompt_snapshot" ConfigInterruptGrace = "interrupt_grace" // Go duration, default 10s ConfigMaxRetries = "max_retries" // CLAUDE_CODE_MAX_RETRIES, default 4 )
Harness profile config keys (HarnessProfile.Config).
const SettingEffort = "effort"
SettingEffort is the model.settings key passed as --effort (CONTRACT.md).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// Tap, when set before Prepare, receives every raw stream-json line
// (diagnostics and recording test fixtures).
Tap func(line []byte)
// contains filtered or unexported fields
}
Adapter runs Claude Code.
func (*Adapter) Checkpoint ¶
func (a *Adapter) Checkpoint(ctx context.Context) (runtimeapi.Checkpoint, error)
func (*Adapter) DescribeCapabilities ¶
func (a *Adapter) DescribeCapabilities() harnesses.Capabilities
func (*Adapter) StartOrResume ¶
func (a *Adapter) StartOrResume(ctx context.Context, rec harnesses.RecoveryDescriptor) (harnesses.ResumeResult, error)
type Init ¶
type Init struct {
SessionID string `json:"session_id"`
Model string `json:"model"`
Tools []string `json:"tools"`
PermissionMode string `json:"permissionMode"`
APIKeySource string `json:"apiKeySource"`
Version string `json:"claude_code_version"`
MCPServers []struct {
Name string `json:"name"`
Status string `json:"status"`
} `json:"mcp_servers"`
}
Init is the "system/init" line.
type ParsedEvent ¶
ParsedEvent is a harness event derived from one stream-json line.
type Result ¶
type Result struct {
Subtype string `json:"subtype"`
IsError bool `json:"is_error"`
Result string `json:"result"`
SessionID string `json:"session_id"`
NumTurns int `json:"num_turns"`
DurationMS int64 `json:"duration_ms"`
TotalCostUSD float64 `json:"total_cost_usd"`
StopReason *string `json:"stop_reason"`
Errors []string `json:"errors"`
Usage json.RawMessage `json:"usage"`
}
Result is the terminal "result" line of a claude -p run.
type SessionState ¶
type SessionState struct {
SessionID string `json:"session_id"`
ClaudeVersion string `json:"claude_version"`
ConfigRevision string `json:"config_revision,omitempty"`
Turns int `json:"turns"`
UpdatedAt time.Time `json:"updated_at"`
}
SessionState is <runner>/claude/session.json.
type StreamParser ¶
type StreamParser struct {
SessionID string
Init *Init
Result *Result
// AssistantMessages counts assistant lines, i.e. model output was produced.
AssistantMessages int
// LastText is the most recent assistant text block.
LastText string
}
StreamParser converts claude --output-format stream-json lines into events.
func (*StreamParser) Parse ¶
func (p *StreamParser) Parse(raw []byte) []ParsedEvent
Parse consumes one line and returns the events it produces. Unknown or malformed lines produce no events (malformed ones a progress note).
func (*StreamParser) ResumeFailed ¶
func (p *StreamParser) ResumeFailed() bool
ResumeFailed reports whether a result shows that --resume could not find or load the session.