perf(staged): pre-compute git context before create-PR agent session#485
perf(staged): pre-compute git context before create-PR agent session#485
Conversation
Run `git log`, `git diff --stat`, and `git diff` in parallel on the Rust side before the agent session starts, then inject the results into the prompt. This lets the agent skip straight to pushing and creating the PR instead of spending time on deterministic git commands. Falls back to the original prompt (agent runs git itself) if any pre-computation command fails. Large diffs are truncated at 50k chars. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3eef30849
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
apps/staged/src-tauri/src/prs.rs
Outdated
| if diff.len() <= DIFF_TRUNCATION_LIMIT { | ||
| return diff; | ||
| } | ||
| let truncated = &diff[..DIFF_TRUNCATION_LIMIT]; |
There was a problem hiding this comment.
Avoid slicing diff at non-UTF-8 character boundaries
truncate_diff indexes the string with a raw byte offset (&diff[..DIFF_TRUNCATION_LIMIT]). If a large diff contains multibyte UTF-8 text, hitting the 50,000-byte cutoff in the middle of a character will panic, which can crash create_pr instead of gracefully falling back. This is reproducible when the diff exceeds the limit and includes non-ASCII content (for example in source strings/comments or filenames), so truncation needs to find a valid character boundary before slicing.
Useful? React with 👍 / 👎.
The `parseContentSegments` regex used non-greedy matching (`*?`), causing it to match nested `<action>` tags inside pre-computed diffs (e.g. diffs of prs.rs itself) instead of the outermost wrapper. Switch to greedy matching so the first opening tag pairs with the last matching closing tag. Also fix a potential panic in `truncate_diff` when slicing at a byte index that falls mid-character in multi-byte UTF-8 by using `floor_char_boundary`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the `git diff origin/{base}...HEAD` pre-computation and the
`truncate_diff` helper. The commit log and diff stat are sufficient
for the agent to write a good PR title and body, and skipping the
full diff avoids large payloads and speeds up the pre-computation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
std::thread::scope; for remote branches they run sequentially (SSH transport serializes anyway)Test plan
🤖 Generated with Claude Code