Skip to content

Commit 07d8ca7

Browse files
RoniEsteinclaude
andcommitted
merge: resolve conflicts with upstream main
Incorporate upstream's sidebarProjectGroupingMode and refactored test fixtures alongside copyButtonPosition field. Co-Authored-By: Claude Opus 4.6 <[email protected]>
2 parents 49aa904 + e0117b2 commit 07d8ca7

38 files changed

Lines changed: 3280 additions & 399 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/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"start": "node dist/bin.mjs",
2121
"prepare": "effect-language-service patch",
2222
"typecheck": "tsc --noEmit",
23-
"test": "vitest run"
23+
"test": "vitest run",
24+
"test:process-reaper": "vitest run src/server.test.ts src/provider/Layers/ClaudeAdapter.test.ts src/provider/Layers/ProviderSessionDirectory.test.ts src/provider/Layers/ProviderSessionReaper.test.ts src/provider/Layers/CodexAdapter.test.ts"
2425
},
2526
"dependencies": {
2627
"@anthropic-ai/claude-agent-sdk": "^0.2.111",

‎apps/server/src/codexAppServerManager.test.ts‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,154 @@ describe("startSession", () => {
470470
manager.stopAll();
471471
}
472472
});
473+
474+
it("disposes an existing session before starting a replacement for the same thread", async () => {
475+
const manager = new CodexAppServerManager();
476+
const existingContext = {
477+
session: {
478+
provider: "codex",
479+
status: "ready",
480+
threadId: asThreadId("thread-1"),
481+
runtimeMode: "full-access",
482+
createdAt: "2026-02-10T00:00:00.000Z",
483+
updatedAt: "2026-02-10T00:00:00.000Z",
484+
},
485+
};
486+
487+
(
488+
manager as unknown as {
489+
sessions: Map<ThreadId, typeof existingContext>;
490+
}
491+
).sessions.set(asThreadId("thread-1"), existingContext);
492+
493+
const disposeSession = vi
494+
.spyOn(
495+
manager as unknown as {
496+
disposeSession: (
497+
context: typeof existingContext,
498+
options?: { readonly emitLifecycleEvent?: boolean },
499+
) => void;
500+
},
501+
"disposeSession",
502+
)
503+
.mockImplementation(() => {});
504+
const assertSupportedCodexCliVersion = vi
505+
.spyOn(
506+
manager as unknown as {
507+
assertSupportedCodexCliVersion: (input: {
508+
binaryPath: string;
509+
cwd: string;
510+
homePath?: string;
511+
}) => void;
512+
},
513+
"assertSupportedCodexCliVersion",
514+
)
515+
.mockImplementation(() => {});
516+
const processCwd = vi.spyOn(process, "cwd").mockImplementation(() => {
517+
throw new Error("cwd missing");
518+
});
519+
520+
try {
521+
await expect(
522+
manager.startSession({
523+
threadId: asThreadId("thread-1"),
524+
provider: "codex",
525+
binaryPath: "codex",
526+
runtimeMode: "full-access",
527+
}),
528+
).rejects.toThrow("cwd missing");
529+
530+
expect(disposeSession).toHaveBeenCalledWith(existingContext, {
531+
emitLifecycleEvent: false,
532+
});
533+
expect(assertSupportedCodexCliVersion).not.toHaveBeenCalled();
534+
} finally {
535+
disposeSession.mockRestore();
536+
assertSupportedCodexCliVersion.mockRestore();
537+
processCwd.mockRestore();
538+
(
539+
manager as unknown as {
540+
sessions: Map<ThreadId, typeof existingContext>;
541+
}
542+
).sessions.clear();
543+
manager.stopAll();
544+
}
545+
});
546+
547+
it("continues replacement start when existing session disposal fails", async () => {
548+
const manager = new CodexAppServerManager();
549+
const existingContext = {
550+
session: {
551+
provider: "codex",
552+
status: "ready",
553+
threadId: asThreadId("thread-1"),
554+
runtimeMode: "full-access",
555+
createdAt: "2026-02-10T00:00:00.000Z",
556+
updatedAt: "2026-02-10T00:00:00.000Z",
557+
},
558+
};
559+
560+
(
561+
manager as unknown as {
562+
sessions: Map<ThreadId, typeof existingContext>;
563+
}
564+
).sessions.set(asThreadId("thread-1"), existingContext);
565+
566+
const disposeSession = vi
567+
.spyOn(
568+
manager as unknown as {
569+
disposeSession: (
570+
context: typeof existingContext,
571+
options?: { readonly emitLifecycleEvent?: boolean },
572+
) => void;
573+
},
574+
"disposeSession",
575+
)
576+
.mockImplementation(() => {
577+
throw new Error("dispose failed");
578+
});
579+
const assertSupportedCodexCliVersion = vi
580+
.spyOn(
581+
manager as unknown as {
582+
assertSupportedCodexCliVersion: (input: {
583+
binaryPath: string;
584+
cwd: string;
585+
homePath?: string;
586+
}) => void;
587+
},
588+
"assertSupportedCodexCliVersion",
589+
)
590+
.mockImplementation(() => {});
591+
const processCwd = vi.spyOn(process, "cwd").mockImplementation(() => {
592+
throw new Error("cwd missing");
593+
});
594+
595+
try {
596+
await expect(
597+
manager.startSession({
598+
threadId: asThreadId("thread-1"),
599+
provider: "codex",
600+
binaryPath: "codex",
601+
runtimeMode: "full-access",
602+
}),
603+
).rejects.toThrow("cwd missing");
604+
605+
expect(disposeSession).toHaveBeenCalledWith(existingContext, {
606+
emitLifecycleEvent: false,
607+
});
608+
expect(assertSupportedCodexCliVersion).not.toHaveBeenCalled();
609+
} finally {
610+
disposeSession.mockRestore();
611+
assertSupportedCodexCliVersion.mockRestore();
612+
processCwd.mockRestore();
613+
(
614+
manager as unknown as {
615+
sessions: Map<ThreadId, typeof existingContext>;
616+
}
617+
).sessions.clear();
618+
manager.stopAll();
619+
}
620+
});
473621
});
474622

