modified
.tickets/issues/0265-steer-a-running-turn-a-message-typed-during-a-turn.yaml +49 -18 | @@ -1,12 +1,13 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 265 |
| 3 | 3 | title: "Steer: a message typed during a turn reaches the model at its next call, without stopping the turn" |
| 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-26T11:30:00.000Z |
| 9 | -updatedAt: 2026-11-26T12:30:00.000Z | |
| 9 | +updatedAt: 2026-11-26T16:00:00.000Z | |
| 10 | +closedAt: 2026-11-26T16:00:00.000Z | |
| 10 | 11 | labels: |
| 11 | 12 | - enhancement |
| 12 | 13 | - kind::feature |
| @@ -59,19 +60,20 @@ body: | | ||
| 59 | 60 | ticket 155 kept for an explicit "after this turn" (a key to choose: |
| 60 | 61 | Alt-Enter? a `/queue` prefix?). Slash commands keep their current |
| 61 | 62 | rules (control commands at once, others queued). |
| 62 | - - Line mode (internal/agent): no steer (user's decision). | |
| 63 | + - Line mode (internal/agent): steers too (internal/agent/steer.go). | |
| 63 | 64 | - Editor (ACP): moved to ticket 266 (blocked on ACP protocol v2 in |
| 64 | 65 | acp-go-sdk and Zed). |
| 65 | 66 | - `-p` and asked agents: nothing (no user during the turn). |
| 66 | 67 | |
| 67 | 68 | ## Decided |
| 68 | 69 | - 2026-11-26, user: in the window, Enter during a turn STEERS; the |
| 69 | - queue of ticket 155 needs another trigger: BOTH Alt-Enter and a | |
| 70 | - `/queue <text>` command (works whatever the terminal sends) — user's | |
| 71 | - agreement 2026-11-26. | |
| 70 | + queue of ticket 155 needs another trigger: `/queue <question>` ONLY | |
| 71 | + (user's choice 2026-11-26, once it turned out Alt-Enter already | |
| 72 | + inserts a newline, like Ctrl-J). | |
| 72 | 73 | |
| 73 | - - 2026-11-26, user: NO steer in the line mode (it keeps reading the | |
| 74 | - terminal only between turns). | |
| 74 | + - 2026-11-26, user: NO steer in the line mode — REVERSED the same day | |
| 75 | + once it was clear the line mode already reads lines typed during a | |
| 76 | + turn (it queued them): the line mode steers too, /queue there as well. | |
| 75 | 77 | - 2026-11-26, user: in the window, a second message sent before the |
| 76 | 78 | turn ends is a steer. |
| 77 | 79 | - Milestone v2.1.1. |
| @@ -89,24 +91,26 @@ body: | | ||
| 89 | 91 | tasks: |
| 90 | 92 | - id: 1 |
| 91 | 93 | title: "Engine: per-turn steer inbox in the context, drained in WrapModel from the second call on" |
| 92 | - state: open | |
| 94 | + state: closed | |
| 93 | 95 | priority: high |
| 94 | 96 | author: |
| 95 | 97 | name: k33g |
| 96 | 98 | email: ph.charriere@gmail.com |
| 97 | 99 | createdAt: 2026-11-26T11:30:00.000Z |
| 98 | - updatedAt: 2026-11-26T11:30:00.000Z | |
| 100 | + updatedAt: 2026-11-26T13:30:00.000Z | |
| 101 | + closedAt: 2026-11-26T13:30:00.000Z | |
| 99 | 102 | - id: 2 |
| 100 | - title: "Window: Enter during a turn steers; queue on Alt-Enter and /queue <text>; transcript line when taken" | |
| 101 | - state: open | |
| 103 | + title: "Window: Enter during a turn steers; queue with /queue <question>; transcript line when taken" | |
| 104 | + state: closed | |
| 102 | 105 | priority: high |
| 103 | 106 | author: |
| 104 | 107 | name: k33g |
| 105 | 108 | email: ph.charriere@gmail.com |
| 106 | 109 | createdAt: 2026-11-26T11:30:00.000Z |
| 107 | - updatedAt: 2026-11-26T11:30:00.000Z | |
| 110 | + updatedAt: 2026-11-26T13:30:00.000Z | |
| 111 | + closedAt: 2026-11-26T13:30:00.000Z | |
| 108 | 112 | - id: 4 |
| 109 | - title: "Line mode: no steer (user's decision, 2026-11-26)" | |
| 113 | + title: "Line mode: a line typed during a turn steers it; /queue keeps the queue" | |
| 110 | 114 | state: closed |
| 111 | 115 | priority: low |
| 112 | 116 | author: |
| @@ -117,19 +121,46 @@ tasks: | ||
| 117 | 121 | closedAt: 2026-11-26T12:00:00.000Z |
| 118 | 122 | - id: 5 |
| 119 | 123 | title: "Check role order on strict chat templates (user after tool) with llama.cpp and razorbill" |
| 120 | - state: open | |
| 124 | + state: closed | |
| 121 | 125 | priority: medium |
| 122 | 126 | author: |
| 123 | 127 | name: k33g |
| 124 | 128 | email: ph.charriere@gmail.com |
| 125 | 129 | createdAt: 2026-11-26T11:30:00.000Z |
| 126 | - updatedAt: 2026-11-26T11:30:00.000Z | |
| 130 | + updatedAt: 2026-11-26T13:30:00.000Z | |
| 131 | + closedAt: 2026-11-26T13:30:00.000Z | |
| 127 | 132 | - id: 6 |
| 128 | 133 | title: Docs EN+FR |
| 129 | - state: open | |
| 134 | + state: closed | |
| 130 | 135 | priority: medium |
| 131 | 136 | author: |
| 132 | 137 | name: k33g |
| 133 | 138 | email: ph.charriere@gmail.com |
| 134 | 139 | createdAt: 2026-11-26T11:30:00.000Z |
| 135 | - updatedAt: 2026-11-26T11:30:00.000Z | |
| 140 | + updatedAt: 2026-11-26T13:30:00.000Z | |
| 141 | + closedAt: 2026-11-26T13:30:00.000Z | |
| 142 | +comments: | |
| 143 | + - id: 1 | |
| 144 | + author: | |
| 145 | + name: k33g | |
| 146 | + email: ph.charriere@gmail.com | |
| 147 | + createdAt: 2026-11-26T13:30:00.000Z | |
| 148 | + body: | | |
| 149 | + Implemented on branch feature/steer: engine Inbox (internal/engine/steer.go, | |
| 150 | + taken in the turn's WrapModel when the call follows tool results), | |
| 151 | + window (Enter steers, /queue, late steers run next, shown once), | |
| 152 | + ↑ recall strips the label. Role order checked live on llama.cpp | |
| 153 | + (gpt-oss 20B, Qwen3.5 2B, LFM3 1.7B: user message after tool results | |
| 154 | + accepted and followed); NOT on razorbill (server down at the time). | |
| 155 | + Not tried live in the window (no TTY in the sandbox). | |
| 156 | + - id: 2 | |
| 157 | + author: | |
| 158 | + name: k33g | |
| 159 | + email: ph.charriere@gmail.com | |
| 160 | + createdAt: 2026-11-26T14:30:00.000Z | |
| 161 | + body: | | |
| 162 | + Line mode added (user's request): internal/agent/steer.go (turnSteer), | |
| 163 | + /queue now Terminal | Window. Live on the host llama router with | |
| 164 | + gpt-oss 20B, piped input: "↪ Steering", then "↪ Steered: answer in | |
| 165 | + French please" after the first tool result, the turn went on (wc -c) | |
| 166 | + and answered in French. | |
| @@ -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: 265 | 2 | id: 265 |
| 3 | title: "Steer: a message typed during a turn reaches the model at its next call, without stopping the turn" | 3 | title: "Steer: a message typed during a turn reaches the model at its next call, without stopping the turn" |
| 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-26T11:30:00.000Z | 8 | createdAt: 2026-11-26T11:30:00.000Z |
| 9 | -updatedAt: 2026-11-26T12:30:00.000Z | 9 | +updatedAt: 2026-11-26T16:00:00.000Z |
| 10 | +closedAt: 2026-11-26T16:00:00.000Z | ||
| 10 | labels: | 11 | labels: |
| 11 | - enhancement | 12 | - enhancement |
| 12 | - kind::feature | 13 | - kind::feature |
| @@ -59,19 +60,20 @@ body: | | |||
| 59 | ticket 155 kept for an explicit "after this turn" (a key to choose: | 60 | ticket 155 kept for an explicit "after this turn" (a key to choose: |
| 60 | Alt-Enter? a `/queue` prefix?). Slash commands keep their current | 61 | Alt-Enter? a `/queue` prefix?). Slash commands keep their current |
| 61 | rules (control commands at once, others queued). | 62 | rules (control commands at once, others queued). |
| 62 | - - Line mode (internal/agent): no steer (user's decision). | 63 | + - Line mode (internal/agent): steers too (internal/agent/steer.go). |
| 63 | - Editor (ACP): moved to ticket 266 (blocked on ACP protocol v2 in | 64 | - Editor (ACP): moved to ticket 266 (blocked on ACP protocol v2 in |
| 64 | acp-go-sdk and Zed). | 65 | acp-go-sdk and Zed). |
| 65 | - `-p` and asked agents: nothing (no user during the turn). | 66 | - `-p` and asked agents: nothing (no user during the turn). |
| 66 | 67 | ||
| 67 | ## Decided | 68 | ## Decided |
| 68 | - 2026-11-26, user: in the window, Enter during a turn STEERS; the | 69 | - 2026-11-26, user: in the window, Enter during a turn STEERS; the |
| 69 | - queue of ticket 155 needs another trigger: BOTH Alt-Enter and a | 70 | + queue of ticket 155 needs another trigger: `/queue <question>` ONLY |
| 70 | - `/queue <text>` command (works whatever the terminal sends) — user's | 71 | + (user's choice 2026-11-26, once it turned out Alt-Enter already |
| 71 | - agreement 2026-11-26. | 72 | + inserts a newline, like Ctrl-J). |
| 72 | 73 | ||
| 73 | - - 2026-11-26, user: NO steer in the line mode (it keeps reading the | 74 | + - 2026-11-26, user: NO steer in the line mode — REVERSED the same day |
| 74 | - terminal only between turns). | 75 | + once it was clear the line mode already reads lines typed during a |
| 76 | + turn (it queued them): the line mode steers too, /queue there as well. | ||
| 75 | - 2026-11-26, user: in the window, a second message sent before the | 77 | - 2026-11-26, user: in the window, a second message sent before the |
| 76 | turn ends is a steer. | 78 | turn ends is a steer. |
| 77 | - Milestone v2.1.1. | 79 | - Milestone v2.1.1. |
| @@ -89,24 +91,26 @@ body: | | |||
| 89 | tasks: | 91 | tasks: |
| 90 | - id: 1 | 92 | - id: 1 |
| 91 | title: "Engine: per-turn steer inbox in the context, drained in WrapModel from the second call on" | 93 | title: "Engine: per-turn steer inbox in the context, drained in WrapModel from the second call on" |
| 92 | - state: open | 94 | + state: closed |
| 93 | priority: high | 95 | priority: high |
| 94 | author: | 96 | author: |
| 95 | name: k33g | 97 | name: k33g |
| 96 | email: ph.charriere@gmail.com | 98 | email: ph.charriere@gmail.com |
| 97 | createdAt: 2026-11-26T11:30:00.000Z | 99 | createdAt: 2026-11-26T11:30:00.000Z |
| 98 | - updatedAt: 2026-11-26T11:30:00.000Z | 100 | + updatedAt: 2026-11-26T13:30:00.000Z |
| 101 | + closedAt: 2026-11-26T13:30:00.000Z | ||
| 99 | - id: 2 | 102 | - id: 2 |
| 100 | - title: "Window: Enter during a turn steers; queue on Alt-Enter and /queue <text>; transcript line when taken" | 103 | + title: "Window: Enter during a turn steers; queue with /queue <question>; transcript line when taken" |
| 101 | - state: open | 104 | + state: closed |
| 102 | priority: high | 105 | priority: high |
| 103 | author: | 106 | author: |
| 104 | name: k33g | 107 | name: k33g |
| 105 | email: ph.charriere@gmail.com | 108 | email: ph.charriere@gmail.com |
| 106 | createdAt: 2026-11-26T11:30:00.000Z | 109 | createdAt: 2026-11-26T11:30:00.000Z |
| 107 | - updatedAt: 2026-11-26T11:30:00.000Z | 110 | + updatedAt: 2026-11-26T13:30:00.000Z |
| 111 | + closedAt: 2026-11-26T13:30:00.000Z | ||
| 108 | - id: 4 | 112 | - id: 4 |
| 109 | - title: "Line mode: no steer (user's decision, 2026-11-26)" | 113 | + title: "Line mode: a line typed during a turn steers it; /queue keeps the queue" |
| 110 | state: closed | 114 | state: closed |
| 111 | priority: low | 115 | priority: low |
| 112 | author: | 116 | author: |
| @@ -117,19 +121,46 @@ tasks: | |||
| 117 | closedAt: 2026-11-26T12:00:00.000Z | 121 | closedAt: 2026-11-26T12:00:00.000Z |
| 118 | - id: 5 | 122 | - id: 5 |
| 119 | title: "Check role order on strict chat templates (user after tool) with llama.cpp and razorbill" | 123 | title: "Check role order on strict chat templates (user after tool) with llama.cpp and razorbill" |
| 120 | - state: open | 124 | + state: closed |
| 121 | priority: medium | 125 | priority: medium |
| 122 | author: | 126 | author: |
| 123 | name: k33g | 127 | name: k33g |
| 124 | email: ph.charriere@gmail.com | 128 | email: ph.charriere@gmail.com |
| 125 | createdAt: 2026-11-26T11:30:00.000Z | 129 | createdAt: 2026-11-26T11:30:00.000Z |
| 126 | - updatedAt: 2026-11-26T11:30:00.000Z | 130 | + updatedAt: 2026-11-26T13:30:00.000Z |
| 131 | + closedAt: 2026-11-26T13:30:00.000Z | ||
| 127 | - id: 6 | 132 | - id: 6 |
| 128 | title: Docs EN+FR | 133 | title: Docs EN+FR |
| 129 | - state: open | 134 | + state: closed |
| 130 | priority: medium | 135 | priority: medium |
| 131 | author: | 136 | author: |
| 132 | name: k33g | 137 | name: k33g |
| 133 | email: ph.charriere@gmail.com | 138 | email: ph.charriere@gmail.com |
| 134 | createdAt: 2026-11-26T11:30:00.000Z | 139 | createdAt: 2026-11-26T11:30:00.000Z |
| 135 | - updatedAt: 2026-11-26T11:30:00.000Z | 140 | + updatedAt: 2026-11-26T13:30:00.000Z |
| 141 | + closedAt: 2026-11-26T13:30:00.000Z | ||
| 142 | +comments: | ||
| 143 | + - id: 1 | ||
| 144 | + author: | ||
| 145 | + name: k33g | ||
| 146 | + email: ph.charriere@gmail.com | ||
| 147 | + createdAt: 2026-11-26T13:30:00.000Z | ||
| 148 | + body: | | ||
| 149 | + Implemented on branch feature/steer: engine Inbox (internal/engine/steer.go, | ||
| 150 | + taken in the turn's WrapModel when the call follows tool results), | ||
| 151 | + window (Enter steers, /queue, late steers run next, shown once), | ||
| 152 | + ↑ recall strips the label. Role order checked live on llama.cpp | ||
| 153 | + (gpt-oss 20B, Qwen3.5 2B, LFM3 1.7B: user message after tool results | ||
| 154 | + accepted and followed); NOT on razorbill (server down at the time). | ||
| 155 | + Not tried live in the window (no TTY in the sandbox). | ||
| 156 | + - id: 2 | ||
| 157 | + author: | ||
| 158 | + name: k33g | ||
| 159 | + email: ph.charriere@gmail.com | ||
| 160 | + createdAt: 2026-11-26T14:30:00.000Z | ||
| 161 | + body: | | ||
| 162 | + Line mode added (user's request): internal/agent/steer.go (turnSteer), | ||
| 163 | + /queue now Terminal | Window. Live on the host llama router with | ||
| 164 | + gpt-oss 20B, piped input: "↪ Steering", then "↪ Steered: answer in | ||
| 165 | + French please" after the first tool result, the turn went on (wc -c) | ||
| 166 | + and answered in French. | ||
modified
.tickets/issues/0266-acp-steer-from-zed-once-acp-v2-prompts-during-a-turn.yaml +6 -1 | @@ -6,13 +6,14 @@ author: | ||
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-26T12:30:00.000Z |
| 9 | -updatedAt: 2026-11-26T12:30:00.000Z | |
| 9 | +updatedAt: 2026-11-26T14:45:00.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - enhancement |
| 12 | 12 | - kind::feature |
| 13 | 13 | epic: ACP integration |
| 14 | 14 | related: |
| 15 | 15 | - 265 |
| 16 | + - 267 | |
| 16 | 17 | body: | |
| 17 | 18 | Split from ticket 265 at the user's request (2026-11-26). Goal: the |
| 18 | 19 | steer of ticket 265 (a message typed during a turn reaches the model at |
| @@ -46,6 +47,10 @@ body: | | ||
| 46 | 47 | - Vendor extensions exist (`_session/steering` in some Claude Code / |
| 47 | 48 | Codex adapters, `_reasonix.io/session/steer`); Zed calls none. |
| 48 | 49 | |
| 50 | + ## Workaround until then | |
| 51 | + - `/redirect <message>` (ticket 267): with Zed's "Send Now", stop the | |
| 52 | + turn and continue the task with the user's correction. | |
| 53 | + | |
| 49 | 54 | ## What to do once unblocked |
| 50 | 55 | - acp-go-sdk with protocol v2; Zed sending session/prompt during a turn |
| 51 | 56 | to external agents. |
| @@ -6,13 +6,14 @@ author: | |||
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-26T12:30:00.000Z | 8 | createdAt: 2026-11-26T12:30:00.000Z |
| 9 | -updatedAt: 2026-11-26T12:30:00.000Z | 9 | +updatedAt: 2026-11-26T14:45:00.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - enhancement | 11 | - enhancement |
| 12 | - kind::feature | 12 | - kind::feature |
| 13 | epic: ACP integration | 13 | epic: ACP integration |
| 14 | related: | 14 | related: |
| 15 | - 265 | 15 | - 265 |
| 16 | + - 267 | ||
| 16 | body: | | 17 | body: | |
| 17 | Split from ticket 265 at the user's request (2026-11-26). Goal: the | 18 | Split from ticket 265 at the user's request (2026-11-26). Goal: the |
| 18 | steer of ticket 265 (a message typed during a turn reaches the model at | 19 | steer of ticket 265 (a message typed during a turn reaches the model at |
| @@ -46,6 +47,10 @@ body: | | |||
| 46 | - Vendor extensions exist (`_session/steering` in some Claude Code / | 47 | - Vendor extensions exist (`_session/steering` in some Claude Code / |
| 47 | Codex adapters, `_reasonix.io/session/steer`); Zed calls none. | 48 | Codex adapters, `_reasonix.io/session/steer`); Zed calls none. |
| 48 | 49 | ||
| 50 | + ## Workaround until then | ||
| 51 | + - `/redirect <message>` (ticket 267): with Zed's "Send Now", stop the | ||
| 52 | + turn and continue the task with the user's correction. | ||
| 53 | + | ||
| 49 | ## What to do once unblocked | 54 | ## What to do once unblocked |
| 50 | - acp-go-sdk with protocol v2; Zed sending session/prompt during a turn | 55 | - acp-go-sdk with protocol v2; Zed sending session/prompt during a turn |
| 51 | to external agents. | 56 | to external agents. |
added
.tickets/issues/0267-acp-redirect-command-stop-the-turn-and-continue-the-task.yaml +98 -0 | new file mode 100644 | ||
| @@ -0,0 +1,98 @@ | ||
| 1 | +# Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | |
| 2 | +id: 267 | |
| 3 | +title: "ACP: /redirect <message> — stop the turn (Zed's Send Now) and continue the task with the user's correction" | |
| 4 | +state: closed | |
| 5 | +author: | |
| 6 | + name: k33g | |
| 7 | + email: ph.charriere@gmail.com | |
| 8 | +createdAt: 2026-11-26T15:00:00.000Z | |
| 9 | +updatedAt: 2026-11-26T16:00:00.000Z | |
| 10 | +closedAt: 2026-11-26T16:00:00.000Z | |
| 11 | +labels: | |
| 12 | + - enhancement | |
| 13 | + - kind::feature | |
| 14 | +milestone: v2.1.1 | |
| 15 | +epic: ACP integration | |
| 16 | +related: | |
| 17 | + - 265 | |
| 18 | + - 266 | |
| 19 | +body: | | |
| 20 | + The user's idea (2026-11-26), name chosen by the user among /redirect, | |
| 21 | + /interrupt, /correct, /almost-steer: a workaround for the steer of | |
| 22 | + ticket 265 in the editor until ACP v2 lets Zed send a prompt during a | |
| 23 | + turn (ticket 266). | |
| 24 | + | |
| 25 | + ## What it does | |
| 26 | + - Editor only (`command.Editor`): the line mode and the window steer for | |
| 27 | + real (ticket 265). | |
| 28 | + - Meant to be sent with Zed's "Send Now" (double Enter), which sends | |
| 29 | + session/cancel then the prompt: the turn stops, and mm already keeps | |
| 30 | + the cancelled turn's full history (session.AfterTurn) — the commands | |
| 31 | + that ran, their results. | |
| 32 | + - `/redirect <message>` runs a turn whose question is the message framed | |
| 33 | + as a correction of the task in progress, not a new task: | |
| 34 | + `[the user redirects the task in progress] <message>` followed by a | |
| 35 | + note asking the model to continue the task it was working on with | |
| 36 | + this taken into account. The framing is neutral about whether the turn | |
| 37 | + was stopped: without Send Now, Zed holds the message until the turn | |
| 38 | + ends, and it then simply continues the task. | |
| 39 | + - `/redirect` alone answers that it needs a message, without a turn. | |
| 40 | + - ↑ recall (store.Questions) shows the message as typed. | |
| 41 | + | |
| 42 | + ## Limits (to document) | |
| 43 | + - The cancel comes first: a tool running at that moment (a bash | |
| 44 | + command) is killed; a real steer waits for the step to end. | |
| 45 | + - It only interrupts when sent with Send Now. | |
| 46 | + | |
| 47 | + ## Acceptance criteria | |
| 48 | + - Command offered to the editor (available_commands), not to the | |
| 49 | + terminal or the window; tests on the ACP façade (framed question, bare | |
| 50 | + /redirect, history kept after a cancel); docs EN+FR. | |
| 51 | +tasks: | |
| 52 | + - id: 1 | |
| 53 | + title: "Command /redirect (Editor), framing in the engine (label + note), ↑ recall strips them" | |
| 54 | + state: closed | |
| 55 | + priority: high | |
| 56 | + author: | |
| 57 | + name: k33g | |
| 58 | + email: ph.charriere@gmail.com | |
| 59 | + createdAt: 2026-11-26T15:00:00.000Z | |
| 60 | + updatedAt: 2026-11-26T15:40:00.000Z | |
| 61 | + closedAt: 2026-11-26T15:40:00.000Z | |
| 62 | + - id: 2 | |
| 63 | + title: "ACP façade: /redirect <message> runs a framed turn; bare /redirect answers without a turn" | |
| 64 | + state: closed | |
| 65 | + priority: high | |
| 66 | + author: | |
| 67 | + name: k33g | |
| 68 | + email: ph.charriere@gmail.com | |
| 69 | + createdAt: 2026-11-26T15:00:00.000Z | |
| 70 | + updatedAt: 2026-11-26T15:40:00.000Z | |
| 71 | + closedAt: 2026-11-26T15:40:00.000Z | |
| 72 | + - id: 3 | |
| 73 | + title: Docs EN+FR | |
| 74 | + state: closed | |
| 75 | + priority: medium | |
| 76 | + author: | |
| 77 | + name: k33g | |
| 78 | + email: ph.charriere@gmail.com | |
| 79 | + createdAt: 2026-11-26T15:00:00.000Z | |
| 80 | + updatedAt: 2026-11-26T15:40:00.000Z | |
| 81 | + closedAt: 2026-11-26T15:40:00.000Z | |
| 82 | +comments: | |
| 83 | + - id: 1 | |
| 84 | + author: | |
| 85 | + name: k33g | |
| 86 | + email: ph.charriere@gmail.com | |
| 87 | + createdAt: 2026-11-26T15:40:00.000Z | |
| 88 | + body: | | |
| 89 | + Implemented on branch feature/steer (with ticket 265): command.Redirect | |
| 90 | + (Editor, hint <message>), engine.Redirect/Unredirect (label + note), | |
| 91 | + acp redirectCommand after skillCommand, bare /redirect answered by | |
| 92 | + slashCommand (f.say), store.Questions strips the framing. Tests: | |
| 93 | + redirect_test.go, command/acp advertisement tests adapted (an editor | |
| 94 | + command with a hint advertises an input). Live: mm -acp driven by a | |
| 95 | + script imitating Zed's Send Now (prompt, session/cancel after 5 s, | |
| 96 | + then /redirect) with gpt-oss 20B on the host llama router: turn 3 | |
| 97 | + "cancelled", turn 4 continued the task with the correction (skipped | |
| 98 | + wc, answered in French). Not tried in Zed itself. | |
| new file mode 100644 | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | +# Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | ||
| 2 | +id: 267 | ||
| 3 | +title: "ACP: /redirect <message> — stop the turn (Zed's Send Now) and continue the task with the user's correction" | ||
| 4 | +state: closed | ||
| 5 | +author: | ||
| 6 | + name: k33g | ||
| 7 | + email: ph.charriere@gmail.com | ||
| 8 | +createdAt: 2026-11-26T15:00:00.000Z | ||
| 9 | +updatedAt: 2026-11-26T16:00:00.000Z | ||
| 10 | +closedAt: 2026-11-26T16:00:00.000Z | ||
| 11 | +labels: | ||
| 12 | + - enhancement | ||
| 13 | + - kind::feature | ||
| 14 | +milestone: v2.1.1 | ||
| 15 | +epic: ACP integration | ||
| 16 | +related: | ||
| 17 | + - 265 | ||
| 18 | + - 266 | ||
| 19 | +body: | | ||
| 20 | + The user's idea (2026-11-26), name chosen by the user among /redirect, | ||
| 21 | + /interrupt, /correct, /almost-steer: a workaround for the steer of | ||
| 22 | + ticket 265 in the editor until ACP v2 lets Zed send a prompt during a | ||
| 23 | + turn (ticket 266). | ||
| 24 | + | ||
| 25 | + ## What it does | ||
| 26 | + - Editor only (`command.Editor`): the line mode and the window steer for | ||
| 27 | + real (ticket 265). | ||
| 28 | + - Meant to be sent with Zed's "Send Now" (double Enter), which sends | ||
| 29 | + session/cancel then the prompt: the turn stops, and mm already keeps | ||
| 30 | + the cancelled turn's full history (session.AfterTurn) — the commands | ||
| 31 | + that ran, their results. | ||
| 32 | + - `/redirect <message>` runs a turn whose question is the message framed | ||
| 33 | + as a correction of the task in progress, not a new task: | ||
| 34 | + `[the user redirects the task in progress] <message>` followed by a | ||
| 35 | + note asking the model to continue the task it was working on with | ||
| 36 | + this taken into account. The framing is neutral about whether the turn | ||
| 37 | + was stopped: without Send Now, Zed holds the message until the turn | ||
| 38 | + ends, and it then simply continues the task. | ||
| 39 | + - `/redirect` alone answers that it needs a message, without a turn. | ||
| 40 | + - ↑ recall (store.Questions) shows the message as typed. | ||
| 41 | + | ||
| 42 | + ## Limits (to document) | ||
| 43 | + - The cancel comes first: a tool running at that moment (a bash | ||
| 44 | + command) is killed; a real steer waits for the step to end. | ||
| 45 | + - It only interrupts when sent with Send Now. | ||
| 46 | + | ||
| 47 | + ## Acceptance criteria | ||
| 48 | + - Command offered to the editor (available_commands), not to the | ||
| 49 | + terminal or the window; tests on the ACP façade (framed question, bare | ||
| 50 | + /redirect, history kept after a cancel); docs EN+FR. | ||
| 51 | +tasks: | ||
| 52 | + - id: 1 | ||
| 53 | + title: "Command /redirect (Editor), framing in the engine (label + note), ↑ recall strips them" | ||
| 54 | + state: closed | ||
| 55 | + priority: high | ||
| 56 | + author: | ||
| 57 | + name: k33g | ||
| 58 | + email: ph.charriere@gmail.com | ||
| 59 | + createdAt: 2026-11-26T15:00:00.000Z | ||
| 60 | + updatedAt: 2026-11-26T15:40:00.000Z | ||
| 61 | + closedAt: 2026-11-26T15:40:00.000Z | ||
| 62 | + - id: 2 | ||
| 63 | + title: "ACP façade: /redirect <message> runs a framed turn; bare /redirect answers without a turn" | ||
| 64 | + state: closed | ||
| 65 | + priority: high | ||
| 66 | + author: | ||
| 67 | + name: k33g | ||
| 68 | + email: ph.charriere@gmail.com | ||
| 69 | + createdAt: 2026-11-26T15:00:00.000Z | ||
| 70 | + updatedAt: 2026-11-26T15:40:00.000Z | ||
| 71 | + closedAt: 2026-11-26T15:40:00.000Z | ||
| 72 | + - id: 3 | ||
| 73 | + title: Docs EN+FR | ||
| 74 | + state: closed | ||
| 75 | + priority: medium | ||
| 76 | + author: | ||
| 77 | + name: k33g | ||
| 78 | + email: ph.charriere@gmail.com | ||
| 79 | + createdAt: 2026-11-26T15:00:00.000Z | ||
| 80 | + updatedAt: 2026-11-26T15:40:00.000Z | ||
| 81 | + closedAt: 2026-11-26T15:40:00.000Z | ||
| 82 | +comments: | ||
| 83 | + - id: 1 | ||
| 84 | + author: | ||
| 85 | + name: k33g | ||
| 86 | + email: ph.charriere@gmail.com | ||
| 87 | + createdAt: 2026-11-26T15:40:00.000Z | ||
| 88 | + body: | | ||
| 89 | + Implemented on branch feature/steer (with ticket 265): command.Redirect | ||
| 90 | + (Editor, hint <message>), engine.Redirect/Unredirect (label + note), | ||
| 91 | + acp redirectCommand after skillCommand, bare /redirect answered by | ||
| 92 | + slashCommand (f.say), store.Questions strips the framing. Tests: | ||
| 93 | + redirect_test.go, command/acp advertisement tests adapted (an editor | ||
| 94 | + command with a hint advertises an input). Live: mm -acp driven by a | ||
| 95 | + script imitating Zed's Send Now (prompt, session/cancel after 5 s, | ||
| 96 | + then /redirect) with gpt-oss 20B on the host llama router: turn 3 | ||
| 97 | + "cancelled", turn 4 continued the task with the correction (skipped | ||
| 98 | + wc, answered in French). Not tried in Zed itself. | ||
modified
README.md +1 -0 | @@ -151,6 +151,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h | ||
| 151 | 151 | | `demos/ollama/` | mm on Ollama | |
| 152 | 152 | | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B | |
| 153 | 153 | | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` | |
| 154 | +| `demos/steer/` | correct the agent while it works: steering a running turn (terminal, window) and `/redirect` (Zed), gpt-oss 20B on llama.cpp | | |
| 154 | 155 | | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off | |
| 155 | 156 | | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them | |
| 156 | 157 | | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) | |
| @@ -151,6 +151,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h | |||
| 151 | | `demos/ollama/` | mm on Ollama | | 151 | | `demos/ollama/` | mm on Ollama | |
| 152 | | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B | | 152 | | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B | |
| 153 | | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` | | 153 | | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` | |
| 154 | +| `demos/steer/` | correct the agent while it works: steering a running turn (terminal, window) and `/redirect` (Zed), gpt-oss 20B on llama.cpp | | ||
| 154 | | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off | | 155 | | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off | |
| 155 | | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them | | 156 | | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them | |
| 156 | | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) | | 157 | | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) | |
added
demos/steer/.gitignore +3 -0 | new file mode 100644 | ||
| @@ -0,0 +1,3 @@ | ||
| 1 | +!.mm | |
| 2 | +.mm/sessions | |
| 3 | +.mm/traces | |
| new file mode 100644 | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | +!.mm | ||
| 2 | +.mm/sessions | ||
| 3 | +.mm/traces | ||
added
demos/steer/.mm/agent.yaml +72 -0 | new file mode 100644 | ||
| @@ -0,0 +1,72 @@ | ||
| 1 | +# Skua — a demo agent to try steering (ticket 265) and /redirect (ticket 267). | |
| 2 | +# | |
| 3 | +# It inspects the notes in notes/ one at a time with ./inspect.sh, which | |
| 4 | +# waits a few seconds before showing each file: while it works, type a | |
| 5 | +# correction and press Enter (terminal, window), or send `/redirect …` with | |
| 6 | +# Send Now (Zed). See README.en.md. | |
| 7 | +# | |
| 8 | +# cd demos/steer && ../../mm line mode | |
| 9 | +# cd demos/steer && ../../mm -tui window | |
| 10 | +# Zed: AGENT_CONFIG=<abs path>/demos/steer/.mm/agent.yaml, args ["-acp"] | |
| 11 | + | |
| 12 | +provider: llamacpp | |
| 13 | +# gpt-oss 20B, the model the steer and /redirect were checked with (host | |
| 14 | +# llama-server router, 2026-11-26). Any model that calls tools works; a | |
| 15 | +# small one may ignore the correction more often. | |
| 16 | +model: "unsloth/gpt-oss-20b-GGUF:Q4_K_M" | |
| 17 | +# No baseUrl: llamacpp's defaults apply — 127.0.0.1:9931 (the Llama app, | |
| 18 | +# llama-server since b11521), then 8080, then host.docker.internal:9931. | |
| 19 | + | |
| 20 | +# Tools run without asking: a permission prompt in the middle of the turn | |
| 21 | +# would get in the way of what is being tried here. | |
| 22 | +yolo: true | |
| 23 | +bashTool: true | |
| 24 | +editTools: false | |
| 25 | +planTool: false | |
| 26 | +askUserTool: false | |
| 27 | +skillsDir: no-skills | |
| 28 | +# The model is shared with your other agents: leave it loaded on exit, and | |
| 29 | +# no unload_model tool (gpt-oss called it on "ChatGPT" in a test run). | |
| 30 | +unloadOnExit: false | |
| 31 | +unloadModels: false | |
| 32 | +maxTurns: 30 | |
| 33 | +# inspect.sh sleeps 8 s (INSPECT_DELAY) before it prints. | |
| 34 | +bashTimeout: 30s | |
| 35 | +watchdogTimeout: 30s | |
| 36 | +firstTokenTimeout: 3m | |
| 37 | + | |
| 38 | +sampling: | |
| 39 | + # family gpt-oss (mm init's presets): the model always reasons, never a | |
| 40 | + # low temperature | |
| 41 | + temperature: 1.0 | |
| 42 | + top_p: 1.0 | |
| 43 | + max_tokens: 8192 | |
| 44 | + # one tool call per reply: one note per step, so a correction lands | |
| 45 | + # between two notes | |
| 46 | + parallel_tool_calls: false | |
| 47 | + chat_template_kwargs: | |
| 48 | + # short reasoning: faster steps, more chances to steer between them | |
| 49 | + reasoning_effort: low | |
| 50 | + | |
| 51 | +sessions: | |
| 52 | + enabled: true | |
| 53 | + dir: .mm/sessions | |
| 54 | + | |
| 55 | +acp: | |
| 56 | + name: skua | |
| 57 | + title: "Skua (steer demo)" | |
| 58 | + | |
| 59 | +system: | | |
| 60 | + Your name is Skua. You work in a terminal, in a folder of notes about | |
| 61 | + seabirds (notes/*.md). | |
| 62 | + When asked to inspect the notes: | |
| 63 | + - list them with `ls notes`, then inspect them ONE AT A TIME, each with | |
| 64 | + its own bash call: `./inspect.sh notes/<file>`. Never inspect two files | |
| 65 | + in one command, and never read a note any other way (no cat, head, | |
| 66 | + read_file): inspect.sh is the only way, even if it is slow. | |
| 67 | + - after each file, write one short sentence about it. | |
| 68 | + - at the end, give a summary table: bird, where it breeds, one fact. | |
| 69 | + A user message that starts with "[message from the user during this | |
| 70 | + turn]" or "[the user redirects the task in progress]" is a correction of | |
| 71 | + the task you are doing: apply it from now on, and go on with the task | |
| 72 | + unless it tells you to stop. | |
| new file mode 100644 | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | +# Skua — a demo agent to try steering (ticket 265) and /redirect (ticket 267). | ||
| 2 | +# | ||
| 3 | +# It inspects the notes in notes/ one at a time with ./inspect.sh, which | ||
| 4 | +# waits a few seconds before showing each file: while it works, type a | ||
| 5 | +# correction and press Enter (terminal, window), or send `/redirect …` with | ||
| 6 | +# Send Now (Zed). See README.en.md. | ||
| 7 | +# | ||
| 8 | +# cd demos/steer && ../../mm line mode | ||
| 9 | +# cd demos/steer && ../../mm -tui window | ||
| 10 | +# Zed: AGENT_CONFIG=<abs path>/demos/steer/.mm/agent.yaml, args ["-acp"] | ||
| 11 | + | ||
| 12 | +provider: llamacpp | ||
| 13 | +# gpt-oss 20B, the model the steer and /redirect were checked with (host | ||
| 14 | +# llama-server router, 2026-11-26). Any model that calls tools works; a | ||
| 15 | +# small one may ignore the correction more often. | ||
| 16 | +model: "unsloth/gpt-oss-20b-GGUF:Q4_K_M" | ||
| 17 | +# No baseUrl: llamacpp's defaults apply — 127.0.0.1:9931 (the Llama app, | ||
| 18 | +# llama-server since b11521), then 8080, then host.docker.internal:9931. | ||
| 19 | + | ||
| 20 | +# Tools run without asking: a permission prompt in the middle of the turn | ||
| 21 | +# would get in the way of what is being tried here. | ||
| 22 | +yolo: true | ||
| 23 | +bashTool: true | ||
| 24 | +editTools: false | ||
| 25 | +planTool: false | ||
| 26 | +askUserTool: false | ||
| 27 | +skillsDir: no-skills | ||
| 28 | +# The model is shared with your other agents: leave it loaded on exit, and | ||
| 29 | +# no unload_model tool (gpt-oss called it on "ChatGPT" in a test run). | ||
| 30 | +unloadOnExit: false | ||
| 31 | +unloadModels: false | ||
| 32 | +maxTurns: 30 | ||
| 33 | +# inspect.sh sleeps 8 s (INSPECT_DELAY) before it prints. | ||
| 34 | +bashTimeout: 30s | ||
| 35 | +watchdogTimeout: 30s | ||
| 36 | +firstTokenTimeout: 3m | ||
| 37 | + | ||
| 38 | +sampling: | ||
| 39 | + # family gpt-oss (mm init's presets): the model always reasons, never a | ||
| 40 | + # low temperature | ||
| 41 | + temperature: 1.0 | ||
| 42 | + top_p: 1.0 | ||
| 43 | + max_tokens: 8192 | ||
| 44 | + # one tool call per reply: one note per step, so a correction lands | ||
| 45 | + # between two notes | ||
| 46 | + parallel_tool_calls: false | ||
| 47 | + chat_template_kwargs: | ||
| 48 | + # short reasoning: faster steps, more chances to steer between them | ||
| 49 | + reasoning_effort: low | ||
| 50 | + | ||
| 51 | +sessions: | ||
| 52 | + enabled: true | ||
| 53 | + dir: .mm/sessions | ||
| 54 | + | ||
| 55 | +acp: | ||
| 56 | + name: skua | ||
| 57 | + title: "Skua (steer demo)" | ||
| 58 | + | ||
| 59 | +system: | | ||
| 60 | + Your name is Skua. You work in a terminal, in a folder of notes about | ||
| 61 | + seabirds (notes/*.md). | ||
| 62 | + When asked to inspect the notes: | ||
| 63 | + - list them with `ls notes`, then inspect them ONE AT A TIME, each with | ||
| 64 | + its own bash call: `./inspect.sh notes/<file>`. Never inspect two files | ||
| 65 | + in one command, and never read a note any other way (no cat, head, | ||
| 66 | + read_file): inspect.sh is the only way, even if it is slow. | ||
| 67 | + - after each file, write one short sentence about it. | ||
| 68 | + - at the end, give a summary table: bird, where it breeds, one fact. | ||
| 69 | + A user message that starts with "[message from the user during this | ||
| 70 | + turn]" or "[the user redirects the task in progress]" is a correction of | ||
| 71 | + the task you are doing: apply it from now on, and go on with the task | ||
| 72 | + unless it tells you to stop. | ||
added
demos/steer/README.en.md +62 -0 | new file mode 100644 | ||
| @@ -0,0 +1,62 @@ | ||
| 1 | +# Steer demo — correct the agent while it works | |
| 2 | + | |
| 3 | +This folder is a small playground for two features: **steering** a running turn in the terminal and the window (ticket 265), and **`/redirect`** in an editor (ticket 267). The agent, Skua, inspects the notes in `notes/` one at a time with `./inspect.sh`, which waits 8 seconds before it shows each file. That leaves time to type a correction while it works. | |
| 4 | + | |
| 5 | +| File | What it is | | |
| 6 | +|------|------------| | |
| 7 | +| `.mm/agent.yaml` | the agent: `provider: llamacpp`, `unsloth/gpt-oss-20b-GGUF:Q4_K_M`, `yolo: true`, one tool call per reply | | |
| 8 | +| `inspect.sh` | shows one note after `INSPECT_DELAY` seconds (default 8) | | |
| 9 | +| `notes/` | six notes about seabirds — five auks and one penguin | | |
| 10 | + | |
| 11 | +Version française : [README.fr.md](README.fr.md). | |
| 12 | + | |
| 13 | +## Before you start | |
| 14 | + | |
| 15 | +The model runs on llama-server on 127.0.0.1:9931 (the Llama app, or `llama-server` in router mode) with `unsloth/gpt-oss-20b-GGUF:Q4_K_M`. Another model that calls tools works too: change `model:` in `.mm/agent.yaml`. | |
| 16 | + | |
| 17 | +## Steer in the terminal or the window | |
| 18 | + | |
| 19 | +```bash | |
| 20 | +cd demos/steer | |
| 21 | +../../mm # line mode | |
| 22 | +../../mm -tui # or the window | |
| 23 | +``` | |
| 24 | + | |
| 25 | +1. Ask: `Inspect the notes.` | |
| 26 | +2. While it runs `./inspect.sh`, type a correction and press Enter, for example `skip the emperor penguin, it is not an auk, and write the summary in French`. | |
| 27 | +3. Watch for `↪ Steering`, then `↪ Steered: …` once the model has it. The turn goes on: the next notes are inspected with your correction applied. | |
| 28 | + | |
| 29 | +Try also: | |
| 30 | + | |
| 31 | +- `/queue list the three shortest notes` during the turn: it waits and runs as the next question. | |
| 32 | +- A correction typed while the model writes its final summary: it comes after the model's last call, so it runs as the next question (`⏳ 1 message(s) came after the model's last call …`). | |
| 33 | + | |
| 34 | +## `/redirect` in Zed | |
| 35 | + | |
| 36 | +Zed keeps a message typed during an external agent's turn until the turn ends, so the agent cannot steer there yet (ticket 266). `/redirect` is the nearest thing. | |
| 37 | + | |
| 38 | +1. Add the agent to Zed's `settings.json`, with the absolute path of this folder's agent file: | |
| 39 | + | |
| 40 | + ```json | |
| 41 | + "agent_servers": { | |
| 42 | + "skua": { | |
| 43 | + "type": "custom", | |
| 44 | + "command": "/absolute/path/to/mm", | |
| 45 | + "args": ["-acp"], | |
| 46 | + "env": { "AGENT_CONFIG": "/absolute/path/to/mini-me/demos/steer/.mm/agent.yaml" } | |
| 47 | + } | |
| 48 | + } | |
| 49 | + ``` | |
| 50 | + | |
| 51 | +2. Open this folder in Zed, start a Skua thread, and ask `Inspect the notes.` | |
| 52 | +3. While it works, type `/redirect skip the emperor penguin and answer in French` and send it with **Send Now** (double Enter). The turn stops, and the model continues the same task with your correction: what it already inspected is kept. | |
| 53 | + | |
| 54 | +A note being shown at that moment is cut off with the turn: that is the difference with a real steer. | |
| 55 | + | |
| 56 | +## What was checked (2026-11-26, from an sbx sandbox, llama-server router on the Mac) | |
| 57 | + | |
| 58 | +- Line mode, piped input: the correction typed during `./inspect.sh notes/atlantic-puffin.md` was taken after that step (`↪ Steered: …`), the emperor penguin was skipped, and the summary came in French. | |
| 59 | +- `/redirect` over ACP, with a script that plays Zed's Send Now (a prompt, `session/cancel` 5 s later, then `/redirect`): the cancelled turn's work was kept and the task went on with the correction. Not tried in Zed itself, nor in the window (no terminal in the sandbox). | |
| 60 | +- Four line-mode runs in all. gpt-oss 20B varies from run to run: it once ended its turn after the first note (the correction then ran as the next question, as designed), once read the notes with `cat` instead of `inspect.sh` (the system prompt now forbids it), and in the last run re-ran a note with `sh inspect.sh` and left one note out. The steer itself was taken every time it arrived during the turn. | |
| 61 | +- In the first run, the model called the `unload_model` tool on "ChatGPT": the file now has `unloadModels: false`. | |
| 62 | +- The start-up line `[warning: no skills found in …/no-skills …]` is expected: this agent has no skills. | |
| new file mode 100644 | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | +# Steer demo — correct the agent while it works | ||
| 2 | + | ||
| 3 | +This folder is a small playground for two features: **steering** a running turn in the terminal and the window (ticket 265), and **`/redirect`** in an editor (ticket 267). The agent, Skua, inspects the notes in `notes/` one at a time with `./inspect.sh`, which waits 8 seconds before it shows each file. That leaves time to type a correction while it works. | ||
| 4 | + | ||
| 5 | +| File | What it is | | ||
| 6 | +|------|------------| | ||
| 7 | +| `.mm/agent.yaml` | the agent: `provider: llamacpp`, `unsloth/gpt-oss-20b-GGUF:Q4_K_M`, `yolo: true`, one tool call per reply | | ||
| 8 | +| `inspect.sh` | shows one note after `INSPECT_DELAY` seconds (default 8) | | ||
| 9 | +| `notes/` | six notes about seabirds — five auks and one penguin | | ||
| 10 | + | ||
| 11 | +Version française : [README.fr.md](README.fr.md). | ||
| 12 | + | ||
| 13 | +## Before you start | ||
| 14 | + | ||
| 15 | +The model runs on llama-server on 127.0.0.1:9931 (the Llama app, or `llama-server` in router mode) with `unsloth/gpt-oss-20b-GGUF:Q4_K_M`. Another model that calls tools works too: change `model:` in `.mm/agent.yaml`. | ||
| 16 | + | ||
| 17 | +## Steer in the terminal or the window | ||
| 18 | + | ||
| 19 | +```bash | ||
| 20 | +cd demos/steer | ||
| 21 | +../../mm # line mode | ||
| 22 | +../../mm -tui # or the window | ||
| 23 | +``` | ||
| 24 | + | ||
| 25 | +1. Ask: `Inspect the notes.` | ||
| 26 | +2. While it runs `./inspect.sh`, type a correction and press Enter, for example `skip the emperor penguin, it is not an auk, and write the summary in French`. | ||
| 27 | +3. Watch for `↪ Steering`, then `↪ Steered: …` once the model has it. The turn goes on: the next notes are inspected with your correction applied. | ||
| 28 | + | ||
| 29 | +Try also: | ||
| 30 | + | ||
| 31 | +- `/queue list the three shortest notes` during the turn: it waits and runs as the next question. | ||
| 32 | +- A correction typed while the model writes its final summary: it comes after the model's last call, so it runs as the next question (`⏳ 1 message(s) came after the model's last call …`). | ||
| 33 | + | ||
| 34 | +## `/redirect` in Zed | ||
| 35 | + | ||
| 36 | +Zed keeps a message typed during an external agent's turn until the turn ends, so the agent cannot steer there yet (ticket 266). `/redirect` is the nearest thing. | ||
| 37 | + | ||
| 38 | +1. Add the agent to Zed's `settings.json`, with the absolute path of this folder's agent file: | ||
| 39 | + | ||
| 40 | + ```json | ||
| 41 | + "agent_servers": { | ||
| 42 | + "skua": { | ||
| 43 | + "type": "custom", | ||
| 44 | + "command": "/absolute/path/to/mm", | ||
| 45 | + "args": ["-acp"], | ||
| 46 | + "env": { "AGENT_CONFIG": "/absolute/path/to/mini-me/demos/steer/.mm/agent.yaml" } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + ``` | ||
| 50 | + | ||
| 51 | +2. Open this folder in Zed, start a Skua thread, and ask `Inspect the notes.` | ||
| 52 | +3. While it works, type `/redirect skip the emperor penguin and answer in French` and send it with **Send Now** (double Enter). The turn stops, and the model continues the same task with your correction: what it already inspected is kept. | ||
| 53 | + | ||
| 54 | +A note being shown at that moment is cut off with the turn: that is the difference with a real steer. | ||
| 55 | + | ||
| 56 | +## What was checked (2026-11-26, from an sbx sandbox, llama-server router on the Mac) | ||
| 57 | + | ||
| 58 | +- Line mode, piped input: the correction typed during `./inspect.sh notes/atlantic-puffin.md` was taken after that step (`↪ Steered: …`), the emperor penguin was skipped, and the summary came in French. | ||
| 59 | +- `/redirect` over ACP, with a script that plays Zed's Send Now (a prompt, `session/cancel` 5 s later, then `/redirect`): the cancelled turn's work was kept and the task went on with the correction. Not tried in Zed itself, nor in the window (no terminal in the sandbox). | ||
| 60 | +- Four line-mode runs in all. gpt-oss 20B varies from run to run: it once ended its turn after the first note (the correction then ran as the next question, as designed), once read the notes with `cat` instead of `inspect.sh` (the system prompt now forbids it), and in the last run re-ran a note with `sh inspect.sh` and left one note out. The steer itself was taken every time it arrived during the turn. | ||
| 61 | +- In the first run, the model called the `unload_model` tool on "ChatGPT": the file now has `unloadModels: false`. | ||
| 62 | +- The start-up line `[warning: no skills found in …/no-skills …]` is expected: this agent has no skills. | ||
added
demos/steer/README.fr.md +62 -0 | new file mode 100644 | ||
| @@ -0,0 +1,62 @@ | ||
| 1 | +# Démo steer — corriger l'agent pendant qu'il travaille | |
| 2 | + | |
| 3 | +Ce dossier est un petit terrain d'essai pour deux fonctions : **réorienter** (steer) un tour en cours dans le terminal et la fenêtre (ticket 265), et **`/redirect`** dans un éditeur (ticket 267). L'agent, Skua, inspecte les notes de `notes/` une par une avec `./inspect.sh`, qui attend 8 secondes avant d'afficher chaque fichier. Ça laisse le temps de taper une correction pendant qu'il travaille. | |
| 4 | + | |
| 5 | +| Fichier | Ce que c'est | | |
| 6 | +|---------|--------------| | |
| 7 | +| `.mm/agent.yaml` | l'agent : `provider: llamacpp`, `unsloth/gpt-oss-20b-GGUF:Q4_K_M`, `yolo: true`, un appel d'outil par réponse | | |
| 8 | +| `inspect.sh` | affiche une note au bout de `INSPECT_DELAY` secondes (8 par défaut) | | |
| 9 | +| `notes/` | six notes sur des oiseaux marins — cinq alcidés et un manchot | | |
| 10 | + | |
| 11 | +English version: [README.en.md](README.en.md). | |
| 12 | + | |
| 13 | +## Avant de commencer | |
| 14 | + | |
| 15 | +Le modèle tourne sur llama-server en 127.0.0.1:9931 (l'application Llama, ou `llama-server` en mode routeur) avec `unsloth/gpt-oss-20b-GGUF:Q4_K_M`. Un autre modèle qui appelle des outils marche aussi : changez `model:` dans `.mm/agent.yaml`. | |
| 16 | + | |
| 17 | +## Réorienter dans le terminal ou la fenêtre | |
| 18 | + | |
| 19 | +```bash | |
| 20 | +cd demos/steer | |
| 21 | +../../mm # mode ligne | |
| 22 | +../../mm -tui # ou la fenêtre | |
| 23 | +``` | |
| 24 | + | |
| 25 | +1. Demandez : `Inspect the notes.` | |
| 26 | +2. Pendant qu'il lance `./inspect.sh`, tapez une correction et appuyez sur Entrée, par exemple `skip the emperor penguin, it is not an auk, and write the summary in French`. | |
| 27 | +3. Guettez `↪ Steering`, puis `↪ Steered: …` quand le modèle l'a reçue. Le tour continue : les notes suivantes sont inspectées avec votre correction. | |
| 28 | + | |
| 29 | +Essayez aussi : | |
| 30 | + | |
| 31 | +- `/queue list the three shortest notes` pendant le tour : la question attend et part comme question suivante. | |
| 32 | +- Une correction tapée pendant que le modèle écrit son résumé final : elle arrive après le dernier appel du modèle, elle part donc comme question suivante (`⏳ 1 message(s) came after the model's last call …`). | |
| 33 | + | |
| 34 | +## `/redirect` dans Zed | |
| 35 | + | |
| 36 | +Zed garde un message tapé pendant le tour d'un agent externe jusqu'à la fin du tour : l'agent ne peut donc pas encore y être réorienté (ticket 266). `/redirect` s'en approche le plus. | |
| 37 | + | |
| 38 | +1. Ajoutez l'agent au `settings.json` de Zed, avec le chemin absolu du fichier d'agent de ce dossier : | |
| 39 | + | |
| 40 | + ```json | |
| 41 | + "agent_servers": { | |
| 42 | + "skua": { | |
| 43 | + "type": "custom", | |
| 44 | + "command": "/chemin/absolu/vers/mm", | |
| 45 | + "args": ["-acp"], | |
| 46 | + "env": { "AGENT_CONFIG": "/chemin/absolu/vers/mini-me/demos/steer/.mm/agent.yaml" } | |
| 47 | + } | |
| 48 | + } | |
| 49 | + ``` | |
| 50 | + | |
| 51 | +2. Ouvrez ce dossier dans Zed, démarrez une conversation avec Skua, et demandez `Inspect the notes.` | |
| 52 | +3. Pendant qu'il travaille, tapez `/redirect skip the emperor penguin and answer in French` et envoyez-le avec **Send Now** (double Entrée). Le tour s'arrête, et le modèle reprend la même tâche avec votre correction : ce qu'il a déjà inspecté est gardé. | |
| 53 | + | |
| 54 | +Une note en cours d'affichage à ce moment-là est coupée avec le tour : c'est la différence avec un vrai steer. | |
| 55 | + | |
| 56 | +## Ce qui a été vérifié (26/11/2026, depuis un sandbox sbx, routeur llama-server sur le Mac) | |
| 57 | + | |
| 58 | +- Mode ligne, entrée par un pipe : la correction tapée pendant `./inspect.sh notes/atlantic-puffin.md` a été prise après cette étape (`↪ Steered: …`), le manchot empereur a été sauté, et le résumé est arrivé en français. | |
| 59 | +- `/redirect` par ACP, avec un script qui joue le Send Now de Zed (un prompt, `session/cancel` 5 s plus tard, puis `/redirect`) : le travail du tour annulé a été gardé et la tâche a continué avec la correction. Pas essayé dans Zed lui-même, ni dans la fenêtre (pas de terminal dans le sandbox). | |
| 60 | +- Quatre essais en mode ligne en tout. gpt-oss 20B varie d'un essai à l'autre : il a une fois terminé son tour après la première note (la correction est alors partie comme question suivante, comme prévu), une fois lu les notes avec `cat` au lieu d'`inspect.sh` (le prompt système l'interdit maintenant), et au dernier essai il a relancé une note avec `sh inspect.sh` et en a oublié une. Le steer lui-même a été pris à chaque fois qu'il arrivait pendant le tour. | |
| 61 | +- Au premier essai, le modèle a appelé l'outil `unload_model` sur « ChatGPT » : le fichier a maintenant `unloadModels: false`. | |
| 62 | +- La ligne de démarrage `[warning: no skills found in …/no-skills …]` est normale : cet agent n'a pas de skill. | |
| new file mode 100644 | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | +# Démo steer — corriger l'agent pendant qu'il travaille | ||
| 2 | + | ||
| 3 | +Ce dossier est un petit terrain d'essai pour deux fonctions : **réorienter** (steer) un tour en cours dans le terminal et la fenêtre (ticket 265), et **`/redirect`** dans un éditeur (ticket 267). L'agent, Skua, inspecte les notes de `notes/` une par une avec `./inspect.sh`, qui attend 8 secondes avant d'afficher chaque fichier. Ça laisse le temps de taper une correction pendant qu'il travaille. | ||
| 4 | + | ||
| 5 | +| Fichier | Ce que c'est | | ||
| 6 | +|---------|--------------| | ||
| 7 | +| `.mm/agent.yaml` | l'agent : `provider: llamacpp`, `unsloth/gpt-oss-20b-GGUF:Q4_K_M`, `yolo: true`, un appel d'outil par réponse | | ||
| 8 | +| `inspect.sh` | affiche une note au bout de `INSPECT_DELAY` secondes (8 par défaut) | | ||
| 9 | +| `notes/` | six notes sur des oiseaux marins — cinq alcidés et un manchot | | ||
| 10 | + | ||
| 11 | +English version: [README.en.md](README.en.md). | ||
| 12 | + | ||
| 13 | +## Avant de commencer | ||
| 14 | + | ||
| 15 | +Le modèle tourne sur llama-server en 127.0.0.1:9931 (l'application Llama, ou `llama-server` en mode routeur) avec `unsloth/gpt-oss-20b-GGUF:Q4_K_M`. Un autre modèle qui appelle des outils marche aussi : changez `model:` dans `.mm/agent.yaml`. | ||
| 16 | + | ||
| 17 | +## Réorienter dans le terminal ou la fenêtre | ||
| 18 | + | ||
| 19 | +```bash | ||
| 20 | +cd demos/steer | ||
| 21 | +../../mm # mode ligne | ||
| 22 | +../../mm -tui # ou la fenêtre | ||
| 23 | +``` | ||
| 24 | + | ||
| 25 | +1. Demandez : `Inspect the notes.` | ||
| 26 | +2. Pendant qu'il lance `./inspect.sh`, tapez une correction et appuyez sur Entrée, par exemple `skip the emperor penguin, it is not an auk, and write the summary in French`. | ||
| 27 | +3. Guettez `↪ Steering`, puis `↪ Steered: …` quand le modèle l'a reçue. Le tour continue : les notes suivantes sont inspectées avec votre correction. | ||
| 28 | + | ||
| 29 | +Essayez aussi : | ||
| 30 | + | ||
| 31 | +- `/queue list the three shortest notes` pendant le tour : la question attend et part comme question suivante. | ||
| 32 | +- Une correction tapée pendant que le modèle écrit son résumé final : elle arrive après le dernier appel du modèle, elle part donc comme question suivante (`⏳ 1 message(s) came after the model's last call …`). | ||
| 33 | + | ||
| 34 | +## `/redirect` dans Zed | ||
| 35 | + | ||
| 36 | +Zed garde un message tapé pendant le tour d'un agent externe jusqu'à la fin du tour : l'agent ne peut donc pas encore y être réorienté (ticket 266). `/redirect` s'en approche le plus. | ||
| 37 | + | ||
| 38 | +1. Ajoutez l'agent au `settings.json` de Zed, avec le chemin absolu du fichier d'agent de ce dossier : | ||
| 39 | + | ||
| 40 | + ```json | ||
| 41 | + "agent_servers": { | ||
| 42 | + "skua": { | ||
| 43 | + "type": "custom", | ||
| 44 | + "command": "/chemin/absolu/vers/mm", | ||
| 45 | + "args": ["-acp"], | ||
| 46 | + "env": { "AGENT_CONFIG": "/chemin/absolu/vers/mini-me/demos/steer/.mm/agent.yaml" } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + ``` | ||
| 50 | + | ||
| 51 | +2. Ouvrez ce dossier dans Zed, démarrez une conversation avec Skua, et demandez `Inspect the notes.` | ||
| 52 | +3. Pendant qu'il travaille, tapez `/redirect skip the emperor penguin and answer in French` et envoyez-le avec **Send Now** (double Entrée). Le tour s'arrête, et le modèle reprend la même tâche avec votre correction : ce qu'il a déjà inspecté est gardé. | ||
| 53 | + | ||
| 54 | +Une note en cours d'affichage à ce moment-là est coupée avec le tour : c'est la différence avec un vrai steer. | ||
| 55 | + | ||
| 56 | +## Ce qui a été vérifié (26/11/2026, depuis un sandbox sbx, routeur llama-server sur le Mac) | ||
| 57 | + | ||
| 58 | +- Mode ligne, entrée par un pipe : la correction tapée pendant `./inspect.sh notes/atlantic-puffin.md` a été prise après cette étape (`↪ Steered: …`), le manchot empereur a été sauté, et le résumé est arrivé en français. | ||
| 59 | +- `/redirect` par ACP, avec un script qui joue le Send Now de Zed (un prompt, `session/cancel` 5 s plus tard, puis `/redirect`) : le travail du tour annulé a été gardé et la tâche a continué avec la correction. Pas essayé dans Zed lui-même, ni dans la fenêtre (pas de terminal dans le sandbox). | ||
| 60 | +- Quatre essais en mode ligne en tout. gpt-oss 20B varie d'un essai à l'autre : il a une fois terminé son tour après la première note (la correction est alors partie comme question suivante, comme prévu), une fois lu les notes avec `cat` au lieu d'`inspect.sh` (le prompt système l'interdit maintenant), et au dernier essai il a relancé une note avec `sh inspect.sh` et en a oublié une. Le steer lui-même a été pris à chaque fois qu'il arrivait pendant le tour. | ||
| 61 | +- Au premier essai, le modèle a appelé l'outil `unload_model` sur « ChatGPT » : le fichier a maintenant `unloadModels: false`. | ||
| 62 | +- La ligne de démarrage `[warning: no skills found in …/no-skills …]` est normale : cet agent n'a pas de skill. | ||
added
demos/steer/inspect.sh +11 -0 | new file mode 100755 | ||
| @@ -0,0 +1,11 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +# Shows one note, slowly: the pause leaves time to type a correction while | |
| 3 | +# the agent works (steer in the terminal and the window, /redirect in Zed). | |
| 4 | +set -eu | |
| 5 | +if [ $# -ne 1 ] || [ ! -f "$1" ]; then | |
| 6 | + echo "usage: ./inspect.sh notes/<file>" >&2 | |
| 7 | + exit 2 | |
| 8 | +fi | |
| 9 | +sleep "${INSPECT_DELAY:-8}" | |
| 10 | +wc -w "$1" | |
| 11 | +cat "$1" | |
| new file mode 100755 | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | +#!/bin/sh | ||
| 2 | +# Shows one note, slowly: the pause leaves time to type a correction while | ||
| 3 | +# the agent works (steer in the terminal and the window, /redirect in Zed). | ||
| 4 | +set -eu | ||
| 5 | +if [ $# -ne 1 ] || [ ! -f "$1" ]; then | ||
| 6 | + echo "usage: ./inspect.sh notes/<file>" >&2 | ||
| 7 | + exit 2 | ||
| 8 | +fi | ||
| 9 | +sleep "${INSPECT_DELAY:-8}" | ||
| 10 | +wc -w "$1" | ||
| 11 | +cat "$1" | ||
added
demos/steer/notes/atlantic-puffin.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Atlantic puffin | |
| 2 | +Seabird of the North Atlantic. Nests in burrows on cliff tops, from Brittany to Iceland. Dives for sand eels and carries up to ten fish across its bill. Its bill is bright orange only in the breeding season. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Atlantic puffin | ||
| 2 | +Seabird of the North Atlantic. Nests in burrows on cliff tops, from Brittany to Iceland. Dives for sand eels and carries up to ten fish across its bill. Its bill is bright orange only in the breeding season. | ||
added
demos/steer/notes/common-guillemot.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Common guillemot | |
| 2 | +The most numerous auk of the North Atlantic and North Pacific. Lays a single pointed egg on bare rock ledges; the shape keeps it from rolling off. Chicks jump from the cliff before they can fly. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Common guillemot | ||
| 2 | +The most numerous auk of the North Atlantic and North Pacific. Lays a single pointed egg on bare rock ledges; the shape keeps it from rolling off. Chicks jump from the cliff before they can fly. | ||
added
demos/steer/notes/emperor-penguin.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Emperor penguin | |
| 2 | +The largest penguin, from Antarctica only. Breeds in winter on the sea ice; the male holds the egg on his feet for about two months without eating. Not an auk: penguins live in the southern hemisphere and cannot fly. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Emperor penguin | ||
| 2 | +The largest penguin, from Antarctica only. Breeds in winter on the sea ice; the male holds the egg on his feet for about two months without eating. Not an auk: penguins live in the southern hemisphere and cannot fly. | ||
added
demos/steer/notes/great-auk.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Great auk | |
| 2 | +A large flightless auk of the North Atlantic, extinct since 1844. The first bird to be called "penguin". Hunted for its feathers, meat and oil until the last known pair was killed in Iceland. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Great auk | ||
| 2 | +A large flightless auk of the North Atlantic, extinct since 1844. The first bird to be called "penguin". Hunted for its feathers, meat and oil until the last known pair was killed in Iceland. | ||
added
demos/steer/notes/little-auk.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Little auk | |
| 2 | +The smallest auk of the Atlantic, about the size of a starling. Breeds by the million in the high Arctic, on Svalbard and in Greenland, and feeds on tiny crustaceans. Winters at sea, sometimes blown to European coasts by storms. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Little auk | ||
| 2 | +The smallest auk of the Atlantic, about the size of a starling. Breeds by the million in the high Arctic, on Svalbard and in Greenland, and feeds on tiny crustaceans. Winters at sea, sometimes blown to European coasts by storms. | ||
added
demos/steer/notes/razorbill.md +2 -0 | new file mode 100644 | ||
| @@ -0,0 +1,2 @@ | ||
| 1 | +# Razorbill | |
| 2 | +An auk with a thick, flat black bill crossed by a white line. Breeds on the cliffs of the North Atlantic and the Baltic. A strong diver: it can reach 120 metres. The closest living relative of the extinct great auk. | |
| new file mode 100644 | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# Razorbill | ||
| 2 | +An auk with a thick, flat black bill crossed by a white line. Breeds on the cliffs of the North Atlantic and the Baltic. A strong diver: it can reach 120 metres. The closest living relative of the extinct great auk. | ||
modified
docs/en/README.md +1 -0 | @@ -109,6 +109,7 @@ This documentation is organised along the four [Diátaxis](https://diataxis.fr) | ||
| 109 | 109 | - [Guard models](explanation/guard-models.md) — why the system message is a risk name, why each guard judges the question alone (`-p`), why a hook rather than `ask_agent`, who reacts (the model or the hook), failing closed, what guards do not give you |
| 110 | 110 | - [Decision models](explanation/decision-models.md) — why a decider is an agent, why routing appends the `$skill` line, the server's confidence, what was measured (0 wrong picks on 23 cases; 12 → 16 right with a 4B chat model), why not decision-4b; why command triage and tool routing only ever remove (questions, tools), a decider on its own |
| 111 | 111 | - [ACP client tools](explanation/acp-client-tools.md) — why mm needed its own convention on top of ACP's extension methods, why `meta` is the default discovery, the session in `_meta`, dynamic tools per session, errors as answers, why not `mcpServers` |
| 112 | +- [Steering a running turn](explanation/steering.md) — how a question sent during a turn reaches the model at its next call, why only after tool results, why Enter steers and `/queue` waits, where it does not exist (Zed) | |
| 112 | 113 | - Package diagram (draw.io source): [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) |
| 113 | 114 | |
| 114 | 115 | ### MCP (Model Context Protocol) Explanation |
| @@ -109,6 +109,7 @@ This documentation is organised along the four [Diátaxis](https://diataxis.fr) | |||
| 109 | - [Guard models](explanation/guard-models.md) — why the system message is a risk name, why each guard judges the question alone (`-p`), why a hook rather than `ask_agent`, who reacts (the model or the hook), failing closed, what guards do not give you | 109 | - [Guard models](explanation/guard-models.md) — why the system message is a risk name, why each guard judges the question alone (`-p`), why a hook rather than `ask_agent`, who reacts (the model or the hook), failing closed, what guards do not give you |
| 110 | - [Decision models](explanation/decision-models.md) — why a decider is an agent, why routing appends the `$skill` line, the server's confidence, what was measured (0 wrong picks on 23 cases; 12 → 16 right with a 4B chat model), why not decision-4b; why command triage and tool routing only ever remove (questions, tools), a decider on its own | 110 | - [Decision models](explanation/decision-models.md) — why a decider is an agent, why routing appends the `$skill` line, the server's confidence, what was measured (0 wrong picks on 23 cases; 12 → 16 right with a 4B chat model), why not decision-4b; why command triage and tool routing only ever remove (questions, tools), a decider on its own |
| 111 | - [ACP client tools](explanation/acp-client-tools.md) — why mm needed its own convention on top of ACP's extension methods, why `meta` is the default discovery, the session in `_meta`, dynamic tools per session, errors as answers, why not `mcpServers` | 111 | - [ACP client tools](explanation/acp-client-tools.md) — why mm needed its own convention on top of ACP's extension methods, why `meta` is the default discovery, the session in `_meta`, dynamic tools per session, errors as answers, why not `mcpServers` |
| 112 | +- [Steering a running turn](explanation/steering.md) — how a question sent during a turn reaches the model at its next call, why only after tool results, why Enter steers and `/queue` waits, where it does not exist (Zed) | ||
| 112 | - Package diagram (draw.io source): [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) | 113 | - Package diagram (draw.io source): [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) |
| 113 | 114 | ||
| 114 | ### MCP (Model Context Protocol) Explanation | 115 | ### MCP (Model Context Protocol) Explanation |
added
docs/en/explanation/steering.md +34 -0 | new file mode 100644 | ||
| @@ -0,0 +1,34 @@ | ||
| 1 | +# Steering a running turn | |
| 2 | + | |
| 3 | +## What is this about? | |
| 4 | + | |
| 5 | +A turn is often long: the model calls a tool, reads the result, calls another, and so on, sometimes for dozens of steps. When you see it going the wrong way, you want to tell it — without throwing away what it has done. In the line mode and in the window, a question sent during a turn does that: it reaches the model at its next call, inside the same turn (ticket 265). This page explains how, and why it works the way it does. | |
| 6 | + | |
| 7 | +## How it works | |
| 8 | + | |
| 9 | +Each turn gets an inbox. A question sent during a turn (Enter) goes into it. Before every call to the model, the turn looks at the inbox, and when the call follows tool results it appends the waiting questions to the history as user messages, labelled `[message from the user during this turn]`. The label tells the model it is a correction of the task in progress, not a new task. From then on the question is part of the turn: the next calls carry it, the session keeps it, and ↑ recalls it without the label. | |
| 10 | + | |
| 11 | +The hook is the same one that shrinks a long turn before a call when it passes the context threshold (in-turn compression): the one place where mm sees every model call of a turn and can change what the model reads. | |
| 12 | + | |
| 13 | +## Why only after tool results | |
| 14 | + | |
| 15 | +A question is taken only by a call that follows tool results. A user message right after the question, or right after the model's own answer, is two user turns in a row or a turn after the end — shapes chat templates handle badly or not at all. After tool results, a user message is ordinary OpenAI wire; it was checked on llama.cpp with gpt-oss 20B, Qwen3.5 2B and LFM3 1.7B, which all answered with the correction applied. | |
| 16 | + | |
| 17 | +The consequence: a question sent while the model writes its final answer — no tool call, so no call after it — comes too late for this turn. It is not lost: when the turn ends, mm runs it as the next question and says so. | |
| 18 | + | |
| 19 | +## Why Enter steers, and `/queue` waits | |
| 20 | + | |
| 21 | +Before, Enter during a turn queued the question for after the turn (ticket 155), so the model only saw a correction once it had finished, often after many steps in the wrong direction. Steering is what a correction needs, so it got the key you press without thinking. Queueing is still useful — "and then, write the tests" — so it moved to `/queue <question>`, in both the line mode and the window. Alt-Enter was not used for it: it already inserts a newline, like Ctrl-J. | |
| 22 | + | |
| 23 | +Slash commands are never steered: they act on the session (`/new`, `/compact`…) and wait for the turn to end, as before. | |
| 24 | + | |
| 25 | +## Where it does not exist | |
| 26 | + | |
| 27 | +- **The editor (ACP)**: Zed keeps a message typed during an external agent's turn in its own queue and sends it when the turn ends; its "Steer" toggle serves Zed's own agent only. ACP's v2 prompt RFD lets a client send a prompt during a turn; once Zed and the Go SDK speak it, the same inbox can take it (ticket 266). Until then, `/redirect <message>` (ticket 267) is the nearest thing: sent with Zed's "Send Now", which cancels the turn first, it runs a turn on the history the cancelled one left — mm keeps its commands and results — with the message framed as a correction of that task. It is not a steer: the turn does stop, and a command running at that moment is stopped with it. | |
| 28 | +- **`mm -p` and asked agents** have no user during the turn. | |
| 29 | + | |
| 30 | +## See also | |
| 31 | + | |
| 32 | +- The keys and messages: [slash commands and window keys](../reference/slash-commands.md). | |
| 33 | +- Using it: [How to use the window mode](../how-to/use-the-window-mode.md). | |
| 34 | +- The other thing that rewrites a turn between calls: [context compression](context-compression.md). | |
| new file mode 100644 | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | +# Steering a running turn | ||
| 2 | + | ||
| 3 | +## What is this about? | ||
| 4 | + | ||
| 5 | +A turn is often long: the model calls a tool, reads the result, calls another, and so on, sometimes for dozens of steps. When you see it going the wrong way, you want to tell it — without throwing away what it has done. In the line mode and in the window, a question sent during a turn does that: it reaches the model at its next call, inside the same turn (ticket 265). This page explains how, and why it works the way it does. | ||
| 6 | + | ||
| 7 | +## How it works | ||
| 8 | + | ||
| 9 | +Each turn gets an inbox. A question sent during a turn (Enter) goes into it. Before every call to the model, the turn looks at the inbox, and when the call follows tool results it appends the waiting questions to the history as user messages, labelled `[message from the user during this turn]`. The label tells the model it is a correction of the task in progress, not a new task. From then on the question is part of the turn: the next calls carry it, the session keeps it, and ↑ recalls it without the label. | ||
| 10 | + | ||
| 11 | +The hook is the same one that shrinks a long turn before a call when it passes the context threshold (in-turn compression): the one place where mm sees every model call of a turn and can change what the model reads. | ||
| 12 | + | ||
| 13 | +## Why only after tool results | ||
| 14 | + | ||
| 15 | +A question is taken only by a call that follows tool results. A user message right after the question, or right after the model's own answer, is two user turns in a row or a turn after the end — shapes chat templates handle badly or not at all. After tool results, a user message is ordinary OpenAI wire; it was checked on llama.cpp with gpt-oss 20B, Qwen3.5 2B and LFM3 1.7B, which all answered with the correction applied. | ||
| 16 | + | ||
| 17 | +The consequence: a question sent while the model writes its final answer — no tool call, so no call after it — comes too late for this turn. It is not lost: when the turn ends, mm runs it as the next question and says so. | ||
| 18 | + | ||
| 19 | +## Why Enter steers, and `/queue` waits | ||
| 20 | + | ||
| 21 | +Before, Enter during a turn queued the question for after the turn (ticket 155), so the model only saw a correction once it had finished, often after many steps in the wrong direction. Steering is what a correction needs, so it got the key you press without thinking. Queueing is still useful — "and then, write the tests" — so it moved to `/queue <question>`, in both the line mode and the window. Alt-Enter was not used for it: it already inserts a newline, like Ctrl-J. | ||
| 22 | + | ||
| 23 | +Slash commands are never steered: they act on the session (`/new`, `/compact`…) and wait for the turn to end, as before. | ||
| 24 | + | ||
| 25 | +## Where it does not exist | ||
| 26 | + | ||
| 27 | +- **The editor (ACP)**: Zed keeps a message typed during an external agent's turn in its own queue and sends it when the turn ends; its "Steer" toggle serves Zed's own agent only. ACP's v2 prompt RFD lets a client send a prompt during a turn; once Zed and the Go SDK speak it, the same inbox can take it (ticket 266). Until then, `/redirect <message>` (ticket 267) is the nearest thing: sent with Zed's "Send Now", which cancels the turn first, it runs a turn on the history the cancelled one left — mm keeps its commands and results — with the message framed as a correction of that task. It is not a steer: the turn does stop, and a command running at that moment is stopped with it. | ||
| 28 | +- **`mm -p` and asked agents** have no user during the turn. | ||
| 29 | + | ||
| 30 | +## See also | ||
| 31 | + | ||
| 32 | +- The keys and messages: [slash commands and window keys](../reference/slash-commands.md). | ||
| 33 | +- Using it: [How to use the window mode](../how-to/use-the-window-mode.md). | ||
| 34 | +- The other thing that rewrites a turn between calls: [context compression](context-compression.md). | ||
modified
docs/en/how-to/use-from-an-editor.md +1 -0 | @@ -29,6 +29,7 @@ This guide shows how to host `mm` inside an editor that speaks the Agent Client | ||
| 29 | 29 | |
| 30 | 30 | - **Allow or refuse a tool for the whole session** (`yolo: false`). Pick "Allow bash for this session" or "Never allow bash in this session" in the permission dialog; the choice is remembered per tool until the session ends. See [How to confirm tool calls](confirm-tool-calls.md). |
| 31 | 31 | - **Cancel a running turn.** Use the editor's stop key (Escape in Zed). The agent answers the prompt with stop reason `cancelled` and keeps the commands that already ran in the history. There is no `/abort` over ACP. |
| 32 | +- **Correct the model while it works.** Type `/redirect <what to change>` and send it with **Send Now** (Zed: double Enter): the turn stops, and the model continues the same task with your correction — what it already ran is kept. Without Send Now, Zed waits for the turn to end before sending it. A command running at that moment is stopped. See [steering a running turn](../explanation/steering.md). | |
| 32 | 33 | - **Compress or restart the conversation.** Send `/compact` or `/new`; editors that list the agent's commands offer both in the slash-command menu. See the [slash commands reference](../reference/slash-commands.md#acp-mode). |
| 33 | 34 | - **Attach a file with `@`.** The editor's picker sends a `resource_link`, passed to the model as `[attached file: <path>]`; a path typed by hand as `@path` is understood the same way (see [`@path`](attach-a-file.md)). The model reads the file with its tools. |
| 34 | 35 | - **Reload the agent without losing the thread.** With `sessions.enabled: true` in the config file, the editor's Reload Agent (Zed) calls `session/load` and the whole conversation, tool calls included, is replayed into the thread; and the editor's history of threads lists the project's stored conversations (`session/list`), so an older one can be reopened. See [Keep sessions and resume them](keep-sessions.md). Without `sessions.enabled`, Reload Agent still works, but the conversation starts over: mm says so in the thread. |
| @@ -29,6 +29,7 @@ This guide shows how to host `mm` inside an editor that speaks the Agent Client | |||
| 29 | 29 | ||
| 30 | - **Allow or refuse a tool for the whole session** (`yolo: false`). Pick "Allow bash for this session" or "Never allow bash in this session" in the permission dialog; the choice is remembered per tool until the session ends. See [How to confirm tool calls](confirm-tool-calls.md). | 30 | - **Allow or refuse a tool for the whole session** (`yolo: false`). Pick "Allow bash for this session" or "Never allow bash in this session" in the permission dialog; the choice is remembered per tool until the session ends. See [How to confirm tool calls](confirm-tool-calls.md). |
| 31 | - **Cancel a running turn.** Use the editor's stop key (Escape in Zed). The agent answers the prompt with stop reason `cancelled` and keeps the commands that already ran in the history. There is no `/abort` over ACP. | 31 | - **Cancel a running turn.** Use the editor's stop key (Escape in Zed). The agent answers the prompt with stop reason `cancelled` and keeps the commands that already ran in the history. There is no `/abort` over ACP. |
| 32 | +- **Correct the model while it works.** Type `/redirect <what to change>` and send it with **Send Now** (Zed: double Enter): the turn stops, and the model continues the same task with your correction — what it already ran is kept. Without Send Now, Zed waits for the turn to end before sending it. A command running at that moment is stopped. See [steering a running turn](../explanation/steering.md). | ||
| 32 | - **Compress or restart the conversation.** Send `/compact` or `/new`; editors that list the agent's commands offer both in the slash-command menu. See the [slash commands reference](../reference/slash-commands.md#acp-mode). | 33 | - **Compress or restart the conversation.** Send `/compact` or `/new`; editors that list the agent's commands offer both in the slash-command menu. See the [slash commands reference](../reference/slash-commands.md#acp-mode). |
| 33 | - **Attach a file with `@`.** The editor's picker sends a `resource_link`, passed to the model as `[attached file: <path>]`; a path typed by hand as `@path` is understood the same way (see [`@path`](attach-a-file.md)). The model reads the file with its tools. | 34 | - **Attach a file with `@`.** The editor's picker sends a `resource_link`, passed to the model as `[attached file: <path>]`; a path typed by hand as `@path` is understood the same way (see [`@path`](attach-a-file.md)). The model reads the file with its tools. |
| 34 | - **Reload the agent without losing the thread.** With `sessions.enabled: true` in the config file, the editor's Reload Agent (Zed) calls `session/load` and the whole conversation, tool calls included, is replayed into the thread; and the editor's history of threads lists the project's stored conversations (`session/list`), so an older one can be reopened. See [Keep sessions and resume them](keep-sessions.md). Without `sessions.enabled`, Reload Agent still works, but the conversation starts over: mm says so in the thread. | 35 | - **Reload the agent without losing the thread.** With `sessions.enabled: true` in the config file, the editor's Reload Agent (Zed) calls `session/load` and the whole conversation, tool calls included, is replayed into the thread; and the editor's history of threads lists the project's stored conversations (`session/list`), so an older one can be reopened. See [Keep sessions and resume them](keep-sessions.md). Without `sessions.enabled`, Reload Agent still works, but the conversation starts over: mm says so in the thread. |
modified
docs/en/how-to/use-the-window-mode.md +1 -1 | @@ -16,7 +16,7 @@ This guide shows how to run mini-me as a single full-screen window — the conve | ||
| 16 | 16 | |
| 17 | 17 | 3. Watch the answer stream into the conversation. Each tool call is one framed line — `‣ bash ls -1 ✓ done 0.03s` — followed by its output, folded to `previewLines` lines; the `+`/`-` lines of a file edit are coloured. The `⏱` in the status bar counts the time since the question was sent, and keeps the final duration once the answer is done. |
| 18 | 18 | |
| 19 | -4. To add something while a turn runs, type it and press **Enter**: the turn is not stopped, the text waits (`⏳ Queued (1)`, and the rule reads `thinking · 1 queued`) and runs as the next question once the answer is written. Press **Esc** to stop a running turn; whatever is queued runs straight after — type the correction, then press Esc, to redirect the model at once. | |
| 19 | +4. To redirect the model while a turn runs, type the correction and press **Enter**: the turn is not stopped, and the model reads your message after its current step — `↪ Steering`, then `↪ Steered: …` once it has it. To keep a question for after the turn instead, send `/queue <question>`: it waits (`⏳ Queued (1)`, and the rule reads `thinking · 1 queued`) and runs as the next question once the answer is written. A message sent while the model writes its final answer comes too late for this turn: it runs as the next question. Press **Esc** to stop a running turn; whatever waits runs straight after. | |
| 20 | 20 | |
| 21 | 21 | 5. Type `/` at the start of the box to open the command picker: ↑/↓ choose, **Tab** completes, **Enter** sends a complete command. `/help` (or **F1**) lists the commands and keys in the conversation. |
| 22 | 22 | |
| @@ -16,7 +16,7 @@ This guide shows how to run mini-me as a single full-screen window — the conve | |||
| 16 | 16 | ||
| 17 | 3. Watch the answer stream into the conversation. Each tool call is one framed line — `‣ bash ls -1 ✓ done 0.03s` — followed by its output, folded to `previewLines` lines; the `+`/`-` lines of a file edit are coloured. The `⏱` in the status bar counts the time since the question was sent, and keeps the final duration once the answer is done. | 17 | 3. Watch the answer stream into the conversation. Each tool call is one framed line — `‣ bash ls -1 ✓ done 0.03s` — followed by its output, folded to `previewLines` lines; the `+`/`-` lines of a file edit are coloured. The `⏱` in the status bar counts the time since the question was sent, and keeps the final duration once the answer is done. |
| 18 | 18 | ||
| 19 | -4. To add something while a turn runs, type it and press **Enter**: the turn is not stopped, the text waits (`⏳ Queued (1)`, and the rule reads `thinking · 1 queued`) and runs as the next question once the answer is written. Press **Esc** to stop a running turn; whatever is queued runs straight after — type the correction, then press Esc, to redirect the model at once. | 19 | +4. To redirect the model while a turn runs, type the correction and press **Enter**: the turn is not stopped, and the model reads your message after its current step — `↪ Steering`, then `↪ Steered: …` once it has it. To keep a question for after the turn instead, send `/queue <question>`: it waits (`⏳ Queued (1)`, and the rule reads `thinking · 1 queued`) and runs as the next question once the answer is written. A message sent while the model writes its final answer comes too late for this turn: it runs as the next question. Press **Esc** to stop a running turn; whatever waits runs straight after. |
| 20 | 20 | ||
| 21 | 5. Type `/` at the start of the box to open the command picker: ↑/↓ choose, **Tab** completes, **Enter** sends a complete command. `/help` (or **F1**) lists the commands and keys in the conversation. | 21 | 5. Type `/` at the start of the box to open the command picker: ↑/↓ choose, **Tab** completes, **Enter** sends a complete command. `/help` (or **F1**) lists the commands and keys in the conversation. |
| 22 | 22 | ||
modified
docs/en/reference/acp.md +1 -0 | @@ -45,6 +45,7 @@ ACP has no notion of a skill. A prompt carries `text`, `image`, `audio`, `resour | ||
| 45 | 45 | ``` |
| 46 | 46 | /compact Compress the history now, keeping the last turns |
| 47 | 47 | /new Clear the history and start a new session |
| 48 | +/redirect [input: <message>] Correct the task in progress — send it with Send Now (double Enter) … | |
| 48 | 49 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… |
| 49 | 50 | /greetings [input: parameters, if …] Greet somebody with a festive message. |
| 50 | 51 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. |
| @@ -45,6 +45,7 @@ ACP has no notion of a skill. A prompt carries `text`, `image`, `audio`, `resour | |||
| 45 | ``` | 45 | ``` |
| 46 | /compact Compress the history now, keeping the last turns | 46 | /compact Compress the history now, keeping the last turns |
| 47 | /new Clear the history and start a new session | 47 | /new Clear the history and start a new session |
| 48 | +/redirect [input: <message>] Correct the task in progress — send it with Send Now (double Enter) … | ||
| 48 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… | 49 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… |
| 49 | /greetings [input: parameters, if …] Greet somebody with a festive message. | 50 | /greetings [input: parameters, if …] Greet somebody with a festive message. |
| 50 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. | 51 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. |
modified
docs/en/reference/slash-commands.md +14 -8 | @@ -41,7 +41,7 @@ While it runs: | ||
| 41 | 41 | | `<name>`'s tool calls | Shown as tool calls titled `<name> · <tool>: <args>`. Permission requests go through this front end: none in the line mode (allowed), `permissions` in the window (`a`/`s`/`r`, "for this session" keyed on `<name>/<tool>`), the editor's dialog over ACP. | |
| 42 | 42 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Cancel the ask; `🔴 Ask aborted — nothing kept.` | |
| 43 | 43 | | `/quit` | Cancels the ask and exits. | |
| 44 | -| Any other line (line mode) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`; the line runs once the ask has ended, like a line typed during a generation (below). | | |
| 44 | +| Any other line (line mode) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`; the line runs once the ask has ended — an ask is not steered, unlike a generation (below). | | |
| 45 | 45 | |
| 46 | 46 | When it ends: |
| 47 | 47 | |
| @@ -93,9 +93,10 @@ Details and examples: [Point the model at a file with `@path`](../how-to/attach- | ||
| 93 | 93 | |
| 94 | 94 | | Input | Behaviour | |
| 95 | 95 | |-------|-----------| |
| 96 | -| A non-command line, or a command other than `/abort` and `/quit` | Does not stop the generation. Prints `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` being the number of lines waiting. Once the turn has ended, the queued lines run in the order they were typed, each one echoed after the `>` prompt as if it had been typed there. | | |
| 96 | +| A non-command line | **Steers** the generation without stopping it (ticket 265): prints `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`; the model gets it after its next tool results, as a user message `[message from the user during this turn] <text>` (`@path` and `$skill` expanded), and `↪ Steered: <first line>` says when. A line sent after the model's last call — while it writes its final answer — runs as the next question: `⏳ N message(s) came after the model's last call — sent as the next question`. | | |
| 97 | +| `/queue <question>`, or a command other than `/abort` and `/quit` | Does not stop the generation. Prints `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` being the number of lines waiting. Once the turn has ended, the queued lines run in the order they were typed, each one echoed after the `>` prompt as if it had been typed there (for `/queue`, the question alone). `/queue` alone prints `⚠️ /queue needs a question: /queue <question>`. | | |
| 97 | 98 | | An empty line | Ignored. | |
| 98 | -| `/abort`, `Ctrl+C` | Stop the generation; the queued lines then run. | | |
| 99 | +| `/abort`, `Ctrl+C` | Stop the generation; the queued lines, and the steered lines the model did not get, then run. | | |
| 99 | 100 | | End of input (the end of a pipe) | The generation goes on; the queued lines run, then `mm` exits. | |
| 100 | 101 | |
| 101 | 102 | ## Keyboard shortcuts |
| @@ -107,9 +108,13 @@ Details and examples: [Point the model at a file with `@path`](../how-to/attach- | ||
| 107 | 108 | |
| 108 | 109 | ## Window mode keys |
| 109 | 110 | |
| 110 | -In `mm -tui` the same commands exist, plus `/shell`; `/abort` when idle prints `⚠️ No generation in progress.` as a notice, and the picker opened by `/` lists them — see [The three pickers](#the-three-pickers). | |
| 111 | +In `mm -tui` the same commands exist, plus `/shell` and `/queue`; `/abort` when idle prints `⚠️ No generation in progress.` as a notice, and the picker opened by `/` lists them — see [The three pickers](#the-three-pickers). | |
| 111 | 112 | |
| 112 | -`/quit`, `/abort` and `/shell` take effect **immediately**, even while a turn is running. Every other command and every question waits for the turn to end, because it needs the history the turn is still writing. See [Leaving a turn that will not stop](#leaving-a-turn-that-will-not-stop). | |
| 113 | +`/quit`, `/abort`, `/shell` and `/queue` take effect **immediately**, even while a turn is running. A question sent during a turn **steers** it: the model reads it after its current step, and the turn goes on (see the `Enter` key below). Every other command waits for the turn to end, because it needs the history the turn is still writing. See [Leaving a turn that will not stop](#leaving-a-turn-that-will-not-stop). | |
| 114 | + | |
| 115 | +### `/queue` | |
| 116 | + | |
| 117 | +Line mode and window mode (not the editor, which has no steering). `/queue <question>`: during a turn, the question waits for the turn to end and runs as the next question (`⏳ Queued (N) — runs once this turn ends · …`) instead of steering the turn; when no turn runs, it is sent at once. Without a question: `⚠️ /queue needs a question: /queue <question>`. | |
| 113 | 118 | |
| 114 | 119 | ### `/shell` |
| 115 | 120 | |
| @@ -149,9 +154,9 @@ The keys: | ||
| 149 | 154 | |
| 150 | 155 | | Key | Action | |
| 151 | 156 | |-----|--------| |
| 152 | -| `Enter` | Sends the box (nothing on an empty box). During a turn, the text does not stop it: it is queued (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, the rule reads `<state> · N queued`) and the queued entries run in order once the turn has settled; `/quit`, `/abort` and `/shell` run at once. With the picker open on an incomplete name, completes it instead. | | |
| 157 | +| `Enter` | Sends the box (nothing on an empty box). During a turn, a question **steers** it without stopping it: it is shown at once with `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`, joins the history as a user message `[message from the user during this turn] <text>` right after the next tool results, and `↪ Steered: <first line>` says when the model got it. A question sent after the model's last call — while it writes its final answer — runs as the next question (`⏳ N message(s) came after the model's last call — sent as the next question`). A command other than `/quit`, `/abort`, `/shell` and `/queue`, and `/queue <question>`, is queued (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, the rule reads `<state> · N queued`) and the queued entries run in order once the turn has settled. With the picker open on an incomplete name, completes it instead. | | |
| 153 | 158 | | `Ctrl-J`, `Alt-Enter` | Inserts a newline in the box. | |
| 154 | -| `Esc` | Cancels the running turn (same as `/abort`) — the queued entries then run; when no turn runs and the box is not empty, clears the box instead; closes the picker; rejects a pending permission. | | |
| 159 | +| `Esc` | Cancels the running turn (same as `/abort`) — the queued entries, and the steered questions the model did not get, then run; when no turn runs and the box is not empty, clears the box instead; closes the picker; rejects a pending permission. | | |
| 155 | 160 | | `Ctrl-C` | Cancels the running turn; quits when idle — and quits too when the turn has already been asked to stop and has not. | |
| 156 | 161 | | `Tab` | Moves the focus between the box and the conversation; completes the picker's choice when it is open (`/`, `@` or `$`). | |
| 157 | 162 | | `↑` `↓` | In the box: move between its rows — a long line wraps at spaces into several rows. From the first row, `↑` recalls the previous question (sessions on: this session, then the earlier ones, newest first); from the last row during a recall, `↓` the next one, then the text typed before. With nothing to recall, they scroll the conversation from the first/last row. On the conversation: scroll one line. In the picker: move the choice. | |
| @@ -225,7 +230,7 @@ The notation works in the line mode and over ACP too, typed by hand: a `$skill` | ||
| 225 | 230 | |
| 226 | 231 | ## ACP mode |
| 227 | 232 | |
| 228 | -Two commands exist in ACP mode, three with `unloadModels` (the default): `/new`, `/compact` and `/unload` — plus `/memory` with `sessions.searchMemory` and `/docs` with `docSearch.searchDocs`. They are advertised to the editor through an `available_commands_update` notification and intercepted by `session/prompt` when the prompt text, trimmed, is exactly the command (`/unload` may be followed by a model name, `/memory` and `/docs` by their words). Each answers with one `agent_message_chunk` carrying the line the terminal would print, then `stopReason: end_turn`; the model is not consulted. | |
| 233 | +Three commands exist in ACP mode, four with `unloadModels` (the default): `/new`, `/compact`, `/redirect` and `/unload` — plus `/memory` with `sessions.searchMemory` and `/docs` with `docSearch.searchDocs`. They are advertised to the editor through an `available_commands_update` notification and intercepted by `session/prompt` when the prompt text, trimmed, is exactly the command (`/unload` may be followed by a model name, `/memory` and `/docs` by their words). Each answers with one `agent_message_chunk` carrying the line the terminal would print, then `stopReason: end_turn`; the model is not consulted. | |
| 229 | 234 | |
| 230 | 235 | | Command | Over ACP | |
| 231 | 236 | |---------|----------| |
| @@ -234,6 +239,7 @@ Two commands exist in ACP mode, three with `unloadModels` (the default): `/new`, | ||
| 234 | 239 | | `/memory <words>` | With `sessions.enabled` and `sessions.searchMemory`, advertised with the input hint `<words>`: same as in the terminal, in the session's project (`sessions.dir` under its `cwd`), as the agent's text; the history is not touched. | |
| 235 | 240 | | `/docs <words>` | With `docSearch.searchDocs`, advertised with the input hint `<words>`: same as in the terminal, from the session's `cwd`, as the agent's text; the history is not touched. | |
| 236 | 241 | | `/unload [model]` | With `unloadModels` (default on), advertised with the input hint `[model]`: same as in the terminal, the `🧹` line as the agent's text; the history is not touched. | |
| 242 | +| `/redirect <message>` | Editor only (ticket 267), advertised with the input hint `<message>`. Runs a turn on the session's history whose question is `[the user redirects the task in progress] <message>` followed by `Continue the task you were working on, taking this into account.` Meant to be sent with the editor's "Send Now" (Zed: double Enter), which cancels the running turn first; the cancelled turn's commands and results stay in the history, so the model continues that task with the correction. A tool running at the cancel is stopped with the turn. Sent without "Send Now", the editor delivers it once the turn has ended. `/redirect` alone answers `/redirect needs a message: …` without a turn. | | |
| 237 | 243 | |
| 238 | 244 | With `mmConfigs`, `/ask-<name>` and `/ask-with-context-<name>` are advertised too, each with the input hint `<prompt>`; the generic `/ask <name>` is not, since an editor's menu completes a command name but not its argument. See [Asking another agent](#asking-another-agent). |
| 239 | 245 | |
| @@ -41,7 +41,7 @@ While it runs: | |||
| 41 | | `<name>`'s tool calls | Shown as tool calls titled `<name> · <tool>: <args>`. Permission requests go through this front end: none in the line mode (allowed), `permissions` in the window (`a`/`s`/`r`, "for this session" keyed on `<name>/<tool>`), the editor's dialog over ACP. | | 41 | | `<name>`'s tool calls | Shown as tool calls titled `<name> · <tool>: <args>`. Permission requests go through this front end: none in the line mode (allowed), `permissions` in the window (`a`/`s`/`r`, "for this session" keyed on `<name>/<tool>`), the editor's dialog over ACP. | |
| 42 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Cancel the ask; `🔴 Ask aborted — nothing kept.` | | 42 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Cancel the ask; `🔴 Ask aborted — nothing kept.` | |
| 43 | | `/quit` | Cancels the ask and exits. | | 43 | | `/quit` | Cancels the ask and exits. | |
| 44 | -| Any other line (line mode) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`; the line runs once the ask has ended, like a line typed during a generation (below). | | 44 | +| Any other line (line mode) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`; the line runs once the ask has ended — an ask is not steered, unlike a generation (below). | |
| 45 | 45 | ||
| 46 | When it ends: | 46 | When it ends: |
| 47 | 47 | ||
| @@ -93,9 +93,10 @@ Details and examples: [Point the model at a file with `@path`](../how-to/attach- | |||
| 93 | 93 | ||
| 94 | | Input | Behaviour | | 94 | | Input | Behaviour | |
| 95 | |-------|-----------| | 95 | |-------|-----------| |
| 96 | -| A non-command line, or a command other than `/abort` and `/quit` | Does not stop the generation. Prints `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` being the number of lines waiting. Once the turn has ended, the queued lines run in the order they were typed, each one echoed after the `>` prompt as if it had been typed there. | | 96 | +| A non-command line | **Steers** the generation without stopping it (ticket 265): prints `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`; the model gets it after its next tool results, as a user message `[message from the user during this turn] <text>` (`@path` and `$skill` expanded), and `↪ Steered: <first line>` says when. A line sent after the model's last call — while it writes its final answer — runs as the next question: `⏳ N message(s) came after the model's last call — sent as the next question`. | |
| 97 | +| `/queue <question>`, or a command other than `/abort` and `/quit` | Does not stop the generation. Prints `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` being the number of lines waiting. Once the turn has ended, the queued lines run in the order they were typed, each one echoed after the `>` prompt as if it had been typed there (for `/queue`, the question alone). `/queue` alone prints `⚠️ /queue needs a question: /queue <question>`. | | ||
| 97 | | An empty line | Ignored. | | 98 | | An empty line | Ignored. | |
| 98 | -| `/abort`, `Ctrl+C` | Stop the generation; the queued lines then run. | | 99 | +| `/abort`, `Ctrl+C` | Stop the generation; the queued lines, and the steered lines the model did not get, then run. | |
| 99 | | End of input (the end of a pipe) | The generation goes on; the queued lines run, then `mm` exits. | | 100 | | End of input (the end of a pipe) | The generation goes on; the queued lines run, then `mm` exits. | |
| 100 | 101 | ||
| 101 | ## Keyboard shortcuts | 102 | ## Keyboard shortcuts |
| @@ -107,9 +108,13 @@ Details and examples: [Point the model at a file with `@path`](../how-to/attach- | |||
| 107 | 108 | ||
| 108 | ## Window mode keys | 109 | ## Window mode keys |
| 109 | 110 | ||
| 110 | -In `mm -tui` the same commands exist, plus `/shell`; `/abort` when idle prints `⚠️ No generation in progress.` as a notice, and the picker opened by `/` lists them — see [The three pickers](#the-three-pickers). | 111 | +In `mm -tui` the same commands exist, plus `/shell` and `/queue`; `/abort` when idle prints `⚠️ No generation in progress.` as a notice, and the picker opened by `/` lists them — see [The three pickers](#the-three-pickers). |
| 111 | 112 | ||
| 112 | -`/quit`, `/abort` and `/shell` take effect **immediately**, even while a turn is running. Every other command and every question waits for the turn to end, because it needs the history the turn is still writing. See [Leaving a turn that will not stop](#leaving-a-turn-that-will-not-stop). | 113 | +`/quit`, `/abort`, `/shell` and `/queue` take effect **immediately**, even while a turn is running. A question sent during a turn **steers** it: the model reads it after its current step, and the turn goes on (see the `Enter` key below). Every other command waits for the turn to end, because it needs the history the turn is still writing. See [Leaving a turn that will not stop](#leaving-a-turn-that-will-not-stop). |
| 114 | + | ||
| 115 | +### `/queue` | ||
| 116 | + | ||
| 117 | +Line mode and window mode (not the editor, which has no steering). `/queue <question>`: during a turn, the question waits for the turn to end and runs as the next question (`⏳ Queued (N) — runs once this turn ends · …`) instead of steering the turn; when no turn runs, it is sent at once. Without a question: `⚠️ /queue needs a question: /queue <question>`. | ||
| 113 | 118 | ||
| 114 | ### `/shell` | 119 | ### `/shell` |
| 115 | 120 | ||
| @@ -149,9 +154,9 @@ The keys: | |||
| 149 | 154 | ||
| 150 | | Key | Action | | 155 | | Key | Action | |
| 151 | |-----|--------| | 156 | |-----|--------| |
| 152 | -| `Enter` | Sends the box (nothing on an empty box). During a turn, the text does not stop it: it is queued (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, the rule reads `<state> · N queued`) and the queued entries run in order once the turn has settled; `/quit`, `/abort` and `/shell` run at once. With the picker open on an incomplete name, completes it instead. | | 157 | +| `Enter` | Sends the box (nothing on an empty box). During a turn, a question **steers** it without stopping it: it is shown at once with `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`, joins the history as a user message `[message from the user during this turn] <text>` right after the next tool results, and `↪ Steered: <first line>` says when the model got it. A question sent after the model's last call — while it writes its final answer — runs as the next question (`⏳ N message(s) came after the model's last call — sent as the next question`). A command other than `/quit`, `/abort`, `/shell` and `/queue`, and `/queue <question>`, is queued (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, the rule reads `<state> · N queued`) and the queued entries run in order once the turn has settled. With the picker open on an incomplete name, completes it instead. | |
| 153 | | `Ctrl-J`, `Alt-Enter` | Inserts a newline in the box. | | 158 | | `Ctrl-J`, `Alt-Enter` | Inserts a newline in the box. | |
| 154 | -| `Esc` | Cancels the running turn (same as `/abort`) — the queued entries then run; when no turn runs and the box is not empty, clears the box instead; closes the picker; rejects a pending permission. | | 159 | +| `Esc` | Cancels the running turn (same as `/abort`) — the queued entries, and the steered questions the model did not get, then run; when no turn runs and the box is not empty, clears the box instead; closes the picker; rejects a pending permission. | |
| 155 | | `Ctrl-C` | Cancels the running turn; quits when idle — and quits too when the turn has already been asked to stop and has not. | | 160 | | `Ctrl-C` | Cancels the running turn; quits when idle — and quits too when the turn has already been asked to stop and has not. | |
| 156 | | `Tab` | Moves the focus between the box and the conversation; completes the picker's choice when it is open (`/`, `@` or `$`). | | 161 | | `Tab` | Moves the focus between the box and the conversation; completes the picker's choice when it is open (`/`, `@` or `$`). | |
| 157 | | `↑` `↓` | In the box: move between its rows — a long line wraps at spaces into several rows. From the first row, `↑` recalls the previous question (sessions on: this session, then the earlier ones, newest first); from the last row during a recall, `↓` the next one, then the text typed before. With nothing to recall, they scroll the conversation from the first/last row. On the conversation: scroll one line. In the picker: move the choice. | | 162 | | `↑` `↓` | In the box: move between its rows — a long line wraps at spaces into several rows. From the first row, `↑` recalls the previous question (sessions on: this session, then the earlier ones, newest first); from the last row during a recall, `↓` the next one, then the text typed before. With nothing to recall, they scroll the conversation from the first/last row. On the conversation: scroll one line. In the picker: move the choice. | |
| @@ -225,7 +230,7 @@ The notation works in the line mode and over ACP too, typed by hand: a `$skill` | |||
| 225 | 230 | ||
| 226 | ## ACP mode | 231 | ## ACP mode |
| 227 | 232 | ||
| 228 | -Two commands exist in ACP mode, three with `unloadModels` (the default): `/new`, `/compact` and `/unload` — plus `/memory` with `sessions.searchMemory` and `/docs` with `docSearch.searchDocs`. They are advertised to the editor through an `available_commands_update` notification and intercepted by `session/prompt` when the prompt text, trimmed, is exactly the command (`/unload` may be followed by a model name, `/memory` and `/docs` by their words). Each answers with one `agent_message_chunk` carrying the line the terminal would print, then `stopReason: end_turn`; the model is not consulted. | 233 | +Three commands exist in ACP mode, four with `unloadModels` (the default): `/new`, `/compact`, `/redirect` and `/unload` — plus `/memory` with `sessions.searchMemory` and `/docs` with `docSearch.searchDocs`. They are advertised to the editor through an `available_commands_update` notification and intercepted by `session/prompt` when the prompt text, trimmed, is exactly the command (`/unload` may be followed by a model name, `/memory` and `/docs` by their words). Each answers with one `agent_message_chunk` carrying the line the terminal would print, then `stopReason: end_turn`; the model is not consulted. |
| 229 | 234 | ||
| 230 | | Command | Over ACP | | 235 | | Command | Over ACP | |
| 231 | |---------|----------| | 236 | |---------|----------| |
| @@ -234,6 +239,7 @@ Two commands exist in ACP mode, three with `unloadModels` (the default): `/new`, | |||
| 234 | | `/memory <words>` | With `sessions.enabled` and `sessions.searchMemory`, advertised with the input hint `<words>`: same as in the terminal, in the session's project (`sessions.dir` under its `cwd`), as the agent's text; the history is not touched. | | 239 | | `/memory <words>` | With `sessions.enabled` and `sessions.searchMemory`, advertised with the input hint `<words>`: same as in the terminal, in the session's project (`sessions.dir` under its `cwd`), as the agent's text; the history is not touched. | |
| 235 | | `/docs <words>` | With `docSearch.searchDocs`, advertised with the input hint `<words>`: same as in the terminal, from the session's `cwd`, as the agent's text; the history is not touched. | | 240 | | `/docs <words>` | With `docSearch.searchDocs`, advertised with the input hint `<words>`: same as in the terminal, from the session's `cwd`, as the agent's text; the history is not touched. | |
| 236 | | `/unload [model]` | With `unloadModels` (default on), advertised with the input hint `[model]`: same as in the terminal, the `🧹` line as the agent's text; the history is not touched. | | 241 | | `/unload [model]` | With `unloadModels` (default on), advertised with the input hint `[model]`: same as in the terminal, the `🧹` line as the agent's text; the history is not touched. | |
| 242 | +| `/redirect <message>` | Editor only (ticket 267), advertised with the input hint `<message>`. Runs a turn on the session's history whose question is `[the user redirects the task in progress] <message>` followed by `Continue the task you were working on, taking this into account.` Meant to be sent with the editor's "Send Now" (Zed: double Enter), which cancels the running turn first; the cancelled turn's commands and results stay in the history, so the model continues that task with the correction. A tool running at the cancel is stopped with the turn. Sent without "Send Now", the editor delivers it once the turn has ended. `/redirect` alone answers `/redirect needs a message: …` without a turn. | | ||
| 237 | 243 | ||
| 238 | With `mmConfigs`, `/ask-<name>` and `/ask-with-context-<name>` are advertised too, each with the input hint `<prompt>`; the generic `/ask <name>` is not, since an editor's menu completes a command name but not its argument. See [Asking another agent](#asking-another-agent). | 244 | With `mmConfigs`, `/ask-<name>` and `/ask-with-context-<name>` are advertised too, each with the input hint `<prompt>`; the generic `/ask <name>` is not, since an editor's menu completes a command name but not its argument. See [Asking another agent](#asking-another-agent). |
| 239 | 245 | ||
modified
docs/fr/README.md +1 -0 | @@ -109,6 +109,7 @@ Cette documentation est organisée selon les quatre quadrants [Diátaxis](https: | ||
| 109 | 109 | - [Les modèles de garde](explanation/guard-models.md) — pourquoi le message système est un nom de risque, pourquoi chaque garde juge la question seule (`-p`), pourquoi un hook plutôt que `ask_agent`, qui réagit (le modèle ou le hook), échouer fermé, ce que les gardes ne donnent pas |
| 110 | 110 | - [Les modèles de décision](explanation/decision-models.md) — pourquoi un décideur est un agent, pourquoi le routage ajoute la ligne `$skill`, la confiance du serveur, ce qui a été mesuré (0 mauvais choix sur 23 cas ; 12 → 16 justes avec un modèle de chat 4B), pourquoi pas decision-4b ; pourquoi le tri des commandes et le routage d'outils ne font que retirer (questions, outils), un décideur seul |
| 111 | 111 | - [Outils du client ACP](explanation/acp-client-tools.md) — pourquoi mm avait besoin de sa propre convention au-dessus des méthodes d'extension d'ACP, pourquoi la découverte `meta` par défaut, la session dans `_meta`, des outils dynamiques par session, les erreurs comme réponses, pourquoi pas `mcpServers` |
| 112 | +- [Réorienter un tour en cours](explanation/steering.md) — comment une question envoyée pendant un tour atteint le modèle à son appel suivant, pourquoi seulement après des résultats d'outils, pourquoi Entrée réoriente et `/queue` attend, là où ça n'existe pas (Zed) | |
| 112 | 113 | - Diagramme des paquets (source draw.io) : [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) |
| 113 | 114 | |
| 114 | 115 | ### Explication MCP (Model Context Protocol) |
| @@ -109,6 +109,7 @@ Cette documentation est organisée selon les quatre quadrants [Diátaxis](https: | |||
| 109 | - [Les modèles de garde](explanation/guard-models.md) — pourquoi le message système est un nom de risque, pourquoi chaque garde juge la question seule (`-p`), pourquoi un hook plutôt que `ask_agent`, qui réagit (le modèle ou le hook), échouer fermé, ce que les gardes ne donnent pas | 109 | - [Les modèles de garde](explanation/guard-models.md) — pourquoi le message système est un nom de risque, pourquoi chaque garde juge la question seule (`-p`), pourquoi un hook plutôt que `ask_agent`, qui réagit (le modèle ou le hook), échouer fermé, ce que les gardes ne donnent pas |
| 110 | - [Les modèles de décision](explanation/decision-models.md) — pourquoi un décideur est un agent, pourquoi le routage ajoute la ligne `$skill`, la confiance du serveur, ce qui a été mesuré (0 mauvais choix sur 23 cas ; 12 → 16 justes avec un modèle de chat 4B), pourquoi pas decision-4b ; pourquoi le tri des commandes et le routage d'outils ne font que retirer (questions, outils), un décideur seul | 110 | - [Les modèles de décision](explanation/decision-models.md) — pourquoi un décideur est un agent, pourquoi le routage ajoute la ligne `$skill`, la confiance du serveur, ce qui a été mesuré (0 mauvais choix sur 23 cas ; 12 → 16 justes avec un modèle de chat 4B), pourquoi pas decision-4b ; pourquoi le tri des commandes et le routage d'outils ne font que retirer (questions, outils), un décideur seul |
| 111 | - [Outils du client ACP](explanation/acp-client-tools.md) — pourquoi mm avait besoin de sa propre convention au-dessus des méthodes d'extension d'ACP, pourquoi la découverte `meta` par défaut, la session dans `_meta`, des outils dynamiques par session, les erreurs comme réponses, pourquoi pas `mcpServers` | 111 | - [Outils du client ACP](explanation/acp-client-tools.md) — pourquoi mm avait besoin de sa propre convention au-dessus des méthodes d'extension d'ACP, pourquoi la découverte `meta` par défaut, la session dans `_meta`, des outils dynamiques par session, les erreurs comme réponses, pourquoi pas `mcpServers` |
| 112 | +- [Réorienter un tour en cours](explanation/steering.md) — comment une question envoyée pendant un tour atteint le modèle à son appel suivant, pourquoi seulement après des résultats d'outils, pourquoi Entrée réoriente et `/queue` attend, là où ça n'existe pas (Zed) | ||
| 112 | - Diagramme des paquets (source draw.io) : [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) | 113 | - Diagramme des paquets (source draw.io) : [`docs/diagrams/packages.drawio`](../diagrams/packages.drawio) |
| 113 | 114 | ||
| 114 | ### Explication MCP (Model Context Protocol) | 115 | ### Explication MCP (Model Context Protocol) |
added
docs/fr/explanation/steering.md +34 -0 | new file mode 100644 | ||
| @@ -0,0 +1,34 @@ | ||
| 1 | +# Réorienter un tour en cours (steer) | |
| 2 | + | |
| 3 | +## De quoi s'agit-il ? | |
| 4 | + | |
| 5 | +Un tour est souvent long : le modèle appelle un outil, lit le résultat, en appelle un autre, et ainsi de suite, parfois pendant des dizaines d'étapes. Quand vous le voyez partir dans la mauvaise direction, vous voulez le lui dire — sans jeter ce qu'il a déjà fait. En mode ligne et dans la fenêtre, une question envoyée pendant un tour fait cela : elle atteint le modèle à son appel suivant, dans le même tour (ticket 265). Cette page explique comment, et pourquoi ça fonctionne ainsi. | |
| 6 | + | |
| 7 | +## Comment ça marche | |
| 8 | + | |
| 9 | +Chaque tour a une boîte de réception. Une question envoyée pendant un tour (Entrée) y est déposée. Avant chaque appel au modèle, le tour regarde la boîte et, quand l'appel suit des résultats d'outils, ajoute les questions en attente à l'historique comme messages utilisateur, étiquetés `[message from the user during this turn]`. L'étiquette dit au modèle qu'il s'agit d'une correction de la tâche en cours, pas d'une nouvelle tâche. À partir de là, la question fait partie du tour : les appels suivants la portent, la session la garde, et ↑ la rappelle sans l'étiquette. | |
| 10 | + | |
| 11 | +Le point d'accroche est celui qui réduit un long tour avant un appel quand il dépasse le seuil de contexte (la compression en cours de tour) : le seul endroit où mm voit chaque appel au modèle d'un tour et peut changer ce que le modèle lit. | |
| 12 | + | |
| 13 | +## Pourquoi seulement après des résultats d'outils | |
| 14 | + | |
| 15 | +Une question n'est prise que par un appel qui suit des résultats d'outils. Un message utilisateur juste après la question, ou juste après la réponse du modèle, donne deux tours utilisateur de suite ou un tour après la fin — des formes que les templates de chat gèrent mal ou pas du tout. Après des résultats d'outils, un message utilisateur est du format OpenAI ordinaire ; c'est vérifié sur llama.cpp avec gpt-oss 20B, Qwen3.5 2B et LFM3 1.7B, qui ont tous répondu en appliquant la correction. | |
| 16 | + | |
| 17 | +Conséquence : une question envoyée pendant que le modèle écrit sa réponse finale — pas d'appel d'outil, donc pas d'appel après — arrive trop tard pour ce tour. Elle n'est pas perdue : à la fin du tour, mm la lance comme question suivante et le dit. | |
| 18 | + | |
| 19 | +## Pourquoi Entrée réoriente et `/queue` attend | |
| 20 | + | |
| 21 | +Avant, Entrée pendant un tour mettait la question en attente pour après le tour (ticket 155) : le modèle ne voyait une correction qu'une fois son travail fini, souvent après beaucoup d'étapes dans la mauvaise direction. Réorienter est ce dont une correction a besoin ; elle a donc pris la touche qu'on presse sans réfléchir. La file d'attente reste utile — « et ensuite, écris les tests » — elle passe donc sur `/queue <question>`, en mode ligne comme dans la fenêtre. Alt-Entrée n'a pas été utilisé pour cela : il insère déjà un saut de ligne, comme Ctrl-J. | |
| 22 | + | |
| 23 | +Les commandes slash ne réorientent jamais : elles agissent sur la session (`/new`, `/compact`…) et attendent la fin du tour, comme avant. | |
| 24 | + | |
| 25 | +## Là où ça n'existe pas | |
| 26 | + | |
| 27 | +- **L'éditeur (ACP)** : Zed garde dans sa propre file un message tapé pendant le tour d'un agent externe et l'envoie à la fin du tour ; son bouton « Steer » ne sert que l'agent de Zed. La RFD prompt de la v2 d'ACP permet à un client d'envoyer un prompt pendant un tour ; quand Zed et le SDK Go la parleront, la même boîte pourra le prendre (ticket 266). D'ici là, `/redirect <message>` (ticket 267) s'en approche le plus : envoyé avec le « Send Now » de Zed, qui annule d'abord le tour, il lance un tour sur l'historique laissé par le tour annulé — mm en garde les commandes et les résultats — avec le message présenté comme une correction de cette tâche. Ce n'est pas un steer : le tour s'arrête bel et bien, et une commande en cours à ce moment-là s'arrête avec lui. | |
| 28 | +- **`mm -p` et les agents interrogés** n'ont pas d'utilisateur pendant le tour. | |
| 29 | + | |
| 30 | +## Voir aussi | |
| 31 | + | |
| 32 | +- Les touches et les messages : [commandes slash et touches de la fenêtre](../reference/slash-commands.md). | |
| 33 | +- L'utiliser : [Comment utiliser le mode fenêtre](../how-to/use-the-window-mode.md). | |
| 34 | +- L'autre mécanisme qui réécrit un tour entre deux appels : [la compression du contexte](context-compression.md). | |
| new file mode 100644 | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | +# Réorienter un tour en cours (steer) | ||
| 2 | + | ||
| 3 | +## De quoi s'agit-il ? | ||
| 4 | + | ||
| 5 | +Un tour est souvent long : le modèle appelle un outil, lit le résultat, en appelle un autre, et ainsi de suite, parfois pendant des dizaines d'étapes. Quand vous le voyez partir dans la mauvaise direction, vous voulez le lui dire — sans jeter ce qu'il a déjà fait. En mode ligne et dans la fenêtre, une question envoyée pendant un tour fait cela : elle atteint le modèle à son appel suivant, dans le même tour (ticket 265). Cette page explique comment, et pourquoi ça fonctionne ainsi. | ||
| 6 | + | ||
| 7 | +## Comment ça marche | ||
| 8 | + | ||
| 9 | +Chaque tour a une boîte de réception. Une question envoyée pendant un tour (Entrée) y est déposée. Avant chaque appel au modèle, le tour regarde la boîte et, quand l'appel suit des résultats d'outils, ajoute les questions en attente à l'historique comme messages utilisateur, étiquetés `[message from the user during this turn]`. L'étiquette dit au modèle qu'il s'agit d'une correction de la tâche en cours, pas d'une nouvelle tâche. À partir de là, la question fait partie du tour : les appels suivants la portent, la session la garde, et ↑ la rappelle sans l'étiquette. | ||
| 10 | + | ||
| 11 | +Le point d'accroche est celui qui réduit un long tour avant un appel quand il dépasse le seuil de contexte (la compression en cours de tour) : le seul endroit où mm voit chaque appel au modèle d'un tour et peut changer ce que le modèle lit. | ||
| 12 | + | ||
| 13 | +## Pourquoi seulement après des résultats d'outils | ||
| 14 | + | ||
| 15 | +Une question n'est prise que par un appel qui suit des résultats d'outils. Un message utilisateur juste après la question, ou juste après la réponse du modèle, donne deux tours utilisateur de suite ou un tour après la fin — des formes que les templates de chat gèrent mal ou pas du tout. Après des résultats d'outils, un message utilisateur est du format OpenAI ordinaire ; c'est vérifié sur llama.cpp avec gpt-oss 20B, Qwen3.5 2B et LFM3 1.7B, qui ont tous répondu en appliquant la correction. | ||
| 16 | + | ||
| 17 | +Conséquence : une question envoyée pendant que le modèle écrit sa réponse finale — pas d'appel d'outil, donc pas d'appel après — arrive trop tard pour ce tour. Elle n'est pas perdue : à la fin du tour, mm la lance comme question suivante et le dit. | ||
| 18 | + | ||
| 19 | +## Pourquoi Entrée réoriente et `/queue` attend | ||
| 20 | + | ||
| 21 | +Avant, Entrée pendant un tour mettait la question en attente pour après le tour (ticket 155) : le modèle ne voyait une correction qu'une fois son travail fini, souvent après beaucoup d'étapes dans la mauvaise direction. Réorienter est ce dont une correction a besoin ; elle a donc pris la touche qu'on presse sans réfléchir. La file d'attente reste utile — « et ensuite, écris les tests » — elle passe donc sur `/queue <question>`, en mode ligne comme dans la fenêtre. Alt-Entrée n'a pas été utilisé pour cela : il insère déjà un saut de ligne, comme Ctrl-J. | ||
| 22 | + | ||
| 23 | +Les commandes slash ne réorientent jamais : elles agissent sur la session (`/new`, `/compact`…) et attendent la fin du tour, comme avant. | ||
| 24 | + | ||
| 25 | +## Là où ça n'existe pas | ||
| 26 | + | ||
| 27 | +- **L'éditeur (ACP)** : Zed garde dans sa propre file un message tapé pendant le tour d'un agent externe et l'envoie à la fin du tour ; son bouton « Steer » ne sert que l'agent de Zed. La RFD prompt de la v2 d'ACP permet à un client d'envoyer un prompt pendant un tour ; quand Zed et le SDK Go la parleront, la même boîte pourra le prendre (ticket 266). D'ici là, `/redirect <message>` (ticket 267) s'en approche le plus : envoyé avec le « Send Now » de Zed, qui annule d'abord le tour, il lance un tour sur l'historique laissé par le tour annulé — mm en garde les commandes et les résultats — avec le message présenté comme une correction de cette tâche. Ce n'est pas un steer : le tour s'arrête bel et bien, et une commande en cours à ce moment-là s'arrête avec lui. | ||
| 28 | +- **`mm -p` et les agents interrogés** n'ont pas d'utilisateur pendant le tour. | ||
| 29 | + | ||
| 30 | +## Voir aussi | ||
| 31 | + | ||
| 32 | +- Les touches et les messages : [commandes slash et touches de la fenêtre](../reference/slash-commands.md). | ||
| 33 | +- L'utiliser : [Comment utiliser le mode fenêtre](../how-to/use-the-window-mode.md). | ||
| 34 | +- L'autre mécanisme qui réécrit un tour entre deux appels : [la compression du contexte](context-compression.md). | ||
modified
docs/fr/how-to/use-from-an-editor.md +1 -0 | @@ -29,6 +29,7 @@ Ce guide montre comment héberger `mm` dans un éditeur qui parle l'Agent Client | ||
| 29 | 29 | |
| 30 | 30 | - **Autoriser ou refuser un outil pour toute la session** (`yolo: false`). Choisissez « Allow bash for this session » ou « Never allow bash in this session » dans le dialogue de permission ; le choix est mémorisé par nom d'outil jusqu'à la fin de la session. Voir [Confirmer les appels d'outils](confirm-tool-calls.md). |
| 31 | 31 | - **Annuler un tour en cours.** Utilisez la touche d'arrêt de l'éditeur (Échap dans Zed). L'agent répond au prompt avec la raison d'arrêt `cancelled` et conserve dans l'historique les commandes déjà exécutées. Il n'y a pas de `/abort` en ACP. |
| 32 | +- **Corriger le modèle pendant qu'il travaille.** Tapez `/redirect <ce qu'il faut changer>` et envoyez-le avec **Send Now** (Zed : double Entrée) : le tour s'arrête, et le modèle reprend la même tâche avec votre correction — ce qu'il a déjà exécuté est gardé. Sans Send Now, Zed attend la fin du tour pour l'envoyer. Une commande en cours à ce moment-là est arrêtée. Voir [réorienter un tour en cours](../explanation/steering.md). | |
| 32 | 33 | - **Compresser ou recommencer la conversation.** Envoyez `/compact` ou `/new` ; les éditeurs qui listent les commandes de l'agent proposent les deux dans le menu des commandes slash. Voir la [référence des commandes slash](../reference/slash-commands.md#mode-acp). |
| 33 | 34 | - **Attacher un fichier avec `@`.** Le sélecteur de l'éditeur envoie un `resource_link`, transmis au modèle sous la forme `[attached file: <chemin>]` ; un chemin tapé à la main comme `@chemin` est compris de la même façon (voir [`@chemin`](attach-a-file.md)). Le modèle lit le fichier avec ses outils. |
| 34 | 35 | - **Recharger l'agent sans perdre le fil.** Avec `sessions.enabled: true` dans le fichier de configuration, le Reload Agent de l'éditeur (Zed) appelle `session/load` et toute la conversation, appels d'outils compris, est rejouée dans le fil ; et l'historique des fils de l'éditeur liste les conversations stockées du projet (`session/list`), pour en rouvrir une plus ancienne. Voir [Conserver les sessions et les reprendre](keep-sessions.md). Sans `sessions.enabled`, le Reload Agent marche quand même, mais la conversation recommence : mm le dit dans le fil. |
| @@ -29,6 +29,7 @@ Ce guide montre comment héberger `mm` dans un éditeur qui parle l'Agent Client | |||
| 29 | 29 | ||
| 30 | - **Autoriser ou refuser un outil pour toute la session** (`yolo: false`). Choisissez « Allow bash for this session » ou « Never allow bash in this session » dans le dialogue de permission ; le choix est mémorisé par nom d'outil jusqu'à la fin de la session. Voir [Confirmer les appels d'outils](confirm-tool-calls.md). | 30 | - **Autoriser ou refuser un outil pour toute la session** (`yolo: false`). Choisissez « Allow bash for this session » ou « Never allow bash in this session » dans le dialogue de permission ; le choix est mémorisé par nom d'outil jusqu'à la fin de la session. Voir [Confirmer les appels d'outils](confirm-tool-calls.md). |
| 31 | - **Annuler un tour en cours.** Utilisez la touche d'arrêt de l'éditeur (Échap dans Zed). L'agent répond au prompt avec la raison d'arrêt `cancelled` et conserve dans l'historique les commandes déjà exécutées. Il n'y a pas de `/abort` en ACP. | 31 | - **Annuler un tour en cours.** Utilisez la touche d'arrêt de l'éditeur (Échap dans Zed). L'agent répond au prompt avec la raison d'arrêt `cancelled` et conserve dans l'historique les commandes déjà exécutées. Il n'y a pas de `/abort` en ACP. |
| 32 | +- **Corriger le modèle pendant qu'il travaille.** Tapez `/redirect <ce qu'il faut changer>` et envoyez-le avec **Send Now** (Zed : double Entrée) : le tour s'arrête, et le modèle reprend la même tâche avec votre correction — ce qu'il a déjà exécuté est gardé. Sans Send Now, Zed attend la fin du tour pour l'envoyer. Une commande en cours à ce moment-là est arrêtée. Voir [réorienter un tour en cours](../explanation/steering.md). | ||
| 32 | - **Compresser ou recommencer la conversation.** Envoyez `/compact` ou `/new` ; les éditeurs qui listent les commandes de l'agent proposent les deux dans le menu des commandes slash. Voir la [référence des commandes slash](../reference/slash-commands.md#mode-acp). | 33 | - **Compresser ou recommencer la conversation.** Envoyez `/compact` ou `/new` ; les éditeurs qui listent les commandes de l'agent proposent les deux dans le menu des commandes slash. Voir la [référence des commandes slash](../reference/slash-commands.md#mode-acp). |
| 33 | - **Attacher un fichier avec `@`.** Le sélecteur de l'éditeur envoie un `resource_link`, transmis au modèle sous la forme `[attached file: <chemin>]` ; un chemin tapé à la main comme `@chemin` est compris de la même façon (voir [`@chemin`](attach-a-file.md)). Le modèle lit le fichier avec ses outils. | 34 | - **Attacher un fichier avec `@`.** Le sélecteur de l'éditeur envoie un `resource_link`, transmis au modèle sous la forme `[attached file: <chemin>]` ; un chemin tapé à la main comme `@chemin` est compris de la même façon (voir [`@chemin`](attach-a-file.md)). Le modèle lit le fichier avec ses outils. |
| 34 | - **Recharger l'agent sans perdre le fil.** Avec `sessions.enabled: true` dans le fichier de configuration, le Reload Agent de l'éditeur (Zed) appelle `session/load` et toute la conversation, appels d'outils compris, est rejouée dans le fil ; et l'historique des fils de l'éditeur liste les conversations stockées du projet (`session/list`), pour en rouvrir une plus ancienne. Voir [Conserver les sessions et les reprendre](keep-sessions.md). Sans `sessions.enabled`, le Reload Agent marche quand même, mais la conversation recommence : mm le dit dans le fil. | 35 | - **Recharger l'agent sans perdre le fil.** Avec `sessions.enabled: true` dans le fichier de configuration, le Reload Agent de l'éditeur (Zed) appelle `session/load` et toute la conversation, appels d'outils compris, est rejouée dans le fil ; et l'historique des fils de l'éditeur liste les conversations stockées du projet (`session/list`), pour en rouvrir une plus ancienne. Voir [Conserver les sessions et les reprendre](keep-sessions.md). Sans `sessions.enabled`, le Reload Agent marche quand même, mais la conversation recommence : mm le dit dans le fil. |
modified
docs/fr/how-to/use-the-window-mode.md +1 -1 | @@ -16,7 +16,7 @@ Ce guide montre comment lancer mini-me dans une fenêtre unique en plein écran | ||
| 16 | 16 | |
| 17 | 17 | 3. Regardez la réponse arriver dans la conversation. Chaque appel d'outil tient sur une ligne encadrée — `‣ bash ls -1 ✓ done 0.03s` — suivie de sa sortie, repliée à `previewLines` lignes ; les lignes `+`/`-` d'une modification de fichier sont colorées. Le `⏱` de la barre d'état compte le temps écoulé depuis l'envoi de la question, et garde la durée finale une fois la réponse terminée. |
| 18 | 18 | |
| 19 | -4. Pour ajouter quelque chose pendant un tour, tapez-le et appuyez sur **Entrée** : le tour n'est pas arrêté, le texte attend (`⏳ Queued (1)`, et la règle affiche `thinking · 1 queued`) et part comme question suivante une fois la réponse écrite. Appuyez sur **Échap** pour arrêter un tour en cours ; ce qui attend part juste après — tapez la correction, puis Échap, pour réorienter le modèle tout de suite. | |
| 19 | +4. Pour réorienter le modèle pendant un tour, tapez la correction et appuyez sur **Entrée** : le tour n'est pas arrêté, et le modèle lit votre message après son étape en cours — `↪ Steering`, puis `↪ Steered: …` quand il l'a reçu. Pour garder une question pour après le tour, envoyez plutôt `/queue <question>` : elle attend (`⏳ Queued (1)`, et la règle affiche `thinking · 1 queued`) et part comme question suivante une fois la réponse écrite. Un message envoyé pendant que le modèle écrit sa réponse finale arrive trop tard pour ce tour : il part comme question suivante. Appuyez sur **Échap** pour arrêter un tour en cours ; ce qui attend part juste après. | |
| 20 | 20 | |
| 21 | 21 | 5. Tapez `/` en début de zone pour ouvrir le sélecteur de commandes : ↑/↓ choisissent, **Tab** complète, **Entrée** envoie une commande complète. `/help` (ou **F1**) liste les commandes et les touches dans la conversation. |
| 22 | 22 | |
| @@ -16,7 +16,7 @@ Ce guide montre comment lancer mini-me dans une fenêtre unique en plein écran | |||
| 16 | 16 | ||
| 17 | 3. Regardez la réponse arriver dans la conversation. Chaque appel d'outil tient sur une ligne encadrée — `‣ bash ls -1 ✓ done 0.03s` — suivie de sa sortie, repliée à `previewLines` lignes ; les lignes `+`/`-` d'une modification de fichier sont colorées. Le `⏱` de la barre d'état compte le temps écoulé depuis l'envoi de la question, et garde la durée finale une fois la réponse terminée. | 17 | 3. Regardez la réponse arriver dans la conversation. Chaque appel d'outil tient sur une ligne encadrée — `‣ bash ls -1 ✓ done 0.03s` — suivie de sa sortie, repliée à `previewLines` lignes ; les lignes `+`/`-` d'une modification de fichier sont colorées. Le `⏱` de la barre d'état compte le temps écoulé depuis l'envoi de la question, et garde la durée finale une fois la réponse terminée. |
| 18 | 18 | ||
| 19 | -4. Pour ajouter quelque chose pendant un tour, tapez-le et appuyez sur **Entrée** : le tour n'est pas arrêté, le texte attend (`⏳ Queued (1)`, et la règle affiche `thinking · 1 queued`) et part comme question suivante une fois la réponse écrite. Appuyez sur **Échap** pour arrêter un tour en cours ; ce qui attend part juste après — tapez la correction, puis Échap, pour réorienter le modèle tout de suite. | 19 | +4. Pour réorienter le modèle pendant un tour, tapez la correction et appuyez sur **Entrée** : le tour n'est pas arrêté, et le modèle lit votre message après son étape en cours — `↪ Steering`, puis `↪ Steered: …` quand il l'a reçu. Pour garder une question pour après le tour, envoyez plutôt `/queue <question>` : elle attend (`⏳ Queued (1)`, et la règle affiche `thinking · 1 queued`) et part comme question suivante une fois la réponse écrite. Un message envoyé pendant que le modèle écrit sa réponse finale arrive trop tard pour ce tour : il part comme question suivante. Appuyez sur **Échap** pour arrêter un tour en cours ; ce qui attend part juste après. |
| 20 | 20 | ||
| 21 | 5. Tapez `/` en début de zone pour ouvrir le sélecteur de commandes : ↑/↓ choisissent, **Tab** complète, **Entrée** envoie une commande complète. `/help` (ou **F1**) liste les commandes et les touches dans la conversation. | 21 | 5. Tapez `/` en début de zone pour ouvrir le sélecteur de commandes : ↑/↓ choisissent, **Tab** complète, **Entrée** envoie une commande complète. `/help` (ou **F1**) liste les commandes et les touches dans la conversation. |
| 22 | 22 | ||
modified
docs/fr/reference/acp.md +1 -0 | @@ -45,6 +45,7 @@ ACP n'a aucune notion de skill. Un prompt porte du `text`, une `image`, de l'`au | ||
| 45 | 45 | ``` |
| 46 | 46 | /compact Compress the history now, keeping the last turns |
| 47 | 47 | /new Clear the history and start a new session |
| 48 | +/redirect [input: <message>] Correct the task in progress — send it with Send Now (double Enter) … | |
| 48 | 49 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… |
| 49 | 50 | /greetings [input: parameters, if …] Greet somebody with a festive message. |
| 50 | 51 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. |
| @@ -45,6 +45,7 @@ ACP n'a aucune notion de skill. Un prompt porte du `text`, une `image`, de l'`au | |||
| 45 | ``` | 45 | ``` |
| 46 | /compact Compress the history now, keeping the last turns | 46 | /compact Compress the history now, keeping the last turns |
| 47 | /new Clear the history and start a new session | 47 | /new Clear the history and start a new session |
| 48 | +/redirect [input: <message>] Correct the task in progress — send it with Send Now (double Enter) … | ||
| 48 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… | 49 | /bg-jobs [input: parameters, if …] Start, wait on, inspect and stop a long-running background job… |
| 49 | /greetings [input: parameters, if …] Greet somebody with a festive message. | 50 | /greetings [input: parameters, if …] Greet somebody with a festive message. |
| 50 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. | 51 | /vulcan-salute [input: parameters, if …] Send a vulcan salute to somebody. |
modified
docs/fr/reference/slash-commands.md +14 -8 | @@ -17,6 +17,7 @@ | ||
| 17 | 17 | | `/memory <mots>` | Avec `sessions.enabled` et `sessions.searchMemory` : cherche dans les sessions enregistrées du projet et affiche `🔎 N hit(s) for "<mots>" in <rép>`, puis deux lignes par résultat — `<id de session> · <date> · turn <n> · question\|answer\|summary` et le texte autour des mots trouvés, plus `→ <réponse>` sous une question (la réponse sur laquelle son tour s'est terminé) — ou `🔎 no hit for "<mots>" in <rép>`. La casse et les accents ne comptent pas ; les mots d'une ou deux lettres sont ignorés à côté de mots plus longs ; un résultat contient au moins un des mots ; les résultats sont classés par nombre de mots contenus, puis du plus récent au plus ancien ; 10 au plus. Les questions, les réponses et les résumés de `/compact` sont cherchés, pas les appels d'outils ; la conversation en cours est exclue. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | |
| 18 | 18 | | `/docs <mots>` | Avec `docSearch.searchDocs` : cherche avec BM25 dans les fichiers texte de `docSearch.dirs` et affiche `🔎 N passage(s) for "<mots>" — F file(s) in <dossiers>`, puis par passage une ligne `── <chemin>:<ligne> · <titre › sous-titre>` et le passage tel qu'il est écrit ; ou `🔎 no passage for "<mots>" — F file(s) in <dossiers>`. La casse et les accents ne comptent pas ; les mots de 4 lettres ou plus trouvent aussi les mots plus longs et les pluriels ; 5 passages au plus. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | |
| 19 | 19 | | `/unload [modèle]` | Avec `unloadModels` (activé par défaut) : décharge un modèle de la mémoire du serveur — celui de l'agent, ou celui nommé — et affiche une ligne : `🧹 unloaded <modèle>`, `🧹 <modèle> was not loaded: nothing to unload`, ou `🧹 cannot unload <modèle>: <raison>` (un fournisseur ou un serveur qui n'a aucun moyen de le faire). L'historique n'est pas touché ; la question suivante recharge le modèle de l'agent. | Envoyée au modèle comme nouveau message. | |
| 20 | +| `/redirect <message>` | Éditeur uniquement (ticket 267), annoncée avec l'indication de saisie `<message>`. Lance un tour sur l'historique de la session dont la question est `[the user redirects the task in progress] <message>` suivi de `Continue the task you were working on, taking this into account.` Prévue pour être envoyée avec le « Send Now » de l'éditeur (Zed : double Entrée), qui annule d'abord le tour en cours ; les commandes et résultats du tour annulé restent dans l'historique, le modèle reprend donc cette tâche avec la correction. Un outil en cours au moment de l'annulation s'arrête avec le tour. Envoyée sans « Send Now », l'éditeur la transmet une fois le tour terminé. `/redirect` seul répond `/redirect needs a message: …` sans tour. | | |
| 20 | 21 | | `/copy [n\|all]` | Copie la dernière réponse (`n` : la n-ième depuis la fin) dans le presse-papiers via `pbcopy`/`wl-copy`/`xclip`/`xsel` ou, à défaut, OSC 52 quand stdout est un terminal, et affiche `📋 copied N chars (<chemin>)` ou `⚠️ …`. `/copy all` est réservé au mode fenêtre : ici la commande le dit. | Envoyée au modèle comme nouveau message. | |
| 21 | 22 | |
| 22 | 23 | Avec `sessions.enabled`, `/new` laisse le fichier de la session courante tel quel ; la question suivante ouvre un nouveau fichier. Une ligne vide à l'invite est ignorée. |
| @@ -41,7 +42,7 @@ Pendant l'exécution : | ||
| 41 | 42 | | Appels d'outils de `<nom>` | Affichés comme des appels d'outils intitulés `<nom> · <outil>: <arguments>`. Les demandes de permission passent par cette façade : aucune en mode ligne (autorisé), `permissions` en mode fenêtre (`a`/`s`/`r`, « pour cette session » indexé sur `<nom>/<outil>`), la boîte de dialogue de l'éditeur en ACP. | |
| 42 | 43 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Annulent la demande ; `🔴 Ask aborted — nothing kept.` | |
| 43 | 44 | | `/quit` | Annule la demande et quitte. | |
| 44 | -| Toute autre ligne (mode ligne) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn` ; la ligne part une fois la demande terminée, comme une ligne tapée pendant une génération (plus bas). | | |
| 45 | +| Toute autre ligne (mode ligne) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn` ; la ligne part une fois la demande terminée — une demande n'est pas réorientée, contrairement à une génération (plus bas). | | |
| 45 | 46 | |
| 46 | 47 | À la fin : |
| 47 | 48 | |
| @@ -93,9 +94,10 @@ Détails et exemples : [Désigner un fichier au modèle avec `@chemin`](../how-t | ||
| 93 | 94 | |
| 94 | 95 | | Saisie | Comportement | |
| 95 | 96 | |--------|--------------| |
| 96 | -| Une ligne qui n'est pas une commande, ou une commande autre que `/abort` et `/quit` | N'arrête pas la génération. Affiche `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` étant le nombre de lignes en attente. Une fois le tour terminé, les lignes en attente partent dans l'ordre où elles ont été tapées, chacune réaffichée après l'invite `>` comme si elle y avait été tapée. | | |
| 97 | +| Une ligne qui n'est pas une commande | **Réoriente** la génération sans l'arrêter (ticket 265) : affiche `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn` ; le modèle la reçoit après ses prochains résultats d'outils, comme message utilisateur `[message from the user during this turn] <texte>` (`@chemin` et `$skill` développés), et `↪ Steered: <première ligne>` indique quand. Une ligne envoyée après le dernier appel du modèle — pendant qu'il écrit sa réponse finale — part comme question suivante : `⏳ N message(s) came after the model's last call — sent as the next question`. | | |
| 98 | +| `/queue <question>`, ou une commande autre que `/abort` et `/quit` | N'arrête pas la génération. Affiche `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` étant le nombre de lignes en attente. Une fois le tour terminé, les lignes en attente partent dans l'ordre où elles ont été tapées, chacune réaffichée après l'invite `>` comme si elle y avait été tapée (pour `/queue`, la question seule). `/queue` seul affiche `⚠️ /queue needs a question: /queue <question>`. | | |
| 97 | 99 | | Une ligne vide | Ignorée. | |
| 98 | -| `/abort`, `Ctrl+C` | Arrêtent la génération ; les lignes en attente partent ensuite. | | |
| 100 | +| `/abort`, `Ctrl+C` | Arrêtent la génération ; les lignes en attente, et les lignes de réorientation que le modèle n'a pas reçues, partent ensuite. | | |
| 99 | 101 | | Fin de l'entrée (la fin d'un pipe) | La génération continue ; les lignes en attente partent, puis `mm` se termine. | |
| 100 | 102 | |
| 101 | 103 | ## Raccourcis clavier |
| @@ -107,9 +109,13 @@ Détails et exemples : [Désigner un fichier au modèle avec `@chemin`](../how-t | ||
| 107 | 109 | |
| 108 | 110 | ## Touches du mode fenêtre |
| 109 | 111 | |
| 110 | -Dans `mm -tui` les mêmes commandes existent, plus `/shell` ; `/abort` au repos affiche `⚠️ No generation in progress.` comme notice, et le sélecteur ouvert par `/` les liste. | |
| 112 | +Dans `mm -tui` les mêmes commandes existent, plus `/shell` et `/queue` ; `/abort` au repos affiche `⚠️ No generation in progress.` comme notice, et le sélecteur ouvert par `/` les liste. | |
| 111 | 113 | |
| 112 | -`/quit`, `/abort` et `/shell` prennent effet **immédiatement**, même pendant un tour. Toutes les autres commandes et toutes les questions attendent la fin du tour, parce qu'elles ont besoin de l'historique que le tour est encore en train d'écrire. Voir [Sortir d'un tour qui ne s'arrête pas](#sortir-dun-tour-qui-ne-sarrête-pas). | |
| 114 | +`/quit`, `/abort`, `/shell` et `/queue` prennent effet **immédiatement**, même pendant un tour. Une question envoyée pendant un tour le **réoriente** (steer) : le modèle la lit après son étape en cours, et le tour continue (voir la touche `Entrée` plus bas). Toutes les autres commandes attendent la fin du tour, parce qu'elles ont besoin de l'historique que le tour est encore en train d'écrire. Voir [Sortir d'un tour qui ne s'arrête pas](#sortir-dun-tour-qui-ne-sarrête-pas). | |
| 115 | + | |
| 116 | +### `/queue` | |
| 117 | + | |
| 118 | +Mode ligne et mode fenêtre (pas l'éditeur, qui n'a pas de réorientation). `/queue <question>` : pendant un tour, la question attend la fin du tour et part comme question suivante (`⏳ Queued (N) — runs once this turn ends · …`) au lieu de réorienter le tour ; quand aucun tour ne tourne, elle part tout de suite. Sans question : `⚠️ /queue needs a question: /queue <question>`. | |
| 113 | 119 | |
| 114 | 120 | ### `/shell` |
| 115 | 121 | |
| @@ -149,9 +155,9 @@ Les touches : | ||
| 149 | 155 | |
| 150 | 156 | | Touche | Action | |
| 151 | 157 | |--------|--------| |
| 152 | -| `Entrée` | Envoie la zone (rien sur une zone vide). Pendant un tour, le texte ne l'arrête pas : il est mis en attente (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, la règle affiche `<état> · N queued`) et les entrées en attente partent dans l'ordre une fois le tour rangé ; `/quit`, `/abort` et `/shell` s'exécutent tout de suite. Avec le sélecteur ouvert sur un nom incomplet, le complète à la place. | | |
| 158 | +| `Entrée` | Envoie la zone (rien sur une zone vide). Pendant un tour, une question le **réoriente** (steer) sans l'arrêter : elle s'affiche tout de suite avec `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`, entre dans l'historique comme message utilisateur `[message from the user during this turn] <texte>` juste après les prochains résultats d'outils, et `↪ Steered: <première ligne>` indique quand le modèle l'a reçue. Une question envoyée après le dernier appel du modèle — pendant qu'il écrit sa réponse finale — part comme question suivante (`⏳ N message(s) came after the model's last call — sent as the next question`). Une commande autre que `/quit`, `/abort`, `/shell` et `/queue`, ainsi que `/queue <question>`, est mise en attente (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, la règle affiche `<état> · N queued`) et les entrées en attente partent dans l'ordre une fois le tour rangé. Avec le sélecteur ouvert sur un nom incomplet, le complète à la place. | | |
| 153 | 159 | | `Ctrl-J`, `Alt-Entrée` | Insère un saut de ligne dans la zone. | |
| 154 | -| `Échap` | Annule le tour en cours (comme `/abort`) — les entrées en attente partent ensuite ; quand aucun tour ne tourne et que la zone n'est pas vide, vide la zone à la place ; ferme le sélecteur ; refuse une permission en attente. | | |
| 160 | +| `Échap` | Annule le tour en cours (comme `/abort`) — les entrées en attente, et les questions de réorientation que le modèle n'a pas reçues, partent ensuite ; quand aucun tour ne tourne et que la zone n'est pas vide, vide la zone à la place ; ferme le sélecteur ; refuse une permission en attente. | | |
| 155 | 161 | | `Ctrl-C` | Annule le tour en cours ; quitte au repos — et quitte aussi lorsque le tour a déjà reçu l'ordre de s'arrêter et ne l'a pas fait. | |
| 156 | 162 | | `Tab` | Déplace le focus entre la zone et la conversation ; complète le choix du sélecteur quand il est ouvert (`/`, `@` ou `$`). | |
| 157 | 163 | | `↑` `↓` | Dans la zone : passent d'une rangée à l'autre — une ligne longue est repliée aux espaces sur plusieurs rangées. Depuis la première rangée, `↑` rappelle la question précédente (sessions activées : cette session, puis les précédentes, de la plus récente à la plus ancienne) ; depuis la dernière rangée pendant un rappel, `↓` la suivante, puis le texte tapé avant. Sans rien à rappeler, ils font défiler la conversation depuis la première/dernière rangée. Sur la conversation : défilent d'une ligne. Dans le sélecteur : déplacent le choix. | |
| @@ -225,7 +231,7 @@ La notation marche aussi en mode ligne et en ACP, tapée à la main : un `$skill | ||
| 225 | 231 | |
| 226 | 232 | ## Mode ACP |
| 227 | 233 | |
| 228 | -Deux commandes existent en mode ACP, trois avec `unloadModels` (le défaut) : `/new`, `/compact` et `/unload` — plus `/memory` avec `sessions.searchMemory` et `/docs` avec `docSearch.searchDocs`. Elles sont annoncées à l'éditeur par une notification `available_commands_update` et interceptées par `session/prompt` quand le texte du prompt, débarrassé de ses espaces, est exactement la commande (`/unload` peut être suivie d'un nom de modèle, `/memory` et `/docs` de leurs mots). Chacune répond par un `agent_message_chunk` portant la ligne que le terminal afficherait, puis `stopReason: end_turn` ; le modèle n'est pas consulté. | |
| 234 | +Trois commandes existent en mode ACP, quatre avec `unloadModels` (le défaut) : `/new`, `/compact`, `/redirect` et `/unload` — plus `/memory` avec `sessions.searchMemory` et `/docs` avec `docSearch.searchDocs`. Elles sont annoncées à l'éditeur par une notification `available_commands_update` et interceptées par `session/prompt` quand le texte du prompt, débarrassé de ses espaces, est exactement la commande (`/unload` peut être suivie d'un nom de modèle, `/memory` et `/docs` de leurs mots). Chacune répond par un `agent_message_chunk` portant la ligne que le terminal afficherait, puis `stopReason: end_turn` ; le modèle n'est pas consulté. | |
| 229 | 235 | |
| 230 | 236 | | Commande | En ACP | |
| 231 | 237 | |----------|--------| |
| @@ -17,6 +17,7 @@ | |||
| 17 | | `/memory <mots>` | Avec `sessions.enabled` et `sessions.searchMemory` : cherche dans les sessions enregistrées du projet et affiche `🔎 N hit(s) for "<mots>" in <rép>`, puis deux lignes par résultat — `<id de session> · <date> · turn <n> · question\|answer\|summary` et le texte autour des mots trouvés, plus `→ <réponse>` sous une question (la réponse sur laquelle son tour s'est terminé) — ou `🔎 no hit for "<mots>" in <rép>`. La casse et les accents ne comptent pas ; les mots d'une ou deux lettres sont ignorés à côté de mots plus longs ; un résultat contient au moins un des mots ; les résultats sont classés par nombre de mots contenus, puis du plus récent au plus ancien ; 10 au plus. Les questions, les réponses et les résumés de `/compact` sont cherchés, pas les appels d'outils ; la conversation en cours est exclue. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | | 17 | | `/memory <mots>` | Avec `sessions.enabled` et `sessions.searchMemory` : cherche dans les sessions enregistrées du projet et affiche `🔎 N hit(s) for "<mots>" in <rép>`, puis deux lignes par résultat — `<id de session> · <date> · turn <n> · question\|answer\|summary` et le texte autour des mots trouvés, plus `→ <réponse>` sous une question (la réponse sur laquelle son tour s'est terminé) — ou `🔎 no hit for "<mots>" in <rép>`. La casse et les accents ne comptent pas ; les mots d'une ou deux lettres sont ignorés à côté de mots plus longs ; un résultat contient au moins un des mots ; les résultats sont classés par nombre de mots contenus, puis du plus récent au plus ancien ; 10 au plus. Les questions, les réponses et les résumés de `/compact` sont cherchés, pas les appels d'outils ; la conversation en cours est exclue. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | |
| 18 | | `/docs <mots>` | Avec `docSearch.searchDocs` : cherche avec BM25 dans les fichiers texte de `docSearch.dirs` et affiche `🔎 N passage(s) for "<mots>" — F file(s) in <dossiers>`, puis par passage une ligne `── <chemin>:<ligne> · <titre › sous-titre>` et le passage tel qu'il est écrit ; ou `🔎 no passage for "<mots>" — F file(s) in <dossiers>`. La casse et les accents ne comptent pas ; les mots de 4 lettres ou plus trouvent aussi les mots plus longs et les pluriels ; 5 passages au plus. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | | 18 | | `/docs <mots>` | Avec `docSearch.searchDocs` : cherche avec BM25 dans les fichiers texte de `docSearch.dirs` et affiche `🔎 N passage(s) for "<mots>" — F file(s) in <dossiers>`, puis par passage une ligne `── <chemin>:<ligne> · <titre › sous-titre>` et le passage tel qu'il est écrit ; ou `🔎 no passage for "<mots>" — F file(s) in <dossiers>`. La casse et les accents ne comptent pas ; les mots de 4 lettres ou plus trouvent aussi les mots plus longs et les pluriels ; 5 passages au plus. Sans mots : `⚠️ nothing to search: give one or more words`. Le modèle n'est pas appelé ; l'historique n'est pas touché. | Envoyée au modèle comme nouveau message. | |
| 19 | | `/unload [modèle]` | Avec `unloadModels` (activé par défaut) : décharge un modèle de la mémoire du serveur — celui de l'agent, ou celui nommé — et affiche une ligne : `🧹 unloaded <modèle>`, `🧹 <modèle> was not loaded: nothing to unload`, ou `🧹 cannot unload <modèle>: <raison>` (un fournisseur ou un serveur qui n'a aucun moyen de le faire). L'historique n'est pas touché ; la question suivante recharge le modèle de l'agent. | Envoyée au modèle comme nouveau message. | | 19 | | `/unload [modèle]` | Avec `unloadModels` (activé par défaut) : décharge un modèle de la mémoire du serveur — celui de l'agent, ou celui nommé — et affiche une ligne : `🧹 unloaded <modèle>`, `🧹 <modèle> was not loaded: nothing to unload`, ou `🧹 cannot unload <modèle>: <raison>` (un fournisseur ou un serveur qui n'a aucun moyen de le faire). L'historique n'est pas touché ; la question suivante recharge le modèle de l'agent. | Envoyée au modèle comme nouveau message. | |
| 20 | +| `/redirect <message>` | Éditeur uniquement (ticket 267), annoncée avec l'indication de saisie `<message>`. Lance un tour sur l'historique de la session dont la question est `[the user redirects the task in progress] <message>` suivi de `Continue the task you were working on, taking this into account.` Prévue pour être envoyée avec le « Send Now » de l'éditeur (Zed : double Entrée), qui annule d'abord le tour en cours ; les commandes et résultats du tour annulé restent dans l'historique, le modèle reprend donc cette tâche avec la correction. Un outil en cours au moment de l'annulation s'arrête avec le tour. Envoyée sans « Send Now », l'éditeur la transmet une fois le tour terminé. `/redirect` seul répond `/redirect needs a message: …` sans tour. | | ||
| 20 | | `/copy [n\|all]` | Copie la dernière réponse (`n` : la n-ième depuis la fin) dans le presse-papiers via `pbcopy`/`wl-copy`/`xclip`/`xsel` ou, à défaut, OSC 52 quand stdout est un terminal, et affiche `📋 copied N chars (<chemin>)` ou `⚠️ …`. `/copy all` est réservé au mode fenêtre : ici la commande le dit. | Envoyée au modèle comme nouveau message. | | 21 | | `/copy [n\|all]` | Copie la dernière réponse (`n` : la n-ième depuis la fin) dans le presse-papiers via `pbcopy`/`wl-copy`/`xclip`/`xsel` ou, à défaut, OSC 52 quand stdout est un terminal, et affiche `📋 copied N chars (<chemin>)` ou `⚠️ …`. `/copy all` est réservé au mode fenêtre : ici la commande le dit. | Envoyée au modèle comme nouveau message. | |
| 21 | 22 | ||
| 22 | Avec `sessions.enabled`, `/new` laisse le fichier de la session courante tel quel ; la question suivante ouvre un nouveau fichier. Une ligne vide à l'invite est ignorée. | 23 | Avec `sessions.enabled`, `/new` laisse le fichier de la session courante tel quel ; la question suivante ouvre un nouveau fichier. Une ligne vide à l'invite est ignorée. |
| @@ -41,7 +42,7 @@ Pendant l'exécution : | |||
| 41 | | Appels d'outils de `<nom>` | Affichés comme des appels d'outils intitulés `<nom> · <outil>: <arguments>`. Les demandes de permission passent par cette façade : aucune en mode ligne (autorisé), `permissions` en mode fenêtre (`a`/`s`/`r`, « pour cette session » indexé sur `<nom>/<outil>`), la boîte de dialogue de l'éditeur en ACP. | | 42 | | Appels d'outils de `<nom>` | Affichés comme des appels d'outils intitulés `<nom> · <outil>: <arguments>`. Les demandes de permission passent par cette façade : aucune en mode ligne (autorisé), `permissions` en mode fenêtre (`a`/`s`/`r`, « pour cette session » indexé sur `<nom>/<outil>`), la boîte de dialogue de l'éditeur en ACP. | |
| 42 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Annulent la demande ; `🔴 Ask aborted — nothing kept.` | | 43 | | `/abort`, `Esc`, `Ctrl+C`, `session/cancel` | Annulent la demande ; `🔴 Ask aborted — nothing kept.` | |
| 43 | | `/quit` | Annule la demande et quitte. | | 44 | | `/quit` | Annule la demande et quitte. | |
| 44 | -| Toute autre ligne (mode ligne) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn` ; la ligne part une fois la demande terminée, comme une ligne tapée pendant une génération (plus bas). | | 45 | +| Toute autre ligne (mode ligne) | `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn` ; la ligne part une fois la demande terminée — une demande n'est pas réorientée, contrairement à une génération (plus bas). | |
| 45 | 46 | ||
| 46 | À la fin : | 47 | À la fin : |
| 47 | 48 | ||
| @@ -93,9 +94,10 @@ Détails et exemples : [Désigner un fichier au modèle avec `@chemin`](../how-t | |||
| 93 | 94 | ||
| 94 | | Saisie | Comportement | | 95 | | Saisie | Comportement | |
| 95 | |--------|--------------| | 96 | |--------|--------------| |
| 96 | -| Une ligne qui n'est pas une commande, ou une commande autre que `/abort` et `/quit` | N'arrête pas la génération. Affiche `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` étant le nombre de lignes en attente. Une fois le tour terminé, les lignes en attente partent dans l'ordre où elles ont été tapées, chacune réaffichée après l'invite `>` comme si elle y avait été tapée. | | 97 | +| Une ligne qui n'est pas une commande | **Réoriente** la génération sans l'arrêter (ticket 265) : affiche `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn` ; le modèle la reçoit après ses prochains résultats d'outils, comme message utilisateur `[message from the user during this turn] <texte>` (`@chemin` et `$skill` développés), et `↪ Steered: <première ligne>` indique quand. Une ligne envoyée après le dernier appel du modèle — pendant qu'il écrit sa réponse finale — part comme question suivante : `⏳ N message(s) came after the model's last call — sent as the next question`. | |
| 98 | +| `/queue <question>`, ou une commande autre que `/abort` et `/quit` | N'arrête pas la génération. Affiche `⏳ Queued (N) — runs once this turn ends · /abort or Ctrl+C stops the turn`, `N` étant le nombre de lignes en attente. Une fois le tour terminé, les lignes en attente partent dans l'ordre où elles ont été tapées, chacune réaffichée après l'invite `>` comme si elle y avait été tapée (pour `/queue`, la question seule). `/queue` seul affiche `⚠️ /queue needs a question: /queue <question>`. | | ||
| 97 | | Une ligne vide | Ignorée. | | 99 | | Une ligne vide | Ignorée. | |
| 98 | -| `/abort`, `Ctrl+C` | Arrêtent la génération ; les lignes en attente partent ensuite. | | 100 | +| `/abort`, `Ctrl+C` | Arrêtent la génération ; les lignes en attente, et les lignes de réorientation que le modèle n'a pas reçues, partent ensuite. | |
| 99 | | Fin de l'entrée (la fin d'un pipe) | La génération continue ; les lignes en attente partent, puis `mm` se termine. | | 101 | | Fin de l'entrée (la fin d'un pipe) | La génération continue ; les lignes en attente partent, puis `mm` se termine. | |
| 100 | 102 | ||
| 101 | ## Raccourcis clavier | 103 | ## Raccourcis clavier |
| @@ -107,9 +109,13 @@ Détails et exemples : [Désigner un fichier au modèle avec `@chemin`](../how-t | |||
| 107 | 109 | ||
| 108 | ## Touches du mode fenêtre | 110 | ## Touches du mode fenêtre |
| 109 | 111 | ||
| 110 | -Dans `mm -tui` les mêmes commandes existent, plus `/shell` ; `/abort` au repos affiche `⚠️ No generation in progress.` comme notice, et le sélecteur ouvert par `/` les liste. | 112 | +Dans `mm -tui` les mêmes commandes existent, plus `/shell` et `/queue` ; `/abort` au repos affiche `⚠️ No generation in progress.` comme notice, et le sélecteur ouvert par `/` les liste. |
| 111 | 113 | ||
| 112 | -`/quit`, `/abort` et `/shell` prennent effet **immédiatement**, même pendant un tour. Toutes les autres commandes et toutes les questions attendent la fin du tour, parce qu'elles ont besoin de l'historique que le tour est encore en train d'écrire. Voir [Sortir d'un tour qui ne s'arrête pas](#sortir-dun-tour-qui-ne-sarrête-pas). | 114 | +`/quit`, `/abort`, `/shell` et `/queue` prennent effet **immédiatement**, même pendant un tour. Une question envoyée pendant un tour le **réoriente** (steer) : le modèle la lit après son étape en cours, et le tour continue (voir la touche `Entrée` plus bas). Toutes les autres commandes attendent la fin du tour, parce qu'elles ont besoin de l'historique que le tour est encore en train d'écrire. Voir [Sortir d'un tour qui ne s'arrête pas](#sortir-dun-tour-qui-ne-sarrête-pas). |
| 115 | + | ||
| 116 | +### `/queue` | ||
| 117 | + | ||
| 118 | +Mode ligne et mode fenêtre (pas l'éditeur, qui n'a pas de réorientation). `/queue <question>` : pendant un tour, la question attend la fin du tour et part comme question suivante (`⏳ Queued (N) — runs once this turn ends · …`) au lieu de réorienter le tour ; quand aucun tour ne tourne, elle part tout de suite. Sans question : `⚠️ /queue needs a question: /queue <question>`. | ||
| 113 | 119 | ||
| 114 | ### `/shell` | 120 | ### `/shell` |
| 115 | 121 | ||
| @@ -149,9 +155,9 @@ Les touches : | |||
| 149 | 155 | ||
| 150 | | Touche | Action | | 156 | | Touche | Action | |
| 151 | |--------|--------| | 157 | |--------|--------| |
| 152 | -| `Entrée` | Envoie la zone (rien sur une zone vide). Pendant un tour, le texte ne l'arrête pas : il est mis en attente (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, la règle affiche `<état> · N queued`) et les entrées en attente partent dans l'ordre une fois le tour rangé ; `/quit`, `/abort` et `/shell` s'exécutent tout de suite. Avec le sélecteur ouvert sur un nom incomplet, le complète à la place. | | 158 | +| `Entrée` | Envoie la zone (rien sur une zone vide). Pendant un tour, une question le **réoriente** (steer) sans l'arrêter : elle s'affiche tout de suite avec `↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn`, entre dans l'historique comme message utilisateur `[message from the user during this turn] <texte>` juste après les prochains résultats d'outils, et `↪ Steered: <première ligne>` indique quand le modèle l'a reçue. Une question envoyée après le dernier appel du modèle — pendant qu'il écrit sa réponse finale — part comme question suivante (`⏳ N message(s) came after the model's last call — sent as the next question`). Une commande autre que `/quit`, `/abort`, `/shell` et `/queue`, ainsi que `/queue <question>`, est mise en attente (`⏳ Queued (N) — runs once this turn ends · Esc stops the turn`, la règle affiche `<état> · N queued`) et les entrées en attente partent dans l'ordre une fois le tour rangé. Avec le sélecteur ouvert sur un nom incomplet, le complète à la place. | |
| 153 | | `Ctrl-J`, `Alt-Entrée` | Insère un saut de ligne dans la zone. | | 159 | | `Ctrl-J`, `Alt-Entrée` | Insère un saut de ligne dans la zone. | |
| 154 | -| `Échap` | Annule le tour en cours (comme `/abort`) — les entrées en attente partent ensuite ; quand aucun tour ne tourne et que la zone n'est pas vide, vide la zone à la place ; ferme le sélecteur ; refuse une permission en attente. | | 160 | +| `Échap` | Annule le tour en cours (comme `/abort`) — les entrées en attente, et les questions de réorientation que le modèle n'a pas reçues, partent ensuite ; quand aucun tour ne tourne et que la zone n'est pas vide, vide la zone à la place ; ferme le sélecteur ; refuse une permission en attente. | |
| 155 | | `Ctrl-C` | Annule le tour en cours ; quitte au repos — et quitte aussi lorsque le tour a déjà reçu l'ordre de s'arrêter et ne l'a pas fait. | | 161 | | `Ctrl-C` | Annule le tour en cours ; quitte au repos — et quitte aussi lorsque le tour a déjà reçu l'ordre de s'arrêter et ne l'a pas fait. | |
| 156 | | `Tab` | Déplace le focus entre la zone et la conversation ; complète le choix du sélecteur quand il est ouvert (`/`, `@` ou `$`). | | 162 | | `Tab` | Déplace le focus entre la zone et la conversation ; complète le choix du sélecteur quand il est ouvert (`/`, `@` ou `$`). | |
| 157 | | `↑` `↓` | Dans la zone : passent d'une rangée à l'autre — une ligne longue est repliée aux espaces sur plusieurs rangées. Depuis la première rangée, `↑` rappelle la question précédente (sessions activées : cette session, puis les précédentes, de la plus récente à la plus ancienne) ; depuis la dernière rangée pendant un rappel, `↓` la suivante, puis le texte tapé avant. Sans rien à rappeler, ils font défiler la conversation depuis la première/dernière rangée. Sur la conversation : défilent d'une ligne. Dans le sélecteur : déplacent le choix. | | 163 | | `↑` `↓` | Dans la zone : passent d'une rangée à l'autre — une ligne longue est repliée aux espaces sur plusieurs rangées. Depuis la première rangée, `↑` rappelle la question précédente (sessions activées : cette session, puis les précédentes, de la plus récente à la plus ancienne) ; depuis la dernière rangée pendant un rappel, `↓` la suivante, puis le texte tapé avant. Sans rien à rappeler, ils font défiler la conversation depuis la première/dernière rangée. Sur la conversation : défilent d'une ligne. Dans le sélecteur : déplacent le choix. | |
| @@ -225,7 +231,7 @@ La notation marche aussi en mode ligne et en ACP, tapée à la main : un `$skill | |||
| 225 | 231 | ||
| 226 | ## Mode ACP | 232 | ## Mode ACP |
| 227 | 233 | ||
| 228 | -Deux commandes existent en mode ACP, trois avec `unloadModels` (le défaut) : `/new`, `/compact` et `/unload` — plus `/memory` avec `sessions.searchMemory` et `/docs` avec `docSearch.searchDocs`. Elles sont annoncées à l'éditeur par une notification `available_commands_update` et interceptées par `session/prompt` quand le texte du prompt, débarrassé de ses espaces, est exactement la commande (`/unload` peut être suivie d'un nom de modèle, `/memory` et `/docs` de leurs mots). Chacune répond par un `agent_message_chunk` portant la ligne que le terminal afficherait, puis `stopReason: end_turn` ; le modèle n'est pas consulté. | 234 | +Trois commandes existent en mode ACP, quatre avec `unloadModels` (le défaut) : `/new`, `/compact`, `/redirect` et `/unload` — plus `/memory` avec `sessions.searchMemory` et `/docs` avec `docSearch.searchDocs`. Elles sont annoncées à l'éditeur par une notification `available_commands_update` et interceptées par `session/prompt` quand le texte du prompt, débarrassé de ses espaces, est exactement la commande (`/unload` peut être suivie d'un nom de modèle, `/memory` et `/docs` de leurs mots). Chacune répond par un `agent_message_chunk` portant la ligne que le terminal afficherait, puis `stopReason: end_turn` ; le modèle n'est pas consulté. |
| 229 | 235 | ||
| 230 | | Commande | En ACP | | 236 | | Commande | En ACP | |
| 231 | |----------|--------| | 237 | |----------|--------| |
modified
internal/acp/acp.go +29 -0 | @@ -362,6 +362,9 @@ func (f *front) Prompt(ctx context.Context, p sdk.PromptRequest) (sdk.PromptResp | ||
| 362 | 362 | // after slashCommand, so a real command always wins whatever a skill is |
| 363 | 363 | // called. |
| 364 | 364 | input = skillCommand(input) |
| 365 | + // /redirect <message> (ticket 267): a turn like any other, its question | |
| 366 | + // framed as a correction of the task the history holds. | |
| 367 | + input = redirectCommand(input) | |
| 365 | 368 | |
| 366 | 369 | // One cancellable context per turn: session/cancel fires s.cancel, the |
| 367 | 370 | // generation and any pending permission request fall with it, and the spec's |
| @@ -483,6 +486,8 @@ func (f *front) slashCommand(ctx context.Context, sid sdk.SessionId, s *session, | ||
| 483 | 486 | return f.searchMemory(ctx, sid, s, arg), true |
| 484 | 487 | case ok && cmd.Name == command.Docs: |
| 485 | 488 | return f.searchDocs(ctx, sid, s, arg), true |
| 489 | + case ok && cmd.Name == command.Redirect && arg == "": | |
| 490 | + return f.say(ctx, sid, s, redirectNeedsMessage), true | |
| 486 | 491 | } |
| 487 | 492 | return sdk.PromptResponse{}, false |
| 488 | 493 | } |
| @@ -667,3 +672,27 @@ func (f *front) CloseSession(context.Context, sdk.CloseSessionRequest) (sdk.Clos | ||
| 667 | 672 | func (f *front) Logout(context.Context, sdk.LogoutRequest) (sdk.LogoutResponse, error) { |
| 668 | 673 | return sdk.LogoutResponse{}, sdk.NewMethodNotFound(sdk.AgentMethodLogout) |
| 669 | 674 | } |
| 675 | + | |
| 676 | +// redirectNeedsMessage is the answer to a bare /redirect. | |
| 677 | +const redirectNeedsMessage = "/redirect needs a message: /redirect <what to change in the task in progress> — send it with Send Now (double Enter) to stop the turn first." | |
| 678 | + | |
| 679 | +// redirectCommand turns "/redirect <message>" into the framed question the | |
| 680 | +// model reads (engine.Redirect); any other input is returned unchanged. | |
| 681 | +// Sent with Zed's "Send Now", it follows a cancelled turn whose work the | |
| 682 | +// history kept (session.AfterTurn), so the model continues that task. | |
| 683 | +// | |
| 684 | +// redirectCommand("/redirect use the v2 API") | |
| 685 | +// // "[the user redirects the task in progress] use the v2 API\n\nContinue the task …" | |
| 686 | +func redirectCommand(input string) string { | |
| 687 | + cmd, arg, ok := command.Parse(input) | |
| 688 | + if !ok || cmd.Name != command.Redirect || arg == "" { | |
| 689 | + return input | |
| 690 | + } | |
| 691 | + return engine.Redirect(arg) | |
| 692 | +} | |
| 693 | + | |
| 694 | +// say answers a prompt with one agent message, without a turn. | |
| 695 | +func (f *front) say(ctx context.Context, sid sdk.SessionId, s *session, text string) sdk.PromptResponse { | |
| 696 | + _ = f.conn.SessionUpdate(ctx, sdk.SessionNotification{SessionId: sid, Update: sdk.UpdateAgentMessageText(text)}) | |
| 697 | + return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn, Usage: s.usage.totals()} | |
| 698 | +} | |
| @@ -362,6 +362,9 @@ func (f *front) Prompt(ctx context.Context, p sdk.PromptRequest) (sdk.PromptResp | |||
| 362 | // after slashCommand, so a real command always wins whatever a skill is | 362 | // after slashCommand, so a real command always wins whatever a skill is |
| 363 | // called. | 363 | // called. |
| 364 | input = skillCommand(input) | 364 | input = skillCommand(input) |
| 365 | + // /redirect <message> (ticket 267): a turn like any other, its question | ||
| 366 | + // framed as a correction of the task the history holds. | ||
| 367 | + input = redirectCommand(input) | ||
| 365 | 368 | ||
| 366 | // One cancellable context per turn: session/cancel fires s.cancel, the | 369 | // One cancellable context per turn: session/cancel fires s.cancel, the |
| 367 | // generation and any pending permission request fall with it, and the spec's | 370 | // generation and any pending permission request fall with it, and the spec's |
| @@ -483,6 +486,8 @@ func (f *front) slashCommand(ctx context.Context, sid sdk.SessionId, s *session, | |||
| 483 | return f.searchMemory(ctx, sid, s, arg), true | 486 | return f.searchMemory(ctx, sid, s, arg), true |
| 484 | case ok && cmd.Name == command.Docs: | 487 | case ok && cmd.Name == command.Docs: |
| 485 | return f.searchDocs(ctx, sid, s, arg), true | 488 | return f.searchDocs(ctx, sid, s, arg), true |
| 489 | + case ok && cmd.Name == command.Redirect && arg == "": | ||
| 490 | + return f.say(ctx, sid, s, redirectNeedsMessage), true | ||
| 486 | } | 491 | } |
| 487 | return sdk.PromptResponse{}, false | 492 | return sdk.PromptResponse{}, false |
| 488 | } | 493 | } |
| @@ -667,3 +672,27 @@ func (f *front) CloseSession(context.Context, sdk.CloseSessionRequest) (sdk.Clos | |||
| 667 | func (f *front) Logout(context.Context, sdk.LogoutRequest) (sdk.LogoutResponse, error) { | 672 | func (f *front) Logout(context.Context, sdk.LogoutRequest) (sdk.LogoutResponse, error) { |
| 668 | return sdk.LogoutResponse{}, sdk.NewMethodNotFound(sdk.AgentMethodLogout) | 673 | return sdk.LogoutResponse{}, sdk.NewMethodNotFound(sdk.AgentMethodLogout) |
| 669 | } | 674 | } |
| 675 | + | ||
| 676 | +// redirectNeedsMessage is the answer to a bare /redirect. | ||
| 677 | +const redirectNeedsMessage = "/redirect needs a message: /redirect <what to change in the task in progress> — send it with Send Now (double Enter) to stop the turn first." | ||
| 678 | + | ||
| 679 | +// redirectCommand turns "/redirect <message>" into the framed question the | ||
| 680 | +// model reads (engine.Redirect); any other input is returned unchanged. | ||
| 681 | +// Sent with Zed's "Send Now", it follows a cancelled turn whose work the | ||
| 682 | +// history kept (session.AfterTurn), so the model continues that task. | ||
| 683 | +// | ||
| 684 | +// redirectCommand("/redirect use the v2 API") | ||
| 685 | +// // "[the user redirects the task in progress] use the v2 API\n\nContinue the task …" | ||
| 686 | +func redirectCommand(input string) string { | ||
| 687 | + cmd, arg, ok := command.Parse(input) | ||
| 688 | + if !ok || cmd.Name != command.Redirect || arg == "" { | ||
| 689 | + return input | ||
| 690 | + } | ||
| 691 | + return engine.Redirect(arg) | ||
| 692 | +} | ||
| 693 | + | ||
| 694 | +// say answers a prompt with one agent message, without a turn. | ||
| 695 | +func (f *front) say(ctx context.Context, sid sdk.SessionId, s *session, text string) sdk.PromptResponse { | ||
| 696 | + _ = f.conn.SessionUpdate(ctx, sdk.SessionNotification{SessionId: sid, Update: sdk.UpdateAgentMessageText(text)}) | ||
| 697 | + return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn, Usage: s.usage.totals()} | ||
| 698 | +} | ||
modified
internal/acp/acp_test.go +5 -4 | @@ -68,7 +68,7 @@ func TestToolKindDefaultsToExecute(t *testing.T) { | ||
| 68 | 68 | // is "what this front end handles". That half is pinned in skillcmd_test.go; |
| 69 | 69 | // this test keeps the command half honest. |
| 70 | 70 | func TestAvailableCommandsMatchWhatPromptIntercepts(t *testing.T) { |
| 71 | - want := []string{"compact", history.NewCommandName} // the shared table's display order | |
| 71 | + want := []string{"compact", history.NewCommandName, "redirect"} // the shared table's display order | |
| 72 | 72 | cmds := availableCommands() |
| 73 | 73 | if len(cmds) != len(want) { |
| 74 | 74 | t.Fatalf("availableCommands: %d command(s) with no skills declared, want %d: %+v", len(cmds), len(want), cmds) |
| @@ -80,12 +80,13 @@ func TestAvailableCommandsMatchWhatPromptIntercepts(t *testing.T) { | ||
| 80 | 80 | if c.Description == "" { |
| 81 | 81 | t.Errorf("%q has no description: the editor would show a bare name", c.Name) |
| 82 | 82 | } |
| 83 | - if c.Input != nil { | |
| 84 | - t.Errorf("%q takes no input, but an input spec is advertised", c.Name) | |
| 83 | + // /redirect takes its message: the editor shows where it goes. | |
| 84 | + if (c.Input != nil) != (c.Name == "redirect") { | |
| 85 | + t.Errorf("%q: input spec advertised = %v", c.Name, c.Input != nil) | |
| 85 | 86 | } |
| 86 | 87 | // Each advertised name must be recognised when it comes back as "/name". |
| 87 | 88 | typed := "/" + c.Name |
| 88 | - if !command.Is(typed, command.New) && !command.Is(typed, command.Compact) { | |
| 89 | + if !command.Is(typed, command.New) && !command.Is(typed, command.Compact) && redirectCommand(typed+" x") == typed+" x" { | |
| 89 | 90 | t.Errorf("%q is advertised but session/prompt would hand it to the model", typed) |
| 90 | 91 | } |
| 91 | 92 | } |
| @@ -68,7 +68,7 @@ func TestToolKindDefaultsToExecute(t *testing.T) { | |||
| 68 | // is "what this front end handles". That half is pinned in skillcmd_test.go; | 68 | // is "what this front end handles". That half is pinned in skillcmd_test.go; |
| 69 | // this test keeps the command half honest. | 69 | // this test keeps the command half honest. |
| 70 | func TestAvailableCommandsMatchWhatPromptIntercepts(t *testing.T) { | 70 | func TestAvailableCommandsMatchWhatPromptIntercepts(t *testing.T) { |
| 71 | - want := []string{"compact", history.NewCommandName} // the shared table's display order | 71 | + want := []string{"compact", history.NewCommandName, "redirect"} // the shared table's display order |
| 72 | cmds := availableCommands() | 72 | cmds := availableCommands() |
| 73 | if len(cmds) != len(want) { | 73 | if len(cmds) != len(want) { |
| 74 | t.Fatalf("availableCommands: %d command(s) with no skills declared, want %d: %+v", len(cmds), len(want), cmds) | 74 | t.Fatalf("availableCommands: %d command(s) with no skills declared, want %d: %+v", len(cmds), len(want), cmds) |
| @@ -80,12 +80,13 @@ func TestAvailableCommandsMatchWhatPromptIntercepts(t *testing.T) { | |||
| 80 | if c.Description == "" { | 80 | if c.Description == "" { |
| 81 | t.Errorf("%q has no description: the editor would show a bare name", c.Name) | 81 | t.Errorf("%q has no description: the editor would show a bare name", c.Name) |
| 82 | } | 82 | } |
| 83 | - if c.Input != nil { | 83 | + // /redirect takes its message: the editor shows where it goes. |
| 84 | - t.Errorf("%q takes no input, but an input spec is advertised", c.Name) | 84 | + if (c.Input != nil) != (c.Name == "redirect") { |
| 85 | + t.Errorf("%q: input spec advertised = %v", c.Name, c.Input != nil) | ||
| 85 | } | 86 | } |
| 86 | // Each advertised name must be recognised when it comes back as "/name". | 87 | // Each advertised name must be recognised when it comes back as "/name". |
| 87 | typed := "/" + c.Name | 88 | typed := "/" + c.Name |
| 88 | - if !command.Is(typed, command.New) && !command.Is(typed, command.Compact) { | 89 | + if !command.Is(typed, command.New) && !command.Is(typed, command.Compact) && redirectCommand(typed+" x") == typed+" x" { |
| 89 | t.Errorf("%q is advertised but session/prompt would hand it to the model", typed) | 90 | t.Errorf("%q is advertised but session/prompt would hand it to the model", typed) |
| 90 | } | 91 | } |
| 91 | } | 92 | } |
added
internal/acp/redirect_test.go +55 -0 | new file mode 100644 | ||
| @@ -0,0 +1,55 @@ | ||
| 1 | +package acp | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "strings" | |
| 5 | + "testing" | |
| 6 | + | |
| 7 | + "mm/internal/engine" | |
| 8 | + | |
| 9 | + sdk "github.com/coder/acp-go-sdk" | |
| 10 | +) | |
| 11 | + | |
| 12 | +// /redirect <message> becomes the framed question the model reads; other | |
| 13 | +// input, and a bare /redirect, are left alone (the bare one is answered by | |
| 14 | +// slashCommand). | |
| 15 | +func TestRedirectCommandFramesTheMessage(t *testing.T) { | |
| 16 | + got := redirectCommand("/redirect use the v2 API ") | |
| 17 | + if got != engine.Redirect("use the v2 API") { | |
| 18 | + t.Errorf("framed = %q", got) | |
| 19 | + } | |
| 20 | + if msg, ok := engine.Unredirect(got); !ok || msg != "use the v2 API" { | |
| 21 | + t.Errorf("Unredirect = %q, %v", msg, ok) | |
| 22 | + } | |
| 23 | + for _, in := range []string{"/redirect", "redirect this", "/compact", "fix the build"} { | |
| 24 | + if out := redirectCommand(in); out != in { | |
| 25 | + t.Errorf("redirectCommand(%q) = %q, want it unchanged", in, out) | |
| 26 | + } | |
| 27 | + } | |
| 28 | +} | |
| 29 | + | |
| 30 | +// A bare /redirect is answered without a turn: the history is untouched. | |
| 31 | +func TestBareRedirectAnswersWithoutATurn(t *testing.T) { | |
| 32 | + w := newWire(t, "sys") | |
| 33 | + f := frontOf(t, w) | |
| 34 | + w.send(1, "session/new", `{"cwd":"`+t.TempDir()+`","mcpServers":[]}`) | |
| 35 | + _, resp := w.until(1) | |
| 36 | + sid := resp["result"].(map[string]any)["sessionId"].(string) | |
| 37 | + | |
| 38 | + w.send(2, "session/prompt", `{"sessionId":"`+sid+`","prompt":[{"type":"text","text":"/redirect"}]}`) | |
| 39 | + notes, resp := w.until(2) | |
| 40 | + if stop := resp["result"].(map[string]any)["stopReason"]; stop != "end_turn" { | |
| 41 | + t.Errorf("stopReason = %v", stop) | |
| 42 | + } | |
| 43 | + var text strings.Builder | |
| 44 | + for _, n := range notes { | |
| 45 | + if n["sessionUpdate"] == "agent_message_chunk" { | |
| 46 | + text.WriteString(n["content"].(map[string]any)["text"].(string)) | |
| 47 | + } | |
| 48 | + } | |
| 49 | + if !strings.HasPrefix(text.String(), "/redirect needs a message") || !strings.Contains(text.String(), "Send Now") { | |
| 50 | + t.Errorf("agent text = %q", text.String()) | |
| 51 | + } | |
| 52 | + if msgs := f.sessions[sdk.SessionId(sid)].messages; len(msgs) != 1 { | |
| 53 | + t.Errorf("history: %d messages, want the system prompt alone", len(msgs)) | |
| 54 | + } | |
| 55 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | +package acp | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "strings" | ||
| 5 | + "testing" | ||
| 6 | + | ||
| 7 | + "mm/internal/engine" | ||
| 8 | + | ||
| 9 | + sdk "github.com/coder/acp-go-sdk" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// /redirect <message> becomes the framed question the model reads; other | ||
| 13 | +// input, and a bare /redirect, are left alone (the bare one is answered by | ||
| 14 | +// slashCommand). | ||
| 15 | +func TestRedirectCommandFramesTheMessage(t *testing.T) { | ||
| 16 | + got := redirectCommand("/redirect use the v2 API ") | ||
| 17 | + if got != engine.Redirect("use the v2 API") { | ||
| 18 | + t.Errorf("framed = %q", got) | ||
| 19 | + } | ||
| 20 | + if msg, ok := engine.Unredirect(got); !ok || msg != "use the v2 API" { | ||
| 21 | + t.Errorf("Unredirect = %q, %v", msg, ok) | ||
| 22 | + } | ||
| 23 | + for _, in := range []string{"/redirect", "redirect this", "/compact", "fix the build"} { | ||
| 24 | + if out := redirectCommand(in); out != in { | ||
| 25 | + t.Errorf("redirectCommand(%q) = %q, want it unchanged", in, out) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +// A bare /redirect is answered without a turn: the history is untouched. | ||
| 31 | +func TestBareRedirectAnswersWithoutATurn(t *testing.T) { | ||
| 32 | + w := newWire(t, "sys") | ||
| 33 | + f := frontOf(t, w) | ||
| 34 | + w.send(1, "session/new", `{"cwd":"`+t.TempDir()+`","mcpServers":[]}`) | ||
| 35 | + _, resp := w.until(1) | ||
| 36 | + sid := resp["result"].(map[string]any)["sessionId"].(string) | ||
| 37 | + | ||
| 38 | + w.send(2, "session/prompt", `{"sessionId":"`+sid+`","prompt":[{"type":"text","text":"/redirect"}]}`) | ||
| 39 | + notes, resp := w.until(2) | ||
| 40 | + if stop := resp["result"].(map[string]any)["stopReason"]; stop != "end_turn" { | ||
| 41 | + t.Errorf("stopReason = %v", stop) | ||
| 42 | + } | ||
| 43 | + var text strings.Builder | ||
| 44 | + for _, n := range notes { | ||
| 45 | + if n["sessionUpdate"] == "agent_message_chunk" { | ||
| 46 | + text.WriteString(n["content"].(map[string]any)["text"].(string)) | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + if !strings.HasPrefix(text.String(), "/redirect needs a message") || !strings.Contains(text.String(), "Send Now") { | ||
| 50 | + t.Errorf("agent text = %q", text.String()) | ||
| 51 | + } | ||
| 52 | + if msgs := f.sessions[sdk.SessionId(sid)].messages; len(msgs) != 1 { | ||
| 53 | + t.Errorf("history: %d messages, want the system prompt alone", len(msgs)) | ||
| 54 | + } | ||
| 55 | +} | ||
modified
internal/acp/skillcmd_test.go +5 -4 | @@ -30,14 +30,15 @@ func TestSkillsAreAdvertisedAsCommands(t *testing.T) { | ||
| 30 | 30 | byName[c.Name] = i |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - // The real commands come first and keep their shape: no input spec. | |
| 33 | + // The real commands come first and keep their shape: an input spec | |
| 34 | + // only for a command that names its argument (/redirect <message>). | |
| 34 | 35 | for _, c := range command.For(command.Editor) { |
| 35 | 36 | i, ok := byName[c.Name] |
| 36 | 37 | if !ok { |
| 37 | 38 | t.Fatalf("%q is no longer advertised", c.Name) |
| 38 | 39 | } |
| 39 | - if cmds[i].Input != nil { | |
| 40 | - t.Errorf("%q takes no input but advertises one", c.Name) | |
| 40 | + if (cmds[i].Input != nil) != (c.Hint != "") { | |
| 41 | + t.Errorf("%q: input spec %v, hint %q", c.Name, cmds[i].Input != nil, c.Hint) | |
| 41 | 42 | } |
| 42 | 43 | delete(byName, c.Name) |
| 43 | 44 | } |
| @@ -70,7 +71,7 @@ func TestASkillNamedLikeACommandIsNotAdvertised(t *testing.T) { | ||
| 70 | 71 | |
| 71 | 72 | var skillish []string |
| 72 | 73 | for _, c := range availableCommands() { |
| 73 | - if c.Input != nil { | |
| 74 | + if c.Input != nil && !commandNamed(c.Name) { | |
| 74 | 75 | skillish = append(skillish, c.Name) |
| 75 | 76 | } |
| 76 | 77 | } |
| @@ -30,14 +30,15 @@ func TestSkillsAreAdvertisedAsCommands(t *testing.T) { | |||
| 30 | byName[c.Name] = i | 30 | byName[c.Name] = i |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | - // The real commands come first and keep their shape: no input spec. | 33 | + // The real commands come first and keep their shape: an input spec |
| 34 | + // only for a command that names its argument (/redirect <message>). | ||
| 34 | for _, c := range command.For(command.Editor) { | 35 | for _, c := range command.For(command.Editor) { |
| 35 | i, ok := byName[c.Name] | 36 | i, ok := byName[c.Name] |
| 36 | if !ok { | 37 | if !ok { |
| 37 | t.Fatalf("%q is no longer advertised", c.Name) | 38 | t.Fatalf("%q is no longer advertised", c.Name) |
| 38 | } | 39 | } |
| 39 | - if cmds[i].Input != nil { | 40 | + if (cmds[i].Input != nil) != (c.Hint != "") { |
| 40 | - t.Errorf("%q takes no input but advertises one", c.Name) | 41 | + t.Errorf("%q: input spec %v, hint %q", c.Name, cmds[i].Input != nil, c.Hint) |
| 41 | } | 42 | } |
| 42 | delete(byName, c.Name) | 43 | delete(byName, c.Name) |
| 43 | } | 44 | } |
| @@ -70,7 +71,7 @@ func TestASkillNamedLikeACommandIsNotAdvertised(t *testing.T) { | |||
| 70 | 71 | ||
| 71 | var skillish []string | 72 | var skillish []string |
| 72 | for _, c := range availableCommands() { | 73 | for _, c := range availableCommands() { |
| 73 | - if c.Input != nil { | 74 | + if c.Input != nil && !commandNamed(c.Name) { |
| 74 | skillish = append(skillish, c.Name) | 75 | skillish = append(skillish, c.Name) |
| 75 | } | 76 | } |
| 76 | } | 77 | } |
modified
internal/agent/agent.go +34 -4 | @@ -134,6 +134,14 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | ||
| 134 | 134 | fmt.Println("⚠️ No generation in progress.") |
| 135 | 135 | continue |
| 136 | 136 | } |
| 137 | + // /queue between two turns: nothing to wait for, the question runs. | |
| 138 | + if q, isQueue := queueArg(input); isQueue { | |
| 139 | + if q == "" { | |
| 140 | + fmt.Println(queueNeedsQuestion) | |
| 141 | + continue | |
| 142 | + } | |
| 143 | + input = q | |
| 144 | + } | |
| 137 | 145 | // The commands that move the history — /compact, /new, /sessions, |
| 138 | 146 | // /resume — are only reachable here, between two generations: Genkit |
| 139 | 147 | // holds its own copy of the conversation while it runs, and a |
| @@ -231,10 +239,14 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | ||
| 231 | 239 | // Hooks that ran outside a turn (an /ask) are not this turn's. |
| 232 | 240 | hooks.Turn.Take() |
| 233 | 241 | |
| 242 | + // A question typed during the turn steers it (ticket 265). | |
| 243 | + steer := newTurnSteer(cwd) | |
| 244 | + steerCtx := steer.context(genCtx) | |
| 245 | + | |
| 234 | 246 | // Launch generation in a goroutine. |
| 235 | 247 | resultCh := make(chan genResult, 1) |
| 236 | 248 | go func() { |
| 237 | - resp, history, err := e.Generate(genCtx, messages, tools) | |
| 249 | + resp, history, err := e.Generate(steerCtx, messages, tools) | |
| 238 | 250 | resultCh <- genResult{resp: resp, history: history, err: err} |
| 239 | 251 | }() |
| 240 | 252 | |
| @@ -320,6 +332,11 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | ||
| 320 | 332 | printCommands(ops) |
| 321 | 333 | } |
| 322 | 334 | printHookRuns(os.Stdout) |
| 335 | + // Questions sent after the model's last call run next. | |
| 336 | + if late := steer.late(); len(late) > 0 { | |
| 337 | + queue.pushFront(late) | |
| 338 | + fmt.Printf("⏳ %d message(s) came after the model's last call — sent as the next question\n", len(late)) | |
| 339 | + } | |
| 323 | 340 | |
| 324 | 341 | case <-sigCh: |
| 325 | 342 | // Handle Ctrl+C during generation. |
| @@ -358,9 +375,22 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | ||
| 358 | 375 | fmt.Println("Goodbye.") |
| 359 | 376 | return |
| 360 | 377 | default: |
| 361 | - // Ticket 155: a new message no longer cancels the turn — | |
| 362 | - // the answer being written is often the one it builds on. | |
| 363 | - // It waits in the queue and runs once the turn has settled. | |
| 378 | + // Ticket 265: a question steers the turn — the model reads | |
| 379 | + // it after its current step. A slash command, and | |
| 380 | + // `/queue <question>`, wait in the queue and run once the | |
| 381 | + // turn has settled (ticket 155). | |
| 382 | + if q, isQueue := queueArg(nextInput); isQueue { | |
| 383 | + if q == "" { | |
| 384 | + spinner.Stop() | |
| 385 | + fmt.Println("\n" + queueNeedsQuestion) | |
| 386 | + continue | |
| 387 | + } | |
| 388 | + nextInput = q | |
| 389 | + } else if notice, steered := steer.offer(nextInput); steered { | |
| 390 | + spinner.Stop() | |
| 391 | + fmt.Println("\n" + notice) | |
| 392 | + continue | |
| 393 | + } | |
| 364 | 394 | if notice := queue.push(nextInput); notice != "" { |
| 365 | 395 | spinner.Stop() |
| 366 | 396 | fmt.Println("\n" + notice) |
| @@ -134,6 +134,14 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | |||
| 134 | fmt.Println("⚠️ No generation in progress.") | 134 | fmt.Println("⚠️ No generation in progress.") |
| 135 | continue | 135 | continue |
| 136 | } | 136 | } |
| 137 | + // /queue between two turns: nothing to wait for, the question runs. | ||
| 138 | + if q, isQueue := queueArg(input); isQueue { | ||
| 139 | + if q == "" { | ||
| 140 | + fmt.Println(queueNeedsQuestion) | ||
| 141 | + continue | ||
| 142 | + } | ||
| 143 | + input = q | ||
| 144 | + } | ||
| 137 | // The commands that move the history — /compact, /new, /sessions, | 145 | // The commands that move the history — /compact, /new, /sessions, |
| 138 | // /resume — are only reachable here, between two generations: Genkit | 146 | // /resume — are only reachable here, between two generations: Genkit |
| 139 | // holds its own copy of the conversation while it runs, and a | 147 | // holds its own copy of the conversation while it runs, and a |
| @@ -231,10 +239,14 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | |||
| 231 | // Hooks that ran outside a turn (an /ask) are not this turn's. | 239 | // Hooks that ran outside a turn (an /ask) are not this turn's. |
| 232 | hooks.Turn.Take() | 240 | hooks.Turn.Take() |
| 233 | 241 | ||
| 242 | + // A question typed during the turn steers it (ticket 265). | ||
| 243 | + steer := newTurnSteer(cwd) | ||
| 244 | + steerCtx := steer.context(genCtx) | ||
| 245 | + | ||
| 234 | // Launch generation in a goroutine. | 246 | // Launch generation in a goroutine. |
| 235 | resultCh := make(chan genResult, 1) | 247 | resultCh := make(chan genResult, 1) |
| 236 | go func() { | 248 | go func() { |
| 237 | - resp, history, err := e.Generate(genCtx, messages, tools) | 249 | + resp, history, err := e.Generate(steerCtx, messages, tools) |
| 238 | resultCh <- genResult{resp: resp, history: history, err: err} | 250 | resultCh <- genResult{resp: resp, history: history, err: err} |
| 239 | }() | 251 | }() |
| 240 | 252 | ||
| @@ -320,6 +332,11 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | |||
| 320 | printCommands(ops) | 332 | printCommands(ops) |
| 321 | } | 333 | } |
| 322 | printHookRuns(os.Stdout) | 334 | printHookRuns(os.Stdout) |
| 335 | + // Questions sent after the model's last call run next. | ||
| 336 | + if late := steer.late(); len(late) > 0 { | ||
| 337 | + queue.pushFront(late) | ||
| 338 | + fmt.Printf("⏳ %d message(s) came after the model's last call — sent as the next question\n", len(late)) | ||
| 339 | + } | ||
| 323 | 340 | ||
| 324 | case <-sigCh: | 341 | case <-sigCh: |
| 325 | // Handle Ctrl+C during generation. | 342 | // Handle Ctrl+C during generation. |
| @@ -358,9 +375,22 @@ func Run(ctx context.Context, e *engine.Engine, system string, tools []ai.ToolRe | |||
| 358 | fmt.Println("Goodbye.") | 375 | fmt.Println("Goodbye.") |
| 359 | return | 376 | return |
| 360 | default: | 377 | default: |
| 361 | - // Ticket 155: a new message no longer cancels the turn — | 378 | + // Ticket 265: a question steers the turn — the model reads |
| 362 | - // the answer being written is often the one it builds on. | 379 | + // it after its current step. A slash command, and |
| 363 | - // It waits in the queue and runs once the turn has settled. | 380 | + // `/queue <question>`, wait in the queue and run once the |
| 381 | + // turn has settled (ticket 155). | ||
| 382 | + if q, isQueue := queueArg(nextInput); isQueue { | ||
| 383 | + if q == "" { | ||
| 384 | + spinner.Stop() | ||
| 385 | + fmt.Println("\n" + queueNeedsQuestion) | ||
| 386 | + continue | ||
| 387 | + } | ||
| 388 | + nextInput = q | ||
| 389 | + } else if notice, steered := steer.offer(nextInput); steered { | ||
| 390 | + spinner.Stop() | ||
| 391 | + fmt.Println("\n" + notice) | ||
| 392 | + continue | ||
| 393 | + } | ||
| 364 | if notice := queue.push(nextInput); notice != "" { | 394 | if notice := queue.push(nextInput); notice != "" { |
| 365 | spinner.Stop() | 395 | spinner.Stop() |
| 366 | fmt.Println("\n" + notice) | 396 | fmt.Println("\n" + notice) |
modified
internal/agent/queue.go +7 -0 | @@ -27,6 +27,13 @@ func (q *inbox) push(line string) string { | ||
| 27 | 27 | return fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · /abort or Ctrl+C stops the turn", len(q.lines)) |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | +// pushFront puts lines back at the head of the queue, in their order: the | |
| 31 | +// questions a turn was steered with but never took (ticket 265) run before | |
| 32 | +// what was queued after them. | |
| 33 | +func (q *inbox) pushFront(lines []string) { | |
| 34 | + q.lines = append(append([]string(nil), lines...), q.lines...) | |
| 35 | +} | |
| 36 | + | |
| 30 | 37 | // pop takes the oldest queued line; false when nothing waits. |
| 31 | 38 | func (q *inbox) pop() (string, bool) { |
| 32 | 39 | if len(q.lines) == 0 { |
| @@ -27,6 +27,13 @@ func (q *inbox) push(line string) string { | |||
| 27 | return fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · /abort or Ctrl+C stops the turn", len(q.lines)) | 27 | return fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · /abort or Ctrl+C stops the turn", len(q.lines)) |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | +// pushFront puts lines back at the head of the queue, in their order: the | ||
| 31 | +// questions a turn was steered with but never took (ticket 265) run before | ||
| 32 | +// what was queued after them. | ||
| 33 | +func (q *inbox) pushFront(lines []string) { | ||
| 34 | + q.lines = append(append([]string(nil), lines...), q.lines...) | ||
| 35 | +} | ||
| 36 | + | ||
| 30 | // pop takes the oldest queued line; false when nothing waits. | 37 | // pop takes the oldest queued line; false when nothing waits. |
| 31 | func (q *inbox) pop() (string, bool) { | 38 | func (q *inbox) pop() (string, bool) { |
| 32 | if len(q.lines) == 0 { | 39 | if len(q.lines) == 0 { |
added
internal/agent/steer.go +94 -0 | new file mode 100644 | ||
| @@ -0,0 +1,94 @@ | ||
| 1 | +package agent | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "context" | |
| 5 | + "strings" | |
| 6 | + | |
| 7 | + "mm/internal/command" | |
| 8 | + "mm/internal/engine" | |
| 9 | + "mm/internal/mention" | |
| 10 | + "mm/internal/skills" | |
| 11 | + "mm/internal/spinner" | |
| 12 | +) | |
| 13 | + | |
| 14 | +// turnSteer is the line mode's side of ticket 265: a question typed during | |
| 15 | +// a turn goes to the turn's inbox (engine.Inbox) and the model reads it | |
| 16 | +// after its current step; a slash command — and `/queue <question>` — waits | |
| 17 | +// in the queue as before (ticket 155). One per turn. | |
| 18 | +// | |
| 19 | +// st := newTurnSteer(cwd) | |
| 20 | +// go e.Generate(st.context(genCtx), messages, tools) | |
| 21 | +// // a line typed meanwhile: | |
| 22 | +// if notice, ok := st.offer(line); ok { fmt.Println(notice) } else { queue.push(line) } | |
| 23 | +// // the turn has ended: | |
| 24 | +// queue.pushFront(st.late()) | |
| 25 | +type turnSteer struct { | |
| 26 | + box *engine.Inbox | |
| 27 | + typed []string // the lines pushed, as typed, oldest first | |
| 28 | + cwd string | |
| 29 | +} | |
| 30 | + | |
| 31 | +// steeringNotice is printed when a line is handed to the turn. | |
| 32 | +const steeringNotice = "↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn" | |
| 33 | + | |
| 34 | +func newTurnSteer(cwd string) *turnSteer { | |
| 35 | + return &turnSteer{cwd: cwd, box: engine.NewInbox(func(text string) { | |
| 36 | + spinner.Stop() // the spinner owns the line while the turn runs | |
| 37 | + dimln("↪ Steered: " + firstLine(text)) | |
| 38 | + })} | |
| 39 | +} | |
| 40 | + | |
| 41 | +// context is ctx carrying the turn's inbox. | |
| 42 | +func (s *turnSteer) context(ctx context.Context) context.Context { | |
| 43 | + return engine.WithSteer(ctx, s.box) | |
| 44 | +} | |
| 45 | + | |
| 46 | +// offer hands line to the turn and returns the notice to print. false: not | |
| 47 | +// a question (blank, a slash command), or the turn takes no more — the | |
| 48 | +// caller queues it. | |
| 49 | +func (s *turnSteer) offer(line string) (string, bool) { | |
| 50 | + trimmed := strings.TrimSpace(line) | |
| 51 | + if trimmed == "" || strings.HasPrefix(trimmed, "/") { | |
| 52 | + return "", false | |
| 53 | + } | |
| 54 | + // @path and $skill mean what they mean in a question. | |
| 55 | + expanded, _ := mention.Expand(line, s.cwd) | |
| 56 | + expanded, _ = skills.ExpandRefs(expanded, skills.Declared()) | |
| 57 | + if !s.box.Push(expanded) { | |
| 58 | + return "", false | |
| 59 | + } | |
| 60 | + s.typed = append(s.typed, line) | |
| 61 | + return steeringNotice, true | |
| 62 | +} | |
| 63 | + | |
| 64 | +// late closes the inbox and returns, as typed, the lines the model never | |
| 65 | +// got — sent after its last call — to run as the next questions. | |
| 66 | +func (s *turnSteer) late() []string { | |
| 67 | + n := len(s.box.Close()) | |
| 68 | + if n == 0 || n > len(s.typed) { | |
| 69 | + return nil | |
| 70 | + } | |
| 71 | + return s.typed[len(s.typed)-n:] | |
| 72 | +} | |
| 73 | + | |
| 74 | +// queueArg reports whether line is `/queue …` and returns its question | |
| 75 | +// ("" when none was given). | |
| 76 | +func queueArg(line string) (string, bool) { | |
| 77 | + cmd, arg, ok := command.Parse(line) | |
| 78 | + if !ok || cmd.Name != command.Queue { | |
| 79 | + return "", false | |
| 80 | + } | |
| 81 | + return arg, true | |
| 82 | +} | |
| 83 | + | |
| 84 | +// queueNeedsQuestion is what a bare /queue prints. | |
| 85 | +const queueNeedsQuestion = "⚠️ /queue needs a question: /queue <question>" | |
| 86 | + | |
| 87 | +// firstLine is text's first line, with "…" when there is more. | |
| 88 | +func firstLine(text string) string { | |
| 89 | + line, rest, _ := strings.Cut(strings.TrimSpace(text), "\n") | |
| 90 | + if rest != "" { | |
| 91 | + return line + " …" | |
| 92 | + } | |
| 93 | + return line | |
| 94 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | +package agent | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "strings" | ||
| 6 | + | ||
| 7 | + "mm/internal/command" | ||
| 8 | + "mm/internal/engine" | ||
| 9 | + "mm/internal/mention" | ||
| 10 | + "mm/internal/skills" | ||
| 11 | + "mm/internal/spinner" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +// turnSteer is the line mode's side of ticket 265: a question typed during | ||
| 15 | +// a turn goes to the turn's inbox (engine.Inbox) and the model reads it | ||
| 16 | +// after its current step; a slash command — and `/queue <question>` — waits | ||
| 17 | +// in the queue as before (ticket 155). One per turn. | ||
| 18 | +// | ||
| 19 | +// st := newTurnSteer(cwd) | ||
| 20 | +// go e.Generate(st.context(genCtx), messages, tools) | ||
| 21 | +// // a line typed meanwhile: | ||
| 22 | +// if notice, ok := st.offer(line); ok { fmt.Println(notice) } else { queue.push(line) } | ||
| 23 | +// // the turn has ended: | ||
| 24 | +// queue.pushFront(st.late()) | ||
| 25 | +type turnSteer struct { | ||
| 26 | + box *engine.Inbox | ||
| 27 | + typed []string // the lines pushed, as typed, oldest first | ||
| 28 | + cwd string | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +// steeringNotice is printed when a line is handed to the turn. | ||
| 32 | +const steeringNotice = "↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn" | ||
| 33 | + | ||
| 34 | +func newTurnSteer(cwd string) *turnSteer { | ||
| 35 | + return &turnSteer{cwd: cwd, box: engine.NewInbox(func(text string) { | ||
| 36 | + spinner.Stop() // the spinner owns the line while the turn runs | ||
| 37 | + dimln("↪ Steered: " + firstLine(text)) | ||
| 38 | + })} | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +// context is ctx carrying the turn's inbox. | ||
| 42 | +func (s *turnSteer) context(ctx context.Context) context.Context { | ||
| 43 | + return engine.WithSteer(ctx, s.box) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// offer hands line to the turn and returns the notice to print. false: not | ||
| 47 | +// a question (blank, a slash command), or the turn takes no more — the | ||
| 48 | +// caller queues it. | ||
| 49 | +func (s *turnSteer) offer(line string) (string, bool) { | ||
| 50 | + trimmed := strings.TrimSpace(line) | ||
| 51 | + if trimmed == "" || strings.HasPrefix(trimmed, "/") { | ||
| 52 | + return "", false | ||
| 53 | + } | ||
| 54 | + // @path and $skill mean what they mean in a question. | ||
| 55 | + expanded, _ := mention.Expand(line, s.cwd) | ||
| 56 | + expanded, _ = skills.ExpandRefs(expanded, skills.Declared()) | ||
| 57 | + if !s.box.Push(expanded) { | ||
| 58 | + return "", false | ||
| 59 | + } | ||
| 60 | + s.typed = append(s.typed, line) | ||
| 61 | + return steeringNotice, true | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +// late closes the inbox and returns, as typed, the lines the model never | ||
| 65 | +// got — sent after its last call — to run as the next questions. | ||
| 66 | +func (s *turnSteer) late() []string { | ||
| 67 | + n := len(s.box.Close()) | ||
| 68 | + if n == 0 || n > len(s.typed) { | ||
| 69 | + return nil | ||
| 70 | + } | ||
| 71 | + return s.typed[len(s.typed)-n:] | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +// queueArg reports whether line is `/queue …` and returns its question | ||
| 75 | +// ("" when none was given). | ||
| 76 | +func queueArg(line string) (string, bool) { | ||
| 77 | + cmd, arg, ok := command.Parse(line) | ||
| 78 | + if !ok || cmd.Name != command.Queue { | ||
| 79 | + return "", false | ||
| 80 | + } | ||
| 81 | + return arg, true | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +// queueNeedsQuestion is what a bare /queue prints. | ||
| 85 | +const queueNeedsQuestion = "⚠️ /queue needs a question: /queue <question>" | ||
| 86 | + | ||
| 87 | +// firstLine is text's first line, with "…" when there is more. | ||
| 88 | +func firstLine(text string) string { | ||
| 89 | + line, rest, _ := strings.Cut(strings.TrimSpace(text), "\n") | ||
| 90 | + if rest != "" { | ||
| 91 | + return line + " …" | ||
| 92 | + } | ||
| 93 | + return line | ||
| 94 | +} | ||
added
internal/agent/steer_test.go +68 -0 | new file mode 100644 | ||
| @@ -0,0 +1,68 @@ | ||
| 1 | +package agent | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "reflect" | |
| 5 | + "testing" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// A question typed during a turn is handed to the turn; a slash command and | |
| 9 | +// a blank line are not (the queue takes the command, drops the blank). | |
| 10 | +func TestTurnSteerTakesQuestionsOnly(t *testing.T) { | |
| 11 | + st := newTurnSteer(t.TempDir()) | |
| 12 | + if n, ok := st.offer("use the v2 API"); !ok || n != steeringNotice { | |
| 13 | + t.Errorf("question: %q, %v", n, ok) | |
| 14 | + } | |
| 15 | + for _, line := range []string{"/compact", " /queue later", " "} { | |
| 16 | + if _, ok := st.offer(line); ok { | |
| 17 | + t.Errorf("%q was steered", line) | |
| 18 | + } | |
| 19 | + } | |
| 20 | +} | |
| 21 | + | |
| 22 | +// The lines the model never got come back as typed, oldest first; after | |
| 23 | +// the turn, nothing is steered any more. | |
| 24 | +func TestTurnSteerHandsBackLateLines(t *testing.T) { | |
| 25 | + st := newTurnSteer(t.TempDir()) | |
| 26 | + st.offer("one") | |
| 27 | + st.offer("two") | |
| 28 | + if late := st.late(); !reflect.DeepEqual(late, []string{"one", "two"}) { | |
| 29 | + t.Errorf("late = %q", late) | |
| 30 | + } | |
| 31 | + if _, ok := st.offer("three"); ok { | |
| 32 | + t.Error("steered after the turn ended") | |
| 33 | + } | |
| 34 | + if late := st.late(); late != nil { | |
| 35 | + t.Errorf("second late = %q", late) | |
| 36 | + } | |
| 37 | +} | |
| 38 | + | |
| 39 | +func TestQueueArg(t *testing.T) { | |
| 40 | + cases := map[string]struct { | |
| 41 | + q string | |
| 42 | + ok bool | |
| 43 | + }{ | |
| 44 | + "/queue and the tests": {"and the tests", true}, | |
| 45 | + "/queue": {"", true}, | |
| 46 | + "/compact": {"", false}, | |
| 47 | + "queue this": {"", false}, | |
| 48 | + } | |
| 49 | + for line, want := range cases { | |
| 50 | + if q, ok := queueArg(line); q != want.q || ok != want.ok { | |
| 51 | + t.Errorf("queueArg(%q) = %q, %v", line, q, ok) | |
| 52 | + } | |
| 53 | + } | |
| 54 | +} | |
| 55 | + | |
| 56 | +// Late steers run before what was queued after them. | |
| 57 | +func TestInboxPushFront(t *testing.T) { | |
| 58 | + var q inbox | |
| 59 | + q.push("/compact") | |
| 60 | + q.pushFront([]string{"one", "two"}) | |
| 61 | + var got []string | |
| 62 | + for line, ok := q.pop(); ok; line, ok = q.pop() { | |
| 63 | + got = append(got, line) | |
| 64 | + } | |
| 65 | + if !reflect.DeepEqual(got, []string{"one", "two", "/compact"}) { | |
| 66 | + t.Errorf("order = %q", got) | |
| 67 | + } | |
| 68 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | +package agent | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "reflect" | ||
| 5 | + "testing" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +// A question typed during a turn is handed to the turn; a slash command and | ||
| 9 | +// a blank line are not (the queue takes the command, drops the blank). | ||
| 10 | +func TestTurnSteerTakesQuestionsOnly(t *testing.T) { | ||
| 11 | + st := newTurnSteer(t.TempDir()) | ||
| 12 | + if n, ok := st.offer("use the v2 API"); !ok || n != steeringNotice { | ||
| 13 | + t.Errorf("question: %q, %v", n, ok) | ||
| 14 | + } | ||
| 15 | + for _, line := range []string{"/compact", " /queue later", " "} { | ||
| 16 | + if _, ok := st.offer(line); ok { | ||
| 17 | + t.Errorf("%q was steered", line) | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +// The lines the model never got come back as typed, oldest first; after | ||
| 23 | +// the turn, nothing is steered any more. | ||
| 24 | +func TestTurnSteerHandsBackLateLines(t *testing.T) { | ||
| 25 | + st := newTurnSteer(t.TempDir()) | ||
| 26 | + st.offer("one") | ||
| 27 | + st.offer("two") | ||
| 28 | + if late := st.late(); !reflect.DeepEqual(late, []string{"one", "two"}) { | ||
| 29 | + t.Errorf("late = %q", late) | ||
| 30 | + } | ||
| 31 | + if _, ok := st.offer("three"); ok { | ||
| 32 | + t.Error("steered after the turn ended") | ||
| 33 | + } | ||
| 34 | + if late := st.late(); late != nil { | ||
| 35 | + t.Errorf("second late = %q", late) | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func TestQueueArg(t *testing.T) { | ||
| 40 | + cases := map[string]struct { | ||
| 41 | + q string | ||
| 42 | + ok bool | ||
| 43 | + }{ | ||
| 44 | + "/queue and the tests": {"and the tests", true}, | ||
| 45 | + "/queue": {"", true}, | ||
| 46 | + "/compact": {"", false}, | ||
| 47 | + "queue this": {"", false}, | ||
| 48 | + } | ||
| 49 | + for line, want := range cases { | ||
| 50 | + if q, ok := queueArg(line); q != want.q || ok != want.ok { | ||
| 51 | + t.Errorf("queueArg(%q) = %q, %v", line, q, ok) | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// Late steers run before what was queued after them. | ||
| 57 | +func TestInboxPushFront(t *testing.T) { | ||
| 58 | + var q inbox | ||
| 59 | + q.push("/compact") | ||
| 60 | + q.pushFront([]string{"one", "two"}) | ||
| 61 | + var got []string | ||
| 62 | + for line, ok := q.pop(); ok; line, ok = q.pop() { | ||
| 63 | + got = append(got, line) | ||
| 64 | + } | ||
| 65 | + if !reflect.DeepEqual(got, []string{"one", "two", "/compact"}) { | ||
| 66 | + t.Errorf("order = %q", got) | ||
| 67 | + } | ||
| 68 | +} | ||
modified
internal/command/command.go +10 -0 | @@ -45,6 +45,8 @@ const ( | ||
| 45 | 45 | Memory = "memory" |
| 46 | 46 | Docs = "docs" |
| 47 | 47 | Shell = "shell" |
| 48 | + Queue = "queue" | |
| 49 | + Redirect = "redirect" | |
| 48 | 50 | ) |
| 49 | 51 | |
| 50 | 52 | // Command is one slash command: what it is called, what it does, who offers |
| @@ -81,6 +83,14 @@ var table = []Command{ | ||
| 81 | 83 | // Window only: the window owns the whole terminal, /shell hands it back |
| 82 | 84 | // for a while (ticket 122). |
| 83 | 85 | {Name: Shell, Description: "Open your shell in this terminal; exit it to come back to the conversation", Fronts: Window}, |
| 86 | + // Ticket 265: during a turn a question steers it; /queue keeps the | |
| 87 | + // former behaviour — the question waits for the end of the turn. The | |
| 88 | + // editor has no steer (ticket 266), so no /queue either. | |
| 89 | + {Name: Queue, Description: "Run this question once the turn in progress ends (a question sent during a turn steers it instead)", Fronts: Terminal | Window, TakesArg: true, Hint: "<question>"}, | |
| 90 | + // Editor only (ticket 267): the editor cannot steer a turn yet (ticket | |
| 91 | + // 266); sent with Zed's "Send Now", this stops the turn and the model | |
| 92 | + // continues the task with the correction. | |
| 93 | + {Name: Redirect, Description: "Correct the task in progress — send it with Send Now (double Enter) to stop the turn; the model continues the task with your message", Fronts: Editor, TakesArg: true, Hint: "<message>"}, | |
| 84 | 94 | } |
| 85 | 95 | |
| 86 | 96 | // All returns the whole table, in display order: the fixed commands, /unload |
| @@ -45,6 +45,8 @@ const ( | |||
| 45 | Memory = "memory" | 45 | Memory = "memory" |
| 46 | Docs = "docs" | 46 | Docs = "docs" |
| 47 | Shell = "shell" | 47 | Shell = "shell" |
| 48 | + Queue = "queue" | ||
| 49 | + Redirect = "redirect" | ||
| 48 | ) | 50 | ) |
| 49 | 51 | ||
| 50 | // Command is one slash command: what it is called, what it does, who offers | 52 | // Command is one slash command: what it is called, what it does, who offers |
| @@ -81,6 +83,14 @@ var table = []Command{ | |||
| 81 | // Window only: the window owns the whole terminal, /shell hands it back | 83 | // Window only: the window owns the whole terminal, /shell hands it back |
| 82 | // for a while (ticket 122). | 84 | // for a while (ticket 122). |
| 83 | {Name: Shell, Description: "Open your shell in this terminal; exit it to come back to the conversation", Fronts: Window}, | 85 | {Name: Shell, Description: "Open your shell in this terminal; exit it to come back to the conversation", Fronts: Window}, |
| 86 | + // Ticket 265: during a turn a question steers it; /queue keeps the | ||
| 87 | + // former behaviour — the question waits for the end of the turn. The | ||
| 88 | + // editor has no steer (ticket 266), so no /queue either. | ||
| 89 | + {Name: Queue, Description: "Run this question once the turn in progress ends (a question sent during a turn steers it instead)", Fronts: Terminal | Window, TakesArg: true, Hint: "<question>"}, | ||
| 90 | + // Editor only (ticket 267): the editor cannot steer a turn yet (ticket | ||
| 91 | + // 266); sent with Zed's "Send Now", this stops the turn and the model | ||
| 92 | + // continues the task with the correction. | ||
| 93 | + {Name: Redirect, Description: "Correct the task in progress — send it with Send Now (double Enter) to stop the turn; the model continues the task with your message", Fronts: Editor, TakesArg: true, Hint: "<message>"}, | ||
| 84 | } | 94 | } |
| 85 | 95 | ||
| 86 | // All returns the whole table, in display order: the fixed commands, /unload | 96 | // All returns the whole table, in display order: the fixed commands, /unload |
modified
internal/command/command_test.go +12 -10 | @@ -16,19 +16,21 @@ func TestForFiltersByFront(t *testing.T) { | ||
| 16 | 16 | } |
| 17 | 17 | return strings.Join(out, " ") |
| 18 | 18 | } |
| 19 | - if got := names(For(Editor)); got != "compact new" { | |
| 20 | - t.Errorf("Editor commands = %q, want %q", got, "compact new") | |
| 19 | + if got := names(For(Editor)); got != "compact new redirect" { | |
| 20 | + t.Errorf("Editor commands = %q, want %q", got, "compact new redirect") | |
| 21 | 21 | } |
| 22 | 22 | want := "quit abort compact new sessions resume help copy save" |
| 23 | - if got := names(For(Terminal)); got != want { | |
| 24 | - t.Errorf("Terminal commands = %q, want %q", got, want) | |
| 23 | + if got := names(For(Terminal)); got != want+" queue" { | |
| 24 | + t.Errorf("Terminal commands = %q, want %q", got, want+" queue") | |
| 25 | 25 | } |
| 26 | - // /shell is the window's own: it hands back the terminal the window owns. | |
| 27 | - if got := names(For(Window)); got != want+" shell" { | |
| 28 | - t.Errorf("Window commands = %q, want %q", got, want+" shell") | |
| 26 | + // /shell is the window's own: it hands back the terminal the window | |
| 27 | + // owns. /queue waits for the turn a question would steer (ticket 265): | |
| 28 | + // line mode and window, not the editor, which has no steer. | |
| 29 | + if got := names(For(Window)); got != want+" shell queue" { | |
| 30 | + t.Errorf("Window commands = %q, want %q", got, want+" shell queue") | |
| 29 | 31 | } |
| 30 | - if len(All()) != 10 { | |
| 31 | - t.Errorf("All() has %d commands, want 10", len(All())) | |
| 32 | + if len(All()) != 12 { | |
| 33 | + t.Errorf("All() has %d commands, want 12", len(All())) | |
| 32 | 34 | } |
| 33 | 35 | } |
| 34 | 36 | |
| @@ -100,7 +102,7 @@ func TestTableIsSelfConsistent(t *testing.T) { | ||
| 100 | 102 | func TestUsageListsAlignedLines(t *testing.T) { |
| 101 | 103 | text := Usage(Editor) |
| 102 | 104 | lines := strings.Split(text, "\n") |
| 103 | - if len(lines) != 2 || !strings.HasPrefix(lines[0], "/compact") || !strings.HasPrefix(lines[1], "/new") { | |
| 105 | + if len(lines) != 3 || !strings.HasPrefix(lines[0], "/compact") || !strings.HasPrefix(lines[1], "/new") || !strings.HasPrefix(lines[2], "/redirect <message>") { | |
| 104 | 106 | t.Fatalf("Usage(Editor):\n%s", text) |
| 105 | 107 | } |
| 106 | 108 | full := Usage(Terminal) |
| @@ -16,19 +16,21 @@ func TestForFiltersByFront(t *testing.T) { | |||
| 16 | } | 16 | } |
| 17 | return strings.Join(out, " ") | 17 | return strings.Join(out, " ") |
| 18 | } | 18 | } |
| 19 | - if got := names(For(Editor)); got != "compact new" { | 19 | + if got := names(For(Editor)); got != "compact new redirect" { |
| 20 | - t.Errorf("Editor commands = %q, want %q", got, "compact new") | 20 | + t.Errorf("Editor commands = %q, want %q", got, "compact new redirect") |
| 21 | } | 21 | } |
| 22 | want := "quit abort compact new sessions resume help copy save" | 22 | want := "quit abort compact new sessions resume help copy save" |
| 23 | - if got := names(For(Terminal)); got != want { | 23 | + if got := names(For(Terminal)); got != want+" queue" { |
| 24 | - t.Errorf("Terminal commands = %q, want %q", got, want) | 24 | + t.Errorf("Terminal commands = %q, want %q", got, want+" queue") |
| 25 | } | 25 | } |
| 26 | - // /shell is the window's own: it hands back the terminal the window owns. | 26 | + // /shell is the window's own: it hands back the terminal the window |
| 27 | - if got := names(For(Window)); got != want+" shell" { | 27 | + // owns. /queue waits for the turn a question would steer (ticket 265): |
| 28 | - t.Errorf("Window commands = %q, want %q", got, want+" shell") | 28 | + // line mode and window, not the editor, which has no steer. |
| 29 | + if got := names(For(Window)); got != want+" shell queue" { | ||
| 30 | + t.Errorf("Window commands = %q, want %q", got, want+" shell queue") | ||
| 29 | } | 31 | } |
| 30 | - if len(All()) != 10 { | 32 | + if len(All()) != 12 { |
| 31 | - t.Errorf("All() has %d commands, want 10", len(All())) | 33 | + t.Errorf("All() has %d commands, want 12", len(All())) |
| 32 | } | 34 | } |
| 33 | } | 35 | } |
| 34 | 36 | ||
| @@ -100,7 +102,7 @@ func TestTableIsSelfConsistent(t *testing.T) { | |||
| 100 | func TestUsageListsAlignedLines(t *testing.T) { | 102 | func TestUsageListsAlignedLines(t *testing.T) { |
| 101 | text := Usage(Editor) | 103 | text := Usage(Editor) |
| 102 | lines := strings.Split(text, "\n") | 104 | lines := strings.Split(text, "\n") |
| 103 | - if len(lines) != 2 || !strings.HasPrefix(lines[0], "/compact") || !strings.HasPrefix(lines[1], "/new") { | 105 | + if len(lines) != 3 || !strings.HasPrefix(lines[0], "/compact") || !strings.HasPrefix(lines[1], "/new") || !strings.HasPrefix(lines[2], "/redirect <message>") { |
| 104 | t.Fatalf("Usage(Editor):\n%s", text) | 106 | t.Fatalf("Usage(Editor):\n%s", text) |
| 105 | } | 107 | } |
| 106 | full := Usage(Terminal) | 108 | full := Usage(Terminal) |
modified
internal/engine/engine.go +3 -0 | @@ -383,6 +383,9 @@ func (e *Engine) generate(ctx context.Context, messages []*ai.Message, tools []a | ||
| 383 | 383 | pl.expect() |
| 384 | 384 | e.compactInTurn(ctx, params) |
| 385 | 385 | } |
| 386 | + // Messages the user sent during the turn (ticket 265, | |
| 387 | + // steer.go) join the history after the tool results. | |
| 388 | + params.Request.Messages = takeSteer(ctx, params.Request.Messages) | |
| 386 | 389 | full = slices.Clone(params.Request.Messages) |
| 387 | 390 | // call runs ONE model call under its own context, which the |
| 388 | 391 | // loop watch cancels when the stream repeats itself — the |
| @@ -383,6 +383,9 @@ func (e *Engine) generate(ctx context.Context, messages []*ai.Message, tools []a | |||
| 383 | pl.expect() | 383 | pl.expect() |
| 384 | e.compactInTurn(ctx, params) | 384 | e.compactInTurn(ctx, params) |
| 385 | } | 385 | } |
| 386 | + // Messages the user sent during the turn (ticket 265, | ||
| 387 | + // steer.go) join the history after the tool results. | ||
| 388 | + params.Request.Messages = takeSteer(ctx, params.Request.Messages) | ||
| 386 | full = slices.Clone(params.Request.Messages) | 389 | full = slices.Clone(params.Request.Messages) |
| 387 | // call runs ONE model call under its own context, which the | 390 | // call runs ONE model call under its own context, which the |
| 388 | // loop watch cancels when the stream repeats itself — the | 391 | // loop watch cancels when the stream repeats itself — the |
added
internal/engine/steer.go +143 -0 | new file mode 100644 | ||
| @@ -0,0 +1,143 @@ | ||
| 1 | +package engine | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "context" | |
| 5 | + "strings" | |
| 6 | + "sync" | |
| 7 | + | |
| 8 | + "github.com/firebase/genkit/go/ai" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// Steering (ticket 265): a message the user sends while a turn runs reaches | |
| 12 | +// the model at its next call, inside the same turn, without stopping it. | |
| 13 | +// The front end gives the turn an Inbox through its context (WithSteer) and | |
| 14 | +// pushes the messages into it; the turn's WrapModel takes them before a | |
| 15 | +// model call that follows tool results (takeSteer) and appends each one as | |
| 16 | +// a user message, marked so the model does not take it for a new task. The | |
| 17 | +// history Genkit builds the next calls from — and the session keeps — | |
| 18 | +// carries them from then on. | |
| 19 | +// | |
| 20 | +// A message the turn cannot take any more — typed while the model writes | |
| 21 | +// its final answer, with no call after it — is not lost: Close, when the | |
| 22 | +// turn ends, hands it back, and the front end runs it as the next question. | |
| 23 | +// | |
| 24 | +// inbox := engine.NewInbox(func(text string) { notice("↪ steered: " + text) }) | |
| 25 | +// ctx = engine.WithSteer(ctx, inbox) | |
| 26 | +// go e.Generate(ctx, msgs, tools) | |
| 27 | +// // on Enter during the turn: | |
| 28 | +// if !inbox.Push(text) { queue(text) } | |
| 29 | +// // when the turn has ended: | |
| 30 | +// for _, late := range inbox.Close() { queue(late) } | |
| 31 | + | |
| 32 | +// SteerLabel introduces a steered message in what the model reads. | |
| 33 | +const SteerLabel = "[message from the user during this turn]" | |
| 34 | + | |
| 35 | +// Inbox holds the messages sent during one turn. Safe for concurrent use: | |
| 36 | +// the front end pushes from its own goroutine, the turn takes from its. | |
| 37 | +type Inbox struct { | |
| 38 | + mu sync.Mutex | |
| 39 | + waiting []string | |
| 40 | + closed bool | |
| 41 | + taken func(text string) // nil = nothing to show | |
| 42 | +} | |
| 43 | + | |
| 44 | +// NewInbox returns an open inbox; taken, when not nil, is called (on the | |
| 45 | +// turn's goroutine) with each message as the model is given it. | |
| 46 | +func NewInbox(taken func(text string)) *Inbox { | |
| 47 | + return &Inbox{taken: taken} | |
| 48 | +} | |
| 49 | + | |
| 50 | +// Push adds text for the turn's next model call. It returns false once the | |
| 51 | +// inbox is closed: the turn is over, the caller runs text otherwise. | |
| 52 | +func (b *Inbox) Push(text string) bool { | |
| 53 | + b.mu.Lock() | |
| 54 | + defer b.mu.Unlock() | |
| 55 | + if b.closed { | |
| 56 | + return false | |
| 57 | + } | |
| 58 | + b.waiting = append(b.waiting, text) | |
| 59 | + return true | |
| 60 | +} | |
| 61 | + | |
| 62 | +// Close ends the inbox and returns what the turn did not take, oldest | |
| 63 | +// first. Push fails from then on. Safe to call more than once. | |
| 64 | +func (b *Inbox) Close() []string { | |
| 65 | + b.mu.Lock() | |
| 66 | + defer b.mu.Unlock() | |
| 67 | + b.closed = true | |
| 68 | + late := b.waiting | |
| 69 | + b.waiting = nil | |
| 70 | + return late | |
| 71 | +} | |
| 72 | + | |
| 73 | +// take empties the inbox while it is open. | |
| 74 | +func (b *Inbox) take() []string { | |
| 75 | + b.mu.Lock() | |
| 76 | + defer b.mu.Unlock() | |
| 77 | + if b.closed { | |
| 78 | + return nil | |
| 79 | + } | |
| 80 | + got := b.waiting | |
| 81 | + b.waiting = nil | |
| 82 | + return got | |
| 83 | +} | |
| 84 | + | |
| 85 | +type steerKey struct{} | |
| 86 | + | |
| 87 | +// WithSteer returns ctx carrying the turn's inbox. | |
| 88 | +func WithSteer(ctx context.Context, b *Inbox) context.Context { | |
| 89 | + return context.WithValue(ctx, steerKey{}, b) | |
| 90 | +} | |
| 91 | + | |
| 92 | +func steerInbox(ctx context.Context) *Inbox { | |
| 93 | + b, _ := ctx.Value(steerKey{}).(*Inbox) | |
| 94 | + return b | |
| 95 | +} | |
| 96 | + | |
| 97 | +// takeSteer appends the messages waiting in ctx's inbox to msgs, as user | |
| 98 | +// messages, when the call follows tool results. Before the turn's first | |
| 99 | +// call — and after the model's own text — nothing is taken: a user message | |
| 100 | +// right after the question, or right after an answer, is not what the | |
| 101 | +// chat templates expect; the message waits for the next tool round, or for | |
| 102 | +// the end of the turn (Close). | |
| 103 | +func takeSteer(ctx context.Context, msgs []*ai.Message) []*ai.Message { | |
| 104 | + b := steerInbox(ctx) | |
| 105 | + if b == nil || len(msgs) == 0 || msgs[len(msgs)-1].Role != ai.RoleTool { | |
| 106 | + return msgs | |
| 107 | + } | |
| 108 | + for _, text := range b.take() { | |
| 109 | + msgs = append(msgs, ai.NewUserTextMessage(SteerLabel+" "+text)) | |
| 110 | + if b.taken != nil { | |
| 111 | + b.taken(text) | |
| 112 | + } | |
| 113 | + } | |
| 114 | + return msgs | |
| 115 | +} | |
| 116 | + | |
| 117 | +// RedirectLabel and RedirectNote frame the message of the editor's | |
| 118 | +// `/redirect` (ticket 267): sent with Zed's "Send Now", it follows a | |
| 119 | +// cancelled turn whose work the history kept, and it must read as a | |
| 120 | +// correction of that task, not as a new one. Neutral about whether the turn | |
| 121 | +// was stopped: without Send Now the editor delivers it after the turn. | |
| 122 | +const ( | |
| 123 | + RedirectLabel = "[the user redirects the task in progress]" | |
| 124 | + RedirectNote = "Continue the task you were working on, taking this into account." | |
| 125 | +) | |
| 126 | + | |
| 127 | +// Redirect is message framed as `/redirect` sends it to the model. | |
| 128 | +// | |
| 129 | +// engine.Redirect("use the v2 API") | |
| 130 | +// // "[the user redirects the task in progress] use the v2 API\n\nContinue the task …" | |
| 131 | +func Redirect(message string) string { | |
| 132 | + return RedirectLabel + " " + strings.TrimSpace(message) + "\n\n" + RedirectNote | |
| 133 | +} | |
| 134 | + | |
| 135 | +// Unredirect is the message a Redirect framed, and whether text is one. | |
| 136 | +func Unredirect(text string) (string, bool) { | |
| 137 | + rest, ok := strings.CutPrefix(text, RedirectLabel+" ") | |
| 138 | + if !ok { | |
| 139 | + return text, false | |
| 140 | + } | |
| 141 | + message, _, _ := strings.Cut(rest, "\n\n"+RedirectNote) | |
| 142 | + return strings.TrimSpace(message), true | |
| 143 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | +package engine | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "strings" | ||
| 6 | + "sync" | ||
| 7 | + | ||
| 8 | + "github.com/firebase/genkit/go/ai" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +// Steering (ticket 265): a message the user sends while a turn runs reaches | ||
| 12 | +// the model at its next call, inside the same turn, without stopping it. | ||
| 13 | +// The front end gives the turn an Inbox through its context (WithSteer) and | ||
| 14 | +// pushes the messages into it; the turn's WrapModel takes them before a | ||
| 15 | +// model call that follows tool results (takeSteer) and appends each one as | ||
| 16 | +// a user message, marked so the model does not take it for a new task. The | ||
| 17 | +// history Genkit builds the next calls from — and the session keeps — | ||
| 18 | +// carries them from then on. | ||
| 19 | +// | ||
| 20 | +// A message the turn cannot take any more — typed while the model writes | ||
| 21 | +// its final answer, with no call after it — is not lost: Close, when the | ||
| 22 | +// turn ends, hands it back, and the front end runs it as the next question. | ||
| 23 | +// | ||
| 24 | +// inbox := engine.NewInbox(func(text string) { notice("↪ steered: " + text) }) | ||
| 25 | +// ctx = engine.WithSteer(ctx, inbox) | ||
| 26 | +// go e.Generate(ctx, msgs, tools) | ||
| 27 | +// // on Enter during the turn: | ||
| 28 | +// if !inbox.Push(text) { queue(text) } | ||
| 29 | +// // when the turn has ended: | ||
| 30 | +// for _, late := range inbox.Close() { queue(late) } | ||
| 31 | + | ||
| 32 | +// SteerLabel introduces a steered message in what the model reads. | ||
| 33 | +const SteerLabel = "[message from the user during this turn]" | ||
| 34 | + | ||
| 35 | +// Inbox holds the messages sent during one turn. Safe for concurrent use: | ||
| 36 | +// the front end pushes from its own goroutine, the turn takes from its. | ||
| 37 | +type Inbox struct { | ||
| 38 | + mu sync.Mutex | ||
| 39 | + waiting []string | ||
| 40 | + closed bool | ||
| 41 | + taken func(text string) // nil = nothing to show | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// NewInbox returns an open inbox; taken, when not nil, is called (on the | ||
| 45 | +// turn's goroutine) with each message as the model is given it. | ||
| 46 | +func NewInbox(taken func(text string)) *Inbox { | ||
| 47 | + return &Inbox{taken: taken} | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +// Push adds text for the turn's next model call. It returns false once the | ||
| 51 | +// inbox is closed: the turn is over, the caller runs text otherwise. | ||
| 52 | +func (b *Inbox) Push(text string) bool { | ||
| 53 | + b.mu.Lock() | ||
| 54 | + defer b.mu.Unlock() | ||
| 55 | + if b.closed { | ||
| 56 | + return false | ||
| 57 | + } | ||
| 58 | + b.waiting = append(b.waiting, text) | ||
| 59 | + return true | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +// Close ends the inbox and returns what the turn did not take, oldest | ||
| 63 | +// first. Push fails from then on. Safe to call more than once. | ||
| 64 | +func (b *Inbox) Close() []string { | ||
| 65 | + b.mu.Lock() | ||
| 66 | + defer b.mu.Unlock() | ||
| 67 | + b.closed = true | ||
| 68 | + late := b.waiting | ||
| 69 | + b.waiting = nil | ||
| 70 | + return late | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +// take empties the inbox while it is open. | ||
| 74 | +func (b *Inbox) take() []string { | ||
| 75 | + b.mu.Lock() | ||
| 76 | + defer b.mu.Unlock() | ||
| 77 | + if b.closed { | ||
| 78 | + return nil | ||
| 79 | + } | ||
| 80 | + got := b.waiting | ||
| 81 | + b.waiting = nil | ||
| 82 | + return got | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +type steerKey struct{} | ||
| 86 | + | ||
| 87 | +// WithSteer returns ctx carrying the turn's inbox. | ||
| 88 | +func WithSteer(ctx context.Context, b *Inbox) context.Context { | ||
| 89 | + return context.WithValue(ctx, steerKey{}, b) | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +func steerInbox(ctx context.Context) *Inbox { | ||
| 93 | + b, _ := ctx.Value(steerKey{}).(*Inbox) | ||
| 94 | + return b | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +// takeSteer appends the messages waiting in ctx's inbox to msgs, as user | ||
| 98 | +// messages, when the call follows tool results. Before the turn's first | ||
| 99 | +// call — and after the model's own text — nothing is taken: a user message | ||
| 100 | +// right after the question, or right after an answer, is not what the | ||
| 101 | +// chat templates expect; the message waits for the next tool round, or for | ||
| 102 | +// the end of the turn (Close). | ||
| 103 | +func takeSteer(ctx context.Context, msgs []*ai.Message) []*ai.Message { | ||
| 104 | + b := steerInbox(ctx) | ||
| 105 | + if b == nil || len(msgs) == 0 || msgs[len(msgs)-1].Role != ai.RoleTool { | ||
| 106 | + return msgs | ||
| 107 | + } | ||
| 108 | + for _, text := range b.take() { | ||
| 109 | + msgs = append(msgs, ai.NewUserTextMessage(SteerLabel+" "+text)) | ||
| 110 | + if b.taken != nil { | ||
| 111 | + b.taken(text) | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + return msgs | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +// RedirectLabel and RedirectNote frame the message of the editor's | ||
| 118 | +// `/redirect` (ticket 267): sent with Zed's "Send Now", it follows a | ||
| 119 | +// cancelled turn whose work the history kept, and it must read as a | ||
| 120 | +// correction of that task, not as a new one. Neutral about whether the turn | ||
| 121 | +// was stopped: without Send Now the editor delivers it after the turn. | ||
| 122 | +const ( | ||
| 123 | + RedirectLabel = "[the user redirects the task in progress]" | ||
| 124 | + RedirectNote = "Continue the task you were working on, taking this into account." | ||
| 125 | +) | ||
| 126 | + | ||
| 127 | +// Redirect is message framed as `/redirect` sends it to the model. | ||
| 128 | +// | ||
| 129 | +// engine.Redirect("use the v2 API") | ||
| 130 | +// // "[the user redirects the task in progress] use the v2 API\n\nContinue the task …" | ||
| 131 | +func Redirect(message string) string { | ||
| 132 | + return RedirectLabel + " " + strings.TrimSpace(message) + "\n\n" + RedirectNote | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +// Unredirect is the message a Redirect framed, and whether text is one. | ||
| 136 | +func Unredirect(text string) (string, bool) { | ||
| 137 | + rest, ok := strings.CutPrefix(text, RedirectLabel+" ") | ||
| 138 | + if !ok { | ||
| 139 | + return text, false | ||
| 140 | + } | ||
| 141 | + message, _, _ := strings.Cut(rest, "\n\n"+RedirectNote) | ||
| 142 | + return strings.TrimSpace(message), true | ||
| 143 | +} | ||
added
internal/engine/steer_test.go +152 -0 | new file mode 100644 | ||
| @@ -0,0 +1,152 @@ | ||
| 1 | +package engine | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "context" | |
| 5 | + "fmt" | |
| 6 | + "strings" | |
| 7 | + "sync" | |
| 8 | + "testing" | |
| 9 | + | |
| 10 | + "mm/internal/compact" | |
| 11 | + "mm/internal/config" | |
| 12 | + | |
| 13 | + "github.com/firebase/genkit/go/ai" | |
| 14 | + "github.com/firebase/genkit/go/genkit" | |
| 15 | +) | |
| 16 | + | |
| 17 | +// steerTurn runs a turn whose model calls the tool `step` `steps` times then | |
| 18 | +// answers "done"; onStep runs inside the tool (the user typing while it | |
| 19 | +// runs). It returns what each model call received and the full history. | |
| 20 | +func steerTurn(t *testing.T, inbox *Inbox, steps int, onStep func(n int)) ([][]*ai.Message, []*ai.Message) { | |
| 21 | + t.Helper() | |
| 22 | + saved := config.Cfg | |
| 23 | + t.Cleanup(func() { config.Cfg = saved }) | |
| 24 | + config.Cfg.MaxTurns = 20 | |
| 25 | + g := genkit.Init(context.Background()) | |
| 26 | + var mu sync.Mutex | |
| 27 | + var requests [][]*ai.Message | |
| 28 | + calls := 0 | |
| 29 | + genkit.DefineModelAction(g, "dmr/"+config.Cfg.Model, | |
| 30 | + &ai.ModelOptions{Supports: &ai.ModelSupports{Tools: true, Multiturn: true, SystemRole: true}}, | |
| 31 | + func(_ context.Context, r *ai.ModelRequest, _ any, _ ai.ModelStreamCallback) (*ai.ModelResponse, error) { | |
| 32 | + mu.Lock() | |
| 33 | + defer mu.Unlock() | |
| 34 | + requests = append(requests, append([]*ai.Message(nil), r.Messages...)) | |
| 35 | + calls++ | |
| 36 | + if calls > steps { | |
| 37 | + return modelTurn(ai.NewTextPart("done")), nil | |
| 38 | + } | |
| 39 | + return modelTurn(ai.NewToolRequestPart(&ai.ToolRequest{Name: "step", Ref: fmt.Sprint(calls), | |
| 40 | + Input: map[string]any{"n": calls}})), nil | |
| 41 | + }) | |
| 42 | + genkit.DefineTool(g, "step", "one step", func(_ *ai.ToolContext, in struct { | |
| 43 | + N int `json:"n"` | |
| 44 | + }) (string, error) { | |
| 45 | + if onStep != nil { | |
| 46 | + onStep(in.N) | |
| 47 | + } | |
| 48 | + return fmt.Sprintf("step %d done", in.N), nil | |
| 49 | + }) | |
| 50 | + ctx := WithSteer(context.Background(), inbox) | |
| 51 | + _, full, err := testEngine(g).Generate(ctx, | |
| 52 | + []*ai.Message{ai.NewSystemTextMessage("system"), ai.NewUserTextMessage("do the steps")}, | |
| 53 | + []ai.ToolRef{ai.ToolName("step")}) | |
| 54 | + if err != nil { | |
| 55 | + t.Fatalf("Generate: %v", err) | |
| 56 | + } | |
| 57 | + return requests, full | |
| 58 | +} | |
| 59 | + | |
| 60 | +func steered(msgs []*ai.Message) []string { | |
| 61 | + var out []string | |
| 62 | + for _, m := range msgs { | |
| 63 | + if m.Role == ai.RoleUser && strings.HasPrefix(m.Text(), SteerLabel) { | |
| 64 | + out = append(out, m.Text()) | |
| 65 | + } | |
| 66 | + } | |
| 67 | + return out | |
| 68 | +} | |
| 69 | + | |
| 70 | +// A message pushed while a tool runs reaches the very next model call, after | |
| 71 | +// the tool's result, labelled; the turn goes on; the history keeps it and | |
| 72 | +// stays valid; the callback names it once. | |
| 73 | +func TestSteerReachesTheNextModelCall(t *testing.T) { | |
| 74 | + var taken []string | |
| 75 | + inbox := NewInbox(func(text string) { taken = append(taken, text) }) | |
| 76 | + requests, full := steerTurn(t, inbox, 2, func(n int) { | |
| 77 | + if n == 1 { | |
| 78 | + inbox.Push("use the v2 API") | |
| 79 | + } | |
| 80 | + }) | |
| 81 | + if len(requests) != 3 { | |
| 82 | + t.Fatalf("%d model calls, want 3 (the turn was not stopped)", len(requests)) | |
| 83 | + } | |
| 84 | + if got := steered(requests[0]); len(got) != 0 { | |
| 85 | + t.Errorf("first call already steered: %q", got) | |
| 86 | + } | |
| 87 | + second := requests[1] | |
| 88 | + last := second[len(second)-1] | |
| 89 | + if last.Role != ai.RoleUser || last.Text() != SteerLabel+" use the v2 API" { | |
| 90 | + t.Errorf("second call ends with %s %q, want the steer", last.Role, last.Text()) | |
| 91 | + } | |
| 92 | + if second[len(second)-2].Role != ai.RoleTool { | |
| 93 | + t.Errorf("the steer does not follow the tool result") | |
| 94 | + } | |
| 95 | + if got := steered(requests[2]); len(got) != 1 { | |
| 96 | + t.Errorf("third call: %d steers, want the one kept in the history", len(got)) | |
| 97 | + } | |
| 98 | + if got := steered(full); len(got) != 1 { | |
| 99 | + t.Errorf("history: %q", got) | |
| 100 | + } | |
| 101 | + if err := compact.Valid(full); err != nil { | |
| 102 | + t.Errorf("history: %v", err) | |
| 103 | + } | |
| 104 | + if len(taken) != 1 || taken[0] != "use the v2 API" { | |
| 105 | + t.Errorf("taken = %q", taken) | |
| 106 | + } | |
| 107 | + if late := inbox.Close(); len(late) != 0 { | |
| 108 | + t.Errorf("late = %q, want none", late) | |
| 109 | + } | |
| 110 | +} | |
| 111 | + | |
| 112 | +// A message that comes too late — no model call after it — stays in the | |
| 113 | +// inbox, and Close hands it back; once closed, Push refuses. | |
| 114 | +func TestSteerTooLateIsHandedBack(t *testing.T) { | |
| 115 | + inbox := NewInbox(nil) | |
| 116 | + requests, full := steerTurn(t, inbox, 0, nil) | |
| 117 | + inbox.Push("and the docs") | |
| 118 | + if len(steered(full)) != 0 || len(requests) != 1 { | |
| 119 | + t.Fatalf("steered without a tool round: %q", steered(full)) | |
| 120 | + } | |
| 121 | + if late := inbox.Close(); len(late) != 1 || late[0] != "and the docs" { | |
| 122 | + t.Errorf("late = %q", late) | |
| 123 | + } | |
| 124 | + if inbox.Push("again") { | |
| 125 | + t.Error("Push after Close accepted") | |
| 126 | + } | |
| 127 | + if inbox.Close() != nil { | |
| 128 | + t.Error("second Close returned messages") | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +// Before the first call nothing is taken: a user message right after the | |
| 133 | +// question is not what chat templates expect; it waits for a tool round. | |
| 134 | +func TestSteerWaitsForAToolRound(t *testing.T) { | |
| 135 | + inbox := NewInbox(nil) | |
| 136 | + inbox.Push("early") | |
| 137 | + requests, _ := steerTurn(t, inbox, 1, nil) | |
| 138 | + if got := steered(requests[0]); len(got) != 0 { | |
| 139 | + t.Errorf("first call steered: %q", got) | |
| 140 | + } | |
| 141 | + if got := steered(requests[1]); len(got) != 1 { | |
| 142 | + t.Errorf("second call: %q, want the early message after the tool result", got) | |
| 143 | + } | |
| 144 | +} | |
| 145 | + | |
| 146 | +// No inbox in the context: the turn is untouched. | |
| 147 | +func TestNoSteerWithoutAnInbox(t *testing.T) { | |
| 148 | + msgs := []*ai.Message{ai.NewUserTextMessage("q"), {Role: ai.RoleTool}} | |
| 149 | + if got := takeSteer(context.Background(), msgs); len(got) != 2 { | |
| 150 | + t.Errorf("takeSteer without inbox changed the messages: %d", len(got)) | |
| 151 | + } | |
| 152 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | +package engine | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "fmt" | ||
| 6 | + "strings" | ||
| 7 | + "sync" | ||
| 8 | + "testing" | ||
| 9 | + | ||
| 10 | + "mm/internal/compact" | ||
| 11 | + "mm/internal/config" | ||
| 12 | + | ||
| 13 | + "github.com/firebase/genkit/go/ai" | ||
| 14 | + "github.com/firebase/genkit/go/genkit" | ||
| 15 | +) | ||
| 16 | + | ||
| 17 | +// steerTurn runs a turn whose model calls the tool `step` `steps` times then | ||
| 18 | +// answers "done"; onStep runs inside the tool (the user typing while it | ||
| 19 | +// runs). It returns what each model call received and the full history. | ||
| 20 | +func steerTurn(t *testing.T, inbox *Inbox, steps int, onStep func(n int)) ([][]*ai.Message, []*ai.Message) { | ||
| 21 | + t.Helper() | ||
| 22 | + saved := config.Cfg | ||
| 23 | + t.Cleanup(func() { config.Cfg = saved }) | ||
| 24 | + config.Cfg.MaxTurns = 20 | ||
| 25 | + g := genkit.Init(context.Background()) | ||
| 26 | + var mu sync.Mutex | ||
| 27 | + var requests [][]*ai.Message | ||
| 28 | + calls := 0 | ||
| 29 | + genkit.DefineModelAction(g, "dmr/"+config.Cfg.Model, | ||
| 30 | + &ai.ModelOptions{Supports: &ai.ModelSupports{Tools: true, Multiturn: true, SystemRole: true}}, | ||
| 31 | + func(_ context.Context, r *ai.ModelRequest, _ any, _ ai.ModelStreamCallback) (*ai.ModelResponse, error) { | ||
| 32 | + mu.Lock() | ||
| 33 | + defer mu.Unlock() | ||
| 34 | + requests = append(requests, append([]*ai.Message(nil), r.Messages...)) | ||
| 35 | + calls++ | ||
| 36 | + if calls > steps { | ||
| 37 | + return modelTurn(ai.NewTextPart("done")), nil | ||
| 38 | + } | ||
| 39 | + return modelTurn(ai.NewToolRequestPart(&ai.ToolRequest{Name: "step", Ref: fmt.Sprint(calls), | ||
| 40 | + Input: map[string]any{"n": calls}})), nil | ||
| 41 | + }) | ||
| 42 | + genkit.DefineTool(g, "step", "one step", func(_ *ai.ToolContext, in struct { | ||
| 43 | + N int `json:"n"` | ||
| 44 | + }) (string, error) { | ||
| 45 | + if onStep != nil { | ||
| 46 | + onStep(in.N) | ||
| 47 | + } | ||
| 48 | + return fmt.Sprintf("step %d done", in.N), nil | ||
| 49 | + }) | ||
| 50 | + ctx := WithSteer(context.Background(), inbox) | ||
| 51 | + _, full, err := testEngine(g).Generate(ctx, | ||
| 52 | + []*ai.Message{ai.NewSystemTextMessage("system"), ai.NewUserTextMessage("do the steps")}, | ||
| 53 | + []ai.ToolRef{ai.ToolName("step")}) | ||
| 54 | + if err != nil { | ||
| 55 | + t.Fatalf("Generate: %v", err) | ||
| 56 | + } | ||
| 57 | + return requests, full | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +func steered(msgs []*ai.Message) []string { | ||
| 61 | + var out []string | ||
| 62 | + for _, m := range msgs { | ||
| 63 | + if m.Role == ai.RoleUser && strings.HasPrefix(m.Text(), SteerLabel) { | ||
| 64 | + out = append(out, m.Text()) | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + return out | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +// A message pushed while a tool runs reaches the very next model call, after | ||
| 71 | +// the tool's result, labelled; the turn goes on; the history keeps it and | ||
| 72 | +// stays valid; the callback names it once. | ||
| 73 | +func TestSteerReachesTheNextModelCall(t *testing.T) { | ||
| 74 | + var taken []string | ||
| 75 | + inbox := NewInbox(func(text string) { taken = append(taken, text) }) | ||
| 76 | + requests, full := steerTurn(t, inbox, 2, func(n int) { | ||
| 77 | + if n == 1 { | ||
| 78 | + inbox.Push("use the v2 API") | ||
| 79 | + } | ||
| 80 | + }) | ||
| 81 | + if len(requests) != 3 { | ||
| 82 | + t.Fatalf("%d model calls, want 3 (the turn was not stopped)", len(requests)) | ||
| 83 | + } | ||
| 84 | + if got := steered(requests[0]); len(got) != 0 { | ||
| 85 | + t.Errorf("first call already steered: %q", got) | ||
| 86 | + } | ||
| 87 | + second := requests[1] | ||
| 88 | + last := second[len(second)-1] | ||
| 89 | + if last.Role != ai.RoleUser || last.Text() != SteerLabel+" use the v2 API" { | ||
| 90 | + t.Errorf("second call ends with %s %q, want the steer", last.Role, last.Text()) | ||
| 91 | + } | ||
| 92 | + if second[len(second)-2].Role != ai.RoleTool { | ||
| 93 | + t.Errorf("the steer does not follow the tool result") | ||
| 94 | + } | ||
| 95 | + if got := steered(requests[2]); len(got) != 1 { | ||
| 96 | + t.Errorf("third call: %d steers, want the one kept in the history", len(got)) | ||
| 97 | + } | ||
| 98 | + if got := steered(full); len(got) != 1 { | ||
| 99 | + t.Errorf("history: %q", got) | ||
| 100 | + } | ||
| 101 | + if err := compact.Valid(full); err != nil { | ||
| 102 | + t.Errorf("history: %v", err) | ||
| 103 | + } | ||
| 104 | + if len(taken) != 1 || taken[0] != "use the v2 API" { | ||
| 105 | + t.Errorf("taken = %q", taken) | ||
| 106 | + } | ||
| 107 | + if late := inbox.Close(); len(late) != 0 { | ||
| 108 | + t.Errorf("late = %q, want none", late) | ||
| 109 | + } | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +// A message that comes too late — no model call after it — stays in the | ||
| 113 | +// inbox, and Close hands it back; once closed, Push refuses. | ||
| 114 | +func TestSteerTooLateIsHandedBack(t *testing.T) { | ||
| 115 | + inbox := NewInbox(nil) | ||
| 116 | + requests, full := steerTurn(t, inbox, 0, nil) | ||
| 117 | + inbox.Push("and the docs") | ||
| 118 | + if len(steered(full)) != 0 || len(requests) != 1 { | ||
| 119 | + t.Fatalf("steered without a tool round: %q", steered(full)) | ||
| 120 | + } | ||
| 121 | + if late := inbox.Close(); len(late) != 1 || late[0] != "and the docs" { | ||
| 122 | + t.Errorf("late = %q", late) | ||
| 123 | + } | ||
| 124 | + if inbox.Push("again") { | ||
| 125 | + t.Error("Push after Close accepted") | ||
| 126 | + } | ||
| 127 | + if inbox.Close() != nil { | ||
| 128 | + t.Error("second Close returned messages") | ||
| 129 | + } | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +// Before the first call nothing is taken: a user message right after the | ||
| 133 | +// question is not what chat templates expect; it waits for a tool round. | ||
| 134 | +func TestSteerWaitsForAToolRound(t *testing.T) { | ||
| 135 | + inbox := NewInbox(nil) | ||
| 136 | + inbox.Push("early") | ||
| 137 | + requests, _ := steerTurn(t, inbox, 1, nil) | ||
| 138 | + if got := steered(requests[0]); len(got) != 0 { | ||
| 139 | + t.Errorf("first call steered: %q", got) | ||
| 140 | + } | ||
| 141 | + if got := steered(requests[1]); len(got) != 1 { | ||
| 142 | + t.Errorf("second call: %q, want the early message after the tool result", got) | ||
| 143 | + } | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +// No inbox in the context: the turn is untouched. | ||
| 147 | +func TestNoSteerWithoutAnInbox(t *testing.T) { | ||
| 148 | + msgs := []*ai.Message{ai.NewUserTextMessage("q"), {Role: ai.RoleTool}} | ||
| 149 | + if got := takeSteer(context.Background(), msgs); len(got) != 2 { | ||
| 150 | + t.Errorf("takeSteer without inbox changed the messages: %d", len(got)) | ||
| 151 | + } | ||
| 152 | +} | ||
modified
internal/store/questions.go +6 -1 | @@ -21,7 +21,8 @@ const maxQuestions = 200 | ||
| 21 | 21 | // read from the stored history, so a question comes back as mm kept it — |
| 22 | 22 | // with its `[attached file: …]` lines and its pastes in full. What the user |
| 23 | 23 | // never typed is left out: a /compact summary, mm's own notes (engine.IsNote), |
| 24 | -// the context a preGeneration hook appended, and the turnReminder. Two identical questions in | |
| 24 | +// the context a preGeneration hook appended, and the turnReminder; a message | |
| 25 | +// sent during a turn (ticket 265) loses its label. Two identical questions in | |
| 25 | 26 | // a row are kept once. A nil Keeper — sessions off — has nothing to recall. |
| 26 | 27 | // |
| 27 | 28 | // recall := keep.Questions(messages) // recall[0] is the last question asked |
| @@ -69,6 +70,10 @@ func question(m *ai.Message) (string, bool) { | ||
| 69 | 70 | for _, label := range []string{hooks.ContextLabel, engine.ReminderLabel} { |
| 70 | 71 | text, _, _ = strings.Cut(text, "\n\n"+label) |
| 71 | 72 | } |
| 73 | + // A message sent during a turn (ticket 265) or with the editor's | |
| 74 | + // /redirect (ticket 267) comes back as typed. | |
| 75 | + text = strings.TrimPrefix(text, engine.SteerLabel+" ") | |
| 76 | + text, _ = engine.Unredirect(text) | |
| 72 | 77 | text = strings.TrimSpace(text) |
| 73 | 78 | if text == "" || engine.IsNote(text) { |
| 74 | 79 | return "", false |
| @@ -21,7 +21,8 @@ const maxQuestions = 200 | |||
| 21 | // read from the stored history, so a question comes back as mm kept it — | 21 | // read from the stored history, so a question comes back as mm kept it — |
| 22 | // with its `[attached file: …]` lines and its pastes in full. What the user | 22 | // with its `[attached file: …]` lines and its pastes in full. What the user |
| 23 | // never typed is left out: a /compact summary, mm's own notes (engine.IsNote), | 23 | // never typed is left out: a /compact summary, mm's own notes (engine.IsNote), |
| 24 | -// the context a preGeneration hook appended, and the turnReminder. Two identical questions in | 24 | +// the context a preGeneration hook appended, and the turnReminder; a message |
| 25 | +// sent during a turn (ticket 265) loses its label. Two identical questions in | ||
| 25 | // a row are kept once. A nil Keeper — sessions off — has nothing to recall. | 26 | // a row are kept once. A nil Keeper — sessions off — has nothing to recall. |
| 26 | // | 27 | // |
| 27 | // recall := keep.Questions(messages) // recall[0] is the last question asked | 28 | // recall := keep.Questions(messages) // recall[0] is the last question asked |
| @@ -69,6 +70,10 @@ func question(m *ai.Message) (string, bool) { | |||
| 69 | for _, label := range []string{hooks.ContextLabel, engine.ReminderLabel} { | 70 | for _, label := range []string{hooks.ContextLabel, engine.ReminderLabel} { |
| 70 | text, _, _ = strings.Cut(text, "\n\n"+label) | 71 | text, _, _ = strings.Cut(text, "\n\n"+label) |
| 71 | } | 72 | } |
| 73 | + // A message sent during a turn (ticket 265) or with the editor's | ||
| 74 | + // /redirect (ticket 267) comes back as typed. | ||
| 75 | + text = strings.TrimPrefix(text, engine.SteerLabel+" ") | ||
| 76 | + text, _ = engine.Unredirect(text) | ||
| 72 | text = strings.TrimSpace(text) | 77 | text = strings.TrimSpace(text) |
| 73 | if text == "" || engine.IsNote(text) { | 78 | if text == "" || engine.IsNote(text) { |
| 74 | return "", false | 79 | return "", false |
modified
internal/store/questions_test.go +4 -2 | @@ -63,7 +63,7 @@ func TestQuestionsOrderCurrentThenEarlierSessions(t *testing.T) { | ||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // What the user never typed is not recalled; what a hook added to a question |
| 66 | -// (hook context, turnReminder) is cut off it; a question asked twice in a row comes back once. | |
| 66 | +// (hook context, turnReminder) is cut off it, a steer loses its label; a question asked twice in a row comes back once. | |
| 67 | 67 | func TestQuestionsSkipWhatTheUserDidNotType(t *testing.T) { |
| 68 | 68 | k := newQuestionsKeeper(t) |
| 69 | 69 | msgs := session0() |
| @@ -76,9 +76,11 @@ func TestQuestionsSkipWhatTheUserDidNotType(t *testing.T) { | ||
| 76 | 76 | msgs = talk(msgs, "run the tests\n\n"+hooks.ContextLabel+"branch: main") |
| 77 | 77 | msgs = talk(msgs, "comment out line 8\n\n"+engine.ReminderLabel+"If a decision is missing, call ask_user first.") |
| 78 | 78 | msgs = talk(msgs, "read main.go\n\n"+hooks.ContextLabel+"branch: main\n\n"+engine.ReminderLabel+"Act.") |
| 79 | + msgs = talk(msgs, engine.SteerLabel+" use the v2 API") | |
| 80 | + msgs = talk(msgs, engine.Redirect("stop, use Go 1.27")) | |
| 79 | 81 | msgs = append(msgs, nil) |
| 80 | 82 | |
| 81 | - want := []string{"read main.go", "comment out line 8", "run the tests", "fix the build"} | |
| 83 | + want := []string{"stop, use Go 1.27", "use the v2 API", "read main.go", "comment out line 8", "run the tests", "fix the build"} | |
| 82 | 84 | if got := k.Questions(msgs); !reflect.DeepEqual(got, want) { |
| 83 | 85 | t.Errorf("Questions = %q, want %q", got, want) |
| 84 | 86 | } |
| @@ -63,7 +63,7 @@ func TestQuestionsOrderCurrentThenEarlierSessions(t *testing.T) { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | // What the user never typed is not recalled; what a hook added to a question | 65 | // What the user never typed is not recalled; what a hook added to a question |
| 66 | -// (hook context, turnReminder) is cut off it; a question asked twice in a row comes back once. | 66 | +// (hook context, turnReminder) is cut off it, a steer loses its label; a question asked twice in a row comes back once. |
| 67 | func TestQuestionsSkipWhatTheUserDidNotType(t *testing.T) { | 67 | func TestQuestionsSkipWhatTheUserDidNotType(t *testing.T) { |
| 68 | k := newQuestionsKeeper(t) | 68 | k := newQuestionsKeeper(t) |
| 69 | msgs := session0() | 69 | msgs := session0() |
| @@ -76,9 +76,11 @@ func TestQuestionsSkipWhatTheUserDidNotType(t *testing.T) { | |||
| 76 | msgs = talk(msgs, "run the tests\n\n"+hooks.ContextLabel+"branch: main") | 76 | msgs = talk(msgs, "run the tests\n\n"+hooks.ContextLabel+"branch: main") |
| 77 | msgs = talk(msgs, "comment out line 8\n\n"+engine.ReminderLabel+"If a decision is missing, call ask_user first.") | 77 | msgs = talk(msgs, "comment out line 8\n\n"+engine.ReminderLabel+"If a decision is missing, call ask_user first.") |
| 78 | msgs = talk(msgs, "read main.go\n\n"+hooks.ContextLabel+"branch: main\n\n"+engine.ReminderLabel+"Act.") | 78 | msgs = talk(msgs, "read main.go\n\n"+hooks.ContextLabel+"branch: main\n\n"+engine.ReminderLabel+"Act.") |
| 79 | + msgs = talk(msgs, engine.SteerLabel+" use the v2 API") | ||
| 80 | + msgs = talk(msgs, engine.Redirect("stop, use Go 1.27")) | ||
| 79 | msgs = append(msgs, nil) | 81 | msgs = append(msgs, nil) |
| 80 | 82 | ||
| 81 | - want := []string{"read main.go", "comment out line 8", "run the tests", "fix the build"} | 83 | + want := []string{"stop, use Go 1.27", "use the v2 API", "read main.go", "comment out line 8", "run the tests", "fix the build"} |
| 82 | if got := k.Questions(msgs); !reflect.DeepEqual(got, want) { | 84 | if got := k.Questions(msgs); !reflect.DeepEqual(got, want) { |
| 83 | t.Errorf("Questions = %q, want %q", got, want) | 85 | t.Errorf("Questions = %q, want %q", got, want) |
| 84 | } | 86 | } |
modified
internal/tui/commands.go +64 -8 | @@ -7,19 +7,24 @@ package tui | ||
| 7 | 7 | import ( |
| 8 | 8 | "context" |
| 9 | 9 | "fmt" |
| 10 | + "strings" | |
| 10 | 11 | |
| 11 | 12 | "mm/internal/agentsmd" |
| 12 | 13 | "mm/internal/command" |
| 13 | 14 | "mm/internal/docsearch" |
| 15 | + "mm/internal/mention" | |
| 14 | 16 | "mm/internal/session" |
| 17 | + "mm/internal/skills" | |
| 15 | 18 | "mm/internal/store" |
| 16 | 19 | "mm/internal/tools" |
| 17 | 20 | ) |
| 18 | 21 | |
| 19 | 22 | // submit is what Enter does with the box: a slash command or a question. |
| 20 | -// During a turn the text waits in a queue and runs once the turn has settled | |
| 21 | -// (ticket 155): a question typed meanwhile no longer cuts the answer being | |
| 22 | -// written. Esc stops the turn; what is queued then runs at once. | |
| 23 | +// During a turn a question STEERS it (ticket 265): the model reads it after | |
| 24 | +// its current step and the turn goes on. Commands, and questions the turn | |
| 25 | +// can no longer take, wait in a queue and run once the turn has settled | |
| 26 | +// (ticket 155), as does `/queue <question>`. Esc stops the turn; what is | |
| 27 | +// queued then runs at once. | |
| 23 | 28 | // |
| 24 | 29 | // The two control commands are the exception, and it is the whole point of |
| 25 | 30 | // ticket 26: /quit and /abort are about the turn in progress, so queueing |
| @@ -31,19 +36,68 @@ func (r *runner) submit(p Prompt) { | ||
| 31 | 36 | return |
| 32 | 37 | } |
| 33 | 38 | if r.isBusy() { |
| 34 | - r.pending = append(r.pending, p) | |
| 35 | - r.t.Notice(fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · Esc stops the turn", len(r.pending))) | |
| 39 | + if r.steer(p) { | |
| 40 | + return | |
| 41 | + } | |
| 42 | + r.enqueue(p) | |
| 36 | 43 | return |
| 37 | 44 | } |
| 38 | 45 | r.dispatch(p) |
| 39 | 46 | } |
| 40 | 47 | |
| 48 | +// enqueue keeps p for when the job in progress has settled (ticket 155). | |
| 49 | +func (r *runner) enqueue(p Prompt) { | |
| 50 | + r.pending = append(r.pending, p) | |
| 51 | + r.t.Notice(fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · Esc stops the turn", len(r.pending))) | |
| 52 | +} | |
| 53 | + | |
| 54 | +// steer hands a question sent during a turn to the turn itself (ticket | |
| 55 | +// 265): the model reads it after its current step, the turn goes on. Only | |
| 56 | +// a question, only during a turn (not a compaction or an /ask), and only | |
| 57 | +// while the turn still takes messages; anything else is queued. | |
| 58 | +func (r *runner) steer(p Prompt) bool { | |
| 59 | + if r.inbox == nil || r.busyLabel() != "thinking" || strings.HasPrefix(strings.TrimSpace(p.Typed), "/") { | |
| 60 | + return false | |
| 61 | + } | |
| 62 | + expanded, attached := mention.Expand(p.Typed, r.opts.Cwd) | |
| 63 | + expanded, refs := skills.ExpandRefs(expanded, r.opts.Skills) | |
| 64 | + if !r.inbox.Push(p.Expand(expanded)) { | |
| 65 | + return false | |
| 66 | + } | |
| 67 | + r.steering = append(r.steering, p) | |
| 68 | + r.t.AddUserFull(p.Display(), p.Text()) | |
| 69 | + for _, ref := range refs { | |
| 70 | + r.t.Notice("📖 $" + ref.Name) | |
| 71 | + } | |
| 72 | + for _, a := range attached { | |
| 73 | + r.t.Notice("📎 " + a.Path) | |
| 74 | + } | |
| 75 | + r.t.Notice("↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn") | |
| 76 | + return true | |
| 77 | +} | |
| 78 | + | |
| 79 | +// queue is /queue: the question waits for the end of the turn in | |
| 80 | +// progress, or runs at once when nothing runs. | |
| 81 | +func (r *runner) queue(p Prompt, arg string) { | |
| 82 | + if arg == "" { | |
| 83 | + r.t.Error("⚠️ /queue needs a question: /queue <question>") | |
| 84 | + return | |
| 85 | + } | |
| 86 | + q := Prompt{Typed: arg, Pastes: p.Pastes} | |
| 87 | + if r.isBusy() { | |
| 88 | + r.enqueue(q) | |
| 89 | + return | |
| 90 | + } | |
| 91 | + r.dispatch(q) | |
| 92 | +} | |
| 93 | + | |
| 41 | 94 | // control runs the commands that must never wait for the turn in progress, |
| 42 | 95 | // and reports whether it ran one. Everything else needs the session the turn |
| 43 | 96 | // is still writing to, so it waits in the queue. /shell touches no session: |
| 44 | -// it runs at once, and the turn goes on under it. | |
| 97 | +// it runs at once, and the turn goes on under it. /queue is the queue | |
| 98 | +// itself (ticket 265): it must not be steered into the turn. | |
| 45 | 99 | func (r *runner) control(p Prompt) bool { |
| 46 | - cmd, _, ok := command.Parse(p.Typed) | |
| 100 | + cmd, arg, ok := command.Parse(p.Typed) | |
| 47 | 101 | if !ok { |
| 48 | 102 | return false |
| 49 | 103 | } |
| @@ -54,6 +108,8 @@ func (r *runner) control(p Prompt) bool { | ||
| 54 | 108 | r.abort() |
| 55 | 109 | case command.Shell: |
| 56 | 110 | r.shell() |
| 111 | + case command.Queue: | |
| 112 | + r.queue(p, arg) | |
| 57 | 113 | default: |
| 58 | 114 | return false |
| 59 | 115 | } |
| @@ -136,7 +192,7 @@ func (r *runner) unload(model string) { | ||
| 136 | 192 | |
| 137 | 193 | // help lists the window's commands and keys. |
| 138 | 194 | func (r *runner) help() { |
| 139 | - r.t.Notice(command.Usage(command.Window) + "\n\nEnter sends (during a turn: queues) · Ctrl-J new line · Esc cancels the turn (idle: clears the box) · ↑/↓ recall earlier questions (sessions on) · Ctrl-C cancels then quits (twice to leave a turn that will not stop) · Ctrl-L clears · Ctrl-Y copies the last answer · F2 mouse on/off (off: select text with the mouse as usual) · PgUp/PgDn scroll · Tab moves the focus · @path attaches a file") | |
| 195 | + r.t.Notice(command.Usage(command.Window) + "\n\nEnter sends (during a turn: steers — the model reads it after its current step; /queue <question> waits for the end of the turn) · Ctrl-J new line · Esc cancels the turn (idle: clears the box) · ↑/↓ recall earlier questions (sessions on) · Ctrl-C cancels then quits (twice to leave a turn that will not stop) · Ctrl-L clears · Ctrl-Y copies the last answer · F2 mouse on/off (off: select text with the mouse as usual) · PgUp/PgDn scroll · Tab moves the focus · @path attaches a file") | |
| 140 | 196 | } |
| 141 | 197 | |
| 142 | 198 | // quitNow ends the loop on its next turn. |
| @@ -7,19 +7,24 @@ package tui | |||
| 7 | import ( | 7 | import ( |
| 8 | "context" | 8 | "context" |
| 9 | "fmt" | 9 | "fmt" |
| 10 | + "strings" | ||
| 10 | 11 | ||
| 11 | "mm/internal/agentsmd" | 12 | "mm/internal/agentsmd" |
| 12 | "mm/internal/command" | 13 | "mm/internal/command" |
| 13 | "mm/internal/docsearch" | 14 | "mm/internal/docsearch" |
| 15 | + "mm/internal/mention" | ||
| 14 | "mm/internal/session" | 16 | "mm/internal/session" |
| 17 | + "mm/internal/skills" | ||
| 15 | "mm/internal/store" | 18 | "mm/internal/store" |
| 16 | "mm/internal/tools" | 19 | "mm/internal/tools" |
| 17 | ) | 20 | ) |
| 18 | 21 | ||
| 19 | // submit is what Enter does with the box: a slash command or a question. | 22 | // submit is what Enter does with the box: a slash command or a question. |
| 20 | -// During a turn the text waits in a queue and runs once the turn has settled | 23 | +// During a turn a question STEERS it (ticket 265): the model reads it after |
| 21 | -// (ticket 155): a question typed meanwhile no longer cuts the answer being | 24 | +// its current step and the turn goes on. Commands, and questions the turn |
| 22 | -// written. Esc stops the turn; what is queued then runs at once. | 25 | +// can no longer take, wait in a queue and run once the turn has settled |
| 26 | +// (ticket 155), as does `/queue <question>`. Esc stops the turn; what is | ||
| 27 | +// queued then runs at once. | ||
| 23 | // | 28 | // |
| 24 | // The two control commands are the exception, and it is the whole point of | 29 | // The two control commands are the exception, and it is the whole point of |
| 25 | // ticket 26: /quit and /abort are about the turn in progress, so queueing | 30 | // ticket 26: /quit and /abort are about the turn in progress, so queueing |
| @@ -31,19 +36,68 @@ func (r *runner) submit(p Prompt) { | |||
| 31 | return | 36 | return |
| 32 | } | 37 | } |
| 33 | if r.isBusy() { | 38 | if r.isBusy() { |
| 34 | - r.pending = append(r.pending, p) | 39 | + if r.steer(p) { |
| 35 | - r.t.Notice(fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · Esc stops the turn", len(r.pending))) | 40 | + return |
| 41 | + } | ||
| 42 | + r.enqueue(p) | ||
| 36 | return | 43 | return |
| 37 | } | 44 | } |
| 38 | r.dispatch(p) | 45 | r.dispatch(p) |
| 39 | } | 46 | } |
| 40 | 47 | ||
| 48 | +// enqueue keeps p for when the job in progress has settled (ticket 155). | ||
| 49 | +func (r *runner) enqueue(p Prompt) { | ||
| 50 | + r.pending = append(r.pending, p) | ||
| 51 | + r.t.Notice(fmt.Sprintf("⏳ Queued (%d) — runs once this turn ends · Esc stops the turn", len(r.pending))) | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +// steer hands a question sent during a turn to the turn itself (ticket | ||
| 55 | +// 265): the model reads it after its current step, the turn goes on. Only | ||
| 56 | +// a question, only during a turn (not a compaction or an /ask), and only | ||
| 57 | +// while the turn still takes messages; anything else is queued. | ||
| 58 | +func (r *runner) steer(p Prompt) bool { | ||
| 59 | + if r.inbox == nil || r.busyLabel() != "thinking" || strings.HasPrefix(strings.TrimSpace(p.Typed), "/") { | ||
| 60 | + return false | ||
| 61 | + } | ||
| 62 | + expanded, attached := mention.Expand(p.Typed, r.opts.Cwd) | ||
| 63 | + expanded, refs := skills.ExpandRefs(expanded, r.opts.Skills) | ||
| 64 | + if !r.inbox.Push(p.Expand(expanded)) { | ||
| 65 | + return false | ||
| 66 | + } | ||
| 67 | + r.steering = append(r.steering, p) | ||
| 68 | + r.t.AddUserFull(p.Display(), p.Text()) | ||
| 69 | + for _, ref := range refs { | ||
| 70 | + r.t.Notice("📖 $" + ref.Name) | ||
| 71 | + } | ||
| 72 | + for _, a := range attached { | ||
| 73 | + r.t.Notice("📎 " + a.Path) | ||
| 74 | + } | ||
| 75 | + r.t.Notice("↪ Steering — the model reads it after its current step · /queue <question> waits for the end of the turn") | ||
| 76 | + return true | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +// queue is /queue: the question waits for the end of the turn in | ||
| 80 | +// progress, or runs at once when nothing runs. | ||
| 81 | +func (r *runner) queue(p Prompt, arg string) { | ||
| 82 | + if arg == "" { | ||
| 83 | + r.t.Error("⚠️ /queue needs a question: /queue <question>") | ||
| 84 | + return | ||
| 85 | + } | ||
| 86 | + q := Prompt{Typed: arg, Pastes: p.Pastes} | ||
| 87 | + if r.isBusy() { | ||
| 88 | + r.enqueue(q) | ||
| 89 | + return | ||
| 90 | + } | ||
| 91 | + r.dispatch(q) | ||
| 92 | +} | ||
| 93 | + | ||
| 41 | // control runs the commands that must never wait for the turn in progress, | 94 | // control runs the commands that must never wait for the turn in progress, |
| 42 | // and reports whether it ran one. Everything else needs the session the turn | 95 | // and reports whether it ran one. Everything else needs the session the turn |
| 43 | // is still writing to, so it waits in the queue. /shell touches no session: | 96 | // is still writing to, so it waits in the queue. /shell touches no session: |
| 44 | -// it runs at once, and the turn goes on under it. | 97 | +// it runs at once, and the turn goes on under it. /queue is the queue |
| 98 | +// itself (ticket 265): it must not be steered into the turn. | ||
| 45 | func (r *runner) control(p Prompt) bool { | 99 | func (r *runner) control(p Prompt) bool { |
| 46 | - cmd, _, ok := command.Parse(p.Typed) | 100 | + cmd, arg, ok := command.Parse(p.Typed) |
| 47 | if !ok { | 101 | if !ok { |
| 48 | return false | 102 | return false |
| 49 | } | 103 | } |
| @@ -54,6 +108,8 @@ func (r *runner) control(p Prompt) bool { | |||
| 54 | r.abort() | 108 | r.abort() |
| 55 | case command.Shell: | 109 | case command.Shell: |
| 56 | r.shell() | 110 | r.shell() |
| 111 | + case command.Queue: | ||
| 112 | + r.queue(p, arg) | ||
| 57 | default: | 113 | default: |
| 58 | return false | 114 | return false |
| 59 | } | 115 | } |
| @@ -136,7 +192,7 @@ func (r *runner) unload(model string) { | |||
| 136 | 192 | ||
| 137 | // help lists the window's commands and keys. | 193 | // help lists the window's commands and keys. |
| 138 | func (r *runner) help() { | 194 | func (r *runner) help() { |
| 139 | - r.t.Notice(command.Usage(command.Window) + "\n\nEnter sends (during a turn: queues) · Ctrl-J new line · Esc cancels the turn (idle: clears the box) · ↑/↓ recall earlier questions (sessions on) · Ctrl-C cancels then quits (twice to leave a turn that will not stop) · Ctrl-L clears · Ctrl-Y copies the last answer · F2 mouse on/off (off: select text with the mouse as usual) · PgUp/PgDn scroll · Tab moves the focus · @path attaches a file") | 195 | + r.t.Notice(command.Usage(command.Window) + "\n\nEnter sends (during a turn: steers — the model reads it after its current step; /queue <question> waits for the end of the turn) · Ctrl-J new line · Esc cancels the turn (idle: clears the box) · ↑/↓ recall earlier questions (sessions on) · Ctrl-C cancels then quits (twice to leave a turn that will not stop) · Ctrl-L clears · Ctrl-Y copies the last answer · F2 mouse on/off (off: select text with the mouse as usual) · PgUp/PgDn scroll · Tab moves the focus · @path attaches a file") |
| 140 | } | 196 | } |
| 141 | 197 | ||
| 142 | // quitNow ends the loop on its next turn. | 198 | // quitNow ends the loop on its next turn. |
modified
internal/tui/paste.go +3 -0 | @@ -109,6 +109,9 @@ func (ps *pastes) labelOf(r rune) (string, bool) { | ||
| 109 | 109 | type Prompt struct { |
| 110 | 110 | Typed string |
| 111 | 111 | Pastes map[rune]paste |
| 112 | + // shown: the conversation already shows it — a message steered into a | |
| 113 | + // turn that came too late and now runs as the next question (ticket 265). | |
| 114 | + shown bool | |
| 112 | 115 | } |
| 113 | 116 | |
| 114 | 117 | // promptOf is a Prompt with no paste: a slash command, a plain question, a |
| @@ -109,6 +109,9 @@ func (ps *pastes) labelOf(r rune) (string, bool) { | |||
| 109 | type Prompt struct { | 109 | type Prompt struct { |
| 110 | Typed string | 110 | Typed string |
| 111 | Pastes map[rune]paste | 111 | Pastes map[rune]paste |
| 112 | + // shown: the conversation already shows it — a message steered into a | ||
| 113 | + // turn that came too late and now runs as the next question (ticket 265). | ||
| 114 | + shown bool | ||
| 112 | } | 115 | } |
| 113 | 116 | ||
| 114 | // promptOf is a Prompt with no paste: a slash command, a plain question, a | 117 | // promptOf is a Prompt with no paste: a slash command, a plain question, a |
modified
internal/tui/turn.go +46 -2 | @@ -122,8 +122,14 @@ type runner struct { | ||
| 122 | 122 | cancelled atomic.Bool |
| 123 | 123 | results chan outcome |
| 124 | 124 | // pending is what was sent during a job, oldest first: each entry runs |
| 125 | - // once the one before it has settled (ticket 155). | |
| 125 | + // once the one before it has settled (ticket 155). During a turn, Enter | |
| 126 | + // steers instead (ticket 265); /queue still lands here. | |
| 126 | 127 | pending []Prompt |
| 128 | + // inbox is the turn in progress's steer inbox (engine.Inbox), nil | |
| 129 | + // between turns; steering is what was pushed into it, oldest first, so | |
| 130 | + // the messages the turn did not take run as the next questions. | |
| 131 | + inbox *engine.Inbox | |
| 132 | + steering []Prompt | |
| 127 | 133 | // asked is the question of the turn in progress, as the model reads it: |
| 128 | 134 | // not in messages until the turn settles, yet the first one ↑ recalls. |
| 129 | 135 | // A turn that fails before answering drops its question from the |
| @@ -188,7 +194,9 @@ func (r *runner) isBusy() bool { return r.busyLabel() != "" } | ||
| 188 | 194 | // typed text only: a pasted block is data the user brought, not a request |
| 189 | 195 | // to attach whatever paths it happens to name. |
| 190 | 196 | func (r *runner) startTurn(p Prompt) { |
| 191 | - r.t.AddUserFull(p.Display(), p.Text()) | |
| 197 | + if !p.shown { | |
| 198 | + r.t.AddUserFull(p.Display(), p.Text()) | |
| 199 | + } | |
| 192 | 200 | // A new question, a new turn: the last one's struggles are history. |
| 193 | 201 | r.struggles.clear() |
| 194 | 202 | expanded, attached := mention.Expand(p.Typed, r.opts.Cwd) |
| @@ -205,6 +213,14 @@ func (r *runner) startTurn(p Prompt) { | ||
| 205 | 213 | r.t.Notice("📎 " + a.Path) |
| 206 | 214 | } |
| 207 | 215 | ctx, cancel := context.WithCancel(context.Background()) |
| 216 | + // Messages sent during the turn reach the model at its next call | |
| 217 | + // (ticket 265): the line says when it got one. | |
| 218 | + r.inbox = engine.NewInbox(func(text string) { | |
| 219 | + r.t.Notice("↪ Steered: " + firstLine(text)) | |
| 220 | + r.wake() | |
| 221 | + }) | |
| 222 | + r.steering = nil | |
| 223 | + ctx = engine.WithSteer(ctx, r.inbox) | |
| 208 | 224 | r.cancel = cancel |
| 209 | 225 | r.cancelled.Store(false) |
| 210 | 226 | r.busy.Store("thinking") |
| @@ -303,9 +319,37 @@ func (r *runner) settle() { | ||
| 303 | 319 | r.watch.stop() |
| 304 | 320 | r.cancel = nil |
| 305 | 321 | r.cancelled.Store(false) |
| 322 | + r.takeBackLateSteers() | |
| 306 | 323 | r.runQueued() |
| 307 | 324 | } |
| 308 | 325 | |
| 326 | +// firstLine is text's first line, with "…" when there is more. | |
| 327 | +func firstLine(text string) string { | |
| 328 | + line, rest, _ := strings.Cut(strings.TrimSpace(text), "\n") | |
| 329 | + if rest != "" { | |
| 330 | + return line + " …" | |
| 331 | + } | |
| 332 | + return line | |
| 333 | +} | |
| 334 | + | |
| 335 | +// takeBackLateSteers closes the finished turn's inbox: what the model never | |
| 336 | +// got — sent after its last call — runs next, before what /queue added. | |
| 337 | +func (r *runner) takeBackLateSteers() { | |
| 338 | + if r.inbox == nil { | |
| 339 | + return | |
| 340 | + } | |
| 341 | + late := len(r.inbox.Close()) | |
| 342 | + if late > 0 && late <= len(r.steering) { | |
| 343 | + back := append([]Prompt(nil), r.steering[len(r.steering)-late:]...) | |
| 344 | + for i := range back { | |
| 345 | + back[i].shown = true | |
| 346 | + } | |
| 347 | + r.pending = append(back, r.pending...) | |
| 348 | + r.t.Notice(fmt.Sprintf("⏳ %d message(s) came after the model's last call — sent as the next question", late)) | |
| 349 | + } | |
| 350 | + r.inbox, r.steering = nil, nil | |
| 351 | +} | |
| 352 | + | |
| 309 | 353 | // runQueued dispatches the queue until a job starts: a command that answers |
| 310 | 354 | // at once (/help, /sessions…) lets the next entry run straight after it. |
| 311 | 355 | func (r *runner) runQueued() { |
| @@ -122,8 +122,14 @@ type runner struct { | |||
| 122 | cancelled atomic.Bool | 122 | cancelled atomic.Bool |
| 123 | results chan outcome | 123 | results chan outcome |
| 124 | // pending is what was sent during a job, oldest first: each entry runs | 124 | // pending is what was sent during a job, oldest first: each entry runs |
| 125 | - // once the one before it has settled (ticket 155). | 125 | + // once the one before it has settled (ticket 155). During a turn, Enter |
| 126 | + // steers instead (ticket 265); /queue still lands here. | ||
| 126 | pending []Prompt | 127 | pending []Prompt |
| 128 | + // inbox is the turn in progress's steer inbox (engine.Inbox), nil | ||
| 129 | + // between turns; steering is what was pushed into it, oldest first, so | ||
| 130 | + // the messages the turn did not take run as the next questions. | ||
| 131 | + inbox *engine.Inbox | ||
| 132 | + steering []Prompt | ||
| 127 | // asked is the question of the turn in progress, as the model reads it: | 133 | // asked is the question of the turn in progress, as the model reads it: |
| 128 | // not in messages until the turn settles, yet the first one ↑ recalls. | 134 | // not in messages until the turn settles, yet the first one ↑ recalls. |
| 129 | // A turn that fails before answering drops its question from the | 135 | // A turn that fails before answering drops its question from the |
| @@ -188,7 +194,9 @@ func (r *runner) isBusy() bool { return r.busyLabel() != "" } | |||
| 188 | // typed text only: a pasted block is data the user brought, not a request | 194 | // typed text only: a pasted block is data the user brought, not a request |
| 189 | // to attach whatever paths it happens to name. | 195 | // to attach whatever paths it happens to name. |
| 190 | func (r *runner) startTurn(p Prompt) { | 196 | func (r *runner) startTurn(p Prompt) { |
| 191 | - r.t.AddUserFull(p.Display(), p.Text()) | 197 | + if !p.shown { |
| 198 | + r.t.AddUserFull(p.Display(), p.Text()) | ||
| 199 | + } | ||
| 192 | // A new question, a new turn: the last one's struggles are history. | 200 | // A new question, a new turn: the last one's struggles are history. |
| 193 | r.struggles.clear() | 201 | r.struggles.clear() |
| 194 | expanded, attached := mention.Expand(p.Typed, r.opts.Cwd) | 202 | expanded, attached := mention.Expand(p.Typed, r.opts.Cwd) |
| @@ -205,6 +213,14 @@ func (r *runner) startTurn(p Prompt) { | |||
| 205 | r.t.Notice("📎 " + a.Path) | 213 | r.t.Notice("📎 " + a.Path) |
| 206 | } | 214 | } |
| 207 | ctx, cancel := context.WithCancel(context.Background()) | 215 | ctx, cancel := context.WithCancel(context.Background()) |
| 216 | + // Messages sent during the turn reach the model at its next call | ||
| 217 | + // (ticket 265): the line says when it got one. | ||
| 218 | + r.inbox = engine.NewInbox(func(text string) { | ||
| 219 | + r.t.Notice("↪ Steered: " + firstLine(text)) | ||
| 220 | + r.wake() | ||
| 221 | + }) | ||
| 222 | + r.steering = nil | ||
| 223 | + ctx = engine.WithSteer(ctx, r.inbox) | ||
| 208 | r.cancel = cancel | 224 | r.cancel = cancel |
| 209 | r.cancelled.Store(false) | 225 | r.cancelled.Store(false) |
| 210 | r.busy.Store("thinking") | 226 | r.busy.Store("thinking") |
| @@ -303,9 +319,37 @@ func (r *runner) settle() { | |||
| 303 | r.watch.stop() | 319 | r.watch.stop() |
| 304 | r.cancel = nil | 320 | r.cancel = nil |
| 305 | r.cancelled.Store(false) | 321 | r.cancelled.Store(false) |
| 322 | + r.takeBackLateSteers() | ||
| 306 | r.runQueued() | 323 | r.runQueued() |
| 307 | } | 324 | } |
| 308 | 325 | ||
| 326 | +// firstLine is text's first line, with "…" when there is more. | ||
| 327 | +func firstLine(text string) string { | ||
| 328 | + line, rest, _ := strings.Cut(strings.TrimSpace(text), "\n") | ||
| 329 | + if rest != "" { | ||
| 330 | + return line + " …" | ||
| 331 | + } | ||
| 332 | + return line | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +// takeBackLateSteers closes the finished turn's inbox: what the model never | ||
| 336 | +// got — sent after its last call — runs next, before what /queue added. | ||
| 337 | +func (r *runner) takeBackLateSteers() { | ||
| 338 | + if r.inbox == nil { | ||
| 339 | + return | ||
| 340 | + } | ||
| 341 | + late := len(r.inbox.Close()) | ||
| 342 | + if late > 0 && late <= len(r.steering) { | ||
| 343 | + back := append([]Prompt(nil), r.steering[len(r.steering)-late:]...) | ||
| 344 | + for i := range back { | ||
| 345 | + back[i].shown = true | ||
| 346 | + } | ||
| 347 | + r.pending = append(back, r.pending...) | ||
| 348 | + r.t.Notice(fmt.Sprintf("⏳ %d message(s) came after the model's last call — sent as the next question", late)) | ||
| 349 | + } | ||
| 350 | + r.inbox, r.steering = nil, nil | ||
| 351 | +} | ||
| 352 | + | ||
| 309 | // runQueued dispatches the queue until a job starts: a command that answers | 353 | // runQueued dispatches the queue until a job starts: a command that answers |
| 310 | // at once (/help, /sessions…) lets the next entry run straight after it. | 354 | // at once (/help, /sessions…) lets the next entry run straight after it. |
| 311 | func (r *runner) runQueued() { | 355 | func (r *runner) runQueued() { |
modified
internal/tui/turn_test.go +81 -4 | @@ -165,13 +165,14 @@ func TestRunnerFailure(t *testing.T) { | ||
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | -// Enter during a turn queues the text (ticket 155): the turn writes its | |
| 169 | -// answer to the end, then the queued question runs. | |
| 168 | +// /queue during a turn queues the question (ticket 155, kept by ticket 265 | |
| 169 | +// when Enter started to steer): the turn writes its answer to the end, then | |
| 170 | +// the queued question runs. | |
| 170 | 171 | func TestRunnerQueuesAQuestionTypedDuringATurn(t *testing.T) { |
| 171 | 172 | m := &fakeModel{hold: make(chan struct{}), answer: "done"} |
| 172 | 173 | r, tr := newTestRunner(t, m) |
| 173 | 174 | r.submit(promptOf("first")) |
| 174 | - r.submit(promptOf("second")) | |
| 175 | + r.submit(promptOf("/queue second")) | |
| 175 | 176 | if r.cancelled.Load() || r.queued() != 1 || r.pending[0].Typed != "second" { |
| 176 | 177 | t.Fatalf("cancelled %v, queue %+v", r.cancelled.Load(), r.pending) |
| 177 | 178 | } |
| @@ -224,7 +225,7 @@ func TestTheQueueRunsInOrderThroughInstantCommands(t *testing.T) { | ||
| 224 | 225 | r, tr := newTestRunner(t, m) |
| 225 | 226 | r.submit(promptOf("first")) |
| 226 | 227 | r.submit(promptOf("/help")) |
| 227 | - r.submit(promptOf("third")) | |
| 228 | + r.submit(promptOf("/queue third")) | |
| 228 | 229 | if r.queued() != 2 || !strings.Contains(notices(tr), "⏳ Queued (2)") { |
| 229 | 230 | t.Fatalf("queue %+v, notices:\n%s", r.pending, notices(tr)) |
| 230 | 231 | } |
| @@ -744,3 +745,79 @@ func TestRunnerNewAndResumeClearThePlans(t *testing.T) { | ||
| 744 | 745 | t.Errorf("after /resume: %s", out) |
| 745 | 746 | } |
| 746 | 747 | } |
| 748 | + | |
| 749 | +// Enter during a turn steers it (ticket 265): the question goes to the | |
| 750 | +// turn's inbox, shows in the conversation at once, and nothing is queued. | |
| 751 | +// A model that makes no further call never takes it: when the turn ends it | |
| 752 | +// runs as the next question — shown once, not twice. | |
| 753 | +func TestEnterDuringATurnSteersAndALateOneRunsNext(t *testing.T) { | |
| 754 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | |
| 755 | + r, tr := newTestRunner(t, m) | |
| 756 | + r.submit(promptOf("first")) | |
| 757 | + r.submit(promptOf("use the v2 API")) | |
| 758 | + if r.queued() != 0 || len(r.steering) != 1 { | |
| 759 | + t.Fatalf("queue %+v, steering %+v", r.pending, r.steering) | |
| 760 | + } | |
| 761 | + if !strings.Contains(notices(tr), "↪ Steering") { | |
| 762 | + t.Errorf("notices:\n%s", notices(tr)) | |
| 763 | + } | |
| 764 | + close(m.hold) | |
| 765 | + waitIdle(t, r) // first settles; the steer came too late: it runs next | |
| 766 | + waitIdle(t, r) | |
| 767 | + if !strings.Contains(notices(tr), "⏳ 1 message(s) came after the model's last call") { | |
| 768 | + t.Errorf("notices:\n%s", notices(tr)) | |
| 769 | + } | |
| 770 | + // system, first, done, use the v2 API, done | |
| 771 | + if m.calls.Load() != 2 || len(r.messages) != 5 || r.messages[3].Text() != "use the v2 API" { | |
| 772 | + t.Errorf("calls %d, history %d", m.calls.Load(), len(r.messages)) | |
| 773 | + } | |
| 774 | + users := 0 | |
| 775 | + for _, e := range tr.Entries() { | |
| 776 | + if e.Kind == KindUser && strings.Contains(e.Text, "use the v2 API") { | |
| 777 | + users++ | |
| 778 | + } | |
| 779 | + } | |
| 780 | + if users != 1 { | |
| 781 | + t.Errorf("the steered question is shown %d times, want once", users) | |
| 782 | + } | |
| 783 | + if r.inbox != nil || r.steering != nil { | |
| 784 | + t.Error("the turn's inbox outlived it") | |
| 785 | + } | |
| 786 | +} | |
| 787 | + | |
| 788 | +// The inbox a turn gets is the one its model call reads: what Enter pushes | |
| 789 | +// is in it, ready for the engine's next call. | |
| 790 | +func TestSteerGoesToTheTurnsInbox(t *testing.T) { | |
| 791 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | |
| 792 | + r, _ := newTestRunner(t, m) | |
| 793 | + r.submit(promptOf("first")) | |
| 794 | + inbox := r.inbox | |
| 795 | + r.submit(promptOf("and the docs")) | |
| 796 | + close(m.hold) | |
| 797 | + waitIdle(t, r) | |
| 798 | + waitIdle(t, r) | |
| 799 | + if inbox == nil || inbox.Push("x") { | |
| 800 | + t.Fatal("the turn had no inbox, or it was not closed when the turn ended") | |
| 801 | + } | |
| 802 | +} | |
| 803 | + | |
| 804 | +// A slash command during a turn is never steered: it waits in the queue. | |
| 805 | +// /queue with nothing after it says what it needs; idle, /queue runs the | |
| 806 | +// question at once. | |
| 807 | +func TestSlashCommandsAreNotSteered(t *testing.T) { | |
| 808 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | |
| 809 | + r, tr := newTestRunner(t, m) | |
| 810 | + r.submit(promptOf("first")) | |
| 811 | + r.submit(promptOf("/sessions")) | |
| 812 | + r.submit(promptOf("/queue")) | |
| 813 | + if r.queued() != 1 || len(r.steering) != 0 || !strings.Contains(notices(tr), "/queue needs a question") { | |
| 814 | + t.Fatalf("queue %+v, steering %+v, notices:\n%s", r.pending, r.steering, notices(tr)) | |
| 815 | + } | |
| 816 | + close(m.hold) | |
| 817 | + waitIdle(t, r) | |
| 818 | + r.submit(promptOf("/queue now")) | |
| 819 | + waitIdle(t, r) | |
| 820 | + if len(r.messages) != 5 || r.messages[3].Text() != "now" { | |
| 821 | + t.Errorf("idle /queue: history %d", len(r.messages)) | |
| 822 | + } | |
| 823 | +} | |
| @@ -165,13 +165,14 @@ func TestRunnerFailure(t *testing.T) { | |||
| 165 | } | 165 | } |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | -// Enter during a turn queues the text (ticket 155): the turn writes its | 168 | +// /queue during a turn queues the question (ticket 155, kept by ticket 265 |
| 169 | -// answer to the end, then the queued question runs. | 169 | +// when Enter started to steer): the turn writes its answer to the end, then |
| 170 | +// the queued question runs. | ||
| 170 | func TestRunnerQueuesAQuestionTypedDuringATurn(t *testing.T) { | 171 | func TestRunnerQueuesAQuestionTypedDuringATurn(t *testing.T) { |
| 171 | m := &fakeModel{hold: make(chan struct{}), answer: "done"} | 172 | m := &fakeModel{hold: make(chan struct{}), answer: "done"} |
| 172 | r, tr := newTestRunner(t, m) | 173 | r, tr := newTestRunner(t, m) |
| 173 | r.submit(promptOf("first")) | 174 | r.submit(promptOf("first")) |
| 174 | - r.submit(promptOf("second")) | 175 | + r.submit(promptOf("/queue second")) |
| 175 | if r.cancelled.Load() || r.queued() != 1 || r.pending[0].Typed != "second" { | 176 | if r.cancelled.Load() || r.queued() != 1 || r.pending[0].Typed != "second" { |
| 176 | t.Fatalf("cancelled %v, queue %+v", r.cancelled.Load(), r.pending) | 177 | t.Fatalf("cancelled %v, queue %+v", r.cancelled.Load(), r.pending) |
| 177 | } | 178 | } |
| @@ -224,7 +225,7 @@ func TestTheQueueRunsInOrderThroughInstantCommands(t *testing.T) { | |||
| 224 | r, tr := newTestRunner(t, m) | 225 | r, tr := newTestRunner(t, m) |
| 225 | r.submit(promptOf("first")) | 226 | r.submit(promptOf("first")) |
| 226 | r.submit(promptOf("/help")) | 227 | r.submit(promptOf("/help")) |
| 227 | - r.submit(promptOf("third")) | 228 | + r.submit(promptOf("/queue third")) |
| 228 | if r.queued() != 2 || !strings.Contains(notices(tr), "⏳ Queued (2)") { | 229 | if r.queued() != 2 || !strings.Contains(notices(tr), "⏳ Queued (2)") { |
| 229 | t.Fatalf("queue %+v, notices:\n%s", r.pending, notices(tr)) | 230 | t.Fatalf("queue %+v, notices:\n%s", r.pending, notices(tr)) |
| 230 | } | 231 | } |
| @@ -744,3 +745,79 @@ func TestRunnerNewAndResumeClearThePlans(t *testing.T) { | |||
| 744 | t.Errorf("after /resume: %s", out) | 745 | t.Errorf("after /resume: %s", out) |
| 745 | } | 746 | } |
| 746 | } | 747 | } |
| 748 | + | ||
| 749 | +// Enter during a turn steers it (ticket 265): the question goes to the | ||
| 750 | +// turn's inbox, shows in the conversation at once, and nothing is queued. | ||
| 751 | +// A model that makes no further call never takes it: when the turn ends it | ||
| 752 | +// runs as the next question — shown once, not twice. | ||
| 753 | +func TestEnterDuringATurnSteersAndALateOneRunsNext(t *testing.T) { | ||
| 754 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | ||
| 755 | + r, tr := newTestRunner(t, m) | ||
| 756 | + r.submit(promptOf("first")) | ||
| 757 | + r.submit(promptOf("use the v2 API")) | ||
| 758 | + if r.queued() != 0 || len(r.steering) != 1 { | ||
| 759 | + t.Fatalf("queue %+v, steering %+v", r.pending, r.steering) | ||
| 760 | + } | ||
| 761 | + if !strings.Contains(notices(tr), "↪ Steering") { | ||
| 762 | + t.Errorf("notices:\n%s", notices(tr)) | ||
| 763 | + } | ||
| 764 | + close(m.hold) | ||
| 765 | + waitIdle(t, r) // first settles; the steer came too late: it runs next | ||
| 766 | + waitIdle(t, r) | ||
| 767 | + if !strings.Contains(notices(tr), "⏳ 1 message(s) came after the model's last call") { | ||
| 768 | + t.Errorf("notices:\n%s", notices(tr)) | ||
| 769 | + } | ||
| 770 | + // system, first, done, use the v2 API, done | ||
| 771 | + if m.calls.Load() != 2 || len(r.messages) != 5 || r.messages[3].Text() != "use the v2 API" { | ||
| 772 | + t.Errorf("calls %d, history %d", m.calls.Load(), len(r.messages)) | ||
| 773 | + } | ||
| 774 | + users := 0 | ||
| 775 | + for _, e := range tr.Entries() { | ||
| 776 | + if e.Kind == KindUser && strings.Contains(e.Text, "use the v2 API") { | ||
| 777 | + users++ | ||
| 778 | + } | ||
| 779 | + } | ||
| 780 | + if users != 1 { | ||
| 781 | + t.Errorf("the steered question is shown %d times, want once", users) | ||
| 782 | + } | ||
| 783 | + if r.inbox != nil || r.steering != nil { | ||
| 784 | + t.Error("the turn's inbox outlived it") | ||
| 785 | + } | ||
| 786 | +} | ||
| 787 | + | ||
| 788 | +// The inbox a turn gets is the one its model call reads: what Enter pushes | ||
| 789 | +// is in it, ready for the engine's next call. | ||
| 790 | +func TestSteerGoesToTheTurnsInbox(t *testing.T) { | ||
| 791 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | ||
| 792 | + r, _ := newTestRunner(t, m) | ||
| 793 | + r.submit(promptOf("first")) | ||
| 794 | + inbox := r.inbox | ||
| 795 | + r.submit(promptOf("and the docs")) | ||
| 796 | + close(m.hold) | ||
| 797 | + waitIdle(t, r) | ||
| 798 | + waitIdle(t, r) | ||
| 799 | + if inbox == nil || inbox.Push("x") { | ||
| 800 | + t.Fatal("the turn had no inbox, or it was not closed when the turn ended") | ||
| 801 | + } | ||
| 802 | +} | ||
| 803 | + | ||
| 804 | +// A slash command during a turn is never steered: it waits in the queue. | ||
| 805 | +// /queue with nothing after it says what it needs; idle, /queue runs the | ||
| 806 | +// question at once. | ||
| 807 | +func TestSlashCommandsAreNotSteered(t *testing.T) { | ||
| 808 | + m := &fakeModel{hold: make(chan struct{}), answer: "done"} | ||
| 809 | + r, tr := newTestRunner(t, m) | ||
| 810 | + r.submit(promptOf("first")) | ||
| 811 | + r.submit(promptOf("/sessions")) | ||
| 812 | + r.submit(promptOf("/queue")) | ||
| 813 | + if r.queued() != 1 || len(r.steering) != 0 || !strings.Contains(notices(tr), "/queue needs a question") { | ||
| 814 | + t.Fatalf("queue %+v, steering %+v, notices:\n%s", r.pending, r.steering, notices(tr)) | ||
| 815 | + } | ||
| 816 | + close(m.hold) | ||
| 817 | + waitIdle(t, r) | ||
| 818 | + r.submit(promptOf("/queue now")) | ||
| 819 | + waitIdle(t, r) | ||
| 820 | + if len(r.messages) != 5 || r.messages[3].Text() != "now" { | ||
| 821 | + t.Errorf("idle /queue: history %d", len(r.messages)) | ||
| 822 | + } | ||
| 823 | +} | ||
modified
internal/tui/view_test.go +2 -2 | @@ -163,8 +163,8 @@ func TestPasteNeverSends(t *testing.T) { | ||
| 163 | 163 | func TestPicker(t *testing.T) { |
| 164 | 164 | hs := newHarness(t, 70, 20) |
| 165 | 165 | hs.typeText("/") |
| 166 | - if got := len(hs.v.choices()); got != 10 { | |
| 167 | - t.Fatalf("%d choices on '/', want 10", got) | |
| 166 | + if got := len(hs.v.choices()); got != 11 { | |
| 167 | + t.Fatalf("%d choices on '/', want 11", got) | |
| 168 | 168 | } |
| 169 | 169 | if text := hs.screenText(); !strings.Contains(text, "/resume") || !strings.Contains(text, "Continue a stored session") { |
| 170 | 170 | t.Errorf("picker not drawn:\n%s", text) |
| @@ -163,8 +163,8 @@ func TestPasteNeverSends(t *testing.T) { | |||
| 163 | func TestPicker(t *testing.T) { | 163 | func TestPicker(t *testing.T) { |
| 164 | hs := newHarness(t, 70, 20) | 164 | hs := newHarness(t, 70, 20) |
| 165 | hs.typeText("/") | 165 | hs.typeText("/") |
| 166 | - if got := len(hs.v.choices()); got != 10 { | 166 | + if got := len(hs.v.choices()); got != 11 { |
| 167 | - t.Fatalf("%d choices on '/', want 10", got) | 167 | + t.Fatalf("%d choices on '/', want 11", got) |
| 168 | } | 168 | } |
| 169 | if text := hs.screenText(); !strings.Contains(text, "/resume") || !strings.Contains(text, "Continue a stored session") { | 169 | if text := hs.screenText(); !strings.Contains(text, "/resume") || !strings.Contains(text, "Continue a stored session") { |
| 170 | t.Errorf("picker not drawn:\n%s", text) | 170 | t.Errorf("picker not drawn:\n%s", text) |