Repository navigation
fix(tasks): plan page and news watches as important-changes checks #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ | |
| CONDITIONS = ("alert", "changed", "noteworthy", "every_run") | ||
| COMPARING = ("changed", "noteworthy") # act on a difference from the last result | ||
| THEN = ("notify", "run") | ||
| # tools that read a page, a feed or the news: counters, times and ads change between checks (#298) | ||
| PAGE_TOOLS = frozenset( | ||
| {"web_fetch", "news_search", "news_top_headlines", "browser_open", "browser_snapshot", "browser_extract"} | ||
| ) | ||
| MAX_CODE_CHARS = 20000 | ||
| MAX_RESULT_CHARS = 20000 | ||
| REPORT_CHARS = 3000 # an every-run report shows this much of the script's output | ||
|
|
@@ -84,6 +88,34 @@ def normalize_script(raw: Any, previous: dict | None = None) -> dict: | |
| return out | ||
|
|
||
|
|
||
| def reads_pages(code: str) -> bool: | ||
| """True when the script calls a tool that reads a page, a feed or the news (``PAGE_TOOLS``).""" | ||
| try: | ||
| tree = ast.parse(code) | ||
| except SyntaxError: | ||
| return False | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name) and node.value.id == "tools": | ||
| name = node.attr # tools.web_fetch(...) | ||
| elif isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == "call_tool" and node.args: | ||
| name = getattr(node.args[0], "value", None) # call_tool("web_fetch", ...) | ||
| else: | ||
| continue | ||
| if isinstance(name, str) and name in PAGE_TOOLS: | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def planner_default(script: dict, previous: dict | None) -> dict: | ||
| """A ``changed`` check the planner proposes for a page, a feed or the news becomes ``noteworthy`` (#298): any | ||
| byte change there (a view counter, a timestamp) would notify. A check that was already ``changed`` stays so.""" | ||
| if script.get("condition") != "changed" or (previous or {}).get("condition") == "changed": | ||
| return script | ||
| if not reads_pages(script.get("code") or ""): | ||
| return script | ||
| return {**script, "condition": "noteworthy"} | ||
|
Comment on lines
+112
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Preserve If a new script calls 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def trigger_prelude(trigger_data: dict | None) -> str: | ||
| """Lines prepended to the code of a triggered script so it can read the event as ``trigger_event``.""" | ||
| payload = json.dumps(trigger_data if isinstance(trigger_data, dict) else None, ensure_ascii=False, default=str) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Recognize aliases of the
toolsimport.If a planner script uses
from sentient_tools import tools as tand callst.web_fetch(...),reads_pagesreturnsFalse. The new watch keepschangedand reports page noise without the relevance check. Resolve the imported binding before matching page-tool calls.🤖 Prompt for AI Agents