csift 0.10.5

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
//! search label taxonomy acceptance: role families render under their leaves.

use crate::harness::*;

#[test]
fn acceptance_communication_sent_spawn_and_subagent_opener() {
    // §C8 a Task/Agent spawn tool_use → `agent.communication.sent` (self ⇨ child); §C6 SendMessage
    // message → sent; §C9 the subagent transcript opener → `agent.communication.inbox` (parent ⇨ self).
    let h = acceptance_home();

    let spawn = acc(&h, "zzspawn", "agent.communication.sent");
    assert!(spawn.success, "C8: stderr {}", spawn.stderr);
    assert!(
        spawn.stdout.contains("agent.communication.sent")
            && spawn.stdout.contains("self ⇨ audit-x"),
        "C8 spawn → comm.sent (self ⇨ audit-x):\n{}",
        spawn.stdout
    );

    let sent = acc(&h, "zzsent", "agent.communication.sent");
    assert!(
        sent.stdout.contains("agent.communication.sent")
            && sent.stdout.contains("self ⇨ GraftBoard"),
        "C6 SendMessage message → comm.sent (self ⇨ GraftBoard):\n{}",
        sent.stdout
    );

    // C9 needs subagent span (the opener lives in the subagent transcript).
    let opener = h.run(&[
        "search",
        "zzopener",
        "-t",
        "agent.communication.inbox",
        &at(ACC_SESS),
    ]);
    assert!(opener.success, "C9: stderr {}", opener.stderr);
    assert!(
        opener.stdout.contains("agent.communication.inbox") && opener.stdout.contains("⇨ self"),
        "C9 subagent opener → comm.inbox (parent ⇨ self):\n{}",
        opener.stdout
    );
}

#[test]
fn slash_command_wrapper_extracted_in_both_tag_orders() {
    // The slash-command wrapper appears in TWO tag orders in real corpora: OLD
    // (`<command-name>` first) and NEW (`<command-message>` first - current CC).
    // Detection must catch both; the rendered body is `/name args` (never wrapper XML),
    // and a pattern INSIDE the args matches through the literal prefilter + whole-file
    // gate (args are verbatim raw substrings).
    let h = Home::new();
    let sess = "5c5d5e5f-2222-4333-8444-955566677788";
    let body = concat!(
        r#"{"type":"user","uuid":"c1","sessionId":"5c5d5e5f-2222-4333-8444-955566677788","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"<command-name>/compact</command-name>\n<command-message>compact</command-message>\n<command-args>old order zqxjkvold</command-args>"}}"#,
        "\n",
        r#"{"type":"assistant","uuid":"a1","sessionId":"5c5d5e5f-2222-4333-8444-955566677788","timestamp":"2026-06-07T05:00:05.000Z","message":{"role":"assistant","content":[{"type":"text","text":"first reply"}]}}"#,
        "\n",
        r#"{"type":"user","uuid":"c2","sessionId":"5c5d5e5f-2222-4333-8444-955566677788","timestamp":"2026-06-07T05:01:00.000Z","message":{"role":"user","content":"<command-message>csift</command-message>\n<command-name>/csift</command-name>\n<command-args>new order zqxjkvnew</command-args>"}}"#,
        "\n",
        r#"{"type":"assistant","uuid":"a2","sessionId":"5c5d5e5f-2222-4333-8444-955566677788","timestamp":"2026-06-07T05:01:05.000Z","message":{"role":"assistant","content":[{"type":"text","text":"second reply"}]}}"#,
        "\n",
        r#"{"type":"user","uuid":"c3","sessionId":"5c5d5e5f-2222-4333-8444-955566677788","timestamp":"2026-06-07T05:02:00.000Z","message":{"role":"user","content":"<command-message>compact</command-message>\n<command-name>/compact</command-name>\n<command-args></command-args>"}}"#,
        "\n",
    );
    h.write(
        &format!("-Users-testuser-Projects-slash/{sess}.jsonl"),
        body,
    );
    let at = format!("@{sess}");

    // A literal inside the NEW-order args matches through prefilter/gate; the excerpt is
    // the extracted `/name args` form, never wrapper XML.
    let out = h.run(&["search", "zqxjkvnew", &at]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("/csift new order zqxjkvnew"),
        "extracted render: {}",
        out.stdout
    );
    assert!(
        !out.stdout.contains("<command-args>"),
        "wrapper XML must not leak: {}",
        out.stdout
    );
    assert!(out.stdout.contains("user.message"), "{}", out.stdout);

    // Same for the OLD order.
    let out = h.run(&["search", "zqxjkvold", &at]);
    assert!(
        out.stdout.contains("/compact old order zqxjkvold"),
        "{}",
        out.stdout
    );

    // `show` renders the same extraction (shared engine).
    let out = h.run(&["show", &at, "--line", "3"]);
    assert!(
        out.stdout.contains("/csift new order zqxjkvnew"),
        "{}",
        out.stdout
    );

    // A NO-ARGS wrapper (either order) is machinery: never user.message, and it must NOT
    // count as a genuine turn opener (all three wrappers fold; no turn boundary shifts).
    let out = h.run(&["search", "", &at, "--count-by", "label", "--format", "json"]);
    let rows = json_rows(&out.stdout, "census");
    let user_msgs = rows
        .iter()
        .find(|r| r["key"] == "user.message")
        .and_then(|r| r["records"].as_u64())
        .unwrap_or(0);
    assert_eq!(user_msgs, 2, "only the two with-args wrappers: {rows:?}");
    let invocations = rows
        .iter()
        .find(|r| r["key"] == "harness.command.invocation")
        .and_then(|r| r["records"].as_u64())
        .unwrap_or(0);
    assert_eq!(invocations, 3, "all three wrappers: {rows:?}");

    // The explicit harness lens still reaches the wrapper form. (`-c` counts EXCHANGES,
    // and no wrapper opens a turn, so all three fold into the single turn-0 lead - the
    // per-RECORD count is the census assertion above.)
    let out = h.run(&["search", "", &at, "-t", "harness.command.invocation", "-c"]);
    assert_eq!(out.stdout.trim(), "1", "{}", out.stdout);
    let out = h.run(&["search", "", &at, "-t", "harness.command.invocation"]);
    assert!(
        out.stdout.contains("harness.command.invocation"),
        "{}",
        out.stdout
    );
}

#[test]
fn acceptance_user_role_message_shapes() {
    // §A1 string · §A2 text-block array · §A3 recovered <command-args> prose - all `user.message`.
    let h = acceptance_home();
    for (oracle, token) in [
        ("A1 string", "zzgenuine"),
        ("A2 text-block", "zzblocktext"),
        ("A3 command-args", "zzcmdargs"),
    ] {
        let out = acc(&h, token, "user.message");
        assert!(out.success, "{oracle}: stderr {}", out.stderr);
        assert!(
            out.stdout.contains("user.message"),
            "{oracle} must classify user.message:\n{}",
            out.stdout
        );
    }
}

#[test]
fn acceptance_communication_signals_render_direction() {
    // §C2 bare-lead inbox · §C3 idle_notification · §C4 teammate_terminated · §C5 shutdown_approved
    // · §C7 SendMessage shutdown_request - each renders `from ⇨ to` (the owner side is `self`).
    let h = acceptance_home();
    let cases = [
        (
            "C2 inbox",
            "zzbareinbox",
            "agent.communication.inbox",
            "team-lead ⇨ self",
        ),
        (
            "C3 idle",
            "zzidle",
            "agent.communication.signal",
            "SOurDnd ⇨ self",
        ),
        (
            "C4 terminated",
            "zzterminated",
            "agent.communication.signal",
            "system ⇨ self",
        ),
        (
            "C5 approved",
            "zzapproved",
            "agent.communication.signal",
            "B38 ⇨ self",
        ),
        (
            "C7 shutdown_req",
            "zzshutdownreq",
            "agent.communication.signal",
            "self ⇨ GraftBoard",
        ),
    ];
    for (oracle, token, selector, dir) in cases {
        let out = acc(&h, token, selector);
        assert!(out.success, "{oracle}: stderr {}", out.stderr);
        assert!(
            out.stdout.contains(selector),
            "{oracle} must classify {selector}:\n{}",
            out.stdout
        );
        assert!(
            out.stdout.contains(dir),
            "{oracle} must render direction `{dir}`:\n{}",
            out.stdout
        );
    }
}

