Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureDefaultSkills() error
- func FormatSkillsSummary(skills []Skill) string
- func GenerateUnifiedDiff(oldContent, newContent, filePath string) string
- func ReadSkillContent(appRoot, skillName string) (string, error)
- func ReadSkillSection(appRoot, skillName, query string) (string, error)
- func SaveSession(appRoot string, session *Session) error
- type AIClient
- type Agent
- type AgentCallbacks
- type AgentState
- type ClarificationQuestion
- type ContentBlock
- type Message
- type MessageResponse
- type NimbusCloudClient
- func (c *NimbusCloudClient) Chat(ctx context.Context, prompt, model string, projCtx *ProjectContext) (string, error)
- func (c *NimbusCloudClient) GeneratePlan(ctx context.Context, prompt string, projCtx *ProjectContext, model string) (*PlanSummary, error)
- func (c *NimbusCloudClient) RegenerateStep(ctx context.Context, stepIndex int, newDesc string, currentPlan *PlanSummary, ...) (*PlanSummary, error)
- func (c *NimbusCloudClient) StreamExecute(ctx context.Context, prompt string, plan *PlanSummary, messages []Message, ...) (*MessageResponse, error)
- func (c *NimbusCloudClient) Turn(ctx context.Context, tr *TurnRequest, onDelta StreamHandler) (*MessageResponse, error)
- type PlanPhase
- type PlanStep
- type PlanSummary
- type ProjectContext
- type Session
- type Skill
- type StreamHandler
- type ToolDefinition
- type ToolExecutor
- func (t *ToolExecutor) Bash(ctx context.Context, commandStr string) (string, error)
- func (t *ToolExecutor) DeleteFile(relPath string) (string, string, error)
- func (t *ToolExecutor) EditFile(relPath, target, replacement string) (string, string, error)
- func (t *ToolExecutor) EditFileAll(relPath, target, replacement string, replaceAll bool) (string, string, error)
- func (t *ToolExecutor) ExecuteTool(ctx context.Context, name string, args map[string]any) (output string, diff string, err error)
- func (t *ToolExecutor) FindFiles(pattern, relPath string) (string, error)
- func (t *ToolExecutor) GetToolDefinitions() []ToolDefinition
- func (t *ToolExecutor) Grep(pattern, relPath string) (string, error)
- func (t *ToolExecutor) GrepFiltered(pattern, relPath, include string) (string, error)
- func (t *ToolExecutor) ListDir(relPath string) (string, error)
- func (t *ToolExecutor) ListDirDepth(relPath string, depth int) (string, error)
- func (t *ToolExecutor) LoadSkill(skillName string) (string, error)
- func (t *ToolExecutor) QuerySkill(skillName, query string) (string, error)
- func (t *ToolExecutor) ReadFile(relPath string) (string, error)
- func (t *ToolExecutor) ReadFileRange(relPath string, startLine, endLine int) (string, error)
- func (t *ToolExecutor) ReadOnlyToolDefinitions() []ToolDefinition
- func (t *ToolExecutor) ReadSkill(name string) (string, error)
- func (t *ToolExecutor) RunCommand(ctx context.Context, commandStr string) (string, bool)
- func (t *ToolExecutor) WriteFile(relPath, newContent string) (string, string, error)
- type TurnMode
- type TurnRecord
- type TurnRequest
Constants ¶
const ExecuteSystemPrompt = `` /* 266-byte string literal not displayed */
ExecuteSystemPrompt documents execution rules (authoritative copy on Nimbus Cloud).
const PlanSystemPrompt = `` /* 569-byte string literal not displayed */
PlanSystemPrompt documents the plan JSON contract the CLI expects. The authoritative prompts live on Nimbus Cloud; this is kept for reference and offline tooling.
Variables ¶
var ErrTurnUnsupported = errors.New("nimbus cloud server does not support agent turns (upgrade the server)")
ErrTurnUnsupported is returned when the cloud server predates the agent turn endpoint; callers fall back to the legacy plan/execute endpoints.
Functions ¶
func EnsureDefaultSkills ¶
func EnsureDefaultSkills() error
EnsureDefaultSkills writes embedded default skills to ~/.nimbus/skills/ if not already present.
func FormatSkillsSummary ¶
FormatSkillsSummary formats the lightweight skill index as a bullet list for the system prompt.
func GenerateUnifiedDiff ¶
GenerateUnifiedDiff builds a simple unified line diff.
func ReadSkillContent ¶
ReadSkillContent reads the full SKILL.md body for a given skill on demand.
func ReadSkillSection ¶ added in v1.5.4
ReadSkillSection reads only the relevant sections matching a query from a skill document.
func SaveSession ¶
SaveSession persists the session JSON under .nimbus/ai-sessions/<id>.json.
Types ¶
type AIClient ¶
type AIClient interface {
Chat(ctx context.Context, prompt, model string, projCtx *ProjectContext) (string, error)
GeneratePlan(ctx context.Context, prompt string, projCtx *ProjectContext, model string) (*PlanSummary, error)
RegenerateStep(ctx context.Context, stepIndex int, newDesc string, currentPlan *PlanSummary, projCtx *ProjectContext, model string) (*PlanSummary, error)
StreamExecute(ctx context.Context, prompt string, plan *PlanSummary, messages []Message, tools []ToolDefinition, projCtx *ProjectContext, onDelta StreamHandler) (*MessageResponse, error)
// Turn runs a single agentic model turn. Implementations that cannot
// support it must return ErrTurnUnsupported.
Turn(ctx context.Context, req *TurnRequest, onDelta StreamHandler) (*MessageResponse, error)
}
AIClient is the interface for communicating with Nimbus Cloud AI backend.
func ResolveClient ¶
ResolveClient returns the appropriate AIClient. All intelligence is routed through nimbusgo.space.
type Agent ¶
type Agent struct {
Client AIClient
Tools *ToolExecutor
Context *ProjectContext
Session *Session
Model string
State AgentState
Callbacks AgentCallbacks
// Verifier runs the project's build/tests after execution and returns
// (output, ok). Defaults to a Go build when go.mod is present; tests
// override it. Nil disables verification.
Verifier func(ctx context.Context) (string, bool)
// contains filtered or unexported fields
}
Agent manages the explore → plan → execute → verify flow.
func NewAgent ¶
func NewAgent(client AIClient, tools *ToolExecutor, projCtx *ProjectContext, session *Session) *Agent
NewAgent creates a new Nimbus AI Agent.
func (*Agent) ExecuteApprovedPlan ¶
ExecuteApprovedPlan executes the approved steps using tools, then verifies the result (build) and lets the model repair failures.
func (*Agent) GeneratePlan ¶
GeneratePlan investigates the codebase for the request, then produces a structured plan grounded in what it found. Conversational requests come back as a plan with zero steps whose Summary holds the answer.
func (*Agent) RegenerateStep ¶
func (a *Agent) RegenerateStep(ctx context.Context, stepIndex int, newDescription string) (*PlanSummary, error)
RegenerateStep regenerates a modified step and any downstream steps.
type AgentCallbacks ¶
type AgentCallbacks struct {
OnRequestSent func()
OnStreamDelta func(delta string)
OnStatus func(text string)
OnPlanGenerated func(plan *PlanSummary)
OnStepUpdate func(step *PlanStep)
OnDiffGenerated func(filePath, diff string)
OnToolCall func(toolName string, args map[string]any)
OnToolResult func(toolName string, args map[string]any, output string, err error)
OnExecutionCompleted func(summary string)
}
AgentCallbacks defines hooks for the TUI to render real-time progress.
type AgentState ¶
type AgentState string
AgentState represents the state of the agent.
const ( StateIdle AgentState = "idle" StateExploring AgentState = "exploring" StatePlanning AgentState = "planning" StateReviewing AgentState = "reviewing" StateExecuting AgentState = "executing" StateVerifying AgentState = "verifying" StateCompleted AgentState = "completed" StateFailed AgentState = "failed" )
type ClarificationQuestion ¶
type ClarificationQuestion struct {
ID string `json:"id"`
Question string `json:"question"`
Options []string `json:"options,omitempty"`
Default string `json:"default,omitempty"`
Selected string `json:"selected,omitempty"`
}
ClarificationQuestion represents an interactive decision required from the user.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // "text" | "tool_use" | "tool_result"
Text string `json:"text,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input map[string]any `json:"input,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
Content string `json:"content,omitempty"`
IsError bool `json:"is_error,omitempty"`
}
ContentBlock represents a text or tool block.
type Message ¶
type Message struct {
Role string `json:"role"` // "user" | "assistant" | "system"
Content any `json:"content"` // string or []ContentBlock
}
Message represents a chat message.
type MessageResponse ¶
type MessageResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Role string `json:"role"`
Content []ContentBlock `json:"content"`
StopReason string `json:"stop_reason"`
}
MessageResponse holds the response from the Nimbus Cloud AI.
func (*MessageResponse) TextContent ¶
func (m *MessageResponse) TextContent() string
func (*MessageResponse) ToolUseBlocks ¶
func (m *MessageResponse) ToolUseBlocks() []ContentBlock
type NimbusCloudClient ¶
NimbusCloudClient connects the CLI to the intelligence engine hosted at nimbusgo.space.
func NewNimbusCloudClient ¶
func NewNimbusCloudClient(serverURL string) (*NimbusCloudClient, error)
NewNimbusCloudClient initializes client using local authentication credentials.
func (*NimbusCloudClient) Chat ¶
func (c *NimbusCloudClient) Chat(ctx context.Context, prompt, model string, projCtx *ProjectContext) (string, error)
Chat sends a conversational query or question to Nimbus Cloud AI with project context.
func (*NimbusCloudClient) GeneratePlan ¶
func (c *NimbusCloudClient) GeneratePlan(ctx context.Context, prompt string, projCtx *ProjectContext, model string) (*PlanSummary, error)
GeneratePlan calls POST /api/v1/ai/plan on Nimbus Cloud.
func (*NimbusCloudClient) RegenerateStep ¶
func (c *NimbusCloudClient) RegenerateStep(ctx context.Context, stepIndex int, newDesc string, currentPlan *PlanSummary, projCtx *ProjectContext, model string) (*PlanSummary, error)
RegenerateStep calls POST /api/v1/ai/plan/regenerate on Nimbus Cloud.
func (*NimbusCloudClient) StreamExecute ¶
func (c *NimbusCloudClient) StreamExecute(ctx context.Context, prompt string, plan *PlanSummary, messages []Message, tools []ToolDefinition, projCtx *ProjectContext, onDelta StreamHandler) (*MessageResponse, error)
StreamExecute streams step execution and tool guidance from Nimbus Cloud.
func (*NimbusCloudClient) Turn ¶ added in v1.5.4
func (c *NimbusCloudClient) Turn(ctx context.Context, tr *TurnRequest, onDelta StreamHandler) (*MessageResponse, error)
Turn calls POST /api/v1/ai/turn: one agentic model turn with native tools.
type PlanPhase ¶
type PlanPhase struct {
Name string `json:"name"` // e.g. "Phase 1: Frontend User Interface"
Description string `json:"description"` // e.g. "Implement responsive Todo app view"
Files []string `json:"files"` // e.g. ["resources/views/todo.html"]
}
PlanPhase groups architectural steps into logical stages.
type PlanStep ¶
type PlanStep struct {
ID int `json:"id"`
Phase string `json:"phase,omitempty"` // e.g. "Phase 1: Frontend UI"
Action string `json:"action"` // "create_file" | "edit_file" | "run_command" | "delete_file" | "clarification_needed"
Target string `json:"target"`
Description string `json:"description"`
Content string `json:"content,omitempty"`
Risk string `json:"risk"` // "low" | "medium" | "high"
Approved bool `json:"approved"`
Status string `json:"status,omitempty"` // "pending" | "running" | "applied" | "failed"
Error string `json:"error,omitempty"`
}
PlanStep represents a single reviewable step in the execution plan.
type PlanSummary ¶
type PlanSummary struct {
Summary string `json:"summary"`
Overview string `json:"overview,omitempty"`
NeedsClarification bool `json:"needs_clarification,omitempty"`
Questions []ClarificationQuestion `json:"questions,omitempty"`
Phases []PlanPhase `json:"phases,omitempty"`
Steps []PlanStep `json:"steps"`
Details []string `json:"details,omitempty"`
}
PlanSummary represents the structured plan generated in Plan Mode.
type ProjectContext ¶
type ProjectContext struct {
AppRoot string `json:"app_root"`
ProjectName string `json:"project_name"`
GoModName string `json:"go_mod_name,omitempty"`
GoVersion string `json:"go_version,omitempty"`
NimbusModules []string `json:"nimbus_modules,omitempty"`
NimbusJSON string `json:"nimbus_json,omitempty"`
DirectoryTree string `json:"directory_tree"`
GitBranch string `json:"git_branch,omitempty"`
GitDiffSummary string `json:"git_diff_summary,omitempty"`
RootFiles []string `json:"root_files,omitempty"`
Models []string `json:"models,omitempty"`
Controllers []string `json:"controllers,omitempty"`
Migrations []string `json:"migrations,omitempty"`
RoutesSummary string `json:"routes_summary,omitempty"`
Skills []Skill `json:"skills,omitempty"`
// ActiveSkillFrame holds the most recently loaded skill so the server can
// keep it in the system prompt rather than the message history.
ActiveSkillFrame string `json:"active_skill_frame,omitempty"`
// Instructions holds project-level guidance for the agent, read from
// AGENTS.md / NIMBUS.md / CLAUDE.md / .nimbus/instructions.md. It is the
// project's persistent memory: conventions, do's and don'ts, commands.
Instructions string `json:"instructions,omitempty"`
// InstructionFiles lists which instruction files were found.
InstructionFiles []string `json:"instruction_files,omitempty"`
// Stack summarises non-Go tooling detected (package.json, Vite, Tailwind…).
Stack []string `json:"stack,omitempty"`
// OS is the host operating system, so shell commands can be phrased correctly.
OS string `json:"os,omitempty"`
}
ProjectContext contains scanned information about the current Nimbus project.
func ScanProject ¶
func ScanProject(appRoot string) (*ProjectContext, error)
ScanProject scans the given project directory and constructs a ProjectContext.
func (*ProjectContext) FormatSystemContext ¶
func (p *ProjectContext) FormatSystemContext() string
FormatSystemContext formats the ProjectContext into a rich markdown block for AI system prompts.
func (*ProjectContext) Refresh ¶ added in v1.5.4
func (p *ProjectContext) Refresh()
Refresh re-reads the cheap, fast-changing parts of the context (git state, directory tree, instructions) so later phases see files created earlier.
type Session ¶
type Session struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
InitialQuery string `json:"initial_query"`
Model string `json:"model"`
Plan *PlanSummary `json:"plan,omitempty"`
ApprovedPlan *PlanSummary `json:"approved_plan,omitempty"`
History []Message `json:"history"`
AppliedSteps []int `json:"applied_steps"`
LoadedSkills map[string]string `json:"loaded_skills,omitempty"`
Status string `json:"status"` // "planning" | "reviewing" | "executing" | "completed"
// Findings is the exploration report produced for the current request.
Findings string `json:"findings,omitempty"`
// Turns is the conversation memory: one record per completed request,
// carried into later prompts so follow-ups build on earlier work.
Turns []TurnRecord `json:"turns,omitempty"`
}
Session represents an AI session stored on disk.
func ListSessions ¶
ListSessions returns a list of recent sessions sorted newest first.
func LoadSession ¶
LoadSession reads an existing session from disk.
func NewSession ¶
NewSession creates an empty initialized Session.
func (*Session) ConversationSummary ¶ added in v1.5.4
ConversationSummary renders recent turns for inclusion in prompts, so the model knows what was asked and done earlier in this session.
func (*Session) RecordTurn ¶ added in v1.5.4
RecordTurn appends a conversation-memory entry for a finished request.
type Skill ¶
type Skill struct {
Name string `json:"name"`
Description string `json:"description"`
Path string `json:"path"`
Source string `json:"source"` // "project" | "global" | "embedded"
}
Skill represents a lightweight index entry for an agent skill.
func LoadSkills ¶
LoadSkills discovers and builds a lightweight index of skills (name + description only).
type StreamHandler ¶
type StreamHandler func(delta string)
StreamHandler receives streaming delta chunks.
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"input_schema"`
}
ToolDefinition describes a tool schema exposed to the AI agent.
type ToolExecutor ¶
type ToolExecutor struct {
AppRoot string
// CommandTimeout bounds a single bash invocation.
CommandTimeout time.Duration
}
ToolExecutor executes agent tool requests.
func NewToolExecutor ¶
func NewToolExecutor(appRoot string) *ToolExecutor
NewToolExecutor creates a tool executor sandboxed to appRoot.
func (*ToolExecutor) Bash ¶
Bash runs a shell command and returns its combined output. A failing command is not an error at the tool level: the failure text is returned so the model can read and act on it.
func (*ToolExecutor) DeleteFile ¶
func (t *ToolExecutor) DeleteFile(relPath string) (string, string, error)
func (*ToolExecutor) EditFile ¶
func (t *ToolExecutor) EditFile(relPath, target, replacement string) (string, string, error)
EditFile replaces a unique target substring.
func (*ToolExecutor) EditFileAll ¶ added in v1.5.4
func (t *ToolExecutor) EditFileAll(relPath, target, replacement string, replaceAll bool) (string, string, error)
EditFileAll replaces the target substring; with replaceAll every occurrence is replaced, otherwise the target must be unique.
func (*ToolExecutor) ExecuteTool ¶
func (t *ToolExecutor) ExecuteTool(ctx context.Context, name string, args map[string]any) (output string, diff string, err error)
ExecuteTool runs the requested tool and returns output string and optional diff string.
func (*ToolExecutor) FindFiles ¶ added in v1.5.4
func (t *ToolExecutor) FindFiles(pattern, relPath string) (string, error)
FindFiles returns workspace-relative paths matching a glob pattern.
func (*ToolExecutor) GetToolDefinitions ¶
func (t *ToolExecutor) GetToolDefinitions() []ToolDefinition
GetToolDefinitions returns the canonical tool schemas for the AI agent.
func (*ToolExecutor) Grep ¶
func (t *ToolExecutor) Grep(pattern, relPath string) (string, error)
Grep searches file contents with a regex (no include filter).
func (*ToolExecutor) GrepFiltered ¶ added in v1.5.4
func (t *ToolExecutor) GrepFiltered(pattern, relPath, include string) (string, error)
GrepFiltered searches file contents, optionally restricted to files whose name matches the include glob.
func (*ToolExecutor) ListDir ¶
func (t *ToolExecutor) ListDir(relPath string) (string, error)
ListDir lists a single directory level.
func (*ToolExecutor) ListDirDepth ¶ added in v1.5.4
func (t *ToolExecutor) ListDirDepth(relPath string, depth int) (string, error)
ListDirDepth lists a directory up to depth levels deep (1-3).
func (*ToolExecutor) LoadSkill ¶
func (t *ToolExecutor) LoadSkill(skillName string) (string, error)
LoadSkill loads the full content and documentation of a skill by name on demand.
func (*ToolExecutor) QuerySkill ¶ added in v1.5.4
func (t *ToolExecutor) QuerySkill(skillName, query string) (string, error)
QuerySkill reads specific sections or topics from a skill to keep context lightweight.
func (*ToolExecutor) ReadFile ¶
func (t *ToolExecutor) ReadFile(relPath string) (string, error)
ReadFile reads a whole file (subject to size limits).
func (*ToolExecutor) ReadFileRange ¶ added in v1.5.4
func (t *ToolExecutor) ReadFileRange(relPath string, startLine, endLine int) (string, error)
ReadFileRange reads a file, optionally restricted to a 1-based inclusive line range. Oversized reads are truncated with a hint to use ranges.
func (*ToolExecutor) ReadOnlyToolDefinitions ¶ added in v1.5.4
func (t *ToolExecutor) ReadOnlyToolDefinitions() []ToolDefinition
ReadOnlyToolDefinitions returns the tools that inspect the workspace without changing files. Used for the exploration and planning phases.
func (*ToolExecutor) ReadSkill ¶
func (t *ToolExecutor) ReadSkill(name string) (string, error)
ReadSkill is an alias for LoadSkill.
func (*ToolExecutor) RunCommand ¶ added in v1.5.4
RunCommand runs a command and reports whether it exited successfully.
type TurnMode ¶ added in v1.5.4
type TurnMode string
TurnMode selects the server-side system prompt for an agent turn.
type TurnRecord ¶ added in v1.5.4
type TurnRecord struct {
At time.Time `json:"at"`
Prompt string `json:"prompt"`
PlanSummary string `json:"plan_summary,omitempty"`
Outcome string `json:"outcome,omitempty"`
FilesChanged []string `json:"files_changed,omitempty"`
}
TurnRecord summarises one completed request/response cycle.
type TurnRequest ¶ added in v1.5.4
type TurnRequest struct {
Mode TurnMode
Model string
Prompt string // the user's original request
Messages []Message
Tools []ToolDefinition
Plan *PlanSummary
Context *ProjectContext
}
TurnRequest is one model turn of the agent loop: the server composes the system prompt for Mode from the project context and returns text and/or tool calls; the CLI executes tools locally and calls again.