Architecture
SCW-AI is a single-file Node.js CLI application built around Puppeteer for browser automation.
Overview
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
│ CLI Args │────▶│ Puppeteer │────▶│ Challenge Page │
│ + .env │ │ Browser │ │ (SCW Portal) │
└─────────────┘ └──────────────┘ └────────┬────────┘
│
┌────────▼────────┐
│ challenge-iframe │
│ (embedded app) │
└────────┬────────┘
│
┌─────────────┬──────┴──────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Default │ │ New │ │ Fix │
│Collector │ │Collector │ │Collector │
└────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────┐
│ Formatter + Clipboard │
└──────────────────────────────────────┘
Key modules
All code lives in src/index.js. The major functions are:
Entry & configuration
| Function | Purpose |
|---|---|
loadEnv() | Zero-dependency .env file loader |
parseArgs(argv) | Custom argument parser supporting flags, named params, and positional args |
createPrompter() | Interactive readline wrapper for missing arguments |
main() | Orchestrates the full pipeline |
Browser automation
| Function | Purpose |
|---|---|
findChallengeFrame(page) | Locates the challenge iframe by name or URL pattern with retry logic |
page.evaluateOnNewDocument() | Seeds localStorage with the session ID before page load |
Data collection
| Function | Mode | Purpose |
|---|---|---|
collectChallengeData() | Default | Collects question, answers, tabs, and solutions |
collectExperimentalNewData() | --new | Collects vulnerability category and highlighted files |
collectExperimentalFixData() | --fix | Collects side-by-side diffs for each solution |
Output formatting
| Function | Mode | Purpose |
|---|---|---|
formatPrompt() | Default | Formats title, question, options, code panels |
formatNewPrompt() | --new | Formats category and file contents |
formatFixDiffPrompt() | --fix | Formats unified diffs per solution |
Selector strategy
The tool uses extensive arrays of CSS selectors to handle different versions of the SCW UI:
- Question selectors: 20+ patterns covering
data-testid,data-test-locator, Material-UI classes, and semantic HTML - Answer selectors: Similar breadth for option/answer containers
- Code selectors: Targets Monaco editor,
<pre>/<code>elements, MUI tables, and tree items
This multi-selector approach ensures resilience against UI framework updates.
Data flow
- Parse CLI arguments and environment variables
- Launch Puppeteer with headless/headed mode
- Seed localStorage with the session ID via
evaluateOnNewDocument - Navigate to the challenge URL, wait for
networkidle2 - Find the challenge iframe (retry for up to 20 seconds)
- Collect data by running
frame.evaluate()which executes in-browser JavaScript - Format the collected data into markdown
- Copy to clipboard via
pbcopy(macOS)