cflx 0.6.98

Conflux – a spec-driven parallel coding orchestrator that runs AI agents on git worktrees
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
//! Configuration templates for different AI agents

use crate::cli::Template;

/// Claude Code agent configuration template
pub const CLAUDE_TEMPLATE: &str = r#"{
  // Conflux Configuration
  // Template: Claude Code

  // Command to analyze dependencies and select next change
  "analyze_command": "claude --dangerously-skip-permissions --verbose --output-format stream-json -p {prompt}",

  // Command to apply a change (supports {change_id} and {prompt} placeholders)
  "apply_command": "claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'",

  // Command to archive a completed change (supports {change_id} and {prompt} placeholders)
  "archive_command": "claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'",

  // Command to run acceptance tests after apply (supports {change_id} and {prompt} placeholders)
  "acceptance_command": "claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'",

  // Operation skill for acceptance prompts (defaults to cflx-accept).
  // Opt into SPECA-style property review without changing acceptance_command:
  // "accept_skill": "cflx-accept-with-speca",

  // Command to resolve conflicts (supports {prompt} placeholder)
  "resolve_command": "claude --dangerously-skip-permissions --verbose --output-format stream-json -p {prompt}",

  // Operation skill preludes loaded into generated prompts (all optional; shown with defaults)
  // Example: set accept_skill to "cflx-accept-with-speca" to customize acceptance guidance only.
  "analyze_skill": "cflx-analyze",
  "apply_skill": "cflx-apply",
  "rejecting_skill": "cflx-rejecting",
  "cleanup_review_skill": "cflx-cleanup-review",
  "accept_skill": "cflx-accept",
  // "accept_skill": "cflx-accept-with-speca",
  "archive_skill": "cflx-archive",
  "resolve_skill": "cflx-resolve",

  // System prompt for apply command (user-customizable, injected into {prompt} placeholder)
  // Note: A hardcoded system prompt is always appended after this value
  //"apply_prompt": "",

  // System prompt for archive command (injected into {prompt} placeholder)
  //"archive_prompt": "",

  // System prompt for acceptance command (injected into {prompt} placeholder)
  // Note: A hardcoded acceptance prompt is always prepended before this value
  //"acceptance_prompt": "",

   // Worktree command for TUI (+ key)
  // Supports {workspace_dir} and {repo_root} placeholders
  "worktree_command": "tmux new-window -n wt ",
  // "worktree_command": "codex '/openspec:proposal --worktree {workspace_dir}'",

  // Maximum iterations for the orchestration loop (default: 50, 0 = no limit)
  // "max_iterations": 50,

  // Logging configuration for TUI debug output
  // "logging": {
  //   "suppress_repetitive_debug": true,
  //   "summary_interval_secs": 60
  // },

  // Lifecycle hooks (optional)
  // Available hooks:
  //   Run lifecycle: on_start, on_finish, on_error
  //   Change lifecycle: on_change_start, pre_apply, post_apply, on_change_complete, pre_archive, post_archive, on_change_end, on_merged
  //   TUI interaction: on_queue_add, on_queue_remove
  // Available placeholders: {change_id}, {changes_processed}, {total_changes}, {remaining_changes}, {apply_count}, {completed_tasks}, {total_tasks}
  "hooks": {
    // Run lifecycle
    // "on_start": "echo '[on_start] changes_processed={changes_processed} total={total_changes} remaining={remaining_changes}'",
    // "on_finish": "echo '[on_finish] status={status} processed={changes_processed}/{total_changes}'",
    // "on_error": "echo '[on_error] change={change_id} error={error}'",

    // Change lifecycle
    // "on_change_start": "echo '[on_change_start] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",
    // "pre_apply": "echo '[pre_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "post_apply": "echo '[post_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "on_change_complete": "echo '[on_change_complete] change={change_id} tasks={total_tasks}/{total_tasks}'",
    // "pre_archive": "echo '[pre_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "post_archive": "echo '[post_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "on_change_end": "echo '[on_change_end] change={change_id} progress={changes_processed}/{total_changes} remaining={remaining_changes}'",
    // "on_merged": "echo '[on_merged] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",

    // TUI interaction
    // "on_queue_add": "echo '[on_queue_add] change={change_id} tasks={completed_tasks}/{total_tasks}'",
    // "on_queue_remove": "echo '[on_queue_remove] change={change_id} tasks={completed_tasks}/{total_tasks}'"
  }
}
"#;

/// OpenCode agent configuration template
pub const OPENCODE_TEMPLATE: &str = r#"{
  // Conflux Configuration
  // Template: OpenCode

  // Command to analyze dependencies and select next change
  "analyze_command": "opencode run --format json {prompt}",

  // Command to apply a change (supports {change_id} and {prompt} placeholders)
  "apply_command": "opencode run '{prompt}'",

  // Command to archive a completed change (supports {change_id} and {prompt} placeholders)
  "archive_command": "opencode run '{prompt}'",

  // Command to run acceptance tests after apply (supports {change_id} and {prompt} placeholders)
  "acceptance_command": "opencode run '{prompt}'",

  // Operation skill for acceptance prompts (defaults to cflx-accept).
  // Opt into SPECA-style property review without changing acceptance_command:
  // "accept_skill": "cflx-accept-with-speca",

  // Command to resolve conflicts (supports {prompt} placeholder)
  "resolve_command": "opencode run {prompt}",

  // Operation skill preludes loaded into generated prompts (all optional; shown with defaults)
  // Example: set accept_skill to "cflx-accept-with-speca" to customize acceptance guidance only.
  "analyze_skill": "cflx-analyze",
  "apply_skill": "cflx-apply",
  "rejecting_skill": "cflx-rejecting",
  "cleanup_review_skill": "cflx-cleanup-review",
  "accept_skill": "cflx-accept",
  // "accept_skill": "cflx-accept-with-speca",
  "archive_skill": "cflx-archive",
  "resolve_skill": "cflx-resolve",

  // System prompt for apply command (user-customizable, injected into {prompt} placeholder)
  // Note: A hardcoded system prompt is always appended after this value
  //"apply_prompt": "",

  // System prompt for archive command (injected into {prompt} placeholder)
  //"archive_prompt": "",

  // System prompt for acceptance command (injected into {prompt} placeholder)
  // Note: A hardcoded acceptance prompt is always prepended before this value
  //"acceptance_prompt": "",

  // Worktree command for TUI (+ key)
  // Supports {workspace_dir} and {repo_root} placeholders
  "worktree_command": "tmux new-window -n wt ",
  // "worktree_command": "claude run '/openspec:proposal --worktree {workspace_dir}'",

  // Maximum iterations for the orchestration loop (default: 50, 0 = no limit)
  // "max_iterations": 50,

  // Logging configuration for TUI debug output
  // "logging": {
  //   "suppress_repetitive_debug": true,
  //   "summary_interval_secs": 60
  // },

  // Lifecycle hooks (optional)
  // Available hooks:
  //   Run lifecycle: on_start, on_finish, on_error
  //   Change lifecycle: on_change_start, pre_apply, post_apply, on_change_complete, pre_archive, post_archive, on_change_end, on_merged
  //   TUI interaction: on_queue_add, on_queue_remove
  // Available placeholders: {change_id}, {changes_processed}, {total_changes}, {remaining_changes}, {apply_count}, {completed_tasks}, {total_tasks}
  "hooks": {
    // Run lifecycle
    // "on_start": "echo '[on_start] changes_processed={changes_processed} total={total_changes} remaining={remaining_changes}'",
    // "on_finish": "echo '[on_finish] status={status} processed={changes_processed}/{total_changes}'",
    // "on_error": "echo '[on_error] change={change_id} error={error}'",

    // Change lifecycle
    // "on_change_start": "echo '[on_change_start] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",
    // "pre_apply": "echo '[pre_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "post_apply": "echo '[post_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "on_change_complete": "echo '[on_change_complete] change={change_id} tasks={total_tasks}/{total_tasks}'",
    // "pre_archive": "echo '[pre_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "post_archive": "echo '[post_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "on_change_end": "echo '[on_change_end] change={change_id} progress={changes_processed}/{total_changes} remaining={remaining_changes}'",
    // "on_merged": "echo '[on_merged] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",

    // TUI interaction
    // "on_queue_add": "echo '[on_queue_add] change={change_id} tasks={completed_tasks}/{total_tasks}'",
    // "on_queue_remove": "echo '[on_queue_remove] change={change_id} tasks={completed_tasks}/{total_tasks}'"
  }
}
"#;

