Commit 3890751
committed
fix: restore correct agent context after implicit compaction in proceed_to_phase
## High level changes
- `plugin.ts`: Added `lastKnownAgent` variable that caches the last enabled agent name seen in `chat.message`
- `plugin.ts`: Post-compaction `promptAsync` now passes `agent: lastKnownAgent` in the request body so the continue message runs under the original workflow agent
- `plugin.ts`: Added `postCompactionAutoResume` flag set on `session.compacted` to bypass the agent filter for OpenCode's own auto-continue message
- `plugin.ts`: `chat.message` hook checks `bypassAgentFilter` before the `isAgentEnabled` guard so phase instructions are injected instead of a suppression/no-workflow notice
## Motivation
After `proceed_to_phase` triggers implicit compaction, OpenCode resumes the session using its default agent (e.g. `build`) rather than the original workflow agent. This caused two problems:
1. OpenCode's built-in auto-continue `chat.message` arrived with agent `build`, hit the `WORKFLOW_AGENTS` filter, and injected "No Active Workflow Detected" instead of phase instructions.
2. The plugin's own follow-up `promptAsync` (sent on `session.idle`) also omitted the agent field, so it too ran under the wrong agent, losing system prompt and tool access.
## Details
- `lastKnownAgent` is only updated when `isAgentEnabled` is true, ensuring a subagent name (e.g. `general`, `explore`) never overwrites the cached workflow agent.
- `postCompactionAutoResume` is set to `true` on `session.compacted` and consumed (set back to `false`) by the very next `chat.message` invocation. This is a one-shot bypass: it covers exactly OpenCode's implicit auto-continue turn and nothing more.
- The `promptAsync` body now spreads `{ agent: lastKnownAgent }` when a cached agent is available. `PromptInput.agent` is an optional string field in the OpenCode API, so this is a safe additive change with no effect when `lastKnownAgent` is `null`.1 parent ab45ac8 commit 3890751
1 file changed
Lines changed: 41 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
179 | 189 | | |
180 | 190 | | |
181 | 191 | | |
| |||
305 | 315 | | |
306 | 316 | | |
307 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
308 | 325 | | |
309 | 326 | | |
310 | 327 | | |
| |||
315 | 332 | | |
316 | 333 | | |
317 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
318 | 348 | | |
319 | 349 | | |
320 | 350 | | |
321 | 351 | | |
322 | 352 | | |
323 | 353 | | |
324 | 354 | | |
325 | | - | |
| 355 | + | |
326 | 356 | | |
327 | 357 | | |
328 | 358 | | |
| |||
560 | 590 | | |
561 | 591 | | |
562 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
563 | 598 | | |
564 | 599 | | |
565 | 600 | | |
| |||
614 | 649 | | |
615 | 650 | | |
616 | 651 | | |
617 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
618 | 656 | | |
619 | 657 | | |
620 | 658 | | |
621 | 659 | | |
622 | 660 | | |
623 | 661 | | |
624 | 662 | | |
| 663 | + | |
625 | 664 | | |
626 | 665 | | |
627 | 666 | | |
| |||
0 commit comments