v2.24.0 — Per-Agent State Isolation
Fix: Cross-Agent Instance Contamination
When multiple Cowork agents/tasks share a single MCP server process, selecting a Unity instance in one agent would override the selection for all other agents. For example, Agent A targeting ProjectA and Agent B targeting ProjectB would interfere — Agent A's commands could route to ProjectB after Agent B selected it.
Root Cause
Instance selection state was stored in shared global variables. Since all agents share a single MCP stdio process, any agent's selectInstance() call would overwrite the global state for everyone.
Fix
All shared state variables converted to per-agent Map<agentId, value>:
_agentInstances— which Unity instance each agent is targeting_agentSelectionRequired— whether each agent still needs to pick an instance_contextInjectedPerAgent— whether project context was auto-injected for each agent_discoveryDonePerAgent— whether instance discovery ran for each agent
Each tool handler now calls setCurrentAgent(agentId) before execution, ensuring all state reads/writes target the correct agent's Map entry. The MCP stdio transport processes requests sequentially (no concurrency), so this "set current agent before handler" pattern is safe.
Files Changed
src/instance-discovery.js— Per-agent state Maps,setCurrentAgent()exportsrc/index.js— Per-agent context/discovery Maps,setCurrentAgent()wiring in tool handler