Skip to content

fix(opencode-plugin): per-session workflow toggle with agent filter and TUI sidebar sync - #257

Closed
udondan wants to merge 11 commits into
codemcp:mainfrom
udondan:main
Closed

udondan wants to merge 11 commits into
codemcp:mainfrom
udondan:main

Conversation

@udondan

@udondan udondan commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR makes three significant changes:

  1. Workflow tools are now suppressed for non-whitelisted agents. Previously the tools were always visible to every agent, causing agents to spontaneously call them when not intended. The plugin now injects a system prompt telling non-whitelisted agents to ignore the tools entirely.

  2. WORKFLOW_ACTIVE_AGENTS replaces WORKFLOW=off. The old boolean env var is gone. The new one accepts a comma-separated list of agent names that should have workflows active. When unset, workflows are active for all agents (same as before).

  3. /workflow on|off is now truly per-session. Previously the toggle was global. It now only affects the current session and correctly syncs the TUI sidebar state across component remounts.

Changes

opencode-plugin

  • Suppress workflow tools for non-whitelisted agents via experimental.chat.system.transform
  • Replace WORKFLOW=off with WORKFLOW_ACTIVE_AGENTS (comma-separated agent whitelist)
  • Replace global workflowsEnabled flag with per-session sessionEnabled map
  • Add isActiveForAgent() to evaluate session override + agent filter in order
  • Handle /workflow on by injecting a counter-instruction to rescind any prior suppression
  • Bound sessionEnabled and sessionAgents maps to 50 entries with LRU eviction

opencode-tui-plugin

  • Fix sidebar not reflecting /workflow on|off after remount: move override state to
    a module-level sessionOverrideMap so it survives component remounts
  • Listen to command.executed event to update override signal in real time
  • sessionOverrideMap is a bounded LRU map (500 entries)

Docs

  • Update /workflow command docs to reflect per-session behaviour and WORKFLOW_ACTIVE_AGENTS
  • Update opencode-plugin README with configuration section

udondan and others added 10 commits April 2, 2026 21:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Use delete+set pattern in setSessionEnabled and setSessionAgent to
  refresh insertion order so active sessions are not prematurely evicted
- Normalize agent name to lowercase in TUI message.updated handler to
  match filter comparison in isActiveForAgent
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 2, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the OpenCode workflows integration to (1) restrict workflow behavior to a configured set of agents, (2) make /workflow on|off a per-session toggle, and (3) keep the TUI sidebar’s workflow widget visibility in sync across remounts.

Changes:

  • Add WORKFLOW_ACTIVE_AGENTS (comma-separated whitelist) and use it to gate hooks/tools, plus suppress tool usage for inactive agents via experimental.chat.system.transform.
  • Replace the prior global workflow toggle with per-session enable/disable state and propagate /workflow on|off effects through the system prompt + UI.
  • Update TUI sidebar to persist per-session override across remounts and react to command execution events; update docs and tests accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/opencode-tui-plugin/workflows-phase.tsx Adds agent filtering + per-session overrides (LRU) and listens for command events to keep sidebar visibility in sync.
packages/opencode-tui-plugin/README.md Documents WORKFLOW_ACTIVE_AGENTS configuration for the sidebar widget.
packages/opencode-plugin/test/e2e/plugin.test.ts Replaces WORKFLOW=off tests with WORKFLOW_ACTIVE_AGENTS coverage (hook gating + suppression behavior).
packages/opencode-plugin/src/plugin.ts Implements agent filtering, per-session toggles, session agent tracking, and system prompt suppression for inactive agents.
packages/opencode-plugin/README.md Documents new env var + session override behavior.
.opencode/commands/workflow.md Updates /workflow command docs for per-session behavior and new env var.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode-tui-plugin/workflows-phase.tsx Outdated
Comment thread packages/opencode-plugin/src/plugin.ts
Comment thread packages/opencode-plugin/src/plugin.ts Outdated
Comment thread packages/opencode-plugin/README.md Outdated
mrsimpson added a commit that referenced this pull request Apr 2, 2026
Eliminates redundant session-level state caches from PR #257 by implementing
pure per-agent filtering based on WORKFLOW_AGENTS environment variable.

## Changes

### Plugin (packages/opencode-plugin/)
- Replace WORKFLOW_ACTIVE_AGENTS env var with WORKFLOW_AGENTS for clarity
- Remove sessionEnabled, sessionAgents, and pendingActivation maps
- Eliminate command.execute.before hook (YAGNI - not needed for pure filtering)
- Simplify agent filtering: evaluate on every chat.message hook
- Tools throw clear error if agent not in WORKFLOW_AGENTS filter

### TUI Plugin (packages/opencode-tui-plugin/)
- Add WORKFLOW_AGENTS env var parsing
- Implement reactive isActive() memo based on agent + filter
- Widget visibility updates automatically on agent switches
- No session-level state map needed

### Tests (packages/opencode-plugin/test/e2e/)
- Replace WORKFLOW=off session toggle tests with WORKFLOW_AGENTS filter tests
- Add 5 comprehensive tests for agent filtering behavior
- All 53 tests passing

### Documentation
- Update opencode-plugin README with Configuration section
- Update TUI plugin README with agent-based visibility explanation
- Delete obsolete .opencode/commands/workflow.md

## Benefits
- Simpler architecture: no session state caches or override maps
- Clearer semantics: agent filter is single source of truth
- Automatic behavior: TUI responds reactively to agent changes
- Better UX: clear error messages for non-whitelisted agents

Co-authored-by: udondan <udondan@users.noreply.github.com>
@mrsimpson

Copy link
Copy Markdown
Collaborator

superseeded by #259

@mrsimpson mrsimpson closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants