codeep 1.0.7 → 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 +36 -17
- 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,13 +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
|
|
30
|
+
- Do EXACTLY what the user asks
|
|
31
31
|
- If user says "create folder X" -> use create_directory tool to create folder X
|
|
32
32
|
- If user says "delete file X" -> use delete_file tool to delete file X
|
|
33
|
-
- Do NOT interpret or expand simple requests into complex tasks
|
|
34
|
-
- Simple tasks should be completed in 1-2 tool calls
|
|
35
33
|
- The user may write in any language - understand their request and execute it
|
|
36
34
|
- Tool names and parameters must ALWAYS be in English (e.g., "create_directory", not "kreiraj_direktorij")
|
|
35
|
+
- When you finish a subtask, provide a clear summary and I will give you the next subtask
|
|
37
36
|
|
|
38
37
|
## Rules
|
|
39
38
|
1. Always read files before editing them to understand the current content
|
|
@@ -70,12 +69,12 @@ function getFallbackSystemPrompt(projectContext) {
|
|
|
70
69
|
return `You are an AI coding agent with FULL autonomous access to this project.
|
|
71
70
|
|
|
72
71
|
## IMPORTANT: Follow User Instructions Exactly
|
|
73
|
-
- Do EXACTLY what the user asks
|
|
72
|
+
- Do EXACTLY what the user asks
|
|
74
73
|
- If user says "create folder X" -> use create_directory tool
|
|
75
|
-
- If user says "delete file X" -> use delete_file tool
|
|
76
|
-
- Do NOT interpret or expand simple requests into complex tasks
|
|
74
|
+
- If user says "delete file X" -> use delete_file tool
|
|
77
75
|
- The user may write in any language - understand and execute
|
|
78
76
|
- Tool names and parameters must ALWAYS be in English
|
|
77
|
+
- When you finish a subtask, provide a clear summary and I will give you the next subtask
|
|
79
78
|
|
|
80
79
|
## Available Tools
|
|
81
80
|
${formatToolDefinitions()}
|
|
@@ -374,9 +373,13 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
374
373
|
const messages = [];
|
|
375
374
|
// Start history session for undo support
|
|
376
375
|
const sessionId = startSession(prompt, projectContext.root || process.cwd());
|
|
377
|
-
// Task planning phase (if enabled
|
|
376
|
+
// Task planning phase (if enabled)
|
|
377
|
+
// Use planning for complex keywords or multi-word prompts
|
|
378
378
|
let taskPlan = null;
|
|
379
|
-
|
|
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) {
|
|
380
383
|
try {
|
|
381
384
|
opts.onIteration?.(0, 'Planning tasks...');
|
|
382
385
|
taskPlan = await planTasks(prompt, {
|
|
@@ -386,6 +389,8 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
386
389
|
});
|
|
387
390
|
if (taskPlan.tasks.length > 1) {
|
|
388
391
|
opts.onTaskPlan?.(taskPlan);
|
|
392
|
+
// Mark first task as in_progress
|
|
393
|
+
taskPlan.tasks[0].status = 'in_progress';
|
|
389
394
|
}
|
|
390
395
|
else {
|
|
391
396
|
taskPlan = null; // Single task, no need for planning
|
|
@@ -478,15 +483,29 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
478
483
|
if (toolCalls.length === 0) {
|
|
479
484
|
// Remove <think>...</think> tags from response (some models include thinking)
|
|
480
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
|
+
}
|
|
506
|
+
}
|
|
481
507
|
break;
|
|
482
508
|
}
|
|
483
|
-
// Also check if response indicates completion (even with tool calls)
|
|
484
|
-
const completionIndicators = ['task completed', 'finished', 'done with', 'successfully created', 'all set'];
|
|
485
|
-
const lowerContent = content.toLowerCase();
|
|
486
|
-
if (completionIndicators.some(indicator => lowerContent.includes(indicator))) {
|
|
487
|
-
// Agent thinks task is complete, but included tool calls - execute them and finish
|
|
488
|
-
// Continue with tool execution but mark this as potentially the last iteration
|
|
489
|
-
}
|
|
490
509
|
// Add assistant response to history
|
|
491
510
|
messages.push({ role: 'assistant', content });
|
|
492
511
|
// Execute tool calls
|
|
@@ -522,7 +541,7 @@ export async function runAgent(prompt, projectContext, options = {}) {
|
|
|
522
541
|
// Add tool results to messages
|
|
523
542
|
messages.push({
|
|
524
543
|
role: 'user',
|
|
525
|
-
content: `Tool results:\n\n${toolResults.join('\n\n')}\n\nContinue with the task. If
|
|
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.`,
|
|
526
545
|
});
|
|
527
546
|
}
|
|
528
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",
|