Skip to content

feat(mapper): add contextFiles for rust seeds - #165

Merged
steipete merged 4 commits into
openclaw:mainfrom
Tanmay-008:feat/rust-context-files
Jul 25, 2026
Merged

feat(mapper): add contextFiles for rust seeds#165
steipete merged 4 commits into
openclaw:mainfrom
Tanmay-008:feat/rust-context-files

Conversation

@Tanmay-008

@Tanmay-008 Tanmay-008 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

This PR resolves an issue where the Rust mapper emitted zero contextFiles for Rust seeds. As a result, AI-generated code and reviews lacked important project context, increasing the likelihood of incorrect assumptions about project structure, modules, and external crates.

This change enriches Rust seed context by automatically including package manifests, crate entry points, and declared modules, resulting in more accurate and context-aware AI reasoning across Rust projects.


Changes Included

Manifest Context

  • Automatically includes the nearest Cargo.toml as a context file.

  • Added with the reason:

    • cargo package manifest

🔗 Entry Point Cross-Linking

  • When a crate contains both src/main.rs and src/lib.rs, they are linked as context to each other.

  • Added with the reasons:

    • crate library entry
    • crate binary entry

This mirrors the common Rust project structure where binaries import functionality from sibling libraries.

📁 Module Declaration Tracking

  • Added lightweight regex parsing for:

    • mod foo;
    • pub mod foo;
  • Module declarations are resolved to their actual source files:

    • src/foo.rs
    • src/foo/mod.rs
  • Resolved modules are included as context with the reason:

    • declared module
  • Context expansion is capped at 16 files to avoid unnecessary AI context growth.

Testing

Added a dedicated test suite in src/mappers/rust.test.ts covering:

  • Single-crate projects
  • Binary + library crates
  • Cargo workspaces
  • Module resolution

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking enhancement)

✔️ Verification

The following checks pass successfully:

pnpm typecheck
pnpm lint        (oxlint)
pnpm format:check (oxfmt)
pnpm test src/mappers/rust.test.ts

Evidence

Test Results

✓ src/mappers/rust.test.ts (3 tests)

Test Files  1 passed (1)
Tests       3 passed (3)

Before

{
  "entryPath": "src/main.rs",
  "contextFiles": []
}

After

{
  "entryPath": "src/main.rs",
  "contextFiles": [
    {
      "path": "Cargo.toml",
      "reason": "cargo package manifest"
    },
    {
      "path": "src/lib.rs",
      "reason": "crate library entry"
    },
    {
      "path": "src/api.rs",
      "reason": "declared module"
    }
  ]
}

Closes #164

@Tanmay-008
Tanmay-008 requested a review from a team as a code owner July 25, 2026 16:23
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 25, 2026, 12:35 PM ET / 16:35 UTC.

ClawSweeper review

What this changes

The branch adds Rust mapper context for each generated seed: its Cargo manifest, related crate entry point, and directly declared Rust modules, with focused Rust mapper tests.

Merge readiness

Blocked until real behavior proof from a real setup is added - 3 items remain

This PR remains necessary because current main is identified as deffd4b799bdb815a7582fa838cb1659c41d1641 and the supplied PR diff adds the missing Rust context behavior rather than duplicating an existing current-main implementation. The implementation is focused and the supplied checks are green, but this external PR still needs after-fix evidence from a real mapper run before merge. Likely related people: no current-main feature-history owner could be confirmed from the available read-only evidence (low confidence).

Priority: P2
Reviewed head: bc062bd2d315798419436d35df8e2350ee675565

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The mapper implementation is focused and supported by tests, but the required real behavior proof is still absent.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR provides focused test output and illustrative JSON, but not inspectable after-fix evidence from a real clawpatch map run; add a redacted terminal capture or live output and update the PR body for a fresh review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR provides focused test output and illustrative JSON, but not inspectable after-fix evidence from a real clawpatch map run; add a redacted terminal capture or live output and update the PR body for a fresh review.
Evidence reviewed 4 items Focused implementation: The supplied PR patch changes src/mappers/rust.ts to pass context files into Rust command, library, binary, integration-test, and workspace seed construction, and adds src/mappers/rust.test.ts coverage for a binary crate, paired main/lib entries, and workspace behavior.
Existing seed contract: FeatureSeed already supports optional contextFiles, so the branch extends the established mapper output shape rather than adding a parallel API.
Related work remains open: The PR body links the concrete report at #164 with closing syntax; because this PR is still open, that linked issue should remain open until a reviewed merge resolves it.
Findings None None.
Security None None.

How this fits together

Clawpatch mappers turn repository files into feature seeds for later automated review and repair. The Rust mapper reads Cargo project structure and Rust source files, then emits each seed with nearby context files that downstream providers can inspect.

flowchart LR
  A[Rust workspace files] --> B[Rust mapper]
  B --> C[Detect crate seeds]
  C --> D[Collect manifest and module context]
  D --> E[Feature seed]
  E --> F[Provider review and repair]
  A --> G[Cargo manifests]
  G --> D
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR provides focused test output and illustrative JSON, but not inspectable after-fix evidence from a real clawpatch map run; add a redacted terminal capture or live output and update the PR body for a fresh review.
  • Resolve merge risk (P1) - The PR body contains test output and a claimed before/after JSON result, but no independently inspectable after-fix run or redacted terminal/log capture from a real Rust project; that leaves the mapper behavior merge-gated despite green automated checks.
  • Complete next step (P2) - The remaining merge blocker is contributor-supplied real behavior proof, which an automated repair worker cannot produce on the contributor's setup.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 227 added, 10 removed across 3 files The change is concentrated in one mapper, one dedicated test file, and one existing mapper assertion.
