@reticlehq/core 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Names that exist ONLY to say where the browser API actually lives.
3
+ *
4
+ * `@reticlehq/core` is the wire contract — zod schemas and constants, no DOM anywhere in it — but it
5
+ * is the package whose name reads like "the thing you install", so agents and hand-written snippets
6
+ * keep reaching for `import { install, reticle } from '@reticlehq/core'`. Reported from the field:
7
+ * that import took a Vite app down with a blank page and `SyntaxError: The requested module does not
8
+ * provide an export named 'install'`, which names neither the mistake nor the fix.
9
+ *
10
+ * Renaming the package would be worse than the problem. Exporting the names, so the module still
11
+ * loads and the first call says where to go, costs three lines and turns a dead end into a sentence.
12
+ */
13
+ declare function browserApiIsElsewhere(): never;
14
+ /** Not the SDK. Throws with the package that has it — see the note above. */
15
+ export declare const install: typeof browserApiIsElsewhere;
16
+ /** Not the SDK. Throws with the package that has it — see the note above. */
17
+ export declare const connect: typeof browserApiIsElsewhere;
18
+ /** Not the SDK instance (that is `@reticlehq/browser`'s). Every call says so. */
19
+ export declare const reticle: {
20
+ readonly connect: typeof browserApiIsElsewhere;
21
+ readonly install: typeof browserApiIsElsewhere;
22
+ };
23
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Names that exist ONLY to say where the browser API actually lives.
3
+ *
4
+ * `@reticlehq/core` is the wire contract — zod schemas and constants, no DOM anywhere in it — but it
5
+ * is the package whose name reads like "the thing you install", so agents and hand-written snippets
6
+ * keep reaching for `import { install, reticle } from '@reticlehq/core'`. Reported from the field:
7
+ * that import took a Vite app down with a blank page and `SyntaxError: The requested module does not
8
+ * provide an export named 'install'`, which names neither the mistake nor the fix.
9
+ *
10
+ * Renaming the package would be worse than the problem. Exporting the names, so the module still
11
+ * loads and the first call says where to go, costs three lines and turns a dead end into a sentence.
12
+ */
13
+ const WRONG_PACKAGE = '@reticlehq/core is the wire contract (schemas + constants) and has no browser API. The SDK that ' +
14
+ 'connects a page lives in @reticlehq/browser (or @reticlehq/react, which re-exports it), and it ' +
15
+ 'is normally wired for you by @reticlehq/vite-plugin or @reticlehq/next — run `npx ' +
16
+ '@reticlehq/server init` and let it do the wiring.';
17
+ function browserApiIsElsewhere() {
18
+ throw new Error(WRONG_PACKAGE);
19
+ }
20
+ /** Not the SDK. Throws with the package that has it — see the note above. */
21
+ export const install = browserApiIsElsewhere;
22
+ /** Not the SDK. Throws with the package that has it — see the note above. */
23
+ export const connect = browserApiIsElsewhere;
24
+ /** Not the SDK instance (that is `@reticlehq/browser`'s). Every call says so. */
25
+ export const reticle = {
26
+ connect: browserApiIsElsewhere,
27
+ install: browserApiIsElsewhere,
28
+ };
@@ -7,8 +7,24 @@ export declare const RETICLE_WS_PATH = "/reticle";
7
7
  /** Agent↔server MCP wire paths — served by the daemon HTTP plane, forwarded by the stdio proxy. */
8
8
  export declare const MCP_SSE_PATH = "/mcp/sse";
9
9
  export declare const MCP_MESSAGE_PATH = "/mcp/message";
10
+ /**
11
+ * SSE event name the daemon writes to every open MCP stream immediately before it shuts itself down.
12
+ *
13
+ * A stream that simply ends looks identical from the proxy whether the daemon retired on schedule or
14
+ * died under it, so every planned shutdown was counted as an outage the agent suffered. The proxy
15
+ * cannot infer the difference — the daemon is the only thing that knows, and this is it saying so.
16
+ * A custom event name rather than a `message`: the proxy forwards `message` frames to the client
17
+ * verbatim, and this is addressed to the proxy, not to the agent.
18
+ */
19
+ export declare const MCP_SHUTDOWN_EVENT = "reticle-shutdown";
10
20
  /** Local-only daemon introspection — `reticle status` GETs this for sessions + health at a glance. */
11
21
  export declare const STATUS_PATH = "/status";
22
+ /**
23
+ * Local-only drive request — `reticle drive <url>` POSTs `{url}` here when a daemon already owns the
24
+ * bridge port, and gets back the pooled session that daemon opened. The CLI asks instead of binding,
25
+ * so the two never fight over the port. Same trust tier as STATUS_PATH.
26
+ */
27
+ export declare const DRIVE_PATH = "/drive";
12
28
  export declare const RETICLE_PROTOCOL_VERSION = 1;
13
29
  /**
14
30
  * The one place the bridge WebSocket URL is built. The SDK connect default, the vite/next snippet
@@ -176,6 +192,13 @@ export declare const ReticleDir: {
176
192
  readonly BASELINES_SUBDIR: "baselines";
177
193
  /** cross-run memory — outcomes of past runs (the "did it behave like last time?" file). */
178
194
  readonly PROJECT_FILE: "project.json";
195
+ /**
196
+ * the user's own record of what Reticle has done for them — .reticle/impact.json.
197
+ *
198
+ * Local only, never uploaded, and deliberately NOT part of telemetry: telemetry answers our
199
+ * questions about the product; this answers the user's question about their own work.
200
+ */
201
+ readonly IMPACT_FILE: "impact.json";
179
202
  /** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
180
203
  readonly VISUAL_SUBDIR: "visual";
181
204
  /** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
@@ -539,6 +562,14 @@ export declare const ElementState: {
539
562
  readonly EXPANDED: "expanded";
540
563
  readonly FOCUSED: "focused";
541
564
  readonly PRESENT: "present";
565
+ /**
566
+ * Inside the viewport right now (getBoundingClientRect intersects the window). Distinct from
567
+ * `visible`, which folds only aria-hidden/[hidden]/display/visibility/opacity and so is already
568
+ * true for content below the fold of a scrolling container. Without this, `scrollIntoView` is
569
+ * ungradeable: the target satisfied `visible`/`present` before the scroll, so act_and_wait
570
+ * returns already_true. (#398)
571
+ */
572
+ readonly IN_VIEWPORT: "inViewport";
542
573
  };
543
574
  export type ElementState = (typeof ElementState)[keyof typeof ElementState];
544
575
  /** Query strategies, aligned with Testing Library semantics (plan/04). */
