@hassangameryt/freeflow 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/.codex-plugin/plugin.json +4 -5
  4. package/README.md +39 -55
  5. package/capabilities/cognitive-routing/SKILL.md +288 -130
  6. package/command-surface.json +0 -24
  7. package/hooks/freeflow-runtime-context.mjs +42 -477
  8. package/hooks/hooks.json +1 -26
  9. package/hooks/tests/check-runtime-context-hook.sh +108 -319
  10. package/package.json +4 -2
  11. package/pi-extension/dist/cognitive-routing/commands.js +3 -3
  12. package/pi-extension/dist/cognitive-routing/config.js +16 -20
  13. package/pi-extension/dist/cognitive-routing/controller.js +478 -48
  14. package/pi-extension/dist/cognitive-routing/history.js +12 -0
  15. package/pi-extension/dist/cognitive-routing/host.js +74 -12
  16. package/pi-extension/dist/cognitive-routing/pi-routing-session.js +414 -0
  17. package/pi-extension/dist/cognitive-routing/pi-session-control.js +320 -0
  18. package/pi-extension/dist/cognitive-routing/tool.js +1 -0
  19. package/pi-extension/dist/cognitive-routing/types.js +1 -1
  20. package/pi-extension/dist/index.js +236 -219
  21. package/pi-extension/dist/runtime/runtime-context.js +126 -286
  22. package/pi-extension/dist/settings/settings-ui.js +52 -336
  23. package/pi-extension/src/cognitive-routing/commands.ts +15 -5
  24. package/pi-extension/src/cognitive-routing/config.ts +16 -20
  25. package/pi-extension/src/cognitive-routing/controller.ts +561 -51
  26. package/pi-extension/src/cognitive-routing/history.ts +12 -0
  27. package/pi-extension/src/cognitive-routing/host.ts +110 -16
  28. package/pi-extension/src/cognitive-routing/pi-routing-session.ts +538 -0
  29. package/pi-extension/src/cognitive-routing/pi-session-control.ts +444 -0
  30. package/pi-extension/src/cognitive-routing/tool.ts +1 -0
  31. package/pi-extension/src/cognitive-routing/types.ts +1 -1
  32. package/pi-extension/src/index.ts +249 -239
  33. package/pi-extension/src/runtime/runtime-context.ts +129 -305
  34. package/pi-extension/src/settings/settings-ui.ts +53 -371
  35. package/pi-extension/tests/cognitive-routing/commands.test.js +1 -1
  36. package/pi-extension/tests/cognitive-routing/controller.test.js +69 -40
  37. package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +128 -57
  38. package/pi-extension/tests/cognitive-routing/pi-normal-lifecycle.test.js +434 -0
  39. package/pi-extension/tests/cognitive-routing/pi-session-control.test.js +174 -0
  40. package/pi-extension/tests/cognitive-routing/pi-session-history.test.js +91 -0
  41. package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +47 -4
  42. package/pi-extension/tests/integration/mode-free-core.test.js +218 -0
  43. package/pi-extension/tests/integration/pi-extension.test.js +430 -2478
  44. package/pi-extension/tests/integration/prompt-architecture.test.js +124 -79
  45. package/pi-extension/tests/integration/unaffected-regressions.test.js +411 -0
  46. package/runtime/prompts/cognitive-routing.md +5 -4
  47. package/runtime/prompts/conversation-history.md +1 -1
  48. package/runtime/prompts/core.md +77 -6
  49. package/runtime/prompts/interaction-contract.md +6 -2
  50. package/skills/action-selection/SKILL.md +93 -44
  51. package/skills/action-selection/references/trajectory-stalls.md +71 -0
  52. package/skills/bypass/SKILL.md +109 -39
  53. package/skills/commit-work/SKILL.md +94 -55
  54. package/skills/commit-work/references/git-state-edges.md +94 -0
  55. package/skills/commit-work/references/simple-push.md +92 -0
  56. package/skills/commit-work/references/staging-decisions.md +79 -46
  57. package/skills/decision-gate/SKILL.md +80 -22
  58. package/skills/design-for-depth/SKILL.md +208 -43
  59. package/skills/design-for-depth/references/design-pressure-signals.md +108 -240
  60. package/skills/design-for-depth/references/interface-design-loop.md +77 -97
  61. package/skills/design-for-depth/references/module-and-dependency-design.md +147 -0
  62. package/skills/design-for-depth/references/software-design-philosophy.md +127 -173
  63. package/skills/design-for-depth/references/state-and-failure-boundaries.md +136 -0
  64. package/skills/diagnose-failure/SKILL.md +198 -52
  65. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +19 -5
  66. package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +13 -5
  67. package/skills/discuss/SKILL.md +118 -76
  68. package/skills/discuss/references/discussion-continuity.md +84 -32
  69. package/skills/evaluate-skill/SKILL.md +166 -52
  70. package/skills/evaluate-skill/references/evaluation-definition-schema.md +2 -2
  71. package/skills/evaluate-skill/references/evaluation-design.md +56 -30
  72. package/skills/evaluate-skill/references/execution-and-evidence.md +1 -1
  73. package/skills/evaluate-skill/references/review-and-revision.md +62 -21
  74. package/skills/execute-work/SKILL.md +98 -59
  75. package/skills/execute-work/references/code-practices.md +4 -4
  76. package/skills/execute-work/references/execute-work-edges.md +42 -22
  77. package/skills/review-artifact/SKILL.md +132 -71
  78. package/skills/review-artifact/references/adjudicate-artifact-review.md +101 -0
  79. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +52 -41
  80. package/skills/review-work/SKILL.md +115 -72
  81. package/skills/review-work/references/adjudicate-work-review.md +97 -0
  82. package/skills/review-work/references/independent-work-reviewer-contract.md +40 -35
  83. package/skills/review-work/references/security-risk-lens.md +17 -15
  84. package/skills/setup-freeflow/SKILL.md +14 -17
  85. package/skills/setup-freeflow/references/activation-contract.md +24 -30
  86. package/skills/setup-freeflow/references/host-setup.md +6 -7
  87. package/skills/simplify-code/SKILL.md +97 -39
  88. package/skills/simplify-code/references/simplification-patterns.md +1 -1
  89. package/skills/tdd/SKILL.md +108 -41
  90. package/skills/tdd/references/test-design.md +1 -1
  91. package/skills/track-work/SKILL.md +133 -300
  92. package/skills/track-work/references/working-record-format.md +515 -0
  93. package/skills/track-work/scripts/lib/document.mjs +713 -0
  94. package/skills/track-work/scripts/lib/format.mjs +166 -0
  95. package/skills/track-work/scripts/lib/store.mjs +233 -0
  96. package/skills/track-work/scripts/lib/transitions.mjs +790 -0
  97. package/skills/track-work/scripts/lib/views.mjs +27 -430
  98. package/skills/track-work/scripts/working-record.mjs +292 -98
  99. package/skills/verify-work/SKILL.md +46 -20
  100. package/skills/verify-work/references/browser-runtime-evidence.md +1 -1
  101. package/skills/verify-work/references/integration-evidence.md +1 -7
  102. package/skills/verify-work/references/performance-evidence.md +1 -1
  103. package/skills/workflow/SKILL.md +110 -80
  104. package/skills/workflow/references/domain-skill-composition.md +24 -18
  105. package/skills/write-skill/SKILL.md +218 -62
  106. package/skills/write-skill/references/activation-boundaries.md +63 -21
  107. package/skills/write-skill/references/agent-first-instructions.md +61 -27
  108. package/skills/write-skill/references/progressive-disclosure.md +91 -41
  109. package/skills/write-skill/references/skill-dependency-graphs.md +190 -0
  110. package/runtime/prompts/skills.md +0 -65
  111. package/skills/mode-contract/SKILL.md +0 -104
  112. package/skills/track-work/scripts/lib/codec.mjs +0 -570
  113. package/skills/track-work/scripts/lib/commands.mjs +0 -568
  114. package/skills/track-work/scripts/lib/contract.mjs +0 -303
  115. package/skills/track-work/scripts/lib/model.mjs +0 -506
  116. package/skills/track-work/scripts/lib/operations.mjs +0 -965
  117. package/skills/track-work/scripts/lib/record-store.mjs +0 -264
  118. package/skills/track-work/scripts/lib/result.mjs +0 -37
  119. package/skills/track-work/scripts/lib/rewrites.mjs +0 -740
  120. package/skills/track-work/scripts/lib/schema.mjs +0 -277
  121. package/skills/track-work/scripts/lib/source-inventory.mjs +0 -162
  122. package/skills/track-work/scripts/lib/workspace.mjs +0 -134
@@ -0,0 +1,147 @@
1
+ # Module And Dependency Design
2
+
3
+ Read this when module decomposition, cohesion, dependency direction, cycles, layering, policy-versus-infrastructure ownership, or change propagation materially affects the design.
4
+
5
+ Do not use this reference merely because the codebase has many files or dependencies.
6
+
7
+ ## Decompose Around Coherent Decisions
8
+
9
+ A module should own one coherent outcome, policy, state boundary, or failure unit.
10
+
11
+ Do not split only by:
12
+
13
+ - processing step;
14
+ - technical file type;
15
+ - framework convention;
16
+ - arbitrary size;
17
+ - desire for more abstractions.
18
+
19
+ Ask:
20
+
21
+ - Which behavior changes together?
22
+ - Which decision has one reason to change?
23
+ - Which state and failure behavior belong together?
24
+ - What should callers stop coordinating?
25
+
26
+ ## Prefer Cohesion Over Convenience
27
+
28
+ High cohesion means related behavior, invariants, state, and failure handling live together.
29
+
30
+ Pressure exists when:
31
+
32
+ - one module owns unrelated policies;
33
+ - one policy is spread across many modules;
34
+ - state transitions are separated from their invariants;
35
+ - failure handling is detached from the operation it protects;
36
+ - callers assemble the real behavior from helpers.
37
+
38
+ Do not centralize unrelated behavior merely to reduce duplication.
39
+
40
+ ## Direct Dependencies Toward Stable Policy
41
+
42
+ Policy should not depend directly on volatile infrastructure details when those details can change independently.
43
+
44
+ Prefer:
45
+
46
+ ```text
47
+ stable outcome or policy
48
+ -> small dependency interface
49
+ -> infrastructure adapter
50
+ ```
51
+
52
+ Use dependency inversion only when it hides real variation, provider mechanics, migration, or testing control.
53
+
54
+ Do not add interfaces around every concrete implementation.
55
+
56
+ ## Detect Dependency Cycles
57
+
58
+ A dependency cycle often indicates:
59
+
60
+ - responsibilities are divided incorrectly;
61
+ - shared policy has no owner;
62
+ - state is jointly owned;
63
+ - interfaces expose implementation details;
64
+ - modules must know each other’s lifecycle.
65
+
66
+ Do not break a cycle by moving imports or creating a neutral-looking utility while preserving the same conceptual cycle.
67
+
68
+ Name the shared decision and assign ownership.
69
+
70
+ ## Preserve Honest Layering
71
+
72
+ A layer is useful when it hides a distinct level of decision.
73
+
74
+ A layer is shallow when it:
75
+
76
+ - forwards calls;
77
+ - renames types;
78
+ - exposes lower-layer errors and states;
79
+ - requires callers to understand both layers;
80
+ - exists only to satisfy a pattern.
81
+
82
+ Allow a higher-level module to request outcomes. Keep infrastructure details below the boundary.
83
+
84
+ ## Use Ports And Adapters Proportionately
85
+
86
+ A port is an outcome or capability required by policy. An adapter supplies concrete infrastructure.
87
+
88
+ Use when:
89
+
90
+ - provider variation exists;
91
+ - migration is known;
92
+ - infrastructure details leak into policy;
93
+ - tests require safe dependency control.
94
+
95
+ Avoid when:
96
+
97
+ - one stable implementation exists;
98
+ - the wrapper hides no decision;
99
+ - the generic interface preserves provider quirks;
100
+ - caller complexity does not decrease.
101
+
102
+ ## Keep Shared Code From Becoming Shared Ownership
103
+
104
+ A shared helper may centralize syntax while leaving policy ownership scattered.
105
+
106
+ Before extracting shared code, ask:
107
+
108
+ - Is this one concept that should evolve together?
109
+ - Who owns its behavior and failure contract?
110
+ - Are callers still making the same decision independently?
111
+ - Does extraction remove coordination or merely relocate code?
112
+
113
+ Some duplication is cheaper than a shared abstraction with unclear ownership.
114
+
115
+ ## Test Through Module Contracts
116
+
117
+ Module tests should protect:
118
+
119
+ - coherent behavior;
120
+ - invariants;
121
+ - public failure semantics;
122
+ - dependency contracts;
123
+ - real seams.
124
+
125
+ Question module shape when tests must:
126
+
127
+ - construct many internals;
128
+ - reproduce dependency ordering;
129
+ - mock several owned collaborators;
130
+ - inspect states callers should not know.
131
+
132
+ Do not make production architecture imitate the test framework.
133
+
134
+ ## Return
135
+
136
+ Return:
137
+
138
+ - affected modules and responsibilities;
139
+ - policy, state, or failure ownership;
140
+ - dependency direction;
141
+ - cycle or layering pressure;
142
+ - proposed boundary and caller contract;
143
+ - variation or migration justifying seams;
144
+ - evidence and unresolved decisions;
145
+ - narrowest supported route.
146
+
147
+ Stop when dependencies support the selected outcome without unnecessary coordination. Do not reorganize the entire codebase for conceptual purity.
@@ -2,247 +2,201 @@
2
2
 
3
3
  Read this when structural pressure is supported but the likely-changing decision or missing information-hiding boundary cannot yet be named.
4
4
 
5
- This is not a checklist to run every time. Pull the idea that changes the next route.
5
+ Use only the principle that identifies the missing ownership. Do not produce a literature review, pattern catalog, or system-wide redesign.
6
6
 
7
- ## Core Claim
7
+ ## Complexity Is Coordination
8
8
 
9
- Good design reduces coordination.
9
+ Complexity is not line count. It appears as:
10
10
 
11
- A deep module lets callers, tests, reviewers, and future agents use a small interface to get a lot of behavior. A shallow module makes them learn almost as much as the implementation.
11
+ - **Change amplification:** one behavior change requires many surrounding edits.
12
+ - **Cognitive load:** callers must remember many facts to use the module correctly.
13
+ - **Obscurity:** important rules or ownership are difficult to discover.
14
+ - **Dependency burden:** safe change requires understanding unrelated modules.
15
+ - **Unknown unknowns:** a caller cannot tell what else it must inspect.
12
16
 
13
- Design work is worthwhile when it hides a decision that would otherwise spread.
17
+ A large implementation can be simple to use. A small helper can be complex when every caller must know its quirks.
14
18
 
15
- ## Ousterhout: Complexity, Deep Modules, Strategic Programming
16
-
17
- ### Complexity
18
-
19
- Complexity shows up as:
19
+ Ask:
20
20
 
21
- - too many dependencies;
22
- - obscurity, where important facts are hard to find;
23
- - change amplification, where a small behavior change touches many places;
24
- - cognitive load, where the user of a module must remember too much;
25
- - unknown unknowns, where a future agent cannot tell what it must inspect.
21
+ - What must a future caller or maintainer know?
22
+ - How many locations must change together?
23
+ - Which important facts are difficult to discover?
24
+ - Which dependencies must be inspected before a safe change?
26
25
 
27
- For Freeflow, complexity is not “many lines.” A single compact helper can be complex if callers must know its quirks. A large implementation can be simple to use if the interface hides the hard parts.
26
+ ## Deep Modules
28
27
 
29
- ### Deep modules
28
+ A deep module provides substantial coherent behavior through a small interface.
30
29
 
31
- A deep module has a simple interface and useful behavior behind it.
30
+ Callers state the outcome they need. The module owns:
32
31
 
33
- Deep means:
32
+ - sequencing;
33
+ - likely-changing policy;
34
+ - internal state transitions;
35
+ - cleanup;
36
+ - provider mechanics;
37
+ - internal failure handling.
34
38
 
35
- - callers say what outcome they need;
36
- - implementation owns sequencing and policy details;
37
- - tests can verify behavior through the public interface;
38
- - future changes stay localized;
39
- - docs and review comments do not need to explain the hidden machinery every time.
39
+ A wrapper is not deep merely because it hides lines. It is deep when callers stop knowing concepts or coordinating protocol.
40
40
 
41
- Shallow means:
41
+ Depth is not breadth. A god module hiding unrelated decisions is not deep.
42
42
 
43
- - the interface mirrors the implementation;
44
- - callers pass many flags and know ordering rules;
45
- - tests assert internal call sequences;
46
- - wrappers rename work without hiding decisions;
47
- - future agents still need to inspect everything to use it safely.
43
+ ## Strategic And Tactical Design
48
44
 
49
- ### Strategic vs tactical programming
45
+ A tactical change makes the current patch fit.
50
46
 
51
- Tactical programming makes the current patch fit, even if it spreads complexity.
47
+ A strategic change spends proportionate effort so that the next likely change remains local and correct use remains simple.
52
48
 
53
- Strategic programming spends a little extra attention to preserve future locality.
49
+ Do not redesign everything in anticipation of the future. Do stop when the current patch clearly:
54
50
 
55
- Freeflow translation:
51
+ - spreads a likely-changing decision;
52
+ - adds caller protocol;
53
+ - exposes internal state;
54
+ - creates another required workaround;
55
+ - makes the next accepted change materially harder.
56
56
 
57
- - Do not redesign everything up front.
58
- - Do stop when the local patch clearly makes the next slice, review, or bug fix harder.
59
- - Return the structural evidence to [Workflow](../../workflow/SKILL.md) when a tactical patch is becoming structural work.
57
+ Strategic design is proportionate investment, not maximal architecture.
60
58
 
61
- ## Parnas: Information Hiding
59
+ ## Hide Likely-Changing Decisions
62
60
 
63
- Parnas's key design move: modules should hide design decisions likely to change.
61
+ Organize modules around decisions likely to change, not merely processing steps.
64
62
 
65
- Do not decompose only by processing steps:
63
+ Instead of exposing:
66
64
 
67
65
  ```text
68
- parse -> validate -> send -> log
66
+ parse -> validate -> retry -> send -> log -> clean up
69
67
  ```
70
68
 
71
- when the real likely-changing decision is:
69
+ look for the decision those steps implement:
72
70
 
73
71
  ```text
74
- notification delivery policy: provider choice, retry, fallback, telemetry, failure semantics
72
+ notification delivery policy
75
73
  ```
76
74
 
77
- A good module hides the unstable decision.
78
-
79
- For consequential systems, failure behavior is often the unstable decision. Hide the contract in the module before callers invent their own retries, fallbacks, state writes, escalation paths, or graceful-failure claims.
80
-
81
75
  Ask:
82
76
 
83
- - What decision would cause the most edits if it changed?
84
- - What can fail, who observes it, what state is written, and what must not happen?
85
- - Does the system fail closed, fail open, degrade, escalate, retry, or stop?
86
- - What recovery path and evidence prove graceful handling?
87
- - Which callers currently know that decision?
88
- - Can one module own it?
89
- - What interface would let callers stop knowing it?
77
+ - What decision would cause the most surrounding edits if it changed?
78
+ - Which callers currently know it?
79
+ - Who should own it?
80
+ - What outcome-level interface would let callers stop knowing it?
81
+ - Is the decision accepted or still user-owned?
90
82
 
91
- Examples:
83
+ Failure and recovery policy are often likely-changing decisions.
92
84
 
93
- - Billing grace period policy should not be spread across webhook handlers, email copy, UI guards, and tests.
94
- - Notification retry/fallback policy should not be duplicated in each route.
95
- - Permission semantics should not be separately encoded in frontend, backend, and test setup.
96
- - Cache invalidation rules should not require every caller to remember freshness knobs.
85
+ ## Preserve Conceptual Integrity
97
86
 
98
- ## Feathers: Seams And Enabling Points
87
+ A module should express one coherent model of its outcome, state, and failure behavior.
99
88
 
100
- A seam is where behavior can change without editing the surrounding work.
89
+ Pressure exists when:
101
90
 
102
- A seam needs an enabling point: the place where a different adapter, test double, probe, or behavior can be supplied.
91
+ - the same concept has different names or rules across callers;
92
+ - several modules partially own the same decision;
93
+ - one module exposes unrelated mental models;
94
+ - callers translate between incompatible representations;
95
+ - each feature adds another exception to the shared concept.
103
96
 
104
- Freeflow use:
97
+ Prefer one clear ownership model over several locally convenient but incompatible ones.
105
98
 
106
- - Use seams to make hard-to-test or hard-to-change behavior tractable.
107
- - Do not create seams merely because a pattern sounds clean.
108
- - Prefer seams that match real variation or observability needs.
99
+ Conceptual integrity does not mean one module or one abstraction. It means related behavior follows one coherent set of decisions.
109
100
 
110
- Questions:
101
+ ## Use Seams And Enabling Points For Real Leverage
111
102
 
112
- - What behavior needs to vary?
113
- - Where can that variation enter without editing callers?
114
- - What enabling point supplies the adapter or behavior?
115
- - Does the seam protect production code and tests, or only add indirection?
103
+ A seam allows behavior, dependencies, or observation to change without editing surrounding code.
116
104
 
117
- Good seam candidates:
105
+ An enabling point supplies the variation:
118
106
 
119
- - provider variation: email/SMS/payment/search/storage;
120
- - environment variation: prod/test/offline/fake implementations;
121
- - observability variation: probes, clocks, log sinks, metrics;
122
- - migration variation: old and new implementations behind one interface.
107
+ - adapter;
108
+ - provider;
109
+ - fake;
110
+ - clock;
111
+ - probe;
112
+ - policy;
113
+ - migration implementation.
123
114
 
124
- Weak seam candidates:
115
+ Good seams correspond to:
125
116
 
126
- - one implementation with no likely variation;
127
- - a seam created only to mock internals while the real interface stays awkward;
128
- - a factory/registry around every function;
129
- - an adapter whose interface still exposes provider-specific quirks.
117
+ - demonstrated provider or environment variation;
118
+ - known migration;
119
+ - dependency control required by tests;
120
+ - observation or fault injection;
121
+ - policy that changes independently from infrastructure.
130
122
 
131
- ## Ports And Adapters
123
+ Weak seams:
132
124
 
133
- Ports/adapters protects core behavior from infrastructure details.
125
+ - wrap one stable call;
126
+ - add factories without ownership;
127
+ - expose provider quirks through generic names;
128
+ - exist only to mock internals while the caller interface remains awkward.
134
129
 
135
- Freeflow wording:
130
+ ## Separate Policy From Infrastructure
136
131
 
137
- - The core owns policy.
138
- - The adapter owns provider mechanics.
139
- - The interface between them says what the core needs or provides.
132
+ When infrastructure details leak into product or domain policy, use a boundary where:
140
133
 
141
- Use this idea when infrastructure details are leaking into product logic.
134
+ ```text
135
+ policy requests outcome
136
+ -> adapter performs provider mechanics
137
+ ```
142
138
 
143
139
  Examples:
144
140
 
145
- - Stripe event parsing is adapter work; billing policy is core work.
146
- - Email provider retries are adapter work; user notification policy may be core work.
147
- - Database query syntax is adapter work; permission semantics are core work.
148
- - Browser event plumbing is adapter work; user-flow state is core work.
149
-
150
- Do not over-apply ports/adapters:
151
-
152
- - simple scripts may not need ports;
153
- - a single stable library call may not need an adapter;
154
- - wrapping an SDK without hiding policy or provider quirks is often shallow.
155
-
156
- ## Public Contract Cost
157
-
158
- Hyrum's Law applies beyond public HTTP APIs: every observable flag, path, state, ordering rule, filename, error, timing behavior, and fallback can become depended upon.
159
-
160
- Expose a fact only when the caller owns it or correct use requires it. Internal protocols may remain detailed and independently tested without becoming public seams.
161
-
162
- A useful split:
163
-
164
- - **Public:** caller-owned outcome, decisions, stable invariants, and observable failure semantics.
165
- - **Internal:** storage layout, provider mechanics, retries, cleanup, integrity publication, temporary states, and optimization machinery.
166
-
167
- Public flexibility has permanent coordination cost. One outcome-level operation is often deeper than a toolkit that lets callers reconstruct the module's lifecycle.
141
+ - billing policy should not depend on payment-provider error names;
142
+ - notification policy should not be repeated in each provider call;
143
+ - permission semantics should not depend on database representation;
144
+ - user-flow state should not depend on browser event plumbing.
168
145
 
169
- ## Maturity And Learning
146
+ Do not add ports and adapters around every stable library call. The boundary is useful only when it hides policy, variation, or mechanics callers should not own.
170
147
 
171
- Classify mechanisms before adding them:
148
+ ## Treat Observable Facts As Contracts
172
149
 
173
- - required trust and safety cannot be deferred merely to simplify the design;
174
- - efficiency, scale, and portability require accepted requirements or observed pressure.
150
+ Callers may depend on any observable:
175
151
 
176
- When the best interface cannot be known from source inspection, use a bounded learning slice. Name the question, competing designs, evidence, cost boundary, and discard-or-promote rule. Code can answer a design question without becoming the production design automatically.
152
+ - flag;
153
+ - path;
154
+ - state;
155
+ - error;
156
+ - timing rule;
157
+ - fallback;
158
+ - ordering behavior;
159
+ - filename;
160
+ - retry count.
177
161
 
178
- ## Refactoring Pressure
162
+ Expose a fact only when:
179
163
 
180
- Design pressure often appears as ordinary implementation pain:
164
+ - the caller owns the decision;
165
+ - correct use requires it;
166
+ - it is stable enough to support;
167
+ - its compatibility cost is understood.
181
168
 
182
- - shotgun surgery;
183
- - repeated review findings;
184
- - flaky tests around ordering;
185
- - many mocks for one behavior;
186
- - hard-to-explain correctness;
187
- - one bug fix causing another;
188
- - “just add this flag everywhere.”
169
+ Public flexibility has lasting coordination cost. Prefer one outcome-level operation over a toolkit that requires callers to reconstruct the lifecycle.
189
170
 
190
- Do not treat all pressure as a command to refactor.
171
+ ## Separate Required Capability From Speculation
191
172
 
192
- Classify it:
173
+ Classify proposed mechanisms as:
193
174
 
194
- - **Real design pressure:** complexity spread blocks safe progress.
195
- - **Local mess:** cleanup can happen within current scope.
196
- - **Deferred deepening:** record the candidate, finish current work.
197
- - **Owner decision:** deeper change affects product/API/security/compatibility.
175
+ - **Trust:** required to know the result is valid.
176
+ - **Safety:** prevents damage, leakage, or runaway behavior.
177
+ - **Efficiency:** saves time, requests, or money.
178
+ - **Scale:** supports concurrency or volume.
179
+ - **Portability:** supports additional environments or providers.
198
180
 
199
- ## Applying The Philosophy In Freeflow
181
+ Required trust and safety cannot be deferred merely to simplify the design.
200
182
 
201
- ### In discussion
183
+ Efficiency, scale, and portability require accepted requirements or observed pressure. Do not turn imagined future variation into present interface cost.
202
184
 
203
- Use design ideas to ask better questions, not to freeze architecture.
185
+ ## Name The Missing Boundary
204
186
 
205
- Good questions:
206
-
207
- - Which decision is most likely to change?
208
- - Who should know this rule?
209
- - What should callers stop coordinating?
210
- - What future variation is real, not imagined?
211
- - Which tests should survive a provider or implementation change?
212
-
213
- ### In specs
214
-
215
- Specs name behavior and boundaries. They should not lock in unproven module shapes.
216
-
217
- Use:
218
-
219
- ```text
220
- Tentative: notification delivery may need one policy-owning module if retries/fallbacks continue spreading.
221
- Open: whether provider variation is real now or deferred.
222
- ```
223
-
224
- not:
187
+ Use supported evidence to state:
225
188
 
226
189
  ```text
227
- Requirement: implement NotificationDeliveryPortFactoryStrategy.
190
+ Outcome:
191
+ Coordination currently spread across:
192
+ Likely-changing decision:
193
+ Current owners:
194
+ Proposed owner:
195
+ What callers would stop knowing:
196
+ Failure unit:
197
+ Evidence still missing:
228
198
  ```
229
199
 
230
- ### In plans
231
-
232
- Use [Write Plan](../../write-plan/SKILL.md) only when the ordered strategy can be stated without guessing. When later direction remains provisional, keep it in [Track Work](../../track-work/SKILL.md) or return the evidence to [Workflow](../../workflow/SKILL.md) rather than freezing it as a Plan.
233
-
234
- For consequential systems, make failure behavior explicit before implementation choices harden. Do not leave it as an implementer guess after planning only the happy path.
235
-
236
- A good slice can be verified through the intended interface. If the slice requires broad caller choreography, revise the slice.
237
-
238
- ### In review
239
-
240
- Review design depth by asking whether the diff reduces or increases caller knowledge.
241
-
242
- A diff can pass tests and still fail design review if it scatters policy or creates a shallow interface.
243
-
244
- ### In diagnosis
245
-
246
- Repeated failures may indicate that the system is missing a module, seam, or source-truth decision.
200
+ If the decision cannot yet be named, define one bounded learning question. Do not create a generic abstraction as a substitute for understanding.
247
201
 
248
- Do not keep fixing symptoms when every fix reveals another coordination problem.
202
+ Stop once the missing decision or boundary is named—or evidence shows no worthwhile boundary change is supported.
@@ -0,0 +1,136 @@
1
+ # State And Failure Boundaries
2
+
3
+ Read this when correctness materially depends on canonical state, partial effects, atomic visibility, concurrency, cancellation, retries, recovery, reconciliation, or evidence of the final outcome.
4
+
5
+ Do not apply this reference to a simple local value change whose state owner and failure behavior are already sound.
6
+
7
+ ## Name Canonical State
8
+
9
+ Identify:
10
+
11
+ - canonical source of truth;
12
+ - who may create, replace, or invalidate it;
13
+ - visible states and invariants;
14
+ - commit or visibility point;
15
+ - diagnostic versus authoritative records;
16
+ - what callers may safely cache or infer.
17
+
18
+ Do not let several modules each behave as the source of truth.
19
+
20
+ A log, cache, temporary file, UI projection, or recovery marker is not canonical merely because it is observable.
21
+
22
+ ## Define State Transitions
23
+
24
+ For every material transition, establish:
25
+
26
+ ```text
27
+ precondition
28
+ -> accepted operation
29
+ -> commit or visibility point
30
+ -> resulting canonical state
31
+ -> evidence
32
+ ```
33
+
34
+ Name forbidden transitions and partial states.
35
+
36
+ Prefer one owner for transition policy. Callers should not reproduce state-machine rules independently.
37
+
38
+ ## Bound Partial Effects
39
+
40
+ When an operation affects several resources or can fail midway, establish:
41
+
42
+ - which effects may occur before commitment;
43
+ - which effects are forbidden before commitment;
44
+ - what must be rolled back, reconciled, or retained;
45
+ - what prior accepted state must survive;
46
+ - how partial outcomes are detected;
47
+ - what result is safe to expose.
48
+
49
+ Atomicity may come from transactions, staging, replacement, versioning, or explicit reconciliation. Do not claim atomic behavior from intention alone.
50
+
51
+ ## Separate Retry, Resume, And Replay
52
+
53
+ These are different capabilities:
54
+
55
+ - **Retry:** attempt the same operation again.
56
+ - **Resume:** continue incomplete work from preserved state.
57
+ - **Replay:** apply an event or request again.
58
+ - **Idempotency:** repeated application has one supported effect.
59
+ - **Recovery:** restore a safe supported state.
60
+ - **Reconciliation:** compare and resolve divergent state.
61
+
62
+ Supporting one does not imply the others.
63
+
64
+ Expose them only when required by accepted behavior or observed failure.
65
+
66
+ ## Design Concurrency Deliberately
67
+
68
+ When operations can overlap, identify:
69
+
70
+ - shared state;
71
+ - ordering and visibility;
72
+ - lost-update or duplicate-effect risk;
73
+ - serialization or conflict rule;
74
+ - cancellation behavior;
75
+ - stale-read policy;
76
+ - observer capable of proving the required outcome.
77
+
78
+ Do not add locks, queues, retries, or optimistic versions without naming the invariant they protect.
79
+
80
+ ## Define Failure And Recovery
81
+
82
+ For the failure unit, state:
83
+
84
+ - who observes failure;
85
+ - canonical state after failure;
86
+ - diagnostic evidence;
87
+ - forbidden partial effects;
88
+ - fail-open, fail-closed, degrade, stop, retry, or escalation behavior;
89
+ - safe restart or recovery operation;
90
+ - evidence proving recovery.
91
+
92
+ A graceful error response does not prove graceful state handling.
93
+
94
+ ## Keep Recovery Out Of Ordinary Callers
95
+
96
+ Callers should normally request an outcome and receive supported success or failure.
97
+
98
+ Do not require every caller to know:
99
+
100
+ - cleanup order;
101
+ - retry schedule;
102
+ - temporary paths;
103
+ - partial-state markers;
104
+ - provider error translation;
105
+ - reconciliation commands.
106
+
107
+ Publish diagnostics without exposing recovery choreography unless callers genuinely own recovery.
108
+
109
+ ## Test State And Failure Through Observable Invariants
110
+
111
+ Tests should verify:
112
+
113
+ - accepted final state;
114
+ - preserved prior state;
115
+ - forbidden writes;
116
+ - composed failures;
117
+ - retry or replay behavior when required;
118
+ - cancellation and recovery;
119
+ - evidence at the real observing boundary.
120
+
121
+ A passing happy-path test does not prove partial-failure safety.
122
+
123
+ ## Return
124
+
125
+ Return:
126
+
127
+ - canonical state and owner;
128
+ - material invariants;
129
+ - transition and visibility boundary;
130
+ - failure unit;
131
+ - forbidden partial outcomes;
132
+ - retry, resume, replay, and recovery capabilities actually required;
133
+ - evidence and remaining uncertainty;
134
+ - narrowest supported route.
135
+
136
+ Stop when state and failure ownership are sufficient for the current design decision. Do not design every theoretical failure mode.