# Operator bridge How to sweep wallet cash to the pre-registered bank account through the vendor's own page. Decision: **ADR-0033**. This is **opt-in and unsupported**. Read the ADR's risk paragraph before turning it on. The bridge exists because no API moves money: INDmoney's Global API has no withdrawal call and IBKR's retail gateway has no funding call. It drives the vendor's web page in a browser profile you unlocked by hand, and it stops for you at the login and at the payment/2FA step. **The surface split (ADR-0033 amendment, 2026-11-30).** The Indian brokerage wallet (INDstocks / INDmoney investing) can load and withdraw **over the web**, so it is the one browser flow. The US wallet (INDmoney Global) is **app-only**: the bridge refuses it at construction and the message says the US leg needs the app or a handoff. IBKR is refused as **not implemented** — its retail APIs cannot move cash, and this bridge has no portal flow. Do not point this tool at either and hope. ## What it will not do - It has no password field and stores no credential. The session is the browser profile you unlocked. - It cannot read an SMS and does not mint a TOTP for this flow. - It cannot add or change a beneficiary. The flow loader refuses such a step and the page is checked for an "add/change account" control before proceeding. - It cannot load a wallet. Both flows are wallet → bank; loading is a bank-side push with its own declaration, and the refusal says so. - It does not log in unattended. A dead profile means you run `unlock` again. - It does not screenshot. The audit trail is timestamp, step id, action, page title and URL. ## 1. Turn it on ```sh export TAPEBOOK_OPERATOR_BRIDGE=1 export TAPEBOOK_BRIDGE_DIR="$HOME/.config/tapebook/bridge" # optional; this is the default export TAPEBOOK_BRIDGE_MAX_WITHDRAWAL=100000 # per-run cap in INR; default ₹1,00,000 ``` Install the browser only on the machine that will run the sweep. Playwright is deliberately not a dependency of the desk: ```sh uv pip install playwright uv run playwright install chromium ``` Check that the switch is really off by default elsewhere: without `TAPEBOOK_OPERATOR_BRIDGE=1`, every `tape bridge withdraw` refuses with `the operator bridge is off`. ## 2. Unlock the profile once ```sh tape bridge unlock ``` This opens a headed browser at the flow's first page and waits. Log in to the vendor, complete any login OTP or app approval **in that window**, then press Enter in the terminal. The profile is kept under `$TAPEBOOK_BRIDGE_DIR/profile`; later runs reuse it. If the vendor logs the session out, run `unlock` again — there is no unattended login. ## 3. Prove the flow with a dry run The shipped Indian-broker flow (`indian-broker-wallet-to-bank.yaml`) is **unverified**: every selector is a placeholder. A dry run walks the flow to the review screen and stops before the submit button. Unlock the profile at the Indian investing web app first (`tape bridge unlock` opens the flow's first page, the funds screen). ```sh tape bridge withdraw \ --amount 1000 \ --reference dry-run-q4 \ --expected-by 2026-12-31 \ --dry-run ``` What to check, in order: 1. No step failed. If one did, the message names the step and the page it saw, for example `step 'read-withdrawable' expected a readable element "[data-testid='withdrawable-balance']", but the page was 'Funds' at https://…`. 2. The printed **request** amount is the amount you asked for. 3. The printed **destination** is the account you expect, including its last four digits. 4. The printed **withdrawable at confirmation** matches the withdrawable figure on the Indian web app. (It must be the vendor's withdrawal figure, not "available to invest".) 5. The run ends at `stopped before step 'submit-withdrawal'`, and the browser has not submitted anything. Correct `src/tapebook/adapters/bridge/flows/indian-broker-wallet-to-bank.yaml` for each failure, then run the dry run again. The three things the dry run must settle before the flow is trusted: - **Page URL** — the funds/withdraw screen the logged-in profile actually lands on. - **Withdrawable label** — the text/selector that shows the withdrawal balance (INDstocks calls it `withdrawal_balance` on `GET /funds`). - **Review screen** — the last screen before the request is sent, and that the destination shown is the registered bank account. When the dry run reaches that screen with the right destination, change `verified: false` to `verified: true` **and record what you changed in this runbook or the gap ledger**. Until that dry run passes, GAP-090/GAP-094 stand. ## 4. The live sweep ```sh tape bridge withdraw \ --amount 25000 \ --reference q4-2026-sweep \ --expected-by 2026-12-05 ``` There are two human gates in the run: 1. **Confirmation.** The terminal prints: ```text Withdraw INR 25000.00 to . The page reports INR withdrawable. The desk will click the vendor's confirm button after this answer, and a submitted withdrawal cannot be recalled from here. Type 'withdraw' to confirm, or anything else to stop: ``` Type exactly `withdraw`. Anything else stops the run with nothing submitted. 2. **Payment/2FA.** After the confirm button the flow pauses: ```text The withdrawal has been requested. Approve it in the INDmoney investing app or enter the OTP in the browser window. The desk cannot read your SMS and will resume when you press Enter. ``` Complete the vendor's own approval in the visible window, then press Enter. The flow then asserts the success page. Do not leave a live run unattended: the pause waits on the terminal. ## 5. Stop a run From another terminal: ```sh tape bridge kill ``` The running bridge checks the kill file between steps and aborts the browser session. It cannot interrupt a network request already in flight, and it **cannot recall a withdrawal already submitted** — it only stops what has not happened yet. Clear it when you are ready: ```sh tape bridge kill --clear ``` ## 6. Reconcile SENT, then RECEIVED A submitted sweep is an outbound `ExpectedCredit` in `PLANNED`. It cannot become `RECEIVED` from the wallet; only a bank line can do that. **Which balance proves what.** | Observation | Source | Proves | |---|---|---| | `withdrawal_balance` **falls** by at least the amount | `GET https://api.indstocks.com/funds` (read with the INDstocks token) | **SENT** — the Indian wallet released the money. `wallet_read_from_indian_funds`/`reconcile_indian_funds` parse and apply it. | | The funds page's withdrawable label falls | The browser page | Corroboration only. The page can lag the ledger; it is not the reconciliation input. | | `eq_cnc` changes | `GET /funds` → `detailed_avl_balance.eq_cnc` | Nothing. That is buying power, not a withdrawal figure. Do not feed it to `--withdrawable`. | | The bank statement shows the credit | Your bank, read by you | **RECEIVED**. No vendor wallet can establish this. | After the withdrawal, read `/funds` and pass its `withdrawal_balance` to the reconciler: ```sh tape bridge reconcile q4-2026-sweep --withdrawable 75000.00 ``` (Omit `--pending` unless the vendor's page shows a pending figure; the Indian wallet's `/funds` read has no pending field.) This records `SENT` and prints what the wallet read established. When the bank statement shows the credit: ```sh tape bridge bank-credit q4-2026-sweep --amount 25000.00 ``` That records `RECEIVED` if the amount matches. A different amount becomes `MISMATCH` and is credited as zero until a person accepts it; the desk never absorbs a shortfall into a return. The US wallet is not part of this reconciliation: it is app-only, and its `GET /v1/wallet` read belongs to the remittance runbook (`docs/runbooks/remittance.md`), not this bridge. Both commands keep the plan in `$TAPEBOOK_BRIDGE_DIR/withdrawal-.json`. There is no database table for it in this lane (GAP-091), so treat that directory as the record and back it up with the rest of the machine. ## Flow file shape A flow is a YAML list of steps. Each step is one action plus the text that proves the page reached the expected state. A site change is a data fix. ```yaml vendor: indian-broker # the only vendor with a browser flow (app/bridge.py's VENDORS table) name: wallet-to-bank verified: false # stays false until the dry run above has passed steps: - id: open-funds action: navigate url: "https://www.indstocks.com/app/funds" expect: "Withdraw" - id: read-withdrawable action: read selector: "[data-testid='withdrawable-balance']" capture: withdrawable - id: assert-registered-beneficiary action: guard text: "Registered bank account" forbidden: ["Add bank account", "Add beneficiary"] - id: enter-amount action: fill selector: "input[name='amount']" value: "{amount}" - id: submit-withdrawal action: click selector: "[data-testid='confirm-withdrawal']" submits: true # exactly one step may carry this - id: pause-for-otp action: pause prompt: "Approve it in the vendor app, then press Enter" ``` Rules the loader enforces: - every step has a unique `id`; an unknown action or a missing field names the file and step; - exactly one (or zero) `submits` step; - a `guard` step needs `text` and at least one `forbidden` entry; - any `click`/`fill`/`navigate`/`expect` that targets an add/change-beneficiary control is refused when the flow is built, not when it reaches the page; - a `{placeholder}` in `value` or `url` must be supplied by the bridge (`{amount}` is), or the run fails naming the step and the missing key. ## Security notes - The profile directory is an authenticated session on disk. Protect it with full-disk encryption and directory permissions; anyone who can read it can act as you at the vendor without a password (GAP-093). Delete it (`rm -rf "$TAPEBOOK_BRIDGE_DIR/profile"`) to revoke local access, and log out at the vendor for a server-side revocation. - The audit log at `$TAPEBOOK_BRIDGE_DIR/audit.jsonl` contains timestamps, step ids, page titles and URLs. Account-like digit runs in the destination are masked before they are written, but URLs can contain account identifiers the vendor chose to put there. Treat it as sensitive. - No screenshot is taken, by design. - The bridge never receives a vendor password or an OTP. Do not "help" it by putting one in an environment variable, a flow file or a selector. ## Troubleshooting | Message | Meaning | What to do | |---|---|---| | `the operator bridge is off` | `TAPEBOOK_OPERATOR_BRIDGE` is not `1` | Turn it on deliberately, or stop | | `the US wallet (INDmoney Global) is app-only …` | The US wallet was named as a vendor | Use the INDmoney app or the handoff in `docs/runbooks/remittance.md`; there is no web flow | | `IBKR is not implemented …` | IBKR was named as a vendor | Move the cash by hand in the IBKR portal; "not implemented", not "impossible" | | `loading a wallet is not implemented …` | A wallet load was requested | Make the push in the bank's app or portal; the bridge is outbound only | | `playwright is not installed` | The optional browser stack is absent | `uv pip install playwright && uv run playwright install chromium` | | `step '' expected … but the page was …` | The page is not where the flow said | Correct that step's selector/text in the YAML; do not add a fallback click | | `refuses ... unverified` | A live run of a placeholder flow | Finish the dry run and set `verified: true`, or pass `--allow-unverified` knowingly | | `the flow never adds or changes a beneficiary` | The page offered an add/change-account control, or a step targeted one | Stop. Withdraw only to the account already registered | | `the page reports ₹X withdrawable` | Amount exceeds fresh funds | Lower the amount; the desk will not overdraw the wallet | | `kill switch is set` | A previous run was aborted | `tape bridge kill --clear` when you are ready | ## What must be verified before the flow is trusted Run every item against the **Indian investing web app** (INDstocks / INDmoney investing), not the US wallet and not IBKR — neither of those can be driven here. 1. `tape bridge unlock` completes at the Indian funds screen and the profile survives a second run (session reuse works). 2. A `--dry-run` reaches the review screen with no failed step. 3. The dry-run destination matches the **registered Indian bank account**, including its last four digits. 4. The printed withdrawable balance matches the Indian web app's withdrawal figure to the rupee — not "available to invest" / `eq_cnc`. 5. A `--dry-run` does not click the submit button (watch the browser; confirm the audit has no `submitted` row). 6. `tape bridge kill` from a second terminal aborts a run before its next step. 7. One small live withdrawal is made; `GET /funds`'s `withdrawal_balance` falls by at least the amount, and `tape bridge reconcile` (fed that figure) records `SENT`. 8. The bank credit is reported with `tape bridge bank-credit` and the plan becomes `RECEIVED`. Only after 1–8 should the flow's `verified` flag be true and the sweep be treated as routine. Items 1–4 are the ones no test in this repository can prove: the tests use a fake page and say so.