Skip to content

The agent that grows with you

refactor(tools): drop redundant mkdir before materialize_tree; pack result dicts

Teknium8f480de704c1
diff --git a/tools/skills_sync_client.py b/tools/skills_sync_client.py
index a4d605c0866..06146cf2e5f 100644
--- a/tools/skills_sync_client.py
+++ b/tools/skills_sync_client.py
@@ -399,15 +399,12 @@ def _resolve_push_conflict(client: SyncClient, identity: Dict[str, Any], actual_
conflict_ref = f"refs/user/{owner}/conflict/{_next_conflict_index(client, owner)}"
with suppress(SyncConflict): # someone else grabbed this index; the head still exists
client.cas_ref(conflict_ref, None, our_commit)
- return {
- "ok": False, "conflict": True, "conflict_ref": conflict_ref,
- "overlapping_skills": sorted(overlaps), "actual_head": actual_head,
- "message": (
- f"{len(overlaps)} skill(s) changed on both sides; wrote "
- f"{conflict_ref}. Resolve out-of-band (hermes sync / NAS UI).")}
+ return {"ok": False, "conflict": True, "conflict_ref": conflict_ref, "overlapping_skills": sorted(overlaps),
+ "actual_head": actual_head, "message": (f"{len(overlaps)} skill(s) changed on both sides; wrote "
+ f"{conflict_ref}. Resolve out-of-band (hermes sync / NAS UI).")}
# Merge commit (parents: actual, ours); re-add our objects so the merge push is self-contained.
merge_objects = ObjectSet()
- merge_objects.objects.update(objects.objects)
+ merge_objects.objects |= objects.objects
merged_root = assemble_root_from_skill_trees(merged, merge_objects)
merge_commit = build_commit(merged_root, [actual_head, our_commit], owner=owner,
device=stable_device_id(), message=f"merge: {message}", objects=merge_objects)
@@ -415,9 +412,8 @@ def _resolve_push_conflict(client: SyncClient, identity: Dict[str, Any], actual_
try:
client.cas_ref(user_head_ref(owner), actual_head, merge_commit)
except SyncConflict as c2:
- return {
- "ok": False, "conflict": True, "actual_head": c2.actual,
- "message": f"merge CAS lost again (head now {c2.actual}); retry sync."}
+ return {"ok": False, "conflict": True, "actual_head": c2.actual,
+ "message": f"merge CAS lost again (head now {c2.actual}); retry sync."}
_record_head(read_sync_state(), merge_commit, merged_root)
return {"ok": True, "head": merge_commit, "merged": True}
@@ -484,11 +480,10 @@ def maybe_pull_skills() -> Optional[Dict[str, Any]]:
def sync_status() -> Dict[str, Any]:
"""Snapshot for ``hermes sync status``; never raises. ``org_available`` False = not in a shared org."""
- status: Dict[str, Any] = {
- "nous_admin": False, "logged_in": False, "feature_enabled": sync_feature_enabled(),
- "default_opt_in": sync_default_opt_in(), "base_url": resolve_sync_base_url(),
- "opted_in_skills": [], "local_head": None, "owner": None, "org_available": False,
- "org_id": None, "org_role": None, "org_skills": [], "org_skills_modified": []}
+ status: Dict[str, Any] = {"nous_admin": False, "logged_in": False, "feature_enabled": sync_feature_enabled(),
+ "default_opt_in": sync_default_opt_in(), "base_url": resolve_sync_base_url(),
+ "opted_in_skills": [], "local_head": None, "owner": None, "org_available": False,
+ "org_id": None, "org_role": None, "org_skills": [], "org_skills_modified": []}
try:
identity = resolve_identity()
status.update(logged_in=True, owner=identity.get("owner"), nous_admin=bool(identity.get("nous_admin")))
diff --git a/tools/skills_sync_client_org.py b/tools/skills_sync_client_org.py
index 54c4ffcbe77..8ac49ad851d 100644
--- a/tools/skills_sync_client_org.py
+++ b/tools/skills_sync_client_org.py
@@ -202,12 +202,10 @@ def pull_org_skills(client: Optional[SyncClient] = None, *, identity: Optional[D
if not head:
return {"ok": True, "org_id": org_id, "head": None, "updated": []}
head_commit = client.get_commit_json(head, org_scope=True)
- skill_trees = skill_trees_of_root(client, head_commit["tree"], org_scope=True)
- dest_root = _mirror_root(org_id)
updated, conflicted = [], []
baseline = _read_org_baseline(org_id)
- for rel_path, tree_hash in sorted(skill_trees.items()):
- dest = dest_root / PurePosixPath(rel_path)
+ for rel_path, tree_hash in sorted(skill_trees_of_root(client, head_commit["tree"], org_scope=True).items()):
+ dest = _mirror_root(org_id) / PurePosixPath(rel_path)
try:
if dest.exists():
if org_skill_is_locally_modified(rel_path, org_id):
@@ -215,8 +213,7 @@ def pull_org_skills(client: Optional[SyncClient] = None, *, identity: Optional[D
conflicted.append(rel_path)
continue
shutil.rmtree(dest)
- dest.mkdir(parents=True, exist_ok=True)
- materialize_tree(client, tree_hash, dest, org_scope=True)
+ materialize_tree(client, tree_hash, dest, org_scope=True) # creates dest
baseline[rel_path] = {"fingerprint": _skill_dir_fingerprint(dest), "tree": tree_hash}
updated.append(rel_path)
except Exception as e: