Skip to content

Commit a63c248

Browse files
Copilotmnriem
andauthored
Move file recording to finalize_setup() — called after init pipeline writes files
Address code review: setup() now only creates directories, while finalize_setup() (on base class) scans the agent's commands_dir for all files and records them. This ensures files are tracked after the full init pipeline has written them, not before. - Add AgentBootstrap.finalize_setup() that scans commands_dir - Remove premature record_installed_files() from all 25 setup() methods - agent_switch calls finalize_setup() after setup() completes - Update test helper to match new pattern Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/spec-kit/sessions/779eabf6-21d5-428b-9f01-dd363df4c84a
1 parent b5a5e3f commit a63c248

File tree

28 files changed

+53
-106
lines changed

28 files changed

+53
-106
lines changed

src/specify_cli/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,8 @@ def agent_switch(
26042604
new_bootstrap = load_bootstrap(resolved.path, resolved.manifest)
26052605
console.print(f" [dim]Setting up {agent_id}...[/dim]")
26062606
new_bootstrap.setup(project_path, script_type, options)
2607+
# Record all installed files for tracked teardown
2608+
new_bootstrap.finalize_setup(project_path)
26072609
console.print(f" [green]✓[/green] {agent_id} installed")
26082610
except AgentPackError as exc:
26092611
console.print(f"[red]Error setting up {agent_id}:[/red] {exc}")

src/specify_cli/agent_pack.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ def agent_dir(self, project_path: Path) -> Path:
222222
"""Return the agent's top-level directory inside the project."""
223223
return project_path / self.manifest.commands_dir.split("/")[0]
224224

225+
def finalize_setup(self, project_path: Path) -> None:
226+
"""Record all files in the agent directory for tracked teardown.
227+
228+
This must be called **after** the full init pipeline has finished
229+
writing files (commands, context files, etc.) into the agent
230+
directory. It scans ``self.manifest.commands_dir`` and records
231+
every file with its SHA-256 hash so that :meth:`teardown` can
232+
detect user modifications.
233+
"""
234+
if not self.manifest.commands_dir:
235+
return
236+
commands_dir = project_path / self.manifest.commands_dir
237+
if commands_dir.is_dir():
238+
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
239+
record_installed_files(project_path, self.manifest.id, installed)
240+
225241

226242
# ---------------------------------------------------------------------------
227243
# Installed-file tracking

src/specify_cli/core_pack/agents/agy/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Agy(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install Antigravity agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove Antigravity agent files from the project.

src/specify_cli/core_pack/agents/amp/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Amp(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install Amp agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove Amp agent files from the project.

src/specify_cli/core_pack/agents/auggie/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Auggie(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install Auggie CLI agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove Auggie CLI agent files from the project.

src/specify_cli/core_pack/agents/bob/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Bob(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install IBM Bob agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove IBM Bob agent files from the project.

src/specify_cli/core_pack/agents/claude/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Claude(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install Claude Code agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove Claude Code agent files from the project.

src/specify_cli/core_pack/agents/codebuddy/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Codebuddy(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install CodeBuddy agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove CodeBuddy agent files from the project.

src/specify_cli/core_pack/agents/codex/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Codex(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install Codex CLI agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove Codex CLI agent files from the project.

src/specify_cli/core_pack/agents/copilot/bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Any, Dict
55

6-
from specify_cli.agent_pack import AgentBootstrap, record_installed_files, remove_tracked_files
6+
from specify_cli.agent_pack import AgentBootstrap, remove_tracked_files
77

88

99
class Copilot(AgentBootstrap):
@@ -16,9 +16,6 @@ def setup(self, project_path: Path, script_type: str, options: Dict[str, Any]) -
1616
"""Install GitHub Copilot agent files into the project."""
1717
commands_dir = project_path / self.AGENT_DIR / self.COMMANDS_SUBDIR
1818
commands_dir.mkdir(parents=True, exist_ok=True)
19-
# Record installed files for tracked teardown
20-
installed = [p for p in commands_dir.rglob("*") if p.is_file()]
21-
record_installed_files(project_path, self.manifest.id, installed)
2219

2320
def teardown(self, project_path: Path, *, force: bool = False) -> None:
2421
"""Remove GitHub Copilot agent files from the project.

0 commit comments

Comments
 (0)