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
//! PM work meaningfulness classification — the WORK tier of the
//! Activity / Work / Effort model for tickets (issue #3916, epic #3914).
//!
//! Why: a raw ticket count is an ACTIVITY number. It counts a one-word
//! sub-task ("Final", "Phase 3") identically to a substantive story, so a PM
//! who decomposes work into many stubs outscores one who does not. This
//! module filters that activity down to the meaningful subset, and the
//! verdict is persisted to `fact_pm_work` (`core::db::pm_work`).
//!
//! What: [`classify`] is a deterministic function of one ticket's title,
//! description, reporter, and whether a human ever moved it. There is no LLM
//! tier in v1 — every input the classifier reads is already in the database.
//!
//! Test: `tests` in `tests.rs`.
//!
//! # Versioning
//!
//! Every persisted row records [`FORMULA_VERSION`]. The thresholds in
//! [`thresholds`] are v1 constants: a retune ships as a NEW version string,
//! never as an edit of the values below, so a stored verdict always names the
//! rule set that produced it.
use fmt;
/// Threshold set version baked into every persisted `fact_pm_work` row.
///
/// Why: a later retune of the constants in [`thresholds`] must be
/// distinguishable from v1 in already-stored rows.
/// What: the string `"pm-work-1"`, written to `fact_pm_work.formula_version`.
/// Test: `classifier_reports_the_v1_formula_version`.
pub const FORMULA_VERSION: &str = "pm-work-1";
/// v1 meaningfulness thresholds (`formula_version = "pm-work-1"`).
///
/// Why: the exclusion rules in issue #3916 are heuristics calibrated against
/// one JIRA instance, so they will be retuned. Keeping every tunable number
/// in one named block means a retune is a reviewable diff of this module and
/// a bump of [`FORMULA_VERSION`] — never a scattered edit that silently
/// changes what already-stored rows meant.
/// What: the word-count bounds and bot-account markers the v1 rules read.
/// Nothing outside this block is tunable.
/// Test: `terse_title_boundary_is_the_documented_threshold`.
/// Why a ticket was excluded from the meaningful-work subset.
///
/// Why: the exclusion list is issue #3916's, verbatim — the consumer
/// (cto-reports) groups by this value to report which filter removed what.
/// What: a four-valued enum stored as text in
/// `fact_pm_work.exclusion_reason`; [`ExclusionReason::None`] is stored as
/// `'NONE'` rather than SQL NULL so every row carries a groupable verdict.
/// Test: `exclusion_reason_round_trips_through_its_wire_string`.
/// Everything the v1 classifier reads about one ticket.
///
/// Borrowed rather than owned: the caller already holds these as columns of a
/// `work_items` row and the classifier never keeps them.
/// One ticket's meaningfulness verdict.
/// Whether `name` is an automation account rather than a person.
///
/// Why: two of the three exclusion rules key off reporter identity, and a
/// naive `contains("bot")` misfires on surnames like "Abbott".
/// What: lowercases `name`, tests it against
/// [`thresholds::BOT_NAME_MARKERS`] as substrings, then splits it into
/// alphanumeric tokens and tests those against
/// [`thresholds::BOT_NAME_TOKENS`] as whole words.
/// Test: `bot_detection_matches_automation_accounts`,
/// `bot_detection_does_not_misfire_on_human_names`.
/// Count whitespace-separated words.
///
/// Deliberately naive: the input is already plain text (HTML tags and
/// Atlassian-Document-Format wrappers are stripped by
/// [`extract::extract_fields`]), and a locale-aware tokenizer would change
/// the meaning of the stored counts without changing any verdict near the
/// v1 thresholds.
/// Classify one ticket's meaningfulness under `formula_version = "pm-work-1"`.
///
/// Why: see the module docs — this is the WORK tier of #3914, filtering the
/// raw ticket count down to tickets that represent management labor.
/// What: applies issue #3916's three exclusion rules in a fixed precedence,
/// because a ticket can satisfy more than one and the stored reason must be
/// deterministic:
///
/// 1. The reporter is an automation account ([`is_bot_account`]). A human
/// later transitioned it → [`ExclusionReason::BotFiled`]; nobody did →
/// [`ExclusionReason::AutoGenerated`]. Provenance is checked first: a
/// bot-filed stub is excluded for being bot-filed, which is the more
/// specific fact about it.
/// 2. The title is at most [`thresholds::TERSE_TITLE_MAX_WORDS`] words AND
/// the body is under [`thresholds::SUBSTANTIVE_BODY_MIN_WORDS`] →
/// [`ExclusionReason::TerseTitle`].
/// 3. Otherwise the ticket is meaningful.
///
/// Test: `terse_title_with_no_body_is_excluded`,
/// `bot_reporter_with_no_human_transition_is_auto_generated`,
/// `bot_reporter_with_human_transition_is_bot_filed`,
/// `substantive_story_is_meaningful`.