import '../../../core/api_gateway.dart'; import 'artifact_capture.dart'; import 'artifact_groups.dart'; import 'artifact_selection.dart'; /// The "capture pending" wording shared by a running visit's summary and the /// run-level empty state, so the two never spell it differently. const String artifactCapturePending = 'capture pending'; /// The explicit message shown where the run's gallery would be when there are /// no recorded artifacts. A running run says capture pending; a finished run /// with available captures says plainly that nothing was recorded. String artifactsEmptyMessage(bool executing) => executing ? 'Artifacts · $artifactCapturePending' : 'No artifacts recorded for this run.'; /// The run summary's Artifacts section header. /// /// The recorded count is the number of recorded entries [galleryGroups] yields: /// stage files plus the turn documents the server actually recorded, never an /// absent slot. The title takes its singular form for one. A run whose capture is /// unavailable says so instead of claiming that nothing was recorded. Partial /// capture is flagged when any visit excluded or omitted files. String artifactsHeader(List steps, {required bool executing}) { final recorded = galleryGroups( steps, ).fold(0, (sum, group) => sum + group.recordedCount); if (recorded == 0) { if (executing) return artifactsEmptyMessage(true); final unavailable = steps.any( (step) => !ArtifactCapture.fromStep(step).isAvailable, ); return unavailable ? 'Artifacts · capture unavailable' : artifactsEmptyMessage(false); } final partial = steps.any((step) => ArtifactCapture.fromStep(step).isPartial); var label = '${recorded == 1 ? 'Artifact' : 'Artifacts'} · $recorded recorded'; if (partial) label += ' · partial capture'; return label; } /// The per-visit artifacts label. /// /// A running visit says capture pending. A finished visit whose capture field was /// absent says capture unavailable rather than "not recorded"; only an explicitly /// empty capture says "not recorded for this visit". Without [count] the recorded /// number excludes the turn-owned files and the retired session markdown, so the /// stage-artifact words match the stage tiles; a caller that presents the turn /// documents too passes its own recorded entry count. String artifactsSummary(JsonMap step, {int? count}) { final capture = ArtifactCapture.fromStep(step); final recorded = count ?? stageArtifacts(step).length; if (recorded == 0) { if (step['status'] == 'running') { return 'Artifacts · $artifactCapturePending'; } if (!capture.isAvailable) return 'Artifacts · capture unavailable'; return 'Artifacts · not recorded for this visit'; } var label = 'Artifacts · $recorded recorded'; if (capture.isPartial) label += ' · partial capture'; return label; } /// The partial-capture notes, one line per non-zero count and nothing when the /// capture was complete or had no presented files. An unavailable capture yields /// no notes because there is no evidence to quantify. List artifactCaptureNotes(JsonMap step) { final notes = []; if (presentedArtifacts(artifactsOf(step)).isEmpty) return notes; final capture = ArtifactCapture.fromStep(step); if (capture.skipped > 0) { notes.add('${capture.skipped} files excluded from artifact capture.'); } if (capture.truncated > 0) { notes.add('${capture.truncated} files omitted by artifact capture limits.'); } return notes; }