Skip to content

About

A LeetCode-native Python visual debugger that shows what your code actually does—even when it fails or never finishes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LeetYourBrain2Code

English | 繁體中文

A LeetCode-native Python visual debugger that shows what your code actually does—even when it fails or never finishes.

A Chrome Manifest V3 extension that runs beside LeetCode in the Side Panel. It re-executes the Python code and testcase currently in the editor, then turns the resulting execution trace into runtime-state visualization.

Why it exists

This project is built for the moment when you understand an algorithm but your implementation does not behave the way your mental model says it should. Instead of guessing from a wrong answer, runtime error, or stalled run, you can inspect what the code actually did and find where the two began to diverge.

It is a visual debugger—not a LeetCode solver and not a replacement for the LeetCode judge.

How it works

Current Python code + selected testcase case
                ↓
Live scheduler (debounce + latest-wins)
                ↓
Warm bundled Pyodide Web Worker
                ↓
Ordered line-level execution trace
                ↓
RuntimeState + FrameDiff/ObjectDiff
                ↓
RuntimeMutation + BehavioralPattern
                ↓
Expression Evidence
                ↓
Decision Evidence
                ↓
Visual interpretation + Behavioral Evidence Navigation
                ↓
Repeated-transition Trace Folding
                ↓
Trace Outline + Behavioral Timeline + Chrome Side Panel visualization

The Side Panel mirrors the active LeetCode editor while you type; pressing LeetCode Run or Submit is not required to start source synchronization. If the current testcase is already available, the latest runnable Python draft is re-executed automatically after the live debounce. If testcase state is not yet available, code continues to sync and execution waits without clearing the last runnable visualization.

The Side Panel follows the active LeetCode tab in its current Chrome window. Switching between already-open LeetCode problems triggers an exact-tab page-state refresh even when the editor content did not change. Page-state updates from background LeetCode tabs are ignored.

When the active tab is not LeetCode, Live Visualization pauses without clearing the last trace. Returning to LeetCode resumes from the newly active tab automatically.

Playback highlights the current line directly in LeetCode's visible Python editor, alongside the Side Panel visualization. Follow line scrolls only when the current line leaves the viewport; it does not move your editing cursor. A before line label means the displayed state was captured before that line executes. Source edits clear the marker until a matching run is available. If the editor cannot be reached, Code · recorded source keeps the trace's original code available in the panel.

Playback controls stay at the bottom of the workspace. Open Details · variables, output & analysis for supporting evidence, or Settings for input mirrors, baseline controls, and privacy information.

The MVP is designed to expose:

  • the active source line;
  • function calls, returns, exceptions, and the call stack;
  • locals, scalar changes, and container mutations;
  • stdout and return values;
  • captured Expression Evidence for supported assignment / return expressions, including operand, intermediate, and result values, factual min / max candidate selection when it can be proven safely, and List / Matrix overlays for operands, the selected candidate, and assignment targets;
  • captured Decision Evidence for if, elif, and while sites, including nested and / or / not, factual short-circuit states, branch-chain outcomes, repeated while history, and List / Matrix condition-operand highlighting;
  • list state with index/pointer bindings;
  • dedicated Matrix / Grid visualization for complete rectangular 2D list / tuple scalar state, including direct matrix[i][j] focus, negative-index normalization, out-of-bounds requested-cell evidence, runtime-backed cell changes, a bounded focus-aware viewport, and persistent cell inspection;
  • dedicated linked-list visualization for Python objects with next topology, including pointer labels, edge mutation, disconnected fragments, and cycle-safe display;
  • dedicated binary-tree visualization for standard LeetCode TreeNode objects, including active pointers, left / right edge mutation, detached components, and deterministic cycle/shared-child fallback presentation;
  • dedicated graph visualization for standard LeetCode Node(val, neighbors) objects, including direct adjacency-list testcase execution, directed and reciprocal runtime references, multiple components, isolated nodes, edge add/remove states, and node/connection inspection;
  • standard LeetCode level-order binary-tree testcase literals, including null child markers, are decoded into TreeNode objects before tracing;
  • factual behavioral signals for repeated observable state, no observable progress at a repeated execution anchor, and repeated execution/mutation motifs, with direct first/previous/next/last evidence navigation;
  • a behavioral trace timeline with raw scrubbing and compact evidence-span bands while preserving raw Previous/Next/Play navigation;
  • a folded Trace Outline for eligible contiguous RepeatedTransitionPattern regions, with collapsed summaries and expandable motif-repetition ranges;
  • collision-safe Behavioral Timeline subtracks so overlapping same-kind evidence bands remain independently visible;
  • raw Previous / Next / Play navigation remains authoritative even when folded presentation is available;
  • the trace prefix captured before a runtime error, trace limit, or hard timeout.
  • a Failure-First Entry Point for local exception, trace_limit, or timeout captures: it deterministically surfaces one validated behavioral evidence location near termination as an optional Start Here inspection point. It does not move the raw cursor automatically, and Start Here is an inspection priority—not a diagnosis.
  • Call Tree / recursion execution story: visualizes concrete user-function invocations, arguments, parent/child call structure, recursion depth, returns, exceptions, and incomplete timeout/trace prefixes while staying synchronized with the raw trace cursor.
  • Pinned baseline behavioral diff: pin one captured run and compare later executions of the same testcase to surface the earliest safely aligned difference in calls, decisions, control flow, stable mutations, expressions, or frame outcomes.
  • Case-to-Case Behavioral Diff: compare two testcase executions under the same source revision and inspect where their captured behavior first diverges.

