Skip to content

refactor: remove code smells and comments, simplify tools and core modules - #321

Merged
JustasMonkev merged 12 commits into
mainfrom
ccr-c60246e9-n8o1g8
Nov 1, 2026
Merged

JustasMonkev merged 12 commits into
mainfrom
ccr-c60246e9-n8o1g8

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Readability refactor across src/. Comments are removed and the code is restructured so it explains itself through names. Tool behavior is preserved. A few user-facing tool descriptions that were wrong are fixed.

Structure

  • Comments: all explanatory comments are gone from src/. License headers, @public tags and lint/TS directives remain. Where a comment carried meaning, the code was renamed or extracted so the name says it.
  • audit_site: the ~500-line handler is split into CrawlScope, CrawlFrontier, OrderedLinkCommits, SessionLossDetector, scanCrawledPage, and report/summary builders.
  • audit_keyboard: issue detection, skip-link activation and focus-trap detection are separate functions. The in-page focus reader is composed of small named helpers.
  • audit_screen_reader and measurement: band counting uses an axis helper and a DisjointSets class, with a groupBy helper and named measurement steps (ref resolution, owner frames, per-frame batches).
  • scan_page_matrix: split into apply / scan / compare / restore / render steps.
  • scan_page and browser_find: report rendering, matcher and snippet windows are extracted. The in-page annotation drawer uses named nested helpers.
  • waitForCompletion: uses a small PageActivity tracker.
  • Context: the InputRecorder subsystem moved out of context.ts into src/inputRecorder.ts.
  • Config: validateResolvedConfig is split into named validators.
  • CLI: program.ts builds the browser backend factory in one place instead of two.

Duplication removed

  • About ten hand-written timer/abort races now share src/utils/timeout.ts (settleWithin, rejectAfterTimeout, rejectOnAbort).
  • Report path reservation and file resource links are shared by all report tools (reserveReportPath, fileResource).
  • Release-once closures, bounded error formatting, late navigation-failure reporting and download file naming each exist once.
  • Magic numbers are named constants.
  • The dead pre-1.61 Playwright _resolveSelector fallback is removed (Playwright is pinned to 1.63).

User-facing fixes

  • Server instructions: they now mention scan_page, the primary single-page scan, which was missing. They also describe scan_page_matrix correctly as viewport, color-scheme, reduced-motion and zoom variants (it previously said "viewports and WCAG tag sets").
  • Timeout ranges: browser_navigation_timeout and browser_default_timeout advertised 0-300000ms, but the schema enforces 30000–1200000. The descriptions and README now state the enforced range.
  • browser_navigation_timeout scope: the description said it only affects the current tab, but it applies to all existing tabs.
  • browser_find validation: argument validation (missing or conflicting text/regex) now lives only in the input schema. Every call goes through schema parsing before the handler runs.

Test harness

  • The direct MCP harness asserted which page dropped the session cookie in its audit_site session-loss checks, while running at the default concurrency of 4. At concurrency 4 the loss is attributed to whichever page checks first, and the culprit appears under concurrentUrls. Those checks now pass concurrency: 1, which is how the tool documents pinning a loss to one page. This check failed before this branch as well.

Verification

Run on Node 24.22.2, the version the project's engines field requires. On the preinstalled Node 22, tests fail before any change because RegExp.escape is missing.

