mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-06 01:54:11 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca6677149a | ||
|
|
880376aefc | ||
|
|
a20f81d44a |
@@ -212,14 +212,14 @@ Write solution JSON to JSONL file (one line per solution):
|
||||
|
||||
**File Format** (JSONL - each line is a complete solution):
|
||||
```
|
||||
{"id":"SOL-GH-123-1","description":"...","approach":"...","analysis":{...},"score":0.85,"tasks":[...]}
|
||||
{"id":"SOL-GH-123-2","description":"...","approach":"...","analysis":{...},"score":0.75,"tasks":[...]}
|
||||
{"id":"SOL-GH-123-a7x9","description":"...","approach":"...","analysis":{...},"score":0.85,"tasks":[...]}
|
||||
{"id":"SOL-GH-123-b2k4","description":"...","approach":"...","analysis":{...},"score":0.75,"tasks":[...]}
|
||||
```
|
||||
|
||||
**Solution Schema** (must match CLI `Solution` interface):
|
||||
```typescript
|
||||
{
|
||||
id: string; // Format: SOL-{issue-id}-{N}
|
||||
id: string; // Format: SOL-{issue-id}-{uid}
|
||||
description?: string;
|
||||
approach?: string;
|
||||
tasks: SolutionTask[];
|
||||
@@ -232,9 +232,14 @@ Write solution JSON to JSONL file (one line per solution):
|
||||
**Write Operation**:
|
||||
```javascript
|
||||
// Append solution to JSONL file (one line per solution)
|
||||
const solutionId = `SOL-${issueId}-${seq}`;
|
||||
// Use 4-char random uid to avoid collisions across multiple plan runs
|
||||
const uid = Math.random().toString(36).slice(2, 6); // e.g., "a7x9"
|
||||
const solutionId = `SOL-${issueId}-${uid}`;
|
||||
const solutionLine = JSON.stringify({ id: solutionId, ...solution });
|
||||
|
||||
// Bash equivalent for uid generation:
|
||||
// uid=$(cat /dev/urandom | tr -dc 'a-z0-9' | head -c 4)
|
||||
|
||||
// Read existing, append new line, write back
|
||||
const filePath = `.workflow/issues/solutions/${issueId}.jsonl`;
|
||||
const existing = existsSync(filePath) ? readFileSync(filePath) : '';
|
||||
@@ -311,7 +316,7 @@ Each line is a solution JSON containing tasks. Schema: `cat .claude/workflows/cl
|
||||
6. Evaluate each solution with `analysis` and `score`
|
||||
7. Write solutions to `.workflow/issues/solutions/{issue-id}.jsonl` (append mode)
|
||||
8. For HIGH complexity: generate 2-3 candidate solutions
|
||||
9. **Solution ID format**: `SOL-{issue-id}-{N}` (e.g., `SOL-GH-123-1`, `SOL-GH-123-2`)
|
||||
9. **Solution ID format**: `SOL-{issue-id}-{uid}` where uid is 4 random alphanumeric chars (e.g., `SOL-GH-123-a7x9`)
|
||||
10. **GitHub Reply Task**: If issue has `github_url` or `github_number`, add final task to comment on GitHub issue with completion summary
|
||||
|
||||
**CONFLICT AVOIDANCE** (for batch processing of similar issues):
|
||||
|
||||
@@ -203,7 +203,7 @@ ${issueList}
|
||||
7. Single solution → auto-bind; Multiple → return for selection
|
||||
|
||||
### Rules
|
||||
- Solution ID format: SOL-{issue-id}-{seq}
|
||||
- Solution ID format: SOL-{issue-id}-{uid} (uid: 4 random alphanumeric chars, e.g., a7x9)
|
||||
- Single solution per issue → auto-bind via ccw issue bind
|
||||
- Multiple solutions → register only, return pending_selection
|
||||
- Tasks must have quantified acceptance.criteria
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "Unique solution identifier: SOL-{issue-id}-{seq}",
|
||||
"pattern": "^SOL-.+-[0-9]+$",
|
||||
"examples": ["SOL-GH-123-1", "SOL-ISS-20251229-1"]
|
||||
"description": "Unique solution identifier: SOL-{issue-id}-{4-char-uid} where uid is 4 alphanumeric chars",
|
||||
"pattern": "^SOL-.+-[a-z0-9]{4}$",
|
||||
"examples": ["SOL-GH-123-a7x9", "SOL-ISS-20251229-001-b2k4"]
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
|
||||
@@ -60,12 +60,30 @@ function readDiscoveryIndex(discoveriesDir: string): { discoveries: any[]; total
|
||||
if (existsSync(statePath)) {
|
||||
try {
|
||||
const state = JSON.parse(readFileSync(statePath, 'utf8'));
|
||||
|
||||
// Extract perspectives - handle both old and new formats
|
||||
let perspectives: string[] = [];
|
||||
if (state.perspectives && Array.isArray(state.perspectives)) {
|
||||
// New format: string array or old format: object array
|
||||
if (state.perspectives.length > 0 && typeof state.perspectives[0] === 'object') {
|
||||
perspectives = state.perspectives.map((p: any) => p.name || p.perspective || '');
|
||||
} else {
|
||||
perspectives = state.perspectives;
|
||||
}
|
||||
} else if (state.metadata?.perspectives) {
|
||||
// Legacy format
|
||||
perspectives = state.metadata.perspectives;
|
||||
}
|
||||
|
||||
// Extract created_at - handle both formats
|
||||
const created_at = state.created_at || state.metadata?.created_at;
|
||||
|
||||
discoveries.push({
|
||||
discovery_id: entry.name,
|
||||
target_pattern: state.target_pattern,
|
||||
perspectives: state.metadata?.perspectives || [],
|
||||
created_at: state.metadata?.created_at,
|
||||
completed_at: state.completed_at
|
||||
perspectives,
|
||||
created_at,
|
||||
completed_at: state.completed_at || state.updated_at
|
||||
});
|
||||
} catch {
|
||||
// Skip invalid entries
|
||||
@@ -110,29 +128,71 @@ function readDiscoveryProgress(discoveriesDir: string, discoveryId: string): any
|
||||
if (existsSync(statePath)) {
|
||||
try {
|
||||
const state = JSON.parse(readFileSync(statePath, 'utf8'));
|
||||
// New merged schema: perspectives array + results object
|
||||
|
||||
// Check if perspectives is an array
|
||||
if (state.perspectives && Array.isArray(state.perspectives)) {
|
||||
const completed = state.perspectives.filter((p: any) => p.status === 'completed').length;
|
||||
const total = state.perspectives.length;
|
||||
return {
|
||||
discovery_id: discoveryId,
|
||||
phase: state.phase,
|
||||
last_update: state.updated_at || state.created_at,
|
||||
progress: {
|
||||
perspective_analysis: {
|
||||
total,
|
||||
completed,
|
||||
in_progress: state.perspectives.filter((p: any) => p.status === 'in_progress').length,
|
||||
percent_complete: total > 0 ? Math.round((completed / total) * 100) : 0
|
||||
// Detect format: object array (old) vs string array (new)
|
||||
const isObjectArray = state.perspectives.length > 0 && typeof state.perspectives[0] === 'object';
|
||||
|
||||
if (isObjectArray) {
|
||||
// Old merged schema: perspectives is array of objects with status
|
||||
const completed = state.perspectives.filter((p: any) => p.status === 'completed').length;
|
||||
const total = state.perspectives.length;
|
||||
return {
|
||||
discovery_id: discoveryId,
|
||||
phase: state.phase,
|
||||
last_update: state.updated_at || state.created_at,
|
||||
progress: {
|
||||
perspective_analysis: {
|
||||
total,
|
||||
completed,
|
||||
in_progress: state.perspectives.filter((p: any) => p.status === 'in_progress').length,
|
||||
percent_complete: total > 0 ? Math.round((completed / total) * 100) : 0
|
||||
},
|
||||
external_research: state.external_research || { enabled: false, completed: false },
|
||||
aggregation: { completed: state.phase === 'aggregation' || state.phase === 'complete' },
|
||||
issue_generation: { completed: state.phase === 'complete', issues_count: state.results?.issues_generated || 0 }
|
||||
},
|
||||
external_research: state.external_research || { enabled: false, completed: false },
|
||||
aggregation: { completed: state.phase === 'aggregation' || state.phase === 'complete' },
|
||||
issue_generation: { completed: state.phase === 'complete', issues_count: state.results?.issues_generated || 0 }
|
||||
},
|
||||
agent_status: state.perspectives
|
||||
};
|
||||
agent_status: state.perspectives
|
||||
};
|
||||
} else {
|
||||
// New schema: perspectives is string array, status in perspectives_completed/perspectives_failed
|
||||
const total = state.perspectives.length;
|
||||
const completedList = state.perspectives_completed || [];
|
||||
const failedList = state.perspectives_failed || [];
|
||||
const completed = completedList.length;
|
||||
const failed = failedList.length;
|
||||
const inProgress = total - completed - failed;
|
||||
|
||||
return {
|
||||
discovery_id: discoveryId,
|
||||
phase: state.phase,
|
||||
last_update: state.updated_at || state.created_at,
|
||||
progress: {
|
||||
perspective_analysis: {
|
||||
total,
|
||||
completed,
|
||||
failed,
|
||||
in_progress: inProgress,
|
||||
percent_complete: total > 0 ? Math.round(((completed + failed) / total) * 100) : 0
|
||||
},
|
||||
external_research: state.external_research || { enabled: false, completed: false },
|
||||
aggregation: { completed: state.phase === 'aggregation' || state.phase === 'complete' },
|
||||
issue_generation: {
|
||||
completed: state.phase === 'complete',
|
||||
issues_count: state.results?.issues_generated || state.issues_generated || 0
|
||||
}
|
||||
},
|
||||
// Convert string array to object array for UI compatibility
|
||||
agent_status: state.perspectives.map((p: string) => ({
|
||||
name: p,
|
||||
status: completedList.includes(p) ? 'completed' : (failedList.includes(p) ? 'failed' : 'pending')
|
||||
}))
|
||||
};
|
||||
}
|
||||
}
|
||||
// Old schema: metadata.perspectives (backward compat)
|
||||
|
||||
// Legacy schema: metadata.perspectives (backward compat)
|
||||
if (state.metadata?.perspectives) {
|
||||
return {
|
||||
discovery_id: discoveryId,
|
||||
@@ -294,12 +354,20 @@ export async function handleDiscoveryRoutes(ctx: RouteContext): Promise<boolean>
|
||||
const enrichedDiscoveries = index.discoveries.map((d: any) => {
|
||||
const state = readDiscoveryState(discoveriesDir, d.discovery_id);
|
||||
const progress = readDiscoveryProgress(discoveriesDir, d.discovery_id);
|
||||
|
||||
// Extract statistics - handle both old and new formats
|
||||
// New format: stats in state.results object
|
||||
// Old format: stats directly in state
|
||||
const total_findings = state?.results?.total_findings ?? state?.total_findings ?? 0;
|
||||
const issues_generated = state?.results?.issues_generated ?? state?.issues_generated ?? 0;
|
||||
const priority_distribution = state?.results?.priority_distribution ?? state?.priority_distribution ?? {};
|
||||
|
||||
return {
|
||||
...d,
|
||||
phase: state?.phase || 'unknown',
|
||||
total_findings: state?.total_findings || 0,
|
||||
issues_generated: state?.issues_generated || 0,
|
||||
priority_distribution: state?.priority_distribution || {},
|
||||
total_findings,
|
||||
issues_generated,
|
||||
priority_distribution,
|
||||
progress: progress?.progress || null
|
||||
};
|
||||
});
|
||||
|
||||
@@ -338,6 +338,14 @@ function renderIssueCard(issue) {
|
||||
${t('issues.boundSolution') || 'Bound'}
|
||||
</span>
|
||||
` : ''}
|
||||
${issue.github_url ? `
|
||||
<a href="${issue.github_url}" target="_blank" rel="noopener noreferrer"
|
||||
class="flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onclick="event.stopPropagation()" title="View on GitHub">
|
||||
<i data-lucide="github" class="w-3.5 h-3.5"></i>
|
||||
${issue.github_number ? `#${issue.github_number}` : 'GitHub'}
|
||||
</a>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -182,6 +182,80 @@ function createDiscoveryFixture(projectRoot: string): { discoveryId: string; fin
|
||||
return { discoveryId, findingId, discoveryDir };
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a discovery fixture using the NEW format:
|
||||
* - perspectives is a string array
|
||||
* - status tracked in perspectives_completed/perspectives_failed
|
||||
* - stats in results object
|
||||
*/
|
||||
function createNewFormatDiscoveryFixture(projectRoot: string): { discoveryId: string; findingId: string; discoveryDir: string } {
|
||||
const discoveryId = `DSC-NEW-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`;
|
||||
const findingId = 'F-NEW-001';
|
||||
|
||||
const discoveryDir = join(projectRoot, '.workflow', 'issues', 'discoveries', discoveryId);
|
||||
const perspectivesDir = join(discoveryDir, 'perspectives');
|
||||
mkdirSync(perspectivesDir, { recursive: true });
|
||||
|
||||
const createdAt = new Date().toISOString();
|
||||
writeFileSync(
|
||||
join(discoveryDir, 'discovery-state.json'),
|
||||
JSON.stringify(
|
||||
{
|
||||
discovery_id: discoveryId,
|
||||
target_pattern: 'src/**/*.ts',
|
||||
phase: 'complete',
|
||||
created_at: createdAt,
|
||||
updated_at: createdAt,
|
||||
target: {
|
||||
files_count: { total: 10 },
|
||||
project: { name: 'test', path: projectRoot },
|
||||
},
|
||||
// New format: perspectives as string array
|
||||
perspectives: ['bug', 'security', 'performance'],
|
||||
perspectives_completed: ['bug', 'security'],
|
||||
perspectives_failed: ['performance'],
|
||||
external_research: { enabled: false, completed: false },
|
||||
// New format: stats in results object
|
||||
results: {
|
||||
total_findings: 5,
|
||||
issues_generated: 2,
|
||||
priority_distribution: { critical: 1, high: 2, medium: 1, low: 1 },
|
||||
findings_by_perspective: { bug: 3, security: 2 },
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
writeFileSync(
|
||||
join(perspectivesDir, 'bug.json'),
|
||||
JSON.stringify(
|
||||
{
|
||||
summary: { total: 3 },
|
||||
findings: [
|
||||
{
|
||||
id: findingId,
|
||||
title: 'New format finding',
|
||||
description: 'Example from new format',
|
||||
priority: 'high',
|
||||
perspective: 'bug',
|
||||
file: 'src/example.ts',
|
||||
line: 100,
|
||||
suggested_issue: { title: 'New format issue', priority: 2, labels: ['bug'] },
|
||||
},
|
||||
],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
return { discoveryId, findingId, discoveryDir };
|
||||
}
|
||||
|
||||
describe('discovery routes integration', async () => {
|
||||
before(async () => {
|
||||
mock.method(console, 'log', () => {});
|
||||
@@ -358,5 +432,103 @@ describe('discovery routes integration', async () => {
|
||||
rmSync(projectRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// ========== NEW FORMAT TESTS ==========
|
||||
|
||||
it('GET /api/discoveries lists new format discovery sessions with correct stats', async () => {
|
||||
const projectRoot = mkdtempSync(join(tmpdir(), 'ccw-discovery-routes-newformat-'));
|
||||
try {
|
||||
const { discoveryId } = createNewFormatDiscoveryFixture(projectRoot);
|
||||
const { server, baseUrl } = await createServer(projectRoot);
|
||||
try {
|
||||
const res = await requestJson(baseUrl, 'GET', '/api/discoveries');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(Array.isArray(res.json.discoveries), true);
|
||||
assert.equal(res.json.total, 1);
|
||||
|
||||
const discovery = res.json.discoveries[0];
|
||||
assert.equal(discovery.discovery_id, discoveryId);
|
||||
assert.equal(discovery.phase, 'complete');
|
||||
// Verify stats are extracted from results object
|
||||
assert.equal(discovery.total_findings, 5);
|
||||
assert.equal(discovery.issues_generated, 2);
|
||||
assert.deepEqual(discovery.priority_distribution, { critical: 1, high: 2, medium: 1, low: 1 });
|
||||
// Verify perspectives is string array
|
||||
assert.ok(Array.isArray(discovery.perspectives));
|
||||
assert.ok(discovery.perspectives.includes('bug'));
|
||||
assert.ok(discovery.perspectives.includes('security'));
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
} finally {
|
||||
rmSync(projectRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('GET /api/discoveries/:id/progress returns correct progress for new format', async () => {
|
||||
const projectRoot = mkdtempSync(join(tmpdir(), 'ccw-discovery-routes-newformat-'));
|
||||
try {
|
||||
const { discoveryId } = createNewFormatDiscoveryFixture(projectRoot);
|
||||
const { server, baseUrl } = await createServer(projectRoot);
|
||||
try {
|
||||
const res = await requestJson(baseUrl, 'GET', `/api/discoveries/${encodeURIComponent(discoveryId)}/progress`);
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(res.json.discovery_id, discoveryId);
|
||||
assert.ok(res.json.progress);
|
||||
|
||||
const pa = res.json.progress.perspective_analysis;
|
||||
assert.equal(pa.total, 3); // bug, security, performance
|
||||
assert.equal(pa.completed, 2); // bug, security
|
||||
assert.equal(pa.failed, 1); // performance
|
||||
assert.equal(pa.in_progress, 0);
|
||||
assert.equal(pa.percent_complete, 100); // (completed + failed) / total = 3/3 = 100%
|
||||
|
||||
// Verify agent_status is converted to object array for UI compatibility
|
||||
assert.ok(Array.isArray(res.json.agent_status));
|
||||
const bugStatus = res.json.agent_status.find((s: any) => s.name === 'bug');
|
||||
assert.ok(bugStatus);
|
||||
assert.equal(bugStatus.status, 'completed');
|
||||
const perfStatus = res.json.agent_status.find((s: any) => s.name === 'performance');
|
||||
assert.ok(perfStatus);
|
||||
assert.equal(perfStatus.status, 'failed');
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
} finally {
|
||||
rmSync(projectRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('mixed old and new format discoveries are listed correctly', async () => {
|
||||
const projectRoot = mkdtempSync(join(tmpdir(), 'ccw-discovery-routes-mixed-'));
|
||||
try {
|
||||
const oldFormat = createDiscoveryFixture(projectRoot);
|
||||
const newFormat = createNewFormatDiscoveryFixture(projectRoot);
|
||||
const { server, baseUrl } = await createServer(projectRoot);
|
||||
try {
|
||||
const res = await requestJson(baseUrl, 'GET', '/api/discoveries');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(res.json.total, 2);
|
||||
|
||||
// Both formats should be parsed correctly
|
||||
const oldDiscovery = res.json.discoveries.find((d: any) => d.discovery_id === oldFormat.discoveryId);
|
||||
const newDiscovery = res.json.discoveries.find((d: any) => d.discovery_id === newFormat.discoveryId);
|
||||
|
||||
assert.ok(oldDiscovery);
|
||||
assert.ok(newDiscovery);
|
||||
|
||||
// Old format stats
|
||||
assert.equal(oldDiscovery.total_findings, 1);
|
||||
|
||||
// New format stats from results object
|
||||
assert.equal(newDiscovery.total_findings, 5);
|
||||
assert.equal(newDiscovery.issues_generated, 2);
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
} finally {
|
||||
rmSync(projectRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "claude-code-workflow",
|
||||
"version": "6.3.21",
|
||||
"version": "6.3.23",
|
||||
"description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution",
|
||||
"type": "module",
|
||||
"main": "ccw/src/index.js",
|
||||
|
||||
Reference in New Issue
Block a user