fix: Switch auto-spawn from discuss to refine agent, surface in UI
The auto-spawned agent on initiative creation was using discuss mode (Q&A) when it should use refine mode (expand content). Now: - Description seeds root page as tiptap content (split on double newlines) - Spawns refine agent with the populated page in inputContext - getActiveRefineAgent broadened to also surface discuss agents (for CLI-spawned discuss agents) - RefineAgentPanel shows mode-appropriate label for discuss vs refine
This commit is contained in:
@@ -7,7 +7,8 @@ import { z } from 'zod';
|
||||
import type { ProcedureBuilder } from '../trpc.js';
|
||||
import { requireAgentManager, requireInitiativeRepository, requireProjectRepository, requireTaskRepository } from './_helpers.js';
|
||||
import { deriveInitiativeActivity } from './initiative-activity.js';
|
||||
import { buildDiscussPrompt } from '../../agent/prompts/index.js';
|
||||
import { buildRefinePrompt } from '../../agent/prompts/index.js';
|
||||
import type { PageForSerialization } from '../../agent/content-serializer.js';
|
||||
|
||||
export function initiativeProcedures(publicProcedure: ProcedureBuilder) {
|
||||
return {
|
||||
@@ -47,38 +48,57 @@ export function initiativeProcedures(publicProcedure: ProcedureBuilder) {
|
||||
await projectRepo.setInitiativeProjects(initiative.id, input.projectIds);
|
||||
}
|
||||
|
||||
// Create root page — seed with description as tiptap content if provided
|
||||
const descriptionText = input.description?.trim();
|
||||
let rootPage: { id: string; parentPageId: string | null; title: string; content: string | null; sortOrder: number } | null = null;
|
||||
if (ctx.pageRepository) {
|
||||
await ctx.pageRepository.create({
|
||||
const tiptapContent = descriptionText
|
||||
? JSON.stringify({
|
||||
type: 'doc',
|
||||
content: descriptionText.split(/\n{2,}/).map(para => ({
|
||||
type: 'paragraph',
|
||||
content: [{ type: 'text', text: para.trim() }],
|
||||
})).filter(p => p.content[0].text),
|
||||
})
|
||||
: null;
|
||||
|
||||
rootPage = await ctx.pageRepository.create({
|
||||
initiativeId: initiative.id,
|
||||
parentPageId: null,
|
||||
title: input.name,
|
||||
content: null,
|
||||
content: tiptapContent,
|
||||
sortOrder: 0,
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-spawn discuss agent when description is provided
|
||||
if (input.description?.trim() && ctx.agentManager && ctx.taskRepository) {
|
||||
// Auto-spawn refine agent when description is provided
|
||||
if (descriptionText && rootPage && ctx.agentManager && ctx.taskRepository) {
|
||||
try {
|
||||
const taskRepo = requireTaskRepository(ctx);
|
||||
const agentManager = requireAgentManager(ctx);
|
||||
|
||||
const task = await taskRepo.create({
|
||||
initiativeId: initiative.id,
|
||||
name: `Discuss: ${initiative.name}`,
|
||||
description: input.description.trim(),
|
||||
category: 'discuss',
|
||||
name: `Refine: ${initiative.name}`,
|
||||
description: descriptionText,
|
||||
category: 'refine',
|
||||
status: 'in_progress',
|
||||
});
|
||||
|
||||
const prompt = buildDiscussPrompt();
|
||||
const pages: PageForSerialization[] = [{
|
||||
id: rootPage.id,
|
||||
parentPageId: null,
|
||||
title: rootPage.title,
|
||||
content: rootPage.content,
|
||||
sortOrder: 0,
|
||||
}];
|
||||
|
||||
agentManager.spawn({
|
||||
taskId: task.id,
|
||||
prompt,
|
||||
mode: 'discuss',
|
||||
prompt: buildRefinePrompt(),
|
||||
mode: 'refine',
|
||||
initiativeId: initiative.id,
|
||||
inputContext: { initiative, task },
|
||||
inputContext: { initiative, pages },
|
||||
});
|
||||
} catch {
|
||||
// Fire-and-forget — don't fail initiative creation if agent spawn fails
|
||||
|
||||
Reference in New Issue
Block a user