Modernize provider support
This commit is contained in:
@@ -44,7 +44,7 @@ python -m cmdforge.cli # Alternative CLI invocation
|
||||
- **runner.py**: Execution engine. Runs tool steps sequentially, handles variable substitution (`{input}`, `{varname}`), executes Python code steps via `exec()`, handles nested tool calls with depth limit (MAX_TOOL_DEPTH=10)
|
||||
- **resolver.py**: Tool resolution. `resolve_tool()` searches: project manifest → local tools → owner/name → registry. Returns `ResolvedTool` with path info
|
||||
- **collection.py**: Collection management (`Collection` dataclass, `resolve_tool_references()`, `classify_tool_reference()`), local collection storage in `~/.cmdforge/collections/`
|
||||
- **providers.py**: Provider abstraction. Calls AI CLI tools via subprocess, reads provider configs from `~/.cmdforge/providers.yaml`
|
||||
- **providers.py**: Provider abstraction. Supports subprocess CLI tools, OpenAI-compatible HTTP APIs, and experimental PTY wrappers. Auto-discovers installed providers on first run. Config in `~/.cmdforge/providers.yaml` with versioned migration.
|
||||
- **profiles.py**: AI persona profiles with system prompts, stored in `~/.cmdforge/profiles/`
|
||||
- **manifest.py**: Project manifest (`cmdforge.yaml`) for declaring tool dependencies with version constraints
|
||||
- **lockfile.py**: Lock file support for reproducible installs (`cmdforge.lock`)
|
||||
@@ -100,31 +100,48 @@ Variable substitution is handled in `runner.py:substitute_variables()`. Settings
|
||||
|
||||
## Provider System
|
||||
|
||||
Providers are CLI tools that accept prompts via stdin and output to stdout. Defined in `~/.cmdforge/providers.yaml`:
|
||||
Providers wrap AI CLIs or compatible HTTP APIs. Defined in `~/.cmdforge/providers.yaml`:
|
||||
|
||||
```yaml
|
||||
version: 2
|
||||
providers:
|
||||
- name: claude
|
||||
command: "claude -p"
|
||||
description: "Anthropic Claude"
|
||||
fallback: claude-haiku # Optional: try this provider if primary fails
|
||||
type: subprocess
|
||||
- name: openrouter
|
||||
command: "https://openrouter.ai/api/v1"
|
||||
description: "OpenRouter API"
|
||||
type: api
|
||||
model: openrouter/auto-beta
|
||||
api_key_env: OPENROUTER_API_KEY
|
||||
- name: mock
|
||||
command: "echo '[MOCK]'"
|
||||
command: "mock"
|
||||
description: "Mock provider for testing"
|
||||
```
|
||||
|
||||
Provider fields:
|
||||
- `name`: Provider identifier used in tool configs
|
||||
- `command`: Shell command to invoke (prompt sent via stdin)
|
||||
- `command`: Shell command (subprocess/pty) or endpoint URL (api)
|
||||
- `type`: `subprocess` (default), `api` (OpenAI-compatible HTTP), or `pty` (interactive CLI, experimental)
|
||||
- `model`: Model ID for api-type providers
|
||||
- `api_key_env`: Environment variable holding the API key for api-type providers
|
||||
- `description`: Optional human-readable description
|
||||
- `fallback`: Optional provider to try if this one fails (prevents infinite loops)
|
||||
- `fallback`: Optional provider to try if this one fails
|
||||
- `fallback_chain`: Ordered list of providers for multi-step fallback
|
||||
- `tags`: List of strings (e.g. `["free", "code", "local"]`)
|
||||
- `pty_config`: Dict with `prompt_pattern`, `response_pattern`, `exit_command` for pty providers
|
||||
- `install`: Optional structured install metadata dict
|
||||
|
||||
The `mock` provider is built-in for testing without API calls. Use `--provider mock` or `--dry-run` flags when testing tools.
|
||||
|
||||
Provider CLI commands:
|
||||
- `cmdforge providers list` - List all providers and their status
|
||||
- `cmdforge providers add <name> <command>` - Add/update a provider
|
||||
- `cmdforge providers check` - Check which providers are available
|
||||
- `cmdforge providers add <name> <command>` - Add/update a provider (supports `--type`, `--model`, `--api-key-env`, `--tag`, `--fallback`, `--fallback-chain`)
|
||||
- `cmdforge providers remove <name>` - Remove a provider
|
||||
- `cmdforge providers test <name>` - Test a provider
|
||||
- `cmdforge providers discover [--add]` - Scan system for installed CLIs and API keys
|
||||
- `cmdforge providers install` - Interactive guide to install AI providers
|
||||
- `cmdforge providers for-tools <tool> [tools...]` - List providers used by tools (with `--warm` to pre-load local models)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user