Python execution stays off the Side Panel's main thread. Pyodide is bundled with the extension and runs locally in a Web Worker; the MVP does not require a backend.

Graph support v0.1

Supported:

  • standard LeetCode Node(val, neighbors);
  • direct adjacency-list testcase execution;
  • directed and reciprocal runtime references;
  • multiple components and isolated nodes;
  • edge add/remove visualization;
  • node and connection inspection.

Not yet supported:

  • generic dict/list adjacency inference;
  • weighted graphs;
  • custom graph classes;
  • BFS/DFS/shortest-path semantic interpretation.

Matrix / Grid support v0.1

Supported:

  • complete rectangular 2D list / tuple snapshots with scalar cells (int, float, bool, str, or None);
  • direct matrix[row][column] focus for variable and integer-literal operands;
  • Python negative-index normalization and explicit out-of-bounds requested-cell evidence;
  • actual cell changes derived from runtime mutation evidence;
  • a bounded focus-aware viewport and persistent cell inspection;
  • Expression Evidence overlays for captured List / Matrix operands, selected min / max candidates, and assignment targets.
  • Decision Evidence overlays for captured List / Matrix condition operands, kept independent from Expression Evidence styling.

Recorded matrix paths

For explicit assignments such as dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + grid[i][j], the visualizer records the selected predecessor after the assignment appears in the runtime snapshot. Direct boundary additions and source-cell copies are also supported, including zero-valued writes. Matrix names need not be dp or grid.

  • Orange cells and arrows show the accumulated route on both the table and its source grid.
  • Dashed borders mark candidates; a blue border marks the selected predecessor.
  • Select a cell to inspect its route in both matrices. Follow current path resumes following execution.
  • The returned cell's route remains visible at completion. Missing or ambiguous evidence produces an incomplete or unavailable path, without inventing earlier choices.

Path recognition currently requires a separate source matrix and direct numeric cell copies or additions from an upper/left neighbor (including captured min / max choices). In-place updates, arbitrary recurrences and traversal paths are not reconstructed. The displayed route represents captured choices, not a proof that the algorithm found an optimal path.

Not yet supported:

  • ragged, 3D, sparse, or NumPy matrix visualization;
  • alias recovery when the same runtime matrix is reached through another name;
  • focus inference for i + 1, j - 1, or other arbitrary index expressions;
  • DP recurrence or algorithm inference, or expected-vs-actual correctness diagnosis.

Important boundaries

  • completed means local execution returned normally. It does not mean LeetCode Accepted.
  • timeout means the local visualization runtime exceeded its wall-clock limit. It does not mean LeetCode TLE.
  • Failure-First v0.1 evaluates only exception, trace_limit, and timeout; Inspect is user-triggered and the recommendation does not claim a cause or correctness result.
  • Behavioral Signals describe evidence in the captured trace. They do not diagnose an infinite loop, correctness failure, bug, or fix.
  • Expression Evidence describes captured executed computation. It does not infer the correct recurrence, algorithm intent, root cause, or a fix; min / max candidate selection is shown only when the runtime evidence proves it safely.
  • Decision Evidence describes how a supported condition evaluated and which branch Python selected. It does not judge whether that branch was correct.
  • Decision Tracing v0.1 does not decompose chained comparisons, infer for loop semantics, explain break / continue causality, compare execution against an expected path, or apply automatic bug fixes.
  • Trace folding is a deterministic presentation projection over captured raw steps. It does not delete raw events or diagnose why execution failed.
  • Pyodide does not perfectly reproduce LeetCode's judge environment.
  • Testcase synchronization observes LeetCode's visible testcase controls; if the testcase editor has not mounted yet, the Side Panel keeps code synchronized and waits for the testcase.
  • Dedicated TreeNode visualization supports the standard LeetCode binary-tree shape only. Generic dict/list adjacency inference, weighted graphs, custom graph classes, BFS/DFS/shortest-path semantic interpretation, custom/N-ary tree inference, and algorithm-specific DP recurrence inference remain outside the current scope.
  • Web Worker and Pyodide isolation should not be treated as a hardened sandbox for hostile code.

Privacy and local processing

The extension reads the active LeetCode Python editor, visible testcase, and problem metadata to build the visualization. Pyodide is bundled and runs locally in a Web Worker. Code, testcases, traces, and comparison state are not sent to a backend, and v0.1 does not intentionally persist a user-code history. See the privacy policy and Chrome Web Store privacy draft.

Support

Use the bug report form for a reproducible visualizer problem, the integration issue form for LeetCode page or tab-state problems, and the feature request form for scoped improvements. The store support draft explains the fields to include. For technical status, open Settings / Support → Copy diagnostic info and review the report before pasting it into a public issue. Before sharing code or testcase content in a public issue, remove anything you do not want to disclose publicly.

License

This project is released under the MIT License.

Development

Current Chrome Web Store release: v0.1.1.

Release lines are intentionally separated:

  • release/v0.1.x is the production maintenance line for compatibility, correctness, recovery, diagnostics, and release-hardening fixes. v0.1.1 is the current published maintenance release.
  • main is the v0.2.0 development line. The first-divergence Case-to-Case Behavioral Diff slice is implemented; ordered multi-divergence navigation remains deferred to v0.2.x.

Do not publish a v0.2.0 artifact from main until its release gates and versioned release evidence are complete.

Requirements: Node.js and npm.

npm ci
npm test
npm run typecheck
npm run build

After building, load dist/ as an unpacked extension from chrome://extensions.

Project documents

About

A LeetCode-native Python visual debugger that shows what your code actually does—even when it fails or never finishes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages