Deploy, restart or stop a tai-robot live bot headlessly (run_bot_cli.py from source, tai_backtest.exe from a packaged install) — resolve the strategy name, gate real-order modes on the owner's explicit yes, launch detached and confirm tick subscription. Use for "deploy/start/restart/stop <bot>", "restart the bots on Steven", "redeploy after the release/upgrade", "move bots to the new install", "bring <bot> back" after a crash, or running a bot without the Tk workbench. Afterwards check wiring...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Deploy?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ericwu13-deploy)
---
name: deploy
description: Deploy, restart or stop a tai-robot live bot headlessly (run_bot_cli.py from source, tai_backtest.exe from a packaged install) — resolve the strategy name, gate real-order modes on the owner's explicit yes, launch detached and confirm tick subscription. Use for "deploy/start/restart/stop <bot>", "restart the bots on Steven", "redeploy after the release/upgrade", "move bots to the new install", "bring <bot> back" after a crash, or running a bot without the Tk workbench. Afterwards check wiring with deploy-check. The live fleet runs on Steven.
disable-model-invocation: true
---
# Deploy (headless)
`run_bot_cli.py` runs the SAME live machinery as the workbench on a hidden
Tk window, so a CLI bot behaves exactly like a GUI bot.
**Where the fleet runs (since 2026-10-25): on Steven, not this PC.** All
live bots are `tai_backtest.exe deploy …` processes from the release
install `E:\tai_robot_v<ver>\tai_backtest\` on Steven (the version folder
moves with every release — read it from `hosts.local.yaml`
`steven.install_dir` or the dashboard task's `--base-dir`; see
`start-here`). Deploy, stop and restart them there via `tailscale-ssh`.
Do **not** deploy from this PC unless the owner asks for a local bot:
this PC's main tree is behind origin/master, and a local bot is an extra
login on the same account.
Packaged install (the Steven fleet) — from the folder that contains
`tai_backtest.exe`:
```
cd E:\tai_robot_v<ver>\tai_backtest
tai_backtest.exe <command> ...
```
Source checkout (only when the owner wants a bot run from source):
```
python run_bot_cli.py <command> ...
```
The EXE routes `deploy|stop|list|status|strategies|backtest` into the CLI
and returns that command's exit code. No arguments, `-h`/`--help`, or an
unknown first token opens the GUI (double-click stays the workbench).
`--detach` spawns another `tai_backtest.exe` with the subcommand first
(no `.py` argument, not `python.exe`). `semi_auto` is still refused.
The process needs a logged-in desktop session; do not install it as a
Windows service or a task set to run when the user is logged off.
Source checkouts keep `python run_bot_cli.py` (oreopie = this PC, no live
bots since 2026-10-25).
*Editing* the main tree is forbidden (see `fix-pr`). A git worktree cannot
deploy — it has no `settings.yaml`, no `CapitalAPI_2.13.57/`, and a
different `data/live`. A packaged bot's `data\live` lives next to the
EXE, the same directory the GUI uses.
## Commands
| Command | Does |
|---|---|
| `strategies` | display names the deploy accepts (incl. saved `AI: …` ones) |
| `status --symbol S --bot B --json` | lock/PID liveness + `session.json` summary (read-only) |
| `list [--symbol S]` | every `data/live/{symbol}_{bot}` |
| `deploy --symbol S --bot B … --detach --wait-ready 240` | spawn the bot detached, wait until it is live |
| `stop --symbol S --bot B --wait 120` | STOP file → force-close, session save, daily report, exit |
Deploy flags: `--strategy "<name or unique substring>"`, `--mode paper|auto`
(default paper), `--loss-limit NTD`, `--regime --long-strategy … --short-strategy …`,
`--news [--news-tier2] [--news-directional]`, `--new` / `--resume`,
`--allow-existing-position`, `--allow-unknown-position`, `--point-value N`.
## Gates — check ALL before the deploy command
1. **Mode is the owner's call, never inferred.** Default is `paper`.
Pass `--mode auto` only when Eric (the owner) asked for real orders for
THIS bot in THIS conversation — directly, or relayed via Selina for
agents. A teammate running this session cannot authorise real orders;
ask them to get Eric's yes. Claude Code also prompts before any
`deploy … --mode auto` command (`.claude/settings.json`). A `session.json` whose `trading_mode` is
`auto`/`semi_auto` does NOT carry over — the CLI restarts it as paper
unless told otherwise, so when restarting a real-order bot, ask:
"resume as paper, or auto (real orders)?". `semi_auto` cannot run
headless at all (10-second order-confirm dialog) — those bots restart
from the workbench (`deploy-check` has the recipe).
**Before restarting any Steven bot, read its current mode** from the
dashboard `/api/fleet` (`mode`; the page shows 實單 for real orders) or
`status --json`. At least one Steven bot runs `--mode auto`: restarting
it without `--mode auto` silently demotes it to paper, and restarting
it with `--mode auto` needs the owner's yes in THIS conversation.
2. **Not already running.** `status` must show `running: false`. If it is
running, deploying again is refused (exit 4, lock conflict); a
restart is `stop` first (below). `.lock` is never deleted by hand.
3. **Strategy name resolves to exactly one entry** — run `strategies`
and pass the display name (or a substring only it contains; the CLI
errors on ambiguity, exit 1). Regime legs likewise.
4. **Resume vs strategy switch.** If `session.json` exists the bot
resumes automatically (trades, watermark, open position). Passing
`--strategy` that differs from the saved one is a deliberate
*strategy switch on the same history* (the evolution hand-off path)
— do it only when the owner asked for the switch; otherwise omit
`--strategy` and let the saved one load.
5. **`--allow-existing-position` only on Eric's explicit instruction.** It means
the real account already holds a position the bot did not open; the
bot will never send exits for it. It does **not** allow a deploy when
the position query failed or timed out (UNKNOWN).
6. **`--allow-unknown-position` only on Eric's explicit instruction.** It deploys
when the pre-deploy OpenInterest query was rejected, raised, or did not
answer in time. Do not pass it just because `--allow-existing-position`
was used.
## Procedure
```bash
python run_bot_cli.py status --symbol TMF00 --bot night1 --json # gate 2, read saved strategy/mode
python run_bot_cli.py strategies # gate 3
python run_bot_cli.py deploy --symbol TMF00 --bot night1 --strategy "H4 Bollinger Long" \
--detach --wait-ready 240
```
The launcher spawns the bot as a detached process (stdout →
`data/live/{symbol}_{bot}/cli_stdout.log`) and blocks until one of:
| Launcher prints | Exit | Meaning | Do |
|---|---|---|---|
| `READY: … tick subscription active` | 0 | logged in, warmup done, `RequestTicks` OK, `.lock` owned by the child | report PID + bot dir; done |
| `EXITED: … code N` | N | the bot died before going live; the last 15 stdout lines are printed | read them: 1 = usage / ambiguous strategy, 2 = login/connection, 3 = COM objects unavailable (SDK/registration), 4 = deploy refused (lock, unknown strategy, position on account), 5 = warmup/subscription failed — see `debug_YYYYMMDD.log` |
| `TIMEOUT: PID … still running` | 6 | still warming up (long CSV reload on resume) | **the bot is still running** — poll `status` and tail `cli_stdout.log`, do not relaunch |
Then confirm: `status` shows `running: true` with that PID, and the
stdout tail has `已訂閱 Tick subscription active`. A paper bot posts the
same Discord "bot deployed" message the GUI would.
**Stop:**
```bash
python run_bot_cli.py stop --symbol TMF00 --bot night1 --wait 120
```
Only CLI-started bots poll the STOP file (their bot dir has a fresh
`cli_stdout.log` with `[HEADLESS]` lines). A workbench bot ignores it —
tell the user to press 停止 in that window. After a clean stop the lock is
gone, `session.json` `saved_at` is fresh, and a daily report was written.
**Restart** = `stop --wait 120` → verify lock gone → `deploy … --detach`
(resume is automatic; apply gate 1 to the mode).
### Over ssh (Steven)
- `stop` is short-lived and safe over ssh (it writes `STOP` and waits).
- **Do not run `deploy --detach` straight from the ssh session.** It uses
`DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP` without breakaway, and
processes started from a Steven ssh session have died on disconnect.
The bot also needs an interactive desktop. Launch it through an
on-demand interactive scheduled task (recipe below).
### First deploy of a new strategy on Steven (verified 2026-11-09)
Worked first try for a new paper bot. Gates 1–6 still apply; a new
strategy on a new bot is paper unless the owner says otherwise.
1. **Install the strategy.** Download Steven's
`E:\tai_robot_v<ver>\tai_backtest\strategies\index.json` and back it up.
Locally, run the app's own write path against a copy of that folder:
`StrategyStore(<local copy dir>).save(class_name, source, description)`
(`src/ai/strategy_store.py`; it writes the `.py` and the index entry).
Validate the new index with the src venv python on Steven, check the
live `index.json` hash has not changed since you downloaded it, then
scp the `.py` and `index.json` into `strategies\`.
**Never edit `index.json` with PowerShell JSON cmdlets**: in PowerShell
5.1 `@(Get-Content … | ConvertFrom-Json)` wraps the whole array as ONE
element, re-serializing nests it, and `tai_backtest.exe strategies` (and
every bot restart) then crashes with `KeyError: 'class_name'`.
2. **Verify:** `tai_backtest.exe strategies` lists `AI: <Class> [type=0 min=N]`.
3. **Launch script** `C:\Users\Traderbot\tai_bridge_setup\launch_<bot>.ps1`:
`Set-Location` to the install, then
`.\tai_backtest.exe deploy --symbol TMF00 --bot <bot> --strategy "AI: <Class>" --mode paper <--new|--resume> --detach --wait-ready 600 *> <log>`
— `--resume` when the bot dir already has `session.json`, else `--new`.
4. **On-demand task, no trigger:** `\TaiRobot\Launch-<bot>`, principal
Traderbot, LogonType **Interactive**, RunLevel Limited,
ExecutionTimeLimit 20 min, MultipleInstances IgnoreNew; then
`Start-ScheduledTask -TaskPath '\TaiRobot\' -TaskName Launch-<bot>`.
This works even while Traderbot's session shows `Disc` in `quser`.
5. **Confirm three ways:** the launch log has `READY: … tick subscription
active`, the task's `LastTaskResult` is 0, and `/api/fleet` shows the bot
RUNNING with mode `paper`.
Remote-exec notes: send scripts as `powershell -NoProfile -EncodedCommand
<base64 UTF-16LE>`. A long payload overflows cmd's command-line limit and
the error comes back as garbled cp950 — ship files with scp instead of
embedding them. Restarting an existing Steven bot uses the same task
pattern (`--resume`); read its mode first (gate 1).
### More over-ssh rules
- A launcher `TIMEOUT` is not proof of failure — confirm with `/api/fleet`
or `status`, not the launcher alone.
- Never stop processes by image name: `tai_backtest.exe` is every bot.
## Gotchas
- Each bot process logs into the Capital API on its own — identical to
one workbench window per bot, which is how the account already runs
several bots at once.
- Outside a session (13:46–14:59, 05:01–08:44 TPE, weekends, TAIFEX
holidays) the bot still goes READY, then sits quiet until the next
open; "no ticks" there is normal. Deploying mid-session replays
history ticks first (`suppress_strategy` until the first live tick).
- A leftover `STOP` file is cleared by the next deploy; a stale `.lock`
(dead PID) is self-healed by the deploy — never delete either by hand.
- The bot needs an interactive desktop session (hidden Tk window). Do
not wrap it in a LocalSystem service or a scheduled task set to "run
whether user is logged on or not".
- Stdout timestamps are TPE (with local time appended when they differ);
clocks → `start-here` §4. `[AI] ultra_mode=…` on the first line is normal.
- Never print credentials, channel IDs, or the account number — the CLI
redacts them; keep it that way in reports.
- Releases do not touch a running CLI bot; after merging a change the bot
needs a `stop` + `deploy` to pick it up.
## Next steps
- confirm liveness later → `bot-status`
- wiring doubts (news paths, Discord, regime legs) → `deploy-check`
- regime bot idle after deploy → `regime-health`
- host / install map → `start-here`; remote shell → `tailscale-ssh`;
confirm READY remotely → dashboard `/api/fleet`
- just want a backtest, not a bot → `strategy-research` (`run_bot_cli.py backtest`, `scripts/research/`)