Documentation
¶
Overview ¶
Package agentic provides security analysis for AI coding assistants. It detects critical threats (config writes, invisible unicode) and performs Rule of Two analysis to detect potential security violations where an action combines more than two of: [A] untrustworthy inputs, [B] sensitive access, [C] state changes or external communication.
Index ¶
- func FormatBlockMessage(result *AnalysisResult) string
- func GenerateCursorDisabledOutput() ([]byte, int, string)
- func GenerateCursorOutput(result *AnalysisResult) ([]byte, int, string)
- func GenerateCursorThreatOutput(threat *CriticalThreat) ([]byte, int, string)
- func IsDebug() bool
- func IsDisabled() bool
- type AgentType
- type AgenticMode
- type AnalysisResult
- type Analyzer
- type BashInput
- type Capability
- type CapabilityResult
- type CriticalThreat
- type CursorOutput
- type CursorShellInput
- type EditInput
- type GlobInput
- type GrepInput
- type HookInput
- type HookOutput
- type HookSpecificOutput
- type InvisibleCharInfo
- type ReadInput
- type WebFetchInput
- type WebSearchInput
- type WriteInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBlockMessage ¶
func FormatBlockMessage(result *AnalysisResult) string
FormatBlockMessage creates a formatted error message for blocked operations.
func GenerateCursorDisabledOutput ¶
GenerateCursorDisabledOutput creates output when agentic checks are disabled.
func GenerateCursorOutput ¶
func GenerateCursorOutput(result *AnalysisResult) ([]byte, int, string)
GenerateCursorOutput converts analysis results to Cursor output format. Returns (jsonOutput, exitCode, stderrMessage).
func GenerateCursorThreatOutput ¶
func GenerateCursorThreatOutput(threat *CriticalThreat) ([]byte, int, string)
GenerateCursorThreatOutput converts critical threat to Cursor output format. Returns (jsonOutput, exitCode, stderrMessage).
func IsDisabled ¶
func IsDisabled() bool
IsDisabled returns true if agentic mode is disabled via environment.
Types ¶
type AgentType ¶
type AgentType string
AgentType represents the type of AI coding assistant.
func DetectAgent ¶
func DetectAgent() AgentType
DetectAgent returns the agent type based on environment variables. Priority: CURSOR_AGENT=1 > CLAUDECODE=1 > unknown
func DetectAgentFromInput ¶
DetectAgentFromInput attempts to determine the agent type from the JSON input structure. This is used as a fallback when environment variable detection fails.
type AgenticMode ¶
type AgenticMode string
AgenticMode controls behavior when Rule of Two is violated.
const ( // ModeBlock blocks the action with exit code 2. ModeBlock AgenticMode = "block" // ModeAsk prompts user for confirmation instead of blocking. ModeAsk AgenticMode = "ask" )
func GetAgenticMode ¶
func GetAgenticMode() AgenticMode
GetAgenticMode returns the configured agentic mode from environment.
type AnalysisResult ¶
type AnalysisResult struct {
ToolName string
CapabilityA CapabilityResult // Untrustworthy inputs
CapabilityB CapabilityResult // Sensitive access
CapabilityC CapabilityResult // State change/external comms
SignalHits []string // Which dashlights signals also triggered
}
AnalysisResult captures the complete Rule of Two analysis for a tool call.
func (*AnalysisResult) AllReasons ¶
func (r *AnalysisResult) AllReasons() []string
AllReasons collects all detection reasons across capabilities.
func (*AnalysisResult) CapabilityCount ¶
func (r *AnalysisResult) CapabilityCount() int
CapabilityCount returns how many capabilities were detected.
func (*AnalysisResult) CapabilityString ¶
func (r *AnalysisResult) CapabilityString() string
CapabilityString returns a string like "A+B" or "A+B+C" for detected capabilities.
func (*AnalysisResult) ViolatesRuleOfTwo ¶
func (r *AnalysisResult) ViolatesRuleOfTwo() bool
ViolatesRuleOfTwo returns true if all three capabilities are detected.
type Analyzer ¶
type Analyzer struct {
// RunSignals controls whether to run dashlights signals for enhanced detection.
RunSignals bool
// SignalTimeout is the timeout for running signals (default 5ms).
SignalTimeout time.Duration
}
Analyzer performs Rule of Two analysis on tool calls.
func NewAnalyzer ¶
func NewAnalyzer() *Analyzer
NewAnalyzer creates an Analyzer with default settings.
func (*Analyzer) Analyze ¶
func (a *Analyzer) Analyze(input *HookInput) *AnalysisResult
Analyze performs Rule of Two analysis on a hook input.
type BashInput ¶
type BashInput struct {
Command string `json:"command"`
Description string `json:"description,omitempty"`
Timeout int `json:"timeout,omitempty"`
}
BashInput represents the tool_input for Bash tool calls.
func ParseBashInput ¶
ParseBashInput extracts BashInput from generic tool_input map.
type Capability ¶
type Capability int
Capability represents one of the three Rule of Two capabilities.
const ( // CapabilityA represents processing untrustworthy inputs. CapabilityA Capability = iota // CapabilityB represents access to sensitive systems or data. CapabilityB // CapabilityC represents state changes or external communication. CapabilityC )
func (Capability) String ¶
func (c Capability) String() string
String returns a human-readable name for the capability.
type CapabilityResult ¶
CapabilityResult holds the detection result for a single capability.
func DetectCapabilityA ¶
func DetectCapabilityA(toolName string, input map[string]interface{}, cwd string) CapabilityResult
DetectCapabilityA checks for untrustworthy input processing.
func DetectCapabilityB ¶
func DetectCapabilityB(toolName string, input map[string]interface{}) CapabilityResult
DetectCapabilityB checks for access to sensitive systems or data.
func DetectCapabilityC ¶
func DetectCapabilityC(toolName string, input map[string]interface{}) CapabilityResult
DetectCapabilityC checks for state changes or external communication.
type CriticalThreat ¶
type CriticalThreat struct {
Type string // "agent_config_write", "invisible_unicode"
Details string
// AllowAskMode indicates whether DASHLIGHTS_AGENTIC_MODE=ask should prompt
// instead of blocking. Agent config writes always block (false).
AllowAskMode bool
}
CriticalThreat represents a security threat that bypasses Rule of Two scoring. These are threats that warrant immediate blocking regardless of capability count.
func DetectCriticalThreat ¶
func DetectCriticalThreat(input *HookInput) *CriticalThreat
DetectCriticalThreat checks for threats that bypass Rule of Two scoring. Returns nil if no critical threat is detected.
type CursorOutput ¶
type CursorOutput struct {
Permission string `json:"permission"` // "allow", "deny", "ask"
UserMessage string `json:"user_message,omitempty"` // Shown in client
AgentMessage string `json:"agent_message,omitempty"` // Sent to agent
}
CursorOutput represents the output format expected by Cursor hooks.
type CursorShellInput ¶
type CursorShellInput struct {
ConversationID string `json:"conversation_id"`
GenerationID string `json:"generation_id"`
Model string `json:"model"`
Command string `json:"command"`
Cwd string `json:"cwd"`
HookEventName string `json:"hook_event_name"`
CursorVersion string `json:"cursor_version"`
WorkspaceRoots []string `json:"workspace_roots"`
UserEmail *string `json:"user_email"`
}
CursorShellInput represents the input format for Cursor beforeShellExecution hook.
type EditInput ¶
type EditInput struct {
FilePath string `json:"file_path"`
OldString string `json:"old_string"`
NewString string `json:"new_string"`
}
EditInput represents the tool_input for Edit tool calls.
func ParseEditInput ¶
ParseEditInput extracts EditInput from generic tool_input map.
type GlobInput ¶
GlobInput represents the tool_input for Glob tool calls.
func ParseGlobInput ¶
ParseGlobInput extracts GlobInput from generic tool_input map.
type GrepInput ¶
type GrepInput struct {
Pattern string `json:"pattern"`
Path string `json:"path,omitempty"`
Glob string `json:"glob,omitempty"`
}
GrepInput represents the tool_input for Grep tool calls.
func ParseGrepInput ¶
ParseGrepInput extracts GrepInput from generic tool_input map.
type HookInput ¶
type HookInput struct {
SessionID string `json:"session_id"`
TranscriptPath string `json:"transcript_path,omitempty"`
Cwd string `json:"cwd"`
HookEventName string `json:"hook_event_name"`
ToolName string `json:"tool_name"`
ToolInput map[string]interface{} `json:"tool_input"`
ToolUseID string `json:"tool_use_id,omitempty"`
}
HookInput represents the JSON input from Claude Code PreToolUse hook. This structure matches the JSON schema provided by Claude Code's hook system.
func ParseCursorInput ¶
ParseCursorInput parses Cursor hook input and normalizes it to HookInput.
type HookOutput ¶
type HookOutput struct {
HookSpecificOutput *HookSpecificOutput `json:"hookSpecificOutput,omitempty"`
SystemMessage string `json:"systemMessage,omitempty"`
}
HookOutput represents the JSON output for Claude Code PreToolUse hooks.
func GenerateOutput ¶
func GenerateOutput(result *AnalysisResult) (*HookOutput, int, string)
GenerateOutput creates the appropriate hook output based on analysis results. Returns (output, exitCode, stderrMessage). - exitCode 0: allow (with optional systemMessage warning) - exitCode 2: block (stderrMessage contains error)
func GenerateThreatOutput ¶
func GenerateThreatOutput(threat *CriticalThreat) (*HookOutput, int, string)
GenerateThreatOutput creates the appropriate hook output for a critical threat. Returns (output, exitCode, stderrMessage).
type HookSpecificOutput ¶
type HookSpecificOutput struct {
HookEventName string `json:"hookEventName"`
PermissionDecision string `json:"permissionDecision"`
PermissionDecisionReason string `json:"permissionDecisionReason"`
}
HookSpecificOutput contains PreToolUse-specific response fields.
type InvisibleCharInfo ¶
type InvisibleCharInfo struct {
Rune rune
Name string
Position int
Context string // surrounding characters for display
Field string // which input field contained this character
}
InvisibleCharInfo describes a detected invisible Unicode character.
type ReadInput ¶
type ReadInput struct {
FilePath string `json:"file_path"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}
ReadInput represents the tool_input for Read tool calls.
func ParseReadInput ¶
ParseReadInput extracts ReadInput from generic tool_input map.
type WebFetchInput ¶
WebFetchInput represents the tool_input for WebFetch tool calls.
func ParseWebFetchInput ¶
func ParseWebFetchInput(input map[string]interface{}) WebFetchInput
ParseWebFetchInput extracts WebFetchInput from generic tool_input map.
type WebSearchInput ¶
type WebSearchInput struct {
Query string `json:"query"`
}
WebSearchInput represents the tool_input for WebSearch tool calls.
func ParseWebSearchInput ¶
func ParseWebSearchInput(input map[string]interface{}) WebSearchInput
ParseWebSearchInput extracts WebSearchInput from generic tool_input map.
type WriteInput ¶
WriteInput represents the tool_input for Write tool calls.
func ParseWriteInput ¶
func ParseWriteInput(input map[string]interface{}) WriteInput
ParseWriteInput extracts WriteInput from generic tool_input map.