csift 0.11.0

ripgrep for Claude Code session transcripts: fast regex list/search over ~/.claude/projects/**/*.jsonl
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
//! The @-token grammar end to end: uuids, prefixes, agent ids, @main, @trap, encoded dirs.

use crate::harness::*;

#[test]
fn dashed_teammate_name_id_round_trips_as_target() {
    // A teammate NAME may carry dashes (real data: teammate "P1-engine" → agent id
    // `aP1-engine-9cf2f06d6235ca64`). The id `csift agents` prints must round-trip as an
    // `@<agent-id>` target - it used to fall through to the project-dir branch and fail.
    let enc = "-Users-testuser-Projects-dashmate";
    let sess = "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
    let id = "aP1-engine-9cf2f06d6235ca64";
    let h = Home::new();
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u0","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"go"}}"#, "\n",
            r#"{"type":"assistant","uuid":"a0","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"call0","name":"Agent","input":{"name":"P1-engine","subagent_type":"executor","description":"do it"}}]}}"#, "\n",
        ),
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{id}.jsonl"),
        concat!(
            r#"{"type":"user","isSidechain":true,"agentId":"aP1-engine-9cf2f06d6235ca64","timestamp":"2026-06-07T05:00:02.000Z","message":{"role":"user","content":"teammate: probe the dashy widget"}}"#, "\n",
            r#"{"type":"assistant","timestamp":"2026-06-07T05:00:03.000Z","message":{"role":"assistant","content":[{"type":"text","text":"probed"}]}}"#, "\n",
        ),
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{id}.meta.json"),
        r#"{"agentType":"P1-engine","name":"P1-engine","taskKind":"in_process_teammate"}"#,
    );
    let l = h.run(&["list", &format!("@{id}")]);
    assert!(l.success, "list @dashed-teammate-id: {}", l.stderr);
    assert!(
        l.stdout.contains("SUBAGENT") && l.stdout.contains(id),
        "the subagent banner names the teammate id: {}",
        l.stdout
    );
    let s = h.run(&["show", &format!("@{id}"), "--line", "1"]);
    assert!(s.success, "show @dashed-teammate-id: {}", s.stderr);
    assert!(
        s.stdout.contains("teammate: probe the dashy widget"),
        "show fetches from the teammate transcript: {}",
        s.stdout
    );
}

#[test]
fn at_agent_hex_subtree_includes_descendants_unless_no_subagents() {
    // The rule: locating an AGENT → itself (--no-subagents), else itself + ALL topological
    // descendants. Build a nested pair (PARENT spawns CHILD) flat on disk, linked via the
    // child's meta toolUseId pointing at the Agent tool_use recorded in PARENT's transcript.
    let enc = "-Users-testuser-Projects-agtree";
    let sess = "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
    let parent = "aaaa1111bbbb2222c"; // 17 hex
    let child = "cccc3333dddd4444e"; // 17 hex
    let h = Home::new();
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u0","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"go"}}"#, "\n",
            r#"{"type":"assistant","uuid":"a0","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"call_parent","name":"Agent","input":{"description":"parent"}}]}}"#, "\n",
        ),
    );
    // PARENT spawns CHILD (the Agent tool_use is recorded HERE).
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{parent}.jsonl"),
        concat!(
            r#"{"type":"user","isSidechain":true,"agentId":"aaaa1111bbbb2222c","timestamp":"2026-06-07T05:00:02.000Z","message":{"role":"user","content":"PARENTWORK"}}"#, "\n",
            r#"{"type":"assistant","timestamp":"2026-06-07T05:00:03.000Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"call_child","name":"Agent","input":{"description":"child"}}]}}"#, "\n",
        ),
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{parent}.meta.json"),
        r#"{"agentType":"general-purpose","toolUseId":"call_parent"}"#,
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{child}.jsonl"),
        concat!(
            r#"{"type":"user","isSidechain":true,"agentId":"cccc3333dddd4444e","timestamp":"2026-06-07T05:00:04.000Z","message":{"role":"user","content":"CHILDWORK"}}"#, "\n",
            r#"{"type":"assistant","timestamp":"2026-06-07T05:00:05.000Z","message":{"role":"assistant","content":[{"type":"text","text":"ok"}]}}"#, "\n",
        ),
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{child}.meta.json"),
        r#"{"agentType":"Explore","toolUseId":"call_child"}"#,
    );

    // Default `@<parent>` → parent + descendant child both searchable.
    let full = h.run(&["search", "WORK", &format!("@{parent}")]);
    assert!(full.success, "stderr: {}", full.stderr);
    assert!(
        full.stdout.contains("PARENTWORK"),
        "parent in scope: {}",
        full.stdout
    );
    assert!(
        full.stdout.contains("CHILDWORK"),
        "descendant child in scope: {}",
        full.stdout
    );

    // `--no-subagents` → the parent agent ALONE (child excluded).
    let alone = h.run(&["search", "WORK", &format!("@{parent}"), "--no-subagents"]);
    assert!(alone.success, "stderr: {}", alone.stderr);
    assert!(
        alone.stdout.contains("PARENTWORK"),
        "parent still in scope: {}",
        alone.stdout
    );
    assert!(
        !alone.stdout.contains("CHILDWORK"),
        "child EXCLUDED under --no-subagents: {}",
        alone.stdout
    );
}

