@canivel/ralph 0.2.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.
- package/.agents/ralph/PROMPT_build.md +126 -0
- package/.agents/ralph/agents.sh +15 -0
- package/.agents/ralph/config.sh +25 -0
- package/.agents/ralph/log-activity.sh +15 -0
- package/.agents/ralph/loop.sh +1001 -0
- package/.agents/ralph/references/CONTEXT_ENGINEERING.md +126 -0
- package/.agents/ralph/references/GUARDRAILS.md +174 -0
- package/AGENTS.md +20 -0
- package/README.md +266 -0
- package/bin/ralph +766 -0
- package/diagram.svg +55 -0
- package/examples/commands.md +46 -0
- package/package.json +39 -0
- package/ralph.webp +0 -0
- package/skills/commit/SKILL.md +219 -0
- package/skills/commit/references/commit_examples.md +292 -0
- package/skills/dev-browser/SKILL.md +211 -0
- package/skills/dev-browser/bun.lock +443 -0
- package/skills/dev-browser/package-lock.json +2988 -0
- package/skills/dev-browser/package.json +31 -0
- package/skills/dev-browser/references/scraping.md +155 -0
- package/skills/dev-browser/scripts/start-relay.ts +32 -0
- package/skills/dev-browser/scripts/start-server.ts +117 -0
- package/skills/dev-browser/server.sh +24 -0
- package/skills/dev-browser/src/client.ts +474 -0
- package/skills/dev-browser/src/index.ts +287 -0
- package/skills/dev-browser/src/relay.ts +731 -0
- package/skills/dev-browser/src/snapshot/__tests__/snapshot.test.ts +223 -0
- package/skills/dev-browser/src/snapshot/browser-script.ts +877 -0
- package/skills/dev-browser/src/snapshot/index.ts +14 -0
- package/skills/dev-browser/src/snapshot/inject.ts +13 -0
- package/skills/dev-browser/src/types.ts +34 -0
- package/skills/dev-browser/tsconfig.json +36 -0
- package/skills/dev-browser/vitest.config.ts +12 -0
- package/skills/prd/SKILL.md +235 -0
- package/tests/agent-loops.mjs +79 -0
- package/tests/agent-ping.mjs +39 -0
- package/tests/audit.md +56 -0
- package/tests/cli-smoke.mjs +47 -0
- package/tests/real-agents.mjs +127 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dev-browser
|
|
3
|
+
description: Browser automation with persistent page state. Use when users ask to navigate websites, fill forms, take screenshots, extract web data, test web apps, or automate browser workflows. Trigger phrases include "go to [url]", "click on", "fill out the form", "take a screenshot", "scrape", "automate", "test the website", "log into", or any browser interaction request.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Dev Browser Skill
|
|
7
|
+
|
|
8
|
+
Browser automation that maintains page state across script executions. Write small, focused scripts to accomplish tasks incrementally. Once you've proven out part of a workflow and there is repeated work to be done, you can write a script to do the repeated work in a single execution.
|
|
9
|
+
|
|
10
|
+
## Choosing Your Approach
|
|
11
|
+
|
|
12
|
+
- **Local/source-available sites**: Read the source code first to write selectors directly
|
|
13
|
+
- **Unknown page layouts**: Use `getAISnapshot()` to discover elements and `selectSnapshotRef()` to interact with them
|
|
14
|
+
- **Visual feedback**: Take screenshots to see what the user sees
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
|
|
18
|
+
Two modes available. Ask the user if unclear which to use.
|
|
19
|
+
|
|
20
|
+
### Standalone Mode (Default)
|
|
21
|
+
|
|
22
|
+
Launches a new Chromium browser for fresh automation sessions.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
./skills/dev-browser/server.sh &
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add `--headless` flag if user requests it. **Wait for the `Ready` message before running scripts.**
|
|
29
|
+
|
|
30
|
+
### Extension Mode
|
|
31
|
+
|
|
32
|
+
Connects to user's existing Chrome browser. Use this when:
|
|
33
|
+
|
|
34
|
+
- The user is already logged into sites and wants you to do things behind an authed experience that isn't local dev.
|
|
35
|
+
- The user asks you to use the extension
|
|
36
|
+
|
|
37
|
+
**Important**: The core flow is still the same. You create named pages inside of their browser.
|
|
38
|
+
|
|
39
|
+
**Start the relay server:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
cd skills/dev-browser && npm i && npm run start-extension &
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Wait for `Waiting for extension to connect...` followed by `Extension connected` in the console. To know that a client has connected and the browser is ready to be controlled.
|
|
46
|
+
**Workflow:**
|
|
47
|
+
|
|
48
|
+
1. Scripts call `client.page("name")` just like the normal mode to create new pages / connect to existing ones.
|
|
49
|
+
2. Automation runs on the user's actual browser session
|
|
50
|
+
|
|
51
|
+
If the extension hasn't connected yet, tell the user to launch and activate it. Download link: https://github.com/SawyerHood/dev-browser/releases
|
|
52
|
+
|
|
53
|
+
## Writing Scripts
|
|
54
|
+
|
|
55
|
+
> **Run all scripts from `skills/dev-browser/` directory.** The `@/` import alias requires this directory's config.
|
|
56
|
+
|
|
57
|
+
Execute scripts inline using heredocs:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
cd skills/dev-browser && npx tsx <<'EOF'
|
|
61
|
+
import { connect, waitForPageLoad } from "@/client.js";
|
|
62
|
+
|
|
63
|
+
const client = await connect();
|
|
64
|
+
// Create page with custom viewport size (optional)
|
|
65
|
+
const page = await client.page("example", { viewport: { width: 1920, height: 1080 } });
|
|
66
|
+
|
|
67
|
+
await page.goto("https://example.com");
|
|
68
|
+
await waitForPageLoad(page);
|
|
69
|
+
|
|
70
|
+
console.log({ title: await page.title(), url: page.url() });
|
|
71
|
+
await client.disconnect();
|
|
72
|
+
EOF
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Write to `tmp/` files only when** the script needs reuse, is complex, or user explicitly requests it.
|
|
76
|
+
|
|
77
|
+
### Key Principles
|
|
78
|
+
|
|
79
|
+
1. **Small scripts**: Each script does ONE thing (navigate, click, fill, check)
|
|
80
|
+
2. **Evaluate state**: Log/return state at the end to decide next steps
|
|
81
|
+
3. **Descriptive page names**: Use `"checkout"`, `"login"`, not `"main"`
|
|
82
|
+
4. **Disconnect to exit**: `await client.disconnect()` - pages persist on server
|
|
83
|
+
5. **Plain JS in evaluate**: `page.evaluate()` runs in browser - no TypeScript syntax
|
|
84
|
+
|
|
85
|
+
## Workflow Loop
|
|
86
|
+
|
|
87
|
+
Follow this pattern for complex tasks:
|
|
88
|
+
|
|
89
|
+
1. **Write a script** to perform one action
|
|
90
|
+
2. **Run it** and observe the output
|
|
91
|
+
3. **Evaluate** - did it work? What's the current state?
|
|
92
|
+
4. **Decide** - is the task complete or do we need another script?
|
|
93
|
+
5. **Repeat** until task is done
|
|
94
|
+
|
|
95
|
+
### No TypeScript in Browser Context
|
|
96
|
+
|
|
97
|
+
Code passed to `page.evaluate()` runs in the browser, which doesn't understand TypeScript:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// ✅ Correct: plain JavaScript
|
|
101
|
+
const text = await page.evaluate(() => {
|
|
102
|
+
return document.body.innerText;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ❌ Wrong: TypeScript syntax will fail at runtime
|
|
106
|
+
const text = await page.evaluate(() => {
|
|
107
|
+
const el: HTMLElement = document.body; // Type annotation breaks in browser!
|
|
108
|
+
return el.innerText;
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Scraping Data
|
|
113
|
+
|
|
114
|
+
For scraping large datasets, intercept and replay network requests rather than scrolling the DOM. See [references/scraping.md](references/scraping.md) for the complete guide covering request capture, schema discovery, and paginated API replay.
|
|
115
|
+
|
|
116
|
+
## Client API
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const client = await connect();
|
|
120
|
+
|
|
121
|
+
// Get or create named page (viewport only applies to new pages)
|
|
122
|
+
const page = await client.page("name");
|
|
123
|
+
const pageWithSize = await client.page("name", { viewport: { width: 1920, height: 1080 } });
|
|
124
|
+
|
|
125
|
+
const pages = await client.list(); // List all page names
|
|
126
|
+
await client.close("name"); // Close a page
|
|
127
|
+
await client.disconnect(); // Disconnect (pages persist)
|
|
128
|
+
|
|
129
|
+
// ARIA Snapshot methods
|
|
130
|
+
const snapshot = await client.getAISnapshot("name"); // Get accessibility tree
|
|
131
|
+
const element = await client.selectSnapshotRef("name", "e5"); // Get element by ref
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The `page` object is a standard Playwright Page.
|
|
135
|
+
|
|
136
|
+
## Waiting
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { waitForPageLoad } from "@/client.js";
|
|
140
|
+
|
|
141
|
+
await waitForPageLoad(page); // After navigation
|
|
142
|
+
await page.waitForSelector(".results"); // For specific elements
|
|
143
|
+
await page.waitForURL("**/success"); // For specific URL
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Inspecting Page State
|
|
147
|
+
|
|
148
|
+
### Screenshots
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
await page.screenshot({ path: "tmp/screenshot.png" });
|
|
152
|
+
await page.screenshot({ path: "tmp/full.png", fullPage: true });
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### ARIA Snapshot (Element Discovery)
|
|
156
|
+
|
|
157
|
+
Use `getAISnapshot()` to discover page elements. Returns YAML-formatted accessibility tree:
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
- banner:
|
|
161
|
+
- link "Hacker News" [ref=e1]
|
|
162
|
+
- navigation:
|
|
163
|
+
- link "new" [ref=e2]
|
|
164
|
+
- main:
|
|
165
|
+
- list:
|
|
166
|
+
- listitem:
|
|
167
|
+
- link "Article Title" [ref=e8]
|
|
168
|
+
- link "328 comments" [ref=e9]
|
|
169
|
+
- contentinfo:
|
|
170
|
+
- textbox [ref=e10]
|
|
171
|
+
- /placeholder: "Search"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Interpreting refs:**
|
|
175
|
+
|
|
176
|
+
- `[ref=eN]` - Element reference for interaction (visible, clickable elements only)
|
|
177
|
+
- `[checked]`, `[disabled]`, `[expanded]` - Element states
|
|
178
|
+
- `[level=N]` - Heading level
|
|
179
|
+
- `/url:`, `/placeholder:` - Element properties
|
|
180
|
+
|
|
181
|
+
**Interacting with refs:**
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
const snapshot = await client.getAISnapshot("hackernews");
|
|
185
|
+
console.log(snapshot); // Find the ref you need
|
|
186
|
+
|
|
187
|
+
const element = await client.selectSnapshotRef("hackernews", "e2");
|
|
188
|
+
await element.click();
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Error Recovery
|
|
192
|
+
|
|
193
|
+
Page state persists after failures. Debug with:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
cd skills/dev-browser && npx tsx <<'EOF'
|
|
197
|
+
import { connect } from "@/client.js";
|
|
198
|
+
|
|
199
|
+
const client = await connect();
|
|
200
|
+
const page = await client.page("hackernews");
|
|
201
|
+
|
|
202
|
+
await page.screenshot({ path: "tmp/debug.png" });
|
|
203
|
+
console.log({
|
|
204
|
+
url: page.url(),
|
|
205
|
+
title: await page.title(),
|
|
206
|
+
bodyText: await page.textContent("body").then((t) => t?.slice(0, 200)),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
await client.disconnect();
|
|
210
|
+
EOF
|
|
211
|
+
```
|