patterns.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. export interface DelegateTaskErrorPattern {
  2. pattern: string;
  3. errorType: string;
  4. fixHint: string;
  5. }
  6. export const DELEGATE_TASK_ERROR_PATTERNS: DelegateTaskErrorPattern[] = [
  7. {
  8. pattern: 'run_in_background',
  9. errorType: 'missing_run_in_background',
  10. fixHint:
  11. 'Add run_in_background=false (delegation) or run_in_background=true (parallel exploration).',
  12. },
  13. {
  14. pattern: 'load_skills',
  15. errorType: 'missing_load_skills',
  16. fixHint: 'Add load_skills=[] (empty array when no skill is needed).',
  17. },
  18. {
  19. pattern: 'category OR subagent_type',
  20. errorType: 'mutual_exclusion',
  21. fixHint:
  22. 'Provide only one: category (e.g., "unspecified-low") OR subagent_type (e.g., "explorer").',
  23. },
  24. {
  25. pattern: 'Must provide either category or subagent_type',
  26. errorType: 'missing_category_or_agent',
  27. fixHint:
  28. 'Add either category="unspecified-low" or subagent_type="explorer".',
  29. },
  30. {
  31. pattern: 'Unknown category',
  32. errorType: 'unknown_category',
  33. fixHint: 'Use a valid category listed in the error output.',
  34. },
  35. {
  36. pattern: 'Unknown agent',
  37. errorType: 'unknown_agent',
  38. fixHint: 'Use a valid agent name from the available list.',
  39. },
  40. {
  41. pattern: 'Skills not found',
  42. errorType: 'unknown_skills',
  43. fixHint: 'Use valid skill names listed in the error output.',
  44. },
  45. {
  46. pattern: 'is not allowed. Allowed agents:',
  47. errorType: 'background_agent_not_allowed',
  48. fixHint:
  49. 'Use one of the allowed agents shown in the error or delegate from a parent agent that can call this subagent.',
  50. },
  51. ];
  52. export interface DetectedError {
  53. errorType: string;
  54. originalOutput: string;
  55. }
  56. export function detectDelegateTaskError(output: string): DetectedError | null {
  57. if (!output || typeof output !== 'string') return null;
  58. const hasErrorSignal =
  59. output.includes('[ERROR]') ||
  60. output.includes('Invalid arguments') ||
  61. output.includes('is not allowed. Allowed agents:');
  62. if (!hasErrorSignal) return null;
  63. for (const pattern of DELEGATE_TASK_ERROR_PATTERNS) {
  64. if (output.includes(pattern.pattern)) {
  65. return {
  66. errorType: pattern.errorType,
  67. originalOutput: output,
  68. };
  69. }
  70. }
  71. return null;
  72. }