crumb-spec
Crumb Protocol specification and filesystem standard for sovereign AI agents
Brought by drakestapleton
crumb-spec / examples / reference-clients / sniff.py
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Zero-dependency reference reader for the Crumb Protocol (RFC-0001). |
| 4 | Usage: python3 sniff.py [path/to/directory] |
| 5 | """ |
| 6 | |
| 7 | import json |
| 8 | import os |
| 9 | import sys |
| 10 | |
| 11 | def sniff_directory(path="."): |
| 12 | target_dir = os.path.abspath(path) |
| 13 | if not os.path.isdir(target_dir): |
| 14 | target_dir = os.path.dirname(target_dir) |
| 15 | |
| 16 | crumb_path = os.path.join(target_dir, ".crumb") |
| 17 | crumb_local_path = os.path.join(target_dir, ".crumb.local") |
| 18 | |
| 19 | print(f"--- Crumb Topography for: {target_dir} ---") |
| 20 | |
| 21 | if os.path.exists(crumb_path): |
| 22 | try: |
| 23 | with open(crumb_path, "r", encoding="utf-8") as f: |
| 24 | crumb = json.load(f) |
| 25 | print(f"Module: {crumb.get("name", "unnamed")} (Layer: {crumb.get("layer", "n/a")})") |
| 26 | print(f"Purpose: {crumb.get("purpose", "n/a")}") |
| 27 | |
| 28 | above = crumb.get("above") |
| 29 | if above: |
| 30 | if isinstance(above, dict): |
| 31 | print(f"Above: {above.get("name")} -> {above.get("path")}") |
| 32 | else: |
| 33 | print(f"Above: {above}") |
| 34 | |
| 35 | invariants = crumb.get("invariants", []) |
| 36 | if invariants: |
| 37 | print("Invariants:") |
| 38 | for inv in invariants: |
| 39 | print(f" * {inv}") |
| 40 | except Exception as e: |
| 41 | print(f"Error reading .crumb: {e}") |
| 42 | else: |
| 43 | print("No .crumb found in this directory.") |
| 44 | |
| 45 | if os.path.exists(crumb_local_path): |
| 46 | try: |
| 47 | with open(crumb_local_path, "r", encoding="utf-8") as f: |
| 48 | local = json.load(f) |
| 49 | |
| 50 | scents = local.get("active_scents", {}) |
| 51 | if scents: |
| 52 | print("\nActive Agent Scents:") |
| 53 | for agent, s in scents.items(): |
| 54 | print(f" [{agent}] Focus: {s.get("focus")} (Updated: {s.get("updated_at")})") |
| 55 | |
| 56 | locks = local.get("locks", {}) |
| 57 | if locks: |
| 58 | print("\nActive Resource Locks:") |
| 59 | for res, lock in locks.items(): |
| 60 | print(f" [LOCK] {res} held by {lock.get("holder")} (Intent: {lock.get("intent")})") |
| 61 | |
| 62 | whispers = local.get("whispers", []) |
| 63 | if whispers: |
| 64 | print("\nRecent Whispers:") |
| 65 | for w in whispers[-5:]: |
| 66 | print(f" From {w.get("from")}: \"{w.get("message")}\" ({w.get("timestamp")})") |
| 67 | |
| 68 | history = local.get("history", []) |
| 69 | if history: |
| 70 | print("\nRecent History Vectors:") |
| 71 | for h in history[-3:]: |
| 72 | print(f" {h.get("timestamp")} | {h.get("agent")} {h.get("action")} {h.get("target")} - {h.get("intent")}") |
| 73 | except Exception as e: |
| 74 | print(f"Error reading .crumb.local: {e}") |
| 75 | else: |
| 76 | print("\nNo .crumb.local detected (no active agent scents).") |
| 77 | |
| 78 | if __name__ == "__main__": |
| 79 | target = sys.argv[1] if len(sys.argv) > 1 else "." |
| 80 | sniff_directory(target) |