#[test]
fn acceptance_harness_notification_monitor() {
    // §D4 / §G6 - a Monitor `<task-notification>` pulse (UNATTESTED in the corpus → synthetic) →
    // `harness.notification.monitor`, rendered as the `[monitor <id> <status>] <summary>` label.
    let h = acceptance_home();
    let out = acc(&h, "zzmonitor", "harness.notification.monitor");
    assert!(out.success, "D4: stderr {}", out.stderr);
    assert!(
        out.stdout.contains("harness.notification.monitor"),
        "D4/G6 monitor pulse → harness.notification.monitor:\n{}",
        out.stdout
    );
    assert!(
        out.stdout.contains("[monitor mon1"),
        "D4/G6 must render the automation_label, not raw XML:\n{}",
        out.stdout
    );
}

#[test]
fn acceptance_harness_command_and_interrupt() {
    // §D8 <command-name> wrapper · §D9 <local-command-stdout> · §D10/§D11 the two interrupt markers.
    let h = acceptance_home();
    for (oracle, token, selector) in [
        ("D8 invocation", "zzcmdargs", "harness.command.invocation"),
        ("D9 stdout", "zzstdout", "harness.command.stdout"),
        (
            "D10 interrupt.user",
            "interrupted by user",
            "harness.interrupt.user",
        ),
        (
            "D11 interrupt.tool",
            "interrupted by user for tool",
            "harness.interrupt.tool",
        ),
    ] {
        let out = acc(&h, token, selector);
        assert!(out.success, "{oracle}: stderr {}", out.stderr);
        assert!(
            out.stdout.contains(selector),
            "{oracle} must classify {selector}:\n{}",
            out.stdout
        );
    }
}

#[test]
fn acceptance_harness_schedule_and_meta() {
    // §D12 fired wakeup tick · §D13 continuation · §G2 meta.hook (stop-hook feedback) · §G2 meta.loop
    // (autonomous-loop driver). All ride on isMeta records that classify (not user.message).
    let h = acceptance_home();
    for (oracle, token, selector) in [
        ("D12 wakeup", "zzwakeup", "harness.schedule.wakeup"),
        (
            "D13 continuation",
            "Continue from where you left off",
            "harness.schedule.continuation",
        ),
        ("G2 meta.hook", "zzhook", "harness.meta.hook"),
        ("G2 meta.loop", "zzloop", "harness.meta.loop"),
    ] {
        let out = acc(&h, token, selector);
        assert!(out.success, "{oracle}: stderr {}", out.stderr);
        assert!(
            out.stdout.contains(selector),
            "{oracle} must classify {selector}:\n{}",
            out.stdout
        );
    }
}

