Skip to content

feat(trae): write directory-scoped rules to nested .trae/rules/ - #3258

Merged
dyoshikawa merged 5 commits into
mainfrom
resolve-issue-3234-trae-nested-rules
Oct 1, 2026
Merged

dyoshikawa merged 5 commits into
mainfrom
resolve-issue-3234-trae-nested-rules

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

Summary

Resolves gap 2 of #3234 (nested .trae/rules/ in project subdirectories). Gap 1 (global rules at ~/.trae/user_rules) remains open.

  • Generate: a non-root rule carrying agentsmd.subprojectPath (explicit or derived from globs) is written to <subprojectPath>/.trae/rules/<name>.md instead of the root .trae/rules/ (project scope only; the root rule never nests). Frontmatter mapping is unchanged.
  • Import: TraeRule.getNestedFilePatterns scans **/.trae/rules/**/*.md, excluding the root .trae/rules/, .trae/rules/ under any hidden directory (worktrees, other tools' output), node_modules/, __pycache__/ and the root build/vendoring directories. The shared buildNestedFilePatterns could not be reused because its **/.*/** ignore would drop .trae itself. fromFile now honors the directory the nested scan passes and re-splits it into <subproject>/.trae/rules + the path inside it.
  • Docs (file-formats.md Trae note), processor comment, unit tests and an e2e import/generate round-trip test.

Design choices

  • Imported name: a nested file keeps its own name (subfolders inside the rules dir are kept, as for the root scan), so import -> generate writes it back to the same path. This follows Roo's user-named mode files rather than Kiro/Reasonix's derived names (those exist because every nested file there is named AGENTS.md/REASONIX.md). Same-named files in two rules directories collide, which the processor's existing import-time collision warning reports.
  • Imported targets: ["trae"], like Kiro/Reasonix nested imports, so the next generate does not make agentsmd/codexcli/etc. emit new nested AGENTS.md files.
  • Globs are not replaced with <dir>/**/* on import, unlike the AGENTS.md helper: Trae's mapping turns specific globs into a file-scoped rule, so injecting a directory glob would silently change an always-applied rule's activation mode. Globs on a nested rule are passed through unchanged (Trae does not document whether they are relative to the subproject or the project root).
  • Three-level recursion limit: Trae's docs tie it to subfolders inside .trae/rules/ ("About multi-level rule nesting"), not to per-subdirectory .trae/rules/ folders, so no depth cap is encoded.
  • --delete: like every other nested scan, nested files are import-only and never swept. The existing **/.trae/rules/ gitignore entry already covers them.

Remaining (gap 1)

Global rules are still not generated. The Trae docs list ~/.trae/user_rules under "Rule directories" but only describe creating global rules through the settings UI input box; they do not state file names, extension or format. Per the issue, supportsGlobal stays false until the on-disk shape is confirmed on a real installation.

Refs #3234

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y4MwhqMc6s4ct5MzMReGJj

A rule carrying agentsmd.subprojectPath is written to <dir>/.trae/rules/ (project scope only), and subdirectory .trae/rules/ folders are imported back through getNestedFilePatterns as trae-only rules carrying the subproject path. Global rules (~/.trae/user_rules) stay unsupported: their on-disk shape is still undocumented.

Refs #3234

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01Y4MwhqMc6s4ct5MzMReGJj
…nore entry

The nested-scan gitignore filter tests the directories above each file, and the **/.trae/rules/ entry rulesync gitignore writes matched the nested rules directory itself, silently disabling the scan. Nested patterns can now name a tool-owned directory, and only the directories above it are tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01Y4MwhqMc6s4ct5MzMReGJj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant