# z3ed CLI Technical Reference **Version**: 0.1.0-alpha **Last Updated**: [Current Date] **Status**: Production Ready (macOS), Windows Testing Pending --- ## Table of Contents 1. [Architecture Overview](#architecture-overview) 2. [Command Reference](#command-reference) 3. [Implementation Guide](#implementation-guide) 4. [Testing & Validation](#testing--validation) 5. [Development Workflows](#development-workflows) 6. [Troubleshooting](#troubleshooting) 7. [API Reference](#api-reference) 8. [Platform Notes](#platform-notes) --- ## Architecture Overview ### System Components ``` ┌─────────────────────────────────────────────────────────┐ │ AI Agent Layer (LLM) │ │ └─ Natural language prompts │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ z3ed CLI (Command-Line Interface) │ │ ├─ agent run --prompt "..." --sandbox │ │ ├─ agent test --prompt "..." (IT-02) │ │ ├─ agent list │ │ ├─ agent diff --proposal-id │ │ ├─ agent describe [--resource ] │ │ ├─ rom info/validate/diff/generate-golden │ │ ├─ palette export/import/list │ │ ├─ overworld get-tile/find-tile/set-tile │ │ └─ dungeon list-rooms/add-object │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ Service Layer (Singleton Services) │ │ ├─ ProposalRegistry (proposal tracking) │ │ ├─ RomSandboxManager (isolated ROM copies) │ │ ├─ ResourceCatalog (machine-readable API specs) │ │ ├─ GuiAutomationClient (gRPC wrapper) │ │ ├─ TestWorkflowGenerator (NL → test steps) │ │ └─ PolicyEvaluator (YAML constraints) [Planned] │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ ImGuiTestHarness (gRPC Server) │ │ ├─ Ping (health check) │ │ ├─ Click (button, menu, tab) │ │ ├─ Type (text input) │ │ ├─ Wait (condition polling) │ │ ├─ Assert (state validation) │ │ ├─ Screenshot (capture) [Stub → IT-08] │ │ ├─ GetTestStatus (query test execution) [IT-05] │ │ ├─ ListTests (enumerate tests) [IT-05] │ │ ├─ GetTestResults (detailed results) [IT-05] │ │ ├─ DiscoverWidgets (widget enumeration) [IT-06] │ │ ├─ StartRecording (test recording) [IT-07] │ │ ├─ StopRecording (finish recording) [IT-07] │ │ └─ ReplayTest (execute test script) [IT-07] │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ YAZE GUI (ImGui Application) │ │ ├─ ProposalDrawer (Debug → Agent Proposals) │ │ │ ├─ List/detail views │ │ │ ├─ Accept/Reject/Delete │ │ │ └─ ROM merging │ │ └─ Editor Windows │ │ ├─ Overworld Editor │ │ ├─ Dungeon Editor │ │ ├─ Palette Editor │ │ └─ Graphics Editor │ └─────────────────────────────────────────────────────────┘ ``` ### Data Flow: Proposal Lifecycle ``` User: z3ed agent run "Make soldiers red" --sandbox │ ▼ ┌────────────────────────┐ │ MockAIService │ → ["palette export sprites_aux1 4 soldier.col"] └────────┬───────────────┘ │ ▼ ┌────────────────────────┐ │ RomSandboxManager │ → Creates: /tmp/.../sandboxes/20251002T100000/zelda3.sfc └────────┬───────────────┘ │ ▼ ┌────────────────────────┐ │ Execute Commands │ → Runs: palette export on sandbox ROM └────────┬───────────────┘ │ ▼ ┌────────────────────────┐ │ ProposalRegistry │ → Creates: proposal-20251002T100000/ │ │ • execution.log │ │ • diff.txt (if generated) └────────┬───────────────┘ │ ▼ (User opens YAZE GUI) ┌────────────────────────┐ │ ProposalDrawer │ → Displays: List of proposals └────────┬───────────────┘ │ ▼ (User clicks "Accept") ┌────────────────────────┐ │ AcceptProposal() │ → 1. Load sandbox ROM │ │ 2. rom_->WriteVector(0, sandbox_rom.vector()) │ │ 3. ROM marked dirty │ │ 4. User saves ROM └────────────────────────┘ ``` --- ## Command Reference ### Agent Commands #### `agent run` - Execute AI-driven ROM modifications ```bash z3ed agent run --prompt "" --rom [--sandbox] Options: --prompt Natural language description of desired changes --rom Path to ROM file (default: current ROM) --sandbox Create isolated copy for testing (recommended) Example: z3ed agent run --prompt "Change soldier armor to red" \ --rom=zelda3.sfc --sandbox ``` **Output**: - Proposal ID - Sandbox path - Command execution log - Next steps guidance #### `agent list` - Show all proposals ```bash z3ed agent list Example Output: === Agent Proposals === ID: proposal-20251002T100000-1 Status: Pending Created: 2025-10-02 10:00:00 Prompt: Change soldier armor to red Commands: 3 Bytes Changed: 128 Total: 1 proposal(s) ``` #### `agent diff` - Show proposal changes ```bash z3ed agent diff [--proposal-id ] Options: --proposal-id View specific proposal (default: latest pending) Example: z3ed agent diff --proposal-id proposal-20251002T100000-1 ``` **Output**: - Proposal metadata - Execution log - Diff content - Next steps #### `agent describe` - Export machine-readable API specs ```bash z3ed agent describe [--format ] [--resource ] [--output ] Options: --format Output format: yaml or json (default: yaml) --resource Filter to specific resource (rom, palette, etc.) --output Write to file instead of stdout Examples: z3ed agent describe --format yaml z3ed agent describe --format json --resource rom z3ed agent describe --output docs/api/z3ed-resources.yaml ``` **Resources Available**: - `rom` - ROM file operations - `patch` - Patch application - `palette` - Palette manipulation - `overworld` - Overworld editing - `dungeon` - Dungeon editing - `agent` - Agent commands #### `agent resource-list` - Enumerate labeled resources for the AI ```bash z3ed agent resource-list --type [--format ] Options: --type Required label family (dungeon, overworld, sprite, palette, etc.) --format Output format, defaults to `table`. Use `json` for LLM tooling. Examples: # Show dungeon labels in a table z3ed agent resource-list --type dungeon # Emit JSON for the conversation agent to consume z3ed agent resource-list --type overworld --format json ``` **Notes**: - When the conversation agent invokes this tool, JSON output is requested automatically. - Labels are loaded from `ResourceContextBuilder`, so the command reflects project-specific metadata. #### `agent dungeon-list-sprites` - Inspect sprites in a dungeon room ```bash z3ed agent dungeon-list-sprites --room [--format ] Options: --room Dungeon room ID (hexadecimal). Accepts `0x` prefixes or decimal. --format Output format, defaults to `table`. Examples: z3ed agent dungeon-list-sprites --room 0x012 z3ed agent dungeon-list-sprites --room 18 --format json ``` **Output**: - Table view prints sprite id/x/y in hex+decimal for quick inspection. - JSON view is tailored for the LLM toolchain and is returned automatically during tool calls. #### `agent chat` - Interactive terminal chat (TUI prototype) ```bash z3ed agent chat ``` - Opens an FTXUI-based interface with scrolling history and input box. - Uses the shared `ConversationalAgentService`, so the same backend powers the GUI widget. - Useful for manual testing of tool dispatching and new prompting strategies. #### `agent test` - Automated GUI testing (IT-02) ```bash z3ed agent test --prompt "" [--host ] [--port ] Options: --prompt Natural language test description --host Test harness hostname (default: localhost) --port Test harness port (default: 50052) --timeout Maximum test duration (default: 30) Supported Prompt Patterns: - "Open editor" - "Open and verify it loads" - "Click