Add `markitect helper <QUESTION>` CLI command that answers questions about markitect using its own documentation as LLM context. Uses OpenRouter with openrouter/aurora-alpha by default; model is configurable via --model flag or MARKITECT_HELPER_MODEL env var. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4.4 KiB
4.4 KiB
Plan: markitect helper CLI Command
Context
Add an interactive Q&A facility to markitect that answers questions about markitect itself using its own documentation as knowledge context. Uses the existing LLM adapter infrastructure with OpenRouter and openrouter/aurora-alpha as default.
New Files
1. markitect/helper/__init__.py
Empty package init.
2. markitect/helper/knowledge.py — Knowledge Loader
collect_knowledge() -> strfunction that:- Finds markitect's documentation directory relative to the package root (
Path(__file__).resolve().parent.parent.parent) - Reads key markdown files in priority order:
INTRODUCTION.mddocs/CLI_TUTORIAL.mddocs/PROJECT_STRUCTURE.mddocs/SCHEMA_MANAGEMENT_GUIDE.mddocs/PLUGIN_SYSTEM.mddocs/ERROR_HANDLING_STRATEGY.mddocs/architecture/CAPABILITIES_ARCHITECTURE.mddocs/architecture/caching-system.mddocs/user-guides/*.md(all files)examples/content-generator/TUTORIAL.mdexamples/infospace-with-history/TUTORIAL.md- Module docstrings from
markitect/prompts/__init__.pyandmarkitect/llm/__init__.py
- Concatenates with
## <filename>section headers between each doc - Skips missing files gracefully (log warning if verbose)
- Returns the combined knowledge string
- Finds markitect's documentation directory relative to the package root (
3. markitect/helper/cli.py — Click Command
@click.command("helper")
@click.argument("question", nargs=-1, required=True) # accepts multi-word questions without quotes
@click.option("--provider", "-p", default="openrouter",
type=click.Choice(["openrouter", "claude-code", "gemini", "openai"]),
help="LLM provider")
@click.option("--model", "-m", default=None,
help="Model name (overrides MARKITECT_HELPER_MODEL env var and default)")
Logic:
- Join
questiontuple into a single string - Resolve model: CLI
--modelflag →MARKITECT_HELPER_MODELenv var →openrouter/aurora-alpha - Call
collect_knowledge()to build the knowledge context - Build system prompt:
"You are a markitect expert assistant. Answer questions based on the following markitect documentation:\n\n{knowledge}" - Call
create_adapter(provider, model=model, system_prompt=system_prompt) - Call
adapter.execute_prompt(question, RunConfig(max_tokens=4000, temperature=0.3)) - Print
response.contentto stdout - Handle errors:
LLMConfigurationError→ helpful message about API key, otherLLMError→ stderr message
Modified Files
4. markitect/cli.py — Register the Command
At the bottom with the other cli.add_command() calls, add:
try:
from markitect.helper.cli import helper_command
cli.add_command(helper_command)
except ImportError:
pass # Helper module not available
This follows the existing pattern used for prompts, finance, etc.
Configuration
- Default provider:
openrouter - Default model:
openrouter/aurora-alpha - Environment variable:
MARKITECT_HELPER_MODEL— overrides the default model - CLI flag:
--model/-m— overrides both env var and default - Precedence:
--modelflag >MARKITECT_HELPER_MODELenv var >openrouter/aurora-alpha
Key Reference Files
markitect/cli.py— main CLI (Click-based,@cli.command()pattern, register viacli.add_command())markitect/llm/factory.py—create_adapter(provider, model, api_key, system_prompt)markitect/llm/openrouter.py— OpenRouterAdapter (default)markitect/prompts/execution/models.py—RunConfig,LLMResponsemarkitect/prompts/execution/llm_adapter.py—LLMAdapterbase class (method:execute_prompt(prompt, config) -> LLMResponse)markitect/llm/exceptions.py—LLMError,LLMConfigurationError,LLMAPIError,LLMRateLimitError- API key resolution: env var
OPENROUTER_API_KEYor fileapikey-openrouter.txtin project root
Verification
markitect helper "What is markitect?"— should return a knowledge-based answermarkitect helper --model anthropic/claude-sonnet-4 "How do schemas work?"— uses different modelMARKITECT_HELPER_MODEL=google/gemini-2.5-flash markitect helper "What are templates?"— env var overridemarkitect helper --provider claude-code "Explain the plugin system"— uses Claude CLImarkitect helper --help— shows usage with all options