Repository navigation
fix(ai-vault): stop labeling the preview fallback as the first prompt - #12178
Conversation
Greptile SummaryThis PR fixes an honest-labeling bug in the AI Vault session details panel: preview-window text that comes from a sliding-window fallback is now tagged with a
Confidence Score: 4/5Safe to merge; the change is display-only with no IPC, auth, or data-persistence side-effects. The core behavioral shift — surfacing truncated preview text for remote sessions instead of hiding it — is intentional, well-tested, and correctly walled off by the 'preview-window' source tag so the renderer never misrepresents it. Two small rough edges exist in ai-vault-first-prompt-card.tsx: the section label briefly reads the generic 'Prompt' while loading for sessions that have no preview user messages (contradicting the 'Loading first prompt…' body text), and promptCopiedLabel silently conflates an undefined source with 'preview-window' in its fallback branch. Neither affects correctness in the paths exercised today, but both could cause confusion if the call-sites evolve. Files Needing Attention: ai-vault-first-prompt-card.tsx — the displaySource derivation and the promptCopiedLabel fallback branch are worth a second look.
|
| Filename | Overview |
|---|---|
| src/shared/ai-vault-session-display.ts | Renamed sessionFirstPrompt → sessionPromptPreview; returns AiVaultSessionPromptPreview |
| src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsx | Card now owns its own section label and derives it from displaySource; loading/copy/clipboard paths are otherwise unchanged. Minor: when preview is null and loading is true, displaySource is undefined and the label shows the generic 'Prompt' before flipping to 'First prompt' once the read settles. The promptCopiedLabel fallback silently equates undefined with 'preview-window'. |
| src/renderer/src/components/right-sidebar/AiVaultSessionDetails.tsx | Removed the SessionReceiptSection wrapper around FirstPromptCard (and the TextCursorInput import) since the card now renders its own section header; the change is clean with no logic impact. |
| src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsx | Three new cases added: stored firstUserPrompt labelled 'First prompt', remote truncated preview labelled 'Recent prompt' with no IPC call, and local truncated preview relabelled after the full load resolves. Existing StrictMode and timeout tests updated for the new prop signature. |
| src/renderer/src/i18n/locales/en.json | Added five new i18n keys: prompt, recentPrompt, recentPromptCopied, copyRecentPrompt, copyPrompt. All other locale files (es, ja, ko, zh) have matching additions. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[sessionPromptPreview called] --> B{firstUserPrompt stored?}
B -- Yes --> C[return text, source: first-user-prompt]
B -- No --> D{user message in previewMessages?}
D -- Yes --> E[return text, source: preview-window]
D -- No --> F[return null]
C --> G[FirstPromptCard receives preview]
E --> G
F --> G
G --> H{canLoadFullFirstPrompt?}
H -- Yes / local --> I[loading = true, show preview label + text]
H -- No / remote --> J[loading = false, show preview label + text]
I --> K[getFirstUserPrompt IPC call]
K -- success --> L[fullText set, displaySource = first-user-prompt, label = First prompt]
K -- timeout / null --> M[fullText stays null, displaySource = preview?.source]
M -- preview-window --> N[label = Recent prompt]
M -- null --> O[label = Prompt generic]
Reviews (1): Last reviewed commit: "fix(ai-vault): label preview prompt hone..." | Re-trigger Greptile
| const displaySource = fullText ? 'first-user-prompt' : preview?.source | ||
| const showEmpty = !loading && !displayText |
There was a problem hiding this comment.
Label shows generic "Prompt" while loading, then flips to "First prompt"
When preview is null and loading is true (a local session that has no stored firstUserPrompt and no user messages in previewMessages), displaySource resolves to undefined, so promptSectionLabel renders the generic "Prompt" header — even though the loading message beneath it already reads "Loading first prompt…". Once the read settles with a real value, the label jumps to "First prompt". The transient mismatch is observable whenever those three conditions coincide.
| function promptCopiedLabel(source: AiVaultSessionPromptPreview['source'] | undefined): string { | ||
| return source === 'first-user-prompt' | ||
| ? translate( | ||
| 'auto.components.right.sidebar.AiVaultSessionDetails.firstPromptCopied', | ||
| 'First prompt copied' | ||
| ) | ||
| : translate( | ||
| 'auto.components.right.sidebar.AiVaultSessionDetails.recentPromptCopied', | ||
| 'Recent prompt copied' | ||
| ) |
There was a problem hiding this comment.
undefined source falls through to "Recent prompt copied" toast
When source is undefined (neither 'first-user-prompt' nor 'preview-window'), promptCopiedLabel silently returns "Recent prompt copied" — the same string as the 'preview-window' case — rather than a neutral fallback. In practice today the toast cannot fire when source is undefined because the caller would have already returned early (empty copyText), but this implicit coupling makes the function's contract easy to break silently if the call-sites change. A third branch (or an explicit fallback matching the generic "Prompt copied" wording) would make the boundary explicit.
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!
📝 WalkthroughWalkthroughThe AI Vault session display now returns structured prompt previews with source metadata. Stored first prompts take precedence, while preview-window user prompts remain available when the window is truncated. The prompt card uses source-specific headings, copy labels, icons, and success messages. Session details pass the structured preview directly to the card. English, Spanish, Japanese, Korean, and Chinese locales include the new prompt strings. Tests cover resolution and rendering behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsx (1)
160-166: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider reusing
SessionReceiptSectioninstead of duplicating its header markup.This block duplicates the icon-wrapper and label markup of
SessionReceiptSectioninAiVaultSessionDetails.tsx(same class names for the outer flex row, icon span, and label span).SessionReceiptSectionstill renders that same header pattern for "Latest turns" and "Worktree" sections in that file.Export
SessionReceiptSectionfrom a shared location and use it here with the dynamic icon andpromptSectionLabel(displaySource)as itslabelprop. This keeps one source of truth for the section-header layout.♻️ Proposed direction
- <section className="space-y-1.5"> - <div className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.05em] text-muted-foreground"> - <span className="text-muted-foreground/80"> - <TextCursorInput className="size-3" /> - </span> - <span>{promptSectionLabel(displaySource)}</span> - </div> - <div className="rounded-md border border-border/70 bg-foreground/[0.04] px-2.5 py-2"> + <SessionReceiptSection + icon={<TextCursorInput className="size-3" />} + label={promptSectionLabel(displaySource)} + > + <div className="rounded-md border border-border/70 bg-foreground/[0.04] px-2.5 py-2">
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 780ac197-2469-4372-8225-7f13aee7c22e
📒 Files selected for processing (11)
src/renderer/src/components/right-sidebar/AiVaultSessionDetails.tsxsrc/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsxsrc/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsxsrc/renderer/src/components/right-sidebar/ai-vault-session-display.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-display.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/ai-vault-session-display.ts
| it('labels stored firstUserPrompt text as the first prompt', () => { | ||
| const remoteSession = { | ||
| ...session, | ||
| executionHostId: 'ssh:dev-box', | ||
| firstUserPrompt: 'The authoritative opening ask' | ||
| } as AiVaultSession | ||
| stubApi(vi.fn().mockResolvedValue({ prompt: null })) | ||
|
|
||
| render( | ||
| <FirstPromptCard session={remoteSession} preview={sessionPromptPreview(remoteSession)} /> | ||
| ) | ||
|
|
||
| expect(screen.getByText('First prompt')).toBeTruthy() | ||
| expect(screen.getByText('The authoritative opening ask')).toBeTruthy() | ||
| }) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Keep stored prompts authoritative for local sessions.
This test uses executionHostId: 'ssh:dev-box', so it cannot detect local behavior. FirstPromptCard starts loadFullPrompt() for a loadable local session even when preview.source is 'first-user-prompt'. A re-read can replace the stored prompt despite the required precedence.
Add a local stored-prompt case that asserts getFirstUserPrompt is not called. Skip the on-demand read when the preview source is 'first-user-prompt'.
Based on PR objective “Stored first prompts take precedence” and the supplied FirstPromptCard implementation.
|
Electron QA — live screenshots of both card states (dev build of this branch, isolated instance, seeded 8-message Claude session fixture so the last-5 preview window excludes the opening ask): Fallback state — full read unavailable (transcript unreadable, standing in for a remote-host session). Previously this text appeared under "First prompt"; it is the sliding-window fallback ("The parser chokes…" is message 5 of 8): Loaded state — on-demand read succeeds and the card relabels with the true opening ask: Method: seeded |


