Commit f6a7ba3
authored
Add output formats, interactive table browser, and multi-chunk results (#4646)
## Why
The `aitools tools query` command outputs results as JSON to stderr via
`cmdio.LogString`. This means output can't be piped, there's no tabular
display for interactive use, and large multi-chunk results are truncated
to the first chunk.
## Changes
Before: always JSON to stderr, single chunk only.
Now: format-aware output routing with interactive table browser.
**Output routing:**
- Interactive terminal (stdout is TTY): table display
- Small results (<=30 rows): static formatted table, prints and exits
- Large results (>30 rows): interactive browser with scrolling and
search
- Non-interactive (piped stdout) or `--output json`: JSON array of
objects (backwards compatible)
- All output goes to stdout, not stderr
**Interactive table browser (`libs/tableview/`):**
Reusable shared component using `bubbles/viewport`. Features:
- Horizontal + vertical scrolling (arrow keys, pgup/pgdn)
- Cursor row highlighting (purple background)
- `/` search with yellow match highlighting, `n`/`N` to navigate matches
- `g`/`G` for top/bottom, `q` to quit
- Footer with row count, scroll position, keybinding hints
**Multi-chunk fetching:**
Queries returning more data than fits in a single response chunk now
fetch all chunks via `GetStatementResultChunkN` and combine them.
https://github.com/user-attachments/assets/60b299aa-01ef-4b75-89e0-1f15dac05e42
https://github.com/user-attachments/assets/86747be1-6c94-4399-b0f3-dd2fc25f3df8
## Test plan
- [x] Unit tests for `libs/tableview` (table rendering, search,
highlighting)
- [x] Unit tests for renderers (JSON format, static table,
extractColumns)
- [x] Unit tests for `fetchAllRows` (single chunk, multi-chunk, nil
result)
- [x] All existing query tests pass (polling, cancellation, input
resolution)
- [x] `make lintfull` clean
- [x] `make checks` clean
- [x] Manual: interactive table with scrolling and search
- [x] Manual: `| cat` produces JSON
- [x] Manual: `--output json` forces JSON1 parent 1d44462 commit f6a7ba3
6 files changed
Lines changed: 776 additions & 63 deletions
File tree
- experimental/aitools/cmd
- libs/tableview
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
39 | 69 | | |
40 | 70 | | |
41 | 71 | | |
| |||
52 | 82 | | |
53 | 83 | | |
54 | 84 | | |
55 | | - | |
| 85 | + | |
| 86 | + | |
56 | 87 | | |
57 | 88 | | |
58 | 89 | | |
| |||
79 | 110 | | |
80 | 111 | | |
81 | 112 | | |
82 | | - | |
| 113 | + | |
| 114 | + | |
83 | 115 | | |
84 | 116 | | |
85 | 117 | | |
86 | 118 | | |
87 | | - | |
88 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
89 | 137 | | |
90 | 138 | | |
91 | 139 | | |
| |||
274 | 322 | | |
275 | 323 | | |
276 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
277 | 350 | | |
278 | 351 | | |
279 | 352 | | |
| |||
334 | 407 | | |
335 | 408 | | |
336 | 409 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
163 | 226 | | |
164 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
165 | 230 | | |
166 | | - | |
| 231 | + | |
| 232 | + | |
167 | 233 | | |
168 | | - | |
| 234 | + | |
169 | 235 | | |
170 | 236 | | |
171 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
172 | 241 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
182 | 245 | | |
183 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
184 | 264 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 265 | + | |
188 | 266 | | |
189 | 267 | | |
190 | 268 | | |
| |||
0 commit comments