@adia-ai/adia-ui-factory 0.2.2 → 0.2.3

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 (94) hide show
  1. package/.claude-plugin/plugin.json +12 -3
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +24 -1
  4. package/bin/adia-scaffold +93 -13
  5. package/package.json +2 -2
  6. package/references/shell-embed.md +10 -0
  7. package/references/spa-architecture.md +7 -0
  8. package/skills/adia-ui-kit/CHANGELOG.md +41 -0
  9. package/skills/adia-ui-kit/SKILL.md +442 -0
  10. package/skills/adia-ui-kit/assets/figma-make/guidelines/Guidelines.md +87 -0
  11. package/skills/adia-ui-kit/assets/figma-make/guidelines/components.md +142 -0
  12. package/skills/adia-ui-kit/assets/figma-make/guidelines/styles.md +118 -0
  13. package/skills/adia-ui-kit/assets/figma-make/guidelines/tokens.md +120 -0
  14. package/skills/adia-ui-kit/assets/team-scaffold/archive-README.md +30 -0
  15. package/skills/adia-ui-kit/assets/team-scaffold/drafts-README.md +57 -0
  16. package/skills/adia-ui-kit/assets/team-scaffold/inbox-README.md +76 -0
  17. package/skills/adia-ui-kit/assets/team-scaffold/outbox-README.md +46 -0
  18. package/skills/adia-ui-kit/assets/team-scaffold/team-root.README.md +51 -0
  19. package/skills/adia-ui-kit/assets/team-scaffold/tickets-README.md +208 -0
  20. package/skills/adia-ui-kit/assets/team-scaffold/tickets-REGISTRY.md +81 -0
  21. package/skills/adia-ui-kit/assets/templates/AGENTS.template.md +128 -0
  22. package/skills/adia-ui-kit/assets/templates/CLAUDE.template.md +1 -0
  23. package/skills/adia-ui-kit/assets/templates/FEEDBACK-OMISSIONS-DEFENSE.template.md +150 -0
  24. package/skills/adia-ui-kit/assets/templates/FEEDBACK.template.md +213 -0
  25. package/skills/adia-ui-kit/assets/templates/RESPONSE.template.md +114 -0
  26. package/skills/adia-ui-kit/assets/templates/figma-make-guidelines.md +90 -0
  27. package/skills/adia-ui-kit/evals/adversarial-content-trust.json +83 -0
  28. package/skills/adia-ui-kit/evals/evals.json +55 -0
  29. package/skills/adia-ui-kit/evals/routing-corpus.json +121 -0
  30. package/skills/adia-ui-kit/evals/teach-routing-cases.json +92 -0
  31. package/skills/adia-ui-kit/references/capabilities.md +245 -0
  32. package/skills/adia-ui-kit/references/catalog-lookup.md +186 -0
  33. package/skills/adia-ui-kit/references/changelog-archive/CHANGELOG-v1.md +8 -0
  34. package/skills/adia-ui-kit/references/changelog-archive/CHANGELOG-v2.md +3585 -0
  35. package/skills/adia-ui-kit/references/changelog-archive/CHANGELOG-v3.md +1899 -0
  36. package/skills/adia-ui-kit/references/common-gotchas-consumer.md +522 -0
  37. package/skills/adia-ui-kit/references/component-literacy.md +291 -0
  38. package/skills/adia-ui-kit/references/composition.md +245 -0
  39. package/skills/adia-ui-kit/references/correction-loop.md +462 -0
  40. package/skills/adia-ui-kit/references/css-policy.md +343 -0
  41. package/skills/adia-ui-kit/references/decision-model.md +158 -0
  42. package/skills/adia-ui-kit/references/diagnostic-output.md +57 -0
  43. package/skills/adia-ui-kit/references/docs-catalog.md +239 -0
  44. package/skills/adia-ui-kit/references/exclusions.md +225 -0
  45. package/skills/adia-ui-kit/references/feedback-authoring.md +466 -0
  46. package/skills/adia-ui-kit/references/figma-make.md +244 -0
  47. package/skills/adia-ui-kit/references/flows-auth.md +307 -0
  48. package/skills/adia-ui-kit/references/flows-content.md +206 -0
  49. package/skills/adia-ui-kit/references/flows-data.md +348 -0
  50. package/skills/adia-ui-kit/references/flows-interaction.md +181 -0
  51. package/skills/adia-ui-kit/references/flows-shells.md +336 -0
  52. package/skills/adia-ui-kit/references/gap-detection.md +266 -0
  53. package/skills/adia-ui-kit/references/harness.md +284 -0
  54. package/skills/adia-ui-kit/references/loading-protocol.md +406 -0
  55. package/skills/adia-ui-kit/references/local-link.md +198 -0
  56. package/skills/adia-ui-kit/references/mcp.md +401 -0
  57. package/skills/adia-ui-kit/references/migration.md +116 -0
  58. package/skills/adia-ui-kit/references/mission.md +194 -0
  59. package/skills/adia-ui-kit/references/mode-routing.md +298 -0
  60. package/skills/adia-ui-kit/references/patterns-agent.md +223 -0
  61. package/skills/adia-ui-kit/references/patterns-data.md +1066 -0
  62. package/skills/adia-ui-kit/references/patterns-forms.md +223 -0
  63. package/skills/adia-ui-kit/references/patterns-layout.md +326 -0
  64. package/skills/adia-ui-kit/references/patterns-recipes.md +1416 -0
  65. package/skills/adia-ui-kit/references/patterns-shells.md +1097 -0
  66. package/skills/adia-ui-kit/references/patterns-traits.md +259 -0
  67. package/skills/adia-ui-kit/references/patterns-wiring.md +339 -0
  68. package/skills/adia-ui-kit/references/pev-rationale.md +137 -0
  69. package/skills/adia-ui-kit/references/reasoning-gate.md +146 -0
  70. package/skills/adia-ui-kit/references/reasoning-methodologies.md +112 -0
  71. package/skills/adia-ui-kit/references/recon.md +192 -0
  72. package/skills/adia-ui-kit/references/rendering-model.md +431 -0
  73. package/skills/adia-ui-kit/references/response-authoring.md +398 -0
  74. package/skills/adia-ui-kit/references/session-log-schema.md +203 -0
  75. package/skills/adia-ui-kit/references/session-log-template.md +118 -0
  76. package/skills/adia-ui-kit/references/setup.md +652 -0
  77. package/skills/adia-ui-kit/references/skill-hygiene.md +135 -0
  78. package/skills/adia-ui-kit/references/spec-to-ui-reasoning.md +394 -0
  79. package/skills/adia-ui-kit/references/state.md +229 -0
  80. package/skills/adia-ui-kit/references/teach-protocol.md +421 -0
  81. package/skills/adia-ui-kit/references/theme.md +142 -0
  82. package/skills/adia-ui-kit/references/version-check.md +69 -0
  83. package/skills/adia-ui-kit/scripts/audit-decision-trace.mjs +198 -0
  84. package/skills/adia-ui-kit/scripts/audit-kit-roster.mjs +366 -0
  85. package/skills/adia-ui-kit/scripts/changelog-archive.mjs +126 -0
  86. package/skills/adia-ui-kit/scripts/check-adia-versions.py +404 -0
  87. package/skills/adia-ui-kit/scripts/run-skill-evals.mjs +358 -0
  88. package/skills/adia-ui-kit/scripts/validate-session-log.mjs +242 -0
  89. package/skills/adia-ui-kit/skill.json +102 -0
  90. package/skills/adia-ui-migration/CHANGELOG.md +47 -0
  91. package/skills/adia-ui-migration/SKILL.md +381 -0
  92. package/skills/adia-ui-migration/skill.json +29 -0
  93. package/skills/adia-ui-spa/SKILL.md +1 -1
  94. package/skills/adia-ui-verify/SKILL.md +2 -2
