feat: auto-pause on data fetch + iron rules update

- All api_get/api_post calls now auto-pause game before executing
- AUTO_PAUSE_ENABLED flag to disable for event daemon polling
- Event daemon explicitly disables auto-pause (frequent light polling)
- Iron rules updated:
  Rule 1: AI must pause BEFORE any reasoning/decision
  Rule 2: Tools auto-pause on state data fetch
  Rule 3: AI must pause before asking user questions
  Rule 4: AI must ensure paused when exiting response state
  Rule 5: Save before major operations
This commit is contained in:
root
2026-05-22 09:28:06 +08:00
parent f8a89a375b
commit 80485d2a5a
3 changed files with 41 additions and 11 deletions

View File

@ -6,6 +6,11 @@ import os
CONFIG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'config.json')
# Auto-pause control
AUTO_PAUSE_ENABLED = True
"""When True, api_get and api_post auto-pause game before executing.
Set to False for event daemon polling (lightweight, frequent checks)."""
def load_config():
with open(CONFIG_PATH) as f:
return json.load(f)
@ -14,7 +19,22 @@ def api_url(endpoint):
cfg = load_config()
return f"http://{cfg['modHost']}:{cfg['modPort']}{endpoint}"
def api_get(endpoint):
def _auto_pause():
"""Auto-pause the game before any AI operation, ensuring data freshness."""
if not AUTO_PAUSE_ENABLED:
return
try:
cfg = load_config()
url = f"http://{cfg['modHost']}:{cfg['modPort']}/api/action/pause"
req = urllib.request.Request(url, data=b'{}', headers={'Content-Type': 'application/json'}, method='POST')
with urllib.request.urlopen(req, timeout=3):
pass
except:
pass
def api_get(endpoint, auto_pause=True):
if auto_pause and AUTO_PAUSE_ENABLED:
_auto_pause()
url = api_url(endpoint)
cfg = load_config()
try:
@ -24,7 +44,9 @@ def api_get(endpoint):
except urllib.error.URLError as e:
return {"error": str(e)}
def api_post(endpoint, data):
def api_post(endpoint, data, auto_pause=True):
if auto_pause and AUTO_PAUSE_ENABLED:
_auto_pause()
url = api_url(endpoint)
cfg = load_config()
try: