Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

docs: record the session-recording design and the v7 protocol bump

Shahriar3a6568ce8c1d
diff --git a/.claude/skills/voicelink/SKILL.md b/.claude/skills/voicelink/SKILL.md
index d3db943..688d822 100644
--- a/.claude/skills/voicelink/SKILL.md
+++ b/.claude/skills/voicelink/SKILL.md
@@ -102,7 +102,7 @@ Useful commands: `voicelink-mcp status | pair | sessions | revoke | tools | logs
## 8. Adding a capability
-There are 17 page tools because there are 17 actions. To add one, write `lib/actions/page/<name>.ts` and add it to the array in `lib/actions/registry.ts` — that single edit publishes it as an MCP tool, because the daemon bundles the same registry. See `CLAUDE.md` for the load-bearing conventions (no top-level DOM, `.describe()` every field, no `.refine()`/`.transform()`, no underscores in action names). Verify with `yarn mcp:manifest`.
+There are 19 page tools because there are 19 actions. To add one, write `lib/actions/page/<name>.ts` and add it to the array in `lib/actions/registry.ts` — that single edit publishes it as an MCP tool, because the daemon bundles the same registry. See `CLAUDE.md` for the load-bearing conventions (no top-level DOM, `.describe()` every field, no `.refine()`/`.transform()`, no underscores in action names). Verify with `yarn mcp:manifest`.
## 9. The other driver: the in-extension agent
@@ -112,5 +112,6 @@ You (an external MCP client) are not the only thing that can drive this browser.
- **Runs are gated, you are not.** Agent-run invocations pass an approval gate (`requireApproval` in `~/.voicelink/config.json`) and appear on the user's timeline; direct MCP invocations do neither. Do not assume something the agent was denied is something you should do instead.
- **Skills live in `mcp/skills/*.md`**, with hand-written overrides in `~/.voicelink/skills/` and extension uploads in `~/voicelink/skills/`; all three are hot-reloaded per run and a later directory shadows an earlier one by name. Front-matter routes by trigger words; `@name` prefix forces one. A `category: site-exploration` skill is an overlay instead of a base — it stacks on top of the routed skill whenever the tab's host matches its `domains`. Skills load in two forms: flat `<name>.md` and `<name>/SKILL.md`. `voicelink-mcp skills` prints what the router can see.
- **Site maps are generated skills.** `@site-mapper map this site` runs a read-only, host-locked crawl that writes `<name>/SKILL.md` plus screenshots into `~/voicelink/skills/`, staged under `.staging/` until the user activates it in the panel. A mapping run refuses anything that changes a page (`MAPPING_READ_ONLY`), anything off the mapped host (`MAPPING_OFF_SITE`) and relative or history navigation; it is pinned to one tab (`MAPPING_TAB_CHANGED`). Mapping mode requires the explicit `@site-mapper` prefix — trigger words alone will not start one. When asked to change how the in-extension agent behaves, that markdown — not this file — is usually the place.
+- **Recordings are the reverse of site maps.** The panel's Record button captures what the *user* does in one pinned tab — clicks, fills, navigations — for at most 15 minutes, then a one-shot `claude -p` splits the trace into ordered steps. They live in the extension's storage, not on disk, so `voicelink-mcp skills` does not show them; `page_listRecordings` and `page_readRecording` are how anything reads one, and the `browse-navigation` skill routes on "do it like last time". Typed values are placeholders (`{{email}}`) unless the user ticked "Save what I type", and passwords and card numbers are dropped either way. A recording is a plan, not a script: replaying one still re-verifies each target on the live page, and `page.submitForm` inside a recording is still approval-gated.
- **Not every instruction becomes a run.** A local intent funnel (`lib/intent/`) scores each utterance first, and confident single-step commands — back, reload, scroll down, open github.com, press enter, click Sign in — run in the extension itself. Those never touch the daemon, so they leave no trace in `voicelink-mcp logs` and never appear as agent runs; on the user's timeline they carry a ⚡. If a user reports "it did the thing but nothing shows in the log", that is this, not a failure. `yarn intent:check "<what they said>"` explains any single routing decision.
- **Debugging a run**: `NO_CLAUDE` means Claude Code is not on the daemon's PATH (set `claudeBin` in config.json); `RUN_IN_PROGRESS` means one instruction at a time; `RUN_INACTIVE` on a tool means the run was cancelled mid-call. Everything else lands in the daemon log.
diff --git a/CLAUDE.md b/CLAUDE.md
index ca77436..e7fc2f6 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -64,7 +64,7 @@ Docs and daemon-printed hints all use the bare `voicelink-mcp` name, so `mcp:lin
Each action is a frozen value from `defineAction()` (`core.ts`): a namespaced name (`page.clickElement`), a one-line description, a zod input schema, and an `execute()` that runs **in the page** (content-script context). The same declarative shape drives typed in-extension calls today and MCP tool definitions later. The pieces:
-- `registry.ts` — the `Map` of all 17 actions, plus `describeActions()` → `[{ name, description, inputSchema }]` with JSON Schema (`io: 'input'`, so defaulted fields stay optional and the manifest matches what `dispatch` actually accepts).
+- `registry.ts` — the `Map` of all 19 actions, plus `describeActions()` → `[{ name, description, inputSchema }]` with JSON Schema (`io: 'input'`, so defaulted fields stay optional and the manifest matches what `dispatch` actually accepts).
- `dispatch.ts` — validates input against the schema and runs the action; always returns the `{ ok: true, data } | { ok: false, error: { code, message } }` envelope, never throws (`UNKNOWN_ACTION`, `INVALID_INPUT`, or the action's own `ActionError` code).
- `host.ts` — `exposeActions()`, called by the content script; listens on the `voicelink/action` channel and dispatches in the page.
- `client.ts` — `invokeInTab` / `invokeInActiveTab`: typed callers usable from any extension context. Passing the action object (not the string name) gives compile-time input typing — and the `input` argument is *required* when the schema has required fields. Transport failures come back as `TAB_UNREACHABLE` / `NO_ACTIVE_TAB` rather than throwing.
@@ -85,7 +85,7 @@ Call path: side panel / bridge → `invokeForHarness` → `browser.tabs.sendMess
- **Auth is two independent gates.** At the HTTP upgrade the daemon classifies the peer by handshake `Origin` (extension scheme → extension path; `http(s)` → 403; absent → control client, lockfile token required). That only proves the peer is *an* extension; the `hello` frame must then carry a one-time `pairingToken` or a session key bound to that same origin. Credentials ride in the frame because the browser `WebSocket` API cannot set request headers, and a URL query would leak into logs.
- **The extension is off by default.** `connectDaemon()` returns without dialing unless `storage.local` holds a session key, so an unpaired browser never contacts the daemon. Pairing state lives in `~/.voicelink/auth.json` (`0600`) — deliberately *not* the lockfile, which is deleted on shutdown.
- Verified: Chrome does send `Origin: chrome-extension://<id>` from an MV3 worker.
-- **The wire protocol is v6** (`SOCKET_PROTOCOL_VERSION`): on top of the v1 request/reply frames, the extension may send `instruct`/`cancel`/`decision`/`reset`/`analyzeFile`/`saveSkill`/`deleteSkill`/`deleteSiteMap`/`activateSiteMap`/`discardSiteMap`/`nameSession` unprompted, and the daemon streams `run` and `siteMapDraft` frames back. Any new extension-initiated frame must also be listed in `EXTENSION_REQUEST_FRAMES` — `isExtensionRequest()` keys on it, and a frame missing from that list is silently dropped by `ExtensionLink.receive` rather than erroring. `assertToolNamesRoundTrip` aside, protocol bumps require rebuilding both sides *and* reloading the extension — an older worker is refused at `hello`.
+- **The wire protocol is v7** (`SOCKET_PROTOCOL_VERSION`): on top of the v1 request/reply frames, the extension may send `instruct`/`cancel`/`decision`/`reset`/`analyzeFile`/`saveSkill`/`deleteSkill`/`deleteSiteMap`/`activateSiteMap`/`discardSiteMap`/`nameSession`/`analyzeRecording` unprompted, and the daemon streams `run` and `siteMapDraft` frames back. Any new extension-initiated frame must also be listed in `EXTENSION_REQUEST_FRAMES` — `isExtensionRequest()` keys on it, and a frame missing from that list is silently dropped by `ExtensionLink.receive` rather than erroring. `assertToolNamesRoundTrip` aside, protocol bumps require rebuilding both sides *and* reloading the extension — an older worker is refused at `hello`.
- **Navigation is special-cased** in `lib/bridge/invoke.ts`. It tries the in-page action first (pushes history) and falls back to `browser.tabs.update` only when `sendMessage` fails with "Receiving end does not exist" — a pre-delivery error proving the action never ran. Any other failure means the page already unloaded and is navigating, so re-issuing would navigate twice.
- **Service-worker lifetime.** Daemon pings every 20s reset Chrome's 30s idle timer; a 1-minute `alarms` tick is the only thing that can revive the worker once it is torn down.
@@ -118,6 +118,19 @@ Call path: side panel/popup → `runtime.connect` port (`lib/bridge/run-port.ts`
- **Attached files reach the agent as prompt, not as a tool.** Nothing in a run can open a file — `page.listFiles` names them and `page.attachFile` uploads one — so `run-port.ts` reads the file index and sends it in `RunContext.files`, and `filesBlock()` renders it into the system prompt under `FILES_INTRO`. The notes come from the summarizer (`agent/analyze.ts` asks one `claude -p` for both the panel's `summary` and a longer `digest`, since the file is only on disk for that call). The list is the user's choice and trustworthy; the notes restate document content, so they are framed untrusted exactly like page text, and `FILES_INTRO` states the capability limit so the agent says "not in the notes" rather than claiming to have read the file. Capped twice — per-file in the extension, per-block in the daemon — and skipped entirely for mapping runs.
- `voicelink-mcp logs` is the debugging surface: every run start/finish, routed skill, and tool call lands in `~/.voicelink/daemon.log`.
+### Session recording (`lib/recordings/`, `lib/bridge/recorder.ts`, `mcp/src/agent/recording.ts`)
+
+The record button in the composer toolbar captures what the *user* does in the active tab and turns it into a workflow the agent can repeat. It is the mirror image of site mapping: mapping has a model drive the browser to describe a site, recording has the human drive it to demonstrate a task. The three parts sit at three lifetimes.
+
+- **The recorder is semantic, not a DOM replay.** `lib/recordings/capture.ts` installs capture-phase listeners and emits events already shaped like the actions that replay them — `click` → `page.clickElement`, `input` committed on change/blur → `page.fillInput`, `change` on a `<select>` → `page.selectOption`. That is the whole reason not to reach for rrweb: it records pixels and node ids, and every recorded step would then need translating back into the 19 actions. Reusing `cssPath`/`accessibleText` from [dom.ts](lib/actions/page/dom.ts) means a recorded target is literally a `resolveTarget` target. Both a `selector` *and* `text`+`role` are stored, because `cssPath` emits `nth-of-type` chains that a redesign breaks and text does not.
+- **Nobody can hold the buffer, so it lives in `storage.session`.** The content script dies on every navigation and the MV3 worker dies after 30s idle, so the content script only batches (1s / 20 events, plus `pagehide`) and the worker persists after every batch. Each flush is a `runtime.sendMessage`, which itself revives the worker; each new page load re-asks `{ op: 'recordingState' }` and re-arms only if `sender.tab.id` matches the pinned tab. `storage.session` is cleared on browser restart, so an in-flight recording is lost there and a finished one is not.
+- **The 15-minute cap is two one-shot `alarms`**, not a timer — a timer dies with the worker. `voicelink/recording-warn` at 13 min pushes a timeline notice *and* the bar's countdown line; `voicelink/recording-stop` at 15 finalizes. Navigation steps also come from the worker (`tabs.onUpdated` on the pinned tab), which covers SPA route changes for free, so no `webNavigation` permission and no history patching from an isolated world. **The whole feature adds no manifest permission.**
+- **Typed values are placeholders by default.** A fill step stores the field's identity and `{{slug}}`, keyed by selector so the same field reuses one variable name. The per-recording "Save what I type" toggle opts into literals, and `isSensitiveField` still drops `password`/`hidden`, card/SSN/OTP-shaped `name`/`id`/`autocomplete`, and any Luhn-valid 13–19 digit value. One predicate serves both modes, so there is one place for this to be right.
+- **The split into steps is a `claude -p`, and the report is typed.** `agent/recording.ts` writes the trace to `stateDir/tmp` and allows `Read` back, like the file summarizer, because a 2000-event trace does not belong in argv. It returns JSON, never markdown: `validateRecordingWorkflow` scrubs and caps every leaf, drops any `action` outside `REPLAYABLE_ACTIONS`, blanks cross-origin urls, and renumbers ordinals — the same discipline as `validateSiteMapReport`, for the same reason, since every selector and every scrap of text in that trace came off a site. `lib/skills/scrub.ts` holds the one copy of `scrub`/`looksLikeInstruction` that both validators use.
+- **Recordings reach the agent as prompt index plus two read actions.** `RunContext.recordings` carries only name/host/goal/step-count, rendered by `recordingsBlock()` under `RECORDINGS_INTRO`; the ordered steps come from `page.readRecording` on demand, so a shelf of recordings does not crowd skills and files out of the 64 KB prompt. Both new actions are worker-fulfilled like `page.listFiles` — a stub `execute()` that throws `UNSUPPORTED`, intercepted in [invoke.ts](lib/bridge/invoke.ts) before any tab is resolved. The bundled `browse-navigation` skill is what teaches replay: read first, re-verify each target live, ask for every `{{variable}}`, stop rather than improvise.
+- **Starting a recording is deliberately not an MCP tool.** `voicelink.startRecording`/`voicelink.stopRecording` exist only as fast-path pseudo-actions — two rules in `lib/intent/grammar.ts`, a branch in `fast-path.ts`, and **not** in `registry.ts` — so "record my browsing session" works by voice while no external MCP client can begin recording someone's browsing. `daemon.invoke` refusing the whole `voicelink.` namespace is the second line. These two are also the only fast-path actions that never escalate on failure: a `RECORDING_IN_PROGRESS` handed to the agent would just make it flail.
+- **`voicelink:recordings` is the fourth index+body store**, and copies `putSession`'s eviction cascade so dropping a record drops its body key. A recording finishes into `status: 'analyzing'` *before* the daemon is consulted, so recording while unpaired works and `onWelcome` retries it — the analogue of `resyncSkills()`.
+
### The local intent funnel (`lib/intent/`, `lib/bridge/fast-path.ts`)
Every instruction — spoken or typed, popup or side panel — reaches `instruct()` in `run-port.ts`, and the local grammar gets first refusal before anything is sent to the daemon. A confident single-step command (back, reload, scroll down, open github.com, press enter, click Sign in) runs straight through `invokeForHarness` in the background worker; everything else escalates as an ordinary agent run with the text untouched.
@@ -151,6 +164,7 @@ One module per action: `lib/actions/page/<name>.ts` exporting `defineAction({ na
- **Voice input:** real, via the browser's Web Speech API (`webkitSpeechRecognition` — Chrome streams the audio to Google to transcribe; no bundled model). `lib/bridge/use-speech.ts` wraps recognition (mic-permission prompt, continuous mode, silence-driven auto-restart, feature detection); `lib/bridge/use-voice-composer.ts` layers hands-free dictation on top — finalized phrases append to an editable buffer and auto-send after a short silence, with any of {more speech, typing, cancel} calling off the pending send. The **side panel** listens by default (persisted `voicelink:voiceEnabled`, toggled by the mic button); the **popup** is press-to-talk, since a popup dies on blur and can't hold continuous listening. Both surfaces fall back to typing when recognition is unavailable or the mic is blocked. STT swap-out point is `use-speech.ts` alone.
- **Page context:** the side panel's paperclip button calls the `page.getPageInfo` action on the active tab and splices the result into the prompt.
- **Attached files:** the upload button stores a file in `storage.local` (`lib/bridge/file-store.ts`) and the daemon summarizes it once. Every later instruction carries the library in `RunContext.files`, which is the only way an agent learns a file exists — see the agent-harness section for why it is prompt rather than a tool.
+- **Recorded sessions:** the composer toolbar's record button captures the user's own browsing in the pinned tab and a `claude -p` splits it into ordered steps — see the session-recording section above. Recording gets its **own** surface rather than riding along in `SkillsPanel`: the button toggles `components/recording-panel.tsx` (start/stop, the capture-values opt-in, and `components/recording-list.tsx` scrolled inside it), exactly as the skills button toggles `SkillsPanel`. `components/recording-bar.tsx` is separate on purpose — it sits above whichever panel is open and stays put when they are all closed, because the countdown and the Stop button have to be reachable without remembering which button opened what.
- **Saved conversations** (`lib/bridge/session-store.ts`, `components/session-list.tsx`) are the third store on the `voicelink:sessions` index + `voicelink:session:<id>` body pattern, and the first one that enforces its own caps (`MAX_SESSIONS`, `MAX_ITEMS`) — sessions accumulate with no user action to prompt pruning. The **side panel** writes them, debounced, from `useRun({ persist: true })`; `text` events arrive per token, so an undebounced write would be one `storage.local.set` per token. Every run end forces a flush, which bounds the loss to one debounce window and only when the panel closes mid-stream. The popup deliberately does *not* persist: it fires one instruction and closes, so it would only ever mint half a session and the panel would mint another.
- **Two writers share each record**, which is why `putSession` merges rather than replaces: the panel owns `SessionFields`, the worker owns `title`/`titledAtTurn`/`namingAt`. A wholesale replace would erase the title on the panel's next keystroke.
- **Names come from a one-shot `claude -p`** (`mcp/src/agent/title.ts`, dispatched beside `analyzeFile` in `daemon.ts` since it is stateless), regenerated at the `TITLE_TURNS` thresholds. It is handed **the user's own messages only** — an assistant turn restates whatever page the agent was reading, so feeding one in would let a site name a conversation in the user's history. The name is flattened and clamped on both ends, and rendered as text, never through `Markdown`. `namingAt` is a timestamp rather than a flag because Chrome can stop the worker mid-request: a flag would sit true forever and that conversation would never be named again.
diff --git a/README.md b/README.md
index 89d01d2..64d05b1 100644
--- a/README.md
+++ b/README.md
@@ -186,6 +186,7 @@ registry the extension ships, so they cannot drift from what the browser can act
| Act | Click, hover, focus, type into inputs and contenteditables, choose a `<select>` option, select text, press keys with modifiers, submit a form |
| Move | Open a URL, back, forward, reload, scroll to an element or position |
| Files | List files stored in VoiceLink and attach one to a file input on the page |
+| Recordings | List the browsing sessions the user recorded, and read one back as ordered, replayable steps |
Most capabilities take a target described by CSS selector, visible text, ARIA role or index.
Targeting by visible text survives redesigns that break selectors.