Goal: Give you (the AI agent) a predictable playbook for working inside this Bun workspace. If you ever feel stuck, skim this file first.
| If you need to⦠| Run this command (from root) |
|---|---|
| Lint code | bun run lint |
| Fix lint issues automatically | bun run lint:fix |
| Format code | bun run format |
| Build all packages | bun run build (uses turbo) |
| Test all packages | bun run test (uses turbo) |
| Type check all packages | bun run typecheck (uses turbo) |
| Dev mode all packages | bun run dev (uses turbo) |
| Create a changeset | bun changeset |
Keep these commands nearbyβmost tasks you perform will be a combination of them.
- Standard Agent Workflow
- Guiding Human Developers
- Git Workflow & Commit Conventions
- Command Reference Library
- Project Overview
- Critical Rules for AI Agents
- Documentation Reference
- Quick Wins
- Need Help?
Use the links above to jump directly to the guidance you need.
This monorepo is designed so you can verify correctness entirely through static checks and targeted tests.
-
Execute targeted tests β Use
cd valtio-y && bun run testto run all tests, orbun vitest --run src/path/to/test.tsto run specific test files. Avoid watch mode unless explicitly requested. -
Type check β
cd valtio-y && bun run typecheckensures TypeScript correctness and catches type errors, const reassignments, type mismatches, and other compilation errors. This is equally important as linting β both tools serve different purposes. -
Lint + Format β Run
bun run lint:fixto fix lint issues automatically, thenbun run formatto format code. Both commands are fast enough to run across the whole repo when needed. Usebun run checkto run both formatting and linting in one command. -
Repeat as Needed β After changes, re-run the relevant steps. If you touch multiple packages, rebuild and verify each affected project.
Important: Use both type checking and linting in equal parts:
- Type checking (
bun run typecheck) catches type errors, const violations, duplicate declarations - Linting (
bun run lint) catches code style, patterns, and best practices
These tools are complementary, not redundant. Your IDE may show both types of errors, but you need to run both commands to verify correctness.
This is your loop. You do not need to run dev servers or browsers to verify your work.
When answering questions from humans, point them to the development workflow:
For testing:
cd valtio-y && bun run testFor development with watch mode:
cd valtio-y && bun run devFor building:
cd valtio-y && bun run buildFor running examples: Each example directory has its own setup. Navigate to the example directory and follow its README or package.json scripts.
Use descriptive branch names that follow this pattern:
<type>/<short-description>
Common types:
feat/- New featuresfix/- Bug fixeschore/- Maintenance tasks (dependencies, tooling, etc.)docs/- Documentation updatesrefactor/- Code refactoringtest/- Test additions or updatesperf/- Performance improvements
Examples:
git checkout -b feat/partykit-provider
git checkout -b fix/array-sync-bug
git checkout -b chore/readme-updates
git checkout -b docs/architecture-guideWe follow Conventional Commits format:
<type>(<scope>): <description>
[optional body]
[optional footer]
Type:
feat- New featurefix- Bug fixchore- Maintenance tasksdocs- Documentation changesrefactor- Code refactoringtest- Test updatesperf- Performance improvementsci- CI/CD changes
Scope (REQUIRED - indicates what part of the codebase):
core- Main valtio-y packagedocs- Documentationexamples- Example applicationsci- CI/CD pipelinedeps- Dependency updatestests- Test infrastructurerepo- Repository-wide changes (tooling, configuration, etc.)
Examples:
feat(core): add Y.Text integration support
fix(core): resolve array sync race condition
chore(docs): clarify provider setup in README
docs(architecture): add data flow diagrams
feat(examples): add PartyKit todo example
fix(ci): update Node version in GitHub Actions
chore(deps): upgrade Valtio to 2.1.8
test(core): add benchmarks for bulk operations
chore(repo): update release-please configurationGuidelines:
- Scope is mandatory - PR titles without a scope will be rejected by CI
- Keep the description concise (β€72 characters)
- Use present tense ("add" not "added")
- Don't capitalize the first letter of description
- No period at the end of description
- Use the body to explain what and why, not how
Example with body:
feat(core): add custom message support for providers
Enables sending custom string messages over the same WebSocket
connection used for Yjs sync. Useful for chat features and
function calling patterns.
Closes #42
-
Create a branch from
main:git checkout main git pull git checkout -b type/description
-
Make changes and commit following conventions:
# Make changes git add . git commit -m "feat(core): add new feature"
-
Run quality checks before pushing:
bun run check # Format + lint cd valtio-y && bun run typecheck cd valtio-y && bun run test
-
Push and create PR:
git push -u origin type/description # Create PR on GitHub -
PR Title must follow conventional commits with scope (enforced by CI):
feat(core): add PartyKit provider support fix(docs): correct installation instructions chore(ci): update deployment workflowNote: PR titles without a scope will be rejected. See
.github/workflows/pr-title.ymlfor enforcement details.
This project uses Changesets to manage versioning and releases, providing explicit control over changelogs.
How it works:
-
Create a changeset - When making changes, run
bun changesetto create a changeset file:bun changeset
This prompts you to:
- Select the packages to version (usually
valtio-y) - Choose the version bump type (major, minor, patch)
- Write a user-focused description for the changelog
- Select the packages to version (usually
-
Commit the changeset - The changeset file (
.changeset/*.md) should be committed with your changes:git add .changeset/ git commit -m "feat(core): add new feature" -
Version PR created - When merged to main, the Release workflow automatically creates/updates a "Version Packages" PR with:
- Runs:
bun run versionβchangeset version && bun update - Updates package.json versions and CHANGELOG.md files
- Bun workaround:
bun updatefixes the lockfile to resolveworkspace:*references - Version PR is ready for review
- Runs:
-
Merge to publish - When you merge the Version Packages PR:
- The workflow runs all quality checks (typecheck, lint, test, build)
- Changesets automatically detects changed packages and publishes them to npm
- Runs the
publishscript in each changed package:npm publish --access public --provenance - Git tags are created automatically for published versions
For AI agents:
When to create a changeset:
Create a changeset ONLY for changes that affect the published npm package:
β Need a changeset:
feat(core)- New features, APIs, exportsfix(core)- Bug fixes users will noticeperf(core)- Performance improvements- Breaking changes to published APIs
β NO changeset needed:
chore(ci)- CI/CD, workflows, build configchore(repo)- Dev tooling, linting, formattingfeat(examples)- Examples don't get publisheddocs(repo)- CLAUDE.md, CONTRIBUTING.md, etc.test(core)- Test files and utilitiesrefactor(core)- Internal changes with no API impact
Rule of thumb: Ask "Does this affect someone using valtio-y from npm?" If yes β changeset. If no β skip.
Workflow:
- Make the code changes
- IF user-facing: Create a changeset using
bun changeset - Commit both the code changes and the changeset file together
- The changeset description should be user-focused, not code-focused
Examples:
# feat(core) - NEEDS changeset
# Changes: src/index.ts exports new function
bun changeset # Select valtio-y, minor, describe feature
git commit -m "feat(core): add useYjsProxy hook"
# chore(ci) - NO changeset
# Changes: .github/workflows/
git commit -m "chore(ci): optimize test workflow"
# Skip bun changeset!
# fix(core) - NEEDS changeset
# Changes: src/synchronizer.ts fixes bug
bun changeset # Select valtio-y, patch, describe fix
git commit -m "fix(core): resolve array sync race condition"Adding new packages:
To make a new package publishable:
-
Add a
publishscript to the package'spackage.json:{ "scripts": { "publish": "npm publish --access public --provenance" } } -
Add the package to the workspace in root
package.json -
Changesets will automatically discover and publish it when you create a changeset for it
Technical details:
- Root scripts:
version:changeset version && bun update(updates versions + fixes Bun lockfile)
- Bun workaround:
bun updateafterchangeset versionis required because changesets doesn't natively support Bun workspaces. This resolvesworkspace:*references in the lockfile. - Publishing: Changesets automatically handles publishing and git tagging when the version PR is merged. It only publishes packages that have changesets and are not marked as
private: true.
Version bumping rules:
majorβ Breaking changes (1.0.0 β 2.0.0)minorβ New features (1.0.0 β 1.1.0)patchβ Bug fixes (1.0.0 β 1.0.1)
Example changeset file (.changeset/cool-feature.md):
---
"valtio-y": minor
---
Add custom message support for providers. You can now send custom string messages over the same WebSocket connection used for Yjs sync, enabling chat features and function calling patterns.Related workflows:
.github/workflows/release.yml- Creates version PRs and publishes to npm.github/workflows/pr-title.yml- Enforces conventional commit format for PR titles
Why changesets over release-please?
- Explicit control: Changelog entries are written intentionally, not inferred from commits
- Better quality: Changeset descriptions can be detailed and user-focused
- Reviewable: Changelog entries are reviewed as part of the PR
- Easy to fix: Mistakes in changesets can be fixed by editing the
.changeset/*.mdfile
Below is a categorized command index. Skim the left column to find the action you need, then run the command in the right column.
| Area | Situation | Command |
|---|---|---|
| Development | Build package | cd valtio-y && bun run build |
| Watch mode (dev) | cd valtio-y && bun run dev |
|
| Testing | Run all tests | cd valtio-y && bun run test |
| Run a single test file | cd valtio-y && bun vitest --run src/path/to/test.ts |
|
| Run benchmarks | cd valtio-y && bun run bench |
|
| Type Safety | Run TypeScript checks | cd valtio-y && bun run typecheck |
| Linting | Check lint issues | bun run lint |
| Fix lint issues automatically | bun run lint:fix |
|
| Formatting | Auto-format files | bun run format |
| Check formatting without fixing | bun run format:check |
|
| Code Quality | Format + lint (full check) | bun run check |
π‘ Usage tips
- After editing files, run
bun run check(which runsformat+lint:fix) before committing. - Never invoke underlying tools (e.g.,
vitest,tsc) directly unless necessaryβuse the package.json scripts to respect project configuration. - When working in the
valtio-ypackage, make sure tocd valtio-yfirst or use relative paths.
TypeScript monorepo using Bun (package manager) for a library that syncs Valtio state with Yjs CRDTs.
Key principle: Two-way sync between Valtio proxies and Yjs CRDTs for building multi-user apps with minimal effort.
- TypeScript 5.9+ - Strict mode with project references
- Bun 1.3.1+ - Package manager with workspace support
- Valtio 2.1.8+ - Reactive state management
- Yjs 13.6.27+ - CRDT library for collaboration
- Vitest 3.2+ - Testing framework
- tsdown - TypeScript bundler for packages
- oxlint - Fast linter
- Prettier - Code formatter
/Users/alex/code/valtio-y/
βββ valtio-y/ # Main package
β βββ src/ # Source code
β βββ tests/ # Test files
β βββ benchmarks/ # Performance benchmarks
β βββ dist/ # Built artifacts
βββ examples/ # Example applications
β βββ 01_obj/ # Object sync example
β βββ 02_array/ # Array sync example
β βββ 03_minecraft/ # Minecraft clone example
β βββ 04_todos/ # Todo app example
β βββ 05_todos_simple/ # Simple todos example
βββ docs/ # Documentation
βββ architecture/ # Architecture docs (architecture, data flow, limitations, ADRs)
valtio-y package affect all examples. Test thoroughly before committing.
- Y.Text Integration: Y.Text and XML types have been removed from the main branch. The library focuses on shared application state (objects, arrays, primitives), not text editors. Y.Text research is preserved in the
research/ytext-integrationbranch. - Scope: valtio-y is for collaborative data structures, not for building text editors. Text editor builders should use native Yjs integrations (Lexical, TipTap, ProseMirror).
-
β οΈ Always usebun runfor scripts - Usebun runto ensure you're using the installed versions and respecting package.json scripts -
β οΈ Run tests from the valtio-y directory - Most test commands need to be run fromcd valtio-yfirst -
β οΈ Use--runflag with vitest - When running vitest directly, use--runflag to avoid watch mode -
β οΈ Always use BOTH typecheck AND lint equally - Type checking and linting serve different purposes and are equally important:cd valtio-y && bun run typecheckcatches type errors (const reassignment, type mismatches, duplicate declarations)bun run lintcatches code patterns (unused vars, floating promises, style issues)- Your IDE may show both, but you must run both commands to verify correctness
-
β οΈ Use format and lint aggressively - After editing files, runbun run check(which runsformat+lint:fix) to ensure code quality. It's fast enough to run on entire packages or the whole repo whenever you want a clean slate. -
β οΈ Follow the workspace structure - The main package is invaltio-y/, examples are inexamples/. Respect the boundaries. -
β οΈ Follow git conventions - Use conventional commit format (type(scope): description) and create feature branches with descriptive names (type/description). See Git Workflow for details. -
β Test changes thoroughly - Run tests before committing changes to ensure nothing breaks
-
β Check documentation - Review
docs/directory for architectural decisions and limitations -
β Respect limitations - See README.md and docs/limitations.md for what's supported and what's not
-
β Use examples for reference - Examples demonstrate real-world usage patterns
Use the docs/architecture/ directory as your deep-dive companion. Start with the topic that matches your task:
| Topic | File | Why you'd open it | Representative Guides |
|---|---|---|---|
| Architecture | docs/architecture/architecture.md |
Understanding how valtio-y syncs state | High-level architecture, data flow, synchronization patterns |
| Data Flow | docs/architecture/data-flow.md |
Understanding how changes propagate | Bidirectional sync, Yjs to Valtio, Valtio to Yjs |
| Limitations | docs/architecture/limitations.md |
Knowing what's supported and what's not | What works, what doesn't, edge cases |
| ADRs | docs/architecture/architectural-decisions.md |
Understanding design decisions | Key architectural choices and rationale |
When unsure where to dig next, skim the relevant file or check the README.md for overview information.
- Check
package.jsonnamefield for package names - Look at
valtio-y/package.jsonfor main package scripts - Review examples in
examples/directory for usage patterns
- Use
bun add <package>(notnpmorpnpm) - Workspace dependencies are managed via Bun workspaces
- Check
package.jsonfiles for dependencies
- Tests are in
valtio-y/tests/directory - Unit tests are co-located with source files (
src/**/*.test.ts) - Integration tests:
tests/integration/**/*.spec.{ts,tsx} - E2E tests:
tests/e2e/**/*.spec.{ts,tsx} - Basic examples:
tests/basic/**/*.spec.ts
- β Running tests from root β β
cd valtio-y && bun run test - β Tests hang in watch mode β β
Always use
--runflag when running vitest directly - β Lint errors but IDE shows clean β β
Run
bun run lintto catch actual lint issues - β IDE shows error but lint doesn't β β
That's a type error, not a linting issue. Run
cd valtio-y && bun run typecheckto catch it - β Formatting inconsistencies β β
Run
bun run formatto auto-fix - β Forgetting to check both lint and typecheck β β
Always run both
bun run checkandcd valtio-y && bun run typecheck
- Check
docs/for detailed implementation guidelines - Review
README.mdfor usage examples and quick start - Look at
examples/directory for real-world usage patterns - Check
valtio-y/package.jsonfor available scripts - Review test files for examples of how things work
Version: 1.0.0 | Last Updated: January 2025