This repository was archived by the owner on Aug 17, 2026. It is now read-only.
Repository navigation
Commit 5801c06
committed
feat(grunt/tui): bare
## Goal
Bare `gruntcode` (no subcommand) should Just Work — the launched TUI is
automatically wakeable. No `serve` + `attach` two-command dance, no
shell wrapper.
Nik framing 2026-05-26: "like i run gruntcode and things can get woken
up via hivemind".
## Behavior of bare `gruntcode` now
1. Probes http://127.0.0.1:4096/session — if a daemon is already serving
there, attach to it.
2. If no daemon: spawns one as a detached child (`gruntcode serve
--port 4096 --hostname 127.0.0.1 --print-logs`), waits up to 10s for
readiness.
3. Re-execs into `gruntcode attach <url>` with all the relevant args
passed through (--peer-id, --dir, --continue, --session, --fork). The
user sees an unchanged TUI; implementation detail (the daemon) is
hidden behind the bare command.
4. Daemon survives the TUI exit — second bare `gruntcode` invocation
reuses it.
## Escape hatches
- `OPENCODE_DISABLE_AUTO_SERVE=1` skips the auto-serve and uses the
legacy in-process worker (the path used today by upstream opencode).
- `OPENCODE_AUTO_SERVE_PORT` / `OPENCODE_AUTO_SERVE_HOST` override the
defaults (4096 / 127.0.0.1).
## Implementation
- New `packages/opencode/src/cli/cmd/tui/auto-serve.ts` exports
`ensureServeDaemon()`. Returns `{ok: true, url, bin}` or `{ok: false, reason}`.
Logic:
- Resolves gruntcode binary path (argv0 if compiled binary; `which
gruntcode` if running via `bun run` in dev mode; fallback to `which
opencode`).
- Probes /session with 1.5s timeout.
- If 200 → returns the URL.
- If connection refused → spawns daemon as detached child, polls
/session every 200ms until ready or 10s timeout.
- `packages/opencode/src/cli/cmd/tui/thread.ts` handler calls
`ensureServeDaemon()` early. On success: builds attach argv from
current args and re-execs via child_process.spawn with stdio inherited.
On failure: logs the reason and falls through to the existing
in-process worker path.
## Verification
End-to-end manual test:
1. Killed existing daemon. Confirmed `curl :4096/session` returns connection refused.
2. Launched bare TUI from patched source: `bun run src/index.ts --peer-id nik-test --project /tmp`.
3. Process tree showed: bun run → child `gruntcode serve --port 4096 ...` AND child
`gruntcode attach http://127.0.0.1:4096 --dir /tmp --peer-id nik-test`.
4. `curl :4096/session` returned 200 with the active session.
5. `curl -X POST :4096/session/<id>/prompt_async` accepted (204) and the
daemon log showed the LLM running. The wake response 'BARE-CMD-WORKS'
was written to opencode.db (verified via `/session/<id>/message`).
## Known follow-up
The wake response sometimes doesn't render visually in the TUI even
though it's persisted server-side. This is a separate refinement of
patch 2c (SSE subscription) that needs investigation — the wake is
audit-complete and the system works for autonomous coordination, but
human-watcher UX needs polish. Tracked in hivemind anomalyco#221.
Refs hivemind anomalyco#224.gruntcode auto-spawns serve + attaches (one-command wakeable TUI) (#5)1 parent 13af607 commit 5801c06
2 files changed
Lines changed: 150 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
138 | 172 | | |
139 | 173 | | |
140 | 174 | | |
| |||
0 commit comments