Repository navigation
feat: add agent progress tracking to CLI run command - #284
Merged
Merged
Conversation
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]>
Site previewCommit: |
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]>
ascerra
approved these changes
Apr 20, 2026
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]>
ralphbean
reviewed
Apr 20, 2026
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]>
2 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SSHStreamwithSSHStreamReader+ NDJSON stream parser to provide real-time visibility into agent execution inside OpenShell sandboxes--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)::notice::annotations for CI log visibilitySSHStreamReaderto sandbox package for piped stdout parsingFiles changed
internal/cli/progress.gointernal/cli/progress_test.gointernal/cli/run.gorunAgentWithProgress, stream-json flaginternal/sandbox/sandbox.goSSHStreamReaderreturningio.ReadCloserinternal/ui/ui.goHeartbeatmethodSecurity considerations
make,git,curl) — arguments are never shown to prevent secret leakageTest plan
go build ./...passesgo test ./internal/cli/...— 4 new tests pass (extractBinaryName, extractSafeContext, progressParser, progressParserStreamEvents)go vet ./internal/cli/...clean