reflection-check 0.0.1 → 0.0.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 (37) hide show
  1. package/dist/cli.js +11 -1
  2. package/dist/cli.js.map +1 -1
  3. package/dist/commands/doctor.d.ts +2 -1
  4. package/dist/commands/doctor.js +109 -2
  5. package/dist/commands/doctor.js.map +1 -1
  6. package/dist/commands/init.d.ts +6 -0
  7. package/dist/commands/init.js +59 -0
  8. package/dist/commands/init.js.map +1 -0
  9. package/dist/commands/run.js +1 -2
  10. package/dist/commands/run.js.map +1 -1
  11. package/dist/commands/update.js +6 -0
  12. package/dist/commands/update.js.map +1 -1
  13. package/dist/contracts/browser/browser-contract.d.ts +2 -1
  14. package/dist/contracts/browser/browser-contract.js +2 -1
  15. package/dist/contracts/browser/browser-contract.js.map +1 -1
  16. package/dist/contracts/browser/route-runner.d.ts +6 -0
  17. package/dist/contracts/browser/route-runner.js +42 -1
  18. package/dist/contracts/browser/route-runner.js.map +1 -1
  19. package/dist/contracts/visual/baseline-compare.js +9 -1
  20. package/dist/contracts/visual/baseline-compare.js.map +1 -1
  21. package/dist/core/baseline-store.d.ts +2 -1
  22. package/dist/core/baseline-store.js +1 -1
  23. package/dist/core/baseline-store.js.map +1 -1
  24. package/dist/core/config.d.ts +8 -0
  25. package/dist/core/config.js +11 -2
  26. package/dist/core/config.js.map +1 -1
  27. package/dist/core/report-schema.d.ts +11 -10
  28. package/dist/core/report-schema.js +47 -1
  29. package/dist/core/report-schema.js.map +1 -1
  30. package/docs/agent-workflows.md +13 -5
  31. package/docs/browser-contract.md +31 -0
  32. package/docs/ci.md +11 -1
  33. package/docs/configuration.md +26 -0
  34. package/docs/getting-started.md +17 -3
  35. package/docs/plans/reflection-dogfood-feedback-implementation-guide.md +639 -0
  36. package/docs/validation-process.md +16 -7
  37. package/package.json +1 -1
@@ -0,0 +1,639 @@
1
+ # Implementation Guide: Reflection Dogfood Feedback
2
+
3
+ Created: 2026-06-01
4
+ Status: draft
5
+ Branch: TBD
6
+
7
+ ---
8
+
9
+ ## Living Document
10
+
11
+ This guide must be updated during implementation:
12
+
13
+ - Check off tasks as they are completed.
14
+ - Add notes when reality diverges from plan.
15
+ - Reorder or split phases when blockers are discovered.
16
+ - Add new tasks discovered during implementation.
17
+ - Mark tasks as "skipped — reason" when they become irrelevant.
18
+ - Record timestamps on phase completions for velocity tracking.
19
+ - Update the test coverage map as tests are written.
20
+
21
+ **Last updated:** 2026-06-02
22
+ **Current phase:** Complete
23
+
24
+ ---
25
+
26
+ ## 0. Project Discovery
27
+
28
+ ### Discovery Summary
29
+
30
+ | Variable | Value |
31
+ |---|---|
32
+ | Package manager | pnpm (`pnpm-lock.yaml`) |
33
+ | Monorepo | No root workspace; includes `examples/basic-react` fixture app |
34
+ | Test runner | Vitest |
35
+ | Test command | `pnpm test` |
36
+ | Typecheck | `pnpm typecheck` |
37
+ | Lint | No lint script discovered |
38
+ | Build | `pnpm build` |
39
+ | Domain checks | `pnpm smoke:package`, `pnpm pack`, `npm publish --dry-run --access public` |
40
+ | CI | `.github/workflows/reflection.yml` |
41
+ | Feature paths | `src/commands/doctor.ts`, `src/commands/run.ts`, `src/core/config.ts`, `src/contracts/browser/**`, `src/core/report-schema.ts`, `docs/**`, `scripts/smoke-package-install.mjs` |
42
+ | Existing tests | `tests/unit/**/*.test.ts`, `tests/integration/**/*.test.ts`, `tests/e2e/**/*.test.ts` |
43
+
44
+ ### Validation Stack
45
+
46
+ | Purpose | Command | Scope |
47
+ |---|---|---|
48
+ | Unit/integration/e2e tests | `pnpm test` | Full package |
49
+ | Typecheck | `pnpm typecheck` | TypeScript package |
50
+ | Build | `pnpm build` | Dist output |
51
+ | Package install smoke | `pnpm smoke:package` | Packed package in temp consumer |
52
+ | Publish dry-run | `npm publish --dry-run --access public` | npm packaging |
53
+
54
+ Validated during guide creation:
55
+
56
+ ```bash
57
+ pnpm test
58
+ pnpm typecheck
59
+ pnpm build
60
+ pnpm smoke:package
61
+ npm publish --dry-run --access public
62
+ ```
63
+
64
+ Current package state:
65
+
66
+ - Published package name: `reflection-check`.
67
+ - Public import path: `import { defineReflection } from 'reflection-check';`
68
+ - CLI binaries: `reflection`, `reflection-check`.
69
+ - Node engine: `>=22`.
70
+ - Runtime browser dependency: `playwright`.
71
+ - Dogfood patch candidate: missing-baseline visual checks now carry the current actual screenshot so `reflection update --dry-run` and targeted update can promote first baselines.
72
+
73
+ ---
74
+
75
+ ## 1. Architecture Contract
76
+
77
+ ### Problem Statement
78
+
79
+ Sourcer dogfooding proved that `reflection-check@0.0.1` can be installed from npm and can produce useful browser evidence, but it also exposed gaps: `doctor` is too shallow, authenticated app setup requires a pattern, report next steps are generic, and setup/CI/baseline flows need stronger first-class support.
80
+
81
+ ### Chosen Approach
82
+
83
+ Convert feedback into small, test-first package improvements. Prioritize improvements that help any consuming app before Sourcer-specific features: better `doctor --config`, explicit browser setup hooks, actionable report suggestions, an `init --dry-run` flow, and CI/package documentation. Keep Reflection read-only by default and avoid silently mutating baselines or target repos.
84
+
85
+ ### Architecture Boundaries
86
+
87
+ | Layer | Owns | Does Not Own |
88
+ |---|---|---|
89
+ | CLI commands | User-facing command flow, errors, dry-run safety | App-specific state or fixtures |
90
+ | Config schema | Stable declarative contract and typed helper | Implicit target repo mutation |
91
+ | Browser contract | Route execution, setup hooks, assertions, screenshots | Login credentials or backend data generation |
92
+ | Report/review | Accurate status, artifacts, next steps | Product-specific remediation content |
93
+ | Docs/scripts | Package install, CI, release and dogfood workflow | Hidden local machine assumptions |
94
+
95
+ ### Non-Negotiables
96
+
97
+ - [ ] Normal `reflection run` must not create or update baselines.
98
+ - [ ] `reflection update` stays explicit and targeted.
99
+ - [ ] `doctor` remains read-only.
100
+ - [ ] Setup hooks must not encourage real credentials or sensitive data in committed config.
101
+ - [ ] Public import path remains `reflection-check`.
102
+ - [ ] Package smoke must prove install from packed artifact before release.
103
+
104
+ ---
105
+
106
+ ## 2. Implementation Phases
107
+
108
+ ### Patch 0.0.2 Candidate: Missing Baseline Promotion
109
+
110
+ **Goal:** Fix the Sourcer-discovered limitation where missing-baseline dry-run/update could not promote the current actual screenshot.
111
+ **Depends on:** Current `0.0.1` package shape
112
+ **Status:** Complete in working tree; full package validation passed. The combined release candidate is now `reflection-check@0.0.3`, and `npm publish --dry-run --access public` passes.
113
+
114
+ #### Inputs
115
+
116
+ - Sourcer feedback: approving first login visual baselines was blocked because missing-baseline visual checks did not expose an `actual` artifact to `reflection update`.
117
+ - Existing visual smoke and update command tests.
118
+
119
+ #### Outputs
120
+
121
+ - Missing-baseline visual checks include `visual/<case-id>/actual.png`.
122
+ - `reflection update --dry-run --case <caseId>` can plan first-baseline promotion.
123
+ - Non-dry targeted update can create the missing baseline root and nested baseline path.
124
+
125
+ #### Relevant Paths
126
+
127
+ | What | Path | Action |
128
+ |---|---|---|
129
+ | Missing baseline check | `src/core/baseline-store.ts` | Edited |
130
+ | Visual comparison | `src/contracts/visual/baseline-compare.ts` | Edited |
131
+ | Baseline update | `src/commands/update.ts` | Edited |
132
+ | Visual smoke tests | `tests/integration/visual-smoke.test.ts` | Edited |
133
+ | Update tests | `tests/integration/update-command.test.ts` | Edited |
134
+
135
+ #### Tasks
136
+
137
+ - [x] Add RED test proving missing-baseline visual checks expose actual screenshot artifacts.
138
+ - **Tool:** edit
139
+ - **Verify:** `pnpm exec vitest run tests/integration/visual-smoke.test.ts`
140
+
141
+ - [x] Add RED test proving update can dry-run and promote a missing baseline into a new path.
142
+ - **Tool:** edit
143
+ - **Verify:** `pnpm exec vitest run tests/integration/update-command.test.ts`
144
+
145
+ - [x] Implement missing-baseline actual artifact and missing baseline root creation.
146
+ - **Tool:** edit
147
+ - **Verify:** focused tests pass.
148
+
149
+ #### Tests for This Patch
150
+
151
+ | Test Type | What to Test | Exists? | Path / Command |
152
+ |---|---|---|---|
153
+ | Integration | Missing-baseline check links current actual artifact | Yes | `pnpm exec vitest run tests/integration/visual-smoke.test.ts` |
154
+ | Integration | Update promotes missing baseline into new path | Yes | `pnpm exec vitest run tests/integration/update-command.test.ts` |
155
+ | Full package | No regressions | Required before publish | `pnpm test`, `pnpm typecheck`, `pnpm smoke:package` |
156
+
157
+ #### Patch Exit Criteria
158
+
159
+ - [x] Focused visual/update tests pass.
160
+ - [x] Full validation passes.
161
+ - [x] Version bumped for patch release.
162
+ - [ ] Sourcer verifies first login baseline dry-run against the patched package.
163
+ - [x] Guide updated with publish outcome.
164
+
165
+ #### Failure Protocol
166
+
167
+ | If | Then |
168
+ |---|---|
169
+ | Dry-run still cannot find actual artifact | Inspect `report.json` visual check artifacts before update planning |
170
+ | Non-dry update cannot create baseline path | Inspect baseline root existence and symlink safety checks |
171
+ | Sourcer still cannot approve baseline | Reproduce with Sourcer artifacts and add another integration test here |
172
+
173
+ ---
174
+
175
+ ### Phase 1: Useful `doctor --config`
176
+
177
+ **Goal:** Turn `doctor` from a shallow status command into a real read-only preflight for consuming repos.
178
+ **Depends on:** Current `0.0.1` package shape
179
+ **Status:** Complete
180
+
181
+ #### Inputs
182
+
183
+ - Existing `src/commands/doctor.ts`.
184
+ - Existing config loader in `src/core/config.ts`.
185
+ - Server readiness behavior in `src/core/server-manager.ts`.
186
+ - Sourcer feedback: doctor previously only printed a one-line status message.
187
+
188
+ #### Outputs
189
+
190
+ - `doctor --config` validates config file presence/import/schema.
191
+ - Doctor reports package/runtime readiness: Node version, Playwright import, browser availability if safe to check, configured routes count, server config summary.
192
+ - Doctor can optionally check server reachability without starting a long-running process unless explicitly configured.
193
+ - Machine-friendly errors with non-zero exit for invalid setup.
194
+
195
+ #### Relevant Paths
196
+
197
+ | What | Path | Action |
198
+ |---|---|---|
199
+ | Doctor command | `src/commands/doctor.ts` | Edit |
200
+ | Config loader | `src/core/config.ts` | Read |
201
+ | CLI wiring | `src/cli.ts` | Read/Edit if options change |
202
+ | Exit codes | `src/core/exit-codes.ts` | Read |
203
+ | Tests | `tests/unit/cli.test.ts`, new `tests/unit/doctor-command.test.ts` | Edit/Create |
204
+ | Docs | `docs/getting-started.md`, `docs/validation-process.md` | Edit |
205
+
206
+ #### Tasks
207
+
208
+ - [x] Add failing unit tests for valid config, missing config, invalid config, and config summary output.
209
+ - **Tool:** edit
210
+ - **Verify:** `pnpm exec vitest run tests/unit/doctor-command.test.ts`
211
+
212
+ - [x] Implement config-aware doctor output.
213
+ - **Tool:** edit
214
+ - **Verify:** focused doctor tests pass.
215
+
216
+ - [x] Add runtime checks that do not mutate or start target state unexpectedly.
217
+ - **Tool:** edit
218
+ - **Verify:** tests cover Playwright/package readiness and safe server summary.
219
+
220
+ - [x] Update docs to describe doctor as a config-aware preflight.
221
+ - **Tool:** edit
222
+ - **Verify:** stale doctor wording search returns no matches in active docs, source, or tests.
223
+
224
+ #### Implementation Notes
225
+
226
+ - `reflection doctor --config` now validates config presence/import/schema and exits with `ExitCode.ToolOrConfigError` for invalid config.
227
+ - `doctor` reports Node version, Playwright package readiness, Chromium executable presence when available, enabled contract counts, base URL, and server configuration.
228
+ - Doctor remains read-only: it does not start configured servers, mutate baselines, or write reports.
229
+ - Added `--check-server` for an explicit one-shot `readyUrl` probe without starting the server.
230
+
231
+ #### Tests for This Phase
232
+
233
+ | Test Type | What to Test | Exists? | Path / Command |
234
+ |---|---|---|---|
235
+ | Unit | Doctor config success/failure summaries | Yes | `tests/unit/doctor-command.test.ts` |
236
+ | CLI | `reflection doctor --config` exit behavior | Yes | `tests/unit/cli.test.ts` |
237
+ | Type safety | Doctor options/types | Auto | `pnpm typecheck` |
238
+ | Package smoke | Installed CLI can run doctor | Yes | `pnpm smoke:package` |
239
+
240
+ #### Phase Exit Criteria
241
+
242
+ - [x] `doctor --config` reports meaningful setup information.
243
+ - [x] Invalid config exits non-zero with actionable error.
244
+ - [x] Docs match behavior.
245
+ - [x] `pnpm test`, `pnpm typecheck`, `pnpm smoke:package` pass.
246
+ - [x] Guide updated with completion status.
247
+
248
+ #### Failure Protocol
249
+
250
+ | If | Then |
251
+ |---|---|
252
+ | Doctor becomes too slow | Split checks into default read-only and optional deep check |
253
+ | Check requires browser install | Report actionable warning instead of hard failure unless required |
254
+ | Output becomes noisy | Keep human summary concise; put detail in JSON later if needed |
255
+
256
+ ---
257
+
258
+ ### Phase 2: Browser Setup Hooks for Authenticated Apps
259
+
260
+ **Goal:** Support authenticated app smoke tests without Sourcer-specific hacks.
261
+ **Depends on:** Phase 1
262
+ **Status:** Complete
263
+
264
+ #### Inputs
265
+
266
+ - Sourcer need: seed localStorage/session or preload state before navigation.
267
+ - Existing browser context factory and route runner.
268
+ - Existing config schema and route expectation model.
269
+
270
+ #### Outputs
271
+
272
+ - Config schema supports browser-level and route-level `setup.localStorage` / `setup.sessionStorage`.
273
+ - Route runner applies setup before visiting a route.
274
+ - Metadata records that setup was applied without logging sensitive values.
275
+ - Docs include examples for non-secret test tokens and mock/test-mode auth.
276
+
277
+ #### Relevant Paths
278
+
279
+ | What | Path | Action |
280
+ |---|---|---|
281
+ | Config schema | `src/core/config.ts` | Edit |
282
+ | Route runner | `src/contracts/browser/route-runner.ts` | Edit |
283
+ | Context factory | `src/integrations/playwright/context-factory.ts` | Edit if storage state belongs there |
284
+ | Browser tests | `tests/integration/browser-contract.test.ts` | Edit |
285
+ | Redaction | `src/core/redaction.ts`, `tests/unit/redaction.test.ts` | Read/Edit if metadata changes |
286
+ | Docs | `docs/configuration.md`, `docs/browser-contract.md` | Edit |
287
+
288
+ #### Tasks
289
+
290
+ - [x] Design the smallest setup API and document rejected alternatives.
291
+ - **Tool:** research/edit guide
292
+ - **Verify:** decision recorded before implementation.
293
+
294
+ - [x] Add failing config tests for setup schema.
295
+ - **Tool:** edit
296
+ - **Verify:** `pnpm exec vitest run tests/unit/config.test.ts`
297
+
298
+ - [x] Add failing integration test proving localStorage/session setup before route navigation.
299
+ - **Tool:** edit
300
+ - **Verify:** `pnpm exec vitest run tests/integration/browser-contract.test.ts`
301
+
302
+ - [x] Implement setup support and metadata redaction.
303
+ - **Tool:** edit
304
+ - **Verify:** focused tests pass.
305
+
306
+ #### Decision Notes
307
+
308
+ - Chosen API: `setup.localStorage` and `setup.sessionStorage` as string key/value maps at browser and route scope.
309
+ - Browser-level setup applies to every route; route-level setup extends or overrides browser-level keys.
310
+ - Rejected for this phase: arbitrary `beforeNavigate` script hooks because they are too broad and harder to make safe; `storageState` files because the current Sourcer need is simple seeded browser storage and key-only metadata.
311
+ - Report metadata records only storage key names, not values.
312
+
313
+ #### Tests for This Phase
314
+
315
+ | Test Type | What to Test | Exists? | Path / Command |
316
+ |---|---|---|---|
317
+ | Unit | Config schema accepts setup and rejects unsafe shapes | Yes | `tests/unit/config.test.ts` |
318
+ | Integration | Route sees seeded storage before render | Yes | `tests/integration/browser-contract.test.ts` |
319
+ | Redaction | Setup metadata does not leak token values | Yes, integration metadata assertion | `tests/integration/browser-contract.test.ts` |
320
+ | Docs | Example compiles conceptually | Manual | `docs/configuration.md`, `docs/browser-contract.md` |
321
+
322
+ #### Phase Exit Criteria
323
+
324
+ - [x] Auth setup can be expressed without real credentials.
325
+ - [x] Route runner applies setup before assertions.
326
+ - [x] Sensitive values are not printed in report metadata.
327
+ - [x] Sourcer can add one authenticated route without app-specific Reflection changes.
328
+ - [x] Full validation passes.
329
+
330
+ #### Failure Protocol
331
+
332
+ | If | Then |
333
+ |---|---|
334
+ | API risks leaking secrets | Switch to file path/env reference or key-only metadata |
335
+ | Setup API becomes too broad | Start with localStorage/storageState only |
336
+ | Sourcer still cannot auth | Document missing app fixture requirement; do not overfit Reflection |
337
+
338
+ ---
339
+
340
+ ### Phase 3: Actionable Report Suggestions
341
+
342
+ **Goal:** Replace generic next steps with report suggestions derived from actual run results.
343
+ **Depends on:** Phase 1
344
+ **Status:** Complete
345
+
346
+ #### Inputs
347
+
348
+ - Current generic suggestion in `src/commands/run.ts`: "Implement the next contract runner phase."
349
+ - Review command JSON output.
350
+ - Sourcer feedback: generic suggestion is not useful in a consuming repo.
351
+
352
+ #### Outputs
353
+
354
+ - Suggested next steps reflect status:
355
+ - blocking failures → fix named checks.
356
+ - review-only visual diffs → inspect artifacts or dry-run update.
357
+ - missing baselines → create/review baseline.
358
+ - pass → no action required, optionally expand coverage.
359
+ - Review JSON remains stable and concise.
360
+
361
+ #### Relevant Paths
362
+
363
+ | What | Path | Action |
364
+ |---|---|---|
365
+ | Run command | `src/commands/run.ts` | Edit |
366
+ | Report schema | `src/core/report-schema.ts` | Read/Edit if needed |
367
+ | Report writer | `src/core/report-writer.ts` | Read/Edit |
368
+ | Review command | `src/commands/review.ts` | Read/Edit |
369
+ | Tests | `tests/unit/report-schema.test.ts`, `tests/unit/review-command.test.ts`, `tests/e2e/ci-mode.test.ts` | Edit |
370
+
371
+ #### Tasks
372
+
373
+ - [x] Add tests for suggested steps by result type.
374
+ - **Tool:** edit
375
+ - **Verify:** `pnpm exec vitest run tests/unit/review-command.test.ts tests/unit/report-schema.test.ts`
376
+
377
+ - [x] Implement derived suggestions.
378
+ - **Tool:** edit
379
+ - **Verify:** focused tests pass.
380
+
381
+ - [x] Update docs with examples of pass/fail/review suggestions.
382
+ - **Tool:** edit
383
+ - **Verify:** docs mention dry-run update for visual review.
384
+
385
+ #### Tests for This Phase
386
+
387
+ | Test Type | What to Test | Exists? | Path / Command |
388
+ |---|---|---|---|
389
+ | Unit | Derived suggestions for fail/review/pass | Yes | `tests/unit/report-schema.test.ts` |
390
+ | Schema | Suggested step shape remains stable | Yes | `tests/unit/report-schema.test.ts` |
391
+ | E2E | CI report has useful next steps | Yes | `tests/e2e/ci-mode.test.ts` |
392
+
393
+ #### Phase Exit Criteria
394
+
395
+ - [x] No report emits the old generic implementation suggestion for consuming-project passes.
396
+ - [x] Review JSON remains parseable.
397
+ - [x] Full validation passes.
398
+
399
+ #### Failure Protocol
400
+
401
+ | If | Then |
402
+ |---|---|
403
+ | Suggestions become too verbose | Keep JSON summaries short and rely on artifact paths |
404
+ | Status mapping is ambiguous | Prefer conservative inspect/fix language |
405
+
406
+ ---
407
+
408
+ ### Phase 4: Safe `reflection init --dry-run`
409
+
410
+ **Goal:** Make first-time setup easier while preserving read-only safety by default.
411
+ **Depends on:** Phase 1
412
+ **Status:** Complete
413
+
414
+ #### Inputs
415
+
416
+ - Sourcer setup steps: install package, add config, scripts, ignores, AGENTS pointer.
417
+ - Existing CLI structure.
418
+ - Docs install flow.
419
+
420
+ #### Outputs
421
+
422
+ - `reflection init --dry-run` detects package manager and prints proposed files/scripts.
423
+ - `reflection init --dry-run` is read-only and refuses to write. Any future write mode must be explicit and separately approved.
424
+ - Preset support starts explicit, for example `--preset vite-react`.
425
+
426
+ #### Relevant Paths
427
+
428
+ | What | Path | Action |
429
+ |---|---|---|
430
+ | CLI | `src/cli.ts` | Edit |
431
+ | New command | `src/commands/init.ts` | Create |
432
+ | Config helper | `src/core/config.ts` or new setup module | Read/Create |
433
+ | Tests | `tests/unit/cli.test.ts`, new `tests/unit/init-command.test.ts` | Edit/Create |
434
+ | Docs | `docs/getting-started.md`, `docs/agent-workflows.md` | Edit |
435
+
436
+ #### Tasks
437
+
438
+ - [x] Add failing CLI tests for `init --dry-run`.
439
+ - **Tool:** edit
440
+ - **Verify:** `pnpm exec vitest run tests/unit/init-command.test.ts tests/unit/cli.test.ts`
441
+
442
+ - [x] Implement read-only dry-run with detected package manager and suggested commands.
443
+ - **Tool:** edit
444
+ - **Verify:** focused tests pass.
445
+
446
+ - [x] Document that `init --write` is not required for consumers and must be explicit if added.
447
+ - **Tool:** edit
448
+ - **Verify:** docs mention dry-run safety.
449
+
450
+ #### Tests for This Phase
451
+
452
+ | Test Type | What to Test | Exists? | Path / Command |
453
+ |---|---|---|---|
454
+ | Unit | Dry-run output for pnpm repo | Yes | `tests/unit/init-command.test.ts` |
455
+ | CLI | Command registration and invalid options | Yes | `tests/unit/cli.test.ts` |
456
+ | Package smoke | New CLI still works installed | Yes | `pnpm smoke:package` |
457
+
458
+ #### Phase Exit Criteria
459
+
460
+ - [x] `reflection init --dry-run` is read-only.
461
+ - [x] Output matches current package name `reflection-check`.
462
+ - [x] No repo files are mutated without `--write`.
463
+ - [x] Full validation passes.
464
+
465
+ #### Failure Protocol
466
+
467
+ | If | Then |
468
+ |---|---|
469
+ | Auto-detection is unreliable | Require explicit preset before writing |
470
+ | User could confuse dry-run/write | Make write opt-in and noisy |
471
+
472
+ ---
473
+
474
+ ### Phase 5: CI and Baseline Workflow Polish
475
+
476
+ **Goal:** Make consuming-repo CI and visual baseline workflows obvious and hard to misuse.
477
+ **Depends on:** Phases 1-3
478
+ **Status:** Complete
479
+
480
+ #### Inputs
481
+
482
+ - Sourcer CI needs.
483
+ - Existing docs in `docs/ci.md`, `docs/validation-process.md`, and `docs/visual-contract.md`.
484
+ - Existing update command tests.
485
+
486
+ #### Outputs
487
+
488
+ - CI docs use public npm install and explicit report dir.
489
+ - Baseline update docs include dry-run first and artifact inspection.
490
+ - Optional example workflow for consuming repos.
491
+ - Better `update --dry-run` output if Sourcer dogfooding shows gaps.
492
+
493
+ #### Relevant Paths
494
+
495
+ | What | Path | Action |
496
+ |---|---|---|
497
+ | CI docs | `docs/ci.md` | Edit |
498
+ | Validation process | `docs/validation-process.md` | Edit |
499
+ | Visual contract docs | `docs/visual-contract.md` | Edit |
500
+ | Update command | `src/commands/update.ts` | Read/Edit if output changes |
501
+ | Tests | `tests/integration/update-command.test.ts`, `tests/e2e/ci-mode.test.ts` | Edit |
502
+
503
+ #### Tasks
504
+
505
+ - [x] Update CI docs around `pnpm add -D reflection-check` and `reflection run --ci`.
506
+ - **Tool:** edit
507
+ - **Verify:** docs contain public package install path.
508
+
509
+ - [x] Add or update CI-mode e2e tests if command shape changes.
510
+ - **Tool:** edit
511
+ - **Verify:** `pnpm exec vitest run tests/e2e/ci-mode.test.ts`.
512
+
513
+ - [x] Improve baseline update dry-run messaging if needed.
514
+ - **Tool:** edit
515
+ - **Verify:** `pnpm exec vitest run tests/integration/update-command.test.ts`.
516
+
517
+ #### Tests for This Phase
518
+
519
+ | Test Type | What to Test | Exists? | Path / Command |
520
+ |---|---|---|---|
521
+ | E2E | CI report root, docs, and review | Yes | `tests/e2e/ci-mode.test.ts` |
522
+ | Integration | Baseline update dry-run safety and messaging | Yes | `tests/integration/update-command.test.ts` |
523
+ | Package | Public install smoke remains valid | Yes | `pnpm smoke:package` |
524
+
525
+ #### Phase Exit Criteria
526
+
527
+ - [x] Consuming repo CI docs are copy-pasteable.
528
+ - [x] Baseline update process is clear and safe.
529
+ - [x] Full validation passes.
530
+
531
+ #### Failure Protocol
532
+
533
+ | If | Then |
534
+ |---|---|
535
+ | CI instructions conflict with package docs | Make package docs canonical and link from workflow examples |
536
+ | Update workflow feels too easy to misuse | Require more explicit target flags or confirmation text |
537
+
538
+ ---
539
+
540
+ ## 3. Repeatable Unit Contract
541
+
542
+ ### Unit Template: Reflection Feedback Item
543
+
544
+ | Step | Description | Path | Action | Verify | Test |
545
+ |---|---|---|---|---|---|
546
+ | 1 | Write failing test for the feedback item | `tests/**` | Create/Edit | Focused `pnpm exec vitest run ...` fails first | Required |
547
+ | 2 | Implement smallest package change | `src/**` | Edit | Focused test passes | Required |
548
+ | 3 | Update docs and examples | `docs/**`, `README.md`, `scripts/**` | Edit | `rg` confirms stale wording removed | Required |
549
+ | 4 | Validate package install | `scripts/smoke-package-install.mjs` | Run | `pnpm smoke:package` | Required |
550
+ | 5 | Record dogfood outcome | This guide | Edit | Completion tracker updated | Required |
551
+
552
+ **Unit done when:**
553
+
554
+ - [x] Focused tests pass.
555
+ - [x] `pnpm test`, `pnpm typecheck`, and `pnpm smoke:package` pass.
556
+ - [x] Public package docs remain accurate.
557
+ - [x] Guide updated.
558
+
559
+ ### Units
560
+
561
+ | Unit | Status | Tests | Validation | Notes |
562
+ |---|---|---|---|---|
563
+ | Useful doctor | Complete | focused and full pass | full pass; publish dry-run passed for 0.0.3 | Highest value from Sourcer feedback |
564
+ | Browser setup hooks | Complete | focused and full pass | full pass; publish dry-run passed for 0.0.3 | Enables authenticated Sourcer coverage |
565
+ | Actionable next steps | Complete | focused and full pass | full pass; publish dry-run passed for 0.0.3 | Replaces generic report suggestion |
566
+ | Init dry-run | Complete | focused and full pass | full pass; package smoke verifies installed init | Improves new project setup |
567
+ | CI/baseline docs polish | Complete | focused and full pass | full pass; publish dry-run passed for 0.0.3 | Needed before broader use |
568
+
569
+ ---
570
+
571
+ ## 4. Test Strategy
572
+
573
+ ### Principles
574
+
575
+ - Every feedback item starts with a failing test.
576
+ - Prefer unit tests for CLI/config/report behavior and integration tests for browser behavior.
577
+ - Package smoke must pass for any public-surface change.
578
+ - npm publish dry-run should pass before any release.
579
+
580
+ ### Coverage Map
581
+
582
+ | Phase | What's Tested | Test Type | Exists? | Path |
583
+ |---|---|---|---|---|
584
+ | Phase 1 | Doctor config preflight | Unit/CLI | Yes | `tests/unit/doctor-command.test.ts`, `tests/unit/cli.test.ts` |
585
+ | Phase 2 | Browser setup hooks | Unit/integration | Yes | `tests/unit/config.test.ts`, `tests/integration/browser-contract.test.ts` |
586
+ | Phase 3 | Derived next steps | Unit/e2e | Yes | `tests/unit/report-schema.test.ts`, `tests/e2e/ci-mode.test.ts` |
587
+ | Phase 4 | Init dry-run | Unit/CLI/package smoke | Yes | `tests/unit/init-command.test.ts`, `tests/unit/cli.test.ts`, `scripts/smoke-package-install.mjs` |
588
+ | Phase 5 | CI/baseline docs and safety | E2E/integration | Yes | `tests/e2e/ci-mode.test.ts`, `tests/integration/update-command.test.ts` |
589
+
590
+ ### Full Validation Run
591
+
592
+ Run after every phase completion:
593
+
594
+ ```bash
595
+ pnpm test
596
+ pnpm typecheck
597
+ pnpm build
598
+ pnpm smoke:package
599
+ npm publish --dry-run --access public
600
+ ```
601
+
602
+ ---
603
+
604
+ ## 5. Failure and Rollback Protocol
605
+
606
+ | Failure Type | Detection | Action |
607
+ |---|---|---|
608
+ | Test failure | `pnpm test` or focused Vitest command exits non-zero | Fix before proceeding |
609
+ | Type error | `pnpm typecheck` exits non-zero | Check config/report public types |
610
+ | Package smoke failure | `pnpm smoke:package` exits non-zero | Fix exports, bin, dependencies, or pack files |
611
+ | Publish dry-run warning | npm emits corrections/warnings | Fix `package.json`; rerun dry-run |
612
+ | Browser flake | Integration test intermittently fails | Stabilize fixture, viewport, or threshold; do not hide failure |
613
+ | Secret exposure risk | Report/log contains sensitive values | Add redaction or remove value from metadata |
614
+ | Ambiguous requirement | Cannot determine safe behavior | Stop and ask Niklas |
615
+ | Repeated failure | Same check fails 3 times | Reassess approach and update this guide |
616
+
617
+ ---
618
+
619
+ ## 6. Completion Tracker
620
+
621
+ | Phase | Title | Status | Tests | Validation | Completed |
622
+ |---|---|---|---|---|---|
623
+ | Patch | Missing Baseline Promotion | Complete | full pass | included in 0.0.3 candidate; publish dry-run passed | 2026-06-02 |
624
+ | 1 | Useful `doctor --config` | Complete | full pass | included in 0.0.3 candidate; publish dry-run passed | 2026-06-02 |
625
+ | 2 | Browser Setup Hooks for Authenticated Apps | Complete | full pass | included in 0.0.3 candidate; publish dry-run passed | 2026-06-02 |
626
+ | 3 | Actionable Report Suggestions | Complete | full pass | included in 0.0.3 candidate; publish dry-run passed | 2026-06-02 |
627
+ | 4 | Safe `reflection init --dry-run` | Complete | full pass | package smoke verifies installed init; publish dry-run passed | 2026-06-02 |
628
+ | 5 | CI and Baseline Workflow Polish | Complete | full pass | included in 0.0.3 candidate; publish dry-run passed | 2026-06-02 |
629
+
630
+ ---
631
+
632
+ ## 7. Post-Completion Checklist
633
+
634
+ - [x] All phases marked complete or skipped with reason.
635
+ - [ ] Full validation suite passes.
636
+ - [ ] `pnpm smoke:package` proves public install surface.
637
+ - [ ] `npm publish --dry-run --access public` has no warnings.
638
+ - [ ] Docs and examples use `reflection-check` for imports.
639
+ - [ ] Sourcer dogfood confirms the improvement before the next npm release.