Documentation
¶
Overview ¶
Package rocketcode provides the reusable RocketCode runtime.
Index ¶
- Constants
- func BashPermissionSubjects(command string) []string
- func CompactAnthropicReplay(ctx context.Context, client *anthropic.Client, model string, ...) (*responses.Response, error)
- func LoadWorkspaceDefinitions(root *os.Root) (Agents, Skills, func(), error)
- func ReplayInputFromParams(items []responses.ResponseInputItemUnionParam) ([]json.RawMessage, error)
- func ReplayInputToParams(raw []json.RawMessage) ([]responses.ResponseInputItemUnionParam, error)
- func SplitPromptAttachmentTokens(text string) (prompt string, files []string, err error)
- type Agent
- type AgentLoadResult
- type AgentMaxRecursionError
- type Agents
- type Attachment
- type BashCommand
- type BashResult
- type ChatResponse
- type Config
- type Looper
- type ObservabilityConfig
- type OpenAICompatibleMode
- type OpenAICompatibleProvider
- type Operation
- type OperationError
- type PermissionAction
- type PermissionBucket
- type PermissionRule
- type PermissionSet
- func (ps *PermissionSet) Allow(permission, pattern string) error
- func (ps *PermissionSet) Deny(permission, pattern string) error
- func (ps PermissionSet) Evaluate(permission, subject string) (action PermissionAction, matched bool)
- func (ps *PermissionSet) Set(permission, pattern string, action PermissionAction) error
- type PromptInput
- type PromptInputRole
- type PromptShellCommandExpansion
- type ProviderDiagnostic
- type Providers
- type ReplayDecodeError
- type Runtime
- type SessionEntry
- type Skill
- type SkillLoadResult
- type Skills
- type SubagentDiagnostic
- type TokenUsage
- type Tool
- type ToolDiagnostic
- type ToolResult
Constants ¶
const ( // ChatResponseAssistantMessage identifies final assistant message output. ChatResponseAssistantMessage = "assistant_message" // ChatResponseAssistantCommentary identifies assistant progress/commentary output. ChatResponseAssistantCommentary = "assistant_commentary" // ChatResponseAssistantTool identifies structured tool and subagent diagnostics. ChatResponseAssistantTool = "assistant_tool" // ChatResponseReasoningSummary identifies reasoning summary output. ChatResponseReasoningSummary = "reasoning_summary" )
Variables ¶
This section is empty.
Functions ¶
func BashPermissionSubjects ¶ added in v0.0.7
BashPermissionSubjects returns the subjects checked by the bash tool for command.
func CompactAnthropicReplay ¶ added in v0.0.14
func CompactAnthropicReplay(ctx context.Context, client *anthropic.Client, model string, input []responses.ResponseInputItemUnionParam, threshold int64) (*responses.Response, error)
CompactAnthropicReplay compacts Responses-shaped replay through Anthropic Messages beta compaction.
func LoadWorkspaceDefinitions ¶ added in v0.0.7
LoadWorkspaceDefinitions loads top-level workspace agents and recursive skills.
func ReplayInputFromParams ¶
func ReplayInputFromParams(items []responses.ResponseInputItemUnionParam) ([]json.RawMessage, error)
ReplayInputFromParams returns SDK-native durable replay JSON after each item round-trips through responses.ResponseInputItemUnionParam.
func ReplayInputToParams ¶
func ReplayInputToParams(raw []json.RawMessage) ([]responses.ResponseInputItemUnionParam, error)
ReplayInputToParams decodes SDK-native durable replay JSON through the OpenAI SDK input union.
Types ¶
type Agent ¶
type Agent struct {
Name string
Description string
Model string
ReasoningEffort string
Verbosity string
MaxRecursion *int
Guardrail string
Prompt string
Location string
Permission PermissionSet
Frontmatter map[string]any
FileMode fs.FileMode
}
Agent contains a single preloaded markdown agent definition.
type AgentLoadResult ¶
AgentLoadResult contains loaded agents and any non-fatal load errors.
func LoadAgents ¶
func LoadAgents(fsys fs.FS) AgentLoadResult
LoadAgents scans the top level of fsys for markdown agent files.
type AgentMaxRecursionError ¶ added in v0.0.7
AgentMaxRecursionError reports invalid maxRecursion frontmatter.
func (*AgentMaxRecursionError) Error ¶ added in v0.0.7
func (e *AgentMaxRecursionError) Error() string
func (*AgentMaxRecursionError) Unwrap ¶ added in v0.0.7
func (e *AgentMaxRecursionError) Unwrap() error
type Attachment ¶
type Attachment struct {
MIME string `json:"mime"`
Filename string `json:"filename,omitempty"`
URL string `json:"url"`
}
Attachment is a model-visible file attachment encoded as a URL, usually a data URL.
func PromptAttachments ¶ added in v0.0.7
PromptAttachments loads prompt attachments from workspace-local files.
type BashCommand ¶ added in v0.0.7
BashCommand is the public shape of the workspace bash tool input.
type BashResult ¶ added in v0.0.7
BashResult is the result of running a workspace bash command.
type ChatResponse ¶
type ChatResponse struct {
Kind string
Text string
Tool *ToolDiagnostic
Subagent *SubagentDiagnostic
Provider *ProviderDiagnostic
}
ChatResponse is one user-visible response item emitted by the runtime.
type Config ¶
type Config struct {
Model shared.ResponsesModel
ReasoningEffort shared.ReasoningEffort
Diagnostics bool
ExperimentalStrongerSkills bool
ExpandPromptShellCommands PromptShellCommandExpansion
CompactThreshold int64
CompactionSteering string
ParallelToolCalls int
ShellOutputDir string
SandboxedBash bool
AutoApprovePermissions bool
Observability ObservabilityConfig
CustomTools []Tool
ShellEnv map[string]string
}
Config contains runtime settings supplied by the embedding application.
func StandaloneConfigFromEnv ¶ added in v0.0.7
StandaloneConfigFromEnv returns the shared default config for RocketCode commands.
type Looper ¶
type Looper interface {
Loop(ctx context.Context, input <-chan PromptInput, sessionIn iter.Seq2[SessionEntry, error], sessionOut func(SessionEntry) error, interrupts <-chan os.Signal) error
}
Looper processes prompt input streams with a configured runtime.
type ObservabilityConfig ¶ added in v0.0.12
type ObservabilityConfig struct {
Enabled bool
Tracer trace.Tracer
TraceConfig instrumentation.TraceConfig
}
ObservabilityConfig controls OpenInference-compatible tracing for RocketCode.
type OpenAICompatibleMode ¶ added in v0.0.14
type OpenAICompatibleMode string
OpenAICompatibleMode selects which OpenAI-compatible API surface a provider supports.
const ( // OpenAICompatibleModeResponses routes through the OpenAI-compatible responses API. OpenAICompatibleModeResponses OpenAICompatibleMode = "responses" // OpenAICompatibleModeChatCompletions routes through the OpenAI-compatible chat completions API. OpenAICompatibleModeChatCompletions OpenAICompatibleMode = "chat_completions" )
type OpenAICompatibleProvider ¶ added in v0.0.14
type OpenAICompatibleProvider struct {
Client openai.Client
Mode OpenAICompatibleMode
}
OpenAICompatibleProvider contains one named OpenAI-compatible provider client.
type Operation ¶ added in v0.0.7
type Operation string
Operation identifies a high-level command/runtime operation.
const ( // OperationLoadConfig identifies standalone config loading. OperationLoadConfig Operation = "load config" // OperationLoadWorkspaceDefinitions identifies workspace-local agent/skill loading. OperationLoadWorkspaceDefinitions Operation = "load workspace definitions" // OperationParsePromptAttachments identifies prompt attachment token parsing. OperationParsePromptAttachments Operation = "parse prompt attachments" // OperationLoadPromptAttachments identifies workspace prompt attachment loading. OperationLoadPromptAttachments Operation = "load prompt attachments" )
type OperationError ¶ added in v0.0.7
OperationError adds typed operation context while preserving the wrapped error.
func (OperationError) Error ¶ added in v0.0.7
func (e OperationError) Error() string
func (OperationError) Unwrap ¶ added in v0.0.7
func (e OperationError) Unwrap() error
type PermissionAction ¶
type PermissionAction string
PermissionAction determines whether a matched operation is allowed or denied.
const ( // PermissionAllow allows a matching operation. PermissionAllow PermissionAction = "allow" // PermissionDeny denies a matching operation. PermissionDeny PermissionAction = "deny" // PermissionAuto requires automatic reviewer approval for a matching operation. PermissionAuto PermissionAction = "auto" )
type PermissionBucket ¶
type PermissionBucket struct {
Name string
Rules []PermissionRule
}
PermissionBucket groups permission rules under a named permission category.
type PermissionRule ¶
type PermissionRule struct {
Pattern string
Action PermissionAction
Reviewer string
}
PermissionRule matches a subject pattern to a permission action.
type PermissionSet ¶
type PermissionSet struct {
Buckets []PermissionBucket
}
PermissionSet contains all permission buckets configured for an agent.
func (*PermissionSet) Allow ¶
func (ps *PermissionSet) Allow(permission, pattern string) error
Allow appends an allow rule for permission and pattern.
func (*PermissionSet) Deny ¶
func (ps *PermissionSet) Deny(permission, pattern string) error
Deny appends a deny rule for permission and pattern.
func (PermissionSet) Evaluate ¶
func (ps PermissionSet) Evaluate(permission, subject string) (action PermissionAction, matched bool)
Evaluate returns the effective permission action for permission and subject. The matched result reports whether a configured rule explicitly matched. When matched is false, action is PermissionDeny, the default action.
func (*PermissionSet) Set ¶
func (ps *PermissionSet) Set(permission, pattern string, action PermissionAction) error
Set appends a permission rule for permission and pattern.
type PromptInput ¶
type PromptInput struct {
// Role defaults to PromptInputRoleUser when empty.
Role PromptInputRole `json:"role,omitempty"`
Text string `json:"text"`
Attachments []Attachment `json:"attachments,omitempty"`
// Responses receives user-visible response items for this prompt. The runtime
// closes it after the prompt's turn reaches a terminal state.
Responses chan<- ChatResponse `json:"-"`
}
PromptInput is one prompt plus optional model-visible attachments.
type PromptInputRole ¶
type PromptInputRole string
PromptInputRole identifies the instruction hierarchy role for a prompt input.
const ( // PromptInputRoleUser identifies ordinary user prompt input. PromptInputRoleUser PromptInputRole = "user" // PromptInputRoleDeveloper identifies developer instruction prompt input. PromptInputRoleDeveloper PromptInputRole = "developer" )
type PromptShellCommandExpansion ¶
type PromptShellCommandExpansion struct {
PrimaryPrompts bool
SubagentPrompts bool
SkillPrompts bool
InputPrompts bool
}
PromptShellCommandExpansion controls which prompt sources expand !`command` snippets.
type ProviderDiagnostic ¶
type ProviderDiagnostic struct {
Phase string `json:"phase"`
HTTPStatus int `json:"http_status,omitempty"`
ResponseStatus string `json:"response_status,omitempty"`
Code string `json:"code,omitempty"`
Type string `json:"type,omitempty"`
Message string `json:"message,omitempty"`
Attempt int `json:"attempt,omitempty"`
RetryAfter string `json:"retry_after,omitempty"`
ResponseID string `json:"response_id,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
ProviderDiagnostic describes provider request diagnostics emitted when diagnostics are enabled.
type Providers ¶ added in v0.0.7
type Providers struct {
OpenAI *openai.Client
Anthropic *anthropic.Client
OpenAICompatible map[string]OpenAICompatibleProvider
}
Providers contains model provider clients supplied by embedding applications.
func StandaloneProvidersFromEnv ¶ added in v0.0.7
StandaloneProvidersFromEnv returns model provider clients for RocketCode commands.
type ReplayDecodeError ¶
ReplayDecodeError describes one durable replay item that could not be decoded through the OpenAI SDK input union.
func (*ReplayDecodeError) Error ¶
func (e *ReplayDecodeError) Error() string
func (*ReplayDecodeError) Unwrap ¶
func (e *ReplayDecodeError) Unwrap() error
type Runtime ¶ added in v0.0.7
type Runtime = looper
Runtime is the concrete RocketCode loop runtime returned by New.
func New ¶
func New( client *openai.Client, configInput *Config, root *os.Root, agents Agents, skills Skills, defaultAgent string, diagnosticsWriter io.Writer, ) (*Runtime, error)
New loads the supplied runtime dependencies and returns a configured looper.
func NewWithProviders ¶ added in v0.0.7
func NewWithProviders( providers Providers, configInput *Config, root *os.Root, agents Agents, skills Skills, defaultAgent string, diagnosticsWriter io.Writer, ) (*Runtime, error)
NewWithProviders loads the supplied runtime dependencies and returns a configured looper.
type SessionEntry ¶
type SessionEntry struct {
Version int `json:"version"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
ResponseID string `json:"response_id,omitempty"`
Model string `json:"model,omitempty"`
TokenUsage *TokenUsage `json:"token_usage,omitempty"`
ReplayInput []json.RawMessage `json:"replay_input,omitempty"`
OutputTrace []json.RawMessage `json:"output_trace,omitempty"`
}
SessionEntry is one denormalized persisted session record.
type Skill ¶
type Skill struct {
Name string
Description string
License string
Compatibility string
Metadata map[string]any
Location string
Content string
}
Skill contains a single preloaded skill definition.
type SkillLoadResult ¶
SkillLoadResult contains loaded skills and any non-fatal load errors.
func LoadSkills ¶
func LoadSkills(fsys fs.FS, root string) SkillLoadResult
LoadSkills scans fsys for SKILL.md files and preloads valid skills.
type Skills ¶
type Skills struct {
Root string
Items map[string]Skill
Dirs []string
// contains filtered or unexported fields
}
Skills contains all discovered skills keyed by name.
type SubagentDiagnostic ¶
type SubagentDiagnostic struct {
Name string `json:"name"`
Label string `json:"label"`
Index int `json:"index,omitempty"`
Total int `json:"total,omitempty"`
Text string `json:"text,omitempty"`
Tool *ToolDiagnostic `json:"tool,omitempty"`
Subagent *SubagentDiagnostic `json:"subagent,omitempty"`
Provider *ProviderDiagnostic `json:"provider,omitempty"`
}
SubagentDiagnostic describes a subagent runtime diagnostic emitted when diagnostics are enabled.
type TokenUsage ¶ added in v0.0.13
type TokenUsage struct {
PromptTokens int64 `json:"prompt_tokens,omitempty"`
CompletionTokens int64 `json:"completion_tokens,omitempty"`
TotalTokens int64 `json:"total_tokens,omitempty"`
PromptCacheReadTokens int64 `json:"prompt_cache_read_tokens,omitempty"`
PromptCacheWriteTokens int64 `json:"prompt_cache_write_tokens,omitempty"`
CompletionReasoningTokens int64 `json:"completion_reasoning_tokens,omitempty"`
}
TokenUsage records replay-neutral provider token counts for a completed turn.
type Tool ¶
type Tool struct {
Name string
Description string
Parameters map[string]any
Permission string
VisibilitySubjects []string
Subjects func(json.RawMessage) ([]string, error)
Call func(context.Context, json.RawMessage, chan<- ChatResponse) (ToolResult, error)
}
Tool is a custom function tool supplied by an embedding application.
type ToolDiagnostic ¶
type ToolDiagnostic struct {
Phase string `json:"phase"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments,omitempty"`
Result string `json:"result,omitempty"`
Status string `json:"status,omitempty"`
Action json.RawMessage `json:"action,omitempty"`
}
ToolDiagnostic describes a tool runtime diagnostic emitted when diagnostics are enabled.
type ToolResult ¶
type ToolResult struct {
Output string
Attachments []Attachment
}
ToolResult is the output of a tool call, including optional model-visible attachments.
func TextToolResult ¶
func TextToolResult(output string) ToolResult
TextToolResult returns a text-only tool result.