Skip to content

feat(agent): instruct sessions to follow repo rules and comment style - #91603

Merged
trunk-io[bot] merged 2 commits into
masterfrom
vojtab/agent-repo-rules
Sep 1, 2026
Merged

feat(agent): instruct sessions to follow repo rules and comment style#91603
trunk-io[bot] merged 2 commits into
masterfrom
vojtab/agent-repo-rules

Conversation

@VojtechBartos

@VojtechBartos VojtechBartos commented Aug 31, 2026

Copy link
Copy Markdown
Member

Problem

  • PRs from the coding agent ignore conventions a repo keeps in Cursor rules or AGENTS.md, and add comments that just narrate the change (support ticket 64146).
  • The Claude harness loads CLAUDE.md automatically, but nothing points the agent at AGENTS.md, .cursor/rules/*.mdc, or .cursorrules, and nothing asks it to match the repo's comment style.

Changes

  • Every Claude adapter session (desktop and cloud) now carries a "Repository Conventions" instruction block: read the repo's convention files before the first edit, follow them, and match the surrounding code's comment density instead of narrating the change.
  • The block explains Cursor rule scoping (alwaysApply, globs) so the agent applies each rule where it belongs.

Nothing user-visible changes in the app UI; the change is prompt content.

How did you test this code?

  • Extended the always-appended-headings case in instructions.test.ts, guarding against the block being dropped from the assembled prompt.
  • Not run: an end-to-end cloud task; the sandbox image needs a published @posthog/agent first.

Automatic notifications

  • Publish to changelog?

Docs update

None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Claude Code session driven by @VojtechBartos. An earlier iteration of this branch read and injected the rule files deterministically at session start; it was replaced with this instruction-only version to keep the agent's judgment in the loop and avoid owning a parser for Cursor's rule format.
  • Skills invoked: /posthog-desktop, /writing-tests, /writing-code-comments, /writing-pr-descriptions, /simplify.
  • Verified locally: vitest for the touched package, turbo typecheck --filter=@posthog/agent, Biome, hogli ci:preflight (pre-push hook).

@VojtechBartos VojtechBartos self-assigned this Aug 31, 2026
@trunk-io

trunk-io Bot commented Aug 31, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 41a4b59.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

Trunk lane — non-backend lane

This PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes.

@hosthog

hosthog Bot commented Aug 31, 2026

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

The previews for this PR have been torn down and no longer serve.

Coding agent sessions ignored conventions kept in Cursor rules and
AGENTS.md, and added comments that narrate the change. A Repository
Conventions block in the appended instructions now tells the agent to
read those files before its first edit and to match the surrounding
code's comment density.
@VojtechBartos
VojtechBartos force-pushed the vojtab/agent-repo-rules branch from 12907b0 to f473bdd Compare August 31, 2026 13:20
@VojtechBartos VojtechBartos changed the title feat(agent): follow repo Cursor rules and AGENTS.md in agent sessions feat(agent): instruct sessions to follow repo rules and comment style Aug 31, 2026
@VojtechBartos
VojtechBartos requested review from a team August 31, 2026 13:23
@VojtechBartos
VojtechBartos marked this pull request as ready for review August 31, 2026 13:23
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
products/desktop/packages/agent/src/adapters/claude/session/instructions.ts:48
**AGENTS.md discovery omits scoped guides**

When a repository has nested `AGENTS.md` files, or maintains independent `AGENTS.md` content alongside `CLAUDE.md`, this instruction skips applicable conventions, causing generated edits to violate the repository rules this feature is intended to enforce.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "feat(agent): instruct sessions to follow..." | Re-trigger Greptile

Comment thread products/desktop/packages/agent/src/adapters/claude/session/instructions.ts Outdated
@VojtechBartos VojtechBartos added the reviewhog ($$$) Reviews pull requests before humans do label Aug 31, 2026
@posthog

posthog Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦔 PostHog Review reviewed this pull request

Nothing worth raising this time, so here's a calming picture instead:

A happy dog on a sunny path

@posthog posthog Bot removed the reviewhog ($$$) Reviews pull requests before humans do label Aug 31, 2026
AGENTS.md guidance no longer gates on CLAUDE.md being absent: the
agent checks AGENTS.md at the root and in edited directories, and
skips only content that mirrors CLAUDE.md. Nested .cursor/rules/
directories are named as well.

@skoob13 skoob13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might be adding useless tokens here. It's worth checking whether CLAUDE/AGENTS.md applies automatically. If not, makes sense to fix that first.


Repositories carry their own coding conventions. Before your first edit, discover and read the ones this harness does not load for you:

- \`AGENTS.md\` files: at the repo root and in any directory whose files you edit. \`CLAUDE.md\` is loaded for you automatically; when an \`AGENTS.md\` merely mirrors it you can move on, but when it carries its own content, follow that too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't AGENTS/CLAUDE.md files automatically apply? I don't think we need to mention it here.

@VojtechBartos VojtechBartos Aug 31, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Claude automatically apply for Claude SDK
Agent for Codex

So if you have both, that's great, but if you are having just CLAUDE.md and using our codex, it will be ignored.

If not, makes sense to fix that first.

You mean updating our harness to include the .md files as part of the prompt? If yes, kinda had the solution, but looks really heavy

Repositories carry their own coding conventions. Before your first edit, discover and read the ones this harness does not load for you:

- \`AGENTS.md\` files: at the repo root and in any directory whose files you edit. \`CLAUDE.md\` is loaded for you automatically; when an \`AGENTS.md\` merely mirrors it you can move on, but when it carries its own content, follow that too.
- Cursor rule files: \`.cursor/rules/*.mdc\` (the repo root's, and any nested \`.cursor/rules/\` near the files you edit) and the legacy \`.cursorrules\`. These are never loaded automatically. A rule's frontmatter tells you its scope: \`alwaysApply: true\` rules apply to every change, \`globs\` scope a rule to matching files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

They should probably migrate to AGENTS/CLAUDE instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally, but a lot of users still using that :(

@trunk-io
trunk-io Bot merged commit 642c476 into master Sep 1, 2026
200 checks passed
@trunk-io
trunk-io Bot deleted the vojtab/agent-repo-rules branch September 1, 2026 08:02
@deployment-status-posthog

deployment-status-posthog Bot commented Sep 1, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-09-01 08:26 UTC Run
prod-us ✅ Deployed 2026-09-01 08:57 UTC Run
prod-eu ✅ Deployed 2026-09-01 08:57 UTC Run

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.

2 participants