Skip to content

feat: add agent progress tracking to CLI run command - #284

Merged
ascerra merged 8 commits into
mainfrom
feat-agent-progress-tracking
Apr 20, 2026
Merged

ascerra merged 8 commits into
mainfrom
feat-agent-progress-tracking

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

  • Replace raw SSHStream with SSHStreamReader + NDJSON stream parser to provide real-time visibility into agent execution inside OpenShell sandboxes
  • Claude Code invoked with --output-format stream-json; parser emits tool names with safe context (binary name only for Bash to avoid leaking secrets, file paths for Read/Edit, patterns for Grep/Glob)
  • 30-second heartbeat goroutine shows elapsed/remaining time; GitHub Actions receives ::notice:: annotations for CI log visibility
  • Added SSHStreamReader to sandbox package for piped stdout parsing

Files changed

File Change
internal/cli/progress.go New — NDJSON stream parser with safe context extraction
internal/cli/progress_test.go New — tests for parser, binary name extraction, safe context
internal/cli/run.go Modified — heartbeat goroutine, runAgentWithProgress, stream-json flag
internal/sandbox/sandbox.go Modified — added SSHStreamReader returning io.ReadCloser
internal/ui/ui.go Modified — added Heartbeat method

Security considerations

  • Bash commands: only the binary name is logged (e.g. make, git, curl) — arguments are never shown to prevent secret leakage
  • File paths and grep patterns are safe to display
  • Unknown tools emit no context

Test plan

  • go build ./... passes
  • go test ./internal/cli/... — 4 new tests pass (extractBinaryName, extractSafeContext, progressParser, progressParserStreamEvents)
  • go vet ./internal/cli/... clean
  • Manual: run fullsend with a test agent, verify heartbeat + tool progress lines appear in CI logs

Replace raw SSHStream with SSHStreamReader + NDJSON stream parser to
provide real-time visibility into agent execution inside OpenShell
sandboxes. Claude Code is invoked with --output-format stream-json and
the parser emits tool names with safe context (binary name only for
Bash, file paths for Read/Edit, patterns for Grep/Glob). A 30-second
heartbeat goroutine provides elapsed/remaining time. GitHub Actions
receives ::notice:: annotations for CI log visibility.

Signed-off-by: Wayne Sun <[email protected]>
@github-actions

github-actions Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

Site preview

Preview: https://abec4af3-site.fullsend-ai.workers.dev

Commit: d5d3cc8a661bee106afaca7273830f6f06b5313c

Security:
- Sanitize GHA ::notice:: annotations to prevent workflow command
  injection from untrusted sandbox output (newlines, :: sequences)
- Add tool name allowlist — unknown tools display as generic "tool"
- Skip KEY=VALUE env var prefixes in extractBinaryName to prevent
  leaking SECRET=value assignments
- Truncate grep/glob patterns over 50 chars

Concurrency:
- Add sync.Mutex to ui.Printer for goroutine-safe output
- Use atomic.Int32 for RunMetrics.ToolCalls counter

Correctness:
- Check scanner.Err() after parse loop to surface truncation errors
- Guard extractBinaryName against empty strings.Fields result
- Remove unused toolResult struct, merge duplicate Grep/Glob cases

Tests:
- Add race-detector concurrency test for heartbeat + printer
- Add tests for GHA sanitization, env var prefix skipping, pattern
  truncation, malformed JSON recovery, and tool name allowlisting

Signed-off-by: Wayne Sun <[email protected]>
Security:
- Strip URL-encoded %0A/%0D in sanitizeGHA to close GHA injection
  bypass via percent-encoding
- Cap file path display at 200 chars to prevent data exfiltration
  through crafted file names
- Only call extractSafeContext for allowlisted tools to prevent
  context extraction from untrusted tool types

Correctness:
- Return scanner.Err() from progressParser so callers can detect
  truncated or broken streams
- Use rune-aware truncation for grep/glob patterns to avoid
  splitting multi-byte UTF-8 characters
- Compute heartbeat elapsed once to keep elapsed/remaining consistent

Tests:
- Rewrite concurrency test with 1ms ticker to force actual concurrent
  writes between goroutines
- Add tests for URL-encoded GHA injection, reader errors via io.Pipe,
  non-allowlisted tool context suppression, file path truncation,
  multi-byte pattern truncation, Write tool coverage

Signed-off-by: Wayne Sun <[email protected]>
- Use rune-aware truncation for file paths (consistent with patterns)
  to avoid splitting multi-byte UTF-8 characters at the 200-char cap
- Route all GHA ::notice:: annotations through Printer.Notice() under
  the existing mutex, eliminating unsynchronized os.Stderr writes from
  the heartbeat goroutine and progress parser
- Add SetCIWriter/Notice methods to ui.Printer; CI writer is
  configured once at runAgent entry based on GITHUB_ACTIONS env var
- Remove isCI threading from progressParser/parseAssistantToolUse/
  emitToolProgress — the Printer now owns CI output responsibility

Signed-off-by: Wayne Sun <[email protected]>
Comment thread internal/cli/progress.go Resolved
The SetCIWriter/Notice API on Printer was over-engineered — stderr
writes from fmt.Fprintf are atomic for small strings (well under
PIPE_BUF), so the mutex protection solved a non-problem. Revert to
the simpler direct fmt.Fprintf(os.Stderr) approach with isCI flag
threading.

Signed-off-by: Wayne Sun <[email protected]>
Address review feedback from @ralphbean: sanitizeGHA only protected
the ::notice:: path but Heartbeat received unsanitized messages. A
crafted file path containing ANSI escapes (e.g., OSC 52 clipboard
write) could reach terminals and log viewers via the Heartbeat output.

Replace sanitizeGHA with sanitizeOutput that strips:
- ANSI CSI sequences (\x1b[...m, \x1b[2J, etc.)
- ANSI OSC sequences (\x1b]52;...BEL clipboard injection)
- All control characters (< 0x20 and 0x7F DEL)
- GHA workflow command markers (::, %0A, %0D)

Applied once to msg before both CI annotation and Heartbeat paths in
emitToolProgress. Heartbeat in runHeartbeat is self-generated content
with no untrusted input, so no sanitization needed there.

Signed-off-by: Wayne Sun <[email protected]>
Two critical issues found by multi-agent review:

1. Pipeline deadlock: if progressParser exits early (e.g. scanner
   ErrTooLong on a >1MB JSON line), stdout is not drained. The SSH
   process blocks on write(), cmd.Wait() blocks on exit, and defer
   cancel() can't run — hanging for the full agent timeout. Fix:
   call cancel() and drain stdout immediately on parse error.

2. Duplicate counting: Claude Code stream-json emits both
   stream_event (content_block_start) and assistant (complete
   message) for each tool call. The parser handled both, doubling
   ToolCalls and emitting duplicate progress lines. Fix: drop the
   stream_event branch entirely — assistant messages arrive with
   full context and negligible latency difference.

Also: sanitize scanner error output, remove unused test variable,
convert stream_event tests to verify they are now ignored.

Signed-off-by: Wayne Sun <[email protected]>
Two fixes from round 2 multi-agent review:

1. sanitizeOutput: 8-bit C1 control characters (U+0080-U+009F)
   passed through the filter. U+009B is the 8-bit CSI equivalent
   of ESC[ and could inject terminal escape sequences on terminals
   that support 8-bit controls. Fix: extend the filter condition to
   exclude the C1 range.

2. progressParser: replaced bufio.Scanner with bufio.Reader.ReadLine
   so lines exceeding the 1MB buffer are skipped instead of killing
   the parser. Scanner.ErrTooLong was fatal — it stopped all parsing,
   triggered cancel()+drain, and terminated the remote agent. Now
   oversized lines (e.g. Write tool with large file content) are
   silently skipped and parsing continues.

Tests added: 8-bit CSI/OSC stripping, full C1 range filtering,
oversized line skip with continued parsing of subsequent lines.

Signed-off-by: Wayne Sun <[email protected]>
@ascerra
ascerra added this pull request to the merge queue Apr 20, 2026
Merged via the queue into main with commit 5a01117 Apr 20, 2026
3 of 4 checks passed
@ascerra
ascerra deleted the feat-agent-progress-tracking branch April 20, 2026 22:04

This branch was successfully deployed

1 active deployment
site-preview — d5d3cc8a Deployed Apr 20, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants