hookpayload

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hookpayload normalizes the hook payloads MemSpace's hook-based agents send on stdin into spool records.

Claude Code defines this payload shape; DSH's hook bridge and the omp and pi extensions reuse it, so one normalizer serves every hook-based adapter. The agent_type stored on sessions is the caller's, not the shape's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppliedFiles

func AppliedFiles(name string, toolInput map[string]any, response any, cwd string) []string

AppliedFiles is the set of files the tool actually changed.

omp's ast_edit rewrites files, directories and globs, so its input names targets, not results: a preview or a zero-replacement run changes nothing, and one glob can hit several files. Its tool response carries the applied file list, which is what MemSpace records. A write to an internal xd:// URL dispatches another tool; that tool's result is nested under tool_response.xdev.inner.sourceResultDetails, so the write's own "path" is never recorded as a changed file. Every other file tool names its single target in the input.

func FilePath

func FilePath(toolInput map[string]any) string

FilePath returns the single file a tool names in its input, when it names one directly.

func IsFileTool

func IsFileTool(name string) bool

IsFileTool reports whether a tool writes files.

func Normalize

func Normalize(agentType string, raw []byte, now time.Time, projectDir func(cwd string) string) ([]spool.Record, error)

Normalize maps one hook invocation to MemSpace events for agentType. Unknown or uninteresting hook events yield no events. projectDir resolves the directory that identifies the session's project; nil means the payload's cwd.

func NormalizeWith added in v0.1.8

func NormalizeWith(agentType string, raw []byte, now time.Time, projectDir func(cwd string) string, rules Rules) ([]spool.Record, error)

NormalizeWith is Normalize with agent-specific rules. The payload shape is the same for every hook-based agent.

func ReferencedFiles

func ReferencedFiles(name string, toolInput map[string]any, response any, cwd string) []string

ReferencedFiles is every file the tool's result mentions, including files an ast_edit preview would touch. Sensitivity checks use it so staged edits of secret files are redacted even before they are applied.

Types

type Input

type Input struct {
	SessionID            string         `json:"session_id"`
	TranscriptPath       string         `json:"transcript_path"`
	Cwd                  string         `json:"cwd"`
	HookEventName        string         `json:"hook_event_name"`
	PermissionMode       string         `json:"permission_mode"`
	Source               string         `json:"source"`
	Model                string         `json:"model"`
	Prompt               string         `json:"prompt"`
	PromptID             string         `json:"prompt_id"`
	ToolName             string         `json:"tool_name"`
	ToolInput            map[string]any `json:"tool_input"`
	ToolResponse         any            `json:"tool_response"`
	ToolUseID            string         `json:"tool_use_id"`
	Error                string         `json:"error"`
	IsInterrupt          bool           `json:"is_interrupt"`
	DurationMS           *int64         `json:"duration_ms"`
	LastAssistantMessage string         `json:"last_assistant_message"`
	Reason               string         `json:"reason"`
	Trigger              string         `json:"trigger"`
	CustomInstructions   string         `json:"custom_instructions"`
}

Input is the union of the hook payload fields MemSpace uses.

type Rules added in v0.1.8

type Rules struct {
	// ResultFilesAnyTool makes a tool result that names the files it changed
	// and states whether it applied them authoritative for every tool, not only
	// for known file tools. pi has no dispatch layer, so an extension or MCP
	// tool that rewrites several files reports them in its own result.
	ResultFilesAnyTool bool
	// ResolveInputPaths completes a file tool's own relative path with the
	// session cwd. pi's tools accept relative paths; Claude Code and omp send
	// absolute ones, so their events are unchanged.
	ResolveInputPaths bool
}

Rules are the agent-specific deviations from the shared payload rules. The zero value is what Claude Code, DSH and omp send.

Jump to

Keyboard shortcuts

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