ai

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const ExecuteSystemPrompt = `` /* 875-byte string literal not displayed */

ExecuteSystemPrompt defines rules and tool constraints during Execute Mode.

View Source
const PlanSystemPrompt = `` /* 1892-byte string literal not displayed */

PlanSystemPrompt defines strict JSON output rules for Plan Mode.

Variables

This section is empty.

Functions

func EnsureDefaultSkills

func EnsureDefaultSkills() error

EnsureDefaultSkills writes embedded default skills to ~/.nimbus/skills/ if not already present.

func FormatSkillsSummary

func FormatSkillsSummary(skills []Skill) string

FormatSkillsSummary formats the lightweight skill index as a bullet list for the system prompt.

func GenerateUnifiedDiff

func GenerateUnifiedDiff(oldContent, newContent, filePath string) string

GenerateUnifiedDiff builds a simple unified line diff.

func ReadSkillContent

func ReadSkillContent(appRoot, skillName string) (string, error)

ReadSkillContent reads the full SKILL.md body for a given skill on demand.

func SaveSession

func SaveSession(appRoot string, session *Session) error

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)
}

AIClient is the interface for communicating with Nimbus Cloud AI backend.

func ResolveClient

func ResolveClient(serverURL, model string) (AIClient, error)

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
}

Agent manages the two-phase planning and execution flow.

func NewAgent

func NewAgent(client AIClient, tools *ToolExecutor, projCtx *ProjectContext, session *Session) *Agent

NewAgent creates a new Nimbus AI Agent.

func (*Agent) ExecuteApprovedPlan

func (a *Agent) ExecuteApprovedPlan(ctx context.Context, plan *PlanSummary) (string, error)

ExecuteApprovedPlan executes the approved steps using tools.

func (*Agent) GeneratePlan

func (a *Agent) GeneratePlan(ctx context.Context, userPrompt string) (*PlanSummary, error)

GeneratePlan generates a structured plan for the user prompt.

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)
	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"
	StatePlanning  AgentState = "planning"
	StateReviewing AgentState = "reviewing"
	StateExecuting AgentState = "executing"
	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

type NimbusCloudClient struct {
	ServerURL  string
	Token      string
	HTTPClient *http.Client
}

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.

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"`
	GoVersion      string   `json:"go_version"`
	NimbusModules  []string `json:"nimbus_modules"`
	NimbusJSON     string   `json:"nimbus_json,omitempty"`
	DirectoryTree  string   `json:"directory_tree"`
	GitBranch      string   `json:"git_branch,omitempty"`
	GitDiffSummary string   `json:"git_diff_summary,omitempty"`
	Models         []string `json:"models"`
	Controllers    []string `json:"controllers"`
	Migrations     []string `json:"migrations"`
	RoutesSummary  string   `json:"routes_summary,omitempty"`
	Skills         []Skill  `json:"skills,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.

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"
}

Session represents an AI session stored on disk.

func ListSessions

func ListSessions(appRoot string) ([]*Session, error)

ListSessions returns a list of recent sessions sorted newest first.

func LoadSession

func LoadSession(appRoot, sessionID string) (*Session, error)

LoadSession reads an existing session from disk.

func NewSession

func NewSession(model string) *Session

NewSession creates an empty initialized Session.

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

func LoadSkills(appRoot string) ([]Skill, error)

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
}

ToolExecutor executes agent tool requests.

func NewToolExecutor

func NewToolExecutor(appRoot string) *ToolExecutor

NewToolExecutor creates a tool executor sandboxed to appRoot.

func (*ToolExecutor) Bash

func (t *ToolExecutor) Bash(ctx context.Context, commandStr string) (string, error)

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)

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) 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)

func (*ToolExecutor) ListDir

func (t *ToolExecutor) ListDir(relPath string) (string, error)

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) ReadFile

func (t *ToolExecutor) ReadFile(relPath string) (string, error)

func (*ToolExecutor) ReadSkill

func (t *ToolExecutor) ReadSkill(name string) (string, error)

ReadSkill is an alias for LoadSkill.

func (*ToolExecutor) WriteFile

func (t *ToolExecutor) WriteFile(relPath, newContent string) (string, string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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