theway-daemon 0.1.25

theway daemon — the single agent-runtime kernel (bin `thewayd`): harness assembly, local/sandbox tool policy, triggers/cron/session/DAG runtime, skills, MCP/LSP wiring, serving the gRPC/HTTP/MCP transports from theway-transport. Terminal UI lives in the theway-tui crate.
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
//! Session lifecycle commands: `/save`, `/undo`, `/name`, `/session`, `/share`.
//! (`/sessions`, `/login`, `/logout` are daemon runtime commands in [`super::auth`].)

use super::*;

use theway_transport::commands::CommandCtx;

pub struct SaveCommand;

#[async_trait]
impl SlashCommand<DaemonCtx> for SaveCommand {
    fn name(&self) -> &'static str {
        "save"
    }
    fn description(&self) -> &'static str {
        "export session transcript to Markdown"
    }
    fn usage(&self) -> &'static str {
        "[path]"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let dest = if let Some(path) = argv.first() {
            std::path::PathBuf::from(path)
        } else {
            crate::export::default_export_path(ctx.session_id)
        };
        // If the path is relative, resolve against cwd so /save foo.md lands where the user
        // expects (and not in some random working dir).
        let dest = if dest.is_absolute() {
            dest
        } else {
            ctx.cwd.join(dest)
        };
        match crate::export::save(ctx.extra.harness.session(), &dest).await {
            Ok(p) => {
                cprintln!("saved transcript: {}", p.display());
                CommandOutcome::Handled
            }
            Err(e) => CommandOutcome::Error(format!("save failed: {e}")),
        }
    }
}

pub struct UndoCommand;

#[async_trait]
impl SlashCommand<DaemonCtx> for UndoCommand {
    fn name(&self) -> &'static str {
        "undo"
    }
    fn description(&self) -> &'static str {
        "remove the most recent user+assistant turn from the active branch"
    }
    async fn run(&self, _argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let session = ctx.extra.harness.session();
        let path = match session.branch(None).await {
            Ok(p) => p,
            Err(e) => return CommandOutcome::Error(format!("read branch: {e}")),
        };
        // Walk backwards for the most recent Message that's a User. That message is the
        // start of the turn we want to drop.
        let mut target_parent: Option<String> = None;
        let mut found = false;
        for entry in path.iter().rev() {
            if let theway_core::SessionTreeEntry::Message {
                message: theway_core::AgentMessage::Llm(theway_llm_provider::Message::User(_)),
                parent_id,
                ..
            } = entry
            {
                target_parent = parent_id.clone();
                found = true;
                break;
            }
        }
        if !found {
            return CommandOutcome::Error("no user message to undo".into());
        }
        match ctx
            .extra
            .harness
            .move_to(target_parent.as_deref(), None)
            .await
        {
            Ok(_) => {
                cprintln!("undid last turn");
                CommandOutcome::Handled
            }
            Err(e) => CommandOutcome::Error(format!("undo failed: {e}")),
        }
    }
}

pub struct NameCommand;

#[async_trait]
impl SlashCommand<DaemonCtx> for NameCommand {
    fn name(&self) -> &'static str {
        "name"
    }
    fn description(&self) -> &'static str {
        "show or set the current session's name"
    }
    fn usage(&self) -> &'static str {
        "[slug]"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let session = ctx.extra.harness.session();
        if argv.is_empty() {
            match session.session_name().await {
                Ok(Some(n)) => cprintln!("session name: {n}"),
                Ok(None) => cprintln!("(unnamed session)"),
                Err(e) => return CommandOutcome::Error(format!("read name: {e}")),
            }
            return CommandOutcome::Handled;
        }
        let name = argv.join(" ");
        let trimmed = name.trim();
        if trimmed.is_empty() {
            return CommandOutcome::Error("empty name".into());
        }
        match session.append_session_name(trimmed.to_string()).await {
            Ok(_) => {
                cprintln!("session name set to: {trimmed}");
                CommandOutcome::Handled
            }
            Err(e) => CommandOutcome::Error(format!("set name failed: {e}")),
        }
    }
}

pub struct SessionCommand;

