Libretto

From saffron-health/libretto · View interactive version

Libretto is an AI agent skill from the GitHub repository saffron-health/libretto. Browser automation CLI for building, maintaining, and running browser automation workflows by inspecting live pages and prototyping interactions.

How to use this skill

Skill file

How Libretto Works

Shipped Source & Documentation

Read references/shipped-source-and-documentation.md for shipped source details, published documentation links, and implementation context beyond what this skill file covers.

Default Integration Approach

  1. Call the site's fetch/XHR endpoints via browser-context fetch().
  2. If references/site-security-review.md (assess only once per site) rules fetch() unsafe, passively capture responses with page.on('response', ...)
  3. Fall back to Playwright UI automation.

Mix strategies freely across steps on a site.

Prefer to enter sites at a user-facing URL (homepage, login, etc.) on the first navigation — deep URLs on a cold session are commonly blocked by edge bot protection.

Always declare that entry URL as workflow startUrl. Do not open the same URL again with page.goto at the top of the handler when Libretto launches the browser; Libretto loads startUrl before the handler runs (and before CDP attach on Kernel / cloud providers). run --cdp attaches without navigating, so leave the existing page as-is or navigate inside the handler.

CAPTCHA Handling

Setup

Experiments

Run Modes

There are three ways to run workflows:

When editing a deployed workflow, validate changes with run --provider <deployment-provider> before redeploying; do not debug by repeatedly deploying and running the deployed job.

If the user prefers a provider for all local CLI runs in a workspace or only deploys workflows to that provider, update .libretto/config.json with provider instead of repeating --provider. Read references/configuration-file-reference.md first.

Working Rules

Commands

`open`

npx libretto open https://example.com
npx libretto open https://example.com --provider libretto-cloud --session provider-debug
npx libretto open https://example.com --read-only --session readonly-example
npx libretto open https://example.com --session debug-example

`connect`

npx libretto connect http://127.0.0.1:9222 --session my-session
npx libretto connect http://127.0.0.1:9222 --read-only --session readonly-session
npx libretto connect http://127.0.0.1:9223 --session another-session

`session-mode`

npx libretto session-mode --session my-session

`snapshot`

npx libretto snapshot --session debug-example
npx libretto snapshot <ref> --session debug-example
npx libretto snapshot --session debug-example --page <page-id>

`exec`

npx libretto exec "await page.url()"
npx libretto exec "await page.locator('button:has-text(\"Continue\")').click()"
npx libretto exec --diff-snapshot "await page.locator('button:has-text(\"Continue\")').click()"
echo "async function textOf(selector) { return await page.locator(selector).textContent(); }" | npx libretto exec - --session debug-example
npx libretto exec --session debug-example "await textOf('h1')"

`pages`

npx libretto pages --session debug-example
npx libretto exec --session debug-example --page <page-id> "await page.url()"

`run`

npx libretto run ./integration.ts --params '{"status":"open"}'
npx libretto run ./integration.ts --provider libretto-cloud
npx libretto run ./integration.ts --cdp http://127.0.0.1:9222
npx libretto run ./integration.ts --cdp http://127.0.0.1:9222 --page page-1
npx libretto run ./integration.ts --read-only
npx libretto run ./integration.ts --stay-open-on-success

`resume`

npx libretto resume --session debug-example

`save`

npx libretto save app.example.com

`close`

npx libretto close --session debug-example
npx libretto close --all

Session Logs

Session state is stored in .libretto/sessions/<session>/state.json.

Session logs are JSONL files at .libretto/sessions/<session>/:

Use jq to query jsonl logs directly — for any filtering, slicing, or inspection task.

# Last 20 action entries
tail -n 20 .libretto/sessions/<session>/actions.jsonl | jq .

# POST requests with captured response previews
jq 'select(.method == "POST" and .responseBodyPreview != null) | {id, resourceType, status, contentType, url, requestBodyPreview, responseBodyPreview, responseBodyPath}' .libretto/sessions/<session>/network.jsonl

