Skip to content

feat(agent/agentcontext): load always-apply rules from rule directories - #232

Merged
ibetitsmike merged 5 commits into
mainfrom
mike/rules-dirs-always-apply
Nov 12, 2026
Merged

ibetitsmike merged 5 commits into
mainfrom
mike/rules-dirs-always-apply

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

The workspace agent now loads Cursor-style .mdc rule files. Rules with alwaysApply: true join the instruction files, so chats get them on every turn, the same as AGENTS.md.

  • Rule directories: .cursor/rules under each scan root, plus two new built-in user roots, ~/.coder/rules and ~/.cursor/rules. A .cursor/rules that resolves outside its root is skipped, because rule bodies are shipped whole.
  • Rules in subfolders of a rule directory (such as .cursor/rules/frontend/components.mdc) load too. The walk does not follow symlinked folders.
  • parseRule reads the front-matter and pushes only the body after it. Cursor writes unquoted headers such as globs: **/*.ts, which YAML reads as an alias, so bare globs values are quoted before parsing.
  • Rules without front-matter (manual rules) and rules that set neither alwaysApply nor globs are ignored.
  • Glob-scoped rules are parsed into Snapshot.ScopedRules and are not pushed or hashed yet. A follow-up PR will attach them when a chat touches matching files.
  • The watcher watches rule directories (and an existing .cursor, so creating .cursor/rules later is noticed) and re-resolves when a rule file changes.

Behavior change: no experiment flag gates this, so alwaysApply rules that already exist in .cursor/rules, ~/.cursor/rules or ~/.coder/rules now reach chats.

Validation on 57bdd40, run in a container: gofmt -l on the changed files, go build ./agent/... ./coderd/..., go vet ./agent/agentcontext/ and go test ./agent/agentcontext/ pass. Negative controls: keeping glob rules with the instruction files makes TestResolver_RuleDirectories fail, and skipping the bare-glob quoting makes TestParseRule fail. Reading only the top level of rule directories makes TestResolver_RuleDirectories fail, and not watching their subfolders makes TestWatcher_Rules/NestedRuleEdit fail. Walking a symlinked rule folder by its link path instead of its target makes TestResolver_RuleContainerSymlinkInsideScanRoot fail.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T06:58:28.209468Z c794766 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ddfb2423f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agent/agentcontext/resolve.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/resolve.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 036498e330

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agent/agentcontext/defaults.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 57bdd40077

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d8e54e6e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/fork_rules.go Resolved
Comment thread agent/agentcontext/watcher.go Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: c794766e39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike merged commit fcd3d20 into main Nov 12, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/rules-dirs-always-apply branch November 12, 2026 07:34
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged after fork-ci passed on head c794766, Codex reviewed that head with no major issues (receipt comment 6817028985), 0 unresolved threads, local Go validation with negative controls, and a live check on a c794766 server and agent: two alwaysApply rules (one in a subfolder) reached the chat context with front matter stripped, and a glob-only rule did not. This change is not behind an experiment: existing alwaysApply rules in .cursor/rules, ~/.cursor/rules and ~/.coder/rules now reach chats.

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