cursor

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 5 Imported by: 0

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

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

func ReadProjectConfig() (*core.Config, error)

ReadProjectConfig reads the project-level .cursor/hooks.json.

func ReadUserConfig

func ReadUserConfig() (*core.Config, error)

ReadUserConfig reads the user-level ~/.cursor/hooks.json.

func WriteProjectConfig

func WriteProjectConfig(cfg *core.Config) error

WriteProjectConfig writes to the project-level .cursor/hooks.json.

Types

type Adapter

type Adapter struct{}

Adapter implements core.Adapter for Cursor hooks.

func NewAdapter

func NewAdapter() *Adapter

NewAdapter creates a new Cursor hooks adapter.

func (*Adapter) DefaultPaths

func (a *Adapter) DefaultPaths() []string

DefaultPaths returns the default config file paths for Cursor hooks.

func (*Adapter) FromCore

func (a *Adapter) FromCore(cfg *core.Config) *Config

FromCore converts canonical config to Cursor format.

func (*Adapter) Marshal

func (a *Adapter) Marshal(cfg *core.Config) ([]byte, error)

Marshal converts canonical config to Cursor format.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the adapter name.

func (*Adapter) Parse

func (a *Adapter) Parse(data []byte) (*core.Config, error)

Parse parses Cursor hooks config data into the canonical format.

func (*Adapter) ReadFile

func (a *Adapter) ReadFile(path string) (*core.Config, error)

ReadFile reads a Cursor hooks config file.

func (*Adapter) SupportedEvents

func (a *Adapter) SupportedEvents() []core.Event

SupportedEvents returns the events supported by Cursor.

func (*Adapter) ToCore

func (a *Adapter) ToCore(cursorCfg *Config) *core.Config

ToCore converts Cursor hooks config to canonical format.

func (*Adapter) WriteFile

func (a *Adapter) WriteFile(cfg *core.Config, path string) error

WriteFile writes canonical config to a Cursor format file.

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.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty Cursor hooks config.

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

type Hook

type Hook struct {
	// Command is the shell command to execute.
	Command string `json:"command"`
}

Hook represents a single Cursor hook definition.

Jump to

Keyboard shortcuts

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