claude-code-workflow 6.3.26 → 6.3.28

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.
Files changed (129) hide show
  1. package/.claude/CLAUDE.md +7 -1
  2. package/.claude/agents/action-planning-agent.md +1 -0
  3. package/.claude/agents/cli-discuss-agent.md +391 -0
  4. package/.claude/agents/cli-execution-agent.md +2 -0
  5. package/.claude/agents/cli-explore-agent.md +2 -1
  6. package/.claude/agents/cli-lite-planning-agent.md +1 -0
  7. package/.claude/agents/cli-planning-agent.md +1 -0
  8. package/.claude/agents/code-developer.md +1 -0
  9. package/.claude/agents/conceptual-planning-agent.md +2 -0
  10. package/.claude/agents/context-search-agent.md +1 -0
  11. package/.claude/agents/debug-explore-agent.md +2 -0
  12. package/.claude/agents/doc-generator.md +1 -0
  13. package/.claude/agents/issue-plan-agent.md +2 -1
  14. package/.claude/agents/issue-queue-agent.md +2 -1
  15. package/.claude/agents/memory-bridge.md +2 -0
  16. package/.claude/agents/test-context-search-agent.md +2 -0
  17. package/.claude/agents/test-fix-agent.md +1 -0
  18. package/.claude/agents/ui-design-agent.md +2 -0
  19. package/.claude/agents/universal-executor.md +1 -0
  20. package/.claude/commands/issue/execute.md +141 -163
  21. package/.claude/commands/workflow/lite-lite-lite.md +798 -0
  22. package/.claude/commands/workflow/multi-cli-plan.md +510 -0
  23. package/.claude/skills/ccw/SKILL.md +262 -372
  24. package/.claude/skills/ccw/command.json +547 -0
  25. package/.claude/skills/ccw-help/SKILL.md +46 -107
  26. package/.claude/skills/ccw-help/command.json +511 -0
  27. package/.claude/skills/skill-tuning/SKILL.md +303 -0
  28. package/.claude/skills/skill-tuning/phases/actions/action-abort.md +164 -0
  29. package/.claude/skills/skill-tuning/phases/actions/action-analyze-requirements.md +406 -0
  30. package/.claude/skills/skill-tuning/phases/actions/action-apply-fix.md +206 -0
  31. package/.claude/skills/skill-tuning/phases/actions/action-complete.md +195 -0
  32. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-agent.md +317 -0
  33. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-context.md +243 -0
  34. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-dataflow.md +318 -0
  35. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-docs.md +299 -0
  36. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-memory.md +269 -0
  37. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-token-consumption.md +200 -0
  38. package/.claude/skills/skill-tuning/phases/actions/action-gemini-analysis.md +322 -0
  39. package/.claude/skills/skill-tuning/phases/actions/action-generate-report.md +228 -0
  40. package/.claude/skills/skill-tuning/phases/actions/action-init.md +149 -0
  41. package/.claude/skills/skill-tuning/phases/actions/action-propose-fixes.md +317 -0
  42. package/.claude/skills/skill-tuning/phases/actions/action-verify.md +222 -0
  43. package/.claude/skills/skill-tuning/phases/orchestrator.md +377 -0
  44. package/.claude/skills/skill-tuning/phases/state-schema.md +378 -0
  45. package/.claude/skills/skill-tuning/specs/category-mappings.json +284 -0
  46. package/.claude/skills/skill-tuning/specs/dimension-mapping.md +212 -0
  47. package/.claude/skills/skill-tuning/specs/problem-taxonomy.md +318 -0
  48. package/.claude/skills/skill-tuning/specs/quality-gates.md +263 -0
  49. package/.claude/skills/skill-tuning/specs/skill-authoring-principles.md +189 -0
  50. package/.claude/skills/skill-tuning/specs/tuning-strategies.md +1537 -0
  51. package/.claude/skills/skill-tuning/templates/diagnosis-report.md +153 -0
  52. package/.claude/skills/skill-tuning/templates/fix-proposal.md +204 -0
  53. package/.claude/workflows/cli-templates/schemas/multi-cli-discussion-schema.json +421 -0
  54. package/.claude/workflows/cli-tools-usage.md +0 -41
  55. package/ccw/dist/core/auth/csrf-middleware.d.ts.map +1 -1
  56. package/ccw/dist/core/auth/csrf-middleware.js +3 -1
  57. package/ccw/dist/core/auth/csrf-middleware.js.map +1 -1
  58. package/ccw/dist/core/data-aggregator.d.ts +2 -0
  59. package/ccw/dist/core/data-aggregator.d.ts.map +1 -1
  60. package/ccw/dist/core/data-aggregator.js +5 -2
  61. package/ccw/dist/core/data-aggregator.js.map +1 -1
  62. package/ccw/dist/core/lite-scanner.d.ts +2 -1
  63. package/ccw/dist/core/lite-scanner.d.ts.map +1 -1
  64. package/ccw/dist/core/lite-scanner.js +295 -6
  65. package/ccw/dist/core/lite-scanner.js.map +1 -1
  66. package/ccw/dist/core/routes/codexlens/config-handlers.d.ts.map +1 -1
  67. package/ccw/dist/core/routes/codexlens/config-handlers.js +5 -5
  68. package/ccw/dist/core/routes/codexlens/config-handlers.js.map +1 -1
  69. package/ccw/dist/core/routes/session-routes.d.ts.map +1 -1
  70. package/ccw/dist/core/routes/session-routes.js +166 -48
  71. package/ccw/dist/core/routes/session-routes.js.map +1 -1
  72. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
  73. package/ccw/dist/core/routes/system-routes.js +87 -0
  74. package/ccw/dist/core/routes/system-routes.js.map +1 -1
  75. package/ccw/dist/core/server.js +2 -2
  76. package/ccw/dist/core/server.js.map +1 -1
  77. package/ccw/scripts/IMPLEMENTATION-SUMMARY.md +226 -0
  78. package/ccw/scripts/QUICK-REFERENCE.md +135 -0
  79. package/ccw/scripts/README-memory-embedder.md +157 -0
  80. package/ccw/scripts/__pycache__/memory_embedder.cpython-313.pyc +0 -0
  81. package/ccw/scripts/__pycache__/test_memory_embedder.cpython-313-pytest-8.4.2.pyc +0 -0
  82. package/ccw/scripts/memory-embedder-example.ts +184 -0
  83. package/ccw/scripts/memory_embedder.py +428 -0
  84. package/ccw/scripts/test_memory_embedder.py +245 -0
  85. package/ccw/src/core/auth/csrf-middleware.ts +3 -1
  86. package/ccw/src/core/data-aggregator.ts +7 -2
  87. package/ccw/src/core/lite-scanner.ts +440 -6
  88. package/ccw/src/core/routes/codexlens/config-handlers.ts +12 -9
  89. package/ccw/src/core/routes/session-routes.ts +201 -48
  90. package/ccw/src/core/routes/system-routes.ts +102 -0
  91. package/ccw/src/core/server.ts +2 -2
  92. package/ccw/src/templates/dashboard-css/01-base.css +8 -0
  93. package/ccw/src/templates/dashboard-css/02-session.css +81 -0
  94. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +2442 -0
  95. package/ccw/src/templates/dashboard-css/21-cli-toolmgmt.css +157 -0
  96. package/ccw/src/templates/dashboard-css/32-issue-manager.css +23 -0
  97. package/ccw/src/templates/dashboard-js/components/cli-stream-viewer.js +38 -4
  98. package/ccw/src/templates/dashboard-js/components/hook-manager.js +38 -13
  99. package/ccw/src/templates/dashboard-js/components/navigation.js +24 -4
  100. package/ccw/src/templates/dashboard-js/i18n.js +194 -6
  101. package/ccw/src/templates/dashboard-js/views/api-settings.js +32 -0
  102. package/ccw/src/templates/dashboard-js/views/claude-manager.js +44 -3
  103. package/ccw/src/templates/dashboard-js/views/cli-manager.js +303 -31
  104. package/ccw/src/templates/dashboard-js/views/history.js +44 -6
  105. package/ccw/src/templates/dashboard-js/views/home.js +1 -0
  106. package/ccw/src/templates/dashboard-js/views/issue-manager.js +54 -7
  107. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +1817 -4
  108. package/ccw/src/templates/dashboard.html +5 -0
  109. package/package.json +2 -1
  110. package/.claude/skills/ccw/index/command-capabilities.json +0 -127
  111. package/.claude/skills/ccw/index/intent-rules.json +0 -136
  112. package/.claude/skills/ccw/index/workflow-chains.json +0 -451
  113. package/.claude/skills/ccw/phases/actions/bugfix.md +0 -218
  114. package/.claude/skills/ccw/phases/actions/coupled.md +0 -194
  115. package/.claude/skills/ccw/phases/actions/docs.md +0 -93
  116. package/.claude/skills/ccw/phases/actions/full.md +0 -154
  117. package/.claude/skills/ccw/phases/actions/issue.md +0 -201
  118. package/.claude/skills/ccw/phases/actions/rapid.md +0 -104
  119. package/.claude/skills/ccw/phases/actions/review-fix.md +0 -84
  120. package/.claude/skills/ccw/phases/actions/tdd.md +0 -66
  121. package/.claude/skills/ccw/phases/actions/ui.md +0 -79
  122. package/.claude/skills/ccw/phases/orchestrator.md +0 -435
  123. package/.claude/skills/ccw/specs/intent-classification.md +0 -336
  124. package/.claude/skills/ccw-help/index/all-agents.json +0 -82
  125. package/.claude/skills/ccw-help/index/all-commands.json +0 -882
  126. package/.claude/skills/ccw-help/index/by-category.json +0 -914
  127. package/.claude/skills/ccw-help/index/by-use-case.json +0 -896
  128. package/.claude/skills/ccw-help/index/command-relationships.json +0 -160
  129. package/.claude/skills/ccw-help/index/essential-commands.json +0 -112
