projectHiddenRecordPreviews function

List<TrajectoryHiddenRecordPreview> projectHiddenRecordPreviews({
  1. required List<String> recordIds,
  2. required Map<String, SessionRecord> resolved,
})

Builds the bounded drill-in previews for the records a hidden range covers, in the order the caller supplies (chain order when the caller read the file). Records that resolved to nothing render as explicit [hidden: not captured for this session] placeholders (E6) — never fake content.

Implementation

List<TrajectoryHiddenRecordPreview> projectHiddenRecordPreviews({
  required List<String> recordIds,
  required Map<String, SessionRecord> resolved,
}) {
  return [
    for (final id in recordIds.take(hiddenRecordPreviewLimit))
      () {
        final record = resolved[id];
        if (record == null) {
          return TrajectoryHiddenRecordPreview(
            id: id,
            type: 'missing',
            preview: '[hidden: not captured for this session]',
          );
        }
        final text = switch (record) {
          MessageRecord(:final message) => switch (message) {
            UserMessage(:final content) => textPayloadOf(content),
            AssistantMessage(:final content) => textPayloadOf(content),
            ToolResultMessage(:final content) => textPayloadOf(content),
            _ => '',
          },
          _ => '',
        };
        return TrajectoryHiddenRecordPreview(
          id: id,
          type: record.runtimeType.toString(),
          preview: text.isEmpty
              ? '[hidden: unparseable record]'
              : (text.length <= hiddenRecordPreviewChars
                    ? text
                    : '${text.substring(0, hiddenRecordPreviewChars)}…'),
          timestamp: record.timestamp,
        );
      }(),
  ];
}