Packages Source: packages/cli/README.md

@tote/cli

On this page (10 sections)

The tote command line. Design: ADR-001.

On npm: tote-agent. Release steps: scripts/release.md.

Commands:

  • tote ask (task T-09b) runs the Tote agent on a shopping request: search, compare against your constraints, build a cart, start checkout and hand off to the merchant. Tote never pays.
  • tote search (task T-09a) runs one Shopify Global Catalog search through @tote/core and prints the offers found.
  • tote web (task T-18) serves a local page on 127.0.0.1 that runs the same agent as tote ask. See tote web.

Model providers: anthropic, openai, google and openrouter (task T-09c). See Models.

Run

From the repo root:

npx -y pnpm@10.20.0 --silent --filter tote-agent tote ask "trail running shoes in size 10 under 100.00 USD"
npx -y pnpm@10.20.0 --silent --filter tote-agent tote search "trail running shoes" --limit 5

or directly with Node (22.19 or newer):

node packages/cli/bin/tote.js ask "trail running shoes in size 10 under 100.00 USD"
node packages/cli/bin/tote.js search "trail running shoes" --max-price 150 --currency USD --ships-to PL

There is no build step yet. bin/tote.js runs the TypeScript source with Node's built-in type stripping and a small resolve hook that maps the source's ./x.js imports to ./x.ts. A build to dist/ replaces it when the packages get one (ADR-001 decision 2).

Options

tote ask <request> [options]

--model <provider:model>  Model to use (default: TOTE_MODEL)
--buyer-ip <address>      Your public IP address (default: TOTE_BUYER_IP)
--ships-to <country>      Delivery country, ISO 3166-1 alpha-2, for example PL
                          (default: TOTE_SHIPS_TO in .env). Adds a ships-to
                          constraint marked "at checkout": the merchant confirms
                          delivery after you enter your address, so an offer that
                          meets the rest is satisfies_pending_shipping
--show-handoff            Print the merchant link even when stdout is not a terminal
--max-steps <n>           Model steps, 1 to 50 (default 12)
--max-tool-calls <n>      Tool calls, 1 to 200 (default 30)
--timeout <seconds>       Run time limit, 1 to 1800 (default 120)
--json                    Print the result as JSON (never contains the merchant link)
-h, --help                Show this help

Model providers for --model and TOTE_MODEL, with the .env variable of each key:
  anthropic:<model>         ANTHROPIC_API_KEY (claude-sonnet-5-5, claude-haiku-5-5)
  openai:<model>            OPENAI_API_KEY (gpt-6.1-sol, gpt-6-luna)
  google:<model>            GOOGLE_API_KEY and GOOGLE_API_TIER=paid
                            (gemini-3.8-flash, gemini-3.5-flash-lite)
  openrouter:<org>/<model>  OPENROUTER_API_KEY, any OpenRouter model slug,
                            for example openrouter:anthropic/claude-haiku-5.5

tote search <query> [options]

--limit <n>            Products per page, 1 to 50 (default 10)
--max-price <amount>   Price ceiling in major units, for example 89.99 (needs --currency)
--currency <code>      ISO 4217 code of --max-price, for example USD
--ships-to <country>   ISO 3166-1 alpha-2 delivery country, for example PL
--json                 Print the rows as JSON
-h, --help             Show this help

tote web [options]

--port <n>             Port on 127.0.0.1, 1024 to 65535 (default: a free port)
--model, --buyer-ip, --ships-to, --max-steps, --max-tool-calls, --timeout
                       As for ask, applied to every request from the page

Flags of one command are refused on the others. The request of tote ask is at most 2000 characters. Currency and country codes of tote search are upper-cased before core parses them, so usd and pl work. A negative or otherwise invalid amount is refused before any request.

Configuration

The CLI loads .env from the current directory, then from the repo root, with process.loadEnvFile. A variable already set in the shell wins over .env, and the current directory wins over the repo root. Exact lines:

# Required. The https URL of the Tote agent profile (ADR-001 decision 3, human task H-04).
TOTE_AGENT_PROFILE_URL=https://<domain Tote controls>/<path to the agent profile>.json
# Optional, both or neither. Dev Dashboard client credentials select the Token tier.
SHOPIFY_CLIENT_ID=<client id>
SHOPIFY_CLIENT_SECRET=<client secret>
# tote ask only. Required at the Token tier: your own current public IPv4 or IPv6 address.
TOTE_BUYER_IP=<your public IP address>
# tote ask only. Required unless --model is passed. Form provider:model.
TOTE_MODEL=<provider>:<model>
# tote ask only. Optional. Your delivery country, ISO 3166-1 alpha-2, for example PL.
TOTE_SHIPS_TO=<country code>
# tote ask only. The key of the provider in TOTE_MODEL (see Models).
OPENROUTER_API_KEY=<key>

