Skip to content
Closed
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
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ Chat view:
- `varro.chat.fontSize` - chat text size from `6` through `100`; defaults to `null`, which uses VS Code's `chat.fontSize`. Tool and diff editor content follows `chat.editor.fontSize`
- `varro.chat.showChangedFiles` - show the changed-files panel above the composer; defaults to `false`
- `varro.chat.showTurnTimer` - show the elapsed duration of the active turn beside the composer status controls; defaults to `true`
- `varro.chat.defaultAgent` - primary agent selected for new chats and sessions; defaults to empty, which uses Build
- `varro.chat.desktopSessionPaneSide` - on large screens, show the sessions pane on the `left` or `right`; defaults to `right`
- Use the scope picker inside the session search field to choose which OpenCode sessions appear. **Folder** shows exact working-directory matches, **Nested** includes folders beneath it in the same OpenCode project, and **Project** shows the entire containing Git project. Varro remembers the choice for each project; non-Git folders offer Folder and Nested independently.
- `varro.chat.autoRenameUntitledSessions` - generate a fallback title when OpenCode leaves a session untitled; defaults to `false`
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@
"default": "right",
"markdownDescription": "Choose which side shows the sessions pane on large screens in the Varro chat view."
},
"varro.chat.defaultAgent": {
"type": "string",
"scope": "application",
"default": "",
"markdownDescription": "Primary agent selected for new chats and sessions. Leave empty to use Build."
},
"varro.chat.defaultPermissionMode": {
"type": "string",
"enum": [
Expand Down
9 changes: 9 additions & 0 deletions src/extension/extension-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('readExtensionConfigState', () => {
showTurnTimer: true,
showEmptyStateHistogram: false,
followupsEnabled: true,
defaultAgent: '',
debugShowQuotaWarning: false,
debugResetWarningDays: 5,
autoAttachProblems: true,
Expand Down Expand Up @@ -89,6 +90,14 @@ describe('readExtensionConfigState', () => {
expect(readExtensionConfigState().followupsEnabled).toBe(false);
});

it('reads and trims the default agent for new sessions', () => {
expect(readExtensionConfigState().defaultAgent).toBe('');
mocks.values.set('varro.chat.defaultAgent', ' plan ');
expect(readExtensionConfigState().defaultAgent).toBe('plan');
mocks.values.set('varro.chat.defaultAgent', 42);
expect(readExtensionConfigState().defaultAgent).toBe('');
});

it('reads follow-up model overrides only from user settings', () => {
expect(readExtensionConfigState().followupModel).toBe('');
mocks.values.set('varro.chat.followupModel', 'openai/fast');
Expand Down
8 changes: 8 additions & 0 deletions src/extension/extension-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function readExtensionConfigState(
remoteImages: parseRemoteImageMode(config.inspect?.('chat.remoteImages')?.globalValue),
promptCompletionModel: config.get<string>('chat.promptCompletionModel', ''),
followupsEnabled: readFollowupsEnabled(config),
defaultAgent: readDefaultAgent(config),
followupModel: readFollowupModel(config),
debugShowQuotaWarning: config.get<boolean>('debug.showQuotaWarning', false),
debugResetWarningDays: readResetWarningDays(config),
Expand Down Expand Up @@ -53,6 +54,13 @@ export function readFollowupModel(
return isString(value) ? value.trim() : '';
}

function readDefaultAgent(
config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('varro')
): string {
const value = config.get<unknown>('chat.defaultAgent');
return isString(value) ? value.trim() : '';
}

function readResetWarningDays(config: vscode.WorkspaceConfiguration): number {
const value = config.get<unknown>('debug.resetWarningDays');
return isNumber(value) && Number.isFinite(value) && value >= DEFAULT_RESET_WARNING_DAYS
Expand Down
13 changes: 13 additions & 0 deletions src/extension/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,19 @@ describe('extension manifest', () => {
expect(packageJson.activationEvents).not.toContain('onStartupFinished');
});

it('contributes a user-scoped default agent setting', () => {
const properties = packageJson.contributes.configuration.properties as Record<
string,
Record<string, unknown>
>;

expect(properties['varro.chat.defaultAgent']).toMatchObject({
type: 'string',
scope: 'application',
default: '',
});
});

it('contributes a disabled-by-default empty-state histogram setting', () => {
const properties = packageJson.contributes.configuration.properties as Record<
string,
Expand Down
9 changes: 9 additions & 0 deletions src/extension/sidebar-provider.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,15 @@ describe('SidebarProvider local config routing', () => {
type: 'config/update',
payload: expect.objectContaining({ debugShowQuotaWarning: true }),
});

await vscodeMock.workspace.getConfiguration('varro').update('chat.defaultAgent', 'plan');
listener?.({
affectsConfiguration: (key: string) => key === 'varro.chat.defaultAgent',
});
expect(posted).toContainEqual({
type: 'config/update',
payload: expect.objectContaining({ defaultAgent: 'plan' }),
});
});

it('reads model routing from project opencode.json', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/extension/sidebar-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
event.affectsConfiguration('varro.chat.remoteImages') ||
event.affectsConfiguration('varro.chat.promptCompletionModel') ||
event.affectsConfiguration('varro.chat.followupsEnabled') ||
event.affectsConfiguration('varro.chat.defaultAgent') ||
event.affectsConfiguration('varro.chat.followupModel') ||
event.affectsConfiguration('varro.debug.showQuotaWarning') ||
event.affectsConfiguration('varro.debug.resetWarningDays') ||
Expand Down
1 change: 1 addition & 0 deletions src/extension/webview-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ export class WebviewSession {
remoteImages: config.remoteImages,
promptCompletionModel: config.promptCompletionModel,
followupsEnabled: config.followupsEnabled,
defaultAgent: config.defaultAgent,
followupModel: config.followupModel,
debugShowQuotaWarning: config.debugShowQuotaWarning,
debugResetWarningDays: config.debugResetWarningDays,
Expand Down
2 changes: 2 additions & 0 deletions src/shared/extension-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ describe('parseExtensionMessage', () => {
showChangedFiles: true,
showTurnTimer: true,
showEmptyStateHistogram: true,
defaultAgent: 'plan',
remoteImages: 'ask',
debugShowQuotaWarning: true,
autoAttachProblems: false,
Expand All @@ -1144,6 +1145,7 @@ describe('parseExtensionMessage', () => {
showChangedFiles: true,
showTurnTimer: true,
showEmptyStateHistogram: true,
defaultAgent: 'plan',
remoteImages: 'ask',
debugShowQuotaWarning: true,
autoAttachProblems: false,
Expand Down
1 change: 1 addition & 0 deletions src/shared/extension-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export function parseExtensionMessage<T>(value: T): ExtensionMessage | null {
if (isString(payload.promptCompletionModel))
config.promptCompletionModel = payload.promptCompletionModel;
if (isBoolean(payload.followupsEnabled)) config.followupsEnabled = payload.followupsEnabled;
if (isString(payload.defaultAgent)) config.defaultAgent = payload.defaultAgent;
if (isString(payload.followupModel)) config.followupModel = payload.followupModel;
if (isBoolean(payload.debugShowQuotaWarning))
config.debugShowQuotaWarning = payload.debugShowQuotaWarning;
Expand Down
1 change: 1 addition & 0 deletions src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ export type InitialWebviewState = {
remoteImages?: RemoteImageMode;
promptCompletionModel?: string;
followupsEnabled?: boolean;
defaultAgent?: string;
followupModel?: string;
debugShowQuotaWarning?: boolean;
debugResetWarningDays?: number;
Expand Down
2 changes: 2 additions & 0 deletions src/shared/provider-limit-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ExtensionConfigState = {
remoteImages?: RemoteImageMode;
promptCompletionModel?: string;
followupsEnabled?: boolean;
defaultAgent?: string;
followupModel?: string;
debugShowQuotaWarning?: boolean;
debugResetWarningDays?: number;
Expand All @@ -34,6 +35,7 @@ export type WebviewConfigUpdatePayload = Pick<
| 'showEmptyStateHistogram'
| 'promptCompletionModel'
| 'followupsEnabled'
| 'defaultAgent'
| 'followupModel'
| 'debugShowQuotaWarning'
| 'debugResetWarningDays'
Expand Down
3 changes: 3 additions & 0 deletions src/webview/hooks/data-loaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function createLoaderDeps(overrides: Partial<DataLoaderDependencies> = {}): Data
getSelectedAgent: () => null,
getSelectedAgentForSession: () => null,
getPersistedSelectedAgent: () => null,
getDefaultAgent: () => '',
hydrateSessionSelectedAgents: vi.fn(),
setAllAgents: vi.fn(),
setPrimaryAgents: vi.fn(),
Expand Down Expand Up @@ -163,6 +164,7 @@ describe('data loaders', () => {
getSelectedAgent: () => 'plan',
getSelectedAgentForSession: () => null,
getPersistedSelectedAgent: () => 'plan',
getDefaultAgent: () => '',
setAllAgents,
setPrimaryAgents,
setSelectedAgent,
Expand All @@ -186,6 +188,7 @@ describe('data loaders', () => {
getSelectedAgent: () => null,
getSelectedAgentForSession: () => null,
getPersistedSelectedAgent: () => null,
getDefaultAgent: () => '',
setAllAgents: vi.fn(),
setPrimaryAgents: vi.fn(),
setSelectedAgent,
Expand Down
5 changes: 5 additions & 0 deletions src/webview/hooks/data-loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function createStateBoundDataLoaderOperations(deps: {
getSelectedAgent: () => appStore.state.selectedAgent,
getSelectedAgentForSession: routingStore.getSelectedAgentForSession,
getPersistedSelectedAgent: routingStore.getPersistedSelectedAgent,
getDefaultAgent: () => appStore.state.defaultAgent,
hydrateSessionSelectedAgents: routingStore.hydrateSessionSelectedAgents,
setAllAgents: routingStore.setAllAgents,
setPrimaryAgents: routingStore.setPrimaryAgents,
Expand Down Expand Up @@ -123,6 +124,7 @@ export function createDataLoaderOperations(deps: {
getSelectedAgent(): string | null;
getSelectedAgentForSession(sessionId: string): string | null;
getPersistedSelectedAgent(): string | null;
getDefaultAgent(): string;
hydrateSessionSelectedAgents(agents: Record<string, string>): void;
setAllAgents(agents: Agent[]): void;
setPrimaryAgents(agents: Agent[]): void;
Expand Down Expand Up @@ -304,6 +306,7 @@ export function createDataLoaderOperations(deps: {
getSelectedAgent: deps.getSelectedAgent,
getSelectedAgentForSession: deps.getSelectedAgentForSession,
getPersistedSelectedAgent: deps.getPersistedSelectedAgent,
getDefaultAgent: deps.getDefaultAgent,
setAllAgents: deps.setAllAgents,
setPrimaryAgents: deps.setPrimaryAgents,
setSelectedAgent: deps.setSelectedAgent,
Expand Down Expand Up @@ -777,6 +780,7 @@ export async function loadAgentsWithDependencies(
getSelectedAgent(): string | null;
getSelectedAgentForSession(sessionId: string): string | null;
getPersistedSelectedAgent(): string | null;
getDefaultAgent(): string;
setAllAgents(agents: Agent[]): void;
setPrimaryAgents(agents: Agent[]): void;
setSelectedAgent(
Expand All @@ -799,6 +803,7 @@ export async function loadAgentsWithDependencies(
? deps.getSelectedAgentForSession(activeSessionId)
: null,
persistedSelectedAgent: deps.getPersistedSelectedAgent(),
defaultAgent: deps.getDefaultAgent(),
});

deps.setAllAgents(routingState.visibleAgents);
Expand Down
2 changes: 2 additions & 0 deletions src/webview/hooks/mount-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ describe('mount bridge helpers', () => {
showTurnTimer: true,
showEmptyStateHistogram: true,
followupsEnabled: false,
defaultAgent: 'plan',
remoteImages: 'ask',
debugShowQuotaWarning: true,
autoAttachProblems: false,
Expand Down Expand Up @@ -939,6 +940,7 @@ describe('mount bridge helpers', () => {
expect(setShowTurnTimer).toHaveBeenCalledWith(true);
expect(setShowEmptyStateHistogram).toHaveBeenCalledWith(true);
expect(setState).toHaveBeenCalledWith('followupsEnabled', false);
expect(setState).toHaveBeenCalledWith('defaultAgent', 'plan');
expect(setState).toHaveBeenCalledWith('debugShowQuotaWarning', true);
expect(setState).toHaveBeenCalledWith('autoAttachProblems', false);
expect(setState).toHaveBeenCalledWith('autoAttachActiveFile', false);
Expand Down
3 changes: 3 additions & 0 deletions src/webview/hooks/mount-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export function createMountBridgeOperations(deps: {
if (payload.followupsEnabled !== undefined) {
appStore.setState('followupsEnabled', payload.followupsEnabled);
}
if (payload.defaultAgent !== undefined) {
appStore.setState('defaultAgent', payload.defaultAgent);
}
if (payload.followupModel !== undefined) {
appStore.setState('followupModel', payload.followupModel);
}
Expand Down
31 changes: 31 additions & 0 deletions src/webview/hooks/routing-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('routing-state helpers', () => {
selectedAgent: 'plan',
sessionSelectedAgent: null,
persistedSelectedAgent: 'plan',
defaultAgent: '',
})
).toMatchObject({
visibleAgents: [agent('plan'), agent('build')],
Expand All @@ -87,6 +88,7 @@ describe('routing-state helpers', () => {
selectedAgent: 'build',
sessionSelectedAgent: 'build',
persistedSelectedAgent: 'build',
defaultAgent: '',
})
).toMatchObject({
nextSelectedAgent: {
Expand All @@ -104,6 +106,7 @@ describe('routing-state helpers', () => {
selectedAgent: 'plan',
sessionSelectedAgent: null,
persistedSelectedAgent: 'plan',
defaultAgent: '',
}).nextSelectedAgent
).toEqual({ value: 'build', options: { persistGlobal: false } });

Expand All @@ -114,6 +117,7 @@ describe('routing-state helpers', () => {
selectedAgent: 'build',
sessionSelectedAgent: null,
persistedSelectedAgent: 'plan',
defaultAgent: '',
}).nextSelectedAgent
).toBeNull();
});
Expand All @@ -126,6 +130,31 @@ describe('routing-state helpers', () => {
selectedAgent: null,
sessionSelectedAgent: null,
persistedSelectedAgent: 'ask',
defaultAgent: '',
}).nextSelectedAgent
).toEqual({ value: 'build', options: { persistGlobal: false } });
});

it('uses the configured default agent for a fresh draft', () => {
expect(
reconcileLoadedAgents({
loadedAgents: [agent('ask'), agent('plan'), agent('build')],
activeSessionId: null,
selectedAgent: null,
sessionSelectedAgent: null,
persistedSelectedAgent: 'ask',
defaultAgent: 'plan',
}).nextSelectedAgent
).toEqual({ value: 'plan', options: { persistGlobal: false } });

expect(
reconcileLoadedAgents({
loadedAgents: [agent('build')],
activeSessionId: null,
selectedAgent: null,
sessionSelectedAgent: null,
persistedSelectedAgent: null,
defaultAgent: 'review',
}).nextSelectedAgent
).toEqual({ value: 'build', options: { persistGlobal: false } });
});
Expand All @@ -138,6 +167,7 @@ describe('routing-state helpers', () => {
selectedAgent: 'ask',
sessionSelectedAgent: null,
persistedSelectedAgent: 'build',
defaultAgent: '',
}).nextSelectedAgent
).toBeNull();
});
Expand All @@ -154,6 +184,7 @@ describe('routing-state helpers', () => {
selectedAgent: null,
sessionSelectedAgent: 'plan',
persistedSelectedAgent: 'build',
defaultAgent: '',
});

expect(result.nextSelectedAgent).toEqual({
Expand Down
7 changes: 6 additions & 1 deletion src/webview/hooks/routing-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ export function reconcileLoadedAgents(args: {
selectedAgent: string | null;
sessionSelectedAgent: string | null;
persistedSelectedAgent: string | null;
defaultAgent: string;
}) {
const visibleAgents = args.loadedAgents.filter((agent) => !agent.hidden);
const primaryAgents = visibleAgents.filter((agent) => agent.mode !== 'subagent');
let nextSelectedAgent: AgentSelectionUpdate | null = null;

if (!args.activeSessionId) {
const fallback = [args.selectedAgent, getDefaultPrimaryAgentName(primaryAgents)].find(
const fallback = [
args.selectedAgent,
args.defaultAgent,
getDefaultPrimaryAgentName(primaryAgents),
].find(
(candidate): candidate is string =>
!!candidate && primaryAgents.some((agent) => agent.name === candidate)
);
Expand Down
1 change: 1 addition & 0 deletions src/webview/hooks/runtime/open-code-runtime-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,7 @@ export function createOpenCodeRuntime(): OpenCodeRuntime {
appStore.state.sessions.find((session) => session.id === sessionId)
),
resolveDefaultAgent: () =>
appStore.state.agents.find((agent) => agent.name === appStore.state.defaultAgent)?.name ||
getBuildAgentNameFromState() ||
routingStore.getPersistedSelectedAgent() ||
getDefaultPrimaryAgentNameFromState(),
Expand Down
29 changes: 29 additions & 0 deletions src/webview/hooks/useOpenCode.sendMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,35 @@ describe('sendMessage', () => {
expect(stateModule.getPersistedSelectedAgent()).toBe('plan');
});

it('uses the configured default agent for a new session', async () => {
const { stateModule, hookModule } = await loadModules();

stateModule.setState('agents', [
{
name: 'build',
mode: 'primary',
builtIn: true,
permission: { edit: 'ask', bash: {} },
tools: {},
},
{
name: 'plan',
mode: 'primary',
builtIn: true,
permission: { edit: 'ask', bash: {} },
tools: {},
},
]);
stateModule.setState('defaultAgent', 'plan');

clientMocks.sessionCreate.mockResolvedValue(session('session-2'));

await hookModule.createSession();

expect(stateModule.state.selectedAgent).toBe('plan');
expect(stateModule.getSelectedAgentForSession('session-2')).toBe('plan');
});

it('sends the first message of a new chat with the selected agent', async () => {
const { stateModule, hookModule } = await loadModules();

Expand Down
Loading