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
2 changes: 2 additions & 0 deletions src/main/app-controls/mcp/tools/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const PROTECTED_SETTINGS_KEYS: ReadonlySet<string> = new Set([
"agentInstances",
"acpRegistryInstalledAgents",
"agentHookSupport",
"crossagentSelectionUsage",
"crossagentRoutingOverrides",
"mcpServers",
]);

Expand Down
10 changes: 10 additions & 0 deletions src/main/ipc/localHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
} from "@/shared/ipc";
import { supportsNativeWindowMaterial, syncNativeThemeForMaterial } from "../window/windowMaterial";
import type { SharedSettings } from "@/shared/settings";
import { removeCrossagentRoutingOverride } from "@/shared/crossagentRanking";
import { headersToRecord, readBoundedResponseBody } from "@/shared/http";
import type { PoracodePaths } from "@/shared/poracodePaths";
import { UsageLoginManager } from "../usageLogin/UsageLoginManager";
Expand Down Expand Up @@ -350,6 +351,15 @@ export function createLocalIpcHandlers(
options.updatePowerSaveBlocker();
options.onSharedSettingsChanged?.(merged);
},
removeCrossagentRoutingOverride: ({ tags }) => {
const settingsPath = options.requirePoracodePaths().settingsPath;
const current = readSharedSettingsFile(settingsPath);
const overrides = removeCrossagentRoutingOverride(current.crossagentRoutingOverrides, tags);
const settings = { ...current, crossagentRoutingOverrides: overrides };
writeSharedSettingsFile(settingsPath, settings);
options.onSharedSettingsChanged?.(settings);
return overrides;
},
setClaudeProfileEnvironment: (payload) => {
const settingsPath = options.requirePoracodePaths().settingsPath;
const { settings, instance } = applyClaudeProfileEnvironment(
Expand Down
67 changes: 67 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ import { readKeybindingsFile } from "./keybindingsFile";
import { QuickComposerShortcutManager } from "./quickComposerShortcut";
import { shouldStartMinimized, syncWindowsStartupRegistration } from "./startupSettings";
import { type PoracodePaths, resolvePoracodeBaseDir } from "@/shared/poracodePaths";
import {
incrementCrossagentSelectionUsage,
removeCrossagentRoutingOverride,
upsertCrossagentRoutingOverride,
} from "@/shared/crossagentRanking";
import { getAppName } from "@/shared/appName";
import { productNameFor, resolvePoracodeChannel } from "@/shared/channel";
import {
Expand Down Expand Up @@ -314,6 +319,40 @@ function handleSharedSettingsChanged(settings: SharedSettings): void {
syncStartupSettings(settings);
}

function recordCrossagentSelectionPreference(
event: Extract<SupervisorEvent, { type: "crossagent-selection-used" }>,
): void {
const settingsPath = requirePoracodePaths().settingsPath;
const current = readSharedSettingsFile(settingsPath);
const next = {
...current,
crossagentSelectionUsage: incrementCrossagentSelectionUsage(
current.crossagentSelectionUsage,
event.selections,
),
};
writeSharedSettingsFile(settingsPath, next);
handleSharedSettingsChanged(next);
mainWindow?.webContents.send(IPC_EVENT_CHANNELS.sharedSettingsChanged, next);
}

function updateCrossagentRoutingOverride(
event: Extract<SupervisorEvent, { type: "crossagent-routing-override-changed" }>,
): void {
const settingsPath = requirePoracodePaths().settingsPath;
const current = readSharedSettingsFile(settingsPath);
const next = {
...current,
crossagentRoutingOverrides:
event.change.action === "set"
? upsertCrossagentRoutingOverride(current.crossagentRoutingOverrides, event.change.override)
: removeCrossagentRoutingOverride(current.crossagentRoutingOverrides, event.change.tags),
};
writeSharedSettingsFile(settingsPath, next);
handleSharedSettingsChanged(next);
mainWindow?.webContents.send(IPC_EVENT_CHANNELS.sharedSettingsChanged, next);
}

function handleMainWindowClose(event: Electron.Event): void {
if (isQuitting) return;
if (!mainWindow || mainWindow.isDestroyed()) return;
Expand Down Expand Up @@ -717,6 +756,34 @@ if (!hasSingleInstanceLock) {
captureMainException(error, tags);
},
onEvent: (event) => {
if (event.type === "crossagent-selection-used") {
try {
recordCrossagentSelectionPreference(event);
} catch (error) {
captureMainException(error, { "poracode.feature_area": "crossagents-routing" });
}
return;
}
if (event.type === "crossagent-routing-override-changed") {
let errorMessage: string | undefined;
try {
updateCrossagentRoutingOverride(event);
} catch (error) {
errorMessage =
error instanceof Error ? error.message : "Unable to save the routing preference";
captureMainException(error, { "poracode.feature_area": "crossagents-routing" });
}
void supervisorClient
.call("confirmCrossagentRoutingOverride", {
requestId: event.requestId,
ok: errorMessage === undefined,
...(errorMessage ? { error: errorMessage } : {}),
})
.catch((error) => {
captureMainException(error, { "poracode.feature_area": "crossagents-routing" });
});
return;
}
persistSupervisorEvent(event);
handleSupervisorEventForSleep(event);
appControlsMcpIngress?.observeSupervisorEvent(event);
Expand Down
44 changes: 44 additions & 0 deletions src/main/sharedSettingsFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@/shared/settings";
import {
applyClaudeProfileEnvironment,
mergeManagedSharedSettings,
readSharedSettingsFile,
writeSharedSettingsFile,
} from "./sharedSettingsFile";
Expand All @@ -36,6 +37,43 @@ afterEach(() => {
});

describe("sharedSettingsFile", () => {
it("preserves supervisor-managed Crossagents routing data during renderer writes", () => {
const onDisk: SharedSettings = {
...defaultSharedSettings,
crossagentSelectionUsage: [
{
agentKind: "kimi",
modelId: "k3",
effort: "max",
fast: false,
tags: ["mobile", "simulator"],
count: 4,
lastUsedAt: 10,
},
],
crossagentRoutingOverrides: [
{
tags: ["frontend", "design"],
agentKind: "claude",
modelId: "opus",
effort: "max",
fast: false,
updatedAt: 11,
},
],
};
const {
agentHookSupport: _agentHookSupport,
crossagentSelectionUsage: _crossagentSelectionUsage,
crossagentRoutingOverrides: _crossagentRoutingOverrides,
...incoming
} = defaultSharedSettings;

const merged = mergeManagedSharedSettings(onDisk, incoming);
expect(merged.crossagentSelectionUsage).toEqual(onDisk.crossagentSelectionUsage);
expect(merged.crossagentRoutingOverrides).toEqual(onDisk.crossagentRoutingOverrides);
});

it("writes and reads shared settings as readable JSON", () => {
const settingsPath = join(makeTempDir(), "settings.json");
writeSharedSettingsFile(settingsPath, {
Expand Down Expand Up @@ -128,6 +166,9 @@ describe("sharedSettingsFile", () => {
workspaces: [],
favoriteModels: [],
recentModels: [],
agentSelectionUsage: [],
crossagentSelectionUsage: [],
crossagentRoutingOverrides: [],
agentHookSupport: {},
enabledMcpServers: {},
mcpServers: [],
Expand Down Expand Up @@ -251,6 +292,9 @@ describe("sharedSettingsFile", () => {
workspaces: [],
favoriteModels: [],
recentModels: [],
agentSelectionUsage: [],
crossagentSelectionUsage: [],
crossagentRoutingOverrides: [],
agentHookSupport: {},
enabledMcpServers: {},
mcpServers: [],
Expand Down
2 changes: 2 additions & 0 deletions src/main/sharedSettingsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export function mergeManagedSharedSettings(
...supervisorManagedInstances,
},
agentHookSupport: onDisk.agentHookSupport,
crossagentSelectionUsage: onDisk.crossagentSelectionUsage,
crossagentRoutingOverrides: onDisk.crossagentRoutingOverrides,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/mobile/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ const remoteBridge = {
pushDesktopSettingsDiff(activeClient, settings);
return Promise.resolve();
},
removeCrossagentRoutingOverride: () =>
Promise.reject(new Error("Manual routing preferences can only be changed on desktop.")),

// Shell conveniences with browser-native equivalents.
openExternal: (url: string) => {
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/actions/threadLaunchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export async function performInitialThreadLaunch(input: {
if (thread.config.model) {
useSharedSettings
.getState()
.pushRecentModel(thread.agentKind, thread.config.model, presentation);
.pushRecentModel(
thread.agentKind,
thread.config.model,
presentation,
thread.config.effort,
thread.config.fast,
);
}

let optimisticUserMessageItemId: string | undefined;
Expand Down
Loading