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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//! Data contract for the intent-source resolver (ISR).
//!
//! Why: both conformance gates (FRONT in trusty-mpm, BACK in trusty-review)
//! must agree on a *single* shape for "the resolved intent" and on how
//! precedence (ticket > spec) was applied. Defining the contract once here —
//! in the crate both gates already depend on — guarantees the two gates can
//! never disagree about which intent source wins (spec §6.1, §6.5).
//! What: the input query (`IntentQuery`), the output (`ResolvedIntent`) and its
//! constituent value types (`Method`, `MethodKind`, `Precedence`, `TicketRef`,
//! `SpecRef`), plus the resolver error type (`IsrError`).
//! Test: `super::tests` — round-trip + constructor coverage (AC-1..AC-7).
use ;
/// Input to [`crate::intent_source::resolve`]: one of two query shapes.
///
/// Why: the BACK gate starts from a PR (it must *extract* the ticket-id and
/// resolve spec links from changed files), while the FRONT gate already holds
/// the ticket-id pre-work. Modelling both as one enum keeps a single resolver
/// entry point (spec §6.1).
/// What: `Pr` carries owner/repo/pr-number plus the diff/changed-file context
/// used for ticket-linkage and spec-resolution; `Ticket` carries a known
/// ticket-id and optional changed files.
/// Test: `super::tests::pr_query_*` / `ticket_query_*`.
/// A changed file paired with the source text the ISR scans for SLD refs.
///
/// Why: SLD spec-resolution (spec §6.4) reads `# Spec References` rustdoc
/// blocks out of the *content* of changed files — a path alone is not enough.
/// What: `path` is the repo-relative path; `content` is the file's text (the
/// caller supplies it; the ISR never reads the filesystem itself).
/// Test: `super::tests::spec_resolve_*`.
/// Which intent source won under the fixed precedence rule (ticket > spec).
///
/// Why: callers must know, without re-deriving, whether the ticket or the spec
/// is the authority for this unit of work — and `None` signals a genuine gap
/// (spec §6.1 precedence resolution).
/// What: a three-state marker serialised lowercase for stable wire shape.
/// Test: `super::tests::precedence_*`.
/// The class of an extracted method statement.
///
/// Why: a conformance gate downstream may treat a hard constraint ("no new
/// dependency") differently from an approach hint ("prefer cursor pagination");
/// tagging the kind keeps that option open without re-parsing the text.
/// What: a coarse taxonomy over the imperative-method phrasings the heuristic
/// extractor recognises (spec §6.2). `Unspecified` is the safe default when a
/// method was supplied verbatim (e.g. by an LLM) without a class.
/// Test: `super::tests::extract_*`.
/// An extracted statement of approach/technique/constraint.
///
/// Why: the matrix (spec §4) compares the *subject* against a *method*, not
/// against free prose. Carrying the verbatim source excerpt keeps the finding
/// explainable and auditable (no hallucinated constraints — spec §6.2).
/// What: `text` is the normalised method statement; `kind` classifies it;
/// `source_excerpt` is the verbatim line(s) it was lifted from.
/// Test: `super::tests::extract_*`.
/// A reference to the ticket the intent was resolved from.
///
/// Why: the BACK gate must cite *which* ticket it checked conformance against;
/// the FRONT gate echoes it into escalation context (spec §6.1 outputs).
/// What: the backend-native id, human title, optional URL, and backend tag.
/// Test: `super::tests::ticket_query_*`.
/// A reference to the spec section the intent was resolved from.
///
/// Why: when the spec axis wins (or conflicts), the gate must cite the exact
/// `SPEC-…` anchor + file it checked against (spec §6.1, §6.4).
/// What: the spec id (`SPEC-SUBSYSTEM-NN~vR`), the `docs/specs/*.md` file, and
/// the in-file anchor (`SPEC-SUBSYSTEM-NN`).
/// Test: `super::tests::spec_resolve_*`.
/// The resolved intent — the single contract both gates consume.
///
/// Why: centralising precedence here (applied exactly once) guarantees FRONT
/// and BACK never disagree about which source wins (spec §6.1, G4).
/// What: the ticket + ticket method, the spec section + spec method, the
/// precedence winner, the `conflict`/`stale_spec` flags, and an `unresolved`
/// fail-open reason. When `unresolved` is `Some`, all method fields are `None`
/// and both gates no-op (spec §4.2).
/// Test: `super::tests` — every AC-1..AC-7 case asserts on this struct.
/// Errors that can arise inside the resolver before the fail-open conversion.
///
/// Why: trusty-common is a library, so internal failure modes are modelled as
/// a structured `thiserror` enum rather than `anyhow` (CLAUDE.md convention).
/// The public `resolve` entry never returns this — it maps every variant into
/// `ResolvedIntent::unresolved` (spec §4.2 fail-open) — but the typed error
/// keeps the internal plumbing precise and testable.
/// What: the failure categories the resolver distinguishes.
/// Test: `super::tests::error_display_*`.