skills/theory-building/SKILL.md
Manually invoked point-of-work workflow for applying Peter Naur's "programming as theory building" during active software work. Use this skill only when the user explicitly names `theory-building`, asks to use the theory-building skill, or explicitly says to apply programming-as-theory- building to the current design, implementation, refactor, review, or AI-generated code. Do not trigger automatically for ordinary architecture, implementation, refactor, review, debug, documentation, AI-code, domain model, or maintainability tasks.
npx skillsauth add ferueda/agent-skills theory-buildingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill as a point-of-work lens. It applies while designing, implementing, refactoring, reviewing, or accepting generated code. Treat understanding as the primary artifact and code as the expression of that understanding. The goal is not to slow down the work; it is to make sure the change strengthens the system's shared theory instead of adding code that only happens to pass locally.
Use this skill only when the user explicitly invokes it. Good triggers include:
theory-building on this change."By default, return theory-building output in the conversation only. Do not
create, edit, or update CONTEXT.md, ADRs, issues, plans, task lists, source
comments, or any other files unless the user explicitly says to write it down
and specifies where and how it should be written.
Use this skill during active work:
Pair it with theory-building-review this way:
theory-building-review finds theory gaps across recent work.theory-building helps design and implement the specific fixes without
introducing more drift.Use this skill when the user is inside one concrete change and needs judgment at the point of work.
| Situation | Use this skill for |
|---|---|
| Designing a feature | Establish the domain model, invariant, and design fit before implementation. |
| Implementing a change | Keep names, boundaries, and tests aligned with the current theory. |
| Reviewing a PR or diff | Check whether the change belongs in the model, after concrete bugs and risks. |
| Accepting AI-generated code | Inspect assumptions before adopting the code. |
| Fixing a finding from theory-building-review | Design the specific correction without adding more drift. |
Do not use this skill for broad repository audits, weekly reviews, or
post-feature drift checks. Use theory-building-review for those.
Choose the lightest mode that can protect the work.
Prefer the 5-minute check unless the change is high-risk or conceptually ambiguous.
A good programmer understands the mapping between world and program. You should be able to say: "This part of the code corresponds to this real-world activity, rule, object, constraint, or workflow." You should also be able to go the other way: "This real-world case is handled here, for this reason."
Treat every codebase as having three layers:
Most engineering dysfunction happens when people work only at the program layer. They move code around, add endpoints, create tables, patch bugs, or ask AI to generate implementations, but they do not update or preserve the theory.
Modification is the real test of understanding. Software inevitably changes, and the hard part is not editing text; it is judging how a new requirement relates to the existing theory of the system. Many implementations can produce the same external behavior, but only some fit the system's underlying theory.
Before making or accepting a meaningful code change, establish the theory:
If those answers are unclear, clarify them before treating the implementation as done.
For non-trivial design, implementation, review, refactor, or debugging tasks:
CONTEXT.md, ADRs, READMEs, and nearby
naming before proposing new concepts.Only show this note to the user when it helps them evaluate the work. Keep it brief; the value is in disciplined thought, not ceremony.
When using, reviewing, or accepting generated code, pause before adoption:
Generated code is acceptable when it expresses the theory cleanly. It is risky when it smuggles in a different theory of the system.
Use this fast acceptance test:
When editing code:
In addition to correctness, review whether the change belongs in the system:
For code review requests, still lead with concrete bugs and risks. Add theory or architectural-fit concerns when they affect maintainability or future change.
Surface durable understanding in the response so the user can decide what to do with it:
CONTEXT.md or an equivalent glossary for domain vocabulary and concept
boundaries only when the user explicitly asks you to write there. Keep it
free of implementation details.Do not create documentation for every small change. Do not write documentation or task artifacts by default. Recommend capturing context only when the decision would otherwise be lost and future work would pay for that loss; then wait for the user to say exactly where and how to write it.
Treat this skill as a small procedural artifact that improves through real work. After using it, notice whether the output was useful.
Make only small edits to the skill at a time, then validate them on the next similar task. Keep changes that make the work clearer, safer to modify, or easier to explain.
Avoid unsupported comparative or editorial claims such as "better than most legacy modules" unless the user asks for qualitative judgment. Prefer phrasing that ties conclusions to observed structure, behavior, tests, or documentation.
Example:
The implementation mostly supports a coherent theory: services validate user
intent, the manager owns local billing objects, tasks own external side effects,
and sync reconciles external truth.
A theory pass explains the model, mappings, invariants, pressure points, and next moves. It should not silently become an implementation plan or start making changes. If the user asks to implement, sequence the work explicitly and then execute within the approved scope.
Return the analysis in the conversation using this structure when it fits the request:
**Theory**
[Core domain model, ownership, and durable concepts.]
**World -> Program Mapping**
- [Real-world case/workflow]: [code location, persisted anchor, external/system
anchor if any, and why it belongs there.]
**Invariants**
- [Rule that must remain true.]
**Conceptual Fit / Pressure Points**
- [Where the current program strengthens, weakens, or obscures the theory.]
**Action Items**
- [Sequenced next step, starting with clarification or tests when needed.]
Keep domain theory, code mapping, and implementation cleanup distinct. Keep action items concrete and sequenced. For high-risk work, prefer this order: confirm the intended theory, add or identify regression tests for the important invariants, make the implementation change, then explicitly defer unsupported behavior or follow-up persistence if needed. Do not write files without explicit user approval.
For the 5-minute check, use this shorter form:
**Theory**
[The concept and why this change belongs or does not belong.]
**Invariant**
[The rule or behavior to protect.]
**Fit**
[Where the implementation should live and what to avoid.]
**Next Step**
[One concrete action: clarify, test, implement, or reject.]
When useful, include a concise final note:
Implemented the change in [files]. The important design choice was [decision],
because [reason/tradeoff]. Verified with [tests/checks].
Prefer this structure:
**Theory**
[Domain problem, concepts, invariants, and current model.]
**World -> Program Mapping**
[Real-world workflows mapped to code locations and anchors.]
**Decision**
[Recommended design and why it fits.]
**Tradeoffs**
[Alternatives rejected and consequences.]
**Action Items**
[Concrete steps to implement or validate.]
Prioritize findings first. For each conceptual issue, explain the practical risk:
[P1/P2/P3] This introduces a second meaning for "Account"
The existing model uses Account for billing ownership, but this change uses it
for login identity. That makes authorization checks ambiguous and future fixes
likely to patch the wrong concept.
Use a short acceptance checklist:
tools
Evaluate, analyze, and systematically react to an adversarial code review report. Decide on the action for each finding (Implement, Adapt, Decline), provide clear justifications, and define the plan to implement the accepted changes.
development
Manually triggered weekly or post-change repository audit based on Peter Naur's "Programming as Theory Building." Use this skill only when the user explicitly names `theory-building-review`, asks to run the theory-building review skill, or says to run the weekly/post-change theory-building review. Do not trigger automatically just because the conversation mentions Naur, domain modeling, refactoring, architecture, craft, or code review. When explicitly invoked, inspect recent diffs or scoped repository areas, reconstruct the system theory, find places where code and domain language diverge, and return actionable refactor, test, documentation, and modeling improvements. For active design, implementation, refactor, review, or AI-code acceptance on a specific change, use `theory-building` instead when explicitly invoked.
documentation
Summarize work done in a spec/plan document.
development
Review a spec document against codebase reality, identifying gaps and ensuring sound, robust implementations.