Skip to content

feat: optional PATH argument for host, serve, mcp, and watch commands#67

Open
sattva1 wants to merge 1 commit intoharshkedia177:mainfrom
sattva1:sattva/feat/path-argument
Open

feat: optional PATH argument for host, serve, mcp, and watch commands#67
sattva1 wants to merge 1 commit intoharshkedia177:mainfrom
sattva1:sattva/feat/path-argument

Conversation

@sattva1
Copy link
Copy Markdown

@sattva1 sattva1 commented Apr 3, 2026

Summary

Closes #65.

Adds an optional [PATH] positional argument to watch, host, serve, and mcp commands, matching the existing analyze pattern. This allows running Axon against a project directory without cd-ing into it — critical when Axon is installed globally and the target project has its own isolated virtualenv.

Changes

  • src/axon/mcp/server.py — New set_db_path() setter following the existing set_storage()/set_lock() injection pattern. Allows the CLI to configure the MCP server's database path before entering the event loop.

  • src/axon/cli/main.py:

    • watch, host, serve, mcp accept path: Path = typer.Argument(Path("."), ...) with early directory validation
    • _run_shared_host() takes repo_path as a parameter instead of hardcoding Path.cwd()
    • _start_host_background() passes the path as an explicit positional argument to the subprocess
    • watch() refactored to delegate to _initialize_writable_storage() (was duplicating ~15 lines of init logic)
    • serve() calls set_db_path() before the watch/no-watch branch, so both code paths honor the path
    • ui() updated to pass repo_path to _run_shared_host() (API contract change, no new argument)
  • tests/cli/test_main.py — 10 new tests: help text visibility, non-existent path rejection, set_db_path() global update, subprocess command verification.

Usage

# Index from anywhere
axon analyze /home/user/projects/my-app

# Run server commands against the same project — no cd required
axon host --watch /home/user/projects/my-app
axon serve --watch /home/user/projects/my-app
axon mcp /home/user/projects/my-app
axon watch /home/user/projects/my-app

Backward compatible — all commands default to . (current directory).

…ost` commands

- Replace hardcoded Path.cwd() with an explicit path argument (defaults to .)
  across affected commands
- Add set_db_path() to mcp/server.py for injecting a custom DB path in
  standalone MCP server mode
- Propagate resolved repo_path into _run_shared_host() and
  _start_host_background() instead of re-deriving it from cwd
- Refactor watch() to delegate to _initialize_writable_storage() instead
  of duplicating init logic
- Add path validation (must be an existing directory) with early exit on failure
- Add tests covering PATH argument visibility in --help, rejection of
  non-existent paths, set_db_path(), and _start_host_background() path forwarding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional path argument to host, serve, and mcp commands

1 participant