Skip to content

[Bug]: ACP session cwd is used for tool execution but not for project context file discovery #11515

@bkbxk

Description

@bkbxk

Bug Description

In ACP mode, the session/workspace cwd appears to be used for tool execution, but not for system-prompt project context discovery.

This creates an inconsistency:

  • ACP tools run against the editor session's workspace cwd
  • but auto-loaded project context files such as .hermes.md, AGENTS.md, CLAUDE.md, and .cursorrules do not appear to be resolved from that same ACP session cwd

As a result, Hermes in ACP mode may execute tools in the correct editor workspace while following project instructions loaded from a different directory, or from the process cwd / global TERMINAL_CWD.

Steps to Reproduce

  1. Start Hermes in ACP mode from a directory that is different from the editor workspace.
  2. Open a project in Zed / VS Code / JetBrains with a workspace-local AGENTS.md or .hermes.md.
  3. Start a new ACP session for that workspace.
  4. Ask Hermes to inspect files or run tools in the workspace.
  5. Observe that tool behavior follows the ACP session cwd, but project-context auto-loading does not appear to be explicitly tied to the ACP session cwd.

Expected Behavior

ACP sessions should use the same workspace cwd for both:

  • tool execution
  • project context file discovery during system prompt construction

If the ACP session cwd is the editor workspace, Hermes should auto-discover project context files from that same directory tree.

Actual Behavior

ACP session cwd is registered as a task-level tool override, so tools are session-aware.

However, system prompt construction in run_agent.py uses:

  • os.getenv("TERMINAL_CWD"), or
  • falls back to os.getcwd()

I could not find ACP code that explicitly passes the session cwd into build_context_files_prompt(...) or synchronizes ACP session cwd into TERMINAL_CWD before system prompt construction.

This suggests ACP can run tools in one workspace while loading project context from another directory.

Affected Component

  • Agent Core (conversation loop, context compression, memory)
  • Tools (terminal, file ops, web, code execution, etc.)
  • Other

Messaging Platform (if gateway-related)

  • N/A (CLI only)

Debug Report

Not attached. This report is based on source analysis rather than a runtime crash.

Operating System

Windows 11

Python Version

Unknown

Hermes Version

Local repo checkout on main, currently behind origin/main by 7 commits at time of inspection.

Additional Logs / Traceback (optional)

None.

Root Cause Analysis (optional)

Relevant code paths:

  1. ACP session cwd is registered for tools:
  • acp_adapter/session.py
    • _register_task_cwd(task_id, cwd) calls tools.terminal_tool.register_task_env_overrides(task_id, {"cwd": cwd})
  • tools/terminal_tool.py
    • terminal_tool(...) resolves cwd via overrides.get("cwd") or config["cwd"]
  1. Project context discovery during system prompt build:
  • run_agent.py
    • _build_system_prompt()
    • uses os.getenv("TERMINAL_CWD") or None
    • then calls build_context_files_prompt(cwd=_context_cwd, skip_soul=_soul_loaded)
  1. Context file loader fallback:
  • agent/prompt_builder.py
    • build_context_files_prompt(cwd=None, ...)
    • if cwd is None, it falls back to os.getcwd()

I could not find code in ACP session creation / prompt handling that:

  • passes state.cwd directly into project context loading, or
  • temporarily binds ACP session cwd into TERMINAL_CWD before prompt construction

So ACP has two cwd paths:

  • session-aware cwd for tools
  • global/process cwd for prompt context discovery

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/acpAgent Communication Protocol adaptercomp/agentCore agent loop, run_agent.py, prompt buildertype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions