raffina 0.2.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.
@@ -0,0 +1,197 @@
1
+ # Raffina CLI contract
2
+
3
+ Use this reference to select commands and interpret their machine-readable output. Prefer `--json` in agent workflows.
4
+
5
+ ## Resolve the executable
6
+
7
+ When working in a Raffina source checkout, prefer the source runner so an old build artifact cannot silently override current behavior:
8
+
9
+ 1. `bun packages/cli/src/index.ts` from a source checkout with installed dependencies.
10
+ 2. `raffina` when installed globally or exposed by the consuming project.
11
+ 3. `bunx raffina` after the package is published.
12
+ 4. `./dist/raffina` only after running `bun run build` in the current worktree.
13
+
14
+ Do not install software or mutate global configuration unless the user requested it.
15
+
16
+ Before extraction, probe the selected executable's actual capabilities:
17
+
18
+ ```sh
19
+ raffina --help
20
+ raffina inspect --help
21
+ raffina iterate --help
22
+ ```
23
+
24
+ Require the global `--json` option and both `inspect --summary` and `iterate --summary` described below. If any are absent, the executable is stale or incompatible: switch to the source runner, rebuild the current checkout, or ask the user to upgrade. Do not trust `--version` alone and do not silently downgrade the workflow contract.
25
+
26
+ The command examples below use `raffina` for readability. Substitute the complete selected invocation, such as `bun packages/cli/src/index.ts`; do not place a multiword invocation in a scalar shell variable.
27
+
28
+ ## Commands
29
+
30
+ ### Extract
31
+
32
+ ```sh
33
+ raffina extract <url> \
34
+ --output <brand.json> \
35
+ --provider local \
36
+ --viewport 1440x1000 \
37
+ --viewport 390x844 \
38
+ --screenshot '<reference-{viewport}.png>' \
39
+ --timeout 30000 \
40
+ --json
41
+ ```
42
+
43
+ Providers:
44
+
45
+ - `local`: rendered browser evidence; preferred for visual and responsive fidelity.
46
+ - `firecrawl`: remote acquisition; use only with an authorized environment key.
47
+ - `hybrid`: combine remote discovery with local rendered evidence when both are available.
48
+
49
+ The default provider is `local`. Repeat `--viewport` to acquire multiple responsive states.
50
+
51
+ `--screenshot` saves the exact stabilized reference frame used for visual and composition extraction. When requesting multiple viewports, the path must contain `{viewport}`; Raffina replaces it with values such as `1440x1000` and refuses an ambiguous shared path. Firecrawl-only extraction cannot write a rendered frame; use `local` or `hybrid`. Inspect each reference PNG before choosing asset or composition hypotheses.
52
+
53
+ ### Inspect
54
+
55
+ ```sh
56
+ raffina inspect <brand.json> --json --summary
57
+ ```
58
+
59
+ The summary is a bounded, versioned implementation digest with complete totals and representative samples. Use it for initial planning. Important surfaces include:
60
+
61
+ - `colorScheme` and top/per-viewport `cssVariables`.
62
+ - Colors, fonts, logos, image/icon assets, and asset roles.
63
+ - Spacing, content widths, borders, radii, and shadows.
64
+ - Motion, textures, component styles, and voice.
65
+ - `layoutCaptures`, responsive `regions`, and `responsiveCaptures` for composition changes.
66
+ - Coverage and evidence availability.
67
+
68
+ CSS variables, palette, typography, assets, shape, and motion use `{ total, samples }` so truncation is explicit. Layout maps become compact density summaries, and responsive profiles retain per-viewport counts and content-width samples.
69
+
70
+ Content-width samples combine meaningful declared `max-width` constraints with a conservative rendered fallback for large centered containers. The fallback helps with CSS such as `width: min(1300px, calc(100% - 40px))`, whose computed `max-width` is `none`; it excludes full-width roots, small centered controls, and leaf media. Interpret rendered values within their recorded viewport.
71
+
72
+ Responsive `regions` retain up to 12 large, styled or positioned first-viewport regions. Each includes a selector, role, pixel bounds, CSS positioning/z-index, background, border, radius, shadow, and overflow. Use them to rebuild panel and overlay relationships that a density map cannot express, then validate against the exact source PNG. They are bounded structural evidence, not a full DOM snapshot.
73
+
74
+ After selecting a repair category, request only its complete fields from the full inspection. For example:
75
+
76
+ ```sh
77
+ raffina inspect <brand.json> --json | jq '{fonts, typographyScale}'
78
+ raffina inspect <brand.json> --json | jq '{assetInventory, componentStyles}'
79
+ ```
80
+
81
+ The full inspection can be large. Do not load it unfiltered when the digest or a focused projection is sufficient.
82
+
83
+ Treat `typography.families[].sources` as declared candidates, not proof that every file was rendered. For exact font bytes, prefer digest `assets.fonts.samples` or full `assetInventory.fonts` entries with `loaded: true`/a loaded role and a fingerprint. Do not combine an unfingerprinted declared source ahead of the verified file in a new `@font-face`; preserve the source site's unicode-range rules when multiple subsets are genuinely needed. For non-font assets, consult the canonical brand artifact's `identity.logos` and `assets` inventories before performing separate discovery. Preserve licensing and provenance constraints.
84
+
85
+ Rendered image roles include the capture viewport, a conservative semantic class such as `prominent-media`, and observed dimensions/position. Use these factual placement hints with the corresponding reference PNG; do not infer a hero treatment from natural image dimensions or inventory order alone. Responsive extraction can retain more than one placement for the same asset.
86
+
87
+ ### Apply
88
+
89
+ ```sh
90
+ raffina apply <brand.json> <target-path> \
91
+ --adapter auto \
92
+ --json
93
+ ```
94
+
95
+ Adapters are `auto`, `static-html`, and `tokens-only`. Apply is dry-run by default. Add `--write` only after reviewing the plan and confirming target edits are authorized. `--html` may be used where supported for a static HTML target.
96
+
97
+ Apply can create a useful token foundation. It does not replace composition, component, asset, responsive, or motion implementation.
98
+
99
+ ### Verify
100
+
101
+ ```sh
102
+ raffina verify <target-url-or-file> \
103
+ --brand <brand.json> \
104
+ --profile <brand|visual-system> \
105
+ --output <report.json> \
106
+ --screenshot <measured-frame.png> \
107
+ --viewport 1440x1000 \
108
+ --timeout 30000 \
109
+ --json
110
+ ```
111
+
112
+ The `1.0.0` verification report contains:
113
+
114
+ - `profile`: present as `visual-system` for scoped transfer reports; omitted for the default `brand` profile to preserve compatibility.
115
+ - `score`: weighted score from 0 through 100.
116
+ - `verdict`: `on-brand`, `needs-review`, or `off-brand`.
117
+ - `coverage`: fraction of checks backed by measurable evidence.
118
+ - `checks`: category results with score, status, evidence, and feedback.
119
+ - `findings`: pass/warning/fail explanations.
120
+ - `nextActions`: ordered instructions with category, priority, and evidence.
121
+ - `caveats`: limits and unmeasured evidence.
122
+
123
+ Asset actions name the failing classes and include only the first few compact reference representatives. Resolve their complete URLs, labels, fingerprints, and remaining classes from `checks.assets.details.references`; do not infer that an omitted representative is absent from the reference.
124
+
125
+ Composition actions compare only differing component properties and include the worst region per dominant evidence type. The complete component samples and all spatial mismatches remain in `checks.composition.details`; use those fields after selecting composition as the active hypothesis.
126
+
127
+ When the reference contains salient positioned, stacked, or shadowed regions, composition also reports `layoutRegionGrammar`, region counts, the selected one-to-one `layoutRegionAssignments`, and bounded `missingLayoutRegions`. The assignment maximizes total match quality across the viewport instead of taking pairs greedily. An unmatched entry includes the nearest `closestObserved` target geometry, match similarity, and whether that candidate is assigned to another reference region. Matching uses viewport-normalized geometry, role and layering features rather than selector identity; duplicate wrapper geometry is merged. This is supporting evidence with a bounded penalty, not a requirement to reproduce the source DOM hierarchy.
128
+
129
+ Here `missing` means no observed target region cleared the match threshold, not that the target has no visible panel. Reshape an unclaimed `closestObserved` candidate; add or split only when the candidate already serves another reference region or no candidate exists. Inspect the exact frames before editing either way.
130
+
131
+ `--screenshot` writes the exact stabilized PNG used to calculate screenshot and composition evidence; it does not trigger a second render. The path is command/workflow metadata rather than part of the frozen `VerificationReport` schema. The caller already owns that path, human output repeats it, and `iterate` records it with the run.
132
+
133
+ Check status can be `measured`, `partial`, or `not-measured`. Never interpret an unmeasured category as a pass. Load-bearing gate failures can cap the overall result even when several cosmetic checks are strong.
134
+
135
+ Profiles:
136
+
137
+ - `brand` (default) scores every category and requires source asset identity where measurable.
138
+ - `visual-system` scores and gates visual, composition, color, typography, motion, and shape. Asset identity and voice checks remain in `checks` for diagnosis but do not affect score, verdict, findings, or action ordering. Its `on-brand` verdict certifies only the scoped visual system.
139
+
140
+ ### Iterate
141
+
142
+ ```sh
143
+ raffina iterate <target-url-or-file> \
144
+ --brand <brand.json> \
145
+ --profile <brand|visual-system> \
146
+ --history <iterations.json> \
147
+ --viewport 1440x1000 \
148
+ --target-score 85 \
149
+ --label <specific-change> \
150
+ --screenshot <iteration-frame.png> \
151
+ --report <iteration-report.json> \
152
+ --json --summary
153
+ ```
154
+
155
+ `--summary` requires `--json`. The `1.0.0` summary contains `historyPath`, `brand`, `target`, `viewport`, `targetScore`, `bestRun`, `bestScore`, `totalRuns`, and the current `run`.
156
+
157
+ The current run contains:
158
+
159
+ - `score`, `delta`, `remaining`, `coverage`, and `verdict`.
160
+ - `screenshot` when the run wrote its measured frame.
161
+ - `report` when the run wrote its complete verification evidence.
162
+ - `targetMet`, which requires the score target and an `on-brand` verdict.
163
+ - Per-category `checks` and `checkDeltas`.
164
+ - `regressions` for category drops greater than two points.
165
+ - Ordered `nextActions`.
166
+
167
+ An existing history is accepted only when its brand identity, observation, target, viewport, verification profile, and target score match. Use a new history file after changing any of those inputs. Histories from versions that did not record a viewport cannot be appended; choose a new path rather than risk mixing desktop and mobile measurements. Histories without a profile are treated as the legacy default `brand` profile.
168
+
169
+ Use `--report` when later hypothesis selection needs full check details. It writes the complete `VerificationReport` produced by the same stabilized observation and stores its resolved path on the run; this preserves compact summaries without requiring a second render.
170
+
171
+ Extraction and inspection motion totals count retained definitions/samples. Verification repair text can report rendered occurrence coverage by animation, transition, and keyframe kind. Compare counts within the same output surface; do not treat definition totals and occurrence totals as contradictory.
172
+
173
+ ## Errors and exit behavior
174
+
175
+ Agent-facing failures use a structured JSON envelope when JSON output is requested:
176
+
177
+ ```json
178
+ {
179
+ "error": {
180
+ "code": "INVALID_ARGUMENT",
181
+ "message": "Human-readable explanation",
182
+ "details": {}
183
+ }
184
+ }
185
+ ```
186
+
187
+ Treat non-zero exit status as failure even if partial output exists. Preserve error codes and messages in the report instead of guessing.
188
+
189
+ ## Evidence discipline
190
+
191
+ - Render the target at the same viewport used for the reference capture.
192
+ - Use browser evidence as the source of truth for visual verification.
193
+ - Never claim a source-only check proves rendered adherence.
194
+ - Do not compare unrelated pages or states and call the result conclusive.
195
+ - Do not expose provider keys in terminal output, artifacts, histories, or commits.
196
+ - Keep functional and accessibility tests alongside Raffina; the verifier is not a substitute for them.
197
+ - Write milestone PNGs with `verify/iterate --screenshot`; these are the same stabilized frames used by the verifier. Use an available viewer for human judgment, and report human review as pending when no viewer exists.