Skip to content

refactor: move caption word utilities into cap-project - #3278

Merged
richiemcilroy merged 1 commit into
CapSoftware:mainfrom
Openroot-MI:refactor/caption-words-shared-module
Oct 26, 2026
Merged

richiemcilroy merged 1 commit into
CapSoftware:mainfrom
Openroot-MI:refactor/caption-words-shared-module

Conversation

@Openroot-MI

@Openroot-MI Openroot-MI commented Oct 25, 2026 •

Copy link
Copy Markdown

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 compares chars().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).

RetriggerView in GreptileConfidence Score: 4/5

The refactor preserves the intended behavior, but the explicit comments requirement must be satisfied before merging.

Findings

  1. P2 Comments violate repository policy ▶
  2. P2 Eight-word guarantee is incorrect ▶
Fix with agent prompt
### Issue 1
crates/project/src/caption_words.rs:3-7
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.

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!

### Issue 2
crates/project/src/caption_words.rs:140-142
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.

Summary

Moves shared caption helpers and constants into cap_project::caption_words.

  • Caption cleanup and word breaks now follow one shared set of rules.

Review used source inspection; no builds or tests were run.

Reviews (1) · Last reviewed commit: "refactor: move caption word utilities in..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

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

Comment on lines +3 to +7
//! 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

Comment on lines +140 to +142
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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.

Suggested change
/// 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.

@Openroot-MI

Copy link
Copy Markdown
Author

Follow-up on the two checks I owed: cargo check -p cap-rendering and cargo check -p cap-desktop didn't run in my environment after all. Both die in dependency build scripts (alsa-sys and x11-2.21) because the box has no pkg-config and I have no sudo to install it, and the Docker fallback I tried took a bad turn. So the verified part of this PR is what's listed above (cap-project tests 195, clippy, fmt) and CI is the build check for the rest. I'll follow up if it turns anything up.

)

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.
@Openroot-MI
Openroot-MI force-pushed the refactor/caption-words-shared-module branch from 7f84158 to e1ded27 Compare October 25, 2026 21:27
@richiemcilroy

Copy link
Copy Markdown
Member

Thanks @Openroot-MI, pulling these into one place is a good cleanup and the chars().count() fix for the Tauri copy is welcome.

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:

  • caption_words.rs adds a module comment about the refactor and a comment above normalize_caption_words that restates the code. AGENTS.md doesn't allow either, so please remove them. The comments explaining the Unicode check and the inflated word duration can stay.
  • The doc on caption_word_chunks promises at most eight words, but merging a short tail can produce ten. Either make the guarantee true or drop it from the doc.

Since apps/desktop is the old Tauri app and no longer ships, it's fine to leave its copy alone if that keeps this smaller. Once the fixes are in, request a re-review. #3284 is stacked on this one, so it lands first.

@Ker102

Ker102 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

sorry, this one went up from the wrong account. replaced by #3295, the review notes are folded in over there.

@richiemcilroy
richiemcilroy merged commit e1ded27 into CapSoftware:main Oct 26, 2026
49 of 52 checks passed
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.

caption word chunking and text assembly duplicated across four places

3 participants