-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cli): readable go-code startup output #1414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,42 @@ | ||
| # Engineering Log | ||
|
|
||
| ## 2026-09-08 — Issue #1413 readable go-code startup output | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding issue #1413 as the newest engineering-log entry materially changes that file, but AGENTS.md reference: AGENTS.md:L55-L56 Useful? React with 👍 / 👎. |
||
|
|
||
| - Symptom: `go-code` printed 13 lines of undifferentiated output on a normal | ||
| startup, mixing three different voices with no visual separation — the | ||
| wrapper's own `[go-code] ...` status lines, harnessd's own boot log (since | ||
| the daemon inherited the wrapper's stdout), and (on failure) a fatal error — | ||
| so the one actionable line was buried in the noise. Because the daemon | ||
| inherited the terminal, a stray daemon log line could also render into the | ||
| TUI after handoff, not just during startup. | ||
| - Cause: `scripts/go-code.sh`'s three one-line output helpers (`info`, `warn`, | ||
| `die`) gave every line the same undifferentiated `[go-code] ...` prefix with | ||
| no severity distinction, and `start_server()` let harnessd inherit the | ||
| wrapper's stdout/stderr instead of capturing them. | ||
| - Fix: color detection now runs once at startup into `COLOR_STDOUT` / | ||
| `COLOR_STDERR` (disabled under `NO_COLOR`, `TERM=dumb`, or when the relevant | ||
| stream isn't a terminal), feeding a `style` helper; `info` is cyan-prefixed, | ||
| `warn` yellow, `die` red, with the literal words `WARN:`/`ERROR:` always kept | ||
| in the text so severity never depends on color alone. A wrapper-started | ||
| harnessd now writes to `${TMPDIR:-/tmp}/harnessd.<pid>.log` (created with | ||
| `umask 077`) instead of the terminal. On success the wrapper prints | ||
| `server ready at <url>` plus a `log: <path>` line, and the daemon boot log no | ||
| longer appears at all. On failure, `die` calls `show_harnessd_log`, which | ||
| prints a `harnessd said:` block with the last 20 log lines indented four | ||
| spaces (lines matching `fatal:`, `panic:`, or `refusing to start` in bold | ||
| red, everything else dimmed) followed by `full log: <path>`. | ||
| - Gotcha (the durable lesson here): the first implementation tested `[[ -t 1 ]]` | ||
| lazily, inside the `style` helper itself. But `style` is invoked from | ||
| command substitution (`$(style ...)`), where `$( )` only redirects stdout — | ||
| so inside that substitution, fd 1 is a pipe, not the terminal, and stdout | ||
| was never colored even on a real tty, while stderr colored correctly. Color | ||
| detection has to happen once at startup, before any command substitution | ||
| runs. This was caught by looking at real rendered pty output, not by the | ||
| test suite — the tests (`TestGoCodeScriptEmitsNoAnsiWhenNotATty`, | ||
| `TestGoCodeScriptSurfacesHarnessdLogOnStartupFailure`, both in | ||
| `cmd/harnesscli/go_code_script_test.go`) check the no-color and log-surfacing | ||
| paths but don't exercise a real tty, so they would have passed either way. | ||
|
|
||
| ## 2026-09-08 — Issue #1411 go-code wrapper bound harnessd beyond loopback | ||
|
|
||
| - Symptom: plain `go-code` (no flags) died on a clean machine with no API key | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,9 +62,59 @@ Description: | |
| EOF | ||
| } | ||
|
|
||
| info() { printf '[go-code] %s\n' "$*"; } | ||
| warn() { printf '[go-code] WARN: %s\n' "$*" >&2; } | ||
| die() { printf '[go-code] ERROR: %s\n' "$*" >&2; exit 1; } | ||
| # Color is an enhancement, never the only signal: the WARN:/ERROR: words stay in | ||
| # the text, so severity survives a monochrome terminal, a pipe, a captured log, | ||
| # and colorblind readers. Only the 8 standard ANSI colors are used, so each | ||
| # terminal applies its own theme and nothing turns invisible on a light | ||
| # background. Issue #1413. | ||
| # | ||
| # Support is detected once, here, and must not be tested lazily inside style(): | ||
| # style() is called from command substitution, where stdout is a pipe rather | ||
| # than the terminal, so an `-t 1` check there is always false and stdout would | ||
| # never be colored. stdout and stderr are tracked separately because either can | ||
| # be redirected on its own. | ||
| COLOR_STDOUT=0 | ||
| COLOR_STDERR=0 | ||
| if [[ -z "${NO_COLOR:-}" && "${TERM:-}" != "dumb" ]]; then | ||
| [[ -t 1 ]] && COLOR_STDOUT=1 | ||
| [[ -t 2 ]] && COLOR_STDERR=1 | ||
| fi | ||
|
|
||
| # style <stream-fd> <sgr> <text> — style text only when that stream is a terminal. | ||
| style() { | ||
| local enabled="$COLOR_STDOUT" | ||
| [[ "$1" == "2" ]] && enabled="$COLOR_STDERR" | ||
| if [[ "$enabled" == "1" ]]; then | ||
| printf '\033[%sm%s\033[0m' "$2" "$3" | ||
| else | ||
| printf '%s' "$3" | ||
| fi | ||
| } | ||
|
|
||
| info() { printf '%s %s\n' "$(style 1 '36' '[go-code]')" "$*"; } | ||
| warn() { printf '%s %s %s\n' "$(style 2 '33' '[go-code]')" "$(style 2 '1;33' 'WARN:')" "$*" >&2; } | ||
| die() { printf '%s %s %s\n' "$(style 2 '31' '[go-code]')" "$(style 2 '1;31' 'ERROR:')" "$*" >&2; show_harnessd_log; exit 1; } | ||
|
|
||
| # show_harnessd_log prints the captured daemon log when a wrapper-started | ||
| # harnessd failed. The daemon's stdout is redirected to a file so a healthy | ||
| # start is not buried in boot noise and no log line can scribble into the TUI | ||
| # after handoff — which means a failure has to bring that output back, or the | ||
| # operator is left with no reason at all. Lines are colored per logical line, so | ||
| # a long fatal message stays emphasized across the terminal's soft wrap. | ||
| show_harnessd_log() { | ||
| [[ -n "${HARNESSD_LOG:-}" && -s "${HARNESSD_LOG:-}" ]] || return 0 | ||
| printf '\n %s\n' "$(style 2 '1' 'harnessd said:')" >&2 | ||
| local line | ||
| while IFS= read -r line; do | ||
| case "$line" in | ||
| *fatal:*|*panic:*|*"refusing to start"*) | ||
| printf ' %s\n' "$(style 2 '1;31' "$line")" >&2 ;; | ||
| *) | ||
| printf ' %s\n' "$(style 2 '2' "$line")" >&2 ;; | ||
| esac | ||
| done < <(tail -n 20 "$HARNESSD_LOG") | ||
| printf '\n %s %s\n\n' "$(style 2 '2' 'full log:')" "$HARNESSD_LOG" >&2 | ||
| } | ||
|
|
||
| require_command() { | ||
| local cmd="$1" | ||
|
|
@@ -184,7 +234,7 @@ start_server() { | |
| local port="${1}" | ||
| local base_url="${2}" | ||
|
|
||
| info "no server at ${base_url}, starting harnessd on port ${port}" | ||
| info "starting harnessd on port ${port}" | ||
|
|
||
| local harnessd_bin | ||
| harnessd_bin="$(command -v harnessd)" | ||
|
|
@@ -202,7 +252,10 @@ start_server() { | |
| # harnessd's bind guard (cmd/harnessd/bind_guard.go, issue #1328) refuses to | ||
| # start there without auth. HARNESS_ADDR supplies the port; the host is ours. | ||
| # Issue #1411. | ||
| HARNESS_ADDR="127.0.0.1:${port}" "$harnessd_bin" & | ||
| local tmpdir="${TMPDIR:-/tmp}" | ||
| HARNESSD_LOG="${tmpdir%/}/harnessd.${$}.log" | ||
| ( umask 077; : > "$HARNESSD_LOG" ) | ||
|
Comment on lines
+256
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a daemon started with Useful? React with 👍 / 👎. |
||
| HARNESS_ADDR="127.0.0.1:${port}" "$harnessd_bin" >"$HARNESSD_LOG" 2>&1 & | ||
| local pid=$! | ||
| PID_FILE="${TMPDIR:-/tmp}/harnessd.${$}.pid" | ||
| echo "$pid" > "$PID_FILE" | ||
|
|
@@ -218,10 +271,11 @@ start_server() { | |
| die "server did not become healthy within 10 s" | ||
| fi | ||
| if ! kill -0 "$pid" 2>/dev/null; then | ||
| die "harnessd (pid ${pid}) exited before becoming healthy on port ${port}. See the harnessd log above for the reason it stopped. If it reports the port is already in use, free it or run on another port with HARNESS_ADDR=:PORT (e.g. HARNESS_ADDR=:9090 go-code)." | ||
| die "harnessd (pid ${pid}) exited before becoming healthy on port ${port}. If it reports the port is already in use, free it or run on another port with HARNESS_ADDR=:PORT (e.g. HARNESS_ADDR=:9090 go-code)." | ||
| fi | ||
| done | ||
| info "server is ready" | ||
| info "$(style 1 '32' 'server ready') at ${base_url}" | ||
| info "log: ${HARNESSD_LOG}" | ||
| } | ||
|
|
||
| # --- project-root detection -------------------------------------------------- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the implementation record for issue #1413, but the reviewed tree's
docs/logs/long-term-thinking-log.mdcontains no #1413 entry. Consequently future agents have no required command intent, user intent, or success definition against which to evaluate follow-up work; add the issue's criteria there as required.AGENTS.md reference: AGENTS.md:L19-L23
Useful? React with 👍 / 👎.