@@ -0,0 +1,1436 @@
1+# Broadcast Sender Tracking Implementation Plan
2+
3+> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
4+
5+**Goal:** Track broadcast message sender and suppress self-response to eliminate conversation loops and fix focus view labels.
6+
7+**Architecture:** Add sender_id to broadcast messages in database and memory flow. Filter sender from broadcast recipients. Update TUI rendering to distinguish broadcast sources.
8+
9+**Tech Stack:** Go 1.22+, SQLite (modernc.org/sqlite), Bubble Tea TUI framework
10+
11+---
12+
13+## Background
14+
15+### Current Behavior
16+
17+Broadcast messages have three problems:
18+
19+1. **Self-response loops**: When a mysis broadcasts, it receives its own message and responds to it
20+2. **Missing sender info**: Database stores broadcasts without sender tracking
21+3. **Incorrect labels**: Focus view shows all broadcasts as "YOU:" regardless of source
22+
23+### Current Flow
24+
25+```
26+User Input → Commander.BroadcastAsync(content)
27+ ↓
28+For each running mysis (including sender):
29+ ↓
30+ mysis.SendMessage(content, source='broadcast')
31+ ↓
32+ Store memory: role='user', source='broadcast', sender_id=NULL
33+ ↓
34+ Mysis processes with LLM and responds
35+```
36+
37+### Desired Flow
38+
39+```
40+Mysis Tool Call → zoea_broadcast(message) → Commander.BroadcastFrom(senderID, content)
41+ ↓
42+Filter: recipients = all running myses EXCEPT sender
43+ ↓
44+For each recipient:
45+ ↓
46+ mysis.SendMessage(content, source='broadcast', senderID)
47+ ↓
48+ Store memory: role='user', source='broadcast', sender_id=<senderID>
49+ ↓
50+ TUI: Show "SWARM:" for other's broadcasts, "YOU (BROADCAST):" for own
51+```
52+
53+### Files Affected
54+
55+**Database:**
56+- `internal/store/schema.sql` - Add sender_id column
57+- `internal/store/memories.go` - Update structs and methods
58+
59+**Core:**
60+- `internal/core/commander.go` - Filter sender from recipients
61+- `internal/core/mysis.go` - Pass sender info when storing
62+
63+**MCP:**
64+- `internal/mcp/tools.go` - Update zoea_broadcast to capture sender
65+- `internal/mcp/proxy.go` - Pass mysis context to tool handlers
66+
67+**TUI:**
68+- `internal/tui/focus.go` - Update rendering logic for sender-aware labels
69+
70+**Tests:**
71+- `internal/core/commander_test.go` - Update broadcast tests
72+- `internal/store/memories_test.go` - Update broadcast storage tests
73+- `internal/tui/focus_test.go` - Add sender label rendering tests
74+
75+---
76+
77+## Task 1: Database Schema Migration
78+
79+**Files:**
80+- Modify: `internal/store/schema.sql`
81+- Modify: `internal/store/migrations.go`
82+
83+### Step 1: Add sender_id column to schema
84+
85+Update `internal/store/schema.sql`:
86+
87+```sql
88+CREATE TABLE IF NOT EXISTS memories (
89+ id INTEGER PRIMARY KEY AUTOINCREMENT,
90+ mysis_id TEXT NOT NULL,
91+ role TEXT NOT NULL,
92+ source TEXT NOT NULL DEFAULT 'direct',
93+ sender_id TEXT, -- NEW: tracks who sent the message (for broadcasts)
94+ content TEXT NOT NULL,
95+ reasoning TEXT,
96+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
97+ FOREIGN KEY (mysis_id) REFERENCES myses(id) ON DELETE CASCADE
98+);
99+```
100+
101+### Step 2: Update SchemaVersion constant
102+
103+In `internal/store/migrations.go` (or schema.sql if version is there):
104+
105+```go
106+// SchemaVersion is the current database schema version.
107+const SchemaVersion = 8
108+```
109+
110+### Step 3: Document migration requirement
111+
112+Add comment to schema.sql:
113+
114+```sql
115+-- Schema v7 → v8 Migration:
116+-- Added sender_id column to memories table for broadcast tracking.
117+-- BREAKING CHANGE: Requires fresh database (make db-reset-accounts)
118+```
119+
120+### Step 4: Verify schema change
121+
122+```bash
123+# Check syntax
124+sqlite3 :memory: < internal/store/schema.sql
125+```
126+
127+Expected: No errors
128+
129+### Step 5: Commit schema changes
130+
131+```bash
132+git add internal/store/schema.sql internal/store/migrations.go
133+git commit -m "feat(db): add sender_id to memories for broadcast tracking
134+
135+Schema v7 → v8. Breaking change requires fresh database."
136+```
137+
138+---
139+
140+## Task 2: Update Store Layer - Structs
141+
142+**Files:**
143+- Modify: `internal/store/memories.go:17-30` (Memory struct)
144+- Modify: `internal/store/memories.go:152-156` (BroadcastMessage struct)
145+
146+### Step 1: Write test for Memory struct with sender_id
147+
148+Add to `internal/store/memories_test.go`:
149+
150+```go
151+func TestMemoryWithSenderID(t *testing.T) {
152+ db := setupTestDB(t)
153+ mysisID := "test-mysis"
154+ senderID := "sender-mysis"
155+
156+ // Add broadcast memory with sender
157+ err := db.AddMemory(mysisID, MemoryRoleUser, MemorySourceBroadcast, "test broadcast", "", senderID)
158+ if err != nil {
159+ t.Fatalf("AddMemory failed: %v", err)
160+ }
161+
162+ // Retrieve and verify sender_id
163+ memories, err := db.GetRecentMemories(mysisID, 10)
164+ if err != nil {
165+ t.Fatalf("GetRecentMemories failed: %v", err)
166+ }
167+
168+ if len(memories) != 1 {
169+ t.Fatalf("expected 1 memory, got %d", len(memories))
170+ }
171+
172+ if memories[0].SenderID != senderID {
173+ t.Errorf("expected sender_id %q, got %q", senderID, memories[0].SenderID)
174+ }
175+}
176+```
177+
178+### Step 2: Run test to verify it fails
179+
180+```bash
181+go test ./internal/store -run TestMemoryWithSenderID -v
182+```
183+
184+Expected: Compilation error - SenderID field doesn't exist
185+
186+### Step 3: Update Memory struct
187+
188+In `internal/store/memories.go`:
189+
190+```go
191+// Memory represents a stored conversation message with role and source tracking.
192+type Memory struct {
193+ ID int64
194+ MysisID string
195+ Role MemoryRole
196+ Source MemorySource
197+ SenderID string // NEW: For broadcasts, tracks who sent the message
198+ Content string
199+ Reasoning string
200+ CreatedAt time.Time
201+}
202+```
203+
204+### Step 4: Update BroadcastMessage struct
205+
206+In `internal/store/memories.go`:
207+
208+```go
209+// BroadcastMessage represents a broadcast message with sender tracking.
210+type BroadcastMessage struct {
211+ SenderID string // NEW: Mysis ID that sent the broadcast
212+ Content string
213+ CreatedAt time.Time
214+}
215+```
216+
217+### Step 5: Run test again
218+
219+```bash
220+go test ./internal/store -run TestMemoryWithSenderID -v
221+```
222+
223+Expected: Still fails - AddMemory signature doesn't accept sender_id
224+
225+### Step 6: Commit struct changes
226+
227+```bash
228+git add internal/store/memories.go
229+git commit -m "feat(store): add SenderID to Memory and BroadcastMessage structs"
230+```
231+
232+---
233+
234+## Task 3: Update Store Layer - AddMemory Method
235+
236+**Files:**
237+- Modify: `internal/store/memories.go` (AddMemory method)
238+
239+### Step 1: Update AddMemory signature and implementation
240+
241+In `internal/store/memories.go`, find the AddMemory method and update:
242+
243+```go
244+// AddMemory stores a new memory for a mysis.
245+// senderID is optional - empty string for direct messages, mysis ID for broadcasts.
246+func (s *Store) AddMemory(mysisID string, role MemoryRole, source MemorySource, content, reasoning, senderID string) error {
247+ s.mu.Lock()
248+ defer s.mu.Unlock()
249+
250+ query := `
251+ INSERT INTO memories (mysis_id, role, source, sender_id, content, reasoning)
252+ VALUES (?, ?, ?, ?, ?, ?)
253+ `
254+
255+ _, err := s.db.Exec(query, mysisID, role, source, senderID, content, reasoning)
256+ return err
257+}
258+```
259+
260+### Step 2: Run test to verify it compiles but still fails
261+
262+```bash
263+go test ./internal/store -run TestMemoryWithSenderID -v
264+```
265+
266+Expected: Compilation succeeds, test might pass now
267+
268+### Step 3: Commit AddMemory changes
269+
270+```bash
271+git add internal/store/memories.go
272+git commit -m "feat(store): update AddMemory to accept sender_id parameter"
273+```
274+
275+---
276+
277+## Task 4: Update Store Layer - Query Methods
278+
279+**Files:**
280+- Modify: `internal/store/memories.go` (GetRecentMemories, GetRecentBroadcasts, SearchBroadcasts)
281+
282+### Step 1: Update GetRecentMemories to retrieve sender_id
283+
284+In `internal/store/memories.go`:
285+
286+```go
287+func (s *Store) GetRecentMemories(mysisID string, limit int) ([]*Memory, error) {
288+ s.mu.RLock()
289+ defer s.mu.RUnlock()
290+
291+ query := `
292+ SELECT id, mysis_id, role, source, sender_id, content, reasoning, created_at
293+ FROM memories
294+ WHERE mysis_id = ?
295+ ORDER BY created_at DESC
296+ LIMIT ?
297+ `
298+
299+ rows, err := s.db.Query(query, mysisID, limit)
300+ if err != nil {
301+ return nil, err
302+ }
303+ defer rows.Close()
304+
305+ memories := []*Memory{}
306+ for rows.Next() {
307+ m := &Memory{}
308+ var senderID sql.NullString
309+ err := rows.Scan(&m.ID, &m.MysisID, &m.Role, &m.Source, &senderID, &m.Content, &m.Reasoning, &m.CreatedAt)
310+ if err != nil {
311+ return nil, err
312+ }
313+ if senderID.Valid {
314+ m.SenderID = senderID.String
315+ }
316+ memories = append(memories, m)
317+ }
318+
319+ // Reverse to chronological order
320+ for i, j := 0, len(memories)-1; i < j; i, j = i+1, j-1 {
321+ memories[i], memories[j] = memories[j], memories[i]
322+ }
323+
324+ return memories, rows.Err()
325+}
326+```
327+
328+### Step 2: Update GetRecentBroadcasts to include sender_id
329+
330+In `internal/store/memories.go`:
331+
332+```go
333+func (s *Store) GetRecentBroadcasts(limit int) ([]*BroadcastMessage, error) {
334+ s.mu.RLock()
335+ defer s.mu.RUnlock()
336+
337+ query := `
338+ SELECT sender_id, content, MIN(created_at) as created_at
339+ FROM memories
340+ WHERE source = 'broadcast'
341+ GROUP BY content, sender_id
342+ ORDER BY created_at DESC
343+ LIMIT ?
344+ `
345+
346+ rows, err := s.db.Query(query, limit)
347+ if err != nil {
348+ return nil, err
349+ }
350+ defer rows.Close()
351+
352+ broadcasts := []*BroadcastMessage{}
353+ for rows.Next() {
354+ b := &BroadcastMessage{}
355+ var senderID sql.NullString
356+ err := rows.Scan(&senderID, &b.Content, &b.CreatedAt)
357+ if err != nil {
358+ return nil, err
359+ }
360+ if senderID.Valid {
361+ b.SenderID = senderID.String
362+ }
363+ broadcasts = append(broadcasts, b)
364+ }
365+
366+ return broadcasts, rows.Err()
367+}
368+```
369+
370+### Step 3: Update SearchBroadcasts to include sender_id
371+
372+In `internal/store/memories.go`:
373+
374+```go
375+func (s *Store) SearchBroadcasts(query string, limit int) ([]*BroadcastMessage, error) {
376+ s.mu.RLock()
377+ defer s.mu.RUnlock()
378+
379+ sql := `
380+ SELECT sender_id, content, MIN(created_at) as created_at
381+ FROM memories
382+ WHERE source = 'broadcast' AND content LIKE ?
383+ GROUP BY content, sender_id
384+ ORDER BY created_at DESC
385+ LIMIT ?
386+ `
387+
388+ rows, err := s.db.Query(sql, "%"+query+"%", limit)
389+ if err != nil {
390+ return nil, err
391+ }
392+ defer rows.Close()
393+
394+ broadcasts := []*BroadcastMessage{}
395+ for rows.Next() {
396+ b := &BroadcastMessage{}
397+ var senderID sql.NullString
398+ err := rows.Scan(&senderID, &b.Content, &b.CreatedAt)
399+ if err != nil {
400+ return nil, err
401+ }
402+ if senderID.Valid {
403+ b.SenderID = senderID.String
404+ }
405+ broadcasts = append(broadcasts, b)
406+ }
407+
408+ return broadcasts, rows.Err()
409+}
410+```
411+
412+### Step 4: Run all store tests
413+
414+```bash
415+go test ./internal/store -v
416+```
417+
418+Expected: TestMemoryWithSenderID should pass. Other tests may fail due to AddMemory signature change.
419+
420+### Step 5: Commit query method updates
421+
422+```bash
423+git add internal/store/memories.go
424+git commit -m "feat(store): update query methods to retrieve sender_id"
425+```
426+
427+---
428+
429+## Task 5: Fix Existing Store Test Failures
430+
431+**Files:**
432+- Modify: `internal/store/memories_test.go`
433+
434+### Step 1: Update all AddMemory calls in tests
435+
436+Find all calls to `AddMemory` in test files and add empty string as sender_id:
437+
438+```go
439+// Before:
440+db.AddMemory(mysisID, MemoryRoleUser, MemorySourceDirect, "test", "")
441+
442+// After:
443+db.AddMemory(mysisID, MemoryRoleUser, MemorySourceDirect, "test", "", "")
444+```
445+
446+### Step 2: Run store tests to verify fixes
447+
448+```bash
449+go test ./internal/store -v
450+```
451+
452+Expected: All tests pass
453+
454+### Step 3: Commit test fixes
455+
456+```bash
457+git add internal/store/memories_test.go
458+git commit -m "test(store): update AddMemory calls for sender_id parameter"
459+```
460+
461+---
462+
463+## Task 6: Update Core Layer - Mysis SendMessage
464+
465+**Files:**
466+- Modify: `internal/core/mysis.go:342-375` (SendMessage method)
467+
468+### Step 1: Write test for Mysis broadcast with sender
469+
470+Add to `internal/core/mysis_test.go`:
471+
472+```go
473+func TestMysisReceivesBroadcastWithSender(t *testing.T) {
474+ db := setupTestStore(t)
475+ bus := NewEventBus()
476+
477+ receiver := createTestMysis(t, db, bus, "receiver")
478+ senderID := "sender-mysis"
479+
480+ // Send broadcast message with sender ID
481+ err := receiver.SendMessageFrom("test broadcast", store.MemorySourceBroadcast, senderID)
482+ if err != nil {
483+ t.Fatalf("SendMessageFrom failed: %v", err)
484+ }
485+
486+ // Verify memory was stored with sender_id
487+ memories, err := db.GetRecentMemories(receiver.ID(), 10)
488+ if err != nil {
489+ t.Fatalf("GetRecentMemories failed: %v", err)
490+ }
491+
492+ if len(memories) == 0 {
493+ t.Fatal("expected at least 1 memory")
494+ }
495+
496+ found := false
497+ for _, m := range memories {
498+ if m.Source == store.MemorySourceBroadcast && m.SenderID == senderID {
499+ found = true
500+ break
501+ }
502+ }
503+
504+ if !found {
505+ t.Error("broadcast memory with correct sender_id not found")
506+ }
507+}
508+```
509+
510+### Step 2: Run test to verify it fails
511+
512+```bash
513+go test ./internal/core -run TestMysisReceivesBroadcastWithSender -v
514+```
515+
516+Expected: Compilation error - SendMessageFrom method doesn't exist
517+
518+### Step 3: Add SendMessageFrom method to Mysis
519+
520+In `internal/core/mysis.go`:
521+
522+```go
523+// SendMessageFrom sends a message to this mysis with sender tracking.
524+// Used for broadcasts to track which mysis originated the message.
525+func (a *Mysis) SendMessageFrom(content string, source store.MemorySource, senderID string) error {
526+ a.mu.Lock()
527+ if a.state != MysisStateRunning {
528+ a.mu.Unlock()
529+ return fmt.Errorf("mysis not running")
530+ }
531+ a.mu.Unlock()
532+
533+ // Determine role
534+ role := store.MemoryRoleUser
535+ if source == store.MemorySourceSystem {
536+ role = store.MemoryRoleSystem
537+ }
538+
539+ // Store message with sender ID
540+ if err := a.store.AddMemory(a.id, role, source, content, "", senderID); err != nil {
541+ return err
542+ }
543+
544+ // Emit message event
545+ a.bus.Publish(Event{
546+ Type: EventMysisMessage,
547+ MysisID: a.id,
548+ MysisName: a.name,
549+ Data: MessageData{
550+ Role: string(role),
551+ Content: content,
552+ },
553+ Timestamp: time.Now(),
554+ })
555+
556+ // Process with LLM
557+ go a.processNextMessage()
558+
559+ return nil
560+}
561+```
562+
563+### Step 4: Update existing SendMessage to use SendMessageFrom
564+
565+```go
566+// SendMessage sends a message to this mysis without sender tracking.
567+// Used for direct messages and system prompts.
568+func (a *Mysis) SendMessage(content string, source store.MemorySource) error {
569+ return a.SendMessageFrom(content, source, "")
570+}
571+```
572+
573+### Step 5: Run test to verify it passes
574+
575+```bash
576+go test ./internal/core -run TestMysisReceivesBroadcastWithSender -v
577+```
578+
579+Expected: Test passes
580+
581+### Step 6: Commit Mysis changes
582+
583+```bash
584+git add internal/core/mysis.go internal/core/mysis_test.go
585+git commit -m "feat(core): add SendMessageFrom for broadcast sender tracking"
586+```
587+
588+---
589+
590+## Task 7: Update Core Layer - Commander Broadcast Filtering
591+
592+**Files:**
593+- Modify: `internal/core/commander.go:312-345` (BroadcastAsync method)
594+
595+### Step 1: Write test for sender exclusion
596+
597+Add to `internal/core/commander_test.go`:
598+
599+```go
600+func TestBroadcastExcludesSender(t *testing.T) {
601+ db := setupTestStore(t)
602+ bus := NewEventBus()
603+ cmd := NewCommander(db, bus)
604+
605+ sender, _ := cmd.CreateMysis("sender", "mock")
606+ receiver, _ := cmd.CreateMysis("receiver", "mock")
607+
608+ // Start both myses
609+ sender.Start()
610+ receiver.Start()
611+ defer sender.Stop()
612+ defer receiver.Stop()
613+
614+ // Wait for myses to be running
615+ time.Sleep(100 * time.Millisecond)
616+
617+ // Broadcast from sender
618+ err := cmd.BroadcastFrom(sender.ID(), "test broadcast")
619+ if err != nil {
620+ t.Fatalf("BroadcastFrom failed: %v", err)
621+ }
622+
623+ // Wait for delivery
624+ time.Sleep(200 * time.Millisecond)
625+
626+ // Verify sender did NOT receive its own broadcast
627+ senderMemories, err := db.GetRecentMemories(sender.ID(), 50)
628+ if err != nil {
629+ t.Fatalf("GetRecentMemories for sender failed: %v", err)
630+ }
631+
632+ for _, m := range senderMemories {
633+ if m.Source == store.MemorySourceBroadcast && m.Content == "test broadcast" {
634+ t.Error("sender received its own broadcast - should be excluded")
635+ }
636+ }
637+
638+ // Verify receiver DID receive the broadcast
639+ receiverMemories, err := db.GetRecentMemories(receiver.ID(), 50)
640+ if err != nil {
641+ t.Fatalf("GetRecentMemories for receiver failed: %v", err)
642+ }
643+
644+ found := false
645+ for _, m := range receiverMemories {
646+ if m.Source == store.MemorySourceBroadcast && m.Content == "test broadcast" && m.SenderID == sender.ID() {
647+ found = true
648+ break
649+ }
650+ }
651+
652+ if !found {
653+ t.Error("receiver did not receive broadcast with correct sender_id")
654+ }
655+}
656+```
657+
658+### Step 2: Run test to verify it fails
659+
660+```bash
661+go test ./internal/core -run TestBroadcastExcludesSender -v
662+```
663+
664+Expected: Test fails - BroadcastFrom method doesn't exist
665+
666+### Step 3: Add BroadcastFrom method to Commander
667+
668+In `internal/core/commander.go`:
669+
670+```go
671+// BroadcastFrom sends a message to all running myses except the sender.
672+func (c *Commander) BroadcastFrom(senderID, content string) error {
673+ c.mu.RLock()
674+ myses := make([]*Mysis, 0)
675+ for _, m := range c.myses {
676+ // Exclude sender and non-running myses
677+ if m.State() == MysisStateRunning && m.ID() != senderID {
678+ myses = append(myses, m)
679+ }
680+ }
681+ c.mu.RUnlock()
682+
683+ if len(myses) == 0 {
684+ return fmt.Errorf("no recipients for broadcast (sender excluded)")
685+ }
686+
687+ // Emit broadcast event
688+ c.bus.Publish(Event{
689+ Type: EventBroadcast,
690+ Data: MessageData{
691+ Role: "user",
692+ Content: content,
693+ },
694+ Timestamp: time.Now(),
695+ })
696+
697+ // Send to each recipient with sender tracking
698+ var errs []error
699+ for _, m := range myses {
700+ if err := m.SendMessageFrom(content, store.MemorySourceBroadcast, senderID); err != nil {
701+ errs = append(errs, err)
702+ }
703+ }
704+
705+ if len(errs) > 0 {
706+ return fmt.Errorf("broadcast failed for %d recipients: %w", len(errs), errors.Join(errs...))
707+ }
708+
709+ return nil
710+}
711+```
712+
713+### Step 4: Update BroadcastAsync to use BroadcastFrom with empty sender
714+
715+In `internal/core/commander.go`:
716+
717+```go
718+// BroadcastAsync sends a message to all running myses (legacy method).
719+// Use BroadcastFrom for sender tracking.
720+func (c *Commander) BroadcastAsync(content string) error {
721+ return c.BroadcastFrom("", content)
722+}
723+```
724+
725+### Step 5: Run test to verify it passes
726+
727+```bash
728+go test ./internal/core -run TestBroadcastExcludesSender -v
729+```
730+
731+Expected: Test passes
732+
733+### Step 6: Run all commander tests
734+
735+```bash
736+go test ./internal/core -run TestCommander -v
737+```
738+
739+Expected: Existing tests still pass (BroadcastAsync now uses BroadcastFrom with empty sender)
740+
741+### Step 7: Commit Commander changes
742+
743+```bash
744+git add internal/core/commander.go internal/core/commander_test.go
745+git commit -m "feat(core): add BroadcastFrom to exclude sender from recipients"
746+```
747+
748+---
749+
750+## Task 8: Update MCP Layer - Tool Handler Context
751+
752+**Files:**
753+- Modify: `internal/mcp/proxy.go` (CallTool to accept caller context)
754+- Modify: `internal/mcp/tools.go` (zoea_broadcast handler)
755+
756+### Step 1: Add context parameter to tool registration
757+
758+In `internal/mcp/proxy.go`, update the Proxy struct to support caller context:
759+
760+```go
761+// CallerContext provides information about who is calling a tool.
762+type CallerContext struct {
763+ MysisID string // ID of the mysis making the call
764+ MysisName string // Name of the mysis making the call
765+}
766+
767+// ToolHandlerWithContext is a function that handles a tool call with caller context.
768+type ToolHandlerWithContext func(ctx context.Context, caller CallerContext, arguments json.RawMessage) (*ToolResult, error)
769+```
770+
771+### Step 2: Update RegisterTool to support context-aware handlers
772+
773+Add new registration method:
774+
775+```go
776+// RegisterToolWithContext registers a tool handler that receives caller context.
777+func (p *Proxy) RegisterToolWithContext(tool Tool, handler ToolHandlerWithContext) {
778+ p.mu.Lock()
779+ defer p.mu.Unlock()
780+
781+ p.localTools[tool.Name] = tool
782+ p.contextHandlers[tool.Name] = handler
783+}
784+```
785+
786+Update Proxy struct to include contextHandlers:
787+
788+```go
789+type Proxy struct {
790+ mu sync.RWMutex
791+ upstream *Client
792+ localTools map[string]Tool
793+ localHandlers map[string]ToolHandler
794+ contextHandlers map[string]ToolHandlerWithContext // NEW
795+ accountStore AccountStore
796+}
797+```
798+
799+### Step 3: Update CallTool to pass caller context
800+
801+In `internal/mcp/proxy.go`:
802+
803+```go
804+// CallTool invokes a tool with caller context.
805+func (p *Proxy) CallTool(ctx context.Context, caller CallerContext, name string, arguments json.RawMessage) (*ToolResult, error) {
806+ p.mu.RLock()
807+ handler, isLocal := p.localHandlers[name]
808+ contextHandler, hasContext := p.contextHandlers[name]
809+ p.mu.RUnlock()
810+
811+ // Try context-aware handler first
812+ if hasContext {
813+ return contextHandler(ctx, caller, arguments)
814+ }
815+
816+ // Fall back to legacy handler
817+ if isLocal {
818+ return handler(ctx, arguments)
819+ }
820+
821+ // Forward to upstream
822+ if p.upstream != nil {
823+ return p.upstream.CallTool(ctx, name, arguments)
824+ }
825+
826+ return &ToolResult{
827+ Content: []ContentBlock{{Type: "text", Text: fmt.Sprintf("tool %q not found", name)}},
828+ IsError: true,
829+ }, nil
830+}
831+```
832+
833+### Step 4: Update Mysis to pass caller context to MCP
834+
835+In `internal/core/mysis.go`, update executeToolCall:
836+
837+```go
838+func (a *Mysis) executeToolCall(ctx context.Context, mcpProxy *mcp.Proxy, tc provider.ToolCall) (*mcp.ToolResult, error) {
839+ if mcpProxy == nil {
840+ return &mcp.ToolResult{
841+ Content: []mcp.ContentBlock{{Type: "text", Text: "MCP not configured"}},
842+ IsError: true,
843+ }, nil
844+ }
845+
846+ // Create caller context
847+ caller := mcp.CallerContext{
848+ MysisID: a.id,
849+ MysisName: a.name,
850+ }
851+
852+ result, err := mcpProxy.CallTool(ctx, caller, tc.Name, tc.Arguments)
853+ // ... rest of method
854+}
855+```
856+
857+### Step 5: Commit MCP context infrastructure
858+
859+```bash
860+git add internal/mcp/proxy.go internal/core/mysis.go
861+git commit -m "feat(mcp): add caller context to tool handlers"
862+```
863+
864+---
865+
866+## Task 9: Update zoea_broadcast Tool Handler
867+
868+**Files:**
869+- Modify: `internal/mcp/tools.go:145-182` (zoea_broadcast registration)
870+
871+### Step 1: Update zoea_broadcast to use context-aware handler
872+
873+In `internal/mcp/tools.go`:
874+
875+```go
876+// Register zoea_broadcast with context
877+proxy.RegisterToolWithContext(
878+ Tool{
879+ Name: "zoea_broadcast",
880+ Description: "Send a message to all running myses (you will not receive your own broadcast)",
881+ InputSchema: json.RawMessage(`{
882+ "type": "object",
883+ "properties": {
884+ "message": {"type": "string", "description": "The message to broadcast"}
885+ },
886+ "required": ["message"]
887+ }`),
888+ },
889+ func(ctx context.Context, caller mcp.CallerContext, args json.RawMessage) (*mcp.ToolResult, error) {
890+ var params struct {
891+ Message string `json:"message"`
892+ }
893+ if err := json.Unmarshal(args, ¶ms); err != nil {
894+ return &mcp.ToolResult{
895+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("invalid arguments: %v", err)}},
896+ IsError: true,
897+ }, nil
898+ }
899+
900+ // Use BroadcastFrom with caller's mysis ID
901+ if err := orchestrator.BroadcastFrom(caller.MysisID, params.Message); err != nil {
902+ return &mcp.ToolResult{
903+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("broadcast failed: %v", err)}},
904+ IsError: true,
905+ }, nil
906+ }
907+
908+ return &mcp.ToolResult{
909+ Content: []mcp.ContentBlock{{Type: "text", Text: "broadcast sent to all running myses (excluding you)"}},
910+ }, nil
911+ },
912+)
913+```
914+
915+### Step 2: Verify compilation
916+
917+```bash
918+go build ./...
919+```
920+
921+Expected: No compilation errors
922+
923+### Step 3: Commit tool handler update
924+
925+```bash
926+git add internal/mcp/tools.go
927+git commit -m "feat(mcp): update zoea_broadcast to use caller context and exclude sender"
928+```
929+
930+---
931+
932+## Task 10: Update TUI Layer - Focus View Rendering
933+
934+**Files:**
935+- Modify: `internal/tui/focus.go:241-247` (LogEntryFromMemory)
936+- Modify: `internal/tui/focus.go:168-191` (renderConversation)
937+
938+### Step 1: Write test for sender-aware label rendering
939+
940+Create `internal/tui/focus_test.go` if it doesn't exist:
Cut short: this commit's diff is over 1000 lines.