fix: use session count instead of message count

This commit is contained in:
Tomasz Stefaniak 2025-10-07 20:44:22 -07:00
parent 914d587d11
commit fd3d402e9d
3 changed files with 27 additions and 29 deletions

View file

@ -351,10 +351,10 @@ describe("CliInstallBanner", () => {
});
});
describe("Message threshold logic", () => {
const renderWithMessageCount = async (
messageCount?: number,
messageThreshold?: number,
describe("Session threshold logic", () => {
const renderWithSessionCount = async (
sessionCount?: number,
sessionThreshold?: number,
) => {
vi.spyOn(mockIdeMessenger.ide, "subprocess").mockResolvedValue([
"",
@ -365,8 +365,8 @@ describe("CliInstallBanner", () => {
render(
<IdeMessengerContext.Provider value={mockIdeMessenger}>
<CliInstallBanner
messageCount={messageCount}
messageThreshold={messageThreshold}
sessionCount={sessionCount}
sessionThreshold={sessionThreshold}
/>
</IdeMessengerContext.Provider>,
),
@ -374,7 +374,7 @@ describe("CliInstallBanner", () => {
};
it("shows banner when no threshold is set", async () => {
await renderWithMessageCount(0, undefined);
await renderWithSessionCount(0, undefined);
await waitFor(() => {
expect(
@ -383,8 +383,8 @@ describe("CliInstallBanner", () => {
});
});
it("does not show banner when message count is below threshold", async () => {
await renderWithMessageCount(2, 3);
it("does not show banner when session count is below threshold", async () => {
await renderWithSessionCount(2, 3);
await waitFor(() => {
expect(
@ -393,8 +393,8 @@ describe("CliInstallBanner", () => {
});
});
it("shows banner when message count meets threshold", async () => {
await renderWithMessageCount(3, 3);
it("shows banner when session count meets threshold", async () => {
await renderWithSessionCount(3, 3);
await waitFor(() => {
expect(
@ -403,8 +403,8 @@ describe("CliInstallBanner", () => {
});
});
it("shows banner when message count exceeds threshold", async () => {
await renderWithMessageCount(5, 3);
it("shows banner when session count exceeds threshold", async () => {
await renderWithSessionCount(5, 3);
await waitFor(() => {
expect(

View file

@ -10,17 +10,17 @@ import { RunInTerminalButton } from "./StyledMarkdownPreview/StepContainerPreToo
import { Card } from "./ui";
interface CliInstallBannerProps {
/** Current message count - banner shows only if >= messageThreshold */
messageCount?: number;
/** Minimum messages before showing banner (default: always show) */
messageThreshold?: number;
/** Number of sessions user has had - banner shows only if >= sessionThreshold */
sessionCount?: number;
/** Minimum sessions before showing banner (default: always show) */
sessionThreshold?: number;
/** If true, dismissal is permanent via localStorage (default: session only) */
permanentDismissal?: boolean;
}
export function CliInstallBanner({
messageCount,
messageThreshold,
sessionCount,
sessionThreshold,
permanentDismissal = false,
}: CliInstallBannerProps = {}) {
const ideMessenger = useContext(IdeMessengerContext);
@ -90,13 +90,13 @@ export function CliInstallBanner({
// - Still loading CLI status
// - CLI is already installed
// - User has dismissed it
// - Message threshold not met (if threshold is set)
// - Session threshold not met (if threshold is set)
if (
cliInstalled === null ||
cliInstalled === true ||
dismissed ||
(messageThreshold !== undefined &&
(messageCount === undefined || messageCount < messageThreshold))
(sessionThreshold !== undefined &&
(sessionCount === undefined || sessionCount < sessionThreshold))
) {
return null;
}

View file

@ -119,6 +119,9 @@ export function Chat() {
const isInEdit = useAppSelector((store) => store.session.isInEdit);
const lastSessionId = useAppSelector((state) => state.session.lastSessionId);
const allSessionMetadata = useAppSelector(
(state) => state.session.allSessionMetadata,
);
const hasDismissedExploreDialog = useAppSelector(
(state) => state.ui.hasDismissedExploreDialog,
);
@ -381,11 +384,6 @@ export function Chat() {
const showScrollbar = showChatScrollbar ?? window.innerHeight > 5000;
// Count user messages for CLI banner threshold
const userMessageCount = useMemo(() => {
return history.filter((item) => item.message.role === "user").length;
}, [history]);
return (
<>
{!!showSessionTabs && !isInEdit && <TabBar ref={tabsRef} />}
@ -428,8 +426,8 @@ export function Chat() {
/>
<CliInstallBanner
messageCount={userMessageCount}
messageThreshold={5}
sessionCount={allSessionMetadata.length}
sessionThreshold={3}
permanentDismissal={true}
/>