termmate icon indicating copy to clipboard operation
termmate copied to clipboard

Workspace folders are not preserved after switching or reloading an agent

Open thiblizz opened this issue 4 months ago • 1 comments

Summary

When a chat starts, ChatSession passes add_dirs to the initial AgentThread.

However, switch_agent() and reload_agent() create a replacement AgentThread without passing add_dirs. Since the default is an empty list, additional workspace folders are no longer available after switching providers or reloading the agent.

_reconnect_chat_view() does not cover these cases. It creates a new ChatSession after a plugin or Sublime restart, while provider switching and agent reloads keep the existing ChatSession and replace only its AgentThread.

Steps to reproduce

  1. Open a project with multiple workspace folders.
  2. Enable:
{
    "share_workspace_folders": true
}
  1. Start a TermMate chat.
  2. Confirm that the agent can access a file in a secondary workspace folder.
  3. Switch providers or resume an existing session.
  4. Ask the agent to access the same file again.

Expected behavior

The replacement agent retains access to the currently shared workspace folders.

Actual behavior

The secondary workspace folders are no longer available to the replacement agent.

Suggested fix

Recompute the current workspace context in both switch_agent() and reload_agent():

share_folders = settings.get("share_workspace_folders", False)
cwd = get_best_dir(self.chat_view)
add_dirs = get_all_folders(self.chat_view) if share_folders else []

self.cwd = cwd
self.add_dirs = add_dirs

self.agent_thread = AgentThread(
    cwd,
    self._handle_agent_message,
    cli_path=cli_path,
    anthropic_config=anthropic_config,
    add_dirs=add_dirs
)

Recomputing is preferable to reusing the original self.add_dirs, since the workspace folders or share_workspace_folders setting may have changed since the chat was created.

thiblizz avatar Jul 25 '26 22:07 thiblizz

Issue #4 is fixed in the current main branch. Closing as resolved.

thiblizz avatar Nov 06 '26 11:11 thiblizz