# AGENTS.md Windows-only codebase. Embarcadero **RAD Studio 13.2 (ProjectVersion 20.5), VCL, C++ personality**. No test framework, no linter, no CI. This `AGENTS.md` lives inside the `RBmaster/` subdirectory — all paths below are relative to it, and shared directories (`Global/`, `Upgrade/`, `CEF4Delphi/`, `res/`, `Deploy/`) are one level up (`..\Global\` etc.). ## Encoding — UTF-8, keep it that way **All C++ sources, headers, `.dfm`s and `.rc`s in `RBmaster/`, `..\Global/`, `..\Upgrade/` and `..\res/` are UTF-8.** This was converted from GBK/CP936 (`..\ToUTF8.py`, pre-conversion backups in `..\backup_before_utf8\`). Verified: 0 of 94 source files fail a strict UTF-8 decode. - **Write UTF-8. Never write GBK/CP936.** Re-encoding a file back to CP936 silently corrupts every Chinese comment and literal (`L"红蓝大师"` is RBmaster's `APPNAME`, at `..\Global\GlobalUnit.h:193`). - **BOM is mixed and that is fine.** 51 of 94 files start with a UTF-8 BOM (most `.cpp`); 43 do not (mostly ASCII-only `.h` / `.dfm` / `.rc`). Don't "normalize" this — just match whatever the file you are editing already does, and never let a single file end up half-and-half. - Comments and user-facing strings are **Simplified Chinese**. Keep it that way. - `..\Upgrade\` already committed its conversion (`bd3861f convert utf8`). The RBmaster-side conversion plus `AGENTS.md` and `opencode.json` were **staged but not committed** at the time of writing — so `git diff` will show whole-file rewrites until that commit lands. Expect it; don't try to "fix" it by reverting. - `AGENTS.md` itself and `opencode.json` are UTF-8 **without** BOM. There is **no working C++ LSP** for this repo (no `compile_commands.json`, no C++ toolchain aware of the VCL include paths). Editor diagnostics report hundreds of bogus errors — `vcl.h file not found`, `Unknown type name 'String'`, `Unknown type name 'TObject'`. **Ignore them.** Trust the C++Builder IDE or a real `msbuild` run instead. ## Agent tooling constraints `opencode.json` (project root) sets: ```json "permission": { "external_directory": { "*": "ask" }, "bash": { "*": "allow" } } ``` - **`bash: allow`** — shell commands run without a prompt. This is the project default and it is **committed**, so it applies to everyone on the team, not just you. - **`external_directory: ask`** — anything outside `RBmaster/` still needs a prompt: `..\Global\`, `..\Upgrade\`, `..\res\`, `..\CEF4Delphi\`, `..\Baccarats.groupproj`. This covers both the file tools (`read`, `grep`, `edit`, `write`) and shell paths — a `bash` command that touches `..\` will be gated by this rule, **not** by the bash rule. Opening bash does not buy you access outside the repo. - Consequence: before planning an edit that crosses the boundary, expect one prompt per such command. Batch them. If a shared contract genuinely cannot be edited, say so rather than silently changing only the RBmaster half. ## This is ONE codebase, MANY products `..\Global\GlobalUnit.h:54-348` is a `#if defined(_PRODUCT_)` chain. The active product sets `APPNAME`, `APPABBR`, `SOFTWARE_ID`, `SORTWARE_VER`, `SINGLE_INSTANCE`, `GLOBAL_VAR_FILE`. ~20 products share this source (`_RBM_` = 红蓝大师, id 23, `GlobalUnit.h:193-195`; `_RBMabc_` id 24, `_ABG_` id 18, `_SPTHDG_` id 13, …). Most branches are commented out. - Active product is selected by a **preprocessor define**, currently `_RBM_` — set in `RBmaster.cbproj:80` (`_RBM_;$(Defines)`), not in source. - To change product: edit the `.cbproj` ``, **not** `GlobalUnit.h`. - `GLOBAL_VAR_FILE` (`glbvrf.cnf` for `_RBM_`, `GlobalUnit.h:347`) is the server-list file — it is the **4th arg to AppUpgrade**, not an app-local config. Do not "clean up" the commented-out product blocks; they are the product matrix. ## Layout & ownership | Path (relative to cwd=`RBmaster/`) | What | |---|---| | `.` (this dir) | **Main program.** Own repo. `RBmaster.exe` | | `..\Upgrade\` | **Auto-updater**, separate repo. `AppUpgrade.exe` | | `..\Global\` | Shared code, compiled into RBmaster only. `TBaseThread`/`TBaseWebThread`, `CSema`, `HttpThread` (WinINet), `CommonV8Handler` (CEF V8 bridge), `SHA2`, `paramcodec`. **Not a separate build target** | | `..\CEF4Delphi\` | Vendored Chromium Embedded Framework. Live for RBmaster, dead for Upgrade | | `..\res\` | Icons/bitmaps/wav (`AppIcon.ico`, `rnb.psd`, `snd1-6.wav`, …); `..\res\RBmaster.Artwork\` is RAD Studio deployment artwork | `Global/` has no project file — its 7 `.cpp` files (`BaseThread`, `CommonV8Handler`, `GlobalUnit`, `HttpThread`, `ResourceHandler`, `SHA2`, `SimpleMutex`) are listed as `..\Global\*.cpp` entries inside `RBmaster.cbproj`, and all 7 are present there. **Adding a new file to `Global/` requires a manual `` edit to the cbproj.** Search paths are `..\Global\;` and `..\CEF4Delphi\$(Platform)\hpps`. ## Git — two repos, not three `RBmaster/` is a git repo; `..\Upgrade\` is its own. Tree root (`..\Baccarats.groupproj`, `..\Deploy\`) is **not** under version control and has no shared history between the two repos. - `RBmaster/` → `ssh://git@gitea/rnb/winapp.git`, branch `main` (81 tracked files) - `..\Upgrade\` → `ssh://git@gitea/BCB_common/AppUpgrade.git`, branch `main` Commit only from inside the respective subdirectory. Commit messages are mixed Chinese/English, often just a version string (e.g. `4.0.7版`). Match that style. ### `.gitignore` — the rules that will surprise you Verbatim, `RBmaster/.gitignore`: ``` **/Win32/ .scratch/ docs/ __history/ __recovery/ *.~dsk *.cbpr *.local *.dsv *.rc ``` - **`docs/` is gitignored.** `docs/agents/*.md` exists on disk but is **not committed**. Skills that reference it will read a file that no other checkout has. - **`.scratch/` is gitignored** — the local-markdown issue tracker is per-developer by design. - **`*.rc` is gitignored**, so `RBmaster_resources.rc` is **untracked**. It compiles but will never be committed unless the rule is changed. - `*.local` and `*.dsv` cover `RBmaster.cbproj.local` and `RBmaster.dsv` — IDE state, correctly ignored. - `AGENTS.md` and `opencode.json` **are** tracked. - A stray `master` branch exists locally alongside `main` and points at the initial commit. Don't commit to it. ## Build Both projects output to `..\Deploy\$(Platform)\$(Config)\` (i.e. `..\Deploy\Win32\Debug\`). That dir is gitignored/absent. ```powershell # Per project (rsvars.bat / $(BDS) must be on PATH first) msbuild RBmaster.cbproj /t:Build /p:Config=Debug /p:Platform=Win32 msbuild ..\Upgrade\AppUpgrade.cbproj /t:Build /p:Config=Debug /p:Platform=Win32 # Both at once — `Baccarats.groupproj` (tree-root; not reachable when cwd=RBmaster/ — run the two projects individually instead) msbuild ..\Baccarats.groupproj /t:Build /p:Config=Debug /p:Platform=Win32 ``` Platforms: `Win32`, `Win64`, `Win64x` (all defined in the cbproj; `Win32` is the enabled one). Configs: `Debug`, `Release`. Default is `Debug`. `..\Baccarats.groupproj` references only `RBmaster\RBmaster.cbproj` and `Upgrade\AppUpgrade.cbproj`, and its `Import` of `$(BDS)\Bin\CodeGear.Group.Targets` is guarded by `Condition="Exists(...)"` — build the two projects individually if the group build silently does nothing. Both projects set `AppExecutionLevel = requireAdministrator` in **every** config. The app will UAC-elevate during IDE-run and debugging. RBmaster links `CEF4DelphiVCLRTL.lib` and `TPNGButton.lib` on top of the standard VCL set (`rtl`, `vcl`, `fmx`, `vclimg`, `xmlrtl`, `vclactnband`, `vclx`). `Upgrade` links only `rtl.lib;vcl.lib`. ## Runtime CLI switches (RBmaster) Parsed at `RBmaster.cpp:229-235`, lowercased before comparison: - `-d` → `g_bBacData = true`, creates the `data\` log directory - `-testing` → `g_bTesting = true`, enables CEF logging (`RBmaster.cpp:92`), and skips the single-instance window-property registration (`RBmaster.cpp:294`, `:302`). It also simulates bet/account feedback across `BacABThread.cpp`, `BacDPThread.cpp:382`, `SettingFormUnit.cpp:263` (`m_cbSimAcc`) — a `-testing` run exercises a different code path than production. Without `-testing` the app registers a window property (`APPABBR` = `rbmaster`, `RBmaster.cpp:295`) used by `IsRestart()` to detect an already-running instance and forward `UM_RESTORE`. ## Startup flow (`RBmaster.cpp`) `_tWinMain` → `Startup()` (line 224): 1. `IsRestart()` (129-159) — finds an existing instance; if this process is that instance's child, it only runs `InitCef()` and exits (line 149). CEF child processes bootstrap here. 2. `InitCef()` (84) — configures `TCefApplication` before any form exists. `NoSandbox=true`, `IgnoreCertificateErrors=true`, `DisableWebSecurity=true`, `SingleProcess=false`, `SitePerProcess=true`. 3. `InitUserPath()` (205-219) — `ForceDirectories` for `user\`, and for `data\` only when `-d` was passed. 4. `Application->CreateForm(TMainForm)` (251). 5. **`TMainForm::Tag` is the control-flow channel** (244-291). It is set by the main form during construction to steer startup: - `0` normal run · `-1` 加载应用模块失败 · `-3` 连接服务器失败 · `-4` 软件已停止运行 · `-5` CEF 初始化失败 - `2` update required → message box, `mode = 2` → `StartUpgrade(2)` (`show`) - `4` new version available → yes/no prompt → `mode = 2` (`show`) or `mode = 0` - any other positive value is taken as the upgrade `mode` verbatim and passed to `StartUpgrade(mode)` (289-290) - `bRun = mode<=1` (287) — `mode` 0/1 keep running, `mode` 2/3 hand off to the updater and exit. `RBmasterMain.cpp` is the main form, not the entrypoint. The entrypoint unit is `RBmaster.cpp` (`USEFORM("RBmasterMain.cpp", MainForm)` at line 222). ## The RBmaster ↔ Upgrade contract `RBmaster.cpp:164-201` `StartUpgrade(mode)` duplicates the process token and `CreateProcessAsUser`s the updater. **RBmaster does not wait for it** — the updater must kill RBmaster itself. Command line actually built at `RBmaster.cpp:186-196`: ``` \AppUpgrade.exe {move|show|hide} ``` The keyword is chosen by RBmaster's `mode` (187-192): `mode==3` → `move`, `mode==2` → `show`, everything else → `hide`. **RBmaster never sends `MD5`.** Verified mapping in `AppUpgrade.cpp:44-75` — **the first arg is a keyword, and its internal `mode` is inverted vs. the keyword's name**: | Arg 1 | Internal `mode` | Form shown? | |---|---|---| | `MD5` | 1 | yes — compute + write `filemd5.lst` only | | `show` | 0 | **yes** — download with visible UI | | `hide` | 2 | **no** — headless thread | | `move` | 3 | no — `Sleep(1000)` then replace files | | anything else | 0 | yes | Gotcha: `AppUpgrade.exe` with **no args returns immediately and does nothing** (`if( ParamStr(1).IsEmpty() ){ return 0; }`, ~line 44). `MD5` is the only mode that ignores `ParamStr(2..4)`. RBmaster's own `mode` is a *different* numbering from AppUpgrade's internal `mode` — the translation happens in the keyword, not the number. Don't line them up. Upstream API: `http:///Api/getUpgradeUrl?sid=`, server list from `srv=` lines in the `GVF` binary file (`GLOBAL_VAR_VERSION 0x03`, header `GVF` + version WORD, `tGVFHeader`). User-Agent is hardcoded `RookIE/1.0`. Downloads land in `\upgrade\`; `filemd5.lst` (`MD5_FILE_NAME`, `UpgradeThread.cpp:18`) is written by `TUpgradeThread::MakeMD5File()` (`UpgradeThread.cpp:318`) as tab-separated `filenamemd5`. No code signing, no rollback — MD5 from the same server is the only integrity check. ## Threading contract Workers post `UM_*` custom messages to the main form; the form handlers live in `RBmasterMain.cpp` (e.g. `UM_ONJSMessage` dispatch at `RBmasterMain.cpp:1752`). **There are three thread base classes — "everything derives from `TBaseThread`" is wrong:** | Base | Declared | Users | |---|---|---| | `TBaseThread : public TThread` | `..\Global\BaseThread.h:10` | `TAutoBetThread`, `TDataParseThread`, `TJSHandleThread` | | `TBaseWebThread : public TThread` | `..\Global\HttpThread.h:107` | `TAsynHttpThread` (:122), `TAsynUrlThread` (:142), `TVeloThread` (:158) | | `TThread` | — | `TUpgradeThread` (`..\Upgrade\UpgradeThread.h:22`), the updater's own worker | Known workers: | Unit | Class | Role | |---|---|---| | `BacABThread.h:13` | `TAutoBetThread : TBaseThread` | places bets by executing injected CEF JavaScript | | `BacDPThread.h:12` | `TDataParseThread : TBaseThread` | parses pipe-delimited game feed, writes `%Y%m%d.txt` logs, posts `UM_ADDTABLE`/`UM_STATUS`/`UM_WEBDEAD` | | `BacJSThread.h:19` | `TJSHandleThread : TBaseThread` | CEF↔C++ bridge round-trips (`UM_JSHANDLED`) | | `..\Global\HttpThread.h:122` | `TAsynHttpThread : TBaseWebThread` | WinINet login/report/logout, posts `UM_HTTPRETURN` | | `..\Global\HttpThread.h:142` | `TAsynUrlThread : TBaseWebThread` | WinINet URL fetch | | `..\Global\HttpThread.h:158` | `TVeloThread : TBaseWebThread` | server-list failover — **defined in `..\Global\HttpThread.h`, not in `RBmasterMain.cpp`**; instantiated from `RBmasterMain.cpp:566`, `:3300` | **The `UM_*` ids are a shared, sparse enum defined once in `..\Global\GlobalUnit.h:9-51`** (`WM_USER+0x1000` = `UM_VCCOMPLETE` upward). Adding a message means editing `GlobalUnit.h`, not a local header. The updater uses a *different* set in `..\Upgrade\UpgradeThread.h`, and the ranges **do collide**: | Updater | Value | RBmaster collision | |---|---|---| | `UM_SHOWTEXT` | `WM_USER+0x1000` | = `UM_VCCOMPLETE` | | `UM_PROGRESS` | `WM_USER+0x1001` | = `UM_WEBLOADED` | | `UM_COMPLETE` | `WM_USER+0x1003` | = `UM_IMAGELODED` | They are harmless only because each message is handled inside its own process. Never unify the two headers by accident, and never assume a `WM_USER+0x100N` value is unambiguous across the two repos. `HookJS.cpp` (`MyGameLink`, line 35) hooks `onSocketData` inside the page and pushes events back as `cefApp.OnJSMessage('|')`. `` is a **numeric message type, not a literal `N`** — observed codes are `0`, `3`, `4`, `5`, `7`, `9` (e.g. `'0|-2'`, `'3|'+vid+'|||12|'`, `'9|'+tableId+'|'+roundId+'|'+card[0]+'|'+card[1]`). C++ parses the leading integer in `RBmasterMain.cpp:1752`. Code `0` carries status/result codes (`0`, `-2`, `-3`) rather than data. ## Persistence Files land **next to the exe**, not in AppData — so the install directory must be writable (it requires admin). - `rbmvrf` — user vars / policies, `USER_VAR_FILE "\t\trbmvrf"` (`RBmasterMain.cpp:28`) - `rbmgmf` — game + bet settings, `USER_GAME_FILE "\t\trbmgmf"` (`RBmasterMain.cpp:33`) - `glbvrf.cnf` — `GLOBAL_VAR_FILE` server list - `user\` — `ForceDirectories` at `RBmaster.cpp:210` - `data\` — `ForceDirectories` at `RBmaster.cpp:216`, only with `-d` - `cache\` — handed to CEF as the cache path in `InitCef()`; CEF creates it, the app never does - `upgrade\`, `filemd5.lst` — updater Saved in `FormClose` / `FileUserVars` / `FileGame`. `rbmvrf`/`rbmgmf` are custom binary (`TUVFHEADER` / `TUGFHEADER` + newline-delimited records), not INI — editing by hand will corrupt them. ## Gotchas - CEF's `WindowlessRenderingEnabled` + `SingleProcess=false` means a **second process** is expected; don't debug by assuming one process tree. - `..\Global\GlobalUnit.h:359-360` `DPIX`/`DPIY` scale everything through `g_xDpi`/`g_yDpi` — new UI code must not hardcode pixel positions. - The default server `23.236.66.46:88` is a **commented-out** `#define DEFAULT_SERVER` in `..\Upgrade\UpgradeThread.cpp`; it is not live. Other hardcoded hosts/ports/URLs live in that file and in `TableIPFormUnit.cpp`. - `RBmasterMain.dfm` uses inherited VCL style-form children; the IDE strips redundant `StyleElements` lines on save, producing large no-op-looking diffs. That's tooling noise, not a behavioral change. - `opencode.json` blocks the file tools from `..\` — see **Agent tooling constraints** above before planning any cross-boundary change. ## Agent skills ### Issue tracker Issues are local markdown under `.scratch/` — no CLI, no auth, no network. **`.scratch/` is gitignored**, so the tracker is per-developer and never shared. See `docs/agents/issue-tracker.md`. ### Triage labels The five canonical roles written to each ticket's `Status:` line. See `docs/agents/triage-labels.md`. ### Domain docs Single-context: `CONTEXT.md` + `docs/adr/` at this root. See `docs/agents/domain.md`. **Neither exists yet** — `CONTEXT.md` is absent and `docs/adr/` is empty; `docs/agents/domain.md:11` says to proceed silently in that case. Note `docs/agents/domain.md:35` claims these are committed with RBmaster, and `:37` claims the sources are GBK — **both are stale**, ignore those two lines.