carryctx 0.5.7

Local-first memory for coding agents — resume tasks, checkpoints, and context across windows, sessions, and 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
409
410
mod common;

#[test]
fn test_decision_add_and_list() {
    let (dir, bin) = common::setup_test_project("decision_test");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DC"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );

    // Create task
    common::run_cmd(
        &dir,
        &bin,
        &["task", "create", "--title", "Decision test task"],
    );

    // Add decision
    let add = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "Test decision",
            "--context",
            "Testing",
            "--decision",
            "Use markdown",
            "--consequences",
            "None",
            "--task",
            "DC-0001",
            "--json",
        ],
    );
    assert!(add.status.success(), "decision add should succeed");
    let stdout = String::from_utf8_lossy(&add.stdout);
    assert!(
        stdout.contains("Test decision"),
        "decision should contain title"
    );

    // List decisions
    let list = common::run_cmd(&dir, &bin, &["decision", "list", "--json"]);
    assert!(list.status.success(), "decision list should succeed");
    let stdout = String::from_utf8_lossy(&list.stdout);
    assert!(
        stdout.contains("Test decision"),
        "list should contain the decision"
    );
}

#[test]
fn test_decision_search() {
    let (dir, bin) = common::setup_test_project("decision_search_test");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DS"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );
    common::run_cmd(
        &dir,
        &bin,
        &["task", "create", "--title", "Search test task"],
    );
    common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "UniqueSearchDecision",
            "--task",
            "DS-0001",
        ],
    );

    let search = common::run_cmd(
        &dir,
        &bin,
        &["decision", "search", "UniqueSearch", "--json"],
    );
    let stdout = String::from_utf8_lossy(&search.stdout);
    assert!(
        stdout.contains("UniqueSearchDecision"),
        "search should find the decision"
    );
}

#[test]
fn test_decision_add_rationale_is_stored_and_searchable() {
    let (dir, bin) = common::setup_test_project("decision_rationale_test");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DR"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );
    common::run_cmd(
        &dir,
        &bin,
        &["task", "create", "--title", "Rationale test task"],
    );

    let add = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "Rationale decision",
            "--rationale",
            "UniqueRationaleReason",
            "--task",
            "DR-0001",
            "--json",
        ],
    );
    assert!(add.status.success(), "decision add should succeed");
    let stdout = String::from_utf8_lossy(&add.stdout);
    assert!(
        stdout.contains("UniqueRationaleReason"),
        "decision.add output should include the rationale field"
    );

    // Rationale alone (no title/context/consequences match) must be searchable.
    let search = common::run_cmd(
        &dir,
        &bin,
        &["decision", "search", "UniqueRationaleReason", "--json"],
    );
    let stdout = String::from_utf8_lossy(&search.stdout);
    assert!(
        stdout.contains("Rationale decision"),
        "search should find the decision purely by its rationale text"
    );
}

#[test]
fn test_decision_rapid_add_does_not_collide_on_display_id() {
    let (dir, bin) = common::setup_test_project("decision_rapid_test");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DP"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );
    common::run_cmd(
        &dir,
        &bin,
        &["task", "create", "--title", "Rapid add test task"],
    );

    // Six rapid inserts used to collide because display_id was a truncated
    // ULID quantised to a 1024ms bucket (issue #54). All must now succeed
    // with distinct, sequential DEC-#### ids.
    let mut display_ids = Vec::new();
    for i in 0..6 {
        let add = common::run_cmd(
            &dir,
            &bin,
            &[
                "decision",
                "add",
                "--title",
                &format!("rapid {i}"),
                "--task",
                "DP-0001",
                "--json",
            ],
        );
        assert!(
            add.status.success(),
            "rapid decision add #{i} should succeed: {}",
            String::from_utf8_lossy(&add.stderr)
        );
        let stdout = String::from_utf8_lossy(&add.stdout);
        let value: serde_json::Value = serde_json::from_str(&stdout)
            .unwrap_or_else(|e| panic!("decision add #{i} did not print JSON: {e}: {stdout}"));
        let display_id = value["data"]["display_id"]
            .as_str()
            .expect("display_id present")
            .to_string();
        display_ids.push(display_id);
    }

    let unique: std::collections::HashSet<_> = display_ids.iter().collect();
    assert_eq!(
        unique.len(),
        display_ids.len(),
        "all display_ids must be unique, got {display_ids:?}"
    );
}

// ── Issue #71: decision list --task must filter and validate ─────────────

