Skip to main content

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​

FunctionPurpose
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​

FunctionPurpose
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​

FunctionModePurpose
collectChallengeData()DefaultCollects question, answers, tabs, and solutions
collectExperimentalNewData()--newCollects vulnerability category and highlighted files
collectExperimentalFixData()--fixCollects side-by-side diffs for each solution

Output formatting​

FunctionModePurpose
formatPrompt()DefaultFormats title, question, options, code panels
formatNewPrompt()--newFormats category and file contents
formatFixDiffPrompt()--fixFormats 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​

  1. Parse CLI arguments and environment variables
  2. Launch Puppeteer with headless/headed mode
  3. Seed localStorage with the session ID via evaluateOnNewDocument
  4. Navigate to the challenge URL, wait for networkidle2
  5. Find the challenge iframe (retry for up to 20 seconds)
  6. Collect data by running frame.evaluate() which executes in-browser JavaScript
  7. Format the collected data into markdown
  8. Copy to clipboard via pbcopy (macOS)