shellJobCommandLabel function

String shellJobCommandLabel(
  1. String command, {
  2. int headChars = shellJobLabelHeadChars,
  3. int tailChars = shellJobLabelTailChars,
})

The bounded model-facing command label (gh-1604 item 1): whitespace (newlines included) flattened to single spaces, then bounded — single-line commands keep the first headChars and last tailChars characters joined by a […N chars…] marker that names the TRUE omitted size; multi-line commands keep the HEAD only, no tail. Commands that already fit pass through untouched. Cuts never split a UTF-16 surrogate pair. Pure.

Why multi-line commands keep only the first line (issue #599 RED contract): the heredoc body is never a transcript row source, and for a multi-line command both the flattened head-crossing and the tail chars are body lines more often than they are the action — echoing them back through every settle notice re-floods the transcript the #599 fix drained. A one-line command's tail is the bench pipeline's action (… ; make test), so the single-line class keeps it.

Implementation

String shellJobCommandLabel(
  String command, {
  int headChars = shellJobLabelHeadChars,
  int tailChars = shellJobLabelTailChars,
}) {
  final flat = command.replaceAll(RegExp(r'\s+'), ' ').trim();
  // Fits: any command whose flattened form fits the head bound passes
  // through untouched — including short multi-line ones (pre-existing
  // flatten-and-show behavior).
  if (flat.length <= headChars) return flat;
  if (!command.trim().contains('\n')) {
    final head = _codepointSafeSlice(flat, 0, headChars);
    final tail = _codepointSafeSlice(
      flat,
      max(0, flat.length - tailChars),
      flat.length,
    );
    final omitted = flat.length - head.length - tail.length;
    if (omitted <= 0) return flat;
    return '$head […$omitted chars…] $tail';
  }
  // Overflows: single-line commands keep head + tail; multi-line
  // commands (issue #599 RED contract) keep the FIRST LINE only,
  // bounded — the first line is the command's face (a heredoc opener,
  // a script's shebang), while everything after it is body more often
  // than it is action. A flattened 120-char head would leak the first
  // body lines; a first-line head cannot. The first line comes from the
  // TRIMMED command: a leading newline must not blank the face
  // (gh-1604 rework).
  final trimmed = command.trim();
  final firstLineEnd = trimmed.indexOf('\n');
  final firstLine =
      (firstLineEnd < 0 ? trimmed : trimmed.substring(0, firstLineEnd))
          .replaceAll(RegExp(r'\s+'), ' ')
          .trim();
  final head = _codepointSafeSlice(firstLine, 0, headChars);
  final omitted = flat.length - head.length;
  return '$head […$omitted chars…]';
}