| 733 | } |
| 734 | |
| 735 | func collectMemoryExtractorOutput(ctx context.Context, events <-chan acp.AgentEvent) (string, error) { |
| 736 | var output strings.Builder |
| 737 | for { |
| 738 | select { |
| 739 | case <-ctx.Done(): |
| 740 | return "", fmt.Errorf("daemon: collect memory extractor output: %w", ctx.Err()) |
| 741 | case event, ok := <-events: |
| 742 | if !ok { |
| 743 | return output.String(), nil |
| 744 | } |
| 745 | switch event.Type { |
| 746 | case acp.EventTypeAgentMessage: |
| 747 | // Agent messages are stream chunks; inserting separators can corrupt JSONL. |
| 748 | output.WriteString(event.Text) |
| 749 | case acp.EventTypeError: |
| 750 | return "", fmt.Errorf("daemon: memory extractor agent error: %s", strings.TrimSpace(event.Error)) |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | type extractedMemoryLine struct { |
| 757 | Type string `json:"type"` |