#[async_trait]
impl SlashCommand<DaemonCtx> for SessionCommand {
    fn name(&self) -> &'static str {
        "session"
    }
    fn description(&self) -> &'static str {
        "export/import replayable .theway-session backups"
    }
    fn usage(&self) -> &'static str {
        "export [path] [--exclude-triggers] | import <path>"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        match argv.first().map(String::as_str) {
            Some("export") => session_export_command(&argv[1..], ctx).await,
            Some("import") => session_import_command(&argv[1..], ctx).await,
            Some(other) => CommandOutcome::Error(format!(
                "unknown /session subcommand: {other}; use /session export [path] or /session import <path>"
            )),
            None => CommandOutcome::Error(
                "usage: /session export [path] [--exclude-triggers] | /session import <path>"
                    .into(),
            ),
        }
    }
}

async fn session_export_command(
    argv: &[String],
    ctx: &CommandCtx<'_, DaemonCtx>,
) -> CommandOutcome {
    let mut exclude_triggers = false;
    let mut path_arg: Option<&str> = None;
    for arg in argv {
        if arg == "--exclude-triggers" {
            exclude_triggers = true;
        } else if path_arg.is_none() {
            path_arg = Some(arg);
        } else {
            return CommandOutcome::Error(
                "usage: /session export [path] [--exclude-triggers]".into(),
            );
        }
    }

    let output_path = match path_arg {
        Some(path) => std::path::PathBuf::from(path),
        None => theway_storage::session_archive::default_export_path(ctx.cwd, ctx.session_id),
    };
    let output_path = if output_path.is_absolute() {
        output_path
    } else {
        ctx.cwd.join(output_path)
    };

    emit_session_archive_warning();
    match theway_storage::session_archive::export_session(
        ctx.extra.harness.session(),
        &output_path,
        exclude_triggers,
    )
    .await
    {
        Ok(summary) => {
            cprintln!(
                "exported session archive: {}",
                summary.output_path.display()
            );
            cprintln!(
                "session {} entries={} triggers={} cron={}",
                short_id(&summary.session_id),
                summary.entry_count,
                yes_no(summary.has_triggers),
                yes_no(summary.has_cron)
            );
            CommandOutcome::Handled
        }
        Err(err) => CommandOutcome::Error(format!("session export failed: {err}")),
    }
}

async fn session_import_command(
    argv: &[String],
    ctx: &CommandCtx<'_, DaemonCtx>,
) -> CommandOutcome {
    if argv.len() != 1 {
        return CommandOutcome::Error("usage: /session import <path>".into());
    }
    let archive_path = std::path::PathBuf::from(&argv[0]);
    let archive_path = if archive_path.is_absolute() {
        archive_path
    } else {
        ctx.cwd.join(archive_path)
    };
    let repo = match ctx.extra.storage.session_repository(ctx.cwd).await {
        Ok(repo) => repo,
        Err(e) => return CommandOutcome::Error(format!("open session repo: {e}")),
    };

    emit_session_archive_warning();
    match repo.import(&archive_path, ctx.cwd).await {
        Ok(summary) => {
            cprintln!("imported session: {}", short_id(&summary.session_id));
            cprintln!("path: {}", summary.session_path.display());
            cprintln!(
                "entries={} triggers={} cron={} automation={}",
                summary.entry_count,
                summary.triggers_imported,
                summary.cron_imported,
                if summary.automation_enabled {
                    "enabled"
                } else {
                    "disabled"
                }
            );
            cprintln!("resume with: theway --resume-id {}", summary.session_id);
            if !summary.originally_enabled_triggers.is_empty()
                || !summary.originally_enabled_cron.is_empty()
            {
                return CommandOutcome::SessionImportActivation {
                    session_path: summary.session_path,
                    trigger_ids: summary.originally_enabled_triggers,
                    cron_ids: summary.originally_enabled_cron,
                };
            }
            CommandOutcome::Handled
        }
        Err(err) => CommandOutcome::Error(format!("session import failed: {err}")),
    }
}

fn emit_session_archive_warning() {
    cprintln!(
        "warning: .theway-session archives include transcript and tool history. They do not include separate auth stores, provider credentials, OAuth tokens, or MCP config."
    );
}

fn short_id(id: &str) -> String {
    id.chars().take(16).collect()
}

/// `/fork` — pi-style session forking: create a new session file that replays the
/// transcript up to (not including) a chosen previous user message.
///
/// Without args it lists the session's user messages newest-first with index
/// numbers; `/fork <n>` forks before the n-th one (1 = most recent). The new
/// session records its parent via `parentSessionPath`, which the `/sessions` and
/// `/resume` tree displays use to nest it under its parent.
pub struct ForkCommand;

#[async_trait]
impl SlashCommand<DaemonCtx> for ForkCommand {
    fn name(&self) -> &'static str {
        "fork"
    }
    fn description(&self) -> &'static str {
        "fork a new session from a previous user message (pi-style session tree)"
    }
    fn usage(&self) -> &'static str {
        "[n]"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let session = ctx.extra.harness.session();
        let entries = match session.storage().get_entries().await {
            Ok(e) => e,
            Err(e) => return CommandOutcome::Error(format!("read session: {e}")),
        };
        // User messages, newest first.
        let users: Vec<(String, String)> = entries
            .iter()
            .rev()
            .filter_map(|e| {
                let theway_core::SessionTreeEntry::Message { id, .. } = e else {
                    return None;
                };
                theway_core::encode_session_entry(e).ok().and_then(|entry| {
                    theway_storage::session::user_message_text(&entry)
                        .map(|preview| (id.clone(), preview))
                })
            })
            .collect();
        if users.is_empty() {
            return CommandOutcome::Error("no user messages to fork from".into());
        }

        let Some(arg) = argv.first() else {
            cprintln!("user messages (newest first):");
            for (i, (_, preview)) in users.iter().enumerate() {
                let p = if preview.chars().count() > 60 {
                    let mut p: String = preview.chars().take(60).collect();
                    p.push('');
                    p
                } else {
                    preview.clone()
                };
                cprintln!("  {}) {p}", i + 1);
            }
            cprintln!(
                "fork before message N with /fork <N> — the new session replays everything before it"
            );
            return CommandOutcome::Handled;
        };

        let n: usize = match arg.parse() {
            Ok(n) if n >= 1 && n <= users.len() => n,
            _ => {
                return CommandOutcome::Error(format!(
                    "fork index must be 1..={} (run /fork to list messages)",
                    users.len()
                ));
            }
        };
        let (target_id, _) = &users[n - 1];
        let options = theway_core::ForkOptions {
            entry_id: Some(target_id.clone()),
            position: theway_core::ForkPosition::Before,
        };
        let to_fork =
            match theway_core::get_entries_to_fork(session.storage().as_ref(), options).await {
                Ok(v) => v,
                Err(e) => return CommandOutcome::Error(format!("fork failed: {e}")),
            };

        let repo = match ctx.extra.storage.session_repository(ctx.cwd).await {
            Ok(repo) => repo,
            Err(e) => return CommandOutcome::Error(format!("open session repo: {e}")),
        };
        let to_fork = match to_fork
            .iter()
            .map(theway_core::encode_session_entry)
            .collect::<Result<Vec<_>, _>>()
        {
            Ok(entries) => entries,
            Err(e) => return CommandOutcome::Error(format!("fork failed: {e}")),
        };
        if let Err(error) = ctx.extra.harness.before_session_fork(Some(target_id)).await {
            return CommandOutcome::Error(format!("fork cancelled: {error}"));
        }
        match repo.fork(ctx.cwd, session, to_fork).await {
            Ok(new) => {
                let meta = match new.get_metadata_json().await {
                    Ok(m) => m,
                    Err(e) => {
                        return CommandOutcome::Error(format!("fork created but unreadable: {e}"));
                    }
                };
                let new_id = meta.get("id").and_then(|v| v.as_str()).unwrap_or("?");
                ctx.extra.harness.session_forked(new_id).await;
                // Issue #55: the success line is TUI-first — the full new id
                // plus a `/session switch <short>` hint to continue there; the
                // CLI resume hint stays on its own line. Forking never
                // auto-switches (pi semantics).
                cprintln!("{}", fork_success_line(new_id));
                cprintln!("resume with: theway --resume-id {}", new_id);
                CommandOutcome::Handled
            }
            Err(e) => CommandOutcome::Error(format!("fork failed: {e}")),
        }
    }
}

/// Success line for `/fork <n>` (issue #55): `forked session {full id} —
/// /session switch {short} to continue there`. The full id is what the TUI's
/// feed shows; the short prefix is enough for `/session switch`. The CLI
/// resume hint prints separately.
fn fork_success_line(new_id: &str) -> String {
    format!(
        "forked session {new_id} — /session switch {} to continue there",
        short_id(new_id)
    )
}

/// `/collapse` — collapse the current session into a session-graph node and
/// create a fresh child session with compact context.
///
/// Issue #94: when no prior summary exists and the session is idle, the
/// collapse first asks the current model to summarize the session (through
/// the harness compaction path, so custom algorithms / observability /
/// budget retries all apply). The summarizer is instructed to emit the five
/// rolling components, which the child then carries as its bounded rolling
/// summary. Busy sessions, missing models, and provider failures degrade to
/// the deterministic transcript rolling fallback.
pub struct CollapseCommand;