Each model provider needs its own key; see Models.

  • Without TOTE_AGENT_PROFILE_URL the CLI stops with exit code 2 and names the variable. Core also refuses every UCP call without it.
  • With neither credential set (or both empty, as in .env.example), the run uses the Anonymous tier and core prints a warning on stderr: Anonymous access shares one rate-limit pool with all unauthenticated traffic and is not for production. Checkout is not available at the Anonymous tier; tote ask still hands off the cart.
  • With only one of the two credentials set, the CLI stops with exit code 2.
  • The client secret becomes a core Secret when it is read. It is never printed or logged.
  • TOTE_BUYER_IP: at the Token tier Shopify requires the buyer's IP on every cart and checkout call to a shop (Shopify-Buyer-IP), and there is no default. Without it tote ask stops with exit code 2 before any request and names the variable. Core's parser refuses loopback, private, link-local, documentation and other non-public addresses; the error names the variable or --buyer-ip and never echoes the value. Tote never looks your address up with a third-party service. --buyer-ip overrides the variable for one run.
  • TOTE_SHIPS_TO or --ships-to (the flag wins): adds a ships to <country> constraint and sends the country as search and cart context. Tote never reads a country from the request text. Catalog data has no shipping destinations, so the constraint is marked at checkout (status deferred): the merchant confirms delivery after you enter your address at checkout. An offer meeting every other constraint is satisfies_pending_shipping and can be carted and checked out. The constraint becomes UNMET only when the store reports address_undeliverable. An invalid code stops with exit code 2 and names the flag or variable.
  • TOTE_MODEL or --model: provider:model, for example anthropic:claude-sonnet-5-5. An unknown provider or a malformed id stops with exit code 2 and lists the providers this build can run. Only adapters that send the provider's no-training option can run (ADR-001 decision 7); any other is refused with exit code 2.

Models

TOTE_MODEL or --model is provider:model. The CLI splits at the first colon.

ProviderExample.env variablesModels
anthropicanthropic:claude-sonnet-5-5ANTHROPIC_API_KEYclaude-sonnet-5-5, claude-haiku-5-5
openaiopenai:gpt-6-lunaOPENAI_API_KEYgpt-6.1-sol, gpt-6-luna
googlegoogle:gemini-3.8-flashGOOGLE_API_KEY, GOOGLE_API_TIER=paidgemini-3.8-flash, gemini-3.5-flash-lite
openrouteropenrouter:anthropic/claude-haiku-5.5OPENROUTER_API_KEYany OpenRouter model slug, organization/model[:variant]
  • anthropic, openai and google run the Index v0 models only, with the effort settings and prices in INDEX_V0_PRESETS (@tote/agent). Another model id stops with exit code 2 and lists the known ones.
  • google also needs GOOGLE_API_TIER=paid: your statement that the key belongs to a Google Cloud project with an active billing account. Google uses free-tier API content to improve its products, so Tote does not run on a free-tier key.
  • openrouter passes the slug through and sends "provider": {"data_collection": "deny", "zdr": true} on every request, so OpenRouter routes only to zero data retention endpoints (sources in packages/agent/README.md, section OpenRouter). A model with no such endpoint fails with HTTP 503 after retries. Cost per step is OpenRouter's own usage.cost, in credits. Use the exact slug from OpenRouter's model list.
  • A missing or empty key stops with exit code 2 before any request and names the variable. Keys become core Secrets when read and are never printed or logged.

Output of tote ask

Constraints Tote checks:
  [1] price <= 100.00 USD
  [2] Size = 10

TITLE             PRICE       SHOP                           VERDICT    [1]    [2]
Trail Runner Pro  89.99 USD   example-running.myshopify.com  satisfies  met    met
Trail Runner Pro  89.99 USD   example-running.myshopify.com  violates   met    UNMET
Trail Runner Max  129.99 USD  example-running.myshopify.com  violates   UNMET  met

Answer:
Trail Runner Pro, size 10, 89.99 USD. Handoff: handoff_...

