@hassangameryt/freeflow 0.8.0 → 0.9.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 (290) hide show
  1. package/.agents/plugins/marketplace.json +2 -2
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +2 -2
  4. package/.codex-plugin/plugin.json +3 -3
  5. package/.cursor-plugin/plugin.json +1 -1
  6. package/README.md +96 -149
  7. package/capabilities/cognitive-routing/SKILL.md +21 -129
  8. package/capabilities/cognitive-routing/references/coordinator.md +163 -0
  9. package/capabilities/cognitive-routing/references/worker.md +38 -0
  10. package/capabilities/compaction/SKILL.md +3 -3
  11. package/capabilities/compaction/references/summary-format.md +26 -15
  12. package/capabilities/messaging/SKILL.md +49 -0
  13. package/capabilities/task-memory/SKILL.md +87 -0
  14. package/command-surface.json +6 -54
  15. package/gemini-extension.json +1 -1
  16. package/hooks/claude/hooks.json +13 -3
  17. package/hooks/codex/hooks.json +2 -1
  18. package/hooks/shared/runtime-context.mjs +69 -77
  19. package/package.json +25 -8
  20. package/pi-extension/dist/ask-user/ask.js +108 -0
  21. package/pi-extension/dist/ask-user/form.js +250 -0
  22. package/pi-extension/dist/ask-user/questions.js +66 -0
  23. package/pi-extension/dist/ask-user/tool.js +124 -0
  24. package/pi-extension/dist/cognitive-routing/assembler.js +35 -11
  25. package/pi-extension/dist/cognitive-routing/bootstrap.js +90 -0
  26. package/pi-extension/dist/cognitive-routing/config.js +3 -4
  27. package/pi-extension/dist/cognitive-routing/event-store.js +4 -1
  28. package/pi-extension/dist/cognitive-routing/gate.js +20 -5
  29. package/pi-extension/dist/cognitive-routing/handlers.js +15 -13
  30. package/pi-extension/dist/cognitive-routing/model-control.js +17 -8
  31. package/pi-extension/dist/cognitive-routing/projection.js +23 -6
  32. package/pi-extension/dist/cognitive-routing/provenance.js +3 -1
  33. package/pi-extension/dist/cognitive-routing/render.js +15 -15
  34. package/pi-extension/dist/cognitive-routing/runtime.js +4 -2
  35. package/pi-extension/dist/cognitive-routing/schemas.js +4 -4
  36. package/pi-extension/dist/cognitive-routing/session.js +3 -1
  37. package/pi-extension/dist/cognitive-routing/sources.js +29 -4
  38. package/pi-extension/dist/cognitive-routing/state.js +18 -8
  39. package/pi-extension/dist/cognitive-routing/status.js +4 -3
  40. package/pi-extension/dist/cognitive-routing/tools.js +29 -15
  41. package/pi-extension/dist/cognitive-routing/types.js +10 -1
  42. package/pi-extension/dist/compaction/carry.js +36 -22
  43. package/pi-extension/dist/compaction/config.js +4 -2
  44. package/pi-extension/dist/compaction/controller.js +52 -29
  45. package/pi-extension/dist/compaction/harness.js +19 -3
  46. package/pi-extension/dist/compaction/results.js +14 -13
  47. package/pi-extension/dist/compaction/tool.js +6 -6
  48. package/pi-extension/dist/host/catalog.js +20 -35
  49. package/pi-extension/dist/host/config-validation.js +233 -0
  50. package/pi-extension/dist/host/config.js +78 -91
  51. package/pi-extension/dist/host/inbound.js +142 -0
  52. package/pi-extension/dist/host/projection-tags.js +1 -1
  53. package/pi-extension/dist/host/prompts.js +24 -13
  54. package/pi-extension/dist/host/read-only-session.js +6 -1
  55. package/pi-extension/dist/host/request-history.js +7 -3
  56. package/pi-extension/dist/host/rows.js +25 -0
  57. package/pi-extension/dist/host/runtime-state.js +17 -2
  58. package/pi-extension/dist/host/section-keeper.js +85 -0
  59. package/pi-extension/dist/host/settings/freeflow-command.js +846 -93
  60. package/pi-extension/dist/host/settings/settings-view.js +27 -8
  61. package/pi-extension/dist/host/status.js +19 -5
  62. package/pi-extension/dist/index.js +638 -72
  63. package/pi-extension/dist/messaging/config.js +27 -0
  64. package/pi-extension/dist/messaging/messaging.js +398 -0
  65. package/pi-extension/dist/messaging/registry.js +57 -0
  66. package/pi-extension/dist/messaging/render.js +90 -0
  67. package/pi-extension/dist/messaging/tools.js +109 -0
  68. package/pi-extension/dist/messaging/transport.js +101 -0
  69. package/pi-extension/dist/provider-support/cache/keepalive.js +16 -4
  70. package/pi-extension/dist/task-memory/config.js +49 -0
  71. package/pi-extension/dist/task-memory/registry.js +119 -0
  72. package/pi-extension/dist/task-memory/render.js +107 -0
  73. package/pi-extension/dist/task-memory/runtime.js +994 -0
  74. package/pi-extension/dist/task-memory/tool.js +233 -0
  75. package/pi-extension/dist/tool-execution/apply-patch/tool.js +1 -1
  76. package/pi-extension/dist/tool-execution/background.js +220 -28
  77. package/pi-extension/dist/tool-execution/config.js +14 -3
  78. package/pi-extension/dist/tool-execution/file-tracking.js +24 -4
  79. package/pi-extension/dist/tool-execution/guidance-notices.js +124 -0
  80. package/pi-extension/dist/tool-execution/skill-reads.js +143 -0
  81. package/pi-extension/dist/tool-execution/tools.js +2 -2
  82. package/runtime/prompts/cognitive-routing.md +4 -4
  83. package/runtime/prompts/core.md +24 -14
  84. package/runtime/prompts/interaction-contract.md +7 -4
  85. package/runtime/prompts/tool-execution.md +3 -16
  86. package/runtime/prompts/working-method.md +16 -99
  87. package/skills/deliver-work/SKILL.md +76 -0
  88. package/skills/deliver-work/references/branch-closeout.md +134 -0
  89. package/skills/deliver-work/references/commit.md +83 -0
  90. package/skills/deliver-work/references/launch.md +94 -0
  91. package/skills/deliver-work/references/release.md +85 -0
  92. package/skills/deliver-work/scripts/commit-state.mjs +139 -0
  93. package/skills/deliver-work/scripts/delivery-state.mjs +107 -0
  94. package/skills/deliver-work/scripts/lib/git-state.mjs +178 -0
  95. package/skills/deliver-work/scripts/push-route.mjs +122 -0
  96. package/skills/deliver-work/scripts/release-preflight.mjs +177 -0
  97. package/skills/discuss-work/SKILL.md +148 -0
  98. package/skills/{discuss → discuss-work}/references/discussion-continuity.md +10 -27
  99. package/skills/discuss-work/references/learning-action.md +36 -0
  100. package/skills/discuss-work/scripts/choices.mjs +101 -0
  101. package/skills/discuss-work/scripts/lib/choices.mjs +159 -0
  102. package/skills/evaluate-behavior/SKILL.md +107 -0
  103. package/skills/evaluate-behavior/references/authoring.md +381 -0
  104. package/skills/evaluate-behavior/references/coding-tasks.md +145 -0
  105. package/skills/evaluate-behavior/references/conversations-pipelines-judges.md +177 -0
  106. package/skills/evaluate-behavior/references/design-and-measurement.md +273 -0
  107. package/skills/evaluate-behavior/references/running-and-evidence.md +245 -0
  108. package/skills/evaluate-behavior/scripts/claude-guard.mjs +76 -0
  109. package/skills/evaluate-behavior/scripts/guard-rules.mjs +309 -0
  110. package/skills/evaluate-behavior/scripts/lib/agreement.mjs +90 -0
  111. package/skills/evaluate-behavior/scripts/lib/arms.mjs +55 -0
  112. package/skills/evaluate-behavior/scripts/lib/budget.mjs +87 -0
  113. package/skills/evaluate-behavior/scripts/lib/build-source.mjs +287 -0
  114. package/skills/evaluate-behavior/scripts/lib/clear.mjs +74 -0
  115. package/skills/evaluate-behavior/scripts/lib/container.mjs +395 -0
  116. package/skills/evaluate-behavior/scripts/lib/decision.mjs +418 -0
  117. package/skills/evaluate-behavior/scripts/lib/definitions.mjs +1072 -0
  118. package/skills/evaluate-behavior/scripts/lib/freeflow.mjs +103 -0
  119. package/skills/evaluate-behavior/scripts/lib/grade-command.mjs +591 -0
  120. package/skills/evaluate-behavior/scripts/lib/grade-comparison.mjs +90 -0
  121. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-interaction.mjs +19 -18
  122. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-support.mjs +32 -5
  123. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-workspace.mjs +28 -12
  124. package/skills/evaluate-behavior/scripts/lib/grade.mjs +101 -0
  125. package/skills/evaluate-behavior/scripts/lib/hooks.mjs +98 -0
  126. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/confinement.mjs +196 -0
  127. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/constraints.mjs +111 -0
  128. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/index.mjs +48 -0
  129. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/isolation.mjs +74 -0
  130. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/launch.mjs +123 -0
  131. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/model-call.mjs +73 -0
  132. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/recorder.mjs +178 -0
  133. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/session.mjs +494 -0
  134. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/skills.mjs +81 -0
  135. package/skills/evaluate-behavior/scripts/lib/hosts/index.mjs +31 -0
  136. package/skills/evaluate-behavior/scripts/lib/hosts/names.mjs +3 -0
  137. package/skills/evaluate-behavior/scripts/lib/hosts/pi/confinement.mjs +173 -0
  138. package/skills/evaluate-behavior/scripts/lib/hosts/pi/host.mjs +148 -0
  139. package/skills/evaluate-behavior/scripts/lib/hosts/pi/index.mjs +70 -0
  140. package/skills/evaluate-behavior/scripts/lib/hosts/pi/isolation.mjs +81 -0
  141. package/skills/evaluate-behavior/scripts/lib/hosts/pi/model-call.mjs +79 -0
  142. package/skills/evaluate-behavior/scripts/lib/hosts/pi/process.mjs +241 -0
  143. package/skills/{evaluate-skill/scripts/lib → evaluate-behavior/scripts/lib/hosts/pi}/rpc.mjs +144 -26
  144. package/skills/evaluate-behavior/scripts/lib/identity.mjs +82 -0
  145. package/skills/evaluate-behavior/scripts/lib/judge.mjs +688 -0
  146. package/skills/evaluate-behavior/scripts/lib/metrics.mjs +332 -0
  147. package/skills/evaluate-behavior/scripts/lib/model-call.mjs +17 -0
  148. package/skills/evaluate-behavior/scripts/lib/participants.mjs +616 -0
  149. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/process.mjs +22 -0
  150. package/skills/evaluate-behavior/scripts/lib/queue.mjs +54 -0
  151. package/skills/evaluate-behavior/scripts/lib/reference.mjs +343 -0
  152. package/skills/evaluate-behavior/scripts/lib/reuse.mjs +277 -0
  153. package/skills/evaluate-behavior/scripts/lib/review.mjs +933 -0
  154. package/skills/evaluate-behavior/scripts/lib/runner.mjs +732 -0
  155. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/sandbox.mjs +119 -14
  156. package/skills/evaluate-behavior/scripts/lib/scan-shell.mjs +457 -0
  157. package/skills/evaluate-behavior/scripts/lib/scan.mjs +479 -0
  158. package/skills/evaluate-behavior/scripts/lib/seal.mjs +91 -0
  159. package/skills/evaluate-behavior/scripts/lib/shell.mjs +560 -0
  160. package/skills/evaluate-behavior/scripts/lib/source-override.mjs +64 -0
  161. package/skills/evaluate-behavior/scripts/lib/subject-file.mjs +88 -0
  162. package/skills/{evaluate-skill/scripts/lib/pi.mjs → evaluate-behavior/scripts/lib/subject.mjs} +235 -265
  163. package/skills/evaluate-behavior/scripts/lib/task-copy.mjs +124 -0
  164. package/skills/evaluate-behavior/scripts/lib/trials.mjs +524 -0
  165. package/skills/evaluate-behavior/scripts/lib/validity.mjs +68 -0
  166. package/skills/evaluate-behavior/scripts/lib/view-html.mjs +454 -0
  167. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/view.mjs +159 -18
  168. package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-command-tool.mjs +21 -6
  169. package/skills/evaluate-behavior/scripts/pi-container-route.mjs +23 -0
  170. package/skills/evaluate-behavior/scripts/pi-guard.mjs +77 -0
  171. package/skills/evaluate-behavior/scripts/pi-login-refresh.mjs +31 -0
  172. package/skills/evaluate-behavior/scripts/skill-eval.mjs +586 -0
  173. package/skills/execute-work/SKILL.md +96 -104
  174. package/skills/execute-work/references/code-practices.md +27 -51
  175. package/skills/execute-work/references/design.md +271 -0
  176. package/skills/execute-work/references/diagnose.md +117 -0
  177. package/skills/execute-work/references/migration.md +108 -0
  178. package/skills/execute-work/references/simplify.md +65 -0
  179. package/skills/execute-work/scripts/self-review.mjs +422 -0
  180. package/skills/execute-work/scripts/touch-map.mjs +290 -0
  181. package/skills/review-work/SKILL.md +89 -65
  182. package/skills/review-work/references/adjudication.md +94 -0
  183. package/skills/review-work/references/artifact.md +198 -0
  184. package/skills/review-work/references/evals-and-judges.md +66 -0
  185. package/skills/review-work/references/work.md +177 -0
  186. package/skills/review-work/scripts/check-brief.mjs +128 -0
  187. package/skills/review-work/scripts/review-packet.mjs +233 -0
  188. package/skills/setup-freeflow/SKILL.md +68 -17
  189. package/skills/track-work/SKILL.md +52 -20
  190. package/skills/track-work/references/handoff.md +190 -0
  191. package/skills/track-work/references/projects.md +51 -0
  192. package/skills/track-work/references/working-record-format.md +36 -18
  193. package/skills/track-work/scripts/lib/document.mjs +17 -13
  194. package/skills/track-work/scripts/lib/format.mjs +2 -0
  195. package/skills/track-work/scripts/lib/recover.mjs +254 -0
  196. package/skills/track-work/scripts/lib/registry.mjs +656 -0
  197. package/skills/track-work/scripts/lib/search.mjs +40 -0
  198. package/skills/track-work/scripts/lib/store.mjs +46 -15
  199. package/skills/track-work/scripts/lib/views.mjs +50 -1
  200. package/skills/track-work/scripts/working-record.mjs +232 -13
  201. package/skills/verify-work/SKILL.md +45 -37
  202. package/skills/verify-work/references/feature-map.md +120 -0
  203. package/skills/verify-work/references/runtime-evidence.md +203 -0
  204. package/skills/verify-work/references/test-design.md +25 -6
  205. package/skills/verify-work/scripts/test-changes.mjs +246 -0
  206. package/skills/write-docs/SKILL.md +113 -25
  207. package/skills/write-docs/references/documentation-shapes.md +68 -3
  208. package/skills/write-docs/references/spec-and-plan-shapes.md +308 -0
  209. package/skills/write-docs/scripts/artifact-check.mjs +148 -0
  210. package/skills/write-docs/scripts/docs-check.mjs +96 -6
  211. package/skills/write-docs/scripts/plan-lint.mjs +123 -0
  212. package/skills/write-skill/SKILL.md +92 -52
  213. package/skills/write-skill/references/activation-and-wording.md +143 -0
  214. package/skills/write-skill/references/placement-and-dependencies.md +154 -0
  215. package/skills/write-skill/scripts/lib/compare.mjs +701 -0
  216. package/skills/write-skill/scripts/lib/skill-author.mjs +197 -3
  217. package/skills/write-skill/scripts/skill-author.mjs +51 -8
  218. package/capabilities/cognitive-routing/references/both-mode.md +0 -36
  219. package/capabilities/cognitive-routing/references/executor-mode.md +0 -48
  220. package/capabilities/cognitive-routing/references/helper-mode.md +0 -47
  221. package/plugin.json +0 -33
  222. package/skills/action-selection/SKILL.md +0 -92
  223. package/skills/action-selection/references/trajectory-stalls.md +0 -73
  224. package/skills/bypass/SKILL.md +0 -153
  225. package/skills/commit-work/SKILL.md +0 -93
  226. package/skills/commit-work/references/git-state-edges.md +0 -94
  227. package/skills/commit-work/references/simple-push.md +0 -94
  228. package/skills/commit-work/references/staging-decisions.md +0 -106
  229. package/skills/decision-gate/SKILL.md +0 -87
  230. package/skills/design-for-depth/SKILL.md +0 -108
  231. package/skills/design-for-depth/references/design-pressure-signals.md +0 -84
  232. package/skills/design-for-depth/references/implementation-decisions.md +0 -76
  233. package/skills/design-for-depth/references/interface-design-loop.md +0 -105
  234. package/skills/design-for-depth/references/module-and-dependency-design.md +0 -117
  235. package/skills/design-for-depth/references/state-and-failure-boundaries.md +0 -125
  236. package/skills/diagnose-failure/SKILL.md +0 -140
  237. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +0 -50
  238. package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +0 -51
  239. package/skills/discuss/SKILL.md +0 -140
  240. package/skills/evaluate-skill/SKILL.md +0 -188
  241. package/skills/evaluate-skill/references/evaluation-definition-schema.md +0 -415
  242. package/skills/evaluate-skill/references/evaluation-design.md +0 -112
  243. package/skills/evaluate-skill/references/execution-and-evidence.md +0 -111
  244. package/skills/evaluate-skill/references/review-and-revision.md +0 -94
  245. package/skills/evaluate-skill/scripts/lib/definitions.mjs +0 -448
  246. package/skills/evaluate-skill/scripts/lib/grade-comparison.mjs +0 -60
  247. package/skills/evaluate-skill/scripts/lib/grade.mjs +0 -64
  248. package/skills/evaluate-skill/scripts/lib/review.mjs +0 -196
  249. package/skills/evaluate-skill/scripts/lib/runner.mjs +0 -405
  250. package/skills/evaluate-skill/scripts/lib/trials.mjs +0 -103
  251. package/skills/evaluate-skill/scripts/pi-guard.mjs +0 -181
  252. package/skills/evaluate-skill/scripts/skill-eval.mjs +0 -182
  253. package/skills/execute-work/references/execute-work-edges.md +0 -78
  254. package/skills/finish-branch/SKILL.md +0 -117
  255. package/skills/finish-branch/references/integration-options.md +0 -80
  256. package/skills/handoff/SKILL.md +0 -82
  257. package/skills/handoff/references/handoff-templates.md +0 -150
  258. package/skills/launch-work/SKILL.md +0 -116
  259. package/skills/launch-work/references/launch-readiness.md +0 -85
  260. package/skills/migration-work/SKILL.md +0 -115
  261. package/skills/migration-work/references/migration-lifecycle.md +0 -82
  262. package/skills/release-work/SKILL.md +0 -118
  263. package/skills/release-work/references/release-evidence.md +0 -78
  264. package/skills/review-artifact/SKILL.md +0 -143
  265. package/skills/review-artifact/references/adjudicate-artifact-review.md +0 -101
  266. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +0 -159
  267. package/skills/review-work/references/adjudicate-work-review.md +0 -97
  268. package/skills/review-work/references/independent-work-reviewer-contract.md +0 -139
  269. package/skills/review-work/references/security-risk-lens.md +0 -67
  270. package/skills/setup-freeflow/references/activation-contract.md +0 -103
  271. package/skills/setup-freeflow/references/host-setup.md +0 -67
  272. package/skills/simplify-code/SKILL.md +0 -85
  273. package/skills/simplify-code/references/simplification-patterns.md +0 -70
  274. package/skills/verify-work/references/browser-runtime-evidence.md +0 -51
  275. package/skills/verify-work/references/integration-evidence.md +0 -49
  276. package/skills/verify-work/references/performance-evidence.md +0 -59
  277. package/skills/workflow/SKILL.md +0 -171
  278. package/skills/workflow/references/domain-skill-composition.md +0 -45
  279. package/skills/write-plan/SKILL.md +0 -92
  280. package/skills/write-plan/references/plan-shapes.md +0 -156
  281. package/skills/write-skill/references/activation-boundaries.md +0 -106
  282. package/skills/write-skill/references/agent-first-instructions.md +0 -133
  283. package/skills/write-skill/references/progressive-disclosure.md +0 -129
  284. package/skills/write-skill/references/skill-dependency-graphs.md +0 -192
  285. package/skills/write-spec/SKILL.md +0 -85
  286. package/skills/write-spec/references/artifact-standards.md +0 -86
  287. package/skills/write-spec/references/decision-records.md +0 -80
  288. package/skills/write-spec/references/spec-shapes.md +0 -143
  289. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/evidence.mjs +0 -0
  290. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-observer.mjs +0 -0
