cursor

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cursor provides the adapter for Cursor integration.

Index

Constants

View Source
const (
	// AgentName is the machine identifier for Cursor.
	AgentName = agent.AgentCursor
	// DisplayName is the human-readable name for Cursor.
	DisplayName = agent.DisplayCursor
)

Variables

View Source
var HookTypeMapping = map[string]events.ActionType{
	"preToolUse":           events.ActionToolUse,
	"postToolUse":          events.ActionToolUse,
	"postToolUseFailure":   events.ActionToolUse,
	"beforeShellExecution": events.ActionCommandExec,
	"afterShellExecution":  events.ActionCommandExec,
	"beforeMCPExecution":   events.ActionToolUse,
	"afterMCPExecution":    events.ActionToolUse,
	"beforeReadFile":       events.ActionFileRead,
	"afterFileEdit":        events.ActionFileWrite,
	"beforeTabFileRead":    events.ActionFileRead,
	"afterTabFileEdit":     events.ActionFileWrite,
	"beforeSubmitPrompt":   events.ActionToolUse,
	"afterAgentResponse":   events.ActionToolUse,
	"subagentStart":        events.ActionToolUse,
	"subagentStop":         events.ActionToolUse,
	"afterAgentThought":    events.ActionToolUse,
	"sessionStart":         events.ActionSessionStart,
	"sessionEnd":           events.ActionSessionEnd,
	"stop":                 events.ActionSessionEnd,
	"preCompact":           events.ActionToolUse,
}

HookTypeMapping maps Cursor hook types to action types.

View Source
var HookTypes = []string{

	"preToolUse",
	"beforeShellExecution",
	"beforeMCPExecution",
	"beforeReadFile",
	"beforeTabFileRead",
	"beforeSubmitPrompt",

	"postToolUse",
	"postToolUseFailure",
	"afterFileEdit",
	"afterTabFileEdit",
	"afterShellExecution",
	"afterMCPExecution",
	"afterAgentResponse",
	"afterAgentThought",

	"sessionStart",
	"sessionEnd",
	"stop",

	"subagentStart",
	"subagentStop",

	"preCompact",
}

HookTypes are the hook types supported by Cursor that we install. These are the hooks that Gryph registers for monitoring.

View Source
var ToolNameToActionType = map[string]events.ActionType{
	"Shell": events.ActionCommandExec,
	"Read":  events.ActionFileRead,
	"Write": events.ActionFileWrite,
	"Edit":  events.ActionFileWrite,
	"Grep":  events.ActionFileRead,
	"Glob":  events.ActionFileRead,
	"Task":  events.ActionToolUse,
}

ToolNameToActionType maps Cursor tool names to action types.

Functions

func Detect

func Detect(ctx context.Context) (*agent.DetectionResult, error)

Detect checks if Cursor is installed on the system.

func GenerateContinueResponse

func GenerateContinueResponse(cont bool, message string) []byte

GenerateContinueResponse generates a response for beforeSubmitPrompt and sessionStart hooks.

func GeneratePermissionResponse

func GeneratePermissionResponse(response *HookResponse) []byte

GeneratePermissionResponse generates a response for beforeShellExecution, beforeMCPExecution, beforeReadFile hooks.

func GeneratePreToolUseResponse

func GeneratePreToolUseResponse(response *HookResponse) []byte

GeneratePreToolUseResponse generates a response for preToolUse hooks.

func GenerateResponse

func GenerateResponse(allow bool, message string) []byte

GenerateResponse generates a generic allow/deny response (for backwards compatibility). Deprecated: Use the hook-specific response generators instead.

func GenerateStopResponse

func GenerateStopResponse(followupMessage string) []byte

GenerateStopResponse generates a response for stop and subagentStop hooks.

func GetHookStatus

func GetHookStatus(ctx context.Context) (*agent.HookStatus, error)

GetHookStatus checks the current hook state.

func InstallHooks

func InstallHooks(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)

InstallHooks installs hooks for Cursor.

func Register

func Register(registry *agent.Registry, privacyChecker *events.PrivacyChecker, loggingLevel config.LoggingLevel, contentHash bool)

Register adds this adapter to the given registry.

func UninstallHooks

func UninstallHooks(ctx context.Context, opts agent.UninstallOptions) (*agent.UninstallResult, error)

UninstallHooks removes hooks from Cursor.

func ValidateHooksContent

func ValidateHooksContent(config *HooksConfig) []string

