| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/event" |
| 5 | "reasonix/internal/evidence" |
| 6 | "reasonix/internal/sessioninbox" |
| 7 | ) |
| 8 | |
| 9 | // inboxEventSink observes unapplied-steer events and forwards optional inbox |
| 10 | // snapshot notifications without stripping the desktop sink capability. |
| 11 | type inboxEventSink struct { |
| 12 | inner event.Sink |
| 13 | c *Controller |
| 14 | } |
| 15 | |
| 16 | var _ event.OptionalSinkCapabilities = (*inboxEventSink)(nil) |
| 17 | var _ event.CheckedSink = (*inboxEventSink)(nil) |
| 18 | |
| 19 | func (s *inboxEventSink) Emit(e event.Event) { |
| 20 | _ = s.emit(e, false) |
| 21 | } |
| 22 | |
| 23 | func (s *inboxEventSink) EmitChecked(e event.Event) error { |
| 24 | return s.emit(e, true) |
| 25 | } |
| 26 | |
| 27 | func (s *inboxEventSink) emit(e event.Event, checked bool) error { |
| 28 | if s == nil { |
| 29 | return nil |
| 30 | } |
| 31 | if s.inner != nil { |
| 32 | if checked { |
| 33 | if err := event.EmitChecked(s.inner, e); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | } else { |
| 37 | s.inner.Emit(e) |
| 38 | } |
| 39 | } |
| 40 | if s.c == nil { |
| 41 | return nil |
| 42 | } |
| 43 | if e.Kind == event.Notice { |
| 44 | if e.Code == event.NoticeCodeUnappliedSteer && e.ItemID != "" { |
| 45 | s.c.onInboxUnappliedSteer(e.ItemID) |
| 46 | } |
| 47 | } |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | func notifyInboxChanged(sink event.Sink, snap sessioninbox.InboxSnapshot) { |
| 52 | if target, ok := sink.(interface { |
| 53 | InboxChanged(sessioninbox.InboxSnapshot) |
| 54 | }); ok { |
| 55 | target.InboxChanged(snap) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func (s *inboxEventSink) InboxChanged(snap sessioninbox.InboxSnapshot) { |
| 60 | if s == nil { |
| 61 | return |
| 62 | } |
| 63 | notifyInboxChanged(s.inner, snap) |
| 64 | } |
| 65 | |
| 66 | // Forward optional sink capabilities so wrapping does not strip accounting. |
| 67 | |
| 68 | func (s *inboxEventSink) RecordTurnCompletion() { |
| 69 | if s == nil { |
| 70 | return |
| 71 | } |
| 72 | event.RecordTurnCompletion(s.inner) |
| 73 | } |
| 74 | |
| 75 | func (s *inboxEventSink) RecordReadinessAudit(a evidence.ReadinessAudit) { |
| 76 | if s == nil { |
| 77 | return |
| 78 | } |
| 79 | event.RecordReadinessAudit(s.inner, a) |
| 80 | } |
| 81 | |
| 82 | func (s *inboxEventSink) RecordAnchorSafetyAudit(a event.AnchorSafetyAudit) { |
| 83 | if s == nil { |
| 84 | return |
| 85 | } |
| 86 | event.RecordAnchorSafetyAudit(s.inner, a) |
| 87 | } |
| 88 | |
| 89 | func (s *inboxEventSink) RecordContractShadow(a event.ContractShadowAudit) { |
| 90 | if s == nil { |
| 91 | return |
| 92 | } |
| 93 | if rs, ok := s.inner.(interface { |
| 94 | RecordContractShadow(event.ContractShadowAudit) |
| 95 | }); ok { |
| 96 | rs.RecordContractShadow(a) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func (s *inboxEventSink) RecordCompletionReport(a event.CompletionReportAudit) { |
| 101 | if s == nil { |
| 102 | return |
| 103 | } |
| 104 | if rs, ok := s.inner.(interface { |
| 105 | RecordCompletionReport(event.CompletionReportAudit) |
| 106 | }); ok { |
| 107 | rs.RecordCompletionReport(a) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func (s *inboxEventSink) RecordOutcomeProgress(sample evidence.OutcomeSample) { |
| 112 | if s == nil { |
| 113 | return |
| 114 | } |
| 115 | if rs, ok := s.inner.(interface{ RecordOutcomeProgress(evidence.OutcomeSample) }); ok { |
| 116 | rs.RecordOutcomeProgress(sample) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func (s *inboxEventSink) RecordDelegationAdmission(a event.DelegationAdmissionAudit) { |
| 121 | if s == nil { |
| 122 | return |
| 123 | } |
| 124 | if rs, ok := s.inner.(interface { |
| 125 | RecordDelegationAdmission(event.DelegationAdmissionAudit) |
| 126 | }); ok { |
| 127 | rs.RecordDelegationAdmission(a) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func (s *inboxEventSink) RecordMemoryRecall(a event.MemoryRecallAudit) { |
| 132 | if s == nil { |
| 133 | return |
| 134 | } |
| 135 | if rs, ok := s.inner.(interface{ RecordMemoryRecall(event.MemoryRecallAudit) }); ok { |
| 136 | rs.RecordMemoryRecall(a) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func (s *inboxEventSink) RecordProtocolRecovery(a event.ProtocolRecoveryAudit) { |
| 141 | if s == nil { |
| 142 | return |
| 143 | } |
| 144 | event.RecordProtocolRecovery(s.inner, a) |
| 145 | } |
| 146 | |
| 147 | func (s *inboxEventSink) RecordDelegationAudit(a evidence.DelegationAudit) { |
| 148 | if s == nil { |
| 149 | return |
| 150 | } |
| 151 | event.RecordDelegationAudit(s.inner, a) |
| 152 | } |
| 153 | |
| 154 | func (s *inboxEventSink) RecordWorkspaceMutation(m event.WorkspaceMutation) { |
| 155 | if s == nil { |
| 156 | return |
| 157 | } |
| 158 | event.RecordWorkspaceMutation(s.inner, m) |
| 159 | } |
| 160 | |
| 161 | func (s *inboxEventSink) RecordRunBudget(sample event.RunBudgetSample) { |
| 162 | if s == nil { |
| 163 | return |
| 164 | } |
| 165 | event.RecordRunBudget(s.inner, sample) |
| 166 | } |
| 167 | |
| 168 | func (s *inboxEventSink) RecordSubagentLifecycle(info event.SubagentLifecycleInfo) { |
| 169 | if s == nil { |
| 170 | return |
| 171 | } |
| 172 | event.RecordSubagentLifecycle(s.inner, info) |
| 173 | } |
| 174 |