@crewx/wbs 0.1.10-rc.20 → 0.1.10-rc.200
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/SKILL.md +2 -2
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +42 -636
- package/dist/src/engine.d.ts +2 -1
- package/dist/src/engine.js +92 -551
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -3
- package/package.json +3 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/src/engine.d.ts.map +0 -1
- package/dist/src/engine.js.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js.map +0 -1
package/dist/src/engine.js
CHANGED
|
@@ -1,551 +1,92 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return getCurrentBranch();
|
|
94
|
-
return setting;
|
|
95
|
-
}
|
|
96
|
-
function getMergeStrategy() {
|
|
97
|
-
const wbs = getWbsConfig();
|
|
98
|
-
if (wbs.merge_strategy === 'pr')
|
|
99
|
-
return 'pr';
|
|
100
|
-
return 'local';
|
|
101
|
-
}
|
|
102
|
-
function getNextId(table, prefix) {
|
|
103
|
-
const prefixLen = prefix.length;
|
|
104
|
-
const result = alasql(`SELECT MAX(CAST(SUBSTR(id, ${prefixLen + 1}) AS INT)) as max FROM ${table}`)[0];
|
|
105
|
-
return `${prefix}${(result.max || 0) + 1}`;
|
|
106
|
-
}
|
|
107
|
-
function saveData() {
|
|
108
|
-
if (!fs.existsSync(CREWX_DIR)) {
|
|
109
|
-
fs.mkdirSync(CREWX_DIR, { recursive: true });
|
|
110
|
-
}
|
|
111
|
-
const data = {
|
|
112
|
-
wbs: alasql('SELECT * FROM wbs'),
|
|
113
|
-
jobs: alasql('SELECT * FROM jobs'),
|
|
114
|
-
executions: alasql('SELECT * FROM executions'),
|
|
115
|
-
};
|
|
116
|
-
fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2));
|
|
117
|
-
}
|
|
118
|
-
function initDB() {
|
|
119
|
-
alasql('CREATE TABLE IF NOT EXISTS wbs (id STRING PRIMARY KEY, title STRING, detail_path STRING, status STRING, created_at STRING, source_branch STRING, target_branch STRING)');
|
|
120
|
-
alasql('CREATE TABLE IF NOT EXISTS jobs (id STRING PRIMARY KEY, wbs_id STRING, title STRING, description STRING, agent STRING, status STRING, seq INT, created_at STRING, completed_at STRING, issue_number INT, no_git BOOLEAN)');
|
|
121
|
-
alasql('CREATE TABLE IF NOT EXISTS executions (id STRING PRIMARY KEY, job_id STRING, pid INT, status STRING, started_at STRING, ended_at STRING, exit_code INT, error STRING, task_id STRING)');
|
|
122
|
-
if (fs.existsSync(DATA_FILE)) {
|
|
123
|
-
try {
|
|
124
|
-
const data = JSON.parse(fs.readFileSync(DATA_FILE, 'utf8'));
|
|
125
|
-
(data.wbs || []).forEach(w => {
|
|
126
|
-
alasql('INSERT INTO wbs VALUES (?, ?, ?, ?, ?, ?, ?)', [w.id, w.title, w.detail_path ?? null, w.status, w.created_at, w.source_branch ?? null, w.target_branch ?? null]);
|
|
127
|
-
});
|
|
128
|
-
(data.jobs || []).forEach(j => {
|
|
129
|
-
alasql('INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [j.id, j.wbs_id, j.title, j.description ?? null, j.agent, j.status, j.seq, j.created_at, j.completed_at, j.issue_number ?? null, j.no_git ?? false]);
|
|
130
|
-
});
|
|
131
|
-
(data.executions || []).forEach(e => {
|
|
132
|
-
alasql('INSERT INTO executions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [e.id, e.job_id, e.pid, e.status, e.started_at, e.ended_at, e.exit_code, e.error, e.task_id ?? null]);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
const err = e;
|
|
137
|
-
console.error('Warning: Could not load persisted data:', err.message);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
initDB();
|
|
142
|
-
function getJobSlug(job) {
|
|
143
|
-
const wbsNum = job.wbs_id.replace('wbs-', '');
|
|
144
|
-
return `wbs-${wbsNum}-${job.seq}`;
|
|
145
|
-
}
|
|
146
|
-
function resolveJobId(idOrSlug) {
|
|
147
|
-
if (idOrSlug.startsWith('job-')) {
|
|
148
|
-
const rows = alasql('SELECT * FROM jobs WHERE id = ?', [idOrSlug]);
|
|
149
|
-
return rows[0] ?? null;
|
|
150
|
-
}
|
|
151
|
-
const slugMatch = idOrSlug.match(/^wbs-(\d+)-(\d+)$/);
|
|
152
|
-
if (slugMatch) {
|
|
153
|
-
const wbsId = `wbs-${slugMatch[1]}`;
|
|
154
|
-
const seq = parseInt(slugMatch[2] ?? '0', 10);
|
|
155
|
-
const rows = alasql('SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? ORDER BY created_at ASC', [wbsId, seq]);
|
|
156
|
-
return rows[0] ?? null;
|
|
157
|
-
}
|
|
158
|
-
const rows = alasql('SELECT * FROM jobs WHERE id = ?', [idOrSlug]);
|
|
159
|
-
return rows[0] ?? null;
|
|
160
|
-
}
|
|
161
|
-
function generateDetailFile(wbsId) {
|
|
162
|
-
const project = alasql('SELECT * FROM wbs WHERE id = ?', [wbsId]);
|
|
163
|
-
if (!project[0])
|
|
164
|
-
return;
|
|
165
|
-
const wbs = project[0];
|
|
166
|
-
const jobs = alasql('SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq, created_at', [wbsId]);
|
|
167
|
-
const lines = [];
|
|
168
|
-
lines.push(`# ${wbs.title}`);
|
|
169
|
-
lines.push('');
|
|
170
|
-
lines.push(`> WBS ID: ${wbs.id} | Status: ${wbs.status} | Jobs: ${jobs.length}`);
|
|
171
|
-
lines.push('');
|
|
172
|
-
lines.push('## Jobs');
|
|
173
|
-
lines.push('');
|
|
174
|
-
if (jobs.length === 0) {
|
|
175
|
-
lines.push('(아직 등록된 Job이 없습니다)');
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
for (const job of jobs) {
|
|
179
|
-
const slug = getJobSlug(job);
|
|
180
|
-
lines.push(`### ${slug}: ${job.title}`);
|
|
181
|
-
lines.push('');
|
|
182
|
-
lines.push(`- **Agent**: ${job.agent}`);
|
|
183
|
-
lines.push(`- **Seq**: ${job.seq}`);
|
|
184
|
-
lines.push(`- **Status**: ${job.status}`);
|
|
185
|
-
lines.push(`- **ID**: ${job.id}`);
|
|
186
|
-
if (job.description) {
|
|
187
|
-
lines.push('');
|
|
188
|
-
lines.push('**AC / Description:**');
|
|
189
|
-
lines.push('');
|
|
190
|
-
lines.push(job.description);
|
|
191
|
-
}
|
|
192
|
-
lines.push('');
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
let detailPath = wbs.detail_path;
|
|
196
|
-
if (!detailPath) {
|
|
197
|
-
const detailsDir = path.join(process.cwd(), 'wbs-details');
|
|
198
|
-
if (!fs.existsSync(detailsDir))
|
|
199
|
-
fs.mkdirSync(detailsDir, { recursive: true });
|
|
200
|
-
detailPath = `wbs-details/${wbsId}-detail.md`;
|
|
201
|
-
alasql('UPDATE wbs SET detail_path = ? WHERE id = ?', [detailPath, wbsId]);
|
|
202
|
-
saveData();
|
|
203
|
-
}
|
|
204
|
-
const fullPath = path.isAbsolute(detailPath)
|
|
205
|
-
? detailPath
|
|
206
|
-
: path.join(process.cwd(), detailPath);
|
|
207
|
-
const dir = path.dirname(fullPath);
|
|
208
|
-
if (!fs.existsSync(dir))
|
|
209
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
210
|
-
fs.writeFileSync(fullPath, lines.join('\n'));
|
|
211
|
-
}
|
|
212
|
-
exports.engine = {
|
|
213
|
-
create(title, detailPath = null, sourceBranch, targetBranch) {
|
|
214
|
-
const id = getNextId('wbs', 'wbs-');
|
|
215
|
-
alasql('INSERT INTO wbs VALUES (?, ?, ?, ?, ?, ?, ?)', [id, title, detailPath, 'planning', new Date().toISOString(), sourceBranch ?? null, targetBranch ?? null]);
|
|
216
|
-
saveData();
|
|
217
|
-
return id;
|
|
218
|
-
},
|
|
219
|
-
list() {
|
|
220
|
-
return alasql('SELECT * FROM wbs ORDER BY created_at DESC');
|
|
221
|
-
},
|
|
222
|
-
getProject(wbsId) {
|
|
223
|
-
const rows = alasql('SELECT * FROM wbs WHERE id = ?', [wbsId]);
|
|
224
|
-
return rows[0] ?? null;
|
|
225
|
-
},
|
|
226
|
-
status(wbsId) {
|
|
227
|
-
const project = this.getProject(wbsId);
|
|
228
|
-
const jobs = alasql('SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq', [wbsId]);
|
|
229
|
-
return { project, jobs };
|
|
230
|
-
},
|
|
231
|
-
delete(wbsId) {
|
|
232
|
-
const jobs = alasql('SELECT id FROM jobs WHERE wbs_id = ?', [wbsId]);
|
|
233
|
-
jobs.forEach(j => alasql('DELETE FROM executions WHERE job_id = ?', [j.id]));
|
|
234
|
-
alasql('DELETE FROM jobs WHERE wbs_id = ?', [wbsId]);
|
|
235
|
-
alasql('DELETE FROM wbs WHERE id = ?', [wbsId]);
|
|
236
|
-
saveData();
|
|
237
|
-
},
|
|
238
|
-
getActiveProjects() {
|
|
239
|
-
return alasql("SELECT * FROM wbs WHERE status = 'running'");
|
|
240
|
-
},
|
|
241
|
-
setStatus(wbsId, status) {
|
|
242
|
-
alasql('UPDATE wbs SET status = ? WHERE id = ?', [status, wbsId]);
|
|
243
|
-
saveData();
|
|
244
|
-
},
|
|
245
|
-
updateDetailPath(wbsId, detailPath) {
|
|
246
|
-
alasql('UPDATE wbs SET detail_path = ? WHERE id = ?', [detailPath, wbsId]);
|
|
247
|
-
saveData();
|
|
248
|
-
},
|
|
249
|
-
addJob(wbsId, opts) {
|
|
250
|
-
const id = getNextId('jobs', 'job-');
|
|
251
|
-
alasql('INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [id, wbsId, opts.title, opts.description ?? null, opts.agent, 'pending', opts.seq ?? 0, new Date().toISOString(), null, opts.issue_number ?? null, opts.no_git ?? false]);
|
|
252
|
-
saveData();
|
|
253
|
-
return id;
|
|
254
|
-
},
|
|
255
|
-
getJob(jobId) {
|
|
256
|
-
const rows = alasql('SELECT * FROM jobs WHERE id = ?', [jobId]);
|
|
257
|
-
return rows[0] ?? null;
|
|
258
|
-
},
|
|
259
|
-
listJobs(wbsId) {
|
|
260
|
-
return alasql('SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq', [wbsId]);
|
|
261
|
-
},
|
|
262
|
-
getJobsBySeq(wbsId, seq, status) {
|
|
263
|
-
if (status) {
|
|
264
|
-
return alasql('SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? AND status = ? ORDER BY created_at ASC', [wbsId, seq, status]);
|
|
265
|
-
}
|
|
266
|
-
return alasql('SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? ORDER BY created_at ASC', [wbsId, seq]);
|
|
267
|
-
},
|
|
268
|
-
getNextSeq(wbsId) {
|
|
269
|
-
const rows = alasql('SELECT MIN(seq) as nextSeq FROM jobs WHERE wbs_id = ? AND status = ?', [wbsId, 'pending']);
|
|
270
|
-
return rows[0]?.nextSeq ?? null;
|
|
271
|
-
},
|
|
272
|
-
getNextJob(wbsId) {
|
|
273
|
-
const jobs = alasql('SELECT * FROM jobs WHERE wbs_id = ? AND status = ? ORDER BY seq', [wbsId, 'pending']);
|
|
274
|
-
return jobs[0] ?? null;
|
|
275
|
-
},
|
|
276
|
-
updateJob(jobId, fields) {
|
|
277
|
-
const updates = [];
|
|
278
|
-
const values = [];
|
|
279
|
-
if (fields.status !== undefined) {
|
|
280
|
-
updates.push('status = ?');
|
|
281
|
-
values.push(fields.status);
|
|
282
|
-
if (fields.status === 'completed' || fields.status === 'failed') {
|
|
283
|
-
updates.push('completed_at = ?');
|
|
284
|
-
values.push(new Date().toISOString());
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (fields.title !== undefined) {
|
|
288
|
-
updates.push('title = ?');
|
|
289
|
-
values.push(fields.title);
|
|
290
|
-
}
|
|
291
|
-
if (fields.agent !== undefined) {
|
|
292
|
-
updates.push('agent = ?');
|
|
293
|
-
values.push(fields.agent);
|
|
294
|
-
}
|
|
295
|
-
if (fields.seq !== undefined) {
|
|
296
|
-
updates.push('seq = ?');
|
|
297
|
-
values.push(fields.seq);
|
|
298
|
-
}
|
|
299
|
-
if (fields.description !== undefined) {
|
|
300
|
-
updates.push('description = ?');
|
|
301
|
-
values.push(fields.description);
|
|
302
|
-
}
|
|
303
|
-
if (fields.issue_number !== undefined) {
|
|
304
|
-
updates.push('issue_number = ?');
|
|
305
|
-
values.push(fields.issue_number);
|
|
306
|
-
}
|
|
307
|
-
if (fields.no_git !== undefined) {
|
|
308
|
-
updates.push('no_git = ?');
|
|
309
|
-
values.push(fields.no_git);
|
|
310
|
-
}
|
|
311
|
-
if (updates.length === 0)
|
|
312
|
-
return;
|
|
313
|
-
values.push(jobId);
|
|
314
|
-
alasql(`UPDATE jobs SET ${updates.join(', ')} WHERE id = ?`, values);
|
|
315
|
-
saveData();
|
|
316
|
-
},
|
|
317
|
-
createExecution(jobId, pid) {
|
|
318
|
-
const id = getNextId('executions', 'exec-');
|
|
319
|
-
alasql('INSERT INTO executions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [id, jobId, pid, 'running', new Date().toISOString(), null, null, null, null]);
|
|
320
|
-
saveData();
|
|
321
|
-
return id;
|
|
322
|
-
},
|
|
323
|
-
getExecution(execId) {
|
|
324
|
-
const rows = alasql('SELECT * FROM executions WHERE id = ?', [execId]);
|
|
325
|
-
return rows[0] ?? null;
|
|
326
|
-
},
|
|
327
|
-
listExecutions(jobId) {
|
|
328
|
-
return alasql('SELECT * FROM executions WHERE job_id = ? ORDER BY started_at DESC', [jobId]);
|
|
329
|
-
},
|
|
330
|
-
getRunningExecutions() {
|
|
331
|
-
return alasql("SELECT * FROM executions WHERE status = 'running'");
|
|
332
|
-
},
|
|
333
|
-
updateExecution(execId, status, opts = {}) {
|
|
334
|
-
if (status !== 'running') {
|
|
335
|
-
alasql('UPDATE executions SET status = ?, ended_at = ?, exit_code = ?, error = ?, task_id = ? WHERE id = ?', [status, new Date().toISOString(), opts.exitCode ?? null, opts.error ?? null, opts.taskId ?? null, execId]);
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
alasql('UPDATE executions SET status = ? WHERE id = ?', [status, execId]);
|
|
339
|
-
}
|
|
340
|
-
saveData();
|
|
341
|
-
},
|
|
342
|
-
killExecution(execId) {
|
|
343
|
-
const exec = this.getExecution(execId);
|
|
344
|
-
if (!exec || exec.status !== 'running')
|
|
345
|
-
return false;
|
|
346
|
-
const proc = runningProcesses.get(execId);
|
|
347
|
-
if (proc) {
|
|
348
|
-
try {
|
|
349
|
-
proc.kill('SIGTERM');
|
|
350
|
-
}
|
|
351
|
-
catch { }
|
|
352
|
-
runningProcesses.delete(execId);
|
|
353
|
-
}
|
|
354
|
-
else if (exec.pid) {
|
|
355
|
-
try {
|
|
356
|
-
process.kill(exec.pid, 'SIGTERM');
|
|
357
|
-
}
|
|
358
|
-
catch { }
|
|
359
|
-
}
|
|
360
|
-
this.updateExecution(execId, 'killed');
|
|
361
|
-
const job = this.getJob(exec.job_id);
|
|
362
|
-
if (job && job.status === 'running') {
|
|
363
|
-
this.updateJob(exec.job_id, { status: 'failed' });
|
|
364
|
-
}
|
|
365
|
-
return true;
|
|
366
|
-
},
|
|
367
|
-
async runWorker(job) {
|
|
368
|
-
this.updateJob(job.id, { status: 'running' });
|
|
369
|
-
console.log(`[WBS] Running job: ${job.title}`);
|
|
370
|
-
console.log(`[WBS] Agent: ${job.agent}`);
|
|
371
|
-
if (job.description) {
|
|
372
|
-
console.log(`[WBS] Description: ${job.description.substring(0, 100)}${job.description.length > 100 ? '...' : ''}`);
|
|
373
|
-
}
|
|
374
|
-
const project = this.getProject(job.wbs_id);
|
|
375
|
-
let detailContent = null;
|
|
376
|
-
if (project?.detail_path) {
|
|
377
|
-
const fullPath = path.isAbsolute(project.detail_path)
|
|
378
|
-
? project.detail_path
|
|
379
|
-
: path.join(process.cwd(), project.detail_path);
|
|
380
|
-
if (fs.existsSync(fullPath)) {
|
|
381
|
-
try {
|
|
382
|
-
detailContent = fs.readFileSync(fullPath, 'utf8');
|
|
383
|
-
}
|
|
384
|
-
catch { }
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
console.log('[WBS] Timeout: 30 minutes');
|
|
388
|
-
console.log('─'.repeat(50));
|
|
389
|
-
let prompt = job.title;
|
|
390
|
-
if (detailContent)
|
|
391
|
-
prompt = `[프로젝트 상세]\n${detailContent}\n\n[작업]\n${prompt}`;
|
|
392
|
-
if (job.description)
|
|
393
|
-
prompt += `\n\n상세 지시:\n${job.description}`;
|
|
394
|
-
if (job.issue_number) {
|
|
395
|
-
prompt += `\n\n## 작업 지시\nGitHub Issue #${job.issue_number}를 처리하세요.\n\n**당신의 기존 개발 프로세스를 따르세요:**\n1. \`gh issue view ${job.issue_number}\`로 이슈 확인\n2. 브랜치 생성 및 작업\n3. PR 생성\n4. 이슈에 결과 코멘트\n\nWBS 추적 정보:\n- WBS: ${job.wbs_id}\n- Job: ${job.id}\n`;
|
|
396
|
-
}
|
|
397
|
-
else if (!job.no_git) {
|
|
398
|
-
const branch = `feature/${getJobSlug(job)}`;
|
|
399
|
-
const sourceBranch = project?.source_branch || getSourceBranch();
|
|
400
|
-
const targetBranch = project?.target_branch || getTargetBranch();
|
|
401
|
-
const mergeStrategy = getMergeStrategy();
|
|
402
|
-
if (mergeStrategy === 'pr') {
|
|
403
|
-
prompt += `\n\n## 작업 지시 (WBS 독립 작업)\n\n이 작업은 GitHub Issue 없이 WBS에서 직접 생성된 작업입니다.\n\n### Git 워크플로우\n\`\`\`bash\ngit worktree add worktree/${branch} -b ${branch} ${sourceBranch}\ncd worktree/${branch}\ngh pr create --base ${targetBranch} --title "[WBS-${job.wbs_id}] ${job.title}" --body "WBS Job: ${job.id}"\n\`\`\`\n\n### 주의사항\n- main/develop에서 직접 작업 금지\n- 반드시 worktree에서 작업\n- PR 생성 후 링크 출력\n\nWBS 추적 정보:\n- WBS: ${job.wbs_id}\n- Job: ${job.id}\n- 브랜치: ${branch}\n- Source 브랜치: ${sourceBranch}\n- Target 브랜치: ${targetBranch}\n`;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
prompt += `\n\n## 작업 지시 (WBS 독립 작업)\n\n이 작업은 GitHub Issue 없이 WBS에서 직접 생성된 작업입니다.\n\n### Git 워크플로우 (로컬 머지)\n\`\`\`bash\ngit worktree add worktree/${branch} -b ${branch} ${sourceBranch}\ncd worktree/${branch}\n# ... 작업 후 커밋 ...\ngit checkout ${targetBranch}\ngit merge ${branch} --no-ff -m 'merge: [WBS-${job.wbs_id}] ${job.title}'\ngit worktree remove worktree/${branch}\ngit branch -d ${branch}\n\`\`\`\n\n### 주의사항\n- main/develop에서 직접 작업 금지\n- 반드시 worktree에서 작업 후 로컬 머지\n- 머지 완료 후 worktree 및 브랜치 정리\n\nWBS 추적 정보:\n- WBS: ${job.wbs_id}\n- Job: ${job.id}\n- 브랜치: ${branch}\n- Source 브랜치: ${sourceBranch}\n- Target 브랜치: ${targetBranch}\n`;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
prompt += `\n\n## 작업 지시 (WBS 독립 작업)\n\n이 작업은 GitHub Issue 없이 WBS에서 직접 생성된 작업입니다.\n\n### 주의사항\n- 이 작업은 \`--no-git\`로 생성되어 Git worktree/PR 템플릿을 생략합니다.\n- 작업 성격에 맞는 절차(예: 디자인/리서치/문서 작업)를 따르세요.\n\nWBS 추적 정보:\n- WBS: ${job.wbs_id}\n- Job: ${job.id}\n- no_git: true\n`;
|
|
411
|
-
}
|
|
412
|
-
return new Promise((resolve) => {
|
|
413
|
-
const env = { ...process.env };
|
|
414
|
-
delete env.CLAUDECODE;
|
|
415
|
-
const child = (0, child_process_1.spawn)('crewx', ['x', `${job.agent} ${prompt}`], {
|
|
416
|
-
stdio: ['inherit', 'pipe', 'inherit'],
|
|
417
|
-
cwd: getProjectRoot(),
|
|
418
|
-
env,
|
|
419
|
-
});
|
|
420
|
-
let stdoutBuffer = '';
|
|
421
|
-
child.stdout?.on('data', (chunk) => {
|
|
422
|
-
const text = chunk.toString();
|
|
423
|
-
process.stdout.write(chunk);
|
|
424
|
-
stdoutBuffer += text;
|
|
425
|
-
});
|
|
426
|
-
const execId = this.createExecution(job.id, child.pid ?? null);
|
|
427
|
-
runningProcesses.set(execId, child);
|
|
428
|
-
console.log(`[WBS] Execution ID: ${execId}`);
|
|
429
|
-
console.log(`[WBS] PID: ${child.pid}`);
|
|
430
|
-
const extractTaskId = () => {
|
|
431
|
-
const match = stdoutBuffer.match(/Task ID:\s*(\S+)/);
|
|
432
|
-
return match?.[1];
|
|
433
|
-
};
|
|
434
|
-
const timeout = setTimeout(() => {
|
|
435
|
-
console.error('[WBS] Timeout reached, killing process...');
|
|
436
|
-
child.kill('SIGTERM');
|
|
437
|
-
this.updateExecution(execId, 'failed', { error: 'Timeout (30 minutes)', taskId: extractTaskId() });
|
|
438
|
-
this.updateJob(job.id, { status: 'failed' });
|
|
439
|
-
runningProcesses.delete(execId);
|
|
440
|
-
resolve({ success: false, error: 'Timeout', execId });
|
|
441
|
-
}, 30 * 60 * 1000);
|
|
442
|
-
child.on('close', (code) => {
|
|
443
|
-
clearTimeout(timeout);
|
|
444
|
-
runningProcesses.delete(execId);
|
|
445
|
-
const taskId = extractTaskId();
|
|
446
|
-
console.log('─'.repeat(50));
|
|
447
|
-
if (taskId) {
|
|
448
|
-
console.log(`[WBS] Traced Task ID: ${taskId}`);
|
|
449
|
-
}
|
|
450
|
-
if (code === 0) {
|
|
451
|
-
this.updateExecution(execId, 'completed', { exitCode: code, taskId });
|
|
452
|
-
this.updateJob(job.id, { status: 'completed' });
|
|
453
|
-
console.log(`[WBS] Job completed: ${job.title}`);
|
|
454
|
-
resolve({ success: true, execId });
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
this.updateExecution(execId, 'failed', { exitCode: code ?? undefined, error: `Exit code: ${code}`, taskId });
|
|
458
|
-
this.updateJob(job.id, { status: 'failed' });
|
|
459
|
-
console.error(`[WBS] Job failed: ${job.title} (exit: ${code})`);
|
|
460
|
-
resolve({ success: false, error: `Exit code: ${code}`, execId });
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
child.on('error', (err) => {
|
|
464
|
-
clearTimeout(timeout);
|
|
465
|
-
runningProcesses.delete(execId);
|
|
466
|
-
this.updateExecution(execId, 'failed', { error: err.message, taskId: extractTaskId() });
|
|
467
|
-
this.updateJob(job.id, { status: 'failed' });
|
|
468
|
-
console.error('─'.repeat(50));
|
|
469
|
-
console.error(`[WBS] Job failed: ${job.title}`);
|
|
470
|
-
console.error(`[WBS] Error: ${err.message}`);
|
|
471
|
-
resolve({ success: false, error: err.message, execId });
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
},
|
|
475
|
-
async run(wbsId, opts = {}) {
|
|
476
|
-
const project = this.getProject(wbsId);
|
|
477
|
-
if (!project) {
|
|
478
|
-
console.error(`[WBS] Project not found: ${wbsId}`);
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
const parallel = opts.parallel ?? false;
|
|
482
|
-
console.log(`\n${'═'.repeat(50)}`);
|
|
483
|
-
console.log(`[WBS] Starting project: ${project.title}`);
|
|
484
|
-
console.log(`[WBS] Mode: ${parallel ? 'parallel-by-seq' : 'sequential'}`);
|
|
485
|
-
console.log(`${'═'.repeat(50)}\n`);
|
|
486
|
-
this.setStatus(wbsId, 'running');
|
|
487
|
-
let completed = 0;
|
|
488
|
-
let failed = 0;
|
|
489
|
-
if (!parallel) {
|
|
490
|
-
let job;
|
|
491
|
-
while ((job = this.getNextJob(wbsId)) !== null) {
|
|
492
|
-
const result = await this.runWorker(job);
|
|
493
|
-
if (result.success)
|
|
494
|
-
completed++;
|
|
495
|
-
else
|
|
496
|
-
failed++;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
let nextSeq;
|
|
501
|
-
while ((nextSeq = this.getNextSeq(wbsId)) !== null) {
|
|
502
|
-
const jobs = this.getJobsBySeq(wbsId, nextSeq, 'pending');
|
|
503
|
-
if (jobs.length === 0)
|
|
504
|
-
continue;
|
|
505
|
-
console.log(`[WBS] Running seq group ${nextSeq} (${jobs.length} job(s)) in parallel`);
|
|
506
|
-
const results = await Promise.all(jobs.map(job => this.runWorker(job)));
|
|
507
|
-
for (const result of results) {
|
|
508
|
-
if (result.success)
|
|
509
|
-
completed++;
|
|
510
|
-
else
|
|
511
|
-
failed++;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
this.setStatus(wbsId, failed === 0 ? 'completed' : 'partial');
|
|
516
|
-
console.log(`\n${'═'.repeat(50)}`);
|
|
517
|
-
console.log(`[WBS] Project ${failed === 0 ? 'completed' : 'partial'}: ${project.title}`);
|
|
518
|
-
console.log(`[WBS] Completed: ${completed}, Failed: ${failed}`);
|
|
519
|
-
console.log(`${'═'.repeat(50)}\n`);
|
|
520
|
-
},
|
|
521
|
-
daemonPidFile: DAEMON_PID_FILE,
|
|
522
|
-
daemonLogFile: DAEMON_LOG_FILE,
|
|
523
|
-
isProcessAlive(pid) {
|
|
524
|
-
try {
|
|
525
|
-
process.kill(pid, 0);
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
catch {
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
},
|
|
532
|
-
checkAndFixZombies() {
|
|
533
|
-
const running = this.getRunningExecutions();
|
|
534
|
-
const zombies = [];
|
|
535
|
-
const now = Date.now();
|
|
536
|
-
for (const exec of running) {
|
|
537
|
-
const elapsed = now - new Date(exec.started_at).getTime();
|
|
538
|
-
const alive = exec.pid ? this.isProcessAlive(exec.pid) : false;
|
|
539
|
-
if (!alive || elapsed > exports.ZOMBIE_TIMEOUT_MS) {
|
|
540
|
-
const reason = !alive ? 'Process dead' : 'Timeout (30min)';
|
|
541
|
-
alasql('UPDATE executions SET status = ?, ended_at = ?, error = ? WHERE id = ?', ['failed', new Date().toISOString(), `Zombie: ${reason}`, exec.id]);
|
|
542
|
-
alasql('UPDATE jobs SET status = ?, completed_at = ? WHERE id = ?', ['failed', new Date().toISOString(), exec.job_id]);
|
|
543
|
-
zombies.push({ execId: exec.id, jobId: exec.job_id, pid: exec.pid, reason });
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
if (zombies.length > 0)
|
|
547
|
-
saveData();
|
|
548
|
-
return zombies;
|
|
549
|
-
},
|
|
550
|
-
};
|
|
551
|
-
//# sourceMappingURL=engine.js.map
|
|
1
|
+
"use strict";var A=exports&&exports.__createBinding||(Object.create?(function(t,e,n,s){if(s===void 0)s=n;var i=Object.getOwnPropertyDescriptor(e,n);if(!i||("get"in i?!e.__esModule:i.writable||i.configurable)){i={enumerable:true,get:function(){return e[n]}}}Object.defineProperty(t,s,i)}):(function(t,e,n,s){if(s===void 0)s=n;t[s]=e[n]}));var C=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:true,value:e})}):function(t,e){t["default"]=e});var $=exports&&exports.__importStar||(function(){var t=function(e){t=Object.getOwnPropertyNames||function(n){var s=[];for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i))s[s.length]=i;return s};return t(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null){for(var s=t(e),i=0;i<s.length;i++)if(s[i]!=="default")A(n,e,s[i])}C(n,e);return n}})();Object.defineProperty(exports,"__esModule",{value:true});exports.engine=exports.ZOMBIE_TIMEOUT_MS=exports.DAEMON_INTERVAL_MS=void 0;exports.getProjectRoot=O;exports.getJobSlug=D;exports.resolveJobId=H;exports.generateDetailFile=q;const I=require("child_process");const h=$(require("path"));const g=$(require("fs"));const y=$(require("js-yaml"));const T=require("@crewx/sdk");const r=require("alasql");const w=h.join(process.cwd(),".crewx");const W=h.join(w,".wbs-data.json");const k=h.join(w,".wbs-daemon.pid");const F=h.join(w,".wbs-daemon.log");exports.DAEMON_INTERVAL_MS=5*60*1e3;exports.ZOMBIE_TIMEOUT_MS=30*60*1e3;const _=new Map;function O(){try{return(0,I.execSync)("git rev-parse --show-toplevel",{encoding:"utf8"}).trim()}catch{return process.cwd()}}function N(){try{const t=process.env.CREWX_CONFIG??h.join(O(),"crewx.yaml");const e=g.readFileSync(t,"utf8");const n=y.load(e);const s=n?.settings;return s?.wbs??{}}catch{return{}}}function M(){try{return(0,I.execSync)("git branch --show-current",{encoding:"utf8"}).trim()}catch{return"main"}}function P(){const t=N();const e=t.base_branch;const n=t.source_branch??e;if(!n||n==="auto")return M();return n}function L(){const t=N();const e=t.base_branch;const n=t.target_branch??e;if(!n||n==="auto")return M();return n}function v(){const t=N();if(t.merge_strategy==="pr")return"pr";return"local"}function B(t,e){const n=e.length;const s=r(`SELECT MAX(CAST(SUBSTR(id, ${n+1}) AS INT)) as max FROM ${t}`)[0];return`${e}${(s.max||0)+1}`}function b(){if(!g.existsSync(w)){g.mkdirSync(w,{recursive:true})}const t={wbs:r("SELECT * FROM wbs"),jobs:r("SELECT * FROM jobs"),executions:r("SELECT * FROM executions")};g.writeFileSync(W,JSON.stringify(t,null,2))}function j(){r("CREATE TABLE IF NOT EXISTS wbs (id STRING PRIMARY KEY, title STRING, detail_path STRING, status STRING, created_at STRING, source_branch STRING, target_branch STRING)");r("CREATE TABLE IF NOT EXISTS jobs (id STRING PRIMARY KEY, wbs_id STRING, title STRING, description STRING, agent STRING, status STRING, seq INT, created_at STRING, completed_at STRING, issue_number INT, no_git BOOLEAN)");r("CREATE TABLE IF NOT EXISTS executions (id STRING PRIMARY KEY, job_id STRING, pid INT, status STRING, started_at STRING, ended_at STRING, exit_code INT, error STRING, task_id STRING)");if(g.existsSync(W)){try{const t=JSON.parse(g.readFileSync(W,"utf8"));(t.wbs||[]).forEach(e=>{r("INSERT INTO wbs VALUES (?, ?, ?, ?, ?, ?, ?)",[e.id,e.title,e.detail_path??null,e.status,e.created_at,e.source_branch??null,e.target_branch??null])});(t.jobs||[]).forEach(e=>{r("INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",[e.id,e.wbs_id,e.title,e.description??null,e.agent,e.status,e.seq,e.created_at,e.completed_at,e.issue_number??null,e.no_git??false])});(t.executions||[]).forEach(e=>{r("INSERT INTO executions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[e.id,e.job_id,e.pid,e.status,e.started_at,e.ended_at,e.exit_code,e.error,e.task_id??null])})}catch(t){const e=t;console.error("Warning: Could not load persisted data:",e.message)}}}j();function D(t){const e=t.wbs_id.replace("wbs-","");return`wbs-${e}-${t.seq}`}function H(t){if(t.startsWith("job-")){const s=r("SELECT * FROM jobs WHERE id = ?",[t]);return s[0]??null}const e=t.match(/^wbs-(\d+)-(\d+)$/);if(e){const s=`wbs-${e[1]}`;const i=parseInt(e[2]??"0",10);const a=r("SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? ORDER BY created_at ASC",[s,i]);return a[0]??null}const n=r("SELECT * FROM jobs WHERE id = ?",[t]);return n[0]??null}function q(t){const e=r("SELECT * FROM wbs WHERE id = ?",[t]);if(!e[0])return;const n=e[0];const s=r("SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq, created_at",[t]);const i=[];i.push(`# ${n.title}`);i.push("");i.push(`> WBS ID: ${n.id} | Status: ${n.status} | Jobs: ${s.length}`);i.push("");i.push("## Jobs");i.push("");if(s.length===0){i.push("(No jobs registered yet)")}else{for(const u of s){const p=D(u);i.push(`### ${p}: ${u.title}`);i.push("");i.push(`- **Agent**: ${u.agent}`);i.push(`- **Seq**: ${u.seq}`);i.push(`- **Status**: ${u.status}`);i.push(`- **ID**: ${u.id}`);if(u.description){i.push("");i.push("**AC / Description:**");i.push("");i.push(u.description)}i.push("")}}let a=n.detail_path;if(!a){const u=h.join(process.cwd(),"wbs-details");if(!g.existsSync(u))g.mkdirSync(u,{recursive:true});a=`wbs-details/${t}-detail.md`;r("UPDATE wbs SET detail_path = ? WHERE id = ?",[a,t]);b()}const c=h.isAbsolute(a)?a:h.join(process.cwd(),a);const E=h.dirname(c);if(!g.existsSync(E))g.mkdirSync(E,{recursive:true});g.writeFileSync(c,i.join("\n"))}exports.engine={create(t,e=null,n,s){const i=B("wbs","wbs-");r("INSERT INTO wbs VALUES (?, ?, ?, ?, ?, ?, ?)",[i,t,e,"planning",new Date().toISOString(),n??null,s??null]);b();return i},list(){return r("SELECT * FROM wbs ORDER BY created_at DESC")},getProject(t){const e=r("SELECT * FROM wbs WHERE id = ?",[t]);return e[0]??null},status(t){const e=this.getProject(t);const n=r("SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq",[t]);return{project:e,jobs:n}},delete(t){const e=r("SELECT id FROM jobs WHERE wbs_id = ?",[t]);e.forEach(n=>r("DELETE FROM executions WHERE job_id = ?",[n.id]));r("DELETE FROM jobs WHERE wbs_id = ?",[t]);r("DELETE FROM wbs WHERE id = ?",[t]);b()},getActiveProjects(){return r("SELECT * FROM wbs WHERE status = 'running'")},setStatus(t,e){r("UPDATE wbs SET status = ? WHERE id = ?",[e,t]);b()},updateDetailPath(t,e){r("UPDATE wbs SET detail_path = ? WHERE id = ?",[e,t]);b()},addJob(t,e){const n=B("jobs","job-");r("INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",[n,t,e.title,e.description??null,e.agent,"pending",e.seq??0,new Date().toISOString(),null,e.issue_number??null,e.no_git??false]);b();return n},getJob(t){const e=r("SELECT * FROM jobs WHERE id = ?",[t]);return e[0]??null},listJobs(t){return r("SELECT * FROM jobs WHERE wbs_id = ? ORDER BY seq",[t])},getJobsBySeq(t,e,n){if(n){return r("SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? AND status = ? ORDER BY created_at ASC",[t,e,n])}return r("SELECT * FROM jobs WHERE wbs_id = ? AND seq = ? ORDER BY created_at ASC",[t,e])},getNextSeq(t){const e=r("SELECT MIN(seq) as nextSeq FROM jobs WHERE wbs_id = ? AND status = ?",[t,"pending"]);return e[0]?.nextSeq??null},getNextJob(t){const e=r("SELECT * FROM jobs WHERE wbs_id = ? AND status = ? ORDER BY seq",[t,"pending"]);return e[0]??null},updateJob(t,e){const n=[];const s=[];if(e.status!==void 0){n.push("status = ?");s.push(e.status);if(e.status==="completed"||e.status==="failed"){n.push("completed_at = ?");s.push(new Date().toISOString())}}if(e.title!==void 0){n.push("title = ?");s.push(e.title)}if(e.agent!==void 0){n.push("agent = ?");s.push(e.agent)}if(e.seq!==void 0){n.push("seq = ?");s.push(e.seq)}if(e.description!==void 0){n.push("description = ?");s.push(e.description)}if(e.issue_number!==void 0){n.push("issue_number = ?");s.push(e.issue_number)}if(e.no_git!==void 0){n.push("no_git = ?");s.push(e.no_git)}if(n.length===0)return;s.push(t);r(`UPDATE jobs SET ${n.join(", ")} WHERE id = ?`,s);b()},createExecution(t,e){const n=B("executions","exec-");r("INSERT INTO executions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[n,t,e,"running",new Date().toISOString(),null,null,null,null]);b();return n},getExecution(t){const e=r("SELECT * FROM executions WHERE id = ?",[t]);return e[0]??null},listExecutions(t){return r("SELECT * FROM executions WHERE job_id = ? ORDER BY started_at DESC",[t])},getRunningExecutions(){return r("SELECT * FROM executions WHERE status = 'running'")},updateExecution(t,e,n={}){if(e!=="running"){r("UPDATE executions SET status = ?, ended_at = ?, exit_code = ?, error = ?, task_id = ? WHERE id = ?",[e,new Date().toISOString(),n.exitCode??null,n.error??null,n.taskId??null,t])}else{r("UPDATE executions SET status = ? WHERE id = ?",[e,t])}b()},killExecution(t){const e=this.getExecution(t);if(!e||e.status!=="running")return false;const n=_.get(t);if(n){try{n.kill("SIGTERM")}catch{}_.delete(t)}else if(e.pid){try{process.kill(e.pid,"SIGTERM")}catch{}}this.updateExecution(t,"killed");const s=this.getJob(e.job_id);if(s&&s.status==="running"){this.updateJob(e.job_id,{status:"failed"})}return true},async runWorker(t){this.updateJob(t.id,{status:"running"});console.log(`[WBS] Running job: ${t.title}`);console.log(`[WBS] Agent: ${t.agent}`);if(t.description){console.log(`[WBS] Description: ${t.description.substring(0,100)}${t.description.length>100?"...":""}`)}const e=this.getProject(t.wbs_id);let n=null;if(e?.detail_path){const o=h.isAbsolute(e.detail_path)?e.detail_path:h.join(process.cwd(),e.detail_path);if(g.existsSync(o)){try{n=g.readFileSync(o,"utf8")}catch{}}}console.log("[WBS] Timeout: 30 minutes");console.log("\u2500".repeat(50));let s=t.title;if(n)s=`[Project Details]
|
|
2
|
+
${n}
|
|
3
|
+
|
|
4
|
+
[Task]
|
|
5
|
+
${s}`;if(t.description)s+=`
|
|
6
|
+
|
|
7
|
+
Detailed instruction:
|
|
8
|
+
${t.description}`;if(t.issue_number){s+=`
|
|
9
|
+
|
|
10
|
+
## Work Instruction
|
|
11
|
+
Handle GitHub Issue #${t.issue_number}.
|
|
12
|
+
|
|
13
|
+
**Follow your normal development process:**
|
|
14
|
+
1. Run \`gh issue view ${t.issue_number}\` to view the issue
|
|
15
|
+
2. Create a branch and implement the change
|
|
16
|
+
3. Create a PR
|
|
17
|
+
4. Comment the result on the issue
|
|
18
|
+
|
|
19
|
+
WBS tracking info:
|
|
20
|
+
- WBS: ${t.wbs_id}
|
|
21
|
+
- Job: ${t.id}
|
|
22
|
+
`}else if(!t.no_git){const o=`feature/${D(t)}`;const S=e?.source_branch||P();const f=e?.target_branch||L();const l=v();if(l==="pr"){s+=`
|
|
23
|
+
|
|
24
|
+
## Work Instruction (WBS standalone job)
|
|
25
|
+
|
|
26
|
+
This job was created directly in WBS without a GitHub Issue.
|
|
27
|
+
|
|
28
|
+
### Git workflow
|
|
29
|
+
\`\`\`bash
|
|
30
|
+
git worktree add worktree/${o} -b ${o} ${S}
|
|
31
|
+
cd worktree/${o}
|
|
32
|
+
gh pr create --base ${f} --title "[WBS-${t.wbs_id}] ${t.title}" --body "WBS Job: ${t.id}"
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
### Notes
|
|
36
|
+
- Do not work directly on main/develop
|
|
37
|
+
- Work in the worktree
|
|
38
|
+
- Print the PR link after creating it
|
|
39
|
+
|
|
40
|
+
WBS tracking info:
|
|
41
|
+
- WBS: ${t.wbs_id}
|
|
42
|
+
- Job: ${t.id}
|
|
43
|
+
- Branch: ${o}
|
|
44
|
+
- Source branch: ${S}
|
|
45
|
+
- Target branch: ${f}
|
|
46
|
+
`}else{s+=`
|
|
47
|
+
|
|
48
|
+
## Work Instruction (WBS standalone job)
|
|
49
|
+
|
|
50
|
+
This job was created directly in WBS without a GitHub Issue.
|
|
51
|
+
|
|
52
|
+
### Git workflow (local merge)
|
|
53
|
+
\`\`\`bash
|
|
54
|
+
git worktree add worktree/${o} -b ${o} ${S}
|
|
55
|
+
cd worktree/${o}
|
|
56
|
+
# ... commit after completing the work ...
|
|
57
|
+
git checkout ${f}
|
|
58
|
+
git merge ${o} --no-ff -m 'merge: [WBS-${t.wbs_id}] ${t.title}'
|
|
59
|
+
git worktree remove worktree/${o}
|
|
60
|
+
git branch -d ${o}
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
### Notes
|
|
64
|
+
- Do not work directly on main/develop
|
|
65
|
+
- Work in the worktree, then merge locally
|
|
66
|
+
- Clean up the worktree and branch after the merge
|
|
67
|
+
|
|
68
|
+
WBS tracking info:
|
|
69
|
+
- WBS: ${t.wbs_id}
|
|
70
|
+
- Job: ${t.id}
|
|
71
|
+
- Branch: ${o}
|
|
72
|
+
- Source branch: ${S}
|
|
73
|
+
- Target branch: ${f}
|
|
74
|
+
`}}else{s+=`
|
|
75
|
+
|
|
76
|
+
## Work Instruction (WBS standalone job)
|
|
77
|
+
|
|
78
|
+
This job was created directly in WBS without a GitHub Issue.
|
|
79
|
+
|
|
80
|
+
### Notes
|
|
81
|
+
- This job was created with \`--no-git\`, so Git worktree/PR templates are omitted.
|
|
82
|
+
- Follow the process appropriate for the work, such as design, research, or docs.
|
|
83
|
+
|
|
84
|
+
WBS tracking info:
|
|
85
|
+
- WBS: ${t.wbs_id}
|
|
86
|
+
- Job: ${t.id}
|
|
87
|
+
- no_git: true
|
|
88
|
+
`}const i=O();const a={...process.env};delete a.CLAUDECODE;const c=(0,T.resolveCrewxExecutable)({env:a,cwd:i});if(!c.ok){const o=(0,T.formatCrewxExecutableFailure)(c);this.updateJob(t.id,{status:"failed"});console.error(`[WBS] Job failed: ${t.title}`);console.error(`[WBS] Error: ${o}`);return{success:false,error:o,execId:""}}const E=(0,T.createCrewxChildInvocation)(c,{baseEnv:a});const u=(0,T.resolveWindowsSpawnProgram)({command:E.command,env:E.env,cwd:i,packageName:"crewx",allowShellFallback:true});const p=(0,T.materializeWindowsSpawnProgram)(u,[...E.args,"x",`${t.agent} ${s}`]);return new Promise(o=>{const S=(0,I.spawn)(p.command,p.argv,{stdio:["inherit","pipe","inherit"],cwd:i,env:E.env,shell:p.shell??false,windowsHide:p.windowsHide});let f="";S.stdout?.on("data",d=>{const R=d.toString();process.stdout.write(d);f+=R});const l=this.createExecution(t.id,S.pid??null);_.set(l,S);console.log(`[WBS] Execution ID: ${l}`);console.log(`[WBS] PID: ${S.pid}`);const m=()=>{const d=f.match(/Task ID:\s*(\S+)/);return d?.[1]};const x=setTimeout(()=>{console.error("[WBS] Timeout reached, killing process...");S.kill("SIGTERM");this.updateExecution(l,"failed",{error:"Timeout (30 minutes)",taskId:m()});this.updateJob(t.id,{status:"failed"});_.delete(l);o({success:false,error:"Timeout",execId:l})},30*60*1e3);S.on("close",d=>{clearTimeout(x);_.delete(l);const R=m();console.log("\u2500".repeat(50));if(R){console.log(`[WBS] Traced Task ID: ${R}`)}if(d===0){this.updateExecution(l,"completed",{exitCode:d,taskId:R});this.updateJob(t.id,{status:"completed"});console.log(`[WBS] Job completed: ${t.title}`);o({success:true,execId:l})}else{this.updateExecution(l,"failed",{exitCode:d??void 0,error:`Exit code: ${d}`,taskId:R});this.updateJob(t.id,{status:"failed"});console.error(`[WBS] Job failed: ${t.title} (exit: ${d})`);o({success:false,error:`Exit code: ${d}`,execId:l})}});S.on("error",d=>{clearTimeout(x);_.delete(l);this.updateExecution(l,"failed",{error:d.message,taskId:m()});this.updateJob(t.id,{status:"failed"});console.error("\u2500".repeat(50));console.error(`[WBS] Job failed: ${t.title}`);console.error(`[WBS] Error: ${d.message}`);o({success:false,error:d.message,execId:l})})})},async run(t,e={}){const n=this.getProject(t);if(!n){console.error(`[WBS] Project not found: ${t}`);return}const s=e.parallel??false;console.log(`
|
|
89
|
+
${"\u2550".repeat(50)}`);console.log(`[WBS] Starting project: ${n.title}`);console.log(`[WBS] Mode: ${s?"parallel-by-seq":"sequential"}`);console.log(`${"\u2550".repeat(50)}
|
|
90
|
+
`);this.setStatus(t,"running");let i=0;let a=0;if(!s){let c;while((c=this.getNextJob(t))!==null){const E=await this.runWorker(c);if(E.success)i++;else a++}}else{let c;while((c=this.getNextSeq(t))!==null){const E=this.getJobsBySeq(t,c,"pending");if(E.length===0)continue;console.log(`[WBS] Running seq group ${c} (${E.length} job(s)) in parallel`);const u=await Promise.all(E.map(p=>this.runWorker(p)));for(const p of u){if(p.success)i++;else a++}}}this.setStatus(t,a===0?"completed":"partial");console.log(`
|
|
91
|
+
${"\u2550".repeat(50)}`);console.log(`[WBS] Project ${a===0?"completed":"partial"}: ${n.title}`);console.log(`[WBS] Completed: ${i}, Failed: ${a}`);console.log(`${"\u2550".repeat(50)}
|
|
92
|
+
`)},daemonPidFile:k,daemonLogFile:F,isProcessAlive(t){try{process.kill(t,0);return true}catch{return false}},checkAndFixZombies(){const t=this.getRunningExecutions();const e=[];const n=Date.now();for(const s of t){const i=n-new Date(s.started_at).getTime();const a=s.pid?this.isProcessAlive(s.pid):false;if(!a||i>exports.ZOMBIE_TIMEOUT_MS){const c=!a?"Process dead":"Timeout (30min)";r("UPDATE executions SET status = ?, ended_at = ?, error = ? WHERE id = ?",["failed",new Date().toISOString(),`Zombie: ${c}`,s.id]);r("UPDATE jobs SET status = ?, completed_at = ? WHERE id = ?",["failed",new Date().toISOString(),s.job_id]);e.push({execId:s.id,jobId:s.job_id,pid:s.pid,reason:c})}}if(e.length>0)b();return e}};
|