@qelos/aidev 0.7.3 → 0.7.4

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.
@@ -45,6 +45,7 @@ exports.formatSubtaskId = formatSubtaskId;
45
45
  exports.subtaskDepth = subtaskDepth;
46
46
  exports.formatSubtaskList = formatSubtaskList;
47
47
  exports.runCommand = runCommand;
48
+ exports.isAidevComment = isAidevComment;
48
49
  exports.hasHumanReply = hasHumanReply;
49
50
  exports.hasTriggerWord = hasTriggerWord;
50
51
  exports.checkNeedsClarification = checkNeedsClarification;
@@ -351,11 +352,33 @@ async function processTask(task, filter, config, provider, runners, screenAvaila
351
352
  }
352
353
  return 'processed';
353
354
  }
355
+ function isAidevComment(text, commentPrefix = '[aidev]') {
356
+ return text.trimStart().startsWith(commentPrefix);
357
+ }
358
+ /**
359
+ * True when someone other than aidev spoke after an aidev message: there is a non-aidev
360
+ * comment that has at least one earlier [aidev]-prefixed comment in the thread.
361
+ * Ignores trailing aidev-only noise after the human (e.g. another bot post or sync).
362
+ */
354
363
  function hasHumanReply(comments, commentPrefix = '[aidev]') {
355
- if (comments.length < 2)
364
+ if (comments.length === 0)
365
+ return false;
366
+ let lastNonAidevIndex = -1;
367
+ for (let i = comments.length - 1; i >= 0; i--) {
368
+ if (!isAidevComment(comments[i].text, commentPrefix)) {
369
+ lastNonAidevIndex = i;
370
+ break;
371
+ }
372
+ }
373
+ if (lastNonAidevIndex === -1) {
356
374
  return false;
357
- const lastComment = comments[comments.length - 1];
358
- return !lastComment.text.includes(commentPrefix);
375
+ }
376
+ for (let j = lastNonAidevIndex - 1; j >= 0; j--) {
377
+ if (isAidevComment(comments[j].text, commentPrefix)) {
378
+ return true;
379
+ }
380
+ }
381
+ return false;
359
382
  }
