Skip to content

feat(af02): add deterministic surface scanner - #61

Merged
TheHalfMoon merged 8 commits into
mainfrom
feat/af02-a0-surface-scanner
Aug 29, 2026
Merged

feat(af02): add deterministic surface scanner#61
TheHalfMoon merged 8 commits into
mainfrom
feat/af02-a0-surface-scanner

Conversation

@TheHalfMoon

@TheHalfMoon TheHalfMoon commented Aug 29, 2026

Copy link
Copy Markdown
Owner

AF-02 Stack A0 — T012 scanner infrastructure

Canonical predecessor:

PR #58 merged as: d280e614f17732a9038662a4d193a3c5f2b5fa42
main tree after predecessor merge: c9051ec6a143ee477d471fe29225269db0da67d9
candidate head: 2fbbae7055aa963878148aaf742c2c5e5b446ed0
base branch: main
supersedes draft PR: #59

This replacement PR exists only because the connected GitHub GraphQL ready-for-review mutation is broken. It preserves the exact branch/head/tree and does not rewrite history.

This A0 infrastructure candidate implements T012 only. It does not alter surface-policy.json, does not commit source-universe/finding evidence, and does not claim T013.

T012 implementation

  • add exact syn = 3.0.3 with full and visit, matching the planning-frozen syn-af02-scanner identity;
  • add tools/af02-verifier/src/surface.rs as the planned SURFACE_SCANNER / SURFACE_POLICY_PARSER implementation path;
  • parse policy JSON with recursive duplicate-key rejection before typed projection;
  • enforce closed surface-policy structure and semantic references;
  • discover only Git-tracked Rust sources under the two closed roots;
  • parse every source with syn and scan cfg-disabled/dead syntax without scanning comments or literal contents;
  • resolve explicit/nested use aliases deterministically and emit uncertain findings for relevant glob ambiguity;
  • implement PATH_CALL, TYPE_CONSTRUCTOR, METHOD_CALL, and MACRO_TOKEN matching with exact identities;
  • prove constructor-bound method ownership only for a direct exact constructor or immutable same-block binding; mutable/unknown ownership remains uncertain;
  • assign deterministic per-file pre-order boundary-syntax ordinals and reject duplicate finding identities;
  • expose parse-surface-policy and scan-surface CLI entrypoints while leaving verify-pr fail-closed.

Temporal/lineage boundary

The canonical surface policy remains the earlier BOOTSTRAP policy. This candidate intentionally does not rebase that policy and does not carry dependent source-universe/finding evidence. dependent_evidence_allowed_in_same_candidate remains false. A dedicated policy-only REBASE is required before T013 dependent evidence.

Qualification boundary

All CI/review evidence for this replacement must be fresh in this PR context and tied to exact head 2fbbae7055aa963878148aaf742c2c5e5b446ed0. No result from superseded PR #59 is inherited as qualification evidence.


Summary by cubic

Implements the T012 deterministic surface scanner with new parse-surface-policy and scan-surface CLI entrypoints. Scans Git-tracked Rust sources under crates/ and tools/ using syn 3.0.3, resolving imports and matching boundary categories without changing the existing surface policy.

New Features

  • Parses policy JSON with recursive duplicate-key rejection and validates the closed surface structure.
  • Scans only Git-tracked Rust sources under the two closed roots, including cfg-disabled code but not comments or literals.
  • Resolves explicit and nested use aliases, emitting definite or uncertain findings based on glob ambiguity.
  • Adds an integration test that locks syn's version and checksum and runs both entrypoints.

Context

  • Replaces superseded PR feat(af02): add deterministic surface scanner #59 due to a GitHub mutation bug; the exact branch/head/tree are preserved.
  • Does not modify the surface policy and carries no dependent evidence for T013.
  • All CI and review evidence must be generated in this PR, tied to the exact head.

Written for commit 2fbbae7. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 40 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a6d7bd76-4706-48a6-8df1-25513a547b91

📥 Commits

Reviewing files that changed from the base of the PR and between d280e61 and 2fbbae7.

⛔ Files ignored due to path filters (1)
  • tools/af02-verifier/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • crates/commandf-pkg/tests/af02_surface_scanner.rs
  • tools/af02-verifier/.gitignore
  • tools/af02-verifier/Cargo.toml
  • tools/af02-verifier/src/lib.rs
  • tools/af02-verifier/src/main.rs
  • tools/af02-verifier/src/surface.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Please review exact head 2fbbae7055aa963878148aaf742c2c5e5b446ed0 for AF-02 Stack A0 T012. Focus on deterministic syn=3.0.3 source discovery, alias/glob uncertainty, METHOD_CALL receiver classification, duplicate finding identity rejection, source-universe closure, and confirming this candidate contains no T013 dependent evidence.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Checked-out commit and requested commit =='
git rev-parse HEAD
git show -s --format='commit=%H%nparents=%P%nsubject=%s' HEAD
printf '%s\n' '== Diff paths from main =='
git diff --name-status main...HEAD
printf '%s\n' '== Relevant tracked paths =='
fd -HI -t f . | rg '(^|/)(Cargo\.toml|Cargo\.lock|surface\.rs|surface-policy\.json|source-universe|finding|evidence)'
printf '%s\n' '== Rust manifest dependency declarations =='
rg -n -C 3 '(^|\s)(syn|serde_json)\s*=' --glob 'Cargo.toml' --glob 'Cargo.lock'
printf '%s\n' '== Scanner outline =='
scanner="$(fd -HI -t f '^surface\.rs$' | head -n 1)"
if [ -n "${scanner:-}" ]; then
  printf 'scanner=%s\n' "$scanner"
  ast-grep outline "$scanner" --items all --view expanded
fi
printf '%s\n' '== Evidence-like changed paths =='
git diff --name-only main...HEAD | rg -i '(source[-_]?universe|finding|evidence|surface-policy)' || true

Length of output: 2198


🏁 Script executed:

#!/bin/bash
set -u

scanner='tools/af02-verifier/src/surface.rs'

printf '%s\n' '== Tool manifest =='
cat -n tools/af02-verifier/Cargo.toml
printf '%s\n' '== Locked syn packages =='
rg -n -C 2 'name = "syn"|version = "3\.0\.3"' tools/af02-verifier/Cargo.lock || true

printf '%s\n' '== Scanner symbols =='
ast-grep outline "$scanner" --items all --view expanded || true

printf '%s\n' '== Focused scanner terms =='
rg -n -C 5 \
  'git|tracked|ls-files|discover|source.*universe|UseTree|glob|alias|METHOD_CALL|MethodCall|receiver|constructor|duplicate|identity|HashSet|BTreeSet|parse.*policy|duplicate.*key|serde_json|PATH_CALL|TYPE_CONSTRUCTOR|MACRO_TOKEN' \
  "$scanner" || true

printf '%s\n' '== Scanner first section =='
sed -n '1,260p' "$scanner"
printf '%s\n' '== Scanner middle section =='
sed -n '261,620p' "$scanner"
printf '%s\n' '== Scanner final section =='
sed -n '621,1100p' "$scanner"

printf '%s\n' '== Scanner test outline and contents =='
ast-grep outline crates/commandf-pkg/tests/af02_surface_scanner.rs --items all --view expanded || true
cat -n crates/commandf-pkg/tests/af02_surface_scanner.rs

printf '%s\n' '== Scanner integration diff =='
git diff main...HEAD -- tools/af02-verifier/Cargo.toml tools/af02-verifier/src/lib.rs tools/af02-verifier/src/main.rs

printf '%s\n' '== Direct T013 boundary check =='
git diff --name-status main...HEAD -- \
  specs/016-af-02-adversarial-test-strength/surface-policy.json \
  specs/016-af-02-adversarial-test-strength \
  ':!specs/016-af-02-adversarial-test-strength/surface-policy.json' || true
git diff --name-only main...HEAD | rg -i '(source[-_]?universe|findings?|dependent.*evidence|evidence.*(json|md|yaml|yml))' || true

Length of output: 78874


🏁 Script executed:

#!/bin/bash
set -u

printf '%s\n' '== Import collection and visitor lines =='
nl -ba tools/af02-verifier/src/surface.rs | sed -n '500,830p'

printf '%s\n' '== Alias and glob test coverage =='
rg -n -C 4 'alias|glob|use std::fs|use .* as ' \
  tools/af02-verifier/src/surface.rs \
  crates/commandf-pkg/tests/af02_surface_scanner.rs || true

printf '%s\n' '== Block-scoped use declarations in scanned roots =='
rg -n -U -P --glob '*.rs' \
  '(?s)\bfn\b[^{}]*\{[^{}]*\buse\s+[^;]+;' \
  crates tools || true

printf '%s\n' '== Canonical policy lineage and evidence fields =='
python3 - <<'PY'
import json
path = "specs/016-af-02-adversarial-test-strength/surface-policy.json"
with open(path, encoding="utf-8") as f:
    policy = json.load(f)
print(json.dumps({
    "source_roots": policy.get("source_roots"),
    "scanner_tool_id": policy.get("scanner_tool_id"),
    "lineage": policy.get("lineage"),
}, indent=2, sort_keys=True))
PY

printf '%s\n' '== Tests for duplicate finding identity and source discovery =='
rg -n -C 3 'duplicate finding|identit|discover_tracked|closed Rust|source_order|NonRegularSource|SourcePath' \
  tools/af02-verifier/src/surface.rs \
  crates/commandf-pkg/tests/af02_surface_scanner.rs || true

printf '%s\n' '== Commit diff stat and T013-like changed files =='
git diff --stat main...HEAD
git diff --name-only main...HEAD | rg -i '(universe|finding|evidence|t013|policy)' || true

Length of output: 24191


@TheHalfMoon Review complete for exact head 2fbbae7055aa963878148aaf742c2c5e5b446ed0.