#[test]
fn cross_surface_session_id_is_identical_for_a_subagent() {
    // id-form unification: the SAME subagent transcript reports the SAME bare-hex
    // session_id from files, search, and turns (search/turns previously kept `agent-`).
    let h = populated_home();
    let files = h.run(&[
        "files",
        at(SESS).as_str(),
        "--by",
        "file",
        "--format",
        "json",
    ]);
    let search = h.run(&["search", "", ENC, at(SESS).as_str(), "--format", "json"]);
    // turns now defaults to top-level-only, so opt INTO spanning subagents to exercise the
    // cross-surface id-form check on the turns surface too.
    let turns = h.run(&[
        "verbatim",
        at(SESS).as_str(),
        "--subagents",
        "--budget",
        "8000",
        "--format",
        "json",
    ]);
    // The bare-hex subagent id (no `agent-` prefix) must appear in each surface's JSON,
    // and the `agent-` prefixed form must NOT.
    for (name, out) in [("files", &files), ("search", &search), ("verbatim", &turns)] {
        assert!(out.success, "{name} stderr: {}", out.stderr);
        assert!(
            !out.stdout.contains("\"agent-aaa111\"") && !out.stdout.contains("agent-aaa111"),
            "{name} leaked an agent- prefixed session_id: {}",
            out.stdout
        );
    }
    // At least one surface must actually mention the bare id (proves the subagent was
    // scanned, not just that the prefix is absent).
    assert!(
        files.stdout.contains("aaa111") || turns.stdout.contains("aaa111"),
        "no surface emitted the bare subagent id; files={} turns={}",
        files.stdout,
        turns.stdout
    );
}

#[test]
fn at_agent_hex_scopes_to_the_subtree() {
    // `@<agent-hex>` now SCOPES to that subagent (+ its topological descendants, unless
    // --no-subagents), per the rule "locating an agent: itself, or itself + descendants".
    // A realistic >=12-char hex is needed (a <=11-char token is a uuid PREFIX, not an agent).
    let enc = "-Users-testuser-Projects-agentscope";
    let sess = "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
    let hex = "aaa111bbb222ccc33"; // 17 hex, like real agent ids
    let h = Home::new();
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u0","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"go"}}"#, "\n",
            r#"{"type":"assistant","uuid":"a0","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"call0","name":"Agent","input":{"description":"do it"}}]}}"#, "\n",
        ),
    );
    h.write(
        &format!("{enc}/{sess}/subagents/agent-{hex}.jsonl"),
        concat!(
            r#"{"type":"user","isSidechain":true,"agentId":"aaa111bbb222ccc33","timestamp":"2026-06-07T05:00:02.000Z","message":{"role":"user","content":"sub: the WIDGET work"}}"#, "\n",
            r#"{"type":"assistant","timestamp":"2026-06-07T05:00:03.000Z","message":{"role":"assistant","content":[{"type":"text","text":"sub done"}]}}"#, "\n",
        ),
    );

    // `search` within `@<agent-hex>` finds content in THAT subagent transcript.
    let s = h.run(&["search", "WIDGET", &format!("@{hex}")]);
    assert!(s.success, "stderr: {}", s.stderr);
    assert!(
        s.stdout.contains(hex),
        "scoped to the subagent: {}",
        s.stdout
    );
    assert!(
        s.stdout.contains("subagent"),
        "branded as a subagent: {}",
        s.stdout
    );

    // A NON-EXISTENT agent hex → honest "no subagent found" (not a session error).
    let miss = h.run(&["search", "x", "@deadbeefdeadbeef0"]);
    assert!(!miss.success);
    assert!(
        miss.stderr.contains("no subagent") && miss.stderr.contains("agents"),
        "guides to agents listing: {}",
        miss.stderr
    );
}

