Stop deploy from overwriting manual FORCE_CLOSE settings.
Apply force-close defaults only when keys are missing so system-settings toggles survive pull_and_restart. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -54,7 +54,8 @@ SHARED_DEFAULTS: dict[str, str] = {
|
||||
"AI_TIMEOUT_SECONDS": "120",
|
||||
}
|
||||
|
||||
# 仅 Gate 启用 0 点强制清仓;币安/OKX 须保持关闭
|
||||
# 仅当某实例 .env 缺少 FORCE_CLOSE_* 时补默认:
|
||||
# Gate 默认开 0 点强制清仓;币安/OKX 默认关.已有手调值绝不覆盖.
|
||||
FORCE_CLOSE_POLICY: dict[str, dict[str, str]] = {
|
||||
"crypto_monitor_gate": {
|
||||
"FORCE_CLOSE_ENABLED": "true",
|
||||
@@ -131,7 +132,7 @@ def sync_one(dir_name: str, *, dry_run: bool, force: bool) -> bool:
|
||||
|
||||
|
||||
def apply_force_close_policy(*, dry_run: bool) -> bool:
|
||||
"""Gate 开启强制清仓;币安/OKX 强制关闭(覆盖已有值)."""
|
||||
"""仅在 FORCE_CLOSE_* 缺失时补默认值;已有手调值绝不覆盖."""
|
||||
any_changed = False
|
||||
for dir_name, values in FORCE_CLOSE_POLICY.items():
|
||||
path = os.path.join(REPO, dir_name, ".env")
|
||||
@@ -139,19 +140,19 @@ def apply_force_close_policy(*, dry_run: bool) -> bool:
|
||||
print(f"skip (no .env): {dir_name}")
|
||||
continue
|
||||
lines = _parse_env(path)
|
||||
changed_keys: list[str] = []
|
||||
added_keys: list[str] = []
|
||||
for key, val in values.items():
|
||||
cur = _env_get(lines, key)
|
||||
if cur != val:
|
||||
if cur is None:
|
||||
lines = _upsert(lines, key, val)
|
||||
changed_keys.append(key)
|
||||
if not changed_keys:
|
||||
print(f"ok (force-close policy): {dir_name}")
|
||||
added_keys.append(key)
|
||||
if not added_keys:
|
||||
print(f"ok (force-close unchanged): {dir_name}")
|
||||
continue
|
||||
any_changed = True
|
||||
print(f"force-close policy: {dir_name}")
|
||||
for key in changed_keys:
|
||||
print(f" = {key}={values[key]}")
|
||||
print(f"force-close fill-missing: {dir_name}")
|
||||
for key in added_keys:
|
||||
print(f" + {key}={values[key]}")
|
||||
if not dry_run:
|
||||
text = "\n".join(lines).rstrip() + "\n"
|
||||
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
||||
@@ -166,7 +167,7 @@ def main() -> None:
|
||||
ap.add_argument(
|
||||
"--apply-force-close-policy",
|
||||
action="store_true",
|
||||
help="Gate 开启 0 点强制清仓,币安/OKX 强制关闭",
|
||||
help="仅补全缺失的 FORCE_CLOSE_* 默认值(不覆盖手调)",
|
||||
)
|
||||
ap.add_argument(
|
||||
"--instances",
|
||||
|
||||
Reference in New Issue
Block a user