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
//! DOC-28 catch-up context injection for the PM prompt (#1762, PR2).
//!
//! Why: When a PM agent starts a task, it has no intrinsic knowledge of recent
//! project activity — paused sessions, new git commits, or recent memory palace
//! entries. Injecting a catch-up digest as seed `fallback_guidance` in the PM
//! system prompt gives it the context to orient quickly, mirroring the behaviour
//! the trusty-mpm harness provides via `session_launch`.
//! What: [`pm_catchup_context`] builds a [`CatchupOptions`] for the project and
//! calls the shared engine in trusty-common, returning `Some(digest)` when
//! meaningful content was produced or `None` to indicate the assembler should
//! skip this section entirely.
//! Test: `catchup::tests::pm_catchup_context_does_not_panic_on_empty_repo`.
//!
//! [`pm_catchup_context`]: crate::catchup::pm_catchup_context
//! [`CatchupOptions`]: trusty_common::catchup::CatchupOptions
use Path;
use debug;
use ;
/// Build PM-prompt catch-up seed context for the given project directory.
///
/// Why: the PM prompt benefits from a one-time digest of what happened in the
/// project since the last session — paused work, recent commits, recent memory
/// palace entries — so it can orient immediately without asking the operator.
/// This is injected as `fallback_guidance` (the last section of the assembled
/// prompt) and is only wired into the PM agent path; sub-agents receive `None`
/// because they operate under the PM's direction and do not need the high-level
/// activity digest.
///
/// **Watermark is NOT advanced** (`advance_watermark = false`). trusty-code is
/// a read-only consumer of the catch-up state: watermark advancement is owned by
/// trusty-mpm's `session_launch` hook, which controls the canonical boundary
/// between sessions. Advancing from trusty-code would skew that boundary and
/// cause cross-harness interference where activity is silently dropped from the
/// next mpm session's digest.
///
/// Fail-open: any error or empty/whitespace result returns `None` rather than
/// propagating, so prompt assembly always succeeds even when the daemon is
/// offline or the project has no git history.
///
/// What: resolves `memory_socket` via
/// [`crate::session::memory_sink::resolve_recorder_socket`] (env override
/// `TRUSTY_MEMORY_SOCKET` first, else the derived socket path,
/// else a fail-fast placeholder — issue #2030; never the live daemon from a
/// test process — #9139), then delegates to
/// [`pm_catchup_context_with_socket`].
/// Test: `catchup::tests::pm_catchup_context_does_not_panic_on_empty_repo`.
pub async
/// Same as [`pm_catchup_context`], but with the trusty-memory base URL passed
/// in explicitly rather than resolved from the process-wide `TRUSTY_MEMORY_SOCKET`
/// env var (issue #3003).
///
/// Why: [`pm_catchup_context`]'s tests need a guaranteed-unreachable dial
/// target so the fail-open path is exercised deterministically. The previous
/// approach mutated the process-global `TRUSTY_MEMORY_SOCKET` env var via
/// `unsafe { std::env::set_var(..) }` with no cleanup and no cross-test lock —
/// `cargo test`'s default parallelism runs every test in this crate's lib
/// binary as threads of ONE process, so that leaked env value was observable
/// by any concurrently-running test whose code path also calls
/// [`trusty_common::memory_rpc::resolve_memory_socket_or_unreachable`]
/// (e.g. `run_task::tests::*`, via `execute_run_task` -> `pm_catchup_context`),
/// producing false-red flakes unrelated to the leaking test itself. Threading
/// `memory_socket` through as a parameter — the same pattern
/// [`crate::session::memory_sink::TurnMemorySink::with_capacity`] already uses
/// for the identical reason — removes the shared mutable global entirely, so
/// tests need no lock and no cleanup.
/// What: builds `CatchupOptions` with `memory_socket` and sane limits, calls
/// `run_catchup` with `advance_watermark = false`, and returns `Some(digest)`
/// when the result is non-whitespace, else `None`.
/// Test: `catchup::tests::pm_catchup_context_does_not_panic_on_empty_repo`,
/// `catchup::tests::pm_catchup_context_does_not_panic_on_non_git_dir`.
async