Publish AED canon v1.1.0-rc.1 (mirror of AgentC-Consulting/aed-conventions)
Browse files- 01_why_models_need_this.md +53 -0
- 02_naming_conventions.md +250 -0
- 03_process_managers.md +29 -0
- 04_feature_stories.md +63 -0
- 05_edit_level_style.md +43 -0
- 06_control_flow.md +907 -0
- 07_how_the_workflow_runs.md +13 -0
- ADOPTION.md +167 -0
- CITATION.cff +39 -0
- CONVENTIONS.md +140 -0
- LICENSE +42 -0
- LICENSE-EXAMPLES +27 -0
- README.md +87 -0
- dist/aed-v1.1.0-rc.1.md +1751 -0
- evidence/benchmark_data.json +306 -0
- evidence/haiku_comprehension_report.md +231 -0
- examples/01_branch_on_type.cr +57 -0
- examples/02_name_the_thing.cr +32 -0
- examples/03_guard_clauses.cr +24 -0
- examples/04_reader_first_names_and_comments.cr +33 -0
- examples/README.md +15 -0
- llms.txt +89 -0
- quick_reference.md +220 -0
01_why_models_need_this.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 01 · Why Models Need This
|
| 2 |
+
|
| 3 |
+
*Excerpted **verbatim** from the author's `naming_conventions.md`, lifted to the
|
| 4 |
+
front of the reading order because it explains why every later rule exists.
|
| 5 |
+
The complete original — with this passage in place — is
|
| 6 |
+
[02_naming_conventions.md](02_naming_conventions.md).*
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
Naming conventions are one of the ways that drive the agent enhanced development workflow. The reason for this is that AI models use token windows to understand the context of things. 
|
| 11 |
+
|
| 12 |
+
## Basic Explanation of Tokens & Token Window
|
| 13 |
+
|
| 14 |
+
AI models, specifically LLMs, use tokens to represent groups of text. For example the statement:
|
| 15 |
+
|
| 16 |
+
`I want to create a new user and assign them to an account.`
|
| 17 |
+
|
| 18 |
+
For this example I’ll use Llama 3 to tokenize this prompt. When we tokenize this prompt, it turns into these tokens:
|
| 19 |
+
|
| 20 |
+
\`
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
'I'
|
| 24 |
+
' want'
|
| 25 |
+
' to'
|
| 26 |
+
' create'
|
| 27 |
+
' a'
|
| 28 |
+
' new'
|
| 29 |
+
' user'
|
| 30 |
+
' and'
|
| 31 |
+
' assign'
|
| 32 |
+
' them'
|
| 33 |
+
' to'
|
| 34 |
+
' an'
|
| 35 |
+
' account'
|
| 36 |
+
'.'
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
The extra spaces inside of the single quotes here is to highlight that spaces can be part of a token. Now when the AI model is scanning through the prompt, it’s going to read a group of tokens at a time, shifting down as it processes. For this example I’ll use a 8 token window, shifting 4 tokens at a time so there is some overlap.
|
| 40 |
+
|
| 41 |
+
Starting token window `’I want to create a new user and’`
|
| 42 |
+
|
| 43 |
+
Next token window `’ a new user and assign them to an’`
|
| 44 |
+
|
| 45 |
+
Final token window `‘ assign them to an account.’`
|
| 46 |
+
|
| 47 |
+
This window is typically larger than this, but for this example it illustrates how as the window shifts and the LLM model associates groups of tokens. This association is how the relationship of a flow of words is established and influences the direction that the model computes. This is why a naming convention needs to be very consistent.
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
*Chapter 01 of the AED canon · continue to
|
| 52 |
+
[02 · Naming Conventions](02_naming_conventions.md) ·
|
| 53 |
+
[reading order](README.md#reading-order)*
|
02_naming_conventions.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Naming Conventions Overview for Agent Enhanced Development (AED or AE-dev)
|
| 2 |
+
|
| 3 |
+
`_This is a work in progress_`
|
| 4 |
+
|
| 5 |
+
Naming conventions are one of the ways that drive the agent enhanced development workflow. The reason for this is that AI models use token windows to understand the context of things. 
|
| 6 |
+
|
| 7 |
+
## Basic Explanation of Tokens & Token Window
|
| 8 |
+
|
| 9 |
+
AI models, specifically LLMs, use tokens to represent groups of text. For example the statement:
|
| 10 |
+
|
| 11 |
+
`I want to create a new user and assign them to an account.`
|
| 12 |
+
|
| 13 |
+
For this example I’ll use Llama 3 to tokenize this prompt. When we tokenize this prompt, it turns into these tokens:
|
| 14 |
+
|
| 15 |
+
\`
|
| 16 |
+
|
| 17 |
+
```
|
| 18 |
+
'I'
|
| 19 |
+
' want'
|
| 20 |
+
' to'
|
| 21 |
+
' create'
|
| 22 |
+
' a'
|
| 23 |
+
' new'
|
| 24 |
+
' user'
|
| 25 |
+
' and'
|
| 26 |
+
' assign'
|
| 27 |
+
' them'
|
| 28 |
+
' to'
|
| 29 |
+
' an'
|
| 30 |
+
' account'
|
| 31 |
+
'.'
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
The extra spaces inside of the single quotes here is to highlight that spaces can be part of a token. Now when the AI model is scanning through the prompt, it’s going to read a group of tokens at a time, shifting down as it processes. For this example I’ll use a 8 token window, shifting 4 tokens at a time so there is some overlap.
|
| 35 |
+
|
| 36 |
+
Starting token window `’I want to create a new user and’`
|
| 37 |
+
|
| 38 |
+
Next token window `’ a new user and assign them to an’`
|
| 39 |
+
|
| 40 |
+
Final token window `‘ assign them to an account.’`
|
| 41 |
+
|
| 42 |
+
This window is typically larger than this, but for this example it illustrates how as the window shifts and the LLM model associates groups of tokens. This association is how the relationship of a flow of words is established and influences the direction that the model computes. This is why a naming convention needs to be very consistent.
|
| 43 |
+
|
| 44 |
+
## Patterns For Naming Conventions
|
| 45 |
+
|
| 46 |
+
For this section I’m going to use the example of implementing the feature story from above:
|
| 47 |
+
|
| 48 |
+
\`I want to create a new user and assign them to an account.
|
| 49 |
+
|
| 50 |
+
### The Rails Way - Conventions That Have Stood The Test of Time
|
| 51 |
+
|
| 52 |
+
The Rails framework has lead the way with “convention over configuration” for well over a decade now. You can really feel the difference this makes in your productivity when getting started. However, once you deviate from the normal Rails conventions you’ll find that Rails can become very painful to work with. This typically happens with non-RESTful business logic being intermingled into what should only be a RESTful end-point.
|
| 53 |
+
|
| 54 |
+
The Rails conventions would typically establish the following flow:
|
| 55 |
+
|
| 56 |
+
1. Assuming that the `UsersController` already exists, with the standard `create` action inside of it to handle a `POST` request
|
| 57 |
+
2. You (the dev) would update the allowed params to add an `account_id` parameter that would be used to allow the user to be associated to the account.
|
| 58 |
+
|
| 59 |
+
This works perfectly for a one-to-one relationship, where one user belongs to one account. What happens if we want to make a many-to-one relationship where the user can have multiple accounts it has access to? This is where the Rails conventions can start to become murky and developers get creative in their solutions.
|
| 60 |
+
|
| 61 |
+
You may do one of the following:
|
| 62 |
+
|
| 63 |
+
1. You create a service object or PORO to handle the logic from the request and neatly organize the process into 1 or more classes to handle the job.
|
| 64 |
+
2. You update the allowed params to make the `account_id` into an `account_ids` array that manages a join table that represents the association for the user.
|
| 65 |
+
3. You split the association into 2 end-points, and you have your UI perform multiple successive requests in order to create/update all of the relationships.
|
| 66 |
+
4. You stuff a bunch of logic into your controller to determine if/when updates to the joining records need to happen (most common rapid development approach).
|
| 67 |
+
|
| 68 |
+
Depending on the maturity of your app, you may start at option 3 and move up in sophistication or simplicity. There’s no real wrong answer here, just a lot of opinions.
|
| 69 |
+
|
| 70 |
+
Rails doesn’t have one way of handling increasingly complexity. It’s up to the developer who is writing the start of the feature to hopefully do it in a way that works right for the maturity level of the project at that time.
|
| 71 |
+
|
| 72 |
+
However, when we introduce an AI agent into the mix the story begins to change.
|
| 73 |
+
|
| 74 |
+
### The Agent Enhanced Way
|
| 75 |
+
|
| 76 |
+
Working with an AI agent can be a powerful multiplier for your efficiency as a dev, especially as the app grows in complexity. This is highly dependent on how clear the patterns are that you choose.
|
| 77 |
+
|
| 78 |
+
The pattern that you choose is critical because it heavily influences the models train of thought. Since AI models don’t have mental models like you or I do, they become heavily influenced by the way a prompt is written. You can effectively ask the same question, word it in various ways and get the AI to provide a varying answer. This is both good and bad. It means the AI can be articulate with some level of complexity, but it creates less certainty in the consistency required for coding. We can overcome this, mostly, by using a more strict and consistent naming convention.
|
| 79 |
+
|
| 80 |
+
Let’s start by looking at something that would generally be acceptable as “good code”.
|
| 81 |
+
|
| 82 |
+
```crystal
|
| 83 |
+
class Customer
|
| 84 |
+
property name : String
|
| 85 |
+
property email : String
|
| 86 |
+
|
| 87 |
+
def initialize(@name, @email)
|
| 88 |
+
end
|
| 89 |
+
|
| 90 |
+
end
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Here we have the barest of minimums that represent a Customer for our new SaaS product. After all, this entire method is around building and maintaining products as they grow in complexity.
|
| 94 |
+
|
| 95 |
+
I am intentionally skipping persistence methods because this explanation is about naming conventions.
|
| 96 |
+
|
| 97 |
+
Our first job is going to be setting up subscriptions for Customers. A Customer can have many Subscriptions.
|
| 98 |
+
|
| 99 |
+
So now we have a setup like this:
|
| 100 |
+
|
| 101 |
+
```crystal
|
| 102 |
+
class Subscription
|
| 103 |
+
property name : String
|
| 104 |
+
property rate : Int16
|
| 105 |
+
property quantity : Int16
|
| 106 |
+
|
| 107 |
+
def initialize(@name, @rate, @quantity)
|
| 108 |
+
end
|
| 109 |
+
|
| 110 |
+
end
|
| 111 |
+
|
| 112 |
+
class Customer
|
| 113 |
+
property name : String
|
| 114 |
+
property email : String
|
| 115 |
+
property subscriptions : Array(Subscription) = [] of Subscription
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def initialize(@name, @email)
|
| 119 |
+
end
|
| 120 |
+
|
| 121 |
+
end
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
At this point the relationship between the two objects is clear and the names are simple and imply their intended meaning. Our minds have mental models of what a Customer is and what a Subscription is because of our life experience. We can fill in the implications of what the property and its type mean. The `name` property is relatively clear.
|
| 125 |
+
|
| 126 |
+
However, to an AI this kind of naming is less than ideal. It will probably still work, but will progressively become less and less useful as the classes grow in complexity.
|
| 127 |
+
|
| 128 |
+
Instead if we change to a more verbose naming convention that adds in contextual meaning, the AI is better able to understand what we are trying to do.
|
| 129 |
+
|
| 130 |
+
Let’s focus on the Customer class first and you’ll see what I mean.
|
| 131 |
+
|
| 132 |
+
```crystal
|
| 133 |
+
class Customer
|
| 134 |
+
property first_name : String
|
| 135 |
+
property last_name : String
|
| 136 |
+
property email_address : String
|
| 137 |
+
property list_of_all_active_subscriptions : Array(Subscription) = [] of Subscription
|
| 138 |
+
|
| 139 |
+
def initialize(@name, @email)
|
| 140 |
+
end
|
| 141 |
+
|
| 142 |
+
end
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
You may have noticed that a lot has changed and at the same time, we changed very little.
|
| 146 |
+
|
| 147 |
+
Notice how explicit the name attributes are now? The name before could have been first, last, middle initial or full name. Who knows? We certainly didn’t have those details before. A more senior developer reading this probably picked up on that quickly!
|
| 148 |
+
|
| 149 |
+
We’ve now expanded our `email` to `email_address` because now it’s 100% clear that we intend to store an email address there and some kind of flag that says the email subscription list that the Customer belongs to. It was implied that the value was intended to be an email address, but it’s entirely possible its intended use was not that.
|
| 150 |
+
|
| 151 |
+
The changes to our old `subscriptions` property are a bit shocking! Did you have any idea that all you needed to track were the active subscriptions? Maybe during the conversation with a product owner, but the AI would have no idea. By updating the naming we now have a clear purpose given to that property with a contextually significant meaning.
|
| 152 |
+
|
| 153 |
+
So far all of the examples are fairly simple and straight forward. In fact, this is already pretty close to what would be considered “good” naming practices. So let’s take this to the next level where there’s a lot more complexity. This is where real business logic becomes messy and far less non-obvious.
|
| 154 |
+
|
| 155 |
+
Well the good news is that our little SaaS is growing up and now has more products and all new licensing. The sales team has been getting enterprise customer inquiries and the deal size is so big that the product team is now being told we need to adapt our one Customer to many Subscriptions model to allow for Customers who aggregate into a single billable entity, and prevents these users from adding any subscription items.
|
| 156 |
+
|
| 157 |
+
By the way, you have a super short window to implement so there’s no way to take time to architect this thoroughly and perform any data migrations.
|
| 158 |
+
|
| 159 |
+
That’s alright, this type of feature request is the Achilles Heel of many code bases. Typically in this kind of scenario we start seeing naming becoming a challenge. Let’s see how we can do it so that it benefits our AI agent assistant, or how our agent would be implementing this feature if we let it drive for us.
|
| 160 |
+
|
| 161 |
+
```crystal
|
| 162 |
+
class Customer
|
| 163 |
+
property first_name : String
|
| 164 |
+
property last_name : String
|
| 165 |
+
property email_address : String
|
| 166 |
+
property list_of_all_active_subscriptions : Array(Subscription) = [] of Subscription
|
| 167 |
+
property is_this_an_enterprise_customer : Bool
|
| 168 |
+
|
| 169 |
+
def initialize(@first_name, @last_name, @email_address, @is_this_an_enterprise_customer = false)
|
| 170 |
+
end
|
| 171 |
+
|
| 172 |
+
end
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class EnterpriseCustomerBillingEntity
|
| 177 |
+
property full_legal_entity_name : String
|
| 178 |
+
property payment_terms_in_number_of_days : Int8
|
| 179 |
+
property billing_cycle_frequency : Int8
|
| 180 |
+
property billing_cycle_time_period : String
|
| 181 |
+
property maximum_customers_according_to_the_contract_limit : Int16
|
| 182 |
+
property current_count_of_customer_accounts : UInt16
|
| 183 |
+
|
| 184 |
+
def initialize(@full_legal_entity_name, @payment_terms_in_number_of_days, @billing_cycle_frequency, @billing_cycle_time_period, @maximum_customers_according_to_the_contract_limit, @current_count_of_customer_accounts)
|
| 185 |
+
end
|
| 186 |
+
|
| 187 |
+
end
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
We now have this new class mixed in that handles the enterprise details. This isn’t about programming the full workflow, it’s about the naming convention used here. A pattern is beginning to emerge.
|
| 191 |
+
|
| 192 |
+
Now depending on your level of seniority as a dev, you may read those class attributes and think “yeah that’s basically what I would do, except I’d simplify the names a bit”. And this is when I can begin outlining the general rules to follow when writing code you want an AI assistant to flourish with:
|
| 193 |
+
|
| 194 |
+
1. Object attributes with primitive types should be short statements or phrases
|
| 195 |
+
2. Object attributes that are booleans should be phrased as a “yes/no” question or statement
|
| 196 |
+
3. Object attributes that are collections, Arrays or enumerable in some way. Usually it’s good to start the name like “list\_of\_” or “array\_of\_” with a descriptive name of the object types it’s holding.
|
| 197 |
+
|
| 198 |
+
Following these guidelines will help keep your naming conventions consistent which helps provide clarity and contextual understanding for your AI agent. It’s also good for you, because you may come back to this code many months or years later and you will not remember the product meeting details but you can clearly read your code.
|
| 199 |
+
|
| 200 |
+
### Method & Variable Naming
|
| 201 |
+
|
| 202 |
+
Next let’s discuss method and variable naming. This is the most common area where devs can help themselves greatly, but typically fall short. Clever naming can make short variable names for easier readability but the context of what and why quickly disappears into your editors background.
|
| 203 |
+
|
| 204 |
+
We left some of the business logic that was in our new feature requirement that we can use for this part. The part we are going to focus on is going to be:
|
| 205 |
+
|
| 206 |
+
`prevents these users from adding any subscription items`
|
| 207 |
+
|
| 208 |
+
This is something that we can use a process manager to handle while exercising good naming conventions.
|
| 209 |
+
|
| 210 |
+
This is a process manager, but it does not use “process” or “manager” in the name. It is acceptable with or without including those details. 
|
| 211 |
+
|
| 212 |
+
```crystal
|
| 213 |
+
class AddSubscriptionToCustomer
|
| 214 |
+
property customer_to_add_subscription_to : Customer
|
| 215 |
+
property subscription_to_add_to_customer : Subscription
|
| 216 |
+
|
| 217 |
+
def initialize(@customer_to_add_subscription_to, @subscription_to_add_to_customer)
|
| 218 |
+
end
|
| 219 |
+
|
| 220 |
+
def add_subscription_to_customer
|
| 221 |
+
return if @customer_to_add_subscription_to.is_this_an_enterprise_customer
|
| 222 |
+
|
| 223 |
+
@customer_to_add_subscription_to.list_of_all_active_subscriptions << subscription_to_add_to_customer
|
| 224 |
+
end
|
| 225 |
+
end
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
1. The class name for the process manager clearly states what the entire process is attempting to do in a short statement.
|
| 229 |
+
2. The initialize method accepts all of the initial data required to perform the process
|
| 230 |
+
3. The name of the method to start the process is clear and obvious. 
|
| 231 |
+
|
| 232 |
+
This reads very plainly now. The logic in the `return` line reads almost like a complete sentence. This makes the intent very clear for both you the developer and your AI agent assistant.
|
| 233 |
+
|
| 234 |
+
The variable names clearly state what the contents are, and the intended use.
|
| 235 |
+
|
| 236 |
+
The method name clearly states the action that is being performed. It does not take any parameters because the intended purpose of a process manager is to be initialized with all of the data it needs in order to perform the process it is managing.
|
| 237 |
+
|
| 238 |
+
Do you come across code this plainly and clearly written? Maybe. It’s more than likely that it’s plain on that it uses simpler wording and phrasing that is less robust, but still clear. You may have seen `customer_to_update` and considered that good over just `customer`. Maybe you consider the one word better. But your AI agent is going to have less and less of a clear intent by using such simplified wording.
|
| 239 |
+
|
| 240 |
+
## The Compounding Rewards of Enhanced Naming
|
| 241 |
+
|
| 242 |
+
You are rewarded for clearer naming practices as your files get larger. In fact, you may start implementing these naming conventions and notice something strange. At first, your code completion suggestions from typical AI coding assistants will usually be pretty bad. Only at first, but it’s distinctly noticeable.
|
| 243 |
+
|
| 244 |
+
Github Copilot tends to be the worst offender by offering up code snippets that are close but make silly naming mistakes when re-using existing variables. Mistakes such as pluralizing when the variable should be phrased singularly and vice-versa.
|
| 245 |
+
|
| 246 |
+
I use Cursor, which has a Copilot++ in editor code suggestion tool and it tends to work much better. It still has lower quality suggestions initially, but as your files grow in size, the suggestions and understanding of what you are trying to do become increasingly more accurate. This includes across files when you’re using Copilot++.
|
| 247 |
+
|
| 248 |
+
---
|
| 249 |
+
|
| 250 |
+
*Chapter 02 of the AED canon · published **verbatim** from the author's original; the work-in-progress marker at the top is his own, kept as written · continue to [03 · Process Managers](03_process_managers.md) · [reading order](README.md#reading-order)*
|
03_process_managers.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Process Manager Conventions
|
| 2 |
+
|
| 3 |
+
`_This is a work in progress_`. Updated on 11/24/2025
|
| 4 |
+
|
| 5 |
+
Process managers are a convention that AI agents need to organize an unRESTful process. This is commonly domain specific business logic or workflows.
|
| 6 |
+
|
| 7 |
+
A process manager name is a statement or phrase that describes what is being done.
|
| 8 |
+
|
| 9 |
+
Let’s use an example of building a report. We are just going to describe the feature story that defines this process, and the triggering event. For this example our app has Customers: 
|
| 10 |
+
|
| 11 |
+
`When a list of Customer ID’s is provided, then lock each customers account.`
|
| 12 |
+
|
| 13 |
+
Processes start with a “when” keyword, always. Because a process is “when” something happens!
|
| 14 |
+
|
| 15 |
+
The second statement “a list of Customer ID’s is provided” tells us the qualifying information we need before this process can be performed. Here were are referencing a “list” aka an Array of IDs which is the attribute type from the Customer model. This could be integers, ULID, UUID’s etc.
|
| 16 |
+
|
| 17 |
+
The second half “lock each customers account” is using jargon that represents an operation we define for the business. “Locking” an account for this means: changing an attribute in the Customer model that requires an additional input from the user to confirm their identity and reset their password.
|
| 18 |
+
|
| 19 |
+
A process manager can perform many operations at a time, and typically will. The more complicated the process, the more likely to require human intervention to write the complete the process writing.
|
| 20 |
+
|
| 21 |
+
If we expand our process statement, it looks like the following:
|
| 22 |
+
|
| 23 |
+
`When an array of Integers that represent Customer IDs is provided then loop through each Customer account using the ID to find the correct record and update the necessary attribute that will prevent the Customer from accessing their account.`
|
| 24 |
+
|
| 25 |
+
The AI is going to analyze this and ultimately make the determination if any jargon was used, and will ask questions if it can’t understand your intent. It will generally phrase it like I explained above, and may provide more details.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
*Chapter 03 of the AED canon · published **verbatim** from the author's original (last revised 2025-11-24); the work-in-progress marker at the top is his own, kept as written · continue to [04 · Feature Stories](04_feature_stories.md) · [reading order](README.md#reading-order)*
|
04_feature_stories.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Agent Enhanced Development - The Whole Process
|
| 2 |
+
|
| 3 |
+
## Introduction To What A Feature Request Is
|
| 4 |
+
The idea of “operating” an AI means we need to be able to define it’s “operations” to begin with.
|
| 5 |
+
|
| 6 |
+
An operation is essentially the work flow for performing a task. This should encompass multiple steps and possibly “tasks” depending on how you want to define a task.
|
| 7 |
+
|
| 8 |
+
To operate an AI agent successfully, we have to shift our mindset on a few topics, such as:
|
| 9 |
+
|
| 10 |
+
1. How we define the work that we want to perform
|
| 11 |
+
2. The expected patterns or overall flexibility we have in our code base
|
| 12 |
+
3. Our definition of naming conventions and what "clear" means for us
|
| 13 |
+
4. How we perform development work
|
| 14 |
+
5. The relationship between the code we write and how it reflects the business
|
| 15 |
+
|
| 16 |
+
To begin with, we are going to start by more clearly defining what a `feature request` really is. If you've been a developer for any period of time, you've most likely already worked with scrum or agile and been exposed to User Stories. The idea here is pretty similar, however instead of managing the details of the story from a 3rd party tool such as Jira, we are going to manage the details directly with our AI agent that works from our code base.
|
| 17 |
+
|
| 18 |
+
Let's define some critical terminology before we move forward.
|
| 19 |
+
|
| 20 |
+
**Operation**: the interaction with the AI agent and ensuring it has the correct knowledge and understanding to perform.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## Our First Feature Request
|
| 24 |
+
Let’s describe some default operations that should come with the framework. I have notes about user stories and I think that operating an AI development agent should mean using Feature Stories to control the behavior of the agent and the outcome.
|
| 25 |
+
|
| 26 |
+
First a simple user story:
|
| 27 |
+
|
| 28 |
+
`As an **Admin** user, I want to _create_ a new **user** **_and_** _assign_ them to an **account**`
|
| 29 |
+
|
| 30 |
+
This story is pretty simple and would mean operations that are required use the typical MVC concepts, which makes things easy to start with.
|
| 31 |
+
|
| 32 |
+
The `As an Admin` establishes our persona, scoping the following **action** to be performed. When there is a persona we have chosen, we also know the feature request requires a view and a controller action at a minimum. Our agent knows which views belong to which controller actions, and if we need to create that controller, action, view etc.
|
| 33 |
+
|
| 34 |
+
The action is the full statement. It should be a clear summary of what would complete a request/response cycle. If it triggers or enqueues a background job, that should be stated. The action description should also include references to any data models that require a relationship. In the example that’s User and Account. The plurality of the data models dictates the relationships between them, and should use the same Active Record pattern expressions as in Rails.
|
| 35 |
+
|
| 36 |
+
The “I want to” part is provided as part of the story builder. The action verb needs to be an HTTP verb of GET POST PUTS PATCH or DELETE followed by the primary data model that is effected.
|
| 37 |
+
|
| 38 |
+
A unique verb of “perform” can be used to trigger a workflow that is not RESTful. This is the keyword you primarily use for our unique business logic, aka your special sauce.
|
| 39 |
+
|
| 40 |
+
The specially called out “and” in the action is because we follow up a simple RESTful action with a secondary action, and it’s establishing a relationship with an additional record. In this case I highlighted “assign” because it’s an example of company jargon that can alias an Active Record relationship of “belongs to”. These kinds of aliases can be configured with restrictions/conditions before creating a feature story. This story implies it is limited to linking the newly created user to an existing account, and that it does not create a new account.
|
| 41 |
+
|
| 42 |
+
A feature story with a persona breaks down it’s structure like this:
|
| 43 |
+
|
| 44 |
+
`As a (specify persona), I want to (RESTful verb, or “perform”) (“a” or “multiple”) (data model name of an existing data model) and (AR relationship name/type or “perform”) (data model name or Process Manager name if performing a process)`
|
| 45 |
+
|
| 46 |
+
A “persona” is a specialized alias of a User data model type that includes an indication of the “authorization” (ie permissions) level of that model type. For example, an Admin persona could be an alias of a Super Administrator type that has unrestricted permissions, which means they would be using controllers/routes that are scoped to this kind of user.
|
| 47 |
+
|
| 48 |
+
Authorization levels work in several ways together to create a robust authorization system.
|
| 49 |
+
|
| 50 |
+
- Model type: the model name should represent the general permission level of that group. This is resource based, so an Administrator user type may have its own API and all administrators would generally be considered to use those end-points.
|
| 51 |
+
- Action specific: RESTful verbs have a matching permission level two on the actual model as an attribute. Your app configuration should define if by default the user of that group is allowed or disallowed, and if the flag necessary to perform the action needs to be specified on the models record.
|
| 52 |
+
- Individual resource: individual resources can restrict behavior to model type or record ID’s.
|
| 53 |
+
|
| 54 |
+
For unRESTful end-points, the permissions are based on if the model type or specific records of models are allowed to execute an action.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
## Breakdown of The Anatomy of A Feature Request
|
| 58 |
+
|
| 59 |
+
TBD
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
*Chapter 04 of the AED canon · published **verbatim** from the author's original. The closing `TBD` is the author's own — the anatomy breakdown is genuinely unwritten, and this release candidate marks it rather than papering over it · continue to [05 · Edit-Level Style](05_edit_level_style.md) · [reading order](README.md#reading-order)*
|
05_edit_level_style.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 05 · Edit-Level Style
|
| 2 |
+
|
| 3 |
+
Chapter 05 of the canon lives at **[CONVENTIONS.md](CONVENTIONS.md)** — six
|
| 4 |
+
rules for how a single line should read, each with before/after Crystal.
|
| 5 |
+
|
| 6 |
+
It keeps its original filename and its `#rule-1` … `#rule-6` anchors on
|
| 7 |
+
purpose. Those anchors were published in v1.0.0 and are cited from outside
|
| 8 |
+
this repository; moving them to renumber a chapter would break every one of
|
| 9 |
+
those links for no reader's benefit.
|
| 10 |
+
|
| 11 |
+
## Where it sits in the canon
|
| 12 |
+
|
| 13 |
+
Chapters 01–04 are the structural doctrine: why models need consistent naming,
|
| 14 |
+
what to name things, how to shape a process manager, how to write a feature
|
| 15 |
+
story. Chapter 05 is narrower and later — it governs the individual edit, once
|
| 16 |
+
the structure is already decided.
|
| 17 |
+
|
| 18 |
+
Read in that order it is a fair chapter. Read alone — which is all v1.0.0
|
| 19 |
+
offered — it reads as though AED were a six-item style guide, which it is not.
|
| 20 |
+
That was the gap this release closes.
|
| 21 |
+
|
| 22 |
+
- [CONVENTIONS.md#rule-1](CONVENTIONS.md#rule-1) — branch on type with an explicit `if … is_a?`
|
| 23 |
+
- [CONVENTIONS.md#rule-2](CONVENTIONS.md#rule-2) — name the thing; don't make the reader decode a chain
|
| 24 |
+
- [CONVENTIONS.md#rule-3](CONVENTIONS.md#rule-3) — prefer explicit guard clauses to nested ternaries
|
| 25 |
+
- [CONVENTIONS.md#rule-4](CONVENTIONS.md#rule-4) — use full, intention-revealing names
|
| 26 |
+
- [CONVENTIONS.md#rule-5](CONVENTIONS.md#rule-5) — say *why* in a comment, let the code say *what*
|
| 27 |
+
- [CONVENTIONS.md#rule-6](CONVENTIONS.md#rule-6) — one statement per line; let the formatter own the layout
|
| 28 |
+
|
| 29 |
+
Plus the [shorthand boundary](CONVENTIONS.md#shorthand-boundary) and the
|
| 30 |
+
[end-of-edit checklist](CONVENTIONS.md#checklist).
|
| 31 |
+
|
| 32 |
+
## One known conflict with chapter 02
|
| 33 |
+
|
| 34 |
+
CONVENTIONS.md rule 4 offers `expected_state` as an improved name. By
|
| 35 |
+
[chapter 02](02_naming_conventions.md) that name is still under-specified —
|
| 36 |
+
expected by whom, of what, in what units? Chapter 02 is the authority where
|
| 37 |
+
the two disagree. Reconciling the example is tracked for v1.1.0 final.
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
*Chapter 05 of the AED canon · continue to
|
| 42 |
+
[06 · Control Flow](06_control_flow.md) ·
|
| 43 |
+
[reading order](README.md#reading-order)*
|
06_control_flow.md
ADDED
|
@@ -0,0 +1,907 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 06 · Control Flow (CF-1 … CF-11)
|
| 2 |
+
|
| 3 |
+
> **Status**: RELEASE CANDIDATE. These eleven rules ship in `v1.1.0-rc.1` as a
|
| 4 |
+
> candidate, not as settled canon. The numbered questions at the end are still
|
| 5 |
+
> open, and the answers may change individual thresholds before `v1.1.0` final.
|
| 6 |
+
> Adopt them if they help; expect the edges to move.
|
| 7 |
+
>
|
| 8 |
+
> **Scope question answered here**: how should AED handle control-flow code
|
| 9 |
+
> whose *syntax* does not naturally align with the reads-like-statements rule?
|
| 10 |
+
> A `while` loop, a `rescue` ladder, or a `spawn` block has no name of its own
|
| 11 |
+
> — the syntax is pure mechanism. AED's answer, developed rule by rule below:
|
| 12 |
+
> **when the syntax can't read like a statement, the *names around it* must
|
| 13 |
+
> say what the syntax is doing.**
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## 0. Census — what actually occurs in our Crystal
|
| 18 |
+
|
| 19 |
+
Rules should target real frequency, not theory. Counted with `grep -rE`
|
| 20 |
+
across the two live codebases (regex counts are ceilings — e.g. the ternary
|
| 21 |
+
pattern also matches nilable type signatures; noted where it matters):
|
| 22 |
+
|
| 23 |
+
| Pattern | premium template `src/` (107 files, 12,250 lines) | agentc_website `src/` (22 files, 2,163 lines) |
|
| 24 |
+
|---|---:|---:|
|
| 25 |
+
| Leading `if` | 154 | 23 |
|
| 26 |
+
| `if … is_a?` (existing Rule 1) | 6 | 0 |
|
| 27 |
+
| `case` statements | 28 | 3 |
|
| 28 |
+
| `when` branches | 124 | 6 |
|
| 29 |
+
| `case … in` | **0** | **0** |
|
| 30 |
+
| Leading `unless` | 25 | 5 |
|
| 31 |
+
| Any ` unless ` (incl. postfix) | 150 | 24 |
|
| 32 |
+
| `while` | 4 | 8 |
|
| 33 |
+
| `until` | **0** | **0** |
|
| 34 |
+
| `loop do` | 2 | 0 |
|
| 35 |
+
| `break` | 3 | 12 |
|
| 36 |
+
| `next` | 15 | 3 |
|
| 37 |
+
| `return` (all) | 127 | 43 |
|
| 38 |
+
| Guard `return … if` | 36 | 19 |
|
| 39 |
+
| Guard `return … unless` | 58 | 7 |
|
| 40 |
+
| Ternary `? … :` (regex ceiling; true ternaries ≈ half) | 61 | 16 |
|
| 41 |
+
| `begin` | 14 | 2 |
|
| 42 |
+
| `rescue` | 57 | 8 |
|
| 43 |
+
| `ensure` | 13 | 0 |
|
| 44 |
+
| `retry` | **0** | **0** |
|
| 45 |
+
| `raise` | 156 (138 typed error, 14 bare string) | 1 |
|
| 46 |
+
| `spawn` | 4 (2 real code sites) | 0 |
|
| 47 |
+
| `Channel` | 1 | 0 |
|
| 48 |
+
| Concurrency `select` | **0** | **0** |
|
| 49 |
+
| `.each` | 16 | 7 |
|
| 50 |
+
| `.map` | 30 | 5 |
|
| 51 |
+
| `.select`/`.reject` | 13 | 4 |
|
| 52 |
+
| `.try` | 98 | 3 |
|
| 53 |
+
| `&.` shorthand | 116 | 7 |
|
| 54 |
+
| `macro` definitions | 3 | 0 |
|
| 55 |
+
| `{% if %}` compile-time branches | 2 | 0 |
|
| 56 |
+
| `def …?` predicate methods | 195 | 26 |
|
| 57 |
+
| `def …!` bang methods | 10 | 0 |
|
| 58 |
+
|
| 59 |
+
**What the census says:**
|
| 60 |
+
|
| 61 |
+
- The codebase already leans AED: guard returns (120 across both repos) far
|
| 62 |
+
outnumber loops (14); typed raises outnumber string raises 10:1; there are
|
| 63 |
+
195 `?` predicates in the template — the "name the question" culture exists.
|
| 64 |
+
- `case … in`, `until`, `retry`, and concurrency `select` occur **zero**
|
| 65 |
+
times. We can codify their status cheaply — banning what nobody uses costs
|
| 66 |
+
nothing and stops an agent from introducing them.
|
| 67 |
+
- The high-frequency gaps that need real rules: `case/when` menus (28+3
|
| 68 |
+
sites), guard ordering (120 guard returns with no stated ordering rule),
|
| 69 |
+
`unless` (175 total uses, some compound), `.try` (98 uses — the single
|
| 70 |
+
biggest "decode a chain" risk), and bare `rescue` (a large share of the 65
|
| 71 |
+
rescues carry no error name).
|
| 72 |
+
- The website's markdown parser is a legitimate **cursor-loop** cluster
|
| 73 |
+
(8 `while` + 12 `break` in one file family) — the loop rule must bless that
|
| 74 |
+
shape, not fight it.
|
| 75 |
+
|
| 76 |
+
---
|
| 77 |
+
|
| 78 |
+
## The core insight: mechanism syntax vs statement syntax
|
| 79 |
+
|
| 80 |
+
The existing skill's rule — *prefer the form that reads like a plain statement
|
| 81 |
+
of intent* — works effortlessly for **expressions**: you pick the spelling
|
| 82 |
+
that reads best. Control flow is different. `while`, `rescue`, `spawn`,
|
| 83 |
+
`{% if %}` are **mechanism keywords**: they say *how* execution moves, never
|
| 84 |
+
*why*. No amount of re-spelling makes `while @i < @lines.size` state an
|
| 85 |
+
intent.
|
| 86 |
+
|
| 87 |
+
So for control flow, AED shifts from "pick the readable spelling" to three
|
| 88 |
+
compensating moves, in priority order:
|
| 89 |
+
|
| 90 |
+
1. **Name the intent next to the mechanism** — the condition is a named
|
| 91 |
+
predicate, the body is a named method, the error is a named type, the
|
| 92 |
+
fiber does a named job.
|
| 93 |
+
2. **Keep the mechanism in one canonical shape** — one blessed way to write
|
| 94 |
+
each construct, so a reader (or a linting hook) recognizes it instantly.
|
| 95 |
+
3. **Ban the shapes that only ever obscure** — the census shows we already
|
| 96 |
+
live without them.
|
| 97 |
+
|
| 98 |
+
Every rule below is one of those three moves. Format per rule: (a) why the
|
| 99 |
+
raw syntax fights the reading rule, (b) the proposed rule with a crisp name,
|
| 100 |
+
(c) before/after in the skill's voice, (d) the honest cost, (e) the
|
| 101 |
+
mechanical check an agent, linter, or hook can apply.
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## Rule CF-1. `case` is a menu — every branch one bite
|
| 106 |
+
|
| 107 |
+
**(a) Why the syntax fights the rule.** A `case` on a *value* (`case action`,
|
| 108 |
+
`case fmt`, `case status_code`) is actually the closest control flow gets to
|
| 109 |
+
a plain statement — *"depending on the action: …"*. It stops reading like a
|
| 110 |
+
statement in exactly two ways: when a branch body grows into a paragraph (the
|
| 111 |
+
reader loses the menu and falls into one dish), and when the subject is an
|
| 112 |
+
expression the reader must evaluate first (`case ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase`).
|
| 113 |
+
|
| 114 |
+
**(b) Proposed rule — "Case is a menu, not a novel."**
|
| 115 |
+
Use `case … when` when branching a **single named value** across **three or
|
| 116 |
+
more** outcomes. Two outcomes is an `if/else` (a menu of two is just a
|
| 117 |
+
choice). Each `when` body is at most ~3 lines or a single named method call —
|
| 118 |
+
if a branch needs a paragraph, extract it to a method whose name is the
|
| 119 |
+
branch's intent. The `case` subject must be a **named local or a plain
|
| 120 |
+
method call**, never an inline expression chain. Always write an explicit
|
| 121 |
+
`else` that states the fallback (`false`, `raise`, or a named default) —
|
| 122 |
+
Crystal's `when` is not exhaustive, so the `else` is where you *say* what
|
| 123 |
+
happens to the unlisted world. `case … in` stays banned per existing Rule 1
|
| 124 |
+
(census: zero uses — nothing to migrate).
|
| 125 |
+
|
| 126 |
+
**(c) Before/after.**
|
| 127 |
+
|
| 128 |
+
```crystal
|
| 129 |
+
# ✅ AED — a menu: named subject, one bite per branch, spoken fallback
|
| 130 |
+
default_provider = ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase
|
| 131 |
+
case default_provider
|
| 132 |
+
when "anthropic" then Anthropic::Client.new
|
| 133 |
+
when "openai" then OpenAI::Client.new
|
| 134 |
+
else raise "Unknown AI_DEFAULT_PROVIDER: #{default_provider}"
|
| 135 |
+
end
|
| 136 |
+
|
| 137 |
+
# 🚫 subject is a puzzle the reader must evaluate before the menu even starts
|
| 138 |
+
case ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase
|
| 139 |
+
when "anthropic" then ...
|
| 140 |
+
end
|
| 141 |
+
|
| 142 |
+
# 🚫 a two-item "menu" — this is just an if wearing a costume
|
| 143 |
+
case backend
|
| 144 |
+
when :smtp then deliver_smtp(message)
|
| 145 |
+
else deliver_log(message)
|
| 146 |
+
end
|
| 147 |
+
# ✅ instead:
|
| 148 |
+
if backend == :smtp
|
| 149 |
+
deliver_smtp(message)
|
| 150 |
+
else
|
| 151 |
+
deliver_log(message)
|
| 152 |
+
end
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
The policy classes are the house exemplar already
|
| 156 |
+
(`src/policies/team_policy.cr`): `case action` with one-line branches
|
| 157 |
+
composed of `?` predicates (`team_lead? || admin_access?`) and `else false`.
|
| 158 |
+
That file reads like an access-control table — which is the point.
|
| 159 |
+
|
| 160 |
+
**(d) Cost.** Extracting fat branches adds methods; a reader who wants the
|
| 161 |
+
details takes one hop. Two-branch `case` fans will find the if/else rule
|
| 162 |
+
fussy. Accepted: the menu shape is only worth its visual weight when there is
|
| 163 |
+
an actual menu.
|
| 164 |
+
|
| 165 |
+
**(e) Mechanical check.** Flag: `case` whose subject line contains `.` more
|
| 166 |
+
than once or any `?.`/`ENV[`; any `when` body exceeding 3 lines; any `case`
|
| 167 |
+
with fewer than 3 `when` branches; any `case` without `else`; any `case … in`
|
| 168 |
+
(already caught by the compile hook on Grant types — extend to a grep ban).
|
| 169 |
+
|
| 170 |
+
---
|
| 171 |
+
|
| 172 |
+
## Rule CF-2. Loops state their finish line
|
| 173 |
+
|
| 174 |
+
**(a) Why the syntax fights the rule.** `while` states a *continuation
|
| 175 |
+
condition*, but a reader thinks in terms of a *finish line* ("keep going
|
| 176 |
+
until the lines run out"). Worse, `loop do … break` scatters the finish line
|
| 177 |
+
into the body, and an index cursor (`@i`) makes progress invisible — the
|
| 178 |
+
reader must verify the loop advances or they can't trust it terminates.
|
| 179 |
+
|
| 180 |
+
**(b) Proposed rule — "Every loop names its finish line and shows its
|
| 181 |
+
step."** Three blessed loop shapes, nothing else:
|
| 182 |
+
|
| 183 |
+
1. **Collection walk** — `items.each do |item|` (default; covers most needs).
|
| 184 |
+
2. **Cursor loop** — `while cursor_has_more?` over an explicit cursor, where
|
| 185 |
+
(i) the condition is a plain comparison or a named `?` predicate, (ii)
|
| 186 |
+
every `break` inside is a one-line guard whose condition is a named
|
| 187 |
+
predicate or plain comparison, and (iii) the cursor visibly advances in
|
| 188 |
+
the body (an `@i += n` a reader can point at). This blesses the website's
|
| 189 |
+
markdown parser shape (`while @i < @lines.size` … `break unless row?(s)` —
|
| 190 |
+
`article_markdown.cr` already complies, its break conditions are named
|
| 191 |
+
predicates like `ordered_item?`, `task_item?`, `row?`).
|
| 192 |
+
3. **Forever loop** — `loop do` only for intentionally unbounded work (the
|
| 193 |
+
SSE heartbeat in `mcp_sse_controller.cr`), and it must sit inside a method
|
| 194 |
+
whose **name says it loops** (`run_heartbeat_loop`, `pump_stdout`), with
|
| 195 |
+
its exit spelled as a guard (`break if client_disconnected?`).
|
| 196 |
+
|
| 197 |
+
If a loop body exceeds ~8 lines, extract the body to a method named for one
|
| 198 |
+
iteration's intent (`consume_blockquote`, `emit_table_row`) — the loop line
|
| 199 |
+
then reads *"while there are lines, consume the next block."*
|
| 200 |
+
`until` is **banned** (census: zero uses): `until done?` forces the reader to
|
| 201 |
+
negate in their head; write `while more?`.
|
| 202 |
+
|
| 203 |
+
**(c) Before/after.**
|
| 204 |
+
|
| 205 |
+
```crystal
|
| 206 |
+
# ✅ AED — cursor loop: named finish line, named break, visible step
|
| 207 |
+
while @i < @lines.size
|
| 208 |
+
line = @lines[@i].strip
|
| 209 |
+
break unless ordered_item?(line)
|
| 210 |
+
emit_ordered_item(line)
|
| 211 |
+
@i += 1
|
| 212 |
+
end
|
| 213 |
+
|
| 214 |
+
# 🚫 the finish line is a negation the reader must invert
|
| 215 |
+
until @i >= @lines.size
|
| 216 |
+
...
|
| 217 |
+
end
|
| 218 |
+
|
| 219 |
+
# 🚫 forever-loop with an anonymous job and a buried exit
|
| 220 |
+
loop do
|
| 221 |
+
sleep 15.seconds
|
| 222 |
+
begin
|
| 223 |
+
send_event(response, "ping", {time: Time.utc.to_unix})
|
| 224 |
+
rescue
|
| 225 |
+
break
|
| 226 |
+
end
|
| 227 |
+
end
|
| 228 |
+
# ✅ instead: the method name carries the loop's intent
|
| 229 |
+
private def run_heartbeat_loop(response) : Nil
|
| 230 |
+
loop do
|
| 231 |
+
sleep 15.seconds
|
| 232 |
+
break unless send_ping(response) # returns false when the client is gone
|
| 233 |
+
end
|
| 234 |
+
end
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
**(d) Cost.** Extraction adds one hop per fat loop; the "visible step" rule
|
| 238 |
+
occasionally forces an `@i += 1` where a cleverer restructure could avoid the
|
| 239 |
+
cursor entirely. Accepted: termination you can point at beats elegance you
|
| 240 |
+
must simulate.
|
| 241 |
+
|
| 242 |
+
**(e) Mechanical check.** Flag: any `until`; any `loop do` in a method whose
|
| 243 |
+
name lacks `loop`/`pump`/`watch`/`poll`; any `while` body > 8 lines; any
|
| 244 |
+
`break` followed by a compound condition (`&&`/`||` on the same line); a
|
| 245 |
+
`while i <`-style loop whose body never reassigns the cursor variable.
|
| 246 |
+
|
| 247 |
+
---
|
| 248 |
+
|
| 249 |
+
## Rule CF-3. Guards are the bouncer — they stand at the door
|
| 250 |
+
|
| 251 |
+
**(a) Why the syntax fights the rule.** An early `return` is invisible in
|
| 252 |
+
prose: a non-technical reader scanning top-to-bottom doesn't naturally know
|
| 253 |
+
that `return nil unless key` means *everything below assumes a key exists*.
|
| 254 |
+
Guards scattered mid-method are worse — the story keeps getting interrupted
|
| 255 |
+
by exits the reader has to fold into their mental state.
|
| 256 |
+
|
| 257 |
+
**(b) Proposed rule — "Guards first, story second."** Guard clauses (already
|
| 258 |
+
the house majority style — 120 guard returns across both repos, and existing
|
| 259 |
+
Rule 3 prefers them) get an *ordering and shape* contract:
|
| 260 |
+
|
| 261 |
+
- All precondition guards sit in a **contiguous block at the top** of the
|
| 262 |
+
method, before the first line of the happy path. A reader — technical or
|
| 263 |
+
not — reads them as a doorman's checklist: *"no ticket, no entry; wrong
|
| 264 |
+
tag, no entry."* Everything after the blank line is the story with all
|
| 265 |
+
assumptions established.
|
| 266 |
+
- One guard per line, one idea per guard. A guard's condition is a plain
|
| 267 |
+
comparison, a named predicate, or a single nil-check — never a compound
|
| 268 |
+
needing parentheses (extract to a `?` method, see CF-8).
|
| 269 |
+
- A `return` *after* the story has started is allowed only when it is the
|
| 270 |
+
method's **answer** (the natural end of a branch), not a late-discovered
|
| 271 |
+
precondition. If you discover a precondition mid-story, either hoist it or
|
| 272 |
+
extract the remainder into a method with its own door.
|
| 273 |
+
- Guards that reject for a *reason worth documenting* say why on the line
|
| 274 |
+
above (`# CSRF: state must match what we issued`), per existing Rule 5.
|
| 275 |
+
|
| 276 |
+
`src/wire/cose.cr` is the exemplar: five `return nil unless …` guards in a
|
| 277 |
+
row, then the single decrypt statement — the shape *is* the security
|
| 278 |
+
argument.
|
| 279 |
+
|
| 280 |
+
**(c) Before/after.**
|
| 281 |
+
|
| 282 |
+
```crystal
|
| 283 |
+
# ✅ AED — the bouncer's checklist, then the story
|
| 284 |
+
def verify_password(password : String) : self?
|
| 285 |
+
return nil if password_digest.empty?
|
| 286 |
+
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 287 |
+
|
| 288 |
+
self
|
| 289 |
+
end
|
| 290 |
+
|
| 291 |
+
# 🚫 nested ifs — the reader carries open questions to the last line
|
| 292 |
+
def verify_password(password : String) : self?
|
| 293 |
+
unless password_digest.empty?
|
| 294 |
+
if Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 295 |
+
self
|
| 296 |
+
end
|
| 297 |
+
end
|
| 298 |
+
end
|
| 299 |
+
|
| 300 |
+
# 🚫 a precondition ambushing the reader mid-story
|
| 301 |
+
def publish(article)
|
| 302 |
+
html = render(article)
|
| 303 |
+
return if article.draft? # ← this belonged at the door
|
| 304 |
+
upload(html)
|
| 305 |
+
end
|
| 306 |
+
```
|
| 307 |
+
|
| 308 |
+
**(d) Cost.** Hoisting sometimes evaluates a guard slightly earlier than
|
| 309 |
+
strictly needed (rarely matters; note it when it does). Multiple exit points
|
| 310 |
+
still bother single-exit purists — AED sides with the checklist reader.
|
| 311 |
+
|
| 312 |
+
**(e) Mechanical check.** Flag: a `return … if/unless` guard appearing after
|
| 313 |
+
the first non-guard, non-comment statement of a method (heuristic: guard
|
| 314 |
+
lines must be a prefix of the method body); any guard condition containing
|
| 315 |
+
`&&`/`||` (send to CF-8); nesting depth > 2 inside a method that has no
|
| 316 |
+
guards (suggests inversion is available).
|
| 317 |
+
|
| 318 |
+
---
|
| 319 |
+
|
| 320 |
+
## Rule CF-4. `unless` carries one positive idea
|
| 321 |
+
|
| 322 |
+
**(a) Why the syntax fights the rule.** `unless` reads beautifully as an
|
| 323 |
+
English exception — *"return nil unless the state matches"* — right up until
|
| 324 |
+
the condition contains logic. `unless a && b` requires De Morgan in the
|
| 325 |
+
reader's head ("so it runs when… a is false, OR b is false…"). The census
|
| 326 |
+
shows 175 total `unless` uses; most are clean guards, but sites like
|
| 327 |
+
`unless key.algorithm == ES256 && key.curve == P256` (`webauthn/verifier.cr`)
|
| 328 |
+
cross the line.
|
| 329 |
+
|
| 330 |
+
**(b) Proposed rule — "`unless` takes one idea."**
|
| 331 |
+
`unless` (postfix or block) may wrap **one positive condition**: a single
|
| 332 |
+
predicate call, a single comparison, or a single presence check. Never
|
| 333 |
+
`unless` with `&&`, `||`, or `!`; never `unless … else` (Crystal allows it;
|
| 334 |
+
AED bans it outright — an inverted two-branch is an `if` written backwards).
|
| 335 |
+
Compound conditions get a named `?` predicate first, then `unless` may carry
|
| 336 |
+
the name. `until` is covered (banned) by CF-2 — same negation tax.
|
| 337 |
+
|
| 338 |
+
**(c) Before/after.**
|
| 339 |
+
|
| 340 |
+
```crystal
|
| 341 |
+
# ✅ AED — name the compound, then the exception reads like English
|
| 342 |
+
def es256_key?(key) : Bool
|
| 343 |
+
key.algorithm == COSE::Algorithm::ES256 && key.curve == COSE::EC2Curve::P256
|
| 344 |
+
end
|
| 345 |
+
raise Error.new("expected an ES256 key") unless es256_key?(key)
|
| 346 |
+
|
| 347 |
+
# 🚫 the reader must run De Morgan to know when this fires
|
| 348 |
+
unless key.algorithm == COSE::Algorithm::ES256 && key.curve == COSE::EC2Curve::P256
|
| 349 |
+
raise Error.new("expected an ES256 key")
|
| 350 |
+
end
|
| 351 |
+
|
| 352 |
+
# 🚫 unless/else — an if, written in a mirror
|
| 353 |
+
unless info.email_verified
|
| 354 |
+
reject_signup
|
| 355 |
+
else
|
| 356 |
+
create_account
|
| 357 |
+
end
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
**(d) Cost.** One extra tiny method per compound; occasionally a predicate
|
| 361 |
+
used exactly once. Accepted: the predicate name doubles as documentation and
|
| 362 |
+
as a doc heading (see §Docs).
|
| 363 |
+
|
| 364 |
+
**(e) Mechanical check.** Flag: `unless` on a line containing `&&`, `||`, or
|
| 365 |
+
` !`; any `unless … else`; any `until`. All three are plain greps — ideal
|
| 366 |
+
hook material.
|
| 367 |
+
|
| 368 |
+
---
|
| 369 |
+
|
| 370 |
+
## Rule CF-5. Ternary picks between two spellings of one value
|
| 371 |
+
|
| 372 |
+
**(a) Why the syntax fights the rule.** A ternary compresses a branch into a
|
| 373 |
+
breath. That's fine when both arms are *values of the same idea*
|
| 374 |
+
(`success ? "info" : "warning"`), because the reader parses it as one noun
|
| 375 |
+
with two spellings. It fights the rule the moment an arm contains a call
|
| 376 |
+
with effects, another `?`, or the arms are different *actions* — then the
|
| 377 |
+
reader is executing code inside a noun slot.
|
| 378 |
+
|
| 379 |
+
**(b) Proposed rule — "Ternary is a value with two spellings, and it gets a
|
| 380 |
+
name."** A ternary is allowed only when **all** hold: both arms are simple
|
| 381 |
+
values (literal, variable, or a single pure call); no nesting; no side
|
| 382 |
+
effects; and the result is immediately **named** — assigned to a variable or
|
| 383 |
+
passed as a named/keyword argument whose name states what it is. Choosing
|
| 384 |
+
between two *actions* is always an `if/else`. Existing Rule 3's ban on
|
| 385 |
+
nested ternaries is subsumed here.
|
| 386 |
+
|
| 387 |
+
**(c) Before/after.**
|
| 388 |
+
|
| 389 |
+
```crystal
|
| 390 |
+
# ✅ AED — one noun, two spellings, and the noun is named at the call site
|
| 391 |
+
severity: success ? "info" : "warning",
|
| 392 |
+
|
| 393 |
+
# ✅ AED — named result
|
| 394 |
+
byte_length = curve == OKPCurve::Ed25519 ? 32 : 57
|
| 395 |
+
|
| 396 |
+
# 🚫 two different actions crammed into a noun slot
|
| 397 |
+
logged_in? ? render_dashboard : redirect_to_login
|
| 398 |
+
|
| 399 |
+
# 🚫 arms with their own lookups and fallbacks (real shape from icon_component.cr)
|
| 400 |
+
path = name ? (ICONS[name]? || "") : (@attributes["path"]? || "")
|
| 401 |
+
# ✅ instead: the branch is a decision — write it as one
|
| 402 |
+
if name
|
| 403 |
+
path = ICONS[name]? || ""
|
| 404 |
+
else
|
| 405 |
+
path = @attributes["path"]? || ""
|
| 406 |
+
end
|
| 407 |
+
```
|
| 408 |
+
|
| 409 |
+
**(d) Cost.** Some three-line `if`s where a one-liner "worked". Accepted:
|
| 410 |
+
the one-liner worked for the author; the `if` works for the reader.
|
| 411 |
+
|
| 412 |
+
**(e) Mechanical check.** Flag: a line matching the ternary shape that also
|
| 413 |
+
contains a second `?`-operator (nesting), a `!`-suffixed call, `<<`, `=`
|
| 414 |
+
inside an arm, or arms containing `(…)` with further calls; ternaries whose
|
| 415 |
+
result is not assigned or passed as an argument.
|
| 416 |
+
|
| 417 |
+
---
|
| 418 |
+
|
| 419 |
+
## Rule CF-6. Chains read like a sentence or get named waypoints
|
| 420 |
+
|
| 421 |
+
**(a) Why the syntax fights the rule.** `users.select(&.active?).map(&.email)`
|
| 422 |
+
*is* a sentence — "take the active users' emails." The syntax stops
|
| 423 |
+
cooperating when a link needs a multi-line block, when a `.try` hides a nil
|
| 424 |
+
branch mid-chain, or when link three depends on remembering what link one
|
| 425 |
+
produced. At that point the chain is a pipeline the reader must trace, not a
|
| 426 |
+
sentence they can hear. The census makes `.try` the sharpest instance: 98
|
| 427 |
+
uses in the template, many nested (`data["mail"]?.try(&.as_s) || …`), versus
|
| 428 |
+
only ~50 collection-chain links total.
|
| 429 |
+
|
| 430 |
+
**(b) Proposed rule — "Two links spoken, three links named."**
|
| 431 |
+
|
| 432 |
+
- A chain may have up to **two transformation links**, each in `&.method`
|
| 433 |
+
shorthand, when it reads aloud as one sentence.
|
| 434 |
+
- Three or more links, or **any** multi-line `do … end` block mid-chain, or
|
| 435 |
+
any link whose output type isn't obvious from its name → break the chain
|
| 436 |
+
with **named waypoints**: intermediate variables named for *what the data
|
| 437 |
+
is at that point* (`active_users`, `member_emails`), not for the operation
|
| 438 |
+
(`filtered`, `mapped`, `result2`).
|
| 439 |
+
- `.each` (side effects) never follows transformation links in the same
|
| 440 |
+
chain — name the collection first, then iterate it. A reader distinguishes
|
| 441 |
+
"computing" from "doing" by the line break.
|
| 442 |
+
- `.try` chains: **one `.try` maximum per expression**, and only the
|
| 443 |
+
`&.method` shorthand form. Two `.try`s, a `.try` with a block containing
|
| 444 |
+
logic, or `.try` feeding `||` feeding `.try` → rewrite as an explicit
|
| 445 |
+
nil-check guard or an `if value = expr` assignment-condition. (This
|
| 446 |
+
restates existing Rule 2 with a hard threshold.)
|
| 447 |
+
|
| 448 |
+
**(c) Before/after.**
|
| 449 |
+
|
| 450 |
+
```crystal
|
| 451 |
+
# ✅ AED — two links, one sentence
|
| 452 |
+
member_emails = users.select(&.active?).map(&.email)
|
| 453 |
+
|
| 454 |
+
# ✅ AED — waypoints named for what the data IS
|
| 455 |
+
oauth_accounts = accounts.select(&.oauth?)
|
| 456 |
+
verified_emails = oauth_accounts.map(&.email).select(&.verified?)
|
| 457 |
+
verified_emails.each { |email| enqueue_welcome(email) }
|
| 458 |
+
|
| 459 |
+
# 🚫 the reader holds three intermediate shapes in their head, then side-effects
|
| 460 |
+
accounts.select(&.oauth?).map(&.email).select(&.verified?).each { |e| enqueue_welcome(e) }
|
| 461 |
+
|
| 462 |
+
# 🚫 nested try-fallback — three nil-branches hidden in one line (real shape, microsoft.cr)
|
| 463 |
+
email = data["mail"]?.try(&.as_s) || data["userPrincipalName"]?.try(&.as_s) || ""
|
| 464 |
+
# ✅ instead: each source named, the preference order visible as lines
|
| 465 |
+
primary_email = data["mail"]?.try(&.as_s)
|
| 466 |
+
fallback_email = data["userPrincipalName"]?.try(&.as_s)
|
| 467 |
+
email = primary_email || fallback_email || ""
|
| 468 |
+
```
|
| 469 |
+
|
| 470 |
+
**(d) Cost.** More lines and more locals; hot paths allocate an intermediate
|
| 471 |
+
array per waypoint (if profiling ever shows it matters, note the exception
|
| 472 |
+
with a *why* comment per existing Rule 5). Accepted: this codebase reads far
|
| 473 |
+
more than it iterates.
|
| 474 |
+
|
| 475 |
+
**(e) Mechanical check.** Flag: ≥3 `.method(` / `&.` links on one expression;
|
| 476 |
+
`.each` preceded by `.map`/`.select`/`.reject` in the same statement; ≥2
|
| 477 |
+
`.try` in one expression; `.try do` block form; waypoint variables named
|
| 478 |
+
`result`, `tmp`, `filtered`, `x2` (existing Rule 4's list, extended).
|
| 479 |
+
|
| 480 |
+
---
|
| 481 |
+
|
| 482 |
+
## Rule CF-7. Errors are vocabulary; rescues say what they forgive
|
| 483 |
+
|
| 484 |
+
**(a) Why the syntax fights the rule.** `begin/rescue` reads like nothing at
|
| 485 |
+
all: a bare `rescue` is the statement *"if anything whatsoever goes wrong,
|
| 486 |
+
do this"* — which is almost never what the author meant and never what the
|
| 487 |
+
reader can verify. Exception flow is invisible control flow: the jump happens
|
| 488 |
+
on a line the reader can't see. The only way it reads like a statement is if
|
| 489 |
+
the **error type carries the sentence**. The census shows the raising side
|
| 490 |
+
already speaks: 138 typed raises vs 14 string raises, and a real error
|
| 491 |
+
vocabulary exists (`WebAuthn::Registration::UnsupportedAttestation`,
|
| 492 |
+
`Storage::FileNotFoundError`, `Authorization::…`). The rescuing side lags:
|
| 493 |
+
a large share of the 65 rescues are bare.
|
| 494 |
+
|
| 495 |
+
**(b) Proposed rule — "Raise nouns, rescue by name."**
|
| 496 |
+
|
| 497 |
+
- **Raising**: always a typed error from the domain vocabulary; new failure
|
| 498 |
+
modes mint a new subclass under the module's base `Error` (the house
|
| 499 |
+
pattern: `class Error < Exception` per module, specific subclasses under
|
| 500 |
+
it). A bare `raise "string"` is allowed only for
|
| 501 |
+
configuration-impossible states at boot (`"ANTHROPIC_API_KEY required"`).
|
| 502 |
+
- **Rescuing**: `rescue ex : SpecificError` naming the narrowest type that
|
| 503 |
+
states what you forgive. A broad `rescue ex` is permitted only at
|
| 504 |
+
**boundaries** — the outermost edge of a request, a fiber, a mailer
|
| 505 |
+
delivery, a worker — and must (i) bind `ex`, (ii) log or report it, and
|
| 506 |
+
(iii) carry a *why* comment stating the boundary ("mailer must never take
|
| 507 |
+
the request down with it"). A bare `rescue` with no binding and no comment
|
| 508 |
+
is banned.
|
| 509 |
+
- **Postfix `rescue nil`** only around a *single parse/convert expression*
|
| 510 |
+
where nil is the honest answer (`Time.parse_rfc2822(date) rescue nil` —
|
| 511 |
+
the two existing uses both qualify). Never around a call with side effects.
|
| 512 |
+
- **`ensure`** is for cleanup only (close, unlink, reset) — never business
|
| 513 |
+
logic; if an `ensure` grows past ~3 lines, extract it to a named cleanup
|
| 514 |
+
method (`ensure … close_worker_pipes`).
|
| 515 |
+
- **`retry`** (census: zero) is banned in its raw form; retrying is a policy,
|
| 516 |
+
so it must live in a method named for it (`with_retries(attempts: 3) do`)
|
| 517 |
+
that owns the counter and backoff — a raw `retry` is an unbounded loop
|
| 518 |
+
wearing an exception costume.
|
| 519 |
+
|
| 520 |
+
**(c) Before/after.**
|
| 521 |
+
|
| 522 |
+
```crystal
|
| 523 |
+
# ✅ AED — the rescue states exactly what it forgives, and why
|
| 524 |
+
def find_verified(token : String) : Users::Regular?
|
| 525 |
+
payload = decode_session_token(token)
|
| 526 |
+
Users::Regular.find(payload.user_id)
|
| 527 |
+
rescue JWT::ExpiredSignatureError
|
| 528 |
+
# Expired session is a normal event, not an error: the caller re-authenticates.
|
| 529 |
+
nil
|
| 530 |
+
end
|
| 531 |
+
|
| 532 |
+
# 🚫 forgives everything — a typo in decode_session_token now returns nil forever
|
| 533 |
+
def find_verified(token : String) : Users::Regular?
|
| 534 |
+
Users::Regular.find(decode_session_token(token).user_id)
|
| 535 |
+
rescue
|
| 536 |
+
nil
|
| 537 |
+
end
|
| 538 |
+
|
| 539 |
+
# ✅ AED — broad rescue earns its breadth at a boundary, with the why on record
|
| 540 |
+
spawn do
|
| 541 |
+
run_heartbeat_loop(response)
|
| 542 |
+
rescue ex
|
| 543 |
+
# Boundary: a dead client must never crash the server fiber pool.
|
| 544 |
+
Log.warn(exception: ex) { "SSE heartbeat fiber exited" }
|
| 545 |
+
end
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
**(d) Cost.** Naming narrow error types takes real thought (what *can* this
|
| 549 |
+
raise?), and Crystal won't tell you — there are no checked exceptions.
|
| 550 |
+
Sometimes you'll name two types where a bare rescue was one word. Accepted:
|
| 551 |
+
that thought is precisely the documentation the next agent needs; a bare
|
| 552 |
+
rescue is a claim of omniscience.
|
| 553 |
+
|
| 554 |
+
**(e) Mechanical check.** Flag: `rescue` at end-of-line or `rescue$` with no
|
| 555 |
+
type and no `ex` binding; `rescue ex` (untyped) with no comment within 2
|
| 556 |
+
lines; `raise "` outside `config/`/boot files; any `retry` keyword; `ensure`
|
| 557 |
+
blocks > 3 lines; postfix `rescue nil` on a line containing `save`/`create`/
|
| 558 |
+
`delete`/`<<`/`=` (side-effect heuristic).
|
| 559 |
+
|
| 560 |
+
---
|
| 561 |
+
|
| 562 |
+
## Rule CF-8. Three ands make a question method
|
| 563 |
+
|
| 564 |
+
**(a) Why the syntax fights the rule.** Boolean operators are the one place
|
| 565 |
+
where "statement-like" degrades *gradually*: `a && b` still reads, `a && b || c && !d`
|
| 566 |
+
is a logic puzzle. The reader shouldn't need parentheses skills to know when
|
| 567 |
+
a branch fires. The template's 195 `?` methods prove the extraction habit
|
| 568 |
+
exists — this rule just fixes the threshold.
|
| 569 |
+
|
| 570 |
+
**(b) Proposed rule — "Two operators is a sentence; three is a method."**
|
| 571 |
+
A condition (in `if`, `unless`, `while`, a guard, or a ternary) may contain
|
| 572 |
+
at most **two** boolean operators, and never a *mix* of `&&` and `||`
|
| 573 |
+
without extraction — a mix means precedence, and precedence means the
|
| 574 |
+
reader is parsing, not reading. Beyond that, extract either a **`?` question
|
| 575 |
+
method** (when the concept recurs or belongs to the object:
|
| 576 |
+
`team_lead?`, `es256_key?`) or a **named `Bool` local** (when it's one-off
|
| 577 |
+
and built from locals: `state_matches = …`). The name must be the *positive*
|
| 578 |
+
form of the question — no `not_invalid?`.
|
| 579 |
+
|
| 580 |
+
**(c) Before/after.**
|
| 581 |
+
|
| 582 |
+
```crystal
|
| 583 |
+
# ✅ AED — the condition IS the sentence
|
| 584 |
+
if oauth_callback_valid?(provider, expected_state, state, code)
|
| 585 |
+
...
|
| 586 |
+
|
| 587 |
+
private def oauth_callback_valid?(provider, expected_state, state, code) : Bool
|
| 588 |
+
return false unless provider && expected_state && state && code
|
| 589 |
+
constant_time_equal?(expected_state, state)
|
| 590 |
+
end
|
| 591 |
+
|
| 592 |
+
# 🚫 four conditions and a continuation line — a parser test, not a sentence
|
| 593 |
+
unless provider && expected_state && state && code &&
|
| 594 |
+
constant_time_equal?(expected_state, state)
|
| 595 |
+
...
|
| 596 |
+
|
| 597 |
+
# ✅ AED — mixed operators earn a named local even at only three terms
|
| 598 |
+
signature_acceptable = algorithm.rs? || algorithm.ps?
|
| 599 |
+
return unless signature_acceptable && key_present?
|
| 600 |
+
```
|
| 601 |
+
|
| 602 |
+
**(d) Cost.** Method count grows; a hostile reviewer can call `?` methods
|
| 603 |
+
"indirection". Accepted — with one honest caveat: the extracted name must
|
| 604 |
+
truly summarize, or you've hidden the puzzle behind a label. Bad name = worse
|
| 605 |
+
than inline. Naming quality falls to existing Rule 4.
|
| 606 |
+
|
| 607 |
+
**(e) Mechanical check.** Flag: any condition line with ≥3 of (`&&`, `||`);
|
| 608 |
+
any condition mixing `&&` and `||`; any `if`/`unless`/`while` condition
|
| 609 |
+
spilling to a continuation line; predicate names starting `not_`/`no_`.
|
| 610 |
+
|
| 611 |
+
---
|
| 612 |
+
|
| 613 |
+
## Rule CF-9. Every fiber gets a job title
|
| 614 |
+
|
| 615 |
+
**(a) Why the syntax fights the rule.** Concurrency breaks the deepest
|
| 616 |
+
assumption of statement-reading: that the next line happens next. `spawn do`
|
| 617 |
+
means "meanwhile, elsewhere" — and an anonymous block gives the reader no
|
| 618 |
+
noun to hold on to while the main story continues. Channels are worse:
|
| 619 |
+
`ch.receive` is a sentence missing its subject (*receive what, from whom?*).
|
| 620 |
+
The census says our exposure is small (4 spawns, 1 channel, 0 `select`) but
|
| 621 |
+
the two real sites (`isolated_worker.cr`, `mcp_sse_controller.cr`) are
|
| 622 |
+
exactly the hardest code in the template — small count, maximal reader risk.
|
| 623 |
+
|
| 624 |
+
**(b) Proposed rule — "Meanwhile, the *named* worker does its *named* job."**
|
| 625 |
+
|
| 626 |
+
- Every `spawn` body is a **single call to a named method** whose name is
|
| 627 |
+
the fiber's job (`spawn { pump_input_to_child(in_writer, input, writer_done) }`,
|
| 628 |
+
`spawn { run_heartbeat_loop(response) }`). Never an inline multi-line
|
| 629 |
+
block: the reader should meet a fiber the way they meet an employee — by
|
| 630 |
+
title — and only read the job description if they choose to. Crystal's
|
| 631 |
+
`spawn(name: "heartbeat")` is encouraged in addition (it labels runtime
|
| 632 |
+
diagnostics) but the method name is the load-bearing part.
|
| 633 |
+
- Every `Channel` variable is named for its **cargo and direction**
|
| 634 |
+
(`writer_done`, `parsed_events`, `shutdown_requested`) — the existing
|
| 635 |
+
`writer_done = Channel(Exception?).new(1)` is the exemplar. Bare `ch`
|
| 636 |
+
banned.
|
| 637 |
+
- A `.receive` reads as *"wait for the writer to be done"* only if the line
|
| 638 |
+
says so: `writer_error = writer_done.receive`.
|
| 639 |
+
- Concurrency `select` (census: zero): when it arrives, each branch must be
|
| 640 |
+
a one-line guard-style clause calling a named method — same menu
|
| 641 |
+
discipline as CF-1.
|
| 642 |
+
- Every fiber body's outermost layer is a boundary rescue per CF-7 — a fiber
|
| 643 |
+
that dies silently is control flow the reader can never follow.
|
| 644 |
+
|
| 645 |
+
*How a statement-reader follows concurrent flow under this rule:* the main
|
| 646 |
+
story reads linearly and each `spawn` line reads as a one-sentence aside —
|
| 647 |
+
"meanwhile, pump input to the child" — and each `receive` reads as
|
| 648 |
+
"wait here for X." The reader never has to interleave two instruction
|
| 649 |
+
streams; they follow one story with named waypoints where the streams touch.
|
| 650 |
+
|
| 651 |
+
**(c) Before/after.**
|
| 652 |
+
|
| 653 |
+
```crystal
|
| 654 |
+
# ✅ AED — the aside has a title; the join point says what it waits for
|
| 655 |
+
writer_done = Channel(Exception?).new(1)
|
| 656 |
+
spawn { pump_input_to_child(in_writer, input, writer_done) }
|
| 657 |
+
output = drain_child_output(out_reader)
|
| 658 |
+
writer_error = writer_done.receive
|
| 659 |
+
|
| 660 |
+
# 🚫 an anonymous ten-line meanwhile — the reader must simulate two timelines at once
|
| 661 |
+
writer_done = Channel(Exception?).new(1)
|
| 662 |
+
spawn do
|
| 663 |
+
begin
|
| 664 |
+
in_writer.write(input) unless input.empty?
|
| 665 |
+
err = nil
|
| 666 |
+
rescue ex
|
| 667 |
+
err = ex
|
| 668 |
+
ensure
|
| 669 |
+
in_writer.close
|
| 670 |
+
writer_done.send(err)
|
| 671 |
+
end
|
| 672 |
+
end
|
| 673 |
+
```
|
| 674 |
+
|
| 675 |
+
**(d) Cost.** Method extraction can force explicit parameter passing where a
|
| 676 |
+
closure captured silently — that's several extra tokens per fiber, and
|
| 677 |
+
occasionally a small struct to carry them. Accepted eagerly: silent capture
|
| 678 |
+
is precisely what makes concurrent code unreadable (and, per the `gc_arena`
|
| 679 |
+
warnings, unsafe — a named method's parameter list *is* the audit of what
|
| 680 |
+
the fiber touches).
|
| 681 |
+
|
| 682 |
+
**(e) Mechanical check.** Flag: `spawn do`/`spawn {` whose body exceeds 1
|
| 683 |
+
statement; channel locals named `ch`/`chan`/`c`; a `spawn` whose body lacks
|
| 684 |
+
a rescue and whose called method lacks one (approximate: warn on every spawn,
|
| 685 |
+
require the boundary-rescue comment to silence); any `select` branch longer
|
| 686 |
+
than one line.
|
| 687 |
+
|
| 688 |
+
---
|
| 689 |
+
|
| 690 |
+
## Rule CF-10. `?` asks, `!` warns — and the suffix is a promise
|
| 691 |
+
|
| 692 |
+
**(a) Why the syntax fights the rule.** The suffixes are Crystal's built-in
|
| 693 |
+
statement-reading aid — `verified?` reads as a question, `save!` as a
|
| 694 |
+
warning — but only if they're *reliable*. A `?` method returning a `String?`
|
| 695 |
+
"sometimes-value" instead of a `Bool`, or a `!` method that's merely "the
|
| 696 |
+
other version", breaks the reader's trained reflex and silently poisons
|
| 697 |
+
every future read. Census: 195 `?` defs and 10 `!` defs in the template —
|
| 698 |
+
the reflex is trainable; the contract just needs writing down.
|
| 699 |
+
|
| 700 |
+
**(b) Proposed rule — "The suffix is a promise."**
|
| 701 |
+
|
| 702 |
+
- `def foo?` returns `Bool` — full stop — with one blessed exception: the
|
| 703 |
+
Crystal-stdlib **maybe-lookup** convention (`session["oauth_state"]?`,
|
| 704 |
+
`ENV["KEY"]?`, `find_by?`) where `?` means *nil instead of raising*. Both
|
| 705 |
+
are questions ("is it?" / "is it there?"); nothing else earns the mark.
|
| 706 |
+
- `def foo!` means **raises where `foo` returns nil, or mutates the
|
| 707 |
+
receiver** — the two Ruby/Crystal senses — and every `!` method's doc
|
| 708 |
+
comment states *which* danger it warns about, in one line.
|
| 709 |
+
- In conditions, prefer the `?` form over comparison chains
|
| 710 |
+
(`user.verified?` not `user.verified_at != nil`).
|
| 711 |
+
- Chaining: a `!` call never appears mid-chain (`fetch!.parse.render` hides
|
| 712 |
+
the raise in the middle of a sentence — the raise belongs on its own
|
| 713 |
+
line, where a guard or rescue can be seen next to it). A `?` predicate
|
| 714 |
+
never has its result chained onward (`valid?.to_s` is a smell: a question
|
| 715 |
+
answers, it doesn't pipeline).
|
| 716 |
+
|
| 717 |
+
**(c) Before/after.**
|
| 718 |
+
|
| 719 |
+
```crystal
|
| 720 |
+
# ✅ AED — the question mark tells the truth
|
| 721 |
+
def team_member? : Bool
|
| 722 |
+
@context.try(&.team_membership) != nil
|
| 723 |
+
end
|
| 724 |
+
|
| 725 |
+
# 🚫 a "question" that answers with a maybe-string — the reflex is now poisoned
|
| 726 |
+
def admin_role?
|
| 727 |
+
membership.role if membership.admin?
|
| 728 |
+
end
|
| 729 |
+
|
| 730 |
+
# ✅ AED — the raise stands on its own line where the reader can see it
|
| 731 |
+
document = Document.find!(document_id) # raises Grant::Querying::NotFound
|
| 732 |
+
render(document)
|
| 733 |
+
|
| 734 |
+
# 🚫 the raise hides mid-sentence
|
| 735 |
+
render(Document.find!(document_id).with_sections)
|
| 736 |
+
```
|
| 737 |
+
|
| 738 |
+
**(d) Cost.** The maybe-lookup exception means `?` is *two* promises, not
|
| 739 |
+
one — genuinely a wart, but it's stdlib-load-bearing (98 `.try`s and every
|
| 740 |
+
`[]?` depend on it), so we document it rather than fight it. Some `!`
|
| 741 |
+
doc-comment ceremony.
|
| 742 |
+
|
| 743 |
+
**(e) Mechanical check.** Flag: `def …?` with a declared return type other
|
| 744 |
+
than `Bool` outside index/find/lookup names; `def …!` with no doc comment;
|
| 745 |
+
`!`-suffixed call followed by `.` on the same line; `?`-suffixed predicate
|
| 746 |
+
call followed by `.` (excluding `[]?`/`find_by?`-style lookups).
|
| 747 |
+
|
| 748 |
+
---
|
| 749 |
+
|
| 750 |
+
## Rule CF-11. Macros write code; they don't hide flow
|
| 751 |
+
|
| 752 |
+
**(a) Why the syntax fights the rule.** `{% if flag?(:preview_mt) %}` is
|
| 753 |
+
control flow the runtime reader *cannot see executing at all* — the branch
|
| 754 |
+
was taken at compile time, and half the file's text is a ghost. `macro
|
| 755 |
+
included` generates methods that exist nowhere in the source a reader greps.
|
| 756 |
+
Both defeat statement-reading not by being dense but by being **invisible**.
|
| 757 |
+
Census: 3 macro defs, 2 compile-time ifs — rare, so the rule is a fence, not
|
| 758 |
+
a renovation.
|
| 759 |
+
|
| 760 |
+
**(b) Proposed rule — "Compile-time branches speak for both worlds."**
|
| 761 |
+
|
| 762 |
+
- `{% if %}` / `{% else %}` is allowed only for **platform/flag gating**
|
| 763 |
+
(`flag?(:preview_mt)`, `flag?(:gc_agentc)`), placed at the **top level of
|
| 764 |
+
a method or file section** — never interleaved inside a runtime `if`
|
| 765 |
+
ladder. Each branch's first line is a comment stating which world this is
|
| 766 |
+
and what the other world does (`# MT builds: forking is unsupported —
|
| 767 |
+
raise; single-thread builds take the fork path below`). The existing
|
| 768 |
+
`isolated_worker.cr` / `gc_arena.cr` sites already approximate this.
|
| 769 |
+
- `macro` definitions live only in **concerns and infrastructure**
|
| 770 |
+
(`src/models/concerns/`, `src/runtime/`), never in controllers/views/
|
| 771 |
+
business logic. Every `macro included` carries a comment block listing,
|
| 772 |
+
by name, the methods/columns it generates (`soft_deletable.cr`'s
|
| 773 |
+
`column deleted_at` style is halfway there — add the roster comment), so
|
| 774 |
+
grep-for-definition finds a mention even though the def is generated.
|
| 775 |
+
- No macro-generated *runtime branching* whose shape depends on macro logic
|
| 776 |
+
(a macro that emits different `if` ladders per include is a puzzle box).
|
| 777 |
+
Generate declarations and delegations; keep decisions in visible code.
|
| 778 |
+
- `{% for %}` (census: zero) — same fence: declaration generation only.
|
| 779 |
+
|
| 780 |
+
**(c) Before/after.**
|
| 781 |
+
|
| 782 |
+
```crystal
|
| 783 |
+
# ✅ AED — the ghost branch is narrated for the reader of either world
|
| 784 |
+
def self.run(&block : -> Bytes) : Bytes
|
| 785 |
+
{% if flag?(:preview_mt) %}
|
| 786 |
+
# MT builds: fork() after threads exist inherits poisoned locks — refuse loudly.
|
| 787 |
+
raise UnsupportedError.new("IsolatedWorker.run requires the single-threaded runtime")
|
| 788 |
+
{% else %}
|
| 789 |
+
# Single-threaded builds: fork, run the block in the child, reap the bytes.
|
| 790 |
+
run_in_forked_child(block)
|
| 791 |
+
{% end %}
|
| 792 |
+
end
|
| 793 |
+
|
| 794 |
+
# 🚫 compile-time and runtime conditions braided together — nobody can trace this
|
| 795 |
+
{% if flag?(:gc_agentc) %} if ENABLED && {% if flag?(:preview_mt) %} false {% else %} arena_ready? {% end %} ... {% end %}
|
| 796 |
+
```
|
| 797 |
+
|
| 798 |
+
**(d) Cost.** The roster comment can drift from what the macro actually
|
| 799 |
+
generates (comments always can); the "concerns only" fence occasionally
|
| 800 |
+
forces a small concern file where an inline macro felt convenient. Accepted:
|
| 801 |
+
invisible code is the single most expensive thing to hand a coding agent.
|
| 802 |
+
|
| 803 |
+
**(e) Mechanical check.** Flag: `{% if` on a line that also contains runtime
|
| 804 |
+
`if`/`unless`; `macro ` definitions outside `src/models/concerns/` and
|
| 805 |
+
`src/runtime/`; `macro included` without a comment containing `generates`
|
| 806 |
+
within 3 lines; nested `{%` inside a method body deeper than one level.
|
| 807 |
+
|
| 808 |
+
---
|
| 809 |
+
|
| 810 |
+
## How these rules feed documentation generation
|
| 811 |
+
|
| 812 |
+
AED's premise for docs: **the names are the source of headings.** Prose docs
|
| 813 |
+
rot; names are re-verified by every compile and every review. Control flow is
|
| 814 |
+
where this pays off most, because control flow *is* the behavior readers ask
|
| 815 |
+
about ("when does it refuse?", "what can go wrong?", "what runs in the
|
| 816 |
+
background?"). Each rule above was written so its mandatory names map onto a
|
| 817 |
+
doc section mechanically:
|
| 818 |
+
|
| 819 |
+
| Rule | Named artifact | Doc surface it generates |
|
| 820 |
+
|---|---|---|
|
| 821 |
+
| CF-3 Guards first | The guard block of each public method | **"Refuses when…"** bullet list per operation — each guard line becomes one bullet, its *why*-comment becomes the bullet's explanation. The wire/cose.cr guard stack *is* its security doc. |
|
| 822 |
+
| CF-8 Question methods | `?` predicates referenced by guards & branches | **Glossary of business rules** — `team_lead?`, `oauth_callback_valid?` become glossary entries; the predicate body is the definition. Policy classes' `can?` menus render directly as **permission tables** (action × predicate). |
|
| 823 |
+
| CF-1 Case menus | `case` subject + `when` labels + extracted branch methods | **Decision tables** — "depending on `default_provider`: …" — subject is the table title, when-labels are rows, extracted method names are the outcome column. The mandatory `else` becomes the documented fallback row. |
|
| 824 |
+
| CF-2 Loop finish lines | Loop-extracted body methods, `loop`-named methods | **"Process steps"** — `consume_blockquote`, `emit_table_row` list as the pipeline's stages; `run_heartbeat_loop` names itself in ops docs. |
|
| 825 |
+
| CF-7 Error vocabulary | Typed error classes; typed rescues | **"What can go wrong"** section per module — the error subclass tree renders as the failure catalogue; each typed `rescue` site documents which layer absorbs which failure. This is also compliance evidence (SOC2 loves an error taxonomy). |
|
| 826 |
+
| CF-9 Fiber job titles | Spawn-target method names; channel names | **"Background work"** section — every `spawn`-called method is a row: job title, what it waits on (channel names), its boundary rescue. Ops runbooks can be generated from exactly this. |
|
| 827 |
+
| CF-11 Macro rosters | The `generates:` comment roster | **"Generated API"** appendix per concern — the roster is the contract; docs list it verbatim so generated methods are findable. |
|
| 828 |
+
| CF-10 Suffix promises | `!` doc comments | **Danger callouts** — every `!` method's one-line warning surfaces as a ⚠️ note wherever the method is documented. |
|
| 829 |
+
|
| 830 |
+
**What does *not* surface:** ternary values, waypoint locals (CF-6), named
|
| 831 |
+
`Bool` locals (CF-8's one-off form), and cursor predicates — these are
|
| 832 |
+
paragraph-level names for the human reading the file, below the doc
|
| 833 |
+
altitude. The doc generator's selection rule is mechanical: **a control-flow
|
| 834 |
+
name surfaces to docs iff it is a method name** (predicates, branch
|
| 835 |
+
extractions, loop bodies, fiber jobs, error classes). Locals stay local.
|
| 836 |
+
|
| 837 |
+
A future `docs/` generator (or a doc-writing agent) therefore needs only:
|
| 838 |
+
method names + `?`/`!` suffixes + guard blocks + case labels + error class
|
| 839 |
+
tree + spawn targets — all extractable with the same grep-grade tooling as
|
| 840 |
+
the mechanical checks in (e). That symmetry is deliberate: **the linter's
|
| 841 |
+
tokens and the doc generator's tokens are the same tokens.**
|
| 842 |
+
|
| 843 |
+
---
|
| 844 |
+
|
| 845 |
+
## Implementation sketch (if adopted)
|
| 846 |
+
|
| 847 |
+
1. Add the accepted rules to `.claude/skills/aed-conventions/SKILL.md` as a
|
| 848 |
+
"Control flow" section, keeping the existing 6 rules and voice; extend
|
| 849 |
+
the end-of-edit checklist with one line per rule.
|
| 850 |
+
2. Extend `.claude/hooks/crystal_check.sh` (or a sibling `aed_lint.sh`) with
|
| 851 |
+
the grep-grade checks from each rule's (e) — start **warn-only**, promote
|
| 852 |
+
to blocking per-rule once the existing codebase is swept. Candidates for
|
| 853 |
+
custom Ameba rules later; greps first (same engine, zero deps).
|
| 854 |
+
3. Sweep order by census-weighted payoff: (1) bare rescues → typed/commented
|
| 855 |
+
(~40 sites), (2) nested `.try` fallbacks (~a dozen sites), (3) compound
|
| 856 |
+
`unless` (+ the two `spawn do` bodies), (4) case menus without `else`.
|
| 857 |
+
The website's markdown parser needs no changes — it already conforms to
|
| 858 |
+
CF-2's cursor-loop shape.
|
| 859 |
+
|
| 860 |
+
---
|
| 861 |
+
|
| 862 |
+
## Open questions before v1.1.0 final
|
| 863 |
+
|
| 864 |
+
These are the thresholds still under review. Each rule above is usable today;
|
| 865 |
+
what is unsettled is exactly where the line falls, not whether the rule holds.
|
| 866 |
+
Opinions are welcome in
|
| 867 |
+
[Discussions](https://github.com/AgentC-Consulting/aed-conventions/discussions).
|
| 868 |
+
|
| 869 |
+
|
| 870 |
+
1. **Case threshold (CF-1):** Adopt "3+ branches or use if/else", every
|
| 871 |
+
`when` body ≤ 3 lines, mandatory `else`? Or allow 2-branch `case` when
|
| 872 |
+
the subject name carries weight?
|
| 873 |
+
2. **Ban `until` outright (CF-2/CF-4)?** Census shows zero uses, so it's
|
| 874 |
+
free today — but it's idiomatic Crystal and some readers find
|
| 875 |
+
`until done?` natural. Ban, or allow with single-predicate conditions?
|
| 876 |
+
3. **Guard contiguity (CF-3):** Enforce "all guards before the first story
|
| 877 |
+
statement" as a hard rule, or as a default with a *why*-comment escape
|
| 878 |
+
hatch for genuinely late preconditions?
|
| 879 |
+
4. **Bare `rescue ex` at boundaries (CF-7):** Is comment-plus-log sufficient
|
| 880 |
+
license, or do you want a named helper (`swallowing_errors(context) do`)
|
| 881 |
+
so boundaries are greppable as one idiom?
|
| 882 |
+
5. **`.try` hard cap (CF-6):** One `.try` per expression is aggressive given
|
| 883 |
+
98 existing uses — adopt as blocking for new code and sweep old, or
|
| 884 |
+
warn-only permanently?
|
| 885 |
+
6. **Spawn body = single named call (CF-9):** Apply retroactively to the two
|
| 886 |
+
existing spawn sites (`isolated_worker.cr`, `mcp_sse_controller.cr`) in
|
| 887 |
+
the sweep, or grandfather them with comments?
|
| 888 |
+
7. **Enforcement vehicle:** extend `crystal_check.sh` with warn-only greps,
|
| 889 |
+
write custom Ameba rules, or both (greps now, Ameba when stable)?
|
| 890 |
+
8. **Docs pipeline:** is the "method names surface, locals don't" selection
|
| 891 |
+
rule right for the doc generator, and which doc surface should be built
|
| 892 |
+
first — permission tables from policies (cheapest, highest compliance
|
| 893 |
+
value) or "What can go wrong" from the error tree?
|
| 894 |
+
9. **Ternary strictness (CF-5):** the `success ? "info" : "warning"`
|
| 895 |
+
argument-position form is blessed; do you also want to allow simple
|
| 896 |
+
ternaries inside string interpolation (common in view components), or
|
| 897 |
+
force extraction there too?
|
| 898 |
+
10. **Where does this land?** Fold into the existing SKILL.md as one
|
| 899 |
+
"Control flow" section (one skill, longer), or a sibling
|
| 900 |
+
`aed-control-flow` skill file referenced from the main one (two hops,
|
| 901 |
+
shorter files)?
|
| 902 |
+
|
| 903 |
+
---
|
| 904 |
+
|
| 905 |
+
*Chapter 06 of the AED canon · the census and code shapes above are drawn from
|
| 906 |
+
AgentC Consulting's own production Crystal, so the rules target real frequency
|
| 907 |
+
rather than theory · back to the [reading order](README.md#reading-order)*
|
07_how_the_workflow_runs.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# How Agent Enhanced Development Work Flows - Local Models
|
| 2 |
+
|
| 3 |
+
Typical development processes are that you focus on small steps at a time to scaffold out an idea and then focus on the logic flow. This usually means a lot of saving and rapid iteration. This is actually the least productive way to work with an agent enhanced development process.
|
| 4 |
+
|
| 5 |
+
When you are first starting out using an AI agent to assist with developing your app, the temptation is to continue using it for the quick iterative feedback like we currently get from a “write, save, retry” development process. However, with an AI agent enhancing our development process, we are rewarded for planning in detail, and using our natural language. By that I mean, writing and building feature requests in large batches and letting the AI run over many features.
|
| 6 |
+
|
| 7 |
+
The agent should be driving the majority of the development, and you should be able to walk away and do something else. It’s a great way to end a day of planning, and then let your laptop sit for a time while the agent runs. It’ll spend the time it needs until it succeeds at building a thorough feature, including your tests.
|
| 8 |
+
|
| 9 |
+
This means you can plan your time so that your agent is building your app while you’re typically away from your computer, this way you’re maximizing your local hardware availability while getting the benefits.
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
*Chapter 07 of the AED canon · published **verbatim** from the author's original · back to the [reading order](README.md#reading-order)*
|
ADOPTION.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adoption log — the dated record of intents
|
| 2 |
+
|
| 3 |
+
Every rule change, publication, and license event gets a dated entry here at
|
| 4 |
+
the time it happens, and every published version is a **signed git tag**
|
| 5 |
+
mirrored to independently-operated hosts. Forward from first publication, this
|
| 6 |
+
log plus the tag history is the public, timestamped record of when each idea
|
| 7 |
+
entered the canon.
|
| 8 |
+
|
| 9 |
+
Entries marked *(reconstructed)* describe practice that predates this public
|
| 10 |
+
repository; they are honest reconstructions, not contemporaneous records — the
|
| 11 |
+
contemporaneous private evidence exists and is referenced where it may later be
|
| 12 |
+
published.
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## 2026-07-29 — v1.1.0-rc.1: the original canon published, control flow added
|
| 17 |
+
|
| 18 |
+
**Practiced since 2024; first published here 2026-07-29.**
|
| 19 |
+
|
| 20 |
+
v1.0.0 published six edit-level style rules and nothing else. Readers — and
|
| 21 |
+
the maintainer — noted that the repository did not contain the doctrine AED
|
| 22 |
+
is actually named for: the token-window rationale, the verbose-naming
|
| 23 |
+
conventions, process managers, and feature stories all existed as private
|
| 24 |
+
notes dating to 2024-06-03 and had never been published. `v1.1.0-rc.1`
|
| 25 |
+
publishes them.
|
| 26 |
+
|
| 27 |
+
**Restored, verbatim from the author's originals** (authored 2024-06-03,
|
| 28 |
+
`process_manager_conventions.md` last revised 2025-11-24). These are published
|
| 29 |
+
as written, including the author's own work-in-progress markers and one
|
| 30 |
+
unfinished section marked `TBD`; nothing was rewritten or smoothed:
|
| 31 |
+
|
| 32 |
+
- `01_why_models_need_this.md` — the token-window explanation (excerpt of 02,
|
| 33 |
+
lifted to the front of the reading order)
|
| 34 |
+
- `02_naming_conventions.md` — `list_of_` naming, boolean-as-question naming,
|
| 35 |
+
attributes as short statements, and the compounding argument
|
| 36 |
+
- `03_process_managers.md` — the "when" grammar
|
| 37 |
+
- `04_feature_stories.md` — personas, operations, authorization levels
|
| 38 |
+
- `07_how_the_workflow_runs.md` — the batch-plan-and-walk-away rhythm
|
| 39 |
+
- `quick_reference.md` — the cheat sheet
|
| 40 |
+
|
| 41 |
+
**Added:**
|
| 42 |
+
|
| 43 |
+
- `06_control_flow.md` — CF-1 through CF-11, developed 2026-07-07 against a
|
| 44 |
+
census of two live production codebases. Ships as a **release candidate**:
|
| 45 |
+
the rules hold, the exact thresholds are still open, and the open questions
|
| 46 |
+
are listed at the end of the file.
|
| 47 |
+
- `evidence/` — the small-model comprehension benchmark (AED 60/60 vs
|
| 48 |
+
conventional 54/60, Claude Haiku, blind-answered and blind-graded) and its
|
| 49 |
+
raw per-probe data, with the method's limits stated up front. Run
|
| 50 |
+
2026-07-07.
|
| 51 |
+
|
| 52 |
+
**Kept, repositioned:** the six v1.0.0 rules remain at `CONVENTIONS.md` with
|
| 53 |
+
their `#rule-1` … `#rule-6` anchors untouched, indexed as chapter 05 of the
|
| 54 |
+
canon. The anchors were published in v1.0.0 and are cited externally;
|
| 55 |
+
renumbering them into a new filename would have broken those links to no
|
| 56 |
+
reader's benefit.
|
| 57 |
+
|
| 58 |
+
**Known conflict, tracked not hidden:** `CONVENTIONS.md` rule 4 offers
|
| 59 |
+
`expected_state` as an improved name; by `02_naming_conventions.md` that name
|
| 60 |
+
is still under-specified. Chapter 02 is the authority. Reconciling the
|
| 61 |
+
example is tracked for v1.1.0 final.
|
| 62 |
+
|
| 63 |
+
**Why a release candidate:** the CF thresholds and that naming conflict are
|
| 64 |
+
genuinely unsettled, and this republication changes what the repository *is*
|
| 65 |
+
rather than adding to it. Publishing as `-rc.1` puts the material where it can
|
| 66 |
+
be fetched and argued with, without asserting that the edges are final. Whether
|
| 67 |
+
the final tag is `v1.1.0` or `v2.0.0` is deliberately left open.
|
| 68 |
+
|
| 69 |
+
**Published surfaces:**
|
| 70 |
+
|
| 71 |
+
- Signed tag `v1.1.0-rc.1`:
|
| 72 |
+
<https://github.com/AgentC-Consulting/aed-conventions/releases/tag/v1.1.0-rc.1>
|
| 73 |
+
- Single-file bundle `dist/aed-v1.1.0-rc.1.md` — the whole canon in reading
|
| 74 |
+
order, fetchable in one request, generated by `scripts/build_bundle.sh`
|
| 75 |
+
- Hugging Face dataset (org-owned):
|
| 76 |
+
<https://huggingface.co/datasets/agentc-consulting/aed-conventions>
|
| 77 |
+
|
| 78 |
+
The tag lives on the `release/v1.1.0-rc.1` branch. `main` remains at `v1.0.0`
|
| 79 |
+
until this candidate is promoted, so anyone fetching the stable line is
|
| 80 |
+
unaffected.
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
## 2026-07-07 — Six core rules written down and licensed (pre-publication)
|
| 86 |
+
|
| 87 |
+
**Practiced since ~late 2025, first published 2026-07-07.** *(reconstructed)*
|
| 88 |
+
The six core rules (branch-on-type, name-the-thing, guard clauses,
|
| 89 |
+
intention-revealing names, why-comments, formatter-owned layout) were not
|
| 90 |
+
designed as a standalone document — they emerged from production
|
| 91 |
+
Agent-Enhanced Development on AgentC's own application and website
|
| 92 |
+
codebases (Crystal/Amber, Grant ORM) during 2025–2026, tested against real
|
| 93 |
+
agent edits before ever being written down. No contemporaneous public record
|
| 94 |
+
exists for that emergence period, so "late 2025" here is deliberately
|
| 95 |
+
approximate rather than implying more precision than the evidence supports;
|
| 96 |
+
the contemporaneous private evidence exists and whether/when to publish it
|
| 97 |
+
is a separate, later decision.
|
| 98 |
+
|
| 99 |
+
On 2026-07-07 the rules were written down in full for the first time as
|
| 100 |
+
`CONVENTIONS.md` in this repository, with four before/after example files
|
| 101 |
+
added under `examples/`, and licensed:
|
| 102 |
+
|
| 103 |
+
- **Prose and documentation** — [CC BY 4.0](LICENSE).
|
| 104 |
+
- **Code examples** (`examples/`) — [MIT](LICENSE-EXAMPLES).
|
| 105 |
+
|
| 106 |
+
Control-flow rules (loops, guard ordering, rescues, fibers, macros) were
|
| 107 |
+
drafted internally during the same period and are held back from this
|
| 108 |
+
publication; they are targeted for a signed `v1.1.0` after their own review
|
| 109 |
+
(see `CONVENTIONS.md` → Status and versioning).
|
| 110 |
+
|
| 111 |
+
*Note on "published": this entry records the rules being committed to this
|
| 112 |
+
repository's local history. The repository going live on GitHub, with a
|
| 113 |
+
signed `v1.0.0` tag and mirrors on GitLab and Codeberg, is a separate, later
|
| 114 |
+
step — a following entry will record that date and the resulting URLs once
|
| 115 |
+
it happens.*
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## 2026-07-07 — Canonical repository goes public; v1.0.0 signed and tagged
|
| 120 |
+
|
| 121 |
+
The repository went live on GitHub as the canonical home of the AED
|
| 122 |
+
conventions, and `v1.0.0` was signed with the AgentC Consulting org key
|
| 123 |
+
and pushed with `--follow-tags`. The org public key is published in this
|
| 124 |
+
repo as [`agentc-signing-pubkey.asc`](agentc-signing-pubkey.asc); see
|
| 125 |
+
[README.md § Verifying signed tags](README.md#verifying-signed-tags) for the
|
| 126 |
+
verify command. Note: because that key is not (yet) registered to any
|
| 127 |
+
GitHub account, GitHub's own UI shows the tag/commits as "Unverified" —
|
| 128 |
+
this is a GitHub account-linking limitation, not a problem with the
|
| 129 |
+
signature itself; `gpg --verify` against the published key is the
|
| 130 |
+
authoritative check. The GPG signature is the authoritative provenance and
|
| 131 |
+
carries the org identity above; the tag object's `tagger` field instead
|
| 132 |
+
shows the maintainer's personal git identity, since that reflects who ran
|
| 133 |
+
the `git tag` command locally — this is expected. Also note: the tag
|
| 134 |
+
object's timestamp is 2026-07-08 UTC (18:51:51 PDT on 2026-07-07, the date
|
| 135 |
+
this entry is dated to), since the `-0700` offset carries it past midnight
|
| 136 |
+
UTC.
|
| 137 |
+
|
| 138 |
+
**Live URLs:**
|
| 139 |
+
|
| 140 |
+
- Canonical repository: <https://github.com/AgentC-Consulting/aed-conventions>
|
| 141 |
+
- Signed tag `v1.0.0`: <https://github.com/AgentC-Consulting/aed-conventions/releases/tag/v1.0.0>
|
| 142 |
+
- Discussions (enabled): <https://github.com/AgentC-Consulting/aed-conventions/discussions>
|
| 143 |
+
- Hugging Face seed dataset (v0): <https://huggingface.co/datasets/crimson-knight/aed-conventions-examples> —
|
| 144 |
+
four before/after pairs drawn from `examples/`, dual-licensed matching this
|
| 145 |
+
repo. Published under the maintainer's existing personal HF namespace
|
| 146 |
+
(`crimson-knight`) rather than an `AgentC-Consulting` org, because that org
|
| 147 |
+
does not yet exist on Hugging Face; an org card and an org-owned copy of
|
| 148 |
+
this dataset are follow-up work once the org exists (owner action).
|
| 149 |
+
|
| 150 |
+
**Not yet live (tracked, not forgotten):**
|
| 151 |
+
|
| 152 |
+
- **GitLab and Codeberg mirrors** (`scripts/push_mirrors.sh`) — both hosts
|
| 153 |
+
require credentials (an SSH key trusted by this machine, and, for
|
| 154 |
+
Codeberg, an accepted host key) that are not present on the publishing
|
| 155 |
+
machine. The script is inert until an owner configures the `gitlab` and
|
| 156 |
+
`codeberg` git remotes; it will then push `main` and all tags with one
|
| 157 |
+
command. Until the mirrors exist, GitHub is the sole host — the
|
| 158 |
+
"independent corroboration" property described in the plan does not yet
|
| 159 |
+
hold and should not be assumed.
|
| 160 |
+
- **Hugging Face org card** — *unblocked 2026-07-29*: the
|
| 161 |
+
`agentc-consulting` organization now exists on Hugging Face, and the
|
| 162 |
+
v1.1.0-rc.1 canon is published there as an org-owned dataset. The v0
|
| 163 |
+
examples dataset still sits in the personal `crimson-knight` namespace;
|
| 164 |
+
moving or duplicating it under the org is follow-up work.
|
| 165 |
+
- **dev.to posts A and B** — drafts exist in `drafts/` and await the owner's
|
| 166 |
+
voice review before either is scheduled; nothing has been published to
|
| 167 |
+
dev.to.
|
CITATION.cff
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cff-version: 1.2.0
|
| 2 |
+
message: >-
|
| 3 |
+
If you apply or reference the AED conventions, please cite this repository.
|
| 4 |
+
title: "AED Conventions — Agent-Enhanced Development: Code That Reads Like Statements"
|
| 5 |
+
type: software
|
| 6 |
+
authors:
|
| 7 |
+
- family-names: Tucker
|
| 8 |
+
given-names: Seth
|
| 9 |
+
email: st@agentc.consulting
|
| 10 |
+
affiliation: AgentC Consulting
|
| 11 |
+
- name: AgentC Consulting
|
| 12 |
+
website: "https://agentc.consulting"
|
| 13 |
+
abstract: >-
|
| 14 |
+
Code conventions for codebases written, reviewed, and maintained by humans
|
| 15 |
+
and coding agents together. The guiding rule: prefer the form that reads
|
| 16 |
+
like a plain statement of intent; reach for shorthand only when it makes
|
| 17 |
+
the intent clearer, never just shorter. Covers the token-window rationale,
|
| 18 |
+
naming doctrine, process managers, feature stories, edit-level style, and
|
| 19 |
+
control flow (CF-1 through CF-11), with before/after Crystal examples, a
|
| 20 |
+
machine-checkable end-of-edit checklist, and a small-model comprehension
|
| 21 |
+
benchmark.
|
| 22 |
+
repository-code: "https://github.com/AgentC-Consulting/aed-conventions"
|
| 23 |
+
url: "https://agentc.consulting"
|
| 24 |
+
keywords:
|
| 25 |
+
- code-conventions
|
| 26 |
+
- agent-enhanced-development
|
| 27 |
+
- coding-agents
|
| 28 |
+
- readability
|
| 29 |
+
- crystal
|
| 30 |
+
- style-guide
|
| 31 |
+
date-released: 2026-07-29
|
| 32 |
+
version: 1.1.0-rc.1
|
| 33 |
+
license:
|
| 34 |
+
- CC-BY-4.0
|
| 35 |
+
- MIT
|
| 36 |
+
license-url: "https://github.com/AgentC-Consulting/aed-conventions/blob/main/README.md#license"
|
| 37 |
+
# NOTE: dual license — CC BY 4.0 covers the prose/documentation (LICENSE),
|
| 38 |
+
# MIT covers the code examples under examples/ (LICENSE-EXAMPLES). See the
|
| 39 |
+
# README's License section for the split.
|
CONVENTIONS.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Conventions — Code That Reads Like Statements
|
| 2 |
+
|
| 3 |
+
**Agent-Enhanced Development (AED)** is how [AgentC Consulting](https://agentc.consulting)
|
| 4 |
+
writes code that both humans and coding agents can read, change, and review
|
| 5 |
+
with the least friction. The guiding rule is simple:
|
| 6 |
+
|
| 7 |
+
> **Prefer the form that reads like a plain statement of intent. Reach for
|
| 8 |
+
> shorthand only when it makes the intent _clearer_, never just shorter.**
|
| 9 |
+
|
| 10 |
+
Clever, compressed syntax saves the author a few keystrokes and costs every later
|
| 11 |
+
reader (human or agent) a re-parse. In an agent-driven codebase, that trade is
|
| 12 |
+
almost always wrong: the code is read and modified far more often than it is
|
| 13 |
+
written. Optimize for the reader.
|
| 14 |
+
|
| 15 |
+
These conventions are the *readability* half of the practice. Their
|
| 16 |
+
*correctness* companion is edit-time verification: run the compiler's type
|
| 17 |
+
check (for Crystal, the compiler frontend with `--no-codegen`) on every edited
|
| 18 |
+
file so mistakes surface immediately, not minutes later in a full build. AED
|
| 19 |
+
keeps the code clear; the edit-time check keeps it compiling. In our own
|
| 20 |
+
tooling this runs automatically after every agent edit — wire the equivalent
|
| 21 |
+
into whatever harness your agents use.
|
| 22 |
+
|
| 23 |
+
The examples below are Crystal, because that is what we build with. The rules
|
| 24 |
+
are about reading, not syntax.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## The rules (with Crystal examples)
|
| 29 |
+
|
| 30 |
+
<a id="rule-1"></a>
|
| 31 |
+
### 1. Branch on type with an explicit `if … is_a?`, not a clever `case`
|
| 32 |
+
|
| 33 |
+
`case … in` demands *exhaustive* matching, and in codebases using the Grant ORM
|
| 34 |
+
it trips over Grant's `Grant::Base+` type inference (`Error: case is not
|
| 35 |
+
exhaustive. Missing types: Grant::Base`). `case … when .is_a?(T)` (the
|
| 36 |
+
dot-receiver sugar) compiles but reads like a puzzle. An ordinary `if` reads
|
| 37 |
+
like a sentence.
|
| 38 |
+
|
| 39 |
+
```crystal
|
| 40 |
+
# ✅ AED — reads like a statement
|
| 41 |
+
if user.is_a?(Users::Regular)
|
| 42 |
+
session[:user_type] = "regular"
|
| 43 |
+
session[:session_version] = user.session_version
|
| 44 |
+
else
|
| 45 |
+
session[:user_type] = "admin"
|
| 46 |
+
end
|
| 47 |
+
|
| 48 |
+
# 🚫 trips Grant inference AND hides intent
|
| 49 |
+
case user
|
| 50 |
+
in Users::Regular then ...
|
| 51 |
+
in Users::Admin then ...
|
| 52 |
+
end
|
| 53 |
+
|
| 54 |
+
# 🚫 compiles, but the leading dot is a riddle
|
| 55 |
+
case user
|
| 56 |
+
when .is_a?(Users::Regular) then ...
|
| 57 |
+
end
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
<a id="rule-2"></a>
|
| 61 |
+
### 2. Name the thing; don't make the reader decode a chain
|
| 62 |
+
|
| 63 |
+
```crystal
|
| 64 |
+
# ✅ AED
|
| 65 |
+
expected_state = session["oauth_state"]?
|
| 66 |
+
return unless expected_state && constant_time_equal?(expected_state, state)
|
| 67 |
+
|
| 68 |
+
# 🚫 terse, but the reader has to hold three operations in their head
|
| 69 |
+
return unless session["oauth_state"]?.try { |s| constant_time_equal?(s, state) }
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
<a id="rule-3"></a>
|
| 73 |
+
### 3. Prefer explicit guard clauses to nested ternaries / one-liners
|
| 74 |
+
|
| 75 |
+
```crystal
|
| 76 |
+
# ✅ AED
|
| 77 |
+
return nil if password_digest.empty?
|
| 78 |
+
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 79 |
+
self
|
| 80 |
+
|
| 81 |
+
# 🚫 dense
|
| 82 |
+
password_digest.empty? ? nil : (Crypto::Bcrypt::Password.new(password_digest).verify(password) ? self : nil)
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
<a id="rule-4"></a>
|
| 86 |
+
### 4. Use full, intention-revealing names
|
| 87 |
+
|
| 88 |
+
Methods and locals are sentences-in-miniature: `establish_session`,
|
| 89 |
+
`invalidate_all_sessions`, `find_or_create_from_oauth`, `expected_state`. Avoid
|
| 90 |
+
`do_it`, `tmp`, `x`, `res2`. A good name removes the need for a comment.
|
| 91 |
+
|
| 92 |
+
<a id="rule-5"></a>
|
| 93 |
+
### 5. Say *why* in a comment, let the code say *what*
|
| 94 |
+
|
| 95 |
+
Comments earn their place by explaining intent, security rationale, or a
|
| 96 |
+
non-obvious constraint — not by restating the line. The house style: a
|
| 97 |
+
session-establishing method carries a comment stating the fixation attack it
|
| 98 |
+
prevents; an encrypted column carries a comment stating what the encryption
|
| 99 |
+
protects and why. If a comment could be deleted with no loss because the code
|
| 100 |
+
already says it, delete it.
|
| 101 |
+
|
| 102 |
+
<a id="rule-6"></a>
|
| 103 |
+
### 6. One statement per line; let the formatter own the layout
|
| 104 |
+
|
| 105 |
+
Run `crystal tool format` (or your language's canonical formatter) as part of
|
| 106 |
+
every edit. Canonical formatting means every reader and every diff sees the
|
| 107 |
+
same shape.
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
<a id="shorthand-boundary"></a>
|
| 112 |
+
## When shorthand IS the clearer form
|
| 113 |
+
|
| 114 |
+
AED is "clarity first," not "verbose always." Idioms that are *more* readable are
|
| 115 |
+
encouraged: `arr.map(&.name)`, `value.try(&.to_i64?)`, a `?`-suffixed predicate,
|
| 116 |
+
a single well-named guard expression. The test is always: **does a reader who has
|
| 117 |
+
never seen this code understand the intent on first pass?** If yes, keep it. If
|
| 118 |
+
they have to mentally execute it, expand it.
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
<a id="checklist"></a>
|
| 123 |
+
## Checklist before you finish an edit
|
| 124 |
+
|
| 125 |
+
- [ ] Type branches use explicit `if … is_a?` (not `case … in` against Grant types).
|
| 126 |
+
- [ ] No one-liner hides more than one operation from the reader.
|
| 127 |
+
- [ ] Names state intent; no `tmp`/`x`/`res2`.
|
| 128 |
+
- [ ] Comments explain *why*, never restate *what*.
|
| 129 |
+
- [ ] `crystal tool format` is clean.
|
| 130 |
+
- [ ] The edit-time type check passed (no `case is not exhaustive`, no undefined methods).
|
| 131 |
+
|
| 132 |
+
---
|
| 133 |
+
|
| 134 |
+
## Status and versioning
|
| 135 |
+
|
| 136 |
+
This document is the public canon of the AED conventions, versioned by signed
|
| 137 |
+
git tags. Rules covering control flow (loops, guards, rescues, fibers, macros)
|
| 138 |
+
are drafted and under internal review; they will land here as a tagged minor
|
| 139 |
+
version. The [ADOPTION.md](ADOPTION.md) log records, with dates, when each rule
|
| 140 |
+
entered practice and when it was published.
|
LICENSE
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AED Conventions — Prose License (CC BY 4.0)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 AgentC Consulting
|
| 4 |
+
|
| 5 |
+
This applies to the prose and documentation in this repository — README.md,
|
| 6 |
+
CONVENTIONS.md, ADOPTION.md, llms.txt, drafts/, CITATION.cff's descriptive
|
| 7 |
+
text, and all other non-code content — licensed under the Creative Commons
|
| 8 |
+
Attribution 4.0 International License (CC BY 4.0).
|
| 9 |
+
|
| 10 |
+
Code examples under examples/ are licensed separately under MIT — see
|
| 11 |
+
LICENSE-EXAMPLES. This dual-license structure is explained in README.md.
|
| 12 |
+
|
| 13 |
+
To view the full legal text of this license, visit:
|
| 14 |
+
https://creativecommons.org/licenses/by/4.0/legalcode
|
| 15 |
+
|
| 16 |
+
Human-readable summary (this summary is not a substitute for the license):
|
| 17 |
+
|
| 18 |
+
You are free to:
|
| 19 |
+
|
| 20 |
+
- Share — copy and redistribute the material in any medium or format
|
| 21 |
+
- Adapt — remix, transform, and build upon the material
|
| 22 |
+
|
| 23 |
+
for any purpose, even commercially.
|
| 24 |
+
|
| 25 |
+
Under the following terms:
|
| 26 |
+
|
| 27 |
+
- Attribution — You must give appropriate credit to AgentC Consulting
|
| 28 |
+
(https://agentc.consulting), provide a link to this license, and
|
| 29 |
+
indicate if changes were made. You may do so in any reasonable manner,
|
| 30 |
+
but not in any way that suggests AgentC Consulting endorses you or
|
| 31 |
+
your use.
|
| 32 |
+
- No additional restrictions — You may not apply legal terms or
|
| 33 |
+
technological measures that legally restrict others from doing
|
| 34 |
+
anything the license permits.
|
| 35 |
+
|
| 36 |
+
No warranties are given. The license may not give you all of the
|
| 37 |
+
permissions necessary for your intended use. For example, other rights
|
| 38 |
+
such as publicity, privacy, or moral rights may limit how you use the
|
| 39 |
+
material.
|
| 40 |
+
|
| 41 |
+
Full legal code: https://creativecommons.org/licenses/by/4.0/legalcode
|
| 42 |
+
Deed (plain-language summary): https://creativecommons.org/licenses/by/4.0/
|
LICENSE-EXAMPLES
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 AgentC Consulting
|
| 4 |
+
|
| 5 |
+
This applies to the code examples in this repository's examples/ directory
|
| 6 |
+
(the "Software"). The surrounding prose and documentation (README.md,
|
| 7 |
+
CONVENTIONS.md, ADOPTION.md, llms.txt, drafts/, and all other non-code
|
| 8 |
+
content) is licensed separately under CC BY 4.0 — see LICENSE. This
|
| 9 |
+
dual-license structure is explained in README.md.
|
| 10 |
+
|
| 11 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 12 |
+
of the Software, to deal in the Software without restriction, including
|
| 13 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 14 |
+
distribute, sublicense, and/or sell copies of the Software, and to permit
|
| 15 |
+
persons to whom the Software is furnished to do so, subject to the
|
| 16 |
+
following conditions:
|
| 17 |
+
|
| 18 |
+
The above copyright notice and this permission notice shall be included in
|
| 19 |
+
all copies or substantial portions of the Software.
|
| 20 |
+
|
| 21 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 22 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 23 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 24 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 25 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 26 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 27 |
+
DEALINGS IN THE SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- code
|
| 7 |
+
- code-conventions
|
| 8 |
+
- coding-agents
|
| 9 |
+
- agent-enhanced-development
|
| 10 |
+
- style-guide
|
| 11 |
+
- crystal
|
| 12 |
+
pretty_name: "AED Conventions — Agent-Enhanced Development"
|
| 13 |
+
size_categories:
|
| 14 |
+
- n<1K
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# AED Conventions — Agent-Enhanced Development
|
| 18 |
+
|
| 19 |
+
**Version `v1.1.0-rc.1` — release candidate.**
|
| 20 |
+
|
| 21 |
+
Code conventions for codebases written, reviewed, and maintained by humans
|
| 22 |
+
*and* coding agents together. The guiding rule:
|
| 23 |
+
|
| 24 |
+
> **Prefer the form that reads like a plain statement of intent. Reach for
|
| 25 |
+
> shorthand only when it makes the intent _clearer_, never just shorter.**
|
| 26 |
+
|
| 27 |
+
This dataset is a mirror. The **canonical source** is
|
| 28 |
+
<https://github.com/AgentC-Consulting/aed-conventions>, and if the two ever
|
| 29 |
+
disagree, the repository wins. Maintained by
|
| 30 |
+
[AgentC Consulting](https://agentc.consulting).
|
| 31 |
+
|
| 32 |
+
## What's here
|
| 33 |
+
|
| 34 |
+
Chapters 01–04, 07 and `quick_reference.md` are the author's original notes
|
| 35 |
+
(written 2024-06-03; `03_process_managers.md` revised 2025-11-24), published
|
| 36 |
+
**verbatim** — including his own work-in-progress markers and one section still
|
| 37 |
+
marked `TBD`. Chapters 05–06 and the evidence are later work.
|
| 38 |
+
|
| 39 |
+
| File | Contents |
|
| 40 |
+
|---|---|
|
| 41 |
+
| `dist/aed-v1.1.0-rc.1.md` | **Everything, in one file, in reading order** — start here |
|
| 42 |
+
| `01_why_models_need_this.md` | Token windows: why naming carries so much weight for a model |
|
| 43 |
+
| `02_naming_conventions.md` | `list_of_` naming, boolean-as-question naming, attributes as short statements |
|
| 44 |
+
| `03_process_managers.md` | The "when" grammar for business processes |
|
| 45 |
+
| `04_feature_stories.md` | Personas, operations, authorization levels |
|
| 46 |
+
| `CONVENTIONS.md` | Chapter 05 — six edit-level style rules with before/after Crystal |
|
| 47 |
+
| `06_control_flow.md` | CF-1…CF-11 — `case`, loops, guards, rescues, fibers, macros |
|
| 48 |
+
| `07_how_the_workflow_runs.md` | Plan in batches, let the agent run, walk away |
|
| 49 |
+
| `quick_reference.md` | The cheat sheet |
|
| 50 |
+
| `examples/` | Runnable before/after Crystal files |
|
| 51 |
+
| `evidence/` | Small-model comprehension benchmark + raw per-probe data |
|
| 52 |
+
| `llms.txt` | Machine-readable map, ordered to match the reading order |
|
| 53 |
+
|
| 54 |
+
## Evidence, with its limits
|
| 55 |
+
|
| 56 |
+
`evidence/haiku_comprehension_report.md` reports AED-style Crystal scoring
|
| 57 |
+
**60/60** against **54/60** for conventional compressed style, on 10 snippet
|
| 58 |
+
pairs blind-answered by Claude Haiku and blind-graded.
|
| 59 |
+
|
| 60 |
+
Read the stated limits before citing it: n=10 pairs, one small model, a single
|
| 61 |
+
run with no variance estimate, a model grader rather than a human one, and the
|
| 62 |
+
snippet pairs were authored by the same party that authored the conventions.
|
| 63 |
+
It is a **directional signal consistent with the hypothesis, not proof of it**.
|
| 64 |
+
|
| 65 |
+
## Status
|
| 66 |
+
|
| 67 |
+
This is a **release candidate**. Two things are unsettled: the CF-1…CF-11
|
| 68 |
+
thresholds (open questions are listed at the end of that chapter), and one
|
| 69 |
+
naming example in `CONVENTIONS.md` that conflicts with `02_naming_conventions.md`
|
| 70 |
+
— chapter 02 is the authority where they disagree.
|
| 71 |
+
|
| 72 |
+
## Citation
|
| 73 |
+
|
| 74 |
+
See `CITATION.cff`. In short:
|
| 75 |
+
|
| 76 |
+
> Tucker, Seth, and AgentC Consulting. *AED Conventions — Agent-Enhanced
|
| 77 |
+
> Development: Code That Reads Like Statements*, v1.1.0-rc.1, 2026.
|
| 78 |
+
> https://github.com/AgentC-Consulting/aed-conventions
|
| 79 |
+
|
| 80 |
+
## License
|
| 81 |
+
|
| 82 |
+
Dual-licensed, matching the canonical repository:
|
| 83 |
+
|
| 84 |
+
- **Prose and documentation** — [CC BY 4.0](LICENSE). Reuse and adapt freely,
|
| 85 |
+
with credit to [AgentC Consulting](https://agentc.consulting).
|
| 86 |
+
- **Code under `examples/`** — [MIT](LICENSE-EXAMPLES). Take it freely, with or
|
| 87 |
+
without credit.
|
dist/aed-v1.1.0-rc.1.md
ADDED
|
@@ -0,0 +1,1751 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Conventions — the complete canon (v1.1.0-rc.1)
|
| 2 |
+
|
| 3 |
+
> **This file is generated.** It is every chapter of
|
| 4 |
+
> [AED Conventions](https://github.com/AgentC-Consulting/aed-conventions)
|
| 5 |
+
> concatenated in reading order, so the whole thing can be fetched with one
|
| 6 |
+
> request or pasted into one context window. The repository is canonical; if
|
| 7 |
+
> this file and the repository disagree, the repository wins.
|
| 8 |
+
>
|
| 9 |
+
> Fetch the newest copy:
|
| 10 |
+
> `https://raw.githubusercontent.com/AgentC-Consulting/aed-conventions/v1.1.0-rc.1/dist/aed-v1.1.0-rc.1.md`
|
| 11 |
+
>
|
| 12 |
+
> Chapters 01–04, 07 and the quick reference are the author's original notes,
|
| 13 |
+
> published verbatim — including his own work-in-progress markers. Chapter 05
|
| 14 |
+
> (`CONVENTIONS.md`) and chapter 06 are later work.
|
| 15 |
+
>
|
| 16 |
+
> Licensed CC BY 4.0 (prose) and MIT (code examples) — AgentC Consulting,
|
| 17 |
+
> https://agentc.consulting
|
| 18 |
+
|
| 19 |
+
## Contents
|
| 20 |
+
|
| 21 |
+
- 01 · Why Models Need This — `01_why_models_need_this.md`
|
| 22 |
+
- Naming Conventions Overview for Agent Enhanced Development (AED or AE-dev) — `02_naming_conventions.md`
|
| 23 |
+
- Process Manager Conventions — `03_process_managers.md`
|
| 24 |
+
- Agent Enhanced Development - The Whole Process — `04_feature_stories.md`
|
| 25 |
+
- AED Conventions — Code That Reads Like Statements — `CONVENTIONS.md`
|
| 26 |
+
- 06 · Control Flow (CF-1 … CF-11) — `06_control_flow.md`
|
| 27 |
+
- How Agent Enhanced Development Work Flows - Local Models — `07_how_the_workflow_runs.md`
|
| 28 |
+
- Quick Reference - AED Cheat Sheet — `quick_reference.md`
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
<!-- source: 01_why_models_need_this.md -->
|
| 34 |
+
|
| 35 |
+
## 01 · Why Models Need This
|
| 36 |
+
|
| 37 |
+
*Excerpted **verbatim** from the author's `naming_conventions.md`, lifted to the
|
| 38 |
+
front of the reading order because it explains why every later rule exists.
|
| 39 |
+
The complete original — with this passage in place — is
|
| 40 |
+
[02_naming_conventions.md](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/02_naming_conventions.md).*
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
Naming conventions are one of the ways that drive the agent enhanced development workflow. The reason for this is that AI models use token windows to understand the context of things. 
|
| 45 |
+
|
| 46 |
+
### Basic Explanation of Tokens & Token Window
|
| 47 |
+
|
| 48 |
+
AI models, specifically LLMs, use tokens to represent groups of text. For example the statement:
|
| 49 |
+
|
| 50 |
+
`I want to create a new user and assign them to an account.`
|
| 51 |
+
|
| 52 |
+
For this example I’ll use Llama 3 to tokenize this prompt. When we tokenize this prompt, it turns into these tokens:
|
| 53 |
+
|
| 54 |
+
\`
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
'I'
|
| 58 |
+
' want'
|
| 59 |
+
' to'
|
| 60 |
+
' create'
|
| 61 |
+
' a'
|
| 62 |
+
' new'
|
| 63 |
+
' user'
|
| 64 |
+
' and'
|
| 65 |
+
' assign'
|
| 66 |
+
' them'
|
| 67 |
+
' to'
|
| 68 |
+
' an'
|
| 69 |
+
' account'
|
| 70 |
+
'.'
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
The extra spaces inside of the single quotes here is to highlight that spaces can be part of a token. Now when the AI model is scanning through the prompt, it’s going to read a group of tokens at a time, shifting down as it processes. For this example I’ll use a 8 token window, shifting 4 tokens at a time so there is some overlap.
|
| 74 |
+
|
| 75 |
+
Starting token window `’I want to create a new user and’`
|
| 76 |
+
|
| 77 |
+
Next token window `’ a new user and assign them to an’`
|
| 78 |
+
|
| 79 |
+
Final token window `‘ assign them to an account.’`
|
| 80 |
+
|
| 81 |
+
This window is typically larger than this, but for this example it illustrates how as the window shifts and the LLM model associates groups of tokens. This association is how the relationship of a flow of words is established and influences the direction that the model computes. This is why a naming convention needs to be very consistent.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
*Chapter 01 of the AED canon · continue to
|
| 86 |
+
[02 · Naming Conventions](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/02_naming_conventions.md) ·
|
| 87 |
+
[reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
<!-- source: 02_naming_conventions.md -->
|
| 93 |
+
|
| 94 |
+
## Naming Conventions Overview for Agent Enhanced Development (AED or AE-dev)
|
| 95 |
+
|
| 96 |
+
`_This is a work in progress_`
|
| 97 |
+
|
| 98 |
+
Naming conventions are one of the ways that drive the agent enhanced development workflow. The reason for this is that AI models use token windows to understand the context of things. 
|
| 99 |
+
|
| 100 |
+
### Basic Explanation of Tokens & Token Window
|
| 101 |
+
|
| 102 |
+
AI models, specifically LLMs, use tokens to represent groups of text. For example the statement:
|
| 103 |
+
|
| 104 |
+
`I want to create a new user and assign them to an account.`
|
| 105 |
+
|
| 106 |
+
For this example I’ll use Llama 3 to tokenize this prompt. When we tokenize this prompt, it turns into these tokens:
|
| 107 |
+
|
| 108 |
+
\`
|
| 109 |
+
|
| 110 |
+
```
|
| 111 |
+
'I'
|
| 112 |
+
' want'
|
| 113 |
+
' to'
|
| 114 |
+
' create'
|
| 115 |
+
' a'
|
| 116 |
+
' new'
|
| 117 |
+
' user'
|
| 118 |
+
' and'
|
| 119 |
+
' assign'
|
| 120 |
+
' them'
|
| 121 |
+
' to'
|
| 122 |
+
' an'
|
| 123 |
+
' account'
|
| 124 |
+
'.'
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
The extra spaces inside of the single quotes here is to highlight that spaces can be part of a token. Now when the AI model is scanning through the prompt, it’s going to read a group of tokens at a time, shifting down as it processes. For this example I’ll use a 8 token window, shifting 4 tokens at a time so there is some overlap.
|
| 128 |
+
|
| 129 |
+
Starting token window `’I want to create a new user and’`
|
| 130 |
+
|
| 131 |
+
Next token window `’ a new user and assign them to an’`
|
| 132 |
+
|
| 133 |
+
Final token window `‘ assign them to an account.’`
|
| 134 |
+
|
| 135 |
+
This window is typically larger than this, but for this example it illustrates how as the window shifts and the LLM model associates groups of tokens. This association is how the relationship of a flow of words is established and influences the direction that the model computes. This is why a naming convention needs to be very consistent.
|
| 136 |
+
|
| 137 |
+
### Patterns For Naming Conventions
|
| 138 |
+
|
| 139 |
+
For this section I’m going to use the example of implementing the feature story from above:
|
| 140 |
+
|
| 141 |
+
\`I want to create a new user and assign them to an account.
|
| 142 |
+
|
| 143 |
+
#### The Rails Way - Conventions That Have Stood The Test of Time
|
| 144 |
+
|
| 145 |
+
The Rails framework has lead the way with “convention over configuration” for well over a decade now. You can really feel the difference this makes in your productivity when getting started. However, once you deviate from the normal Rails conventions you’ll find that Rails can become very painful to work with. This typically happens with non-RESTful business logic being intermingled into what should only be a RESTful end-point.
|
| 146 |
+
|
| 147 |
+
The Rails conventions would typically establish the following flow:
|
| 148 |
+
|
| 149 |
+
1. Assuming that the `UsersController` already exists, with the standard `create` action inside of it to handle a `POST` request
|
| 150 |
+
2. You (the dev) would update the allowed params to add an `account_id` parameter that would be used to allow the user to be associated to the account.
|
| 151 |
+
|
| 152 |
+
This works perfectly for a one-to-one relationship, where one user belongs to one account. What happens if we want to make a many-to-one relationship where the user can have multiple accounts it has access to? This is where the Rails conventions can start to become murky and developers get creative in their solutions.
|
| 153 |
+
|
| 154 |
+
You may do one of the following:
|
| 155 |
+
|
| 156 |
+
1. You create a service object or PORO to handle the logic from the request and neatly organize the process into 1 or more classes to handle the job.
|
| 157 |
+
2. You update the allowed params to make the `account_id` into an `account_ids` array that manages a join table that represents the association for the user.
|
| 158 |
+
3. You split the association into 2 end-points, and you have your UI perform multiple successive requests in order to create/update all of the relationships.
|
| 159 |
+
4. You stuff a bunch of logic into your controller to determine if/when updates to the joining records need to happen (most common rapid development approach).
|
| 160 |
+
|
| 161 |
+
Depending on the maturity of your app, you may start at option 3 and move up in sophistication or simplicity. There’s no real wrong answer here, just a lot of opinions.
|
| 162 |
+
|
| 163 |
+
Rails doesn’t have one way of handling increasingly complexity. It’s up to the developer who is writing the start of the feature to hopefully do it in a way that works right for the maturity level of the project at that time.
|
| 164 |
+
|
| 165 |
+
However, when we introduce an AI agent into the mix the story begins to change.
|
| 166 |
+
|
| 167 |
+
#### The Agent Enhanced Way
|
| 168 |
+
|
| 169 |
+
Working with an AI agent can be a powerful multiplier for your efficiency as a dev, especially as the app grows in complexity. This is highly dependent on how clear the patterns are that you choose.
|
| 170 |
+
|
| 171 |
+
The pattern that you choose is critical because it heavily influences the models train of thought. Since AI models don’t have mental models like you or I do, they become heavily influenced by the way a prompt is written. You can effectively ask the same question, word it in various ways and get the AI to provide a varying answer. This is both good and bad. It means the AI can be articulate with some level of complexity, but it creates less certainty in the consistency required for coding. We can overcome this, mostly, by using a more strict and consistent naming convention.
|
| 172 |
+
|
| 173 |
+
Let’s start by looking at something that would generally be acceptable as “good code”.
|
| 174 |
+
|
| 175 |
+
```crystal
|
| 176 |
+
class Customer
|
| 177 |
+
property name : String
|
| 178 |
+
property email : String
|
| 179 |
+
|
| 180 |
+
def initialize(@name, @email)
|
| 181 |
+
end
|
| 182 |
+
|
| 183 |
+
end
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
Here we have the barest of minimums that represent a Customer for our new SaaS product. After all, this entire method is around building and maintaining products as they grow in complexity.
|
| 187 |
+
|
| 188 |
+
I am intentionally skipping persistence methods because this explanation is about naming conventions.
|
| 189 |
+
|
| 190 |
+
Our first job is going to be setting up subscriptions for Customers. A Customer can have many Subscriptions.
|
| 191 |
+
|
| 192 |
+
So now we have a setup like this:
|
| 193 |
+
|
| 194 |
+
```crystal
|
| 195 |
+
class Subscription
|
| 196 |
+
property name : String
|
| 197 |
+
property rate : Int16
|
| 198 |
+
property quantity : Int16
|
| 199 |
+
|
| 200 |
+
def initialize(@name, @rate, @quantity)
|
| 201 |
+
end
|
| 202 |
+
|
| 203 |
+
end
|
| 204 |
+
|
| 205 |
+
class Customer
|
| 206 |
+
property name : String
|
| 207 |
+
property email : String
|
| 208 |
+
property subscriptions : Array(Subscription) = [] of Subscription
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def initialize(@name, @email)
|
| 212 |
+
end
|
| 213 |
+
|
| 214 |
+
end
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
At this point the relationship between the two objects is clear and the names are simple and imply their intended meaning. Our minds have mental models of what a Customer is and what a Subscription is because of our life experience. We can fill in the implications of what the property and its type mean. The `name` property is relatively clear.
|
| 218 |
+
|
| 219 |
+
However, to an AI this kind of naming is less than ideal. It will probably still work, but will progressively become less and less useful as the classes grow in complexity.
|
| 220 |
+
|
| 221 |
+
Instead if we change to a more verbose naming convention that adds in contextual meaning, the AI is better able to understand what we are trying to do.
|
| 222 |
+
|
| 223 |
+
Let’s focus on the Customer class first and you’ll see what I mean.
|
| 224 |
+
|
| 225 |
+
```crystal
|
| 226 |
+
class Customer
|
| 227 |
+
property first_name : String
|
| 228 |
+
property last_name : String
|
| 229 |
+
property email_address : String
|
| 230 |
+
property list_of_all_active_subscriptions : Array(Subscription) = [] of Subscription
|
| 231 |
+
|
| 232 |
+
def initialize(@name, @email)
|
| 233 |
+
end
|
| 234 |
+
|
| 235 |
+
end
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
You may have noticed that a lot has changed and at the same time, we changed very little.
|
| 239 |
+
|
| 240 |
+
Notice how explicit the name attributes are now? The name before could have been first, last, middle initial or full name. Who knows? We certainly didn’t have those details before. A more senior developer reading this probably picked up on that quickly!
|
| 241 |
+
|
| 242 |
+
We’ve now expanded our `email` to `email_address` because now it’s 100% clear that we intend to store an email address there and some kind of flag that says the email subscription list that the Customer belongs to. It was implied that the value was intended to be an email address, but it’s entirely possible its intended use was not that.
|
| 243 |
+
|
| 244 |
+
The changes to our old `subscriptions` property are a bit shocking! Did you have any idea that all you needed to track were the active subscriptions? Maybe during the conversation with a product owner, but the AI would have no idea. By updating the naming we now have a clear purpose given to that property with a contextually significant meaning.
|
| 245 |
+
|
| 246 |
+
So far all of the examples are fairly simple and straight forward. In fact, this is already pretty close to what would be considered “good” naming practices. So let’s take this to the next level where there’s a lot more complexity. This is where real business logic becomes messy and far less non-obvious.
|
| 247 |
+
|
| 248 |
+
Well the good news is that our little SaaS is growing up and now has more products and all new licensing. The sales team has been getting enterprise customer inquiries and the deal size is so big that the product team is now being told we need to adapt our one Customer to many Subscriptions model to allow for Customers who aggregate into a single billable entity, and prevents these users from adding any subscription items.
|
| 249 |
+
|
| 250 |
+
By the way, you have a super short window to implement so there’s no way to take time to architect this thoroughly and perform any data migrations.
|
| 251 |
+
|
| 252 |
+
That’s alright, this type of feature request is the Achilles Heel of many code bases. Typically in this kind of scenario we start seeing naming becoming a challenge. Let’s see how we can do it so that it benefits our AI agent assistant, or how our agent would be implementing this feature if we let it drive for us.
|
| 253 |
+
|
| 254 |
+
```crystal
|
| 255 |
+
class Customer
|
| 256 |
+
property first_name : String
|
| 257 |
+
property last_name : String
|
| 258 |
+
property email_address : String
|
| 259 |
+
property list_of_all_active_subscriptions : Array(Subscription) = [] of Subscription
|
| 260 |
+
property is_this_an_enterprise_customer : Bool
|
| 261 |
+
|
| 262 |
+
def initialize(@first_name, @last_name, @email_address, @is_this_an_enterprise_customer = false)
|
| 263 |
+
end
|
| 264 |
+
|
| 265 |
+
end
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class EnterpriseCustomerBillingEntity
|
| 270 |
+
property full_legal_entity_name : String
|
| 271 |
+
property payment_terms_in_number_of_days : Int8
|
| 272 |
+
property billing_cycle_frequency : Int8
|
| 273 |
+
property billing_cycle_time_period : String
|
| 274 |
+
property maximum_customers_according_to_the_contract_limit : Int16
|
| 275 |
+
property current_count_of_customer_accounts : UInt16
|
| 276 |
+
|
| 277 |
+
def initialize(@full_legal_entity_name, @payment_terms_in_number_of_days, @billing_cycle_frequency, @billing_cycle_time_period, @maximum_customers_according_to_the_contract_limit, @current_count_of_customer_accounts)
|
| 278 |
+
end
|
| 279 |
+
|
| 280 |
+
end
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
We now have this new class mixed in that handles the enterprise details. This isn’t about programming the full workflow, it’s about the naming convention used here. A pattern is beginning to emerge.
|
| 284 |
+
|
| 285 |
+
Now depending on your level of seniority as a dev, you may read those class attributes and think “yeah that’s basically what I would do, except I’d simplify the names a bit”. And this is when I can begin outlining the general rules to follow when writing code you want an AI assistant to flourish with:
|
| 286 |
+
|
| 287 |
+
1. Object attributes with primitive types should be short statements or phrases
|
| 288 |
+
2. Object attributes that are booleans should be phrased as a “yes/no” question or statement
|
| 289 |
+
3. Object attributes that are collections, Arrays or enumerable in some way. Usually it’s good to start the name like “list\_of\_” or “array\_of\_” with a descriptive name of the object types it’s holding.
|
| 290 |
+
|
| 291 |
+
Following these guidelines will help keep your naming conventions consistent which helps provide clarity and contextual understanding for your AI agent. It’s also good for you, because you may come back to this code many months or years later and you will not remember the product meeting details but you can clearly read your code.
|
| 292 |
+
|
| 293 |
+
#### Method & Variable Naming
|
| 294 |
+
|
| 295 |
+
Next let’s discuss method and variable naming. This is the most common area where devs can help themselves greatly, but typically fall short. Clever naming can make short variable names for easier readability but the context of what and why quickly disappears into your editors background.
|
| 296 |
+
|
| 297 |
+
We left some of the business logic that was in our new feature requirement that we can use for this part. The part we are going to focus on is going to be:
|
| 298 |
+
|
| 299 |
+
`prevents these users from adding any subscription items`
|
| 300 |
+
|
| 301 |
+
This is something that we can use a process manager to handle while exercising good naming conventions.
|
| 302 |
+
|
| 303 |
+
This is a process manager, but it does not use “process” or “manager” in the name. It is acceptable with or without including those details. 
|
| 304 |
+
|
| 305 |
+
```crystal
|
| 306 |
+
class AddSubscriptionToCustomer
|
| 307 |
+
property customer_to_add_subscription_to : Customer
|
| 308 |
+
property subscription_to_add_to_customer : Subscription
|
| 309 |
+
|
| 310 |
+
def initialize(@customer_to_add_subscription_to, @subscription_to_add_to_customer)
|
| 311 |
+
end
|
| 312 |
+
|
| 313 |
+
def add_subscription_to_customer
|
| 314 |
+
return if @customer_to_add_subscription_to.is_this_an_enterprise_customer
|
| 315 |
+
|
| 316 |
+
@customer_to_add_subscription_to.list_of_all_active_subscriptions << subscription_to_add_to_customer
|
| 317 |
+
end
|
| 318 |
+
end
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
1. The class name for the process manager clearly states what the entire process is attempting to do in a short statement.
|
| 322 |
+
2. The initialize method accepts all of the initial data required to perform the process
|
| 323 |
+
3. The name of the method to start the process is clear and obvious. 
|
| 324 |
+
|
| 325 |
+
This reads very plainly now. The logic in the `return` line reads almost like a complete sentence. This makes the intent very clear for both you the developer and your AI agent assistant.
|
| 326 |
+
|
| 327 |
+
The variable names clearly state what the contents are, and the intended use.
|
| 328 |
+
|
| 329 |
+
The method name clearly states the action that is being performed. It does not take any parameters because the intended purpose of a process manager is to be initialized with all of the data it needs in order to perform the process it is managing.
|
| 330 |
+
|
| 331 |
+
Do you come across code this plainly and clearly written? Maybe. It’s more than likely that it’s plain on that it uses simpler wording and phrasing that is less robust, but still clear. You may have seen `customer_to_update` and considered that good over just `customer`. Maybe you consider the one word better. But your AI agent is going to have less and less of a clear intent by using such simplified wording.
|
| 332 |
+
|
| 333 |
+
### The Compounding Rewards of Enhanced Naming
|
| 334 |
+
|
| 335 |
+
You are rewarded for clearer naming practices as your files get larger. In fact, you may start implementing these naming conventions and notice something strange. At first, your code completion suggestions from typical AI coding assistants will usually be pretty bad. Only at first, but it’s distinctly noticeable.
|
| 336 |
+
|
| 337 |
+
Github Copilot tends to be the worst offender by offering up code snippets that are close but make silly naming mistakes when re-using existing variables. Mistakes such as pluralizing when the variable should be phrased singularly and vice-versa.
|
| 338 |
+
|
| 339 |
+
I use Cursor, which has a Copilot++ in editor code suggestion tool and it tends to work much better. It still has lower quality suggestions initially, but as your files grow in size, the suggestions and understanding of what you are trying to do become increasingly more accurate. This includes across files when you’re using Copilot++.
|
| 340 |
+
|
| 341 |
+
---
|
| 342 |
+
|
| 343 |
+
*Chapter 02 of the AED canon · published **verbatim** from the author's original; the work-in-progress marker at the top is his own, kept as written · continue to [03 · Process Managers](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/03_process_managers.md) · [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
---
|
| 347 |
+
|
| 348 |
+
<!-- source: 03_process_managers.md -->
|
| 349 |
+
|
| 350 |
+
## Process Manager Conventions
|
| 351 |
+
|
| 352 |
+
`_This is a work in progress_`. Updated on 11/24/2025
|
| 353 |
+
|
| 354 |
+
Process managers are a convention that AI agents need to organize an unRESTful process. This is commonly domain specific business logic or workflows.
|
| 355 |
+
|
| 356 |
+
A process manager name is a statement or phrase that describes what is being done.
|
| 357 |
+
|
| 358 |
+
Let’s use an example of building a report. We are just going to describe the feature story that defines this process, and the triggering event. For this example our app has Customers: 
|
| 359 |
+
|
| 360 |
+
`When a list of Customer ID’s is provided, then lock each customers account.`
|
| 361 |
+
|
| 362 |
+
Processes start with a “when” keyword, always. Because a process is “when” something happens!
|
| 363 |
+
|
| 364 |
+
The second statement “a list of Customer ID’s is provided” tells us the qualifying information we need before this process can be performed. Here were are referencing a “list” aka an Array of IDs which is the attribute type from the Customer model. This could be integers, ULID, UUID’s etc.
|
| 365 |
+
|
| 366 |
+
The second half “lock each customers account” is using jargon that represents an operation we define for the business. “Locking” an account for this means: changing an attribute in the Customer model that requires an additional input from the user to confirm their identity and reset their password.
|
| 367 |
+
|
| 368 |
+
A process manager can perform many operations at a time, and typically will. The more complicated the process, the more likely to require human intervention to write the complete the process writing.
|
| 369 |
+
|
| 370 |
+
If we expand our process statement, it looks like the following:
|
| 371 |
+
|
| 372 |
+
`When an array of Integers that represent Customer IDs is provided then loop through each Customer account using the ID to find the correct record and update the necessary attribute that will prevent the Customer from accessing their account.`
|
| 373 |
+
|
| 374 |
+
The AI is going to analyze this and ultimately make the determination if any jargon was used, and will ask questions if it can’t understand your intent. It will generally phrase it like I explained above, and may provide more details.
|
| 375 |
+
|
| 376 |
+
---
|
| 377 |
+
|
| 378 |
+
*Chapter 03 of the AED canon · published **verbatim** from the author's original (last revised 2025-11-24); the work-in-progress marker at the top is his own, kept as written · continue to [04 · Feature Stories](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/04_feature_stories.md) · [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
---
|
| 382 |
+
|
| 383 |
+
<!-- source: 04_feature_stories.md -->
|
| 384 |
+
|
| 385 |
+
## Agent Enhanced Development - The Whole Process
|
| 386 |
+
|
| 387 |
+
### Introduction To What A Feature Request Is
|
| 388 |
+
The idea of “operating” an AI means we need to be able to define it’s “operations” to begin with.
|
| 389 |
+
|
| 390 |
+
An operation is essentially the work flow for performing a task. This should encompass multiple steps and possibly “tasks” depending on how you want to define a task.
|
| 391 |
+
|
| 392 |
+
To operate an AI agent successfully, we have to shift our mindset on a few topics, such as:
|
| 393 |
+
|
| 394 |
+
1. How we define the work that we want to perform
|
| 395 |
+
2. The expected patterns or overall flexibility we have in our code base
|
| 396 |
+
3. Our definition of naming conventions and what "clear" means for us
|
| 397 |
+
4. How we perform development work
|
| 398 |
+
5. The relationship between the code we write and how it reflects the business
|
| 399 |
+
|
| 400 |
+
To begin with, we are going to start by more clearly defining what a `feature request` really is. If you've been a developer for any period of time, you've most likely already worked with scrum or agile and been exposed to User Stories. The idea here is pretty similar, however instead of managing the details of the story from a 3rd party tool such as Jira, we are going to manage the details directly with our AI agent that works from our code base.
|
| 401 |
+
|
| 402 |
+
Let's define some critical terminology before we move forward.
|
| 403 |
+
|
| 404 |
+
**Operation**: the interaction with the AI agent and ensuring it has the correct knowledge and understanding to perform.
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
### Our First Feature Request
|
| 408 |
+
Let’s describe some default operations that should come with the framework. I have notes about user stories and I think that operating an AI development agent should mean using Feature Stories to control the behavior of the agent and the outcome.
|
| 409 |
+
|
| 410 |
+
First a simple user story:
|
| 411 |
+
|
| 412 |
+
`As an **Admin** user, I want to _create_ a new **user** **_and_** _assign_ them to an **account**`
|
| 413 |
+
|
| 414 |
+
This story is pretty simple and would mean operations that are required use the typical MVC concepts, which makes things easy to start with.
|
| 415 |
+
|
| 416 |
+
The `As an Admin` establishes our persona, scoping the following **action** to be performed. When there is a persona we have chosen, we also know the feature request requires a view and a controller action at a minimum. Our agent knows which views belong to which controller actions, and if we need to create that controller, action, view etc.
|
| 417 |
+
|
| 418 |
+
The action is the full statement. It should be a clear summary of what would complete a request/response cycle. If it triggers or enqueues a background job, that should be stated. The action description should also include references to any data models that require a relationship. In the example that’s User and Account. The plurality of the data models dictates the relationships between them, and should use the same Active Record pattern expressions as in Rails.
|
| 419 |
+
|
| 420 |
+
The “I want to” part is provided as part of the story builder. The action verb needs to be an HTTP verb of GET POST PUTS PATCH or DELETE followed by the primary data model that is effected.
|
| 421 |
+
|
| 422 |
+
A unique verb of “perform” can be used to trigger a workflow that is not RESTful. This is the keyword you primarily use for our unique business logic, aka your special sauce.
|
| 423 |
+
|
| 424 |
+
The specially called out “and” in the action is because we follow up a simple RESTful action with a secondary action, and it’s establishing a relationship with an additional record. In this case I highlighted “assign” because it’s an example of company jargon that can alias an Active Record relationship of “belongs to”. These kinds of aliases can be configured with restrictions/conditions before creating a feature story. This story implies it is limited to linking the newly created user to an existing account, and that it does not create a new account.
|
| 425 |
+
|
| 426 |
+
A feature story with a persona breaks down it’s structure like this:
|
| 427 |
+
|
| 428 |
+
`As a (specify persona), I want to (RESTful verb, or “perform”) (“a” or “multiple”) (data model name of an existing data model) and (AR relationship name/type or “perform”) (data model name or Process Manager name if performing a process)`
|
| 429 |
+
|
| 430 |
+
A “persona” is a specialized alias of a User data model type that includes an indication of the “authorization” (ie permissions) level of that model type. For example, an Admin persona could be an alias of a Super Administrator type that has unrestricted permissions, which means they would be using controllers/routes that are scoped to this kind of user.
|
| 431 |
+
|
| 432 |
+
Authorization levels work in several ways together to create a robust authorization system.
|
| 433 |
+
|
| 434 |
+
- Model type: the model name should represent the general permission level of that group. This is resource based, so an Administrator user type may have its own API and all administrators would generally be considered to use those end-points.
|
| 435 |
+
- Action specific: RESTful verbs have a matching permission level two on the actual model as an attribute. Your app configuration should define if by default the user of that group is allowed or disallowed, and if the flag necessary to perform the action needs to be specified on the models record.
|
| 436 |
+
- Individual resource: individual resources can restrict behavior to model type or record ID’s.
|
| 437 |
+
|
| 438 |
+
For unRESTful end-points, the permissions are based on if the model type or specific records of models are allowed to execute an action.
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
### Breakdown of The Anatomy of A Feature Request
|
| 442 |
+
|
| 443 |
+
TBD
|
| 444 |
+
|
| 445 |
+
---
|
| 446 |
+
|
| 447 |
+
*Chapter 04 of the AED canon · published **verbatim** from the author's original. The closing `TBD` is the author's own — the anatomy breakdown is genuinely unwritten, and this release candidate marks it rather than papering over it · continue to [05 · Edit-Level Style](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/05_edit_level_style.md) · [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
---
|
| 451 |
+
|
| 452 |
+
<!-- source: CONVENTIONS.md -->
|
| 453 |
+
|
| 454 |
+
## AED Conventions — Code That Reads Like Statements
|
| 455 |
+
|
| 456 |
+
**Agent-Enhanced Development (AED)** is how [AgentC Consulting](https://agentc.consulting)
|
| 457 |
+
writes code that both humans and coding agents can read, change, and review
|
| 458 |
+
with the least friction. The guiding rule is simple:
|
| 459 |
+
|
| 460 |
+
> **Prefer the form that reads like a plain statement of intent. Reach for
|
| 461 |
+
> shorthand only when it makes the intent _clearer_, never just shorter.**
|
| 462 |
+
|
| 463 |
+
Clever, compressed syntax saves the author a few keystrokes and costs every later
|
| 464 |
+
reader (human or agent) a re-parse. In an agent-driven codebase, that trade is
|
| 465 |
+
almost always wrong: the code is read and modified far more often than it is
|
| 466 |
+
written. Optimize for the reader.
|
| 467 |
+
|
| 468 |
+
These conventions are the *readability* half of the practice. Their
|
| 469 |
+
*correctness* companion is edit-time verification: run the compiler's type
|
| 470 |
+
check (for Crystal, the compiler frontend with `--no-codegen`) on every edited
|
| 471 |
+
file so mistakes surface immediately, not minutes later in a full build. AED
|
| 472 |
+
keeps the code clear; the edit-time check keeps it compiling. In our own
|
| 473 |
+
tooling this runs automatically after every agent edit — wire the equivalent
|
| 474 |
+
into whatever harness your agents use.
|
| 475 |
+
|
| 476 |
+
The examples below are Crystal, because that is what we build with. The rules
|
| 477 |
+
are about reading, not syntax.
|
| 478 |
+
|
| 479 |
+
---
|
| 480 |
+
|
| 481 |
+
### The rules (with Crystal examples)
|
| 482 |
+
|
| 483 |
+
<a id="rule-1"></a>
|
| 484 |
+
#### 1. Branch on type with an explicit `if … is_a?`, not a clever `case`
|
| 485 |
+
|
| 486 |
+
`case … in` demands *exhaustive* matching, and in codebases using the Grant ORM
|
| 487 |
+
it trips over Grant's `Grant::Base+` type inference (`Error: case is not
|
| 488 |
+
exhaustive. Missing types: Grant::Base`). `case … when .is_a?(T)` (the
|
| 489 |
+
dot-receiver sugar) compiles but reads like a puzzle. An ordinary `if` reads
|
| 490 |
+
like a sentence.
|
| 491 |
+
|
| 492 |
+
```crystal
|
| 493 |
+
# ✅ AED — reads like a statement
|
| 494 |
+
if user.is_a?(Users::Regular)
|
| 495 |
+
session[:user_type] = "regular"
|
| 496 |
+
session[:session_version] = user.session_version
|
| 497 |
+
else
|
| 498 |
+
session[:user_type] = "admin"
|
| 499 |
+
end
|
| 500 |
+
|
| 501 |
+
# 🚫 trips Grant inference AND hides intent
|
| 502 |
+
case user
|
| 503 |
+
in Users::Regular then ...
|
| 504 |
+
in Users::Admin then ...
|
| 505 |
+
end
|
| 506 |
+
|
| 507 |
+
# 🚫 compiles, but the leading dot is a riddle
|
| 508 |
+
case user
|
| 509 |
+
when .is_a?(Users::Regular) then ...
|
| 510 |
+
end
|
| 511 |
+
```
|
| 512 |
+
|
| 513 |
+
<a id="rule-2"></a>
|
| 514 |
+
#### 2. Name the thing; don't make the reader decode a chain
|
| 515 |
+
|
| 516 |
+
```crystal
|
| 517 |
+
# ✅ AED
|
| 518 |
+
expected_state = session["oauth_state"]?
|
| 519 |
+
return unless expected_state && constant_time_equal?(expected_state, state)
|
| 520 |
+
|
| 521 |
+
# 🚫 terse, but the reader has to hold three operations in their head
|
| 522 |
+
return unless session["oauth_state"]?.try { |s| constant_time_equal?(s, state) }
|
| 523 |
+
```
|
| 524 |
+
|
| 525 |
+
<a id="rule-3"></a>
|
| 526 |
+
#### 3. Prefer explicit guard clauses to nested ternaries / one-liners
|
| 527 |
+
|
| 528 |
+
```crystal
|
| 529 |
+
# ✅ AED
|
| 530 |
+
return nil if password_digest.empty?
|
| 531 |
+
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 532 |
+
self
|
| 533 |
+
|
| 534 |
+
# 🚫 dense
|
| 535 |
+
password_digest.empty? ? nil : (Crypto::Bcrypt::Password.new(password_digest).verify(password) ? self : nil)
|
| 536 |
+
```
|
| 537 |
+
|
| 538 |
+
<a id="rule-4"></a>
|
| 539 |
+
#### 4. Use full, intention-revealing names
|
| 540 |
+
|
| 541 |
+
Methods and locals are sentences-in-miniature: `establish_session`,
|
| 542 |
+
`invalidate_all_sessions`, `find_or_create_from_oauth`, `expected_state`. Avoid
|
| 543 |
+
`do_it`, `tmp`, `x`, `res2`. A good name removes the need for a comment.
|
| 544 |
+
|
| 545 |
+
<a id="rule-5"></a>
|
| 546 |
+
#### 5. Say *why* in a comment, let the code say *what*
|
| 547 |
+
|
| 548 |
+
Comments earn their place by explaining intent, security rationale, or a
|
| 549 |
+
non-obvious constraint — not by restating the line. The house style: a
|
| 550 |
+
session-establishing method carries a comment stating the fixation attack it
|
| 551 |
+
prevents; an encrypted column carries a comment stating what the encryption
|
| 552 |
+
protects and why. If a comment could be deleted with no loss because the code
|
| 553 |
+
already says it, delete it.
|
| 554 |
+
|
| 555 |
+
<a id="rule-6"></a>
|
| 556 |
+
#### 6. One statement per line; let the formatter own the layout
|
| 557 |
+
|
| 558 |
+
Run `crystal tool format` (or your language's canonical formatter) as part of
|
| 559 |
+
every edit. Canonical formatting means every reader and every diff sees the
|
| 560 |
+
same shape.
|
| 561 |
+
|
| 562 |
+
---
|
| 563 |
+
|
| 564 |
+
<a id="shorthand-boundary"></a>
|
| 565 |
+
### When shorthand IS the clearer form
|
| 566 |
+
|
| 567 |
+
AED is "clarity first," not "verbose always." Idioms that are *more* readable are
|
| 568 |
+
encouraged: `arr.map(&.name)`, `value.try(&.to_i64?)`, a `?`-suffixed predicate,
|
| 569 |
+
a single well-named guard expression. The test is always: **does a reader who has
|
| 570 |
+
never seen this code understand the intent on first pass?** If yes, keep it. If
|
| 571 |
+
they have to mentally execute it, expand it.
|
| 572 |
+
|
| 573 |
+
---
|
| 574 |
+
|
| 575 |
+
<a id="checklist"></a>
|
| 576 |
+
### Checklist before you finish an edit
|
| 577 |
+
|
| 578 |
+
- [ ] Type branches use explicit `if … is_a?` (not `case … in` against Grant types).
|
| 579 |
+
- [ ] No one-liner hides more than one operation from the reader.
|
| 580 |
+
- [ ] Names state intent; no `tmp`/`x`/`res2`.
|
| 581 |
+
- [ ] Comments explain *why*, never restate *what*.
|
| 582 |
+
- [ ] `crystal tool format` is clean.
|
| 583 |
+
- [ ] The edit-time type check passed (no `case is not exhaustive`, no undefined methods).
|
| 584 |
+
|
| 585 |
+
---
|
| 586 |
+
|
| 587 |
+
### Status and versioning
|
| 588 |
+
|
| 589 |
+
This document is the public canon of the AED conventions, versioned by signed
|
| 590 |
+
git tags. Rules covering control flow (loops, guards, rescues, fibers, macros)
|
| 591 |
+
are drafted and under internal review; they will land here as a tagged minor
|
| 592 |
+
version. The [ADOPTION.md](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/ADOPTION.md) log records, with dates, when each rule
|
| 593 |
+
entered practice and when it was published.
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
---
|
| 597 |
+
|
| 598 |
+
<!-- source: 06_control_flow.md -->
|
| 599 |
+
|
| 600 |
+
## 06 · Control Flow (CF-1 … CF-11)
|
| 601 |
+
|
| 602 |
+
> **Status**: RELEASE CANDIDATE. These eleven rules ship in `v1.1.0-rc.1` as a
|
| 603 |
+
> candidate, not as settled canon. The numbered questions at the end are still
|
| 604 |
+
> open, and the answers may change individual thresholds before `v1.1.0` final.
|
| 605 |
+
> Adopt them if they help; expect the edges to move.
|
| 606 |
+
>
|
| 607 |
+
> **Scope question answered here**: how should AED handle control-flow code
|
| 608 |
+
> whose *syntax* does not naturally align with the reads-like-statements rule?
|
| 609 |
+
> A `while` loop, a `rescue` ladder, or a `spawn` block has no name of its own
|
| 610 |
+
> — the syntax is pure mechanism. AED's answer, developed rule by rule below:
|
| 611 |
+
> **when the syntax can't read like a statement, the *names around it* must
|
| 612 |
+
> say what the syntax is doing.**
|
| 613 |
+
|
| 614 |
+
---
|
| 615 |
+
|
| 616 |
+
### 0. Census — what actually occurs in our Crystal
|
| 617 |
+
|
| 618 |
+
Rules should target real frequency, not theory. Counted with `grep -rE`
|
| 619 |
+
across the two live codebases (regex counts are ceilings — e.g. the ternary
|
| 620 |
+
pattern also matches nilable type signatures; noted where it matters):
|
| 621 |
+
|
| 622 |
+
| Pattern | premium template `src/` (107 files, 12,250 lines) | agentc_website `src/` (22 files, 2,163 lines) |
|
| 623 |
+
|---|---:|---:|
|
| 624 |
+
| Leading `if` | 154 | 23 |
|
| 625 |
+
| `if … is_a?` (existing Rule 1) | 6 | 0 |
|
| 626 |
+
| `case` statements | 28 | 3 |
|
| 627 |
+
| `when` branches | 124 | 6 |
|
| 628 |
+
| `case … in` | **0** | **0** |
|
| 629 |
+
| Leading `unless` | 25 | 5 |
|
| 630 |
+
| Any ` unless ` (incl. postfix) | 150 | 24 |
|
| 631 |
+
| `while` | 4 | 8 |
|
| 632 |
+
| `until` | **0** | **0** |
|
| 633 |
+
| `loop do` | 2 | 0 |
|
| 634 |
+
| `break` | 3 | 12 |
|
| 635 |
+
| `next` | 15 | 3 |
|
| 636 |
+
| `return` (all) | 127 | 43 |
|
| 637 |
+
| Guard `return … if` | 36 | 19 |
|
| 638 |
+
| Guard `return … unless` | 58 | 7 |
|
| 639 |
+
| Ternary `? … :` (regex ceiling; true ternaries ≈ half) | 61 | 16 |
|
| 640 |
+
| `begin` | 14 | 2 |
|
| 641 |
+
| `rescue` | 57 | 8 |
|
| 642 |
+
| `ensure` | 13 | 0 |
|
| 643 |
+
| `retry` | **0** | **0** |
|
| 644 |
+
| `raise` | 156 (138 typed error, 14 bare string) | 1 |
|
| 645 |
+
| `spawn` | 4 (2 real code sites) | 0 |
|
| 646 |
+
| `Channel` | 1 | 0 |
|
| 647 |
+
| Concurrency `select` | **0** | **0** |
|
| 648 |
+
| `.each` | 16 | 7 |
|
| 649 |
+
| `.map` | 30 | 5 |
|
| 650 |
+
| `.select`/`.reject` | 13 | 4 |
|
| 651 |
+
| `.try` | 98 | 3 |
|
| 652 |
+
| `&.` shorthand | 116 | 7 |
|
| 653 |
+
| `macro` definitions | 3 | 0 |
|
| 654 |
+
| `{% if %}` compile-time branches | 2 | 0 |
|
| 655 |
+
| `def …?` predicate methods | 195 | 26 |
|
| 656 |
+
| `def …!` bang methods | 10 | 0 |
|
| 657 |
+
|
| 658 |
+
**What the census says:**
|
| 659 |
+
|
| 660 |
+
- The codebase already leans AED: guard returns (120 across both repos) far
|
| 661 |
+
outnumber loops (14); typed raises outnumber string raises 10:1; there are
|
| 662 |
+
195 `?` predicates in the template — the "name the question" culture exists.
|
| 663 |
+
- `case … in`, `until`, `retry`, and concurrency `select` occur **zero**
|
| 664 |
+
times. We can codify their status cheaply — banning what nobody uses costs
|
| 665 |
+
nothing and stops an agent from introducing them.
|
| 666 |
+
- The high-frequency gaps that need real rules: `case/when` menus (28+3
|
| 667 |
+
sites), guard ordering (120 guard returns with no stated ordering rule),
|
| 668 |
+
`unless` (175 total uses, some compound), `.try` (98 uses — the single
|
| 669 |
+
biggest "decode a chain" risk), and bare `rescue` (a large share of the 65
|
| 670 |
+
rescues carry no error name).
|
| 671 |
+
- The website's markdown parser is a legitimate **cursor-loop** cluster
|
| 672 |
+
(8 `while` + 12 `break` in one file family) — the loop rule must bless that
|
| 673 |
+
shape, not fight it.
|
| 674 |
+
|
| 675 |
+
---
|
| 676 |
+
|
| 677 |
+
### The core insight: mechanism syntax vs statement syntax
|
| 678 |
+
|
| 679 |
+
The existing skill's rule — *prefer the form that reads like a plain statement
|
| 680 |
+
of intent* — works effortlessly for **expressions**: you pick the spelling
|
| 681 |
+
that reads best. Control flow is different. `while`, `rescue`, `spawn`,
|
| 682 |
+
`{% if %}` are **mechanism keywords**: they say *how* execution moves, never
|
| 683 |
+
*why*. No amount of re-spelling makes `while @i < @lines.size` state an
|
| 684 |
+
intent.
|
| 685 |
+
|
| 686 |
+
So for control flow, AED shifts from "pick the readable spelling" to three
|
| 687 |
+
compensating moves, in priority order:
|
| 688 |
+
|
| 689 |
+
1. **Name the intent next to the mechanism** — the condition is a named
|
| 690 |
+
predicate, the body is a named method, the error is a named type, the
|
| 691 |
+
fiber does a named job.
|
| 692 |
+
2. **Keep the mechanism in one canonical shape** — one blessed way to write
|
| 693 |
+
each construct, so a reader (or a linting hook) recognizes it instantly.
|
| 694 |
+
3. **Ban the shapes that only ever obscure** — the census shows we already
|
| 695 |
+
live without them.
|
| 696 |
+
|
| 697 |
+
Every rule below is one of those three moves. Format per rule: (a) why the
|
| 698 |
+
raw syntax fights the reading rule, (b) the proposed rule with a crisp name,
|
| 699 |
+
(c) before/after in the skill's voice, (d) the honest cost, (e) the
|
| 700 |
+
mechanical check an agent, linter, or hook can apply.
|
| 701 |
+
|
| 702 |
+
---
|
| 703 |
+
|
| 704 |
+
### Rule CF-1. `case` is a menu — every branch one bite
|
| 705 |
+
|
| 706 |
+
**(a) Why the syntax fights the rule.** A `case` on a *value* (`case action`,
|
| 707 |
+
`case fmt`, `case status_code`) is actually the closest control flow gets to
|
| 708 |
+
a plain statement — *"depending on the action: …"*. It stops reading like a
|
| 709 |
+
statement in exactly two ways: when a branch body grows into a paragraph (the
|
| 710 |
+
reader loses the menu and falls into one dish), and when the subject is an
|
| 711 |
+
expression the reader must evaluate first (`case ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase`).
|
| 712 |
+
|
| 713 |
+
**(b) Proposed rule — "Case is a menu, not a novel."**
|
| 714 |
+
Use `case … when` when branching a **single named value** across **three or
|
| 715 |
+
more** outcomes. Two outcomes is an `if/else` (a menu of two is just a
|
| 716 |
+
choice). Each `when` body is at most ~3 lines or a single named method call —
|
| 717 |
+
if a branch needs a paragraph, extract it to a method whose name is the
|
| 718 |
+
branch's intent. The `case` subject must be a **named local or a plain
|
| 719 |
+
method call**, never an inline expression chain. Always write an explicit
|
| 720 |
+
`else` that states the fallback (`false`, `raise`, or a named default) —
|
| 721 |
+
Crystal's `when` is not exhaustive, so the `else` is where you *say* what
|
| 722 |
+
happens to the unlisted world. `case … in` stays banned per existing Rule 1
|
| 723 |
+
(census: zero uses — nothing to migrate).
|
| 724 |
+
|
| 725 |
+
**(c) Before/after.**
|
| 726 |
+
|
| 727 |
+
```crystal
|
| 728 |
+
# ✅ AED — a menu: named subject, one bite per branch, spoken fallback
|
| 729 |
+
default_provider = ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase
|
| 730 |
+
case default_provider
|
| 731 |
+
when "anthropic" then Anthropic::Client.new
|
| 732 |
+
when "openai" then OpenAI::Client.new
|
| 733 |
+
else raise "Unknown AI_DEFAULT_PROVIDER: #{default_provider}"
|
| 734 |
+
end
|
| 735 |
+
|
| 736 |
+
# 🚫 subject is a puzzle the reader must evaluate before the menu even starts
|
| 737 |
+
case ENV["AI_DEFAULT_PROVIDER"]?.to_s.downcase
|
| 738 |
+
when "anthropic" then ...
|
| 739 |
+
end
|
| 740 |
+
|
| 741 |
+
# 🚫 a two-item "menu" — this is just an if wearing a costume
|
| 742 |
+
case backend
|
| 743 |
+
when :smtp then deliver_smtp(message)
|
| 744 |
+
else deliver_log(message)
|
| 745 |
+
end
|
| 746 |
+
# ✅ instead:
|
| 747 |
+
if backend == :smtp
|
| 748 |
+
deliver_smtp(message)
|
| 749 |
+
else
|
| 750 |
+
deliver_log(message)
|
| 751 |
+
end
|
| 752 |
+
```
|
| 753 |
+
|
| 754 |
+
The policy classes are the house exemplar already
|
| 755 |
+
(`src/policies/team_policy.cr`): `case action` with one-line branches
|
| 756 |
+
composed of `?` predicates (`team_lead? || admin_access?`) and `else false`.
|
| 757 |
+
That file reads like an access-control table — which is the point.
|
| 758 |
+
|
| 759 |
+
**(d) Cost.** Extracting fat branches adds methods; a reader who wants the
|
| 760 |
+
details takes one hop. Two-branch `case` fans will find the if/else rule
|
| 761 |
+
fussy. Accepted: the menu shape is only worth its visual weight when there is
|
| 762 |
+
an actual menu.
|
| 763 |
+
|
| 764 |
+
**(e) Mechanical check.** Flag: `case` whose subject line contains `.` more
|
| 765 |
+
than once or any `?.`/`ENV[`; any `when` body exceeding 3 lines; any `case`
|
| 766 |
+
with fewer than 3 `when` branches; any `case` without `else`; any `case … in`
|
| 767 |
+
(already caught by the compile hook on Grant types — extend to a grep ban).
|
| 768 |
+
|
| 769 |
+
---
|
| 770 |
+
|
| 771 |
+
### Rule CF-2. Loops state their finish line
|
| 772 |
+
|
| 773 |
+
**(a) Why the syntax fights the rule.** `while` states a *continuation
|
| 774 |
+
condition*, but a reader thinks in terms of a *finish line* ("keep going
|
| 775 |
+
until the lines run out"). Worse, `loop do … break` scatters the finish line
|
| 776 |
+
into the body, and an index cursor (`@i`) makes progress invisible — the
|
| 777 |
+
reader must verify the loop advances or they can't trust it terminates.
|
| 778 |
+
|
| 779 |
+
**(b) Proposed rule — "Every loop names its finish line and shows its
|
| 780 |
+
step."** Three blessed loop shapes, nothing else:
|
| 781 |
+
|
| 782 |
+
1. **Collection walk** — `items.each do |item|` (default; covers most needs).
|
| 783 |
+
2. **Cursor loop** — `while cursor_has_more?` over an explicit cursor, where
|
| 784 |
+
(i) the condition is a plain comparison or a named `?` predicate, (ii)
|
| 785 |
+
every `break` inside is a one-line guard whose condition is a named
|
| 786 |
+
predicate or plain comparison, and (iii) the cursor visibly advances in
|
| 787 |
+
the body (an `@i += n` a reader can point at). This blesses the website's
|
| 788 |
+
markdown parser shape (`while @i < @lines.size` … `break unless row?(s)` —
|
| 789 |
+
`article_markdown.cr` already complies, its break conditions are named
|
| 790 |
+
predicates like `ordered_item?`, `task_item?`, `row?`).
|
| 791 |
+
3. **Forever loop** — `loop do` only for intentionally unbounded work (the
|
| 792 |
+
SSE heartbeat in `mcp_sse_controller.cr`), and it must sit inside a method
|
| 793 |
+
whose **name says it loops** (`run_heartbeat_loop`, `pump_stdout`), with
|
| 794 |
+
its exit spelled as a guard (`break if client_disconnected?`).
|
| 795 |
+
|
| 796 |
+
If a loop body exceeds ~8 lines, extract the body to a method named for one
|
| 797 |
+
iteration's intent (`consume_blockquote`, `emit_table_row`) — the loop line
|
| 798 |
+
then reads *"while there are lines, consume the next block."*
|
| 799 |
+
`until` is **banned** (census: zero uses): `until done?` forces the reader to
|
| 800 |
+
negate in their head; write `while more?`.
|
| 801 |
+
|
| 802 |
+
**(c) Before/after.**
|
| 803 |
+
|
| 804 |
+
```crystal
|
| 805 |
+
# ✅ AED — cursor loop: named finish line, named break, visible step
|
| 806 |
+
while @i < @lines.size
|
| 807 |
+
line = @lines[@i].strip
|
| 808 |
+
break unless ordered_item?(line)
|
| 809 |
+
emit_ordered_item(line)
|
| 810 |
+
@i += 1
|
| 811 |
+
end
|
| 812 |
+
|
| 813 |
+
# 🚫 the finish line is a negation the reader must invert
|
| 814 |
+
until @i >= @lines.size
|
| 815 |
+
...
|
| 816 |
+
end
|
| 817 |
+
|
| 818 |
+
# 🚫 forever-loop with an anonymous job and a buried exit
|
| 819 |
+
loop do
|
| 820 |
+
sleep 15.seconds
|
| 821 |
+
begin
|
| 822 |
+
send_event(response, "ping", {time: Time.utc.to_unix})
|
| 823 |
+
rescue
|
| 824 |
+
break
|
| 825 |
+
end
|
| 826 |
+
end
|
| 827 |
+
# ✅ instead: the method name carries the loop's intent
|
| 828 |
+
private def run_heartbeat_loop(response) : Nil
|
| 829 |
+
loop do
|
| 830 |
+
sleep 15.seconds
|
| 831 |
+
break unless send_ping(response) # returns false when the client is gone
|
| 832 |
+
end
|
| 833 |
+
end
|
| 834 |
+
```
|
| 835 |
+
|
| 836 |
+
**(d) Cost.** Extraction adds one hop per fat loop; the "visible step" rule
|
| 837 |
+
occasionally forces an `@i += 1` where a cleverer restructure could avoid the
|
| 838 |
+
cursor entirely. Accepted: termination you can point at beats elegance you
|
| 839 |
+
must simulate.
|
| 840 |
+
|
| 841 |
+
**(e) Mechanical check.** Flag: any `until`; any `loop do` in a method whose
|
| 842 |
+
name lacks `loop`/`pump`/`watch`/`poll`; any `while` body > 8 lines; any
|
| 843 |
+
`break` followed by a compound condition (`&&`/`||` on the same line); a
|
| 844 |
+
`while i <`-style loop whose body never reassigns the cursor variable.
|
| 845 |
+
|
| 846 |
+
---
|
| 847 |
+
|
| 848 |
+
### Rule CF-3. Guards are the bouncer — they stand at the door
|
| 849 |
+
|
| 850 |
+
**(a) Why the syntax fights the rule.** An early `return` is invisible in
|
| 851 |
+
prose: a non-technical reader scanning top-to-bottom doesn't naturally know
|
| 852 |
+
that `return nil unless key` means *everything below assumes a key exists*.
|
| 853 |
+
Guards scattered mid-method are worse — the story keeps getting interrupted
|
| 854 |
+
by exits the reader has to fold into their mental state.
|
| 855 |
+
|
| 856 |
+
**(b) Proposed rule — "Guards first, story second."** Guard clauses (already
|
| 857 |
+
the house majority style — 120 guard returns across both repos, and existing
|
| 858 |
+
Rule 3 prefers them) get an *ordering and shape* contract:
|
| 859 |
+
|
| 860 |
+
- All precondition guards sit in a **contiguous block at the top** of the
|
| 861 |
+
method, before the first line of the happy path. A reader — technical or
|
| 862 |
+
not — reads them as a doorman's checklist: *"no ticket, no entry; wrong
|
| 863 |
+
tag, no entry."* Everything after the blank line is the story with all
|
| 864 |
+
assumptions established.
|
| 865 |
+
- One guard per line, one idea per guard. A guard's condition is a plain
|
| 866 |
+
comparison, a named predicate, or a single nil-check — never a compound
|
| 867 |
+
needing parentheses (extract to a `?` method, see CF-8).
|
| 868 |
+
- A `return` *after* the story has started is allowed only when it is the
|
| 869 |
+
method's **answer** (the natural end of a branch), not a late-discovered
|
| 870 |
+
precondition. If you discover a precondition mid-story, either hoist it or
|
| 871 |
+
extract the remainder into a method with its own door.
|
| 872 |
+
- Guards that reject for a *reason worth documenting* say why on the line
|
| 873 |
+
above (`# CSRF: state must match what we issued`), per existing Rule 5.
|
| 874 |
+
|
| 875 |
+
`src/wire/cose.cr` is the exemplar: five `return nil unless …` guards in a
|
| 876 |
+
row, then the single decrypt statement — the shape *is* the security
|
| 877 |
+
argument.
|
| 878 |
+
|
| 879 |
+
**(c) Before/after.**
|
| 880 |
+
|
| 881 |
+
```crystal
|
| 882 |
+
# ✅ AED — the bouncer's checklist, then the story
|
| 883 |
+
def verify_password(password : String) : self?
|
| 884 |
+
return nil if password_digest.empty?
|
| 885 |
+
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 886 |
+
|
| 887 |
+
self
|
| 888 |
+
end
|
| 889 |
+
|
| 890 |
+
# 🚫 nested ifs — the reader carries open questions to the last line
|
| 891 |
+
def verify_password(password : String) : self?
|
| 892 |
+
unless password_digest.empty?
|
| 893 |
+
if Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 894 |
+
self
|
| 895 |
+
end
|
| 896 |
+
end
|
| 897 |
+
end
|
| 898 |
+
|
| 899 |
+
# 🚫 a precondition ambushing the reader mid-story
|
| 900 |
+
def publish(article)
|
| 901 |
+
html = render(article)
|
| 902 |
+
return if article.draft? # ← this belonged at the door
|
| 903 |
+
upload(html)
|
| 904 |
+
end
|
| 905 |
+
```
|
| 906 |
+
|
| 907 |
+
**(d) Cost.** Hoisting sometimes evaluates a guard slightly earlier than
|
| 908 |
+
strictly needed (rarely matters; note it when it does). Multiple exit points
|
| 909 |
+
still bother single-exit purists — AED sides with the checklist reader.
|
| 910 |
+
|
| 911 |
+
**(e) Mechanical check.** Flag: a `return … if/unless` guard appearing after
|
| 912 |
+
the first non-guard, non-comment statement of a method (heuristic: guard
|
| 913 |
+
lines must be a prefix of the method body); any guard condition containing
|
| 914 |
+
`&&`/`||` (send to CF-8); nesting depth > 2 inside a method that has no
|
| 915 |
+
guards (suggests inversion is available).
|
| 916 |
+
|
| 917 |
+
---
|
| 918 |
+
|
| 919 |
+
### Rule CF-4. `unless` carries one positive idea
|
| 920 |
+
|
| 921 |
+
**(a) Why the syntax fights the rule.** `unless` reads beautifully as an
|
| 922 |
+
English exception — *"return nil unless the state matches"* — right up until
|
| 923 |
+
the condition contains logic. `unless a && b` requires De Morgan in the
|
| 924 |
+
reader's head ("so it runs when… a is false, OR b is false…"). The census
|
| 925 |
+
shows 175 total `unless` uses; most are clean guards, but sites like
|
| 926 |
+
`unless key.algorithm == ES256 && key.curve == P256` (`webauthn/verifier.cr`)
|
| 927 |
+
cross the line.
|
| 928 |
+
|
| 929 |
+
**(b) Proposed rule — "`unless` takes one idea."**
|
| 930 |
+
`unless` (postfix or block) may wrap **one positive condition**: a single
|
| 931 |
+
predicate call, a single comparison, or a single presence check. Never
|
| 932 |
+
`unless` with `&&`, `||`, or `!`; never `unless … else` (Crystal allows it;
|
| 933 |
+
AED bans it outright — an inverted two-branch is an `if` written backwards).
|
| 934 |
+
Compound conditions get a named `?` predicate first, then `unless` may carry
|
| 935 |
+
the name. `until` is covered (banned) by CF-2 — same negation tax.
|
| 936 |
+
|
| 937 |
+
**(c) Before/after.**
|
| 938 |
+
|
| 939 |
+
```crystal
|
| 940 |
+
# ✅ AED — name the compound, then the exception reads like English
|
| 941 |
+
def es256_key?(key) : Bool
|
| 942 |
+
key.algorithm == COSE::Algorithm::ES256 && key.curve == COSE::EC2Curve::P256
|
| 943 |
+
end
|
| 944 |
+
raise Error.new("expected an ES256 key") unless es256_key?(key)
|
| 945 |
+
|
| 946 |
+
# 🚫 the reader must run De Morgan to know when this fires
|
| 947 |
+
unless key.algorithm == COSE::Algorithm::ES256 && key.curve == COSE::EC2Curve::P256
|
| 948 |
+
raise Error.new("expected an ES256 key")
|
| 949 |
+
end
|
| 950 |
+
|
| 951 |
+
# 🚫 unless/else — an if, written in a mirror
|
| 952 |
+
unless info.email_verified
|
| 953 |
+
reject_signup
|
| 954 |
+
else
|
| 955 |
+
create_account
|
| 956 |
+
end
|
| 957 |
+
```
|
| 958 |
+
|
| 959 |
+
**(d) Cost.** One extra tiny method per compound; occasionally a predicate
|
| 960 |
+
used exactly once. Accepted: the predicate name doubles as documentation and
|
| 961 |
+
as a doc heading (see §Docs).
|
| 962 |
+
|
| 963 |
+
**(e) Mechanical check.** Flag: `unless` on a line containing `&&`, `||`, or
|
| 964 |
+
` !`; any `unless … else`; any `until`. All three are plain greps — ideal
|
| 965 |
+
hook material.
|
| 966 |
+
|
| 967 |
+
---
|
| 968 |
+
|
| 969 |
+
### Rule CF-5. Ternary picks between two spellings of one value
|
| 970 |
+
|
| 971 |
+
**(a) Why the syntax fights the rule.** A ternary compresses a branch into a
|
| 972 |
+
breath. That's fine when both arms are *values of the same idea*
|
| 973 |
+
(`success ? "info" : "warning"`), because the reader parses it as one noun
|
| 974 |
+
with two spellings. It fights the rule the moment an arm contains a call
|
| 975 |
+
with effects, another `?`, or the arms are different *actions* — then the
|
| 976 |
+
reader is executing code inside a noun slot.
|
| 977 |
+
|
| 978 |
+
**(b) Proposed rule — "Ternary is a value with two spellings, and it gets a
|
| 979 |
+
name."** A ternary is allowed only when **all** hold: both arms are simple
|
| 980 |
+
values (literal, variable, or a single pure call); no nesting; no side
|
| 981 |
+
effects; and the result is immediately **named** — assigned to a variable or
|
| 982 |
+
passed as a named/keyword argument whose name states what it is. Choosing
|
| 983 |
+
between two *actions* is always an `if/else`. Existing Rule 3's ban on
|
| 984 |
+
nested ternaries is subsumed here.
|
| 985 |
+
|
| 986 |
+
**(c) Before/after.**
|
| 987 |
+
|
| 988 |
+
```crystal
|
| 989 |
+
# ✅ AED — one noun, two spellings, and the noun is named at the call site
|
| 990 |
+
severity: success ? "info" : "warning",
|
| 991 |
+
|
| 992 |
+
# ✅ AED — named result
|
| 993 |
+
byte_length = curve == OKPCurve::Ed25519 ? 32 : 57
|
| 994 |
+
|
| 995 |
+
# 🚫 two different actions crammed into a noun slot
|
| 996 |
+
logged_in? ? render_dashboard : redirect_to_login
|
| 997 |
+
|
| 998 |
+
# 🚫 arms with their own lookups and fallbacks (real shape from icon_component.cr)
|
| 999 |
+
path = name ? (ICONS[name]? || "") : (@attributes["path"]? || "")
|
| 1000 |
+
# ✅ instead: the branch is a decision — write it as one
|
| 1001 |
+
if name
|
| 1002 |
+
path = ICONS[name]? || ""
|
| 1003 |
+
else
|
| 1004 |
+
path = @attributes["path"]? || ""
|
| 1005 |
+
end
|
| 1006 |
+
```
|
| 1007 |
+
|
| 1008 |
+
**(d) Cost.** Some three-line `if`s where a one-liner "worked". Accepted:
|
| 1009 |
+
the one-liner worked for the author; the `if` works for the reader.
|
| 1010 |
+
|
| 1011 |
+
**(e) Mechanical check.** Flag: a line matching the ternary shape that also
|
| 1012 |
+
contains a second `?`-operator (nesting), a `!`-suffixed call, `<<`, `=`
|
| 1013 |
+
inside an arm, or arms containing `(…)` with further calls; ternaries whose
|
| 1014 |
+
result is not assigned or passed as an argument.
|
| 1015 |
+
|
| 1016 |
+
---
|
| 1017 |
+
|
| 1018 |
+
### Rule CF-6. Chains read like a sentence or get named waypoints
|
| 1019 |
+
|
| 1020 |
+
**(a) Why the syntax fights the rule.** `users.select(&.active?).map(&.email)`
|
| 1021 |
+
*is* a sentence — "take the active users' emails." The syntax stops
|
| 1022 |
+
cooperating when a link needs a multi-line block, when a `.try` hides a nil
|
| 1023 |
+
branch mid-chain, or when link three depends on remembering what link one
|
| 1024 |
+
produced. At that point the chain is a pipeline the reader must trace, not a
|
| 1025 |
+
sentence they can hear. The census makes `.try` the sharpest instance: 98
|
| 1026 |
+
uses in the template, many nested (`data["mail"]?.try(&.as_s) || …`), versus
|
| 1027 |
+
only ~50 collection-chain links total.
|
| 1028 |
+
|
| 1029 |
+
**(b) Proposed rule — "Two links spoken, three links named."**
|
| 1030 |
+
|
| 1031 |
+
- A chain may have up to **two transformation links**, each in `&.method`
|
| 1032 |
+
shorthand, when it reads aloud as one sentence.
|
| 1033 |
+
- Three or more links, or **any** multi-line `do … end` block mid-chain, or
|
| 1034 |
+
any link whose output type isn't obvious from its name → break the chain
|
| 1035 |
+
with **named waypoints**: intermediate variables named for *what the data
|
| 1036 |
+
is at that point* (`active_users`, `member_emails`), not for the operation
|
| 1037 |
+
(`filtered`, `mapped`, `result2`).
|
| 1038 |
+
- `.each` (side effects) never follows transformation links in the same
|
| 1039 |
+
chain — name the collection first, then iterate it. A reader distinguishes
|
| 1040 |
+
"computing" from "doing" by the line break.
|
| 1041 |
+
- `.try` chains: **one `.try` maximum per expression**, and only the
|
| 1042 |
+
`&.method` shorthand form. Two `.try`s, a `.try` with a block containing
|
| 1043 |
+
logic, or `.try` feeding `||` feeding `.try` → rewrite as an explicit
|
| 1044 |
+
nil-check guard or an `if value = expr` assignment-condition. (This
|
| 1045 |
+
restates existing Rule 2 with a hard threshold.)
|
| 1046 |
+
|
| 1047 |
+
**(c) Before/after.**
|
| 1048 |
+
|
| 1049 |
+
```crystal
|
| 1050 |
+
# ✅ AED — two links, one sentence
|
| 1051 |
+
member_emails = users.select(&.active?).map(&.email)
|
| 1052 |
+
|
| 1053 |
+
# ✅ AED — waypoints named for what the data IS
|
| 1054 |
+
oauth_accounts = accounts.select(&.oauth?)
|
| 1055 |
+
verified_emails = oauth_accounts.map(&.email).select(&.verified?)
|
| 1056 |
+
verified_emails.each { |email| enqueue_welcome(email) }
|
| 1057 |
+
|
| 1058 |
+
# 🚫 the reader holds three intermediate shapes in their head, then side-effects
|
| 1059 |
+
accounts.select(&.oauth?).map(&.email).select(&.verified?).each { |e| enqueue_welcome(e) }
|
| 1060 |
+
|
| 1061 |
+
# 🚫 nested try-fallback — three nil-branches hidden in one line (real shape, microsoft.cr)
|
| 1062 |
+
email = data["mail"]?.try(&.as_s) || data["userPrincipalName"]?.try(&.as_s) || ""
|
| 1063 |
+
# ✅ instead: each source named, the preference order visible as lines
|
| 1064 |
+
primary_email = data["mail"]?.try(&.as_s)
|
| 1065 |
+
fallback_email = data["userPrincipalName"]?.try(&.as_s)
|
| 1066 |
+
email = primary_email || fallback_email || ""
|
| 1067 |
+
```
|
| 1068 |
+
|
| 1069 |
+
**(d) Cost.** More lines and more locals; hot paths allocate an intermediate
|
| 1070 |
+
array per waypoint (if profiling ever shows it matters, note the exception
|
| 1071 |
+
with a *why* comment per existing Rule 5). Accepted: this codebase reads far
|
| 1072 |
+
more than it iterates.
|
| 1073 |
+
|
| 1074 |
+
**(e) Mechanical check.** Flag: ≥3 `.method(` / `&.` links on one expression;
|
| 1075 |
+
`.each` preceded by `.map`/`.select`/`.reject` in the same statement; ≥2
|
| 1076 |
+
`.try` in one expression; `.try do` block form; waypoint variables named
|
| 1077 |
+
`result`, `tmp`, `filtered`, `x2` (existing Rule 4's list, extended).
|
| 1078 |
+
|
| 1079 |
+
---
|
| 1080 |
+
|
| 1081 |
+
### Rule CF-7. Errors are vocabulary; rescues say what they forgive
|
| 1082 |
+
|
| 1083 |
+
**(a) Why the syntax fights the rule.** `begin/rescue` reads like nothing at
|
| 1084 |
+
all: a bare `rescue` is the statement *"if anything whatsoever goes wrong,
|
| 1085 |
+
do this"* — which is almost never what the author meant and never what the
|
| 1086 |
+
reader can verify. Exception flow is invisible control flow: the jump happens
|
| 1087 |
+
on a line the reader can't see. The only way it reads like a statement is if
|
| 1088 |
+
the **error type carries the sentence**. The census shows the raising side
|
| 1089 |
+
already speaks: 138 typed raises vs 14 string raises, and a real error
|
| 1090 |
+
vocabulary exists (`WebAuthn::Registration::UnsupportedAttestation`,
|
| 1091 |
+
`Storage::FileNotFoundError`, `Authorization::…`). The rescuing side lags:
|
| 1092 |
+
a large share of the 65 rescues are bare.
|
| 1093 |
+
|
| 1094 |
+
**(b) Proposed rule — "Raise nouns, rescue by name."**
|
| 1095 |
+
|
| 1096 |
+
- **Raising**: always a typed error from the domain vocabulary; new failure
|
| 1097 |
+
modes mint a new subclass under the module's base `Error` (the house
|
| 1098 |
+
pattern: `class Error < Exception` per module, specific subclasses under
|
| 1099 |
+
it). A bare `raise "string"` is allowed only for
|
| 1100 |
+
configuration-impossible states at boot (`"ANTHROPIC_API_KEY required"`).
|
| 1101 |
+
- **Rescuing**: `rescue ex : SpecificError` naming the narrowest type that
|
| 1102 |
+
states what you forgive. A broad `rescue ex` is permitted only at
|
| 1103 |
+
**boundaries** — the outermost edge of a request, a fiber, a mailer
|
| 1104 |
+
delivery, a worker — and must (i) bind `ex`, (ii) log or report it, and
|
| 1105 |
+
(iii) carry a *why* comment stating the boundary ("mailer must never take
|
| 1106 |
+
the request down with it"). A bare `rescue` with no binding and no comment
|
| 1107 |
+
is banned.
|
| 1108 |
+
- **Postfix `rescue nil`** only around a *single parse/convert expression*
|
| 1109 |
+
where nil is the honest answer (`Time.parse_rfc2822(date) rescue nil` —
|
| 1110 |
+
the two existing uses both qualify). Never around a call with side effects.
|
| 1111 |
+
- **`ensure`** is for cleanup only (close, unlink, reset) — never business
|
| 1112 |
+
logic; if an `ensure` grows past ~3 lines, extract it to a named cleanup
|
| 1113 |
+
method (`ensure … close_worker_pipes`).
|
| 1114 |
+
- **`retry`** (census: zero) is banned in its raw form; retrying is a policy,
|
| 1115 |
+
so it must live in a method named for it (`with_retries(attempts: 3) do`)
|
| 1116 |
+
that owns the counter and backoff — a raw `retry` is an unbounded loop
|
| 1117 |
+
wearing an exception costume.
|
| 1118 |
+
|
| 1119 |
+
**(c) Before/after.**
|
| 1120 |
+
|
| 1121 |
+
```crystal
|
| 1122 |
+
# ✅ AED — the rescue states exactly what it forgives, and why
|
| 1123 |
+
def find_verified(token : String) : Users::Regular?
|
| 1124 |
+
payload = decode_session_token(token)
|
| 1125 |
+
Users::Regular.find(payload.user_id)
|
| 1126 |
+
rescue JWT::ExpiredSignatureError
|
| 1127 |
+
# Expired session is a normal event, not an error: the caller re-authenticates.
|
| 1128 |
+
nil
|
| 1129 |
+
end
|
| 1130 |
+
|
| 1131 |
+
# 🚫 forgives everything — a typo in decode_session_token now returns nil forever
|
| 1132 |
+
def find_verified(token : String) : Users::Regular?
|
| 1133 |
+
Users::Regular.find(decode_session_token(token).user_id)
|
| 1134 |
+
rescue
|
| 1135 |
+
nil
|
| 1136 |
+
end
|
| 1137 |
+
|
| 1138 |
+
# ✅ AED — broad rescue earns its breadth at a boundary, with the why on record
|
| 1139 |
+
spawn do
|
| 1140 |
+
run_heartbeat_loop(response)
|
| 1141 |
+
rescue ex
|
| 1142 |
+
# Boundary: a dead client must never crash the server fiber pool.
|
| 1143 |
+
Log.warn(exception: ex) { "SSE heartbeat fiber exited" }
|
| 1144 |
+
end
|
| 1145 |
+
```
|
| 1146 |
+
|
| 1147 |
+
**(d) Cost.** Naming narrow error types takes real thought (what *can* this
|
| 1148 |
+
raise?), and Crystal won't tell you — there are no checked exceptions.
|
| 1149 |
+
Sometimes you'll name two types where a bare rescue was one word. Accepted:
|
| 1150 |
+
that thought is precisely the documentation the next agent needs; a bare
|
| 1151 |
+
rescue is a claim of omniscience.
|
| 1152 |
+
|
| 1153 |
+
**(e) Mechanical check.** Flag: `rescue` at end-of-line or `rescue$` with no
|
| 1154 |
+
type and no `ex` binding; `rescue ex` (untyped) with no comment within 2
|
| 1155 |
+
lines; `raise "` outside `config/`/boot files; any `retry` keyword; `ensure`
|
| 1156 |
+
blocks > 3 lines; postfix `rescue nil` on a line containing `save`/`create`/
|
| 1157 |
+
`delete`/`<<`/`=` (side-effect heuristic).
|
| 1158 |
+
|
| 1159 |
+
---
|
| 1160 |
+
|
| 1161 |
+
### Rule CF-8. Three ands make a question method
|
| 1162 |
+
|
| 1163 |
+
**(a) Why the syntax fights the rule.** Boolean operators are the one place
|
| 1164 |
+
where "statement-like" degrades *gradually*: `a && b` still reads, `a && b || c && !d`
|
| 1165 |
+
is a logic puzzle. The reader shouldn't need parentheses skills to know when
|
| 1166 |
+
a branch fires. The template's 195 `?` methods prove the extraction habit
|
| 1167 |
+
exists — this rule just fixes the threshold.
|
| 1168 |
+
|
| 1169 |
+
**(b) Proposed rule — "Two operators is a sentence; three is a method."**
|
| 1170 |
+
A condition (in `if`, `unless`, `while`, a guard, or a ternary) may contain
|
| 1171 |
+
at most **two** boolean operators, and never a *mix* of `&&` and `||`
|
| 1172 |
+
without extraction — a mix means precedence, and precedence means the
|
| 1173 |
+
reader is parsing, not reading. Beyond that, extract either a **`?` question
|
| 1174 |
+
method** (when the concept recurs or belongs to the object:
|
| 1175 |
+
`team_lead?`, `es256_key?`) or a **named `Bool` local** (when it's one-off
|
| 1176 |
+
and built from locals: `state_matches = …`). The name must be the *positive*
|
| 1177 |
+
form of the question — no `not_invalid?`.
|
| 1178 |
+
|
| 1179 |
+
**(c) Before/after.**
|
| 1180 |
+
|
| 1181 |
+
```crystal
|
| 1182 |
+
# ✅ AED — the condition IS the sentence
|
| 1183 |
+
if oauth_callback_valid?(provider, expected_state, state, code)
|
| 1184 |
+
...
|
| 1185 |
+
|
| 1186 |
+
private def oauth_callback_valid?(provider, expected_state, state, code) : Bool
|
| 1187 |
+
return false unless provider && expected_state && state && code
|
| 1188 |
+
constant_time_equal?(expected_state, state)
|
| 1189 |
+
end
|
| 1190 |
+
|
| 1191 |
+
# 🚫 four conditions and a continuation line — a parser test, not a sentence
|
| 1192 |
+
unless provider && expected_state && state && code &&
|
| 1193 |
+
constant_time_equal?(expected_state, state)
|
| 1194 |
+
...
|
| 1195 |
+
|
| 1196 |
+
# ✅ AED — mixed operators earn a named local even at only three terms
|
| 1197 |
+
signature_acceptable = algorithm.rs? || algorithm.ps?
|
| 1198 |
+
return unless signature_acceptable && key_present?
|
| 1199 |
+
```
|
| 1200 |
+
|
| 1201 |
+
**(d) Cost.** Method count grows; a hostile reviewer can call `?` methods
|
| 1202 |
+
"indirection". Accepted — with one honest caveat: the extracted name must
|
| 1203 |
+
truly summarize, or you've hidden the puzzle behind a label. Bad name = worse
|
| 1204 |
+
than inline. Naming quality falls to existing Rule 4.
|
| 1205 |
+
|
| 1206 |
+
**(e) Mechanical check.** Flag: any condition line with ≥3 of (`&&`, `||`);
|
| 1207 |
+
any condition mixing `&&` and `||`; any `if`/`unless`/`while` condition
|
| 1208 |
+
spilling to a continuation line; predicate names starting `not_`/`no_`.
|
| 1209 |
+
|
| 1210 |
+
---
|
| 1211 |
+
|
| 1212 |
+
### Rule CF-9. Every fiber gets a job title
|
| 1213 |
+
|
| 1214 |
+
**(a) Why the syntax fights the rule.** Concurrency breaks the deepest
|
| 1215 |
+
assumption of statement-reading: that the next line happens next. `spawn do`
|
| 1216 |
+
means "meanwhile, elsewhere" — and an anonymous block gives the reader no
|
| 1217 |
+
noun to hold on to while the main story continues. Channels are worse:
|
| 1218 |
+
`ch.receive` is a sentence missing its subject (*receive what, from whom?*).
|
| 1219 |
+
The census says our exposure is small (4 spawns, 1 channel, 0 `select`) but
|
| 1220 |
+
the two real sites (`isolated_worker.cr`, `mcp_sse_controller.cr`) are
|
| 1221 |
+
exactly the hardest code in the template — small count, maximal reader risk.
|
| 1222 |
+
|
| 1223 |
+
**(b) Proposed rule — "Meanwhile, the *named* worker does its *named* job."**
|
| 1224 |
+
|
| 1225 |
+
- Every `spawn` body is a **single call to a named method** whose name is
|
| 1226 |
+
the fiber's job (`spawn { pump_input_to_child(in_writer, input, writer_done) }`,
|
| 1227 |
+
`spawn { run_heartbeat_loop(response) }`). Never an inline multi-line
|
| 1228 |
+
block: the reader should meet a fiber the way they meet an employee — by
|
| 1229 |
+
title — and only read the job description if they choose to. Crystal's
|
| 1230 |
+
`spawn(name: "heartbeat")` is encouraged in addition (it labels runtime
|
| 1231 |
+
diagnostics) but the method name is the load-bearing part.
|
| 1232 |
+
- Every `Channel` variable is named for its **cargo and direction**
|
| 1233 |
+
(`writer_done`, `parsed_events`, `shutdown_requested`) — the existing
|
| 1234 |
+
`writer_done = Channel(Exception?).new(1)` is the exemplar. Bare `ch`
|
| 1235 |
+
banned.
|
| 1236 |
+
- A `.receive` reads as *"wait for the writer to be done"* only if the line
|
| 1237 |
+
says so: `writer_error = writer_done.receive`.
|
| 1238 |
+
- Concurrency `select` (census: zero): when it arrives, each branch must be
|
| 1239 |
+
a one-line guard-style clause calling a named method — same menu
|
| 1240 |
+
discipline as CF-1.
|
| 1241 |
+
- Every fiber body's outermost layer is a boundary rescue per CF-7 — a fiber
|
| 1242 |
+
that dies silently is control flow the reader can never follow.
|
| 1243 |
+
|
| 1244 |
+
*How a statement-reader follows concurrent flow under this rule:* the main
|
| 1245 |
+
story reads linearly and each `spawn` line reads as a one-sentence aside —
|
| 1246 |
+
"meanwhile, pump input to the child" — and each `receive` reads as
|
| 1247 |
+
"wait here for X." The reader never has to interleave two instruction
|
| 1248 |
+
streams; they follow one story with named waypoints where the streams touch.
|
| 1249 |
+
|
| 1250 |
+
**(c) Before/after.**
|
| 1251 |
+
|
| 1252 |
+
```crystal
|
| 1253 |
+
# ✅ AED — the aside has a title; the join point says what it waits for
|
| 1254 |
+
writer_done = Channel(Exception?).new(1)
|
| 1255 |
+
spawn { pump_input_to_child(in_writer, input, writer_done) }
|
| 1256 |
+
output = drain_child_output(out_reader)
|
| 1257 |
+
writer_error = writer_done.receive
|
| 1258 |
+
|
| 1259 |
+
# 🚫 an anonymous ten-line meanwhile — the reader must simulate two timelines at once
|
| 1260 |
+
writer_done = Channel(Exception?).new(1)
|
| 1261 |
+
spawn do
|
| 1262 |
+
begin
|
| 1263 |
+
in_writer.write(input) unless input.empty?
|
| 1264 |
+
err = nil
|
| 1265 |
+
rescue ex
|
| 1266 |
+
err = ex
|
| 1267 |
+
ensure
|
| 1268 |
+
in_writer.close
|
| 1269 |
+
writer_done.send(err)
|
| 1270 |
+
end
|
| 1271 |
+
end
|
| 1272 |
+
```
|
| 1273 |
+
|
| 1274 |
+
**(d) Cost.** Method extraction can force explicit parameter passing where a
|
| 1275 |
+
closure captured silently — that's several extra tokens per fiber, and
|
| 1276 |
+
occasionally a small struct to carry them. Accepted eagerly: silent capture
|
| 1277 |
+
is precisely what makes concurrent code unreadable (and, per the `gc_arena`
|
| 1278 |
+
warnings, unsafe — a named method's parameter list *is* the audit of what
|
| 1279 |
+
the fiber touches).
|
| 1280 |
+
|
| 1281 |
+
**(e) Mechanical check.** Flag: `spawn do`/`spawn {` whose body exceeds 1
|
| 1282 |
+
statement; channel locals named `ch`/`chan`/`c`; a `spawn` whose body lacks
|
| 1283 |
+
a rescue and whose called method lacks one (approximate: warn on every spawn,
|
| 1284 |
+
require the boundary-rescue comment to silence); any `select` branch longer
|
| 1285 |
+
than one line.
|
| 1286 |
+
|
| 1287 |
+
---
|
| 1288 |
+
|
| 1289 |
+
### Rule CF-10. `?` asks, `!` warns — and the suffix is a promise
|
| 1290 |
+
|
| 1291 |
+
**(a) Why the syntax fights the rule.** The suffixes are Crystal's built-in
|
| 1292 |
+
statement-reading aid — `verified?` reads as a question, `save!` as a
|
| 1293 |
+
warning — but only if they're *reliable*. A `?` method returning a `String?`
|
| 1294 |
+
"sometimes-value" instead of a `Bool`, or a `!` method that's merely "the
|
| 1295 |
+
other version", breaks the reader's trained reflex and silently poisons
|
| 1296 |
+
every future read. Census: 195 `?` defs and 10 `!` defs in the template —
|
| 1297 |
+
the reflex is trainable; the contract just needs writing down.
|
| 1298 |
+
|
| 1299 |
+
**(b) Proposed rule — "The suffix is a promise."**
|
| 1300 |
+
|
| 1301 |
+
- `def foo?` returns `Bool` — full stop — with one blessed exception: the
|
| 1302 |
+
Crystal-stdlib **maybe-lookup** convention (`session["oauth_state"]?`,
|
| 1303 |
+
`ENV["KEY"]?`, `find_by?`) where `?` means *nil instead of raising*. Both
|
| 1304 |
+
are questions ("is it?" / "is it there?"); nothing else earns the mark.
|
| 1305 |
+
- `def foo!` means **raises where `foo` returns nil, or mutates the
|
| 1306 |
+
receiver** — the two Ruby/Crystal senses — and every `!` method's doc
|
| 1307 |
+
comment states *which* danger it warns about, in one line.
|
| 1308 |
+
- In conditions, prefer the `?` form over comparison chains
|
| 1309 |
+
(`user.verified?` not `user.verified_at != nil`).
|
| 1310 |
+
- Chaining: a `!` call never appears mid-chain (`fetch!.parse.render` hides
|
| 1311 |
+
the raise in the middle of a sentence — the raise belongs on its own
|
| 1312 |
+
line, where a guard or rescue can be seen next to it). A `?` predicate
|
| 1313 |
+
never has its result chained onward (`valid?.to_s` is a smell: a question
|
| 1314 |
+
answers, it doesn't pipeline).
|
| 1315 |
+
|
| 1316 |
+
**(c) Before/after.**
|
| 1317 |
+
|
| 1318 |
+
```crystal
|
| 1319 |
+
# ✅ AED — the question mark tells the truth
|
| 1320 |
+
def team_member? : Bool
|
| 1321 |
+
@context.try(&.team_membership) != nil
|
| 1322 |
+
end
|
| 1323 |
+
|
| 1324 |
+
# 🚫 a "question" that answers with a maybe-string — the reflex is now poisoned
|
| 1325 |
+
def admin_role?
|
| 1326 |
+
membership.role if membership.admin?
|
| 1327 |
+
end
|
| 1328 |
+
|
| 1329 |
+
# ✅ AED — the raise stands on its own line where the reader can see it
|
| 1330 |
+
document = Document.find!(document_id) # raises Grant::Querying::NotFound
|
| 1331 |
+
render(document)
|
| 1332 |
+
|
| 1333 |
+
# 🚫 the raise hides mid-sentence
|
| 1334 |
+
render(Document.find!(document_id).with_sections)
|
| 1335 |
+
```
|
| 1336 |
+
|
| 1337 |
+
**(d) Cost.** The maybe-lookup exception means `?` is *two* promises, not
|
| 1338 |
+
one — genuinely a wart, but it's stdlib-load-bearing (98 `.try`s and every
|
| 1339 |
+
`[]?` depend on it), so we document it rather than fight it. Some `!`
|
| 1340 |
+
doc-comment ceremony.
|
| 1341 |
+
|
| 1342 |
+
**(e) Mechanical check.** Flag: `def …?` with a declared return type other
|
| 1343 |
+
than `Bool` outside index/find/lookup names; `def …!` with no doc comment;
|
| 1344 |
+
`!`-suffixed call followed by `.` on the same line; `?`-suffixed predicate
|
| 1345 |
+
call followed by `.` (excluding `[]?`/`find_by?`-style lookups).
|
| 1346 |
+
|
| 1347 |
+
---
|
| 1348 |
+
|
| 1349 |
+
### Rule CF-11. Macros write code; they don't hide flow
|
| 1350 |
+
|
| 1351 |
+
**(a) Why the syntax fights the rule.** `{% if flag?(:preview_mt) %}` is
|
| 1352 |
+
control flow the runtime reader *cannot see executing at all* — the branch
|
| 1353 |
+
was taken at compile time, and half the file's text is a ghost. `macro
|
| 1354 |
+
included` generates methods that exist nowhere in the source a reader greps.
|
| 1355 |
+
Both defeat statement-reading not by being dense but by being **invisible**.
|
| 1356 |
+
Census: 3 macro defs, 2 compile-time ifs — rare, so the rule is a fence, not
|
| 1357 |
+
a renovation.
|
| 1358 |
+
|
| 1359 |
+
**(b) Proposed rule — "Compile-time branches speak for both worlds."**
|
| 1360 |
+
|
| 1361 |
+
- `{% if %}` / `{% else %}` is allowed only for **platform/flag gating**
|
| 1362 |
+
(`flag?(:preview_mt)`, `flag?(:gc_agentc)`), placed at the **top level of
|
| 1363 |
+
a method or file section** — never interleaved inside a runtime `if`
|
| 1364 |
+
ladder. Each branch's first line is a comment stating which world this is
|
| 1365 |
+
and what the other world does (`# MT builds: forking is unsupported —
|
| 1366 |
+
raise; single-thread builds take the fork path below`). The existing
|
| 1367 |
+
`isolated_worker.cr` / `gc_arena.cr` sites already approximate this.
|
| 1368 |
+
- `macro` definitions live only in **concerns and infrastructure**
|
| 1369 |
+
(`src/models/concerns/`, `src/runtime/`), never in controllers/views/
|
| 1370 |
+
business logic. Every `macro included` carries a comment block listing,
|
| 1371 |
+
by name, the methods/columns it generates (`soft_deletable.cr`'s
|
| 1372 |
+
`column deleted_at` style is halfway there — add the roster comment), so
|
| 1373 |
+
grep-for-definition finds a mention even though the def is generated.
|
| 1374 |
+
- No macro-generated *runtime branching* whose shape depends on macro logic
|
| 1375 |
+
(a macro that emits different `if` ladders per include is a puzzle box).
|
| 1376 |
+
Generate declarations and delegations; keep decisions in visible code.
|
| 1377 |
+
- `{% for %}` (census: zero) — same fence: declaration generation only.
|
| 1378 |
+
|
| 1379 |
+
**(c) Before/after.**
|
| 1380 |
+
|
| 1381 |
+
```crystal
|
| 1382 |
+
# ✅ AED — the ghost branch is narrated for the reader of either world
|
| 1383 |
+
def self.run(&block : -> Bytes) : Bytes
|
| 1384 |
+
{% if flag?(:preview_mt) %}
|
| 1385 |
+
# MT builds: fork() after threads exist inherits poisoned locks — refuse loudly.
|
| 1386 |
+
raise UnsupportedError.new("IsolatedWorker.run requires the single-threaded runtime")
|
| 1387 |
+
{% else %}
|
| 1388 |
+
# Single-threaded builds: fork, run the block in the child, reap the bytes.
|
| 1389 |
+
run_in_forked_child(block)
|
| 1390 |
+
{% end %}
|
| 1391 |
+
end
|
| 1392 |
+
|
| 1393 |
+
# 🚫 compile-time and runtime conditions braided together — nobody can trace this
|
| 1394 |
+
{% if flag?(:gc_agentc) %} if ENABLED && {% if flag?(:preview_mt) %} false {% else %} arena_ready? {% end %} ... {% end %}
|
| 1395 |
+
```
|
| 1396 |
+
|
| 1397 |
+
**(d) Cost.** The roster comment can drift from what the macro actually
|
| 1398 |
+
generates (comments always can); the "concerns only" fence occasionally
|
| 1399 |
+
forces a small concern file where an inline macro felt convenient. Accepted:
|
| 1400 |
+
invisible code is the single most expensive thing to hand a coding agent.
|
| 1401 |
+
|
| 1402 |
+
**(e) Mechanical check.** Flag: `{% if` on a line that also contains runtime
|
| 1403 |
+
`if`/`unless`; `macro ` definitions outside `src/models/concerns/` and
|
| 1404 |
+
`src/runtime/`; `macro included` without a comment containing `generates`
|
| 1405 |
+
within 3 lines; nested `{%` inside a method body deeper than one level.
|
| 1406 |
+
|
| 1407 |
+
---
|
| 1408 |
+
|
| 1409 |
+
### How these rules feed documentation generation
|
| 1410 |
+
|
| 1411 |
+
AED's premise for docs: **the names are the source of headings.** Prose docs
|
| 1412 |
+
rot; names are re-verified by every compile and every review. Control flow is
|
| 1413 |
+
where this pays off most, because control flow *is* the behavior readers ask
|
| 1414 |
+
about ("when does it refuse?", "what can go wrong?", "what runs in the
|
| 1415 |
+
background?"). Each rule above was written so its mandatory names map onto a
|
| 1416 |
+
doc section mechanically:
|
| 1417 |
+
|
| 1418 |
+
| Rule | Named artifact | Doc surface it generates |
|
| 1419 |
+
|---|---|---|
|
| 1420 |
+
| CF-3 Guards first | The guard block of each public method | **"Refuses when…"** bullet list per operation — each guard line becomes one bullet, its *why*-comment becomes the bullet's explanation. The wire/cose.cr guard stack *is* its security doc. |
|
| 1421 |
+
| CF-8 Question methods | `?` predicates referenced by guards & branches | **Glossary of business rules** — `team_lead?`, `oauth_callback_valid?` become glossary entries; the predicate body is the definition. Policy classes' `can?` menus render directly as **permission tables** (action × predicate). |
|
| 1422 |
+
| CF-1 Case menus | `case` subject + `when` labels + extracted branch methods | **Decision tables** — "depending on `default_provider`: …" — subject is the table title, when-labels are rows, extracted method names are the outcome column. The mandatory `else` becomes the documented fallback row. |
|
| 1423 |
+
| CF-2 Loop finish lines | Loop-extracted body methods, `loop`-named methods | **"Process steps"** — `consume_blockquote`, `emit_table_row` list as the pipeline's stages; `run_heartbeat_loop` names itself in ops docs. |
|
| 1424 |
+
| CF-7 Error vocabulary | Typed error classes; typed rescues | **"What can go wrong"** section per module — the error subclass tree renders as the failure catalogue; each typed `rescue` site documents which layer absorbs which failure. This is also compliance evidence (SOC2 loves an error taxonomy). |
|
| 1425 |
+
| CF-9 Fiber job titles | Spawn-target method names; channel names | **"Background work"** section — every `spawn`-called method is a row: job title, what it waits on (channel names), its boundary rescue. Ops runbooks can be generated from exactly this. |
|
| 1426 |
+
| CF-11 Macro rosters | The `generates:` comment roster | **"Generated API"** appendix per concern — the roster is the contract; docs list it verbatim so generated methods are findable. |
|
| 1427 |
+
| CF-10 Suffix promises | `!` doc comments | **Danger callouts** — every `!` method's one-line warning surfaces as a ⚠️ note wherever the method is documented. |
|
| 1428 |
+
|
| 1429 |
+
**What does *not* surface:** ternary values, waypoint locals (CF-6), named
|
| 1430 |
+
`Bool` locals (CF-8's one-off form), and cursor predicates — these are
|
| 1431 |
+
paragraph-level names for the human reading the file, below the doc
|
| 1432 |
+
altitude. The doc generator's selection rule is mechanical: **a control-flow
|
| 1433 |
+
name surfaces to docs iff it is a method name** (predicates, branch
|
| 1434 |
+
extractions, loop bodies, fiber jobs, error classes). Locals stay local.
|
| 1435 |
+
|
| 1436 |
+
A future `docs/` generator (or a doc-writing agent) therefore needs only:
|
| 1437 |
+
method names + `?`/`!` suffixes + guard blocks + case labels + error class
|
| 1438 |
+
tree + spawn targets — all extractable with the same grep-grade tooling as
|
| 1439 |
+
the mechanical checks in (e). That symmetry is deliberate: **the linter's
|
| 1440 |
+
tokens and the doc generator's tokens are the same tokens.**
|
| 1441 |
+
|
| 1442 |
+
---
|
| 1443 |
+
|
| 1444 |
+
### Implementation sketch (if adopted)
|
| 1445 |
+
|
| 1446 |
+
1. Add the accepted rules to `.claude/skills/aed-conventions/SKILL.md` as a
|
| 1447 |
+
"Control flow" section, keeping the existing 6 rules and voice; extend
|
| 1448 |
+
the end-of-edit checklist with one line per rule.
|
| 1449 |
+
2. Extend `.claude/hooks/crystal_check.sh` (or a sibling `aed_lint.sh`) with
|
| 1450 |
+
the grep-grade checks from each rule's (e) — start **warn-only**, promote
|
| 1451 |
+
to blocking per-rule once the existing codebase is swept. Candidates for
|
| 1452 |
+
custom Ameba rules later; greps first (same engine, zero deps).
|
| 1453 |
+
3. Sweep order by census-weighted payoff: (1) bare rescues → typed/commented
|
| 1454 |
+
(~40 sites), (2) nested `.try` fallbacks (~a dozen sites), (3) compound
|
| 1455 |
+
`unless` (+ the two `spawn do` bodies), (4) case menus without `else`.
|
| 1456 |
+
The website's markdown parser needs no changes — it already conforms to
|
| 1457 |
+
CF-2's cursor-loop shape.
|
| 1458 |
+
|
| 1459 |
+
---
|
| 1460 |
+
|
| 1461 |
+
### Open questions before v1.1.0 final
|
| 1462 |
+
|
| 1463 |
+
These are the thresholds still under review. Each rule above is usable today;
|
| 1464 |
+
what is unsettled is exactly where the line falls, not whether the rule holds.
|
| 1465 |
+
Opinions are welcome in
|
| 1466 |
+
[Discussions](https://github.com/AgentC-Consulting/aed-conventions/discussions).
|
| 1467 |
+
|
| 1468 |
+
|
| 1469 |
+
1. **Case threshold (CF-1):** Adopt "3+ branches or use if/else", every
|
| 1470 |
+
`when` body ≤ 3 lines, mandatory `else`? Or allow 2-branch `case` when
|
| 1471 |
+
the subject name carries weight?
|
| 1472 |
+
2. **Ban `until` outright (CF-2/CF-4)?** Census shows zero uses, so it's
|
| 1473 |
+
free today — but it's idiomatic Crystal and some readers find
|
| 1474 |
+
`until done?` natural. Ban, or allow with single-predicate conditions?
|
| 1475 |
+
3. **Guard contiguity (CF-3):** Enforce "all guards before the first story
|
| 1476 |
+
statement" as a hard rule, or as a default with a *why*-comment escape
|
| 1477 |
+
hatch for genuinely late preconditions?
|
| 1478 |
+
4. **Bare `rescue ex` at boundaries (CF-7):** Is comment-plus-log sufficient
|
| 1479 |
+
license, or do you want a named helper (`swallowing_errors(context) do`)
|
| 1480 |
+
so boundaries are greppable as one idiom?
|
| 1481 |
+
5. **`.try` hard cap (CF-6):** One `.try` per expression is aggressive given
|
| 1482 |
+
98 existing uses — adopt as blocking for new code and sweep old, or
|
| 1483 |
+
warn-only permanently?
|
| 1484 |
+
6. **Spawn body = single named call (CF-9):** Apply retroactively to the two
|
| 1485 |
+
existing spawn sites (`isolated_worker.cr`, `mcp_sse_controller.cr`) in
|
| 1486 |
+
the sweep, or grandfather them with comments?
|
| 1487 |
+
7. **Enforcement vehicle:** extend `crystal_check.sh` with warn-only greps,
|
| 1488 |
+
write custom Ameba rules, or both (greps now, Ameba when stable)?
|
| 1489 |
+
8. **Docs pipeline:** is the "method names surface, locals don't" selection
|
| 1490 |
+
rule right for the doc generator, and which doc surface should be built
|
| 1491 |
+
first — permission tables from policies (cheapest, highest compliance
|
| 1492 |
+
value) or "What can go wrong" from the error tree?
|
| 1493 |
+
9. **Ternary strictness (CF-5):** the `success ? "info" : "warning"`
|
| 1494 |
+
argument-position form is blessed; do you also want to allow simple
|
| 1495 |
+
ternaries inside string interpolation (common in view components), or
|
| 1496 |
+
force extraction there too?
|
| 1497 |
+
10. **Where does this land?** Fold into the existing SKILL.md as one
|
| 1498 |
+
"Control flow" section (one skill, longer), or a sibling
|
| 1499 |
+
`aed-control-flow` skill file referenced from the main one (two hops,
|
| 1500 |
+
shorter files)?
|
| 1501 |
+
|
| 1502 |
+
---
|
| 1503 |
+
|
| 1504 |
+
*Chapter 06 of the AED canon · the census and code shapes above are drawn from
|
| 1505 |
+
AgentC Consulting's own production Crystal, so the rules target real frequency
|
| 1506 |
+
rather than theory · back to the [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 1507 |
+
|
| 1508 |
+
|
| 1509 |
+
---
|
| 1510 |
+
|
| 1511 |
+
<!-- source: 07_how_the_workflow_runs.md -->
|
| 1512 |
+
|
| 1513 |
+
## How Agent Enhanced Development Work Flows - Local Models
|
| 1514 |
+
|
| 1515 |
+
Typical development processes are that you focus on small steps at a time to scaffold out an idea and then focus on the logic flow. This usually means a lot of saving and rapid iteration. This is actually the least productive way to work with an agent enhanced development process.
|
| 1516 |
+
|
| 1517 |
+
When you are first starting out using an AI agent to assist with developing your app, the temptation is to continue using it for the quick iterative feedback like we currently get from a “write, save, retry” development process. However, with an AI agent enhancing our development process, we are rewarded for planning in detail, and using our natural language. By that I mean, writing and building feature requests in large batches and letting the AI run over many features.
|
| 1518 |
+
|
| 1519 |
+
The agent should be driving the majority of the development, and you should be able to walk away and do something else. It’s a great way to end a day of planning, and then let your laptop sit for a time while the agent runs. It’ll spend the time it needs until it succeeds at building a thorough feature, including your tests.
|
| 1520 |
+
|
| 1521 |
+
This means you can plan your time so that your agent is building your app while you’re typically away from your computer, this way you’re maximizing your local hardware availability while getting the benefits.
|
| 1522 |
+
|
| 1523 |
+
---
|
| 1524 |
+
|
| 1525 |
+
*Chapter 07 of the AED canon · published **verbatim** from the author's original · back to the [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
| 1526 |
+
|
| 1527 |
+
|
| 1528 |
+
---
|
| 1529 |
+
|
| 1530 |
+
<!-- source: quick_reference.md -->
|
| 1531 |
+
|
| 1532 |
+
## Quick Reference - AED Cheat Sheet
|
| 1533 |
+
|
| 1534 |
+
This is a quick reference, please read the entire guide for more details.
|
| 1535 |
+
|
| 1536 |
+
**This is the bare minimum to improve the performance of untrained coding assistants**
|
| 1537 |
+
|
| 1538 |
+
If you're a Rails developer, or come from a similarly structured framework, you'll find a lot of this inspired by the Rails conventions.
|
| 1539 |
+
|
| 1540 |
+
|
| 1541 |
+
## Naming Conventions
|
| 1542 |
+
|
| 1543 |
+
|
| 1544 |
+
### General Principles & Guidelines
|
| 1545 |
+
|
| 1546 |
+
- Avoid unnecessary jargon or slang.
|
| 1547 |
+
- Never create a whole new lexicon for your code base by applying a theme.
|
| 1548 |
+
- Code names for code bases are entirely acceptable and expected.
|
| 1549 |
+
- Names that read like plain English are preferred
|
| 1550 |
+
|
| 1551 |
+
|
| 1552 |
+
### Object & Attribute Naming Conventions
|
| 1553 |
+
|
| 1554 |
+
- Data models should be singular, and only concerned with their own individual behavior.
|
| 1555 |
+
- Good: `Customer`
|
| 1556 |
+
- Bad: `Customers`
|
| 1557 |
+
- Classes should be name spaced according to the feature that is being implemented.
|
| 1558 |
+
- Good: `Billing::ActivateNewCustomerSubscription`
|
| 1559 |
+
- Bad: `NewCustomerSubscription`
|
| 1560 |
+
- Class names should be short statements or phrases that clearly express the process being performed.
|
| 1561 |
+
- Good: `PerformCustomerAccountLocking`
|
| 1562 |
+
- Bad: `LockCustomers`
|
| 1563 |
+
- Class attributes of non-enumerable primitive types should be phrased as short statements for what the intended purpose of the attribute is.
|
| 1564 |
+
- Example class `Customer`
|
| 1565 |
+
- Well named attribute: `first_name` or `full_name`
|
| 1566 |
+
- Poorly named attribute: `name`
|
| 1567 |
+
- Class attributes of enumerable (Array or Array-like) objects or types should be phrased with `list_of_` or `collection_of_` or `array_of_`
|
| 1568 |
+
- Example class `Customer` has many `Order`s
|
| 1569 |
+
- Well named attribute: `list_of_previous_orders` or `collection_of_previous_orders` or `array_of_previous_orders`
|
| 1570 |
+
- Poorly named attribute: `orders` or `previous_orders`
|
| 1571 |
+
- **Suggestion**: in dynamically typed languages, adding the object type to the end of the name can be very helpful by using the `_as_` phrasing in your naming
|
| 1572 |
+
- Example: `list_of_previous_orders_as_hashes`
|
| 1573 |
+
- Class attributes of non-primitive types should be named using short statements or phrases that accurately and clearly express how that attribute is to be used
|
| 1574 |
+
- Example class: `Customer` with a `Subscription`
|
| 1575 |
+
- Ideal: `currently_active_subscription`
|
| 1576 |
+
- Acceptable: `active_subscription`
|
| 1577 |
+
- Bad: `subscription`
|
| 1578 |
+
- Class attributes for boolean types should be named as if the expression is a question beginning with `if`
|
| 1579 |
+
- Example class: `Customer`
|
| 1580 |
+
- Good: `has_a_valid_payment_method`
|
| 1581 |
+
- Bad: `payment_method_present`
|
| 1582 |
+
|
| 1583 |
+
|
| 1584 |
+
### Method Naming Conventions
|
| 1585 |
+
|
| 1586 |
+
- Method names should be phrases or statements that explain the process thats taking place
|
| 1587 |
+
- When possible, include wording to describe the expected return type
|
| 1588 |
+
- Method parameters should be named when possible
|
| 1589 |
+
- Ideally as if reading a plain statement
|
| 1590 |
+
|
| 1591 |
+
|
| 1592 |
+
### File & Folder Naming Conventions
|
| 1593 |
+
|
| 1594 |
+
These primarily apply to domain/business logic. Use your appropriate framework folder structure where necessary. These conventions are primarily if you are using an agent helper that is trained to work with more than 1 file at a time or perform file edits/updates autonomously.
|
| 1595 |
+
|
| 1596 |
+
- The file name should be a lower snake case of the primary class from the file.
|
| 1597 |
+
- Class name `ProcessCustomersWithExpiredSubscriptions`
|
| 1598 |
+
- Filename: `process_customers_with_expired_subscriptions.cr`
|
| 1599 |
+
- Classes that are name spaced should be in folders named for that namespace
|
| 1600 |
+
- Class name `Billing::ProcessCustomersWithExpiredSubscriptions`
|
| 1601 |
+
- Filename: `billing/process_customers_with_expired_subscriptions.cr`
|
| 1602 |
+
- Data models rarely need to be name spaced.
|
| 1603 |
+
- Reserve this kind of naming for single-table inheritance or other very specific situations where you need a data model to be name spaced.
|
| 1604 |
+
|
| 1605 |
+
|
| 1606 |
+
|
| 1607 |
+
Example
|
| 1608 |
+
```crystal
|
| 1609 |
+
# File found under `billing/process_customers_with_expired_payment_methods`
|
| 1610 |
+
class Billing::ProcessCustomersWithExpiredPaymentMethods
|
| 1611 |
+
property collection_of_customers_that_have_expired_payment_methods : Array(Customer) = [] of Customer
|
| 1612 |
+
property collection_of_customers_that_were_retried_and_failed : Array(Customer) = [] of Customer
|
| 1613 |
+
property all_of_the_customers_have_been_processed : Bool = false
|
| 1614 |
+
|
| 1615 |
+
def initialize(@collection_of_customers_that_have_expired_payment_methods)
|
| 1616 |
+
end
|
| 1617 |
+
|
| 1618 |
+
def perform
|
| 1619 |
+
retry_customers_who_failed_payment_processing_with_an_expired_card
|
| 1620 |
+
mark_customer_accounts_as_delinquent_and_prevent_further_use
|
| 1621 |
+
end
|
| 1622 |
+
|
| 1623 |
+
private def retry_customers_who_failed_payment_processing_with_an_expired_card
|
| 1624 |
+
# Your business logic goes here
|
| 1625 |
+
end
|
| 1626 |
+
|
| 1627 |
+
private def mark_customer_accounts_as_delinquent_and_prevent_further_use
|
| 1628 |
+
# Your business logic goes here
|
| 1629 |
+
end
|
| 1630 |
+
|
| 1631 |
+
end
|
| 1632 |
+
```
|
| 1633 |
+
|
| 1634 |
+
### Process Manager Conventions
|
| 1635 |
+
|
| 1636 |
+
Process managers are the starting point of your businesses internal domain-specific language (DSL).
|
| 1637 |
+
|
| 1638 |
+
These objects are _typically_ just a plain class that is not part of a specific framework. Many frameworks have some utilities that bleed out of the framework and into your business logic for common usecase tasks.
|
| 1639 |
+
|
| 1640 |
+
A more formal definition that encompasses what the spirit of the process manager is:
|
| 1641 |
+
|
| 1642 |
+
`Process Manager: a starting point in a business process where a workflow of one or more steps begins and ends, with the final product being the end of the computational process for the business.`
|
| 1643 |
+
|
| 1644 |
+
Process managers conform to the following:
|
| 1645 |
+
- The `initialize` method receives all of the necessary information possible to perform the process
|
| 1646 |
+
- Any necessary data organization should happen during the objects initialization step
|
| 1647 |
+
- Prefer to use named parameters when initializing objects
|
| 1648 |
+
- The entry point method `perform` is defined, and performs all of the methods necessary for the business task to be completed in a single method call
|
| 1649 |
+
- A well written `perform` method will read almost like psuedo code when outlining each step that's being performed.
|
| 1650 |
+
- Use read-only public accessor methods if the object is going to be used for anything other than returning a single result
|
| 1651 |
+
- Use "middle managers" if your business process requires a secondary layer of business logic.
|
| 1652 |
+
|
| 1653 |
+
### Process "Middle" Manager Conventions
|
| 1654 |
+
|
| 1655 |
+
Just like process managers, these are objects that are in your codebase and represent your business process. As a middle manager, they typically are responsible for small parts of a larger process that has complex logic.
|
| 1656 |
+
|
| 1657 |
+
- Middle managers _should be named spaced to the process manager_. These are not meant to be re-used across the code base, just as an organization tool in a large process.
|
| 1658 |
+
- Middle managers _do not_ use any other managers.
|
| 1659 |
+
|
| 1660 |
+
## Framework Conventions
|
| 1661 |
+
|
| 1662 |
+
These conventions have (amber)[https://amberframework.org] and (Ruby on Rails)[https://rubyonrails.org] in mind, but any RESTful routing app will tend to follow these well.
|
| 1663 |
+
|
| 1664 |
+
- The standard `Create`, `Edit`, `Update` and `Destroy` will only effect a single resource object.
|
| 1665 |
+
- The typical `CRUD` actions should maintain the bare minimum logic to do the following:
|
| 1666 |
+
- a single resource:
|
| 1667 |
+
- Recieve whitelisted parameters
|
| 1668 |
+
- update and validate the target object
|
| 1669 |
+
- Render a response (successful or otherwise)
|
| 1670 |
+
- multiple resources:
|
| 1671 |
+
- Render a response with 0 or more of the desired resource (more commonly known as an index route)
|
| 1672 |
+
- Any non-RESTful routes should do the following:
|
| 1673 |
+
- Recieve and validate any incoming parameters or request body
|
| 1674 |
+
- Use a process manager to perform any logic required for the response
|
| 1675 |
+
- Render a response (successful or otherwise)
|
| 1676 |
+
|
| 1677 |
+
A well written Rails controller would look like the following:
|
| 1678 |
+
```ruby
|
| 1679 |
+
# app/controllers/customers_controller.rb
|
| 1680 |
+
class CustomersController < ApplicationController
|
| 1681 |
+
def create
|
| 1682 |
+
@customer = Customer.new(customer_params)
|
| 1683 |
+
if @customer.save
|
| 1684 |
+
render json: @customer, status: :created
|
| 1685 |
+
else
|
| 1686 |
+
render json: @customer.errors, status: :unprocessable_entity
|
| 1687 |
+
end
|
| 1688 |
+
end
|
| 1689 |
+
|
| 1690 |
+
def update_payment_and_subscription
|
| 1691 |
+
customer = Customer.find(params[:id])
|
| 1692 |
+
new_payment_method = params[:payment_method]
|
| 1693 |
+
|
| 1694 |
+
if customer && new_payment_method
|
| 1695 |
+
process_manager = Billing::UpdateCustomerPaymentAndSubscription.new(
|
| 1696 |
+
customer: customer,
|
| 1697 |
+
new_payment_method: new_payment_method
|
| 1698 |
+
)
|
| 1699 |
+
if process_manager.perform
|
| 1700 |
+
render json: { message: 'Customer payment method and subscription updated successfully' }, status: :ok
|
| 1701 |
+
else
|
| 1702 |
+
render json: { error: 'Failed to update payment method and subscription' }, status: :unprocessable_entity
|
| 1703 |
+
end
|
| 1704 |
+
else
|
| 1705 |
+
render json: { error: 'Invalid parameters' }, status: :bad_request
|
| 1706 |
+
end
|
| 1707 |
+
end
|
| 1708 |
+
|
| 1709 |
+
private def customer_params
|
| 1710 |
+
params.require(:customer).permit(:first_name, :last_name, :email)
|
| 1711 |
+
end
|
| 1712 |
+
end
|
| 1713 |
+
```
|
| 1714 |
+
|
| 1715 |
+
Here's the accompanying process manager:
|
| 1716 |
+
|
| 1717 |
+
```ruby
|
| 1718 |
+
module Billing
|
| 1719 |
+
class UpdateCustomerPaymentAndSubscription
|
| 1720 |
+
attr_reader :customer, :new_payment_method
|
| 1721 |
+
|
| 1722 |
+
def initialize(customer:, new_payment_method:)
|
| 1723 |
+
@customer = customer
|
| 1724 |
+
@new_payment_method = new_payment_method
|
| 1725 |
+
end
|
| 1726 |
+
|
| 1727 |
+
def perform
|
| 1728 |
+
update_payment_method && update_subscription_status
|
| 1729 |
+
end
|
| 1730 |
+
|
| 1731 |
+
private def update_payment_method
|
| 1732 |
+
# Implement the logic to update the customer's payment method
|
| 1733 |
+
customer.update(payment_method: new_payment_method)
|
| 1734 |
+
end
|
| 1735 |
+
|
| 1736 |
+
private def update_subscription_status
|
| 1737 |
+
# Implement the logic to update the customer's subscription status based on the new payment method
|
| 1738 |
+
if customer.payment_method_valid?
|
| 1739 |
+
customer.update(subscription_status: 'active')
|
| 1740 |
+
else
|
| 1741 |
+
customer.update(subscription_status: 'inactive')
|
| 1742 |
+
end
|
| 1743 |
+
end
|
| 1744 |
+
end
|
| 1745 |
+
end
|
| 1746 |
+
```
|
| 1747 |
+
|
| 1748 |
+
|
| 1749 |
+
---
|
| 1750 |
+
|
| 1751 |
+
*The AED cheat sheet · published **verbatim** from the author's original · back to the [reading order](https://github.com/AgentC-Consulting/aed-conventions/blob/v1.1.0-rc.1/README.md#reading-order)*
|
evidence/benchmark_data.json
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"benchmark": "AED vs conventional Crystal — small-model comprehension",
|
| 3 |
+
"date": "2026-07-07",
|
| 4 |
+
"hypothesis": "AED-style Crystal ('reads like statements', per the premium template's aed-conventions skill) lets smaller models reason about and understand code intent better than conventional compressed style.",
|
| 5 |
+
"method": {
|
| 6 |
+
"pairs": 10,
|
| 7 |
+
"probes_per_variant": 3,
|
| 8 |
+
"probe_types": [
|
| 9 |
+
"intent",
|
| 10 |
+
"modification",
|
| 11 |
+
"defect"
|
| 12 |
+
],
|
| 13 |
+
"probe_descriptions": {
|
| 14 |
+
"intent": "Explain what the code does and why (business intent, not line-by-line).",
|
| 15 |
+
"modification": "Describe how to make a specified behavior change correctly.",
|
| 16 |
+
"defect": "A subtle behavioral question / planted-defect-style probe about an edge case."
|
| 17 |
+
},
|
| 18 |
+
"answering_model": "Claude Haiku (answered blind: never told which style variant it was reading)",
|
| 19 |
+
"grading": "Graded blind by a model grader that never saw which style produced the answer. 0 = wrong/missed, 1 = partially correct, 2 = fully correct. Max 6 per variant per pair.",
|
| 20 |
+
"semantic_equivalence": "Each pair's two variants were verified behaviorally identical by a Crystal differential-test harness (scratchpad aed_bench/build_harness.py + tests.cr) that runs both variants against shared checks and diffs outputs.",
|
| 21 |
+
"runs": "Single run per probe (no repeats).",
|
| 22 |
+
"note": "Haiku's raw answer transcripts and the grader's rationales were not persisted; this file carries the full source of both variants per pair plus the graded scores, which is sufficient to re-run the probes."
|
| 23 |
+
},
|
| 24 |
+
"aggregate": {
|
| 25 |
+
"aed_total": 60,
|
| 26 |
+
"conventional_total": 54,
|
| 27 |
+
"max_per_variant": 60
|
| 28 |
+
},
|
| 29 |
+
"per_probe_type_totals": {
|
| 30 |
+
"aed": {
|
| 31 |
+
"intent": 20,
|
| 32 |
+
"modification": 20,
|
| 33 |
+
"defect": 20
|
| 34 |
+
},
|
| 35 |
+
"conventional": {
|
| 36 |
+
"intent": 18,
|
| 37 |
+
"modification": 20,
|
| 38 |
+
"defect": 16
|
| 39 |
+
},
|
| 40 |
+
"max_per_cell": 20
|
| 41 |
+
},
|
| 42 |
+
"pairs": [
|
| 43 |
+
{
|
| 44 |
+
"id": "p1-auth-mfa-routing",
|
| 45 |
+
"topic": "auth/session logic — post-password MFA routing and pending-challenge TTL",
|
| 46 |
+
"aed_source": "module Auth\n # Routes a user who has just passed the password check. The password is only\n # the FIRST factor: an MFA-enrolled regular user must verify a second factor\n # before a session is established. Admin accounts have no MFA flag here.\n module PostPasswordRouter\n MFA_PENDING_TTL_SECONDS = 300\n\n def self.next_step(user : Users::Regular | Users::Admin | Nil) : Symbol\n return :reject_login if user.nil?\n return :begin_mfa_challenge if second_factor_required?(user)\n\n :complete_login\n end\n\n # Only regular users can enroll in MFA in this template.\n def self.second_factor_required?(user : Users::Regular | Users::Admin) : Bool\n if user.is_a?(Users::Regular)\n user.mfa_enabled\n else\n false\n end\n end\n\n # A pending second factor is honored only inside the TTL window; a stale\n # challenge sends the user back to the password step. This bounds the\n # window an attacker has to guess codes.\n def self.mfa_challenge_still_valid?(pending_started_at : Int64?, now : Int64) : Bool\n return false if pending_started_at.nil?\n\n seconds_pending = now - pending_started_at\n seconds_pending <= MFA_PENDING_TTL_SECONDS\n end\n end\nend\n",
|
| 47 |
+
"conventional_source": "module Auth\n module PostPasswordRouter\n MFA_PENDING_TTL_SECONDS = 300\n\n def self.next_step(user : Users::Regular | Users::Admin | Nil) : Symbol\n return :reject_login unless user\n user.is_a?(Users::Regular) && user.mfa_enabled ? :begin_mfa_challenge : :complete_login\n end\n\n def self.second_factor_required?(user : Users::Regular | Users::Admin) : Bool\n user.is_a?(Users::Regular) ? user.mfa_enabled : false\n end\n\n def self.mfa_challenge_still_valid?(pending_started_at : Int64?, now : Int64) : Bool\n pending_started_at ? (now - pending_started_at) <= MFA_PENDING_TTL_SECONDS : false\n end\n end\nend\n"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"id": "p2-lead-scoring",
|
| 51 |
+
"topic": "lead scoring — email-domain classification plus message-effort bonus",
|
| 52 |
+
"aed_source": "class LeadScorer\n BUSINESS_DOMAIN_BONUS = 25\n SUBSTANTIAL_MESSAGE_LEN = 120\n SUBSTANTIAL_MESSAGE_BONUS = 10\n\n FREE_PROVIDER_DOMAINS = %w[gmail.com yahoo.com outlook.com hotmail.com icloud.com proton.me]\n DISPOSABLE_DOMAINS = %w[mailinator.com guerrillamail.com yopmail.com temp-mail.org]\n\n # Triage score: business senders who write substantively float to the top.\n def self.score(email : String, message : String) : Int32\n domain_class = classify_domain(extract_domain(email))\n\n score = 0\n score += BUSINESS_DOMAIN_BONUS if domain_class == \"business\"\n score -= BUSINESS_DOMAIN_BONUS if domain_class == \"suspicious\"\n score += SUBSTANTIAL_MESSAGE_BONUS if substantial_message?(message)\n score\n end\n\n def self.classify_domain(domain : String) : String\n return \"unknown\" if domain.empty?\n return \"suspicious\" if DISPOSABLE_DOMAINS.includes?(domain)\n return \"free_provider\" if FREE_PROVIDER_DOMAINS.includes?(domain)\n return \"business\" if plausible_custom_domain?(domain)\n \"unknown\"\n end\n\n # A custom domain must contain a dot that is not at either end.\n def self.plausible_custom_domain?(domain : String) : Bool\n domain.includes?('.') && !domain.starts_with?('.') && !domain.ends_with?('.')\n end\n\n # A few sentences of detail is a real effort signal vs. a one-liner.\n def self.substantial_message?(message : String) : Bool\n message.strip.size >= SUBSTANTIAL_MESSAGE_LEN\n end\n\n def self.extract_domain(address : String) : String\n normalized = address.strip.downcase\n at_index = normalized.rindex('@')\n return \"\" unless at_index\n normalized[(at_index + 1)..].strip\n end\nend\n",
|
| 53 |
+
"conventional_source": "class LeadScorer\n BUSINESS_DOMAIN_BONUS = 25\n SUBSTANTIAL_MESSAGE_LEN = 120\n SUBSTANTIAL_MESSAGE_BONUS = 10\n\n FREE_PROVIDER_DOMAINS = %w[gmail.com yahoo.com outlook.com hotmail.com icloud.com proton.me]\n DISPOSABLE_DOMAINS = %w[mailinator.com guerrillamail.com yopmail.com temp-mail.org]\n\n def self.score(email : String, message : String) : Int32\n dc = classify_domain(extract_domain(email))\n base = dc == \"business\" ? BUSINESS_DOMAIN_BONUS : dc == \"suspicious\" ? -BUSINESS_DOMAIN_BONUS : 0\n base + (message.strip.size >= SUBSTANTIAL_MESSAGE_LEN ? SUBSTANTIAL_MESSAGE_BONUS : 0)\n end\n\n def self.classify_domain(domain : String) : String\n case\n when domain.empty? then \"unknown\"\n when DISPOSABLE_DOMAINS.includes?(domain) then \"suspicious\"\n when FREE_PROVIDER_DOMAINS.includes?(domain) then \"free_provider\"\n when domain.includes?('.') && !domain.starts_with?('.') && !domain.ends_with?('.') then \"business\"\n else \"unknown\"\n end\n end\n\n def self.extract_domain(address : String) : String\n a = address.strip.downcase\n (i = a.rindex('@')) ? a[(i + 1)..].strip : \"\"\n end\nend\n"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"id": "p3-document-workflow",
|
| 57 |
+
"topic": "state transitions — document review workflow state machine",
|
| 58 |
+
"aed_source": "module Documents\n enum Status\n Draft\n InReview\n Approved\n Rejected\n Archived\n end\n\n # Review flow for client documents: a document moves strictly\n # draft -> in_review -> (approved | rejected). A rejected document returns\n # to draft for revision, only an approved document can be archived, and\n # archived is terminal, immutable history.\n module Workflow\n def self.transition_allowed?(from : Status, to : Status) : Bool\n allowed_destinations(from).includes?(to)\n end\n\n def self.allowed_destinations(from : Status) : Array(Status)\n if from.draft?\n [Status::InReview]\n elsif from.in_review?\n [Status::Approved, Status::Rejected]\n elsif from.rejected?\n [Status::Draft]\n elsif from.approved?\n [Status::Archived]\n else\n [] of Status\n end\n end\n\n def self.terminal?(status : Status) : Bool\n allowed_destinations(status).empty?\n end\n end\nend\n",
|
| 59 |
+
"conventional_source": "module Documents\n enum Status\n Draft\n InReview\n Approved\n Rejected\n Archived\n end\n\n module Workflow\n def self.transition_allowed?(from : Status, to : Status) : Bool\n allowed_destinations(from).includes?(to)\n end\n\n def self.allowed_destinations(from : Status) : Array(Status)\n case from\n in .draft? then [Status::InReview]\n in .in_review? then [Status::Approved, Status::Rejected]\n in .rejected? then [Status::Draft]\n in .approved? then [Status::Archived]\n in .archived? then [] of Status\n end\n end\n\n def self.terminal?(status : Status) : Bool\n allowed_destinations(status).empty?\n end\n end\nend\n"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"id": "p4-storage-safe-delete",
|
| 63 |
+
"topic": "file/storage handling — path-safe delete with metadata sidecar",
|
| 64 |
+
"aed_source": "module Storage\n # Deletes an object and its metadata sidecar from the local disk store.\n # Refuses any key that could reach outside the storage root.\n class LocalObjectRemover\n getter root : String\n\n def initialize(@root : String)\n end\n\n def delete(key : String) : Bool\n return false unless safe_key?(key)\n\n path = File.join(root, key)\n return false unless File.exists?(path)\n\n File.delete(path)\n remove_metadata_sidecar(path)\n true\n rescue error\n Log.error { \"LocalObjectRemover.delete error: #{error.message}\" }\n false\n end\n\n # A key may not be empty, may not be absolute, and may not contain a\n # \"..\" segment — any of those could escape the storage root.\n def safe_key?(key : String) : Bool\n return false if key.empty?\n return false if key.starts_with?('/')\n return false if key.split('/').includes?(\"..\")\n true\n end\n\n # Content-type metadata lives in a \"<path>.meta\" sidecar written by put.\n private def remove_metadata_sidecar(path : String)\n meta_path = \"#{path}.meta\"\n File.delete(meta_path) if File.exists?(meta_path)\n end\n end\nend\n",
|
| 65 |
+
"conventional_source": "module Storage\n class LocalObjectRemover\n getter root : String\n\n def initialize(@root : String)\n end\n\n def delete(key : String) : Bool\n return false unless safe_key?(key)\n path = File.join(root, key)\n return false unless File.exists?(path)\n File.delete(path)\n File.delete(\"#{path}.meta\") if File.exists?(\"#{path}.meta\")\n true\n rescue e\n Log.error { \"LocalObjectRemover.delete error: #{e.message}\" }\n false\n end\n\n def safe_key?(key : String) : Bool\n !key.empty? && !key.starts_with?('/') && !key.split('/').includes?(\"..\")\n end\n end\nend\n"
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"id": "p5-rate-limiter",
|
| 69 |
+
"topic": "rate limiting — sliding-window per-IP submission ceiling",
|
| 70 |
+
"aed_source": "# Sliding-window, in-memory rate limit for the contact form: an IP may\n# submit at most MAX_SUBMISSIONS_PER_WINDOW times per rolling hour.\n# Requests without a usable IP are never limited — we fail open on purpose.\nclass SubmissionRateLimiter\n MAX_SUBMISSIONS_PER_WINDOW = 3\n WINDOW_SECONDS = 60 * 60\n\n def initialize\n @submission_times_by_ip = Hash(String, Array(Int64)).new\n @lock = Mutex.new\n end\n\n # Records this attempt, then reports whether the IP has now gone over the\n # ceiling. Every attempt is recorded, even ones that end up limited.\n def over_limit?(ip : String?, now : Int64) : Bool\n return false if ip.nil? || ip.empty?\n\n attempts_in_window = record_and_count(ip, now)\n attempts_in_window > MAX_SUBMISSIONS_PER_WINDOW\n end\n\n private def record_and_count(ip : String, now : Int64) : Int32\n window_start = now - WINDOW_SECONDS\n\n @lock.synchronize do\n recent_times = @submission_times_by_ip[ip]? || Array(Int64).new\n recent_times.reject! { |time| time < window_start }\n recent_times << now\n @submission_times_by_ip[ip] = recent_times\n recent_times.size\n end\n end\nend\n",
|
| 71 |
+
"conventional_source": "class SubmissionRateLimiter\n MAX_SUBMISSIONS_PER_WINDOW = 3\n WINDOW_SECONDS = 60 * 60\n\n def initialize\n @submission_times_by_ip = Hash(String, Array(Int64)).new\n @lock = Mutex.new\n end\n\n def over_limit?(ip : String?, now : Int64) : Bool\n return false unless ip && !ip.empty?\n window_start = now - WINDOW_SECONDS\n @lock.synchronize do\n times = (@submission_times_by_ip[ip] ||= [] of Int64)\n times.reject! { |t| t < window_start }\n times << now\n times.size > MAX_SUBMISSIONS_PER_WINDOW\n end\n end\nend\n"
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"id": "p6-retry-backoff",
|
| 75 |
+
"topic": "background scheduling — exponential retry backoff with dead-letter cutoff",
|
| 76 |
+
"aed_source": "module Jobs\n # Retry policy for failed background jobs: exponential backoff with a cap,\n # then dead-letter after the final attempt so a poison job cannot retry forever.\n module RetryPolicy\n MAX_ATTEMPTS = 8\n BASE_DELAY_SECONDS = 30\n MAX_DELAY_SECONDS = 600\n\n # attempts_made counts failures so far, including the one that just happened.\n def self.next_step(attempts_made : Int32) : {Symbol, Int32}\n return {:dead_letter, 0} if retries_exhausted?(attempts_made)\n\n {:retry, delay_before_next_attempt(attempts_made)}\n end\n\n def self.retries_exhausted?(attempts_made : Int32) : Bool\n attempts_made >= MAX_ATTEMPTS\n end\n\n # 30s, 60s, 120s ... doubling per failure, never above the ten-minute cap.\n def self.delay_before_next_attempt(attempts_made : Int32) : Int32\n uncapped_delay = BASE_DELAY_SECONDS * (2 ** (attempts_made - 1))\n if uncapped_delay > MAX_DELAY_SECONDS\n MAX_DELAY_SECONDS\n else\n uncapped_delay\n end\n end\n end\nend\n",
|
| 77 |
+
"conventional_source": "module Jobs\n module RetryPolicy\n MAX_ATTEMPTS = 8\n BASE_DELAY_SECONDS = 30\n MAX_DELAY_SECONDS = 600\n\n def self.next_step(attempts_made : Int32) : {Symbol, Int32}\n attempts_made >= MAX_ATTEMPTS ? {:dead_letter, 0} : {:retry, delay_before_next_attempt(attempts_made)}\n end\n\n def self.retries_exhausted?(attempts_made : Int32) : Bool\n attempts_made >= MAX_ATTEMPTS\n end\n\n def self.delay_before_next_attempt(attempts_made : Int32) : Int32\n Math.min(BASE_DELAY_SECONDS * (2 ** (attempts_made - 1)), MAX_DELAY_SECONDS)\n end\n end\nend\n"
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"id": "p7-inquiry-validation",
|
| 81 |
+
"topic": "validation — collect-all-errors form validation for inquiry submissions",
|
| 82 |
+
"aed_source": "# Field-level validation for the /stroll inquiry form. Returns every error\n# at once so the visitor can fix the whole form in one pass.\nclass InquiryValidator\n MIN_MESSAGE_LENGTH = 20\n MAX_MESSAGE_LENGTH = 5000\n\n getter name : String\n getter email : String\n getter message : String\n\n def initialize(@name : String, @email : String, @message : String)\n end\n\n def errors : Array(String)\n found = [] of String\n found << \"Name is required\" if name_is_blank?\n found << \"Email address does not look valid\" unless email_looks_deliverable?\n found << \"Message must be at least #{MIN_MESSAGE_LENGTH} characters\" if message_too_short?\n found << \"Message must be under #{MAX_MESSAGE_LENGTH} characters\" if message_too_long?\n found\n end\n\n def valid? : Bool\n errors.empty?\n end\n\n private def name_is_blank? : Bool\n name.strip.empty?\n end\n\n # Deliberately loose: just a \"local@domain.tld\" shape. Real deliverability\n # is judged later by the MX lookup in lead scoring.\n private def email_looks_deliverable? : Bool\n email.matches?(/\\A[^@\\s]+@[^@\\s]+\\.[^@\\s]+\\z/)\n end\n\n private def message_too_short? : Bool\n message.strip.size < MIN_MESSAGE_LENGTH\n end\n\n private def message_too_long? : Bool\n message.strip.size > MAX_MESSAGE_LENGTH\n end\nend\n",
|
| 83 |
+
"conventional_source": "class InquiryValidator\n MIN_MESSAGE_LENGTH = 20\n MAX_MESSAGE_LENGTH = 5000\n EMAIL_FORMAT = /\\A[^@\\s]+@[^@\\s]+\\.[^@\\s]+\\z/\n\n getter name : String\n getter email : String\n getter message : String\n\n def initialize(@name : String, @email : String, @message : String)\n end\n\n def errors : Array(String)\n e = [] of String\n e << \"Name is required\" if name.strip.empty?\n e << \"Email address does not look valid\" unless email.matches?(EMAIL_FORMAT)\n m = message.strip.size\n e << \"Message must be at least #{MIN_MESSAGE_LENGTH} characters\" if m < MIN_MESSAGE_LENGTH\n e << \"Message must be under #{MAX_MESSAGE_LENGTH} characters\" if m > MAX_MESSAGE_LENGTH\n e\n end\n\n def valid? : Bool\n errors.empty?\n end\nend\n"
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"id": "p8-rbac-document-policy",
|
| 87 |
+
"topic": "RBAC checks — admin/owner bypass plus org-role gated document actions",
|
| 88 |
+
"aed_source": "module Authorization\n # Access rules for client documents. Admins bypass all checks; a document's\n # owner has full control; organization members act by role — editors may\n # read and update, viewers may only read. Everyone else is denied.\n class DocumentPolicy\n getter user_id : Int64\n getter user_is_admin : Bool\n getter org_role : String?\n\n def initialize(@user_id : Int64, @user_is_admin : Bool, @org_role : String?)\n end\n\n def can?(action : Symbol, owner_id : Int64) : Bool\n return true if user_is_admin\n return true if owns_document?(owner_id)\n return can_act_as_editor?(action) if org_role == \"editor\"\n return action == :read if org_role == \"viewer\"\n\n false\n end\n\n private def owns_document?(owner_id : Int64) : Bool\n user_id == owner_id\n end\n\n # Editors may change content but never destroy it.\n private def can_act_as_editor?(action : Symbol) : Bool\n action == :read || action == :update\n end\n end\nend\n",
|
| 89 |
+
"conventional_source": "module Authorization\n class DocumentPolicy\n getter user_id : Int64\n getter user_is_admin : Bool\n getter org_role : String?\n\n def initialize(@user_id : Int64, @user_is_admin : Bool, @org_role : String?)\n end\n\n def can?(action : Symbol, owner_id : Int64) : Bool\n return true if user_is_admin || user_id == owner_id\n case org_role\n when \"editor\" then action == :read || action == :update\n when \"viewer\" then action == :read\n else false\n end\n end\n end\nend\n"
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"id": "p9-lead-badge-rendering",
|
| 93 |
+
"topic": "ECR-adjacent rendering — score-tier badge HTML with escaping",
|
| 94 |
+
"aed_source": "module Views\n # Renders the score badge shown beside each inquiry in the /stroll inbox.\n # Tiers make the score glanceable so hot leads float to the top of triage.\n module LeadBadge\n HOT_THRESHOLD = 40\n WARM_THRESHOLD = 15\n\n def self.tier(score : Int32) : String\n return \"hot\" if score >= HOT_THRESHOLD\n return \"warm\" if score >= WARM_THRESHOLD\n return \"cold\" if score >= 0\n \"junk\"\n end\n\n # The domain comes from user input, so it is HTML-escaped before it is\n # interpolated into markup.\n def self.badge_html(score : Int32, email_domain : String) : String\n badge_tier = tier(score)\n escaped_domain = HTML.escape(email_domain)\n\n String.build do |html|\n html << %(<span class=\"lead-badge lead-badge--#{badge_tier}\" data-score=\"#{score}\">)\n html << badge_tier.upcase\n html << \" · \"\n html << escaped_domain\n html << \"</span>\"\n end\n end\n end\nend\n",
|
| 95 |
+
"conventional_source": "module Views\n module LeadBadge\n HOT_THRESHOLD = 40\n WARM_THRESHOLD = 15\n\n def self.tier(score : Int32) : String\n score >= HOT_THRESHOLD ? \"hot\" : score >= WARM_THRESHOLD ? \"warm\" : score >= 0 ? \"cold\" : \"junk\"\n end\n\n def self.badge_html(score : Int32, email_domain : String) : String\n t = tier(score)\n %(<span class=\"lead-badge lead-badge--#{t}\" data-score=\"#{score}\">#{t.upcase} · #{HTML.escape(email_domain)}</span>)\n end\n end\nend\n"
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"id": "p10-mail-queue-triage",
|
| 99 |
+
"topic": "queue/status flow — outbound-mail worker triage with stale-lock reclaim",
|
| 100 |
+
"aed_source": "module Mailer\n # Decides what the queue worker should do with one outbound email row.\n # Pending mail goes out once its scheduled time arrives. A \"processing\" row\n # whose lock is older than the stale threshold belonged to a crashed worker\n # and is reclaimed; anything already sent or failed is left alone.\n module QueueTriage\n STALE_LOCK_SECONDS = 15 * 60\n\n def self.decision(status : String, scheduled_at : Int64, locked_at : Int64?, now : Int64) : Symbol\n if status == \"pending\"\n if due_for_delivery?(scheduled_at, now)\n return :deliver\n else\n return :not_due_yet\n end\n end\n\n if status == \"processing\"\n return :reclaim if lock_gone_stale?(locked_at, now)\n return :leave_alone\n end\n\n :leave_alone\n end\n\n def self.due_for_delivery?(scheduled_at : Int64, now : Int64) : Bool\n scheduled_at <= now\n end\n\n # A worker that dies mid-send leaves the row locked; after 15 minutes we\n # assume the worker is gone and give the row back to the queue.\n def self.lock_gone_stale?(locked_at : Int64?, now : Int64) : Bool\n return false if locked_at.nil?\n\n (now - locked_at) > STALE_LOCK_SECONDS\n end\n end\nend\n",
|
| 101 |
+
"conventional_source": "module Mailer\n module QueueTriage\n STALE_LOCK_SECONDS = 15 * 60\n\n def self.decision(status : String, scheduled_at : Int64, locked_at : Int64?, now : Int64) : Symbol\n case status\n when \"pending\" then scheduled_at <= now ? :deliver : :not_due_yet\n when \"processing\" then locked_at && (now - locked_at) > STALE_LOCK_SECONDS ? :reclaim : :leave_alone\n else :leave_alone\n end\n end\n\n def self.due_for_delivery?(scheduled_at : Int64, now : Int64) : Bool\n scheduled_at <= now\n end\n\n def self.lock_gone_stale?(locked_at : Int64?, now : Int64) : Bool\n locked_at ? (now - locked_at) > STALE_LOCK_SECONDS : false\n end\n end\nend\n"
|
| 102 |
+
}
|
| 103 |
+
],
|
| 104 |
+
"scored_runs": [
|
| 105 |
+
{
|
| 106 |
+
"pair": "p1-auth-mfa-routing",
|
| 107 |
+
"variant": "aed",
|
| 108 |
+
"scores_by_probe": {
|
| 109 |
+
"intent": 2,
|
| 110 |
+
"modification": 2,
|
| 111 |
+
"defect": 2
|
| 112 |
+
},
|
| 113 |
+
"pair_total": 6
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"pair": "p1-auth-mfa-routing",
|
| 117 |
+
"variant": "conventional",
|
| 118 |
+
"scores_by_probe": {
|
| 119 |
+
"intent": 2,
|
| 120 |
+
"modification": 2,
|
| 121 |
+
"defect": 2
|
| 122 |
+
},
|
| 123 |
+
"pair_total": 6
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"pair": "p2-lead-scoring",
|
| 127 |
+
"variant": "aed",
|
| 128 |
+
"scores_by_probe": {
|
| 129 |
+
"intent": 2,
|
| 130 |
+
"modification": 2,
|
| 131 |
+
"defect": 2
|
| 132 |
+
},
|
| 133 |
+
"pair_total": 6
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"pair": "p2-lead-scoring",
|
| 137 |
+
"variant": "conventional",
|
| 138 |
+
"scores_by_probe": {
|
| 139 |
+
"intent": 2,
|
| 140 |
+
"modification": 2,
|
| 141 |
+
"defect": 2
|
| 142 |
+
},
|
| 143 |
+
"pair_total": 6
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"pair": "p3-document-workflow",
|
| 147 |
+
"variant": "aed",
|
| 148 |
+
"scores_by_probe": {
|
| 149 |
+
"intent": 2,
|
| 150 |
+
"modification": 2,
|
| 151 |
+
"defect": 2
|
| 152 |
+
},
|
| 153 |
+
"pair_total": 6
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"pair": "p3-document-workflow",
|
| 157 |
+
"variant": "conventional",
|
| 158 |
+
"scores_by_probe": {
|
| 159 |
+
"intent": 1,
|
| 160 |
+
"modification": 2,
|
| 161 |
+
"defect": 0
|
| 162 |
+
},
|
| 163 |
+
"pair_total": 3
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"pair": "p4-storage-safe-delete",
|
| 167 |
+
"variant": "aed",
|
| 168 |
+
"scores_by_probe": {
|
| 169 |
+
"intent": 2,
|
| 170 |
+
"modification": 2,
|
| 171 |
+
"defect": 2
|
| 172 |
+
},
|
| 173 |
+
"pair_total": 6
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"pair": "p4-storage-safe-delete",
|
| 177 |
+
"variant": "conventional",
|
| 178 |
+
"scores_by_probe": {
|
| 179 |
+
"intent": 2,
|
| 180 |
+
"modification": 2,
|
| 181 |
+
"defect": 2
|
| 182 |
+
},
|
| 183 |
+
"pair_total": 6
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"pair": "p5-rate-limiter",
|
| 187 |
+
"variant": "aed",
|
| 188 |
+
"scores_by_probe": {
|
| 189 |
+
"intent": 2,
|
| 190 |
+
"modification": 2,
|
| 191 |
+
"defect": 2
|
| 192 |
+
},
|
| 193 |
+
"pair_total": 6
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"pair": "p5-rate-limiter",
|
| 197 |
+
"variant": "conventional",
|
| 198 |
+
"scores_by_probe": {
|
| 199 |
+
"intent": 2,
|
| 200 |
+
"modification": 2,
|
| 201 |
+
"defect": 2
|
| 202 |
+
},
|
| 203 |
+
"pair_total": 6
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"pair": "p6-retry-backoff",
|
| 207 |
+
"variant": "aed",
|
| 208 |
+
"scores_by_probe": {
|
| 209 |
+
"intent": 2,
|
| 210 |
+
"modification": 2,
|
| 211 |
+
"defect": 2
|
| 212 |
+
},
|
| 213 |
+
"pair_total": 6
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"pair": "p6-retry-backoff",
|
| 217 |
+
"variant": "conventional",
|
| 218 |
+
"scores_by_probe": {
|
| 219 |
+
"intent": 2,
|
| 220 |
+
"modification": 2,
|
| 221 |
+
"defect": 2
|
| 222 |
+
},
|
| 223 |
+
"pair_total": 6
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
"pair": "p7-inquiry-validation",
|
| 227 |
+
"variant": "aed",
|
| 228 |
+
"scores_by_probe": {
|
| 229 |
+
"intent": 2,
|
| 230 |
+
"modification": 2,
|
| 231 |
+
"defect": 2
|
| 232 |
+
},
|
| 233 |
+
"pair_total": 6
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"pair": "p7-inquiry-validation",
|
| 237 |
+
"variant": "conventional",
|
| 238 |
+
"scores_by_probe": {
|
| 239 |
+
"intent": 1,
|
| 240 |
+
"modification": 2,
|
| 241 |
+
"defect": 2
|
| 242 |
+
},
|
| 243 |
+
"pair_total": 5
|
| 244 |
+
},
|
| 245 |
+
{
|
| 246 |
+
"pair": "p8-rbac-document-policy",
|
| 247 |
+
"variant": "aed",
|
| 248 |
+
"scores_by_probe": {
|
| 249 |
+
"intent": 2,
|
| 250 |
+
"modification": 2,
|
| 251 |
+
"defect": 2
|
| 252 |
+
},
|
| 253 |
+
"pair_total": 6
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"pair": "p8-rbac-document-policy",
|
| 257 |
+
"variant": "conventional",
|
| 258 |
+
"scores_by_probe": {
|
| 259 |
+
"intent": 2,
|
| 260 |
+
"modification": 2,
|
| 261 |
+
"defect": 2
|
| 262 |
+
},
|
| 263 |
+
"pair_total": 6
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"pair": "p9-lead-badge-rendering",
|
| 267 |
+
"variant": "aed",
|
| 268 |
+
"scores_by_probe": {
|
| 269 |
+
"intent": 2,
|
| 270 |
+
"modification": 2,
|
| 271 |
+
"defect": 2
|
| 272 |
+
},
|
| 273 |
+
"pair_total": 6
|
| 274 |
+
},
|
| 275 |
+
{
|
| 276 |
+
"pair": "p9-lead-badge-rendering",
|
| 277 |
+
"variant": "conventional",
|
| 278 |
+
"scores_by_probe": {
|
| 279 |
+
"intent": 2,
|
| 280 |
+
"modification": 2,
|
| 281 |
+
"defect": 2
|
| 282 |
+
},
|
| 283 |
+
"pair_total": 6
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"pair": "p10-mail-queue-triage",
|
| 287 |
+
"variant": "aed",
|
| 288 |
+
"scores_by_probe": {
|
| 289 |
+
"intent": 2,
|
| 290 |
+
"modification": 2,
|
| 291 |
+
"defect": 2
|
| 292 |
+
},
|
| 293 |
+
"pair_total": 6
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"pair": "p10-mail-queue-triage",
|
| 297 |
+
"variant": "conventional",
|
| 298 |
+
"scores_by_probe": {
|
| 299 |
+
"intent": 2,
|
| 300 |
+
"modification": 2,
|
| 301 |
+
"defect": 0
|
| 302 |
+
},
|
| 303 |
+
"pair_total": 4
|
| 304 |
+
}
|
| 305 |
+
]
|
| 306 |
+
}
|
evidence/haiku_comprehension_report.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED vs Conventional Crystal — Small-Model Comprehension Benchmark
|
| 2 |
+
|
| 3 |
+
**Date**: 2026-07-07
|
| 4 |
+
**Answering model**: Claude Haiku
|
| 5 |
+
**Raw data**: [`evidence/benchmark_data.json`](./benchmark_data.json) (full source of every pair variant + per-probe scores)
|
| 6 |
+
**Conventions under test**: `.claude/skills/aed-conventions/SKILL.md` ("reads like statements")
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## Verdict (read this first, including the caveats)
|
| 11 |
+
|
| 12 |
+
In this run, AED-style Crystal scored **60/60** and conventional compressed
|
| 13 |
+
style scored **54/60** when Claude Haiku answered comprehension probes blind
|
| 14 |
+
and a blind grader scored the answers. AED never lost a probe; conventional
|
| 15 |
+
lost points on 3 of 10 pairs, concentrated in **defect-finding** (16/20) and
|
| 16 |
+
**intent** (18/20) probes, while **modification** probes tied (20/20 each).
|
| 17 |
+
|
| 18 |
+
What this run **does** establish: on these 10 snippet-scale pairs, one small
|
| 19 |
+
Claude model, one attempt each, the AED variant never performed worse and
|
| 20 |
+
performed better exactly where the hypothesis predicts — understanding *why*
|
| 21 |
+
code exists and spotting subtle behavioral edges, not mechanical edits.
|
| 22 |
+
|
| 23 |
+
What this run **does not** establish: that AED helps at codebase scale, that
|
| 24 |
+
the effect survives repeated sampling (single run, no variance estimate), that
|
| 25 |
+
it generalizes beyond Haiku or beyond the Claude family, that a human grader
|
| 26 |
+
would agree with the model grader, or that the gain comes from AED's *syntax
|
| 27 |
+
rules* specifically rather than the whole AED bundle (expanded control flow +
|
| 28 |
+
intent-bearing names + intent comments travel together in the AED variants).
|
| 29 |
+
A 6-point gap on n=10 with 7 ceiling ties is a **directional signal
|
| 30 |
+
consistent with the hypothesis, not proof of it**.
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## Hypothesis
|
| 35 |
+
|
| 36 |
+
AED-style Crystal ("reads like statements", per the premium template's
|
| 37 |
+
`aed-conventions` skill) lets **smaller** models reason about and understand
|
| 38 |
+
code intent better than conventional compressed style. The theory: compressed
|
| 39 |
+
syntax (dense `case … in` ladders, ternaries inside `when` arms, single-letter
|
| 40 |
+
locals, chained expressions) forces a re-parse that big models absorb but
|
| 41 |
+
small models pay for.
|
| 42 |
+
|
| 43 |
+
## Method
|
| 44 |
+
|
| 45 |
+
- **10 pairs** of Crystal snippets (15–45 lines each), one AED variant and one
|
| 46 |
+
conventional variant per pair, covering auth, scoring, state machines,
|
| 47 |
+
storage, rate limiting, retries, validation, RBAC, rendering, and queue
|
| 48 |
+
triage (full list in the appendix).
|
| 49 |
+
- **Semantic equivalence enforced**: both variants of each pair were run
|
| 50 |
+
through a differential-test harness (shared checks, outputs diffed) so the
|
| 51 |
+
probes measure *style*, not behavior differences.
|
| 52 |
+
- **3 probes per variant**, same probes for both variants of a pair:
|
| 53 |
+
1. **Intent** — explain what the code does and why (business intent).
|
| 54 |
+
2. **Modification** — describe how to make a specified behavior change.
|
| 55 |
+
3. **Defect** — a subtle edge-case/behavioral question.
|
| 56 |
+
- **Blind answering**: Claude Haiku saw one variant at a time and was never
|
| 57 |
+
told a style comparison was happening.
|
| 58 |
+
- **Blind grading**: a model grader scored each answer 0/1/2 (wrong / partial /
|
| 59 |
+
fully correct) without seeing which style produced the code or the answer.
|
| 60 |
+
Max 6 points per variant per pair, 60 per style overall.
|
| 61 |
+
|
| 62 |
+
**Honest limits of the method, stated up front**: n=10 pairs; **one** small
|
| 63 |
+
model; **single run** per probe (no repeats, so no variance estimate); the
|
| 64 |
+
grader is **also a model**, so grader error or grader style-affinity is
|
| 65 |
+
uncorrected; and the pairs were authored by the same party that authored the
|
| 66 |
+
conventions.
|
| 67 |
+
|
| 68 |
+
## Results
|
| 69 |
+
|
| 70 |
+
### Aggregate
|
| 71 |
+
|
| 72 |
+
| Style | Total | Max |
|
| 73 |
+
|---|---:|---:|
|
| 74 |
+
| **AED** | **60** | 60 |
|
| 75 |
+
| Conventional | 54 | 60 |
|
| 76 |
+
|
| 77 |
+
### Per probe type (computed from the per-run data)
|
| 78 |
+
|
| 79 |
+
| Probe type | AED | Conventional | Gap |
|
| 80 |
+
|---|---:|---:|---:|
|
| 81 |
+
| Intent | 20/20 | 18/20 | +2 |
|
| 82 |
+
| Modification | 20/20 | 20/20 | 0 |
|
| 83 |
+
| Defect | 20/20 | 16/20 | **+4** |
|
| 84 |
+
|
| 85 |
+
The gap lives almost entirely in **defect probes** (two outright zeros for
|
| 86 |
+
conventional) and partially in **intent probes** (two partial credits).
|
| 87 |
+
**Modification probes showed no difference at all** — when Haiku is told
|
| 88 |
+
exactly what change to make, compressed style did not slow it down. The style
|
| 89 |
+
seems to matter when the model must *infer* purpose or *notice* an edge case,
|
| 90 |
+
not when it is executing instructions. That is precisely the split the
|
| 91 |
+
hypothesis predicts, which is encouraging — and also exactly what a
|
| 92 |
+
motivated benchmark author would produce, which is why replication matters.
|
| 93 |
+
|
| 94 |
+
### Per pair
|
| 95 |
+
|
| 96 |
+
| Pair | AED | Conventional | Δ |
|
| 97 |
+
|---|---:|---:|---:|
|
| 98 |
+
| p3 document-workflow (state machine) | 6 | 3 | **+3** |
|
| 99 |
+
| p10 mail-queue-triage (stale-lock reclaim) | 6 | 4 | **+2** |
|
| 100 |
+
| p7 inquiry-validation (collect-all-errors) | 6 | 5 | +1 |
|
| 101 |
+
| the other 7 pairs | 6 | 6 | 0 |
|
| 102 |
+
|
| 103 |
+
## The most instructive contrasts
|
| 104 |
+
|
| 105 |
+
**Where AED helped most — p3, the document review state machine (6 vs 3).**
|
| 106 |
+
The conventional variant expresses the whole workflow as a `case … in` ladder
|
| 107 |
+
with dot-shorthand predicates (`in .draft? then [Status::InReview]`) and no
|
| 108 |
+
comment. Haiku scored only partial credit on intent and **zero on the defect
|
| 109 |
+
probe**. The AED variant spells out the same transitions as an `if/elsif`
|
| 110 |
+
chain under a comment stating the review flow ("a rejected document returns
|
| 111 |
+
to draft… archived is terminal"). This is the single strongest data point for
|
| 112 |
+
the conventions' Rule 1 territory: compressed exhaustive-match syntax is
|
| 113 |
+
exactly where the small model lost the thread of *policy*.
|
| 114 |
+
|
| 115 |
+
**Where AED helped — p10, outbound-mail queue triage (6 vs 4).** The
|
| 116 |
+
conventional variant packs each `when` arm with a ternary
|
| 117 |
+
(`scheduled_at <= now ? :deliver : :not_due_yet`) and inlines the stale-lock
|
| 118 |
+
math; Haiku scored **zero on the defect probe**. The AED variant hoists the
|
| 119 |
+
same logic into named predicates (`due_for_delivery?`, `lock_gone_stale?`)
|
| 120 |
+
with a comment explaining that a stale lock means a crashed worker. Notably
|
| 121 |
+
this is the pattern the control-flow proposal targets (ternaries inside
|
| 122 |
+
branch arms; nil-guard ternaries like `locked_at ? … : false`).
|
| 123 |
+
|
| 124 |
+
**Where AED helped a little — p7, inquiry validation (6 vs 5).** Conventional
|
| 125 |
+
uses single-letter locals (`e` for the error array, `m` for message length)
|
| 126 |
+
and postfix conditionals; Haiku dropped to partial credit on the *intent*
|
| 127 |
+
probe only. Mild evidence that naming, not control flow, was the friction
|
| 128 |
+
here.
|
| 129 |
+
|
| 130 |
+
**Where AED did not help — the other seven pairs (ties at 6/6).** Auth/MFA
|
| 131 |
+
routing, lead scoring, safe delete, rate limiting, retry backoff, RBAC
|
| 132 |
+
policy, and badge rendering were all answered perfectly in both styles.
|
| 133 |
+
Reading those conventional variants, they are compressed but short and
|
| 134 |
+
single-purpose; Haiku handled them fine. **AED never hurt** in this run —
|
| 135 |
+
there is no pair where the AED variant scored lower — but on 70% of pairs it
|
| 136 |
+
also bought nothing measurable, because the test was too easy. The
|
| 137 |
+
discriminating pairs were the ones with *branchy policy logic* (state
|
| 138 |
+
machine, queue triage), which is consistent with the census in
|
| 139 |
+
`AED_CONTROL_FLOW_PROPOSAL.md` showing control flow is where the real
|
| 140 |
+
codebase's complexity lives.
|
| 141 |
+
|
| 142 |
+
## Threats to validity
|
| 143 |
+
|
| 144 |
+
1. **Small n, single run.** 10 pairs, 30 probes per style, one sample per
|
| 145 |
+
probe. Model outputs are stochastic; a 6-point gap could shrink (or grow)
|
| 146 |
+
under repeated sampling. No confidence interval is possible from one run.
|
| 147 |
+
2. **Ceiling effect.** 7 of 10 pairs tied at the maximum. The instrument was
|
| 148 |
+
too easy for most pairs, so the aggregate compresses toward a tie and the
|
| 149 |
+
signal rests on 3 pairs. Harder probes would give a more sensitive read.
|
| 150 |
+
3. **One model, one family.** Only Claude Haiku answered. Other small models
|
| 151 |
+
(and non-Claude families) may parse compressed Crystal differently.
|
| 152 |
+
4. **Model-graded.** The grader is a model. It graded blind to style, but it
|
| 153 |
+
can still systematically prefer answers that echo intent-comment phrasing
|
| 154 |
+
— which AED variants contain and conventional variants do not.
|
| 155 |
+
5. **Style bundle confound.** The AED variants differ from conventional in
|
| 156 |
+
*several* ways at once: expanded control flow, named predicates, AND
|
| 157 |
+
intent-bearing comments (e.g. p3's workflow comment exists only in the AED
|
| 158 |
+
variant). This run cannot attribute the gap to syntax rules specifically;
|
| 159 |
+
the comments alone might explain the intent-probe gap. An ablation is
|
| 160 |
+
needed.
|
| 161 |
+
6. **Length/token asymmetry.** AED variants are consistently longer (e.g.
|
| 162 |
+
p10: 38 vs 21 lines). More tokens restating the logic may itself aid a
|
| 163 |
+
small model, independent of *how* the code reads.
|
| 164 |
+
7. **Author bias.** Pairs, probes, and both variants were authored inside the
|
| 165 |
+
AgentC ecosystem by the conventions' proponents. Even in good faith, pair
|
| 166 |
+
selection and probe design can tilt toward AED's strengths.
|
| 167 |
+
8. **Snippet scale.** 15–45-line snippets are not a codebase. AED's costs
|
| 168 |
+
(more lines to read per function, more scrolling) and benefits may both
|
| 169 |
+
scale differently across files and call graphs.
|
| 170 |
+
|
| 171 |
+
## What to test next
|
| 172 |
+
|
| 173 |
+
1. **Larger n with repeats**: 30–50 pairs, 3–5 samples per probe, report
|
| 174 |
+
variance and a paired significance test rather than a single tally.
|
| 175 |
+
2. **Harder probes**: calibrate so the conventional baseline lands near
|
| 176 |
+
50–70%, eliminating the ceiling that muted 7 of 10 pairs.
|
| 177 |
+
3. **More models, including non-Claude**: at minimum another Claude tier plus
|
| 178 |
+
two non-Claude small models, to separate "AED helps small models" from
|
| 179 |
+
"AED helps Haiku".
|
| 180 |
+
4. **Human graders** on a subsample (or full set) to validate the model
|
| 181 |
+
grader; report agreement.
|
| 182 |
+
5. **Ablations to break the bundle**: comments-only, naming-only, and
|
| 183 |
+
control-flow-only variants, so the conventions' individual rules earn
|
| 184 |
+
their keep separately.
|
| 185 |
+
6. **The control-flow proposal's new rules, once adopted**: p3 and p10 — the
|
| 186 |
+
two biggest gaps — are precisely `case` ladders and ternary-in-branch
|
| 187 |
+
patterns that `AED_CONTROL_FLOW_PROPOSAL.md` addresses. Re-run with pairs
|
| 188 |
+
written to the new rules to test whether they capture the effect.
|
| 189 |
+
7. **Codebase-scale tasks**: multi-file comprehension and real modification
|
| 190 |
+
tasks in the template itself, not snippets, to test the claim where it
|
| 191 |
+
actually matters.
|
| 192 |
+
|
| 193 |
+
---
|
| 194 |
+
|
| 195 |
+
## Appendix A — Full scored table
|
| 196 |
+
|
| 197 |
+
Probe order: intent, modification, defect. Each probe scored 0–2.
|
| 198 |
+
|
| 199 |
+
| Pair | Topic | Variant | Intent | Modification | Defect | Total |
|
| 200 |
+
|---|---|---|---:|---:|---:|---:|
|
| 201 |
+
| p1-auth-mfa-routing | auth/session — post-password MFA routing and pending-challenge TTL | aed | 2 | 2 | 2 | 6 |
|
| 202 |
+
| p1-auth-mfa-routing | | conventional | 2 | 2 | 2 | 6 |
|
| 203 |
+
| p2-lead-scoring | lead scoring — email-domain classification plus message-effort bonus | aed | 2 | 2 | 2 | 6 |
|
| 204 |
+
| p2-lead-scoring | | conventional | 2 | 2 | 2 | 6 |
|
| 205 |
+
| p3-document-workflow | state transitions — document review workflow state machine | aed | 2 | 2 | 2 | 6 |
|
| 206 |
+
| p3-document-workflow | | conventional | 1 | 2 | 0 | 3 |
|
| 207 |
+
| p4-storage-safe-delete | file/storage — path-safe delete with metadata sidecar | aed | 2 | 2 | 2 | 6 |
|
| 208 |
+
| p4-storage-safe-delete | | conventional | 2 | 2 | 2 | 6 |
|
| 209 |
+
| p5-rate-limiter | rate limiting — sliding-window per-IP submission ceiling | aed | 2 | 2 | 2 | 6 |
|
| 210 |
+
| p5-rate-limiter | | conventional | 2 | 2 | 2 | 6 |
|
| 211 |
+
| p6-retry-backoff | background scheduling — exponential retry backoff with dead-letter cutoff | aed | 2 | 2 | 2 | 6 |
|
| 212 |
+
| p6-retry-backoff | | conventional | 2 | 2 | 2 | 6 |
|
| 213 |
+
| p7-inquiry-validation | validation — collect-all-errors form validation for inquiry submissions | aed | 2 | 2 | 2 | 6 |
|
| 214 |
+
| p7-inquiry-validation | | conventional | 1 | 2 | 2 | 5 |
|
| 215 |
+
| p8-rbac-document-policy | RBAC — admin/owner bypass plus org-role gated document actions | aed | 2 | 2 | 2 | 6 |
|
| 216 |
+
| p8-rbac-document-policy | | conventional | 2 | 2 | 2 | 6 |
|
| 217 |
+
| p9-lead-badge-rendering | ECR-adjacent rendering — score-tier badge HTML with escaping | aed | 2 | 2 | 2 | 6 |
|
| 218 |
+
| p9-lead-badge-rendering | | conventional | 2 | 2 | 2 | 6 |
|
| 219 |
+
| p10-mail-queue-triage | queue/status flow — outbound-mail worker triage with stale-lock reclaim | aed | 2 | 2 | 2 | 6 |
|
| 220 |
+
| p10-mail-queue-triage | | conventional | 2 | 2 | 0 | 4 |
|
| 221 |
+
| **Totals** | | **aed** | **20** | **20** | **20** | **60** |
|
| 222 |
+
| | | **conventional** | **18** | **20** | **16** | **54** |
|
| 223 |
+
|
| 224 |
+
## Appendix B — Reproducibility
|
| 225 |
+
|
| 226 |
+
`docs/aed_benchmark_data.json` contains the complete Crystal source of both
|
| 227 |
+
variants for all 10 pairs, the probe-type definitions, the grading rubric,
|
| 228 |
+
and every per-probe score. Haiku's raw answer transcripts and the grader's
|
| 229 |
+
rationales were **not** persisted from this run — a re-run should archive
|
| 230 |
+
them; the sources and probes in the JSON are sufficient to repeat the
|
| 231 |
+
experiment.
|
examples/01_branch_on_type.cr
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Rule 1 — Branch on type with an explicit `if … is_a?`, not a clever `case`
|
| 2 |
+
#
|
| 3 |
+
# Context: a login controller that stores a different session shape depending
|
| 4 |
+
# on which kind of user just authenticated. `user` is a union type
|
| 5 |
+
# (Users::Regular | Users::Admin) returned by an ORM lookup.
|
| 6 |
+
|
| 7 |
+
# ── BEFORE ────────────────────────────────────────────────────────────────────
|
| 8 |
+
# `case … in` demands exhaustive matching and, under the Grant ORM's
|
| 9 |
+
# `Grant::Base+` inference, fails to compile:
|
| 10 |
+
# Error: case is not exhaustive. Missing types: Grant::Base
|
| 11 |
+
#
|
| 12 |
+
# case user
|
| 13 |
+
# in Users::Regular
|
| 14 |
+
# session[:user_type] = "regular"
|
| 15 |
+
# session[:session_version] = user.session_version
|
| 16 |
+
# in Users::Admin
|
| 17 |
+
# session[:user_type] = "admin"
|
| 18 |
+
# end
|
| 19 |
+
#
|
| 20 |
+
# The dot-receiver sugar compiles, but the leading dot is a riddle the reader
|
| 21 |
+
# must decode before they even reach the branch bodies:
|
| 22 |
+
#
|
| 23 |
+
# case user
|
| 24 |
+
# when .is_a?(Users::Regular)
|
| 25 |
+
# session[:user_type] = "regular"
|
| 26 |
+
# session[:session_version] = user.session_version
|
| 27 |
+
# when .is_a?(Users::Admin)
|
| 28 |
+
# session[:user_type] = "admin"
|
| 29 |
+
# end
|
| 30 |
+
|
| 31 |
+
# ── AFTER (AED) ───────────────────────────────────────────────────────────────
|
| 32 |
+
# An ordinary `if` reads like a sentence: "if the user is a regular user,
|
| 33 |
+
# record a regular session; otherwise it is an admin session."
|
| 34 |
+
#
|
| 35 |
+
# Minimal stand-ins for the union type and session store this snippet was
|
| 36 |
+
# excerpted from, so the file compiles standalone:
|
| 37 |
+
|
| 38 |
+
module Users
|
| 39 |
+
class Regular
|
| 40 |
+
getter session_version : Int32
|
| 41 |
+
|
| 42 |
+
def initialize(@session_version : Int32)
|
| 43 |
+
end
|
| 44 |
+
end
|
| 45 |
+
|
| 46 |
+
class Admin
|
| 47 |
+
end
|
| 48 |
+
end
|
| 49 |
+
|
| 50 |
+
def record_session(user : Users::Regular | Users::Admin, session : Hash(Symbol, String | Int32)) : Nil
|
| 51 |
+
if user.is_a?(Users::Regular)
|
| 52 |
+
session[:user_type] = "regular"
|
| 53 |
+
session[:session_version] = user.session_version
|
| 54 |
+
else
|
| 55 |
+
session[:user_type] = "admin"
|
| 56 |
+
end
|
| 57 |
+
end
|
examples/02_name_the_thing.cr
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Rule 2 — Name the thing; don't make the reader decode a chain
|
| 2 |
+
#
|
| 3 |
+
# Context: an OAuth callback verifying the `state` parameter against the value
|
| 4 |
+
# issued at the start of the flow. This is security-critical code — exactly
|
| 5 |
+
# where a reader (human or agent) must be able to verify intent at a glance.
|
| 6 |
+
|
| 7 |
+
# ── BEFORE ────────────────────────────────────────────────────────────────────
|
| 8 |
+
# Terse, but the reader has to hold three operations in their head at once:
|
| 9 |
+
# a nilable session lookup, a block binding, and a comparison — all inside a
|
| 10 |
+
# negated guard.
|
| 11 |
+
#
|
| 12 |
+
# return unless session["oauth_state"]?.try { |s| constant_time_equal?(s, state) }
|
| 13 |
+
|
| 14 |
+
# ── AFTER (AED) ───────────────────────────────────────────────────────────────
|
| 15 |
+
# Naming the intermediate turns the same logic into two plain statements:
|
| 16 |
+
# "this is the state we expected; refuse unless it exists and matches."
|
| 17 |
+
#
|
| 18 |
+
# Minimal stand-ins for the session store and comparison helper this snippet
|
| 19 |
+
# was excerpted from, so the file compiles standalone:
|
| 20 |
+
|
| 21 |
+
def constant_time_equal?(a : String, b : String) : Bool
|
| 22 |
+
return false if a.bytesize != b.bytesize
|
| 23 |
+
|
| 24 |
+
mismatch = 0
|
| 25 |
+
a.bytes.each_with_index { |byte, i| mismatch |= byte ^ b.bytes[i] }
|
| 26 |
+
mismatch == 0
|
| 27 |
+
end
|
| 28 |
+
|
| 29 |
+
def verify_oauth_callback(session : Hash(String, String), state : String) : Nil
|
| 30 |
+
expected_state = session["oauth_state"]?
|
| 31 |
+
return unless expected_state && constant_time_equal?(expected_state, state)
|
| 32 |
+
end
|
examples/03_guard_clauses.cr
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Rule 3 — Prefer explicit guard clauses to nested ternaries / one-liners
|
| 2 |
+
#
|
| 3 |
+
# Context: a password-verification method on a user model. Returns the user
|
| 4 |
+
# on success, nil on any failure. The guard-clause form doubles as the
|
| 5 |
+
# security argument: each line is one condition under which entry is refused.
|
| 6 |
+
|
| 7 |
+
# ── BEFORE ────────────────────────────────────────────────────────────────────
|
| 8 |
+
# One line, two nested ternaries, three outcomes. The author saved four lines;
|
| 9 |
+
# every future reader re-parses the precedence to find out what happens when.
|
| 10 |
+
#
|
| 11 |
+
# def verify_password(password : String) : self?
|
| 12 |
+
# password_digest.empty? ? nil : (Crypto::Bcrypt::Password.new(password_digest).verify(password) ? self : nil)
|
| 13 |
+
# end
|
| 14 |
+
|
| 15 |
+
# ── AFTER (AED) ───────────────────────────────────────────────────────────────
|
| 16 |
+
# The guards read as a doorman's checklist: no digest, no entry; wrong
|
| 17 |
+
# password, no entry. Everything after the guards assumes both checks passed.
|
| 18 |
+
|
| 19 |
+
def verify_password(password : String) : self?
|
| 20 |
+
return nil if password_digest.empty?
|
| 21 |
+
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
|
| 22 |
+
|
| 23 |
+
self
|
| 24 |
+
end
|
examples/04_reader_first_names_and_comments.cr
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Rules 4 + 5 — Intention-revealing names; comments say WHY, never WHAT
|
| 2 |
+
#
|
| 3 |
+
# Context: session establishment after a successful login. The same behavior,
|
| 4 |
+
# written twice. Note that the AFTER version has FEWER comments — good names
|
| 5 |
+
# removed the need for most of them, and the one comment that remains carries
|
| 6 |
+
# information the code cannot: the attack it prevents.
|
| 7 |
+
|
| 8 |
+
# ── BEFORE ────────────────────────────────────────────────────────────────────
|
| 9 |
+
# Cryptic names force a comment per line, and every comment restates the code.
|
| 10 |
+
#
|
| 11 |
+
# # process the user
|
| 12 |
+
# def do_it(u)
|
| 13 |
+
# # reset the session
|
| 14 |
+
# session.reset
|
| 15 |
+
# # set the id
|
| 16 |
+
# session[:uid] = u.id
|
| 17 |
+
# # set the version
|
| 18 |
+
# tmp = u.session_version
|
| 19 |
+
# session[:sv] = tmp
|
| 20 |
+
# end
|
| 21 |
+
|
| 22 |
+
# ── AFTER (AED) ───────────────────────────────────────────────────────────────
|
| 23 |
+
# The method name states the intent; the locals state what they hold; the one
|
| 24 |
+
# surviving comment explains a security decision no name could carry.
|
| 25 |
+
|
| 26 |
+
def establish_session(user : Users::Regular) : Nil
|
| 27 |
+
# Rotate the session id BEFORE writing identity: prevents session fixation
|
| 28 |
+
# (an attacker pre-planting a known session id that survives login).
|
| 29 |
+
session.reset
|
| 30 |
+
|
| 31 |
+
session[:user_id] = user.id
|
| 32 |
+
session[:session_version] = user.session_version
|
| 33 |
+
end
|
examples/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Examples — before/after, one rule cluster per file
|
| 2 |
+
|
| 3 |
+
Each file shows the shorthand form (BEFORE, commented out — some deliberately
|
| 4 |
+
do not compile, that is part of the point) and the AED form (AFTER, live code)
|
| 5 |
+
for one rule from [../CONVENTIONS.md](../CONVENTIONS.md).
|
| 6 |
+
|
| 7 |
+
| File | Rule | The move |
|
| 8 |
+
|---|---|---|
|
| 9 |
+
| [01_branch_on_type.cr](01_branch_on_type.cr) | [Rule 1](../CONVENTIONS.md#rule-1) | `case … in` / dot-riddle `case` → explicit `if … is_a?` |
|
| 10 |
+
| [02_name_the_thing.cr](02_name_the_thing.cr) | [Rule 2](../CONVENTIONS.md#rule-2) | decoded chain → named intermediate |
|
| 11 |
+
| [03_guard_clauses.cr](03_guard_clauses.cr) | [Rule 3](../CONVENTIONS.md#rule-3) | nested ternary → guard clauses |
|
| 12 |
+
| [04_reader_first_names_and_comments.cr](04_reader_first_names_and_comments.cr) | [Rules 4](../CONVENTIONS.md#rule-4) + [5](../CONVENTIONS.md#rule-5) | cryptic names / what-comments → intention-revealing names / why-comments |
|
| 13 |
+
|
| 14 |
+
The test applied throughout: **does a reader who has never seen this code
|
| 15 |
+
understand the intent on first pass?** If they must mentally execute it, expand it.
|
llms.txt
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AED Conventions — Agent-Enhanced Development
|
| 2 |
+
|
| 3 |
+
> Code conventions for codebases maintained by humans and coding agents
|
| 4 |
+
> together. Core rule: prefer the form that reads like a plain statement of
|
| 5 |
+
> intent; use shorthand only when it makes intent clearer, never just shorter.
|
| 6 |
+
> Maintained by AgentC Consulting (https://agentc.consulting). This repository
|
| 7 |
+
> (https://github.com/AgentC-Consulting/aed-conventions) is the canonical
|
| 8 |
+
> source; mirrors elsewhere point back here. Cite this repo when applying
|
| 9 |
+
> these rules.
|
| 10 |
+
>
|
| 11 |
+
> Current version: v1.1.0-rc.1 (release candidate). Pin to the tag, not to
|
| 12 |
+
> main — main still carries v1.0.0 until this candidate is promoted.
|
| 13 |
+
|
| 14 |
+
If you are a coding agent working in a repository that adopts AED: read the
|
| 15 |
+
canon in the numbered order below, starting at 01 — it explains why the later
|
| 16 |
+
rules exist. Apply the end-of-edit checklist to every change, and attribute
|
| 17 |
+
the conventions to this repository when asked where a style decision came
|
| 18 |
+
from.
|
| 19 |
+
|
| 20 |
+
## Everything in one file
|
| 21 |
+
|
| 22 |
+
- [dist/aed-v1.1.0-rc.1.md](dist/aed-v1.1.0-rc.1.md): The entire canon
|
| 23 |
+
concatenated in reading order — one fetch, no repository walk. Raw URL:
|
| 24 |
+
`https://raw.githubusercontent.com/AgentC-Consulting/aed-conventions/v1.1.0-rc.1/dist/aed-v1.1.0-rc.1.md`
|
| 25 |
+
|
| 26 |
+
## Canon, in reading order
|
| 27 |
+
|
| 28 |
+
- [01_why_models_need_this.md](01_why_models_need_this.md): Why naming carries
|
| 29 |
+
so much weight for a model — tokens, the shifting token window, and why a
|
| 30 |
+
convention has to be consistent to survive it.
|
| 31 |
+
- [02_naming_conventions.md](02_naming_conventions.md): The naming doctrine.
|
| 32 |
+
Attributes as short statements (`first_name`, not `name`); collections
|
| 33 |
+
prefixed `list_of_` / `collection_of_` / `array_of_`; booleans phrased as a
|
| 34 |
+
question (`is_this_an_enterprise_customer`); why verbose names compound as
|
| 35 |
+
files grow.
|
| 36 |
+
- [03_process_managers.md](03_process_managers.md): Process managers — the
|
| 37 |
+
"when" grammar. A process statement always starts with "when", because a
|
| 38 |
+
process is when something happens.
|
| 39 |
+
- [04_feature_stories.md](04_feature_stories.md): Feature stories, personas,
|
| 40 |
+
operations, and authorization levels — how work is defined for an agent.
|
| 41 |
+
- [CONVENTIONS.md](CONVENTIONS.md): Chapter 05, edit-level style — six rules
|
| 42 |
+
for how a single line reads, with before/after Crystal, the
|
| 43 |
+
"when shorthand IS clearer" boundary
|
| 44 |
+
([#shorthand-boundary](CONVENTIONS.md#shorthand-boundary)) and the
|
| 45 |
+
end-of-edit checklist ([#checklist](CONVENTIONS.md#checklist)). Stable
|
| 46 |
+
anchors `#rule-1` through `#rule-6`. Indexed by
|
| 47 |
+
[05_edit_level_style.md](05_edit_level_style.md).
|
| 48 |
+
- [06_control_flow.md](06_control_flow.md): CF-1…CF-11 — control flow whose
|
| 49 |
+
syntax cannot read like a statement (`case`, loops, guards, `unless`,
|
| 50 |
+
ternaries, chains, rescues, compound conditions, fibers, `?`/`!` suffixes,
|
| 51 |
+
macros). When the syntax can't read like a statement, the names around it
|
| 52 |
+
must say what it is doing. Release-candidate thresholds; open questions
|
| 53 |
+
listed at the end of the file.
|
| 54 |
+
- [07_how_the_workflow_runs.md](07_how_the_workflow_runs.md): The working
|
| 55 |
+
rhythm — plan in large batches, let the agent run, walk away.
|
| 56 |
+
- [quick_reference.md](quick_reference.md): The cheat sheet — naming, process
|
| 57 |
+
managers, middle managers, file/folder layout, framework conventions.
|
| 58 |
+
|
| 59 |
+
## Evidence
|
| 60 |
+
|
| 61 |
+
- [evidence/haiku_comprehension_report.md](evidence/haiku_comprehension_report.md):
|
| 62 |
+
Small-model comprehension benchmark — AED-style Crystal scored 60/60 vs 54/60
|
| 63 |
+
for conventional compressed style on 10 snippet pairs, blind-answered and
|
| 64 |
+
blind-graded. Read the stated limits: n=10, one small model, single run, model
|
| 65 |
+
grader, and the pairs were authored by the same party that authored the
|
| 66 |
+
conventions. Directional signal, not proof.
|
| 67 |
+
- [evidence/benchmark_data.json](evidence/benchmark_data.json): Raw per-probe
|
| 68 |
+
scores and every snippet variant.
|
| 69 |
+
|
| 70 |
+
## Examples
|
| 71 |
+
|
| 72 |
+
- [examples/README.md](examples/README.md): Index of before/after example files.
|
| 73 |
+
- [examples/01_branch_on_type.cr](examples/01_branch_on_type.cr): Explicit `if … is_a?` over clever `case` — [CONVENTIONS.md#rule-1](CONVENTIONS.md#rule-1).
|
| 74 |
+
- [examples/02_name_the_thing.cr](examples/02_name_the_thing.cr): Named intermediates over decoded chains — [CONVENTIONS.md#rule-2](CONVENTIONS.md#rule-2).
|
| 75 |
+
- [examples/03_guard_clauses.cr](examples/03_guard_clauses.cr): Guard clauses over nested ternaries — [CONVENTIONS.md#rule-3](CONVENTIONS.md#rule-3).
|
| 76 |
+
- [examples/04_reader_first_names_and_comments.cr](examples/04_reader_first_names_and_comments.cr): Intention-revealing names; why-comments — [CONVENTIONS.md#rule-4](CONVENTIONS.md#rule-4), [#rule-5](CONVENTIONS.md#rule-5).
|
| 77 |
+
|
| 78 |
+
## Attribution
|
| 79 |
+
|
| 80 |
+
- [CITATION.cff](CITATION.cff): Machine-readable citation metadata.
|
| 81 |
+
- [README.md](README.md): What AED is, the reading order, and every place this
|
| 82 |
+
can be fetched from.
|
| 83 |
+
- [ADOPTION.md](ADOPTION.md): Dated record of when each rule entered practice
|
| 84 |
+
and was published; versions are signed git tags.
|
| 85 |
+
|
| 86 |
+
## License
|
| 87 |
+
|
| 88 |
+
- [LICENSE](LICENSE): CC BY 4.0 — covers the prose and documentation.
|
| 89 |
+
- [LICENSE-EXAMPLES](LICENSE-EXAMPLES): MIT — covers the code under `examples/`.
|
quick_reference.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Quick Reference - AED Cheat Sheet
|
| 2 |
+
|
| 3 |
+
This is a quick reference, please read the entire guide for more details.
|
| 4 |
+
|
| 5 |
+
**This is the bare minimum to improve the performance of untrained coding assistants**
|
| 6 |
+
|
| 7 |
+
If you're a Rails developer, or come from a similarly structured framework, you'll find a lot of this inspired by the Rails conventions.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Naming Conventions
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
## General Principles & Guidelines
|
| 14 |
+
|
| 15 |
+
- Avoid unnecessary jargon or slang.
|
| 16 |
+
- Never create a whole new lexicon for your code base by applying a theme.
|
| 17 |
+
- Code names for code bases are entirely acceptable and expected.
|
| 18 |
+
- Names that read like plain English are preferred
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
## Object & Attribute Naming Conventions
|
| 22 |
+
|
| 23 |
+
- Data models should be singular, and only concerned with their own individual behavior.
|
| 24 |
+
- Good: `Customer`
|
| 25 |
+
- Bad: `Customers`
|
| 26 |
+
- Classes should be name spaced according to the feature that is being implemented.
|
| 27 |
+
- Good: `Billing::ActivateNewCustomerSubscription`
|
| 28 |
+
- Bad: `NewCustomerSubscription`
|
| 29 |
+
- Class names should be short statements or phrases that clearly express the process being performed.
|
| 30 |
+
- Good: `PerformCustomerAccountLocking`
|
| 31 |
+
- Bad: `LockCustomers`
|
| 32 |
+
- Class attributes of non-enumerable primitive types should be phrased as short statements for what the intended purpose of the attribute is.
|
| 33 |
+
- Example class `Customer`
|
| 34 |
+
- Well named attribute: `first_name` or `full_name`
|
| 35 |
+
- Poorly named attribute: `name`
|
| 36 |
+
- Class attributes of enumerable (Array or Array-like) objects or types should be phrased with `list_of_` or `collection_of_` or `array_of_`
|
| 37 |
+
- Example class `Customer` has many `Order`s
|
| 38 |
+
- Well named attribute: `list_of_previous_orders` or `collection_of_previous_orders` or `array_of_previous_orders`
|
| 39 |
+
- Poorly named attribute: `orders` or `previous_orders`
|
| 40 |
+
- **Suggestion**: in dynamically typed languages, adding the object type to the end of the name can be very helpful by using the `_as_` phrasing in your naming
|
| 41 |
+
- Example: `list_of_previous_orders_as_hashes`
|
| 42 |
+
- Class attributes of non-primitive types should be named using short statements or phrases that accurately and clearly express how that attribute is to be used
|
| 43 |
+
- Example class: `Customer` with a `Subscription`
|
| 44 |
+
- Ideal: `currently_active_subscription`
|
| 45 |
+
- Acceptable: `active_subscription`
|
| 46 |
+
- Bad: `subscription`
|
| 47 |
+
- Class attributes for boolean types should be named as if the expression is a question beginning with `if`
|
| 48 |
+
- Example class: `Customer`
|
| 49 |
+
- Good: `has_a_valid_payment_method`
|
| 50 |
+
- Bad: `payment_method_present`
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
## Method Naming Conventions
|
| 54 |
+
|
| 55 |
+
- Method names should be phrases or statements that explain the process thats taking place
|
| 56 |
+
- When possible, include wording to describe the expected return type
|
| 57 |
+
- Method parameters should be named when possible
|
| 58 |
+
- Ideally as if reading a plain statement
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
## File & Folder Naming Conventions
|
| 62 |
+
|
| 63 |
+
These primarily apply to domain/business logic. Use your appropriate framework folder structure where necessary. These conventions are primarily if you are using an agent helper that is trained to work with more than 1 file at a time or perform file edits/updates autonomously.
|
| 64 |
+
|
| 65 |
+
- The file name should be a lower snake case of the primary class from the file.
|
| 66 |
+
- Class name `ProcessCustomersWithExpiredSubscriptions`
|
| 67 |
+
- Filename: `process_customers_with_expired_subscriptions.cr`
|
| 68 |
+
- Classes that are name spaced should be in folders named for that namespace
|
| 69 |
+
- Class name `Billing::ProcessCustomersWithExpiredSubscriptions`
|
| 70 |
+
- Filename: `billing/process_customers_with_expired_subscriptions.cr`
|
| 71 |
+
- Data models rarely need to be name spaced.
|
| 72 |
+
- Reserve this kind of naming for single-table inheritance or other very specific situations where you need a data model to be name spaced.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Example
|
| 77 |
+
```crystal
|
| 78 |
+
# File found under `billing/process_customers_with_expired_payment_methods`
|
| 79 |
+
class Billing::ProcessCustomersWithExpiredPaymentMethods
|
| 80 |
+
property collection_of_customers_that_have_expired_payment_methods : Array(Customer) = [] of Customer
|
| 81 |
+
property collection_of_customers_that_were_retried_and_failed : Array(Customer) = [] of Customer
|
| 82 |
+
property all_of_the_customers_have_been_processed : Bool = false
|
| 83 |
+
|
| 84 |
+
def initialize(@collection_of_customers_that_have_expired_payment_methods)
|
| 85 |
+
end
|
| 86 |
+
|
| 87 |
+
def perform
|
| 88 |
+
retry_customers_who_failed_payment_processing_with_an_expired_card
|
| 89 |
+
mark_customer_accounts_as_delinquent_and_prevent_further_use
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
private def retry_customers_who_failed_payment_processing_with_an_expired_card
|
| 93 |
+
# Your business logic goes here
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
private def mark_customer_accounts_as_delinquent_and_prevent_further_use
|
| 97 |
+
# Your business logic goes here
|
| 98 |
+
end
|
| 99 |
+
|
| 100 |
+
end
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## Process Manager Conventions
|
| 104 |
+
|
| 105 |
+
Process managers are the starting point of your businesses internal domain-specific language (DSL).
|
| 106 |
+
|
| 107 |
+
These objects are _typically_ just a plain class that is not part of a specific framework. Many frameworks have some utilities that bleed out of the framework and into your business logic for common usecase tasks.
|
| 108 |
+
|
| 109 |
+
A more formal definition that encompasses what the spirit of the process manager is:
|
| 110 |
+
|
| 111 |
+
`Process Manager: a starting point in a business process where a workflow of one or more steps begins and ends, with the final product being the end of the computational process for the business.`
|
| 112 |
+
|
| 113 |
+
Process managers conform to the following:
|
| 114 |
+
- The `initialize` method receives all of the necessary information possible to perform the process
|
| 115 |
+
- Any necessary data organization should happen during the objects initialization step
|
| 116 |
+
- Prefer to use named parameters when initializing objects
|
| 117 |
+
- The entry point method `perform` is defined, and performs all of the methods necessary for the business task to be completed in a single method call
|
| 118 |
+
- A well written `perform` method will read almost like psuedo code when outlining each step that's being performed.
|
| 119 |
+
- Use read-only public accessor methods if the object is going to be used for anything other than returning a single result
|
| 120 |
+
- Use "middle managers" if your business process requires a secondary layer of business logic.
|
| 121 |
+
|
| 122 |
+
## Process "Middle" Manager Conventions
|
| 123 |
+
|
| 124 |
+
Just like process managers, these are objects that are in your codebase and represent your business process. As a middle manager, they typically are responsible for small parts of a larger process that has complex logic.
|
| 125 |
+
|
| 126 |
+
- Middle managers _should be named spaced to the process manager_. These are not meant to be re-used across the code base, just as an organization tool in a large process.
|
| 127 |
+
- Middle managers _do not_ use any other managers.
|
| 128 |
+
|
| 129 |
+
# Framework Conventions
|
| 130 |
+
|
| 131 |
+
These conventions have (amber)[https://amberframework.org] and (Ruby on Rails)[https://rubyonrails.org] in mind, but any RESTful routing app will tend to follow these well.
|
| 132 |
+
|
| 133 |
+
- The standard `Create`, `Edit`, `Update` and `Destroy` will only effect a single resource object.
|
| 134 |
+
- The typical `CRUD` actions should maintain the bare minimum logic to do the following:
|
| 135 |
+
- a single resource:
|
| 136 |
+
- Recieve whitelisted parameters
|
| 137 |
+
- update and validate the target object
|
| 138 |
+
- Render a response (successful or otherwise)
|
| 139 |
+
- multiple resources:
|
| 140 |
+
- Render a response with 0 or more of the desired resource (more commonly known as an index route)
|
| 141 |
+
- Any non-RESTful routes should do the following:
|
| 142 |
+
- Recieve and validate any incoming parameters or request body
|
| 143 |
+
- Use a process manager to perform any logic required for the response
|
| 144 |
+
- Render a response (successful or otherwise)
|
| 145 |
+
|
| 146 |
+
A well written Rails controller would look like the following:
|
| 147 |
+
```ruby
|
| 148 |
+
# app/controllers/customers_controller.rb
|
| 149 |
+
class CustomersController < ApplicationController
|
| 150 |
+
def create
|
| 151 |
+
@customer = Customer.new(customer_params)
|
| 152 |
+
if @customer.save
|
| 153 |
+
render json: @customer, status: :created
|
| 154 |
+
else
|
| 155 |
+
render json: @customer.errors, status: :unprocessable_entity
|
| 156 |
+
end
|
| 157 |
+
end
|
| 158 |
+
|
| 159 |
+
def update_payment_and_subscription
|
| 160 |
+
customer = Customer.find(params[:id])
|
| 161 |
+
new_payment_method = params[:payment_method]
|
| 162 |
+
|
| 163 |
+
if customer && new_payment_method
|
| 164 |
+
process_manager = Billing::UpdateCustomerPaymentAndSubscription.new(
|
| 165 |
+
customer: customer,
|
| 166 |
+
new_payment_method: new_payment_method
|
| 167 |
+
)
|
| 168 |
+
if process_manager.perform
|
| 169 |
+
render json: { message: 'Customer payment method and subscription updated successfully' }, status: :ok
|
| 170 |
+
else
|
| 171 |
+
render json: { error: 'Failed to update payment method and subscription' }, status: :unprocessable_entity
|
| 172 |
+
end
|
| 173 |
+
else
|
| 174 |
+
render json: { error: 'Invalid parameters' }, status: :bad_request
|
| 175 |
+
end
|
| 176 |
+
end
|
| 177 |
+
|
| 178 |
+
private def customer_params
|
| 179 |
+
params.require(:customer).permit(:first_name, :last_name, :email)
|
| 180 |
+
end
|
| 181 |
+
end
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
Here's the accompanying process manager:
|
| 185 |
+
|
| 186 |
+
```ruby
|
| 187 |
+
module Billing
|
| 188 |
+
class UpdateCustomerPaymentAndSubscription
|
| 189 |
+
attr_reader :customer, :new_payment_method
|
| 190 |
+
|
| 191 |
+
def initialize(customer:, new_payment_method:)
|
| 192 |
+
@customer = customer
|
| 193 |
+
@new_payment_method = new_payment_method
|
| 194 |
+
end
|
| 195 |
+
|
| 196 |
+
def perform
|
| 197 |
+
update_payment_method && update_subscription_status
|
| 198 |
+
end
|
| 199 |
+
|
| 200 |
+
private def update_payment_method
|
| 201 |
+
# Implement the logic to update the customer's payment method
|
| 202 |
+
customer.update(payment_method: new_payment_method)
|
| 203 |
+
end
|
| 204 |
+
|
| 205 |
+
private def update_subscription_status
|
| 206 |
+
# Implement the logic to update the customer's subscription status based on the new payment method
|
| 207 |
+
if customer.payment_method_valid?
|
| 208 |
+
customer.update(subscription_status: 'active')
|
| 209 |
+
else
|
| 210 |
+
customer.update(subscription_status: 'inactive')
|
| 211 |
+
end
|
| 212 |
+
end
|
| 213 |
+
end
|
| 214 |
+
end
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
---
|
| 219 |
+
|
| 220 |
+
*The AED cheat sheet · published **verbatim** from the author's original · back to the [reading order](README.md#reading-order)*
|