@@ -0,0 +1,271 @@
1
+ # Design
2
+
3
+ Read this when a design choice could make later work wrong or harder, at the section the situation names: building on a representation, identity, ownership or algorithm choice that dependent work would redo if wrong, or writing one into a Spec, recommendation or delegation contract (Settle The Choices); a new or changed interface between parts, or choosing which part owns a decision (Interfaces); module cycles, layering, dependency direction, or extracting shared code (Modules And Dependencies); the same change keeps touching many places, or each fix adds another flag, state or caller rule (Pressure Signals); state that must survive a failure: partial effects, retries, concurrent writers, recovery (State And Failure).
4
+
5
+ This reference is judgment, with four Rules of its own below. It is a lens under the current activity, not a mandatory phase, an architecture owner, or permission to refactor. Read the section you need; the first three sections apply to all of them. Do not turn its lists into obligations unrelated to the accepted result.
6
+
7
+ Hide coherent, likely-changing decisions behind small, stable, outcome-level interfaces, so callers need less knowledge and coordination for the same accepted outcome. A module is anything with an interface and an implementation. Its interface includes every fact a caller needs for correct use: operations, decisions, inputs, state, ordering, effects, errors, dependencies, timing, and recovery. A module is **deep** when it provides much useful, coherent behavior per unit of caller knowledge; depth is not fewer methods or more responsibilities, and a god module hiding unrelated decisions is not deep.
8
+
9
+ ## Rules
10
+
11
+ - A design recommendation is not implementation authority, and this lens never enlarges a task by itself.
12
+ - Never remove required correctness, trust, or safety to make a design smaller, and never turn hypothetical lifecycle completeness into a production requirement.
13
+ - Never design around an invented product or failure policy. When a boundary would settle a user-owned choice, as [Discuss Work](../../discuss-work/SKILL.md) defines it, take its concrete consequences and supported alternatives there.
14
+ - Do not invent APIs, files, or stronger guarantees to make a design look complete; name the missing observation or choice instead.
15
+
16
+ ## Start With The Required Outcome
17
+
18
+ Goal: know whether the change touches a boundary worth designing, before designing anything.
19
+
20
+ Understand enough to state the caller's complete outcome, source-backed behavior and non-goals, the decisions the caller genuinely owns, accepted constraints, the current interface, dependencies, canonical state, and the relevant success and failure boundary. Do not begin from existing flags, storage paths, classes, or temporary states; they may be symptoms of the current design. Do not survey the whole system or settle future variations without a present question. Ask:
21
+
22
+ 1. What outcome is changing?
23
+ 2. What must callers currently know or coordinate?
24
+ 3. Does the change spread policy, state, dependency choices, or lifecycle knowledge?
25
+ 4. Would the current boundary make correct use or the next likely change materially harder?
26
+
27
+ For a local, source-backed, reversible change that leaves these boundaries sound, apply the lens silently and continue: generate no alternatives and add no abstraction because another shape is imaginable. A large mechanical change may need no design; a one-line change may need it when it changes permissions, public behavior, canonical state, or consequential failure semantics.
28
+
29
+ Once a boundary is supported, do not reopen it because this lens is still in context. Re-enter when evidence shows growing caller coordination, scattered policy, exposed internal states, fragile test choreography, unclear dependency or failure ownership, or an invalidated design assumption. Ordinary bugs, duplication, test awkwardness, finding count, and preference do not establish structural pressure. When failures repeat without a supported cause, [diagnose](diagnose.md) first; this lens consumes a structural finding rather than inventing one.
30
+
31
+ ## Bound Success And Failure Proportionately
32
+
33
+ Goal: the failure behavior that matters is owned, and nothing more is built.
34
+
35
+ Before choosing classes, services, packages, flags, or states, name the caller and complete accepted outcome; caller-owned decisions and observable success and failure; the likely-changing coordination the module could hide; and the **failure unit**: what must succeed, fail, and recover as one coherent boundary, including whether partial reuse is required or merely an optimization. Where effects or partial state are consequential, establish the failure contract (observer, canonical and diagnostic state, forbidden outcomes, stop, degrade, fail or retry behavior, and supported recovery) with [State And Failure](#state-and-failure). Include cancellation, concurrency, or reconciliation only where required behavior or observed reachability makes them material.
36
+
37
+ Classify each proposed mechanism by what it is for: **trust** (knowing the result is valid), **safety** (preventing damage, leakage, or runaway behavior), **efficiency**, **scale**, or **portability**. Trust and safety cannot be deferred to simplify a design; efficiency, scale, and portability need an accepted requirement or observed pressure before they shape it. A module owning a failure unit does not automatically need durable replay, rollback, universal provenance, or every recovery mechanism.
38
+
39
+ ## Settle The Choices
40
+
41
+ Goal: the choices that could change correctness, complexity or failure behavior, or force dependent work to be redone, are settled before that work starts; ordinary mechanics stay free.
42
+
43
+ Name the actual question, not a generic demand for more design. Deciding which occurrence identifies a source matters more than choosing a map or an array; deciding what survives a failed transfer matters more than choosing a retry helper. For each consequential unknown, take one route:
44
+
45
+ - **Evidence supports a mechanism:** select it and say why it fits.
46
+ - **An environmental fact is missing:** find the observation that distinguishes the alternatives before dependent work.
47
+ - **A user-owned choice is unsettled:** take it to Discuss Work.
48
+ - **Only ordinary mechanics remain:** leave them to implementation.
49
+
50
+ Make explicit only what the question needs:
51
+
52
+ - **Representation and identity:** domain objects and their independent lifetimes; what counts as the same occurrence; what must stay distinct.
53
+ - **Algorithm and cost:** the essential steps; collection keys and relationships; update and invalidation rules; work repeated as input grows. Naming a data structure without its keys, meaning, and maintenance rules is not useful direction.
54
+ - **Ownership, effects and modules:** the sections below.
55
+
56
+ When you pass a decision on to another implementer or your later context, give the decision, why it fits, the invariant it protects, the plausible wrong approach and the observation that tells them apart, and which parts are required versus local freedom. Do not prescribe every loop or helper, or reproduce the whole program in prose. Reuse design decisions already supplied the same way; a path to a design is not its content.
57
+
58
+ Weak and useful direction, for example:
59
+
60
+ - Weak: "Use a Map and avoid repeated scans." Useful: "Keep native occurrence IDs as source identity. Equal bodies may identify several candidates; do not merge their occurrences. Let the source owner maintain the result-to-exchange relationship, and rebuild affected indexes after ancestry replacement. Check repeated equal bodies, late attribution, and a branch change; measure the repeated preparation path rather than only an isolated lookup. Helper layout is local. Reconsider the index if the source does not provide the assumed stable identity."
61
+ - Weak: "Make persistence idempotent and robust." Useful: "The append owner distinguishes observed acknowledgment from an uncertain attempt; an equal entry in memory does not resolve an earlier failure. Validate before mutation; publish accepted state only at the supported acknowledgment boundary. Test append advancing memory then failing, followed by the identical operation: uncertainty must remain until supported reconciliation. Also test an acknowledged duplicate, so not every retry is rejected. Do not infer filesystem durability from readback."
62
+
63
+ When an unfamiliar boundary could invalidate substantial later work, build the first coherent path that can disagree with the design, often across several files and a failure case, before expanding dependent work; a skeleton, happy-path result, or green summary alone may not exercise the decision. Compare the actual ownership, identity, ordering, and failure behavior with the decision, not its suggested filenames or helpers. A precise sketch can be wrong: keep accepted behavior, stop dependent effects when the mechanism is invalidated, and settle the affected choice before continuing. Supported local corrections need no design restart.
64
+
65
+ ## Interfaces
66
+
67
+ Goal: callers request outcomes; the module owns the protocol, with the smallest honest contract.
68
+
69
+ List only the facts callers must know that could affect the boundary: operations and inputs, caller-owned decisions, ordering and lifecycle states, configuration and provider details, dependencies, errors and failure semantics, compatibility and migration, and recovery, cost and performance expectations. For each, and before exposing any flag, path, state, ordering rule, retry, provider detail, or recovery step, ask whether the caller genuinely owns it, whether the module could, whether it is stable enough to become a supported contract with an understood compatibility cost, and whether changing it would force surrounding edits.
70
+
71
+ Keep public: caller-owned outcomes and decisions, necessary inputs and stable invariants, observable success and failure, and information required for correct recovery. Keep internal unless callers genuinely control it: sequencing, storage layout, dependency construction, provider mechanics, retries, cleanup, temporary states, caches, optimization machinery, and diagnostic details. Every observable fact is a contract callers may come to depend on.
72
+
73
+ A **seam** lets behavior, a dependency, or an observer change without coordinated surrounding edits; the adapter, clock, provider, or probe that plugs into it is what varies. Add one for demonstrated variation, a known migration, a required observer, or a dependency needing control, not for imagined flexibility.
74
+
75
+ When materially different ownership choices remain viable, design two or three interfaces that change seam placement, not only terminology. For each show ordinary caller usage, caller-owned decisions, the hidden internal protocol, the failure unit and observable behavior, the dependency and adapter strategy, the evidence needed, and the material cost. Compare only on criteria that could change the choice: behavior per interface fact, locality of likely change, cohesion and ownership clarity, correct-use ergonomics, misuse and hidden-decision risk, dependency direction, failure honesty and recovery, contract stability, test surface, reversibility, maturity fit, and implementation and evidence cost. Do not manufacture alternatives for a local, reversible, source-backed choice.
76
+
77
+ Prefer the boundary that removes concepts and coordination over one that centralizes the same protocol behind new terminology or another helper. Do not centralize unrelated responsibilities to reduce interface count, or scatter an old protocol into callers while claiming an abstraction was removed.
78
+
79
+ The intended interface should normally be the behavior and test surface. Question the design when callers or tests must bypass it, coordinate private lifecycle steps, replace many internals, or know dependency construction the module should own. An internal test inspecting internals is not itself a defect; the concern is callers needing hidden knowledge, or a fixture manufacturing the behavior it claims to observe. Tests that protect accidental machinery do not justify keeping it, and production architecture should not imitate the test framework.
80
+
81
+ ## Modules And Dependencies
82
+
83
+ Goal: modules own coherent decisions and dependencies point toward stable policy; do not reorganize the codebase for conceptual purity, or because it has many files.
84
+
85
+ A module should own one coherent outcome, policy, state boundary, or failure unit. Do not split only by processing step, file type, framework convention, size, or a wish for more abstractions; ask which behavior changes together, which decision has one reason to change, which state and failure behavior belong together, and what callers should stop coordinating. Pressure exists when one module owns unrelated policies, one policy is spread across many modules, state transitions sit apart from their invariants, failure handling is detached from the operation it protects, or callers assemble the real behavior from helpers.
86
+
87
+ Policy should not depend directly on volatile infrastructure that can change independently: stable outcome or policy, then a small dependency interface, then the infrastructure adapter. A **port** is an outcome or capability policy requires; an **adapter** supplies the concrete infrastructure. Use them for provider variation, a known migration, infrastructure details leaking into policy, or tests that need safe dependency control; not when one stable implementation exists, the wrapper hides no decision, the generic interface keeps provider quirks, or caller complexity does not drop. Do not add interfaces around every concrete implementation.
88
+
89
+ A dependency cycle usually means responsibilities are divided wrongly, shared policy or state has no single owner, an interface exposes implementation details, or modules must know each other's lifecycle. Do not break it by moving imports or adding a neutral-looking utility while the conceptual cycle stays; name the shared decision and give it an owner. A layer earns its place when it hides a distinct level of decision; it is shallow when it forwards calls, renames types, exposes lower-layer errors and states, makes callers understand both layers, or exists only to satisfy a pattern.
90
+
91
+ A shared helper can centralize syntax while policy ownership stays scattered. Before extracting shared code, ask whether it is one concept that should evolve together, who owns its behavior and failure contract, whether callers still make the same decision independently, and whether extraction removes coordination or only moves code. Some duplication is cheaper than a shared abstraction with unclear ownership.
92
+
93
+ ## Pressure Signals
94
+
95
+ Goal: identify the pressure that changes the next action, or conclude that none does; do not count smells or redesign the system.
96
+
97
+ Ask what caller outcome and interface are affected, what callers must know or coordinate, whether the current change added to it, what policy, dependency, state transition or failure behavior is spreading, whether the cause is supported, and whether it can be resolved inside accepted scope and authority.
98
+
99
+ Complexity is coordination, not line count; a large implementation can be simple to use, and a small helper complex when every caller must know its quirks: change amplification (one change needs many surrounding edits), cognitive load (callers must remember many facts), obscurity (important rules are hard to find), dependency burden (a safe change needs unrelated modules understood), and unknown unknowns (a caller cannot tell what else to inspect). Signals:
100
+
101
+ - **Change amplification:** one policy change needs edits across unrelated callers. Name the decision causing them; do not merely move the same choreography into one helper.
102
+ - **Caller protocol growth:** callers perform internal lifecycle steps, each correction adds a state or flag, recovery becomes ordinary caller behavior, or callers depend on paths, filenames, provider errors, or queue names. Ask whether one operation can own the whole success and failure unit and publish diagnostics separately.
103
+ - **Scattered policy:** one product or operational decision is encoded in several places. Do not centralize it until the policy is accepted; stop for a decision when it is user-owned or conflicting.
104
+ - **Unowned state or failure:** no module owns canonical state and its visibility point, forbidden partial outcomes, retry or escalation, cancellation and reconciliation, recovery after partial completion, or the evidence proving the final state.
105
+ - **Contract-surface growth:** each patch adds public flags, temporary states, manifest fields, retry links, recovery instructions, provider-specific errors, or cache and integrity controls.
106
+ - **Distorted tests:** tests reproduce caller choreography, mock many helpers to verify one outcome, depend on private lifecycle states, protect machinery from recent patches, prove rejection without checking forbidden writes, or make provider mechanics look like domain requirements. First check whether the production boundary owns the complete behavior; do not add mocks or test-only seams automatically.
107
+ - **Edge-case patch streams:** related fixes keep adding conditions, states, or caller rules. Diagnose whether they share one missing contract, state owner, or failure unit; finding count alone is not architecture.
108
+ - **Scope growth:** a bounded result unexpectedly needs a subsystem, pulls in deferred capabilities, invalidates earlier evidence, or requires unrelated callers to change.
109
+ - **Wrong edits that look right:** assume the next contributor knows only the files it has open, imitates the closest existing code, and stops at the first change that builds. That edit goes wrong when one piece of state has two writers and the edit reaches only one, when two supported ways do one task and each copy spreads the one found first, when outside code can import a module's internals and so turns them into interface, or when lists of the same items are kept in step by hand. Look for the boundary that makes the obvious local edit correct everywhere: one writer, one way, unreachable internals, and lists derived from one source or checked against it.
110
+ - **Interface mismatches:** a pass-through wrapper that hides no policy (keep it only for a real domain, compatibility, or observation boundary); a leaky interface exposing infrastructure details; a god module; a speculative seam; a dependency cycle; a Spec or Plan freezing classes, tables, or algorithms before evidence supports the boundary.
111
+
112
+ Do not escalate when stable repetition is small and local, broad edits are mechanical and source-backed, a one-off script needs no abstraction, a wrapper keeps a real compatibility contract, one condition is wrong but the interface is sound, an internal test deliberately checks an internal module, or resolving the pressure would exceed the user's goal without blocking it.
113
+
114
+ Choose the narrowest supported route: continue (the boundary is sound); a local correction (the defect stays within one module and contract); diagnosis (the failure is repeated or unexplained); a Spec or Plan revision (behavior, acceptance, or the execution boundary is incomplete); a user decision (resolving it makes a user-owned choice); learning (evidence cannot distinguish viable boundaries); deepening (a supported information-hiding improvement fits accepted scope); or deferred deepening (real but not worth resolving now).
115
+
116
+ When pressure is supported, find the decision the module should hide. Organize modules around decisions likely to change, not processing steps: instead of exposing `parse -> validate -> retry -> send -> log -> clean up`, look for the policy those steps implement: ask which decision would cause the most surrounding edits if it changed, which callers know it now, who should own it, and what outcome-level interface would let callers stop knowing it. A wrapper is not deep because it hides lines; it is deep when callers stop knowing concepts or coordinating protocol. Failure and recovery policy are often that decision. Keep one coherent model of the outcome, state, and failure behavior; pressure exists when a concept has different names or rules across callers, several modules partly own one decision, or callers translate between incompatible representations. Stop the current patch when it clearly spreads a likely-changing decision, adds caller protocol, exposes internal state, creates another required workaround, or makes the next accepted change materially harder. Name the boundary:
117
+
118
+ ```text
119
+ Outcome:
120
+ Coordination currently spread across:
121
+ Likely-changing decision:
122
+ Current owners:
123
+ Proposed owner:
124
+ What callers would stop knowing:
125
+ Failure unit:
126
+ Evidence still missing:
127
+ ```
128
+
129
+ If the decision cannot yet be named, define one bounded learning question rather than a generic abstraction.
130
+
131
+ ## State And Failure
132
+
133
+ Use this section when state must survive a failure: correctness materially depends on canonical state, partial effects, atomic visibility, concurrent writers, cancellation, retries, recovery, reconciliation, or evidence of the final outcome. Do not apply it to a simple local value change whose state owner and failure behavior are already sound.
134
+
135
+ ### Name Canonical State
136
+
137
+ Identify:
138
+
139
+ - canonical source of truth;
140
+ - who may create, replace, or invalidate it;
141
+ - visible states and invariants;
142
+ - commit or visibility point;
143
+ - diagnostic versus authoritative records;
144
+ - what callers may safely cache or infer.
145
+
146
+ Do not let several modules each behave as the source of truth.
147
+
148
+ A log, cache, temporary file, UI projection, or recovery marker is not canonical merely because it is observable.
149
+
150
+ ### Define State Transitions
151
+
152
+ For every material transition, establish:
153
+
154
+ ```text
155
+ precondition
156
+ -> accepted operation
157
+ -> commit or visibility point
158
+ -> resulting canonical state
159
+ -> evidence
160
+ ```
161
+
162
+ Name forbidden transitions and partial states.
163
+
164
+ Prefer one owner for transition policy. Callers should not reproduce state-machine rules independently.
165
+
166
+ ### Bound Partial Effects
167
+
168
+ When an operation affects several resources or can fail midway, establish:
169
+
170
+ - which effects may occur before commitment;
171
+ - which effects are forbidden before commitment;
172
+ - what must be rolled back, reconciled, or retained;
173
+ - what prior accepted state must survive;
174
+ - how partial outcomes are detected;
175
+ - what result is safe to expose.
176
+
177
+ Atomicity may come from transactions, staging, replacement, versioning, or explicit reconciliation. Do not claim atomic behavior from intention alone.
178
+
179
+ ### Separate Retry, Resume, And Replay
180
+
181
+ These are different capabilities:
182
+
183
+ - **Retry:** attempt the same operation again.
184
+ - **Resume:** continue incomplete work from preserved state.
185
+ - **Replay:** apply an event or request again.
186
+ - **Idempotency:** repeated application has one supported effect.
187
+ - **Recovery:** restore a safe supported state.
188
+ - **Reconciliation:** compare and resolve divergent state.
189
+
190
+ Supporting one does not imply the others.
191
+
192
+ Expose them only when required by accepted behavior or observed failure.
193
+
194
+ ### Design Concurrency Deliberately
195
+
196
+ When operations can overlap, identify:
197
+
198
+ - shared state;
199
+ - ordering and visibility;
200
+ - lost-update or duplicate-effect risk;
201
+ - serialization or conflict rule;
202
+ - cancellation behavior;
203
+ - stale-read policy;
204
+ - observer capable of proving the required outcome.
205
+
206
+ Before serializing writers, ask whether they need one shared target at all. When each publishes its own facts, give each its own file, key, or record and combine them where they are read; two workers updating different fields of one state file still share it. Serialize, with a lock, a queue, or a single writer, only when one shared target is itself required.
207
+
208
+ Do not add locks, queues, retries, or optimistic versions without naming the invariant they protect.
209
+
210
+ ### Define Failure And Recovery
211
+
212
+ For the failure unit, state:
213
+
214
+ - who observes failure;
215
+ - canonical state after failure;
216
+ - diagnostic evidence;
217
+ - forbidden partial effects;
218
+ - fail-open, fail-closed, degrade, stop, retry, or escalation behavior;
219
+ - safe restart or recovery operation;
220
+ - evidence proving recovery.
221
+
222
+ A graceful error response does not prove graceful state handling.
223
+
224
+ ### Keep Recovery Out Of Ordinary Callers
225
+
226
+ Callers should normally request an outcome and receive supported success or failure.
227
+
228
+ Do not require every caller to know:
229
+
230
+ - cleanup order;
231
+ - retry schedule;
232
+ - temporary paths;
233
+ - partial-state markers;
234
+ - provider error translation;
235
+ - reconciliation commands.
236
+
237
+ Publish diagnostics without exposing recovery choreography unless callers genuinely own recovery.
238
+
239
+ ### Test State And Failure Through Observable Invariants
240
+
241
+ Tests should verify:
242
+
243
+ - accepted final state;
244
+ - preserved prior state;
245
+ - forbidden writes;
246
+ - composed failures;
247
+ - retry or replay behavior when required;
248
+ - cancellation and recovery;
249
+ - evidence at the real observing boundary.
250
+
251
+ A passing happy-path test does not prove partial-failure safety.
252
+
253
+ ### Return For State And Failure
254
+
255
+ Return the canonical state and owner, material invariants, the failure unit and its forbidden partial outcomes, the retry, resume, replay, and recovery capabilities actually required, and remaining uncertainty. Stop when state and failure ownership are sufficient for the current decision; do not design every theoretical failure mode.
256
+
257
+ ## Return The Smallest Supported Change
258
+
259
+ When evidence cannot choose between viable boundaries, answer that question with a bounded learning action rather than building the future system:
260
+
261
+ ```text
262
+ Question:
263
+ Competing boundaries:
264
+ Smallest prototype or observation:
265
+ Evidence required:
266
+ Time or cost boundary:
267
+ Discard-or-promote rule:
268
+ Return condition:
269
+ ```
270
+
271
+ The experiment must answer the design question; if its next prerequisite is future production infrastructure, reassess before building it. Working exploratory code is evidence, not production architecture. Compare alternatives only when they are real. Recommend the simplest supported boundary that preserves required behavior, with the structural evidence, the decision it hides, its caller contract and failure behavior, its principal cost, and what would invalidate it: keeping the existing design, a local correction, diagnosis, an artifact revision, a learning action, an accepted deepening, explicit deferral, or a stop for the user's direction. When the selected result is behavior-preserving reduction, use [simplify](simplify.md). Freeze a sufficiently supported boundary instead of pursuing architectural completeness.
@@ -0,0 +1,117 @@
1
+ # Diagnose
2
+
3
+ Read this when a failure has no known cause, or two fixes did not hold: an unexplained bug, failed check, regression, slowdown, flaky or environmental behavior, or contradictory observations.
4
+
5
+ This reference is judgment, with the Rules below and one more under Flaky And Performance Failures. It adds the loop and its routing to Execute Work's [Diagnose Before Fixing](../SKILL.md#diagnose-before-fixing), which already holds the essentials: a plausible line is a hypothesis, the explanation must cover the whole symptom, and two failed fixes mean the diagnosis is wrong.
6
+
7
+ Establish what fails and why before selecting a correction. A supported cause distinguishes the meaningful alternatives well enough to bound the next action; it does not require impossible certainty. A requested patch, a reviewer's theory or a favorable rerun is not a supported cause.
8
+
9
+ ## Rules
10
+
11
+ - Never invent the expected behavior. When accepted behavior or source truth is unsettled, settle it through [Discuss Work](../../discuss-work/SKILL.md) before diagnosing against it.
12
+ - Before active evidence generation, confirm the work agreement covers its path, environment, repetition, instrumentation, cost, sensitive data, and cleanup. Covered bug investigation needs no extra permission; otherwise propose the observation and its stop condition to the user and wait.
13
+ - Preserve unfavorable evidence. Never rerun until a failure disappears, and never drop a contradicting observation.
14
+ - Minimize and sanitize logs, traces, payloads, dumps, screenshots, and browser state; never expose credentials or unnecessary private data.
15
+ - Report a mitigation as containment, not resolution; never claim fixed when only a mitigation succeeded or the reported boundary is unverified.
16
+ - When a remedy makes a user-owned choice, as Discuss Work defines it, take its concrete consequence and alternatives there before adopting it.
17
+
18
+ ## Enter Only For An Unsettled Cause
19
+
20
+ When fresh evidence already shows a clear local defect and the remedy, correct it under [Execute Work](../SKILL.md) instead. Several bugs in one area do not establish a shared structural cause. Keep diagnosis inside the current Slice; when continuity needs it, record the hypothesis, the evidence that decides it, rejected approaches and the next action through [Track Work](../../track-work/SKILL.md), not every trial.
21
+
22
+ ## Establish The Failure, Not The Proposed Fix
23
+
24
+ Identify only what the investigation needs: the expected behavior and its source; the observed symptom and any counterevidence; the relevant input, state, environment, timing and path; and the strongest boundary actually observed, with any gap between it and the reported failure. A nearby symptom suggests a hypothesis but does not reproduce the reported defect; state reduced fidelity.
25
+
26
+ Allowed behavior is not a bug: a cache hit is not a stale-read failure when caching is permitted. A possible race in source is not the cause without evidence connecting its timing and state to the symptom.
27
+
28
+ ## Choose A Distinguishing Observation
29
+
30
+ State a falsifiable leading explanation and only the alternatives the next observation must tell apart:
31
+
32
+ ```text
33
+ Hypothesis:
34
+ Predicted observation:
35
+ What would contradict it:
36
+ Meaningful alternative:
37
+ ```
38
+
39
+ Choose a repeatable loop whose possible results differ between those explanations. Do not build a hypothesis around the requested patch and then treat consistency with it as proof. When timing, randomness, environmental variance, concurrency, or resource behavior shapes the failure, read Flaky And Performance Failures below before selecting or running an observation.
40
+
41
+ Common loops, smallest first that reaches the reported boundary:
42
+
43
+ - **Failing test:** an existing stable interface or test boundary reaches the reported behavior.
44
+ - **Reproduction command:** one CLI, package task, or script with representative fixture input.
45
+ - **HTTP or protocol script:** the smallest real request sequence that crosses the affected boundary.
46
+ - **Browser path:** the user flow with relevant DOM, console, network, and visual observations.
47
+ - **Captured trace:** a sanitized log window, HAR, event payload, seed, timestamped screenshot, dump, or production sample replayed safely.
48
+ - **Throwaway harness:** a minimal script around the real module when no test framework reaches it.
49
+ - **Differential loop:** the same input through old and new code, configuration, dataset, dependency, or environment.
50
+ - **Instrumented run:** targeted probes at boundaries that distinguish competing hypotheses.
51
+
52
+ Before running, write down only the outcomes that tell the hypotheses apart:
53
+
54
+ ```text
55
+ Observation outcome | Effect on leading hypothesis | Effect on alternative
56
+ ```
57
+
58
+ If every likely outcome leaves the same hypotheses plausible, sharpen the observer or choose another loop before generating evidence. Prefer a loop that is sharper (observes the symptom, not generic failure), more representative (keeps the relevant input, state, environment and boundary), more distinguishing, more deterministic (pins time, randomness, dependencies, filesystem or network only when that preserves the failure), faster without narrowing the claim, and safer (isolated mutation, sanitized evidence, bounded cleanup).
59
+
60
+ An observer must sit on the real path and cover the complete operation; a manual counter beside the path, a helper call, or a nearby mocked flow does not prove the reported boundary ran. A UI save that stays pending needs the browser path with its request, console and rendered state, not a reducer unit test. A callback said never to run needs its registered entrypoint invoked or observed, not its helper called directly. A failure only in CI needs the same input compared across local and CI configuration before any timing change or retry.
61
+
62
+ ## Flaky And Performance Failures
63
+
64
+ Rule: never stabilize a flaky failure with sleeps, retries, wider timeouts, swallowed errors, or disabled checks unless evidence shows that mechanism addresses the causal timing or availability contract. Suppressing observation is not correction.
65
+
66
+ Diagnostic measurement explains why variance or resource behavior occurs; after correction, Verify Work establishes whether the representative behavior or performance claim holds.
67
+
68
+ **Flaky failures.** The goal is not one lucky rerun: raise the reproduction rate or capture the distinguishing event until the failure can be explained. Use, when safe and representative, bounded repetition of the exact failing path; captured seeds, time, timezone, locale, viewport, browser, runtime and dependency versions; controlled scheduling, fake clocks, CPU pressure, network delay or concurrency; console, network, event-order, scheduler, screenshot or video traces; and old-versus-new, local-versus-CI or headed-versus-headless differential runs. Choose the repetition count from runtime, cost, side effects and the estimated failure rate, and state the stop condition before running. One green rerun does not contradict an intermittent-failure hypothesis; one red rerun may establish the symptom but not its cause. Classify from the aggregate pattern or the captured event. Do not loop mutating production behavior to improve reproduction. Twenty green reruns after widening a timeout mean the failure was suppressed or became rarer; its cause is still unresolved.
69
+
70
+ **Performance problems.** Measure the reported path before optimizing it. Useful causal evidence includes a baseline for the representative workload; the slow input, dataset, concurrency, cache and dependency state; a profiler, flamegraph, query plan, allocation profile or browser trace; an old-versus-new comparison under matched conditions; and a benchmark of the dominant work the evidence identified.
71
+
72
+ Reduce a large profile, trace, or heap snapshot to a form you can query before reading it, such as one row per sample, frame, or node in SQLite. Then query for the frames holding the most time, or follow the retainer chain from the leaked object to a root. A hot frame without a source mapping is not yet a diagnosis: resolve its symbols, or say the artifact lacks them. One capture supports the strongest remaining hypothesis; a matched before-and-after capture or another distinguishing observation is needed to support the cause.
73
+
74
+ A microbenchmark can test a hypothesis but does not explain the reported slowdown unless the isolated operation determines the real path: a parser benchmark that improves while the trace is dominated by database waiting explains nothing. Repeated calls with one object justify memoization only when the reported workload repeats that object and measurement shows the repeated work dominates. Median latency improving while tail latency or memory crosses the accepted boundary leaves the claim contradicted or incomplete.
75
+
76
+ When choosing the correction for the dominant work, try the cheapest kind first and stop at the first that meets the target: drop work whose result nothing uses, stop repeating it, do less of it, defer it, move it off the path someone waits on, run it concurrently, and only then make it faster. Sanitize production traces and payloads; when safe production evidence is unavailable, use representative non-production evidence and downgrade the claim. After an authorized correction, verify that the representative baseline improves and required behavior stays correct, and report variance and resource trade-offs rather than one favorable run.
77
+
78
+ Stop when the loop has produced a distinguishing pattern or event, the planned repetition or cost boundary is reached, or the required representative evidence is unavailable.
79
+
80
+ Stop reading once the context supports the experiment. If no safe, useful observer exists, report the smallest missing input, trace, environment, permission, or instrumentation rather than patching a guess.
81
+
82
+ ## Interpret One Iteration
83
+
84
+ Run one covered observation, changing one distinguishing variable at a time. [Verify Work](../../verify-work/SKILL.md) owns what a check result means; diagnosis owns the causal inference. Keep three results apart:
85
+
86
+ - **Check result:** Passed, Failed, Error, or Unavailable, as Verify Work defines them. Observing an expected target failure can be a Passed check.
87
+ - **Hypothesis result:** Supported, Contradicted, Inconclusive, or Unavailable at the stated boundary.
88
+ - **Cause status:** Supported or Unresolved.
89
+
90
+ A supported cause connects trigger and state through a mechanism to the symptom, predicts the observations, weakens the viable alternatives, and bounds a correction without guessing. A supported hypothesis need not establish the cause: if only the strongest remaining hypothesis is supported, say so and name its missing link.
91
+
92
+ - Check Error -> repair or replace the observer, not production.
93
+ - Check Unavailable -> return the missing evidence or authority.
94
+ - Hypothesis Contradicted -> keep the result and revise the explanation.
95
+ - Hypothesis Inconclusive -> choose a sharper observer if one is useful and covered.
96
+ - Hypothesis Supported, cause Unresolved -> test the remaining link or alternative.
97
+ - Cause Supported -> return the correction boundary.
98
+
99
+ Stop when the cause is sufficiently supported or no covered observation can improve the decision; do not keep investigating because stronger certainty is imaginable.
100
+
101
+ ## Keep The Correction Inside The Task
102
+
103
+ A failed reproduction method is not proof that production needs new infrastructure, a stronger guarantee, or a host change. Choose the smallest correction that preserves accepted behavior, and classify only the owning cause the evidence supports: a local defect; an invalid, stale or inadequate check; an environment, dependency, data, timing or configuration issue; a missing observer; unsettled behavior or a source conflict; the wrong result, scope, order or strategy; or structural ownership, interface, state or failure-unit pressure.
104
+
105
+ Before adding a guard that lets the failing state pass, such as a check, default, retry or caught error, ask whether accepted behavior allows that state. If it should never exist, the guard hides the defect; correct what produced it. Once the cause is supported, look for the same fault wherever the same mechanism recurs; correct instances inside the agreed boundary and report the rest.
106
+
107
+ When the evidence establishes structural pressure, read [design](design.md); it shapes the boundary without re-proving the cause. If design reveals an unsupported causal premise, come back here with that exact uncertainty.
108
+
109
+ ## Contain Harm And Keep Instrumentation Honest
110
+
111
+ Bound repetitions by time, cost, effects, and environment safety. Temporary instrumentation must distinguish hypotheses; keep it isolated and state its observer, its mutation or performance impact, its removal condition, and whether it remains. When immediate harm needs containment before the cause is settled, propose one narrow, reversible mitigation to the user that preserves evidence, defines its check and recovery, and settles no undefined behavior. An experimental patch can generate evidence when authorized as learning; it does not select production behavior.
112
+
113
+ ## Return A Supported Correction Boundary
114
+
115
+ Return proportionately: the failure and expectation at the required boundary; the loop, check result and hypothesis result; the causal chain, alternatives weakened and remaining uncertainty; the owning cause and smallest correction; a minimized regression signal; when the deciding fact took deep digging, a cheap always-on signal (a log line, assertion or metric) that would have shown it at first look; and instrumentation, containment, residual effects and authority limits.
116
+
117
+ A covered correction continues under Execute Work. Use [simplify](simplify.md) only for an accepted removal of obsolete or workaround machinery, not as a substitute for the fix. After correction, verify the minimized signal and the original reported path or the strongest available observer; a nearby passing test is not enough. If the fix fails or reveals related shared-state consequences, return to the causal question before another patch.
@@ -0,0 +1,108 @@
1
+ # Migration
2
+
3
+ Read this when moving users, data or traffic to a replacement, or removing an old path: a new implementation, schema, service, configuration form, dependency or platform that consumers in use must move to safely.
4
+
5
+ This reference is judgment about moving consumers, state or traffic without losing compatibility, evidence or recovery options; its "do not" lines and the authority Rule below are binding.
6
+
7
+ A replacement existing does not prove that consumers moved. A migration unit may be complete while the old path remains under an accepted support contract. Removal is a separate claim with separate evidence and authority.
8
+
9
+ ## Establish Authority And Scope
10
+
11
+ Rule: loading this reference, discussing a migration, or approving a general implementation Plan does not authorize migration, deprecation, cutover, destructive cleanup, or removal. Carry out only the stages and units explicitly requested or separately approved.
12
+
13
+ Take to [Discuss Work](../../discuss-work/SKILL.md) whatever remains unresolved among: maintaining, deprecating or removing the old behavior; advisory versus compulsory migration, deadlines or support windows; compatibility, public API, data conversion, downtime, permissions, billing, security, privacy or data-loss behavior; irreversible cutover, destructive cleanup or rollback limits.
14
+
15
+ Do not manufacture a migration because code looks old: inspect ownership, supported consumers, runtime use, source truth, incidents, maintenance cost, and current value. When replacement behavior, interfaces, ownership or failure semantics remain unsettled, settle them first: Discuss Work for a user-owned choice, [design](design.md) for a design-bearing boundary, [Write Docs](../../write-docs/SKILL.md) when the accepted migration behavior needs a durable contract.
16
+
17
+ ## Define The Migration Contract
18
+
19
+ Before moving anything, establish:
20
+
21
+ ```text
22
+ Old contract and current value:
23
+ Replacement contract and known differences:
24
+ Consumers / callers / data / traffic:
25
+ Compatibility promise and support window:
26
+ Migration unit and ordering:
27
+ State written during transition:
28
+ Verification for each unit:
29
+ Rollback or forward-recovery path:
30
+ Removal proof:
31
+ Owner decisions and stop conditions:
32
+ Approved stages and scope:
33
+ ```
34
+
35
+ Treat undocumented observable behavior as a possible consumer dependency until evidence says otherwise. Do not preserve every quirk automatically; surface consequential differences for decision.
36
+
37
+ Choose the smallest shape that preserves accepted compatibility, safety, and evidence; do not force every migration through one sequence:
38
+
39
+ - **Code or API:** add the new contract, migrate callers in bounded groups, remove the old contract.
40
+ - **Configuration:** support old and new forms temporarily, migrate stored and generated config, reject the old form only after compatibility obligations end.
41
+ - **Traffic:** route bounded cohorts to the new path, compare behavior and operational signals, expand only when the advance criteria hold.
42
+ - **Data:** expand the schema, backfill or transform, move reads and writes, reconcile, then contract the old representation.
43
+ - **Dependency:** introduce the replacement, verify compatibility at owning seams, migrate packages or consumers, remove the old dependency and its transitive assumptions.
44
+ - **Feature:** define replacement or removal behavior, migrate users and documentation, observe usage, then remove code and operational surfaces.
45
+
46
+ Inventory consumers from static references and dependency graphs; runtime traffic, logs, metrics, traces or audit records; generated clients, plugins, scripts, jobs and configuration; external teams, independently deployed services, offline clients and dormant accounts; package download or version-support data; and owner attestations where observation is impossible. Classify unknowns: missing telemetry is unavailable evidence, not zero use. For the static part, Execute Work's [touch-map](../scripts/touch-map.mjs) lists entry points, readers, writers and covering tests for each old symbol or file, and what it did not search.
47
+
48
+ ## Prepare The Replacement
49
+
50
+ When an additive or replacement stage is approved:
51
+
52
+ - prove the replacement through the real caller path or interface;
53
+ - keep old and new ownership explicit;
54
+ - add adapters, flags, aliases, translation, or dual reads and writes only when the migration contract requires them;
55
+ - do not add features to the old path unless safety or an explicit support decision requires it.
56
+
57
+ Adapters, aliases, dual writes, translation, flags, and shims are migration tools, not permanent architecture. For each, record:
58
+
59
+ ```text
60
+ Purpose:
61
+ Consumers protected:
62
+ Observable differences:
63
+ Owner:
64
+ Exit condition:
65
+ Removal evidence:
66
+ Failure behavior:
67
+ ```
68
+
69
+ If a shim grows harder to remove with each consumer, or starts spreading caller knowledge, public states or exceptions, take the structural evidence to [design](design.md#pressure-signals) rather than building a second permanent system.
70
+
71
+ Before moving data, settle the authoritative source in each phase; idempotency and restart; duplicate, partial, invalid and late records; read and write ordering and reconciliation; privacy, retention, permissions and audit; rollback versus forward-only recovery; and backup, restore and destructive-cleanup proof. A reversible schema change does not imply reversible data semantics.
72
+
73
+ An emergency migration without a viable replacement may be necessary for security or data safety, but it needs explicit owner direction, bounded impact, and a documented failure and recovery contract.
74
+
75
+ ## Move Bounded Units
76
+
77
+ Move one accepted consumer, cohort, traffic segment, configuration set, or data partition at a time:
78
+
79
+ 1. capture the relevant pre-migration state or baseline;
80
+ 2. apply the migration through the intended path;
81
+ 3. verify behavior, data, errors, permissions, and operational signals at the required boundary;
82
+ 4. confirm rollback or forward recovery remains possible;
83
+ 5. preserve evidence and account for remaining units.
84
+
85
+ Decide each next step by criteria set before the unit began, using the advance, hold and abort vocabulary in Deliver Work's [launch](../../deliver-work/references/launch.md); the owner decides consequential thresholds and acceptable degradation.
86
+
87
+ Code search alone cannot prove completion when runtime, external, dormant, generated, offline, or independently deployed consumers may exist. Stop and report the evidence, taking any choice it leaves to the user through Discuss Work, when replacement behavior diverges, unknown consumers appear, a new owner decision is needed, data cannot be reconciled, recovery assumptions fail, compatibility machinery spreads, or the next safe unit is unclear. Keep completed units; do not restart the whole migration.
88
+
89
+ ## Remove The Old Path
90
+
91
+ Remove or disable the old path only when that stage is explicitly authorized and the removal proof holds, combining the strongest available evidence:
92
+
93
+ 1. no supported consumer, active or dormant, still requires the old contract;
94
+ 2. runtime, telemetry or owner evidence covers consumers static analysis cannot see;
95
+ 3. data and configuration are reconciled;
96
+ 4. compatibility, support-window, observation and rollback obligations have ended;
97
+ 5. the replacement stays verified with the old path disabled or absent;
98
+ 6. old code, adapters, flags, tests, docs, alerts, dashboards, secrets, jobs and configuration are classified for removal or retention, and removal erases no required history, audit evidence or recovery material.
99
+
100
+ If a consumer class cannot be observed, state the uncertainty and obtain the owning decision before destructive removal. Do not delete source truth or historical migration evidence to make searches clean. When current docs or contracts would become false, report them, and update them when the approved scope includes them.
101
+
102
+ ## Verify, Deliver And Report
103
+
104
+ Use [Verify Work](../../verify-work/SKILL.md) for each unit, compatibility, reconciliation and absence claim: "the new path passes" does not prove "the old path is unused". Propose an independent review through Review Work when the migration changes public contracts, moves consequential data, crosses security or privacy boundaries, affects many consumers, or performs an irreversible cutover or cleanup.
105
+
106
+ Publishing the replacement as a versioned artifact, and any stage that changes production traffic, data, configuration or exposure, including the rollout and the old path's removal from production, go through [Deliver Work](../../deliver-work/SKILL.md), each within its own yes.
107
+
108
+ Report the approved scope and completed units; replacement and compatibility status; remaining consumers, state, traffic or observation windows; verification and operational evidence; rollback or forward-recovery status; legacy parts removed and deliberately kept; unresolved decisions and residual risk; and the next approved unit, removal boundary, deferral or stop. Removal is complete only when its separate authorization and proof are satisfied.
@@ -0,0 +1,65 @@
1
+ # Simplify
2
+
3
+ Read this when behavior-preserving cleanup, refactoring or deletion is the agreed result.
4
+
5
+ This reference is judgment: adapt it to the code in front of you. It supplies a behavior-preserving transformation under Execute Work; it does not define behavior, authorize redesign, or turn nearby cleanup into accepted work.
6
+
7
+ Remove one named source of complexity while preserving accepted behavior. Judge simplicity by the concepts and coordination a reader must hold, not by line, file, or abstraction count.
8
+
9
+ ## Establish What Must Stay True
10
+
11
+ Before editing, identify:
12
+
13
+ - the accepted behavior, relevant callers, and failure semantics;
14
+ - a reliable baseline that would detect a change;
15
+ - the complexity or coordination to remove;
16
+ - why the current structure exists, including compatibility, platform, performance, migration, and recovery constraints.
17
+
18
+ If expected behavior is unclear or should change, settle it through [Discuss Work](../../discuss-work/SKILL.md); if current behavior or a failure is unexplained, [diagnose](diagnose.md) first. Do not characterize an invented expectation. When protection is missing, establish the smallest useful observation of behavior before transforming it ([Test Design](../../verify-work/references/test-design.md) when you design that check). Characterization protects required stable behavior, not every accidental implementation detail.
19
+
20
+ Take a change to interfaces, ownership, public state, or failure behavior to Discuss Work, with [design](design.md) as the lens. Do not disguise a redesign as cleanup.
21
+
22
+ ## Select One Coherent Transformation
23
+
24
+ Name the actual complexity: a confusing expression, name, branch or temporary state; a pass-through wrapper that hides no decision; generalized machinery with no accepted variation; a scattered concept that can have one owner without changing its contract; an unused, superseded, unreachable or impossible path; or structural pressure that needs a separately agreed boundary change.
25
+
26
+ Choose the smallest complete transformation that removes it, and keep related edits together even across files. Incidental local cleanup inside implementation needs no separate method; this one applies when reducing complexity is itself the agreed result. Fewer helpers are not better if their removal spreads lifecycle or error-handling knowledge into callers.
27
+
28
+ Candidate patterns, to compare against the named complexity rather than to apply because they exist:
29
+
30
+ - **Control flow:** guard clauses where exits are truly equivalent; one named path for duplicate branches; an explicit model or dispatcher when the same shape is branched on across callers; a named intermediate for a dense expression. Keep straightforward branching when a lookup table or hierarchy would add concepts.
31
+ - **Locality:** move behavior toward the state or policy it owns; gather scattered validation, normalization or failure handling behind one stable seam; separate orchestration from business rules when each then reads and tests on its own; reuse a canonical helper instead of a near-duplicate. Do not centralize unrelated behavior because its syntax looks alike.
32
+ - **Indirection:** question pass-through wrappers, one-use factories and strategy layers, aliases that no longer protect compatibility, helpers whose interface is as complex as their body, extension points with no accepted variation, and adapters that outlived a migration. Keep indirection that hides a volatile dependency, enforces policy, preserves a real compatibility contract, or creates real test and change locality.
33
+ - **Names and types:** rename generic or misleading terms to the domain's language; make an invariant explicit at a type or interface boundary when that removes downstream checks; remove casts, optionality and silent fallbacks only after proving the stronger invariant.
34
+ - **Duplication:** harmful when one behavior must change in several places and can drift. First confirm two snippets are the same concept that should evolve together; a little explicit repetition can be simpler than an abstraction with flags, callbacks or hidden coupling.
35
+
36
+ ## Apply And Observe
37
+
38
+ Within the existing agreement:
39
+
40
+ 1. State which concepts or coordination will disappear.
41
+ 2. Make the complete behavior-preserving change.
42
+ 3. Run focused behavior and failure checks.
43
+ 4. Inspect the real caller path and the resulting code.
44
+ 5. Compare the required coordination before and after.
45
+ 6. Keep the supported result, or return a failed transformation for correction or covered rollback.
46
+
47
+ Preserve inputs and outputs, side effects and ordering, errors and recovery, relevant timing and resources, permissions, compatibility, and externally visible state. Follow repository conventions, not personal style. Do not combine feature work, bug fixes, new edge-case behavior, public contract changes, broad modernization, or unrelated cleanup with the transformation.
48
+
49
+ ## Read Checks Without Protecting Accidental Machinery
50
+
51
+ Use [Verify Work](../../verify-work/SKILL.md) for what the observations establish; a green suite cannot prove unchanged behavior it did not exercise. When an implementation-detail check fails while caller behavior looks unchanged, establish whether the detail is contractual, the check is stale or over-coupled, the transformation changed behavior, or the observer is inadequate. Do not infer the answer from the cleanup you want, and do not rewrite a valid behavioral assertion to make the refactor pass. Retain or add independent checks where needed, and inspect the changed behavior rather than report only test counts.
52
+
53
+ ## Delete Only With Supported Absence
54
+
55
+ Before removing code, establish its purpose and current consumers through source, runtime registration, configuration, generated callers, tests, history, and compatibility obligations. Execute Work's [touch-map](../scripts/touch-map.mjs) lists the local ones for each symbol or file, with what it did not search. An empty local search does not establish the absence of external or dormant consumers.
56
+
57
+ Truly dead local code may go within the agreed boundary. Supported legacy behavior, and compatibility, fallback, platform, migration, audit or recovery behavior that only looks redundant, needs consumer evidence first; read [migration](migration.md) when removal carries consumer, state or compatibility obligations. Historical docs and evidence are not dead code; do not delete them to make a search clean. Commented-out code normally belongs in version history, unless it is an intentional operational instruction.
58
+
59
+ ## Judge The Result And Stop
60
+
61
+ Ask whether there are fewer concepts and branches to coordinate, clearer ownership, fewer related edit locations, visible failure semantics, a smaller or unchanged public interface, and tests focused on behavior rather than internal choreography. If the result is shorter but harder to understand, test, or change, complexity was relocated rather than reduced.
62
+
63
+ Stop and return the changed boundary when unchanged behavior is unsupported, public or failure semantics changed, a resource trade-off is unmeasured, source truth conflicts, or each correction exposes another ownership or edge-case problem. Do not extend cleanup to rescue a failing approach.
64
+
65
+ When the named complexity is gone and the behavior boundary is supported, report the protected behavior, the concepts removed, before and after evidence and its limits, comment changes, and complexity deliberately kept. Begin no further cleanup and claim no broader modernization from this result.