renderFeedbackMarkdown method

String renderFeedbackMarkdown(
  1. List<ReviewComment> comments, {
  2. String? updatedAt,
})

Generates the full <reviewDirectoryName>/feedback.md document for coding agents.

Implementation

String renderFeedbackMarkdown(
  List<ReviewComment> comments, {
  String? updatedAt,
}) {
  final counts = computeCommentCounts(comments);
  final openComments = [
    for (final item in comments)
      if (item.status != 'resolved') item,
  ];
  final resolvedComments = [
    for (final item in comments)
      if (item.status == 'resolved') item,
  ];

  final buffer = StringBuffer()
    ..writeln('# Visual Review Feedback')
    ..writeln()
    ..writeln('- **Open comments**: ${counts['open']}')
    ..writeln('- **Resolved comments**: ${counts['resolved']}')
    ..writeln('- **Total comments**: ${counts['total']}')
    ..writeln(
      '- **Updated**: '
      '${updatedAt ?? DateTime.now().toUtc().toIso8601String()}',
    )
    ..writeln()
    ..writeln('## Agent Instructions')
    ..writeln()
    ..writeln(
      'Apply each open review comment below in its resolved repository file.',
    )
    ..writeln(
      'Once you address a comment, mark it resolved so the browser toolbar '
      'and `$feedbackRelativePath` stay synchronized:',
    )
    ..writeln()
    ..writeln('```bash')
    ..writeln('$cliResolveCommand <comment-id>')
    ..writeln('```')
    ..writeln();

  buffer.writeln('## Open Comments');
  buffer.writeln();

  if (openComments.isEmpty) {
    buffer.writeln('_No open review comments._');
    buffer.writeln();
  } else {
    _writeGroupedOpenComments(buffer, openComments);
  }

  if (resolvedComments.isNotEmpty) {
    buffer
      ..writeln('## Resolved Comments')
      ..writeln();
    for (final item in resolvedComments) {
      final singleLineSummary = item.comment
          .replaceAll(RegExp(r'\s+'), ' ')
          .trim();
      final pageScope = item.site.isNotEmpty
          ? '`${item.site}` `${item.pageUrl}`'
          : '`${item.pageUrl}`';
      buffer.writeln(
        '- `[${item.id}]` `${item.locationLabel}` '
        '($pageScope): $singleLineSummary',
      );
    }
    buffer.writeln();
  }

  return buffer.toString();
}