fix(agents): claude reports what still carries the uuid (Issue #31)

claude had no residual_artifacts, so a purge always printed `residual: none`.
It now reports names holding the uuid under ~/.claude (projects excluded),
in projects two levels deep, in the tmp roots, plus the owned jobs dir and
session files. Shared files (history.jsonl, ~/.claude.json) are not
reported: they always mention every session. scan_names goes to base.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-10-15 15:16:06 +00:00
1 parent 9ccd3c1835
commit 366da3b3d6
2 files changed
+51 -1

No files matched your search

@@ -1,6 +1,6 @@
import os, re, json, glob, time, shutil, subprocess
from typing import Optional, Any
from lib_py.agents.base import BaseAgentAdapter, DiscoveryContext, conversation_in_use, _plausible_id
from lib_py.agents.base import BaseAgentAdapter, DiscoveryContext, conversation_in_use, scan_names, _plausible_id
from lib_py.verify_session import workspace_key
@@ -256,6 +256,40 @@ class ClaudeAgentAdapter(BaseAgentAdapter):
purged.append(_label(path))
return purged
def residual_artifacts(self, uuid: str, ctx: DiscoveryContext) -> list:
"""What still carries this session: names holding the uuid under the
config root, in projects (two levels: key, then entry) and in the tmp
roots (two levels), plus the content-matched jobs dir and session
files. projects is not walked deeper; it can be very large."""
if not _plausible_id(uuid):
return []
cfg = _config_dir(ctx)
found = set(scan_names(cfg, uuid, skip=(os.path.join(cfg, "projects"), ctx.claude_dir)))
try:
keys = sorted(os.listdir(ctx.claude_dir))
except OSError:
keys = []
for key in keys:
kdir = os.path.join(ctx.claude_dir, key)
if uuid in key:
found.add(kdir)
elif os.path.isdir(kdir):
try:
found.update(os.path.join(kdir, n) for n in os.listdir(kdir) if uuid in n)
except OSError:
pass
job = self._owned_job(uuid, ctx)
if job:
found.add(job)
found.update(path for path, _, _ in self._session_files(uuid, ctx))
for root in _tmp_roots():
try:
tkeys = os.listdir(root)
except OSError:
continue
found.update(p for p in (os.path.join(root, k, uuid) for k in tkeys) if os.path.lexists(p))
return sorted(found)
def spawn_spec(self, binary: str, session_uuid: str = "", use_wrapper: bool = False) -> str:
if use_wrapper or not session_uuid:
return f"{binary} --dangerously-skip-permissions"