agentleFS
nicobailonnicobailon/surf-cli/.claude/skills/surf-codebase/SKILL.md

surf-codebase

Skill685 starsChanged 7 days agoMITView on GitHub

Navigate and modify surf-cli codebase - Chrome extension + native host for AI browser automation. Use for surf-cli code work, architecture questions, implementing browser control/CDP/accessibility/network features.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add to TOOLS in native/cli.cjs:158 (args, opts, examples)

    line 15
  2. Very specific:

    Add handler in src/service-worker/index.ts:50 handleMessage() switch

    line 16
  3. Very specific:

    Add method to CDPController class src/cdp/controller.ts:60

    line 22

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

surf-cli Codebase

Architecture

cli.cjs --socket:/tmp/surf.sock--> host.cjs --native-msg--> service-worker/index.ts --CDP/chrome-APIs--> browser

Add CLI Command

  1. Add to TOOLS in native/cli.cjs:158 (args, opts, examples)
  2. Add handler in src/service-worker/index.ts:50 handleMessage() switch
  3. CDP op? → add method src/cdp/controller.ts:60
  4. DOM interaction? → add handler src/content/accessibility-tree.ts:99

Add CDP Operation

  1. Add method to CDPController class src/cdp/controller.ts:60
  2. Use this.send(tabId, "Domain.method", params)
  3. Handle events in handleCDPEvent() if needed

Core Files

src/service-worker/index.ts (~2500L) - Central msg router, CDP ops, screenshot cache, tab registry

  • Msg types: EXECUTE_CLICK, EXECUTE_TYPE, READ_PAGE, EXECUTE_SCREENSHOT
  • Screenshot cache: generateScreenshotId(), cacheScreenshot(), getScreenshot()
  • Tab names: tabNameRegistry Map<name,tabId>

src/cdp/controller.ts (~1000L) - CDP wrapper, CDPController class

  • Mouse: click(), rightClick(), doubleClick(), hover(), drag()
  • Keyboard: type(), pressKey(), pressKeyChord()
  • Screenshots: captureScreenshot(), captureRegion()
  • Network/Console: enableNetworkTracking(), getNetworkRequests(), getResponseBody(), subscribeToNetwork(), enableConsoleTracking(), getConsoleMessages()
  • Emulation: emulateNetwork(), emulateCPU(), emulateGeolocation()

src/content/accessibility-tree.ts (~1900L) - Content script, generates a11y tree YAML, element interactions

  • Handlers: GENERATE_ACCESSIBILITY_TREE, CLICK_ELEMENT, FORM_INPUT, GET_ELEMENT_COORDINATES, WAIT_FOR_ELEMENT, WAIT_FOR_URL
  • Element refs: e1, e2... in window.__piRefs for stable references

native/cli.cjs (~2100L) - CLI parser, socket client

  • TOOLS: command defs with args/opts
  • ALIASES: shortcut→command map
  • AUTO_SCREENSHOT_TOOLS: commands that auto-capture
  • parseArgs(), sendRequest()

native/host.cjs (~2100L) - Socket server, AI integration

  • handleToolRequest(): main dispatcher
  • mapToolToMessage(): tool→extension msg converter
  • queueAiRequest(): AI request serialization
  • AI clients: chatgptClient, geminiClient, perplexityClient

src/native/port-manager.ts - Extension↔native messaging, auto-reconnect, request/response tracking

Message Flow

  1. CLI: surf click e5
  2. cli.cjs parses → socket → host.cjs
  3. host.cjs routes to EXECUTE_CLICK msg
  4. Native msg → service-worker/index.ts
  5. Service worker: CDP (cdp/controller.ts) or content script (chrome.tabs.sendMessage)
  6. Response flows back to CLI

Debug

  • Extension logs: chrome://extensions → Service Worker → Console
  • Host logs: /tmp/surf-host.log
  • CLI raw output: --json flag

Test

npm run build            # Build ext
npm test                 # Run tests
npm run test:coverage    # Coverage

Element Refs

A11y tree assigns e1, e2... during READ_PAGE. Stored window.__piRefs. Reset each read command.

Network Capture

  • CDP captures via Network.* events cdp/controller.ts:73
  • Storage: /tmp/surf/requests.jsonl
  • Formatters: native/formatters/network.cjs:259

Build/Install

npm run dev              # Watch mode
npm run build            # Prod → dist/
# Load dist/ as unpacked ext
surf install             # Register native host; prints the dist/ folder to load

Gotchas

  • CDP attach: 100-500ms first time/tab
  • chrome:// pages restricted
  • Content script needs page refresh on existing tabs
  • Screenshots auto-resize 1200px unless --full

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.