agent_primitives 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da696225c6309f5ba731ae7a8d1b0d8c1e5fd8b50275c0b937cb082a9d357dd1
4
+ data.tar.gz: b8172f0c2222739ed5111d4ecbfa74ab07c434f26edcb65d6476dd73e2c00e05
5
+ SHA512:
6
+ metadata.gz: ea29d512d3e7a236e5b4a1c137d8f5fd8fdef390a17da712c87ab9514d3498e69fc3f02783abebf6607bc17b21fc3c53cb9ac1dbb7490630ce05c61572f6995e
7
+ data.tar.gz: 4590a7a5dbf749bd1ef12a5b87a67ca670de54bbb351914ac240ba157dde683894412d37a58db6b8dbb7b745ba18894109bad081cb076369f089e6aeb5306d20
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-11-15
4
+
5
+ - `evals` no longer reads provenance. It used to infer mid-amendment state from the newest provenance date, and a same-day `backfilled` line hid the `planned` line after it. A `built` doc mid-amendment now fails `clause/unproven` on its new clauses until you set `status: amending`, `plan:`, and its index line.
6
+ - `guard` ranks `amending` with `built`, so `built` → `amending` is not a downgrade. It reports `amending` → `built` as `status/closed-out`.
7
+ - Update the status line in your `docs/primitives/index.md` (and `SCHEMA.md`, if it has one) by hand: `import` does not touch the tree.
8
+ - New skill `integrating-primitives`: adds hooks for the primitives skills to an app's own planning, implementing and reviewing skills, agents and rules. It surveys first and confirms each file and each edit with you before writing. Run `agent_primitives import` again to get it.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris Bellairs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # agent_primitives
2
+
3
+ Code shows what an app does today. Code does not show what the app must continue to do, or why. Code does not show which spec proves each required behaviour. When coding agents write most of the code, no one keeps this knowledge. Each new agent session starts without it.
4
+
5
+ The results are concrete. An agent changes a deliberate decision because the decision looks like a bug. An agent proposes an alternative that you rejected before. An agent deletes or weakens the spec for a required behaviour, and the suite stays green.
6
+
7
+ `agent_primitives` keeps this knowledge in your repository, next to the code. Each capability of the app gets a capability doc. The capability doc states what the capability must do, as numbered intent clauses. Tagged RSpec examples prove each intent clause. Before an agent plans or changes code, it reads the capability doc or an excerpt of it.
8
+
9
+ The primitives tree is the `docs/primitives/` directory. It contains the capability docs. Each RSpec example that proves an intent clause has an `intent:` tag with the ID of that intent clause. Three commands check the primitives tree:
10
+
11
+ - `evals` fails CI when an intent clause of a built capability doc has no tagged example. It also fails when a tag names an intent clause that does not exist.
12
+ - `guard` reports what a change did to the intent clauses and to the examples that prove them.
13
+ - `proofs` lists the tagged examples that prove each intent clause.
14
+
15
+ Ten skills tell your agent when to read, write and check the primitives tree, from planning to review. The `import` command copies these skills into the skills directory of your agent.
16
+
17
+ What you get:
18
+
19
+ - A change that removes or weakens a tagged example shows in the `guard` output. If no tagged example remains, `evals` fails.
20
+ - `guard` reports each changed intent clause. The skills tell the agent that only your decision can change an intent clause.
21
+ - Each capability doc keeps a history of decisions and rejected alternatives. The planning agent reads this history before it proposes an approach. The review agent reports a change that reverses a recorded decision.
22
+ - Your planning and implementing workflows write the primitives tree. Your review workflow checks it. You do not write documentation as a separate task.
23
+
24
+ ## The primitives tree
25
+
26
+ Each capability doc records four things.
27
+
28
+ | Part | Location | Contents |
29
+ | --- | --- | --- |
30
+ | **Intent** | `intent:` in the frontmatter | Numbered intent clauses. Each intent clause states one thing that must be true. `I1 — A reader can reply to any comment.` |
31
+ | **Shape** | `## Shape` section | Constraints that the implementation must obey, in addition to the framework defaults. |
32
+ | **Evaluations** | `evaluations:` on each intent clause | The spec files that prove the intent clause. |
33
+ | **Provenance** | `## Provenance` section | A history of decisions, rejected alternatives and accepted debt. Agents add entries and never change them. |
34
+
35
+ ```
36
+ docs/primitives/
37
+ SCHEMA.md # the format contract
38
+ index.md # one line for each capability doc
39
+ compilation.md # constraints for the whole app — you own this file
40
+ capabilities/ # one capability doc for each capability
41
+ ```
42
+
43
+ Each capability doc keeps its intent clauses and its evaluations in YAML frontmatter. The commands read this frontmatter.
44
+
45
+ The `intent:` tag is RSpec metadata:
46
+
47
+ ```ruby
48
+ it "shows replies nested under their parent", intent: "comment_threads#I2" do
49
+ ```
50
+
51
+ An example with an `intent:` tag is a tagged example. An evaluation names the spec file that contains the tagged examples for one intent clause.
52
+
53
+ Use the same tag to run the tagged examples for one intent clause:
54
+
55
+ ```bash
56
+ bundle exec rspec --tag 'intent:comment_threads#I2'
57
+ ```
58
+
59
+ ## Install
60
+
61
+ 1. Add the gem to your `Gemfile`:
62
+
63
+ ```ruby
64
+ gem "agent_primitives", group: :development
65
+ ```
66
+
67
+ 2. Install the gem:
68
+
69
+ ```bash
70
+ bundle install
71
+ ```
72
+
73
+ 3. Import the skills. The next section gives the procedure.
74
+
75
+ ## Import the skills
76
+
77
+ The `import` command copies the ten skills into a directory. Use the directory that your editor reads skills from.
78
+
79
+ ```bash
80
+ bundle exec agent_primitives import .claude/skills
81
+ ```
82
+
83
+ The directory must exist. If the directory does not exist, `import` stops with an error. Without this rule, a mistyped path would create a directory that no editor reads.
84
+
85
+ `import` adds and updates files. It never deletes a file.
86
+
87
+ - It adds each skill file of the gem that is not in the directory.
88
+ - It updates a skill file of the gem when the version in the gem is different.
89
+ - It does not change a file that is identical to the version in the gem.
90
+ - It does not change other files in the directory. Your own skills stay as they are.
91
+
92
+ The command lists each new file and each updated file.
93
+
94
+ When a new version of the gem removes a file, the CHANGELOG names that file. `import` does not delete it. You must delete it.
95
+
96
+ To update the skills after a new version of the gem:
97
+
98
+ 1. Run `bundle update agent_primitives`.
99
+ 2. Run `bundle exec agent_primitives import <dir>` again.
100
+ 3. Examine the changes with `git diff`.
101
+ 4. Read the CHANGELOG.
102
+ 5. Delete each file that the CHANGELOG names as removed.
103
+
104
+ ## Skills
105
+
106
+ | Skill | Purpose |
107
+ | --- | --- |
108
+ | `primitives-format` | Defines the format of the primitives tree: layout, ownership, capability docs, intent clauses, evaluations and provenance. |
109
+ | `tagging-intent` | Tags the example that proves an intent clause. Decides if an evaluation proves its intent clause. |
110
+ | `running-primitives-checks` | Runs `evals`, `guard` and `proofs`, and explains their output. |
111
+ | `planning-with-primitives` | Writes intent clauses in a requirements spec or a plan, before the tasks. Updates the capability doc when you approve the plan. |
112
+ | `closing-out-primitives` | Verifies each task with `proofs` and `guard`. Writes the evaluations, the status and the provenance when the work is complete. |
113
+ | `reviewing-primitives` | Reviews a plan or a change against the primitives tree. Keeps intent tags correct during a spec refactor. |
114
+ | `bootstrapping-primitives` | Creates the primitives tree in an app. Writes a draft `compilation.md` from a survey of the code and an interview with you. |
115
+ | `maintaining-primitives` | Maintains the primitives tree outside the workflows: trace, update and lint. |
116
+ | `backfilling-primitives` | Writes a capability doc for an existing feature. It asks you about each intent clause before it writes. |
117
+ | `integrating-primitives` | Adds an instruction line for each primitives skill to your own skills, agents and rules. It asks you before it changes a file. |
118
+
119
+ ## Check the primitives tree
120
+
121
+ Three commands check the primitives tree. No command needs a database. No command starts Rails.
122
+
123
+ ### `evals`
124
+
125
+ `evals` checks the capability docs against the `intent:` tags. An active intent clause is an intent clause that is not superseded or retired. Each active intent clause on a built capability doc must name a spec file. Each spec file that an intent clause names must exist. That file must contain a tagged example for the intent clause.
126
+
127
+ Each `intent:` tag must be on an example, not on a group. The tag must name an active intent clause. The evaluations of that intent clause must name the file of the tag. A malformed capability doc or tag also fails. Each failure is an offence. `evals` exits 1 when it finds an offence.
128
+
129
+ ```console
130
+ $ bundle exec agent_primitives evals
131
+ docs/primitives/capabilities/comment_threads.md
132
+ 12:1 E I3 has no evaluation — a built clause must name the spec that proves it [clause/unproven]
133
+
134
+ 3 capabilities, 14 clauses — 1 offence
135
+ ```
136
+
137
+ A capability doc with `status: amending` has shipped, and an approved plan is changing it. The `plan:` key of the doc names that plan. Its intent clauses without evaluations are warnings, not offences. A tag for one of these intent clauses is also a warning. This is also true for the tags of a planned capability doc. The intent clauses that already have evaluations are checked as usual. An amending capability doc without `plan:` is an offence, and so is `plan:` on any other capability doc. When the file that `plan:` names does not exist, `evals` reports a warning. `evals` does not read provenance.
138
+
139
+ ### `guard`
140
+
141
+ `guard` compares the primitives tree with a base revision. It reports each intent clause, evaluation or tagged example that became smaller or different. For example, it reports an intent clause with new words under the same ID. It also reports a tagged example that lost assertions. It does not report growth.
142
+
143
+ Each `guard` finding is a notice. `guard` exits 0 when the comparison runs. An agent reads its own notices. The agent restores each tagged example or assertion that it removed by accident. An agent sends intent notices to you, because only your decision can change intent.
144
+
145
+ ```console
146
+ $ bundle exec agent_primitives guard --base main
147
+ spec/system/comment_threads_spec.rb
148
+ 7:1 N the example proving comment_threads#I2 lost 1 assertion(s) — it still carries the tag while proving less of the clause [proof/weakened]
149
+ ```
150
+
151
+ ### `proofs`
152
+
153
+ `proofs` is a lookup, not a check. It lists the tagged examples that prove each intent clause. `proofs` always exits 0.
154
+
155
+ Compare this list with the examples that the plan names for each intent clause. A planned example that is not in the list has no tag, or does not exist. `proofs --since main` counts the tagged examples for each intent clause that the branch touched. `--format json` also lists the examples that have no tag.
156
+
157
+ ```console
158
+ $ bundle exec agent_primitives proofs
159
+ comment_threads (built)
160
+ I1 A reader can reply to any comment. 1 tagged example
161
+ I2 Replies show nested under their parent. 1 tagged example
162
+ I3 Threads never nest deeper than 3 levels. superseded by I4
163
+ I4 A reader can reply at any depth. 1 tagged example
164
+
165
+ 4 clauses, 3 tagged examples
166
+ ```
167
+
168
+ ### Run `evals` in CI
169
+
170
+ Add `evals` to your CI workflow. The job fails when `evals` finds an offence.
171
+
172
+ ```yaml
173
+ - name: Check intent clauses
174
+ run: bundle exec agent_primitives evals
175
+ ```
176
+
177
+ ## Use it in your workflows
178
+
179
+ You do not write the primitives tree as a separate task. Your planning workflow writes the intent clauses. Your implementing workflow writes the evaluations and the provenance. Your review workflow checks that each change traces to an intent clause.
180
+
181
+ The skills in this gem do not replace your own workflow skills. Each skill below adds the primitives steps to one step of your workflow. Each subsection gives an instruction line. An instruction line is one line of text for your skill or agent instructions. `§` names a section heading in the skill. Paste each instruction line into the matching skill or agent instructions of your app. Each instruction line applies only when `docs/primitives/` exists. The § Hook map of `integrating-primitives` lists every instruction line it proposes; the lines below are the ones most apps need.
182
+
183
+ ### Adoption order
184
+
185
+ 1. Install the gem and import the skills.
186
+ 2. Ask your agent to adopt the primitives tree. The agent loads `bootstrapping-primitives`.
187
+ 3. Answer the interview. Then edit the draft `compilation.md`.
188
+ 4. Ask your agent to integrate the primitives skills. The agent loads `integrating-primitives`, proposes each instruction line below, and asks you before it changes a file. You can also paste the lines yourself.
189
+ 5. Add `evals` to CI.
190
+
191
+ Do not write capability docs for all existing features at once. Planning writes a capability doc for an existing feature the first time that a plan changes it.
192
+
193
+ ### Specifying
194
+
195
+ Your requirements spec workflow loads `planning-with-primitives` § In a requirements spec. The agent reads `index.md` and `compilation.md` before you choose an approach. The agent writes the outcomes of the requirements spec as intent clauses in the capability doc.
196
+
197
+ ```text
198
+ When docs/primitives/ exists, follow planning-with-primitives § In a requirements spec.
199
+ ```
200
+
201
+ ### Planning
202
+
203
+ Your planning workflow loads these sections of `planning-with-primitives`:
204
+
205
+ - § Primitives gate, before the plan has content.
206
+ - § Intent impact block, to name the examples that each intent clause needs.
207
+ - § Citing clauses in tasks, to name the intent clauses that each task serves.
208
+ - § At final approval, to update the status and the provenance of the capability doc.
209
+ - § When the plan is revised, for each change to an approved plan.
210
+
211
+ ```text
212
+ When docs/primitives/ exists, follow planning-with-primitives.
213
+ ```
214
+
215
+ An existing feature can have no capability doc. In this case, § Primitives gate sends the agent to `backfilling-primitives`. The agent interviews you about each intent clause. Then planning continues with the new capability doc.
216
+
217
+ ```text
218
+ When docs/primitives/ exists and an existing feature has no capability doc, follow backfilling-primitives.
219
+ ```
220
+
221
+ ### Implementing
222
+
223
+ Your plan execution workflow loads `closing-out-primitives` § Before starting work. The agent reads the one capability doc and `compilation.md`. Then the agent pastes the relevant excerpts into the prompt of each task.
224
+
225
+ ```text
226
+ When docs/primitives/ exists, follow closing-out-primitives § Before starting work.
227
+ ```
228
+
229
+ Your implementing agent loads two more sections of `closing-out-primitives`:
230
+
231
+ - § Working from an excerpt. The agent uses the excerpt and does not read `docs/primitives/`.
232
+ - § Verifying one task. The agent runs `proofs` and `guard` before it reports.
233
+
234
+ ```text
235
+ When docs/primitives/ exists, follow closing-out-primitives § Working from an excerpt and § Verifying one task.
236
+ ```
237
+
238
+ ### Closing out
239
+
240
+ Your plan execution workflow loads these sections of `closing-out-primitives` after the last task:
241
+
242
+ - § Close-out pass, to write the evaluations, the status and the provenance.
243
+ - § What to report, to tell you what changed in the primitives tree.
244
+ - § When finished work is revised, when you ask for a change to finished work. The agent decides if the change is a bug fix or a change of intent.
245
+
246
+ ```text
247
+ When docs/primitives/ exists, follow closing-out-primitives § Close-out pass, § What to report and § When finished work is revised.
248
+ ```
249
+
250
+ ### Reviewing
251
+
252
+ Your review workflow loads these sections of `reviewing-primitives`:
253
+
254
+ - § Inputs, to read the capability doc and the command output.
255
+ - § Checks, to check traceability, the Intent impact block, evaluations and provenance.
256
+ - § Report section, to write the primitives section of the review.
257
+
258
+ ```text
259
+ When docs/primitives/ exists, follow reviewing-primitives.
260
+ ```
261
+
262
+ The agent that sends work to a reviewer loads `running-primitives-checks` § Handing the output to a reviewer. This agent runs the commands and pastes their output into the review prompt. The reviewer can then work without a shell.
263
+
264
+ ```text
265
+ Before you send work to a reviewer, when docs/primitives/ exists, follow running-primitives-checks § Handing the output to a reviewer.
266
+ ```
267
+
268
+ ### Writing or refactoring specs
269
+
270
+ Your spec-writing workflow loads `tagging-intent`. The agent tags each example that proves an intent clause. The agent also decides if the tagged examples prove the full intent clause.
271
+
272
+ ```text
273
+ When docs/primitives/ exists, follow tagging-intent.
274
+ ```
275
+
276
+ Your spec-refactoring workflow also loads `reviewing-primitives` § Auditing tagged examples in a spec refactor. The agent keeps each tag on its example when examples move, merge or change.
277
+
278
+ ```text
279
+ When docs/primitives/ exists, follow reviewing-primitives § Auditing tagged examples in a spec refactor.
280
+ ```
281
+
282
+ ## License
283
+
284
+ MIT. See `LICENSE`.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Load-path require, as RubyGems and Bundler arrange: run from a checkout with
5
+ # `ruby -Ilib exe/agent_primitives` or `bundle exec`.
6
+ require "agent_primitives/cli"
7
+
8
+ exit AgentPrimitives::CLI.new(ARGV).run