# Neotoma CLI reference ## Scope This document covers CLI commands, options, configuration, and developer facing details. It does not cover MCP behavior or server side implementation beyond public API references. ## Purpose Provide a complete CLI command reference and developer context for Neotoma CLI behavior. ## Invariants 1. Commands and options MUST match the CLI implementation. 2. Output formatting MUST remain deterministic and stable. 3. Configuration details MUST remain consistent with the CLI config module. ## Definitions - **Operation ID**: OpenAPI operation identifier used by `neotoma request`. - **Config path**: The file path where CLI stores connection settings. - **PKCE**: OAuth Proof Key for Code Exchange used for login. ## Running the CLI Run via npm scripts: `npm run cli` or `npm run cli:dev` (dev mode with immediate source changes). For global `neotoma` command: `npm run setup:cli` (build and link in one step), or manually `npm run build:server` then `npm install -g .` or `npm link`. If `neotoma` is not found, add `$(npm config get prefix)/bin` to PATH. See [CLI setup](getting_started.md#cli-setup) and [CLI overview](cli_overview.md#installation-and-setup) for full installation and troubleshooting details. ### Keeping the global CLI in sync The global `neotoma` runs the built files in `dist/`, not the TypeScript source. After you change CLI code, either build once (`npm run build:server`) or run a watcher so the global install stays current: - **One-off:** `npm run build:server` after CLI changes. - **Ongoing (terminal):** Run `npm run dev:types` in a terminal. It runs `tsc --watch` so every save recompiles `dist/`; the next `neotoma` invocation uses the new code. With `npm link`, no re-link is needed. - **Ongoing (after reboot):** Run `npm run setup:launchd-cli-sync` once (alias: `setup:launchd-watch-build`). This installs a macOS LaunchAgent that re-links the global `neotoma` command to the current checkout, runs `tsc --watch` at login, and keeps it running so the global CLI stays in sync even after restart. The agent captures the current `node` / `npm` paths during setup; re-run the setup command after switching Node manager or Node version. Logs: `data/logs/launchd-watch-build.log`. Unload with `launchctl unload ~/Library/LaunchAgents/com.neotoma.watch-build.plist`. ### Dev or prod HTTP at login (macOS) - **Dev API:** `npm run setup:launchd-dev` (alias `setup:launchd-dev-server`) installs `com.neotoma.dev-server`, which runs `npm run dev:server`. See [`docs/developer/launchd_dev_servers.md`](launchd_dev_servers.md). - **Built production-mode API:** `npm run setup:launchd-prod-server` installs `com.neotoma.prod-server`, which runs `npm run start:server:prod`. See [`docs/developer/launchd_prod_server.md`](launchd_prod_server.md). ### Scheduled GitHub issues sync (macOS) Run `npm run setup:launchd-issues-sync` once to install `com.neotoma.issues-sync`: it runs `neotoma issues sync` every 5 minutes (and once at login). Logs: `data/logs/launchd-issues-sync.log`. Optional env for launchd (not in your shell profile): copy `scripts/launchd-issues-sync.env.example` to `data/local/launchd-issues-sync.env`. Unload with `launchctl unload ~/Library/LaunchAgents/com.neotoma.issues-sync.plist`. ### Environment: `neotoma dev` / `neotoma prod` To target a specific API environment, pass `dev` or `prod` as the first argument or use `--env`. - `neotoma dev` — development API (port 3080). - `neotoma prod` — production API (port 3180). Examples: `neotoma prod`, `neotoma dev`, `neotoma prod storage info`. Equivalent to using `--env`. ### Default: interactive session (use-existing only) When you run `neotoma` with **no arguments**, source checkout selection follows this precedence: 1. explicit CLI flags (for commands that accept root/path flags) 2. `NEOTOMA_REPO_ROOT` 3. directory-local checkout (walk up from current directory) 4. saved config `project_root` (legacy `repo_root`) in `~/.config/neotoma/config.json` 5. user-level env at `~/.config/neotoma/.env` when no checkout is detected With a source checkout, the CLI: 1. Uses **use-existing** policy only (no automatic server start). 2. Discovers running API instances from session ports, default ports (`3080`, `3180`), remembered ports, and optional extra configured ports. 3. Applies `--env` as a preference when selecting among multiple detected instances. 4. If multiple candidates remain, prompts you to choose the instance. 5. If none respond, shows fallback startup guidance and the command menu. 6. Enters an **interactive session** with a `neotoma> ` prompt. **Non-interactive (e.g. agents):** When stdout is not a TTY, the CLI does **not** prompt. It uses **use-existing** (connect only). If **no command** is given and stdout is not a TTY (e.g. an agent runs `neotoma` with no args), the CLI prints: "No command given. Run neotoma (e.g. neotoma entities list). Use neotoma --help for options." and exits with code 1. **Direct invocation and session parity:** Every action available at the interactive `neotoma>` prompt is available as a direct CLI call: `neotoma [subcommand] [options] [args]`. Examples: `neotoma entities list`, `neotoma relationships list `, `neotoma storage info`. Agents and scripts should always use direct invocation; do not depend on entering the interactive session. See [CLI overview](cli_overview.md) and the command sections below for the full command tree. To show the intro and then a **command menu** (prompt `> ` and `? for shortcuts`; no servers), use: - `neotoma --no-session` You get the same intro panel, then an interactive prompt. Type a command, or `?` / `help` to list commands. Type `exit` or `quit`, or press Ctrl+D, to exit. To enter a session without starting any servers (connect to an already-running API): - `neotoma --no-servers` or `neotoma --servers=use-existing` Connect-only startup. Detects all available local API instances (not only `3080`/`3180`), prefers `--env` matches when available, and prompts when multiple candidates remain. To start the API in the **background**: - `neotoma api start --background --env dev` (or `--env prod`) Starts the selected environment only and writes env-specific PID/log files. - `neotoma api start --background --env dev --tunnel` (or `--env prod --tunnel`) Starts the API with an HTTPS tunnel (ngrok/cloudflared) for remote MCP access. Tunnel URL is written to `/tmp/ngrok-mcp-url.txt` when ready. Use `--tunnel-provider ngrok` or `--tunnel-provider cloudflare` to force a provider; otherwise the script auto-detects from installed tools. - `neotoma api start --env dev --tunnel` (or `--env prod --tunnel`, no `--background`) Runs the API and tunnel in the **foreground** in the current terminal (same as `npm run dev:server:tunnel`). Logs stream to the terminal; Ctrl+C stops both. Tunnel URL: `cat /tmp/ngrok-mcp-url.txt`. **`--watch` flag (source checkouts).** The product CLI command remains `neotoma api start`, but source-checkout npm spawn targets now use the `dev:server*` taxonomy. Production-env source checkouts route to `dev:server:prod`; installed-package production starts route to `start:server:prod`. - `neotoma api start --env prod --watch` — keeps source-checkout watch behavior explicit. - `neotoma api start --env prod --tunnel` — routes to `dev:server:prod:tunnel`. The flag is a no-op on `--env dev`, on installed-package checkouts without source watch scripts, and on the `--tunnel` path (the tunnel flow always wants the watcher). The deprecation line is suppressed under `--output json`. For a real **headless / systemd** production deployment, install the published npm package (`npm install -g neotoma`) and use the recipe in [install.md § Production deployment (headless / systemd)](../../install.md#production-deployment-headless--systemd) rather than `neotoma api start` on a source checkout. ## npm scripts summary All `npm run