Skip to content

Commit 2a90f2e

Browse files
committed
fix(stuff): working on next release
♬ Amberian Dawn - Temptation's Gates
1 parent 3bc48d7 commit 2a90f2e

41 files changed

Lines changed: 2548 additions & 1436 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Taint-mode semgrep presets for JavaScript (`presets/javascript.toml`) and Go (`presets/go.toml`), with taint-source/sink rules for SQLi, command injection, and path traversal
1212
- Taint-mode rules added to existing PHP and Python presets
1313
- `max_target_bytes` config field under `[scanner.semgrep]` to cap file size passed to semgrep via `--max-target-bytes`
14+
- Incremental scanning: `[scanner] incremental_scan = true` (requires `prior_runs.enabled = true`) skips LLM analysis for files unchanged since the last completed run and carries their previous findings forward; the changed/unchanged decision hashes every file, comparison uses one predicate for both the restriction and the carry, and `<output>/file-hashes.json` is written only after a scan completes fully
1415
- Graduated verification gate: individual check results (reachability, controllability, preconditions, context, impact) are recorded separately instead of a single binary kill
1516

1617
### Changed

‎Cargo.lock‎

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,21 @@ BACO runs a phased pipeline that progressively refines findings:
6969
4. **Score** — confidence calibration with citation verification
7070
5. **Report** — JSON, HTML, SARIF, Markdown outputs
7171

72-
Optional phases add CWE-aware MoE routing, rule synthesis, exploit
73-
synthesis, threat modeling, auto-patching, and PoC compilation.
74-
See [Architecture](docs/architecture.md) for the full phase graph and
75-
[Configuration](docs/configuration.md) for enabling flags.
72+
The pipeline is a fixed 15-phase core (3 parallel + 12 sequential): indexing,
73+
semgrep, LLM static analysis, then CWE routing, LLM discovery, LLM verification,
74+
validate, ticket cross-reference, git analysis, cross-file analysis, confidence
75+
scoring, AI aggregation, root-cause dedup, CVE bootstrap and reporting.
76+
See [Architecture](docs/architecture.md) for the phase graph and
77+
[Configuration](docs/configuration.md) for the enabling flags.
7678

7779
## Supported Languages
7880

