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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
//! Directive API methods.
use uuid::Uuid;
use super::client::{ApiClient, ApiError};
use super::supervisor::JsonValue;
impl ApiClient {
/// Create a new directive.
pub async fn create_directive(
&self,
goal: &str,
repository_url: Option<&str>,
autonomy_level: &str,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct CreateRequest<'a> {
goal: &'a str,
repository_url: Option<&'a str>,
autonomy_level: &'a str,
}
let req = CreateRequest {
goal,
repository_url,
autonomy_level,
};
self.post("/api/v1/directives", &req).await
}
/// List all directives for the authenticated user.
pub async fn list_directives(
&self,
status: Option<&str>,
limit: i32,
) -> Result<JsonValue, ApiError> {
let mut params = Vec::new();
if let Some(s) = status {
params.push(format!("status={}", s));
}
params.push(format!("limit={}", limit));
let query_string = format!("?{}", params.join("&"));
self.get(&format!("/api/v1/directives{}", query_string))
.await
}
/// Get a directive by ID (includes progress info).
pub async fn get_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}", directive_id))
.await
}
/// Archive a directive.
pub async fn archive_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.delete_with_response(&format!("/api/v1/directives/{}", directive_id))
.await
}
/// Start a directive (plans and begins execution).
pub async fn start_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!("/api/v1/directives/{}/start", directive_id))
.await
}
/// Pause a directive.
pub async fn pause_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!("/api/v1/directives/{}/pause", directive_id))
.await
}
/// Resume a paused directive.
pub async fn resume_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!("/api/v1/directives/{}/resume", directive_id))
.await
}
/// Stop a directive.
pub async fn stop_directive(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!("/api/v1/directives/{}/stop", directive_id))
.await
}
/// Get the current chain and steps for a directive.
pub async fn get_directive_chain(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}/chain", directive_id))
.await
}
/// Get directive DAG structure for visualization.
pub async fn get_directive_graph(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}/chain/graph", directive_id))
.await
}
/// List events for a directive.
pub async fn list_directive_events(
&self,
directive_id: Uuid,
limit: i32,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/directives/{}/events?limit={}",
directive_id, limit
))
.await
}
/// List pending approvals for a directive.
pub async fn list_directive_approvals(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}/approvals", directive_id))
.await
}
/// Approve an approval request.
pub async fn approve_directive_request(
&self,
directive_id: Uuid,
approval_id: Uuid,
response: Option<&str>,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct ApprovalRequest<'a> {
response: Option<&'a str>,
}
let req = ApprovalRequest { response };
self.post(
&format!(
"/api/v1/directives/{}/approvals/{}/approve",
directive_id, approval_id
),
&req,
)
.await
}
/// Deny an approval request.
pub async fn deny_directive_request(
&self,
directive_id: Uuid,
approval_id: Uuid,
response: Option<&str>,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct ApprovalRequest<'a> {
response: Option<&'a str>,
}
let req = ApprovalRequest { response };
self.post(
&format!(
"/api/v1/directives/{}/approvals/{}/deny",
directive_id, approval_id
),
&req,
)
.await
}
// =========================================================================
// Chain operations
// =========================================================================
/// Force chain regeneration (replan).
pub async fn replan_directive_chain(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/chain/replan",
directive_id
))
.await
}
// =========================================================================
// Step management
// =========================================================================
/// Add a step to a directive's chain.
pub async fn add_directive_step(
&self,
directive_id: Uuid,
name: &str,
description: Option<&str>,
step_type: Option<&str>,
depends_on: Option<Vec<Uuid>>,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct AddStepReq<'a> {
name: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
step_type: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
depends_on: Option<Vec<Uuid>>,
}
let req = AddStepReq {
name,
description,
step_type,
depends_on,
};
self.post(
&format!("/api/v1/directives/{}/chain/steps", directive_id),
&req,
)
.await
}
/// Get a step by ID.
pub async fn get_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/directives/{}/chain/steps/{}",
directive_id, step_id
))
.await
}
/// Update a step.
pub async fn update_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
update: serde_json::Value,
) -> Result<JsonValue, ApiError> {
self.put(
&format!(
"/api/v1/directives/{}/chain/steps/{}",
directive_id, step_id
),
&update,
)
.await
}
/// Delete a step.
pub async fn delete_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<(), ApiError> {
self.delete(&format!(
"/api/v1/directives/{}/chain/steps/{}",
directive_id, step_id
))
.await
}
/// Skip a step.
pub async fn skip_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/chain/steps/{}/skip",
directive_id, step_id
))
.await
}
/// Force re-evaluation of a step.
pub async fn evaluate_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/chain/steps/{}/evaluate",
directive_id, step_id
))
.await
}
/// Trigger manual rework for a step.
pub async fn rework_directive_step(
&self,
directive_id: Uuid,
step_id: Uuid,
instructions: Option<&str>,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct ReworkReq<'a> {
instructions: Option<&'a str>,
}
let req = ReworkReq { instructions };
self.post(
&format!(
"/api/v1/directives/{}/chain/steps/{}/rework",
directive_id, step_id
),
&req,
)
.await
}
// =========================================================================
// Evaluations
// =========================================================================
/// List evaluations for a directive.
pub async fn list_directive_evaluations(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/directives/{}/evaluations",
directive_id
))
.await
}
// =========================================================================
// Verifiers
// =========================================================================
/// List verifiers for a directive.
pub async fn list_directive_verifiers(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}/verifiers", directive_id))
.await
}
/// Add a verifier to a directive.
pub async fn add_directive_verifier(
&self,
directive_id: Uuid,
name: &str,
verifier_type: &str,
command: Option<&str>,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct CreateVerifierReq<'a> {
name: &'a str,
verifier_type: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
command: Option<&'a str>,
}
let req = CreateVerifierReq {
name,
verifier_type,
command,
};
self.post(
&format!("/api/v1/directives/{}/verifiers", directive_id),
&req,
)
.await
}
/// Update a verifier.
pub async fn update_directive_verifier(
&self,
directive_id: Uuid,
verifier_id: Uuid,
update: serde_json::Value,
) -> Result<JsonValue, ApiError> {
self.put(
&format!(
"/api/v1/directives/{}/verifiers/{}",
directive_id, verifier_id
),
&update,
)
.await
}
/// Auto-detect verifiers based on repository content.
pub async fn auto_detect_directive_verifiers(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/verifiers/auto-detect",
directive_id
))
.await
}
// =========================================================================
// Requirements & Spec
// =========================================================================
/// Update directive requirements.
pub async fn update_directive_requirements(
&self,
directive_id: Uuid,
requirements: serde_json::Value,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct UpdateReq {
requirements: serde_json::Value,
}
let req = UpdateReq { requirements };
self.put(
&format!("/api/v1/directives/{}/requirements", directive_id),
&req,
)
.await
}
/// Update directive acceptance criteria.
pub async fn update_directive_criteria(
&self,
directive_id: Uuid,
acceptance_criteria: serde_json::Value,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct UpdateReq {
acceptance_criteria: serde_json::Value,
}
let req = UpdateReq { acceptance_criteria };
self.put(
&format!("/api/v1/directives/{}/criteria", directive_id),
&req,
)
.await
}
/// Generate a specification from the directive's goal.
pub async fn generate_directive_spec(
&self,
directive_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/generate-spec",
directive_id
))
.await
}
}
|