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
47 changes: 30 additions & 17 deletions apps/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,9 @@ app.whenReady().then(async () => {
const setActiveProject = (projectRoot: string | null): void => {
activeProjectRoot = projectRoot ? normalizeProjectRoot(projectRoot) : null;
for (const [root, ctx] of projectContexts) {
ctx.syncService?.setHostDiscoveryEnabled?.(activeProjectRoot != null && root === activeProjectRoot);
const isActive = activeProjectRoot != null && root === activeProjectRoot;
ctx.syncService?.setHostStartupEnabled?.(isActive);
ctx.syncService?.setHostDiscoveryEnabled?.(isActive);
}
if (activeProjectRoot) {
projectLastActivatedAt.set(activeProjectRoot, Date.now());
Expand Down Expand Up @@ -2650,6 +2652,14 @@ app.whenReady().then(async () => {
emitProjectEvent(projectRoot, IPC.orchestratorDagMutation, event),
});
aiOrchestratorServiceRef = aiOrchestratorService;
// Only the project that matches the currently-active root should auto-start
// its sync host; background project contexts stay dormant until activated.
// ADE_DISABLE_SYNC_HOST=1 is a global kill switch for tests / CI.
const isActiveProjectContext =
activeProjectRoot != null
&& normalizeProjectRoot(projectRoot) === activeProjectRoot;
const syncHostAutoStart =
process.env.ADE_DISABLE_SYNC_HOST !== "1" && isActiveProjectContext;
const syncService = createSyncService({
db,
logger,
Expand Down Expand Up @@ -2685,18 +2695,26 @@ app.whenReady().then(async () => {
getLinearIssueTracker: () => linearIssueTracker,
getLinearSyncService: () => linearSyncServiceRef,
processService,
hostStartupEnabled: process.env.ADE_DISABLE_SYNC_HOST !== "1",
hostDiscoveryEnabled: activeProjectRoot != null && normalizeProjectRoot(projectRoot) === activeProjectRoot,
hostStartupEnabled: syncHostAutoStart,
phonePairingStateDir: path.join(app.getPath("userData"), "phone-sync"),
hostDiscoveryEnabled: isActiveProjectContext,
notificationEventBus,
projectCatalogProvider: {
listProjects: listMobileSyncProjects,
prepareProjectConnection: prepareMobileSyncProjectConnection,
},
onStatusChanged: (snapshot) =>
emitProjectEvent(projectRoot, IPC.syncEvent, {
onStatusChanged: (snapshot) => {
if (
activeProjectRoot == null
|| normalizeProjectRoot(projectRoot) !== activeProjectRoot
) {
return;
}
broadcast(IPC.syncEvent, {
type: "sync-status",
snapshot,
}),
});
},
});
syncServiceRef = syncService;
// Late-bind the sync service into the notification bus dependencies so
Expand Down Expand Up @@ -4009,15 +4027,12 @@ app.whenReady().then(async () => {
let createdLeaseExpiresAt: number | null = null;
let createdLeaseTimer: ReturnType<typeof setTimeout> | null = null;
try {
await switchProjectFromDialog(targetRoot);
const ctx = await ensureProjectContextForMobileSync(targetRoot);
if (!ctx.syncService) {
throw new Error("Sync is not available for that project.");
}
await ctx.syncService.initialize();
const status = await ctx.syncService.getStatus();
if (!status.bootstrapToken || !status.pairingConnectInfo) {
throw new Error("That project is not ready for phone sync yet.");
}
const recent = (readGlobalState(globalStatePath).recentProjects ?? [])
.map(toRecentProjectSummary)
.find((entry) => normalizeProjectRoot(entry.rootPath) === targetRoot) ?? null;
Expand All @@ -4042,13 +4057,7 @@ app.whenReady().then(async () => {
return {
ok: true,
project,
connection: {
authKind: "bootstrap",
token: status.bootstrapToken,
hostIdentity: status.pairingConnectInfo.hostIdentity,
port: status.pairingConnectInfo.port,
addressCandidates: status.pairingConnectInfo.addressCandidates,
},
connection: null,
};
} catch (error) {
const currentLeaseTimer = mobileSyncHandoffLeaseTimers.get(targetRoot);
Expand Down Expand Up @@ -4483,6 +4492,10 @@ app.whenReady().then(async () => {
}
return ctx;
},
getSyncService: () => {
if (!activeProjectRoot) return null;
return projectContexts.get(activeProjectRoot)?.syncService ?? null;
},
switchProjectFromDialog,
closeCurrentProject,
closeProjectByPath,
Expand Down
22 changes: 11 additions & 11 deletions apps/desktop/src/main/services/chat/agentChatService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5192,8 +5192,8 @@ describe("createAgentChatService", () => {
| { mode?: unknown; settings?: { model?: unknown; reasoning_effort?: unknown; developer_instructions?: unknown } }
| undefined;

expect(params?.approvalPolicy).toBeUndefined();
expect(params?.sandboxPolicy).toBeUndefined();
expect(params?.approvalPolicy).toBe("untrusted");
expect(params?.sandboxPolicy?.type).toBe("readOnly");
expect(params?.effort).toBe("medium");
expect(collaborationMode?.mode).toBe("plan");
expect(collaborationMode?.settings?.model).toBe("gpt-5.4");
Expand Down Expand Up @@ -5245,8 +5245,8 @@ describe("createAgentChatService", () => {
} | undefined;
const collaborationMode = params?.collaborationMode as { mode?: unknown } | undefined;

expect(params?.approvalPolicy).toBeUndefined();
expect(params?.sandboxPolicy).toBeUndefined();
expect(params?.approvalPolicy).toBe("on-request");
expect(params?.sandboxPolicy?.type).toBe("workspaceWrite");
expect(params?.effort).toBe("medium");
expect(collaborationMode?.mode).toBe("default");
});
Expand Down Expand Up @@ -5318,12 +5318,12 @@ describe("createAgentChatService", () => {
sandboxPolicy?: { type?: unknown };
effort?: unknown;
} | undefined;
expect(turnStartParams?.approvalPolicy).toBeUndefined();
expect(turnStartParams?.sandboxPolicy).toBeUndefined();
expect(turnStartParams?.approvalPolicy).toBe("never");
expect(turnStartParams?.sandboxPolicy?.type).toBe("dangerFullAccess");
expect(turnStartParams?.effort).toBe("medium");
});

it("uses the app-server's effective Codex policy after thread/start without re-overriding it on turn/start", async () => {
it("uses the app-server's effective Codex policy for subsequent turn/start overrides", async () => {
mockState.codexResponseOverrides.set("thread/start", () => ({
thread: { id: "thread-effective-start" },
approvalPolicy: "on-failure",
Expand Down Expand Up @@ -5360,8 +5360,8 @@ describe("createAgentChatService", () => {
sandboxPolicy?: { type?: unknown };
effort?: unknown;
} | undefined;
expect(turnStartParams?.approvalPolicy).toBeUndefined();
expect(turnStartParams?.sandboxPolicy).toBeUndefined();
expect(turnStartParams?.approvalPolicy).toBe("on-failure");
expect(turnStartParams?.sandboxPolicy?.type).toBe("workspaceWrite");
expect(turnStartParams?.effort).toBe("high");

const summary = await service.getSessionSummary(session.id);
Expand Down Expand Up @@ -5452,8 +5452,8 @@ describe("createAgentChatService", () => {
collaborationMode?: { mode?: unknown };
effort?: unknown;
} | undefined;
expect(turnStartParams?.approvalPolicy).toBeUndefined();
expect(turnStartParams?.sandboxPolicy).toBeUndefined();
expect(turnStartParams?.approvalPolicy).toBe("never");
expect(turnStartParams?.sandboxPolicy?.type).toBe("dangerFullAccess");
expect(turnStartParams?.collaborationMode?.mode).toBe("default");
expect(turnStartParams?.effort).toBe("medium");
});
Expand Down
Loading
Loading