79-
C/C++, Rust, Python, JavaScript, TypeScript, PHP, Go, Java, C#, Ruby —
80-
all with static analysis (tree-sitter + semgrep) and LLM verification.
81+
C/C++, Rust, Python, JavaScript, TypeScript, PHP, Go, Java, C#, Ruby.
82+
83+
All ten get tree-sitter parsing plus LLM verification. The bundled semgrep taint
84+
rules cover eight of them (C/C++, Python, JavaScript/TypeScript, PHP, Go, Java,
85+
C#, Ruby); **Rust has no bundled taint rule file**, so on Rust the semgrep layer
86+
only sees whatever rulesets you configure.
8187
See [Supported Languages](docs/languages.md) for the full matrix.
8288

8389
## Outputs

‎config.example.toml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ include_rejected = false
3535
max_file_size_kb = 512
3636
# Paths to exclude from scanning (use glob patterns like "tests/" or "docs/*")
3737
exclude_paths = ["tests/", "docs/", "target/"]
38+
# When true, files unchanged since the last completed run are not analyzed
39+
# again; their findings are carried from that run into this one. Requires
40+
# prior_runs.enabled = true (validated at startup). The comparison store is
41+
# written only after a scan completes fully, so an interrupted scan never
42+
# marks files as already analyzed.
43+
incremental_scan = false
3844

3945
[scanner.semgrep]
4046
# Rulesets can be a single string or an array of strings
@@ -89,6 +95,18 @@ enable_cve_bootstrap = true
8995
# Default: true
9096
enable_hunt_prompts = true
9197

98+
# Agent mode: lets the LLM read source and use tools before analysing findings
99+
[agent]
100+
# Disabled by default
101+
enabled = false
102+
# Maximum conversation turns with tools
103+
max_turns = 10
104+
# Timeout in seconds for a single tool execution
105+
tool_timeout_secs = 60
106+
# Whether the agent may run code it compiled. While false the test_run tool is
107+
# not offered to the model, so generated code is compiled but never executed.
108+
run_compiled_code = false
109+
92110
# LLM configuration with per-phase settings
93111
[llm]
94112
# Timeout in seconds for LLM API requests

‎docs/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ check against.
946946
| Section | Key fields |
947947
|--------------|---------------------------------------------------------------------------|
948948
| `project` | `name`, `path`, `languages` |
949-
| `scanner` | `max_file_size_kb`, `exclude_paths`, `semgrep.rulesets`, `semgrep.custom_rules`, `performance.*` |
949+
| `scanner` | `max_file_size_kb`, `exclude_paths`, `incremental_scan`, `semgrep.rulesets`, `semgrep.custom_rules`, `performance.*` |
950950
| `llm` | `timeout_secs`, `max_concurrent`, `temperature`, `phases.*` |
951951
| `triage` | `enabled`, `model`, `batch_size`, `suspicion_threshold` |
952952
| `priority` | `enabled`, `git_recent_boost`, `entry_point_boost`, `small_file_boost`, `entry_point_patterns`, `sink_patterns` |

‎scripts/coverage_gate.py‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/env python3
2+
"""Coverage gate for the files where defects actually surfaced.
3+
4+
Fails when the line coverage of a hot file drops below the versioned baseline
5+
in scripts/coverage-baseline.json. The point is not the absolute number: it is
6+
that a change which removes exercised behaviour cannot land silently.
7+
8+
Regenerating the baseline is a deliberate act, reviewed like code:
9+
10+
cargo llvm-cov --lcov --output-path lcov.info
11+
python3 scripts/coverage_gate.py --write-baseline lcov.info scripts/coverage-baseline.json
12+
13+
Only ever move it upward in review.
14+
"""
15+
16+
import fnmatch
17+
import json
18+
import sys
19+
20+
HOT_GLOBS = [
21+
"src/doctor.rs",
22+
"src/cli/**",
23+
"src/config/**",
24+
"src/scan_health.rs",
25+
"src/scanner/orchestrator.rs",
26+
"src/scanner/phases/llm_phases/**",
27+
]
28+
29+
30+
def canonical(path: str) -> str:
31+
path = path.replace("\\", "/")
32+
if "/src/" in path:
33+
return "src/" + path.split("/src/", 1)[1]
34+
if path.startswith("./"):
35+
return path[2:]
36+
return path
37+
38+
39+
def parse_lcov(lcov_path):
40+
"""Return {canonical_path: {line: hit_count}}, merging duplicate records.
41+
42+
cargo-llvm-cov can emit one record per test binary; the same source line
43+
hit in either counts as hit, so records merge by summing counts per line.
44+
"""
45+
records = {}
46+
current = None
47+
with open(lcov_path, encoding="utf-8", errors="replace") as fh:
48+
for raw in fh:
49+
line = raw.strip()
50+
if line.startswith("SF:"):
51+
current = canonical(line[3:])
52+
records.setdefault(current, {})
53+
elif line.startswith("DA:") and current is not None:
54+
fields = line[3:].split(",")
55+
try:
56+
lineno = int(fields[0])
57+
hits = int(fields[1])
58+
except (IndexError, ValueError):
59+
continue
60+
records[current][lineno] = records[current].get(lineno, 0) + hits
61+
elif line == "end_of_record":
62+
current = None
63+
return {path: lines for path, lines in records.items() if lines}
64+
65+
66+
def tally(lines):
67+
found = len(lines)
68+
hit = sum(1 for count in lines.values() if count > 0)
69+
return hit, found
70+
71+
72+
def pct(hit, found):
73+
return f"{100.0 * hit / found:.2f}%" if found else "100.00%"
74+
75+
76+
def write_baseline(records, baseline_path):
77+
files = {}
78+
for path, lines in sorted(records.items()):
79+
if not any(fnmatch.fnmatch(path, glob) for glob in HOT_GLOBS):
80+
continue
81+
hit, found = tally(lines)
82+
files[path] = {"lines_hit": hit, "lines_found": found}
83+
payload = {
84+
"comment": (
85+
"Line-coverage floor for the hot files, as (lines_hit, lines_found). "
86+
"The ci.yml coverage job fails a build when a file falls below its "
87+
"recorded pair. Regenerate with --write-baseline after adding tests; "
88+
"in review, only ever upward."
89+
),
90+
"files": files,
91+
}
92+
with open(baseline_path, "w", encoding="utf-8") as fh:
93+
json.dump(payload, fh, indent=2, sort_keys=True)
94+
fh.write("\n")
95+
print(f"baseline written: {len(files)} hot files to {baseline_path}")
96+
97+
98+
def gate(records, baseline_path):
99+
with open(baseline_path, encoding="utf-8") as fh:
100+
baseline = json.load(fh)
101+
problems = []
102+
checked = 0
103+
for path, entry in sorted(baseline["files"].items()):
104+
hit_b = int(entry["lines_hit"])
105+
found_b = int(entry["lines_found"])
106+
if path not in records:
107+
problems.append(
108+
f"{path}: in the baseline but absent from the coverage report - "
109+
f"renamed or deleted; update scripts/coverage-baseline.json"
110+
)
111+
continue
112+
hit_c, found_c = tally(records[path])
113+
checked += 1
114+
# Integer cross-multiplication: hit_c/found_c < hit_b/found_b exactly.
115+
if found_c == 0 and found_b > 0:
116+
problems.append(
117+
f"{path}: no instrumented lines in the coverage report "
118+
f"(baseline was {hit_b}/{found_b})"
119+
)
120+
elif hit_c * found_b < hit_b * found_c:
121+
problems.append(
122+
f"{path}: line coverage fell: {hit_c}/{found_c} ({pct(hit_c, found_c)}) "
123+
f"< baseline {hit_b}/{found_b} ({pct(hit_b, found_b)}) - add tests, "
124+
f"or update scripts/coverage-baseline.json deliberately"
125+
)
126+
if problems:
127+
print("coverage gate: FAILED", file=sys.stderr)
128+
for problem in problems:
129+
print(f" {problem}", file=sys.stderr)
130+
return 1
131+
print(f"coverage gate: {checked} hot files at or above the baseline")
132+
return 0
133+
134+
135+
def main(argv):
136+
if "--help" in argv:
137+
print(__doc__)
138+
return 0
139+
if len(argv) == 4 and argv[1] == "--write-baseline":
140+
write_baseline(parse_lcov(argv[2]), argv[3])
141+
return 0
142+
if len(argv) == 3:
143+
return gate(parse_lcov(argv[1]), argv[2])
144+
print(
145+
"usage: coverage_gate.py <lcov.info> <baseline.json> (gate)\n"
146+
" coverage_gate.py --write-baseline <lcov.info> <baseline.json>",
147+
file=sys.stderr,
148+
)
149+
return 2
150+
151+
152+
if __name__ == "__main__":
153+
sys.exit(main(sys.argv))

‎src/agent/sandbox.rs‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ fn validate_test_source_content(path: &str, content: &str) -> Result<(), String>
3737
Ok(())
3838
}
3939

