sessions: default new sessions to no agent (raw chat)

Was picking the alphabetically-first agent from AGENTS.md ("Code
Reviewer") which felt presumptuous. New sessions now create with
agent_id=null; user picks from the AgentPicker if they want one.
Removes resolveDefaultAgent helper + the getAgentsForProject import
since this was the only caller. The project SELECT no longer needs
the path column either.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-20 20:11:57 +00:00
parent 1ffcf67c47
commit 4ec196273b

View File

@@ -5,7 +5,6 @@ import type { Config } from '../config.js';
import type { Broker } from '../services/broker.js'; import type { Broker } from '../services/broker.js';
import type { Session } from '../types/api.js'; import type { Session } from '../types/api.js';
import { getSetting } from './settings.js'; import { getSetting } from './settings.js';
import { getAgentsForProject } from '../services/agents.js';
const CreateBody = z.object({ const CreateBody = z.object({
name: z.string().min(1).max(200).optional(), name: z.string().min(1).max(200).optional(),
@@ -29,13 +28,6 @@ async function resolveDefaultModel(sql: Sql, config: Config): Promise<string> {
return config.DEFAULT_MODEL; return config.DEFAULT_MODEL;
} }
// First agent in the project's effective list (file-defined or builtin),
// or null if somehow none exist.
async function resolveDefaultAgent(projectPath: string): Promise<string | null> {
const { agents } = await getAgentsForProject(projectPath);
return agents[0]?.id ?? null;
}
export function registerSessionRoutes( export function registerSessionRoutes(
app: FastifyInstance, app: FastifyInstance,
sql: Sql, sql: Sql,
@@ -69,14 +61,13 @@ export function registerSessionRoutes(
reply.code(400); reply.code(400);
return { error: 'invalid body', details: parsed.error.flatten() }; return { error: 'invalid body', details: parsed.error.flatten() };
} }
const project = await sql<{ id: string; path: string }[]>` const project = await sql<{ id: string }[]>`
SELECT id, path FROM projects WHERE id = ${req.params.id} SELECT id FROM projects WHERE id = ${req.params.id}
`; `;
if (project.length === 0) { if (project.length === 0) {
reply.code(404); reply.code(404);
return { error: 'project not found' }; return { error: 'project not found' };
} }
const projectPath = project[0]!.path;
let model = parsed.data.model; let model = parsed.data.model;
if (!model) { if (!model) {
@@ -91,12 +82,11 @@ export function registerSessionRoutes(
const name = parsed.data.name ?? 'New session'; const name = parsed.data.name ?? 'New session';
const systemPrompt = parsed.data.system_prompt ?? ''; const systemPrompt = parsed.data.system_prompt ?? '';
// If the client provided agent_id (string or null), use it; otherwise // v1.11.5.2: default is null (no agent / raw chat) when the client
// resolve to the project's first agent (file-defined or builtin), or null. // omits agent_id. Sam can still pick one from the AgentPicker after
const agentId = // the session loads. Was: first agent in the project's effective list
parsed.data.agent_id !== undefined // (alphabetically — usually "Code Reviewer"), which felt presumptuous.
? parsed.data.agent_id const agentId = parsed.data.agent_id ?? null;
: await resolveDefaultAgent(projectPath);
const row = await sql.begin(async (tx) => { const row = await sql.begin(async (tx) => {
const [session] = await tx<Session[]>` const [session] = await tx<Session[]>`