Rewrite the content of an existing chapter.
(
title: Annotated[str, ParamMeta(description="Chapter title to rewrite (supports multi-level index e.g. 'Intro/Background')")],
content: Annotated[str, ParamMeta(description="New content")],
_context: Dict[str, Any] | None = None,
)
| 389 | |
| 390 | |
| 391 | def report_rewrite_chapter( |
| 392 | title: Annotated[str, ParamMeta(description="Chapter title to rewrite (supports multi-level index e.g. 'Intro/Background')")], |
| 393 | content: Annotated[str, ParamMeta(description="New content")], |
| 394 | _context: Dict[str, Any] | None = None, |
| 395 | ) -> str: |
| 396 | """ |
| 397 | Rewrite the content of an existing chapter. |
| 398 | """ |
| 399 | ctx = FileToolContext(_context) |
| 400 | _, report_file = _get_files(ctx) |
| 401 | _, report_lock = _get_locks(ctx) |
| 402 | |
| 403 | with FileLock(report_lock): |
| 404 | lines = _read_report_lines(report_file) |
| 405 | |
| 406 | start, end = _find_chapter_range(lines, title) |
| 407 | if start == -1: |
| 408 | return f"Chapter '{title}' not found." |
| 409 | |
| 410 | # Keep the header, replace the body |
| 411 | # new body should not contain the header itself, just the content |
| 412 | new_body = [lines[start]] + content.splitlines() + [""] |
| 413 | |
| 414 | # Replace slice |
| 415 | lines[start:end] = new_body |
| 416 | |
| 417 | _save_report(report_file, lines) |
| 418 | return f"Rewrote chapter '{title}'" |
| 419 | |
| 420 | |
| 421 | def report_continue_chapter( |
nothing calls this directly
no test coverage detected