Marketplace CLI.
A command line for an AI agent that finds the cheapest offers, other sellers, similar items, specs and review statistics on two Belarus marketplaces, with prices in the local currency and delivery to the capital. Every call prints one JSON envelope with a single error table, and shop data is read through a real browser.
- Year
- 2026
- Personal project
- My part
- Sole developer
- Website
- Not public
- No public link
My role
I wrote the whole command line alone, for my own daily use with an AI agent.
Capabilities
Shop commands
- Cheapest offers from both marketplaces searched in parallel, with filters and a funnel of what each one removed
- Other sellers of the same product and similar items
- Card details, variants and full specs for several products at once
- Review statistics for chosen products or for the top results of an earlier search
Agent contract
- One JSON envelope per call, for success and failure alike
- A single error table of 15 codes with a person-needed flag, retry flag, user message and agent instruction
- Time budget that ends before the caller's limit, with a list of what remains to re-run
- Exit codes ordered so that a site needing the user outranks a partial result
Reading and ranking
- Pages read from a persistent real browser profile per shop, with recovery when a page does not answer
- Score from price, review-weighted rating and review count, returned with its parts
- Review reading with an exact or estimated low-star share and a defect-word count
Quality
- 50+ tests on captured shop replies, and a doctor command that checks both shops, the delivery city and the hidden window
Patterns and decisions
- The caller is an AI agent, not a person. Every design choice starts from what a program with a hard time limit, a small reading budget and no way to ask a follow-up question needs from a command.
- The tool is TypeScript on Bun, close to 1,400 lines, with one runtime dependency, Playwright. The syntax is limited to what Node can also run, so the code stays portable.
- Layers are kept thin. A command line entry calls commands, commands call a run object that holds the time budget and opens browser sessions only when needed, and site adapters sit on top of pure parsers of the shops' data.
- Browser profiles, saved runs and raw dumps live in a home folder outside the repository.
- Requests to each shop are queued with a pause between them.
Cases
A command line built for a caller that is an AI agent. The agent has a hard 120 second limit and cannot ask what went wrong, while the shops fail in ways that sometimes need a human. Every command prints one JSON envelope, for success and failure alike. A single table of 15 error codes states for each one whether a person is needed, whether a retry makes sense, what to tell the user in plain Russian and what the agent should do next. A time budget ends before the caller's limit. A loop over many products stops in time and returns what is done plus a list of what remains to re-run. Output too large for the reading cap goes to a saved run that the envelope points to. Exit codes are ordered so that "a site needs the user" outranks "partial result".
Reading shop data from inside a real browser. Both shops answer a plain HTTP client with a check page. I kept a persistent browser profile per shop and sent every request from inside a loaded page of that shop, so the data is read the way a visitor sees it. One shop works without a window. The other needs a real one, so I parked it off every monitor and added a doctor command that warns if some monitor would still show it. When a page does not answer, the session reloads the home page and retries a few times, then stops with a named error and a message that says what to do. A second call while the browser is in use gets an immediate "busy" answer. When the Windows session is locked and a shop returns an empty list, the tool reports a locked screen instead of "nothing found".
"Cheapest" is not "best". Neither shop shows how often something was bought, price sorting favours junk, and an average over three reviews means little. I scored each offer out of 100: price against the cheapest at half the weight, rating pulled toward the mean of the results at 30 percent, and a log-scaled review count as the stand-in for demand at 20 percent. The parts come back with the score. Filters normalise spelling, including Cyrillic and Latin unit forms, and a funnel shows how many offers each filter removed. For reviews, the low-star share is exact when the shop publishes the distribution and labelled an estimate when it does not. A count of defect words in a hand-built Russian list catches complaints written under a good rating. Variants merged into one card are detected so the same reviews are not counted twice.
Tests without the shops. The browser cannot run in a test, and the shops change. The parsers are tested on 50+ checks over captured shop replies, and the adapters run over a fake transport that serves those replies. The real browser path is checked live, by hand.