{
    "sourceFile": "Tickets/REFACTOR-001-plan.md",
    "activeCommit": 0,
    "commits": [
        {
            "activePatchIndex": 2,
            "patches": [
                {
                    "date": 1745343175929,
                    "content": "Index: \n===================================================================\n--- \n+++ \n"
                },
                {
                    "date": 1745344031618,
                    "content": "Index: \n===================================================================\n--- \n+++ \n@@ -51,5 +51,18 @@\n \r\n     H2 -- Saves Temp Files --> I2{Processed/Merged Map Details};\r\n \r\n     I2 --> J2(_generate_metadata_file);\r\n-    J2 --> K2(_organize_output_files);\n\\ No newline at end of file\n+    J2 --> K2(_organize_output_files);\r\n+## Current Status (as of 2025-04-22 ~19:45 CET)\r\n+\r\n+*   **DONE:** Step 1: Implemented `_load_and_transform_source` helper function (including caching logic) and inserted into `asset_processor.py`.\r\n+*   **DONE:** Step 2: Implemented `_save_image` helper function and inserted into `asset_processor.py`.\r\n+*   **DONE:** Step 5 (Partial): Updated `process` method to initialize `loaded_data_cache` and updated calls to use new function names (`_process_individual_maps`, `_merge_maps_from_source`) and pass the cache.\r\n+*   **DONE:** Renamed function definitions: `_process_maps` -> `_process_individual_maps`, `_merge_maps` -> `_merge_maps_from_source`, and added `loaded_data_cache` parameter.\r\n+*   **DONE:** Corrected syntax errors introduced during previous `apply_diff` operations (related to docstrings).\r\n+\r\n+## Remaining Steps:\r\n+\r\n+1.  **Modify `_process_individual_maps` Logic:** Update the internal logic to correctly utilize `_load_and_transform_source` (with cache) and `_save_image` for maps not involved in merging.\r\n+2.  **Modify `_merge_maps_from_source` Logic:** Update the internal logic to correctly utilize `_load_and_transform_source` (with cache) for *source* files, perform the channel merge, and then use `_save_image` for the merged result.\r\n+3.  **Testing:** Thoroughly test the refactored code to ensure correctness, quality improvement, and acceptable performance.\n\\ No newline at end of file\n"
                },
                {
                    "date": 1745344780240,
                    "content": "Index: \n===================================================================\n--- \n+++ \n@@ -62,7 +62,7 @@\n *   **DONE:** Corrected syntax errors introduced during previous `apply_diff` operations (related to docstrings).\r\n \r\n ## Remaining Steps:\r\n \r\n-1.  **Modify `_process_individual_maps` Logic:** Update the internal logic to correctly utilize `_load_and_transform_source` (with cache) and `_save_image` for maps not involved in merging.\r\n-2.  **Modify `_merge_maps_from_source` Logic:** Update the internal logic to correctly utilize `_load_and_transform_source` (with cache) for *source* files, perform the channel merge, and then use `_save_image` for the merged result.\r\n-3.  **Testing:** Thoroughly test the refactored code to ensure correctness, quality improvement, and acceptable performance.\n\\ No newline at end of file\n+1.  **DONE:** Modify `_process_individual_maps` Logic: Updated the internal logic to correctly utilize `_load_and_transform_source` (with cache) and `_save_image` for maps not involved in merging.\r\n+2.  **DONE:** Modify `_merge_maps_from_source` Logic: Updated the internal logic to correctly utilize `_load_and_transform_source` (with cache) for *source* files, perform the channel merge, and then use `_save_image` for the merged result.\r\n+3.  **DONE:** Testing: User confirmed the refactored code works correctly.\n\\ No newline at end of file\n"
                }
            ],
            "date": 1745343175929,
            "name": "Commit-0",
            "content": "# Refactoring Plan for REFACTOR-001: Merge Maps From Source\r\n\r\nThis plan details the steps to implement the refactoring described in `Tickets/REFACTOR-001-merge-from-source.md`. The goal is to improve merged map quality by loading data directly from original source files, avoiding intermediate compression artifacts.\r\n\r\n## Final Plan Summary:\r\n\r\n1.  **Implement `_load_and_transform_source` Helper:**\r\n    *   Loads source image, performs initial prep (BGR->RGB, gloss inversion), resizes to target resolution.\r\n    *   Includes an in-memory cache (passed from `process`) using a `(source_path, resolution_key)` key to store and retrieve resized results, avoiding redundant loading and resizing within a single `process` call.\r\n\r\n2.  **Implement `_save_image` Helper:**\r\n    *   Encapsulates all saving logic: determining output format/bit depth based on rules, final data type/color space conversions, filename construction, saving with `cv2.imwrite`, and fallback logic (e.g., EXR->PNG).\r\n\r\n3.  **Refactor `_process_maps` (Potential Rename):**\r\n    *   Modify to process only maps *not* used as inputs for any merge rule.\r\n    *   Calls `_load_and_transform_source` (passing cache) and `_save_image`.\r\n\r\n4.  **Replace `_merge_maps` with `_merge_maps_from_source`:**\r\n    *   Iterates through merge rules.\r\n    *   Calls `_load_and_transform_source` (passing cache) for each required *source* input at target resolutions.\r\n    *   Merges the resulting channel data.\r\n    *   Calls `_save_image` to save the final merged map.\r\n\r\n5.  **Update `process` Method:**\r\n    *   Initializes an empty cache dictionary (`loaded_data_cache = {}`) at the beginning of the method.\r\n    *   Passes this cache dictionary to all calls to `_load_and_transform_source` within its scope.\r\n    *   Coordinates calls to the refactored/new processing and merging functions.\r\n    *   Ensures results are collected correctly for metadata generation.\r\n\r\n## New Workflow Visualization:\r\n\r\n```mermaid\r\ngraph TD\r\n    A2[Input Files] --> B2(_inventory_and_classify_files);\r\n    B2 --> C2{Classified Maps Info};\r\n\r\n    subgraph Processing Logic\r\n        C2 --> D2(_process_individual_map);\r\n        C2 --> E2(_merge_maps_from_source);\r\n        D2 --> F2([_load_and_transform_source w/ Cache]);\r\n        E2 --> F2;\r\n    end\r\n\r\n    F2 --> G2{Loaded/Transformed Data (Cached)};\r\n\r\n    subgraph Saving Logic\r\n         G2 --> H2([_save_image]);\r\n         D2 --> H2;\r\n         E2 --> H2;\r\n    end\r\n\r\n    H2 -- Saves Temp Files --> I2{Processed/Merged Map Details};\r\n\r\n    I2 --> J2(_generate_metadata_file);\r\n    J2 --> K2(_organize_output_files);"
        }
    ]
}