hookctx

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookContentUpdate

type HookContentUpdate struct {
	OldString string `json:"old_str"`
	NewString string `json:"new_str"`
}

type HookInput

type HookInput struct {
	SessionID             string            `json:"session_id"`
	TranscriptPath        string            `json:"transcript_path"`
	Cwd                   string            `json:"cwd"`
	PermissionMode        string            `json:"permission_mode"`
	HookEventName         string            `json:"hook_event_name"`
	ToolName              string            `json:"tool_name"`
	ToolInput             HookToolInput     `json:"-"`
	ToolInputRaw          json.RawMessage   `json:"tool_input"`
	PermissionSuggestions []json.RawMessage `json:"permission_suggestions"`
}

func (HookInput) MetricsFields added in v0.4.2

func (h HookInput) MetricsFields() (command, filePath, path, pattern string)

MetricsFields returns the subset of tool_input recorded in metrics. Only command/file_path/path/pattern are exposed; description, content, content_updates and the raw JSON are intentionally omitted to keep metrics compact and avoid leaking descriptive or file-body text.

func (HookInput) ToolInputText

func (h HookInput) ToolInputText() string

ToolInputText returns a textual representation of the tool input for path extraction.

func (*HookInput) UnmarshalJSON

func (h *HookInput) UnmarshalJSON(data []byte) error

type HookToolInput

type HookToolInput struct {
	Command        string              `json:"command"`
	Description    string              `json:"description"`
	FilePath       string              `json:"file_path"`
	Path           string              `json:"path"`
	Pattern        string              `json:"pattern"`
	Content        string              `json:"content"`
	ContentUpdates []HookContentUpdate `json:"content_updates"`
}

type PermissionContext

type PermissionContext struct {
	Cwd                 string   `json:"cwd"`
	RepoRoot            string   `json:"repo_root,omitempty"`
	GitDir              string   `json:"git_dir,omitempty"`
	GitCommonDir        string   `json:"git_common_dir,omitempty"`
	PrimaryCheckoutRoot string   `json:"primary_checkout_root,omitempty"`
	BranchName          string   `json:"branch_name,omitempty"`
	IsWorktree          bool     `json:"is_worktree"`
	ReferencedPaths     []string `json:"referenced_paths,omitempty"`
}

func BuildPermissionContext

func BuildPermissionContext(input HookInput) PermissionContext

BuildPermissionContext gathers git repository context for the given hook input.

type RecentTranscript

type RecentTranscript struct {
	UserMessages    []string `json:"user_messages,omitempty"`
	RecentToolCalls []string `json:"recent_tool_calls,omitempty"`
}

RecentTranscript holds recent user messages and tool operations from the session transcript.

func LoadRecentTranscript

func LoadRecentTranscript(path string) (RecentTranscript, error)

LoadRecentTranscript reads the tail of the transcript JSONL and extracts the most recent user messages and tool call summaries.

type SettingsPermissions

type SettingsPermissions struct {
	Allow []string `json:"allow,omitempty"`
	Deny  []string `json:"deny,omitempty"`
}

func LoadSettingsPermissions

func LoadSettingsPermissions(cwd string) SettingsPermissions

LoadSettingsPermissions reads permissions from settings.json files. File-not-found errors are expected and silently ignored. JSON parse errors are logged as warnings but do not fail the operation.

Jump to

Keyboard shortcuts

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