Summary
AI Vault session details now label sliding-window fallback text as "Recent prompt" and reserve "First prompt" for stored or successfully re-read opening prompts. Local sessions keep showing the preview while the full prompt loads, then update both the text and label when the authoritative read succeeds; remote sessions retain the honest recent-prompt state without adding remote file reads. Copy accessibility labels and success messages follow the same provenance, with translations added to every renderer locale catalog.
Screenshots
No screenshot captured because the required
$electronvalidation capability is unavailable in this session. The visual delta is limited to the existing prompt section label: preview-window text reads "Recent prompt" (localized), then changes to "First prompt" only after a local authoritative read succeeds.Testing
pnpm lint(not run; targeted changed-code quality gate passed)pnpm typecheck(pnpm tc)pnpm test(not run in full; targeted tests passed)pnpm build(not run)Additional checks:
pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/right-sidebar/ai-vault-session-display.test.ts src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsxpnpm run verify:localization-catalogpnpm run verify:localization-extractionpnpm run check:code-quality:changedAI Review Report
Reviewed prompt provenance through stored
firstUserPrompt, preview-window fallback, remote/unavailable reads, local successful replacement, loading stability, copy feedback, and locale coverage. The review found that the base branch suppressed truncated fallback text entirely; this change instead preserves the useful recent text while carrying explicit provenance through the display layer. Cross-platform compatibility was checked for macOS, Linux, and Windows: the change adds no shortcuts, path handling, shell behavior, platform checks, or Electron-specific branching, and the same localized labels and host-aware behavior apply on every platform.Security Audit
Reviewed input handling, IPC, path handling, command execution, auth, secrets, and dependencies. This PR adds no IPC surface, remote file access, command execution, path manipulation, authentication flow, secrets, or dependencies; it only classifies already-scanned prompt text and adjusts renderer copy. The existing local-only first-prompt read boundary remains unchanged, so no security follow-up is needed.
Notes
Remote-host first-prompt reads remain intentionally out of scope.
$electronwas unavailable, so Electron UI validation and screenshots could not be performed without violating the repository instruction against substitute UI automation.