fix(prompt): show configured working directory in system prompt (closes #24882, #24969, #27383, #29265)
This commit is contained in:
parent
2564760d7a
commit
16047655b5
2 changed files with 26 additions and 1 deletions
|
|
@ -14,6 +14,7 @@ from pathlib import Path
|
|||
from hermes_constants import get_hermes_home, get_skills_dir, is_wsl
|
||||
from typing import Optional
|
||||
|
||||
from agent.runtime_cwd import resolve_agent_cwd
|
||||
from agent.skill_utils import (
|
||||
extract_skill_conditions,
|
||||
extract_skill_description,
|
||||
|
|
@ -802,7 +803,7 @@ def build_environment_hints() -> str:
|
|||
|
||||
host_lines.append(f"User home directory: {os.path.expanduser('~')}")
|
||||
try:
|
||||
host_lines.append(f"Current working directory: {os.getcwd()}")
|
||||
host_lines.append(f"Current working directory: {resolve_agent_cwd()}")
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import builtins
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
|
@ -18,6 +19,7 @@ from agent.prompt_builder import (
|
|||
build_skills_system_prompt,
|
||||
build_nous_subscription_prompt,
|
||||
build_context_files_prompt,
|
||||
build_environment_hints,
|
||||
CONTEXT_FILE_MAX_CHARS,
|
||||
DEFAULT_AGENT_IDENTITY,
|
||||
TOOL_USE_ENFORCEMENT_GUIDANCE,
|
||||
|
|
@ -1248,3 +1250,25 @@ class TestOpenAIModelExecutionGuidance:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
class TestBuildEnvironmentHints:
|
||||
"""The cwd line must reflect the configured TERMINAL_CWD, not the daemon launch dir.
|
||||
|
||||
Regression for the gateway working-directory cluster (#24882, #24969, #27383, #29265):
|
||||
gateway/cron set TERMINAL_CWD, but build_environment_hints emitted os.getcwd() — telling
|
||||
the model the wrong directory.
|
||||
"""
|
||||
|
||||
def test_uses_terminal_cwd_when_set(self, monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("TERMINAL_ENV", raising=False)
|
||||
monkeypatch.setenv("TERMINAL_CWD", str(tmp_path))
|
||||
monkeypatch.chdir(os.path.expanduser("~"))
|
||||
assert f"Current working directory: {tmp_path}" in build_environment_hints()
|
||||
|
||||
def test_falls_back_to_launch_dir_when_unset(self, monkeypatch, tmp_path):
|
||||
# The #19242 local-CLI contract: no TERMINAL_CWD → the launch dir.
|
||||
monkeypatch.delenv("TERMINAL_ENV", raising=False)
|
||||
monkeypatch.delenv("TERMINAL_CWD", raising=False)
|
||||
monkeypatch.chdir(tmp_path)
|
||||
assert f"Current working directory: {tmp_path}" in build_environment_hints()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue