| 535 | |
| 536 | |
| 537 | class WriteChapters(BatchNode): |
| 538 | def prep(self, shared): |
| 539 | chapter_order = shared["chapter_order"] # List of indices |
| 540 | abstractions = shared[ |
| 541 | "abstractions" |
| 542 | ] # List of {"name": str, "description": str, "files": [int]} |
| 543 | files_data = shared["files"] # List of (path, content) tuples |
| 544 | project_name = shared["project_name"] |
| 545 | language = shared.get("language", "english") |
| 546 | use_cache = shared.get("use_cache", True) # Get use_cache flag, default to True |
| 547 | |
| 548 | # Get already written chapters to provide context |
| 549 | # We store them temporarily during the batch run, not in shared memory yet |
| 550 | # The 'previous_chapters_summary' will be built progressively in the exec context |
| 551 | self.chapters_written_so_far = ( |
| 552 | [] |
| 553 | ) # Use instance variable for temporary storage across exec calls |
| 554 | |
| 555 | # Create a complete list of all chapters |
| 556 | all_chapters = [] |
| 557 | chapter_filenames = {} # Store chapter filename mapping for linking |
| 558 | for i, abstraction_index in enumerate(chapter_order): |
| 559 | if 0 <= abstraction_index < len(abstractions): |
| 560 | chapter_num = i + 1 |
| 561 | chapter_name = abstractions[abstraction_index][ |
| 562 | "name" |
| 563 | ] # Potentially translated name |
| 564 | # Create safe filename (from potentially translated name) |
| 565 | safe_name = "".join( |
| 566 | c if c.isalnum() else "_" for c in chapter_name |
| 567 | ).lower() |
| 568 | filename = f"{i+1:02d}_{safe_name}.md" |
| 569 | # Format with link (using potentially translated name) |
| 570 | all_chapters.append(f"{chapter_num}. [{chapter_name}]({filename})") |
| 571 | # Store mapping of chapter index to filename for linking |
| 572 | chapter_filenames[abstraction_index] = { |
| 573 | "num": chapter_num, |
| 574 | "name": chapter_name, |
| 575 | "filename": filename, |
| 576 | } |
| 577 | |
| 578 | # Create a formatted string with all chapters |
| 579 | full_chapter_listing = "\n".join(all_chapters) |
| 580 | |
| 581 | items_to_process = [] |
| 582 | for i, abstraction_index in enumerate(chapter_order): |
| 583 | if 0 <= abstraction_index < len(abstractions): |
| 584 | abstraction_details = abstractions[ |
| 585 | abstraction_index |
| 586 | ] # Contains potentially translated name/desc |
| 587 | # Use 'files' (list of indices) directly |
| 588 | related_file_indices = abstraction_details.get("files", []) |
| 589 | # Get content using helper, passing indices |
| 590 | related_files_content_map = get_content_for_indices( |
| 591 | files_data, related_file_indices |
| 592 | ) |
| 593 | |
| 594 | # Get previous chapter info for transitions (uses potentially translated name) |
no outgoing calls
no test coverage detected