@qelos/aidev 0.7.3 → 0.7.5

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;
@@ -59,6 +60,7 @@ exports.buildNonCodePrompt = buildNonCodePrompt;
59
60
  exports.buildNonCodeCompletionComment = buildNonCodeCompletionComment;
60
61
  exports.hasAidevComment = hasAidevComment;
61
62
  exports.filterAutomatedComments = filterAutomatedComments;
63
+ exports.hasHumanComment = hasHumanComment;
62
64
  exports.parseReplyDirectives = parseReplyDirectives;
63
65
  exports.buildReviewPrompt = buildReviewPrompt;
64
66
  exports.buildReviewCompletionComment = buildReviewCompletionComment;
@@ -309,14 +311,14 @@ async function processTask(task, filter, config, provider, runners, screenAvaila
309
311
  const comments = await provider.getComments(task.id);
310
312
  const trigger = hasTriggerWord(comments, config.triggerWord);
311
313
  if (isPending) {
312
- const reply = hasHumanReply(comments, config.commentPrefix);
313
- if (!reply && !trigger) {
314
- logger_1.logger.info(`[${task.id}] "${task.name}" skipped — pending task has no human reply or trigger word ("${config.triggerWord}")`);
314
+ const hasHumanFollowUp = hasHumanComment(comments, config.commentPrefix);
315
+ if (!hasHumanFollowUp && !trigger) {
316
+ logger_1.logger.info(`[${task.id}] "${task.name}" skipped — pending task has no human comment or trigger word ("${config.triggerWord}")`);
315
317
  return 'skipped';
316
318
  }
317
319
  logger_1.logger.info(trigger
318
320
  ? `Trigger word "${config.triggerWord}" found — re-processing pending task`
319
- : 'Pending task has a human reply — proceeding');
321
+ : 'Pending task has a human comment — proceeding');
320
322
  }
321
323
  else {
322
324
  if (!trigger) {
@@ -351,11 +353,33 @@ async function processTask(task, filter, config, provider, runners, screenAvaila
351
353
  }
352
354
  return 'processed';
353
355
  }
356
+ function isAidevComment(text, commentPrefix = '[aidev]') {
357
+ return text.trimStart().startsWith(commentPrefix);
358
+ }
359
+ /**
360
+ * True when someone other than aidev spoke after an aidev message: there is a non-aidev
361
+ * comment that has at least one earlier [aidev]-prefixed comment in the thread.
362
+ * Ignores trailing aidev-only noise after the human (e.g. another bot post or sync).
363
+ */
354
364
  function hasHumanReply(comments, commentPrefix = '[aidev]') {
355
- if (comments.length < 2)
365
+ if (comments.length === 0)
366
+ return false;
367
+ let lastNonAidevIndex = -1;
368
+ for (let i = comments.length - 1; i >= 0; i--) {
369
+ if (!isAidevComment(comments[i].text, commentPrefix)) {
370
+ lastNonAidevIndex = i;
371
+ break;
372
+ }
373
+ }
374
+ if (lastNonAidevIndex === -1) {
356
375
  return false;
357
- const lastComment = comments[comments.length - 1];
358
- return !lastComment.text.includes(commentPrefix);
376
+ }
377
+ for (let j = lastNonAidevIndex - 1; j >= 0; j--) {
378
+ if (isAidevComment(comments[j].text, commentPrefix)) {
379
+ return true;
380
+ }
381
+ }
382
+ return false;
359
383
  }
360
384
  /**
361
385
  * Returns true if the last comment contains the trigger word.
@@ -403,16 +427,16 @@ async function checkNeedsClarification(task, config, provider, runners) {
403
427
  logger_1.logger.warn('No AI runner available — skipping clarification check');
404
428
  return null;
405
429
  }
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"
430
+ const clarificationPrompt = `You are a senior software developer reviewing a task.
431
+ Determine if the following task has enough information to implement without further clarification.
432
+
433
+ Task name: ${task.name}
434
+ Task description: ${task.description || '(no description)'}
435
+
436
+ Respond with valid JSON only:
437
+ {
438
+ "clear": true|false,
439
+ "question": "question to ask if not clear, or null"
416
440
  }`;
417
441
  for (const runner of availableRunners) {
418
442
  const result = await runner.run(clarificationPrompt);
@@ -440,30 +464,30 @@ Respond with valid JSON only:
440
464
  return null;
441
465
  }
442
466
  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
467
+ return `You are resolving merge conflicts in a software development task branch.
468
+
469
+ The task branch has fallen behind the base branch and has merge conflicts that need to be resolved.
470
+
471
+ ## Task context (DO NOT break this — the task must still work after conflict resolution)
472
+
473
+ Task: ${task.name}
474
+
475
+ Description:
476
+ ${task.description || '(no description provided)'}
477
+ ${context}
478
+
479
+ ## Merge conflicts
480
+
481
+ The following files have merge conflicts with conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...):
482
+ ${conflictFiles.map((f) => `- ${f}`).join('\n')}
483
+
484
+ ## Instructions
485
+
486
+ 1. Open each conflicting file and resolve the conflict markers
487
+ 2. Keep BOTH the task's changes AND the base branch updates where possible
488
+ 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
489
+ 4. Remove all conflict markers (<<<<<<< HEAD, =======, >>>>>>> ...)
490
+ 5. Make sure the code compiles and is consistent after resolution
467
491
  6. Do NOT make any changes beyond what is needed to resolve the conflicts`;
468
492
  }
469
493
  async function resolveConflictsWithAI(task, config, provider, runners, context, hooks, vm, branchName) {
@@ -731,14 +755,14 @@ async function implementTask(task, branchName, branchExists, config, provider, r
731
755
  logger_1.logger.success(`Task implemented: branch ${branchName} pushed`);
732
756
  }
733
757
  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
-
758
+ return `You are implementing a software development task. Make the necessary code changes to complete the task described below.
759
+
760
+ Task: ${task.name}
761
+
762
+ Description:
763
+ ${task.description || '(no description provided)'}
764
+ ${context}
765
+
742
766
  Please implement the required changes. Focus on correctness and follow the existing code style in the project.`;
743
767
  }
744
768
  async function analyzeAndPlan(task, context, runners) {
@@ -747,28 +771,28 @@ async function analyzeAndPlan(task, context, runners) {
747
771
  logger_1.logger.error('No AI runner available for task analysis');
748
772
  return null;
749
773
  }
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
-
774
+ const analysisPrompt = `You are a senior software architect breaking down a development task into smaller, sequential implementation steps.
775
+
776
+ Task name: ${task.name}
777
+
778
+ Description:
779
+ ${task.description || '(no description provided)'}
780
+ ${context}
781
+
782
+ 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.
783
+
784
+ Respond with valid JSON only — no markdown fences, no extra text:
785
+ {
786
+ "instructions": "Detailed implementation instructions in markdown covering the full task — architecture decisions, key files to modify, edge cases to handle, testing approach",
787
+ "subtasks": [
788
+ {
789
+ "id": 1,
790
+ "title": "Short title for the sub-task",
791
+ "description": "Detailed description of what to implement in this step, including specific files and functions to change"
792
+ }
793
+ ]
794
+ }
795
+
772
796
  Keep sub-tasks focused: 2-6 sub-tasks is ideal. Order them by dependency (foundation first).`;
773
797
  logger_1.logger.info('Analyzing task and creating implementation plan...');
774
798
  const result = await runner.run(analysisPrompt);
@@ -820,31 +844,31 @@ async function splitFailedSubtask(parentTask, plan, failedSubtask, runners) {
820
844
  const diagnostics = failedSubtask.lastError && failedSubtask.lastError !== '__git__'
821
845
  ? failedSubtask.lastError
822
846
  : '(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
-
847
+ const splitPrompt = `You are a senior software architect helping recover a stalled implementation step by splitting it into exactly two smaller, sequential sub-tasks.
848
+
849
+ Overall task: ${parentTask.name}
850
+ ${parentTask.description ? `\nTask description:\n${parentTask.description}\n` : ''}
851
+ ## Surrounding plan
852
+ ${siblings || '(no sibling sub-tasks)'}
853
+
854
+ ## Failed sub-task
855
+ ID: ${formatSubtaskId(failedSubtask.id)}
856
+ Title: ${failedSubtask.title}
857
+ Description: ${failedSubtask.description}
858
+
859
+ ## Previous failure diagnostics
860
+ ${diagnostics}
861
+
862
+ 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.
863
+
864
+ Respond with valid JSON only — no markdown fences, no extra text:
865
+ {
866
+ "subtasks": [
867
+ { "title": "Short title for the first new sub-task", "description": "Detailed description of what to implement in this step" },
868
+ { "title": "Short title for the second new sub-task", "description": "Detailed description of what to implement in this step" }
869
+ ]
870
+ }
871
+
848
872
  Exactly two entries — no more, no fewer.`;
849
873
  logger_1.logger.info(`Splitting failed sub-task ${formatSubtaskId(failedSubtask.id)} into two smaller steps...`);
850
874
  const result = await runner.run(splitPrompt);
@@ -899,20 +923,20 @@ async function executeSubTask(subtask, task, plan, config, runners, reviewContex
899
923
  const retrySection = previousError && previousError !== '__git__'
900
924
  ? `\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
925
  : '';
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
-
926
+ const prompt = `You are implementing step ${subtask.id} of a multi-step task.
927
+
928
+ Overall task: ${task.name}
929
+ ${task.description ? `\nTask description:\n${task.description}` : ''}
930
+
931
+ ## Full implementation instructions
932
+ ${instructions}
933
+ ${reviewContext || ''}${retrySection}
934
+ ## Progress
935
+ ${completedSteps || '(no steps completed yet)'}
936
+
937
+ ## Current step: ${subtask.id}. ${subtask.title}
938
+ ${subtask.description}
939
+
916
940
  Implement ONLY this step. Focus on correctness and follow the existing code style.`;
917
941
  let implemented = false;
918
942
  let previousNotes = '';
@@ -1199,29 +1223,29 @@ function buildCompletionComment(branch, prUrl, config) {
1199
1223
  function buildNonCodePrompt(task, context) {
1200
1224
  const hasComments = context.trim().length > 0;
1201
1225
  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
-
1226
+ return `Task: ${task.name}
1227
+
1228
+ Original description:
1229
+ ${task.description || '(no description provided)'}
1230
+ ${context}
1231
+
1232
+ ⚠️ CRITICAL: This is a FOLLOW-UP request. The conversation above contains new comments from the user.
1233
+ YOUR PRIMARY TASK is to address the LATEST comment at the bottom of the conversation - this is the user's current request.
1234
+ The latest comment may:
1235
+ - Ask for something completely different from the original task
1236
+ - Request modifications to what was already done
1237
+ - Add new requirements
1238
+
1239
+ DO NOT repeat what was already done. DO NOT re-execute the original task unless explicitly asked.
1240
+ Focus ENTIRELY on addressing the latest comment as your main instruction.
1241
+
1218
1242
  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
1243
  }
1220
- return `Task: ${task.name}
1221
-
1222
- Description:
1223
- ${task.description || '(no description provided)'}
1224
-
1244
+ return `Task: ${task.name}
1245
+
1246
+ Description:
1247
+ ${task.description || '(no description provided)'}
1248
+
1225
1249
  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
1250
  }
1227
1251
  function buildNonCodeCompletionComment(config, agentResponse) {
@@ -1252,10 +1276,13 @@ function buildNonCodeCompletionComment(config, agentResponse) {
1252
1276
  return lines.join('\n');
1253
1277
  }
1254
1278
  function hasAidevComment(comments, commentPrefix = '[aidev]') {
1255
- return comments.some((c) => c.text.includes(commentPrefix));
1279
+ return comments.some((c) => isAidevComment(c.text, commentPrefix));
1256
1280
  }
1257
1281
  function filterAutomatedComments(comments, commentPrefix = '[aidev]') {
1258
- return comments.filter((c) => !c.text.includes(commentPrefix));
1282
+ return comments.filter((c) => !isAidevComment(c.text, commentPrefix));
1283
+ }
1284
+ function hasHumanComment(comments, commentPrefix = '[aidev]') {
1285
+ return comments.some((c) => !isAidevComment(c.text, commentPrefix));
1259
1286
  }
1260
1287
  async function buildConversationContext(taskId, comments, config, runners) {
1261
1288
  const humanComments = filterAutomatedComments(comments, config.commentPrefix);
@@ -1288,14 +1315,14 @@ async function processNonCodeTask(task, filter, config, provider, runners, scree
1288
1315
  const trigger = hasTriggerWord(comments, config.triggerWord);
1289
1316
  const hasHumanFollowUp = hasHumanReply(comments, config.commentPrefix);
1290
1317
  if (isPending) {
1291
- const reply = hasHumanReply(comments, config.commentPrefix);
1292
- if (!reply && !trigger) {
1293
- logger_1.logger.info(`[${task.id}] "${task.name}" skipped — pending with no human reply or trigger word ("${config.triggerWord}")`);
1318
+ const hasHumanCommentForPending = hasHumanComment(comments, config.commentPrefix);
1319
+ if (!hasHumanCommentForPending && !trigger) {
1320
+ logger_1.logger.info(`[${task.id}] "${task.name}" skipped — pending with no human comment or trigger word ("${config.triggerWord}")`);
1294
1321
  return 'skipped';
1295
1322
  }
1296
1323
  logger_1.logger.info(trigger
1297
1324
  ? `Trigger word "${config.triggerWord}" found — re-processing non-code task`
1298
- : 'Pending non-code task has a human reply — proceeding');
1325
+ : 'Pending non-code task has a human comment — proceeding');
1299
1326
  }
1300
1327
  else {
1301
1328
  // For already processed tasks, check if there's a human follow-up or trigger word
@@ -1531,22 +1558,22 @@ async function implementReviewTask(task, branchName, config, provider, runners,
1531
1558
  logger_1.logger.success(`Review comments addressed for: ${task.name}`);
1532
1559
  }
1533
1560
  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
-
1561
+ let prompt = `You are addressing code review comments on a pull request for a software development task.
1562
+
1563
+ Task: ${task.name}
1564
+
1565
+ Description:
1566
+ ${task.description || '(no description provided)'}
1567
+
1568
+ ## Unresolved Code Review Threads
1569
+
1570
+ The following review threads need to be addressed. For each thread, either:
1571
+ - Fix the code as requested (make the changes directly in the files)
1572
+ - Or, if it's a discussion/question that doesn't require code changes, output a REPLY block:
1573
+ <!-- AIDEV-REPLY thread_id -->Your reply here<!-- /AIDEV-REPLY -->
1574
+
1575
+ Replace "thread_id" with the actual thread ID shown below.
1576
+
1550
1577
  `;
1551
1578
  for (const thread of threads) {
1552
1579
  const location = thread.line
@@ -1558,12 +1585,12 @@ Replace "thread_id" with the actual thread ID shown below.
1558
1585
  }
1559
1586
  prompt += '\n';
1560
1587
  }
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
1588
+ prompt += `## Instructions
1589
+
1590
+ 1. Read each review thread carefully
1591
+ 2. For code change requests: make the fix directly in the relevant file(s)
1592
+ 3. For questions or discussions: output a REPLY block with a clear, helpful response
1593
+ 4. You may handle multiple threads — some with code fixes, others with replies
1567
1594
  5. Focus on correctness and follow the existing code style`;
1568
1595
  return prompt;
1569
1596
  }