|
| 1 | +--- |
| 2 | +name: argent-create-flow |
| 3 | +description: Record a reusable flow (scripted sequence of MCP tool calls) that can be replayed later with a single command. Use when the user asks to create, record, or build a flow, or to script a sequence of simulator actions. |
| 4 | +--- |
| 5 | + |
| 6 | +## 1. Overview |
| 7 | + |
| 8 | +A flow is a recorded sequence of MCP tool calls saved to a `.yaml` file in the `.argent/flows/` directory. Each step is **executed live** as you add it, so you verify it works before it becomes part of the flow. Replay a finished flow with `flow-execute`. |
| 9 | + |
| 10 | +## 2. Tools |
| 11 | + |
| 12 | +| Tool | Purpose | |
| 13 | +| ------------------------ | -------------------------------------------------------------------------- | |
| 14 | +| `flow-start-recording` | Start recording β takes a name and executionPrerequisite, creates the file | |
| 15 | +| `flow-add-step` | Execute a tool call live and record it if it succeeds | |
| 16 | +| `flow-add-echo` | Add a label/comment that prints during replay | |
| 17 | +| `flow-finish-recording` | Stop recording and get a summary | |
| 18 | +| `flow-read-prerequisite` | Read a flow's execution prerequisite without running it | |
| 19 | +| `flow-execute` | Replay a saved flow by name | |
| 20 | + |
| 21 | +## 3. Workflow |
| 22 | + |
| 23 | +### Recording |
| 24 | + |
| 25 | +1. **Start**: Call `flow-start-recording` with a descriptive name, the absolute `project_root`, and an `executionPrerequisite` describing the required app state before running the flow (e.g. "App on home screen after a fresh reload"). `project_root` is stored for the session β you do **not** need to pass it again to subsequent tools. |
| 26 | +2. **Build step-by-step**: For each action, call `flow-add-step` with the tool name and args. The tool runs immediately β check the result before moving on. |
| 27 | +3. **Add labels**: Use `flow-add-echo` between steps to describe what each section does. |
| 28 | +4. **Finish**: Call `flow-finish-recording` to stop recording. It returns the file path where the flow was saved and a summary of all steps. You can edit the `.yaml` file directly afterwards to remove, reorder, or tweak steps. |
| 29 | + |
| 30 | +Every tool during recording returns the current flow file contents so you can track what has been recorded. |
| 31 | + |
| 32 | +### Replaying |
| 33 | + |
| 34 | +Call `flow-execute` with the flow name. If the flow has an execution prerequisite: |
| 35 | + |
| 36 | +1. The tool returns a **notice** with the prerequisite text instead of running. It asks you to verify the prerequisite is met and call `flow-execute` again with `prerequisiteAcknowledged: true`. |
| 37 | +2. You can also call `flow-read-prerequisite` beforehand to inspect the prerequisite without triggering a run. |
| 38 | +3. Once you pass `prerequisiteAcknowledged: true`, the flow runs all steps in order and returns every tool call result (including screenshots) merged into a single response. |
| 39 | + |
| 40 | +If the flow has no prerequisite, it runs immediately without needing acknowledgment. |
| 41 | + |
| 42 | +## 4. flow-add-step Usage |
| 43 | + |
| 44 | +The `command` parameter is the MCP tool name. The `args` parameter is a **JSON string** (not an object): |
| 45 | + |
| 46 | +``` |
| 47 | +command: "launch-app" |
| 48 | +args: "{\"udid\": \"<UDID>\", \"bundleId\": \"com.apple.Preferences\"}" |
| 49 | +``` |
| 50 | + |
| 51 | +``` |
| 52 | +command: "gesture-tap" |
| 53 | +args: "{\"udid\": \"<UDID>\", \"x\": 0.5, \"y\": 0.35}" |
| 54 | +``` |
| 55 | + |
| 56 | +``` |
| 57 | +command: "screenshot" |
| 58 | +args: "{\"udid\": \"<UDID>\"}" |
| 59 | +``` |
| 60 | + |
| 61 | +For tools with no arguments, omit `args` entirely. |
| 62 | + |
| 63 | +## 5. Important Rules |
| 64 | + |
| 65 | +- **Every step runs live.** You will see the real tool result (including screenshots). Use this to verify the step worked before continuing. |
| 66 | +- **Only successful steps are recorded.** If a tool call fails, nothing is written to the flow file β fix the issue and try again. |
| 67 | +- **Pass `project_root` only to `flow-start-recording`.** It is stored for the session and automatically used by all subsequent flow tools. An error is returned if the path is not absolute. |
| 68 | +- **You do NOT need to pass a flow name** to `flow-add-step`, `flow-add-echo`, or `flow-finish-recording`. The active flow is tracked automatically after `flow-start-recording`. |
| 69 | +- **Start before adding.** Calling `flow-add-step`, `flow-add-echo`, or `flow-finish-recording` without an active recording returns an error: _"No active flow. Call flow-start-recording first."_ |
| 70 | +- **One flow at a time.** If you call `flow-start-recording` while already recording, the active flow switches to the new one. The response tells you which flow was abandoned and which is now active. The old flow's file remains on disk. |
| 71 | +- **Mistakes can be edited out.** If a step was recorded by mistake, edit the `.yaml` file directly to remove or reorder entries. |
| 72 | + |
| 73 | +## 6. Example Session |
| 74 | + |
| 75 | +``` |
| 76 | +flow-start-recording { name: "open-settings", project_root: "/Users/dev/MyApp", executionPrerequisite: "Simulator booted with app installed" } |
| 77 | +flow-add-echo { message: "Launch Settings app" } |
| 78 | +flow-add-step { command: "launch-app", args: "{\"udid\": \"ABC\", \"bundleId\": \"com.apple.Preferences\"}" } |
| 79 | +flow-add-echo { message: "Tap General" } |
| 80 | +flow-add-step { command: "gesture-tap", args: "{\"udid\": \"ABC\", \"x\": 0.5, \"y\": 0.35}" } |
| 81 | +flow-add-echo { message: "Tap About" } |
| 82 | +flow-add-step { command: "gesture-tap", args: "{\"udid\": \"ABC\", \"x\": 0.5, \"y\": 0.17}" } |
| 83 | +flow-finish-recording {} |
| 84 | +``` |
| 85 | + |
| 86 | +## 7. Replay Example |
| 87 | + |
| 88 | +``` |
| 89 | +flow-execute { name: "open-settings", project_root: "/Users/dev/MyApp" } |
| 90 | +β Returns: notice with executionPrerequisite: "Simulator booted with app installed" |
| 91 | + "Verify the prerequisite is met and call flow-execute again with prerequisiteAcknowledged set to true." |
| 92 | +
|
| 93 | +flow-execute { name: "open-settings", project_root: "/Users/dev/MyApp", prerequisiteAcknowledged: true } |
| 94 | +β Runs all steps, returns merged results with status and output for every step |
| 95 | +``` |
| 96 | + |
| 97 | +## 8. Flow File Format |
| 98 | + |
| 99 | +Flow files use YAML. The top-level is an object with `executionPrerequisite` (describes required state) and `steps` (array of actions): |
| 100 | + |
| 101 | +- `- echo: <message>` β a label |
| 102 | +- `- tool: <name>` with optional `args:` β a tool call. Add `delayMs: <ms>` to sleep that long before the step runs (use sparingly β only when the app needs a fixed wait between actions). |
| 103 | + |
| 104 | +Example `.yaml` file: |
| 105 | + |
| 106 | +```yaml |
| 107 | +executionPrerequisite: Simulator booted with app installed |
| 108 | +steps: |
| 109 | + - echo: Launch Settings app |
| 110 | + - tool: launch-app |
| 111 | + args: |
| 112 | + udid: ABC |
| 113 | + bundleId: com.apple.Preferences |
| 114 | + - echo: Tap General |
| 115 | + - tool: gesture-tap |
| 116 | + args: |
| 117 | + udid: ABC |
| 118 | + x: 0.5 |
| 119 | + y: 0.35 |
| 120 | + - echo: Tap About |
| 121 | + - tool: gesture-tap |
| 122 | + args: |
| 123 | + udid: ABC |
| 124 | + x: 0.5 |
| 125 | + y: 0.17 |
| 126 | +``` |
| 127 | +
|
| 128 | +## 9. When to Proactively Record a Flow |
| 129 | +
|
| 130 | +You do not need the user to ask for a flow. Record one proactively when you recognize any of these patterns: |
| 131 | +
|
| 132 | +- **About to re-profile**: You completed a profiling session and are about to apply a fix and re-profile. Record the interaction steps now so the re-profile replays them identically (see `argent-react-native-profiler` and `argent-native-profiler` skills). |
| 133 | +- **Repeating steps**: You have already performed a multi-step interaction sequence once and the task requires doing it again (comparison, retry, re-test). |
| 134 | +- **Complex path discovered**: You worked through a non-trivial sequence of taps/swipes/navigation to reach a desired app state. Capture it before it is lost. |
| 135 | +- **User says "again" / "one more time"**: Any request to redo what you just did is a signal to record first, then replay. |
| 136 | + |
| 137 | +## 10. Flow Self-Improvement |
| 138 | + |
| 139 | +Flows break. UI layouts change, coordinates drift, screens get added or removed. When `flow-execute` returns a failure, follow this procedure to diagnose and fix the flow instead of silently re-recording or giving up. |
| 140 | + |
| 141 | +### 10.1 Classify the Result |
| 142 | + |
| 143 | +After every `flow-execute`, classify the outcome before proceeding: |
| 144 | + |
| 145 | +| Outcome | Signal | Action | |
| 146 | +| ---------------------- | --------------------------------------------------------------------- | ------------------ | |
| 147 | +| **Success** | All steps completed, final screenshot shows expected state | Continue with task | |
| 148 | +| **Hard error** | A step has `ERROR` in the result β engine stopped there | Enter Β§10.2 | |
| 149 | +| **Silent misfire** | All steps completed but final screenshot shows wrong screen | Enter Β§10.2 | |
| 150 | +| **Partial divergence** | Intermediate screenshot shows wrong state even though later steps ran | Enter Β§10.2 | |
| 151 | + |
| 152 | +For silent misfires and partial divergence, echo annotations (Β§10.5) are your reference for what each screen _should_ look like. |
| 153 | + |
| 154 | +### 10.2 Diagnose |
| 155 | + |
| 156 | +1. Note the failure step index and error message (if hard error). |
| 157 | +2. Call `screenshot` to see where the app actually is now. |
| 158 | +3. Call `describe` or `debugger-component-tree` to get the current element tree. |
| 159 | +4. Compare current state to what the failed step expected. Classify the root cause: |
| 160 | + |
| 161 | +| Root cause | Symptoms | |
| 162 | +| ---------------- | --------------------------------------------------------------- | |
| 163 | +| Coordinate drift | Tap succeeded but hit wrong element; elements shifted positions | |
| 164 | +| Missing element | Target element not present in element tree | |
| 165 | +| Wrong screen | Screenshot shows entirely different page than expected | |
| 166 | +| Timing | Element exists in tree but tap missed; loading spinner visible | |
| 167 | +| State mismatch | First step fails β executionPrerequisite was not actually met | |
| 168 | + |
| 169 | +5. State the diagnosis in one sentence before attempting any correction. |
| 170 | + |
| 171 | +### 10.3 Correct |
| 172 | + |
| 173 | +Choose the lightest strategy that fits: |
| 174 | + |
| 175 | +**Strategy 1 β Edit the YAML** (coordinate drift, parameter changes). |
| 176 | +Read `.argent/flows/<flow-name>.yaml`, update the broken step's `x`/`y`, `bundleId`, `text`, or other args. Re-run `flow-execute` to verify. |
| 177 | + |
| 178 | +**Strategy 2 β Manual recovery + continue** (timing/transient issues, one-off replay). |
| 179 | +Manually execute the failed step with corrected coordinates from Β§10.2 discovery, then manually execute remaining steps. Does not fix the YAML β use only when re-recording is not worth it. |
| 180 | + |
| 181 | +**Strategy 3 β Re-record from failure point** (structural changes, new intermediate screens). |
| 182 | +Navigate the app to the state just before the failure point. Call `flow-start-recording` with the same flow name (overwrites). Re-add the working prefix steps via `flow-add-step`, then continue recording new steps from the divergence point. Call `flow-finish-recording`. |
| 183 | + |
| 184 | +**Strategy 4 β Full re-record** (major changes, unclear diagnosis, or 3+ broken steps). |
| 185 | +Reset the app to prerequisite state (`restart-app` + `launch-app`). Record from scratch with the same flow name. |
| 186 | + |
| 187 | +**Decision heuristic:** |
| 188 | + |
| 189 | +- 1 step broken, parameter-only change β Strategy 1 |
| 190 | +- 1 step broken, transient issue, not worth persisting β Strategy 2 |
| 191 | +- 2β3 steps broken or flow structure partially changed β Strategy 3 |
| 192 | +- 3+ steps broken, or unclear root cause β Strategy 4 |
| 193 | +- Flow used for profiling comparison (must be identical) β Strategy 4 |
| 194 | + |
| 195 | +### 10.4 Verify and Bound Retries |
| 196 | + |
| 197 | +After applying a correction, re-run `flow-execute` to verify. |
| 198 | + |
| 199 | +- If it succeeds β done. Report what changed (e.g. "Fixed step 4: updated tap coordinates from 0.5,0.35 to 0.5,0.42"). |
| 200 | +- If it fails at a **different** step β return to Β§10.2 for a second attempt. |
| 201 | +- If this is already the second correction attempt β **stop**. Report the diagnosis to the user and recommend a full re-record or manual investigation. |
| 202 | + |
| 203 | +**Hard cap: 2 correction cycles.** Do not enter an unbounded fix loop. |
| 204 | + |
| 205 | +### 10.5 Making Flows Resilient |
| 206 | + |
| 207 | +Apply these when recording new flows to reduce future breakage: |
| 208 | + |
| 209 | +- **Echo expected state, not just actions.** Write `"On Settings > General screen, about to tap About"` not `"Tap About"`. During diagnosis these tell you what the screen _should_ look like. |
| 210 | +- **Add screenshot steps after critical navigation.** Insert `screenshot` steps after screen transitions. These produce images in the flow result you can inspect during diagnosis. |
| 211 | +- **Write specific executionPrerequisites.** `"App on home tab, user logged in, simulator UDID is <X>"` β not `"App running"`. Verify with `screenshot` + `describe` before acknowledging. |
| 212 | +- **Prefer launch-app / open-url over navigation chains.** Deep links are more resilient to layout changes than tap sequences. |
| 213 | +- **Echo accessibility labels for coordinate taps.** When recording a tap, add an echo with the target's label or testID: `"Tapping 'Submit' button (testID: submit-btn) at 0.5, 0.82"`. During repair, use `describe` to find the element by label and update coordinates. Only use `screenshot` for permission or system overlays when `describe` cannot expose the target reliably. |
0 commit comments