config

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: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultListenAddr = "127.0.0.1:18980"
	DefaultTimeout    = 60 * time.Second
	DefaultLanguage   = "zh"

	DefaultOpenaceAddr            = "127.0.0.1:8765"
	DefaultOpenaceMaxOutputLength = 12000
	DefaultOpenaceTimeout         = 30 * time.Second
	DefaultOpenaceMaxRetries      = 2
	DefaultOpenaceRetryBaseDelay  = 250 * time.Millisecond
	DefaultOpenaceRetryMaxDelay   = 2 * time.Second
	DefaultOpenaceRetryJitter     = 100 * time.Millisecond

	DefaultCodexHistoryMaxMessages = 12
	DefaultCodexHistoryMaxChars    = 12000

	DefaultClaudeTranscriptMaxMessages = 12
	DefaultClaudeTranscriptMaxChars    = 12000

	DefaultDevinHistoryMaxMessages = 12
	DefaultDevinHistoryMaxChars    = 12000
	// DefaultDevinHistoryRecency bounds how recently the located Devin session
	// must have been active to be reused as context. The Devin UserPromptSubmit
	// hook carries no session id and the current prompt is not yet in the DB
	// when the hook fires, so devinhistory locates the session by working
	// directory + most-recent activity; this window prevents an abandoned older
	// session in the same directory from leaking stale history into a new one.
	// Raised 2h -> 6h (2026-07-02, user decision): with 2h the FIRST
	// continuation prompt after a same-day resume (e.g. a morning "继续 Phase 3"
	// on last night's session) kept missing history, because the just-submitted
	// prompt has not refreshed last_activity_at yet. 6h still guards against
	// genuinely abandoned sessions while covering same-day work gaps.
	DefaultDevinHistoryRecency = 6 * time.Hour

	// DefaultHookDedupWindow is the freshness window for the cross-adapter
	// single-flight de-duplication applied when a host agent (e.g. the Devin
	// CLI) aggregates UserPromptSubmit hooks from several ecosystems and fires
	// them all for one prompt. See internal/adapters/hookdedup.
	DefaultHookDedupWindow = 5 * time.Second
	DefaultHookDeadline    = 100 * time.Second

	// DefaultMaxContextTokens is the global token budget applied to every
	// outbound enhancer.Request via Options.MaxContextTokens. Zero means
	// "no budget" — enhancer.assemblePrompt skips its section-level
	// truncator entirely, matching the pre-budget behaviour. Setting a
	// positive value (via OPENPE_MAX_CONTEXT_TOKENS) lets every caller
	// path (codex / claude / windsurf hooks, future patch inject, future
	// IDE clients) share a single user-facing knob that controls the
	// total prompt size handed to the LLM provider, regardless of which
	// collector populated history / context.files / context.retrieval.
	DefaultMaxContextTokens = 0

	// DefaultUpdateCheckInterval is the freshness window for the background
	// new-version check that feeds the hook disclosure notice. The check
	// itself never runs on the enhancement critical path (it refreshes a
	// local cache out-of-band); this interval only bounds how often the
	// detached refresh may hit the module proxy.
	DefaultUpdateCheckInterval = 24 * time.Hour

	// Language guard keeps the enhanced prompt in the user's input language.
	// Enabled by default and a no-op when the languages already match (the
	// common case), so it is backward compatible. Reanchor adds one re-request
	// on a detected mismatch; disable it (OPENPE_LANGUAGE_GUARD_REANCHOR=false)
	// for latency-sensitive setups, in which case the guard only warns.
	DefaultLanguageGuardEnabled  = true
	DefaultLanguageGuardReanchor = true
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaudeConfig

type ClaudeConfig struct {
	Transcript ClaudeTranscriptConfig
}

type ClaudeTranscriptConfig

type ClaudeTranscriptConfig struct {
	Enabled     bool
	MaxMessages int
	MaxChars    int
}

type CodexConfig

type CodexConfig struct {
	History CodexHistoryConfig
}

type CodexHistoryConfig

type CodexHistoryConfig struct {
	Enabled     bool
	Home        string
	MaxMessages int
	MaxChars    int
}

type Config

