codeep 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/agent.js +53 -54
- package/dist/utils/taskPlanner.js +12 -10
- package/package.json +1 -1
package/dist/utils/agent.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getProviderBaseUrl, getProviderAuthHeader, supportsNativeTools } from '
|
|
|
7
7
|
import { startSession, endSession, undoLastAction, undoAllActions, getCurrentSession, getRecentSessions, formatSession } from './history.js';
|
|
8
8
|
import { runAllVerifications, formatErrorsForAgent, hasVerificationErrors, getVerificationSummary } from './verify.js';
|
|
9
9
|
import { gatherSmartContext, formatSmartContext, extractTargetFile } from './smartContext.js';
|
|
10
|
-
import { planTasks, formatTaskPlan } from './taskPlanner.js';
|
|
10
|
+
import { planTasks, getNextTask, formatTaskPlan } from './taskPlanner.js';
|
|
11
11
|
const DEFAULT_OPTIONS = {
|
|
12
12
|
maxIterations: 100, // Increased for large tasks
|
|
13
13
|
maxDuration: 20 * 60 * 1000, // 20 minutes
|
|
@@ -27,23 +27,22 @@ function getAgentSystemPrompt(projectContext) {
|
|
|
27
27
|
- List directory contents
|
|
28
28
|
|
|
29
29
|
## IMPORTANT: Follow User Instructions Exactly
|
|
30
|
-
- Do EXACTLY what the user asks
|
|
31
|
-
- If user says "create a website" -> create ALL necessary files (HTML, CSS, JS, etc.)
|
|
30
|
+
- Do EXACTLY what the user asks
|
|
32
31
|
- If user says "create folder X" -> use create_directory tool to create folder X
|
|
33
32
|
- If user says "delete file X" -> use delete_file tool to delete file X
|
|
34
|
-
- Do NOT stop after just 1-2 tool calls unless the task is trivially simple
|
|
35
|
-
- Complex tasks (like creating websites) require MANY tool calls to complete
|
|
36
33
|
- The user may write in any language - understand their request and execute it
|
|
37
34
|
- Tool names and parameters must ALWAYS be in English (e.g., "create_directory", not "kreiraj_direktorij")
|
|
38
|
-
-
|
|
35
|
+
- When you finish a subtask, provide a clear summary and I will give you the next subtask
|
|
39
36
|
|
|
40
37
|
## Rules
|
|
41
38
|
1. Always read files before editing them to understand the current content
|
|
42
39
|
2. Use edit_file for modifications to existing files (preserves other content)
|
|
43
40
|
3. Use write_file only for creating new files or complete overwrites
|
|
44
41
|
4. Use create_directory to create new folders/directories
|
|
45
|
-
5.
|
|
46
|
-
6.
|
|
42
|
+
5. Use list_files to see directory contents (NOT execute_command with ls)
|
|
43
|
+
6. Use execute_command only for npm, git, build tools, tests (NOT for ls, cat, etc.)
|
|
44
|
+
7. When the task is complete, respond with a summary WITHOUT any tool calls
|
|
45
|
+
8. IMPORTANT: After finishing, your response must NOT include any tool calls - just provide a summary
|
|
47
46
|
|
|
48
47
|
## Self-Verification
|
|
49
48
|
After you make changes, the system will automatically run build and tests.
|
|
@@ -72,15 +71,12 @@ function getFallbackSystemPrompt(projectContext) {
|
|
|
72
71
|
return `You are an AI coding agent with FULL autonomous access to this project.
|
|
73
72
|
|
|
74
73
|
## IMPORTANT: Follow User Instructions Exactly
|
|
75
|
-
- Do EXACTLY what the user asks
|
|
76
|
-
- If user says "create a website" -> create ALL necessary files (HTML, CSS, JS, etc.)
|
|
74
|
+
- Do EXACTLY what the user asks
|
|
77
75
|
- If user says "create folder X" -> use create_directory tool
|
|
78
76
|
- If user says "delete file X" -> use delete_file tool
|
|
79
|
-
- Do NOT stop after just 1-2 tool calls unless the task is trivially simple
|
|
80
|
-
- Complex tasks (like creating websites) require MANY tool calls to complete
|
|
81
77
|
- The user may write in any language - understand and execute
|
|
82
78
|
- Tool names and parameters must ALWAYS be in English
|
|
83
|
-
-
|
|
79
|
+
- When you finish a subtask, provide a clear summary and I will give you the next subtask
|
|
84
80
|
|
|
85
81
|
## Available Tools
|
|
86
82
|
${formatToolDefinitions()}
|
|
@@ -96,14 +92,20 @@ When you need to use a tool, respond with:
|
|
|
96
92
|
{"tool": "create_directory", "parameters": {"path": "my-folder"}}
|
|
97
93
|
</tool_call>
|
|
98
94
|
|
|
95
|
+
<tool_call>
|
|
96
|
+
{"tool": "list_files", "parameters": {"path": "."}}
|
|
97
|
+
</tool_call>
|
|
98
|
+
|
|
99
99
|
<tool_call>
|
|
100
100
|
{"tool": "write_file", "parameters": {"path": "test/index.html", "content": "<!DOCTYPE html>..."}}
|
|
101
101
|
</tool_call>
|
|
102
102
|
|
|
103
103
|
## Rules
|
|
104
104
|
1. Use the exact format shown above
|
|
105
|
-
2.
|
|
106
|
-
3.
|
|
105
|
+
2. Use list_files to see directory contents (NOT execute_command with ls)
|
|
106
|
+
3. Use execute_command only for npm, git, build tools (NOT for ls, cat, etc.)
|
|
107
|
+
4. Always read files before editing
|
|
108
|
+
5. When done, respond WITHOUT tool calls
|
|
107
109
|
|
|
108
110
|
## Project: ${projectContext.name} (${projectContext.type})
|
|
109
111
|
${projectContext.structure}
|
|
@@ -379,9 +381,13 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
379
381
|
const messages = [];
|
|
380
382
|
// Start history session for undo support
|
|
381
383
|
const sessionId = startSession(prompt, projectContext.root || process.cwd());
|
|
382
|
-
// Task planning phase (if enabled
|
|
384
|
+
// Task planning phase (if enabled)
|
|
385
|
+
// Use planning for complex keywords or multi-word prompts
|
|
383
386
|
let taskPlan = null;
|
|
384
|
-
|
|
387
|
+
const complexKeywords = ['create', 'build', 'implement', 'add', 'setup', 'generate', 'make', 'develop'];
|
|
388
|
+
const hasComplexKeyword = complexKeywords.some(kw => prompt.toLowerCase().includes(kw));
|
|
389
|
+
const shouldPlan = opts.usePlanning && (prompt.split(' ').length > 3 || hasComplexKeyword);
|
|
390
|
+
if (shouldPlan) {
|
|
385
391
|
try {
|
|
386
392
|
opts.onIteration?.(0, 'Planning tasks...');
|
|
387
393
|
taskPlan = await planTasks(prompt, {
|
|
@@ -391,6 +397,8 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
391
397
|
});
|
|
392
398
|
if (taskPlan.tasks.length > 1) {
|
|
393
399
|
opts.onTaskPlan?.(taskPlan);
|
|
400
|
+
// Mark first task as in_progress
|
|
401
|
+
taskPlan.tasks[0].status = 'in_progress';
|
|
394
402
|
}
|
|
395
403
|
else {
|
|
396
404
|
taskPlan = null; // Single task, no need for planning
|
|
@@ -479,41 +487,35 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
479
487
|
toolCalls = textToolCalls;
|
|
480
488
|
}
|
|
481
489
|
}
|
|
482
|
-
// If no tool calls,
|
|
483
|
-
// Don't exit on first iteration without tool calls - agent might be thinking
|
|
490
|
+
// If no tool calls, this is the final response
|
|
484
491
|
if (toolCalls.length === 0) {
|
|
485
|
-
//
|
|
486
|
-
|
|
487
|
-
//
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
continue;
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
// Later iteration without completion indicator - accept as final
|
|
514
|
-
finalResponse = content.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
515
|
-
break;
|
|
492
|
+
// Remove <think>...</think> tags from response (some models include thinking)
|
|
493
|
+
finalResponse = content.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
494
|
+
// Check if we're using task planning and there are more tasks
|
|
495
|
+
if (taskPlan && taskPlan.tasks.some(t => t.status === 'pending')) {
|
|
496
|
+
const nextTask = getNextTask(taskPlan.tasks);
|
|
497
|
+
if (nextTask) {
|
|
498
|
+
// Mark previous task as completed
|
|
499
|
+
const prevTask = taskPlan.tasks.find(t => t.status === 'in_progress' && t.id !== nextTask.id);
|
|
500
|
+
if (prevTask) {
|
|
501
|
+
prevTask.status = 'completed';
|
|
502
|
+
}
|
|
503
|
+
// Move to next task
|
|
504
|
+
nextTask.status = 'in_progress';
|
|
505
|
+
opts.onTaskUpdate?.(nextTask);
|
|
506
|
+
// Build progress summary
|
|
507
|
+
const completedTasks = taskPlan.tasks.filter(t => t.status === 'completed');
|
|
508
|
+
const progressSummary = completedTasks.map(t => `✓ ${t.id}. ${t.description}`).join('\n');
|
|
509
|
+
messages.push({ role: 'assistant', content: finalResponse });
|
|
510
|
+
messages.push({
|
|
511
|
+
role: 'user',
|
|
512
|
+
content: `Excellent! Task ${prevTask?.id} is complete.\n\nProgress so far:\n${progressSummary}\n\nNow continue with:\n${nextTask.id}. ${nextTask.description}\n\nOriginal request: ${taskPlan.originalPrompt}`
|
|
513
|
+
});
|
|
514
|
+
finalResponse = ''; // Reset for next task
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
516
517
|
}
|
|
518
|
+
break;
|
|
517
519
|
}
|
|
518
520
|
// Add assistant response to history
|
|
519
521
|
messages.push({ role: 'assistant', content });
|
|
@@ -548,12 +550,9 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
548
550
|
}
|
|
549
551
|
}
|
|
550
552
|
// Add tool results to messages
|
|
551
|
-
const nextStepPrompt = iteration < 5
|
|
552
|
-
? `Tool results:\n\n${toolResults.join('\n\n')}\n\nGood progress! Continue working on the task. Use more tools to complete what was requested. Only stop when EVERYTHING is finished and working.`
|
|
553
|
-
: `Tool results:\n\n${toolResults.join('\n\n')}\n\nContinue with the task. If the task is fully complete, provide a final summary without any tool calls.`;
|
|
554
553
|
messages.push({
|
|
555
554
|
role: 'user',
|
|
556
|
-
content:
|
|
555
|
+
content: `Tool results:\n\n${toolResults.join('\n\n')}\n\nContinue with the task. If this subtask is complete, provide a summary without tool calls.`,
|
|
557
556
|
});
|
|
558
557
|
}
|
|
559
558
|
// Check if we hit max iterations
|
|
@@ -10,19 +10,21 @@ export async function planTasks(userPrompt, projectContext) {
|
|
|
10
10
|
const systemPrompt = `You are a task planning expert. Break down user requests into clear, sequential subtasks.
|
|
11
11
|
|
|
12
12
|
RULES:
|
|
13
|
-
1. Create 3-
|
|
14
|
-
2. Each subtask should be specific and
|
|
15
|
-
3. Order tasks logically
|
|
13
|
+
1. Create 3-10 subtasks maximum (keep it focused)
|
|
14
|
+
2. Each subtask should be specific and achievable in 2-5 tool calls
|
|
15
|
+
3. Order tasks logically - one file/component per task
|
|
16
16
|
4. Use simple, clear descriptions
|
|
17
|
-
5.
|
|
17
|
+
5. For websites: separate HTML, CSS, JS into different tasks
|
|
18
|
+
6. Respond ONLY with a JSON object, no other text
|
|
18
19
|
|
|
19
|
-
Example
|
|
20
|
+
Example for "create a website":
|
|
20
21
|
{
|
|
21
22
|
"tasks": [
|
|
22
|
-
{"id": 1, "description": "Create
|
|
23
|
-
{"id": 2, "description": "Create index.html with
|
|
24
|
-
{"id": 3, "description": "Create styles.css with
|
|
25
|
-
{"id": 4, "description": "
|
|
23
|
+
{"id": 1, "description": "Create directory structure", "dependencies": []},
|
|
24
|
+
{"id": 2, "description": "Create index.html with page structure", "dependencies": [1]},
|
|
25
|
+
{"id": 3, "description": "Create styles.css with layout and design", "dependencies": [1]},
|
|
26
|
+
{"id": 4, "description": "Create script.js with interactive features", "dependencies": [1]},
|
|
27
|
+
{"id": 5, "description": "Add content and finalize all pages", "dependencies": [2, 3, 4]}
|
|
26
28
|
]
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -32,7 +34,7 @@ Project Context:
|
|
|
32
34
|
|
|
33
35
|
User Request: ${userPrompt}
|
|
34
36
|
|
|
35
|
-
Break this down into subtasks. Respond with JSON only.`;
|
|
37
|
+
Break this down into subtasks. Each task = one file or one logical unit. Respond with JSON only.`;
|
|
36
38
|
try {
|
|
37
39
|
const apiKey = await getApiKey();
|
|
38
40
|
if (!apiKey) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeep",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "AI-powered coding assistant built for the terminal. Multiple LLM providers, project-aware context, and a seamless development workflow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|