(ctx context.Context, inv *serpent.Invocation)
| 592 | } |
| 593 | |
| 594 | func (s *mcpServer) startReporter(ctx context.Context, inv *serpent.Invocation) { |
| 595 | go func() { |
| 596 | for { |
| 597 | // TODO: Even with the queue, there is still the potential that a message |
| 598 | // from the screen watcher and a message from the AI agent could arrive |
| 599 | // out of order if the timing is just right. We might want to wait a bit, |
| 600 | // then check if the status has changed before committing. |
| 601 | item, ok := s.queue.Pop() |
| 602 | if !ok { |
| 603 | return |
| 604 | } |
| 605 | |
| 606 | req, err := agentsdk.ProtoFromPatchAppStatus(agentsdk.PatchAppStatus{ |
| 607 | AppSlug: s.appStatusSlug, |
| 608 | Message: item.summary, |
| 609 | URI: item.link, |
| 610 | State: item.state, |
| 611 | }) |
| 612 | if err != nil { |
| 613 | cliui.Warnf(inv.Stderr, "Failed to convert task status: %s", err) |
| 614 | continue |
| 615 | } |
| 616 | _, err = s.socketClient.UpdateAppStatus(ctx, req) |
| 617 | if err != nil && !errors.Is(err, context.Canceled) { |
| 618 | cliui.Warnf(inv.Stderr, "Failed to report task status: %s", err) |
| 619 | } |
| 620 | } |
| 621 | }() |
| 622 | } |
| 623 | |
| 624 | func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) { |
| 625 | go func() { |
no test coverage detected