0791a4702d
The Artifacts badge counted every recorded turn document (input, memory, output, session.html) while the tab lists only deliverables, so a run whose visits recorded only debugging files (the Caplens ticket runs) badged dozens of artifacts and opened to an empty tab. The badge and the header now count deliverables only; the tab stays reachable when only debugging files exist and ends with a collapsed 'Show debugging files' entry naming their count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
4.2 KiB
Dart
99 lines
4.2 KiB
Dart
import '../../../core/api_gateway.dart';
|
|
import 'artifact_capture.dart';
|
|
import 'artifact_groups.dart';
|
|
import 'artifact_selection.dart';
|
|
import '../../../ui/text/plural.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.';
|
|
|
|
/// How many deliverables the run recorded: the stage-published files the
|
|
/// gallery lists by default, each shared `public/` file counted once. The run
|
|
/// detail's Artifacts badge and the gallery header both use this count, so a
|
|
/// run whose visits recorded only debugging files never advertises them.
|
|
int runDeliverableCount(List<JsonMap> steps) => artifactGroups(
|
|
steps,
|
|
).fold<int>(0, (sum, group) => sum + group.artifacts.length);
|
|
|
|
/// How many debugging files the run recorded (turn documents, history,
|
|
/// private scratch, session exports): the gallery's secondary section.
|
|
int debugFileCount(List<JsonMap> steps) =>
|
|
steps.fold<int>(0, (sum, step) => sum + systemArtifacts(step).length);
|
|
|
|
/// The run summary's Artifacts section header.
|
|
///
|
|
/// The recorded count is the run's deliverables ([runDeliverableCount]);
|
|
/// debugging files are not counted as artifacts. 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<JsonMap> steps, {required bool executing}) {
|
|
final recorded = runDeliverableCount(steps);
|
|
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<String> artifactCaptureNotes(JsonMap step) {
|
|
final notes = <String>[];
|
|
if (presentedArtifacts(artifactsOf(step)).isEmpty) return notes;
|
|
final capture = ArtifactCapture.fromStep(step);
|
|
if (capture.skipped > 0) {
|
|
notes.add(
|
|
'${countLabel(capture.skipped, 'file')} excluded from artifact capture.',
|
|
);
|
|
}
|
|
if (capture.truncated > 0) {
|
|
notes.add(
|
|
'${countLabel(capture.truncated, 'file')} omitted by artifact '
|
|
'capture limits.',
|
|
);
|
|
}
|
|
return notes;
|
|
}
|