Skip to content

Add agent output streaming support (#361)#371

Open
jafreck wants to merge 5 commits into
mainfrom
cadre/issue-361
Open

Add agent output streaming support (#361)#371
jafreck wants to merge 5 commits into
mainfrom
cadre/issue-361

Conversation

@jafreck

@jafreck jafreck commented Mar 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds real-time stdout/stderr streaming from agent processes via an optional onData callback threaded through the entire backend invocation stack. Also introduces an AgentOutputEvent type and FleetEventBus.dispatchAgentOutput() for event-bus consumers. Closes #361

Changes

Types and Contracts

  • packages/framework/src/runtime/backend/contract.ts — Added AgentInvocationOptions interface with optional onData?: (chunk: string, stream: 'stdout' | 'stderr') => void field; updated AgentBackend.invoke() to accept optional third options parameter (backward-compatible)
  • packages/framework/src/core/events.ts — Added AgentOutputEvent type (type: 'agent-output', issueNumber, agent, chunk, stream) and included it in FrameworkLifecycleEvent union

Core Streaming Wiring

  • packages/framework/src/runtime/commands/exec.ts — Added onData to SpawnOpts; spawnProcess() now calls onData per chunk for both stdout and stderr while preserving buffered ProcessResult
  • packages/framework/src/runtime/backend/backend.ts — Threaded AgentInvocationOptions through runInvokePipeline() and both CopilotBackend.invoke() / ClaudeBackend.invoke()
  • packages/framework/src/core/event-bus.ts — Added dispatchAgentOutput() method to FleetEventBus

Launcher Propagation

  • packages/framework/src/runtime/launcher/agent-launcher.ts — Updated launchAgent() to accept and forward AgentInvocationOptions
  • src/core/agent-launcher.ts — Updated cadre-app launchAgent() to accept and forward streaming options to the framework backend

Tests

  • packages/framework/__tests__/runtime/commands/exec.test.ts — New tests: onData called per-chunk for stdout/stderr, absent onData does not throw, buffered result is correct when onData is wired
  • packages/framework/__tests__/runtime/backend/contract.test.ts — Tests for AgentInvocationOptions shape and optional options parameter
  • packages/framework/__tests__/core/events.test.ts — Type-narrowing tests for AgentOutputEvent via type === 'agent-output' discriminant
  • packages/framework/__tests__/runtime/backend/backend.test.ts — Tests verifying onData is forwarded through both backend invoke() implementations
  • packages/framework/__tests__/core/event-bus.test.ts — Test for dispatchAgentOutput() event shape and dispatch call
  • packages/framework/__tests__/runtime/launcher/agent-launcher.test.ts — Streaming pass-through test
  • tests/agent-launcher.test.ts — Test verifying onData callback is forwarded to the backend

Testing

All tests pass (npx vitest run exit code 0) and the build succeeds (npm run build exit code 0). The one noted regression (error: unknown option '--help') is a pre-existing unrelated issue. New unit tests cover onData callback invocation at every layer of the stack—spawnProcess(), backend invoke(), FleetEventBus.dispatchAgentOutput(), and both launcher implementations—verifying that streaming is additive and all callers without options continue to work unchanged.

Closes #361

…estrator mock (#361)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jafreck jafreck added the cadre-generated Pull request automatically generated by cadre label Mar 7, 2026
@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.42529% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.23%. Comparing base (7bc0e4b) to head (4819474).

Files with missing lines Patch % Lines
...amework/__tests__/runtime/backend/contract.test.ts 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
+ Coverage   91.20%   91.23%   +0.03%     
==========================================
  Files         212      213       +1     
  Lines       22302    22467     +165     
  Branches     3498     3525      +27     
==========================================
+ Hits        20340    20498     +158     
- Misses       1915     1921       +6     
- Partials       47       48       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cadre-generated Pull request automatically generated by cadre

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(framework): Add agent output streaming support

1 participant