Smart macros — record once, replay many (literal + LLM-adaptive)#4
Merged
Conversation
Adds the macro recording/replay system from goal/009:
- mobile_use/record_replay.py: `_ui_fingerprint(helpers)` digest (top-N
labels, focused element, app bundle id, ~200 bytes), `annotate(intent)`
ctx mgr that attaches intent + fingerprint to journal entries, sidecar
.jsonl alongside the .py script, `replay_smart(script, helpers, llm)`
literal-first / LLM-fallback engine, `MacroStepFailed` with rich context
for skip-vs-raise recovery.
- mobile_use/agent_loop.py: `retarget_action(intent, recorded_fp,
current_ui, llm)` reuses agent prompt scaffolding, mockable callable LLM.
- mobile_use/macro.py + cli.py: `mobile-use macro {record,replay,list,show}`
CLI. Flags: --smart/--literal (default literal), --intent <txt> for record,
--dir <path> (default ~/.mobile-use/macros/).
- docs/macros.md: end-to-end walkthrough.
- README + SKILL: smart-macro example + when-to-use vs agent loop guidance.
Tests: 68 new (record_replay + smart_replay + macro_cli). Full suite 611 pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
record_replay._ui_fingerprint(helpers)— lightweight screen digest (top-N labels, focused element, app bundle id, ~200 bytes).record_replay.annotate(intent)context manager — attaches intent + fingerprint to journaled actions; backward-compat outside annotate blocks (unchanged behavior).record_replay.replay_smart(script, helpers, llm=None, on_failure='raise')— per-step probe; if fingerprint matches → literal replay, if drift →retarget_action()via LLM → execute adapted action;MacroStepFailedraised (or skipped) with rich context on irrecoverable mismatch.agent_loop.retarget_action(intent, recorded_fp, current_ui, llm)— reuses agent prompt scaffolding; mockable callable LLM.mobile-use macro {record,replay,list,show}CLI subcommand. Flags:--smart/--literal(default literal),--intent <txt>for record,--dir <path>(default~/.mobile-use/macros/).docs/macros.md— full walkthrough; README + SKILL updated with example.Test plan
python3 -m pytest tests/ -q→ 611 passed locally (was 556 → 68 new macros tests)mobile-use macro record demo, run flow,mobile-use macro replay demo(literal) +mobile-use macro replay demo --smart(LLM-adaptive)Notes