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
//! Typed handle for a clash session directory.
//!
//! Centralizes the session directory layout so that path construction
//! lives in one place instead of being scattered across audit, trace,
//! settings, and session_policy modules.
use std::path::{Path, PathBuf};
/// A session directory rooted at `<tmp>/clash-<session_id>/`.
///
/// Every session-scoped file (stats, audit log, trace, policy) is
/// accessed through this struct, making the directory layout explicit
/// and easy to change in one place.
#[derive(Debug, Clone)]
pub struct SessionDir {
root: PathBuf,
}
impl SessionDir {
/// Build the session directory path for the given session ID.
pub fn new(session_id: &str) -> Self {
Self {
root: std::env::temp_dir().join(format!("clash-{session_id}")),
}
}
/// The root directory path.
pub fn root(&self) -> &Path {
&self.root
}
/// `stats.json` — per-session decision counters.
pub fn stats(&self) -> PathBuf {
self.root.join("stats.json")
}
/// `audit.jsonl` — per-session audit log.
pub fn audit_log(&self) -> PathBuf {
self.root.join("audit.jsonl")
}
/// `trace.json` — session trace metadata + incremental state.
pub fn trace_meta(&self) -> PathBuf {
self.root.join("trace.json")
}
/// `trace.jsonl` — append-only toolpath steps.
pub fn trace_steps(&self) -> PathBuf {
self.root.join("trace.jsonl")
}
/// `policy.star` — session-level policy overrides.
pub fn policy(&self) -> PathBuf {
self.root.join("policy.star")
}
/// `metadata.json` — session metadata written at init.
pub fn metadata(&self) -> PathBuf {
self.root.join("metadata.json")
}
/// `pending/` — directory for pending session policy proposals.
pub fn pending_dir(&self) -> PathBuf {
self.root.join("pending")
}
}