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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
import React, { useEffect, useState } from 'react'
import { useParams, Link } from 'react-router-dom'
interface FileSummary {
id: string
name: string
description?: string
contract_phase?: string
}
interface TaskSummary {
id: string
name: string
status: string
is_supervisor?: boolean
is_red_team?: boolean
}
interface ContractRepository {
id: string
name: string
source_type: string
is_primary: boolean
}
interface Contract {
id: string
name: string
description?: string
contract_type: string
phase: string
status: string
version: number
created_at: string
red_team_enabled?: boolean
red_team_prompt?: string
}
interface RedTeamNotification {
id: string
contract_id: string
red_team_task_id: string
related_task_id?: string
message: string
severity: 'info' | 'warning' | 'critical'
file_path?: string
context?: string
delivered: boolean
delivered_at?: string
acknowledged: boolean
acknowledged_at?: string
created_at: string
}
interface ContractWithRelations {
contract: Contract
repositories: ContractRepository[]
files: FileSummary[]
tasks: TaskSummary[]
}
type Tab = 'overview' | 'files' | 'tasks' | 'repositories' | 'red-team'
export function ContractDetail() {
const { id } = useParams<{ id: string }>()
const [data, setData] = useState<ContractWithRelations | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
const [activeTab, setActiveTab] = useState<Tab>('overview')
const [notifications, setNotifications] = useState<RedTeamNotification[]>([])
const [notificationsLoading, setNotificationsLoading] = useState(false)
useEffect(() => {
async function fetchContract() {
if (!id) return
try {
setLoading(true)
const response = await fetch(`/api/v1/contracts/${id}`)
if (!response.ok) {
throw new Error(`Failed to fetch contract: ${response.statusText}`)
}
const contractData = await response.json()
setData(contractData)
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error')
} finally {
setLoading(false)
}
}
fetchContract()
}, [id])
// Fetch red team notifications when viewing red-team tab
useEffect(() => {
async function fetchNotifications() {
if (!id || activeTab !== 'red-team' || !data?.contract.red_team_enabled) return
try {
setNotificationsLoading(true)
const response = await fetch(`/api/v1/contracts/${id}/red-team/notifications`)
if (response.ok) {
const notificationData = await response.json()
setNotifications(notificationData.notifications || [])
}
} catch (err) {
console.error('Failed to fetch red team notifications:', err)
} finally {
setNotificationsLoading(false)
}
}
fetchNotifications()
}, [id, activeTab, data?.contract.red_team_enabled])
if (loading) {
return (
<div className="contract-detail-container">
<div className="loading">Loading contract...</div>
</div>
)
}
if (error) {
return (
<div className="contract-detail-container">
<div className="error">Error: {error}</div>
<Link to="/contracts" className="back-link">
Back to Contracts
</Link>
</div>
)
}
if (!data) {
return (
<div className="contract-detail-container">
<div className="not-found">Contract not found</div>
<Link to="/contracts" className="back-link">
Back to Contracts
</Link>
</div>
)
}
const { contract, repositories, files, tasks } = data
return (
<div className="contract-detail-container">
<div className="contract-detail-header">
<Link to="/contracts" className="back-link">
Back to Contracts
</Link>
<h1 className="contract-title">
{contract.name}
{contract.red_team_enabled && (
<span className="red-team-badge" title="Red Team monitoring enabled">
🛡️ Red Team
</span>
)}
</h1>
{contract.description && (
<p className="contract-description">{contract.description}</p>
)}
<div className="contract-meta">
<span>Phase: {contract.phase}</span>
<span>Status: {contract.status}</span>
<span>Version: {contract.version}</span>
</div>
</div>
<div className="contract-tabs">
<button
className={`tab-button ${activeTab === 'overview' ? 'active' : ''}`}
onClick={() => setActiveTab('overview')}
>
Overview
</button>
<button
className={`tab-button ${activeTab === 'files' ? 'active' : ''}`}
onClick={() => setActiveTab('files')}
>
Files ({files.length})
</button>
<button
className={`tab-button ${activeTab === 'tasks' ? 'active' : ''}`}
onClick={() => setActiveTab('tasks')}
>
Tasks ({tasks.length})
</button>
<button
className={`tab-button ${activeTab === 'repositories' ? 'active' : ''}`}
onClick={() => setActiveTab('repositories')}
>
Repositories ({repositories.length})
</button>
{contract.red_team_enabled && (
<button
className={`tab-button red-team-tab ${activeTab === 'red-team' ? 'active' : ''}`}
onClick={() => setActiveTab('red-team')}
>
🛡️ Red Team
</button>
)}
</div>
<div className="contract-tab-content">
{activeTab === 'overview' && (
<div className="tab-panel">
<h2>Contract Overview</h2>
<dl className="overview-list">
<dt>Type</dt>
<dd>{contract.contract_type}</dd>
<dt>Phase</dt>
<dd>{contract.phase}</dd>
<dt>Status</dt>
<dd>{contract.status}</dd>
<dt>Created</dt>
<dd>{new Date(contract.created_at).toLocaleString()}</dd>
</dl>
</div>
)}
{activeTab === 'files' && (
<div className="tab-panel">
<h2>Files</h2>
{files.length === 0 ? (
<p>No files in this contract</p>
) : (
<ul className="file-list">
{files.map((file) => (
<li key={file.id} className="file-item">
<Link to={`/contracts/${contract.id}/files/${file.id}`}>
<h3>{file.name}</h3>
{file.description && <p>{file.description}</p>}
{file.contract_phase && (
<span className="file-phase">Phase: {file.contract_phase}</span>
)}
</Link>
</li>
))}
</ul>
)}
</div>
)}
{activeTab === 'tasks' && (
<div className="tab-panel">
<h2>Tasks</h2>
{tasks.length === 0 ? (
<p>No tasks in this contract</p>
) : (
<ul className="task-list">
{tasks.map((task) => (
<li key={task.id} className={`task-item ${task.is_red_team ? 'red-team-task' : ''}`}>
<h3>
{task.is_red_team && <span className="task-badge red-team">🛡️</span>}
{task.is_supervisor && <span className="task-badge supervisor">👔</span>}
{task.name}
</h3>
<span className={`task-status status-${task.status}`}>
{task.status}
</span>
</li>
))}
</ul>
)}
</div>
)}
{activeTab === 'repositories' && (
<div className="tab-panel">
<h2>Repositories</h2>
{repositories.length === 0 ? (
<p>No repositories linked to this contract</p>
) : (
<ul className="repository-list">
{repositories.map((repo) => (
<li key={repo.id} className="repository-item">
<h3>
{repo.name}
{repo.is_primary && <span className="primary-badge">Primary</span>}
</h3>
<span className="repo-type">{repo.source_type}</span>
</li>
))}
</ul>
)}
</div>
)}
{activeTab === 'red-team' && contract.red_team_enabled && (
<div className="tab-panel red-team-panel">
<h2>🛡️ Red Team Monitoring</h2>
{contract.red_team_prompt && (
<div className="red-team-prompt">
<h3>Review Criteria</h3>
<p>{contract.red_team_prompt}</p>
</div>
)}
<div className="red-team-status">
<h3>Red Team Task</h3>
{(() => {
const redTeamTask = tasks.find(t => t.is_red_team)
if (redTeamTask) {
return (
<div className="red-team-task-info">
<span className="task-name">{redTeamTask.name}</span>
<span className={`task-status status-${redTeamTask.status}`}>
{redTeamTask.status}
</span>
</div>
)
}
return <p className="no-task">Red team task not yet spawned</p>
})()}
</div>
<div className="red-team-notifications">
<h3>Alerts ({notifications.length})</h3>
{notificationsLoading ? (
<p>Loading notifications...</p>
) : notifications.length === 0 ? (
<p className="no-alerts">No alerts from red team</p>
) : (
<ul className="notification-list">
{notifications.map((notification) => (
<li
key={notification.id}
className={`notification-item severity-${notification.severity}`}
>
<div className="notification-header">
<span className={`severity-badge ${notification.severity}`}>
{notification.severity === 'critical' && '🚨'}
{notification.severity === 'warning' && '⚠️'}
{notification.severity === 'info' && 'ℹ️'}
{notification.severity.toUpperCase()}
</span>
<span className="notification-time">
{new Date(notification.created_at).toLocaleString()}
</span>
</div>
<p className="notification-message">{notification.message}</p>
{notification.file_path && (
<span className="notification-file">File: {notification.file_path}</span>
)}
{notification.context && (
<pre className="notification-context">{notification.context}</pre>
)}
</li>
))}
</ul>
)}
</div>
</div>
)}
</div>
</div>
)
}
|