7.2 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
CmdForge is a lightweight personal tool builder for AI-powered CLI commands. It lets users create custom terminal commands that call AI providers, chain prompts with Python code steps, and use them like any Unix pipe command.
Development Commands
# Install for development
pip install -e ".[dev]"
# Run all unit tests (excluding integration tests that need a server)
pytest tests/ -m "not integration"
# Run all tests with verbose output
pytest tests/ -v
# Run a specific test file
pytest tests/test_runner.py -v
# Run a specific test class
pytest tests/test_runner.py::TestSubstituteVariables -v
# Run with coverage
pytest tests/ --cov=cmdforge --cov-report=html
# Run integration tests (requires local registry server at localhost:5000)
python -m cmdforge.registry.app # Start server first
pytest tests/test_registry_integration.py -v -m integration
# Run the CLI
python -m cmdforge.cli
# Launch the GUI
cmdforge
Architecture
Core Modules (src/cmdforge/)
- cli/: CLI commands entry points (
cmdforgecommand). Routes subcommands: list, create, edit, delete, test, run, refresh, collections, registry, settings, system-deps - tool.py: Tool definition dataclasses (
Tool,ToolArgument,PromptStep,CodeStep,ToolStep), YAML config loading/saving, wrapper script generation - runner.py: Execution engine. Runs tool steps sequentially, handles variable substitution (
{input},{varname}), executes Python code steps viaexec(), 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. ReturnsResolvedToolwith path info - collection.py: Collection management (
Collectiondataclass,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 - 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) - registry_client.py: Client for registry API (search, publish, download, authentication)
- gui/: PySide6 desktop GUI
- main_window.py: Main application window with sidebar navigation
- pages/: Tools page, Tool Builder, Registry browser, Collections page, Providers management, Profiles
- dialogs/: Step editors, Argument editor, Provider dialog, Connect/Publish dialogs
Key Paths
- Tools storage:
~/.cmdforge/<toolname>/config.yaml - Tool defaults:
~/.cmdforge/<toolname>/defaults.yaml(optional, published with tool) - Tool settings:
~/.cmdforge/<toolname>/settings.yaml(user overrides, auto-created from defaults) - Wrapper scripts:
~/.local/bin/<toolname>(auto-generated bash scripts) - Provider config:
~/.cmdforge/providers.yaml - Collections storage:
~/.cmdforge/collections/<name>.yaml
Tool Structure
Tools are YAML configs with:
name,description,categoryarguments: Custom flags with defaults (e.g.,--max→{max})steps: Ordered list ofpromptorcodestepsoutput: Template for final output (e.g.,"{response}")
Step Types
- Prompt Step: Calls AI provider with template, stores result in
output_var. Supportsprofilefor AI personas andstrip_fencesfor markdown cleanup - Code Step: Executes Python code via
exec(), captures specified variables (comma-separated for multiple outputs) - Tool Step: Calls another tool (meta-tools), supports
argsdict andprovideroverride. Dependencies resolved viaresolver.py
Variable Flow
Variables are passed between steps:
{input}- always available (stdin/file content){argname}- from tool arguments{step_output_var}- from previous step'soutput_var{settings.key}- from tool's settings.yaml (top-level scalars only in templates)settings['key']- full dict access in code steps
Variable substitution is handled in runner.py:substitute_variables(). Settings are loaded from settings.yaml if it exists, otherwise an empty dict is used.
Provider System
Providers are CLI tools that accept prompts via stdin and output to stdout. Defined in ~/.cmdforge/providers.yaml:
providers:
- name: claude
command: "claude -p"
- name: mock
command: "echo '[MOCK]'"
The mock provider is built-in for testing without API calls.
Web UI & Registry
CmdForge includes a web interface and tool registry:
Web Modules (src/cmdforge/web/)
- app.py: Flask app factory, registers blueprints
- routes.py: Main web routes (docs, tutorials, tools, etc.)
- forum/: Community forum blueprint
- models.py: Forum database schema (categories, topics, replies)
- routes.py: Forum routes (/forum, /forum/c/, /forum/t/)
- filters.py: Jinja2 filters (timeago, markdown, etc.)
- docs_content.py: Documentation and tutorial content
Registry Modules (src/cmdforge/registry/)
- app.py: Flask-based Registry API (tool publishing, search, downloads, authentication, rate limiting)
- db.py: SQLite schema and queries (
connect_db(),query_one(),query_all()) - embeddings.py: Semantic search with vector embeddings for tool discovery
- sync.py: Git-based tool sync from Gitea repository
Key URLs
/forum- Community forum/docs- Documentation/tutorials- Tutorial guides/tools- Tool registry browser
Running the Web UI
# Development
python -m cmdforge.web.app
# Production (example)
CMDFORGE_REGISTRY_DB=/path/to/db PORT=5050 python -m cmdforge.web.app
Testing Conventions
Tests use pytest with common fixtures:
temp_tools_dir(tmp_path): RedirectsTOOLS_DIRandBIN_DIRto temp directorytemp_providers_file(tmp_path): Redirectsproviders.yamlto temp directory
Mocking strategy:
- File system: Use
tmp_pathfixture and patch module-level paths - Subprocess calls: Mock
subprocess.runandshutil.which - Provider calls: Mock
call_providerto returnProviderResult
Integration tests are marked with @pytest.mark.integration and require a running registry server.
Infrastructure Documentation
For deployment, server details, and operations, see the docs/ folder:
- docs/servers.md - Server IPs (192.168.0.162), SSH access, paths, service commands
- docs/deployment.md - Architecture diagram, deploy process, systemd service config
- docs/maintenance.md - Backups, updates, troubleshooting
- docs/architecture.md - Module structure, data flow diagrams
Production Server Quick Reference
| Property | Value |
|---|---|
| Server | 192.168.0.162 (OpenMediaVault) |
| SSH | ssh rob@192.168.0.162 |
| App Path | /srv/mergerfs/data_pool/home/rob/cmdforge-registry/ |
| Service | systemctl --user status cmdforge-web |
| Public URL | https://cmdforge.brrd.tech |
| Port | 5050 (via Cloudflare tunnel) |