Skip to content

fix(prompt): honor TERMINAL_CWD in local environment hints - #31206

Closed
ArnBdev wants to merge 1 commit into
NousResearch:mainfrom
ArnBdev:fix/prompt-terminal-cwd
Closed

ArnBdev wants to merge 1 commit into
NousResearch:mainfrom
ArnBdev:fix/prompt-terminal-cwd

Conversation

@ArnBdev

@ArnBdev ArnBdev commented May 24, 2026

Copy link
Copy Markdown

Summary

Use TERMINAL_CWD when building local environment hints so the prompt reports the same current working directory that the terminal tool will use by default.

If TERMINAL_CWD is not set, the existing os.getcwd() behavior is preserved.

Why

Long-running Hermes processes can be launched from one directory while a session, cron job, worktree, or worker is configured to run terminal commands from another directory.

In that case, the terminal tool may correctly default to TERMINAL_CWD, but the prompt still reports the process cwd from os.getcwd(). This can mislead the model into passing the stale prompt cwd back as an explicit workdir, overriding the intended terminal default.

Changes

  • Prefer TERMINAL_CWD over os.getcwd() in build_environment_hints().
  • Expand ~ in the reported cwd for consistency.
  • Add a regression test covering local-backend environment hints with TERMINAL_CWD.

Test plan

python -m pytest tests/agent/test_prompt_builder.py::TestEnvironmentHints::test_build_environment_hints_uses_terminal_cwd_for_local_backend -q -o 'addopts='

Also run together with the related delegate timeout diagnostic tests:

python -m pytest \
  tests/agent/test_prompt_builder.py::TestEnvironmentHints::test_build_environment_hints_uses_terminal_cwd_for_local_backend \
  tests/tools/test_delegate_subagent_timeout_diagnostic.py \
  -q -o 'addopts='

Result:

8 passed, 1 warning

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists labels May 24, 2026
@alt-glitch

Copy link
Copy Markdown

Duplicate of #24888 — same fix: prefer TERMINAL_CWD over os.getcwd() in build_environment_hints() in prompt_builder.py. Multiple competing PRs for this fix: #24888, #24957, #24985, #27488, #29365.

@ArnBdev

ArnBdev commented May 24, 2026

Copy link
Copy Markdown
Author

Closing at contributor request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants