Every bubble has a circle that belongs to its Silicon: the visual. You fill it with a small JavaScript file that peek runs every frame. The API feels like HTML <canvas> 2D, plus a few peek-only extensions for Liquid Glass, blur and vibrancy. This page is the complete contract for writing that file.
- You write JavaScript (ES2023), not Swift and not JSON.
- The script only draws. It reads everything happening in its bubble (speech, microphone level, show, ask, pointer, backdrop), reacts to clicks, and sends nothing out. There is no network, no file access, and no channel back to you.
- Peek owns everything outside the visual: the information arc, pills, the question arc, the mic and keyboard buttons and the down-arrow. A drawing cannot change them.
- There is no bubble background. The panel is invisible, so whatever your drawing leaves transparent shows the Carbon's desktop (or the window behind it). Draw your own backing, for example a glass disc, if you want one.
Lifecycle and CLI#
| Event | What happens to the drawing |
|---|---|
register drawing ./x.js | Validated (see Validation below). On success it is stored, loaded, its top-level code runs once, then it is paused. |
register drawing again | The old script is thrown away; the new one loads fresh. All state is lost. |
register side N | The bubble moves. The same script instance keeps running, and top-level variables survive. input.slot changes and the move event fires. |
peek send … | Resumes: enter event → frames → … → leave event → paused. |
unregister | Script destroyed; the stored copies (on the Mac and on the server) are deleted. |
| Peek.app restarts | The script reloads from the top. State does not survive restarts. |
A custom drawing is optional: Peek uses its built-in visual when none is registered. Save defaults with peek config set '{"position":5,"drawing":"./logo.js"}'; later CLI sends apply them only when registration is missing. Relative config paths are saved as absolute paths. peek register drawing without a file explicitly applies the configured drawing.
Useful flags:
The file is resolved against your current directory and the CLI reads it, so Peek.app never opens your files. The active drawing is stored at ~/Library/Application Support/Peek/drawings/<context>/<account_uuid>/<sha256>.js (the previous one is kept for rollback), and a copy is kept on the peek backend. When you register a position on a Mac that has no local copy, peek fetches the server copy and validates it before using it.
The drawing area#
- The script always draws in a fixed 100 × 100 unit square.
(0, 0)is top-left and y points down, like canvas. - The area cannot be resized. Peek scales it to pixels for Retina, normal mode and compact mode. The script never deals with pixels.
- The visual circle is the circle inscribed in the square: centre
(50, 50), radius50. Keep important content inside it; in some positions peek's arc and buttons cover the square's corners. - Anything drawn outside
0…100is clipped. - All sizes (
lineWidth, font size, radii) are in units.ctx.font = '8px SF Pro'means 8 units tall. - Angles are in radians, like canvas:
0points right, positive is clockwise (because y points down).
Script structure#
A drawing is one .js file (ES2023, at most 256 KiB, no imports). Top-level code runs once when it loads. Top-level variables are the script's memory between frames.
peek.frame(fn)#
fn(ctx, input)is called once per display frame (60 or 120 Hz) while awake.Draw the whole visual every frame. Nothing carries over from the last frame; peek clears the area before each call.
Return value:
true: peek schedules another frame.falseorundefined: the drawing sleeps. The last frame stays on screen and costs nothing.
A sleeping drawing wakes automatically for one or more frames when any of these happen:
input.phasechanges;- a send arrives, or an answer is submitted;
input.speech.levelorinput.mic.levelrises above 0;- hover starts or ends, or the pointer moves while hovering;
- a click;
- the slot, mode, appearance or backdrop changes.
So a drawing that only reacts to voice can return
falseand still animate while someone is talking.
peek.on(event, fn)#
One-off moments. Continuous values live in input.
| Event | Payload | Fires when |
|---|---|---|
enter | – | the bubble is about to slide in (see below) |
leave | – | the bubble starts sliding out |
send | the new input.show / input.ask / input.speech | a peek send arrives |
answer | { value, via } | the Carbon submits an answer (via: voice, keyboard or click) |
click | { x, y, count } | the Carbon clicks the visual (units; count 2 = double click) |
move | { from, to } | you moved to another position |
A click on the visual does nothing else. It exists only so the drawing can animate.
enter comes shortly before the slide. peek prepares each bubble out of sight first, so the glass, the backdrop colours and your first frame are ready when it lands: it fires enter and renders your frames off screen for about 0.35 s (at most 0.6 s), then slides the bubble in. An entrance animation you start on enter should therefore last longer than that, or it is over before the Carbon sees it.
Any other event name throws a TypeError that lists the valid ones. The one exception is the old word event from early drafts: registering it loads with a one-time warning in logs, and it never fires, because peek has no word timing (use input.speech.progress and input.speech.level).
peek.log(...args)#
Debug output. Shown in register drawing output and in Simulation. Ignored during normal operation.
The input reference#
input is a fresh read-only snapshot every frame.
Notes:
speech.levelversusmic.level:speechis peek talking,micis the Carbon talking. For "react to voice", useMath.max(input.speech?.level ?? 0, input.mic.level).speech.progresscomes from the audio clock, so it tracks what the Carbon actually hears. Before the whole speech has arrived it is an estimate that only moves forward and stays below 1.- There is no live transcript and no word timing. A voice answer is transcribed once, after the Carbon stops; during that wait
phaseis'transcribing'(choice, slider and range asks only). backdropis peek's estimate of what is behind the bubble. Usebackdrop.inkfor strokes and text that must stand out, andappearancefor overall light or dark styling.ImageHandleis an opaque object. Its only use isctx.drawImage(handle, …); it also has.widthand.height. File paths are never exposed. Handles become invalid when the next send replaces the content, and drawing an invalid handle does nothing.typing.textis the Carbon's in-progress input. The drawing can see it because it has no way to send it anywhere.
The ctx reference#
Supported (HTML canvas 2D subset)#
| Group | API |
|---|---|
| State | save(), restore() |
| Transform | translate(x,y), rotate(a), scale(x,y), transform(a,b,c,d,e,f), setTransform(...), resetTransform() |
| Paths | beginPath(), closePath(), moveTo, lineTo, arc, arcTo, ellipse, rect, roundRect(x,y,w,h,r), quadraticCurveTo, bezierCurveTo |
| Path2D | new Path2D(), new Path2D('M0 0 L10 10 …') (SVG path strings), and passing a Path2D to fill / stroke / clip |
| Painting | fill(rule?), stroke(), fillRect, strokeRect, clearRect, clip(rule?) where rule is 'nonzero' or 'evenodd' |
| Style | fillStyle, strokeStyle (CSS colours or gradients), lineWidth, lineCap, lineJoin, miterLimit, setLineDash, lineDashOffset, globalAlpha, globalCompositeOperation (source-over, multiply, screen, overlay, destination-out, lighter) |
| Gradients | createLinearGradient, createRadialGradient, createConicGradient, addColorStop |
| Shadows | shadowColor, shadowBlur, shadowOffsetX/Y |
| Filter | filter = 'blur(Npx)' only (blurs your own drawing, not the desktop) |
| Text | font, textAlign, textBaseline, fillText, strokeText, measureText (returns width, actualBoundingBoxLeft/Right/Ascent/Descent and fontBoundingBoxAscent/Descent) |
| Images | drawImage(handle, dx, dy, dw, dh) and the 9-argument crop form |
Fonts: SF Pro, SF Pro Rounded, SF Mono, New York, system-ui, weights 100 to 900. Nothing else is loaded.
Not supported#
getImageData, putImageData, toDataURL, createPattern, isPointInPath (do hit-testing with math), any DOM, fetch, XMLHttpRequest, setTimeout/setInterval (use input.t and input.dt), require, import, WebAssembly. Math.random works.
Peek extensions#
These use native macOS materials, which see what is behind the window: the wallpaper and other apps. Ordinary canvas drawing cannot.
Stacking rule: calls stack in the order you make them. Anything drawn before a fillGlass sits under the glass and is refracted by it. Anything drawn after sits on top.
Limit: at most 3 glass or blur fills per frame. Extra ones are drawn as a flat translucent fill.
Glass: what is cheap and what is not#
Each glass fill is a real system view. Peek records the path as you built it (the local path) together with the current transform, and treats the two differently:
- Transform-only changes apply every frame. Drawing the same path under a different
translate,rotateorscaleonly moves the existing glass view. That is cheap. - Outline and option changes are capped at 10 Hz per bubble. A new path shape, or a new
style,tint,interactiveorrule, rebuilds the glass view; peek applies at most 10 such rebuilds per second, and the last write wins. Rebuilding every frame would cost about a third of a CPU core per bubble. input.glassis'frosted'on systems where peek cannot show live Liquid Glass. There,style:'clear'looks like'regular', and content under the glass is blurred through rather than refracted. Use it to compensate, for example with a stronger outline.
Rules for good drawings#
- Keep glass outlines still; animate on top of them. Build glass paths once at the top level. Move them with transforms if you must; never reshape them per frame.
register drawingwarns when a glass outline changes in more than 10% of test frames. - Return
falsewhen nothing moves. A sleeping drawing costs nothing, and peek wakes it for voice, hover, clicks and sends anyway. - Use
input.dtfor motion, not frame counts. Frame rate varies between 60 and 120 Hz. - Smooth values over time. Voice levels jump around. Use
v += (target - v) * Math.min(1, dt * 10). - Use
backdrop.inkorctx.vibrantfor thin lines and text, so they stay readable on any wallpaper. - Simplify in
compactmode. The drawing is tiny there. Drop text and thin details. - Keep it inside the circle.
- Do not assume
show,askorspeechexist. Use?.everywhere.
Limits#
| Limit | Value | When exceeded |
|---|---|---|
| Script size | 256 KiB | rejected at register (drawing_too_large) |
| Top-level code | 250 ms when the script loads | the load fails (drawing_invalid) |
| Frame time | 4 ms per frame() call (and per event handler) | frame dropped (the last frame stays); 30 overruns in 5 s → fallback visual |
| Ops per frame | 5,000 | extra ops ignored, warning logged |
| Glass + blur fills per frame | 3 | extra ones drawn as a flat translucent fill |
| Glass rebuilds (outline or options) | 10 per second per bubble | later writes wait; the last one wins |
| JS memory | 16 MB | script killed → fallback visual |
Uncaught exception in frame() | – | frame dropped; 10 in a row → fallback visual |
Fallback visual: a plain glass circle with your initial. Your next peek send, peek register side or peek status carries a drawing_fallback_active warning with the error message and stack, once, so you can fix and re-register. Other commands do not carry it. Until you register again, peek status also shows drawing.active: false and the error in drawing.last_error.
Examples#
Example 1: minimal (a dot that pulses with any voice)#
Example 2: glass orb with a voice ring#
Example 3: cassette (glass with holes, clipped tape, reels, clicks)#
Example 4: vinyl record using the shown cover art#
Example 5: reacting to an ask (a gauge that follows the slider live)#
Example 6: an eye that looks inward, and at the pointer when hovered#
Example 7: speech progress, transcribing and frosted glass#
Validation#
Before a drawing is accepted, peek runs it offscreen for 90 frames inside Peek.app, with the same JavaScript engine and renderer used on screen, cycling through:
- every
phase, includingtranscribing; modenormal and compact;appearancelight and dark,backdroplight and dark;contextproduction and simulation, andglasslive and frosted;showwith a sample image and text, and anaskof each type with a movingvalue;speech.levelandmic.levelas sine waves,speech.progressrunning from 0 to 1 andspeech.done;- hover on and off, the pointer circling, one click, one
move.
Test frames are numbered 0 to 89.
It fails if the script throws (while loading, in frame() or in an event handler), if its top-level code runs longer than 250 ms, if frame() is interrupted at the 4 ms limit in 5 test frames or its 95th-percentile time is over 4 ms, if it runs out of memory, is larger than 256 KiB or is not UTF-8, if it never calls peek.frame, or if it draws nothing at all. It warns (but accepts) with these warnings[].code values:
| Code | Why |
|---|---|
glass_outline_unstable | a glass outline changed in more than 10% of the test frames |
text_in_compact | text is drawn in compact mode |
ops_truncated | a frame recorded more than 5,000 ops; the rest were ignored |
glass_limit | more than 3 glass or blur fills in a frame; the extra ones were drawn flat |
ignored_value | something peek ignored or clamped while drawing (for example an unsupported value), reported once per message |
dump_frame_unavailable | --dump-frame N named a frame outside 0–89, or one that was interrupted |
Success:
Failure (exit 4, drawing_invalid; the block goes to stderr and is followed by the usual error: and hint: lines):
Warning:
With --json, the same warning is {"code":"glass_outline_unstable","message":"glass fill #1 changed outline in 90/90 frames. …"} in warnings, and peek.log lines are in logs.
For --preview, glass layers are drawn as a flat translucent approximation, because live glass needs a real window.
Debugging: the display list#
--dump-frame N adds what test frame N (0–89) turned into, which is what peek actually draws, as dump in the result (the human output prints it after the summary). Example (cassette, mid-speech):
(Shortened here; the real dump lists every op.)
againis whatframe()returned;opsanddropped_opscount the recorded and ignored ops;inputsummarizes the test input of that frame.- A new layer starts at every
fillGlass,fillBlur, and every change ofctx.vibrant.kindisglass,blur,draworvibrant-draw. - A glass layer's
local_pathis the path as you built it, andtransformis the canvas transform at the time of the call,[a, b, c, d, e, f], which is applied to the glass view as a layer transform.pathis the same outline with the transform applied (in drawing units). Thehashcovers the local path, the fill rule and the glass options only, so a transform change never rebuilds the glass. - Paths are written with
M,L,Q,CandZcommands, whatever you used to build them. drawops keep canvas-style state (save,translate, …) and are replayed as they are. Path2D objects appear as{"path2d":[…]}, gradients as{"type","params","stops"}, and images as{"image":<id>}.- If a layer's
hashmatches the previous frame, peek does not redraw it.
Next#
- Try your drawing in Peek's Simulation window (menu bar → Simulation). It shows
peek.logoutput and every combination of inputs, without Silicon Accounts or Ting. - Speak and show and Ask a question describe what fills
input.showandinput.ask.