Next step:
  example-running.myshopify.com: cart ready, finish at the merchant.
    https://<merchant link>
  • Constraints are read from the request by @tote/agent's deterministic extraction. Each compared offer gets one mark per constraint: met, UNMET, unknown or at checkout (ships-to only). Unknown is never met. The verdict is satisfies (all met), satisfies_pending_shipping (all met except ships-to, which the merchant confirms at checkout), incomplete (some unknown) or violates (some unmet), and rows are sorted in that order. Exit code 0 covers both satisfies verdicts. With a ships-to constraint the output adds the note "Delivery to your country is confirmed by the merchant after you enter your address at checkout."
  • Notes: what extraction could not read with certainty, for example Note: A budget is mentioned but no amount could be read, so no offer counts as within budget. Restate it, for example "under 100.00 USD". A denied or accepted constraint gap also gets a note, and so does a cart or checkout that could not be built because of Shopify, the network or configuration, for example Note: A cart could not be built: the store call failed. The cause is on stderr; run again later.
  • Product titles go through core's sanitizer and are shown only in the TITLE column. The model's answer is printed with control, format and bidi characters removed, so it cannot send terminal escape sequences.
  • Next step: one handoff per cart. A checkout replaces the cart's own link. A checkout that needs the buyer (requires_escalation) shows as finish at the merchant: the checkout needs you to continue there.
  • The merchant link (continue_url) is printed only when stdout is a terminal or with --show-handoff (ADR-001 decision 7). Otherwise the line says the link is hidden and shows the handoff reference. The link exists only in this process's memory, so a hidden link cannot be recovered later. stderr never contains it.
  • --json prints model, outcome, answer, constraints, notes, extractionNotes, offers (title, ids, shop, price, verdict, per-constraint checks with evidence), carts, handoffs (handoff reference, shop, kind: cart, escalation, ready or incomplete, and action), toolFailures (tool and code: rate_limited, upstream, agent_profile_required or buyer_ip_required), override counts, steps, usage and durationMs. It never contains the merchant link, with or without --show-handoff; the two together print a notice on stderr that --show-handoff has no effect.
  • Progress goes to stderr: one line per tool call (tote: search ok), override decisions, and a final line with model steps and token counts.

Constraint gaps: the agent can ask to put an offer that does not meet every constraint into a cart. When stdin and stderr are terminals, the CLI shows the per-constraint marks on stderr and asks Accept these gaps and build the cart? [y/N]; only y or yes accepts. Otherwise every such request is denied (OverridePolicy deny).

One row per offer (product variant), because price, seller and availability belong to the variant in the Global Catalog:

TITLE             PRICE      SHOP                           AVAILABLE
Trail Runner Pro  89.99 USD  example-running.myshopify.com  yes
  • TITLE is the product title after core's sanitizer (control, format and bidi characters dropped, < and > escaped), with line breaks folded into spaces and cut at 60 characters. Product text is data and is shown only in this column.
  • SHOP is the seller domain core parsed from the response, or (not stated).
  • AVAILABLE is yes, no or unknown when the response does not state it.
  • --json prints the same fields as an array of { "title", "price": { "amount", "currency" }, "shop", "available" }, where shop may be null and available is true, false or "unknown".

Results go to stdout. Warnings and errors go to stderr, one line each, with a hint. Search has no continue_url, so the CLI never prints one.

Exit codes

CodeMeaning
0ask: a handoff, or an offer meeting every constraint. search: offers found. Or --help
1ask: the run finished but no offer met every constraint. search: no offers
2Bad flags or configuration (profile URL, credentials, buyer IP, model, adapter refused)
3UCP or network error after core's retries, a model call failure, or a run limit reached

In tote ask every Shopify call runs inside an agent tool, which reports a failure to the model as data. The CLI still records it: a missing or refused agent profile or a missing buyer IP gives exit 2 and names the variable; any other Shopify or network failure gives exit 3 when the run ends without a handoff, with one stderr line naming the tool, for example tote: search failed. Shopify rate limited the request. Retry after 7 s. Hint: .... A failure the run recovered from (a later call succeeded and a handoff was made) keeps exit 0.

A rate limit prints the wait Shopify asked for, for example tote: Shopify rate limited the request. Retry after 120 s. Hint: .... Core retries waits up to 30 s itself (ADR-001 decision 4).

Tests

