merge(app): land artifact-session-repair micro-slice

This commit is contained in:
2026-10-22 11:09:47 +01:00
18 changed files with 670 additions and 14 deletions
@@ -20,6 +20,8 @@ Widget buildCupertinoRunDetail({
required String? copyStatus,
required VoidCallback onBack,
required VoidCallback onCopy,
required ApiGateway gateway,
required ValueChanged<JsonMap> onRunChanged,
required String configuredEndpoint,
String? initialStageKey,
int? initialVisit,
@@ -31,6 +33,8 @@ Widget buildCupertinoRunDetail({
copying: copying,
copyStatus: copyStatus,
onCopy: onCopy,
gateway: gateway,
onRunChanged: onRunChanged,
configuredEndpoint: configuredEndpoint,
initialStageKey: initialStageKey,
initialVisit: initialVisit,
@@ -20,6 +20,8 @@ Widget buildMaterialRunDetail({
required String? copyStatus,
required VoidCallback onBack,
required VoidCallback onCopy,
required ApiGateway gateway,
required ValueChanged<JsonMap> onRunChanged,
required String configuredEndpoint,
String? initialStageKey,
int? initialVisit,
@@ -31,6 +33,8 @@ Widget buildMaterialRunDetail({
copying: copying,
copyStatus: copyStatus,
onCopy: onCopy,
gateway: gateway,
onRunChanged: onRunChanged,
configuredEndpoint: configuredEndpoint,
initialStageKey: initialStageKey,
initialVisit: initialVisit,
@@ -36,6 +36,8 @@ class RunDetailTabs extends StatefulWidget {
required this.copying,
required this.copyStatus,
required this.onCopy,
required this.gateway,
required this.onRunChanged,
required this.configuredEndpoint,
this.initialStageKey,
this.initialVisit,
@@ -52,6 +54,11 @@ class RunDetailTabs extends StatefulWidget {
final String? copyStatus;
final VoidCallback onCopy;
/// The shared gateway and accepted-detail fold used by the visit session's
/// export-only repair. Tabs never open their own socket.
final ApiGateway gateway;
final ValueChanged<JsonMap> onRunChanged;
/// The configured server origin used to resolve a recorded session export
/// through the landed safe-link helper. Blank leaves relative urls unresolved.
final String configuredEndpoint;
@@ -244,6 +251,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
visitIndex: index,
step: step,
runSteps: detailRunSteps(widget.run),
gateway: widget.gateway,
onRunChanged: widget.onRunChanged,
configuredEndpoint: widget.configuredEndpoint,
cupertino: widget.cupertino,
onClose: _closeVisit,
@@ -72,6 +72,8 @@ class _RunDetailViewState extends State<RunDetailView> {
copyStatus: _copyStatus,
onBack: widget.onBack,
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
configuredEndpoint: endpoint,
initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit,
@@ -86,6 +88,8 @@ class _RunDetailViewState extends State<RunDetailView> {
copyStatus: _copyStatus,
onBack: widget.onBack,
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
configuredEndpoint: endpoint,
initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit,
@@ -21,6 +21,8 @@ class RunVisitPane extends StatefulWidget {
required this.visitIndex,
required this.step,
required this.runSteps,
required this.gateway,
required this.onRunChanged,
required this.configuredEndpoint,
required this.cupertino,
required this.onClose,
@@ -35,6 +37,12 @@ class RunVisitPane extends StatefulWidget {
final JsonMap step;
final List<JsonMap> runSteps;
/// The app's shared gateway and the accepted-detail fold for the session's
/// export-only repair. The visit never opens its own socket.
final ApiGateway gateway;
final ValueChanged<JsonMap> onRunChanged;
final String configuredEndpoint;
final bool cupertino;
final VoidCallback onClose;
@@ -106,6 +114,8 @@ class _RunVisitPaneState extends State<RunVisitPane> {
visitIndex: widget.visitIndex,
stageKey: widget.visit.stage,
runSteps: widget.runSteps,
gateway: widget.gateway,
onRunChanged: widget.onRunChanged,
configuredEndpoint: widget.configuredEndpoint,
cupertino: widget.cupertino,
),
@@ -108,6 +108,28 @@ String? detailVisitSessionIdentity(JsonMap step) {
return evidence == null ? null : recordedText(evidence['session_id']);
}
/// The session identity the web client requires before it offers an
/// export-only repair: the visit's own `session_id` or its original
/// `session_export.session_id`. A repair attempt's identity is not enough, and
/// neither is an identity read only from that repair, exactly as the web's
/// availability check does not widen the case.
String? detailVisitRepairIdentity(JsonMap step) {
final direct = recordedText(step['session_id']);
if (direct != null) return direct;
final original = step['session_export'];
return original is Map ? recordedText(original['session_id']) : null;
}
/// Whether the web audit pane offers the export-only repair for a document it
/// can open: only when recorded evidence is incomplete or truncated.
///
/// A legacy `session.html` selected by the no-evidence fallback has nothing to
/// compare and gets no control. A `complete` status without the server's
/// verified evidence stays [VisitSessionExportState.partial] here, so it keeps
/// the control; that is this client's deliberate, stricter rule.
bool visitSessionExportNeedsRepair(VisitSessionExport export) =>
export.truncated || (export.status != null && !export.isComplete);
/// The visit's recorded export document, or null when no recorded export name
/// is present in the inventory.
///
@@ -88,6 +88,8 @@ Widget runVisitSectionBody({
required int visitIndex,
required String stageKey,
required List<JsonMap> runSteps,
required ApiGateway gateway,
required ValueChanged<JsonMap> onRunChanged,
required String configuredEndpoint,
required bool cupertino,
}) {
@@ -115,7 +117,10 @@ Widget runVisitSectionBody({
);
case RunVisitSection.session:
return RunVisitSession(
run: run,
step: step,
gateway: gateway,
onRunChanged: onRunChanged,
configuredEndpoint: configuredEndpoint,
);
case RunVisitSection.definition:
@@ -6,6 +6,8 @@ import '../../../ui/adaptive/host.dart';
import '../../artifacts/domain/artifact_record.dart';
import '../../artifacts/domain/artifact_url.dart';
import '../../artifacts/ui/artifact_external_open.dart';
import '../actions/session_export_repair_action.dart';
import 'run_detail_visit_recorded.dart';
import 'run_detail_visit_session_state.dart';
/// The visit's recorded session pointer, its recorded export state and, when
@@ -15,19 +17,29 @@ import 'run_detail_visit_session_state.dart';
/// repair, a still-running session and a failed one each report what the server
/// recorded. Complete, partial, missing, skipped, repair and unrecognised
/// states each keep the server's own word and diagnostic; recorded repair
/// attempts and their open-option labels are shown read-only and make no
/// request. The open goes through the landed safe-link helper: the recorded url
/// is resolved by [resolveArtifactUrl] and passed to [openArtifactExternally]
/// without being fetched, rewritten or previewed. A refusal is reported.
/// attempts and their open-option labels stay read-only. An export whose
/// recorded evidence is incomplete or truncated offers the web client's
/// export-only repair, which sends that exact visit's recorded sequence and
/// keeps this recorded state until the server replies; a legacy `session.html`
/// with no recorded evidence offers no control, exactly as the web does. The
/// open goes through the landed safe-link helper: the recorded url is resolved
/// by [resolveArtifactUrl] and passed to [openArtifactExternally] without being
/// fetched, rewritten or previewed. A refusal is reported.
class RunVisitSession extends StatefulWidget {
const RunVisitSession({
super.key,
required this.run,
required this.step,
required this.gateway,
required this.onRunChanged,
required this.configuredEndpoint,
this.openExternal = openArtifactExternally,
});
final JsonMap run;
final JsonMap step;
final ApiGateway gateway;
final ValueChanged<JsonMap> onRunChanged;
final String configuredEndpoint;
final ArtifactExternalOpen openExternal;
@@ -57,6 +69,8 @@ class _RunVisitSessionState extends State<RunVisitSession> {
: resolveArtifactUrl(widget.configuredEndpoint, export.artifact.url);
final note = export?.statusNote;
final fact = session.exportFact;
final sequence = recordedCount(widget.step['sequence']);
final repair = _repairAction(session, sequence);
final showReason =
export != null &&
fact?.reason != null &&
@@ -84,6 +98,7 @@ class _RunVisitSessionState extends State<RunVisitSession> {
const Text(visitSessionEndpointMissing)
else
_openButton(export.artifact, resolved),
?repair,
if (_status != null)
Padding(
padding: const EdgeInsets.only(top: 8),
@@ -130,8 +145,39 @@ class _RunVisitSessionState extends State<RunVisitSession> {
);
}
/// Recorded repair attempts, in the pane's own fact rows. Nothing here is a
/// control: the repair request belongs to its own action and is not wired.
/// The export-only repair option: offered only for a visit whose recorded
/// session identity and sequence can be read again, and whose recorded export
/// evidence is incomplete or truncated (or which has no openable document at
/// all). A legacy `session.html` chosen only by the no-evidence fallback has
/// no evidence to repair and keeps the web's absence of the control. The
/// visit's own recorded sequence is sent, never a guessed one.
Widget? _repairAction(VisitSessionState session, int sequence) {
final runId = recordedCount(widget.run['id']);
if (runId < 1 || sequence < 1) return null;
if (detailVisitRepairIdentity(widget.step) == null) return null;
final export = session.export;
if (export != null && !visitSessionExportNeedsRepair(export)) return null;
final status = recordedText(widget.step['status']);
final runStatus = recordedText(widget.run['status']);
final pending = recordedCount(widget.run['export_pending_sequence']);
final running =
widget.step['agent_active'] == true ||
status == 'running' ||
status == 'queued' ||
runStatus == 'running' ||
runStatus == 'queued' ||
(runStatus == 'waiting' && pending != sequence);
return SessionExportRepairAction(
runId: runId,
sequence: sequence,
gateway: widget.gateway,
running: running,
onRepaired: widget.onRunChanged,
);
}
/// Recorded repair attempts, in the pane's own fact rows. These labels stay
/// read-only; the request is made only by [SessionExportRepairAction].
List<Widget> _repairFacts(List<VisitSessionRepair> repairs) {
final facts = <Widget>[];
for (var index = 0; index < repairs.length; index += 1) {