Finding

  • Hightools/af02-verifier/src/surface.rs Line 537 collects imports only from module-level Item::Use entries. Rust permits use declarations inside a function or nested block. The scanner does not add those aliases or globs to the scope used by classify_path and receiver_ownership.

    For example, this valid source does not resolve io::read to std::fs::read:

    fn read_fixture() {
        use std::fs as io;
        let _ = io::read("fixture");
    }

    A block-scoped use std::fs::*; read("fixture") also does not produce the required uncertain finding. Track lexical import scopes in ScannerVisitor, or explicitly reject unsupported block-scoped imports. Add tests for both the explicit-alias and glob cases.

Confirmed checks

  • The manifest pins syn = "=3.0.3" with full and visit.
  • The lockfile contains one frozen syn 3.0.3 package entry with the expected checksum.
  • Source discovery uses git ls-files -z, filters the two closed Rust roots, validates paths and regular files, then sorts paths.
  • Policy parsing rejects duplicate JSON keys before typed projection. Typed policy structures reject unknown fields.
  • METHOD_CALL handling classifies direct constructor calls, immutable same-block bindings, mutable bindings, and unknown receivers as specified.
  • The scanner deterministically sorts findings and rejects duplicate (source_path, syntax_ordinal, matcher_id) identities.
  • The diff contains no T013 source-universe, finding, or dependent-evidence artifact. The unchanged canonical policy sets dependent_evidence_allowed_in_same_candidate to false.
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TheHalfMoon
TheHalfMoon merged commit d7d75b4 into main Aug 29, 2026
30 of 31 checks passed

Copy link
Copy Markdown
Owner Author

@coderabbitai

Please compute and report the exact identities of the canonical surface policy at merged main d7d75b46de4df3cf58023d6245712feddb338afb using repository Git objects, not candidate files:

git rev-parse 'd7d75b46de4df3cf58023d6245712feddb338afb:specs/016-af-02-adversarial-test-strength/surface-policy.json'
git show 'd7d75b46de4df3cf58023d6245712feddb338afb:specs/016-af-02-adversarial-test-strength/surface-policy.json' | sha256sum

Return only the resolved Git blob SHA and SHA-256, and flag any command failure. This is for the dedicated policy-only REBASE lineage before T013.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -o pipefail

commit='d7d75b46de4df3cf58023d6245712feddb338afb'
path='specs/016-af-02-adversarial-test-strength/surface-policy.json'

if ! git rev-parse "${commit}:${path}"; then
  printf 'COMMAND_FAILURE: git rev-parse\n' >&2
fi

if ! git show "${commit}:${path}" | sha256sum; then
  printf 'COMMAND_FAILURE: git show | sha256sum\n' >&2
fi

Length of output: 603


@TheHalfMoon

Git blob SHA: bbc463f27c522b1a355f985d4fb0aa199552b15c
SHA-256: cb858294529a858ae6be8735bf273e2df0348b55efb53e730509527e0dbea86a

You are interacting with an AI system.

Copy link
Copy Markdown
Owner Author

@coderabbitai

On canonical merged main d7d75b46de4df3cf58023d6245712feddb338afb, run the already-canonical AF-02 scanner against the canonical surface policy and report the deterministic results. Use the Git object, not a PR working tree:

set -euo pipefail
git checkout --detach d7d75b46de4df3cf58023d6245712feddb338afb
cargo run --quiet --locked --manifest-path tools/af02-verifier/Cargo.toml -- scan-surface specs/016-af-02-adversarial-test-strength/surface-policy.json .

Report:

  1. total finding count;
  2. every finding tuple (source_path, syntax_ordinal, matcher_id, category, certainty);
  3. which findings are already covered by an exact critical-surface source_path+matcher_id pairing;
  4. which findings are not so covered and therefore require a reviewed exclusion or a new critical-surface disposition before T013;
  5. command exit status.

Do not modify files.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

commit='d7d75b46de4df3cf58023d6245712feddb338afb'
policy='specs/016-af-02-adversarial-test-strength/surface-policy.json'
manifest='tools/af02-verifier/Cargo.toml'
scanner='tools/af02-verifier/src/surface.rs'

git cat-file -e "${commit}^{commit}"
printf 'commit=%s\n' "$(git rev-parse "${commit}^{commit}")"

for path in "$policy" "$manifest" "$scanner"; do
  printf '%s blob=%s\n' "$path" "$(git rev-parse "${commit}:${path}")"
done

Length of output: 916


@TheHalfMoon, Git-object verification succeeded.

  • Commit: d7d75b46de4df3cf58023d6245712feddb338afb
  • Canonical policy blob: bbc463f27c522b1a355f985d4fb0aa199552b15c
  • Canonical verifier manifest blob: 4b2f7e28a68d09eb5fc424efda9b21d643d84ba3
  • Canonical scanner blob: 9a9c77d2120fd9bb977ec8f8d361ae54948df320

I still cannot run cargo run in this sandbox. Please provide the stdout, stderr, and exit status from the requested scan command. I will then classify every finding against the canonical policy’s exact source_path + matcher_id critical-surface pairings.

You are interacting with an AI system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant