@agentic15.com/agentic15-claude-zen 1.0.0 → 1.1.0
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/CHANGELOG.md +60 -45
- package/LICENSE +1 -1
- package/README.md +6 -4
- package/bin/create-agentic15-claude-zen.js +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +3 -3
- package/package.json +64 -61
- package/src/core/DependencyInstaller.js +1 -1
- package/src/core/GitHubClient.js +170 -0
- package/src/core/GitHubConfig.js +192 -0
- package/src/core/GitInitializer.js +1 -1
- package/src/core/HookInstaller.js +71 -54
- package/src/core/ProjectInitializer.js +1 -1
- package/src/core/TaskIssueMapper.js +137 -0
- package/src/core/TemplateManager.js +1 -1
- package/src/index.js +1 -1
- package/src/utils/updateTaskGitHubStatus.js +81 -0
- package/templates/.claude/POST-INSTALL.md +367 -248
- package/templates/.claude/hooks/complete-task.js +224 -0
- package/templates/.claude/hooks/post-merge.js +163 -0
- package/templates/.claude/hooks/start-task.js +233 -0
- package/templates/.claude/settings.json +272 -262
- package/templates/.claude/settings.local.json.example +11 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright 2024-2025 agentic15.com
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Complete Task Hook with GitHub Issues Integration
|
|
21
|
+
*
|
|
22
|
+
* This hook runs when a task is completed. It:
|
|
23
|
+
* 1. Updates task status to 'completed'
|
|
24
|
+
* 2. Updates GitHub issue (if configured)
|
|
25
|
+
* 3. Updates task tracker
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import fs from 'fs';
|
|
29
|
+
import path from 'path';
|
|
30
|
+
|
|
31
|
+
// Import GitHub integration utility
|
|
32
|
+
let updateTaskGitHubStatus;
|
|
33
|
+
try {
|
|
34
|
+
const statusModule = await import('@agentic15.com/agentic15-claude-zen/src/utils/updateTaskGitHubStatus.js');
|
|
35
|
+
updateTaskGitHubStatus = statusModule.updateTaskGitHubStatus;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// GitHub integration not available yet (framework not installed or old version)
|
|
38
|
+
// Continue without GitHub integration
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Main execution
|
|
43
|
+
*/
|
|
44
|
+
async function main() {
|
|
45
|
+
const taskId = process.argv[2];
|
|
46
|
+
|
|
47
|
+
if (!taskId) {
|
|
48
|
+
console.error('\n❌ ERROR: Task ID required');
|
|
49
|
+
console.error('Usage: npm run task:done TASK-001\n');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Check for active plan
|
|
54
|
+
const activePlanFile = '.claude/ACTIVE-PLAN';
|
|
55
|
+
if (!fs.existsSync(activePlanFile)) {
|
|
56
|
+
console.error('\n❌ ERROR: No active plan found');
|
|
57
|
+
console.error('Set active plan first: npm run plan:manager\n');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const activePlan = fs.readFileSync(activePlanFile, 'utf8').trim();
|
|
62
|
+
const planDir = path.join('.claude/plans', activePlan);
|
|
63
|
+
const trackerFile = path.join(planDir, 'TASK-TRACKER.json');
|
|
64
|
+
const taskFile = path.join(planDir, 'tasks', `${taskId}.json`);
|
|
65
|
+
|
|
66
|
+
// Check if tracker exists
|
|
67
|
+
if (!fs.existsSync(trackerFile)) {
|
|
68
|
+
console.error('\n❌ ERROR: Task tracker not found');
|
|
69
|
+
console.error(`Plan: ${activePlan}`);
|
|
70
|
+
console.error('Initialize first: npm run plan:init\n');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check if task exists
|
|
75
|
+
if (!fs.existsSync(taskFile)) {
|
|
76
|
+
console.error(`\n❌ ERROR: Task file not found: ${taskFile}`);
|
|
77
|
+
console.error('Available tasks:');
|
|
78
|
+
|
|
79
|
+
const tracker = JSON.parse(fs.readFileSync(trackerFile, 'utf8'));
|
|
80
|
+
tracker.taskFiles.forEach(task => {
|
|
81
|
+
console.error(` ${task.id}: ${task.title} [${task.status}]`);
|
|
82
|
+
});
|
|
83
|
+
console.error('');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Load task and tracker
|
|
88
|
+
const tracker = JSON.parse(fs.readFileSync(trackerFile, 'utf8'));
|
|
89
|
+
const taskData = JSON.parse(fs.readFileSync(taskFile, 'utf8'));
|
|
90
|
+
|
|
91
|
+
// Check if already completed
|
|
92
|
+
if (taskData.status === 'completed') {
|
|
93
|
+
console.log(`\nℹ Task ${taskId} is already completed`);
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Check if this is the active task
|
|
98
|
+
if (tracker.activeTask !== taskId) {
|
|
99
|
+
console.warn(`\n⚠️ Warning: ${taskId} is not the active task`);
|
|
100
|
+
console.warn(` Active task: ${tracker.activeTask || 'none'}`);
|
|
101
|
+
console.warn(' Completing anyway...\n');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Update task status
|
|
105
|
+
const previousStatus = taskData.status;
|
|
106
|
+
taskData.status = 'completed';
|
|
107
|
+
taskData.completedAt = new Date().toISOString();
|
|
108
|
+
|
|
109
|
+
// Calculate actual hours if started time exists
|
|
110
|
+
if (taskData.startedAt) {
|
|
111
|
+
const startTime = new Date(taskData.startedAt);
|
|
112
|
+
const endTime = new Date(taskData.completedAt);
|
|
113
|
+
const hoursWorked = (endTime - startTime) / (1000 * 60 * 60);
|
|
114
|
+
taskData.actualHours = parseFloat(hoursWorked.toFixed(2));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// GitHub Issues Integration
|
|
118
|
+
if (updateTaskGitHubStatus) {
|
|
119
|
+
try {
|
|
120
|
+
// Prepare completion comment
|
|
121
|
+
let comment = `Task completed! ✅\n\n`;
|
|
122
|
+
comment += `**Status:** ${previousStatus} → completed\n`;
|
|
123
|
+
|
|
124
|
+
if (taskData.actualHours) {
|
|
125
|
+
comment += `**Time Taken:** ${taskData.actualHours}h`;
|
|
126
|
+
if (taskData.estimatedHours) {
|
|
127
|
+
const variance = taskData.actualHours - taskData.estimatedHours;
|
|
128
|
+
const variancePercent = ((variance / taskData.estimatedHours) * 100).toFixed(1);
|
|
129
|
+
comment += ` (estimated: ${taskData.estimatedHours}h, ${variance > 0 ? '+' : ''}${variancePercent}%)\n`;
|
|
130
|
+
} else {
|
|
131
|
+
comment += `\n`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (taskData.completionCriteria && taskData.completionCriteria.length > 0) {
|
|
136
|
+
comment += `\n**Completion Criteria:**\n`;
|
|
137
|
+
taskData.completionCriteria.forEach(criteria => {
|
|
138
|
+
comment += `- ✓ ${criteria}\n`;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Update GitHub issue
|
|
143
|
+
await updateTaskGitHubStatus(
|
|
144
|
+
taskData,
|
|
145
|
+
process.cwd(),
|
|
146
|
+
'completed',
|
|
147
|
+
{ comment }
|
|
148
|
+
);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.warn('⚠ GitHub integration failed:', error.message);
|
|
151
|
+
// Continue anyway - task completion should not fail due to GitHub issues
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Save updated task
|
|
156
|
+
fs.writeFileSync(taskFile, JSON.stringify(taskData, null, 2));
|
|
157
|
+
|
|
158
|
+
// Update tracker
|
|
159
|
+
if (tracker.activeTask === taskId) {
|
|
160
|
+
tracker.activeTask = null;
|
|
161
|
+
}
|
|
162
|
+
tracker.lastUpdated = new Date().toISOString();
|
|
163
|
+
|
|
164
|
+
const trackerTask = tracker.taskFiles.find(t => t.id === taskId);
|
|
165
|
+
if (trackerTask) {
|
|
166
|
+
trackerTask.status = 'completed';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Update statistics
|
|
170
|
+
tracker.statistics = {
|
|
171
|
+
totalTasks: tracker.taskFiles.length,
|
|
172
|
+
pending: tracker.taskFiles.filter(t => t.status === 'pending').length,
|
|
173
|
+
inProgress: tracker.taskFiles.filter(t => t.status === 'in_progress').length,
|
|
174
|
+
completed: tracker.taskFiles.filter(t => t.status === 'completed').length,
|
|
175
|
+
blocked: tracker.taskFiles.filter(t => t.status === 'blocked').length
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
fs.writeFileSync(trackerFile, JSON.stringify(tracker, null, 2));
|
|
179
|
+
|
|
180
|
+
// Display completion message
|
|
181
|
+
console.log(`\n✅ Completed task: ${taskId}`);
|
|
182
|
+
console.log(`📋 Plan: ${activePlan}\n`);
|
|
183
|
+
console.log(`📌 ${taskData.title}`);
|
|
184
|
+
|
|
185
|
+
if (taskData.actualHours) {
|
|
186
|
+
console.log(`⏱️ Time: ${taskData.actualHours}h`);
|
|
187
|
+
if (taskData.estimatedHours) {
|
|
188
|
+
const variance = taskData.actualHours - taskData.estimatedHours;
|
|
189
|
+
if (Math.abs(variance) > 0.1) {
|
|
190
|
+
const symbol = variance > 0 ? '⚠️' : '✓';
|
|
191
|
+
console.log(` ${symbol} ${variance > 0 ? 'Over' : 'Under'} by ${Math.abs(variance).toFixed(2)}h`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (taskData.githubIssue) {
|
|
197
|
+
console.log(`🔗 GitHub Issue: Updated #${taskData.githubIssue}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
console.log('');
|
|
201
|
+
console.log('📊 Progress:');
|
|
202
|
+
console.log(` Completed: ${tracker.statistics.completed}/${tracker.statistics.totalTasks}`);
|
|
203
|
+
console.log(` Remaining: ${tracker.statistics.pending + tracker.statistics.inProgress}`);
|
|
204
|
+
|
|
205
|
+
// Suggest next task
|
|
206
|
+
const nextPendingTask = tracker.taskFiles.find(t => t.status === 'pending');
|
|
207
|
+
if (nextPendingTask) {
|
|
208
|
+
console.log('');
|
|
209
|
+
console.log('📝 Next task:');
|
|
210
|
+
console.log(` ${nextPendingTask.id}: ${nextPendingTask.title}`);
|
|
211
|
+
console.log(` Run: npm run task:start ${nextPendingTask.id}`);
|
|
212
|
+
} else {
|
|
213
|
+
console.log('');
|
|
214
|
+
console.log('🎉 All tasks completed!');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
console.log('');
|
|
218
|
+
process.exit(0);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
main().catch(error => {
|
|
222
|
+
console.error('\n❌ Fatal error:', error);
|
|
223
|
+
process.exit(1);
|
|
224
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright 2024-2025 agentic15.com
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Post-Merge Hook - Close GitHub issues when merged to main
|
|
21
|
+
*
|
|
22
|
+
* This git hook runs after: git merge, git pull
|
|
23
|
+
* Detects: Task IDs in commit messages
|
|
24
|
+
* Action: Close associated GitHub issues
|
|
25
|
+
*
|
|
26
|
+
* IMPORTANT: This is a traditional git hook that must be installed in .git/hooks/
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import fs from 'fs';
|
|
30
|
+
import path from 'path';
|
|
31
|
+
import { execSync } from 'child_process';
|
|
32
|
+
|
|
33
|
+
// Import GitHub integration classes
|
|
34
|
+
let GitHubClient, GitHubConfig;
|
|
35
|
+
try {
|
|
36
|
+
const { GitHubClient: GHClient } = await import('@agentic15.com/agentic15-claude-zen/src/core/GitHubClient.js');
|
|
37
|
+
const { GitHubConfig: GHConfig } = await import('@agentic15.com/agentic15-claude-zen/src/core/GitHubConfig.js');
|
|
38
|
+
|
|
39
|
+
GitHubClient = GHClient;
|
|
40
|
+
GitHubConfig = GHConfig;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
// GitHub integration not available yet (framework not installed or old version)
|
|
43
|
+
// Hook will exit silently
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Main execution
|
|
49
|
+
*/
|
|
50
|
+
async function main() {
|
|
51
|
+
const projectRoot = process.cwd();
|
|
52
|
+
|
|
53
|
+
// Check if we're on main branch
|
|
54
|
+
try {
|
|
55
|
+
const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {
|
|
56
|
+
encoding: 'utf8'
|
|
57
|
+
}).trim();
|
|
58
|
+
|
|
59
|
+
if (currentBranch !== 'main' && currentBranch !== 'master') {
|
|
60
|
+
// Not on main, skip
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// Could not detect current branch, skip
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Load GitHub config
|
|
69
|
+
const githubConfig = new GitHubConfig(projectRoot);
|
|
70
|
+
|
|
71
|
+
if (!githubConfig.isAutoCloseEnabled()) {
|
|
72
|
+
// Auto-close not enabled, skip
|
|
73
|
+
process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Get commits from the merge
|
|
77
|
+
let mergeCommits;
|
|
78
|
+
try {
|
|
79
|
+
mergeCommits = execSync('git log ORIG_HEAD..HEAD --oneline', {
|
|
80
|
+
encoding: 'utf8'
|
|
81
|
+
}).trim();
|
|
82
|
+
|
|
83
|
+
if (!mergeCommits) {
|
|
84
|
+
// No commits in merge, skip
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
// Could not get merge commits, skip
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Extract task IDs from commit messages
|
|
93
|
+
// Matches: [TASK-001], TASK-001, [task-001], task-001
|
|
94
|
+
const taskIds = new Set();
|
|
95
|
+
const taskIdRegex = /\[?(TASK-\d+)\]?/gi;
|
|
96
|
+
|
|
97
|
+
for (const match of mergeCommits.matchAll(taskIdRegex)) {
|
|
98
|
+
taskIds.add(match[1].toUpperCase());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (taskIds.size === 0) {
|
|
102
|
+
// No task IDs found in merge commits
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Load active plan to get task-to-issue mappings
|
|
107
|
+
const activePlanPath = path.join(projectRoot, '.claude', 'ACTIVE-PLAN');
|
|
108
|
+
if (!fs.existsSync(activePlanPath)) {
|
|
109
|
+
// No active plan, skip
|
|
110
|
+
process.exit(0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const activePlan = fs.readFileSync(activePlanPath, 'utf8').trim();
|
|
114
|
+
const planDir = path.join(projectRoot, '.claude', 'plans', activePlan);
|
|
115
|
+
|
|
116
|
+
// Initialize GitHub client
|
|
117
|
+
const { owner, repo } = githubConfig.getRepoInfo();
|
|
118
|
+
const githubClient = new GitHubClient(
|
|
119
|
+
githubConfig.getToken(),
|
|
120
|
+
owner,
|
|
121
|
+
repo
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (!githubClient.isConfigured()) {
|
|
125
|
+
// GitHub not configured, skip
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Close issues for each task
|
|
130
|
+
let closedCount = 0;
|
|
131
|
+
for (const taskId of taskIds) {
|
|
132
|
+
const taskFile = path.join(planDir, 'tasks', `${taskId}.json`);
|
|
133
|
+
|
|
134
|
+
if (!fs.existsSync(taskFile)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const taskData = JSON.parse(fs.readFileSync(taskFile, 'utf8'));
|
|
139
|
+
|
|
140
|
+
// Only close issue if task is completed and has associated GitHub issue
|
|
141
|
+
if (taskData.githubIssue && taskData.status === 'completed') {
|
|
142
|
+
const comment = `Merged to main branch! 🎉\n\nTask ${taskId} has been successfully integrated.`;
|
|
143
|
+
const success = await githubClient.closeIssue(taskData.githubIssue, comment);
|
|
144
|
+
|
|
145
|
+
if (success) {
|
|
146
|
+
console.log(`✓ Closed GitHub issue #${taskData.githubIssue} for ${taskId}`);
|
|
147
|
+
closedCount++;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (closedCount > 0) {
|
|
153
|
+
console.log(`\n✅ Closed ${closedCount} GitHub issue${closedCount > 1 ? 's' : ''} after merge to main`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
main().catch(error => {
|
|
160
|
+
// Don't block the merge on errors
|
|
161
|
+
console.warn('⚠ Post-merge hook encountered an error:', error.message);
|
|
162
|
+
process.exit(0);
|
|
163
|
+
});
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright 2024-2025 agentic15.com
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Start Task Hook with GitHub Issues Integration
|
|
21
|
+
*
|
|
22
|
+
* This hook runs when a task is started. It:
|
|
23
|
+
* 1. Updates task status to 'in_progress'
|
|
24
|
+
* 2. Creates a GitHub issue (if configured)
|
|
25
|
+
* 3. Updates task tracker
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import fs from 'fs';
|
|
29
|
+
import path from 'path';
|
|
30
|
+
|
|
31
|
+
// Import GitHub integration classes
|
|
32
|
+
// These classes are bundled with the framework
|
|
33
|
+
let GitHubClient, GitHubConfig, TaskIssueMapper;
|
|
34
|
+
try {
|
|
35
|
+
// Try to import from node_modules (after framework is installed)
|
|
36
|
+
const { GitHubClient: GHClient } = await import('@agentic15.com/agentic15-claude-zen/src/core/GitHubClient.js');
|
|
37
|
+
const { GitHubConfig: GHConfig } = await import('@agentic15.com/agentic15-claude-zen/src/core/GitHubConfig.js');
|
|
38
|
+
const { TaskIssueMapper: GHMapper } = await import('@agentic15.com/agentic15-claude-zen/src/core/TaskIssueMapper.js');
|
|
39
|
+
|
|
40
|
+
GitHubClient = GHClient;
|
|
41
|
+
GitHubConfig = GHConfig;
|
|
42
|
+
TaskIssueMapper = GHMapper;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// GitHub integration not available yet (framework not installed or old version)
|
|
45
|
+
// Continue without GitHub integration
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Main execution
|
|
50
|
+
*/
|
|
51
|
+
async function main() {
|
|
52
|
+
const taskId = process.argv[2];
|
|
53
|
+
|
|
54
|
+
if (!taskId) {
|
|
55
|
+
console.error('\n❌ ERROR: Task ID required');
|
|
56
|
+
console.error('Usage: npm run task:start TASK-001\n');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Check for active plan
|
|
61
|
+
const activePlanFile = '.claude/ACTIVE-PLAN';
|
|
62
|
+
if (!fs.existsSync(activePlanFile)) {
|
|
63
|
+
console.error('\n❌ ERROR: No active plan found');
|
|
64
|
+
console.error('Set active plan first: npm run plan:manager\n');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const activePlan = fs.readFileSync(activePlanFile, 'utf8').trim();
|
|
69
|
+
const planDir = path.join('.claude/plans', activePlan);
|
|
70
|
+
const trackerFile = path.join(planDir, 'TASK-TRACKER.json');
|
|
71
|
+
const taskFile = path.join(planDir, 'tasks', `${taskId}.json`);
|
|
72
|
+
|
|
73
|
+
// Check if tracker exists
|
|
74
|
+
if (!fs.existsSync(trackerFile)) {
|
|
75
|
+
console.error('\n❌ ERROR: Task tracker not found');
|
|
76
|
+
console.error(`Plan: ${activePlan}`);
|
|
77
|
+
console.error('Initialize first: npm run plan:init\n');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check if task exists
|
|
82
|
+
if (!fs.existsSync(taskFile)) {
|
|
83
|
+
console.error(`\n❌ ERROR: Task file not found: ${taskFile}`);
|
|
84
|
+
console.error('Available tasks:');
|
|
85
|
+
|
|
86
|
+
const tracker = JSON.parse(fs.readFileSync(trackerFile, 'utf8'));
|
|
87
|
+
tracker.taskFiles.forEach(task => {
|
|
88
|
+
console.error(` ${task.id}: ${task.title} [${task.status}]`);
|
|
89
|
+
});
|
|
90
|
+
console.error('');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Load task and tracker
|
|
95
|
+
const tracker = JSON.parse(fs.readFileSync(trackerFile, 'utf8'));
|
|
96
|
+
const taskData = JSON.parse(fs.readFileSync(taskFile, 'utf8'));
|
|
97
|
+
|
|
98
|
+
// Check if already completed
|
|
99
|
+
if (taskData.status === 'completed') {
|
|
100
|
+
console.error(`\n❌ ERROR: Task ${taskId} is already completed`);
|
|
101
|
+
console.error('Cannot restart a completed task\n');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Pause any currently active task
|
|
106
|
+
if (tracker.activeTask && tracker.activeTask !== taskId) {
|
|
107
|
+
const activeTaskFile = path.join(planDir, 'tasks', `${tracker.activeTask}.json`);
|
|
108
|
+
if (fs.existsSync(activeTaskFile)) {
|
|
109
|
+
const activeTask = JSON.parse(fs.readFileSync(activeTaskFile, 'utf8'));
|
|
110
|
+
console.log(`\n⚠️ Pausing task ${activeTask.id}: ${activeTask.title}`);
|
|
111
|
+
activeTask.status = 'pending';
|
|
112
|
+
fs.writeFileSync(activeTaskFile, JSON.stringify(activeTask, null, 2));
|
|
113
|
+
|
|
114
|
+
// Update in tracker
|
|
115
|
+
const trackerTask = tracker.taskFiles.find(t => t.id === tracker.activeTask);
|
|
116
|
+
if (trackerTask) {
|
|
117
|
+
trackerTask.status = 'pending';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Update task status
|
|
123
|
+
taskData.status = 'in_progress';
|
|
124
|
+
taskData.startedAt = new Date().toISOString();
|
|
125
|
+
|
|
126
|
+
// GitHub Issues Integration
|
|
127
|
+
if (GitHubConfig && GitHubClient && TaskIssueMapper) {
|
|
128
|
+
try {
|
|
129
|
+
const githubConfig = new GitHubConfig(process.cwd());
|
|
130
|
+
|
|
131
|
+
if (githubConfig.isAutoCreateEnabled()) {
|
|
132
|
+
const { owner, repo } = githubConfig.getRepoInfo();
|
|
133
|
+
const githubClient = new GitHubClient(
|
|
134
|
+
githubConfig.getToken(),
|
|
135
|
+
owner,
|
|
136
|
+
repo
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
// Only create issue if not already created
|
|
140
|
+
if (!taskData.githubIssue) {
|
|
141
|
+
const title = TaskIssueMapper.taskToIssueTitle(taskData);
|
|
142
|
+
const body = TaskIssueMapper.taskToIssueBody(taskData);
|
|
143
|
+
const labels = TaskIssueMapper.taskStatusToLabels(taskData.status, taskData.phase);
|
|
144
|
+
|
|
145
|
+
const issueNumber = await githubClient.createIssue(title, body, labels);
|
|
146
|
+
|
|
147
|
+
if (issueNumber) {
|
|
148
|
+
taskData.githubIssue = issueNumber;
|
|
149
|
+
console.log(`✓ Created GitHub issue #${issueNumber}`);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
console.log(`ℹ Task already linked to GitHub issue #${taskData.githubIssue}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.warn('⚠ GitHub integration failed:', error.message);
|
|
157
|
+
// Continue anyway - task creation should not fail due to GitHub issues
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Save updated task
|
|
162
|
+
fs.writeFileSync(taskFile, JSON.stringify(taskData, null, 2));
|
|
163
|
+
|
|
164
|
+
// Update tracker
|
|
165
|
+
tracker.activeTask = taskId;
|
|
166
|
+
tracker.lastUpdated = new Date().toISOString();
|
|
167
|
+
|
|
168
|
+
const trackerTask = tracker.taskFiles.find(t => t.id === taskId);
|
|
169
|
+
if (trackerTask) {
|
|
170
|
+
trackerTask.status = 'in_progress';
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Update statistics
|
|
174
|
+
tracker.statistics = {
|
|
175
|
+
totalTasks: tracker.taskFiles.length,
|
|
176
|
+
pending: tracker.taskFiles.filter(t => t.status === 'pending').length,
|
|
177
|
+
inProgress: tracker.taskFiles.filter(t => t.status === 'in_progress').length,
|
|
178
|
+
completed: tracker.taskFiles.filter(t => t.status === 'completed').length,
|
|
179
|
+
blocked: tracker.taskFiles.filter(t => t.status === 'blocked').length
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
fs.writeFileSync(trackerFile, JSON.stringify(tracker, null, 2));
|
|
183
|
+
|
|
184
|
+
// Display task info
|
|
185
|
+
console.log(`\n✅ Started task: ${taskId}`);
|
|
186
|
+
console.log(`📋 Plan: ${activePlan}\n`);
|
|
187
|
+
console.log(`📌 ${taskData.title}`);
|
|
188
|
+
|
|
189
|
+
if (taskData.description) {
|
|
190
|
+
console.log(`📝 ${taskData.description}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.log('');
|
|
194
|
+
|
|
195
|
+
if (taskData.phase) {
|
|
196
|
+
console.log(`🔧 Phase: ${taskData.phase}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (taskData.githubIssue) {
|
|
200
|
+
const { owner, repo } = new GitHubConfig(process.cwd()).getRepoInfo();
|
|
201
|
+
const issueUrl = `https://github.com/${owner}/${repo}/issues/${taskData.githubIssue}`;
|
|
202
|
+
console.log(`🔗 GitHub Issue: ${issueUrl}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (taskData.completionCriteria && taskData.completionCriteria.length > 0) {
|
|
206
|
+
console.log('\n✓ Completion criteria:');
|
|
207
|
+
taskData.completionCriteria.forEach((criteria, index) => {
|
|
208
|
+
console.log(` ${index + 1}. ${criteria}`);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (taskData.testCases && taskData.testCases.length > 0) {
|
|
213
|
+
console.log('\n🧪 Test cases:');
|
|
214
|
+
taskData.testCases.forEach((test, index) => {
|
|
215
|
+
console.log(` ${index + 1}. ${test}`);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
console.log(`\n📂 Task file: ${taskFile}`);
|
|
220
|
+
console.log('\n📝 WORKFLOW:');
|
|
221
|
+
console.log(' 1. Make your changes on main branch');
|
|
222
|
+
console.log(' 2. Commit frequently with task reference:');
|
|
223
|
+
console.log(` git commit -m "[${taskId}] Description of changes"`);
|
|
224
|
+
console.log(' 3. When finished:');
|
|
225
|
+
console.log(` npm run task:done ${taskId}`);
|
|
226
|
+
|
|
227
|
+
process.exit(0);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
main().catch(error => {
|
|
231
|
+
console.error('\n❌ Fatal error:', error);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
});
|