# Update trail watch for trail-wide events

`0cad45f`·

dipree·3w ago·2 files·+128 added/-44 removed

## Sessions

8259670f86bdView transcript

## Changes

2

- cmd/entire/cli

- Mtrail_watch_cmd.go+115/-32

- Mtrail_watch_cmd_test.go+13/-12

```
17 unmodified lines

...

```

```go
"github.com/spf13/cobra"

// SSE control events for the agent-native finding stream. Domain events
// (for example "session.started" or "comment.created") are emitted as their
// SSE control events for the trail-wide event stream. Domain events
// (for example "review.started" or "comment.created") are emitted as their
// code_review_events.event_type values.
const (
	sseEventReady     = "ready"
)

cmd := &cobra.Command{
	Use:   "watch [<number>]",
	Short: "Tail a trail's finding events live",
	Long: `Subscribe to the trail-scoped agent-native finding SSE stream and
print events as they arrive. Reconnects automatically when the server caps the
connection (~50s) and on transient network errors.`,
}

...

type reviewReadyPayload struct {
	TrailID string `json:"trail_id"`
	Cursor  int    `json:"cursor"`
}

type reviewStreamEvent struct {
	ID              any            `json:"id"`
	TrailID         string         `json:"trail_id"`
	ReviewSessionID *string        `json:"review_session_id"`
	ActorID         string         `json:"actor_id"`
	EventType       string         `json:"event_type"`
	TargetType      string         `json:"target_type"`
	TargetID        string         `json:"target_id"`
	Payload         map[string]any `json:"payload"`
	CreatedAt       time.Time      `json:"created_at"`
}

...

func printReadyEvent(w io.Writer, data string) {
	var p reviewReadyPayload
	if err := json.Unmarshal([]byte(data), &p); err == nil {
		parts := []string{"● connected"}
		if p.TrailID != "" {
			...
		}
	}
}

...

func TestStreamOnce_PrintsReadyAndReviewEvents(t *testing.T) {
	frames := []string{
		"event: ready\ndata: {\"trail_id\":\"trl_1\",\"cursor\":0}\n\n",
		"id: 1\nevent: session.started\ndata: {...}
		...
	}
	...
}

...

```
