@homericintelligence/athena-opencode 0.5.0 → 0.5.1

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.
Files changed (136) hide show
  1. package/README.md +30 -17
  2. package/package.json +2 -2
  3. package/plugin.js +20 -5
  4. package/skills/TECHNICAL_ENGLISH.md +78 -0
  5. package/skills/_cli.py +26 -18
  6. package/skills/_support/docs/dependency-resolution.md +192 -0
  7. package/skills/_support/docs/policies/development.md +117 -0
  8. package/skills/_support/docs/policies/evidence-integrity.md +40 -0
  9. package/skills/_support/docs/principles/README.md +542 -0
  10. package/skills/_support/docs/principles/details/p001-kiss.md +114 -0
  11. package/skills/_support/docs/principles/details/p002-yagni.md +109 -0
  12. package/skills/_support/docs/principles/details/p003-dry.md +126 -0
  13. package/skills/_support/docs/principles/details/p004-solid.md +165 -0
  14. package/skills/_support/docs/principles/details/p005-modularity.md +123 -0
  15. package/skills/_support/docs/principles/details/p006-principle-of-least-astonishment.md +115 -0
  16. package/skills/_support/docs/principles/details/p007-subtraction-over-addition.md +113 -0
  17. package/skills/_support/docs/principles/details/p008-understand-before-subtracting.md +115 -0
  18. package/skills/_support/docs/principles/details/p009-general-mechanisms-over-special-cases.md +108 -0
  19. package/skills/_support/docs/principles/details/p010-scope-fidelity.md +117 -0
  20. package/skills/_support/docs/principles/details/p011-minimal-coherent-change.md +128 -0
  21. package/skills/_support/docs/principles/details/p012-evidence-before-modification.md +115 -0
  22. package/skills/_support/docs/principles/details/p013-avoid-hasty-abstractions.md +112 -0
  23. package/skills/_support/docs/principles/details/p014-preserve-unrequested-behavior.md +110 -0
  24. package/skills/_support/docs/principles/details/p015-architecture-conformance.md +124 -0
  25. package/skills/_support/docs/principles/details/p016-separation-of-concerns.md +125 -0
  26. package/skills/_support/docs/principles/details/p017-high-cohesion-low-coupling.md +130 -0
  27. package/skills/_support/docs/principles/details/p018-information-hiding.md +128 -0
  28. package/skills/_support/docs/principles/details/p019-explicit-contracts.md +134 -0
  29. package/skills/_support/docs/principles/details/p020-executable-architecture.md +130 -0
  30. package/skills/_support/docs/principles/details/p021-evolutionary-and-reversible-design.md +126 -0
  31. package/skills/_support/docs/principles/details/p022-test-behavior-not-implementation.md +129 -0
  32. package/skills/_support/docs/principles/details/p023-parameterized-table-driven-testing.md +129 -0
  33. package/skills/_support/docs/principles/details/p024-boundary-value-testing.md +128 -0
  34. package/skills/_support/docs/principles/details/p025-property-based-testing-for-invariants.md +133 -0
  35. package/skills/_support/docs/principles/details/p026-regression-before-repair.md +134 -0
  36. package/skills/_support/docs/principles/details/p027-deterministic-and-hermetic-tests.md +128 -0
  37. package/skills/_support/docs/principles/details/p028-test-failure-paths.md +133 -0
  38. package/skills/_support/docs/principles/details/p029-generalize-error-policy-preserve-specific-cause.md +131 -0
  39. package/skills/_support/docs/principles/details/p030-nearest-responsible-error-boundary.md +133 -0
  40. package/skills/_support/docs/principles/details/p031-propagate-rather-than-swallow.md +131 -0
  41. package/skills/_support/docs/principles/details/p032-handle-once-preserve-causality.md +137 -0
  42. package/skills/_support/docs/principles/details/p033-state-safe-failure-semantics.md +140 -0
  43. package/skills/_support/docs/principles/details/p034-fail-fast.md +132 -0
  44. package/skills/_support/docs/principles/details/p035-fail-secure-fail-closed.md +137 -0
  45. package/skills/_support/docs/principles/details/p036-graceful-degradation.md +137 -0
  46. package/skills/_support/docs/principles/details/p037-idempotency-before-retry.md +139 -0
  47. package/skills/_support/docs/principles/details/p038-bounded-retry.md +145 -0
  48. package/skills/_support/docs/principles/details/p039-bounded-waiting.md +151 -0
  49. package/skills/_support/docs/principles/details/p040-bounded-resources.md +138 -0
  50. package/skills/_support/docs/principles/details/p041-backpressure-and-load-shedding.md +141 -0
  51. package/skills/_support/docs/principles/details/p042-fault-isolation-bulkheads.md +140 -0
  52. package/skills/_support/docs/principles/details/p043-circuit-breakers.md +148 -0
  53. package/skills/_support/docs/principles/details/p044-atomicity-where-possible.md +141 -0
  54. package/skills/_support/docs/principles/details/p045-compensation-where-atomicity-is-impossible.md +163 -0
  55. package/skills/_support/docs/principles/details/p046-resumability.md +138 -0
  56. package/skills/_support/docs/principles/details/p047-observability-is-part-of-correctness.md +134 -0
  57. package/skills/_support/docs/principles/details/p048-secure-by-design.md +132 -0
  58. package/skills/_support/docs/principles/details/p049-secure-by-default.md +126 -0
  59. package/skills/_support/docs/principles/details/p050-least-privilege.md +123 -0
  60. package/skills/_support/docs/principles/details/p051-complete-mediation.md +124 -0
  61. package/skills/_support/docs/principles/details/p052-separation-of-duties.md +129 -0
  62. package/skills/_support/docs/principles/details/p053-validate-at-trust-boundaries.md +126 -0
  63. package/skills/_support/docs/principles/details/p054-defense-in-depth.md +135 -0
  64. package/skills/_support/docs/principles/details/p055-minimize-attack-surface.md +133 -0
  65. package/skills/_support/docs/principles/details/p056-secrets-stay-out-of-code-and-context.md +137 -0
  66. package/skills/_support/docs/principles/details/p057-supply-chain-integrity.md +135 -0
  67. package/skills/_support/docs/principles/details/p058-bounded-agent-authority.md +137 -0
  68. package/skills/_support/docs/principles/details/p059-data-is-not-instruction.md +130 -0
  69. package/skills/_support/docs/principles/details/p060-constrain-sub-agents.md +136 -0
  70. package/skills/_support/docs/principles/details/p061-separate-decision-from-high-impact-execution.md +131 -0
  71. package/skills/_support/docs/principles/details/p062-human-approval-for-irreversible-or-high-risk-actions.md +129 -0
  72. package/skills/_support/docs/principles/details/p063-requirement-to-code-traceability.md +116 -0
  73. package/skills/_support/docs/principles/details/p064-requirement-to-test-traceability.md +116 -0
  74. package/skills/_support/docs/principles/details/p065-verify-before-claiming-completion.md +129 -0
  75. package/skills/_support/docs/principles/details/p066-preserve-existing-work.md +114 -0
  76. package/skills/_support/docs/principles/details/p067-no-test-cheating.md +126 -0
  77. package/skills/_support/docs/principles/details/p068-no-validation-bypass.md +119 -0
  78. package/skills/_support/docs/principles/details/p069-independent-review-for-high-risk-changes.md +129 -0
  79. package/skills/_support/docs/principles/details/p070-code-health-must-not-regress.md +116 -0
  80. package/skills/_support/docs/principles/details/p071-consistency-over-personal-preference.md +117 -0
  81. package/skills/_support/docs/principles/details/p072-technical-evidence-over-preference.md +122 -0
  82. package/skills/_support/docs/principles/details/p073-optimize-only-with-evidence.md +123 -0
  83. package/skills/_support/docs/principles/details/p074-prefer-existing-mechanisms.md +121 -0
  84. package/skills/_support/docs/principles/details/p075-make-invalid-states-hard-to-represent.md +128 -0
  85. package/skills/_support/docs/principles/details/p076-parse-then-validate-then-operate.md +133 -0
  86. package/skills/_support/docs/principles/details/p077-separate-policy-from-mechanism.md +112 -0
  87. package/skills/_support/docs/principles/details/p078-single-source-of-truth.md +131 -0
  88. package/skills/_support/docs/principles/details/p079-explicit-ownership-and-lifetimes.md +124 -0
  89. package/skills/_support/docs/principles/details/p080-make-concurrency-deliberate.md +122 -0
  90. package/skills/_support/docs/principles/details/p081-forward-progress-with-safety.md +125 -0
  91. package/skills/_support/docs/principles/details/p082-design-for-cancellation.md +133 -0
  92. package/skills/_support/docs/principles/details/p083-irreversible-actions-last.md +124 -0
  93. package/skills/_support/docs/principles/details/p084-prefer-local-reasoning.md +131 -0
  94. package/skills/_support/docs/principles/details/p085-explicit-is-better-than-implicit.md +123 -0
  95. package/skills/_support/docs/principles/details/p086-readability-counts.md +113 -0
  96. package/skills/_support/docs/principles/details/p087-comments-explain-why-code-explains-what.md +120 -0
  97. package/skills/_support/docs/principles/details/p088-delete-dead-code.md +125 -0
  98. package/skills/_support/docs/principles/details/p089-delete-obsolete-configuration-and-dependencies.md +125 -0
  99. package/skills/_support/docs/principles/details/p090-prefer-negative-code.md +134 -0
  100. package/skills/_support/docs/principles/details/p091-test-driven-development.md +149 -0
  101. package/skills/_support/docs/review/README.md +59 -0
  102. package/skills/_support/docs/review/behavior-first-testing.md +73 -0
  103. package/skills/_support/docs/review/common.md +365 -0
  104. package/skills/_support/docs/review/design-docs.md +74 -0
  105. package/skills/_support/docs/review/issue-planning.md +220 -0
  106. package/skills/_support/docs/review/language-routing.md +141 -0
  107. package/skills/_support/docs/review/repository-scorecard.md +170 -0
  108. package/skills/advise/SKILL.md +93 -67
  109. package/skills/advise/scripts/list_retrievable_skills.py +3 -3
  110. package/skills/brainstorm/SKILL.md +160 -127
  111. package/skills/change-review/SKILL.md +91 -71
  112. package/skills/change-review/references/scope-resolution.md +69 -46
  113. package/skills/change-review/scripts/resolve_scope.py +119 -73
  114. package/skills/finalize-plan/SKILL.md +198 -139
  115. package/skills/git-worktrees/SKILL.md +100 -80
  116. package/skills/git-worktrees/scripts/prepare_worktree.py +16 -10
  117. package/skills/issue-review/SKILL.md +136 -79
  118. package/skills/learn/SKILL.md +276 -186
  119. package/skills/myrmidon-swarm/SKILL.md +126 -86
  120. package/skills/plan-issue/SKILL.md +122 -81
  121. package/skills/pr-review/SKILL.md +164 -114
  122. package/skills/pr-review/references/criteria.md +58 -37
  123. package/skills/pr-review/references/delivery.md +156 -98
  124. package/skills/pr-review/references/evidence.md +265 -148
  125. package/skills/pr-review/references/prevalidated.md +93 -61
  126. package/skills/pr-review/scripts/collect_evidence.py +211 -140
  127. package/skills/pr-review/scripts/diff_context.py +6 -4
  128. package/skills/pr-review/scripts/materialize_snapshot.py +112 -120
  129. package/skills/pr-review/scripts/pr_identity.py +27 -15
  130. package/skills/pr-review/scripts/resolve_pr.py +53 -31
  131. package/skills/repo-review/SKILL.md +202 -131
  132. package/skills/systematic-debugging/SKILL.md +210 -192
  133. package/skills/systematic-debugging/scripts/repository_evidence.py +9 -4
  134. package/skills/test-driven-development/SKILL.md +126 -96
  135. package/skills/tidy/SKILL.md +92 -59
  136. package/skills/tidy/scripts/run_tidy.py +3 -3
@@ -0,0 +1,109 @@
1
+ # P002 — YAGNI
2
+
3
+ ## Definition
4
+
5
+ **YAGNI** (*You Aren't Going to Need It* or *You Ain't Gonna Need It*) does not let authors add elements
6
+ with no current requirement. These elements include functionality, extension points,
7
+ configuration, abstraction, and infrastructure. Do only the work that evidence shows is necessary
8
+ for the current requirement. Keep paths for change.
9
+
10
+ ## Provenance
11
+
12
+ **Classification:** established principle.
13
+
14
+ Extreme Programming is the source of YAGNI. Martin Fowler gives Chet Hendrickson as the
15
+ source of the phrase after a conversation with Kent Beck. Sources give different expansions. Each expansion
16
+ gives the principle the same meaning.
17
+
18
+ ## Decision rule
19
+
20
+ If a proposed element is only for a future condition with no evidence, do not add it. Add the element
21
+ for an accepted requirement, a condition that occurs more than one time, or a measured constraint.
22
+
23
+ ## How to apply
24
+
25
+ - Keep current acceptance criteria isolated from future requests with no evidence.
26
+ - Delete flags, hooks, providers, compatibility paths, and configuration that have no current requirement.
27
+ - Use clear contracts and tests to make future change easy. Do not add extension points with no purpose.
28
+ - When plan information has value and has an owner or trigger, record an idea for future work.
29
+ - When evidence changes, examine the decision again.
30
+
31
+ ## Diagram
32
+
33
+ ```mermaid
34
+ flowchart TD
35
+ A["Find a proposed element"] --> B{"Is it necessary for a current requirement?"}
36
+ B -->|No| C["Do not add the element"]
37
+ B -->|Yes| D["Do the minimum necessary implementation"]
38
+ C --> E["After new evidence, examine again"]
39
+ D --> E
40
+ ```
41
+
42
+ ## Language examples
43
+
44
+ The two examples contain only the necessary delivery modes.
45
+
46
+ ```python
47
+ def shipping_cost(express: bool) -> int:
48
+ if express:
49
+ return 20
50
+ return 5
51
+ ```
52
+
53
+ ```rust
54
+ fn shipping_cost(express: bool) -> u32 {
55
+ if express {
56
+ 20
57
+ } else {
58
+ 5
59
+ }
60
+ }
61
+ ```
62
+
63
+ ## Boundaries and tensions
64
+
65
+ YAGNI does not let authors ignore explicit quality requirements, specified migrations, security
66
+ controls, or protocol duties in the current scope. It rejects implementation with no evidence, not
67
+ design necessary for the current requirement. [P004 SOLID](p004-solid.md) and
68
+ [P005 Modularity](p005-modularity.md) can make a boundary necessary for a current requirement. They do
69
+ not make a framework necessary when it has no current purpose.
70
+ [P013 AHA](p013-avoid-hasty-abstractions.md) gives the related rule for abstraction time.
71
+
72
+ ## Examples
73
+
74
+ **Positive:** A service uses the current repository interface for the one necessary authentication
75
+ provider. It does not add a provider marketplace until approval of a second provider.
76
+
77
+ **Misuse:** Although an alternative is necessary for a deployment requirement, a contributor does
78
+ not add a configuration option for the value. This decision does not agree with the requirement.
79
+
80
+ **Athena/agent workflow:** Evidence must show a product consumer for each artifact in a plan. The plan
81
+ does not add a changelog, generator, registry, or compatibility layer for unknown requests.
82
+
83
+ ## Related principles
84
+
85
+ - [P001 KISS](p001-kiss.md)
86
+ - [P010 Scope Fidelity](p010-scope-fidelity.md)
87
+ - [P013 AHA](p013-avoid-hasty-abstractions.md)
88
+ - [P073 Optimize Only With Evidence](p073-optimize-only-with-evidence.md)
89
+
90
+ ## References
91
+
92
+ ### Source information
93
+
94
+ - [Martin Fowler: Yagni](https://martinfowler.com/bliki/Yagni.html) gives Extreme Programming and Chet
95
+ Hendrickson as sources of the term. It also shows the economic basis.
96
+ - [Extreme Programming Explained, second edition](https://www.pearson.com/en-us/subject-catalog/p/extreme-programming-explained-embrace-change/P200000000118/9780321278654)
97
+ is the publisher's record for the Extreme Programming book from Kent Beck and Cynthia Andres.
98
+
99
+ ### Applicable information
100
+
101
+ - [Google Engineering Practices: What to look for in a code review](https://google.github.io/eng-practices/review/reviewer/looking-for.html)
102
+ tells reviewers to reject functionality with no current requirement.
103
+
104
+ ### More information
105
+
106
+ - [Martin Fowler: Design Stamina Hypothesis](https://martinfowler.com/bliki/DesignStaminaHypothesis.html)
107
+ gives information about design work that has value without features that have no current requirement.
108
+
109
+ [Back to the engineering principles catalog](../README.md#p002)
@@ -0,0 +1,126 @@
1
+ # P003 — DRY
2
+
3
+ ## Definition
4
+
5
+ **DRY** (*Don't Repeat Yourself*) gives each authoritative item of knowledge one canonical
6
+ representation. DRY is for duplicate rules, schemas, calculations, and policies. It is not for
7
+ each syntax sequence that occurs more than one time.
8
+
9
+ ## Provenance
10
+
11
+ **Classification:** established principle.
12
+
13
+ Andrew Hunt and David Thomas gave DRY its name and definition in *The Pragmatic Programmer*. Their definition
14
+ is about duplicate knowledge in a system. Some authors do not keep this distinction and
15
+ include all code that has almost the same text in DRY.
16
+
17
+ ## Decision rule
18
+
19
+ When two representations must change together, select one authority. Derive the other representations
20
+ from that authority. Connect each other representation to that authority with a derived form or a
21
+ link. When code has only text that is almost the same, do not put it together.
22
+
23
+ ## How to apply
24
+
25
+ - Find the fact or rule that must stay the same after one isolated edit.
26
+ - Give one owner.
27
+ - Connect each consumer to that authority with derivation or reference.
28
+ - When different formats are necessary for consumers, use links and derived views. Do not use
29
+ manual copies.
30
+ - When the same text does not show the same stable concept, do not put the logic together.
31
+ - Do a test of the canonical behavior. Do not write one test for each text representation.
32
+
33
+ ## Diagram
34
+
35
+ ```mermaid
36
+ flowchart TD
37
+ A["Find representations that must agree"] --> B["Select one authority"]
38
+ B --> C["Connect each consumer to the authority"]
39
+ C --> D{"Can one edit cause inconsistency?"}
40
+ D -->|Yes| B
41
+ D -->|No| E["Keep one clear authority"]
42
+ ```
43
+
44
+ ## Language examples
45
+
46
+ The two examples accept cents in the unsigned 64-bit domain. Each example uses one 20-percent
47
+ tax-rate authority and rounds half up to the nearest cent.
48
+
49
+ ```python
50
+ TAX_BPS = 2_000
51
+ BASIS_POINTS = 10_000
52
+
53
+ def tax_cents(subtotal_cents: int) -> int:
54
+ if type(subtotal_cents) is not int:
55
+ raise TypeError("subtotal must be an integer")
56
+ if not 0 <= subtotal_cents <= 2**64 - 1:
57
+ raise ValueError("subtotal is not in the unsigned 64-bit domain")
58
+ return (subtotal_cents * TAX_BPS + BASIS_POINTS // 2) // BASIS_POINTS
59
+
60
+ def total_cents(subtotal_cents: int) -> int:
61
+ return subtotal_cents + tax_cents(subtotal_cents)
62
+ ```
63
+
64
+ ```rust
65
+ const TAX_BPS: u128 = 2_000;
66
+ const BASIS_POINTS: u128 = 10_000;
67
+
68
+ fn tax_cents(subtotal_cents: u64) -> u128 {
69
+ let subtotal = u128::from(subtotal_cents);
70
+ (subtotal * TAX_BPS + BASIS_POINTS / 2) / BASIS_POINTS
71
+ }
72
+
73
+ fn total_cents(subtotal_cents: u64) -> u128 {
74
+ u128::from(subtotal_cents) + tax_cents(subtotal_cents)
75
+ }
76
+ ```
77
+
78
+ ## Boundaries and tensions
79
+
80
+ Some duplication can help local analysis or keep unrelated domains isolated. Centralization
81
+ before sufficient evidence can make an incorrect abstraction and tighter coupling. Before you
82
+ extract shared code, use [P013 AHA](p013-avoid-hasty-abstractions.md). Before you add shared mutable
83
+ state, use [P005 Modularity](p005-modularity.md). A registry or generator is not
84
+ necessary for DRY when repository discovery supplies the answer. Evidence for a product consumer
85
+ must show that each artifact is necessary.
86
+
87
+ ## Examples
88
+
89
+ **Positive:** One schema is the authority. API documentation and validators derive from it or have links to it.
90
+ They do not use a manual restatement of field constraints.
91
+
92
+ **Misuse:** Two domain workflows contain the same three steps. A generic engine puts them together,
93
+ although their policies and causes of change are different.
94
+
95
+ **Athena/agent workflow:** The principles catalog has authority for IDs and definitions. Skills have links to the
96
+ applicable principles and show only the workflow effects of those principles.
97
+
98
+ ## Related principles
99
+
100
+ - [P005 Modularity](p005-modularity.md)
101
+ - [P013 AHA](p013-avoid-hasty-abstractions.md)
102
+ - [P074 Prefer Existing Mechanisms](p074-prefer-existing-mechanisms.md)
103
+ - [P078 Single Source of Truth](p078-single-source-of-truth.md)
104
+ - [P084 Prefer Local Reasoning](p084-prefer-local-reasoning.md)
105
+
106
+ ## References
107
+
108
+ ### Source information
109
+
110
+ - [The Pragmatic Programmer DRY excerpt](https://media.pragprog.com/titles/tpp20/dry.pdf) gives
111
+ the authors' definition and examples of duplicate knowledge.
112
+ - [The Pragmatic Programmer, 20th Anniversary Edition](https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/)
113
+ is the publisher's current book record.
114
+
115
+ ### Applicable information
116
+
117
+ - [Google Engineering Practices: What to look for in a code review](https://google.github.io/eng-practices/review/reviewer/looking-for.html).
118
+ The guidance tells reviewers to find if a change belongs in the codebase or a library. It
119
+ also tells reviewers to find complexity that is not necessary.
120
+
121
+ ### More information
122
+
123
+ - [Sandi Metz: The Wrong Abstraction](https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction)
124
+ shows that duplicate removal before sufficient evidence can have more cost than a temporary duplicate.
125
+
126
+ [Back to the engineering principles catalog](../README.md#p003)
@@ -0,0 +1,165 @@
1
+ # P004 — SOLID
2
+
3
+ ## Definition
4
+
5
+ **SOLID** is a family of five object-oriented design principles. The family contains Single
6
+ Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
7
+ Use these principles to give clear responsibilities. Make dependencies agree with stable behavioral
8
+ contracts. Classes and interfaces are not necessary for SOLID.
9
+
10
+ ### The five principles
11
+
12
+ #### Single Responsibility Principle (SRP)
13
+
14
+ A module or component must have one primary responsibility and one cause of change.
15
+ Responsibility is about policy ownership, not the number of functions or lines in a file.
16
+
17
+ #### Open/Closed Principle (OCP)
18
+
19
+ A stable component must have a specified extension mechanism for necessary variation.
20
+ For each new variation, the mechanism must not change core policy. Abstractions for unknown
21
+ variations are not necessary for OCP.
22
+
23
+ #### Liskov Substitution Principle (LSP)
24
+
25
+ A subtype or implementation must keep the observable contract of its abstraction. This
26
+ contract includes applicable inputs, promised outputs, invariants, and failure semantics.
27
+
28
+ #### Interface Segregation Principle (ISP)
29
+
30
+ Clients must have dependencies only on capabilities that they use. Select cohesive, role-oriented
31
+ interfaces. Consumers of interfaces with many responsibilities must accept methods or permissions
32
+ with no purpose.
33
+
34
+ #### Dependency Inversion Principle (DIP)
35
+
36
+ High-level policy must have no dependency on low-level details that can change. High-level
37
+ policy and low-level details must have dependencies on a stable contract at the correct boundary.
38
+ Dependency injection is one method, not the principle.
39
+
40
+ ## Provenance
41
+
42
+ **Classification:** established principle.
43
+
44
+ Robert C. Martin wrote separate papers about the five principles. One paper describes Single
45
+ Responsibility. A second paper includes the other four principles. Bertrand Meyer was the first
46
+ source for Open/Closed. Barbara Liskov and Jeannette Wing give Liskov Substitution a formal basis.
47
+
48
+ ## Decision rule
49
+
50
+ When evidence shows a responsibility, variation point, or substitution contract, use an applicable
51
+ SOLID principle to make it clear. Do not add abstraction only for the SOLID name.
52
+
53
+ ## How to apply
54
+
55
+ - Before you divide responsibilities, find actors, policy owners, and causes of change.
56
+ - Only when evidence shows a variation, add an extension seam for that variation.
57
+ - Before a substitution claim, give the behavioral contracts.
58
+ - Give consumers the narrowest capability surface for one role.
59
+ - Make dependencies point to stable policy. Keep system connections clear.
60
+
61
+ ## Diagram
62
+
63
+ ```mermaid
64
+ flowchart TD
65
+ A["Find a responsibility or contract"] --> B{"Which SOLID principle is applicable?"}
66
+ B --> C["Give one responsibility"]
67
+ B --> D["Specify necessary variation"]
68
+ B --> E["Keep substitution behavior"]
69
+ B --> F["Give each client only necessary capability"]
70
+ B --> G["Make dependencies point to stable policy"]
71
+ C --> H["Make sure there is a clear design benefit"]
72
+ D --> H
73
+ E --> H
74
+ F --> H
75
+ G --> H
76
+ ```
77
+
78
+ ## Language examples
79
+
80
+ The two examples use signed 32-bit amounts and give invoice policy a dependency on a narrow tax contract.
81
+
82
+ ```python
83
+ from collections.abc import Callable
84
+
85
+ I32_MIN, I32_MAX = -(2**31), 2**31 - 1
86
+
87
+ def invoice_total(subtotal: int, tax: Callable[[int], int]) -> int:
88
+ if type(subtotal) is not int or not I32_MIN <= subtotal <= I32_MAX:
89
+ raise OverflowError("amount is not in the i32 range")
90
+ tax_value = tax(subtotal)
91
+ if type(tax_value) is not int or not I32_MIN <= tax_value <= I32_MAX:
92
+ raise OverflowError("amount is not in the i32 range")
93
+ total = subtotal + tax_value
94
+ if not I32_MIN <= total <= I32_MAX:
95
+ raise OverflowError("amount is not in the i32 range")
96
+ return total
97
+ ```
98
+
99
+ ```rust
100
+ trait Tax {
101
+ fn for_subtotal(&self, subtotal: i32) -> i32;
102
+ }
103
+
104
+ fn invoice_total<T: Tax>(subtotal: i32, tax: &T) -> Result<i32, &'static str> {
105
+ subtotal
106
+ .checked_add(tax.for_subtotal(subtotal))
107
+ .ok_or("amount is not in the i32 range")
108
+ }
109
+ ```
110
+
111
+ ## Boundaries and tensions
112
+
113
+ Object-oriented design is the source of SOLID. Keep its behavioral intent in functional,
114
+ data-oriented, or procedural systems. If evidence shows no requirement for an interface, class, or
115
+ dependency injection mechanism, that addition does not obey [P001 KISS](p001-kiss.md),
116
+ [P002 YAGNI](p002-yagni.md), and [P013 AHA](p013-avoid-hasty-abstractions.md). Current architecture and repository contracts are
117
+ more important than a SOLID interpretation with no evidence.
118
+
119
+ ## Examples
120
+
121
+ **Positive:** Business policy has a dependency on a narrow storage capability. Production and test
122
+ adapters obey the same error and transaction contract.
123
+
124
+ **Misuse:** Each function receives a one-method interface, although there is only one stable
125
+ implementation. No necessary substitution makes the added indirection necessary.
126
+
127
+ **Athena/agent workflow:** A skill has responsibility for its workflow policy and uses an explicit capability boundary
128
+ to delegate execution. It records behavior for a missing capability.
129
+
130
+ ## Related principles
131
+
132
+ - [P005 Modularity](p005-modularity.md)
133
+ - [P013 AHA](p013-avoid-hasty-abstractions.md)
134
+ - [P016 Separation of Concerns](p016-separation-of-concerns.md)
135
+ - [P017 High Cohesion, Low Coupling](p017-high-cohesion-low-coupling.md)
136
+ - [P018 Information Hiding](p018-information-hiding.md)
137
+ - [P019 Explicit Contracts](p019-explicit-contracts.md)
138
+
139
+ ## References
140
+
141
+ ### Source information
142
+
143
+ - [Robert C. Martin: The Single Responsibility Principle](https://objectmentor.com/resources/articles/srp.pdf)
144
+ shows that responsibility is a cause of change. The paper shows that a class must have only one such
145
+ cause.
146
+ - [Robert C. Martin: Design Principles and Design Patterns](https://objectmentor.com/resources/articles/Principles_and_Patterns.pdf)
147
+ includes Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion in one
148
+ primary paper.
149
+ - [Bertrand Meyer: Object-Oriented Software Construction](https://bertrandmeyer.com/OOSC2/)
150
+ is the author's page for the work that is the source of the Open/Closed Principle.
151
+ - [Liskov and Wing: A Behavioral Notion of Subtyping](https://doi.org/10.1145/197320.197383)
152
+ gives the formal basis for behavioral substitution.
153
+
154
+ ### Applicable information
155
+
156
+ - [Microsoft: Architectural principles](https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles)
157
+ gives separation of concerns, explicit dependencies, single responsibility, and dependency
158
+ inversion as application-architecture principles.
159
+
160
+ ### More information
161
+
162
+ - [Bertrand Meyer: Applying Design by Contract](https://www.kth.se/social/files/59526bfb56be5b4f17000807/meyer-92-contracts.pdf)
163
+ gives the precondition, postcondition, and invariant model for LSP analysis.
164
+
165
+ [Back to the engineering principles catalog](../README.md#p004)
@@ -0,0 +1,123 @@
1
+ # P005 — Modularity
2
+
3
+ ## Definition
4
+
5
+ **Modularity** divides a system into cohesive components with clear interfaces and a small number
6
+ of dependencies. A change in one module must have a small number of effects on unrelated
7
+ modules.
8
+
9
+ ## Provenance
10
+
11
+ **Classification:** established principle.
12
+
13
+ Modular design was in engineering before modern software. David Parnas's 1972 paper is an important
14
+ source for software modularity. The paper tells designers to put decisions that can change in modules
15
+ with clear boundaries. An operation sequence is not sufficient to specify the boundaries.
16
+
17
+ ## Decision rule
18
+
19
+ When a module boundary gives one responsibility a clear owner, select that boundary. A
20
+ boundary can also hide a decision that can change or contain change and failure. Do not divide a system
21
+ only to increase its module count.
22
+
23
+ ## How to apply
24
+
25
+ - When behavior and data share policy and causes of change, keep them together.
26
+ - Give a small contract.
27
+ - Hide implementation decisions.
28
+ - Make dependency direction clear. Find boundary crossings that are not necessary.
29
+ - When product independence is necessary, use the same boundary for deployment, failure, and ownership.
30
+ - Do a test of each module's behavior and the contracts that connect modules.
31
+
32
+ ## Diagram
33
+
34
+ ```mermaid
35
+ flowchart TD
36
+ A["Find one responsibility"] --> B["Give one module owner"]
37
+ B --> C["Give a small contract"]
38
+ C --> D["Hide decisions that can change"]
39
+ D --> E{"Does the boundary contain the change?"}
40
+ E -->|No| B
41
+ E -->|Yes| F["Keep the boundary"]
42
+ ```
43
+
44
+ ## Language examples
45
+
46
+ The two examples accept only ASCII decimal digits for ports from 1 to 65,535.
47
+
48
+ ```python
49
+ def parse_port(text: str) -> int:
50
+ if not text.isascii() or not text.isdigit():
51
+ raise ValueError("port is not correct")
52
+ try:
53
+ port = int(text)
54
+ except ValueError as error:
55
+ raise ValueError("port is not correct") from error
56
+ if not 1 <= port <= 65_535:
57
+ raise ValueError("port is not correct")
58
+ return port
59
+ ```
60
+
61
+ ```rust
62
+ fn parse_port(text: &str) -> Result<u16, &'static str> {
63
+ if text.is_empty() || !text.bytes().all(|byte| byte.is_ascii_digit()) {
64
+ return Err("port is not correct");
65
+ }
66
+ let port = text.parse::<u16>().map_err(|_| "port is not correct")?;
67
+ if port == 0 {
68
+ return Err("port is not correct");
69
+ }
70
+ Ok(port)
71
+ }
72
+ ```
73
+
74
+ ## Boundaries and tensions
75
+
76
+ Physical separation is not sufficient for modularity. Small packages can make calls at all
77
+ boundaries and can share mutable state or cyclic dependencies. Such packages can have less
78
+ modularity than one cohesive component.
79
+
80
+ Distributed services add boundaries in operation. Do not add them only for code organization.
81
+ When you use [P003 DRY](p003-dry.md), keep local ownership. Before you change an established
82
+ boundary, use [P012 Evidence Before Modification](p012-evidence-before-modification.md).
83
+
84
+ ## Examples
85
+
86
+ **Positive:** A parser has responsibility for external syntax and returns a stable internal value. Business policy
87
+ has a dependency on that value, not on parser details.
88
+
89
+ **Misuse:** A small application uses services that must deploy together and share one database.
90
+ This design adds network failure without a specified owner or evolution path.
91
+
92
+ **Athena/agent workflow:** Canonical skills are in `skills/`. Host manifests have links to those
93
+ skills and do not contain skill copies for one host.
94
+
95
+ ## Related principles
96
+
97
+ - [P004 SOLID](p004-solid.md)
98
+ - [P015 Architecture Conformance](p015-architecture-conformance.md)
99
+ - [P016 Separation of Concerns](p016-separation-of-concerns.md)
100
+ - [P017 High Cohesion, Low Coupling](p017-high-cohesion-low-coupling.md)
101
+ - [P018 Information Hiding](p018-information-hiding.md)
102
+ - [P077 Separate Policy from Mechanism](p077-separate-policy-from-mechanism.md)
103
+
104
+ ## References
105
+
106
+ ### Source information
107
+
108
+ - [David Parnas: On the Criteria To Be Used in Decomposing Systems into Modules](https://doi.org/10.1145/361598.361623).
109
+ The paper connects modular boundaries to hidden design decisions.
110
+
111
+ ### Applicable information
112
+
113
+ - [Microsoft: Architectural principles](https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles)
114
+ shows that separation of concerns and encapsulation are architecture practices.
115
+ - [SEI: Quality Attribute Workshops](https://www.sei.cmu.edu/library/quality-attribute-workshops/)
116
+ gives a method that connects architecture decisions to specified quality requirements.
117
+
118
+ ### More information
119
+
120
+ - [Liskov and Wing: A Behavioral Notion of Subtyping](https://doi.org/10.1145/197320.197383)
121
+ gives information for analysis of module contracts with substitutable implementations.
122
+
123
+ [Back to the engineering principles catalog](../README.md#p005)
@@ -0,0 +1,115 @@
1
+ # P006 — Principle of Least Astonishment
2
+
3
+ ## Definition
4
+
5
+ For the **Principle of Least Astonishment** (**POLA**, also the principle of least surprise),
6
+ behavior must agree with user expectations that evidence shows. POLA is applicable to interfaces, defaults,
7
+ state changes, and failures. The system context and specified contract give evidence for those
8
+ expectations.
9
+
10
+ ## Provenance
11
+
12
+ **Classification:** practitioner heuristic.
13
+
14
+ The phrase has a long history in language and interface design. No source supplies sufficient
15
+ evidence for the source of the phrase. Context also changes POLA. User expectations are not the
16
+ same for all audiences.
17
+ Repository precedent and research with users have more value as evidence than a design that personnel select without evidence.
18
+
19
+ ## Decision rule
20
+
21
+ When there are two or more correct designs, examine the public contract, local conventions, and evidence
22
+ about user expectations. Select the design that agrees with this evidence. Make each necessary
23
+ difference clear. Give a safe migration.
24
+
25
+ ## How to apply
26
+
27
+ - Find the intended audience and its conventions that evidence shows.
28
+ - Make sure names, defaults, units, mutability, side effects, and errors agree with related conventions.
29
+ - Use clear confirmation or clear names for destructive behavior and behavior not in user expectations.
30
+ - Keep expectations that evidence shows for related CLI, API, and configuration operations.
31
+ - Do a test of defaults and failure behavior in the public contract.
32
+
33
+ ## Diagram
34
+
35
+ ```mermaid
36
+ flowchart TD
37
+ A["Find the intended audience"] --> B["Examine contracts and conventions"]
38
+ B --> C["Select a design that agrees with conventions"]
39
+ C --> D{"Does behavior agree with user expectations?"}
40
+ D -->|No| E["Make the difference clear"]
41
+ E --> C
42
+ D -->|Yes| F["Do a test of defaults and failures"]
43
+ ```
44
+
45
+ ## Language examples
46
+
47
+ Explicit confirmation is necessary before the destructive step in the two examples.
48
+
49
+ ```python
50
+ def delete_user(user_id: str, confirmed: bool) -> None:
51
+ if not confirmed:
52
+ raise ValueError("confirmation is necessary")
53
+ database.delete(user_id)
54
+ ```
55
+
56
+ ```rust
57
+ fn delete_user(user_id: &str, confirmed: bool) -> Result<(), &'static str> {
58
+ if !confirmed {
59
+ return Err("confirmation is necessary");
60
+ }
61
+ database_delete(user_id);
62
+ Ok(())
63
+ }
64
+ ```
65
+
66
+ ## Boundaries and tensions
67
+
68
+ POLA is not applicable when personnel know that behavior is dangerous. Security controls, correct behavior, accessibility, or an
69
+ explicit specification can make an explicit change from precedent necessary. Make the difference clear.
70
+ Give a migration that is safe.
71
+ [P014 Preserve Unrequested Behavior](p014-preserve-unrequested-behavior.md) gives protection to established
72
+ contracts. [P019 Explicit Contracts](p019-explicit-contracts.md) decreases ambiguity when expectations
73
+ are not the same.
74
+
75
+ ## Examples
76
+
77
+ **Positive:** A `--dry-run` flag does no external writes and gives the planned actions for a
78
+ usual operation.
79
+
80
+ **Misuse:** A command with the name `list` repairs and deletes stale resources without notice because cleanup
81
+ is easy during enumeration.
82
+
83
+ **Athena/agent workflow:** A skill uses its documented fallback when a necessary capability is
84
+ missing. It does not select a workflow with more authority without notice.
85
+
86
+ ## Related principles
87
+
88
+ - [P014 Preserve Unrequested Behavior](p014-preserve-unrequested-behavior.md)
89
+ - [P019 Explicit Contracts](p019-explicit-contracts.md)
90
+ - [P049 Secure by Default](p049-secure-by-default.md)
91
+ - [P071 Consistency Over Personal Preference](p071-consistency-over-personal-preference.md)
92
+ - [P085 Explicit Is Better Than Implicit](p085-explicit-is-better-than-implicit.md)
93
+
94
+ ## References
95
+
96
+ ### Source information
97
+
98
+ - [The Open Group Base Specifications, Utility Syntax Guidelines](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html)
99
+ give established consistency rules for command interfaces. They show POLA but do not
100
+ give a source for the phrase.
101
+
102
+ ### Applicable information
103
+
104
+ - [Google Cloud API Design Guide](https://cloud.google.com/apis/design) shows that resource-oriented
105
+ conventions are important properties of API design. Related APIs that use the conventions have
106
+ the same behavior.
107
+ - [Google API Improvement Proposals: General principles](https://google.aip.dev/general) gives
108
+ conventions that agree for related APIs.
109
+
110
+ ### More information
111
+
112
+ - [PEP 20 — The Zen of Python](https://peps.python.org/pep-0020/) gives a short example of how
113
+ a language community records expectations for clear design in which related properties agree.
114
+
115
+ [Back to the engineering principles catalog](../README.md#p006)