|
1 | | -import { ToolCall } from 'types/agent-definition' |
2 | | -import { publisher } from '../constants' |
3 | | -import { |
4 | | - PLACEHOLDER, |
5 | | - type SecretAgentDefinition, |
6 | | -} from '../types/secret-agent-definition' |
| 1 | +import type { SecretAgentDefinition } from '../types/secret-agent-definition' |
| 2 | +import { plannerFactory } from './planner-factory' |
7 | 3 |
|
8 | | -const planner: SecretAgentDefinition = { |
| 4 | +const definition: SecretAgentDefinition = { |
9 | 5 | id: 'planner', |
10 | | - publisher, |
11 | | - |
12 | | - model: 'google/gemini-2.5-pro', |
13 | | - displayName: 'Peter Plan', |
14 | | - spawnerPrompt: |
15 | | - 'Creates comprehensive plans by exploring the codebase and deep thinking', |
16 | | - inputSchema: { |
17 | | - prompt: { |
18 | | - type: 'string', |
19 | | - description: 'The coding task to plan for', |
20 | | - }, |
21 | | - }, |
22 | | - outputMode: 'last_message', |
23 | | - includeMessageHistory: true, |
24 | | - toolNames: ['spawn_agents', 'end_turn'], |
25 | | - spawnableAgents: ['file-explorer', 'researcher', 'gemini-thinker-high'], |
26 | | - |
27 | | - systemPrompt: `You are a strategic planner who creates comprehensive plans for coding tasks. |
28 | | -You should spawn agents to help you gather information and think through the problem before creating your plan. |
29 | | -${PLACEHOLDER.FILE_TREE_PROMPT} |
30 | | -${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`, |
31 | | - |
32 | | - instructionsPrompt: `Create a comprehensive plan for the given coding task. |
33 | | -
|
34 | | -Process: |
35 | | -1. First, spawn a file-explorer to understand the relevant codebase. You may also spawn a researcher to search the web for relevant information at the same time. |
36 | | -2. Then spawn a thinker to analyze the best approach |
37 | | -3. Finally, write out a plan that focuses on the high level approach to the task, with short excerpts of code/types that help |
38 | | -
|
39 | | -Your plan should be specific, actionable, and account for the current codebase structure.`, |
40 | | - |
41 | | - handleSteps: function* ({ prompt }) { |
42 | | - // Step 1: Spawn file-explorer and parse out the file paths |
43 | | - const { agentState: stateAfterFileExplorer } = yield 'STEP' |
44 | | - const { messageHistory } = stateAfterFileExplorer |
45 | | - const lastAssistantMessageIndex = |
46 | | - stateAfterFileExplorer.messageHistory.findLastIndex( |
47 | | - (message) => message.role === 'assistant', |
48 | | - ) |
49 | | - const toolResultMessage = messageHistory[lastAssistantMessageIndex + 1] ?? { |
50 | | - content: '', |
51 | | - } |
52 | | - const filePaths = parseFilePathsFromToolResult(toolResultMessage.content) |
53 | | - |
54 | | - // Step 2: Read the files |
55 | | - yield { |
56 | | - toolName: 'read_files', |
57 | | - input: { |
58 | | - paths: filePaths, |
59 | | - }, |
60 | | - } satisfies ToolCall |
61 | | - |
62 | | - // Step 3: Spawn deep-thinker to analyze approach |
63 | | - const { toolResult: deepThinkerToolResult } = yield { |
64 | | - toolName: 'spawn_agents', |
65 | | - input: { |
66 | | - agents: [ |
67 | | - { |
68 | | - agent_type: 'gemini-thinker-high', |
69 | | - prompt: `Create a clear implementation plan for the following task, with a focus on simplicity and making the minimal changes necessary for an awesome implementation. Prompt: ${prompt}`, |
70 | | - }, |
71 | | - ], |
72 | | - }, |
73 | | - } |
74 | | - |
75 | | - yield { |
76 | | - toolName: 'set_output', |
77 | | - input: { |
78 | | - plan: deepThinkerToolResult, |
79 | | - }, |
80 | | - } |
81 | | - |
82 | | - function parseFilePathsFromToolResult(content: string): string[] { |
83 | | - const filePaths: string[] = [] |
84 | | - |
85 | | - // Match file paths that look like valid paths (containing / and file extensions) |
86 | | - const filePathRegex = |
87 | | - /(?:^|\s|\*\s*)((?:[\w-]+\/)*[\w.-]+\.[a-zA-Z]{1,4})(?=\s|$|,|\.|:)/gm |
88 | | - |
89 | | - let match |
90 | | - while ((match = filePathRegex.exec(content)) !== null) { |
91 | | - const filePath = match[1] |
92 | | - // Filter out obvious false positives and ensure reasonable path structure |
93 | | - if ( |
94 | | - filePath && |
95 | | - !filePath.startsWith('http') && |
96 | | - !filePath.includes('@') && |
97 | | - filePath.length > 3 && |
98 | | - filePath.split('/').length <= 10 |
99 | | - ) { |
100 | | - filePaths.push(filePath) |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - // Also look for backtick-quoted file paths |
105 | | - const backtickPathRegex = /`([^`]+\.[a-zA-Z]{1,4})`/g |
106 | | - while ((match = backtickPathRegex.exec(content)) !== null) { |
107 | | - const filePath = match[1] |
108 | | - if ( |
109 | | - filePath && |
110 | | - !filePath.startsWith('http') && |
111 | | - !filePath.includes('@') |
112 | | - ) { |
113 | | - filePaths.push(filePath) |
114 | | - } |
115 | | - } |
116 | | - |
117 | | - // Remove duplicates and return |
118 | | - return [...new Set(filePaths)] |
119 | | - } |
120 | | - }, |
| 6 | + ...plannerFactory('google/gemini-2.5-pro', 'gemini-thinker-high'), |
121 | 7 | } |
122 | 8 |
|
123 | | -export default planner |
| 9 | +export default definition |
0 commit comments