/// Instruction appended to the compaction summarizer prompt so the result
/// parses as the five rolling components of [`render_rolling_summary`].
const COLLAPSE_SUMMARY_INSTRUCTION: &str = "This summary will become the new session's entire memory of this conversation (a session collapse). Output exactly the following five labeled sections, one section per line, each a single concise paragraph, and nothing else:\n\
goal: <one sentence — what this session set out to achieve>\n\
completed work: <what was done and what changed>\n\
key decisions: <decisions made and why>\n\
next steps: <what remains to do>\n\
critical context: <facts and constraints the next session must not lose>";

#[async_trait]
impl SlashCommand<DaemonCtx> for CollapseCommand {
    fn name(&self) -> &'static str {
        "collapse"
    }
    fn description(&self) -> &'static str {
        "collapse the current session into a session-graph node and create a fresh child"
    }
    fn usage(&self) -> &'static str {
        "[name] [--adopt]"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let mut adopt = false;
        let mut name = None;
        for arg in argv {
            if arg == "--adopt" {
                adopt = true;
            } else if name.is_none() {
                name = Some(arg.clone());
            } else {
                return CommandOutcome::Error("usage: /collapse [name] [--adopt]".to_string());
            }
        }

        let repo = match ctx.extra.storage.session_repository(ctx.cwd).await {
            Ok(repo) => repo,
            Err(e) => return CommandOutcome::Error(format!("open session repo: {e}")),
        };

        // Resolve the collapse summary first (issue #94): reuse the newest
        // existing summary; otherwise summarize with the current model when
        // the session is idle. Busy sessions skip the summarizer so it cannot
        // race the live turn — the ops layer then falls back to the
        // deterministic transcript rolling summary.
        let mut summarized = false;
        let summary = match repo.open(ctx.session_id).await {
            Ok(Some(store)) => {
                let source = theway_core::Session::from_store(store);
                let existing = match source.latest_collapse_summary().await {
                    Ok(Some(summary)) if !summary.trim().is_empty() => Some(summary),
                    _ => None,
                };
                match existing {
                    Some(summary) => Some(summary),
                    None if ctx.extra.harness.agent().is_streaming() => {
                        cprintln!(
                            "collapse during a busy turn: LLM summarization skipped; \
                             rolling transcript fallback used"
                        );
                        None
                    }
                    None => {
                        let instruction = COLLAPSE_SUMMARY_INSTRUCTION.to_string();
                        match ctx
                            .extra
                            .harness
                            .summarize_for_collapse(Some(instruction))
                            .await
                        {
                            Ok(Some(summary)) => {
                                summarized = true;
                                Some(summary)
                            }
                            Ok(None) => None,
                            Err(e) => {
                                cprintln!(
                                    "summarize before collapse failed: {e}; \
                                     rolling transcript fallback used"
                                );
                                None
                            }
                        }
                    }
                }
            }
            Ok(None) => {
                return CommandOutcome::Error(format!("no session matches id {}", ctx.session_id));
            }
            Err(e) => return CommandOutcome::Error(format!("open session: {e}")),
        };
        let response = match theway_daemon::session_ops::collapse_session_for_command(
            repo,
            ctx.cwd,
            ctx.session_id,
            name,
            adopt,
            summary,
        )
        .await
        {
            Ok(response) => response,
            Err(e) => return CommandOutcome::Error(format!("collapse failed: {e}")),
        };
        let child_id = response
            .collapsed
            .as_ref()
            .and_then(|c| c.collapsed_into_session_id.clone())
            .unwrap_or_default();
        let node_id = response
            .node
            .as_ref()
            .map(|n| n.id.clone())
            .unwrap_or_default();
        // Issue #100: carry the source session's model + thinking level over
        // to the child. The model is daemon-memory per-session state — the
        // child runtime would otherwise have none and the first DAG launch /
        // delegation in it would fail with "no model set for this session".
        if !child_id.is_empty() {
            let state = ctx.extra.harness.agent().state();
            if let Some(model) = &state.model {
                let model_spec = format!("{}:{}", model.provider.0, model.id);
                let thinking_level = state.thinking_level.map(|level| level.as_str().to_string());
                if let Ok(mut slot) = ctx.extra.inherit_slot.lock() {
                    *slot = Some(crate::commands::InheritedSessionSettings {
                        session_id: child_id.clone(),
                        model_spec,
                        thinking_level,
                    });
                }
            }
        }
        cprintln!(
            "collapsed {} into node {} (child session {})",
            ctx.session_id,
            node_id,
            child_id
        );
        if summarized {
            cprintln!("summarized with the current model before collapsing");
        }
        if adopt {
            cprintln!("--adopt: ownership migration requested");
        }
        cprintln!("resume with: theway --resume-id {}", child_id);
        // Memory unload: release the collapsed source session's runtime so
        // only its persisted record remains. The host consumes the slot right
        // after dispatch (the command layer has no &mut TurnHost); `note`
        // carries the confirmation because the source feed is dropped with
        // its runtime.
        if !child_id.is_empty() {
            let note = format!(
                "collapsed {source} into node {node} — active session switched to child \
                 {child} (source runtime unloaded)",
                source = ctx.session_id,
                node = node_id,
                child = child_id,
            );
            if let Ok(mut slot) = ctx.extra.collapse_unload_slot.lock() {
                *slot = Some(crate::commands::CollapseUnloadRequest {
                    source_id: ctx.session_id.to_string(),
                    child_id,
                    note,
                });
            }
        }
        CommandOutcome::Handled
    }
}