ValidateHooksContent checks if hooks.json contains correctly formatted gryph commands.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements the agent.Adapter interface for Cursor.

func New

func New(privacyChecker *events.PrivacyChecker, loggingLevel config.LoggingLevel, contentHash bool) *Adapter

New creates a new Cursor adapter.

func (*Adapter) Detect

func (a *Adapter) Detect(ctx context.Context) (*agent.DetectionResult, error)

Detect determines if Cursor is installed.

func (*Adapter) DisplayName

func (a *Adapter) DisplayName() string

DisplayName returns the human-readable name.

func (*Adapter) Install

func (a *Adapter) Install(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)

Install installs hooks for Cursor.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the machine identifier.

func (*Adapter) ParseEvent

func (a *Adapter) ParseEvent(ctx context.Context, hookType string, rawData []byte) (*events.Event, error)

ParseEvent converts a Cursor event to the common format.

func (*Adapter) Status

func (a *Adapter) Status(ctx context.Context) (*agent.HookStatus, error)

Status checks the current hook state.

func (*Adapter) Uninstall

Uninstall removes hooks from Cursor.

type AfterAgentThoughtInput

type AfterAgentThoughtInput struct {
	HookInput
	Text       string `json:"text"`
	DurationMs int64  `json:"duration_ms"`
}

AfterAgentThoughtInput represents the input for afterAgentThought hooks.

type AfterFileEditInput

type AfterFileEditInput struct {
	HookInput
	FilePath string `json:"file_path"`
	Edits    []struct {
		OldString string `json:"old_string"`
		NewString string `json:"new_string"`
	} `json:"edits"`
}

AfterFileEditInput represents the input for afterFileEdit hooks.

type AfterMCPExecutionInput

type AfterMCPExecutionInput struct {
	HookInput
	ToolName   string                 `json:"tool_name"`
	ToolInput  map[string]interface{} `json:"tool_input"`
	ResultJSON map[string]interface{} `json:"result_json,omitempty"`
	Duration   int64                  `json:"duration"`
}

AfterMCPExecutionInput represents the input for afterMCPExecution hooks.

type AfterShellExecutionInput

type AfterShellExecutionInput struct {
	HookInput
	Command  string `json:"command"`
	Output   string `json:"output"`
	Duration int64  `json:"duration"`
	Cwd      string `json:"cwd,omitempty"`
}

AfterShellExecutionInput represents the input for afterShellExecution hooks.

type BeforeMCPExecutionInput

type BeforeMCPExecutionInput struct {
	HookInput
	ToolName  string                 `json:"tool_name"`
	ToolInput map[string]interface{} `json:"tool_input"`
	URL       string                 `json:"url,omitempty"`
	Command   string                 `json:"command,omitempty"`
	Cwd       string                 `json:"cwd,omitempty"`
}

BeforeMCPExecutionInput represents the input for beforeMCPExecution hooks.

type BeforeReadFileInput

type BeforeReadFileInput struct {
	HookInput
	FilePath string `json:"file_path"`
	Content  string `json:"content,omitempty"`
}

BeforeReadFileInput represents the input for beforeReadFile hooks.

type BeforeShellExecutionInput

type BeforeShellExecutionInput struct {
	HookInput
	Command string `json:"command"`
	Cwd     string `json:"cwd"`
	Timeout int    `json:"timeout"`
}

BeforeShellExecutionInput represents the input for beforeShellExecution hooks.

type BeforeSubmitPromptInput

type BeforeSubmitPromptInput struct {
	HookInput
	Prompt string `json:"prompt"`
}

BeforeSubmitPromptInput represents the input for beforeSubmitPrompt hooks.

type HookCommand

type HookCommand struct {
	Command string `json:"command"`
}

HookCommand represents a single hook command.

type HookDecision

type HookDecision int

HookDecision represents the decision for a Cursor hook.

const (
	// HookAllow allows the action to proceed.
	HookAllow HookDecision = iota
	// HookDeny blocks the action.
	HookDeny
	// HookAsk prompts the user to confirm (only for some hooks).
	HookAsk
)

type HookInput

type HookInput struct {
	ConversationID string   `json:"conversation_id"`
	GenerationID   string   `json:"generation_id"`
	Model          string   `json:"model,omitempty"`
	HookEventName  string   `json:"hook_event_name"`
	CursorVersion  string   `json:"cursor_version,omitempty"`
	WorkspaceRoots []string `json:"workspace_roots,omitempty"`
	UserEmail      string   `json:"user_email,omitempty"`
	TranscriptPath string   `json:"transcript_path,omitempty"`
}

HookInput represents the common fields in all Cursor hook inputs.

type HookResponse

type HookResponse struct {
	// Decision is whether to allow, deny, or ask.
	Decision HookDecision
	// Reason is the reason for the decision (shown to agent or user).
	Reason string
}

HookResponse represents a response to Cursor hooks.

func NewAllowResponse

func NewAllowResponse() *HookResponse

NewAllowResponse creates a response that allows the action.

func NewAskResponse

func NewAskResponse(reason string) *HookResponse

NewAskResponse creates a response that asks the user to confirm.

func NewDenyResponse

func NewDenyResponse(reason string) *HookResponse

NewDenyResponse creates a response that denies the action.

type HooksConfig

type HooksConfig struct {
	Version int                      `json:"version"`
	Hooks   map[string][]HookCommand `json:"hooks"`
}

HooksConfig represents the Cursor hooks.json structure.

func GenerateHooksConfig

func GenerateHooksConfig() *HooksConfig

GenerateHooksConfig generates the hooks.json content for Gryph.

type PostToolUseFailureInput

type PostToolUseFailureInput struct {
	HookInput
	ToolName     string                 `json:"tool_name"`
	ToolInput    map[string]interface{} `json:"tool_input"`
	ToolUseID    string                 `json:"tool_use_id"`
	Cwd          string                 `json:"cwd"`
	ErrorMessage string                 `json:"error_message"`
	FailureType  string                 `json:"failure_type"` // timeout, error, permission_denied
	Duration     int64                  `json:"duration"`
	IsInterrupt  bool                   `json:"is_interrupt"`
}

PostToolUseFailureInput represents the input for postToolUseFailure hooks.

type PostToolUseInput

type PostToolUseInput struct {
	HookInput
	ToolName   string                 `json:"tool_name"`
	ToolInput  map[string]interface{} `json:"tool_input"`
	ToolOutput string                 `json:"tool_output"`
	ToolUseID  string                 `json:"tool_use_id"`
	Cwd        string                 `json:"cwd"`
	Duration   int64                  `json:"duration"`
}

PostToolUseInput represents the input for postToolUse hooks.

type PreToolUseInput

type PreToolUseInput struct {
	HookInput
	ToolName     string                 `json:"tool_name"`
	ToolInput    map[string]interface{} `json:"tool_input"`
	ToolUseID    string                 `json:"tool_use_id"`
	Cwd          string                 `json:"cwd"`
	AgentMessage string                 `json:"agent_message,omitempty"`
}

PreToolUseInput represents the input for preToolUse hooks.

type SessionEndInput

type SessionEndInput struct {
	HookInput
	SessionID         string `json:"session_id"`
	Reason            string `json:"reason"` // completed, aborted, error, window_close, user_close
	DurationMs        int64  `json:"duration_ms"`
	IsBackgroundAgent bool   `json:"is_background_agent"`
	FinalStatus       string `json:"final_status,omitempty"`
	ErrorMessage      string `json:"error_message,omitempty"`
}

SessionEndInput represents the input for sessionEnd hooks.

type SessionStartInput

type SessionStartInput struct {
	HookInput
	SessionID         string `json:"session_id"`
	IsBackgroundAgent bool   `json:"is_background_agent"`
	ComposerMode      string `json:"composer_mode"` // agent, ask, edit
}

SessionStartInput represents the input for sessionStart hooks.

type StopInput

type StopInput struct {
	HookInput
	Status    string `json:"status"` // completed, aborted, error
	LoopCount int    `json:"loop_count"`
}

StopInput represents the input for stop hooks.

type SubagentStartInput

type SubagentStartInput struct {
	HookInput
	SubagentType string `json:"subagent_type"`
	Prompt       string `json:"prompt,omitempty"`
	SubModel     string `json:"model,omitempty"`
}

SubagentStartInput represents the input for subagentStart hooks.

type SubagentStopInput

type SubagentStopInput struct {
	HookInput
	SubagentType string `json:"subagent_type"`
	Status       string `json:"status"`
	Result       string `json:"result,omitempty"`
	Duration     int64  `json:"duration"`
}

SubagentStopInput represents the input for subagentStop hooks.

Jump to

Keyboard shortcuts

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