Check Result
npm run lint (oxlint + tsc --noEmit) Clean
npm run build Clean
npm test (vitest) 1961 passed, 5 skipped, 1 failed. The failure (mcp-http.test.ts > keeps wildcard listener :: restricted to loopback hosts) also fails on main in this environment, which has no IPv6 wildcard listener.
npm run knip Reports only tests/transportFixture.ts unused, which main reports too
Direct MCP harness (node .codex/run-mcp-direct-harness.mjs, every tool against a real headless Chromium) 33/33 passed, 0 failed. browser_install is skipped by default. Before this branch: 32 passed, 1 failed (audit_site, see above).
Claude Haiku tool loop (all 34 prompts in .codex/mcp-tool-prompts.tsv, run through claude -p --model haiku with only this server's MCP tools available) 34/34 passed, including browser_install. Every run was served by claude-haiku-5-5.

The Haiku loop reuses the prompts and fixture server from .codex/run-mcp-tool-loop.mjs, but drives Claude Code instead of Codex. Each prompt runs in its own isolated server, and Haiku must report concrete tool output as evidence plus a final PASS/FAIL line. That run surfaced the browser_navigation_timeout description mismatch fixed above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable regressions were found.

Summary

Extracts named helpers across browser tools, audits, recording, and timeout code while removing explanatory comments.

  • Browser tools split their work into named helpers while keeping the same workflows.
  • Browser input recording now lives in its own module.
  • Browser and server waits now use shared timeout helpers.
  • Explanatory comments are removed and timeout wording is brought in line with the enforced range.

No actionable issues were found. Tests were not run.

Reviews (1) · Last reviewed commit: "fix: browser_navigation_timeout descript..." · Reviewed by Greptile

Summary by CodeRabbit

  • New Features
    • Browser automation can now record interactions and generate updated action sequences.
    • Audit reports and screenshots use clearer file handling, and download filenames include timestamps.
    • Page-matrix guidance now covers viewport, color-scheme, reduced-motion, and zoom comparisons.
  • Bug Fixes
    • Increased the maximum browser timeout to 20 minutes.
    • Improved handling of timeout, abort, download, navigation, and server heartbeat failures.
    • Improved page activity waiting and locator generation when selector normalization fails.

claude added 12 commits November 1, 2026 18:00
Extract named helpers (PageActivity, fillField, waitForFirstTextCondition,
readStableRegularFile, find snippet rendering, in-page annotation helpers)
so the code documents itself, drop the dead pre-1.61 Playwright locator
fallback, move browser_find argument validation to the schema only, and fix
timeout tool descriptions to state the enforced 30000-1200000ms range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
Extract variant apply/scan/compare/restore helpers, keyboard issue
detection, skip-link activation, focus-trap detection, an in-page focus
reader composed of small named functions, and shared report path/resource
helpers used by every report-writing tool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
Named band counting with a DisjointSets helper, groupBy for sibling
grouping, aria-hidden inheritance helper, summary rendering helpers, and
named measurement steps (ref resolution, owner frames, per-frame batches).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
…session detector

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
Move the recorder subsystem out of context.ts, replace hand-rolled
timer races with settleWithin/rejectAfterTimeout, dedupe release-once
closures, bounded error formatting, late navigation failure reporting
and download file naming, and name timeout/limit constants. Server
instructions now advertise scan_page and describe scan_page_matrix's
variants accurately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
…heartbeat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
The harness asserted which page dropped the session cookie, but with the
default concurrency of 4 the loss is attributed to whichever page checks
first and the culprit appears under concurrentUrls. The tool documents
concurrency 1 for pinning a loss to exactly one page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ry3T5sGF3JufzTgSc9VU6Y
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T20:14:54.841021Z 9d2b25b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request refactors browser lifecycle management, input recording, site crawling, accessibility audits, and browser tool helpers. It adds shared timeout utilities, changes MCP heartbeat failure handling, updates timeout limits, and adjusts related test expectations.

Changes: Browser lifecycle and bounded operations

Layer / File(s) Summary
Browser lifecycle and bounded operations
src/browserContextFactory.ts, src/browserServerBackend.ts, src/browserSessions.ts, src/context.ts, src/tab.ts, src/response.ts, src/utils/timeout.ts
Browser context startup and cleanup use extracted helpers and shared timeout utilities. Page closing, download error truncation, release callbacks, and timeout handling are consolidated.
Browser-context input recording
src/inputRecorder.ts, src/context.ts
Input recording moves into a per-browser-context recorder hub. The hub distributes actions and signals to recorders and active recording targets.
Site crawl and report flow
src/tools/auditSite.ts, .codex/run-mcp-direct-harness.mjs
The crawl flow separates scope, frontier, ordered link commits, session-loss detection, page scanning, and report generation. Three harness crawl cases set concurrency to one.
Accessibility audits and reports
src/tools/auditKeyboard.ts, src/tools/auditScreenReader.ts, src/tools/screenReaderMeasurement.ts, src/tools/axe.ts, src/tools/scanPageMatrix.ts, src/tools/report.ts, src/tools.ts, tests/tool-policy.test.ts
Audit and measurement logic uses extracted helpers. Report paths and file resources use shared functions. Frame coverage checks and matrix comparison are reorganized, and audit guidance and policy expectations are updated.
Tool execution and browser interaction helpers
src/tools/{utils,wait,files,form,evaluate,keyboard,navigate,network,screenshot,snapshot,tabs,tool,dialogs}.ts, tests/tools-snapshot.test.ts, tests/tools-utils.test.ts
Tool handlers and utility functions use shared or extracted logic for activity waits, locator generation, uploads, validation, screenshots, navigation, and result formatting. Tests now check schema validation and locator string fallbacks.
Configuration, server wiring, and supporting changes
src/config.ts, src/program.ts, src/mcp/*, src/extension/*, src/utils/*, src/vscode/*, src/webmcp.ts, README.md
Configuration checks and browser backend construction move into helpers. MCP heartbeat pings use rejectAfterTimeout; any rejection now reaches the server-close path. The README documents 1,200,000 ms timeout maxima. Many explanatory comments are removed without changing the described implementation behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Possibly related PRs

Suggested reviewers: claude

Merge Risk: Minimal · up to 9d2b2

The refactor preserves the inspected filename, download-error, and heartbeat behavior. No actionable merge blocker remains; merge after normal checks pass.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@JustasMonkev JustasMonkev changed the title refactor: simplify tool handlers and remove explanatory comments refactor: remove code smells and comments, simplify tools and core modules Nov 1, 2026
@JustasMonkev
JustasMonkev merged commit 25cf275 into main Nov 1, 2026
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants