# Pi LeetCode Practice

A guided LeetCode practice workflow for [Pi](https://github.com/earendil-works/pi-coding-agent): start problems, learn with notes, edit locally, and open LeetCode for manual Run/Submit.

The main idea: **only learn 5 commands**. Everything else happens through a numbered `/lc-next` menu.

## Why this exists

Most LeetCode helpers either expose too many commands, depend on brittle LeetCode judge APIs, or try to automate the browser. This extension is intentionally calmer:

- Fetches public problem data.
- Creates local `problem.md`, `solution.<ext>`, and `notes.md` files.
- Guides practice through a dashboard and numbered action menu.
- Tracks what you learned across problems.
- Opens the LeetCode URL for manual Run/Submit in your normal browser.
- Does **not** require LeetCode cookies for the default workflow.
- Does **not** send your code, notes, cookies, or telemetry anywhere by default.

## Features

- Native Pi extension; no web server required.
- Only 5 user-facing `/lc-` commands.
- Language selection: TypeScript, JavaScript, Python3, C++, Java, Go, Rust.
- Practice dashboard with status, confidence, last action, files, and notes.
- Numbered actions: understand, hint, co-code, edit, debug, run, submit prep, review, solve, learning history.
- `notes.md` per problem with highlights, approach, mistakes, edge cases, and complexity.
- Learning review across past notes and tracked topics.
- Privacy-safe local usage counters in `.pi/leetcode/usage.json`.

## Install

### Try locally from this repo

```bash
npm install
pi -e ./src/leetcode.ts
```

### Project-local install

```bash
mkdir -p .pi/extensions/pi-leetcode
cp src/leetcode.ts .pi/extensions/pi-leetcode/index.ts
/reload
```

### Once published as a Pi package

```bash
pi install npm:pi-leetcode-practice
```

or try without installing:

```bash
pi -e npm:pi-leetcode-practice
```

## Commands

| Command | Purpose |
| --- | --- |
| `/lc-start [titleSlug]` | Start a problem. With no slug, continue current, pick recent, review history, search, or random top-50 |
| `/lc-next` | Show the numbered “What next?” menu for the active problem |
| `/lc-lang` | Choose your LeetCode solution language |
| `/lc-list [search]` | Search/select a problem, then continue with `/lc-start` |
| `/lc-help` | Show help inside Pi |

## Typical flow

```text
/lc-lang
/lc-start 3sum
# choose an action from the numbered menu
/lc-next
# use /lc-next anytime to continue practicing
```

Or start without a slug:

```text
/lc-start
```

You can then choose:

- Continue current problem
- Recent problem
- Review learning history
- Search new problem
- Random top-50 problem

## Files created per problem

```text
leetcode/<titleSlug>/problem.md
leetcode/<titleSlug>/solution.<ext>
leetcode/<titleSlug>/notes.md
```

State and local usage counters:

```text
.pi/leetcode/state.json
.pi/leetcode/usage.json
```

## Learning review

Use `/lc-start` with no slug or `/lc-next` and choose learning history. It scans tracked problems and `notes.md` files to summarize:

- skills practiced
- key lessons
- mistakes to remember
- missing notes files

If you delete `leetcode/`, the review may still know which problems were tracked, but detailed notes are gone unless backed up.

## Privacy

Default behavior is local and privacy-safe:

- No telemetry is sent.
- No code is uploaded by this extension.
- No LeetCode cookies are required.
- Local usage counters stay in `.pi/leetcode/usage.json`.
- Run/Submit opens LeetCode in your normal browser for manual action.

If you publish or fork this project, keep telemetry opt-in only.

## Usage tracking

The extension writes local counters only:

```json
{
  "commands": {
    "lc-start": 3,
    "lc-next": 8
  },
  "actions": {
    "1. Understand": 2,
    "6. Run": 1
  },
  "languages": {
    "javascript": 4
  },
  "difficulties": {
    "Medium": 3
  }
}
```

For public adoption after publishing, use npm downloads and GitHub stars/issues. Do not collect user code or notes.

## Packaging for public release

This repo is configured as a Pi package via `package.json`:

```json
{
  "keywords": ["pi-package", "pi-extension", "leetcode"],
  "pi": {
    "extensions": ["./src/leetcode.ts"]
  }
}
```

To publish to npm you need an npm account:

```bash
npm login
npm publish --access public
```

If you do not have npm login, publish to GitHub first and install via git:

```bash
git tag v0.1.0
git push origin main --tags
pi install git:github.com/YOUR_USER/pi-leetcode-practice@v0.1.0
```

## Quality checks

```bash
npm run typecheck
npm run lint:namespaces
```

`lint:namespaces` verifies every command registered through `pi.registerCommand` starts with `lc-`.

## Legacy live smoke tests

`npm run smoke:live` and `npm run smoke:live:prompt` are legacy API/auth smoke tests. They are not part of the default workflow, which avoids LeetCode judge APIs and opens LeetCode for manual Run/Submit instead.

## License

MIT
