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>
134 lines
4.1 KiB
Dart
134 lines
4.1 KiB
Dart
// A check stage visit's recorded output: the per-command results the server
|
|
// ran for a `check` stage, read without widget imports.
|
|
//
|
|
// Only an output map carrying a `checks` list is a check output; older
|
|
// servers never send one, so every other step keeps its ordinary rendering.
|
|
|
|
/// How one command ended. [unknown] keeps a status this client does not know
|
|
/// (its raw word stays in [CheckCommandResult.statusWord]).
|
|
enum CheckCommandStatus { passed, failed, timedOut, notRun, unknown }
|
|
|
|
CheckCommandStatus checkCommandStatus(String word) =>
|
|
switch (word.trim().toLowerCase()) {
|
|
'passed' => CheckCommandStatus.passed,
|
|
'failed' => CheckCommandStatus.failed,
|
|
'timed_out' => CheckCommandStatus.timedOut,
|
|
'not_run' => CheckCommandStatus.notRun,
|
|
_ => CheckCommandStatus.unknown,
|
|
};
|
|
|
|
/// The status as the row reads it; an unknown status shows its raw word.
|
|
String checkStatusLabel(CheckCommandResult check) => switch (check.status) {
|
|
CheckCommandStatus.passed => 'Passed',
|
|
CheckCommandStatus.failed => 'Failed',
|
|
CheckCommandStatus.timedOut => 'Timed out',
|
|
CheckCommandStatus.notRun => 'Not run',
|
|
CheckCommandStatus.unknown =>
|
|
check.statusWord.isEmpty ? 'Unknown status' : check.statusWord,
|
|
};
|
|
|
|
/// One command's recorded result.
|
|
class CheckCommandResult {
|
|
const CheckCommandResult({
|
|
required this.command,
|
|
required this.statusWord,
|
|
this.exitCode,
|
|
this.durationMs,
|
|
this.output = '',
|
|
this.truncated = false,
|
|
});
|
|
|
|
final String command;
|
|
|
|
/// The server's status word verbatim.
|
|
final String statusWord;
|
|
|
|
/// Null when not recorded (a command that never ran has none).
|
|
final int? exitCode;
|
|
final int? durationMs;
|
|
final String output;
|
|
|
|
/// Whether the server cut [output] at its capture limit.
|
|
final bool truncated;
|
|
|
|
CheckCommandStatus get status => checkCommandStatus(statusWord);
|
|
|
|
/// `exit 1 · 51s`, leaving out whichever fact was not recorded.
|
|
String get meta => [
|
|
if (exitCode != null) 'exit $exitCode',
|
|
if (durationMs != null) formatCheckDuration(durationMs!),
|
|
].join(' · ');
|
|
}
|
|
|
|
/// A check visit's whole recorded output.
|
|
class CheckStepOutput {
|
|
const CheckStepOutput({
|
|
required this.checks,
|
|
this.summary,
|
|
this.markdown,
|
|
this.delivery = false,
|
|
});
|
|
|
|
final List<CheckCommandResult> checks;
|
|
|
|
/// The server's one-line summary (`1 of 2 checks failed: go test ./...`).
|
|
final String? summary;
|
|
|
|
/// The handoff document the next stage reads.
|
|
final String? markdown;
|
|
|
|
/// Whether this visit was the delivery gate.
|
|
final bool delivery;
|
|
}
|
|
|
|
/// The check output recorded in [output], or null when it is not one.
|
|
CheckStepOutput? checkStepOutput(dynamic output) {
|
|
if (output is! Map) return null;
|
|
final checks = output['checks'];
|
|
if (checks is! List) return null;
|
|
return CheckStepOutput(
|
|
checks: [
|
|
for (final item in checks)
|
|
if (item is Map) _check(item),
|
|
],
|
|
summary: _text(output['summary']),
|
|
markdown: _text(output['markdown']),
|
|
delivery: output['delivery'] == true,
|
|
);
|
|
}
|
|
|
|
CheckCommandResult _check(Map item) => CheckCommandResult(
|
|
command: '${item['command'] ?? ''}',
|
|
statusWord: '${item['status'] ?? ''}'.trim(),
|
|
exitCode: _int(item['exit_code']),
|
|
durationMs: _int(item['duration_ms']),
|
|
output: item['output'] is String ? item['output'] as String : '',
|
|
truncated: item['truncated'] == true,
|
|
);
|
|
|
|
/// A command duration: `850ms`, `2.1s`, `51s`, `3m 05s`.
|
|
String formatCheckDuration(int ms) {
|
|
if (ms < 1000) return '${ms}ms';
|
|
if (ms < 10000) {
|
|
final tenths = (ms / 100).round();
|
|
return tenths % 10 == 0 ? '${tenths ~/ 10}s' : '${tenths / 10}s';
|
|
}
|
|
final seconds = (ms / 1000).round();
|
|
if (seconds < 60) return '${seconds}s';
|
|
final minutes = seconds ~/ 60;
|
|
final rest = (seconds % 60).toString().padLeft(2, '0');
|
|
if (minutes < 60) return '${minutes}m ${rest}s';
|
|
return '${minutes ~/ 60}h ${(minutes % 60).toString().padLeft(2, '0')}m';
|
|
}
|
|
|
|
int? _int(dynamic value) {
|
|
if (value is num) return value.toInt();
|
|
if (value is String) return int.tryParse(value.trim());
|
|
return null;
|
|
}
|
|
|
|
String? _text(dynamic value) {
|
|
if (value is! String) return null;
|
|
return value.trim().isEmpty ? null : value;
|
|
}
|