Write correct, idiomatic tidyjs code. Activates when the user works with @tidyjs/tidy imports, mentions tidyjs, or asks about JavaScript data wrangling in a project that uses tidyjs.
Before writing any tidyjs code, you MUST read the relevant docs. tidyjs has a distinctive pipeline pattern and function taxonomy that differs from pandas, SQL, and lodash. Pre-training knowledge is often wrong for this library — always prefer the docs.
The genai-docs should be found at one of these locations. Check in order:
node_modules/@tidyjs/tidy/genai-docs/If found, use that path as DOCS_ROOT below and proceed to How to navigate.
Fetch them from the public docs site. The AI-optimized docs are available at:
https://pbeshai.github.io/tidy/genai-docs/
The site also has llms.txt at https://pbeshai.github.io/tidy/llms.txt with a full index.
Key files to fetch:
https://pbeshai.github.io/tidy/genai-docs/mental-model.md — start herehttps://pbeshai.github.io/tidy/genai-docs/quick-reference.md — task-to-function lookuphttps://pbeshai.github.io/tidy/genai-docs/gotchas.md — common mistakesapi-*.md files as neededDOCS_ROOT/mental-model.md for the pipeline pattern, accessor conventions, and function taxonomy. This is essential before writing any code.DOCS_ROOT/quick-reference.md to find which function to use for a given task.api-*.md file for function signatures, parameters, and examples:
api-core.mdapi-grouping.mdapi-summarize.mdapi-vector.mdapi-joins.mdapi-pivot.mdapi-slice.mdapi-selectors.mdapi-sequences.mdapi-other.mdDOCS_ROOT/patterns.md for multi-verb composition patterns.DOCS_ROOT/gotchas.md before finalizing code.tidy(data, verb1(), verb2()). Verbs are curried functions.(d) => d.column for field access, not string column names (except in summary functions like sum('key') and sort helpers like desc('key')).mutate is per-item (item, index, array) => value. mutateWithSummary receives the full array (items[]) => value[] | value. Using summary/vector functions inside mutate() is a silent bug. Always check gotchas.md if unsure.groupBy returns a flat array. With groupBy.object(), .entries(), .map(), etc., the output shape changes. Export modes must be the last pipeline step.summarize(). Vector functions go inside mutateWithSummary(). Item functions go inside mutate(). Selectors go inside select(). Getting this wrong produces incorrect results.