# Read a saved response sidecar
gunzip -c .libretto/sessions/<session>/raw-network/000001.response.json.gz | jq .

Action log (`actions.jsonl`)

Key fields: ts (ISO timestamp), source (user or agent), action (click, fill, goto, etc.), selector (locator used by the agent), bestSemanticSelector (canonical selector for user DOM events), success (boolean), url (navigation target), value (typed or submitted value), error (message on failure).

Read references/action-logs.md for full field descriptions and user-vs-agent entry semantics.

Network log (`network.jsonl`)

Libretto logs useful document, xhr, fetch, and non-noisy mutating requests; obvious static/media/tracking noise is skipped.

Key fields: id (incrementing request id), ts (ISO timestamp), pageId (page target id), method (HTTP method, e.g. GET, POST), url (request URL), resourceType (browser resource type, e.g. document, xhr, fetch), status (HTTP status code, or null for failed requests), statusText (HTTP status text), contentType (response content type), requestHeaders (request headers), responseHeaders (response headers), requestBodyPreview (inline request body preview), requestBodyPath (gzipped full request body sidecar path), requestBodyBytes (request body byte size), requestBodyTruncated (true when the request body exceeded the save limit), requestBodyOmittedReason (why the request body was not captured), responseBodyPreview (inline response body preview), responseBodyPath (gzipped full response body sidecar path), responseBodyBytes (response body byte size), responseBodyTruncated (true when the response body exceeded the save limit), responseBodyOmittedReason (why the response body was not captured), and errorText (request failure or body read error).

Examples

Building new browser automation workflows

Interactive building
<example>
[Context: The user wants to build a new browser workflow and does not yet know the page structure]
Assistant: I'll inspect the real site first if needed, but before I finish I'll create `target-workflow.ts` so the task produces reusable automation code.
Assistant: [Runs `npx libretto open https://target.example.com --headed`]
Assistant: [If sign-in is required, follows the authenticated workflow rules before continuing]
Assistant: [Reads `references/site-security-review.md` before choosing between passive network inspection, direct browser fetch calls, and Playwright-first automation]
Assistant: [Runs `npx libretto snapshot --session <session>`]
Assistant: [Uses `snapshot` and `exec` as needed to understand the site and decide the implementation path]
Assistant: [Reads `references/code-generation-rules.md` before writing production workflow code]
Assistant: I found the working path. I'll now create the workflow file and verify it.
Assistant: [Creates or edits `target-workflow.ts` following `references/code-generation-rules.md`]
Assistant: [Runs `npx libretto run ./target-workflow.ts --params '{"status":"open"}'` on a fresh, unauthenticated session to verify both sign-in and workflow behavior]
Assistant: [If sign-in validation passes and a reusable session is useful, adds an auth profile and reruns validation]
Assistant: Validation passed. Here are the results:
[Shows the output/results from the validation run]
To run it again, use: npx libretto run ./target-workflow.ts --params '{"status":"open"}'
</example>

Debugging existing workflows

<example>
[Context: The user has an existing Libretto workflow that is failing]
Assistant: I'll reproduce the failure first so we can inspect the exact browser state it leaves behind.
Assistant: [Runs `npx libretto run ./integration.ts --session debug-flow`]
Assistant: The workflow failed and Libretto kept the browser open. I'll inspect the page state before changing code.
Assistant: [Runs `npx libretto snapshot --session debug-flow`]
Assistant: [Runs `npx libretto exec --session debug-flow "...focused inspection or prototype..."`]
Assistant: [Reads `references/code-generation-rules.md` before patching the workflow file]
Assistant: I found the issue. I'll patch the workflow code and verify.
Assistant: [Edits `integration.ts` following `references/code-generation-rules.md`]
Assistant: [Runs `npx libretto run ./integration.ts` to validate the fix]
Assistant: Fix verified. Here are the results:
[Shows the output/results from the validation run]
To run it again, use: npx libretto run ./integration.ts
</example>

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.