Skip to content

Commit bbca822

Browse files
committed
docs: First draft on the TUI/WebUI specs
1 parent 9b68f7d commit bbca822

File tree

4 files changed

+757
-0
lines changed

4 files changed

+757
-0
lines changed

docs/cli-spec.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
## AW CLI — Command-Line and TUI Specification
2+
3+
### Overview
4+
5+
The AW CLI (`aw`) unifies local and remote workflows for launching and managing agent coding sessions. Running `aw` with no subcommands starts the TUI dashboard. Subcommands provide scriptable operations for task/session lifecycle, configuration, repository management, and developer ergonomics.
6+
7+
The CLI honors the layered configuration model in `docs/configuration.md` (system, user, project, project-user, env, CLI flags). Flags map from config keys using the `--a-b-c` convention and env var prefix `AGENTS_WORKFLOW_`.
8+
9+
### Primary Goals
10+
11+
- One tool for both the TUI dashboard and automation-ready commands
12+
- First-class support for:
13+
- Local directory mode (PID-like files for discovery)
14+
- Remote REST service mode (on-prem/private cloud), aligned with `docs/rest-service.md`
15+
- Terminal multiplexers: tmux, zellij, screen
16+
- Devcontainers and local runtimes (including unsandboxed, policy-gated)
17+
- IDE integrations (VS Code, Cursor, Windsurf) and terminal-based agents
18+
19+
### Global Behavior and Flags
20+
21+
- `aw` (no args): Launches the TUI dashboard (default mode described below)
22+
- Common global flags (apply to all subcommands unless noted):
23+
- `--mode <auto|local|rest>`: Discovery/operation mode. Default: `auto` (prefer local when in a repo with `.agents/`; otherwise rest if `network.apiUrl` configured)
24+
- `--repo <PATH|URL>`: Target repository (filesystem path in local mode; git URL otherwise)
25+
- `--project <NAME>`: Project/workspace name (REST mode)
26+
- `--json`: Emit machine-readable JSON
27+
- `--quiet`: Reduce output
28+
- `--log-level <debug|info|warn|error>`
29+
- `--no-color`
30+
31+
Configuration mapping examples:
32+
33+
- `network.apiUrl``--network-api-url`, `AGENTS_WORKFLOW_NETWORK_API_URL`
34+
- `tui.defaultMode``--mode`
35+
- `terminal.multiplexer``--multiplexer <tmux|zellij|screen>`
36+
- `editor.default``--editor`
37+
38+
### Subcommands
39+
40+
#### 1) TUI
41+
42+
- `aw` or `aw tui [--mode <local|rest>] [--multiplexer <tmux|zellij|screen>]`
43+
- Starts the dashboard and auto-attaches to the active multiplexer session (creating one if needed).
44+
- Mode `rest`: connects to REST service to retrieve projects/repos/agents/branches and launches local (or remote via SSH) multiplexer windows for new tasks.
45+
- Mode `local`: operates in current repository (default), discovering running tasks via PID-like files in the filesystem.
46+
47+
TUI dashboard (simplified quick-launch UI):
48+
49+
- Top: fixed-height selectors for Project, Branch, Agent with filter input and arrow-key navigation (long lists scroll within the viewport).
50+
- Bottom: multiline task description editor (resizable). A Start action launches the task.
51+
- Existing task windows are already visible in the multiplexer; the dashboard focuses on selecting options and starting new tasks.
52+
53+
Task launch behavior in TUI:
54+
55+
- Creates a new multiplexer window immediately with split panes: right pane shows the agent activity; left pane starts a terminal or configured editor in the task-specific workspace mount.
56+
57+
#### 2) Tasks
58+
59+
- `aw task [create] [--prompt <TEXT> | --prompt-file <FILE>] [--repo <PATH|URL>] [--branch <NAME>] [--agent <TYPE>[@VERSION]] [--instances <N>] [--runtime <devcontainer|local|unsandboxed>] [--devcontainer-path <PATH>] [--labels k=v ...] [--delivery <pr|branch|patch>] [--target-branch <NAME>] [--yes]`
60+
61+
Behavior:
62+
63+
- In local mode, prepares a per-task workspace using snapshot preference order (ZFS > Btrfs > Overlay > copy) and launches the agent.
64+
- In rest mode, calls `POST /api/v1/tasks` with the provided parameters.
65+
- Creates/updates a local PID-like session record when launching locally (see “Local Discovery”).
66+
- Branch autocompletion uses standard git protocol:
67+
- Local mode: `git for-each-ref` on the repo; cached with debounce.
68+
- REST mode: server uses `git ls-remote`/refs against admin-configured URL to populate its cache; CLI/Web query capability endpoints for suggestions.
69+
70+
Draft flow (TUI/Web parity):
71+
72+
- CLI supports `--draft` to persist an editable draft; `aw task start <draft-id>` to submit.
73+
74+
#### 3) Sessions
75+
76+
- `aw session list [--status <...>] [--project <...>] [--repo <...>]`
77+
- `aw session get <SESSION_ID>`
78+
- `aw session logs <SESSION_ID> [-f] [--tail <N>]`
79+
- `aw session events <SESSION_ID> [-f]`
80+
- `aw session stop <SESSION_ID>`
81+
- `aw session pause <SESSION_ID>`
82+
- `aw session resume <SESSION_ID>`
83+
- `aw session cancel <SESSION_ID>`
84+
85+
Behavior:
86+
87+
- Local mode reads session records from filesystem; `logs -f` tails the agent log.
88+
- REST mode proxies to the service and uses SSE for `events -f`.
89+
90+
#### 4) Attach / Open
91+
92+
- `aw attach <SESSION_ID> [--pane <left|right|full>]` — Attach to the multiplexer window for a session.
93+
- `aw open ide <SESSION_ID> --ide <vscode|cursor|windsurf>` — Open IDE on the session workspace.
94+
95+
Remote sessions:
96+
97+
- When a session runs on another machine (VM or remote host), the REST service returns SSH connection details. `aw attach` uses these to open a remote multiplexer session (e.g., `ssh -t host tmux attach -t <name>`), or to run zellij/screen equivalents.
98+
99+
#### 5) Repositories and Projects
100+
101+
- `aw repo list` (local: from recent usage; rest: from workspace projects)
102+
- `aw repo add <PATH|URL>` (local only by default)
103+
- `aw repo remove <PATH|URL>` (local; protected confirm)
104+
- `aw project list` (rest mode)
105+
106+
#### 6) Runtimes, Agents, Hosts (capabilities)
107+
108+
- `aw agents list`
109+
- `aw runtimes list`
110+
- `aw hosts list`
111+
112+
REST-backed: proxies to `/api/v1/agents`, `/api/v1/runtimes`, `/api/v1/hosts`.
113+
114+
#### 7) Config (Git-like)
115+
116+
- `aw config get <key> [--scope <system|user|project|project-user>] [--explain]`
117+
- `aw config set <key> <value> [--scope ...] [--enforced]` (system scope only can be enforced)
118+
- `aw config list [--scope ...] [--show-origin]`
119+
- `aw config unset <key> [--scope ...]`
120+
121+
Mirrors `docs/configuration.md` including provenance, precedence, and Windows behavior.
122+
123+
#### 8) Service and WebUI (local developer convenience)
124+
125+
- `aw serve rest [--local] [--bind 127.0.0.1] [--port <P>] [--db <URL|PATH>]`
126+
- Starts the REST service (localhost-only by default with `--local`).
127+
- `aw webui [--local] [--port <P>] [--rest <URL>]`
128+
- Serves the WebUI for local use; in `--local` it binds to `127.0.0.1` and hides admin features.
129+
130+
#### 9) Utilities
131+
132+
- `aw doctor` — Environment diagnostics (snapshot providers, multiplexer availability, docker/devcontainer, git).
133+
- `aw completion [bash|zsh|fish|pwsh]` — Shell completions.
134+
135+
### Local Discovery (PID-like Files)
136+
137+
Purpose: Enable TUI and CLI to enumerate and manage running local sessions without a server.
138+
139+
Location:
140+
141+
- Per-repo: `.agents/sessions/` within the repository root.
142+
- Optional user index: `~/.config/agents-workflow/sessions/` to aggregate across repos (TUI may use this for “recent sessions”).
143+
144+
Record format (JSON example):
145+
146+
```json
147+
{
148+
"id": "01HVZ6K9T1N8S6M3V3Q3F0X5B7",
149+
"repoPath": "/home/user/src/app",
150+
"workspacePath": "/workspaces/agent-01HVZ6K9",
151+
"agent": {"type": "claude-code", "version": "latest"},
152+
"runtime": {"type": "devcontainer", "devcontainerPath": ".devcontainer/devcontainer.json"},
153+
"multiplexer": {"kind": "tmux", "session": "aw:01HVZ6K9", "window": 3, "paneLeft": "%5", "paneRight": "%6"},
154+
"pids": {"agent": 12345},
155+
"status": "running",
156+
"startedAt": "2025-01-01T12:00:00Z",
157+
"logPath": "/workspaces/agent-01HVZ6K9/.agents/logs/agent.log"
158+
}
159+
```
160+
161+
Creation and lifecycle:
162+
163+
- `aw task` writes the record on successful launch and updates status transitions.
164+
- On normal termination, the record is finalized (endedAt, final status) and moved to an archive file.
165+
- Crash/unclean exit detection: stale PID check on startup; records marked as `failed` with reason.
166+
167+
### Multiplexer Integration
168+
169+
Selection:
170+
171+
- `--multiplexer` flag or `terminal.multiplexer` config determines which tool is used. Autodetect if unset (tmux > zellij > screen if found in PATH).
172+
173+
Layout on launch:
174+
175+
- Create a new window in the current session (or create a session if none) with two panes:
176+
- Right: agent activity (logs/stream)
177+
- Left: terminal in the per-task workspace (or launch editor if configured)
178+
179+
Remote attach:
180+
181+
- Using SSH details from the REST service, run the appropriate attach command remotely (e.g., `ssh -t host tmux new-session -A -s aw:<id> ...`).
182+
183+
Devcontainers:
184+
185+
- When `runtime.type=devcontainer`, run the multiplexer and both panes inside the container context. The left pane starts a login shell or editor; the right follows the agent process output.
186+
187+
### Runtime and Workspace Behavior
188+
189+
- Snapshot selection priority: ZFS → Btrfs → OverlayFS → copy (`cp --reflink=auto` when available), per `docs/fs-snapshots/overview.md`.
190+
- Unsandboxed local runs require explicit `--runtime unsandboxed` and may be disabled by admin policy.
191+
- Delivery modes: PR, Branch push, Patch artifact (as in REST spec).
192+
193+
### IDE and Terminal Agent Integration
194+
195+
- `aw open ide` opens VS Code / Cursor / Windsurf for the per-task workspace (local or via remote commands as provided by the REST service).
196+
- Terminal-based agent alongside GUI editor: user can choose an editor in the left pane while the agent runs on the right; alternatively, `--editor` launches `vim`/`emacs`/other terminal editor with an integrated terminal.
197+
198+
### Examples
199+
200+
Create a task locally and immediately open TUI window/panes:
201+
202+
```bash
203+
aw task --prompt "Refactor checkout service for reliability" --repo . --agent openhands --runtime devcontainer --branch main --instances 2
204+
```
205+
206+
List and tail logs for sessions:
207+
208+
```bash
209+
aw session list --status running --json
210+
aw session logs 01HVZ6K9T1N8S6M3V3Q3F0X5B7 -f --tail 500
211+
```
212+
213+
Attach to a running session window:
214+
215+
```bash
216+
aw attach 01HVZ6K9T1N8S6M3V3Q3F0X5B7 --pane left
217+
```
218+
219+
Run the TUI against a REST service:
220+
221+
```bash
222+
aw tui --mode rest --multiplexer tmux
223+
```
224+
225+
Start local REST service and WebUI for a single developer:
226+
227+
```bash
228+
aw serve rest --local --port 8081
229+
aw webui --local --port 8080 --rest http://127.0.0.1:8081
230+
```
231+
232+
### Exit Codes
233+
234+
- 0 success; non-zero on validation, environment, or network errors (with descriptive stderr messages).
235+
236+
### Security Notes
237+
238+
- Honors admin-enforced config. Secrets never printed. Unsandboxed runtime gated and requires explicit opt-in.
239+
240+

0 commit comments

Comments
 (0)