Repository navigation
refactor: move caption word utilities into cap-project - #3278
richiemcilroy merged 1 commit into
Conversation
|
@Ker102 is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
| //! Single source of truth for how transcribed words are cleaned up and grouped | ||
| //! into on-screen caption segments. This used to be copy-pasted across the | ||
| //! Tauri captions pipeline (`apps/desktop/src-tauri/src/captions.rs`), the gpui | ||
| //! transcription pipeline (`apps/desktop-gpui/src/transcription.rs`), | ||
| //! `caption_timing`, and `editor_window`, and the copies drifted apart. |
There was a problem hiding this comment.
Comments violate repository policy
The new module comment describes this refactor, and the comment above normalize_caption_words repeats what the code does. AGENTS.md explicitly bans both kinds of comments. Remove these before merging to satisfy that requirement. Keep the comments explaining the Unicode check and inflated word durations.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/project/src/caption_words.rs
Line: 3-7
Comment:
**Comments violate repository policy**
The new module comment describes this refactor, and the comment above `normalize_caption_words` repeats what the code does. `AGENTS.md` explicitly bans both kinds of comments. Remove these before merging to satisfy that requirement. Keep the comments explaining the Unicode check and inflated word durations.
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| /// Groups normalized words into caption segments of at most | ||
| /// [`MAX_CAPTION_WORDS_PER_SEGMENT`] words, aiming for | ||
| /// [`TARGET_CAPTION_WORDS_PER_SEGMENT`]. The boundary word may move past the |
There was a problem hiding this comment.
Eight-word guarantee is incorrect
The new documentation promises at most eight words, but merging a short tail can produce ten. With ten words and weak words at positions six, seven, and nine, the first chunk extends to eight and then takes the remaining two. Callers of this newly public helper could rely on a limit it does not enforce. Remove the hard-limit claim rather than changing the existing behavior in this refactor.
| /// Groups normalized words into caption segments of at most | |
| /// [`MAX_CAPTION_WORDS_PER_SEGMENT`] words, aiming for | |
| /// [`TARGET_CAPTION_WORDS_PER_SEGMENT`]. The boundary word may move past the | |
| /// Groups normalized words into caption segments, aiming for | |
| /// [`TARGET_CAPTION_WORDS_PER_SEGMENT`]. The boundary word may move past the |
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/project/src/caption_words.rs
Line: 140-142
Comment:
**Eight-word guarantee is incorrect**
The new documentation promises at most eight words, but merging a short tail can produce ten. With ten words and weak words at positions six, seven, and nine, the first chunk extends to eight and then takes the remaining two. Callers of this newly public helper could rely on a limit it does not enforce. Remove the hard-limit claim rather than changing the existing behavior in this refactor.
```suggestion
/// Groups normalized words into caption segments, aiming for
/// [`TARGET_CAPTION_WORDS_PER_SEGMENT`]. The boundary word may move past the
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Follow-up on the two checks I owed: |
) caption_text_from_words, the attach-to-previous helpers, normalize_caption_words, caption_word_chunks and the segment size constants were copy-pasted across captions.rs (tauri), transcription.rs (gpui), editor_window.rs (gpui) and caption_timing.rs, and the copies had drifted. They now all consume the single set in cap_project::caption_words. One behavior change: the weak-word boundary check on the Tauri side compared byte length (normalized.len() <= 1), so non-ASCII one letter words like "à" counted as two letters there. The shared version compares chars().count(), matching what CapSoftware#2685 landed in the gpui backend.
7f84158 to
e1ded27
Compare
|
Thanks @Openroot-MI, pulling these into one place is a good cleanup and the Before we can merge, it needs a 5/5 from Greptile on its latest commit and green CI. It's at 4/5 right now, for two things:
Since |
|
sorry, this one went up from the wrong account. replaced by #3295, the review notes are folded in over there. |
Moves the caption word utilities (caption_text_from_words, the attach-to-previous helpers, normalize_caption_words, caption_word_chunks, and the segment size constants) into cap_project::caption_words and points everything at it. They were copy-pasted in four places and had already drifted, details in #3274.
One behavior change: the Tauri backend's weak-word boundary check compared byte length (
normalized.len() <= 1), so one letter words like "à" counted as two letters there. The shared version compareschars().count(), matching the #2685 fix that only landed in the gpui backend. Everything else is a straight move.Also folds in the f64 copy of MAX_CAPTION_WORD_DURATION from crates/rendering/src/layers/captions.rs, which now derives from the shared const instead of a comment asking people to keep it in sync.
Tested:
Still running locally, I'll post results: cargo check -p cap-rendering and cargo check -p cap-desktop. The gpui workspace pulls its own giant dep tree so I haven't built it here, the transcription.rs and editor_window.rs changes are deletes plus imports.
Closes #3274
I've got a follow-up ready to build on this for #3275 (configurable words per caption).
The refactor preserves the intended behavior, but the explicit comments requirement must be satisfied before merging.
Findings
Fix with agent prompt
Summary
Moves shared caption helpers and constants into
cap_project::caption_words.Review used source inspection; no builds or tests were run.
Reviews (1) · Last reviewed commit: "refactor: move caption word utilities in..." · Reviewed by Greptile