Skip to content

The agent that grows with you

refactor(tools): inline _reset_spawn_warning_state, share _active_org_id, tighten eligibility checks

Tekniume50e571719cb
diff --git a/tests/tools/test_tirith_security.py b/tests/tools/test_tirith_security.py
index ed5f8be92d2..7efd02c1926 100644
--- a/tests/tools/test_tirith_security.py
+++ b/tests/tools/test_tirith_security.py
@@ -603,7 +603,7 @@ class TestSpawnWarningDedup:
}
mock_run.side_effect = FileNotFoundError("[WinError 2]")
# Fresh dedupe state — clear any keys left by other tests.
- _tirith_mod._reset_spawn_warning_state()
+ _tirith_mod._warned_messages.clear()
with caplog.at_level("WARNING", logger="tools.tirith_security"):
for i in range(15):
diff --git a/tools/skills_sync_client.py b/tools/skills_sync_client.py
index 858bbc1f465..3f7058a34a8 100644
--- a/tools/skills_sync_client.py
+++ b/tools/skills_sync_client.py
@@ -99,8 +99,7 @@ def _parse_bool(value: Any) -> Optional[bool]:
def _sync_config_bool(env_var: str, config_key: str, *, default: bool) -> bool:
"""``env_var`` -> ``sync.<config_key>`` -> default."""
- env_val = _parse_bool(os.getenv(env_var))
- if env_val is not None:
+ if (env_val := _parse_bool(os.getenv(env_var))) is not None:
return env_val
cfg_val = _parse_bool(_sync_config(config_key))
return default if cfg_val is None else cfg_val
@@ -162,9 +161,7 @@ def is_sync_eligible(skill_name: str) -> bool:
from agent.skill_utils import is_external_skill_path
except Exception:
return False
- if is_bundled(skill_name) or is_hub_installed(skill_name):
- return False
- skill_dir = _find_skill_dir(skill_name)
+ skill_dir = None if is_bundled(skill_name) or is_hub_installed(skill_name) else _find_skill_dir(skill_name)
if skill_dir is None or is_external_skill_path(skill_dir):
return False
rel = _rel_to_skills_dir(skill_dir)
@@ -379,8 +376,7 @@ def push_skills(client: Optional[SyncClient] = None, *, skill_names: Optional[Li
if client is None:
return dict(_NO_BASE_URL)
owner = identity["owner"]
- if skill_names is None:
- skill_names = list_synced_skill_names()
+ skill_names = list_synced_skill_names() if skill_names is None else skill_names
if not skill_names:
return {"ok": True, "reason": "no skills opted into sync", "noop": True}
diff --git a/tools/skills_sync_client_org.py b/tools/skills_sync_client_org.py
index a8369f9721e..5aa5a0ffce4 100644
--- a/tools/skills_sync_client_org.py
+++ b/tools/skills_sync_client_org.py
@@ -157,11 +157,15 @@ def org_skill_is_locally_modified(skill_rel_path: str, org_id: str) -> bool:
return bool(recorded) and _skill_dir_fingerprint(dest) != recorded
+def _active_org_id() -> Optional[str]:
+ from agent.skill_utils import read_active_org_id
+ return read_active_org_id(_ssc()._skills_dir())
+
+
def list_locally_modified_org_skills(org_id: Optional[str] = None) -> List[str]:
"""Org skills with local edits that upstream has not seen."""
try:
- from agent.skill_utils import read_active_org_id
- org_id = org_id or read_active_org_id(_ssc()._skills_dir())
+ org_id = org_id or _active_org_id()
if not org_id:
return []
return sorted(rel for rel in _read_org_baseline(org_id) if org_skill_is_locally_modified(rel, org_id))
@@ -174,14 +178,11 @@ def list_org_skill_names() -> List[str]:
"""Skill names present in the local org mirror (empty when none pulled)."""
names: List[str] = []
try:
- from agent.skill_utils import read_active_org_id
- org_id = read_active_org_id(_ssc()._skills_dir())
+ org_id = _active_org_id()
root = _mirror_root(org_id) if org_id else None
if root and root.is_dir():
- for skill_md in root.rglob("SKILL.md"):
- rel = skill_md.parent.relative_to(root)
- if rel.parts:
- names.append(str(rel).replace("\\", "/"))
+ names = [str(rel).replace("\\", "/") for rel in (p.parent.relative_to(root) for p in root.rglob("SKILL.md"))
+ if rel.parts]
except Exception as e:
logger.debug("skills_sync_client: org skill listing failed: %s", e)
return sorted(names)
diff --git a/tools/threat_patterns.py b/tools/threat_patterns.py
index 2ea657e08bb..819a6f57b2f 100644
--- a/tools/threat_patterns.py
+++ b/tools/threat_patterns.py
@@ -106,9 +106,8 @@ def _compile() -> dict[str, List[Tuple[re.Pattern, str]]]:
for pattern, pid, scope in _PATTERNS:
if scope not in _SCOPE_SETS:
raise ValueError(f"threat_patterns: unknown scope {scope!r} for pattern {pid!r}")
- entry = (re.compile(pattern, re.IGNORECASE), pid)
for s in _SCOPE_SETS[scope]:
- compiled[s].append(entry)
+ compiled[s].append((re.compile(pattern, re.IGNORECASE), pid))
return compiled
diff --git a/tools/tirith_security.py b/tools/tirith_security.py
index 3a6962fe30f..d50140a5152 100644
--- a/tools/tirith_security.py
+++ b/tools/tirith_security.py
@@ -106,12 +106,6 @@ def _warn_once(key: str, message: str, *args) -> None:
logger.warning(message, *args)
-def _reset_spawn_warning_state() -> None:
- """Clear the warn-once set so a failure after a fresh (re)install surfaces again."""
- with _warned_lock:
- _warned_messages.clear()
-
-
def _cached_path() -> str | None:
"""The path resolved on a previous call, or None if unresolved (None) / failed (_INSTALL_FAILED)."""
return _resolved_path or None
@@ -165,8 +159,9 @@ def _mark_install_failed(reason: str = ""):
def _clear_install_failed():
- """Remove the failure marker and reset warn-once state after a successful install."""
- _reset_spawn_warning_state()
+ """Remove the failure marker and reset warn-once state (so a failure after a reinstall surfaces again)."""
+ with _warned_lock:
+ _warned_messages.clear()
with suppress(OSError):
os.unlink(_failure_marker_path())