terminal-tool-for-agents 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "terminal-tool-for-agents",
3
+ "version": "0.1.3",
4
+ "description": "terminal-tool-for-agents (tta) — terminal tool for AI agents. Command: tta. Package: terminal-tool-for-agents.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/yanggggjie/terminal-tool-for-agents.git"
9
+ },
10
+ "homepage": "https://github.com/yanggggjie/terminal-tool-for-agents#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/yanggggjie/terminal-tool-for-agents/issues"
13
+ },
14
+ "keywords": [
15
+ "tui",
16
+ "pty",
17
+ "terminal",
18
+ "tool",
19
+ "automation",
20
+ "agent",
21
+ "cli",
22
+ "xterm"
23
+ ],
24
+ "bin": {
25
+ "tta": "./dist/cli.js"
26
+ },
27
+ "files": [
28
+ "dist/",
29
+ "skills/tta/SKILL.md",
30
+ "skills/tta/tta-agents-skill.md",
31
+ "src/watch-ui/logo.png",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "build": "node scripts/copy-watch-vendor.js && rm -rf dist && tsc && cp -r src/watch-ui dist/watch-ui && chmod +x dist/cli.js",
37
+ "dev": "node scripts/dev.mjs",
38
+ "start": "node dist/cli.js",
39
+ "test": "node scripts/verify.js",
40
+ "prepack": "npm run build",
41
+ "version": "node scripts/sync-skill-version.js",
42
+ "prepublishOnly": "npm test",
43
+ "release": "node scripts/release.js"
44
+ },
45
+ "dependencies": {
46
+ "@fastify/static": "^9.1.3",
47
+ "@fastify/websocket": "^11.2.0",
48
+ "@xterm/headless": "^6.0.0",
49
+ "@xterm/xterm": "^6.0.0",
50
+ "commander": "^15.0.0",
51
+ "fastify": "^5.8.5",
52
+ "node-pty": "^1.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^24.0.0",
56
+ "@types/ws": "^8.18.1",
57
+ "concurrently": "^9.2.1",
58
+ "nodemon": "^3.1.11",
59
+ "typescript": "^6.0.0"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.0.0 <27.0.0"
63
+ },
64
+ "allowScripts": {
65
+ "node-pty@1.1.0": true
66
+ }
67
+ }
@@ -0,0 +1,226 @@
1
+ ---
2
+ name: tta
3
+ version: 0.1.3
4
+ description: Operate interactive CLI, TUI, and dev-server sessions through a PTY. Use when a command needs keystrokes, redraws a terminal UI, step-by-step screen reads, or for npm create, lazygit, npm run dev, etc. Not for plain non-interactive bash. APIs: sess, act, obs. Bundled tta-agents sub-skill when the user uses tta with coding agents.
5
+ ---
6
+
7
+ # tta - terminal tool for agents
8
+
9
+ `terminal-tool-for-agents` provides the `tta` command. Use shell for plain non-interactive commands. Use `tta` for interactive programs that need a PTY.
10
+
11
+ Idea: start background terminals as `sess`, send keys or text as `act`, then wait for a stable screen and read results as `obs`.
12
+
13
+ ## Session
14
+
15
+ All tta work happens inside a **session** (PTY-backed terminal instance): `tta sess start/kill/list`, `--sess=`.
16
+
17
+ ## tta-agents (bundled sub-skill)
18
+
19
+ `skills/tta/tta-agents-skill.md` ships **with the tta skill** — **no separate install**.
20
+
21
+ **When to enable:** If the user wants tta to drive coding agent CLIs (Claude Code, Codex, Cursor Agent, OpenCode, Pi, etc.) or mentions Orchestrator / Worker / multi-agent coordination, read and follow [`tta-agents-skill.md`](./tta-agents-skill.md). For other interactive terminals (TUI, wizards, dev servers), this skill alone is enough.
22
+
23
+ ## When to use
24
+
25
+ **Use `tta` for:**
26
+
27
+ - REPLs, e.g. `GDB`, `IPython`
28
+ - Interactive setup, e.g. `npm create vite@latest`
29
+ - TUIs, e.g. `lazygit`
30
+ - Long-running processes whose output must be observed over time, e.g. `npm run dev`
31
+ - Coding agent CLIs → enable bundled [`tta-agents-skill.md`](./tta-agents-skill.md)
32
+
33
+ **Do not use `tta` for:**
34
+
35
+ - Plain bash commands that run to completion without interaction
36
+ - Human session observation (use `tta sess watch`; agents must not)
37
+
38
+ ## Standard workflow
39
+
40
+ Follow in order; do not skip steps:
41
+
42
+ 1. **Pick the tool** — interactive / TUI / needs step-by-step screen reads → `tta`; otherwise shell
43
+ 2. **Start and read** — `tta sess start` (see **Parameter quoting**), then `tta obs screen stable --sess=<name>`
44
+ 3. **Choose input by screen**
45
+ - TUI menu, numbered options, `[Y/n]` → `tta act send key` (keys only, not text)
46
+ - Free-form shell input → quoted heredoc, then Enter:
47
+
48
+ ```bash
49
+ tta act send text --sess=<name> <<'EOF'
50
+ <your input>
51
+ EOF
52
+ tta act send key --sess=<name> --key=enter
53
+ ```
54
+
55
+ Must use `<<'EOF'` (quoted delimiter), not `<<EOF`, or `$`, `()`, and backticks will be expanded by the shell.
56
+ 4. **After every `act`** — `tta obs screen stable --sess=<name>` to confirm the screen updated
57
+ 5. **Kill by session type** — kill one-shot CLI/TUI when done with `tta sess kill`; keep dev-server sessions until observation ends (see **Session lifecycle** table)
58
+ 6. **Process exited** — still use `obs` for errors and final output, then `tta sess kill`
59
+
60
+ ```text
61
+ sess start -> obs screen stable -> (act -> obs screen stable)* -> [sess kill]
62
+ ```
63
+
64
+ ## Three APIs
65
+
66
+ | API | Commands | Role | stdout |
67
+ |-----|----------|------|--------|
68
+ | **sess** | `start`, `kill`, `killall`, `list`, `keys`, `watch` | Create, stop, list sessions; human watch UI | `success` (start/kill); list: `name running` / `name exited exit_code=N` |
69
+ | **act** | `send text`, `send key` | Send input to a **running** session | `success` |
70
+ | **obs** | `screen now`, `screen stable`, `screen scroll` | Read a session's screen (running or exited) | screen text |
71
+
72
+ On failure: one line `error: <reason>` (exit 1).
73
+
74
+ ## Session lifecycle
75
+
76
+ | Session usage | Examples | Kill when done? |
77
+ |---------------|----------|-----------------|
78
+ | One-shot interactive CLI | `npm create vite@latest` | **Yes** |
79
+ | One-shot interactive TUI | `lazygit` | **Yes** |
80
+ | Long-running + observe | `npm run dev` | **No** while observing; kill when done |
81
+
82
+ Coding agent workers (multi-turn context) — see [`tta-agents-skill.md`](./tta-agents-skill.md).
83
+
84
+ **Naming:** one lowercase word, or 2–3 words joined by `-`, e.g. `dev`, `vite-once`.
85
+
86
+ **Exited sessions:** after the PTY process exits, the session stays `exited` in `sess list` until `tta sess kill`. `obs` still works; `act` fails. Read errors with `obs`, then `kill`.
87
+
88
+ **Rules:**
89
+
90
+ - `act` / `obs` require `--sess=` and an existing session
91
+ - Send text: `tta act send text --sess=<name> <<'EOF'` … `EOF` (quoted heredoc, `<<'EOF'`)
92
+ - Do not background `tta` calls; wait for each to finish
93
+ - Do not rely on `act` stdout; use `obs` to read the screen
94
+ - Do not use `tta sess watch`
95
+
96
+ ## Parameter quoting
97
+
98
+ | Flag | Used by | Quoting |
99
+ |------|---------|---------|
100
+ | `--cmd=` | sess start (**required**) | always `--cmd="..."` |
101
+ | `--cwd=` | sess start (**required**) | always `--cwd="..."`; prefer absolute paths |
102
+ | `--sess=` | sess start/kill, act, obs | not required |
103
+ | `--key=` | act send key | not required |
104
+ | `--dire=` | obs screen scroll | not required |
105
+ | send text input | act send text | always `<<'EOF'` |
106
+
107
+ **`sess start` template:**
108
+
109
+ ```bash
110
+ tta sess start --sess=<name> --cmd="<command>" --cwd="/absolute/path/to/project"
111
+ ```
112
+
113
+ Examples:
114
+
115
+ ```bash
116
+ tta sess start --sess=dev --cmd="npm run dev" --cwd="/Users/you/project"
117
+ tta sess start --sess=vite-once --cmd="npm create vite@latest" --cwd="/Users/you/project"
118
+ tta sess start --sess=lazy --cmd="lazygit" --cwd="/Users/you/project"
119
+ ```
120
+
121
+ **Common mistake:** an unquoted multi-word command is split by the shell; tta reports `too many arguments`:
122
+
123
+ ```bash
124
+ # wrong
125
+ tta sess start --sess=dev --cmd=npm run dev --cwd="/tmp"
126
+ # correct
127
+ tta sess start --sess=dev --cmd="npm run dev" --cwd="/tmp"
128
+ ```
129
+
130
+ ### `--cmd=` and `--cwd=`
131
+
132
+ `sess start` runs `--cmd=` in a PTY under `--cwd=` — the same command line you would type in a terminal. tta handles platform details; do not pick or configure a shell.
133
+
134
+ ## Prompts, choices, and confirmations
135
+
136
+ **TUI menus, numbered options, yes/no prompts — use `send key` only.** Do not use `send text` to pick TUI options.
137
+
138
+ | Screen | Use |
139
+ |--------|-----|
140
+ | TUI menu, list, `[Y/n]`, numbered choices | `send key` — `arrow_up` / `arrow_down` to move, `enter` to select or confirm |
141
+ | Free-form shell input | `tta act send text --sess=<name> <<'EOF'` … `EOF`, then `send key --key=enter` |
142
+
143
+ ### Send text (heredoc)
144
+
145
+ Same pattern for short and long input; `<<'EOF'` sends content literally to the PTY:
146
+
147
+ ```bash
148
+ tta act send text --sess=vite-once <<'EOF'
149
+ my-project-name
150
+ EOF
151
+ ```
152
+
153
+ **Must use `<<'EOF'` (quoted delimiter)** — not `<<EOF`, or `$()`, backticks, and `$var` will be expanded by the shell.
154
+
155
+ After every `act`, run `obs screen stable`.
156
+
157
+ ```bash
158
+ # TUI menu
159
+ tta act send key --sess=vite-once --key=arrow_down
160
+ tta act send key --sess=vite-once --key=enter
161
+ tta obs screen stable --sess=vite-once
162
+ ```
163
+
164
+ Run `tta sess keys` for supported key names.
165
+
166
+ ## Fallbacks
167
+
168
+ **Screen stuck (menu/confirm not advancing):**
169
+
170
+ 1. Try `send key --key=enter` first (accept default / confirm)
171
+ 2. Still stuck → try `arrow_up` / `arrow_down` or `tab`
172
+ 3. Run `obs screen stable` again to confirm progress
173
+
174
+ **`act` failed:**
175
+
176
+ 1. `tta sess list` — check `running` vs `exited`
177
+ 2. If `exited` → `obs screen stable` for errors, then `sess kill`
178
+ 3. If `running` but screen unchanged → check whether `send text` was used on a TUI menu by mistake
179
+
180
+ **Start failed (command not found, quoting error, etc.):**
181
+
182
+ ```bash
183
+ tta sess start --sess=bad --cmd="this-command-does-not-exist" --cwd="/Users/you/project"
184
+ tta sess list
185
+ tta obs screen stable --sess=bad
186
+ tta sess kill --sess=bad
187
+ ```
188
+
189
+ ## Commands
190
+
191
+ ```bash
192
+ tta sess start --sess=<name> --cmd="<command>" --cwd="/absolute/path/to/project"
193
+ tta sess kill --sess=<name>
194
+ tta sess killall
195
+ tta sess list
196
+ tta sess keys
197
+ tta sess watch # human-only
198
+
199
+ # send text: quoted heredoc
200
+ tta act send text --sess=<name> <<'EOF'
201
+ <text>
202
+ EOF
203
+ tta act send key --sess=<name> --key=<key>
204
+
205
+ tta obs screen now --sess=<name>
206
+ tta obs screen stable --sess=<name>
207
+ tta obs screen scroll --sess=<name> --dire=<up|down|top|bottom>
208
+ ```
209
+
210
+ ## Examples
211
+
212
+ ```bash
213
+ # One-shot: kill when done
214
+ tta sess start --sess=vite-once --cmd="npm create vite@latest" --cwd="/Users/you/project"
215
+ tta obs screen stable --sess=vite-once
216
+ tta act send key --sess=vite-once --key=enter
217
+ tta obs screen stable --sess=vite-once
218
+ tta sess kill --sess=vite-once
219
+
220
+ # Dev server: keep, use obs
221
+ tta sess start --sess=dev --cmd="npm run dev" --cwd="/Users/you/project"
222
+ tta obs screen stable --sess=dev
223
+ tta sess kill --sess=dev
224
+ ```
225
+
226
+ Coding agent worker examples — see [`tta-agents-skill.md`](./tta-agents-skill.md).
@@ -0,0 +1,200 @@
1
+ ---
2
+ name: tta-agents
3
+ version: 0.1.3
4
+ description: Bundled tta sub-skill. When triggered: current agent is Orchestrator; serially schedules multiple workers (separated concerns, e.g. code/review/test). Workers cannot use tta; feedback relayed by Orchestrator. Must obey user permission scope. Use when driving coding agents via tta or when user mentions Orchestrator/Worker.
5
+ ---
6
+
7
+ # tta-agents - orchestrate coding agents with tta
8
+
9
+ **This file is a bundled sub-skill of the [tta skill](./SKILL.md).** When read, **immediately adopt the Orchestrator role**.
10
+
11
+ **Prerequisites:** `tta` CLI installed and tta skill loaded. Architecture: [`docs/tta-agents-docs.md`](../../docs/tta-agents-docs.md).
12
+
13
+ ## You are the Orchestrator
14
+
15
+ **The agent using tta is the Orchestrator.** **You** are the Orchestrator, not a worker.
16
+
17
+ | Role | Who | Can use tta? |
18
+ |------|-----|--------------|
19
+ | **Orchestrator** | **You** | **Yes** |
20
+ | **Worker** | Coding agent CLI you start with `tta sess start` | **No** |
21
+
22
+ Workers must not call tta, load tta skill, or spawn sub-workers.
23
+
24
+ ## Orchestrator workflow (required reading)
25
+
26
+ The Orchestrator **manages workers** via tta and may **use tta on ordinary sessions** in the same task (TUI, dev server, etc.; see tta skill).
27
+
28
+ For **long, multi-step** tasks:
29
+
30
+ 1. Split into **phases** (e.g. phase one: implement → review → fix → test; phase two: …)
31
+ 2. Use **multiple workers for separated concerns** (e.g. `worker-coder`, `worker-reviewer`, `worker-test`)
32
+ 3. **Serial scheduling** — on one task chain, **advance only one worker step at a time**; after it completes and you summarize, assign the next step
33
+
34
+ **Workers do not talk to each other.** The flow is always:
35
+
36
+ ```text
37
+ Assign → obs until worker completes → Orchestrator reads screen, summarizes
38
+ → Orchestrator decides next step
39
+ → Assign to next worker (or send feedback back to previous worker)
40
+ → loop until phase/task completes
41
+ ```
42
+
43
+ Example phase one:
44
+
45
+ - Assign “implement” to **coding worker** → wait → **you** summarize changes
46
+ - Send summary to **review worker** → wait → **you** summarize review feedback
47
+ - **Relay** review feedback to **coding worker** to fix → wait → **you** summarize
48
+ - Send summary to **test worker** → wait → **you** summarize test results → decide phase two or revisit a step
49
+
50
+ You may keep multiple worker **sessions** open (each keeps context), but **scheduling must be serial**: review starts only after coding finishes and **you relay**; **forbid** two workers parallelizing the same step.
51
+
52
+ ## Worker constraints
53
+
54
+ 1. **Workers cannot use tta**
55
+ 2. **Workers default to auto mode** — start commands below; prompt is authorization
56
+ 3. **Every prompt must include:** forbid tta, task, directory, Allowed / Forbidden
57
+
58
+ ## Permissions
59
+
60
+ The Orchestrator **must** obey the user’s permission scope; **fully write** Allowed / Forbidden when assigning workers; read screens to **prevent worker overreach**; stop and report if overreach occurs. Information passed between workers must stay within user authorization (e.g. if review is read-only, do not let coder worker include unauthorized actions in feedback).
61
+
62
+ **Assignment prompt template:**
63
+
64
+ ```bash
65
+ tta act send text --sess=worker-coder-claude <<'EOF'
66
+ You are a coding worker. Do NOT use tta or spawn sub-agents.
67
+
68
+ Task: <concrete step task>
69
+ Working directory: /absolute/path/to/project
70
+
71
+ Allowed:
72
+ - ...
73
+
74
+ Forbidden:
75
+ - ...
76
+ - Using tta
77
+
78
+ When done, summarize what you did (files changed, test status).
79
+ EOF
80
+ tta act send key --sess=worker-coder-claude --key=enter
81
+ ```
82
+
83
+ When **relaying review feedback to coder**, state in the prompt that feedback comes from the Orchestrator and paste your summarized review points; do not let workers assume they can contact the reviewer directly.
84
+
85
+ ## Session and Worker
86
+
87
+ **Worker ⊆ Session.** Naming: `worker-coder-claude`, `worker-reviewer-codex`, `worker-test-pi`.
88
+
89
+ ## Orchestrator responsibilities
90
+
91
+ 1. Start / maintain worker sessions (avoid kill until task ends, keep context)
92
+ 2. Serial loop: assign → `obs screen stable` → summarize → think → next assignment
93
+ 3. **Relay** results and feedback between workers (do not assume workers know each other)
94
+ 4. When needed, use tta on **non-worker** sessions (e.g. `npm run dev` to observe logs)
95
+ 5. Enforce permissions; do not act beyond user authorization
96
+
97
+ ## Standard workflow (single step)
98
+
99
+ 1. Confirm you are Orchestrator; clarify user permissions and task phases
100
+ 2. `tta sess start --sess=worker-<role>-<name> --cmd="..." --cwd="/absolute/path"`
101
+ 3. `tta obs screen stable`
102
+ 4. `tta act send text` (heredoc) + Enter
103
+ 5. `obs screen stable` → **summarize** → decide next worker or send back
104
+ 6. Repeat until phase completes
105
+
106
+ ## Worker start commands (auto mode)
107
+
108
+ | Coding Agent | `--cmd="..."` |
109
+ |--------------|---------------|
110
+ | Claude Code | `claude --dangerously-skip-permissions` |
111
+ | Codex | `codex --sandbox workspace-write --ask-for-approval never` |
112
+ | Cursor Agent | `agent --yolo --sandbox disabled` |
113
+ | OpenCode | `opencode --yolo` |
114
+ | Pi | `pi` |
115
+ | Kimi Code | `kimi --auto` |
116
+
117
+ ## Example: single worker (simple task)
118
+
119
+ ```bash
120
+ tta sess start --sess=worker-coder-claude --cmd="claude --dangerously-skip-permissions" --cwd="/Users/you/project"
121
+ tta obs screen stable --sess=worker-coder-claude
122
+ tta act send text --sess=worker-coder-claude <<'EOF'
123
+ You are a worker. Do NOT use tta.
124
+ Task: Fix auth bug, run npm test, summarize.
125
+ Working directory: /Users/you/project
126
+ Allowed: edit src/, run npm test
127
+ Forbidden: git push, deploy, using tta
128
+ EOF
129
+ tta act send key --sess=worker-coder-claude --key=enter
130
+ tta obs screen stable --sess=worker-coder-claude
131
+ # Orchestrator reads screen and summarizes; sess kill when task ends
132
+ ```
133
+
134
+ ## Example: multiple workers serial (implement → review → fix → test)
135
+
136
+ **Separated concerns, serial Orchestrator scheduling.** Workers do not talk; feedback is **relayed by you**.
137
+
138
+ ```bash
139
+ # --- 0. Optionally start multiple worker sessions upfront (each keeps context) ---
140
+ tta sess start --sess=worker-coder-claude --cmd="claude --dangerously-skip-permissions" --cwd="/Users/you/project"
141
+ tta sess start --sess=worker-reviewer-codex --cmd="codex --sandbox workspace-write --ask-for-approval never" --cwd="/Users/you/project"
142
+ tta sess start --sess=worker-test-pi --cmd="pi" --cwd="/Users/you/project"
143
+
144
+ # --- 1. Implement (only coding worker active; others wait) ---
145
+ tta obs screen stable --sess=worker-coder-claude
146
+ tta act send text --sess=worker-coder-claude <<'EOF'
147
+ Do NOT use tta. Implement feature X in src/. Summarize changes when done.
148
+ Allowed: edit src/, run npm test
149
+ Forbidden: git push, using tta
150
+ EOF
151
+ tta act send key --sess=worker-coder-claude --key=enter
152
+ tta obs screen stable --sess=worker-coder-claude
153
+ # Orchestrator: read screen, draft change summary; do not touch reviewer yet
154
+
155
+ # --- 2. Review (coding done; Orchestrator sends summary to reviewer) ---
156
+ tta obs screen stable --sess=worker-reviewer-codex
157
+ tta act send text --sess=worker-reviewer-codex <<'EOF'
158
+ Do NOT use tta. Review the following changes (from Orchestrator, not from another agent):
159
+
160
+ <paste Orchestrator's summarized change summary>
161
+
162
+ List issues and suggestions. Summarize when done.
163
+ Forbidden: editing files, using tta
164
+ EOF
165
+ tta act send key --sess=worker-reviewer-codex --key=enter
166
+ tta obs screen stable --sess=worker-reviewer-codex
167
+ # Orchestrator: read screen, draft review feedback
168
+
169
+ # --- 3. Fix (Orchestrator relays review to coder; wait until step 2 completes) ---
170
+ tta obs screen stable --sess=worker-coder-claude
171
+ tta act send text --sess=worker-coder-claude <<'EOF'
172
+ Do NOT use tta. Address the following review feedback (from Orchestrator):
173
+
174
+ <paste Orchestrator's summarized review feedback>
175
+
176
+ Summarize what you fixed.
177
+ EOF
178
+ tta act send key --sess=worker-coder-claude --key=enter
179
+ tta obs screen stable --sess=worker-coder-claude
180
+
181
+ # --- 4. Test (Orchestrator sends summary to test worker) ---
182
+ tta obs screen stable --sess=worker-test-pi
183
+ tta act send text --sess=worker-test-pi <<'EOF'
184
+ Do NOT use tta. Run npm test and report results.
185
+ Context from Orchestrator: <change and fix summary>
186
+ EOF
187
+ tta act send key --sess=worker-test-pi --key=enter
188
+ tta obs screen stable --sess=worker-test-pi
189
+ # Orchestrator: summarize test results → phase two or revisit a step
190
+
191
+ # When full task ends: tta sess kill --sess=worker-coder-claude etc.
192
+ ```
193
+
194
+ ## Failures and fallbacks
195
+
196
+ - **Worker unresponsive:** `sess list` → `obs screen stable`
197
+ - **Worker overreach:** stop / kill, report user
198
+ - **No parallel step stealing:** do not assign reviewer while coding is incomplete
199
+
200
+ **Split:** ordinary TUI / dev server → tta skill; coding agent task chains → this skill, **serial** Orchestrator loop.
Binary file