Documentation
¶
Overview ¶
Package cursor provides an adapter for Cursor IDE hooks configuration.
Cursor hooks are configured in hooks.json files:
- Project: .cursor/hooks.json
- User: ~/.cursor/hooks.json
- Enterprise: /Library/Application Support/Cursor/hooks.json (macOS)
Cursor hook events:
- beforeShellExecution: Gates shell commands
- afterShellExecution: Audits executed commands
- beforeMCPExecution: Controls MCP tool usage
- afterMCPExecution: Monitors MCP results
- beforeReadFile: Controls file access
- afterFileEdit: Processes file modifications
- beforeSubmitPrompt: Validates prompts
- afterAgentResponse: Observes assistant messages
- afterAgentThought: Tracks reasoning blocks
- stop: Handles agent loop termination
- beforeTabFileRead: Controls Tab file access
- afterTabFileEdit: Processes Tab edits
Index ¶
- Constants
- func ProjectConfigPath() string
- func ReadProjectConfig() (*core.Config, error)
- func ReadUserConfig() (*core.Config, error)
- func WriteProjectConfig(cfg *core.Config) error
- type Adapter
- func (a *Adapter) DefaultPaths() []string
- func (a *Adapter) FromCore(cfg *core.Config) *Config
- func (a *Adapter) Marshal(cfg *core.Config) ([]byte, error)
- func (a *Adapter) Name() string
- func (a *Adapter) Parse(data []byte) (*core.Config, error)
- func (a *Adapter) ReadFile(path string) (*core.Config, error)
- func (a *Adapter) SupportedEvents() []core.Event
- func (a *Adapter) ToCore(cursorCfg *Config) *core.Config
- func (a *Adapter) WriteFile(cfg *core.Config, path string) error
- type Config
- type CursorEvent
- type Hook
Constants ¶
View Source
const ( // AdapterName is the identifier for this adapter. AdapterName = "cursor" // ConfigFileName is the hooks config file name. ConfigFileName = "hooks.json" // ProjectConfigDir is the project config directory. ProjectConfigDir = ".cursor" )
Variables ¶
This section is empty.
Functions ¶
func ProjectConfigPath ¶
func ProjectConfigPath() string
ProjectConfigPath returns the project hooks config path.
func ReadProjectConfig ¶
ReadProjectConfig reads the project-level .cursor/hooks.json.
func ReadUserConfig ¶
ReadUserConfig reads the user-level ~/.cursor/hooks.json.
func WriteProjectConfig ¶
WriteProjectConfig writes to the project-level .cursor/hooks.json.
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter implements core.Adapter for Cursor hooks.
func (*Adapter) DefaultPaths ¶
DefaultPaths returns the default config file paths for Cursor hooks.
func (*Adapter) SupportedEvents ¶
SupportedEvents returns the events supported by Cursor.
type Config ¶
type Config struct {
// Version is the configuration version.
Version int `json:"version"`
// Hooks maps event names to hook definitions.
Hooks map[CursorEvent][]Hook `json:"hooks"`
}
Config represents Cursor's hooks.json configuration.
type CursorEvent ¶
type CursorEvent string
CursorEvent represents Cursor-specific hook event names.
const ( BeforeShellExecution CursorEvent = "beforeShellExecution" AfterShellExecution CursorEvent = "afterShellExecution" BeforeMCPExecution CursorEvent = "beforeMCPExecution" AfterMCPExecution CursorEvent = "afterMCPExecution" BeforeReadFile CursorEvent = "beforeReadFile" AfterFileEdit CursorEvent = "afterFileEdit" BeforeSubmitPrompt CursorEvent = "beforeSubmitPrompt" AfterAgentResponse CursorEvent = "afterAgentResponse" AfterAgentThought CursorEvent = "afterAgentThought" Stop CursorEvent = "stop" BeforeTabFileRead CursorEvent = "beforeTabFileRead" AfterTabFileEdit CursorEvent = "afterTabFileEdit" )
Click to show internal directories.
Click to hide internal directories.