Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

2.4 KB
Raw Blame
/**
 * Parent-measured visibility attestation of the sandbox iframe (protocol v2 §6.6 addendum / §13).
 *
 * The parent owns the sandbox iframe, so only it can measure the element from the embedder document;
 * the sandbox cannot observe its own frame from inside a cross-origin context. This module keeps the
 * geometry/observer attestation shape in one place. It intentionally does not send a parent hit-test
 * claim: a compromised embedder can manufacture that boolean, and high-risk authorization now runs
 * in a top-level sandbox confirmation window instead.
 */
export type VaultConfirmSurface = {
  frame: {
    frameWidth: number;
    frameHeight: number;
    intersectionRatio: number;
    visibleByIntersectionObserver: boolean;
    opacity: number;
    pointerEvents: boolean;
  };
  sampledAt: number;
};

/** Raw parent-side measurements, as read straight from the DOM (rect, computed style, observer). */
export type VaultConfirmSurfaceMeasurement = {
  frameWidth: number;
  frameHeight: number;
  intersectionRatio: number;
  visibleByIntersectionObserver: boolean;
  /** Computed `opacity` — a CSS string ("1") or a number; anything non-numeric collapses to 0. */
  opacity: string | number;
  /** Computed `pointer-events` — anything other than "none" (or a `true` boolean) is interactive. */
  pointerEvents: string | boolean;
  sampledAt: number;
};

/**
 * Shape raw parent-side measurements into the attestation object understood by the sandbox. Pure and
 * honest: it never invents values — a hidden, occluded, or degenerate measurement yields failing
 * numbers (e.g. opacity 0, pointerEvents false, zero size). Fail-closed: a non-numeric opacity
 * becomes 0 rather than silently passing.
 */
export function buildVaultConfirmSurface(measurement: VaultConfirmSurfaceMeasurement): VaultConfirmSurface {
  const opacity =
    typeof measurement.opacity === 'number' ? measurement.opacity : Number.parseFloat(measurement.opacity);
  const pointerEvents =
    typeof measurement.pointerEvents === 'boolean' ? measurement.pointerEvents : measurement.pointerEvents !== 'none';
  return {
    frame: {
      frameWidth: measurement.frameWidth,
      frameHeight: measurement.frameHeight,
      intersectionRatio: measurement.intersectionRatio,
      visibleByIntersectionObserver: measurement.visibleByIntersectionObserver,
      opacity: Number.isFinite(opacity) ? opacity : 0,
      pointerEvents,
    },
    sampledAt: measurement.sampledAt,
  };
}