@muggleai/works 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ ---
2
+ name: test-feature-local
3
+ description: Test a feature's user experience on localhost. Sync entities in cloud (muggle-remote-* tools), then execute locally (muggle-local-* tools) against localhost. Requires explicit approval before launching electron-app.
4
+ ---
5
+
6
+ # Test Feature Locally (Cloud-First Approach)
7
+
8
+ Test a feature's user experience on a local web app using a cloud-first workflow:
9
+ - **muggle-remote-* tools**: Authentication and all entity management (projects, use cases, test cases)
10
+ - **muggle-local-* tools**: Local execution, results viewing, and publishing
11
+
12
+ ## Design Principle
13
+
14
+ **"Create remotely, execute locally"** - All entity management happens in the cloud via `muggle-remote-*` tools. Local `muggle-local-*` tools only handle execution and results.
15
+
16
+ ## Workflow Overview
17
+
18
+ ```
19
+ muggle-remote-auth-login → Authenticate with Muggle AI
20
+
21
+ muggle-remote-project-* → List projects → [Prompt user to pick]
22
+
23
+ muggle-remote-use-case-* → List use cases → [Prompt user to pick]
24
+
25
+ muggle-remote-test-case-* → List test cases → [Prompt user to pick]
26
+
27
+ muggle-remote-test-script-list → Check for existing scripts
28
+
29
+ [Analyze git changes → recommend replay or regenerate]
30
+
31
+ muggle-local-execute-replay OR muggle-local-execute-test-generation
32
+
33
+ muggle-local-run-result-* → View execution results
34
+
35
+ muggle-local-publish-test-script → Publish script back to cloud
36
+ ```
37
+
38
+ ## Prerequisites
39
+
40
+ - MCP server running with both `muggle-remote-*` and `muggle-local-*` tools available
41
+ - Target local app running (e.g., `http://localhost:3000`)
42
+ - Feature description from user, or repo changes to analyze
43
+
44
+ ## Tool Namespace Summary
45
+
46
+ | Namespace | Purpose | Examples |
47
+ | :-------------------- | :-------------------------------- | :----------------------------------------------------------- |
48
+ | `muggle-remote-auth-*`| Authentication | `muggle-remote-auth-login`, `muggle-remote-auth-status` |
49
+ | `muggle-remote-*` | Cloud entity management | `muggle-remote-project-create`, `muggle-remote-test-case-create` |
50
+ | `muggle-local-*` | Local execution & results | `muggle-local-execute-test-generation` |
51
+
52
+ ## Step 0: Authentication (Required)
53
+
54
+ Always verify auth before testing. Auth tools are in `muggle-remote-*` namespace.
55
+
56
+ 1. Call `muggle-remote-auth-status`
57
+ 2. Check the response:
58
+ - **If authenticated and not expired**: Proceed to Step 1
59
+ - **If not authenticated or token expired**: Continue to step 3
60
+ 3. Call `muggle-remote-auth-login` to start authentication
61
+ 4. If login remains pending, call `muggle-remote-auth-poll`
62
+ 5. Proceed only when authenticated
63
+
64
+ ### Handling Expired Tokens
65
+
66
+ If `muggle-remote-auth-status` shows expired credentials (check `expiresAt` field):
67
+
68
+ 1. **Token expired**: Call `muggle-remote-auth-login` to re-authenticate
69
+ 2. **Login fails with "unauthorized_client"**: This indicates environment mismatch
70
+ - Check if MCP is configured for the correct environment (production vs dev)
71
+ - User may need to update `MUGGLE_MCP_PROMPT_SERVICE_TARGET` in their MCP config
72
+ - After config change, user must restart Cursor and retry
73
+
74
+ ### Authentication Failure Recovery
75
+
76
+ If authentication repeatedly fails:
77
+
78
+ 1. Suggest user run `muggle logout` then `muggle login` from terminal
79
+ 2. Or delete credential files manually: `~/.muggle-ai/auth.json` and `~/.muggle-ai/credentials.json`
80
+ 3. Ensure MCP configuration has correct environment variable set
81
+
82
+ ## Step 1: Select or Create Cloud Project
83
+
84
+ Use `muggle-remote-*` tools for all project management.
85
+
86
+ ### Option A: Use Existing Cloud Project (Preferred)
87
+
88
+ 1. Call `muggle-remote-project-list` to list available projects
89
+ 2. Analyze and rank by relevance to user's request (name, description, URL match)
90
+ 3. **Recommend the best match** with reasoning, present other options
91
+ 4. **Confirm with user** before proceeding
92
+ 5. Note the `projectId` for subsequent calls
93
+
94
+ ### Option B: Create New Cloud Project
95
+
96
+ 1. Propose project details and ask user confirmation:
97
+ - `projectName`: Project name
98
+ - `description`: Project description
99
+ - `url`: Production URL (will be replaced with localhost during local execution)
100
+ 2. Call `muggle-remote-project-create` with the final project details
101
+
102
+
103
+ ## Step 2: Analyze Current Changes (Optional)
104
+
105
+ When user says "test my changes" or scope is vague, inspect repo deltas:
106
+
107
+ ```bash
108
+ git status
109
+ git diff
110
+ git diff --cached
111
+ git log -3 --oneline
112
+ ```
113
+
114
+ Extract impacted feature areas to prioritize use cases/test cases.
115
+
116
+ ## Step 3: Select or Create Cloud Use Cases
117
+
118
+ Use `muggle-remote-*` tools for use case management.
119
+
120
+ ### Option A: Use Existing Cloud Use Cases (Preferred)
121
+
122
+ 1. Call `muggle-remote-use-case-list` with the project ID
123
+ 2. Analyze and rank by relevance to user's feature/changes (title, user story match)
124
+ 3. **Recommend the best match** with reasoning, present other options
125
+ 4. **Confirm with user** before proceeding
126
+ 5. Note the `useCaseId` for test case selection
127
+
128
+ ### Option B: Create New Cloud Use Cases
129
+
130
+ 1. Call `muggle-remote-use-case-create-from-prompts`:
131
+ - `projectId`: The cloud project ID
132
+ - `prompts`: Array of natural language descriptions
133
+
134
+ Or use the two-step flow:
135
+ 1. Call `muggle-remote-use-case-prompt-preview` to generate preview
136
+ 2. Review and confirm to create
137
+
138
+ ## Step 4: Select or Create Cloud Test Cases
139
+
140
+ Use `muggle-remote-*` tools for test case management.
141
+
142
+ ### Option A: Use Existing Cloud Test Cases (Preferred)
143
+
144
+ 1. Call `muggle-remote-test-case-list-by-use-case` with the use case ID
145
+ 2. Analyze and rank by relevance to user's testing goal (title, goal, instructions match)
146
+ 3. **Recommend the best match** with reasoning, present other options
147
+ 4. **Confirm with user** before proceeding
148
+ 5. Note the `testCaseId` for execution
149
+
150
+ ### Option B: Create New Cloud Test Cases
151
+
152
+ 1. Call `muggle-remote-test-case-generate-from-prompt`:
153
+ - `projectId`: The cloud project ID
154
+ - `useCaseId`: The use case ID
155
+ - `instruction`: Natural language description of what to test
156
+
157
+ 2. Then call `muggle-remote-test-case-create` to save the generated test case
158
+
159
+ When multiple candidates match:
160
+ - Group by use case
161
+ - Mark impacted candidates (if change analysis exists)
162
+ - Ask user whether to run all impacted or specific cases
163
+
164
+ ## Step 5: Execute Test Locally
165
+
166
+ Use `muggle-remote-*` tools to fetch details, then `muggle-local-*` tools for local execution.
167
+
168
+ ### Check for Existing Scripts First
169
+
170
+ 1. **Check for existing scripts**: Call `muggle-remote-test-script-list` with the project ID
171
+ - Filter results by `testCaseId` to find scripts for the selected test case
172
+
173
+ 2. **If no existing script found**: Proceed directly to generate new script
174
+
175
+ 3. **If existing script found**: Analyze changes and make a recommendation
176
+
177
+ ### Analyze Changes to Recommend Replay vs Regenerate
178
+
179
+ When an existing script is found, analyze the current git changes to make an informed recommendation:
180
+
181
+ 1. **Inspect repo changes**:
182
+ ```bash
183
+ git diff --name-only
184
+ git diff
185
+ ```
186
+
187
+ 2. **Classify the change impact**:
188
+ - **Significant (user-flow level)**: Changes to UI components, page layouts, navigation, form fields, button labels, or interaction flows that the test script interacts with
189
+ - **Minor (non-user-flow)**: Backend logic, API changes, styling tweaks, refactoring, or changes to unrelated features
190
+
191
+ 3. **Make recommendation to user**:
192
+ - **Recommend REGENERATE** if significant user-flow changes detected:
193
+ > "I found an existing script, but detected significant UI/flow changes in [affected areas]. Recommend regenerating the test script to capture the new flow. Proceed with regeneration?"
194
+ - **Recommend REPLAY** if only minor changes or no relevant changes:
195
+ > "I found an existing script and the changes appear minor (no user-flow impact). Recommend replaying the existing script for faster execution. Proceed with replay?"
196
+
197
+ 4. **Let user decide**: Present both options with the recommendation highlighted, allow user to override
198
+
199
+ ### Option A: Replay Existing Script
200
+
201
+ 1. **Fetch script details**: Call `muggle-remote-test-script-get` with the test script ID
202
+ - This returns: `id`, `name`, `testCaseId`, `actionScript`, `url`
203
+
204
+ 2. **Execute locally**: Call `muggle-local-execute-replay`:
205
+ - `testScript`: The full test script object from step 1
206
+ - `localUrl`: The localhost URL
207
+ - `approveElectronAppLaunch`: **Must be `true`** (requires explicit user approval)
208
+
209
+ ### Option B: Generate New Script
210
+
211
+ 1. **Fetch test case details**: Call `muggle-remote-test-case-get` with the test case ID
212
+ - This returns: `id`, `title`, `goal`, `expectedResult`, `precondition`, `instructions`, `url`
213
+
214
+ 2. **Execute locally**: Call `muggle-local-execute-test-generation`:
215
+ - `testCase`: The full test case object from step 1
216
+ - `localUrl`: The localhost URL (e.g., `http://localhost:3000`)
217
+ - `approveElectronAppLaunch`: **Must be `true`** (requires explicit user approval)
218
+
219
+ ### Explicit Approval Requirement (Critical)
220
+
221
+ Before calling execution tools, get explicit user approval to launch Electron app.
222
+
223
+ **Never** set `approveElectronAppLaunch: true` without user confirmation.
224
+
225
+ ## Step 6: View and Summarize Results
226
+
227
+ Use `muggle-local-*` tools for results:
228
+
229
+ - `muggle-local-run-result-list` - List recent runs (optionally filtered by `cloudTestCaseId`)
230
+ - `muggle-local-run-result-get` - Get detailed run info including screenshots, action script, and ending state
231
+
232
+ **Always print the ending state** after execution completes. Use the `runId` returned by `muggle-local-execute-test-generation` or `muggle-local-execute-replay`, call `muggle-local-run-result-get`, then report:
233
+
234
+ - **Status:** passed / failed
235
+ - **Duration:** execution time in ms
236
+ - **Steps generated:** number of action script steps (for generation runs)
237
+ - **Artifacts path:** where the user can view the action script and screenshots (e.g. `~/.muggle-ai/sessions/{runId}/`)
238
+
239
+ Tell the user they can open the artifacts folder to see:
240
+ - `action-script.json` — generated test steps
241
+ - `results.md` — step-by-step report with screenshot links
242
+ - `screenshots/` — per-step images (`step-001.png`, `step-002.png`, …)
243
+
244
+ For batch runs, return a compact summary table/list and print the ending state for the most recent run.
245
+
246
+ ## Step 7: Publish to Cloud (Optional)
247
+
248
+ After successful local execution, offer to publish the generated script to cloud.
249
+
250
+ 1. Call `muggle-local-publish-test-script`:
251
+ - `runId`: The run result ID from step 5
252
+ - `cloudTestCaseId`: The cloud test case ID
253
+
254
+ This uploads the generated action script to the cloud for future replays.
255
+
256
+ ## Quick Reference
257
+
258
+ ### Authentication (muggle-remote-auth-*)
259
+
260
+ | Action | Tool |
261
+ | :----------- | :---------------------------- |
262
+ | Check auth | `muggle-remote-auth-status` |
263
+ | Start login | `muggle-remote-auth-login` |
264
+ | Poll login | `muggle-remote-auth-poll` |
265
+ | Logout | `muggle-remote-auth-logout` |
266
+
267
+ ### Cloud Entity Management (muggle-remote-*)
268
+
269
+ | Action | Tool |
270
+ | :---------------------- | :-------------------------------------------- |
271
+ | List projects | `muggle-remote-project-list` |
272
+ | Create project | `muggle-remote-project-create` |
273
+ | Get project | `muggle-remote-project-get` |
274
+ | List use cases | `muggle-remote-use-case-list` |
275
+ | Create use cases | `muggle-remote-use-case-create-from-prompts` |
276
+ | List test cases | `muggle-remote-test-case-list-by-use-case` |
277
+ | Generate test cases | `muggle-remote-test-case-generate-from-prompt`|
278
+ | Create test case | `muggle-remote-test-case-create` |
279
+ | Get test case | `muggle-remote-test-case-get` |
280
+ | List test scripts | `muggle-remote-test-script-list` |
281
+ | Get test script | `muggle-remote-test-script-get` |
282
+
283
+ ### Local Execution (muggle-local-*)
284
+
285
+ | Action | Tool |
286
+ | :-------------------- | :------------------------------------ |
287
+ | Check local status | `muggle-local-check-status` |
288
+ | List sessions | `muggle-local-list-sessions` |
289
+ | Generate script | `muggle-local-execute-test-generation`|
290
+ | Replay script | `muggle-local-execute-replay` |
291
+ | Cancel execution | `muggle-local-cancel-execution` |
292
+ | List run results | `muggle-local-run-result-list` |
293
+ | Get run details | `muggle-local-run-result-get` |
294
+ | List local scripts | `muggle-local-test-script-list` |
295
+ | Get local script | `muggle-local-test-script-get` |
296
+ | Publish script | `muggle-local-publish-test-script` |
297
+
298
+ ## Example Interaction
299
+
300
+ **User:** "Test my login changes on localhost:3999"
301
+
302
+ **Agent flow:**
303
+
304
+ 1. `muggle-remote-auth-status` (login if required using `muggle-remote-auth-login`)
305
+
306
+ 2. `muggle-remote-project-list` to find existing project
307
+ - If found: Use existing project ID
308
+ - If not found: `muggle-remote-project-create` with production URL
309
+
310
+ 3. Analyze git diff to identify auth/login impact
311
+
312
+ 4. `muggle-remote-use-case-list` to find login-related use case
313
+ - If not found: `muggle-remote-use-case-create-from-prompts` with login user story
314
+
315
+ 5. `muggle-remote-test-case-list-by-use-case` to find relevant test cases
316
+ - If not found: `muggle-remote-test-case-generate-from-prompt` + `muggle-remote-test-case-create`
317
+
318
+ 6. **Check for existing scripts**: `muggle-remote-test-script-list` filtered by test case ID
319
+ - If script exists: Analyze git diff from step 3
320
+ - If changes affect user flow (UI components, navigation, forms): Recommend regenerate
321
+ - If changes are minor (backend, styling, unrelated): Recommend replay
322
+ - Present recommendation with both options to user
323
+
324
+ 7. Ask user for approval to launch Electron app
325
+
326
+ 8. **If replaying**: `muggle-remote-test-script-get` then `muggle-local-execute-replay`
327
+ **If generating new**: `muggle-remote-test-case-get` then `muggle-local-execute-test-generation`:
328
+ - `localUrl`: "http://localhost:3999"
329
+ - `approveElectronAppLaunch`: true
330
+
331
+ 9. `muggle-local-run-result-get` with the `runId` from the execution result to view results
332
+
333
+ 10. **Print the ending state** to user: status, duration, steps count, and artifacts path. Tell the user they can open the artifacts folder to view action script (`action-script.json`), step report (`results.md`), and screenshots (`step-001.png`, `step-002.png`, …). Summarize pass/fail.
334
+
335
+ 11. Offer `muggle-local-publish-test-script` to upload script to cloud
336
+
337
+ ## Notes
338
+
339
+ - **Cloud-first**: All entity management happens via `muggle-remote-*` tools
340
+ - **Fetch-then-execute**: Call `muggle-remote-test-case-get` or `muggle-remote-test-script-get` first, then pass the full object to `muggle-local-execute-*` tools
341
+ - **Local execution only**: `muggle-local-*` tools have no cloud dependencies - they receive all data they need as input
342
+ - **URL replacement**: The `localUrl` parameter replaces the cloud URL during local execution
343
+ - **Explicit approval required**: Never launch Electron without user confirmation
344
+ - Secrets and workflow files are managed via `muggle-remote-secret-*` and `muggle-remote-workflow-*` cloud tools