This document provides instructions for AI agents working with this codebase. All commands use Makefile targets for consistency between human and AI workflows.
| Task | Command | Exit 0 = Success |
|---|---|---|
| Setup project | make setup |
Yes |
| Install deps | make install |
Yes |
| Run dev | make dev |
Yes |
| Run tests | make test |
Yes |
| Type check | make typecheck |
Yes |
| Lint code (auto-fix) | make lint |
Yes |
| Format code | make format |
Yes |
| All checks | make check |
Yes |
| Build | make build |
Yes |
| Generate docs | make docs |
Yes |
| Security scan | make security |
Yes |
ALWAYS run make check before committing. This runs type checking, linting, and formatting validation.
make check # Run typecheck + lint + oxlint (full validation)
make test # Run test suitemake setup # Initial setup (install tools, git hooks)
make install # Install dependencies
make dev # Run in development mode
make lint # Auto-fix lint issues
make format # Format code
bd sync # Sync with Beads (run before git push)When starting work or looking for what to do next, use Beads to find high-priority tasks:
bd ready --json # Get next ready task in JSON format
bv --robot-priority # Get task priority recommendationsWorkflow: Run bd ready --json to see the next task, or combine with bv --robot-priority to get AI-recommended priorities. This helps identify what to work on next.
bd ready- Get the next ready taskbd ready --json- Get next task in JSON format (for programmatic use)bd create- Create a new taskbd close- Close a completed taskbd sync- Sync with Beads tool (run before git push)
bv --robot-priority- Get AI-recommended task prioritiesbv --robot-plan- Get AI-generated plan for tasks
Finding the next task: Run bd ready --json or combine with bv --robot-priority to identify high-priority work.
Pre-commit validation and bug detection:
ubs --staged --fail-on-warning # Scan staged changes, fail on warnings
ubs --staged # Scan staged changes (report only)
ubs doctor # Check UBS installation and healthWhen to use: Before committing to catch bugs and issues in staged files.
Search past sessions for solutions and context:
cass search "query" --robot # Search sessions with AI context
cass index --stats # View indexing statisticsWhen to use: When looking for similar problems solved in past sessions or need historical context.
Store and retrieve task context:
cm context "task" --json # Get context for a task in JSON format
cm context "task" # Get context for a taskWhen to use: When working on tasks that need context from previous work or related tasks.
Prefer semantic search over text search when possible - it understands code structure and meaning.
mgrep- Semantic code search (prefer over grep/ripgrep for natural language queries)mgrep "What code parsers are available?" mgrep "How are chunks defined?" src/models mgrep -m 10 "Maximum concurrent workers in parser?"
grep-ast- AST-based pattern matching (finds code patterns, not just text)ast-grep- Fast AST-based code search and transformation
rg/ripgrep- Fast text search (faster than grep, respects .gitignore)rg "functionName" # Search for text pattern rg -t ts "pattern" # Search only TypeScript files rg -i "pattern" # Case-insensitive search
grep- Basic text search (fallback if ripgrep unavailable)ag(The Silver Searcher) - Fast text search alternativeack- Text search tool optimized for code
fd- Fast file finder (alternative tofind, respects .gitignore)fd "pattern" # Find files matching pattern fd -e ts # Find only .ts files
fzf- Fuzzy finder (interactive file/command selection)fzf # Interactive fuzzy file finder fzf --preview 'bat {}' # Preview files with syntax highlighting ls | fzf # Fuzzy search through command output git ls-files | fzf # Fuzzy search through git-tracked files
Search strategy: Use mgrep for semantic queries, rg for exact text matches, grep-ast/ast-grep for code patterns, fd for finding files, and fzf for interactive fuzzy selection.
These commands are destructive or irreversible and should never be run without explicit user approval:
rm -rf * # Destructive - deletes all files
rm -r * # Destructive - recursive deletion
git reset --hard* # Irreversible - discards all uncommitted changes
git clean -fd* # Destructive - removes untracked files
git push --force* # Dangerous - overwrites remote history
git push -f * # Dangerous - force push shorthandRule: If a command could cause data loss or overwrite remote history, ask for explicit approval before running.
- Always use Makefile targets - They wrap the underlying tools consistently
- Run
make checkbefore committing - Catches most issues - Exit code 0 means success - Non-zero means failure
- Use Beads (
bdCLI) - Runbd syncbefore pushing to remote to sync with Beads tool
- Never delete files without explicit user command in current session
- Use Bun for JS/TS (never npm/yarn/pnpm)
- Use mise for runtime versions (bun, node, etc.)
- Use Biome + Oxlint for linting (never ESLint/Prettier)
- Use TypeScript for new code (never JavaScript)
CRITICAL: Never add an underscore or prepend an underscore to a variable name in order to fix linting errors unless explicitly approved by the user. Instead, fix the underlying issue (e.g., use the variable, remove it if unused, or refactor the code properly).
- Use
neverthrowResult types for functions that can fail. ReturnResult<T, E>and useok()/err()helpers. - Use custom error classes (extend
CliError) for domain-specific errors with meaningful names. - Always handle errors explicitly - check
.isErr()or use.map()/.mapErr()on Results. - Never throw in async functions - return
Resulttypes instead.
- Use Zod schemas for runtime validation. Infer TypeScript types with
z.infer<typeof Schema>. - TypeScript strictest config - all strict checks are enabled. No
anytypes (useunknownif needed). - Always check for
undefinedwhen accessing array elements or optional properties (noUncheckedIndexedAccessis enabled).
- Always handle promises - oxlint enforces
no-floating-promises. Useawait,.then(), or.catch(). - Mark async functions - if a function returns a Promise, it should be marked
asyncor explicitly returnPromise<T>.
- Single quotes for strings (Biome config).
- Always semicolons (Biome config).
- Use
const-useConstrule enforces this. - Use template literals instead of string concatenation (
useTemplaterule). - No parameter reassignment -
noParameterAssignis an error.
- Write tests for new functionality using Bun's test runner (
bun:test). - Test error cases - especially when using Result types, test both success and error paths.
- Use descriptive test names - follow the pattern
describe('feature', () => { it('should do something', () => {}) }).
When ending a work session, you MUST complete ALL steps below. Work is NOT complete until git push succeeds.
MANDATORY WORKFLOW:
- File issues for remaining work - Create issues for anything that needs follow-up
- Run quality gates (if code changed) - Run
make check && make test - Update issue status - Close finished work, update in-progress items
- PUSH TO REMOTE - This is MANDATORY:
git pull --rebase bd sync # Sync with Beads tool git push git status # MUST show "up to date with origin"
- Clean up - Clear stashes, prune remote branches
- Verify - All changes committed AND pushed
- Hand off - Provide context for next session
CRITICAL RULES:
- Work is NOT complete until
git pushsucceeds - NEVER stop before pushing - that leaves work stranded locally
- NEVER say "ready to push when you are" - YOU must push
- If push fails, resolve and retry until it succeeds