Commit 95a6543
feat(ssh): add -o json support for --setup-only (#106)
## Summary
- Adds `-o json` flag to `kernel browsers ssh --setup-only` for
machine-readable output
- When set, suppresses all pterm progress messages and emits a JSON
object to stdout with `vm_domain`, `session_id`, `ssh_key_file`,
`proxy_command`, and `ssh_command`
- Skips ephemeral key cleanup when JSON output is used so the key file
remains available for the caller
## Motivation
Scripting around `--setup-only` currently requires fragile `grep`/`awk`
parsing of human-readable output:
```bash
OUTPUT=$(kernel browsers ssh "$SESSION_ID" -i /tmp/kernel-scp-key --setup-only 2>&1)
VM_DOMAIN=$(echo "$OUTPUT" | grep "VM domain:" | awk '{print $NF}')
```
With `-o json`, this becomes:
```bash
SETUP=$(kernel browsers ssh "$SESSION_ID" -i /tmp/kernel-scp-key --setup-only -o json)
VM_DOMAIN=$(echo "$SETUP" | jq -r '.vm_domain')
```
## Example output
```json
{
"vm_domain": "actual-vm-domain.onkernel.app",
"session_id": "abc123",
"ssh_key_file": "/tmp/kernel-scp-key",
"proxy_command": "websocat --binary wss://actual-vm-domain.onkernel.app:2222",
"ssh_command": "ssh -o 'ProxyCommand=websocat --binary wss://...:2222' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/kernel-scp-key root@localhost"
}
```
## Test plan
- [ ] Run `kernel browsers ssh <id> -i <key> --setup-only -o json` and
verify clean JSON on stdout
- [ ] Run `kernel browsers ssh <id> --setup-only -o json` (ephemeral
key) and verify key file is not cleaned up
- [ ] Run `kernel browsers ssh <id> --setup-only` without `-o` and
verify existing behavior is unchanged
- [ ] Run `kernel browsers ssh <id> -o json` without `--setup-only` and
verify it errors
- [ ] Run `kernel browsers ssh <id> -o yaml` and verify it errors
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> CLI-only behavior changes gated behind `--setup-only -o json`, with
limited impact on the default interactive SSH path; main risk is leaving
temporary key files behind when JSON output is used.
>
> **Overview**
> Adds `-o/--output json` support to `kernel browsers ssh` when used
with `--setup-only`, emitting a single JSON object (vm domain, session
id, key path, and ready-to-run proxy/ssh commands) for scripting.
>
> When JSON output is enabled, progress/log messaging is suppressed,
`setupVMSSH` gains a quiet mode for key-injection/setup messaging, and
ephemeral key cleanup is skipped so callers can reuse the generated key
file; invalid output formats and `-o json` without `--setup-only` now
error.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
405d824. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 4d9565b commit 95a6543
2 files changed
Lines changed: 62 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
| |||
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
| 62 | + | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
| |||
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
63 | 82 | | |
64 | 83 | | |
65 | 84 | | |
66 | 85 | | |
67 | 86 | | |
68 | 87 | | |
69 | 88 | | |
| 89 | + | |
70 | 90 | | |
71 | 91 | | |
72 | 92 | | |
73 | 93 | | |
74 | 94 | | |
75 | 95 | | |
| 96 | + | |
| 97 | + | |
76 | 98 | | |
77 | 99 | | |
78 | 100 | | |
79 | 101 | | |
80 | 102 | | |
81 | 103 | | |
82 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
83 | 107 | | |
84 | 108 | | |
85 | 109 | | |
| |||
95 | 119 | | |
96 | 120 | | |
97 | 121 | | |
98 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
99 | 125 | | |
100 | 126 | | |
101 | 127 | | |
| |||
104 | 130 | | |
105 | 131 | | |
106 | 132 | | |
107 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
108 | 136 | | |
109 | 137 | | |
110 | 138 | | |
| |||
117 | 145 | | |
118 | 146 | | |
119 | 147 | | |
120 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
121 | 151 | | |
122 | 152 | | |
123 | 153 | | |
| |||
134 | 164 | | |
135 | 165 | | |
136 | 166 | | |
137 | | - | |
138 | | - | |
| 167 | + | |
| 168 | + | |
139 | 169 | | |
140 | 170 | | |
141 | 171 | | |
142 | 172 | | |
143 | 173 | | |
144 | 174 | | |
145 | 175 | | |
146 | | - | |
147 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
148 | 180 | | |
149 | 181 | | |
150 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
151 | 185 | | |
152 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
153 | 201 | | |
154 | 202 | | |
155 | 203 | | |
| |||
192 | 240 | | |
193 | 241 | | |
194 | 242 | | |
195 | | - | |
| 243 | + | |
196 | 244 | | |
197 | 245 | | |
198 | 246 | | |
| |||
205 | 253 | | |
206 | 254 | | |
207 | 255 | | |
208 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
209 | 259 | | |
210 | 260 | | |
211 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
0 commit comments