360
383
  /**
361
384
  * Returns true if the last comment contains the trigger word.
@@ -403,16 +426,16 @@ async function checkNeedsClarification(task, config, provider, runners) {
403
426
  logger_1.logger.warn('No AI runner available — skipping clarification check');
404
427
  return null;
405
428
  }
406
- const clarificationPrompt = `You are a senior software developer reviewing a task.
407
- Determine if the following task has enough information to implement without further clarification.
408
-
409
- Task name: ${task.name}
410
- Task description: ${task.description || '(no description)'}
411
-
412
- Respond with valid JSON only:
413
- {
414
- "clear": true|false,
415
- "question": "question to ask if not clear, or null"
429
+ const clarificationPrompt = `You are a senior software developer reviewing a task.
430
+ Determine if the following task has enough information to implement without further clarification.
431
+
432
+ Task name: ${task.name}
433
+ Task description: ${task.description || '(no description)'}
434
+
435
+ Respond with valid JSON only:
436
+ {
437
+ "clear": true|false,
438
+ "question": "question to ask if not clear, or null"
416
439
  }`;
417
440
  for (const runner of availableRunners) {
418
441
  const result = await runner.run(clarificationPrompt);
@@ -440,30 +463,30 @@ Respond with valid JSON only:
440
463
  return null;
441
464
  }
442
465
  function buildConflictResolutionPrompt(task, conflictFiles, context) {
443
- return `You are resolving merge conflicts in a software development task branch.
444
-
445
- The task branch has fallen behind the base branch and has merge conflicts that need to be resolved.
446
-
447
- ## Task context (DO NOT break this — the task must still work after conflict resolution)
448
-
449
- Task: ${task.name}
450
-
451
- Description:
452
- ${task.description || '(no description provided)'}
453
- ${context}
454
-
455
- ## Merge conflicts
456
-
457
- The following files have merge conflicts with conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...):
458
- ${conflictFiles.map((f) => `- ${f}`).join('\n')}
459
-
460
- ## Instructions
461
-
462
- 1. Open each conflicting file and resolve the conflict markers
463
- 2. Keep BOTH the task's changes AND the base branch updates where possible
464
- 3. If the base branch changed something the task also changed, prefer the task's intent but make sure it works with the new base branch code
465
- 4. Remove all conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...)
466
- 5. Make sure the code compiles and is consistent after resolution
466
+ return `You are resolving merge conflicts in a software development task branch.
467
+
468
+ The task branch has fallen behind the base branch and has merge conflicts that need to be resolved.
469
+
470
+ ## Task context (DO NOT break this — the task must still work after conflict resolution)
471
+
472
+ Task: ${task.name}
473
+
474
+ Description:
475
+ ${task.description || '(no description provided)'}
476
+ ${context}
477
+
478
+ ## Merge conflicts
479
+
480
+ The following files have merge conflicts with conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...):
481
+ ${conflictFiles.map((f) => `- ${f}`).join('\n')}
482
+
483
+ ## Instructions
484
+
485
+ 1. Open each conflicting file and resolve the conflict markers
486
+ 2. Keep BOTH the task's changes AND the base branch updates where possible
487
+ 3. If the base branch changed something the task also changed, prefer the task's intent but make sure it works with the new base branch code
488
+ 4. Remove all conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...)
489
+ 5. Make sure the code compiles and is consistent after resolution
467
490
  6. Do NOT make any changes beyond what is needed to resolve the conflicts`;
468
491
  }
469
492
  async function resolveConflictsWithAI(task, config, provider, runners, context, hooks, vm, branchName) {
@@ -731,14 +754,14 @@ async function implementTask(task, branchName, branchExists, config, provider, r
731
754
  logger_1.logger.success(`Task implemented: branch ${branchName} pushed`);
732
755
  }
733
756
  function buildImplementPrompt(task, context) {
734
- return `You are implementing a software development task. Make the necessary code changes to complete the task described below.
735
-
736
- Task: ${task.name}
737
-
738
- Description:
739
- ${task.description || '(no description provided)'}
740
- ${context}
741
-
757
+ return `You are implementing a software development task. Make the necessary code changes to complete the task described below.
758
+
759
+ Task: ${task.name}
760
+
761
+ Description:
762
+ ${task.description || '(no description provided)'}
763
+ ${context}
764
+
742
765
  Please implement the required changes. Focus on correctness and follow the existing code style in the project.`;
743
766
  }
744
767
  async function analyzeAndPlan(task, context, runners) {
@@ -747,28 +770,28 @@ async function analyzeAndPlan(task, context, runners) {
747
770
  logger_1.logger.error('No AI runner available for task analysis');
748
771
  return null;
749
772
  }
750
- const analysisPrompt = `You are a senior software architect breaking down a development task into smaller, sequential implementation steps.
751
-
752
- Task name: ${task.name}
753
-
754
- Description:
755
- ${task.description || '(no description provided)'}
756
- ${context}
757
-
758
- Analyze this task and break it into smaller, independently implementable sub-tasks that should be executed sequentially. Each sub-task should be a coherent unit of work that can be committed separately.
759
-
760
- Respond with valid JSON only — no markdown fences, no extra text:
761
- {
762
- "instructions": "Detailed implementation instructions in markdown covering the full task — architecture decisions, key files to modify, edge cases to handle, testing approach",
763
- "subtasks": [
764
- {
765
- "id": 1,
766
- "title": "Short title for the sub-task",
767
- "description": "Detailed description of what to implement in this step, including specific files and functions to change"
768
- }
769
- ]
770
- }
771
-
773
+ const analysisPrompt = `You are a senior software architect breaking down a development task into smaller, sequential implementation steps.
774
+
775
+ Task name: ${task.name}
776
+
777
+ Description:
778
+ ${task.description || '(no description provided)'}
779
+ ${context}
780
+
781
+ Analyze this task and break it into smaller, independently implementable sub-tasks that should be executed sequentially. Each sub-task should be a coherent unit of work that can be committed separately.
782
+
783
+ Respond with valid JSON only — no markdown fences, no extra text:
784
+ {
785
+ "instructions": "Detailed implementation instructions in markdown covering the full task — architecture decisions, key files to modify, edge cases to handle, testing approach",
786
+ "subtasks": [
787
+ {
788
+ "id": 1,
789
+ "title": "Short title for the sub-task",
790
+ "description": "Detailed description of what to implement in this step, including specific files and functions to change"
791
+ }
792
+ ]
793
+ }
794
+
772
795
  Keep sub-tasks focused: 2-6 sub-tasks is ideal. Order them by dependency (foundation first).`;
773
796
  logger_1.logger.info('Analyzing task and creating implementation plan...');
774
797
  const result = await runner.run(analysisPrompt);
@@ -820,31 +843,31 @@ async function splitFailedSubtask(parentTask, plan, failedSubtask, runners) {
820
843
  const diagnostics = failedSubtask.lastError && failedSubtask.lastError !== '__git__'
821
844
  ? failedSubtask.lastError
822
845
  : '(no diagnostics captured)';
823
- const splitPrompt = `You are a senior software architect helping recover a stalled implementation step by splitting it into exactly two smaller, sequential sub-tasks.
824
-
825
- Overall task: ${parentTask.name}
826
- ${parentTask.description ? `\nTask description:\n${parentTask.description}\n` : ''}
827
- ## Surrounding plan
828
- ${siblings || '(no sibling sub-tasks)'}
829
-
830
- ## Failed sub-task
831
- ID: ${formatSubtaskId(failedSubtask.id)}
832
- Title: ${failedSubtask.title}
833
- Description: ${failedSubtask.description}
834
-
835
- ## Previous failure diagnostics
836
- ${diagnostics}
837
-
838
- Split the failed sub-task above into exactly two smaller, independently implementable sub-tasks that together achieve the original goal. Each new sub-task should be a coherent unit of work that can be committed separately, ordered by dependency (foundation first). Take the diagnostics into account so the split actually addresses what broke.
839
-
840
- Respond with valid JSON only — no markdown fences, no extra text:
841
- {
842
- "subtasks": [
843
- { "title": "Short title for the first new sub-task", "description": "Detailed description of what to implement in this step" },
844
- { "title": "Short title for the second new sub-task", "description": "Detailed description of what to implement in this step" }
845
- ]
846
- }
847
-
846
+ const splitPrompt = `You are a senior software architect helping recover a stalled implementation step by splitting it into exactly two smaller, sequential sub-tasks.
847
+
848
+ Overall task: ${parentTask.name}
849
+ ${parentTask.description ? `\nTask description:\n${parentTask.description}\n` : ''}
850
+ ## Surrounding plan
851
+ ${siblings || '(no sibling sub-tasks)'}
852
+
853
+ ## Failed sub-task
854
+ ID: ${formatSubtaskId(failedSubtask.id)}
855
+ Title: ${failedSubtask.title}
856
+ Description: ${failedSubtask.description}
857
+
858
+ ## Previous failure diagnostics
859
+ ${diagnostics}
860
+
861
+ Split the failed sub-task above into exactly two smaller, independently implementable sub-tasks that together achieve the original goal. Each new sub-task should be a coherent unit of work that can be committed separately, ordered by dependency (foundation first). Take the diagnostics into account so the split actually addresses what broke.
862
+
863
+ Respond with valid JSON only — no markdown fences, no extra text:
864
+ {
865
+ "subtasks": [
866
+ { "title": "Short title for the first new sub-task", "description": "Detailed description of what to implement in this step" },
867
+ { "title": "Short title for the second new sub-task", "description": "Detailed description of what to implement in this step" }
868
+ ]
869
+ }
870
+
848
871
  Exactly two entries — no more, no fewer.`;
849
872
  logger_1.logger.info(`Splitting failed sub-task ${formatSubtaskId(failedSubtask.id)} into two smaller steps...`);
850
873
  const result = await runner.run(splitPrompt);
@@ -899,20 +922,20 @@ async function executeSubTask(subtask, task, plan, config, runners, reviewContex
899
922
  const retrySection = previousError && previousError !== '__git__'
900
923
  ? `\n## Previous attempt failure diagnostics\nThis step failed on a previous attempt. Diagnostics below — please take them into account and avoid repeating the same failure.\n\n${previousError}\n`
901
924
  : '';
902
- const prompt = `You are implementing step ${subtask.id} of a multi-step task.
903
-
904
- Overall task: ${task.name}
905
- ${task.description ? `\nTask description:\n${task.description}` : ''}
906
-
907
- ## Full implementation instructions
908
- ${instructions}
909
- ${reviewContext || ''}${retrySection}
910
- ## Progress
911
- ${completedSteps || '(no steps completed yet)'}
912
-
913
- ## Current step: ${subtask.id}. ${subtask.title}
914
- ${subtask.description}
915
-
925
+ const prompt = `You are implementing step ${subtask.id} of a multi-step task.
926
+
927
+ Overall task: ${task.name}
928
+ ${task.description ? `\nTask description:\n${task.description}` : ''}
929
+
930
+ ## Full implementation instructions
931
+ ${instructions}
932
+ ${reviewContext || ''}${retrySection}
933
+ ## Progress
934
+ ${completedSteps || '(no steps completed yet)'}
935
+
936
+ ## Current step: ${subtask.id}. ${subtask.title}
937
+ ${subtask.description}
938
+
916
939
  Implement ONLY this step. Focus on correctness and follow the existing code style.`;
917
940
  let implemented = false;
918
941
  let previousNotes = '';
@@ -1199,29 +1222,29 @@ function buildCompletionComment(branch, prUrl, config) {
1199
1222
  function buildNonCodePrompt(task, context) {
1200
1223
  const hasComments = context.trim().length > 0;
1201
1224
  if (hasComments) {
1202
- return `Task: ${task.name}
1203
-
1204
- Original description:
1205
- ${task.description || '(no description provided)'}
1206
- ${context}
1207
-
1208
- ⚠️ CRITICAL: This is a FOLLOW-UP request. The conversation above contains new comments from the user.
1209
- YOUR PRIMARY TASK is to address the LATEST comment at the bottom of the conversation - this is the user's current request.
1210
- The latest comment may:
1211
- - Ask for something completely different from the original task
1212
- - Request modifications to what was already done
1213
- - Add new requirements
1214
-
1215
- DO NOT repeat what was already done. DO NOT re-execute the original task unless explicitly asked.
1216
- Focus ENTIRELY on addressing the latest comment as your main instruction.
1217
-
1225
+ return `Task: ${task.name}
1226
+
1227
+ Original description:
1228
+ ${task.description || '(no description provided)'}
1229
+ ${context}
1230
+
1231
+ ⚠️ CRITICAL: This is a FOLLOW-UP request. The conversation above contains new comments from the user.
1232
+ YOUR PRIMARY TASK is to address the LATEST comment at the bottom of the conversation - this is the user's current request.
1233
+ The latest comment may:
1234
+ - Ask for something completely different from the original task
1235
+ - Request modifications to what was already done
1236
+ - Add new requirements
1237
+
1238
+ DO NOT repeat what was already done. DO NOT re-execute the original task unless explicitly asked.
1239
+ Focus ENTIRELY on addressing the latest comment as your main instruction.
1240
+
1218
1241
  Please provide a clear, detailed response to the LATEST comment. Your response will be posted as a comment on the task ticket, so write it as a direct answer or explanation addressed to the person who wrote the latest comment.`;
1219
1242
  }
1220
- return `Task: ${task.name}
1221
-
1222
- Description:
1223
- ${task.description || '(no description provided)'}
1224
-
1243
+ return `Task: ${task.name}
1244
+
1245
+ Description:
1246
+ ${task.description || '(no description provided)'}
1247
+
1225
1248
  Please provide a clear, detailed response to this task. Your response will be posted as a comment on the task ticket, so write it as a direct answer or explanation addressed to the person who created the task.`;
1226
1249
  }
1227
1250
  function buildNonCodeCompletionComment(config, agentResponse) {
@@ -1252,10 +1275,10 @@ function buildNonCodeCompletionComment(config, agentResponse) {
1252
1275
  return lines.join('\n');
1253
1276
  }
1254
1277
  function hasAidevComment(comments, commentPrefix = '[aidev]') {
1255
- return comments.some((c) => c.text.includes(commentPrefix));
1278
+ return comments.some((c) => isAidevComment(c.text, commentPrefix));
1256
1279
  }
1257
1280
  function filterAutomatedComments(comments, commentPrefix = '[aidev]') {
1258
- return comments.filter((c) => !c.text.includes(commentPrefix));
1281
+ return comments.filter((c) => !isAidevComment(c.text, commentPrefix));
1259
1282
  }
1260
1283
  async function buildConversationContext(taskId, comments, config, runners) {
1261
1284
  const humanComments = filterAutomatedComments(comments, config.commentPrefix);
@@ -1531,22 +1554,22 @@ async function implementReviewTask(task, branchName, config, provider, runners,
1531
1554
  logger_1.logger.success(`Review comments addressed for: ${task.name}`);
1532
1555
  }
1533
1556
  function buildReviewPrompt(task, threads) {
1534
- let prompt = `You are addressing code review comments on a pull request for a software development task.
1535
-
1536
- Task: ${task.name}
1537
-
1538
- Description:
1539
- ${task.description || '(no description provided)'}
1540
-
1541
- ## Unresolved Code Review Threads
1542
-
1543
- The following review threads need to be addressed. For each thread, either:
1544
- - Fix the code as requested (make the changes directly in the files)
1545
- - Or, if it's a discussion/question that doesn't require code changes, output a REPLY block:
1546
- <!-- AIDEV-REPLY thread_id -->Your reply here<!-- /AIDEV-REPLY -->
1547
-
1548
- Replace "thread_id" with the actual thread ID shown below.
1549
-
1557
+ let prompt = `You are addressing code review comments on a pull request for a software development task.
1558
+
1559
+ Task: ${task.name}
1560
+
1561
+ Description:
1562
+ ${task.description || '(no description provided)'}
1563
+
1564
+ ## Unresolved Code Review Threads
1565
+
1566
+ The following review threads need to be addressed. For each thread, either:
1567
+ - Fix the code as requested (make the changes directly in the files)
1568
+ - Or, if it's a discussion/question that doesn't require code changes, output a REPLY block:
1569
+ <!-- AIDEV-REPLY thread_id -->Your reply here<!-- /AIDEV-REPLY -->
1570
+
1571
+ Replace "thread_id" with the actual thread ID shown below.
1572
+
1550
1573
  `;
1551
1574
  for (const thread of threads) {
1552
1575
  const location = thread.line
@@ -1558,12 +1581,12 @@ Replace "thread_id" with the actual thread ID shown below.
1558
1581
  }
1559
1582
  prompt += '\n';
1560
1583
  }
1561
- prompt += `## Instructions
1562
-
1563
- 1. Read each review thread carefully
1564
- 2. For code change requests: make the fix directly in the relevant file(s)
1565
- 3. For questions or discussions: output a REPLY block with a clear, helpful response
1566
- 4. You may handle multiple threads — some with code fixes, others with replies
1584
+ prompt += `## Instructions
1585
+
1586
+ 1. Read each review thread carefully
1587
+ 2. For code change requests: make the fix directly in the relevant file(s)
1588
+ 3. For questions or discussions: output a REPLY block with a clear, helpful response
1589
+ 4. You may handle multiple threads — some with code fixes, others with replies
1567
1590
  5. Focus on correctness and follow the existing code style`;
1568
1591
  return prompt;
1569
1592
  }