@mushi-mushi/ux 0.2.1 → 0.3.1

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.
package/dist/index.d.ts CHANGED
@@ -111,10 +111,25 @@ declare function cursorCloudAdapter(deps?: CursorCloudDeps): AgentAdapter;
111
111
  *
112
112
  * WebSockets are not routed: a Supabase Realtime socket only subscribes, and
113
113
  * table writes go through REST, which the route sees.
114
+ *
115
+ * Fresh-eyes runs (ADR 0053) may write, but only on the app's own origins
116
+ * (`writes: 'same-origin'`). In every mode, a request is refused when it would
117
+ * pay, sign in with a third party, or create an account through a public
118
+ * sign-up endpoint: those never reach the network, whatever the allowlist.
114
119
  */
115
120
 
116
121
  /** `"POST /rest/v1/rpc/*"`, or a bare path glob meaning any method. */
117
122
  type AllowRule = string;
123
+ /**
124
+ * read-only (the default): every write is aborted unless the allowlist names it.
125
+ * same-origin (fresh-eyes, ADR 0053): writes may also reach `appOrigins`.
126
+ */
127
+ type WriteMode = 'read-only' | 'same-origin';
128
+ interface GuardPolicy {
129
+ writes?: WriteMode;
130
+ /** The app's own origins (`https://app.example.com`), with writes: 'same-origin'. */
131
+ appOrigins?: readonly string[];
132
+ }
118
133
  interface GuardLog {
119
134
  blocked: Array<{
120
135
  method: string;
@@ -122,10 +137,10 @@ interface GuardLog {
122
137
  }>;
123
138
  }
124
139
  /** Pure decision, exported for tests: may this request leave the browser? */
125
- declare function isRequestAllowed(method: string, url: string, allow: readonly AllowRule[]): boolean;
140
+ declare function isRequestAllowed(method: string, url: string, allow: readonly AllowRule[], policy?: GuardPolicy, isNavigation?: boolean): boolean;
126
141
  /** Pure: should discovery refuse to click an element with this label? */
127
142
  declare function isDestructiveLabel(label: string): boolean;
128
- declare function installGuard(context: BrowserContext, allow: readonly AllowRule[], log?: GuardLog): Promise<GuardLog>;
143
+ declare function installGuard(context: BrowserContext, allow: readonly AllowRule[], log?: GuardLog, policy?: GuardPolicy): Promise<GuardLog>;
129
144
 
130
145
  /**
131
146
  * Shared shapes for the UX loop: a surface is one screen state worth
@@ -240,6 +255,8 @@ interface SessionOptions {
240
255
  allow?: readonly AllowRule[];
241
256
  /** Extra selectors to ignore on top of DEFAULT_IGNORE. */
242
257
  ignore?: readonly string[];
258
+ /** Write policy (guard.ts). Default read-only; fresh-eyes runs may write to the app's own origins (ADR 0053). */
259
+ policy?: GuardPolicy;
243
260
  }
244
261
  declare function openSession(opts?: SessionOptions): Promise<BrowserSession>;
245
262
  /**
@@ -338,6 +355,9 @@ declare function discover(session: BrowserSession, opts: DiscoverOptions): Promi
338
355
  * PNG helpers: decode, pad two captures to one size, pixel diff, and a
339
356
  * difference hash (dHash) for "is this the same screen" checks. No native
340
357
  * image library, so the package installs anywhere Node does.
358
+ *
359
+ * Diffs go through pixelmatch 8 (OKLab HyAB). Threshold 0.1 is still a tenth
360
+ * of black versus white, the same scale as v7, so it is not retuned.
341
361
  */
342
362
  interface PixelDiff {
343
363
  /** Share of pixels that differ, 0..1, over the larger of the two sizes. */
@@ -362,6 +382,7 @@ interface ChangeRegion {
362
382
  w: number;
363
383
  h: number;
364
384
  }
385
+ /** `threshold` is the per-pixel OKLab distance, 0..1 (1 = black vs white). Default 0.1. */
365
386
  declare function pixelDiff(before: Buffer, after: Buffer, threshold?: number): PixelDiff;
366
387
  /**
367
388
  * Keep the top `maxHeight` px of a capture. Full-page shots of long pages
@@ -420,6 +441,131 @@ interface CheckerVerdict {
420
441
  error?: string;
421
442
  }
422
443
 
444
+ /**
445
+ * Final review by a different model: for each screen the loop changed, one
446
+ * pairwise comparison of the original against the kept version, per
447
+ * viewport, grounded in the repo's design tokens and the measured probe
448
+ * deltas.
449
+ *
450
+ * Why pairwise and evidence-bound: open-ended screenshot critique is mostly
451
+ * wrong (Baymard measured an 80% error rate for GPT-4 UX audits; UICrit found
452
+ * 13% of zero-shot critiques valid). Asking "which is better, and point at
453
+ * where" is a narrower question, every claim must carry a bounding box, and
454
+ * the two images are shown in random order so the model cannot learn that
455
+ * "the second one is the new one".
456
+ *
457
+ * The judge advises; it never reverts or keeps anything. Runs on the
458
+ * person's own Anthropic credentials.
459
+ */
460
+
461
+ declare const DEFAULT_JUDGE_MODEL = "claude-opus-5-5";
462
+ declare const JudgeOutput: z.ZodObject<{
463
+ preferred: z.ZodEnum<{
464
+ A: "A";
465
+ tie: "tie";
466
+ B: "B";
467
+ }>;
468
+ confidence: z.ZodEnum<{
469
+ low: "low";
470
+ medium: "medium";
471
+ high: "high";
472
+ }>;
473
+ summary: z.ZodString;
474
+ better: z.ZodArray<z.ZodObject<{
475
+ image: z.ZodEnum<{
476
+ A: "A";
477
+ B: "B";
478
+ }>;
479
+ box: z.ZodObject<{
480
+ x: z.ZodNumber;
481
+ y: z.ZodNumber;
482
+ width: z.ZodNumber;
483
+ height: z.ZodNumber;
484
+ }, z.core.$strip>;
485
+ what: z.ZodString;
486
+ why: z.ZodString;
487
+ }, z.core.$strip>>;
488
+ worse: z.ZodArray<z.ZodObject<{
489
+ image: z.ZodEnum<{
490
+ A: "A";
491
+ B: "B";
492
+ }>;
493
+ box: z.ZodObject<{
494
+ x: z.ZodNumber;
495
+ y: z.ZodNumber;
496
+ width: z.ZodNumber;
497
+ height: z.ZodNumber;
498
+ }, z.core.$strip>;
499
+ what: z.ZodString;
500
+ why: z.ZodString;
501
+ }, z.core.$strip>>;
502
+ design_system_breaks: z.ZodArray<z.ZodObject<{
503
+ image: z.ZodEnum<{
504
+ A: "A";
505
+ B: "B";
506
+ }>;
507
+ box: z.ZodObject<{
508
+ x: z.ZodNumber;
509
+ y: z.ZodNumber;
510
+ width: z.ZodNumber;
511
+ height: z.ZodNumber;
512
+ }, z.core.$strip>;
513
+ what: z.ZodString;
514
+ why: z.ZodString;
515
+ token_or_rule: z.ZodString;
516
+ }, z.core.$strip>>;
517
+ }, z.core.$strip>;
518
+ type JudgeOutputT = z.infer<typeof JudgeOutput>;
519
+ interface JudgeClaim {
520
+ /** Which capture the claim points at, after un-shuffling. */
521
+ image: 'before' | 'after';
522
+ box: {
523
+ x: number;
524
+ y: number;
525
+ width: number;
526
+ height: number;
527
+ };
528
+ what: string;
529
+ why: string;
530
+ tokenOrRule?: string;
531
+ }
532
+ interface JudgeVerdict {
533
+ viewport: string;
534
+ model: string;
535
+ preferred: 'before' | 'after' | 'tie';
536
+ confidence: 'low' | 'medium' | 'high';
537
+ summary: string;
538
+ better: JudgeClaim[];
539
+ worse: JudgeClaim[];
540
+ designBreaks: JudgeClaim[];
541
+ /** Claims dropped because their box fell outside the image. */
542
+ droppedClaims: number;
543
+ /** Set when the model declined or the call failed; no verdict then. */
544
+ error?: string;
545
+ }
546
+ interface JudgeOptions {
547
+ dir: string;
548
+ repoRoot: string;
549
+ designFiles: string[];
550
+ model?: string;
551
+ client?: Anthropic;
552
+ /** Deterministic order for tests; defaults to Math.random. */
553
+ random?: () => number;
554
+ }
555
+ /** Pure: map the shuffled A/B answer back to before/after and drop out-of-image claims. */
556
+ declare function unshuffle(out: JudgeOutputT, aIsBefore: boolean, sizes: {
557
+ A: {
558
+ width: number;
559
+ height: number;
560
+ };
561
+ B: {
562
+ width: number;
563
+ height: number;
564
+ };
565
+ }, viewport: string, model: string): JudgeVerdict;
566
+ /** Judge one screen at one viewport: its baseline against its last kept capture. */
567
+ declare function judgeSurface(s: SurfaceState, viewport: string, opts: JudgeOptions): Promise<JudgeVerdict | null>;
568
+
423
569
  /**
424
570
  * A finished run's pull request. The studio's "Open draft PR" pushes the run
425
571
  * branch and opens a draft PR into the default branch, or, when the run
@@ -607,130 +753,481 @@ declare function newRunId(now?: Date): string;
607
753
  declare function saveState(dir: string, state: RunState): void;
608
754
  declare function loadState(dir: string): RunState | null;
609
755
 
756
+ interface SyncConfig {
757
+ apiKey: string;
758
+ projectId: string;
759
+ endpoint: string;
760
+ /** 'cloud' when the run executes on the host's CI rather than a laptop. */
761
+ mode: 'local' | 'cloud';
762
+ }
763
+ declare function syncConfigFromEnv(env?: NodeJS.ProcessEnv): SyncConfig | null;
764
+ /** Pure, for tests: the PUT body for one run state. `uploaded` maps upload name → the file it came from. */
765
+ declare function toSnapshot(state: RunState, finished: boolean, uploaded: ReadonlyMap<string, string>, mode?: SyncConfig['mode']): {
766
+ started_at: string;
767
+ finished_at: string | null;
768
+ surfaces: {
769
+ surface_key: string;
770
+ kind: SurfaceKind;
771
+ path: string;
772
+ label: string;
773
+ status: SurfaceStatus;
774
+ note: string | null;
775
+ plan: {
776
+ text: string;
777
+ status: "done" | "pending" | "skipped" | "failed";
778
+ attempt: number | null;
779
+ }[] | null;
780
+ penalty_before: number | null;
781
+ penalty_after: number | null;
782
+ probe_before: {
783
+ axe: {
784
+ id: string;
785
+ impact: string | null;
786
+ help: string;
787
+ count: number;
788
+ }[];
789
+ overflowX: boolean;
790
+ smallTargets: number;
791
+ consoleErrors: number;
792
+ cls: number;
793
+ } | null;
794
+ probe_after: {
795
+ axe: {
796
+ id: string;
797
+ impact: string | null;
798
+ help: string;
799
+ count: number;
800
+ }[];
801
+ overflowX: boolean;
802
+ smallTargets: number;
803
+ consoleErrors: number;
804
+ cls: number;
805
+ } | null;
806
+ judge: {
807
+ error?: string | undefined;
808
+ viewport: string;
809
+ model: string;
810
+ preferred: "before" | "after" | "tie";
811
+ confidence: "low" | "medium" | "high";
812
+ summary: string;
813
+ better: {
814
+ what: string;
815
+ why: string;
816
+ }[];
817
+ worse: {
818
+ what: string;
819
+ why: string;
820
+ }[];
821
+ }[] | null;
822
+ thumbs: {
823
+ before: string;
824
+ after: string;
825
+ diff: string;
826
+ };
827
+ shots: Record<string, string>;
828
+ iterations: {
829
+ n: number;
830
+ agent: string;
831
+ model: string | null;
832
+ duration_ms: number;
833
+ outcome: "accepted" | "rejected" | "agent_failed" | "capture_failed" | "no_change";
834
+ reason: string;
835
+ commit_sha: string | null;
836
+ pixel_diff: Record<string, number>;
837
+ penalty_after: number | null;
838
+ steps: string | null;
839
+ step: string | null;
840
+ shots: Record<string, string>;
841
+ }[];
842
+ }[];
843
+ pr?: {
844
+ url: string;
845
+ number: number;
846
+ } | undefined;
847
+ mode: "local" | "cloud";
848
+ status: string;
849
+ agent: string;
850
+ model: string | null;
851
+ judge_model: string | null;
852
+ skill: string | null;
853
+ base_ref: string | null;
854
+ phase: RunPhase | null;
855
+ phase_detail: string | null;
856
+ current_surface: string | null;
857
+ current_attempt: number | null;
858
+ current_progress: {
859
+ steps: number;
860
+ last_step: string | null;
861
+ files: string[];
862
+ started_at: string;
863
+ timeout_ms: number | null;
864
+ } | null;
865
+ error: string | null;
866
+ branch: string | null;
867
+ base_sha: string | null;
868
+ cli_version: null;
869
+ };
870
+ interface SyncHandle {
871
+ /** Final sync; resolves with an error message when it did not land. */
872
+ finish(): Promise<string | null>;
873
+ }
874
+ declare function startSync(dir: string, cfg: SyncConfig, events: EventEmitter, log: (m: string) => void): SyncHandle;
875
+
610
876
  /**
611
- * Final review by a different model: for each screen the loop changed, one
612
- * pairwise comparison of the original against the kept version, per
613
- * viewport, grounded in the repo's design tokens and the measured probe
614
- * deltas.
877
+ * `mushi-ux audit`: find UI/UX bugs on the signed-in screens of a live app
878
+ * and file each one as a Mushi report, so the fix loop picks it up (ADR 0045).
615
879
  *
616
- * Why pairwise and evidence-bound: open-ended screenshot critique is mostly
617
- * wrong (Baymard measured an 80% error rate for GPT-4 UX audits; UICrit found
618
- * 13% of zero-shot critiques valid). Asking "which is better, and point at
619
- * where" is a narrower question, every claim must carry a bounding box, and
620
- * the two images are shown in random order so the model cannot learn that
621
- * "the second one is the new one".
880
+ * - The session is a cached, signed-in browser profile (`--profile-dir`),
881
+ * never a fresh browser that needs a new sign-in.
882
+ * - Read-only: discovery and captures run behind the write guard (guard.ts).
883
+ * - Facts first (ADR 0039): serious axe violations, sideways scrolling,
884
+ * console errors and layout shift come from measurements. A model review of
885
+ * the screenshots is optional and only adds concrete visual defects with an
886
+ * element and a "Done when"; taste notes are dropped.
887
+ * - Filing is deduped by a fingerprint per (screen, kind, rule): a ledger on
888
+ * this machine plus a marker in the report description that the reports
889
+ * search finds, so an open report is never filed twice.
890
+ */
891
+
892
+ /** @internal Exported for tests only. */
893
+ type FindingKind = 'axe' | 'overflow' | 'layout' | 'console' | 'cls' | 'visual' | 'explore' | 'fresh-eyes';
894
+ type FindingSeverity = 'high' | 'medium' | 'low';
895
+ interface AuditFinding {
896
+ /** sha1 of (path, screen key, kind, rule), 16 hex. */
897
+ fingerprint: string;
898
+ kind: FindingKind;
899
+ /** axe rule id, 'horizontal-overflow', 'console-error', 'layout-shift', or the visual defect kind. */
900
+ rule: string;
901
+ severity: FindingSeverity;
902
+ path: string;
903
+ screen: string;
904
+ viewports: Viewport['name'][];
905
+ summary: string;
906
+ evidence: string[];
907
+ expected: string;
908
+ doneWhen: string;
909
+ /** The report's footer line; default: the read-only audit. */
910
+ foundBy?: string;
911
+ }
912
+
913
+ /**
914
+ * Explore mode (`mushi-ux explore`, ADR 0046): a cheap model (Grok through
915
+ * the Cursor CLI by default) drives a signed-in, read-only browser like a
916
+ * curious or careless user, and code decides what is a bug.
622
917
  *
623
- * The judge advises; it never reverts or keeps anything. Runs on the
624
- * person's own Anthropic credentials.
918
+ * - The model only picks the next action from the page's accessibility
919
+ * snapshot and a charter (forms, navigation, stress, filters). It never
920
+ * judges: a finding is a console error, an uncaught page error, a 5xx, or a
921
+ * blank screen, caught by listeners ("the agent navigates, code judges").
922
+ * - Safety is the audit's: the guard aborts every request that is not GET,
923
+ * HEAD or OPTIONS (bar the allowlist), cancels form submits and blocks
924
+ * service workers (guard.ts), and no element whose label reads as
925
+ * destructive is touched.
926
+ * - A candidate is filed only when replaying its last steps from a fresh page,
927
+ * with no model, shows the same signal again (the site-watch rule, ADR
928
+ * 0029): one flaky load is not a bug.
929
+ * - Bounded: steps per session, sessions per run, a time box per model call.
625
930
  */
