Skip to content
Merged
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
4 changes: 2 additions & 2 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { matchesInboxView } from "@t3tools/contracts";
import { effectiveInboxView, matchesInboxView } from "@t3tools/contracts";
import { SidebarInboxBar } from "./sidebar/SidebarInboxBar";
import { threadRoutingUpdateFromMenuAction } from "./threadActionMenu.logic";
import { attachSidebarTree } from "../lib/sidebarTree";
Expand Down Expand Up @@ -1103,7 +1103,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
);
const threads = useQuietThreadShells();
const promotingDraftThreadKeys = usePromotingDraftThreadKeys();
const inboxView = useClientSettings((settings) => settings.founderInboxView);
const inboxView = useClientSettings(effectiveInboxView);
const inboxThreads = threads.filter(
(thread) =>
threadSearchQuery.trim().length > 0 ||
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/ThreadNotificationCoordinator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { matchesInboxView } from "@t3tools/contracts";
import { effectiveInboxView, matchesInboxView } from "@t3tools/contracts";
import {
type EnvironmentThreadShell,
type PendingSubagentRequest,
Expand Down Expand Up @@ -116,7 +116,7 @@ export function startThreadNotifications(
const outsideInbox = new Set<string>();
for (const [environmentId, state] of watched) {
for (const [threadId, entry] of state.previous) {
if (!matchesInboxView(entry.thread.source.inbox, getClientSettings().founderInboxView))
if (!matchesInboxView(entry.thread.source.inbox, effectiveInboxView(getClientSettings())))
outsideInbox.add(threadKey({ environmentId, threadId }));
}
}
Expand All @@ -143,7 +143,7 @@ export function startThreadNotifications(
kind: ThreadNotificationKind,
) => {
const { thread, status } = state;
if (!matchesInboxView(thread.source.inbox, getClientSettings().founderInboxView)) return;
if (!matchesInboxView(thread.source.inbox, effectiveInboxView(getClientSettings()))) return;
if (
registry
.get(environmentThreadShells.hiddenThreadKeysAtom)
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/components/sidebar/SidebarInboxBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { InboxView } from "@t3tools/contracts";
import { effectiveInboxView, type InboxView } from "@t3tools/contracts";
import { updateClientSettings, useClientSettings } from "../../hooks/useSettings";

/** A local view of the shared pool; All and search always include every thread. */
export function SidebarInboxBar() {
const view = useClientSettings((settings) => settings.founderInboxView);
const view = useClientSettings(effectiveInboxView);
const owner = useClientSettings((settings) => settings.founderInboxOwner);
return (
<div className="flex flex-wrap items-center gap-2 px-2 pb-2 text-xs text-muted-foreground">
Expand Down Expand Up @@ -33,13 +33,18 @@ export function SidebarInboxBar() {
New threads{" "}
<select
aria-label="Owner for new threads"
value={owner}
value={owner ?? ""}
onChange={(event) =>
void updateClientSettings({
founderInboxOwner: event.target.value === "jeff" ? "jeff" : "kameron",
})
}
>
{owner === undefined ? (
<option value="" disabled>
Not set
</option>
) : null}
<option value="kameron">Kameron</option>
<option value="jeff">Jeff</option>
</select>
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/state/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export const olderSettledThreads = createOlderSettledThreadAtoms(
export const threadEnvironment = createThreadEnvironmentAtoms(
connectionAtomRuntime,
threadFamilies.snapshotAtom,
{ getInboxOrigin: () => ({ kind: "human", id: getClientSettings().founderInboxOwner }) },
{
getInboxOrigin: () => ({
kind: "human",
id: getClientSettings().founderInboxOwner ?? "kameron",
}),
},
);
const environmentThreads = createEnvironmentThreadStateAtoms(connectionAtomRuntime);
export const environmentThreadDetails = createEnvironmentThreadDetailAtoms(
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ export const VoiceTranscriptionDestination = Schema.Union([
export type VoiceTranscriptionDestination = typeof VoiceTranscriptionDestination.Type;

export const ClientSettingsSchema = Schema.Struct({
founderInboxOwner: Founder.pipe(Schema.withDecodingDefault(Effect.succeed("kameron" as const))),
// Upgraded devices have no saved view; a founder view would hide all unclassified history.
founderInboxView: InboxView.pipe(Schema.withDecodingDefault(Effect.succeed("all" as const))),
// Absent until chosen; whole-snapshot saves must not record a default as a choice.
founderInboxOwner: Schema.optionalKey(Founder),
founderInboxView: Schema.optionalKey(InboxView),
notificationMode: NotificationMode.pipe(
Schema.withDecodingDefault(Effect.succeed("off" as const)),
),
Expand Down
30 changes: 18 additions & 12 deletions packages/contracts/src/threadInbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
makeThreadInbox,
routeThreadInbox,
matchesInboxView,
effectiveInboxView,
founderInboxLane,
compositeThreadKey,
} from "./threadInbox.ts";
Expand All @@ -27,21 +28,26 @@ describe("shared fleet organizational inbox", () => {
expect(matchesInboxView(j, "all")).toBe(true);
expect(matchesInboxView(k, "all")).toBe(true);
});
it("shows unclassified history on upgraded devices and persists the picked view", () => {
it("keeps All until a founder is chosen, then defaults to that founder's view", () => {
const decode = Schema.decodeUnknownSync(ClientSettingsSchema);
const encode = Schema.encodeSync(ClientSettingsSchema);
const upgraded = decode({ notificationMode: "off" });
expect(upgraded.founderInboxView).toBe("all");
expect(upgraded.founderInboxOwner).toBe("kameron");
for (const unclassified of [undefined, null]) {
expect(matchesInboxView(unclassified, upgraded.founderInboxView)).toBe(true);
expect(matchesInboxView(unclassified, "jeff")).toBe(false);
}
for (const view of ["jeff", "kameron", "shared", "agents", "all"] as const) {
const saved = decode(
encode({ ...upgraded, founderInboxView: view, founderInboxOwner: "jeff" }),
);
expect([saved.founderInboxView, saved.founderInboxOwner]).toEqual([view, "jeff"]);
// Any later settings write saves the whole snapshot; it must not record an unmade choice.
const resaved = encode(decode(encode(upgraded)));
expect(["founderInboxView", "founderInboxOwner"].filter((key) => key in resaved)).toEqual([]);
expect(effectiveInboxView(upgraded)).toBe("all");
expect(matchesInboxView(undefined, effectiveInboxView(upgraded))).toBe(true);
const jeffClient = decode(encode({ ...upgraded, founderInboxOwner: "jeff" }));
const view = effectiveInboxView(jeffClient);
expect(view).toBe("jeff");
expect(matchesInboxView(makeThreadInbox({ actor: jeff }), view)).toBe(true);
expect(matchesInboxView(makeThreadInbox({ actor: kameron }), view)).toBe(false);
expect(matchesInboxView(makeThreadInbox({ actor: bot }), view)).toBe(false);
expect(matchesInboxView(makeThreadInbox({ actor: bot }), "agents")).toBe(true);
expect(matchesInboxView(undefined, "all")).toBe(true);
for (const picked of ["jeff", "kameron", "shared", "agents", "all"] as const) {
const saved = decode(encode({ ...jeffClient, founderInboxView: picked }));
expect([effectiveInboxView(saved), saved.founderInboxOwner]).toEqual([picked, "jeff"]);
}
});
it("hides bot-only work by default while All and Agents retain it", () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts/src/threadInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export function founderInboxLane(inbox: ThreadInbox | null | undefined, founder:
return inbox.attentionKind;
}

/** The chosen view, else the chosen founder's, else All so unclassified history stays visible. */
export const effectiveInboxView = (settings: {
readonly founderInboxView?: InboxView | undefined;
readonly founderInboxOwner?: Founder | undefined;
}): InboxView => settings.founderInboxView ?? settings.founderInboxOwner ?? "all";

/** All deliberately includes every thread, including unclassified history. */
export function matchesInboxView(inbox: ThreadInbox | null | undefined, view: InboxView) {
if (view === "all") return true;
Expand Down
Loading