instinct-cli 0.3.9

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//! The short, loud and indirect corrections the sentence rules above do not reach: a bare "nope", "undo
//! that", "why did you delete the tests", "too long, cut it in half", "great, now nothing builds".
//!
//! Every rule is a closed word class plus a position in the message. None of them fires on tone alone:
//! profanity and frustration only count next to something the agent did, a refusal, or a repeat.
use super::{has, starts, words, THINGS};

/// Whole-message rules, run once on the normalised text.
pub fn message(text: &str) -> bool {
    let t = text.trim();
    again_burst(t) || bare(t) || style(t) || sarcastic(t)
}

/// "again??" alone: the burst of punctuation is the complaint.
fn again_burst(t: &str) -> bool {
    t.starts_with("again?") || t.starts_with("again!")
}

/// "nooo" and "no" are one word; "nahh" and "nah" too.
fn canon(x: &str) -> &str {
    if x.len() >= 2 && x.starts_with('n') && x.chars().all(|c| c == 'n' || c == 'o') {
        "no"
    } else if x.starts_with("nah") && x.chars().skip(2).all(|c| c == 'h') {
        "nah"
    } else {
        x
    }
}

/// Words that may stand around a bare refusal without changing it.
fn trim_noise<'a>(w: &'a [&'a str]) -> &'a [&'a str] {
    let mut w = w;
    while let Some((f, rest)) = w.split_first() {
        if matches!(*f, "dude" | "bro" | "man" | "ugh" | "hey" | "oh" | "omg" | "ffs" | "please" | "uh" | "um") {
            w = rest;
        } else {
            break;
        }
    }
    while let Some((l, rest)) = w.split_last() {
        if matches!(*l, "please" | "now" | "man" | "dude" | "bro") {
            w = rest;
        } else {
            break;
        }
    }
    w
}

/// "nope", "wrong", "undo that", "stop": a message that is only a refusal or a reversal.
fn bare(t: &str) -> bool {
    let all = words(t);
    let w = trim_noise(&all);
    if w.is_empty() || w.len() > 7 {
        return false;
    }
    // "nooo", "nahh", "wrongg": stretched spellings.
    let sq: Vec<&str> = w.iter().map(|x| canon(x)).collect();
    let refusal = |x: &str| matches!(x, "no" | "nope" | "nah" | "nop" | "naw");
    // "undo that change", "undo what you just did", "revert your last commit": a reversal and little else.
    if matches!(sq[0], "undo" | "revert" | "rollback" | "reset") && sq.len() >= 2 {
        const TAIL: &[&str] = &[
            "that", "this", "it", "the", "last", "previous", "change", "changes", "edit", "edits", "commit", "step", "what", "you",
            "just", "did", "your", "my", "all", "everything", "back", "please", "now", "thing", "one", "work", "stuff",
        ];
        if sq[1..].iter().all(|x| TAIL.contains(x)) {
            return true;
        }
    }
    // "put it back", "put it back the way it was".
    if sq[0] == "put" && sq.len() >= 3 && matches!(sq[1], "it" | "that" | "this" | "everything" | "them") && sq[2] == "back" && sq[3..].iter().all(|x| matches!(*x, "the" | "way" | "it" | "was" | "as" | "before" | "where" | "original" | "place" | "how" | "please")) {
        return true;
    }
    // "dont", "dont do that", "dont touch that": a refusal in the imperative.
    if sq[0] == "don't" && sq.len() <= 3 && sq[1..].iter().all(|x| matches!(*x, "do" | "touch" | "that" | "it" | "this" | "change" | "delete" | "move" | "push" | "commit" | "run" | "edit")) {
        return true;
    }
    if matches!(sq.as_slice(), ["enough"] | ["enough", "already"] | ["cut", "it", "out"] | ["knock", "it", "off"] | ["quit", "it"] | ["worse"] | ["even", "worse"] | ["much", "worse"] | ["that's", "worse"] | ["nope", "that's", "worse"] | ["no", "that's", "worse"] | ["wrong", "approach"] | ["wrong", "way"]) {
        return true;
    }
    // "stop stop stop", "no no no no": the same word again and again.
    // "not that file", "not the right one"
    if sq.len() == 3 && sq[0] == "not" && matches!(sq[1], "that" | "this" | "the") && THINGS.contains(&sq[2]) {
        return true;
    }
    // "reverse that", "go back to how it was"
    if matches!(sq.as_slice(), ["reverse", "that" | "it" | "this"]) {
        return true;
    }
    if sq.len() >= 3 && sq[0] == "go" && sq[1] == "back" && sq[2..].iter().all(|x| matches!(*x, "to" | "how" | "the" | "way" | "it" | "was" | "before" | "previous" | "original" | "state" | "version" | "please")) {
        return true;
    }
    if sq.len() >= 2 && sq.iter().all(|x| *x == sq[0]) && (refusal(sq[0]) || matches!(sq[0], "stop" | "wrong" | "undo" | "revert")) {
        return true;
    }
    if matches!(sq.as_slice(), ["reset", "it" | "that" | "this"] | ["take", "that" | "it", "back"] | ["not", "this", "one"] | ["bad", "idea"] | ["that's", "not", "it"] | ["not", "it"] | ["no", "that", "one"] | ["wrong", "idea"] | ["not", "that", "one"] | ["not", "this"] | ["that", "was", "wrong"] | ["not", "correct"]) {
        return true;
    }
    // Only refusals and reversals, in the orders people type them.
    match sq.as_slice() {
        [a] if refusal(a) || matches!(*a, "wrong" | "incorrect" | "stop" | "undo" | "revert" | "bad" | "rollback") => true,
        [a, b] => {
            (refusal(a) && (refusal(b) || matches!(*b, "stop" | "wait" | "wrong" | "that" | "it" | "again")))
                || (matches!(*a, "wait" | "hold") && (refusal(b) || *b == "stop"))
                || (matches!(*a, "wrong") && matches!(*b, "one" | "again" | "file" | "branch"))
                || (matches!(*a, "stop" | "undo" | "revert" | "cancel") && matches!(*b, "it" | "that" | "this" | "stop"))
                || (*a == "not" && matches!(*b, "that" | "right" | "correct"))
                || (matches!(*a, "that's" | "thats") && matches!(*b, "wrong" | "incorrect"))
                || (*a == "roll" && *b == "back")
                || (*a == "go" && *b == "back")
        }
        [a, b, c] => {
            (matches!(*a, "hold") && *b == "on" && (refusal(c) || *c == "stop"))
                || (refusal(a) && refusal(b) && refusal(c))
                || (*a == "roll" && matches!(*b, "it" | "that") && *c == "back")
                || (*a == "not" && *b == "like" && *c == "that")
                || (*a == "not" && *b == "that" && *c == "one")
                || (matches!(*a, "that's" | "thats") && *b == "not" && matches!(*c, "right" | "correct"))
                || (*a == "that" && *b == "is" && matches!(*c, "wrong" | "incorrect"))
                || (matches!(*a, "undo" | "revert") && matches!(*b, "the") && *c == "change")
                || (refusal(a) && matches!(*b, "that" | "it") && matches!(*c, "wrong" | "again"))
                || (matches!(*a, "nope" | "no") && *b == "wrong" && *c == "again")
        }
        [a, b, c, d] => {
            (matches!(*a, "undo" | "revert") && *b == "the" && matches!(*c, "last" | "previous") && matches!(*d, "change" | "edit" | "step" | "one"))
                || (*a == "nope" && *b == "wrong" && *c == "again")
        }
        _ => false,
    }
}

/// Style complaints: "too long", "make it shorter", "no emojis", "drop the intro".
fn style(t: &str) -> bool {
    const ADJ: &[&str] = &[
        "long", "verbose", "wordy", "formal", "chatty", "much", "many", "complicated", "complex", "clever", "casual",
        "detailed", "technical", "lengthy", "polite", "friendly", "cute", "smart", "fancy", "dense", "vague", "abstract",
    ];
    let w = words(t);
    if w.len() > 14 {
        return false;
    }
    // "too long", "way too long", "a bit too wordy", "this is too long": "too" leads the sentence or follows
    // only a degree word, never a subject ("the output is too long for the terminal" is about the output).
    if let Some(i) = w.iter().position(|x| *x == "too") {
        let before_ok = w[..i].iter().all(|x| matches!(*x, "way" | "a" | "bit" | "little" | "much" | "far" | "this" | "is" | "it's" | "that's" | "its" | "that" | "it" | "just" | "really" | "so" | "wow" | "dude"));
        if before_ok && i <= 4 && w.get(i + 1).is_some_and(|a| ADJ.contains(a)) && !matches!(w.get(i + 2), Some(&"to") | Some(&"for")) {
            return true;
        }
    }
    if w.len() > 7 {
        return false;
    }
    // "can you make it shorter", "please keep it brief": the politeness is not part of the complaint.
    let mut t = t;
    for polite in ["can you ", "could you ", "would you ", "please ", "just ", "pls ", "now "] {
        if let Some(r) = t.strip_prefix(polite) {
            t = r.trim_start();
        }
    }
    const OPENERS: &[&str] = &[
        "brief please", "simpler please", "less explanation", "less detail", "less details", "fewer words", "no walls of text",
        "no wall of text", "keep answers short", "keep replies short", "keep responses short", "keep answers brief",
        "keep it shorter", "just give me the code", "give me the code", "only the code", "code only", "just the code", "give me the code only",
        "stop explaining", "don't explain", "no need to explain", "less talking", "less words", "fewer details",
        "shorter answers", "shorter replies", "shorter responses", "more brief", "more succinct", "be succinct",
        "briefer", "simpler", "more concise please", "make it concise", "make it brief", "make it terse", "make that shorter",
        "shorter", "shorten it", "shorten that", "make it shorter", "make it short", "make it simpler", "make it more concise",
        "make it less verbose", "make it briefer", "make it tighter", "make that shorter", "keep it short", "keep it brief",
        "keep it simple", "keep it tight", "keep it concise", "keep it shorter", "be more concise", "be more brief", "be brief",
        "be concise", "be terse", "be shorter", "more concise", "more brief", "less verbose", "less wordy", "less fluff",
        "less text", "less chatty", "less formal", "no emojis", "no emoji", "no fluff", "no essays", "dont write essays",
        "don't write essays", "cut it in half", "cut it down", "cut that down", "trim it", "trim that", "drop the intro",
        "drop the preamble", "drop the fluff", "drop the outro", "no explanation", "just the code", "tl;dr", "tldr",
        "simplify it", "simplify that", "simplify this", "shorten this", "shorten", "trim this", "make this shorter", "stop being so verbose", "stop being so wordy", "stop being so formal", "stop the fluff",
        "stop the essays", "stop writing essays", "simpler please", "shorter please", "concise please",
    ];
    // A one-word opener ("simpler", "shorter") only counts when it is nearly the whole message.
    OPENERS.iter().any(|p| (starts(t, p) && (p.contains(' ') || w.len() <= 2)) || (w.len() <= 3 && has(t, p)))
        || (t.starts_with("just the code") || t.contains(", no explanation") || t.contains(", no fluff"))
}

/// "great, now nothing builds", "nice, you broke the tests": praise opener, then something that went wrong.
fn sarcastic(t: &str) -> bool {
    const OPENERS: &[&str] = &[
        "great", "nice", "perfect", "awesome", "wow", "brilliant", "good job", "great job", "well done", "thanks", "thank you",
        "amazing", "wonderful", "fantastic", "love it", "super", "cool", "oh great", "oh nice", "oh wow", "ok great", "okay great",
        "oh cool", "fine", "sure", "yeah", "well", "lovely", "excellent", "impressive", "genius", "bravo", "thanks a lot",
        "thanks for nothing", "oh perfect", "oh awesome", "oh brilliant", "oh good", "good", "love that", "just great",
        "fucking great", "great job genius",
    ];
    const BAD: &[&str] = &[
        "broke", "broken", "breaks", "deleted", "wiped", "removed", "crash", "crashes", "crashed", "fail", "fails", "failed",
        "failing", "errors", "error", "wont", "won't", "doesn't", "doesnt", "didn't", "red", "gone", "empty", "blank", "dead",
        "ruined", "killed", "destroyed", "lost", "overwrote", "nuked", "trashed", "messed", "worse", "useless", "wrong",
        "stuck", "hangs", "frozen", "missing", "corrupted", "panics", "panic", "mess", "disaster", "exploded", "undefined",
        "breaking", "deleting", "wiping", "removing", "killing", "ruining", "destroying", "overwriting", "loops", "forever",
        "infinite", "loop", "hangs", "hanging", "crashing", "failing",
        "again", "everything", "nothing", "copies", "duplicates", "duplicate", "warnings", "conflicts", "break",
    ];
    const FIXED: &[&str] = &[
        "fixed", "solved", "resolved", "works", "working", "passes", "passing", "passed", "green", "clean", "fast", "faster",
        "ship", "merge", "add", "next", "now add", "worked", "better",
    ];
    let w = words(t);
    if w.len() < 3 || w.len() > 24 {
        return false;
    }
    let head = OPENERS.iter().any(|o| starts(t, o) || (starts(t, "oh") && has(&t.chars().take(14).collect::<String>(), o)));
    if !head {
        return false;
    }
    // "nothing" and "everything" and "again" need the full phrase so "nothing to add" stays quiet.
    let everything = ["rewrote", "changed", "touched", "deleted", "removed", "replaced", "reformatted", "renamed", "reverted", "wiped"]
        .iter()
        .any(|v| w.windows(2).any(|p| p[0] == *v && p[1] == "everything"));
    let nothing = everything || has(t, "now none") || has(t, "now no") || has(t, "while you're at it") || has(t, "while you are at it") || has(t, "now nobody")
        || has(t, "now nothing") || has(t, "for nothing") || has(t, "broke everything") || has(t, "nothing builds")
        || has(t, "nothing compiles") || has(t, "nothing works") || has(t, "the same bug again") || has(t, "same bug") || has(t, "same error");
    let another = starts(t, "oh") && has(t, "another");
    let redo = has(t, "now i have to") || has(t, "now i need to") || has(t, "now i must") || has(t, "redo") || has(t, "start over");
    if nothing {
        return true;
    }
    if w.iter().any(|x| FIXED.contains(x)) {
        return false;
    }
    another || redo || w.iter().any(|x| BAD.contains(x) && !matches!(*x, "again" | "everything" | "nothing"))
}

/// Sentence rules that skip the interrogative guard: a "why did you ..." is blame, not curiosity.
pub fn blame(s: &str) -> bool {
    if has(s, "curious") || has(s, "curiosity") || has(s, "wondering") || has(s, "just asking") || has(s, "out of interest") {
        return false;
    }
    const PHRASES: &[&str] = &[
        "were you even", "who said you could", "who said you can", "are you kidding", "are you serious", "are you insane", "are you blind", "are you even", "are you listening",
        "not listening", "what are you doing", "what are you even doing", "what the hell are you", "what the fuck are you",
        "what the actual fuck are", "wtf are you", "wtf did you", "what did you just do", "what did you do",
        "what have you done", "what is wrong with you", "what's wrong with you", "how are you still", "how could you",
        "what were you thinking", "did you even", "you didn't even", "you can't even", "have you even", "who told you",
        "what made you think", "have to repeat", "why do i keep", "what the hell did you", "what the fuck did you",
        "wtf did you just", "do you even", "can you not", "did you not read", "did you read", "who asked", "don't remember asking",
        "don't recall asking", "i never requested", "i didn't request", "i didn't want", "i never wanted", "i didn't tell you to",
        "i never told you to", "i didn't say to", "i never said to", "beyond what i", "outside what i", "outside of what i",
        "more than i asked", "more than what i asked", "instead of what i", "went way outside", "way beyond",
        "not asking you to", "not asking for", "nobody asked", "no one asked", "did not just", "didn't just", "made that up",
        "made it up", "made up", "hallucinated", "hallucinating", "fabricated", "you invented", "in my message",
        "in my last message", "i literally wrote", "i already wrote", "i just wrote",
    ];
    if PHRASES.iter().any(|p| has(s, p)) && !has(s, "can you not only") {
        return !has(s, "did you read the") || has(s, "did you read it") || has(s, "did you read what");
    }
    let w = words(s);
    // "i dont know why you removed that line": the reason is asked about something the agent did.
    if let Some(k) = w.iter().position(|x| *x == "why") {
        if w.get(k + 1) == Some(&"you") && w.get(k + 2).is_some_and(|v| matches!(*v, "deleted" | "removed" | "changed" | "touched" | "renamed" | "added" | "overwrote" | "reverted" | "dropped" | "broke" | "rewrote" | "edited" | "modified" | "moved" | "replaced" | "reformatted")) {
            return true;
        }
    }
    // "how did the lockfile end up changed"
    if (has(s, "end up") || has(s, "ended up")) && w.iter().any(|x| matches!(*x, "changed" | "deleted" | "removed" | "modified" | "touched" | "renamed" | "gone" | "overwritten" | "reverted" | "different" | "edited")) {
        return true;
    }
    // "what made you delete the fixture"
    if let Some(k) = w.iter().position(|x| *x == "made") {
        if k >= 1 && w[k - 1] == "what" && w.get(k + 1) == Some(&"you") && w.get(k + 2).is_some_and(|v| matches!(*v, "delete" | "remove" | "change" | "touch" | "rename" | "add" | "overwrite" | "revert" | "drop" | "rewrite" | "edit" | "modify" | "move" | "replace" | "reformat" | "install" | "commit" | "push")) {
            return true;
        }
    }
    // "why is it using the old api now"
    if w.len() >= 5 && w[0] == "why" && w[1] == "is" && w[2] == "it" && w[3].ends_with("ing") && matches!(w.last(), Some(&"now") | Some(&"again") | Some(&"still") | Some(&"anymore")) {
        return true;
    }
    // "why did you delete the tests", "why would you rename it", "why are you using npm".
    let skip = w.iter().take(6).position(|x| *x == "why").unwrap_or(0);
    let w = &w[skip..];
    if w.len() >= 4 && w[0] == "why" {
        const CHANGE: &[&str] = &[
            "delete", "remove", "change", "touch", "rename", "add", "modify", "overwrite", "revert", "drop", "break", "skip",
            "ignore", "rewrite", "edit", "push", "commit", "reformat", "install", "create", "replace", "move", "wipe", "kill",
            "disable", "mock", "hardcode", "use", "bump", "pin", "unpin", "reorder", "squash", "merge", "format", "refactor", "downgrade", "upgrade",
        ];
        const CHANGING: &[&str] = &[
            "using", "adding", "deleting", "removing", "changing", "touching", "editing", "rewriting", "renaming", "installing",
            "creating", "ignoring", "modifying", "mocking", "pushing", "committing", "reformatting", "replacing", "moving",
            "running", "formatting", "refactoring", "rewriting", "wiping", "killing",
        ];
        // "why is main changed", "why was the test deleted": the same blame, said about the thing.
        if matches!(w[1], "is" | "are" | "was" | "were") && w[2..].iter().take(5).any(|x| matches!(*x, "changed" | "deleted" | "removed" | "modified" | "touched" | "renamed" | "gone" | "missing" | "overwritten" | "reverted" | "different" | "edited" | "rewritten" | "dropped")) {
            return true;
        }
        if matches!(w[1], "did" | "would" | "do") && w[2] == "you" && (CHANGE.contains(&w[3]) || (w[3] == "just" && w.get(4).is_some_and(|v| CHANGE.contains(v)))) {
            return true;
        }
        if w[1] == "are" && w[2] == "you" && CHANGING.contains(&w[3]) {
            return true;
        }
        if (w[1] == "is" && w[2] == "there" && w[3] == "a" && w.get(4) == Some(&"new")) || (w[1] == "are" && w[2] == "there" && w[3] == "new") {
            return true;
        }
    }
    false
}

/// "you deleted the migration", "holy shit you broke the build", "you never checked the lockfile".
pub fn you_blame(s: &str) -> bool {
    const VERBS: &[&str] = &[
        "deleted", "removed", "changed", "broke", "overwrote", "ignored", "forgot", "missed", "dropped", "pushed", "left",
        "reverted", "rewrote", "renamed", "modified", "touched", "edited", "wiped", "killed", "skipped", "reformatted",
        "committed", "merged", "added", "created", "installed", "replaced", "moved", "messed", "screwed", "destroyed", "lost",
        "hardcoded", "mocked", "disabled", "stripped", "truncated", "duplicated", "never", "didn't", "failed", "stopped",
        "mangled", "clobbered", "trashed", "nuked", "bypassed", "formatted", "refactored", "rebased", "amended", "squashed",
        "bumped", "upgraded", "downgraded", "cleaned", "pruned", "reset", "reinstalled", "regenerated", "swapped", "shipped",
        "deployed", "ruined", "wrecked", "erased", "uninstalled", "inlined", "stubbed", "hid", "commented", "unstaged",
    ];
    const GOOD: &[&str] = &[
        "thanks", "thank", "great", "nice", "perfect", "awesome", "love", "good", "right", "well", "appreciate", "helpful",
        "excellent", "brilliant", "amazing", "fixed", "correctly",
    ];
    const NO_LEAD: &[&str] = &[
        "if", "when", "whether", "unless", "can", "could", "would", "should", "will", "do", "does", "did", "how", "why", "where",
        "which", "who", "thank", "thanks", "please", "once", "after", "before", "since", "while", "that", "because",
    ];
    let w = words(s);
    for i in 0..w.len().min(5) {
        if w[i] != "you" {
            continue;
        }
        if w[..i].iter().any(|x| NO_LEAD.contains(x)) {
            return false;
        }
        let mut j = i + 1;
        while w.get(j).is_some_and(|x| matches!(*x, "just" | "also" | "then" | "even" | "really" | "literally" | "totally" | "completely" | "already" | "now" | "again" | "actually" | "somehow")) {
            j += 1;
        }
        let Some(v) = w.get(j) else { return false };
        // "you made that api up", "you made it up"
        if *v == "made" && w[j + 1..].iter().take(4).any(|x| *x == "up") {
            return !w.iter().any(|x| GOOD.contains(x));
        }
        if !VERBS.contains(v) {
            return false;
        }
        // "you never listen" is about_you's; "you never" alone with a plain verb is blame too.
        return !w.iter().any(|x| GOOD.contains(x));
    }
    false
}

/// "it's not running, check the logs", "still wrong", "nothing changed", "that's false".
pub fn claim(s: &str) -> bool {
    s.split(',').any(|clause| claim_clause(clause.trim()))
}

fn claim_clause(s: &str) -> bool {
    let w = words(s);
    let Some(&f) = w.first() else { return false };
    // "this" is left out on purpose: "This is not working, the page is blank" opens a new bug report.
    const SUBJ: &[&str] = &["it", "that", "it's", "that's", "its", "these", "those"];
    const NEG: &[&str] = &["not", "isn't", "doesn't", "didn't", "won't", "wasn't", "hasn't", "can't", "aren't", "don't"];
    const STATE: &[&str] = &[
        "working", "running", "true", "right", "correct", "fixed", "there", "installed", "compiling", "compile", "passing",
        "pass", "real", "valid", "work", "fix", "exist", "load", "loading", "start", "starting", "build", "building", "help",
        "run", "accurate", "found", "how", "available", "enabled", "set", "print", "show", "output", "return", "display",
        "produce", "respond", "appear", "change", "update", "save", "finish", "log", "open", "boot",
    ];
    const FAIL: &[&str] = &[
        "fails", "failed", "failing", "crashed", "crashes", "crashing", "errors", "errored", "hangs", "hung", "panics", "panicked",
        "broke", "breaks", "froze", "freezes", "segfaults", "exploded", "broken", "wrong", "blank", "empty",
    ];
    // "this isnt fixed": three or four words and a verdict word; "This is not working, ..." stays a new report.
    if f == "this" && w.len() <= 4 && w.iter().any(|x| NEG.contains(x) || *x == "not") && matches!(w.last(), Some(&"fixed") | Some(&"right") | Some(&"correct") | Some(&"true") | Some(&"done")) {
        return true;
    }
    if SUBJ.contains(&f) {
        let mut i = 1;
        while w.get(i).is_some_and(|x| matches!(*x, "is" | "was" | "does" | "did" | "has" | "still" | "even" | "actually" | "really" | "just" | "do")) {
            i += 1;
        }
        let still = w[1..i].contains(&"still");
        if let Some(n) = w.get(i) {
            if NEG.contains(n) {
                let after = w.get(i + 1).copied().unwrap_or("");
                if STATE.contains(&after) {
                    return !(after == "how" && f != "that's" && f != "that");
                }
                // "that's not the cause / the bug / the problem"
                if after == "the" && w.get(i + 2).is_some_and(|x| THINGS.contains(x) || matches!(*x, "cause" | "bug" | "problem" | "issue" | "fix" | "right" | "schema" | "answer" | "api" | "endpoint" | "same")) {
                    return true;
                }
                // "it's not on port 5000", "that's not in src": where the agent said it was.
                if matches!(after, "on" | "in" | "at") && w.len() >= i + 3 && matches!(f, "it's" | "its" | "that's") {
                    return true;
                }
                if matches!(after, "a" | "an") && matches!(w.get(i + 2), Some(&"real") | Some(&"valid")) {
                    return true;
                }
            }
            // "it crashes when the input is empty" opens a new bug report; "it still crashes" does not.
            let recent = w.last().is_some_and(|x| matches!(*x, "now" | "again" | "anymore" | "too"));
            let conditional = !recent && w.get(i + 1).is_some_and(|x| matches!(*x, "when" | "if" | "on" | "with" | "for" | "at" | "only" | "in" | "whenever" | "after" | "during" | "because" | "under"));
            // "its broken": a three-word verdict, not a bug report with a place and a cause.
            let terse_verdict = w.len() <= 3 && matches!(*n, "broken" | "wrong");
            if FAIL.contains(n) && (still || terse_verdict || (!conditional && !matches!(*n, "wrong" | "blank" | "empty" | "broken"))) {
                return true;
            }
            // "that's false", "that is untrue"
            if matches!(*n, "false" | "untrue" | "inaccurate" | "incorrect") {
                return true;
            }
            if *n == "not" && w.get(i + 1) == Some(&"true") {
                return true;
            }
        }
        return false;
    }
    match f {
        "still" => {
            const OK: &[&str] = &[
                "using", "doing", "showing", "returning", "getting", "adding", "deleting", "ignoring", "touching", "writing",
                "editing", "changing", "failing", "crashing", "erroring", "hanging", "missing", "broken", "wrong", "not", "no",
                "there", "happening", "empty", "blank", "red", "same", "doesn't", "can't", "won't", "fails", "errors",
            ];
            w.get(1).is_some_and(|x| OK.contains(x)) || (w.get(1) == Some(&"the") && w.get(2) == Some(&"same"))
        }
        "nothing" => w.get(1).is_some_and(|x| matches!(*x, "changed" | "happened" | "happens" | "works" | "worked" | "helped" | "builds" | "runs" | "compiles" | "loads" | "is" | "has" | "fixed" | "changes" | "prints" | "shows")) && !w.contains(&"urgent"),
        "same" => w.get(1).is_some_and(|x| matches!(*x, "error" | "problem" | "issue" | "result" | "output" | "mistake" | "thing" | "bug" | "behavior" | "behaviour" | "stack" | "trace" | "stacktrace" | "message" | "failure" | "failures" | "warning" | "warnings" | "errors")),
        // "not fixed", "not working": the whole message is a verdict on the last change.
        "not" => w.len() <= 4 && w.get(1).is_some_and(|x| STATE.contains(x) || matches!(*x, "there" | "done" | "finished" | "solved")),
        // "didnt fix it", "doesnt work": no subject, the agent's last change is understood.
        "didn't" | "doesn't" | "won't" | "isn't" => w.len() <= 5 && w.get(1).is_some_and(|x| STATE.contains(x) && !matches!(*x, "how" | "there")),
        _ => {
            // "the test still fails", "the build still doesnt pass"
            if f != "this" {
                if let Some(k) = w.iter().take(5).position(|x| *x == "still") {
                    if k >= 1 && !w[..k].iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "what" | "is" | "whether" | "while")) && w.get(k + 1).is_some_and(|x| FAIL.contains(x) || NEG.contains(x) || matches!(*x, "there" | "happening" | "shows" | "returns" | "uses" | "prints" | "says" | "hangs" | "leaks" | "points" | "renders" | "contains")) {
                        return true;
                    }
                }
                // "the fix didnt take", "that patch doesnt work"
                if matches!(f, "the" | "your" | "that" | "my") && w.get(1).is_some_and(|x| matches!(*x, "fix" | "change" | "patch" | "solution" | "update" | "edit" | "commit" | "retry" | "workaround" | "suggestion" | "rewrite")) && w.get(2).is_some_and(|x| NEG.contains(x)) && w.get(3).is_some_and(|x| STATE.contains(x) || matches!(*x, "take" | "stick")) {
                    return true;
                }
            }
            // "the page is still blank", "tests are not passing", "the build is still broken"
            const STATE2: &[&str] = &["working", "running", "passing", "fixed", "broken", "failing", "blank", "red", "compiling", "loading", "there", "installed", "empty", "down", "building"];
            for i in 1..w.len().min(5) {
                if f == "this" {
                    break;
                }
                if matches!(w[i], "is" | "are") {
                    let mut j = i + 1;
                    let mut flagged = false;
                    while w.get(j).is_some_and(|x| matches!(*x, "still" | "not" | "also")) {
                        flagged = true;
                        j += 1;
                    }
                    return flagged && w.get(j).is_some_and(|x| STATE2.contains(x)) && !w[..i].iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "what" | "is" | "whether"));
                }
            }
            // "that function doesn't exist", "that endpoint isn't real", "no such flag"
            if matches!(f, "that" | "this") {
                return false;
            }
            has(s, "no such flag") || has(s, "no such option") || has(s, "no such command") || has(s, "no such function")
        }
    }
}

