Documentation
¶
Index ¶
- func ApplyTargetPlan(plan TargetPlan) error
- func BuildExecutionSpec(target harness.Target, hook Hook, event Event, context RenderContext, ...) (string, error)
- func CandidateToolNames(raw string) []string
- func CheckSupport(target harness.Target, hook Hook, support Support, output *RenderOutput, ...) (bool, error)
- func Executable() string
- func ExecutableCommand() string
- func ExtractJSONObject(text string) (any, error)
- func ExtractToolName(value any) string
- func GuidanceAdditionalContext(body string) map[string]any
- func GuidanceAdditionalContextContinue(body string) map[string]any
- func GuidanceHookSpecific(body string, event Event) map[string]any
- func HandlerObject(hook Hook, includeExtra bool) map[string]any
- func HookAssetRoot(target harness.Target, root string) string
- func HookDispatchCommand(target harness.Target, event Event, specsRoot string) string
- func HookExecCommand(kind HandlerKind, target harness.Target, specPath string) string
- func HookOutput(target harness.Target, event Event, result Result) any
- func LooksLikeCursor(value any) bool
- func MatcherMatches(matcher string, candidates []string) bool
- func PushDiagnostic(output *RenderOutput, level string, hook Hook, message string)
- func SpecPath(target harness.Target, root string, hook Hook) string
- func StageOriginPackages(bundle Bundle, target harness.Target, targetRoot string, ...) (map[string]string, error)
- func StrictMappingError(target harness.Target, hook Hook, reason string) error
- func WriteRenderedFiles(output RenderOutput) error
- type Bundle
- func Collect(projectRoot string, lock lockfile.PackLock, seededCodexHooks string, ...) (Bundle, error)
- func ParseCodex(sourcePath string, value any, base Origin) (Bundle, error)
- func ParseCursor(sourcePath string, value any, base Origin) (Bundle, error)
- func ParseNested(sourcePath string, value any, base Origin) (Bundle, error)
- type CommandOutput
- type Decision
- type Diagnostic
- type Dialect
- type DispatchArgs
- type DispatchOutcome
- type Event
- type ExecutionSpec
- type Handler
- type HandlerKind
- type Hook
- type Layer
- type Origin
- type OriginInput
- type PlannedFile
- type RenderContext
- type RenderOutput
- type RenderSummary
- type RenderedFile
- type Renderer
- type Result
- func NormalizeResponse(value any) Result
- func RunAgent(ctx context.Context, spec ExecutionSpec, stdin []byte) (Result, error)
- func RunHTTP(ctx context.Context, client *http.Client, spec ExecutionSpec, stdin []byte) (Result, error)
- func RunPrompt(ctx context.Context, spec ExecutionSpec, stdin []byte) (Result, error)
- type Support
- type SupportKind
- type TargetPlan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTargetPlan ¶ added in v0.9.0
func ApplyTargetPlan(plan TargetPlan) error
func BuildExecutionSpec ¶
func BuildExecutionSpec(target harness.Target, hook Hook, event Event, context RenderContext, output *RenderOutput) (string, error)
func CandidateToolNames ¶
func CheckSupport ¶
func Executable ¶
func Executable() string
Executable is the agentpack binary a staged hook runs: the absolute path of the one that is staging, so that the hook does not depend on what the name `agentpack` resolves to on the agent's PATH (nothing, or another version). A test binary has no hook-exec; there the bare name is kept.
func ExecutableCommand ¶
func ExecutableCommand() string
ExecutableCommand is Executable as a word of a shell command line.
func ExtractJSONObject ¶
func ExtractToolName ¶
func HookDispatchCommand ¶
func HookExecCommand ¶
func HookExecCommand(kind HandlerKind, target harness.Target, specPath string) string
func LooksLikeCursor ¶
LooksLikeCursor reports whether a hooks file found at a default location is in Cursor's format: it names Cursor events and no Claude Code event.
func MatcherMatches ¶
func PushDiagnostic ¶
func PushDiagnostic(output *RenderOutput, level string, hook Hook, message string)
func StageOriginPackages ¶
func StrictMappingError ¶
func WriteRenderedFiles ¶
func WriteRenderedFiles(output RenderOutput) error
Types ¶
type Bundle ¶
type Bundle struct {
Hooks []Hook `json:"hooks,omitempty"`
// Skipped names what a hook file holds that was not read: an event no
// agent documents, a handler type agentpack cannot run, a file that does
// not parse. The rest of the package is unaffected.
Skipped []Diagnostic `json:"-"`
}
func ParseCursor ¶
ParseCursor reads a Cursor hooks file: {"version": 1, "hooks": {"<event>": [{"command": "...", "matcher": "...", ...}]}}, with camelCase event names and one flat entry per hook.
func (Bundle) ForTarget ¶
ForTarget keeps, for each package, the hooks of one dialect: the target's own when the package publishes hooks for that agent, otherwise Claude Code's, then Cursor's, then Codex's. A package that ships a hook file per agent would otherwise run every one of them on each agent.
type CommandOutput ¶
func RunCommand ¶
func RunCommand(ctx context.Context, spec ExecutionSpec, stdin []byte) (CommandOutput, error)
type Diagnostic ¶
type Diagnostic struct {
Level, Source, Message string
}
type Dialect ¶
type Dialect string
Dialect says which agent's hook file a hook was published in. The handler reads that agent's input and writes that agent's output.
type DispatchArgs ¶
type DispatchOutcome ¶
func Dispatch ¶
func Dispatch(ctx context.Context, arguments DispatchArgs) (DispatchOutcome, error)
type Event ¶
type Event string
const ( PreToolUse Event = "PreToolUse" PostToolUse Event = "PostToolUse" UserPromptSubmit Event = "UserPromptSubmit" Stop Event = "Stop" SubagentStop Event = "SubagentStop" SessionStart Event = "SessionStart" SessionEnd Event = "SessionEnd" PreCompact Event = "PreCompact" Notification Event = "Notification" PermissionRequest Event = "PermissionRequest" )
Events that Claude Code and Cursor both have, under their Claude Code names.
func ParseCursorEvent ¶
ParseCursorEvent reads an event name of a Cursor hooks file.
func ParseEvent ¶
ParseEvent reads an event as a hook file or the hook-exec command line names it: a Claude Code event, its dashed alias, or a Cursor event.
func (Event) CursorName ¶
CursorName is the event's name in a Cursor hooks file, when Cursor has it.
type ExecutionSpec ¶
type ExecutionSpec struct {
Target harness.Target `json:"target"`
Event Event `json:"event"`
Handler Handler `json:"handler"`
WorkingDir string `json:"working_dir"`
Matcher string `json:"matcher,omitempty"`
}
func LoadExecutionSpec ¶
func LoadExecutionSpec(path string) (ExecutionSpec, error)
type Handler ¶
type Handler struct {
Kind HandlerKind
Command string
// Args makes a command hook exec-form, as Claude Code writes it: Command
// is the program and Args its arguments, run without a shell.
Args []string
Timeout *uint64
URL string
Method string
Headers map[string]string
Body any
Prompt string
Agent string
Model string
}
func (Handler) MarshalJSON ¶
MarshalJSON preserves the externally tagged representation used by hook execution specs.
func (*Handler) UnmarshalJSON ¶
type HandlerKind ¶
type HandlerKind string
const ( CommandHandler HandlerKind = "command" HTTPHandler HandlerKind = "http" PromptHandler HandlerKind = "prompt" AgentHandler HandlerKind = "agent" )
type Hook ¶
type Hook struct {
Event Event `json:"event"`
Dialect Dialect `json:"dialect,omitempty"`
Matcher string `json:"matcher,omitempty"`
Handler Handler `json:"handler"`
Origin Origin `json:"origin"`
MatcherGroupExtra map[string]any `json:"matcher_group_extra,omitempty"`
RawExtra map[string]any `json:"raw_extra,omitempty"`
}
type Origin ¶
type Origin struct {
Layer Layer `json:"layer"`
Module string `json:"module"`
CacheKey string `json:"cache_key,omitempty"`
SourceRelative string `json:"source_rel"`
SourceRoot string `json:"source_root"`
SourceFile string `json:"source_file"`
SourceDigest string `json:"source_digest,omitempty"`
PackageKey string `json:"package_key"`
EventIndex int `json:"event_index"`
MatcherGroupIndex int `json:"matcher_group_index"`
HookIndex int `json:"hook_index"`
}
func (Origin) SourcePackage ¶
SourcePackage identifies the package (or layer) a hook came from.
type OriginInput ¶ added in v0.9.0
type OriginInput struct{ Path, Digest string }
type PlannedFile ¶ added in v0.9.0
func PlanOriginPackages ¶ added in v0.9.0
func SerializeRenderedFiles ¶ added in v0.9.0
func SerializeRenderedFiles(output RenderOutput) ([]PlannedFile, error)
type RenderContext ¶
type RenderOutput ¶
type RenderOutput struct {
Files []RenderedFile
Diagnostics []Diagnostic
Summary RenderSummary
}
type RenderSummary ¶
type RenderSummary struct{ Native, Emulated, Degraded, Omitted int }
type RenderedFile ¶
type Renderer ¶
type Renderer interface {
Target() harness.Target
Render(Bundle, RenderContext) (RenderOutput, error)
}
type Result ¶
type Result struct {
Decision Decision `json:"decision"`
Message string `json:"message,omitempty"`
AdditionalContext string `json:"additional_context,omitempty"`
UpdatedInput any `json:"updated_input,omitempty"`
UpdatedToolOutput any `json:"updated_tool_output,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
func NormalizeResponse ¶
type Support ¶
type Support struct {
Kind SupportKind
Reason string
}
type SupportKind ¶
type SupportKind string
const ( Native SupportKind = "native" Emulated SupportKind = "emulated" Degraded SupportKind = "degraded" Unsupported SupportKind = "unsupported" )
type TargetPlan ¶ added in v0.9.0
type TargetPlan struct {
Target harness.Target
Files []PlannedFile
Diagnostics []Diagnostic
Summary RenderSummary
Skipped []Diagnostic
Hooks []Hook
Inputs []OriginInput
}
func PlanTarget ¶ added in v0.9.0
func PlanTarget(bundle Bundle, target harness.Target, renderer Renderer, context RenderContext, effective mode.Effective) (TargetPlan, error)
PlanTarget computes the exact support and rendered hook files for a target. The caller supplies the same renderer/context that staging will use.
func (TargetPlan) Validate ¶ added in v0.9.0
func (plan TargetPlan) Validate() error