codeep 1.0.8 → 1.0.9
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 +38 -50
- 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,15 +27,12 @@ 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
|
|
@@ -72,15 +69,12 @@ function getFallbackSystemPrompt(projectContext) {
|
|
|
72
69
|
return `You are an AI coding agent with FULL autonomous access to this project.
|
|
73
70
|
|
|
74
71
|
## 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.)
|
|
72
|
+
- Do EXACTLY what the user asks
|
|
77
73
|
- If user says "create folder X" -> use create_directory tool
|
|
78
74
|
- 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
75
|
- The user may write in any language - understand and execute
|
|
82
76
|
- Tool names and parameters must ALWAYS be in English
|
|
83
|
-
-
|
|
77
|
+
- When you finish a subtask, provide a clear summary and I will give you the next subtask
|
|
84
78
|
|
|
85
79
|
## Available Tools
|
|
86
80
|
${formatToolDefinitions()}
|
|
@@ -379,9 +373,13 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
379
373
|
const messages = [];
|
|
380
374
|
// Start history session for undo support
|
|
381
375
|
const sessionId = startSession(prompt, projectContext.root || process.cwd());
|
|
382
|
-
// Task planning phase (if enabled
|
|
376
|
+
// Task planning phase (if enabled)
|
|
377
|
+
// Use planning for complex keywords or multi-word prompts
|
|
383
378
|
let taskPlan = null;
|
|
384
|
-
|
|
379
|
+
const complexKeywords = ['create', 'build', 'implement', 'add', 'setup', 'generate', 'make', 'develop'];
|
|
380
|
+
const hasComplexKeyword = complexKeywords.some(kw => prompt.toLowerCase().includes(kw));
|
|
381
|
+
const shouldPlan = opts.usePlanning && (prompt.split(' ').length > 3 || hasComplexKeyword);
|
|
382
|
+
if (shouldPlan) {
|
|
385
383
|
try {
|
|
386
384
|
opts.onIteration?.(0, 'Planning tasks...');
|
|
387
385
|
taskPlan = await planTasks(prompt, {
|
|
@@ -391,6 +389,8 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
391
389
|
});
|
|
392
390
|
if (taskPlan.tasks.length > 1) {
|
|
393
391
|
opts.onTaskPlan?.(taskPlan);
|
|
392
|
+
// Mark first task as in_progress
|
|
393
|
+
taskPlan.tasks[0].status = 'in_progress';
|
|
394
394
|
}
|
|
395
395
|
else {
|
|
396
396
|
taskPlan = null; // Single task, no need for planning
|
|
@@ -479,41 +479,32 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
479
479
|
toolCalls = textToolCalls;
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
|
-
// If no tool calls,
|
|
483
|
-
// Don't exit on first iteration without tool calls - agent might be thinking
|
|
482
|
+
// If no tool calls, this is the final response
|
|
484
483
|
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
|
-
role: 'user',
|
|
508
|
-
content: 'Continue with the task. Use the tools to complete what was requested. Do not stop until all files are created and the task is fully complete.'
|
|
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;
|
|
484
|
+
// Remove <think>...</think> tags from response (some models include thinking)
|
|
485
|
+
finalResponse = content.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
486
|
+
// Check if we're using task planning and there are more tasks
|
|
487
|
+
if (taskPlan && taskPlan.tasks.some(t => t.status === 'pending')) {
|
|
488
|
+
const nextTask = getNextTask(taskPlan.tasks);
|
|
489
|
+
if (nextTask) {
|
|
490
|
+
// Move to next task
|
|
491
|
+
nextTask.status = 'in_progress';
|
|
492
|
+
opts.onTaskUpdate?.(nextTask);
|
|
493
|
+
messages.push({ role: 'assistant', content: finalResponse });
|
|
494
|
+
messages.push({
|
|
495
|
+
role: 'user',
|
|
496
|
+
content: `Good progress! Next task:\n\n${nextTask.id}. ${nextTask.description}\n\nComplete this task now.`
|
|
497
|
+
});
|
|
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
|
+
finalResponse = ''; // Reset for next task
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
516
506
|
}
|
|
507
|
+
break;
|
|
517
508
|
}
|
|
518
509
|
// Add assistant response to history
|
|
519
510
|
messages.push({ role: 'assistant', content });
|
|
@@ -548,12 +539,9 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
548
539
|
}
|
|
549
540
|
}
|
|
550
541
|
// 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
542
|
messages.push({
|
|
555
543
|
role: 'user',
|
|
556
|
-
content:
|
|
544
|
+
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
545
|
});
|
|
558
546
|
}
|
|
559
547
|
// 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.9",
|
|
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",
|