@@ -0,0 +1,462 @@
1
+ ---
2
+ name: correction-loop
3
+ load-when: When output is wrong, doesn't match intent, or the user says 'that's not right'. Load before patching surface; the procedure forces root-cause identification before fix.
4
+ load-size-tokens: ~6,200
5
+ required-for:
6
+ - recovery mode (mode 9)
7
+ - any time the user says output is wrong
8
+ - compound-fix avoidance
9
+ ---
10
+
11
+ # §CorrectionLoop — How to reason when output is wrong
12
+
13
+ This is the third posture, alongside Author and Consultant. It triggers
14
+ whenever something you produced — markup, plan, recipe, diagnostic
15
+ report, ticket, commit, or response — is reported as incorrect, or you
16
+ yourself notice it is wrong before the user does.
17
+
18
+ **The instinct to fix is the failure mode.** Patching the surface
19
+ without finding the root cause guarantees the bug re-emerges in another
20
+ shape next turn. The Correction Loop is a strict 5-phase recovery
21
+ discipline that pre-empts that instinct.
22
+
23
+ ### The Correction Loop (in strict order)
24
+
25
+ ```
26
+ 1. CONTEXT What is the current state, and what is being said?
27
+ 2. REFERENT What is the user or agent referring to — concretely?
28
+ 3. DECOMPOSE What are the layers of the stack, and where does the
29
+ symptom originate?
30
+ 4. ROOT-CAUSE First-principles analysis: what is the irreducible
31
+ source of the wrong output?
32
+ 5. CLASSIFY Which layer owns the fix? Apply the right remediation
33
+ and route to the right channel.
34
+ ```
35
+
36
+ Skip none. Each phase has a stop-condition that gates the next.
37
+
38
+ ### Phase 1 — CONTEXT — Re-anchor before reacting
39
+
40
+ Before any analysis, restate the current context to yourself in plain
41
+ English:
42
+
43
+ - **What turn is this?** (greeting, mid-task, post-task review, error
44
+ report.)
45
+ - **What did I just produce?** (markup file, diagnostic report, plan,
46
+ commit, conversation reply.)
47
+ - **What did the user just say?** (the literal words; do not paraphrase
48
+ defensively.)
49
+ - **What other context is live?** (peer agent commits since last turn,
50
+ uncommitted working-tree state, stale memory entries that may now be
51
+ wrong — AGENTS.md hard rule: memory is "as of last write", trust
52
+ `git log` + filesystem over memory.)
53
+
54
+ **Stop-condition:** you can write two sentences summarizing the current
55
+ state without assumption or interpretation. If you can't, re-read the
56
+ last 3 user messages + `git log --oneline -5` + `git status` before
57
+ proceeding to Phase 2.
58
+
59
+ **Anti-pattern:** reacting to the most recent user message in isolation.
60
+ Almost every "wrong output" report has 2–3 turns of prior context that
61
+ shapes the correct fix. Re-anchor first.
62
+
63
+ ### Phase 2 — REFERENT — What are they actually pointing at?
64
+
65
+ User feedback on wrong output is rarely precise. You must resolve the
66
+ referent before you can analyze:
67
+
68
+ - **Concrete artifact** — which file / URL / component / spec / commit
69
+ is the user pointing at? Quote them or extract the exact reference.
70
+ - **Comparison anchor** — what is the user comparing against? ("this
71
+ doesn't match the reference shell at /site/examples/admin-dashboard"
72
+ has two referents: the produced output AND the comparison anchor.)
73
+ - **Failure mode** — what specifically is wrong? Wrong markup, wrong
74
+ styling, wrong intent, wrong primitive choice, wrong spec citation,
75
+ wrong file location, wrong version. Each maps to a different
76
+ remediation path.
77
+ - **Implicit reference** — what is the user *assuming* you know? (A
78
+ spec, an ADR, a journal entry, a prior conversation.) If the
79
+ assumption is unstated and you can't verify it, ask before fixing.
80
+
81
+ **Stop-condition:** you can name (a) the artifact, (b) the comparison
82
+ anchor (if any), (c) the failure mode, and (d) any implicit references
83
+ the user is invoking. If any of (a)–(d) is fuzzy, ask one targeted
84
+ clarifying question — do not guess.
85
+
86
+ **Anti-pattern:** taking the user's diagnosis ("the table is broken")
87
+ as the root cause. The user is reporting a symptom from their
88
+ perspective; your job is to translate that into a verifiable referent.
89
+ Their diagnosis is a hint, not a specification.
90
+
91
+ ### Phase 3 — DECOMPOSE — Locate the layer of origin
92
+
93
+ Map the symptom to the stack layer it originates from. AdiaUI's stack:
94
+
95
+ ```
96
+ Layer Owner Fix shape
97
+ ───────────────────────────── ────────────── ──────────────────────
98
+ 1. User intent / spec User Clarify, restate, plan
99
+ 2. Skill content (this file) Skill author Patch SKILL.md
100
+ 3. Consumer codebase Consumer repo PR / commit
101
+ 4. AdiaUI substrate chat-ui repo Substrate fix + release
102
+ 5. Substrate spec / ADR chat-ui repo ADR amendment + sweep
103
+ 6. Tooling / harness / MCP chat-ui repo Script / config fix
104
+ 7. Browser / runtime Browser vendor Workaround + report
105
+ ```
106
+
107
+ For the symptom: walk **downward** from layer 1. Find the *first*
108
+ layer at which the symptom is *not yet caused*. The symptom originates
109
+ at the *next* layer down. This is the layer of origin.
110
+
111
+ Worked example A — **tag-swap class** ("the produced admin shell uses
112
+ `<main>` instead of `<admin-content>`"):
113
+
114
+ - Layer 1 (intent): User asked for an admin shell. Intent is fine.
115
+ - Layer 2 (skill): Did the skill teach `<main>`? Grep SKILL.md. If
116
+ yes → the skill is the layer of origin. If no → continue.
117
+ - Layer 3 (codebase): Did the codebase have `<main>` examples I
118
+ cargo-culted? Grep the consumer repo. If yes → consumer-codebase
119
+ inheritance was the layer of origin.
120
+ - Layer 4 (substrate): Does `<admin-content>` exist in the substrate?
121
+ Check `node_modules/@adia-ai/web-modules/shell/admin-content/`. If
122
+ no → substrate is the layer of origin (substrate missing primitive).
123
+ - Layer 5 (spec): Does an ADR mandate the `<main>` → `<admin-content>`
124
+ swap? Check `.brain/adrs/`. If the spec is silent → spec gap.
125
+
126
+ Worked example B — **slot-omission class, with the substrate-mechanics
127
+ trap** ("the admin shell renders but the topbar appears mispositioned"):
128
+
129
+ This class is what tag-swap looks like *after* the consumer already
130
+ adopted the canonical vocabulary. The bug is now an attribute (slot,
131
+ variant, name, mode) — right tag, wrong attribute. The diagnosis flow
132
+ below ends with **a discipline rule that pre-empts the failure that
133
+ produced this example.** Read it through before generalizing.
134
+
135
+ - Layer 1 (intent): User asked for canonical admin chrome. Intent
136
+ is fine.
137
+ - **Substrate-mechanics check FIRST, symptom probe second.** Before
138
+ measuring anything with `getBoundingClientRect()`, verify your
139
+ *mental model* matches how the affected components actually
140
+ render. For AdiaUI shell components specifically:
141
+ - `<admin-shell>`, `<admin-sidebar>`, `<admin-content>` are
142
+ **CSS-only light-DOM** (per ADR-0033,
143
+ the canonical Light-DOM substrate stance; surfaced in `AGENTS.md`
144
+ L50 — "Light-DOM
145
+ web components"). They have **no shadow root**.
146
+ - A `slot=` attribute on a child of a light-DOM parent is
147
+ **inert**. There is no `<slot>` element to project into.
148
+ - Positioning is done by CSS rules matching **tag + ancestor
149
+ + DOM order + sibling structure** (e.g. `admin-content >
150
+ admin-topbar:first-child`), NOT by named-slot projection.
151
+ - Therefore: `slot="header"` on `<admin-topbar>` inside
152
+ `<admin-content>` is **decorative** — it does nothing to
153
+ positioning. Adding or removing it leaves the layout
154
+ identical.
155
+ Light-DOM vs Shadow-DOM is the irreducible rate-limiting
156
+ mechanic. Misidentifying it short-circuits everything below.
157
+ - **Symptom probe second.** Run `getBoundingClientRect()` on the
158
+ affected element + its parent + its siblings. But interpret
159
+ carefully:
160
+ - A sidebar's topbar IS expected to span only the sidebar's
161
+ column width (not the viewport). `(0, 0, 200, 48)` inside
162
+ a 200-px sidebar is correct, not broken.
163
+ - A content's topbar IS expected to span the content area's
164
+ width. `(200, 0, 1080, 48)` inside a 1080-px content area
165
+ is correct.
166
+ - Missing elements (no boundingClientRect at all) point at
167
+ a real bug — not at slot-projection failure but at DOM
168
+ construction or CSS-not-loaded.
169
+ - Layer 2 (skill): Does SKILL.md teach the missing attribute? Grep.
170
+ *But also:* does the skill's diagnostic guidance assume Shadow-DOM
171
+ slot mechanics when the affected components are Light-DOM? If yes
172
+ → the skill is teaching a wrong substrate model, which is a more
173
+ serious finding than a missing attribute.
174
+ - Layer 3 (codebase): Does the consumer's source actually differ
175
+ from the canonical references? Diff against `apps/saas/` /
176
+ `*.examples.html` / `site/index.html`. A genuine difference that
177
+ correlates with the visual symptom is the immediate origin;
178
+ cosmetic differences (slot attributes on light-DOM components)
179
+ are NOT the cause even when they look like they could be.
180
+ - Layer 4 (substrate): Could the bug be substrate-side? Check
181
+ whether the affected component has shipped fixes in recent
182
+ CHANGELOG entries; check for CSS-load-order bugs, missing
183
+ imports, or framework regressions.
184
+ - Layer 5 (spec): Is the substrate-mechanics distinction documented?
185
+ AGENTS.md hard rule states Light-DOM but Light-vs-Shadow per
186
+ component is not always called out at the component level. Worth
187
+ promoting to component yaml.
188
+
189
+ > **Real-world arc — and the failure mode this example documents:**
190
+ > Worked example B was extracted from a §CorrectionLoop session
191
+ > against `claims-ui-v4` where the agent (this skill, running in
192
+ > chat-ui) **misdiagnosed** a layout symptom as slot-omission and
193
+ > filed FEEDBACK-37 requesting a substrate `console.warn` for
194
+ > missing `slot="header"` on `<admin-topbar>`. The substrate
195
+ > maintainer shipped the warn in v0.6.20 (`d32e34b4f`), then
196
+ > reverted it 27 minutes later in `664cb3f55` after audit revealed
197
+ > the warn fired on correct markup with a factually wrong message:
198
+ > `<admin-content>` / `<admin-sidebar>` are Light-DOM, the slot
199
+ > attribute is inert there, positioning is by tag + DOM order, and
200
+ > the bars render identically with or without the slot.
201
+ >
202
+ > Root cause of the misdiagnosis: the agent ran
203
+ > `getBoundingClientRect()` and interpreted `(0, 0, 200, 48)` for
204
+ > the sidebar's topbar as "broken (only 200 px wide instead of
205
+ > viewport-spanning)" — but 200 px is the correct sidebar-column
206
+ > width and the topbar correctly spans it. The "missing
207
+ > content-topbar from normal flow" was a separate symptom with a
208
+ > different cause, conflated with the first under one wrong
209
+ > diagnosis.
210
+ >
211
+ > **The discipline this teaches:** verify your mental model of the
212
+ > substrate's rendering mechanism (Light-DOM vs Shadow-DOM,
213
+ > CSS-projection vs slot-projection) *before* the symptom probe.
214
+ > A wrong mental model turns correct measurements into wrong
215
+ > conclusions. The `getBoundingClientRect()` probe is only as good
216
+ > as the model interpreting its output.
217
+ >
218
+ > The compound-fix rule still holds — but here the "fix" turned
219
+ > out to be: Layer 3 was already correct; Layer 4 needed no
220
+ > change; Layer 2 (this skill) needed the substrate-mechanics
221
+ > check at the top of the diagnostic flow; Layer 5 (spec) is the
222
+ > Light-DOM-vs-Shadow-DOM clarity that AGENTS.md mentions but
223
+ > component yamls don't always surface.
224
+ >
225
+ > **Pedagogical value: a misdiagnosis ticket that shipped + got
226
+ > reverted is more useful than a clean diagnosis would have been.**
227
+ > The post-mortem captures a discipline gap (substrate-mechanics
228
+ > assumption) that a clean case would have hidden.
229
+
230
+ ### Bug-shape taxonomy (what to expect at Phase 3)
231
+
232
+ Real bugs cluster into a small number of shapes. Recognizing the shape
233
+ narrows the layer hunt:
234
+
235
+ | Shape | Symptom | Most common origin layer |
236
+ |---|---|---|
237
+ | **Tag swap** | Wrong tag entirely (`<main>` for `<admin-content>`) | Layer 2 (skill stale) or Layer 3 (codebase predates ADR) |
238
+ | **Slot misdiagnosis** (the Light-DOM trap) | Looks like missing `slot=` attribute; actually the parent is Light-DOM and slot is inert | Layer 2 (agent's wrong substrate model) — NOT a real slot bug |
239
+ | **Attribute-shape misuse** | Right tag/slot, wrong value type (string for array, object for primitive) | Layer 4 (substrate silent on bad shape) + Layer 2 (skill missing shape contract) |
240
+ | **Composition violation** | Right primitives, wrong nesting (`<button-ui>` inside `<button-ui>`, `<field-ui>` containing a self-labeling widget) | Layer 5 (composition rules not in ADR) + Layer 4 (no nest-check warn) |
241
+ | **Token override** | Right styling, wrong cascade source (`--a-fg` set in `:root` shadowing variant scope) | Layer 3 (consumer global overrides) + Layer 2 (skill missing scope-discipline note) |
242
+ | **Version-trailing** | Right code, behavior matches older substrate version | Layer 3 (declared range too loose) + Layer 6 (no version-check gate) |
243
+ | **Doc-stale** | Right code matching old spec, spec since superseded | Layer 5 (ADR/spec/journal contradicts itself) |
244
+
245
+ When the bug shape is one of the four lower rows, **expect a compound
246
+ layer-3 + layer-4-or-5 fix**. Single-layer fixes for these shapes
247
+ re-emerge as the next agent hits the same silent trap.
248
+
249
+ The layer of origin determines the remediation channel. Misidentify
250
+ the layer, and you patch the wrong artifact.
251
+
252
+ **Stop-condition:** you can name the layer and cite one piece of
253
+ evidence supporting that assignment.
254
+
255
+ **Anti-pattern:** assuming the symptom's surface layer is its origin.
256
+ "The markup is wrong" → "patch the markup" is wrong 80% of the time;
257
+ the markup is a *symptom* of a deeper layer (skill, consumer
258
+ inheritance, substrate gap, spec silence).
259
+
260
+ ### Phase 4 — ROOT-CAUSE — First-principles analysis at the layer of origin
261
+
262
+ Once you know the layer, run first-principles analysis *at that layer*.
263
+ The questions are layer-specific:
264
+
265
+ **Zeroth question (asked at every layer, not just one):** *Does my
266
+ mental model of the substrate's rendering mechanism match how it
267
+ actually renders?* For AdiaUI specifically, the recurring trap is
268
+ Light-DOM vs Shadow-DOM:
269
+
270
+ - AdiaUI ships **Light-DOM web components** (canonical reference:
271
+ ADR-0033; surfaced
272
+ in `AGENTS.md` L50).
273
+ Shell-tier components (`<admin-shell>`, `<admin-sidebar>`,
274
+ `<admin-content>`, plus most primitives) have **no shadow root**.
275
+ - A `slot=` attribute on a child of a Light-DOM parent is **inert**.
276
+ There is no `<slot>` element to project into. The attribute is
277
+ decorative and changing it does nothing to positioning.
278
+ - Light-DOM positioning is done by CSS rules matching tag + ancestor +
279
+ DOM order + sibling structure (e.g. `admin-content > admin-topbar`),
280
+ NOT by named-slot projection.
281
+ - Components that DO use Shadow-DOM (rare in this substrate) document
282
+ it explicitly in their class.js. When in doubt, grep for
283
+ `attachShadow` / `createShadowRoot` in the component source.
284
+
285
+ **If you skip this check, every measurement you take will be
286
+ interpreted against the wrong model**, and your root cause will be
287
+ plausibly-shaped but factually wrong. The FB-37 misdiagnosis (the
288
+ arc that produced Worked Example B) is the archetype: correct
289
+ `getBoundingClientRect()` measurements were interpreted against a
290
+ Shadow-DOM mental model when the components are Light-DOM, and the
291
+ resulting ticket asked the substrate to enforce a contract that
292
+ doesn't exist.
293
+
294
+ After the zeroth question, the layer-specific questions:
295
+
296
+ **If layer 2 (skill):**
297
+ - What exact section of SKILL.md taught the wrong shape?
298
+ - Why was it phrased that way? (predates SoT change? cargo-culted from
299
+ legacy doc? autocompleted from memory?)
300
+ - What's the irreducible fix? (patch the exact paragraph; the failure
301
+ mode is "skill teaches stale shape" — fix at source, not in markup.)
302
+
303
+ **If layer 3 (consumer codebase):**
304
+ - Does the codebase have an AGENTS.md / convention doc that
305
+ *contradicts* the SoT?
306
+ - Is the codebase predates an ADR adoption that should have happened?
307
+ - Is the codebase deliberately carved-out from the convention? (Check
308
+ the journal / commit log for a "we chose to keep X because Y" note.)
309
+
310
+ **If layer 4 (substrate):**
311
+ - Does the substrate primitive *exist*? (yaml exists, JS class exists,
312
+ examples render?)
313
+ - Does it work correctly? (run the demo locally; check the latest
314
+ CHANGELOG for a fix in flight.)
315
+ - Is the consumer's installed version *behind* the fix? (3-tuple check
316
+ from §GapDetection.)
317
+
318
+ **If layer 5 (spec / ADR):**
319
+ - Is there an ADR for this concern? If no → spec gap; propose one.
320
+ - Is the ADR ambiguous? Quote the ambiguous sentence; propose a
321
+ clarifying patch.
322
+ - Is the ADR contradicted by a more recent journal/spec entry? Trust
323
+ the more recent + flag the contradiction for resolution.
324
+
325
+ **If layer 6 (tooling):**
326
+ - Did a verification gate miss this? (check:lockstep, check:skills,
327
+ check:skill-patterns-sot.) If yes → gate is incomplete; propose a
328
+ gate extension.
329
+ - Did a generation script produce wrong output? (harvester, MCP
330
+ generator.) Trace upstream to the script bug.
331
+
332
+ **Stop-condition:** you can state the root cause in one sentence in the
333
+ shape "**The wrong output happened because <Layer-N artifact> says/does
334
+ <X>, when it should say/do <Y> because of <first-principles reason>.**"
335
+
336
+ If you can't write that sentence, you don't have the root cause yet —
337
+ go back to Phase 3 and recheck the layer assignment.
338
+
339
+ **Anti-pattern:** "the fix is to change the markup" — that's a *patch*,
340
+ not a *root cause*. Markup is layer 3 output; the root cause is in
341
+ layer 2 or 4 or 5. Patching markup without fixing the source layer
342
+ means the next agent will hit the same bug.
343
+
344
+ ### Phase 5 — CLASSIFY — Route the fix to the right channel
345
+
346
+ Every layer of origin has a canonical remediation channel. Apply the
347
+ right one — and frequently, *more than one* (the immediate patch +
348
+ the upstream fix + the prevention gate).
349
+
350
+ | Layer of origin | Immediate fix | Upstream remediation | Prevention gate |
351
+ |---|---|---|---|
352
+ | 1. Intent | Clarify with user, restate plan | n/a | §0 Reasoning Gate (catches at next surface) |
353
+ | 2. Skill | `patch SKILL.md`, bump version | `skill_manage(action='patch')` | check:skills + check:skill-patterns-sot |
354
+ | 3. Consumer codebase | PR / commit to consumer repo | Add convention to AGENTS.md | Consumer-side `check:` script |
355
+ | 4. Substrate | Patch substrate file, lockstep cut | npm release + CHANGELOG | substrate `npm run check` |
356
+ | 5. Spec / ADR | Amend ADR, sweep affected surfaces | Journal entry capturing change | `check:skill-patterns-sot` + spec-INDEX update |
357
+ | 6. Tooling | Patch script / harness / MCP | Add to `npm run check` | CI gate |
358
+ | 7. Runtime | Document workaround, file upstream | Vendor bug report | Catch in §3 Validation |
359
+
360
+ **Compound fixes are common.** A symptom that surfaces in markup
361
+ (layer 3) often has its root in the skill (layer 2) AND a missing
362
+ substrate gate (layer 4) AND a stale spec (layer 5). All three need
363
+ addressing — the markup patch alone leaves the door open.
364
+
365
+ **Ticket submission is layer-routing, not effort-routing.** Don't
366
+ file a ticket "because the fix is big"; file a ticket because the
367
+ layer of origin is owned by someone else, or because the fix needs
368
+ cross-version coordination. The §FeedbackDiscipline four-bucket
369
+ classification + §Team Tickets pipeline cover this.
370
+
371
+ **Stop-condition:** you have a written list of (a) immediate fixes
372
+ landed, (b) upstream remediations queued (with channel: PR, ticket,
373
+ ADR amendment), and (c) prevention gates added or extended. The
374
+ correction is complete when all three are addressed *or* explicitly
375
+ deferred with rationale.
376
+
377
+ **Anti-pattern:** landing only the immediate fix. The next agent re-
378
+ hits the bug in 3 turns. Compound fixes prevent recurrence; that's
379
+ the whole point of root-cause-before-patching.
380
+
381
+ ### When the user reports the wrong output (the conversational shape)
382
+
383
+ When a user message reports incorrect output ("this is wrong",
384
+ "that's not what I asked for", "the X doesn't match Y"), your reply
385
+ shape is:
386
+
387
+ 1. **Acknowledge** without defensive framing. ("You're right — let me
388
+ trace this.")
389
+ 2. **Restate the referent** (Phase 2 output, one sentence).
390
+ 3. **Walk the decomposition** (Phase 3, one sentence — "this came from
391
+ layer N because <evidence>").
392
+ 4. **Name the root cause** (Phase 4, one sentence — the irreducible
393
+ reason).
394
+ 5. **Propose the compound fix** (Phase 5 list — immediate + upstream +
395
+ prevention).
396
+ 6. **Wait for confirmation** before executing — *unless* the immediate
397
+ fix is trivial and obviously correct, in which case land it and
398
+ surface the upstream items for approval.
399
+
400
+ The user gets to see your reasoning chain, which lets them correct any
401
+ layer-assignment mistake before you act on it.
402
+
403
+ ### When the agent (you) notices the wrong output before the user
404
+
405
+ Same loop, same shape. Do not silently swap the fix in — surface the
406
+ correction with the same 5-step chain. Silent correction destroys the
407
+ trail and trains the user to distrust your output.
408
+
409
+ The exception: trivial in-the-moment typo or formatting fix during
410
+ the same turn. Anything load-bearing (markup, plan, spec citation,
411
+ commit content) goes through the full loop with explicit surfacing.
412
+
413
+ ### Sniff tests before declaring root cause
414
+
415
+ Before committing to a layer assignment + root cause, run these
416
+ sniff tests:
417
+
418
+ 1. **Could this symptom occur in a clean repo with the same skill and
419
+ same substrate version?** If yes → root cause is in skill or
420
+ substrate or spec, not consumer codebase. If no → consumer
421
+ codebase carries state that triggers it.
422
+
423
+ 2. **Did this symptom exist before the most recent change I or a peer
424
+ made?** Check `git log -p <file>` for the section in question. The
425
+ commit that introduced the bug is usually the layer of origin.
426
+
427
+ 3. **Does a verification gate exist that *should have* caught this?**
428
+ If yes → gate has a hole; that's a layer-6 finding alongside the
429
+ primary layer. If no → propose adding one.
430
+
431
+ 4. **Is this the same shape of bug I've seen before in this session?**
432
+ If yes → there's a deeper pattern; the layer may be one up from
433
+ where you think. (Example: three wrong markup outputs in a row
434
+ probably means the skill teaches a wrong pattern, not three
435
+ independent markup mistakes.)
436
+
437
+ 5. **Am I about to fix the symptom or the cause?** If you can answer
438
+ "fix" in one verb (`patch markup`, `delete file`, `rename
439
+ attribute`), you're probably surface-patching. If the fix has
440
+ multiple steps across multiple layers, you're addressing the
441
+ cause.
442
+
443
+ ### Correction Loop pitfalls
444
+
445
+ - **Defensive framing.** "Actually, the output is correct because…"
446
+ blocks the loop at Phase 1. Drop the defense; verify the referent.
447
+ - **Authority deference.** "The user says X, so X." Users report
448
+ symptoms; you classify root causes. Take their words as evidence,
449
+ not as the diagnosis.
450
+ - **Skipping Phase 2.** Jumping from "user said wrong" to "I'll fix"
451
+ skips referent resolution and produces fixes for the wrong thing.
452
+ - **Layer mis-assignment.** Patching markup when the skill is the
453
+ origin. Patching the skill when the substrate is the origin.
454
+ Re-run Phase 3 if a fix doesn't hold.
455
+ - **Single-layer fixes for compound problems.** The bug emerges from
456
+ layer 3 because of layer 2 and a missing layer 6 gate. Fixing only
457
+ 3 means it comes back.
458
+ - **Silent correction.** Swapping in the right output without
459
+ surfacing the loop. Train the user to trust your reasoning, not
460
+ your luck.
461
+
462
+ ---