The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): keep the tool store out of each dependency generation's workspace
Ben Barclaya3dc84170715
diff --git a/pm/workspace.py b/pm/workspace.pyindex 67b275dddc2..74b4ef881a4 100644--- a/pm/workspace.py+++ b/pm/workspace.py@@ -7,6 +7,7 @@ failure propagates without changing plugin configuration or the live venv.from __future__ import annotationsimport hashlib+import jsonimport osimport shutilfrom collections.abc import Mapping@@ -62,6 +63,29 @@ def members_stamp(plugin_dirs) -> str:return h.hexdigest()+def _published_store_entries(directory: Path) -> frozenset[str]:+ """Names of the PM tool-store entries published in *directory*, if it is a store root.++ The container image keeps its store in the ``tools`` package directory, so the snapshot would+ otherwise copy every pinned interpreter, browser and media binary (about 1.5 GB) into each+ dependency generation. Nothing builds from them: the build runs the store's own tools in+ place. A directory counts as a store only when its ``facts.json`` records published entries,+ and only those entries (plus hash-keyed fetch caches) are left out.+ """+ try:+ facts = json.loads((directory / "facts.json").read_text(encoding="utf-8-sig"))+ except (OSError, ValueError):+ return frozenset()+ packages = facts.get("packages") if isinstance(facts, dict) else None+ if not isinstance(packages, dict):+ return frozenset()+ names = {fact["entry"] for fact in packages.values()+ if isinstance(fact, dict) and isinstance(fact.get("entry"), str)}+ names = {name for name in names if name and Path(name).name == name}+ names.update(child.name for child in directory.glob("fetch-*") if child.is_dir())+ return frozenset(name for name in names if (directory / name).is_dir())++def _copy_core_inputs(source: Path, destination: Path) -> None:"""Build from a writable snapshot, never from signed/read-only source."""import fnmatch@@ -89,8 +113,9 @@ def _copy_core_inputs(source: Path, destination: Path) -> None:# environment runs from this snapshot and serves bundled plugins' dashboard/dist/.nested_excluded = excluded - {"dist"}def ignore(directory, names):+ published = _published_store_entries(Path(directory))return [name for name in names if name in nested_excluded or name.startswith(".")- or name.endswith(".egg-info") or (Path(directory) / name).is_symlink()]+ or name in published or name.endswith(".egg-info") or (Path(directory) / name).is_symlink()]for entry in source.iterdir():if (entry.is_dir() and not entry.is_symlink() and entry.name not in excludeddiff --git a/tests/pm/test_workspace_build_inputs.py b/tests/pm/test_workspace_build_inputs.pyindex 51122a036fc..7dc68d21c3d 100644--- a/tests/pm/test_workspace_build_inputs.py+++ b/tests/pm/test_workspace_build_inputs.py@@ -282,3 +282,52 @@ def test_nested_dist_travels_but_root_dist_stays_out(tmp_path):assert (destination / "plugins/kanban/dashboard/dist/index.js").read_text(encoding="utf-8") == "ENTRY\n"assert not (destination / "dist").exists(), "root build output never enters the snapshot"+++def test_tool_store_inside_a_package_stays_out_of_the_snapshot(tmp_path):+ """The container image keeps PM's tool store in the ``tools`` package directory; each dependency+ generation copied its interpreters, browser and media binaries (~1.5 GB) into its workspace."""+ core = tmp_path / "core"+ tools = core / "tools"+ (tools / "environments").mkdir(parents=True)+ (tools / "wakewords").mkdir()+ for entry in ("python-3.14.7-linux-x64", "chromium-1208", "fetch-abc123"):+ (tools / entry / "bin").mkdir(parents=True)+ (tools / entry / "bin" / "payload").write_text("BINARY\n", encoding="utf-8")+ (tools / "__init__.py").write_text("", encoding="utf-8")+ (tools / "environments" / "__init__.py").write_text("", encoding="utf-8")+ (tools / "wakewords" / "hey.onnx").write_text("DATA\n", encoding="utf-8")+ (tools / "facts.json").write_text(json.dumps({"packages": {+ "python": {"entry": "python-3.14.7-linux-x64"}, "chromium": {"entry": "chromium-1208"},+ "venv": {"entry": None}, "escape": {"entry": "../environments"}}}), encoding="utf-8")+ (core / "pyproject.toml").write_text(+ '[project]\nname="core"\nversion="1"\nrequires-python=">=3.11"\n'+ '[tool.setuptools.packages.find]\ninclude=["tools", "tools.*"]\n',+ encoding="utf-8",+ )++ destination = tmp_path / "stage"+ workspace._copy_core_inputs(core, destination)++ assert (destination / "tools/environments/__init__.py").is_file()+ assert (destination / "tools/wakewords/hey.onnx").read_text(encoding="utf-8") == "DATA\n"+ for entry in ("python-3.14.7-linux-x64", "chromium-1208", "fetch-abc123"):+ assert not (destination / "tools" / entry).exists(), f"store entry {entry} copied into the snapshot"+++def test_a_facts_file_without_published_entries_hides_nothing(tmp_path):+ core = tmp_path / "core"+ data = core / "agent" / "chromium-1208"+ data.mkdir(parents=True)+ (data / "kept.txt").write_text("KEPT\n", encoding="utf-8")+ (core / "agent" / "facts.json").write_text('{"schema": 1}', encoding="utf-8")+ (core / "pyproject.toml").write_text(+ '[project]\nname="core"\nversion="1"\nrequires-python=">=3.11"\n'+ '[tool.setuptools.packages.find]\ninclude=["agent"]\n',+ encoding="utf-8",+ )++ destination = tmp_path / "stage"+ workspace._copy_core_inputs(core, destination)++ assert (destination / "agent/chromium-1208/kept.txt").read_text(encoding="utf-8") == "KEPT\n"