Put the release's tools on PATH of every claude the loop starts, and name them bare in the prose
CI / tests (pull_request) Successful in 4m36s

This commit is contained in:
2026-12-03 12:49:56 +01:00
parent fb1dd763e2
commit 0653c2744e
64 changed files with 306 additions and 169 deletions
+10
View File
@@ -2,6 +2,7 @@
import dataclasses
from collections.abc import Mapping
import os
import pathlib
# The release root: the folder the running code ships in, with bin/, skills/ and agents/.
@@ -17,6 +18,15 @@ CONFIG_FOLDER = ".claude-projects"
STATE_FOLDER = ".local/state"
def with_release_tools(env: Mapping[str, str]) -> dict[str, str]:
"""env with the release's tools first on `PATH`: what every claude the loop starts runs in, so its Bash tool and its hooks find each tool by its bare name."""
tools = str(RELEASE_ROOT / "bin")
rest = env.get("PATH", "")
if rest.split(os.pathsep)[0] == tools:
return dict(env)
return {**env, "PATH": f"{tools}{os.pathsep}{rest}" if rest else tools}
def state_folder(env: Mapping[str, str], home: pathlib.Path) -> pathlib.Path:
"""The state folder of a tool that honours `XDG_STATE_HOME`."""
return pathlib.Path(env.get("XDG_STATE_HOME") or home / STATE_FOLDER)
+24
View File
@@ -0,0 +1,24 @@
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from loop_state.paths import RELEASE_ROOT, with_release_tools
TOOLS = str(RELEASE_ROOT / "bin")
class WithReleaseTools(unittest.TestCase):
def test_puts_the_releases_tools_first_on_path_and_keeps_every_other_variable(self):
self.assertEqual(with_release_tools({"PATH": "/usr/bin:/bin", "HOME": "/h"}), {"PATH": f"{TOOLS}:/usr/bin:/bin", "HOME": "/h"})
def test_leaves_a_path_that_already_opens_with_the_tools_as_it_is(self):
self.assertEqual(with_release_tools({"PATH": f"{TOOLS}:/bin"}), {"PATH": f"{TOOLS}:/bin"})
def test_an_environment_without_a_path_gets_the_tools_alone(self):
self.assertEqual(with_release_tools({}), {"PATH": TOOLS})
if __name__ == "__main__":
unittest.main()