Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/app/src/components/plugin/PluginThreadChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { PluginComposerHostScopeProvider } from "@/components/plugin/plugin-comp
import { ThreadProviderContext } from "@/components/thread/thread-provider-context";
import { useEnvironment } from "@/hooks/queries/environment-queries";
import { useEnvironmentCheckoutDisplay } from "@/hooks/queries/git-plugin-queries";
import { useSystemProviderInfo } from "@/hooks/queries/system-queries";
import {
useMarkThreadsReadOnView,
useSystemProviderInfo,
} from "@/hooks/queries/system-queries";
import { useThread } from "@/hooks/queries/thread-queries";
import { useThreadTimelineSubscription } from "@/hooks/queries/thread-panel-queries";
import { useMarkThreadRead } from "@/hooks/mutations/thread-state-mutations";
Expand Down Expand Up @@ -125,7 +128,9 @@ function PluginThreadChatBody({
routeThreadId: threadId,
thread,
});
const markOnView = useMarkThreadsReadOnView();
useThreadReadTracking({
markOnView,
markThreadRead,
thread: hasComposer && unreadDividerState.ready ? thread : undefined,
});
Expand Down
4 changes: 4 additions & 0 deletions apps/app/src/hooks/queries/system-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ export function useSystemConfig(options?: QueryOptions) {
});
}

export function useMarkThreadsReadOnView(): boolean {
return useSystemConfig().data?.generalSettings.markThreadsReadOnView === true;
}

export function useCliSkillsStatus(options?: QueryOptions) {
return useQuery<SystemCliSkillsStatusResponse>({
queryKey: systemCliSkillsQueryKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function setup(deferAbort = false) {
enabled: false,
});
useThreadReadTracking({
markOnView: true,
thread: query.data,
markThreadRead: useMarkThreadRead(),
});
Expand Down
53 changes: 53 additions & 0 deletions apps/app/src/hooks/useThreadReadTracking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe("useThreadReadTracking", () => {

renderHook(() =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: undefined,
}),
Expand All @@ -85,6 +86,7 @@ describe("useThreadReadTracking", () => {

renderHook(() =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: {
id: "thr_mobile_restore",
Expand Down Expand Up @@ -118,6 +120,7 @@ describe("useThreadReadTracking", () => {
const { rerender } = renderHook(
({ latestAttentionAt }: { latestAttentionAt: number }) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: {
id: "thr_side_chat",
Expand Down Expand Up @@ -145,6 +148,7 @@ describe("useThreadReadTracking", () => {
markThreadRead.mutateAsync.mockRejectedValueOnce(new Error("Failed"));
renderHook(() =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: {
id: "thr_side_chat",
Expand All @@ -168,6 +172,7 @@ describe("useThreadReadTracking", () => {
const { rerender } = renderHook(
({ lastReadAt }: VisibleThreadProps) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: {
id: "thr_side_chat",
Expand Down Expand Up @@ -206,6 +211,7 @@ describe("useThreadReadTracking", () => {
const { rerender } = renderHook(
({ lastReadAt, visible }: ReopenThreadProps) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: visible
? {
Expand Down Expand Up @@ -239,6 +245,7 @@ describe("useThreadReadTracking", () => {

renderHook(() =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: { id: "thr_unfocused", lastReadAt: 10, latestAttentionAt: 20 },
}),
Expand All @@ -263,6 +270,7 @@ describe("useThreadReadTracking", () => {
const { rerender } = renderHook(
({ latestAttentionAt }: { latestAttentionAt: number }) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: { id: "thr_idle", lastReadAt: 20, latestAttentionAt },
}),
Expand All @@ -281,12 +289,56 @@ describe("useThreadReadTracking", () => {
expect(markThreadRead.mutateAsync).toHaveBeenCalledTimes(1);
});

it("leaves a viewed thread unread while marking on view is off", () => {
const markThreadRead = makeMarkThreadRead();
const { rerender } = renderHook(
({ latestAttentionAt }: { latestAttentionAt: number }) =>
useThreadReadTracking({
markOnView: false,
markThreadRead,
thread: { id: "thr_manual", lastReadAt: 10, latestAttentionAt },
}),
{ initialProps: { latestAttentionAt: 20 } },
);
hideDocument();
setDocumentVisibilityState("visible");
act(() => {
document.dispatchEvent(new Event("visibilitychange"));
});
rerender({ latestAttentionAt: 30 });
pressKey();

expect(markThreadRead.mutateAsync).not.toHaveBeenCalled();
});

it("marks the open thread read once marking on view turns on", () => {
const markThreadRead = makeMarkThreadRead();
const { rerender } = renderHook(
({ markOnView }: { markOnView: boolean }) =>
useThreadReadTracking({
markOnView,
markThreadRead,
thread: { id: "thr_loading", lastReadAt: 10, latestAttentionAt: 20 },
}),
{ initialProps: { markOnView: false } },
);
expect(markThreadRead.mutateAsync).not.toHaveBeenCalled();

rerender({ markOnView: true });

expect(markThreadRead.mutateAsync).toHaveBeenCalledTimes(1);
expect(markThreadRead.mutateAsync).toHaveBeenLastCalledWith(
expect.objectContaining({ threadId: "thr_loading" }),
);
});

it("goes idle when the window loses focus", () => {
pressKeyWithFakeTimers();
const markThreadRead = makeMarkThreadRead();
const { rerender } = renderHook(
({ latestAttentionAt }: { latestAttentionAt: number }) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: { id: "thr_blurred", lastReadAt: 20, latestAttentionAt },
}),
Expand All @@ -309,6 +361,7 @@ describe("useThreadReadTracking", () => {
const { rerender } = renderHook(
({ lastReadAt }: { lastReadAt: number | null }) =>
useThreadReadTracking({
markOnView: true,
markThreadRead,
thread: {
id: "thr_remote_unread",
Expand Down
5 changes: 4 additions & 1 deletion apps/app/src/hooks/useThreadReadTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface MarkThreadReadMutation {
}

interface UseThreadReadTrackingParams {
markOnView: boolean;
markThreadRead: MarkThreadReadMutation;
thread?: ThreadReadTrackingState;
}
Expand All @@ -30,9 +31,11 @@ interface ReadTrackingSnapshot {
}

export function useThreadReadTracking({
markOnView,
markThreadRead,
thread,
thread: viewedThread,
}: UseThreadReadTrackingParams) {
const thread = markOnView ? viewedThread : undefined;
const failedReadKeysRef = useRef<Set<string>>(new Set());
const pendingReadControllersRef = useRef<Map<string, AbortController>>(
new Map(),
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/views/SettingsView.branch-prefix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function renderSection(overrides?: {
onKeepHistoryAfterContextClearChange={vi.fn()}
summarizeShellCommands={true}
onSummarizeShellCommandsChange={vi.fn()}
markThreadsReadOnView={true}
onMarkThreadsReadOnViewChange={vi.fn()}
desktopBrowserAvailable={false}
generalSettingsDisabled={overrides?.generalSettingsDisabled ?? false}
terminalCopyOnSelect={overrides?.terminalCopyOnSelect ?? true}
Expand Down
5 changes: 5 additions & 0 deletions apps/app/src/views/SettingsView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function useSettingsStoryState() {
const [keepHistoryAfterContextClear, setKeepHistoryAfterContextClear] =
useState(false);
const [summarizeShellCommands, setSummarizeShellCommands] = useState(true);
const [markThreadsReadOnView, setMarkThreadsReadOnView] = useState(true);
const [streamerMode, setStreamerMode] = useState(false);
const [telemetryEnabled, setTelemetryEnabled] = useState(true);
const [managedBranchPrefix, setManagedBranchPrefix] = useState(
Expand Down Expand Up @@ -158,6 +159,8 @@ function useSettingsStoryState() {
setKeepHistoryAfterContextClear,
summarizeShellCommands,
setSummarizeShellCommands,
markThreadsReadOnView,
setMarkThreadsReadOnView,
streamerMode,
telemetryEnabled,
setTelemetryEnabled,
Expand Down Expand Up @@ -218,6 +221,8 @@ function GeneralSettingsStory({
}
summarizeShellCommands={state.summarizeShellCommands}
onSummarizeShellCommandsChange={state.setSummarizeShellCommands}
markThreadsReadOnView={state.markThreadsReadOnView}
onMarkThreadsReadOnViewChange={state.setMarkThreadsReadOnView}
desktopBrowserAvailable={desktopBrowserAvailable}
generalSettingsDisabled={false}
terminalCopyOnSelect={terminalCopyOnSelect}
Expand Down
22 changes: 22 additions & 0 deletions apps/app/src/views/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ interface GeneralSettingsSectionProps {
onResumeThreadsAfterRestartChange: (enabled: boolean) => void;
summarizeShellCommands: boolean;
onSummarizeShellCommandsChange: (enabled: boolean) => void;
markThreadsReadOnView: boolean;
onMarkThreadsReadOnViewChange: (enabled: boolean) => void;
desktopBrowserAvailable: boolean;
generalSettingsDisabled: boolean;
managedBranchPrefix: string;
Expand Down Expand Up @@ -882,6 +884,8 @@ export function GeneralSettingsSection({
onSummarizeShellCommandsChange,
resumeThreadsAfterRestart,
onResumeThreadsAfterRestartChange,
markThreadsReadOnView,
onMarkThreadsReadOnViewChange,
desktopBrowserAvailable,
generalSettingsDisabled,
managedBranchPrefix,
Expand Down Expand Up @@ -1030,6 +1034,18 @@ export function GeneralSettingsSection({
/>
</SettingsWithControl>

<SettingsWithControl
label="Mark threads read when opened"
description="Mark a thread read when you open it or new replies arrive while you view it. Turn off to keep threads unread until you mark them read or reply."
>
<Switch
checked={markThreadsReadOnView}
disabled={generalSettingsDisabled}
onCheckedChange={onMarkThreadsReadOnViewChange}
aria-label="Mark threads read when opened"
/>
</SettingsWithControl>

<SettingsWithControl
label="Setup guide"
description="Walk through connecting an agent, adding projects, plugins, and devices again."
Expand Down Expand Up @@ -1480,6 +1496,12 @@ export function SettingsView() {
summarizeShellCommands: enabled,
})
}
markThreadsReadOnView={generalSettings.markThreadsReadOnView}
onMarkThreadsReadOnViewChange={(enabled) =>
updateGeneralSettingsMutation.mutate({
markThreadsReadOnView: enabled,
})
}
onReplaySetupGuide={() =>
updateGeneralSettingsMutation.mutate({
...generalSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ vi.mock("@/hooks/useRealtimeSubscription", () => ({
useThreadTimelineRealtimeSubscription: vi.fn(),
}));

vi.mock("@/hooks/queries/system-queries", async (importOriginal) => ({
...(await importOriginal<typeof import("@/hooks/queries/system-queries")>()),
useMarkThreadsReadOnView: () => true,
}));

vi.mock("@/hooks/useServerConnectionState", () => ({
useServerConnectionState: () => "connected",
}));
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/views/thread-detail/useThreadDetailThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useThreadDetailBootstrap,
} from "@/hooks/queries/thread-queries";
import { useMarkThreadRead } from "@/hooks/mutations/thread-state-mutations";
import { useMarkThreadsReadOnView } from "@/hooks/queries/system-queries";
import { useThreadReadTracking } from "@/hooks/useThreadReadTracking";
import { useThreadUnreadDividerState } from "./useThreadUnreadDividerState";

Expand Down Expand Up @@ -33,6 +34,7 @@ export function useThreadDetailThread(
thread,
});
useThreadReadTracking({
markOnView: useMarkThreadsReadOnView(),
markThreadRead: useMarkThreadRead(),
thread: trackRead && unreadDividerState.ready ? thread : undefined,
});
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/routes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export function registerSystemRoutes(
current.keepHistoryAfterContextClear,
summarizeShellCommands:
settings.summarizeShellCommands ?? current.summarizeShellCommands,
markThreadsReadOnView:
settings.markThreadsReadOnView ?? current.markThreadsReadOnView,
confirmThreadArchive:
settings.confirmThreadArchive ?? current.confirmThreadArchive,
confirmDesktopQuit:
Expand Down
1 change: 1 addition & 0 deletions apps/server/test/system/general-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ it.each([
"confirmThreadArchive",
"confirmDesktopQuit",
"summarizeShellCommands",
"markThreadsReadOnView",
] as const)(
"persists %s opt-out and preserves it for older clients",
async (key) => {
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ for the command surface.
| `confirmDesktopQuit` | `true` | Settings → General → Ask before quitting. `false` quits the desktop app without asking; see [Desktop quit confirmation](#desktop-quit-confirmation). |
| `keepHistoryAfterContextClear` | `false` | Settings → General → Show messages from before a context clear. When `false`, a thread's timeline, conversation outline, and message lookup start at its latest `Context cleared` boundary; `true` keeps earlier messages, which load on scroll and appear in the outline and `bb thread log --message`. Clearing always starts a fresh provider conversation and resets the context meter. |
| `summarizeShellCommands` | `true` | Settings → General → Summarize shell commands. `true` titles a shell command that runs `ls`, `find`, `grep`, `rg`, `cat`, `head`, `tail`, `nl`, or `sed -n` with a summary such as `Searched for X`, and the row does not expand. `false` titles every shell command row with its command (`Running …`, `Ran …`), expands it to the command and its output, and counts it as a command in step summaries. Native read and search tool rows keep their titles. |
| `markThreadsReadOnView` | `true` | Settings → General → Mark threads read when opened. `true` marks a thread read when you open it in the app, and again when new replies arrive while you view it. `false` keeps it unread until you mark it read (thread menu, the `thread.markRead` shortcut, `bb thread read`, or `sdk.threads.markRead`) or send it a message. While the settings are still loading, the app does not mark threads read. |
| `streamerMode` | `false` | Settings → General. Hides every `customModels` entry from the web and mobile pickers, `bb provider models`, and `sdk.providers.models`, for example before a screen share. Entries stay in `config.json`; a thread that names a hidden model still runs, and default model resolution keeps the full list, so a provider whose only models are custom still starts. A composer whose stored selection is hidden falls back to the provider default and records it on the next send; reselect the custom model after turning streamer mode off. |
| `allowFastServiceTier` | `true` | Settings → Providers. `false` hides the service tier control and runs every new turn at the default tier, including explicit requests for another tier (`fast`, Codex `ultrafast`, or any tier a provider lists), automations, and queued messages. Completed turns and project defaults saved while off keep the default tier. |
| `managedBranchPrefix` | `bb/` | Settings → General → New branch prefix. Prefix for branches bb creates for worktrees and new checkout branches (`bb/fix-login-flow-thr_ab12cd34ef`); empty for none. At most 64 characters and must start a valid git branch name (no space or leading `-`). Existing branches and worktrees keep their names. |
Expand All @@ -318,7 +319,7 @@ the terminal and pastes the primary selection independently of this setting.
Unsupported browsers never substitute unrelated regular clipboard contents.

Older clients that omit `keepHistoryAfterContextClear`,
`summarizeShellCommands`, or `earlyAdopter` preserve the saved value. The
`summarizeShellCommands`, `markThreadsReadOnView`, or `earlyAdopter` preserve the saved value. The
former Show Git changes and Commit button switch is now
[plugin settings](#git-and-github-pr-status-plugins), and the general-settings
API rejects an update that still sends `showGitChanges`. For older SDK callers, the
Expand Down
1 change: 1 addition & 0 deletions packages/db/test/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ describe("migrate", () => {
keepHistoryAfterContextClear: false,
summarizeShellCommands: true,
resumeThreadsAfterRestart: false,
markThreadsReadOnView: true,
providerOrder: [],
defaultProviderId: null,
providerCompletedTurnDisplay: {},
Expand Down
4 changes: 4 additions & 0 deletions packages/domain/src/app-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const appSettingsSchema = z
keepHistoryAfterContextClear: z.boolean(),
summarizeShellCommands: z.boolean(),
resumeThreadsAfterRestart: z.boolean(),
markThreadsReadOnView: z.boolean(),
providerOrder: z.array(z.string().min(1)),
defaultProviderId: z.string().min(1).nullable(),
providerCompletedTurnDisplay: z.record(
Expand Down Expand Up @@ -77,6 +78,7 @@ export const defaultAppSettings: AppSettings = {
keepHistoryAfterContextClear: false,
summarizeShellCommands: true,
resumeThreadsAfterRestart: false,
markThreadsReadOnView: true,
providerOrder: [],
defaultProviderId: null,
providerCompletedTurnDisplay: {},
Expand Down Expand Up @@ -121,6 +123,7 @@ export const appSettingsUpdateSchema = z.union([
keepHistoryAfterContextClear: z.boolean().optional(),
summarizeShellCommands: z.boolean().optional(),
resumeThreadsAfterRestart: z.boolean().optional(),
markThreadsReadOnView: z.boolean().optional(),
showUnhandledProviderEvents: z.boolean().optional(),
onboardingCompletedAt: z.string().min(1).nullable().optional(),
earlyAdopter: z.boolean().optional(),
Expand All @@ -136,6 +139,7 @@ export const appSettingsUpdateSchema = z.union([
keepHistoryAfterContextClear: z.boolean().optional(),
summarizeShellCommands: z.boolean().optional(),
resumeThreadsAfterRestart: z.boolean().optional(),
markThreadsReadOnView: z.boolean().optional(),
showUnhandledProviderEvents: z.boolean(),
onboardingCompletedAt: z.string().min(1).nullable().optional(),
earlyAdopter: z.boolean().optional(),
Expand Down
2 changes: 1 addition & 1 deletion packages/domain/src/plugin-sdk-version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const PLUGIN_SDK_VERSION = "0.6.205";
export const PLUGIN_SDK_VERSION = "0.6.206";

export const PLUGIN_SDK_MAJOR = Number(PLUGIN_SDK_VERSION.split(".", 1)[0]);
2 changes: 1 addition & 1 deletion packages/plugin-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@get-bb/plugin-sdk",
"version": "0.6.205",
"version": "0.6.206",
"license": "MIT",
"homepage": "https://github.com/get-bb/bb#readme",
"bugs": {
Expand Down
Loading