Skip to content

Commit 799871a

Browse files
kevinelliottclaude
andcommitted
Add --stream and --no-stream flags to run command and connect bridge emitter
Problem: - Bridge emitter was created but never connected to orchestrator - Conversations were not actually streaming to AgentPipe Web - No way to override bridge config on a per-run basis Solution: - Added --stream flag to enable streaming for a run (overrides config) - Added --no-stream flag to disable streaming for a run (overrides config) - Actually create and connect bridge emitter in run command - Load bridge config and create emitter with proper version - Set emitter on orchestrator before starting conversation - Priority: --no-stream > --stream > config file setting Implementation: - Added streamEnabled and noStream bool flags - Created determineShouldStream() helper function - Load bridge config if streaming should be enabled - Create bridge.NewEmitter() with AgentPipe version - Call orchestrator.SetBridgeEmitter() to connect it - Added imports for internal/bridge and internal/version Testing: - All tests pass with race detector - --stream and --no-stream flags appear in help - Bridge events now actually get sent to web API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5b2abe9 commit 799871a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

cmd/run.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/spf13/viper"
1616

1717
_ "github.com/kevinelliott/agentpipe/pkg/adapters"
18+
"github.com/kevinelliott/agentpipe/internal/bridge"
19+
"github.com/kevinelliott/agentpipe/internal/version"
1820
"github.com/kevinelliott/agentpipe/pkg/agent"
1921
"github.com/kevinelliott/agentpipe/pkg/config"
2022
"github.com/kevinelliott/agentpipe/pkg/conversation"
@@ -40,6 +42,8 @@ var (
4042
watchConfig bool
4143
saveState bool
4244
stateFile string
45+
streamEnabled bool
46+
noStream bool
4347
)
4448

4549
var runCmd = &cobra.Command{
@@ -69,6 +73,8 @@ func init() {
6973
runCmd.Flags().BoolVar(&watchConfig, "watch-config", false, "Watch config file for changes and hot-reload (requires --config)")
7074
runCmd.Flags().BoolVar(&saveState, "save-state", false, "Save conversation state on exit (to ~/.agentpipe/states)")
7175
runCmd.Flags().StringVar(&stateFile, "state-file", "", "Specific file path to save conversation state")
76+
runCmd.Flags().BoolVar(&streamEnabled, "stream", false, "Enable streaming to AgentPipe Web for this run (overrides config)")
77+
runCmd.Flags().BoolVar(&noStream, "no-stream", false, "Disable streaming to AgentPipe Web for this run (overrides config)")
7278
}
7379

7480
func runConversation(cobraCmd *cobra.Command, args []string) {
@@ -344,6 +350,25 @@ func startConversation(cmd *cobra.Command, cfg *config.Config) error {
344350
orch.SetLogger(chatLogger)
345351
}
346352

353+
// Set up streaming bridge if enabled
354+
shouldStream := determineShouldStream(streamEnabled, noStream)
355+
if shouldStream {
356+
bridgeConfig := bridge.LoadConfig()
357+
if bridgeConfig.Enabled || streamEnabled {
358+
// Override config enabled setting if --stream was specified
359+
if streamEnabled {
360+
bridgeConfig.Enabled = true
361+
}
362+
363+
emitter := bridge.NewEmitter(bridgeConfig, version.GetShortVersion())
364+
orch.SetBridgeEmitter(emitter)
365+
366+
if verbose {
367+
fmt.Printf("🌐 Streaming enabled (conversation ID: %s)\n", emitter.GetConversationID())
368+
}
369+
}
370+
}
371+
347372
fmt.Println("🚀 Starting AgentPipe conversation...")
348373
fmt.Printf("Mode: %s | Max turns: %d | Agents: %d\n", cfg.Orchestrator.Mode, cfg.Orchestrator.MaxTurns, len(agentsList))
349374
if !cfg.Logging.Enabled {
@@ -495,3 +520,27 @@ func printSessionSummary(orch *orchestrator.Orchestrator, cfg *config.Config) {
495520
fmt.Println(strings.Repeat("=", 60))
496521
fmt.Println("Session ended. All messages logged.")
497522
}
523+
524+
// determineShouldStream determines if streaming should be enabled based on CLI flags.
525+
// Priority: --no-stream > --stream > config file setting
526+
func determineShouldStream(streamEnabled, noStream bool) bool {
527+
// If both flags are set, --no-stream takes priority
528+
if streamEnabled && noStream {
529+
return false
530+
}
531+
532+
// If --no-stream is set, disable streaming
533+
if noStream {
534+
return false
535+
}
536+
537+
// If --stream is set, enable streaming
538+
if streamEnabled {
539+
return true
540+
}
541+
542+
// Otherwise, use config file setting (checked later)
543+
// We return true here to let the config be checked
544+
bridgeConfig := bridge.LoadConfig()
545+
return bridgeConfig.Enabled
546+
}

0 commit comments

Comments
 (0)