/// "you said it passed but it fails": the user is quoting the agent's claim back.
pub fn quoted_claim(s: &str) -> bool {
    let quoted = has(s, "you said") || has(s, "you told me") || has(s, "you claimed") || has(s, "you promised");
    let against = has(s, "but") || has(s, "yet") || has(s, "actually")
        || ["empty", "nothing", "not", "doesn't", "didn't", "isn't", "fails", "failed", "wrong", "broken", "missing", "no"].iter().any(|x| has(s, x));
    quoted && against && !has(s, "you said yes") && !has(s, "you said it's fine")
}

/// "that function doesn't exist": a demonstrative plus a thing plus a negative existence verb.
pub fn missing_thing(s: &str) -> bool {
    let w = words(s);
    if !matches!(w.first(), Some(&"that") | Some(&"this") | Some(&"there")) || w.len() < 3 {
        return false;
    }
    if w[0] == "there" {
        return w.get(1) == Some(&"is") && w.get(2) == Some(&"no") && w.get(3) == Some(&"such") && matches!(w.get(4), Some(&"flag") | Some(&"option") | Some(&"command") | Some(&"function") | Some(&"method") | Some(&"endpoint") | Some(&"api"));
    }
    w.iter().skip(1).take(3).any(|x| matches!(*x, "doesn't" | "isn't" | "aren't" | "does")) && (w.contains(&"exist") || has(s, "isn't a real") || has(s, "isn't real") || has(s, "not a real"))
}

/// "the server isn't on 3000, it's 8080": the user states what is false and then what is true.
pub fn contrast_fact(s: &str) -> bool {
    let Some(i) = s.find(',') else { return false };
    let (a, b) = (&s[..i], &s[i + 1..]);
    let wa = words(a);
    if wa.len() < 2 || !wa.iter().any(|x| matches!(*x, "isn't" | "aren't" | "wasn't" | "doesn't")) || wa.iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "whether")) {
        return false;
    }
    let wb = words(b);
    matches!(wb.first(), Some(&"it's") | Some(&"its") | Some(&"they're")) && wb.get(1).is_some_and(|x| !matches!(*x, "just" | "only" | "a" | "an" | "fine" | "ok" | "okay" | "not" | "also"))
}

/// An outburst followed by an order or a verdict: "ffs use pnpm", "jesus christ stop rewriting everything",
/// "damn it, wrong branch again". The outburst alone is never enough. Also "that's not the file i said".
pub fn frustrated(s: &str) -> bool {
    const OUTBURST: &[&[&str]] = &[
        &["wtf"], &["ffs"], &["jesus", "christ"], &["jesus"], &["christ"], &["jeez"], &["for", "fucks", "sake"],
        &["for", "fuck's", "sake"], &["for", "fucking", "sake"], &["for", "gods", "sake"], &["damn", "it"], &["dammit"],
        &["goddamn", "it"], &["god", "damn", "it"], &["come", "on"], &["bro"], &["dude"], &["man"], &["omg"], &["ugh"],
        &["what", "the", "hell"], &["what", "the", "fuck"], &["what", "the", "actual", "fuck"], &["holy", "shit"],
        &["oh", "my", "god"], &["fuck", "sake"], &["for", "real"], &["seriously"], &["jesus", "fucking", "christ"],
    ];
    let w = words(s);
    // "that's not the file i said": a verdict on the agent's pick, quoting the user's own instruction.
    const VERDICT: &[&str] = &["that's not", "it's not", "this isn't", "that isn't", "this is not", "that is not"];
    if let Some(p) = VERDICT.iter().filter_map(|v| s.find(v).map(|i| i + v.len())).min() {
        let tail = words(&s[p..]);
        let said = tail.windows(2).any(|p| p[0] == "i" && matches!(p[1], "said" | "asked" | "meant" | "wanted" | "told" | "wrote" | "mentioned"));
        if said && tail.len() <= 9 {
            return true;
        }
    }
    // "ffs the second file, not the first one": an outburst, a thing, then what it should have been.
    if let Some(c) = s.find(", not ") {
        let head = words(&s[..c]);
        let tail = words(&s[c + 6..]);
        let outburst = head.first().is_some_and(|x| matches!(*x, "ffs" | "wtf" | "jesus" | "christ" | "goddamn" | "dude" | "bro" | "damn" | "ugh" | "omg"));
        if outburst && head.len() >= 3 && tail.first().is_some_and(|x| matches!(*x, "the" | "a" | "an" | "that" | "this" | "those" | "it")) {
            return true;
        }
    }
    let mut i = 0;
    let mut loud = false;
    while i < w.len() && i < 8 {
        let hit = OUTBURST.iter().find(|p| w[i..].starts_with(p));
        match hit {
            Some(p) => {
                loud |= !matches!(p[0], "seriously" | "man" | "bro" | "dude" | "ugh" | "omg" | "come");
                i += p.len();
            }
            None if matches!(w[i], "the" | "hell" | "fuck" | "fucking" | "shit" | "ok" | "okay" | "hey" | "oh" | "please" | "just") && i > 0 => i += 1,
            None => break,
        }
    }
    if i == 0 || !loud {
        return false;
    }
    let rest = &w[i..];
    let Some(&first) = rest.first() else { return false };
    if matches!(first, "stop" | "quit") {
        return rest.get(1).is_some_and(|x| x.len() > 4 && x.ends_with("ing") || matches!(*x, "it" | "that" | "this"));
    }
    if first == "wrong" || first == "you" {
        return true;
    }
    super::LEAD_VERBS.contains(&first) && rest.len() >= 2
}

/// "once again, the tests live in tests/", "this is the third time", "same thing as before".
pub fn repeat(s: &str) -> bool {
    const PHRASES: &[&str] = &[
        "this is the second time", "this is the third time", "this is the fourth time", "this is the fifth time",
        "the third time", "the fourth time", "the fifth time", "twice now", "third time", "fourth time", "same mistake",
        "same thing as before", "same thing again", "same error again", "you keep", "keep doing this", "you never listen",
        "you don't listen", "you're not listening", "not listening", "have to repeat", "told you already", "i said this",
        "i've said this", "i have said this", "said this three times", "read my message", "read it again", "read again",
        "i just said that", "i literally just said", "i literally said", "i already said", "i already told you", "what i said",
        "that's what i said", "that is what i said", "we went over this", "i said it", "you forgot again", "again??",
        "doing it again", "doing that again", "did it again", "did that again", "did this again", "done it again", "at it again",
        "doing this again", "every single time", "twice already", "done this twice", "done this before", "already said",
        "said already", "already told you", "you've done this", "you have done this", "second time now", "told you twice",
        "told you before", "told you earlier", "i told you", "said it twice", "tell you again", "telling you again", "already covered", "covered this", "we covered", "we talked about", "we discussed",
    ];
    if PHRASES.iter().any(|p| has(s, p)) {
        return !has(s, "you keep the") && !has(s, "keep it") && !has(s, "you keep me");
    }
    let w = words(s);
    // "this is the 4th time", "for the nth time": the count is the complaint.
    let ordinal = |x: &str| {
        matches!(x, "nth" | "umpteenth" | "hundredth" | "tenth" | "sixth" | "seventh" | "eighth" | "ninth")
            || (x.len() >= 3 && x.as_bytes()[..x.len() - 2].iter().all(u8::is_ascii_digit) && matches!(&x.as_bytes()[x.len() - 2..], b"st" | b"nd" | b"rd" | b"th"))
    };
    if w.windows(2).any(|p| ordinal(p[0]) && p[1] == "time") {
        return true;
    }
    // "please read the task again": the instructions were already given.
    if w.len() <= 8 && w.contains(&"again") && w.iter().any(|x| matches!(*x, "read" | "reread")) && w.iter().any(|x| matches!(*x, "task" | "prompt" | "message" | "instructions" | "request" | "question" | "brief" | "spec" | "ticket" | "ask" | "rules")) {
        return !matches!(w[0], "can" | "could" | "would");
    }
    // "told you to leave the lockfile": the "i" is dropped when typing fast.
    (starts(s, "told you") && !has(s, "so")) || (starts(s, "once again") && !has(s, "thanks") && !has(s, "thank"))
}

/// "nope", "no, use pnpm", "nah the port is 8080": an opening refusal followed by anything that is not calm,
/// a question or a polite brush-off. `NOT_CORRECTIONS` has already been checked by the caller.
pub fn hard_no(s: &str) -> bool {
    let mut t = s.trim_start();
    // "uh no, ...", "ok no ...", "dude no": a small word in front of the refusal.
    for _ in 0..2 {
        let lead: String = t.chars().take_while(|c| c.is_alphabetic()).collect();
        if matches!(lead.as_str(), "uh" | "um" | "hm" | "hmm" | "ok" | "okay" | "well" | "so" | "oh" | "ah" | "ahh" | "eh" | "yeah" | "yea" | "hey" | "hell" | "dude" | "bro" | "man" | "ugh" | "wait" | "bruh" | "lol") {
            t = t[lead.len()..].trim_start_matches(|c: char| c == ',' || c == '.' || c.is_whitespace());
        }
    }
    if super::NOT_CORRECTIONS.iter().any(|p| starts(t, p)) {
        return false;
    }
    let w0: String = t.chars().take_while(|c| c.is_alphanumeric() || *c == '\'').collect();
    let is_no = matches!(w0.as_str(), "no" | "nope" | "nah" | "nop" | "naw") || (w0.len() >= 3 && w0.starts_with("no") && w0.chars().all(|c| c == 'n' || c == 'o'));
    if !is_no {
        return false;
    }
    let after = &t[w0.len()..];
    let rest = after.trim_start_matches(|c: char| c == ',' || c == '.' || c == '-' || c == ':' || c == '!' || c.is_whitespace());
    let punct = after.starts_with(|c: char| matches!(c, ',' | '.' | '-' | ':' | '!'));
    if rest.is_empty() {
        return true;
    }
    let rw = words(rest);
    let Some(&first) = rw.first() else { return true };
    if !punct {
        // "no use pnpm", "no that's wrong": a plain word after the no must be a verb or a pronoun that carries a verdict.
        const FOLLOW: &[&str] = &[
            "that", "that's", "this", "it", "it's", "its", "we", "i", "you", "they", "the", "don't", "do", "not", "stop", "wait",
            "wrong", "actually", "never", "always", "only", "other", "no", "nope", "keep", "use", "put", "run", "call", "make",
            "revert", "undo", "go", "switch", "try", "read", "look", "check", "set", "move", "rename", "change", "open", "write",
            "name", "store", "place", "save", "add", "delete", "remove", "pick", "choose", "follow", "install", "build", "test",
            "start", "update", "fix", "create", "edit", "leave",
        ];
        if !FOLLOW.contains(&first) {
            return false;
        }
    }
    if matches!(first, "can" | "could" | "would" | "will" | "is" | "are" | "was" | "were" | "does" | "did" | "how" | "what" | "why" | "which" | "where" | "when" | "who" | "should" | "shall" | "have" | "has" | "am" | "isn't" | "aren't" | "wasn't") && first != "do" {
        return false;
    }
    const CALM: &[&str] = &[
        "fine", "good", "ok", "okay", "great", "perfect", "thanks", "thank", "works", "lgtm", "nice", "awesome", "worries",
        "problem", "rush", "hurry", "matter", "idea", "yet", "later", "sure", "welcome", "excellent", "cool", "sweet", "love",
        "nothing", "nevermind", "wait", "please",
    ];
    // "wait" and "please" only calm the line when they open it ("no, wait for the build"); keep the plain test simple.
    !rw.iter().any(|x| CALM.contains(x) && !matches!(*x, "wait" | "please" | "later" | "nothing" | "sure"))
        && !(matches!(first, "wait" | "please" | "later" | "nothing" | "sure"))
        && !(first == "i" && matches!(rw.get(1), Some(&"don't") | Some(&"dont") | Some(&"was") | Some(&"am") | Some(&"have") | Some(&"haven't") | Some(&"can't") | Some(&"think") | Some(&"guess") | Some(&"meant") | Some(&"mean")))
}