#[test]
fn test_decision_list_task_filters_by_task() {
    let (dir, bin) = common::setup_test_project("decision_task_filter");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DF"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );
    common::run_cmd(&dir, &bin, &["task", "create", "--title", "Task A"]);
    common::run_cmd(&dir, &bin, &["task", "create", "--title", "Task B"]);

    for (task_ref, title) in [("DF-0001", "decision for A"), ("DF-0002", "decision for B")] {
        let add = common::run_cmd(
            &dir,
            &bin,
            &["decision", "add", "--title", title, "--task", task_ref],
        );
        assert!(add.status.success(), "decision add for {task_ref}");
    }

    // Unfiltered list sees both.
    let all = common::run_cmd(&dir, &bin, &["decision", "list", "--json"]);
    let all_value: serde_json::Value = serde_json::from_slice(&all.stdout).unwrap();
    assert_eq!(all_value["data"].as_array().unwrap().len(), 2);

    // Filtered list sees only the requested task's decision.
    let filtered = common::run_cmd(
        &dir,
        &bin,
        &["decision", "list", "--task", "DF-0001", "--json"],
    );
    assert!(filtered.status.success());
    let filtered_value: serde_json::Value = serde_json::from_slice(&filtered.stdout).unwrap();
    let rows = filtered_value["data"].as_array().unwrap();
    assert_eq!(rows.len(), 1, "list --task must narrow the row count");
    let task_ids: std::collections::HashSet<_> = rows
        .iter()
        .map(|r| r["task_id"].as_str().unwrap())
        .collect();
    assert_eq!(task_ids.len(), 1, "every row must belong to the same task");

    // A bad ref is rejected, not silently ignored.
    let bad = common::run_cmd(
        &dir,
        &bin,
        &["decision", "list", "--task", "GARBAGE-9999", "--json"],
    );
    assert!(!bad.status.success(), "bad task ref must fail");
    let bad_value: serde_json::Value = serde_json::from_slice(&bad.stderr).unwrap();
    assert_eq!(bad_value["error"]["code"], "RESOURCE_NOT_FOUND");
}

#[test]
fn test_decision_supersede_text_and_json_output() {
    let (dir, bin) = common::setup_test_project("decision_supersede_test");
    common::run_cmd(&dir, &bin, &["init", "--force", "--task-prefix", "DS"]);
    common::run_cmd(
        &dir,
        &bin,
        &[
            "agent",
            "register",
            "--name",
            "tester",
            "--provider",
            "test",
        ],
    );
    common::run_cmd(&dir, &bin, &["task", "create", "--title", "Supersede Task"]);

    let d1 = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "Decision One",
            "--task",
            "DS-0001",
            "--json",
        ],
    );
    assert!(d1.status.success());

    let d2 = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "Decision Two",
            "--task",
            "DS-0001",
            "--json",
        ],
    );
    assert!(d2.status.success());
    let d2_val: serde_json::Value = serde_json::from_slice(&d2.stdout).unwrap();
    let d2_ulid = d2_val["data"]["id"].as_str().unwrap();

    // 1. Text output test using display IDs
    let sup_text = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "supersede",
            "DEC-0001",
            "--by",
            "DEC-0002",
            "--agent",
            "tester",
        ],
    );
    assert!(
        sup_text.status.success(),
        "decision supersede with display ID should succeed"
    );
    let stdout_text = String::from_utf8_lossy(&sup_text.stdout);
    assert!(
        stdout_text.contains("Decision DEC-0001 superseded by DEC-0002"),
        "stdout must contain both display IDs, got: {stdout_text}"
    );
    assert!(
        !stdout_text.contains("Decision  superseded by "),
        "stdout must not have missing IDs: {stdout_text}"
    );

    // 2. Add a third decision and supersede using ULIDs
    let d3 = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "add",
            "--title",
            "Decision Three",
            "--task",
            "DS-0001",
            "--json",
        ],
    );
    assert!(d3.status.success());
    let d3_val: serde_json::Value = serde_json::from_slice(&d3.stdout).unwrap();
    let d3_ulid = d3_val["data"]["id"].as_str().unwrap();

    let sup_ulid = common::run_cmd(
        &dir,
        &bin,
        &[
            "decision",
            "supersede",
            d2_ulid,
            "--by",
            d3_ulid,
            "--agent",
            "tester",
        ],
    );
    assert!(
        sup_ulid.status.success(),
        "decision supersede with ULIDs should succeed"
    );
    let stdout_ulid = String::from_utf8_lossy(&sup_ulid.stdout);
    assert!(
        !stdout_ulid.contains("Decision  superseded by "),
        "stdout must not have missing IDs with ULID: {stdout_ulid}"
    );
}