refactor: simplify finalize_setup scan to agent_root only, improve comments

Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/spec-kit/sessions/054690bb-c048-41e0-b553-377d5cb36b78
This commit is contained in:
copilot-swe-agent[bot]
2026-03-20 22:32:36 +00:00
committed by GitHub
parent 9b580a536b
commit 978addc390

View File

@@ -324,8 +324,10 @@ class AgentBootstrap:
all_extension = list(extension_files or []) all_extension = list(extension_files or [])
# Filter agent_files: only keep files under the agent's directory # Filter agent_files: only keep files under the agent's directory
# tree. setup() may return shared project files (e.g. .specify/) # tree. setup() returns *all* scaffolded files (including shared
# which must not be tracked per-agent. # project infrastructure in .specify/) but only agent-owned files
# should be tracked per-agent — shared files are not removed
# during teardown/switch.
agent_root = self.agent_dir(project_path) agent_root = self.agent_dir(project_path)
agent_root_resolved = agent_root.resolve() agent_root_resolved = agent_root.resolve()
all_agent: List[Path] = [] all_agent: List[Path] = []
@@ -334,25 +336,22 @@ class AgentBootstrap:
p.resolve().relative_to(agent_root_resolved) p.resolve().relative_to(agent_root_resolved)
all_agent.append(p) all_agent.append(p)
except ValueError: except ValueError:
pass # shared file — not tracked per-agent pass
# Scan the agent's directory tree for files created by the init # Scan the agent's directory tree for files created by later
# pipeline that setup() did not report directly. We scan the # init pipeline steps (skills, presets, extensions) that
# entire agent directory (the parent of commands_dir) because # setup() did not report. We scan the agent root directory
# skills-migrated agents replace the commands directory with a # (e.g. .claude/) so we catch both commands and skills
# sibling skills directory during init. # directories (skills-migrated agents replace the commands
# directory with a sibling skills directory during init).
if self.manifest.commands_dir: if self.manifest.commands_dir:
commands_dir = project_path / self.manifest.commands_dir agent_root = self.agent_dir(project_path)
# Scan the agent root (e.g. .claude/) so we catch both if agent_root.is_dir():
# commands and skills directories. agent_set = {p.resolve() for p in all_agent}
agent_root = commands_dir.parent for p in agent_root.rglob("*"):
agent_set = {p.resolve() for p in all_agent} if p.is_file() and p.resolve() not in agent_set:
for scan_dir in (commands_dir, agent_root): all_agent.append(p)
if scan_dir.is_dir(): agent_set.add(p.resolve())
for p in scan_dir.rglob("*"):
if p.is_file() and p.resolve() not in agent_set:
all_agent.append(p)
agent_set.add(p.resolve())
record_installed_files( record_installed_files(
project_path, project_path,