/// Codex agent configuration template
pub const CODEX_TEMPLATE: &str = r#"{
  // Conflux Configuration
  // Template: Codex

  // Command to analyze dependencies and select next change
  "analyze_command": "codex --json {prompt}",

  // Command to apply a change (supports {change_id} and {prompt} placeholders)
  "apply_command": "codex '{prompt}'",

  // Command to archive a completed change (supports {change_id} and {prompt} placeholders)
  "archive_command": "codex '{prompt}'",

  // Command to run acceptance tests after apply (supports {change_id} and {prompt} placeholders)
  "acceptance_command": "codex '{prompt}'",

  // Operation skill for acceptance prompts (defaults to cflx-accept).
  // Opt into SPECA-style property review without changing acceptance_command:
  // "accept_skill": "cflx-accept-with-speca",

  // Command to resolve conflicts (supports {prompt} placeholder)
  "resolve_command": "codex {prompt}",

  // Operation skill preludes loaded into generated prompts (all optional; shown with defaults)
  // Example: set accept_skill to "cflx-accept-with-speca" to customize acceptance guidance only.
  "analyze_skill": "cflx-analyze",
  "apply_skill": "cflx-apply",
  "rejecting_skill": "cflx-rejecting",
  "cleanup_review_skill": "cflx-cleanup-review",
  "accept_skill": "cflx-accept",
  // "accept_skill": "cflx-accept-with-speca",
  "archive_skill": "cflx-archive",
  "resolve_skill": "cflx-resolve",

  // System prompt for apply command (user-customizable, injected into {prompt} placeholder)
  // Note: A hardcoded system prompt is always appended after this value
  //"apply_prompt": "",

  // System prompt for archive command (injected into {prompt} placeholder)
  //"archive_prompt": "",

  // System prompt for acceptance command (injected into {prompt} placeholder)
  // Note: A hardcoded acceptance prompt is always prepended before this value
  //"acceptance_prompt": "",

  // Worktree command for TUI (+ key)
  // Supports {workspace_dir} and {repo_root} placeholders
  "worktree_command": "tmux new-window -n wt ",
  // "worktree_command": "opencode run '/openspec:proposal --worktree {workspace_dir}'",

  // Maximum iterations for the orchestration loop (default: 50, 0 = no limit)
  // "max_iterations": 50,

  // Logging configuration for TUI debug output
  // "logging": {
  //   "suppress_repetitive_debug": true,
  //   "summary_interval_secs": 60
  // },

  // Lifecycle hooks (optional)
  // Available hooks:
  //   Run lifecycle: on_start, on_finish, on_error
  //   Change lifecycle: on_change_start, pre_apply, post_apply, on_change_complete, pre_archive, post_archive, on_change_end, on_merged
  //   TUI interaction: on_queue_add, on_queue_remove
  // Available placeholders: {change_id}, {changes_processed}, {total_changes}, {remaining_changes}, {apply_count}, {completed_tasks}, {total_tasks}
  "hooks": {
    // Run lifecycle
    // "on_start": "echo '[on_start] changes_processed={changes_processed} total={total_changes} remaining={remaining_changes}'",
    // "on_finish": "echo '[on_finish] status={status} processed={changes_processed}/{total_changes}'",
    // "on_error": "echo '[on_error] change={change_id} error={error}'",

    // Change lifecycle
    // "on_change_start": "echo '[on_change_start] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",
    // "pre_apply": "echo '[pre_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "post_apply": "echo '[post_apply] change={change_id} apply_count={apply_count} tasks={completed_tasks}/{total_tasks}'",
    // "on_change_complete": "echo '[on_change_complete] change={change_id} tasks={total_tasks}/{total_tasks}'",
    // "pre_archive": "echo '[pre_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "post_archive": "echo '[post_archive] change={change_id} progress={changes_processed}/{total_changes}'",
    // "on_change_end": "echo '[on_change_end] change={change_id} progress={changes_processed}/{total_changes} remaining={remaining_changes}'",
    // "on_merged": "echo '[on_merged] change={change_id} tasks={completed_tasks}/{total_tasks} progress={changes_processed}/{total_changes}'",

    // TUI interaction
    // "on_queue_add": "echo '[on_queue_add] change={change_id} tasks={completed_tasks}/{total_tasks}'",
    // "on_queue_remove": "echo '[on_queue_remove] change={change_id} tasks={completed_tasks}/{total_tasks}'"
  }
}
"#;

/// Get the configuration template content for the specified template type
pub fn get_template_content(template: Template) -> &'static str {
    match template {
        Template::Claude => CLAUDE_TEMPLATE,
        Template::Opencode => OPENCODE_TEMPLATE,
        Template::Codex => CODEX_TEMPLATE,
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::config::OrchestratorConfig;

    #[test]
    fn test_claude_template_is_valid_jsonc() {
        // JSONC allows comments and trailing commas, but we should at least
        // verify the template contains expected fields
        assert!(CLAUDE_TEMPLATE.contains("apply_command"));
        assert!(CLAUDE_TEMPLATE.contains("archive_command"));
        assert!(CLAUDE_TEMPLATE.contains("analyze_command"));
        assert!(CLAUDE_TEMPLATE.contains("claude --dangerously-skip-permissions"));
        assert!(CLAUDE_TEMPLATE.contains("--verbose --output-format stream-json"));
        // Should NOT contain nested agent structure
        assert!(!CLAUDE_TEMPLATE.contains("\"agent\":"));
    }

    #[test]
    fn test_opencode_template_is_valid_jsonc() {
        assert!(OPENCODE_TEMPLATE.contains("apply_command"));
        assert!(OPENCODE_TEMPLATE.contains("archive_command"));
        assert!(OPENCODE_TEMPLATE.contains("analyze_command"));
        assert!(OPENCODE_TEMPLATE.contains("opencode run"));
        // Should NOT contain nested agent structure
        assert!(!OPENCODE_TEMPLATE.contains("\"agent\":"));
    }

    #[test]
    fn test_codex_template_is_valid_jsonc() {
        assert!(CODEX_TEMPLATE.contains("apply_command"));
        assert!(CODEX_TEMPLATE.contains("archive_command"));
        assert!(CODEX_TEMPLATE.contains("analyze_command"));
        assert!(CODEX_TEMPLATE.contains("codex"));
        // Should NOT contain nested agent structure
        assert!(!CODEX_TEMPLATE.contains("\"agent\":"));
    }

    #[test]
    fn test_templates_document_operation_skill_keys_and_speca_example() {
        for template in [CLAUDE_TEMPLATE, OPENCODE_TEMPLATE, CODEX_TEMPLATE] {
            assert!(template.contains("\"analyze_skill\": \"cflx-analyze\""));
            assert!(template.contains("\"apply_skill\": \"cflx-apply\""));
            assert!(template.contains("\"rejecting_skill\": \"cflx-rejecting\""));
            assert!(template.contains("\"cleanup_review_skill\": \"cflx-cleanup-review\""));
            assert!(template.contains("\"accept_skill\": \"cflx-accept\""));
            assert!(template.contains("\"archive_skill\": \"cflx-archive\""));
            assert!(template.contains("\"resolve_skill\": \"cflx-resolve\""));
            assert!(template.contains("\"accept_skill\": \"cflx-accept-with-speca\""));
        }
    }

    #[test]
    fn test_get_template_content() {
        assert_eq!(get_template_content(Template::Claude), CLAUDE_TEMPLATE);
        assert_eq!(get_template_content(Template::Opencode), OPENCODE_TEMPLATE);
        assert_eq!(get_template_content(Template::Codex), CODEX_TEMPLATE);
    }

    #[test]
    fn test_claude_template_matches_sample_style() {
        assert!(CLAUDE_TEMPLATE.contains("\"apply_command\": \"claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'\""));
        assert!(CLAUDE_TEMPLATE.contains("\"archive_command\": \"claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'\""));
        assert!(CLAUDE_TEMPLATE.contains("\"acceptance_command\": \"claude --dangerously-skip-permissions --verbose --output-format stream-json -p '{prompt}'\""));
        assert!(CLAUDE_TEMPLATE.contains("\"worktree_command\": \"tmux new-window -n wt \""));
        assert!(!CLAUDE_TEMPLATE.contains("\"acceptance_prompt_mode\""));
        assert!(CLAUDE_TEMPLATE.contains("\"accept_skill\": \"cflx-accept-with-speca\""));
    }

    #[test]
    fn test_opencode_template_matches_sample_style() {
        assert!(OPENCODE_TEMPLATE.contains("\"apply_command\": \"opencode run '{prompt}'\""));
        assert!(OPENCODE_TEMPLATE.contains("\"archive_command\": \"opencode run '{prompt}'\""));
        assert!(OPENCODE_TEMPLATE.contains("\"acceptance_command\": \"opencode run '{prompt}'\""));
        assert!(OPENCODE_TEMPLATE.contains("\"worktree_command\": \"tmux new-window -n wt \""));
        assert!(!OPENCODE_TEMPLATE.contains("\"acceptance_prompt_mode\""));
        assert!(OPENCODE_TEMPLATE.contains("\"accept_skill\": \"cflx-accept-with-speca\""));
    }

    #[test]
    fn test_codex_template_matches_sample_style() {
        assert!(CODEX_TEMPLATE.contains("\"apply_command\": \"codex '{prompt}'\""));
        assert!(CODEX_TEMPLATE.contains("\"archive_command\": \"codex '{prompt}'\""));
        assert!(CODEX_TEMPLATE.contains("\"acceptance_command\": \"codex '{prompt}'\""));
        assert!(CODEX_TEMPLATE.contains("\"worktree_command\": \"tmux new-window -n wt \""));
        assert!(!CODEX_TEMPLATE.contains("\"acceptance_prompt_mode\""));
        assert!(CODEX_TEMPLATE.contains("\"accept_skill\": \"cflx-accept-with-speca\""));
    }

    #[test]
    fn test_claude_template_parseable_by_config() {
        // Template should be parseable by OrchestratorConfig
        let config = OrchestratorConfig::parse_jsonc(CLAUDE_TEMPLATE)
            .expect("CLAUDE_TEMPLATE should be valid JSONC");
        assert!(config.apply_command.is_some());
        assert!(config.archive_command.is_some());
        assert!(config.analyze_command.is_some());
        assert_eq!(config.get_accept_skill(), "cflx-accept");
        assert_eq!(config.get_resolve_skill(), "cflx-resolve");
        assert!(config.apply_command.unwrap().contains("claude"));
    }

    #[test]
    fn test_opencode_template_parseable_by_config() {
        // Template should be parseable by OrchestratorConfig
        let config = OrchestratorConfig::parse_jsonc(OPENCODE_TEMPLATE)
            .expect("OPENCODE_TEMPLATE should be valid JSONC");
        assert!(config.apply_command.is_some());
        assert!(config.archive_command.is_some());
        assert!(config.analyze_command.is_some());
        assert_eq!(config.get_accept_skill(), "cflx-accept");
        assert_eq!(config.get_resolve_skill(), "cflx-resolve");
        assert!(config.apply_command.unwrap().contains("opencode"));
    }

    #[test]
    fn test_codex_template_parseable_by_config() {
        // Template should be parseable by OrchestratorConfig
        let config = OrchestratorConfig::parse_jsonc(CODEX_TEMPLATE)
            .expect("CODEX_TEMPLATE should be valid JSONC");
        assert!(config.apply_command.is_some());
        assert!(config.archive_command.is_some());
        assert!(config.analyze_command.is_some());
        assert_eq!(config.get_accept_skill(), "cflx-accept");
        assert_eq!(config.get_resolve_skill(), "cflx-resolve");
        assert!(config.apply_command.unwrap().contains("codex"));
    }
}