renderYamlScalar function
Renders raw as a YAML scalar: booleans/numbers verbatim, plain-safe
strings unquoted, everything else JSON-quoted (a JSON string is a valid
YAML double-quoted scalar — the same convention the prompts: section
uses).
Implementation
String renderYamlScalar(String raw) {
if (raw == 'true' || raw == 'false' || raw == 'null' || raw == '~') {
return raw;
}
if (int.tryParse(raw) != null) return raw;
if (double.tryParse(raw) != null) return raw;
final plainSafe = RegExp(r'^[A-Za-z0-9_.~][A-Za-z0-9_./@+-]*$');
final uri = RegExp(r'^[a-z][a-z0-9+.-]*://\S*$');
return plainSafe.hasMatch(raw) || uri.hasMatch(raw) ? raw : jsonEncode(raw);
}