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
//! The instruction-pipeline half of the `tm sessions` command group.
//!
//! Why: split out of `session.rs` (#7422) to bring that file back under the
//! 500-SLOC production cap, following the `start`/`catchup` submodule pattern
//! already used there. The move is mechanical — no behaviour change — except
//! for [`print_excluded_scope`], which #7422 adds.
//! What: [`compose_session_instructions`] and
//! [`compose_session_instructions_with_roster`] (the one source of truth for
//! the PM prompt a session receives, and the `last-instructions.md` stash), plus
//! [`print_excluded_scope`], the stderr companion naming the PLUGINS this
//! project does not load. // #7892: MCP servers are no longer scoped out, so
//! the server half of that companion is gone.
//! Test: `compose_session_instructions_*` in `session_tests.rs`.
/// Print, on stderr, the plugins this project's sessions will not load.
///
/// Why: `tm session instructions` is where an operator goes to see what a
/// session actually receives, and for plugins that answer still includes an
/// absence — an installed plugin this project does not opt into. stderr, not
/// stdout, because the prompt on stdout is piped into files and diffs.
/// What: one line per excluded plugin, then the `[session]` key that opts them
/// back in. Silent when nothing is excluded, and silent when the managed config
/// dir does not resolve. // #7892: no MCP line — every user-scope server loads
/// in every session, and `.mcp.json` is Claude Code's to approve.
/// Test: `session_scope::check_session_scope` covers the same derivation;
/// `print_excluded_scope_is_silent_when_nothing_is_excluded`.
pub
/// Run the instruction merge pipeline and stash the override-resolved PM prompt.
///
/// Why: `session start` and `session instructions` both need the effective PM
/// prompt — the text actually delivered to `claude --append-system-prompt-file`.
/// The old code returned `output.merged` (the legacy pipeline: INSTRUCTIONS.md +
/// delegation authority + CLAUDE.md) for display, while stashing `resolve_pm_prompt`
/// separately. That caused `tm session instructions` to print content that differed
/// from what Claude received, which is exactly the divergence issue #382 describes.
/// The single source of truth for "what claude receives" is `resolve_pm_prompt`;
/// the display and the stash must both come from it.
/// #4832: `fw` is gone — the pipeline no longer reads a framework path, so the
/// parameter had no remaining use.
/// What: builds a `PipelineInput` and runs `build_instructions` to ensure
/// `CLAUDE.md` is seeded (the side-effect we still need); resolves the PM prompt
/// via `crate::core::instruction_overrides::resolve_pm_prompt`; writes it to
/// `<project>/.trusty-mpm/last-instructions.md`; returns the resolved prompt text,
/// the `PipelineOutput` metadata flags, and the stash path.
/// Test: `compose_session_instructions_display_matches_stash`,
/// `compose_session_instructions_display_matches_live_prompt`.
pub
/// [`compose_session_instructions`] with the deployed-agent roster supplied.
///
/// Why (#5544): the equality this function's tests assert —
/// `compose_session_instructions(p).0 == build_system_prompt_for(p)` — puts two
/// independent scans of the three LIVE agent tiers on either side of an
/// `assert_eq!`. Those tiers are machine-global mutable state, so the two scans
/// can legitimately disagree and the test fails with a message that reads as a
/// prompt regression. Injecting one roster into both sides is the fix. The
/// alternative — pinning `$HOME` and `$CLAUDE_CONFIG_DIR` around the test — is
/// a PROCESS-GLOBAL write every sibling in the `tm` bin target can observe
/// mid-scan, which is the flake class #5544 tracks rather than a cure for it.
/// What: identical to [`compose_session_instructions`] except that a
/// `Some(roster)` routes the prompt through
/// [`trusty_mpm::core::session_launch::build_system_prompt_for_with_roster`].
/// `None` — every production caller — takes the live scan, unchanged.
/// Test: `compose_session_instructions_display_matches_live_prompt`,
/// `compose_session_instructions_display_matches_live_prompt_with_override`.
pub
/// The exact text [`stdin_git_init_prompt`] shows, naming the directory that
/// would be initialised (#7673 round 3 review, LOW).
///
/// Why: split so the wording is assertable without a real TTY — the prior
/// text never named a directory at all, which cost nothing at this call site
/// (there is exactly one directory in view), but is wasted ambiguity on a
/// prompt an operator actually reads.
/// What: `"<dir> is not a git repository; initialise one? [y/N] "`.
/// Test: `git_init_prompt_text_names_the_directory`.
/// A real yes/no `git init` prompt, built only when stdin is a TTY (#7673
/// round 3 follow-up, owner ruling 2026-09-13).
///
/// Why: `tm sessions instructions --dir <dir>` is the one production entry
/// point `load_or_create_claude_md` reaches with no prior git-project check
/// (`session start`'s in-place path already refuses a non-git directory
/// before it gets here; `tm launch`/bare `tm` already run the pre-existing,
/// unconditional `commands::auto_git_init::ensure_git_repo` before project
/// detection, so the seed site never sees a non-git directory from there
/// either — see the module-choice note on [`compose_session_instructions_with_roster_and_init`]).
/// A non-interactive caller (no TTY — piped, `--yes`-style automation, a
/// daemon or MCP caller) must get the existing silent-decline default;
/// asking a question nobody can answer would hang the process.
/// What: `None` when stdin is not a terminal. Otherwise a closure that prints
/// [`git_init_prompt_text`] — naming `dir` — on stderr, reads one line, and
/// classifies it through the SAME confirm helper the picker's other yes/no
/// prompts use ([`crate::commands::picker_delete::confirm_is_yes`]) rather
/// than a new stdin reader.
/// Test: the decline/accept DECISION is tested directly through
/// [`compose_session_instructions_with_roster_and_init`]'s injected closure
/// (`instructions_tests.rs`); actually reading stdin is terminal interaction,
/// not exercised in CI, matching every other confirm prompt in this crate.
/// [`compose_session_instructions_with_roster`] with the git-init-offer
/// prompt seam threaded through explicitly, so the decline/accept decision is
/// testable without a real TTY or stdin (#7673 round 3 follow-up).
///
/// Why this entry point, and not `session start`'s in-place path or `tm
/// launch`: `start_session_in_place` only runs once
/// `refuse_outside_a_git_project` has already certified the target is inside
/// a git working tree, so `load_or_create_claude_md`'s seed site there can
/// never see a non-git directory — there is nothing for this prompt to offer.
/// `tm launch`/bare `tm` call `commands::auto_git_init::ensure_git_repo`
/// (#6274) before project detection even runs, which already turns a plain
/// directory into an ordinary no-origin git project (or refuses Home/
/// filesystem-root) — by the time either reaches the seed path the directory
/// is already resolved, so wiring a second, different git-init decision onto
/// an already-working flow would be the parallel path the reuse note warns
/// against, not a fix. This function is the one production call that reaches
/// `load_or_create_claude_md` with NEITHER guard in front of it — the
/// documented `tm sessions instructions --dir <dir>` first-touch shape.
/// What: identical to [`compose_session_instructions_with_roster`] except
/// `should_init` is passed straight through to
/// [`trusty_mpm::core::instruction_pipeline::build_instructions_with_init`]
/// instead of being derived from stdin here.
/// Test: `compose_session_instructions_declines_git_init_without_a_prompt`,
/// `compose_session_instructions_runs_git_init_when_the_prompt_accepts`,
/// `compose_session_instructions_refuses_to_seed_when_git_init_fails`.