feat(a4,c3b): complete A-4 Phase 2 agent knowledge migration & Option B isolation removal

- Option B / C-3b: Deprecate isolation.root and remove its 4 legacy consumers in lib.sh, workspace_uuid.py, verify_session.py, and stop_session.sh.
- M2~M7 Migration: Implement artifact_path, verify_artifact, purge_artifacts, spawn_spec, resume_spec, auth_ok, discover, ready_tokens, exit_key, and delegate_agent_key across BaseAgentAdapter and all 4 adapters (Claude, Agy, Hermes, Cline).
- Migrate shell duplications in lib.sh, create_session.sh, resume_session.sh, stop_session.sh, and reconcile.sh to python -m lib_py.agents facts.
- Hardening & Corrections: Fix Cline resume_spec flag to '-i --id', apply shlex.quote across all facts variables with MAM_ prefix, add safe fallback in wait_for_tui_ready.
- Add comprehensive contract tests in tests/test_a4_adapter_contract.py and sync IMPROVEMENTS.md / LOG.md.
- Verified: 100% PASS across unit, component, contract, and integration tests.
This commit is contained in:
2026-08-16 23:15:24 +09:00
parent 971f14ad3f
commit b4821fafa8
21 changed files with 904 additions and 531 deletions
+10 -106
View File
@@ -83,12 +83,11 @@ from lib_py.paths import resolve_home
def verify_session_uuid(ws, agent, uuid, row=None, home_dir=None, claude_dir=None, mode="discover"):
import os, json, sqlite3
home = resolve_home(home_dir)
c_dir = claude_dir or os.environ.get("CLAUDE_PROJECT_DIR", f"{home}/.claude/projects")
row = row or {}
_iso = row.get("isolation")
iso_root = _iso.get("root") if isinstance(_iso, dict) and _iso.get("root") else None
from lib_py.paths import resolve_home
from lib_py.agents.registry import get_adapter
from lib_py.agents.base import DiscoveryContext
row = row or {}
epoch = row.get("herdr_session_epoch", 0) if mode == "discover" else 0
cwd = row.get("pane", {}).get("cwd", "") or ws
@@ -103,104 +102,9 @@ def verify_session_uuid(ws, agent, uuid, row=None, home_dir=None, claude_dir=Non
and not row.get("session_id_verified")):
return True
if agent == "claude":
base = (iso_root + "/projects") if iso_root else c_dir
key = workspace_key(ws)
path = f"{base}/{key}/{uuid}.jsonl"
if not os.path.exists(path):
return False
if epoch and os.path.getmtime(path) < epoch:
return False
try:
valid_session = False
found_cwd = None
with open(path) as f:
for _ in range(50):
line = f.readline()
if not line:
break
line = line.strip()
if not line:
continue
try:
payload = json.loads(line)
if payload.get("sessionId") == uuid:
valid_session = True
if payload.get("cwd"):
found_cwd = payload.get("cwd")
break
except Exception:
pass
if not valid_session:
return False
if found_cwd and workspace_key(found_cwd) != workspace_key(cwd):
return False
except Exception:
return False
elif agent == "agy":
base = f"{iso_root or home}/.gemini/antigravity-cli/conversations"
path = f"{base}/{uuid}.db"
if not os.path.exists(path):
return False
if epoch and os.path.getmtime(path) < epoch:
return False
if mode == "discover":
lc = f"{iso_root or home}/.gemini/antigravity-cli/cache/last_conversations.json"
cache_match = False
if os.path.exists(lc):
try:
with open(lc) as f:
lc_data = json.load(f)
cache_match = (lc_data.get(cwd) == uuid)
except Exception:
cache_match = False
if not cache_match:
if uuid in (row.get("_sibling_claimed_uuids") or []):
return False
try:
conn = sqlite3.connect(path)
r = conn.execute("SELECT count(*) FROM steps").fetchone()
conn.close()
if not r or r[0] < 1:
return False
except Exception:
return False
elif agent == "hermes":
hdb = f"{iso_root or home}/.hermes/state.db"
if not os.path.exists(hdb):
return False
if epoch and os.path.getmtime(hdb) < epoch:
return False
try:
conn = sqlite3.connect(hdb)
r = conn.execute("SELECT cwd FROM sessions WHERE id=?", (uuid,)).fetchone()
conn.close()
if not r:
return False
found_cwd = r[0]
if found_cwd and workspace_key(found_cwd) != workspace_key(cwd):
return False
except Exception:
return False
elif agent == "cline":
base = (iso_root + "/sessions") if iso_root else f"{home}/.cline/data/sessions"
path = f"{base}/{uuid}/{uuid}.json"
if not os.path.exists(path):
return False
if epoch and os.path.getmtime(path) < epoch:
return False
try:
with open(path) as f:
sdata = json.load(f)
if sdata.get("session_id") != uuid:
return False
found_cwd = sdata.get("cwd") or sdata.get("workspace_root")
if found_cwd and workspace_key(found_cwd) != workspace_key(cwd):
return False
except Exception:
return False
return True
adapter = get_adapter(agent)
if not adapter:
return False
ctx = DiscoveryContext(workspace=ws, agent_name=agent, home_dir=home_dir, claude_dir=claude_dir, epoch=epoch, row=row, mode=mode)
return adapter.verify_artifact(uuid, ctx)