Documentation
¶
Overview ¶
Package cursor implements the Agent interface for Cursor.
Index ¶
- Constants
- func NewCursorAgent() agent.Agent
- type CursorAgent
- func (c *CursorAgent) AreHooksInstalled(ctx context.Context) bool
- func (c *CursorAgent) ChunkTranscript(_ context.Context, content []byte, maxSize int) ([][]byte, error)
- func (c *CursorAgent) Description() string
- func (c *CursorAgent) DetectPresence(ctx context.Context) (bool, error)
- func (c *CursorAgent) ExtractModifiedFilesFromOffset(_ string, _ int) ([]string, int, error)
- func (c *CursorAgent) ExtractPrompts(sessionRef string, fromOffset int) ([]string, error)
- func (c *CursorAgent) ExtractSummary(sessionRef string) (string, error)
- func (c *CursorAgent) FormatResumeCommand(_ string) string
- func (c *CursorAgent) GetSessionDir(repoPath string) (string, error)
- func (c *CursorAgent) GetSessionID(input *agent.HookInput) string
- func (c *CursorAgent) GetSupportedHooks() []agent.HookType
- func (c *CursorAgent) GetTranscriptPosition(path string) (int, error)
- func (c *CursorAgent) HookNames() []string
- func (c *CursorAgent) InstallHooks(ctx context.Context, localDev bool, force bool) (int, error)
- func (c *CursorAgent) IsPreview() bool
- func (c *CursorAgent) Name() types.AgentName
- func (c *CursorAgent) ParseHookEvent(ctx context.Context, hookName string, stdin io.Reader) (*agent.Event, error)
- func (c *CursorAgent) ProtectedDirs() []string
- func (c *CursorAgent) ReadSession(input *agent.HookInput) (*agent.AgentSession, error)
- func (c *CursorAgent) ReadTranscript(sessionRef string) ([]byte, error)
- func (c *CursorAgent) ReassembleTranscript(chunks [][]byte) ([]byte, error)
- func (c *CursorAgent) ResolveSessionFile(sessionDir, agentSessionID string) string
- func (c *CursorAgent) Type() types.AgentType
- func (c *CursorAgent) UninstallHooks(ctx context.Context) error
- func (c *CursorAgent) WriteSession(_ context.Context, session *agent.AgentSession) error
- type CursorHookEntry
- type CursorHooks
- type CursorHooksFile
Constants ¶
const ( HookNameSessionStart = "session-start" HookNameSessionEnd = "session-end" HookNameBeforeSubmitPrompt = "before-submit-prompt" HookNameStop = "stop" HookNamePreCompact = "pre-compact" HookNameSubagentStart = "subagent-start" HookNameSubagentStop = "subagent-stop" )
Cursor hook names - these become subcommands under `entire hooks cursor`
const HooksFileName = "hooks.json"
HooksFileName is the hooks file used by Cursor.
Variables ¶
This section is empty.
Functions ¶
func NewCursorAgent ¶
NewCursorAgent creates a new Cursor agent instance.
Types ¶
type CursorAgent ¶
type CursorAgent struct{}
CursorAgent implements the Agent interface for Cursor.
func (*CursorAgent) AreHooksInstalled ¶
func (c *CursorAgent) AreHooksInstalled(ctx context.Context) bool
AreHooksInstalled checks if Entire hooks are installed.
func (*CursorAgent) ChunkTranscript ¶
func (c *CursorAgent) ChunkTranscript(_ context.Context, content []byte, maxSize int) ([][]byte, error)
ChunkTranscript splits a JSONL transcript at line boundaries.
func (*CursorAgent) Description ¶
func (c *CursorAgent) Description() string
Description returns a human-readable description.
func (*CursorAgent) DetectPresence ¶
func (c *CursorAgent) DetectPresence(ctx context.Context) (bool, error)
DetectPresence checks if Cursor is configured in the repository.
func (*CursorAgent) ExtractModifiedFilesFromOffset ¶ added in v0.5.0
ExtractModifiedFilesFromOffset returns no modified files for Cursor and a constant position of 0, because Cursor transcripts do not contain tool_use blocks. File detection relies on git status and hook-provided modified_files instead.
func (*CursorAgent) ExtractPrompts ¶ added in v0.5.0
func (c *CursorAgent) ExtractPrompts(sessionRef string, fromOffset int) ([]string, error)
ExtractPrompts extracts user prompts from the transcript starting at the given line offset. Cursor uses the same JSONL format as Claude Code; the shared transcript package normalizes "role" → "type" and strips <user_query> tags.
func (*CursorAgent) ExtractSummary ¶ added in v0.5.0
func (c *CursorAgent) ExtractSummary(sessionRef string) (string, error)
ExtractSummary extracts the last assistant message as a session summary.
func (*CursorAgent) FormatResumeCommand ¶
func (c *CursorAgent) FormatResumeCommand(_ string) string
FormatResumeCommand returns an instruction to resume a Cursor session. Cursor is a GUI IDE, so there's no CLI command to resume a session directly.
func (*CursorAgent) GetSessionDir ¶
func (c *CursorAgent) GetSessionDir(repoPath string) (string, error)
GetSessionDir returns the directory where Cursor stores session transcripts.
func (*CursorAgent) GetSessionID ¶
func (c *CursorAgent) GetSessionID(input *agent.HookInput) string
GetSessionID extracts the session ID from hook input.
func (*CursorAgent) GetSupportedHooks ¶
func (c *CursorAgent) GetSupportedHooks() []agent.HookType
GetSupportedHooks returns the hook types Cursor supports.
func (*CursorAgent) GetTranscriptPosition ¶ added in v0.5.0
func (c *CursorAgent) GetTranscriptPosition(path string) (int, error)
GetTranscriptPosition returns the current line count of a Cursor transcript. Cursor uses the same JSONL format as Claude Code, so position is the number of lines. Uses bufio.Reader to handle arbitrarily long lines (no size limit). Returns 0 if the file doesn't exist or is empty.
func (*CursorAgent) HookNames ¶
func (c *CursorAgent) HookNames() []string
HookNames returns the hook verbs Cursor supports. These become subcommands: entire hooks cursor <verb>
func (*CursorAgent) InstallHooks ¶
InstallHooks installs Cursor hooks in .cursor/hooks.json. If force is true, removes existing Entire hooks before installing. Returns the number of hooks installed. Unknown top-level fields and hook types are preserved on round-trip.
func (*CursorAgent) IsPreview ¶
func (c *CursorAgent) IsPreview() bool
func (*CursorAgent) Name ¶
func (c *CursorAgent) Name() types.AgentName
Name returns the agent registry key.
func (*CursorAgent) ParseHookEvent ¶
func (c *CursorAgent) ParseHookEvent(ctx context.Context, hookName string, stdin io.Reader) (*agent.Event, error)
ParseHookEvent translates a Cursor hook into a normalized lifecycle Event. Returns nil if the hook has no lifecycle significance.
func (*CursorAgent) ProtectedDirs ¶
func (c *CursorAgent) ProtectedDirs() []string
ProtectedDirs returns directories that Cursor uses for config/state.
func (*CursorAgent) ReadSession ¶
func (c *CursorAgent) ReadSession(input *agent.HookInput) (*agent.AgentSession, error)
ReadSession reads a session from Cursor's storage (JSONL transcript file). Note: ModifiedFiles is left empty because Cursor's transcript does not contain tool_use blocks for file detection. TranscriptAnalyzer extracts prompts and summaries; file detection relies on git status.
func (*CursorAgent) ReadTranscript ¶
func (c *CursorAgent) ReadTranscript(sessionRef string) ([]byte, error)
ReadTranscript reads the raw JSONL transcript bytes for a session.
func (*CursorAgent) ReassembleTranscript ¶
func (c *CursorAgent) ReassembleTranscript(chunks [][]byte) ([]byte, error)
ReassembleTranscript concatenates JSONL chunks with newlines.
func (*CursorAgent) ResolveSessionFile ¶
func (c *CursorAgent) ResolveSessionFile(sessionDir, agentSessionID string) string
ResolveSessionFile returns the path to a Cursor session file. Cursor IDE uses a nested layout: <dir>/<id>/<id>.jsonl Cursor CLI uses a flat layout: <dir>/<id>.jsonl We prefer nested if the file OR directory exists (the directory may be created before the file is flushed), otherwise fall back to flat.
func (*CursorAgent) Type ¶
func (c *CursorAgent) Type() types.AgentType
Type returns the agent type identifier.
func (*CursorAgent) UninstallHooks ¶
func (c *CursorAgent) UninstallHooks(ctx context.Context) error
UninstallHooks removes Entire hooks from Cursor HooksFileName. Unknown top-level fields and hook types are preserved on round-trip.
func (*CursorAgent) WriteSession ¶
func (c *CursorAgent) WriteSession(_ context.Context, session *agent.AgentSession) error
WriteSession writes a session to Cursor's storage (JSONL transcript file).
type CursorHookEntry ¶
type CursorHookEntry struct {
Command string `json:"command"`
Matcher string `json:"matcher,omitempty"`
}
CursorHookEntry represents a single hook command. Cursor hooks have a command string and an optional matcher field for filtering by tool name.
type CursorHooks ¶
type CursorHooks struct {
SessionStart []CursorHookEntry `json:"sessionStart,omitempty"`
SessionEnd []CursorHookEntry `json:"sessionEnd,omitempty"`
BeforeSubmitPrompt []CursorHookEntry `json:"beforeSubmitPrompt,omitempty"`
Stop []CursorHookEntry `json:"stop,omitempty"`
PreCompact []CursorHookEntry `json:"preCompact,omitempty"`
SubagentStart []CursorHookEntry `json:"subagentStart,omitempty"`
SubagentStop []CursorHookEntry `json:"subagentStop,omitempty"`
}
CursorHooks contains all hook configurations using camelCase keys.
type CursorHooksFile ¶
type CursorHooksFile struct {
Version int `json:"version"`
Hooks CursorHooks `json:"hooks"`
}
CursorHooksFile represents the .cursor/HooksFileName structure. Cursor uses a flat JSON file with version and hooks sections.