path = 'c:/NeoZQYY/docs/h5_ui/compare/AGENT-PLAYBOOK.md'
path_hist = 'c:/NeoZQYY/docs/h5_ui/compare/HISTORY.md'

with open(path, 'rb') as f:
    lines = f.read().decode('utf-8').split('\n')

# Split at line 1439 (0-indexed 1438)
split_idx = 1438  # 0-indexed

playbook_lines = lines[:split_idx]  # keep up to line 1438
history_lines = lines[split_idx:]   # from line 1439 onward

# Add history file header
history_header = [
    '# \u5386\u53f2\u63a8\u5bfc\u4e0e\u57fa\u51c6\u6d4b\u8bd5\u8bb0\u5f55',
    '',
    '\u672c\u6587\u4ef6\u5305\u542b H5 \u2192 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u8fc1\u79fb\u9879\u76ee\u7684\u5386\u53f2\u63a8\u5bfc\u8fc7\u7a0b\u3001Benchmark \u5206\u6790\u3001\u65e7\u7248\u672c\u6362\u7b97\u7cfb\u6570\u8bb0\u5f55\u3002',
    '\u4e0d\u5c5e\u4e8e\u6267\u884c\u624b\u518c\uff0c\u4ec5\u4f9b\u5386\u53f2\u53c2\u8003\u3002',
    '',
]
history_content = '\n'.join(history_header + history_lines)

# Remove trailing whitespace from playbook
while playbook_lines and playbook_lines[-1].strip() == '':
    playbook_lines.pop()
playbook_lines.append('')  # single trailing newline
playbook_content = '\n'.join(playbook_lines)

# Write history file
with open(path_hist, 'wb') as f:
    f.write(history_content.encode('utf-8'))
print(f'HISTORY.md: {len(history_lines)} lines')

# Write trimmed playbook
with open(path, 'wb') as f:
    f.write(playbook_content.encode('utf-8'))
print(f'AGENT-PLAYBOOK.md: {len(playbook_lines)} lines')
