get-tbd 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +508 -0
  2. package/dist/bin-bootstrap.cjs +25 -0
  3. package/dist/bin-bootstrap.cjs.map +1 -0
  4. package/dist/bin.d.mts +2 -0
  5. package/dist/bin.mjs +106320 -0
  6. package/dist/bin.mjs.map +1 -0
  7. package/dist/cli.d.mts +13 -0
  8. package/dist/cli.mjs +9711 -0
  9. package/dist/cli.mjs.map +1 -0
  10. package/dist/docs/README.md +508 -0
  11. package/dist/docs/SKILL.md +222 -0
  12. package/dist/docs/guidelines/backward-compatibility-rules.md +78 -0
  13. package/dist/docs/guidelines/commit-conventions.md +78 -0
  14. package/dist/docs/guidelines/convex-limits-best-practices.md +170 -0
  15. package/dist/docs/guidelines/convex-rules.md +942 -0
  16. package/dist/docs/guidelines/general-coding-rules.md +36 -0
  17. package/dist/docs/guidelines/general-comment-rules.md +45 -0
  18. package/dist/docs/guidelines/general-eng-assistant-rules.md +54 -0
  19. package/dist/docs/guidelines/general-style-rules.md +37 -0
  20. package/dist/docs/guidelines/general-tdd-guidelines.md +52 -0
  21. package/dist/docs/guidelines/general-testing-rules.md +26 -0
  22. package/dist/docs/guidelines/golden-testing-guidelines.md +72 -0
  23. package/dist/docs/guidelines/python-cli-patterns.md +84 -0
  24. package/dist/docs/guidelines/python-rules.md +60 -0
  25. package/dist/docs/guidelines/typescript-cli-tool-rules.md +346 -0
  26. package/dist/docs/guidelines/typescript-code-coverage.md +171 -0
  27. package/dist/docs/guidelines/typescript-monorepo-patterns.md +71 -0
  28. package/dist/docs/guidelines/typescript-rules.md +55 -0
  29. package/dist/docs/install/claude-header.md +12 -0
  30. package/dist/docs/install/ensure-gh-cli.sh +88 -0
  31. package/dist/docs/shortcuts/standard/commit-code.md +23 -0
  32. package/dist/docs/shortcuts/standard/create-or-update-pr-simple.md +29 -0
  33. package/dist/docs/shortcuts/standard/create-or-update-pr-with-validation-plan.md +48 -0
  34. package/dist/docs/shortcuts/standard/implement-beads.md +31 -0
  35. package/dist/docs/shortcuts/standard/new-architecture-doc.md +31 -0
  36. package/dist/docs/shortcuts/standard/new-implementation-beads-from-spec.md +28 -0
  37. package/dist/docs/shortcuts/standard/new-plan-spec.md +49 -0
  38. package/dist/docs/shortcuts/standard/new-research-brief.md +30 -0
  39. package/dist/docs/shortcuts/standard/new-validation-plan.md +51 -0
  40. package/dist/docs/shortcuts/standard/precommit-process.md +88 -0
  41. package/dist/docs/shortcuts/standard/review-code-python.md +47 -0
  42. package/dist/docs/shortcuts/standard/review-code-typescript.md +46 -0
  43. package/dist/docs/shortcuts/standard/welcome-user.md +65 -0
  44. package/dist/docs/shortcuts/system/shortcut-explanation.md +61 -0
  45. package/dist/docs/shortcuts/system/skill-brief.md +40 -0
  46. package/dist/docs/shortcuts/system/skill.md +210 -0
  47. package/dist/docs/skill-brief.md +40 -0
  48. package/dist/docs/tbd-closing.md +31 -0
  49. package/dist/docs/tbd-design.md +5308 -0
  50. package/dist/docs/tbd-docs.md +1113 -0
  51. package/dist/docs/tbd-prime.md +119 -0
  52. package/dist/docs/templates/architecture-doc.md +117 -0
  53. package/dist/docs/templates/plan-spec.md +69 -0
  54. package/dist/docs/templates/research-brief.md +71 -0
  55. package/dist/index.d.mts +567 -0
  56. package/dist/index.mjs +3 -0
  57. package/dist/src-CWD4YCBk.mjs +319 -0
  58. package/dist/src-CWD4YCBk.mjs.map +1 -0
  59. package/dist/tbd +106320 -0
  60. package/package.json +92 -0