fn yes_no(value: bool) -> &'static str {
    if value { "yes" } else { "no" }
}

pub struct ShareCommand;

/// The `gh` binary to use for `/share`. Defaults to `gh` on PATH; `THEWAY_GH_BIN`
/// overrides it (gh installed outside PATH, or a test shim).
fn gh_bin() -> String {
    std::env::var("THEWAY_GH_BIN").unwrap_or_else(|_| "gh".to_string())
}

#[async_trait]
impl SlashCommand<DaemonCtx> for ShareCommand {
    fn name(&self) -> &'static str {
        "share"
    }
    fn description(&self) -> &'static str {
        "upload transcript as a private Gist via gh (requires `gh` on PATH)"
    }
    fn usage(&self) -> &'static str {
        "[--public]"
    }
    async fn run(&self, argv: &[String], ctx: &CommandCtx<'_, DaemonCtx>) -> CommandOutcome {
        let public = argv.iter().any(|a| a == "--public");

        // Render and write to a temp file so gh gist create can ingest it.
        let dir = std::env::temp_dir().join(format!("theway-share-{}", ctx.session_id));
        if let Err(e) = tokio::fs::create_dir_all(&dir).await {
            return CommandOutcome::Error(format!("share tmp dir: {e}"));
        }
        let file = dir.join("transcript.md");
        if let Err(e) = crate::export::save(ctx.extra.harness.session(), &file).await {
            return CommandOutcome::Error(format!("save transcript: {e}"));
        }

        let mut cmd = tokio::process::Command::new(gh_bin());
        cmd.current_dir(ctx.cwd);
        cmd.arg("gist").arg("create");
        if public {
            cmd.arg("--public");
        }
        cmd.arg("--desc")
            .arg(format!("theway session {}", ctx.session_id))
            .arg(file.as_os_str());

        let output = match cmd.output().await {
            Ok(o) => o,
            Err(e) => {
                return CommandOutcome::Error(format!(
                    "gh gist create failed to spawn: {e}. Is gh on PATH?"
                ));
            }
        };
        if !output.status.success() {
            return CommandOutcome::Error(format!(
                "gh gist create exited {}: {}",
                output.status.code().unwrap_or(-1),
                String::from_utf8_lossy(&output.stderr).trim()
            ));
        }
        let url = String::from_utf8_lossy(&output.stdout).trim().to_string();
        cprintln!("shared: {url}");
        CommandOutcome::Handled
    }
}

#[cfg(test)]
mod tests {
    use super::fork_success_line;

    #[test]
    fn fork_success_line_uses_full_id_and_short_switch_hint() {
        // Act
        let line = fork_success_line("0123456789abcdef-0123456789abcdef");

        // Assert: full id first, short id (16 chars) in the switch hint.
        assert_eq!(
            line,
            "forked session 0123456789abcdef-0123456789abcdef — /session switch 0123456789abcdef to continue there"
        );
    }
}

#[cfg(test)]
mod commands_session_tests {
    #[allow(unused_imports)]
    use super::*;
    tests_bridge_macro::tests_bridge!("commands/session");
}

#[cfg(test)]
mod commands_session_line_coverage_tests {
    #[allow(unused_imports)]
    use super::*;
    tests_bridge_macro::tests_bridge!("commands/session/line_coverage");
}