Replace a strategy file
replace_fileReplaces the full contents of an existing strategy file in a new immutable revision for any strategy owned by the authenticated user. Requires editHandle from get_file/list_files. Use this for first-build main.py replacement after create_strategy returns neutral starter files. For the current attached/open strategy, omit strategyId and revisionId after get_file; the server resolves the latest conversation revision, so do not manually transcribe those UUIDs. Pass explicit ids only for a named or different strategy. For existing-strategy fixes, this is the action step after get_file identified the concrete change and returned an editHandle. Mutate only the strategy/revision named by the user when it differs from the open page context. After a successful replace, call get_file on the returned new revisionId to read back the final saved code and verify the saved executable code before final-answering; do not verify by re-reading the original/base revisionId from before the edit. For direct edits to existing saved strategies, edit plus readback completes the direct edit unless the user explicitly asked for a backtest. Do not start a backtest just because you want validation after this edit. For copy/apply-same-rules requests, do not use replace_file after reading only one strategy, and do not use it after reading only the target. A different revision of the named target is still target evidence, not source evidence, unless the user explicitly asked to copy from an older target revision. First read the source strategy code and the named target strategy code, then diff executable assignments/thresholds/cadence/branches within the requested copy scope. Copy only explicitly requested mechanics for a limited transfer; update every differing target value to the source value only for whole-strategy parity. Preserve target-specific identity such as symbol/ticker, strategy name, account/broker identity, and labels unless the user explicitly asks to change them; do not copy the source symbol/name into the target. Build the replacement from the target file and selectively copy behavior values into it; do not replace the named target wholesale with the source file when identities differ. In Python strategy code, self.symbol is target identity when source and target tickers differ; for a TQQQ source applied to an SQQQ target, keep self.symbol as SQQQ while copying behavior rules. Target identity does not include cadence, sleeptime, trigger thresholds, order sizing, entry/exit branches, helper calls, or risk rules; those are behavior and must match the source only when included in the requested copy scope. Do not add settings absent from the source or merge unrelated memory/preferences. Before replace_file in a copy/apply-same-rules edit, preserve the literal target identity line from the target readback in the replacement content. If your replacement would turn target identity into source identity, do not call this tool yet; correct the replacement first. After readback for a copy/apply-same-rules edit, if the target file contains source identity such as the source symbol/name/account/broker, edit again before final-answering. Do not list source identity as evidence of success. When the fix replaces an executable setting, guard, helper call, order path, or branch, remove or replace the stale executable code; do not append a competing line and leave the old contradictory behavior in place. When the user says to stop using a value/source, or says that value/source is stale or wrong, remove executable fallback uses of that value/source instead of keeping them as a backup path. If the readback still contains the stale executable value/source/fallback the user asked to remove, the edit is not complete; call patch_file or replace_file again before final-answering. If the user supplied a concrete replacement value for a code-owned setting such as cost basis, entry price, threshold, cadence, market, symbol, or helper path, replace the stale executable literal/path and read it back. For live fill/cost-basis fixes where live order tools fail but the user supplied a concrete bot-owned fill, record/use that exact fill value in executable state/code as the bootstrap latest verified bot-owned fill; do not add only an unset placeholder such as None. For plan-driven first-build work, make the visible implementation item in_progress with update_plan_item before using file tools so the user sees the current plan step while file work runs. If replace_file or patch_file fails, no new revision was created: read the current file/editHandle and retry with a valid edit before starting a backtest or ending the strategy build.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| content | Yes | ||
| editHandle | Yes | Opaque edit handle returned by list_files or get_file. It replaces raw hash copying while preserving stale-write protection. | |
| revisionId | No | Base revision ID to snapshot from. Omit with strategyId for the current attached/open strategy. | |
| strategyId | No | Base strategy id. Omit with revisionId for the current attached/open strategy so the server uses the conversation's latest saved revision. | |
| description | No |