Skip to content

#70 set up Cargo.toml and base main.rs - #71

Merged
Asifdotexe merged 6 commits into
68-refactor-architecturefrom
70-port-logic-to-rust
Jul 26, 2026
Merged

Asifdotexe merged 6 commits into
68-refactor-architecturefrom
70-port-logic-to-rust

Conversation

@Asifdotexe

@Asifdotexe Asifdotexe commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a Rust-based repository analysis engine for faster snapshot and history processing.
    • Added options to resume processing from the latest point, reprocess data, or perform a full fossil scan.
    • Added Windows build and run scripts for easier engine execution.
    • Analysis results now include expanded history, fossil, and state artifacts.
  • Bug Fixes

    • Improved processing reliability by preserving intermediate state and supporting resumable runs.
  • Tests

    • Added automated Rust formatting, linting, caching, and test checks.

@Asifdotexe Asifdotexe self-assigned this Jul 26, 2026
@Asifdotexe Asifdotexe added the enhancement New feature or request label Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Asifdotexe, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e24d354-3d2c-476c-9b64-103f183997ad

📥 Commits

Reviewing files that changed from the base of the PR and between 37bb1b3 and bba6709.

📒 Files selected for processing (7)
  • .github/workflows/theseus-engine.yml
  • .github/workflows/unit-tests.yml
  • build_engine.bat
  • engine/src/main.rs
  • journal.md
  • run_engine.bat
  • scripts/analyse_repository.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 70-port-logic-to-rust

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.

@Asifdotexe
Asifdotexe marked this pull request as ready for review July 26, 2026 10:42

@coderabbitai coderabbitai 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.

Actionable comments posted: 6

🧹 Nitpick comments (2)
engine/src/main.rs (1)

115-146: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid re-opening a Repository per file; open once per worker thread.

into_par_iter().filter_map(...) calls Repository::open(repo_path) once for every file dispatched to rayon, not once per worker thread. For repos with thousands of tracked/changed files this adds redundant repo-initialization I/O on the hot path this PR is specifically trying to speed up.

Use rayon's map_init/for_each_init to open the Repository once per worker thread and reuse it across all files that thread processes, while still respecting git2::Repository's lack of Sync (each thread still gets its own handle).

⚡ Proposed refactor
-    let results: Vec<(String, HashMap<String, u32>)> = files_to_blame
-        .into_par_iter()
-        .filter_map(|path| {
-            // Open a thread-local repository instance
-            let repo = Repository::open(repo_path).ok()?;
-
-            let mut opts = BlameOptions::new();
+    let results: Vec<(String, HashMap<String, u32>)> = files_to_blame
+        .into_par_iter()
+        .map_init(
+            || Repository::open(repo_path).ok(),
+            |repo, path| {
+                let repo = repo.as_ref()?;
+                let mut opts = BlameOptions::new();
                 opts.newest_commit(commit_oid);
 
                 let blame = repo.blame_file(Path::new(&path), Some(&mut opts)).ok()?;
 
                 let mut year_counts = HashMap::new();
                 for hunk in blame.iter() {
                     let time = hunk.final_signature().when();
                     let datetime = Utc.timestamp_opt(time.seconds(), 0).unwrap();
                     let year = datetime.format("%Y").to_string();
                     let lines = hunk.lines_in_hunk() as u32;
 
                     *year_counts.entry(year).or_insert(0) += lines;
                 }
 
-            Some((path, year_counts))
-        })
+                Some((path, year_counts))
+            },
+        )
+        .flatten()
         .collect();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@engine/src/main.rs` around lines 115 - 146, Update process_blame to use
Rayon’s per-worker initialization, such as map_init, creating one
Repository::open(repo_path) handle for each worker and reusing it while
processing that worker’s files. Preserve the existing blame and aggregation
behavior, and ensure each thread retains its own repository handle to respect
git2::Repository’s thread-safety constraints.
scripts/analyse_repository.py (1)

396-438: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider invoking a pre-built engine binary instead of cargo run --release at analysis time.

The non-Windows branch shells out to cargo run --release --manifest-path engine/Cargo.toml -- ... directly, while Windows goes through a dedicated run_engine.bat wrapper. This asymmetry means build/runtime flags added to the batch wrapper aren't automatically mirrored here, and cargo run re-triggers Cargo's dependency/build check on every repository processed rather than invoking a pre-built artifact — adding overhead and an implicit reliance on the Rust toolchain (and possibly network access for crate resolution) being available wherever this orchestration script runs.

Consider adding an equivalent run_engine.sh/wrapper for non-Windows, or building the release binary once (e.g., in CI, consistent with the "Rust caching" work mentioned for this PR stack) and invoking the compiled path directly from both branches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/analyse_repository.py` around lines 396 - 438, Update the engine
invocation in process_repository so analysis uses a pre-built Rust release
binary or equivalent run_engine.sh wrapper on non-Windows, matching the existing
Windows run_engine.bat behavior. Remove the per-repository cargo run --release
dependency while preserving the existing repository, output, state, and optional
reprocess arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/theseus-engine.yml:
- Around line 8-12: Update the reprocess input definition and its dispatch
handling to advertise and accept only the supported values, all and last. Remove
the misleading YYYY-MM example from the reprocess description and prevent
unsupported period-specific values from being passed through as valid requests.
- Around line 65-78: Update the workflow step containing REPROCESS_FLAG and
SURVIVOR_FLAG so github.event.inputs.reprocess is passed through an environment
variable rather than interpolated into the Bash script. Build the reprocess
arguments with a quoted Bash array and expand that array safely when invoking
scripts.run_pipeline, preserving the existing behavior for empty and non-empty
inputs.
- Around line 57-60: Pin the Swatinem/rust-cache action to commit SHA
e18b497796c12c097a38f9edb9d0641fb99eee32 instead of the mutable `@v2` tag in the
Rust Cache step of .github/workflows/theseus-engine.yml lines 57-60 and the
corresponding step in .github/workflows/unit-tests.yml lines 38-41.

In `@build_engine.bat`:
- Around line 9-10: Update build_engine.bat at lines 9-10 and run_engine.bat at
lines 8-10 to use a checked pushd to "%~dp0engine" and exit on failure, ensuring
both scripts resolve the engine directory from their own locations. After the
Cargo command, preserve its exit code while running popd, then return the
preserved code.

In `@engine/src/main.rs`:
- Around line 222-300: Persist the updated file_compositions state at the end of
every successfully processed period within the periods loop, immediately after
writing its SnapshotData to out_file. Reuse the existing args.state
parent-directory creation and serde_json serialization behavior, ensuring each
checkpoint is written before the next iteration; retain the final persistence
only if needed as a fallback.
- Around line 177-218: Before opening out_file, rewrite the existing output
JSONL when appending so it retains only rows whose snapshot_date remains in the
final processed_periods set. Apply this to both reprocess_val == "last" and
reprocess_val == "<YYYY-MM>", then open out_file for appending so reprocessed
snapshots do not create duplicate or stale records.

---

Nitpick comments:
In `@engine/src/main.rs`:
- Around line 115-146: Update process_blame to use Rayon’s per-worker
initialization, such as map_init, creating one Repository::open(repo_path)
handle for each worker and reusing it while processing that worker’s files.
Preserve the existing blame and aggregation behavior, and ensure each thread
retains its own repository handle to respect git2::Repository’s thread-safety
constraints.

In `@scripts/analyse_repository.py`:
- Around line 396-438: Update the engine invocation in process_repository so
analysis uses a pre-built Rust release binary or equivalent run_engine.sh
wrapper on non-Windows, matching the existing Windows run_engine.bat behavior.
Remove the per-repository cargo run --release dependency while preserving the
existing repository, output, state, and optional reprocess arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12e1a6c3-0fa2-4846-a982-10ca04f3022b

📥 Commits

Reviewing files that changed from the base of the PR and between f7deba3 and 37bb1b3.

⛔ Files ignored due to path filters (1)
  • engine/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/workflows/theseus-engine.yml
  • .github/workflows/unit-tests.yml
  • build_engine.bat
  • engine/Cargo.toml
  • engine/src/main.rs
  • journal.md
  • run_engine.bat
  • scripts/analyse_repository.py

Comment thread .github/workflows/theseus-engine.yml Outdated
Comment thread .github/workflows/theseus-engine.yml
Comment thread .github/workflows/theseus-engine.yml Outdated
Comment thread build_engine.bat Outdated
Comment thread engine/src/main.rs
Comment thread engine/src/main.rs
…ld scripts

- Fix reprocess inputs and bash arrays in theseus-engine.yml

- Pin rust-cache actions to verified commit

- Refactor engine main.rs to use map_init for git2 thread-safety

- Persist incremental state inside period processing loop

- Rewrite JSONL when appending to deduplicate reprocessed rows

- Avoid cargo run inside analyse_repository for non-Windows

- Use checked pushd in bat scripts with preserved exit code
@Asifdotexe

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

@Asifdotexe
Asifdotexe merged commit a260e07 into 68-refactor-architecture Jul 26, 2026
1 check passed
@Asifdotexe
Asifdotexe deleted the 70-port-logic-to-rust branch July 26, 2026 11:20
@Asifdotexe Asifdotexe linked an issue Jul 26, 2026 that may be closed by this pull request
@coderabbitai coderabbitai Bot mentioned this pull request Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

port logic to rust

1 participant