From b388c02f4bc2e03701b08ff64ffaf1c7214f9bad Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Mon, 26 Jan 2026 18:13:52 -0800 Subject: [PATCH] Add respond tool for safe queue manipulation by subagents --- .skills/working-with-subagents/SKILL.md | 10 ++- tools/respond.py | 107 ++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 tools/respond.py diff --git a/.skills/working-with-subagents/SKILL.md b/.skills/working-with-subagents/SKILL.md index 8a4972a..32ba124 100644 --- a/.skills/working-with-subagents/SKILL.md +++ b/.skills/working-with-subagents/SKILL.md @@ -52,16 +52,18 @@ Return the text to post. **Prompt Template (bulk queue)**: ``` -Read drafts/queue.yaml and fill in response fields. Edit the file directly. - -Use the memory tool to note patterns (new users, tone adjustments, recurring topics). Update your user_patterns or topics blocks if you learn something. +1. Run: uv run python -m tools.respond list +2. For each item needing response, run: uv run python -m tools.respond set-by-index "response text" +3. Use memory tool to note patterns (users, tone, topics). **Report when done**: - How many responses drafted -- Any notable interactions (new users, interesting threads, tone adjustments made) +- Notable interactions (new users, interesting threads) - What you stored in memory (if anything) ``` +**Important**: Do NOT edit queue.yaml directly - use the respond tool to set responses. + **Memory Instructions** (include in prompts): - "Use the memory tool to store learnings" - "Note patterns that work for future reference" diff --git a/tools/respond.py b/tools/respond.py new file mode 100644 index 0000000..dcdc1f8 --- /dev/null +++ b/tools/respond.py @@ -0,0 +1,107 @@ +""" +Respond Tool - Set responses in the notification queue. + +Usage: + python -m tools.respond set + python -m tools.respond list # Show queue with indices + python -m tools.respond set-by-index + +This tool handles YAML manipulation properly so subagents don't corrupt the file. +""" + +import sys +import yaml +from pathlib import Path + +QUEUE_FILE = Path("drafts/queue.yaml") + + +def load_queue(): + """Load the queue, return empty list if missing/corrupt.""" + if not QUEUE_FILE.exists(): + return [] + try: + with open(QUEUE_FILE, "r") as f: + return yaml.safe_load(f) or [] + except yaml.YAMLError as e: + print(f"Error loading queue: {e}") + return [] + + +def save_queue(queue): + """Save queue to YAML.""" + QUEUE_FILE.parent.mkdir(exist_ok=True) + with open(QUEUE_FILE, "w") as f: + yaml.dump(queue, f, sort_keys=False, allow_unicode=True, width=1000) + + +def list_queue(): + """List queue items with indices.""" + queue = load_queue() + if not queue: + print("Queue is empty.") + return + + for i, item in enumerate(queue): + author = item.get("author", "unknown") + text = item.get("text", "")[:60].replace("\n", " ") + response = item.get("response") + status = "✓" if response else "○" + print(f"{i}: [{status}] @{author}: {text}...") + + +def set_response(uri: str, response: str): + """Set response for a specific URI.""" + queue = load_queue() + found = False + + for item in queue: + if item.get("uri") == uri: + item["response"] = response + found = True + break + + if found: + save_queue(queue) + print(f"Set response for {uri[:50]}...") + else: + print(f"URI not found in queue: {uri[:50]}...") + + +def set_response_by_index(index: int, response: str): + """Set response by queue index.""" + queue = load_queue() + + if index < 0 or index >= len(queue): + print(f"Invalid index {index}. Queue has {len(queue)} items.") + return + + queue[index]["response"] = response + save_queue(queue) + author = queue[index].get("author", "unknown") + print(f"Set response for item {index} (@{author})") + + +if __name__ == "__main__": + if len(sys.argv) < 2: + print(__doc__) + sys.exit(1) + + cmd = sys.argv[1] + + if cmd == "list": + list_queue() + + elif cmd == "set" and len(sys.argv) >= 4: + uri = sys.argv[2] + response = sys.argv[3] + set_response(uri, response) + + elif cmd == "set-by-index" and len(sys.argv) >= 4: + index = int(sys.argv[2]) + response = sys.argv[3] + set_response_by_index(index, response) + + else: + print(__doc__) + sys.exit(1) -- 2.51.2