agents-cli-automation 1.0.21 → 1.0.22
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.
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -33,7 +33,8 @@ export default async function initCommand() {
|
|
|
33
33
|
"JavaScript (ES Modules)",
|
|
34
34
|
"Java (Maven + JUnit)",
|
|
35
35
|
"C# (NUnit + .NET)",
|
|
36
|
-
"API+DB+UI Full Stack (All-in-One Template)"
|
|
36
|
+
"API+DB+UI Full Stack (All-in-One Template)",
|
|
37
|
+
"Playwright CLI Agent (Token Efficient - CoPilot Chat)"
|
|
37
38
|
]
|
|
38
39
|
}
|
|
39
40
|
]);
|
|
@@ -53,9 +54,12 @@ export default async function initCommand() {
|
|
|
53
54
|
} else if (language.includes("C#")) {
|
|
54
55
|
templateFile = "playwright-agent-csharp.md";
|
|
55
56
|
templateName = "C#";
|
|
56
|
-
}else if (language.includes("API+DB+UI")) {
|
|
57
|
+
} else if (language.includes("API+DB+UI")) {
|
|
57
58
|
templateFile = "playwright-agent-api-db-ui.md";
|
|
58
59
|
templateName = "API+DB+UI Full Stack";
|
|
60
|
+
} else if (language.includes("Playwright CLI")) {
|
|
61
|
+
templateFile = "playwright-agent-cli.md";
|
|
62
|
+
templateName = "Playwright CLI Agent";
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
const templatePath = path.resolve(__dirname, `../templates/${templateFile}`);
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
name: Playwright CLI Agent - Token Efficient
|
|
2
|
+
description: GitHub Copilot Chat agent using Playwright CLI for near-zero token usage. Browser work runs outside the LLM context.
|
|
3
|
+
argument-hint: "(no args)"
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
# Playwright CLI Agent — Token Efficient with GitHub Copilot Chat
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This agent uses **Playwright CLI** instead of MCP to minimize token usage when working with GitHub Copilot Chat. Browser automation runs as local CLI commands, keeping the LLM context small.
|
|
12
|
+
|
|
13
|
+
### Key Advantage
|
|
14
|
+
|
|
15
|
+
- **Browser actions**: 0 tokens (run as CLI commands)
|
|
16
|
+
- **DOM extraction**: 0 tokens (executes in browser)
|
|
17
|
+
- **Total per task**: ~80–300 tokens vs. thousands with full DOM snapshots
|
|
18
|
+
|
|
19
|
+
## Step-by-Step Token Usage Flow
|
|
20
|
+
|
|
21
|
+
### 1️⃣ Prompt Processing (~10–30 tokens)
|
|
22
|
+
```
|
|
23
|
+
Copilot reads your instruction:
|
|
24
|
+
"Generate JS test data for modal id='hjahdj'"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2️⃣ Agent Reasoning (~20–60 tokens)
|
|
28
|
+
```
|
|
29
|
+
Agent decides:
|
|
30
|
+
Run "npx playwright" or "node extractModal.js"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3️⃣ Playwright CLI Executes (0 tokens)
|
|
34
|
+
```
|
|
35
|
+
Local shell commands run:
|
|
36
|
+
- open page
|
|
37
|
+
- click menu
|
|
38
|
+
- open modal
|
|
39
|
+
- extract fields
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 4️⃣ DOM Extraction in Browser (0 tokens)
|
|
43
|
+
```javascript
|
|
44
|
+
// Runs inside browser, not sent to LLM
|
|
45
|
+
document.querySelectorAll("#hjahdj input, select, textarea")
|
|
46
|
+
|
|
47
|
+
// Returns JSON:
|
|
48
|
+
[
|
|
49
|
+
{ "name":"username", "type":"text" },
|
|
50
|
+
{ "name":"role", "type":"select" }
|
|
51
|
+
]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 5️⃣ JSON Result Returned (~20–100 tokens)
|
|
55
|
+
```
|
|
56
|
+
Agent reads result file and passes to LLM
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 6️⃣ Output Formatting (~30–150 tokens)
|
|
60
|
+
```
|
|
61
|
+
Copilot generates final answer
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Typical Modal with ~20 Fields
|
|
65
|
+
|
|
66
|
+
| Step | Tokens |
|
|
67
|
+
|------|--------|
|
|
68
|
+
| Prompt understanding | 10–30 |
|
|
69
|
+
| Agent reasoning | 20–60 |
|
|
70
|
+
| Playwright CLI execution | 0 |
|
|
71
|
+
| DOM extraction | 0 |
|
|
72
|
+
| JSON returned | 20–100 |
|
|
73
|
+
| Output formatting | 30–150 |
|
|
74
|
+
| **Total** | **~80–300** |
|
|
75
|
+
|
|
76
|
+
## Why CLI is More Token Efficient
|
|
77
|
+
|
|
78
|
+
**With Playwright MCP:**
|
|
79
|
+
- Full DOM snapshot sent to model
|
|
80
|
+
- Accessibility tree included
|
|
81
|
+
- Element metadata attached
|
|
82
|
+
- Result: thousands of tokens
|
|
83
|
+
|
|
84
|
+
**With CLI:**
|
|
85
|
+
- LLM → run shell command
|
|
86
|
+
- Browser → produce file
|
|
87
|
+
- LLM → read small JSON
|
|
88
|
+
- Result: tokens stay minimal
|
|
89
|
+
|
|
90
|
+
## Practical Architecture
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Copilot prompt
|
|
94
|
+
↓
|
|
95
|
+
Agent (reasons ~20–60 tokens)
|
|
96
|
+
↓
|
|
97
|
+
Run CLI script (~0 tokens)
|
|
98
|
+
↓
|
|
99
|
+
Playwright browser automation
|
|
100
|
+
↓
|
|
101
|
+
Extract modal fields / DOM data
|
|
102
|
+
↓
|
|
103
|
+
Return JSON test data (~20–100 tokens)
|
|
104
|
+
↓
|
|
105
|
+
Format final answer (~30–150 tokens)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Common Commands
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Codegen: generates test code by recording actions
|
|
112
|
+
npx playwright codegen https://example.com
|
|
113
|
+
|
|
114
|
+
# Snapshot: captures page state
|
|
115
|
+
npx playwright screenshot https://example.com
|
|
116
|
+
|
|
117
|
+
# Run tests
|
|
118
|
+
npx playwright test
|
|
119
|
+
|
|
120
|
+
# Debug mode
|
|
121
|
+
npx playwright test --debug
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Setup Instructions
|
|
125
|
+
|
|
126
|
+
1. Install Playwright CLI:
|
|
127
|
+
```bash
|
|
128
|
+
npm install -D @playwright/test
|
|
129
|
+
npx playwright install
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
2. Create CLI scripts for your workflows:
|
|
133
|
+
```bash
|
|
134
|
+
mkdir -p scripts
|
|
135
|
+
touch scripts/extract-modal.js
|
|
136
|
+
touch scripts/snapshot.js
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
3. In your agent prompt, reference these CLI commands:
|
|
140
|
+
```
|
|
141
|
+
Run "node scripts/extract-modal.js --modal-id=hjahdj" to get test data
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
4. Use CLI output (JSON files) in your test generation.
|
|
145
|
+
|
|
146
|
+
## Best Practices
|
|
147
|
+
|
|
148
|
+
- **Keep browser scripts minimal**: extract only needed data
|
|
149
|
+
- **Return JSON**: structured output for LLM parsing
|
|
150
|
+
- **Use snapshots**: instead of full DOM dumps
|
|
151
|
+
- **Batch operations**: run multiple CLI commands in sequence, not parallel
|
|
152
|
+
- **Cache results**: reuse JSON between agent calls
|
|
153
|
+
|
|
154
|
+
## Integration with GitHub Copilot Chat
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
You: "Generate test data for the login modal"
|
|
158
|
+
Agent:
|
|
159
|
+
1. Runs: npx playwright screenshot --url=... --selector=".modal"
|
|
160
|
+
2. Runs: node scripts/extract-fields.js
|
|
161
|
+
3. Returns: { "username": "string", "password": "string" }
|
|
162
|
+
Copilot:
|
|
163
|
+
4. Formats final test template
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Performance Benefits
|
|
167
|
+
|
|
168
|
+
- ✅ Instant feedback (no token wait)
|
|
169
|
+
- ✅ Scales to large DOMs (no snapshot overhead)
|
|
170
|
+
- ✅ Reusable CLI scripts across teams
|
|
171
|
+
- ✅ Local-first (no external API calls)
|
|
172
|
+
- ✅ Works offline
|