{"slug": "agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it", "title": "Agent_primitives – tie each app behaviour to the specs that prove it", "summary": "A new Ruby gem called agent_primitives ties each app behaviour to the RSpec examples that prove it, so coding agents can read a repository's intent clauses before planning or changing code. The gem stores capability docs in a docs/primitives/ directory, tags proving RSpec examples with an intent: ID, and ships three commands — evals, guard and proofs — plus ten skills installed via an import command. The evals command fails CI when an intent clause of a built capability doc has no tagged example, or when a tag names an intent clause that does not exist.", "body_md": "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.\n\nThe 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.\n\n`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.\n\nThe 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:\n\n- `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.\n- `guard` reports what a change did to the intent clauses and to the examples that prove them.\n- `proofs` lists the tagged examples that prove each intent clause.\n\nTen 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.\n\nWhat you get:\n\n- A change that removes or weakens a tagged example shows in the `guard` output. If no tagged example remains,`evals` fails.\n- `guard` reports each changed intent clause. The skills tell the agent that only your decision can change an intent clause.\n- 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.\n- Your planning and implementing workflows write the primitives tree. Your review workflow checks it. You do not write documentation as a separate task.\n\nEach capability doc records four things.\n\n| Part | Location | Contents | \n|---|---|---|\n| **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.` | \n| **Shape** | `## Shape` section | Constraints that the implementation must obey, in addition to the framework defaults. | \n| **Evaluations** | `evaluations:` on each intent clause | The spec files that prove the intent clause. | \n| **Provenance** | `## Provenance` section | A history of decisions, rejected alternatives and accepted debt. Agents add entries and never change them. | \n\n```\ndocs/primitives/\n  SCHEMA.md          # the format contract\n  index.md           # one line for each capability doc\n  compilation.md     # constraints for the whole app — you own this file\n  capabilities/      # one capability doc for each capability\n```\n\nEach capability doc keeps its intent clauses and its evaluations in YAML frontmatter. The commands read this frontmatter.\n\nThe `intent:` tag is RSpec metadata:\n\n```\nit \"shows replies nested under their parent\", intent: \"comment_threads#I2\" do\n```\n\nAn example with an `intent:` tag is a tagged example. An evaluation names the spec file that contains the tagged examples for one intent clause.\n\nUse the same tag to run the tagged examples for one intent clause:\n\n```\nbundle exec rspec --tag 'intent:comment_threads#I2'\n```\n\n1. \nAdd the gem to your `Gemfile` :\n\n```\ngem \"agent_primitives\", group: :development\n```\n\n2. \nInstall the gem: \n\n```\nbundle install\n```\n\n3. \nImport the skills. The next section gives the procedure.\n\nThe `import` command copies the ten skills into a directory. Use the directory that your editor reads skills from.\n\n```\nbundle exec agent_primitives import .claude/skills\n```\n\nThe 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.\n\n`import` adds and updates files. It never deletes a file.\n\n- It adds each skill file of the gem that is not in the directory.\n- It updates a skill file of the gem when the version in the gem is different.\n- It does not change a file that is identical to the version in the gem.\n- It does not change other files in the directory. Your own skills stay as they are.\n\nThe command lists each new file and each updated file.\n\nWhen a new version of the gem removes a file, the CHANGELOG names that file. `import` does not delete it. You must delete it.\n\nTo update the skills after a new version of the gem:\n\n1. Run `bundle update agent_primitives` .\n2. Run `bundle exec agent_primitives import <dir>` again.\n3. Examine the changes with `git diff` .\n4. Read the CHANGELOG.\n5. Delete each file that the CHANGELOG names as removed.\n\n| Skill | Purpose | \n|---|---|\n| `primitives-format` | Defines the format of the primitives tree: layout, ownership, capability docs, intent clauses, evaluations and provenance. | \n| `tagging-intent` | Tags the example that proves an intent clause. Decides if an evaluation proves its intent clause. | \n| `running-primitives-checks` | Runs `evals` ,`guard` and`proofs` , and explains their output. | \n| `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. | \n| `closing-out-primitives` | Verifies each task with `proofs` and`guard` . Writes the evaluations, the status and the provenance when the work is complete. | \n| `reviewing-primitives` | Reviews a plan or a change against the primitives tree. Keeps intent tags correct during a spec refactor. | \n| `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. | \n| `maintaining-primitives` | Maintains the primitives tree outside the workflows: trace, update and lint. | \n| `backfilling-primitives` | Writes a capability doc for an existing feature. It asks you about each intent clause before it writes. | \n| `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. | \n\nThree commands check the primitives tree. No command needs a database. No command starts Rails.\n\n`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.\n\nEach `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.\n\n``` bash\n$ bundle exec agent_primitives evals\ndocs/primitives/capabilities/comment_threads.md\n  12:1   E  I3 has no evaluation — a built clause must name the spec that proves it   [clause/unproven]\n\n3 capabilities, 14 clauses — 1 offence\n```\n\nA 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.\n\n`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.\n\nEach `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.\n\n``` bash\n$ bundle exec agent_primitives guard --base main\nspec/system/comment_threads_spec.rb\n  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]\n```\n\n`proofs` is a lookup, not a check. It lists the tagged examples that prove each intent clause. `proofs` always exits 0.\n\nCompare 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.\n\n``` bash\n$ bundle exec agent_primitives proofs\ncomment_threads (built)\n  I1  A reader can reply to any comment.          1 tagged example\n  I2  Replies show nested under their parent.     1 tagged example\n  I3  Threads never nest deeper than 3 levels.    superseded by I4\n  I4  A reader can reply at any depth.            1 tagged example\n\n4 clauses, 3 tagged examples\n```\n\nAdd `evals` to your CI workflow. The job fails when `evals` finds an offence.\n\n```\n- name: Check intent clauses\n  run: bundle exec agent_primitives evals\n```\n\nYou 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.\n\nThe 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.\n\n1. Install the gem and import the skills.\n2. Ask your agent to adopt the primitives tree. The agent loads `bootstrapping-primitives` .\n3. Answer the interview. Then edit the draft `compilation.md` .\n4. 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.\n5. Add `evals` to CI.\n\nDo 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.\n\nYour 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.\n\n```\nWhen docs/primitives/ exists, follow planning-with-primitives § In a requirements spec.\n```\n\nYour planning workflow loads these sections of `planning-with-primitives`:\n\n- § Primitives gate, before the plan has content.\n- § Intent impact block, to name the examples that each intent clause needs.\n- § Citing clauses in tasks, to name the intent clauses that each task serves.\n- § At final approval, to update the status and the provenance of the capability doc.\n- § When the plan is revised, for each change to an approved plan.\n\n```\nWhen docs/primitives/ exists, follow planning-with-primitives.\n```\n\nAn 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.\n\n```\nWhen docs/primitives/ exists and an existing feature has no capability doc, follow backfilling-primitives.\n```\n\nYour 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.\n\n```\nWhen docs/primitives/ exists, follow closing-out-primitives § Before starting work.\n```\n\nYour implementing agent loads two more sections of `closing-out-primitives`:\n\n- § Working from an excerpt. The agent uses the excerpt and does not read `docs/primitives/` .\n- § Verifying one task. The agent runs `proofs` and`guard` before it reports.\n\n```\nWhen docs/primitives/ exists, follow closing-out-primitives § Working from an excerpt and § Verifying one task.\n```\n\nYour plan execution workflow loads these sections of `closing-out-primitives` after the last task:\n\n- § Close-out pass, to write the evaluations, the status and the provenance.\n- § What to report, to tell you what changed in the primitives tree.\n- § 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.\n\n```\nWhen docs/primitives/ exists, follow closing-out-primitives § Close-out pass, § What to report and § When finished work is revised.\n```\n\nYour review workflow loads these sections of `reviewing-primitives`:\n\n- § Inputs, to read the capability doc and the command output.\n- § Checks, to check traceability, the Intent impact block, evaluations and provenance.\n- § Report section, to write the primitives section of the review.\n\n```\nWhen docs/primitives/ exists, follow reviewing-primitives.\n```\n\nThe 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.\n\n```\nBefore you send work to a reviewer, when docs/primitives/ exists, follow running-primitives-checks § Handing the output to a reviewer.\n```\n\nYour 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.\n\n```\nWhen docs/primitives/ exists, follow tagging-intent.\n```\n\nYour 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.\n\n```\nWhen docs/primitives/ exists, follow reviewing-primitives § Auditing tagged examples in a spec refactor.\n```\n\nMIT. See `LICENSE`.", "url": "https://wpnews.pro/news/agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it", "canonical_source": "https://github.com/pitch-sourcery/agent_primitives", "published_at": "2026-11-23 08:42:40+00:00", "updated_at": "2026-11-23 09:14:12.147442+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["agent_primitives", "RSpec", "Ruby", "Gemfile", "bundle"], "also_reported_by": [], "takeaway": "Tag each proving RSpec example with an intent: ID such as intent: \"comment_threads#I2\" and run evals in CI so a capability doc's intent clause without a tagged example fails the build.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it", "markdown": "https://wpnews.pro/news/agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it.md", "text": "https://wpnews.pro/news/agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it.txt", "jsonld": "https://wpnews.pro/news/agent-primitives-tie-each-app-behaviour-to-the-specs-that-prove-it.jsonld"}}