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
//! Shared helper for `defect-cli` examples. **For `examples/` only** — not part of the
//! crate's public API (`defect-cli` is a binary crate with no lib target).
//!
//! Difference from [`crates/llm/examples/common/mod.rs`]: this module is ACP-oriented —
//! - subscriber always uses `with_writer(std::io::stderr)` (stdout is reserved for wire)
//! - default `EnvFilter` silences toac's `INFO request` events (which contain
//! authorization header in plain text; see tracing design)
//!
//! See tracing design.
use IsTerminal;
use Path;
/// Set up tracing: defaults to `info,toac=warn`, overridden entirely by the `RUST_LOG`
/// environment variable.
///
/// `toac=warn` is part of the default directive — the toac wire crate emits request
/// events at `info` level with `headers={"authorization": "Bearer ..."}`, so they must be
/// silenced by default to avoid leaking credentials to stderr. To inspect wire requests,
/// explicitly set `RUST_LOG=...,toac=debug` (debug level does not include headers).
///
/// **stderr is mandatory**: the stdio ACP occupies stdout; writing to stdout from the
/// subscriber would corrupt the protocol wire, causing client decode failures.
///
/// # Panics
///
/// Re-initialization panics — examples call this only once in `main`.
/// A minimal `.env` loader: one `KEY=VALUE` per line, lines starting with `#` are
/// comments, blank lines are skipped; outer `"..."` / `'...'` quotes are stripped.
/// **Variables already set in the process environment are preserved**, so `.env` cannot
/// override a shell-exported variable. Missing file or parse errors only produce a
/// warning.
///
/// This is the same implementation as `crates/cli/src/main.rs::load_env_file` — examples
/// cannot reference private functions from the binary crate, so this is a copy.