@@ -578,6 +609,12 @@ export declare const ReticleCommand: {
578
609
  * AGENT-driven pause/end keeps the presenter in sync. `args: { state, text? }`.
579
610
  */
580
611
  readonly PRESENTER: "presenter";
612
+ /**
613
+ * Bridge -> browser: the user's own impact record, so the HUD can show what Reticle has done for
614
+ * them without the page asking for it. `args: { snapshot: ImpactSnapshot }`. Local data on a
615
+ * local socket - it is the same file the report is stored in, not a fetch to us.
616
+ */
617
+ readonly IMPACT: "impact";
581
618
  /**
582
619
  * Ask the DESKTOP shell to photograph its own window and return `{ png: <base64> }`.
583
620
  *
package/dist/constants.js CHANGED
@@ -7,8 +7,24 @@ export const RETICLE_WS_PATH = '/reticle';
7
7
  /** Agent↔server MCP wire paths — served by the daemon HTTP plane, forwarded by the stdio proxy. */
8
8
  export const MCP_SSE_PATH = '/mcp/sse';
9
9
  export const MCP_MESSAGE_PATH = '/mcp/message';
10
+ /**
11
+ * SSE event name the daemon writes to every open MCP stream immediately before it shuts itself down.
12
+ *
13
+ * A stream that simply ends looks identical from the proxy whether the daemon retired on schedule or
14
+ * died under it, so every planned shutdown was counted as an outage the agent suffered. The proxy
15
+ * cannot infer the difference — the daemon is the only thing that knows, and this is it saying so.
16
+ * A custom event name rather than a `message`: the proxy forwards `message` frames to the client
17
+ * verbatim, and this is addressed to the proxy, not to the agent.
18
+ */
19
+ export const MCP_SHUTDOWN_EVENT = 'reticle-shutdown';
10
20
  /** Local-only daemon introspection — `reticle status` GETs this for sessions + health at a glance. */
11
21
  export const STATUS_PATH = '/status';
22
+ /**
23
+ * Local-only drive request — `reticle drive <url>` POSTs `{url}` here when a daemon already owns the
24
+ * bridge port, and gets back the pooled session that daemon opened. The CLI asks instead of binding,
25
+ * so the two never fight over the port. Same trust tier as STATUS_PATH.
26
+ */
27
+ export const DRIVE_PATH = '/drive';
12
28
  export const RETICLE_PROTOCOL_VERSION = 1;
13
29
  /**
14
30
  * The one place the bridge WebSocket URL is built. The SDK connect default, the vite/next snippet
@@ -178,6 +194,13 @@ export const ReticleDir = {
178
194
  BASELINES_SUBDIR: 'baselines',
179
195
  /** cross-run memory — outcomes of past runs (the "did it behave like last time?" file). */
180
196
  PROJECT_FILE: 'project.json',
197
+ /**
198
+ * the user's own record of what Reticle has done for them — .reticle/impact.json.
199
+ *
200
+ * Local only, never uploaded, and deliberately NOT part of telemetry: telemetry answers our
201
+ * questions about the product; this answers the user's question about their own work.
202
+ */
203
+ IMPACT_FILE: 'impact.json',
181
204
  /** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
182
205
  VISUAL_SUBDIR: 'visual',
183
206
  /** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
@@ -521,6 +544,14 @@ export const ElementState = {
521
544
  EXPANDED: 'expanded',
522
545
  FOCUSED: 'focused',
523
546
  PRESENT: 'present',
547
+ /**
548
+ * Inside the viewport right now (getBoundingClientRect intersects the window). Distinct from
549
+ * `visible`, which folds only aria-hidden/[hidden]/display/visibility/opacity and so is already
550
+ * true for content below the fold of a scrolling container. Without this, `scrollIntoView` is
551
+ * ungradeable: the target satisfied `visible`/`present` before the scroll, so act_and_wait
552
+ * returns already_true. (#398)
553
+ */
554
+ IN_VIEWPORT: 'inViewport',
524
555
  };
525
556
  /** Query strategies, aligned with Testing Library semantics (plan/04). */