type Config struct {
	BaseURL    string
	APIKey     string
	Model      string
	ListenAddr string
	Timeout    time.Duration
	Language   string
	// MaxContextTokens is the consumer-layer global token budget. Each
	// caller path (codex / claude / windsurf hook, future patch inject)
	// forwards this value into enhancer.Request.Options.MaxContextTokens,
	// where enhancer.assemblePrompt applies section-level truncation
	// preserving required sections (original prompt, target client,
	// workspace, enhancement contract, final instruction) and shrinking
	// optional sections (history, rules, guidelines, context.files,
	// context.retrieval). Zero (the default) keeps the historical
	// "no budget" behaviour so this field is purely additive.
	MaxContextTokens int
	// MessageStyle selects the provider message layout: "flatten" (default —
	// [system, user] with history embedded as labeled text) or "hybrid"
	// ([system, prior user/assistant turns, final user task]). Sourced from
	// OPENPE_MESSAGE_STYLE. Unknown values fall back to "flatten" so the
	// historical, eval-validated layout stays the default until hybrid is
	// promoted by eval A/B.
	MessageStyle string
	// Provider selects the model provider wire protocol: "openai" (default,
	// OpenAI-compatible /v1/chat/completions) or "anthropic" (Anthropic Messages
	// API /v1/messages). Sourced from OPENPE_PROVIDER; unknown/empty → "openai"
	// so existing setups are unaffected.
	Provider string
	// MaxTokens caps the model's response length. It is required by the
	// Anthropic provider and ignored by the OpenAI one (which lets the gateway
	// default). Sourced from OPENPE_MAX_TOKENS; 0 (default) lets the provider
	// pick its own default.
	MaxTokens int
	// SystemPrompt, when non-empty, overrides the enhancer's built-in system
	// prompt. It is populated from OPENPE_SYSTEM_PROMPT_FILE (file contents,
	// preferred) or OPENPE_SYSTEM_PROMPT (inline). Empty (the default) keeps
	// the compiled-in enhancer.defaultSystemPrompt, so this field is purely
	// additive and lets operators iterate on the prompt without recompiling.
	SystemPrompt string
	// PromptStyle selects a built-in system-prompt preset by audience:
	// "agent" (default — compact prompt for the downstream coding agent) or
	// "human" (detailed report-style expansion for human reading; the
	// former v7h default kept verbatim). Sourced from OPENPE_PROMPT_STYLE.
	// An explicit SystemPrompt overrides it. The raw value is validated at
	// service construction (enhancer.ResolveSystemPrompt), where an unknown
	// style fails startup loudly instead of silently degrading to a default.
	PromptStyle string
	// LanguageGuard configures the enhancer's post-processing language-
	// preservation guard (see internal/enhancer.LanguageGuardConfig). Sourced
	// from OPENPE_LANGUAGE_GUARD_ENABLED / OPENPE_LANGUAGE_GUARD_REANCHOR.
	LanguageGuard LanguageGuardConfig
	// Warnings configures the deterministic output-side advisory checks
	// (out-of-context numbers / undecided irreversible actions — the
	// model-independent backstop behind the v7g/v7h prompt guardrails).
	// Sourced from OPENPE_WARNINGS_ENABLED (default true),
	// OPENPE_WARNINGS_ACTIONS (comma-separated extra action words) and
	// OPENPE_WARNINGS_NUM_MAXLEN (digit-run length cap, default 5).
	Warnings WarningsConfig
	// Specs configures explicit user prompt-spec loading (`pe+<name> <task>`).
	// Dir empty means the per-user default ~/.config/openpe/specs (resolved by
	// internal/specs.DefaultDir, kept out of this package like the other
	// mirror configs); MaxChars <= 0 means the specs package default.
	Specs SpecsConfig
	// Update configures the new-version notice and its background check
	// (docs/requirements/2026-08-25-version-and-update.md U2). Notice
	// defaults to true; the actual `openpe update` command is always
	// available regardless of this switch.
	Update       UpdateConfig
	Openace      OpenaceConfig
	Codex        CodexConfig
	Claude       ClaudeConfig
	Devin        DevinConfig
	Inject       InjectConfig
	Delivery     DeliveryConfig
	Server       ServerConfig
	HookDedup    HookDedupConfig
	HookDeadline time.Duration
}

func Load

func Load() Config

type DeliveryConfig

type DeliveryConfig struct {
	CacheDir               string
	CopyCommand            string
	DisableOSC52Clipboard  bool
	OSC52TTY               string
	ClaudePromptFallback   bool
	WindsurfPromptFallback bool
}

type DevinConfig

