Documentation
¶
Overview ¶
Package cursor provides Cursor CLI configuration management.
Package cursor provides Cursor CLI configuration management.
Package cursor provides Cursor CLI configuration management.
Index ¶
- Constants
- Variables
- func AddMCPServer(workDir, name string, server MCPServer) error
- func Available() bool
- func CaptureSessionID(output string) string
- func CleanOrphanClaudeConfig(workDir string) (bool, error)
- func CreateChat(workDir string) (string, error)
- func EnsureGasTownMCPServers(workDir string) error
- func EnsureHooks(workDir string) error
- func EnsureSettings(workDir string, roleType RoleType) error
- func EnsureSettingsForRole(workDir, role string) error
- func EnsureWorkspaceReady(workDir, role string) error
- func GetLatestSession() (string, error)
- func GetModelForRole(role string) string
- func GetModelRationale(role string) string
- func GlobalMCPConfigPath() (string, error)
- func HooksInstalled(workDir string) bool
- func IsValidModel(model string) bool
- func ListCursorSessions() ([]string, error)
- func ListMCPServers(workDir string) ([]string, error)
- func MCPConfigPath(workDir string) string
- func ModelProvider(model string) string
- func RemoveHooks(workDir string) error
- func RemoveMCPServer(workDir, name string) error
- func ResumeSession(sessionID string, args ...string) []string
- func SaveMCPConfig(path string, config *MCPConfig) error
- func Version() (string, error)
- type Adapter
- type HookEntry
- type HooksConfig
- type MCPAuth
- type MCPConfig
- type MCPServer
- type RoleType
- type Session
- type SessionStore
- func (s *SessionStore) CleanupStale(maxAge time.Duration) error
- func (s *SessionStore) Delete(id string) error
- func (s *SessionStore) Get(id string) *Session
- func (s *SessionStore) GetByRole(role, rigName string) *Session
- func (s *SessionStore) List() []*Session
- func (s *SessionStore) ListActive() []*Session
- func (s *SessionStore) Put(sess *Session) error
Constants ¶
const ( SessionStatusActive = "active" SessionStatusSuspended = "suspended" SessionStatusCompleted = "completed" )
SessionStatus constants.
Variables ¶
var SupportedModels = []string{
"auto",
"opus-4.5-thinking",
"opus-4.5",
"sonnet-4.5",
"sonnet-4.5-thinking",
"gpt-5.2",
"gpt-5.2-high",
"gpt-5.1-codex-max",
"gemini-3-pro",
"gemini-3-flash",
"grok",
}
SupportedModels returns the list of supported models. These are the models available via cursor-agent.
Functions ¶
func AddMCPServer ¶
AddMCPServer adds or updates an MCP server in the workspace configuration.
func CaptureSessionID ¶
CaptureSessionID attempts to capture the session ID from cursor-agent output. This is called from the stop hook to record the session for potential resume.
cursor-agent outputs session info in various ways: - In JSON output mode: {"chat_id": "..."} - In text mode: Look for patterns like "Session: abc123" or "Chat ID: abc123"
func CleanOrphanClaudeConfig ¶
CleanOrphanClaudeConfig removes any orphaned Claude-specific configuration files. Returns true if any files were cleaned, false otherwise. This is a no-op in the current implementation as we've moved to multi-model orchestration.
func CreateChat ¶
CreateChat creates a new cursor-agent chat and returns its ID. This uses 'cursor-agent create-chat' if available.
func EnsureGasTownMCPServers ¶
EnsureGasTownMCPServers ensures Gas Town MCP servers are configured. Currently a no-op as Gas Town does not yet have an MCP server.
func EnsureHooks ¶
EnsureHooks ensures Gas Town hooks are installed in the workspace. This creates .cursor/hooks.json and .cursor/hooks/ directory with hook scripts.
func EnsureSettings ¶
EnsureSettings ensures .cursor/rules directory exists with Gas Town rules, and installs Gas Town hooks for Cursor CLI. For worktrees, we use sparse checkout to exclude source repo's .cursor/ directory, so our rules are the only ones Cursor sees.
func EnsureSettingsForRole ¶
EnsureSettingsForRole is a convenience function that combines RoleTypeFor and EnsureSettings.
func EnsureWorkspaceReady ¶
EnsureWorkspaceReady ensures the workspace is ready for cursor-agent. This creates necessary directories and configuration files.
func GetLatestSession ¶
GetLatestSession returns the most recent cursor-agent session.
func GetModelForRole ¶
GetModelForRole returns the recommended model for a Gas Town role. This implements the Council's role-model matrix.
func GetModelRationale ¶
GetModelRationale returns the reasoning for a role's model choice.
func GlobalMCPConfigPath ¶
GlobalMCPConfigPath returns the path to the global mcp.json. This is located at ~/.cursor/mcp.json for user-wide configuration.
func HooksInstalled ¶
HooksInstalled checks if Gas Town hooks are installed in the workspace.
func IsValidModel ¶
IsValidModel checks if a model name is valid.
func ListCursorSessions ¶
ListCursorSessions runs 'cursor-agent ls' to list available sessions. Note: This may not work in non-TTY environments.
func ListMCPServers ¶
ListMCPServers returns a list of configured MCP server names.
func MCPConfigPath ¶
MCPConfigPath returns the path to the workspace-level mcp.json. This is located at .cursor/mcp.json in the workspace root.
func ModelProvider ¶
ModelProvider returns the provider for a given model.
func RemoveHooks ¶
RemoveHooks removes Gas Town hooks from the workspace.
func RemoveMCPServer ¶
RemoveMCPServer removes an MCP server from the workspace configuration.
func ResumeSession ¶
ResumeSession builds a command to resume a cursor-agent session.
func SaveMCPConfig ¶
SaveMCPConfig writes an MCP configuration to the given path.
Types ¶
type Adapter ¶
type Adapter struct {
// WorkDir is the workspace directory.
WorkDir string
// Model is the model to use (e.g., "sonnet-4.5", "gpt-5.2").
Model string
// ForceMode enables YOLO/force mode (-f flag).
ForceMode bool
// PrintMode enables non-interactive/print mode (-p flag).
PrintMode bool
// OutputFormat specifies output format ("text" or "json").
OutputFormat string
// SessionID is an optional session ID for resume.
SessionID string
// ApproveAll auto-approves MCP servers and other prompts.
ApproveAll bool
// AdditionalArgs are extra arguments to pass to cursor-agent.
AdditionalArgs []string
}
Adapter translates Gas Town operations to Cursor CLI commands. This is the primary interface for interacting with cursor-agent.
func AdapterForRole ¶
AdapterForRole returns an adapter configured for a specific Gas Town role.
func DefaultAdapter ¶
DefaultAdapter returns an adapter with sensible defaults for Gas Town.
func TranslateRuntimeConfig ¶
func TranslateRuntimeConfig(rc *config.RuntimeConfig, workDir string) *Adapter
TranslateRuntimeConfig converts a Gas Town RuntimeConfig to an Adapter.
func (*Adapter) BuildCommand ¶
BuildCommand builds the cursor-agent command with all configured options.
func (*Adapter) BuildCommandString ¶
BuildCommandString returns the full command as a string (for tmux SendKeys).
type HookEntry ¶
type HookEntry struct {
Command string `json:"command"`
}
HookEntry represents a single hook configuration
type HooksConfig ¶
type HooksConfig struct {
Version int `json:"version"`
Hooks map[string][]HookEntry `json:"hooks"`
}
HooksConfig represents the structure of Cursor's hooks.json
type MCPAuth ¶
type MCPAuth struct {
// ClientID is the OAuth 2.0 Client ID from the MCP provider.
ClientID string `json:"CLIENT_ID,omitempty"`
// ClientSecret is the OAuth 2.0 Client Secret (for confidential clients).
ClientSecret string `json:"CLIENT_SECRET,omitempty"`
// Scopes are the OAuth scopes to request.
Scopes []string `json:"scopes,omitempty"`
}
MCPAuth contains OAuth configuration for remote MCP servers.
type MCPConfig ¶
type MCPConfig struct {
// McpServers maps server names to their configurations.
McpServers map[string]MCPServer `json:"mcpServers"`
}
MCPConfig represents the structure of a Cursor mcp.json file. See: https://cursor.com/docs/context/mcp
func LoadMCPConfig ¶
LoadMCPConfig loads an MCP configuration from the given path. Returns an empty config if the file doesn't exist.
func MergeMCPConfigs ¶
MergeMCPConfigs merges multiple MCP configurations. Later configs override earlier ones for servers with the same name.
type MCPServer ¶
type MCPServer struct {
// Type indicates the server transport type: "stdio" for local commands.
// If URL is set and Command is empty, the type is implied to be HTTP/SSE.
Type string `json:"type,omitempty"`
// URL is the endpoint URL for the MCP server (for HTTP-based servers).
URL string `json:"url,omitempty"`
// Command is the command to run for stdio-based MCP servers.
Command string `json:"command,omitempty"`
// Args are command-line arguments for stdio-based servers.
Args []string `json:"args,omitempty"`
// Env contains environment variables for the server process.
// Supports interpolation: ${env:NAME}, ${workspaceFolder}, ${userHome}
Env map[string]string `json:"env,omitempty"`
// EnvFile is the path to an environment file to load additional variables.
// Supports interpolation: ${workspaceFolder}/.env
EnvFile string `json:"envFile,omitempty"`
// Headers contains HTTP headers for HTTP-based servers.
// Supports interpolation: ${env:MY_TOKEN}
Headers map[string]string `json:"headers,omitempty"`
// Auth contains OAuth configuration for remote servers.
Auth *MCPAuth `json:"auth,omitempty"`
}
MCPServer represents an MCP server configuration. Supports both stdio (local command) and HTTP-based (remote URL) servers.
func GetMCPServer ¶
GetMCPServer returns a specific MCP server configuration. Returns nil if the server doesn't exist.
func (*MCPServer) IsConfigured ¶
IsConfigured checks if the MCP server has minimum required configuration.
func (*MCPServer) MCPServerType ¶
MCPServerType returns the type of an MCP server ("stdio" or "http").
type RoleType ¶
type RoleType string
RoleType indicates whether a role is autonomous or interactive.
func RoleTypeFor ¶
RoleTypeFor returns the RoleType for a given role name.
type Session ¶
type Session struct {
// ID is the unique chat/session identifier from cursor-agent.
ID string `json:"id"`
// WorkDir is the workspace directory where the session was created.
WorkDir string `json:"work_dir"`
// Role is the Gas Town role (mayor, polecat, witness, etc.).
Role string `json:"role,omitempty"`
// RigName is the rig this session belongs to (empty for town-level sessions).
RigName string `json:"rig_name,omitempty"`
// Model is the model used for this session.
Model string `json:"model,omitempty"`
// CreatedAt is when the session was created.
CreatedAt time.Time `json:"created_at"`
// LastActiveAt is the last time the session was active.
LastActiveAt time.Time `json:"last_active_at"`
// Status is the current session status (active, suspended, completed).
Status string `json:"status"`
}
Session represents a Cursor CLI session.
func SessionFromEnv ¶
SessionFromEnv creates a Session from environment variables. This is used during session startup to capture context.
func (*Session) MarkCompleted ¶
func (s *Session) MarkCompleted()
MarkCompleted marks the session as completed.
func (*Session) MarkSuspended ¶
func (s *Session) MarkSuspended()
MarkSuspended marks the session as suspended.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore manages session state persistence.
func NewSessionStore ¶
func NewSessionStore(dir string) (*SessionStore, error)
NewSessionStore creates a new session store. The store is backed by a JSON file in the given directory.
func (*SessionStore) CleanupStale ¶
func (s *SessionStore) CleanupStale(maxAge time.Duration) error
CleanupStale removes sessions older than the given duration.
func (*SessionStore) Delete ¶
func (s *SessionStore) Delete(id string) error
Delete removes a session.
func (*SessionStore) Get ¶
func (s *SessionStore) Get(id string) *Session
Get returns a session by ID.
func (*SessionStore) GetByRole ¶
func (s *SessionStore) GetByRole(role, rigName string) *Session
GetByRole returns the most recent active session for a role.
func (*SessionStore) ListActive ¶
func (s *SessionStore) ListActive() []*Session
ListActive returns all active sessions.