1
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
import { useMemo } from "react";
import type { ContractWithRelations, ContractPhase, ContractType } from "../../lib/api";
// Phase deliverables configuration (mirrors backend phase_guidance.rs)
// IDs must match backend phase_guidance.rs exactly for mark_deliverable_complete
interface PhaseDeliverable {
id: string; // Must match backend deliverable ID
name: string;
priority: "required" | "recommended" | "optional";
description: string;
}
interface PhaseConfig {
deliverables: PhaseDeliverable[];
requiresRepository: boolean;
requiresTasks: boolean;
guidance: string;
}
// Contract type specific deliverables (must match backend phase_guidance.rs)
type ContractTypeDeliverables = Partial<Record<ContractPhase, PhaseConfig>>;
const CONTRACT_TYPE_DELIVERABLES: Record<ContractType, ContractTypeDeliverables> = {
simple: {
plan: {
deliverables: [
{ id: "plan-document", name: "Plan", priority: "required", description: "Implementation plan detailing the approach and tasks" },
],
requiresRepository: true,
requiresTasks: false,
guidance: "Create a plan document that outlines the implementation approach. A repository must be configured before moving to Execute phase.",
},
execute: {
deliverables: [
{ id: "pull-request", name: "Pull Request", priority: "required", description: "Pull request with the implemented changes" },
],
requiresRepository: true,
requiresTasks: true,
guidance: "Execute the plan and create a PR with the implemented changes. Complete all tasks to finish the contract.",
},
},
specification: {
research: {
deliverables: [
{ id: "research-notes", name: "Research Notes", priority: "required", description: "Document findings and insights during research" },
],
requiresRepository: false,
requiresTasks: false,
guidance: "Focus on understanding the problem space and document your findings in the Research Notes before moving to Specify phase.",
},
specify: {
deliverables: [
{ id: "requirements-document", name: "Requirements Document", priority: "required", description: "Define functional and non-functional requirements" },
],
requiresRepository: false,
requiresTasks: false,
guidance: "Define what needs to be built with clear requirements in the Requirements Document. Ensure specifications are detailed enough for planning.",
},
plan: {
deliverables: [
{ id: "plan-document", name: "Plan", priority: "required", description: "Implementation plan detailing the approach and tasks" },
],
requiresRepository: true,
requiresTasks: false,
guidance: "Create a plan document that outlines the implementation approach. A repository must be configured before moving to Execute phase.",
},
execute: {
deliverables: [
{ id: "pull-request", name: "Pull Request", priority: "required", description: "Pull request with the implemented changes" },
],
requiresRepository: true,
requiresTasks: true,
guidance: "Execute the plan and create a PR with the implemented changes. Complete all tasks before moving to Review phase.",
},
review: {
deliverables: [
{ id: "release-notes", name: "Release Notes", priority: "required", description: "Document changes for release communication" },
],
requiresRepository: false,
requiresTasks: false,
guidance: "Review completed work and document the release in the Release Notes. The contract can be completed after review.",
},
},
execute: {
execute: {
deliverables: [], // No deliverables for execute-only contract type
requiresRepository: true,
requiresTasks: true,
guidance: "Execute the tasks directly. No deliverable documents are required for this contract type.",
},
},
};
// Get phase config for a specific contract type and phase
function getPhaseConfig(contractType: ContractType, phase: ContractPhase): PhaseConfig {
const typeConfig = CONTRACT_TYPE_DELIVERABLES[contractType];
const phaseConfig = typeConfig?.[phase];
if (phaseConfig) {
return phaseConfig;
}
// Fallback for unknown phase/type combinations
return {
deliverables: [],
requiresRepository: false,
requiresTasks: false,
guidance: `Unknown phase "${phase}" for contract type "${contractType}"`,
};
}
interface DeliverableStatus {
id: string;
name: string;
priority: "required" | "recommended" | "optional";
description: string;
completed: boolean;
fileId?: string;
actualName?: string;
}
interface PhaseDeliverablesProps {
contract: ContractWithRelations;
onCreateFile?: (templateId: string, suggestedName: string) => void;
}
export function PhaseDeliverablesPanel({ contract, onCreateFile }: PhaseDeliverablesProps) {
// Get phase config based on contract type AND phase
const phaseConfig = useMemo(
() => getPhaseConfig(contract.contractType, contract.phase),
[contract.contractType, contract.phase]
);
// Calculate deliverable status
const deliverableStatuses = useMemo((): DeliverableStatus[] => {
return phaseConfig.deliverables.map((deliverable) => {
// Find matching file by name similarity
const matchedFile = contract.files.find((f) => {
const nameLower = f.name.toLowerCase();
const deliverableLower = deliverable.name.toLowerCase();
return (
f.contractPhase === contract.phase &&
(nameLower.includes(deliverableLower) || deliverableLower.includes(nameLower) || nameLower.includes(deliverable.id.replace("-", " ")))
);
});
return {
...deliverable,
completed: !!matchedFile,
fileId: matchedFile?.id,
actualName: matchedFile?.name,
};
});
}, [contract.files, contract.phase, phaseConfig.deliverables]);
// Check repository status
const hasRepository = contract.repositories.length > 0;
// Check task status
const taskStats = useMemo(() => {
const total = contract.tasks.length;
const done = contract.tasks.filter((t) => t.status === "done" || t.status === "merged").length;
const pending = contract.tasks.filter((t) => t.status === "pending").length;
const running = contract.tasks.filter((t) => ["running", "initializing", "starting"].includes(t.status)).length;
const failed = contract.tasks.filter((t) => t.status === "failed").length;
return { total, done, pending, running, failed };
}, [contract.tasks]);
// Calculate completion percentage
const completionPercent = useMemo(() => {
let completed = 0;
let total = 0;
// Count required and recommended deliverables
deliverableStatuses.forEach((s) => {
if (s.priority !== "optional") {
total++;
if (s.completed) completed++;
}
});
// Count repository if required
if (phaseConfig.requiresRepository) {
total++;
if (hasRepository) completed++;
}
// Count tasks if required
if (phaseConfig.requiresTasks && taskStats.total > 0) {
total++;
if (taskStats.done === taskStats.total) completed++;
}
return total > 0 ? Math.round((completed / total) * 100) : 100;
}, [deliverableStatuses, hasRepository, phaseConfig, taskStats]);
const priorityColors = {
required: "text-red-400",
recommended: "text-yellow-400",
optional: "text-[#555]",
};
return (
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="font-mono text-xs text-[#75aafc] uppercase">
Phase Deliverables
</h3>
<div className="flex items-center gap-2">
<div className="w-24 h-1.5 bg-[rgba(117,170,252,0.1)] rounded overflow-hidden">
<div
className={`h-full transition-all duration-300 ${
completionPercent === 100 ? "bg-green-400" : "bg-[#75aafc]"
}`}
style={{ width: `${completionPercent}%` }}
/>
</div>
<span className="font-mono text-[10px] text-[#555]">{completionPercent}%</span>
</div>
</div>
{/* Guidance text */}
<p className="font-mono text-xs text-[#555] italic">{phaseConfig.guidance}</p>
{/* Deliverables checklist */}
<div className="space-y-2">
{deliverableStatuses.map((status) => (
<div
key={status.id}
className={`flex items-center justify-between p-2 border ${
status.completed
? "border-green-400/20 bg-green-400/5"
: "border-[rgba(117,170,252,0.15)]"
}`}
>
<div className="flex items-center gap-2">
<span
className={`font-mono text-xs ${
status.completed ? "text-green-400" : "text-[#555]"
}`}
>
{status.completed ? "[+]" : "[ ]"}
</span>
<div>
<div className="flex items-center gap-2">
<span className="font-mono text-xs text-[#dbe7ff]">
{status.completed ? status.actualName : status.name}
</span>
{!status.completed && (
<span className={`font-mono text-[9px] uppercase ${priorityColors[status.priority]}`}>
{status.priority}
</span>
)}
</div>
<span className="font-mono text-[10px] text-[#555]">
{status.description}
</span>
</div>
</div>
{!status.completed && onCreateFile && (
<button
onClick={() => onCreateFile(status.id, status.name)}
className="px-2 py-1 font-mono text-[10px] text-[#75aafc] border border-[rgba(117,170,252,0.25)] hover:border-[#3f6fb3] transition-colors"
>
Create
</button>
)}
</div>
))}
</div>
{/* Repository status */}
{phaseConfig.requiresRepository && (
<div
className={`flex items-center gap-2 p-2 border ${
hasRepository
? "border-green-400/20 bg-green-400/5"
: "border-[rgba(117,170,252,0.15)]"
}`}
>
<span
className={`font-mono text-xs ${
hasRepository ? "text-green-400" : "text-[#555]"
}`}
>
{hasRepository ? "[+]" : "[ ]"}
</span>
<div>
<span className="font-mono text-xs text-[#dbe7ff]">
Repository Configured
</span>
{!hasRepository && (
<span className="font-mono text-[9px] uppercase text-red-400 ml-2">
required
</span>
)}
</div>
</div>
)}
{/* Task status */}
{phaseConfig.requiresTasks && (
<div
className={`flex items-center justify-between p-2 border ${
taskStats.total > 0 && taskStats.done === taskStats.total
? "border-green-400/20 bg-green-400/5"
: "border-[rgba(117,170,252,0.15)]"
}`}
>
<div className="flex items-center gap-2">
<span
className={`font-mono text-xs ${
taskStats.total > 0 && taskStats.done === taskStats.total
? "text-green-400"
: "text-[#555]"
}`}
>
{taskStats.total > 0 && taskStats.done === taskStats.total ? "[+]" : "[ ]"}
</span>
<span className="font-mono text-xs text-[#dbe7ff]">
Tasks Completed
</span>
</div>
{taskStats.total > 0 ? (
<span className="font-mono text-[10px] text-[#9bc3ff]">
{taskStats.done}/{taskStats.total}
{taskStats.running > 0 && ` (${taskStats.running} running)`}
{taskStats.failed > 0 && (
<span className="text-red-400"> ({taskStats.failed} failed)</span>
)}
</span>
) : (
<span className="font-mono text-[10px] text-[#555]">No tasks yet</span>
)}
</div>
)}
</div>
);
}
|