Skip to content

Commit a344a1c

Browse files
feat: use session.working_dir capability for path resolution (microsoft#4)
* feat: use session.working_dir capability for path resolution Part of the unified working directory capability feature. When Amplifier runs as a backend service (web app), Path.cwd() returns the server's directory instead of the user's project directory. This change queries the session.working_dir capability registered by amplifier-foundation during session creation, falling back to Path.cwd() for backward compatibility. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> * docs: document session.working_dir capability usage Explains how the module uses the session.working_dir coordinator capability for path resolution, with fallback to Path.cwd() for backward compatibility. Critical for server/web deployments. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --------- Co-authored-by: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent 0d8d290 commit a344a1c

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • modules/hooks-python-check/amplifier_module_hooks_python_check

modules/hooks-python-check/amplifier_module_hooks_python_check/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def total_issues(self) -> int:
5858
class PythonCheckHooks:
5959
"""Hook handlers for automatic Python quality checking."""
6060

61-
def __init__(self, config: dict[str, Any] | None = None):
61+
def __init__(self, config: dict[str, Any] | None = None, working_dir: Path | None = None):
6262
"""Initialize hooks with configuration.
6363
6464
Args:
@@ -70,9 +70,11 @@ def __init__(self, config: dict[str, Any] | None = None):
7070
- checks: list[str] (default: all) - which checks to run
7171
- verbosity: str (default: "normal") - "minimal", "normal", "detailed"
7272
- show_clean: bool (default: True) - show clean pass indicator
73+
working_dir: Working directory for path resolution (falls back to cwd)
7374
"""
7475
config = config or {}
7576
self.enabled = config.get("enabled", True)
77+
self.working_dir = working_dir or Path.cwd()
7678
self.file_patterns = config.get("file_patterns", ["*.py"])
7779
self.report_level = config.get("report_level", "warning")
7880
self.auto_inject = config.get("auto_inject", True)
@@ -112,7 +114,7 @@ def _get_relative_path(self, file_path: str) -> str:
112114
"""Convert absolute path to relative path for display."""
113115
try:
114116
path = Path(file_path)
115-
cwd = Path.cwd()
117+
cwd = self.working_dir
116118

117119
# If file is under cwd, show relative path
118120
if path.is_absolute():
@@ -394,8 +396,17 @@ async def mount(coordinator: Any, config: dict[str, Any] | None = None) -> dict[
394396
395397
Returns:
396398
Module metadata
399+
400+
Note:
401+
Retrieves 'session.working_dir' capability for path resolution,
402+
falling back to cwd. This handles server deployments where the
403+
process cwd differs from the user's project directory.
397404
"""
398-
hooks = PythonCheckHooks(config)
405+
# Get working_dir from capability (for server deployments where cwd is wrong)
406+
working_dir_str = coordinator.get_capability("session.working_dir")
407+
working_dir = Path(working_dir_str) if working_dir_str else None
408+
409+
hooks = PythonCheckHooks(config, working_dir=working_dir)
399410

400411
# Register the post-tool hook
401412
coordinator.hooks.register(

0 commit comments

Comments
 (0)