Validation checks 7 successful GitHub checks The branch passed automated test, static-analysis, secret-scan, and security checks, while real behavior proof remains separate.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the focused Rust context expansion, then add a redacted terminal capture or live output from clawpatch map on a representative Rust crate showing the emitted manifest, sibling entry, and declared-module context before merging.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the focused Rust context expansion, then add a redacted terminal capture or live output from clawpatch map on a representative Rust crate showing the emitted manifest, sibling entry, and declared-module context before merging.

Do we have a high-confidence way to reproduce the issue?

Unclear for a failing current-main path: the supplied issue and patch show that Rust seeds currently omit context, and the changed mapper path is source-reproducible, but this review could not run the mapper against a real fixture in the restricted read-only environment.

Is this the best way to solve the issue?

Yes, provisionally: extending the existing contextFiles field in the Rust mapper follows the repository's established mapper model and avoids a new public configuration surface; a real-project mapper capture should confirm the path handling before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against deffd4b799bd.

Labels

Label changes:

  • add P2: The change improves Rust project context quality for mapper output but does not show an urgent user-facing outage or data-loss/security condition.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused test output and illustrative JSON, but not inspectable after-fix evidence from a real clawpatch map run; add a redacted terminal capture or live output and update the PR body for a fresh review.

Label justifications:

  • P2: The change improves Rust project context quality for mapper output but does not show an urgent user-facing outage or data-loss/security condition.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused test output and illustrative JSON, but not inspectable after-fix evidence from a real clawpatch map run; add a redacted terminal capture or live output and update the PR body for a fresh review.

Evidence

What I checked:

  • Focused implementation: The supplied PR patch changes src/mappers/rust.ts to pass context files into Rust command, library, binary, integration-test, and workspace seed construction, and adds src/mappers/rust.test.ts coverage for a binary crate, paired main/lib entries, and workspace behavior. (src/mappers/rust.ts:32, bc062bd2d315)
  • Existing seed contract: FeatureSeed already supports optional contextFiles, so the branch extends the established mapper output shape rather than adding a parallel API. (src/mappers/types.ts:1, deffd4b799bd)
  • Related work remains open: The PR body links the concrete report at Rust Mapper emits zero contextFiles for seeds #164 with closing syntax; because this PR is still open, that linked issue should remain open until a reviewed merge resolves it. (bc062bd2d315)
  • Repository review policy applied: The repository guidance requires focused mapper tests and conservative handling of files that may contain secrets; the diff stays limited to the Rust mapper and tests, and the PR check suite reports successful typecheck, lint, secret scanning, CodeQL, and tests. (AGENTS.md:260, deffd4b799bd)

Likely related people:

  • No confirmed current-main owner: The required local git history and blame inspection could not be completed in the read-only execution environment, and the PR author is not treated as an owner solely for proposing this branch. (role: feature-history ownership unresolved; confidence: low; files: src/mappers/rust.ts, src/mappers/types.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Run the built CLI against a representative Rust crate and attach redacted terminal output showing the generated contextFiles for manifest, sibling entry, and declared modules.
  • After adding proof, update the PR body; if no automatic re-review occurs, ask a maintainer to comment @clawsweeper re-review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@Tanmay-008

Copy link
Copy Markdown
Contributor Author

Evidence

Real Behavior Proof (clawpatch map): Ran clawpatch map on a real Rust project directory (src/main.rs with mod api;):

json

{
"featureId": "feat_cli-command_d7b99a1ec5",
"title": "Rust command rust-proof",
"entrypoints": [
{
"path": "src/main.rs",
"symbol": "main"
}
],
"contextFiles": [
{
"path": "Cargo.toml",
"reason": "cargo package manifest"
},
{
"path": "src/api.rs",
"reason": "declared module"
}
]
}

  • Test Results:

✓ src/mappers/rust.test.ts (3 tests) 15ms
Test Files 1 passed (1)
Tests 3 passed (3)

@clawsweeper

clawsweeper Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: feat(mapper): add contextFiles for rust seeds This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

Copy link
Copy Markdown
Contributor

Maintainer exact-head proof for 7035b87cee9213e7000875c0c81c48e42e1a3fd5:

  • Reproduced current main mapping a real Rust crate with empty contextFiles.
  • Preserved @Tanmay-008's original commits and added separate maintainer commits f7ba1b1 (entrypoint-relative nested/flat binary module resolution plus regressions) and 7035b87 (credited changelog).
  • Focused regressions: both src/bin/worker/main.rs -> mod protocol; and src/bin/audit.rs -> mod output; failed before the repair and pass afterward.
  • Full local gate: typecheck, Oxlint, Oxfmt, 894 tests passed / 1 skipped, build, and packaged CLI smoke.
  • Installed-tarball proof emitted src/bin/worker/protocol.rs and src/bin/audit/output.rs, rejected a crate-root decoy, and remained stable across a repeat map. Structural SHA-256: ba243844ce8ca0a46e5a4ca073808bd32e7237ccbc3c44f54dc7650435e2e9fd. Tarball SHA-256: 5d113e4b10ab33dead1c1a0c0f52f706504887f10fbcb62f459dedaca42d20c6.
  • Codex autoreview: clean, no accepted/actionable findings.
  • Hosted exact-head checks: CI 30168989215, CodeQL 30168989313, and secret scanning 30168989236 all succeeded.

This resolves #164 while keeping direct module discovery bounded.

@steipete
steipete merged commit 53cdeaa into openclaw:main Jul 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust Mapper emits zero contextFiles for seeds

2 participants