clt-rs 0.6.19

File-backed task manager with a TUI Kanban board and multi-project Codex agent registry
Documentation
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
use crate::task::follow_up_session;
use crate::test_support::prelude::*;
use crate::test_support::*;

#[test]
fn actionable_follow_up_is_committed_and_can_start_a_fresh_git_run() {
    for folders in [false, true] {
        let root = temp_root("git-todo-follow-up");
        let project_root = root.join("project");
        let state_dir = root.join("state");
        init_tasks(&project_root, folders).unwrap();
        let board = TaskBoard::for_project(&project_root);
        board
            .insert_content(
                TaskStatus::Doing,
                None,
                "Implement feature codex:parent-session",
            )
            .unwrap();
        initialize_test_git_repository(&project_root);
        let project_root = fs::canonicalize(project_root).unwrap();
        let store = agent::TursoAgentStore::open_blocking(&state_dir).unwrap();
        store
            .register_project_blocking(&project_root, "project")
            .unwrap();
        store
            .set_project_git_mode_for_path_blocking(&project_root, AgentGitMode::Commit)
            .unwrap();
        let project = store.list_projects_blocking().unwrap().remove(0);
        store
            .mark_session_running_blocking(
                project.id,
                "parent-session",
                123,
                "parent-run",
                &root.join("out"),
                &root.join("err"),
            )
            .unwrap();
        let start = capture_agent_git_start_state(&project_root, AgentGitMode::Commit).unwrap();
        ensure_agent_git_working_record(
            &store,
            &project,
            "parent-session",
            "parent-run",
            Some(&start),
        )
        .unwrap();
        bind_agent_git_working_task_identity(&store, &project, "parent-session", "parent-run")
            .unwrap();
        let workflow = ManagedTaskWorkflow::new(&project_root);
        for _ in 0..2 {
            assert_eq!(
                workflow
                    .add_follow_up(
                        TaskStatus::Doing,
                        "1",
                        "Fix existing lint warnings.",
                        "Same failure on starting revision; feature checks pass",
                        None
                    )
                    .unwrap(),
                TaskStatus::Todo
            );
        }
        assert_eq!(board.entries(TaskStatus::Todo).unwrap().len(), 1);
        let follow_up = board.entry(TaskStatus::Todo, 1).unwrap();
        assert_eq!(
            follow_up_session(&follow_up.content),
            Some("parent-session")
        );
        assert!(!task_entry_is_blocked(&follow_up));
        assert!(
            workflow
                .add_follow_up(
                    TaskStatus::Doing,
                    "1",
                    "Duplicate follow-up.",
                    "Evidence",
                    Some("No runtime")
                )
                .is_err()
        );

        let parent = board.entry(TaskStatus::Doing, 1).unwrap();
        board.write_entry_content(TaskStatus::Doing, &parent, "Implement feature — COMPLETED 2026-09-05: verified; lint cleanup queued codex:parent-session").unwrap();
        fs::write(project_root.join("feature.txt"), "implemented\n").unwrap();
        run_test_git(&project_root, &["add", "feature.txt", "tasks"]);
        // Preserve an unrelated Todo added after the task payload was staged.
        board
            .insert_content(TaskStatus::Todo, None, "Concurrent human task")
            .unwrap();
        let context = AutomatedAgentChildContext {
            project_id: project.id,
            run_token: "parent-run".to_string(),
        };
        move_task_to_done_with_agent_store(&project_root, TaskStatus::Doing, "1", &context, &store)
            .unwrap();
        let paths = if folders {
            ["tasks/doing", "tasks/done"]
        } else {
            ["tasks/doing.md", "tasks/done.md"]
        };
        run_test_git(&project_root, &["add", "--", paths[0], paths[1]]);
        run_test_agent_git(
            &project_root,
            &[
                "commit",
                "-m",
                "Implement feature and queue lint cleanup",
                "-m",
                "CLT-Task: codex:parent-session",
            ],
        );
        let sealed = store
            .git_finalization_blocking(project.id, "parent-session")
            .unwrap()
            .unwrap();
        let completed = reconcile_agent_git_finalization(
            &store,
            &project_root,
            sealed,
            Some("parent-run"),
            None,
        )
        .unwrap();
        assert_eq!(completed.state, GitFinalizationState::Completed);
        let entries = git_ref_task_entries(&project_root, "HEAD").unwrap();
        assert_eq!(
            entries
                .iter()
                .filter(|entry| entry.status == "todo"
                    && follow_up_session(&entry.content) == Some("parent-session"))
                .count(),
            1
        );
        assert!(
            !entries
                .iter()
                .any(|entry| entry.content.contains("Concurrent human task"))
        );
        let scan = scan_agent_project(&project_root);
        assert_eq!(scan.blocked_task_count(), 0);
        assert!(scan.has_pending_task());
        assert_eq!(
            automated_codex_session_to_resume(&project_root, AgentTaskSelection::NextTodo).unwrap(),
            None
        );

        // This previously failed as RecoverBlocked because the new task has no journal.
        let next_start = prepare_agent_git_start_state_for_run(
            &store,
            &project,
            AgentTaskSelection::NextTodo,
            false,
            false,
            "follow-up-run",
        )
        .unwrap()
        .unwrap();
        assert_ne!(next_start.starting_head, start.starting_head);
        move_task(&project_root, TaskStatus::Todo, TaskStatus::Doing, "1").unwrap();
        assert!(
            attach_codex_session_to_active_task(
                &project_root,
                AgentTaskSelection::NextTodo,
                &[],
                &[],
                "follow-up-session"
            )
            .unwrap()
        );
        assert_eq!(
            task_status_for_codex_session(&project_root, "parent-session").unwrap(),
            Some(TaskStatus::Done)
        );
        assert_eq!(
            task_status_for_codex_session(&project_root, "follow-up-session").unwrap(),
            Some(TaskStatus::Doing)
        );
        fs::remove_dir_all(root).unwrap();
    }
}

#[test]
fn blocked_follow_up_is_sealed_resealable_and_recoverable_in_both_board_formats() {
    for folders in [false, true] {
        let root = temp_root("git-blocked-follow-up");
        let project_root = root.join("project");
        let state_dir = root.join("state");
        init_tasks(&project_root, folders).unwrap();
        let board = TaskBoard::for_project(&project_root);
        board
            .insert_content(
                TaskStatus::Doing,
                None,
                "Implement feature — BLOCKED 2026-09-03: GPU harness fails codex:session-follow-up",
            )
            .unwrap();
        board
            .insert_content(TaskStatus::Doing, None, "Keep another task unchanged")
            .unwrap();
        initialize_test_git_repository(&project_root);
        let project_root = fs::canonicalize(project_root).unwrap();
        let store = agent::TursoAgentStore::open_blocking(&state_dir).unwrap();
        store
            .register_project_blocking(&project_root, "project")
            .unwrap();
        store
            .set_project_git_mode_for_path_blocking(&project_root, AgentGitMode::Commit)
            .unwrap();
        let project = store.list_projects_blocking().unwrap().remove(0);
        store
            .mark_session_running_blocking(
                project.id,
                "session-follow-up",
                123,
                "run-follow-up",
                &root.join("out"),
                &root.join("err"),
            )
            .unwrap();
        let start = capture_agent_git_start_state(&project_root, AgentGitMode::Commit).unwrap();
        ensure_agent_git_working_record(
            &store,
            &project,
            "session-follow-up",
            "run-follow-up",
            Some(&start),
        )
        .unwrap();
        bind_agent_git_working_task_identity(
            &store,
            &project,
            "session-follow-up",
            "run-follow-up",
        )
        .unwrap();
        let original = board.entry(TaskStatus::Doing, 1).unwrap();
        let other = board.entry(TaskStatus::Doing, 2).unwrap();
        let mut recovery_job = AgentRunJob {
            state_dir: state_dir.clone(),
            project: project.clone(),
            holder: "recovery".to_string(),
            worker_token: None,
            max_global_jobs: 1,
            task_selection: AgentTaskSelection::RecoverBlocked,
            resume_session_id: Some("session-follow-up".to_string()),
            blocked_task_count_before: 1,
            done_task_contents_before: completed_task_contents(&project_root).unwrap(),
            blocked_task_snapshots_before: blocked_task_snapshots(&project_root).unwrap(),
        };
        assert!(blocked_recovery_made_no_progress(&recovery_job));
        ManagedTaskWorkflow::new(&project_root)
            .add_follow_up(
                TaskStatus::Doing,
                "1",
                "Repair GPU harness.",
                "GPU harness fails identically at starting revision; requires working GPU runtime",
                Some("GPU harness fails identically at starting revision; requires working GPU runtime"),
            )
            .unwrap();
        let preserved = board.entry(TaskStatus::Doing, 2).unwrap();
        assert_eq!(preserved.source, other.source);
        assert_eq!(preserved.content, other.content);
        board.write_entry_content(TaskStatus::Doing, &original, "Implement feature — COMPLETED 2026-09-04: feature tests passed; GPU baseline failure recorded in linked follow-up codex:session-follow-up").unwrap();
        fs::write(project_root.join("feature.txt"), "implemented\n").unwrap();
        run_test_git(&project_root, &["add", "feature.txt", "tasks"]);
        // A separate concurrent Todo must remain outside the task commit.
        board
            .insert_content(TaskStatus::Todo, None, "Concurrent human task")
            .unwrap();
        let context = AutomatedAgentChildContext {
            project_id: project.id,
            run_token: "run-follow-up".to_string(),
        };
        move_task_to_done_with_agent_store(&project_root, TaskStatus::Doing, "1", &context, &store)
            .unwrap();
        let doing_path = if folders {
            "tasks/doing"
        } else {
            "tasks/doing.md"
        };
        let done_path = if folders {
            "tasks/done"
        } else {
            "tasks/done.md"
        };
        run_test_git(&project_root, &["add", "--", doing_path, done_path]);
        let pending = store
            .git_finalization_blocking(project.id, "session-follow-up")
            .unwrap()
            .unwrap();
        // Corrected implementation after a hook may be resealed with the same follow-up.
        fs::write(
            project_root.join("feature.txt"),
            "formatted implementation\n",
        )
        .unwrap();
        run_test_git(&project_root, &["add", "feature.txt"]);
        let manifest = capture_agent_git_resealed_manifest(
            AgentGitProofContext {
                store: &store,
                project_id: project.id,
            },
            &project_root,
            &pending.worktree_baseline,
            "session-follow-up",
            pending.task_identity.as_deref().unwrap(),
            pending.starting_head.as_deref().unwrap(),
            pending.branch_ref.as_deref(),
        )
        .unwrap();
        assert!(
            store
                .reseal_git_finalization_manifest_blocking(
                    project.id,
                    "session-follow-up",
                    pending.generation,
                    pending.task_identity.as_deref().unwrap(),
                    &manifest,
                    "run-follow-up",
                    "200"
                )
                .unwrap()
        );
        run_test_agent_git(
            &project_root,
            &[
                "commit",
                "-m",
                "Implement feature and track GPU failure",
                "-m",
                "CLT-Task: codex:session-follow-up",
            ],
        );
        let sealed = store
            .git_finalization_blocking(project.id, "session-follow-up")
            .unwrap()
            .unwrap();
        let completed = reconcile_agent_git_finalization(
            &store,
            &project_root,
            sealed,
            Some("run-follow-up"),
            None,
        )
        .unwrap();
        assert_eq!(completed.state, GitFinalizationState::Completed);
        assert_eq!(
            run_test_git(
                &project_root,
                &[
                    "rev-list",
                    "--count",
                    &format!("{}..HEAD", start.starting_head)
                ]
            ),
            "1"
        );
        let entries = git_ref_task_entries(&project_root, "HEAD").unwrap();
        assert_eq!(
            entries
                .iter()
                .filter(|entry| entry.status == "doing"
                    && follow_up_session(&entry.content) == Some("session-follow-up"))
                .count(),
            1
        );
        assert!(
            !entries
                .iter()
                .any(|entry| entry.content.contains("Concurrent human task"))
        );
        let scan = scan_agent_project(&project_root);
        assert_eq!(scan.blocked_doing_count, 1);
        assert!(!blocked_recovery_made_no_progress(&recovery_job));
        recovery_job.blocked_task_snapshots_before[0].content =
            "Different blocked task".to_string();
        assert!(blocked_recovery_made_no_progress(&recovery_job));
        let follow_up = board
            .entries(TaskStatus::Doing)
            .unwrap()
            .into_iter()
            .find(task_entry_is_blocked)
            .unwrap();
        assert_eq!(
            recoverable_codex_session_id_from_task_content(&follow_up.content),
            None
        );
        let doing_before = task_contents_for_status(&project_root, TaskStatus::Doing).unwrap();
        let blocked_before = blocked_task_snapshots(&project_root).unwrap();
        assert_eq!(
            automated_codex_session_to_resume(&project_root, AgentTaskSelection::RecoverBlocked)
                .unwrap(),
            None
        );
        assert!(
            attach_codex_session_to_active_task(
                &project_root,
                AgentTaskSelection::RecoverBlocked,
                &doing_before,
                &blocked_before,
                "follow-up-own-session"
            )
            .unwrap()
        );
        assert_eq!(
            task_status_for_codex_session(&project_root, "session-follow-up").unwrap(),
            Some(TaskStatus::Done)
        );
        assert_eq!(
            task_status_for_codex_session(&project_root, "follow-up-own-session").unwrap(),
            Some(TaskStatus::Doing)
        );
        fs::remove_dir_all(root).unwrap();
    }
}

#[test]
fn follow_up_allowance_preserves_exact_board_scope() {
    for folders in [false, true] {
        for blocked in [false, true] {
            let follow_up_status = if blocked {
                TaskStatus::Doing
            } else {
                TaskStatus::Todo
            };
            let follow_up_index = if blocked { 3 } else { 1 };
            for mutation in [
                "unrelated",
                "wrong-state",
                "second-follow-up",
                "wrong-parent",
                "duplicate-session",
                "header",
                "existing",
                "attachment",
                "symlink",
            ] {
                let root = temp_root("follow-up-scope");
                init_tasks(&root, folders).unwrap();
                let board = TaskBoard::for_project(&root);
                board
                    .insert_content(
                        TaskStatus::Doing,
                        None,
                        "Finish feature codex:session-scope",
                    )
                    .unwrap();
                board
                    .insert_content(TaskStatus::Doing, None, "Existing task")
                    .unwrap();
                initialize_test_git_repository(&root);
                let parent = run_test_git(&root, &["rev-parse", "HEAD"]);
                let identity = durable_task_identity("Finish feature").unwrap();
                let scope =
                    agent_git_task_scope_without_selected(&root, &parent, &identity).unwrap();
                let selected = board.entry(TaskStatus::Doing, 1).unwrap();
                board
                    .write_entry_content(
                        TaskStatus::Doing,
                        &selected,
                        "Finish feature — COMPLETED 2026-09-04: verified codex:session-scope",
                    )
                    .unwrap();
                ManagedTaskWorkflow::new(&root)
                    .add_follow_up(
                        TaskStatus::Doing,
                        "1",
                        "Repair harness.",
                        "baseline failure; requires runtime",
                        blocked.then_some("baseline failure; requires runtime"),
                    )
                    .unwrap();
                match mutation {
                    "second-follow-up" => board
                        .insert_content(
                            TaskStatus::Todo,
                            None,
                            "Another follow-up clt-follow-up:session-scope",
                        )
                        .unwrap(),
                    "unrelated" => board
                        .insert_content(TaskStatus::Todo, None, "Unrelated addition")
                        .unwrap(),
                    "header" => {
                        fs::write(root.join("tasks/unrelated.txt"), "extra board payload\n")
                            .unwrap()
                    }
                    "attachment" if folders => {
                        let follow_up = board.entry(follow_up_status, follow_up_index).unwrap();
                        let TaskSource::Path { path, .. } = follow_up.source else {
                            unreachable!()
                        };
                        fs::remove_file(&path).unwrap();
                        fs::create_dir(&path).unwrap();
                        fs::write(path.join("task.md"), follow_up.content).unwrap();
                        fs::write(path.join("attachment.txt"), "unsealed attachment").unwrap();
                    }
                    "attachment" => fs::write(
                        root.join("tasks/doing.md"),
                        format!(
                            "{}\nExtra footer\n",
                            fs::read_to_string(root.join("tasks/doing.md")).unwrap()
                        ),
                    )
                    .unwrap(),
                    "symlink" => {
                        #[cfg(unix)]
                        if folders {
                            let follow_up = board.entry(follow_up_status, follow_up_index).unwrap();
                            let TaskSource::Path { path, .. } = follow_up.source else {
                                unreachable!()
                            };
                            // A link to otherwise valid text must not widen the file allowance.
                            let target = root.join("linked.txt");
                            fs::write(&target, follow_up.content).unwrap();
                            fs::remove_file(&path).unwrap();
                            std::os::unix::fs::symlink(target, &path).unwrap();
                        } else {
                            board
                                .insert_content(TaskStatus::Todo, None, "Unrelated task")
                                .unwrap();
                        }
                        #[cfg(not(unix))]
                        board
                            .insert_content(TaskStatus::Todo, None, "Unrelated task")
                            .unwrap();
                    }
                    _ => {
                        let (status, index) = if mutation == "existing" {
                            (TaskStatus::Doing, 2)
                        } else {
                            (follow_up_status, follow_up_index)
                        };
                        let entry = board.entry(status, index).unwrap();
                        let replacement = match mutation {
                            "wrong-state" if !blocked => {
                                "Repair harness — BLOCKED 2026-09-04: failure clt-follow-up:session-scope"
                            }
                            "wrong-state" => {
                                "Repair harness — UNBLOCKED 2026-09-04: ready clt-follow-up:session-scope"
                            }
                            "wrong-parent" => {
                                "Repair harness — BLOCKED 2026-09-04: failure clt-follow-up:other-session"
                            }
                            "duplicate-session" => {
                                "Repair harness — BLOCKED 2026-09-04: failure clt-follow-up:session-scope codex:session-scope"
                            }
                            "existing" => "Rewritten existing task",
                            _ => unreachable!(),
                        };
                        board
                            .write_entry_content(status, &entry, replacement)
                            .unwrap();
                    }
                }
                run_test_git(&root, &["add", "tasks"]);
                let staged = run_test_git(&root, &["write-tree"]);
                assert!(
                    project_agent_git_completed_tree(
                        &root,
                        &staged,
                        "session-scope",
                        &identity,
                        &parent,
                        &scope
                    )
                    .is_err(),
                    "accepted {mutation} with folders={folders}, blocked={blocked}"
                );
                fs::remove_dir_all(root).unwrap();
            }
        }
    }
}

#[test]
fn completed_note_cannot_hide_a_later_blocker() {
    assert!(!task_content_has_completed_note(
        "Feature — COMPLETED 2026-09-03: implemented — BLOCKED 2026-09-04: acceptance fails"
    ));
    assert!(task_content_has_completed_note(
        "Feature — BLOCKED 2026-09-03: acceptance fails — COMPLETED 2026-09-04: fixed and verified"
    ));
}