#[test]
fn agent_twelve_hex_fallback_ambiguity_fails_loud() {
    // Mutation pin: the 12+-hex exact-miss prefix FALLBACK has its own ambiguity guard -
    // two agents sharing 12 leading hex chars must produce the AMBIGUOUS error naming
    // both ids, never the generic no-subagent miss (and never a silent pick).
    let h = Home::new();
    let enc = "-Users-dev-example-project";
    let sess = "55667788-9900-4000-8000-00000000000a";
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"lead"}}"#, "\n",
        ),
    );
    let twin_a = "abcd1234abcd1234aaaa";
    let twin_b = "abcd1234abcd1234bbbb";
    for (agent, word) in [(twin_a, "TWINALPHA"), (twin_b, "TWINBETA")] {
        h.write(
            &format!("{enc}/{sess}/subagents/agent-{agent}.jsonl"),
            &format!(
                "{}\n",
                format_args!(
                    r#"{{"type":"user","isSidechain":true,"agentId":"{agent}","timestamp":"2026-06-07T05:00:02.000Z","message":{{"role":"user","content":"seed {word}"}}}}"#
                ),
            ),
        );
    }
    // 16 shared leading hex chars -> the 16-char token is an exact-miss AND a 2-way prefix.
    let ambi = h.run(&["search", "TWIN", &format!("@{}", &twin_a[..16])]);
    assert!(!ambi.success, "ambiguous fallback must error");
    assert!(
        ambi.stderr.contains("AMBIGUOUS")
            && ambi.stderr.contains(twin_a)
            && ambi.stderr.contains(twin_b),
        "the fallback names both candidates: {}",
        ambi.stderr
    );
}

// An UNRECOGNIZED `@`-shape must fail loud naming the @-grammar - never strip the `@` and
// fall through to cwd-relative path resolution (the old behavior sent an ID typo down a
// misleading "no Claude Code project dir" filesystem trail).
#[test]
fn at_token_unrecognized_shapes_fail_loud_never_path_fallthrough() {
    let h = populated_home();
    // 1-3 dashless hex chars: below the 4-char uuid-prefix minimum → the dedicated message.
    for tok in ["@a", "@22", "@224"] {
        let out = h.run(&["list", tok]);
        assert!(!out.success, "{tok} must hard-error: {}", out.stdout);
        assert!(
            out.stderr.contains("too short") && out.stderr.contains("4-11"),
            "{tok} names the prefix minimum: {}",
            out.stderr
        );
        assert!(
            !out.stderr.contains("no Claude Code project dir"),
            "{tok} must not fall through to path resolution: {}",
            out.stderr
        );
    }
    // Non-hex / dashed / empty tokens → the general @-grammar error.
    for tok in ["@notanid", "@1234-ab", "@"] {
        let out = h.run(&["list", tok]);
        assert!(!out.success, "{tok} must hard-error: {}", out.stdout);
        assert!(
            out.stderr.contains("not a recognized @-target"),
            "{tok} names the grammar: {}",
            out.stderr
        );
    }
    // The `@-Users-…` encoded-dir spelling STILL resolves (encoded cwds lead with `-`).
    let enc = h.run(&["list", &format!("@{ENC}")]);
    assert!(enc.success, "stderr: {}", enc.stderr);
    assert!(
        enc.stdout.contains(SESS),
        "lists the fixture session: {}",
        enc.stdout
    );
}

#[test]
fn windows_drive_encoded_dir_targets_resolve() {
    // A Windows cwd (`C:\Users\dev\winproj`) encodes to a DRIVE-LETTER-led projects dir
    // (`C--Users-dev-winproj` - verbatim from CC's sanitizer), which leads with a letter,
    // not `-`. Both target forms must resolve it: the bare positional token and the
    // `@`-prefixed form.
    let h = Home::new();
    let enc = "C--Users-dev-winproj";
    let sess = "99aabbcc-ddee-4000-8000-00000000000e";
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"win work"}}"#, "\n",
        ),
    );
    let bare = h.run(&["list", enc]);
    assert!(bare.success, "stderr: {}", bare.stderr);
    assert!(
        bare.stdout.contains(sess),
        "bare drive-encoded token resolves: {}",
        bare.stdout
    );
    let at_form = h.run(&["list", &format!("@{enc}")]);
    assert!(at_form.success, "stderr: {}", at_form.stderr);
    assert!(
        at_form.stdout.contains(sess),
        "@-prefixed drive-encoded token resolves: {}",
        at_form.stdout
    );
}