626
931
 
627
- declare const DEFAULT_JUDGE_MODEL = "claude-opus-5-5";
628
- declare const JudgeOutput: z.ZodObject<{
629
- preferred: z.ZodEnum<{
630
- A: "A";
631
- tie: "tie";
632
- B: "B";
633
- }>;
634
- confidence: z.ZodEnum<{
635
- low: "low";
636
- medium: "medium";
637
- high: "high";
638
- }>;
639
- summary: z.ZodString;
640
- better: z.ZodArray<z.ZodObject<{
641
- image: z.ZodEnum<{
642
- A: "A";
643
- B: "B";
644
- }>;
645
- box: z.ZodObject<{
646
- x: z.ZodNumber;
647
- y: z.ZodNumber;
648
- width: z.ZodNumber;
649
- height: z.ZodNumber;
650
- }, z.core.$strip>;
651
- what: z.ZodString;
652
- why: z.ZodString;
653
- }, z.core.$strip>>;
654
- worse: z.ZodArray<z.ZodObject<{
655
- image: z.ZodEnum<{
656
- A: "A";
657
- B: "B";
658
- }>;
659
- box: z.ZodObject<{
660
- x: z.ZodNumber;
661
- y: z.ZodNumber;
662
- width: z.ZodNumber;
663
- height: z.ZodNumber;
664
- }, z.core.$strip>;
665
- what: z.ZodString;
666
- why: z.ZodString;
667
- }, z.core.$strip>>;
668
- design_system_breaks: z.ZodArray<z.ZodObject<{
669
- image: z.ZodEnum<{
670
- A: "A";
671
- B: "B";
672
- }>;
673
- box: z.ZodObject<{
674
- x: z.ZodNumber;
675
- y: z.ZodNumber;
676
- width: z.ZodNumber;
677
- height: z.ZodNumber;
678
- }, z.core.$strip>;
679
- what: z.ZodString;
680
- why: z.ZodString;
681
- token_or_rule: z.ZodString;
682
- }, z.core.$strip>>;
683
- }, z.core.$strip>;
684
- type JudgeOutputT = z.infer<typeof JudgeOutput>;
685
- interface JudgeClaim {
686
- /** Which capture the claim points at, after un-shuffling. */
687
- image: 'before' | 'after';
688
- box: {
689
- x: number;
690
- y: number;
691
- width: number;
692
- height: number;
693
- };
694
- what: string;
932
+ /** One action from the closed set (explore and fresh-eyes). */
933
+ type ExploreAction = {
934
+ action: 'click';
935
+ role: string;
936
+ name: string;
937
+ } | {
938
+ action: 'fill';
939
+ role: string;
940
+ name: string;
941
+ value: string;
942
+ } | {
943
+ action: 'press';
944
+ key: string;
945
+ } | {
946
+ action: 'select';
947
+ role: string;
948
+ name: string;
949
+ value: string;
950
+ } | {
951
+ action: 'back' | 'forward' | 'reload' | 'scroll' | 'done';
952
+ } | {
953
+ action: 'resize';
954
+ width: number;
955
+ height: number;
956
+ };
957
+ /** Something the page did that code counts as a bug candidate. */
958
+ interface Signal {
959
+ kind: 'console-error' | 'page-error' | 'server-error' | 'blank-screen';
960
+ message: string;
961
+ url: string;
962
+ }
963
+
964
+ /**
965
+ * Fresh-eyes runs (`mushi-ux fresh-eyes`, ADR 0053): a model plays someone
966
+ * who has never seen the product and tries one goal ("get my first bug
967
+ * explained") from the landing page, signed out, while code measures the path.
968
+ *
969
+ * - The model only picks the next action from the page's accessibility
970
+ * snapshot (explore's closed action set, plus "stuck"), and may say a screen
971
+ * confused it from a closed list. It never sees the source or the docs: each
972
+ * call runs the Cursor CLI in ask mode in an empty folder holding one prompt.
973
+ * - Code decides everything else: whether the goal is reached (a declared
974
+ * check, never the model's "done"), how long the app made the visitor wait,
975
+ * dead ends, backtracks, errors, steps that need something outside the app
976
+ * (an inbox, an API key, a terminal, a third-party account), captchas and
977
+ * sign-up walls.
978
+ * - Writes reach only the app's own origins, and only with a synthetic identity
979
+ * the model types as placeholders (`{{email}}`); code substitutes the values,
980
+ * and they never reach a prompt, the timeline or the console. Payments,
981
+ * third-party sign-in and public sign-up endpoints are refused (guard.ts).
982
+ * - Findings: measured page facts are filed once a model-free replay shows them
983
+ * again; opinions only when at least 2 sessions agree on the screen.
984
+ */
985
+
986
+ type FreshAction = Exclude<ExploreAction, {
987
+ action: 'resize';
988
+ }> | {
989
+ action: 'stuck';
990
+ reason: string;
991
+ };
992
+ /** What a screen made the visitor feel, from a closed list. `gave_up` is added by code when the model stops with no measured cause. */
993
+ declare const OPINION_CATEGORIES: readonly ["confusing", "unclear_copy", "too_many_choices"];
994
+ type OpinionCategory = (typeof OPINION_CATEGORIES)[number] | 'gave_up';
995
+ interface Opinion {
996
+ category: OpinionCategory;
695
997
  why: string;
696
- tokenOrRule?: string;
697
998
  }
698
- interface JudgeVerdict {
699
- viewport: string;
700
- model: string;
701
- preferred: 'before' | 'after' | 'tie';
702
- confidence: 'low' | 'medium' | 'high';
703
- summary: string;
704
- better: JudgeClaim[];
705
- worse: JudgeClaim[];
706
- designBreaks: JudgeClaim[];
707
- /** Claims dropped because their box fell outside the image. */
708
- droppedClaims: number;
709
- /** Set when the model declined or the call failed; no verdict then. */
999
+ interface Identity {
1000
+ email: string;
1001
+ password: string;
1002
+ name?: string;
1003
+ /** The synthetic account's user id, when Mushi minted it: printed in the log and timeline (never the password), so a sweep check needs no SQL. */
1004
+ userId?: string;
1005
+ }
1006
+ interface PageFacts {
1007
+ url: string;
1008
+ /** Visible text, whitespace folded, capped. */
1009
+ text: string;
1010
+ hasPassword: boolean;
1011
+ emailFields: number;
1012
+ /** Visible, enabled controls that lead somewhere or take input. */
1013
+ forwardControls: number;
1014
+ captcha: boolean;
1015
+ /** Characters of text in the page's main content (`main`, `[role=main]`, else the body): what an "I see nothing" opinion is checked against. */
1016
+ mainChars?: number;
1017
+ }
1018
+ type RequirementKind = 'inbox' | 'api_key' | 'terminal' | 'third_party_account';
1019
+ /** The goal check, all given parts must hold: a URL reached, text or a selector visible, or a GET that answers with data. */
1020
+ interface SuccessCheck {
1021
+ /** Glob on the path (`/admin/reports/*`), or on the full URL when it starts with http. `*` stays in one segment, `**` crosses them. */
1022
+ url?: string;
1023
+ /** Case-insensitive regular expression on the visible text. */
1024
+ text?: string;
1025
+ selector?: string;
1026
+ /** GET in the session's own browser context (its cookies); passes on 2xx with a non-empty JSON body. */
1027
+ api?: string;
1028
+ }
1029
+ /** The question to the model: the prompt in a file in an empty folder, so ask mode reads nothing else. */
1030
+ type FreshAsk = (prompt: string, dir: string) => Promise<{
1031
+ text: string | null;
710
1032
  error?: string;
1033
+ }>;
1034
+ type StepOutcome = 'ok' | 'refused' | 'failed' | 'blocked' | 'left-app' | 'terminal';
1035
+ interface FreshEyesStep {
1036
+ /** 0 is the landing page load. */
1037
+ n: number;
1038
+ action: string;
1039
+ /** Path and query after the step. */
1040
+ path: string;
1041
+ screen: string;
1042
+ /** The model's think time (never part of time to first value). */
1043
+ modelMs: number;
1044
+ /** What the app made the visitor wait: the action, navigation and settle. */
1045
+ appMs: number;
1046
+ /** Reading time for a screen seen for the first time in the session. */
1047
+ readMs: number;
1048
+ outcome: StepOutcome;
1049
+ note?: string;
1050
+ opinion?: Opinion;
1051
+ backtrack?: boolean;
1052
+ deadEnd?: boolean;
1053
+ requirements?: RequirementKind[];
1054
+ signals?: Array<Signal['kind']>;
1055
+ /** File name under shots/, e.g. s1-step07.png. */
1056
+ shot?: string;
1057
+ /** The wait for the page's content hit its cap (the page kept showing a loading sign): appMs is the cap, not the app's real wait. */
1058
+ capped?: boolean;
711
1059
  }
712
- interface JudgeOptions {
1060
+ /** Why a session ended without reaching its goal. Measured causes are page facts; the last two are the model's. */
1061
+ type StallReason = 'signup_wall' | 'captcha' | 'external' | 'dead_end' | 'blocked' | 'error' | 'model_gave_up' | 'model_unavailable' | 'out_of_steps';
1062
+ interface FreshEyesSession {
1063
+ index: number;
1064
+ outcome: 'reached' | 'stalled';
1065
+ stall: {
1066
+ step: number;
1067
+ screen: string;
1068
+ reason: StallReason;
1069
+ detail: string;
1070
+ } | null;
1071
+ /** App time plus reading time to the goal; null when it was not reached. */
1072
+ ttfvSeconds: number | null;
1073
+ appSeconds: number;
1074
+ readSeconds: number;
1075
+ modelSeconds: number;
1076
+ backtracks: number;
1077
+ steps: FreshEyesStep[];
1078
+ opinions: Array<Opinion & {
1079
+ screen: string;
1080
+ step: number;
1081
+ mainChars?: number;
1082
+ }>;
1083
+ /** The synthetic account's user id, when the session had one Mushi minted (never the password). */
1084
+ accountId?: string;
1085
+ }
1086
+ interface FreshEyesFinding extends AuditFinding {
1087
+ /** measured: a page fact a replay showed again; opinion: sessions that agreed. */
1088
+ basis: 'measured' | 'opinion';
1089
+ sessions: number[];
1090
+ }
1091
+ interface FreshEyesResult {
1092
+ runId: string;
713
1093
  dir: string;
714
- repoRoot: string;
715
- designFiles: string[];
716
- model?: string;
717
- client?: Anthropic;
718
- /** Deterministic order for tests; defaults to Math.random. */
719
- random?: () => number;
1094
+ goal: string;
1095
+ startUrl: string;
1096
+ model: string;
1097
+ dryRun: boolean;
1098
+ hasAccount: boolean;
1099
+ startedAt: string;
1100
+ finishedAt: string;
1101
+ sessions: FreshEyesSession[];
1102
+ /** Median over sessions that reached the goal; null when none did. */
1103
+ ttfvSeconds: number | null;
1104
+ /** Median steps over all sessions. */
1105
+ steps: number;
1106
+ reached: number;
1107
+ /** The screen most sessions stalled on, when any stalled. */
1108
+ stalledAt: {
1109
+ screen: string;
1110
+ reason: StallReason;
1111
+ sessions: number;
1112
+ } | null;
1113
+ findings: FreshEyesFinding[];
1114
+ refused: string[];
1115
+ blocked: number;
1116
+ warnings: string[];
720
1117
  }
721
- /** Pure: map the shuffled A/B answer back to before/after and drop out-of-image claims. */
722
- declare function unshuffle(out: JudgeOutputT, aIsBefore: boolean, sizes: {
723
- A: {
724
- width: number;
725
- height: number;
726
- };
727
- B: {
728
- width: number;
729
- height: number;
1118
+ /** A measured fact seen in a session, waiting for its replay. */
1119
+ type Candidate = {
1120
+ kind: 'signal';
1121
+ signal: Signal;
1122
+ screen: string;
1123
+ steps: FreshAction[];
1124
+ session: number;
1125
+ } | {
1126
+ kind: 'wall' | 'captcha' | 'dead_end';
1127
+ screen: string;
1128
+ detail: string;
1129
+ steps: FreshAction[];
1130
+ session: number;
1131
+ } | {
1132
+ kind: 'external';
1133
+ requirement: RequirementKind;
1134
+ evidence: string;
1135
+ screen: string;
1136
+ steps: FreshAction[];
1137
+ session: number;
1138
+ };
1139
+ /** Runs a CLI setup step outside the browser (fresh-eyes-terminal.ts) and reports each phase. */
1140
+ type TerminalHandoff = (input: {
1141
+ projectId: string;
1142
+ apiKey: string;
1143
+ dir: string;
1144
+ }) => Promise<{
1145
+ ok: boolean;
1146
+ phases: Array<{
1147
+ name: string;
1148
+ ms: number;
1149
+ ok: boolean;
1150
+ detail: string;
1151
+ }>;
1152
+ }>;
1153
+ interface FreshEyesOptions {
1154
+ url: string;
1155
+ goal: string;
1156
+ success: SuccessCheck;
1157
+ sessions?: number;
1158
+ steps?: number;
1159
+ model?: string;
1160
+ /** Hosts that are the app's own (e.g. its Supabase project); writes may reach them. */
1161
+ appHosts?: string[];
1162
+ /** A synthetic identity per session (minted by the caller). Without it the run has no account and stays read-only. */
1163
+ identity?: (session: number) => Promise<Identity | null>;
1164
+ /** Read-only and no account, whatever else is set. */
1165
+ dryRun?: boolean;
1166
+ allow?: readonly AllowRule[];
1167
+ ask?: FreshAsk;
1168
+ terminal?: TerminalHandoff;
1169
+ /** Known setup values for the terminal step when the screen does not show them. */
1170
+ setupValues?: {
1171
+ projectId: string;
1172
+ apiKey: string;
730
1173
  };
731
- }, viewport: string, model: string): JudgeVerdict;
732
- /** Judge one screen at one viewport: its baseline against its last kept capture. */
733
- declare function judgeSurface(s: SurfaceState, viewport: string, opts: JudgeOptions): Promise<JudgeVerdict | null>;
1174
+ outDir?: string;
1175
+ onProgress?: (line: string) => void;
1176
+ /** Open the browser this way (tests). */
1177
+ session?: () => Promise<BrowserSession>;
1178
+ /** The run id to use, when the console queued the run and already named it (`20261028-091500-ab12`). */
1179
+ runId?: string;
1180
+ }
1181
+ declare function runFreshEyes(opts: FreshEyesOptions): Promise<FreshEyesResult>;
1182
+
1183
+ /**
1184
+ * The terminal part of a fresh-eyes run (ADR 0053), for apps whose setup is a
1185
+ * CLI (Mushi's is `npx mushi-mushi`). Model-free, each phase timed:
1186
+ *
1187
+ * scaffold a tiny sample web app in a temp folder
1188
+ * setup the setup command, non-interactive, with the supplied project id and key
1189
+ * env the values the setup wrote (.env.local / .env)
1190
+ * start the sample served on 127.0.0.1 with the widget's script tag
1191
+ * report one report sent through the widget, answered by the API
1192
+ *
1193
+ * The browser then goes back to the console to see the diagnosis. A phase
1194
+ * that fails ends the run there and says why: that is the finding.
1195
+ */
1196
+
1197
+ /** `{projectId}` and `{apiKey}` are replaced; each is one whitespace-free word. */
1198
+ declare const DEFAULT_SETUP_COMMAND = "npx --yes mushi-mushi@latest --yes --project-id {projectId} --api-key {apiKey}";
1199
+ type PhaseName = 'scaffold' | 'setup' | 'env' | 'start' | 'report';
1200
+ interface Phase {
1201
+ name: PhaseName;
1202
+ ms: number;
1203
+ ok: boolean;
1204
+ detail: string;
1205
+ }
1206
+ interface TerminalResult {
1207
+ ok: boolean;
1208
+ phases: Phase[];
1209
+ failedAt: PhaseName | null;
1210
+ sampleUrl: string | null;
1211
+ }
1212
+ interface TerminalOptions {
1213
+ projectId: string;
1214
+ apiKey: string;
1215
+ /** Work folder (created): the sample app lives in sample/. */
1216
+ dir: string;
1217
+ setupCommand?: string;
1218
+ /** A self-hosted API (data-endpoint); default the hosted one. */
1219
+ endpoint?: string;
1220
+ setupTimeoutMs?: number;
1221
+ reportTimeoutMs?: number;
1222
+ /** Tests: run a command. */
1223
+ runCommand?: (cmd: string, args: readonly string[], cwd: string) => Promise<RunResult>;
1224
+ /** Tests: send the report from the sample page. */
1225
+ sendReport?: (sampleUrl: string) => Promise<{
1226
+ ok: boolean;
1227
+ detail: string;
1228
+ }>;
1229
+ }
1230
+ declare function runTerminalSetup(o: TerminalOptions): Promise<TerminalResult>;
734
1231
 
735
1232
  /**
736
1233
  * The loop. One run:
@@ -893,126 +1390,6 @@ declare function routesFromSource(root: string): string[];
893
1390
  /** Paths listed in /sitemap.xml on the same origin; empty when there is none. */
894
1391
  declare function sitemapPaths(baseUrl: string): Promise<string[]>;
895
1392
 
896
- interface SyncConfig {
897
- apiKey: string;
898
- projectId: string;
899
- endpoint: string;
900
- /** 'cloud' when the run executes on the host's CI rather than a laptop. */
901
- mode: 'local' | 'cloud';
902
- }
903
- declare function syncConfigFromEnv(env?: NodeJS.ProcessEnv): SyncConfig | null;
904
- /** Pure, for tests: the PUT body for one run state. `uploaded` maps upload name → the file it came from. */
905
- declare function toSnapshot(state: RunState, finished: boolean, uploaded: ReadonlyMap<string, string>, mode?: SyncConfig['mode']): {
906
- started_at: string;
907
- finished_at: string | null;
908
- surfaces: {
909
- surface_key: string;
910
- kind: SurfaceKind;
911
- path: string;
912
- label: string;
913
- status: SurfaceStatus;
914
- note: string | null;
915
- plan: {
916
- text: string;
917
- status: "done" | "pending" | "skipped" | "failed";
918
- attempt: number | null;
919
- }[] | null;
920
- penalty_before: number | null;
921
- penalty_after: number | null;
922
- probe_before: {
923
- axe: {
924
- id: string;
925
- impact: string | null;
926
- help: string;
927
- count: number;
928
- }[];
929
- overflowX: boolean;
930
- smallTargets: number;
931
- consoleErrors: number;
932
- cls: number;
933
- } | null;
934
- probe_after: {
935
- axe: {
936
- id: string;
937
- impact: string | null;
938
- help: string;
939
- count: number;
940
- }[];
941
- overflowX: boolean;
942
- smallTargets: number;
943
- consoleErrors: number;
944
- cls: number;
945
- } | null;
946
- judge: {
947
- error?: string | undefined;
948
- viewport: string;
949
- model: string;
950
- preferred: "before" | "after" | "tie";
951
- confidence: "low" | "medium" | "high";
952
- summary: string;
953
- better: {
954
- what: string;
955
- why: string;
956
- }[];
957
- worse: {
958
- what: string;
959
- why: string;
960
- }[];
961
- }[] | null;
962
- thumbs: {
963
- before: string;
964
- after: string;
965
- diff: string;
966
- };
967
- shots: Record<string, string>;
968
- iterations: {
969
- n: number;
970
- agent: string;
971
- model: string | null;
972
- duration_ms: number;
973
- outcome: "accepted" | "rejected" | "agent_failed" | "capture_failed" | "no_change";
974
- reason: string;
975
- commit_sha: string | null;
976
- pixel_diff: Record<string, number>;
977
- penalty_after: number | null;
978
- steps: string | null;
979
- step: string | null;
980
- shots: Record<string, string>;
981
- }[];
982
- }[];
983
- pr?: {
984
- url: string;
985
- number: number;
986
- } | undefined;
987
- mode: "local" | "cloud";
988
- status: string;
989
- agent: string;
990
- model: string | null;
991
- judge_model: string | null;
992
- skill: string | null;
993
- base_ref: string | null;
994
- phase: RunPhase | null;
995
- phase_detail: string | null;
996
- current_surface: string | null;
997
- current_attempt: number | null;
998
- current_progress: {
999
- steps: number;
1000
- last_step: string | null;
1001
- files: string[];
1002
- started_at: string;
1003
- timeout_ms: number | null;
1004
- } | null;
1005
- error: string | null;
1006
- branch: string | null;
1007
- base_sha: string | null;
1008
- cli_version: null;
1009
- };
1010
- interface SyncHandle {
1011
- /** Final sync; resolves with an error message when it did not land. */
1012
- finish(): Promise<string | null>;
1013
- }
1014
- declare function startSync(dir: string, cfg: SyncConfig, events: EventEmitter, log: (m: string) => void): SyncHandle;
1015
-
1016
1393
  /**
1017
1394
  * The cheap, objective keep-or-revert decision after one agent run. It only
1018
1395
  * uses measurements (probes, pixel diff, files changed), never a model's
@@ -1042,4 +1419,4 @@ interface Verdict {
1042
1419
  }
1043
1420
  declare function decide(input: VerdictInput): Verdict;
1044
1421
 
1045
- export { AGENTS, type AgentAdapter, type AgentName, type AgentRunOptions, type AllowRule, type AxeViolation, type BrowserSession, type Capture, type CursorCloudDeps, DEFAULT_JUDGE_MODEL, type Dashboard, type DiscoverOptions, type IterationRecord, type JudgeClaim, type JudgeOptions, type JudgeVerdict, type LayoutIssue, type LoopEvent, type LoopHandle, type LoopOptions, POINTER_PROMPT, type PacketInput, type ProbeResult, type ReplayStep, type RunState, type Surface, type SurfaceKind, type SurfaceState, type SurfaceStatus, type SyncConfig, type SyncHandle, VIEWPORTS, type Verdict, type VerdictInput, type Viewport, buildPacket, captureSurface, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, findDesignFiles, getAgent, hammingHex, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, newRunId, nextRoutePath, normalizeLink, openSession, pixelDiff, probePenalty, quoteArg, reactRouterPaths, routesFromSource, runDir, runProbes, safeShotPath, saveState, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, toSnapshot, unshuffle };
1422
+ export { AGENTS, type AgentAdapter, type AgentName, type AgentRunOptions, type AllowRule, type AxeViolation, type BrowserSession, type Candidate, type Capture, type CursorCloudDeps, DEFAULT_JUDGE_MODEL, DEFAULT_SETUP_COMMAND, type Dashboard, type DiscoverOptions, type FreshAction, type FreshAsk, type FreshEyesFinding, type FreshEyesOptions, type FreshEyesResult, type FreshEyesSession, type FreshEyesStep, type GuardPolicy, type Identity, type IterationRecord, type JudgeClaim, type JudgeOptions, type JudgeVerdict, type LayoutIssue, type LoopEvent, type LoopHandle, type LoopOptions, type Opinion, type OpinionCategory, POINTER_PROMPT, type PacketInput, type PageFacts, type Phase, type PhaseName, type ProbeResult, type ReplayStep, type RequirementKind, type RunState, type StallReason, type StepOutcome, type SuccessCheck, type Surface, type SurfaceKind, type SurfaceState, type SurfaceStatus, type SyncConfig, type SyncHandle, type TerminalHandoff, type TerminalOptions, type TerminalResult, VIEWPORTS, type Verdict, type VerdictInput, type Viewport, type WriteMode, buildPacket, captureSurface, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, findDesignFiles, getAgent, hammingHex, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, newRunId, nextRoutePath, normalizeLink, openSession, pixelDiff, probePenalty, quoteArg, reactRouterPaths, routesFromSource, runDir, runFreshEyes, runProbes, runTerminalSetup, safeShotPath, saveState, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, toSnapshot, unshuffle };