> Agent-ready spec from Diff of the Day (2026-12-02, playbook 1). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: State-in, state-out web tools for agents

## Problem Statement
Agents that drive a web page by screenshots are slow, cost more and fail more often than agents that call real functions. Shopify measured 27.4 seconds and 56 of 60 successes for browser automation against 10.3 seconds and 60 of 60 for WebMCP tools. A small team has no such comparison for its own app.

## Goals
- Expose 3 actions of one app as agent tools with schemas.
- Make repeated calls harmless: the same call twice leaves the same state.
- Compare the tools with a browser-automation agent on 20 attempts each.
- Report time, cost and success rate for both paths.

## Non-Goals
- Production rollout: the first version is a demo app, because browser support for WebMCP may need a flag or an origin trial.
- Bot authentication: signing agent requests is a separate problem that Shopify also lists as open.
- Covering every page: three actions are enough to measure the gap.

## User Stories
- As a maintainer, I want one tool call per action so that an agent does not click through the page.
- As the owner of the app, I want the risky action to need a person so that an agent cannot spend money alone.
- Edge case: as an agent, I want an error when the state changed outside my tool, so that I read the new state and retry instead of overwriting it.

## Requirements
### P0
- Three tools with input and output schemas where the input is the full state and the output is the new state.
  - [ ] Calling a tool twice with the same input gives the same result.
  - [ ] A change made outside the tools makes the next call return a clear error.
- A consequential marker on the risky tool and a person confirmation step.
  - [ ] The risky tool does nothing until a person confirms.
  - [ ] The marker is part of the tool description data.
- A comparison script that runs 20 attempts through the tools and 20 through browser automation.
  - [ ] Each attempt records time, cost and pass or fail.
  - [ ] The report shows both paths side by side.

### P1
- Deterministic tests for each tool in CI.
  - [ ] A failing tool test fails the build.
- A log of every tool call with its duration.
  - [ ] The log has no personal data.

### P2
- A second app page that reuses the same tools.
  - [ ] No tool code is copied.

## Success Metrics
- Seconds per attempt, both paths.
- Cost per attempt, both paths.
- Successes out of 20, both paths.

## Open Questions
- Which browser build and flag exposes WebMCP today?
- How do you price the browser-automation path fairly?
- What should a tool return when the confirmation is pending?

## Timeline
Two days: tools and error checks on day one, confirmation step and comparison on day two.

## Agent Instructions
- Suggested stack: A small web app you own, TypeScript, the WebMCP browser API, one browser-automation agent for the baseline.
- Build order: Demo app, first tool, state check, second and third tool, confirmation, comparison script, report.
- Safety: Use a demo app with fake data and test payment values only; read keys from the environment; keep the person confirmation on; never point the comparison at a live store.
- Done when: The report compares 20 tool attempts with 20 browser-automation attempts on time, cost and success, and the risky action never ran without a person.

## Sources
- https://shopify.engineering/webmcp
