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
//! Storage-path derivation for the workstream store (DOC-48 §3.1).
//!
//! Why: the spec pins the filename shape (`workstreams-{project_slug}-{hash}.json`)
//! to the daemon's OWN [`ProjectBinding`] — never a caller-supplied label —
//! so two daemons bound to the same project always agree on one file, and
//! two different projects (even same-named checkouts) never collide.
//! What: [`store_filename`] derives the filesystem-safe slug + a truncated
//! SHA-256 fingerprint of the canonical root from a [`ProjectBinding`];
//! [`store_path`] joins it under a data directory; [`default_data_dir`]
//! resolves `~/.trusty-code` (mirrors trusty-mpm's `~/.trusty-mpm`
//! precedent, `crates/trusty-mpm/src/core/paths.rs`).
//! Test: `path_tests`.
use ;
use ;
use crateProjectBinding;
/// Number of hex characters kept from the SHA-256 digest (§3.1: "truncated
/// to 8 chars").
const HASH_LEN: usize = 8;
/// Fixed filename used when the daemon is projectless (`ProjectBinding::None`).
///
/// Why: DOC-48 §2.3/§3.1 only specify the filename shape for a BOUND
/// project; a projectless daemon has no path to slug or hash. Rather than
/// fabricate a fake root, this ticket resolves the ambiguity with one fixed,
/// documented filename — a projectless daemon has at most one workstream
/// store regardless of which directory `tcode serve` happened to start in.
const PROJECTLESS_FILENAME: &str = "workstreams-projectless.json";
/// Resolve `~/.trusty-code`, the trusty-code data directory.
///
/// Why: mirrors `trusty-mpm`'s `~/.trusty-mpm` precedent
/// (`crates/trusty-mpm/src/core/paths.rs`) rather than inventing a new
/// resolution convention.
/// What: `dirs::home_dir()/.trusty-code`, falling back to a relative
/// `.trusty-code` if the home directory cannot be resolved (never panics).
/// Test: `path_tests::default_data_dir_is_dot_trusty_code`.
/// Turn an arbitrary string into a filesystem-safe, lowercase, hyphenated
/// slug.
///
/// Why: a project's directory basename may contain characters unsafe for a
/// filename component (spaces, underscores, mixed case); the slug must be
/// stable and readable.
/// What: keeps ASCII alphanumerics (lowercased), collapses any run of other
/// characters into a single `-`, and trims leading/trailing `-`. An
/// all-non-alphanumeric input slugs to `"project"` rather than an empty
/// string.
/// Test: `path_tests::slugify_*`.
/// Deterministic 8-hex-char fingerprint of a project root path.
///
/// Why: disambiguates multiple checkouts that share a directory basename
/// (§3.1: "to handle multiple checkouts of the same project").
/// What: SHA-256 of the path's platform string, truncated to
/// [`HASH_LEN`] lowercase hex characters. Deterministic for a given path,
/// unlike a per-process `RandomState`-seeded hasher.
/// Test: `path_tests::project_hash_is_deterministic`,
/// `path_tests::project_hash_differs_for_different_paths`.
/// Derive the workstream store's filename from a daemon's project binding
/// (DOC-48 §3.1).
///
/// Why: the ONE place the filename shape is assembled, so the store and any
/// future inspection tooling can never disagree on it.
/// What: for a bound project, `workstreams-{slug}-{hash}.json` where `slug`
/// comes from the root's basename and `hash` fingerprints the full root
/// path (§3.1). For [`ProjectBinding::None`], the fixed
/// [`PROJECTLESS_FILENAME`] (see its docs for why).
/// Test: `path_tests::store_filename_for_bound_project`,
/// `path_tests::store_filename_for_projectless`.
/// Join [`store_filename`] under a data directory to get the full store path.
///
/// Why: the single entry point `WorkstreamStore::load_for_binding` (and any
/// future daemon boot code) calls to resolve where the store file lives.
/// What: `data_dir.join(store_filename(binding))`.
/// Test: `path_tests::store_path_joins_data_dir_and_filename`.