diff --git a/AGENTS.md b/AGENTS.md index 21f6ccb..059080e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -104,10 +104,18 @@ npm run preview - Prefer precise, minimal changes. - Do not flatter or over-explain. - Explain risks directly. -- Prefer single quotes for strings unless interpolation or escaping makes double quotes better. +- Prefer single quotes for strings unless interpolation or escaping makes + double quotes better. - Ruby: never put a space before method-call parentheses. +- Ruby: never put a line break immediately before `)`. - Ruby: do not use `%w` or `%i`. -- TypeScript and Python: use GNU-style spacing before parentheses where syntactically valid. +- Ruby hashes are not blocks; keep `}` on the same line as the final pair. +- Ruby hashes keep the first pair on the same line as `{` unless line length + requires a break. +- Ruby blocks use separate `{ ... }` rules from hashes, with 2-space body + indentation. +- TypeScript and Python: use GNU-style spacing before parentheses where + syntactically valid. - Never write Ruby, TypeScript, or TSX lines longer than 99 characters. - Aim to keep Ruby, TypeScript, and TSX lines within 79 characters where practical. - TypeScript and TSX use 4-space logical indentation. @@ -128,6 +136,8 @@ npm run preview - Be careful with version tables, `version_no`, optimistic concurrency, wiki revisions, and restore/diff behavior. - Be careful with tag names, tag normalization, implications, similarities, and discard behavior. +- Be sensitive to N+1 queries; avoid introducing them and proactively fix + existing N+1 issues in the code path being edited. - Keep migration files and `backend/db/schema.rb` consistent when changing schema. ## Frontend rules diff --git a/backend/AGENTS.md b/backend/AGENTS.md index 773b8ee..622272b 100644 --- a/backend/AGENTS.md +++ b/backend/AGENTS.md @@ -68,15 +68,22 @@ service, representation, and spec. - Prefer precise, minimal changes. - Use single quotes unless interpolation or escaping makes double quotes better. - Do not put a space before Ruby method-call parentheses. +- Never put a line break immediately before `)` in Ruby. - Do not use `%w` or `%i` in new Ruby code. - Never write a Ruby line longer than 99 characters. - Aim to keep Ruby lines within 79 characters where practical. - For small Ruby method definitions that take keyword arguments, match the local no-parentheses style when nearby code uses it. -- For multi-line Ruby hashes and keyword constructors, prefer a readable - vertical shape with the opening brace on its own line. -- Put one logical field per line when the expression would otherwise - become dense. +- Treat Ruby hash `{ ... }` style and Ruby block `{ ... }` style as separate + rules. +- Do not format Ruby hashes like Ruby blocks. +- For Ruby hashes, keep the closing `}` on the same line as the final pair. +- Keep the first pair on the same line as `{` by default. +- If the hash would exceed the line limit, break after `{` and indent pairs + by 4 spaces. +- Put one logical pair per line when the expression would otherwise become + dense. +- For Ruby blocks, use 2-space indentation for the block body. - Keep comments short and useful; avoid narrating obvious code. - Do not add production dependencies without approval. @@ -186,6 +193,9 @@ service, representation, and spec. - When a controller action serializes nested associations, preload the associations it will touch instead of allowing N+1 queries. +- Be sensitive to N+1 queries in all backend work. +- Avoid introducing N+1 queries, and proactively fix existing N+1 issues when + you find them in the code path you are editing. - When an association may already be preloaded, prefer loaded-association checks that reuse the preloaded data without losing the efficient database path.