Purpose
This file documents conventions and practical tips for automated agents (LLM-driven or human) working in this repository. It prefers using the gh CLI for GitHub interactions and Chrome DevTools / CDP (referred to here as "mcp") for e2e debugging. It also recommends a git worktree + branch workflow so multiple agents can work concurrently on the same machine without interfering with each other.
Scope & precedence
- The guidelines in this file apply to the entire repository unless a more deeply nested
AGENTS.mdoverrides them. - Direct system/developer/user instructions (prompts) take precedence over this file.
Quick environment notes
- Package Manager: This project uses
pnpm. Install dependencies withpnpm install. - Node scripts: see
package.jsonfor the authoritative scripts. Common scripts:pnpm dev— starts the Vite dev serverpnpm build— builds a production bundlepnpm preview— preview the buildpnpm test— run unit tests withvitestpnpm test:e2e— run Playwright e2e testspnpm test:e2e:headed— run Playwright e2e tests in headed modepnpm lint/pnpm lint:fix— ESLint + Prettier checks/fixpnpm type-check— TypeScript type check
Workflow: git worktree + branch (recommended for multi-agent)
Rationale: multiple agents and/or editors on the same machine should not share a single working copy. Use git worktree to create an isolated working directory per task/agent.
Example flow (from repository root):
- Create a worktree and new branch in one command:
git worktree add ../worktrees/my-feature -b my-feature— creates../worktrees/my-featureand checks out a new branchmy-featurethere.
- Move into the worktree and work there:
cd ../worktrees/my-feature- Run and edit normally (start the dev server, run tests, make changes).
- Commit locally in the worktree; push when ready:
git add -A && git commit -m "feat: short description of why"git push -u origin my-feature
- Create a PR with
gh(preferred):gh pr create --title "Short title" --body "## Summary\n- bullet 1\n- bullet 2" --base main
Notes:
- Use descriptive branch names and commit messages that explain the purpose (the why) not only the what.
- Avoid
git checkoutin the main working copy while agents are running in their worktrees. - Clean up completed worktrees with
git worktree remove ../worktrees/my-featureand consider pruning stale branches.
Post-merge cleanup (mandatory after every PR merge):
After a PR is merged, always perform these cleanup steps:
- Delete the remote branch (if not auto-deleted by the merge):
gh api repos/OWNER/REPO/git/refs/heads/BRANCH -X DELETE
- Remove the worktree:
git worktree remove ../worktrees/my-feature- Use
--forceif the worktree has stale uncommitted changes that are no longer needed.
- Switch to the main repo and update local main:
cd /path/to/main/repogit fetch origin main && git reset --hard origin/main
- Delete the local feature branch:
git branch -D my-feature
- Prune stale remote refs:
git remote prune origin
- Verify clean state:
git status— should show clean working tree on maingit worktree list— should show only the main working copy
Using gh CLI (preferred) for GitHub interactions
- Authenticate once per machine with
gh auth login. - Create PRs:
gh pr create --title "..." --body "..." --base main. - View PRs and open in browser:
gh pr view --web. - Add reviewers:
gh pr edit --add-reviewer usernameor during creation use--reviewer. - Reference GitHub from automation scripts rather than using the web UI when possible.
E2E tests & debugging (Playwright + Chrome DevTools / CDP (mcp))
Playwright is used for e2e tests here (pnpm test:e2e). For debugging and deep inspection, prefer using Chrome DevTools and the Chrome DevTools Protocol (CDP / "mcp") as follows:
- Fast debug (Playwright inspector):
PWDEBUG=1 npx playwright test --debugorPWDEBUG=1 npx playwright test --headedopens the Playwright inspector which is useful for stepping through tests.
- Use Chrome DevTools / CDP for network/console/coverage inspection:
- Launch a real Chrome/Chromium with a remote debugging port:
- macOS example:
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222 --user-data-dir=/tmp/playwright-profile.
- macOS example:
- In your test setup, connect Playwright to that browser via CDP (example in code):
const browser = await chromium.connectOverCDP('http://localhost:9222');- This lets tests run against a DevTools-attached browser so you can open the DevTools and inspect pages, network, and console while tests run.
- Open Chrome DevTools and connect to the remote debugging endpoint (DevTools will auto-connect when you open
http://localhost:9222in another browser), or use tools that can attach to the CDP endpoint.
- Launch a real Chrome/Chromium with a remote debugging port:
- If you need to record traces or videos for failing tests, use Playwright tracing and video options (see Playwright docs). The repo already includes Playwright in devDependencies.
- MCP Chrome DevTools for interactive testing:
- When available, use the MCP Chrome DevTools tools to interactively test functionality:
- Start dev server:
pnpm dev - Use
mcp_chromedevtool_navigate_pageto navigate tohttp://localhost:5173 - Use
mcp_chromedevtool_take_snapshotto capture page structure and identify elements - Use
mcp_chromedevtool_click,mcp_chromedevtool_fill, etc. to interact with the UI - Use
mcp_chromedevtool_list_console_messagesto check for errors or debug logs - Use
mcp_chromedevtool_evaluate_scriptto inspect application state
- Start dev server:
- This approach is useful for:
- Reproducing user-reported issues interactively
- Testing complex interactions (e.g., clicking segments during generation)
- Verifying fixes before writing formal E2E tests
- Inspecting application state and console logs in real-time
- When available, use the MCP Chrome DevTools tools to interactively test functionality:
Recommendations when running e2e locally/CI
- Run
pnpm dev(orpnpm previewfor a full build preview) beforepnpm test:e2ewhen you need a live app server. - For local debugging prefer
pnpm test:e2e:headedso you can see the browser window. - Use
PWDEBUG=1whenever you want interactive test debugging.
Agent safety & repository etiquette
- Read the repo files you will edit before making changes — start with
package.json,vitest.config.ts,playwright.config.ts, andsrc/. - Make minimal, focused changes. Do not change unrelated code or formatting unless required by a pre-commit hook.
- Respect existing linters and pre-commit hooks: this repo uses
husky+lint-staged(seepackage.jsonfor details). - Run
pnpm lintandpnpm type-checkbefore pushing changes to catch issues early.
Testing requirements for new features (Test-Driven Development)
This project follows Test-Driven Development (TDD) principles. Write tests BEFORE implementing functionality.
TDD Workflow (Red-Green-Refactor):
-
Red: Write a failing test that describes the desired behavior
- Start with the simplest test case
- Run test and verify it fails for the right reason
- Do not write implementation yet
-
Green: Write minimal code to make the test pass
- Implement only what's needed to pass the test
- It's okay if the implementation is naive/simple
- Run test and verify it passes
-
Refactor: Clean up code while keeping tests green
- Improve structure, naming, efficiency
- Run tests after each refactor to ensure nothing broke
- Commit when tests pass
Test Requirements:
- Unit tests are mandatory for all new features and bug fixes. Place tests in
src/lib/**/*.test.tsalongside the code they test.- Write tests FIRST before implementation (TDD)
- Test both happy-path and error scenarios.
- Test edge cases relevant to the feature (empty inputs, boundary conditions, state transitions, etc.).
- Aim for meaningful coverage; focus on testing logic and behavior, not just line coverage.
- E2E tests are strongly recommended when the feature involves user interactions or cross-component workflows.
- Add tests to
e2e/**/*.spec.tsthat verify the feature from the user's perspective. - E2E tests can be written after unit tests pass (since they're slower and more complex)
- Test against realistic use cases (e.g., for audio playback, test playing different languages, switching chapters, etc.).
- Use
pnpm test:e2e:headedlocally to debug flaky tests interactively.
- Add tests to
TDD Best Practices:
-
Start with the simplest test case, then add more complex ones
-
One test should verify one specific behavior
-
Keep test names descriptive:
should return mobile chunk size of 300 when on mobile device -
Run tests frequently during development (
pnpm test --watch) -
Commit after each green test (with passing implementation)
-
If you find yourself writing implementation first, stop and write the test
-
Always run the full test suite before submitting changes:
pnpm lintandpnpm type-checkto catch style/type issues.pnpm testto run all unit tests and ensure nothing breaks.pnpm test:e2eto run end-to-end tests (or a subset if specified).- If any test fails, investigate and fix before pushing. Do not ignore failing tests.
Testing and validation
- Unit tests:
pnpm test(vitest) - E2E tests:
pnpm test:e2e(Playwright) - Lint and format:
pnpm lint/pnpm format
Files & locations (quick references)
- Main scripts and dependencies:
package.json - Playwright config:
playwright.config.ts - Vitest config:
vitest.config.ts - Source code:
src/(components, lib, etc.) - E2E test specs:
e2e/(e.g.e2e/audiobook-generation.spec.ts)
Troubleshooting tips
- If Playwright can't launch browsers (CI/mac differences), try installing Playwright browsers:
npx playwright install. - If you get port collisions when creating worktrees and running servers, use different dev server ports via environment variables.
- If
ghis not authenticated, rungh auth login.
If you want, I can:
- Add per-folder or per-file agent guidance (e.g. where to find tests, how to run a specific test).
- Create a small script
scripts/new-worktree.shto automate creating a worktree + branch template.
End of AGENTS.md