🐛 Window: the "context N% full" badge goes once the history shrinks (#269)
The badge kept saying "context 85% full" after a /compact that compressed, /new or /resume, against the header's ctx figure. The context warning is now marked (ui.Struggle.Context) and dropped alone when the history shrinks; a severe badge still stays until the next question. Tests, docs EN+FR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0d61ace parent: 5e82ddd modified
.tickets/issues/0269-window-the-context-full-badge-stays-after-a-compression.yaml +43 -11 | @@ -1,12 +1,13 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 269 |
| 3 | 3 | title: "Window: the \"context N% full\" badge stays after /compact (and /new, /resume)" |
| 4 | -state: open | |
| 4 | +state: closed | |
| 5 | 5 | author: |
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-27T01:00:00.000Z |
| 9 | -updatedAt: 2026-11-27T01:00:00.000Z | |
| 9 | +updatedAt: 2026-11-27T02:30:00.000Z | |
| 10 | +closedAt: 2026-11-27T02:30:00.000Z | |
| 10 | 11 | labels: |
| 11 | 12 | - bug |
| 12 | 13 | - kind::bug |
| @@ -56,38 +57,69 @@ body: | | ||
| 56 | 57 | tasks: |
| 57 | 58 | - id: 1 |
| 58 | 59 | title: "ui.Struggle: mark the context struggle; tui struggles: keep the list, forget the context one" |
| 59 | - state: open | |
| 60 | + state: closed | |
| 60 | 61 | priority: medium |
| 61 | 62 | author: |
| 62 | 63 | name: k33g |
| 63 | 64 | email: ph.charriere@gmail.com |
| 64 | 65 | createdAt: 2026-11-27T01:00:00.000Z |
| 65 | - updatedAt: 2026-11-27T01:00:00.000Z | |
| 66 | + updatedAt: 2026-11-27T02:00:00.000Z | |
| 67 | + closedAt: 2026-11-27T02:00:00.000Z | |
| 66 | 68 | - id: 2 |
| 67 | 69 | title: "Clear it after /compact (compressed), /new, /resume — with tests" |
| 68 | - state: open | |
| 70 | + state: closed | |
| 69 | 71 | priority: medium |
| 70 | 72 | author: |
| 71 | 73 | name: k33g |
| 72 | 74 | email: ph.charriere@gmail.com |
| 73 | 75 | createdAt: 2026-11-27T01:00:00.000Z |
| 74 | - updatedAt: 2026-11-27T01:00:00.000Z | |
| 76 | + updatedAt: 2026-11-27T02:00:00.000Z | |
| 77 | + closedAt: 2026-11-27T02:00:00.000Z | |
| 75 | 78 | - id: 3 |
| 76 | 79 | title: "Check ACP (does the editor keep the warning?) and the line mode" |
| 77 | - state: open | |
| 80 | + state: closed | |
| 78 | 81 | priority: low |
| 79 | 82 | author: |
| 80 | 83 | name: k33g |
| 81 | 84 | email: ph.charriere@gmail.com |
| 82 | 85 | createdAt: 2026-11-27T01:00:00.000Z |
| 83 | - updatedAt: 2026-11-27T01:00:00.000Z | |
| 86 | + updatedAt: 2026-11-27T02:00:00.000Z | |
| 87 | + closedAt: 2026-11-27T02:00:00.000Z | |
| 84 | 88 | - id: 4 |
| 85 | 89 | title: "Docs EN+FR: when the context badge goes" |
| 86 | - state: open | |
| 90 | + state: closed | |
| 87 | 91 | priority: low |
| 88 | 92 | author: |
| 89 | 93 | name: k33g |
| 90 | 94 | email: ph.charriere@gmail.com |
| 91 | 95 | createdAt: 2026-11-27T01:00:00.000Z |
| 92 | - updatedAt: 2026-11-27T01:00:00.000Z | |
| 93 | -comments: [] | |
| 96 | + updatedAt: 2026-11-27T02:00:00.000Z | |
| 97 | + closedAt: 2026-11-27T02:00:00.000Z | |
| 98 | +comments: | |
| 99 | + - id: 1 | |
| 100 | + author: | |
| 101 | + name: k33g | |
| 102 | + email: ph.charriere@gmail.com | |
| 103 | + createdAt: 2026-11-27T02:00:00.000Z | |
| 104 | + body: | | |
| 105 | + Done on branch feature/context-badge (not merged yet): | |
| 106 | + - internal/ui: `Struggle.Context` marks the context warning; | |
| 107 | + engine/struggle.go `contextStruggle` sets it. | |
| 108 | + - internal/tui/struggle.go: `struggles` keeps the list (not only the | |
| 109 | + worst + a count), `forgetContext()` drops the context ones, `badge()` | |
| 110 | + recomputes the worst with the same rule as before (severe beats a | |
| 111 | + warning, the latest of a level wins). | |
| 112 | + - Called after a /compact that compressed (turn.go apply, outcome | |
| 113 | + "compact" changed), /new and /resume (commands.go). A failed or | |
| 114 | + empty /compact keeps it. The automatic compaction at a question's | |
| 115 | + start needed nothing (startTurn clears the badge). | |
| 116 | + - ACP: the warning is a line of the agent's message at the moment it | |
| 117 | + happens, nothing stays — nothing to do. Line mode: a printed line, | |
| 118 | + nothing stays — nothing to do. | |
| 119 | + - Tests: internal/tui/contextbadge_test.go (forgetContext keeps the | |
| 120 | + others; /compact compressed vs failed vs nothing; /new, /resume; | |
| 121 | + the real /compact path through the sink); the engine test now | |
| 122 | + expects `Context: true`. go test ./..., vet, gofmt clean. | |
| 123 | + - Docs EN+FR: reference/cli.md struggle signals (Window row), | |
| 124 | + explanation/struggling-models.md. | |
| 125 | + - Not tried live in the window (no terminal in the sandbox). | |
| @@ -1,12 +1,13 @@ | |||
| 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | id: 269 | 2 | id: 269 |
| 3 | title: "Window: the \"context N% full\" badge stays after /compact (and /new, /resume)" | 3 | title: "Window: the \"context N% full\" badge stays after /compact (and /new, /resume)" |
| 4 | -state: open | 4 | +state: closed |
| 5 | author: | 5 | author: |
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-27T01:00:00.000Z | 8 | createdAt: 2026-11-27T01:00:00.000Z |
| 9 | -updatedAt: 2026-11-27T01:00:00.000Z | 9 | +updatedAt: 2026-11-27T02:30:00.000Z |
| 10 | +closedAt: 2026-11-27T02:30:00.000Z | ||
| 10 | labels: | 11 | labels: |
| 11 | - bug | 12 | - bug |
| 12 | - kind::bug | 13 | - kind::bug |
| @@ -56,38 +57,69 @@ body: | | |||
| 56 | tasks: | 57 | tasks: |
| 57 | - id: 1 | 58 | - id: 1 |
| 58 | title: "ui.Struggle: mark the context struggle; tui struggles: keep the list, forget the context one" | 59 | title: "ui.Struggle: mark the context struggle; tui struggles: keep the list, forget the context one" |
| 59 | - state: open | 60 | + state: closed |
| 60 | priority: medium | 61 | priority: medium |
| 61 | author: | 62 | author: |
| 62 | name: k33g | 63 | name: k33g |
| 63 | email: ph.charriere@gmail.com | 64 | email: ph.charriere@gmail.com |
| 64 | createdAt: 2026-11-27T01:00:00.000Z | 65 | createdAt: 2026-11-27T01:00:00.000Z |
| 65 | - updatedAt: 2026-11-27T01:00:00.000Z | 66 | + updatedAt: 2026-11-27T02:00:00.000Z |
| 67 | + closedAt: 2026-11-27T02:00:00.000Z | ||
| 66 | - id: 2 | 68 | - id: 2 |
| 67 | title: "Clear it after /compact (compressed), /new, /resume — with tests" | 69 | title: "Clear it after /compact (compressed), /new, /resume — with tests" |
| 68 | - state: open | 70 | + state: closed |
| 69 | priority: medium | 71 | priority: medium |
| 70 | author: | 72 | author: |
| 71 | name: k33g | 73 | name: k33g |
| 72 | email: ph.charriere@gmail.com | 74 | email: ph.charriere@gmail.com |
| 73 | createdAt: 2026-11-27T01:00:00.000Z | 75 | createdAt: 2026-11-27T01:00:00.000Z |
| 74 | - updatedAt: 2026-11-27T01:00:00.000Z | 76 | + updatedAt: 2026-11-27T02:00:00.000Z |
| 77 | + closedAt: 2026-11-27T02:00:00.000Z | ||
| 75 | - id: 3 | 78 | - id: 3 |
| 76 | title: "Check ACP (does the editor keep the warning?) and the line mode" | 79 | title: "Check ACP (does the editor keep the warning?) and the line mode" |
| 77 | - state: open | 80 | + state: closed |
| 78 | priority: low | 81 | priority: low |
| 79 | author: | 82 | author: |
| 80 | name: k33g | 83 | name: k33g |
| 81 | email: ph.charriere@gmail.com | 84 | email: ph.charriere@gmail.com |
| 82 | createdAt: 2026-11-27T01:00:00.000Z | 85 | createdAt: 2026-11-27T01:00:00.000Z |
| 83 | - updatedAt: 2026-11-27T01:00:00.000Z | 86 | + updatedAt: 2026-11-27T02:00:00.000Z |
| 87 | + closedAt: 2026-11-27T02:00:00.000Z | ||
| 84 | - id: 4 | 88 | - id: 4 |
| 85 | title: "Docs EN+FR: when the context badge goes" | 89 | title: "Docs EN+FR: when the context badge goes" |
| 86 | - state: open | 90 | + state: closed |
| 87 | priority: low | 91 | priority: low |
| 88 | author: | 92 | author: |
| 89 | name: k33g | 93 | name: k33g |
| 90 | email: ph.charriere@gmail.com | 94 | email: ph.charriere@gmail.com |
| 91 | createdAt: 2026-11-27T01:00:00.000Z | 95 | createdAt: 2026-11-27T01:00:00.000Z |
| 92 | - updatedAt: 2026-11-27T01:00:00.000Z | 96 | + updatedAt: 2026-11-27T02:00:00.000Z |
| 93 | -comments: [] | 97 | + closedAt: 2026-11-27T02:00:00.000Z |
| 98 | +comments: | ||
| 99 | + - id: 1 | ||
| 100 | + author: | ||
| 101 | + name: k33g | ||
| 102 | + email: ph.charriere@gmail.com | ||
| 103 | + createdAt: 2026-11-27T02:00:00.000Z | ||
| 104 | + body: | | ||
| 105 | + Done on branch feature/context-badge (not merged yet): | ||
| 106 | + - internal/ui: `Struggle.Context` marks the context warning; | ||
| 107 | + engine/struggle.go `contextStruggle` sets it. | ||
| 108 | + - internal/tui/struggle.go: `struggles` keeps the list (not only the | ||
| 109 | + worst + a count), `forgetContext()` drops the context ones, `badge()` | ||
| 110 | + recomputes the worst with the same rule as before (severe beats a | ||
| 111 | + warning, the latest of a level wins). | ||
| 112 | + - Called after a /compact that compressed (turn.go apply, outcome | ||
| 113 | + "compact" changed), /new and /resume (commands.go). A failed or | ||
| 114 | + empty /compact keeps it. The automatic compaction at a question's | ||
| 115 | + start needed nothing (startTurn clears the badge). | ||
| 116 | + - ACP: the warning is a line of the agent's message at the moment it | ||
| 117 | + happens, nothing stays — nothing to do. Line mode: a printed line, | ||
| 118 | + nothing stays — nothing to do. | ||
| 119 | + - Tests: internal/tui/contextbadge_test.go (forgetContext keeps the | ||
| 120 | + others; /compact compressed vs failed vs nothing; /new, /resume; | ||
| 121 | + the real /compact path through the sink); the engine test now | ||
| 122 | + expects `Context: true`. go test ./..., vet, gofmt clean. | ||
| 123 | + - Docs EN+FR: reference/cli.md struggle signals (Window row), | ||
| 124 | + explanation/struggling-models.md. | ||
| 125 | + - Not tried live in the window (no terminal in the sandbox). | ||
modified
docs/en/explanation/struggling-models.md +1 -1 | @@ -14,7 +14,7 @@ Struggle signals (ticket 153) make the same detections visible to the **user**, | ||
| 14 | 14 | |
| 15 | 15 | **One event, three renderings**, as for everything else in `mm` ([architecture](architecture.md)): the window keeps the worst struggle of the turn as a badge in the status bar; the line mode prints a coloured line when it happens; an editor gets a short italic paragraph signed `mm` in the agent's message, because it has no status bar of ours. |
| 16 | 16 | |
| 17 | -**In the window, the status bar, until the next question.** The badge sits on the right of the bottom bar, in the version's place: the version is the least useful thing there while something is wrong, and the key hints on the left — `Ctrl-C quit` above all, the way out of a turn that will not stop — keep their room. It outlives the turn on purpose: once a turn ended badly, the badge says why, and it goes when the next question starts a new turn. A severe signal beats a warning; between two of the same level the latest wins, so `loop: bash ×4` replaces `×3`; `(+N)` counts the others. | |
| 17 | +**In the window, the status bar, until the next question.** The badge sits on the right of the bottom bar, in the version's place: the version is the least useful thing there while something is wrong, and the key hints on the left — `Ctrl-C quit` above all, the way out of a turn that will not stop — keep their room. It outlives the turn on purpose: once a turn ended badly, the badge says why, and it goes when the next question starts a new turn. One exception: `context N% full` describes the history, not how the turn went, so it goes as soon as the history shrinks — a `/compact` that compressed, `/new`, `/resume` — while a `looped — stopped` beside it stays (ticket 269); a badge saying 85 % over a history just compressed would contradict the header's `ctx` figure. A severe signal beats a warning; between two of the same level the latest wins, so `loop: bash ×4` replaces `×3`; `(+N)` counts the others. | |
| 18 | 18 | |
| 19 | 19 | **Failures in a row, not only repeats** (ticket 160). The loop detector needs the same call with the same result; a model that tries `cat config.yml`, then `cat conf/config.yml`, then `cat config.yaml` and fails each time is struggling just as much. Whether a call failed is only known inside each tool, so every tool now hands its outcome to the detector with the call (`record`, `recordFailure`, `recordOutcome`); the detector, which already sees every call, counts the failures in a row and reports `failing: N tool calls in a row` from the third. It is a warning only: the model reads each failure in the tool's output already, and a hard stop would end turns that a fourth attempt would have saved. |
| 20 | 20 | |
| @@ -14,7 +14,7 @@ Struggle signals (ticket 153) make the same detections visible to the **user**, | |||
| 14 | 14 | ||
| 15 | **One event, three renderings**, as for everything else in `mm` ([architecture](architecture.md)): the window keeps the worst struggle of the turn as a badge in the status bar; the line mode prints a coloured line when it happens; an editor gets a short italic paragraph signed `mm` in the agent's message, because it has no status bar of ours. | 15 | **One event, three renderings**, as for everything else in `mm` ([architecture](architecture.md)): the window keeps the worst struggle of the turn as a badge in the status bar; the line mode prints a coloured line when it happens; an editor gets a short italic paragraph signed `mm` in the agent's message, because it has no status bar of ours. |
| 16 | 16 | ||
| 17 | -**In the window, the status bar, until the next question.** The badge sits on the right of the bottom bar, in the version's place: the version is the least useful thing there while something is wrong, and the key hints on the left — `Ctrl-C quit` above all, the way out of a turn that will not stop — keep their room. It outlives the turn on purpose: once a turn ended badly, the badge says why, and it goes when the next question starts a new turn. A severe signal beats a warning; between two of the same level the latest wins, so `loop: bash ×4` replaces `×3`; `(+N)` counts the others. | 17 | +**In the window, the status bar, until the next question.** The badge sits on the right of the bottom bar, in the version's place: the version is the least useful thing there while something is wrong, and the key hints on the left — `Ctrl-C quit` above all, the way out of a turn that will not stop — keep their room. It outlives the turn on purpose: once a turn ended badly, the badge says why, and it goes when the next question starts a new turn. One exception: `context N% full` describes the history, not how the turn went, so it goes as soon as the history shrinks — a `/compact` that compressed, `/new`, `/resume` — while a `looped — stopped` beside it stays (ticket 269); a badge saying 85 % over a history just compressed would contradict the header's `ctx` figure. A severe signal beats a warning; between two of the same level the latest wins, so `loop: bash ×4` replaces `×3`; `(+N)` counts the others. |
| 18 | 18 | ||
| 19 | **Failures in a row, not only repeats** (ticket 160). The loop detector needs the same call with the same result; a model that tries `cat config.yml`, then `cat conf/config.yml`, then `cat config.yaml` and fails each time is struggling just as much. Whether a call failed is only known inside each tool, so every tool now hands its outcome to the detector with the call (`record`, `recordFailure`, `recordOutcome`); the detector, which already sees every call, counts the failures in a row and reports `failing: N tool calls in a row` from the third. It is a warning only: the model reads each failure in the tool's output already, and a hard stop would end turns that a fourth attempt would have saved. | 19 | **Failures in a row, not only repeats** (ticket 160). The loop detector needs the same call with the same result; a model that tries `cat config.yml`, then `cat conf/config.yml`, then `cat config.yaml` and fails each time is struggling just as much. Whether a call failed is only known inside each tool, so every tool now hands its outcome to the detector with the call (`record`, `recordFailure`, `recordOutcome`); the detector, which already sees every call, counts the failures in a row and reports `failing: N tool calls in a row` from the third. It is a warning only: the model reads each failure in the tool's output already, and a hard stop would end turns that a fourth attempt would have saved. |
| 20 | 20 | ||
modified
docs/en/reference/cli.md +1 -1 | @@ -226,7 +226,7 @@ A turn cancelled by the user reports nothing. `demos/struggle-signals/` triggers | ||
| 226 | 226 | |
| 227 | 227 | | Front end | Shown as | |
| 228 | 228 | |-----------|----------| |
| 229 | -| Window | A badge on the right of the status bar, in front of the duration and the counters (the version gives way): black on yellow for `⚠`, white on red for `✖`. The worst of the turn, with `(+N)` for the others; a severe signal beats a warning, the latest of the same level wins. It stays after the turn and goes when the next question is sent. | | |
| 229 | +| Window | A badge on the right of the status bar, in front of the duration and the counters (the version gives way): black on yellow for `⚠`, white on red for `✖`. The worst of the turn, with `(+N)` for the others; a severe signal beats a warning, the latest of the same level wins. It stays after the turn and goes when the next question is sent. `context N% full` goes sooner, alone, as soon as the history shrinks: a `/compact` that compressed, `/new`, `/resume` — the other signals of the turn stay. | | |
| 230 | 230 | | Line mode, `-p` | One line `⚠ <signal>` / `✖ <signal>` on stdout when it happens: yellow or red on a terminal, plain otherwise. | |
| 231 | 231 | | ACP | A paragraph `*⚠ mm: <signal>*` in the agent's message when it happens; not kept in the history. | |
| 232 | 232 | | `-p` with `structuredOutput` | The plain line, on stderr. | |
| @@ -226,7 +226,7 @@ A turn cancelled by the user reports nothing. `demos/struggle-signals/` triggers | |||
| 226 | 226 | ||
| 227 | | Front end | Shown as | | 227 | | Front end | Shown as | |
| 228 | |-----------|----------| | 228 | |-----------|----------| |
| 229 | -| Window | A badge on the right of the status bar, in front of the duration and the counters (the version gives way): black on yellow for `⚠`, white on red for `✖`. The worst of the turn, with `(+N)` for the others; a severe signal beats a warning, the latest of the same level wins. It stays after the turn and goes when the next question is sent. | | 229 | +| Window | A badge on the right of the status bar, in front of the duration and the counters (the version gives way): black on yellow for `⚠`, white on red for `✖`. The worst of the turn, with `(+N)` for the others; a severe signal beats a warning, the latest of the same level wins. It stays after the turn and goes when the next question is sent. `context N% full` goes sooner, alone, as soon as the history shrinks: a `/compact` that compressed, `/new`, `/resume` — the other signals of the turn stay. | |
| 230 | | Line mode, `-p` | One line `⚠ <signal>` / `✖ <signal>` on stdout when it happens: yellow or red on a terminal, plain otherwise. | | 230 | | Line mode, `-p` | One line `⚠ <signal>` / `✖ <signal>` on stdout when it happens: yellow or red on a terminal, plain otherwise. | |
| 231 | | ACP | A paragraph `*⚠ mm: <signal>*` in the agent's message when it happens; not kept in the history. | | 231 | | ACP | A paragraph `*⚠ mm: <signal>*` in the agent's message when it happens; not kept in the history. | |
| 232 | | `-p` with `structuredOutput` | The plain line, on stderr. | | 232 | | `-p` with `structuredOutput` | The plain line, on stderr. | |
modified
docs/fr/explanation/struggling-models.md +1 -1 | @@ -14,7 +14,7 @@ Les signaux de difficulté (ticket 153) rendent ces mêmes détections visibles | ||
| 14 | 14 | |
| 15 | 15 | **Un événement, trois rendus**, comme tout le reste de `mm` ([architecture](architecture.md)) : la fenêtre garde la difficulté la plus grave du tour en badge dans la barre d'état ; le mode ligne imprime une ligne colorée au moment où elle arrive ; un éditeur reçoit un court paragraphe en italique signé `mm` dans le message de l'agent, faute de barre d'état à nous. |
| 16 | 16 | |
| 17 | -**Dans la fenêtre, la barre d'état, jusqu'à la question suivante.** Le badge se place à droite de la barre du bas, à la place de la version : c'est ce qui sert le moins quand quelque chose ne va pas, et les raccourcis à gauche — `Ctrl-C quit` avant tout, la sortie d'un tour qui ne s'arrête pas — gardent leur place. Il survit au tour exprès : quand un tour finit mal, le badge dit pourquoi, et il disparaît quand la question suivante ouvre un nouveau tour. Un signal grave l'emporte sur un avertissement ; entre deux de même niveau le plus récent gagne, si bien que `loop: bash ×4` remplace `×3` ; `(+N)` compte les autres. | |
| 17 | +**Dans la fenêtre, la barre d'état, jusqu'à la question suivante.** Le badge se place à droite de la barre du bas, à la place de la version : c'est ce qui sert le moins quand quelque chose ne va pas, et les raccourcis à gauche — `Ctrl-C quit` avant tout, la sortie d'un tour qui ne s'arrête pas — gardent leur place. Il survit au tour exprès : quand un tour finit mal, le badge dit pourquoi, et il disparaît quand la question suivante ouvre un nouveau tour. Une exception : `context N% full` décrit l'historique, pas la façon dont le tour s'est passé ; il part donc dès que l'historique rétrécit — un `/compact` qui a compressé, `/new`, `/resume` — tandis qu'un `looped — stopped` à côté de lui reste (ticket 269) ; un badge qui dirait 85 % sur un historique tout juste compressé contredirait le chiffre `ctx` de l'en-tête. Un signal grave l'emporte sur un avertissement ; entre deux de même niveau le plus récent gagne, si bien que `loop: bash ×4` remplace `×3` ; `(+N)` compte les autres. | |
| 18 | 18 | |
| 19 | 19 | **Des échecs d'affilée, pas seulement des répétitions** (ticket 160). Le détecteur de boucles veut le même appel avec le même résultat ; un modèle qui essaie `cat config.yml`, puis `cat conf/config.yml`, puis `cat config.yaml` et échoue à chaque fois peine tout autant. L'échec d'un appel n'est connu qu'à l'intérieur de chaque outil : chaque outil transmet donc maintenant son résultat au détecteur avec l'appel (`record`, `recordFailure`, `recordOutcome`) ; le détecteur, qui voit déjà chaque appel, compte les échecs d'affilée et signale `failing: N tool calls in a row` à partir du troisième. C'est seulement un avertissement : le modèle lit déjà chaque échec dans la sortie de l'outil, et un arrêt brutal couperait des tours qu'un quatrième essai aurait sauvés. |
| 20 | 20 | |
| @@ -14,7 +14,7 @@ Les signaux de difficulté (ticket 153) rendent ces mêmes détections visibles | |||
| 14 | 14 | ||
| 15 | **Un événement, trois rendus**, comme tout le reste de `mm` ([architecture](architecture.md)) : la fenêtre garde la difficulté la plus grave du tour en badge dans la barre d'état ; le mode ligne imprime une ligne colorée au moment où elle arrive ; un éditeur reçoit un court paragraphe en italique signé `mm` dans le message de l'agent, faute de barre d'état à nous. | 15 | **Un événement, trois rendus**, comme tout le reste de `mm` ([architecture](architecture.md)) : la fenêtre garde la difficulté la plus grave du tour en badge dans la barre d'état ; le mode ligne imprime une ligne colorée au moment où elle arrive ; un éditeur reçoit un court paragraphe en italique signé `mm` dans le message de l'agent, faute de barre d'état à nous. |
| 16 | 16 | ||
| 17 | -**Dans la fenêtre, la barre d'état, jusqu'à la question suivante.** Le badge se place à droite de la barre du bas, à la place de la version : c'est ce qui sert le moins quand quelque chose ne va pas, et les raccourcis à gauche — `Ctrl-C quit` avant tout, la sortie d'un tour qui ne s'arrête pas — gardent leur place. Il survit au tour exprès : quand un tour finit mal, le badge dit pourquoi, et il disparaît quand la question suivante ouvre un nouveau tour. Un signal grave l'emporte sur un avertissement ; entre deux de même niveau le plus récent gagne, si bien que `loop: bash ×4` remplace `×3` ; `(+N)` compte les autres. | 17 | +**Dans la fenêtre, la barre d'état, jusqu'à la question suivante.** Le badge se place à droite de la barre du bas, à la place de la version : c'est ce qui sert le moins quand quelque chose ne va pas, et les raccourcis à gauche — `Ctrl-C quit` avant tout, la sortie d'un tour qui ne s'arrête pas — gardent leur place. Il survit au tour exprès : quand un tour finit mal, le badge dit pourquoi, et il disparaît quand la question suivante ouvre un nouveau tour. Une exception : `context N% full` décrit l'historique, pas la façon dont le tour s'est passé ; il part donc dès que l'historique rétrécit — un `/compact` qui a compressé, `/new`, `/resume` — tandis qu'un `looped — stopped` à côté de lui reste (ticket 269) ; un badge qui dirait 85 % sur un historique tout juste compressé contredirait le chiffre `ctx` de l'en-tête. Un signal grave l'emporte sur un avertissement ; entre deux de même niveau le plus récent gagne, si bien que `loop: bash ×4` remplace `×3` ; `(+N)` compte les autres. |
| 18 | 18 | ||
| 19 | **Des échecs d'affilée, pas seulement des répétitions** (ticket 160). Le détecteur de boucles veut le même appel avec le même résultat ; un modèle qui essaie `cat config.yml`, puis `cat conf/config.yml`, puis `cat config.yaml` et échoue à chaque fois peine tout autant. L'échec d'un appel n'est connu qu'à l'intérieur de chaque outil : chaque outil transmet donc maintenant son résultat au détecteur avec l'appel (`record`, `recordFailure`, `recordOutcome`) ; le détecteur, qui voit déjà chaque appel, compte les échecs d'affilée et signale `failing: N tool calls in a row` à partir du troisième. C'est seulement un avertissement : le modèle lit déjà chaque échec dans la sortie de l'outil, et un arrêt brutal couperait des tours qu'un quatrième essai aurait sauvés. | 19 | **Des échecs d'affilée, pas seulement des répétitions** (ticket 160). Le détecteur de boucles veut le même appel avec le même résultat ; un modèle qui essaie `cat config.yml`, puis `cat conf/config.yml`, puis `cat config.yaml` et échoue à chaque fois peine tout autant. L'échec d'un appel n'est connu qu'à l'intérieur de chaque outil : chaque outil transmet donc maintenant son résultat au détecteur avec l'appel (`record`, `recordFailure`, `recordOutcome`) ; le détecteur, qui voit déjà chaque appel, compte les échecs d'affilée et signale `failing: N tool calls in a row` à partir du troisième. C'est seulement un avertissement : le modèle lit déjà chaque échec dans la sortie de l'outil, et un arrêt brutal couperait des tours qu'un quatrième essai aurait sauvés. |
| 20 | 20 | ||
modified
docs/fr/reference/cli.md +1 -1 | @@ -226,7 +226,7 @@ Un tour annulé par l'utilisateur ne signale rien. `demos/struggle-signals/` dé | ||
| 226 | 226 | |
| 227 | 227 | | Front end | Affiché comme | |
| 228 | 228 | |-----------|---------------| |
| 229 | -| Fenêtre | Un badge à droite de la barre d'état, devant la durée et les compteurs (la version s'efface) : noir sur jaune pour `⚠`, blanc sur rouge pour `✖`. Le plus grave du tour, avec `(+N)` pour les autres ; un signal grave l'emporte sur un avertissement, le plus récent d'un même niveau gagne. Il reste après le tour et disparaît quand la question suivante est envoyée. | | |
| 229 | +| Fenêtre | Un badge à droite de la barre d'état, devant la durée et les compteurs (la version s'efface) : noir sur jaune pour `⚠`, blanc sur rouge pour `✖`. Le plus grave du tour, avec `(+N)` pour les autres ; un signal grave l'emporte sur un avertissement, le plus récent d'un même niveau gagne. Il reste après le tour et disparaît quand la question suivante est envoyée. `context N% full` part plus tôt, seul, dès que l'historique rétrécit : un `/compact` qui a compressé, `/new`, `/resume` — les autres signaux du tour restent. | | |
| 230 | 230 | | Mode ligne, `-p` | Une ligne `⚠ <signal>` / `✖ <signal>` sur stdout au moment où il arrive : jaune ou rouge dans un terminal, sans couleur sinon. | |
| 231 | 231 | | ACP | Un paragraphe `*⚠ mm: <signal>*` dans le message de l'agent au moment où il arrive ; pas gardé dans l'historique. | |
| 232 | 232 | | `-p` avec `structuredOutput` | La ligne sans couleur, sur stderr. | |
| @@ -226,7 +226,7 @@ Un tour annulé par l'utilisateur ne signale rien. `demos/struggle-signals/` dé | |||
| 226 | 226 | ||
| 227 | | Front end | Affiché comme | | 227 | | Front end | Affiché comme | |
| 228 | |-----------|---------------| | 228 | |-----------|---------------| |
| 229 | -| Fenêtre | Un badge à droite de la barre d'état, devant la durée et les compteurs (la version s'efface) : noir sur jaune pour `⚠`, blanc sur rouge pour `✖`. Le plus grave du tour, avec `(+N)` pour les autres ; un signal grave l'emporte sur un avertissement, le plus récent d'un même niveau gagne. Il reste après le tour et disparaît quand la question suivante est envoyée. | | 229 | +| Fenêtre | Un badge à droite de la barre d'état, devant la durée et les compteurs (la version s'efface) : noir sur jaune pour `⚠`, blanc sur rouge pour `✖`. Le plus grave du tour, avec `(+N)` pour les autres ; un signal grave l'emporte sur un avertissement, le plus récent d'un même niveau gagne. Il reste après le tour et disparaît quand la question suivante est envoyée. `context N% full` part plus tôt, seul, dès que l'historique rétrécit : un `/compact` qui a compressé, `/new`, `/resume` — les autres signaux du tour restent. | |
| 230 | | Mode ligne, `-p` | Une ligne `⚠ <signal>` / `✖ <signal>` sur stdout au moment où il arrive : jaune ou rouge dans un terminal, sans couleur sinon. | | 230 | | Mode ligne, `-p` | Une ligne `⚠ <signal>` / `✖ <signal>` sur stdout au moment où il arrive : jaune ou rouge dans un terminal, sans couleur sinon. | |
| 231 | | ACP | Un paragraphe `*⚠ mm: <signal>*` dans le message de l'agent au moment où il arrive ; pas gardé dans l'historique. | | 231 | | ACP | Un paragraphe `*⚠ mm: <signal>*` dans le message de l'agent au moment où il arrive ; pas gardé dans l'historique. | |
| 232 | | `-p` avec `structuredOutput` | La ligne sans couleur, sur stderr. | | 232 | | `-p` avec `structuredOutput` | La ligne sans couleur, sur stderr. | |
modified
internal/engine/struggle.go +1 -1 | @@ -105,7 +105,7 @@ func contextStruggle(used, window int) (ui.Struggle, bool) { | ||
| 105 | 105 | if window <= 0 || used*100 < window*contextFullShare { |
| 106 | 106 | return ui.Struggle{}, false |
| 107 | 107 | } |
| 108 | - return ui.Struggle{Label: fmt.Sprintf("context %d%% full", used*100/window)}, true | |
| 108 | + return ui.Struggle{Label: fmt.Sprintf("context %d%% full", used*100/window), Context: true}, true | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // answerStruggle reports an answer that looped (ticket 235) or that was cut |
| @@ -105,7 +105,7 @@ func contextStruggle(used, window int) (ui.Struggle, bool) { | |||
| 105 | if window <= 0 || used*100 < window*contextFullShare { | 105 | if window <= 0 || used*100 < window*contextFullShare { |
| 106 | return ui.Struggle{}, false | 106 | return ui.Struggle{}, false |
| 107 | } | 107 | } |
| 108 | - return ui.Struggle{Label: fmt.Sprintf("context %d%% full", used*100/window)}, true | 108 | + return ui.Struggle{Label: fmt.Sprintf("context %d%% full", used*100/window), Context: true}, true |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | // answerStruggle reports an answer that looped (ticket 235) or that was cut | 111 | // answerStruggle reports an answer that looped (ticket 235) or that was cut |
modified
internal/engine/struggle_test.go +1 -1 | @@ -44,7 +44,7 @@ func TestContextStruggleWarnsFromEightyPercent(t *testing.T) { | ||
| 44 | 44 | if _, ok := contextStruggle(25599, 32000); ok { |
| 45 | 45 | t.Error("79.9 % reported") |
| 46 | 46 | } |
| 47 | - if s, ok := contextStruggle(25600, 32000); !ok || s != (ui.Struggle{Label: "context 80% full"}) { | |
| 47 | + if s, ok := contextStruggle(25600, 32000); !ok || s != (ui.Struggle{Label: "context 80% full", Context: true}) { | |
| 48 | 48 | t.Errorf("80 %% = %+v, %v", s, ok) |
| 49 | 49 | } |
| 50 | 50 | if _, ok := contextStruggle(90000, 0); ok { |
| @@ -44,7 +44,7 @@ func TestContextStruggleWarnsFromEightyPercent(t *testing.T) { | |||
| 44 | if _, ok := contextStruggle(25599, 32000); ok { | 44 | if _, ok := contextStruggle(25599, 32000); ok { |
| 45 | t.Error("79.9 % reported") | 45 | t.Error("79.9 % reported") |
| 46 | } | 46 | } |
| 47 | - if s, ok := contextStruggle(25600, 32000); !ok || s != (ui.Struggle{Label: "context 80% full"}) { | 47 | + if s, ok := contextStruggle(25600, 32000); !ok || s != (ui.Struggle{Label: "context 80% full", Context: true}) { |
| 48 | t.Errorf("80 %% = %+v, %v", s, ok) | 48 | t.Errorf("80 %% = %+v, %v", s, ok) |
| 49 | } | 49 | } |
| 50 | if _, ok := contextStruggle(90000, 0); ok { | 50 | if _, ok := contextStruggle(90000, 0); ok { |
modified
internal/tui/commands.go +2 -0 | @@ -226,6 +226,7 @@ func (r *runner) newSession() { | ||
| 226 | 226 | forgotten := session.Forgotten(r.messages) |
| 227 | 227 | r.messages = session.Fresh(agentsmd.System(r.opts.System, r.opts.Cwd)) |
| 228 | 228 | r.opts.Model.ForgetInputTokens() |
| 229 | + r.struggles.forgetContext() // ticket 269 | |
| 229 | 230 | r.opts.Detector.Reset() |
| 230 | 231 | r.keep.Renew() |
| 231 | 232 | tools.ClearPlans("") // plans belong to the conversation just closed (ticket 109) |
| @@ -244,5 +245,6 @@ func (r *runner) resume(id string) { | ||
| 244 | 245 | tools.ClearPlans("") // the plans in memory were the previous conversation's |
| 245 | 246 | r.opts.Detector.Reset() |
| 246 | 247 | r.opts.Model.ForgetInputTokens() |
| 248 | + r.struggles.forgetContext() // ticket 269 | |
| 247 | 249 | r.t.Notice(line) |
| 248 | 250 | } |
| @@ -226,6 +226,7 @@ func (r *runner) newSession() { | |||
| 226 | forgotten := session.Forgotten(r.messages) | 226 | forgotten := session.Forgotten(r.messages) |
| 227 | r.messages = session.Fresh(agentsmd.System(r.opts.System, r.opts.Cwd)) | 227 | r.messages = session.Fresh(agentsmd.System(r.opts.System, r.opts.Cwd)) |
| 228 | r.opts.Model.ForgetInputTokens() | 228 | r.opts.Model.ForgetInputTokens() |
| 229 | + r.struggles.forgetContext() // ticket 269 | ||
| 229 | r.opts.Detector.Reset() | 230 | r.opts.Detector.Reset() |
| 230 | r.keep.Renew() | 231 | r.keep.Renew() |
| 231 | tools.ClearPlans("") // plans belong to the conversation just closed (ticket 109) | 232 | tools.ClearPlans("") // plans belong to the conversation just closed (ticket 109) |
| @@ -244,5 +245,6 @@ func (r *runner) resume(id string) { | |||
| 244 | tools.ClearPlans("") // the plans in memory were the previous conversation's | 245 | tools.ClearPlans("") // the plans in memory were the previous conversation's |
| 245 | r.opts.Detector.Reset() | 246 | r.opts.Detector.Reset() |
| 246 | r.opts.Model.ForgetInputTokens() | 247 | r.opts.Model.ForgetInputTokens() |
| 248 | + r.struggles.forgetContext() // ticket 269 | ||
| 247 | r.t.Notice(line) | 249 | r.t.Notice(line) |
| 248 | } | 250 | } |
added
internal/tui/contextbadge_test.go +113 -0 | new file mode 100644 | ||
| @@ -0,0 +1,113 @@ | ||
| 1 | +package tui | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "strings" | |
| 5 | + "testing" | |
| 6 | + | |
| 7 | + "github.com/firebase/genkit/go/ai" | |
| 8 | + | |
| 9 | + "mm/internal/config" | |
| 10 | + "mm/internal/store" | |
| 11 | + "mm/internal/ui" | |
| 12 | +) | |
| 13 | + | |
| 14 | +// Ticket 269: the "context N% full" warning describes the history; once the | |
| 15 | +// history shrinks it goes, and only it. | |
| 16 | +func TestForgetContextKeepsTheOtherStruggles(t *testing.T) { | |
| 17 | + var s struggles | |
| 18 | + s.add(ui.Struggle{Label: "context 85% full", Context: true}) | |
| 19 | + if b := s.badge(); b.text != " ⚠ context 85% full " { | |
| 20 | + t.Fatalf("badge = %+v", b) | |
| 21 | + } | |
| 22 | + s.forgetContext() | |
| 23 | + if b := s.badge(); b.text != "" { | |
| 24 | + t.Errorf("context only, after forgetContext: %+v", b) | |
| 25 | + } | |
| 26 | + | |
| 27 | + s.add(ui.Struggle{Severe: true, Label: "looped — stopped"}) | |
| 28 | + s.add(ui.Struggle{Label: "context 91% full", Context: true}) | |
| 29 | + if b := s.badge(); b.text != " ✖ looped — stopped (+1) " || !b.severe { | |
| 30 | + t.Fatalf("badge = %+v", b) | |
| 31 | + } | |
| 32 | + s.forgetContext() | |
| 33 | + if b := s.badge(); b.text != " ✖ looped — stopped " || !b.severe { | |
| 34 | + t.Errorf("the severe one must stay, alone: %+v", b) | |
| 35 | + } | |
| 36 | + | |
| 37 | + s.clear() | |
| 38 | + s.add(ui.Struggle{Label: "loop: bash ×3"}) | |
| 39 | + s.add(ui.Struggle{Label: "context 80% full", Context: true}) | |
| 40 | + s.forgetContext() | |
| 41 | + if b := s.badge(); b.text != " ⚠ loop: bash ×3 " { | |
| 42 | + t.Errorf("the warning that is not about the context stays: %+v", b) | |
| 43 | + } | |
| 44 | +} | |
| 45 | + | |
| 46 | +// /compact that compressed forgets the context badge; one that failed keeps | |
| 47 | +// it — the history is still as big. | |
| 48 | +func TestCompactForgetsTheContextBadge(t *testing.T) { | |
| 49 | + cases := []struct { | |
| 50 | + name string | |
| 51 | + res outcome | |
| 52 | + keeps bool | |
| 53 | + }{ | |
| 54 | + {"compressed", outcome{kind: "compact", changed: true, line: "🗜 compressed"}, false}, | |
| 55 | + {"failed", outcome{kind: "compact", err: errIf(true), line: "⚠ summary failed"}, true}, | |
| 56 | + {"nothing to compress", outcome{kind: "compact", line: "nothing to compress"}, true}, | |
| 57 | + } | |
| 58 | + for _, c := range cases { | |
| 59 | + t.Run(c.name, func(t *testing.T) { | |
| 60 | + r, _ := newTestRunner(t, &fakeModel{}) | |
| 61 | + r.struggles.add(ui.Struggle{Label: "context 88% full", Context: true}) | |
| 62 | + r.apply(c.res) | |
| 63 | + if got := r.struggles.badge().text != ""; got != c.keeps { | |
| 64 | + t.Errorf("badge kept = %v, want %v (%+v)", got, c.keeps, r.struggles.badge()) | |
| 65 | + } | |
| 66 | + }) | |
| 67 | + } | |
| 68 | +} | |
| 69 | + | |
| 70 | +// /new and /resume start from another history: the context badge goes, a | |
| 71 | +// severe badge stays until the next question. | |
| 72 | +func TestNewAndResumeForgetTheContextBadge(t *testing.T) { | |
| 73 | + r, _ := newTestRunner(t, &fakeModel{}) | |
| 74 | + r.struggles.add(ui.Struggle{Label: "context 88% full", Context: true}) | |
| 75 | + r.newSession() | |
| 76 | + if b := r.struggles.badge(); b.text != "" { | |
| 77 | + t.Errorf("after /new: %+v", b) | |
| 78 | + } | |
| 79 | + | |
| 80 | + config.Cfg.Sessions = config.SessionsConfig{Enabled: true, Dir: ".mm/sessions"} | |
| 81 | + r.keep = store.NewKeeper(r.opts.Cwd) | |
| 82 | + if err := store.Open(r.keep.Dir()).Save(&store.Session{ID: "20260101-000000-aaaaaaaa", Messages: []*ai.Message{ai.NewUserTextMessage("old question")}}); err != nil { | |
| 83 | + t.Fatal(err) | |
| 84 | + } | |
| 85 | + r.struggles.add(ui.Struggle{Severe: true, Label: "max turns reached"}) | |
| 86 | + r.struggles.add(ui.Struggle{Label: "context 90% full", Context: true}) | |
| 87 | + r.resume("20260101-000000-aaaaaaaa") | |
| 88 | + if b := r.struggles.badge(); b.text != " ✖ max turns reached " { | |
| 89 | + t.Errorf("after /resume: %+v", b) | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | +// Through the real path: the warning reaches the badge through the sink, | |
| 94 | +// the user types /compact, the history is compressed — the badge is gone. | |
| 95 | +func TestContextBadgeGoesAfterACompactThatCompressed(t *testing.T) { | |
| 96 | + r, tr := newTestRunner(t, &fakeModel{summary: "they talked"}) | |
| 97 | + config.Cfg.Context.KeepLastTurns = 1 | |
| 98 | + (&sink{r: r}).Struggle(ui.Struggle{Label: "context 90% full", Context: true}) | |
| 99 | + if r.struggles.badge().text == "" { | |
| 100 | + t.Fatal("no badge after the warning") | |
| 101 | + } | |
| 102 | + for _, q := range []string{"a", "b", "c"} { | |
| 103 | + r.messages = append(r.messages, ai.NewUserTextMessage(q), ai.NewModelMessage(ai.NewTextPart("ans "+q))) | |
| 104 | + } | |
| 105 | + r.submit(promptOf("/compact")) | |
| 106 | + waitIdle(t, r) | |
| 107 | + if !strings.Contains(notices(tr), "compressed") { | |
| 108 | + t.Fatalf("not compressed:\n%s", notices(tr)) | |
| 109 | + } | |
| 110 | + if b := r.struggles.badge(); b.text != "" { | |
| 111 | + t.Errorf("compressed, badge still %+v", b) | |
| 112 | + } | |
| 113 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | +package tui | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "strings" | ||
| 5 | + "testing" | ||
| 6 | + | ||
| 7 | + "github.com/firebase/genkit/go/ai" | ||
| 8 | + | ||
| 9 | + "mm/internal/config" | ||
| 10 | + "mm/internal/store" | ||
| 11 | + "mm/internal/ui" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +// Ticket 269: the "context N% full" warning describes the history; once the | ||
| 15 | +// history shrinks it goes, and only it. | ||
| 16 | +func TestForgetContextKeepsTheOtherStruggles(t *testing.T) { | ||
| 17 | + var s struggles | ||
| 18 | + s.add(ui.Struggle{Label: "context 85% full", Context: true}) | ||
| 19 | + if b := s.badge(); b.text != " ⚠ context 85% full " { | ||
| 20 | + t.Fatalf("badge = %+v", b) | ||
| 21 | + } | ||
| 22 | + s.forgetContext() | ||
| 23 | + if b := s.badge(); b.text != "" { | ||
| 24 | + t.Errorf("context only, after forgetContext: %+v", b) | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + s.add(ui.Struggle{Severe: true, Label: "looped — stopped"}) | ||
| 28 | + s.add(ui.Struggle{Label: "context 91% full", Context: true}) | ||
| 29 | + if b := s.badge(); b.text != " ✖ looped — stopped (+1) " || !b.severe { | ||
| 30 | + t.Fatalf("badge = %+v", b) | ||
| 31 | + } | ||
| 32 | + s.forgetContext() | ||
| 33 | + if b := s.badge(); b.text != " ✖ looped — stopped " || !b.severe { | ||
| 34 | + t.Errorf("the severe one must stay, alone: %+v", b) | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + s.clear() | ||
| 38 | + s.add(ui.Struggle{Label: "loop: bash ×3"}) | ||
| 39 | + s.add(ui.Struggle{Label: "context 80% full", Context: true}) | ||
| 40 | + s.forgetContext() | ||
| 41 | + if b := s.badge(); b.text != " ⚠ loop: bash ×3 " { | ||
| 42 | + t.Errorf("the warning that is not about the context stays: %+v", b) | ||
| 43 | + } | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// /compact that compressed forgets the context badge; one that failed keeps | ||
| 47 | +// it — the history is still as big. | ||
| 48 | +func TestCompactForgetsTheContextBadge(t *testing.T) { | ||
| 49 | + cases := []struct { | ||
| 50 | + name string | ||
| 51 | + res outcome | ||
| 52 | + keeps bool | ||
| 53 | + }{ | ||
| 54 | + {"compressed", outcome{kind: "compact", changed: true, line: "🗜 compressed"}, false}, | ||
| 55 | + {"failed", outcome{kind: "compact", err: errIf(true), line: "⚠ summary failed"}, true}, | ||
| 56 | + {"nothing to compress", outcome{kind: "compact", line: "nothing to compress"}, true}, | ||
| 57 | + } | ||
| 58 | + for _, c := range cases { | ||
| 59 | + t.Run(c.name, func(t *testing.T) { | ||
| 60 | + r, _ := newTestRunner(t, &fakeModel{}) | ||
| 61 | + r.struggles.add(ui.Struggle{Label: "context 88% full", Context: true}) | ||
| 62 | + r.apply(c.res) | ||
| 63 | + if got := r.struggles.badge().text != ""; got != c.keeps { | ||
| 64 | + t.Errorf("badge kept = %v, want %v (%+v)", got, c.keeps, r.struggles.badge()) | ||
| 65 | + } | ||
| 66 | + }) | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +// /new and /resume start from another history: the context badge goes, a | ||
| 71 | +// severe badge stays until the next question. | ||
| 72 | +func TestNewAndResumeForgetTheContextBadge(t *testing.T) { | ||
| 73 | + r, _ := newTestRunner(t, &fakeModel{}) | ||
| 74 | + r.struggles.add(ui.Struggle{Label: "context 88% full", Context: true}) | ||
| 75 | + r.newSession() | ||
| 76 | + if b := r.struggles.badge(); b.text != "" { | ||
| 77 | + t.Errorf("after /new: %+v", b) | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + config.Cfg.Sessions = config.SessionsConfig{Enabled: true, Dir: ".mm/sessions"} | ||
| 81 | + r.keep = store.NewKeeper(r.opts.Cwd) | ||
| 82 | + if err := store.Open(r.keep.Dir()).Save(&store.Session{ID: "20260101-000000-aaaaaaaa", Messages: []*ai.Message{ai.NewUserTextMessage("old question")}}); err != nil { | ||
| 83 | + t.Fatal(err) | ||
| 84 | + } | ||
| 85 | + r.struggles.add(ui.Struggle{Severe: true, Label: "max turns reached"}) | ||
| 86 | + r.struggles.add(ui.Struggle{Label: "context 90% full", Context: true}) | ||
| 87 | + r.resume("20260101-000000-aaaaaaaa") | ||
| 88 | + if b := r.struggles.badge(); b.text != " ✖ max turns reached " { | ||
| 89 | + t.Errorf("after /resume: %+v", b) | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +// Through the real path: the warning reaches the badge through the sink, | ||
| 94 | +// the user types /compact, the history is compressed — the badge is gone. | ||
| 95 | +func TestContextBadgeGoesAfterACompactThatCompressed(t *testing.T) { | ||
| 96 | + r, tr := newTestRunner(t, &fakeModel{summary: "they talked"}) | ||
| 97 | + config.Cfg.Context.KeepLastTurns = 1 | ||
| 98 | + (&sink{r: r}).Struggle(ui.Struggle{Label: "context 90% full", Context: true}) | ||
| 99 | + if r.struggles.badge().text == "" { | ||
| 100 | + t.Fatal("no badge after the warning") | ||
| 101 | + } | ||
| 102 | + for _, q := range []string{"a", "b", "c"} { | ||
| 103 | + r.messages = append(r.messages, ai.NewUserTextMessage(q), ai.NewModelMessage(ai.NewTextPart("ans "+q))) | ||
| 104 | + } | ||
| 105 | + r.submit(promptOf("/compact")) | ||
| 106 | + waitIdle(t, r) | ||
| 107 | + if !strings.Contains(notices(tr), "compressed") { | ||
| 108 | + t.Fatalf("not compressed:\n%s", notices(tr)) | ||
| 109 | + } | ||
| 110 | + if b := r.struggles.badge(); b.text != "" { | ||
| 111 | + t.Errorf("compressed, badge still %+v", b) | ||
| 112 | + } | ||
| 113 | +} | ||
modified
internal/tui/struggle.go +35 -17 | @@ -16,45 +16,63 @@ import ( | ||
| 16 | 16 | // badly — and goes when the next question is sent. |
| 17 | 17 | |
| 18 | 18 | // struggles is what a turn reported, written from the engine's goroutines |
| 19 | -// and read by the event loop. | |
| 19 | +// and read by the event loop. It keeps them all, in order, so that one kind | |
| 20 | +// can be forgotten and the badge drawn again from what is left. | |
| 20 | 21 | type struggles struct { |
| 21 | - mu sync.Mutex | |
| 22 | - worst ui.Struggle | |
| 23 | - count int | |
| 22 | + mu sync.Mutex | |
| 23 | + list []ui.Struggle | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | -// add keeps the worst struggle so far: a severe one beats a warning, and | |
| 27 | -// between two of the same weight the latest wins (it is what is happening | |
| 28 | -// now: "loop: bash ×4" after "×3"). | |
| 26 | +// add records a struggle of the turn. | |
| 29 | 27 | func (s *struggles) add(st ui.Struggle) { |
| 30 | 28 | s.mu.Lock() |
| 31 | 29 | defer s.mu.Unlock() |
| 32 | - if s.count == 0 || st.Severe || !s.worst.Severe { | |
| 33 | - s.worst = st | |
| 34 | - } | |
| 35 | - s.count++ | |
| 30 | + s.list = append(s.list, st) | |
| 36 | 31 | } |
| 37 | 32 | |
| 38 | 33 | // clear forgets the turn's struggles. |
| 39 | 34 | func (s *struggles) clear() { |
| 40 | 35 | s.mu.Lock() |
| 41 | 36 | defer s.mu.Unlock() |
| 42 | - s.worst, s.count = ui.Struggle{}, 0 | |
| 37 | + s.list = nil | |
| 38 | +} | |
| 39 | + | |
| 40 | +// forgetContext drops the "context N% full" warnings and keeps the rest | |
| 41 | +// (ticket 269): after /compact, /new or /resume the history they measured | |
| 42 | +// is gone, while "looped — stopped" still says why the last turn ended. | |
| 43 | +func (s *struggles) forgetContext() { | |
| 44 | + s.mu.Lock() | |
| 45 | + defer s.mu.Unlock() | |
| 46 | + kept := s.list[:0] | |
| 47 | + for _, st := range s.list { | |
| 48 | + if !st.Context { | |
| 49 | + kept = append(kept, st) | |
| 50 | + } | |
| 51 | + } | |
| 52 | + s.list = kept | |
| 43 | 53 | } |
| 44 | 54 | |
| 45 | 55 | // badge is what the status bar draws: the worst struggle, and how many |
| 46 | 56 | // others the turn had ("⚠ loop: bash ×3 (+1)"); the zero badge when none. |
| 57 | +// A severe one beats a warning, and between two of the same weight the | |
| 58 | +// latest wins (it is what is happening now: "loop: bash ×4" after "×3"). | |
| 47 | 59 | func (s *struggles) badge() badge { |
| 48 | 60 | s.mu.Lock() |
| 49 | 61 | defer s.mu.Unlock() |
| 50 | - if s.count == 0 { | |
| 62 | + if len(s.list) == 0 { | |
| 51 | 63 | return badge{} |
| 52 | 64 | } |
| 53 | - text := " " + s.worst.String() + " " | |
| 54 | - if s.count > 1 { | |
| 55 | - text = fmt.Sprintf(" %s (+%d) ", s.worst.String(), s.count-1) | |
| 65 | + worst := s.list[0] | |
| 66 | + for _, st := range s.list[1:] { | |
| 67 | + if st.Severe || !worst.Severe { | |
| 68 | + worst = st | |
| 69 | + } | |
| 70 | + } | |
| 71 | + text := " " + worst.String() + " " | |
| 72 | + if len(s.list) > 1 { | |
| 73 | + text = fmt.Sprintf(" %s (+%d) ", worst.String(), len(s.list)-1) | |
| 56 | 74 | } |
| 57 | - return badge{text: text, severe: s.worst.Severe} | |
| 75 | + return badge{text: text, severe: worst.Severe} | |
| 58 | 76 | } |
| 59 | 77 | |
| 60 | 78 | // badge is the struggle as the status bar draws it. |
| @@ -16,45 +16,63 @@ import ( | |||
| 16 | // badly — and goes when the next question is sent. | 16 | // badly — and goes when the next question is sent. |
| 17 | 17 | ||
| 18 | // struggles is what a turn reported, written from the engine's goroutines | 18 | // struggles is what a turn reported, written from the engine's goroutines |
| 19 | -// and read by the event loop. | 19 | +// and read by the event loop. It keeps them all, in order, so that one kind |
| 20 | +// can be forgotten and the badge drawn again from what is left. | ||
| 20 | type struggles struct { | 21 | type struggles struct { |
| 21 | - mu sync.Mutex | 22 | + mu sync.Mutex |
| 22 | - worst ui.Struggle | 23 | + list []ui.Struggle |
| 23 | - count int | ||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | -// add keeps the worst struggle so far: a severe one beats a warning, and | 26 | +// add records a struggle of the turn. |
| 27 | -// between two of the same weight the latest wins (it is what is happening | ||
| 28 | -// now: "loop: bash ×4" after "×3"). | ||
| 29 | func (s *struggles) add(st ui.Struggle) { | 27 | func (s *struggles) add(st ui.Struggle) { |
| 30 | s.mu.Lock() | 28 | s.mu.Lock() |
| 31 | defer s.mu.Unlock() | 29 | defer s.mu.Unlock() |
| 32 | - if s.count == 0 || st.Severe || !s.worst.Severe { | 30 | + s.list = append(s.list, st) |
| 33 | - s.worst = st | ||
| 34 | - } | ||
| 35 | - s.count++ | ||
| 36 | } | 31 | } |
| 37 | 32 | ||
| 38 | // clear forgets the turn's struggles. | 33 | // clear forgets the turn's struggles. |
| 39 | func (s *struggles) clear() { | 34 | func (s *struggles) clear() { |
| 40 | s.mu.Lock() | 35 | s.mu.Lock() |
| 41 | defer s.mu.Unlock() | 36 | defer s.mu.Unlock() |
| 42 | - s.worst, s.count = ui.Struggle{}, 0 | 37 | + s.list = nil |
| 38 | +} | ||
| 39 | + | ||
| 40 | +// forgetContext drops the "context N% full" warnings and keeps the rest | ||
| 41 | +// (ticket 269): after /compact, /new or /resume the history they measured | ||
| 42 | +// is gone, while "looped — stopped" still says why the last turn ended. | ||
| 43 | +func (s *struggles) forgetContext() { | ||
| 44 | + s.mu.Lock() | ||
| 45 | + defer s.mu.Unlock() | ||
| 46 | + kept := s.list[:0] | ||
| 47 | + for _, st := range s.list { | ||
| 48 | + if !st.Context { | ||
| 49 | + kept = append(kept, st) | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + s.list = kept | ||
| 43 | } | 53 | } |
| 44 | 54 | ||
| 45 | // badge is what the status bar draws: the worst struggle, and how many | 55 | // badge is what the status bar draws: the worst struggle, and how many |
| 46 | // others the turn had ("⚠ loop: bash ×3 (+1)"); the zero badge when none. | 56 | // others the turn had ("⚠ loop: bash ×3 (+1)"); the zero badge when none. |
| 57 | +// A severe one beats a warning, and between two of the same weight the | ||
| 58 | +// latest wins (it is what is happening now: "loop: bash ×4" after "×3"). | ||
| 47 | func (s *struggles) badge() badge { | 59 | func (s *struggles) badge() badge { |
| 48 | s.mu.Lock() | 60 | s.mu.Lock() |
| 49 | defer s.mu.Unlock() | 61 | defer s.mu.Unlock() |
| 50 | - if s.count == 0 { | 62 | + if len(s.list) == 0 { |
| 51 | return badge{} | 63 | return badge{} |
| 52 | } | 64 | } |
| 53 | - text := " " + s.worst.String() + " " | 65 | + worst := s.list[0] |
| 54 | - if s.count > 1 { | 66 | + for _, st := range s.list[1:] { |
| 55 | - text = fmt.Sprintf(" %s (+%d) ", s.worst.String(), s.count-1) | 67 | + if st.Severe || !worst.Severe { |
| 68 | + worst = st | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + text := " " + worst.String() + " " | ||
| 72 | + if len(s.list) > 1 { | ||
| 73 | + text = fmt.Sprintf(" %s (+%d) ", worst.String(), len(s.list)-1) | ||
| 56 | } | 74 | } |
| 57 | - return badge{text: text, severe: s.worst.Severe} | 75 | + return badge{text: text, severe: worst.Severe} |
| 58 | } | 76 | } |
| 59 | 77 | ||
| 60 | // badge is the struggle as the status bar draws it. | 78 | // badge is the struggle as the status bar draws it. |
modified
internal/tui/turn.go +1 -0 | @@ -381,6 +381,7 @@ func (r *runner) apply(res outcome) { | ||
| 381 | 381 | r.record(store.NewFailure(r.messages, store.FailCompaction, res.line, nil)) |
| 382 | 382 | case res.changed: |
| 383 | 383 | r.opts.Model.ForgetInputTokens() |
| 384 | + r.struggles.forgetContext() // the history it measured is gone (ticket 269) | |
| 384 | 385 | r.save() |
| 385 | 386 | r.t.Notice(res.line) |
| 386 | 387 | default: |
| @@ -381,6 +381,7 @@ func (r *runner) apply(res outcome) { | |||
| 381 | r.record(store.NewFailure(r.messages, store.FailCompaction, res.line, nil)) | 381 | r.record(store.NewFailure(r.messages, store.FailCompaction, res.line, nil)) |
| 382 | case res.changed: | 382 | case res.changed: |
| 383 | r.opts.Model.ForgetInputTokens() | 383 | r.opts.Model.ForgetInputTokens() |
| 384 | + r.struggles.forgetContext() // the history it measured is gone (ticket 269) | ||
| 384 | r.save() | 385 | r.save() |
| 385 | r.t.Notice(res.line) | 386 | r.t.Notice(res.line) |
| 386 | default: | 387 | default: |
modified
internal/ui/ui.go +7 -2 | @@ -223,9 +223,14 @@ func Display(text string) { | ||
| 223 | 223 | // exist… Severe means the turn was stopped or failed because of it; the |
| 224 | 224 | // others are warnings — the turn goes on. Label is short enough for a status |
| 225 | 225 | // bar: "loop: bash ×3", "stalled". |
| 226 | +// | |
| 227 | +// Context marks the "context N% full" warning (ticket 269): it describes the | |
| 228 | +// history, not how the turn went, so a front end that keeps it (the window's | |
| 229 | +// badge) forgets it once the history shrinks — /compact, /new, /resume. | |
| 226 | 230 | type Struggle struct { |
| 227 | - Severe bool | |
| 228 | - Label string | |
| 231 | + Severe bool | |
| 232 | + Label string | |
| 233 | + Context bool | |
| 229 | 234 | } |
| 230 | 235 | |
| 231 | 236 | // Mark is the struggle's sign: ✖ when severe, ⚠ otherwise. |
| @@ -223,9 +223,14 @@ func Display(text string) { | |||
| 223 | // exist… Severe means the turn was stopped or failed because of it; the | 223 | // exist… Severe means the turn was stopped or failed because of it; the |
| 224 | // others are warnings — the turn goes on. Label is short enough for a status | 224 | // others are warnings — the turn goes on. Label is short enough for a status |
| 225 | // bar: "loop: bash ×3", "stalled". | 225 | // bar: "loop: bash ×3", "stalled". |
| 226 | +// | ||
| 227 | +// Context marks the "context N% full" warning (ticket 269): it describes the | ||
| 228 | +// history, not how the turn went, so a front end that keeps it (the window's | ||
| 229 | +// badge) forgets it once the history shrinks — /compact, /new, /resume. | ||
| 226 | type Struggle struct { | 230 | type Struggle struct { |
| 227 | - Severe bool | 231 | + Severe bool |
| 228 | - Label string | 232 | + Label string |
| 233 | + Context bool | ||
| 229 | } | 234 | } |
| 230 | 235 | ||
| 231 | // Mark is the struggle's sign: ✖ when severe, ⚠ otherwise. | 236 | // Mark is the struggle's sign: ✖ when severe, ⚠ otherwise. |