Does Diamond know the location of file-based rules...
# ideas
k
Does Diamond know the location of file-based rules? It's awesome to see that Diamond now supports rules defines in checked in files! 🎉 I want to find out if an idea I have would would work... Problem There are some "localized gotchas" I would like Diamond to pay extra attention to. They're fairly trivial things, just easy to miss by a human and not possible to enforce with a linter or typechecker. Two examples: 1. In a
pytest
file which contains Python service fixtures, instantiate dependent services from scratch (using a shared DB session), instead of using their global fixtures. 2. If the content of an external-facing docs page changes significantly, review the frontmatter
description:
property of the relevant
.mdx
file. Solution I'm hypothesising Wanted to create a custom file-based Diamond ruleset for these gotchas, based on globbing a pattern like
*.diamondrules
. I wanted to start with a
/.root.diamondrules
file like this:
Copy code
# What are `.diamondrules` files?

Files with the `.diamondrules` extension are used to define "localized gotchas" to pay careful attention to.

As an AI code reviewer:

1. Diligently follow the procedures described by these rules.
2. Apply these rules to files in the same directory as the `*.diamondrules` file, especially if it references a specific relative file.
And then we'd put write extra
.*.diamondrules
files as needed in each dir, for example:
Copy code
# Maintaining consistent `description` Frontmatter property

Whenever an `*.mdx` file in this directory is modified, review that the `description` Frontmatter property matches the updated content of the file.
Some Qs: 1. Do you think this would work? 2. When you concatenate the globbed files, does the resulting prompt / tool call output also give diamond the location of each file? 3. Can Diamond look over the whole file when doing code review? In these gotchas sometimes context more than a few hundred lines away from the diff is important. CC @Alyssa Baum for thoughts
These rules are completely independent from each other, so ideally each of them would be run as a separate agent to improve performance. But I don't think it's possible to define custom file-based rules this way... My understanding is that they must be concatenated into a single agent.
j
@Peter Stakoun 👀 (Alyssa has moved on from Graphite! we miss her! and i need to remove her as a workspace admin lol)
🙏 1
Immediate answer, we are planning to add this type of context to the file-based rules system, but started with the open-ended version so we could collect this sort of feedback! super helpful, ty for the detail
🙏 1
k
Thanks Jacob, would love a ping when you're thinking about testing something that would support this use case. I'm thinking about shipping this anyway now, and seeing how it would perform? Hopefully would provide some value already, and any changes on your end would only improve it.
j
yeah, go for it!
👍 1
let me double check that we pass the filename with each rule, I think we do but not sure
k
Thanks so much, lmk! (Would love to hear about 3 too btw)
j
we may not currently
👍 1
(pass the rule filename)
Can Diamond look over the whole file when doing code review? In these gotchas sometimes context more than a few hundred lines away from the diff is important.
this is rolling out slowly, you may get some reviews with full file context
k
Cool, so for now we'll need to use absolute paths to describe the files they apply to. Just a little more error prone / something people can forget, but I trust you'll be improving the experience there!
👍 1
Gonna try something like this:
Copy code
---
ruleLocation: /
ruleTitle: What are `.diamondrules` files?
---

Files with the `.diamondrules` extension are used to define "localized gotchas" to pay careful attention to.

As an AI code reviewer:

1. Diligently follow the procedures described by these rules.
2. Apply these rules to files in the same directory as the `*.diamondrules` file, especially if it references a specific relative file.
Copy code
---
ruleLocation: /python/services/backend/api-docs/
ruleTitle: Maintain consistent `description` Frontmatter property
---

Whenever an `*.mdx` file in this directory is modified, review that the `description` Frontmatter property matches the updated content of the file.
and add a CI check that
ruleLocation
is correct the frontmatter block should also make them nicely distinct, regardless of how you concatenate them
👍 1