#[test]
fn target_jsonl_file_path_scopes_to_session() {
    // THE marquee fix: an LLM that has the session's transcript PATH (from ls/find) passes it
    // directly. Before, csift re-encoded the whole path into a bogus dir and errored.
    let h = populated_home();
    let jsonl = h.projects().join(format!("{ENC}/{SESS}.jsonl"));
    let out = h.run(&["search", "carry", jsonl.to_str().unwrap(), "--no-subagents"]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains(&format!("{}\u{b7}t", &SESS[..8])),
        "scoped to the session: {}",
        out.stdout
    );
    // A non-existent jsonl target errors honestly (never fabricates a dir).
    let bad = h.run(&["search", "carry", "/no/such/session.jsonl"]);
    assert!(!bad.success);
    assert!(
        bad.stderr.contains("no session transcript at"),
        "honest missing-file error: {}",
        bad.stderr
    );
}

#[test]
fn target_at_uuid_routes_to_session() {
    // `@<uuid>` is the explicit session-id target (the form that will replace --session).
    let h = populated_home();
    let out = h.run(&["agents", &format!("@{SESS}")]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("builtin-task"),
        "resolved the session: {}",
        out.stdout
    );
}

#[test]
fn target_at_main_resolves_env_session() {
    // `@main` resolves the calling session from CLAUDE_CODE_SESSION_ID.
    let h = populated_home();
    let out = h.run_with_env(&["agents", "@main"], &[("CLAUDE_CODE_SESSION_ID", SESS)]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("builtin-task"),
        "@main → env session: {}",
        out.stdout
    );
    // @main with no env errors with guidance.
    let no_env = h.run(&["agents", "@main"]);
    assert!(!no_env.success);
    assert!(
        no_env.stderr.contains("CLAUDE_CODE_SESSION_ID is not set"),
        "guidance when env absent: {}",
        no_env.stderr
    );
}

#[test]
fn target_at_encoded_dir_resolves() {
    // `@<encoded-dir>` names a project dir by its encoded form directly.
    let h = populated_home();
    let out = h.run(&["agents", &format!("@{ENC}")]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("builtin-task"),
        "@encoded resolved: {}",
        out.stdout
    );
}

#[test]
fn target_at_uuid_prefix_resolves_unique_and_errors_on_ambiguity() {
    // `@<first-segment>` (the emergent shorthand): a short hex prefix resolves the UNIQUE
    // session whose uuid starts with it, and errors (never silently picks) when ambiguous.
    let h = Home::new();
    // Two sessions sharing the 8-hex first segment `0a1b2c3d`, and one distinct (`deadbeef`).
    let a = "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
    let b = "0a1b2c3d-ffff-4a6b-8c7d-9e0f1a2b3c4d";
    let c = "deadbeef-1111-2222-3333-444455556666";
    for s in [a, b, c] {
        h.write(
            &format!("{ENC}/{s}.jsonl"),
            &format!(
                "{{\"type\":\"user\",\"sessionId\":\"{s}\",\"cwd\":\"/p\",\"timestamp\":\"2026-06-07T05:00:00.000Z\",\"message\":{{\"role\":\"user\",\"content\":\"hi\"}}}}\n"
            ),
        );
    }
    // A unique prefix → that one session (list shows its id).
    let uniq = h.run(&["list", "@deadbeef"]);
    assert!(uniq.success, "stderr: {}", uniq.stderr);
    assert!(
        uniq.stdout.contains(c),
        "unique prefix resolved: {}",
        uniq.stdout
    );
    assert!(
        !uniq.stdout.contains(a),
        "scoped to ONLY the matched session: {}",
        uniq.stdout
    );

    // An ambiguous prefix → error listing BOTH candidates, never a silent pick.
    let amb = h.run(&["list", "@0a1b2c3d"]);
    assert!(!amb.success, "ambiguous prefix must error: {}", amb.stdout);
    assert!(
        amb.stderr.contains("AMBIGUOUS"),
        "says ambiguous: {}",
        amb.stderr
    );
    assert!(
        amb.stderr.contains(a) && amb.stderr.contains(b),
        "lists both candidates: {}",
        amb.stderr
    );

    // A prefix nobody starts with → honest no-match.
    let none = h.run(&["list", "@99999999"]);
    assert!(!none.success);
    assert!(
        none.stderr.contains("no session or agent id starts with"),
        "{}",
        none.stderr
    );
}

