Skip to content

Commit da9bcea

Browse files
committed
Add YAML-based tmux session logging and OpenTUI viewer
- Update tmux helper scripts to use YAML format: - session-info.yaml for session metadata - commands.yaml for command history - YAML front-matter on capture files - Create .agents/tmux-viewer/ OpenTUI package: - Interactive TUI for viewing session captures chronologically - --json flag for AI consumption (single source of truth) - --list flag to show available sessions - Timeline navigation with arrow keys - Update cli-tmux-tester.ts to reference new viewer tool - Update README.md with new YAML format documentation
1 parent 128d963 commit da9bcea

File tree

17 files changed

+1251
-33
lines changed

17 files changed

+1251
-33
lines changed

.agents/cli-tmux-tester.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,52 @@ sleep 2
186186
187187
## Session Logs (Paper Trail)
188188
189-
Captures are **automatically saved** to \`debug/tmux-sessions/{session-name}/\` whenever you capture output.
189+
All session data is stored in **YAML format** in \`debug/tmux-sessions/{session-name}/\`:
190+
191+
- \`session-info.yaml\` - Session metadata (start time, dimensions, status)
192+
- \`commands.yaml\` - YAML array of all commands sent with timestamps
193+
- \`capture-{sequence}-{label}.txt\` - Captures with YAML front-matter
190194
191195
\`\`\`bash
192196
# Capture with a descriptive label (recommended)
193197
./scripts/tmux/tmux-cli.sh capture "$SESSION" --label "after-help-command" --wait 2
194198
195-
# Capture saved to: debug/tmux-sessions/{session}/capture-{timestamp}-after-help-command.txt
199+
# Capture saved to: debug/tmux-sessions/{session}/capture-001-after-help-command.txt
200+
\`\`\`
201+
202+
Each capture file has YAML front-matter with metadata:
203+
\`\`\`yaml
204+
---
205+
sequence: 1
206+
label: after-help-command
207+
timestamp: 2025-01-01T12:00:30Z
208+
after_command: "/help"
209+
dimensions:
210+
width: 120
211+
height: 30
212+
---
213+
[terminal content]
196214
\`\`\`
197215
198216
The capture path is printed to stderr. Both you and the parent agent can read these files to see exactly what the CLI displayed.
199217
218+
## Viewing Session Data
219+
220+
Use the **tmux-viewer** to inspect session data interactively or as JSON:
221+
222+
\`\`\`bash
223+
# Interactive TUI (for humans)
224+
bun .agents/tmux-viewer/index.tsx "$SESSION"
225+
226+
# JSON output (for AIs) - includes all captures, commands, and timeline
227+
bun .agents/tmux-viewer/index.tsx "$SESSION" --json
228+
229+
# List available sessions
230+
bun .agents/tmux-viewer/index.tsx --list
231+
\`\`\`
232+
233+
The viewer parses all YAML data (session-info.yaml, commands.yaml, capture front-matter) and presents it in a unified format.
234+
200235
## Debugging Tips
201236
202237
- **Attach interactively**: \`tmux attach -t SESSION_NAME\`

.agents/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"typecheck": "bun x tsc --noEmit -p tsconfig.json",
88
"test": "bun test __tests__",
9-
"test:e2e": "bun test e2e"
9+
"test:e2e": "bun test e2e",
10+
"view-session": "bun run tmux-viewer/index.tsx"
1011
}
1112
}

.agents/tmux-viewer/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# tmux-viewer
2+
3+
Interactive TUI for viewing tmux session logs. Designed to work for **both humans and AIs**.
4+
5+
## Usage
6+
7+
```bash
8+
# Interactive TUI (for humans)
9+
bun .agents/tmux-viewer/index.tsx <session-name>
10+
11+
# JSON output (for AIs)
12+
bun .agents/tmux-viewer/index.tsx <session-name> --json
13+
14+
# List available sessions
15+
bun .agents/tmux-viewer/index.tsx --list
16+
17+
# View most recent session (if no session specified)
18+
bun .agents/tmux-viewer/index.tsx
19+
```
20+
21+
Or using the npm script:
22+
23+
```bash
24+
cd .agents && bun run view-session <session-name>
25+
```
26+
27+
## Features
28+
29+
### For Humans (Interactive TUI)
30+
- **Timeline panel**: Navigate through captures with ↑↓ arrows
31+
- **Capture panel**: View terminal output at each point in time
32+
- **Metadata display**: Session info, dimensions, command count
33+
- **Keyboard shortcuts**:
34+
- `↑↓` or `jk`: Navigate captures
35+
- `←→` or `hl`: Switch panels
36+
- `q` or Ctrl+C: Quit
37+
- Use the `--json` flag on the CLI entrypoint for JSON output
38+
39+
### For AIs (JSON Output)
40+
Use the `--json` flag to get structured output:
41+
42+
```json
43+
{
44+
"session": {
45+
"session": "cli-test-1234567890",
46+
"started": "2025-01-01T12:00:00Z",
47+
"dimensions": { "width": 120, "height": 30 },
48+
"status": "active"
49+
},
50+
"commands": [
51+
{ "timestamp": "...", "type": "text", "input": "/help", "auto_enter": true }
52+
],
53+
"captures": [
54+
{
55+
"sequence": 1,
56+
"label": "initial-state",
57+
"timestamp": "...",
58+
"after_command": null,
59+
"dimensions": { "width": 120, "height": 30 },
60+
"path": "debug/tmux-sessions/.../capture-001-initial-state.txt",
61+
"content": "[terminal output]"
62+
}
63+
],
64+
"timeline": [
65+
{ "timestamp": "...", "type": "command", "data": {...} },
66+
{ "timestamp": "...", "type": "capture", "data": {...} }
67+
]
68+
}
69+
```
70+
71+
## Data Format
72+
73+
The viewer reads YAML-formatted session data from `debug/tmux-sessions/{session}/`:
74+
75+
- `session-info.yaml` - Session metadata
76+
- `commands.yaml` - Array of commands sent
77+
- `capture-*.txt` - Capture files with YAML front-matter
78+
79+
### Session Info (session-info.yaml)
80+
```yaml
81+
session: cli-test-1234567890
82+
started: 2025-01-01T12:00:00Z
83+
started_local: Wed Jan 1 12:00:00 PST 2025
84+
dimensions:
85+
width: 120
86+
height: 30
87+
status: active
88+
```
89+
90+
### Commands (commands.yaml)
91+
```yaml
92+
- timestamp: 2025-01-01T12:00:05Z
93+
type: text
94+
input: "/help"
95+
auto_enter: true
96+
```
97+
98+
### Capture Files (capture-001-label.txt)
99+
```yaml
100+
---
101+
sequence: 1
102+
label: initial-state
103+
timestamp: 2025-01-01T12:00:30Z
104+
after_command: null
105+
dimensions:
106+
width: 120
107+
height: 30
108+
---
109+
[terminal content here]
110+
```
111+
112+
## Integration with cli-tmux-tester
113+
114+
The `@cli-tmux-tester` agent can use this viewer to inspect session data:
115+
116+
```typescript
117+
// In cli-tmux-tester output
118+
{
119+
captures: [
120+
{ path: "debug/tmux-sessions/cli-test-123/capture-001-initial.txt", label: "initial" }
121+
]
122+
}
123+
124+
// Parent agent can view the session
125+
// bun .agents/tmux-viewer/index.tsx cli-test-123 --json
126+
```
127+
128+
## Development
129+
130+
```bash
131+
# Typecheck
132+
cd .agents && bun run typecheck
133+
134+
# Run directly
135+
bun .agents/tmux-viewer/index.tsx --list
136+
```

0 commit comments

Comments
 (0)