@@ -0,0 +1,222 @@
1
+ ---
2
+ name: tbd
3
+ description: >-
4
+ Git-native issue tracking (beads), coding guidelines, and spec-driven planning for AI agents.
5
+ Use for tracking issues with dependencies, creating and closing bugs, features, and tasks,
6
+ planning specs for new features, implementing features from specs, code reviews, committing code,
7
+ creating PRs, research briefs, and architecture docs. Invoke when user mentions: tbd, beads,
8
+ issues, bugs, tasks, todo, tracking, specs, planning, implementation, validation, guidelines,
9
+ shortcuts, templates, commit, PR workflows, code review, testing best practices, or monorepo patterns.
10
+ allowed-tools: Bash(tbd:*), Read, Write
11
+ ---
12
+
13
+ # tbd Workflow
14
+
15
+ **`tbd` helps humans and agents ship code with greater speed, quality, and discipline.**
16
+
17
+ 1. **Issue Tracking**: Git-native tasks/bugs.
18
+ Never lose work across sessions.
19
+ 2. **Spec-Driven Workflows**: Plan features → break into issues → implement
20
+ systematically.
21
+ 3. **Shortcuts**: Pre-built processes for commits, PRs, reviews.
22
+ 4. **Guidelines**: Best practices for TypeScript, Python, testing.
23
+
24
+ These features work together to create high-quality workflows.
25
+ Be sure to apply the workflows below for all issue tracking, spec driven planning and
26
+ implementation, and code review.
27
+
28
+ ## Installation
29
+
30
+ If `tbd` is not installed, install and set up:
31
+
32
+ ```bash
33
+ npm install -g get-tbd@latest
34
+ tbd # Gives full orientation
35
+ tbd setup --auto --prefix=<name> # Fresh project (--prefix REQUIRED)
36
+ tbd setup --auto # Existing tbd project (prefix already set)
37
+ ```
38
+
39
+ The prefix appears in every issue ID (e.g., `myapp-a1b2`) and is a matter of user
40
+ preference for a given project.
41
+
42
+ **IMPORTANT NOTES ON SETUP:**
43
+ - **Fresh projects**: `--prefix` is REQUIRED. NEVER guess or invent a prefix.
44
+ Always ask the user first.
45
+ - **Existing tbd projects** (`.tbd/` exists): No `--prefix` needed, just run
46
+ `tbd setup --auto`.
47
+ - **Beads migration** (`.beads/` exists): Use `tbd setup --from-beads` (uses beads
48
+ prefix).
49
+ - **Refresh configs**: Run `tbd setup --auto` anytime to update skill files, hooks, and
50
+ get the latest shortcuts/guidelines/templates.
51
+
52
+ > `tbd prime` restores context after compaction/clear (auto-called by hooks).
53
+
54
+ ## CRITICAL: You Use tbd — The User Doesn’t
55
+
56
+ **You are the tbd operator.** The user talks to you naturally; you translate their
57
+ requests into tbd actions.
58
+ Never tell the user to run tbd commands themselves.
59
+
60
+ - **WRONG**: "Run `tbd create` to track this bug"
61
+
62
+ - **RIGHT**: *(you run `tbd create` yourself and tell the user it’s tracked)*
63
+
64
+ - **WRONG**: "You can use `tbd ready` to see available work"
65
+
66
+ - **RIGHT**: *(you run `tbd ready` yourself and show the user what’s available)*
67
+
68
+ ## Orientation and Help
69
+
70
+ When users ask for orientation, help getting started, or want to understand tbd:
71
+
72
+ - Run `tbd shortcut welcome-user` and follow its instructions
73
+ - Show the user what they can **say** (natural language), not commands to run
74
+ - The welcome message explains tbd’s value through examples of what the user can ask
75
+
76
+ **DO NOT** respond to “what is tbd?”
77
+ or “help me get started” by listing CLI commands.
78
+ Instead, welcome them and show them the kinds of things they can ask you to do.
79
+
80
+ ## How to Use tbd to Help Users
81
+
82
+ Use tbd proactively on behalf of the user:
83
+
84
+ - User describes a bug → You run `tbd create "Bug: ..." --type=bug`
85
+ - User wants a feature → You create a plan spec, then break into issues
86
+ - Starting a session → You check `tbd ready` for available work
87
+ - Completing work → You run `tbd close <id>` with clear reason
88
+ - User asks what tbd does → You run `tbd shortcut welcome-user`
89
+ - User asks for help/orientation → You run `tbd shortcut welcome-user`
90
+
91
+ ### Quick Reference Table
92
+
93
+ This table shows what the user says naturally and what you (the agent) do in response.
94
+
95
+ | What the User Says | What You (Agent) Do | What Happens |
96
+ | --- | --- | --- |
97
+ | "There's a bug where ..." | `tbd create "..." --type=bug` | Creates and tracks a bug |
98
+ | "Let's work on current issues" | `tbd ready` | Shows ready issues |
99
+ | "Build a TypeScript CLI" | `tbd guidelines typescript-cli-tool-rules` | You follow the guidelines |
100
+ | "Improve eslint setup" | `tbd guidelines typescript-monorepo-patterns` | You follow the guidelines |
101
+ | "Add better e2e testing" | `tbd guidelines golden-testing-guidelines` | You follow the guidelines |
102
+ | "Review these changes" (TypeScript) | `tbd guidelines typescript-rules` | You follow the guidelines |
103
+ | "Review these changes" (Python) | `tbd guidelines python-rules` | You follow the guidelines |
104
+ | "Let's plan a new feature" | `tbd shortcut new-plan-spec` | You follow the spec template |
105
+ | "Break spec into issues" | `tbd shortcut new-implementation-beads-from-spec` | You create implementation issues |
106
+ | "Implement these issues" | `tbd shortcut implement-beads` | You implement systematically |
107
+ | "Commit this" | `tbd shortcut commit-code` | You review and commit |
108
+ | "Create a PR" | `tbd shortcut create-or-update-pr-simple` | You create the PR |
109
+ | "Research this topic" | `tbd shortcut new-research-brief` | You research and document |
110
+ | "Document this architecture" | `tbd shortcut new-architecture-doc` | You create the doc |
111
+ | *(your judgment)* | `tbd dep add`, `tbd close`, `tbd sync` | You manage issues as needed |
112
+
113
+ ## IMPORTANT: Session Closing Protocol
114
+
115
+ **CRITICAL**: Before saying “done” or “complete”, you MUST run this checklist:
116
+
117
+ ```
118
+ [ ] 1. Stage and commit: git add + git commit
119
+ [ ] 2. Push to remote: git push
120
+ [ ] 3. Start CI watch (BLOCKS until done): gh pr checks <PR> --watch 2>&1
121
+ [ ] 4. While CI runs: tbd close/update <id> for issues worked on
122
+ [ ] 5. While CI runs: tbd sync
123
+ [ ] 6. Return to step 3 and CONFIRM CI passed
124
+ [ ] 7. If CI failed: fix, re-push, restart from step 3
125
+ ```
126
+
127
+ ### NON-NEGOTIABLE Requirements
128
+
129
+ #### CI: Wait for `--watch` to finish
130
+
131
+ The `--watch` flag blocks until ALL checks complete.
132
+ Do NOT see “passing” in early output and move on—wait for the **final summary** showing
133
+ all checks passed.
134
+
135
+ #### tbd: Update issues and sync
136
+
137
+ Every session must end with tbd in a clean state:
138
+ - Close/update **every issue** you worked on
139
+ - Run `tbd sync` and confirm it completed
140
+
141
+ **Work is not done until pushed, CI passes, and tbd is synced.**
142
+
143
+ ## IMPORTANT: Issue Tracking Rules
144
+
145
+ - Track *all task work* not being done immediately as beads using `tbd` (discovered
146
+ work, future work, TODOs for the session, multi-session work)
147
+ - When in doubt, prefer tbd for tracking tasks, bugs, and issues
148
+ - Use `tbd create` for creating beads
149
+ - Git workflow: update or close issues and run `tbd sync` at session end
150
+ - If not given specific directions, check `tbd ready` for available work
151
+
152
+ ## Essential Commands
153
+
154
+ ### Finding Work
155
+
156
+ - `tbd ready` - Show issues ready to work (no blockers)
157
+ - `tbd list --status open` - All open issues
158
+ - `tbd list --status in_progress` - Your active work
159
+ - `tbd show <id>` - Detailed issue view with dependencies
160
+
161
+ ### Creating & Updating
162
+
163
+ - `tbd create "title" --type task|bug|feature --priority=P2` - New issue
164
+ - Priority: P0-P4 (P0=critical, P2=medium, P4=backlog).
165
+ Do NOT use "high"/"medium"/"low"
166
+ - `tbd update <id> --status in_progress` - Claim work
167
+ - `tbd update <id> --assignee username` - Assign to someone
168
+ - `tbd close <id>` - Mark complete
169
+ - `tbd close <id> --reason "explanation"` - Close with reason
170
+ - **Tip**: When creating multiple issues, use parallel subagents for efficiency
171
+
172
+ ### Dependencies & Blocking
173
+
174
+ - `tbd dep add <issue> <depends-on>` - Add dependency (issue depends on depends-on)
175
+ - `tbd blocked` - Show all blocked issues
176
+ - `tbd show <id>` - See what’s blocking/blocked by this issue
177
+
178
+ ### Sync & Collaboration
179
+
180
+ - `tbd sync` - Sync with git remote (run at session end)
181
+ - `tbd sync --status` - Check sync status without syncing
182
+
183
+ Note: `tbd sync` handles all git operations for issues--no manual git push needed.
184
+
185
+ ### Project Health
186
+
187
+ - `tbd stats` - Project statistics (open/closed/blocked counts)
188
+ - `tbd doctor` - Check for issues (sync problems, missing hooks)
189
+
190
+ ## Documentation Commands
191
+
192
+ ### Shortcuts
193
+
194
+ Reusable instruction templates for common tasks:
195
+
196
+ - `tbd shortcut <name>` - Output a shortcut by name
197
+ - `tbd shortcut --list` - List all available shortcuts
198
+
199
+ ### Guidelines
200
+
201
+ Coding rules and best practices:
202
+
203
+ - `tbd guidelines <name>` - Output a guideline by name
204
+ - `tbd guidelines --list` - List all available guidelines
205
+
206
+ Example: `tbd guidelines typescript-rules`
207
+
208
+ ### Templates
209
+
210
+ Document templates for specs, research, architecture:
211
+
212
+ - `tbd template <name>` - Output a template by name
213
+ - `tbd template --list` - List all available templates
214
+
215
+ Example: `tbd template plan-spec > docs/project/specs/active/plan-YYYY-MM-DD-feature.md`
216
+
217
+ ## Quick Reference
218
+
219
+ - **Priority levels**: 0=critical, 1=high, 2=medium (default), 3=low, 4=backlog
220
+ - **Issue types**: task, bug, feature, epic
221
+ - **Status values**: open, in_progress, closed
222
+ - **JSON output**: Add `--json` to any command for machine-readable output
@@ -0,0 +1,78 @@
1
+ ---
2
+ title: Backward Compatibility Rules
3
+ description: Guidelines for maintaining backward compatibility across code, APIs, file formats, and database schemas
4
+ ---
5
+ ## Backward Compatibility Guidelines
6
+
7
+ ### Types of Backward Compatibility
8
+
9
+ When making code changes, you should be aware of compatibility requirements for:
10
+
11
+ - Code compatibility internal to a single application (types and method or function
12
+ signatures)
13
+
14
+ - API compatibility for libraries (types and method or function signatures)
15
+
16
+ - Server API compatibility (REST, GraphQL, gRPC, etc.)
17
+
18
+ - File format compatibility
19
+
20
+ - Database schema compatibility
21
+
22
+ ### Backward Compatibility Template
23
+
24
+ > Use the following template when clarifying backward compatibility requirements:
25
+
26
+ For the following areas:
27
+
28
+ - “DO NOT MAINTAIN” means simply make the changes and DO NOT preserve any old stubs or
29
+ add comments about past changes
30
+
31
+ - “KEEP DEPRECATED” means to add new features but also preserve support, function stubs,
32
+ and comments about past changes
33
+
34
+ - “SUPPORT BOTH” means to add new features but also preserve support, function
35
+
36
+ - “MIGRATE” means to add new features but also document and use database migrations or
37
+ automated tasks to migrate to new formats or schemas
38
+
39
+ - “N/A” means this area isn’t applicable
40
+
41
+ **BACKWARD COMPATIBILITY REQUIREMENTS:**
42
+
43
+ - **Code types, methods, and function signatures**:
44
+ [DO NOT MAINTAIN or KEEP DEPRECATED, additional notes if necessary]
45
+
46
+ - **Library APIs**:
47
+ [DO NOT MAINTAIN or KEEP DEPRECATED or N/A, plus any additional notes]
48
+
49
+ - **Server APIs**:
50
+ [DO NOT MAINTAIN or KEEP DEPRECATED or N/A, plus any additional notes]
51
+
52
+ - **File formats**: [DO NOT MAINTAIN or SUPPORT BOTH or N/A, plus any additional notes]
53
+
54
+ - **Database schemas**: [DO NOT MAINTAIN or MIGRATE or N/A, plus any additional notes]
55
+
56
+ ### Always Clarify Backward Compatibility Requirements
57
+
58
+ - ALWAYS be clear on backward compatibility requirements when making changes.
59
+ These should ALWAYS be clear in any specification.
60
+
61
+ - If they are not clear, stop and ask the user for clarification.
62
+
63
+ ### When Backward Compatibility Is Important
64
+
65
+ - In general, compatibility for libraries, servers, file formats and database schemas is
66
+ VERY IMPORTANT. Compatibility and migration should be planned carefully.
67
+
68
+ - Backward compatibility and legacy support *within* a single application is usually NOT
69
+ important and should NOT be done if it needlessly complicates code changes.
70
+ But if not specified, it also should be clarified to be sure it is not needed.
71
+
72
+ ### Single Application Code Backward Compatibility
73
+
74
+ - Unless stated in the spec or stated by the user, deprecated and backward compatibility
75
+ code support should NOT be left after refactors to a single application repository.
76
+
77
+ - When doing normal refactoring or reorganizing code, REMOVE deprecated functions,
78
+ methods, classes, or files completely if backward compatibility is not needed.
@@ -0,0 +1,78 @@
1
+ ---
2
+ title: Commit Conventions
3
+ description: Conventional Commits format with extensions for agentic workflows
4
+ ---
5
+ # Commit Conventions
6
+
7
+ We use [Conventional Commits](https://www.conventionalcommits.org/) with extensions for
8
+ agentic use cases, including use for content work and operational tasks in addition to
9
+ software development.
10
+
11
+ ## Format
12
+
13
+ ```
14
+ <type>[optional scope][!]: <description>
15
+
16
+ [optional body]
17
+
18
+ [optional footer(s)]
19
+ ```
20
+
21
+ - First line short, ideally 72 characters or less
22
+ - Use imperative mood ("Add feature" not “Added feature”)
23
+ - No scope by default; only use when disambiguation is needed (e.g., `fix(parser):`)
24
+ - For breaking changes: add `!` before `:` AND include `BREAKING CHANGE:` in the footer
25
+
26
+ ## Types
27
+
28
+ Classic software development work:
29
+
30
+ - `feat`: New feature (improved software functionality)
31
+ - `fix`: Bug fix (corrected software functionality)
32
+ - `style`: Code formatting (no logic change)
33
+ - `refactor`: Code restructuring (no behavior change)
34
+ - `test`: Adding or updating tests
35
+ - `chore`: Software maintenance (deps, config, build, upgrades)
36
+ - `docs`: User-facing docs (README, API docs, guides, tutorials)
37
+
38
+ Agentic project work:
39
+
40
+ - `plan`: Internal design, plans, specs, architecture, requirements docs
41
+ - `research`: Internal research docs, notes, resources, reports
42
+ - `ops`: Operational tasks (issue tracking, syncing, publishing, maintenance)
43
+ - `process`: Changes to processes, methodology, conventions, policies
44
+
45
+ Commit types can drive automated versioning and changelogs.
46
+ See your project’s release process for specific rules.
47
+
48
+ The type indicates the *category of artifact* being changed.
49
+ Corrections within a category use that category’s type (e.g., fixing a typo in docs is
50
+ `docs:`, not `fix:`).
51
+
52
+ Note: `plan`, `research`, `ops`, and `process` are extensions for agentic development,
53
+ not part of the standard Conventional Commits spec.
54
+
55
+ **Key distinctions:** `docs` is for users; `plan` is design/specs for building;
56
+ `research` is internal learning/investigation; `ops` is operational work; `process` is
57
+ methodology.
58
+
59
+ ## Examples
60
+
61
+ ```
62
+ feat: Add support for custom labels
63
+ feat(parser): Add YAML front matter support
64
+ fix: Handle empty issue list gracefully
65
+ fix(api): Return 404 for missing resources
66
+ docs: Update CLI usage examples
67
+ docs: Fix typo in API reference
68
+ style: Format with prettier
69
+ refactor: Extract validation logic to separate module
70
+ test: Add golden tests for sync command
71
+ chore: Update dependencies
72
+ plan: Add design document for dependency resolution
73
+ research: Comparison of TypeScript monorepo build tools
74
+ research: A summary of SEO best practices in 2026
75
+ ops: Update issue status for auth feature
76
+ ops: Sync beads with remote
77
+ process: Add TDD guidelines for agent workflows
78
+ ```
@@ -0,0 +1,170 @@
1
+ ---
2
+ title: Convex Limits and Best Practices
3
+ description: Comprehensive reference for Convex platform limits, workarounds, and performance best practices
4
+ ---
5
+ # Convex Database Limits, Best Practices, and Workarounds
6
+
7
+ ## Core Limits Reference
8
+
9
+ ### Transaction Read/Write Limits
10
+
11
+ | Limit Type | Value |
12
+ | --- | --- |
13
+ | Maximum data read | 8 MiB per query/mutation |
14
+ | Maximum documents scanned | 16,384 per query/mutation |
15
+ | Maximum data written | 8 MiB per mutation |
16
+ | Maximum documents written | 8,192 per mutation |
17
+ | Maximum db.get/db.query calls | 4,096 per transaction |
18
+
19
+ The read limit includes **all scanned document bytes**, not just returned results.
20
+ Convex does not support field projection.
21
+
22
+ ### Document Size and Structure Limits
23
+
24
+ | Limit | Value |
25
+ | --- | --- |
26
+ | Maximum document size | 1 MiB |
27
+ | Maximum fields per document | 1,024 |
28
+ | Maximum nesting depth | 16 levels |
29
+ | Maximum array elements | 8,192 per array |
30
+ | Maximum field name length | 1,024 characters |
31
+ | Maximum identifier length | 64 characters |
32
+
33
+ The 8,192 array limit also applies to arrays **returned** by query functions.
34
+ Use `.take(8000)` to stay safely under this limit.
35
+
36
+ ### Concurrency and Execution Limits
37
+
38
+ | Limit | Value |
39
+ | --- | --- |
40
+ | Concurrent queries/mutations/actions (default) | 16 each |
41
+ | Scheduled job parallelism | 10 concurrent |
42
+ | Query/Mutation user timeout | 1 second |
43
+ | Action timeout | 10 minutes |
44
+ | Log lines per execution | 256 (silently truncated) |
45
+ | Max scheduled per mutation | 1,000 |
46
+
47
+ ### Action Memory Limits
48
+
49
+ | Runtime | Memory Limit |
50
+ | --- | --- |
51
+ | Convex Runtime (default) | 64 MB |
52
+ | Node.js Runtime (`"use node;"`) | 512 MB |
53
+
54
+ ### Index and Schema Limits
55
+
56
+ | Limit | Value |
57
+ | --- | --- |
58
+ | Indexes per table | 32 (source code: 64) |
59
+ | Fields per index | 16 |
60
+ | Full-text indexes per table | 4 |
61
+ | Vector indexes per table | 4 |
62
+ | Vector index max documents | 100,000 |
63
+ | Maximum tables | 10,000 |
64
+
65
+ ### Storage and Bandwidth (Starter / Professional)
66
+
67
+ | Resource | Starter | Professional |
68
+ | --- | --- | --- |
69
+ | Database storage | 0.5 GB | 50 GB |
70
+ | Database bandwidth/month | 1 GB | 50 GB |
71
+ | File storage | 1 GB | 100 GB |
72
+ | Function calls/month | 1,000,000 | 25,000,000 |
73
+
74
+ ## Function Calling Rules
75
+
76
+ | Caller | Can Call | Method |
77
+ | --- | --- | --- |
78
+ | Query | Helper functions only | Direct call |
79
+ | Mutation | Helper functions only | Direct call |
80
+ | Action | Queries, mutations, actions | `ctx.runQuery/runMutation/runAction` |
81
+
82
+ - Queries and mutations cannot call other queries/mutations
83
+ - Actions orchestrate across transactions (not atomic)
84
+ - Avoid nested same-runtime action calls; use helper functions instead
85
+
86
+ ## Common Pitfalls and Workarounds
87
+
88
+ ### 1. Exceeding 8 MiB Read Limit with `.collect()`
89
+
90
+ Never use `.collect()` on unbounded tables.
91
+ Use `.take(n)` or `.paginate()`.
92
+
93
+ ### 2. Large Documents Causing Read Limit Issues
94
+
95
+ Keep documents used for listing/counting small (<10KB). Store large payloads in separate
96
+ detail tables.
97
+
98
+ ### 3. Counting/Aggregating Large Datasets
99
+
100
+ Use the [Convex Aggregate Component](https://github.com/get-convex/aggregate) for O(log
101
+ n) counts and sums.
102
+
103
+ ### 4. Post-Index Filtering
104
+
105
+ Create composite indexes instead of `.withIndex()` followed by `.filter()`.
106
+
107
+ ```typescript
108
+ // BAD: reads all items for parentId, then filters
109
+ .withIndex('by_parent', q => q.eq('parentId', id))
110
+ .filter(q => q.eq(q.field('status'), 'active'))
111
+
112
+ // GOOD: composite index
113
+ .withIndex('by_parent_and_status', q => q.eq('parentId', id).eq('status', 'active'))
114
+ ```
115
+
116
+ ### 5. OCC Conflicts
117
+
118
+ - Consolidate related writes into single mutations
119
+ - Batch create operations
120
+ - Use namespacing to isolate writes
121
+ - Stagger scheduled mutations with delays
122
+
123
+ ### 6. Pagination Loops in Queries
124
+
125
+ Never use pagination loops in queries/mutations (1s timeout, test hangs).
126
+ Use actions for pagination loops (10-minute limit).
127
+
128
+ ### 7. Bucket Timestamp Keys
129
+
130
+ Bucket monotonically increasing keys to spread writes across B-tree nodes:
131
+
132
+ ```typescript
133
+ const bucketedTime = Math.floor(timestamp / 60000) * 60000;
134
+ ```
135
+
136
+ ### 8. Dangling Promises in Actions
137
+
138
+ Always `await` every async call.
139
+ Never use `void asyncFn()` or `asyncFn().catch()`. Use `ctx.scheduler.runAfter` for
140
+ truly independent operations.
141
+
142
+ ### 9. Nested Same-Runtime Action Calls
143
+
144
+ Use `ctx.runAction()` only for cross-runtime calls (V8 to Node.js).
145
+ Extract shared logic into plain TypeScript helper functions.
146
+
147
+ ## Best Practices Checklist
148
+
149
+ - Never `.collect()` on unbounded tables; use `.take()` or `.paginate()`
150
+ - Use composite indexes matching query patterns
151
+ - Keep listing documents small (<10KB); separate large payloads
152
+ - Use Aggregate Component for stats over >100 records
153
+ - Bound all aggregate reads with `lower`/`upper`
154
+ - Namespace writes to avoid OCC contention
155
+ - Keep queries/mutations under 1 second; use actions for heavy work
156
+ - Await all promises in actions
157
+ - Use `internalQuery`/`internalMutation`/`internalAction` for private functions
158
+ - Always include `args` and `returns` validators
159
+
160
+ ## Decision Matrix
161
+
162
+ | Use Case | Pattern |
163
+ | --- | --- |
164
+ | Count <100 records | Direct `.collect()` |
165
+ | Count 100-1000 records | `.take(limit)` with head+1 |
166
+ | Count >1000 records | Aggregate Component |
167
+ | List unbounded records | `.paginate()` |
168
+ | Large text fields (>10KB) | Separate detail table |
169
+ | Processing <10 min | Action with progress logging |
170
+ | Processing >10 min | Resumable action or scheduled jobs |