@robhowley/pi-structured-return 1.10.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -83
  3. package/extensions/structured-return/config/registry.ts +4 -30
  4. package/extensions/structured-return/index.ts +105 -76
  5. package/extensions/structured-return/native.ts +223 -0
  6. package/extensions/structured-return/parsers/ava-text.ts +2 -168
  7. package/extensions/structured-return/parsers/bandit-json.ts +2 -79
  8. package/extensions/structured-return/parsers/black-text.ts +2 -73
  9. package/extensions/structured-return/parsers/cargo-build.ts +2 -78
  10. package/extensions/structured-return/parsers/cargo-test.ts +2 -135
  11. package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
  12. package/extensions/structured-return/parsers/clang-text.ts +2 -60
  13. package/extensions/structured-return/parsers/dbt-json.ts +2 -135
  14. package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
  15. package/extensions/structured-return/parsers/eslint-json.ts +2 -38
  16. package/extensions/structured-return/parsers/go-test-json.ts +2 -138
  17. package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
  18. package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
  19. package/extensions/structured-return/parsers/isort-text.ts +2 -63
  20. package/extensions/structured-return/parsers/javac-text.ts +2 -82
  21. package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
  22. package/extensions/structured-return/parsers/junit-xml.ts +2 -325
  23. package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
  24. package/extensions/structured-return/parsers/minitest-text.ts +2 -107
  25. package/extensions/structured-return/parsers/mocha-json.ts +2 -83
  26. package/extensions/structured-return/parsers/mypy-json.ts +2 -79
  27. package/extensions/structured-return/parsers/node-test-text.ts +2 -92
  28. package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
  29. package/extensions/structured-return/parsers/prettier-text.ts +2 -66
  30. package/extensions/structured-return/parsers/pylint-json.ts +2 -63
  31. package/extensions/structured-return/parsers/pyright-json.ts +2 -82
  32. package/extensions/structured-return/parsers/rspec-json.ts +2 -75
  33. package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
  34. package/extensions/structured-return/parsers/ruff-json.ts +2 -36
  35. package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
  36. package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
  37. package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
  38. package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
  39. package/extensions/structured-return/parsers/tidy-text.ts +2 -66
  40. package/extensions/structured-return/parsers/tsc-text.ts +2 -46
  41. package/extensions/structured-return/parsers/unittest-text.ts +2 -125
  42. package/extensions/structured-return/parsers/utils.ts +28 -0
  43. package/extensions/structured-return/parsers/vale-json.ts +2 -79
  44. package/extensions/structured-return/parsers/vitest-json.ts +2 -59
  45. package/extensions/structured-return/storage/log-store.ts +0 -15
  46. package/extensions/structured-return/types.ts +1 -14
  47. package/native/Cargo.lock +193 -0
  48. package/native/Cargo.toml +21 -0
  49. package/native/THIRD-PARTY-LICENSES.txt +3660 -0
  50. package/native/bin/darwin-arm64/build.json +7 -0
  51. package/native/bin/darwin-arm64/structured-return-native +0 -0
  52. package/native/bin/darwin-x64/build.json +7 -0
  53. package/native/bin/darwin-x64/structured-return-native +0 -0
  54. package/native/bin/linux-arm64-musl/build.json +7 -0
  55. package/native/bin/linux-arm64-musl/structured-return-native +0 -0
  56. package/native/bin/linux-x64-musl/build.json +7 -0
  57. package/native/bin/linux-x64-musl/structured-return-native +0 -0
  58. package/native/src/common.rs +118 -0
  59. package/native/src/main.rs +55 -0
  60. package/native/src/parsers/ava_text.rs +125 -0
  61. package/native/src/parsers/bandit_json.rs +120 -0
  62. package/native/src/parsers/black_text.rs +45 -0
  63. package/native/src/parsers/cargo_build.rs +96 -0
  64. package/native/src/parsers/cargo_test.rs +140 -0
  65. package/native/src/parsers/checkstyle_xml.rs +137 -0
  66. package/native/src/parsers/clang_text.rs +39 -0
  67. package/native/src/parsers/compiler_helpers.rs +74 -0
  68. package/native/src/parsers/dbt_json.rs +243 -0
  69. package/native/src/parsers/dotnet_build_text.rs +50 -0
  70. package/native/src/parsers/eslint_json.rs +58 -0
  71. package/native/src/parsers/go_test_json.rs +346 -0
  72. package/native/src/parsers/hadolint_json.rs +37 -0
  73. package/native/src/parsers/htmlhint_json.rs +71 -0
  74. package/native/src/parsers/isort_text.rs +22 -0
  75. package/native/src/parsers/javac_text.rs +49 -0
  76. package/native/src/parsers/json_support.rs +287 -0
  77. package/native/src/parsers/jsonlint_text.rs +50 -0
  78. package/native/src/parsers/junit_xml.rs +430 -0
  79. package/native/src/parsers/markdownlint_json.rs +68 -0
  80. package/native/src/parsers/minitest_text.rs +91 -0
  81. package/native/src/parsers/mocha_json.rs +75 -0
  82. package/native/src/parsers/mod.rs +119 -0
  83. package/native/src/parsers/mypy_json.rs +93 -0
  84. package/native/src/parsers/node_test_text.rs +106 -0
  85. package/native/src/parsers/npm_audit_json.rs +119 -0
  86. package/native/src/parsers/prettier_text.rs +34 -0
  87. package/native/src/parsers/pylint_json.rs +44 -0
  88. package/native/src/parsers/pyright_json.rs +88 -0
  89. package/native/src/parsers/rspec_json.rs +84 -0
  90. package/native/src/parsers/rubocop_json.rs +46 -0
  91. package/native/src/parsers/ruff_json.rs +30 -0
  92. package/native/src/parsers/shellcheck_json.rs +40 -0
  93. package/native/src/parsers/stylelint_json.rs +46 -0
  94. package/native/src/parsers/swiftc_text.rs +38 -0
  95. package/native/src/parsers/tail_fallback.rs +51 -0
  96. package/native/src/parsers/test_helpers.rs +172 -0
  97. package/native/src/parsers/tidy_text.rs +77 -0
  98. package/native/src/parsers/tsc_text.rs +28 -0
  99. package/native/src/parsers/unittest_text.rs +125 -0
  100. package/native/src/parsers/vale_json.rs +66 -0
  101. package/native/src/parsers/vitest_json.rs +71 -0
  102. package/native/src/parsers/xml_support.rs +241 -0
  103. package/native/src/runner.rs +252 -0
  104. package/package.json +22 -7
  105. package/scripts/build-native.mjs +73 -0
  106. package/scripts/native-artifacts.mjs +69 -0
  107. package/skills/structured-return/SKILL.md +103 -249
  108. package/extensions/structured-return/config/project-config.ts +0 -10
  109. package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
  110. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
@@ -0,0 +1,7 @@
1
+ {
2
+ "target": "aarch64-apple-darwin",
3
+ "version": "2.0.0",
4
+ "sourceHash": "b1a9fca56157294377f807240a67f93f0c39f4fa771b5668e8c9a00018f4c23a",
5
+ "sha256": "8ef027cb8069b12ff45b522eebf477c9006885632da57ec981f31e5779be4d10",
6
+ "rust": "1.88.0"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "target": "x86_64-apple-darwin",
3
+ "version": "2.0.0",
4
+ "sourceHash": "b1a9fca56157294377f807240a67f93f0c39f4fa771b5668e8c9a00018f4c23a",
5
+ "sha256": "e925ffc13ab1e319e289e013f8e78a64305d596674fb3f0253d8623a0054a408",
6
+ "rust": "1.88.0"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "target": "aarch64-unknown-linux-musl",
3
+ "version": "2.0.0",
4
+ "sourceHash": "b1a9fca56157294377f807240a67f93f0c39f4fa771b5668e8c9a00018f4c23a",
5
+ "sha256": "520b3bb332693c9ea0f8c7242b268d5d7bdca9fd9b8a049038e9f2784695bd61",
6
+ "rust": "1.88.0"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "target": "x86_64-unknown-linux-musl",
3
+ "version": "2.0.0",
4
+ "sourceHash": "b1a9fca56157294377f807240a67f93f0c39f4fa771b5668e8c9a00018f4c23a",
5
+ "sha256": "b12b60cb02033a1fd6befd24a84f09e34cf0600a5b415aa2b647fbc2899042e2",
6
+ "rust": "1.88.0"
7
+ }
@@ -0,0 +1,118 @@
1
+ use serde::Deserialize;
2
+ use serde_json::{json, Value};
3
+ use std::path::{Component, Path, PathBuf};
4
+
5
+ #[derive(Debug, Clone, Deserialize)]
6
+ #[serde(rename_all = "camelCase")]
7
+ pub struct Context {
8
+ #[allow(dead_code)]
9
+ pub command: String,
10
+ pub argv: Vec<String>,
11
+ pub cwd: String,
12
+ pub artifact_paths: Vec<String>,
13
+ pub stdout_path: String,
14
+ pub stderr_path: String,
15
+ pub log_path: String,
16
+ }
17
+
18
+ #[derive(Deserialize)]
19
+ pub struct Request {
20
+ pub parser: String,
21
+ pub context: Context,
22
+ }
23
+
24
+ pub fn read_file(path: &str) -> Result<String, String> {
25
+ match std::fs::read(path) {
26
+ Ok(bytes) => Ok(String::from_utf8_lossy(&bytes).into_owned()),
27
+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(String::new()),
28
+ Err(e) => Err(format!("{path}: {e}")),
29
+ }
30
+ }
31
+
32
+ pub fn result(
33
+ tool: &str,
34
+ status: &str,
35
+ summary: impl Into<String>,
36
+ failures: Vec<Value>,
37
+ ctx: &Context,
38
+ ) -> Value {
39
+ json!({"tool": tool, "status": status, "summary": summary.into(), "failures": failures, "logPath": ctx.log_path})
40
+ }
41
+
42
+ pub fn normalize(path: &Path) -> PathBuf {
43
+ let mut out = PathBuf::new();
44
+ for part in path.components() {
45
+ match part {
46
+ Component::CurDir => {}
47
+ Component::ParentDir => {
48
+ if !out.pop() && !path.is_absolute() {
49
+ out.push("..");
50
+ }
51
+ }
52
+ other => out.push(other.as_os_str()),
53
+ }
54
+ }
55
+ out
56
+ }
57
+
58
+ pub fn relative(cwd: &str, file: &str) -> String {
59
+ let cwd = if Path::new(cwd).is_absolute() {
60
+ normalize(Path::new(cwd))
61
+ } else {
62
+ normalize(&std::env::current_dir().unwrap_or_default().join(cwd))
63
+ };
64
+ let target = normalize(&cwd.join(file));
65
+ let a: Vec<_> = cwd.components().collect();
66
+ let b: Vec<_> = target.components().collect();
67
+ let common = a.iter().zip(&b).take_while(|(x, y)| x == y).count();
68
+ let mut out = PathBuf::new();
69
+ for _ in common..a.len() {
70
+ out.push("..");
71
+ }
72
+ for c in &b[common..] {
73
+ out.push(c.as_os_str());
74
+ }
75
+ out.to_string_lossy().into_owned()
76
+ }
77
+
78
+ pub fn basename(file: &str) -> String {
79
+ Path::new(file)
80
+ .file_name()
81
+ .map(|s| s.to_string_lossy().into_owned())
82
+ .unwrap_or_default()
83
+ }
84
+
85
+ pub fn string(value: &Value) -> String {
86
+ match value {
87
+ Value::String(s) => s.clone(),
88
+ Value::Null => "null".to_owned(),
89
+ other => other.to_string(),
90
+ }
91
+ }
92
+
93
+ pub fn truthy(value: &Value) -> bool {
94
+ match value {
95
+ Value::Null => false,
96
+ Value::Bool(b) => *b,
97
+ Value::Number(n) => n.as_f64().is_some_and(|n| n != 0.0),
98
+ Value::String(s) => !s.is_empty(),
99
+ _ => true,
100
+ }
101
+ }
102
+
103
+ pub fn js_space(c: char) -> bool {
104
+ matches!(c, '\u{0009}'..='\u{000D}' | '\u{0020}' | '\u{00A0}' | '\u{1680}'
105
+ | '\u{2000}'..='\u{200A}' | '\u{2028}' | '\u{2029}' | '\u{202F}'
106
+ | '\u{205F}' | '\u{3000}' | '\u{FEFF}')
107
+ }
108
+
109
+ pub fn trim(text: &str) -> &str {
110
+ text.trim_matches(js_space)
111
+ }
112
+
113
+ pub fn trim_start(text: &str) -> &str {
114
+ text.trim_start_matches(js_space)
115
+ }
116
+ pub fn trim_end(text: &str) -> &str {
117
+ text.trim_end_matches(js_space)
118
+ }
@@ -0,0 +1,55 @@
1
+ mod common;
2
+ mod parsers;
3
+ mod runner;
4
+ use serde_json::{json, Value};
5
+ use std::io::{self, BufRead, Write};
6
+
7
+ pub fn message(value: Value) -> Value {
8
+ let mut value = value;
9
+ value["protocol"] = json!(1);
10
+ value["version"] = json!(env!("CARGO_PKG_VERSION"));
11
+ value
12
+ }
13
+
14
+ fn execute() -> Result<Value, String> {
15
+ if std::env::args().nth(1).as_deref() == Some("--version") {
16
+ return Ok(
17
+ json!({"name":"structured-return-native","version":env!("CARGO_PKG_VERSION"),"protocol":1}),
18
+ );
19
+ }
20
+ println!("{}", message(json!({"event":"ready"})));
21
+ io::stdout().flush().map_err(|e| e.to_string())?;
22
+ let mut input = String::new();
23
+ io::stdin()
24
+ .lock()
25
+ .read_line(&mut input)
26
+ .map_err(|e| e.to_string())?;
27
+ let request: Value = serde_json::from_str(&input).map_err(|e| e.to_string())?;
28
+ if request.get("protocol").and_then(Value::as_u64) != Some(1)
29
+ || request.get("version").and_then(Value::as_str) != Some(env!("CARGO_PKG_VERSION"))
30
+ {
31
+ return Err("native protocol/version mismatch".into());
32
+ }
33
+ if request.get("op").and_then(Value::as_str) == Some("run") {
34
+ runner::run(serde_json::from_value(request).map_err(|e| e.to_string())?)
35
+ } else {
36
+ let request: common::Request =
37
+ serde_json::from_value(request).map_err(|e| e.to_string())?;
38
+ parsers::parse(&request.parser, &request.context)
39
+ }
40
+ }
41
+ fn main() {
42
+ match execute() {
43
+ Ok(value) => {
44
+ if std::env::args().nth(1).as_deref() == Some("--version") {
45
+ println!("{value}");
46
+ } else {
47
+ println!("{}", message(json!({"result":value})));
48
+ }
49
+ }
50
+ Err(error) => {
51
+ eprintln!("{error}");
52
+ std::process::exit(1);
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,125 @@
1
+ use super::test_helpers::{stack_location, without_failures};
2
+ use crate::common::{read_file, relative, result, Context};
3
+ use regex::Regex;
4
+ use serde_json::{json, Map, Value};
5
+
6
+ fn parse_block(name: String, lines: &[&str], ctx: &Context) -> Result<Value, String> {
7
+ let mut failure = Map::new();
8
+ failure.insert("id".to_owned(), json!(name));
9
+ if lines
10
+ .iter()
11
+ .any(|line| line.trim() == "Error thrown in test:")
12
+ {
13
+ let message_re = Regex::new(r"^message:\s*'(.+)',?$").unwrap();
14
+ if let Some(message) = lines
15
+ .iter()
16
+ .find_map(|line| message_re.captures(line.trim()).map(|m| m[1].to_owned()))
17
+ {
18
+ failure.insert("message".to_owned(), json!(message));
19
+ }
20
+ let stack = json!(lines.join("\n"));
21
+ if let Some((file, line)) = stack_location(Some(&stack))? {
22
+ failure.insert("file".to_owned(), json!(relative(&ctx.cwd, &file)));
23
+ failure.insert("line".to_owned(), json!(line));
24
+ }
25
+ } else {
26
+ let location_re = Regex::new(r"^(.+\.[a-z]{1,4}):([0-9]+)$").unwrap();
27
+ let mut file: Option<String> = None;
28
+ let mut line_number = None;
29
+ let mut actual = None;
30
+ let mut expected = None;
31
+ for line in lines {
32
+ let line = line.trim();
33
+ if file.as_ref().is_none_or(String::is_empty) {
34
+ if let Some(m) = location_re.captures(line) {
35
+ file = Some(relative(&ctx.cwd, &m[1]));
36
+ line_number = Some(m[2].parse::<u64>().unwrap_or(0));
37
+ continue;
38
+ }
39
+ }
40
+ if line.starts_with("- ") && actual.is_none() {
41
+ actual = Some(line[2..].to_owned());
42
+ } else if line.starts_with("+ ") && expected.is_none() {
43
+ expected = Some(line[2..].to_owned());
44
+ }
45
+ }
46
+ if let Some(file) = file {
47
+ failure.insert("file".to_owned(), json!(file));
48
+ }
49
+ if let Some(line) = line_number {
50
+ failure.insert("line".to_owned(), json!(line));
51
+ }
52
+ if let (Some(actual), Some(expected)) = (actual, expected) {
53
+ failure.insert(
54
+ "message".to_owned(),
55
+ json!(format!("expected {expected}, got {actual}")),
56
+ );
57
+ }
58
+ }
59
+ Ok(Value::Object(failure))
60
+ }
61
+
62
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
63
+ // Preserve stdout selection despite the original local variable name and
64
+ // skill description referring to stderr.
65
+ let output = read_file(&ctx.stdout_path)?;
66
+ if output.trim().is_empty() {
67
+ return Ok(without_failures("ava", "error", "no output", ctx));
68
+ }
69
+ let summary_re = Regex::new(r"([0-9]+) tests? (passed|failed)").unwrap();
70
+ let mut passed = 0_u64;
71
+ let mut failed = 0_u64;
72
+ for m in summary_re.captures_iter(&output) {
73
+ if &m[2] == "passed" {
74
+ passed = m[1].parse().unwrap_or(0);
75
+ } else {
76
+ failed = m[1].parse().unwrap_or(0);
77
+ }
78
+ }
79
+ if passed == 0 && failed == 0 {
80
+ return Ok(without_failures(
81
+ "ava",
82
+ "error",
83
+ "could not parse ava output",
84
+ ctx,
85
+ ));
86
+ }
87
+ let marker_re = Regex::new(r"^\s*✘\s+\[fail\]:\s+(.+?)(?:\s+Error thrown in test)?$").unwrap();
88
+ let separator_re = Regex::new(r"^\s*─\s*$").unwrap();
89
+ let lines: Vec<_> = output.lines().collect();
90
+ let names: Vec<_> = lines
91
+ .iter()
92
+ .filter_map(|line| marker_re.captures(line).map(|m| m[1].to_owned()))
93
+ .collect();
94
+ let separators: Vec<_> = lines
95
+ .iter()
96
+ .enumerate()
97
+ .filter_map(|(index, line)| separator_re.is_match(line).then_some(index))
98
+ .collect();
99
+ let mut failures = Vec::new();
100
+ if !names.is_empty() && separators.len() >= 2 {
101
+ let mut blocks: Vec<(String, Vec<&str>)> = Vec::new();
102
+ for line in &lines[separators[0] + 1..*separators.last().unwrap()] {
103
+ let trimmed = line.trim();
104
+ if names.iter().any(|name| name == trimmed) {
105
+ blocks.push((trimmed.to_owned(), Vec::new()));
106
+ } else if let Some((_, block)) = blocks.last_mut() {
107
+ block.push(line);
108
+ }
109
+ }
110
+ for (name, lines) in blocks {
111
+ failures.push(parse_block(name, &lines, ctx)?);
112
+ }
113
+ }
114
+ Ok(result(
115
+ "ava",
116
+ if failed > 0 { "fail" } else { "pass" },
117
+ if failed > 0 {
118
+ format!("{failed} failed, {passed} passed")
119
+ } else {
120
+ format!("{passed} passed")
121
+ },
122
+ failures,
123
+ ctx,
124
+ ))
125
+ }
@@ -0,0 +1,120 @@
1
+ use super::json_support::{
2
+ copy_field, js_string, null_object, parse_error, relative_input, required_array,
3
+ required_string,
4
+ };
5
+ use crate::common::{read_file, result, trim, Context};
6
+ use serde_json::{json, Map, Value};
7
+ use std::collections::HashMap;
8
+
9
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
10
+ let source = read_file(&ctx.stdout_path)?;
11
+ if trim(&source).is_empty() {
12
+ return Ok(result(
13
+ "bandit",
14
+ "pass",
15
+ "no security issues",
16
+ Vec::new(),
17
+ ctx,
18
+ ));
19
+ }
20
+ let report: Value = match super::json_support::parse_json(trim(&source)) {
21
+ Ok(v) => v,
22
+ Err(_) => return Ok(parse_error("bandit", ctx)),
23
+ };
24
+ null_object(&report, "results")?;
25
+ let items = match report.get("results").filter(|v| !v.is_null()) {
26
+ Some(v) => required_array(Some(v), "results")?,
27
+ None => &[],
28
+ };
29
+ let scan_errors = match report.get("errors").filter(|v| !v.is_null()) {
30
+ Some(v) => required_array(Some(v), "errors")?,
31
+ None => &[],
32
+ };
33
+ let mut failures = Vec::new();
34
+ let mut severities: HashMap<String, usize> = HashMap::new();
35
+ for item in items {
36
+ let file = relative_input(&ctx.cwd, required_string(item.get("filename"), "filename")?);
37
+ let mut out = Map::new();
38
+ out.insert(
39
+ "id".into(),
40
+ json!(format!(
41
+ "{}:{}:{}",
42
+ file,
43
+ js_string(item.get("line_number")),
44
+ js_string(item.get("test_id"))
45
+ )),
46
+ );
47
+ out.insert("file".into(), json!(file));
48
+ copy_field(&mut out, "line", item.get("line_number"));
49
+ copy_field(&mut out, "message", item.get("issue_text"));
50
+ out.insert(
51
+ "rule".into(),
52
+ json!(format!(
53
+ "{}:{}",
54
+ js_string(item.get("test_id")),
55
+ js_string(item.get("test_name"))
56
+ )),
57
+ );
58
+ failures.push(Value::Object(out));
59
+ let severity =
60
+ required_string(item.get("issue_severity"), "issue_severity")?.to_lowercase();
61
+ *severities.entry(severity).or_default() += 1;
62
+ }
63
+ let parts: Vec<_> = ["high", "medium", "low"]
64
+ .iter()
65
+ .filter_map(|s| {
66
+ severities
67
+ .get(*s)
68
+ .filter(|n| **n > 0)
69
+ .map(|n| format!("{n} {s}"))
70
+ })
71
+ .collect();
72
+ for error in scan_errors {
73
+ let file = relative_input(
74
+ &ctx.cwd,
75
+ required_string(error.get("filename"), "filename")?,
76
+ );
77
+ failures.push(json!({
78
+ "id": format!("{file}:scan-error"),
79
+ "file": file,
80
+ "message": required_string(error.get("reason"), "reason")?,
81
+ }));
82
+ }
83
+ let summary = if items.is_empty() {
84
+ "no security issues".into()
85
+ } else {
86
+ format!(
87
+ "{} issue{} ({})",
88
+ items.len(),
89
+ if items.len() == 1 { "" } else { "s" },
90
+ parts.join(", ")
91
+ )
92
+ };
93
+ let summary = if scan_errors.is_empty() {
94
+ summary
95
+ } else {
96
+ let errors = format!(
97
+ "{} scan error{}",
98
+ scan_errors.len(),
99
+ if scan_errors.len() == 1 { "" } else { "s" }
100
+ );
101
+ if items.is_empty() {
102
+ errors
103
+ } else {
104
+ format!("{summary}; {errors}")
105
+ }
106
+ };
107
+ Ok(result(
108
+ "bandit",
109
+ if !scan_errors.is_empty() {
110
+ "error"
111
+ } else if failures.is_empty() {
112
+ "pass"
113
+ } else {
114
+ "fail"
115
+ },
116
+ summary,
117
+ failures,
118
+ ctx,
119
+ ))
120
+ }
@@ -0,0 +1,45 @@
1
+ use super::compiler_helpers::{node_relative, regex, status, trim};
2
+ use crate::common::{read_file, result, Context};
3
+ use serde_json::{json, Value};
4
+
5
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
6
+ let combined = read_file(&ctx.stdout_path)? + "\n" + &read_file(&ctx.stderr_path)?;
7
+ let reformat = regex(r"^would reformat (.+)$");
8
+ let parse_error = regex(r"^error: cannot format (.+?): (Cannot parse: .+)$");
9
+ let error = regex(r"^error: cannot format (.+?): (.+)$");
10
+ let mut failures = Vec::new();
11
+ let mut reformats = 0;
12
+ let mut errors = 0;
13
+ for line in trim(&combined).lines() {
14
+ if let Some(m) = reformat.captures(line) {
15
+ reformats += 1;
16
+ let file = node_relative(&ctx.cwd, &m[1])?;
17
+ failures.push(json!({"id":file,"file":file,"message":"would reformat"}));
18
+ continue;
19
+ }
20
+ if let Some(m) = parse_error.captures(line).or_else(|| error.captures(line)) {
21
+ errors += 1;
22
+ let file = node_relative(&ctx.cwd, &m[1])?;
23
+ failures.push(json!({"id":file,"file":file,"message":&m[2]}));
24
+ }
25
+ }
26
+ let mut parts = Vec::new();
27
+ if reformats > 0 {
28
+ parts.push(format!(
29
+ "{reformats} file{} would be reformatted",
30
+ if reformats == 1 { "" } else { "s" }
31
+ ));
32
+ }
33
+ if errors > 0 {
34
+ parts.push(format!(
35
+ "{errors} file{} failed to format",
36
+ if errors == 1 { "" } else { "s" }
37
+ ));
38
+ }
39
+ let summary = if parts.is_empty() {
40
+ "all files formatted".into()
41
+ } else {
42
+ parts.join(", ")
43
+ };
44
+ Ok(result("black", status(&failures), summary, failures, ctx))
45
+ }
@@ -0,0 +1,96 @@
1
+ use super::compiler_helpers::{errors, status, trim};
2
+ use crate::common::{read_file, relative, result, string, truthy, Context};
3
+ use serde_json::{Map, Value};
4
+
5
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
6
+ let stdout = read_file(&ctx.stdout_path)?;
7
+ // SR-018: a UTF-8 BOM marks the stream, not its first JSON record.
8
+ let stdout = stdout.strip_prefix('\u{feff}').unwrap_or(&stdout);
9
+ let mut failures = Vec::new();
10
+ let mut build_failed = false;
11
+ for line in stdout.split('\n') {
12
+ if !trim(line).starts_with('{') {
13
+ continue;
14
+ }
15
+ let Ok(obj) = super::json_support::parse_json(line) else {
16
+ continue;
17
+ };
18
+ if obj.get("reason").and_then(Value::as_str) == Some("build-finished")
19
+ && obj.get("success").and_then(Value::as_bool) == Some(false)
20
+ {
21
+ build_failed = true;
22
+ }
23
+ if obj.get("reason").and_then(Value::as_str) != Some("compiler-message") {
24
+ continue;
25
+ }
26
+ let Some(message) = obj.get("message") else {
27
+ continue;
28
+ };
29
+ if message.get("level").and_then(Value::as_str) != Some("error") {
30
+ continue;
31
+ }
32
+ let primary = message
33
+ .get("spans")
34
+ .and_then(Value::as_array)
35
+ .and_then(|spans| {
36
+ spans
37
+ .iter()
38
+ .find(|span| span.get("is_primary").is_some_and(truthy))
39
+ });
40
+ let file = match primary {
41
+ Some(span) => Some(Value::String(relative(
42
+ &ctx.cwd,
43
+ span.get("file_name")
44
+ .and_then(Value::as_str)
45
+ .ok_or("primary span file_name is not a string")?,
46
+ ))),
47
+ None => None,
48
+ };
49
+ let line_number = primary.and_then(|span| span.get("line_start"));
50
+ let label = primary
51
+ .and_then(|span| span.get("label"))
52
+ .filter(|label| !label.is_null());
53
+ let code = message.get("code").and_then(|code| code.get("code"));
54
+ let id = [file.as_ref(), line_number, code]
55
+ .into_iter()
56
+ .flatten()
57
+ .filter(|value| truthy(value))
58
+ .map(string)
59
+ .collect::<Vec<_>>()
60
+ .join(":");
61
+ let mut failure = Map::new();
62
+ failure.insert("id".into(), Value::String(id));
63
+ if let Some(file) = file {
64
+ failure.insert("file".into(), file);
65
+ }
66
+ if let Some(line) = line_number {
67
+ failure.insert("line".into(), line.clone());
68
+ }
69
+ if let Some(label) = label.filter(|label| truthy(label)) {
70
+ let text = message
71
+ .get("message")
72
+ .map(string)
73
+ .unwrap_or_else(|| "undefined".into());
74
+ failure.insert(
75
+ "message".into(),
76
+ Value::String(format!("{text}\n{}", string(label))),
77
+ );
78
+ } else if let Some(text) = message.get("message") {
79
+ failure.insert("message".into(), text.clone());
80
+ }
81
+ if let Some(code) = code {
82
+ failure.insert("rule".into(), code.clone());
83
+ }
84
+ failures.push(Value::Object(failure));
85
+ }
86
+ if build_failed && failures.is_empty() {
87
+ return Ok(result("cargo", "error", "build failed", failures, ctx));
88
+ }
89
+ Ok(result(
90
+ "cargo",
91
+ status(&failures),
92
+ errors(failures.len(), "build succeeded"),
93
+ failures,
94
+ ctx,
95
+ ))
96
+ }