Skip to content

feat(skills): add opt-in AST deep diagnostics (salvage of #30918) - #31198

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-7e344468
May 24, 2026
Merged

teknium1 merged 2 commits into
mainfrom
hermes/hermes-7e344468

Conversation

@teknium1

@teknium1 teknium1 commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Salvages @Tranquil-Flow's PR #30918 onto current main, then trims it from +704/-12 to +264/-6.

Summary

hermes skills audit [name] --deep now runs an opt-in AST pass over installed hub skills' Python files and prints any importlib / dynamic-import / dynamic-getattr / __dict__[<computed>] patterns it finds. Diagnostic only — Skills Guard verdicts are unchanged (tools/skills_guard.py has zero diff). Matches the direction laid out when closing #7436.

Changes

  • tools/skills_ast_audit.py (new, 133 LOC): single ast_scan_path(path) handles file or directory; plain tuple findings; format_ast_report() returns plain text.
  • hermes_cli/skills_hub.py: do_audit(..., deep=False) runs the scan after the existing Skills Guard scan when --deep is passed.
  • hermes_cli/main.py: skills audit --deep argparse flag.
  • hermes_cli/commands.py: register audit as a /skills subcommand.
  • tests/tools/test_skills_ast_audit.py (103 LOC): bypass payload, syntax-error / RecursionError survival, false-positive guards, dir recursion + ignored dirs, formatter.

What changed vs the original PR

  • Dropped the inspect --ast-deep surface — same scanner, same output, redundant. Operators audit after install.
  • Folded three entry points (file / skill-dir / bundle) into one ast_scan_path.
  • Dropped the AstFinding dataclass + severity field — display theater for a diagnostic that explicitly disclaims security verdicts.
  • Replaced Rich-markup formatter with plain text grouped by file.
  • Tests trimmed to the cases that earn their place (~60 LOC of core + small dir/formatter coverage).

Validation

Before --deep After --deep
Skills Guard verdict SAFE SAFE (unchanged)
AST output none 3 findings on #7072 bypass payload (importlib_import, dynamic_import, dict_access)

Authorship

Closes #30918.

Infographic

ast-deep-diagnostic

Tranquil-Flow and others added 2 commits May 23, 2026 16:33
Add opt-in AST diagnostics for skill review without making Skills Guard stricter by default.

- Add hermes skills inspect --ast-deep to scan fetched skill bundles before installation
- Add hermes skills audit --deep to scan already-installed hub skills
- Keep AST analysis in tools/skills_ast_audit.py, separate from tools/skills_guard.py
- Label output as diagnostic hints, not security verdicts
- Cover dynamic import/access patterns: importlib, __import__(computed), getattr(computed), and __dict__[computed]

This follows the maintainer guidance from closed PR #7436: useful AST-level analysis belongs in an opt-in diagnostic path, not in Skills Guard's default heuristic scan.
Trim ~600 LOC off the original contribution while keeping the same
operator-facing surface and detection coverage.

- Collapse three entry points (file / dir / bundle) into one
  ast_scan_path(path) that handles both files and directories.
- Drop AstFinding dataclass + severity field — replaced with plain
  (file, line, pattern_id, description) tuples. Severity ordering was
  display-only for a diagnostic that explicitly disclaims security
  verdicts, so the field added bookkeeping without earning its place.
- Replace Rich-markup formatter with plain text grouped by file.
- Drop the 'inspect --ast-deep' surface — same scanner, same output as
  'audit --deep', single CLI entry is enough. Operators audit after
  install; pre-install inspection signal isn't worth the second surface.
- Trim test file to the cases that earn their place: bypass payload,
  syntax error survival, RecursionError survival, false-positive guard
  (importer lookalike), literal-arg false-positive guard, non-.py
  ignored, directory recursion + cache-dir skipping, missing-path,
  getattr/__dict__ detection, formatter empty + populated.

Net: tools/skills_ast_audit.py 353 -> 133 LOC,
tests/tools/test_skills_ast_audit.py 299 -> 103 LOC, full diff
+704/-12 -> +264/-6. No change to tools/skills_guard.py — Skills Guard
verdicts remain untouched per SECURITY.md §2.4.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-7e344468 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9037 on HEAD, 9037 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4811 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/feature New feature or request comp/cli CLI entry point, hermes_cli/, setup wizard tool/skills Skills system (list, view, manage) P3 Low — cosmetic, nice to have labels May 23, 2026
@teknium1
teknium1 merged commit 4254f7d into main May 24, 2026
26 checks passed
@teknium1
teknium1 deleted the hermes/hermes-7e344468 branch May 24, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have tool/skills Skills system (list, view, manage) type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants