CLI Commands & Tooling
Overview
The DeepDoc CLI (deepdoc/cli.py) is the primary interface for generating, updating, previewing, and deploying documentation for code repositories. It orchestrates the entire documentation lifecycle, from initializing configuration to building and serving a Fumadocs-powered site, and integrates with LLM providers (Anthropic, OpenAI, Ollama, Azure) and optional chatbot/embedding backends.
The CLI is designed for developer productivity, enabling both one-off and automated workflows. It is deeply integrated with the Pipeline & Generation Engine, Site Generation & Frontend Integration Overview, and supports advanced features like smart incremental updates, config editing, and local/CI deployment.
For a high-level system view, see DeepDoc Architecture & System Overview.
Related features:
- Site Generation & Frontend Integration Overview
- Site Builder Workflow and Frontend Integration
- Anthropic Integration
- Documentation Chunking and Summarization
- Webhook Integrations
Files Covered
| File Path | Role | Key Symbols | Responsibility |
|---|---|---|---|
deepdoc/cli.py | Handler | main, init, generate, update, clean, status, serve, config_cmd, config_show, config_set, _deploy | Main CLI entrypoint and all command implementations |
deepdoc/__main__.py | Entrypoint | main | Python module entrypoint; runs CLI as python -m deepdoc |
tests/test_cli_serve.py | Test | test functions | Tests CLI serve logic, dependency checks, and port selection |
Main Workflows
The CLI supports several core workflows:
1. Initialization
deepdoc initcreates a.deepdoc.yamlconfig file with sensible defaults for the chosen LLM provider, output directory, and (optionally) chatbot scaffolding.- Prompts for overwrite if config exists.
- Adds
.gitignoreentries for generated artifacts.
2. Documentation Generation
deepdoc generatescans the codebase, plans documentation buckets, generates pages, stages OpenAPI assets, and builds the Fumadocs site.- Supports full (
--force), clean (--clean), and incremental (deepdoc update) modes. - Handles include/exclude patterns and batch size.
3. Incremental Update
deepdoc updateonly regenerates docs for files changed since the last sync, using a smart update strategy (see Pipeline & Generation Engine).- Optionally triggers deploy.
4. Status & Benchmarking
deepdoc statusshows how many pages were generated, which buckets are stale, and summary stats.deepdoc benchmarkruns planner/nav quality benchmarks.
5. Local Preview & Deployment
deepdoc servelaunches a local Fumadocs dev server (requires Node.js), optionally scaffolds and starts the chatbot backend.deepdoc deploybuilds a static export for deployment to any static host.
6. Config Management
deepdoc config showprints the current config as a table.deepdoc config set KEY.PATH VALUEupdates a config value without editing YAML.
Main CLI Flow
Participating Endpoints
The CLI itself does not expose HTTP endpoints, but it scaffolds and interacts with services that do. Notably:
- Chatbot Backend: When
--with-chatbotis enabled, the CLI scaffolds and (optionally) starts a FastAPI backend for code Q&A. See DeepDoc Chat API Integration. - Embedding API: If enabled, the CLI ensures the embedding backend is scaffolded. See DeepDoc Embedding API Integration.
For public API endpoints, see Public API Endpoints.
Core Helpers & Business Rules
Command: init() (deepdoc/cli.py:131)
Purpose: Initializes DeepDoc in the current repo, creating .deepdoc.yaml with provider/model/output_dir defaults.
Branching & Validation:
- If
.deepdoc.yamlexists, prompts for overwrite unless confirmed. - Provider-specific defaults:
anthropic: modelclaude-3-5-sonnet-20241022, envANTHROPIC_API_KEYopenai: modelgpt-4o, envOPENAI_API_KEYollama: modelollama/llama3.2, no API key, setsbase_urlazure: modelazure/gpt-4o, envAZURE_API_KEY
- If
--with-chatbot, merges in chatbot config fromDEFAULT_CHATBOT_CONFIG(deepdoc/chatbot/settings.py).
Example:
deepdoc init --provider openai --model gpt-4o --output-dir documentationCommand: generate() (deepdoc/cli.py:246)
Purpose: Runs the full documentation pipeline.
Branching & Validation:
- If
--clean, wipes output and state before generating. - If DeepDoc-managed output exists and not
--force, errors out and suggestsupdateor--force. - If output dir exists but not DeepDoc-managed, errors unless
--clean. - Handles
include,exclude,include_api,batch_sizeoptions.
Pipeline Steps:
- Scan files/symbols/endpoints
- Plan docs with LLM
- Generate pages in batches
- Stage OpenAPI assets
- Build Fumadocs site
Example:
deepdoc generate --clean --yesCommand: update() (deepdoc/cli.py:362)
Purpose: Incrementally updates docs for changed files.
Branching & Validation:
- Requires prior
generate. - Determines
--sincecommit: explicit > last synced >HEAD~1. - If
generation_modeis"feature_buckets", usesSmartUpdater()(deepdoc/smart_update_v2.py:141). - If
--replan, forces a full replan. - Optionally triggers deploy.
Example:
deepdoc update --since HEAD~3 --deployCommand: clean() (deepdoc/cli.py:323)
Purpose: Removes all DeepDoc config, output, and state.
Branching & Validation:
- If nothing to remove, prints a message and exits.
- Prompts for confirmation unless
--yes.
Example:
deepdoc clean --yesCommand: status() (deepdoc/cli.py:429)
Purpose: Shows doc generation status, bucket counts, and stale buckets.
Branching & Validation:
- If no plan found, prompts to run
generate. - Uses
ledger_summary()(deepdoc/persistence_v2.py:633) for stats. - Uses
find_stale_buckets()(deepdoc/persistence_v2.py:563) to detect out-of-date docs.
Command: serve() (deepdoc/cli.py:547)
Purpose: Runs a local Fumadocs dev server with live reload.
Branching & Validation:
- Requires Node.js >= 18.
- If
site/package.jsonmissing, errors and suggestsgenerate. - If chatbot enabled, starts backend via
_start_chatbot_backend().
Example:
deepdoc serve --port 4000Command: config_show() / config_set() (deepdoc/cli.py:744, deepdoc/cli.py:762)
Purpose: Inspect or update .deepdoc.yaml without editing manually.
Branching & Validation:
- If config missing, errors and suggests
init. config_setrequires a value.
Example:
deepdoc config set llm.provider openaiHelper: _site_dependencies_need_install() (deepdoc/cli.py:674)
Purpose: Checks if site/node_modules or lockfile/stamp are missing or stale.
Branching:
- Returns
Trueifnode_modulesorpackage-lock.jsonmissing, or if the hash in.deepdoc-package-sync.jsondoes not match the currentpackage.json.
Tested in: tests/test_cli_serve.py
Helper: _start_chatbot_backend() (deepdoc/cli.py:889)
Purpose: Scaffolds and starts the chatbot backend if enabled and not using an external URL.
Branching:
- If
backend.base_urlis set, skips local spawn. - If backend scaffold missing, prints warning and continues without chat.
- Picks an available port, warns if preferred port is busy.
State Transitions
The CLI manages several stateful artifacts:
.deepdoc.yaml: Project config (created/updated/removed)docs/(or custom output): Generated Markdown docssite/: Fumadocs site scaffold and build output.deepdoc/: Plan, ledger, and sync statechatbot_backend/: Chatbot backend scaffold (if enabled)
State transitions:
Integrations Involved
- LLM Providers: Used for planning/generation (
anthropic,openai,ollama,azure). See Anthropic Integration. - Fumadocs: Site generator and frontend integration. See Site Generation & Frontend Integration Overview.
- Chatbot Backend: Optional FastAPI backend for code Q&A. See DeepDoc Chat API Integration.
- Embedding API: Optional backend for vector search. See DeepDoc Embedding API Integration.
- Webhooks: CLI scaffolds integration points. See Webhook Integrations.
Configuration & Environment
Key config options (in .deepdoc.yaml):
| Key | Purpose | Default / Example Value |
|---|---|---|
project_name | Name for docs/site | Directory name |
description | Short project description | "" |
output_dir | Docs output directory | "docs" |
llm.provider | LLM provider | "anthropic" |
llm.model | Model name | Provider-specific default |
llm.api_key_env | Env var for API key | e.g., "OPENAI_API_KEY" |
llm.base_url | (Ollama only) Base URL for local LLM | "http://localhost:11434" |
chatbot.enabled | Enable chatbot backend | false |
Environment variables (set via .env or shell):
OPENAI_API_KEY,ANTHROPIC_API_KEY,AZURE_API_KEY: Used for LLM access, depending on provider.
Edge Cases & Failure Modes
- Config Exists:
initprompts before overwriting.deepdoc.yaml. - Output Directory Not Managed: If output dir exists but is not DeepDoc-managed,
generateerrors unless--cleanis used. - Node.js Missing:
serveanddeployrequire Node.js >= 18. If missing, errors out. - Chatbot Port Busy: If the preferred port for the chatbot backend is busy, picks another and warns.
- Stale Buckets:
statusreports buckets as stale if source files are changed, deleted, or output is missing. - Missing Config: Most commands error and suggest
initif.deepdoc.yamlis missing. - Dependency Sync: If
site/node_modulesor lockfiles are missing or stale, triggersnpm install.
Diagrams
CLI Main Flow
Quick Reference
| Symbol | File Path | Signature / Args | What It Does |
|---|---|---|---|
main | deepdoc/cli.py | (ctx: click.Context) | CLI entrypoint, dispatches to subcommands |
init | deepdoc/cli.py | (name, description, provider, model, output_dir, with_chatbot) | Initialize DeepDoc config and scaffold |
generate | deepdoc/cli.py | (force, clean, yes, include, exclude, include_api, deploy, batch_size, max_parallel_workers, rate_limit_pause) | Run full doc generation pipeline |
update | deepdoc/cli.py | (since, deploy, replan) | Incrementally update docs for changed files |
clean | deepdoc/cli.py | (yes) | Remove config, output, and state |
status | deepdoc/cli.py | () | Show doc generation status and stale buckets |
benchmark | deepdoc/cli.py | (catalog, repo_path, gold) | Run planner/nav quality benchmarks |
serve | deepdoc/cli.py | (port) | Start local Fumadocs dev server |
_deploy | deepdoc/cli.py | () | Build static export for deployment |
config_cmd | deepdoc/cli.py | (ctx: click.Context) | Config command group |
config_show | deepdoc/cli.py | () | Print current config as table |
config_set | deepdoc/cli.py | (key_path, value) | Update config value by key path |
_site_dependencies_need_install | deepdoc/cli.py | (site_dir: Path) | Check if site deps are missing/stale |
_start_chatbot_backend | deepdoc/cli.py | (repo_root, cfg, frontend_port) | Scaffold/start chatbot backend if enabled |
Constants, Enums & Status Values
LLM Providers (init):
"anthropic","openai","ollama","azure"
Config keys affecting behavior:
llm.provider,llm.model,llm.api_key_env,llm.base_url,chatbot.enabled
See Also
- Setup & Getting Started
- Pipeline & Generation Engine
- Site Generation & Frontend Integration Overview
- Site Builder Workflow and Frontend Integration
- Anthropic Integration
- Documentation Chunking and Summarization
- Webhook Integrations
- DeepDoc Chat API Integration
- DeepDoc Embedding API Integration
Pipeline & Generation Engine
DeepDoc's core document planning and generation pipeline.
Site Generation & Frontend Integration
How the CLI builds and serves the Fumadocs-powered frontend.
Anthropic Integration
LLM provider setup and configuration.
DeepDoc Chat API Integration
Chatbot backend and API integration.