Commit Graph

25 Commits

Author SHA1 Message Date
Ed Zynda 63704f55b5 godoc 2025-11-12 16:48:46 +03:00
Ed Zynda d3f9759eb4 refactor debug messages 2025-08-08 09:32:04 +03:00
Ed Zynda fe4db1998d feat: add --tls-skip-verify flag for self-signed certificates (#115)
* feat: add --tls-skip-verify flag for self-signed certificates

Adds support for skipping TLS certificate verification when connecting to
providers with self-signed certificates. This is particularly useful for
local Ollama instances secured with HTTPS.

- Add --tls-skip-verify command-line flag with security warnings
- Update ProviderConfig to include TLSSkipVerify field
- Modify HTTP client creation for all providers (Ollama, OpenAI, Anthropic, Google, Azure)
- Create helper functions for TLS-aware HTTP client creation
- Add comprehensive unit tests for TLS skip verify functionality
- Update documentation with usage examples and security warnings

Fixes #113

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

* feat: add TLS skip verify support to script mode

- Add TLSSkipVerify field to Config struct for script frontmatter
- Update script parsing to handle tls-skip-verify in YAML frontmatter
- Pass TLS configuration to model creation in script mode
- Add example script demonstrating TLS skip verify usage
- Update script examples documentation

This allows scripts to specify tls-skip-verify: true in their frontmatter
to connect to providers with self-signed certificates.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

---------

Co-authored-by: opencode <noreply@opencode.ai>
2025-08-05 17:00:58 +03:00
Ed Zynda cdc4abfb36 Add comprehensive hooks system for MCPHost lifecycle events (#111)
* Add comprehensive hooks system for MCPHost lifecycle events

Implements a flexible hooks system based on Anthropic Claude Code specification:

- **Hook Events**: PreToolUse, PostToolUse, UserPromptSubmit, Stop
- **Hook Types**: Command execution with JSON input/output
- **Configuration**: XDG-compliant with layered config support
- **Security**: Command validation, timeout controls, safe execution
- **Common Fields**: Consistent session ID, timestamps, model info across all hooks

Key features:
- Hooks receive JSON via stdin and can control flow via stdout
- Pattern matching for tool-specific hooks (regex support)
- Enhanced Stop hook with agent response and metadata
- Centralized session management with consistent IDs
- Built-in examples for logging, validation, and monitoring

This enables users to:
- Log and audit all tool usage and prompts
- Implement custom security policies
- Track usage metrics and model performance
- Integrate with external systems
- Build custom workflows around MCPHost

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

* Enable hooks in script mode

Previously, hooks were only initialized and executed in normal mode but not
in script mode. This was because script mode had its own execution path that
bypassed the hook initialization code.

This fix:
- Adds hook initialization to runScriptMode function
- Creates hook executor with proper session ID and model info
- Passes the hook executor to runAgenticLoop

Now hooks work consistently across all execution modes (normal, script, and
interactive), ensuring uniform behavior for logging, validation, and monitoring.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

* Remove unnecessary hooks.local.yml pattern

The .local.yml pattern adds unnecessary complexity. Users who want project-specific
hooks that aren't committed to git can simply add .mcphost/ to their .gitignore.

This simplifies the hooks configuration loading and makes it clearer that:
- Global user hooks go in ~/.config/mcphost/hooks.yml
- Project-specific hooks go in .mcphost/hooks.yml
- Git ignore management is left to the user

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

* Fix hooks test isolation and add --no-hooks flag

- Fix TestLoadHooksConfig by setting temporary XDG_CONFIG_HOME to prevent loading global hooks
- Add --no-hooks flag to disable all hooks execution across all modes
- Update README with documentation for the new flag
- Add test to verify hooks loading behavior

This allows users to temporarily disable hooks for security or debugging purposes.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

---------

Co-authored-by: opencode <noreply@opencode.ai>
2025-07-24 13:56:33 +03:00
Ed Zynda df9337d085 fix script frontmatter parsing 2025-07-15 14:27:58 +03:00
Ed Zynda df29dc1673 fix frontmatter parsing 2025-07-09 12:58:16 +03:00
Ed Zynda 4f524d3b16 Fix compact mode in scripts 2025-06-28 14:36:35 +03:00
Ed Zynda ddd7856f9b Refactor: Extract shared code between normal and script modes (#94)
This commit addresses issue #92 by extracting duplicated code between
normal mode (cmd/root.go) and script mode (cmd/script.go) into reusable
factory functions and utilities.

## Changes Made

### New Factory Files
- **internal/agent/factory.go**: Agent creation factory with spinner support
  - `CreateAgent()` function with configurable options
  - `ParseModelName()` utility for model string parsing
  - Spinner function injection to avoid import cycles

- **internal/ui/factory.go**: CLI setup factory with standard configuration
  - `SetupCLI()` function for consistent CLI initialization
  - Usage tracking setup for supported providers
  - Model info and tool count display

- **internal/config/merger.go**: Config loading and merging utilities
  - `LoadAndValidateConfig()` for standard config loading
  - `MergeConfigs()` for script frontmatter merging

### Updated Command Files
- **cmd/root.go**: Refactored to use new factories
  - Replaced ~50 lines of agent creation logic
  - Replaced ~30 lines of CLI setup logic
  - Replaced ~20 lines of config loading logic
  - Added agentUIAdapter to handle interface compatibility

- **cmd/script.go**: Refactored to use new factories
  - Same factory usage as normal mode for consistency
  - Maintained script-specific behavior (no spinners)
  - Improved config merging with frontmatter

## Benefits
- **Reduced code duplication**: ~33 lines of duplicated code eliminated
- **Single source of truth**: Agent creation and CLI setup logic centralized
- **Consistent behavior**: Both modes now use identical underlying logic
- **Easier maintenance**: Changes apply to both modes automatically
- **Better testability**: Factory functions can be unit tested independently
- **Cleaner command files**: Focus on mode-specific logic only

## Testing
- All existing tests pass
- Build verification successful
- Both normal and script modes tested for basic functionality
- Code formatting and linting checks passed

🤖 Generated with [opencode](https://opencode.ai)

Co-authored-by: opencode <noreply@opencode.ai>
2025-06-27 17:41:18 +03:00
Ed Zynda 47718a7fed stream in script mode 2025-06-27 16:40:42 +03:00
Ed Zynda 00aa3c6995 Env substitution (#93)
* compact mode

* tweaks

* tweaks

* tweaks

* fix streaming in tool calls

* impl env sub

* fix
2025-06-27 16:30:18 +03:00
Ed Zynda 76dd18030a Compact mode (#91)
* compact mode

* tweaks

* tweaks

* tweaks

* fix streaming in tool calls
2025-06-27 15:56:09 +03:00
Ed Zynda e5b6e7e123 convert to newer config format automatically 2025-06-25 10:58:14 +03:00
Ed Zynda 3fcee53836 enhanced script vars 2025-06-24 17:44:26 +03:00
Ed Zynda 7686577d9a fix config 2025-06-19 17:48:47 +03:00
Ed Zynda 34ea275a0c cleanup 2025-06-18 09:41:36 +03:00
Ed Zynda 1a5d4ccf8a consolidate 2025-06-17 23:09:29 +03:00
Ed Zynda 354e8a09fb fix config/flags in script 2025-06-17 22:03:21 +03:00
Ed Zynda d273436091 refactor 2025-06-17 20:54:18 +03:00
Ed Zynda 798b1ede0e --no-exit in script mode 2025-06-16 17:49:27 +03:00
Ed Zynda d4910a9164 --no-exit 2025-06-16 17:35:01 +03:00
Ed Zynda 5ac43f1646 fix settings in scripts for real 2025-06-15 14:42:17 +03:00
Ed Zynda 4b23623270 fix settings in scripts 2025-06-15 14:33:41 +03:00
Ed Zynda 42eb398148 format 2025-06-11 13:09:51 +03:00
Ed Zynda 306fbdb3d0 Standardize (#67)
* Model generation params

* Standardize model URL

* standardize more flags and update max steps check

* fix system prompt handling

* standardize api key handling

* update readme
2025-06-11 11:45:55 +03:00
Ed Zynda e0c20348b4 Scripting (#66)
* Move script to separate command

* Improve scripting

* cleanup

* cleanup

* Arg validation
2025-06-11 10:26:52 +03:00