#[test]
fn uuid_prefix_minimum_boundary_is_exactly_four() {
    // Mutation pin: the too-short-hex boundary is len < 4 (a 4-char prefix RESOLVES; a
    // 3-char one errors with the dedicated guidance).
    let h = Home::new();
    h.write(
        "-Users-testuser-Projects-pfx/abcd1234-4e5f-4a6b-8c7d-9e0f1a2b3c4d.jsonl",
        "{\"type\":\"user\",\"uuid\":\"u0\",\"timestamp\":\"2026-06-07T05:00:00.000Z\",\"message\":{\"role\":\"user\",\"content\":\"go\"}}\n",
    );
    let ok = h.run(&["list", "@abcd"]);
    assert!(
        ok.success && ok.stdout.contains("abcd1234"),
        "4-hex prefix resolves: {}\n{}",
        ok.stderr,
        ok.stdout
    );
    let short = h.run(&["list", "@abc"]);
    assert!(
        !short.success && short.stderr.contains("too short"),
        "3-hex errors with guidance: {}",
        short.stderr
    );
}

#[test]
fn bare_id_shaped_tokens_get_the_at_hint() {
    // Mutation pin: the bare-id shape catch fires for BOTH the uuid-prefix shape and the
    // bare agent-hex shape (the || chain + the !exists guard).
    let h = Home::new();
    let p = h.run(&["list", "abcd1234"]);
    assert!(
        !p.success && p.stderr.contains("did you mean '@abcd1234'"),
        "prefix shape hint: {}",
        p.stderr
    );
    let a = h.run(&["list", "aabbccdd11223344"]);
    assert!(
        !a.success && a.stderr.contains("did you mean '@aabbccdd11223344'"),
        "agent-hex shape hint: {}",
        a.stderr
    );
}

#[test]
fn bare_basename_jsonl_target_resolves_from_its_own_dir() {
    // A `*.jsonl` token with NO path separator used to feed its empty parent ("") into
    // the project scan (a wrong "no session file found" bail), and the same shape
    // misclassified a bare `agent-<hex>.jsonl` as a top-level session (the `subagents`
    // component test sees no components). The token is absolutized first now, so every
    // spelling of the same file resolves identically.
    let h = Home::new();
    let sess = "3f2e1d0c-9b8a-4756-a432-10fedcba9876";
    let enc = "-Users-dev-example-project";
    let top = h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u1","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"drifting buoy"}}"#,
            "\n",
            r#"{"type":"assistant","uuid":"a1","parentUuid":"u1","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"text","text":"charted"}]}}"#,
            "\n",
        ),
    );
    let sub = h.write(
        &format!("{enc}/{sess}/subagents/agent-b7c6d5e4f3a29180.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"su1","timestamp":"2026-06-07T05:00:02.000Z","message":{"role":"user","content":"probe the reef"}}"#,
            "\n",
            r#"{"type":"assistant","uuid":"sa1","parentUuid":"su1","timestamp":"2026-06-07T05:00:03.000Z","message":{"role":"assistant","content":[{"type":"text","text":"reef probed"}]}}"#,
            "\n",
        ),
    );

    // Top-level transcript, four spellings of the same file: absolute · ./relative ·
    // subdir-relative (from the encoded dir's parent) · bare basename (cwd = its dir).
    let abs = h.run(&["list", top.to_str().unwrap()]);
    assert!(abs.success, "absolute: {}", abs.stderr);
    let dir = top.parent().unwrap();
    let dot = h.run_full(&["list", &format!("./{sess}.jsonl")], &[], Some(dir));
    assert!(dot.success, "./relative: {}", dot.stderr);
    let subdir = h.run_full(
        &["list", &format!("{enc}/{sess}.jsonl")],
        &[],
        Some(dir.parent().unwrap()),
    );
    assert!(subdir.success, "subdir-relative: {}", subdir.stderr);
    let bare = h.run_full(&["list", &format!("{sess}.jsonl")], &[], Some(dir));
    assert!(bare.success, "bare basename: {}", bare.stderr);
    for out in [&abs, &dot, &subdir, &bare] {
        assert!(
            out.stdout.contains(sess) && out.stdout.contains("drifting buoy"),
            "same session row from every spelling:\n{}",
            out.stdout
        );
    }

    // Bare-basename SUBAGENT transcript: must classify as the agent (its own id, its
    // own record), never as a top-level session named by the `agent-` stem.
    let sdir = sub.parent().unwrap();
    let sbare = h.run_full(
        &["list", "agent-b7c6d5e4f3a29180.jsonl", "--no-subagents"],
        &[],
        Some(sdir),
    );
    assert!(sbare.success, "bare subagent basename: {}", sbare.stderr);
    assert!(
        sbare.stdout.contains("SUBAGENT  b7c6d5e4f3a29180")
            && sbare.stdout.contains("probe the reef"),
        "classified as the subagent, bare id, own content:\n{}",
        sbare.stdout
    );
}