40-
/// Error type for sandbox operations
41-
#[derive(Debug, thiserror::Error)]
42-
pub enum SandboxError {
43-
#[error("Docker unavailable: {0}")]
44-
DockerUnavailable(String),
45-
#[error("Runtime error: {0}")]
46-
RuntimeError(String),
47-
#[error("Timeout after {0}s")]
48-
Timeout(u64),
49-
}
50-
5140
/// Validate that a resolved path is contained within the sandbox root.
5241
///
5342
/// Checks:

‎src/config/mod.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ pub struct ScannerConfig {
6060
#[serde(default)]
6161
pub router: RouterConfig,
6262
#[serde(default)]
63-
pub aggregation: AggregationConfig,
64-
#[serde(default)]
6563
pub normalization: NormalizationConfig,
6664
#[serde(default)]
6765
pub validate: ValidateConfig,
@@ -328,6 +326,16 @@ impl ScannerConfig {
328326
message: format!("must be > 0, got {}", self.scanner.max_file_size_kb),
329327
});
330328
}
329+
// Incremental scanning carries findings from the run store's newest
330+
// complete run; with prior_runs disabled nothing is ever saved, so
331+
// the chokepoint would drop unchanged-file findings with nothing to
332+
// carry. Fail loudly at config load rather than lose findings.
333+
if self.scanner.incremental_scan && !self.prior_runs.enabled {
334+
return Err(ConfigError::Validation {
335+
field: "scanner.incremental_scan".to_string(),
336+
message: "requires prior_runs.enabled = true: carried findings are read from the run store".to_string(),
337+
});
338+
}
331339
let max_allowed = u64::MAX / 1024;
332340
if self.scanner.max_file_size_kb > max_allowed {
333341
return Err(ConfigError::Validation {

‎src/config/phases.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
use serde::{Deserialize, Serialize};
21
use std::path::PathBuf;
32

4-
/// Aggregation configuration including false positive store settings
5-
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6-
#[serde(deny_unknown_fields)]
7-
pub struct AggregationConfig {}
8-
93
pub const DEFAULT_ENABLE_ROOT_CAUSE_DEDUP: bool = true;
104
pub fn default_enable_root_cause_dedup() -> bool {
115
DEFAULT_ENABLE_ROOT_CAUSE_DEDUP

‎src/config/scanner.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ pub struct ScannerSettings {
1313
pub semgrep: SemgrepSettings,
1414
#[serde(default)]
1515
pub performance: PerformanceSettings,
16+
/// Incremental scanning: files whose content hash and rule fingerprint
17+
/// match the previous run keep their previous findings instead of being
18+
/// re-analyzed. Requires `prior_runs.enabled = true`, because the
19+
/// carried findings are read from the run store. Default: false.
20+
#[serde(default)]
21+
pub incremental_scan: bool,
1622
}
1723

1824
impl Default for ScannerSettings {
@@ -22,6 +28,7 @@ impl Default for ScannerSettings {
2228
exclude_paths: Vec::new(),
2329
semgrep: SemgrepSettings::default(),
2430
performance: PerformanceSettings::default(),
31+
incremental_scan: false,
2532
}
2633
}
2734
}

0 commit comments

Comments
 (0)