Skip to content

Commit 188a40c

Browse files
tlh38juliusmarmingecodex
authored
feat: configurable project grouping (pingdotgg#2055)
Co-authored-by: tlh38 <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
1 parent 7a08fcf commit 188a40c

21 files changed

Lines changed: 1592 additions & 345 deletions

‎apps/desktop/src/clientPersistence.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const clientSettings: ClientSettings = {
5252
confirmThreadArchive: true,
5353
confirmThreadDelete: false,
5454
diffWordWrap: true,
55+
sidebarProjectGroupingMode: "repository_path",
56+
sidebarProjectGroupingOverrides: {
57+
"environment-1:/tmp/project-a": "separate",
58+
},
5559
sidebarProjectSortOrder: "manual",
5660
sidebarThreadSortOrder: "created_at",
5761
timestampFormat: "24-hour",

‎apps/desktop/src/main.ts‎

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,35 @@ const TITLEBAR_COLOR = "#01000000"; // #00000000 does not work correctly on Linu
160160
const TITLEBAR_LIGHT_SYMBOL_COLOR = "#1f2937";
161161
const TITLEBAR_DARK_SYMBOL_COLOR = "#f8fafc";
162162

163+
function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextMenuItem[] {
164+
const normalizedItems: ContextMenuItem[] = [];
165+
166+
for (const sourceItem of source) {
167+
if (typeof sourceItem.id !== "string" || typeof sourceItem.label !== "string") {
168+
continue;
169+
}
170+
171+
const normalizedItem: ContextMenuItem = {
172+
id: sourceItem.id,
173+
label: sourceItem.label,
174+
destructive: sourceItem.destructive === true,
175+
disabled: sourceItem.disabled === true,
176+
};
177+
178+
if (sourceItem.children) {
179+
const normalizedChildren = normalizeContextMenuItems(sourceItem.children);
180+
if (normalizedChildren.length === 0) {
181+
continue;
182+
}
183+
normalizedItem.children = normalizedChildren;
184+
}
185+
186+
normalizedItems.push(normalizedItem);
187+
}
188+
189+
return normalizedItems;
190+
}
191+
163192
type WindowTitleBarOptions = Pick<
164193
BrowserWindowConstructorOptions,
165194
"titleBarOverlay" | "titleBarStyle" | "trafficLightPosition"
@@ -1715,14 +1744,7 @@ function registerIpcHandlers(): void {
17151744
ipcMain.handle(
17161745
CONTEXT_MENU_CHANNEL,
17171746
async (_event, items: ContextMenuItem[], position?: { x: number; y: number }) => {
1718-
const normalizedItems = items
1719-
.filter((item) => typeof item.id === "string" && typeof item.label === "string")
1720-
.map((item) => ({
1721-
id: item.id,
1722-
label: item.label,
1723-
destructive: item.destructive === true,
1724-
disabled: item.disabled === true,
1725-
}));
1747+
const normalizedItems = normalizeContextMenuItems(items);
17261748
if (normalizedItems.length === 0) {
17271749
return null;
17281750
}
@@ -1743,28 +1765,37 @@ function registerIpcHandlers(): void {
17431765
if (!window) return null;
17441766

17451767
return new Promise<string | null>((resolve) => {
1746-
const template: MenuItemConstructorOptions[] = [];
1747-
let hasInsertedDestructiveSeparator = false;
1748-
for (const item of normalizedItems) {
1749-
if (item.destructive && !hasInsertedDestructiveSeparator && template.length > 0) {
1750-
template.push({ type: "separator" });
1751-
hasInsertedDestructiveSeparator = true;
1752-
}
1753-
const itemOption: MenuItemConstructorOptions = {
1754-
label: item.label,
1755-
enabled: !item.disabled,
1756-
click: () => resolve(item.id),
1757-
};
1758-
if (item.destructive) {
1759-
const destructiveIcon = getDestructiveMenuIcon();
1760-
if (destructiveIcon) {
1761-
itemOption.icon = destructiveIcon;
1768+
const buildTemplate = (
1769+
entries: readonly ContextMenuItem[],
1770+
): MenuItemConstructorOptions[] => {
1771+
const template: MenuItemConstructorOptions[] = [];
1772+
let hasInsertedDestructiveSeparator = false;
1773+
for (const item of entries) {
1774+
if (item.destructive && !hasInsertedDestructiveSeparator && template.length > 0) {
1775+
template.push({ type: "separator" });
1776+
hasInsertedDestructiveSeparator = true;
1777+
}
1778+
const itemOption: MenuItemConstructorOptions = {
1779+
label: item.label,
1780+
enabled: !item.disabled,
1781+
};
1782+
if (item.children && item.children.length > 0) {
1783+
itemOption.submenu = buildTemplate(item.children);
1784+
} else {
1785+
itemOption.click = () => resolve(item.id);
17621786
}
1787+
if (item.destructive && (!item.children || item.children.length === 0)) {
1788+
const destructiveIcon = getDestructiveMenuIcon();
1789+
if (destructiveIcon) {
1790+
itemOption.icon = destructiveIcon;
1791+
}
1792+
}
1793+
template.push(itemOption);
17631794
}
1764-
template.push(itemOption);
1765-
}
1795+
return template;
1796+
};
17661797

1767-
const menu = Menu.buildFromTemplate(template);
1798+
const menu = Menu.buildFromTemplate(buildTemplate(normalizedItems));
17681799
menu.popup({
17691800
window,
17701801
...popupPosition,

‎apps/server/src/project/Layers/RepositoryIdentityResolver.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { realpathSync } from "node:fs";
2+
13
import * as NodeServices from "@effect/platform-node/NodeServices";
24
import { expect, it } from "@effect/vitest";
35
import { Duration, Effect, FileSystem, Layer } from "effect";
@@ -10,6 +12,10 @@ import {
1012
RepositoryIdentityResolverLive,
1113
} from "./RepositoryIdentityResolver.ts";
1214

15+
const normalizePathSeparators = (value: string) => value.replaceAll("\\", "/");
16+
const normalizeResolvedPath = (value: string) =>
17+
normalizePathSeparators(realpathSync.native(value));
18+
1319
const git = (cwd: string, args: ReadonlyArray<string>) =>
1420
Effect.promise(() => runProcess("git", ["-C", cwd, ...args]));
1521

@@ -41,13 +47,35 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
4147

4248
expect(identity).not.toBeNull();
4349
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
50+
expect(normalizeResolvedPath(identity?.rootPath ?? "")).toBe(normalizeResolvedPath(cwd));
4451
expect(identity?.displayName).toBe("t3tools/t3code");
4552
expect(identity?.provider).toBe("github");
4653
expect(identity?.owner).toBe("t3tools");
4754
expect(identity?.name).toBe("t3code");
4855
}).pipe(Effect.provide(RepositoryIdentityResolverLive)),
4956
);
5057

58+
it.effect("returns the git top-level root path when resolving from a nested workspace", () =>
59+
Effect.gen(function* () {
60+
const fileSystem = yield* FileSystem.FileSystem;
61+
const repoRoot = yield* fileSystem.makeTempDirectoryScoped({
62+
prefix: "t3-repository-identity-nested-root-test-",
63+
});
64+
const nestedWorkspace = `${repoRoot}/packages/web`;
65+
66+
yield* fileSystem.makeDirectory(nestedWorkspace, { recursive: true });
67+
yield* git(repoRoot, ["init"]);
68+
yield* git(repoRoot, ["remote", "add", "origin", "[email protected]:T3Tools/t3code.git"]);
69+
70+
const resolver = yield* RepositoryIdentityResolver;
71+
const identity = yield* resolver.resolve(nestedWorkspace);
72+
73+
expect(identity).not.toBeNull();
74+
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
75+
expect(normalizeResolvedPath(identity?.rootPath ?? "")).toBe(normalizeResolvedPath(repoRoot));
76+
}).pipe(Effect.provide(RepositoryIdentityResolverLive)),
77+
);
78+
5179
it.effect("returns null for non-git folders and repos without remotes", () =>
5280
Effect.gen(function* () {
5381
const fileSystem = yield* FileSystem.FileSystem;

‎apps/server/src/project/Layers/RepositoryIdentityResolver.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function pickPrimaryRemote(
4242
function buildRepositoryIdentity(input: {
4343
readonly remoteName: string;
4444
readonly remoteUrl: string;
45+
readonly rootPath: string;
4546
}): RepositoryIdentity {
4647
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
4748
const hostingProvider = detectGitHostingProviderFromRemoteUrl(input.remoteUrl);
@@ -57,6 +58,7 @@ function buildRepositoryIdentity(input: {
5758
remoteName: input.remoteName,
5859
remoteUrl: input.remoteUrl,
5960
},
61+
rootPath: input.rootPath,
6062
...(repositoryPath ? { displayName: repositoryPath } : {}),
6163
...(hostingProvider ? { provider: hostingProvider.kind } : {}),
6264
...(owner ? { owner } : {}),
@@ -108,7 +110,7 @@ async function resolveRepositoryIdentityFromCacheKey(
108110
}
109111

110112
const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.stdout));
111-
return remote ? buildRepositoryIdentity(remote) : null;
113+
return remote ? buildRepositoryIdentity({ ...remote, rootPath: cacheKey }) : null;
112114
} catch {
113115
return null;
114116
}

‎apps/server/src/provider/Layers/ClaudeAdapter.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ describe("ClaudeAdapterLive", () => {
351351
);
352352
});
353353

354-
it.effect("defaults Claude Opus 4.7 sessions to xhigh effort", () => {
354+
it.effect("maps the Claude Opus 4.7 default effort to the SDK-supported max value", () => {
355355
const harness = makeHarness();
356356
return Effect.gen(function* () {
357357
const adapter = yield* ClaudeAdapter;
@@ -366,14 +366,14 @@ describe("ClaudeAdapterLive", () => {
366366
});
367367

368368
const createInput = harness.getLastCreateQueryInput();
369-
assert.equal(createInput?.options.effort, "xhigh");
369+
assert.equal(createInput?.options.effort, "max");
370370
}).pipe(
371371
Effect.provideService(Random.Random, makeDeterministicRandomService()),
372372
Effect.provide(harness.layer),
373373
);
374374
});
375375

376-
it.effect("forwards xhigh effort for Claude Opus 4.7", () => {
376+
it.effect("maps xhigh effort for Claude Opus 4.7 to the SDK-supported max value", () => {
377377
const harness = makeHarness();
378378
return Effect.gen(function* () {
379379
const adapter = yield* ClaudeAdapter;
@@ -391,7 +391,7 @@ describe("ClaudeAdapterLive", () => {
391391
});
392392

393393
const createInput = harness.getLastCreateQueryInput();
394-
assert.equal(createInput?.options.effort, "xhigh");
394+
assert.equal(createInput?.options.effort, "max");
395395
}).pipe(
396396
Effect.provideService(Random.Random, makeDeterministicRandomService()),
397397
Effect.provide(harness.layer),

‎apps/server/src/provider/Layers/ClaudeAdapter.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type ClaudeToolResultStreamKind = Extract<
8484
RuntimeContentStreamKind,
8585
"command_output" | "file_change_output"
8686
>;
87+
type ClaudeSdkEffort = NonNullable<ClaudeQueryOptions["effort"]>;
8788

8889
type PromptQueueItem =
8990
| {
@@ -217,11 +218,17 @@ function normalizeClaudeStreamMessages(cause: Cause.Cause<Error>): ReadonlyArray
217218

218219
function getEffectiveClaudeAgentEffort(
219220
effort: ClaudeAgentEffort | null | undefined,
220-
): Exclude<ClaudeAgentEffort, "ultrathink"> | null {
221+
): ClaudeSdkEffort | null {
221222
if (!effort) {
222223
return null;
223224
}
224-
return effort === "ultrathink" ? null : effort;
225+
if (effort === "ultrathink") {
226+
return null;
227+
}
228+
if (effort === "xhigh") {
229+
return "max";
230+
}
231+
return effort;
225232
}
226233

227234
function isClaudeInterruptedMessage(message: string): boolean {

‎apps/web/src/components/ChatView.browser.tsx‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import {
1717
OrchestrationSessionStatus,
1818
DEFAULT_SERVER_SETTINGS,
1919
} from "@t3tools/contracts";
20-
import {
21-
scopedProjectKey,
22-
scopedThreadKey,
23-
scopeProjectRef,
24-
scopeThreadRef,
25-
} from "@t3tools/client-runtime";
20+
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime";
2621
import { RouterProvider, createMemoryHistory } from "@tanstack/react-router";
2722
import { HttpResponse, http, ws } from "msw";
2823
import { setupWorker } from "msw/browser";
@@ -52,6 +47,7 @@ import { __resetLocalApiForTests } from "../localApi";
5247
import { AppAtomRegistryProvider } from "../rpc/atomRegistry";
5348
import { getServerConfig } from "../rpc/serverState";
5449
import { getRouter } from "../router";
50+
import { deriveLogicalProjectKeyFromSettings } from "../logicalProject";
5551
import { selectBootstrapCompleteForActiveEnvironment, useStore } from "../store";
5652
import { useTerminalStateStore } from "../terminalStateStore";
5753
import { useUiStateStore } from "../uiStateStore";
@@ -78,7 +74,18 @@ const THREAD_REF = scopeThreadRef(LOCAL_ENVIRONMENT_ID, THREAD_ID);
7874
const THREAD_KEY = scopedThreadKey(THREAD_REF);
7975
const UUID_ROUTE_RE = /^\/draft\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
8076
const PROJECT_DRAFT_KEY = `${LOCAL_ENVIRONMENT_ID}:${PROJECT_ID}`;
81-
const PROJECT_KEY = scopedProjectKey(scopeProjectRef(LOCAL_ENVIRONMENT_ID, PROJECT_ID));
77+
const PROJECT_LOGICAL_KEY = deriveLogicalProjectKeyFromSettings(
78+
{
79+
environmentId: LOCAL_ENVIRONMENT_ID,
80+
id: PROJECT_ID,
81+
cwd: "/repo/project",
82+
repositoryIdentity: null,
83+
},
84+
{
85+
sidebarProjectGroupingMode: DEFAULT_CLIENT_SETTINGS.sidebarProjectGroupingMode,
86+
sidebarProjectGroupingOverrides: DEFAULT_CLIENT_SETTINGS.sidebarProjectGroupingOverrides,
87+
},
88+
);
8289
const NOW_ISO = "2026-03-04T12:00:00.000Z";
8390
const BASE_TIME_MS = Date.parse(NOW_ISO);
8491
const ATTACHMENT_SVG = "<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'></svg>";
@@ -1638,12 +1645,12 @@ describe("ChatView timeline estimator parity (full app)", () => {
16381645
customWsRpcResolver = null;
16391646
document.body.innerHTML = "";
16401647
});
1641-
it("re-expands the bootstrap project using its scoped key", async () => {
1648+
it("re-expands the bootstrap project using its logical key", async () => {
16421649
useUiStateStore.setState({
16431650
projectExpandedById: {
1644-
[PROJECT_KEY]: false,
1651+
[PROJECT_LOGICAL_KEY]: false,
16451652
},
1646-
projectOrder: [PROJECT_KEY],
1653+
projectOrder: [PROJECT_LOGICAL_KEY],
16471654
threadLastVisitedAtById: {},
16481655
});
16491656

@@ -1658,7 +1665,7 @@ describe("ChatView timeline estimator parity (full app)", () => {
16581665
try {
16591666
await vi.waitFor(
16601667
() => {
1661-
expect(useUiStateStore.getState().projectExpandedById[PROJECT_KEY]).toBe(true);
1668+
expect(useUiStateStore.getState().projectExpandedById[PROJECT_LOGICAL_KEY]).toBe(true);
16621669
},
16631670
{ timeout: 8_000, interval: 16 },
16641671
);

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ import { getProviderModelCapabilities, resolveSelectableProvider } from "../prov
113113
import { useSettings } from "../hooks/useSettings";
114114
import { resolveAppModelSelection } from "../modelSelection";
115115
import { isTerminalFocused } from "../lib/terminalFocus";
116-
import { deriveLogicalProjectKey } from "../logicalProject";
116+
import { deriveLogicalProjectKeyFromSettings } from "../logicalProject";
117117
import {
118118
useSavedEnvironmentRegistryStore,
119119
useSavedEnvironmentRuntimeStore,
@@ -847,10 +847,16 @@ export default function ChatView(props: ChatViewProps) {
847847
const primaryEnvironmentId = usePrimaryEnvironmentId();
848848
const savedEnvironmentRegistry = useSavedEnvironmentRegistryStore((s) => s.byId);
849849
const savedEnvironmentRuntimeById = useSavedEnvironmentRuntimeStore((s) => s.byId);
850+
const projectGroupingSettings = useSettings((settings) => ({
851+
sidebarProjectGroupingMode: settings.sidebarProjectGroupingMode,
852+
sidebarProjectGroupingOverrides: settings.sidebarProjectGroupingOverrides,
853+
}));
850854
const logicalProjectEnvironments = useMemo(() => {
851855
if (!activeProject) return [];
852-
const logicalKey = deriveLogicalProjectKey(activeProject);
853-
const memberProjects = allProjects.filter((p) => deriveLogicalProjectKey(p) === logicalKey);
856+
const logicalKey = deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings);
857+
const memberProjects = allProjects.filter(
858+
(p) => deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings) === logicalKey,
859+
);
854860
const seen = new Set<string>();
855861
const envs: Array<{
856862
environmentId: EnvironmentId;
@@ -886,6 +892,7 @@ export default function ChatView(props: ChatViewProps) {
886892
}, [
887893
activeProject,
888894
allProjects,
895+
projectGroupingSettings,
889896
primaryEnvironmentId,
890897
savedEnvironmentRegistry,
891898
savedEnvironmentRuntimeById,
@@ -915,7 +922,10 @@ export default function ChatView(props: ChatViewProps) {
915922
throw new Error("No active project is available for this pull request.");
916923
}
917924
const activeProjectRef = scopeProjectRef(activeProject.environmentId, activeProject.id);
918-
const logicalProjectKey = deriveLogicalProjectKey(activeProject);
925+
const logicalProjectKey = deriveLogicalProjectKeyFromSettings(
926+
activeProject,
927+
projectGroupingSettings,
928+
);
919929
const storedDraftSession = getDraftSessionByLogicalProjectKey(logicalProjectKey);
920930
if (storedDraftSession) {
921931
setDraftThreadContext(storedDraftSession.draftId, input);
@@ -976,6 +986,7 @@ export default function ChatView(props: ChatViewProps) {
976986
getDraftSessionByLogicalProjectKey,
977987
isServerThread,
978988
navigate,
989+
projectGroupingSettings,
979990
routeKind,
980991
setDraftThreadContext,
981992
setLogicalProjectDraftThreadId,

0 commit comments

Comments
 (0)