Skip to content

Read the amount an agent pays whole and in its own currency - #1147

Open
r0c0y wants to merge 2 commits into
yetanotherbrowser:mainfrom
r0c0y:fix-agent-pay-amount
Open

r0c0y wants to merge 2 commits into
yetanotherbrowser:mainfrom
r0c0y:fix-agent-pay-amount

Conversation

@r0c0y

@r0c0y r0c0y commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What changes

When an agent presses Pay, the amount on the card and the pay sheet is the page's, whole and in its currency: R$1.234,56, not $1.23, and €1.299,00, not €1.29. Only US dollars count toward the spending limit, so a total in reais, Hong Kong dollars or pesos asks instead of being paid as dollars.

Fixes #1146

Why it happened

Two readings, one after the other:

  • The page script (about in AgentPermit.swift) took the amount with /(US)?[$€£]\s?\d[\d,]*(\.\d{2})?/. [\d,]* stops at a point that groups thousands, so 1.234,56 became 1.23, and only a US before the sign was kept.
  • AgentRules.dollars kept every digit and point of what it got, and checked for A$ and C$, which the script had already cut to $.

Now:

  • The script takes the letters right before the sign and the number to its last digit: /(\b[A-Za-z]{1,3})?[$€£]\s?\d(?:[\d.,]*\d)?/.
  • AgentRules.dollars counts an amount only when its sign is $ or US$, and reads the number through Calc.digits, the calculator's reading of grouped digits (Read 1,5 in the field's calculator as one and a half, not fifteen #1080): $1,234.56 and $1.234,56 are both 1,234.56. Anything it can't read gives nil, which asks.

Proof

  • Logic: tests that fail on main and pass here: swift test --filter "ReleaseGuardsTests|AgentHoldTests" (testOnlyUSDollarsCountTowardTheLimitAsWritten, testAnAmountIsHeldWholeWithItsCurrency)

I can't build Yab here (no Xcode), so I ran both changed pieces on their own:

  • about(), taken from AgentPermit.swift on main and on this branch, in Chromium (Playwright), on AgentHoldTests' page with the new form, then on a few checkouts:

    Total on the page main This branch
    Total R$ 1.234,56 (the new test's form) $1.23 R$1.234,56
    Order total $42.10 (the existing test's form) $42.10 $42.10
    Order total € 1.299,00 €1.29 €1.299,00
    Order total A$50.00 $50.00 A$50.00
    Order total HK$ 780.00 $780.00 HK$780.00
    Order total Mex$19.99 $19.99 Mex$19.99
    Order total $1,234.56 $1,234.56 $1,234.56
    Order total $42.10. $42.10 $42.10
    ORDER TOTAL$42.10 $42.10 $42.10
    button Pay US$42.10 US$42.10 US$42.10
  • AgentRules.dollars from both, compiled with Calculator.swift: the new unit test's lines fail on main for $1.234,56 (1.23), R$1.234,56 (1.23), HK$780.00 (780), MX$1,000.00 (1000) and Mex$19.99 (19.99), and all pass here.

AgentHoldTests itself runs in WebKit, which I couldn't run here; the page script is the same one I ran in Chromium.

Checked on

  • Yab Dev built from this branch on macOS: not built here (no Xcode). Run as above on macOS 27.2.1, Swift 6.2.1 and Playwright's Chromium.
  • Engine(s) tried: the page script in Chromium (Playwright); WebKit through AgentHoldTests, not run here

Checklist

  • swift test passes (or the suites this touches: list them): ReleaseGuardsTests, AgentHoldTests; not run with swift test here, see above
  • ./design-check --head is clean, or each exception says why with // design:
  • Anything that changes how Yab looks was approved in the issue first (only the amount's text, which was wrong)
  • A new menu item is also a command in the field; a new Settings row is classified in NativeActions.swift (none)
  • Words on screen and in docs are American English, with no em dashes

A total written with its sign after the number (1.299,00 €, as in German and French) still has no amount, as before, and so asks. Reading those too would be a separate change.

Written by an AI coding agent (Claude Code, Claude Opus 5.5) at my request.

The page script took a payment's amount with /(US)?[$€£]\s?\d[\d,]*(\.\d{2})?/,
which stops at the first point of a number grouped with points and
leaves out the letters before the sign. "Total R$ 1.234,56" (Brazilian
reais, about 220 US dollars) was held as "$1.23", and "€ 1.299,00" as
"€1.29": the card and the pay sheet asked for those amounts, and
AgentRules.dollars counted $1.23 under the spending limit, so an agent
paid it without asking. The A$ and C$ check there never saw the A or C.

The script now keeps the letters before the sign and the number to its
last digit. AgentRules.dollars takes only "$" and "US$" as dollars and
reads the number through Calc.digits, so "$1.234,56" is 1,234.56.
@r0c0y
r0c0y requested a review from serafimcloud as a code owner November 25, 2026 14:29
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Critical impact] The change affects when an agent can pay without asking the person.

Fix mixed-case currency prefixes before merging so non-US payments cannot skip approval.

Findings

  1. P1 Pesos can skip approval ▶

Summary

Keeps grouped digits and currency prefixes in payment amounts, then uses Calc.digits to read US-dollar totals.

  • Agent payment prompts keep the page’s whole amount and currency.

Deferred scope: r0c0y explicitly deferred currency signs after the number as a separate change.

Reviews (1) · Last reviewed commit: "Read the amount an agent pays whole and ..." · Reviewed by Greptile

Comment thread Sources/Fast/AgentPermit.swift Outdated
// the total's line of its form or page, or the line under it. Whole,
// with the letters before its sign (US$, A$, R$) and its digits as
// written: "€ 1.299,00" was read only to its first point, €1.29.
const cash = /(\\b[A-Z]{1,3})?[$€£]\\s?\\d(?:[\\d.,]*\\d)?/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Pesos can skip approval

For Total Mex$19.99, [A-Z]{1,3} cannot match the mixed-case prefix, so cash falls back to $19.99. dollars accepts that as US dollars, and Bench.decide can pay without asking under a $20 limit. Preserve mixed-case currency prefixes, or reject the amount rather than falling back to a bare dollar sign.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed in c71f8e2: the prefix is [A-Za-z]{1,3} now, so Total Mex$19.99 is held as Mex$19.99, and AgentRules.dollars gives nil for it, which asks. \b still keeps a longer word out of the prefix: Total$5 is $5, as before. Mex$19.99 is in the unit test, and the Chromium run of about() gives Mex$19.99 here ($19.99 on main).

[A-Z]{1,3} left Mex$19.99 as $19.99, counted as US dollars (review).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents: a payment's amount is cut at its first point and loses its currency, so R$ 1.234,56 is paid as $1.23 under the limit

1 participant