#[test]
fn search_teammate_message_is_inbox_not_user_regression() {
    // GOLD §1 / oracle §H: an inbound `<teammate-message>` is `type:user/role:user/string` and
    // matches NO synthetic marker, so the OLD `is_genuine_user` counted it as the human. The
    // cutover classifies it `agent.communication.inbox` (from ⇨ self) and DROPS it from `user`.
    let h = Home::new();
    let sess = "11111111-2222-3333-4444-555555555555";
    let lines = [
        r#"{"type":"user","uuid":"u0","sessionId":"11111111-2222-3333-4444-555555555555","cwd":"/Users/x/team","version":"2.1.0","gitBranch":"main","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"the human asks about throughput"}}"#,
        r#"{"type":"assistant","uuid":"a0","parentUuid":"u0","timestamp":"2026-06-07T05:00:05.000Z","message":{"role":"assistant","content":[{"type":"text","text":"ok"}]}}"#,
        r#"{"type":"user","uuid":"tm0","timestamp":"2026-06-07T05:10:00.000Z","message":{"role":"user","content":"Another Claude session sent a message:\n<teammate-message teammate_id=\"VSMultiRegion\" color=\"blue\">\nplease check the rate limit handling\n</teammate-message>"}}"#,
    ];
    h.write(
        &format!("-Users-x-team/{sess}.jsonl"),
        &(lines.join("\n") + "\n"),
    );

    // Under `-t agent.communication.inbox` it surfaces WITH the `from ⇨ to` direction.
    let inbox = h.run(&[
        "search",
        "rate limit",
        "-t",
        "agent.communication.inbox",
        at(sess).as_str(),
        "--no-subagents",
    ]);
    assert!(inbox.success, "stderr: {}", inbox.stderr);
    assert!(
        inbox.stdout.contains("agent.communication.inbox"),
        "teammate message must classify as inbox; got: {}",
        inbox.stdout
    );
    assert!(
        inbox.stdout.contains("VSMultiRegion ⇨"),
        "the comm direction `from ⇨ to` must render; got: {}",
        inbox.stdout
    );

    // Under `-t user` it must NOT appear (the §1 bug fix) - the human turn does, the peer does not.
    let user = h.run(&[
        "search",
        "rate limit",
        "-t",
        "user",
        at(sess).as_str(),
        "--no-subagents",
    ]);
    assert!(user.success, "stderr: {}", user.stderr);
    assert!(
        user.stdout.contains("no matching exchanges"),
        "a teammate message must NOT surface under -t user; got: {}",
        user.stdout
    );
}

#[test]
fn search_redacted_thinking_is_agent_thinking() {
    // #12 / oracle B3 (G7): a `redacted_thinking` block (opaque encrypted reasoning, no readable
    // text) is UNATTESTED in the corpus, so this SYNTHETIC fixture exercises it. It must classify
    // `agent.thinking` and surface under `-t agent.thinking` as a `[redacted thinking]` placeholder
    // (never the opaque `data` blob). The search pattern `redacted` is present BOTH in the raw line
    // (the `redacted_thinking` type) - so the literal prefilter keeps the line - AND in the rendered
    // placeholder, so the regex locates a match on the emitted text.
    let h = Home::new();
    let sess = "abababab-cdcd-efef-0101-232323232323";
    let lines = [
        r#"{"type":"user","uuid":"u0","sessionId":"abababab-cdcd-efef-0101-232323232323","cwd":"/Users/x/redact","version":"2.1.0","gitBranch":"main","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"think hard"}}"#,
        r#"{"type":"assistant","uuid":"a0","parentUuid":"u0","timestamp":"2026-06-07T05:00:05.000Z","message":{"role":"assistant","content":[{"type":"redacted_thinking","data":"EncryptedOpaqueBlob=="},{"type":"text","text":"done"}]}}"#,
    ];
    h.write(
        &format!("-Users-x-redact/{sess}.jsonl"),
        &(lines.join("\n") + "\n"),
    );

    let out = h.run(&[
        "search",
        "redacted",
        "-t",
        "agent.thinking",
        at(sess).as_str(),
        "--no-subagents",
    ]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("agent.thinking"),
        "a redacted_thinking block must classify as agent.thinking; got: {}",
        out.stdout
    );
    assert!(
        out.stdout.contains("[redacted thinking]"),
        "a redacted_thinking block must render the placeholder, not the opaque data; got: {}",
        out.stdout
    );
    assert!(
        !out.stdout.contains("EncryptedOpaqueBlob"),
        "the opaque `data` blob must NOT be surfaced; got: {}",
        out.stdout
    );
}

#[test]
fn search_quoted_tags_mid_prose_stay_user_message() {
    // FINDING-1: a genuine user message that merely QUOTES `<task-notification>` /
    // `<teammate-message>` mid-prose stays `user.message` - it is NOT reclassified
    // `harness.notification` / `agent.communication.inbox` (this bit csift's OWN dev sessions,
    // which quote these tags constantly).
    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":"In csift the <task-notification> pulse and the <teammate-message peer form both route through classify zzquoted."}}"#, "\n",
            r#"{"type":"assistant","uuid":"a0","parentUuid":"u0","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"text","text":"ack"}]}}"#, "\n",
        ),
    );
    // Found under user.message …
    let um = h.run(&[
        "search",
        "zzquoted",
        "-t",
        "user.message",
        &at(SESS),
        "--no-subagents",
    ]);
    assert!(um.success, "stderr: {}", um.stderr);
    assert!(
        um.stdout.contains("user.message"),
        "FINDING-1: quoted tags stay user.message:\n{}",
        um.stdout
    );
    // … and NOT under harness.notification …
    let notif = h.run(&[
        "search",
        "zzquoted",
        "-t",
        "harness.notification",
        &at(SESS),
        "--no-subagents",
    ]);
    assert!(notif.success, "stderr: {}", notif.stderr);
    assert!(
        notif.stdout.contains("no matching exchanges"),
        "FINDING-1: a quoted <task-notification> is not a notification:\n{}",
        notif.stdout
    );
    // … and NOT under agent.communication.inbox.
    let inbox = h.run(&[
        "search",
        "zzquoted",
        "-t",
        "agent.communication.inbox",
        &at(SESS),
        "--no-subagents",
    ]);
    assert!(inbox.success, "stderr: {}", inbox.stderr);
    assert!(
        inbox.stdout.contains("no matching exchanges"),
        "FINDING-1: a quoted <teammate-message> is not inbox:\n{}",
        inbox.stdout
    );
}

#[test]
fn acceptance_compaction_summary_and_boundary_searchable() {
    // §D6 the isCompactSummary record is a `type:"user"` record → searchable as
    // `harness.compaction.summary`. §D7 (user-reversed): the `compact_boundary` is a `type:"system"`
    // record NOW ALSO search-surfaced - the §7 prefilter keeps it (one memmem on `compact_boundary`)
    // and `record_raw_text` renders its top-level content + compactMetadata as the match/excerpt, so
    // compaction points can be enumerated + inspected.
    let h = acceptance_home();

    let summary = acc(&h, "zzsummary", "harness.compaction.summary");
    assert!(summary.success, "D6: stderr {}", summary.stderr);
    assert!(
        summary.stdout.contains("harness.compaction.summary"),
        "D6 compaction summary → searchable:\n{}",
        summary.stdout
    );

    let boundary = acc(&h, "zzboundary", "harness.compaction.boundary");
    assert!(boundary.success, "D7: stderr {}", boundary.stderr);
    assert!(
        boundary.stdout.contains("harness.compaction.boundary"),
        "D7 compact_boundary → now searchable:\n{}",
        boundary.stdout
    );
    // The compactMetadata renders as the excerpt (trigger / pre/post tokens / duration).
    assert!(
        boundary.stdout.contains("trigger") && boundary.stdout.contains("auto"),
        "D7 boundary excerpt carries its compactMetadata:\n{}",
        boundary.stdout
    );
}

#[test]
fn acceptance_excluded_and_unmarked_meta_carry_no_label() {
    // §E an `attachment` carries no label; §J an isMeta record matching no harness marker is EXCLUDED
    // (never `user.message`). Neither surfaces under ANY selector.
    let h = acceptance_home();
    for (oracle, token) in [
        ("E attachment", "zzattach"),
        ("J isMeta-unmarked", "zzunmarked"),
    ] {
        // No `-t` → every label eligible; still nothing, because classify returns empty.
        let out = h.run(&["search", token, &at(ACC_SESS), "--no-subagents"]);
        assert!(out.success, "{oracle}: stderr {}", out.stderr);
        assert!(
            out.stdout.contains("no matching exchanges"),
            "{oracle} must carry no label (no hit):\n{}",
            out.stdout
        );
    }
}

