codex

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModePreview = manual.ModePreview
)
View Source
const UserPromptSubmit = "UserPromptSubmit"

Variables

This section is empty.

Functions

func AdditionalContext

func AdditionalContext(enhanced string) string

func EncodeHookOutput

func EncodeHookOutput(w io.Writer, output HookOutput) error

func EncodeHookOutputOrFallback

func EncodeHookOutputOrFallback(w io.Writer, output HookOutput) int

func HasOpenPEHookConfig

func HasOpenPEHookConfig(path string) bool

func HasUserOpenPEHookConfig

func HasUserOpenPEHookConfig() bool

func HookCommand

func HookCommand(bin string, envFile string) string

func HookCommandForScope

func HookCommandForScope(bin string, envFile string, scope string) string

func HooksConfigContainsOpenPEHook

func HooksConfigContainsOpenPEHook(data []byte) bool

func IsOpenPEHookCommand

func IsOpenPEHookCommand(command string) bool

func LastPreviewPath

func LastPreviewPath() (string, error)

func LastPromptPath

func LastPromptPath() (string, error)

func MarkdownPreview

func MarkdownPreview(enhanced string, language string) string

func MergeHooksConfig

func MergeHooksConfig(existing []byte, command string, timeout int) ([]byte, error)

func PreviewReason

func PreviewReason(cachePath string, language string) string

func ProjectEnvFile

func ProjectEnvFile(cwd string) string

func ProjectHooksPath

func ProjectHooksPath(cwd string) string

func ReadLastPreview

func ReadLastPreview() (string, error)

func ReadLastPrompt

func ReadLastPrompt() (string, error)

func SavePreview

func SavePreview(enhanced string, language string) (string, error)

func ShouldHandleHook

func ShouldHandleHook(input HookInput, auto bool) (bool, bool)

func ShouldSkipDuplicateHook

func ShouldSkipDuplicateHook(scope string, envFile string, cwd string) bool

func UserHooksPath

func UserHooksPath() string

func WriteTerminalPreview

func WriteTerminalPreview(content string) error

Types

type HookInput

type HookInput struct {
	HookEventName string `json:"hook_event_name"`
	Prompt        string `json:"prompt"`
	CWD           string `json:"cwd"`
}

func DecodeHookInput

func DecodeHookInput(r io.Reader) (HookInput, error)

type HookOptions

type HookOptions struct {
	Client   string
	Mode     string
	Auto     bool
	CWD      string
	Prompt   string
	Language string
	Timeout  time.Duration
	History  []enhancer.Message
	// Inject makes a manual `pe` trigger inject the enhanced prompt as
	// additional context (exit 0, hookSpecificOutput.additionalContext) instead
	// of holding the original with a clipboard/preview review. Codex CLI
	// consumes UserPromptSubmit additionalContext into the model context, so
	// this is a real injection there. Default false preserves the review model.
	Inject bool
	// MaxContextTokens forwards the consumer-layer global token budget
	// (config.Config.MaxContextTokens, sourced from
	// OPENPE_MAX_CONTEXT_TOKENS) into enhancer.Request.Options. Zero
	// means "no budget" so this field is purely additive — callers that
	// do not set it preserve the historical unbounded behaviour.
	MaxContextTokens int
	CacheDir         string
	// SpecsDir / SpecMaxChars configure explicit user prompt-spec loading
	// (`pe+<name> <task>`, config.Config.Specs). Empty dir means the per-user
	// default ~/.config/openpe/specs; MaxChars <= 0 means the specs package
	// default. Spec resolution failures BLOCK the enhancement (business
	// contract D7: never silently drop a user-named spec).
	SpecsDir     string
	SpecMaxChars int
}

type HookOutput

type HookOutput struct {
	Continue           bool                `json:"continue,omitempty"`
	Decision           string              `json:"decision,omitempty"`
	Reason             string              `json:"reason,omitempty"`
	SystemMessage      string              `json:"systemMessage,omitempty"`
	HookSpecificOutput *HookSpecificOutput `json:"hookSpecificOutput,omitempty"`
	TerminalPreview    string              `json:"-"`
	PreviewPrompt      string              `json:"-"`
	// Warnings carries enhancer.Response.Warnings (out-of-context numbers /
	// undecided actions / language guard) so the runner folds them into the
	// user-facing disclosure before the user acts on the enhancement. Not part
	// of the wire JSON.
	Warnings []string `json:"-"`
	// AppliedSpecs lists the user spec names appended to the enhanced prompt
	// (`pe+<name>`), so the runner can disclose "applied specs: …" alongside
	// the delivery status. Not part of the wire JSON.
	AppliedSpecs []string `json:"-"`
}

func Block

func Block(reason string) HookOutput

func BlockPreview

func BlockPreview(reason string, terminalPreview string, previewPrompt string) HookOutput

func HandleHook

func HandleHook(ctx context.Context, service *enhancer.Service, input HookInput, opts HookOptions) (HookOutput, error)

func HookError

func HookError(manual bool, message string, language string) HookOutput

func Skip

func Skip(message string) HookOutput

type HookSpecificOutput

type HookSpecificOutput struct {
	HookEventName     string `json:"hookEventName"`
	AdditionalContext string `json:"additionalContext,omitempty"`
}

type Mode

type Mode = manual.Mode

func ParseManualEnhance

func ParseManualEnhance(prompt string) (string, []string, Mode, bool)

Jump to

Keyboard shortcuts

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