Claude/add prompt before hook 01 sab pegi wd k3 j mk2p6u4 g hx#4403
Closed
analoguezone wants to merge 11 commits into
Closed
Claude/add prompt before hook 01 sab pegi wd k3 j mk2p6u4 g hx#4403analoguezone wants to merge 11 commits into
analoguezone wants to merge 11 commits into
Conversation
This commit implements a new plugin hook `prompt.before` that fires BEFORE OpenCode sends a prompt to the LLM, enabling powerful plugin capabilities: Features: - Inspect prompt text and session context before LLM call - Override model selection dynamically based on task complexity - Inject additional context into prompts - Block prompts based on custom validation logic Implementation: - Added hook type definition in packages/plugin/src/index.ts - Integrated hook execution in packages/opencode/src/session/prompt.ts - Hook fires after agent resolution but before model selection - Plugins can modify model, add context, or block prompts Test Plugins: - PromptLoggerPlugin: Logs all prompts for debugging - ModelSwitcherPlugin: Dynamic model selection based on complexity - PromptBlockerPlugin: Content filtering and validation Example Use Cases: - Cost optimization by routing simple tasks to cheaper models - Security filtering of sensitive content - Task-specific model selection (coding vs chat) - Prompt enhancement with additional context - Rate limiting and quota management Breaking Changes: None Backward Compatible: Yes (optional hook) Resolves: Dynamic model selection requirement Related: OpenCode plugin system enhancement
…n access Implemented a user-controlled toggle for model optimization that: - Shows OPTIMIZE: ON/OFF in the status bar (bottom, next to model info) - Provides toggle command via command palette (Cmd+O) - Makes state available to plugins via prompt.before hook - Persists state across sessions to ~/.opencode/state/optimize.json Changes: - Added optimize state management to local context (TUI) - Updated status bar to display optimization state with color coding - Added toggle command to command palette under Agent category - Extended PromptInput schema to include optimizeEnabled field - Updated prompt.before hook to pass optimization state to plugins - Updated plugin types to include optimizeEnabled in input Plugins can now check input.optimizeEnabled and skip model switching when disabled, giving users full control over optimization behavior. Default state: ON (optimization enabled)
- Move wrapMode from box to text elements - Remove keybind field (not in KeybindsConfig type) - Command still accessible via command palette
Changed default keybinding for opening command palette from Ctrl+P to Ctrl+O
- Added optimize_toggle keybinding with Ctrl+O default - Reverted command_list back to Ctrl+P - Users can now press Ctrl+O to instantly toggle optimization on/off - Toggle still accessible via command palette Note: SDK types will be regenerated on next server run/build
The optimizeEnabled field was not being sent from the TUI client to the server, causing plugins to always receive true (the default fallback). Now correctly passes local.optimize.enabled to the server in the prompt request body, so plugins can properly check the user's toggle state. Note: SDK types will regenerate on next run to include optimizeEnabled field
…mization toggle Added two detailed documentation files: 1. PROMPT_BEFORE_HOOK.md - Complete hook API reference - Input/output parameters - Execution order and timing - Multiple practical examples (logger, optimizer, filter, context injector) - Best practices and performance tips - Comparison with chat.params hook - Use cases and troubleshooting 2. OPTIMIZATION_TOGGLE.md - User guide for the optimization toggle feature - Ctrl+O keybinding documentation - Status bar display explanation - When to use ON vs OFF - Plugin integration guide - Persistent state details - FAQ and troubleshooting Both docs are ready for users and plugin developers.
Created BUILD.md with complete instructions for: - Quick build (--single flag for current platform) - Full build (all platforms) - Testing the binary - Installing globally (copy, symlink, or PATH) - Build output structure - Differences between bun dev and binary - Development workflow - Troubleshooting common issues - Platform-specific notes - CI/CD integration Users can now easily build and distribute OpenCode binaries.
Collaborator
|
im not really sure what this means |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.