type DevinConfig struct {
	History DevinHistoryConfig
}

type DevinHistoryConfig

type DevinHistoryConfig struct {
	Enabled     bool
	DBPath      string
	MaxMessages int
	MaxChars    int
	Recency     time.Duration
}

DevinHistoryConfig controls reading the current Devin CLI session from its local SQLite store (~/.local/share/devin/cli/sessions.db) to populate enhancer.Request.History. DBPath empty means the devinhistory collector resolves the platform default. Recency bounds reuse of the located session.

type HookDedupConfig

type HookDedupConfig struct {
	Enabled bool
	Window  time.Duration
}

HookDedupConfig controls the cross-adapter single-flight de-duplication that prevents a host agent which aggregates hooks from multiple ecosystems (the Devin CLI loads its own, Claude Code, and Windsurf hooks at once) from enhancing the same prompt several times. Enabled by default; the window is the claim freshness used by internal/adapters/hookdedup.

type InjectConfig

type InjectConfig struct {
	Codex  bool
	Claude bool
	Devin  bool
}

InjectConfig is the resolved per-client silent-injection switch. The global default OPENPE_HOOK_INJECT (default false = review + clipboard, preserving openPE's "never auto-apply" philosophy) is overridden per client by OPENPE_<CLIENT>_INJECT. Windsurf cannot ingest hook-provided context, so it has no field here — the switch is a documented no-op there.

type LanguageGuardConfig

type LanguageGuardConfig struct {
	Enabled  bool
	Reanchor bool
}

LanguageGuardConfig is the config-layer mirror of enhancer.LanguageGuardConfig. cmd maps between the two, keeping internal/config free of an enhancer import (consistent with MessageStyle).

type OpenaceConfig

type OpenaceConfig struct {
	Enabled           bool
	Addr              string
	Token             string
	ProviderProfileID string
	MaxOutputLength   int
	Timeout           time.Duration
	MaxRetries        int
	RetryBaseDelay    time.Duration
	RetryMaxDelay     time.Duration
	RetryJitter       time.Duration
}

type ServerConfig

type ServerConfig struct {
	// Token, when non-empty, enables bearer-token authentication on the
	// HTTP server. Use a 256-bit hex string (e.g. produced by
	// integration.GenerateToken). When LifecycleEnabled is true and Token
	// is empty, openpe-server generates an ephemeral token at startup.
	Token string
	// CORSOrigins is the list of Origin headers the server reflects in
	// Access-Control-Allow-Origin. Comma-separated in env / .env. Special
	// values: "*" allows any origin, "null" allows Electron file:// webviews.
	CORSOrigins []string
	// LifecycleEnabled controls whether openpe-server writes a descriptor
	// file at startup so IDE installers can discover its base URL and token.
	// Default false — opt in only when integrating with a patch installer
	// (Windsurf, Cursor, ...). Enabling auto-generates an ephemeral token
	// when Token is empty.
	LifecycleEnabled bool
	// DescriptorFile overrides integration.DefaultDescriptorPath when set.
	// Only consulted when LifecycleEnabled is true.
	DescriptorFile string
}

ServerConfig collects HTTP server runtime options that are independent of the prompt enhancement core. Empty fields preserve the historical default behaviour (no authentication, no CORS, no lifecycle hooks).

type SpecsConfig

type SpecsConfig struct {
	Dir      string
	MaxChars int
}

SpecsConfig is the config-layer mirror of the internal/specs loader knobs (kept apart so config does not import the specs package, consistent with LanguageGuardConfig / WarningsConfig). Sourced from OPENPE_SPECS_DIR and OPENPE_SPEC_MAX_CHARS.

type UpdateConfig

type UpdateConfig struct {
	Notice        bool
	CheckInterval time.Duration
}

UpdateConfig mirrors the internal/update knobs (kept apart so config does not import the update package, consistent with the other mirror configs). Sourced from OPENPE_UPDATE_NOTICE and OPENPE_UPDATE_CHECK_INTERVAL.

type WarningsConfig

type WarningsConfig struct {
	Enabled      bool
	ExtraActions []string
	NumMaxLen    int
}

WarningsConfig is the config-layer mirror of enhancer.ContentWarningsConfig (kept apart so config does not import the enhancer package). Enabled defaults to true: the checks are advisory-only (never rewrite or block), so they are safe on by default.

Jump to

Keyboard shortcuts

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