npx -y pnpm@10.20.0 test runs offline: core's network guard makes fetch, sockets and DNS throw. tote search tests run the CLI entry point with an offline client over a FixtureTransport and core's recorded Global Catalog example. tote ask tests run the same entry point with a scripted fake model adapter; search and create_cart go through a FixtureTransport (core's documented create_cart example), and create_checkout is a core test fake returning an escalation, because core's offline client is Anonymous only and refuses checkout. Covered: happy path to a HandoffRef, link shown on a TTY or with --show-handoff and never in --json, escalation, override denied off a TTY, override confirmed and declined on a TTY, missing and invalid buyer IP, model selection errors, an adapter without the no-training option, the unparsed budget note, run limit and model failure exit codes, and terminal escape sequences in product titles and the model's answer.

Shipping and withdrawn handoffs

When a store reports that it cannot deliver a cart (merchant message code address_undeliverable), the agent cancels the cart and its checkout and withdraws the cart's handoff. tote ask then prints neither link and says on stderr "the store cannot deliver one cart to your address; Tote cancelled it." Only handoffs the run still holds are printed. A checkout that only lacks an address (delivery_address_required) keeps its handoff: delivery is checked after you enter your address at the merchant.

tote web

tote web starts a local page and prints its address, then runs until Ctrl+C (exit code 0). It opens nothing by itself.

node packages/cli/bin/tote.js web
node packages/cli/bin/tote.js web --port 8765 --ships-to PL

How it is protected:

  • It binds to 127.0.0.1 only. The address is http://127.0.0.1:<port>/<token>/, where the token is 32 random bytes in base64url, made at each start. Every request whose path does not start with the token gets 403, the favicon included.
  • The Host header must be 127.0.0.1:<port> or localhost:<port>, against DNS rebinding.
  • api/ask, api/handoff, api/browse and api/cart take POST only, with the page's Origin and a JSON body of at most 16 KiB. No CORS headers are sent, so other sites cannot read any answer.
  • Every response has Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' https://cdn.shopify.com; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none', Referrer-Policy: no-referrer and Cache-Control: no-store. The only outside requests the page can make are product images from cdn.shopify.com.
  • The page (web/index.html, web/app.css, web/app.js) sets every value with textContent. Product text arrives already sanitized by core, with < and > as entities, and is shown exactly as the terminal shows it. Image sources must start with https://cdn.shopify.com/ and links with https://, or they are left out.

Browse mode (T-19), the default tab: the page posts { query, maxPrice?, currency?, shipsTo?, cursor? } to api/browse, which runs one search_catalog call (Global Catalog, 24 results, ships-to defaulting to --ships-to or TOTE_SHIPS_TO) and answers { cards, nextCursor }. No model is called. Each "Load more" sends the cursor back. A card holds the product's first offer: title, price, number of offers, seller name and public domain (the host of seller.url unless it is a myshopify.com domain; null otherwise, shown as "Shopify store"), description (plain text, at most 300 characters), the first image, rating (value, scaleMax, count) and the product page link. Core keeps an image only from cdn.shopify.com and a product link only on the seller's shop or storefront host. A card also lists every offer in variants[]: variantId, label (the variant title, or its options), price, available, seller and shop (the shop that sells it, or null when the catalog names none; such an offer cannot go in a cart).

Browse carts (T-25): "Add to cart" on a card picks one offer (option select when there are several) and a quantity from 1 to 10. The picked items stay in page memory only. The cart panel groups them by shop and shows a subtotal per currency, never converted. "Go to cart at <seller>" posts { shop, lines: [{ variantId, quantity }] } to api/cart, which:

  • accepts only offers api/browse returned in this process with that shop. The server keeps each returned offer's variant id and shop in memory (at most 5000, oldest forgotten first) and nothing else; a variant returned with two different shops is refused. Anything else gets 403 before any store call, so the page cannot build an arbitrary cart.
  • checks 1 to 10 lines, no repeated variant, and whole quantities from 1 to 10 (else 400).
  • allows 10 requests a minute (then 429 with Retry-After).
  • calls core createCart once with exactly those lines, the buyer IP (TOTE_BUYER_IP or --buyer-ip, required at the Token tier as in tote ask) and the ships-to country as cart context. A cart whose lines or quantities differ from the request, for example because an item is out of stock, is cancelled and refused (502). Core errors come back as core's fixed message and hint: 429 for a rate limit, 400 for configuration or input, 502 otherwise.
  • answers { url } with the cart's continue_url, which Shopify documents as the link "that the buyer can use to pick up the cart on the merchant's storefront" (https://shopify.dev/docs/agents/carts-and-checkout/cart-mcp). Tote never builds cart links itself.

In ask mode each compared offer is shown as the same card, with its verdict and its marks. tote ask --json and the page's result carry these fields as offers[].card when the catalog gave them.

How a request runs: the page sends the request to api/ask, which runs the agent as tote ask does and streams NDJSON lines: progress (the lines tote ask writes to stderr, without tote: ), then one result with the exit code and the same view as tote ask --json, plus a run id. Each handoff has "Go to cart" (the cart's handoff, kept as cartHandoff when a checkout replaced it) and, for a checkout, "Go to checkout". Their link is fetched from api/handoff only on the click.

One click opens a merchant link, in Ask and in Browse: the click handler opens a blank tab at once (so the browser does not block it as a pop-up) and sets its opener to null, which has the effect of rel="noopener" (window.open cannot take noopener and still return the tab). Then the page fetches the link and sends the tab there, only for an https link. On any failure the tab is closed and the error is shown next to the button. The link is never put on the page. The server writes nothing per request: the terminal shows only the address line, and the link is never in the progress stream, NDJSON, HTML or any output.

Limits: one request at a time (a second one gets 409), the last 20 runs' links stay available, and nothing is kept after the process stops. The page uses OverridePolicy deny: a constraint gap is never accepted there.