@@ -0,0 +1,195 @@
1
+ # Action: Complete
2
+
3
+ Finalize the tuning session with summary report and cleanup.
4
+
5
+ ## Purpose
6
+
7
+ - Generate final summary report
8
+ - Record tuning statistics
9
+ - Clean up temporary files (optional)
10
+ - Provide recommendations for future maintenance
11
+
12
+ ## Preconditions
13
+
14
+ - [ ] state.status === 'running'
15
+ - [ ] quality_gate === 'pass' OR max_iterations reached
16
+
17
+ ## Execution
18
+
19
+ ```javascript
20
+ async function execute(state, workDir) {
21
+ console.log('Finalizing skill tuning session...');
22
+
23
+ const targetSkill = state.target_skill;
24
+ const startTime = new Date(state.started_at);
25
+ const endTime = new Date();
26
+ const duration = Math.round((endTime - startTime) / 1000);
27
+
28
+ // Generate final summary
29
+ const summary = `# Skill Tuning Summary
30
+
31
+ **Target Skill**: ${targetSkill.name}
32
+ **Path**: ${targetSkill.path}
33
+ **Session Duration**: ${duration} seconds
34
+ **Completed**: ${endTime.toISOString()}
35
+
36
+ ---
37
+
38
+ ## Final Status
39
+
40
+ | Metric | Value |
41
+ |--------|-------|
42
+ | Final Health Score | ${state.quality_score}/100 |
43
+ | Quality Gate | ${state.quality_gate.toUpperCase()} |
44
+ | Total Iterations | ${state.iteration_count} |
45
+ | Issues Found | ${state.issues.length + state.applied_fixes.flatMap(f => f.issues_resolved || []).length} |
46
+ | Issues Resolved | ${state.applied_fixes.flatMap(f => f.issues_resolved || []).length} |
47
+ | Fixes Applied | ${state.applied_fixes.length} |
48
+ | Fixes Verified | ${state.applied_fixes.filter(f => f.verification_result === 'pass').length} |
49
+
50
+ ---
51
+
52
+ ## Diagnosis Summary
53
+
54
+ | Area | Issues Found | Severity |
55
+ |------|--------------|----------|
56
+ | Context Explosion | ${state.diagnosis.context?.issues_found || 'N/A'} | ${state.diagnosis.context?.severity || 'N/A'} |
57
+ | Long-tail Forgetting | ${state.diagnosis.memory?.issues_found || 'N/A'} | ${state.diagnosis.memory?.severity || 'N/A'} |
58
+ | Data Flow | ${state.diagnosis.dataflow?.issues_found || 'N/A'} | ${state.diagnosis.dataflow?.severity || 'N/A'} |
59
+ | Agent Coordination | ${state.diagnosis.agent?.issues_found || 'N/A'} | ${state.diagnosis.agent?.severity || 'N/A'} |
60
+
61
+ ---
62
+
63
+ ## Applied Fixes
64
+
65
+ ${state.applied_fixes.length === 0 ? '_No fixes applied_' :
66
+ state.applied_fixes.map((fix, i) => `
67
+ ### ${i + 1}. ${fix.fix_id}
68
+
69
+ - **Applied At**: ${fix.applied_at}
70
+ - **Success**: ${fix.success ? 'Yes' : 'No'}
71
+ - **Verification**: ${fix.verification_result}
72
+ - **Rollback Available**: ${fix.rollback_available ? 'Yes' : 'No'}
73
+ `).join('\n')}
74
+
75
+ ---
76
+
77
+ ## Remaining Issues
78
+
79
+ ${state.issues.length === 0 ? '✅ All issues resolved!' :
80
+ `${state.issues.length} issues remain:\n\n` +
81
+ state.issues.map(issue =>
82
+ `- **[${issue.severity.toUpperCase()}]** ${issue.description} (${issue.id})`
83
+ ).join('\n')}
84
+
85
+ ---
86
+
87
+ ## Recommendations
88
+
89
+ ${generateRecommendations(state)}
90
+
91
+ ---
92
+
93
+ ## Backup Information
94
+
95
+ Original skill files backed up to:
96
+ \`${state.backup_dir}\`
97
+
98
+ To restore original skill:
99
+ \`\`\`bash
100
+ cp -r "${state.backup_dir}/${targetSkill.name}-backup"/* "${targetSkill.path}/"
101
+ \`\`\`
102
+
103
+ ---
104
+
105
+ ## Session Files
106
+
107
+ | File | Description |
108
+ |------|-------------|
109
+ | ${workDir}/tuning-report.md | Full diagnostic report |
110
+ | ${workDir}/diagnosis/*.json | Individual diagnosis results |
111
+ | ${workDir}/fixes/fix-proposals.json | Proposed fixes |
112
+ | ${workDir}/fixes/applied-fixes.json | Applied fix history |
113
+ | ${workDir}/tuning-summary.md | This summary |
114
+
115
+ ---
116
+
117
+ *Skill tuning completed by skill-tuning*
118
+ `;
119
+
120
+ Write(`${workDir}/tuning-summary.md`, summary);
121
+
122
+ // Update final state
123
+ return {
124
+ stateUpdates: {
125
+ status: 'completed',
126
+ completed_at: endTime.toISOString()
127
+ },
128
+ outputFiles: [`${workDir}/tuning-summary.md`],
129
+ summary: `Tuning complete: ${state.quality_gate} with ${state.quality_score}/100 health score`
130
+ };
131
+ }
132
+
133
+ function generateRecommendations(state) {
134
+ const recommendations = [];
135
+
136
+ // Based on remaining issues
137
+ if (state.issues.some(i => i.type === 'context_explosion')) {
138
+ recommendations.push('- **Context Management**: Consider implementing a context summarization agent to prevent token growth');
139
+ }
140
+
141
+ if (state.issues.some(i => i.type === 'memory_loss')) {
142
+ recommendations.push('- **Constraint Tracking**: Add explicit constraint injection to each phase prompt');
143
+ }
144
+
145
+ if (state.issues.some(i => i.type === 'dataflow_break')) {
146
+ recommendations.push('- **State Centralization**: Migrate to single state.json with schema validation');
147
+ }
148
+
149
+ if (state.issues.some(i => i.type === 'agent_failure')) {
150
+ recommendations.push('- **Error Handling**: Wrap all Task calls in try-catch blocks');
151
+ }
152
+
153
+ // General recommendations
154
+ if (state.iteration_count >= state.max_iterations) {
155
+ recommendations.push('- **Deep Refactoring**: Consider architectural review if issues persist after multiple iterations');
156
+ }
157
+
158
+ if (state.quality_score < 80) {
159
+ recommendations.push('- **Regular Tuning**: Schedule periodic skill-tuning runs to catch issues early');
160
+ }
161
+
162
+ if (recommendations.length === 0) {
163
+ recommendations.push('- Skill is in good health! Monitor for regressions during future development.');
164
+ }
165
+
166
+ return recommendations.join('\n');
167
+ }
168
+ ```
169
+
170
+ ## State Updates
171
+
172
+ ```javascript
173
+ return {
174
+ stateUpdates: {
175
+ status: 'completed',
176
+ completed_at: '<timestamp>'
177
+ }
178
+ };
179
+ ```
180
+
181
+ ## Output
182
+
183
+ - **File**: `tuning-summary.md`
184
+ - **Location**: `${workDir}/tuning-summary.md`
185
+ - **Format**: Markdown
186
+
187
+ ## Error Handling
188
+
189
+ | Error Type | Recovery |
190
+ |------------|----------|
191
+ | Summary write failed | Write to alternative location |
192
+
193
+ ## Next Actions
194
+
195
+ - None (terminal state)
@@ -0,0 +1,317 @@
1
+ # Action: Diagnose Agent Coordination
2
+
3
+ Analyze target skill for agent coordination failures - call chain fragility and result passing issues.
4
+
5
+ ## Purpose
6
+
7
+ - Detect fragile agent call patterns
8
+ - Identify result passing issues
9
+ - Find missing error handling in agent calls
10
+ - Analyze agent return format consistency
11
+
12
+ ## Preconditions
13
+
14
+ - [ ] state.status === 'running'
15
+ - [ ] state.target_skill.path is set
16
+ - [ ] 'agent' in state.focus_areas OR state.focus_areas is empty
17
+
18
+ ## Detection Patterns
19
+
20
+ ### Pattern 1: Unhandled Agent Failures
21
+
22
+ ```regex
23
+ # Task calls without try-catch or error handling
24
+ /Task\s*\(\s*\{[^}]*\}\s*\)(?![^;]*catch)/
25
+ ```
26
+
27
+ ### Pattern 2: Missing Return Validation
28
+
29
+ ```regex
30
+ # Agent result used directly without validation
31
+ /const\s+\w+\s*=\s*await?\s*Task\([^)]+\);\s*(?!.*(?:if|try|JSON\.parse))/
32
+ ```
33
+
34
+ ### Pattern 3: Inconsistent Agent Configuration
35
+
36
+ ```regex
37
+ # Different agent configurations in same skill
38
+ /subagent_type:\s*['"](\w+)['"]/g
39
+ ```
40
+
41
+ ### Pattern 4: Deeply Nested Agent Calls
42
+
43
+ ```regex
44
+ # Agent calling another agent (nested)
45
+ /Task\s*\([^)]*prompt:[^)]*Task\s*\(/
46
+ ```
47
+
48
+ ## Execution
49
+
50
+ ```javascript
51
+ async function execute(state, workDir) {
52
+ const skillPath = state.target_skill.path;
53
+ const startTime = Date.now();
54
+ const issues = [];
55
+ const evidence = [];
56
+
57
+ console.log(`Diagnosing agent coordination in ${skillPath}...`);
58
+
59
+ // 1. Find all Task/agent calls
60
+ const allFiles = Glob(`${skillPath}/**/*.md`);
61
+ const agentCalls = [];
62
+ const agentTypes = new Set();
63
+
64
+ for (const file of allFiles) {
65
+ const content = Read(file);
66
+ const relativePath = file.replace(skillPath + '/', '');
67
+
68
+ // Find Task calls
69
+ const taskMatches = content.matchAll(/Task\s*\(\s*\{([^}]+)\}/g);
70
+ for (const match of taskMatches) {
71
+ const config = match[1];
72
+
73
+ // Extract agent type
74
+ const typeMatch = config.match(/subagent_type:\s*['"]([^'"]+)['"]/);
75
+ const agentType = typeMatch ? typeMatch[1] : 'unknown';
76
+ agentTypes.add(agentType);
77
+
78
+ // Check for error handling context
79
+ const hasErrorHandling = /try\s*\{.*Task|\.catch\(|await\s+Task.*\.then/s.test(
80
+ content.slice(Math.max(0, match.index - 100), match.index + match[0].length + 100)
81
+ );
82
+
83
+ // Check for result validation
84
+ const hasResultValidation = /JSON\.parse|if\s*\(\s*result|result\s*\?\./s.test(
85
+ content.slice(match.index, match.index + match[0].length + 200)
86
+ );
87
+
88
+ // Check for background execution
89
+ const runsInBackground = /run_in_background:\s*true/.test(config);
90
+
91
+ agentCalls.push({
92
+ file: relativePath,
93
+ agentType,
94
+ hasErrorHandling,
95
+ hasResultValidation,
96
+ runsInBackground,
97
+ config: config.slice(0, 200)
98
+ });
99
+ }
100
+ }
101
+
102
+ // 2. Analyze agent call patterns
103
+ const totalCalls = agentCalls.length;
104
+ const callsWithoutErrorHandling = agentCalls.filter(c => !c.hasErrorHandling);
105
+ const callsWithoutValidation = agentCalls.filter(c => !c.hasResultValidation);
106
+
107
+ // Issue: Missing error handling
108
+ if (callsWithoutErrorHandling.length > 0) {
109
+ issues.push({
110
+ id: `AGT-${issues.length + 1}`,
111
+ type: 'agent_failure',
112
+ severity: callsWithoutErrorHandling.length > 2 ? 'high' : 'medium',
113
+ location: { file: 'multiple' },
114
+ description: `${callsWithoutErrorHandling.length}/${totalCalls} agent calls lack error handling`,
115
+ evidence: callsWithoutErrorHandling.slice(0, 3).map(c =>
116
+ `${c.file}: ${c.agentType}`
117
+ ),
118
+ root_cause: 'Agent failures not caught, may crash workflow',
119
+ impact: 'Unhandled agent errors cause cascading failures',
120
+ suggested_fix: 'Wrap Task calls in try-catch with graceful fallback'
121
+ });
122
+ evidence.push({
123
+ file: 'multiple',
124
+ pattern: 'missing_error_handling',
125
+ context: `${callsWithoutErrorHandling.length} calls affected`,
126
+ severity: 'high'
127
+ });
128
+ }
129
+
130
+ // Issue: Missing result validation
131
+ if (callsWithoutValidation.length > 0) {
132
+ issues.push({
133
+ id: `AGT-${issues.length + 1}`,
134
+ type: 'agent_failure',
135
+ severity: 'medium',
136
+ location: { file: 'multiple' },
137
+ description: `${callsWithoutValidation.length}/${totalCalls} agent calls lack result validation`,
138
+ evidence: callsWithoutValidation.slice(0, 3).map(c =>
139
+ `${c.file}: ${c.agentType} result not validated`
140
+ ),
141
+ root_cause: 'Agent results used directly without type checking',
142
+ impact: 'Invalid agent output may corrupt state',
143
+ suggested_fix: 'Add JSON.parse with try-catch and schema validation'
144
+ });
145
+ }
146
+
147
+ // 3. Check for inconsistent agent types usage
148
+ if (agentTypes.size > 3 && state.target_skill.execution_mode === 'autonomous') {
149
+ issues.push({
150
+ id: `AGT-${issues.length + 1}`,
151
+ type: 'agent_failure',
152
+ severity: 'low',
153
+ location: { file: 'multiple' },
154
+ description: `Using ${agentTypes.size} different agent types`,
155
+ evidence: [...agentTypes].slice(0, 5),
156
+ root_cause: 'Multiple agent types increase coordination complexity',
157
+ impact: 'Different agent behaviors may cause inconsistency',
158
+ suggested_fix: 'Standardize on fewer agent types with clear roles'
159
+ });
160
+ }
161
+
162
+ // 4. Check for nested agent calls
163
+ for (const file of allFiles) {
164
+ const content = Read(file);
165
+ const relativePath = file.replace(skillPath + '/', '');
166
+
167
+ // Detect nested Task calls
168
+ const hasNestedTask = /Task\s*\([^)]*prompt:[^)]*Task\s*\(/s.test(content);
169
+
170
+ if (hasNestedTask) {
171
+ issues.push({
172
+ id: `AGT-${issues.length + 1}`,
173
+ type: 'agent_failure',
174
+ severity: 'high',
175
+ location: { file: relativePath },
176
+ description: 'Nested agent calls detected',
177
+ evidence: ['Agent prompt contains another Task call'],
178
+ root_cause: 'Agent calls another agent, creating deep nesting',
179
+ impact: 'Context explosion, hard to debug, unpredictable behavior',
180
+ suggested_fix: 'Flatten agent calls, use orchestrator to coordinate'
181
+ });
182
+ }
183
+ }
184
+
185
+ // 5. Check SKILL.md for agent configuration consistency
186
+ const skillMd = Read(`${skillPath}/SKILL.md`);
187
+
188
+ // Check if allowed-tools includes Task
189
+ const allowedTools = skillMd.match(/allowed-tools:\s*([^\n]+)/i);
190
+ if (allowedTools && !allowedTools[1].includes('Task') && totalCalls > 0) {
191
+ issues.push({
192
+ id: `AGT-${issues.length + 1}`,
193
+ type: 'agent_failure',
194
+ severity: 'medium',
195
+ location: { file: 'SKILL.md' },
196
+ description: 'Task tool used but not declared in allowed-tools',
197
+ evidence: [`${totalCalls} Task calls found, but Task not in allowed-tools`],
198
+ root_cause: 'Tool declaration mismatch',
199
+ impact: 'May cause runtime permission issues',
200
+ suggested_fix: 'Add Task to allowed-tools in SKILL.md front matter'
201
+ });
202
+ }
203
+
204
+ // 6. Check for agent result format consistency
205
+ const returnFormats = new Set();
206
+ for (const file of allFiles) {
207
+ const content = Read(file);
208
+
209
+ // Look for return format definitions
210
+ const returnMatch = content.match(/\[RETURN\][^[]*|return\s*\{[^}]+\}/gi);
211
+ if (returnMatch) {
212
+ returnMatch.forEach(r => {
213
+ const format = r.includes('JSON') ? 'json' :
214
+ r.includes('summary') ? 'summary' :
215
+ r.includes('file') ? 'file_path' : 'other';
216
+ returnFormats.add(format);
217
+ });
218
+ }
219
+ }
220
+
221
+ if (returnFormats.size > 2) {
222
+ issues.push({
223
+ id: `AGT-${issues.length + 1}`,
224
+ type: 'agent_failure',
225
+ severity: 'medium',
226
+ location: { file: 'multiple' },
227
+ description: 'Inconsistent agent return formats',
228
+ evidence: [...returnFormats],
229
+ root_cause: 'Different agents return data in different formats',
230
+ impact: 'Orchestrator must handle multiple format types',
231
+ suggested_fix: 'Standardize return format: {status, output_file, summary}'
232
+ });
233
+ }
234
+
235
+ // 7. Calculate severity
236
+ const criticalCount = issues.filter(i => i.severity === 'critical').length;
237
+ const highCount = issues.filter(i => i.severity === 'high').length;
238
+ const severity = criticalCount > 0 ? 'critical' :
239
+ highCount > 1 ? 'high' :
240
+ highCount > 0 ? 'medium' :
241
+ issues.length > 0 ? 'low' : 'none';
242
+
243
+ // 8. Write diagnosis result
244
+ const diagnosisResult = {
245
+ status: 'completed',
246
+ issues_found: issues.length,
247
+ severity: severity,
248
+ execution_time_ms: Date.now() - startTime,
249
+ details: {
250
+ patterns_checked: [
251
+ 'error_handling',
252
+ 'result_validation',
253
+ 'agent_type_consistency',
254
+ 'nested_calls',
255
+ 'return_format_consistency'
256
+ ],
257
+ patterns_matched: evidence.map(e => e.pattern),
258
+ evidence: evidence,
259
+ agent_analysis: {
260
+ total_agent_calls: totalCalls,
261
+ unique_agent_types: agentTypes.size,
262
+ calls_without_error_handling: callsWithoutErrorHandling.length,
263
+ calls_without_validation: callsWithoutValidation.length,
264
+ agent_types_used: [...agentTypes]
265
+ },
266
+ recommendations: [
267
+ callsWithoutErrorHandling.length > 0
268
+ ? 'Add try-catch to all Task calls' : null,
269
+ callsWithoutValidation.length > 0
270
+ ? 'Add result validation with JSON.parse and schema check' : null,
271
+ agentTypes.size > 3
272
+ ? 'Consolidate agent types for consistency' : null
273
+ ].filter(Boolean)
274
+ }
275
+ };
276
+
277
+ Write(`${workDir}/diagnosis/agent-diagnosis.json`,
278
+ JSON.stringify(diagnosisResult, null, 2));
279
+
280
+ return {
281
+ stateUpdates: {
282
+ 'diagnosis.agent': diagnosisResult,
283
+ issues: [...state.issues, ...issues]
284
+ },
285
+ outputFiles: [`${workDir}/diagnosis/agent-diagnosis.json`],
286
+ summary: `Agent diagnosis: ${issues.length} issues found (severity: ${severity})`
287
+ };
288
+ }
289
+ ```
290
+
291
+ ## State Updates
292
+
293
+ ```javascript
294
+ return {
295
+ stateUpdates: {
296
+ 'diagnosis.agent': {
297
+ status: 'completed',
298
+ issues_found: <count>,
299
+ severity: '<critical|high|medium|low|none>',
300
+ // ... full diagnosis result
301
+ },
302
+ issues: [...existingIssues, ...newIssues]
303
+ }
304
+ };
305
+ ```
306
+
307
+ ## Error Handling
308
+
309
+ | Error Type | Recovery |
310
+ |------------|----------|
311
+ | Regex match error | Use simpler patterns |
312
+ | File access error | Skip and continue |
313
+
314
+ ## Next Actions
315
+
316
+ - Success: action-generate-report
317
+ - Skipped: If 'agent' not in focus_areas