#[test]
fn harness_role_excludes_the_boundary_and_the_drilldown_keeps_it() {
    let h = Home::new();
    h.write(
        &format!("{ENC}/{SESS}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u1","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"go"}}"#, "\n",
            r#"{"type":"system","subtype":"compact_boundary","uuid":"cb1","timestamp":"2026-06-07T05:01:00.000Z","content":"Compacted","compactMetadata":{"trigger":"auto","preTokens":900,"postTokens":90,"durationMs":4}}"#, "\n",
        ),
    );
    // The bare role: the metrics-only boundary is not the conversation.
    let role = h.run(&["search", "", &at(SESS), "-t", "harness"]);
    assert!(
        !role.stdout.contains("compaction boundary"),
        "-t harness excludes the boundary:\n{}",
        role.stdout
    );
    // The deliberate drill-down keeps its full set - compaction points stay findable.
    let drill = h.run(&["search", "", &at(SESS), "-t", "harness.compaction"]);
    assert!(
        drill.stdout.contains("trigger=auto"),
        "-t harness.compaction still reaches the boundary:\n{}",
        drill.stdout
    );
    // And the glob reaches everything too.
    let glob = h.run(&["search", "", &at(SESS), "-t", "harness.*"]);
    assert!(glob.stdout.contains("trigger=auto"), "{}", glob.stdout);
}

#[test]
fn a_freeform_askuserquestion_response_is_a_user_answer() {
    // A carrier whose toolUseResult carries `response` and an empty `answers` map (the
    // harness's `The user responded:` branch) is a user.answer hit rendering the
    // response, and the marker text is prefilter-safe under the whole-file gate.
    let h = Home::new();
    let enc = "-Users-dev-example-project";
    let sess = "45454545-5656-4767-8878-989898989898";
    h.write(
        &format!("{enc}/{sess}.jsonl"),
        concat!(
            r#"{"type":"user","uuid":"u1","timestamp":"2026-06-07T05:00:00.000Z","message":{"role":"user","content":"pick a route"}}"#, "\n",
            r#"{"type":"assistant","uuid":"a1","parentUuid":"u1","timestamp":"2026-06-07T05:00:01.000Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"ask1","name":"AskUserQuestion","input":{"questions":[{"question":"Which harbor?","header":"Harbor","options":[{"label":"north","description":"a"},{"label":"south","description":"b"}],"multiSelect":false}]}}]}}"#, "\n",
            r#"{"type":"user","uuid":"r1","parentUuid":"a1","timestamp":"2026-06-07T05:00:03.000Z","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"ask1","content":"The user responded: skip the harbor, go by land"}]},"toolUseResult":{"questions":[{"question":"Which harbor?","header":"Harbor","options":[{"label":"north","description":"a"},{"label":"south","description":"b"}],"multiSelect":false}],"answers":{},"response":"skip the harbor, go by land"}}"#, "\n",
            r#"{"type":"assistant","uuid":"a2","parentUuid":"r1","timestamp":"2026-06-07T05:00:05.000Z","message":{"role":"assistant","content":[{"type":"text","text":"by land it is"}]}}"#, "\n",
        ),
    );
    let out = h.run(&["search", "go by land", &at(sess), "-t", "user.answer"]);
    assert!(out.success, "stderr: {}", out.stderr);
    assert!(
        out.stdout.contains("user.answer")
            && out.stdout.contains("response: skip the harbor, go by land"),
        "{}",
        out.stdout
    );
    let count = h.run(&["search", "", &at(sess), "-t", "user.answer", "-c"]);
    assert_eq!(count.stdout.trim(), "1", "{}", count.stdout);
    // The synthesized head alone (never a raw substring of the line beyond the marker)
    // still matches: the marker is a verifiable synth needle.
    let head = h.run(&["search", "AskUserQuestion · 1 question", &at(sess), "-c"]);
    assert_eq!(head.stdout.trim(), "1", "{}", head.stdout);
}