87016ef5dc
- New `type=check` stage: the server runs a `commands` block (sh -c, per command_timeout, workspace env) and routes on pass/fail; per-command status, exit code, duration and bounded output are recorded and the failing output is the handoff. With delivery=true it is the landing gate (commit leftovers, merge moved main, checks in a fresh candidate worktree, fast-forward main). Parser/registry, lint (silent guards), format docs, CLI inspect, app graph and run detail rendering. - delivery=true is accepted on every harness (and on check stages). - permissions.shell on claude stages maps to Bash(cmd) / Bash(prefix:*) rules instead of a bare Bash allow; stages without edit that change the workspace fail the visit with the changed files listed (allow_workspace_changes=true opts out; artifacts, public and harness state dirs are ignored). - File-change capture: symlinks compared by target, untouched protected files no longer make captures partial, untracked caches/dependency/build output left out, lockfiles listed without patch, huge files compared by metadata, raised patch/line limits. Outcome repair follow-ups are logged and counted on the step (control.outcome_repairs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
178 lines
5.9 KiB
Dart
178 lines
5.9 KiB
Dart
import 'check_stage.dart';
|
|
import 'graph_protocol.dart';
|
|
|
|
/// The graph definition: nodes and edges declared by a pipeline, never the
|
|
/// evidence that a run executed them. Run evidence lives in
|
|
/// `run_graph_state.dart`; keeping the two shapes separate means a definition
|
|
/// can be drawn without claiming a visit happened.
|
|
///
|
|
/// Mirrors `stageOutcomes`, `edgeLabel`, `graphEdges` and `nodeDisplayLabel`
|
|
/// from `web/src/graph.js` (and `web/src/runDetail.js`). Pure data only.
|
|
|
|
/// Ordering priority: success first, error last, every other outcome
|
|
/// alphabetical in between (the web client's `outcomePriority`).
|
|
int _outcomePriority(String outcome) {
|
|
if (outcome == 'success') return 0;
|
|
if (outcome == 'error') return 2;
|
|
return 1;
|
|
}
|
|
|
|
/// A stage's edge outcomes in the app's one stable order.
|
|
List<String> stageOutcomes(dynamic stage) {
|
|
final edges = stage is Map ? stage['edges'] : null;
|
|
if (edges is! Map) return const <String>[];
|
|
final outcomes = edges.keys.map((key) => '$key').toList();
|
|
outcomes.sort((a, b) {
|
|
final priority = _outcomePriority(a) - _outcomePriority(b);
|
|
return priority != 0 ? priority : a.compareTo(b);
|
|
});
|
|
return outcomes;
|
|
}
|
|
|
|
/// The outcome label on an edge: `error*` for an implicit fallback error route.
|
|
String edgeLabel(dynamic stage, String outcome) {
|
|
final implicitFallback = stage is Map && stage['fallback_error'] == true;
|
|
return outcome == 'error' && implicitFallback ? 'error*' : outcome;
|
|
}
|
|
|
|
/// One declared edge, in stable definition order.
|
|
class GraphEdge {
|
|
const GraphEdge({
|
|
required this.id,
|
|
required this.source,
|
|
required this.outcome,
|
|
required this.target,
|
|
required this.label,
|
|
required this.fallback,
|
|
required this.knownTarget,
|
|
});
|
|
|
|
/// The 1-based id assigned in stable definition order (`Graph.edges()`).
|
|
final int id;
|
|
final String source;
|
|
final String outcome;
|
|
|
|
/// The resolved target: `#` has already become `#success`/`#failure`.
|
|
final String target;
|
|
final String label;
|
|
|
|
/// True only for the parser's implicit `error -> #failure` route.
|
|
final bool fallback;
|
|
|
|
/// True when [target] is a terminal or a stage declared in this graph.
|
|
///
|
|
/// An empty or unknown target is kept exactly as recorded, with this flag
|
|
/// false, so callers can show it honestly instead of inventing a node.
|
|
final bool knownTarget;
|
|
|
|
bool get isTerminal => isTerminalTarget(target);
|
|
}
|
|
|
|
/// One graph definition node: a declared stage, or a terminal the definition
|
|
/// routes to.
|
|
class GraphNode {
|
|
const GraphNode({
|
|
required this.key,
|
|
required this.terminal,
|
|
this.stageIndex,
|
|
this.type = '',
|
|
this.delivery = false,
|
|
});
|
|
|
|
final String key;
|
|
final bool terminal;
|
|
|
|
/// The stage's declared `type` exactly as recorded (blank reads `model`);
|
|
/// empty for a terminal.
|
|
final String type;
|
|
|
|
/// Whether this is a check stage marked as the delivery gate.
|
|
final bool delivery;
|
|
|
|
/// `Check` or `Delivery gate` for a check stage, otherwise null.
|
|
String? get kindCaption => checkStageCaption(type: type, delivery: delivery);
|
|
|
|
/// The node's stage declaration index, or null for a terminal.
|
|
final int? stageIndex;
|
|
|
|
String get label => nodeDisplayLabel(key);
|
|
String get shortLabel => nodeLabel(key);
|
|
}
|
|
|
|
List<Map<String, dynamic>> _stages(dynamic graph) {
|
|
if (graph is! Map) return const <Map<String, dynamic>>[];
|
|
final stages = graph['stages'];
|
|
if (stages is! List) return const <Map<String, dynamic>>[];
|
|
return stages.whereType<Map>().map(Map<String, dynamic>.from).toList();
|
|
}
|
|
|
|
String _stageKey(Map<String, dynamic> stage) => '${stage['key'] ?? ''}';
|
|
|
|
/// Every definition edge in stable id order.
|
|
///
|
|
/// Stages keep declaration order and each stage's outcomes use
|
|
/// [stageOutcomes]; ids are contiguous in that order. An absent (null) edge
|
|
/// value declares no edge and is skipped, while an empty or unknown target is
|
|
/// preserved with [GraphEdge.knownTarget] false.
|
|
List<GraphEdge> graphEdges(dynamic graph) {
|
|
final stages = _stages(graph);
|
|
final stageKeys = <String>{
|
|
for (final stage in stages)
|
|
if (_stageKey(stage).isNotEmpty) _stageKey(stage),
|
|
};
|
|
final result = <GraphEdge>[];
|
|
for (final stage in stages) {
|
|
final edges = stage['edges'];
|
|
if (edges is! Map) continue;
|
|
final source = _stageKey(stage);
|
|
for (final outcome in stageOutcomes(stage)) {
|
|
final raw = edges[outcome];
|
|
if (raw == null) continue;
|
|
final target = resolveTarget(outcome, '$raw') ?? '';
|
|
result.add(
|
|
GraphEdge(
|
|
id: result.length + 1,
|
|
source: source,
|
|
outcome: outcome,
|
|
target: target,
|
|
label: edgeLabel(stage, outcome),
|
|
fallback: outcome == 'error' && stage['fallback_error'] == true,
|
|
knownTarget: isTerminalTarget(target) || stageKeys.contains(target),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// The definition's nodes in declaration order.
|
|
///
|
|
/// A stage key identifies one node even when it is declared twice; self edges
|
|
/// and loops therefore never duplicate identity. Terminal nodes are appended
|
|
/// failure first, then success, once any declared edge resolves to a terminal
|
|
/// (the same `hasTerminal` rule the web layout uses). They are still
|
|
/// definition nodes, not evidence that a run reached them.
|
|
List<GraphNode> graphNodes(dynamic graph) {
|
|
final stages = _stages(graph);
|
|
final seen = <String>{};
|
|
final nodes = <GraphNode>[];
|
|
for (var index = 0; index < stages.length; index += 1) {
|
|
final key = _stageKey(stages[index]);
|
|
if (key.isEmpty || !seen.add(key)) continue;
|
|
nodes.add(
|
|
GraphNode(
|
|
key: key,
|
|
terminal: false,
|
|
stageIndex: index,
|
|
type: '${stages[index]['type'] ?? ''}',
|
|
delivery: isDeliveryGate(stages[index]),
|
|
),
|
|
);
|
|
}
|
|
if (graphEdges(graph).any((edge) => edge.isTerminal)) {
|
|
nodes.add(const GraphNode(key: failureEnd, terminal: true));
|
|
nodes.add(const GraphNode(key: successEnd, terminal: true));
|
|
}
|
|
return nodes;
|
|
}
|