refactor(tools): dedup stat check, secret-capture walrus, comment reflow

This commit is contained in:
Teknium
2026-09-03 00:53:28 -07:00
parent 9197b7926f
commit 9bcf3069eb
3 changed files with 14 additions and 17 deletions

View File

@@ -41,7 +41,7 @@ _SKILLS_CACHE_TTL_SECONDS = 30.0
def _skills_scan_signature(dirs_to_scan, disabled) -> tuple:
"""O(#dirs + #categories) stat-based change signature. The platform is read via
"""O(#dirs + #categories) stat-based change signature; platform is read via
``agent.skill_utils.sys`` so test patches are honored."""
from agent import skill_utils as _skill_utils
sig = []
@@ -316,10 +316,9 @@ def _resolve_plugin_skill(name, file_path, task_id, preprocess):
def _under_any(path: Path, dirs) -> bool:
"""True when ``path`` (resolved where possible) lives under one of ``dirs``."""
try:
resolved = path
with suppress(Exception):
resolved = path.resolve()
except Exception:
resolved = path
return any(resolved.is_relative_to(d) for d in dirs)
@@ -525,8 +524,8 @@ def skill_view(
skills. ``preprocess`` applies the configured SKILL.md template / inline shell rendering;
slash/preload callers render the message themselves."""
try:
# Validate before the ':' dispatch so a Windows drive path (C:\skills\foo)
# can't be reinterpreted as a plugin namespace.
# Validate before the ':' dispatch so a Windows drive path (C:\skills\foo) can't be
# reinterpreted as a plugin namespace.
if lookup_error := _skill_lookup_path_error(name):
return _fail(lookup_error, hint=_LOOKUP_HINT)
local_category_name: str | None = None
@@ -534,8 +533,8 @@ def skill_view(
served, local_category_name = _resolve_plugin_skill(name, file_path, task_id, preprocess)
if served is not None:
return served
# The fall-through form (namespace/bare) joins onto each search dir too;
# re-validate it since `bare` is not namespace-checked.
# The fall-through form (namespace/bare) joins onto each search dir too; re-validate it
# since `bare` is not namespace-checked.
if local_category_name and (lookup_error := _skill_lookup_path_error(local_category_name)):
return _fail(lookup_error, hint=_LOOKUP_HINT)
project_dirs, all_dirs, active_skills_dir = _skill_search_dirs()

View File

@@ -66,10 +66,10 @@ def _check_skill_view_dedup(task_id, name, file_path) -> str | None:
continue
try:
st = os.stat(src)
if (st.st_mtime_ns, st.st_size) != (mtime_ns, size):
cache.pop(key, None)
return None
changed = (st.st_mtime_ns, st.st_size) != (mtime_ns, size)
except OSError:
changed = True
if changed:
cache.pop(key, None)
return None
return json.dumps({

View File

@@ -102,14 +102,12 @@ def _capture_required_environment_variables(
if not missing_entries:
return _capture_result([])
missing_names = [entry["name"] for entry in missing_entries]
# Messaging-platform gateway surfaces can't prompt for a secret, so they get
# the "unsupported" hint. Interactive gateway surfaces (desktop app / TUI) set
# HERMES_INTERACTIVE (same flag tools/approval.py uses) and register a callback
# routing to a secure secret.request overlay, so they fall through and prompt.
# Messaging-platform gateway surfaces can't prompt for a secret, so they get the "unsupported"
# hint. Interactive gateway surfaces (desktop app / TUI) set HERMES_INTERACTIVE (same flag
# tools/approval.py uses) and register a callback routing to a secure secret.request overlay.
if _is_gateway_surface() and not env_var_enabled("HERMES_INTERACTIVE"):
return _capture_result(missing_names, gateway_setup_hint=_gateway_setup_hint())
callback = _st._secret_capture_callback
if callback is None:
if (callback := _st._secret_capture_callback) is None:
return _capture_result(missing_names)
remaining_names: List[str] = []
for entry in missing_entries: