@hobin/developer 0.1.7 → 0.1.9

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 (66) hide show
  1. package/README.md +212 -355
  2. package/REFERENCE_ROUTING.md +243 -0
  3. package/extensions/developer.ts +601 -23
  4. package/extensions/machine.ts +45 -0
  5. package/extensions/references/behavior-preserving-structural-change.md +87 -8
  6. package/extensions/skills.ts +330 -52
  7. package/extensions/state.ts +227 -2
  8. package/extensions/tool-policy.ts +87 -0
  9. package/package.json +9 -3
  10. package/skills/abstraction-review/SKILL.md +37 -23
  11. package/skills/abstraction-review/reference-policy.json +66 -0
  12. package/skills/abstraction-review/references/field-card.md +113 -168
  13. package/skills/abstraction-review/references/repair-table.md +66 -80
  14. package/skills/abstraction-review/references/worked-examples.md +79 -256
  15. package/skills/model/SKILL.md +31 -13
  16. package/skills/model/reference-policy.json +96 -0
  17. package/skills/model/references/contract-and-replacement-models.md +112 -0
  18. package/skills/model/references/logic-query-semantics.md +89 -0
  19. package/skills/model/references/planning-models.md +75 -0
  20. package/skills/model/references/problem-modeling.md +143 -276
  21. package/skills/model/references/proof-obligations.md +71 -0
  22. package/skills/model/references/relational-constraint-models.md +110 -0
  23. package/skills/model/references/solver-result-boundaries.md +83 -0
  24. package/skills/model/references/temporal-behavior-models.md +106 -0
  25. package/skills/naming-judgment/SKILL.md +17 -4
  26. package/skills/naming-judgment/reference-policy.json +29 -0
  27. package/skills/naming-judgment/references/domain-naming.md +29 -10
  28. package/skills/schedule/SKILL.md +16 -6
  29. package/skills/schedule/reference-policy.json +29 -0
  30. package/skills/schedule/references/structural-change-timing.md +81 -18
  31. package/skills/signal/SKILL.md +17 -6
  32. package/skills/signal/reference-policy.json +29 -0
  33. package/skills/signal/references/structural-movement.md +87 -14
  34. package/skills/sketch/SKILL.md +38 -42
  35. package/skills/sketch/reference-policy.json +212 -0
  36. package/skills/sketch/references/accumulator-invariants.md +125 -0
  37. package/skills/sketch/references/closure-and-conventional-interfaces.md +87 -0
  38. package/skills/sketch/references/composition-by-wishes.md +69 -0
  39. package/skills/sketch/references/data-driven-design.md +99 -22
  40. package/skills/sketch/references/data-shape-template-catalog.md +58 -19
  41. package/skills/sketch/references/design-levels-and-boundaries.md +133 -0
  42. package/skills/sketch/references/earned-abstraction.md +75 -0
  43. package/skills/sketch/references/generative-recursion.md +122 -0
  44. package/skills/sketch/references/generic-dispatch-systems.md +75 -0
  45. package/skills/sketch/references/language-semantics.md +82 -0
  46. package/skills/sketch/references/meaning-preserving-conversions.md +69 -0
  47. package/skills/sketch/references/process-shape-and-resources.md +157 -0
  48. package/skills/sketch/references/representation-barriers.md +73 -0
  49. package/skills/sketch/references/responsibility-and-collaboration.md +108 -0
  50. package/skills/sketch/references/runtime-and-compilation.md +84 -0
  51. package/skills/sketch/references/selection-and-creation.md +76 -0
  52. package/skills/sketch/references/state-history-and-order.md +126 -0
  53. package/skills/sketch/references/type-transitions.md +54 -0
  54. package/skills/sketch/references/variation-roles.md +59 -0
  55. package/skills/verify/SKILL.md +17 -6
  56. package/skills/verify/reference-policy.json +30 -0
  57. package/skills/verify/references/verifier-selection-and-pass-but-wrong.md +152 -192
  58. package/SOURCES.md +0 -104
  59. package/skills/abstraction-review/references/recipe-cards.md +0 -322
  60. package/skills/model/references/worked-models-and-specialized-techniques.md +0 -218
  61. package/skills/sketch/references/abstraction-barriers-and-closure.md +0 -160
  62. package/skills/sketch/references/abstraction-composition-and-state.md +0 -184
  63. package/skills/sketch/references/composition-generative-recursion-and-accumulators.md +0 -196
  64. package/skills/sketch/references/generic-operations-and-languages.md +0 -134
  65. package/skills/sketch/references/processes-state-and-time.md +0 -171
  66. package/skills/sketch/references/responsibility-and-variation.md +0 -245
@@ -0,0 +1,87 @@
1
+ # Closure And Conventional Interfaces
2
+
3
+ Use this reference after [Design Levels And Boundaries](design-levels-and-boundaries.md)
4
+ when the unresolved question is which operations keep results inside one
5
+ composable value world and which operations intentionally finalize outside it.
6
+
7
+ ## Closure Unit
8
+
9
+ ```text
10
+ unit predicate: what values belong to the world
11
+ primitives: smallest units
12
+ closed operations: Unit... -> Unit
13
+ observers/finalizers: Unit -> outside world
14
+ invalid combinations: forbidden by meaning or cost
15
+ ```
16
+
17
+ Example:
18
+
19
+ ```text
20
+ Panel = Text(content) | Image(src) | Row(List<Panel>) | Column(List<Panel>)
21
+ ```
22
+
23
+ `Row` and `Column` accept and produce `Panel`, so primitive and compound panels
24
+ combine uniformly. Rendering is `Panel -> Pixels`, an explicit finalizer.
25
+
26
+ Do not make every method chainable. Preserve closure only for the central
27
+ composition unit.
28
+
29
+ ## Procedures As Values
30
+
31
+ A higher-order role is justified when variation has a stable contract:
32
+
33
+ ```text
34
+ aggregate(items, base, project, combine)
35
+ ```
36
+
37
+ Record preconditions, effects, errors, order, and cost. Passing a callback does
38
+ not make mutation, retry, or demand irrelevant.
39
+
40
+ ## Conventional Interface
41
+
42
+ Independent stages may exchange a shared shape:
43
+
44
+ ```text
45
+ enumerateOrders : Query -> Sequence<Order>
46
+ eligible : Sequence<Order> -> Sequence<Order>
47
+ invoice : Sequence<Order> -> Sequence<Invoice>
48
+ sum : Sequence<Invoice> -> Money
49
+ ```
50
+
51
+ State whether the sequence is eager/lazy, ordered/unordered, finite/unbounded,
52
+ single-use/replayable, and effectful/pure. A common type name does not guarantee
53
+ operational compatibility.
54
+
55
+ ## Artifact
56
+
57
+ ```text
58
+ Composition unit and membership rule:
59
+ Primitives:
60
+ Closed operations:
61
+ Observers/finalizers:
62
+ Invalid combinations:
63
+ Higher-order role contracts:
64
+ Conventional interface operational assumptions:
65
+ Transfer composition and failure check:
66
+ ```
67
+
68
+ ## Stop And Separation
69
+
70
+ Stop when closed operations can build every required larger value of the same
71
+ unit, finalizers are explicit, and conventional stages agree on operational
72
+ semantics.
73
+
74
+ Use `representation-barriers` when raw layout rather than composability is the
75
+ question, and `process-shape-and-resources` when eager/lazy/order/resource
76
+ assumptions need their own execution design.
77
+
78
+ ## Source Trace
79
+
80
+ - Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
81
+ Interpretation of Computer Programs*, Second Edition,
82
+ Section 1.3
83
+ for procedures as values and
84
+ Section 2.2
85
+ for closure and conventional interfaces.
86
+ - Operational interface assumptions and finalizer failure checks are Developer
87
+ adaptations of those composition boundaries.
@@ -0,0 +1,69 @@
1
+ # Composition By Wished Operations
2
+
3
+ Use this reference after the data-driven recipe when one accepted purpose contains
4
+ several independently meaningful subproblems whose results must compose.
5
+
6
+ ## Wish Before Helper Bodies
7
+
8
+ Write the product-level result first:
9
+
10
+ ```text
11
+ publishableTasks(tasks):
12
+ return sortByPriority(onlyReady(normalize(tasks)))
13
+ ```
14
+
15
+ For each wished operation state:
16
+
17
+ ```text
18
+ purpose and domain result
19
+ contract and failure behavior
20
+ representative examples
21
+ its own data-derived template
22
+ why it is an independent subproblem
23
+ ```
24
+
25
+ A helper is earned when it solves a separately nameable domain problem, delegates
26
+ to another data definition, or exposes a required intermediate result. Length
27
+ alone is not a purpose.
28
+
29
+ ## Composition Boundary
30
+
31
+ Check that adjacent results have compatible meaning, ordering, eagerness,
32
+ replayability, effects, and failure behavior. Acquisition, pure transformation,
33
+ and effects often deserve separate owners because their contracts differ, but do
34
+ not split an atomic invariant merely to obtain a neat pipeline.
35
+
36
+ ## Artifact
37
+
38
+ ```text
39
+ Top-level wished composition:
40
+ Subproblem purposes and contracts:
41
+ Intermediate result meanings:
42
+ Ordering, effect, and failure compatibility:
43
+ Independent examples and templates:
44
+ First composable implementation slice:
45
+ Deferred helpers:
46
+ ```
47
+
48
+ ## Stop And Separation
49
+
50
+ Stop when each wished operation can be designed and checked independently and the
51
+ top-level composition reads in product language without hiding an incompatible
52
+ process boundary.
53
+
54
+ Use `earned-abstraction` only after several completed correct designs expose
55
+ stable shared roles. Use process/state routes when the unresolved issue is
56
+ execution or history rather than decomposition.
57
+
58
+ ## Source Trace
59
+
60
+ - Matthias Felleisen et al., *How to Design Programs*, living build 9.2.0.3,
61
+ Chapter 11
62
+ for wish lists, composition, and independently designed functions.
63
+ - Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
64
+ Interpretation of Computer Programs*, Second Edition,
65
+ Section 1.1
66
+ for wishful decomposition and black-box procedures.
67
+ - Zachary Tellman, *Elements of Clojure*, Leanpub 2019-02-11, Composition,
68
+ public-manuscript pp. 98-115, calibrates composition units and phase ownership;
69
+ process details remain on their dedicated route.
@@ -1,10 +1,17 @@
1
1
  # Data-Driven Design
2
2
 
3
3
  Use this reference when product information should determine the program shape.
4
- The central insight is concrete: **a data definition is a construction rule for
5
- valid values, and that same rule determines the first honest function
6
- template**. Code shape should not be guessed from framework files or a favorite
7
- pattern when the cases are already present in the data.
4
+ It extends `sketch` from accepted meaning through data, examples, template, and
5
+ first executable item. Specialized references refine one later step; they do not
6
+ replace this derivation.
7
+
8
+ The central insight is concrete: **a data definition states how valid values are
9
+ constructed and what they mean, and that construction rule determines the first
10
+ honest structural template**. The template inventories possible branches,
11
+ fields, recursions, and delegations. Purpose and examples decide which available
12
+ parts the completed function actually uses. Code shape should not be guessed
13
+ from framework files or a favorite pattern when the cases are already present
14
+ in the data.
8
15
 
9
16
  ## The Six-Artifact Recipe
10
17
 
@@ -24,9 +31,31 @@ required case, repair the data definition. If the template exposes all required
24
31
  ingredients but the result is wrong, repair the completed body. If no template
25
32
  ingredient can express the purpose, design an auxiliary with its own recipe.
26
33
 
27
- In an existing repository, recover the same artifacts from schemas, types,
28
- fixtures, callers, UI states, persistence, and tests. Do not copy pedagogical
29
- comments into production merely to imitate the recipe.
34
+ In an existing repository, recover equivalent evidence from schemas, types,
35
+ fixtures, callers, UI states, persistence, and tests. This recovery is a
36
+ Developer adaptation for production repositories, not a claim that HtDP replaces
37
+ its pedagogical artifacts with those sources. Do not copy recipe comments into
38
+ production merely to imitate the teaching form.
39
+
40
+ ## Function Recipe Versus Program Recipe
41
+
42
+ The six artifacts organize one function. Whole-program design has a different
43
+ collaboration:
44
+
45
+ ```text
46
+ analyze the information and external interfaces
47
+ -> sketch a top-down wish list of needed functions
48
+ -> choose a coherent inspectable slice
49
+ -> design wished functions bottom-up with the small recipe
50
+ -> run or demonstrate the slice
51
+ -> refine the model and work list from observed discrepancies
52
+ ```
53
+
54
+ Do not flatten top-down planning and bottom-up function construction into one
55
+ large template. Iterative refinement changes an intentionally simplified model
56
+ and propagates the change through data examples, behavior examples, templates,
57
+ implementations, tests, and compatibility surfaces. It is not arbitrary cleanup
58
+ of an unchanged problem.
30
59
 
31
60
  ## Complete Example: Let The Variants Write The Skeleton
32
61
 
@@ -108,20 +137,29 @@ Run all three examples. Then try a fake fourth variant. A compiler failure or
108
137
  explicit missing branch reveals the exact extension point; a catch-all returning
109
138
  an empty string would hide it.
110
139
 
111
- ## Select The Specific Recipe
140
+ ## Select One Design Extension
112
141
 
113
- Read only the detail that matches the unresolved design question:
142
+ Read only the extension that answers the unresolved question:
114
143
 
115
- | Evidence | Read | Expected artifact |
144
+ | Question after the base recipe | Read | Expected artifact |
116
145
  | --- | --- | --- |
117
- | atomic values, intervals, itemizations, records, recursive or mutually recursive data, multiple complex inputs, complex outputs, or event loops | [Data-Shape Template Catalog](data-shape-template-catalog.md) | a template whose branches, selectors, recursive positions, and delegations correspond to the data definition |
118
- | wished helpers, several completed concrete functions, generated subproblems, termination uncertainty, repeated work, or lost traversal knowledge | [Composition, Generative Recursion, And Accumulators](composition-generative-recursion-and-accumulators.md) | separately designed auxiliaries, a justified abstraction, a generation template plus termination argument, or an accumulator invariant |
146
+ | Which branches, selectors, recursive positions, or delegations follow from this data shape? | [Data-Shape Template Catalog](data-shape-template-catalog.md) | a data-corresponding template |
147
+ | Which independently meaningful operations compose the result? | [Composition By Wished Operations](composition-by-wishes.md) | wished-operation contracts and one composable slice |
148
+ | Which stable roles appear across several completed designs? | [Earned Abstraction](earned-abstraction.md) | completed-design alignment, variation-role table, and candidate handoff |
149
+ | How are new problem instances generated, preserved, and proven to progress? | [Generative Recursion](generative-recursion.md) | generation, preservation, combination, and progress artifacts |
150
+ | What lost knowledge or repeated work should traversal carry? | [Accumulator Invariants](accumulator-invariants.md) | an original/current/accumulated invariant with ownership and semantic-delta checks |
119
151
 
120
- These documents extend this recipe; they do not replace the six artifacts.
152
+ Each extension refines a different design step. Select several only when their
153
+ questions are independently consequential; do not treat them as a progression or
154
+ one bundled recursion topic.
121
155
 
122
- ## Existing-Code Recovery
156
+ ## Existing-Code Recovery (Developer Adaptation)
123
157
 
124
- Use this recovery table rather than assuming the declared type is complete.
158
+ Use this recovery table rather than assuming the declared type is complete. The
159
+ evidence sources and compatibility obligations below adapt HtDP's artifacts to
160
+ an existing repository; they are package-owned operational guidance.
161
+
162
+ <!-- markdownlint-disable MD013 -->
125
163
 
126
164
  | Artifact | Repository evidence | Typical contradiction |
127
165
  | --- | --- | --- |
@@ -132,10 +170,31 @@ Use this recovery table rather than assuming the declared type is complete.
132
170
  | template | branches, selectors, traversal, delegation | catch-all hides a meaningful clause |
133
171
  | completed body | implementation | code needs information absent from the data model |
134
172
 
173
+ <!-- markdownlint-enable MD013 -->
174
+
135
175
  When evidence conflicts, keep the contradiction visible. `model` owns disputed
136
176
  validity or policy; this reference shapes the implementable surface once the
137
177
  meaning is accepted.
138
178
 
179
+ ## Propagate Model Refinement
180
+
181
+ When a required case cannot be represented or a forbidden value remains easy to
182
+ construct, revise one accepted model fact and propagate it through:
183
+
184
+ ```text
185
+ data definition and interpretation
186
+ -> data examples
187
+ -> behavior examples
188
+ -> template
189
+ -> implementation
190
+ -> checks
191
+ -> persisted and public compatibility surfaces
192
+ ```
193
+
194
+ A type edit is not complete while older serialized values or callers still use
195
+ the prior model. Propagation is a consistency obligation, not permission for
196
+ unrelated cleanup.
197
+
139
198
  ## Sketch Output
140
199
 
141
200
  ```text
@@ -152,6 +211,8 @@ Deferred: abstractions or policies not yet earned
152
211
 
153
212
  ## Failure Diagnosis
154
213
 
214
+ <!-- markdownlint-disable MD013 -->
215
+
155
216
  | Symptom | Return to |
156
217
  | --- | --- |
157
218
  | valid product case has no representation | data definition and interpretation |
@@ -163,15 +224,31 @@ Deferred: abstractions or policies not yet earned
163
224
  | abstraction precedes comparable completed designs | abstraction-from-examples recipe |
164
225
  | changed type ignores stored/public older forms | existing-code recovery and compatibility model |
165
226
 
227
+ <!-- markdownlint-enable MD013 -->
228
+
166
229
  ## Source Trace
167
230
 
168
231
  - Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram
169
- Krishnamurthi, *How to Design Programs, Second Edition*, MIT Press, 2018,
170
- and the [official living edition](https://htdp.org/2026-5-28/Book/index.html):
171
- information analysis, data definitions and interpretations, examples,
172
- signatures and purpose statements, templates, implementations, tests, and
173
- iterative refinement.
232
+ Krishnamurthi, *How to Design Programs*, official living build 9.2.0.3,
233
+ released 2026-05-28 and audited 2026-05-28:
234
+ Preface: Systematic Program Design
235
+ for the ordered recipe and function/program distinction;
236
+ Chapter 3: How to Design Programs
237
+ for signatures, purpose, examples, templates, definitions, and tests;
238
+ Chapter 6: Itemizations and Structures
239
+ for mixed-data derivation; and
240
+ Epilogue: Moving On
241
+ for top-down work lists, bottom-up construction, feedback, and maintenance
242
+ communication.
243
+ - The repository-recovery table, compatibility surfaces, and production artifact
244
+ substitutions are Developer adaptations derived from the source method; they
245
+ are not canonical HtDP artifacts.
174
246
  - Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
175
247
  Interpretation of Computer Programs*, Second Edition, MIT Press, 1996:
176
- wishful decomposition and the distinction between procedure text and the
177
- process it generates.
248
+ Section 2.1
249
+ for wishful decomposition and
250
+ Section 1.2
251
+ for the distinction between procedure text and the process it generates. Data
252
+ interpretation, templates, ordered recipe steps, repository recovery, and
253
+ compatibility artifacts remain HtDP-derived or Developer adaptations as
254
+ identified above.
@@ -1,7 +1,10 @@
1
1
  # Data-Shape Template Catalog
2
2
 
3
3
  Use this catalog after the six-artifact recipe in
4
- [Data-Driven Design](data-driven-design.md). Its core rule is:
4
+ [Data-Driven Design](data-driven-design.md) when the unresolved step is deriving
5
+ the structural template. Stop after branches, selectors, recursions, and
6
+ delegations correspond to accepted data; generated algorithms and carried
7
+ knowledge have separate routes. Its core rule is:
5
8
 
6
9
  ```text
7
10
  data clause -> function branch
@@ -10,8 +13,10 @@ self-reference -> natural recursive call at that exact position
10
13
  reference to B -> delegation to B's template at that exact position
11
14
  ```
12
15
 
13
- The template inventories available ingredients. The purpose and examples decide
14
- how to combine them.
16
+ The initial template inventories all structurally available ingredients. The
17
+ purpose and examples decide how to combine them and may justify omitting an
18
+ irrelevant selector, recursion, or delegation from the completed body. Record
19
+ that omission instead of pretending the data reference never existed.
15
20
 
16
21
  ## Atomic And Fixed-Size Data
17
22
 
@@ -57,13 +62,17 @@ render(result):
57
62
  ```
58
63
 
59
64
  Merge two clauses only when their product meaning, not merely their current body,
60
- is the same. A catch-all branch is suspicious when adding a variant should force
61
- a new decision.
65
+ is the same. A catch-all branch is justified only when every accepted remainder
66
+ has one known meaning. It is suspicious when adding a variant should force a new
67
+ decision, or when it groups unmodeled external values with a domain default.
62
68
 
63
69
  ## Structures And Records
64
70
 
65
- A record groups a fixed natural whole. List only fields relevant to the purpose;
66
- the template is not permission to expose every stored field.
71
+ A record groups a fixed natural whole. The canonical structural template first
72
+ lists the record's selectors so the complete inventory is visible. A production
73
+ sketch may destructure only purpose-relevant fields, but that is a Developer
74
+ adaptation: explain why omitted fields cannot affect the stated result instead of
75
+ silently treating them as nonexistent.
67
76
 
68
77
  ```text
69
78
  Schedule = Schedule(start, end, timezone)
@@ -79,8 +88,9 @@ than stated or the data definition lacks information.
79
88
  ## Self-Referential Data
80
89
 
81
90
  A valid self-referential definition has at least one non-recursive clause from
82
- which values can be constructed and at least one recursive clause that creates
83
- larger values.
91
+ which finite values can be constructed and at least one recursive clause that
92
+ creates larger values. A self-reference with no reachable base describes no
93
+ finite value and must be repaired before a recursive template is trusted.
84
94
 
85
95
  ```text
86
96
  Tasks = Empty | Node(Task, Tasks)
@@ -147,8 +157,11 @@ countBlock(block):
147
157
  Image(src) -> 0
148
158
  ```
149
159
 
150
- The reference graph, not convenience, determines the delegations. An oversized
151
- function with nested tags usually means the template family was collapsed.
160
+ The reference graph, not convenience, determines the initial delegations. An
161
+ oversized function with nested tags usually means the template family was
162
+ collapsed. In a completed function, purpose may eliminate a structurally
163
+ available delegation; the evidence is the explicit purpose, not convenience or
164
+ call-count reduction.
152
165
 
153
166
  ## Two Complex Inputs
154
167
 
@@ -156,11 +169,16 @@ Do not automatically multiply every clause. Decide how the two values move.
156
169
 
157
170
  ### One input controls
158
171
 
159
- `applyDiscounts(cart, rules)` traverses the cart while `rules` is constant or
160
- queried. Derive the traversal from `Cart`; treat `Rules` as domain knowledge.
172
+ `applyDiscounts(cart, rules)` traverses the cart while `rules` is carried as a
173
+ complete value or queried. Derive recursive progress from `Cart`; do not
174
+ decompose `Rules` merely because its representation is complex.
161
175
 
162
176
  ### Inputs move in lockstep
163
177
 
178
+ Use this route only when a same-size or same-shape invariant and positional
179
+ correspondence make progress on both inputs meaningful. State what happens when
180
+ the invariant is violated; do not inherit shortest-input truncation silently.
181
+
164
182
  `sameShape(leftTree, rightTree)` compares corresponding nodes. State the shape
165
183
  relation and branch on paired cases:
166
184
 
@@ -172,9 +190,16 @@ relation and branch on paired cases:
172
190
 
173
191
  ### Inputs vary independently
174
192
 
193
+ When neither control nor lockstep correspondence applies, enumerate the
194
+ Cartesian product of data alternatives. Use one case example per meaningful cell,
195
+ inventory the selectors available there, and treat all selector-based recursive
196
+ calls as candidates until purpose selects which arguments progress together.
197
+
175
198
  Collision policy between `UserRole` and `ResourceState` may need the meaningful
176
199
  cross-product or a decision table. Write all relevant combinations explicitly;
177
- do not hide them in nested defaults.
200
+ do not hide them in nested defaults. For three independent complex inputs the
201
+ same reasoning becomes a conceptual three-dimensional space; first look for a
202
+ better relation or decomposition before materializing the cube.
178
203
 
179
204
  The smell is not “two loops.” It is an unstated relationship between the input
180
205
  shapes.
@@ -234,8 +259,22 @@ temporal rule to `model`.
234
259
 
235
260
  ## Source Trace
236
261
 
237
- - [*How to Design Programs*, official living edition](https://htdp.org/2026-5-28/Book/index.html):
238
- the recipes for atomic data, intervals, itemizations, structures,
239
- self-referential and intertwined definitions, multiple complex inputs,
240
- complex outputs, and world programs. The examples here are adapted to ordinary
241
- product code and are not copied from the book.
262
+ - Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram
263
+ Krishnamurthi, *How to Design Programs*, official living build 9.2.0.3,
264
+ released 2026-05-28 and audited 2026-05-28:
265
+ Chapter 4,
266
+ Chapter 5,
267
+ and Chapter 6
268
+ for intervals, itemizations, records, and mixed data;
269
+ Chapter 8,
270
+ Chapter 9,
271
+ and Chapter 10
272
+ for constructible self-reference and natural recursion;
273
+ Chapter 19
274
+ for mutually referential definitions and template families; and
275
+ Chapter 23
276
+ plus Chapter 24
277
+ for controlling, lockstep, and Cartesian multi-input design.
278
+ - Purpose-only destructuring, product-language examples, explicit invariant
279
+ violation behavior, and repository diagnostics are Developer adaptations. The
280
+ source's initial structure templates inventory the full selector set.
@@ -0,0 +1,133 @@
1
+ # Design Levels And Boundaries
2
+
3
+ Use this reference when a sketch must decide which vocabulary a caller may use,
4
+ which owner controls a consequential choice, and which lower-level details may
5
+ change independently. It is the common kernel for representation, process,
6
+ state, generic-operation, and language routes; it does not contain their
7
+ specialized construction methods.
8
+
9
+ ## Boundary Spine
10
+
11
+ ```text
12
+ caller purpose and cases
13
+ -> wished operations in caller language
14
+ -> contract and admitted observers
15
+ -> owner of policy/invariant/history
16
+ -> hidden lower-level choice
17
+ -> alternate implementation or counterexample
18
+ ```
19
+
20
+ A boundary is real only when it hides a consequential choice and leaves a
21
+ smaller truthful contract. A renamed mechanism is not a new level.
22
+
23
+ ## Write Levels Explicitly
24
+
25
+ ```text
26
+ product level:
27
+ operations users or callers intend
28
+
29
+ domain/service level:
30
+ concepts, laws, roles, and state transitions
31
+
32
+ mechanism level:
33
+ storage fields, libraries, transport, threads, runtime instructions
34
+ ```
35
+
36
+ Each level may depend on the vocabulary immediately below it. Higher levels must
37
+ not inspect the representation that a lower owner promises to hide. Add a level
38
+ only when it supplies meaningful primitives, combinations, or reusable laws.
39
+
40
+ ## Contract Before Shape
41
+
42
+ For each wished operation state:
43
+
44
+ ```text
45
+ caller-visible result and failure
46
+ normal, boundary, and forbidden examples
47
+ observers callers may rely on
48
+ owner of validation, normalization, state, or ordering
49
+ mechanism callers should stop knowing
50
+ smallest replacement or falsifying check
51
+ ```
52
+
53
+ Do not invent public selectors merely because a representation has fields. Expose
54
+ only operations current caller purposes support. Conversely, a claimed boundary
55
+ is false when callers still need raw layout to complete their work.
56
+
57
+ ## Environment And Assumptions
58
+
59
+ Every boundary models an environment:
60
+
61
+ ```text
62
+ environment: real participants and change pressure
63
+ model: represented facets
64
+ ignored facts: deliberately outside the contract
65
+ interface: stable sense exposed to callers
66
+ assumptions: environmental facts required for usefulness
67
+ drift signal: evidence assumptions may no longer hold
68
+ ```
69
+
70
+ Internal invariants can keep the model self-consistent; they cannot prevent the
71
+ environment from changing. Public boundaries calcify, so mature them locally when
72
+ participants co-evolve. Independent participants, purposes, deployment cycles, or
73
+ replacement pressure justify stronger interfaces.
74
+
75
+ ## Select One Specialized Judgment
76
+
77
+ | Unresolved question | Reference | Output |
78
+ | --- | --- | --- |
79
+ | representation independence and public laws | [Representation Barriers](representation-barriers.md) | public operations/laws, two representations, caller rewrite, and leak check |
80
+ | closed composition or conventional interfaces | [Closure And Conventional Interfaces](closure-and-conventional-interfaces.md) | unit, closed operations, finalizers, and operational interface contract |
81
+ | generated work, control, waits, capacity, resources, or effects | [Process Shape And Resources](process-shape-and-resources.md) | process trace, bounds, phase and completion ownership |
82
+ | history, identity, mutation, state transition, event order, or logs | [State, History, And Order](state-history-and-order.md) | history owner, transition/order law, stale/duplicate policy |
83
+ | additive representations and operation dispatch | [Generic Dispatch Systems](generic-dispatch-systems.md) | variant-operation matrix and conflict policy |
84
+ | cross-representation operation and semantic loss | [Meaning-Preserving Conversions](meaning-preserving-conversions.md) | conversion graph and preserved/lost observers |
85
+ | notation, grammar, evaluator, and language results | [Language Semantics](language-semantics.md) | expression boundary and evaluator/result contract |
86
+ | interpreter/compiler lowering and optimization | [Runtime And Compilation](runtime-and-compilation.md) | execution convention, effects, guards, roots, and interoperation |
87
+ | knowledge and participant ownership | [Responsibility And Collaboration](responsibility-and-collaboration.md) | responsibility and collaboration map |
88
+ | shared caller roles across implementations | [Variation Roles](variation-roles.md) | role and substitution contract |
89
+ | one domain type becoming another | [Type Transitions](type-transitions.md) | source/event/target and preserved-meaning contract |
90
+ | variant selection and construction | [Selection And Creation](selection-and-creation.md) | selection owner and least-powerful creation boundary |
91
+
92
+ Select several only when they answer independent questions. Do not load this
93
+ common kernel as permission to absorb the specialized judgment.
94
+
95
+ ## Artifact
96
+
97
+ ```text
98
+ Caller purpose and representative cases:
99
+ Wished operations:
100
+ Levels and dependency direction:
101
+ Contract and observers:
102
+ Owner:
103
+ Hidden choice:
104
+ Environment, ignored facts, assumptions, and drift:
105
+ Alternate implementation or falsifier:
106
+ Specialized handoff:
107
+ ```
108
+
109
+ ## Stop And Separation
110
+
111
+ Stop when every dependency arrow uses a truthful vocabulary, each guarantee has
112
+ one owner, and a lower-level choice can be varied or falsified without rewriting
113
+ unrelated callers.
114
+
115
+ Separate when the unresolved issue has its own output and stop check in the table
116
+ above. Return to `model` when admitted meaning is disputed, and to
117
+ `abstraction-review` only after the candidate surface exists.
118
+
119
+ ## Source Trace
120
+
121
+ - Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
122
+ Interpretation of Computer Programs*, Second Edition:
123
+ Section 1.1,
124
+ Section 1.2,
125
+ Section 1.3,
126
+ and Section 2.1
127
+ for wishful decomposition, levels of language, procedures as black boxes, data
128
+ abstraction, and representation laws.
129
+ - Zachary Tellman, *Elements of Clojure*, Leanpub 2019-02-11:
130
+ Indirection, public-manuscript pp. 70-95, for environment/model/interface/
131
+ assumptions, participant pressure, interface collapse, and calcification.
132
+ - Hillel Wayne, *Logic for Programmers*, v0.14.0:
133
+ Chapters 2-3 and 9-10 for ability/guarantee and observer-relative refinement.
@@ -0,0 +1,75 @@
1
+ # Earned Abstraction
2
+
3
+ Use this reference when at least two correct completed designs with stable
4
+ purposes and data models may share one common movement and variation-role set.
5
+
6
+ ## Align Completed Designs
7
+
8
+ ```text
9
+ sum: Empty -> 0; Node(x, xs) -> x + sum(xs)
10
+ allReady: Empty -> true; Node(x, xs) -> x.ready && allReady(xs)
11
+ ```
12
+
13
+ Align roles:
14
+
15
+ | Role | `sum` | `allReady` |
16
+ | --- | --- | --- |
17
+ | base | `0` | `true` |
18
+ | item projection | identity | readiness |
19
+ | combination | addition | conjunction |
20
+
21
+ Only then is a candidate such as `fold(sequence, base, project, combine)` visible.
22
+ The shared template locates a candidate; it does not approve it.
23
+
24
+ ## Stability And Migration
25
+
26
+ Check:
27
+
28
+ - roles have domain or process meaning rather than syntax-fragment names;
29
+ - old designs become simple clients after migration;
30
+ - one realistic transfer case fits without flags exposing internals;
31
+ - evaluation order, effects, errors, numeric association, and resource shape are
32
+ preserved for declared observers;
33
+ - the data interpretation is stable enough that difference is understood.
34
+
35
+ An abstraction is not a single point of control until intended clients migrate.
36
+ Stop at a candidate and route `abstraction-review` for promotion.
37
+
38
+ ## Artifact
39
+
40
+ ```text
41
+ Completed concrete designs and purposes:
42
+ Aligned common movement:
43
+ Variation-role table:
44
+ Candidate interface and caller examples:
45
+ Process and observer obligations:
46
+ Client migration boundary:
47
+ Transfer case:
48
+ Deferred or rejected abstraction:
49
+ ```
50
+
51
+ ## Stop And Separation
52
+
53
+ Stop when completed designs align under stable roles, migrated clients are
54
+ simple, and one transfer case fits without semantic drift. The result is a
55
+ candidate, not approval.
56
+
57
+ Return to `signal` when only horizontal similarity is visible, to `model` when
58
+ data meaning is unstable, and to `abstraction-review` for keep/revise/split/
59
+ reject/defer.
60
+
61
+ ## Source Trace
62
+
63
+ - Matthias Felleisen et al., *How to Design Programs*, living build 9.2.0.3:
64
+ Chapter 14,
65
+ Chapter 15,
66
+ and Chapter 16
67
+ for completed examples, aligned roles, abstraction, and client use; Chapters
68
+ 19-20 calibrate model stability before simplification.
69
+ - Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
70
+ Interpretation of Computer Programs*, Second Edition,
71
+ Section 1.3
72
+ for higher-order procedure roles.
73
+ - Sandi Metz, Katrina Owen, and TJ Stankus, *99 Bottles of OOP*, Second Edition,
74
+ v2.2.2, Chapters 3-4, pp. 51-101, calibrates smallest difference, horizontal
75
+ movement, stable landings, and the stop before promotion.