475623
describe("sendTurn", () => {

‎apps/server/src/codexAppServerManager.ts‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,25 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
450450
let context: CodexSessionContext | undefined;
451451

452452
try {
453+
const existingContext = this.sessions.get(threadId);
454+
if (existingContext) {
455+
await Effect.logWarning("codex app-server replacing existing session", {
456+
threadId,
457+
existingStatus: existingContext.session.status,
458+
}).pipe(this.runPromise);
459+
try {
460+
this.disposeSession(existingContext, {
461+
emitLifecycleEvent: false,
462+
});
463+
} catch (error) {
464+
await Effect.logWarning("codex app-server failed to dispose existing session", {
465+
threadId,
466+
existingStatus: existingContext.session.status,
467+
cause: error instanceof Error ? error.message : String(error),
468+
}).pipe(this.runPromise);
469+
}
470+
}
471+
453472
const resolvedCwd = input.cwd ?? process.cwd();
454473

455474
const session: ProviderSession = {
@@ -901,6 +920,19 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
901920
return;
902921
}
903922

923+
this.disposeSession(context, {
924+
emitLifecycleEvent: true,
925+
});
926+
}
927+
928+
private disposeSession(
929+
context: CodexSessionContext,
930+
options?: { readonly emitLifecycleEvent?: boolean },
931+
): void {
932+
if (context.stopping) {
933+
return;
934+
}
935+
904936
context.stopping = true;
905937

906938
for (const pending of context.pending.values()) {
@@ -921,8 +953,10 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
921953
status: "closed",
922954
activeTurnId: undefined,
923955
});
924-
this.emitLifecycleEvent(context, "session/closed", "Session stopped");
925-
this.sessions.delete(threadId);
956+
if (options?.emitLifecycleEvent !== false) {
957+
this.emitLifecycleEvent(context, "session/closed", "Session stopped");
958+
}
959+
this.sessions.delete(context.session.threadId);
926960
}
927961

928962
listSessions(): ProviderSession[] {

‎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;

0 commit comments

Comments
 (0)