526
557
  export const QueryBy = {
@@ -558,6 +589,12 @@ export const ReticleCommand = {
558
589
  * AGENT-driven pause/end keeps the presenter in sync. `args: { state, text? }`.
559
590
  */
560
591
  PRESENTER: 'presenter',
592
+ /**
593
+ * Bridge -> browser: the user's own impact record, so the HUD can show what Reticle has done for
594
+ * them without the page asking for it. `args: { snapshot: ImpactSnapshot }`. Local data on a
595
+ * local socket - it is the same file the report is stored in, not a fetch to us.
596
+ */
597
+ IMPACT: 'impact',
561
598
  /**
562
599
  * Ask the DESKTOP shell to photograph its own window and return `{ png: <base64> }`.
563
600
  *
@@ -15,6 +15,13 @@
15
15
  * Derived on purpose. A hand-maintained contract number is one somebody eventually forgets to bump,
16
16
  * and a forgotten bump is silent skew — the failure this exists to end.
17
17
  */
18
+ /**
19
+ * FNV-1a, 32-bit. Chosen over a crypto hash because this runs in the PAGE: `crypto.subtle` is async
20
+ * and unavailable on insecure origins, and a dependency is not worth 40 lines. Collisions do not
21
+ * matter here — the comparison is equality between two builds of the same project, not a security
22
+ * boundary.
23
+ */
24
+ export declare function fnv1a(input: string): string;
18
25
  /**
19
26
  * Hash a named vocabulary. Keys and values are sorted, so declaration order — which changes for
20
27
  * cosmetic reasons — never moves the fingerprint, while a renamed, added or removed name always does.
@@ -22,7 +22,7 @@ import { ActionType, EventType, MessageKind, ReticleCommand } from './constants.
22
22
  * matter here — the comparison is equality between two builds of the same project, not a security
23
23
  * boundary.
24
24
  */
25
- function fnv1a(input) {
25
+ export function fnv1a(input) {
26
26
  let hash = 0x811c9dc5;
27
27
  for (let i = 0; i < input.length; i++) {
28
28
  hash ^= input.charCodeAt(i);
@@ -501,13 +501,14 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
501
501
  readonly WRAPPED_NETWORK: "wrapped-network";
502
502
  readonly UNOBSERVED_IPC: "unobserved-ipc";
503
503
  readonly VERDICTLESS_SEND: "verdictless-send";
504
+ readonly UNWATCHED_STATE: "unwatched-state";
504
505
  }>;
505
506
  count: z.ZodNumber;
506
507
  }, "strip", z.ZodTypeAny, {
507
- kind: "closed-shadow-root" | "rate-limited" | "cross-origin-iframe" | "uninstrumented-frame" | "virtualized-unmounted" | "wrapped-network" | "unobserved-ipc" | "verdictless-send";
508
+ kind: "closed-shadow-root" | "rate-limited" | "cross-origin-iframe" | "uninstrumented-frame" | "virtualized-unmounted" | "wrapped-network" | "unobserved-ipc" | "verdictless-send" | "unwatched-state";
508
509
  count: number;
509
510
  }, {
510
- kind: "closed-shadow-root" | "rate-limited" | "cross-origin-iframe" | "uninstrumented-frame" | "virtualized-unmounted" | "wrapped-network" | "unobserved-ipc" | "verdictless-send";
511
+ kind: "closed-shadow-root" | "rate-limited" | "cross-origin-iframe" | "uninstrumented-frame" | "virtualized-unmounted" | "wrapped-network" | "unobserved-ipc" | "verdictless-send" | "unwatched-state";
511
512
  count: number;
512
513
  }>;
513
514
  "sdk.failed": z.ZodObject<{
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A stable, privacy-safe fingerprint for a finding — so the same defect can be recognised across
3
+ * sessions without sending any app-specific data over the wire.
4
+ *
5
+ * The hash travels in `bug_found`; the inputs (route, selector) never do. Same pattern as
6
+ * `projectId`: hash the identifying bits, send only the hash, let the analytics side group by it.
7
+ */
8
+ export interface FindingIdentity {
9
+ /** The classified kind from Reticle's findings vocabulary (`signal-contradicted`, `console-error`, …). */
10
+ kind: string;
11
+ /** How Reticle found it (`contradiction`, `crawl`, `assertion`, `replay`). */
12
+ source: string;
13
+ /** The route the app was on when this was found. Hashed, never sent raw. */
14
+ route?: string;
15
+ }
16
+ /**
17
+ * Produce a short hex fingerprint that identifies a finding stably across sessions.
18
+ *
19
+ * Same inputs = same output, regardless of when or where it runs. A changed route or a changed
20
+ * kind = a different fingerprint = a different defect. The analytics side can then answer "was this
21
+ * fixed?" by checking whether a fingerprint stops appearing.
22
+ */
23
+ export declare function fingerprintFinding(identity: FindingIdentity): string;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A stable, privacy-safe fingerprint for a finding — so the same defect can be recognised across
3
+ * sessions without sending any app-specific data over the wire.
4
+ *
5
+ * The hash travels in `bug_found`; the inputs (route, selector) never do. Same pattern as
6
+ * `projectId`: hash the identifying bits, send only the hash, let the analytics side group by it.
7
+ */
8
+ import { fnv1a } from './contract-fingerprint.js';
9
+ /**
10
+ * Produce a short hex fingerprint that identifies a finding stably across sessions.
11
+ *
12
+ * Same inputs = same output, regardless of when or where it runs. A changed route or a changed
13
+ * kind = a different fingerprint = a different defect. The analytics side can then answer "was this
14
+ * fixed?" by checking whether a fingerprint stops appearing.
15
+ */
16
+ export function fingerprintFinding(identity) {
17
+ const canonical = [identity.kind, identity.source, identity.route ?? ''].join('\x00');
18
+ return fnv1a(canonical);
19
+ }
@@ -409,6 +409,16 @@ export interface FlowReplayResult {
409
409
  code: string;
410
410
  message: string;
411
411
  };
412
+ /**
413
+ * Set on an `ok` replay whose flow cannot fail: it asserts no observable consequence, or has no
414
+ * steps at all. The replay genuinely completed, so the status stays `ok` — but a bare `ok` read
415
+ * as proof the feature works is exactly the false confidence `flow-risk.ts` argues against, and
416
+ * `reticle_flow_verify` already refuses to count these as passes. This carries the same reason,
417
+ * from the same function, to the single-flow caller who would otherwise never see it.
418
+ */
419
+ unverifiable?: {
420
+ reason: string;
421
+ };
412
422
  /**
413
423
  * The confident rebind proposals aggregated across drifted steps (additive,
414
424
  * optional — present only when at least one drifted step has a confident nearest match).
@@ -0,0 +1,17 @@
1
+ import type { ImpactCounts, ImpactSavings } from './impact.js';
2
+ /** What the two numbers are measured against, shown beside them in the report. */
3
+ export declare const IMPACT_BASIS: {
4
+ readonly TOKENS: "vs an agent reading the app through screenshots";
5
+ readonly MINUTES: "vs one re-prompt cycle per defect caught";
6
+ };
7
+ /**
8
+ * Estimate what the recorded work saved.
9
+ *
10
+ * Tokens: every verdict-bearing call replaced a look the agent would otherwise have taken as a
11
+ * screenshot. The tokens Reticle actually returned are subtracted, so the figure is a NET saving
12
+ * and can never exceed the modelled cost of the runs it replaced.
13
+ *
14
+ * Minutes: only DEFECTS count. A pass saves nothing by itself - the run was going to pass either
15
+ * way; what a false green costs is the round trip, and that is what catching it returns.
16
+ */
17
+ export declare function estimateImpactSavings(counts: ImpactCounts): ImpactSavings;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The savings model: one file, so every claim Reticle makes about its own worth is derivable here
3
+ * and nowhere else.
4
+ *
5
+ * A saving is a counterfactual - a comparison against a run that did not happen - so each constant
6
+ * below carries the run it stands for. Change a number here and the claim changes everywhere; there
7
+ * is deliberately no second place to tune one.
8
+ */
9
+ /**
10
+ * Tokens an agent spends to LOOK at an app it cannot see from the inside: a screenshot into
11
+ * context, plus the prose it writes reasoning about the pixels. Screenshots dominate - an image
12
+ * costs on the order of a thousand tokens before anything is understood from it.
13
+ *
14
+ * Reticle's answer to the same question is a semantic snapshot, and what that cost is not modelled:
15
+ * it is COUNTED, per call, and subtracted below.
16
+ */
17
+ const TOKENS_PER_SCREENSHOT_LOOK = 1600;
18
+ /**
19
+ * Minutes a false green costs when it escapes: the agent reports done, a person tries it, finds it
20
+ * broken, writes the correction, and the agent goes round again. Deliberately conservative - one
21
+ * short cycle, not the afternoon a shipped regression can take.
22
+ */
23
+ const MINUTES_PER_REPROMPT_CYCLE = 4;
24
+ /** What the two numbers are measured against, shown beside them in the report. */
25
+ export const IMPACT_BASIS = {
26
+ TOKENS: 'vs an agent reading the app through screenshots',
27
+ MINUTES: 'vs one re-prompt cycle per defect caught',
28
+ };
29
+ /**
30
+ * Estimate what the recorded work saved.
31
+ *
32
+ * Tokens: every verdict-bearing call replaced a look the agent would otherwise have taken as a
33
+ * screenshot. The tokens Reticle actually returned are subtracted, so the figure is a NET saving
34
+ * and can never exceed the modelled cost of the runs it replaced.
35
+ *
36
+ * Minutes: only DEFECTS count. A pass saves nothing by itself - the run was going to pass either
37
+ * way; what a false green costs is the round trip, and that is what catching it returns.
38
+ */
39
+ export function estimateImpactSavings(counts) {
40
+ const looksReplaced = counts.verdicts;
41
+ const grossTokens = looksReplaced * TOKENS_PER_SCREENSHOT_LOOK;
42
+ const netTokens = Math.max(0, grossTokens - counts.tokensReturned);
43
+ return {
44
+ tokens: { value: netTokens, basis: IMPACT_BASIS.TOKENS },
45
+ minutes: { value: counts.failed * MINUTES_PER_REPROMPT_CYCLE, basis: IMPACT_BASIS.MINUTES },
46
+ };
47
+ }